* src/z80/main.c: enabled "critical" keyword
[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     { "enterxl",
19                 "ld hl,#-%d\n"
20                 "\tadd\thl,sp\n"
21                 "\tld\tsp,hl"
22     },
23     { "leave", ""
24     },
25     { "leavex", "lda sp,%d(sp)"
26     },
27     { "leavexl",
28                 "ld hl,#%d\n"
29                 "\tadd\thl,sp\n"
30                 "\tld\tsp,hl"
31     },
32     { "pusha", 
33       "push af\n"
34       "\tpush bc\n"
35       "\tpush de\n"
36       "\tpush hl"
37     },
38     { "popa", 
39       "pop hl\n"
40       "\tpop de\n"
41       "\tpop bc\n"
42       "\tpop af"
43     },
44     { "adjustsp", "lda sp,-%d(sp)" },
45     { "fileprelude", "" },
46     { "profileenter",
47                 "ld a,#3\n"
48                 "\trst\t0x08"
49     },
50     { "profileexit",
51                 "ld a,#4\n"
52                 "\trst\t0x08"
53     },
54     { NULL, NULL }
55 };
56
57 static const ASM_MAPPING _asxxxx_z80_mapping[] = {
58     /* We want to prepend the _ */
59     { "area", ".area _%s" },
60     { "areacode", ".area _%s" },
61     { "areadata", ".area _%s" },
62     { "areahome", ".area _%s" },
63     { "*ixx", "%d(ix)" },
64     { "*iyx", "%d(iy)" },
65     { "*hl", "(hl)" },
66     { "di", "di" },
67     { "ldahli", 
68                 "ld a,(hl)\n"
69                 "\tinc\thl" },
70     { "ldahlsp", 
71                 "ld hl,#%d\n"
72                 "\tadd\thl,sp" },
73     { "ldaspsp", 
74                 "ld hl,#%d\n"
75                 "\tadd\thl,sp\n"
76                 "\tld\tsp,hl" },
77     { "*pair", "(%s)" },
78     { "shortjp", "jp" },
79     { "enter", 
80                 "push\tix\n"
81                 "\tld\tix,#0\n"
82                 "\tadd\tix,sp" },
83     { "enterx", 
84                 "push\tix\n"
85                 "\tld\tix,#0\n"
86                 "\tadd\tix,sp\n"
87                 "\tld\thl,#-%d\n"
88                 "\tadd\thl,sp\n"
89                 "\tld\tsp,hl" 
90         },
91     { "leave", 
92                 "pop\tix"
93     },
94     { "leavex", 
95                 "ld sp,ix\n"
96                 "\tpop\tix"
97     },
98     { "pusha", 
99                 "push af\n"
100                 "\tpush\tbc\n"
101                 "\tpush\tde\n"
102                 "\tpush\thl\n"
103                 "\tpush\tiy"
104     },
105     { "popa",
106                 "pop iy\n"
107                 "\tpop\thl\n"
108                 "\tpop\tde\n"
109                 "\tpop\tbc\n"
110                 "\tpop\taf"
111     },
112     { "adjustsp", "lda sp,-%d(sp)" },
113     { "profileenter",
114                 "ld a,#3\n"
115                 "\trst\t0x08"
116     },
117     { "profileexit",
118                 "ld a,#4\n"
119                 "\trst\t0x08"
120     },
121     { NULL, NULL }
122 };
123
124 static const ASM_MAPPING _rgbds_mapping[] = {
125     { "global", "GLOBAL %s" },
126     { "extern", "GLOBAL %s" },
127     { "slabeldef", "%s:" },
128     { "labeldef", "%s:" },
129     { "tlabeldef", ".l%05d:" },
130     { "tlabel", ".l%05d" },
131     { "fileprelude", 
132       "; Generated using the rgbds tokens.\n"
133       "\t; We have to define these here as sdcc dosnt make them global by default\n"
134       "\tGLOBAL __mulschar\n"
135       "\tGLOBAL __muluchar\n"
136       "\tGLOBAL __mulint\n"
137       "\tGLOBAL __divschar\n"
138       "\tGLOBAL __divuchar\n"
139       "\tGLOBAL __divsint\n"
140       "\tGLOBAL __divuint\n"
141       "\tGLOBAL __modschar\n"
142       "\tGLOBAL __moduchar\n"
143       "\tGLOBAL __modsint\n"
144       "\tGLOBAL __moduint\n"
145       "\tGLOBAL __mullong\n"  
146       "\tGLOBAL __modslong\n"  
147       "\tGLOBAL __divslong\n"  
148       "\tGLOBAL banked_call\n"
149       "\tGLOBAL banked_ret\n"
150     },
151     { "functionheader", 
152       "; ---------------------------------\n"
153       "; Function %s\n"
154       "; ---------------------------------"
155     },
156     { "functionlabeldef", "%s:" },
157     { "zero", "$00" },
158     { "one", "$01" },
159     { "area", "SECTION \"%s\",CODE" },
160     { "areadata", "SECTION \"%F_%s\",BSS" },
161     { "areacode", "SECTION \"%F_CODE\",%s" }, 
162     { "areahome", "SECTION \"%F_HOME\",HOME" },
163     { "ascii", "DB \"%s\"" },
164     { "ds", "DS %d" },
165     { "db", "DB" },
166     { "dbs", "DB %s" },
167     { "dw", "DW" },
168     { "dws", "DW %s" },
169     { "immed", "" },
170     { "constbyte", "$%02X" },
171     { "constword", "$%04X" },
172     { "immedword", "$%04X" },
173     { "immedbyte", "$%02X" },
174     { "hashedstr", "%s" },
175     { "lsbimmeds", "%s & $FF" },
176     { "msbimmeds", "%s >> 8" },
177     { "bankimmeds", "BANK(%s)" },
178     { "module", "; MODULE %s" },
179     { NULL, NULL }
180 };
181
182 static const ASM_MAPPING _rgbds_gb_mapping[] = {
183     { "pusha", 
184       "push af\n"
185       "\tpush bc\n"
186       "\tpush de\n"
187       "\tpush hl"
188     },
189     { "popa", 
190       "pop hl\n"
191       "\tpop de\n"
192       "\tpop bc\n"
193       "\tpop af"
194     },
195     { "di", "di" },
196     { "adjustsp", "add sp,-%d" },
197     { "enter", "" },
198     { "enterx", "add sp,-%d"
199     },
200     { "leave", ""
201     },
202     { "leavex", "add sp,%d"
203     },
204     { "ldahli", "ld a,[hl+]" },
205     { "*hl", "[hl]" },
206     { "ldahlsp", "ld hl,[sp+%d]" },
207     { "ldaspsp", "add sp,%d" },
208     { "*pair", "[%s]" },
209     { "shortjp", "jr" },
210     { NULL, NULL }
211 };
212
213 static const ASM_MAPPING _isas_mapping[] = {
214     { "global", "GLOBAL %s" },
215     { "extern", "GLOBAL %s" },
216     { "slabeldef", "%s:" },
217     { "labeldef", "%s:" },
218     { "tlabeldef", "?l%05d:" },
219     { "tlabel", "?l%05d" },
220     { "fileprelude", 
221       ";Generated using the isas tokens.\n"
222       "\tLPREFIX '?'  ; Treat labels starting with ? as local.\n"
223       "\tONCNUM       ; Numbers are hex\n"
224       "\tCAPSOFF      ; Case sensitive\n"
225       "\tISDMG        ; Gameboy mode\n"
226       "_CODE\tGROUP\n"
227       "\t; We have to define these here as sdcc doesnt make them global by default\n"
228       "\tGLOBAL __mulschar\n"
229       "\tGLOBAL __muluchar\n"
230       "\tGLOBAL __mulint\n"
231       "\tGLOBAL __divschar\n"
232       "\tGLOBAL __divuchar\n"
233       "\tGLOBAL __divsint\n"
234       "\tGLOBAL __divuint\n"
235       "\tGLOBAL __modschar\n"
236       "\tGLOBAL __moduchar\n"
237       "\tGLOBAL __modsint\n"
238       "\tGLOBAL __moduint\n"
239       "\tGLOBAL banked_call\n"
240       "\tGLOBAL banked_ret\n"
241     },
242     { "functionheader", 
243       "; ---------------------------------\n"
244       "; Function %s\n"
245       "; ---------------------------------"
246     },
247     { "functionlabeldef", "%s:" },
248     { "zero", "$00" },
249     { "one", "$01" },
250     { "area", "%s\tGROUP" },
251     { "areacode", "_CODE\tGROUP" },
252     { "areadata", "_DATA\tGROUP" },
253     { "areahome", "_CODE\tGROUP" },
254     { "ascii", "DB \"%s\"" },
255     { "ds", "DS %d" },
256     { "db", "DB" },
257     { "dbs", "DB %s" },
258     { "dw", "DW" },
259     { "dws", "DW %s" },
260     { "immed", "" },
261     { "constbyte", "0x%02X" },
262     { "constword", "0x%04X" },
263     { "immedword", "0x%04X" },
264     { "immedbyte", "0x%02X" },
265     { "hashedstr", "%s" },
266     { "lsbimmeds", "%s & 0xFF" },
267     { "msbimmeds", "%s >> 8" },
268     { "bankimmeds", "!%s" },
269     { "module", "; MODULE %s" },
270     { NULL, NULL }
271 };
272
273 static const ASM_MAPPING _isas_gb_mapping[] = {
274     { "pusha", 
275       "push af\n"
276       "\tpush bc\n"
277       "\tpush de\n"
278       "\tpush hl"
279     },
280     { "popa", 
281       "pop hl\n"
282       "\tpop de\n"
283       "\tpop bc\n"
284       "\tpop af"
285     },
286     { "di", "di" },
287     { "adjustsp", "add sp,-%d" },
288     { "enter", "" },
289     { "enterx", "add sp,-%d"
290     },
291     { "leave", ""
292     },
293     { "leavex", "add sp,%d\n" },
294     { "ldahli", "ld a,(hli)" },
295     { "*hl", "(hl)" },
296     { "ldahlsp", "ldhl sp,%d" },
297     { "ldaspsp", "add sp,%d" },
298     { "*pair", "(%s)" },
299     { "shortjp", "jr" },
300     { NULL, NULL }
301 };
302
303 static const ASM_MAPPING _z80asm_mapping[] = {
304     { "global", "XDEF %s" },
305     { "extern", "XREF %s" },
306     { "slabeldef", "\n.%s" },
307     { "labeldef", "\n.%s" },
308     { "tlabeldef", "\n.l%N%05d" },
309     { "tlabel", "l%N%05d" },
310     { "fileprelude", 
311         "; Generated using the z80asm/z88 tokens.\n"
312         "\tXREF __muluchar_rrx_s\n"
313         "\tXREF __mulschar_rrx_s\n"
314         "\tXREF __mulint_rrx_s\n"
315         "\tXREF __mullong_rrx_s\n"
316         "\tXREF __divuchar_rrx_s\n"
317         "\tXREF __divschar_rrx_s\n"
318         "\tXREF __divsint_rrx_s\n"
319         "\tXREF __divuint_rrx_s\n"
320         "\tXREF __divulong_rrx_s\n"
321         "\tXREF __divslong_rrx_s\n"
322         "\tXREF __rrulong_rrx_s\n"
323         "\tXREF __rrslong_rrx_s\n"
324         "\tXREF __rlulong_rrx_s\n"
325         "\tXREF __rlslong_rrx_s\n"
326     },
327     { "functionheader", 
328       "; ---------------------------------\n"
329       "; Function %s\n"
330       "; ---------------------------------"
331     },
332     { "functionlabeldef", ".%s" },
333     { "zero", "$00" },
334     { "one", "$01" },
335     { "ascii", "DEFM \"%s\"" },
336     { "ds", "DEFS %d" },
337     { "db", "DEFB" },
338     { "dbs", "DEFB %s" },
339     { "dw", "DEFW" },
340     { "dws", "DEFB %s" },
341     { "immed", "" },
342     { "constbyte", "$%02X" },
343     { "constword", "$%04X" },
344     { "immedword", "$%04X" },
345     { "immedbyte", "$%02X" },
346     { "hashedstr", "%s" },
347     { "lsbimmeds", "%s & $FF" },
348     { "msbimmeds", "%s / 256" },
349
350     { "bankimmeds", "BANK(%s)" },
351     { "module", "MODULE %s" },
352     { "area", "; Area  %s" },
353     { "areadata", "; Aread BSS" },
354     { "areacode", "; Area CODE" }, 
355     { "areahome", "; Area HOME" },
356     { NULL, NULL }
357 };
358
359 static const ASM_MAPPING _z80asm_z80_mapping[] = {
360     { "*ixx", "(ix%+d)" },
361     { "*iyx", "(iy%+d)" },
362     { "*hl", "(hl)" },
363     { "di", "di" },
364     { "ldahli", 
365                 "ld a,(hl)\n"
366                 "\tinc\thl" },
367     { "ldahlsp", 
368                 "ld hl,%d\n"
369                 "\tadd\thl,sp" },
370     { "ldaspsp", 
371                 "ld hl,%d\n"
372                 "\tadd\thl,sp\n"
373                 "\tld\tsp,hl" },
374     { "*pair", "(%s)" },
375     { "shortjp", "jp" },
376     { "enter", 
377                 "push\tix\n"
378                 "\tld\tix,0\n"
379                 "\tadd\tix,sp" },
380     { "enterx", 
381                 "push\tix\n"
382                 "\tld\tix,0\n"
383                 "\tadd\tix,sp\n"
384                 "\tld\thl,-%d\n"
385                 "\tadd\thl,sp\n"
386                 "\tld\tsp,hl" 
387         },
388     { "leave", 
389                 "pop\tix"
390     },
391     { "leavex", 
392                 "ld sp,ix\n"
393                 "\tpop\tix"
394     },
395     { "pusha", 
396                 "push af\n"
397                 "\tpush\tbc\n"
398                 "\tpush\tde\n"
399                 "\tpush\thl\n"
400                 "\tpush\tiy"
401     },
402     { "popa", 
403                 "pop\tiy\n"
404                 "\tpop\thl\n"
405                 "\tpop\tde\n"
406                 "\tpop\tbc\n"
407                 "\tpop\taf"
408     },
409     { "adjustsp", "lda sp,(sp%+d)" },
410     { "profileenter",
411                 "ld a,3\n"
412                 "\trst\t$08"
413     },
414     { "profileexit",
415                 "ld a,4\n"
416                 "\trst\t$08"
417     },
418     { NULL, NULL }
419 };
420
421 static const ASM_MAPPINGS _isas = {
422     NULL,
423     _isas_mapping
424 };
425
426 const ASM_MAPPINGS _isas_gb = {
427     &_isas,
428     _isas_gb_mapping
429 };
430
431 static const ASM_MAPPINGS _rgbds = {
432     NULL,
433     _rgbds_mapping
434 };
435
436 const ASM_MAPPINGS _rgbds_gb = {
437     &_rgbds,
438     _rgbds_gb_mapping
439 };
440
441 const ASM_MAPPINGS _asxxxx_gb = {
442     &asm_asxxxx_mapping,
443     _asxxxx_gb_mapping
444 };
445
446 const ASM_MAPPINGS _asxxxx_z80 = {
447     &asm_asxxxx_mapping,
448     _asxxxx_z80_mapping
449 };
450
451 static const ASM_MAPPINGS _z80asm = {
452     NULL,
453     _z80asm_mapping
454 };
455
456 const ASM_MAPPINGS _z80asm_z80 = {
457     &_z80asm,
458     _z80asm_z80_mapping
459 };