5 static char _z80_defaultRules[] =
8 #include "peeph-z80.rul"
11 static char _gbz80_defaultRules[] =
14 #include "peeph-gbz80.rul"
34 static char *_keywords[] =
42 extern PORT gbz80_port;
50 z80_opts.sub = SUB_Z80;
51 asm_addTree (&_asxxxx_z80);
57 z80_opts.sub = SUB_GBZ80;
60 static int regParmFlg = 0; /* determine if we can register a parameter */
69 _reg_parm (sym_link * l)
79 _startsWith (const char *sz, const char *key)
81 return !strncmp (sz, key, strlen (key));
88 while ((nl = strrchr (sz, '\n')))
93 _process_pragma (const char *sz)
95 if (_startsWith (sz, "bank="))
98 strcpy (buffer, sz + 5);
100 if (isdigit (buffer[0]))
104 else if (!strcmp (buffer, "BASE"))
106 strcpy (buffer, "HOME");
108 if (isdigit (buffer[0]))
110 /* Arg was a bank number. Handle in an ASM independent
113 strcpy (num, sz + 5);
118 case ASM_TYPE_ASXXXX:
119 sprintf (buffer, "CODE_%s", num);
122 sprintf (buffer, "CODE,BANK[%s]", num);
125 /* PENDING: what to use for ISAS? */
126 sprintf (buffer, "CODE,BANK(%s)", num);
132 gbz80_port.mem.code_name = gc_strdup (buffer);
133 code->sname = gbz80_port.mem.code_name;
139 static const char *_gbz80_rgbasmCmd[] =
141 "rgbasm", "-o$1.o", "$1.asm", NULL
144 static const char *_gbz80_rgblinkCmd[] =
146 "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
150 _gbz80_rgblink (void)
160 /* first we need to create the <filename>.lnk file */
161 sprintf (scratchFileName, "%s.lnk", sz);
162 if (!(lnkfile = fopen (scratchFileName, "w")))
164 werror (E_FILE_OPEN_ERR, scratchFileName);
168 fprintf (lnkfile, "[Objects]\n");
171 fprintf (lnkfile, "%s.o\n", sz);
173 for (i = 0; i < nrelFiles; i++)
174 fprintf (lnkfile, "%s\n", relFiles[i]);
176 fprintf (lnkfile, "\n[Libraries]\n");
177 /* additional libraries if any */
178 for (i = 0; i < nlibFiles; i++)
179 fprintf (lnkfile, "%s\n", libFiles[i]);
182 fprintf (lnkfile, "\n[Output]\n" "%s.gb", sz);
186 buildCmdLine (buffer,port->linker.cmd, sz, NULL, NULL, NULL);
187 /* call the linker */
188 if (my_system (buffer))
190 perror ("Cannot exec linker");
196 _parseOptions (int *pargc, char **argv, int *i)
198 if (argv[*i][0] == '-')
200 if (argv[*i][1] == 'b' && IS_GB)
202 int bank = atoi (argv[*i] + 3);
208 sprintf (buffer, "CODE_%u", bank);
209 gbz80_port.mem.code_name = gc_strdup (buffer);
213 sprintf (buffer, "DATA_%u", bank);
214 gbz80_port.mem.data_name = gc_strdup (buffer);
218 else if (!strncmp (argv[*i], "--asm=", 6))
220 if (!strcmp (argv[*i], "--asm=rgbds"))
222 asm_addTree (&_rgbds_gb);
223 gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
224 gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
225 gbz80_port.linker.do_link = _gbz80_rgblink;
226 _G.asmType = ASM_TYPE_RGBDS;
229 else if (!strcmp (argv[*i], "--asm=asxxxx"))
231 _G.asmType = ASM_TYPE_ASXXXX;
234 else if (!strcmp (argv[*i], "--asm=isas"))
236 asm_addTree (&_isas_gb);
237 /* Munge the function prefix */
238 gbz80_port.fun_prefix = "";
239 _G.asmType = ASM_TYPE_ISAS;
248 _finaliseOptions (void)
250 port->mem.default_local_map = data;
251 port->mem.default_globl_map = data;
252 if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB)
253 asm_addTree (&_asxxxx_gb);
257 _setDefaultOptions (void)
259 options.genericPtr = 1; /* default on */
261 options.stackAuto = 1;
262 options.mainreturn = 1;
263 /* first the options part */
264 options.intlong_rent = 1;
266 optimize.global_cse = 1;
271 optimize.loopInvariant = 1;
272 optimize.loopInduction = 0;
276 _getRegName (struct regs *reg)
284 /** $1 is always the basename.
285 $2 is always the output file.
287 $l is the list of extra options that should be there somewhere...
288 MUST be terminated with a NULL.
290 static const char *_z80_linkCmd[] =
292 "link-z80", "-nf", "$1", NULL
295 static const char *_z80_asmCmd[] =
297 "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
300 /** $1 is always the basename.
301 $2 is always the output file.
303 $l is the list of extra options that should be there somewhere...
304 MUST be terminated with a NULL.
306 static const char *_gbz80_linkCmd[] =
308 "link-gbz80", "-nf", "$1", NULL
311 static const char *_gbz80_asmCmd[] =
313 "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
321 "Zilog Z80", /* Target name */
324 MODEL_MEDIUM | MODEL_SMALL,
329 "-plosgff", /* Options with debug */
330 "-plosgff", /* Options without debug */
343 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
344 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
366 /* Z80 has no native mul/div commands */
378 0, /* no assembler preamble */
379 0, /* no local IVT generation code */
386 1, /* transform <= to ! > */
387 1, /* transform >= to ! < */
388 1, /* transform != to !(a == b) */
398 "Gameboy Z80-like", /* Target name */
401 MODEL_MEDIUM | MODEL_SMALL,
406 "-plosgff", /* Options with debug */
407 "-plosgff", /* Options without debug */
420 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
421 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
443 /* gbZ80 has no native mul/div commands */
455 0, /* no assembler preamble */
456 0, /* no local IVT generation code */
463 1, /* transform <= to ! > */
464 1, /* transform >= to ! < */
465 1, /* transform != to !(a == b) */