@@ -463,12 +463,12 @@ calcBCDLinesAndTileQueue:
463
463
@ret:
464
464
rts
465
465
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.
467
467
sta cycleCount
468
468
lda #$6F
469
469
sta cycleCount+1 ;low byte at +1
470
470
471
- lda completedLines
471
+ lda completedLines ; checking if lines cleared
472
472
beq @linesNotCleared
473
473
ldx #$04 ;setting loop to run 4x
474
474
@clearedLine:
@@ -490,7 +490,7 @@ testCrash:
490
490
bne @clearedLine
491
491
492
492
@linesNotCleared:
493
- lda displayNextPiece
493
+ lda displayNextPiece ;00 is nextbox enabled
494
494
bne @nextOff
495
495
lda #$8A ; add 394 cycles for nextbox
496
496
adc cycleCount+1
@@ -504,7 +504,7 @@ testCrash:
504
504
bne @allegro
505
505
lda #$95 ; 149 in decimal.
506
506
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
508
508
beq @addMusicCycles
509
509
adc #$26 ;add 38 cycles for disabling allegro
510
510
@addMusicCycles:
@@ -520,7 +520,7 @@ testCrash:
520
520
asl
521
521
asl
522
522
asl
523
- asl ;multiply by 16
523
+ asl ;multiply by 16 cycles per cell checked
524
524
tax ; save low byte result
525
525
lda cycleCount
526
526
adc #$00 ; add high byte carry
@@ -555,14 +555,14 @@ testCrash:
555
555
lda crashFlag
556
556
and #$01
557
557
beq @digit2
558
- lda #$4F ; add 79 cycles for 10s place
558
+ lda #$4F ; add 79 cycles for lines 10s place
559
559
adc allegroIndex
560
560
sta allegroIndex
561
561
@digit2:
562
562
lda crashFlag
563
563
and #$02
564
564
beq @clearStats
565
- lda #$0C ; add 12 cycles for 100s place
565
+ lda #$0C ; add 12 cycles for lines 100s place
566
566
adc allegroIndex
567
567
sta allegroIndex
568
568
@clearStats:
@@ -585,7 +585,7 @@ testCrash:
585
585
bcc @single
586
586
cmp #$08
587
587
bcs @over7
588
- lda #$09 ; 1-6 costs 9
588
+ lda #$09 ; 1-6 pushdown costs 9 add'l cycles
589
589
adc allegroIndex
590
590
sta allegroIndex
591
591
@over7:
@@ -627,7 +627,7 @@ testCrash:
627
627
sta factorA24+2
628
628
sta factorB24+1
629
629
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.
631
631
jsr unsigned_mul24 ; result in product24
632
632
clc
633
633
lda product24
@@ -650,10 +650,10 @@ testCrash:
650
650
cmp #$08
651
651
bne @not8
652
652
clc
653
- adc allegroIndex
653
+ adc allegroIndex ; adds 8 cycles for current piece = 8 (horizontal Z)
654
654
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
657
657
adc allegroIndex
658
658
sta allegroIndex
659
659
@randomFactors:
@@ -672,13 +672,13 @@ testCrash:
672
672
@newBit0:
673
673
lda nmiReturnAddr
674
674
cmp #<updateAudioWaitForNmiAndResetOamStaging+10
675
- beq @returnLate ; checking which instruction returned to
675
+ beq @returnLate ; checking which instruction returned to. if so, add 3 cycles
676
676
lda #$03
677
677
clc
678
678
adc allegroIndex
679
679
sta allegroIndex
680
680
@returnLate:
681
- lda rng_seed+1 ; RNG for OAMDMA
681
+ lda rng_seed+1 ; RNG for OAMDMA, add 1 cycle for syncing
682
682
lsr
683
683
bcc @noDMA
684
684
inc allegroIndex
@@ -707,141 +707,141 @@ testCrash:
707
707
cmp #$31 ; gap
708
708
bcs @continue
709
709
lda #$F0
710
- sta crashFlag
711
- jmp @crashGraphics
710
+ sta crashFlag ; F0 means standard crash.
711
+ jmp @crashGraphics ;too far to branch
712
712
@continue:
713
713
cmp #$36
714
714
bcc @nextSwitch
715
715
cmp #$49
716
- bcs @nextSwitch
716
+ bcs @nextSwitch ;between 7436 & 7448
717
717
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
721
721
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.
724
724
ldy #$00
725
- lda #$81
725
+ lda #$81 ; value normally held at this point in sw6
726
726
jsr satanSpawn
727
- jmp @allegroClear
727
+ jmp @allegroClear ;allegroClear is basically return, just clears the variable first.
728
728
@notRed:
729
729
lda #$F0
730
730
sta crashFlag
731
- jmp @crashGraphics
731
+ jmp @crashGraphics ;triggering crash in all other cases
732
732
733
733
@nextSwitch:
734
734
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
736
736
dex
737
737
bne @loop
738
738
;562 has been added to the cycle count
739
739
;confettiA at 30405-30754 76C5-7822
740
740
lda displayNextPiece
741
741
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.
743
743
adc #$8A
744
744
sta cycleCount+1
745
745
lda cycleCount
746
746
adc #$01 ; high byte of 18A
747
747
sta cycleCount
748
748
bne @nextCheck
749
749
@nextOn:
750
- lda cycleCount
751
- cmp #$76
750
+ lda cycleCount ;testing for limited confetti
751
+ cmp #$76 ;high byte min
752
752
bcc @allegroClear
753
753
bne @not76
754
754
lda cycleCount+1
755
- cmp #$C5
755
+ cmp #$C5 ;low byte min
756
756
bcc @allegroClear
757
757
bcs @confettiA
758
- @not76: cmp #$78
758
+ @not76: cmp #$78 ;high byte max
759
759
bcc @confettiA
760
760
bne @nextCheck
761
761
lda cycleCount+1
762
- cmp #$23
762
+ cmp #$23 ;low byte max
763
763
bcs @nextCheck
764
764
@confettiA:
765
- lda #$E0
765
+ lda #$E0 ;E0 = limited confetti
766
766
sta crashFlag
767
767
jmp confettiHandler
768
768
@nextCheck:
769
- ;levellag at 30877 789D
769
+ ;levellag at 30877 = 0x789D
770
770
lda cycleCount
771
- cmp #$78
771
+ cmp #$78 ;high byte min
772
772
bcc @allegroClear
773
773
bne @levelLag
774
774
lda cycleCount+1
775
- cmp #$9D
775
+ cmp #$9D ;low byte min
776
776
bcc @allegroClear
777
777
@levelLag:
778
778
lda #$01
779
779
sta lagFlag
780
- ;linelag at 31072 7960
780
+ ;linelag at 31072 = 0x7960
781
781
lda cycleCount
782
- cmp #$79
782
+ cmp #$79 ;high byte min
783
783
bcc @allegroClear
784
784
bne @lineLag
785
785
lda cycleCount+1
786
- cmp #$60
786
+ cmp #$60 ;low byte min
787
787
bcc @allegroClear
788
788
@lineLag:
789
789
lda #$03
790
790
sta lagFlag
791
791
;confettiB at 31327-31755 7A5F-7C0B
792
792
lda cycleCount
793
- cmp #$7A
793
+ cmp #$7A ;high byte min
794
794
bcc @allegroClear
795
795
bne @not7A
796
796
lda cycleCount+1
797
- cmp #$5F
797
+ cmp #$5F ;low byte min
798
798
bcc @allegroClear
799
799
bcs @confettiB
800
- @not7A: cmp #$7C
800
+ @not7A: cmp #$7C ;high byte max
801
801
bcc @confettiB
802
802
bne @allegroClear
803
803
lda cycleCount+1
804
- cmp #$0C
804
+ cmp #$0C ;low byte max
805
805
bcs @allegroClear
806
806
@confettiB:
807
- lda #$D0
807
+ lda #$D0 ;D0 = infinite confetti
808
808
sta crashFlag
809
809
jmp confettiHandler
810
810
@allegroClear:
811
- lda #$00
811
+ lda #$00 ;reset allegro flag and return to program execution, no crash
812
812
sta allegroIndex
813
813
lda lagFlag
814
- beq @noLag
814
+ beq @noLag ;if lag should happen, wait a frame here so that sprite staging doesn't happen.
815
815
lda #$00
816
816
sta verticalBlankingInterval
817
817
@checkForNmi:
818
- lda verticalBlankingInterval
818
+ lda verticalBlankingInterval ;busyloop
819
819
beq @checkForNmi
820
820
@noLag: rts
821
821
@crashGraphics:
822
822
lda #$00
823
- sta allegroIndex
823
+ sta allegroIndex ; resetting variable
824
824
lda crashMode
825
825
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
827
827
ora #$04
828
828
sta outOfDateRenderFlags
829
829
lda #$02
830
- sta soundEffectSlot0Init
830
+ sta soundEffectSlot0Init ; play topout sfx
831
831
rts
832
832
@otherMode:
833
- cmp #CRASH_CRASH
833
+ cmp #CRASH_CRASH ;if crash mode, crash
834
834
bcc @topout
835
835
bne @allegroClear
836
- .byte 02
836
+ .byte 02 ; stp
837
837
@topout:
838
- lda #LINECAP_HALT
838
+ lda #LINECAP_HALT ;if topout, activate linecap
839
839
sta linecapState
840
840
rts
841
841
factorTable:
842
- .byte $53 , $88 , $7D , $7D , $7D
842
+ .byte $53 , $88 , $7D , $7D , $7D ;0 single double triple tetris
843
843
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
845
845
switchTable:
846
846
.byte $3C , $77 , $3C , $65 , $3C , $66 , $3C ;60 119 60 101 60 102 60 gets read in reverse
847
847
confettiHandler:
@@ -851,35 +851,35 @@ confettiHandler:
851
851
lda heldButtons_player1
852
852
and #$A0 ; A, Select
853
853
bne @endConfetti
854
- lda frameCounter
854
+ lda frameCounter ;use framecounter for Y coordinate of text, like original confetti but without the offset
855
855
cmp #$FF
856
856
bne @drawConfetti
857
857
lda heldButtons_player1
858
858
and #$47 ; B, Down, Left, Right
859
859
beq @endConfetti
860
860
@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
863
863
sta spriteXOffset
864
- lda #$19
864
+ lda #$19 ;ID for "confetti" text
865
865
sta spriteIndexInOamContentLookup
866
- jsr stringSpriteAlignRight
866
+ jsr stringSpriteAlignRight ;draw to screen
867
867
lda #$00
868
- sta verticalBlankingInterval
868
+ sta verticalBlankingInterval ;wait until next frame
869
869
@checkForNmi:
870
- lda verticalBlankingInterval
870
+ lda verticalBlankingInterval ;busyloop
871
871
beq @checkForNmi
872
872
jmp confettiHandler
873
873
@infiniteConfetti:
874
874
lda heldButtons_player1
875
- adc #$80
875
+ adc #$80 ; loading 80 as Y coordinate of confetti text if nothing is held.
876
876
cmp #$80
877
- beq @drawConfetti
877
+ beq @drawConfetti ; if any button is pressed, exit confetti
878
878
@endConfetti:
879
879
lda #$00
880
880
sta allegroIndex
881
881
rts
882
- satanSpawn:
882
+ satanSpawn: ; copied from routine vanilla game's memset_ppu_page_and_more which is no longer present in gym
883
883
sta tmp1
884
884
stx tmp2
885
885
sty tmp3
0 commit comments