+
+ /* Release memory for the string */
+ SB_Done (&Buf);
+}
+
+
+
+static void NewSymbol (const char* SymName, long Val)
+/* Define a symbol with a fixed numeric value in the current scope */
+{
+ ExprNode* Expr;
+ SymEntry* Sym;
+
+ /* Convert the name to a string buffer */
+ StrBuf SymBuf = STATIC_STRBUF_INITIALIZER;
+ SB_CopyStr (&SymBuf, SymName);
+
+ /* Search for the symbol, allocate a new one if it doesn't exist */
+ Sym = SymFind (CurrentScope, &SymBuf, 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);
+
+ /* Free string buffer memory */
+ SB_Done (&SymBuf);
+}
+
+
+
+static void CBMSystem (const char* Sys)
+/* Define a CBM system */
+{
+ NewSymbol ("__CBM__", 1);
+ NewSymbol (Sys, 1);
+}
+
+
+
+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_ATARI5200:
+ NewSymbol ("__ATARI5200__", 1);
+ break;
+
+ case TGT_ATARI:
+ NewSymbol ("__ATARI__", 1);
+ break;
+
+ case TGT_ATARIXL:
+ NewSymbol ("__ATARI__", 1);
+ NewSymbol ("__ATARIXL__", 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_PLUS4:
+ CBMSystem ("__C16__");
+ NewSymbol ("__PLUS4__", 1);
+ 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 ("__APPLE2__", 1);
+ NewSymbol ("__APPLE2ENH__", 1);
+ break;
+
+ case TGT_GAMATE:
+ NewSymbol ("__GAMATE__", 1);
+ break;
+
+ case TGT_GEOS_CBM:
+ /* Do not handle as a CBM system */
+ NewSymbol ("__GEOS__", 1);
+ NewSymbol ("__GEOS_CBM__", 1);
+ break;
+
+ case TGT_GEOS_APPLE:
+ NewSymbol ("__GEOS__", 1);
+ NewSymbol ("__GEOS_APPLE__", 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;
+
+ case TGT_LYNX:
+ NewSymbol ("__LYNX__", 1);
+ break;
+
+ case TGT_SIM6502:
+ NewSymbol ("__SIM6502__", 1);
+ break;
+
+ case TGT_SIM65C02:
+ NewSymbol ("__SIM65C02__", 1);
+ break;
+
+ case TGT_OSIC1P:
+ NewSymbol ("__OSIC1P__", 1);
+ break;
+
+ case TGT_PCENGINE:
+ NewSymbol ("__PCE__", 1);
+ break;
+
+ default:
+ AbEnd ("Invalid target name: `%s'", Sys);
+
+ }
+
+ /* Initialize the translation tables for the target system */
+ TgtTranslateInit ();
+}
+
+
+
+static void FileNameOption (const char* Opt, const char* Arg, StrBuf* Name)
+/* Handle an option that remembers a file name for later */
+{
+ /* Cannot have the option twice */
+ if (SB_NotEmpty (Name)) {
+ AbEnd ("Cannot use option `%s' twice", Opt);
+ }
+ /* Remember the file name for later */
+ SB_CopyStr (Name, Arg);
+ SB_Terminate (Name);