; *************************************************************************** ; *************************************************************************** ; ; unpack-zx0.asm ; ; HuC6280 decompressor for Einar Saukas's "classic" ZX0 format. ; ; The code length is 205 bytes for RAM, plus 222 (shorter) or 262 (faster) ; bytes for direct-to-VRAM, plus some generic utility code. ; ; Copyright John Brandwood 2021-2024. ; ; Distributed under the Boost Software License, Version 1.0. ; (See accompanying file LICENSE_1_0.txt or copy at ; http://www.boost.org/LICENSE_1_0.txt) ; ; *************************************************************************** ; *************************************************************************** ; ; ZX0 "modern" format is not supported, because it costs an extra 4 bytes of ; code in this decompressor, and it runs slower. ; ; Use Emmanuel Marty's SALVADOR ZX0 compressor which can be found here ... ; https://github.com/emmanuel-marty/salvador ; ; To create a ZX0 file to decompress to RAM ; ; salvador -classic ; ; To create a ZX0 file to decompress to VRAM, using a 2KB ring-buffer in RAM ; ; salvador -classic -w 2048 ; ; *************************************************************************** ; *************************************************************************** ; ; Configure Library ... ; .ifndef SUPPORT_ACD SUPPORT_ACD = 1 .endif .ifndef SUPPORT_ZX0RAM SUPPORT_ZX0RAM = 1 ; Include decompress-to-RAM? .endif .ifndef SUPPORT_ZX0VRAM SUPPORT_ZX0VRAM = 1 ; Include decompress-to-VRAM? .endif .ifndef ZX0_PREFER_SIZE ZX0_PREFER_SIZE = 1 ; Smaller size or 10% faster. .endif ; *************************************************************************** ; *************************************************************************** ; ; If you decompress directly to VRAM, then you need to define a ring-buffer ; in RAM, both sized and aligned to a power-of-two (i.e. 256, 512, 1KB, 2KB). ; ; You also need to make sure that you tell the compressor that it needs to ; limit the window size with its "-w" option. ; ; Note that CD-ROM developers should really just decompress to RAM, and then ; use a TIA to copy the data to VRAM, because that is faster, you get better ; compression without a window, and you save code memory by not needing both ; versions of the decompression routine. ; ; HuCARD developers who either can't afford the RAM, or who prefer execution ; speed over compression, can choose a ring-buffer size of 256 bytes so that ; a faster version of the decompression code is used. ; .ifndef ZX0_WINBUF ZX0_WINBUF = ($3800) ; Default to a 2KB window in ZX0_WINMSK = ($0800 - 1) ; RAM, located at $3800. .endif .ifndef ZX0_WINMSK ZX0_WINMSK = ZX0_WINLEN - 1 ; Some folks prefer a length. .endif ; *************************************************************************** ; *************************************************************************** ; ; Data usage is 10..14 bytes of zero-page, using aliases for clarity. ; zx0_srcptr = _bp ; 1 word. zx0_dstptr = _di ; 1 word. zx0_winptr = _si ; 1 word. zx0_length = _ax ; 1 word. zx0_offset = _bx ; 1 word. .if (SUPPORT_ZX0RAM + SUPPORT_ZX0VRAM) zx0_group .procgroup ; Keep RAM and VDC together. .if SUPPORT_ZX0RAM ; *************************************************************************** ; *************************************************************************** ; ; zx0_to_ram - Decompress data stored in Einar Saukas's ZX0 "classic" format. ; ; Args: _bp, Y = _farptr to compressed data in MPR3. ; Args: _di = ptr to output address in RAM (anywhere except MPR3!). ; ; Returns: _bp, Y = _farptr to byte after compressed data. ; ; Uses: _bp, _di, _si, _ax, _bx ! ; zx0_to_ram .proc tma3 ; Preserve MPR3. pha jsr map_bp_to_mpr3 ; Map zx0_srcptr to MPR3. ldx #$40 ; Initialize bit-buffer. lda #$FF ; Initialize offset to $FFFF. sta.l