A fix to a bug, to make line_down draw lines with small slopes.
I needed to use 16bit logic to ashive this. Also moved out dx*2, dy*2 calculation outside of loop for better performance.
This commit is contained in:
parent
9c86b570ed
commit
4f396fd740
3 changed files with 70 additions and 46 deletions
|
@ -9,13 +9,24 @@
|
||||||
STA a_hi
|
STA a_hi
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
||||||
|
.macro Sub_16 a_low, a_hi, b_low, b_hi ; a = a - b
|
||||||
|
SEC
|
||||||
|
LDA a_low
|
||||||
|
SBC b_low
|
||||||
|
STA a_low
|
||||||
|
LDA a_hi
|
||||||
|
SBC b_hi
|
||||||
|
STA a_hi
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
|
||||||
.macro mult_16 low_, hi_ ; [low, hi] = [low, hi]*2
|
.macro mult_16 low_, hi_ ; [low, hi] = [low, hi]*2
|
||||||
CLC
|
CLC
|
||||||
ROL low_
|
ROL low_
|
||||||
ROL hi_
|
ROL hi_
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
||||||
;
|
|
||||||
;.proc Sub_abs_8 ;return, primary, secondary
|
;.proc Sub_abs_8 ;return, primary, secondary
|
||||||
; LDA primary
|
; LDA primary
|
||||||
; SEC
|
; SEC
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
;;drawing line from 2 cordinates
|
;;drawing line from 2 cordinates
|
||||||
.proc line
|
.proc line
|
||||||
testing:
|
|
||||||
;;# (X_pos, Y_pos) #
|
;;# (X_pos, Y_pos) #
|
||||||
;;# * #
|
;;# * #
|
||||||
;;# * #
|
;;# * #
|
||||||
|
@ -14,63 +13,76 @@ testing:
|
||||||
Y_end = $05
|
Y_end = $05
|
||||||
X_pos = $FC
|
X_pos = $FC
|
||||||
Y_pos = $FB
|
Y_pos = $FB
|
||||||
dy = $06
|
dy_2 = $0607
|
||||||
dx = $07
|
dx = $08
|
||||||
D = $08
|
D = $0a0b
|
||||||
|
|
||||||
;;Set values
|
;;Set values
|
||||||
LDA #$00
|
LDA #$00
|
||||||
STA $FD ; for pixel_draw
|
STA $FD ; for pixel_draw
|
||||||
|
|
||||||
;;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 #$50
|
LDA #$f0
|
||||||
STA X_end
|
STA X_end
|
||||||
STA dx
|
LDA #$80
|
||||||
LDA #$40
|
|
||||||
STA Y_end
|
STA Y_end
|
||||||
STA dy
|
;;~~~~~~~~~~
|
||||||
LDA #($40 + $40 - $50 )
|
|
||||||
STA D ; = 2*dy - dx
|
;;2*dy = 2*(Y_end -Y_pos)
|
||||||
;; ~~~~~~~
|
LDA Y_end
|
||||||
|
SEC
|
||||||
|
SBC Y_pos
|
||||||
|
STA >dy_2
|
||||||
|
LDA #$00
|
||||||
|
STA <dy_2
|
||||||
|
mult_16 >dy_2, <dy_2
|
||||||
|
|
||||||
|
;;dx = (X_end -X_pos)
|
||||||
|
LDA X_end
|
||||||
|
SEC
|
||||||
|
SBC X_pos
|
||||||
|
STA dx
|
||||||
|
|
||||||
|
;;D = 2*dy - dx + 2*255. 0 <=D <= 4*255
|
||||||
|
;;Our D is bigger then wikipedia to not use negative numbers
|
||||||
|
LDA >dy_2
|
||||||
|
STA >D
|
||||||
|
LDA <dy_2
|
||||||
|
STA <D
|
||||||
|
Add_16 >D, <D, #$01, #$00
|
||||||
|
Sub_16 >D, <D, dx, #$00
|
||||||
|
|
||||||
|
|
||||||
|
;;We wont use dx, only 2*dx from now on
|
||||||
|
dx_2 = $0809 ;Lets reuse dx register ($08)
|
||||||
|
LDA #$00
|
||||||
|
STA <dx_2
|
||||||
|
mult_16 >dx_2, <dx_2
|
||||||
|
|
||||||
for_x:
|
for_x:
|
||||||
jsr pixel_draw
|
jsr pixel_draw
|
||||||
;;LDY D ; FOR DEBUG
|
;;Increment X until X_pos = X_end and Y_pos = Y_end
|
||||||
;;If D <= 0 then: skipp
|
INC X_pos
|
||||||
LDX D;
|
LDX X_pos
|
||||||
DEX
|
CPX X_end
|
||||||
BMI case_2
|
BEQ end
|
||||||
|
|
||||||
|
;;If D < %00000001 11111111 <==> >D ==0, then: case_2
|
||||||
|
LDA <D; if <D > 0 then: case_1
|
||||||
|
CMP #$00
|
||||||
|
BEQ case_2
|
||||||
case_1:
|
case_1:
|
||||||
INC Y_pos
|
INC Y_pos
|
||||||
|
;; D = D - 2*dx
|
||||||
;;D = D_before -2*dx
|
Sub_16 >D, <D, >dx_2, <dx_2
|
||||||
LDA dx
|
|
||||||
ROL A
|
|
||||||
TAX
|
|
||||||
LDA D
|
|
||||||
STX D ; D = -2*dx, A = D_before
|
|
||||||
SEC
|
|
||||||
SBC D ; A = D_before -2*dx
|
|
||||||
STA D;
|
|
||||||
jmp last
|
|
||||||
case_2:
|
case_2:
|
||||||
;;D = D + 2*dx
|
;;D = D + 2*dy
|
||||||
LDA dx
|
Add_16 >D, <D, >dy_2, <dy_2
|
||||||
ROL
|
|
||||||
CLC
|
|
||||||
ADC D
|
|
||||||
STA D
|
|
||||||
last:
|
last:
|
||||||
CMP #$00
|
|
||||||
;;increment x untill x == large
|
|
||||||
INC X_pos
|
|
||||||
LDA X_pos
|
|
||||||
CMP #199
|
|
||||||
BEQ end
|
|
||||||
JMP for_x
|
JMP for_x
|
||||||
end:
|
end:
|
||||||
jmp testing
|
.endproc
|
||||||
.endproc
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
;;Screen print. Draws a pixel at a specified position.
|
;;Screen print. Draws a pixel at a specified position.
|
||||||
|
;; Destroys A X Y
|
||||||
.proc pixel_draw; Draws a pixel at [Y = FB , X = FC, FD]. Y = 0 - 320, X= 0 - 200
|
.proc pixel_draw; Draws a pixel at [Y = FB , X = FC, FD]. Y = 0 - 320, X= 0 - 200
|
||||||
;;write_byte = 00010000,
|
;;write_byte = 00010000,
|
||||||
LDA $FC ; X (mod 8)
|
LDA $FC ; X (mod 8)
|
||||||
|
|
Loading…
Add table
Reference in a new issue