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