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