From b86815613888c8d1c6495db79a1f5285f6f42f95 Mon Sep 17 00:00:00 2001 From: hugova Date: Thu, 10 Jul 2025 16:28:17 +0200 Subject: [PATCH] reduse zeropage usage of circle-draw --- wip-hugo/routines/circle/circle.inc | 41 +++++++++++++---------------- wip-hugo/routines/circle/circle.s | 22 ++++++++-------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/wip-hugo/routines/circle/circle.inc b/wip-hugo/routines/circle/circle.inc index 9495d4e..6e1c76a 100644 --- a/wip-hugo/routines/circle/circle.inc +++ b/wip-hugo/routines/circle/circle.inc @@ -6,34 +6,29 @@ ;; private args t1 = $E0 t2 = $E1 - X_rel = radius - Y_rel = $E2 - Y_copy = $E3 - temp_ = $ED - jmp_location_pointer_two = $E4 ;16bit value (uses E5) - jmp_location_pointer = $EE ;16 bit value (uses EF) + X_math = radius + Y_math = $E2 + jmp_location_pointer_two = $E3 ;16-bit value (uses E4) + jmp_location_pointer = $E5 ;16-bit value (uses E6) + ;; E8 - EA is used by pixel.inc byte_to_paint_qaa = byte_to_paint byte_to_paint_qcb = $EB byte_to_paint_qca = $EC - - ; E8 - EA is used by pixel.inc - byte_to_paint_qdb = $CF - btp_mem_pos_center = $E6 - btp_mem_pos_center_two = btp_mem_pos_center + byte_to_paint_qdb = $ED btp_mem_pos_qaa = btp_mem_pos - btp_mem_pos_qcb = $D0 ; 16bit value (uses D1) - btp_mem_pos_qdb = $D2 ;16bit value (uses D3) - btp_mem_pos_qda =$D4 ; 16bit value (uses D5) - - ;;mirrord - btp_mem_pos_qab = $D6 - btp_mem_pos_qca = $D8 - btp_mem_pos_qba = $DA - btp_mem_pos_qbb = $DC + btp_mem_pos_qcb = $D0 ; 16bit value (uses D1) + btp_mem_pos_qdb = $D2 ; 16bit value (uses D3) + btp_mem_pos_qda = $D4 ; 16bit value (uses D5) + btp_mem_pos_qab = $D6 ; 16bit value (uses D7) + btp_mem_pos_qca = $D8 ; 16bit value (uses D9) + btp_mem_pos_qba = $DA ; 16bit value (uses DB) + btp_mem_pos_qbb = $DC ; 16bit value (uses DD) Y_qda = $DE Y_qdb = $DF - Y_qbb = $CE - temp__ = $CD - Y_qaa = Y_copy + Y_qbb = $E7 ;; <-- we use E7 here! + Y_qaa = $C0 + ;;Reuse addresses, be carful here! + temp__ = Y_qaa + temp_ = Y_qda diff --git a/wip-hugo/routines/circle/circle.s b/wip-hugo/routines/circle/circle.s index 7a57b0b..50573ad 100644 --- a/wip-hugo/routines/circle/circle.s +++ b/wip-hugo/routines/circle/circle.s @@ -35,10 +35,10 @@ STA jmp_location_pointer_two + 1 - ;; X_rel = radius (share the same address) - ;;Y_rel =0 + ;; X_math = radius (share the same address) + ;;Y_math =0 LDA #$00 - STA Y_rel + STA Y_math ;; t1 = radius >> 4 LDA radius @@ -94,7 +94,7 @@ draw_left_px_in_circle: ;similar as above LDA temp__ STA X_pos draw_lower_px_in_circle: ;similar as above - CLC + ;; C=0 becuase pixel draw! LDA Y_pos ADC radius STA Y_pos @@ -174,13 +174,13 @@ draw_qab: STA (btp_mem_pos_qab), Y -;; Y_rel and X_rel is the X and Y in the eye of the algorithm. Thsese are calculated seperatly from the pixel cordinates, +;; Y_math and X_math is the X and Y in the eye of the algorithm. Thsese are calculated seperatly from the pixel cordinates, ;; but are modified at the same time. This is becsuse the pixel cordinate system is complex (see pixel draw) LDY #$07 ;; Y is expected to be 7 from this point on in the loop change_Y: - INC Y_rel ; y++ + INC Y_math ; y++ qaa_y: DEC Y_qaa BPL qaa_y_end @@ -222,11 +222,11 @@ qcb_x_end: ;;t1 += y CLC LDA t1 - ADC Y_rel + ADC Y_math STA t1 ;; t2 = t1 - x SEC - SBC X_rel + SBC X_math STA t2 ;; if t2 < 0 then skip to endif ;; we can skipp CMP #$00 because SBC above do the same @@ -234,7 +234,7 @@ qcb_x_end: JMP (jmp_location_pointer_two) if: change_x: - DEC X_rel + DEC X_math LDA t2 STA t1 ; t1 = t2 qaa_x: @@ -279,8 +279,8 @@ qbb_y_end: endif: ;; repeat if X > Y - LDA X_rel - CMP Y_rel + LDA X_math + CMP Y_math BCC end JMP (jmp_location_pointer) end: