Skip to content

Commit 58373f0

Browse files
committed
optimized crunch with crash mode accommodated
1 parent b499e7e commit 58373f0

File tree

4 files changed

+70
-57
lines changed

4 files changed

+70
-57
lines changed

src/modes/crunch.asm

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,66 @@
1717
; F - 3 left 3 right
1818

1919
advanceGameCrunch:
20-
lda #0
21-
sta vramRow
22-
lda #20
23-
advanceSides:
24-
pha
25-
sta tmp3
20+
; initialize vars
2621
lda crunchModifier
27-
lsr a
28-
lsr a
29-
ldx #0
30-
jsr advanceSide
31-
pla
32-
sta tmp3
22+
lsr
23+
lsr
24+
sta crunchLeftColumns
3325
lda crunchModifier
34-
and #%00000011
35-
pha
36-
eor #$FF
37-
sec
38-
adc #0
26+
and #$03
3927
clc
40-
adc #10
41-
tax
42-
pla
43-
jsr advanceSide
28+
adc crunchLeftColumns ; carry still clear
29+
eor #$FF
30+
adc #$0B ; 10 + 1 to get two's complement. result is playable column count
31+
sta crunchClearColumns
32+
33+
; initialize playfield row 19 to 0
34+
lda #$13
35+
sta generalCounter
36+
@nextRow:
37+
jsr advanceSidesInit
38+
dec generalCounter
39+
bpl @nextRow
40+
41+
; restore playfieldAddr and set vramRow for rendering
42+
lda #$00
43+
sta vramRow
44+
sta playfieldAddr
45+
crunchReturn:
4446
rts
4547

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:
48+
; for init only. row determined by generalCounter
49+
advanceSidesInit:
50+
ldy generalCounter
51+
lda multBy10Table,y
52+
sta playfieldAddr
53+
54+
; after init, only top row is drawn. using (playfieldAddr),y defaults to top row
55+
; as playfieldAddr is 0 when this is called (and most of the time)
56+
advanceSides:
57+
ldy #$00
6358
lda #BLOCK_TILES
64-
sta (tmp1), y
65-
inc tmp1
59+
60+
; x controls left tile count. x can start at 0,1,2 or 3.
61+
ldx crunchLeftColumns
62+
@leftLoop:
6663
dex
67-
bne @blockLoop
68-
pla
69-
pha
70-
eor #$FF
71-
sec
72-
adc #0
73-
clc
74-
adc tmp1
64+
bmi @right
65+
sta (playfieldAddr),y
66+
iny
67+
bne @leftLoop ; unconditional
68+
69+
@right:
70+
tya
7571
clc
76-
adc #10
77-
sta tmp1
78-
dec tmp3
79-
bne @rowLoop
80-
pla
81-
@end:
82-
rts
72+
adc crunchClearColumns
73+
tay
74+
lda #BLOCK_TILES
75+
76+
; y is replaced with crunchClearColumns + y and increments until y == 10. y can start at 7,8,9 or 10.
77+
@rightLoop:
78+
cpy #$0A
79+
beq crunchReturn
80+
sta (playfieldAddr),y
81+
iny
82+
bne @rightLoop ; unconditional

src/playstate/completedrows.asm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ playState_checkForCompletedRows:
144144
lda practiseType
145145
cmp #MODE_CRUNCH
146146
bne @crunchEnd
147-
lda #1
148147
jsr advanceSides
149148
@crunchEnd:
150149

src/playstate/util.asm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ updateMusicSpeed:
8181
ldx #$05
8282
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.
8383
tay
84+
85+
; check if crunch mode
86+
lda practiseType
87+
cmp #MODE_CRUNCH
88+
bne @notCrunch
89+
90+
; start at first clear column and repeat only for playable columns
91+
ldy crunchLeftColumns
92+
ldx crunchClearColumns
93+
bne @checkForBlockInRow ; unconditional, expected range 4 - 10
94+
95+
@notCrunch:
8496
ldx #$0A
8597
@checkForBlockInRow:
8698
lda (playfieldAddr),y

src/ram.asm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ dasOnlyShiftDisabled: .res 1 ; $63A
220220
invisibleFlag: .res 1 ; $63B ; 0 for normal mode, non-zero for Invisible playfield rendering. Reset on game init and game over.
221221
currentFloor: .res 1 ; $63C floorModifier is copied here at game init. Set to 0 otherwise and incremented when linecap floor.
222222
mapperId: .res 1 ; $63D ; For INES_MAPPER 1000 (autodetect). 0 = CNROM. 1 = MMC1.
223+
crunchLeftColumns: .res 1
224+
crunchClearColumns: .res 1 ; playable column count
223225

224-
.res $37
226+
.res $35
225227

226228
.if KEYBOARD
227229
newlyPressedKeys: .res 1 ; $0675

0 commit comments

Comments
 (0)