mirror of
https://github.com/pfusik/zlib6502.git
synced 2024-09-27 11:55:11 +00:00
Fix more than 256 codes of same length.
Fix all 256 literal codes of same length. Fixes #2
This commit is contained in:
parent
02c09a514e
commit
0608c9adef
@ -15,8 +15,8 @@ Use [xasm](https://github.com/pfusik/xasm).
|
|||||||
|
|
||||||
The routine uses three memory areas:
|
The routine uses three memory areas:
|
||||||
|
|
||||||
* `inflate` - code and constants (492 bytes)
|
* `inflate` - code and constants (508 bytes)
|
||||||
* `inflate_data` - uninitialized data (764 bytes)
|
* `inflate_data` - uninitialized data (765 bytes)
|
||||||
* `inflate_zp` - variables on zero page
|
* `inflate_zp` - variables on zero page
|
||||||
|
|
||||||
You must select these locations at compile time, for example:
|
You must select these locations at compile time, for example:
|
||||||
|
40
inflate.asx
40
inflate.asx
@ -1,11 +1,11 @@
|
|||||||
; inflate - uncompress data stored in the DEFLATE format
|
; inflate - uncompress data stored in the DEFLATE format
|
||||||
; by Piotr Fusik <fox@scene.pl>
|
; by Piotr Fusik <fox@scene.pl>
|
||||||
; Last modified: 2017-11-06
|
; Last modified: 2017-11-07
|
||||||
|
|
||||||
; Compile with xasm (http://xasm.atari.org/), for example:
|
; Compile with xasm (http://xasm.atari.org/), for example:
|
||||||
; xasm inflate.asx /l /d:inflate=$b700 /d:inflate_data=$b900 /d:inflate_zp=$f0
|
; xasm inflate.asx /l /d:inflate=$b700 /d:inflate_data=$b900 /d:inflate_zp=$f0
|
||||||
; inflate is 492 bytes of code and constants
|
; inflate is 508 bytes of code and constants
|
||||||
; inflate_data is 764 bytes of uninitialized data
|
; inflate_data is 765 bytes of uninitialized data
|
||||||
; inflate_zp is 10 bytes on page zero
|
; inflate_zp is 10 bytes on page zero
|
||||||
|
|
||||||
|
|
||||||
@ -288,6 +288,7 @@ buildHuffmanTree
|
|||||||
buildHuffmanTree_countCodeLengths
|
buildHuffmanTree_countCodeLengths
|
||||||
ldx literalSymbolCodeLength,y
|
ldx literalSymbolCodeLength,y
|
||||||
inc nBitCode_literalCount,x
|
inc nBitCode_literalCount,x
|
||||||
|
sne:stx allLiteralsCodeLength
|
||||||
cpy #CONTROL_SYMBOLS
|
cpy #CONTROL_SYMBOLS
|
||||||
bcs buildHuffmanTree_noControlSymbol
|
bcs buildHuffmanTree_noControlSymbol
|
||||||
ldx controlSymbolCodeLength,y
|
ldx controlSymbolCodeLength,y
|
||||||
@ -335,11 +336,33 @@ fetchCode_nextBit
|
|||||||
jsr getBit
|
jsr getBit
|
||||||
rol @
|
rol @
|
||||||
inx
|
inx
|
||||||
|
bcs fetchCode_ge256
|
||||||
|
; are all 256 literal codes of this length?
|
||||||
|
cpx allLiteralsCodeLength
|
||||||
|
beq fetchCode_allLiterals
|
||||||
|
; is it literal code of length X?
|
||||||
sub nBitCode_literalCount,x
|
sub nBitCode_literalCount,x
|
||||||
bcc fetchCode_literal
|
bcs fetchCode_tryControl
|
||||||
|
; literal code
|
||||||
|
fetchCode_literal
|
||||||
|
; clc
|
||||||
|
adc nBitCode_literalOffset,x
|
||||||
|
fetchCode_allLiterals
|
||||||
|
tax
|
||||||
|
lda codeToLiteralSymbol,x
|
||||||
|
clc
|
||||||
|
rts
|
||||||
|
; code >= 256, must be control
|
||||||
|
fetchCode_ge256
|
||||||
|
; sec
|
||||||
|
sbc nBitCode_literalCount,x
|
||||||
|
sec
|
||||||
|
; is it control code of length X?
|
||||||
|
fetchCode_tryControl
|
||||||
; sec
|
; sec
|
||||||
sbc nBitCode_controlCount,x
|
sbc nBitCode_controlCount,x
|
||||||
bcs fetchCode_nextBit
|
bcs fetchCode_nextBit
|
||||||
|
; control code
|
||||||
; clc
|
; clc
|
||||||
adc nBitCode_controlOffset,x
|
adc nBitCode_controlOffset,x
|
||||||
tax
|
tax
|
||||||
@ -348,13 +371,6 @@ fetchCode_nextBit
|
|||||||
tax
|
tax
|
||||||
; sec
|
; sec
|
||||||
rts
|
rts
|
||||||
fetchCode_literal
|
|
||||||
; clc
|
|
||||||
adc nBitCode_literalOffset,x
|
|
||||||
tax
|
|
||||||
lda codeToLiteralSymbol,x
|
|
||||||
clc
|
|
||||||
rts
|
|
||||||
|
|
||||||
; Read A minus 1 bits, but no more than 8
|
; Read A minus 1 bits, but no more than 8
|
||||||
getAMinus1BitsMax8
|
getAMinus1BitsMax8
|
||||||
@ -446,6 +462,8 @@ nBitCode_literalOffset
|
|||||||
org *+2*TREE_SIZE
|
org *+2*TREE_SIZE
|
||||||
nBitCode_controlOffset
|
nBitCode_controlOffset
|
||||||
org *+2*TREE_SIZE
|
org *+2*TREE_SIZE
|
||||||
|
allLiteralsCodeLength
|
||||||
|
org *+1
|
||||||
|
|
||||||
codeToLiteralSymbol
|
codeToLiteralSymbol
|
||||||
org *+256
|
org *+256
|
||||||
|
Loading…
Reference in New Issue
Block a user