From c8d7d6039963ca84d74a42233a1524d1a98836f7 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 4 Nov 2022 00:40:43 -0400 Subject: Micro-optimization: Self-modifying code! --- dla.s | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/dla.s b/dla.s index 4b2be32..4b861f8 100644 --- a/dla.s +++ b/dla.s @@ -380,13 +380,13 @@ jsaveimage: set_limits: ldx circlesize lda xmin,x - sta min_x + sta selfmod_xmin lda ymin,x - sta min_y + sta selfmod_ymin lda xmax,x - sta max_x + sta selfmod_xmax lda ymax,x - sta max_y + sta selfmod_ymax rts ;;; Subroutine: initscreen @@ -526,16 +526,21 @@ right: inc part_x ;3 checkbounds: + ; all the "cmp #0" here get their operands modified by set_limits. lda part_x - cmp min_x +selfmod_xmin = * + 1 + cmp #0 beq oob - cmp max_x +selfmod_xmax = * + 1 + cmp #0 beq oob ;sta cursor_x lda part_y - cmp min_y +selfmod_ymin = * + 1 + cmp #0 beq oob - cmp max_y +selfmod_ymax = * + 1 + cmp #0 beq oob ;sta cursor_y ; checkbounds is 30 cycles when the pixel is in bounds. @@ -573,12 +578,23 @@ slow_x: bne stick check_y: ; (0,-1) +.if 0 ldx part_y ;3 lda lineaddrs_l-1,x ;5 sta pixptr ;3 lda lineaddrs_h-1,x ;5 sta pixptr+1 ;3 ;=19 +.else + lda pixptr ; 3 + sec ; 2 + sbc #$20 ; 2 + sta pixptr ; 3 + bcs pp1ok ; 3|2 + dec pixptr+1 ; 0|5 + ; =13|17 (avg closer to 13) +pp1ok: +.endif ldx part_x ldy xoffsets,x lda xmasks,x @@ -594,7 +610,7 @@ check_y: bne stick jmp drunkwalk ; too far for a branch -stick: +stick: ; we always get here with Z flag clear rts ;;; Subroutine: drawseed -- cgit v1.2.3