From 89d706cb0efbbcf428b01843dc0555cab0fd3f9c Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 28 Mar 2021 18:04:19 -0400 Subject: [PATCH] graphics: lines: look into recursive --- graphics/gr/lines/Makefile | 13 ++- graphics/gr/lines/lines_recurse.s | 138 ++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 graphics/gr/lines/lines_recurse.s diff --git a/graphics/gr/lines/Makefile b/graphics/gr/lines/Makefile index 84575fff..8a2dddee 100644 --- a/graphics/gr/lines/Makefile +++ b/graphics/gr/lines/Makefile @@ -7,7 +7,7 @@ EMPTYDISK = ../../../empty_disk/empty.dsk all: lines.dsk -lines.dsk: HELLO LINES LINES_SMALL LINES_ROM LINES_WIKI LINES_BOT +lines.dsk: HELLO LINES LINES_SMALL LINES_ROM LINES_WIKI LINES_BOT LINES_RECURSE cp $(EMPTYDISK) lines.dsk $(DOS33) -y lines.dsk SAVE A HELLO $(DOS33) -y lines.dsk BSAVE -a 0xC00 LINES @@ -15,6 +15,7 @@ lines.dsk: HELLO LINES LINES_SMALL LINES_ROM LINES_WIKI LINES_BOT $(DOS33) -y lines.dsk BSAVE -a 0xC00 LINES_ROM $(DOS33) -y lines.dsk BSAVE -a 0xC00 LINES_WIKI $(DOS33) -y lines.dsk BSAVE -a 0x36B LINES_BOT + $(DOS33) -y lines.dsk BSAVE -a 0xC00 LINES_RECURSE ### @@ -55,6 +56,14 @@ lines_wiki.o: lines_wiki.s ### +LINES_RECURSE: lines_recurse.o + ld65 -o LINES_RECURSE lines_recurse.o -C $(LINKERSCRIPTS)/apple2_c00.inc + +lines_recurse.o: lines_recurse.s + ca65 -o lines_recurse.o lines_recurse.s -l lines_recurse.lst + +### + LINES_BOT: lines_bot.o ld65 -o LINES_BOT lines_bot.o -C ./apple2_36b.inc @@ -64,4 +73,4 @@ lines_bot.o: lines_bot.s ### clean: - rm -f *~ *.o *.lst HELLO LINES LINES_SMALL LINES_ROM LINES_WIKI LINES_BOT + rm -f *~ *.o *.lst HELLO LINES LINES_SMALL LINES_ROM LINES_WIKI LINES_BOT LINES_RECURSE diff --git a/graphics/gr/lines/lines_recurse.s b/graphics/gr/lines/lines_recurse.s new file mode 100644 index 00000000..7b2aed89 --- /dev/null +++ b/graphics/gr/lines/lines_recurse.s @@ -0,0 +1,138 @@ +; Bresenham Lines + +; by Vince `deater` Weaver + +; http://www.retroprogramming.com/2016/05/divide-and-conquer-line-algorithm-for.html + +.include "zp.inc" +.include "hardware.inc" + +B_X1 = $F0 +B_Y1 = $F1 +B_X2 = $F2 +B_Y2 = $F3 +COUNT = $F9 + +X1 = $1000 +Y1 = $1100 +X2 = $1200 +Y2 = $1300 +MIDX = $1400 +MIDY = $1500 + +lines: + + jsr SETGR ; set lo-res 40x40 mode + ; A=$D0 afterward + +restart: + lda #0 + sta COUNT +lines_loop: + + jsr NEXTCOL + + lda #0 + sta X1 + lda #36 + sta Y2 + + lda COUNT + cmp #10 +;end: + beq restart + + asl + asl + sta Y1 + sta X2 + + jsr draw_line + + inc COUNT + + jmp lines_loop + + + + ;============================ + ; draw line + ; from x1,y1 to x2,y2 + ;============================ +draw_line: + ldx #0 +draw_recurse: + +;int draw ( ax, ay, bx, by ) +;{ +; int midx, midy; +; midx = ( ax+bx ) / 2; +; midy = ( ay+by ) / 2; +; if ( midx != ax && midy != ay ) +; { +; draw( midx, midy, ax, ay ); +; draw( bx, by, midx, midy ); +; plot( midx, midy ); +; } +;} + + clc + lda X1,X + adc X2,X + lsr + sta MIDX,X + tay + + clc + lda Y1,X + adc Y2,X + lsr + sta MIDY,X + ; plot midx,midy + jsr PLOT ;; PLOT AT Y,A (A colors output, Y preserved) + + ; check if done + + lda X1,X + cmp MIDX,X + bne recurse + + lda Y1,X + cmp MIDY,X + beq done_draw_line + +recurse: + ; draw( ax, ay, midx, midy); + lda MIDX,X + sta X1+1,X + lda MIDY,X + sta Y1+1,X + lda X1,X + sta X2+1,X + lda Y1,X + sta Y2+1,X + + inx + + jsr draw_recurse + + ; draw( bx, by, midx, midy ); + + lda X2,X + sta X1+1,X + lda Y2,X + sta Y1+1,X + lda MIDX,X + sta X2+1,X + lda MIDY,X + sta Y2+1,X + + inx + + jsr draw_recurse + +done_draw_line: + dex + rts + +