From 26935161906772c6e3ae4b821fad239ad737c420 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 31 Dec 2018 11:29:12 -0500 Subject: [PATCH] fire_tiny: shave some more bytes off by reducing lookup table --- fire/Makefile | 14 ++++- fire/cool_effect.s | 154 +++++++++++++++++++++++++++++++++++++++++++++ fire/fire_tiny.s | 57 ++++++++++++----- 3 files changed, 208 insertions(+), 17 deletions(-) create mode 100644 fire/cool_effect.s diff --git a/fire/Makefile b/fire/Makefile index b70a71bb..a2631bde 100644 --- a/fire/Makefile +++ b/fire/Makefile @@ -6,10 +6,11 @@ PNG_TO_RLE = ../gr-utils/png2rle all: fire.dsk -fire.dsk: FIRE FIRE_TINY HELLO +fire.dsk: FIRE FIRE_TINY HELLO COOL_EFFECT $(DOS33) -y fire.dsk SAVE A HELLO $(DOS33) -y fire.dsk BSAVE -a 0x1000 FIRE $(DOS33) -y fire.dsk BSAVE -a 0x70 FIRE_TINY + $(DOS33) -y fire.dsk BSAVE -a 0x70 COOL_EFFECT #### @@ -29,6 +30,15 @@ fire_tiny.o: fire_tiny.s ca65 -o fire_tiny.o fire_tiny.s -l fire_tiny.lst +#### + +COOL_EFFECT: cool_effect.o + ld65 -o COOL_EFFECT cool_effect.o -C ../linker_scripts/apple2_70.inc + +cool_effect.o: cool_effect.s + ca65 -o cool_effect.o cool_effect.s -l cool_effect.lst + + #### @@ -39,6 +49,6 @@ HELLO: hello.bas ##### clean: - rm -f *~ *.o *.lst FIRE FIRE_TINY HELLO + rm -f *~ *.o *.lst FIRE FIRE_TINY COOL_EFFECT HELLO diff --git a/fire/cool_effect.s b/fire/cool_effect.s new file mode 100644 index 00000000..71f1c080 --- /dev/null +++ b/fire/cool_effect.s @@ -0,0 +1,154 @@ +; Lo-res fire animation, size-optimized + +; by deater (Vince Weaver) + +; based on code described here http://fabiensanglard.net/doom_fire_psx/ + +; 611 bytes at first +; 601 bytes -- strip out some unused code +; 592 bytes -- don't init screen +; 443 bytes -- remove more dead code +; 206 bytes -- no need to clear screen +; 193 bytes -- un-cycle exact the random16 code +; 189 bytes -- more optimization of random16 code +; 161 bytes -- move to 8-bit RNG +; 152 bytes -- reduce lookup to top half colors (had to remove brown) +; also changed maroon to pink +; 149 bytes -- use monitor GR +; 149 bytes -- load into zero page +; 140 bytes -- start using zero-page addressing +; 139 bytes -- rotate instead of mask for low bit +; 138 bytes -- bcs instead of jmp +; 137 bytes -- BIT nop trick to get rid of jump +; 135 bytes -- push/pull instead of saving to zero page + +; Zero Page +SEEDL = $4E +TEMP = $00 +TEMPY = $01 + +; 100 = $64 + +; Soft Switches +SET_GR = $C050 ; Enable graphics +FULLGR = $C052 ; Full screen, no text +LORES = $C056 ; Enable LORES graphics + +; monitor routines +GR = $F390 + +fire_demo: + + ; GR part + jsr GR ; 3 + bit FULLGR ; 3 + ;========== + ; 6 + + + ; Setup white line on bottom + + lda #$ff ; 2 + ldy #39 ; 2 +white_loop: + sta $7d0,Y ; hline 24 (46+47) ; 3 + dey ; 1 + bpl white_loop ; 2 + ;============ + ; 10 + +fire_loop: + + ldx #44 ; 22 * 2 ; 2 + +yloop: + ; low bytes of address + lda 0 ; 1000 0101 + .byte $bb ; 9->11 ; 1001 0001 + .byte 0 ; 10->0 ; 1010 0000 + .byte $aa ; 11->10 ; 1011 0000 + .byte 0 ; 12->0 ; 1100 0000 + .byte $99 ; 13->9 ; 1101 1001 + .byte $00 ; 14->0 ; 1110 0000 + .byte $dd ; 15->13 ; 1111 1101 + +gr_offsets: + .word $400,$480,$500,$580,$600,$680,$700,$780 + .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 + .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 + diff --git a/fire/fire_tiny.s b/fire/fire_tiny.s index 9f1813f0..b5bc58d0 100644 --- a/fire/fire_tiny.s +++ b/fire/fire_tiny.s @@ -21,9 +21,12 @@ ; 138 bytes -- bcs instead of jmp ; 137 bytes -- BIT nop trick to get rid of jump ; 135 bytes -- push/pull instead of saving to zero page +; 134 bytes -- replace half of lookup table with math +; 119 bytes -- replace that half of lookup table with better math ; Zero Page SEEDL = $4E +TEMP = $00 TEMPY = $01 ; 100 = $64 @@ -58,24 +61,45 @@ white_loop: fire_loop: - ldx #44 ; 22 * 2 ; 2 + ldx #22 ; 22 ; 2 yloop: + ; low bytes of address lda 13 ; 1111 1101 gr_offsets: - .word $400,$480,$500,$580,$600,$680,$700,$780 - .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 - .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 +; .word $400,$480,$500,$580,$600,$680,$700,$780 +; .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 +; .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 + + .byte $00,$80,$00,$80,$00,$80,$00,$80 + .byte $28,$a8,$28,$a8,$28,$a8,$28,$a8 + .byte $50,$d0,$50,$d0,$50,$d0,$50,$d0