From 8eb5ff855b2e00dcfac19d354a7b1e8c26a5395a Mon Sep 17 00:00:00 2001 From: hugova Date: Sat, 26 Jul 2025 19:42:57 +0200 Subject: [PATCH] fix most of by one errors of linedraw. --- wip-hugo/routines/line/line.s | 29 +++++++-------- wip-hugo/routines/line/line_down.s | 1 + wip-hugo/routines/line/line_down_inv.s | 1 + wip-hugo/routines/line/line_test_extensive.s | 39 ++++++++++++++++++-- wip-hugo/routines/line/line_up.s | 1 + wip-hugo/routines/line/line_up_inv.s | 1 + 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/wip-hugo/routines/line/line.s b/wip-hugo/routines/line/line.s index 9768771..89a50de 100644 --- a/wip-hugo/routines/line/line.s +++ b/wip-hugo/routines/line/line.s @@ -5,26 +5,24 @@ .include "line.inc" ;; Fix line that is too long - LDA Y_pos - CMP #$C8 ;;y_max = $C8 - BCC do_not_fix_y_pos - LDA #$C8 + LDA #$C8 ;y_max = $C8 + CMP Y_pos + BCS do_not_fix_y_pos STA Y_pos do_not_fix_y_pos: - LDA Y_end - CMP #$C8 ;;y_max = $C8 - BCC do_not_fix_y_end LDA #$C8 + CMP Y_pos ;y_max = $C8 + BCS do_not_fix_y_end STA Y_end do_not_fix_y_end: - ;;dx SEC LDA X_end SBC X_pos BCS dx_no_underflow;; X_end >= X_pos EOR #$ff ; Fix bit underflow + ADC #$01 STA dx ;; line_* expect X_pos < X_end and now its not the case. ;; Lets move them around @@ -36,28 +34,27 @@ do_not_fix_y_end: LDY Y_end STX Y_end STY Y_pos - - dx_no_underflow: STA dx + SEC - LDA Y_pos - SBC Y_end - STA dy - BCC down ;normal Y_pos < Y_end + LDA Y_end + SBC Y_pos + BCS down ;normal Y_pos < Y_end up:; Y_pos > Y_end + EOR #$ff ; Fix bit underflow + ADC #$01 STA dy + CMP dx BCC shallow; dy < dx steep: jsr line_up_inv RTS shallow: ;dy =< dx - lda dx jsr line_up RTS down: - EOR #$ff ; Fix bit underflow STA dy CMP dx BCC shallow_; dy < dx diff --git a/wip-hugo/routines/line/line_down.s b/wip-hugo/routines/line/line_down.s index b81a095..6641a0a 100644 --- a/wip-hugo/routines/line/line_down.s +++ b/wip-hugo/routines/line/line_down.s @@ -67,6 +67,7 @@ end_selfmod: STA byte_to_paint ;; X = X_end - X_pos LDX dx + INX ; okay if it overflow to $00 because it will go back to $ff in loop. Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00,! ;; Y has always a offset of at least 1 = C + $0000 INY for_x: diff --git a/wip-hugo/routines/line/line_down_inv.s b/wip-hugo/routines/line/line_down_inv.s index 465ffdf..4446379 100644 --- a/wip-hugo/routines/line/line_down_inv.s +++ b/wip-hugo/routines/line/line_down_inv.s @@ -55,6 +55,7 @@ end_selfmod: INY Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00, ! LDX dy + INX CLC for_y: ; C =0 LDA byte_to_paint diff --git a/wip-hugo/routines/line/line_test_extensive.s b/wip-hugo/routines/line/line_test_extensive.s index f24537c..8438af5 100644 --- a/wip-hugo/routines/line/line_test_extensive.s +++ b/wip-hugo/routines/line/line_test_extensive.s @@ -8,6 +8,8 @@ X_pos_ = $0E Y_end_ = $0F X_end_ = $0C + +full_angle_test: LDA #$d2 STA X_pos_ LDA #$62 @@ -36,14 +38,43 @@ jsr clear_screen +full_angle_test_pos_end_swapped: +LDA #$d2 +STA X_end_ +LDA #$62 +STA Y_end_ +LDA #$ff +STA X_pos_ +LDA #$0 +STA Y_pos_ + +;; Full angle test +@loop: +LDA Y_end_ +STA Y_end +LDA X_end_ +STA X_end +LDA X_pos_ +STA X_pos +LDA Y_pos_ +STA Y_pos + +jsr line +INC Y_pos_ +LDA Y_pos_ +CMP #$ff +bne @loop + +jsr clear_screen + long_line_test_a: - LDA #$00 + LDA #$01 STA X_pos_ LDA #$60 STA Y_pos_ LDA #$ff STA X_end_ - LDA #$0 + LDA #$00 STA Y_end_ @loop: LDA Y_pos_ @@ -64,7 +95,7 @@ long_line_test_a: jsr clear_screen long_line_test_b: - LDA #$00 + LDA #$01 STA X_pos_ LDA #$00 STA Y_pos_ @@ -90,7 +121,7 @@ long_line_test_b: jsr clear_screen long_line_test_b_pos_end_swapped: - LDA #$00 + LDA #$01 STA X_end_ LDA #$00 STA Y_end_ diff --git a/wip-hugo/routines/line/line_up.s b/wip-hugo/routines/line/line_up.s index 0edae87..24f1ae1 100644 --- a/wip-hugo/routines/line/line_up.s +++ b/wip-hugo/routines/line/line_up.s @@ -50,6 +50,7 @@ end_selfmod: ;LDY #$01 INY LDX dx + INX for_x: LDA byte_to_paint ORA (btp_mem_pos), Y diff --git a/wip-hugo/routines/line/line_up_inv.s b/wip-hugo/routines/line/line_up_inv.s index 5ad7940..a99b39b 100644 --- a/wip-hugo/routines/line/line_up_inv.s +++ b/wip-hugo/routines/line/line_up_inv.s @@ -52,6 +52,7 @@ end_selfmod: Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00,! CLC LDX dy + INX for_y: LDA byte_to_paint ORA (btp_mem_pos), Y