From 737ebbbe511cc93e7fdf012eaff59e9535d7bbcf Mon Sep 17 00:00:00 2001 From: hugova Date: Thu, 1 May 2025 16:17:42 +0200 Subject: [PATCH] Add more skeleton code for future triangle drawing --- wip-hugo/routines/line/line_down.s | 3 +- wip-hugo/routines/line/line_test.s | 2 + wip-hugo/routines/triangle/lower_triangle.s | 6 +++ wip-hugo/routines/triangle/triangle.inc | 2 + wip-hugo/routines/triangle/triangle.s | 41 ++++++++------------- wip-hugo/routines/triangle/triangle_test.s | 14 ++++--- wip-hugo/routines/triangle/upper_triangle.s | 31 ++++++++++++++++ wip-hugo/source.s | 2 +- 8 files changed, 67 insertions(+), 34 deletions(-) create mode 100644 wip-hugo/routines/triangle/lower_triangle.s create mode 100644 wip-hugo/routines/triangle/upper_triangle.s diff --git a/wip-hugo/routines/line/line_down.s b/wip-hugo/routines/line/line_down.s index a924e30..9b34434 100644 --- a/wip-hugo/routines/line/line_down.s +++ b/wip-hugo/routines/line/line_down.s @@ -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. diff --git a/wip-hugo/routines/line/line_test.s b/wip-hugo/routines/line/line_test.s index 7e46c90..1db169c 100644 --- a/wip-hugo/routines/line/line_test.s +++ b/wip-hugo/routines/line/line_test.s @@ -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_ diff --git a/wip-hugo/routines/triangle/lower_triangle.s b/wip-hugo/routines/triangle/lower_triangle.s new file mode 100644 index 0000000..c628a6f --- /dev/null +++ b/wip-hugo/routines/triangle/lower_triangle.s @@ -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 diff --git a/wip-hugo/routines/triangle/triangle.inc b/wip-hugo/routines/triangle/triangle.inc index b53011f..9f66a22 100644 --- a/wip-hugo/routines/triangle/triangle.inc +++ b/wip-hugo/routines/triangle/triangle.inc @@ -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 diff --git a/wip-hugo/routines/triangle/triangle.s b/wip-hugo/routines/triangle/triangle.s index 0a28e50..1dcbd8f 100644 --- a/wip-hugo/routines/triangle/triangle.s +++ b/wip-hugo/routines/triangle/triangle.s @@ -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 diff --git a/wip-hugo/routines/triangle/triangle_test.s b/wip-hugo/routines/triangle/triangle_test.s index f46bd62..091d325 100644 --- a/wip-hugo/routines/triangle/triangle_test.s +++ b/wip-hugo/routines/triangle/triangle_test.s @@ -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 diff --git a/wip-hugo/routines/triangle/upper_triangle.s b/wip-hugo/routines/triangle/upper_triangle.s new file mode 100644 index 0000000..19ba595 --- /dev/null +++ b/wip-hugo/routines/triangle/upper_triangle.s @@ -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 diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 44893be..6f5e109 100755 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -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"