mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2024-10-12 09:23:37 +00:00
smaller
This commit is contained in:
parent
36e7316f30
commit
7861ef1552
@ -29,15 +29,10 @@
|
|||||||
; 3. This notice may not be removed or altered from any source distribution.
|
; 3. This notice may not be removed or altered from any source distribution.
|
||||||
; -----------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------
|
||||||
|
|
||||||
OFFSLO = $43 ; zero-page location for temp offset
|
NIBCOUNT = $FC ; zero-page location for temp offset
|
||||||
OFFSHI = $44
|
|
||||||
FIXUP = $4B
|
|
||||||
NIBBLES = $FB
|
|
||||||
NIBCOUNT = $FC
|
|
||||||
|
|
||||||
DECOMPRESS_LZSA2
|
DECOMPRESS_LZSA2
|
||||||
LDY #$00
|
LDY #$00
|
||||||
STY NIBBLES
|
|
||||||
STY NIBCOUNT
|
STY NIBCOUNT
|
||||||
|
|
||||||
DECODE_TOKEN
|
DECODE_TOKEN
|
||||||
@ -51,7 +46,7 @@ DECODE_TOKEN
|
|||||||
|
|
||||||
JSR GETNIBBLE ; get extra literals length nibble
|
JSR GETNIBBLE ; get extra literals length nibble
|
||||||
; add nibble to len from token
|
; add nibble to len from token
|
||||||
ADC #$03 ; (LITERALS_RUN_LEN_V2)
|
ADC #$02 ; (LITERALS_RUN_LEN_V2) minus carry
|
||||||
CMP #$12 ; LITERALS_RUN_LEN_V2 + 15 ?
|
CMP #$12 ; LITERALS_RUN_LEN_V2 + 15 ?
|
||||||
BNE PREPARE_COPY_LITERALS ; if less, literals count is complete
|
BNE PREPARE_COPY_LITERALS ; if less, literals count is complete
|
||||||
|
|
||||||
@ -87,22 +82,22 @@ COPY_LITERALS
|
|||||||
NO_LITERALS
|
NO_LITERALS
|
||||||
PLA ; retrieve token from stack
|
PLA ; retrieve token from stack
|
||||||
PHA ; preserve token again
|
PHA ; preserve token again
|
||||||
BMI REPMATCH_OR_LARGE_OFFSET ; 1YZ: rep-match or 13/16 bit offset
|
ASL
|
||||||
|
BCS REPMATCH_OR_LARGE_OFFSET ; 1YZ: rep-match or 13/16 bit offset
|
||||||
|
|
||||||
ASL ; 0YZ: 5 or 9 bit offset
|
ASL ; 0YZ: 5 or 9 bit offset
|
||||||
BMI OFFSET_9_BIT
|
BCS OFFSET_9_BIT
|
||||||
|
|
||||||
; 00Z: 5 bit offset
|
; 00Z: 5 bit offset
|
||||||
|
|
||||||
LDX #$0FF ; set offset bits 15-8 to 1
|
LDX #$0FF ; set offset bits 15-8 to 1
|
||||||
STX OFFSHI
|
|
||||||
|
|
||||||
JSR GETCOMBINEDBITS ; rotate Z bit into bit 0, read nibble for bits 4-1
|
JSR GETCOMBINEDBITS ; rotate Z bit into bit 0, read nibble for bits 4-1
|
||||||
ORA #$E0 ; set bits 7-5 to 1
|
ORA #$E0 ; set bits 7-5 to 1
|
||||||
BNE GOT_OFFSET_LO ; go store low byte of match offset and prepare match
|
BNE GOT_OFFSET_LO ; go store low byte of match offset and prepare match
|
||||||
|
|
||||||
OFFSET_9_BIT ; 01Z: 9 bit offset
|
OFFSET_9_BIT ; 01Z: 9 bit offset
|
||||||
ASL ; shift Z (offset bit 8) in place
|
;;ASL ; shift Z (offset bit 8) in place
|
||||||
ROL
|
ROL
|
||||||
ROL
|
ROL
|
||||||
AND #$01
|
AND #$01
|
||||||
@ -112,7 +107,7 @@ OFFSET_9_BIT ; 01Z: 9 bit offset
|
|||||||
|
|
||||||
REPMATCH_OR_LARGE_OFFSET
|
REPMATCH_OR_LARGE_OFFSET
|
||||||
ASL ; 13 bit offset?
|
ASL ; 13 bit offset?
|
||||||
BMI REPMATCH_OR_16_BIT ; handle rep-match or 16-bit offset if not
|
BCS REPMATCH_OR_16_BIT ; handle rep-match or 16-bit offset if not
|
||||||
|
|
||||||
; 10Z: 13 bit offset
|
; 10Z: 13 bit offset
|
||||||
|
|
||||||
@ -122,36 +117,38 @@ REPMATCH_OR_LARGE_OFFSET
|
|||||||
; (*same as JMP GOT_OFFSET_HI but shorter)
|
; (*same as JMP GOT_OFFSET_HI but shorter)
|
||||||
|
|
||||||
REPMATCH_OR_16_BIT ; rep-match or 16 bit offset
|
REPMATCH_OR_16_BIT ; rep-match or 16 bit offset
|
||||||
ASL ; XYZ=111?
|
;;ASL ; XYZ=111?
|
||||||
BMI REP_MATCH ; reuse previous offset if so (rep-match)
|
BMI REP_MATCH ; reuse previous offset if so (rep-match)
|
||||||
|
|
||||||
; 110: handle 16 bit offset
|
; 110: handle 16 bit offset
|
||||||
JSR GETSRC ; grab high 8 bits
|
JSR GETSRC ; grab high 8 bits
|
||||||
GOT_OFFSET_HI
|
GOT_OFFSET_HI
|
||||||
STA OFFSHI ; store high byte of match offset
|
TAX
|
||||||
JSR GETSRC ; grab low 8 bits
|
JSR GETSRC ; grab low 8 bits
|
||||||
GOT_OFFSET_LO
|
GOT_OFFSET_LO
|
||||||
STA OFFSLO ; store low byte of match offset
|
STA OFFSLO ; store low byte of match offset
|
||||||
|
STX OFFSHI ; store high byte of match offset
|
||||||
|
|
||||||
REP_MATCH
|
REP_MATCH
|
||||||
CLC ; add dest + match offset
|
CLC ; add dest + match offset
|
||||||
LDA PUTDST+1 ; low 8 bits
|
LDA PUTDST+1 ; low 8 bits
|
||||||
ADC OFFSLO
|
OFFSLO = *+1
|
||||||
|
ADC #$AA
|
||||||
STA COPY_MATCH_LOOP+1 ; store back reference address
|
STA COPY_MATCH_LOOP+1 ; store back reference address
|
||||||
LDA OFFSHI ; high 8 bits
|
OFFSHI = *+1
|
||||||
|
LDA #$AA ; high 8 bits
|
||||||
ADC PUTDST+2
|
ADC PUTDST+2
|
||||||
STA COPY_MATCH_LOOP+2 ; store high 8 bits of address
|
STA COPY_MATCH_LOOP+2 ; store high 8 bits of address
|
||||||
|
|
||||||
PLA ; retrieve token from stack again
|
PLA ; retrieve token from stack again
|
||||||
AND #$07 ; isolate match len (MMM)
|
AND #$07 ; isolate match len (MMM)
|
||||||
CLC
|
ADC #$01 ; add MIN_MATCH_SIZE_V2 and carry
|
||||||
ADC #$02 ; add MIN_MATCH_SIZE_V2
|
|
||||||
CMP #$09 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2?
|
CMP #$09 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2?
|
||||||
BNE PREPARE_COPY_MATCH ; if less, length is directly embedded in token
|
BNE PREPARE_COPY_MATCH ; if less, length is directly embedded in token
|
||||||
|
|
||||||
JSR GETNIBBLE ; get extra match length nibble
|
JSR GETNIBBLE ; get extra match length nibble
|
||||||
; add nibble to len from token
|
; add nibble to len from token
|
||||||
ADC #$09 ; (MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2)
|
ADC #$08 ; (MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2) minus carry
|
||||||
CMP #$18 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2 + 15?
|
CMP #$18 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2 + 15?
|
||||||
BNE PREPARE_COPY_MATCH ; if less, match length is complete
|
BNE PREPARE_COPY_MATCH ; if less, match length is complete
|
||||||
|
|
||||||
@ -165,7 +162,7 @@ REP_MATCH
|
|||||||
; Handle 16 bits match length
|
; Handle 16 bits match length
|
||||||
JSR GETLARGESRC ; grab low 8 bits in X, high 8 bits in A
|
JSR GETLARGESRC ; grab low 8 bits in X, high 8 bits in A
|
||||||
TAY ; put high 8 bits in Y
|
TAY ; put high 8 bits in Y
|
||||||
TXA
|
.DB $A9 ; mask TAX, faster than TXA/TAX
|
||||||
|
|
||||||
PREPARE_COPY_MATCH
|
PREPARE_COPY_MATCH
|
||||||
TAX
|
TAX
|
||||||
@ -188,34 +185,33 @@ GETMATCH_INC_HI
|
|||||||
BNE GETMATCH_DONE ; (*like JMP GETMATCH_DONE but shorter)
|
BNE GETMATCH_DONE ; (*like JMP GETMATCH_DONE but shorter)
|
||||||
|
|
||||||
GETCOMBINEDBITS
|
GETCOMBINEDBITS
|
||||||
STA FIXUP
|
EOR #$80
|
||||||
|
ASL
|
||||||
|
PHP
|
||||||
|
|
||||||
JSR GETNIBBLE ; get nibble into bits 0-3 (for offset bits 1-4)
|
JSR GETNIBBLE ; get nibble into bits 0-3 (for offset bits 1-4)
|
||||||
BIT FIXUP ; merge Z bit as the carry bit (for offset bit 0)
|
PLP ; merge Z bit as the carry bit (for offset bit 0)
|
||||||
BVS COMBINEDBITZ
|
|
||||||
SEC
|
|
||||||
COMBINEDBITZ
|
COMBINEDBITZ
|
||||||
ROL ; nibble -> bits 1-4; carry(!Z bit) -> bit 0 ; carry cleared
|
ROL ; nibble -> bits 1-4; carry(!Z bit) -> bit 0 ; carry cleared
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
GETNIBBLE
|
GETNIBBLE
|
||||||
|
NIBBLES = *+1
|
||||||
|
LDA #$AA
|
||||||
LSR NIBCOUNT
|
LSR NIBCOUNT
|
||||||
BCS HAS_NIBBLES
|
BCS HAS_NIBBLES
|
||||||
|
|
||||||
INC NIBCOUNT
|
INC NIBCOUNT
|
||||||
JSR GETSRC ; get 2 nibbles
|
JSR GETSRC ; get 2 nibbles
|
||||||
STA NIBBLES
|
STA NIBBLES
|
||||||
LSR A
|
LSR
|
||||||
LSR A
|
LSR
|
||||||
LSR A
|
LSR
|
||||||
LSR A
|
LSR
|
||||||
CLC
|
SEC
|
||||||
RTS
|
|
||||||
|
|
||||||
HAS_NIBBLES
|
HAS_NIBBLES
|
||||||
LDA NIBBLES
|
|
||||||
AND #$0F ; isolate low 4 bits of nibble
|
AND #$0F ; isolate low 4 bits of nibble
|
||||||
CLC
|
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
GETPUT
|
GETPUT
|
||||||
|
Loading…
Reference in New Issue
Block a user