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)
This commit is contained in:
parent
1524c837ca
commit
4d12f20a6e
8 changed files with 157 additions and 96 deletions
|
@ -25,35 +25,18 @@
|
||||||
ROL low_
|
ROL low_
|
||||||
ROL hi_
|
ROL hi_
|
||||||
.endmacro
|
.endmacro
|
||||||
|
;;Se below for some fast 16bit logic
|
||||||
|
;;http://6502.org/tutorials/compare_beyond.html
|
||||||
|
|
||||||
|
;; exampel 4.1.1
|
||||||
;.proc Sub_abs_8 ;return, primary, secondary
|
;;Larger then operation. IF a < b then jump to label
|
||||||
; LDA primary
|
.macro Lag_16 a_low, a_hi, b_low, b_hi, label ; [low, hi] = [low, hi]*2
|
||||||
; SEC
|
LDA a_hi ; compare high bytes
|
||||||
; SBC secondary
|
CMP b_hi
|
||||||
; BPL end_;we got z positive result
|
BCC label ; if NUM1H < NUM2H then NUM1 < NUM2
|
||||||
; LDA secondary
|
BNE LABEL ; if NUM1H <> NUM2H then NUM1 > NUM2 (so NUM1 >= NUM2)
|
||||||
; SEC
|
LDA a_low ; compare low bytes
|
||||||
; SBC primary
|
CMP b_low
|
||||||
; end_:
|
BCC label ; if NUM1L < NUM2L then NUM1 < NUM2
|
||||||
; STA return
|
LABEL:
|
||||||
;.endproc
|
.endmacro
|
||||||
;
|
|
||||||
;.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
|
|
||||||
|
|
41
wip-hugo/routines/memory/line/line.s
Normal file
41
wip-hugo/routines/memory/line/line.s
Normal file
|
@ -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"
|
|
@ -1,5 +1,5 @@
|
||||||
;;drawing line from 2 cordinates
|
;;drawing line from 2 cordinates
|
||||||
.proc line
|
.proc line_down
|
||||||
;;# (X_pos, Y_pos) #
|
;;# (X_pos, Y_pos) #
|
||||||
;;# * #
|
;;# * #
|
||||||
;;# * #
|
;;# * #
|
||||||
|
@ -17,17 +17,6 @@
|
||||||
V = $0809
|
V = $0809
|
||||||
D = $0a0b
|
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
|
;;We need to clear this memory
|
||||||
LDA #$00
|
LDA #$00
|
||||||
STA <V
|
STA <V
|
||||||
|
@ -35,7 +24,7 @@
|
||||||
STA $FD ; for pixel_draw
|
STA $FD ; for pixel_draw
|
||||||
|
|
||||||
;; V = 2*(dx -dy)
|
;; V = 2*(dx -dy)
|
||||||
;; where: dy = Y_end - Y_start, dx = X_end - X_start
|
;; where: dy = Y_end - Y_start, dx = OO - X_start
|
||||||
LDA Y_end
|
LDA Y_end
|
||||||
SEC
|
SEC
|
||||||
SBC Y_pos
|
SBC Y_pos
|
||||||
|
@ -53,14 +42,24 @@
|
||||||
;dy_2 = dy*2
|
;dy_2 = dy*2
|
||||||
mult_16 >dy_2, <dy_2
|
mult_16 >dy_2, <dy_2
|
||||||
|
|
||||||
|
;; D = 2*dy - dx
|
||||||
|
;; In loop we have that D = D -V
|
||||||
|
;; So D needs to be at least >=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
|
;;D = 2*dy - dx + 2*255
|
||||||
;;Our D is bigger then wikipedia because D is unsigned.
|
;;Our D is bigger then wikipedia because D is unsigned.
|
||||||
LDA >dy_2
|
LDA >dy_2
|
||||||
STA >D
|
STA >D
|
||||||
LDA <dy_2
|
LDA <dy_2
|
||||||
STA <D
|
STA <D
|
||||||
Add_16 >D, <D, #$00, #$01
|
Add_16 >D, <D, #$ff, #$01
|
||||||
Sub_16 >D, <D, dx, #$00
|
Sub_16 >D, <D, dx, #$00
|
||||||
|
;hihi:
|
||||||
|
;jmp hihi
|
||||||
|
|
||||||
|
|
||||||
for_x:
|
for_x:
|
||||||
jsr pixel_draw
|
jsr pixel_draw
|
||||||
|
@ -70,10 +69,9 @@ for_x:
|
||||||
CPX X_end
|
CPX X_end
|
||||||
BEQ end
|
BEQ end
|
||||||
|
|
||||||
;;If D < %00000001 11111111 <==> >D ==0, then: case_2
|
;;If D < %00000010 00000000: case_2
|
||||||
LDA <D; if <D > 0 then: case_1
|
;;else case 1.
|
||||||
CMP #$00
|
Lag_16 >D, <D, #$00, #$02, case_2
|
||||||
BEQ case_2
|
|
||||||
case_1:
|
case_1:
|
||||||
INC Y_pos
|
INC Y_pos
|
||||||
Sub_16 >D, <D, >V, <V; D = D - V
|
Sub_16 >D, <D, >V, <V; D = D - V
|
||||||
|
@ -82,4 +80,5 @@ case_2:
|
||||||
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
|
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
|
||||||
JMP for_x
|
JMP for_x
|
||||||
end:
|
end:
|
||||||
|
RTS
|
||||||
.endproc
|
.endproc
|
|
@ -1,5 +1,5 @@
|
||||||
;;drawing line from 2 cordinates
|
;;drawing line from 2 cordinates
|
||||||
.proc line
|
.proc line_down_inv
|
||||||
;;# (X_pos, Y_pos) #
|
;;# (X_pos, Y_pos) #
|
||||||
;;# * #
|
;;# * #
|
||||||
;;# * #
|
;;# * #
|
||||||
|
@ -18,14 +18,13 @@
|
||||||
D = $0a0b
|
D = $0a0b
|
||||||
|
|
||||||
;example values ~~~~~ SHOULD BE PRECOMPILED
|
;example values ~~~~~ SHOULD BE PRECOMPILED
|
||||||
LDA #$00
|
;LDA #$00
|
||||||
STA X_pos
|
;STA X_pos
|
||||||
STA Y_pos
|
;STA Y_pos
|
||||||
|
;LDA #$40
|
||||||
LDA #$40
|
;STA X_end
|
||||||
STA X_end
|
;LDA #$a0
|
||||||
LDA #$a0
|
;STA Y_end
|
||||||
STA Y_end
|
|
||||||
;;~~~~~~~~~~
|
;;~~~~~~~~~~
|
||||||
|
|
||||||
;;We need to clear this memory
|
;;We need to clear this memory
|
||||||
|
@ -59,7 +58,7 @@
|
||||||
STA >D
|
STA >D
|
||||||
LDA <dx_2
|
LDA <dx_2
|
||||||
STA <D
|
STA <D
|
||||||
Add_16 >D, <D, #$00, #$01
|
Add_16 >D, <D, #$ff, #$01
|
||||||
Sub_16 >D, <D, dy, #$00
|
Sub_16 >D, <D, dy, #$00
|
||||||
|
|
||||||
for_y:
|
for_y:
|
||||||
|
@ -70,10 +69,9 @@ for_y:
|
||||||
CPY Y_end
|
CPY Y_end
|
||||||
BEQ end
|
BEQ end
|
||||||
|
|
||||||
;;If D < %00000001 11111111 <==> >D ==0, then: case_2
|
;;If D < %00000010 00000000: case_2
|
||||||
LDA <D; if <D > 0 then: case_1
|
;;else case 1.
|
||||||
CMP #$00
|
Lag_16 >D, <D, #$00, #$02, case_2
|
||||||
BEQ case_2
|
|
||||||
case_1:
|
case_1:
|
||||||
INC X_pos
|
INC X_pos
|
||||||
Sub_16 >D, <D, >V, <V; D = D - V
|
Sub_16 >D, <D, >V, <V; D = D - V
|
||||||
|
@ -82,4 +80,5 @@ case_2:
|
||||||
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dx
|
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dx
|
||||||
JMP for_y
|
JMP for_y
|
||||||
end:
|
end:
|
||||||
|
RTS
|
||||||
.endproc
|
.endproc
|
|
@ -1,5 +1,5 @@
|
||||||
;;drawing line from 2 cordinates
|
;;drawing line from 2 cordinates
|
||||||
.proc line
|
.proc line_up
|
||||||
;;# * (X_end, Y_end) #
|
;;# * (X_end, Y_end) #
|
||||||
;;# #
|
;;# #
|
||||||
;;# * #
|
;;# * #
|
||||||
|
@ -18,15 +18,14 @@
|
||||||
V = $0809
|
V = $0809
|
||||||
D = $0a0b
|
D = $0a0b
|
||||||
|
|
||||||
;example values ~~~~~ SHOULD BE PRECOMPILED
|
;;example values ~~~~~ SHOULD BE PRECOMPILED
|
||||||
LDA #$90
|
;LDA #$90
|
||||||
STA X_pos
|
;STA X_pos
|
||||||
STA Y_pos
|
;STA Y_pos
|
||||||
|
;LDA #$aa
|
||||||
LDA #$aa
|
;STA X_end
|
||||||
STA X_end
|
;LDA #$80
|
||||||
LDA #$80
|
;STA Y_end
|
||||||
STA Y_end
|
|
||||||
;;~~~~~~~~~~
|
;;~~~~~~~~~~
|
||||||
|
|
||||||
;;We need to clear this memory
|
;;We need to clear this memory
|
||||||
|
@ -60,7 +59,7 @@
|
||||||
STA >D
|
STA >D
|
||||||
LDA <dy_2
|
LDA <dy_2
|
||||||
STA <D
|
STA <D
|
||||||
Add_16 >D, <D, #$00, #$01
|
Add_16 >D, <D, #$ff, #$01
|
||||||
Sub_16 >D, <D, dx, #$00
|
Sub_16 >D, <D, dx, #$00
|
||||||
for_x:
|
for_x:
|
||||||
jsr pixel_draw
|
jsr pixel_draw
|
||||||
|
@ -70,10 +69,9 @@ for_x:
|
||||||
CPX X_end
|
CPX X_end
|
||||||
BEQ end
|
BEQ end
|
||||||
|
|
||||||
;;If D < %00000001 11111111 <==> >D ==0, then: case_2
|
;;If D < %00000010 00000000: case_2
|
||||||
LDA <D; if <D > 0 then: case_1
|
;;else case 1.
|
||||||
CMP #$00
|
Lag_16 >D, <D, #$00, #$02, case_2
|
||||||
BEQ case_2
|
|
||||||
case_1:
|
case_1:
|
||||||
DEC Y_pos
|
DEC Y_pos
|
||||||
Sub_16 >D, <D, >V, <V; D = D - V
|
Sub_16 >D, <D, >V, <V; D = D - V
|
||||||
|
@ -82,4 +80,5 @@ case_2:
|
||||||
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
|
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
|
||||||
JMP for_x
|
JMP for_x
|
||||||
end:
|
end:
|
||||||
|
RTS
|
||||||
.endproc
|
.endproc
|
|
@ -1,5 +1,5 @@
|
||||||
;drawing line from 2 cordinates
|
;drawing line from 2 cordinates
|
||||||
.proc line
|
.proc line_up_inv
|
||||||
;;# (X_pos, Y_pos) #
|
;;# (X_pos, Y_pos) #
|
||||||
;;# * #
|
;;# * #
|
||||||
;;# * #
|
;;# * #
|
||||||
|
@ -18,14 +18,13 @@
|
||||||
D = $0a0b
|
D = $0a0b
|
||||||
|
|
||||||
;example values ~~~~~ SHOULD BE PRECOMPILED
|
;example values ~~~~~ SHOULD BE PRECOMPILED
|
||||||
LDA #$60
|
;LDA #$60
|
||||||
STA X_pos
|
;STA X_pos
|
||||||
STA Y_pos
|
;STA Y_pos
|
||||||
|
;LDA #$50
|
||||||
LDA #$50
|
;STA X_end
|
||||||
STA X_end
|
;LDA #$90
|
||||||
LDA #$90
|
;STA Y_end
|
||||||
STA Y_end
|
|
||||||
;;~~~~~~~~~~
|
;;~~~~~~~~~~
|
||||||
|
|
||||||
;We need to clear this memory
|
;We need to clear this memory
|
||||||
|
@ -59,7 +58,7 @@
|
||||||
STA >D
|
STA >D
|
||||||
LDA <dx_2
|
LDA <dx_2
|
||||||
STA <D
|
STA <D
|
||||||
Add_16 >D, <D, #$00, #$01
|
Add_16 >D, <D, #$ff, #$01
|
||||||
Sub_16 >D, <D, dy, #$00
|
Sub_16 >D, <D, dy, #$00
|
||||||
for_y:
|
for_y:
|
||||||
jsr pixel_draw
|
jsr pixel_draw
|
||||||
|
@ -69,10 +68,9 @@ for_y:
|
||||||
CPY Y_end
|
CPY Y_end
|
||||||
BEQ end
|
BEQ end
|
||||||
|
|
||||||
;;If D < %00000001 11111111 <==> >D ==0, then: case_2
|
;;If D < %00000010 00000000: case_2
|
||||||
LDA <D; if <D > 0 then: case_1
|
;;else case 1.
|
||||||
CMP #$00
|
Lag_16 >D, <D, #$00, #$02, case_2
|
||||||
BEQ case_2
|
|
||||||
case_1:
|
case_1:
|
||||||
DEC X_pos
|
DEC X_pos
|
||||||
Sub_16 >D, <D, >V, <V; D = D - V
|
Sub_16 >D, <D, >V, <V; D = D - V
|
||||||
|
@ -81,4 +79,5 @@ case_2:
|
||||||
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dy
|
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dy
|
||||||
JMP for_y
|
JMP for_y
|
||||||
end:
|
end:
|
||||||
|
RTS
|
||||||
.endproc
|
.endproc
|
|
@ -1,4 +1,4 @@
|
||||||
# !/bin/bash
|
# !/bin/bash
|
||||||
pkill -f pulseaudio
|
|
||||||
killall x64sc ; cl65 -o file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg source.s && nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 file.prg </dev/null &>/dev/null &
|
killall x64sc ; cl65 -o file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg source.s && nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 file.prg </dev/null &>/dev/null &
|
||||||
#https://vice-emu.sourceforge.io/vice_7.html
|
sleep 2
|
||||||
|
rm source.o
|
||||||
|
|
|
@ -1,9 +1,50 @@
|
||||||
.include "STARTUP.s"
|
.include "STARTUP.s"
|
||||||
.include "macros/16aritmatic.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_:
|
loop_:
|
||||||
jmp loop_
|
jmp loop_
|
||||||
|
|
||||||
.include "routines/memory/memory_rec.s"
|
.include "routines/memory/memory_rec.s"
|
||||||
.include "routines/memory/pixel_draw.s"
|
.include "routines/memory/pixel_draw.s"
|
||||||
|
.include "routines/memory/line/line.s"
|
||||||
|
|
Loading…
Add table
Reference in a new issue