Kernel 0.9.1 : ASM rewrite....Addressing Modes

This commit is contained in:
Rémy GIBERT 2018-03-16 16:33:11 +00:00
parent ff0efac421
commit bb8b8f1bd8
12 changed files with 531 additions and 234 deletions

Binary file not shown.

View File

@ -2,8 +2,13 @@ NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
*---------------------------------------
* U-Operators :
* B-Operators :
* EXP.Modifiers:
* # : 8b,Byte 1
* / : 8b,Byte 2
* ^ : 8b,Byte 3
* < : 24b,Byte 1,2,3
* > : 32b
*---------------------------------------
* Num Format : 0-9 -> decimal
* $ = Hex
* % = binary
@ -11,11 +16,11 @@ AUTO 4,1
* * = PC
*---------------------------------------
EXP.Eval lda #2
sta SRC.ACC.SIZE Assume WORD (2 bytes)
sta SRC.ACC.SIZE Default To WORD (2 bytes)
stz EXP.Modifier
stz EXP.Operator
>STZ.G EXP.Modifier
>STZ.G EXP.Prefix
>STZ.G EXP.Operator
jsr SRC.GetChar
bcs EXP.Eval.Missing
@ -23,7 +28,11 @@ EXP.Eval lda #2
jsr SRC.IsMODReserved
bcs EXP.Eval.Next1
stx EXP.Modifier
txa
>STA.G EXP.Modifier
lda #'#'
>STA.G EXP.Prefix
bra EXP.Eval.Next
EXP.Eval.Missing lda #ERR.MISSING.EXP
@ -123,7 +132,12 @@ EXP.Eval.Next1 cmp #'.' Local Label?
bcs EXP.EvalExitUND
bra EXP.EvalOperator
EXP.EvalExitOK clc
EXP.EvalExitOK >LDA.G EXP.Modifier
beq .8
asl
tax
jmp (J.EXP.MOD,x)
.8 clc
EXP.EvalExitRTS rts
EXP.EvalExitSYN lda #ERR.SYNTAX.ERROR
@ -134,7 +148,7 @@ EXP.EvalExitUND lda #ERR.UNDEF.SYMBOL
sec
rts
EXP.EvalOperator lda EXP.Operator
EXP.EvalOperator >LDA.G EXP.Operator
beq .7
jsr EXP.Compute
@ -151,8 +165,8 @@ EXP.EvalOperator lda EXP.Operator
jsr SRC.IsEXPReserved
bcs EXP.EvalExitSYN
stx EXP.Operator
txa
>STA.G EXP.Operator
ldx #3
@ -213,6 +227,23 @@ EXP.Compute dec
.8 clc
rts
*---------------------------------------
EXP.MOD.8.3 lda SRC.ACC+2
bra EXP.MOD.8
EXP.MOD.8.2 lda SRC.ACC+1
EXP.MOD.8 sta SRC.ACC
EXP.MOD.8.1 lda #1
sta SRC.ACC.SIZE
clc
rts
EXP.MOD.24 lda #3
sta SRC.ACC.SIZE
clc
rts
EXP.MOD.32 lda #4
sta SRC.ACC.SIZE
clc
rts
*---------------------------------------
EXP.OP.EOR ldx #3
.1 lda SRC.ARG,x

View File

@ -76,7 +76,6 @@ OUT.PrintLine.9 rts
OUT.PrintLineOn clc
rts
>LDA.G ASM.LI.ON
bpl .9
@ -147,11 +146,11 @@ OUT.PrintLineAcc ldx SRC.ACC.SIZE
dex
bne .1
.2 lda SRC.ACC.SIZE
lda SRC.ACC.SIZE
asl
tax
ldy L.MSG.EQU0,x
.2 ldy L.MSG.EQU0,x
lda L.MSG.EQU0+1,x
>SYSCALL PrintF.YA
rts

View File

