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 /* Default code and data locations. */
267 options.code_loc = 0x200;
268 options.data_loc = 0x8000;
270 optimize.global_cse = 1;
275 optimize.loopInvariant = 1;
276 optimize.loopInduction = 0;
280 _getRegName (struct regs *reg)
288 /** $1 is always the basename.
289 $2 is always the output file.
291 $l is the list of extra options that should be there somewhere...
292 MUST be terminated with a NULL.
294 static const char *_z80_linkCmd[] =
297 "-n", // Don't echo output
298 "-c", // Command line input
299 "--", // Again, command line input...
300 "-b_CODE=0x200", // Code starts at 0x200
301 "-b_DATA=0x8000", // RAM starts at 0x8000
302 "-j", // Output a symbol file as well
303 "-k" SDCC_LIB_DIR "/z80", // Library path
304 "-lz80.lib", // Library to use
305 "-i", // Output Intel IHX
306 "$1.ihx", // Output to
307 SDCC_LIB_DIR "/z80/crt0.o", // Link in crt0 first
308 "$1.o", // Actual code
312 /* sprintf that appends to the string. */
314 _saprintf(char *pinto, const char *format, ...)
317 va_start(ap, format);
319 vsprintf(pinto + strlen(pinto), format, ap);
332 "-n " // Don't echo output
333 "-c " // Command line input
334 "-- " // Again, command line input...
335 "-b_CODE=0x%04X " // Code starts at 0x200
336 "-b_DATA=0x%04X " // RAM starts at 0x8000
337 "-j ", // Output a symbol file as well
342 // Add the standard lib in.
343 if (options.nostdlib == FALSE) {
345 "-k" SDCC_LIB_DIR "/z80 " // Library path
346 "-lz80.lib " // Library to use
350 // Add in the library paths and libraries
351 for (i = 0; i < nlibFiles; i++) {
352 _saprintf(buffer, "-k%s ", libFiles[i]);
354 for (i = 0; i < nlibPaths; i++) {
355 _saprintf(buffer, "-l%s ", libPaths[i]);
359 "-i " // Output Intel IHX
360 "%s.ihx ", // Output to
364 if (options.nostdlib == FALSE) {
366 SDCC_LIB_DIR "/z80/crt0.o " // Link in crt0 first
371 "%s.o ", // Actual code
375 // Append all the other targets
376 for (i = 0; i < nrelFiles; i++) {
377 _saprintf(buffer, "%s ", relFiles[i]);
381 if (my_system (buffer)) {
386 static const char *_z80_asmCmd[] =
388 "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
391 /** $1 is always the basename.
392 $2 is always the output file.
394 $l is the list of extra options that should be there somewhere...
395 MUST be terminated with a NULL.
397 static const char *_gbz80_linkCmd[] =
400 "link-gbz80", "-nf", "$1", NULL
403 static const char *_gbz80_asmCmd[] =
405 "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
413 "Zilog Z80", /* Target name */
416 MODEL_MEDIUM | MODEL_SMALL,
421 "-plosgff", /* Options with debug */
422 "-plosgff", /* Options without debug */
435 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
436 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
458 /* Z80 has no native mul/div commands */
470 0, /* no assembler preamble */
471 0, /* no local IVT generation code */
478 1, /* transform <= to ! > */
479 1, /* transform >= to ! < */
480 1, /* transform != to !(a == b) */
490 "Gameboy Z80-like", /* Target name */
493 MODEL_MEDIUM | MODEL_SMALL,
498 "-plosgff", /* Options with debug */
499 "-plosgff", /* Options without debug */
512 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
513 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
535 /* gbZ80 has no native mul/div commands */
547 0, /* no assembler preamble */
548 0, /* no local IVT generation code */
555 1, /* transform <= to ! > */
556 1, /* transform >= to ! < */
557 1, /* transform != to !(a == b) */