; *************************************************************************** ; *************************************************************************** ; ; aplib_6502.s ; ; NMOS 6502 decompressor for data stored in Jorgen Ibsen's aPLib format. ; ; Includes support for Emmanuel Marty's enhancements to the aPLib format. ; ; The code is 252 bytes long for standard format, 270 for enhanced format. ; ; This code is written for the ACME assembler. ; ; Copyright John Brandwood 2019. ; ; 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) ; ; *************************************************************************** ; *************************************************************************** ; *************************************************************************** ; *************************************************************************** ; ; Decompression Options & Macros ; ; ; Use the enhanced format from Emmanuel Marty's APULTRA? ; ; The enhancements speed up decompression on an 8-bit CPU. ; ; This gives an 11% improvement in decompresison speed, but ; breaks compatibility with standard aPLib encoders. ; APL_ENHANCED = 0 ; ; Assume that we're decompessing from a large multi-bank ; compressed data file, and that the next bank may need to ; paged in when a page-boundary is crossed. ; APL_FROM_BANK = 0 ; ; Macro to increment the source pointer to the next page. ; !if APL_FROM_BANK { !macro APL_INC_PAGE { jsr .next_page } } else { !macro APL_INC_PAGE { inc 64768 bytes has ; been removed, since these don't occur with a 16-bit address range. ; ; As an optimization, the code to handle window offsets > 32000 bytes can ; be commented-out, since these don't occur in typical 8-bit computer usage. ; apl_decompress: ldy #0 ; Initialize source index. lda #$80 ; Initialize an empty sta bne .skip2 jsr .load_bit .skip2: bcc .copy_large asl - gamma-coded LZSS pair. ; !if APL_ENHANCED { .copy_large: jsr .get_gamma ; Bits 8..15 of offset (min 2). cpx #1 ; CC if LWM==0, CS if LWM==1. ldx #0 ; Clear hi-byte of length. sbc #2 ; -3 if LWM==0, -2 if LWM==1. bcs .normal_pair ; CC if LWM==0 && offset==2. jsr .get_gamma ; Get length (A=lo-byte & CS). bcs .do_match ; Use previous Offset. .normal_pair: sta = 32000, length += 2. bcs .match_plus2 cpy #$05 ; If offset >= 1280, length += 1. bcs .match_plus1 bcc .do_match .lt256: ldy