Skip to content

Commit 3e93562

Browse files
Merge pull request #120 from zohassadar/optimized_crunch
optimized crunch with crash mode accommodated
2 parents 303a93f + 2f04da6 commit 3e93562

File tree

3 files changed

+76
-63
lines changed

3 files changed

+76
-63
lines changed

src/modes/crunch.asm

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,53 @@
1616
; E - 3 left 2 right
1717
; F - 3 left 3 right
1818

19+
; clobbers generalCounter3 & generalCounter4 (defined in playstate/util.asm)
20+
1921
advanceGameCrunch:
20-
lda #0
21-
sta vramRow
22-
lda #20
23-
advanceSides:
24-
pha
25-
sta tmp3
26-
lda crunchModifier
27-
lsr a
28-
lsr a
29-
ldx #0
30-
jsr advanceSide
31-
pla
32-
sta tmp3
33-
lda crunchModifier
34-
and #%00000011
35-
pha
36-
eor #$FF
37-
sec
38-
adc #0
39-
clc
40-
adc #10
41-
tax
42-
pla
43-
jsr advanceSide
22+
; initialize playfield row 19 to 0
23+
ldx #$13
24+
@nextRow:
25+
lda multBy10Table,x
26+
sta playfieldAddr ; restored to 0 at end of loop
27+
jsr advanceSides
28+
dex
29+
bpl @nextRow
30+
inx ; x is FF, increase to store 0 in vramRow
31+
stx vramRow
32+
crunchReturn:
4433
rts
4534

46-
advanceSide:
47-
cmp #0
48-
beq @end
49-
pha
50-
ldy #0
51-
txa
52-
clc
53-
adc #<playfield
54-
sta tmp1
55-
lda #>playfield
56-
sta tmp2
57-
@rowLoop:
58-
pla
59-
pha
60-
tax
61-
beq @end
62-
@blockLoop:
35+
advanceSides:
36+
; called in playState_checkForCompletedRows and in advanceGameCrunch
37+
; draws to row defined in playfieldAddr, which defaults to 0
38+
jsr unpackCrunchModifier
39+
6340
lda #BLOCK_TILES
64-
sta (tmp1), y
65-
inc tmp1
66-
dex
67-
bne @blockLoop
68-
pla
69-
pha
70-
eor #$FF
71-
sec
72-
adc #0
73-
clc
74-
adc tmp1
75-
clc
76-
adc #10
77-
sta tmp1
78-
dec tmp3
79-
bne @rowLoop
80-
pla
81-
@end:
41+
42+
ldy #$0
43+
@leftLoop:
44+
dec crunchLeftColumns
45+
bmi @initRight
46+
sta (playfieldAddr),y
47+
iny
48+
bpl @leftLoop ; unconditional
49+
50+
@initRight:
51+
ldy #$9
52+
@rightLoop:
53+
dec crunchRightColumns
54+
bmi crunchReturn
55+
sta (playfieldAddr),y
56+
dey
57+
bpl @rightLoop ; unconditional
58+
59+
60+
unpackCrunchModifier:
61+
lda crunchModifier
62+
lsr
63+
lsr
64+
sta crunchLeftColumns ; generalCounter3
65+
lda crunchModifier
66+
and #$03
67+
sta crunchRightColumns ; generalCounter4
8268
rts

src/playstate/completedrows.asm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ playState_checkForCompletedRows:
144144
lda practiseType
145145
cmp #MODE_CRUNCH
146146
bne @crunchEnd
147-
lda #1
148-
jsr advanceSides
147+
jsr advanceSides ; clobbers generalCounter3 and generalCounter4
149148
@crunchEnd:
150149

151150
lda completedLines

src/playstate/util.asm

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,38 @@ updatePlayfield:
7777
sta vramRow
7878
@ret: rts
7979

80+
crunchLeftColumns = generalCounter3
81+
crunchRightColumns = generalCounter4
82+
8083
updateMusicSpeed:
81-
ldx #$05
82-
lda multBy10Table,x ;this piece of code is parameterized for no reason but the crash checking code relies on the index being 50-59 so if you ever optimize this part out of the code please also adjust the crash test, specifically the part which handles cycles for allegro.
84+
85+
; ldx #$05
86+
; lda multBy10Table,x ;this piece of code is parameterized for no reason but the crash checking code relies on the index being 50-59 so if you ever optimize this part out of the code please also adjust the crash test, specifically the part which handles cycles for allegro.
87+
; tay
88+
89+
ldy #50 ; replaces above
90+
91+
; check if crunch mode
92+
ldx practiseType
93+
cpx #MODE_CRUNCH
94+
bne @notCrunch
95+
96+
; add crunch left columns to y
97+
jsr unpackCrunchModifier
98+
tya
99+
clc
100+
adc crunchLeftColumns ; offset y with left column count (generalCounter3)
83101
tay
102+
103+
; set x to playable column count
104+
lda #$0A
105+
sec
106+
sbc crunchLeftColumns ; generalCounter3
107+
sbc crunchRightColumns ; generalCounter4
108+
tax
109+
bne @checkForBlockInRow ; unconditional, expected range 4 - 10
110+
111+
@notCrunch:
84112
ldx #$0A
85113
@checkForBlockInRow:
86114
lda (playfieldAddr),y

0 commit comments

Comments
 (0)