Pre 2.92
[fw/sdcc] / src / z80 / gbz80.c
1 /** @file z80/gbz80.c
2     Extra bits ontop of the z80 port to target the Gameboy's Z80 like
3     processor.
4
5     Michael Hope <michaelh@earthling.net> 2000
6 */
7
8 #include "z80.h"
9
10 static char _defaultRules[] =
11 {
12 #include "peeph.rul"
13 #include "peeph-gbz80.rul"
14 };
15
16 static char *_gbz80_keywords[] = { NULL };
17
18 static bool _gbz80_parseOptions(int *pargc, char **argv, int *i)
19 {
20     return FALSE;
21 }
22
23 static void _gbz80_init(void)
24 {
25     z80_opts.sub = SUB_GBZ80;
26 }
27
28 static void _gbz80_finaliseOptions(void)
29 {
30 }
31
32 static void _gbz80_setDefaultOptions(void)
33 {    
34     options.genericPtr = 1;   /* default on */
35     options.nopeep    = 0;
36     options.stackAuto = 1;
37     options.mainreturn = 1;
38     options.noregparms = 1;
39     /* first the options part */
40     options.intlong_rent = 1;
41
42     optimize.global_cse = 1;    
43     optimize.label1 = 1;
44     optimize.label2 = 1;
45     optimize.label3 = 1;
46     optimize.label4 = 1;    
47     optimize.loopInvariant = 1;
48     optimize.loopInduction = 0;
49 }
50
51 static const char *_gbz80_getRegName(struct regs *reg)
52 {
53     if (reg)
54         return reg->name;
55     assert(0);
56     return "err";
57 }
58
59 /** $1 is always the basename.
60     $2 is always the output file.
61     $3 varies
62     $l is the list of extra options that should be there somewhere...
63     MUST be terminated with a NULL.
64 */
65 static const char *_linkCmd[] = {
66     "link-gbz80", "-nf", "$1", NULL
67 };
68
69 static const char *_asmCmd[] = {
70     "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
71 };
72
73 /* Globals */
74 PORT gbz80_port = {
75     "gbz80",
76     "Gameboy Z80-like",         /* Target name */
77     {
78         FALSE,
79     },
80     {   
81         _asmCmd,
82         "-plosgff",             /* Options with debug */
83         "-plosgff",             /* Options without debug */
84     },
85     {
86         _linkCmd
87     },
88     {
89         _defaultRules
90     },
91     {
92         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
93         1, 1, 2, 4, 2, 2, 2, 1, 4, 4
94     },
95     {
96         "_XSEG",
97         "_STACK",
98         "_CODE",
99         "_DATA",
100         "_ISEG",
101         "_XSEG",
102         "_BSEG",
103         "_RSEG",
104         "_GSINIT",
105         "_OVERLAY",
106         "_GSFINAL"
107     },
108     { 
109         -1, 0, 0, 4, 0
110     },
111     /* Z80 has no native mul/div commands */
112     {  
113         0
114     },
115     _gbz80_init,
116     _gbz80_parseOptions,
117     _gbz80_finaliseOptions,
118     _gbz80_setDefaultOptions,
119     z80_assignRegisters,
120     _gbz80_getRegName,
121     _gbz80_keywords,
122     0,  /* no assembler preamble */
123     0,  /* no local IVT generation code */
124 };