;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;drawing line from 2 cordinates ;;# (X_pos, Y_pos) # ;;# * # ;;# * # ;;# * # ;;# (X_end, Y_end) # ;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Max 45deg! .proc line_down .include "line.inc"; Defines memory positions, ex X_pos ;;We need to clear this memory LDA #$00 STA V +1 STA dy_2 +1 STA $FD ; for pixel_draw ;; V = 2*(dx -dy) SEC LDA dx SBC dy STA V Mult_16 V, V +1 ;dy_2 = dy*2 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 Mov_16 D, D + 1, dy_2, dy_2 +1 Add_16 D, D + 1, #$ff, #$01, ! Sub_16 D, D + 1, dx, #$00 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 ;address that needs to be modified ;; dy_2 ;; Modifies LDA >dy_2 LDA dy_2 STA case_2 +1 ;; Modifies LDA V LDA V STA case_1 +1 ;; Modifies SBC D Sub_16_A D, D + 1, #>V, # C=1 LDY #$00 ;; Switch to chunk bellow ; C = 1 ; So we subtract #$3F, #$01 +C Add_16 btp_mem_pos, btp_mem_pos +1, #$3F, #$01, !; +320 JMP for_x increment_y_pos_end: case_2: Add_16 D, D + 1, #>dy_2, #