optimise line_down by using signed 16-bit
This commit is contained in:
parent
e5c78e7565
commit
b23a63ddf5
1 changed files with 21 additions and 35 deletions
|
@ -25,39 +25,26 @@
|
||||||
Mult_16 A, V +1
|
Mult_16 A, V +1
|
||||||
STA V
|
STA V
|
||||||
;dy_2 = dy*2
|
;dy_2 = dy*2
|
||||||
Mult_16 dy_2, dy_2 +1 ;>dy_2 = dy (same address)
|
Mult_16 dy_2, dy_2 +1 ;dy_2 = dy (same address)
|
||||||
|
|
||||||
;; This is an Bresenham's line algorithm, se wikipedia bellow.
|
|
||||||
;;https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
|
||||||
;; We need to compute the Value D = 2*dy - dx,
|
|
||||||
;; but it may be or get negative.
|
|
||||||
;; IN the loop we may set D = D -V
|
|
||||||
;; Because math D needs to be at least >=V.
|
|
||||||
;; V_max = %00000001 11111111
|
|
||||||
;; We therefor need to add this offset to V 00000001 11111111
|
|
||||||
;; and to its branch logic later in the loop.
|
|
||||||
|
|
||||||
;;D = 2*dy - dx + 2*255
|
|
||||||
LDA dy_2
|
|
||||||
ADC #$ff
|
|
||||||
TAX
|
|
||||||
LDA dy + 1
|
|
||||||
ADC #$01
|
|
||||||
TAY
|
|
||||||
|
|
||||||
|
;; D = dy_2 - x. (signed 16-bit)
|
||||||
SEC
|
SEC
|
||||||
TXA
|
LDA dy_2
|
||||||
SBC dx
|
SBC dx
|
||||||
STA D
|
STA D
|
||||||
TYA
|
LDA dy_2 + 1
|
||||||
SBC #$00
|
SBC #$00
|
||||||
STA D + 1
|
STA D + 1
|
||||||
|
|
||||||
|
;; because C flag is wrong value we let dy_2 be 1 to small
|
||||||
|
Sub_16 dy_2, dy_2 +1, #$01,#$00
|
||||||
|
|
||||||
|
|
||||||
selfmod:
|
selfmod:
|
||||||
;; Self modifying code. Makes LDA and SBC instructions each take 1 cycle less.
|
;; Self modifying code. Makes LDA and SBC instructions each take 1 cycle less.
|
||||||
;; You can remove this if you run the loop without # at dy_2 and V.
|
;; You can remove this if you run the loop without # at dy_2 and V.
|
||||||
;;Note: The offsets like +2 etc is because there are instructions betwean the label and the
|
;;Note: The offsets like +2 etc is because there are instructions betwean the label and the
|
||||||
;address that needs to be modified
|
;; address that needs to be modified.
|
||||||
;; dy_2
|
;; dy_2
|
||||||
;; Modifies LDA >dy_2
|
;; Modifies LDA >dy_2
|
||||||
LDA dy_2
|
LDA dy_2
|
||||||
|
@ -68,10 +55,10 @@ selfmod:
|
||||||
;; V
|
;; V
|
||||||
;;Modidies SBC >V
|
;;Modidies SBC >V
|
||||||
LDA V
|
LDA V
|
||||||
STA case_1 + 1
|
STA case_1 + 3
|
||||||
;; Modifies SBC <V
|
;; Modifies SBC <V
|
||||||
LDA V + 1
|
LDA V + 1
|
||||||
STA case_1 + 7
|
STA case_1 + 9
|
||||||
end_selfmod:
|
end_selfmod:
|
||||||
LDA X_end
|
LDA X_end
|
||||||
STA X_pos
|
STA X_pos
|
||||||
|
@ -103,28 +90,27 @@ move_8px_right:
|
||||||
decrement_pixel_x_end:
|
decrement_pixel_x_end:
|
||||||
DEX
|
DEX
|
||||||
BEQ end ;We keep track on when to stop line draw with the X registry.
|
BEQ end ;We keep track on when to stop line draw with the X registry.
|
||||||
;;If D < %00000010 00000000: case_2
|
;;If D < 0 goto case_2
|
||||||
;;else case 1.
|
LDA D + 1
|
||||||
Lag_16 D, D + 1, #$00, #$02, case_2
|
BMI case_2
|
||||||
case_1:
|
case_1:
|
||||||
;; D = D - V
|
;; D = D - V
|
||||||
;; Because Lag_16:
|
;; Because Sub_16 C = 1 so we can use !
|
||||||
;; C =1 so we can use !
|
Sub_16 D, D + 1, #V, #V + 1, !
|
||||||
;; A = >D
|
|
||||||
Sub_16_A D, D + 1, #V, #V + 1, !
|
|
||||||
decrement_y_pos:
|
decrement_y_pos:
|
||||||
DEY ; Increment Y pos inside the buffer
|
DEY ; Increment Y pos inside the buffer
|
||||||
BNE for_x
|
BNE for_x
|
||||||
move_8px_up: ; Z=1 --> C=1
|
move_8px_up:
|
||||||
LDY #$08
|
LDY #$08
|
||||||
;; Switch to chunk bellow
|
;; Switch to chunk bellow
|
||||||
; C = 1
|
; C = 1 or 0
|
||||||
; So we subtract #$40, #$01
|
; So we subtract #$40, #$01
|
||||||
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01, !; +320
|
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01;
|
||||||
JMP for_x
|
JMP for_x
|
||||||
decrement_y_pos_end:
|
decrement_y_pos_end:
|
||||||
case_2:
|
case_2:
|
||||||
Add_16 D, D + 1, #dy_2, #dy_2 + 1, ! ;D = D + 2*dy
|
; dy_2 is one off but C= 1 witch is off as well
|
||||||
|
Add_16 D, D + 1, #dy_2, #dy_2 + 1, ! ;D = D + 2*dy
|
||||||
JMP for_x
|
JMP for_x
|
||||||
end:
|
end:
|
||||||
RTS
|
RTS
|
||||||
|
|
Loading…
Add table
Reference in a new issue