summaryrefslogtreecommitdiff
path: root/engine/title.asm
blob: c39abdde5f7b8a344c8e69a4dc8a16ad1b380d40 (plain)
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
INCLUDE "constants.asm"

SECTION "engine/title.asm@Title screen", ROMX

IntroSequence::
	callab GameFreakIntro	; Bank $39 
	jr c, TitleSequenceStart
	ld a, [wTitleSequenceOpeningType]
	and a
	jr z, .opening_sequence
	
.pikachu_minigame
	callab PikachuMiniGame	; Bank $38 
	jr TitleSequenceStart

.opening_sequence
	callab OpeningCutscene	; Bank $39 

TitleSequenceStart::
	call TitleSequenceInit
	callab SetTitleBGDecorationBorder	; Bank $02 
	
.loop
	call TitleScreenMain 
	jr nc, .loop
	
	call ClearBGPalettes
	call ClearSprites
	ld a, $01
	ldh [hBGMapMode], a
	call ClearTileMap
	call UpdateTimePals
	
	ld a, [wJumptableIndex + 1]
	ld e, a
	ld d, 0
	ld hl, TitleScreenJumpTable
	add hl, de
	add hl, de
	ld a, [hli]
	ld h, [hl]
	ld l, a
	
	jp hl

TitleScreenJumpTable::
	dw MainMenu
	dw DebugMenu 
	dw SRAMClearMenu
	dw IntroSequence

TitleSequenceInit::
	call ClearPalettes
	
	xor a
	ldh [hMapAnims], a
	ldh [hSCY], a
	ldh [hSCX], a
	
	ld de, MUSIC_NONE	; Stop the music. 
	call PlayMusic
	
	call ClearTileMap
	call DisableLCD
	call ClearSprites
	
	callba InitEffectObject	; Bank $23 
	ld hl, vChars0
	ld bc, vBGMap0 - vChars0

.clear_loop
	ld [hl], $00
	inc hl
	dec bc
	ld a, b
	or c
	jr nz, .clear_loop

	ld hl, TitleScreenGFX
	ld de, vChars2 + 65 tiles
	ld bc, 13 tiles
	ld a, BANK(TitleScreenGFX)
	call FarCopyData
	
	ld hl, TitleScreenVersionGFX
	ld de, vChars2 + 96 tiles
	ld bc, 24 tiles
	ld a, BANK(TitleScreenVersionGFX)
	call FarCopyData
	
	ld hl, TitleScreenHoOhGFX
	ld de, vChars2
	ld bc, 49 tiles
	ld a, BANK(TitleScreenHoOhGFX)
	call FarCopyData
	
	ld hl, TitleScreenLogoGFX
	ld de, vChars1
	ld bc, 58 tiles
	ld a, BANK(TitleScreenLogoGFX)
	call FarCopyData
	
	ld hl, TitleScreenGoldLogoGFX
	ld de, vChars0 + 186 tiles
	ld bc, 20 tiles
	ld a, BANK(TitleScreenGoldLogoGFX)
	call FarCopyData
	
	call SetTitleGfx
	ld hl, wTileMapBackup
	ld a, $24
	ld [hli], a
	ld a, $00
	ld [hli], a
	
	ld hl, vBGMap0
	ld bc, 128 tiles
	ld a, " "
	call ByteFill
	
	ld b, $06
	call GetSGBLayout
	call EnableLCD
	ld a, $01	
	ldh [hBGMapMode], a
	call WaitBGMap
	xor a
	ldh [hBGMapMode], a
	ld hl, wJumptableIndex
	ld [hli], a	; (Possibly wJumptableIndex from Crystal) 
	ld [hli], a	; (Possibly wIntroSceneFrameCounter from Crystal) 
	ld [hli], a	; (Possibly wTitleScreenTimer from Crystal) 
	ld [hl], a	; (Possibly wTitleScreenTimer + 1 from Crystal) 
	
	call .load_position_table
		
	
	ld a, %00011010
	ldh [rBGP], a
	ld a, %11100100
	ldh [rOBP0], a
	ret
	
.load_position_table:
	ld hl, FirePositionTable
	ld c, 6	; Load 6 flying objects on the screen. 
	
