-
Notifications
You must be signed in to change notification settings - Fork 1
/
crt0.s
162 lines (132 loc) · 4.79 KB
/
crt0.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
| SEGA MegaDrive support code
| by Chilly Willy
.text
| Initial exception vectors
.long 0x01000000,initialize,exception,exception,exception,exception,exception,exception
.long exception,exception,exception,exception,exception,exception,exception,exception
.long exception,exception,exception,exception,exception,exception,exception,exception
.long exception,exception,exception,exception,hblank,exception,vblank,exception
.long exception,exception,exception,exception,exception,exception,exception,exception
.long exception,exception,exception,exception,exception,exception,exception,exception
.long exception,exception,exception,exception,exception,exception,exception,exception
.long exception,exception,exception,exception,exception,exception,exception,exception
| Standard MegaDrive ROM header at 0x100
.ascii "SEGA Mode1 Demo " /* SEGA must be the first four chars for TMSS */
.ascii "(C)2011 "
.ascii "Mode 1 CD Player" /* export name */
.ascii " "
.ascii " "
.ascii "Mode 1 CD Player" /* domestic (Japanese) name */
.ascii " "
.ascii " "
.ascii "GM MK-0000 -00"
.word 0x0000 /* checksum - not needed */
.ascii "J6C "
.long 0x00000000,0x0007FFFF /* ROM start, end */
.long 0x00FF0000,0x00FFFFFF /* RAM start, end */
.ifdef HAS_SAVE_RAM
.ascii "RA" /* External RAM */
.byte 0xF8 /* don't clear + odd bytes */
.byte 0x20 /* SRAM */
.long 0x00200001,0x0020FFFF /* SRAM start, end */
.else
.ascii " " /* no SRAM */
.endif
.ascii " "
.ascii " "
.ascii " " /* memo */
.ascii " "
.ascii " "
.ascii "F " /* enable any hardware configuration */
| Standard MegaDrive startup at 0x200
initialize:
move #0x2700,sr /* disable interrupts */
tst.l 0xA10008 /* check CTRL1 and CTRL2 setup */
bne.b 1f
tst.w 0xA1000C /* check CTRL3 setup */
1:
bne.b skip_tmss /* if any controller control port is setup, skip TMSS handling */
| Check Hardware Version Number
move.b 0xA10001,d0
andi.b #0x0F,d0 /* VERS */
beq 2f /* 0 = original hardware, TMSS not present */
move.l #0x53454741,0xA14000 /* Store Sega Security Code "SEGA" to TMSS */
2:
move.w 0xC00004,d0 /* read VDP Status reg */
skip_tmss:
move.w #0x8104,0xC00004 /* display off, vblank disabled */
move.w 0xC00004,d0 /* read VDP Status reg */
| Clear Work RAM
lea 0xFF0000,a0
moveq #0,d0
move.w #0x3FFF,d1
1:
move.l d0,(a0)+
dbra d1,1b
| Copy initialized variables from ROM to Work RAM
lea __text_end,a0
lea 0xFF0000,a1
move.l #__data_size,d0
lsr.l #1,d0
subq.w #1,d0
2:
move.w (a0)+,(a1)+
dbra d0,2b
lea 0x01000000,a0
movea.l a0,sp /* set stack pointer to top of Work RAM */
link.w a6,#-8 /* set up initial stack frame */
jsr init_hardware /* initialize the console hardware */
jsr __INIT_SECTION__ /* do all program initializers */
jsr main /* call program main() */
jsr __FINI_SECTION__ /* do all program finishers */
3:
bra.b 3b
| put redirection vectors and gTicks at start of Work RAM
.data
.global exception_vector
exception_vector:
.long 0
.global hblank_vector
hblank_vector:
.long 0
.global vblank_vector
vblank_vector:
.long 0
.global gTicks
gTicks:
.long 0
| Exception handlers
exception:
move.l exception_vector,-(sp)
beq.b 1f
rts
1:
addq.l #4,sp
rte
hblank:
move.l hblank_vector,-(sp)
beq.b 1f
rts
1:
addq.l #4,sp
rte
vblank:
addq.l #1,gTicks
move.l vblank_vector,-(sp)
beq.b 1f
rts
1:
addq.l #4,sp
rte
.text
.global gen_lvl2
gen_lvl2:
movem.l d0/a0,-(sp)
lea 0xA12000,a0
move.w (a0),d0
ori.w #0x0100,d0
move.w d0,(a0)
movem.l (sp)+,d0/a0
rte
.global _start
_start: