A2osX/SHARED/X.UNPAK.S.txt

229 lines
3.8 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
*--------------------------------------
* ZPInBufPtr = Ptr to Shunk Data
* ZPOutBufPtr = Ptr to Uncompressed Data
*--------------------------------------
* ZPnCnt = !ZPULen
* ZPPtr1
* ZPPtr2
* ZPInMask,ZPBLOfsLBits,ZPBLOfsHBits,ZPBLLenBits
*--------------------------------------
X.Unpak lda (ZPInBufPtr) ULEN LO
eor #$ff
sta ZPnCnt
jsr X.Unpak.NextByte
lda (ZPInBufPtr) ULEN HI
eor #$ff
sta ZPnCnt+1
jsr X.Unpak.NextByte
lda (ZPInBufPtr) CHNK.DATA.T
bne X.Unpak.PAK
*--------------------------------------
X.Unpak.STORE ldy #0
.1 iny
bne .2
inc ZPInBufPtr+1
.2 lda (ZPInBufPtr),y
jsr X.Unpak.PutByte
bne .1
clc
rts
*--------------------------------------
X.Unpak.PAK pha A = BLBITS
and #$70
lsr
lsr
lsr
lsr
sta ZPBLLenBits
pla
ldx #8
and #$0f
tax
cmp #8
bcc .10
ldx #8
and #7
.10 stx ZPBLOfsLBits
sta ZPBLOfsHBits
jsr X.Unpak.NextByte get TOPCNT
lda (ZPInBufPtr) CHNK.DATA.PAK.TOPLEN
tax
jsr X.Unpak.NextByte get TOPCNT
lda ZPInBufPtr
sta ZPPtr1
lda ZPInBufPtr+1
sta ZPPtr1+1
txa
clc
adc ZPInBufPtr skip TOP table
sta ZPInBufPtr
lda ZPInBufPtr+1
adc #0
sta ZPInBufPtr+1
lda #$80
sta ZPInMask
*--------------------------------------
.1 lda ZPnCnt
ora ZPnCnt+1
bne .2
clc
rts
*--------------------------------------
.2 jsr X.Unpak.GetBitInC
bcs .3 ->TOP
* BYTE8
jsr X.Unpak.GetByteInA
bra .52
*--------------------------------------
.3 jsr X.Unpak.GetBitInC
bcs .4 ->TOP16
* TOP8
ldx #3
jsr X.Unpak.GetXBitInA
bra .51
*--------------------------------------
.4 jsr X.Unpak.GetBitInC
bcs .5 ->TOP32
* TOP16
ldx #3
jsr X.Unpak.GetXBitInA
ora #8
bra .51
*--------------------------------------
.5 jsr X.Unpak.GetBitInC
bcs .6 ->BACKLINK
* TOP32
ldx #4
jsr X.Unpak.GetXBitInA
ora #32
.51 tay
lda (ZPPtr1),y
.52 jsr X.Unpak.PutByte
bne .2
clc
rts
*--------------------------------------
* BACKLINK : 1111 OfsLBits OfsHBits LenBits
.6 ldx ZPBLOfsLBits
jsr X.Unpak.GetXBitInA
clc
adc ZPOutBufPtr
sta ZPPtr2
php
lda ZPBLOfsHBits
beq .61
tax
jsr X.Unpak.GetXBitInA
.61 plp
adc ZPOutBufPtr+1
sta ZPPtr2+1
ldx ZPBLLenBits
jsr X.Unpak.GetXBitInA
inc +1
inc +1
inc +1
tay
.62 lda (ZPPtr2),y
jsr X.Unpak.PutByte
beq .99
dey
bne .62
bra .1
.99 sec
rts
*--------------------------------------
X.Unpak.GetByteInA
ldx #8
X.Unpak.GetXBitInA
lda #0
.1 jsr X.Unpak.GetBitInC
rol
dex
bne .1
rts
*--------------------------------------
X.Unpak.GetBitInC
pha
clc
lda (ZPInBufPtr)
and ZPInMask
beq .1
sec
.1 php
lsr ZPInMask
bcc .8
ror ZPInMask
jsr X.Unpak.NextByte
.8 plp
pla
rts
*--------------------------------------
X.Unpak.NextByte
inc ZPInBufPtr
bne .8
inc ZPInBufPtr+1
.8 rts
*--------------------------------------
X.Unpak.PutByte sta (ZPOutBufPtr)
inc ZPOutBufPtr
bne .1
inc ZPOutBufPtr+1
.1 inc ZPnCnt
bne .2
inc ZPnCnt+1
.2 rts
*--------------------------------------
.LIST ON
X.Unpak.Size .EQ *-X.Unpak
.LIST OFF
*--------------------------------------
MAN
SAVE USR/SRC/SHARED/X.UNPAK.S
LOAD USR/SRC/BIN/UNPAK.S
ASM