Propergate optimisations from line_down.s to the other line_*.s files

This commit is contained in:
hugova 2025-03-29 16:16:47 +01:00
parent be3e9582ba
commit 46a52661b8
6 changed files with 66 additions and 72 deletions

View file

@ -5,10 +5,10 @@
Y_end = $05
X_pos = $FC
Y_pos = $FB
dy= $0c
dx = dy
dx = $0c
dy = $06
dy_2 = $0607
dx_2 = dy_2
dx_2 = $0cF3
V = $0809
D = $0a0b
;;These are also used in pixel_draw. Look there to find out more

View file

@ -35,6 +35,8 @@ down:
CMP dx
BCC shallow_; dy < dx
steep_:
;LDA dx
jsr line_down_inv
RTS
shallow_: ;dy < dx

View file

@ -10,24 +10,7 @@
.proc line_down
;; TEMPORARY
;; Hack because changing dx and dy makes other line draws bugg and idk why
;; This is offcorse temporary
;.include "line.inc"; Defines memory positions, ex X_pos
X_end = $04
Y_end = $05
X_pos = $FC
Y_pos = $FB
dx = $0c
dy = $06
dy_2 = $0607
dx_2 = dy_2
V = $0809
D = $0a0b
;;These are also used in pixel_draw. Look there to find out more
byte_to_paint = $FE ;Byte with one 1 that corasponds to a pixel.
btp_mem_pos =$494A; byte to paint memory position ;Position of byte on screen
;;END TEMPORARY
.include "line.inc"; Defines memory positions, ex X_pos
;;We need to clear this memory
LDA #$00
@ -63,7 +46,7 @@
jsr pixel_draw ;;only used first pixel. after this relative position is abused
LDX X_pos
selfmod:
selfmod:
;; 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.
;;Note: The offsets like +2 etc is because there are instructions betwean the label and the
@ -82,7 +65,7 @@
;; Modifies SBC <V
LDA <V
STA case_1 +9
end_selfmod:
end_selfmod:
for_x:
;; Paints A to address in |btp_mem_pos* + Y|

View file

@ -8,35 +8,38 @@
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Min 45deg!
.proc line_down_inv
;; Look at line_down for referense
.include "line.inc"
;; Look at line_down for referense
.include "line.inc"; Defines memory positions, ex X_pos
LDA #$00
STA <V
STA <dx_2
STA $FD
LDA dx
STA >V
STA >dx_2
LDA Y_end
SEC
SBC Y_pos
STA dy
SEC
SBC >V
LDA dy
SBC dx
STA >V
Mult_16 >V, <V
Mult_16 >dx_2, <dx_2
LDA >dx_2
STA >D
LDA <dx_2
STA <D
Add_16 >D, <D, #$ff, #$01
Mov_16 >D, <D, >dx_2, <dx_2
Add_16 >D, <D, #$ff, #$01, !
Sub_16 >D, <D, dy, #$00
selfmod:
LDA >dx_2
STA case_2 +1
LDA <dx_2
STA case_2 +7
LDA >V
STA case_1 +3
LDA <V
STA case_1 +9
end_selfmod:
jsr pixel_draw
LDX Y_pos
for_y:
@ -49,14 +52,14 @@ increment_y_pos:
BNE increment_y_pos_end
move_8px_down:
LDY #$00
Add_16 >btp_mem_pos, <btp_mem_pos,#$40 , #$01;
Add_16 >btp_mem_pos, <btp_mem_pos, #$40 ,#$01
increment_y_pos_end:
INX
CPX Y_end
BEQ end
Lag_16 >D, <D, #$00, #$02, case_2
case_1:
Sub_16 >D, <D, >V, <V, !
Sub_16 >D, <D, #>V, #<V, !
increment_pixel_x:
LDA byte_to_paint
LSR byte_to_paint
@ -67,7 +70,7 @@ move_8px_left:
STA byte_to_paint
JMP for_y
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
end:
RTS

View file

@ -11,32 +11,36 @@
.proc line_up
;; Look at line_down for referense
.include "line.inc"
.include "line.inc"; Defines memory positions, ex X_pos
LDA #$00
STA <V
STA <dy_2
STA $FD
LDA Y_pos
SEC
SBC Y_end
STA >V
STA >dy_2
LDA dx
SEC
SBC >V
SBC dy
STA >V
Mult_16 >V, <V
Mult_16 >dy_2, <dy_2, !
Mult_16 >dy_2, <dy_2
LDA >dy_2
STA >D
LDA <dy_2
STA <D
Mov_16 >D, <D, >dy_2, <dy_2
Add_16 >D, <D, #$ff, #$01, !
Sub_16 >D, <D, dx, #$00
selfmod:
LDA >dy_2
STA case_2 +1
LDA <dy_2
STA case_2 +7
LDA >V
STA case_1 +3
LDA <V
STA case_1 +9
end_selfmod:
jsr pixel_draw
LDX X_pos
for_x:
@ -56,7 +60,7 @@ increment_pixel_x_end:
BEQ end
Lag_16 >D, <D, #$00, #$02, case_2
case_1:
Sub_16 >D, <D, >V, <V, !
Sub_16 >D, <D, #>V, #<V, !
decrement_y_pos:
DEY
CPY #$ff
@ -67,7 +71,7 @@ move_8px_up:
jmp for_x
decrement_y_pos_end:
case_2:
Add_16 >D, <D, >dy_2, <dy_2, !
Add_16 >D, <D, #>dy_2, #<dy_2, !
JMP for_x
end:
RTS

View file

@ -10,34 +10,36 @@
.proc line_up_inv
;; Look at line_down for referense
.include "line.inc"
.include "line.inc"; Defines memory positions, ex X_pos
LDA #$00
STA <V
STA <dx_2
STA $FD
LDA dx
STA >V
STA >dx_2
LDA Y_pos
SEC
SBC Y_end
STA dy
SEC
SBC >V
LDA dy
SBC dx
STA >V
Mult_16 >V, <V
Mult_16 >dx_2, <dx_2
LDA >dx_2
STA >D
LDA <dx_2
STA <D
Add_16 >D, <D, #$ff, #$01
Mov_16 >D, <D, >dx_2, <dx_2
Add_16 >D, <D, #$ff, #$01, !
Sub_16 >D, <D, dy, #$00
selfmod:
LDA >dx_2
STA case_2 +1
LDA <dx_2
STA case_2 +7
LDA >V
STA case_1 +3
LDA <V
STA case_1 +9
end_selfmod:
jsr pixel_draw
LDX Y_pos
for_y:
@ -57,7 +59,7 @@ decrement_y_pos_end:
BEQ end
Lag_16 >D, <D, #$00, #$02, case_2
case_1:
Sub_16 >D, <D, >V, <V, !
Sub_16 >D, <D, #>V, #<V, !
increment_pixel_x:
LDA byte_to_paint
LSR byte_to_paint
@ -68,7 +70,7 @@ move_8px_left:
STA byte_to_paint
JMP for_y
case_2:
Add_16 >D, <D, >dx_2, <dx_2,!
Add_16 >D, <D, #>dx_2, #<dx_2, !
JMP for_y
end:
RTS