@ -178,7 +178,7 @@ SRC.ParseLine.LABEL lda #0
bit #SYM.F.RESOLVED
bne SRC.ParseLine.Redef
.2 jsr SYM.UpdateGlobal
.2 jsr SYM.UpdateGlobalPC
bra SRC.ParseLine.DirOp
.3 jsr SYM.LookupGlobal Pass #2: should be already defined...
@ -243,7 +243,7 @@ SRC.ParseLine.ExecMacro
rts
*---------------------------------------
SRC.ParseLine.OpCode
stz SRC.AM.ID
stz SRC.AM.StrBuf
>LDYA ZPOPtr
>STYA ZPPtr1
@ -310,20 +310,23 @@ SRC.ParseLine.OpCode
sta ZPPtr1+1
bra .1
.8 clc
rts
.8 jmp SRC.ParseLine.AMCheck
.9 lda #ERR.INV.OPCODE
sec
.99 rts
*---------------------------------------
SRC.ParseLine.AM stz SRC.AM.StrBuf
SRC.ParseLine.AM >LDA.G EXP.Prefix
beq .1
inc SRC.AM.StrBuf
ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
.1 jsr SRC.GetChar
bcs .8
bcs SRC.ParseLine.AMCheck
.10 cmp #' ' another space ?
beq .8 ignore end of line (comment)
beq SRC.ParseLine.AMCheck ignore end of line (comment)
jsr SRC.IsAMReserved
bcs .2
@ -333,18 +336,7 @@ SRC.ParseLine.AM stz SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
bra .7
.2 jsr SRC.IsMODReserved
bcs .3
lda #'#'
inc SRC.AM.StrBuf
ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
jsr SRC.GetNextChar
bcs .9
.3 jsr SRC.IsLetter Any register?
.2 jsr SRC.IsLetter Any register?
bcs .6 no, try something else
>LDYA ZPRPtr Check in register table
@ -395,13 +387,22 @@ SRC.ParseLine.AM stz SRC.AM.StrBuf
.7 jsr SRC.GetNextChar
bcc .10
.8 clc
rts
jmp SRC.ParseLine.AMCheck
.9 lda #ERR.INV.AM.SYN
sec
.99 rts
*---------------------------------------
SRC.ParseLine.AMCheck
jsr OUT.PrintLine.1
>PUSHW L.SRC.AM.StrBuf
>LDYA L.MSG.PSTRCRLF
>SYSCALL PrintF.YA
>DEBUG
clc
rts
*---------------------------------------
SRC.GetDecimal jsr SRC.GetChar
beq .99
@ -618,9 +619,11 @@ SRC.GetBinary jsr SRC.GetNextChar skip '%'
*---------------------------------------
SRC.GetKeyword >STYA ZPPtr1 KeyWord table
stz SRC.Keyword.ID
lda #0 Keyword.ID
.1 lda (ZPPtr1)
.1 pha
lda (ZPPtr1)
beq .9 End Of table
tax KW len
@ -628,14 +631,14 @@ SRC.GetKeyword >STYA ZPPtr1 KeyWord table
.2 ldy #0
.3 lda (ZPLinePtr),y
beq .5
beq .6
jsr SRC.IsKeywordLetterUC
bcs .5
bcs .6
iny
cmp (ZPPtr1),y
bne .5
bne .6
dex
bne .3
@ -644,31 +647,34 @@ SRC.GetKeyword >STYA ZPPtr1 KeyWord table
beq .4 End of Line ?
jsr SRC.IsKeywordLetterUC
bcc .5 Additional letters...
bcc .6 Additional letters...
.4 lda ZPLinePtr
clc
adc (ZPPtr1)
sta ZPLinePtr
bcc .41
bcc .5
inc ZPLinePtr+1
.41 ldx SRC.Keyword.ID
.5 pla Keyword.ID
clc
rts
.5 lda (ZPPtr1)
.6 lda (ZPPtr1)
sec Add keyword Len+1
adc ZPPtr1
sta ZPPtr1
bcc .6
bcc .7
inc ZPPtr1+1
.6 inc SRC.Keyword.ID
inc SRC.Keyword.ID
.7 pla Keyword.ID
inc
inc
bra .1
.9 sec
.9 plx
sec
rts
*---------------------------------------
SRC.IsAMReserved ldx SRC.AM.RESERVED

View File

