options.model specific fixes
[fw/sdcc] / src / z80 / main.c
index 935e1f07e642725b7a7282f45f5de20d780d426f..e48ed3e21bc5a34c4e36e3028cabf02a34dd51df 100644 (file)
@@ -14,12 +14,20 @@ static char _gbz80_defaultRules[] =
 
 Z80_OPTS z80_opts;
 
+typedef enum {
+    /* Must be first */
+    ASM_TYPE_ASXXXX,
+    ASM_TYPE_RGBDS,
+    ASM_TYPE_ISAS
+} ASM_TYPE;
+
 static struct {
-    bool fsetAsmType;
+    ASM_TYPE asmType;
 } _G;
 
 static char *_keywords[] = {
     "sfr",
+    "nonbanked",
     "banked",
     NULL 
 };
@@ -72,11 +80,36 @@ static int _process_pragma(const char *sz)
 {
     if (_startsWith(sz, "bank=")) {
        char buffer[128];
-       sprintf(buffer, "%s", sz+5);
+       strcpy(buffer, sz+5);
        _chomp(buffer);
-       if (!strcmp(buffer, "BASE")) {
+       if (isdigit(buffer[0])) {
+           
+       }
+       else if (!strcmp(buffer, "BASE")) {
            strcpy(buffer, "HOME");
        }
+       if (isdigit(buffer[0])) {
+           /* Arg was a bank number.  Handle in an ASM independent
+              way. */
+           char num[128];
+           strcpy(num, sz+5);
+           _chomp(num);
+
+           switch (_G.asmType) {
+           case ASM_TYPE_ASXXXX:
+               sprintf(buffer, "CODE_%s", num);
+               break;
+           case ASM_TYPE_RGBDS:
+               sprintf(buffer, "CODE,BANK[%s]", num);
+               break;
+           case ASM_TYPE_ISAS:
+               /* PENDING: what to use for ISAS? */
+               sprintf(buffer, "CODE,BANK(%s)", num);
+               break;
+           default:
+               wassert(0);
+           }
+       }
        gbz80_port.mem.code_name = gc_strdup(buffer);
        code->sname = gbz80_port.mem.code_name;
        return 0;
@@ -161,19 +194,18 @@ static bool _parseOptions(int *pargc, char **argv, int *i)
                gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
                gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
                gbz80_port.linker.do_link = _gbz80_rgblink;
-               _G.fsetAsmType = TRUE;
+               _G.asmType = ASM_TYPE_RGBDS;
                return TRUE;
            }
            else if (!strcmp(argv[*i], "--asm=asxxxx")) {
-               asm_addTree(&_asxxxx_gb);
-               _G.fsetAsmType = TRUE;
+               _G.asmType = ASM_TYPE_ASXXXX;
                return TRUE;
            }
            else if (!strcmp(argv[*i], "--asm=isas")) {
                asm_addTree(&_isas_gb);
                /* Munge the function prefix */
                gbz80_port.fun_prefix = "";
-               _G.fsetAsmType = TRUE;
+               _G.asmType = ASM_TYPE_ISAS;
                return TRUE;
            }
        }
@@ -185,7 +217,7 @@ static void _finaliseOptions(void)
 {
     port->mem.default_local_map = data;
     port->mem.default_globl_map = data;
-    if (!_G.fsetAsmType && IS_GB)
+    if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB)
        asm_addTree(&_asxxxx_gb);
 }
 
@@ -228,7 +260,7 @@ static const char *_z80_linkCmd[] = {
 };
 
 static const char *_z80_asmCmd[] = {
-    "as-z80", "-plosgff", "$1.asm", NULL
+    "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
 };
 
 /** $1 is always the basename.
@@ -251,6 +283,8 @@ PORT z80_port = {
     "Zilog Z80",               /* Target name */
     {
        FALSE,
+       MODEL_MEDIUM | MODEL_SMALL,
+       MODEL_SMALL
     },
     {  
        _z80_asmCmd,
@@ -281,6 +315,7 @@ PORT z80_port = {
        "GSINIT",
        "OVERLAY",
        "GSFINAL",
+       "HOME",
        NULL,
        NULL,
        1
@@ -290,7 +325,7 @@ PORT z80_port = {
     },
     /* Z80 has no native mul/div commands */
     {  
-       0
+       0, 2
     },
     "_",
     _z80_init,
@@ -314,6 +349,8 @@ PORT gbz80_port = {
     "Gameboy Z80-like",                /* Target name */
     {
        FALSE,
+       MODEL_MEDIUM | MODEL_SMALL,
+       MODEL_SMALL
     },
     {  
        _gbz80_asmCmd,
@@ -345,6 +382,7 @@ PORT gbz80_port = {
        "GSINIT",
        "OVERLAY",
        "GSFINAL",
+       "HOME",
        NULL,
        NULL,
        1
@@ -354,7 +392,7 @@ PORT gbz80_port = {
     },
     /* gbZ80 has no native mul/div commands */
     {  
-       0
+       0, 2
     },
     "_",
     _gbz80_init,