-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_051.asm
executable file
·11603 lines (10312 loc) · 136 KB
/
bank_051.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
; Disassembly of "DQM.gbc"
; This file was created with:
; mgbdis v1.4 - Game Boy ROM disassembler by Matt Currie and contributors.
; https://github.com/mattcurrie/mgbdis
SECTION "ROM Bank $051", ROMX[$4000], BANK[$51]
ld d, c
ld a, $42
db $f4
ld b, e
sub [hl]
ld c, d
add sp, $4b
or e
ld c, h
ld d, $4d
ld e, [hl]
ld c, [hl]
xor d
ld c, a
or $50
ld c, d
ld d, d
xor d
ld b, [hl]
xor c
ld b, h
ld a, b
ld d, l
ld sp, $335b
ld e, h
ld a, d
ld d, e
ld e, c
ld l, c
ld l, c
ld d, l
rrca
ld a, e
Call_051_4027:
ld hl, $c817
ld [hl], $00
inc hl
ld [hl], $00
ld hl, $0801
rst $10
ld a, $fc
call $1688
ld de, $5b00
ld hl, $9600
call $14cf
ld de, $5b01
ld hl, $8800
call $14cf
ld de, $2e00
ld hl, $8d00
call $14cf
ld hl, $8b00
ld de, $1202
call $098f
call Call_051_4107
call Call_051_40d1
ld a, [$c86c]
or a
jr z, jr_051_4073
ld a, $ff
ld [$c8b7], a
ld [$c8b8], a
call $3331
jr_051_4073:
ld b, $27
ld a, [$c968]
cp $5d
jp nz, Jump_051_408b
ld hl, $c8ea
res 7, [hl]
ld a, [$d999]
cp $02
jr nz, jr_051_408b
ld b, $2b
Jump_051_408b:
jr_051_408b:
ld a, b
call $1ae1
ld a, $07
ldh [$b5], a
ld a, $ff
ldh [$b6], a
ld a, $00
ldh [$bb], a
ld a, $00
ldh [$b7], a
call $122f
call $1417
xor a
ld [$c8a4], a
ld [$c8a5], a
xor a
ld [$c892], a
xor a
ld [$dd62], a
xor a
ld [$c873], a
xor a
ld [$c86e], a
ld hl, $170a
rst $10
ld hl, $5110
rst $10
ld a, $03
ld [$c8a1], a
call $125d
ld a, $0b
jp $11cb
Call_051_40d1:
ld a, [$ca8d]
or a
ret z
ld a, [$ca8e]
ld d, a
ld hl, $0107
rst $10
ld a, d
ld [$da15], a
ld a, [$ca8d]
cp $01
ret z
ld a, [$ca8f]
ld d, a
ld hl, $0107
rst $10
ld a, d
ld [$da16], a
ld a, [$ca8d]
cp $02
ret z
ld a, [$ca90]
ld d, a
ld hl, $0107
rst $10
ld a, d
ld [$da17], a
ret
Call_051_4107:
ld hl, $c8da
ld bc, $0008
ld a, $00
call $12c7
call Call_051_419f
ld a, $04
ld [$db89], a
ld de, $dc40
ld a, [$c863]
bit 1, a
jr z, jr_051_412b
xor a
ld [$db89], a
ld de, $dc3c
jr_051_412b:
ld hl, $9000
ld a, [$db89]
call $2fa5
jr c, jr_051_413c
ld a, [de]
call Call_051_6a67
jr jr_051_4140
jr_051_413c:
ld hl, $5801
rst $10
jr_051_4140:
ld hl, $db89
inc [hl]
inc de
ld hl, $9240
ld a, [$db89]
call $2fa5
jr c, jr_051_4156
ld a, [de]
call Call_051_6a67
jr jr_051_415a
jr_051_4156:
ld hl, $5801
rst $10
jr_051_415a:
ld hl, $db89
inc [hl]
inc de
ld hl, $9480
ld a, [$db89]
call $2fa5
jr c, jr_051_4170
ld a, [de]
call Call_051_6a67
jr jr_051_4174
jr_051_4170:
ld hl, $5801
rst $10
jr_051_4174:
xor a
ld hl, $d9f4
ld bc, $0008
call $12c7
ld hl, $9800
ld a, l
ld [$d9f8], a
ld a, h
ld [$d9f9], a
call Call_051_742a
call Call_051_7439
call Call_051_7524
call Call_051_7628
call Call_051_768a
call Call_051_79cb
call Call_051_736a
ret
Call_051_419f:
ld d, $00
ld a, [$c86c]
or a
jr z, jr_051_41b0
ld a, [$c863]
bit 1, a
jr z, jr_051_41b0
ld d, $04
jr_051_41b0:
ld a, d
ld [$db89], a
call Call_051_7929
inc d
ld a, d
ld [$db89], a
call Call_051_7929
inc d
ld a, d
ld [$db89], a
call Call_051_7929
ld hl, $9700
ld b, $60
jr_051_41cc:
ld a, $ff
ld [hl+], a
ld a, $00
ld [hl+], a
dec b
jr nz, jr_051_41cc
ld a, [$c86c]
or a
ld a, [$ca8d]
ld [$dd72], a
jr nz, jr_051_41e3
or a
ret z
jr_051_41e3:
ld d, $00
ld a, [$c86c]
or a
jr z, jr_051_41fc
ld a, [$c863]
bit 1, a
jr z, jr_051_41fc
ld a, [$db75]
ld [$dd72], a
ld d, $04
jr jr_051_41fc
jr_051_41fc:
push de
ld hl, $cac2
ld a, d
call $2229
ld e, l
ld d, h
ld hl, $9700
call Call_051_73dc
pop de
ld a, [$dd72]
cp $01
ret z
inc d
push de
ld hl, $cac2
ld a, d
call $2229
ld e, l
ld d, h
ld hl, $9740
call Call_051_73dc
pop de
ld a, [$dd72]
cp $02
ret z
inc d
push de
ld hl, $cac2
ld a, d
call $2229
ld e, l
ld d, h
ld hl, $9780
call Call_051_73dc
pop de
ret
call Call_051_4245
call Call_051_4027
ret
Call_051_4245:
call Call_051_43c9
call Call_051_4452
ld a, [$db74]
or a
jr nz, jr_051_4257
ld a, $6d
ld [$dc40], a
ret
jr_051_4257:
xor a
ld [$da88], a
ld a, $ff
ld [$da82], a
xor a
ld hl, $db00
ld bc, $0073
call $12c7
ld hl, $dd1b
ld bc, $0008
ld a, $ff
call $12c7
ld hl, $db8b
ld bc, $00d9
xor a
call $12c7
ld hl, $dc3c
ld bc, $0008
ld a, $ff
call $12c7
ld a, $ff
ld hl, $dd03
ld bc, $0008
call $12c7
ld a, [$db74]
or a
jr z, jr_051_42ae
ld c, a
ld b, $00
xor a
ld hl, $dd03
push bc
call $12c7
pop bc
ld hl, $c876
xor a
call $12c7
jr_051_42ae:
ld hl, $d9fc
ld bc, $0006
xor a
call $12c7
ld a, [$d929]
ld [$d9fd], a
xor a
ld hl, $dd0b
ld bc, $0010
call $12c7
ld a, $ff
ld hl, $dc64
ld bc, $0080
call $12c7
ld a, $ff
ld hl, $c1ca
ld [hl+], a
ld [hl+], a
ld [hl], a
ld a, [$db74]
ld b, a
ld c, $00
jr_051_42e1:
call Call_051_44b2
inc c
dec b
jr nz, jr_051_42e1
ld a, [$db75]
ld b, a
ld c, $04
jr_051_42ee:
call Call_051_44b2
inc c
dec b
jr nz, jr_051_42ee
xor a
ld [$db76], a
ld [$dd61], a
xor a
ld [$d9ed], a
ld a, $ff
ld hl, $dce4
ld bc, $0018
call $12c7
xor a
ld hl, $dcfc
ld bc, $0007
call $12c7
ld hl, $ffff
ld a, l
ld [$db77], a
ld a, h
ld [$db78], a
xor a
ld hl, $db4c
ld bc, $0027
call $12c7
ld hl, $000a
ld a, l
ld [$db83], a
ld a, h
ld [$db84], a
ld a, $ff
ld [$db77], a
ld [$db78], a
ld a, [$db74]
ld d, a
ld e, $00
ld a, [$c86c]
or a
jr nz, jr_051_4358
ld hl, $dd1f
ld b, $00
ld a, [$db75]
ld c, a
or a
ld a, $00
call nz, $12c7
jr_051_4358:
call Call_051_499f
call Call_051_4a28
ld de, $db8b
ld bc, $0800
jr_051_4364:
push bc
ld a, c
ld hl, $dd1b
add l
ld l, a
ld a, $00
adc h
ld h, a
ld a, [hl]
cp $ff
jr z, jr_051_4393
ld a, c
ld hl, $dc3c
add l
ld l, a
ld a, $00
adc h
ld h, a
ld a, [hl]
ld [$da31], a
push de
ld hl, $0301
rst $10
pop de
ld a, [$da38]
ld h, a
ld a, [$da37]
swap a
or h
ld [de], a
jr_051_4393:
pop bc
inc de
inc c
dec b
jr nz, jr_051_4364
ld hl, $c8da
ld bc, $0008
xor a
call $12c7
ld hl, $c1c0
ld bc, $000f
ld a, $ff
call $12c7
ld a, $00
ld [$c1c2], a
ld hl, $c1cd
ld bc, $0008
ld a, $80
call $12c7
call Call_051_548c
call Call_051_5507
ld hl, $d9ed
inc [hl]
ret
Call_051_43c9:
ld a, [$c86c]
or a
jr nz, jr_051_43dc
ld a, [$da09]
or a
jr z, jr_051_43e0
ld a, [$d8d3]
cp $5d
jr nz, jr_051_43e4
jr_051_43dc:
ld a, $02
jr jr_051_43e6
jr_051_43e0:
ld a, $00
jr jr_051_43e6
jr_051_43e4:
ld a, $01
jr_051_43e6:
ld [$db73], a
ld a, [$c86c]
or a
ret z
ld a, $06
ld [$c8ee], a
ret
ld a, [$db4c]
ld l, a
ld a, [$db4d]
ld h, a
ld a, [$db4e]
ld e, a
ld a, [$db4f]
ld d, a
Call_051_4404:
push hl
ld a, $1a
add l
ld l, a
ld a, $00
adc h
ld h, a
ld a, [hl]
and $03
rrc a
rrc a
ld c, a
pop hl
ld a, [hl+]
sla a
sla a
or [hl]
inc hl
sla a
sla a
or [hl]
inc hl
or c
ld [de], a
inc de
ld b, $05
jr_051_4428:
ld a, [hl+]
sla a
sla a
or [hl]
inc hl
sla a
sla a
or [hl]
inc hl
sla a
sla a
or [hl]
inc hl
ld [de], a
inc de
dec b
jr nz, jr_051_4428
ld a, [hl+]
sla a
sla a
or [hl]
inc hl
sla a
sla a
or [hl]
sla a
sla a
ld [de], a
ret
Call_051_4452:
ld a, [$c86c]
or a
jr z, jr_051_4498
ld bc, $0300
jr_051_445b:
ld a, c
ld hl, $cac1
call $224a
or a
jr z, jr_051_4469
inc c
dec b
jr nz, jr_051_445b
jr_051_4469:
ld a, c
ld [$db74], a
ld [$c1d9], a
ld bc, $0304
jr_051_4473:
ld a, c
ld hl, $cac1
call $224a
or a
jr z, jr_051_4481
inc c
dec b
jr nz, jr_051_4473
jr_051_4481:
ld a, c
sub $04
ld [$db75], a
dec a
ld [$da02], a
ld a, [$c863]
bit 1, a
ret z
ld a, [$db75]
ld [$c1d9], a
ret
jr_051_4498:
ld a, [$ca8d]
ld [$db74], a
ld [$c1d9], a
ld a, [$da02]
inc a
ld [$db75], a
ret
Call_051_44a9:
ld a, [$db4c]
ld c, a
ld a, $01
ld [$db55], a
Call_051_44b2:
ld a, [$c86c]
or a
jr nz, jr_051_44cb
ld a, c
cp $04
jr nc, jr_051_44c4
call Call_051_44cb
call Call_051_548c
ret
jr_051_44c4:
call Call_051_4627
call Call_051_548c
ret
Call_051_44cb:
jr_051_44cb:
ld a, c
ld hl, $caca
call $2229
ld a, c
ld de, $dc3c
add e
ld e, a
ld a, $00
adc d
ld d, a
call Call_051_4669
ld a, [hl+]
ld [de], a
inc hl
ld a, c
ld de, $db93
add e
ld e, a
ld a, $00
adc d
ld d, a
ld a, [hl]
and $0f
ld [de], a
ld a, [hl+]
swap a
and $0f
push af
ld a, c
ld de, $dd03
add e
ld e, a
ld a, $00
adc d
ld d, a
pop af
push af
and $03
ld [de], a
pop af
push af
push af
ld a, c
ld de, $c876
add e
ld e, a
ld a, $00
adc d
ld d, a
pop af
rrca
rrca
and $03
ld [de], a
ld a, c
bit 2, a
jr nz, jr_051_4536
ld a, [$c863]
bit 1, a
jr nz, jr_051_4551
ld a, c
inc a
inc a
ld de, $d9fc
add e
ld e, a
ld a, $00
adc d
ld d, a
pop af
and $03
ld [de], a
jr jr_051_4552
jr_051_4536:
ld a, [$c863]
bit 1, a
jr z, jr_051_4551
ld a, c
and $03
inc a
inc a
ld de, $d9fc
add e
ld e, a
ld a, $00
adc d
ld d, a
pop af
and $03
ld [de], a
jr jr_051_4552
jr_051_4551:
pop af
jr_051_4552:
ld a, $1d
add l
ld l, a
ld a, $00
adc h
ld h, a
push hl
push bc
ld a, [$db4c]
or a
jr nz, jr_051_4567
call Call_051_46ff
jr jr_051_456a
jr_051_4567:
call Call_051_46aa
jr_051_456a:
pop bc
pop hl
ld a, $21
add l
ld l, a
ld a, $00
adc h
ld h, a
ld a, [$db55]
or a
call z, Call_051_4769
inc hl
ld de, $db9b
call Call_051_4692
inc hl
inc hl
inc hl
inc hl
ld a, [$db55]
or a
jr z, jr_051_459e
inc hl
inc hl
ld de, $dbb3
call Call_051_469c
inc hl
inc hl
ld de, $dbd3
call Call_051_469c
jr jr_051_45b6
jr_051_459e:
ld de, $dba3
call Call_051_469c
ld de, $dbb3
call Call_051_469c
ld de, $dbc3
call Call_051_469c
ld de, $dbd3
call Call_051_469c
jr_051_45b6:
ld de, $dbe3
call Call_051_469c
ld de, $dbf3
call Call_051_469c
ld de, $dc03
call Call_051_469c
ld de, $dc13
call Call_051_469c
ld de, $dc23
call Call_051_469c
inc hl
inc hl
ld a, [$db55]
or a
jr z, jr_051_45f8
ld a, [$db4c]
push hl
ld hl, $db03
add a
add a
add a
add l
ld l, a
ld a, $00
adc h
ld h, a
ld a, [hl]
and $30
pop hl
jr nz, jr_051_45f8
inc hl
inc hl
inc hl
inc hl
jr jr_051_4610
jr_051_45f8:
ld de, $dc44
call Call_051_4692
ld de, $dc54
call Call_051_4692
ld de, $dc5c
call Call_051_4692
ld de, $dc4c
call Call_051_4692
jr_051_4610:
ld a, c
add a
add c
add a
add c
ld de, $dd28
add e
ld e, a
ld a, $00
adc d
ld d, a
push bc
call Call_051_4404
pop bc
call Call_051_47a5
ret
Call_051_4627:
push bc
ld a, c
sub $04
ld c, a
push bc
ld hl, $da03
ld a, c
add a
add l
ld l, a
ld a, $00
adc h
ld h, a
ld a, [hl+]
ld h, [hl]
ld l, a
ld a, l
ld [$da12], a
ld a, h
ld [$da13], a
ld hl, $1401
rst $10
pop bc
call Call_051_47e0
ld a, c
add $04