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