mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-20 03:31:42 +00:00
320 lines
8.5 KiB
Plaintext
320 lines
8.5 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* S.NewPStrYA
|
||
* IN:
|
||
* PULLW = PTR to buffer
|
||
* OUT:
|
||
* A = hMem to S (PSTRING)
|
||
*--------------------------------------
|
||
S.NewPStrYA >STYA ZPQuickPtr1
|
||
lda (ZPQuickPtr1)
|
||
inc
|
||
tay
|
||
lda #0 Y,A = len of new string
|
||
>PUSHYA
|
||
>PUSHA 0 = no option
|
||
jsr S.GetMem
|
||
bcs .9
|
||
phx
|
||
>STYA ZPQuickPtr2
|
||
lda (ZPQuickPtr1)
|
||
sta (ZPQuickPtr2)
|
||
tay
|
||
beq .2
|
||
.1 lda (ZPQuickPtr1),y
|
||
sta (ZPQuickPtr2),y
|
||
dey
|
||
bne .1
|
||
.2 pla
|
||
clc
|
||
rts
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
* S.PStrCat
|
||
* IN:
|
||
* PULLB = hMem to S1 (PSTRING)
|
||
* PULLB = hMem to S2 (PSTRING)
|
||
* OUT:
|
||
* A = hMem to S1+S2 (PSTRING)
|
||
*--------------------------------------
|
||
S.PStrCat >PULLA
|
||
jsr S.GetMemPtrA
|
||
>STYA ZPQuickPtr1 save S1
|
||
>PULLA
|
||
jsr S.GetMemPtrA
|
||
>STYA ZPQuickPtr2 save S2
|
||
lda (ZPQuickPtr1) Compute length of new path = S1 + S2 + 1
|
||
sec
|
||
adc (ZPQuickPtr2)
|
||
tay
|
||
lda #0 Y,A = len of new string
|
||
>PUSHYA
|
||
>PUSHA 0 = no option
|
||
jsr S.GetMem
|
||
bcs .9 OOM error
|
||
>STYA ZPQuickPtr3
|
||
phx save New hMem
|
||
lda (ZPQuickPtr1)
|
||
tax
|
||
ldy #0
|
||
.2 iny
|
||
lda (ZPQuickPtr1),y
|
||
sta (ZPQuickPtr3),y
|
||
dex
|
||
bne .2
|
||
lda (ZPQuickPtr2)
|
||
tax
|
||
.3 inc ZPQuickPtr2
|
||
bne .4
|
||
inc ZPQuickPtr2+1
|
||
.4 iny
|
||
lda (ZPQuickPtr2)
|
||
sta (ZPQuickPtr3),y
|
||
dex
|
||
bne .3
|
||
tya
|
||
sta (ZPQuickPtr3)
|
||
pla returns A = new hMem
|
||
clc
|
||
rts
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
* S.PStrMatch
|
||
* IN:
|
||
* PULLB = PTR to String (PSTRING)
|
||
* PULLB = PTR to Pattern (PSTRING)
|
||
* OUT:
|
||
* cc = match
|
||
* cs = no match
|
||
*--------------------------------------
|
||
S.PStrMatch >PULLW ZPQuickPtr2 pull String
|
||
>PULLW ZPQuickPtr1 pull Pattern
|
||
|
||
lda (ZPQuickPTR1) Keep Pattern Length in X
|
||
tax
|
||
beq .8 Match always if empty
|
||
ldy #0
|
||
|
||
.1 inc ZPQuickPTR1 Make PTR1 advance to next char
|
||
bne .2
|
||
inc ZPQuickPTR1+1
|
||
|
||
.2 lda (ZPQuickPTR1) get pattern char
|
||
cmp #'*'
|
||
beq .5
|
||
|
||
.3 tya we must match ? or regular char
|
||
cmp (ZPQuickPTR2) check if at end of string
|
||
beq .9 yes, no char left, exit with error
|
||
|
||
iny advance to next char to compare
|
||
|
||
lda (ZPQuickPTR1) get back pattern char
|
||
cmp #'?'
|
||
beq .4 no need to compare, any char will match
|
||
cmp (ZPQuickPTR2),y Regular Char, compare with string at Y
|
||
bne .9 no match, exit
|
||
|
||
.4 dex char matched, check if end of pattern
|
||
bne .1 continue if remaining char in pattern
|
||
|
||
tya end of pattern, but end of string ?
|
||
cmp (ZPQuickPTR2) end of string ?
|
||
beq .8 yes, string matched entirely
|
||
bra .9 no, remaining char in string, no match
|
||
|
||
.5 dex we have '*', last char of pattern ?
|
||
beq .8 yes, match everything, including empty string
|
||
|
||
inc ZPQuickPTR1 Make PTR1 advance to next char
|
||
bne .6
|
||
inc ZPQuickPTR1+1
|
||
|
||
.6 lda (ZPQuickPTR1) get next char of pattern
|
||
cmp #'*' another '*' ?
|
||
beq .5 yes, '**' = '*', go next char
|
||
cmp #'?' '*?' ??? we must match a least one char
|
||
beq .3
|
||
|
||
.7 tya we need at least one remaining char in string,
|
||
cmp (ZPQuickPTR2) check if at end of string
|
||
beq .9 no chance to match ? or regular char
|
||
|
||
iny
|
||
lda (ZPQuickPTR1) get again char in pattern
|
||
cmp (ZPQuickPTR2),y compare with char in string
|
||
bne .7 not equal to next non wildcard in pattern
|
||
|
||
bra .4 go check remaining char in pattern...
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
* S.PStrGetTkn
|
||
* IN:
|
||
* PULLB = Token IDX
|
||
* 0: "Split mode": first token + remaining
|
||
* !0: "Std Mode": Return token #
|
||
* PULLB = SEP char
|
||
* PULLB = hMem to PSTRING
|
||
* OUT:
|
||
* A = hMem to Token (PSTRING)
|
||
* X = hMem to Remaining String After Token "Split Mode"
|
||
*--------------------------------------
|
||
S.PStrGetTkn >PULLA Get IDX
|
||
sta S.PStrGetTkn.IDX
|
||
>PULLA Get SEP
|
||
sta S.PStrGetTkn.SEP
|
||
>PULLA Get PStr
|
||
jsr S.GetMemPtrA
|
||
>STYA ZPQuickPtr1
|
||
|
||
S.PStrGetTkn1 ldx #0 init token count to 0
|
||
ldy #0
|
||
stz S.PStrGetTkn.START init INTOKEN start to 0
|
||
.1 iny
|
||
lda (ZPQuickPtr1),y
|
||
and #$7F
|
||
cmp S.PStrGetTkn.SEP char=SEP ?
|
||
bne .3 no, start a new token if not alredy in
|
||
lda S.PStrGetTkn.START SEP:in INTOKEN ?
|
||
beq .4 no, skip this SEP
|
||
inx yes, increase token count
|
||
lda S.PStrGetTkn.IDX requested token=0 ?
|
||
beq .71 yes, we are in "split mode"
|
||
cpx S.PStrGetTkn.IDX no,is current X=requested IDX?
|
||
beq .71
|
||
stz S.PStrGetTkn.START reset in INTOKEN start
|
||
bra .4
|
||
.3 lda S.PStrGetTkn.START char:already INTOKEN ?
|
||
bne .4 yes, keep existing start index
|
||
sty S.PStrGetTkn.START mark begining of token
|
||
.4 tya
|
||
cmp (ZPQuickPtr1) end of string ?
|
||
bne .1 no, get next one
|
||
lda S.PStrGetTkn.START INTOKEN?
|
||
beq .6
|
||
inx yes, last one is ending with string
|
||
.6 lda S.PStrGetTkn.IDX split mode ?
|
||
beq .7
|
||
cpx S.PStrGetTkn.IDX is token = requested?
|
||
beq .7
|
||
sec End of String reached, no matching token
|
||
.61 rts
|
||
|
||
.71 dey move back yo end of token before this SEP
|
||
.7 sty S.PStrGetTkn.END we have matching token (or 1st one in split mode) at [START,END]
|
||
tya compute token len=Y-END
|
||
sec
|
||
sbc S.PStrGetTkn.START
|
||
inc +1
|
||
inc +1 for string len
|
||
tay
|
||
lda #0
|
||
>PUSHYA Get a hMem for this token
|
||
>PUSHA 0 = no option
|
||
jsr S.GetMem
|
||
bcs .61
|
||
phx save hMem
|
||
>STYA ZPQuickPtr2
|
||
lda S.PStrGetTkn.END
|
||
sec
|
||
sbc S.PStrGetTkn.START
|
||
inc
|
||
sta (ZPQuickPtr2) set this string length
|
||
ldy S.PStrGetTkn.START
|
||
dey
|
||
.8 iny
|
||
inc ZPQuickPtr2
|
||
bne .9
|
||
inc ZPQuickPtr2+1
|
||
.9 lda (ZPQuickPtr1),y
|
||
sta (ZPQuickPtr2)
|
||
cpy S.PStrGetTkn.END
|
||
bne .8
|
||
lda S.PStrGetTkn.IDX requested token=0 ?
|
||
bne .87
|
||
tya yes, we are in "split mode"
|
||
cmp (ZPQuickPtr1) Remaining chars ?
|
||
beq .87
|
||
.10 iny move to next char
|
||
lda (ZPQuickPtr1),y
|
||
cmp S.PStrGetTkn.SEP char=SEP?
|
||
bne .11
|
||
tya
|
||
cmp (ZPQuickPtr1) last one ?
|
||
bne .10
|
||
bra .87 yes, nothing to return
|
||
.11 sty S.PStrGetTkn.END S.PStrGetTkn.END=1st non SEP char
|
||
lda (ZPQuickPtr1) compute reamining len=Y-ZPQuickPtr1+1
|
||
sec
|
||
sbc S.PStrGetTkn.END
|
||
inc
|
||
inc +1 for string len
|
||
tay
|
||
lda #0
|
||
>PUSHYA Get a hMem for remaining string
|
||
>PUSHA 0 = no option
|
||
jsr S.GetMem
|
||
bcs .98
|
||
phx save hMem
|
||
>STYA ZPQuickPtr2
|
||
lda (ZPQuickPtr1)
|
||
sec
|
||
sbcS.PStrGetTkn.END
|
||
inc
|
||
sta (ZPQuickPtr2)
|
||
ldy S.PStrGetTkn.END
|
||
dey
|
||
.12 iny
|
||
inc ZPQuickPtr2
|
||
bne .13
|
||
inc ZPQuickPtr2+1
|
||
.13 lda (ZPQuickPtr1),y
|
||
sta (ZPQuickPtr2)
|
||
tya
|
||
cmp (ZPQuickPtr1)
|
||
bne .12
|
||
plx get back remaining string hMem
|
||
pla get back token hMem
|
||
clc
|
||
rts
|
||
|
||
.87 ldx #0 Splitmode but no remaining string to return
|
||
pla get back token hMem
|
||
clc
|
||
rts
|
||
|
||
.98 pla get back Token hMem
|
||
jsr S.FreeMemA discard Token
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
S.PStrGetTkn.SEP .BS 1
|
||
S.PStrGetTkn.IDX .BS 1
|
||
S.PStrGetTkn.START .BS 1
|
||
S.PStrGetTkn.END .BS 1
|
||
*--------------------------------------
|
||
S.GetArgCount
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
S.GetArgA
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE SYS/KERNEL.S.STR
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|