.set_fire_note_loop
	push bc
	ld e, [hl]
	inc hl
	ld d, [hl]
	inc hl
	push hl
	ld a, $2E	; Title fire/note object effect type? 
	call InitSpriteAnimStruct
	pop hl
	pop bc
	dec c
	jr nz, .set_fire_note_loop
	ret

FirePositionTable::
	dw $4CE0
	dw $58A0
	dw $6490
	dw $70D0
	dw $7CB0
	dw $8800

TitleFireGFX:: INCBIN "gfx/title/fire.2bpp"	; 5EB8-5F37 
TitleNotesGFX:: INCBIN "gfx/title/notes.2bpp"	; 5F38=5FB7 

TitleScreenMain::
	ld a, [wJumptableIndex]
	bit 7, a
	jr nz, .exit
	call TitleScreenSequence
	callba EffectObjectJumpNoDelay	; Bank $23 
	call DelayFrame
	and a
	ret

.exit
	scf
	ret

TitleScreenSequence::
	ld e, a
	ld d, 0
	ld hl, TitleScreenSequenceTable
	add hl, de
	add hl, de
	ld a, [hli]
	ld h, [hl]
	ld l, a
	jp hl
	
TitleScreenSequenceTable::
	dw TitleSeq_Start 
	dw TitleSeq_LoadPokemonLogo 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_MoveTitle 
	dw TitleSeq_MoveTitleEnd 
	dw TitleSeq_InitFlashTitle 
	dw TitleSeq_FlashTitle

	dw TitleSeq_PMJapaneseChara 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_WaitForNextSequence 
	dw TitleSeq_PMSubtitle 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex

	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_WaitForNextSequence 
	dw TitleSeq_Version 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_WaitForNextSequence 
	dw TitleSeq_CopyRight

	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_WaitForNextSequence 
	dw TitleSeq_HoOh 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex 
	dw TitleSeq_IncreaseJumpTableIndex

	dw TitleSeq_WaitForNextSequence 
	dw TitleSeq_PressButtonInit 
	dw TitleSeq_TitleScreenInputAndTimeout 
	dw TitleSeq_FadeMusicOut

TitleSeq_IncreaseJumpTableIndex::
	ld hl, wJumptableIndex
	inc [hl]
	ret

TitleSeq_WaitForNextSequence::
	xor a
	ldh [hBGMapMode], a
	ld hl, wJumptableIndex + 2
	ld a, [hl]
	and a
	jr z, .next_seq
	dec [hl]
	ret

.next_seq
	call TitleSeq_IncreaseJumpTableIndex
	ret

TitleSeq_LoadPokemonLogo::
	call PrintPokemonLogo
	call TitleSeq_IncreaseJumpTableIndex
	ld a, $01
	ldh [hBGMapMode], a
	ret	
	
TitleSeq_Start:: 
	call TitleSeq_IncreaseJumpTableIndex
	push de
	ld de, $002D
	call PlaySFX	; Play "Swish" sound 
	pop de
	ld a, $80
	ld [wJumptableIndex + 2], a
	call SetLYOverrides
	ld a, $43
	ldh [hLCDCPointer], a
	ret

TitleSeq_MoveTitle:: 
	xor a
	ldh [hBGMapMode], a
	ld hl, wJumptableIndex + 2
	ld a, [hl]
	and a
	jr z, .nextseq
	add $04
	ld [hl], a
	ld e, a
.wait
	ldh a, [rLY]
	cp $40
	jr c, .wait
	ld a, e
	call SetLYOverrides
	ret

.nextseq
	call TitleSeq_IncreaseJumpTableIndex
	ret	
	
TitleSeq_MoveTitleEnd::
	xor a
	ldh [hLCDCPointer], a
	call TitleSeq_IncreaseJumpTableIndex
	ld de, MUSIC_TITLE
	call PlayMusic	; Play "Title Theme" 
	ret

TitleSeq_InitFlashTitle::
	call TitleSeq_IncreaseJumpTableIndex
	ld a, %00011010
	ld [wJumptableIndex + 2], a
	ld a, 6
	ld [wJumptableIndex + 3], a
	ret