@ -66,19 +66,13 @@ SYM.Dump stz ZPLinePtr
>PUSHW ZPLinePtr
>PUSHW ZPTmpBuf
>SYSCALL SListGetByID
pha
txa
sta ZPLinePtr
tya
sta ZPLinePtr+1
pla
bcs .8
stx ZPLinePtr Save Next ID
sty ZPLinePtr+1
>LDA.G ASM.LI.ON
bpl .1
>PUSHW ZPTmpBuf Label (PString)
lda (ZPTmpBuf)
sec
adc ZPTmpBuf
@ -87,8 +81,15 @@ SYM.Dump stz ZPLinePtr
adc #0
sta ZPPtr1+1
ldx #4
ldy #2
ldy #SYM.F Get Symbol Size
lda (ZPPtr1),y
and #3
beq .3
pha
tax
iny SYM.V
.2 lda (ZPPtr1),y
>PUSHA
@ -96,18 +97,26 @@ SYM.Dump stz ZPLinePtr
dex
bne .2
>LDYA L.MSG.GSYMBOL
pla
asl
.3 tax
ldy L.MSG.EQU0,x
lda L.MSG.EQU0+1,x
>SYSCALL PrintF.YA
>PUSHW ZPTmpBuf Label (PString)
>LDYA L.MSG.PSTRCRLF
>SYSCALL PrintF.YA
bcc .1
rts
.8 clc
rts
*---------------------------------------
SYM.AddGlobalPC jsr SYM.PC2Global
lda #SYM.F.RESOLVED
SYM.AddGlobalPC jsr SYM.PC2Global A=SYM.Len
ora #SYM.F.RESOLVED PC is always known
*---------------------------------------
SYM.AddGlobal >STA.G SYM.Global+SYM.F
@ -170,8 +179,19 @@ SYM.UpdateGlobalAcc ldx #3
dey
dex
bpl .1
ldx #4
ldy #3
.3 lda SRC.ACC,y
bne .4
dex
dey
bne .3
.4 txa
*---------------------------------------
SYM.UpdateGlobal lda #SYM.F.RESOLVED
SYM.UpdateGlobal ora #SYM.F.RESOLVED
>STA.G SYM.Global+SYM.F
lda #5 F+DWORD
@ -203,6 +223,18 @@ SYM.PC2Global ldx #4
dey
dex
bne .2
ldx #4
ldy #ASM.PC+3
.3 lda (pData),y
bne .4
dex
dey
bne .3
.4 txa
rts
*---------------------------------------
SYM.AddLocalPC tax Save ID

View File

