-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootix_mgb.asm
214 lines (183 loc) · 3.35 KB
/
bootix_mgb.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
INCLUDE "inc/hardware.inc"
SCX_MAX_OFF EQU $10
ANIM_TIMEOUT EQU 30
SOUND_TIMEOUT_1 EQU 30
SOUND_TIMEOUT_2 EQU 498
SECTION "Bootrom", ROM0[0]
; Initialize SP
ld sp, $FFFE
; Clear VRAM
ld hl, $9FFF
ClearVRAM:
xor a
ld [hld], a
bit 7, h
jr nz, ClearVRAM
; Initialize Audio
ld c, $11
ld hl, rAUDENA
ld a, AUDENA_ON
ld [hld], a
ldh [$ff00+c], a
inc c
ld a, $F3
ld [hld], a
ldh [$ff00+c], a
inc c
ld a, $77
ld [hld], a
ldh [$ff00+c], a
; Decode logo and load into VRAM
ld de, $0104
ld hl, $8010
DecodeLoop:
; Decode first 4 bits of byte
ld a, [de]
call LoadLogoNibble
; Decode second 4 bits of byte
ld a, [de]
swap a
call LoadLogoNibble
; Loop if necessary
inc de
ld a, e
cp $34
jr nz, DecodeLoop
; Load Trademark Symbol into VRAM
ld de, TrademarkLogo
ld b, 8
TrademarkLoadLoop:
ld a, [de]
inc de
ld [hli], a
inc hl
dec b
jr nz, TrademarkLoadLoop
; Initialize tilemap (Row 1)
ld hl, $9904
ld bc, $010C
call LogoMapInit
; Trademark Symbol
ld a, $19
ld [hl], a
; Initialize Tilemap (Row 2)
ld hl, $9924
ld c, $0C
call LogoMapInit
; Initialize LCDC
ld a, LCDCF_ON | LCDCF_BG8000 | LCDCF_BGON
ldh [rLCDC], a
; Play intro animation
ld b, SCX_MAX_OFF
ld de, FadeValues
IntroAnimLoop:
; Set SCX to OFFSET
ld a, b
ldh [rSCX], a
dec b
; Update BGP Fade
ld a, e
cp LOW(FadeValues+4)
jr z, .skipFade
ld a, [de]
ldh [rBGP], a
inc de
.skipFade
; Wait...
ld c, ANIM_TIMEOUT
call DoTimeout
; Set SCX to -OFFSET
xor a
sub b
ldh [rSCX], a
dec b
; Wait... (Return to loop if OFFSET != 0)
ld c, ANIM_TIMEOUT
call DoTimeout
xor a
or b
jr nz, IntroAnimLoop
ldh [rSCX], a
; Play sound 1
ld a, $83
call PlaySound
; Wait...
ld c, SOUND_TIMEOUT_1
call DoTimeout
; Play sound 2
ld a, $C1
call PlaySound
; Wait...
ld de, SOUND_TIMEOUT_2
LongWaitLoop:
ldh a, [rLY]
cp SCRN_Y
jr nz, LongWaitLoop
dec de
ld a, d
or e
jr nz, LongWaitLoop
; Finalize Bootrom
jr EndBootrom
PlaySound:
ld c, $13
ld [$ff00+c], a
inc c
ld a, $87
ld [$ff00+c], a
ret
; Routine for waiting a certain amount of time
DoTimeout:
ldh a, [rLY]
cp SCRN_Y
jr nz, DoTimeout
dec c
jr nz, DoTimeout
ret
; Routine for loading logo tile numbers into VRAM
LogoMapInit:
ld a, b
ld [hli], a
inc b
dec c
jr nz, LogoMapInit
ret
; Routine for converting logo byte to VRAM data
LoadLogoNibble:
ld b, a
ld c, $04
xor a
.bitShiftLoop
push bc
rl b
rla
pop bc
rl b
rla
dec c
jr nz, .bitShiftLoop
ld [hli], a
inc hl
ld [hli], a
inc hl
ret
; Trademark Logo
TrademarkLogo:
db $3C, $42, $B9, $A5, $B9, $A5, $42, $3C
; BGP Fade Values
FadeValues:
db %00000000, %01010100, %10101000, %11111100
; Mandatory Copyright Notice
db "BOOTIX.DMG v1.2", 0
EndBootrom:
; Initialize registers
ld a, $FF
add $01
dec bc
ld e, $D8
ld hl, $014D
; Pad remaining space with NOP
ds $100-@-4, 0
; Disable Bootrom
ld a, $FF
ldh [$FF50], a