-
Notifications
You must be signed in to change notification settings - Fork 15
/
bank_05.asm
9741 lines (9461 loc) · 291 KB
/
bank_05.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 $058000
TilesetMAP16Loc:
dw Map16Tileset0 ; Addresses to tileset-specific MAP16 data
dw Map16Tileset1
dw Map16Tileset2
dw Map16Tileset3
dw Map16Tileset4
dw Map16Tileset4
dw Map16Tileset2
dw Map16Tileset0
dw Map16Tileset2
dw Map16Tileset3
dw Map16Tileset3
dw Map16Tileset3
dw Map16Tileset0
dw Map16Tileset4
dw Map16Tileset3
CODE_05801E:
PHP
SEP #$20 ; A->8
REP #$10 ; XY->16
LDX.W #$0000 ; \
- LDA.B #$25 ; |
STA.L Layer2TilemapLow,X ; |Set all background tiles (lower bytes) to x25
STA.L Layer2TilemapLow+$200,X ; |
INX ; |
CPX.W #$0200 ; |
BNE - ; /
STZ.W LevelLoadObject
LDA.B Layer2DataPtr+2 ; \
CMP.B #$FF ; |If the layer 2 data is a background,
BNE CODE_058074 ; / branch to $8074
REP #$10 ; XY->16
LDY.W #$0000 ; \
LDX.B Layer2DataPtr ; |
CPX.W #DATA_0CE8FE ; |If Layer 2 pointer >= $E8FF,
BCC + ; |the background should use Map16 page x11 instead of x10
LDY.W #$0001 ; |
+ LDX.W #$0000 ; \
TYA ; |
- STA.L Layer2TilemapHigh,X ; |Set the background's Map16 page
STA.L Layer2TilemapHigh+$200,X ; |(i.e. setting all high tile bytes to Y)
INX ; |
CPX.W #$0200 ; |
BNE - ; /
LDA.B #$0C ; \ Set highest Layer 2 address to x0C
STA.B Layer2DataPtr+2 ; / (All backgrounds are stored in bank 0C)
STZ.W Empty1932 ; \ Set tileset to 0
STZ.W ObjectTileset ; /
LDX.W #$B900
STX.B _D
REP #$20 ; A->16
JSR CODE_058126
CODE_058074:
SEP #$20 ; A->8
LDX.W #$0000 ; \
- LDA.B #$00 ; |
JSR CODE_05833A ; |Clear level data
DEX ; |
LDA.B #$25 ; |
JSR CODE_0582C8 ; |
CPX.W #$0200 ; |
BNE - ; /
STZ.W LevelLoadObject
JSR LoadLevel ; Load the level
SEP #$30 ; AXY->8
LDA.W GameMode ; \
CMP.B #$22 ; |
BPL + ; |If level mode is less than x22,
JSL CODE_02A751 ; |JSL to $02A751
+ PLP
RTL
if ver_is_lores(!_VER) ;\================== J, U, SS, & E0 =============
CODE_05809E: ;!
PHP ;!
SEP #$20 ;! A->8
else ;<======================== E1 ===================
EDATA_05809E: ;!
db $20,$00,$5F,$FE,$FA,$18,$30,$00 ;!
db $5F,$FE,$FA,$18,$FF ;!
;!
CODE_05809E: ;!
PHP ;!
SEP #$20 ;! A->8
LDX.B #$0C ;!
- LDA.L EDATA_05809E,X ;!
STA.L DynamicStripeImage,X ;!
DEX ;!
BPL - ;!
STZ.B StripeImage ;!
JSL CODE_0084C8 ;!
LDA.B #$80 ;!
STA.W HW_M7SEL ;!
endif ;/===============================================
STZ.W LevelLoadObject ; Zero a byte in the middle of the RAM table for the level header
REP #$30 ; AXY->16
LDA.W #$FFFF
STA.B Layer1PrevTileUp ; $4D to $50 = #$FF
STA.B Layer1PrevTileDown
JSR CODE_05877E ; -> here
LDA.B Layer1TileUp
STA.B Layer1TileDown
LDA.B Layer2TileUp
STA.B Layer2TileDown
LDA.W #$0202
STA.B Layer1ScrollDir
CODE_0580BD:
REP #$30 ; AXY->16
JSL CODE_0588EC
JSL CODE_058955
JSL UploadOneMap16Strip
REP #$30 ; AXY->16
INC.B Layer1TileDown
INC.B Layer2TileDown
SEP #$30 ; AXY->8
LDA.B Layer1TileDown
LSR A
LSR A
LSR A
REP #$30 ; AXY->16
AND.W #$0006
TAX
LDA.W #$0133
ASL A
TAY
LDA.W #$0007
STA.B _0
LDA.L MAP16AppTable,X
- STA.W Map16Pointers,Y
INY
INY
CLC
ADC.W #$0008
DEC.B _0
BPL -
SEP #$20 ; A->8
INC.W LevelLoadObject
LDA.W LevelLoadObject
CMP.B #$20
BNE CODE_0580BD
LDA.W ThroughMain
STA.W HW_TM
STA.W HW_TMW
LDA.W ThroughSub
STA.W HW_TS
STA.W HW_TSW
REP #$20 ; A->16
LDA.W #$FFFF
STA.B Layer1PrevTileUp
STA.B Layer1PrevTileDown
STA.B Layer2PrevTileUp
STA.B Layer2PrevTileDown
PLP
RTL
CODE_058126:
PHP
REP #$30 ; AXY->16
LDY.W #$0000
STY.B _3
STY.B _5
SEP #$30 ; AXY->8
LDA.B #$7E
STA.B _F
CODE_058136:
SEP #$20 ; A->8
REP #$10 ; XY->16
LDY.B _3
LDA.B [Layer2DataPtr],Y
STA.B _7
INY
REP #$20 ; A->16
STY.B _3
SEP #$20 ; A->8
AND.B #$80
BEQ CODE_05816A
LDA.B _7
AND.B #$7F
STA.B _7
LDA.B [Layer2DataPtr],Y
INY
REP #$20 ; A->16
STY.B _3
LDY.B _5
- SEP #$20 ; A->8
STA.B [_D],Y
INY
DEC.B _7
BPL -
REP #$20 ; A->16
STY.B _5
JMP CODE_058188
CODE_05816A:
REP #$20 ; A->16
LDY.B _3
SEP #$20 ; A->8
LDA.B [Layer2DataPtr],Y
INY
REP #$20 ; A->16
STY.B _3
LDY.B _5
SEP #$20 ; A->8
STA.B [_D],Y
REP #$20 ; A->16
INY
STY.B _5
SEP #$20 ; A->8
DEC.B _7
BPL CODE_05816A
CODE_058188:
REP #$20 ; A->16
LDY.B _3
SEP #$20 ; A->8
LDA.B [Layer2DataPtr],Y
CMP.B #$FF
BNE CODE_058136
INY
LDA.B [Layer2DataPtr],Y
CMP.B #$FF
BNE CODE_058136
REP #$20 ; A->16
LDA.W #Map16BGTiles
STA.B _0
LDX.W #$0000
- LDA.B _0
STA.W Map16Pointers,X
LDA.B _0
CLC
ADC.W #$0008
STA.B _0
INX
INX
CPX.W #$0400
BNE -
PLP
RTS
DATA_0581BB:
db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
db $FF,$FF,$FF,$FF,$FF,$FF,$E0,$00
db $00,$00,$00,$00,$00,$00,$00,$00
db $00,$00,$00,$00,$00,$00,$00,$00
db $FE,$00,$7F,$FF,$FF,$FF,$FF,$FF
db $FF,$FF,$E0,$00,$00,$03,$FF,$FF
db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
CODE_0581FB:
SEP #$30 ; AXY->8
LDA.W ObjectTileset ; \
ASL A ; |Store tileset*2 in X
TAX ; /
LDA.B #DATA_0581BB>>16 ; \Store x05 in $0F
STA.B _F ; /
LDA.B #DATA_00E55E>>16 ; \Store x00 in $84
STA.B SlopesPtr+2 ; /
LDA.B #$C4 ; \Store xC4 in $1430
STA.W SolidTileStart ; /
LDA.B #$CA ; \Store xCA in $1431
STA.W SolidTileEnd ; /
REP #$20 ; A->16
LDA.W #DATA_00E55E ; \Store xE55E in $82-$83
STA.B SlopesPtr ; /
LDA.L TilesetMAP16Loc,X ; \Store address to MAP16 data in $00-$01
STA.B _0 ; /
LDA.W #Map16Common ; \Store x8000 in $02-$03
STA.B _2 ; /
LDA.W #DATA_0581BB ; \Store x81BB in $0D-$0E
STA.B _D ; /
STZ.B _4 ; \
STZ.B _9 ; |Store x00 in $04, $09 and $0B
STZ.B _B ; /
REP #$10 ; XY->16
LDY.W #$0000 ; \Set X and Y to x0000
TYX ; /
CODE_058237:
SEP #$20 ; A->8
LDA.B [_D],Y
STA.B _C
CODE_05823D:
ASL.B _C
BCC +
REP #$20 ; A->16
LDA.B _2
STA.W Map16Pointers,X
LDA.B _2
CLC
ADC.W #$0008
STA.B _2
JMP CODE_058262
+ REP #$20 ; A->16
LDA.B _0
STA.W Map16Pointers,X
LDA.B _0
CLC
ADC.W #$0008
STA.B _0
CODE_058262:
SEP #$20 ; A->8
INX
INX
INC.B _9
INC.B _B
LDA.B _B
CMP.B #$08
BNE CODE_05823D
STZ.B _B
INY
CPY.W #$0040
BNE CODE_058237
LDA.W ObjectTileset
BEQ CODE_058281
CMP.B #$07
BNE CODE_0582C5
CODE_058281:
LDA.B #$FF
STA.W SolidTileStart
STA.W SolidTileEnd
REP #$30 ; AXY->16
LDA.W #DATA_00E5C8
STA.B SlopesPtr
LDA.W #$01C4
ASL A
TAY
LDA.W #$8A70
STA.B _0
LDX.W #$0003
- LDA.B _0
STA.W Map16Pointers,Y
CLC
ADC.W #$0008
STA.B _0
INY
INY
DEX
BPL -
LDA.W #$01EC
ASL A
TAY
LDX.W #$0003
- LDA.B _0
STA.W Map16Pointers,Y
CLC
ADC.W #$0008
STA.B _0
INY
INY
DEX
BPL -
CODE_0582C5:
SEP #$30 ; AXY->8
RTS
CODE_0582C8:
STA.L Map16TilesLow,X
STA.L Map16TilesLow+$200,X
STA.L Map16TilesLow+$400,X
STA.L Map16TilesLow+$600,X
STA.L Map16TilesLow+$800,X
STA.L Map16TilesLow+$A00,X
STA.L Map16TilesLow+$C00,X
STA.L Map16TilesLow+$E00,X
STA.L Map16TilesLow+$1000,X
STA.L Map16TilesLow+$1200,X
STA.L Map16TilesLow+$1400,X
STA.L Map16TilesLow+$1600,X
STA.L Map16TilesLow+$1800,X
STA.L Map16TilesLow+$1A00,X
STA.L Map16TilesLow+$1C00,X
STA.L Map16TilesLow+$1E00,X
STA.L Map16TilesLow+$2000,X
STA.L Map16TilesLow+$2200,X
STA.L Map16TilesLow+$2400,X
STA.L Map16TilesLow+$2600,X
STA.L Map16TilesLow+$2800,X
STA.L Map16TilesLow+$2A00,X
STA.L Map16TilesLow+$2C00,X
STA.L Map16TilesLow+$2E00,X
STA.L Map16TilesLow+$3000,X
STA.L Map16TilesLow+$3200,X
STA.L Map16TilesLow+$3400,X
STA.L Map16TilesLow+$3600,X
INX
RTS
CODE_05833A:
STA.L Map16TilesHigh,X
STA.L Map16TilesHigh+$200,X
STA.L Map16TilesHigh+$400,X
STA.L Map16TilesHigh+$600,X
STA.L Map16TilesHigh+$800,X
STA.L Map16TilesHigh+$A00,X
STA.L Map16TilesHigh+$C00,X
STA.L Map16TilesHigh+$E00,X
STA.L Map16TilesHigh+$1000,X
STA.L Map16TilesHigh+$1200,X
STA.L Map16TilesHigh+$1400,X
STA.L Map16TilesHigh+$1600,X
STA.L Map16TilesHigh+$1800,X
STA.L Map16TilesHigh+$1A00,X
STA.L Map16TilesHigh+$1C00,X
STA.L Map16TilesHigh+$1E00,X
STA.L Map16TilesHigh+$2000,X
STA.L Map16TilesHigh+$2200,X
STA.L Map16TilesHigh+$2400,X
STA.L Map16TilesHigh+$2600,X
STA.L Map16TilesHigh+$2800,X
STA.L Map16TilesHigh+$2A00,X
STA.L Map16TilesHigh+$2C00,X
STA.L Map16TilesHigh+$2E00,X
STA.L Map16TilesHigh+$3000,X
STA.L Map16TilesHigh+$3200,X
STA.L Map16TilesHigh+$3400,X
STA.L Map16TilesHigh+$3600,X
INX
RTS
LoadLevel:
PHP
SEP #$30 ; AXY->8
STZ.W LayerProcessing ; Layer number (0=Layer 1, 1=Layer 2)
JSR CODE_0584E3 ; Loads level header
JSR CODE_0581FB
LoadAgain:
LDA.W LevelModeSetting ; Get current level mode
CMP.B #$09 ; \
BEQ LoadLevelDone ; |
CMP.B #$0B ; |If the current level is a boss level,
BEQ LoadLevelDone ; |don't load anything else.
CMP.B #$10 ; |
BEQ LoadLevelDone ; /
LDY.B #$00 ; \
LDA.B [Layer1DataPtr],Y ; |
CMP.B #$FF ; |If level isn't empty, load the level.
BEQ + ; |
JSR LoadLevelData ; /
+ SEP #$30 ; AXY->8
LDA.W LevelModeSetting ; Get current level mode
BEQ LoadLevelDone ; \
CMP.B #$0A ; |
BEQ LoadLevelDone ; |
CMP.B #$0C ; |
BEQ LoadLevelDone ; |If the current level isn't a Layer 2 level,
CMP.B #$0D ; |branch to LoadLevelDone
BEQ LoadLevelDone ; |
CMP.B #$0E ; |
BEQ LoadLevelDone ; |
CMP.B #$11 ; |
BEQ LoadLevelDone ; |
CMP.B #$1E ; |
BEQ LoadLevelDone ; /
INC.W LayerProcessing ; \Increase layer number and load into A
LDA.W LayerProcessing ; /
CMP.B #$02 ; \If it is x02, end. (Layer 1 and 2 are done)
BEQ LoadLevelDone ; /
LDA.B Layer2DataPtr ; \
CLC ; |
ADC.B #$05 ; |
STA.B Layer1DataPtr ; |Move address stored in $68-$6A to $65-$67.
LDA.B Layer2DataPtr+1 ; |(Move Layer 2 address to "Level to load" address)
ADC.B #$00 ; |It also increases the address by 5 (to ignore Layer 2's header)
STA.B Layer1DataPtr+1 ; |
LDA.B Layer2DataPtr+2 ; |
STA.B Layer1DataPtr+2 ; /
STZ.W LevelLoadObject
JMP LoadAgain
LoadLevelDone:
STZ.W LayerProcessing
PLP
RTS
VerticalTable:
db $00,$00,$80,$01,$81,$02,$82,$03 ; Vertical level settings for each level mode ; Format:
db $83,$00,$01,$00,$00,$01,$00,$00 ; ?uuuuu?v
db $00,$00,$00,$00,$00,$00,$00,$00 ; ?= Unknown purpose ; u= Unused?
db $00,$00,$00,$00,$00,$00,$00,$80 ; v= Vertical level
LevMainScrnTbl:
db $15,$15,$17,$15,$15,$15,$17,$15 ; Main screen settings for each level mode
db $17,$15,$15,$15,$15,$15,$04,$04
db $15,$17,$15,$15,$15,$15,$15,$15
db $15,$15,$15,$15,$15,$15,$01,$02
LevSubScrnTbl:
db $02,$02,$00,$02,$02,$02,$00,$02 ; Subscreen settings for each level mode
db $00,$00,$02,$00,$02,$02,$13,$13
db $00,$00,$02,$02,$02,$02,$02,$02
db $02,$02,$02,$02,$02,$02,$16,$15
LevCGADSUBtable:
db $24,$24,$24,$24,$24,$24,$20,$24 ; CGADSUB settings for each level mode
db $24,$20,$24,$20,$70,$70,$24,$24
db $20,$FF,$24,$24,$24,$24,$24,$24
db $24,$24,$24,$24,$24,$24,$21,$22
SpecialLevTable:
db $00,$00,$00,$00,$00,$00,$00,$00 ; Special level settings for each level mode ; 00: Normal level
db $00,$C0,$00,$80,$00,$00,$00,$00 ; 80: Iggy/Larry level ; C0: Morton/Ludwig/Roy level
db $C1,$00,$00,$00,$00,$00,$00,$00 ; C1: Bowser level
db $00,$00,$00,$00,$00,$00,$00,$00
LevXYPPCCCTtbl:
db $20,$20,$20,$30,$30,$30,$30,$30 ; XYPPCCCT settings for each level mode ; (The XYPPCCCT setting appears to be XORed with nearly all
db $30,$30,$30,$30,$30,$30,$20,$20 ; sprites' XYPPCCCT settings)
db $30,$30,$30,$30,$30,$30,$30,$30
db $30,$30,$30,$30,$30,$30,$30,$30
TimerTable:
db $00,$02,$03,$04
LevelMusicTable:
db !BGM_OVERWORLD ; A level can choose between 8 tracks. ; This table contains the tracks to choose from.
db !BGM_UNDERGROUND
db !BGM_ATHLETIC
db !BGM_CASTLE
db !BGM_GHOSTHOUSE
db !BGM_UNDERWATER
db !BGM_BOSSFIGHT
db !BGM_BONUSGAME
CODE_0584E3:
LDY.B #$00
LDA.B [Layer1DataPtr],Y ; Get first byte
TAX ; \
AND.B #$1F ; |Get amount of screens
INC A ; |
STA.B LevelScrLength ; /
TXA ; \
LSR A ; |
LSR A ; |
LSR A ; |Get BG color setting
LSR A ; |
LSR A ; |
STA.W BackgroundPalette ; /
INY ; \Get second byte
LDA.B [Layer1DataPtr],Y ; /
AND.B #$1F ; \Get level mode
STA.W LevelModeSetting ; /
TAX
LDA.L LevXYPPCCCTtbl,X ; \Get XYPPCCCT settings from table
STA.B SpriteProperties ; /
LDA.L LevMainScrnTbl,X ; \Get main screen setting from table
STA.W ThroughMain ; /
LDA.L LevSubScrnTbl,X ; \Get subscreen setting from table
STA.W ThroughSub ; /
LDA.L LevCGADSUBtable,X ; \Get CGADSUB settings from table
STA.B ColorSettings ; /
LDA.L SpecialLevTable,X ; \Get special level setting from table
STA.W IRQNMICommand ; /
LDA.L VerticalTable,X ; \Get vertical level setting from table
STA.B ScreenMode ; /
LSR A ; \
LDA.B LevelScrLength ; |
LDX.B #$01 ; |If level mode is even:
BCC + ; |Store screen amount in $5E and x01 in $5F
TAX ; |Otherwise:
LDA.B #$01 ; |Store x01 in $5E and screen amount in $5F
+ STA.B LastScreenHoriz ; |
STX.B LastScreenVert ; /
LDA.B [Layer1DataPtr],Y ; Reload second byte
LSR A ; \
LSR A ; |
LSR A ; |Get BG color settings
LSR A ; |
LSR A ; |
STA.W BackAreaColor ; /
INY ; \Get third byte
LDA.B [Layer1DataPtr],Y ; /
STA.B _0 ; "Push" third byte
TAX ; "Push" third byte
AND.B #$0F ; \Load sprite set
STA.W SpriteTileset ; /
TXA ; "Pull" third byte
LSR A ; \
LSR A ; |
LSR A ; |
LSR A ; |
AND.B #$07 ; |
TAX ; |Get music
LDA.L LevelMusicTable,X ; |
LDX.W MusicBackup ; | \
BPL + ; | |
ORA.B #$80 ; | |Related to not restarting music if the new track
+ CMP.W MusicBackup ; | |is the same as the old one?
BNE + ; | |
ORA.B #$40 ; | /
+ STA.W MusicBackup ; /
LDA.B _0 ; "Pull" third byte
AND.B #$80 ; \
LSR A ; |
LSR A ; |
LSR A ; |Get Layer 3 priority
LSR A ; |
ORA.B #$01 ; |
STA.B MainBGMode ; /
INY ; \Get fourth bit
LDA.B [Layer1DataPtr],Y ; /
STA.B _0 ; "Push" fourth bit
LSR A ; \
LSR A ; |
LSR A ; |
LSR A ; |
LSR A ; |
LSR A ; |
TAX ; |Get time
LDA.W SublevelCount ; |
BNE + ; |
LDA.L TimerTable,X ; |
STA.W InGameTimerHundreds ; |
STZ.W InGameTimerTens ; |
STZ.W InGameTimerOnes ; /
+ LDA.B _0 ; "Pull" fourth bit
AND.B #$07 ; \Get FG color settings
STA.W ForegroundPalette ; /
LDA.B _0 ; "Pull" fourth bit (again)
AND.B #$38 ; \
LSR A ; |
LSR A ; |Get sprite palette
LSR A ; |
STA.W SpritePalette ; /
INY ; \Get fifth byte
LDA.B [Layer1DataPtr],Y ; /
AND.B #$0F ; \
STA.W ObjectTileset ; |Get tileset
STA.W Empty1932 ; /
LDA.B [Layer1DataPtr],Y ; Reload fifth byte
AND.B #$C0 ; \
ASL A ; |
ROL A ; |Get item memory settings
ROL A ; |
STA.W ItemMemorySetting ; /
LDA.B [Layer1DataPtr],Y ; Reload fifth byte
AND.B #$30 ; \
LSR A ; |Get horizontal/vertical scroll
LSR A ; |
LSR A ; |
LSR A ; |
CMP.B #$03 ; | \
BNE + ; | |If scroll mode is x03, disable both
STZ.W HorizLayer1Setting ; | |vertical and horizontal scroll
LDA.B #$00 ; | /
+ STA.W VertLayer1Setting ; /
LDA.B Layer1DataPtr ; \
CLC ; |
ADC.B #$05 ; |
STA.B Layer1DataPtr ; |Make $65 point at the level data
LDA.B Layer1DataPtr+1 ; |(Level data comes right after the header)
ADC.B #$00 ; |
STA.B Layer1DataPtr+1 ; /
RTS ; We're done!
CODE_0585D8:
LDA.B LvlLoadObjNo
BNE CODE_0585E2
LDA.B LvlLoadObjSize
CMP.B #$02
BCC +
CODE_0585E2:
LDA.B _A
AND.B #$0F
STA.B _0
LDA.B _B
AND.B #$0F
STA.B _1
LDA.B _A
AND.B #$F0
ORA.B _1
STA.B _A
LDA.B _B
AND.B #$F0
ORA.B _0
STA.B _B
+ RTS
LoadLevelData:
SEP #$30 ; AXY->8
LDY.B #$00 ; \
LDA.B [Layer1DataPtr],Y ; |
STA.B _A ; |
INY ; |
LDA.B [Layer1DataPtr],Y ; |Read three bytes of level data
STA.B _B ; |Store them in $0A, $0B and $59
INY ; |
LDA.B [Layer1DataPtr],Y ; |
STA.B LvlLoadObjSize ; |
INY ; /
TYA ; \
CLC ; |
ADC.B Layer1DataPtr ; |
STA.B Layer1DataPtr ; |Increase address by 3 (as 3 bytes were read)
LDA.B Layer1DataPtr+1 ; |
ADC.B #$00 ; |
STA.B Layer1DataPtr+1 ; /
LDA.B _B ; \
LSR A ; |
LSR A ; |
LSR A ; |
LSR A ; |
STA.B LvlLoadObjNo ; |Get block number, store in $5A
LDA.B _A ; |
AND.B #$60 ; |
LSR A ; |
ORA.B LvlLoadObjNo ; |
STA.B LvlLoadObjNo ; /
LDA.B ScreenMode ; A = vertical level setting
LDY.W LayerProcessing ; \
BEQ + ; |If $1933=x00, divide A by 2
LSR A ; /
+ AND.B #$01 ; \
BEQ + ; |If lowest bit of A is set, jump to sub
JSR CODE_0585D8 ; /
+ LDA.B _A ; \
AND.B #$0F ; |
ASL A ; |
ASL A ; |
ASL A ; |Set upper half of $57 to Y pos
ASL A ; |and lower half of $57 to X pos
STA.B LevelLoadPos ; |
LDA.B _B ; |
AND.B #$0F ; |
ORA.B LevelLoadPos ; |
STA.B LevelLoadPos ; /
REP #$20 ; A->16
LDA.W LayerProcessing ; \
AND.W #$00FF ; |Load $1993*2 into X
ASL A ; |
TAX ; /
LDA.L LoadBlkPtrs,X
STA.B _3
LDA.L LoadBlkTable2,X
STA.B _6
LDA.W LevelModeSetting ; \
AND.W #$001F ; |Set Y to Level Mode*2
ASL A ; |
TAY ; /
SEP #$20 ; A->8
LDA.B #$00
STA.B _5
STA.B _8
LDA.B [_3],Y
STA.B _0
LDA.B [_6],Y
STA.B _D
INY
LDA.B [_3],Y
STA.B _1
LDA.B [_6],Y
STA.B _E
LDA.B #$00
STA.B _2
STA.B _F
LDA.B _A ; \
AND.B #$80 ; |
ASL A ; |If New Page flag is set, increase $1928 by 1
ADC.W LevelLoadObject ; |(A = $1928)
STA.W LevelLoadObject ; /
STA.W LevelLoadObjectTile ; Store A in $1BA1
ASL A ; \
CLC ; |Multiply A by 2 and add $1928 to it
ADC.W LevelLoadObject ; |Set Y to A
TAY ; /
LDA.B [_0],Y
STA.B Map16LowPtr
LDA.B [_D],Y
STA.B Map16HighPtr
INY
LDA.B [_0],Y
STA.B Map16LowPtr+1
LDA.B [_D],Y
STA.B Map16HighPtr+1
INY
LDA.B [_0],Y
STA.B Map16LowPtr+2
LDA.B [_D],Y
STA.B Map16HighPtr+2
LDA.B _A ; \
AND.B #$10 ; |If high coordinate is set...
BEQ + ; |(Lower half of horizontal level)
INC.B Map16LowPtr+1 ; |(Right half of vertical level)
INC.B Map16HighPtr+1 ; |...increase $6C and $6F
+ LDA.B LvlLoadObjNo ; \
BNE + ; |If block number is x00 (extended object),
JSR LevLoadExtObj ; |Jump to sub LevLoadExtObj
JMP LevLoadContinue ; | (Why didn't they use BRA here?)
+ JSR LevLoadNrmObj ; |Jump to sub LevLoadNrmObj
LevLoadContinue:
SEP #$20 ; A->8
REP #$10 ; XY->16
LDY.W #$0000 ; \
LDA.B [Layer1DataPtr],Y ; |
CMP.B #$FF ; |If the next byte is xFF, return (loading is done).
BEQ + ; |Otherwise, repeat this routine.
JMP LoadLevelData ; |
+ RTS ; /
LevLoadExtObj:
SEP #$30 ; AXY->8
JSL CODE_0DA100
RTS
LevLoadNrmObj:
SEP #$30 ; AXY->8
JSL CODE_0DA40F
RTS
CODE_0586F1:
PHP
REP #$30 ; AXY->16
JSR CODE_05877E
SEP #$20 ; A->8
LDA.B ScreenMode
AND.B #!ScrMode_Layer1Vert
BNE CODE_058713
REP #$20 ; A->16
LDA.B Layer1ScrollDir
AND.W #$00FF
TAX
LDA.B Layer1XPos
AND.W #$FFF0
CMP.B Layer1PrevTileUp,X
BEQ +
JMP CODE_058724
CODE_058713:
REP #$20 ; A->16
LDA.B Layer1ScrollDir
AND.W #$00FF
TAX
LDA.B Layer1YPos
AND.W #$FFF0
CMP.B Layer1PrevTileUp,X
BEQ +
CODE_058724:
STA.B Layer1PrevTileUp,X
TXA
EOR.W #$0002
TAX
LDA.W #$FFFF
STA.B Layer1PrevTileUp,X
JSL CODE_05881A
JMP CODE_058774
+ SEP #$20 ; A->8
LDA.B ScreenMode
AND.B #!ScrMode_Layer2Vert
BNE CODE_058753
REP #$20 ; A->16
LDA.B Layer2ScrollDir
AND.W #$00FF
TAX
LDA.B Layer2XPos
AND.W #$FFF0
CMP.B Layer2PrevTileUp,X
BEQ CODE_058774
JMP CODE_058764
CODE_058753:
REP #$20 ; A->16
LDA.B Layer2ScrollDir
AND.W #$00FF
TAX
LDA.B Layer2YPos
AND.W #$FFF0
CMP.B Layer2PrevTileUp,X
BEQ CODE_058774
CODE_058764:
STA.B Layer2PrevTileUp,X
TXA
EOR.W #$0002
TAX
LDA.W #$FFFF
STA.B Layer2PrevTileUp,X
JSL CODE_058883
CODE_058774:
PLP
RTL
MAP16AppTable:
db $B0,$8A,$E0,$84,$F0,$8A,$30,$8B
CODE_05877E:
PHP
SEP #$20 ; A->8
LDA.B ScreenMode
AND.B #!ScrMode_Layer1Vert
BNE CODE_0587CB
REP #$20 ; A->16
LDA.B Layer1XPos ; Load "Xpos of Screen Boundary"
LSR A ; \
LSR A ; |Multiply by 16
LSR A ; |
LSR A ; /
TAY
SEC ; \
SBC.W #$0008 ; /Subtract 8
STA.B Layer1TileUp ; Store to $45 (Seems to be Scratch RAM)
TYA ; Get back the multiplied XPos
CLC
ADC.W #$0017 ; Add $17
STA.B Layer1TileDown ; Store to $47 (Seems to be Scratch RAM)
SEP #$30 ; AXY->8
LDA.B Layer1ScrollDir ; \
TAX ; | LDA $45,x / $55
LDA.B Layer1TileUp,X ; /
LSR A ; \ multiply by 8
LSR A ; |
LSR A ; /
REP #$30 ; AXY->16
AND.W #$0006 ; AND to make it either 6, 4, 2, or 0.
TAX
LDA.W #$0133 ; \LDY #$0266
ASL A ; |
TAY ; /
LDA.W #$0007
STA.B _0
LDA.L MAP16AppTable,X
- STA.W Map16Pointers,Y ; MAP16 pointer table
INY
INY
CLC
ADC.W #$0008 ; 8 bytes per tile?
DEC.B _0
BPL -
JMP CODE_0587E1
CODE_0587CB:
REP #$20 ; A->16
LDA.B Layer1YPos
LSR A
LSR A
LSR A
LSR A
TAY
SEC
SBC.W #$0008
STA.B Layer1TileUp
TYA
CLC
ADC.W #$0017
STA.B Layer1TileDown
CODE_0587E1:
SEP #$20 ; A->8
LDA.B ScreenMode ; Load the vertical level flag
AND.B #!ScrMode_Layer2Vert ; \if bit 1 is set, process based on that
BNE + ; /
REP #$20 ; A->16, Not a vertical level
LDA.B Layer2XPos ; \Y = L2XPos * 16
LSR A ; |
LSR A ; |
LSR A ; |
LSR A ; |
TAY ; /
SEC
SBC.W #$0008
STA.B Layer2TileUp
TYA
CLC
ADC.W #$0017
STA.B Layer2TileDown
JMP CODE_058818
+ REP #$20 ; \ A->16, A = Y = !4*16 (?)
LDA.B Layer2YPos ; |
LSR A ; |
LSR A ; |
LSR A ; |
LSR A ; |
TAY ; /
SEC ; \
SBC.W #$0008 ; |Subtract x08 and store in $49
STA.B Layer2TileUp ; /
TYA ; \
CLC ; |"Undo", add x17 and store in $4B
ADC.W #$0017 ; |
STA.B Layer2TileDown ; /
CODE_058818:
PLP
RTS
CODE_05881A:
SEP #$30 ; AXY->8
LDA.W LevelModeSetting
JSL ExecutePtrLong
dl CODE_0589CE
dl CODE_0589CE
dl CODE_0589CE
dl CODE_058A9B
dl CODE_058A9B
dl CODE_0589CE
dl CODE_0589CE
dl CODE_058A9B
dl CODE_058A9B
dl Return058A9A
dl CODE_058A9B