-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbank_038.asm
13059 lines (11493 loc) · 154 KB
/
bank_038.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 "crystalkaizo.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 $038", ROMX[$4000], BANK[$38]
push de
xor a
call $2fcb
ld hl, $a000
ld bc, $0000
jr_038_400b:
push bc
push hl
push bc
ld de, $d002
call Call_038_404e
call Call_038_4057
ld hl, $408b
pop bc
add hl, bc
add hl, bc
ld a, [hl+]
ld e, a
ld d, [hl]
ld hl, $d012
call Call_038_404e
pop hl
ld bc, $0010
add hl, bc
pop bc
inc c
ld a, c
cp $31
jr c, jr_038_400b
ld hl, $c800
ld de, $a000
ld bc, $0310
call $3026
pop hl
ld de, $a000
ld c, $31
ldh a, [$9d]
ld b, a
call $0f82
call $2fe1
ret
Call_038_404e:
ld c, $10
jr_038_4050:
ld a, [hl+]
ld [de], a
inc de
dec c
jr nz, jr_038_4050
ret
Call_038_4057:
ld hl, $d012
ld e, $80
ld d, $08
jr_038_405e:
push hl
ld hl, $d002
call Call_038_4078
pop hl
ld a, b
ld [hl+], a
push hl
ld hl, $d003
call Call_038_4078
pop hl
ld a, b
ld [hl+], a
srl e
dec d
jr nz, jr_038_405e
ret
Call_038_4078:
ld b, $00
ld c, $08
jr_038_407c:
ld a, [hl+]
jr_038_407d:
and e
jr z, jr_038_4083
scf
jr jr_038_4084
jr_038_4083:
and a
jr_038_4084:
rr b
inc hl
dec c
jr nz, jr_038_407c
ret
jr_038_408b:
and b
jp z, $ca30
ret nz
ret
ld d, b
ret
ldh [$c8], a
ld [hl], b
jr_038_4096:
ret z
nop
ret z
or b
jp z, $ca40
ret nc
ret
ld h, b
ret
ldh a, [$c8]
add b
jr_038_40a4:
ret z
db $10
ret z
ret nz
jp z, $ca50
ldh [$c9], a
ld [hl], b
ret
nop
ret
sub b
ret z
jr nz, jr_038_407d
ret nc
jp z, $ca60
ldh a, [$c9]
add b
ret
db $10
ret
and b
ret z
jr nc, jr_038_408b
ldh [$ca], a
ld [hl], b
jp z, $ca00
sub b
ret
jr nz, jr_038_4096
or b
ret z
ld b, b
ret z
ldh a, [$ca]
add b
jp z, $ca10
and b
ret
jr nc, jr_038_40a4
ret nz
ret z
ld d, b
ret z
nop
res 2, b
jp z, $ca20
or b
ret
ld b, b
ret
ret nc
ret z
ld h, b
ret z
Call_038_40ed:
ret
ld hl, $cfcc
set 4, [hl]
call $31f3
call $0fc8
call $300b
ld de, $0000
call $3b97
call $045a
call $0568
call $0e51
call $0e5f
ld hl, $4d16
ld de, $9000
call $0b50
ld hl, $4ea8
ld de, $93e0
call $0b50
ld hl, $4cdb
ld de, $8000
call $0b50
ld hl, $4cf6
ld de, $8ef0
ld bc, $0010
call $3026
ld hl, $4d06
ld de, $8f50
ld bc, $0010
call $3026
call Call_038_4521
call Call_038_44c1
call $4c37
call $058a
call $3200
ld a, $e4
call $0c9f
ld de, $e4e4
call $0ccb
call $045a
xor a
ld [$cf63], a
ld a, $02
ld [$cf64], a
ld [$cf65], a
ld de, $0012
call $3b97
jr_038_4170:
ld a, [$cf63]
bit 7, a
jr nz, jr_038_417c
call Call_038_4191
jr jr_038_4170
jr_038_417c:
call $3c55
ld de, $009d
call $3c23
call $3c55
call $31f3
ld hl, $cfcc
res 4, [hl]
ret
Call_038_4191:
ld a, [$cf63]
ld e, a
ld d, $00
ld hl, $41a0
add hl, de
add hl, de
ld a, [hl+]
ld h, [hl]
ld l, a
jp hl
or l
ld b, c
jp nc, $1741
ld b, d
or a
ld b, d
jp c, $1442
ld b, e
ld e, $43
ld h, b
ld b, e
Call_038_41b0:
ld hl, $cf63
inc [hl]
ret
ld hl, $41cd
call Call_038_4489
call $1dcf
jr c, jr_038_41c7
call Call_038_4366
call Call_038_41b0
ret
jr_038_41c7:
ld a, $07
ld [$cf63], a
ret
ld d, $93
ld d, a
ld [hl], c
ld d, b
ld a, [$d855]
ld h, a
ld a, [$d856]
ld l, a
ld a, h
and a
jr nz, jr_038_41ef
ld a, l
cp $03
jr nc, jr_038_41ef
ld hl, $4212
call Call_038_4489
ld a, $07
ld [$cf63], a
ret
jr_038_41ef:
ld de, $fffd
add hl, de
ld a, h
ld [$d855], a
ld a, l
ld [$d856], a
ld de, $0022
call $3c23
xor a
ldh [$d4], a
call Call_038_449c
ld a, $01
ldh [$d4], a
call $3c55
call Call_038_41b0
ret
ld d, $ab
ld d, a
ld [hl], c
ld d, b
xor a
ldh [$d4], a
ld hl, $c4a0
ld bc, $0c09
call Call_038_44e5
ld hl, $c4a9
ld bc, $0014
ld a, [$c6e8]
call $30fe
ld [hl], $f5
ld a, $01
ldh [$d4], a
ld c, $14
call $0468
ld hl, $c4a2
call Call_038_43c1
ld a, $01
ldh [$d4], a
ld c, $14
call $0468
ld hl, $c51a
call Call_038_43c1
call $31f6
ld hl, $42b2
call Call_038_4489
xor a
ld [$cf66], a
jr_038_425c:
call $0a57
ldh a, [$a9]
and $01
jr nz, jr_038_427c
ld de, $002f
call $3c23
call Call_038_4849
ld c, $04
call $0468
ld hl, $cf66
ld a, [hl]
xor $01
ld [hl], a
jr jr_038_425c
jr_038_427c:
ld de, $002c
call $3c23
ld a, $03
jr_038_4284:
push af
call Call_038_4849
ld c, $04
call $0468
call $300b
ld c, $04
call $0468
pop af
dec a
jr nz, jr_038_4284
ld hl, $cf66
ld a, [hl]
push af
xor $01
ld [hl], a
call Call_038_43ac
ld bc, $0605
call Call_038_44e5
pop af
ld [$cf66], a
call Call_038_41b0
ret
ld d, $be
ld d, a
ld [hl], c
ld d, b
ld hl, $42d5
call Call_038_4489
jr_038_42bd:
call $0a57
ldh a, [$a9]
and $01
jr nz, jr_038_42d1
call Call_038_489c
call Call_038_4960
call $045a
jr jr_038_42bd
jr_038_42d1:
call Call_038_41b0
ret
ld d, $ce
ld d, a
ld [hl], c
ld d, b
xor a
ldh [$9b], a
call Call_038_4960
call $3c55
ld de, $009a
call $3c23
call $3c55
ld a, [$c6e8]
ld e, a
ld d, $00
ld hl, $c6d0
add hl, de
add hl, de
ld a, [$cf66]
ld e, a
add hl, de
ld a, [hl]
ld [$c6e9], a
ld e, a
ld hl, $c6ea
add hl, de
ld [hl], $01
call Call_038_43ac
call Call_038_43ec
call $3200
call Call_038_41b0
ret
call Call_038_4637
call $0a80
call Call_038_41b0
ret
call $300b
ld hl, $4356
call Call_038_4489
call $1dcf
jr nc, jr_038_4330
call Call_038_41b0
ret
jr_038_4330:
ld a, [$c6e8]
inc a
ld [$c6e8], a
cp $0c
jr c, jr_038_434d
call Call_038_44c1
ld a, $01
ldh [$d4], a
call Call_038_4366
ld hl, $435b
call $1057
jr jr_038_4350
jr_038_434d:
call Call_038_4534
jr_038_4350:
ld a, $01
ld [$cf63], a
ret
ld d, $df
ld d, a
ld [hl], c
ld d, b
ld d, $f4
ld d, a
ld [hl], c
ld d, b
ld hl, $cf63
set 7, [hl]
ret
Call_038_4366:
ld hl, $c6d0
ld bc, $0018
xor a
call $3041
ld de, $c6d0
ld c, $17
jr_038_4375:
call $2f8c
and $1f
cp $18
jr nc, jr_038_4375
ld l, a
ld h, $00
add hl, de
ld a, [hl]
and a
jr nz, jr_038_4375
ld [hl], c
dec c
jr nz, jr_038_4375
xor a
ld [$c6e8], a
ld hl, $c6ea
ld bc, $0018
call $3041
ret
Call_038_4398:
ld hl, $0000
ld bc, $0006
ld a, [$cf64]
call $30fe
ld b, $00
ld a, [$cf65]
ld c, a
add hl, bc
ret
Call_038_43ac:
ld a, [$cf66]
and a
jr nz, jr_038_43ba
ld hl, $c4a2
ld bc, $1018
jr jr_038_43c0
jr_038_43ba:
ld hl, $c51a
ld bc, $4018
jr_038_43c0:
ret
Call_038_43c1:
xor a
ldh [$d4], a
ld de, $43ce
ld bc, $0605
call Call_038_44f7
ret
ld [$0909], sp
add hl, bc
ld a, [bc]
dec bc
jr z, @+$2d
jr z, jr_038_43e4
dec bc
inc l
dec l
ld l, $0c
dec bc
cpl
jr nc, jr_038_4412
inc c
dec bc
ld [hl-], a
jr_038_43e4:
inc sp
inc [hl]
inc c
dec c
ld c, $0e
ld c, $0f
Call_038_43ec:
xor a
ldh [$d4], a
push hl
push hl
ld de, $443b
ld bc, $0605
call Call_038_44f7
ld a, [$c6e9]
ld e, a
ld d, $00
ld hl, $4459
add hl, de
add hl, de
ld a, [hl+]
ld e, a
ld d, [hl]
pop hl
ld bc, $0017
add hl, bc
ld [hl], e
ld bc, $0012
add hl, bc
jr_038_4412:
ld a, d
ld de, $0014
ld b, $03
jr_038_4418:
push hl
ld c, $03
jr_038_441b:
ld [hl+], a
inc a
dec c
jr nz, jr_038_441b
pop hl
add hl, de
dec b
jr nz, jr_038_4418
pop hl
ldh a, [$e6]
and a
ret z
ld de, $0939
add hl, de
ld a, [$c6e9]
and $03
inc a
ld bc, $0605
call Call_038_44e7
ret
jr @+$1b
add hl, de
add hl, de
ld a, [de]
dec de
dec [hl]
ld a, a
ld a, a
inc e
dec bc
Call_038_4446:
jr z, jr_038_4470
jr z, @+$0e
dec bc
jr z, jr_038_4475
jr z, jr_038_445b
dec bc
jr z, jr_038_447a
jr z, jr_038_4460
dec e
ld e, $1e
ld e, $1f
rst $30
ld c, [hl]
jr_038_445b:
rst $30
ld d, a
rst $30
ld l, c
rst $30
jr_038_4460:
ld h, b
ld hl, sp+$4e
ld hl, sp+$57
ld hl, sp+$69
ld hl, sp+$60
ld sp, hl
ld c, [hl]
ld sp, hl
ld d, a
ld sp, hl
ld l, c
ld sp, hl
jr_038_4470:
ld h, b
ld a, [$fa4e]
ld d, a
jr_038_4475:
ld a, [$fa69]
ld h, b
ei
jr_038_447a:
ld c, [hl]
ei
ld d, a
ei
ld l, c
ei
ld h, b
db $fc
ld c, [hl]
db $fc
ld d, a
db $fc
ld l, c
db $fc
ld h, b
Call_038_4489:
push hl
ld hl, $c590
ld b, $04
ld c, $12
call $0fe8
pop hl
call $1065
call Call_038_449c
ret
Call_038_449c:
ld hl, $c5d5
ld b, $01
ld c, $09
call $0fe8
ld hl, $c5ea
ld de, $44bc
call $1078
ld hl, $c5ef
ld de, $d855
ld bc, $8204
call $3198
ret
add d
adc [hl]
adc b
adc l
ld d, b
Call_038_44c1:
xor a
ldh [$d4], a
ld hl, $c4a0
ld bc, $0168
ld a, $29
call $3041
ld hl, $c4a9
ld de, $510c
ld bc, $0c0b
call Call_038_44f7
ld hl, $c590
ld bc, $0412
call $0fe8
ret
Call_038_44e5:
ld a, $29
Call_038_44e7:
jr_038_44e7:
push bc
push hl
jr_038_44e9:
ld [hl+], a
dec c
jr nz, jr_038_44e9
pop hl
ld bc, $0014
add hl, bc
pop bc
dec b
jr nz, jr_038_44e7
ret
Call_038_44f7:
jr_038_44f7:
push bc
push hl
jr_038_44f9:
ld a, [de]
inc de
ld [hl+], a
dec c
jr nz, jr_038_44f9
pop hl
ld bc, $0014
add hl, bc
pop bc
dec b
jr nz, jr_038_44f7
ret
Call_038_4509:
ld de, $c400
ld a, [hl+]
jr_038_450d:
push af
ld a, [hl+]
add b
ld [de], a
inc de
ld a, [hl+]
add c
ld [de], a
inc de
ld a, [hl+]
ld [de], a
inc de
ld a, [hl+]
ld [de], a
inc de
pop af
dec a
jr nz, jr_038_450d
ret
Call_038_4521:
ld de, $8f60
ld hl, $8f62
ld bc, $009e
call $3026
ld hl, $8ffe
xor a
ld [hl+], a
ld [hl], a
ret
Call_038_4534:
xor a
ldh [$d4], a
ld a, [$c6e9]
ld e, a
ld d, $00
and $03
ld c, a
ld b, $00
ld a, e
and $1c
srl a
add $53
ld l, a
ld a, $00
adc $45
ld h, a
ld a, [hl+]
ld h, [hl]
ld l, a
jp hl
ld e, a
ld b, l
add e
ld b, l
and a
ld b, l
bit 0, l
rst $28