@ -90,7 +90,7 @@ L.MSG.EQU0 .DA MSG.EQU0
L.MSG.SRCLINE .DA MSG.SRCLINE
L.MSG.ERROR .DA MSG.ERROR
L.MSG.SYMBOLS .DA MSG.SYMBOLS
L.MSG.GSYMBOL .DA MSG.GSYMBOL
L.MSG.PSTRCRLF .DA MSG.PSTRCRLF
L.MSG.SUMMARY .DA MSG.SUMMARY
L.MSG.PASS .DA MSG.PASS
L.MSG.SRC.FILE .DA MSG.SRC.FILE
@ -150,6 +150,11 @@ J.LI .DA DIR.LI.ON
.DA DIR.LI.MOFF
.DA DIR.LI.XON
.DA DIR.LI.XOFF
J.EXP.MOD .DA EXP.MOD.8.1
.DA EXP.MOD.8.2
.DA EXP.MOD.8.3
.DA EXP.MOD.24
.DA EXP.MOD.32
J.EXP.OP .DA EXP.OP.EOR ^!|&<=>+-*/
.DA EXP.OP.ORA
.DA EXP.OP.ORA
@ -383,43 +388,38 @@ T.LI >PSTR "ON"
>PSTR "XOFF"
.HS 00
*---------------------------------------
MSG.HELP >CSTR "A2osX-Macro Assembler (S-C MASM 3.0 Based)\r\nUsage : ASM <src file> [type TXT ($04) or S-C/BAS ($FA)]\r\n"
MSG.PASS >CSTR "Pass:#%d\r\n"
MSG.SRC.FILE >CSTR "Reading SRC File:%s\r\n"
MSG.OBJ.FILE >CSTR "Writing OBJ File:%s, Type=%02x\r\n"
MSG.T.FILE >CSTR "Loading CPU File:%s\r\n"
MSG.OUT0 >CSTR "%H- "
MSG.OUT1 >CSTR "%H-%h "
MSG.OUT2 >CSTR "%H-%h %h "
MSG.OUT3 >CSTR "%H-%h %h %h"
MSG.EQU0 >CSTR "[ ]"
MSG.EQU1 >CSTR "[ %h]"
MSG.EQU2 >CSTR "[ %h%h]"
MSG.EQU3 >CSTR "[ %h%h%h]"
MSG.EQU4 >CSTR "[ %h%h%h%h]"
MSG.SRCLINE >CSTR " %05D %s\r\n"
MSG.ERROR >CSTR "*** Fatal Error $%h "
MSG.SYMBOLS >CSTR "Symbol Table:\r\n"
MSG.GSYMBOL >CSTR "$%h%h%h%h:%S\r\n"
MSG.SUMMARY >CSTR "\r\nSymbol Table Size : %5D Bytes.\r\nEnd Of Assembly.\r\n"
SRC.AM.RESERVED >PSTR "[](),"
SRC.MOD.RESERVED >PSTR "#/<>"
ASM.6502 .AZ "6502"
MSG.HELP .AZ "A2osX-Macro Assembler (S-C MASM 3.0 Based)\r\nUsage : ASM <src file> [type TXT ($04) or S-C/BAS ($FA)]\r\n"
MSG.PASS .AZ "Pass:#%d\r\n"
MSG.SRC.FILE .AZ "Reading SRC File:%s\r\n"
MSG.OBJ.FILE .AZ "Writing OBJ File:%s, Type=%02x\r\n"
MSG.T.FILE .AZ "Loading CPU File:%s\r\n"
MSG.OUT0 .AZ "%H- "
MSG.OUT1 .AZ "%H-%h "
MSG.OUT2 .AZ "%H-%h %h "
MSG.OUT3 .AZ "%H-%h %h %h"
MSG.EQU0 .AZ "[ ?]"
MSG.EQU1 .AZ "[ %h]"
MSG.EQU2 .AZ "[ %h%h]"
MSG.EQU3 .AZ "[ %h%h%h]"
MSG.EQU4 .AZ "[ %h%h%h%h]"
MSG.SRCLINE .AZ " %05D %s\r\n"
MSG.ERROR .AZ "*** Fatal Error $%h "
MSG.SYMBOLS .AZ "Symbol Table:\r\n"
MSG.PSTRCRLF .AZ " %S\r\n"
MSG.SUMMARY .AZ "\r\nSymbol Table Size : %5D Bytes.\r\nEnd Of Assembly.\r\n"
SRC.MOD.RESERVED >PSTR "#/^<>"
SRC.EXP.RESERVED >PSTR "^!|&<=>+-*/"
ASM.6502 >CSTR "6502"
SRC.AM.RESERVED >PSTR "[](),"
*---------------------------------------
ASM.T.FILENAME .BS 65
FIO.Stat .BS S.STAT
EXP.Modifier .BS 1
EXP.Operator .BS 1
SRC.Keyword.ID .BS 1
SRC.ACC.SIZE .BS 1
SRC.ACC .BS 4
SRC.ACCTMP .BS 4
SRC.ARG .BS 4
SRC.AM.ID .BS 1
SRC.AM.StrBuf .BS 32
*--------------------------------------
.DUMMY
@ -446,6 +446,11 @@ ASM.T.hMem .BS 1
DIR.Word .BS 2
DIR.Byte .BS 1
EXP.Modifier .BS 1
EXP.Prefix .BS 1
EXP.Operator .BS 1
ASM.PASS .BS 1
ASM.DO.StackPtr .BS 1
ASM.DO.Stack .BS SRC.DO.MAXDEPTH

View File

@ -1,10 +1,6 @@
PR#3
PREFIX /A2OSX.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
PREFIX /A2OSX.BUILD
AUTO 4,1
*--------------------------------------
* File Header :
*--------------------------------------
@ -14,17 +10,12 @@ S.PAKFILE.VER .EQ 8
S.PAKFILE.TF .EQ 9 Target File (C-String)
*--------------------------------------
* Shunk Header :
* WORD : !Target UNCompressed Length
* USED TO STOP UNPACK
* !!!NO EOF TOKEN!!!
* Short3 : [0..7]
* Short4 : [0..15]
* WORD : Target UNCompressed Length
* !!! USED TO STOP UNPACK,NO EOF TOKEN!!!
*--------------------------------------
S.PAKHDR.LEN .EQ 0
S.PAKHDR.SHORT3 .EQ 2
S.PAKHDR.SHORT4 .EQ 10
S.PAKSHK.ULEN .EQ 0 Uncompressed length
*
S.PAKHDR .EQ 26
S.PAKSHK .EQ 26
*--------------------------------------
S.PAKSTAT.PASS1 .EQ 0
S.PAKSTAT.PASS2 .EQ 2

