From 89c2b42bfe15c90e3798132f558551764e6c673a Mon Sep 17 00:00:00 2001 From: hugova Date: Tue, 4 Mar 2025 23:01:57 +0100 Subject: [PATCH] Reorginisation of line-drawing code. Also added a macro to benchmark line drawing logic. Addition of line_test_time to benchmark line drawing time (Do not work yet) --- wip-hugo/macros/timer.s | 18 ++++ wip-hugo/routines/line/line.inc | 11 +++ wip-hugo/routines/{memory => }/line/line.s | 11 ++- .../routines/{memory => }/line/line_down.s | 11 +-- .../{memory => }/line/line_down_inv.s | 11 +-- wip-hugo/routines/line/line_test.s | 90 +++++++++++++++++++ wip-hugo/routines/line/line_test_time.s | 38 ++++++++ wip-hugo/routines/{memory => }/line/line_up.s | 61 ++++++------- .../routines/{memory => }/line/line_up_inv.s | 13 +-- wip-hugo/source.s | 50 ++--------- 10 files changed, 202 insertions(+), 112 deletions(-) create mode 100644 wip-hugo/macros/timer.s create mode 100644 wip-hugo/routines/line/line.inc rename wip-hugo/routines/{memory => }/line/line.s (70%) rename wip-hugo/routines/{memory => }/line/line_down.s (90%) rename wip-hugo/routines/{memory => }/line/line_down_inv.s (90%) create mode 100644 wip-hugo/routines/line/line_test.s create mode 100644 wip-hugo/routines/line/line_test_time.s rename wip-hugo/routines/{memory => }/line/line_up.s (60%) rename wip-hugo/routines/{memory => }/line/line_up_inv.s (87%) diff --git a/wip-hugo/macros/timer.s b/wip-hugo/macros/timer.s new file mode 100644 index 0000000..51e5589 --- /dev/null +++ b/wip-hugo/macros/timer.s @@ -0,0 +1,18 @@ +;; Max 1.5s +.macro time_start + PHA + LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 + AND #%00001111 + STA $f1 + PLA +.endmacro + +.macro time_stop + PHA + LDA $DC08 ; Bit 0..3: Tenth seconds in BCD-format, others may be 0 or 1 + AND #%00001111 + SEC + SBC $f1 + STA $f1 + PLA +.endmacro diff --git a/wip-hugo/routines/line/line.inc b/wip-hugo/routines/line/line.inc new file mode 100644 index 0000000..8f5777b --- /dev/null +++ b/wip-hugo/routines/line/line.inc @@ -0,0 +1,11 @@ + ;;Not values but register position in memory + X_end = $04 + Y_end = $05 + X_pos = $FC + Y_pos = $FB + dy= $0c + dx = dy + dy_2 = $0607 + dx_2 = dy_2 + V = $0809 + D = $0a0b diff --git a/wip-hugo/routines/memory/line/line.s b/wip-hugo/routines/line/line.s similarity index 70% rename from wip-hugo/routines/memory/line/line.s rename to wip-hugo/routines/line/line.s index 202074c..3e7a289 100644 --- a/wip-hugo/routines/memory/line/line.s +++ b/wip-hugo/routines/line/line.s @@ -1,11 +1,16 @@ .proc line; X_pos =< X_end skall alltid gälla - dx = $fe - dy = $69 + ;; note that these have same adresses as stuff in line.inc + ;; This should be used as a optimisation in the future + dx = $0c + dy = $06 ;;dx SEC LDA X_end SBC X_pos STA dx + BCC dx_no_underflow;; X_end >= X_pos + EOR #$ff ; Fix bit underflow + dx_no_underflow: SEC LDA Y_pos @@ -20,6 +25,7 @@ steep: jsr line_up_inv RTS shallow: ;dy =< dx + lda dx jsr line_up RTS down: @@ -34,7 +40,6 @@ shallow_: ;dy < dx jsr line_down RTS .endproc - .include "line_down.s" .include "line_down_inv.s" .include "line_up.s" diff --git a/wip-hugo/routines/memory/line/line_down.s b/wip-hugo/routines/line/line_down.s similarity index 90% rename from wip-hugo/routines/memory/line/line_down.s rename to wip-hugo/routines/line/line_down.s index 287b8c2..ce1c898 100644 --- a/wip-hugo/routines/memory/line/line_down.s +++ b/wip-hugo/routines/line/line_down.s @@ -6,16 +6,7 @@ ;;# * # ;;# (X_end, Y_end) # ;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Max 45deg! - - ;;Not values but register position in memory - X_end = $04 - Y_end = $05 - X_pos = $FC - Y_pos = $FB - dx = $0c - dy_2 = $0607 - V = $0809 - D = $0a0b + .include "line.inc"; Defines memory positions, ex X_pos ;;We need to clear this memory LDA #$00 diff --git a/wip-hugo/routines/memory/line/line_down_inv.s b/wip-hugo/routines/line/line_down_inv.s similarity index 90% rename from wip-hugo/routines/memory/line/line_down_inv.s rename to wip-hugo/routines/line/line_down_inv.s index 5ddaf4c..9e5831f 100644 --- a/wip-hugo/routines/memory/line/line_down_inv.s +++ b/wip-hugo/routines/line/line_down_inv.s @@ -6,16 +6,7 @@ ;;# * # ;;# (X_end, Y_end) # ;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Min 45deg! - - ;;Not values but register position in memory - X_end = $04 - Y_end = $05 - X_pos = $FC - Y_pos = $FB - dy = $0c - dx_2 = $0607 - V = $0809 - D = $0a0b + .include "line.inc"; Defines memory positions, ex X_pos ;example values ~~~~~ SHOULD BE PRECOMPILED ;LDA #$00 diff --git a/wip-hugo/routines/line/line_test.s b/wip-hugo/routines/line/line_test.s new file mode 100644 index 0000000..a2e689a --- /dev/null +++ b/wip-hugo/routines/line/line_test.s @@ -0,0 +1,90 @@ + X_end = $04 + Y_end = $05 + X_pos = $FC + Y_pos = $FB + ;;for testing stuff + Y_pos_ = $0D + X_pos_ = $0E + Y_end_ = $10 + X_end_ = $11 + LDA #$d0 + STA X_pos_ + LDA #$60 + STA Y_pos_ + LDA #$ff + STA X_end + LDA #$0 + STA Y_end + +;; Short test for timing +@loop: + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos + + jsr line + INC Y_end + LDA Y_end + CMP #$bb + BEQ end__ + jmp @loop +end__: + + + +;; Full anfle test +@loop: + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos + + jsr line + INC Y_end + LDA Y_end + CMP #$bb + BEQ end + jmp @loop +end: +;;Long lines + +;;Lets cleer bitmap +LDA #>VIC_bank +STA $FC +LDA #$5f3f +STA $FE +LDA #<$5f3f +STA $FD + +LDA #$0 +jsr memory_rec + +LDA #$00 +STA X_pos_ +LDA #$60 +STA Y_pos_ +LDA #$ff +STA X_end +LDA #$0 +STA Y_end +@loop: + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos + + jsr line + INC Y_end + LDA Y_end + CMP #$bb + BEQ end_ + jmp @loop +end_: +jmp exit + +.include "line.s" +.include "macros/" diff --git a/wip-hugo/routines/line/line_test_time.s b/wip-hugo/routines/line/line_test_time.s new file mode 100644 index 0000000..d45d553 --- /dev/null +++ b/wip-hugo/routines/line/line_test_time.s @@ -0,0 +1,38 @@ + X_end = $04 + Y_end = $05 + X_pos = $FC + Y_pos = $FB + ;;for testing stuff + Y_pos_ = $0D + X_pos_ = $0E + Y_end_ = $10 + X_end_ = $11 + LDA #$d0 + STA X_pos_ + LDA #$60 + STA Y_pos_ + LDA #$ff + STA X_end + LDA #$0 + STA Y_end + +;; Short test for timing +time_start + +@loop: + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos + + jsr line + INC Y_end + LDA Y_end + CMP #$30 + BEQ end__ + jmp @loop +end__: +time_stop +jmp exit + +.include "line.s" diff --git a/wip-hugo/routines/memory/line/line_up.s b/wip-hugo/routines/line/line_up.s similarity index 60% rename from wip-hugo/routines/memory/line/line_up.s rename to wip-hugo/routines/line/line_up.s index 310d8dd..3d7f2b4 100644 --- a/wip-hugo/routines/memory/line/line_up.s +++ b/wip-hugo/routines/line/line_up.s @@ -7,16 +7,7 @@ ;;# (X_pos, Y_pos) # ;; ;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg! - - ;;Not values but register position in memory - X_end = $04 - Y_end = $05 - X_pos = $FC - Y_pos = $FB - dy_2 = $0607 - dx = $0c - V = $0809 - D = $0a0b + .include "line.inc"; Defines memory positions, ex X_pos ;;example values ~~~~~ SHOULD BE PRECOMPILED ;LDA #$90 @@ -35,32 +26,34 @@ STA $FD ; for pixel_draw ;; V = 2*(dx -dy) - ;; where: dy = Y_pos - Y_end, dx = X_end - X_start - LDA Y_pos - SEC - SBC Y_end - STA >V - STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V) - LDA X_end - SEC - SBC X_pos - STA dx - SEC - SBC >V - STA >V; V, V + STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V) + LDA X_end + SEC + SBC X_pos + STA dx + SEC + SBC >dy_2 + STA >V; V, dy_2, dy_2, dy_2 - STA >D - LDA D, D, dy_2 + STA >D + LDA D, D, ) Y_end, X_pos <= X_end. Min 45deg! + .include "line.inc" - ;;Not values but register position in memory - X_end = $04 - Y_end = $05 - X_pos = $FC - Y_pos = $FB - dx_2 = $0607 - dy = $0c - V = $0809 - D = $0a0b - - ;We need to clear this memory + ;;We need to clear this memory LDA #$00 STA