From eff01e5411f90a2cfe7b2861adadc171e6ed4b35 Mon Sep 17 00:00:00 2001 From: hugova Date: Fri, 1 Aug 2025 19:24:40 +0200 Subject: [PATCH] make circle draw not write over program mem. --- host/src/routines/circle/circle.s | 13 +++++++++++++ host/src/routines/circle/circle_test_position.s | 4 ++-- host/src/routines/circle/circle_test_size.s | 2 +- host/src/test.s | 12 ++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/host/src/routines/circle/circle.s b/host/src/routines/circle/circle.s index 81428b5..e58b3b3 100644 --- a/host/src/routines/circle/circle.s +++ b/host/src/routines/circle/circle.s @@ -45,6 +45,8 @@ draw_upper_px_in_circle: SBC radius STA Y_pos + BCC outside_screen_error + JSR pixel_calc ;; A = byte_to_paint (small_X_offset) ;; Y =small_y_offset @@ -93,6 +95,11 @@ draw_lower_px_in_circle: ;similar as above ADC radius STA Y_pos + ;; Stop this if overflow or if outside screen. + BCS outside_screen_error + CMP #$C8 ;; Screen width + BCS outside_screen_error + JSR pixel_calc ;; A = byte_to_paint (small_X_offset) ;; Y =small_y_offset @@ -132,8 +139,13 @@ draw_right_px_in_circle:; similar as above STY Y_qaa +JMP outside_screen_error_end +outside_screen_error: +RTS +outside_screen_error_end: LDX #$08 ; X=8 always expected inside the loop SEC + while_x_bigger_then_y: ; C=1 here because above and branching logic draw_pixels: draw_qaa: @@ -286,4 +298,5 @@ endif: jmp while_x_bigger_then_y end: RTS + .endproc diff --git a/host/src/routines/circle/circle_test_position.s b/host/src/routines/circle/circle_test_position.s index ffa296f..89635a4 100644 --- a/host/src/routines/circle/circle_test_position.s +++ b/host/src/routines/circle/circle_test_position.s @@ -2,7 +2,7 @@ .include "circle.inc" ;; Set initial parameters for circle - LDA #$50 + LDA #$00 STA $AD LDA #$50 STA $AE @@ -38,6 +38,6 @@ loop: ;; end loop when x_pos = $70 LDA $AD - CMP #$70 + CMP #$ff BNE loop .endscope diff --git a/host/src/routines/circle/circle_test_size.s b/host/src/routines/circle/circle_test_size.s index 1c9093a..558f8e2 100644 --- a/host/src/routines/circle/circle_test_size.s +++ b/host/src/routines/circle/circle_test_size.s @@ -37,6 +37,6 @@ loop: ;; end loop if radius = $aa LDA $AD - CMP #$20 + CMP #$ff BNE loop .endscope diff --git a/host/src/test.s b/host/src/test.s index 43b4300..467ca40 100644 --- a/host/src/test.s +++ b/host/src/test.s @@ -15,12 +15,12 @@ mainsetup: ;; Note that arithmetic tests may use upp all the memory and the compiler don't complain! ;.include "routines/arithmatic/mult_test.s" -.include "routines/arithmatic/div_test.s" +;.include "routines/arithmatic/div_test.s" ;.include "routines/arithmatic/div_test_zero.s" -;.include "routines/circle/circle_test.s" -;.include "routines/circle/circle_test_size.s" -;.include "routines/circle/circle_test_position.s" +.include "routines/circle/circle_test.s" +.include "routines/circle/circle_test_size.s" +.include "routines/circle/circle_test_position.s" ;.include "routines/line/line_test.s" ;.include "routines/line/line_test_extensive.s" ;.include "routines/text/char_draw_test.s" @@ -33,10 +33,10 @@ exit: JMP exit .include "public.inc" ;.include "routines/line/line.s" -;.include "routines/circle/circle.s" +.include "routines/circle/circle.s" ;.include "routines/triangle/triangle.s" .include "routines/pixel/pixel_draw.s" -;.include "routines/pixel/pixel_calc.s" +.include "routines/pixel/pixel_calc.s" ;.include "routines/pixel/misc_pixel.s" ;.include "routines/text/char_draw.s" .include "routines/memory/memset.s"