A2osX/SHARED/X.UNPAK.S.txt
2019-10-16 22:42:21 +02:00

234 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 jsr X.Unpak.GetNextByte CHNK.DATA.T
tax
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
and #$0f
ldx #0
cmp #8
bcc .10
and #7
tax
lda #8
.10 sta ZPBLOfsLBits
stx ZPBLOfsHBits
jsr X.Unpak.GetNextByte ULEN LO
eor #$ff
sta ZPnCnt
jsr X.Unpak.GetNextByte ULEN HI
eor #$ff
sta ZPnCnt+1
jsr X.Unpak.GetNextByte get TOPCNT
ldx ZPInBufPtr ZPPtr1 = TOP table
stx ZPPtr1
ldx ZPInBufPtr+1
stx ZPPtr1+1
clc
adc ZPInBufPtr skip TOP table
sta ZPInBufPtr
bcc .11
inc ZPInBufPtr+1
.11 lda #$80
sta ZPInMask
*--------------------------------------
.2 jsr X.Unpak.GetBitInC
bcs .3 ->TOP
* BYTE8
ldx #8
jsr X.Unpak.GetXBitInA
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 #%1000
bra .51
*--------------------------------------
.5 jsr X.Unpak.GetBitInC
bcs .6 ->BACKLINK
* TOP32
ldx #4
jsr X.Unpak.GetXBitInA
ora #%10000
.51 tay
lda (ZPPtr1),y
.52 jsr X.Unpak.PutByte
bne .80
.99 sec
rts
*--------------------------------------
* BACKLINK : 1111 OfsLBits OfsHBits LenBits
.6 ldx ZPBLOfsLBits
jsr X.Unpak.GetXBitInA
eor #$ff
sec
adc ZPOutBufPtr
sta ZPPtr2
lda ZPBLOfsHBits
beq .61
php
tax
jsr X.Unpak.GetXBitInA
plp
.61 eor #$ff
adc ZPOutBufPtr+1
sta ZPPtr2+1
ldx ZPBLLenBits
jsr X.Unpak.GetXBitInA
inc +1
inc +1
inc +1
tax
ldy #0
.62 lda (ZPPtr2),y
jsr X.Unpak.PutByte
bne .63
dex
bne .99
clc
rts
.63 iny
dex
bne .62
.80 lda ZPnCnt
and ZPnCnt+1
inc
bne .2
clc
rts
*--------------------------------------
X.Unpak.GetXBitInA
lda #0
.1 pha
jsr X.Unpak.GetBitInC
pla
rol
dex
bne .1
rts
*--------------------------------------
X.Unpak.GetBitInC
clc
lda (ZPInBufPtr)
and ZPInMask
beq .1
sec
.1 php
lsr ZPInMask
bcc .8
ror ZPInMask
jsr X.Unpak.NextByte
.8 plp
rts
*--------------------------------------
X.Unpak.GetNextByte
lda (ZPInBufPtr)
X.Unpak.NextByte
inc ZPInBufPtr
bne .8
inc ZPInBufPtr+1
.8 rts
*--------------------------------------
X.Unpak.PutByte inc ZPnCnt
bne .1
inc ZPnCnt+1
beq .8
.1 sta (ZPOutBufPtr)
inc ZPOutBufPtr
bne .8
inc ZPOutBufPtr+1
.8 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