Skip to content

Commit 68a7f59

Browse files
committed
added comments
1 parent 2d211e0 commit 68a7f59

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

src/playstate/updatestats.asm

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,12 @@ calcBCDLinesAndTileQueue:
463463
@ret:
464464
rts
465465
testCrash:
466-
lda #$1C ; setting all cycles which always happen
466+
lda #$1C ; setting all cycles which always happen. for optimizing, this can be removed if all compared numbers are reduced by $6F1C.
467467
sta cycleCount
468468
lda #$6F
469469
sta cycleCount+1 ;low byte at +1
470470

471-
lda completedLines
471+
lda completedLines ; checking if lines cleared
472472
beq @linesNotCleared
473473
ldx #$04 ;setting loop to run 4x
474474
@clearedLine:
@@ -490,7 +490,7 @@ testCrash:
490490
bne @clearedLine
491491

492492
@linesNotCleared:
493-
lda displayNextPiece
493+
lda displayNextPiece ;00 is nextbox enabled
494494
bne @nextOff
495495
lda #$8A ; add 394 cycles for nextbox
496496
adc cycleCount+1
@@ -504,7 +504,7 @@ testCrash:
504504
bne @allegro
505505
lda #$95 ; 149 in decimal.
506506
clc
507-
ldx wasAllegro ; FF is allegro. 00 is no allegro.
507+
ldx wasAllegro ; FF is allegro. 00 is no allegro. wasAllegro contains allegro status prior to this frame
508508
beq @addMusicCycles
509509
adc #$26 ;add 38 cycles for disabling allegro
510510
@addMusicCycles:
@@ -520,7 +520,7 @@ testCrash:
520520
asl
521521
asl
522522
asl
523-
asl ;multiply by 16
523+
asl ;multiply by 16 cycles per cell checked
524524
tax ; save low byte result
525525
lda cycleCount
526526
adc #$00 ; add high byte carry
@@ -555,14 +555,14 @@ testCrash:
555555
lda crashFlag
556556
and #$01
557557
beq @digit2
558-
lda #$4F ; add 79 cycles for 10s place
558+
lda #$4F ; add 79 cycles for lines 10s place
559559
adc allegroIndex
560560
sta allegroIndex
561561
@digit2:
562562
lda crashFlag
563563
and #$02
564564
beq @clearStats
565-
lda #$0C ; add 12 cycles for 100s place
565+
lda #$0C ; add 12 cycles for lines 100s place
566566
adc allegroIndex
567567
sta allegroIndex
568568
@clearStats:
@@ -585,7 +585,7 @@ testCrash:
585585
bcc @single
586586
cmp #$08
587587
bcs @over7
588-
lda #$09 ; 1-6 costs 9
588+
lda #$09 ; 1-6 pushdown costs 9 add'l cycles
589589
adc allegroIndex
590590
sta allegroIndex
591591
@over7:
@@ -627,7 +627,7 @@ testCrash:
627627
sta factorA24+2
628628
sta factorB24+1
629629
sta factorB24+2
630-
sta crashFlag ; done with flags and can now reuse variable
630+
sta crashFlag ; unrelated to current routine, just needed to clear the flag and $00 was loaded.
631631
jsr unsigned_mul24 ; result in product24
632632
clc
633633
lda product24
@@ -650,10 +650,10 @@ testCrash:
650650
cmp #$08
651651
bne @not8
652652
clc
653-
adc allegroIndex
653+
adc allegroIndex ; adds 8 cycles for current piece = 8 (horizontal Z)
654654
sta allegroIndex
655-
@not8: bcc @randomFactors
656-
lda #$0B ; would be 12 but carry is set
655+
@not8: bcc @randomFactors ; adc above means branch always when entered after it. piece < 8 adds 0 cycles.
656+
lda #$0B ; would be 12 but carry is set. for piece > 8
657657
adc allegroIndex
658658
sta allegroIndex
659659
@randomFactors:
@@ -672,13 +672,13 @@ testCrash:
672672
@newBit0:
673673
lda nmiReturnAddr
674674
cmp #<updateAudioWaitForNmiAndResetOamStaging+10
675-
beq @returnLate ; checking which instruction returned to
675+
beq @returnLate ; checking which instruction returned to. if so, add 3 cycles
676676
lda #$03
677677
clc
678678
adc allegroIndex
679679
sta allegroIndex
680680
@returnLate:
681-
lda rng_seed+1 ; RNG for OAMDMA
681+
lda rng_seed+1 ; RNG for OAMDMA, add 1 cycle for syncing
682682
lsr
683683
bcc @noDMA
684684
inc allegroIndex
@@ -707,141 +707,141 @@ testCrash:
707707
cmp #$31 ; gap
708708
bcs @continue
709709
lda #$F0
710-
sta crashFlag
711-
jmp @crashGraphics
710+
sta crashFlag ; F0 means standard crash.
711+
jmp @crashGraphics ;too far to branch
712712
@continue:
713713
cmp #$36
714714
bcc @nextSwitch
715715
cmp #$49
716-
bcs @nextSwitch
716+
bcs @nextSwitch ;between 7436 & 7448
717717
cmp #$43
718-
bcc @notRed
719-
cpx #$07
720-
beq @nextSwitch
718+
bcc @notRed ;checking if crash is during first crashable instruction
719+
cpx #$07 ; checking which switch routine is active.
720+
beq @nextSwitch ;continues crashless if sw2
721721
cpx #$03
722-
bne @notRed
723-
ldx #$FF
722+
bne @notRed ; runs graphics corruption if sw6
723+
ldx #$FF ; these are normally set by the code it would jump to after NMI.
724724
ldy #$00
725-
lda #$81
725+
lda #$81 ; value normally held at this point in sw6
726726
jsr satanSpawn
727-
jmp @allegroClear
727+
jmp @allegroClear ;allegroClear is basically return, just clears the variable first.
728728
@notRed:
729729
lda #$F0
730730
sta crashFlag
731-
jmp @crashGraphics
731+
jmp @crashGraphics ;triggering crash in all other cases
732732

