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