From 36f8287f87570cd771852cd78dd11c38c7ed51ba Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 27 Sep 2022 16:00:36 -0400 Subject: [PATCH] hgr: parallax: sier --- graphics/hgr/parallax/Makefile | 12 +++- graphics/hgr/parallax/sier.s | 111 +++++++++++++++++---------------- 2 files changed, 69 insertions(+), 54 deletions(-) diff --git a/graphics/hgr/parallax/Makefile b/graphics/hgr/parallax/Makefile index c8312656..e4e8d2c3 100644 --- a/graphics/hgr/parallax/Makefile +++ b/graphics/hgr/parallax/Makefile @@ -8,7 +8,7 @@ TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft all: paralax.dsk -paralax.dsk: HELLO BOXES PAR WEIRD +paralax.dsk: HELLO BOXES PAR WEIRD SIER cp $(EMPTY_DISK) paralax.dsk $(DOS33) -y paralax.dsk SAVE A HELLO $(DOS33) -y paralax.dsk BSAVE -a 0xc00 BOXES @@ -18,6 +18,7 @@ paralax.dsk: HELLO BOXES PAR WEIRD $(DOS33) -y paralax.dsk BSAVE -a 0x3f5 PAR # $(DOS33) -y paralax.dsk BSAVE -a 0x37B PAR_BOT $(DOS33) -y paralax.dsk BSAVE -a 0xc00 WEIRD + $(DOS33) -y paralax.dsk BSAVE -a 0xc00 SIER ### @@ -52,6 +53,15 @@ WEIRD: weird.o weird.o: weird.s ca65 -o weird.o weird.s -l weird.lst +### + +SIER: sier.o + ld65 -o SIER sier.o -C $(LINKER_DIR)/apple2_c00.inc + +sier.o: sier.s + ca65 -o sier.o sier.s -l sier.lst + + diff --git a/graphics/hgr/parallax/sier.s b/graphics/hgr/parallax/sier.s index fe4907c7..038bbea4 100644 --- a/graphics/hgr/parallax/sier.s +++ b/graphics/hgr/parallax/sier.s @@ -1,7 +1,10 @@ -; Parallax HGR +; Parallax Sierpinski/xor boxes HGR ; by deater (Vince Weaver) +; Already heavily optimized: +; frame 0: 27c78 = 162,936 cycles = roughly 6.1 fps +; frame 1: 27ba8 ; Zero Page GBASL = $26 @@ -39,7 +42,8 @@ HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y) hgr_lookup_h = $1000 hgr_lookup_l = $1100 -div4_lookup = $1200 +div4_lookup = $90 + parallax: @@ -64,19 +68,27 @@ init_loop: and #$1F ; 20 30 001X 40 50 010X sta hgr_lookup_h,X - txa - asl - asl - sta div4_lookup,X dex cpx #$ff bne init_loop + ldx #39 +div4_loop: + txa + asl + asl + sta div4_lookup,X + dex + bpl div4_loop + parallax_forever: - inc FRAME ; 5 + ; increment offsets + + inc large_smc+1 ; 6 + inc medium_smc+1 ; 6 ;======================== ; flip page @@ -90,88 +102,81 @@ parallax_forever: asl rol eor #$1 - tay - lda PAGE1,Y + tax + lda PAGE1,X ; flip show_page - ldx #127 ; init Y + ldy #159 ; init Y yloop: ;============== ; point output to current line - lda hgr_lookup_l,X - sta out_smc+1 - lda hgr_lookup_h,X - ora HGR_PAGE - sta out_smc+2 + lda hgr_lookup_l,Y ; 4+ + sta out_smc+1 ; 4 + lda hgr_lookup_h,Y ; 4+ + ora HGR_PAGE ; 3 + sta out_smc+2 ; 4 ;============== ; current column (work backwards) - ldy #39 ; 2 + ldx #39 ; 2 xloop: -; lda div4_lookup,Y ; 4+ -; sta X2 ; 3 - ;=========================== - ; LARGE + ; Boxes - txa ; 2 + tya ; 2 -; carry always clear here? -; sec ; subtract frame from Y - sbc FRAME ; 3 + ; carry always clear here? +large_smc: + sbc #$DD ; 2 + eor div4_lookup,X ; 4 + and #$40 ; 2 - eor div4_lookup,Y ; 4+ - and #$40 ; 2 + bne draw_white ; 2/3 + + ; 0 means transparent - beq skip_color_large ; 2/3 - lda #$ff ; 2 - bne draw_color ; 2/3 skip_color_large: ;=========================== - ; MEDIUM + ; Sierpinski - txa ; 2 + tya ; 2 +medium_smc: + adc #$DD ; go other way ; 2 + and div4_lookup,X ; sierpinski ; 4 - sec ; subtract frame from Y ; 2 - - adc FRAME ; go other way ; 3 - - and div4_lookup,Y ; sierpinski ; 4+ - - bne skip_color_medium - lda #$55 - bne draw_color -skip_color_medium: - - ; fallthrough is black + bne draw_black ; draw black ; 2/3 +draw_purple: + lda #$55 ; purple/green ; 2 + bne draw_color ; bra ; 3 +draw_black: lda #$00 ; 2 + beq draw_color ; bra ; 3 + ; white block +draw_white: + lda #$7f ; 2 ;======================== ; actually draw color draw_color: out_smc: - sta $2000,Y ; 5 - - dey ; 2 - bpl xloop ; 2/3 + sta $2000,X ; 5 dex ; 2 + bpl xloop ; 2/3 - bpl yloop ; 2/3 + dey ; 2 + cpy #32 ; 2 + bne yloop ; 2/3 - bmi parallax_forever ; 2/3 + beq parallax_forever ; 2/3 -; for bot - ; $3F5 - 127 + 3 = $379 - -; jmp parallax