3 static char _z80_defaultRules[] =
6 #include "peeph-z80.rul"
9 static char _gbz80_defaultRules[] =
12 #include "peeph-gbz80.rul"
21 static char *_keywords[] = {
27 extern PORT gbz80_port;
32 static void _z80_init(void)
34 z80_opts.sub = SUB_Z80;
35 asm_addTree(&_asxxxx_z80);
38 static void _gbz80_init(void)
40 z80_opts.sub = SUB_GBZ80;
43 static int regParmFlg = 0; /* determine if we can register a parameter */
45 static void _reset_regparm()
50 static int _reg_parm(link *l)
59 static bool _startsWith(const char *sz, const char *key)
61 return !strncmp(sz, key, strlen(key));
64 static void _chomp(char *sz)
67 while ((nl = strrchr(sz, '\n')))
71 static int _process_pragma(const char *sz)
73 if (_startsWith(sz, "bank=")) {
75 sprintf(buffer, "%s", sz+5);
77 if (!strcmp(buffer, "BASE")) {
78 strcpy(buffer, "HOME");
80 gbz80_port.mem.code_name = gc_strdup(buffer);
81 code->sname = gbz80_port.mem.code_name;
87 static const char *_gbz80_rgbasmCmd[] = {
88 "rgbasm", "-o$1.o", "$1.asm", NULL
91 static const char *_gbz80_rgblinkCmd[] = {
92 "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
95 static void _gbz80_rgblink(void)
106 /* first we need to create the <filename>.lnk file */
107 sprintf(buffer,"%s.lnk", sz);
108 if (!(lnkfile = fopen(buffer,"w"))) {
109 werror(E_FILE_OPEN_ERR, buffer);
113 fprintf(lnkfile, "[Objects]\n");
116 fprintf(lnkfile, "%s.o\n", sz);
118 for (i = 0 ; i < nrelFiles ; i++ )
119 fprintf (lnkfile,"%s\n",relFiles[i]);
121 fprintf(lnkfile, "\n[Libraries]\n");
122 /* additional libraries if any */
123 for (i = 0 ; i < nlibFiles; i++)
124 fprintf (lnkfile,"%s\n",libFiles[i]);
127 fprintf(lnkfile,"\n[Output]\n" "%s.gb",sz);
131 buildCmdLine(buffer, argv, port->linker.cmd, sz, NULL, NULL, NULL);
132 /* call the linker */
133 if (my_system(argv[0], argv)) {
134 perror("Cannot exec linker");
139 static bool _parseOptions(int *pargc, char **argv, int *i)
141 if (argv[*i][0] == '-') {
142 if (argv[*i][1] == 'b' && IS_GB) {
143 int bank = atoi(argv[*i] + 3);
145 switch (argv[*i][2]) {
148 sprintf(buffer, "CODE_%u", bank);
149 gbz80_port.mem.code_name = gc_strdup(buffer);
153 sprintf(buffer, "DATA_%u", bank);
154 gbz80_port.mem.data_name = gc_strdup(buffer);
158 else if (!strncmp(argv[*i], "--asm=", 6)) {
159 if (!strcmp(argv[*i], "--asm=rgbds")) {
160 asm_addTree(&_rgbds_gb);
161 gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
162 gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
163 gbz80_port.linker.do_link = _gbz80_rgblink;
164 _G.fsetAsmType = TRUE;
167 else if (!strcmp(argv[*i], "--asm=asxxxx")) {
168 asm_addTree(&_asxxxx_gb);
169 _G.fsetAsmType = TRUE;
172 else if (!strcmp(argv[*i], "--asm=isas")) {
173 asm_addTree(&_isas_gb);
174 /* Munge the function prefix */
175 gbz80_port.fun_prefix = "";
176 _G.fsetAsmType = TRUE;
184 static void _finaliseOptions(void)
186 port->mem.default_local_map = data;
187 port->mem.default_globl_map = data;
188 if (!_G.fsetAsmType && IS_GB)
189 asm_addTree(&_asxxxx_gb);
192 static void _setDefaultOptions(void)
194 options.genericPtr = 1; /* default on */
196 options.stackAuto = 1;
197 options.mainreturn = 1;
198 options.noregparms = 1;
200 /* first the options part */
201 options.intlong_rent = 1;
203 optimize.global_cse = 1;
208 optimize.loopInvariant = 1;
209 optimize.loopInduction = 0;
212 static const char *_getRegName(struct regs *reg)
220 /** $1 is always the basename.
221 $2 is always the output file.
223 $l is the list of extra options that should be there somewhere...
224 MUST be terminated with a NULL.
226 static const char *_z80_linkCmd[] = {
227 "link-z80", "-nf", "$1", NULL
230 static const char *_z80_asmCmd[] = {
231 "as-z80", "-plosgff", "$1.asm", NULL
234 /** $1 is always the basename.
235 $2 is always the output file.
237 $l is the list of extra options that should be there somewhere...
238 MUST be terminated with a NULL.
240 static const char *_gbz80_linkCmd[] = {
241 "link-gbz80", "-nf", "$1", NULL
244 static const char *_gbz80_asmCmd[] = {
245 "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
251 "Zilog Z80", /* Target name */
257 "-plosgff", /* Options with debug */
258 "-plosgff", /* Options without debug */
269 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
270 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
291 /* Z80 has no native mul/div commands */
303 0, /* no assembler preamble */
304 0, /* no local IVT generation code */
314 "Gameboy Z80-like", /* Target name */
320 "-plosgff", /* Options with debug */
321 "-plosgff", /* Options without debug */
333 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
334 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
355 /* gbZ80 has no native mul/div commands */
367 0, /* no assembler preamble */
368 0, /* no local IVT generation code */