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