From f233d552ca799b74018969bdcc5fe1e95467dde3 Mon Sep 17 00:00:00 2001 From: Doug Masten Date: Sat, 20 Jun 2020 12:11:35 -0500 Subject: [PATCH 1/9] Remove unnecessary "TSTB" instruction from 6809 LZSA depackers --- asm/6809/unlzsa1.s | 4 +--- asm/6809/unlzsa1b.s | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/asm/6809/unlzsa1.s b/asm/6809/unlzsa1.s index ec49aef..b23b8a0 100644 --- a/asm/6809/unlzsa1.s +++ b/asm/6809/unlzsa1.s @@ -60,9 +60,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 diff --git a/asm/6809/unlzsa1b.s b/asm/6809/unlzsa1b.s index f658872..6b97d92 100644 --- a/asm/6809/unlzsa1b.s +++ b/asm/6809/unlzsa1b.s @@ -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 From 1dd65731c4e4f495c9b7fa280a5320cb3d736b8d Mon Sep 17 00:00:00 2001 From: Doug Masten Date: Sat, 20 Jun 2020 12:19:32 -0500 Subject: [PATCH 2/9] Remove unnecessary "ADDB #$12" as B register will always have this value from 6809 LZSA depackers --- asm/6809/unlzsa1.s | 3 +-- asm/6809/unlzsa1b.s | 3 +-- asm/6809/unlzsa2.s | 3 +-- asm/6809/unlzsa2b.s | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/asm/6809/unlzsa1.s b/asm/6809/unlzsa1.s index b23b8a0..16abd6a 100644 --- a/asm/6809/unlzsa1.s +++ b/asm/6809/unlzsa1.s @@ -78,8 +78,7 @@ lz1gotof leau d,y ; put backreference start address in U (dst+offset) 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 diff --git a/asm/6809/unlzsa1b.s b/asm/6809/unlzsa1b.s index 6b97d92..7afeb40 100644 --- a/asm/6809/unlzsa1b.s +++ b/asm/6809/unlzsa1b.s @@ -82,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 diff --git a/asm/6809/unlzsa2.s b/asm/6809/unlzsa2.s index f99c453..3788620 100644 --- a/asm/6809/unlzsa2.s +++ b/asm/6809/unlzsa2.s @@ -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 diff --git a/asm/6809/unlzsa2b.s b/asm/6809/unlzsa2b.s index 162f972..0bcfd3f 100644 --- a/asm/6809/unlzsa2b.s +++ b/asm/6809/unlzsa2b.s @@ -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) From e8edc3242dcac0fe580a45d7ac9e8b195b619108 Mon Sep 17 00:00:00 2001 From: Doug Masten Date: Sat, 20 Jun 2020 12:27:31 -0500 Subject: [PATCH 3/9] Restructure code to eliminate one BRA instruction in unlzsa1.s 6809 LZSA depacker --- asm/6809/unlzsa1.s | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/asm/6809/unlzsa1.s b/asm/6809/unlzsa1.s index 16abd6a..bb0caf9 100644 --- a/asm/6809/unlzsa1.s +++ b/asm/6809/unlzsa1.s @@ -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,11 +88,11 @@ 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 @@ -65,41 +103,3 @@ lz1nolt ldb ,s ; get token again, don't pop it from the stack 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 - - 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 - bra lz1token ; go decode next token From 7f0316b81cbe164591a3ef60b56eb1fbcbb29f6a Mon Sep 17 00:00:00 2001 From: Doug Masten Date: Sat, 20 Jun 2020 12:45:51 -0500 Subject: [PATCH 4/9] Update code byte counts for 6809 LZSA depackers --- asm/6809/unlzsa1.s | 2 +- asm/6809/unlzsa1b.s | 2 +- asm/6809/unlzsa2.s | 2 +- asm/6809/unlzsa2b.s | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/asm/6809/unlzsa1.s b/asm/6809/unlzsa1.s index bb0caf9..5b55862 100644 --- a/asm/6809/unlzsa1.s +++ b/asm/6809/unlzsa1.s @@ -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 ; ; in: x = start of compressed data diff --git a/asm/6809/unlzsa1b.s b/asm/6809/unlzsa1b.s index 7afeb40..eff2fba 100644 --- a/asm/6809/unlzsa1b.s +++ b/asm/6809/unlzsa1b.s @@ -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 ; ; in: x = last byte of compressed data diff --git a/asm/6809/unlzsa2.s b/asm/6809/unlzsa2.s index 3788620..e21d0cd 100644 --- a/asm/6809/unlzsa2.s +++ b/asm/6809/unlzsa2.s @@ -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 ; ; in: x = start of compressed data diff --git a/asm/6809/unlzsa2b.s b/asm/6809/unlzsa2b.s index 0bcfd3f..5defa09 100644 --- a/asm/6809/unlzsa2b.s +++ b/asm/6809/unlzsa2b.s @@ -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 ; ; in: x = last byte of compressed data From 2f79779bebdb9dd393f532cc8c452859be6757a5 Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Sat, 20 Jun 2020 23:57:22 +0200 Subject: [PATCH 5/9] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e526760..dacb0f9 100755 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ License: * Z80 decompressors (size- and speed-optimized) written by [introspec](https://github.com/specke) * 6502 and 8088 size-optimized improvements by [Peter Ferrie](https://github.com/peterferrie) * 8088 speed-optimized decompressor by [Jim Leonard](https://github.com/mobygamer) -* 6809 decompressors (for the Tandy CoCo, Thomson MO5/MO6/TO7/TO8/TO9, Dragon 32/64..) +* 6809 decompressors (Tandy Coco, Thomson MO/TO, Dragon 32/64..) optimized by [Doug Masten](https://github.com/dougmasten) External links: From 798c07f6e026cbc9cab587ccddaf4dc5b7c137b4 Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Sat, 20 Jun 2020 23:59:01 +0200 Subject: [PATCH 6/9] Update README again --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dacb0f9..a8f1af5 100755 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ License: 8-bit assembly code: -* Z80 decompressors (size- and speed-optimized) written by [introspec](https://github.com/specke) +* Z80 decompressors (size- and speed-optimized) written by [introspec](https://github.com/specke) with optimizations by [uniabis](https://github.com/uniabis) * 6502 and 8088 size-optimized improvements by [Peter Ferrie](https://github.com/peterferrie) * 8088 speed-optimized decompressor by [Jim Leonard](https://github.com/mobygamer) * 6809 decompressors (Tandy Coco, Thomson MO/TO, Dragon 32/64..) optimized by [Doug Masten](https://github.com/dougmasten) From f724663ba8ff19a0fa8ee60e91bffadfc3f2b591 Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Sun, 21 Jun 2020 00:04:03 +0200 Subject: [PATCH 7/9] Update README some more --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a8f1af5..e2b90df 100755 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ License: * Z80 decompressors (size- and speed-optimized) written by [introspec](https://github.com/specke) with optimizations by [uniabis](https://github.com/uniabis) * 6502 and 8088 size-optimized improvements by [Peter Ferrie](https://github.com/peterferrie) +* 6502 speed-optimized decompressor by [John Brandwood](https://github.com/jbrandwood) * 8088 speed-optimized decompressor by [Jim Leonard](https://github.com/mobygamer) -* 6809 decompressors (Tandy Coco, Thomson MO/TO, Dragon 32/64..) optimized by [Doug Masten](https://github.com/dougmasten) +* 6809 decompressors (Tandy CoCo, Thomson MO/TO, Dragon 32/64..) optimized by [Doug Masten](https://github.com/dougmasten) External links: From 07c39694325872770c64eee1b77f6d0b74c1996e Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Mon, 22 Jun 2020 00:13:14 +0200 Subject: [PATCH 8/9] Compress LZSA2 raw files one byte shorter --- src/shrink_block_v2.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/shrink_block_v2.c b/src/shrink_block_v2.c index 32d76b9..67d9b81 100644 --- a/src/shrink_block_v2.c +++ b/src/shrink_block_v2.c @@ -1048,7 +1048,7 @@ static int lzsa_write_block_v2(lzsa_compressor *pCompressor, lzsa_match *pBestMa return -1; if (pCompressor->flags & LZSA_FLAG_RAW_BLOCK) - pOutData[nOutOffset++] = (nTokenLiteralsLen << 3) | 0x47; + pOutData[nOutOffset++] = (nTokenLiteralsLen << 3) | 0xe7; else pOutData[nOutOffset++] = (nTokenLiteralsLen << 3) | 0x00; nOutOffset = lzsa_write_literals_varlen_v2(pOutData, nOutOffset, nMaxOutDataSize, &nCurNibbleOffset, &nCurFreeNibbles, nNumLiterals); @@ -1081,7 +1081,6 @@ static int lzsa_write_block_v2(lzsa_compressor *pCompressor, lzsa_match *pBestMa if (nOutOffset >= nMaxOutDataSize) return -1; - pOutData[nOutOffset++] = 0; /* Match offset */ nOutOffset = lzsa_write_nibble_v2(pOutData, nOutOffset, nMaxOutDataSize, &nCurNibbleOffset, &nCurFreeNibbles, 15); /* Extended match length nibble */ if (nOutOffset < 0) return -1; @@ -1119,12 +1118,12 @@ static int lzsa_write_raw_uncompressed_block_v2(lzsa_compressor *pCompressor, co int nTokenLiteralsLen = (nNumLiterals >= LITERALS_RUN_LEN_V2) ? LITERALS_RUN_LEN_V2 : nNumLiterals; int nOutOffset = 0; - int nCommandSize = 8 /* token */ + lzsa_get_literals_varlen_size_v2(nNumLiterals) + (nNumLiterals << 3) + 8 + 4 + 8; + int nCommandSize = 8 /* token */ + lzsa_get_literals_varlen_size_v2(nNumLiterals) + (nNumLiterals << 3) + 4 + 8; if ((nOutOffset + ((nCommandSize + 7) >> 3)) > nMaxOutDataSize) return -1; pCompressor->num_commands = 0; - pOutData[nOutOffset++] = (nTokenLiteralsLen << 3) | 0x47; + pOutData[nOutOffset++] = (nTokenLiteralsLen << 3) | 0xe7; nOutOffset = lzsa_write_literals_varlen_v2(pOutData, nOutOffset, nMaxOutDataSize, &nCurNibbleOffset, &nCurFreeNibbles, nNumLiterals); if (nOutOffset < 0) return -1; @@ -1137,8 +1136,6 @@ static int lzsa_write_raw_uncompressed_block_v2(lzsa_compressor *pCompressor, co /* Emit EOD marker for raw block */ - pOutData[nOutOffset++] = 0; /* Match offset */ - nOutOffset = lzsa_write_nibble_v2(pOutData, nOutOffset, nMaxOutDataSize, &nCurNibbleOffset, &nCurFreeNibbles, 15); /* Extended match length nibble */ if (nOutOffset < 0) return -1; From 40212975c2a15ae6be5bed6b8223792ea3b34c07 Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Mon, 22 Jun 2020 10:08:40 +0200 Subject: [PATCH 9/9] Bump version --- src/lzsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lzsa.c b/src/lzsa.c index 82aa902..29d4aa5 100755 --- a/src/lzsa.c +++ b/src/lzsa.c @@ -48,7 +48,7 @@ #define OPT_RAW_BACKWARD 8 #define OPT_STATS 16 -#define TOOL_VERSION "1.2.2" +#define TOOL_VERSION "1.3.0" /*---------------------------------------------------------------------------*/