10
LIB/LIBPAK.S.AC.txt Normal file
View File

@ -0,0 +1,10 @@
NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBPAK.S.AC
ASM

71
LIB/LIBPAK.S.IN.txt Normal file
View File

@ -0,0 +1,71 @@
NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
Pak.In.Init >LDYA Pak.SrcPtr
>STYA ZPSrcPtr
lda Pak.Hdr+S.PAKHDR.LEN
eor #$ff
sta Pak.SrcCnt
lda Pak.Hdr+S.PAKHDR.LEN+1
eor #$ff
sta Pak.SrcCnt+1
rts
*--------------------------------------
Pak.In.GetRH lda #$ff
cmp Pak.SrcCnt+1 return 255 if not $ffxx
bne .1
lda Pak.SrcCnt
eor #$ff return !xx if $ffxx
.1 rts
*--------------------------------------
Pak.In.MoveFWA clc
adc ZPSrcPtr
sta ZPSrcPtr
bcc .8
inc ZPSrcPtr+1
.8 rts
*--------------------------------------
Pak.In.Get8Bits ldy #8
.HS 2C bit abs
Pak.In.Get4Bits ldy #4
lda #0 make sure to reset A before reading less than 8 bits only
.1 jsr Pak.In.GetBit and to exit with CC if even if 8 bits read
rol
dey
bne .1
rts always CC
*--------------------------------------
Pak.In.GetBit ldx Pak.In.Mask
bne .1
jsr Pak.In.NxtByte
ldx #8
.1 dex
stx Pak.In.GetBit+1
pha Don't trash A
lda (UnZPSrcPtr)
and Pak.In.BitMask,x
cmp #1 if 0:CC, i>0 CS
pla
rts Bit is in C
*--------------------------------------
Pak.In.GetByte lda (UnZPSrcPtr)
Pak.In.NxtByte inc UnZPSrcPtr
bne .8
inc UnZPSrcPtr+1
.8 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBPAK.S.IN
ASM

166
LIB/LIBPAK.S.LZ.txt Normal file
View File

@ -0,0 +1,166 @@
NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
* Sliding Window = 4096
*--------------------------------------
WSIZE .EQ 4096 power of 2
*--------------------------------------
* Output BITSTREAM :
* 0 : Lit (8)
* 1 : Copy, L (4), P.HI (4), P.LO (8)
*--------------------------------------
Pak.LZ jsr Pak.In.Init Init SrcPtr,SrcCnt
jsr Pak.Out.Init
* future optimization, make P grows from 2 to 12 while increasing W size
* lda #2 Ptr width starts at 2 bits
* sta Pak.LZ.PWidth
* lda #%00000011 Ptr Mask Starts at %000000000011
* sta Pak.LZ.PMaskLO
* stz Pak.LZ.PMaskHI
lda #$ff
sta Pak.LZ.WCnt
sta Pak.LZ.WCnt+1 WCnt=!0
.1 jsr Pak.In.GetRH Z if EOF
beq .80
cmp #3
bcc .8 no more than 2 bytes left....store
cmp #19 more than 18 bytes left, limit to 18
bcc .2
lda #18
.2 tax X = Read ahead max size
lda ZPSrcPtr make ZPSrcWPtr=ZPSrcPtr
sta ZPSrcWPtr
lda ZPSrcPtr
sta ZPSrcWPtr
lda Pak.LZ.WCnt
sta ZPCnt
lda Pak.LZ.WCnt+1
sta ZPCnt+1
stz Pak.LZ.BestLen
.3 inc ZPCnt
bne .4
inc ZPCnt+1
beq .7 reached begining of window....store
lda ZPSrcWPtr make ZPSrcWPtr-=1
sec
sbc #1
sta ZPSrcWPtr
bcs .4
dec ZPSrcWPtr+1
.4 ldy #0
phx save Read ahead max size
.5 lda (ZPSrcPtr),y Try to find a match
cmp (ZPSrcWPtr),y
bne .6
iny
dex don't exceed 18 or Src Buffer
bne .5
.6 plx get back Read ahead max size
cpy #3 matched a least 3 chars ?
bcc .3 no....try one char back in Wnd
cpy Pak.LZ.BestLen better than last match ?
bcc .3 no....try one char back in Wnd
sty Pak.LZ.BestLen
lda ZPSrcWPtr
sta Pak.LZ.BestPtr
lda ZPSrcWPtr+1
sta Pak.LZ.BestPtr+1
bra .3
.7 lda Pak.LZ.BestLen do we match something ?
beq .8
lda Pak.LZ.BestPtr
sec
sbc ZPSrcPtr
sta Pak.LZ.BestPtr
lda Pak.LZ.BestPtr+1
sbc ZPSrcPtr+1
sta Pak.LZ.BestPtr+1
tya get len
dec Adjust range 0-15
dec
dec
ora Pak.LZ.BestPtr+1 merge with P.HI
sec
jsr Pak.Out.PutCA Put 9 bits 1+LLLL+PPPP
bcs .99
lda Pak.LZ.BestPtr Put 8 bits pppppppp
jsr Pak.Out.PutA
bcs .99
tya
bra .81
.8 lda (ZPSrcPtr)
clc
jsr Pak.Out.PutCA Put 9 bits 0+xxxxxxxx
bcs .99
lda #1
.81 jsr Pak.In.MoveFWA
tya
jsr LZ.MoveWndY
bra .3
bra .71
.80 clc
.99 rts
*--------------------------------------
Unpak.LZ
clc
rts
*--------------------------------------
LZ.MoveWndY tya
sec
sbc Pak.LZ.WCnt
tax
lda #0
sbc Pak.LZ.WCnt+1
cpx #WSIZE^$FF
sbc /WSIZE^$FF
bcs .1
ldx #WSIZE^$FF
lda /WSIZE^$FF
.1 stx Pak.LZ.WCnt
sta Pak.LZ.WCnt+1
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBPAK.S.LZ
ASM

