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[] =
293 "-n", // Don't echo output
294 "-c", // Command line input
295 "--", // Again, command line input...
296 "-b_CODE=0x200", // Code starts at 0x200
297 "-b_DATA=0x8000", // RAM starts at 0x8000
298 "-j", // Output a symbol file as well
299 "-k" SDCC_LIB_DIR "/z80", // Library path
300 "-lz80.lib", // Library to use
301 "-i", // Output Intel IHX
302 "$1.ihx", // Output to
303 SDCC_LIB_DIR "/z80/crt0.o", // Link in crt0 first
304 "$1.o", // Actual code
308 static const char *_z80_asmCmd[] =
310 "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
313 /** $1 is always the basename.
314 $2 is always the output file.
316 $l is the list of extra options that should be there somewhere...
317 MUST be terminated with a NULL.
319 static const char *_gbz80_linkCmd[] =
322 "link-gbz80", "-nf", "$1", NULL
325 static const char *_gbz80_asmCmd[] =
327 "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
335 "Zilog Z80", /* Target name */
338 MODEL_MEDIUM | MODEL_SMALL,
343 "-plosgff", /* Options with debug */
344 "-plosgff", /* Options without debug */
357 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
358 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
380 /* Z80 has no native mul/div commands */
392 0, /* no assembler preamble */
393 0, /* no local IVT generation code */
400 1, /* transform <= to ! > */
401 1, /* transform >= to ! < */
402 1, /* transform != to !(a == b) */
412 "Gameboy Z80-like", /* Target name */
415 MODEL_MEDIUM | MODEL_SMALL,
420 "-plosgff", /* Options with debug */
421 "-plosgff", /* Options without debug */
434 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
435 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
457 /* gbZ80 has no native mul/div commands */
469 0, /* no assembler preamble */
470 0, /* no local IVT generation code */
477 1, /* transform <= to ! > */
478 1, /* transform >= to ! < */
479 1, /* transform != to !(a == b) */