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