-
Notifications
You must be signed in to change notification settings - Fork 1
/
bank_000.asm
13104 lines (10668 loc) · 164 KB
/
bank_000.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 $000", ROM0[$0]
RST_00::
di
Jump_000_0001:
jp Boot
nop
nop
nop
nop
RST_08::
jp Jump_000_2d63
nop
nop
nop
nop
nop
RST_10::
ldh [$9d], a
ld [$2000], a
ret
nop
nop
RST_18::
rst $38
nop
nop
nop
nop
nop
nop
nop
RST_20::
rst $38
nop
nop
nop
nop
nop
nop
nop
RST_28::
push de
ld e, a
ld d, $00
add hl, de
add hl, de
ld a, [hl+]
ld h, [hl]
RST_30::
ld l, a
pop de
jp hl
nop
nop
nop
nop
nop
RST_38::
rst $38
nop
nop
nop
nop
nop
nop
nop
VBlankInterrupt::
jp Jump_000_0283
nop
nop
nop
nop
nop
LCDCInterrupt::
jp Jump_000_0552
nop
nop
nop
nop
nop
TimerOverflowInterrupt::
jp Jump_000_3e93
nop
nop
nop
nop
nop
SerialTransferCompleteInterrupt::
jp Jump_000_06ef
nop
nop
nop
nop
nop
JoypadTransitionInterrupt::
jp Jump_000_092e
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
Jump_000_00ff:
nop
Boot::
nop
jp Jump_000_016e
HeaderLogo::
db $ce, $ed, $66, $66, $cc, $0d, $00, $0b, $03, $73, $00, $83, $00, $0c, $00, $0d
db $00, $08, $11, $1f, $88, $89, $00, $0e, $dc, $cc, $6e, $e6, $dd, $dd, $d9, $99
db $bb, $bb, $67, $63, $6e, $0e, $ec, $cc, $dd, $dc, $99, $9f, $bb, $b9, $33, $3e
HeaderTitle::
db "PM_CRYSTAL", $00
HeaderManufacturerCode::
db "BYTE"
HeaderCGBFlag::
db $c0
HeaderNewLicenseeCode::
db $30, $31
HeaderSGBFlag::
db $00
HeaderCartridgeType::
db $10
HeaderROMSize::
db $06
HeaderRAMSize::
db $03
HeaderDestinationCode::
db $01
HeaderOldLicenseeCode::
db $33
HeaderMaskROMVersion::
db $01
HeaderComplementCheck::
db $26
HeaderGlobalChecksum::
db $23, $1a
Jump_000_0150:
di
call Call_000_3b4e
xor a
ldh [$de], a
call Call_000_3317
xor a
ldh [rIF], a
ld a, $01
ldh [rIE], a
ei
ld hl, $cfbe
set 7, [hl]
ld c, $20
call Call_000_0468
jr jr_000_017d
Jump_000_016e:
cp $11
jr z, jr_000_0175
xor a
jr jr_000_0177
jr_000_0175:
ld a, $01
jr_000_0177:
ldh [$e6], a
ld a, $01
ldh [$ea], a
jr_000_017d:
di
xor a
ldh [rIF], a
ldh [rIE], a
ldh [rRP], a
ldh [rSCX], a
ldh [rSCY], a
ldh [rSB], a
ldh [rSC], a
ldh [rWX], a
ldh [rWY], a
ldh [rBGP], a
ldh [rOBP0], a
ldh [rOBP1], a
ldh [rTMA], a
ldh [rTAC], a
ld [$d000], a
ld a, $04
ldh [rTAC], a
jr_000_01a2:
ldh a, [rLY]
cp $91
jr nz, jr_000_01a2
xor a
ldh [rLCDC], a
ld hl, $c000
ld bc, $1000
jr_000_01b1:
ld [hl], $00
inc hl
dec bc
ld a, b
or c
jr nz, jr_000_01b1
ld sp, $c0ff
ldh a, [$e6]
push af
ldh a, [$ea]
push af
xor a
ld hl, $ff80
ld bc, $007f
call Call_000_3041
pop af
ldh [$ea], a
pop af
ldh [$e6], a
call Call_000_025a
ld a, $01
ldh [rSVBK], a
call Call_000_0245
call Call_000_300b
call Call_000_0270
ld a, $01
rst $10
call $4031
xor a
ldh [$de], a
ldh [$cf], a
ldh [$d0], a
ldh [rP1], a
ld a, $08
ldh [rSTAT], a
ld a, $90
ldh [$d2], a
ldh [rWY], a
ld a, $07
ldh [$d1], a
ldh [rWX], a
ld a, $e3
ldh [rLCDC], a
ld a, $ff
ldh [$cb], a
ld a, $02
ld hl, $5890
rst $08
ld a, $9c
ldh [$d7], a
xor a
ldh [$d6], a
ld a, $05
ld hl, $4089
rst $08
xor a
ld [$6000], a
ld [$0000], a
ldh a, [$e6]
and a
jr z, jr_000_022b
call Call_000_2ff7
jr_000_022b:
xor a
ldh [rIF], a
ld a, $0f
ldh [rIE], a
ei
call Call_000_045a
ld a, $30
call Call_000_2d83
call Call_000_3b4e
xor a
ld [$c2c0], a
jp $642e
Call_000_0245:
ld a, $01
ldh [rVBK], a
call Call_000_024f
xor a
ldh [rVBK], a
Call_000_024f:
ld hl, $8000
ld bc, $2000
xor a
call Call_000_3041
ret
Call_000_025a:
ld a, $01
jr_000_025c:
push af
ldh [rSVBK], a
xor a
ld hl, $d000
ld bc, $1000
call Call_000_3041
pop af
inc a
cp $08
jr nc, jr_000_025c
ret
Call_000_0270:
ld a, $00
call Call_000_2fcb
ld hl, $a000
ld bc, $0020
xor a
call Call_000_3041
call Call_000_2fe1
ret
Jump_000_0283:
push af
push bc
push de
push hl
ldh a, [$9e]
and $07
ld e, a
ld d, $00
ld hl, $02a1
add hl, de
add hl, de
ld a, [hl+]
ld h, [hl]
ld l, a
call Call_000_2fec
call Call_000_209e
pop hl
pop de
pop bc
pop af
reti
or c
ld [bc], a
scf
inc bc
dec h
inc bc
sub [hl]
inc bc
rst $18
inc bc
nop
inc b
ld [hl], $04
or c
ld [bc], a
ld hl, $ff9b
inc [hl]
ldh a, [rDIV]
ld b, a
ldh a, [$e1]
adc b
ldh [$e1], a
ldh a, [rDIV]
ld b, a
ldh a, [$e2]
sbc b
ldh [$e2], a
ldh a, [$9d]
ldh [$8a], a
ldh a, [$cf]
ldh [rSCX], a
ldh a, [$d0]
ldh [rSCY], a
ldh a, [$d2]
ldh [rWY], a
ldh a, [$d1]
ldh [rWX], a
call Call_000_15e3
jr c, jr_000_02f4
call Call_000_0c2f
jr c, jr_000_02f4
call Call_000_15d8
jr c, jr_000_02f4
call Call_000_164c
call Call_000_1769
call Call_000_170a
call Call_000_17d3
jr_000_02f4:
ldh a, [$d8]
and a
jr nz, jr_000_02fc
call $ff80
jr_000_02fc:
xor a
ld [$cfb3], a
ld a, [$cfb1]
and a
jr z, jr_000_030a
dec a
ld [$cfb1], a
jr_000_030a:
ld a, [$cfb2]
and a
jr z, jr_000_0314
dec a
ld [$cfb2], a
jr_000_0314:
call Call_000_0935
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
ldh a, [$98]
ldh [$e3], a
ret
ldh a, [$9d]
ldh [$8a], a
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
xor a
ld [$cfb3], a
ret
ldh a, [$9d]
ldh [$8a], a
ldh a, [$cf]
ldh [rSCX], a
ldh a, [$d0]
ldh [rSCY], a
call Call_000_037f
jr c, jr_000_0351
call Call_000_164c
call Call_000_1778
call $ff80
jr_000_0351:
xor a
ld [$cfb3], a
ldh a, [rIF]
ld b, a
xor a
ldh [rIF], a
ld a, $02
ldh [rIE], a
ld a, b
and $08
or $02
ldh [rIF], a
ei
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
di
ldh a, [rIF]
ld b, a
xor a
ldh [rIF], a
ld a, $0f
ldh [rIE], a
ld a, b
ldh [rIF], a
ret
Call_000_037f:
ldh a, [$e6]
and a
jp nz, Jump_000_0c33
ld a, [$cfc7]
ldh [rBGP], a
ld a, [$cfc8]
ldh [rOBP0], a
ld a, [$cfc9]
ldh [rOBP1], a
and a
ret
ldh a, [$9d]
ldh [$8a], a
ldh a, [$cf]
ldh [rSCX], a
ldh a, [$d0]
ldh [rSCY], a
ldh a, [$e5]
and a
call nz, Call_000_0c37
jr c, jr_000_03b3
call Call_000_164c
call Call_000_1778
call $ff80
jr_000_03b3:
xor a
ld [$cfb3], a
ldh a, [rIF]
push af
xor a
ldh [rIF], a
ld a, $02
ldh [rIE], a
ldh [rIF], a
ei
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
di
ldh a, [rIF]
ld b, a
pop af
or b
ld b, a
xor a
ldh [rIF], a
ld a, $0f
ldh [rIE], a
ld a, b
ldh [rIF], a
ret
ldh a, [$9d]
ldh [$8a], a
call Call_000_164c
call Call_000_1769
call $ff80
call Call_000_0935
xor a
ld [$cfb3], a
call Call_000_2063
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
ret
ldh a, [$9d]
ldh [$8a], a
ldh a, [$cf]
ldh [rSCX], a
call Call_000_0c2f
jr c, jr_000_0413
call Call_000_164c
call Call_000_1769
jr_000_0413:
xor a
ld [$cfb3], a
call Call_000_0935
xor a
ldh [rIF], a
ld a, $02
ldh [rIE], a
ldh [rIF], a
ei
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
di
xor a
ldh [rIF], a
ld a, $0f
ldh [rIE], a
ret
ldh a, [$9d]
ldh [$8a], a
ld hl, $ff9b
inc [hl]
call Call_000_0c33
jr c, jr_000_044c
call Call_000_1769
call Call_000_170a
call Call_000_15d8
jr_000_044c:
xor a
ld [$cfb3], a
ld a, $3a
rst $10
call $405c
ldh a, [$8a]
rst $10
ret
Call_000_045a:
ld a, $01
ld [$cfb3], a
jr_000_045f:
halt
ld a, [$cfb3]
and a
jr nz, jr_000_045f
ret
Call_000_0468:
Jump_000_0468:
jr_000_0468:
call Call_000_045a
dec c
jr nz, jr_000_0468
ret
Call_000_046f:
ld a, [$c2ce]
cp $00
ret z
call Call_000_05a7
ld a, [$d0ed]
bit 0, a
ret z
ld hl, $4011
ld a, $23
rst $08
ret
Call_000_0485:
Jump_000_0485:
ld hl, $4070
ld a, $23
rst $08
ret
ld a, [$d841]
ld b, a
ld hl, $0538
ld a, l
sub b
ld l, a
jr nc, jr_000_0499
dec h
jr_000_0499:
ld a, [hl+]
ldh [rBGP], a
ld a, [hl+]
ldh [rOBP0], a
ld a, [hl+]
ldh [rOBP1], a
ret
ldh a, [$e6]
and a
jr z, jr_000_04af
ld hl, $0517
ld b, $04
jr jr_000_04c7
jr_000_04af:
ld hl, $052f
ld b, $04
jr jr_000_04c7
ldh a, [$e6]
and a
jr z, jr_000_04c2
ld hl, $0526
ld b, $03
jr jr_000_04c7
jr_000_04c2:
ld hl, $053e
ld b, $03
jr_000_04c7:
push de
ld a, [hl+]
call Call_000_0c9f
ld a, [hl+]
ld e, a
ld a, [hl+]
ld d, a
call Call_000_0ccb
ld c, $08
call Call_000_0468
pop de
dec b
jr nz, jr_000_04c7
ret
ldh a, [$e6]
and a
jr z, jr_000_04e9
ld hl, $0522
ld b, $04
jr jr_000_0501
jr_000_04e9:
ld hl, $053a
ld b, $04
jr jr_000_0501
ldh a, [$e6]
and a
jr z, jr_000_04fc
ld hl, $052b
ld b, $03
jr jr_000_0501
jr_000_04fc:
ld hl, $0543
ld b, $03
jr_000_0501:
push de
ld a, [hl-]
ld d, a
ld a, [hl-]
ld e, a
call Call_000_0ccb
ld a, [hl-]
call Call_000_0c9f
ld c, $08
call Call_000_0468
pop de
dec b
jr nz, jr_000_0501
ret
rst $38
rst $38
rst $38
cp $fe
cp $f9
ld sp, hl
ld sp, hl
db $e4
db $e4
db $e4
db $e4
db $e4
db $e4
sub b
sub b