comparison boot/sega.s @ 0:826a1cb3f873

Copied SGDK project skeleton
author Mike Pavone <pavone@retrodev.com>
date Sun, 12 Jan 2014 11:24:36 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:826a1cb3f873
1 .text
2
3 *-------------------------------------------------------
4 *
5 * Sega startup code for the GNU Assembler
6 * Translated from:
7 * Sega startup code for the Sozobon C compiler
8 * Written by Paul W. Lee
9 * Modified by Charles Coty
10 * Modified by Stephane Dallongeville
11 *
12 *-------------------------------------------------------
13
14 .org 0x00000000
15
16 _Start_Of_Rom:
17 _Vecteurs_68K:
18 dc.l 0x00FFFE00 /* Stack address */
19 dc.l _Entry_Point /* Program start address */
20 dc.l _Bus_Error
21 dc.l _Address_Error
22 dc.l _Illegal_Instruction
23 dc.l _Zero_Divide
24 dc.l _Chk_Instruction
25 dc.l _Trapv_Instruction
26 dc.l _Privilege_Violation
27 dc.l _Trace
28 dc.l _Line_1010_Emulation
29 dc.l _Line_1111_Emulation
30 dc.l _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
31 dc.l _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
32 dc.l _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
33 dc.l _Error_Exception, _INT, _EXTINT, _INT
34 dc.l _HINT
35 dc.l _INT
36 dc.l _VINT
37 dc.l _INT
38 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
39 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
40 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
41 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
42
43 .incbin "boot/rom_head.bin", 0x10, 0x100
44
45 _Entry_Point:
46 move #0x2700,%sr
47 tst.l 0xa10008
48 bne.s SkipJoyDetect
49 tst.w 0xa1000c
50 SkipJoyDetect:
51 bne.s SkipSetup
52
53 lea Table,%a5
54 movem.w (%a5)+,%d5-%d7
55 movem.l (%a5)+,%a0-%a4
56 * Check Version Number
57 move.b -0x10ff(%a1),%d0
58 andi.b #0x0f,%d0
59 beq.s WrongVersion
60 * Sega Security Code (SEGA)
61 move.l #0x53454741,0x2f00(%a1)
62 WrongVersion:
63 move.w (%a4),%d0
64 moveq #0x00,%d0
65 movea.l %d0,%a6
66 move %a6,%usp
67 move.w %d7,(%a1)
68 move.w %d7,(%a2)
69 jmp Continue
70
71 Table:
72 dc.w 0x8000,0x3fff,0x0100
73 dc.l 0xA00000,0xA11100,0xA11200,0xC00000,0xC00004
74
75 SkipSetup:
76 move.w #0,%a7
77 jmp _reset_entry
78
79 Continue:
80
81 * clear Genesis RAM
82 lea 0xff0000,%a0
83 moveq #0,%d0
84 move.w #0x3FFF,%d1
85
86 ClearRam:
87 move.l %d0,(%a0)+
88 dbra %d1,ClearRam
89
90 * copy initialized variables from ROM to Work RAM
91 lea _stext,%a0
92 lea 0xFF0000,%a1
93 move.l #_sdata,%d0
94 lsr.l #1,%d0
95 beq NoCopy
96
97 subq.w #1,%d0
98 CopyVar:
99 move.w (%a0)+,(%a1)+
100 dbra %d0,CopyVar
101
102 NoCopy:
103
104 * Jump to initialisation process...
105
106 move.w #0,%a7
107 jmp _start_entry
108
109
110 *------------------------------------------------
111 *
112 * interrupt functions
113 *
114 *------------------------------------------------
115
116 _Bus_Error:
117 movem.l %d0-%d1/%a0-%a1,-(%sp)
118 move.l busErrorCB, %a0
119 jsr (%a0)
120 movem.l (%sp)+,%d0-%d1/%a0-%a1
121 rte
122
123 _Address_Error:
124 movem.l %d0-%d1/%a0-%a1,-(%sp)
125 move.l addressErrorCB, %a0
126 jsr (%a0)
127 movem.l (%sp)+,%d0-%d1/%a0-%a1
128 rte
129
130 _Illegal_Instruction:
131 movem.l %d0-%d1/%a0-%a1,-(%sp)
132 move.l illegalInstCB, %a0
133 jsr (%a0)
134 movem.l (%sp)+,%d0-%d1/%a0-%a1
135 rte
136
137 _Zero_Divide:
138 movem.l %d0-%d1/%a0-%a1,-(%sp)
139 move.l zeroDivideCB, %a0
140 jsr (%a0)
141 movem.l (%sp)+,%d0-%d1/%a0-%a1
142 rte
143
144 _Chk_Instruction:
145 movem.l %d0-%d1/%a0-%a1,-(%sp)
146 move.l chkInstCB, %a0
147 jsr (%a0)
148 movem.l (%sp)+,%d0-%d1/%a0-%a1
149 rte
150
151 _Trapv_Instruction:
152 movem.l %d0-%d1/%a0-%a1,-(%sp)
153 move.l trapvInstCB, %a0
154 jsr (%a0)
155 movem.l (%sp)+,%d0-%d1/%a0-%a1
156 rte
157
158 _Privilege_Violation:
159 movem.l %d0-%d1/%a0-%a1,-(%sp)
160 move.l privilegeViolationCB, %a0
161 jsr (%a0)
162 movem.l (%sp)+,%d0-%d1/%a0-%a1
163 rte
164
165 _Trace:
166 movem.l %d0-%d1/%a0-%a1,-(%sp)
167 move.l traceCB, %a0
168 jsr (%a0)
169 movem.l (%sp)+,%d0-%d1/%a0-%a1
170 rte
171
172 _Line_1010_Emulation:
173 _Line_1111_Emulation:
174 movem.l %d0-%d1/%a0-%a1,-(%sp)
175 move.l line1x1xCB, %a0
176 jsr (%a0)
177 movem.l (%sp)+,%d0-%d1/%a0-%a1
178 rte
179
180 _Error_Exception:
181 movem.l %d0-%d1/%a0-%a1,-(%sp)
182 move.l errorExceptionCB, %a0
183 jsr (%a0)
184 movem.l (%sp)+,%d0-%d1/%a0-%a1
185 rte
186
187 _INT:
188 movem.l %d0-%d1/%a0-%a1,-(%sp)
189 move.l intCB, %a0
190 jsr (%a0)
191 movem.l (%sp)+,%d0-%d1/%a0-%a1
192 rte
193
194 _EXTINT:
195 movem.l %d0-%d1/%a0-%a1,-(%sp)
196 move.l internalExtIntCB, %a0
197 jsr (%a0)
198 movem.l (%sp)+,%d0-%d1/%a0-%a1
199 rte
200
201 _HINT:
202 movem.l %d0-%d1/%a0-%a1,-(%sp)
203 move.l internalHIntCB, %a0
204 jsr (%a0)
205 movem.l (%sp)+,%d0-%d1/%a0-%a1
206 rte
207
208 _VINT:
209 movem.l %d0-%d1/%a0-%a1,-(%sp)
210 move.l internalVIntCB, %a0
211 jsr (%a0)
212 movem.l (%sp)+,%d0-%d1/%a0-%a1
213 rte
214
215 *------------------------------------------------
216 *
217 * Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg
218 *
219 * Permission is granted to anyone to use this software for any purpose
220 * on any computer system, and to redistribute it freely, with the
221 * following restrictions:
222 * 1) No charge may be made other than reasonable charges for reproduction.
223 * 2) Modified versions must be clearly marked as such.
224 * 3) The authors are not responsible for any harmful consequences
225 * of using this software, even if they result from defects in it.
226 *
227 *------------------------------------------------
228
229 ldiv:
230 move.l 4(%a7),%d0
231 bpl ld1
232 neg.l %d0
233 ld1:
234 move.l 8(%a7),%d1
235 bpl ld2
236 neg.l %d1
237 eor.b #0x80,4(%a7)
238 ld2:
239 bsr i_ldiv /* d0 = d0/d1 */
240 tst.b 4(%a7)
241 bpl ld3
242 neg.l %d0
243 ld3:
244 rts
245
246 lmul:
247 move.l 4(%a7),%d0
248 bpl lm1
249 neg.l %d0
250 lm1:
251 move.l 8(%a7),%d1
252 bpl lm2
253 neg.l %d1
254 eor.b #0x80,4(%a7)
255 lm2:
256 bsr i_lmul /* d0 = d0*d1 */
257 tst.b 4(%a7)
258 bpl lm3
259 neg.l %d0
260 lm3:
261 rts
262
263 lrem:
264 move.l 4(%a7),%d0
265 bpl lr1
266 neg.l %d0
267 lr1:
268 move.l 8(%a7),%d1
269 bpl lr2
270 neg.l %d1
271 lr2:
272 bsr i_ldiv /* d1 = d0%d1 */
273 move.l %d1,%d0
274 tst.b 4(%a7)
275 bpl lr3
276 neg.l %d0
277 lr3:
278 rts
279
280 ldivu:
281 move.l 4(%a7),%d0
282 move.l 8(%a7),%d1
283 bsr i_ldiv
284 rts
285
286 lmulu:
287 move.l 4(%a7),%d0
288 move.l 8(%a7),%d1
289 bsr i_lmul
290 rts
291
292 lremu:
293 move.l 4(%a7),%d0
294 move.l 8(%a7),%d1
295 bsr i_ldiv
296 move.l %d1,%d0
297 rts
298 *
299 * A in d0, B in d1, return A*B in d0
300 *
301 i_lmul:
302 move.l %d3,%a2 /* save d3 */
303 move.w %d1,%d2
304 mulu %d0,%d2 /* d2 = Al * Bl */
305
306 move.l %d1,%d3
307 swap %d3
308 mulu %d0,%d3 /* d3 = Al * Bh */
309
310 swap %d0
311 mulu %d1,%d0 /* d0 = Ah * Bl */
312
313 add.l %d3,%d0 /* d0 = (Ah*Bl + Al*Bh) */
314 swap %d0
315 clr.w %d0 /* d0 = (Ah*Bl + Al*Bh) << 16 */
316
317 add.l %d2,%d0 /* d0 = A*B */
318 move.l %a2,%d3 /* restore d3 */
319 rts
320 *
321 *A in d0, B in d1, return A/B in d0, A%B in d1
322 *
323 i_ldiv:
324 tst.l %d1
325 bne nz1
326
327 * divide by zero
328 * divu #0,%d0 /* cause trap */
329 move.l #0x80000000,%d0
330 move.l %d0,%d1
331 rts
332 nz1:
333 move.l %d3,%a2 /* save d3 */
334 cmp.l %d1,%d0
335 bhi norm
336 beq is1
337 * A<B, so ret 0, rem A
338 move.l %d0,%d1
339 clr.l %d0
340 move.l %a2,%d3 /* restore d3 */
341 rts
342 * A==B, so ret 1, rem 0
343 is1:
344 moveq.l #1,%d0
345 clr.l %d1
346 move.l %a2,%d3 /* restore d3 */
347 rts
348 * A>B and B is not 0
349 norm:
350 cmp.l #1,%d1
351 bne not1
352 * B==1, so ret A, rem 0
353 clr.l %d1
354 move.l %a2,%d3 /* restore d3 */
355 rts
356 * check for A short (implies B short also)
357 not1:
358 cmp.l #0xffff,%d0
359 bhi slow
360 * A short and B short -- use 'divu'
361 divu %d1,%d0 /* d0 = REM:ANS */
362 swap %d0 /* d0 = ANS:REM */
363 clr.l %d1
364 move.w %d0,%d1 /* d1 = REM */
365 clr.w %d0
366 swap %d0
367 move.l %a2,%d3 /* restore d3 */
368 rts
369 * check for B short
370 slow:
371 cmp.l #0xffff,%d1
372 bhi slower
373 * A long and B short -- use special stuff from gnu
374 move.l %d0,%d2
375 clr.w %d2
376 swap %d2
377 divu %d1,%d2 /* d2 = REM:ANS of Ahi/B */
378 clr.l %d3
379 move.w %d2,%d3 /* d3 = Ahi/B */
380 swap %d3
381
382 move.w %d0,%d2 /* d2 = REM << 16 + Alo */
383 divu %d1,%d2 /* d2 = REM:ANS of stuff/B */
384
385 move.l %d2,%d1
386 clr.w %d1
387 swap %d1 /* d1 = REM */
388
389 clr.l %d0
390 move.w %d2,%d0
391 add.l %d3,%d0 /* d0 = ANS */
392 move.l %a2,%d3 /* restore d3 */
393 rts
394 * A>B, B > 1
395 slower:
396 move.l #1,%d2
397 clr.l %d3
398 moreadj:
399 cmp.l %d0,%d1
400 bhs adj
401 add.l %d2,%d2
402 add.l %d1,%d1
403 bpl moreadj
404 * we shifted B until its >A or sign bit set
405 * we shifted #1 (d2) along with it
406 adj:
407 cmp.l %d0,%d1
408 bhi ltuns
409 or.l %d2,%d3
410 sub.l %d1,%d0
411 ltuns:
412 lsr.l #1,%d1
413 lsr.l #1,%d2
414 bne adj
415 * d3=answer, d0=rem
416 move.l %d0,%d1
417 move.l %d3,%d0
418 move.l %a2,%d3 /* restore d3 */
419 rts
420