-
Notifications
You must be signed in to change notification settings - Fork 75
/
bank0.asm
9868 lines (8878 loc) · 166 KB
/
bank0.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
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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Code for bank 0 ("Home").
; Unlike other banks, this code is always adressable at `0000:xxxx`, without
; the need to switch banks.
SelectRomBank_2100 equ $2100
Start:: ;
; Switch CPU to double-speed if needed
cp GBC ; is running on Game Boy Color?
jr nz, .notGBC
ld a, [rKEY1]
and $80 ; do we need to switch the CPU speed?
jr nz, .speedSwitchDone
ld a, $30 ; \
ld [rJOYP], a ; |
ld a, $01 ; |
ld [rKEY1], a ; | Switch the CPU speed
xor a ; |
ld [rIE], a ; |
stop ; /
.speedSwitchDone
xor a
ld [rSVBK], a
ld a, $01 ; isGBC = true
jr Init
.notGBC
xor a ; isGBC = false
Init::
ldh [hIsGBC], a ; Save isGBC value
call LCDOff ; Turn off screen
ld sp, $DFFF ; Init stack pointer
; Call 003C:6A22
ld a, $3C
ld [SelectRomBank_2100], a
call label_6A22
; Clear registers
xor a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
; Clear Tiles Map 0
ld hl, vTiles0
ld bc, $1800
call ClearBytes
; Clear Tiles Map 1 (if GBC)
ld a, $24
ld [SelectRomBank_2100], a
call ClearTilesMap1
; Clear Background Map
call ClearBGMap
call ClearHRAMAndWRAM
; Copy DMA routine to HRAM
ld a, $01
ld [SelectRomBank_2100], a
call WriteDMACodeToHRAM
; Initiate DMA transfer
call hDMARoutine
call LCDOn
; Load default tiles
call LoadBank0CTiles
; Initialize LCD Status register
; Bit 6: LYC coincidence interrupt enabled
; Bit 5: Mode 2 OAM interrupt disabled
; Bit 4: Mode 1 V-Blank interrupt disabled
; Bit 3: Mode 0 H-Blank interrupt disabled
; Bit 2-0: read-only
ld a, %01000100
ld [rSTAT], a
; Initialize LY Compare register
; Request a STAT interrupt when LY equals $4F
ld a, $4F
ld [rLYC], a
; Initialize wCurrentBank
ld a, $01
ld [wCurrentBank], a
; Initialize Interrupts
; Bit 4: Joypad interrupt disabled
; Bit 3: Serial interrupt disabled
; Bit 2: Timer interrupt disabled
; Bit 1: LCD STAT interrupt disabled
; Bit 0: V-Blank interrupt enabled
ld a, %00001
ld [rIE], a
; Initialize save files
call InitSaveFiles
; Initialize sound
; (calls 001F:4000)
ld a, $1F
ld [SelectRomBank_2100], a
call label_4000
; Ignore joypad input during 24 frames
ld a, 24
ldh [hButtonsInactiveDelay], a
; Enable interrupts
ei
; If GBC, clear WRAM Bank 5
; (calls 20:4854)
ld a, $20
ld [SelectRomBank_2100], a
call label_4854
; Start rendering
jp WaitForNextFrame
RenderLoop::
; Set DidRenderFrame
ld a, 1
ldh [hDidRenderFrame], a
; Special case for $C500 == 1 (alternate background position)
; If $C500 != 0...
ld a, [$C500]
and a
jr z, .applyRegularScrollYOffset
; and GameplayType == OVERWORLD...
ld a, [wGameplayType]
cp GAMEPLAY_OVERWORLD
jr nz, .applyRegularScrollYOffset
; set scroll Y to $00 or $80 alternatively every other frame.
ldh a, [hFrameCounter]
rrca
and $80
jr .setScrollY
.applyRegularScrollYOffset
; Compose the base offset and the screen shake offset
ld hl, wScreenShakeVertical
ldh a, [hBaseScrollY]
add a, [hl]
.setScrollY
ld [rSCY], a ; scrollY
; Set ScrollX
ldh a, [hBaseScrollX]
ld hl, wScreenShakeHorizontal
add a, [hl]
ld hl, $C1BF
add a, [hl]
ld [rSCX], a ; scrollX
; If the LCD screen is off, load new map data
ld a, [$D6FE]
and a ; if $D6FE != 0, LoadNewMap
jr nz, RenderLoopLoadNewMap
ld a, [$D6FF] ; tilemap to load?
cp $00 ; if $D6FF != 0, LoadNewMap
jr z, RenderFrame
RenderLoopLoadNewMap::
; Control audio during the transition
ld a, [wGameplayType]
cp GAMEPLAY_MARIN_BEACH
jr z, .playAudioStep
cp GAMEPLAY_FILE_SAVE
jr c, .playAudioStep
cp GAMEPLAY_OVERWORLD
jr nz, .skipAudio
; GameplayType == OVERWORLD
ld a, [wGameplaySubtype]
cp $07
jr nc, .skipAudio
.playAudioStep
call PlayAudioStep
call PlayAudioStep
.skipAudio
di
call LoadMapData
ei
call PlayAudioStep
call PlayAudioStep
jp WaitForNextFrame
RenderFrame::
; Update LCD status flags
ld a, [wLCDControl]
and $7F
ld e, a
ld a, [rLCDC]
and $80
or e
ld [rLCDC], a
; Increment the global frame counter
ld hl, hFrameCounter
inc [hl]
; Special case for the intro screen sprites
ld a, [wGameplayType]
cp GAMEPLAY_INTRO
jr nz, RenderWarpTransition
; GameplayType == INTRO
ld a, [wGameplaySubtype]
cp $08
jr c, RenderWarpTransition
; GameplaySubtype > GAMEPLAY_INTRO_BEACH
ld a, $20
ld [SelectRomBank_2100], a
call label_5257 ; position sprites for the title screen?
RenderWarpTransition::
ld a, [wWarpTransition]
and a
jp z, RenderInteractiveFrame
inc a
jr nz, label_279
label_26E::
ld a, $17
ld [SelectRomBank_2100], a
call label_48DD
jp RenderInteractiveFrame
label_279::
inc a
jr z, label_26E
ld a, $14
ld [SelectRomBank_2100], a
ld a, [$C180]
inc a
ld [$C180], a
cp $C0
jr nz, label_2A0
ld a, [wWarpTransition]
cp $02
jr nz, label_296
call label_4E51
label_296::
xor a
ld [wWarpTransition], a
ld [$C3CA], a
jp RenderInteractiveFrame
label_2A0::
push af
cp $60
jr c, label_2B7
ldh a, [hIsGBC]
and a
jr z, label_2B4
ld a, $20
ld [SelectRomBank_2100], a
call label_6CA7
jr label_2B7
label_2B4::
call label_4FE8
label_2B7::
ld a, $14
ld [SelectRomBank_2100], a
pop af
call label_5038
call PlayAudioStep
ld a, [wBGPalette]
ld [rBGP], a
ld a, [wOBJ0Palette]
ld [rOBP0], a
ld a, [wOBJ1Palette]
ld [rOBP1], a
jp WaitForNextFrame
RenderInteractiveFrame::
; Update graphics registers from game values
ld a, [wWindowY]
ld [rWY], a
ld a, [wBGPalette]
ld [rBGP], a
ld a, [wOBJ0Palette]
ld [rOBP0], a
ld a, [wOBJ1Palette]
ld [rOBP1], a
call PlayAudioStep
call ReadJoypadState
; If NeedsUpdatingBGTiles or NeedsUpdatingEnnemiesTiles or NeedsUpdatingNPCTiles…
ldh a, [hNeedsUpdatingBGTiles]
ld hl, hNeedsUpdatingEnnemiesTiles
or [hl]
ld hl, wneedsUpdatingNPCTiles
or [hl]
; skip further rendering: the vblank interrupt will load the required data
jr nz, WaitForNextFrame
; Debug functions
ld a, [ROM_DebugTool1]
and a ; Is debug mode disabled?
jr z, RenderUpdateSprites
ld a, [wEnginePaused]
and a ; Is engine already paused?
jr nz, .engineIsPaused
ldh a, [hPressedButtonsMask]
and J_RIGHT | J_LEFT | J_UP | J_DOWN ; Are none of the directional keys pressed?
jr z, .saveEngineStatus
.engineIsPaused
ldh a, [$FFCC]
and J_SELECT ; Was Select button just pressed?
jr z, .saveEngineStatus
; If Select button was just pressed,
; toogle engine paused status.
ld a, [wEnginePaused]
xor $01
ld [wEnginePaused], a
; If the engine was just paused, skip the rest of the render loop
jr nz, WaitForNextFrame
; If the engine was just unpaused,
; toggle Free-movement mode.
ld a, [wFreeMovementMode]
xor $10
ld [wFreeMovementMode], a
jr WaitForNextFrame
.saveEngineStatus
; If the engine is paused, skip the rest of the render loop
ld a, [wEnginePaused]
and a
jr nz, WaitForNextFrame
RenderUpdateSprites::
; If not in Inventory, update sprites
ld a, [wGameplayType]
cp GAMEPLAY_INVENTORY
jr nz, .updateSprites
; If Inventory is actually visible, skip sprites update
ld a, [wGameplaySubtype]
cp GAMEPLAY_INVENTORY_DELAY1
jr c, RenderGameplay
.updateSprites
ld a, $01
call SwitchBank
call label_5F2E ; sprite-related-method
RenderGameplay::
call ExecuteGameplayHandler
RenderPalettes::
; If isGBC
ldh a, [hIsGBC]
and a
jr z, .resetDDD2
; update palettes
ld a, $21
call SwitchBank
call label_406E ; update palette set defined in $DDD2?
.resetDDD2
xor a
ld [$DDD2], a
RenderWindow::
ld a, $01
call SwitchBank
call UpdateWindowPosition
WaitForNextFrame::
ld a, $1F
call SwitchBank
call label_7F80
ld a, $0C
call AdjustBankNumberForGBC
call SwitchBank
xor a
ldh [hDidRenderFrame], a ; Waiting for next frame
halt
PollNeedsRenderingFrame::
; Loop until hNeedsRenderingFrame != 0
ldh a, [hNeedsRenderingFrame]
and a
jr z, PollNeedsRenderingFrame
; Clear hNeedsRenderingFrame
xor a
ldh [hNeedsRenderingFrame], a
; Jump to the top of the render loop
jp RenderLoop
IntroSeaScreenSections::
; Indexes of rows to divide the screen in horizontal sections.
; This is used to enable differential scrolling during the sea intro sequence.
db $20, $30, $40, $60, 0 ; upper clouds, lower clouds, sea, upper waves, lower waves
IntroBeachScreenSections::
; Indexes of rows to divide the screen in horizontal sections.
; This is used to enable differential scrolling during the beach intro sequence.
db $30, $56, $68, 0 ; moutains, trees, beach, waves
InterruptLCDStatus::
; Manipulate the Background's scrollX and scrollY value while the screen is drawn,
; to create various effects like differential scrolling.
di
push af
push hl
push de
push bc
ld a, [rSVBK] ; Save current WRAM Bank to c
ld c, a ;
xor a ; Load WRAM Bank 1 (as "0" fallbacks to loading bank 1)
ld [rSVBK], a ;
ld a, [wGameplayType]
cp GAMEPLAY_CREDITS ; if GameplayType != GAMEPLAY_CREDITS
jr nz, skipScrollY
; GameplayType == CREDITS
ld a, [wGameplaySubtype]
cp $05 ; if GameplaySubtype != 5
jr nz, setStandardScrollY
; GameplaySubtype == 5
ld a, [$D000] ; override scrollY with WRA1:$D000 value
jr setScrollY
setStandardScrollY::
; Set standard scrollY, without specific offset
ldh a, [hBaseScrollY]
setScrollY::
ld [rSCY], a ; scrollY
jp restoreSavedWRAMBankAndReturn
skipScrollY::
cp GAMEPLAY_INTRO ; if not during the introduction sequence
jr nz, clearScrollX ; skip
; GameplayType == INTRO
; Apply differential scrolling to each section:
; load and apply the scrollX offset for the current screen section being drawn
ld a, [wLCDSectionIndex]
ld e, a ; hl = ScrollXOffsetForSection + LCDSectionIndex
ld d, $00 ;
ld hl, wScrollXOffsetForSection
add hl, de ;
ld a, [hl]
ld hl, hBaseScrollX ; a = hBaseScrollX + [hl]
add a, [hl]
ld [rSCX], a ; set scrollX
ld a, [wGameplaySubtype]
cp $06 ; if GameplaySubtype < 6 (intro sea)
jr c, setupNextInterruptForIntroSea
; If TransitionCounter >= 6 (intro beach)
setupNextInterruptForIntroBeach::
ld hl, IntroBeachScreenSections
add hl, de ; hl = ScreenSectionsTable + SectionIndex
ld a, [hl] ;
ld [rLYC], a ; Fire LCD Y-compare interrupt when reaching the row for the next section
ld a, e ; a = SectionIndex + 1
inc a ;
and $03 ; a = a % 4
ld [wLCDSectionIndex], a ; save SectionIndex
jr restoreSavedWRAMBankAndReturn
setupNextInterruptForIntroSea::
ld hl, IntroSeaScreenSections
add hl, de ; hl = LCDScreenSectionsTable + SectionIndex
ld a, [hl] ;
ld [rLYC], a ; Fire LCD Y-compare interrupt when reaching the row for the next section
ld a, e ; a = SectionIndex + 1
inc a ;
cp $05 ; if SectionIndex != 5
jr nz, skipResetSectionIndex ; skip
; If SectionIndex reached 5, reset it to 0
xor a ; a = 0
skipResetSectionIndex::
ld [wLCDSectionIndex], a ; save SectionIndex
nop
cp $04 ; if SectionIndex != 4
jr nz, restoreSavedWRAMBankAndReturn ; skip
; If we are drawing the last section (4)
ld a, [wIntroBGYOffset] ; Apply the Y offset to compensate for sea vertical movement
ld [rSCY], a ; (so that the horizon position stays constant).
cpl ; a = $FF - a + $61
inc a ;
add a, $60 ;
ld [rLYC], a ; Fire LCD Y-compare interrupt when reaching the row for the next transition step
jr restoreSavedWRAMBankAndReturn
clearScrollX::
xor a
ld [rSCX], a ; scrollX
restoreSavedWRAMBankAndReturn::
ld a, c
ld [rSVBK], a
pop bc
pop de
pop hl
pop af
ei
reti
InterruptSerial::
push af
ld a, $28
ld [SelectRomBank_2100], a
call label_4601
ld a, [wCurrentBank]
ld [SelectRomBank_2100], a
pop af
reti
; Load tileset, background, sprites while the LCD screen is off
LoadMapData::
ld a, [$D6FE]
and a
jr z, .commonCase
;
; $D6FE != 0: special case
;
ld [$DDD2], a
cp $23 ; if $D6FE == $23
jr z, .skipLCDOff
push af
call LCDOff
pop af
.skipLCDOff
call .executeMapLoadFunction
jr .clearValuesAndReturn
.executeMapLoadFunction
ld e, a
ld a, $20
ld [SelectRomBank_2100], a
; label_4657
; input: $D6FE in e
; output: address to jump to in hl
; Table address: 20:4664
; Table values:
; 01 $309B
; 02 $28F7
; 03 $2BCF
; 04 $2C03
; 05 $2D2D
; 06 $2C28
; 07 $2D2D
; 08 $28F0
; 09 $2E73
; ...
call label_4657
jp [hl]
;
; $D6FE == 0: common case
;
.commonCase
call LCDOff
ld a, $24
ld [SelectRomBank_2100], a
call label_5C2C
ld a, $20
ld [SelectRomBank_2100], a
call label_4577
ld a, $08
ld [SelectRomBank_2100], a
call label_292D
ld a, $0C
call AdjustBankNumberForGBC
ld [SelectRomBank_2100], a
.clearValuesAndReturn
xor a
ld [$D6FF], a
ld [$D6FE], a
ld a, [wLCDControl]
ld [rLCDC], a
ret
data_046A::
db 7, 9
InterruptVBlank::
push af
push bc
push de
push hl
; Adjust loaded bank
ld a, [rSVBK]
and $07
ld c, a
xor a
ld [rSVBK], a
push bc
di
;
; Photo Album handling
;
ld a, [wGameplayType]
cp GAMEPLAY_PHOTO_ALBUM
jr nz, .continue
; GameplayType == PHOTO_ALBUM
ld a, [wGameplaySubtype]
cp $09
jr c, .continue
cp $12
jp c, PhotoAlbumVBlankHandler
.continue
ldh a, [hDidRenderFrame]
and a
jp nz, WaitForVBlankAndReturn ; if not already waiting for next frame, do
;
; Dialog handling
;
ld a, [wDialogState]
and $7F ; If dialog is closed
jr z, vBlankContinue
cp DIALOG_OPENING_1 ; If DialogState == 1
jr z, vBlankContinue
cp DIALOG_OPENING_5 ; If DialogState > 5
jr nc, .renderDialogText
; DialogState < 5
; Open dialog
call label_23E4
ld hl, wDialogState
inc [hl] ; Increment DialogState
jp WaitForVBlankAndReturn
.renderDialogText
cp DIALOG_SCROLLING_1 ; if DialogState != Scrolling
jr nz, .renderDialogTextContinue
; DialogState == Scrolling
call DialogBeginScrolling
jp WaitForVBlankAndReturn
.renderDialogTextContinue
cp DIALOG_SCROLLING_2 ; if DialogState != Scrolling2
jr nz, vBlankContinue
ld a, [wDialogScrollDelay]
and a ; if DialogScrollDelay == 0
jr z, .DialogFinishScrolling
; DialogScrollDelay > 0
dec a ; decrement the delay
ld [wDialogScrollDelay], a
jr vBlankContinue
.DialogFinishScrolling
call DialogFinishScrolling
jp WaitForVBlankAndReturn
;
; Photo Picture handling
;
vBlankContinue::
ld a, [wGameplayType]
cp GAMEPLAY_PHOTO_DIZZY_LINK ; If GameplayType < Photo Picture
jr c, .continue3
; GameplayType is one of the Pictures
ld a, [wGameplaySubtype]
cp $06
jr c, label_52B
ld a, $38
ld [SelectRomBank_2100], a
call label_785A
jr label_52B
.continue3
ld a, [$D6FE]
and a
jr nz, WaitForVBlankAndReturn
ldh a, [hNeedsUpdatingBGTiles]
ldh [$FFE8], a
ld hl, hNeedsUpdatingEnnemiesTiles
or [hl]
ld hl, wneedsUpdatingNPCTiles
or [hl]
jr z, label_509
call label_5BC ; Copy tiles?
ldh a, [$FFE8]
cp $08
jr nc, label_504
label_501::
call DrawLinkSprite
label_504::
call hDMARoutine
jr WaitForVBlankAndReturn
label_509::
ldh a, [$FFBB]
and a
jr z, label_521
dec a
ldh [$FFBB], a
ld e, a
ld d, $00
ld hl, data_046A
add hl, de
ld a, [hl]
ld [$D6F8], a
call label_1ED7
jr label_501
label_521::
ld a, [wGameplayType]
cp GAMEPLAY_PHOTO_ALBUM
jr z, label_52B
call AnimateTiles
label_52B::
ldh a, [hIsGBC]
and a
jr z, .notGBC
ld a, $24
ld [SelectRomBank_2100], a
call label_5C1A ; Change BG column palette. Triggered by an interrupt?
.notGBC
ld de, $D601
call label_2927 ; Load BG column tiles
xor a
ld [$D600], a
ld [$D601], a
ld [$DC90], a
ld [$DC91], a
ld a, $36
ld [SelectRomBank_2100], a
call label_72BA
call hDMARoutine
ldh a, [hIsGBC]
and a
jr z, WaitForVBlankAndReturn
ld a, $21
ld [SelectRomBank_2100], a
call label_4000
ld a, [wCurrentBank]
ld [SelectRomBank_2100], a
WaitForVBlankAndReturn::
ei
WaitForVBlankAndReturn_direct::
pop bc
ld a, c
ld [rSVBK], a
pop hl
pop de
pop bc
ld a, $01
ldh [hNeedsRenderingFrame], a
pop af
reti
PhotoAlbumVBlankHandler::
ld a, [wCurrentBank]
push af
ldh a, [hDidRenderFrame]
and a
jr nz, label_5AB
call hDMARoutine
ldh a, [hIsGBC]
and a
jr z, label_598
ld a, $21
call SwitchBank
call label_4000
ld a, $24
call SwitchBank
call label_5C1A
label_598::
ld de, $D601
call label_2927
xor a
ld [$D600], a
ld [$D601], a
ld [$DC90], a
ld [$DC91], a
label_5AB::
ld a, $28
call SwitchBank
call label_4616
pop af
ld [wCurrentBank], a
ld [SelectRomBank_2100], a
jr WaitForVBlankAndReturn_direct
; Copy tiles?
label_5BC::
ldh a, [hNeedsUpdatingBGTiles]
and a
jp z, label_69E
cp $07
jp z, label_7B0
cp $03
jp z, $0062
cp $04
jp z, $006A
cp $05
jp z, $0072
cp $06
jp z, $007A
cp $08
jp nc, label_7D3
ld a, [$DBA5]
and a
jp z, label_656
ldh a, [hNeedsUpdatingBGTiles]
cp $02
jp z, label_826
ld a, $0D
call AdjustBankNumberForGBC
ld [SelectRomBank_2100], a
ldh a, [$FF92]
ld c, a
ld b, $00
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld hl, $9000
add hl, bc
ld e, l
ld d, h
ld hl, $5000
ldh a, [$FFF7]
cp $FF
jr nz, label_62F
ld a, $20
ld [SelectRomBank_2100], a
call label_4616
ld [SelectRomBank_2100], a
jr label_641
label_62F::
ldh a, [$FF94]
add a, $50
ld h, a
add hl, bc
ldh a, [$FFBB]
and a
jr z, label_641
ldh a, [$FF92]
dec a
cp $02
jr c, label_647
label_641::
ld bc, $0040
call CopyData
label_647::
ldh a, [$FF92]
inc a
ldh [$FF92], a
cp $04
jr nz, label_655
xor a
ldh [hNeedsUpdatingBGTiles], a
ldh [$FF92], a
label_655::
ret
label_656::
ld a, $0F
call AdjustBankNumberForGBC
ld [SelectRomBank_2100], a
ldh a, [$FF92]
ld c, a
ld b, $00
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld hl, $9000
add hl, bc
ld e, l
ld d, h
ldh a, [$FF94]
add a, $40
ld h, a
ld l, $00
add hl, bc
ld bc, $0040
call CopyData
ldh a, [$FF92]
inc a
ldh [$FF92], a
cp $08
jr nz, label_69D
xor a
ldh [hNeedsUpdatingBGTiles], a
ldh [$FF92], a
label_69D::
ret
label_69E::
ldh a, [hIsGBC]
and a
jr z, label_6CB
ldh a, [$FFF7]
cp $FF
jr nz, label_6CB
ld a, $20
ld [SelectRomBank_2100], a
call label_475A
xor a
ld [wneedsUpdatingNPCTiles], a
ld [$C10F], a
ld hl, $9000
ld bc, $0000
call label_4616
ld c, $90
ld b, h
ld h, $00
call label_A13
jr label_738
label_6CB::
ldh a, [hNeedsUpdatingEnnemiesTiles]
and a
jp z, label_73E
ld a, [$C197]
ld e, a
ld d, $00
ld hl, $C193
add hl, de
ld a, [hl]
push af
and $3F
ld d, a
ld e, $00
pop af
swap a
rra
rra
and $03
ld c, a
ld b, $00
ld hl, data_2E6F
add hl, bc
ld a, [hl]
and a
jr z, label_6F7
call AdjustBankNumberForGBC
label_6F7::
ld [SelectRomBank_2100], a
ldh a, [$FF93]
ld c, a
ld b, $00
sla c
rl b