;Copyright (c) 2012-2013 Peter Ferrie LZ4 data decompressor for the Apple II by Peter Ferrie. Two versions, depending on your unpacking needs. l4dstsrc.s is for when the unpacked address is lower in memory than the packed address (for example, if you load the packed data to the top of memory and want to unpack to the bottom of memory). l4srcdst.s is for when the unpacked address is higher in memory than the packed address (for example, if you load the packed data to the bottom of memory and want to unpack to the top of memory). Both versions support an option called "init". You can use this if you know both addresses and unpacked entrypoint at assemble-time. Sample initialisation code will be generated for you. l4dstsrc.s has more options: hiunp: unpacker will be relocated to high memory ($d000 or higher) and run from there. It allows the unpacker code in low memory to be overwritten. hipak: packed data will also be relocated to high memory. It allows the entire low memory to be used for unpacked data. l4srcdst.s unpacks backwards in memory to maximise the amount that can be unpacked. Packed data must be stored backwards for this to work. The src and dst can overlap up to the point of the last byte fetched by parsetoken. lz4.exe can be used to pack data on a PC, just remove the LZ4 header (8 bytes), the rest is the packed data. http://pferrie.host22.com ;---------------------------------------------------------- ; L4DSTSRC.S VERSION ;---------------------------------------------------------- ;LZ4 data decompressor for Apple II ;Peter Ferrie (peter.ferrie@gmail.com) ;assemble using ACME ;dstpakoff sta src+1 adc #>paksize sta end+1 lda #>orgoff ;original unpacked data offset sta dst+1 !if (>(oep-1)=>orgoff) { ;oep = original entrypoint pha } else { lda #>(oep-1) pha } lda #parsetoken sta A1H lda #pakoff+paksize ;packed data offset + packed data size sta A2H lda #pakoff sta A2H lda #hioff sta A4H lda #pakoff+paksize ;packed data offset + packed data size sta src+1 lda #orgoff+orgsize ;original unpacked data offset + original unpacked size sta dst+1 !if (>(oep-1)=>(orgoff+orgsize)) { ;oep = original entrypoint pha } else { lda #>(oep-1) pha } lda #(pakoff+1) bcc done copymatches jsr getsrc sta delta jsr getsrc sta delta+1 txa and #$0f inc count+1 jsr buildcount adc #4 tay lda count+1 adc #0 sta count+1 lda src+1 pha lda src pha clc lda dst adc delta sta src lda dst+1 adc delta+1 sta src+1 jsr docopy pla sta src pla sta src+1 jmp parsetoken docopy jsr getput dey bne docopy dec count+1 bne docopy done rts buildcount cmp #$0f bne + sta count - jsr getsrc tay clc adc count sta count lda #0 adc count+1 sta count+1 iny beq - lda count + rts getput jsr getsrc putdst pha lda dst bne + dec dst+1 + dec dst pla sty tmpy ldy #0 sta (dst), y ldy tmpy rts getsrc lda src bne + dec src+1 + dec src sty tmpy ldy #0 lda (src), y ldy tmpy rts pakoff ;place packed data here