-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.asm
executable file
·7125 lines (6439 loc) · 118 KB
/
start.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 "Home", ROM0[$150]
_Start: ; 0x150
cp $11
jr nz, .asm_16e
ld a, [rKEY1]
and $80
jr nz, .asm_167
ld a, $30
ld [rJOYP], a
ld a, $1
ld [rKEY1], a
xor a
ld [rIE], a
stop
.asm_167
xor a
ld [rSVBK], a
ld a, $1
jr .asm_16f
.asm_16e
xor a
.asm_16f
ld [$fffe], a
call Function28c6
ld sp, wdfff
ld a, BANK(Functionf2a22)
ld [MBC5RomBank], a
call Functionf2a22
xor a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
ld hl, v8000
ld bc, $1800
call Function29d6
ld a, BANK(Function91c00)
ld [MBC5RomBank], a
call Function91c00
call Function28ee
call Function29c7
ld a, BANK(Function6df5)
ld [MBC5RomBank], a
call Function6df5
call $ffc0
call Function4110
call Function2bc6
ld a, $44
ld [rSTAT], a
ld a, $4f
ld [rLYC], a
ld a, $1
ld [$dbaf], a
ld a, $1
ld [rIE], a
call $46ad
ld a, BANK(Function7c000) ; $1f
ld [MBC5RomBank], a
call Function7c000 ; $4000
ld a, $18
ld [$ffb5], a
ei
ld a, BANK(Function80854)
ld [MBC5RomBank], a
call Function80854
jp Function35c
; 0x1da
Function1da:
ld a, $1
ld [$fffd], a
ld a, [$c500]
and a
jr z, .asm_1ef
ld a, [$db95]
cp $b
jr nz, .asm_1ef
ld a, $0
jr .asm_1f5
.asm_1ef
ld hl, $c156
ld a, [$ff97]
add [hl]
.asm_1f5
ld [rSCY], a
ld a, [$ff96]
ld hl, $c155
add [hl]
ld hl, $c1bf
add [hl]
ld [rSCX], a
ld a, [$d6fe]
and a
jr nz, .asm_210
ld a, [$d6ff]
cp $0
jr z, .asm_23a
.asm_210
ld a, [$db95]
cp $9
jr z, .asm_226
cp $6
jr c, .asm_226
cp $b
jr nz, .asm_22c
ld a, [$db96]
cp $7
jr nc, .asm_22c
.asm_226
call Function89f
call Function89f
.asm_22c
di
call Function416
ei
call Function89f
call Function89f
jp Function35c
.asm_23a
ld a, [$d6fd]
and $7f
ld e, a
ld a, [rLCDC]
and $80
or e
ld [rLCDC], a
ld hl, $ffe7
inc [hl]
ld a, [$db95]
cp $0
jr nz, .asm_261
ld a, [$db96]
cp $8
jr c, .asm_261
ld a, BANK(Function81263)
ld [MBC5RomBank], a
call Function81263
.asm_261
ld a, [$c17f]
and a
jp z, Function2d2
inc a
jr nz, .asm_276
.asm_26b
ld a, BANK(Function5c8d7)
ld [MBC5RomBank], a
call Function5c8d7
jp Function2d2
.asm_276
inc a
jr z, .asm_26b
ld a, BANK(Function50e51)
ld [MBC5RomBank], a
ld a, [$c180]
inc a
ld [$c180], a
cp $c0
jr nz, .asm_29d
ld a, [$c17f]
cp $2
jr nz, .asm_293
call Function50e51
.asm_293
xor a
ld [$c17f], a
ld [$c3ca], a
jp Function2d2
.asm_29d
push af
cp $60
jr c, .asm_2b4
ld a, [$fffe]
and a
jr z, .asm_2b1
ld a, BANK(Function82caf)
ld [MBC5RomBank], a
call Function82caf
jr .asm_2b4
.asm_2b1
call $4fe8
.asm_2b4
ld a, BANK(Function51038)
ld [MBC5RomBank], a
pop af
call Function51038
call Function89f
ld a, [$db97]
ld [rBGP], a
ld a, [$db98]
ld [rOBP0], a
ld a, [$db99]
ld [rOBP1], a
jp Function35c
; 0x2d2
Function2d2:
ld a, [$db9a]
ld [rWY], a
ld a, [$db97]
ld [rBGP], a
ld a, [$db98]
ld [rOBP0], a
ld a, [$db99]
ld [rOBP1], a
call Function89f
call Function2815
ld a, [hff90]
ld hl, hff91
or [hl]
ld hl, $c10e
or [hl]
jr nz, asm_35c
ld a, [$0003]
and a
jr z, .asm_32a
ld a, [$d6fc]
and a
jr nz, .asm_30a
ld a, [$ffcb]
and $f
jr z, .asm_324
.asm_30a
ld a, [$ffcc]
and $40
jr z, .asm_324
ld a, [$d6fc]
xor $1
ld [$d6fc], a
jr nz, asm_35c
ld a, [$c17b]
xor $10
ld [$c17b], a
jr asm_35c
.asm_324
ld a, [$d6fc]
and a
jr nz, asm_35c
.asm_32a
ld a, [$db95]
cp $c
jr nz, .asm_338
ld a, [$db96]
cp $2
jr c, .asm_340
.asm_338
ld a, BANK(Function5ff1)
call ChangeROMBank
call Function5ff1
.asm_340
call Functione30
ld a, [$fffe]
and a
jr z, .asm_350
ld a, $21
call ChangeROMBank
call $406e
.asm_350
xor a
ld [$ddd2], a
ld a, BANK(Function600e)
call ChangeROMBank
call Function600e
Function35c:
asm_35c:
ld a, $1f
call ChangeROMBank
call $7f80
ld a, $c
call Functionb07
call ChangeROMBank
xor a
ld [$fffd], a
halt
.asm_371
ld a, [$ffd1]
and a
jr z, .asm_371
xor a
ld [$ffd1], a
jp Function1da
; 0x37c
Function37c:
jr nz, asm_3ae
ld b, b
ld h, b
nop
jr nc, asm_3d9
ld l, b
nop
Function385:
di
push af
push hl
push de
push bc
ld a, [rSVBK]
ld c, a
xor a
ld [rSVBK], a
ld a, [$db95]
cp $1
jr nz, .asm_3aa
ld a, [$db96]
cp $5
jr nz, .asm_3a3
ld a, [$d000]
jr .asm_3a5
.asm_3a3
ld a, [$ff97]
.asm_3a5
ld [rSCY], a
jp Function3fc
.asm_3aa
cp $0
jr nz, asm_3f9
asm_3ae:
ld a, [wc105]
ld e, a
ld d, $0
ld hl, wc100
add hl, de
ld a, [hl]
ld hl, $ff96
add [hl]
ld [rSCX], a
ld a, [$db96]
cp $6
jr c, .asm_3d6
ld hl, $0381
add hl, de
ld a, [hl]
ld [rLYC], a
ld a, e
inc a
and $3
ld [wc105], a
jr Function3fc
.asm_3d6
ld hl, Function37c
asm_3d9:
add hl, de
ld a, [hl]
ld [rLYC], a
ld a, e
inc a
cp $5
jr nz, .asm_3e4
xor a
.asm_3e4
ld [wc105], a
nop
cp $4
jr nz, Function3fc
ld a, [wc106]
ld [rSCY], a
cpl
inc a
add $60
ld [rLYC], a
jr Function3fc
asm_3f9:
xor a
ld [rSCX], a
Function3fc:
ld a, c
ld [rSVBK], a
pop bc
pop de
pop hl
pop af
ei
reti
; 0x405
Function405:
push af
ld a, $28
ld [MBC5RomBank], a
call $4601
ld a, [$dbaf]
ld [MBC5RomBank], a
pop af
reti
; 0x416
Function416:
ld a, [$d6fe]
and a
jr z, asm_437
ld [$ddd2], a
cp $23
jr z, .asm_428
push af
call Function28c6
pop af
.asm_428
call Function42d
jr asm_45a
Function42d:
ld e, a
ld a, BANK(Function80657)
ld [MBC5RomBank], a
call Function80657
jp [hl]
asm_437:
call Function28c6
ld a, BANK(Function91c2c)
ld [MBC5RomBank], a
call Function91c2c
ld a, BANK(Function80577)
ld [MBC5RomBank], a
call Function80577
ld a, $8
ld [MBC5RomBank], a
call Function2924
ld a, $c
call Functionb07
ld [MBC5RomBank], a
asm_45a:
xor a
ld [$d6ff], a
ld [$d6fe], a
ld a, [$d6fd]
ld [rLCDC], a
ret
; 0x467
Function467:
rlca
add hl, bc
Function469:
push af
push bc
push de
push hl
ld a, [rSVBK]
and $7
ld c, a
xor a
ld [rSVBK], a
push bc
di
ld a, [$db95]
cp $d
jr nz, .asm_48a
ld a, [$db96]
cp $9
jr c, .asm_48a
cp $12
jp c, Function574
.asm_48a
ld a, [hfffd]
and a
jp nz, Function566
ld a, [$c19f]
and $7f
jr z, .asm_4c9
cp $1
jr z, .asm_4c9
cp $5
jr nc, .asm_4a9
call Function23db
ld hl, $c19f
inc [hl]
jp Function566
.asm_4a9
cp $a
jr nz, .asm_4b3
call Function2710
jp Function566
.asm_4b3
cp $b
jr nz, .asm_4c9
ld a, [$c172]
and a
jr z, .asm_4c3
dec a
ld [$c172], a
jr .asm_4c9
.asm_4c3
call Function2764
jp Function566
.asm_4c9
ld a, [$db95]
cp $e
jr c, .asm_4e1
ld a, [$db96]
cp $6
jr c, .asm_528
ld a, $38
ld [MBC5RomBank], a
call $785a
jr .asm_528
.asm_4e1
ld a, [$d6fe]
and a
jr nz, asm_566
ld a, [hff90]
ld [$ffe8], a
ld hl, hff91
or [hl]
ld hl, $c10e
or [hl]
jr z, .asm_506
call Function5b9
ld a, [$ffe8]
cp $8
jr nc, .asm_501
.asm_4fe
call Function1d31
.asm_501
call $ffc0
jr asm_566
.asm_506
ld a, [$ffbb]
and a
jr z, .asm_51e
dec a
ld [$ffbb], a
ld e, a
ld d, $0
ld hl, $0467
add hl, de
ld a, [hl]
ld [$d6f8], a
call Function1ed9
jr .asm_4fe
.asm_51e
ld a, [$db95]
cp $d
jr z, .asm_528
call Function1b08
.asm_528
ld a, [hfffe]
and a
jr z, .asm_535
ld a, BANK(Function91c1a)
ld [MBC5RomBank], a
call Function91c1a
.asm_535
ld de, wd601
call Function291e
xor a
ld [wd600], a
ld [wd601], a
ld [$dc90], a
ld [$dc91], a
ld a, $36
ld [MBC5RomBank], a
call $7310
call $ffc0
ld a, [hfffe]
and a
jr z, asm_566
ld a, BANK(Function84000) ; $21
ld [MBC5RomBank], a
call Function84000 ; $4000
ld a, [$dbaf]
ld [MBC5RomBank], a
Function566:
asm_566:
ei
asm_567:
pop bc
ld a, c
ld [rSVBK], a
pop hl
pop de
pop bc
ld a, $1
ld [$ffd1], a
pop af
reti
; 0x574
Function574:
ld a, [$dbaf]
push af
ld a, [hfffd]
and a
jr nz, .asm_5a8
call $ffc0
ld a, [hfffe]
and a
jr z, .asm_595
ld a, $21
call ChangeROMBank
call $4000
ld a, BANK(Function91c1a)
call ChangeROMBank
call Function91c1a
.asm_595
ld de, wd601
call Function291e
xor a
ld [wd600], a
ld [wd601], a
ld [$dc90], a
ld [$dc91], a
.asm_5a8
ld a, $28
call ChangeROMBank
call $4616
pop af
ld [$dbaf], a
ld [MBC5RomBank], a
jr asm_567 ; 0x5b7 $ae
; 0x5b9
Function5b9:
ld a, [hff90]
and a
jp z, Function69a
cp $7
jp z, Function7ab
cp $3
jp z, rst62
cp $4
jp z, rst6a
cp $5
jp z, rst72
cp $6
jp z, rst7a
cp $8
jp nc, Function7ce
ld a, [$dba5]
and a
jr z, .asm_652
ld a, [hff90]
cp $2
jp z, Function821
ld a, $d
call Functionb07
ld [MBC5RomBank], a
ld a, [hff92]
ld c, a
ld b, $0
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld hl, $9000
add hl, bc
ld e, l
ld d, h
ld hl, $5000
ld a, [hfff7]
cp $ff
jr nz, .asm_62b
ld a, BANK(Function80616)
ld [MBC5RomBank], a
call Function80616
ld [MBC5RomBank], a
jr .asm_63d
.asm_62b
ld a, [hff94]
add $50
ld h, a
add hl, bc
ld a, [hffbb]
and a
jr z, .asm_63d
ld a, [hff92]
dec a
cp $2
jr c, .asm_643
.asm_63d
ld bc, $0040
call CopyBytes
.asm_643
ld a, [hff92]
inc a
ld [hff92], a
cp $4
jr nz, .asm_651
xor a
ld [hff90], a
ld [hff92], a
.asm_651
ret
.asm_652
ld a, $f
call Functionb07
ld [MBC5RomBank], a
ld a, [hff92]
ld c, a
ld b, $0
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld hl, $9000
add hl, bc
ld e, l
ld d, h
ld a, [hff94]
add $40
ld h, a
ld l, $0
add hl, bc
ld bc, $0040
call CopyBytes
ld a, [hff92]
inc a
ld [hff92], a
cp $8
jr nz, .asm_699
xor a
ld [hff90], a
ld [hff92], a
.asm_699
ret
; 0x69a
Function69a:
ld a, [hfffe]
and a
jr z, .asm_6c7
ld a, [hfff7]
cp $ff
jr nz, .asm_6c7
ld a, BANK(Function8075a)
ld [MBC5RomBank], a
call Function8075a
xor a
ld [$c10e], a
ld [$c10f], a
ld hl, $9000
ld bc, $0000
call Function80616
ld c, $90
ld b, h
ld h, $0
call Functiona03
jr .asm_733
.asm_6c7
ld a, [hff91]
and a
jr z, .asm_739
ld a, [$c197]
ld e, a
ld d, $0
ld hl, $c193
add hl, de
ld a, [hl]
push af
and $3f
ld d, a
ld e, $0
pop af
swap a
rra
rra
and $3
ld c, a
ld b, $0
ld hl, $2e66
add hl, bc
ld a, [hl]
and a
jr z, .asm_6f2
call Functionb07
.asm_6f2
ld [MBC5RomBank], a
ld a, [hff93]
ld c, a
ld b, $0
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld hl, $4000
add hl, bc
add hl, de
push hl
ld a, [$c197]
ld d, a
ld hl, v8400
add hl, bc
add hl, de
ld e, l
ld d, h
pop hl
ld bc, $0040
call CopyBytes
ld a, [hff93]
inc a
ld [hff93], a
cp $4
jr nz, .asm_738
.asm_733
xor a
ld [hff91], a
ld [hff93], a
.asm_738
ret
.asm_739
ld a, [$c10d]
ld e, a
ld d, $0
ld hl, $c193
add hl, de
ld a, [hl]
push af
and $3f
ld d, a
ld e, $0
pop af
swap a
rra
rra
and $3
ld c, a
ld b, $0
ld hl, $2e66
add hl, bc
ld a, [hl]
and a
jr z, .asm_75f
call Functionb07
.asm_75f
ld [MBC5RomBank], a
ld a, [$c10f]
ld c, a
ld b, $0
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld hl, $4000
add hl, bc
add hl, de
push hl
ld a, [$c10d]
ld d, a
ld hl, v8400
add hl, bc
add hl, de
ld e, l
ld d, h
pop hl
ld bc, $0040
call CopyBytes
ld a, [$c10f]
inc a
ld [$c10f], a
cp $4
jr nz, .asm_7aa
xor a
ld [$c10e], a
ld [$c10f], a
.asm_7aa
ret
; 0x7ab
Function7ab:
ld a, BANK(Function6c78)
ld [MBC5RomBank], a
call Function6c78
jp Function8b
; 0x7b6
Function7b6:
ld h, b
ld l, c
and b
ld l, c
ret nz
ld l, c
nop
ld b, d
ld b, b
ld b, d
ld h, b
ld b, d
nop
add d
ld b, b
add d
ld h, b
add d
nop
add d
ld b, b
add d
ld h, b
add d
Function7ce:
sub $8
sla a
ld e, a
ld d, $0
ld hl, $07b6
add hl, de
push hl
ld hl, $07c2
add hl, de
ld e, [hl]
inc hl
ld d, [hl]