mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2025-03-20 16:29:18 +00:00
Merge pull request #47 from dougmasten/dom
Various optimizations to the 6809 LZSA depackers
This commit is contained in:
commit
a9b5a7511c
@ -1,4 +1,4 @@
|
||||
; unlzsa1.s - 6809 decompression routine for raw LZSA1 - 117 bytes
|
||||
; unlzsa1.s - 6809 decompression routine for raw LZSA1 - 111 bytes
|
||||
; compress with lzsa -r <original_file> <compressed_file>
|
||||
;
|
||||
; in: x = start of compressed data
|
||||
@ -23,7 +23,45 @@
|
||||
; misrepresented as being the original software.
|
||||
; 3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
decompress_lzsa1
|
||||
decompress_lzsa1 equ lz1token
|
||||
|
||||
lz1bigof ldb ,x+ ; O set: load long 16 bit (negative, signed) offset
|
||||
lda ,x+ ; (little endian)
|
||||
lz1gotof leau d,y ; put backreference start address in U (dst+offset)
|
||||
|
||||
puls b ; restore token
|
||||
|
||||
clra ; clear A (high part of match length)
|
||||
andb #$0F ; isolate MMMM (embedded match length)
|
||||
addb #$03 ; add MIN_MATCH_SIZE
|
||||
cmpb #$12 ; MATCH_RUN_LEN?
|
||||
bne lz1gotln ; no, we have the full match length, go copy
|
||||
|
||||
addb ,x+ ; add extra match length byte + MIN_MATCH_SIZE + MATCH_RUN_LEN
|
||||
bcc lz1gotln ; if no overflow, we have the full length
|
||||
bne lz1midln
|
||||
|
||||
ldb ,x+ ; load 16-bit len in D (low part in B, high in A)
|
||||
lda ,x+ ; (little endian)
|
||||
bne lz1gotln ; check if we hit EOD (16-bit length = 0)
|
||||
tstb
|
||||
bne lz1gotln ; go copy matched bytes if not
|
||||
|
||||
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 pshs x ; save source compressed data pointer
|
||||
tfr d,x ; copy match length to X
|
||||
|
||||
lz1cpymt lda ,u+ ; copy matched byte
|
||||
sta ,y+
|
||||
leax -1,x ; decrement X
|
||||
bne lz1cpymt ; loop until all matched bytes are copied
|
||||
|
||||
puls x ; restore source compressed data pointer
|
||||
|
||||
lz1token ldb ,x+ ; load next token into B: O|LLL|MMMM
|
||||
pshs b ; save it
|
||||
|
||||
@ -50,59 +88,18 @@ lz1declt lsrb ; shift literals count into place
|
||||
lsrb
|
||||
lsrb
|
||||
lsrb
|
||||
|
||||
|
||||
lz1gotlt tfr x,u
|
||||
tfr d,x ; transfer 16-bit count into X
|
||||
lz1cpylt lda ,u+ ; copy literal byte
|
||||
sta ,y+
|
||||
sta ,y+
|
||||
leax -1,x ; decrement X and update Z flag
|
||||
bne lz1cpylt ; loop until all literal bytes are copied
|
||||
tfr u,x
|
||||
|
||||
lz1nolt ldb ,s ; get token again, don't pop it from the stack
|
||||
|
||||
tstb ; test O bit (small or large offset)
|
||||
bmi lz1bigof
|
||||
bmi lz1bigof ; test O bit (small or large offset)
|
||||
|
||||
ldb ,x+ ; O clear: load 8 bit (negative, signed) offset
|
||||
lda #$ff ; set high 8 bits
|
||||
bra lz1gotof
|
||||
|
||||
lz1bigof ldb ,x+ ; O set: load long 16 bit (negative, signed) offset
|
||||
lda ,x+ ; (little endian)
|
||||
lz1gotof leau d,y ; put backreference start address in U (dst+offset)
|
||||
|
||||
puls b ; restore token
|
||||
|
||||
clra ; clear A (high part of match length)
|
||||
andb #$0F ; isolate MMMM (embedded match length)
|
||||
addb #$03 ; add MIN_MATCH_SIZE
|
||||
cmpb #$12 ; MATCH_RUN_LEN?
|
||||
bne lz1gotln ; no, we have the full match length, go copy
|
||||
|
||||
ldb ,x+ ; grab extra match length byte
|
||||
addb #$12 ; add MIN_MATCH_SIZE + MATCH_RUN_LEN
|
||||
bcc lz1gotln ; if no overflow, we have the full length
|
||||
bne lz1midln
|
||||
|
||||
ldb ,x+ ; load 16-bit len in D (low part in B, high in A)
|
||||
lda ,x+ ; (little endian)
|
||||
bne lz1gotln ; check if we hit EOD (16-bit length = 0)
|
||||
tstb
|
||||
bne lz1gotln ; go copy matched bytes if not
|
||||
|
||||
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 pshs x ; save source compressed data pointer
|
||||
tfr d,x ; copy match length to X
|
||||
|
||||
lz1cpymt lda ,u+ ; copy matched byte
|
||||
sta ,y+
|
||||
leax -1,x ; decrement X
|
||||
bne lz1cpymt ; loop until all matched bytes are copied
|
||||
|
||||
puls x ; restore source compressed data pointer
|
||||
bra lz1token ; go decode next token
|
||||
|
@ -1,4 +1,4 @@
|
||||
; unlzsa1b.s - 6809 backward decompression routine for raw LZSA1 - 116 bytes
|
||||
; unlzsa1b.s - 6809 backward decompression routine for raw LZSA1 - 112 bytes
|
||||
; compress with lzsa -r -b <original_file> <compressed_file>
|
||||
;
|
||||
; in: x = last byte of compressed data
|
||||
@ -62,9 +62,7 @@ lz1cpylt lda ,-u ; copy literal byte
|
||||
tfr u,x
|
||||
|
||||
lz1nolt ldb ,s ; get token again, don't pop it from the stack
|
||||
|
||||
tstb ; test O bit (small or large offset)
|
||||
bmi lz1bigof
|
||||
bmi lz1bigof ; test O bit (small or large offset)
|
||||
|
||||
ldb ,-x ; O clear: load 8 bit (negative, signed) offset
|
||||
lda #$ff ; set high 8 bits
|
||||
@ -84,8 +82,7 @@ lz1gotof nega ; reverse sign of offset in D
|
||||
cmpb #$12 ; MATCH_RUN_LEN?
|
||||
bne lz1gotln ; no, we have the full match length, go copy
|
||||
|
||||
ldb ,-x ; grab extra match length byte
|
||||
addb #$12 ; add MIN_MATCH_SIZE + MATCH_RUN_LEN
|
||||
addb ,-x ; add extra match length byte + MIN_MATCH_SIZE + MATCH_RUN_LEN
|
||||
bcc lz1gotln ; if no overflow, we have the full length
|
||||
bne lz1midln
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
; unlzsa2.s - 6809 decompression routine for raw LZSA2 - 187 bytes
|
||||
; unlzsa2.s - 6809 decompression routine for raw LZSA2 - 183 bytes
|
||||
; compress with lzsa -f2 -r <original_file> <compressed_file>
|
||||
;
|
||||
; in: x = start of compressed data
|
||||
@ -40,8 +40,7 @@ lz2token ldb ,x+ ; load next token into B: XYZ|LL|MMM
|
||||
cmpb #$12 ; LITERALS_RUN_LEN_V2 + 15 ?
|
||||
bne lz2gotlt ; if not, we have the full literals count, go copy
|
||||
|
||||
ldb ,x+ ; load extra literals count byte
|
||||
addb #$12 ; add LITERALS_RUN_LEN + 15
|
||||
addb ,x+ ; add extra literals count byte + LITERALS_RUN_LEN + 15
|
||||
bcc lz2gotlt ; if no overflow, we got the complete count, copy
|
||||
|
||||
ldb ,x+ ; load low 8 bits of little-endian literals count
|
||||
|
@ -1,4 +1,4 @@
|
||||
; unlzsa2.s - 6809 backward decompression routine for raw LZSA2 - 189 bytes
|
||||
; unlzsa2b.s - 6809 backward decompression routine for raw LZSA2 - 187 bytes
|
||||
; compress with lzsa -f2 -r -b <original_file> <compressed_file>
|
||||
;
|
||||
; in: x = last byte of compressed data
|
||||
@ -42,8 +42,7 @@ lz2token ldb ,-x ; load next token into B: XYZ|LL|MMM
|
||||
cmpb #$12 ; LITERALS_RUN_LEN_V2 + 15 ?
|
||||
bne lz2gotlt ; if not, we have the full literals count, go copy
|
||||
|
||||
ldb ,-x ; load extra literals count byte
|
||||
addb #$12 ; add LITERALS_RUN_LEN + 15
|
||||
addb ,-x ; add extra literals count byte + LITERALS_RUN_LEN + 15
|
||||
bcc lz2gotlt ; if no overflow, we got the complete count, copy
|
||||
|
||||
ldd ,--x ; load 16 bit count in D (low part in B, high in A)
|
||||
|
Loading…
x
Reference in New Issue
Block a user