Fixing decompressor bugs.

This commit is contained in:
Martin Haye 2014-03-17 07:49:40 -07:00
parent 95fbd98acb
commit 539c878c5f
2 changed files with 50 additions and 12 deletions

View File

@ -534,7 +534,7 @@ class PackPartitions
} }
if (debugCompression) if (debugCompression)
println "Literal: $literalLen bytes." println String.format("Literal: len=\$%x.", literalLen)
// Copy the literal bytes // Copy the literal bytes
outLen += literalLen outLen += literalLen
@ -571,7 +571,7 @@ class PackPartitions
matchLen += 4 // min match length is 4 matchLen += 4 // min match length is 4
if (debugCompression) if (debugCompression)
println "Match: $matchLen bytes at offset $offset." println String.format("Match: offset=\$%x, len=\$%x.", offset, matchLen)
// We do nothing with the match bytes except count them // We do nothing with the match bytes except count them
outLen += matchLen outLen += matchLen
@ -611,14 +611,14 @@ class PackPartitions
// If we saved at least 20 bytes, take the compressed version. // If we saved at least 20 bytes, take the compressed version.
if ((uncompressedLen - recompressedLen) >= 20) { if ((uncompressedLen - recompressedLen) >= 20) {
if (debugCompression) if (debugCompression)
println " Compress. rawLen=$uncompressedLen compLen=$recompressedLen" println String.format(" Compress. rawLen=\$%x compLen=\$%x", uncompressedLen, recompressedLen)
compressionSavings += (uncompressedLen - recompressedLen) - 2 - (ADD_COMP_CHECKSUMS ? 1 : 0) compressionSavings += (uncompressedLen - recompressedLen) - 2 - (ADD_COMP_CHECKSUMS ? 1 : 0)
return [data:compressedData, len:recompressedLen, return [data:compressedData, len:recompressedLen,
compressed:true, uncompressedLen:uncompressedLen] compressed:true, uncompressedLen:uncompressedLen]
} }
else { else {
if (debugCompression) if (debugCompression)
println " No compress. rawLen=$uncompressedLen compLen=$recompressedLen" println String.format(" No compress. rawLen=\$%x compLen=\$%x", uncompressedLen, recompressedLen)
return [data:uncompressedData, len:uncompressedLen, compressed:false] return [data:uncompressedData, len:uncompressedLen, compressed:false]
} }
} }

View File

@ -1266,7 +1266,7 @@ lz4Decompress: !zone
pla ; toss unused match length pla ; toss unused match length
!if DO_COMP_CHECKSUMS { !if DO_COMP_CHECKSUMS {
lda checksum ; get computed checksum lda checksum ; get computed checksum
bne + ; should be zero, because compressor stores checksum byte as part of stream beq + ; should be zero, because compressor stores checksum byte as part of stream
brk ; checksum doesn't match -- abort! brk ; checksum doesn't match -- abort!
+ } + }
rts ; all done! rts ; all done!
@ -1274,6 +1274,7 @@ lz4Decompress: !zone
.decodeMatch: .decodeMatch:
+LOAD_YSRC ; grab first byte of match offset +LOAD_YSRC ; grab first byte of match offset
sta tmp ; save for later sta tmp ; save for later
cmp #0
bmi .far ; if hi bit is set, there will be a second byte bmi .far ; if hi bit is set, there will be a second byte
lda #0 ; otherwise, second byte is assumed to be zero lda #0 ; otherwise, second byte is assumed to be zero
beq .doInv ; always taken beq .doInv ; always taken
@ -1289,6 +1290,7 @@ lz4Decompress: !zone
lda .dstStore2+2 ; same with hi byte of offset lda .dstStore2+2 ; same with hi byte of offset
sbc tmp+1 sbc tmp+1
sta .srcLoad+2 ; to hi byte of offsetted pointer sta .srcLoad+2 ; to hi byte of offsetted pointer
!if DEBUG { jsr .debug4 }
.getMatchLen: .getMatchLen:
pla ; recover the token byte pla ; recover the token byte
and #$F ; mask to get just the match length and #$F ; mask to get just the match length
@ -1356,8 +1358,8 @@ nextSrcPage:
sta clrAuxWr ; buffer is in main mem sta clrAuxWr ; buffer is in main mem
jsr readToBuf ; read more pages jsr readToBuf ; read more pages
.auxWr3 sta setAuxWr ; go back to writing aux mem (self-modified for aux or main) .auxWr3 sta setAuxWr ; go back to writing aux mem (self-modified for aux or main)
pla ; restore loaded byte + pla ; restore loaded byte
+ rts rts
.nextDstPage: .nextDstPage:
sta clrAuxWr ; write to main mem so we can increment stuff in code blocks sta clrAuxWr ; write to main mem so we can increment stuff in code blocks
@ -1390,15 +1392,51 @@ setupDecomp:
+prWord ucLen +prWord ucLen
+crout +crout
rts rts
.debug2 +prStr : !text "Lit len=",0 .debug2 +prStr : !text "Lit ptr=",0
tya
clc
adc pSrc
sta pTmp
lda pSrc+1
adc #0
sta pTmp+1
+prWord pTmp
+prStr : !text "len=",0
+prWord ucLen
+crout
rts
.debug3 +prStr : !text "len=",0
+prWord ucLen +prWord ucLen
+crout +crout
+waitKey +waitKey
rts rts
.debug3 +prStr : !text "Match len=",0 .debug4 +prStr : !text "Match src=",0
+prWord ucLen txa ; calculate src address with X (not Y!) as offset
+crout clc
+waitKey adc .srcLoad+1
sta pTmp
lda .srcLoad+2
adc #0
sta pTmp+1
+prWord pTmp
+prStr : !text "dst=",0
txa ; calculate dest address with X as offset
clc
adc .dstStore2+1
sta tmp
lda .dstStore2+2
adc #0
sta tmp+1
+prWord tmp
+prStr : !text "offset=",0
lda tmp ; now calculate the difference
sec
sbc pTmp
sta pTmp
lda tmp+1
sbc pTmp+1
sta pTmp+1
+prWord pTmp ; and print it
rts rts
} }