From b2be06be8dff7d7584463d0d598d920e2f58f7be Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 7 Feb 2024 19:35:27 -0500 Subject: [PATCH] lovebyte: at size target --- demos/lovebyte2024/plasma_mask_1k/TODO | 4 - .../lovebyte2024/plasma_mask_1k/make_tables.s | 19 ++ .../plasma_mask_1k/plasma_compress.s | 5 +- .../lovebyte2024/plasma_mask_1k/plasma_new.s | 171 +++++++++++++++++- 4 files changed, 186 insertions(+), 13 deletions(-) diff --git a/demos/lovebyte2024/plasma_mask_1k/TODO b/demos/lovebyte2024/plasma_mask_1k/TODO index aaa0654e..05647fc1 100644 --- a/demos/lovebyte2024/plasma_mask_1k/TODO +++ b/demos/lovebyte2024/plasma_mask_1k/TODO @@ -1,6 +1,2 @@ optimize music code: + depending on alignment can hard-code the high value for track0/track1 - + check the frequencies, high freq might always be 0 - -optimize other: - + can hardcode zx if only use it once? diff --git a/demos/lovebyte2024/plasma_mask_1k/make_tables.s b/demos/lovebyte2024/plasma_mask_1k/make_tables.s index 404ef258..7e0cb797 100644 --- a/demos/lovebyte2024/plasma_mask_1k/make_tables.s +++ b/demos/lovebyte2024/plasma_mask_1k/make_tables.s @@ -39,6 +39,20 @@ save = $2300 make_tables: + ; print pre-calc string + + ldx #0 +write_string: + lda precalc_string,X + beq done_string +; ora #$80 + sta $650,X + inx + bne write_string +done_string: + + + ;==================================================== ; sin1[i]=round(47.0+ ; 32.0*sin(i*(PI*2.0/256.0))+ @@ -107,6 +121,8 @@ make_tables: make_sin_table: + dec $659 + ldx #0 sin_loop: stx OURX @@ -220,3 +236,6 @@ three_input: ; ; 8*2*pi/256 = .196349541 ; .byte $7E,$49,$0F,$da,$a2 +precalc_string: + .byte 'P'|$80,'R'|$80,'E'|$80,'C'|$80,'A'|$80,'L'|$80,'C'|$80,':'|$80,' '|$80,'4' + .byte ' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,'d'|$80,'S'|$80,'r'|$80,0 diff --git a/demos/lovebyte2024/plasma_mask_1k/plasma_compress.s b/demos/lovebyte2024/plasma_mask_1k/plasma_compress.s index 05b9a434..d4e10f96 100644 --- a/demos/lovebyte2024/plasma_mask_1k/plasma_compress.s +++ b/demos/lovebyte2024/plasma_mask_1k/plasma_compress.s @@ -9,6 +9,8 @@ ; 1135 -- initial ; 1000 -- compressed ; 997 -- minor optimization +; 984 -- inline zx02 compress +; 988 -- fix fullscreen .include "hardware.inc" .include "zp.inc" @@ -23,7 +25,7 @@ tracker_song = peasant_song plasma_mask: jsr HGR ; have table gen appear on hgr page1 -; bit FULLGR + ;================= @@ -51,6 +53,7 @@ plasma_mask: cli ; start music bit LORES ; set lo-res + bit FULLGR ; ============================================================================ ; init lores colors (inline) diff --git a/demos/lovebyte2024/plasma_mask_1k/plasma_new.s b/demos/lovebyte2024/plasma_mask_1k/plasma_new.s index aad0405d..e8af4fda 100644 --- a/demos/lovebyte2024/plasma_mask_1k/plasma_new.s +++ b/demos/lovebyte2024/plasma_mask_1k/plasma_new.s @@ -2,18 +2,173 @@ .include "zp.inc" - ; TODO: inline +plasma_new: + + ; inlined + +; De-compressor for ZX02 files +; ---------------------------- +; +; Decompress ZX02 data (6502 optimized format), optimized for speed and size +; 138 bytes code, 58.0 cycles/byte in test file. +; +; Compress with: +; zx02 input.bin output.zx0 +; +; (c) 2022 DMSC +; Code under MIT license, see LICENSE file. + + +;ZP=$80 + +;offset = ZP+0 +;ZX0_src = ZP+2 +;ZX0_dst = ZP+4 +;bitr = ZP+6 +;pntr = ZP+7 + + ; Initial values for offset, source, destination and bitr +;zx0_ini_block: +; .byte $00, $00, comp_data, out_addr, $80 + +;-------------------------------------------------- +; Decompress ZX0 data (6502 optimized format) + +zx02_full_decomp: +; ; Get initialization block +; ldy #7 +; +;copy_init: lda zx0_ini_block-1, y +; sta offset-1, y +; dey +; bne copy_init - lda #compressed_data - sta zx_src_h+1 lda #$40 - jsr zx02_full_decomp + sta ZX0_dst+1 ; page to output to in A +zx_src_l: + ldy #compressed_data + sty ZX0_src+1 + ldy #$80 + sty bitr + ldy #0 + sty offset + sty offset+1 + sty ZX0_dst ; always on even page + +; Decode literal: Ccopy next N bytes from compressed file +; Elias(length) byte[1] byte[2] ... byte[N] +decode_literal: + jsr get_elias + +cop0: lda (ZX0_src), y + inc ZX0_src + bne plus1 + inc ZX0_src+1 +plus1: sta (ZX0_dst),y + inc ZX0_dst + bne plus2 + inc ZX0_dst+1 +plus2: dex + bne cop0 + + asl bitr + bcs dzx0s_new_offset + +; Copy from last offset (repeat N bytes from last offset) +; Elias(length) + jsr get_elias +dzx0s_copy: + lda ZX0_dst + sbc offset ; C=0 from get_elias + sta pntr + lda ZX0_dst+1 + sbc offset+1 + sta pntr+1 + +cop1: + lda (pntr), y + inc pntr + bne plus3 + inc pntr+1 +plus3: sta (ZX0_dst),y + inc ZX0_dst + bne plus4 + inc ZX0_dst+1 +plus4: dex + bne cop1 + + asl bitr + bcc decode_literal + +; Copy from new offset (repeat N bytes from new offset) +; Elias(MSB(offset)) LSB(offset) Elias(length-1) +dzx0s_new_offset: + ; Read elias code for high part of offset + jsr get_elias + beq exit ; Read a 0, signals the end + ; Decrease and divide by 2 + dex + txa + lsr ; @ + sta offset+1 + + ; Get low part of offset, a literal 7 bits + lda (ZX0_src), y + inc ZX0_src + bne plus5 + inc ZX0_src+1 +plus5: + ; Divide by 2 + ror ; @ + sta offset + + ; And get the copy length. + ; Start elias reading with the bit already in carry: + ldx #1 + jsr elias_skip1 + + inx + bcc dzx0s_copy + +; Read an elias-gamma interlaced code. +; ------------------------------------ +get_elias: + ; Initialize return value to #1 + ldx #1 + bne elias_start + +elias_get: ; Read next data bit to result + asl bitr + rol ; @ + tax + +elias_start: + ; Get one bit + asl bitr + bne elias_skip1 + + ; Read new bit from stream + lda (ZX0_src), y + inc ZX0_src + bne plus6 + inc ZX0_src+1 +plus6: ;sec ; not needed, C=1 guaranteed from last bit + rol ;@ + sta bitr + +elias_skip1: + txa + bcs elias_get + ; Got ending bit, stop reading + + rts +exit: jmp $4000 -.include "zx02_optim.s" - compressed_data: .incbin "PLASMA_COMPRESS.zx02" +