Kernel 0.9.1 : LIBPAK rewrite...

This commit is contained in:
Rémy GIBERT 2018-02-09 16:02:47 +00:00
parent b740939760
commit ff0efac421
4 changed files with 312 additions and 96 deletions

Binary file not shown.

Binary file not shown.

View File

@ -23,19 +23,15 @@ AUTO 4,1
*-------------------------------------- *--------------------------------------
* 1111 : STOREn (4) + 4 cnt + 8n.... * 1111 : STOREn (4) + 4 cnt + 8n....
*-------------------------------------- *--------------------------------------
PAK.L.SHORT3 .EQ 1 PAK.B.SHORT3 .EQ %00000000 0xxx0000
PAK.B.SHORT3 .EQ %00000000 PAK.B.SHORT4 .EQ %10000000 10xxxx00
PAK.L.SHORT4 .EQ 2 PAK.B.REPn .EQ %11000000 110xxxxx
PAK.B.SHORT4 .EQ %10000000 PAK.B.BACKLINK .EQ %11100000 1110hhhhllllllllxxxxxxxx
PAK.L.REPn .EQ 3 PAK.B.STOREn .EQ %11110000 1111xxxx ...
PAK.B.REPn .EQ %11000000
PAK.L.BACKLINK .EQ 4
PAK.B.BACKLINK .EQ %11100000
PAK.L.STOREn .EQ 4
PAK.B.STOREn .EQ %11110000
*-------------------------------------- *--------------------------------------
WSIZE .EQ 4096 WSIZE .EQ 4096
REPMAX .EQ 32 REPMAX .EQ 32
STOREMAX .EQ 16
*-------------------------------------- *--------------------------------------
.INB /A2OSX.BUILD/INC/MACROS.I .INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I .INB /A2OSX.BUILD/INC/A2OSX.I
@ -90,59 +86,65 @@ Pak >PULLW ZPStatPtr
sta ZPHdrPtr sta ZPHdrPtr
clc clc
adc #S.PAKHDR adc #S.PAKHDR
sta Pak.DstPtr sta ZPDstPtr
>PULLA >PULLA
sta ZPHdrPtr+1 sta ZPHdrPtr+1
adc /S.PAKHDR adc /S.PAKHDR
sta Pak.DstPtr+1 sta ZPDstPtr+1
>PULLW Pak.Hdr+S.PAKHDR.LEN >PULLW Pak.Hdr+S.PAKHDR.LEN
>PULLW Pak.SrcPtr >PULLW Pak.SrcPtr
* Reset Byte counters
ldx #0
.1 stz Pak.CntL,x
stz Pak.CntH,x
inx
bne .1
* PASS #1 : REP & BL, raw store * PASS #1 : REP & BL, no store, update byte counters
jsr Pak.InitPass jsr Pak.InitPass
stz Pak.StoreMode stz Pak.bPass2
jsr Pak.Run jsr Pak.Run
bcs .9 bcs .9
>LDYA Pak.Stat+S.PAKSTAT.PASS2
>STYA Pak.Stat+S.PAKSTAT.PASS1
* PASS #2a : Count occurence for each value...
jsr Pak.BuildShortTable jsr Pak.BuildShortTable
* PASS #2b : REP & BL, true store with S3,S4 * PASS #2 : REP & BL, store with S3,S4
jsr Pak.InitPass jsr Pak.InitPass
dec Pak.StoreMode dec Pak.bPass2
lda #8 lda #$80
sta Pak.PutBit+1 Initialize properly for sta Pak.Mask Initialize properly for
stz Pak.Byte first "PutBit" Call stz Pak.Byte first "PutBit" Call
stz Pak.StoreCnt
jsr Pak.Run jsr Pak.Run
bcs .9 bcs .9
ldy #S.PAKHDR-1 ldy #S.PAKHDR-1
.1 lda Pak.Hdr,y .2 lda Pak.Hdr,y
sta (ZPHdrPtr),y sta (ZPHdrPtr),y
dey dey
bpl .1 bpl .2
ldy #S.PAKSTAT-1 ldy #S.PAKSTAT-1
.2 lda Pak.Stat,y .3 lda Pak.Stat,y
sta (ZPStatPtr),y sta (ZPStatPtr),y
dey dey
bpl .2 bpl .3
clc clc
rts rts
@ -155,9 +157,6 @@ Pak.InitPass >LDYA Pak.SrcPtr
>STYA ZPSrcPtr >STYA ZPSrcPtr
>STYA Pak.WPtr >STYA Pak.WPtr
>LDYA Pak.DstPtr
>STYA ZPDstPtr
lda Pak.Hdr+S.PAKHDR.LEN lda Pak.Hdr+S.PAKHDR.LEN
eor #$ff eor #$ff
sta Pak.SrcCnt sta Pak.SrcCnt
@ -237,7 +236,13 @@ Pak.Run lda #$ff
bra Pak.Run bra Pak.Run
.8 clc .8 lda Pak.RepCnt do we have a pending REP ?
beq .80
ora #PAK.B.REPn yes, add it
jmp Pak.PutA.1
.80 clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
Pak.SrcForward pha Len Pak.SrcForward pha Len
@ -337,43 +342,8 @@ Pak.ScanBL stx Pak.WStrLen
rts rts
*-------------------------------------- *--------------------------------------
Pak.BuildShortTable Pak.BuildShortTable
ldx #0
.1 stz Pak.CntL,x
stz Pak.CntH,x
inx
bne .1
lda Pak.Stat+S.PAKSTAT.PASS1
eor #$ff
sta Pak.Cnt
lda Pak.Stat+S.PAKSTAT.PASS1+1
eor #$ff
sta Pak.Cnt+1
>LDYA Pak.SrcPtr
>STYA .3+1
ldy #0 ldy #0
.2 inc Pak.Cnt
bne .3
inc Pak.Cnt+1
beq .5
.3 ldx $FFFF,y SELF MODIFIED
inc Pak.CntL,x
bne .4
inc Pak.CntH,x
.4 iny
bne .2
inc .3+2
bra .2
* ...Search for Top 24
.5 ldy #0
.6 stz Pak.Cnt Init best score to 0 .6 stz Pak.Cnt Init best score to 0
stz Pak.Cnt+1 stz Pak.Cnt+1
@ -383,7 +353,7 @@ Pak.BuildShortTable
cmp Pak.CntL,x is it better at X cmp Pak.CntL,x is it better at X
lda Pak.Cnt+1 lda Pak.Cnt+1
sbc Pak.CntH,x sbc Pak.CntH,x
bcc .8 not better or equal... bcs .8 not better or equal...
stx Pak.Byte save new score index... stx Pak.Byte save new score index...
@ -450,12 +420,21 @@ Pak.PutA bit Pak.RepCnt
.8 clc .8 clc
.9 rts .9 rts
Pak.PutA.1 bit Pak.StoreMode Pak.PutA.1 bit Pak.bPass2
bmi .10 bmi .10
ldx #S.PAKSTAT.STORE tax
jsr Pak.UpdateStats inc Pak.CntL,x
bra Pak.PutByte bne .11
inc Pak.CntH,x
.11 inc Pak.Stat+S.PAKSTAT.PASS1
bne .12
inc Pak.Stat+S.PAKSTAT.PASS1+1
.12 clc
rts
* Pak.PutA.1 PASS #2
.10 ldy #7 .10 ldy #7
@ -491,8 +470,15 @@ Pak.PutA.1 bit Pak.StoreMode
ldx #S.PAKSTAT.S4 ldx #S.PAKSTAT.S4
bra .8 bra .8
.7 ldy #8 .7 ldx Pak.StoreCnt
ldx #S.PAKSTAT.STORE sta Pak.StoreBuf,x
inx
cpx #STOREMAX
beq Pak.Flush
stx Pak.StoreCnt
clc
rts
.8 jsr Pak.UpdateStats .8 jsr Pak.UpdateStats
*-------------------------------------- *--------------------------------------
Pak.PutYBits asl Pak.PutYBits asl
@ -502,37 +488,56 @@ Pak.PutYBits asl
bne Pak.PutYBits bne Pak.PutYBits
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
Pak.Flush ldx Pak.StoreCnt
beq .8
lda #PAK.B.STOREn
ldy #4
jsr Pak.PutYBits
bcs .9
ldx #0
.1 lda Pak.StoreBuf,x
ldy #4
jsr Pak.PutYBits
bcs .9
inx
dec Pak.StoreCnt
bne .1
ldx #S.PAKSTAT.STORE
jsr Pak.UpdateStats
.8 clc
.9 rts
*--------------------------------------
* Pak.PutBit (bit in C) * Pak.PutBit (bit in C)
*-------------------------------------- *--------------------------------------
Pak.PutBit ldx #$ff SELF MODIFIED Pak.PutBit pha
pha bcc .1
bne .1 lda Pak.Mask
tsb Pak.Byte
clc
lda Pak.Byte .1 lsr Pak.Mask
php bne .8
jsr Pak.PutByte jsr Pak.PutByte
bcs .9 bcs .9
plp
stz Pak.Byte stz Pak.Byte
ldx #8 lda #$80
.1 dex sta Pak.Mask
stx Pak.PutBit+1
bcc .8 Nothing to "light up"
lda Pak.BitMask,x
tsb Pak.Byte
clc
.8 pla .8 pla
* clc
rts rts
.9 plp .9 pla
pla * sec
sec
rts rts
*-------------------------------------- *--------------------------------------
Pak.PutByte inc Pak.DstCnt Pak.PutByte inc Pak.DstCnt
@ -541,6 +546,7 @@ Pak.PutByte inc Pak.DstCnt
beq .9 beq .9
.1 sta (ZPDstPtr) .1 sta (ZPDstPtr)
inc ZPDstPtr inc ZPDstPtr
bne .2 bne .2
inc ZPDstPtr+1 inc ZPDstPtr+1
@ -720,17 +726,20 @@ UnPak.PutByte inc UnZPDstPtr
CS.END CS.END
Pak.SrcPtr .BS 2 Pak.SrcPtr .BS 2
Pak.SrcCnt .BS 2 Pak.SrcCnt .BS 2
Pak.DstPtr .BS 2
Pak.DstCnt .BS 2 Pak.DstCnt .BS 2
Pak.RepCnt .BS 1 Pak.RepCnt .BS 1
Pak.LastByte .BS 1 Pak.LastByte .BS 1
Pak.StoreCnt .BS 1
Pak.StoreBuf .BS STOREMAX
Pak.Mask .BS 1
Pak.Byte .BS 1 Pak.Byte .BS 1
Pak.Cnt .BS 2 Pak.Cnt .BS 2
Pak.StoreMode .BS 1 Pak.bPass2 .BS 1
Pak.MaxReadAhead .BS 1 Pak.MaxReadAhead .BS 1
Pak.BestBLLen .BS 1 Pak.BestBLLen .BS 1
@ -739,13 +748,11 @@ Pak.WPtr .BS 2
Pak.WLimit .BS 2 Pak.WLimit .BS 2
Pak.WStrLen .BS 1 Pak.WStrLen .BS 1
*-------------------------------------- *--------------------------------------
Pak.StoreBuf .BS 16
Pak.CntL .BS 256 Pak.CntL .BS 256
Pak.CntH .BS 256 Pak.CntH .BS 256
Pak.Hdr .BS S.PAKHDR Pak.Hdr .BS S.PAKHDR
Pak.Stat .BS S.PAKSTAT Pak.Stat .BS S.PAKSTAT
*-------------------------------------- *--------------------------------------
Pak.BitMask .HS 0102040810204080
UnPak.BitMask .HS 8040201008040201 UnPak.BitMask .HS 8040201008040201
MAN MAN
SAVE /A2OSX.SRC/LIB/LIBPAK.S SAVE /A2OSX.SRC/LIB/LIBPAK.S

