-
Notifications
You must be signed in to change notification settings - Fork 15
/
bank_04.asm
8956 lines (8605 loc) · 242 KB
/
bank_04.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
ORG $048000
DATA_048000:
dw $B480,$B498,$B4B0
DATA_048006:
dw $B300,$B318,$B330,$B348
dw $B360,$B378,$B390,$B3A8
dw $B3C0,$B3D8,$B3F0,$B408
dw $B420,$B438,$B450,$B468
dw $B480,$B498,$B4B0,$B4C8
dw $B4E0,$B4F8,$B510,$B528
dw $B540,$B558,$B570,$B588
dw $B5A0,$B5B8,$B5D0,$B5E8
dw $B600,$B618,$B630,$B648
dw $B660,$B678,$B690,$B6A8
dw $B6C0,$B6D8,$B6F0,$B708
dw $B720,$B738,$B750,$B768
dw $B780,$B798,$B7B0,$B7C8
dw $B7E0,$B7F8,$B810,$B828
dw $B840,$B858,$B870,$B888
dw $B8A0,$B8B8,$B8D0,$B8E8
CODE_048086:
REP #$30 ; AXY->16
STZ.B _3
STZ.B _5
- LDX.B _3
LDA.W DATA_048000,X
STA.B _0
SEP #$10 ; XY->8
LDY.B #$7E
STY.B _2
REP #$10 ; XY->16
LDX.B _5
JSR CODE_0480B9
LDA.B _5
CLC
ADC.W #$0020
STA.B _5
LDA.B _3
INC A
INC A
STA.B _3
AND.W #$00FF
CMP.W #$0006
BNE -
SEP #$30 ; AXY->8
RTS
CODE_0480B9:
LDY.W #$0000
LDA.W #$0008
STA.B _7
STA.B _9
- LDA.B [_0],Y
STA.W GfxDecompOWAni,X
INY
INY
INX
INX
DEC.B _7
BNE -
- LDA.B [_0],Y
AND.W #$00FF
STA.W GfxDecompOWAni,X
INY
INX
INX
DEC.B _9
BNE -
RTS
OW_Tile_Animation:
LDA.B TrueFrame ; \
AND.B #$07 ; |If lower 3 bits of frame counter isn't 0,
BNE CODE_048101 ; / don't update the water animation
LDX.B #$1F
CODE_0480E8:
LDA.W GfxDecompOWAni,X
STA.B _0
TXA
AND.B #$08
BNE CODE_0480F9
ASL.B _0
ROL.W GfxDecompOWAni,X
BRA +
CODE_0480F9:
LSR.B _0
ROR.W GfxDecompOWAni,X
+ DEX
BPL CODE_0480E8
CODE_048101:
LDA.B TrueFrame ; \
AND.B #$07 ; |If lower 3 bits of frame counter isn't 0,
BNE + ; / don't update the waterfall animation
LDX.B #$20
JSR CODE_048172
+ LDA.B TrueFrame ; \
AND.B #$07 ; |If lower 3 bits of frame counter isn't 0,
BNE CODE_048123 ; / branch to $8123
LDX.B #$1F
- LDA.W GfxDecompOWAni+$40,X
ASL A
ROL.W GfxDecompOWAni+$40,X
DEX
BPL -
LDX.B #$40
JSR CODE_048172
CODE_048123:
REP #$30 ; AXY->16
LDA.W #$0060
STA.B _D
STZ.B _B
CODE_04812C:
LDX.W #$0038
LDA.B _B
CMP.W #$0020
BCS +
LDX.W #$0070
+ TXA
AND.B TrueFrame
LSR A
LSR A
CPX.W #$0038
BEQ +
LSR A
+ CLC
ADC.B _B
TAX
LDA.W DATA_048006,X
STA.B _0
SEP #$10 ; XY->8
LDY.B #$7E
STY.B _2
REP #$10 ; XY->16
LDX.B _D
JSR CODE_0480B9
LDA.B _D
CLC
ADC.W #$0020
STA.B _D
LDA.B _B
CLC
ADC.W #$0010
STA.B _B
CMP.W #$0080
BNE CODE_04812C
SEP #$30 ; AXY->8
RTS
CODE_048172:
REP #$20 ; A->16
LDY.B #$00
- PHX
TXA
CLC
ADC.W #$000E
TAX
LDA.W GfxDecompOWAni,X
STA.B _0
PLX
CODE_048183:
LDA.W GfxDecompOWAni,X
STA.B _2
LDA.B _0
STA.W GfxDecompOWAni,X
LDA.B _2
STA.B _0
INX
INX
INY
CPY.B #$08
BEQ -
CPY.B #$10
BNE CODE_048183
SEP #$20 ; A->8
RTS
OWScrollArrowStripe:
db $50,$CF,$00,$03,$7E,$78,$7E,$38
db $50,$EF,$00,$03,$7F,$38,$7F,$78
db $51,$C3,$00,$03,$7E,$78,$7D,$78
db $51,$E3,$00,$03,$7E,$F8,$7D,$F8
db $51,$DB,$00,$03,$7D,$38,$7E,$38
db $51,$FB,$00,$03,$7D,$B8,$7E,$B8
db $52,$EF,$00,$03,$7F,$B8,$7F,$F8
db $53,$0F,$00,$03,$7E,$F8,$7E,$B8
db $FF
OWScrollEraseStripe:
db $50,$CF,$40,$02,$FC,$00,$50,$EF
db $40,$02,$FC,$00,$51,$C3,$40,$02
db $FC,$00,$51,$E3,$40,$02,$FC,$00
db $51,$DB,$40,$02,$FC,$00,$51,$FB
db $40,$02,$FC,$00,$52,$EF,$40,$02
db $FC,$00,$53,$0F,$40,$02,$FC,$00
db $FF
OWScrollSpeed:
db $00,$00,$02,$00,$FE,$FF,$02,$00
db $00,$00,$02,$00,$FE,$FF,$02,$00
OWMaxScrollRange:
db $00,$00,$11,$01,$EF,$FF,$11,$01
db $00,$00,$32,$01,$D7,$FF,$32,$01
DATA_048231:
db $0F,$0F,$07,$07,$07,$03,$03,$03
db $01,$01,$03,$03,$03,$07,$07,$07
GameMode_0E_Prim:
PHB
PHK
PLB
LDX.B #$01 ; \ If player 1 pushes select...
CODE_048246:
LDA.W byetudlrP1Frame,X ; |
AND.B #$20 ; | ...disabled by BRA
BRA CODE_048261 ; / Change to BEQ to enable debug code below
LDA.W SavedPlayerYoshi,X ; \ Unreachable
INC A ; | Debug: Change Yoshi color
INC A ; |
CMP.B #$04 ; |
BCS + ; |
LDA.B #$04 ; |
+ CMP.B #$0B ; |
BCC + ; |
LDA.B #$00 ; |
+ STA.W SavedPlayerYoshi,X ; /
CODE_048261:
DEX
BPL CODE_048246
JSR CODE_0485A7
JSR OW_Tile_Animation
LDA.W SwitchPalaceColor ; \ If "! blocks flying away color" is 0,
BEQ + ; / don't play the animation
JSR CODE_04F290
JMP CODE_04840D
+ LDA.W ShowContinueEnd ; \ If not showing Continue/End message,
BEQ + ; / branch to $8281
JSL ProcContinueEndMenu
JMP CODE_048410
+ LDA.W OverworldPromptProcess
BEQ CODE_048295
CMP.B #$05
BCS CODE_04828F
LDY.W IsTwoPlayerGame
BEQ CODE_048295
CODE_04828F:
JSR CODE_04F3E5
JMP CODE_048413
CODE_048295:
LDA.W PauseFlag
LSR A
BNE +
JMP CODE_048356
+ REP #$20 ; A->16
LDA.W OverworldFreeCamYPos
SEC
SBC.B Layer1YPos
STA.B _1
BPL +
EOR.W #$FFFF
INC A
+ LSR A
SEP #$20 ; A->8
STA.B _5
REP #$20 ; A->16
LDA.W OverworldFreeCamXPos
SEC
SBC.B Layer1XPos
STA.B _0
BPL +
EOR.W #$FFFF
INC A
+ LSR A
SEP #$20 ; A->8
STA.B _4
LDX.B #$01
CMP.B _5
BCS +
DEX
LDA.B _5
+ CMP.B #$02
BCS +
REP #$20 ; A->16
LDA.W OverworldFreeCamXPos
STA.B Layer1XPos
STA.B Layer2XPos
LDA.W OverworldFreeCamYPos
STA.B Layer1YPos
STA.B Layer2YPos
SEP #$20 ; A->8
STZ.W PauseFlag
JMP CODE_0483BD
+ STZ.W HW_WRDIV
LDY.B _4,X
STY.W HW_WRDIV+1
STA.W HW_WRDIV+2
NOP ; \
NOP ; |
NOP ; |Makes you wonder what used to be here...
NOP ; |
NOP ; | NOTHING! Division takes time!
NOP ; /
REP #$20 ; A->16
LDA.W HW_RDDIV
LSR A
LSR A
SEP #$20 ; A->8
LDY.B _1,X
BPL +
EOR.B #$FF
INC A
+ STA.B _1,X
TXA
EOR.B #$01
TAX
LDA.B #$40
LDY.B _1,X
BPL +
LDA.B #$C0
+ STA.B _1,X
LDY.B #$01
CODE_048320:
TYA
ASL A
TAX
LDA.W _1,Y
ASL A
ASL A
ASL A
ASL A
CLC
ADC.W Layer1PosSpx,Y
STA.W Layer1PosSpx,Y
LDA.W _1,Y
PHY
PHP
LSR A
LSR A
LSR A
LSR A
LDY.B #$00
PLP
BPL +
ORA.B #$F0
DEY
+ ADC.B Layer1XPos,X
STA.B Layer1XPos,X
STA.B Layer2XPos,X
TYA
ADC.B Layer1XPos+1,X
STA.B Layer1XPos+1,X
STA.B Layer2XPos+1,X
PLY
DEY
BPL CODE_048320
JMP CODE_04840D
CODE_048356:
LDA.W OverworldProcess
CMP.B #$03
BEQ CODE_048366
CMP.B #$04
BNE CODE_04839A
LDA.W PlayerSwitching
BNE CODE_04839A
CODE_048366:
if ver_is_console(!_VER) ;\================= J, U, E0, & E1 ==============
LDA.W axlr0000P1Frame ;!
ORA.W axlr0000P2Frame ;!
AND.B #$30 ;!
BEQ + ;!
LDA.B #$01 ;!
STA.W OverworldPromptProcess ;!
endif ;/===============================================
+ LDX.W PlayerTurnLvl
LDA.W OWPlayerSubmap,X
BNE CODE_04839A
LDA.B byetudlrFrame
AND.B #$10
BEQ CODE_04839A
INC.W PauseFlag ; Look around overworld
LDA.W PauseFlag
LSR A
BNE CODE_04839A
REP #$20 ; A->16
LDA.B Layer1XPos
STA.W OverworldFreeCamXPos
LDA.B Layer1YPos
STA.W OverworldFreeCamYPos
SEP #$20 ; A->8
CODE_04839A:
LDA.W PauseFlag
BEQ CODE_0483C3
LDX.B #$00
LDA.B byetudlrHold
AND.B #$03
ASL A
JSR OWFreeLook
LDX.B #$02
LDA.B byetudlrHold
AND.B #$0C
ORA.B #$10
LSR A
JSR OWFreeLook
LDY.B #$15
LDA.B TrueFrame
AND.B #$18
BNE +
CODE_0483BD:
LDY.B #$18
+ STY.B StripeImage
BRA CODE_04840D
CODE_0483C3:
LDX.W OverworldEarthquake
BEQ CODE_04840A
CPX.B #$FE
BNE +
LDA.B #!SFX_RUMBLINGON
STA.W SPCIO0 ; / Play sound effect
LDA.B #!BGM_VALLEYOPENS
STA.W SPCIO2 ; / Change music
+ TXA
LSR A
LSR A
LSR A
LSR A
TAY
LDA.B TrueFrame
AND.W DATA_048231,Y
BNE +
LDA.B Layer1XPos
EOR.B #$01
STA.B Layer1XPos
STA.B Layer2XPos
LDA.B Layer1YPos
EOR.B #$01
STA.B Layer1YPos
STA.B Layer2YPos
+ CPX.B #$80
BCS CODE_0483FE
LDA.W OverworldProcess
CMP.B #$02
BNE CODE_04840A
CODE_0483FE:
DEC.W OverworldEarthquake
BNE CODE_04840D
LDA.B #!SFX_RUMBLINGOFF
STA.W SPCIO0 ; / Play sound effect
BRA CODE_04840D
CODE_04840A:
JSR CODE_048576
CODE_04840D:
JSR CODE_04F708
CODE_048410:
JSR CODE_04862E
CODE_048413:
PLB
RTL
OWFreeLook:
TAY ; A=$2,X=$0 for right; A=$4,X=$0 for left; A=$A,X=$2 for down; A=$C,X=$2 for up
REP #$20 ; A->16
LDA.B Layer1XPos,X
CLC
ADC.W OWScrollSpeed,Y
PHA
SEC
SBC.W OWMaxScrollRange,Y
EOR.W OWScrollSpeed,Y
ASL A
PLA
BCC +
STA.B Layer1XPos,X
STA.B Layer2XPos,X
+ SEP #$20 ; A->8
RTS
DATA_048431:
db $11,$00,$0A,$00,$09,$00,$0B,$00
db $12,$00,$0A,$00,$07,$00,$0A,$02
db $03,$02,$10,$04,$12,$04,$1C,$04
db $14,$04,$12,$06,$00,$02,$12,$06
db $10,$00,$17,$06,$14,$00,$1C,$06
db $14,$00,$1C,$06,$17,$06,$11,$05
db $11,$05,$14,$04,$06,$01
DATA_048467:
db $07,$00,$03,$00,$10,$00,$0E,$00
db $17,$00,$18,$00,$12,$00,$14,$00
db $0B,$00,$03,$00,$01,$00,$09,$00
db $09,$00,$1D,$00,$0E,$00,$18,$00
db $0F,$00,$16,$00,$10,$00,$18,$00
db $02,$00,$1D,$00,$18,$00,$13,$00
db $11,$00,$03,$00,$07,$00
DATA_04849D:
db $A8,$04,$38,$04,$08,$09,$28,$09
db $C8,$09,$48,$09,$28,$0D,$18,$01
db $A8,$00,$98,$00,$B8,$00,$28,$01
db $A8,$00,$78,$00,$28,$0D,$08,$04
db $78,$0D,$08,$01,$C8,$0D,$48,$01
db $C8,$0D,$48,$09,$18,$0B,$78,$0D
db $68,$02,$C8,$0D,$28,$0D
DATA_0484D3:
db $48,$01,$B8,$00,$38,$00,$18,$00
db $98,$00,$98,$00,$D8,$01,$78,$00
db $38,$00,$08,$01,$E8,$00,$78,$01
db $88,$01,$28,$01,$88,$01,$E8,$00
db $68,$01,$F8,$00,$88,$01,$08,$01
db $D8,$01,$38,$00,$38,$01,$88,$01
db $78,$00,$D8,$01,$D8,$01
CODE_048509:
LDY.W PlayerTurnLvl ; \ Get current player's submap
LDA.W OWPlayerSubmap,Y ; /
STA.B _1 ; Store it in $01
STZ.B _0 ; Store x00 in $00
REP #$20 ; A->16
LDX.W PlayerTurnOW ; Set X to Current character*4
LDY.B #$34 ; Set Y to x34
CODE_04851A:
LDA.W DATA_048431,Y
EOR.B _0
CMP.W #$0200
BCS CODE_048531
CMP.W OWPlayerXPosPtr,X
BNE CODE_048531
LDA.W OWPlayerYPosPtr,X
CMP.W DATA_048467,Y
BEQ CODE_048535
CODE_048531:
DEY
DEY
BPL CODE_04851A
CODE_048535:
STY.W StarWarpIndex ; Store Y in "Warp destination"
SEP #$20 ; A->8
RTS
CODE_04853B:
PHB
PHK
PLB
REP #$20 ; A->16
LDX.W PlayerTurnOW
LDY.W StarWarpIndex
LDA.W DATA_04849D,Y
PHA
AND.W #$01FF
STA.W OWPlayerXPos,X
LSR A
LSR A
LSR A
LSR A
STA.W OWPlayerXPosPtr,X
LDA.W DATA_0484D3,Y
STA.W OWPlayerYPos,X
LSR A
LSR A
LSR A
LSR A
STA.W OWPlayerYPosPtr,X
PLA
LSR A
XBA
AND.W #$000F
STA.W CurrentSubmap
REP #$10 ; XY->16
JSR CODE_049A93
SEP #$30 ; AXY->8
PLB
RTL
CODE_048576:
LDA.W OverworldProcess
JSL ExecutePtrLong
dl CODE_048EF1
dl CODE_04E570
dl CODE_048F87
dl CODE_049120
dl CODE_04945D
dl CODE_049D9A
dl CODE_049E22
dl CODE_049DD1
dl CODE_049E22
dl CODE_049E4C
dl CODE_04DAEF
dl CODE_049E52
dl CODE_0498C6
DrawOWBoarder_:
JSR CODE_04862E
CODE_0485A7:
REP #$20 ; A->16
LDA.W #$001E ; \ Mario X postion = #$001E
CLC ; | (On overworld boarder)
ADC.B Layer1XPos ; |
STA.B PlayerXPosNext ; /
LDA.W #$0006 ; \ Mario Y postion = #$0006
CLC ; | (On overworld boarder)
ADC.B Layer1YPos ; |
STA.B PlayerYPosNext ; /
SEP #$20 ; A->8
LDA.B #$08
STA.W PlayerXSpeed+1
PHB
LDA.B #$00
PHA
PLB
JSL CODE_00CEB1
PLB
LDA.B #$03
STA.W PlayerBehindNet
JSL DrawMarioAndYoshi
LDA.B #$06
STA.W PlayerGfxTileCount
LDA.W PlayerAniTimer
BEQ +
DEC.W PlayerAniTimer
+ LDA.W CapeAniTimer
BEQ +
DEC.W CapeAniTimer
+ LDA.B #$18
STA.B _0
LDA.B #$07
STA.B _1
LDY.B #$00
TYX
CODE_0485F3:
LDA.B _0
STA.W OAMTileXPos,X
CLC
ADC.B #$08
STA.B _0
LDA.B _1
STA.W OAMTileYPos,X
LDA.B #$7E
STA.W OAMTileNo,X
LDA.B #$36
STA.W OAMTileAttr,X
PHX
TYX
LDA.B #$00
STA.W OAMTileSize,X
PLX
INY
TYA
AND.B #$03
BNE +
LDA.B #$18
STA.B _0
LDA.B _1
CLC
ADC.B #$08
STA.B _1
+ INX
INX
INX
INX
CPY.B #$10
BNE CODE_0485F3
RTS
CODE_04862E:
REP #$30 ; AXY->16
LDX.W PlayerTurnOW ; X = player x 4
LDA.W OWPlayerXPos,X ; A = player X-pos on OW
SEC
SBC.B Layer1XPos ; A = X-pos on screen
CMP.W #$0100
BCS CODE_04864D ; \ if < #$0100
STA.B _0 ; | $00 = X-pos on screen
STA.B _8 ; | $08 = X-pos on screen
LDA.W OWPlayerYPos,X ; | A = player Y-pos on OW
SEC ; |
SBC.B Layer1YPos ; | A = Y-pos on screen
CMP.W #$0100 ; |
BCC + ; /
CODE_04864D:
LDA.W #$00F0 ; \
+ STA.B _2 ; | $02 = Y-pos on screen
STA.B _A ; / $0A = Y-pos on screen
TXA ; A = player x 4
EOR.W #$0004 ; A = other player x 4
TAX ; X = other player x 4
LDA.W OWPlayerXPos,X ; \
SEC ; | (same as above, but for luigi)
SBC.B Layer1XPos ; |
CMP.W #$0100 ; |
BCS CODE_048673 ; |
STA.B _4 ; | $04 = X-pos on screen
STA.B _C ; | $0C = X-pos on screen
LDA.W OWPlayerYPos,X ; |
SEC ; |
SBC.B Layer1YPos ; |
CMP.W #$0100 ; |
BCC + ; |
CODE_048673:
LDA.W #$00F0 ; |
+ STA.B _6 ; | $06 = Y-pos on screen
STA.B _E ; / $0E = Y-pos on screen
SEP #$30 ; AXY->8
LDA.B _0
SEC
SBC.B #$08 ; subtract 8 from 1P X-pos
STA.B _0 ; $00 = 1P X-pos on screen
LDA.B _2
SEC
SBC.B #$09 ; subtract 9 from 1P Y-pos
STA.B _1 ; $01 = 1P Y-pos on screen
LDA.B _4
SEC
SBC.B #$08 ; subtract 8 from 2P X-pos
STA.B _2 ; $02 = 2P X-pos on screen
LDA.B _6
SEC
SBC.B #$09 ; subtract 9 from 2P Y-pos
STA.B _3 ; $03 = 2P Y-pos on screen
LDA.B #$03
STA.B GraphicsCompPtr+2 ; $8C = #$03
LDA.B _0
STA.B _6 ; $06 = 1P X-pos on screen
STA.B GraphicsCompPtr ; $8A = 1P X-pos on screen
LDA.B _1
STA.B _7 ; $07 = 1P Y-pos on screen
STA.B GraphicsCompPtr+1 ; $8B = 1P Y-pos on screen
LDA.W PlayerTurnOW ; A = player x 4
LSR A ; A = player x 2
TAY ; Y = player x 2
LDA.W OWPlayerAnimation,Y ; A = player OW animation type
CMP.B #$12
BEQ CODE_0486C5 ; skip if enter level in water animation
CMP.B #$07
BCC CODE_0486BC ; don't skip if moving on land
CMP.B #$0F
BCC CODE_0486C5 ; skip if moving in water
CODE_0486BC:
LDA.B GraphicsCompPtr+1
SEC
SBC.B #$05 ; subtract 5 from Y-pos if on land
STA.B GraphicsCompPtr+1 ; $8B = 1P Y-pos on screen
STA.B _7 ; $07 = 1P Y-pos on screen
CODE_0486C5:
REP #$30 ; AXY->16
LDA.W PlayerTurnOW ; A = player x 4
XBA ; A = player x #$400
LSR A ; A = player x #$200
STA.B _4 ; $04 = player x #$200
LDX.W #$0000 ; X = #$0000
JSR CODE_048789 ; draw halo if out of lives
LDA.W PlayerTurnOW ; A = player x 4
LSR A ; A = player x 2
TAY ; Y = player x 2
LDX.W #$0000 ; X = #$0000
JSR CODE_04894F
SEP #$30 ; AXY->8
STZ.W OAMTileSize+$27 ; \
STZ.W OAMTileSize+$28 ; | make OAM tiles 8x8
STZ.W OAMTileSize+$29 ; |
STZ.W OAMTileSize+$2A ; |
STZ.W OAMTileSize+$2B ; |
STZ.W OAMTileSize+$2C ; |
STZ.W OAMTileSize+$2D ; |
STZ.W OAMTileSize+$2E ; /
LDA.B #$03
STA.B GraphicsCompPtr+2 ; $8C = #$03
LDA.W OWPlayerSubmap ; A = 1P submap
LDY.W OverworldProcess ; Y = overworld process
CPY.B #$0A
BNE +
EOR.B #$01 ; ??
+ CMP.W OWPlayerSubmap+1
BNE CODE_048786 ; skip everything if 1P and 2P are on different submaps
LDA.B _2
STA.B _6 ; $06 = 2P X-pos on screen
STA.B GraphicsCompPtr ; $8A = 2P X-pos on screen
LDA.B _3
STA.B _7 ; $07 = 2P Y-pos on screen
STA.B GraphicsCompPtr+1 ; $8B = 2P Y-pos on screen
LDA.W PlayerTurnOW ; A = player x 4
LSR A ; A = player x 2
EOR.B #$02 ; A = other player x 2
TAY ; Y = other player x 2
LDA.W OWPlayerAnimation,Y ; A = other player OW animation type
CMP.B #$12
BEQ CODE_048739 ; skip if enter level in water animation
CMP.B #$07
BCC CODE_048730 ; don't skip if moving on land
CMP.B #$0F
BCC CODE_048739 ; skip if moving in water
CODE_048730:
LDA.B GraphicsCompPtr+1
SEC
SBC.B #$05 ; subtract 5 from Y-pos if on land
STA.B GraphicsCompPtr+1 ; $8B = 2P Y-pos on screen
STA.B _7 ; $07 = 2P Y-pos on screen
CODE_048739:
REP #$30 ; AXY->16
LDA.W IsTwoPlayerGame
AND.W #$00FF
BEQ CODE_048786 ; skip everything if we are in a 1P-game (why check that so late?)
LDA.B _C
CMP.W #$00F0
BCS CODE_048786 ; skip if 2P is offscreen in the X direction
LDA.B _E
CMP.W #$00F0
BCS CODE_048786 ; skip if 2P is offscreen in the Y direction
LDA.B _4 ; A = player x #$200
EOR.W #$0200 ; A = other player x #$200
STA.B _4 ; $04 = other player x #$200
LDX.W #$0020 ; X = #$0020
JSR CODE_048789 ; draw halo if out of lives
LDA.W PlayerTurnOW ; A = player x 4
LSR A ; A = player x 2
EOR.W #$0002 ; A = other player x 2
TAY ; Y = other player x 2
LDX.W #$0020 ; X = #$0020
JSR CODE_04894F
SEP #$30 ; AXY->8
STZ.W OAMTileSize+$2F ; \
STZ.W OAMTileSize+$30 ; | make OAM tiles 8x8
STZ.W OAMTileSize+$31 ; |
STZ.W OAMTileSize+$32 ; |
STZ.W OAMTileSize+$33 ; |
STZ.W OAMTileSize+$34 ; |
STZ.W OAMTileSize+$35 ; |
STZ.W OAMTileSize+$36 ; /
CODE_048786:
SEP #$30 ; AXY->8
RTS
CODE_048789:
LDA.B GraphicsCompPtr ; A = Y-pos on screen | X-pos on screen
PHA
PHX ; X = player x #$20
LDA.B _4 ; A = player x #$200
XBA ; A = player x 2
LSR A ; A = player
TAX ; X = player
LDA.W SavedPlayerLives-1,X ; A = player lives | junk
PLX ; X = player x #$20
AND.W #$FF00 ; A = player lives | #$00
BPL + ; skip if player lives positive
SEP #$20 ; A->8
LDA.B GraphicsCompPtr
STA.W OAMTileXPos+$B4,X ; OAM X-pos of 1st halo tile
CLC
ADC.B #$08
STA.W OAMTileXPos+$B8,X ; OAM X-pos of 2nd halo tile
LDA.B GraphicsCompPtr+1
CLC
ADC.B #$F9
STA.W OAMTileYPos+$B4,X ; OAM Y-pos of 1st halo tile
STA.W OAMTileYPos+$B8,X ; OAM Y-pos of 2nd halo tile
LDA.B #$7C
STA.W OAMTileNo+$B4,X ; OAM tile number of 1st halo tile
STA.W OAMTileNo+$B8,X ; OAM tile number of 2nd halo tile
LDA.B #$20
STA.W OAMTileAttr+$B4,X ; OAM yxppccct of 1st halo tile
LDA.B #$60
STA.W OAMTileAttr+$B8,X ; OAM yxppccct of 2nd halo tile
REP #$20 ; A->16
+ PLA ; A = Y-pos on screen | X-pos on screen
STA.B GraphicsCompPtr ; $8A = X-pos on screen, $8B = Y-pos on screen
RTS
OWPlayerTiles:
db $0E,$24,$0F,$24,$1E,$24,$1F,$24
db $20,$24,$21,$24,$30,$24,$31,$24
db $0E,$24,$0F,$24,$1E,$24,$1F,$24
db $20,$24,$21,$24,$31,$64,$30,$64
db $0A,$24,$0B,$24,$1A,$24,$1B,$24
db $0C,$24,$0D,$24,$1C,$24,$1D,$24
db $0A,$24,$0B,$24,$1A,$24,$1B,$24
db $0C,$24,$0D,$24,$1D,$64,$1C,$64
db $08,$24,$09,$24,$18,$24,$19,$24
db $06,$24,$07,$24,$16,$24,$17,$24
db $08,$24,$09,$24,$18,$24,$19,$24
db $06,$24,$07,$24,$16,$24,$17,$24
db $09,$64,$08,$64,$19,$64,$18,$64
db $07,$64,$06,$64,$17,$64,$16,$64
db $09,$64,$08,$64,$19,$64,$18,$64
db $07,$64,$06,$64,$17,$64,$16,$64
db $0E,$24,$0F,$24,$38,$24,$38,$64
db $20,$24,$21,$24,$39,$24,$39,$64
db $0E,$24,$0F,$24,$38,$24,$38,$64
db $20,$24,$21,$24,$39,$24,$39,$64
db $0A,$24,$0B,$24,$38,$24,$38,$64
db $0C,$24,$0D,$24,$39,$24,$39,$64
db $0A,$24,$0B,$24,$38,$24,$38,$64
db $0C,$24,$0D,$24,$39,$24,$39,$64
db $08,$24,$09,$24,$38,$24,$38,$64
db $06,$24,$07,$24,$39,$24,$39,$64
db $08,$24,$09,$24,$38,$24,$38,$64
db $06,$24,$07,$24,$39,$24,$39,$64
db $09,$64,$08,$64,$38,$24,$38,$64
db $07,$64,$06,$64,$39,$24,$39,$64
db $09,$64,$08,$64,$38,$24,$38,$64
db $07,$64,$06,$64,$39,$24,$39,$64
db $24,$24,$25,$24,$34,$24,$35,$24
db $24,$24,$25,$24,$34,$24,$35,$24
db $24,$24,$25,$24,$34,$24,$35,$24
db $24,$24,$25,$24,$34,$24,$35,$24
db $24,$24,$25,$24,$38,$24,$38,$64
db $24,$24,$25,$24,$38,$24,$38,$64
db $24,$24,$25,$24,$38,$24,$38,$64
db $24,$24,$25,$24,$38,$24,$38,$64
db $46,$24,$47,$24,$56,$24,$57,$24
db $47,$64,$46,$64,$57,$64,$56,$64
db $46,$24,$47,$24,$56,$24,$57,$24
db $47,$64,$46,$64,$57,$64,$56,$64
db $46,$24,$47,$24,$56,$24,$57,$24
db $47,$64,$46,$64,$57,$64,$56,$64
db $46,$24,$47,$24,$56,$24,$57,$24
db $47,$64,$46,$64,$57,$64,$56,$64
OWWarpIndex:
db $20,$60,$00,$40
CODE_04894F:
SEP #$30 ; AXY->8
PHY ; Y = player x 2
TYA ; A = player x 2
LSR A ; A = player
TAY ; Y = player
LDA.W SavedPlayerYoshi,Y ; A = player's yoshi color
BEQ + ; branch if no yoshi
STA.B _E ; $0E = player's yoshi color
STZ.B _F ; $0F = #$00
PLY ; Y = player x 2
JMP CODE_048CE6 ; jump
+ PLY ; Y = player x 2
REP #$30 ; AXY->16
LDA.W OWPlayerAnimation,Y ; A = player OW animation type
ASL A
ASL A
ASL A
ASL A ; A = player OW animation type x #$10
STA.B _0 ; $00 = player OW animation type x #$10
LDA.B TrueFrame ; A = frame counter
AND.W #$0018 ; A = 5 LSB of frame counter
CLC
ADC.B _0 ; A = 0000 000a aaaf ffff (a = animation type, f = 5 LSB of frame counter)
TAY ; Y = that index ^
PHX ; X = player x #$20
LDA.B _4 ; A = player x #$200
XBA ; A = player x 2
LSR A ; A = player
TAX ; X = player
LDA.W SavedPlayerLives-1,X ; A = player's lives | junk
PLX ; X = player x #$20
AND.W #$FF00 ; A = player's lives | #$00
BPL CODE_04898B ; branch if player's lives positive
LDA.B _0 ; A = player OW animation type x #$10
TAY ; Y = player OW animation type x #$10
BRA CODE_0489A7 ; branch (basically, if player is out of lives, their sprite is static)
CODE_04898B:
CPX.W #$0000
BNE CODE_0489A7 ; skip if 2P
LDA.W OverworldProcess
CMP.W #$000B
BNE CODE_0489A7 ; skip if not on star warp
LDA.B TrueFrame ; A = frame counter
AND.W #$000C ; A = 0000 ff00 (f = frame counter bits)
LSR A
LSR A ; A = 2 LSB of frame counter / 4
TAY ; Y = 2 LSB of frame counter / 4
LDA.W OWWarpIndex,Y ; A = index to use when using a star warp (overrides that complicated thing)
AND.W #$00FF
TAY ; Y = index into tilemap table
CODE_0489A7:
REP #$20 ; A->16
LDA.B GraphicsCompPtr ; A = Y-pos on screen | X-pos on screen
STA.W OAMTileXPos+$9C,X ; OAM y-pos and x-pos for tile
LDA.W OWPlayerTiles,Y ; get tile | yxppccct
CLC
ADC.B _4 ; add player x #$200 (increment palette of tile by 1)
STA.W OAMTileNo+$9C,X ; OAM tile and yxppccct for tile
SEP #$20 ; A->8
INX
INX
INX
INX ; increment X to next OAM tile