-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank02.asm
825 lines (714 loc) · 9.18 KB
/
bank02.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
SECTION "bank2", ROMX, BANK[$2]
Bank2Start: ; 2:4000
db 2
Function24001: ; 2:4001
jp Function24035
; 0x8004
StartMusic: ; 2:4004
jp _StartMusic
; 0x8007
Function24007: ; 2:4007
jp Function24027
; 0x800a
Function2400a: ; 2:400a
jp Function2401a
; 0x800d
ResetAndFullVolume: ; 2:400d
call TurnAllSoundOff
xor a
ld [hffa3], a
ld [$ffb4], a
ld a, $77
ld [rNR50], a
ret
; 0x801a
Function2401a: ; 2:401a
push af
ld a, $1
ld [$ffb4], a
xor a
call TurnAllSoundOff
pop af
jp _StartMusic
; 0x8027
Function24027: ; 2:4027
xor a
ld [$ffb1], a
ld [hffa3], a
TurnAllSoundOff: ; 2:402c
call ResetAllSoundRegisters
ld [rNR52], a
dec a
ld [rNR52], a
ret
; 0x8035
Function24035: ; 2:4035
call Function2403c
call Function240f9
ret
; 0x803c
Function2403c: ; 2:403c
ld a, [hffa3]
or a
jr nz, .asm_804c
ld [hffa7], a
ld [hffa8], a
ld [hffa9], a
ld [hffaa], a
ld [hffab], a
ret
.asm_804c
dec a
ld [hffa3], a
ret nz
ld a, [hffa4]
ld l, a
ld a, [hffa5]
ld h, a
.asm_8056
ld a, [hli]
cp $0
jp z, .asm_80c7
cp $1
jr z, .asm_80aa
cp $2
jr z, .asm_80a8
cp $3
jr z, .asm_8096
cp $fe
jr z, .asm_8090
cp $ff
jr z, .asm_8080
sub $4
ld [hffa3], a
jp z, .asm_80f2
ld b, a
ld a, [hffa6]
add b
ld [hffa3], a
jp .asm_80f2
.asm_8080
call Function243ab
and [hl]
inc hl
ld [hffa2], a
call Function243ab
and [hl]
inc hl
ld [hffa6], a
jr .asm_8056
.asm_8090
ld a, [hli]
ld e, a
ld h, [hl]
ld l, e
jr .asm_8056
.asm_8096
ld a, [hli]
ld [rNR41], a
ld a, [hli]
ld [rNR42], a
ld a, [hli]
ld [rNR43], a
ld a, [hli]
ld [rNR44], a
ld a, $ff
ld [hffaa], a
jr .asm_8056
.asm_80a8
jr .asm_8056
.asm_80aa
ld a, [hli]
ld [rNR21], a
ld a, [hli]
ld [rNR22], a
ld a, [hffa2]
ld b, a
or a
ld a, [hli]
add b
ld [rNR23], a
ld a, $0
adc [hl]
inc hl
and $c7
ld [rNR24], a
ld a, $ff
ld [hffa8], a
jp .asm_8056
.asm_80c7
ld a, $1
ld [rNR10], a
xor a
ld [rNR11], a
ld [rNR12], a
ld [rNR14], a
ld a, [hli]
ld [rNR10], a
ld a, [hli]
ld [rNR11], a
ld a, [hli]
ld [rNR12], a
ld a, [hffa2]
ld b, a
or a
ld a, [hli]
add b
ld [rNR13], a
ld a, $0
adc [hl]
inc hl
and $c7
ld [rNR14], a
ld a, $ff
ld [hffa7], a
jp Function2403c.asm_8056
.asm_80f2
ld a, l
ld [hffa4], a
ld a, h
ld [hffa5], a
ret
; 0x80f9
Function240f9: ; 2:40f9
ld a, [$ffb4]
or a
ret nz
ld a, [$ffb1]
or a
jp nz, Function2410b
ld a, [rNR52]
and $f
jp nz, Function241dd
ret
; 0x810b
Function2410b: ; 2:410b
dec a
ld [$ffb1], a
jp nz, Function241dd
ld a, [$ffaf]
ld l, a
ld a, [$ffb0]
ld h, a
Function24117: ; 2:4117
ld a, [$ffac]
ld b, a
ld a, [hl]
cp $fe
jp z, Function241d8
jp nc, Function241dd
sub b
jp c, Function2413d
sub $10
jp c, Function24188
sub $10
jp c, Function241c7
ld [$ffb1], a
inc hl
ld a, l
ld [$ffaf], a
ld a, h
ld [$ffb0], a
jp Function241dd
; 0x813d
Function2413d: ; 2:413d
add b
inc hl
push hl
ld e, a
ld d, $0
ld a, [$ffad]
ld l, a
ld a, [$ffae]
ld h, a
add hl, de
ld c, [hl]
ld b, d
ld a, [$ffac]
ld e, a
add hl, de
ld a, [hl]
sub $3
push af
ld hl, $ffce
add hl, bc
ld c, [hl]
ld hl, $44c4
add hl, bc
ld e, [hl]
ld hl, $ffc8
ld a, c
cp $48
jp nc, Function24178
ld hl, $44c0
swap c
srl c
ld a, c
and $3
ld c, a
add hl, bc
ld c, [hl]
ld hl, $ffb6
add hl, bc
Function24178: ; 2:4178
ld a, $1
ld [hli], a
ld a, e
ld [hli], a
pop af
ld [hli], a
inc hl
inc hl
ld a, $1
ld [hl], a
pop hl
jp Function24117
; 0x8188
Function24188: ; 2:4188
add $10
inc hl
push hl
ld c, a
ld b, $0
ld hl, $ffce
add hl, bc
ld c, [hl]
ld hl, $450e
add hl, bc
ld e, [hl]
ld a, e
or a
jp z, Function241c3
ld hl, $ffc8
ld a, c
cp $48
jp nc, Function241b8
ld hl, $44c0
swap c
srl c
ld a, c
and $3
ld c, a
add hl, bc
ld c, [hl]
ld hl, $ffb6
add hl, bc
Function241b8: ; 2:41b8
ld a, $1
ld [hli], a
ld a, e
ld [hli], a
inc hl
inc hl
inc hl
ld a, $1
ld [hl], a
Function241c3: ; 2:41c3
pop hl
jp Function24117
; 0x81c7
Function241c7: ; 2:41c7
add $10
inc hl
ld c, a
ld b, $0
ld a, [hli]
push hl
ld hl, $ffce
add hl, bc
ld [hl], a
pop hl
jp Function24117
; 0x81d8
Function241d8: ; 2:41d8
inc hl
ld a, [hl]
jp _StartMusic
; 0x81dd
Function241dd: ; 2:41dd
ld bc, $ffb6
ld de, $0000
Function241e3: ; 2:41e3
ld a, [bc]
or a
jp z, Function242fd
dec a
ld [bc], a
jp nz, Function242fd
ld hl, hffa7
add hl, de
ld a, [hl]
or a
jp z, Function241fb
xor a
ld [bc], a
jp Function242fd
; 0x81fb
Function241fb: ; 2:41fb
push bc
push de
ld hl, $44b8
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
push de
inc bc
ld a, [bc]
inc bc
ld hl, $4558
ld d, $0
ld e, a
sla e
rl d
sla e
rl d
add hl, de
sla e
rl d
add hl, de
ld d, h
ld e, l
ld a, [de]
inc de
bit 0, a
jp z, Function24246
push af
ld a, [bc]
inc bc
ld hl, $4416
add a
add l
ld l, a
ld a, $0
adc h
ld h, a
ld a, [de]
inc de
add [hl]
inc hl
ld [bc], a
inc bc
ld a, $0
adc [hl]
ld l, a
pop af
and $80
or l
ld [bc], a
dec bc
jp Function24250
; 0x8246
Function24246: ; 2:4246
inc bc
inc bc
inc de
and $80
ld l, a
ld a, [bc]
or l
ld [bc], a
dec bc
Function24250: ; 2:4250
ld h, b
ld l, c
ld a, [de]
inc de
add [hl]
ld [hli], a
ld a, [de]
inc de
adc [hl]
ld [hli], a
and $38
jp z, Function24264
dec hl
dec hl
xor a
ld [hli], a
ld [hli], a
Function24264: ; 2:4264
ld b, h
ld c, l
ld h, d
ld l, e
ld a, [rNR51]
and [hl]
inc hl
or [hl]
inc hl
ld [rNR51], a
ld d, h
ld e, l
ld hl, sp+$4
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [de]
inc de
ld [hli], a
ld a, [bc]
or a
jp z, Function2428c
dec a
ld [bc], a
jp nz, Function2428c
ld a, [de]
inc de
ld [hl], a
ld a, [de]
ld [bc], a
jp Function2428d
; 0x828c
Function2428c: ; 2:428c
inc de
Function2428d: ; 2:428d
inc de
pop hl
ld a, [de]
inc de
cp $fd
jp z, Function242d8
cp $fe
jp z, Function242a8
jp nc, Function242ee
ld [hli], a
ld a, [de]
inc de
ld [hli], a
ld a, [de]
inc de
ld [hli], a
jp Function242f1
; 0x82a8
Function242a8: ; 2:42a8
ld a, [de]
ld hl, $ffb5
cp [hl]
jp z, Function242c7
ld [hl], a
ld c, a
ld b, $0
ld hl, $43d6
add hl, bc
xor a
ld [rNR30], a
ld bc, $ff30
ld d, $10
Function242c0: ; 2:42c0
ld a, [hli]
ld [bc], a
inc bc
dec d
jp nz, Function242c0
Function242c7: ; 2:42c7
ld a, $20
ld [rNR32], a
ld a, $80
ld [rNR30], a
ld bc, $ffc5
ld hl, rNR33
jp Function242f3
; 0x82d8
Function242d8: ; 2:42d8
ld a, [de]
inc de
ld [rNR42], a
ld a, [de]
ld e, a
ld a, [$ffca]
and $7
swap a
or e
ld [rNR43], a
ld a, $80
ld [rNR44], a
pop af
pop af
ret
; 0x82ee
Function242ee: ; 2:42ee
inc hl
inc hl
inc hl
Function242f1: ; 2:42f1
dec bc
dec bc
Function242f3: ; 2:42f3
ld a, [bc]
inc bc
ld [hli], a
ld a, [bc]
ld [hl], a
and $7f
ld [bc], a
pop de
pop bc
Function242fd: ; 2:42fd
ld hl, $0006
add hl, bc
ld b, h
ld c, l
inc de
ld a, e
cp $4
jp nz, Function241e3
ret
; 0x830b
_StartMusic: ; 2:430b
ld b, a
bit 7, a
jr nz, .asm_836e
bit 6, a
jr nz, .asm_8318
ld a, [hffab]
or a
ret nz
.asm_8318
xor a
ld [hffa3], a
ld [hffa2], a
ld [hffa6], a
ld a, [hffa7]
or a
jp z, .asm_832a
xor a
ld [rNR12], a
ld [hffa7], a
.asm_832a
ld a, [hffa8]
or a
jp z, .asm_8335
xor a
ld [rNR22], a
ld [hffa8], a
.asm_8335
ld a, [hffa9]
or a
jp z, .asm_8340
xor a
ld [rNR32], a
ld [hffa9], a
.asm_8340
ld a, [hffaa]
or a
jp z, .asm_834b
xor a
ld [rNR42], a
ld [hffaa], a
.asm_834b
ld a, b
and $40
ld [hffab], a
ld a, b
and $3f
add a
ld e, a
ld d, $0
ld hl, data_249e4
add hl, de
ld a, [hli]
ld [hffa4], a
ld a, [hli]
ld [hffa5], a
ld a, $77
ld [rNR50], a
ld a, $ff
ld [rNR51], a
ld a, $1
ld [hffa3], a
ret
.asm_836e
call ResetAllSoundRegisters
ld [$ffb1], a
ld [$ffb3], a
ld [$ffb4], a
dec a
ld [$ffb2], a
ld [$ffb5], a
ld a, b
and $3f
add a
ld e, a
ld d, $0
ld hl, data_249e4
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [hli]
ld [$ffac], a
ld e, a
ld d, $0
ld a, l
ld [$ffad], a
ld a, h
ld [$ffae], a
add hl, de
add hl, de
ld a, l
ld [$ffaf], a
ld a, h
ld [$ffb0], a
ld a, $77
ld [rNR50], a
ld a, $ff
ld [rNR51], a
ld a, $1
ld [$ffb1], a
ret
; 0x83ab
Function243ab: ; 2:43ab
push hl
ld hl, $ffa0
ld a, [hl]
rla
xor [hl]
and $40
jr z, .asm_83b7
ccf
.asm_83b7
ld a, [hl]
rla
ld [hl], a
pop hl
ret
; 0x83bc
ResetAllSoundRegisters: ; 2:43bc
xor a
ld [rNR12], a
ld [rNR22], a
ld [rNR32], a
ld [rNR42], a
ld [rNR14], a
ld [rNR24], a
ld [rNR34], a
ld [rNR44], a
ld [$ffb6], a
ld [$ffbc], a
ld [$ffc2], a
ld [$ffc8], a
ret
; 0x83d6
INCBIN "baserom.gb", 16384*2+$3d6, $9e4-$3d6
data_249e4: ; 2:49e4
dw $4BC2, $57CE, $61D4, $7064, $7132, $7233, .data_24a14, $4A27, $4A76, $4A8C, $4AA2, $4AB4, $4AD1, $4AEE, $4AFA, $4B0C, $4B52, $4B5A, $4B70, $4B77, $4B7E, $4B9B, $4BA8, $4BB5
.data_24a14 ; 2:4a14
INCBIN "baserom.gb", 16384*2+$a14, $32e7-$a14
data_272e7: ; 2:72e7
INCBIN "build/data/2-1.rle"
data_273dc: ; 2:73dc
INCBIN "build/data/2-2.rle"
data_2759c: ; 2:759c
INCBIN "build/data/2-3.rle"
data_277a5: ; 2:77a5
INCBIN "build/data/2-4.rle"
data_27994: ; 2:7994
INCBIN "build/data/2-5.rle"
data_27c2a: ; 2:7c2a
INCBIN "build/data/2-6.rle"
data_27e2d: ; 2:7e2d
INCBIN "build/data/2-7.rle"
data_27ff6: ; 2:7ff6
INCBIN "baserom.gb", 16384*2+$3ff6, $4000-$3ff6