diff --git a/wip-hugo/routines/line/line_down.s b/wip-hugo/routines/line/line_down.s index a947cf9..8143a52 100644 --- a/wip-hugo/routines/line/line_down.s +++ b/wip-hugo/routines/line/line_down.s @@ -17,16 +17,12 @@ STA $FD ; for pixel_draw ;; V = 2*(dx -dy) - ;; where: dy = Y_end - Y_start, dx = OO - X_start - LDA Y_end SEC + LDA Y_end SBC Y_pos STA >V STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V) - LDA X_end - SEC - SBC X_pos - STA dx + LDA dx SEC SBC >V STA >V; dy_2, =V. - ;; V_max = 00000001 11111111 - ;; For us to work with unsigned numbers we add 00000001 11111111 - ;; to V and the branch logic to V! + + ;; 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 - ;;Our D is bigger then wikipedia because D is unsigned. LDA >dy_2 STA >D LDA btp_mem_pos), Y STA (>btp_mem_pos), Y increment_pixel_x: - LSR byte_to_paint - BCC increment_pixel_x_end + LSR byte_to_paint ; Rotates the pixel one bit to the left ON THE SCREEN. + BCC increment_pixel_x_end; We need to move to the next chunk move_8px_left: - ;; add +8 to btp_mem_pos. Find more of why in pixel_draw + ;; Next chunk is 8 addresses away. Look in pixel_draw for more detail. Add_16 >btp_mem_pos, D, D, V, C=1 LDY #$00 + ;; Switch to chunk bellow Add_16 >btp_mem_pos, V - STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V) + STA >dx_2 LDA Y_end SEC SBC Y_pos STA dy + SEC SBC >V - STA >V; V, V + mult_16 >V, dx_2, dx_2 STA >D LDA D, D, btp_mem_pos, btp_mem_pos, D, D, V, D, V, btp_mem_pos, D, dx_2, = Y_end. Max 45deg! .proc line_up - .include "line.inc"; Defines memory positions, ex X_pos - - ;;We need to clear this memory + ;; Look at line_down for referense + .include "line.inc" LDA #$00 STA V - STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V) - LDA X_end - SEC - SBC X_pos - STA dx + STA >dy_2 + LDA dx SEC SBC >V - STA >V; V, V + mult_16 >V, dy_2, =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 - ;;Our D is bigger then wikipedia because D is unsigned. LDA >dy_2 STA >D LDA btp_mem_pos, btp_mem_pos, D, dy_2, D, dy_2, ) Y_end, X_pos <= X_end. Min 45deg! .proc line_up_inv + ;; Look at line_down for referense .include "line.inc" - ;We need to clear this memory LDA #$00 STA V - STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V) + STA >dx_2 LDA Y_pos SEC SBC Y_end STA dy SEC SBC >V - STA >V; V, V + mult_16 >V, dx_2, dx_2 STA >D LDA btp_mem_pos, btp_mem_pos, D, D, V, D, V, btp_mem_pos, D, dx_2, D, dx_2,