91
LIB/LIBPAK.S.OUT.txt Normal file
View File

@ -0,0 +1,91 @@
NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
Pak.Out.Init lda #$80
sta Pak.Out.Mask
stz Pak.Out.Byte
rts
*--------------------------------------
Pak.Out.Close bit Pak.Out.Mask
bmi .8
lda Pak.Out.Byte
jmp Pak.Out.PutByte
.8 clc
rts
*--------------------------------------
Pak.Out.PutCA jsr Pak.Out.PutBitC
bcs Pak.Out.Put.rts
Pak.Out.PutA ldy #8
.1 asl
jsr Pak.Out.PutBitC
bcs Pak.Out.Put.rts
dey
bne .1
Pak.Out.Put.rts rts
*--------------------------------------
Pak.Out.PutBitC pha
bcc .1
lda Pak.Mask
tsb Pak.Byte
clc
.1 lsr Pak.Mask
bne .8
jsr Pak.Out.PutByte
bcs .9
jsr Pak.Out.Init
.8 pla
* clc
rts
.9 pla
* sec
rts
*--------------------------------------
Pak.Out.PutByte inc Pak.DstCnt
bne .1
inc Pak.DstCnt+1
beq .9
.1 ldx Pak.Pass
bne .6
phx
tax
inc Pak.CntL,x
bne .2
inc Pak.CntH,x
.2 plx
bra .7
.6 sta (ZPDstPtr)
inc ZPDstPtr
bne .2
inc ZPDstPtr+1
.7 inc Pak.Stat+S.PAKSTAT.PASS1,x
bne .8
inc Pak.Stat+S.PAKSTAT.PASS1+1,x
.8 clc
rts
.9 sec
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBPAK.S.OUT
ASM

View File

