2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* main.c */
|
|
|
|
|
/* */
|
|
|
|
|
/* Main program for the ca65 macroassembler */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2004-05-10 21:50:13 +00:00
|
|
|
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
2003-11-08 17:20:21 +00:00
|
|
|
|
/* R<>merstra<72>e 52 */
|
2003-05-25 17:57:50 +00:00
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
|
/* */
|
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
|
/* distribution. */
|
|
|
|
|
/* */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2000-07-28 12:15:40 +00:00
|
|
|
|
/* common */
|
2003-11-07 19:28:37 +00:00
|
|
|
|
#include "addrsize.h"
|
2001-01-05 19:24:47 +00:00
|
|
|
|
#include "chartype.h"
|
2000-07-28 12:15:40 +00:00
|
|
|
|
#include "cmdline.h"
|
2003-11-28 22:12:14 +00:00
|
|
|
|
#include "mmodel.h"
|
2001-03-10 10:21:03 +00:00
|
|
|
|
#include "print.h"
|
2000-08-23 07:01:18 +00:00
|
|
|
|
#include "target.h"
|
2000-09-14 19:26:13 +00:00
|
|
|
|
#include "tgttrans.h"
|
2000-07-28 12:15:40 +00:00
|
|
|
|
#include "version.h"
|
2000-08-01 21:36:45 +00:00
|
|
|
|
|
2000-07-28 12:15:40 +00:00
|
|
|
|
/* ca65 */
|
2000-08-21 21:20:40 +00:00
|
|
|
|
#include "abend.h"
|
2003-06-06 20:47:59 +00:00
|
|
|
|
#include "asserts.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "error.h"
|
|
|
|
|
#include "expr.h"
|
2000-09-02 11:35:22 +00:00
|
|
|
|
#include "feature.h"
|
2000-08-01 21:36:45 +00:00
|
|
|
|
#include "filetab.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "global.h"
|
2000-05-29 18:40:56 +00:00
|
|
|
|
#include "incpath.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "instr.h"
|
2000-07-09 13:19:25 +00:00
|
|
|
|
#include "istack.h"
|
2001-05-23 19:03:40 +00:00
|
|
|
|
#include "lineinfo.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "listing.h"
|
|
|
|
|
#include "macro.h"
|
2000-06-03 11:15:11 +00:00
|
|
|
|
#include "nexttok.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "objfile.h"
|
|
|
|
|
#include "options.h"
|
|
|
|
|
#include "pseudo.h"
|
|
|
|
|
#include "scanner.h"
|
2003-10-21 20:34:56 +00:00
|
|
|
|
#include "segment.h"
|
2003-12-02 22:09:45 +00:00
|
|
|
|
#include "sizeof.h"
|
2003-05-25 17:57:50 +00:00
|
|
|
|
#include "spool.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "symtab.h"
|
|
|
|
|
#include "ulabel.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Code */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Usage (void)
|
|
|
|
|
/* Print usage information and exit */
|
|
|
|
|
{
|
2005-03-24 20:08:41 +00:00
|
|
|
|
printf ("Usage: %s [options] file\n"
|
|
|
|
|
"Short options:\n"
|
|
|
|
|
" -D name[=value]\tDefine a symbol\n"
|
|
|
|
|
" -I dir\t\tSet an include directory search path\n"
|
|
|
|
|
" -U\t\t\tMark unresolved symbols as import\n"
|
|
|
|
|
" -V\t\t\tPrint the assembler version\n"
|
|
|
|
|
" -W n\t\t\tSet warning level n\n"
|
|
|
|
|
" -g\t\t\tAdd debug info to object file\n"
|
|
|
|
|
" -h\t\t\tHelp (this text)\n"
|
|
|
|
|
" -i\t\t\tIgnore case of symbols\n"
|
|
|
|
|
" -l\t\t\tCreate a listing if assembly was ok\n"
|
|
|
|
|
" -mm model\t\tSet the memory model\n"
|
|
|
|
|
" -o name\t\tName the output file\n"
|
|
|
|
|
" -s\t\t\tEnable smart mode\n"
|
|
|
|
|
" -t sys\t\tSet the target system\n"
|
|
|
|
|
" -v\t\t\tIncrease verbosity\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Long options:\n"
|
|
|
|
|
" --auto-import\t\tMark unresolved symbols as import\n"
|
|
|
|
|
" --cpu type\t\tSet cpu type\n"
|
|
|
|
|
" --debug-info\t\tAdd debug info to object file\n"
|
|
|
|
|
" --feature name\tSet an emulation feature\n"
|
|
|
|
|
" --help\t\tHelp (this text)\n"
|
|
|
|
|
" --ignore-case\t\tIgnore case of symbols\n"
|
|
|
|
|
" --include-dir dir\tSet an include directory search path\n"
|
|
|
|
|
" --listing\t\tCreate a listing if assembly was ok\n"
|
|
|
|
|
" --list-bytes n\tMaximum number of bytes per listing line\n"
|
|
|
|
|
" --memory-model model\tSet the memory model\n"
|
|
|
|
|
" --pagelength n\tSet the page length for the listing\n"
|
|
|
|
|
" --smart\t\tEnable smart mode\n"
|
|
|
|
|
" --target sys\t\tSet the target system\n"
|
|
|
|
|
" --verbose\t\tIncrease verbosity\n"
|
|
|
|
|
" --version\t\tPrint the assembler version\n",
|
|
|
|
|
ProgName);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void SetOptions (void)
|
|
|
|
|
/* Set the option for the translator */
|
|
|
|
|
{
|
|
|
|
|
char Buf [256];
|
|
|
|
|
|
|
|
|
|
/* Set the translator */
|
|
|
|
|
sprintf (Buf, "ca65 V%u.%u.%u", VER_MAJOR, VER_MINOR, VER_PATCH);
|
|
|
|
|
OptTranslator (Buf);
|
|
|
|
|
|
|
|
|
|
/* Set date and time */
|
|
|
|
|
OptDateTime ((unsigned long) time(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-03 21:12:29 +00:00
|
|
|
|
static void NewSymbol (const char* SymName, long Val)
|
|
|
|
|
/* Define a symbol with a fixed numeric value in the current scope */
|
|
|
|
|
{
|
|
|
|
|
ExprNode* Expr;
|
|
|
|
|
|
|
|
|
|
/* Search for the symbol, allocate a new one if it doesn't exist */
|
|
|
|
|
SymEntry* Sym = SymFind (CurrentScope, SymName, SYM_ALLOC_NEW);
|
|
|
|
|
|
|
|
|
|
/* Check if have already a symbol with this name */
|
|
|
|
|
if (SymIsDef (Sym)) {
|
|
|
|
|
AbEnd ("`%s' is already defined", SymName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Generate an expression for the symbol */
|
|
|
|
|
Expr = GenLiteralExpr (Val);
|
|
|
|
|
|
|
|
|
|
/* Mark the symbol as defined */
|
|
|
|
|
SymDef (Sym, Expr, ADDR_SIZE_DEFAULT, SF_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void CBMSystem (const char* Sys)
|
|
|
|
|
/* Define a CBM system */
|
|
|
|
|
{
|
|
|
|
|
NewSymbol ("__CBM__", 1);
|
|
|
|
|
NewSymbol (Sys, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-08 09:23:59 +00:00
|
|
|
|
|
2004-06-03 21:12:29 +00:00
|
|
|
|
static void SetSys (const char* Sys)
|
|
|
|
|
/* Define a target system */
|
|
|
|
|
{
|
|
|
|
|
switch (Target = FindTarget (Sys)) {
|
|
|
|
|
|
|
|
|
|
case TGT_NONE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_MODULE:
|
|
|
|
|
AbEnd ("Cannot use `module' as a target for the assembler");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_ATARI:
|
|
|
|
|
NewSymbol ("__ATARI__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_C16:
|
|
|
|
|
CBMSystem ("__C16__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_C64:
|
|
|
|
|
CBMSystem ("__C64__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_VIC20:
|
|
|
|
|
CBMSystem ("__VIC20__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_C128:
|
|
|
|
|
CBMSystem ("__C128__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_ACE:
|
|
|
|
|
CBMSystem ("__ACE__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_PLUS4:
|
|
|
|
|
CBMSystem ("__PLUS4__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_CBM510:
|
|
|
|
|
CBMSystem ("__CBM510__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_CBM610:
|
|
|
|
|
CBMSystem ("__CBM610__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_PET:
|
|
|
|
|
CBMSystem ("__PET__");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_BBC:
|
|
|
|
|
NewSymbol ("__BBC__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_APPLE2:
|
|
|
|
|
NewSymbol ("__APPLE2__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_APPLE2ENH:
|
|
|
|
|
NewSymbol ("__APPLE2ENH__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_GEOS:
|
|
|
|
|
/* Do not handle as a CBM system */
|
|
|
|
|
NewSymbol ("__GEOS__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_LUNIX:
|
|
|
|
|
NewSymbol ("__LUNIX__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_ATMOS:
|
|
|
|
|
NewSymbol ("__ATMOS__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_NES:
|
|
|
|
|
NewSymbol ("__NES__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TGT_SUPERVISION:
|
|
|
|
|
NewSymbol ("__SUPERVISION__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-10-08 09:23:59 +00:00
|
|
|
|
case TGT_LYNX:
|
|
|
|
|
NewSymbol ("__LYNX__", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-06-03 21:12:29 +00:00
|
|
|
|
default:
|
|
|
|
|
AbEnd ("Invalid target name: `%s'", Sys);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the translation tables for the target system */
|
|
|
|
|
TgtTranslateInit ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
static void DefineSymbol (const char* Def)
|
|
|
|
|
/* Define a symbol from the command line */
|
|
|
|
|
{
|
|
|
|
|
const char* P;
|
|
|
|
|
unsigned I;
|
|
|
|
|
long Val;
|
|
|
|
|
char SymName [MAX_STR_LEN+1];
|
2003-11-06 11:22:31 +00:00
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* The symbol must start with a character or underline */
|
2001-01-05 19:24:47 +00:00
|
|
|
|
if (Def [0] != '_' && !IsAlpha (Def [0])) {
|
2000-06-14 09:32:22 +00:00
|
|
|
|
InvDef (Def);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
P = Def;
|
|
|
|
|
|
|
|
|
|
/* Copy the symbol, checking the rest */
|
|
|
|
|
I = 0;
|
2001-01-05 19:24:47 +00:00
|
|
|
|
while (IsAlNum (*P) || *P == '_') {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
if (I <= MAX_STR_LEN) {
|
|
|
|
|
SymName [I++] = *P;
|
|
|
|
|
}
|
|
|
|
|
++P;
|
|
|
|
|
}
|
|
|
|
|
SymName [I] = '\0';
|
|
|
|
|
|
|
|
|
|
/* Do we have a value given? */
|
|
|
|
|
if (*P != '=') {
|
|
|
|
|
if (*P != '\0') {
|
2000-06-14 09:32:22 +00:00
|
|
|
|
InvDef (Def);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
Val = 0;
|
|
|
|
|
} else {
|
2004-06-03 21:12:29 +00:00
|
|
|
|
/* We have a value */
|
|
|
|
|
++P;
|
|
|
|
|
if (*P == '$') {
|
|
|
|
|
++P;
|
|
|
|
|
if (sscanf (P, "%lx", &Val) != 1) {
|
|
|
|
|
InvDef (Def);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (sscanf (P, "%li", &Val) != 1) {
|
|
|
|
|
InvDef (Def);
|
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-08 09:23:59 +00:00
|
|
|
|
|
2004-06-03 21:12:29 +00:00
|
|
|
|
/* Define the new symbol */
|
|
|
|
|
NewSymbol (SymName, Val);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptAutoImport (const char* Opt attribute ((unused)),
|
2004-06-03 21:12:29 +00:00
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Mark unresolved symbols as imported */
|
|
|
|
|
{
|
|
|
|
|
AutoImport = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Handle the --cpu option */
|
|
|
|
|
{
|
2003-10-10 17:08:08 +00:00
|
|
|
|
cpu_t CPU = FindCPU (Arg);
|
|
|
|
|
if (CPU == CPU_UNKNOWN) {
|
2000-08-21 21:20:40 +00:00
|
|
|
|
AbEnd ("Invalid CPU: `%s'", Arg);
|
2003-10-10 17:08:08 +00:00
|
|
|
|
} else {
|
|
|
|
|
SetCPU (CPU);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptDebugInfo (const char* Opt attribute ((unused)),
|
2004-06-03 21:12:29 +00:00
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Add debug info to the object file */
|
|
|
|
|
{
|
|
|
|
|
DbgSyms = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
|
2000-09-02 11:35:22 +00:00
|
|
|
|
/* Set an emulation feature */
|
|
|
|
|
{
|
|
|
|
|
/* Set the feature, check for errors */
|
|
|
|
|
if (SetFeature (Arg) == FEAT_UNKNOWN) {
|
|
|
|
|
AbEnd ("Illegal emulation feature: `%s'", Arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptHelp (const char* Opt attribute ((unused)),
|
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-06-14 07:22:25 +00:00
|
|
|
|
/* Print usage information and exit */
|
|
|
|
|
{
|
|
|
|
|
Usage ();
|
2000-06-14 09:32:22 +00:00
|
|
|
|
exit (EXIT_SUCCESS);
|
2000-06-14 07:22:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptIgnoreCase (const char* Opt attribute ((unused)),
|
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Ignore case on symbols */
|
|
|
|
|
{
|
|
|
|
|
IgnoreCase = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Add an include search path */
|
|
|
|
|
{
|
|
|
|
|
AddIncludePath (Arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-10 21:50:13 +00:00
|
|
|
|
static void OptListBytes (const char* Opt, const char* Arg)
|
|
|
|
|
/* Set the maximum number of bytes per listing line */
|
|
|
|
|
{
|
|
|
|
|
unsigned Num;
|
|
|
|
|
char Check;
|
|
|
|
|
|
|
|
|
|
/* Convert the argument to a number */
|
|
|
|
|
if (sscanf (Arg, "%u%c", &Num, &Check) != 1) {
|
|
|
|
|
AbEnd ("Invalid argument for option `%s'", Opt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check the bounds */
|
|
|
|
|
if (Num != 0 && (Num < MIN_LIST_BYTES || Num > MAX_LIST_BYTES)) {
|
|
|
|
|
AbEnd ("Argument for option `%s' is out of range", Opt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Use the value */
|
|
|
|
|
SetListBytes (Num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptListing (const char* Opt attribute ((unused)),
|
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Create a listing file */
|
|
|
|
|
{
|
|
|
|
|
Listing = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-28 22:12:14 +00:00
|
|
|
|
static void OptMemoryModel (const char* Opt, const char* Arg)
|
2003-11-23 21:38:23 +00:00
|
|
|
|
/* Set the memory model */
|
|
|
|
|
{
|
2003-11-28 22:12:14 +00:00
|
|
|
|
mmodel_t M;
|
|
|
|
|
|
|
|
|
|
/* Check the current memory model */
|
|
|
|
|
if (MemoryModel != MMODEL_UNKNOWN) {
|
|
|
|
|
AbEnd ("Cannot use option `%s' twice", Opt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Translate the memory model name and check it */
|
|
|
|
|
M = FindMemoryModel (Arg);
|
|
|
|
|
if (M == MMODEL_UNKNOWN) {
|
2003-11-23 21:38:23 +00:00
|
|
|
|
AbEnd ("Unknown memory model: %s", Arg);
|
2003-11-28 22:12:14 +00:00
|
|
|
|
} else if (M == MMODEL_HUGE) {
|
|
|
|
|
AbEnd ("Unsupported memory model: %s", Arg);
|
2003-11-23 21:38:23 +00:00
|
|
|
|
}
|
2003-11-28 22:12:14 +00:00
|
|
|
|
|
|
|
|
|
/* Set the memory model */
|
|
|
|
|
SetMemoryModel (M);
|
2003-11-23 21:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptPageLength (const char* Opt attribute ((unused)), const char* Arg)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Handle the --pagelength option */
|
|
|
|
|
{
|
2001-09-30 22:19:39 +00:00
|
|
|
|
int Len = atoi (Arg);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
if (Len != -1 && (Len < MIN_PAGE_LEN || Len > MAX_PAGE_LEN)) {
|
2000-08-21 21:20:40 +00:00
|
|
|
|
AbEnd ("Invalid page length: %d", Len);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
PageLength = Len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptSmart (const char* Opt attribute ((unused)),
|
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Handle the -s/--smart options */
|
|
|
|
|
{
|
|
|
|
|
SmartMode = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
|
2000-08-21 21:20:40 +00:00
|
|
|
|
/* Set the target system */
|
|
|
|
|
{
|
2004-06-03 21:12:29 +00:00
|
|
|
|
SetSys (Arg);
|
2000-08-21 21:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptVerbose (const char* Opt attribute ((unused)),
|
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Increase verbosity */
|
|
|
|
|
{
|
2001-03-10 10:21:03 +00:00
|
|
|
|
++Verbosity;
|
2000-05-29 18:40:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:19:39 +00:00
|
|
|
|
static void OptVersion (const char* Opt attribute ((unused)),
|
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-05-29 18:40:56 +00:00
|
|
|
|
/* Print the assembler version */
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
2003-05-25 17:57:50 +00:00
|
|
|
|
"ca65 V%u.%u.%u - %s\n",
|
|
|
|
|
VER_MAJOR, VER_MINOR, VER_PATCH, Copyright);
|
2000-05-29 18:40:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-02 11:05:32 +00:00
|
|
|
|
static void DoPCAssign (void)
|
|
|
|
|
/* Start absolute code */
|
|
|
|
|
{
|
|
|
|
|
long PC = ConstExpression ();
|
|
|
|
|
if (PC < 0 || PC > 0xFFFFFF) {
|
2003-11-08 17:20:21 +00:00
|
|
|
|
Error ("Range error");
|
2000-09-02 11:05:32 +00:00
|
|
|
|
} else {
|
|
|
|
|
SetAbsPC (PC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
static void OneLine (void)
|
|
|
|
|
/* Assemble one line */
|
2003-12-03 09:18:31 +00:00
|
|
|
|
{
|
2004-04-20 12:49:36 +00:00
|
|
|
|
Segment* Seg = 0;
|
|
|
|
|
unsigned long PC = 0;
|
|
|
|
|
SymEntry* Sym = 0;
|
|
|
|
|
int Macro = 0;
|
|
|
|
|
int Instr = -1;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2000-07-09 13:19:25 +00:00
|
|
|
|
/* Initialize the new listing line if we are actually reading from file
|
2000-07-28 12:15:40 +00:00
|
|
|
|
* and not from internally pushed input.
|
2000-07-09 13:19:25 +00:00
|
|
|
|
*/
|
|
|
|
|
if (!HavePushedInput ()) {
|
2004-04-20 12:49:36 +00:00
|
|
|
|
InitListingLine ();
|
2000-08-01 21:36:45 +00:00
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
if (Tok == TOK_COLON) {
|
2004-04-20 12:49:36 +00:00
|
|
|
|
/* An unnamed label */
|
|
|
|
|
ULabDef ();
|
|
|
|
|
NextTok ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-20 12:49:36 +00:00
|
|
|
|
/* If the first token on the line is an identifier, check for a macro or
|
|
|
|
|
* an instruction.
|
|
|
|
|
*/
|
|
|
|
|
if (Tok == TOK_IDENT) {
|
|
|
|
|
if (!UbiquitousIdents) {
|
|
|
|
|
/* Macros and symbols cannot use instruction names */
|
|
|
|
|
Instr = FindInstruction (SVal);
|
|
|
|
|
if (Instr < 0) {
|
|
|
|
|
Macro = IsMacro (SVal);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Macros and symbols may use the names of instructions */
|
|
|
|
|
Macro = IsMacro (SVal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handle an identifier */
|
|
|
|
|
if (Tok == TOK_LOCAL_IDENT || (Tok == TOK_IDENT && Instr < 0 && !Macro)) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
/* Did we have whitespace before the ident? */
|
|
|
|
|
int HadWS = WS;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
/* Generate the symbol table entry, then skip the name */
|
|
|
|
|
if (Tok == TOK_IDENT) {
|
|
|
|
|
Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
|
|
|
|
|
} else {
|
2003-11-30 18:41:32 +00:00
|
|
|
|
Sym = SymFindLocal (SymLast, SVal, SYM_ALLOC_NEW);
|
2003-11-29 07:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
NextTok ();
|
|
|
|
|
|
|
|
|
|
/* If a colon follows, this is a label definition. If there
|
|
|
|
|
* is no colon, it's an assignment.
|
|
|
|
|
*/
|
|
|
|
|
if (Tok == TOK_EQ || Tok == TOK_ASSIGN) {
|
|
|
|
|
/* If it's an assign token, we have a label */
|
|
|
|
|
unsigned Flags = (Tok == TOK_ASSIGN)? SF_LABEL : SF_NONE;
|
|
|
|
|
/* Skip the '=' */
|
|
|
|
|
NextTok ();
|
|
|
|
|
/* Define the symbol with the expression following the '=' */
|
|
|
|
|
SymDef (Sym, Expression(), ADDR_SIZE_DEFAULT, Flags);
|
|
|
|
|
/* Don't allow anything after a symbol definition */
|
2004-04-20 13:10:52 +00:00
|
|
|
|
ConsumeSep ();
|
|
|
|
|
return;
|
2003-11-29 07:53:26 +00:00
|
|
|
|
} else {
|
2003-12-02 22:09:45 +00:00
|
|
|
|
/* A label. Remember the current segment, so we can later
|
|
|
|
|
* determine the size of the data stored under the label.
|
|
|
|
|
*/
|
|
|
|
|
Seg = ActiveSeg;
|
|
|
|
|
PC = GetPC ();
|
|
|
|
|
|
|
|
|
|
/* Define the label */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
SymDef (Sym, GenCurrentPC (), ADDR_SIZE_DEFAULT, SF_LABEL);
|
2003-12-02 22:09:45 +00:00
|
|
|
|
|
2003-11-29 07:53:26 +00:00
|
|
|
|
/* Skip the colon. If NoColonLabels is enabled, allow labels
|
|
|
|
|
* without a colon if there is no whitespace before the
|
|
|
|
|
* identifier.
|
|
|
|
|
*/
|
|
|
|
|
if (Tok != TOK_COLON) {
|
|
|
|
|
if (HadWS || !NoColonLabels) {
|
|
|
|
|
Error ("`:' expected");
|
|
|
|
|
/* Try some smart error recovery */
|
|
|
|
|
if (Tok == TOK_NAMESPACE) {
|
|
|
|
|
NextTok ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Skip the colon */
|
|
|
|
|
NextTok ();
|
|
|
|
|
}
|
2004-04-20 13:10:52 +00:00
|
|
|
|
|
|
|
|
|
/* If we come here, a new identifier may be waiting, which may
|
|
|
|
|
* be a macro or instruction.
|
|
|
|
|
*/
|
|
|
|
|
if (Tok == TOK_IDENT) {
|
|
|
|
|
if (!UbiquitousIdents) {
|
|
|
|
|
/* Macros and symbols cannot use instruction names */
|
|
|
|
|
Instr = FindInstruction (SVal);
|
|
|
|
|
if (Instr < 0) {
|
|
|
|
|
Macro = IsMacro (SVal);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Macros and symbols may use the names of instructions */
|
|
|
|
|
Macro = IsMacro (SVal);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-29 07:53:26 +00:00
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-20 13:10:52 +00:00
|
|
|
|
/* We've handled a possible label, now handle the remainder of the line */
|
|
|
|
|
if (Tok >= TOK_FIRSTPSEUDO && Tok <= TOK_LASTPSEUDO) {
|
|
|
|
|
/* A control command */
|
|
|
|
|
HandlePseudo ();
|
|
|
|
|
} else if (Macro) {
|
|
|
|
|
/* A macro expansion */
|
|
|
|
|
MacExpandStart ();
|
|
|
|
|
} else if (Instr >= 0 ||
|
|
|
|
|
(UbiquitousIdents && ((Instr = FindInstruction (SVal)) >= 0))) {
|
|
|
|
|
/* A mnemonic - assemble one instruction */
|
|
|
|
|
HandleInstruction (Instr);
|
|
|
|
|
} else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
|
|
|
|
|
NextTok ();
|
|
|
|
|
if (Tok != TOK_EQ) {
|
|
|
|
|
Error ("`=' expected");
|
|
|
|
|
SkipUntilSep ();
|
|
|
|
|
} else {
|
|
|
|
|
/* Skip the equal sign */
|
|
|
|
|
NextTok ();
|
|
|
|
|
/* Enter absolute mode */
|
|
|
|
|
DoPCAssign ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we have defined a label, remember its size. Sym is also set by
|
|
|
|
|
* a symbol assignment, but in this case Done is false, so we don't
|
|
|
|
|
* come here.
|
|
|
|
|
*/
|
|
|
|
|
if (Sym) {
|
|
|
|
|
unsigned long Size;
|
|
|
|
|
if (Seg == ActiveSeg) {
|
|
|
|
|
/* Same segment */
|
|
|
|
|
Size = GetPC () - PC;
|
|
|
|
|
} else {
|
|
|
|
|
/* The line has switched the segment */
|
|
|
|
|
Size = 0;
|
2003-12-02 22:09:45 +00:00
|
|
|
|
}
|
2004-04-20 13:10:52 +00:00
|
|
|
|
DefSizeOfSymbol (Sym, Size);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Line separator must come here */
|
|
|
|
|
ConsumeSep ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Assemble (void)
|
|
|
|
|
/* Start the ball rolling ... */
|
|
|
|
|
{
|
|
|
|
|
/* Prime the pump */
|
|
|
|
|
NextTok ();
|
|
|
|
|
|
|
|
|
|
/* Assemble lines until end of file */
|
|
|
|
|
while (Tok != TOK_EOF) {
|
|
|
|
|
OneLine ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void CreateObjFile (void)
|
|
|
|
|
/* Create the object file */
|
|
|
|
|
{
|
|
|
|
|
/* Open the object, write the header */
|
|
|
|
|
ObjOpen ();
|
|
|
|
|
|
|
|
|
|
/* Write the object file options */
|
|
|
|
|
WriteOptions ();
|
|
|
|
|
|
|
|
|
|
/* Write the list of input files */
|
|
|
|
|
WriteFiles ();
|
|
|
|
|
|
|
|
|
|
/* Write the segment data to the file */
|
|
|
|
|
WriteSegments ();
|
|
|
|
|
|
|
|
|
|
/* Write the import list */
|
|
|
|
|
WriteImports ();
|
|
|
|
|
|
|
|
|
|
/* Write the export list */
|
|
|
|
|
WriteExports ();
|
|
|
|
|
|
|
|
|
|
/* Write debug symbols if requested */
|
|
|
|
|
WriteDbgSyms ();
|
|
|
|
|
|
2001-05-23 19:03:40 +00:00
|
|
|
|
/* Write line infos if requested */
|
|
|
|
|
WriteLineInfo ();
|
|
|
|
|
|
2003-05-25 17:57:50 +00:00
|
|
|
|
/* Write the string pool */
|
|
|
|
|
WriteStrPool ();
|
|
|
|
|
|
2003-06-06 12:45:19 +00:00
|
|
|
|
/* Write the assertions */
|
|
|
|
|
WriteAssertions ();
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Write an updated header and close the file */
|
|
|
|
|
ObjClose ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char* argv [])
|
|
|
|
|
/* Assembler main program */
|
|
|
|
|
{
|
2000-06-14 07:22:25 +00:00
|
|
|
|
/* Program long options */
|
|
|
|
|
static const LongOpt OptTab[] = {
|
|
|
|
|
{ "--auto-import", 0, OptAutoImport },
|
|
|
|
|
{ "--cpu", 1, OptCPU },
|
|
|
|
|
{ "--debug-info", 0, OptDebugInfo },
|
2000-09-02 11:35:22 +00:00
|
|
|
|
{ "--feature", 1, OptFeature },
|
|
|
|
|
{ "--help", 0, OptHelp },
|
2000-06-14 07:22:25 +00:00
|
|
|
|
{ "--ignore-case", 0, OptIgnoreCase },
|
|
|
|
|
{ "--include-dir", 1, OptIncludeDir },
|
2004-05-10 21:50:13 +00:00
|
|
|
|
{ "--list-bytes", 1, OptListBytes },
|
2000-09-02 11:35:22 +00:00
|
|
|
|
{ "--listing", 0, OptListing },
|
2003-11-23 21:38:23 +00:00
|
|
|
|
{ "--memory-model", 1, OptMemoryModel },
|
2000-06-14 07:22:25 +00:00
|
|
|
|
{ "--pagelength", 1, OptPageLength },
|
2004-04-20 13:10:52 +00:00
|
|
|
|
{ "--smart", 0, OptSmart },
|
2000-09-02 11:35:22 +00:00
|
|
|
|
{ "--target", 1, OptTarget },
|
|
|
|
|
{ "--verbose", 0, OptVerbose },
|
|
|
|
|
{ "--version", 0, OptVersion },
|
2000-06-14 07:22:25 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-09-15 11:51:08 +00:00
|
|
|
|
unsigned I;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2000-06-14 07:22:25 +00:00
|
|
|
|
/* Initialize the cmdline module */
|
2001-03-09 21:59:23 +00:00
|
|
|
|
InitCmdLine (&argc, &argv, "ca65");
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Enter the base lexical level. We must do that here, since we may
|
|
|
|
|
* define symbols using -D.
|
|
|
|
|
*/
|
2003-11-13 00:21:31 +00:00
|
|
|
|
SymEnterLevel ("", ST_GLOBAL, ADDR_SIZE_DEFAULT);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Check the parameters */
|
|
|
|
|
I = 1;
|
2001-03-09 21:59:23 +00:00
|
|
|
|
while (I < ArgCount) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Get the argument */
|
2001-03-09 21:59:23 +00:00
|
|
|
|
const char* Arg = ArgVec [I];
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Check for an option */
|
2003-11-23 21:38:23 +00:00
|
|
|
|
if (Arg[0] == '-') {
|
|
|
|
|
switch (Arg[1]) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-23 21:38:23 +00:00
|
|
|
|
case '-':
|
|
|
|
|
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-23 21:38:23 +00:00
|
|
|
|
case 'g':
|
|
|
|
|
OptDebugInfo (Arg, 0);
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-23 21:38:23 +00:00
|
|
|
|
case 'h':
|
|
|
|
|
OptHelp (Arg, 0);
|
|
|
|
|
break;
|
2000-07-08 21:01:02 +00:00
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
case 'i':
|
2003-11-23 21:38:23 +00:00
|
|
|
|
OptIgnoreCase (Arg, 0);
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-11-23 21:38:23 +00:00
|
|
|
|
case 'l':
|
|
|
|
|
OptListing (Arg, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
|
if (Arg[2] == 'm') {
|
|
|
|
|
OptMemoryModel (Arg, GetArg (&I, 3));
|
|
|
|
|
} else {
|
|
|
|
|
UnknownOption (Arg);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
case 'o':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
OutFile = GetArg (&I, 2);
|
2001-09-15 11:51:08 +00:00
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
case 's':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
OptSmart (Arg, 0);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-08-21 21:20:40 +00:00
|
|
|
|
case 't':
|
|
|
|
|
OptTarget (Arg, GetArg (&I, 2));
|
|
|
|
|
break;
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
case 'v':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
OptVerbose (Arg, 0);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-05-29 18:40:56 +00:00
|
|
|
|
case 'D':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
DefineSymbol (GetArg (&I, 2));
|
2000-05-29 18:40:56 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'I':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
OptIncludeDir (Arg, GetArg (&I, 2));
|
2000-05-29 18:40:56 +00:00
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
case 'U':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
OptAutoImport (Arg, 0);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'V':
|
2000-09-14 19:26:13 +00:00
|
|
|
|
OptVersion (Arg, 0);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'W':
|
2000-06-14 07:22:25 +00:00
|
|
|
|
WarnLevel = atoi (GetArg (&I, 2));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
UnknownOption (Arg);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Filename. Check if we already had one */
|
|
|
|
|
if (InFile) {
|
2000-06-14 09:32:22 +00:00
|
|
|
|
fprintf (stderr, "%s: Don't know what to do with `%s'\n",
|
2000-08-23 07:01:18 +00:00
|
|
|
|
ProgName, Arg);
|
|
|
|
|
exit (EXIT_FAILURE);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
} else {
|
2000-08-23 07:01:18 +00:00
|
|
|
|
InFile = Arg;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Next argument */
|
|
|
|
|
++I;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do we have an input file? */
|
|
|
|
|
if (InFile == 0) {
|
2000-06-14 09:32:22 +00:00
|
|
|
|
fprintf (stderr, "%s: No input files\n", ProgName);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-01 23:24:20 +00:00
|
|
|
|
/* If no CPU given, use the default CPU for the target */
|
2003-05-25 17:57:50 +00:00
|
|
|
|
if (GetCPU () == CPU_UNKNOWN) {
|
2003-05-01 23:24:20 +00:00
|
|
|
|
if (Target != TGT_UNKNOWN) {
|
|
|
|
|
SetCPU (DefaultCPU[Target]);
|
|
|
|
|
} else {
|
|
|
|
|
SetCPU (CPU_6502);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-28 22:12:14 +00:00
|
|
|
|
/* If no memory model was given, use the default */
|
|
|
|
|
if (MemoryModel == MMODEL_UNKNOWN) {
|
2003-11-29 07:53:26 +00:00
|
|
|
|
SetMemoryModel (MMODEL_NEAR);
|
2003-11-28 22:12:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the segments */
|
|
|
|
|
InitSegments ();
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Initialize the scanner, open the input file */
|
|
|
|
|
InitScanner (InFile);
|
|
|
|
|
|
|
|
|
|
/* Define the default options */
|
|
|
|
|
SetOptions ();
|
|
|
|
|
|
|
|
|
|
/* Assemble the input */
|
|
|
|
|
Assemble ();
|
|
|
|
|
|
2002-11-28 17:42:16 +00:00
|
|
|
|
/* If we didn't have any errors, check the segment stack */
|
|
|
|
|
if (ErrorCount == 0) {
|
|
|
|
|
SegStackCheck ();
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* If we didn't have any errors, check the unnamed labels */
|
|
|
|
|
if (ErrorCount == 0) {
|
2000-05-29 18:40:56 +00:00
|
|
|
|
ULabCheck ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we didn't have any errors, check the symbol table */
|
|
|
|
|
if (ErrorCount == 0) {
|
|
|
|
|
SymCheck ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we didn't have any errors, check and resolve the segment data */
|
|
|
|
|
if (ErrorCount == 0) {
|
|
|
|
|
SegCheck ();
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-23 19:03:40 +00:00
|
|
|
|
/* If we didn't have an errors, index the line infos */
|
|
|
|
|
MakeLineInfoIndex ();
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Dump the data */
|
2001-03-10 10:21:03 +00:00
|
|
|
|
if (Verbosity >= 2) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
SymDump (stdout);
|
|
|
|
|
SegDump ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we didn't have any errors, create the object and listing files */
|
|
|
|
|
if (ErrorCount == 0) {
|
|
|
|
|
CreateObjFile ();
|
|
|
|
|
if (Listing) {
|
|
|
|
|
CreateListing ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Close the input file */
|
|
|
|
|
DoneScanner ();
|
|
|
|
|
|
|
|
|
|
/* Return an apropriate exit code */
|
|
|
|
|
return (ErrorCount == 0)? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|