mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2024-11-22 05:33:58 +00:00
commit
6445d9ff6f
@ -42,7 +42,7 @@ DECODE_TOKEN
|
||||
LSR A
|
||||
LSR A
|
||||
CMP #$07 ; LITERALS_RUN_LEN?
|
||||
BNE PREPARE_COPY_LITERALS ; if not, count is directly embedded in token
|
||||
BCC PREPARE_COPY_LITERALS ; if not, count is directly embedded in token
|
||||
|
||||
JSR GETSRC ; get extra byte of variable literals count
|
||||
; the carry is always set by the CMP above
|
||||
@ -62,7 +62,6 @@ LARGE_VARLEN_LITERALS ; handle 16 bits literals count
|
||||
BYTE $A9 ; mask TAX (faster than BCS)
|
||||
PREPARE_COPY_LITERALS
|
||||
TAX
|
||||
PREPARE_COPY_LITERALS_HIGH
|
||||
INY
|
||||
|
||||
COPY_LITERALS
|
||||
@ -95,7 +94,8 @@ PREPARE_COPY_MATCH_Y
|
||||
COPY_MATCH_LOOP
|
||||
LDA $AAAA ; get one byte of backreference
|
||||
INC COPY_MATCH_LOOP+1
|
||||
BEQ GETMATCH_INC_HI
|
||||
BNE GETMATCH_DONE
|
||||
INC COPY_MATCH_LOOP+2
|
||||
GETMATCH_DONE
|
||||
JSR PUTDST ; copy to destination
|
||||
DEX
|
||||
@ -104,10 +104,6 @@ GETMATCH_DONE
|
||||
BNE COPY_MATCH_LOOP
|
||||
BEQ DECODE_TOKEN ; (*like JMP DECODE_TOKEN but shorter)
|
||||
|
||||
GETMATCH_INC_HI
|
||||
INC COPY_MATCH_LOOP+2
|
||||
BNE GETMATCH_DONE ; (*like JMP GETMATCH_DONE but shorter)
|
||||
|
||||
GET_LONG_OFFSET ; handle 16 bit offset:
|
||||
JSR GETLARGESRC ; grab low 8 bits in X, high 8 bits in A
|
||||
|
||||
@ -128,7 +124,7 @@ OFFSHI = *+1
|
||||
AND #$0F ; isolate match len (MMMM)
|
||||
ADC #$02 ; plus carry which is always set by the high ADC
|
||||
CMP #$12 ; MATCH_RUN_LEN?
|
||||
BNE PREPARE_COPY_MATCH ; if not, count is directly embedded in token
|
||||
BCC PREPARE_COPY_MATCH ; if not, count is directly embedded in token
|
||||
|
||||
JSR GETSRC ; get extra byte of variable match length
|
||||
; the carry is always set by the CMP above
|
||||
@ -142,7 +138,7 @@ OFFSHI = *+1
|
||||
TAY ; put high 8 bits in Y
|
||||
; large match length with zero high byte?
|
||||
BNE PREPARE_COPY_MATCH_Y ; if not, continue
|
||||
; (*like JMP PREPARE_COPY_MATCH_Y but shorter)
|
||||
|
||||
DECOMPRESSION_DONE
|
||||
RTS
|
||||
|
||||
@ -153,11 +149,9 @@ LZSA_DST_LO = *+1
|
||||
LZSA_DST_HI = *+2
|
||||
STA $AAAA
|
||||
INC PUTDST+1
|
||||
BEQ PUTDST_INC_HI
|
||||
PUTDST_DONE
|
||||
RTS
|
||||
PUTDST_INC_HI
|
||||
BNE PUTDST_DONE
|
||||
INC PUTDST+2
|
||||
PUTDST_DONE
|
||||
RTS
|
||||
|
||||
GETLARGESRC
|
||||
@ -170,9 +164,7 @@ LZSA_SRC_LO = *+1
|
||||
LZSA_SRC_HI = *+2
|
||||
LDA $AAAA
|
||||
INC GETSRC+1
|
||||
BEQ GETSRC_INC_HI
|
||||
BNE GETSRC_DONE
|
||||
INC GETSRC+2
|
||||
GETSRC_DONE
|
||||
RTS
|
||||
GETSRC_INC_HI
|
||||
INC GETSRC+2
|
||||
RTS
|
||||
|
@ -41,34 +41,32 @@ DECODE_TOKEN
|
||||
|
||||
AND #$18 ; isolate literals count (LL)
|
||||
BEQ NO_LITERALS ; skip if no literals to copy
|
||||
CMP #$18 ; LITERALS_RUN_LEN_V2 << 3?
|
||||
BNE EMBEDDED_LITERALS ; if less, count is directly embedded in token
|
||||
LSR A ; shift literals count into place
|
||||
LSR A
|
||||
LSR A
|
||||
CMP #$03 ; LITERALS_RUN_LEN_V2?
|
||||
BCC PREPARE_COPY_LITERALS ; if less, count is directly embedded in token
|
||||
|
||||
JSR GETNIBBLE ; get extra literals length nibble
|
||||
; add nibble to len from token
|
||||
ADC #$02 ; (LITERALS_RUN_LEN_V2) minus carry
|
||||
CMP #$12 ; LITERALS_RUN_LEN_V2 + 15 ?
|
||||
BNE PREPARE_COPY_LITERALS ; if less, literals count is complete
|
||||
BCC PREPARE_COPY_LITERALS ; if less, literals count is complete
|
||||
|
||||
JSR GETSRC ; get extra byte of variable literals count
|
||||
; 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
|
||||
|
||||
PREPARE_COPY_LITERALS
|
||||
TAX
|
||||
BCC PREPARE_COPY_LITERALS_HIGH ; if not, literals count is complete
|
||||
|
||||
; handle 16 bits literals count
|
||||
; literals count = directly these 16 bits
|
||||
JSR GETLARGESRC ; grab low 8 bits in X, high 8 bits in A
|
||||
TAY ; put high 8 bits in Y
|
||||
BCS PREPARE_COPY_LITERALS_HIGH ; (*like JMP PREPARE_COPY_LITERALS_HIGH but shorter)
|
||||
|
||||
EMBEDDED_LITERALS
|
||||
LSR A ; shift literals count into place
|
||||
LSR A
|
||||
LSR A
|
||||
|
||||
PREPARE_COPY_LITERALS
|
||||
TAX
|
||||
PREPARE_COPY_LITERALS_HIGH
|
||||
INY
|
||||
|
||||
@ -144,35 +142,36 @@ OFFSHI = *+1
|
||||
AND #$07 ; isolate match len (MMM)
|
||||
ADC #$01 ; add MIN_MATCH_SIZE_V2 and carry
|
||||
CMP #$09 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2?
|
||||
BNE PREPARE_COPY_MATCH ; if less, length is directly embedded in token
|
||||
BCC PREPARE_COPY_MATCH ; if less, length is directly embedded in token
|
||||
|
||||
JSR GETNIBBLE ; get extra match length nibble
|
||||
; add nibble to len from token
|
||||
ADC #$08 ; (MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2) minus carry
|
||||
CMP #$18 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2 + 15?
|
||||
BNE PREPARE_COPY_MATCH ; if less, match length is complete
|
||||
BCC PREPARE_COPY_MATCH ; if less, match length is complete
|
||||
|
||||
JSR GETSRC ; get extra byte of variable match length
|
||||
; 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
|
||||
|
||||
PREPARE_COPY_MATCH
|
||||
TAX
|
||||
BCC PREPARE_COPY_MATCH_Y ; if not, the match length is complete
|
||||
BEQ DECOMPRESSION_DONE ; if EOD code, bail
|
||||
|
||||
; Handle 16 bits match length
|
||||
JSR GETLARGESRC ; grab low 8 bits in X, high 8 bits in A
|
||||
TAY ; put high 8 bits in Y
|
||||
BYTE $A9 ; mask TAX, faster than TXA/TAX
|
||||
|
||||
PREPARE_COPY_MATCH
|
||||
TAX
|
||||
PREPARE_COPY_MATCH_Y
|
||||
INY
|
||||
|
||||
COPY_MATCH_LOOP
|
||||
LDA $AAAA ; get one byte of backreference
|
||||
INC COPY_MATCH_LOOP+1
|
||||
BEQ GETMATCH_INC_HI
|
||||
BNE GETMATCH_DONE
|
||||
INC COPY_MATCH_LOOP+2
|
||||
GETMATCH_DONE
|
||||
JSR PUTDST ; copy to destination
|
||||
DEX
|
||||
@ -180,9 +179,6 @@ GETMATCH_DONE
|
||||
DEY
|
||||
BNE COPY_MATCH_LOOP
|
||||
JMP DECODE_TOKEN
|
||||
GETMATCH_INC_HI
|
||||
INC COPY_MATCH_LOOP+2
|
||||
BNE GETMATCH_DONE ; (*like JMP GETMATCH_DONE but shorter)
|
||||
|
||||
GETCOMBINEDBITS
|
||||
EOR #$80
|
||||
@ -193,6 +189,7 @@ GETCOMBINEDBITS
|
||||
PLP ; merge Z bit as the carry bit (for offset bit 0)
|
||||
COMBINEDBITZ
|
||||
ROL ; nibble -> bits 1-4; carry(!Z bit) -> bit 0 ; carry cleared
|
||||
DECOMPRESSION_DONE
|
||||
RTS
|
||||
|
||||
GETNIBBLE
|
||||
@ -221,12 +218,9 @@ LZSA_DST_LO = *+1
|
||||
LZSA_DST_HI = *+2
|
||||
STA $AAAA
|
||||
INC PUTDST+1
|
||||
BEQ PUTDST_INC_HI
|
||||
PUTDST_DONE
|
||||
DECOMPRESSION_DONE
|
||||
RTS
|
||||
PUTDST_INC_HI
|
||||
BNE PUTDST_DONE
|
||||
INC PUTDST+2
|
||||
PUTDST_DONE
|
||||
RTS
|
||||
|
||||
GETLARGESRC
|
||||
@ -239,9 +233,7 @@ LZSA_SRC_LO = *+1
|
||||
LZSA_SRC_HI = *+2
|
||||
LDA $AAAA
|
||||
INC GETSRC+1
|
||||
BEQ GETSRC_INC_HI
|
||||
BNE GETSRC_DONE
|
||||
INC GETSRC+2
|
||||
GETSRC_DONE
|
||||
RTS
|
||||
GETSRC_INC_HI
|
||||
INC GETSRC+2
|
||||
RTS
|
||||
|
@ -89,8 +89,8 @@ lzsa2_decompress:
|
||||
jmp short .get_match_length
|
||||
|
||||
.rep_match_or_large_offset:
|
||||
cmp dl,0c0H ; check if this is a 13-bit offset or a 16-bit offset/rep match (Y bit)
|
||||
jnb .rep_match_or_16_bit
|
||||
;;cmp dl,0c0H ; check if this is a 13-bit offset or a 16-bit offset/rep match (Y bit)
|
||||
jpe .rep_match_or_16_bit
|
||||
|
||||
; 13 bit offset
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user