-
Notifications
You must be signed in to change notification settings - Fork 3
/
twoplayer.s
1516 lines (1360 loc) · 40 KB
/
twoplayer.s
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
;
; Two-player Tetris Mod
;
; Player 1 uses palette 2 and 6 (zero indexed) and Player 2 uses palette 1
; and 5. This keeps player 1 palettes the same as original Tetris.
; TODO:
; Save another RNG to let the behind player catch up.
; Allow toggling on garbage?
; Integrations:
; Any way to fit stats on screen? Seems like there's no room.
; No room for A/B-Type, high score
.include "build/tetris.inc"
.include "tetris-tbl.inc"
__TWOPLAYERSIMPORT = 1
.include "twoplayer.inc"
.ifdef TOURNAMENT_MODE
.include "tournament.romlayout.inc"
.endif
.exportzp personal_rng := $005C ; size 2
.exportzp spawnID_ := $005E
.exportzp spawnCount_ := $005F
.exportzp player1_rng := $007C ; size 2
.exportzp player1_spawnID_ := $007E
.exportzp player1_spawnCount_:= $007F
.exportzp player2_rng := $009C ; size 2
.exportzp player2_spawnID_ := $009E
.exportzp player2_spawnCount_:= $009F
.segment "CHR"
.incbin "build/tetris-CHR-00.chr"
.incbin "build/twoplayer-CHR-01.chr"
.bss
.segment "GAMEBSS"
; 0 for both players demo
demo_playingPlayer:
.res 1
demoIndex_player2:
.res 1
garbageUntilResetHole_P1:
.res 1
garbageUntilResetHole_P2:
.res 1
.ifdef TOURNAMENT_MODE
tetrisCount_P1:
.res 1
tetrisCount_P2:
.res 1
binaryLines_P1:
.res 1
binaryLines_P2:
.res 1
binaryLines_P1_HI:
.res 1
binaryLines_P2_HI:
.res 1
.endif
.code
; unreferenced_data1 padding to avoid colliding with
; TetrisControllerInputDisplay.
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
initGameState_mod:
.export initGameState_mod
.import __GAMEBSS_SIZE__, __GAMEBSS_RUN__
jsr memset_page
lda #$00
ldx #<__GAMEBSS_SIZE__
@clearByte:
sta __GAMEBSS_RUN__-1,x
dex
bne @clearByte
lda rng_seed
sta personal_rng
lda rng_seed+1
sta personal_rng+1
.import after_initGameState_mod
jsr after_initGameState_mod
lda personal_rng
sta player1_rng
sta player2_rng
lda personal_rng+1
sta player1_rng+1
sta player2_rng+1
lda spawnID_
sta player1_spawnID_
sta player2_spawnID_
lda spawnCount_
sta player1_spawnCount_
sta player2_spawnCount_
lda #$0A
sta garbageUntilResetHole_P1
sta garbageUntilResetHole_P2
rts
initGameBackground_mod:
.export initGameBackground_mod
lda numberOfPlayers
cmp #$01
bne @twoPlayers
jsr bulkCopyToPpu
.addr game_nametable
.import after_initGameBackground_mod
jmp after_initGameBackground_mod
@twoPlayers:
jsr copyRleNametableToPpu
.addr twoplayer_game_nametable
jmp gameModeState_initGameBackground_finish
twoplayer_game_nametable:
.ifdef TOURNAMENT_MODE
.incbin "build/tournament.nam.rle"
.elseif .defined(NEXT_ON_TOP)
.incbin "build/twoplayer_game_top.nam.rle"
.else
.incbin "build/twoplayer_game.nam.rle"
.endif
copyRleNametableToPpu:
.export copyRleNametableToPpu
jsr bulkCopyToPpu_reworkReturnAddress
ldx PPUSTATUS
lda #$20
sta PPUADDR
lda #$00
sta PPUADDR
.import rleDecodeToPpu
jmp rleDecodeToPpu
renderPlay_mod:
.export renderPlay_mod
lda numberOfPlayers
cmp #$02
beq @twoPlayers
.import after_renderPlay_mod
jmp after_renderPlay_mod
@twoPlayers:
; Update level/palette on a different frame than score (and implicitly
; lines) is updated. This reduces the number of updates on the same
; frame to help squeeze updates within vblank. The wrong palette is not
; visible the first frame of the game in two-player because the game
; logic runs after rendering, so the first frame has no sprites. In
; one-player the statistics will have the wrong palette for an extra
; frame.
lda outOfDateRenderFlags
eor #$02
and #$06
bne @renderScore
lda #>INGAME_LAYOUT_P1_LEVEL
sta PPUADDR
lda #<INGAME_LAYOUT_P1_LEVEL
sta PPUADDR
ldx player1_levelNumber
lda levelDisplayTable,x
jsr twoDigsToPPU
jsr updatePaletteForLevel
lda #>INGAME_LAYOUT_P2_LEVEL
sta PPUADDR
lda #<INGAME_LAYOUT_P2_LEVEL
sta PPUADDR
ldx player2_levelNumber
lda levelDisplayTable,x
jsr twoDigsToPPU
; updatePaletteForLevel_player2
lda player2_levelNumber
ldy #$04
.import updatePaletteForLevel_postConf
jsr updatePaletteForLevel_postConf
lda outOfDateRenderFlags
and #$FD
sta outOfDateRenderFlags
.ifdef TOURNAMENT_MODE
;in tourmanent mode we try to reduce updates
;so we update only one set of numbers at once
;if we updated level, we just leave
lda #$00
jmp after_renderPlay_mod
.endif
@renderScore:
lda outOfDateRenderFlags
and #$04
beq @ret
lda #>INGAME_LAYOUT_P1_SCORE
sta PPUADDR
lda #<INGAME_LAYOUT_P1_SCORE
sta PPUADDR
lda player1_score+2
jsr twoDigsToPPU
lda player1_score+1
jsr twoDigsToPPU
lda player1_score
jsr twoDigsToPPU
lda #>INGAME_LAYOUT_P2_SCORE
sta PPUADDR
lda #<INGAME_LAYOUT_P2_SCORE
sta PPUADDR
lda player2_score+2
jsr twoDigsToPPU
lda player2_score+1
jsr twoDigsToPPU
lda player2_score
jsr twoDigsToPPU
lda outOfDateRenderFlags
and #$FB
sta outOfDateRenderFlags
.ifdef TOURNAMENT_MODE
;in tourmanent mode we try to reduce updates
;so we update only one set of numbers at once
;if we updated score, we just leave
lda #$00
jmp after_renderPlay_mod
@ret:
;we did no update so far, lets see if the
;tournament statistics need update
jsr updateTournamentRendering
.else
@ret:
.endif
lda #$00
jmp after_renderPlay_mod
.import vramPlayfieldRowsHi
.import vramPlayfieldRowsLo
.define FASTROWTOVRAM 2
.if FASTROWTOVRAM = 1
; A faster implementation of copying to the VRAM, by 92 cycles (from 246
; cycles down to 154).
;
; An unmodified implementation of render_mode_play_and_demo, but with 2 players
; enabled, does not fit within a vblank because 8 rows are copied which totals
; 1968 cycles by itself. The optimization here brings it down to 1232 cycles
; which may still be tight but isn't too much more than the 984 cycles
; normally used for 1 player.
copyPlayfieldRowToVRAM_fast:
.export copyPlayfieldRowToVRAM_fast
ldx vramRow
cpx #$15
bmi @skipRts
rts
@skipRts:
ldy multBy10Table,x
lda vramPlayfieldRowsHi,x
sta PPUADDR
lda numberOfPlayers
cmp #$01
beq @onePlayer
lda playfieldAddr+1
cmp #$05
beq @playerTwo
lda vramPlayfieldRowsLo,x
sec
sbc #$04
sta PPUADDR
jmp @copyRowForPlayer1
@playerTwo:
lda vramPlayfieldRowsLo,x
clc
adc #$0E
sta PPUADDR
.repeat 10,I
lda playfieldForSecondPlayer+I,y
sta PPUDATA
.endrepeat
jmp @doneWithRow
@onePlayer:
lda vramPlayfieldRowsLo,x
clc
adc #$06
sta PPUADDR
@copyRowForPlayer1:
.repeat 10,I
lda playfield+I,y
sta PPUDATA
.endrepeat
@doneWithRow:
inc vramRow
lda vramRow
cmp #$14
bmi @ret
lda #$20
sta vramRow
@ret: rts
.elseif FASTROWTOVRAM = 2
; A batched implementation of copying playfield to the VRAM, saving 76 cycles
; compared to copying each row individually (from 635 cycles down to 559,
; including boilerplate in caller).
;
; reg x: (input/output) vramRow
; reg a: (input) 0=player 1, 1=player 2
;
copyPlayfieldRowToVRAM4:
; generalCounter is off-limits as it is used by multiple callers of
; updateAudioWaitForNmiAndResetOamStaging, which waits for render.
; Specifically, it breaks Type B via initPlayfieldIfTypeB. While
; generalCounter is used by parts of render (e.g., @renderLevel,
; twoDigsToPPU, updateLineClearingAnimation), those render paths aren't
; taken in cases like Type B init. But this copying code path is taken.
.export copyPlayfieldRowToVRAM4
cpx #$20
bmi @skipRts
rts
@skipRts:
sta tmp3
tay
beq @playerOne
;playerTwo:
lda #$0E
sta tmp2
bne @continueSetup
@playerOne:
ldy numberOfPlayers
lda @offsetTable-1,y
sta tmp2
@continueSetup:
lda #$04
sta tmp1
; reg x: vramRow
; reg y: playfield offset for row
; tmp1: loop counter
; tmp2: VRAM LO offset
; tmp3: 0=player 1, 1=player 2
@loop:
lda vramPlayfieldRowsHi,x
sta PPUADDR
lda vramPlayfieldRowsLo,x
clc
adc tmp2
sta PPUADDR
ldy multBy10Table,x
lda tmp3
bne @playerTwoCopy
.repeat 10,I
lda playfield+I,y
sta PPUDATA
.endrepeat
jmp @nextIter
@playerTwoCopy:
.repeat 10,I
lda playfieldForSecondPlayer+I,y
sta PPUDATA
.endrepeat
@nextIter:
inx
cpx #$14
bpl @doneWithAllRows
@vramInRange:
dec tmp1
beq @ret
jmp @loop
@doneWithAllRows:
ldx #$20
@ret:
rts
@offsetTable:
.byte $06,(-$04)&$FF
.endif
copyOamStagingToOam_mod:
.export copyOamStagingToOam_mod
lda #$00
sta OAMADDR
lda #$02
sta OAMDMA
.import after_copyOamStagingToOam_mod
jmp after_copyOamStagingToOam_mod
gameModeState_updateCountersAndNonPlayerState_mod:
.export gameModeState_updateCountersAndNonPlayerState_mod
lda newlyPressedButtons_player2
and #$20
beq @continue
lda displayNextPiece
eor #$02
sta displayNextPiece
@continue:
lda newlyPressedButtons_player1
and #$20
rts
stageSpriteForNextPiece_player1_mod:
.export stageSpriteForNextPiece_player1_mod
lda displayNextPiece
and #$01
bne @ret
lda numberOfPlayers
cmp #$01
bne @twoPlayers
lda #$C8
sta spriteXOffset
lda #$77
sta spriteYOffset
jmp @stage
@twoPlayers:
lda #INGAME_LAYOUT_P1_PREVIEW_X
sta spriteXOffset
lda #INGAME_LAYOUT_P1_PREVIEW_Y
sta spriteYOffset
@stage:
ldx nextPiece
lda orientationToSpriteTable,x
sta spriteIndexInOamContentLookup
jmp loadSpriteIntoOamStaging
@ret: rts
savePlayer2State_mod:
.export savePlayer2State_mod
; fix recent result of stageSpriteForCurrentPiece
jsr adjustLast4SpritesInOamPlayer1PaletteToPlayer2
jsr savePlayer2State
jsr stageSpriteForNextPiece_player2
.ifndef NEXT_ON_TOP
; Alternate draw order to flicker on conflict
lda frameCounter
and #$0F
jsr moveSpriteToEndOfOamStaging
lda frameCounter
and #$0F
eor #$08
jsr moveSpriteToEndOfOamStaging
.endif
.ifdef TOURNAMENT_MODE
jmp tournamentLeadCheck
.else
rts
.endif
stageSpriteForNextPiece_player2:
lda displayNextPiece
and #$02
bne @ret
lda #INGAME_LAYOUT_P2_PREVIEW_X
sta spriteXOffset
lda #INGAME_LAYOUT_P2_PREVIEW_Y
sta spriteYOffset
ldx twoPlayerPieceDelayPiece
lda orientationToSpriteTable,x
sta spriteIndexInOamContentLookup
jsr loadSpriteIntoOamStaging
jsr adjustLast4SpritesInOamPlayer1PaletteToPlayer2
@ret: rts
adjustLast4SpritesInOamPlayer1PaletteToPlayer2:
lda oamStagingLength
sec
sbc #4*4
tax
@adjustSprite:
inx
inx
dec oamStaging,x
inx
inx
cpx oamStagingLength
bne @adjustSprite
rts
.ifndef NEXT_ON_TOP
; Move a sprite in oamStaging to end of oamStaging.
;
; reg a: sprite number in oamStaging to move
moveSpriteToEndOfOamStaging:
asl a
asl a
tax
ldy oamStagingLength
lda #$04
sta generalCounter
@copySprite:
lda oamStaging,x
sta oamStaging,y
lda #$FF
sta oamStaging,x
inx
iny
dec generalCounter
bne @copySprite
sty oamStagingLength
rts
.endif
isStartNewlyPressed:
.export isStartNewlyPressed
lda newlyPressedButtons_player1
ora newlyPressedButtons_player2
and #$10
cmp #$10
rts
.segment "CODE2"
legal_screen_nametable_rle:
.export legal_screen_nametable_rle
.incbin "build/legal_screen_nametable.nam.rle"
demo_pollController_mod_after := $9D66
demo_pollController_mod_skip := $9D6A
demo_pollController_mod:
.export demo_pollController_mod
jsr pollController
lda newlyPressedButtons_player1
ora newlyPressedButtons_player2
and #$10
bne @ret
lda numberOfPlayers
cmp #$02
bne @done
lda demo_playingPlayer
cmp #$01
beq @player1Playing
cmp #$02
beq @player2Playing
; check for starting player
lda newlyPressedButtons_player1
bne @startPlayer1
lda newlyPressedButtons_player2
beq @bothPlayersDemo
@startPlayer2:
lda #$02
sta demo_playingPlayer
@player2Playing:
@done:
lda #$00
@ret:
jmp demo_pollController_mod_after
@startPlayer1:
inc demo_playingPlayer
@player1Playing:
; copy player1 input to player2
lda newlyPressedButtons_player1
sta newlyPressedButtons_player2
lda heldButtons_player1
sta heldButtons_player2
jsr demo_pollController_mod_skip
; now swap player1 and player2 input
lda newlyPressedButtons_player2
sta tmp1
lda newlyPressedButtons_player1
sta newlyPressedButtons_player2
lda tmp1
sta newlyPressedButtons_player1
lda heldButtons_player2
sta tmp1
lda heldButtons_player1
sta heldButtons_player2
lda tmp1
sta heldButtons_player1
rts
@bothPlayersDemo:
jsr demo_pollController_mod_skip
lda newlyPressedButtons_player1
sta newlyPressedButtons_player2
lda heldButtons_player1
sta heldButtons_player2
rts
chooseNextTetrimino_mod:
.export chooseNextTetrimino_mod
bne @pickRandomTetrimino_mod
; Assume that when demoIndex is 0/1, this is being called from
; gameModeState_initGameState and that it applies to both players
lda demoIndex
cmp #$02
bmi @bothPlayers
lda activePlayer
cmp #$01
bne @player2
ldx demoIndex
inc demoIndex
rts
@bothPlayers:
inc demoIndex
@player2:
ldx demoIndex_player2
inc demoIndex_player2
rts
@pickRandomTetrimino_mod:
pla ; throw away return address
pla
ldx #personal_rng
ldy #$02
jsr generateNextPseudorandomNumber
ldx #personal_rng
ldy #$02
jsr generateNextPseudorandomNumber
ldx #personal_rng
ldy #$02
jsr generateNextPseudorandomNumber
jsr swapRngState
jsr pickRandomTetrimino
pha
jsr swapRngState
pla
rts
swapRngState:
ldx #$04
@swapByte:
lda rng_seed-1,x
ldy personal_rng-1,x
sty rng_seed-1,x
sta personal_rng-1,x
dex
bne @swapByte
rts
playState_receiveGarbage_fillGarbage_mod:
.export playState_receiveGarbage_fillGarbage_mod
sta (playfieldAddr),y
inx
cpx #$0A
bne @rts
txa
ldx activePlayer
dec garbageUntilResetHole_P1-1,x
bne @ret
; reset hole
pha
lda #$0A
sta garbageUntilResetHole_P1-1,x
tya
pha
@generateRandom:
ldx #rng_seed
ldy #$02
jsr generateNextPseudorandomNumber
lda rng_seed
and #$0F
cmp #$0A
bpl @generateRandom
cmp garbageHole
beq @generateRandom
sta garbageHole
pla
tay
pla
@ret: tax
@rts: rts
gameMode_levelMenu_nametable_mod:
.export gameMode_levelMenu_nametable_mod
jsr bulkCopyToPpu
.addr level_menu_nametable
lda numberOfPlayers
cmp #$01
bne @twoPlayers
jsr bulkCopyToPpu
.addr player2PressStartPatch
jmp @levelMenuInit
@twoPlayers:
jsr bulkCopyToPpu
.addr player1ActivePatch
@levelMenuInit:
lda player2_startLevel
@forceStartLevelToRange:
sta player2_startLevel
sec
sbc #$0A
bcs @forceStartLevelToRange
rts
gameMode_levelMenu_processPlayer1Navigation_processPlayer2:
.export gameMode_levelMenu_processPlayer1Navigation_processPlayer2
lda newlyPressedButtons_player2
and #$90 ; Start or A. A is required for Famicom
beq @checkBPressed
lda numberOfPlayers
cmp #$01
bne @checkBPressed
inc numberOfPlayers
lda #$08
sta soundEffectSlot1Init
jmp gameMode_levelMenu
@checkBPressed:
lda newlyPressedButtons_player2
cmp #$40
bne @ret
lda numberOfPlayers
cmp #$02
bne @ret
dec numberOfPlayers
lda #$01
sta soundEffectSlot3Init
jmp gameMode_levelMenu
@ret:
jsr updateAudioWaitForNmiAndResetOamStaging
jmp gameMode_levelMenu_processPlayer1Navigation
player2PressStartPatch:
set_tbl $0000
.byte $20,$A4,$18
.byte " P2 PRESS START! "
.byte $FF
player1ActivePatch:
.byte $20,$A4,$18
.byte " PLAYER 1 "
.byte $FF
player2ActivePatch:
.byte $20,$A4,$18
.byte " PLAYER 2 "
.byte $FF
gameMode_levelMenu_processPlayer2Navigation:
.export gameMode_levelMenu_processPlayer2Navigation
lda numberOfPlayers
cmp #$01
bne @twoPlayers
inc gameMode
rts
@twoPlayers:
jsr updateAudioWaitForNmiAndDisablePpuRendering
jsr disableNmi
jsr bulkCopyToPpu
.addr player2ActivePatch
jsr waitForVBlankAndEnableNmi
jsr updateAudioWaitForNmiAndEnablePpuRendering
@afterPatch:
lda #$00
sta activePlayer
lda player2_startLevel
sta startLevel
lda player2_startHeight
sta startHeight
lda originalY
sta selectingLevelOrHeight
lda newlyPressedButtons_player2
sta newlyPressedButtons
jsr gameMode_levelMenu_handleLevelHeightNavigation
lda startLevel
sta player2_startLevel
lda startHeight
sta player2_startHeight
lda selectingLevelOrHeight
sta originalY
lda newlyPressedButtons_player2
; allow player1 to press start for Famicom
ora newlyPressedButtons_player1
and #$10
beq @checkBPressed
lda heldButtons_player2
and #$80
beq @startAndANotPressed
lda player2_startLevel
clc
adc $8469 ; normally #$0A, GPTEPG support. Same for PAL
sta player2_startLevel
@startAndANotPressed:
lda #$00
sta gameModeState
lda #$02
sta soundEffectSlot1Init
inc gameMode
rts
@checkBPressed:
lda newlyPressedButtons_player2
cmp #$40
bne @doneProcessing
lda #$02
sta soundEffectSlot1Init
jsr updateAudioWaitForNmiAndResetOamStaging
jmp gameMode_levelMenu
@doneProcessing:
jsr updateAudioWaitForNmiAndResetOamStaging
jmp @afterPatch
gameModeState_handleGameOver_mod:
.export gameModeState_handleGameOver_mod
lda numberOfPlayers
cmp #$01
bne @twoPlayers
ldx #$00 ; player score offset for handleHighScoreIfNecessary
stx tmp3
jmp gameModeState_handleGameOver
@twoPlayers:
lda player1_playState
ora player2_playState
beq @gameOver
; put known data in a, to avoid it from matching "cmp gameModeState" in
; @mainLoop. In 1 player mode, numberOfPlayers will be in a.
lda #$00
inc gameModeState
rts
@gameOver:
ldx #$00 ; player score offset for handleHighScoreIfNecessary
stx tmp3
jsr handleHighScoreIfNecessary
ldx #player2_score-player1_score
stx tmp3
jsr handleHighScoreIfNecessary
jmp gameModeState_handleGameOver
highScoreEntryScreen_render:
.export highScoreEntryScreen_render
lda numberOfPlayers
cmp #$01
beq @ret
lda tmp3
bne @player2
jsr bulkCopyToPpu
.addr player1ActivePatch
jmp @ret
@player2:
jsr bulkCopyToPpu
.addr player2ActivePatch
@ret:
jsr waitForVBlankAndEnableNmi
rts
highScoreEntryScreen_get_player:
.export highScoreEntryScreen_get_player
jsr loadSpriteIntoOamStaging
ldx tmp3
beq @ret
; copy start presses from player1 to player2 for famicom
lda newlyPressedButtons_player1
and #$10 ; start
ora newlyPressedButtons_player2
sta newlyPressedButtons_player2
ldx #$01
@ret:
rts
updateMusicSpeed_noBlockInRow_mod:
.export updateMusicSpeed_noBlockInRow_mod
tax
and activePlayer
eor allegro
sta allegro
txa
cmp activePlayer
rts
updateMusicSpeed_foundBlockInRow_mod:
.export updateMusicSpeed_foundBlockInRow_mod
tax
ora activePlayer
sta allegro
txa
cmp #$00
rts
playState_bTypeGoalCheck_mod:
.export playState_bTypeGoalCheck_mod
lda numberOfPlayers
cmp #$02
beq @twoPlayers
lda #$00
sta player1_vramRow
rts
@twoPlayers:
; pop return address
pla
pla
lda sleepCounter
bne @alreadyInited
; No need to set vramRow=0 to display the "Success!" message, as
; playState_checkForCompletedRows does so already
lda #$80
sta sleepCounter
rts
@alreadyInited:
lda currentlyPlayingMusicTrack
cmp #$02
bne @checkIfMusicComplete
; The music is already loaded; don't restart it
lda #$00
sta musicTrack
@checkIfMusicComplete:
lda sleepCounter
cmp #$01
beq @doneWithEndMusic
rts
@doneWithEndMusic:
lda #$00
; a is 0, to be stored in playState
playState_updateGameOverCurtain_curtainFinished_mod:
.export playState_updateGameOverCurtain_curtainFinished_mod
sta playState
lda numberOfPlayers
cmp #$02
bne @ret
lda $9AE3
cmp #pendingGarbageInactivePlayer
beq @garbageEnabled
; playState has not yet been copied to player*_playState.
; If a player has already died, then this would make two.
lda player1_playState
beq @bothPlayersDead
lda player2_playState
beq @bothPlayersDead
jmp @updateMusicSpeed_playerDied
@garbageEnabled:
; End game immediately if garbage is enabled
lda #$00