Remove set flag instruction to optimize circledraw from 5846 to 5640 cpu cycles

This commit is contained in:
hugova 2025-06-29 10:23:41 +02:00
parent b7f04d1fcb
commit c5b0d5f64b

View file

@ -32,7 +32,7 @@ draw_center_px_in_circle:
draw_right_px_in_circle: draw_right_px_in_circle:
CLC ;; C = 0, because Mult_16
LDA X_pos LDA X_pos
ADC radius ADC radius
STA X_pos STA X_pos
@ -41,6 +41,7 @@ draw_right_px_in_circle:
JSR pixel_draw JSR pixel_draw
;; This sets byte_to_paint, btp_mem_pos and Y ;; This sets byte_to_paint, btp_mem_pos and Y
SEC ;; See draw_pixel_inv
while_x_bigger_then_y: while_x_bigger_then_y:
@ -50,7 +51,7 @@ draw_pixel:
STA (btp_mem_pos), Y STA (btp_mem_pos), Y
draw_pixel_inv: draw_pixel_inv:
SEC ;;C = 1 beacause the branching to while_x_bigger_then_y and SEC on first ittteration.
LDA btp_mem_pos_center_two LDA btp_mem_pos_center_two
SBC btp_mem_pos SBC btp_mem_pos
STA btp_mem_pos_inv STA btp_mem_pos_inv
@ -61,23 +62,23 @@ draw_pixel_inv:
;; calculate the inverted y value Y = 7-Y ;; calculate the inverted y value Y = 7-Y
STY temp STY temp
LDA #$07 LDA #$07
SEC ;; C = 1 because arithmatic above
SBC temp SBC temp
TAY TAY
;; calculate byte_to_paint_inv 00000001 --> 10000000, 00000010 --> 01000000 ... etc ;; calculate byte_to_paint_inv 00000001 --> 10000000, 00000010 --> 01000000 ... etc
;; uses a table! ;; uses a table!
stx temp_ STX temp_
ldx byte_to_paint LDX byte_to_paint
LDA inverse_factor_value, X;; (see END.s) LDA inverse_factor_value, X;; (see END.s)
ldx temp_ LDX temp_
; A = byte_to_paint_inv ; A = byte_to_paint_inv
ORA (btp_mem_pos_inv), Y ORA (btp_mem_pos_inv), Y
STA (btp_mem_pos_inv), Y STA (btp_mem_pos_inv), Y
;;Recover the Y value (we changed it because evrything is inverted) ;;Recover the Y value (we changed it because evrything is inverted)
ldy temp LDY temp
increment_y_pos: increment_y_pos:
INC Y_rel ; y++ INC Y_rel ; y++
@ -88,8 +89,9 @@ increment_y_pos:
move_8px_down: move_8px_down:
LDY #$00 LDY #$00
;; Switch to chunk bellow ;; Switch to chunk bellow
; So we subtract #$4000 ; So we subtract #$4001
Add_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01 ;+320 ; C = 1 because branching!
Add_16 btp_mem_pos, btp_mem_pos + 1, #$3F, #$01, ! ;+320
increment_y_pos_end: increment_y_pos_end:
;;t1 += y ;;t1 += y
@ -113,7 +115,8 @@ decrement_x_pos:
move_8px_left: move_8px_left:
;; Next chunk is 8 addresses away. Look in pixel_draw for more detail. ;; Next chunk is 8 addresses away. Look in pixel_draw for more detail.
;; -8. ;; -8.
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$08, #$00 ;; C = 1 because branching
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$08, #$00, !
;; Restores byte to paint ;; Restores byte to paint
LDA #%00000001 LDA #%00000001
STA byte_to_paint STA byte_to_paint