Small improvement over 6502 LZSA2 depacker

This commit is contained in:
Emmanuel Marty 2019-06-08 16:18:36 +02:00 committed by GitHub
parent affa08c213
commit 659f6c14a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -56,8 +56,9 @@ DECODE_TOKEN
BNE PREPARE_COPY_LITERALS ; if less, literals count is complete BNE PREPARE_COPY_LITERALS ; if less, literals count is complete
JSR GETSRC ; get extra byte of variable literals count JSR GETSRC ; get extra byte of variable literals count
CLC ; the carry is always set by the CMP above
ADC #$12 ; overflow? ; GETSRC doesn't change it
SBC #$EE ; overflow?
BCC PREPARE_COPY_LITERALS ; if not, literals count is complete BCC PREPARE_COPY_LITERALS ; if not, literals count is complete
; handle 16 bits literals count ; handle 16 bits literals count
@ -155,8 +156,9 @@ REP_MATCH
BNE PREPARE_COPY_MATCH ; if less, match length is complete BNE PREPARE_COPY_MATCH ; if less, match length is complete
JSR GETSRC ; get extra byte of variable match length JSR GETSRC ; get extra byte of variable match length
CLC ; the carry is always set by the CMP above
ADC #$18 ; overflow? ; GETSRC doesn't change it
SBC #$E8 ; overflow?
BCC PREPARE_COPY_MATCH ; if not, the match length is complete BCC PREPARE_COPY_MATCH ; if not, the match length is complete
BEQ DECOMPRESSION_DONE ; if EOD code, bail BEQ DECOMPRESSION_DONE ; if EOD code, bail

View File

@ -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); size_t nReadBytes = pInStream->read(pInStream, pInBlock, nBlockSize);
if (nFlags & LZSA_FLAG_RAW_BLOCK) { if (nFlags & LZSA_FLAG_RAW_BLOCK) {
if (nReadBytes > 2) size_t nEODBytes = (nFormatVersion == 2) ? 2 : 4;
nReadBytes -= 2; if (nReadBytes > nEODBytes)
nReadBytes -= nEODBytes;
else else
nReadBytes = 0; nReadBytes = 0;
nBlockSize = (unsigned int)nReadBytes; nBlockSize = (unsigned int)nReadBytes;