319afdd1190fe44d3e1a0878911cc15601fc7d86
[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\n" 
84         },
85     { "leave", 
86                 "pop\tix\n"
87     },
88     { "leavex", 
89                 "ld sp,ix\n"
90                 "\tpop\tix\n"
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     { "slabeldef", "%s:" },
113     { "labeldef", "%s:" },
114     { "tlabeldef", ".l%05d:" },
115     { "tlabel", ".l%05d" },
116     { "fileprelude", 
117       "; Generated using the rgbds tokens.\n"
118       "\t; We have to define these here as sdcc dosnt make them global by default\n"
119       "\tGLOBAL __mulschar\n"
120       "\tGLOBAL __muluchar\n"
121       "\tGLOBAL __mulsint\n"
122       "\tGLOBAL __muluint\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 __mulslong\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     { "slabeldef", "%s:" },
196     { "labeldef", "%s:" },
197     { "tlabeldef", "?l%05d:" },
198     { "tlabel", "?l%05d" },
199     { "fileprelude", 
200       ";Generated using the isas tokens.\n"
201       "\tLPREFIX '?'  ; Treat labels starting with ? as local.\n"
202       "\tONCNUM       ; Numbers are hex\n"
203       "\tCAPSOFF      ; Case sensitive\n"
204       "\tISDMG        ; Gameboy mode\n"
205       "_CODE\tGROUP\n"
206       "\t; We have to define these here as sdcc dosnt make them global by default\n"
207       "\tGLOBAL __mulschar\n"
208       "\tGLOBAL __muluchar\n"
209       "\tGLOBAL __mulsint\n"
210       "\tGLOBAL __muluint\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_MAPPINGS _isas = {
278     NULL,
279     _isas_mapping
280 };
281
282 const ASM_MAPPINGS _isas_gb = {
283     &_isas,
284     _isas_gb_mapping
285 };
286
287 static const ASM_MAPPINGS _rgbds = {
288     NULL,
289     _rgbds_mapping
290 };
291
292 const ASM_MAPPINGS _rgbds_gb = {
293     &_rgbds,
294     _rgbds_gb_mapping
295 };
296
297 const ASM_MAPPINGS _asxxxx_gb = {
298     &asm_asxxxx_mapping,
299     _asxxxx_gb_mapping
300 };
301
302 const ASM_MAPPINGS _asxxxx_z80 = {
303     &asm_asxxxx_mapping,
304     _asxxxx_z80_mapping
305 };