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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
Copyright_GFPresents: ; e49a8 (39:49a8)
; Play the copyright screen and GameFreak Presents sequence.
; Return carry if user cancels animation by pressing a button.
call ClearBGPalettes
call ClearTilemap
ld a, HIGH(vBGMap0)
ldh [hBGMapAddress + 1], a
xor a ; LOW(vBGMap0)
ldh [hBGMapAddress], a
ldh [hJoyDown], a
ldh [hSCX], a
ldh [hSCY], a
ld a, SCREEN_HEIGHT_PX
ldh [hWY], a
call WaitBGMap
ld b, SCGB_GAMEFREAK_LOGO
call GetSGBLayout
call SetPalettes
ld c, 10
call DelayFrames
callfar Copyright
call WaitBGMap
ld c, 100
call DelayFrames
call ClearTilemap
call GFPresents_Init
.loop
call GFPresents_PlayFrame
jr nc, .loop
; high bits of wJumpTableIndex are recycled for some flags
; this was set if user canceled by pressing a button
ld a, [wJumpTableIndex]
bit 6, a
jr nz, .canceled
; clear carry flag from GFPresents_PlayFrame
and a
ret
.canceled
scf
ret
GFPresents_Init: ; e49f3 (39:49f3)
; Load gfx and initialize variables
ld de, GFPresentsGFX1
ld hl, vTiles1
lb bc, BANK(GFPresentsGFX1), 28
call Get1bpp
ld de, GFPresentsGFX2
ld hl, vTiles1 tile 28
lb bc, BANK(GFPresentsGFX2), 5
call Request2bpp
farcall ClearAnimatedObjectBuffer
ld hl, wAnimatedObjectDynamicVTileOffsets
ld a, 6
ld [hli], a
ld a, $8d
ld [hl], a
xor a
ld [wJumpTableIndex], a
ld [$ce64], a
ld [wIntroSceneTimer], a
ldh [hSCX], a
ldh [hSCY], a
ld a, 1
ldh [hBGMapMode], a
ld a, SCREEN_HEIGHT_PX
ldh [hWY], a
lb de, %00100100, %11111000
call DmgToCgbObjPals
ret
GFPresents_PlayFrame: ; e4a37 (39:4a37)
; Play one frame of GFPresents sequence.
; Return carry when the sequence completes or is canceled.
call JoyTextDelay
ldh a, [hJoyLast]
and BUTTONS
jr nz, .pressed_button
; high bits of wJumpTableIndex are recycled for some flags
; this is set when the sequence finished
ld a, [wJumpTableIndex]
bit 7, a
jr nz, .finish
farcall AnimatedObjects_PlayFrame
call GFPresents_HandleFrame
call DelayFrame
; ensure carry is cleared
and a
ret
.pressed_button
; high bits of wJumpTableIndex are recycled for some flags
ld hl, wJumpTableIndex
set 6, [hl]
.finish
callfar ClearAnimatedObjectBuffer
call ClearTilemap
call ClearSprites
ld c, 16
call DelayFrames
scf
ret
GFPresents_HandleFrame: ; e4a6d (39:4a6d)
; Dispatch to the current scene handler
ld a, [wJumpTableIndex]
ld e, a
ld d, 0
ld hl, .scenes
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.scenes
dw GFPresents_Star
dw GFPresents_PlaceLogo
dw GFPresents_LogoSparkles
dw GFPresents_PlacePresents
dw GFPresents_WaitForTimer
dw GFPresents_SetDoneFlag
GFPresents_NextScene: ; e4a88 (39:4a88)
ld hl, wJumpTableIndex
inc [hl]
ret
; unused?
Func_e4a8d: ; e4a8d (39:4a8d)
ld c, 64
call DelayFrames
call GFPresents_NextScene
ret
GFPresents_Star: ; e4a96 (39:4a96)
; tell GFPresents_PlaceLogo we haven't finished yet
xor a
ld [$ce64], a
depixel 10, 11, 4, 0
ld a, $16
call InitSpriteAnimStruct
; TODO set some flag in the struct?
ld hl, $c
add hl, bc
ld [hl], $80
ld de, SFX_GAME_FREAK_LOGO_GS
call PlaySFX
call GFPresents_NextScene
ret
GFPresents_PlaceLogo: ; e4ab2 (39:4ab2)
; Draw the Game Freak logo (may be initially invisible due to palette)
; wait until the star animation completed
; TODO this is cleared above, but when is it set?
ld a, [$ce64]
and a
ret z
depixel 10, 11, 4, 0
ld a, $15
call InitSpriteAnimStruct
call GFPresents_NextScene
; set timer for GFPresents_LogoSparkles
ld a, $80
ld [wIntroSceneTimer], a
ret
GFPresents_LogoSparkles: ; e4ac8 (39:4ac8)
ld hl, wIntroSceneTimer
ld a, [hl]
and a
jr z, .done
dec [hl]
; add first text when timer passes half
cp $3f
call z, GFPresents_PlaceGameFreak
; add sparkles continuously
call GFPresents_Sparkle
ret
.done
; set (unused?) timer for GFPresents_PlacePresents
ld [hl], $80
call GFPresents_NextScene
ret
GFPresents_PlaceGameFreak: ; e4adf (39:4adf)
hlcoord 5, 12
ld de, .game_freak
call PlaceString
ret
.game_freak
db $80, $81, $82, $83, $8d, $84, $85, $83, $81, $86, "@"
GFPresents_PlacePresents: ; e4af4 (39:4af4)
hlcoord 7, 13
ld de, .presents
call PlaceString
call GFPresents_NextScene
; set timer for GFPresents_WaitForTimer
ld a, $80
ld [wIntroSceneTimer], a
ret
.presents
db $87, $88, $89, $8a, $8b, $8c, "@"
GFPresents_SetDoneFlag: ; e4b0d (39:4b0d)
; Tell GFPresents_PlayFrame and TitleScreenFrame (01:63da) that we're finished.
ld hl, wJumpTableIndex
set 7, [hl]
ret
GFPresents_WaitForTimer: ; e4b13 (39:4b13)
; Wait for the timer to elapse
ld hl, wIntroSceneTimer
ld a, [hl]
and a
jr z, .done
dec [hl]
ret
.done
call GFPresents_NextScene
ret
GFPresents_UpdateLogoPal: ; e4b20 (39:4b20)
; called from 29:5928
; OBP1 was initialized at end of GFPresents_Init
; once we reached the final state, leave it alone
ldh a, [rOBP1]
cp %10010000
ret z
; wait 16 frames before next change
ld a, [wIntroSceneTimer]
and $f
ret nz
; rotate OBP1 by one color slot (2 bits)
; DMG: logo is white, then light gray, then dark gray
; CGB: logo is white, then yellow
ldh a, [rOBP1]
rrca
rrca
call DmgToCgbObjPal1
ret
GFPresents_Sparkle: ; e4b33 (39:4b33)
; Initialize and configure a sparkle sprite.
; TODO unclear how this relates to the actual screen display,
; seems to be called more times than there are visible sparkles?
; run only every second frame
ld d, a
and 1
ret nz
; shift over so our index is still changing by 1 each time
ld a, d
srl a
; set up a new sparkle sprite
push af
depixel 11, 11
ld a, $17
call InitSpriteAnimStruct
pop af
; take the bottom 4 bits of a as an index into
; sparkle_vectors (16 entries)
and %00001111
ld e, a
ld d, 0
ld hl, .sparkle_vectors
add hl, de
add hl, de
; set the angle and distance for this sprite
; bc+$b <- hl (angle), bc+$c <- 0, bc+$d <- hl+1 (distance)
ld e, l
ld d, h
ld hl, $b
add hl, bc
ld a, [de]
ld [hl], a
inc de
ld hl, $c
add hl, bc
ld [hl], 0
inc hl
ld a, [de]
ld [hl], a
ret
.sparkle_vectors
; values control final position of each sparkle
; position is automatically animated along the vector
; each entry emits two sparkles in opposite directions
; angle (6 bits) and distance (tiles?)
db $00, $03
db $08, $04
db $04, $03
db $0c, $02
db $10, $02
db $18, $03
db $14, $04
db $1c, $03
db $20, $02
db $28, $02
db $24, $03
db $2c, $04
db $30, $04
db $38, $03
db $34, $02
db $3c, $04
GFPresentsGFX1:
INCBIN "gfx/intro/gamefreak_presents.1bpp"
INCBIN "gfx/intro/gamefreak_logo.1bpp"
GFPresentsGFX2:
INCBIN "gfx/intro/logo_star.2bpp"
INCBIN "gfx/intro/logo_sparkle.2bpp"
|