aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2022-10-25 05:04:07 -0400
committerB. Watson <urchlay@slackware.uk>2022-10-25 05:04:07 -0400
commit7a3031ddfc191b70fd5c241716952accf8fc2e78 (patch)
tree142d6df80e85b5d89b9919e52567b711c463738e
parent8088993af2f38f33a134f15f50e80a3a56115006 (diff)
downloaddla-asm-7a3031ddfc191b70fd5c241716952accf8fc2e78.tar.gz
Micro-optimizations
-rw-r--r--dla.s53
1 files changed, 23 insertions, 30 deletions
diff --git a/dla.s b/dla.s
index 691387f..1886944 100644
--- a/dla.s
+++ b/dla.s
@@ -502,28 +502,27 @@ spawn:
;;; This is the innermost loop, so it should be as optimized as
;;; possible (we're not there yet).
drunkwalk:
- lda RANDOM ; pick a random direction, up/down/left/right
- and #$C0 ; use top 2 bits (hopefully more random than bottom 2).
- cmp #$C0
- beq up
- cmp #$80
- beq down
- cmp #$40
- beq left
- ; $00: right
- inc part_x
- bne checkbounds
-up:
- dec part_y
- bne checkbounds
+ ; using bit/bmi/bvc saves 6.25 cycles on average, compared to
+ ; immediate cmp and bne.
+ ; 4 code paths: up=14, down=15, left=15, right=13, avg=14.25
+ bit RANDOM ;4 ; use top 2 bits (probably more random, definitely faster)
+ bmi lr ;2/3
+ bvc down ;2/3
+ dec part_y ;3 ; N=1 V=1 up
+ bne checkbounds ;3
down:
- inc part_y
- bne checkbounds
-left:
- dec part_x
+ inc part_y ;3 ; N=1 V=0 down
+ bne checkbounds ;3
+lr:
+ bvc right ;2/3
+ dec part_x ;3 ; N=0 V=1 left
+ bne checkbounds ;3
+right:
+ inc part_x ;3
checkbounds:
lda part_x
+ sta cursor_x
cmp min_x
beq oob
cmp max_x
@@ -534,10 +533,8 @@ checkbounds:
cmp max_y
beq oob
- lda part_x
- sta cursor_x
- lda part_y
sta cursor_y
+
ldx #0
lda CONSOL
cmp #6
@@ -556,23 +553,19 @@ dontplot:
and (pixptr),y
bne stick
; (1,0)
- inc cursor_x
- inc cursor_x
- jsr plotsetup
+ inx
+ stx cursor_x
+ inx
+ ldy xoffsets,x
+ lda xmasks,x
and (pixptr),y
bne stick
; (0,-1)
- dec cursor_x
dec cursor_y
jsr plotsetup
and (pixptr),y
bne stick
; (0,1)
- ; used to:
- ;inc cursor_y
- ;inc cursor_y
- ;jsr locate
- ; this avoids recalculating the pointer:
tya
ora #$40 ; add 64
tay