passport/src/unpack.a
2017-08-17 21:45:46 -07:00

178 lines
1.7 KiB
Plaintext

;aPLib data decompressor for Apple II
;Peter Ferrie (peter.ferrie@gmail.com)
;assemble using ACME
;dst<src
!zone {
Unpack ;unpacker entrypoint
lda #0
sta last
sta ecx+1
literal
jsr getput
ldy #2
nexttag
jsr getbit
bcc literal
jsr getbit
bcc codepair
jsr getbit
bcs onebyte
jsr getsrc
lsr
beq donedepacking
ldx #0
stx ecx
rol ecx
stx last+1
tax
bne domatch_with_2inc
getbit
asl last
bne .stillbitsleft
jsr getsrc
asl
sta last
inc last
.stillbitsleft
donedepacking
rts
onebyte
ldy #1
sty ecx
iny
lda #0
sta tmpu+1
lda #$10
.getmorebits
pha
jsr getbit
pla
rol
bcc .getmorebits
bne domatch
jsr putdst
linktag
bne nexttag
codepair
jsr getgamma
- jsr dececx
dey
bne -
tay
ora ecx+1
beq +
normalcodepair
dey
sty last+1
jsr getsrc
tax
!byte $a9
+ iny
jsr getgamma
cpy #$7d
bcs domatch_with_2inc
cpy #5
bcs domatch_with_inc
txa
bmi domatch_new_lastpos
tya
bne domatch_new_lastpos
domatch_with_2inc
inc ecx
bne domatch_with_inc
inc ecx+1
domatch_with_inc
inc ecx
bne domatch_new_lastpos
inc ecx+1
domatch_new_lastpos
domatch_lastpos
ldy #1
lda last+1
sta tmpu+1
txa
domatch
sta tmpu
lda src+1
pha
lda src
pha
lda dst
sec
sbc tmpu
sta src
lda dst+1
sbc tmpu+1
sta src+1
- jsr getput
jsr dececx
ora ecx+1
bne -
pla
sta src
pla
sta src+1
bne linktag
getgamma
lda #1
sta ecx
sta ecx+1
dec ecx+1
.getgammaloop
jsr getbit
rol ecx
rol ecx+1
jsr getbit
bcs .getgammaloop
rts
dececx
lda ecx
bne +
dec ecx+1
+ dec ecx
lda ecx
rts
getput
jsr getsrc
putdst
sty tmpu
ldy #0
sta (dst), y
ldy tmpu
inc dst
bne +
inc dst+1
+ rts
getsrc
sty tmpu
ldy #0
lda (src), y
ldy tmpu
inc src
bne +
inc src+1
+ rts
}