@ -5,41 +5,14 @@ AUTO 4,1
.OP 65C02
.OR $2000
.TF /A2OSX.BUILD/LIB/LIBPAK.O
*--------------------------------------
* BITSTREAM :
*--------------------------------------
* 0 : SHORT3 (1)+3=4 bits
* 3 bits : index in Short3 Table
*--------------------------------------
* 10 : SHORT4 (2)+4=6 bits
* 4 bits : index in Short4 Table
*--------------------------------------
* 110 : REPn (3)+5=8 bits
* 5 bits count (1+n)
*--------------------------------------
* 1110 = BACKLINK : (4)+12+8=24 bits
* 12 bits : Offset (HI-4,LO-8)
* 8 bits : 4 + n (8 bits count) (259 max)
*--------------------------------------
* 1111 : STOREn (4) + 4 cnt + 8n....
*--------------------------------------
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
.INB /A2OSX.BUILD/INC/LIBPAK.I
*--------------------------------------
ZPSrcWPtr .EQ ZPLIB
ZPSrcPtr .EQ ZPLIB+2
ZPSrcPtr .EQ ZPLIB
ZPSrcWPtr .EQ ZPLIB+2
ZPCnt .EQ ZPLIB+4
ZPHdrPtr .EQ ZPLIB+14
ZPDstPtr .EQ ZPLIB+16
ZPStatPtr .EQ ZPLIB+18
@ -499,68 +472,24 @@ Pak.Flush ldx Pak.StoreCnt
ldx #0
.1 lda Pak.StoreBuf,x
ldy #4
sta Pak.LastByte update last byte for REP
ldy #8
jsr Pak.PutYBits
bcs .9
inx
inc Pak.Stat+S.PAKSTAT.STORE
bne .2
inc Pak.Stat+S.PAKSTAT.STORE+1
.2 inx
dec Pak.StoreCnt
bne .1
ldx #S.PAKSTAT.STORE
jsr Pak.UpdateStats
stz Pak.RepCnt Don't forget to set last byte valid
.8 clc
.9 rts
*--------------------------------------
* Pak.PutBit (bit in C)
*--------------------------------------
Pak.PutBit pha
bcc .1
lda Pak.Mask
tsb Pak.Byte
clc
.1 lsr Pak.Mask
bne .8
jsr Pak.PutByte
bcs .9
stz Pak.Byte
lda #$80
sta Pak.Mask
.8 pla
* clc
rts
.9 pla
* sec
rts
*--------------------------------------
Pak.PutByte inc Pak.DstCnt
bne .1
inc Pak.DstCnt+1
beq .9
.1 sta (ZPDstPtr)
inc ZPDstPtr
bne .2
inc ZPDstPtr+1
.2 inc Pak.Stat+S.PAKSTAT.PASS2
bne .8
inc Pak.Stat+S.PAKSTAT.PASS2+1
.8 clc
rts
.9 sec
rts
*--------------------------------------
Pak.UpdateStats inc Pak.Stat,x
bne .8
inc Pak.Stat+1,x
@ -684,45 +613,6 @@ UnPak >PULLA Get Dst PTR LO
bne .9
jmp .1
*--------------------------------------
UnPak.Get8Bits ldy #8
.HS 2C bit abs
UnPak.Get4Bits ldy #4
lda #0 make sure to reset A before reading less than 8 bits only
.1 jsr UnPak.GetBit and to exit with CC if even if 8 bits read
rol
dey
bne .1
rts always CC
*--------------------------------------
UnPak.GetBit ldx #$ff Self Modified code
bne .1
jsr UnPak.NxtByte
ldx #8
.1 dex
stx UnPak.GetBit+1
pha Don't trash A
lda (UnZPSrcPtr)
and UnPak.BitMask,x
cmp #1 if 0:CC, i>0 CS
pla
rts Bit is in C
*--------------------------------------
UnPak.GetByte lda (UnZPSrcPtr)
UnPak.NxtByte inc UnZPSrcPtr
bne .8
inc UnZPSrcPtr+1
.8 rts
*--------------------------------------
UnPak.PutByte inc UnZPDstPtr
bne .8
inc UnZPDstPtr+1
.8 sta (UnZPDstPtr)
rts
*--------------------------------------
CS.END
Pak.SrcPtr .BS 2
Pak.SrcCnt .BS 2
@ -734,8 +624,6 @@ Pak.LastByte .BS 1
Pak.StoreCnt .BS 1
Pak.StoreBuf .BS STOREMAX
Pak.Mask .BS 1
Pak.Byte .BS 1
Pak.Cnt .BS 2
@ -747,6 +635,13 @@ Pak.BestBL .BS 2
Pak.WPtr .BS 2
Pak.WLimit .BS 2
Pak.WStrLen .BS 1
Pak.In.Byte .BS 1
Pak.In.Mask .BS 1
Pak.Out.Byte .BS 1
Pak.Out.Mask .BS 1
*--------------------------------------
Pak.CntL .BS 256
Pak.CntH .BS 256