TitleSeq_FlashTitle:: 
	ld hl, wJumptableIndex + 3
	ld a, [hl]
	and a
	jr z, .exit
	dec [hl]
	ld a, [wJumptableIndex + 2]
	xor %00011010
	ld [wJumptableIndex +2 ], a
	ldh [rBGP], a
	call DelayFrame
	call DelayFrame
	ret

.exit
	call TitleSeq_IncreaseJumpTableIndex
	ld a, %11100100
	ldh [rBGP], a
	ret

TitleSeq_PMJapaneseChara::
	call PrintPMJapaneseChara
	ld a, $10
	ld [wJumptableIndex + 2], a
	call TitleSeq_IncreaseJumpTableIndex
	ld a, $01
	ldh [hBGMapMode], a
	ret

TitleSeq_PMSubtitle::
	call PrintPMSubtitle
	ld a, $10
	ld [wJumptableIndex + 2], a
	call TitleSeq_IncreaseJumpTableIndex
	ld a, $01
	ldh [hBGMapMode], a
	ret

TitleSeq_Version::
	call PrintVersion
	ld a, $10
	ld [wJumptableIndex + 2], a
	call TitleSeq_IncreaseJumpTableIndex
	ld a, $01
	ldh [hBGMapMode], a
	ret

TitleSeq_CopyRight:: 
	call PrintCopyRight
	ld a, $10
	ld [wJumptableIndex + 2], a
	call TitleSeq_IncreaseJumpTableIndex
	ld a, $01
	ldh [hBGMapMode], a
	ret

TitleSeq_HoOh::
	call Set_HoOh
	ld a, $10
	ld [wJumptableIndex + 2], a
	call TitleSeq_IncreaseJumpTableIndex
	ld a, $01
	ldh [hBGMapMode], a
	ret

TitleSeq_PressButtonInit::
	ld hl, wJumptableIndex
	inc [hl]
	ld hl, wJumptableIndex + 2
	ld de, DecodeNybble0Table - 3	; DecodeNybble0Table - 3 = $0C00 
	ld [hl], e
	inc hl
	ld [hl], d
	ret	
	
TitleSeq_TitleScreenInputAndTimeout::
	ld hl, wJumptableIndex + 2
	ld e, [hl]
	inc hl
	ld d, [hl]
	ld a, e
	or d
	jr z, .psbtn_reset
	dec de
	ld [hl], d
	dec hl
	ld [hl], e
	call GetJoypad
	ld hl, hJoyState 
	ld a, [hl]
	and D_UP | B_BUTTON | SELECT	; UP + B + SELECT brings you to the SRAM clear screen. 
	cp D_UP | B_BUTTON | SELECT
	jr z, .psbtn_sramclear
	ld a, [hl]
	and SELECT	; SELECT will bring you to the debug menu. 
	jr nz, .psbtn_gotodebug
	ld a, [hl]
	and $09
	ret z
	
.psbtn_play
	ld a, $00	; MainMenu 
	jr .psbtn_nextseq

.psbtn_gotodebug
if DEBUG 
	ld a, $01	; DebugMenu 
	jr .psbtn_nextseq
else
	ret
endc

.psbtn_sramclear
	ld a, $02
	
.psbtn_nextseq
	ld [wJumptableIndex + 1], a
	ld hl, wJumptableIndex
	set 7, [hl]
	ret

.psbtn_reset
	ld hl, wJumptableIndex
	inc [hl]
	xor a
	ld [wMusicFadeID], a 
	ld [wMusicFadeID + 1], a
	ld hl, wMusicFade
	ld [hl], 8
	ret	
	
TitleSeq_FadeMusicOut::
	ld a, [wMusicFade]
	and a
	ret nz
	ld a, 3
	ld [wJumptableIndex + 1], a
	ld hl, wJumptableIndex
	set 7, [hl]
	ret	

SetLYOverrides::
	ld hl, wLYOverrides
	ld c, $30
.setly_loop
	ld [hli], a
	dec c
	jr nz, .setly_loop
	ret

PrintPMSubtitle::
	coord hl, 2, 6
	ld b, 15
	ld a, $69
	jr LoadPrintArea

PrintVersion::
	coord hl, 4, 1
	ld b, $09
	ld a, $60
	
