From e7c061baff5e21d0acce0e586a89d08e3c3af3b4 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 12 Apr 2021 14:47:49 -0400 Subject: [PATCH] hgr: work on sier --- graphics/hgr/tiny_triangles/Makefile | 25 +- graphics/hgr/tiny_triangles/sier_hgr.s | 147 ++++++------ graphics/hgr/tiny_triangles/sier_hplot.s | 214 +++++++++++++++++ graphics/hgr/tiny_triangles/sier_moveright.s | 228 +++++++++++++++++++ 4 files changed, 532 insertions(+), 82 deletions(-) create mode 100644 graphics/hgr/tiny_triangles/sier_hplot.s create mode 100644 graphics/hgr/tiny_triangles/sier_moveright.s diff --git a/graphics/hgr/tiny_triangles/Makefile b/graphics/hgr/tiny_triangles/Makefile index 5ce2145b..a7176e97 100644 --- a/graphics/hgr/tiny_triangles/Makefile +++ b/graphics/hgr/tiny_triangles/Makefile @@ -8,7 +8,7 @@ EMPTY_DISK = ../../../empty_disk/empty.dsk all: triangles.dsk triangles.dsk: HELLO TINY_TRIANGLES XOR MOD9 MOD9_64 WRITING MOVE_RIGHT \ - SIER_HGR RAINBOW_SQUARES + SIER_HGR SIER_HPLOT SIER_MOVERIGHT RAINBOW_SQUARES cp $(EMPTY_DISK) triangles.dsk $(DOS33) -y triangles.dsk SAVE A HELLO $(DOS33) -y triangles.dsk BSAVE -a 0x070 TINY_TRIANGLES @@ -18,6 +18,8 @@ triangles.dsk: HELLO TINY_TRIANGLES XOR MOD9 MOD9_64 WRITING MOVE_RIGHT \ $(DOS33) -y triangles.dsk BSAVE -a 0x300 WRITING $(DOS33) -y triangles.dsk BSAVE -a 0x300 MOVE_RIGHT $(DOS33) -y triangles.dsk BSAVE -a 0x300 SIER_HGR + $(DOS33) -y triangles.dsk BSAVE -a 0x300 SIER_MOVERIGHT + $(DOS33) -y triangles.dsk BSAVE -a 0x300 SIER_HPLOT $(DOS33) -y triangles.dsk BSAVE -a 0x300 RAINBOW_SQUARES ### @@ -57,6 +59,24 @@ SIER_HGR: sier_hgr.o sier_hgr.o: sier_hgr.s ca65 -o sier_hgr.o sier_hgr.s -l sier_hgr.lst +### + +SIER_HPLOT: sier_hplot.o + ld65 -o SIER_HPLOT sier_hplot.o -C $(LINKER_SCRIPTS)/apple2_300.inc + +sier_hplot.o: sier_hplot.s + ca65 -o sier_hplot.o sier_hplot.s -l sier_hplot.lst + +### + +SIER_MOVERIGHT: sier_moveright.o + ld65 -o SIER_MOVERIGHT sier_moveright.o -C $(LINKER_SCRIPTS)/apple2_300.inc + +sier_moveright.o: sier_moveright.s + ca65 -o sier_moveright.o sier_moveright.s -l sier_moveright.lst + + + ### RAINBOW_SQUARES: rainbow_squares.o @@ -98,4 +118,5 @@ move_right.o: move_right.s clean: rm -f *~ *.o *.lst HELLO TINY_TRIANGLES XOR MOD9 MOD9_64 WRITING \ - MOVE_RIGHT SIER_HGR RAINBOW_SQUARES + MOVE_RIGHT SIER_HGR SIER_HPLOT SIER_MOVERIGHT \ + RAINBOW_SQUARES diff --git a/graphics/hgr/tiny_triangles/sier_hgr.s b/graphics/hgr/tiny_triangles/sier_hgr.s index 009dee31..b13382dd 100644 --- a/graphics/hgr/tiny_triangles/sier_hgr.s +++ b/graphics/hgr/tiny_triangles/sier_hgr.s @@ -23,21 +23,24 @@ ; zero page HGR_BITS = $1C +GBASL = $26 GBASH = $27 MASK = $2E COLOR = $30 +HGR_HMASK = $30 HGR_X = $E0 HGR_Y = $E2 HGR_COLOR = $E4 -;XX = $F7 + +SAVEX = $F7 XX_TH = $F8 XX_TL = $F9 -;YY = $FA +YY = $FA YY_TH = $FB YY_TL = $FC -;T_L = $FD -;T_H = $FE +T_L = $FD +T_H = $FE SAVED = $FF ; Soft switches @@ -49,10 +52,18 @@ LORES = $C056 ; Enable LORES graphics ; ROM routines HGR = $F3E2 HGR2 = $F3D8 -HPLOT0 = $F457 -PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0) -GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear) -SETGR = $FB40 +HPOSN = $F411 +HPLOT0 = $F457 +HPLOT1 = $F45A ; skip the HPOSN call +COLOR_SHIFT = $F47E ; shift color for odd/even Y (0..7 or 7..13) +MOVE_RIGHT = $F48A ; move next plot location one to the right +MOVE_DOWN = $F504 ; clc at f504, needed? + ; f505 is applesoft entry point but assumes c? + ; move next plot location one to the right + + ; note moveright/movedown respect HGR_PAGE + +COLORTBL = $F6F6 ;.zeropage @@ -65,19 +76,29 @@ sier: jsr HGR2 ; set FULLGR, sets A=0 -; lda #0 ; start with multiplier 0 -; sta T_L -; sta T_H + lda #0 ; start with multiplier 0 + sta T_L + sta T_H sier_outer: + ldy #$40 + sty GBASH + ldy #0 ; YY starts at 0 + sty YY + sty GBASL sty YY_TL sty YY_TH sier_yloop: + ldy #0 ; y is x/7 + + lda #$FF + sta HGR_HMASK + ; calc YY_T (8.8 fixed point add) ; save space by skipping clc as it's only a slight variation w/o ; clc @@ -88,29 +109,6 @@ sier_yloop: adc T_H sta YY_TH -; txa ; YY ; plot call needs Y/2 -; lsr - -; php - -; bcc even_mask -; ldy #$f0 -; .byte $2C ; bit hack -;even_mask: -; ldy #$0f -; sty MASK - -; jsr GBASCALC ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear) - -; lda GBASH -;draw_page_smc: -; adc #0 -; sta GBASH ; adjust for PAGE1/PAGE2 ($400/$800) - -; plp -; jsr $f806 ; trick to calculate MASK by jumping - ; into middle of PLOT routine - ; reset XX to 0 ldx #0 ; XX @@ -124,63 +122,63 @@ sier_xloop: ; SAVED = XX+(Y*T) ; clc - txa ; XX - adc YY_TH - sta SAVED - + txa ; XX ; 2 + adc YY_TH ; 3 + sta SAVED ; 3 ; calc XX*T ; clc - lda XX_TL - adc T_L - sta XX_TL - lda XX_TH - adc T_H - sta XX_TH - + lda XX_TL ; 3 + adc T_L ; 3 + sta XX_TL ; 3 + lda XX_TH ; 3 + adc T_H ; 3 + sta XX_TH ; 3 ; calc (YY-X_T) - tya ; lda YY - sec - sbc XX_TH + lda YY ; 3 + sec ; 2 + sbc XX_TH ; 3 ; want (YY-(XX*T)) & (XX+(YY*T) - and SAVED + and SAVED ; 3 + ;============ + ; 37 - and #$f0 + + and #$f0 ; 2 beq white black: - lda #00 ; black + lda #0 ; black .byte $2C ; bit trick white: - lda #$ff ; green - sta HGR_COLOR + lda #$ff ; white +color_ready: + sta HGR_BITS - tya ; YY in A - ldy #0 - ; XX in X +no_shift: - jsr HPLOT0 ; plot at (Y,X), (A) - ; at begin, stores A to HGR_Y - ; X to HGR_X and Y to HGR_X+1 - ; destroys X,Y,A - ; Y is XX/7 + jsr HPLOT1 ; plot at current position + jsr MOVE_RIGHT ; move current position right (trashes A) - ldy HGR_Y - ldx HGR_X - - inx ; XX - cpx #255 + ;================================== + inx bne sier_xloop - iny ; YY + ;================================== + + jsr MOVE_DOWN ; X/Y left alone + + inc YY ; repeat until Y=192 + ldy YY cpy #192 bne sier_yloop + ; inc T ; clc lda T_L @@ -194,21 +192,10 @@ no_carry: ; speed up the zoom as it goes inc blah_smc+1 - - ; x is 48 ;flip_pages: -; lda draw_page_smc+1 ; DRAW_PAGE -; beq done_page -; inx -;done_page: - ; X=48 ($30) PAGE1=$C054-$30=$C024 -; ldy $C024,X ; set display page to PAGE1 or PAGE2 - -; eor #$4 ; flip draw page between $400/$800 -; sta draw_page_smc+1 ; DRAW_PAGE +; TODO if frame rate ever gets fast enough jmp sier_outer ; what can we branch on? -T_L: .byte $00 -T_H: .byte $00 + diff --git a/graphics/hgr/tiny_triangles/sier_hplot.s b/graphics/hgr/tiny_triangles/sier_hplot.s new file mode 100644 index 00000000..009dee31 --- /dev/null +++ b/graphics/hgr/tiny_triangles/sier_hplot.s @@ -0,0 +1,214 @@ +; sierpinski-like demo +; based on the code from Hellmood's Memories demo + +; by Vince `deater` Weaver + +; the simple sierpinski you more or less just plot +; X AND Y + +; Hellmood's you plot something more or less like +; COLOR = ( (Y-(X*T)) & (X+(Y*T) ) & 0xf0 +; where T is an incrementing frame value + +; to get speed on 6502/Apple II we change the multiplies to +; a series of 16-bit 8.8 fixed point adds + +; TODO: +; HPLOT timing +; MOVERIGHT timing +; MOVERIGHT MOVEDOWN timing +; LOOKUP TABLE timing + + +; zero page + +HGR_BITS = $1C +GBASH = $27 +MASK = $2E +COLOR = $30 +HGR_X = $E0 +HGR_Y = $E2 +HGR_COLOR = $E4 + +;XX = $F7 +XX_TH = $F8 +XX_TL = $F9 +;YY = $FA +YY_TH = $FB +YY_TL = $FC +;T_L = $FD +;T_H = $FE +SAVED = $FF + +; Soft switches +FULLGR = $C052 +PAGE1 = $C054 +PAGE2 = $C055 +LORES = $C056 ; Enable LORES graphics + +; ROM routines +HGR = $F3E2 +HGR2 = $F3D8 +HPLOT0 = $F457 +PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0) +GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear) +SETGR = $FB40 + + +;.zeropage +;.globalzp T_L,T_H + + ;================================ + ; Clear screen and setup graphics + ;================================ +sier: + jsr HGR2 ; set FULLGR, sets A=0 + + +; lda #0 ; start with multiplier 0 +; sta T_L +; sta T_H + +sier_outer: + + ldy #0 ; YY starts at 0 + + sty YY_TL + sty YY_TH + +sier_yloop: + + ; calc YY_T (8.8 fixed point add) + ; save space by skipping clc as it's only a slight variation w/o +; clc + lda YY_TL + adc T_L + sta YY_TL + lda YY_TH + adc T_H + sta YY_TH + +; txa ; YY ; plot call needs Y/2 +; lsr + +; php + +; bcc even_mask +; ldy #$f0 +; .byte $2C ; bit hack +;even_mask: +; ldy #$0f +; sty MASK + +; jsr GBASCALC ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear) + +; lda GBASH +;draw_page_smc: +; adc #0 +; sta GBASH ; adjust for PAGE1/PAGE2 ($400/$800) + +; plp +; jsr $f806 ; trick to calculate MASK by jumping + ; into middle of PLOT routine + + ; reset XX to 0 + + ldx #0 ; XX + stx XX_TL + stx XX_TH + +sier_xloop: + + ; want (YY-(XX*T)) & (XX+(YY*T) + + + ; SAVED = XX+(Y*T) +; clc + txa ; XX + adc YY_TH + sta SAVED + + + ; calc XX*T +; clc + lda XX_TL + adc T_L + sta XX_TL + lda XX_TH + adc T_H + sta XX_TH + + + ; calc (YY-X_T) + tya ; lda YY + sec + sbc XX_TH + + ; want (YY-(XX*T)) & (XX+(YY*T) + + and SAVED + + and #$f0 + + beq white +black: + lda #00 ; black + .byte $2C ; bit trick +white: + lda #$ff ; green + sta HGR_COLOR + + + tya ; YY in A + ldy #0 + ; XX in X + + jsr HPLOT0 ; plot at (Y,X), (A) + ; at begin, stores A to HGR_Y + ; X to HGR_X and Y to HGR_X+1 + ; destroys X,Y,A + ; Y is XX/7 + + + ldy HGR_Y + ldx HGR_X + + inx ; XX + cpx #255 + bne sier_xloop + + iny ; YY + cpy #192 + bne sier_yloop + + ; inc T +; clc + lda T_L +blah_smc: + adc #1 + sta T_L + bcc no_carry + inc T_H +no_carry: + + ; speed up the zoom as it goes + inc blah_smc+1 + + + ; x is 48 +;flip_pages: +; lda draw_page_smc+1 ; DRAW_PAGE +; beq done_page +; inx +;done_page: + ; X=48 ($30) PAGE1=$C054-$30=$C024 +; ldy $C024,X ; set display page to PAGE1 or PAGE2 + +; eor #$4 ; flip draw page between $400/$800 +; sta draw_page_smc+1 ; DRAW_PAGE + + jmp sier_outer ; what can we branch on? + +T_L: .byte $00 +T_H: .byte $00 + diff --git a/graphics/hgr/tiny_triangles/sier_moveright.s b/graphics/hgr/tiny_triangles/sier_moveright.s new file mode 100644 index 00000000..a58eca38 --- /dev/null +++ b/graphics/hgr/tiny_triangles/sier_moveright.s @@ -0,0 +1,228 @@ +; sierpinski-like demo +; based on the code from Hellmood's Memories demo + +; by Vince `deater` Weaver + +; the simple sierpinski you more or less just plot +; X AND Y + +; Hellmood's you plot something more or less like +; COLOR = ( (Y-(X*T)) & (X+(Y*T) ) & 0xf0 +; where T is an incrementing frame value + +; to get speed on 6502/Apple II we change the multiplies to +; a series of 16-bit 8.8 fixed point adds + +; TODO: +; HPLOT timing +; MOVERIGHT timing +; MOVERIGHT MOVEDOWN timing +; LOOKUP TABLE timing + + +; zero page + +HGR_BITS = $1C +GBASH = $27 +MASK = $2E +COLOR = $30 +HGR_X = $E0 +HGR_Y = $E2 +HGR_COLOR = $E4 + + +SAVEX = $F7 +XX_TH = $F8 +XX_TL = $F9 +YY = $FA +YY_TH = $FB +YY_TL = $FC +;T_L = $FD +;T_H = $FE +SAVED = $FF + +; Soft switches +FULLGR = $C052 +PAGE1 = $C054 +PAGE2 = $C055 +LORES = $C056 ; Enable LORES graphics + +; ROM routines +HGR = $F3E2 +HGR2 = $F3D8 +HPOSN = $F411 +HPLOT0 = $F457 +HPLOT1 = $F45A ; skip the HPOSN call +COLOR_SHIFT = $F47E ; shift color for odd/even Y (0..7 or 7..13) +MOVE_RIGHT = $F48A ; move next plot location one to the right + +COLORTBL = $F6F6 + + +;.zeropage +;.globalzp T_L,T_H + + ;================================ + ; Clear screen and setup graphics + ;================================ +sier: + jsr HGR2 ; set FULLGR, sets A=0 + + +; lda #0 ; start with multiplier 0 +; sta T_L +; sta T_H + +sier_outer: + + ldy #0 ; YY starts at 0 + sty YY + + sty YY_TL + sty YY_TH + +sier_yloop: + + ; calc YY_T (8.8 fixed point add) + ; save space by skipping clc as it's only a slight variation w/o +; clc + lda YY_TL + adc T_L + sta YY_TL + lda YY_TH + adc T_H + sta YY_TH + + ; XX in X + ; YY in YY + + ldy #0 + ldx #0 ; XX = 0 + lda YY ; Y co-ord + jsr HPOSN ; set cursor position to (Y,X), (A) + +; ldy HGR_Y + +; lda GBASH +;draw_page_smc: +; adc #0 +; sta GBASH ; adjust for PAGE1/PAGE2 ($400/$800) + +; plp +; jsr $f806 ; trick to calculate MASK by jumping + ; into middle of PLOT routine + + ; reset XX to 0 + + ldx #0 ; XX + stx XX_TL + stx XX_TH + +sier_xloop: + + stx SAVEX + + ; want (YY-(XX*T)) & (XX+(YY*T) + + + ; SAVED = XX+(Y*T) +; clc + txa ; XX + adc YY_TH + sta SAVED + + + ; calc XX*T +; clc + lda XX_TL + adc T_L + sta XX_TL + lda XX_TH + adc T_H + sta XX_TH + + + ; calc (YY-X_T) + lda YY + sec + sbc XX_TH + + ; want (YY-(XX*T)) & (XX+(YY*T) + + and SAVED + + and #$f0 + + beq white +black: + lda #0 ; black + .byte $2C ; bit trick +white: + lda #$ff ; white + +color_ready: +; tax + +; tya +; lsr ; check even or odd +; php + +; lda COLORTBL,X + sta HGR_BITS + +; plp +; bcc no_shift + +; jsr COLOR_SHIFT ; if odd then color shift + +no_shift: + + jsr HPLOT1 ; plot at current position + + jsr MOVE_RIGHT ; move current position right (trashes A) + + ldx SAVEX ; restore X + + + ;================================== + inx ; XX + bne sier_xloop + + ;================================== + inc YY ; repeat until Y=192 + ldy YY + cpy #192 + bne sier_yloop + + + ; inc T +; clc + lda T_L +blah_smc: + adc #1 + sta T_L + bcc no_carry + inc T_H +no_carry: + + ; speed up the zoom as it goes + inc blah_smc+1 + + + ; x is 48 +;flip_pages: +; lda draw_page_smc+1 ; DRAW_PAGE +; beq done_page +; inx +;done_page: + ; X=48 ($30) PAGE1=$C054-$30=$C024 +; ldy $C024,X ; set display page to PAGE1 or PAGE2 + +; eor #$4 ; flip draw page between $400/$800 +; sta draw_page_smc+1 ; DRAW_PAGE + + jmp sier_outer ; what can we branch on? + +T_L: .byte $00 +T_H: .byte $00 +