diff --git a/.Floppies/A2OSX.BUILD.po b/.Floppies/A2OSX.BUILD.po index 2b6e14f7..7f4d16ba 100644 Binary files a/.Floppies/A2OSX.BUILD.po and b/.Floppies/A2OSX.BUILD.po differ diff --git a/.Floppies/A2OSX.SRC.po b/.Floppies/A2OSX.SRC.po index 5dc5461a..25329ca9 100644 Binary files a/.Floppies/A2OSX.SRC.po and b/.Floppies/A2OSX.SRC.po differ diff --git a/LIB/LIBPAK.S.txt b/LIB/LIBPAK.S.txt index 5991e2aa..4b592b34 100644 --- a/LIB/LIBPAK.S.txt +++ b/LIB/LIBPAK.S.txt @@ -23,19 +23,15 @@ AUTO 4,1 *-------------------------------------- * 1111 : STOREn (4) + 4 cnt + 8n.... *-------------------------------------- -PAK.L.SHORT3 .EQ 1 -PAK.B.SHORT3 .EQ %00000000 -PAK.L.SHORT4 .EQ 2 -PAK.B.SHORT4 .EQ %10000000 -PAK.L.REPn .EQ 3 -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 +PAK.B.SHORT3 .EQ %00000000 0xxx0000 +PAK.B.SHORT4 .EQ %10000000 10xxxx00 +PAK.B.REPn .EQ %11000000 110xxxxx +PAK.B.BACKLINK .EQ %11100000 1110hhhhllllllllxxxxxxxx +PAK.B.STOREn .EQ %11110000 1111xxxx ... *-------------------------------------- WSIZE .EQ 4096 REPMAX .EQ 32 +STOREMAX .EQ 16 *-------------------------------------- .INB /A2OSX.BUILD/INC/MACROS.I .INB /A2OSX.BUILD/INC/A2OSX.I @@ -90,59 +86,65 @@ Pak >PULLW ZPStatPtr sta ZPHdrPtr clc adc #S.PAKHDR - sta Pak.DstPtr + sta ZPDstPtr >PULLA sta ZPHdrPtr+1 adc /S.PAKHDR - sta Pak.DstPtr+1 + sta ZPDstPtr+1 >PULLW Pak.Hdr+S.PAKHDR.LEN >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 - stz Pak.StoreMode + stz Pak.bPass2 jsr Pak.Run bcs .9 - >LDYA Pak.Stat+S.PAKSTAT.PASS2 - >STYA Pak.Stat+S.PAKSTAT.PASS1 - -* PASS #2a : Count occurence for each value... - jsr Pak.BuildShortTable -* PASS #2b : REP & BL, true store with S3,S4 +* PASS #2 : REP & BL, store with S3,S4 jsr Pak.InitPass - dec Pak.StoreMode + dec Pak.bPass2 - lda #8 - sta Pak.PutBit+1 Initialize properly for + lda #$80 + sta Pak.Mask Initialize properly for stz Pak.Byte first "PutBit" Call + stz Pak.StoreCnt + jsr Pak.Run bcs .9 ldy #S.PAKHDR-1 -.1 lda Pak.Hdr,y +.2 lda Pak.Hdr,y sta (ZPHdrPtr),y dey - bpl .1 + bpl .2 ldy #S.PAKSTAT-1 -.2 lda Pak.Stat,y +.3 lda Pak.Stat,y sta (ZPStatPtr),y dey - bpl .2 + bpl .3 clc rts @@ -155,9 +157,6 @@ Pak.InitPass >LDYA Pak.SrcPtr >STYA ZPSrcPtr >STYA Pak.WPtr - >LDYA Pak.DstPtr - >STYA ZPDstPtr - lda Pak.Hdr+S.PAKHDR.LEN eor #$ff sta Pak.SrcCnt @@ -237,7 +236,13 @@ Pak.Run lda #$ff 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 *-------------------------------------- Pak.SrcForward pha Len @@ -337,43 +342,8 @@ Pak.ScanBL stx Pak.WStrLen rts *-------------------------------------- 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 -.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 stz Pak.Cnt+1 @@ -383,7 +353,7 @@ Pak.BuildShortTable cmp Pak.CntL,x is it better at X lda Pak.Cnt+1 sbc Pak.CntH,x - bcc .8 not better or equal... + bcs .8 not better or equal... stx Pak.Byte save new score index... @@ -450,12 +420,21 @@ Pak.PutA bit Pak.RepCnt .8 clc .9 rts -Pak.PutA.1 bit Pak.StoreMode +Pak.PutA.1 bit Pak.bPass2 bmi .10 - ldx #S.PAKSTAT.STORE - jsr Pak.UpdateStats - bra Pak.PutByte + tax + inc Pak.CntL,x + 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 @@ -491,8 +470,15 @@ Pak.PutA.1 bit Pak.StoreMode ldx #S.PAKSTAT.S4 bra .8 -.7 ldy #8 - ldx #S.PAKSTAT.STORE +.7 ldx Pak.StoreCnt + sta Pak.StoreBuf,x + inx + cpx #STOREMAX + beq Pak.Flush + stx Pak.StoreCnt + clc + rts + .8 jsr Pak.UpdateStats *-------------------------------------- Pak.PutYBits asl @@ -502,37 +488,56 @@ Pak.PutYBits asl bne Pak.PutYBits .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 ldx #$ff SELF MODIFIED +Pak.PutBit pha - pha - bne .1 + bcc .1 + lda Pak.Mask + tsb Pak.Byte + clc - lda Pak.Byte - php +.1 lsr Pak.Mask + bne .8 jsr Pak.PutByte bcs .9 - plp stz Pak.Byte - ldx #8 + lda #$80 -.1 dex - stx Pak.PutBit+1 - bcc .8 Nothing to "light up" - - lda Pak.BitMask,x - tsb Pak.Byte - clc + sta Pak.Mask .8 pla +* clc rts -.9 plp - pla - sec +.9 pla +* sec rts *-------------------------------------- Pak.PutByte inc Pak.DstCnt @@ -541,6 +546,7 @@ Pak.PutByte inc Pak.DstCnt beq .9 .1 sta (ZPDstPtr) + inc ZPDstPtr bne .2 inc ZPDstPtr+1 @@ -720,17 +726,20 @@ UnPak.PutByte inc UnZPDstPtr CS.END Pak.SrcPtr .BS 2 Pak.SrcCnt .BS 2 -Pak.DstPtr .BS 2 Pak.DstCnt .BS 2 Pak.RepCnt .BS 1 Pak.LastByte .BS 1 +Pak.StoreCnt .BS 1 +Pak.StoreBuf .BS STOREMAX + +Pak.Mask .BS 1 Pak.Byte .BS 1 Pak.Cnt .BS 2 -Pak.StoreMode .BS 1 +Pak.bPass2 .BS 1 Pak.MaxReadAhead .BS 1 Pak.BestBLLen .BS 1 @@ -739,13 +748,11 @@ Pak.WPtr .BS 2 Pak.WLimit .BS 2 Pak.WStrLen .BS 1 *-------------------------------------- -Pak.StoreBuf .BS 16 Pak.CntL .BS 256 Pak.CntH .BS 256 Pak.Hdr .BS S.PAKHDR Pak.Stat .BS S.PAKSTAT *-------------------------------------- -Pak.BitMask .HS 0102040810204080 UnPak.BitMask .HS 8040201008040201 MAN SAVE /A2OSX.SRC/LIB/LIBPAK.S diff --git a/TEST.S.txt b/TEST.S.txt index 597cbf57..65a9db7f 100644 --- a/TEST.S.txt +++ b/TEST.S.txt @@ -10,6 +10,17 @@ AUTO 4,1 .INB /A2OSX.BUILD/INC/A2OSX.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) *-------------------------------------- CS.START cld @@ -20,7 +31,7 @@ CS.START cld .DA CS.END-CS.START CS .DA DS.END-DS.START DS .DA #64 SS - .DA #0 ZP + .DA #16 ZP .DA 0 *-------------------------------------- * Relocation Table @@ -44,6 +55,8 @@ L.MSG3 .DA MSG3 L.MSG4 .DA MSG4 L.MSG5 .DA MSG5 L.MSG6 .DA MSG6 +L.MSG.UnpakErr .DA MSG.UnpakErr +L.MSG.DEBUG.S3 .DA MSG.DEBUG.S3 .DA 0 *-------------------------------------- CS.INIT >LDYA L.LIBPAK @@ -80,7 +93,7 @@ CS.RUN.Pak >PUSHWI 0 Aux type >LDYA.G PAK.FileSize >SYSCALL GetMem.YA bcs .9 - + >STYA ZPPakSrcPtr txa >STA.G PAK.hOutBuf @@ -92,6 +105,7 @@ CS.RUN.Pak >PUSHWI 0 Aux type >LDA.G PAK.hOutBuf >SYSCALL GetMemPtr.A + >STYA ZPPakHdrPtr >PUSHYA >PUSHEA.G PAK.Stat @@ -110,9 +124,202 @@ CS.RUN.Pak >PUSHWI 0 Aux type >LDYA L.MSG6 >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 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 *-------------------------------------- CS.RUN.Math >PUSHEA.G ENDPTR @@ -221,6 +428,8 @@ MSG6 .AS "Src Length : %D\r\n" .AS "S3 Count : %D\r\n" .AS "S4 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 .OR 0