A2osX/SYS/KERNEL.S.STR.txt

320 lines
8.5 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2015-03-14 21:48:35 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
2015-06-03 18:30:57 +00:00
* S.NewPStrYA
* IN:
* PULLW = PTR to buffer
* OUT:
* A = hMem to S (PSTRING)
*--------------------------------------
S.NewPStrYA >STYA ZPQuickPtr1
lda (ZPQuickPtr1)
2015-03-14 21:48:35 +00:00
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)
2015-03-14 21:48:35 +00:00
* OUT:
* cc = match
* cs = no match
*--------------------------------------
S.PStrMatch >PULLW ZPQuickPtr2 pull String
2015-03-14 21:48:35 +00:00
>PULLW ZPQuickPtr1 pull Pattern
lda (ZPQuickPTR1) Keep Pattern Length in X
2015-03-14 21:48:35 +00:00
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
2016-06-07 06:10:18 +00:00
sta S.PStrGetTkn.IDX
2015-03-14 21:48:35 +00:00
>PULLA Get SEP
2016-06-07 06:10:18 +00:00
sta S.PStrGetTkn.SEP
2015-03-14 21:48:35 +00:00
>PULLA Get PStr
jsr S.GetMemPtrA
>STYA ZPQuickPtr1
2016-06-07 06:10:18 +00:00
S.PStrGetTkn1 ldx #0 init token count to 0
2015-03-14 21:48:35 +00:00
ldy #0
2016-06-07 06:10:18 +00:00
stz S.PStrGetTkn.START init INTOKEN start to 0
2015-03-14 21:48:35 +00:00
.1 iny
lda (ZPQuickPtr1),y
and #$7F
2016-06-07 06:10:18 +00:00
cmp S.PStrGetTkn.SEP char=SEP ?
2015-03-14 21:48:35 +00:00
bne .3 no, start a new token if not alredy in
2016-06-07 06:10:18 +00:00
lda S.PStrGetTkn.START SEP:in INTOKEN ?
2015-03-14 21:48:35 +00:00
beq .4 no, skip this SEP
inx yes, increase token count
2016-06-07 06:10:18 +00:00
lda S.PStrGetTkn.IDX requested token=0 ?
2015-03-14 21:48:35 +00:00
beq .71 yes, we are in "split mode"
2016-06-07 06:10:18 +00:00
cpx S.PStrGetTkn.IDX no,is current X=requested IDX?
2015-03-14 21:48:35 +00:00
beq .71
2016-06-07 06:10:18 +00:00
stz S.PStrGetTkn.START reset in INTOKEN start
2015-03-14 21:48:35 +00:00
bra .4
2016-06-07 06:10:18 +00:00
.3 lda S.PStrGetTkn.START char:already INTOKEN ?
2015-03-14 21:48:35 +00:00
bne .4 yes, keep existing start index
2016-06-07 06:10:18 +00:00
sty S.PStrGetTkn.START mark begining of token
2015-03-14 21:48:35 +00:00
.4 tya
cmp (ZPQuickPtr1) end of string ?
bne .1 no, get next one
2016-06-07 06:10:18 +00:00
lda S.PStrGetTkn.START INTOKEN?
2015-03-14 21:48:35 +00:00
beq .6
inx yes, last one is ending with string
2016-06-07 06:10:18 +00:00
.6 lda S.PStrGetTkn.IDX split mode ?
2015-03-14 21:48:35 +00:00
beq .7
2016-06-07 06:10:18 +00:00
cpx S.PStrGetTkn.IDX is token = requested?
2015-03-14 21:48:35 +00:00
beq .7
sec End of String reached, no matching token
.61 rts
2016-06-07 06:10:18 +00:00
2015-03-14 21:48:35 +00:00
.71 dey move back yo end of token before this SEP
2016-06-07 06:10:18 +00:00
.7 sty S.PStrGetTkn.END we have matching token (or 1st one in split mode) at [START,END]
tya compute token len=Y-END
2015-03-14 21:48:35 +00:00
sec
2016-06-07 06:10:18 +00:00
sbc S.PStrGetTkn.START
2015-03-14 21:48:35 +00:00
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
2016-06-07 06:10:18 +00:00
>STYA ZPQuickPtr2
lda S.PStrGetTkn.END
2015-03-14 21:48:35 +00:00
sec
2016-06-07 06:10:18 +00:00
sbc S.PStrGetTkn.START
2015-03-14 21:48:35 +00:00
inc
2016-06-07 06:10:18 +00:00
sta (ZPQuickPtr2) set this string length
ldy S.PStrGetTkn.START
2015-03-14 21:48:35 +00:00
dey
.8 iny
2016-06-07 06:10:18 +00:00
inc ZPQuickPtr2
2015-03-14 21:48:35 +00:00
bne .9
2016-06-07 06:10:18 +00:00
inc ZPQuickPtr2+1
2015-03-14 21:48:35 +00:00
.9 lda (ZPQuickPtr1),y
2016-06-07 06:10:18 +00:00
sta (ZPQuickPtr2)
cpy S.PStrGetTkn.END
2015-03-14 21:48:35 +00:00
bne .8
2016-06-07 06:10:18 +00:00
lda S.PStrGetTkn.IDX requested token=0 ?
2015-03-14 21:48:35 +00:00
bne .87
tya yes, we are in "split mode"
cmp (ZPQuickPtr1) Remaining chars ?
beq .87
.10 iny move to next char
lda (ZPQuickPtr1),y
2016-06-07 06:10:18 +00:00
cmp S.PStrGetTkn.SEP char=SEP?
2015-03-14 21:48:35 +00:00
bne .11
tya
cmp (ZPQuickPtr1) last one ?
bne .10
bra .87 yes, nothing to return
2016-06-07 06:10:18 +00:00
.11 sty S.PStrGetTkn.END S.PStrGetTkn.END=1st non SEP char
lda (ZPQuickPtr1) compute reamining len=Y-ZPQuickPtr1+1
2015-03-14 21:48:35 +00:00
sec
2016-06-07 06:10:18 +00:00
sbc S.PStrGetTkn.END
2015-03-14 21:48:35 +00:00
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
2016-06-07 06:10:18 +00:00
>STYA ZPQuickPtr2
2015-03-14 21:48:35 +00:00
lda (ZPQuickPtr1)
sec
2016-06-07 06:10:18 +00:00
sbcS.PStrGetTkn.END
2015-03-14 21:48:35 +00:00
inc
2016-06-07 06:10:18 +00:00
sta (ZPQuickPtr2)
ldy S.PStrGetTkn.END
2015-03-14 21:48:35 +00:00
dey
.12 iny
2016-06-07 06:10:18 +00:00
inc ZPQuickPtr2
2015-03-14 21:48:35 +00:00
bne .13
2016-06-07 06:10:18 +00:00
inc ZPQuickPtr2+1
2015-03-14 21:48:35 +00:00
.13 lda (ZPQuickPtr1),y
2016-06-07 06:10:18 +00:00
sta (ZPQuickPtr2)
2015-03-14 21:48:35 +00:00
tya
cmp (ZPQuickPtr1)
bne .12
plx get back remaining string hMem
pla get back token hMem
clc
rts
2016-06-07 06:10:18 +00:00
2015-03-14 21:48:35 +00:00
.87 ldx #0 Splitmode but no remaining string to return
pla get back token hMem
clc
rts
2016-06-07 06:10:18 +00:00
2015-03-14 21:48:35 +00:00
.98 pla get back Token hMem
jsr S.FreeMemA discard Token
.99 sec
rts
*--------------------------------------
2016-06-07 06:10:18 +00:00
S.PStrGetTkn.SEP .BS 1
S.PStrGetTkn.IDX .BS 1
S.PStrGetTkn.START .BS 1
S.PStrGetTkn.END .BS 1
*--------------------------------------
2016-05-01 21:13:54 +00:00
S.GetArgCount
clc
rts
*--------------------------------------
S.GetArgA
clc
rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
SAVE SYS/KERNEL.S.STR
LOAD SYS/KERNEL.S
ASM