Skip to content

Commit 2e04484

Browse files
committed
save 20 bytes
1 parent 9312571 commit 2e04484

File tree

3 files changed

+42
-52
lines changed

3 files changed

+42
-52
lines changed

src/modes/crunch.asm

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,48 @@
1616
; E - 3 left 2 right
1717
; F - 3 left 3 right
1818

19-
; defined in playstate/completedrows.asm:
20-
; crunchLeftColumns = generalCounter3
21-
; crunchClearColumns = generalCounter4
19+
; clobbers generalCounter3 & generalCounter4 (defined in playstate/util.asm)
2220

2321
advanceGameCrunch:
24-
; populate vars
25-
jsr unpackCrunchModifier
2622
; initialize playfield row 19 to 0
27-
lda #$13
28-
sta generalCounter
23+
ldx #$13
2924
@nextRow:
30-
ldy generalCounter
31-
lda multBy10Table,y
32-
; playfieldAddr ends restored to 0 as top row is done last
33-
sta playfieldAddr
34-
jsr advanceSidesContinue
35-
dec generalCounter
25+
lda multBy10Table,x
26+
sta playfieldAddr ; restored to 0 at end of loop
27+
jsr advanceSides
28+
dex
3629
bpl @nextRow
37-
38-
; set vramRow to render entire playfield
39-
lda #$00
40-
sta vramRow
30+
inx ; x is FF, increase to store 0 in vramRow
31+
stx vramRow
4132
crunchReturn:
4233
rts
4334

4435
advanceSides:
45-
; called in playState_checkForCompletedRows
46-
; after init, only top row is drawn. using (playfieldAddr),y defaults to top row
47-
; as playfieldAddr is 0 when this is called (and most of the time)
36+
; called in playState_checkForCompletedRows and in advanceGameCrunch
37+
; draws to row defined in playfieldAddr, which defaults to 0
4838
jsr unpackCrunchModifier
4939

50-
advanceSidesContinue:
51-
ldy #$00
5240
lda #BLOCK_TILES
5341

54-
; x controls left tile count. x can start at 0,1,2 or 3.
55-
ldx crunchLeftColumns
42+
; y controls left tile count and offset into playfield
43+
ldy #$0
5644
@leftLoop:
57-
dex
58-
bmi @right
45+
dec crunchLeftColumns
46+
bmi @initRight
5947
sta (playfieldAddr),y
6048
iny
61-
bne @leftLoop ; unconditional
49+
bpl @leftLoop ; unconditional
6250

63-
@right:
64-
tya
65-
clc
66-
adc crunchClearColumns
67-
tay
68-
lda #BLOCK_TILES
69-
70-
; y is replaced with crunchClearColumns + y and increments until y == 10. y can start at 7,8,9 or 10.
51+
@initRight:
52+
ldy #$9
53+
; x controls right tile count, y controls offset into playfield
7154
@rightLoop:
72-
cpy #$0A
73-
beq crunchReturn
55+
dec crunchRightColumns
56+
bmi crunchReturn
7457
sta (playfieldAddr),y
75-
iny
76-
bne @rightLoop ; unconditional
58+
dey
59+
bpl @rightLoop ; unconditional
60+
7761

7862
unpackCrunchModifier:
7963
; initialize vars
@@ -83,9 +67,5 @@ unpackCrunchModifier:
8367
sta crunchLeftColumns ; generalCounter3
8468
lda crunchModifier
8569
and #$03
86-
clc
87-
adc crunchLeftColumns ; carry still clear
88-
eor #$FF
89-
adc #$0B ; 10 + 1 to get two's complement. result is playable column count
90-
sta crunchClearColumns ; generalCounter4
70+
sta crunchRightColumns ; generalCounter4
9171
rts

src/playstate/completedrows.asm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
crunchLeftColumns := generalCounter3
2-
crunchClearColumns := generalCounter4
31
activeFloorMode := generalCounter5
42

53
playState_checkForCompletedRows:
@@ -146,7 +144,7 @@ playState_checkForCompletedRows:
146144
lda practiseType
147145
cmp #MODE_CRUNCH
148146
bne @crunchEnd
149-
jsr advanceSides
147+
jsr advanceSides ; clobbers generalCounter3 and generalCounter4
150148
@crunchEnd:
151149

152150
lda completedLines

src/playstate/util.asm

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,35 @@ 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.
83-
tay
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
8490

8591
; check if crunch mode
8692
ldx practiseType
8793
cpx #MODE_CRUNCH
8894
bne @notCrunch
8995

90-
; start at first clear column and repeat only for playable columns
96+
; add crunch left columns to y
9197
jsr unpackCrunchModifier
9298
tya
9399
clc
94100
adc crunchLeftColumns ; offset y with left column count (generalCounter3)
95101
tay
96-
ldx crunchClearColumns ; generalCounter4
102+
103+
; set x to playable column count
104+
lda #$0A
105+
sec
106+
sbc crunchLeftColumns ; generalCounter3
107+
sbc crunchRightColumns ; generalCounter4
108+
tax
97109
bne @checkForBlockInRow ; unconditional, expected range 4 - 10
98110

99111
@notCrunch:

0 commit comments

Comments
 (0)