733733
@nextSwitch:
734734
lda switchTable-2,x ; adding cycles to advance to next switch routine
735-
sta allegroIndex
735+
sta allegroIndex ; reusing code at the beginning of the loop that added the accumulated allegroIndex to the main cycle count
736736
dex
737737
bne @loop
738738
;562 has been added to the cycle count
739739
;confettiA at 30405-30754 76C5-7822
740740
lda displayNextPiece
741741
beq @nextOn
742-
lda cycleCount+1 ; add 394 cycles for nextbox if not added earlier
742+
lda cycleCount+1 ; add 394 cycles for nextbox if not added earlier. Necessary because we're checking for pre-nextbox NMI now.
743743
adc #$8A
744744
sta cycleCount+1
745745
lda cycleCount
746746
adc #$01 ; high byte of 18A
747747
sta cycleCount
748748
bne @nextCheck
749749
@nextOn:
750-
lda cycleCount
751-
cmp #$76
750+
lda cycleCount ;testing for limited confetti
751+
cmp #$76 ;high byte min
752752
bcc @allegroClear
753753
bne @not76
754754
lda cycleCount+1
755-
cmp #$C5
755+
cmp #$C5 ;low byte min
756756
bcc @allegroClear
757757
bcs @confettiA
758-
@not76: cmp #$78
758+
@not76: cmp #$78 ;high byte max
759759
bcc @confettiA
760760
bne @nextCheck
761761
lda cycleCount+1
762-
cmp #$23
762+
cmp #$23 ;low byte max
763763
bcs @nextCheck
764764
@confettiA:
765-
lda #$E0
765+
lda #$E0 ;E0 = limited confetti
766766
sta crashFlag
767767
jmp confettiHandler
768768
@nextCheck:
769-
;levellag at 30877 789D
769+
;levellag at 30877 = 0x789D
770770
lda cycleCount
771-
cmp #$78
771+
cmp #$78 ;high byte min
772772
bcc @allegroClear
773773
bne @levelLag
774774
lda cycleCount+1
775-
cmp #$9D
775+
cmp #$9D;low byte min
776776
bcc @allegroClear
777777
@levelLag:
778778
lda #$01
779779
sta lagFlag
780-
;linelag at 31072 7960
780+
;linelag at 31072 = 0x7960
781781
lda cycleCount
782-
cmp #$79
782+
cmp #$79;high byte min
783783
bcc @allegroClear
784784
bne @lineLag
785785
lda cycleCount+1
786-
cmp #$60
786+
cmp #$60;low byte min
787787
bcc @allegroClear
788788
@lineLag:
789789
lda #$03
790790
sta lagFlag
791791
;confettiB at 31327-31755 7A5F-7C0B
792792
lda cycleCount
793-
cmp #$7A
793+
cmp #$7A ;high byte min
794794
bcc @allegroClear
795795
bne @not7A
796796
lda cycleCount+1
797-
cmp #$5F
797+
cmp #$5F ;low byte min
798798
bcc @allegroClear
799799
bcs @confettiB
800-
@not7A: cmp #$7C
800+
@not7A: cmp #$7C ;high byte max
801801
bcc @confettiB
802802
bne @allegroClear
803803
lda cycleCount+1
804-
cmp #$0C
804+
cmp #$0C ;low byte max
805805
bcs @allegroClear
806806
@confettiB:
807-
lda #$D0
807+
lda #$D0 ;D0 = infinite confetti
808808
sta crashFlag
809809
jmp confettiHandler
810810
@allegroClear:
811-
lda #$00
811+
lda #$00 ;reset allegro flag and return to program execution, no crash
812812
sta allegroIndex
813813
lda lagFlag
814-
beq @noLag
814+
beq @noLag ;if lag should happen, wait a frame here so that sprite staging doesn't happen.
815815
lda #$00
816816
sta verticalBlankingInterval
817817
@checkForNmi:
818-
lda verticalBlankingInterval
818+
lda verticalBlankingInterval ;busyloop
819819
beq @checkForNmi
820820
@noLag: rts
821821
@crashGraphics:
822822
lda #$00
823-
sta allegroIndex
823+
sta allegroIndex ; resetting variable
824824
lda crashMode
825825
bne @otherMode
826-
lda outOfDateRenderFlags
826+
lda outOfDateRenderFlags ; if mode = 0, tell score to update (might not be necessary?) so that crash info is printed
827827
ora #$04
828828
sta outOfDateRenderFlags
829829
lda #$02
830-
sta soundEffectSlot0Init
830+
sta soundEffectSlot0Init ; play topout sfx
831831
rts
832832
@otherMode:
833-
cmp #CRASH_CRASH
833+
cmp #CRASH_CRASH ;if crash mode, crash
834834
bcc @topout
835835
bne @allegroClear
836-
.byte 02
836+
.byte 02 ; stp
837837
@topout:
838-
lda #LINECAP_HALT
838+
lda #LINECAP_HALT ;if topout, activate linecap
839839
sta linecapState
840840
rts
841841
factorTable:
842-
.byte $53, $88, $7D, $7D, $7D
842+
.byte $53, $88, $7D, $7D, $7D ;0 single double triple tetris
843843
sumTable:
844-
.byte $E1, $1C, $38, $54, $80 ; tetris is 4*28+16 = 128
844+
.byte $E1, $1C, $38, $54, $80 ; 0 single double triple tetris. tetris is 4*28+16 = 128
845845
switchTable:
846846
.byte $3C, $77, $3C, $65, $3C, $66, $3C;60 119 60 101 60 102 60 gets read in reverse
847847
confettiHandler:
@@ -851,35 +851,35 @@ confettiHandler:
851851
lda heldButtons_player1
852852
and #$A0 ; A, Select
853853
bne @endConfetti
854-
lda frameCounter
854+
lda frameCounter ;use framecounter for Y coordinate of text, like original confetti but without the offset
855855
cmp #$FF
856856
bne @drawConfetti
857857
lda heldButtons_player1
858858
and #$47 ; B, Down, Left, Right
859859
beq @endConfetti
860860
@drawConfetti:
861-
sta spriteYOffset
862-
lda #$A8
861+
sta spriteYOffset ;either frameCounter or 80 loaded to A depending on confetti type
862+
lda #$A8 ;center of playfield
863863
sta spriteXOffset
864-
lda #$19
864+
lda #$19 ;ID for "confetti" text
865865
sta spriteIndexInOamContentLookup
866-
jsr stringSpriteAlignRight
866+
jsr stringSpriteAlignRight ;draw to screen
867867
lda #$00
868-
sta verticalBlankingInterval
868+
sta verticalBlankingInterval ;wait until next frame
869869
@checkForNmi:
870-
lda verticalBlankingInterval
870+
lda verticalBlankingInterval ;busyloop
871871
beq @checkForNmi
872872
jmp confettiHandler
873873
@infiniteConfetti:
874874
lda heldButtons_player1
875-
adc #$80
875+
adc #$80 ; loading 80 as Y coordinate of confetti text if nothing is held.
876876
cmp #$80
877-
beq @drawConfetti
877+
beq @drawConfetti ; if any button is pressed, exit confetti
878878
@endConfetti:
879879
lda #$00
880880
sta allegroIndex
881881
rts
882-
satanSpawn:
882+
satanSpawn: ; copied from routine vanilla game's memset_ppu_page_and_more which is no longer present in gym
883883
sta tmp1
884884
stx tmp2
885885
sty tmp3

0 commit comments

Comments
 (0)