From 4d12f20a6e588e3cf4323260ef7893df5d9220b7 Mon Sep 17 00:00:00 2001 From: hugova Date: Mon, 3 Mar 2025 22:08:00 +0100 Subject: [PATCH] A Fix for D that gets the wrong initial value and the branch logic in line_* checked for the wrong value. A new proc, line.s that can chose whitch line_* to use A small test program in source.s Wrote a smal test program in source.s (all looks good exept line_up_inv) --- wip-hugo/macros/16aritmatic.s | 45 ++++++------------- wip-hugo/routines/memory/line/line.s | 41 +++++++++++++++++ .../routines/memory/{ => line}/line_down.s | 35 +++++++-------- .../memory/{ => line}/line_down_inv.s | 27 ++++++----- wip-hugo/routines/memory/{ => line}/line_up.s | 29 ++++++------ .../routines/memory/{ => line}/line_up_inv.s | 27 ++++++----- wip-hugo/run.sh | 4 +- wip-hugo/source.s | 45 ++++++++++++++++++- 8 files changed, 157 insertions(+), 96 deletions(-) create mode 100644 wip-hugo/routines/memory/line/line.s rename wip-hugo/routines/memory/{ => line}/line_down.s (75%) rename wip-hugo/routines/memory/{ => line}/line_down_inv.s (85%) rename wip-hugo/routines/memory/{ => line}/line_up.s (83%) rename wip-hugo/routines/memory/{ => line}/line_up_inv.s (85%) diff --git a/wip-hugo/macros/16aritmatic.s b/wip-hugo/macros/16aritmatic.s index 8ef0a96..d7e0efb 100755 --- a/wip-hugo/macros/16aritmatic.s +++ b/wip-hugo/macros/16aritmatic.s @@ -25,35 +25,18 @@ ROL low_ ROL hi_ .endmacro +;;Se below for some fast 16bit logic +;;http://6502.org/tutorials/compare_beyond.html - -;.proc Sub_abs_8 ;return, primary, secondary -; LDA primary -; SEC -; SBC secondary -; BPL end_;we got z positive result -; LDA secondary -; SEC -; SBC primary -; end_: -; STA return -;.endproc -; -;.proc poer ;low, hi, in ; [low, hi] = [in]^2 -; LDY in -; STY low -; LDA #$00 -; STA hi -; ;pow: -; DEY ; count = count -1 -; BEQ y_pow_end; -; CLC -; LDA in -; ADC low -; STA low -; LDA #$00 -; ADC hi -; STA hi -; ;jmp pow -; y_pow_end: -;.endproc +;; exampel 4.1.1 +;;Larger then operation. IF a < b then jump to label +.macro Lag_16 a_low, a_hi, b_low, b_hi, label ; [low, hi] = [low, hi]*2 + LDA a_hi ; compare high bytes + CMP b_hi + BCC label ; if NUM1H < NUM2H then NUM1 < NUM2 + BNE LABEL ; if NUM1H <> NUM2H then NUM1 > NUM2 (so NUM1 >= NUM2) + LDA a_low ; compare low bytes + CMP b_low + BCC label ; if NUM1L < NUM2L then NUM1 < NUM2 + LABEL: +.endmacro diff --git a/wip-hugo/routines/memory/line/line.s b/wip-hugo/routines/memory/line/line.s new file mode 100644 index 0000000..202074c --- /dev/null +++ b/wip-hugo/routines/memory/line/line.s @@ -0,0 +1,41 @@ +.proc line; X_pos =< X_end skall alltid gälla + dx = $fe + dy = $69 + ;;dx + SEC + LDA X_end + SBC X_pos + STA dx + + SEC + LDA Y_pos + SBC Y_end + STA dy + BCC down ;normal Y_pos < Y_end +up:; Y_pos > Y_end + STA dy + CMP dx + BCC shallow; dy < dx +steep: + jsr line_up_inv + RTS +shallow: ;dy =< dx + jsr line_up + RTS +down: + EOR #$ff ; Fix bit underflow + STA dy + CMP dx + BCC shallow_; dy < dx +steep_: + jsr line_down_inv + RTS +shallow_: ;dy < dx + jsr line_down + RTS +.endproc + +.include "line_down.s" +.include "line_down_inv.s" +.include "line_up.s" +.include "line_up_inv.s" diff --git a/wip-hugo/routines/memory/line_down.s b/wip-hugo/routines/memory/line/line_down.s similarity index 75% rename from wip-hugo/routines/memory/line_down.s rename to wip-hugo/routines/memory/line/line_down.s index 9943a61..287b8c2 100644 --- a/wip-hugo/routines/memory/line_down.s +++ b/wip-hugo/routines/memory/line/line_down.s @@ -1,5 +1,5 @@ ;;drawing line from 2 cordinates -.proc line +.proc line_down ;;# (X_pos, Y_pos) # ;;# * # ;;# * # @@ -17,17 +17,6 @@ V = $0809 D = $0a0b - ;example values ~~~~~ SHOULD BE PRECOMPILED - LDA #$00 - STA X_pos - STA Y_pos - - LDA #$90 - STA X_end - LDA #$10 - STA Y_end - ;;~~~~~~~~~~ - ;;We need to clear this memory LDA #$00 STA dy_2, =V. + ;; V_max = 00000001 11111111 + ;; For us to work with unsigned numbers we add 00000001 11111111 + ;; to V and the branch logic to V! + ;;D = 2*dy - dx + 2*255 ;;Our D is bigger then wikipedia because D is unsigned. LDA >dy_2 STA >D LDA D, D, D, >D ==0, then: case_2 - LDA 0 then: case_1 - CMP #$00 - BEQ case_2 + ;;If D < %00000010 00000000: case_2 + ;;else case 1. + Lag_16 >D, D, V, D, dy_2, D LDA D, D, D, >D ==0, then: case_2 - LDA 0 then: case_1 - CMP #$00 - BEQ case_2 + ;;If D < %00000010 00000000: case_2 + ;;else case 1. + Lag_16 >D, D, V, D, dx_2, D LDA D, D, D, >D ==0, then: case_2 - LDA 0 then: case_1 - CMP #$00 - BEQ case_2 + ;;If D < %00000010 00000000: case_2 + ;;else case 1. + Lag_16 >D, D, V, D, dy_2, D LDA D, D, D, >D ==0, then: case_2 - LDA 0 then: case_1 - CMP #$00 - BEQ case_2 + ;;If D < %00000010 00000000: case_2 + ;;else case 1. + Lag_16 >D, D, V, D, dx_2, /dev/null & -#https://vice-emu.sourceforge.io/vice_7.html +sleep 2 +rm source.o diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 21017ef..8cf7114 100755 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -1,9 +1,50 @@ .include "STARTUP.s" .include "macros/16aritmatic.s" -.include "routines/memory/line_up_inv.s" + + 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_ + +@loop: + LDA Y_pos_ + STA Y_pos + LDA X_pos_ + STA X_pos + LDA Y_end_ + STA Y_end + LDA X_end_ + STA X_end + + jsr line + INC Y_end_ + LDA Y_end_ + CMP #$bb + BEQ loop + jmp @loop +loop: + jmp loop + + + loop_: jmp loop_ - .include "routines/memory/memory_rec.s" .include "routines/memory/pixel_draw.s" +.include "routines/memory/line/line.s"