forked from TwitchPlaysPokemon/pokepinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.asm
3632 lines (3425 loc) · 53.4 KB
/
home.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
SECTION "rst 00", ROM0
di
jp Entry
SECTION "rst 10", ROM0
jp DelayFrame
SECTION "rst 18", ROM0
jp JumpToFuncInTable
SECTION "rst 20", ROM0
jp _ReadHalfword
SECTION "VBlankInt", ROM0
jp VBlank
SECTION "HBlankInt", ROM0
jp LCD
SECTION "TimerInt", ROM0
jp Timer
SECTION "SerialInt", ROM0
jp Serial
SECTION "JoypadInt", ROM0
jp Joypad
SECTION "Entry", ROM0
Entry: ; 0x100
nop
jp Start
SECTION "Header", ROM0
; The header is generated by rgbfix.
; The space here is allocated to prevent code from being overwritten.
rept $150 - $104
db 0 ;using ds fills the area with the fill value (which may not be $00); if this is changed from $00 the ROM won't build
endr
SECTION "Main", ROM0
Start: ; 0x150
ld [hGameBoyColorFlag], a
ld sp, hGameBoyColorFlag
di
xor a
ld [rIF], a
ld a, [rLCDC] ; LCD Control
bit 7, a ; Check if LCD Display is enabled
jr nz, .LCDDisplayEnabled
set 7, a
ld [rLCDC], a
.LCDDisplayEnabled
ld bc, $0002
call SGBWait1750
.waitForVBlank
ld a, [rLY] ; LY register (LCDC Y-Coordinate)
cp 145 ; > 144 means V-Blank
jr c, .waitForVBlank
ld a, $81
ld [rLCDC], a ; Enable LCD Display
xor a
ld [rBGP], a ; Clear Palette Data
ld [rOBP0], a
ld [rOBP1], a
ld bc, $0002
call SGBWait1750
.waitForVBlank2
ld a, [rLY] ; LY register (LCDC Y-Coordinate)
cp 145 ; > 144 means V-Blank
jr c, .waitForVBlank2
xor a
ld [rLCDC], a ; Disable LCD Display
ld hl, wc000
ld bc, $2000
call ClearData ; Clear WRAM Bank 0
ld hl, vTilesOB
ld bc, $1000
call ClearData ; Clear First half of VRAM
ld a, SRAM_ENABLE
ld [MBC5SRamEnable], a ; Enable RAM
ld a, $1
ld [MBC5RomBank], a ; Load ROM Bank $1
ld a, $0
ld [MBC5RomBankOn], a ; Enable ROM Banking Mode
ld a, $0
ld [MBC5SRamBank], a ; Set bits 5 and 6 of ROM Bank Number
ld a, $1
ld [hLoadedROMBank], a
ld a, $1
ld [MBC5RomBankOn], a ; Enable RAM Banking Mode
ld a, $0
ld [MBC5SRamBank], a ; Load RAM Bank $0
ld sp, wStack ; Initialize stack pointer to the end of WRAM Bank $1
ld hl, hPushOAM
ld bc, $007e
call ClearData ; Clear High RAM (HRAM)
call WriteDMACodeToHRAM
call ClearOAMBuffer
xor a
ld [wd7fb], a
ld [wd7fc], a
ld [wd7fd], a
ld [hHBlankRoutine], a
ld [$ffb1], a
ld [wd8e1], a
ld [wd7fe], a
ld [hSGBInit], a
ld hl, hLCDC
xor a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld a, $8f
ld [hli], a
ld a, $a6
ld [hli], a
ld a, $0
ld [wUpdateAudioEngineUsingTimerInterrupt], a
ld [wToggleAudioEngineUpdateMethod], a
ld a, Bank(PlaySong_BankF)
call SetSongBank
call Func_23b
ld a, [hGameBoyColorFlag]
and a
jr nz, .asm_222
call InitSGB
rl a
and $1
ld [hSGBFlag], a
call SendSGBBorder
ld a, [hSGBFlag]
and a
jr z, .asm_222
ld a, $1
ld [wd917], a
.asm_222
ld a, $1
ld [rIE], a ; Only enable LCD Status interrupt
ei
ld a, $ff
ld [wRNGModulus], a
call ResetRNG
xor a
ld [wBootCheck], a
ld a, BANK(Func_1ffc)
ld hl, Func_1ffc
call BankSwitchSimple
Func_23b: ; 0x23b
ld a, [hGameBoyColorFlag]
cp $11
jr nz, .asm_248
ld a, $1
ld [hGameBoyColorFlag], a
ld [$fffd], a
ret
.asm_248
xor a
ld [hGameBoyColorFlag], a
ld [$fffd], a
ret
SoftReset:
di
ld sp, hGameBoyColorFlag
xor a
ld [rIF], a
ld bc, $2
call SGBWait1750
ld hl, wc000
ld bc, $2000
call ClearData
ld hl, $8000
ld bc, $1000
call ClearData
ld a, SRAM_ENABLE
ld [MBC5SRamEnable], a
ld a, $1
ld [MBC5RomBank], a
ld a, $0
ld [MBC5RomBankOn], a
ld a, $0
ld [MBC5SRamBank], a
ld a, $1
ld [hLoadedROMBank], a
ld a, $1
ld [MBC5RomBankOn], a
ld a, $0
ld [MBC5SRamBank], a
ld sp, wStack
call WriteDMACodeToHRAM
call ClearOAMBuffer
xor a
ld [wd7fb], a
ld [wd7fc], a
ld [wd7fd], a
ld [hHBlankRoutine], a
ld [$ffb1], a
ld [wd8e1], a
ld [wd7fe], a
ld hl, hLCDC
xor a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld a, $8f
ld [hli], a
ld a, $a6
ld [hli], a
ld a, $0
ld [wUpdateAudioEngineUsingTimerInterrupt], a
ld [wToggleAudioEngineUpdateMethod], a
ld a, BANK(Func_3c000)
call SetSongBank
ld a, [hSGBFlag]
and a
jr z, .asm_02d5
ld a, $1
ld [wd917], a
.asm_02d5
ld a, $1
ld [rIE], a
ei
ld a, $ff
ld [wRNGModulus], a
call ResetRNG
ld a, [hGameBoyColorFlag]
ld [$fffd], a
xor a
ld [wBootCheck], a
ld a, $0
ld hl, Func_1ffc
call BankSwitchSimple
; fallthrough
VBlank: ; 0x2f2
push af
push bc
push de
push hl
call hPushOAM ; OAM DMA transfer
ld a, [hLCDC]
ld [rLCDC], a
call Func_113a
ei
ld a, [rLY]
cp $90
jr c, .asm_328
ld hl, hSTAT
ld c, rSTAT - $ff00
ld a, [hli]
ld [$ff00+c], a
inc c
ld a, [hli]
ld [$ff00+c], a
inc c
ld a, [hli]
ld [$ff00+c], a
inc c
inc c
ld a, [hli]
ld [$ff00+c], a
inc c
inc c
ld a, [hli]
ld [$ff00+c], a
inc c
ld a, [hli]
ld [$ff00+c], a
inc c
ld a, [hli]
ld [$ff00+c], a
inc c
ld a, [hli] ;hWY
ld [$ff00+c], a ;into FF4A
inc c
ld a, [hli]
ld [$ff00+c], a
.asm_328
ld a, [hLYC]
ld [hLastLYC], a
ld a, [hNextLYCSub]
ld [hLYCSub], a
ld a, [hNextFrameHBlankSCX]
ld [hHBlankSCX], a
ld a, [hNextFrameHBlankSCY]
ld [hHBlankSCY], a
call ReadJoypad
ld a, [wBootCheck]
and a
jr nz, .skipBootCheck
ld a, [hJoypadState]
cp $f
jr nz, .skipBootCheck
ld a, [hNewlyPressedButtons]
and $f
jr z, .skipBootCheck
ld hl, sp + 8
ld [hl], Func_3c3 & $ff
inc hl
ld [hl], Func_3c3 >> 8
ld a, $1
ld [wBootCheck], a
.skipBootCheck
ld hl, hNumFramesSinceLastVBlank
ld a, [hl]
inc [hl]
and a
jr nz, .asm_365
ld hl, hNumFramesDropped
inc [hl]
.asm_365
ld hl, hVBlankCount
inc [hl]
ld a, [wd8e1]
and a
call nz, Func_167b
ld a, [wUpdateAudioEngineUsingTimerInterrupt]
and a
jr nz, .skipAudioEngineUpdate
ld a, [wAudioEngineEnabled]
and a
call nz, UpdateSFX
.skipAudioEngineUpdate
ld a, [wToggleAudioEngineUpdateMethod]
and a
jr z, .skipTimerToggle
; Enable timer interrupts for audio engine updating.
xor a
ld [wToggleAudioEngineUpdateMethod], a
ld a, $1
ld [wUpdateAudioEngineUsingTimerInterrupt], a
ld a, -68
ld [rTMA], a
ld a, $0
ld [rTAC], a
ld hl, rIE
set 2, [hl]
ld a, $4
ld [rTAC], a ; Timer interrupt will fire ~60 times per second
.skipTimerToggle
ld hl, MBC5SRamBank
ld a, [wd917]
and a
jr nz, .asm_3b5
ld a, [wRumblePattern]
rrca
ld [wRumblePattern], a
and $1
jr z, .asm_3b5
set 3, [hl]
jr .asm_3b7
.asm_3b5
res 3, [hl]
.asm_3b7
ld a, [wDrawBottomMessageBox]
and a
call nz, DrawBottomMessageBox
pop hl
pop de
pop bc
pop af
reti
Func_3c3:
ld a, [rLCDC]
bit 7, a
jr z, .asm_03cf
call FadeOut
; Fades palettes in from white screen.
call DisableLCD
.asm_03cf
ld hl, hSTAT
res 6, [hl]
ld hl, rIE
res 1, [hl]
xor a
ld [MBC5SRamEnable], a
ld [rSB], a
ld [rSC], a
ld [rIE], a
ld [rNR52], a
ld a, [$fffd]
ld [hGameBoyColorFlag], a
jp SoftReset
LCD: ; 0x3ec
push af
push bc
push de
push hl
ld a, [hHBlankRoutine]
sla a
ld c, a
ld b, $0
ld hl, PointerTable_408
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
Func_3ff: ; 0x3ff
ld a, $1
ld [$ffb5], a
pop hl
pop de
pop bc
pop af
reti
PointerTable_408: ; 0x408
dw Func_fbc
dw Func_fbf
dw Func_fea
dw Func_105d
dw Func_109e
dw Func_10a1
dw Func_10a4
dw Func_10a7
Timer: ; 0x418
ei
push af
push bc
push de
push hl
ld a, [wUpdateAudioEngineUsingTimerInterrupt]
and a
jr z, .asm_42a
ld a, [wAudioEngineEnabled]
and a
call nz, UpdateSFX
.asm_42a
ld a, [wToggleAudioEngineUpdateMethod]
and a
jr z, .skipTimer
xor a
ld [wToggleAudioEngineUpdateMethod], a
ld [wUpdateAudioEngineUsingTimerInterrupt], a
; disable timer
ld a, $0
ld [rTAC], a
ld hl, rIE
res 2, [hl]
.skipTimer
pop hl
pop de
pop bc
pop af
reti
Serial: ; 0x445
push af
push bc
push de
push hl
ld hl, Data_45d
push hl
ld a, [$ffb1]
sla a
ld c, a
ld b, $0
ld hl, Data_462
add hl, bc
ld c, [hl]
inc hl
ld b, [hl]
push bc
ret
Data_45d:
db $e1, $d1, $c1, $f1, $d9
Data_462:
db $64, $16, $66, $04, $c9
Joypad: ; 0x467
reti
DelayFrame: ; 0x468
ld a, [rLCDC]
bit 7, a
ret z
ld hl, hNumFramesSinceLastVBlank
xor a
ld [hl], a
.asm_472
ld a, [hl]
and a
jr z, .asm_472
ret
JumpToFuncInTable: ; 0x477
; Jumps to a function in the pointer table immediately following
; a "rst JumpTable" call. Function must be in the same Bank as the pointer table.
; input: a = index of function in table
sla a
pop hl
push de
ld e, a
ld d, $0
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld l, e
ld h, d
pop de
jp hl
_ReadHalfword: ; 0x486
rlca
add l
ld l, a
jr nc, .noCarry
inc h
.noCarry
ld a, [hli]
ld h, [hl]
ld l, a
ret
INCLUDE "home/audio.asm"
CallInFollowingTable: ; 0x532
; Calls a function in a table located immediately after a call to this function.
; Inputs: a = entry in the table
ld e, a
ld d, $0
sla e
rl d
sla e
rl d ; multiplied a by 4 because entries in the table are 4 bytes each
pop hl
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
inc hl
ld a, [hl]
ld h, d
ld l, e
jp BankSwitch
BankSwitchSimple: ; 0x549
; Switches to Bank in register a and jumps to hl.
ld [hLoadedROMBank], a
ld [MBC5RomBank], a ; Load Bank
jp hl
BankSwitch: ; 0x54f
ld e, a
ld a, [hLoadedROMBank] ; currently-loaded Bank
cp e
jr z, .doJump
push af
ld a, e
call .loadNewBank
call .doJump
pop de
ld a, d
.loadNewBank
push hl
push de
ld hl, rIE
ld d, [hl]
ld [hl], $0
ld [MBC5RomBank], a
ld [hLoadedROMBank], a
ld [hl], d
pop de
pop hl
ret
.doJump
ld a, [hFarCallTempE]
ld e, a
ld a, [hFarCallTempA]
jp hl
DisableLCD: ; 0x576
ld a, [rLCDC]
bit 7, a
ret z
ld a, [hLCDC]
res 7, a
ld [hLCDC], a
.asm_581
ld a, [rLCDC]
bit 7, a
jr nz, .asm_581
ret
EnableLCD: ; 0x588
ld a, [hFFC4]
and a
call nz, .UpdatePals
ld a, [hLCDC]
set 7, a
ld [rLCDC], a
ld [hLCDC], a
ret
.UpdatePals
ld de, rBGPI
ld a, $80
ld [de], a
inc de
ld b, $8
.asm_5a0
ld a, [wBGP]
call .UpdateDMGPals
dec b
jr nz, .asm_5a0
ld de, rOBPI
ld a, $80
ld [de], a
inc de
ld b, $4
.asm_5b2
ld a, [wOBP0]
call .UpdateDMGPals
ld a, [wOBP1]
call .UpdateDMGPals
dec b
jr nz, .asm_5b2
ret
.UpdateDMGPals
push bc
ld b, $4
.asm_5c5
push af
push bc
and $3
sla a
ld c, a
ld b, $0
ld hl, GreyscalePalette
add hl, bc
ld a, [hli]
ld [de], a
ld a, [hli]
ld [de], a
pop bc
pop af
srl a
srl a
dec b
jr nz, .asm_5c5
pop bc
ret
GreyscalePalette:
RGB 31, 31, 31
RGB 21, 21, 21
RGB 11, 11, 11
RGB 0, 0, 0
VBlankIntDisable:
ld a, [rIE]
res 0, a
ld [rIE], a
ret
VBlankIntEnable:
ld a, [rIE]
set 0, a
ld [rIE], a
ret
WriteDMACodeToHRAM: ; 0x5f7
; Initializes registers hPushOAM - hFarCallTempA
ld c, $80
ld b, $a ; number of bytes to load
ld hl, DMARoutine
.loop
ld a, [hli]
ld [$ff00+c], a ; add register c to $ff00, and store register a into the resulting address
inc c
dec b
jr nz, .loop
ret
DMARoutine:
; This routine is initially loaded into hPushOAM - hFarCallTempA by WriteDMACodeToHRAM.
ld a, (wOAMBuffer >> 8)
ld [rDMA], a ; start DMA
ld a, $28
.waitLoop ; wait for DMA to finish
dec a
jr nz, .waitLoop
ret
WaitForLCD: ; 0x60f
; Wait for LCD controller to stop reading from both OAM and VRAM because
; CPU can't access OAM, VRAM, or palette data ($ff69, $ff6b) during this time.
ld a, [rSTAT] ; LCDC Status register
and $3
jr nz, WaitForLCD
ld a, $a
.delay40Cycles
dec a
jr nz, .delay40Cycles
ret
INCLUDE "home/copy.asm"
ClearOAMBuffer: ; 0x916
; Clears the OAM buffer by loading $f0 into all of the entries.
ld hl, wOAMBuffer ; 0xd000
ld b, 4 * 40 ; wOAMBuffer is 4 * 40 bytes long (40 OAM entries, 4 bytes each)
ld a, $f0 ; byte to write
.loop
ld [hli], a
dec b
jr nz, .loop
xor a
ld [wOAMBufferSize], a
ret
CleanOAMBuffer: ; 0x926
; Cleans up any trailing unused oam slots in the oam buffer.
ld a, [wOAMBufferSize]
cp wOAMBufferEnd % $100
jr nc, .done
ld l, a
ld h, wOAMBufferEnd / $100
cpl
add (wOAMBufferEnd + 1) % $100
ld b, a
ld a, $f0
.loop
ld [hli], a
dec b
jr nz, .loop
.done
xor a
ld [wOAMBufferSize], a
ret
AdvanceFrames: ; 0x93f
push bc
rst AdvanceFrame
pop bc
dec bc
ld a, c
or b
jr nz, AdvanceFrames
ret
SGBWait1750: ; 0x948
ld de, 1750
.asm_94b
nop
nop
nop
dec de
ld a, d
or e
jr nz, .asm_94b
dec bc
ld a, b
or c
jr nz, SGBWait1750
ret
INCLUDE "home/random.asm"
INCLUDE "home/joypad.asm"
INCLUDE "home/palettes.asm"
HorrendousMultiplyAbyL: ; 0xdd4
; Return a * l to hl
; Stupid waste of space
push bc
ld c, l
ld b, $0
ld hl, $0000
bit 0, a
jr z, .asm_de0
add hl, bc
.asm_de0
sla c
rl b
bit 1, a
jr z, .asm_de9
add hl, bc
.asm_de9
sla c
rl b
bit 2, a
jr z, .asm_df2
add hl, bc
.asm_df2
sla c
rl b
bit 3, a
jr z, .asm_dfb
add hl, bc
.asm_dfb
sla c
rl b
bit 4, a
jr z, .asm_e04
add hl, bc
.asm_e04
sla c
rl b
bit 5, a
jr z, .asm_e0d
add hl, bc
.asm_e0d
sla c
rl b
bit 6, a
jr z, .asm_e16
add hl, bc
.asm_e16
sla c
rl b
bit 7, a
jr z, .asm_e1f
add hl, bc
.asm_e1f
pop bc
ret
ConvertHexByteToDecWord: ; 0xe21
; Convert the base-16 value in register a into a Binary Coded Decimal (base-10) word.
; Example: If a = $97, de = $0151.
ld b, a
ld hl, PowersOfTwo
ld de, $0000
.asm_e28
srl b
ld a, [hli]
jr nc, .asm_e34
add e
daa
ld e, a
ld a, [hl]
adc d
daa
ld d, a
.asm_e34
inc hl
ld a, b
and a
jr nz, .asm_e28
ret
PowersOfTwo: ; 0xe3a
dw $0001
dw $0002
dw $0004
dw $0008
dw $0016
dw $0032
dw $0064
dw $0128
Increment_Max100: ; 0xe4a
; Increments the value at [hl], but caps it at 100.
; Sets carry flag if the increment happens.
ld a, [hl]
cp $64
jr z, .maxValue
inc a
ld [hl], a
scf
ret
.maxValue
and a
ret
Modulo_C: ; 0xe55
; Calculates A modulo C
; Sets zero flag if result is zero
cp c
jr c, .done
sub c
jr Modulo_C
.done
and a
ret
ToggleAudioEngineUpdateMethod: ; 0xe5d
; The audio engine is normally updated once every V-Blank interrupt. However, during pinball gameplay,
; the LCD is disabled (no V-Blanks) when the pinball is transitioning between the Top- and Bottom-halfs of
; the Red and Blue Fields. Therefore, the audio engine wouldn't get updated for a fraction of a second, which
; would has a noticeable pause in the music. To solve this, the Timer interrupt is enabled while the V-Blank is
; disabled, and the audio engine gets updated during the Timer interrupt.
ld a, $1
ld [wToggleAudioEngineUpdateMethod], a
.wait
ld a, [wToggleAudioEngineUpdateMethod]
and a
jr nz, .wait
ret
DrawBottomMessageBox: ; 0xe69
; Draws the current scrolling bottom message box to VRAM during V-Blank.
; Note, this only applies to the 1-tile high message bar. When it displays, things like Ball Bonus summary, and
; the Save/Cancel menu, this is not used to draw the message buffer.
ld a, [rLY]
cp $90
jr nc, DrawBottomMessageBox ; ensure we're in V-Blank
.asm_e6f
ld a, [rSTAT]
and $3
jr nz, .asm_e6f
ld a, $a
.asm_e77
dec a
jr nz, .asm_e77
ld hl, wBottomMessageBuffer + $40
call Load4BottomMessageBytes
push hl
ld hl, $9c00
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c04
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c08
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c0c
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c10
call Write4BottomMessageBytes
pop hl
ld hl, wBottomMessageBuffer + $c0
call Load4BottomMessageBytes
push hl
ld hl, $9c20
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c24
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c28
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c2c
call Write4BottomMessageBytes
pop hl
call Load4BottomMessageBytes
push hl
ld hl, $9c30
call Write4BottomMessageBytes
pop hl
ret
Load4BottomMessageBytes: ; 0xeef
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
ld a, [hli]
ld d, a
ld a, [hli]
ld e, a
ret
Write4BottomMessageBytes: ; 0xef8
ld a, [rSTAT]