Martins ddd/sdcdb changes
[fw/sdcc] / src / z80 / main.c
index 8336b0556aa47f01478ef2fb9de9b856aa974dae..bd3537ea1be99a6e67b09daea96c219b8c417331 100644 (file)
@@ -41,6 +41,12 @@ 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 */
@@ -169,27 +175,22 @@ _process_pragma (const char *sz)
 
 static const char *_gbz80_rgbasmCmd[] =
 {
-  "rgbasm", "-o$1.o", "$1.asm", NULL
+  "rgbasm", "-o\"$1.o\"", "\"$1.asm\"", NULL
 };
 
 static const char *_gbz80_rgblinkCmd[] =
 {
-  "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
+  "xlink", "-tg", "-n\"$1.sym\"", "-m\"$1.map\"", "-zFF", "\"$1.lnk\"", NULL
 };
 
 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);
@@ -198,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]);
@@ -210,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))
     {
@@ -287,8 +287,8 @@ _setValues(void)
 {
   if (options.nostdlib == FALSE)
     {
-      setMainValue ("z80libspec", "-k{libdir}{sep}{port} -l{port}.lib");
-      setMainValue ("z80crt0", "{libdir}{sep}{port}{sep}crt0{objext}");
+      setMainValue ("z80libspec", "-k\"{libdir}{sep}{port}\" -l\"{port}.lib\"");
+      setMainValue ("z80crt0", "\"{libdir}{sep}{port}{sep}crt0{objext}\"");
     }
   else
     {
@@ -310,8 +310,11 @@ _setValues(void)
       setMainValue ("z80outext", ".ihx");
     }
 
+  setMainValue ("stdobjdstfilename" , "{dstfilename}{objext}");
+  setMainValue ("stdlinkdstfilename", "{dstfilename}{z80outext}");
+
   setMainValue ("z80extraobj", joinn (relFiles, nrelFiles));
-  
+
   sprintf (buffer, "-b_CODE=0x%04X -b_DATA=0x%04X", options.code_loc, options.data_loc);
   setMainValue ("z80bases", buffer);
 }
@@ -330,7 +333,6 @@ _finaliseOptions (void)
 static void
 _setDefaultOptions (void)
 {
-  options.genericPtr = 1;      /* default on */
   options.nopeep = 0;
   options.stackAuto = 1;
   options.mainreturn = 1;
@@ -438,16 +440,16 @@ _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
 }
 
 #define LINKCMD \
-    "{bindir}{sep}link-{port} -n -c -- {z80bases} -m -j" \
+    "link-{port} -n -c -- {z80bases} -m -j" \
     " {z80libspec}" \
     " {z80extralibfiles} {z80extralibpaths}" \
-    " {z80outputtypeflag} {srcfilename}{z80outext}" \
+    " {z80outputtypeflag} \"{linkdstfilename}\"" \
     " {z80crt0}" \
-    " {srcfilename}{objext}" \
-    " {z80extraobj}" 
+    " \"{dstfilename}{objext}\"" \
+    " {z80extraobj}"
 
 #define ASMCMD \
-    "{bindir}{sep}as-{port} -plosgff {srcfilename}{objext} {srcfilename}{asmext}"
+    "as-{port} -plosgff \"{objdstfilename}\" \"{dstfilename}{asmext}\""
 
 /* Globals */
 PORT z80_port =
@@ -455,6 +457,7 @@ PORT z80_port =
   TARGET_ID_Z80,
   "z80",
   "Zilog Z80",                 /* Target name */
+  NULL,                                /* Processor name */
   {
     FALSE,
     MODEL_MEDIUM | MODEL_SMALL,
@@ -510,12 +513,14 @@ 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,
@@ -545,6 +550,7 @@ PORT gbz80_port =
   TARGET_ID_GBZ80,
   "gbz80",
   "Gameboy Z80-like",          /* Target name */
+  NULL,
   {
     FALSE,
     MODEL_MEDIUM | MODEL_SMALL,
@@ -556,7 +562,8 @@ PORT gbz80_port =
     "-plosgff",                        /* Options with debug */
     "-plosgff",                        /* Options without debug */
     0,
-    ".asm"
+    ".asm",
+    NULL                       /* no do_assemble function */
   },
   {
     NULL,
@@ -600,12 +607,14 @@ 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,