From 659f6c14a976759941eba715d5d8ce6699abde23 Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Sat, 8 Jun 2019 16:18:36 +0200 Subject: [PATCH] Small improvement over 6502 LZSA2 depacker --- asm/6502/decompress_v2.asm | 10 ++++++---- src/expand_streaming.c | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/asm/6502/decompress_v2.asm b/asm/6502/decompress_v2.asm index 3bd3093..0b94e8b 100755 --- a/asm/6502/decompress_v2.asm +++ b/asm/6502/decompress_v2.asm @@ -56,8 +56,9 @@ DECODE_TOKEN BNE PREPARE_COPY_LITERALS ; if less, literals count is complete JSR GETSRC ; get extra byte of variable literals count - CLC - ADC #$12 ; overflow? + ; the carry is always set by the CMP above + ; GETSRC doesn't change it + SBC #$EE ; overflow? BCC PREPARE_COPY_LITERALS ; if not, literals count is complete ; handle 16 bits literals count @@ -155,8 +156,9 @@ REP_MATCH BNE PREPARE_COPY_MATCH ; if less, match length is complete JSR GETSRC ; get extra byte of variable match length - CLC - ADC #$18 ; overflow? + ; the carry is always set by the CMP above + ; GETSRC doesn't change it + SBC #$E8 ; overflow? BCC PREPARE_COPY_MATCH ; if not, the match length is complete BEQ DECOMPRESSION_DONE ; if EOD code, bail diff --git a/src/expand_streaming.c b/src/expand_streaming.c index f96755b..215c265 100644 --- a/src/expand_streaming.c +++ b/src/expand_streaming.c @@ -185,8 +185,9 @@ lzsa_status_t lzsa_decompress_stream(lzsa_stream_t *pInStream, lzsa_stream_t *pO } size_t nReadBytes = pInStream->read(pInStream, pInBlock, nBlockSize); if (nFlags & LZSA_FLAG_RAW_BLOCK) { - if (nReadBytes > 2) - nReadBytes -= 2; + size_t nEODBytes = (nFormatVersion == 2) ? 2 : 4; + if (nReadBytes > nEODBytes) + nReadBytes -= nEODBytes; else nReadBytes = 0; nBlockSize = (unsigned int)nReadBytes;