-
Notifications
You must be signed in to change notification settings - Fork 8
/
bank4.asm
18569 lines (17083 loc) · 323 KB
/
bank4.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
.SEGMENT "BANK4"
.ORG $C40000
.DEFINE score_popup_s 0
.IF USE_MULTI5_BIOS
aStartOfMulti5B:.BYTE "START OF MULTI5 BIOS"
.A8
.I16
; e=0
multi5_read_input:
PHP
SEP #$30
.I8
STZ a:.LOWORD(multitap_status) ; orig=0x0CE0
loc_C4001A: ; Wait for auto-joypad to complete
LDA a:.LOWORD(H_V_BLANK_FLAGS_AND_JOYPAD_STATUS)
AND #1
BNE loc_C4001A
LDA a:.LOWORD(JOYPAD_1_DATA_HIGH_BYTE)
STA a:.LOWORD(joypad_1+1) ; orig=0x0CE2
LDA a:.LOWORD(JOYPAD_1_DATA_LOW_BYTE)
STA a:.LOWORD(joypad_1) ; orig=0x0CE1
AND #$F
STA a:.LOWORD(joypad_1_connected) ; orig=0x0CEB
LDA a:.LOWORD($4016)
LSR
ROL a:.LOWORD(joypad_1_connected) ; orig=0x0CEB
LDA a:.LOWORD(JOYPAD_2_DATA_HIGH_BYTE)
loc_C4003C:
STA a:.LOWORD(joypad_2+1) ; orig=0x0CE4
LDA a:.LOWORD(JOYPAD_2_DATA_LOW_BYTE)
STA a:.LOWORD(joypad_2) ; orig=0x0CE3
AND #$F
STA a:.LOWORD(joypad_2_connected) ; orig=0x0CEC
LDA a:.LOWORD(JOYPAD_4_DATA_HIGH_BYTE)
STA a:.LOWORD(joypad_3+1) ; orig=0x0CE6
LDA a:.LOWORD(JOYPAD_4_DATA_LOW_BYTE)
STA a:.LOWORD(joypad_3) ; orig=0x0CE5
AND #$F
STA a:.LOWORD(joypad_3_connected) ; orig=0x0CED
LDA a:.LOWORD($4017)
LSR
ROL a:.LOWORD(joypad_2_connected) ; orig=0x0CEC
LSR
ROL a:.LOWORD(joypad_3_connected) ; orig=0x0CED
STZ a:.LOWORD(PROGRAMMABLE_I_O_PORT_OUTPUT)
LDY #$10
loc_C4006B:
LDA a:.LOWORD($4017)
REP #$20
.A16
LSR
ROL a:.LOWORD(joypad_4) ; orig=0x0CE7
LSR
ROL a:.LOWORD(joypad_5) ; orig=0x0CE9
SEP #$20
.A8
DEY
BNE loc_C4006B
LDA a:.LOWORD(joypad_4) ; orig=0x0CE7
AND #$F
STA a:.LOWORD(joypad_4_connected) ; orig=0x0CEE
LDA a:.LOWORD(joypad_5) ; orig=0x0CE9
AND #$F
STA a:.LOWORD(joypad_5_connected) ; orig=0x0CEF
LDA a:.LOWORD($4017)
LSR
ROL a:.LOWORD(joypad_4_connected) ; orig=0x0CEE
LSR
ROL a:.LOWORD(joypad_5_connected) ; orig=0x0CEF
LDA #$80
STA a:.LOWORD(PROGRAMMABLE_I_O_PORT_OUTPUT)
PLP
.I16
RTS
; End of function multi5_read_input
; ---------------------------------------------------------------------------
.BYTE "MODIFIED FROM SHVC MULTI5 BIOS Ver2.00"
.BYTE "END OF MULTI5 BIOS"
.A8
.I16
multi5_update_multitap_status:
PHP
SEP #$30
.I8
STZ a:.LOWORD(multitap_status) ; orig=0x0CE0
loc_C400DD: ; Wait for auto-joypad to finish
LDA a:.LOWORD(H_V_BLANK_FLAGS_AND_JOYPAD_STATUS)
AND #1
BNE loc_C400DD
STZ a:.LOWORD($4016)
LDA #1
STA a:.LOWORD($4016)
LDX #8
loc_C400EE:
LDA a:.LOWORD($4016)
LSR
LSR
ROL AZ .LOWORD(word_7E0040+1) ; orig=0x0041
loc_C400F6:
LDA a:.LOWORD($4017)
LSR
LSR
ROL AZ .LOWORD(word_7E0042+1) ; orig=0x0043
DEX
BNE loc_C400EE
STZ a:.LOWORD($4016)
LDX #8
loc_C40106:
LDA a:.LOWORD($4016)
LSR
LSR
ROL AZ .LOWORD(word_7E0040) ; orig=0x0040
LDA a:.LOWORD($4017)
LSR
LSR
ROL AZ .LOWORD(word_7E0042) ; orig=0x0042
DEX
BNE loc_C40106
LDA AZ .LOWORD(word_7E0040+1) ; orig=0x0041
CMP #$FF
BNE loc_C4012C
LDA AZ .LOWORD(word_7E0040) ; orig=0x0040
CMP #$FF
BEQ loc_C4012C
LDA #$80
STA a:.LOWORD(multitap_status) ; orig=0x0CE0
loc_C4012C:
LDA AZ .LOWORD(word_7E0042+1) ; orig=0x0043
CMP #$FF
BNE loc_C40142
LDA AZ .LOWORD(word_7E0042) ; orig=0x0042
CMP #$FF
BEQ loc_C40142
loc_C4013A:
LDA #$40
ORA a:.LOWORD(multitap_status) ; orig=0x0CE0
STA a:.LOWORD(multitap_status) ; orig=0x0CE0
loc_C40142:
PLP
.I16
RTS
; End of function multi5_update_multitap_status
; ---------------------------------------------------------------------------
aModifiedFromSh:.BYTE "MODIFIED FROM SHVC MULTI5 CONNECT CHECK Ver1.00"
aEndOfMulti5Con:.BYTE "END OF MULTI5 CONNECT CHECK"
.ENDIF ; USE_MULTI5_BIOS
.A8
.I8
main:
.IFNDEF J
SEP #$20
.ENDIF
STZ a:.LOWORD(NMI_V_H_COUNT_AND_JOYPAD_ENABLE)
STZ a:.LOWORD(H_DMA_CHANNEL_ENABLE)
STZ a:.LOWORD(REGULAR_DMA_CHANNEL_ENABLE)
STZ a:.LOWORD(REGULAR_DMA_CHANNEL_ENABLE)
STZ a:.LOWORD(APU_I_O_PORT_0)
STZ a:.LOWORD(APU_I_O_PORT_1)
STZ a:.LOWORD(APU_I_O_PORT_2)
STZ a:.LOWORD(APU_I_O_PORT_3)
LDA #$8F
STA a:.LOWORD(SCREEN_DISPLAY_REGISTER)
.IFDEF J
CLC
XCE
SEI
SEP #$20
.ENDIF
LDA #0
PHA
PLB
REP #$30
.A16
.I16
LDA #$2FF
TCS
REP #$20
LDA #0
TAX ; Clear RAM
loc_C401BD:
STA f:$7F0000,X
INX
INX
BNE loc_C401BD
LDA #$2000
TAX
loc_C401C9: ; Clear tilemaps
STA f:$7E0000,X
INX
INX
BNE loc_C401C9
LDA a:.LOWORD(word_7E0C7F) ; orig=0x0C7F
STA f:temp_uncompressed_graphics
LDA a:.LOWORD(word_7E0C81) ; orig=0x0C81
STA f:temp_uncompressed_graphics+2
LDA a:.LOWORD(word_7E0C83) ; orig=0x0C83
STA f:byte3_7E2804
LDA a:.LOWORD(word_7E0C85) ; orig=0x0C85
STA f:byte3_7E2804+2
LDA a:.LOWORD(word_7E0C87) ; orig=0x0C87
STA f:byte3_7E2808
LDA a:.LOWORD(word_7E0C89) ; orig=0x0C89
STA f:byte3_7E2808+2
LDA a:.LOWORD(word_7E0C8B) ; orig=0x0C8B
STA f:byte3_7E280C
LDA a:.LOWORD(word_7E0C8D) ; orig=0x0C8D
STA f:byte3_7E280C+2
LDA #0
TAX
loc_C4020D:
STA f:0,X
INX
INX
CPX #$2000
BNE loc_C4020D
LDA f:byte3_7E280C
STA a:.LOWORD(word_7E0C8B) ; orig=0x0C8B
LDA f:byte3_7E280C+2
STA a:.LOWORD(word_7E0C8D) ; orig=0x0C8D
LDA a:.LOWORD(word_7E0C8B) ; orig=0x0C8B
CMP #$6D61
BNE loc_C40280
LDA a:.LOWORD(word_7E0C8D) ; orig=0x0C8D
CMP #$6B6F
BNE loc_C40280
LDA f:temp_uncompressed_graphics
CMP f:byte3_7E2804
BNE loc_C40280
CMP f:byte3_7E2808
BNE loc_C40280
LDA f:temp_uncompressed_graphics+2
CMP f:byte3_7E2804+2
BNE loc_C40280
CMP f:byte3_7E2808+2
BNE loc_C40280
LDA f:temp_uncompressed_graphics
STA a:.LOWORD(word_7E0C7F) ; orig=0x0C7F
LDA f:temp_uncompressed_graphics+2
STA a:.LOWORD(word_7E0C81) ; orig=0x0C81
LDA f:byte3_7E2804
STA a:.LOWORD(word_7E0C83) ; orig=0x0C83
LDA f:byte3_7E2804+2
STA a:.LOWORD(word_7E0C85) ; orig=0x0C85
LDA f:byte3_7E2808
STA a:.LOWORD(word_7E0C87) ; orig=0x0C87
LDA f:byte3_7E2808+2
STA a:.LOWORD(word_7E0C89) ; orig=0x0C89
loc_C40280:
LDA #$6D61
STA a:.LOWORD(word_7E0C8B) ; orig=0x0C8B
LDA #$6B6F
STA a:.LOWORD(word_7E0C8D) ; orig=0x0C8D
JSL f:interrupt_register_init
JSL f:gpu_registers_init
JSL f:init_dboot
JSL f:dboot_related_
JSL f:unknown_init_
JSL f:dma_reset
REP #$20
LDA #$4000
STA a:.LOWORD(ADDRESS_FOR_VRAM_READ_WRITE_LOW_BYTE)
LDA #$1000
STA a:.LOWORD(DMA_4_BYTES_COUNT_LOW_BYTE)
REP #$20
LDA #.LOWORD(bg3_tileset_graphic)
STA a:.LOWORD(DMA_4_A_ADDRESS_LOW_BYTE)
SEP #$20
.A8
LDA #.BANKBYTE(bg3_tileset_graphic)
STA a:.LOWORD(DMA_4_A_ADDRESS_BANK)
JSL f:dma_related_
REP #$20
.A16
LDA #$58C0
STA a:.LOWORD(ADDRESS_FOR_VRAM_READ_WRITE_LOW_BYTE)
LDA #$680
STA a:.LOWORD(DMA_4_BYTES_COUNT_LOW_BYTE)
REP #$20
LDA #.LOWORD(bg3_ram_map)
STA a:.LOWORD(DMA_4_A_ADDRESS_LOW_BYTE)
SEP #$20
.A8
LDA #.BANKBYTE(bg3_ram_map)
STA a:.LOWORD(DMA_4_A_ADDRESS_BANK)
JSL f:dma_related_
REP #$20
.A16
LDA #$3FF
STA a:.LOWORD(bg3_v_scroll_2) ; orig=0x0CA7
REP #$20
LDA #.LOWORD(sub_C4633F)
STA a:.LOWORD(level_manager_object+object::handler) ; orig=0x0D00
SEP #$20
.A8
LDA #.BANKBYTE(sub_C4633F)
STA a:.LOWORD(level_manager_object+object::handler+2) ; orig=0x0D02
.IFNDEF J
; Moved up
REP #$20
.A16
LDA #.LOWORD(nullsub_1)
STA AZ2 .LOWORD(unknown_function_pointer) ; orig=0x00D0
SEP #$20
.A8
LDA #.BANKBYTE(nullsub_1)
STA AZ2 .LOWORD(unknown_function_pointer+2) ; orig=0x00D2
.ENDIF
SEP #$20
CLI
.IFDEF J
LDA #$B1
STA a:.LOWORD(NMI_V_H_COUNT_AND_JOYPAD_ENABLE)
.ENDIF
LDA #$20
STA a:.LOWORD(V_COUNT_TIMER)
LDA #$B8
STA a:.LOWORD(H_COUNT_TIMER)
.IFDEF J
REP #$20
.A16
LDA #.LOWORD(nullsub_1)
STA a:.LOWORD(unknown_function_pointer) ; orig=0x00D0
SEP #$20
.A8
LDA #.BANKBYTE(nullsub_1)
STA a:.LOWORD(unknown_function_pointer+2) ; orig=0x00D2
SEP #$20
.ELSE
LDA #$B1
STA a:.LOWORD(NMI_V_H_COUNT_AND_JOYPAD_ENABLE)
.ENDIF
LDA #$17
STA a:.LOWORD(main_screen_status) ; orig=0x0C97
LDA #$17
STA a:.LOWORD(subscreen_status) ; orig=0x0C98
LDA #1
STA a:.LOWORD(CYCLE_SPEED_DESIGNATION)
LDA #%111001
STA a:.LOWORD(BG_MODE_AND_TILE_SIZE_SETTING)
LDA #$8F
STA a:.LOWORD(word_7E031A) ; orig=0x031A
REP #$20
.A16
LDY #0
JSL f:dboot_19
REP #$30
.A8
wait_for_vblank:
SEP #$20
LDA a:.LOWORD(screen_flags) ; orig=0x0312
BIT #1
BEQ wait_for_vblank
SEP #$20
LDA #$8F
STA a:.LOWORD(SCREEN_DISPLAY_REGISTER)
STZ a:.LOWORD(H_DMA_CHANNEL_ENABLE)
JSL f:transfer_oam
JSL f:transfer_bg1_bg3_tilemaps
JSL f:sub_C62460
SEP #$20
LDA a:.LOWORD(word_7E031A) ; orig=0x031A
STA a:.LOWORD(SCREEN_DISPLAY_REGISTER)
LDA a:.LOWORD(byte_7E0CA9) ; orig=0x0CA9
STA a:.LOWORD(MOSAIC_SIZE_AND_BG_ENABLE)
JSL f:update_bg_scrolling
JSL f:handle_player_input
.IFDEF DEBUG
JSL f:transfer_debug_menu_to_vram
JSL f:clear_vs_check_graphics
.ENDIF
REP #$20
.A16
LDA #.LOWORD(player2_object+player::anonymous_6)
STA a:.LOWORD(word_7E00BE) ; orig=0x00BE
LDA #.LOWORD(player1_object+player::anonymous_6)
STA a:.LOWORD(level_manager_object+level_manager_object::anonymous_7) ; orig=0x0D28
LDA #$FFFF
STA a:.LOWORD(player1_object+player::anonymous_6) ; orig=0x0D68
REP #$20
LDA #.LOWORD(unk_7F0000)
STA a:.LOWORD(word_7E0306) ; orig=0x0306
SEP #$20
.A8
LDA #.BANKBYTE(unk_7F0000)
STA a:.LOWORD(word_7E0308) ; orig=0x0308
REP #$20
.A16
LDX #.LOWORD(level_manager_object)
LDA a:.LOWORD(level_manager_object+object::handler+1) ; orig=0x0D01
STA AZ .LOWORD(byte_7E0051)
LDA a:.LOWORD(level_manager_object+object::handler) ; orig=0x0D00
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
JSL f:call_function_at_0050
REP #$20
LDX #.LOWORD(player1_object)
LDA #4
loc_C403B7:
PHA
STX a:.LOWORD(word_7E0310) ; orig=0x0310
LDA AZ .LOWORD(player::gameover_related),X
BIT #1
BEQ loc_C403D5
LDA AZ .LOWORD(object::handler+1),X
STA AZ .LOWORD(byte_7E0051) ; orig=0x0051
LDA AZ .LOWORD(object::handler),X
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
JSL f:call_function_at_0050
REP #$20
loc_C403D5:
LDA a:.LOWORD(word_7E0310) ; orig=0x0310
CLC
ADC #$40
TAX
PLA
DEC
BNE loc_C403B7
LDX #.LOWORD(enemy_objects)
loc_C403E4:
LDA AZ .LOWORD(1),X
STA AZ .LOWORD(byte_7E0051) ; orig=0x0051
LDA AZ .LOWORD(0),X
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
JSL f:call_function_at_0050
REP #$20
LDA AZ .LOWORD(6),X
TAX
INC
BNE loc_C403E4
REP #$20
LDY a:.LOWORD(level_manager_object+level_manager_object::anonymous_7) ; orig=0x0D28
loc_C40402:
LDX a: .LOWORD(2),Y
LDA a: .LOWORD(0),Y
CMP #$FFFF
BEQ loc_C40417
PHA
JSL f:sub_C625D3
PLY
REP #$20
BRA loc_C40402
; ---------------------------------------------------------------------------
loc_C40417:
REP #$20
LDX #.LOWORD(unk_7E1C80)
loc_C4041C:
LDA AZ .LOWORD(6),X
CMP #$FFFF
BEQ loc_C4043A
PHA
LDA #$C4
STA AZ .LOWORD(byte_7E0052) ; orig=0x0052
LDA AZ .LOWORD(0),X
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
JSL f:call_function_at_0050
REP #$20
PLX
BRA loc_C4041C
; ---------------------------------------------------------------------------
loc_C4043A:
JSL f:related_to_oam_transfer
JSL f:update_palettes
SEP #$20
.A8
LDA a:.LOWORD(screen_flags) ; orig=0x0312
AND #$FE
STA a:.LOWORD(screen_flags) ; orig=0x0312
JMP a:.LOWORD(wait_for_vblank)
; End of function main
.A16
.I16
call_function_at_0050:
JMP [$50]
; ---------------------------------------------------------------------------
RTI
; End of function call_function_at_0050
.A8
.I16
update_bg_scrolling:
SEP #$20
LDA a:.LOWORD(bg1_h_scroll) ; orig=0x0C9D
STA a:.LOWORD(BG_1_H_SCROLL_OFFSET)
LDA a:.LOWORD(bg1_h_scroll+1) ; orig=0x0C9E
STA a:.LOWORD(BG_1_H_SCROLL_OFFSET)
LDA a:.LOWORD(bg1_v_scroll) ; orig=0x0C9F
STA a:.LOWORD(BG_1_V_SCROLL_OFFSET)
LDA a:.LOWORD(bg1_v_scroll+1) ; orig=0x0CA0
STA a:.LOWORD(BG_1_V_SCROLL_OFFSET)
LDA a:.LOWORD(bg2_h_scroll) ; orig=0x0CA1
STA a:.LOWORD(BG_2_H_SCROLL_OFFSET)
LDA a:.LOWORD(bg2_h_scroll+1) ; orig=0x0CA2
STA a:.LOWORD(BG_2_H_SCROLL_OFFSET)
LDA a:.LOWORD(bg2_v_scroll) ; orig=0x0CA3
STA a:.LOWORD(BG_2_V_SCROLL_OFFSET)
LDA a:.LOWORD(bg2_v_scroll+1) ; orig=0x0CA4
STA a:.LOWORD(BG_2_V_SCROLL_OFFSET)
RTL
; End of function update_bg_scrolling
.A8
.I16
transfer_bg1_bg3_tilemaps:
SEP #$20
LDA a:.LOWORD(level_manager_object+level_manager_object::fade_related_) ; orig=0x0D10
CMP #$30
BEQ locret_C404DF
LDA #1
STA a:.LOWORD(DMA_5_PARAMS)
STA a:.LOWORD(DMA_6_PARAMS)
LDA #$18
STA a:.LOWORD(DMA_5_B_ADDRESS)
STA a:.LOWORD(DMA_6_B_ADDRESS)
REP #$20
.A16
LDA #$5000
STA a:.LOWORD(ADDRESS_FOR_VRAM_READ_WRITE_LOW_BYTE)
LDA #$322
STA a:.LOWORD(DMA_5_BYTES_COUNT_LOW_BYTE)
LDA #.LOWORD(bg1_tilemap)
STA a:.LOWORD(DMA_5_A_ADDRESS_LOW_BYTE)
SEP #$20
.A8
LDA #0
STA a:.LOWORD(DMA_5_A_ADDRESS_BANK)
LDA #$20
STA a:.LOWORD(REGULAR_DMA_CHANNEL_ENABLE)
REP #$20
.A16
LDA #$5800
STA a:.LOWORD(ADDRESS_FOR_VRAM_READ_WRITE_LOW_BYTE)
LDA #$100
STA a:.LOWORD(DMA_6_BYTES_COUNT_LOW_BYTE)
LDA #$816
STA a:.LOWORD(DMA_6_A_ADDRESS_LOW_BYTE)
SEP #$20
.A8
LDA #0
STA a:.LOWORD(DMA_6_A_ADDRESS_BANK)
LDA #$40
STA a:.LOWORD(REGULAR_DMA_CHANNEL_ENABLE)
locret_C404DF:
RTL
; End of function transfer_bg1_bg3_tilemaps
.A8
.I8
vblank:
REP #$30
.A16
.I16
PHB
PHA
PHX
PHY
SEP #$30
.A8
.I8
LDA #0
PHA
PLB
CMP f:NMI_ENABLE
LDA f:.LOWORD(screen_flags) ; orig=0x0312
BIT #1
BNE loc_C404FE
ORA #1
STA f:.LOWORD(screen_flags) ; orig=0x0312
loc_C404FE:
LDA a:.LOWORD(current_mode) ; orig=0x0C3C
BIT #2
BEQ loc_C40525
LDA #4
STA a:.LOWORD(BG_AND_OBJECT_ENABLE_MAIN_SCREEN)
LDA #0
STA a:.LOWORD(BG_AND_OBJECT_ENABLE_SUB_SCREEN)
LDA #0
STA a:.LOWORD(INITIAL_SETTINGS_FOR_COLOR_ADDITION)
LDA #0
STA a:.LOWORD(ADD_SUBTRACT_SELECT_AND_ENABLE)
LDA a:.LOWORD(bg3_v_scroll_2) ; orig=0x0CA7
STA a:.LOWORD(BG_3_V_SCROLL_OFFSET)
LDA a:.LOWORD(bg3_v_scroll_2+1) ; orig=0x0CA8
STA a:.LOWORD(BG_3_V_SCROLL_OFFSET)
loc_C40525:
REP #$30
.A16
.I16
INC a:.LOWORD(frame_count) ; orig=0x0300
PLY
PLX
PLA
PLB
RTI
; End of function vblank
.A8
.I8
irq:
REP #$30
.A16
.I16
PHB
PHA
PHX
PHY
SEP #$30
.A8
.I8
LDA #0
PHA
PLB
LDA a:.LOWORD(IRQ_FLAG_BY_H_V_COUNT_TIMER)
BPL loc_C40572
LDA a:.LOWORD(bg3_v_scroll) ; orig=0x0CA5
STA a:.LOWORD(BG_3_V_SCROLL_OFFSET)
LDA a:.LOWORD(bg3_v_scroll+1) ; orig=0x0CA6
STA a:.LOWORD(BG_3_V_SCROLL_OFFSET)
LDA a:.LOWORD(main_screen_status) ; orig=0x0C97
STA a:.LOWORD(BG_AND_OBJECT_ENABLE_MAIN_SCREEN)
LDA a:.LOWORD(subscreen_status) ; orig=0x0C98
STA a:.LOWORD(BG_AND_OBJECT_ENABLE_SUB_SCREEN)
LDA a:.LOWORD(color_addition_settings) ; orig=0x0C99
STA a:.LOWORD(INITIAL_SETTINGS_FOR_COLOR_ADDITION)
LDA a:.LOWORD(add_substract_select_and_enable) ; orig=0x0C9A
STA a:.LOWORD(ADD_SUBTRACT_SELECT_AND_ENABLE)
JSL f:call_function_at_00d0
LDA #$81
STA a:.LOWORD(NMI_V_H_COUNT_AND_JOYPAD_ENABLE)
LDA #$B1
STA a:.LOWORD(NMI_V_H_COUNT_AND_JOYPAD_ENABLE)
loc_C40572:
REP #$30
.A16
.I16
PLY
PLX
PLA
PLB
RTI
; End of function irq
.A8
.I8
call_function_at_00d0:
JMP [$D0]
; ---------------------------------------------------------------------------
RTI
; End of function call_function_at_00d0
.A8
.I8
nullsub_1:
RTL
; End of function nullsub_1
.A8
.I16
gameover_writing_object:
REP #$20
.A16
LDA #.LOWORD(loc_C40592)
STA AZ .LOWORD(0),X
SEP #$20
.A8
LDA #.BANKBYTE(loc_C40592)
STA AZ .LOWORD(2),X
REP #$20
.A16
STZ AZ .LOWORD($20),X
loc_C40592:
SEP #$20
.A8
LDA a:.LOWORD(current_mode) ; orig=0x0C3C
CMP #2 ; single object::handler
BEQ loc_C4059F
JML f:nullsub_2
; ---------------------------------------------------------------------------
loc_C4059F:
REP #$20
.A16
INC AZ .LOWORD($20),X
LDA AZ .LOWORD($20),X
STA AZ .LOWORD(word_7E0048) ; orig=0x0048
PHX
LDX #.LOWORD(player1_object)
JSL f:write_gameover_for_player_if_needed
LDX #.LOWORD(player2_object)
JSL f:write_gameover_for_player_if_needed
PLX
RTL
; End of function gameover_writing_object
.A16
.I16
write_gameover_for_player_if_needed:
REP #$20
LDA AZ .LOWORD(4),X
BIT #$FF
BEQ loc_C405C9
JML f:nullsub_2
; ---------------------------------------------------------------------------
loc_C405C9:
TXA
EOR #$C0 ; Clever way to get the other object::handler
TAY
LDA #$46
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
LDA AZ .LOWORD(5),X
AND #$FF
BEQ loc_C405E2
LDA #$68
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
loc_C405E2:
LDA a:.LOWORD(level_manager_object+level_manager_object::gameover_related) ; orig=0x0D32
AND #$FF
.IF SHORT_GAMEOVER_BRANCH
BEQ write_gameover
.ELSE
BNE loc_C405EE
JML f:write_gameover
.ENDIF
; ---------------------------------------------------------------------------
loc_C405EE:
LDA a:.LOWORD($3D),Y
AND #$FF
BNE loc_C405FA
JML f:write_gameover
; ---------------------------------------------------------------------------
loc_C405FA:
LDY AZ .LOWORD(word_7E0040) ; orig=0x0040
LDA #$B
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
REP #$20
LDA #.LOWORD(word_C30B2A)
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
SEP #$20
.A8
LDA #.BANKBYTE(word_C30B2A)
STA AZ .LOWORD(byte_7E0052) ; orig=0x0052
JSL f:copy_to_bg3_tilemap
REP #$20
.A16
TYA
CLC
ADC #$2A
TAY
LDA #$B
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
JSL f:copy_to_bg3_tilemap
RTL
; End of function write_gameover_for_player_if_needed
.A16
.I16
hud_related:
REP #$20
LDA #$B
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
REP #$20
LDA #.LOWORD(storymode_hud_tilemap+$46)
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
SEP #$20
.A8
LDA #.BANKBYTE(storymode_hud_tilemap+$46)
STA AZ .LOWORD(byte_7E0052) ; orig=0x0052
JSL f:copy_to_bg3_tilemap
REP #$20
.A16
TYA
CLC
ADC #$2A
TAY
LDA #$B
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
REP #$20
LDA #.LOWORD(storymode_hud_tilemap+$86)
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
SEP #$20
.A8
LDA #.BANKBYTE(storymode_hud_tilemap+$86)
STA AZ .LOWORD(byte_7E0052) ; orig=0x0052
JSL f:copy_to_bg3_tilemap
REP #$20
.A16
STZ AZ .LOWORD(word_7E0040) ; orig=0x0040
STZ AZ .LOWORD(word_7E0042) ; orig=0x0042
JSL f:add_to_score
RTL
; End of function hud_related
.A16
.I16
write_gameover:
REP #$20
LDY AZ .LOWORD(word_7E0040) ; orig=0x0040
LDA #$B
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
REP #$20
LDA #.LOWORD(gameover_tilemap_top)
STA AZ .LOWORD(byte_7E0050) ; orig=0x0050
SEP #$20
.A8
LDA #.BANKBYTE(gameover_tilemap_top)
STA AZ .LOWORD(byte_7E0052) ; orig=0x0052
JSL f:copy_to_bg3_tilemap
REP #$20
.A16
TYA
CLC
ADC #$2A
TAY
LDA #$B
STA AZ .LOWORD(word_7E0040) ; orig=0x0040
JSL f:copy_to_bg3_tilemap
; End of function write_gameover
.A16
.I16
nullsub_2:
RTL
; End of function nullsub_2
; ---------------------------------------------------------------------------
SEP #$20
.A8
.I16
hud_related_object:
REP #$20
.A16
STZ AZ .LOWORD($10),X
STZ AZ .LOWORD($12),X
REP #$20
LDA #.LOWORD(loc_C406BC)
STA AZ .LOWORD(0),X
SEP #$20
.A8
LDA #.BANKBYTE(loc_C406BC)
STA AZ .LOWORD(2),X
loc_C406BC:
SEP #$20
LDA a:.LOWORD(current_mode) ; orig=0x0C3C
CMP #2 ; story mode
BEQ loc_C406D0
CMP #3 ; battle mode
BNE loc_C406CD
JML f:loc_C407C9
; ---------------------------------------------------------------------------
loc_C406CD:
JMP a:.LOWORD(locret_C40768)
; ---------------------------------------------------------------------------
loc_C406D0:
SEP #$20
LDA a:.LOWORD(game_flags) ; orig=0x0314
BIT #$90
BEQ loc_C406DD
JML f:locret_C30015
; ---------------------------------------------------------------------------
loc_C406DD: ; is paused or debug-paused
BIT #$41
BEQ loc_C406E5
JML f:locret_C40768
; ---------------------------------------------------------------------------
loc_C406E5:
REP #$20
.A16
LDA a:.LOWORD(game_flags) ; orig=0x0314
BIT #$C
BEQ loc_C406F3
JML f:locret_C40768
; ---------------------------------------------------------------------------
loc_C406F3:
INC AZ .LOWORD($12),X
LDA AZ .LOWORD($12),X
CMP a:.LOWORD(level_manager_object+level_manager_object::anonymous_10) ; orig=0x0D3A
BNE locret_C40768
STZ AZ .LOWORD($12),X
SEP #$20
.A8
LDY #$5E
INC AZ .LOWORD($10),X
LDA AZ .LOWORD($10),X
AND #7
STA AZ .LOWORD($10),X
ASL
ADC #$C0
STA a:.LOWORD(bg3_tilemap),Y
INC
STA a:.LOWORD(bg3_tilemap+2),Y
CLC
ADC #$F
STA a:.LOWORD(bg3_tilemap+$40),Y
INC
STA a:.LOWORD(bg3_tilemap+$42),Y
LDA AZ .LOWORD($10),X
BNE locret_C40768
LDA a:.LOWORD(player1_object+player::gameover_related) ; orig=0x0D44
BEQ loc_C40746
LDY a:.LOWORD(word_7E0CAA) ; orig=0x0CAA
CPY #$1C
BNE loc_C4073B
JML f:hurry_up
; ---------------------------------------------------------------------------
loc_C4073B:
LDA #$A7
STA a:.LOWORD(bg3_tilemap+$C2),Y
INC a:.LOWORD(word_7E0CAA) ; orig=0x0CAA
INC a:.LOWORD(word_7E0CAA) ; orig=0x0CAA
loc_C40746:
LDA a:.LOWORD(player2_object+player::gameover_related) ; orig=0x0D84
BEQ locret_C40768
LDA a:.LOWORD(word_7E0CAC) ; orig=0x0CAC
CMP #$1C
BNE loc_C40756
JML f:hurry_up
; ---------------------------------------------------------------------------
loc_C40756:
SEC
SBC #$BC
EOR #$FF
INC
TAY
LDA #$A7
STA a:.LOWORD(bg3_tilemap+$40),Y
INC a:.LOWORD(word_7E0CAC) ; orig=0x0CAC
INC a:.LOWORD(word_7E0CAC) ; orig=0x0CAC
locret_C40768:
RTL
; ---------------------------------------------------------------------------
.A16
loc_C40769:
REP #$20
LDA #.LOWORD(locret_C407C8)
STA AZ .LOWORD(0),X
SEP #$20
.A8
LDA #.BANKBYTE(locret_C407C8)