mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2024-08-28 00:28:56 +00:00
Update LZSA2 6502 and 8088 depackers
This commit is contained in:
parent
62003a82c2
commit
272f2e7a29
@ -56,8 +56,9 @@ DECODE_TOKEN
|
|||||||
BNE PREPARE_COPY_LITERALS ; if less, literals count is complete
|
BNE PREPARE_COPY_LITERALS ; if less, literals count is complete
|
||||||
|
|
||||||
JSR GETSRC ; get extra byte of variable literals count
|
JSR GETSRC ; get extra byte of variable literals count
|
||||||
TAX ; non-zero?
|
CLC
|
||||||
BNE PREPARE_COPY_LITERALS_HIGH ; if so, literals count is complete
|
ADC #$12 ; overflow?
|
||||||
|
BCC PREPARE_COPY_LITERALS ; if not, literals count is complete
|
||||||
|
|
||||||
; handle 16 bits literals count
|
; handle 16 bits literals count
|
||||||
; literals count = directly these 16 bits
|
; literals count = directly these 16 bits
|
||||||
@ -96,23 +97,21 @@ NO_LITERALS
|
|||||||
AND #$10
|
AND #$10
|
||||||
STA FIXUP
|
STA FIXUP
|
||||||
|
|
||||||
|
LDA #$0FF ; set offset bits 15-8 to 1
|
||||||
|
STA OFFSHI
|
||||||
|
|
||||||
JSR GETNIBBLE ; get nibble for offset bits 0-3
|
JSR GETNIBBLE ; get nibble for offset bits 0-3
|
||||||
ORA FIXUP ; merge offset bit 4
|
ORA FIXUP ; merge offset bit 4
|
||||||
ORA #$E0 ; set offset bits 7-5 to 1
|
ORA #$E0 ; set offset bits 7-5 to 1
|
||||||
TAX ; store low byte of match offset
|
JMP GOT_OFFSET_LO ; go store low byte of match offset and prepare match
|
||||||
LDA #$0FF ; set offset bits 15-8 to 1
|
|
||||||
BNE GOT_OFFSET ; (*same as JMP GOT_OFFSET but shorter)
|
|
||||||
|
|
||||||
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
|
||||||
ORA #$FE ; set offset bits 15-9 to 1
|
ORA #$FE ; set offset bits 15-9 to 1
|
||||||
STA OFFSHI
|
BNE GOT_OFFSET_HI ; go store high byte, read low byte of match offset and prepare match
|
||||||
|
; (*same as JMP GOT_OFFSET_HI but shorter)
|
||||||
JSR GETSRC ; get offset bits 0-7 from stream in A
|
|
||||||
TAX ; store low byte of match offset
|
|
||||||
JMP GOT_OFFSET_LO ; go prepare match
|
|
||||||
|
|
||||||
REPMATCH_OR_LARGE_OFFSET
|
REPMATCH_OR_LARGE_OFFSET
|
||||||
ASL ; 13 bit offset?
|
ASL ; 13 bit offset?
|
||||||
@ -125,26 +124,24 @@ REPMATCH_OR_LARGE_OFFSET
|
|||||||
AND #$10
|
AND #$10
|
||||||
STA FIXUP
|
STA FIXUP
|
||||||
|
|
||||||
JSR GETSRC ; get offset bits 0-7 from stream in A
|
|
||||||
TAX ; store low byte of match offset
|
|
||||||
|
|
||||||
JSR GETNIBBLE ; get nibble for offset bits 8-11
|
JSR GETNIBBLE ; get nibble for offset bits 8-11
|
||||||
ORA FIXUP ; merge offset bit 12
|
ORA FIXUP ; merge offset bit 12
|
||||||
CLC
|
CLC
|
||||||
ADC #$DE ; set bits 13-15 to 1 and substract 2 (to substract 512)
|
ADC #$DE ; set bits 13-15 to 1 and substract 2 (to substract 512)
|
||||||
BNE GOT_OFFSET ; go prepare match (*same as JMP GOT_OFFSET but shorter)
|
BNE GOT_OFFSET_HI ; go store high byte, read low byte of match offset and prepare match
|
||||||
|
; (*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 GETLARGESRC ; grab low 8 bits in X, high 8 bits in A
|
JSR GETSRC ; grab high 8 bits
|
||||||
|
GOT_OFFSET_HI
|
||||||
GOT_OFFSET
|
STA OFFSHI ; store high byte of match offset
|
||||||
STA OFFSHI ; store final match offset
|
JSR GETSRC ; grab low 8 bits
|
||||||
GOT_OFFSET_LO
|
GOT_OFFSET_LO
|
||||||
STX OFFSLO
|
STA OFFSLO ; store low byte of match offset
|
||||||
|
|
||||||
REP_MATCH
|
REP_MATCH
|
||||||
CLC ; add dest + match offset
|
CLC ; add dest + match offset
|
||||||
@ -169,14 +166,14 @@ REP_MATCH
|
|||||||
BNE PREPARE_COPY_MATCH ; if less, match length is complete
|
BNE PREPARE_COPY_MATCH ; if less, match length is complete
|
||||||
|
|
||||||
JSR GETSRC ; get extra byte of variable match length
|
JSR GETSRC ; get extra byte of variable match length
|
||||||
TAX ; non-zero?
|
CLC
|
||||||
BNE PREPARE_COPY_MATCH_Y ; if so, the match length is complete
|
ADC #$18 ; overflow?
|
||||||
|
BCC PREPARE_COPY_MATCH ; if not, the match length is complete
|
||||||
|
BEQ DECOMPRESSION_DONE ; if EOD code, bail
|
||||||
|
|
||||||
; 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
|
||||||
; large match length with zero high byte?
|
|
||||||
BEQ DECOMPRESSION_DONE ; if so, this is the EOD code, bail
|
|
||||||
TXA
|
TXA
|
||||||
|
|
||||||
PREPARE_COPY_MATCH
|
PREPARE_COPY_MATCH
|
||||||
|
@ -56,8 +56,8 @@ lzsa2_decompress:
|
|||||||
jne .got_literals ; if not, we have the full literals count, go copy
|
jne .got_literals ; if not, we have the full literals count, go copy
|
||||||
|
|
||||||
lodsb ; grab extra length byte
|
lodsb ; grab extra length byte
|
||||||
test al,al ; zero?
|
add al,012H ; overflow?
|
||||||
jne .got_literals ; if not, we have the full literals count, go copy
|
jnc .got_literals ; if not, we have the full literals count, go copy
|
||||||
|
|
||||||
lodsw ; grab 16-bit extra length
|
lodsw ; grab 16-bit extra length
|
||||||
|
|
||||||
@ -96,7 +96,6 @@ lzsa2_decompress:
|
|||||||
jnb .rep_match_or_16_bit
|
jnb .rep_match_or_16_bit
|
||||||
|
|
||||||
; 13 bit offset
|
; 13 bit offset
|
||||||
lodsb ; load match offset bits 0-7
|
|
||||||
|
|
||||||
mov ah,020H ; shift Z (offset bit 12) in place
|
mov ah,020H ; shift Z (offset bit 12) in place
|
||||||
and ah,dl
|
and ah,dl
|
||||||
@ -105,6 +104,7 @@ lzsa2_decompress:
|
|||||||
or ah,cl ; merge nibble
|
or ah,cl ; merge nibble
|
||||||
or ah,0E0H ; set offset bits 15-13 to 1
|
or ah,0E0H ; set offset bits 15-13 to 1
|
||||||
sub ah,2 ; substract 512
|
sub ah,2 ; substract 512
|
||||||
|
lodsb ; load match offset bits 0-7
|
||||||
jmp short .get_match_length
|
jmp short .get_match_length
|
||||||
|
|
||||||
.rep_match_or_16_bit:
|
.rep_match_or_16_bit:
|
||||||
@ -113,6 +113,7 @@ lzsa2_decompress:
|
|||||||
|
|
||||||
; 16 bit offset
|
; 16 bit offset
|
||||||
lodsw ; Get 2-byte match offset
|
lodsw ; Get 2-byte match offset
|
||||||
|
xchg ah,al
|
||||||
|
|
||||||
.get_match_length:
|
.get_match_length:
|
||||||
mov bp,ax ; bp: offset
|
mov bp,ax ; bp: offset
|
||||||
@ -130,12 +131,11 @@ lzsa2_decompress:
|
|||||||
jne .got_matchlen ; no, we have the full match length from the token, go copy
|
jne .got_matchlen ; no, we have the full match length from the token, go copy
|
||||||
|
|
||||||
lodsb ; grab extra length byte
|
lodsb ; grab extra length byte
|
||||||
test al,al ; zero?
|
add al,018H ; overflow?
|
||||||
jne .got_matchlen ; if not, we have the entire length
|
jnc .got_matchlen ; if not, we have the entire length
|
||||||
|
je short .done_decompressing ; detect EOD code
|
||||||
|
|
||||||
lodsw ; grab 16-bit length
|
lodsw ; grab 16-bit length
|
||||||
test ax,ax ; bail if we hit EOD
|
|
||||||
je short .done_decompressing
|
|
||||||
|
|
||||||
.got_matchlen:
|
.got_matchlen:
|
||||||
xchg cx,ax ; copy match length into cx
|
xchg cx,ax ; copy match length into cx
|
||||||
|
Loading…
Reference in New Issue
Block a user