LoadPrintArea::
	ld [hli], a
	inc a
	dec b
	jr nz, LoadPrintArea
	ret

PrintPMJapaneseChara::
	coord hl, 15, 2
	ld a, "こ"
	lb bc, 4, 4
	jr PrintBoxArea

PrintPokemonLogo::
	coord hl, 15, 3
	ld [hl], $B8
	coord hl, 15, 4
	ld [hl], $B9
	coord hl, 1, 2
	ld a, $80
	ld bc, $0E04
	
PrintBoxArea::
	ld de, SCREEN_WIDTH
	push bc
	push hl
	
.xloop
	ld [hli], a
	inc a
	dec b
	jr nz, .xloop
	pop hl
	add hl, de
	pop bc
	dec c
	jr nz, PrintBoxArea
	ret
	
PrintCopyRight::
	coord hl, 3, 17
	ld a, $41
	ld b, $0D
	
.loop
	ld [hli], a
	inc a
	dec b
	jr nz, .loop
	ret
	
SRAMClearMenu::
	call ClearTileMap
	call GetMemSGBLayout
	call LoadFont
	call LoadFontExtra
	ld hl, SRAMClear_Message
	call PrintText
	ld hl, SRAMClear_WinPOS
	call CopyMenuHeader
	call VerticalMenu
	jp c, Init
	ld a, [wMenuCursorY]
	cp $01
	jp z, Init

	callab InitAllSRAMBanks	; Bank $05
	jp Init

SRAMClear_Message::
	db "<NULL>すべての セーブデータエりアを"
	db "<LINE>クりア しますか?<DONE>"

SRAMClear_WinPOS::
	db 0
	db 7,14,11,19
	dw SRAMClear_TextChoice ; menu data
	db 1 ; default option 

SRAMClear_TextChoice::
	db %11000000
	db 2
	db "いいえ@"
	db "はい@"

IntroCopyRightInfo::
	call ClearTileMap
	call LoadFontExtra
	ld de, TitleScreenGFX
	ld hl, $9600
	lb bc, BANK(TitleScreenGFX), $19
	call Request2bpp

	coord hl, 5, 7
	ld de, IntroCopyRightInfo_Text
	jp PlaceString

IntroCopyRightInfo_Text::
	db $60, $61, $62, $63, $6D, $6E, $6F, $70, $71, $72, $4E	; "(C)1997 Nintendo\n" 
	db $60, $61, $62, $63, $73, $74, $75, $76, $77, $78, $6B, $6C, $4E	; "(C)1997 Creatures Inc.\n" 
	db $60, $61, $62, $63, $64, $65, $66, $67, $68, $69, $6A, $6B, $6C, $50	; "(C)1997 GAME FREAK Inc.{EOL}" 

Set_HoOh::
	coord hl, 7, 9
	ld de, $000D
	ld a, $00
	ld b, $07
.loop
	ld c, $07
.loop2
	ld [hli], a
	inc a
	dec c
	jr nz, .loop2
	add hl, de
	dec b
	jr nz, .loop
	ret

; Unused code, looks like it sets the font type for the logo? 
SetTitleFont::
	ld de, vChars1
	ld hl, TitleScreenLogoGFX
	ld bc, 130 tiles
	ld a, $04
	jp FarCopyDataDouble

; Sets the type of art that will be displayed on the title screen 
; depending on wTitleSequenceOpeningType. 
SetTitleGfx::
	ld hl, wTitleSequenceOpeningType
	ld a, [hl]
	xor $01
	ld [hl], a
	jr nz, .flame
	
.note
	ld hl, TitleNotesGFX
	jr SetTitleGfxNext

.flame
	ld hl, TitleFireGFX
SetTitleGfxNext::
	ld de, vChars0
	ld c, $80
.loop
	ld a, [hli]
	ld [de], a
	inc de
	dec c
	jr nz, .loop
	ret

; if DEBUG
SECTION "engine/title.asm@Title screen TEMPORARY", ROMX
; else
; SECTION "Title screen TEMPORARY", ROMX[$62A2], BANK[$01] ; TODO: merge this with the main section above
; endc
	

GameInit::
	call ClearWindowData
	ld a, $23
	ld [wce5f], a
	jp IntroSequence