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