diff --git a/asm/6809/unlzsa1b-6309.s b/asm/6809/unlzsa1b-6309.s index c975f19..6078085 100644 --- a/asm/6809/unlzsa1b-6309.s +++ b/asm/6809/unlzsa1b-6309.s @@ -1,4 +1,4 @@ -; unlzsa1-6309.s - H6309 backward decompressor for raw LZSA1 - 105 bytes +; unlzsa1-6309.s - H6309 backward decompressor for raw LZSA1 - 97 bytes ; compress with lzsa -f1 -r -b ; ; in: x = last byte of compressed data @@ -25,11 +25,10 @@ decompress_lzsa1 leax 1,x - bra lz1start + bra lz1token lz1bigof ldd ,--x ; O set: load long 16-bit (negative, signed) offest lz1gotof negd ; reverse sign of offset in D - decd ; tfm below is post-decrement, not pre-decrement leau d,y ; put backreference start address in U (dst+offset) ldd #$000f ; clear MSB match length and set mask for MMMM @@ -45,15 +44,14 @@ lz1gotof negd ; reverse sign of offset in D ldd ,--x ; load 16-bit len in D (low part in B, high in A) bne lz1gotln ; check if we hit EOD (16-bit length = 0) + leay 1,y ; adjust pointer to first byte of decompressed data rts ; done, bail lz1midln tfr b,a ; copy high part of len into A ldb ,-x ; grab low 8 bits of len in B lz1gotln tfr d,w ; set W with match length for TFM instruction - leay -1,y ; tfm is post-decrement tfm u-,y- ; copy match bytes -lz1start leay 1,y ; fix destination for pre-decrement again lz1token ldb ,-x ; load next token into B: O|LLL|MMMM pshs b ; save it @@ -83,10 +81,8 @@ lz1declt lsrb ; shift literals count into place lz1gotla clra ; clear A (high part of literals count) lz1gotlt tfr d,w ; set W with literals count for TFM instruction leax -1,x ; tfm is post-decrement - leay -1,y tfm x-,y- ; copy literal bytes leax 1,x - leay 1,y lz1nolt ldb ,s ; get token again, don't pop it from the stack bmi lz1bigof ; test O bit (small or large offset) diff --git a/asm/6809/unlzsa2b-6309.s b/asm/6809/unlzsa2b-6309.s index e3b2c0e..8e15bf8 100644 --- a/asm/6809/unlzsa2b-6309.s +++ b/asm/6809/unlzsa2b-6309.s @@ -1,4 +1,4 @@ -; unlzsa2b-6309.s - H6309 backward decompressor for raw LZSA2 - 163 bytes +; unlzsa2b-6309.s - H6309 backward decompressor for raw LZSA2 - 155 bytes ; compress with lzsa -f2 -r -b ; ; in: x = last byte of compressed data @@ -25,8 +25,7 @@ decompress_lzsa2 clr lz2nibct ; reset nibble available flag - leax 1,x - leay 1,y + leax 1,x ; adjust compressed data pointer bra lz2token lz2nibct fcb 0 ; nibble ready flag @@ -35,7 +34,7 @@ lz2replg lslb ; push token's Y flag bit into carry bcs lz2rep16 ; if token's Y bit is set, rep or 16 bit offset sex ; push token's Z flag bit into reg A - lbsr lz2nibl ; get offset nibble in B + bsr lz2nibl ; get offset nibble in B lsla ; push token's Z flag bit into carry rolb ; shift Z flag from carry into bit 0 of B eorb #$e1 ; set bits 13-15 of offset, reverse bit 8 @@ -48,7 +47,6 @@ lz2rep16 bmi lz2repof ; if token's Z flag bit is set, rep match lz2lowof ldb ,-x ; load low 8 bits of offset lz2gotof negd ; reverse sign of offset in D - decd ; tfm below is post-decrement, not pre-decrement std lz2moff+2 ; store match offset lz2repof ldd #$0007 ; clear MSB match length and set mask for MMM @@ -70,9 +68,7 @@ lz2moff leau $aaaa,y ; put backreference start address in U (dst+offset) ldd ,--x ; load 16-bit len in D (low part in B, high in A) lz2gotln tfr d,w ; set W with match count for TFM instruction - leay -1,y ; tfm is post-decrement tfm u-,y- ; copy match bytes - leay 1,y ; fix destination for pre-decrement again lz2token ldb ,-x ; load next token into B: XYZ|LL|MMM tfr x,u ; save token address @@ -92,6 +88,17 @@ lz2token ldb ,-x ; load next token into B: XYZ|LL|MMM ldd ,--x ; load 16 bit count in D (low part in B, high in A) bra lz2gotlt ; we now have the complete count, go copy +lz2nibl com lz2nibct ; nibble ready? + bpl lz2gotnb + + ldb ,-x ; load two nibbles + stb lz2gotnb+1 ; store nibble for next time (low 4 bits) + lsrb ; shift 4 high bits of nibble down + lsrb + lsrb + lsrb + rts + lz2declt lsrb ; shift literals count into place lsrb lsrb @@ -99,10 +106,8 @@ lz2gotla clra ; clear A (high part of literals count) lz2gotlt tfr d,w ; set W with literals count for TFM instruction leax -1,x ; tfm is post-decrement - leay -1,y tfm x-,y- ; copy literal bytes leax 1,x - leay 1,y lz2nolt ldb ,u ; get token again lslb ; push token's X flag bit into carry @@ -122,15 +127,7 @@ lz2nolt ldb ,u ; get token again lz2offs9 deca ; set bits 9-15 of offset, reverse bit 8 bra lz2lowof -lz2nibl ldb #$aa - com lz2nibct ; nibble ready? - bpl lz2gotnb - - ldb ,-x ; load two nibbles - stb lz2nibl+1 ; store nibble for next time (low 4 bits) - lsrb ; shift 4 high bits of nibble down - lsrb - lsrb - lsrb -lz2gotnb andb #$0f ; only keep low 4 bits -lz2done rts +lz2done leay 1,y ; adjust pointer to first byte of decompressed data and then exit +lz2gotnb ldb #$aa ; load nibble + andb #$0f ; only keep low 4 bits + rts