forked from pkmncoraldev/polishedcoral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.asm
217 lines (176 loc) · 2.55 KB
/
init.asm
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
SoftReset:: ; 150
di
call MapSetup_Sound_Off
xor a
ld [hMapAnims], a
call ClearPalettes
xor a
ld [rIF], a
ld a, 1 ; VBlank int
ld [rIE], a
ei
ld hl, wInputFlags
set 7, [hl]
ld c, 3
call DelayFrames
jr Init
; 16e
_Start:: ; 16e
cp $11
jr z, .cgb
xor a
jr .load
.cgb
ld a, $1
.load
ld [hCGB], a
; fallthrough
Init:: ; 17d
di
xor a
ld [rIF], a
ld [rIE], a
ld [rRP], a
ld [rSCX], a
ld [rSCY], a
ld [rSB], a
ld [rSC], a
ld [rWX], a
ld [rWY], a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
ld [rTMA], a
ld [rTAC], a
ld [wRAM1Start], a
.wait
ld a, [rLY]
cp 145
jr nz, .wait
xor a
ld [rLCDC], a
; Clear WRAM bank 0
ld hl, wRAM0Start
ld bc, wRAM0End - wRAM0Start
.ByteFill:
ld [hl], 0
inc hl
dec bc
ld a, b
or c
jr nz, .ByteFill
ld sp, wStack
; Clear HRAM
ld a, [hCGB]
push af
xor a
ld hl, HRAM_START
ld bc, HRAM_END - HRAM_START
call ByteFill
pop af
ld [hCGB], a
call ClearWRAM
ld a, 1
ld [rSVBK], a
call ClearVRAM
call ClearSprites
call ClearsScratch
; Initialize the RNG state. It can be initialized to anything but zero; this is just a simple way of doing it.
ld hl, wRNGState
ld a, "R"
ld [hli], a
ld a, "N"
ld [hli], a
ld a, "G"
ld [hli], a
ld [hl], "!"
ld a, BANK(LoadPushOAM)
rst Bankswitch
call LoadPushOAM
xor a
ld [hMapAnims], a
ld [hSCX], a
ld [hSCY], a
ld [rJOYP], a
ld a, $8 ; HBlank int enable
ld [rSTAT], a
ld a, $90
ld [hWY], a
ld [rWY], a
ld a, 7
ld [hWX], a
ld [rWX], a
ld a, %11100011
; LCD on
; Win tilemap 1
; Win on
; BG/Win tiledata 0
; BG Tilemap 0
; OBJ 8x8
; OBJ on
; BG on
ld [rLCDC], a
ld a, CONNECTION_NOT_ESTABLISHED
ld [hSerialConnectionStatus], a
farcall InitSGBBorder
farcall InitCGBPals
ld a, VBGMap1 / $100
ld [hBGMapAddress + 1], a
xor a ; VBGMap1 % $100
ld [hBGMapAddress], a
farcall StartClock
xor a
ld [MBC3LatchClock], a
ld [MBC3SRamEnable], a
ld a, [hCGB]
and a
call nz, DoubleSpeed
xor a
ld [rIF], a
ld a, 1 << VBLANK | 1 << SERIAL
ld [rIE], a
ei
call DelayFrame
call MapSetup_Sound_Off
xor a
ld [wMapMusic], a
jp GameInit
; 245
ClearVRAM:: ; 245
; Wipe VRAM banks 0 and 1
ld a, 1
ld [rVBK], a
call .clear
xor a
ld [rVBK], a
.clear
ld hl, VTiles0
ld bc, $2000
xor a
jp ByteFill
; 25a
ClearWRAM:: ; 25a
; Wipe swappable WRAM banks (1-7)
ld a, 1
.bank_loop
push af
ld [rSVBK], a
xor a
ld hl, wRAM1Start
ld bc, $1000
call ByteFill
pop af
inc a
cp 8
jr c, .bank_loop
ret
; 270
ClearsScratch:: ; 270
xor a
call GetSRAMBank
ld hl, sScratch
ld bc, $20
xor a
call ByteFill
jp CloseSRAM
; 283