; *************************************************************************** ; *************************************************************************** ; ; unpack-zx0.asm ; ; HuC6280 decompressor for Einar Saukas's "classic" ZX0 format. ; ; The code length is 193 bytes for RAM, 243 bytes for direct-to-VRAM, plus ; some generic utility code. ; ; Copyright John Brandwood 2021. ; ; 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. ; ; *************************************************************************** ; *************************************************************************** ; *************************************************************************** ; *************************************************************************** ; ; 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. 512, 1KB, 2KB, 4KB). ; ; 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. ; .ifndef ZX0_WINBUF ZX0_WINBUF = ($3800) >> 8 ; Default to a 2KB window in ZX0_WINMSK = ($0800 - 1) >> 8 ; RAM, located at $3800. .endif ; *************************************************************************** ; *************************************************************************** ; ; Data usage is 11 bytes of zero-page, using aliases for clarity. ; zx0_srcptr = __si ; 1 word. zx0_dstptr = __di ; 1 word. zx0_length = __ax ; 1 word. zx0_offset = __bx ; 1 word. zx0_winptr = __cx ; 1 word. zx0_bitbuf = __dl ; 1 byte. ; *************************************************************************** ; *************************************************************************** ; ; zx0_to_ram - Decompress data stored in Einar Saukas's ZX0 "classic" format. ; ; Args: __si, __si_bank = _farptr to compressed data in MPR3. ; Args: __di = ptr to output address in RAM. ; ; Uses: __si, __di, __ax, __bx, __cx, __dh ! ; zx0_to_ram .proc jsr __si_to_mpr3 ; Map zx0_srcptr to MPR3. ldx #$40 ; Initialize bit-buffer. ldy #$FF ; Initialize offset to $FFFF. sty