aboutsummaryrefslogtreecommitdiff
path: root/drunkwalk.s
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2022-11-08 03:07:04 -0500
committerB. Watson <urchlay@slackware.uk>2022-11-08 03:07:19 -0500
commit3d6abe38d72347d6b254070edb50cf56f236f5d7 (patch)
treeed204fb4b2e90caea36c102e00d0f50099fcdd45 /drunkwalk.s
parent8303d83efab1ee1135cf2396a792479966ed2303 (diff)
downloaddla-asm-3d6abe38d72347d6b254070edb50cf56f236f5d7.tar.gz
Add/fix comments, profiling for initscreen and render. Runtime ~3:05 now.
Diffstat (limited to 'drunkwalk.s')
-rw-r--r--drunkwalk.s41
1 files changed, 26 insertions, 15 deletions
diff --git a/drunkwalk.s b/drunkwalk.s
index 02ab67d..8cea4cf 100644
--- a/drunkwalk.s
+++ b/drunkwalk.s
@@ -1,11 +1,20 @@
;;; Subroutine: drunkwalk
-;;; Walk the point around randomly until it either is
-;;; adjacent to a set pixel or goes out of bounds.
-;;; Return with Z=0 if out of bounds, Z=1 if it hit a pixel.
+;;; Spawn a particle, walk it randomly until it's adjacent to a set
+;;; pixel, then draw it. If it goes out of bounds, start over (spawn
+;;; another).
;;; This is the innermost loop, so it should be as optimized as
;;; possible.
-; Y and X are backwards: Y holds the X coordinate, and X holds the Y coordinate.
-; Has to be, because there's no (zpind),x addressing mode.
+
+; Here be self-modifying code. All the 'cpx #0' and 'cpy #0' get
+; their operands modified by set_limits.
+
+; BEWARE!
+; Y and X are backwards: Y holds the X coordinate, and X holds the
+; Y coordinate. Has to be, because there's no (zpind),x addressing
+; mode.
+
+; TODO: Fix the cycle counts. I did them from my years-old memory, and
+; I got at least one wrong, after looking it up again.
drunkwalk:
oob:
@@ -24,29 +33,29 @@ oob:
move_pixel:
bit RANDOM ; 4 ; use top 2 bits (probably more random, definitely faster)
- bmi lr ; 2/3
- bvc down ; 2/3
+ bmi lr ; 3/4
+ bvc down ; 3/4
up:
dex ; 2 ; N=1 V=1 up
selfmod_ymin = * + 1
cpx #0 ; 2
- beq oob ; 2
+ beq oob ; 3
stx cursor_y
jmp check_lru
down:
inx ; 2 ; N=1 V=0 down
selfmod_ymax = * + 1
cpx #0 ; 2
- beq oob ; 2
+ beq oob ; 3
stx cursor_y
jmp check_lrd
lr:
- bvc right ; 2/3
+ bvc right ; 3/4
left:
dey ; 3 ; N=0 V=1 left
selfmod_xmin = * + 1
cpy #0 ; 2
- beq oob ; 2
+ beq oob ; 3
sty cursor_x
; check left neighbor (we just vacated the right one)
dey
@@ -58,7 +67,7 @@ right:
iny ; 3 ; N=0 V=0 right
selfmod_xmax = * + 1
cpy #0 ; 2
- beq oob ; 2
+ beq oob ; 3
sty cursor_x
; check right neighbor (we just vacated the left one)
iny
@@ -83,9 +92,10 @@ check_ud:
sta pixptr2+1
lda (pixptr2),y
bne stick
- jmp move_pixel
+ jmp move_pixel ; pixel didn't stick, move it again.
check_lru:
+ ; pixel's Y coord changed, must update pointer.
lda lineaddrs_l,x ; 5
sta pixptr ; 3
lda lineaddrs_h,x ; 5
@@ -108,9 +118,10 @@ check_lru:
sta pixptr2+1
lda (pixptr2),y
bne stick
- jmp move_pixel
+ jmp move_pixel ; pixel didn't stick, move it again.
check_lrd:
+ ; pixel's Y coord changed, must update pointer.
lda lineaddrs_l,x ; 5
sta pixptr ; 3
lda lineaddrs_h,x ; 5
@@ -133,7 +144,7 @@ check_lrd:
sta pixptr2+1
lda (pixptr2),y
bne stick
- jmp move_pixel
+ jmp move_pixel ; pixel didn't stick, move it again.
stick:
; pixel stuck next to an existing pixel, draw it and return.