-
Notifications
You must be signed in to change notification settings - Fork 3
/
twoplayer-tetris-PRG.s.diff
1106 lines (1074 loc) · 34.2 KB
/
twoplayer-tetris-PRG.s.diff
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
--- orig
+++ mod
@@ -1,11 +1,11 @@
; Input file: build/tetris-PRG.bin
; Page: 1
.setcpu "6502"
-
+.include "../twoplayer.inc"
tmp1 := $0000
tmp2 := $0001
tmp3 := $0002
tmpBulkCopyToPpuReturnAddr:= $0005
patchToPpuAddr := $0014
@@ -251,20 +251,20 @@ initRam:ldx #$00
nmi: pha
txa
pha
tya
pha
+ jsr render
+ jmp_ie copyOamStagingToOam_mod
lda #$00
sta oamStagingLength
- jsr render
dec sleepCounter
lda sleepCounter
cmp #$FF
bne @jumpOverIncrement
inc sleepCounter
@jumpOverIncrement:
- jsr copyOamStagingToOam
lda frameCounter
clc
adc #$01
sta frameCounter
lda #$00
@@ -447,21 +447,21 @@ gameModeState_updatePlayer2:
cmp #$02
bne @ret
jsr makePlayer2Active
jsr branchOnPlayStatePlayer2
jsr stageSpriteForCurrentPiece
- jsr savePlayer2State
+ jsr_i savePlayer2State_mod ;jsr savePlayer2State
@ret: inc gameModeState
rts
gameMode_playAndEndingHighScore:
lda gameModeState
jsr switchOnA
.addr gameModeState_initGameBackground
.addr gameModeState_initGameState
.addr gameModeState_updateCountersAndNonPlayerState
- .addr gameModeState_handleGameOver
+ addr_i gameModeState_handleGameOver_mod
.addr gameModeState_updatePlayer1
.addr gameModeState_updatePlayer2
.addr gameModeState_checkForResetKeyCombo
.addr gameModeState_startButtonHandling
.addr gameModeState_vblankThenRunState2
@@ -517,12 +517,12 @@ gameMode_legalScreen:
jsr changeCHRBank0
lda #$00
jsr changeCHRBank1
jsr bulkCopyToPpu
.addr legal_screen_palette
- jsr bulkCopyToPpu
- .addr legal_screen_nametable
+ jsr copyRleNametableToPpu ;jsr bulkCopyToPpu
+ .addr legal_screen_nametable_rle ;.addr legal_screen_nametable
jsr waitForVBlankAndEnableNmi
jsr updateAudioWaitForNmiAndResetOamStaging
jsr updateAudioWaitForNmiAndEnablePpuRendering
jsr updateAudioWaitForNmiAndResetOamStaging
lda #$00
@@ -763,18 +763,18 @@ gameMode_levelMenu:
jsr changeCHRBank0
lda #$00
jsr changeCHRBank1
jsr bulkCopyToPpu
.addr menu_palette
- jsr bulkCopyToPpu
- .addr level_menu_nametable
+ jsr_i gameMode_levelMenu_nametable_mod ;jsr bulkCopyToPpu
+ nop_rep 2 ;.addr level_menu_nametable
lda gameType
bne @skipTypeBHeightDisplay
jsr bulkCopyToPpu
.addr height_menu_nametablepalette_patch
@skipTypeBHeightDisplay:
- jsr showHighScores
+ jsr showHighScores_real ;jsr showHighScores
jsr waitForVBlankAndEnableNmi
jsr updateAudioWaitForNmiAndResetOamStaging
lda #$00
sta PPUSCROLL
lda #$00
@@ -824,12 +824,12 @@ gameMode_levelMenu_processPlayer1Navigat
@startAndANotPressed:
lda #$00
sta gameModeState
lda #$02
sta soundEffectSlot1Init
- inc gameMode
- rts
+ jmp_i gameMode_levelMenu_processPlayer2Navigation ;inc gameMode
+ ;rts
@checkBPressed:
lda newlyPressedButtons_player1
cmp #$40
bne @chooseRandomHole_player1
@@ -842,23 +842,23 @@ @chooseRandomHole_player1:
ldx #$17
ldy #$02
jsr generateNextPseudorandomNumber
lda rng_seed
and #$0F
- cmp #$0A
+ cmp #$09 ;#$0A
bpl @chooseRandomHole_player1
sta player1_garbageHole
@chooseRandomHole_player2:
ldx #$17
ldy #$02
jsr generateNextPseudorandomNumber
lda rng_seed
and #$0F
- cmp #$0A
+ cmp #$09 ;#$0A
bpl @chooseRandomHole_player2
sta player2_garbageHole
- jsr updateAudioWaitForNmiAndResetOamStaging
+ jmp_i gameMode_levelMenu_processPlayer1Navigation_processPlayer2 ;jsr updateAudioWaitForNmiAndResetOamStaging
jmp gameMode_levelMenu_processPlayer1Navigation
; Starts by checking if right pressed
gameMode_levelMenu_handleLevelHeightNavigation:
lda newlyPressedButtons
@@ -1036,12 +1036,12 @@ gameModeState_initGameBackground:
jsr changeCHRBank0
lda #$03
jsr changeCHRBank1
jsr bulkCopyToPpu
.addr game_palette
- jsr bulkCopyToPpu
- .addr game_nametable
+ jmp_ie initGameBackground_mod ;jsr bulkCopyToPpu
+ nop_rep 2 ;.addr game_nametable
lda #$20
sta PPUADDR
lda #$83
sta PPUADDR
lda gameType
@@ -1123,12 +1123,12 @@ game_typeb_nametable_patch:
.byte $FE,$23,$57,$3D,$3E,$3E,$3E,$3E
.byte $3E,$3E,$3F,$FD
gameModeState_initGameState:
lda #$EF
ldx #$04
- ldy #$04
- jsr memset_page
+ ldy #$05 ;ldy #$04
+ jmp_ie initGameState_mod ;jsr memset_page
ldx #$0F
lda #$00
; statsByType
@initStatsByType:
sta $03EF,x
@@ -1175,12 +1175,12 @@ @initStatsByType:
sta player1_autorepeatY
sta player2_autorepeatY
jsr chooseNextTetrimino
sta player1_currentPiece
sta player2_currentPiece
- jsr incrementPieceStat
- ldx #$17
+ jsr_i incrementPieceStat_mod
+ ldx #personal_rng ;ldx #$17
ldy #$02
jsr generateNextPseudorandomNumber
jsr chooseNextTetrimino
sta nextPiece
sta twoPlayerPieceDelayPiece
@@ -1374,15 +1374,15 @@ gameModeState_updateCountersAndNonPlayer
inc player2_fallTimer
lda twoPlayerPieceDelayCounter
beq @checkSelectButtonPressed
inc twoPlayerPieceDelayCounter
@checkSelectButtonPressed:
- lda newlyPressedButtons_player1
- and #$20
+ jsr_i gameModeState_updateCountersAndNonPlayerState_mod ;lda newlyPressedButtons_player1
+ nop ;and #$20
beq @ret
lda displayNextPiece
- eor #$01
+ eor #$03 ;eor #$01
sta displayNextPiece
@ret: inc gameModeState
rts
rotate_tetrimino:
@@ -1569,17 +1569,17 @@ stageSpriteForCurrentPiece:
lda numberOfPlayers
cmp #$01
beq @calcYPos
lda generalCounter3
sec
- sbc #$40
+ sbc #$50 ;sbc #$40
sta generalCounter3
lda activePlayer
cmp #$01
beq @calcYPos
lda generalCounter3
- adc #$6F
+ adc #$8F ;adc #$6F
sta generalCounter3
; generalCounter4=tetrimino y pos
@calcYPos:
clc
lda tetriminoY
@@ -1717,12 +1717,12 @@ L8B9D: lda orientationTable,y
bne L8B9D
stx oamStagingLength
rts
stageSpriteForNextPiece:
- lda displayNextPiece
- bne @ret
+ jmp_i stageSpriteForNextPiece_player1_mod ;lda displayNextPiece
+ nop ;bne @ret
lda #$C8
sta spriteXOffset
lda #$77
sta spriteYOffset
ldx nextPiece
@@ -1899,28 +1899,53 @@ sprite03PausePalette6:
sprite05PausePalette4:
.byte $00,$19,$00,$00,$00,$0A,$00,$08
.byte $00,$1E,$00,$10,$00,$1C,$00,$18
.byte $00,$0E,$00,$20,$FF
sprite06TPiece:
+.ifndef NEXT_ON_TOP
.byte $00,$7B,$02,$FC,$00,$7B,$02,$04
.byte $00,$7B,$02,$0C,$08,$7B,$02,$04
+.else
+ .byte $00,$7B,$02,$00,$00,$7B,$02,$08
+ .byte $00,$7B,$02,$10,$08,$7B,$02,$08
+.endif
.byte $FF
sprite07SPiece:
+.ifndef NEXT_ON_TOP
.byte $00,$7D,$02,$04,$00,$7D,$02,$0C
.byte $08,$7D,$02,$FC,$08,$7D,$02,$04
+.else
+ .byte $00,$7D,$02,$08,$00,$7D,$02,$10
+ .byte $08,$7D,$02,$00,$08,$7D,$02,$08
+.endif
.byte $FF
sprite08ZPiece:
+.ifndef NEXT_ON_TOP
.byte $00,$7C,$02,$FC,$00,$7C,$02,$04
.byte $08,$7C,$02,$04,$08,$7C,$02,$0C
+.else
+ .byte $00,$7C,$02,$00,$00,$7C,$02,$08
+ .byte $08,$7C,$02,$08,$08,$7C,$02,$10
+.endif
.byte $FF
sprite09JPiece:
+.ifndef NEXT_ON_TOP
.byte $00,$7D,$02,$FC,$00,$7D,$02,$04
.byte $00,$7D,$02,$0C,$08,$7D,$02,$0C
+.else
+ .byte $00,$7D,$02,$00,$00,$7D,$02,$08
+ .byte $00,$7D,$02,$10,$08,$7D,$02,$10
+.endif
.byte $FF
sprite0ALPiece:
+.ifndef NEXT_ON_TOP
.byte $00,$7C,$02,$FC,$00,$7C,$02,$04
.byte $00,$7C,$02,$0C,$08,$7C,$02,$FC
+.else
+ .byte $00,$7C,$02,$00,$00,$7C,$02,$08
+ .byte $00,$7C,$02,$10,$08,$7C,$02,$00
+.endif
.byte $FF
sprite0BOPiece:
.byte $00,$7B,$02,$00,$00,$7B,$02,$08
.byte $08,$7B,$02,$00,$08,$7B,$02,$08
.byte $FF
@@ -2369,20 +2394,40 @@ render_mode_play_and_demo:
lda #$00
sta player1_vramRow
jmp @renderPlayer2Playfield
@playStateNotDisplayLineClearingAnimation:
+; 0 for original. 1 for fast. 2 for fast row4
+.define FASTROWTOVRAM 2
+.if FASTROWTOVRAM <> 2
lda player1_vramRow
sta vramRow
lda #$04
sta playfieldAddr+1
+.if FASTROWTOVRAM = 0
jsr copyPlayfieldRowToVRAM
jsr copyPlayfieldRowToVRAM
jsr copyPlayfieldRowToVRAM
jsr copyPlayfieldRowToVRAM
+.else
+ .import copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+.endif
lda vramRow
sta player1_vramRow
+.else
+ ldx player1_vramRow
+ lda #$00
+ .import copyPlayfieldRowToVRAM4
+ jsr copyPlayfieldRowToVRAM4
+ stx player1_vramRow
+ jmp @renderPlayer2Playfield
+ nop_rep 12
+.endif
@renderPlayer2Playfield:
lda numberOfPlayers
cmp #$02
bne @renderLines
lda player2_playState
@@ -2410,20 +2455,36 @@ @renderPlayer2Playfield:
lda #$00
sta player2_vramRow
jmp @renderLines
@player2PlayStateNotDisplayLineClearingAnimation:
+.if FASTROWTOVRAM <> 2
lda player2_vramRow
sta vramRow
lda #$05
sta playfieldAddr+1
+.if FASTROWTOVRAM = 0
jsr copyPlayfieldRowToVRAM
jsr copyPlayfieldRowToVRAM
jsr copyPlayfieldRowToVRAM
jsr copyPlayfieldRowToVRAM
+.else
+ jsr copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+ jsr copyPlayfieldRowToVRAM_fast
+.endif
lda vramRow
sta player2_vramRow
+.else
+ ldx player2_vramRow
+ lda #$01
+ jsr copyPlayfieldRowToVRAM4
+ stx player2_vramRow
+ jmp @renderLines
+ nop_rep 12
+.endif
@renderLines:
lda outOfDateRenderFlags
and #$01
beq @renderLevel
lda numberOfPlayers
@@ -2441,36 +2502,36 @@ @renderLines:
and #$FE
sta outOfDateRenderFlags
jmp @renderLevel
@renderLinesTwoPlayers:
- lda #$20
+ lda #>INGAME_LAYOUT_P1_LINES ;lda #$20
sta PPUADDR
- lda #$68
+ lda #<INGAME_LAYOUT_P1_LINES ;lda #$68
sta PPUADDR
lda player1_lines+1
sta PPUDATA
lda player1_lines
jsr twoDigsToPPU
- lda #$20
+ lda #>INGAME_LAYOUT_P2_LINES ;lda #$20
sta PPUADDR
- lda #$7A
+ lda #<INGAME_LAYOUT_P2_LINES ;lda #$7A
sta PPUADDR
lda player2_lines+1
sta PPUDATA
lda player2_lines
jsr twoDigsToPPU
lda outOfDateRenderFlags
and #$FE
sta outOfDateRenderFlags
@renderLevel:
- lda outOfDateRenderFlags
- and #$02
- beq @renderScore
lda numberOfPlayers
cmp #$02
beq @renderScore
+ lda outOfDateRenderFlags
+ and #$02
+ beq @renderScore
ldx player1_levelNumber
lda levelDisplayTable,x
sta generalCounter
lda #$22
sta PPUADDR
@@ -2481,12 +2542,13 @@ @renderLevel:
jsr updatePaletteForLevel
lda outOfDateRenderFlags
and #$FD
sta outOfDateRenderFlags
@renderScore:
- lda numberOfPlayers
- cmp #$02
+ jmp_i renderPlay_mod ;lda numberOfPlayers
+ nop ;cmp #$02
+.export after_renderPlay_mod := *
beq @renderStats
lda outOfDateRenderFlags
and #$04
beq @renderStats
lda #$21
@@ -2534,13 +2596,14 @@ @renderTetrisFlashAndSound:
lda #$3F
sta PPUADDR
lda #$0E
sta PPUADDR
ldx #$00
- lda completedLines
- cmp #$04
- bne @setPaletteColor
+ lda player1_completedLines
+ ora player2_completedLines
+ and #$04
+ beq @setPaletteColor
lda frameCounter
and #$03
bne @setPaletteColor
ldx #$30
lda frameCounter
@@ -2549,16 +2612,17 @@ @renderTetrisFlashAndSound:
lda #$09
sta soundEffectSlot1Init
@setPaletteColor:
stx PPUDATA
ldy #$00
- sty ppuScrollX
+ ;sty ppuScrollX
sty PPUSCROLL
- ldy #$00
- sty ppuScrollY
+ ;ldy #$00
+ ;sty ppuScrollY
sty PPUSCROLL
rts
+ nop_rep 4
pieceToPpuStatAddr:
.dbyt $2186,$21C6,$2206,$2246
.dbyt $2286,$22C6,$2306
levelDisplayTable:
@@ -2569,63 +2633,72 @@ levelDisplayTable:
multBy10Table:
.byte $00,$0A,$14,$1E,$28,$32,$3C,$46
.byte $50,$5A,$64,$6E,$78,$82,$8C,$96
.byte $A0,$AA,$B4,$BE
; addresses
-vramPlayfieldRows:
- .word $20C6,$20E6,$2106,$2126
- .word $2146,$2166,$2186,$21A6
- .word $21C6,$21E6,$2206,$2226
- .word $2246,$2266,$2286,$22A6
- .word $22C6,$22E6,$2306,$2326
+vramPlayfieldRowsHi:
+ .export vramPlayfieldRowsHi
+ .byte >$20C6,>$20E6,>$2106,>$2126
+ .byte >$2146,>$2166,>$2186,>$21A6
+ .byte >$21C6,>$21E6,>$2206,>$2226
+ .byte >$2246,>$2266,>$2286,>$22A6
+ .byte >$22C6,>$22E6,>$2306,>$2326
+vramPlayfieldRowsLo:
+ .export vramPlayfieldRowsLo
+ .byte <$20C6,<$20E6,<$2106,<$2126
+ .byte <$2146,<$2166,<$2186,<$21A6
+ .byte <$21C6,<$21E6,<$2206,<$2226
+ .byte <$2246,<$2266,<$2286,<$22A6
+ .byte <$22C6,<$22E6,<$2306,<$2326
twoDigsToPPU:
- sta generalCounter
+ tax ;sta generalCounter
and #$F0
lsr a
lsr a
lsr a
lsr a
sta PPUDATA
- lda generalCounter
+ txa ;lda generalCounter
and #$0F
sta PPUDATA
rts
+ nop_rep 2
copyPlayfieldRowToVRAM:
ldx vramRow
cpx #$15
bpl @ret
lda multBy10Table,x
tay
- txa
- asl a
- tax
- inx
- lda vramPlayfieldRows,x
+ nop ;txa
+ nop ;asl a
+ nop ;tax
+ nop ;inx
+ lda vramPlayfieldRowsHi,x
sta PPUADDR
- dex
+ nop ;dex
lda numberOfPlayers
cmp #$01
beq @onePlayer
lda playfieldAddr+1
cmp #$05
beq @playerTwo
- lda vramPlayfieldRows,x
+ lda vramPlayfieldRowsLo,x
sec
- sbc #$02
+ sbc #$04 ;sbc #$02
sta PPUADDR
jmp @copyRow
@playerTwo:
- lda vramPlayfieldRows,x
+ lda vramPlayfieldRowsLo,x
clc
- adc #$0C
+ adc #$0E ;adc #$0C
sta PPUADDR
jmp @copyRow
@onePlayer:
- lda vramPlayfieldRows,x
+ lda vramPlayfieldRowsLo,x
clc
adc #$06
sta PPUADDR
@copyRow:
ldx #$0A
@@ -2648,16 +2721,16 @@ updateLineClearingAnimation:
and #$03
bne @ret
lda #$00
sta generalCounter3
@whileCounter3LessThan4:
- ldx generalCounter3
- lda completedRow,x
+ ldx generalCounter3 ;lda completedRow,x
+ ldy completedRow,x
beq @nextRow
- asl a
- tay
- lda vramPlayfieldRows,y
+ nop ;asl a
+ nop ;tay
+ lda vramPlayfieldRowsLo,y
sta generalCounter
lda numberOfPlayers
cmp #$01
bne @twoPlayers
lda generalCounter
@@ -2670,22 +2743,22 @@ @twoPlayers:
lda playfieldAddr+1
cmp #$04
bne @player2
lda generalCounter
sec
- sbc #$02
+ sbc #$04 ;sbc #$02
sta generalCounter
jmp @updateVRAM
@player2:
lda generalCounter
clc
- adc #$0C
+ adc #$0E ;adc #$0C
sta generalCounter
@updateVRAM:
- iny
- lda vramPlayfieldRows,y
+ nop ;iny
+ lda vramPlayfieldRowsHi,y
sta generalCounter2
sta PPUADDR
ldx rowY
lda leftColumns,x
clc
@@ -2719,44 +2792,44 @@ leftColumns:
rightColumns:
.byte $05,$06,$07,$08,$09
; Set Background palette 2 and Sprite palette 2
updatePaletteForLevel:
lda player1_levelNumber
-@mod10: cmp #$0A
- bmi @copyPalettes
+ ldy #$08
+.export updatePaletteForLevel_postConf := *
sec
+@mod10:
sbc #$0A
- jmp @mod10
+ bcs @mod10
+ adc #$0A
@copyPalettes:
asl a
asl a
tax
- lda #$00
- sta generalCounter
@copyPalette:
lda #$3F
sta PPUADDR
- lda #$08
- clc
- adc generalCounter
- sta PPUADDR
+ sty PPUADDR
lda colorTable,x
sta PPUDATA
lda colorTable+1,x
sta PPUDATA
lda colorTable+1+1,x
sta PPUDATA
lda colorTable+1+1+1,x
sta PPUDATA
- lda generalCounter
+ tya
clc
adc #$10
- sta generalCounter
+ tay
cmp #$20
- bne @copyPalette
+ bmi @copyPalette
rts
+ nop_rep 12
+
+
; 4 bytes per level (bg, fg, c3, c4)
colorTable:
.dbyt $0F30,$2112,$0F30,$291A
.dbyt $0F30,$2414,$0F30,$2A12
@@ -2784,15 +2857,15 @@ @ret: rts
playState_spawnNextTetrimino:
lda vramRow
cmp #$20
bmi @ret
- lda numberOfPlayers
+ lda activePlayer ;lda numberOfPlayers
cmp #$01
- beq @spawnPiece
- lda twoPlayerPieceDelayCounter
- cmp #$00
+ beq @spawn1
+ ldx twoPlayerPieceDelayPiece;lda twoPlayerPieceDelayCounter
+ bne @spawnPiece; always jump;cmp #$00
bne @twoPlayerWaiting
inc twoPlayerPieceDelayCounter
lda activePlayer
sta twoPlayerPieceDelayPlayer
jsr chooseNextTetrimino
@@ -2804,29 +2877,29 @@ @twoPlayerWaiting:
cmp activePlayer
bne @ret
lda twoPlayerPieceDelayCounter
cmp #$1C
bne @ret
+@spawn1:ldx nextPiece
@spawnPiece:
lda #$00
sta twoPlayerPieceDelayCounter
sta fallTimer
sta tetriminoY
lda #$01
sta playState
lda #$05
sta tetriminoX
- ldx nextPiece
lda spawnOrientationFromOrientation,x
sta currentPiece
- jsr incrementPieceStat
- lda numberOfPlayers
+ jsr incrementPieceStat_mod
+ lda activePlayer ;lda numberOfPlayers
cmp #$01
beq @onePlayerPieceSelection
- lda twoPlayerPieceDelayPiece
- sta nextPiece
- jmp @resetDownHold
+ jsr chooseNextTetrimino ;lda twoPlayerPieceDelayPiece
+ sta twoPlayerPieceDelayPiece ;sta nextPiece
+ bne @resetDownHold ; always jump ;jmp @resetDownHold
@onePlayerPieceSelection:
jsr chooseNextTetrimino
sta nextPiece
@resetDownHold:
@@ -2835,13 +2908,13 @@ @resetDownHold:
@ret: rts
chooseNextTetrimino:
lda gameMode
cmp #$05
- bne pickRandomTetrimino
- ldx demoIndex
- inc demoIndex
+ jsr_i chooseNextTetrimino_mod ;bne pickRandomTetrimino
+ nop ;ldx demoIndex
+ nop_rep 2 ;inc demoIndex
lda demoTetriminoTypeTable,x
lsr a
lsr a
lsr a
lsr a
@@ -3045,12 +3118,12 @@ @checkForStartButton:
lda newlyPressedButtons_player1
cmp #$10
bne @ret2
@exitGame:
lda #$00
- sta playState
- sta newlyPressedButtons_player1
+ jsr_i playState_updateGameOverCurtain_curtainFinished_mod ;sta playState
+ nop ;sta newlyPressedButtons_player1
@ret2: rts
playState_checkForCompletedRows:
lda vramRow
cmp #$20
@@ -3123,11 +3196,11 @@ @incrementLineIndex:
bmi @ret
ldy completedLines
lda garbageLines,y
clc
adc pendingGarbageInactivePlayer
- sta pendingGarbageInactivePlayer
+ sta generalCounter ; Disable garbage ;sta pendingGarbageInactivePlayer
lda #$00
sta vramRow
sta rowY
lda completedLines
cmp #$04
@@ -3172,13 +3245,13 @@ @fillGarbage:
cpx garbageHole
beq @hole
lda #$78
jmp @set
-@hole: lda #$FF
-@set: sta (playfieldAddr),y
- inx
+@hole: lda #$EF
+@set: jsr_i playState_receiveGarbage_fillGarbage_mod ;sta (playfieldAddr),y
+ ;inx
cpx #$0A
bne @inc
ldx #$00
@inc: iny
cpy #$C8
@@ -3369,11 +3442,16 @@ @score2Low:
adc #$06
sta score+2
@score2High:
lda score+2
and #$F0
+.ifdef TOURNAMENT_MODE
+ ;this basically is no real fix, it just disables the check
+ cmp #$FF
+.else
cmp #$A0
+.endif
bcc @levelLoopCheck
lda #$99
sta score
sta score+1
sta score+2
@@ -3381,12 +3459,17 @@ @levelLoopCheck:
dec generalCounter
bne @levelLoop
lda outOfDateRenderFlags
ora #$04
sta outOfDateRenderFlags
+.ifdef TOURNAMENT_MODE
+ jsr_i statsPerLineClear_tournamentMode
+ nop
+.else
lda #$00
sta completedLines
+.endif
inc playState
rts
pointsTable:
.word $0000,$0040,$0100,$0300
@@ -3417,11 +3500,11 @@ gameModeState_handleGameOver:
sta generalCounter2
lda player2_playState
cmp #$00
bne @ret
@gameOver:
- lda numberOfPlayers
+ lda #$01 ;lda numberOfPlayers
cmp #$01
beq @onePlayerGameOver
lda #$09
sta gameModeState
rts
@@ -3466,23 +3549,23 @@ @checkForBlockInRow:
bne @foundBlockInRow
iny
dex
bne @checkForBlockInRow
lda allegro
- beq @ret
- lda #$00
- sta allegro
+ jsr_i updateMusicSpeed_noBlockInRow_mod ;beq @ret
+ bne @ret ;lda #$00
+ nop ;sta allegro
ldx musicType
lda musicSelectionTable,x
jsr setMusicTrack
jmp @ret
@foundBlockInRow:
lda allegro
- bne @ret
- lda #$FF
- sta allegro
+ jsr_i updateMusicSpeed_foundBlockInRow_mod ;bne @ret
+ bne @ret ;lda #$FF
+ nop ;sta allegro
lda musicType
clc
adc #$04
tax
lda musicSelectionTable,x
@@ -3498,15 +3581,15 @@ pollControllerButtons:
@demoGameMode:
lda demo_recording
cmp #$FF
beq @recording
- jsr pollController
+ jmp_i demo_pollController_mod ;jsr pollController
lda newlyPressedButtons_player1
- cmp #$10
+@demo_pollController_mod_after: cmp #$10
beq @startButtonPressed
- lda demo_repeats
+@demo_pollController_mod_skip: lda demo_repeats
beq @finishedMove
dec demo_repeats
jmp @moveInProgress
@finishedMove:
@@ -3953,11 +4036,11 @@ byteToBcdTable:
.byte $16,$17,$18,$19,$20,$21,$22,$23
.byte $24,$25,$26,$27,$28,$29,$30,$31
.byte $32,$33,$34,$35,$36,$37,$38,$39
.byte $40,$41,$42,$43,$44,$45,$46,$47
.byte $48,$49
-; Adjusts high score table and handles data entry, if necessary
+; Adjusts high score table and handles data entry, if necessary; x comes from gameModeState_handleGameOver_mod
handleHighScoreIfNecessary:
lda #$00
sta highScoreEntryRawPos
lda gameType
beq @compareWithPos
@@ -3969,26 +4052,26 @@ @compareWithPos:
asl a
clc
adc generalCounter2
tay
lda highScoreScoresA,y
- cmp player1_score+2
+ cmp player1_score+2,x
beq @checkHundredsByte
bcs @tooSmall
bcc adjustHighScores
@checkHundredsByte:
iny
lda highScoreScoresA,y
- cmp player1_score+1
+ cmp player1_score+1,x
beq @checkOnesByte
bcs @tooSmall
bcc adjustHighScores
; This breaks ties by prefering the new score
@checkOnesByte:
iny
lda highScoreScoresA,y
- cmp player1_score
+ cmp player1_score,x
beq adjustHighScores
bcc adjustHighScores
@tooSmall:
inc highScoreEntryRawPos
lda highScoreEntryRawPos
@@ -4031,22 +4114,22 @@ @clearNameLetter:
inx
dey
bne @clearNameLetter
ldx highScoreEntryRawPos
lda highScoreIndexToHighScoreScoresOffset,x
- tax
- lda player1_score+2
- sta highScoreScoresA,x
- inx
- lda player1_score+1
- sta highScoreScoresA,x
- inx
- lda player1_score
- sta highScoreScoresA,x
- ldx highScoreEntryRawPos
- lda player1_levelNumber
- sta highScoreLevels,x
+ tay ; swapped to y
+ ldx tmp3 ; player offset
+ lda player1_score+2,x
+ sta highScoreScoresA,y ; removed inx from next line
+ lda player1_score+1,x
+ sta highScoreScoresA+1,y
+ ;inx
+ lda player1_score,x
+ sta highScoreScoresA+2,y
+ ldy highScoreEntryRawPos
+ lda player1_levelNumber,x
+ sta highScoreLevels,y
jmp highScoreEntryScreen
; reg a: start byte to copy
copyHighScoreNameToNextIndex:
sta generalCounter
@@ -4140,14 +4223,14 @@ highScoreEntryScreen:
sta PPUADDR
lda #$0A
clc
adc gameType
sta PPUDATA
- jsr showHighScores
+ jsr showHighScores_real
lda #$02
sta renderMode
- jsr waitForVBlankAndEnableNmi
+ jsr_i highScoreEntryScreen_render ;jsr waitForVBlankAndEnableNmi
jsr updateAudioWaitForNmiAndResetOamStaging
jsr updateAudioWaitForNmiAndEnablePpuRendering
jsr updateAudioWaitForNmiAndResetOamStaging
lda highScoreEntryRawPos
asl a
@@ -4175,21 +4258,21 @@ @renderFrame:
lda frameCounter
and #$03
bne @flickerStateSelected_checkForStartPressed
lda #$02
sta spriteIndexInOamContentLookup
-@flickerStateSelected_checkForStartPressed:
- jsr loadSpriteIntoOamStaging
- lda newlyPressedButtons_player1
+@flickerStateSelected_checkForStartPressed:
+ jsr_i highScoreEntryScreen_get_player ;jsr loadSpriteIntoOamStaging
+ lda newlyPressedButtons_player1,x ; player id (0 or 1) was loaded into x
and #$10
beq @checkForAOrRightPressed
lda #$02
sta soundEffectSlot1Init
jmp @ret
@checkForAOrRightPressed:
- lda newlyPressedButtons_player1
+ lda newlyPressedButtons_player1,x