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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
HandleTitlescreen: ; 0xc000
ld a, [wScreenState]
rst JumpTable ; calls JumpToFuncInTable
TitlescreenFunctions: ; 0xc004
dw FadeInTitlescreen
dw TitlescreenLoop ; titlescreen loop
dw Func_c10e ; previously saved game menu
dw Func_c1cb ; game start, pokedex, option
dw GoToHighScoresFromTitlescreen ; go to high scores
FadeInTitlescreen: ; 0xc00e
ld a, $43
ld [hLCDC], a
ld a, $e4
ld [wBGP], a
ld a, $d2
ld [wOBP0], a
ld a, $e1
ld [wOBP1], a
xor a
ld [hSCX], a
ld [hSCY], a
ld hl, TitlescreenFadeInGfxPointers
ld a, [hGameBoyColorFlag]
call LoadVideoData
ld a, $1
ld [wTitleScreenGameStartCursorSelection], a
call ClearOAMBuffer
ld a, $2
ld [wTitleScreenPokeballAnimationCounter], a
call HandleTitlescreenAnimations
call SetAllPalettesWhite
ld a, Bank(Music_Title)
call SetSongBank
ld de, MUSIC_TITLE_SCREEN
call PlaySong
call EnableLCD
call FadeIn
ld hl, wScreenState
inc [hl]
ret
TitlescreenFadeInGfxPointers: ; 0xc057
dw TitlescreenFadeInGfx_GameBoy
dw TitlescreenFadeInGfx_GameBoyColor
TitlescreenFadeInGfx_GameBoy: ; 0xc05b
VIDEO_DATA_TILES TitlescreenGfx, vTilesOB, $1800
VIDEO_DATA_TILEMAP TitlescreenTilemap, vBGMap, $240
db $FF, $FF ; terminators
TitlescreenFadeInGfx_GameBoyColor: ; 0xc06b
VIDEO_DATA_TILES TitlescreenFadeInGfx, vTilesOB, $1800
VIDEO_DATA_TILEMAP TitlescreenTilemap, vBGMap, $240
VIDEO_DATA_BGATTR TitlescreenBGAttributes, vBGMap, $240
VIDEO_DATA_PALETTES TitlescreenPalettes, $80
db $FF, $FF ; terminators
TitlescreenLoop: ; 0xc089
call Func_c0ee
call HandleTitlescreenAnimations
ld a, [hNewlyPressedButtons]
bit BIT_A_BUTTON, a ; was A button pressed?
jr z, .AButtonNotPressed
ld a, [wTitleScreenCursorSelection]
and a
jr nz, .asm_c0d3
; player chose "Game Start"
ld a, [wSavedGame] ; if this is non-zero, the main menu will prompt for "continue or new game?".
and a
jr z, .noPreviouslySavedGame
lb de, $00, $01
call PlaySoundEffect
xor a
ld [wd910], a
ld a, $2
ld [wd911], a
ld a, $1
ld [wTitleScreenGameStartCursorSelection], a
ld hl, wScreenState
inc [hl]
ret
.noPreviouslySavedGame
ld de, MUSIC_NOTHING
call PlaySong
rst AdvanceFrame
lb de, $00, $27
call PlaySoundEffect
ld bc, $0037
call AdvanceFrames
ld a, $3
ld [wScreenState], a
ret
.asm_c0d3
lb de, $00, $01
call PlaySoundEffect
ld a, $3
ld [wScreenState], a
ret
.AButtonNotPressed
bit BIT_B_BUTTON, a ; was B button pressed?
ret z
lb de, $00, $01
call PlaySoundEffect
ld a, $4
ld [wScreenState], a
ret
Func_c0ee: ; 0xc0ee
ld hl, wTitleScreenCursorSelection
ld c, $2
call Func_c1fc
ret
HandleTitlescreenAnimations: ; 0xc0f7
ld a, [hGameBoyColorFlag]
and a
jr z, .asm_c104
ld bc, $2040
ld a, $62 ; seemingly-unused OAM data for titlescreen. It's just blank tiles.
call LoadOAMData
.asm_c104
call Func_c21d ; does nothing...
call HandleTitlescreenPikachuBlinkingAnimation
call HandleTitlescreenPokeballAnimation
ret
Func_c10e: ; 0xc10e
call Func_c1a2
call Func_c1b1
ld a, [wd910]
cp $6
ret nz
ld a, [hNewlyPressedButtons]
bit 0, a
jr z, .asm_c17c
ld de, MUSIC_NOTHING
call PlaySong
rst AdvanceFrame
lb de, $00, $27
call PlaySoundEffect
ld bc, $0041
call AdvanceFrames
ld a, [wTitleScreenGameStartCursorSelection]
and a
jr z, .asm_c177
call FadeOut
call DisableLCD
ld a, [wSavedGame]
and a
jr z, .notLoadingSavedGame
ld hl, sSaveGame
ld de, wPartyMons
ld bc, $04c3
call LoadSavedData
jr nc, .notLoadingSavedGame
xor a
ld [wSavedGame], a
ld hl, wPartyMons
ld de, sSaveGame
ld bc, $04c3
call SaveData
ld a, $1
ld [wLoadingSavedGame], a
ld a, SCREEN_PINBALL_GAME
ld [wCurrentScreen], a
ld a, $0
ld [wScreenState], a
ret
.notLoadingSavedGame
xor a
ld [wLoadingSavedGame], a
.asm_c177
ld hl, wScreenState
inc [hl]
ret
.asm_c17c
bit 1, a
ret z
lb de, $00, $01
call PlaySoundEffect
ld a, $8
ld [wd910], a
ld a, $2
ld [wd911], a
.asm_c18f
call CleanOAMBuffer
rst AdvanceFrame
call Func_c1b1
ld a, [wd910]
cp $e
jr nz, .asm_c18f
ld hl, wScreenState
dec [hl]
ret
Func_c1a2: ; 0xc1a2
ld a, [wd910]
cp $6
ret nz
ld hl, wTitleScreenGameStartCursorSelection
ld c, $1
call Func_c1fc
ret
Func_c1b1: ; 0xc1b1
call Func_c2df
ld a, [hGameBoyColorFlag]
and a
jr z, .asm_c1c1
ld bc, $2040
ld a, $62
call LoadOAMData
.asm_c1c1
call Func_c21d
call HandleTitlescreenPikachuBlinkingAnimation
call HandleTitlescreenPokeballAnimation
ret
Func_c1cb: ; 0c1cb
call FadeOut
call DisableLCD
ld a, [wTitleScreenCursorSelection]
ld c, a
ld b, $0
ld hl, Data_c1e4
add hl, bc
ld a, [hl]
ld [wCurrentScreen], a
xor a
ld [wScreenState], a
ret
Data_c1e4: ; 0xc1e4
db SCREEN_FIELD_SELECT
db SCREEN_POKEDEX
db SCREEN_OPTIONS
GoToHighScoresFromTitlescreen: ; 0xc1e7
call FadeOut
call DisableLCD
ld a, SCREEN_HIGH_SCORES
ld [wCurrentScreen], a
ld a, $1
ld [wScreenState], a
xor a
ld [wda7f], a
ret
Func_c1fc: ; 0xc1fc
ld a, [hPressedButtons]
ld b, a
ld a, [hl]
bit 6, b
jr z, .asm_c20f
and a
ret z
dec a
ld [hl], a
lb de, $00, $03
call PlaySoundEffect
ret
.asm_c20f
bit 7, b
ret z
cp c
ret z
inc a
ld [hl], a
lb de, $00, $03
call PlaySoundEffect
ret
Func_c21d: ; 0xc21d
; World's greatest function.
ret
HandleTitlescreenPikachuBlinkingAnimation: ; 0xc21e
ld a, [wTitleScreenBlinkAnimationFrame]
sla a
ld c, a
ld b, $0
ld hl, TitleScreenBlinkAnimation
add hl, bc
lb bc, $38, $10
ld a, [hl]
cp $5a ; blink animation frame 1 OAM id
call nz, LoadOAMData
ld a, [wTitleScreenBlinkAnimationCounter]
dec a
jr nz, .done
inc hl
inc hl ; hl points to next frame in TitleScreenBlinkAnimation array
ld a, [hl]
and a ; reached the end of the animation frames?
jr z, .saveAnimationFrame
ld a, [wTitleScreenBlinkAnimationFrame]
inc a
.saveAnimationFrame
ld [wTitleScreenBlinkAnimationFrame], a
sla a
ld c, a
ld b, $0
ld hl, (TitleScreenBlinkAnimation + 1)
add hl, bc
ld a, [hl] ; a contains second byte in the current animation frame data
cp $3c ; is this a long-duration animation frame?
jr c, .done
ld c, a
call GenRandom
and $1f
add c
.done
ld [wTitleScreenBlinkAnimationCounter], a
ret
TitleScreenBlinkAnimation: ; 0xc25f
; Array of animation frames. The animation is looped when it finishes.
; first byte = OAM data id to load
; second byte = number of frames to show this animation.
db $5a, $c8
db $5b, $04
db $5c, $04
db $5b, $04
db $5a, $3c
db $5b, $03
db $5c, $03
db $5b, $03
db $5a, $03
db $5b, $03
db $5c, $03
db $5b, $03
db $00 ; terminator
HandleTitlescreenPokeballAnimation: ; 0xc278
ld a, [wTitleScreenCursorSelection]
sla a
ld c, a
ld b, $0
ld hl, TitleScreenPokeballCoordOffsets
add hl, bc
ld a, [hli]
ld c, a
ld a, [hli]
ld b, a
ld e, $0
ld a, [wScreenState] ; TODO: I think this is the "titlescreen state" byte.
cp $1
jr nz, .loadOAM ; skip getting the correct animation frame
ld a, [wTitleScreenBouncingBallAnimationFrame]
sla a
ld e, a
.loadOAM
ld d, $0
ld hl, TitleScreenPokeballAnimation
add hl, de
ld a, [hl] ; a contains OAM id
call LoadOAMData
ld a, [wTitleScreenPokeballAnimationCounter]
dec a
jr nz, .done
ld a, [wTitleScreenBouncingBallAnimationFrame]
sla a
ld c, a
ld b, $0
ld hl, (TitleScreenPokeballAnimation + 2) ; first frame of actual animation
add hl, bc
ld a, [hl]
and a
jr z, .saveAnimationFrame ; end of list?
ld a, [wTitleScreenBouncingBallAnimationFrame]
inc a
.saveAnimationFrame
ld [wTitleScreenBouncingBallAnimationFrame], a
sla a
ld c, a
ld b, $0
ld hl, (TitleScreenPokeballAnimation + 1) ; first duration
add hl, bc
ld a, [hl]
.done
ld [wTitleScreenPokeballAnimationCounter], a
ret
TitleScreenPokeballAnimation: ; 0xc2cc
; first byte = OAM id
; second byte = animation frame duration
db $5D, $02
db $5E, $06
db $5F, $02
db $60, $04
db $61, $06
db $5F, $04
db $00 ; terminator
TitleScreenPokeballCoordOffsets: ; 0xc2d9
db $67, $15
db $73, $15
db $7F, $15
Func_c2df: ; 0xc2df
ld bc, $4446 ; pixel offsets, not data
ld a, [wd910]
cp $6
jr nz, .asm_c2f0
ld a, [wTitleScreenGameStartCursorSelection]
add $58
jr .asm_c2fd
.asm_c2f0
ld a, [wd910]
sla a
ld e, a
ld d, $0
ld hl, Data_c32b
add hl, de
ld a, [hl]
.asm_c2fd
call LoadOAMData
ld a, [wd911]
dec a
jr nz, .asm_c327
ld a, [wd910]
sla a
ld c, a
ld b, $0
ld hl, Data_c32b + 2
add hl, bc
ld a, [hl]
and a
ld a, [wd910]
jr z, .asm_c31d
inc a
ld [wd910], a
.asm_c31d
sla a
ld c, a
ld b, $0
ld hl, Data_c32b + 1
add hl, bc
ld a, [hl]
.asm_c327
ld [wd911], a
ret
Data_c32b: ; 0xc32b
db $52, $02
db $53, $02
db $54, $02
db $55, $02
db $56, $02
db $57, $02
db $57, $02
db $00, $00
db $57, $02
db $56, $02
db $55, $02
db $54, $02
db $53, $02
db $52, $02
db $52, $02
db $00
|