* Makefile.in, configure.in, configure,
[fw/sdcc] / src / z80 / mappings.i
index 53c593385fbc7f578fb74f3d5f5766da2036b23b..43d29afbb726fe089754411a2395c5ca127c33c1 100644 (file)
@@ -3,26 +3,32 @@ static const ASM_MAPPING _asxxxx_gb_mapping[] = {
     { "area", ".area _%s" },
     { "areacode", ".area _%s" },
     { "areadata", ".area _%s" },
+    { "areahome", ".area _%s" },
     { "functionlabeldef", "%s:" },
     { "*hl", "(hl)" },
     { "di", "di" },
+    { "ei", "ei" },
     { "ldahli", "ld a,(hl+)" },
     { "ldahlsp", "lda hl,%d(sp)" },
     { "ldaspsp", "lda sp,%d(sp)" },
     { "*pair", "(%s)" },
     { "shortjp", "jr" },
-    { "enter", "push bc" },
+    { "enter", "" },
     { "enterx", 
-      "push bc\n"
-      "\tlda sp,-%d(sp)" },
-    { "leave", 
-      "pop bc\n"
-      "\tret"
+      "lda sp,-%d(sp)" },
+    { "enterxl",
+                "ld hl,#-%d\n"
+                "\tadd\thl,sp\n"
+                "\tld\tsp,hl"
     },
-    { "leavex", 
-      "lda sp,%d(sp)\n"
-      "\tpop bc\n"
-      "\tret"
+    { "leave", ""
+    },
+    { "leavex", "lda sp,%d(sp)"
+    },
+    { "leavexl",
+                "ld hl,#%d\n"
+                "\tadd\thl,sp\n"
+                "\tld\tsp,hl"
     },
     { "pusha", 
       "push af\n"
@@ -30,45 +36,96 @@ static const ASM_MAPPING _asxxxx_gb_mapping[] = {
       "\tpush de\n"
       "\tpush hl"
     },
+    { "popa", 
+      "pop hl\n"
+      "\tpop de\n"
+      "\tpop bc\n"
+      "\tpop af"
+    },
     { "adjustsp", "lda sp,-%d(sp)" },
+    { "fileprelude", "" },
+    { "profileenter",
+                "ld a,#3\n"
+                "\trst\t0x08"
+    },
+    { "profileexit",
+                "ld a,#4\n"
+                "\trst\t0x08"
+    },
     { NULL, NULL }
 };
 
 static const ASM_MAPPING _asxxxx_z80_mapping[] = {
-    { "*ixx", "%d(ix)" },
-    { "*iyx", "%d(iy)" },
+    /* We want to prepend the _ */
+    { "area", ".area _%s" },
+    { "areacode", ".area _%s" },
+    { "areadata", ".area _%s" },
+    { "areahome", ".area _%s" },
+    { "*ixx", "%d (ix)" },
+    { "*iyx", "%d (iy)" },
     { "*hl", "(hl)" },
     { "di", "di" },
-    { "ldahli", "ld a,(hl+)" },
-    { "ldahlsp", "lda hl,%d(sp)" },
-    { "ldaspsp", "lda sp,%d(sp)" },
+    { "ei", "ei" },
+    { "ldahli", 
+               "ld a,(hl)\n"
+               "\tinc\thl" },
+    { "ldahlsp", 
+               "ld hl,#%d\n"
+               "\tadd\thl,sp" },
+    { "ldaspsp", 
+               "ld hl,#%d\n"
+               "\tadd\thl,sp\n"
+               "\tld\tsp,hl" },
     { "*pair", "(%s)" },
-    { "shortjp", "jr" },
-    { "enter", "push bc" },
+    { "shortjp", "jp" },
+    { "enter", 
+               "push\tix\n"
+               "\tld\tix,#0\n"
+               "\tadd\tix,sp" },
     { "enterx", 
-      "push bc\n"
-      "lda sp,-%d(sp)" },
+               "push\tix\n"
+               "\tld\tix,#0\n"
+               "\tadd\tix,sp\n"
+               "\tld\thl,#-%d\n"
+               "\tadd\thl,sp\n"
+               "\tld\tsp,hl" 
+        },
     { "leave", 
-      "pop bc\n"
-      "\tret"
+               "pop\tix"
     },
     { "leavex", 
-      "lda sp,%d(sp)\n"
-      "\tpop bc\n"
-      "\tret"
+               "ld sp,ix\n"
+               "\tpop\tix"
     },
     { "pusha", 
-      "push af\n"
-      "\tpush bc\n"
-      "\tpush de\n"
-      "\tpush hl"
+               "push af\n"
+               "\tpush\tbc\n"
+               "\tpush\tde\n"
+               "\tpush\thl\n"
+               "\tpush\tiy"
+    },
+    { "popa",
+               "pop iy\n"
+               "\tpop\thl\n"
+               "\tpop\tde\n"
+               "\tpop\tbc\n"
+               "\tpop\taf"
     },
     { "adjustsp", "lda sp,-%d(sp)" },
+    { "profileenter",
+                "ld a,#3\n"
+                "\trst\t0x08"
+    },
+    { "profileexit",
+                "ld a,#4\n"
+                "\trst\t0x08"
+    },
     { NULL, NULL }
 };
 
 static const ASM_MAPPING _rgbds_mapping[] = {
     { "global", "GLOBAL %s" },
+    { "extern", "GLOBAL %s" },
     { "slabeldef", "%s:" },
     { "labeldef", "%s:" },
     { "tlabeldef", ".l%05d:" },
@@ -78,8 +135,7 @@ static const ASM_MAPPING _rgbds_mapping[] = {
       "\t; We have to define these here as sdcc dosnt make them global by default\n"
       "\tGLOBAL __mulschar\n"
       "\tGLOBAL __muluchar\n"
-      "\tGLOBAL __mulsint\n"
-      "\tGLOBAL __muluint\n"
+      "\tGLOBAL __mulint\n"
       "\tGLOBAL __divschar\n"
       "\tGLOBAL __divuchar\n"
       "\tGLOBAL __divsint\n"
@@ -87,7 +143,12 @@ static const ASM_MAPPING _rgbds_mapping[] = {
       "\tGLOBAL __modschar\n"
       "\tGLOBAL __moduchar\n"
       "\tGLOBAL __modsint\n"
-      "\tGLOBAL __moduint"
+      "\tGLOBAL __moduint\n"
+      "\tGLOBAL __mullong\n"  
+      "\tGLOBAL __modslong\n"  
+      "\tGLOBAL __divslong\n"  
+      "\tGLOBAL banked_call\n"
+      "\tGLOBAL banked_ret\n"
     },
     { "functionheader", 
       "; ---------------------------------\n"
@@ -97,14 +158,15 @@ static const ASM_MAPPING _rgbds_mapping[] = {
     { "functionlabeldef", "%s:" },
     { "zero", "$00" },
     { "one", "$01" },
-    { "area", "SECTION \"%s\",%C" },
-    { "areacode", "SECTION \"CODE\",%C" },
-    { "areadata", "SECTION \"DATA\",BSS" },
+    { "area", "SECTION \"%s\",CODE" },
+    { "areadata", "SECTION \"%F_%s\",BSS" },
+    { "areacode", "SECTION \"%F_CODE\",%s" }, 
+    { "areahome", "SECTION \"%F_HOME\",HOME" },
     { "ascii", "DB \"%s\"" },
     { "ds", "DS %d" },
-    { "db", "DB %d" },
+    { "db", "DB" },
     { "dbs", "DB %s" },
-    { "dw", "DW %d" },
+    { "dw", "DW" },
     { "dws", "DW %s" },
     { "immed", "" },
     { "constbyte", "$%02X" },
@@ -114,6 +176,7 @@ static const ASM_MAPPING _rgbds_mapping[] = {
     { "hashedstr", "%s" },
     { "lsbimmeds", "%s & $FF" },
     { "msbimmeds", "%s >> 8" },
+    { "bankimmeds", "BANK(%s)" },
     { "module", "; MODULE %s" },
     { NULL, NULL }
 };
@@ -125,21 +188,21 @@ static const ASM_MAPPING _rgbds_gb_mapping[] = {
       "\tpush de\n"
       "\tpush hl"
     },
+    { "popa", 
+      "pop hl\n"
+      "\tpop de\n"
+      "\tpop bc\n"
+      "\tpop af"
+    },
     { "di", "di" },
+    { "ei", "ei" },
     { "adjustsp", "add sp,-%d" },
-    { "enter", "push bc" },
-    { "enterx", 
-      "push bc\n"
-      "\tadd sp,-%d"
+    { "enter", "" },
+    { "enterx", "add sp,-%d"
     },
-    { "leave", 
-      "pop bc\n"
-      "\tret"
+    { "leave", ""
     },
-    { "leavex", 
-      "add sp,%d\n"
-      "\tpop bc\n"
-      "\tret"
+    { "leavex", "add sp,%d"
     },
     { "ldahli", "ld a,[hl+]" },
     { "*hl", "[hl]" },
@@ -152,6 +215,7 @@ static const ASM_MAPPING _rgbds_gb_mapping[] = {
 
 static const ASM_MAPPING _isas_mapping[] = {
     { "global", "GLOBAL %s" },
+    { "extern", "GLOBAL %s" },
     { "slabeldef", "%s:" },
     { "labeldef", "%s:" },
     { "tlabeldef", "?l%05d:" },
@@ -163,11 +227,10 @@ static const ASM_MAPPING _isas_mapping[] = {
       "\tCAPSOFF      ; Case sensitive\n"
       "\tISDMG        ; Gameboy mode\n"
       "_CODE\tGROUP\n"
-      "\t; We have to define these here as sdcc dosnt make them global by default\n"
+      "\t; We have to define these here as sdcc doesnt make them global by default\n"
       "\tGLOBAL __mulschar\n"
       "\tGLOBAL __muluchar\n"
-      "\tGLOBAL __mulsint\n"
-      "\tGLOBAL __muluint\n"
+      "\tGLOBAL __mulint\n"
       "\tGLOBAL __divschar\n"
       "\tGLOBAL __divuchar\n"
       "\tGLOBAL __divsint\n"
@@ -175,7 +238,9 @@ static const ASM_MAPPING _isas_mapping[] = {
       "\tGLOBAL __modschar\n"
       "\tGLOBAL __moduchar\n"
       "\tGLOBAL __modsint\n"
-      "\tGLOBAL __moduint"
+      "\tGLOBAL __moduint\n"
+      "\tGLOBAL banked_call\n"
+      "\tGLOBAL banked_ret\n"
     },
     { "functionheader", 
       "; ---------------------------------\n"
@@ -188,11 +253,12 @@ static const ASM_MAPPING _isas_mapping[] = {
     { "area", "%s\tGROUP" },
     { "areacode", "_CODE\tGROUP" },
     { "areadata", "_DATA\tGROUP" },
+    { "areahome", "_CODE\tGROUP" },
     { "ascii", "DB \"%s\"" },
     { "ds", "DS %d" },
-    { "db", "DB %d" },
+    { "db", "DB" },
     { "dbs", "DB %s" },
-    { "dw", "DW %d" },
+    { "dw", "DW" },
     { "dws", "DW %s" },
     { "immed", "" },
     { "constbyte", "0x%02X" },
@@ -202,6 +268,7 @@ static const ASM_MAPPING _isas_mapping[] = {
     { "hashedstr", "%s" },
     { "lsbimmeds", "%s & 0xFF" },
     { "msbimmeds", "%s >> 8" },
+    { "bankimmeds", "!%s" },
     { "module", "; MODULE %s" },
     { NULL, NULL }
 };
@@ -213,22 +280,21 @@ static const ASM_MAPPING _isas_gb_mapping[] = {
       "\tpush de\n"
       "\tpush hl"
     },
+    { "popa", 
+      "pop hl\n"
+      "\tpop de\n"
+      "\tpop bc\n"
+      "\tpop af"
+    },
     { "di", "di" },
+    { "ei", "ei" },
     { "adjustsp", "add sp,-%d" },
-    { "enter", "push bc" },
-    { "enterx", 
-      "push bc\n"
-      "\tadd sp,-%d"
-    },
-    { "leave", 
-      "pop bc\n"
-      "\tret"
+    { "enter", "" },
+    { "enterx", "add sp,-%d"
     },
-    { "leavex", 
-      "add sp,%d\n"
-      "\tpop bc\n"
-      "\tret"
+    { "leave", ""
     },
+    { "leavex", "add sp,%d\n" },
     { "ldahli", "ld a,(hli)" },
     { "*hl", "(hl)" },
     { "ldahlsp", "ldhl sp,%d" },
@@ -238,6 +304,125 @@ static const ASM_MAPPING _isas_gb_mapping[] = {
     { NULL, NULL }
 };
 
+static const ASM_MAPPING _z80asm_mapping[] = {
+    { "global", "XDEF %s" },
+    { "extern", "XREF %s" },
+    { "slabeldef", "\n.%s" },
+    { "labeldef", "\n.%s" },
+    { "tlabeldef", "\n.l%N%05d" },
+    { "tlabel", "l%N%05d" },
+    { "fileprelude", 
+        "; Generated using the z80asm/z88 tokens.\n"
+        "\tXREF __muluchar_rrx_s\n"
+        "\tXREF __mulschar_rrx_s\n"
+        "\tXREF __mulint_rrx_s\n"
+        "\tXREF __mullong_rrx_s\n"
+        "\tXREF __divuchar_rrx_s\n"
+        "\tXREF __divschar_rrx_s\n"
+        "\tXREF __divsint_rrx_s\n"
+        "\tXREF __divuint_rrx_s\n"
+        "\tXREF __divulong_rrx_s\n"
+        "\tXREF __divslong_rrx_s\n"
+        "\tXREF __rrulong_rrx_s\n"
+        "\tXREF __rrslong_rrx_s\n"
+        "\tXREF __rlulong_rrx_s\n"
+        "\tXREF __rlslong_rrx_s\n"
+    },
+    { "functionheader", 
+      "; ---------------------------------\n"
+      "; Function %s\n"
+      "; ---------------------------------"
+    },
+    { "functionlabeldef", ".%s" },
+    { "zero", "$00" },
+    { "one", "$01" },
+    { "ascii", "DEFM \"%s\"" },
+    { "ds", "DEFS %d" },
+    { "db", "DEFB" },
+    { "dbs", "DEFB %s" },
+    { "dw", "DEFW" },
+    { "dws", "DEFB %s" },
+    { "immed", "" },
+    { "constbyte", "$%02X" },
+    { "constword", "$%04X" },
+    { "immedword", "$%04X" },
+    { "immedbyte", "$%02X" },
+    { "hashedstr", "%s" },
+    { "lsbimmeds", "%s & $FF" },
+    { "msbimmeds", "%s / 256" },
+
+    { "bankimmeds", "BANK(%s)" },
+    { "module", "MODULE %s" },
+    { "area", "; Area  %s" },
+    { "areadata", "; Aread BSS" },
+    { "areacode", "; Area CODE" }, 
+    { "areahome", "; Area HOME" },
+    { NULL, NULL }
+};
+
+static const ASM_MAPPING _z80asm_z80_mapping[] = {
+    { "*ixx", "(ix%+d)" },
+    { "*iyx", "(iy%+d)" },
+    { "*hl", "(hl)" },
+    { "di", "di" },
+    { "ei", "ei" },
+    { "ldahli", 
+               "ld a,(hl)\n"
+               "\tinc\thl" },
+    { "ldahlsp", 
+               "ld hl,%d\n"
+               "\tadd\thl,sp" },
+    { "ldaspsp", 
+               "ld hl,%d\n"
+               "\tadd\thl,sp\n"
+               "\tld\tsp,hl" },
+    { "*pair", "(%s)" },
+    { "shortjp", "jp" },
+    { "enter", 
+               "push\tix\n"
+               "\tld\tix,0\n"
+               "\tadd\tix,sp" },
+    { "enterx", 
+               "push\tix\n"
+               "\tld\tix,0\n"
+               "\tadd\tix,sp\n"
+               "\tld\thl,-%d\n"
+               "\tadd\thl,sp\n"
+               "\tld\tsp,hl" 
+        },
+    { "leave", 
+               "pop\tix"
+    },
+    { "leavex", 
+               "ld sp,ix\n"
+               "\tpop\tix"
+    },
+    { "pusha", 
+               "push af\n"
+               "\tpush\tbc\n"
+               "\tpush\tde\n"
+               "\tpush\thl\n"
+               "\tpush\tiy"
+    },
+    { "popa", 
+               "pop\tiy\n"
+               "\tpop\thl\n"
+               "\tpop\tde\n"
+               "\tpop\tbc\n"
+               "\tpop\taf"
+    },
+    { "adjustsp", "lda sp,(sp%+d)" },
+    { "profileenter",
+                "ld a,3\n"
+                "\trst\t$08"
+    },
+    { "profileexit",
+                "ld a,4\n"
+                "\trst\t$08"
+    },
+    { NULL, NULL }
+};
+
 static const ASM_MAPPINGS _isas = {
     NULL,
     _isas_mapping
@@ -267,3 +452,13 @@ const ASM_MAPPINGS _asxxxx_z80 = {
     &asm_asxxxx_mapping,
     _asxxxx_z80_mapping
 };
+
+static const ASM_MAPPINGS _z80asm = {
+    NULL,
+    _z80asm_mapping
+};
+
+const ASM_MAPPINGS _z80asm_z80 = {
+    &_z80asm,
+    _z80asm_z80_mapping
+};