8727764106985639ff5f1556466722e2c09747aa
[fw/sdcc] / src / z80 / mappings.i
1 static const ASM_MAPPING _asxxxx_gb_mapping[] = {
2     /* We want to prepend the _ */
3     { "area", ".area _%s" },
4     { "areacode", ".area _%s" },
5     { "areadata", ".area _%s" },
6     { "areahome", ".area _%s" },
7     { "functionlabeldef", "%s:" },
8     { "*hl", "(hl)" },
9     { "di", "di" },
10     { "ldahli", "ld a,(hl+)" },
11     { "ldahlsp", "lda hl,%d(sp)" },
12     { "ldaspsp", "lda sp,%d(sp)" },
13     { "*pair", "(%s)" },
14     { "shortjp", "jr" },
15     { "enter", "" },
16     { "enterx", 
17       "lda sp,-%d(sp)" },
18     { "leave", ""
19     },
20     { "leavex", "lda sp,%d(sp)"
21     },
22     { "pusha", 
23       "push af\n"
24       "\tpush bc\n"
25       "\tpush de\n"
26       "\tpush hl"
27     },
28     { "adjustsp", "lda sp,-%d(sp)" },
29     { "fileprelude", "" },
30     { NULL, NULL }
31 };
32
33 static const ASM_MAPPING _asxxxx_z80_mapping[] = {
34     /* We want to prepend the _ */
35     { "area", ".area _%s" },
36     { "areacode", ".area _%s" },
37     { "areadata", ".area _%s" },
38     { "areahome", ".area _%s" },
39     { "*ixx", "%d(ix)" },
40     { "*iyx", "%d(iy)" },
41     { "*hl", "(hl)" },
42     { "di", "di" },
43     { "ldahli", 
44                 "ld a,(hl)\n"
45                 "\tinc\thl" },
46     { "ldahlsp", 
47                 "ld hl,#%d\n"
48                 "\tadd\thl,sp" },
49     { "ldaspsp", 
50                 "ld hl,#%d\n"
51                 "\tadd\thl,sp\n"
52                 "\tld\tsp,hl" },
53     { "*pair", "(%s)" },
54     { "shortjp", "jp" },
55     { "enter", 
56                 "push\tix\n"
57                 "\tld\tix,#0\n"
58                 "\tadd\tix,sp" },
59     { "enterx", 
60                 "push\tix\n"
61                 "\tld\tix,#0\n"
62                 "\tadd\tix,sp\n"
63                 "\tld\tb,h\n"
64                 "\tld\tc,l\n"
65                 "\tld\thl,#-%d\n"
66                 "\tadd\thl,sp\n"
67                 "\tld\tsp,hl\n" 
68                 "\tld\th,b\n"
69                 "\tld\tl,c"
70         },
71     { "leave", 
72                 "pop\tix\n"
73     },
74     { "leavex", 
75                 "ld sp,ix\n"
76                 "\tpop\tix\n"
77     },
78     { "pusha", 
79                 "push af\n"
80                 "\tpush\tbc\n"
81                 "\tpush\tde\n"
82                 "\tpush\thl"
83     },
84     { "adjustsp", "lda sp,-%d(sp)" },
85     { NULL, NULL }
86 };
87
88 static const ASM_MAPPING _rgbds_mapping[] = {
89     { "global", "GLOBAL %s" },
90     { "slabeldef", "%s:" },
91     { "labeldef", "%s:" },
92     { "tlabeldef", ".l%05d:" },
93     { "tlabel", ".l%05d" },
94     { "fileprelude", 
95       "; Generated using the rgbds tokens.\n"
96       "\t; We have to define these here as sdcc dosnt make them global by default\n"
97       "\tGLOBAL __mulschar\n"
98       "\tGLOBAL __muluchar\n"
99       "\tGLOBAL __mulsint\n"
100       "\tGLOBAL __muluint\n"
101       "\tGLOBAL __divschar\n"
102       "\tGLOBAL __divuchar\n"
103       "\tGLOBAL __divsint\n"
104       "\tGLOBAL __divuint\n"
105       "\tGLOBAL __modschar\n"
106       "\tGLOBAL __moduchar\n"
107       "\tGLOBAL __modsint\n"
108       "\tGLOBAL __moduint\n"
109       "\tGLOBAL __mulslong\n"  
110       "\tGLOBAL __modslong\n"  
111       "\tGLOBAL __divslong\n"  
112       "\tGLOBAL banked_call\n"
113       "\tGLOBAL banked_ret\n"
114     },
115     { "functionheader", 
116       "; ---------------------------------\n"
117       "; Function %s\n"
118       "; ---------------------------------"
119     },
120     { "functionlabeldef", "%s:" },
121     { "zero", "$00" },
122     { "one", "$01" },
123     { "area", "SECTION \"%s\",CODE" },
124     { "areadata", "SECTION \"%F_%s\",BSS" },
125     { "areacode", "SECTION \"%F_CODE\",%s" }, 
126     { "areahome", "SECTION \"%F_HOME\",HOME" },
127     { "ascii", "DB \"%s\"" },
128     { "ds", "DS %d" },
129     { "db", "DB" },
130     { "dbs", "DB %s" },
131     { "dw", "DW" },
132     { "dws", "DW %s" },
133     { "immed", "" },
134     { "constbyte", "$%02X" },
135     { "constword", "$%04X" },
136     { "immedword", "$%04X" },
137     { "immedbyte", "$%02X" },
138     { "hashedstr", "%s" },
139     { "lsbimmeds", "%s & $FF" },
140     { "msbimmeds", "%s >> 8" },
141     { "bankimmeds", "BANK(%s)" },
142     { "module", "; MODULE %s" },
143     { NULL, NULL }
144 };
145
146 static const ASM_MAPPING _rgbds_gb_mapping[] = {
147     { "pusha", 
148       "push af\n"
149       "\tpush bc\n"
150       "\tpush de\n"
151       "\tpush hl"
152     },
153     { "di", "di" },
154     { "adjustsp", "add sp,-%d" },
155     { "enter", "" },
156     { "enterx", "add sp,-%d"
157     },
158     { "leave", ""
159     },
160     { "leavex", "add sp,%d"
161     },
162     { "ldahli", "ld a,[hl+]" },
163     { "*hl", "[hl]" },
164     { "ldahlsp", "ld hl,[sp+%d]" },
165     { "ldaspsp", "add sp,%d" },
166     { "*pair", "[%s]" },
167     { "shortjp", "jr" },
168     { NULL, NULL }
169 };
170
171 static const ASM_MAPPING _isas_mapping[] = {
172     { "global", "GLOBAL %s" },
173     { "slabeldef", "%s:" },
174     { "labeldef", "%s:" },
175     { "tlabeldef", "?l%05d:" },
176     { "tlabel", "?l%05d" },
177     { "fileprelude", 
178       ";Generated using the isas tokens.\n"
179       "\tLPREFIX '?'  ; Treat labels starting with ? as local.\n"
180       "\tONCNUM       ; Numbers are hex\n"
181       "\tCAPSOFF      ; Case sensitive\n"
182       "\tISDMG        ; Gameboy mode\n"
183       "_CODE\tGROUP\n"
184       "\t; We have to define these here as sdcc dosnt make them global by default\n"
185       "\tGLOBAL __mulschar\n"
186       "\tGLOBAL __muluchar\n"
187       "\tGLOBAL __mulsint\n"
188       "\tGLOBAL __muluint\n"
189       "\tGLOBAL __divschar\n"
190       "\tGLOBAL __divuchar\n"
191       "\tGLOBAL __divsint\n"
192       "\tGLOBAL __divuint\n"
193       "\tGLOBAL __modschar\n"
194       "\tGLOBAL __moduchar\n"
195       "\tGLOBAL __modsint\n"
196       "\tGLOBAL __moduint\n"
197       "\tGLOBAL banked_call\n"
198       "\tGLOBAL banked_ret\n"
199     },
200     { "functionheader", 
201       "; ---------------------------------\n"
202       "; Function %s\n"
203       "; ---------------------------------"
204     },
205     { "functionlabeldef", "%s:" },
206     { "zero", "$00" },
207     { "one", "$01" },
208     { "area", "%s\tGROUP" },
209     { "areacode", "_CODE\tGROUP" },
210     { "areadata", "_DATA\tGROUP" },
211     { "areahome", "_CODE\tGROUP" },
212     { "ascii", "DB \"%s\"" },
213     { "ds", "DS %d" },
214     { "db", "DB" },
215     { "dbs", "DB %s" },
216     { "dw", "DW" },
217     { "dws", "DW %s" },
218     { "immed", "" },
219     { "constbyte", "0x%02X" },
220     { "constword", "0x%04X" },
221     { "immedword", "0x%04X" },
222     { "immedbyte", "0x%02X" },
223     { "hashedstr", "%s" },
224     { "lsbimmeds", "%s & 0xFF" },
225     { "msbimmeds", "%s >> 8" },
226     { "bankimmeds", "!%s" },
227     { "module", "; MODULE %s" },
228     { NULL, NULL }
229 };
230
231 static const ASM_MAPPING _isas_gb_mapping[] = {
232     { "pusha", 
233       "push af\n"
234       "\tpush bc\n"
235       "\tpush de\n"
236       "\tpush hl"
237     },
238     { "di", "di" },
239     { "adjustsp", "add sp,-%d" },
240     { "enter", "" },
241     { "enterx", "add sp,-%d"
242     },
243     { "leave", ""
244     },
245     { "leavex", "add sp,%d\n" },
246     { "ldahli", "ld a,(hli)" },
247     { "*hl", "(hl)" },
248     { "ldahlsp", "ldhl sp,%d" },
249     { "ldaspsp", "add sp,%d" },
250     { "*pair", "(%s)" },
251     { "shortjp", "jr" },
252     { NULL, NULL }
253 };
254
255 static const ASM_MAPPINGS _isas = {
256     NULL,
257     _isas_mapping
258 };
259
260 const ASM_MAPPINGS _isas_gb = {
261     &_isas,
262     _isas_gb_mapping
263 };
264
265 static const ASM_MAPPINGS _rgbds = {
266     NULL,
267     _rgbds_mapping
268 };
269
270 const ASM_MAPPINGS _rgbds_gb = {
271     &_rgbds,
272     _rgbds_gb_mapping
273 };
274
275 const ASM_MAPPINGS _asxxxx_gb = {
276     &asm_asxxxx_mapping,
277     _asxxxx_gb_mapping
278 };
279
280 const ASM_MAPPINGS _asxxxx_z80 = {
281     &asm_asxxxx_mapping,
282     _asxxxx_z80_mapping
283 };