Skip to content

Commit 55c7313

Browse files
committed
wrote the entire rest of the hack lol
1 parent a64b86d commit 55c7313

File tree

2 files changed

+271
-1
lines changed

2 files changed

+271
-1
lines changed

src/playstate/updatestats.asm

Lines changed: 270 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ checkLevelUp:
113113

114114
@nextLevel:
115115
inc levelNumber
116+
lda crashFlag
117+
ora #$08
118+
sta crashFlag
116119
lda #$06 ; checked in floor linecap stuff, just below
117120
sta soundEffectSlot1Init
118121
lda outOfDateRenderFlags
@@ -198,7 +201,8 @@ addPointsRaw:
198201
lda #4
199202
sta completedLines
200203
@notTapQuantity:
201-
lda holdDownPoints
204+
jsr testCrash
205+
lda holdDownPoints
202206
cmp #$02
203207
bmi @noPushDown
204208
jsr addPushDownPoints
@@ -450,3 +454,268 @@ calcBCDLinesAndTileQueue:
450454
sta linesTileQueue
451455
@ret:
452456
rts
457+
testCrash:
458+
lda #$1C ; setting all cycles which always happen
459+
sta cycleCount
460+
lda #$6F
461+
sta cycleCount+1 ;low byte at +1
462+
463+
lda completedLines
464+
beq @linesNotCleared
465+
ldx #$04 ;setting loop to run 4x
466+
@clearedLine:
467+
lda completedRow-1, x
468+
beq @noneThisRow ; adds no cycles if lines not cleared
469+
cmp #$0B
470+
lda #$00
471+
bcc @sub11
472+
lda #$02 ;97 cycles if row is above 11
473+
clc
474+
@sub11: adc #$5F ;95 cycles
475+
adc cycleCount+1
476+
sta cycleCount+1
477+
lda cycleCount
478+
adc #$00 ; dealing with carry
479+
sta cycleCount
480+
@noneThisRow:
481+
dex
482+
bne @clearedLine
483+
484+
@linesNotCleared:
485+
lda displayNextPiece
486+
and #BUTTON_SELECT
487+
beq @nextOff
488+
lda #$8A ; add 394 cycles for nextbox
489+
adc cycleCount+1
490+
sta cycleCount+1
491+
lda cycleCount
492+
adc #$01 ; high byte of 18A
493+
sta cycleCount
494+
495+
@nextOff:
496+
lda allegroIndex
497+
bne @allegro
498+
lda #$95 ; 149 in decimal.
499+
clc
500+
ldx wasAllegro ; FF is no allegro. 00 is allegro.
501+
bne @addMusicCycles
502+
adc #$26 ;add 38 cycles for disabling allegro
503+
@addMusicCycles:
504+
adc cycleCount+1
505+
sta cycleCount+1
506+
lda cycleCount
507+
adc #$00
508+
sta cycleCount
509+
bne @linesCycles
510+
@allegro:
511+
sec
512+
sbc #$32 ; subtract 50, allegro index already loaded
513+
asl
514+
asl
515+
asl
516+
asl ;multiply by 16
517+
tax ; save low byte result
518+
lda cycleCount
519+
adc #$00 ; add high byte carry
520+
sta cycleCount
521+
txa
522+
adc cycleCount+1
523+
sta cycleCount+1
524+
lda cycleCount
525+
adc #$00 ; add carry again
526+
sta cycleCount
527+
lda wasAllegro
528+
beq @linesCycles ; 00 is allegro
529+
lda #$29 ; add 41 cycles for changing to allegro
530+
adc cycleCount+1
531+
sta cycleCount+1
532+
lda cycleCount
533+
adc #$00
534+
sta cycleCount
535+
536+
@linesCycles:
537+
538+
lda #$00
539+
sta allegroIndex ;will be reusing to store small amounts of cycles and add at the end.
540+
541+
lda newlyPressedButtons_player1
542+
and #BUTTON_SELECT
543+
beq @digit1
544+
lda #$07 ; add 7 cycles for select
545+
adc allegroIndex
546+
sta allegroIndex
547+
@digit1:
548+
lda crashFlag
549+
and #$01
550+
beq @digit2
551+
lda #$4F ; add 79 cycles for 10s place
552+
adc allegroIndex
553+
sta allegroIndex
554+
@digit2:
555+
lda crashFlag
556+
and #$02
557+
beq @clearStats
558+
lda #$0C ; add 12 cycles for 100s place
559+
adc allegroIndex
560+
sta allegroIndex
561+
@clearStats:
562+
lda crashFlag
563+
and #$04
564+
beq @newLevel
565+
lda #$0B ; 11 cycles for clearcount 10s place
566+
adc allegroIndex
567+
sta allegroIndex
568+
@newLevel:
569+
lda crashFlag
570+
and #$08
571+
beq @pushDown
572+
lda #$12 ; 18 cycles for levelup
573+
adc allegroIndex
574+
sta allegroIndex
575+
@pushDown:
576+
lda holdDownPoints
577+
cmp #$02
578+
bcc @single
579+
cmp #$08
580+
bcs @over7
581+
lda #$09 ; 1-6 costs 9
582+
adc allegroIndex
583+
sta allegroIndex
584+
@over7:
585+
clc
586+
lda #$5A ; add 90 cycles for pushdown
587+
adc allegroIndex
588+
sta allegroIndex
589+
bcc @scoreCycles
590+
@single:
591+
lda completedLines
592+
cmp #$01
593+
bne @notsingle
594+
lda #$52 ; 53 for singles, carry is set
595+
adc allegroIndex
596+
sta allegroIndex
597+
@notsingle:
598+
bcc @scoreCycles
599+
lda #$41 ; 42 for clears over a single, carry is set
600+
adc allegroIndex
601+
sta allegroIndex
602+
@scoreCycles:
603+
ldx completedLines
604+
beq @not0
605+
inc cycleCount ; no cleared lines is +737, adding 256 twice and rest is covered by sumTable
606+
inc cycleCount
607+
@not0: lda sumTable, x ; constant amount of cycles added for each line clear
608+
clc
609+
adc cycleCount+1
610+
sta cycleCount+1
611+
lda cycleCount
612+
adc #$00
613+
sta cycleCount
614+
lda factorTable,x ; linear amount of cycles added for each line clear
615+
sta factorB24
616+
lda levelNumber
617+
sta factorA24
618+
lda #$00
619+
sta factorA24+1 ;overkill 24-bit multiplication, both factors are 8 bit.
620+
sta factorA24+2
621+
sta factorB24+1
622+
sta factorB24+2
623+
sta crashFlag ; done with flags and can now reuse variable
624+
jsr unsigned_mul24 ; result in product24
625+
clc
626+
lda product24
627+
adc cycleCount+1
628+
sta cycleCount+1
629+
lda product24+1
630+
adc cycleCount
631+
sta cycleCount
632+
lda completedLines
633+
cmp #$04
634+
bne @currentPieceCheck
635+
lda frameCounter
636+
and #$07 ; check if frame counter is 0%8
637+
bne @currentPieceCheck
638+
lda #$04 ; would be 5, but carry is set by cmp #$04
639+
adc allegroIndex
640+
sta allegroIndex
641+
@currentPieceCheck:
642+
lda currentPiece
643+
cmp #$08
644+
bne @not8
645+
clc
646+
adc allegroIndex
647+
sta allegroIndex
648+
@not8: bcc @randomFactors
649+
lda #$0B ; would be 12 but carry is set
650+
adc allegroIndex
651+
sta allegroIndex
652+
@randomFactors:
653+
lda oneThirdPRNG ; RNG for which cycle of the last instruction the game returns to
654+
adc allegroIndex
655+
sta allegroIndex
656+
lda frameCounter
657+
and #$01 ; RNG for frame length
658+
adc allegroIndex
659+
sta allegroIndex
660+
lda rng_seed ; RNG for RNG
661+
asl
662+
bcc @newBit0
663+
inc allegroIndex
664+
@newBit0:
665+
lda nmiReturnAddr
666+
cmp <updateAudioWaitForNmiAndResetOamStaging+10
667+
beq @returnLate ; RNG for which instruction returned to
668+
lda #$03
669+
clc
670+
adc allegroIndex
671+
sta allegroIndex
672+
@returnLate:
673+
lda rng_seed+1 ; RNG for OAMDMA
674+
lsr
675+
bcc @noDMA
676+
inc allegroIndex
677+
@noDMA:
678+
ldx #$08
679+
@loop: lda cycleCount ; adding stockpiled
680+
clc
681+
adc allegroIndex
682+
sta cycleCount+1
683+
lda cycleCount
684+
adc #$00
685+
sta cycleCount
686+
;crash should occur on cycle count results 29734-29739, 29745-29763 = $7426-742B, $7431-7443
687+
cmp #$74 ;high byte of cycle count is already loaded
688+
bne @nextSwitch
689+
lda cycleCount+1
690+
cmp #$26 ; minimum crash
691+
bcc @nextSwitch
692+
cmp #$2C ; gap
693+
bcs @continue
694+
lda #$FF
695+
sta crashFlag
696+
bne @allegroClear
697+
@continue:
698+
cmp #$31
699+
bcc @nextSwitch
700+
cmp #$44
701+
bcs @nextSwitch
702+
lda $FF
703+
sta crashFlag
704+
705+
@nextSwitch:
706+
lda switchTable-1,x ; adding cycles to advance to next switch routine
707+
sta allegroIndex
708+
dex
709+
bne @loop
710+
711+
@allegroClear:
712+
lda #$00
713+
sta allegroIndex
714+
rts
715+
716+
factorTable:
717+
.byte $53, $88, $7D, $7D, $7D
718+
sumTable:
719+
.byte $E1, $1C, $38, $54, $80 ; tetris is 4*28+16 = 128
720+
switchTable:
721+
.byte $3C, $77, $3C, $65, $3C, $66, $3C;60 119 60 101 60 102 60 gets read in reverse

src/playstate/util.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ updateMusicSpeed:
9090
dex
9191
bne @checkForBlockInRow
9292
lda allegro
93+
sta wasAllegro
9394
beq @ret
9495
lda #$00
9596
sta allegro

0 commit comments

Comments
 (0)