Skip to content

Commit 91eb752

Browse files
Merge pull request #84 from HydrantDude/Crash-Detection
Added crash support for PAL, and support for a "strict" mode in which…
2 parents 1ecc034 + 7ea32ac commit 91eb752

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

src/constants.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ MODE_HARDDROP
8484
MODE_SPEED_TEST
8585
MODE_SCORE_DISPLAY
8686
MODE_CRASH
87+
MODE_STRICT
8788
MODE_HZ_DISPLAY
8889
MODE_INPUT_DISPLAY
8990
MODE_DISABLE_FLASH
@@ -149,6 +150,7 @@ MENU_TOP_MARGIN_SCROLL := 7 ; in blocks
149150
.byte $0 ; MODE_SPEED_TEST
150151
.byte $5 ; MODE_SCORE_DISPLAY
151152
.byte $3 ; MODE_CRASH
153+
.byte $1 ; MODE_STRICT
152154
.byte $1 ; MODE_HZ_DISPLAY
153155
.byte $1 ; MODE_INPUT_DISPLAY
154156
.byte $1 ; MODE_DISABLE_FLASH

src/nametables/game_type_menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ drawTiles(buffer, lookup, `
6363
`);drawTiles(extra, lookup, `
6464
#a SCORING d#
6565
#a CRASH d#
66+
#a STRICT CRASH d#
6667
#a HZ DISPLAY d#
6768
#a INPUT DISPLAY d#
6869
#a DISABLE FLASH d#
@@ -74,7 +75,6 @@ drawTiles(buffer, lookup, `
7475
#a QUAL MODE d#
7576
#a PAL MODE d#
7677
#a d#
77-
#a d#
7878
#a V5 d#
7979
#a d#
8080
#a d#

src/playstate/updatestats.asm

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ testCrash:
586586
beq @dontClearCount
587587
tax
588588
ldy lineClearStatsByType-1,x
589-
beq @dontClearCount
589+
bne @dontClearCount
590590
lda #$0B ; 11 cycles for clearcount 10s place
591591
adc allegroIndex
592592
sta allegroIndex
@@ -648,11 +648,24 @@ testCrash:
648648
clc
649649
adc allegroIndex ; adds 8 cycles for current piece = 8 (horizontal Z)
650650
sta allegroIndex
651-
@not8: bcc @randomFactors ; adc above means branch always when entered after it. piece < 8 adds 0 cycles.
651+
@not8: bcc @palCycles ; adc above means branch always when entered after it. piece < 8 adds 0 cycles.
652652
lda #$0B ; would be 12 but carry is set. for piece > 8
653653
adc allegroIndex
654654
sta allegroIndex
655+
@palCycles:
656+
lda palFlag ; if pal, move thresholds for crashes 3467 cycles away
657+
beq @randomFactors
658+
sec
659+
lda cycleCount+1
660+
sbc #$8B
661+
sta cycleCount+1
662+
lda cycleCount
663+
sbc #$0D
664+
sta cycleCount
665+
clc
655666
@randomFactors:
667+
lda strictFlag
668+
bne @noDMA ;for strict crash, do not add random cycles.
656669
lda oneThirdPRNG ; RNG for which cycle of the last instruction the game returns to
657670
adc allegroIndex
658671
sta allegroIndex
@@ -697,6 +710,13 @@ testCrash:
697710
;confettiB = 30765-31193
698711
cmp #$74 ;high byte of cycle count is already loaded
699712
bne @nextSwitch
713+
lda strictFlag
714+
beq @normalChecks ;special conditions for "strict" mode. crash on 7423-7442, check red on 7443-7448.
715+
lda cycleCount+1
716+
cmp #$23 ;up to 8 cycles could have been added, but weren't, so our low bound is 8 below the typical.
717+
bcc @nextSwitch ;if too low, exit
718+
bcs @highBoundary ;otherwise, check high bound and skip check for gap.
719+
@normalChecks:
700720
lda cycleCount+1
701721
cmp #$2B ; minimum crash
702722
bcc @nextSwitch
@@ -708,19 +728,31 @@ testCrash:
708728
@continue:
709729
cmp #$36
710730
bcc @nextSwitch
731+
@highBoundary:
711732
cmp #$49
712733
bcs @nextSwitch ;between 7436 & 7448
713734
cmp #$43
714735
bcc @notRed ;checking if crash is during first crashable instruction
736+
txa
737+
lsr ;all odd switches on PAL result in no crash.
738+
bcs @oddSwitch
739+
lda palFlag
740+
bne @nextSwitch ;if PAL, no crash.
741+
@oddSwitch:
715742
cpx #$07 ; checking which switch routine is active.
716-
beq @nextSwitch ;continues crashless if sw2
743+
beq @isPal ;checks version if sw2
717744
cpx #$03
718745
bne @notRed ; runs graphics corruption if sw6
719746
ldx #$FF ; these are normally set by the code it would jump to after NMI.
720747
ldy #$00
721748
lda #$81 ; value normally held at this point in sw6
722749
jsr satanSpawn
723750
jmp @allegroClear ;allegroClear is basically return, just clears the variable first.
751+
@isPal:
752+
lda palFlag
753+
beq @nextSwitch ;if NTSC, continue, no crash.
754+
jsr blackBox
755+
jmp @allegroClear
724756
@notRed:
725757
lda #$F0
726758
sta crashState
@@ -867,6 +899,8 @@ confettiHandler:
867899
beq @checkForNmi
868900
jmp confettiHandler
869901
@infiniteConfetti:
902+
lda palFlag
903+
bne @endConfetti ;infinite confetti does not exist on PAL
870904
lda heldButtons_player1
871905
adc #$80 ; loading 80 as Y coordinate of confetti text if nothing is held.
872906
cmp #$80
@@ -876,6 +910,18 @@ confettiHandler:
876910
sta allegroIndex
877911
rts
878912
satanSpawn: ; copied from routine vanilla game's memset_ppu_page_and_more which is no longer present in gym
913+
lda palFlag
914+
beq @ntsc
915+
lda #$00
916+
sta verticalBlankingInterval
917+
@checkForNmi:
918+
lda verticalBlankingInterval ;busyloop
919+
beq @checkForNmi
920+
ldx #$FF
921+
ldy #$00
922+
923+
@ntsc:
924+
lda #$AA
879925
sta tmp1
880926
stx tmp2
881927
sty tmp3
@@ -913,3 +959,41 @@ LAC61: sty PPUDATA
913959
bne LAC61
914960
LAC67: ldx tmp2
915961
rts
962+
blackBox: ;copied from patchToPpu from original game as it's no longer present in gym
963+
lda #$00
964+
sta verticalBlankingInterval
965+
@checkForNmi:
966+
lda verticalBlankingInterval ;busyloop
967+
beq @checkForNmi
968+
ldy #$00
969+
@patchAddr:
970+
lda patchData,y
971+
sta PPUADDR
972+
iny
973+
lda patchData,y
974+
sta PPUADDR
975+
iny
976+
@patchValue:
977+
lda patchData,y
978+
iny
979+
cmp #$FE
980+
beq @patchAddr
981+
cmp #$FD
982+
beq @ret
983+
sta PPUDATA
984+
jmp @patchValue
985+
986+
@ret: rts
987+
patchData:
988+
.byte $22,$58,$FF,$FE,$22,$75,$FF,$FF
989+
.byte $FF,$FF,$FF,$FF,$FE,$22,$94,$FF
990+
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FE
991+
.byte $22,$B4,$FF,$FF,$FF,$FF,$FF,$FF
992+
.byte $FF,$FF,$FE,$22,$D4,$FF,$FF,$FF
993+
.byte $FF,$FF,$FF,$FF,$FF,$FE,$22,$F4
994+
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
995+
.byte $FE,$23,$14,$FF,$FF,$FF,$FF,$FF
996+
.byte $FF,$FF,$FF,$FE,$23,$34,$FF,$FF
997+
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FE,$22
998+
.byte $CA,$46,$47,$FE,$22,$EA,$56,$57
999+
.byte $FD

src/ram.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ droughtModifier: .res 1
341341
dasModifier: .res 1
342342
scoringModifier: .res 1
343343
crashModifier: .res 1
344+
strictFlag: .res 1 ;used for crash detection. If 1, the game will register a crash anytime there is a possibility of one.
344345
hzFlag: .res 1
345346
inputDisplayFlag: .res 1
346347
disableFlashFlag: .res 1

src/util/strings.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ stringLookup:
9696
.byte stringTopout-stringLookup
9797
.byte stringCrash-stringLookup
9898
.byte stringConfetti-stringLookup ;19
99+
.byte stringStrict-stringLookup
99100
stringClassic:
100101
.byte $7,'C','L','A','S','S','I','C'
101102
stringLetters:
@@ -150,3 +151,5 @@ stringCrash:
150151
.byte $5,'C','R','A','S','H'
151152
stringConfetti:
152153
.byte $8,'C','O','N','F','E','T','T','I'
154+
stringStrict:
155+
.byte $6,'S','T','R','I','C','T'

0 commit comments

Comments
 (0)