new option -o
[fw/sdcc] / src / z80 / main.c
index 0f9f5a81221f7b90582c0a1d4e6632244c0e74b3..eafbd6552f576da8f2ddd73f99098bb820918a11 100644 (file)
@@ -41,12 +41,19 @@ static char _gbz80_defaultRules[] =
 
 Z80_OPTS z80_opts;
 
+static OPTION _z80_options[] = 
+  {
+    { 0,   "--callee-saves-bc", &z80_opts.calleeSavesBC, "Force a called function to always save BC" },
+    { 0, NULL }
+  };
+
 typedef enum
   {
     /* Must be first */
     ASM_TYPE_ASXXXX,
     ASM_TYPE_RGBDS,
-    ASM_TYPE_ISAS
+    ASM_TYPE_ISAS,
+    ASM_TYPE_Z80ASM
   }
 ASM_TYPE;
 
@@ -180,15 +187,10 @@ static void
 _gbz80_rgblink (void)
 {
   FILE *lnkfile;
-  const char *sz;
-
   int i;
-  sz = srcFileName;
-  if (!sz)
-    sz = "a";
 
   /* first we need to create the <filename>.lnk file */
-  sprintf (scratchFileName, "%s.lnk", sz);
+  sprintf (scratchFileName, "%s.lnk", dstFileName);
   if (!(lnkfile = fopen (scratchFileName, "w")))
     {
       werror (E_FILE_OPEN_ERR, scratchFileName);
@@ -197,8 +199,7 @@ _gbz80_rgblink (void)
 
   fprintf (lnkfile, "[Objects]\n");
 
-  if (srcFileName)
-    fprintf (lnkfile, "%s.o\n", sz);
+  fprintf (lnkfile, "%s.o\n", dstFileName);
 
   for (i = 0; i < nrelFiles; i++)
     fprintf (lnkfile, "%s\n", relFiles[i]);
@@ -209,11 +210,11 @@ _gbz80_rgblink (void)
     fprintf (lnkfile, "%s\n", libFiles[i]);
 
 
-  fprintf (lnkfile, "\n[Output]\n" "%s.gb", sz);
+  fprintf (lnkfile, "\n[Output]\n" "%s.gb", dstFileName);
 
   fclose (lnkfile);
 
-  buildCmdLine (buffer,port->linker.cmd, sz, NULL, NULL, NULL);
+  buildCmdLine (buffer,port->linker.cmd, dstFileName, NULL, NULL, NULL);
   /* call the linker */
   if (my_system (buffer))
     {
@@ -269,6 +270,13 @@ _parseOptions (int *pargc, char **argv, int *i)
              _G.asmType = ASM_TYPE_ISAS;
              return TRUE;
            }
+         else if (!strcmp (argv[*i], "--asm=z80asm"))
+           {
+              port->assembler.externGlobal = TRUE;
+             asm_addTree (&_z80asm_z80);
+             _G.asmType = ASM_TYPE_ISAS;
+             return TRUE;
+           }
        }
     }
   return FALSE;
@@ -302,6 +310,9 @@ _setValues(void)
       setMainValue ("z80outext", ".ihx");
     }
 
+  setMainValue ("z80stdobjdstfilename" , "{dstfilename}{objext}");
+  setMainValue ("z80stdlinkdstfilename", "{dstfilename}{z80outext}");
+
   setMainValue ("z80extraobj", joinn (relFiles, nrelFiles));
   
   sprintf (buffer, "-b_CODE=0x%04X -b_DATA=0x%04X", options.code_loc, options.data_loc);
@@ -433,13 +444,13 @@ _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
     "{bindir}{sep}link-{port} -n -c -- {z80bases} -m -j" \
     " {z80libspec}" \
     " {z80extralibfiles} {z80extralibpaths}" \
-    " {z80outputtypeflag} {srcfilename}{z80outext}" \
+    " {z80outputtypeflag} {z80linkdstfilename}" \
     " {z80crt0}" \
-    " {srcfilename}{objext}" \
+    " {dstfilename}{objext}" \
     " {z80extraobj}" 
 
 #define ASMCMD \
-    "{bindir}{sep}as-{port} -plosgff {srcfilename}{objext} {srcfilename}{asmext}"
+    "{bindir}{sep}as-{port} -plosgff {z80objdstfilename} {dstfilename}{asmext}"
 
 /* Globals */
 PORT z80_port =
@@ -447,6 +458,7 @@ PORT z80_port =
   TARGET_ID_Z80,
   "z80",
   "Zilog Z80",                 /* Target name */
+  NULL,                                /* Processor name */
   {
     FALSE,
     MODEL_MEDIUM | MODEL_SMALL,
@@ -486,6 +498,8 @@ PORT z80_port =
     "OVERLAY",
     "GSFINAL",
     "HOME",
+    NULL, // xidata
+    NULL, // xinit
     NULL,
     NULL,
     1
@@ -500,13 +514,16 @@ PORT z80_port =
   "_",
   _z80_init,
   _parseOptions,
+  _z80_options,
   _finaliseOptions,
   _setDefaultOptions,
   z80_assignRegisters,
   _getRegName,
   _keywords,
   0,                           /* no assembler preamble */
+  NULL,                                /* no genAssemblerEnd */
   0,                           /* no local IVT generation code */
+  0,                            /* no genXINIT code */
   _reset_regparm,
   _reg_parm,
   _process_pragma,
@@ -522,6 +539,9 @@ PORT z80_port =
   TRUE,                         /* Array initializer support. */       
   0,                            /* no CSE cost estimation yet */
   _z80_builtins,               /* no builtin functions */
+  GPOINTER,                    /* treat unqualified pointers as "generic" pointers */
+  1,                           /* reset labelKey to 1 */
+  1,                           /* globals & local static allowed */
   PORT_MAGIC
 };
 
@@ -531,6 +551,7 @@ PORT gbz80_port =
   TARGET_ID_GBZ80,
   "gbz80",
   "Gameboy Z80-like",          /* Target name */
+  NULL,
   {
     FALSE,
     MODEL_MEDIUM | MODEL_SMALL,
@@ -542,7 +563,8 @@ PORT gbz80_port =
     "-plosgff",                        /* Options with debug */
     "-plosgff",                        /* Options without debug */
     0,
-    ".asm"
+    ".asm",
+    NULL                       /* no do_assemble function */
   },
   {
     NULL,
@@ -570,6 +592,8 @@ PORT gbz80_port =
     "OVERLAY",
     "GSFINAL",
     "HOME",
+    NULL, // xidata
+    NULL, // xinit
     NULL,
     NULL,
     1
@@ -584,13 +608,16 @@ PORT gbz80_port =
   "_",
   _gbz80_init,
   _parseOptions,
+  _z80_options,
   _finaliseOptions,
   _setDefaultOptions,
   z80_assignRegisters,
   _getRegName,
   _keywords,
   0,                           /* no assembler preamble */
+  NULL,                                /* no genAssemblerEnd */
   0,                           /* no local IVT generation code */
+  0,                            /* no genXINIT code */
   _reset_regparm,
   _reg_parm,
   _process_pragma,
@@ -605,6 +632,9 @@ PORT gbz80_port =
   0,                           /* leave == */
   TRUE,                         /* Array initializer support. */
   0,                            /* no CSE cost estimation yet */
-  NULL,                                /* no builtin functions */
+  NULL,                        /* no builtin functions */
+  GPOINTER,                    /* treat unqualified pointers as "generic" pointers */
+  1,                           /* reset labelKey to 1 */
+  1,                           /* globals & local static allowed */
   PORT_MAGIC
 };