-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.asm
8859 lines (7828 loc) · 110 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
call Function12cc
ld sp, wdfff
call Function12b4
ld hl, wc000
ld bc, $2000
.asm_15f
ld [hl], $0
inc hl
dec bc
ld a, b
or c
jr nz, .asm_15f
ld hl, $cf0f
ld [hl], $1
inc hl
ld [hl], $1
inc hl
ld [hl], $1
inc hl
ld [hl], $1
ld a, $14
ld [$ff8e], a
ld [$ff8f], a
ld a, $80
ld [rLCDC], a
ld a, $83
ld [$c0b3], a
ei
call Function316f_ResetHRam
call Function31b3
call Function333f
call Functiond0a
ld h, h
ccf
call Functioneec
call Functioneec
call Functioned3
call Functiond00
ld b, h
ccf
ld a, Sound_80
call FarCall_StartMusic
ld a, $99
ld [wc0e5], a
ld a, $3
ld [wc0e6], a
ld a, $1
ld [wc0e8], a
ld [SubLevelNr], a
ld a, $2
ld [wc0db], a
.asm_1bd
ld a, $1
ld [wc10e], a
call ReadInputs
call Function59e
call Function4ff
ld a, [wc0dd]
cp $0
jr nz, .asm_1f1
ld a, [wc0db]
cp $b
jr nc, .asm_1e5
cp $5
jr z, .asm_1e5
cp $7
jr z, .asm_1e5
cp $0
jr nz, .asm_1f1
.asm_1e5
call Function29e
call Function163a
call Function1849
call Function19ad
.asm_1f1
ld hl, wc104
inc [hl]
.asm_1f5
ld a, [hff8c]
and a
jr z, .asm_1f5
xor a
ld [hff8c], a
call Function3180
ld a, [wc10e]
or a
jr nz, .asm_1f5
jr .asm_1bd
; 0x208
Function208: ; 0x208
push af
push bc
push de
push hl
ld a, [$4000]
ld [$cef2], a
call $ff80
ld hl, $cef1
bit 1, [hl]
jr z, .asm_230
ld a, [wc10f]
ld [rSCX], a
ld a, $80
ld hl, $c111
sub [hl]
ld [rSCY], a
ld hl, rLCDC
res 3, [hl]
set 1, [hl]
.asm_230
call Function1240
ld a, [$c0eb]
and a
jr z, .asm_23c
call Function336a
.asm_23c
call Function3280
ld a, [$cef2]
ld [MBC1RomBank], a
ld hl, wc103
inc [hl]
ld hl, hff8c
inc [hl]
ld a, [wc10e]
dec a
cp $ff
jr z, .asm_258
ld [wc10e], a
.asm_258
pop hl
pop de
pop bc
pop af
reti
; 0x25d
Function25d: ; 0x25d
push af
push hl
ld a, $b
.asm_261
dec a
jr nz, .asm_261
xor a
ld a, [$c11a]
ld [rSCY], a
xor a
ld [rSCX], a
ld hl, rLCDC
set 3, [hl]
res 1, [hl]
ld a, [$ce95]
cp $0
jr z, .asm_292
ld a, [wc105]
and $3
jr nz, .asm_292
ld hl, rLYC
ld a, [$c0b4]
cp [hl]
jr z, .asm_292
jr nc, .asm_292
dec [hl]
ld hl, $c11a
inc [hl]
.asm_292
pop hl
pop af
reti
; 0x295
Function295: ; 0x295
push af
push hl
ld hl, wc105
inc [hl]
pop hl
pop af
reti
; 0x29e
Function29e: ; 0x29e
call Function4ff
ld a, [$cf01]
inc a
cp $58
jr c, .asm_2aa
xor a
.asm_2aa
ld [$cf01], a
xor a
.asm_2ae
ld [$cee1], a
ld c, a
ld b, $0
xor a
ld [wc0ca], a
ld hl, $cd4b
add hl, bc
ld a, [hl]
or a
jr z, .asm_2d9
ld [$cee2], a
call Function1752
ld a, [$cee2]
ld l, a
ld h, $0
add hl, hl
ld de, data_2570
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld de, .asm_2d9
push de
jp hl
.asm_2d9
call Function3180
ld a, [$cee1]
inc a
cp $f
jr nz, .asm_2ae
jp Function17d6
; 0x2e7
Function2e7: ; 0x2e7
.asm_2e7
ld hl, hCurInputs
bit 3, [hl]
jr z, .asm_2e7
ret
; 0x2ef
Function2ef: ; 0x2ef
push hl
push de
ld e, a
ld d, $0
add hl, de
ld a, [hl]
pop de
pop hl
ret
; 0x2f9
NegAcc: ; 0x2f9
xor $ff
add $1
ret
; 0x2fe
Function2fe: ; 0x2fe
push bc
xor a
ld [$cf00], a
ld hl, $cef3
ld e, [hl]
inc hl
ld d, [hl]
ld hl, wc10f
ld a, [hli]
ld h, [hl]
ld l, a
call Compare_dehl
jr c, .asm_327
push bc
ld bc, $00a0
add hl, bc
pop bc
call Compare_dehl
jr nc, .asm_327
ld hl, $cee3
ld [hl], e
inc hl
ld [hl], d
jr .asm_32c
.asm_327
ld a, $1
ld [$cf00], a
.asm_32c
ld hl, $cef5
ld e, [hl]
inc hl
ld d, [hl]
ld hl, $c111
ld a, [hli]
ld h, [hl]
ld l, a
call Compare_dehl
jr c, .asm_350
push bc
ld bc, $0080
add hl, bc
pop bc
call Compare_dehl
jr nc, .asm_350
ld hl, $cee5
ld [hl], e
inc hl
ld [hl], d
pop bc
ret
.asm_350
ld a, $1
ld [$cf00], a
pop bc
ret
; 0x357
Function357: ; 0x357
push bc
call Function4dd
jr nc, .asm_360
jp .asm_4b3
.asm_360
ld a, $18
jr .asm_397
.asm_364
push bc
call Function4dd
jr nc, .asm_36d
jp .asm_4b3
.asm_36d
push bc
ld a, [$ce95]
cp $1
jr nz, .asm_37a
ld a, $d
call FarCall_StartMusic
.asm_37a
pop bc
ld a, $1a
jr .asm_397
.asm_37f
push bc
call Function4dd
jr nc, .asm_388
jp .asm_4b3
.asm_388
ld a, $19
jr .asm_397
.asm_38c
push bc
call Function4e3
jr nc, .asm_395
jp .asm_4b3
.asm_395
ld a, $1
.asm_397
ld hl, $cd4b
add hl, bc
ld [hl], a
ld e, a
ld a, c
ld [$cee0], a
ld a, [$cee1]
ld c, a
ld b, $0
ld a, e
cp $18
jr z, .asm_3ce
ld hl, $ce86
add hl, bc
ld a, [hl]
and $f
ld hl, data_4b5
call Function2ef
ld [wc0d9], a
ld hl, $ce86
add hl, bc
ld a, [hl]
and $f
ld hl, data_4c5
call Function2ef
ld [$c0da], a
jr .asm_3f8
.asm_3ce
ld hl, $ce86
add hl, bc
ld a, [hl]
and $f
srl a
srl a
ld hl, data_4d5
call Function2ef
ld [wc0d9], a
ld hl, $ce86
add hl, bc
ld a, [hl]
and $f
srl a
srl a
ld hl, data_4d9
call Function2ef
ld [$c0da], a
jr .asm_3f8
.asm_3f8
ld hl, $cd5a
add hl, bc
ld a, [hl]
ld [wc0cd], a
ld hl, $cd69
add hl, bc
ld a, [hl]
ld [wc0cf], a
ld hl, $cd78
add hl, bc
ld a, [hl]
ld [$c0d1], a
ld hl, $cd87
add hl, bc
ld a, [hl]
ld [$c0d3], a
ld a, [$cee0]
ld c, a
ld b, $0
ld a, [wc0d9]
ld e, $0
bit 7, a
jr z, .asm_428
dec e
.asm_428
ld hl, wc0cd
and a
add [hl]
ld [$cee9], a
ld a, [wc0cf]
adc e
ld [$ceea], a
ld hl, $cd5a
add hl, bc
ld a, [$cee9]
ld [hl], a
ld hl, $cd69
add hl, bc
ld a, [$ceea]
ld [hl], a
ld a, [$c0da]
ld e, $0
bit 7, a
jr z, .asm_451
dec e
.asm_451
ld hl, $c0d1
and a
add [hl]
ld [$ceeb], a
ld a, [$c0d3]
adc e
ld [$ceec], a
ld hl, $cd78
add hl, bc
ld a, [$ceeb]
ld [hl], a
ld hl, $cd87
add hl, bc
ld a, [$ceec]
ld [hl], a
ld a, [$cee1]
ld c, a
ld b, $0
ld hl, $ce86
add hl, bc
ld a, [hl]
and $f
ld [wc0cd], a
ld b, $0
ld a, [$cee0]
ld c, a
ld a, [wc0cd]
ld hl, data_22b6
call Function2ef
ld hl, $cdb4
add hl, bc
ld [hl], a
ld a, [wc0cd]
ld hl, data_22c6
call Function2ef
ld hl, $cdc3
add hl, bc
ld [hl], a
ld a, [wc0cd]
and $f
ld hl, $ce86
add hl, bc
ld [hl], a
ld hl, $ce77
add hl, bc
ld a, $3c
ld [hl], a
.asm_4b3
pop bc
ret
; 0x4b5
data_4b5: ; 0x4b5
db $03, $04, $04, $02, $03, $04, $02, $02, $03, $FF, $FE, $FE, $00, $FF, $FF, $FF
data_4c5: ; 0x4c5
db $05, $04, $02, $03, $00, $FF, $FF, $FC, $FB, $FC, $FC, $FD, $FF, $02, $03, $04
data_4d5: ; 0x4d5
db $FD, $03, $FD, $00
data_4d9: ; 0x4d9
db $05, $04, $FB, $04
Function4dd: ; 0x4dd
ld c, $4
ld a, $e
jr Function4e3.asm_4e7
Function4e3: ; 0x4e3
ld c, $1
ld a, $3
.asm_4e7
ld [$c0d5], a
ld b, $0
.asm_4ec
ld hl, $cd4b
add hl, bc
ld a, [hl]
and a
jr z, .asm_4fd
inc c
ld a, [$c0d5]
cp c
jr nc, .asm_4ec
scf
ret
.asm_4fd
and a
ret
; 0x4ff
Function4ff: ; 0x4ff
ld hl, wc0c1
ld [hl], $0
inc hl
ld [hl], $c0
ld a, [wc0dd]
cp $0
jr z, .asm_543
ld a, $34
ld [wc0cd], a
ld a, $3c
ld [wc0cf], a
xor a
ld c, $10
call Function544
ld a, $44
ld [wc0cd], a
ld a, $3c
ld [wc0cf], a
ld a, $1
ld c, $10
call Function544
ld a, $54
ld [wc0cd], a
ld a, $3c
ld [wc0cf], a
ld a, $2
ld c, $10
call Function544
jp Function17d6
.asm_543
ret
; 0x544
Function544: ; 0x544
ld [wc0c7], a
ld hl, wc0c6
ld [hl], c
xor a
ld [$cee4], a
ld [$cee6], a
ld a, [wc0cd]
ld [$cee3], a
ld a, [wc0cf]
ld [$cee5], a
ld a, [$cee3]
ld l, a
ld a, [$cee4]
ld h, a
ld a, [wc10f]
ld e, a
ld a, [$c110]
ld d, a
add hl, de
ld a, l
ld [$cee3], a
ld a, h
ld [$cee4], a
ld a, [$cee5]
ld l, a
ld a, [$cee6]
ld h, a
ld a, [$c111]
ld e, a
ld a, [$c112]
ld d, a
add hl, de
ld a, l
ld [$cee5], a
ld a, h
ld [$cee6], a
ld a, [wc0ca]
and $80
ld [wc0ca], a
call Function15af
jp Functione41
; 0x59e
Function59e: ; 0x59e
ld a, [wc0db]
and a
jp z, Function71a
cp $b
jp nc, .asm_643
cp $1
jr z, .asm_5d6
cp $5
jr z, .asm_61f
cp $7
jp z, Function701
ld a, $0
ld [wc0e1], a
call Function2bc1
call Function2cea
.asm_5c2
call Function865
jp nc, Function6d0
call Function340f
ld a, $1
ld [wc0ea], a
xor a
ld [$cf13], a
jr .asm_5c2
.asm_5d6
call Functiond5a
ld a, [wc0e6]
dec a
ld [wc0e6], a
and a
jp nz, .asm_685
ld a, $3
ld [wc0e6], a
call Function17d6
call Functiond00
ld h, [hl]
ld a, $fa
push hl
ret nz
and a
jp z, .asm_61a
call Function31b3
ld a, Sound_81
call FarCall_StartMusic
ld a, $0
ld [wc0e1], a
call Function85f
jr nc, .asm_61a
ld a, [wLevelNr]
inc a
ld hl, SubLevelNr
sub [hl]
ld [wLevelNr], a
ld a, $1
ld [hl], a
jr .asm_685
.asm_61a
pop hl
jp _Start
.asm_61e
ret
.asm_61f
ld hl, hCurInputs
bit 2, [hl]
jr nz, .asm_639
ld a, [wc0de]
inc a
cp $ff
jr nz, .asm_63f
ld a, [wc0df]
inc a
ld [wc0df], a
cp $69
jr nz, .asm_61e
.asm_639
ld a, $1
ld [wc0db], a
ret
.asm_63f
ld [wc0de], a
ret
.asm_643
ld a, [wLevelNr]
cp MaxLevelNr
jp nz, .asm_660
ld a, Sound_81
call FarCall_StartMusic
ld hl, data_6c7
ld a, [hl]
call Function30f5
call Function2f7b
call Function9ba
jp .asm_61a
.asm_660
ld a, [SubLevelNr]
cp $1
jr nz, .asm_685
ld a, [wc0e8]
cp $1
jr z, .asm_685
ld a, Sound_81
call FarCall_StartMusic
ld a, [wc0e8]
dec a
ld c, a
ld b, $0
ld hl, data_6c7
add hl, bc
ld a, [hl]
call Function30f5
call Function2f7b
.asm_685
call Function31b3
xor a
ld [wc0df], a
ld a, $9f
ld [wc0de], a
call Functiond00
add [hl]
ld a, Sound_3e
add e
call FarCall_StartMusic
call Function2b2b
call Function1823
call Function206d
call Function3180
call Functiona8a
call Functionabf
call Functiond0a
ld h, h
dec bc
ld a, [wLevelNr]
and $3
ld c, a
ld b, $0
ld hl, BGMLoopOrder
add hl, bc
ld a, [hl]
call FarCall_StartMusic
;nop
;nop
;nop
xor a
ld [wc0db], a
ret
; 0x6c7
data_6c7: ; 0x6c7
db 8, 5, 6, 7, 3, 4, 1, 2, 8
Function6d0: ; 0x6d0
call Function31b3
ld a, [wLevelNr]
push af
ld a, MaxLevelNr
ld [wLevelNr], a
call Functiond0a
db $f4
ld a, [bc]
ld a, $1
ld [wc0df], a
ld a, $9a
ld [wc0de], a
call Function2dff
pop af
ld [wLevelNr], a
xor a
call Function30f5
ld a, Sound_81
call FarCall_StartMusic
call Function2f7b
jp Function59e.asm_685
; 0x701
Function701: ; 0x701
call Function83d
jr nc, .asm_70e
.asm_706
ld a, $b
ld [wc0db], a
jp Function59e
.asm_70e
ld hl, hHoldInputs
bit 2, [hl]
jr nz, .asm_706
bit 3, [hl]
jr nz, .asm_706
ret
; 0x71a
Function71a: ; 0x71a
ld hl, hCurInputs
bit 3, [hl]
jr z, .asm_742
ld hl, hHoldInputs
bit 2, [hl]
jr z, .asm_731
ld a, [wc0dd]
and a
jr nz, .asm_731
jp .asm_7b3
.asm_731
ld a, [wc0dd]
xor $1
ld [wc0dd], a
and a
jr z, .asm_73f
jp Function31c4
.asm_73f
jp Call_ResetAndFullVolume
.asm_742
ld a, [$c11b]
and a
jr z, .asm_789
ld a, [wc0dd]
cp $1
jr z, .asm_789
ld hl, hCurInputs
bit 2, [hl]
jr z, .asm_789
ld hl, hHoldInputs
bit 6, [hl]
jr z, .asm_789
ld a, $b
ld [wc0db], a
ld hl, hHoldInputs
bit 0, [hl]
jr nz, .asm_76c
jp IncreaseLevelNr
.asm_76c
ld a, [wc0e8]
inc a
cp $9
jr nz, .asm_776
ld a, $1
.asm_776
ld [wc0e8], a
dec a
sla a
sla a
sla a
ld [wLevelNr], a
ld a, $1
ld [SubLevelNr], a
ret
.asm_789
ld a, [$ce95]
cp $2
jr nz, .asm_791
ret
.asm_791
ld a, [wc104]
and $3f
jr nz, .asm_7e8
ld a, [wc0dd]
cp $0
jr nz, .asm_7e8
ld a, [wc0dc]
dec a
daa
cp $0
jr nz, .asm_7e5
ld [wc0dc], a
ld a, [$ce95]
cp $2
jr nz, .asm_7b3
ret
.asm_7b3
ld a, $5
ld [wc0db], a
xor a
ld [wc0de], a
ld [wc0df], a
ld [$cd4c], a
ld [$cd4d], a
ld [$cd4e], a
ld a, [wc0e5]
and a
jr nz, .asm_7db
ld a, $0
ld [wLevelNr], a
ld a, $1
ld [wc0e8], a
ld [SubLevelNr], a
.asm_7db
ld a, Sound_15
call FarCall_StartMusic
ld a, Sound_85
jp FarCall_StartMusic
.asm_7e5
ld [wc0dc], a
.asm_7e8
ld a, [wcaf6]