View File

@ -10,6 +10,17 @@ AUTO 4,1
.INB /A2OSX.BUILD/INC/A2OSX.I .INB /A2OSX.BUILD/INC/A2OSX.I
.INB /A2OSX.BUILD/INC/LIBPAK.I .INB /A2OSX.BUILD/INC/LIBPAK.I
*-------------------------------------- *--------------------------------------
ZPPakHdrPtr .EQ ZPBIN
ZPPakDataPtr .EQ ZPBIN+2
ZPPakSrcPtr .EQ ZPBIN+4
*--------------------------------------
UNPAK.Mask .EQ ZPBIN+8
UNPAK.LastByte .EQ ZPBIN+9
UNPAK.Cnt .EQ ZPBIN+10
UNPAK.Ofs .EQ ZPBIN+12
UNPAK.BLOfs .EQ ZPBIN+14
*--------------------------------------
* File Header (16 Bytes) * File Header (16 Bytes)
*-------------------------------------- *--------------------------------------
CS.START cld CS.START cld
@ -20,7 +31,7 @@ CS.START cld
.DA CS.END-CS.START CS .DA CS.END-CS.START CS
.DA DS.END-DS.START DS .DA DS.END-DS.START DS
.DA #64 SS .DA #64 SS
.DA #0 ZP .DA #16 ZP
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
* Relocation Table * Relocation Table
@ -44,6 +55,8 @@ L.MSG3 .DA MSG3
L.MSG4 .DA MSG4 L.MSG4 .DA MSG4
L.MSG5 .DA MSG5 L.MSG5 .DA MSG5
L.MSG6 .DA MSG6 L.MSG6 .DA MSG6
L.MSG.UnpakErr .DA MSG.UnpakErr
L.MSG.DEBUG.S3 .DA MSG.DEBUG.S3
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
CS.INIT >LDYA L.LIBPAK CS.INIT >LDYA L.LIBPAK
@ -80,7 +93,7 @@ CS.RUN.Pak >PUSHWI 0 Aux type
>LDYA.G PAK.FileSize >LDYA.G PAK.FileSize
>SYSCALL GetMem.YA >SYSCALL GetMem.YA
bcs .9 bcs .9
>STYA ZPPakSrcPtr
txa txa
>STA.G PAK.hOutBuf >STA.G PAK.hOutBuf
@ -92,6 +105,7 @@ CS.RUN.Pak >PUSHWI 0 Aux type
>LDA.G PAK.hOutBuf >LDA.G PAK.hOutBuf
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>STYA ZPPakHdrPtr
>PUSHYA >PUSHYA
>PUSHEA.G PAK.Stat >PUSHEA.G PAK.Stat
@ -110,9 +124,202 @@ CS.RUN.Pak >PUSHWI 0 Aux type
>LDYA L.MSG6 >LDYA L.MSG6
>SYSCALL PrintF.YA >SYSCALL PrintF.YA
*--------------------------------------
CS.RUN.Unpak lda ZPPakHdrPtr
clc
adc #S.PAKSTAT
sta ZPPakDataPtr
lda ZPPakHdrPtr+1
adc /S.PAKSTAT
sta ZPPakDataPtr+1
lda (ZPPakHdrPtr)
eor #$ff
sta UNPAK.Cnt
ldy #1
lda (ZPPakHdrPtr),y
eor #$ff
sta UNPAK.Cnt+1
lda #$80
sta UNPAK.Mask
>LDA.G PAK.hFileBuf
>SYSCALL GetMemPtr.A
>STYA ZPPakSrcPtr
stz UNPAK.Ofs
stz UNPAK.Ofs+1
.1 inc UNPAK.Cnt
bne .2
inc UNPAK.Cnt+1
bne .2
lda #0 lda #0
sec sec
rts
.2 lda #'>'
>SYSCALL PutChar.A
jsr CS.RUN.UnpakGetBitInC
bcs .3
*--------------------------------------
* SHORT3
ldx #3
jsr CS.RUN.UnpakGetXBitInA
clc
adc #S.PAKHDR.SHORT3
tay
lda (ZPPakHdrPtr),y
sta UNPAK.LastByte
jsr DEBUG.S3
jsr CS.RUN.UnpakCmpA
bcs .9
bra .1
.3 jsr CS.RUN.UnpakGetBitInC
bcs .4
*--------------------------------------
* SHORT4
ldx #4
jsr CS.RUN.UnpakGetXBitInA
clc
adc #S.PAKHDR.SHORT4
tay
lda (ZPPakHdrPtr),y
sta UNPAK.LastByte
jsr CS.RUN.UnpakCmpA
bcs .9
bra .1
.4 jsr CS.RUN.UnpakGetBitInC
bcs .5
*--------------------------------------
* REPn
ldx #4
jsr CS.RUN.UnpakGetXBitInA
tay
tax
lda UNPAK.LastByte
.41 jsr CS.RUN.UnpakCmpA
bcs .9
dey
bne .41
.42 txa
clc
adc UNPAK.Cnt
sta UNPAK.Cnt
bcc .2
inc UNPAK.Cnt+1
bra .2
.5 jsr CS.RUN.UnpakGetBitInC
bcs .6
*--------------------------------------
* BACKLINK
ldx #4
jsr CS.RUN.UnpakGetXBitInA
sta UNPAK.BLOfs+1
jsr CS.RUN.UnpakGetByteInA
sta UNPAK.BLOfs
jsr CS.RUN.UnpakGetByteInA
tax
tay
.51
bra .42
*--------------------------------------
* STOREn
.6 ldx #4
jsr CS.RUN.UnpakGetXBitInA
tay
tax
.61 jsr CS.RUN.UnpakGetByteInA
dey
bne .61
sta UNPAK.LastByte
bra .42
.9 >PUSHW UNPAK.Ofs
>LDYA L.MSG.UnpakErr
>SYSCALL PrintF.YA
lda #0
sec
rts
*--------------------------------------
CS.RUN.UnpakGetByteInA
ldx #8
*--------------------------------------
CS.RUN.UnpakGetXBitInA
lda #0
.1 jsr CS.RUN.UnpakGetBitInC
rol
dex
bne .1
rts
*--------------------------------------
CS.RUN.UnpakGetBitInC
pha
clc
lda (ZPPakDataPtr)
and UNPAK.Mask
beq .1
sec
.1 php
lsr UNPAK.Mask
bne .8
lda #$80
sta UNPAK.Mask
inc ZPPakDataPtr
bne .8
inc ZPPakDataPtr+1
.8 plp
pla
rts
*--------------------------------------
CS.RUN.UnpakCmpA
cmp (ZPPakSrcPtr)
bne .9
inc ZPPakSrcPtr
bne .1
inc ZPPakSrcPtr+1
.1 inc UNPAK.Ofs
bne .8
inc UNPAK.Ofs+1
.8 clc
rts
.9 sec
rts
*--------------------------------------
DEBUG.S3 pha
phx
phy
>PUSHA
>LDYA L.MSG.DEBUG.S3
>SYSCALL PrintF.YA
ply
plx
pla
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN.Math >PUSHEA.G ENDPTR CS.RUN.Math >PUSHEA.G ENDPTR
@ -221,6 +428,8 @@ MSG6 .AS "Src Length : %D\r\n"
.AS "S3 Count : %D\r\n" .AS "S3 Count : %D\r\n"
.AS "S4 Count : %D\r\n" .AS "S4 Count : %D\r\n"
.AZ "STO Count : %D\r\n" .AZ "STO Count : %D\r\n"
MSG.UnpakErr .AZ "UnPak Error at Offset : %H\r\n"
MSG.DEBUG.S3 .AZ "S3:%h\r\n"
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
.OR 0 .OR 0