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
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

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);
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;