byte mode, dtack safety
[megadrive.git] / hexed / sega_gcc.s
CommitLineData
4db6e09f 1*-------------------------------------------------------\r
2*\r
3* Sega startup code for the GNU Assembler\r
4* Translated from:\r
5* Sega startup code for the Sozobon C compiler\r
6* Written by Paul W. Lee\r
7* Modified from Charles Coty's code\r
8*\r
9*-------------------------------------------------------\r
10\r
11 dc.l 0x0,0x200\r
12 dc.l INT,INT,INT,INT,INT,INT,INT\r
13 dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
14 dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
15 dc.l INT,INT,INT,HBL,INT,VBL,INT,INT\r
16 dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
17 dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
18 dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
19 dc.l INT,INT,INT,INT,INT,INT,INT\r
20 .ascii "SEGA GENESIS "\r
27d5cc88 21 .ascii "hexed (c) notaz, 2009 "\r
22 .ascii "HEXED (C) NOTAZ, 2009 "\r
4db6e09f 23 .ascii "GM 00000000-00"\r
27d5cc88 24 .byte 0x00,0x00\r
4db6e09f 25 .ascii "JD "\r
26 .byte 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00\r
27 .byte 0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff\r
28 .ascii " "\r
29 .ascii " "\r
30 .ascii " "\r
31 .ascii "JUE "\r
32*debugee:\r
33* bra debugee\r
34 tst.l 0xa10008\r
35 bne SkipJoyDetect \r
36 tst.w 0xa1000c\r
37SkipJoyDetect:\r
38 bne SkipSetup\r
39 lea Table,%a5 \r
40 movem.w (%a5)+,%d5-%d7\r
41 movem.l (%a5)+,%a0-%a4 \r
42* Check Version Number \r
43 move.b -0x10ff(%a1),%d0\r
44 andi.b #0x0f,%d0 \r
45 beq WrongVersion \r
46* Sega Security Code (SEGA) \r
47 move.l #0x53454741,0x2f00(%a1)\r
48WrongVersion:\r
49 move.w (%a4),%d0\r
50 moveq #0x00,%d0 \r
51 movea.l %d0,%a6 \r
52 move %a6,%usp\r
53* Set VDP registers\r
54 moveq #0x17,%d1\r
55FillLoop: \r
56 move.b (%a5)+,%d5\r
57 move.w %d5,(%a4) \r
58 add.w %d7,%d5 \r
59 dbra %d1,FillLoop \r
60 move.l (%a5)+,(%a4) \r
61 move.w %d0,(%a3) \r
62 move.w %d7,(%a1) \r
63 move.w %d7,(%a2) \r
64L0250:\r
65 btst %d0,(%a1)\r
66 bne L0250 \r
67* Put initial values into a00000 \r
68 moveq #0x25,%d2\r
69Filla: \r
70 move.b (%a5)+,(%a0)+\r
71 dbra %d2,Filla\r
72 move.w %d0,(%a2) \r
73 move.w %d0,(%a1) \r
74 move.w %d7,(%a2) \r
75L0262:\r
76 move.l %d0,-(%a6)\r
77 dbra %d6,L0262 \r
78 move.l (%a5)+,(%a4) \r
79 move.l (%a5)+,(%a4) \r
80* Put initial values into c00000 \r
81 moveq #0x1f,%d3\r
82Filc0: \r
83 move.l %d0,(%a3)\r
84 dbra %d3,Filc0\r
85 move.l (%a5)+,(%a4) \r
86* Put initial values into c00000 \r
87 moveq #0x13,%d4\r
88Fillc1: \r
89 move.l %d0,(%a3)\r
90 dbra %d4,Fillc1\r
91* Put initial values into c00011 \r
92 moveq #0x03,%d5\r
93Fillc2: \r
94 move.b (%a5)+,0x0011(%a3) \r
95 dbra %d5,Fillc2 \r
96 move.w %d0,(%a2) \r
97 movem.l (%a6),%d0-%d7/%a0-%a6 \r
98 move #0x2700,%sr \r
99SkipSetup:\r
100 bra Continue\r
101Table:\r
102 dc.w 0x8000, 0x3fff, 0x0100, 0x00a0, 0x0000, 0x00a1, 0x1100, 0x00a1\r
103 dc.w 0x1200, 0x00c0, 0x0000, 0x00c0, 0x0004, 0x0414, 0x302c, 0x0754\r
104 dc.w 0x0000, 0x0000, 0x0000, 0x812b, 0x0001, 0x0100, 0x00ff, 0xff00 \r
105 dc.w 0x0080, 0x4000, 0x0080, 0xaf01, 0xd91f, 0x1127, 0x0021, 0x2600\r
106 dc.w 0xf977, 0xedb0, 0xdde1, 0xfde1, 0xed47, 0xed4f, 0xd1e1, 0xf108 \r
107 dc.w 0xd9c1, 0xd1e1, 0xf1f9, 0xf3ed, 0x5636, 0xe9e9, 0x8104, 0x8f01 \r
108 dc.w 0xc000, 0x0000, 0x4000, 0x0010, 0x9fbf, 0xdfff \r
109\r
110Continue:\r
111 tst.w 0x00C00004\r
112\r
113* set stack pointer\r
114* clr.l %a7\r
115 move.w #0,%a7\r
116\r
117* user mode\r
118 move.w #0x2300,%sr\r
119\r
120* clear Genesis RAM\r
121 lea 0xff0000,%a0\r
122 moveq #0,%d0\r
123clrram: move.w #0,(%a0)+\r
124 subq.w #2,%d0\r
125 bne clrram\r
126\r
127*---------------------------------------------------------- \r
128*\r
129* Load driver into the Z80 memory\r
130*\r
131*---------------------------------------------------------- \r
132\r
133* halt the Z80\r
134 move.w #0x100,0xa11100\r
135* reset it\r
136 move.w #0x100,0xa11200\r
137\r
138 lea Z80Driver,%a0\r
139 lea 0xa00000,%a1\r
140 move.l #Z80DriverEnd,%d0\r
141 move.l #Z80Driver,%d1\r
142 sub.l %d1,%d0\r
143Z80loop:\r
144 move.b (%a0)+,(%a1)+\r
145 subq.w #1,%d0\r
146 bne Z80loop\r
147\r
148* enable the Z80\r
149 move.w #0x0,0xa11100\r
150\r
151*---------------------------------------------------------- \r
152 jmp main\r
153\r
154INT: \r
155 rte\r
156\r
157HBL:\r
158 /* addq.l #1,htimer */\r
159 rte\r
160\r
1286a1ba 161* VBL:\r
162* addq.l #1,(vtimer).l\r
163* rte\r
4db6e09f 164\r
4db6e09f 165*---------------------------------------------------------- \r
166*\r
167* Z80 Sound Driver\r
168*\r
169*---------------------------------------------------------- \r
170Z80Driver:\r
171 dc.b 0xc3,0x46,0x00,0x00,0x00,0x00,0x00,0x00\r
172 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
173 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
174 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
175 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
176 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
177 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
178 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
179 dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0xf3,0xed\r
180 dc.b 0x56,0x31,0x00,0x20,0x3a,0x39,0x00,0xb7\r
181 dc.b 0xca,0x4c,0x00,0x21,0x3a,0x00,0x11,0x40\r
182 dc.b 0x00,0x01,0x06,0x00,0xed,0xb0,0x3e,0x00\r
183 dc.b 0x32,0x39,0x00,0x3e,0xb4,0x32,0x02,0x40\r
184 dc.b 0x3e,0xc0,0x32,0x03,0x40,0x3e,0x2b,0x32\r
185 dc.b 0x00,0x40,0x3e,0x80,0x32,0x01,0x40,0x3a\r
186 dc.b 0x43,0x00,0x4f,0x3a,0x44,0x00,0x47,0x3e\r
187 dc.b 0x06,0x3d,0xc2,0x81,0x00,0x21,0x00,0x60\r
188 dc.b 0x3a,0x41,0x00,0x07,0x77,0x3a,0x42,0x00\r
189 dc.b 0x77,0x0f,0x77,0x0f,0x77,0x0f,0x77,0x0f\r
190 dc.b 0x77,0x0f,0x77,0x0f,0x77,0x0f,0x77,0x3a\r
191 dc.b 0x40,0x00,0x6f,0x3a,0x41,0x00,0xf6,0x80\r
192 dc.b 0x67,0x3e,0x2a,0x32,0x00,0x40,0x7e,0x32\r
193 dc.b 0x01,0x40,0x21,0x40,0x00,0x7e,0xc6,0x01\r
194 dc.b 0x77,0x23,0x7e,0xce,0x00,0x77,0x23,0x7e\r
195 dc.b 0xce,0x00,0x77,0x3a,0x39,0x00,0xb7,0xc2\r
196 dc.b 0x4c,0x00,0x0b,0x78,0xb1,0xc2,0x7f,0x00\r
197 dc.b 0x3a,0x45,0x00,0xb7,0xca,0x4c,0x00,0x3d\r
198 dc.b 0x3a,0x45,0x00,0x06,0xff,0x0e,0xff,0xc3\r
199 dc.b 0x7f,0x00\r
200Z80DriverEnd:\r
201\r
202\r