A2osX/SYS/KERNEL.S.STRING.txt

187 lines
4.5 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*/--------------------------------------
* # StrLen.YA
* Returns Length of C-String
* ## In:
* Y,A = Ptr to CSTR
* ## Out:
* Y,A = String length
*\--------------------------------------
K.StrLen.YA >STYA ZPPtr1
ldy #0
ldx #0
.1 lda (ZPPtr1),y
beq .8
iny
bne .1
inx
inc ZPPtr1+1
bra .1
.8 txa
rts
*/--------------------------------------
* # StrCat
* Append SRC to DST
* ## In:
* PUSHW = Ptr to SRC (CSTR)
* PUSHW = Ptr to DST (CSTR)
* ## Out:
* DST = DST+SRC
*\--------------------------------------
K.StrCat jsr PullPtr1Ptr2
.1 lda (ZPPtr1)
beq K.StrCpy.I
inc ZPPtr1
bne .1
inc ZPPtr1+1
bra .1
*/--------------------------------------
* # StrCpy
* Copy string
* ## In:
* PUSHW = Ptr to SRC (CSTR)
* PUSHW = Ptr to DST (CSTR)
* ## Out:
* DST = SRC
*\--------------------------------------
K.StrCpy jsr PullPtr1Ptr2
K.StrCpy.I ldy #0
.1 lda (ZPPtr2),y
sta (ZPPtr1),y
beq .8
iny
bne .1
inc ZPPtr2+1
inc ZPPtr1+1
bra .1
.8 rts
*/--------------------------------------
* # StrMatch
* Compare a String against pattern
* ## In:
* PUSHW = PTR to Pattern (e.g. '*test?.txt')
* PUSHW = PTR to Src String
* ## Out:
* CC : match
* CS : no match
*\--------------------------------------
K.StrMatch jsr PullPtr1Ptr2
lda (ZPPtr2) Get pattern 1st byte
beq .8 Match always if empty
ldy #0
bra .21
.1 inc ZPPtr2 Make PTR2 advance to next char
bne .2
inc ZPPtr2+1
.2 lda (ZPPtr2) get pattern char
beq .41
.21 cmp #'*'
beq .5
.3 lda (ZPPtr1) we must match ? or regular char, check if at end of string
beq .9 no char left, exit with error
lda (ZPPtr2) get back pattern char
cmp #'?'
beq .4 no need to compare, any char will match
cmp (ZPPtr1),y Regular Char, compare with string at Y
bne .9 no match, exit
iny advance to next char to compare
.4 dex char matched, check if end of pattern
bne .1 continue if remaining char in pattern
.41 lda (ZPPtr1),y end of pattern, but end of string ?
beq .8 yes, string matched entirely
bra .9 no, remaining char in string, no match
.5 inc ZPPtr2 Make PTR2 advance to next char
bne .6
inc ZPPtr2+1
lda (ZPPtr2) we have '*', last char of pattern ?
beq .8 yes, match everything, including empty string
.6 lda (ZPPtr2) get next char of pattern
cmp #'*' another '*' ?
beq .5 yes, '**' = '*', go next char
cmp #'?' '*?' ??? we must match a least one char
beq .3
.7 lda (ZPPtr1),y we need at least one remaining char in string, check if at end of string
beq .9 no chance to match ? or regular char
iny
lda (ZPPtr2) get again char in pattern
cmp (ZPPtr1),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
*/--------------------------------------
* # StrUpr.YA/StrLwr.YA
* Convert string to UPPERCASE/lowercase
* ## In:
* Y,A = PTR to String (CSTR)
* ## Out:
* Uppercased/lowercased String in Buffer
*\--------------------------------------
K.StrUpr.YA ldx #0
.HS 2C bit abs
K.StrLwr.YA ldx #2
>STYA ZPPtr1
pha save Y,A to restore them at exit
phy
ldy #0
.1 lda (ZPPtr1),y
beq .8
cmp .9,x
bcc .2
cmp .9+1,x
bcs .2
eor #$20
sta (ZPPtr1),y
.2 iny
bne .1
inc ZPPtr1+1
bra .1
.8 ply
pla
rts
*--------------------------------------
.9 .AS "azAZ"
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.STRING
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM