Add more skeleton code for future triangle drawing

This commit is contained in:
hugova 2025-05-01 16:17:42 +02:00
parent c27e79efa6
commit 737ebbbe51
8 changed files with 67 additions and 34 deletions

View file

@ -9,9 +9,9 @@
;;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
@ -42,7 +42,6 @@
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.

View file

@ -3,6 +3,7 @@
;; Program for testing of line-drawing. It draws a bunch of lines
;;Start line-timer-here
.include "line.inc"
Y_pos_ = $0D
X_pos_ = $0E
Y_end_ = $10
@ -31,6 +32,7 @@
jmp @loop
end__:
;; Full anfle test
@loop:
LDA Y_pos_

View file

@ -0,0 +1,6 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; This is a help program for triangle.s to draw the lower triangle
.scope lower_triangle
NOP
.endscope

View file

@ -1,3 +1,5 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;The triangles 3 corner-positions, they may be in any given order.
A_X = $EA
A_Y = $E9

View file

@ -1,6 +1,8 @@
.proc triangle
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; Subroutine for drawing a filld triangle.
;; It takes in values from A_X, A_Y, B_X, B_Y C_X, C_Y, see triangle.inc
.proc triangle
;; It takes in values from A_X, A_Y, B_X, B_Y C_X, C_Y, see triangle.inc
.include "triangle.inc"
;; Algorithm
@ -19,7 +21,7 @@
;; * AB for differense betwean A and B
;; * BC for differense betwean B and C
;;AB
;;AB
SEC
LDA B_Y
SBC A_Y
@ -38,12 +40,12 @@ AB_overflow:
STX A_X
STY B_X
AB_overflow_end:
;;BC
SEC
LDA C_Y
SBC B_Y
STA BC
BCC BC_overflow_end
;;BC
SEC
LDA C_Y
SBC B_Y
STA BC
BCC BC_overflow_end
;; B_Y > C_Y
BC_overflow:
EOR #$ff ; Fix byte underflow
@ -61,20 +63,9 @@ BC_overflow:
BC_overflow_end:
draw_upper_triangle:
# This triangle has 10 posibol cases, see table bellow
# ----------------------------------------------------
# | name left_side right_side |
# ----------------------------------------------------
# | RR right-sloaping-steep right-sloaping-steep|
# | rR right-sloaping right-sloaping-steep|
# | lR left-sloaping right-sloaping-steep|
# | LR left-sloaping-steep right-sloaping-steep|
# | rr right-sloaping right-sloaping |
# | lr left-sloaping right-sloaping |
# | Lr left-sloaping-steep right-sloaping |
# | ll left-sloaping left-sloaping |
# | Ll left-sloaping-sleep left-sloaping |
# | LL left-sloaping-sleep left-sloaping-sleep |
# ----------------------------------------------------
RTS
.include "upper_triangle.s"
draw_lower_triangle:
;;This has the same cases as upper triangle
.include "lower_triangle.s"
RTS
.endproc

View file

@ -1,5 +1,7 @@
.scope triangle_test
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; Test program that tries to draw a triangle
.scope triangle_test
.include "triangle.inc"
LDA #$33
STA A_X
@ -22,17 +24,17 @@ edges:
;;; A -- B
Mov_16 X_pos, Y_pos, A_X, A_Y
Mov_16 X_end, Y_end, B_X, B_Y
jsr line
JSR line
;;; A -- C
Mov_16 X_pos, Y_pos, A_X, A_Y
Mov_16 X_end, Y_end, C_X, C_Y
jsr line
JSR line
;;; B -- C
Mov_16 X_pos, Y_pos, C_X, C_Y
Mov_16 X_end, Y_end, B_X, B_Y
jsr line
JSR line
skip_edges:
;; lets draw the example triangle
jsr triangle
jmp exit
JSR triangle
JMP exit
.endscope

View file

@ -0,0 +1,31 @@
;; Test program that tries to draw a triangle
;; This is a help program for triangle.s to draw the upper triangle
;; We know that (se triangle.inc)
;; (i) A is at the highest point
;; (ii) B is at the middle point
;; (iii) C is at the lowest point
;; This triangle has 10 posibol cases, see table bellow
;; ----------------------------------------------------
;; | name left_side right_side |
;; ----------------------------------------------------
;; | RR right-sloaping-steep right-sloaping-steep|
;; | rR right-sloaping right-sloaping-steep|
;; | lR left-sloaping right-sloaping-steep|
;; | LR left-sloaping-steep right-sloaping-steep|
;; | rr right-sloaping right-sloaping |
;; | lr left-sloaping right-sloaping |
;; | Lr left-sloaping-steep right-sloaping |
;; | ll left-sloaping left-sloaping |
;; | Ll left-sloaping-sleep left-sloaping |
;; | LL left-sloaping-sleep left-sloaping-sleep |
;; ----------------------------------------------------
.scope upper_triangle
LDA #$00
;; Lets for the sake of it say its a lr triangle
;; we need to compute V_l, V_r, dy_2l, dy_2_r, D_l, and D_r
.endscope

View file

@ -10,7 +10,7 @@
;.include "routines/memory/memcpy_test.s"
.include "routines/triangle/triangle_test.s"
exit:
jmp exit
JMP exit
.include "routines/line/line.s"
.include "routines/triangle/triangle.s"
.include "routines/memory/pixel_draw.s"