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
|
@ -1,6 +1,6 @@
|
|||
|
||||
.macro Add_16 a_low, a_hi, b_low, b_hi ; a = a + b
|
||||
CLC
|
||||
CLC
|
||||
LDA b_low
|
||||
ADC a_low
|
||||
STA a_low
|
||||
|
@ -9,13 +9,24 @@
|
|||
STA a_hi
|
||||
.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
|
||||
CLC
|
||||
ROL low_
|
||||
ROL hi_
|
||||
.endmacro
|
||||
|
||||
;
|
||||
|
||||
;.proc Sub_abs_8 ;return, primary, secondary
|
||||
; LDA primary
|
||||
; SEC
|
||||
|
@ -35,7 +46,7 @@
|
|||
; STA hi
|
||||
; ;pow:
|
||||
; DEY ; count = count -1
|
||||
; BEQ y_pow_end;
|
||||
; BEQ y_pow_end;
|
||||
; CLC
|
||||
; LDA in
|
||||
; ADC low
|
||||
|
@ -45,4 +56,4 @@
|
|||
; STA hi
|
||||
; ;jmp pow
|
||||
; y_pow_end:
|
||||
;.endproc
|
||||
;.endproc
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
;;drawing line from 2 cordinates
|
||||
.proc line
|
||||
testing:
|
||||
;;# (X_pos, Y_pos) #
|
||||
;;# * #
|
||||
;;# * #
|
||||
|
@ -14,63 +13,76 @@ testing:
|
|||
Y_end = $05
|
||||
X_pos = $FC
|
||||
Y_pos = $FB
|
||||
dy = $06
|
||||
dx = $07
|
||||
D = $08
|
||||
dy_2 = $0607
|
||||
dx = $08
|
||||
D = $0a0b
|
||||
|
||||
;;Set values
|
||||
LDA #$00
|
||||
STA $FD ; for pixel_draw
|
||||
|
||||
;;example values ~~~~~ SHOULD BE PRECOMPILED
|
||||
;example values ~~~~~ SHOULD BE PRECOMPILED
|
||||
LDA #$00
|
||||
STA X_pos
|
||||
STA Y_pos
|
||||
|
||||
LDA #$50
|
||||
LDA #$f0
|
||||
STA X_end
|
||||
STA dx
|
||||
LDA #$40
|
||||
LDA #$80
|
||||
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:
|
||||
jsr pixel_draw
|
||||
;;LDY D ; FOR DEBUG
|
||||
;;If D <= 0 then: skipp
|
||||
LDX D;
|
||||
DEX
|
||||
BMI case_2
|
||||
;;Increment X until X_pos = X_end and Y_pos = Y_end
|
||||
INC X_pos
|
||||
LDX X_pos
|
||||
CPX X_end
|
||||
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:
|
||||
INC Y_pos
|
||||
|
||||
;;D = D_before -2*dx
|
||||
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
|
||||
;; D = D - 2*dx
|
||||
Sub_16 >D, <D, >dx_2, <dx_2
|
||||
case_2:
|
||||
;;D = D + 2*dx
|
||||
LDA dx
|
||||
ROL
|
||||
CLC
|
||||
ADC D
|
||||
STA D
|
||||
;;D = D + 2*dy
|
||||
Add_16 >D, <D, >dy_2, <dy_2
|
||||
last:
|
||||
CMP #$00
|
||||
;;increment x untill x == large
|
||||
INC X_pos
|
||||
LDA X_pos
|
||||
CMP #199
|
||||
BEQ end
|
||||
JMP for_x
|
||||
end:
|
||||
jmp testing
|
||||
.endproc
|
||||
.endproc
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
;;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
|
||||
;;write_byte = 00010000,
|
||||
LDA $FC ; X (mod 8)
|
||||
|
|
Loading…
Add table
Reference in a new issue