2016-12-09 16:36:24 +00:00
|
|
|
|
PR#3
|
2017-03-29 15:48:15 +00:00
|
|
|
|
PREFIX /A2OSX.BUILD
|
2016-12-09 16:36:24 +00:00
|
|
|
|
NEW
|
|
|
|
|
INC 1
|
|
|
|
|
AUTO 6
|
|
|
|
|
.LIST OFF
|
|
|
|
|
.OP 65C02
|
|
|
|
|
.OR $2000
|
2017-03-29 15:48:15 +00:00
|
|
|
|
.TF /A2OSX.BUILD/LIB/LIBPAK.O
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* File Header :
|
|
|
|
|
* SFX :
|
|
|
|
|
* - BIN must begin with CLD (QCODE)
|
|
|
|
|
* - BIN must be relocatable
|
|
|
|
|
* - BIN must overwrite itself
|
|
|
|
|
* (well, best way is moving CODE to $200)
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Shunk Header :
|
|
|
|
|
* WORD : !Target Length
|
|
|
|
|
* USED TO STOP UNPACK
|
|
|
|
|
* !!!NO EOF TOKEN!!!
|
|
|
|
|
* Short4 : [0..15]
|
|
|
|
|
* Short3 : [0..7]
|
|
|
|
|
*--------------------------------------
|
2017-03-29 15:48:15 +00:00
|
|
|
|
S.PAKHDR.LEN .EQ 0
|
|
|
|
|
S.PAKHDR.SHORT4 .EQ 2
|
|
|
|
|
S.PAKHDR.SHORT3 .EQ 18
|
|
|
|
|
*
|
|
|
|
|
S.PAKHDR .EQ 26
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
S.PAKSTAT.BL .EQ 0
|
|
|
|
|
S.PAKSTAT.REP .EQ 2
|
|
|
|
|
S.PAKSTAT.S3 .EQ 4
|
|
|
|
|
S.PAKSTAT.S4 .EQ 6
|
|
|
|
|
S.PAKSTAT.STORE .EQ 8
|
|
|
|
|
*
|
|
|
|
|
S.PAKSTAT .EQ 10
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
PIPELEN .EQ 18
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* BITSTREAM :
|
2017-03-29 15:48:15 +00:00
|
|
|
|
* 0 = STORE : 1 byte follow (9 bits)
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------
|
|
|
|
|
* 1 = CMD :
|
|
|
|
|
*---SHORT4 --- (3)+4=7 bits --------
|
|
|
|
|
* 100 : SHORT4
|
|
|
|
|
* xxxx = index in Short4 Table
|
|
|
|
|
*---SHORT3 --- (3)+3=6 bits --------
|
|
|
|
|
* 101 : SHORT3
|
|
|
|
|
* xxx = index in Short3 Table
|
2017-03-29 15:48:15 +00:00
|
|
|
|
*--- BACKLINK : (3)+9+4=16 bits ----
|
2016-12-09 16:36:24 +00:00
|
|
|
|
* 110 : BackLink
|
|
|
|
|
* 9 bits : Offset (LO8,HI1)
|
|
|
|
|
* 4 bits : 3 + n (4 bits count) (18 max)
|
|
|
|
|
*--- REP : (3)+1, (3)+1+4 =4/8 bits ----
|
|
|
|
|
* 111 : REP
|
|
|
|
|
* 0 : repeat last byte
|
|
|
|
|
* 1 : repeat 2 + n (4 bits count)
|
2017-03-29 15:48:15 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
.INB /A2OSX.BUILD/INC/MACROS.I
|
|
|
|
|
.INB /A2OSX.BUILD/INC/A2OSX.I
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
Pak.SrcPtr .EQ ZPLIB
|
|
|
|
|
Pak.SrcBlPtr .EQ ZPLIB+2
|
|
|
|
|
Pak.SrcBlPtrT .EQ ZPLIB+4
|
|
|
|
|
Pak.DstPtr .EQ ZPLIB+6
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* File Header (16 Bytes)
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
CS.START cld
|
|
|
|
|
jmp (.1,x)
|
|
|
|
|
.DA #$61 6502,Level 1 (65c02)
|
|
|
|
|
.DA #1 BIN Layout Version 1
|
|
|
|
|
.DA 0
|
|
|
|
|
.DA CS.END-CS.START
|
|
|
|
|
.DA 0
|
|
|
|
|
.DA 0
|
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Relocation Table
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.1 .DA LIB.LOAD
|
|
|
|
|
.DA LIB.UNLOAD
|
|
|
|
|
.DA Pak
|
|
|
|
|
.DA Unpak
|
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
LIB.LOAD
|
|
|
|
|
LIB.UNLOAD clc
|
|
|
|
|
rts
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* In :
|
|
|
|
|
* PULLW = Src PTR
|
|
|
|
|
* PULLW = Src LEN
|
|
|
|
|
* PULLW = Dst PTR Compressed Buffer
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak >PULLYA
|
|
|
|
|
>STYA Pak.Src Init for pass #1
|
|
|
|
|
>STYA Pak.SrcPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
>PULLA Get Src Len LO
|
|
|
|
|
eor #$ff
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta Pak.SrcCnt
|
|
|
|
|
sta Pak.Cnt Init for pass #1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
tax
|
|
|
|
|
|
|
|
|
|
>PULLA Get Src Len HI
|
|
|
|
|
eor #$ff
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta Pak.SrcCnt+1
|
|
|
|
|
sta Pak.Cnt+1 Init for pass #1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
tay
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
>PULLW Pak.DstPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
txa
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
tya
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
ldx #S.PAKSTAT-1
|
|
|
|
|
.1 stz PakStat,x Reset Stats
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dex
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
* PASS #1 : Count occurence for each value...
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.1 ldx #0
|
|
|
|
|
.1 stz Pak.CntL,x
|
|
|
|
|
stz Pak.CntH,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
inx
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.2 inc Pak.Cnt
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .3
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc Pak.Cnt+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
beq .5
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.3 lda (Pak.SrcPtr),y
|
2016-12-09 16:36:24 +00:00
|
|
|
|
tax
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc Pak.CntL,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .4
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc Pak.CntH,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
.4 iny
|
|
|
|
|
bne .2
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc Pak.SrcPtr+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bra .2
|
|
|
|
|
|
|
|
|
|
* ...Search for Top 24
|
|
|
|
|
.5 ldy #23
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.6 stz Pak.Cnt Init best score to 0
|
|
|
|
|
stz Pak.Cnt+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
stz Pak.Byte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ldx #0
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.7 lda Pak.CntL,x is it better at X
|
|
|
|
|
cmp Pak.Cnt
|
|
|
|
|
lda Pak.CntH,x
|
|
|
|
|
sbc Pak.Cnt+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcs .8 not better
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
stx Pak.Byte
|
|
|
|
|
lda Pak.CntL,x
|
|
|
|
|
sta Pak.Cnt
|
|
|
|
|
lda Pak.CntH,x
|
|
|
|
|
sta Pak.Cnt+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
.8 inx
|
|
|
|
|
bne .7
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda Pak.Byte
|
2017-03-29 15:48:15 +00:00
|
|
|
|
sta PakHdr+S.PAKHDR.SHORT4,y
|
2017-03-29 06:33:26 +00:00
|
|
|
|
stz Pak.CntL,x Discard this entry
|
|
|
|
|
stz Pak.CntH,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dey
|
|
|
|
|
bpl .6
|
|
|
|
|
|
|
|
|
|
ldx #15
|
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
.9 lda PakHdr+S.PAKHDR.SHORT4,x Store SHORT4 in reverse order
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dex
|
|
|
|
|
bpl .9
|
|
|
|
|
|
|
|
|
|
ldx #7
|
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
.10 lda PakHdr+S.PAKHDR.SHORT3,x Store SHORT3 in reverse order
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dex
|
|
|
|
|
bpl .10
|
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
>LDYAI S.PAKHDR Total Header Size
|
|
|
|
|
>STYA PakHdr+S.PAKHDR.LEN
|
2016-12-09 16:36:24 +00:00
|
|
|
|
* PASS #2 :
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.2 >LDYA Pak.Src Init for pass #2
|
|
|
|
|
>STYA Pak.SrcPtr
|
|
|
|
|
>STYA Pak.SrcBlPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
>LDYA Pak.SrcCnt
|
|
|
|
|
>STYA Pak.Cnt
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
lda #8
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta Pak.PutBit+1 Initialize properly for first "PutBit" Call
|
|
|
|
|
stz Pak.Byte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
stz Pak.PipeLen
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.2.LOOP ldx Pak.PipeLen Always fill Bytes in the PIPE until full
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.1 jsr Pak.GetByte Load PIPE....
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcs .2 end of Buffer ?
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta Pak.Pipe,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
inx
|
|
|
|
|
cpx #PIPELEN PIPE Full ?
|
|
|
|
|
bne .1
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.2 stx Pak.PipeLen
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
txa
|
|
|
|
|
beq Pak.2.EXIT PIPE empty ....exit
|
|
|
|
|
dex
|
|
|
|
|
bne Pak.2.REP more than one char in PIPE...REP?
|
|
|
|
|
|
|
|
|
|
jmp Pak.2.Store only one....store it
|
|
|
|
|
|
|
|
|
|
Pak.2.EXIT clc
|
|
|
|
|
rts
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
* try finding REPeating same bytes.....
|
2017-03-29 15:48:15 +00:00
|
|
|
|
Pak.2.REP ldx #0
|
|
|
|
|
lda Pak.Pipe
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
.1 cmp Pak.Pipe+1,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .2
|
|
|
|
|
inx
|
2017-03-29 06:33:26 +00:00
|
|
|
|
cpx Pak.PipeLen
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
.2 dex if one char.....no REP
|
2017-03-29 06:33:26 +00:00
|
|
|
|
beq Pak.2.BL
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dex if 2, -> REP ONE (not 2)
|
|
|
|
|
phx REP 1 + 0 or more....save REP count for later....
|
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
jsr Pak.PutA a = byte to store
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
lda #%11100000
|
|
|
|
|
plx
|
|
|
|
|
phx
|
|
|
|
|
beq .3
|
2017-03-29 15:48:15 +00:00
|
|
|
|
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ora #%00010000
|
2017-03-29 15:48:15 +00:00
|
|
|
|
|
|
|
|
|
.3 ldy #4
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutYBits
|
2016-12-09 16:36:24 +00:00
|
|
|
|
txa
|
|
|
|
|
beq .4 if not REP 2 or more no extra count
|
|
|
|
|
ldy #4
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutYBits
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
.4 pla
|
|
|
|
|
clc
|
|
|
|
|
adc #2
|
|
|
|
|
tay
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.StripPipe Remove REP bytes from PIPE
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
ldx #S.PAKSTAT.REP
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.UpdateStats
|
|
|
|
|
jmp Pak.2.LOOP
|
|
|
|
|
Pak.2.BL
|
2016-12-09 16:36:24 +00:00
|
|
|
|
* Try finding best matching BackLink between SrcBlPtr and SrcPtr (max 512)
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.4 lda Pak.SrcPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
sec
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sbc Pak.PipeLen
|
|
|
|
|
sta Pak.Limit setup Limit to SrcPtr-PIPE
|
|
|
|
|
lda Pak.SrcPtr+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
sbc #0
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta Pak.Limit+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.40 lda Pak.SrcBlPtr
|
|
|
|
|
sta Pak.SrcBlPtrT
|
|
|
|
|
lda Pak.SrcBlPtr+1
|
|
|
|
|
sta Pak.SrcBlPtrT+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
.5 txa Get PIPE Len
|
|
|
|
|
|
|
|
|
|
clc make sure SrcBlPtrT+PIPE < Limit
|
2017-03-29 06:33:26 +00:00
|
|
|
|
adc Pak.SrcBlPtrT
|
2016-12-09 16:36:24 +00:00
|
|
|
|
tay
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda Pak.SrcBlPtrT+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
adc #0
|
2017-03-29 06:33:26 +00:00
|
|
|
|
cpy Pak.Limit
|
|
|
|
|
sbc Pak.Limit+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcc .10 not enough room
|
|
|
|
|
|
|
|
|
|
txa
|
|
|
|
|
dec
|
|
|
|
|
tay
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.8 lda (Pak.SrcBlPtrT),y
|
|
|
|
|
cmp Pak.Pipe,y
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .9
|
|
|
|
|
dey
|
|
|
|
|
bpl .8
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
* Found a BL at Pak.SrcBlPtrT, Store it and remove X bytes from PIPE
|
2016-12-09 16:36:24 +00:00
|
|
|
|
phx save BL length
|
|
|
|
|
|
|
|
|
|
lda #%1100000
|
|
|
|
|
ldy #3
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutYBits
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda Pak.Limit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
sec
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sbc Pak.SrcBlPtrT
|
2016-12-09 16:36:24 +00:00
|
|
|
|
php save C
|
|
|
|
|
|
|
|
|
|
ldy #8
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutYBits
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
plp
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda Pak.Limit+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
sec
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sbc Pak.SrcBlPtrT+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
ply Get back BL len
|
|
|
|
|
phy
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.StripPipe Remove LEN bytes from PIPE
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
pla Get back BL len
|
|
|
|
|
sec
|
|
|
|
|
sbc #3 Adjust Range..3-18 to 0->15
|
|
|
|
|
asl
|
|
|
|
|
asl
|
|
|
|
|
asl
|
|
|
|
|
asl
|
|
|
|
|
ldy #4 store 4 bits len
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.PutYBits
|
2017-03-29 15:48:15 +00:00
|
|
|
|
ldx #S.PAKSTAT.BL
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.UpdateStats
|
|
|
|
|
jmp Pak.2.LOOP
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
* No match...try starting at next byte
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.9 inc Pak.SrcBlPtrT
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .5
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc Pak.SrcBlPtrT+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bra .5
|
|
|
|
|
.10 dex reduce PIPE
|
|
|
|
|
cpx #2 2 bytes remaining? no need to BL, a BL is 16bits wide.....
|
|
|
|
|
bne .40 and start over from BLPtr
|
|
|
|
|
|
|
|
|
|
* NO Bl Found, STORE
|
2017-03-29 15:48:15 +00:00
|
|
|
|
Pak.2.Store lda Pak.Pipe
|
|
|
|
|
ldx #23
|
|
|
|
|
|
|
|
|
|
.1 cmp PakHdr+S.PAKHDR.SHORT4,x
|
|
|
|
|
beq .2
|
|
|
|
|
dex
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
|
ldy #1
|
|
|
|
|
jsr Pak.PutYBits write 0
|
|
|
|
|
|
|
|
|
|
lda Pak.Pipe ...and byte
|
|
|
|
|
jsr Pak.PutA
|
|
|
|
|
|
|
|
|
|
ldy #1
|
|
|
|
|
jsr Pak.StripPipe
|
|
|
|
|
jmp Pak.2.LOOP
|
|
|
|
|
|
|
|
|
|
.2 cpx #16 16-23 -> SHORT3
|
|
|
|
|
bcs .3
|
|
|
|
|
|
|
|
|
|
txa 0-15, SHORT4
|
|
|
|
|
asl move to BIT 000xxxx0
|
|
|
|
|
|
|
|
|
|
ora #10000000 SHORT4
|
|
|
|
|
ldy #7
|
|
|
|
|
bra .8
|
|
|
|
|
|
|
|
|
|
.3 txa
|
|
|
|
|
and #7 make it xxx
|
|
|
|
|
asl
|
|
|
|
|
asl and 000xxx00
|
|
|
|
|
ora #10100000 SHORT3
|
|
|
|
|
ldy #6
|
|
|
|
|
|
|
|
|
|
.8 jsr Pak.PutYBits write 100xxxx
|
|
|
|
|
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ldy #1
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr Pak.StripPipe
|
|
|
|
|
jmp Pak.2.LOOP
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
2017-03-29 15:48:15 +00:00
|
|
|
|
Pak.PutA ldy #8
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.PutYBits asl
|
|
|
|
|
jsr Pak.PutBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dey
|
2017-03-29 06:33:26 +00:00
|
|
|
|
bne Pak.PutYBits
|
2016-12-09 16:36:24 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
* Pak.PutBit (bit in C)
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.PutBit ldx #$ff
|
2016-12-09 16:36:24 +00:00
|
|
|
|
pha
|
|
|
|
|
bne .1
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda Pak.Byte
|
|
|
|
|
jsr Pak.PutByte
|
|
|
|
|
stz Pak.Byte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ldx #8
|
|
|
|
|
|
|
|
|
|
.1 dex
|
2017-03-29 06:33:26 +00:00
|
|
|
|
stx Pak.PutBit+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcc .8 Nothing to "light up"
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda Pak.Byte
|
|
|
|
|
lda Pak.BitMask,x
|
|
|
|
|
sta Pak.Byte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
.8 pla
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.PutByte sta (Pak.DstPtr)
|
|
|
|
|
inc Pak.DstPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .1
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc Pak.DstPtr+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 15:48:15 +00:00
|
|
|
|
.1 inc PakHdr+S.PAKHDR.LEN
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .2
|
2017-03-29 15:48:15 +00:00
|
|
|
|
inc PakHdr+S.PAKHDR.LEN+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
.2
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Y = count to remove from PIPE
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
Pak.StripPipe ldx Pak.PipeLen
|
2016-12-09 16:36:24 +00:00
|
|
|
|
beq .9
|
|
|
|
|
|
|
|
|
|
ldx #0
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.1 lda Pak.Pipe+1,x
|
|
|
|
|
sta Pak.Pipe,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
inx
|
2017-03-29 06:33:26 +00:00
|
|
|
|
cpx Pak.PipeLen
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .1
|
2017-03-29 06:33:26 +00:00
|
|
|
|
dec Pak.PipeLen
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dey
|
2017-03-29 06:33:26 +00:00
|
|
|
|
bne Pak.StripPipe
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
.9 rts
|
|
|
|
|
*--------------------------------------
|
2017-03-29 15:48:15 +00:00
|
|
|
|
Pak.UpdateStats inc PakStat,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .8
|
2017-03-29 15:48:15 +00:00
|
|
|
|
inc PakStat+1,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
.8 rts
|
|
|
|
|
*--------------------------------------
|
2017-03-29 15:48:15 +00:00
|
|
|
|
Pak.GetByte inc UnPak.Cnt
|
|
|
|
|
bne .1
|
|
|
|
|
inc UnPak.Cnt+1
|
|
|
|
|
beq .9
|
|
|
|
|
|
|
|
|
|
.1 lda (Pak.SrcPtr)
|
|
|
|
|
|
|
|
|
|
inc Pak.SrcPtr
|
|
|
|
|
bne .2
|
|
|
|
|
inc Pak.SrcPtr+1
|
|
|
|
|
|
|
|
|
|
.2 clc
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.9 sec
|
|
|
|
|
rts
|
2017-03-29 06:33:26 +00:00
|
|
|
|
*--------------------------------------
|
2017-03-29 15:48:15 +00:00
|
|
|
|
* UNPACK code as short as possible
|
|
|
|
|
* For Self Extract
|
2017-03-29 06:33:26 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* UnPak
|
2016-12-09 16:36:24 +00:00
|
|
|
|
* In :
|
|
|
|
|
* PULLW = Src PTR Compressed Buffer
|
|
|
|
|
* PULLW = Dst PTR
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.SrcPtr .EQ ZPLIB
|
|
|
|
|
UnPak.DstPtr .EQ ZPLIB+2
|
|
|
|
|
UnPak.ShrtTbl .EQ ZPLIB+4
|
|
|
|
|
UnPak.Cnt .EQ ZPLIB+6
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak >PULLW UnPak.SrcPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
>PULLA Get Dst PTR LO
|
|
|
|
|
sec
|
|
|
|
|
sbc #1
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta UnPak.DstPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
>PULLA Get Dst PTR HI
|
|
|
|
|
sbc #0
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta UnPak.DstPtr+1 setup Dst PTR-1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.GetByte Get !LEN for counting up to $0000
|
|
|
|
|
sta UnPak.Cnt
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.GetByte
|
|
|
|
|
sta UnPak.Cnt+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
>LDYA UnPak.SrcPtr Get PTR to Short Table.....
|
|
|
|
|
>STYA UnPak.ShrtTbl and save it for SHORTx
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
lda #8
|
2017-03-29 06:33:26 +00:00
|
|
|
|
sta UnPak.GetBit+1 Initialize properly for first "GetBit" Call
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.1 inc UnPak.Cnt
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .2
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc UnPak.Cnt+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
beq .99
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.2 jsr UnPak.GetBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcs .4 CMD....
|
|
|
|
|
*---- STORE
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.GetBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ldx #1
|
|
|
|
|
bcc .3 if CC one byte
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.Get4Bits CC
|
2016-12-09 16:36:24 +00:00
|
|
|
|
adc #2 range is 2->17
|
|
|
|
|
tax
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.3 jsr UnPak.Get8Bits
|
|
|
|
|
jsr UnPak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dex
|
|
|
|
|
bne .3
|
|
|
|
|
bra .1
|
|
|
|
|
.99 rts
|
|
|
|
|
*---- CMD
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.4 jsr UnPak.GetBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcs .6 BACKLINK or REP...
|
|
|
|
|
*---- CMD : SHORT
|
|
|
|
|
lda #0
|
|
|
|
|
ldy #4
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.GetBit if CS short3
|
2016-12-09 16:36:24 +00:00
|
|
|
|
rol make offset 00000001
|
|
|
|
|
asl ....00000010
|
|
|
|
|
beq .5
|
|
|
|
|
|
|
|
|
|
dey if short3, only 3 bits
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.5 jsr UnPak.GetBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
rol
|
|
|
|
|
dey
|
|
|
|
|
bne .5
|
|
|
|
|
|
|
|
|
|
tay if s3, offset is 00010xxx
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda (UnPak.ShrtTbl),y if s4, offset is 0000xxxx
|
|
|
|
|
jsr UnPak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bra .1
|
|
|
|
|
*---- CMD : BACKLINK or REP
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.6 jsr UnPak.GetBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcs .8 if CS -> REP
|
|
|
|
|
*---- CMD : BACKLINK
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.Get8Bits get Offset LO, (CC)
|
2016-12-09 16:36:24 +00:00
|
|
|
|
eor #$ff !offset LO
|
2017-03-29 06:33:26 +00:00
|
|
|
|
adc UnPak.DstPtr equiv. SUB offset
|
2016-12-09 16:36:24 +00:00
|
|
|
|
sta .7+1 PTR to Backlink LO
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda UnPak.DstPtr+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcs .61 if ADC sets C, no need to dec HI
|
|
|
|
|
dec
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.61 jsr UnPak.GetBit get Offset HI in C
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bcc .62
|
|
|
|
|
dec
|
|
|
|
|
.62 sta .7+2 PTR to Backlink HI
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.Get4Bits CC
|
2016-12-09 16:36:24 +00:00
|
|
|
|
adc #3 Backlink are ate least 3 bytes...
|
|
|
|
|
tax
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.7 lda $ffff,y Self Modified code : PTR to Backlink
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
iny
|
|
|
|
|
dex
|
|
|
|
|
bne .7
|
|
|
|
|
beq .1
|
|
|
|
|
*---- CMD : REP
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.8 jsr UnPak.GetBit
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ldx #1
|
|
|
|
|
bcc .9 REP 1
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.Get4Bits REP xxxx, CC
|
2016-12-09 16:36:24 +00:00
|
|
|
|
adc #2 range is 2->17
|
|
|
|
|
tax
|
|
|
|
|
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.9 lda (UnPak.DstPtr) Get Last Byte
|
|
|
|
|
jsr UnPak.PutByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
dex
|
|
|
|
|
bne .9
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jmp .1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.Get8Bits ldy #8
|
2016-12-09 16:36:24 +00:00
|
|
|
|
.HS 2C bit abs
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.Get4Bits ldy #4
|
2016-12-09 16:36:24 +00:00
|
|
|
|
lda #0 make sure to reset A before reading less than 8 bits only
|
2017-03-29 06:33:26 +00:00
|
|
|
|
.1 jsr UnPak.GetBit and to exit with CC if even if 8 bits read
|
2016-12-09 16:36:24 +00:00
|
|
|
|
rol
|
|
|
|
|
dey
|
|
|
|
|
bne .1
|
|
|
|
|
rts always CC
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.GetBit ldx #$ff Self Modified code
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .1
|
2017-03-29 06:33:26 +00:00
|
|
|
|
jsr UnPak.NxtByte
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
ldx #8
|
|
|
|
|
|
|
|
|
|
.1 dex
|
2017-03-29 06:33:26 +00:00
|
|
|
|
stx UnPak.GetBit+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
|
|
|
|
|
pha Don't trash A
|
2017-03-29 06:33:26 +00:00
|
|
|
|
lda (UnPak.SrcPtr)
|
|
|
|
|
and UnPak.BitMask,x
|
2016-12-09 16:36:24 +00:00
|
|
|
|
cmp #1 if 0:CC, i>0 CS
|
|
|
|
|
|
|
|
|
|
pla
|
|
|
|
|
rts Bit is in C
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.GetByte lda (UnPak.SrcPtr)
|
|
|
|
|
UnPak.NxtByte inc UnPak.SrcPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .8
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc UnPak.SrcPtr+1
|
2016-12-09 16:36:24 +00:00
|
|
|
|
.8 rts
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.PutByte inc UnPak.DstPtr
|
2016-12-09 16:36:24 +00:00
|
|
|
|
bne .8
|
2017-03-29 06:33:26 +00:00
|
|
|
|
inc UnPak.DstPtr+1
|
|
|
|
|
.8 sta (UnPak.DstPtr)
|
2016-12-09 16:36:24 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-03-29 15:48:15 +00:00
|
|
|
|
CS.END
|
|
|
|
|
Pak.Src .BS 2
|
|
|
|
|
Pak.SrcCnt .BS 2
|
|
|
|
|
Pak.Cnt .BS 2
|
|
|
|
|
Pak.CntL .BS 256
|
|
|
|
|
Pak.CntH .BS 256
|
|
|
|
|
Pak.Byte .BS 1
|
|
|
|
|
Pak.Limit .BS 2
|
|
|
|
|
Pak.PipeLen .BS 1
|
|
|
|
|
Pak.Pipe .BS 18
|
|
|
|
|
Pak.BitMask .HS 0102040810204080
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
PakHdr .BS S.PAKHDR
|
|
|
|
|
PakStat .BS S.PAKSTAT
|
|
|
|
|
*--------------------------------------
|
2017-03-29 06:33:26 +00:00
|
|
|
|
UnPak.BitMask .HS 8040201008040201
|
2016-12-09 16:36:24 +00:00
|
|
|
|
MAN
|
2017-03-30 06:31:12 +00:00
|
|
|
|
SAVE /A2OSX.SRC/LIB/LIBPAK.S
|
2016-12-09 16:36:24 +00:00
|
|
|
|
ASM
|