mirror of
https://github.com/pfusik/zlib6502.git
synced 2024-06-15 13:29:29 +00:00
Make the routine ROM-friendly - the initialized data is now constant. Shorten by four bytes.
This commit is contained in:
parent
bc8b90cf24
commit
e5dfc7db2f
|
@ -15,7 +15,7 @@ Use [xasm](https://github.com/pfusik/xasm).
|
||||||
|
|
||||||
The routine uses three memory areas:
|
The routine uses three memory areas:
|
||||||
|
|
||||||
* `inflate` - code and initialized data (508 bytes)
|
* `inflate` - code and constants (504 bytes)
|
||||||
* `inflate_data` - uninitialized data (764 bytes)
|
* `inflate_data` - uninitialized data (764 bytes)
|
||||||
* `inflate_zp` - variables on zero page
|
* `inflate_zp` - variables on zero page
|
||||||
|
|
||||||
|
|
27
inflate.asx
27
inflate.asx
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
; 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 508 bytes of code and initialized data
|
; inflate is 504 bytes of code and constants
|
||||||
; inflate_data is 764 bytes of uninitialized data
|
; inflate_data is 764 bytes of uninitialized data
|
||||||
; inflate_zp is 10 bytes on page zero
|
; inflate_zp is 10 bytes on page zero
|
||||||
|
|
||||||
|
@ -24,13 +24,13 @@ inflateStoredBlock_pageCounter equ inflate_zp+5 ; 1 byte
|
||||||
|
|
||||||
inflateCodes_sourcePointer equ inflate_zp+6 ; 2 bytes
|
inflateCodes_sourcePointer equ inflate_zp+6 ; 2 bytes
|
||||||
inflateDynamicBlock_lengthIndex equ inflate_zp+6 ; 1 byte
|
inflateDynamicBlock_lengthIndex equ inflate_zp+6 ; 1 byte
|
||||||
inflateDynamicBlock_lastLength equ inflate_zp+7 ; 1 byte
|
inflateDynamicBlock_lastLength equ inflate_zp+7 ; 1 byte
|
||||||
inflateDynamicBlock_tempCodes equ inflate_zp+7 ; 1 byte
|
inflateDynamicBlock_tempCodes equ inflate_zp+7 ; 1 byte
|
||||||
|
|
||||||
inflateCodes_lengthMinus2 equ inflate_zp+8 ; 1 byte
|
inflateCodes_lengthMinus2 equ inflate_zp+8 ; 1 byte
|
||||||
inflateDynamicBlock_allCodes equ inflate_zp+8 ; 1 byte
|
inflateDynamicBlock_allCodes equ inflate_zp+8 ; 1 byte
|
||||||
|
|
||||||
inflateCodes_primaryCodes equ inflate_zp+9 ; 1 byte
|
inflateDynamicBlock_primaryCodes equ inflate_zp+9 ; 1 byte
|
||||||
|
|
||||||
|
|
||||||
; Argument values for getBits
|
; Argument values for getBits
|
||||||
|
@ -123,7 +123,6 @@ inflateFixedBlock_setControlCodeLength
|
||||||
inflateFixedBlock_noControlSymbol
|
inflateFixedBlock_noControlSymbol
|
||||||
iny
|
iny
|
||||||
bne inflateFixedBlock_setCodeLengths
|
bne inflateFixedBlock_setCodeLengths
|
||||||
mva #LENGTH_SYMBOLS inflateCodes_primaryCodes
|
|
||||||
|
|
||||||
dex
|
dex
|
||||||
beq inflateCodes
|
beq inflateCodes
|
||||||
|
@ -142,11 +141,11 @@ inflateDynamicBlock_decodeLength
|
||||||
; Fetch a temporary code
|
; Fetch a temporary code
|
||||||
jsr fetchPrimaryCode
|
jsr fetchPrimaryCode
|
||||||
; Temporary code 0..15: put this length
|
; Temporary code 0..15: put this length
|
||||||
tax
|
|
||||||
bpl inflateDynamicBlock_verbatimLength
|
bpl inflateDynamicBlock_verbatimLength
|
||||||
; Temporary code 16: repeat last length 3 + getBits(2) times
|
; Temporary code 16: repeat last length 3 + getBits(2) times
|
||||||
; Temporary code 17: put zero length 3 + getBits(3) times
|
; Temporary code 17: put zero length 3 + getBits(3) times
|
||||||
; Temporary code 18: put zero length 11 + getBits(7) times
|
; Temporary code 18: put zero length 11 + getBits(7) times
|
||||||
|
tax
|
||||||
jsr getBits
|
jsr getBits
|
||||||
; sec
|
; sec
|
||||||
adc #1
|
adc #1
|
||||||
|
@ -171,8 +170,13 @@ inflateDynamicBlock_storeNext
|
||||||
; jmp inflateDynamicBlock_decodeLength
|
; jmp inflateDynamicBlock_decodeLength
|
||||||
beq inflateDynamicBlock_decodeLength
|
beq inflateDynamicBlock_decodeLength
|
||||||
inflateDynamicBlock_controlSymbolCodeLength
|
inflateDynamicBlock_controlSymbolCodeLength
|
||||||
cpx inflateCodes_primaryCodes
|
cpx inflateDynamicBlock_primaryCodes
|
||||||
scc:ora #DISTANCE_TREE
|
bcc inflateDynamicBlock_storeControl
|
||||||
|
; the code lengths we skip here were zero-initialized
|
||||||
|
; in inflateDynamicBlock_clearCodeLengths
|
||||||
|
sne:ldx #LENGTH_SYMBOLS
|
||||||
|
ora #DISTANCE_TREE
|
||||||
|
inflateDynamicBlock_storeControl
|
||||||
sta controlSymbolCodeLength,x+
|
sta controlSymbolCodeLength,x+
|
||||||
cpx inflateDynamicBlock_allCodes
|
cpx inflateDynamicBlock_allCodes
|
||||||
bcc inflateDynamicBlock_storeNext
|
bcc inflateDynamicBlock_storeNext
|
||||||
|
@ -186,7 +190,6 @@ inflateCodes
|
||||||
inflateCodes_loop
|
inflateCodes_loop
|
||||||
jsr fetchPrimaryCode
|
jsr fetchPrimaryCode
|
||||||
bcc inflateStoreByte
|
bcc inflateStoreByte
|
||||||
tax
|
|
||||||
beq inflate_nextBlock
|
beq inflate_nextBlock
|
||||||
; Copy sequence from look-behind buffer
|
; Copy sequence from look-behind buffer
|
||||||
; ldy #0
|
; ldy #0
|
||||||
|
@ -211,9 +214,6 @@ inflateCodes_setSequenceLength
|
||||||
sta inflateCodes_lengthMinus2
|
sta inflateCodes_lengthMinus2
|
||||||
ldx #DISTANCE_TREE
|
ldx #DISTANCE_TREE
|
||||||
jsr fetchCode
|
jsr fetchCode
|
||||||
; sec
|
|
||||||
sbc inflateCodes_primaryCodes
|
|
||||||
tax
|
|
||||||
cmp #4
|
cmp #4
|
||||||
bcc inflateCodes_setOffsetLowByte
|
bcc inflateCodes_setOffsetLowByte
|
||||||
inc getBits_base
|
inc getBits_base
|
||||||
|
@ -260,7 +260,6 @@ inflateDynamicBlock_getHeader
|
||||||
; sec
|
; sec
|
||||||
adc inflateDynamicBlock_headerBase-1,x
|
adc inflateDynamicBlock_headerBase-1,x
|
||||||
sta inflateDynamicBlock_tempCodes-1,x
|
sta inflateDynamicBlock_tempCodes-1,x
|
||||||
sta inflateDynamicBlock_headerBase+1
|
|
||||||
dex
|
dex
|
||||||
bne inflateDynamicBlock_getHeader
|
bne inflateDynamicBlock_getHeader
|
||||||
|
|
||||||
|
@ -353,6 +352,8 @@ fetchCode_control
|
||||||
adc nBitCode_controlOffset-1,x
|
adc nBitCode_controlOffset-1,x
|
||||||
tax
|
tax
|
||||||
lda codeToControlSymbol-1,x
|
lda codeToControlSymbol-1,x
|
||||||
|
and #$1f ; make distance symbols zero-based
|
||||||
|
tax
|
||||||
sec
|
sec
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@ -422,7 +423,7 @@ tempCodeLengthOrder
|
||||||
dta GET_2_BITS,GET_3_BITS,GET_7_BITS,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15
|
dta GET_2_BITS,GET_3_BITS,GET_7_BITS,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15
|
||||||
|
|
||||||
inflateDynamicBlock_headerBits dta GET_4_BITS,GET_5_BITS,GET_5_BITS
|
inflateDynamicBlock_headerBits dta GET_4_BITS,GET_5_BITS,GET_5_BITS
|
||||||
inflateDynamicBlock_headerBase dta 3,0,0 ; second byte is modified at runtime!
|
inflateDynamicBlock_headerBase dta 3,LENGTH_SYMBOLS,0
|
||||||
|
|
||||||
org inflate_data
|
org inflate_data
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user