3 static char _z80_defaultRules[] =
6 #include "peeph-z80.rul"
9 static char _gbz80_defaultRules[] =
12 #include "peeph-gbz80.rul"
28 static char *_keywords[] = {
35 extern PORT gbz80_port;
40 static void _z80_init(void)
42 z80_opts.sub = SUB_Z80;
43 asm_addTree(&_asxxxx_z80);
46 static void _gbz80_init(void)
48 z80_opts.sub = SUB_GBZ80;
51 static int regParmFlg = 0; /* determine if we can register a parameter */
53 static void _reset_regparm()
58 static int _reg_parm(link *l)
67 static bool _startsWith(const char *sz, const char *key)
69 return !strncmp(sz, key, strlen(key));
72 static void _chomp(char *sz)
75 while ((nl = strrchr(sz, '\n')))
79 static int _process_pragma(const char *sz)
81 if (_startsWith(sz, "bank=")) {
85 if (isdigit(buffer[0])) {
88 else if (!strcmp(buffer, "BASE")) {
89 strcpy(buffer, "HOME");
91 if (isdigit(buffer[0])) {
92 /* Arg was a bank number. Handle in an ASM independent
100 sprintf(buffer, "CODE_%s", num);
103 sprintf(buffer, "CODE,BANK[%s]", num);
106 /* PENDING: what to use for ISAS? */
107 sprintf(buffer, "CODE,BANK(%s)", num);
113 gbz80_port.mem.code_name = gc_strdup(buffer);
114 code->sname = gbz80_port.mem.code_name;
120 static const char *_gbz80_rgbasmCmd[] = {
121 "rgbasm", "-o$1.o", "$1.asm", NULL
124 static const char *_gbz80_rgblinkCmd[] = {
125 "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
128 static void _gbz80_rgblink(void)
139 /* first we need to create the <filename>.lnk file */
140 sprintf(buffer,"%s.lnk", sz);
141 if (!(lnkfile = fopen(buffer,"w"))) {
142 werror(E_FILE_OPEN_ERR, buffer);
146 fprintf(lnkfile, "[Objects]\n");
149 fprintf(lnkfile, "%s.o\n", sz);
151 for (i = 0 ; i < nrelFiles ; i++ )
152 fprintf (lnkfile,"%s\n",relFiles[i]);
154 fprintf(lnkfile, "\n[Libraries]\n");
155 /* additional libraries if any */
156 for (i = 0 ; i < nlibFiles; i++)
157 fprintf (lnkfile,"%s\n",libFiles[i]);
160 fprintf(lnkfile,"\n[Output]\n" "%s.gb",sz);
164 buildCmdLine(buffer, argv, port->linker.cmd, sz, NULL, NULL, NULL);
165 /* call the linker */
166 if (my_system(argv[0], argv)) {
167 perror("Cannot exec linker");
172 static bool _parseOptions(int *pargc, char **argv, int *i)
174 if (argv[*i][0] == '-') {
175 if (argv[*i][1] == 'b' && IS_GB) {
176 int bank = atoi(argv[*i] + 3);
178 switch (argv[*i][2]) {
181 sprintf(buffer, "CODE_%u", bank);
182 gbz80_port.mem.code_name = gc_strdup(buffer);
186 sprintf(buffer, "DATA_%u", bank);
187 gbz80_port.mem.data_name = gc_strdup(buffer);
191 else if (!strncmp(argv[*i], "--asm=", 6)) {
192 if (!strcmp(argv[*i], "--asm=rgbds")) {
193 asm_addTree(&_rgbds_gb);
194 gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
195 gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
196 gbz80_port.linker.do_link = _gbz80_rgblink;
197 _G.asmType = ASM_TYPE_RGBDS;
200 else if (!strcmp(argv[*i], "--asm=asxxxx")) {
201 _G.asmType = ASM_TYPE_ASXXXX;
204 else if (!strcmp(argv[*i], "--asm=isas")) {
205 asm_addTree(&_isas_gb);
206 /* Munge the function prefix */
207 gbz80_port.fun_prefix = "";
208 _G.asmType = ASM_TYPE_ISAS;
216 static void _finaliseOptions(void)
218 port->mem.default_local_map = data;
219 port->mem.default_globl_map = data;
220 if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB)
221 asm_addTree(&_asxxxx_gb);
224 static void _setDefaultOptions(void)
226 options.genericPtr = 1; /* default on */
228 options.stackAuto = 1;
229 options.mainreturn = 1;
230 options.noregparms = 1;
232 /* first the options part */
233 options.intlong_rent = 1;
235 optimize.global_cse = 1;
240 optimize.loopInvariant = 1;
241 optimize.loopInduction = 0;
244 static const char *_getRegName(struct regs *reg)
252 /** $1 is always the basename.
253 $2 is always the output file.
255 $l is the list of extra options that should be there somewhere...
256 MUST be terminated with a NULL.
258 static const char *_z80_linkCmd[] = {
259 "link-z80", "-nf", "$1", NULL
262 static const char *_z80_asmCmd[] = {
263 "as-z80", "-plosgff", "$1.asm", NULL
266 /** $1 is always the basename.
267 $2 is always the output file.
269 $l is the list of extra options that should be there somewhere...
270 MUST be terminated with a NULL.
272 static const char *_gbz80_linkCmd[] = {
273 "link-gbz80", "-nf", "$1", NULL
276 static const char *_gbz80_asmCmd[] = {
277 "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
283 "Zilog Z80", /* Target name */
286 MODEL_MEDIUM | MODEL_SMALL,
291 "-plosgff", /* Options with debug */
292 "-plosgff", /* Options without debug */
303 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
304 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
326 /* Z80 has no native mul/div commands */
338 0, /* no assembler preamble */
339 0, /* no local IVT generation code */
349 "Gameboy Z80-like", /* Target name */
352 MODEL_MEDIUM | MODEL_SMALL,
357 "-plosgff", /* Options with debug */
358 "-plosgff", /* Options without debug */
370 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
371 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
393 /* gbZ80 has no native mul/div commands */
405 0, /* no assembler preamble */
406 0, /* no local IVT generation code */