2017-12-22 21:24:30 +00:00
|
|
|
|
NEW
|
2017-08-23 15:05:29 +00:00
|
|
|
|
PREFIX /A2OSX.BUILD
|
2017-12-22 21:24:30 +00:00
|
|
|
|
AUTO 4,1
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # StrLen
|
2017-08-24 06:47:31 +00:00
|
|
|
|
* Returns Length of C-String
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* ## C
|
2018-06-19 15:08:22 +00:00
|
|
|
|
* `int strlen ( char * str);`
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* ## ASM
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-06-19 15:08:22 +00:00
|
|
|
|
* `>LDYAI str`
|
|
|
|
|
* `>SYSCALL strlen`
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* Y,A = String length
|
2017-08-24 06:47:31 +00:00
|
|
|
|
*\--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
K.StrLen >STYA ZPPtr1
|
2017-08-24 06:47:31 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
ldx #0
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtr1),y
|
|
|
|
|
beq .8
|
|
|
|
|
iny
|
|
|
|
|
bne .1
|
|
|
|
|
inx
|
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.8 txa
|
|
|
|
|
rts
|
|
|
|
|
*/--------------------------------------
|
2017-08-23 15:05:29 +00:00
|
|
|
|
* # StrCat
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* Concatenate strings
|
|
|
|
|
* ## C
|
|
|
|
|
* `char * strcat ( char * destination, const char * source );`
|
|
|
|
|
* ## ASM
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* `>PUSHWI source`
|
|
|
|
|
* `>LDYAI destination`
|
|
|
|
|
* `>SYSCALL strcat`
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* Y,A = destination
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*\--------------------------------------
|
2018-06-18 08:44:02 +00:00
|
|
|
|
K.StrCat sec
|
|
|
|
|
.HS 90 BCC
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrCpy
|
|
|
|
|
* Copy string
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* ## C
|
|
|
|
|
* `char * strcpy ( char * destination, const char * source );`
|
|
|
|
|
* ## ASM
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* `>PUSHWI source`
|
|
|
|
|
* `>LDYAI destination`
|
|
|
|
|
* `>SYSCALL strcpy`
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* Y,A = destination
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*\--------------------------------------
|
2018-06-18 08:44:02 +00:00
|
|
|
|
K.StrCpy clc
|
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
>PULLW ZPPtr2
|
|
|
|
|
|
|
|
|
|
bcc .2
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtr1)
|
|
|
|
|
beq .2
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
2018-06-18 08:44:02 +00:00
|
|
|
|
inc ZPPtr1
|
|
|
|
|
bne .1
|
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.2 ldy #0
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
2018-06-18 08:44:02 +00:00
|
|
|
|
.3 lda (ZPPtr2),y
|
2017-08-23 15:05:29 +00:00
|
|
|
|
sta (ZPPtr1),y
|
|
|
|
|
beq .8
|
|
|
|
|
iny
|
2018-06-18 08:44:02 +00:00
|
|
|
|
bne .3
|
2017-08-23 15:05:29 +00:00
|
|
|
|
inc ZPPtr2+1
|
|
|
|
|
inc ZPPtr1+1
|
2018-06-18 08:44:02 +00:00
|
|
|
|
bra .3
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
.8 rts
|
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrMatch
|
|
|
|
|
* Compare a String against pattern
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2017-08-23 15:05:29 +00:00
|
|
|
|
* PUSHW = PTR to Pattern (e.g. '*test?.txt')
|
|
|
|
|
* PUSHW = PTR to Src String
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2017-08-23 15:05:29 +00:00
|
|
|
|
* CC : match
|
|
|
|
|
* CS : no match
|
|
|
|
|
*\--------------------------------------
|
2018-04-29 19:10:13 +00:00
|
|
|
|
K.StrMatch jsr MEM.PullP1P2
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
lda (ZPPtr2) Get pattern 1st byte
|
|
|
|
|
beq .8 Match always if empty
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
bra .21
|
|
|
|
|
|
2017-10-03 15:33:30 +00:00
|
|
|
|
.1 inc ZPPtr2 Make PTR2 (pattern) advance to next char
|
2017-08-23 15:05:29 +00:00
|
|
|
|
bne .2
|
|
|
|
|
inc ZPPtr2+1
|
|
|
|
|
|
|
|
|
|
.2 lda (ZPPtr2) get pattern char
|
2017-10-03 15:33:30 +00:00
|
|
|
|
beq .41 end of pattern...
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
.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
|
|
|
|
|
|
2017-10-03 15:33:30 +00:00
|
|
|
|
.4 iny advance to next char to compare
|
|
|
|
|
bra .1 continue if remaining char in pattern
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
.41 lda (ZPPtr1),y end of pattern, but end of string ?
|
|
|
|
|
|
|
|
|
|
beq .8 yes, string matched entirely
|
2017-10-03 15:33:30 +00:00
|
|
|
|
* no, remaining char in string, no match
|
|
|
|
|
.9 sec
|
|
|
|
|
rts
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
.5 inc ZPPtr2 Make PTR2 advance to next char
|
|
|
|
|
bne .6
|
|
|
|
|
inc ZPPtr2+1
|
2017-10-03 15:33:30 +00:00
|
|
|
|
|
|
|
|
|
.6 lda (ZPPtr2) we have '*', last char of pattern ?
|
2017-08-23 15:05:29 +00:00
|
|
|
|
beq .8 yes, match everything, including empty string
|
|
|
|
|
|
2017-10-03 15:33:30 +00:00
|
|
|
|
lda (ZPPtr2) get next char of pattern
|
2017-08-23 15:05:29 +00:00
|
|
|
|
cmp #'*' another '*' ?
|
|
|
|
|
beq .5 yes, '**' = '*', go next char
|
2017-10-03 15:33:30 +00:00
|
|
|
|
cmp #'?' '*?' ? we must match a least one char
|
2017-08-23 15:05:29 +00:00
|
|
|
|
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
|
|
|
|
|
|
2017-10-03 15:33:30 +00:00
|
|
|
|
iny
|
|
|
|
|
bra .1 go check remaining char in pattern...
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # StrUpr/StrLwr
|
2017-08-23 15:05:29 +00:00
|
|
|
|
* Convert string to UPPERCASE/lowercase
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* Y,A = PTR to String (CSTR)
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* Uppercased/lowercased String in Buffer
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*\--------------------------------------
|
2018-06-22 14:59:24 +00:00
|
|
|
|
K.StrUpr ldx #0
|
2017-08-23 15:05:29 +00:00
|
|
|
|
.HS 2C bit abs
|
2018-06-22 14:59:24 +00:00
|
|
|
|
K.StrLwr ldx #2
|
2017-08-23 15:05:29 +00:00
|
|
|
|
>STYA ZPPtr1
|
|
|
|
|
|
|
|
|
|
pha save Y,A to restore them at exit
|
|
|
|
|
phy
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtr1),y
|
|
|
|
|
beq .8
|
|
|
|
|
|
2017-08-24 12:46:48 +00:00
|
|
|
|
cmp .9,x
|
2017-08-23 15:05:29 +00:00
|
|
|
|
bcc .2
|
2017-08-24 12:46:48 +00:00
|
|
|
|
cmp .9+1,x
|
2017-08-23 15:05:29 +00:00
|
|
|
|
bcs .2
|
|
|
|
|
eor #$20
|
|
|
|
|
sta (ZPPtr1),y
|
|
|
|
|
.2 iny
|
|
|
|
|
bne .1
|
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.8 ply
|
|
|
|
|
pla
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2017-08-24 12:46:48 +00:00
|
|
|
|
.9 .AS "azAZ"
|
2018-01-15 16:51:44 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrCmp
|
|
|
|
|
* Compare 2 strings
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-01-15 16:51:44 +00:00
|
|
|
|
* PUSHW = Ptr to String1 (CSTR)
|
|
|
|
|
* PUSHW = Ptr to String2 (CSTR)
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2018-01-15 16:51:44 +00:00
|
|
|
|
* DST = SRC
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
K.StrCmp sec
|
|
|
|
|
.HS 90 BCC
|
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrICmp
|
|
|
|
|
* Compare 2 strings
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-01-15 16:51:44 +00:00
|
|
|
|
* PUSHW = Ptr to String1 (CSTR)
|
|
|
|
|
* PUSHW = Ptr to String2 (CSTR)
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **Out:**
|
2018-01-15 16:51:44 +00:00
|
|
|
|
* CC, Y,A=0
|
|
|
|
|
* CS, Y,A > 0 or < 0
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
K.StrICmp clc
|
2018-04-29 19:10:13 +00:00
|
|
|
|
jsr MEM.PullP1P2
|
2018-01-15 16:51:44 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtr1),y
|
|
|
|
|
beq .7
|
|
|
|
|
jsr K.StrICmp.toUpper
|
2018-01-19 07:14:38 +00:00
|
|
|
|
sta .2+1
|
2018-01-15 16:51:44 +00:00
|
|
|
|
|
|
|
|
|
lda (ZPPtr2),y
|
|
|
|
|
beq .9
|
|
|
|
|
jsr K.StrICmp.toUpper
|
|
|
|
|
|
|
|
|
|
.2 eor #$ff SELF MODIFIED
|
|
|
|
|
bne .9
|
|
|
|
|
iny
|
|
|
|
|
bne .1
|
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
inc ZPPtr2+1
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.7 lda (ZPPtr2),y
|
|
|
|
|
bne .9
|
|
|
|
|
tay
|
|
|
|
|
|
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.9 sec
|
|
|
|
|
|
|
|
|
|
lda (ZPPtr1),y
|
|
|
|
|
sbc (ZPPtr2),y
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
K.StrICmp.toUpper
|
|
|
|
|
bcs .9
|
|
|
|
|
php
|
|
|
|
|
|
|
|
|
|
cmp #'a'
|
|
|
|
|
bcc .1
|
|
|
|
|
cmp #'z'+1
|
|
|
|
|
bcs .1
|
|
|
|
|
eor #$20
|
|
|
|
|
|
|
|
|
|
.1 plp
|
|
|
|
|
.9 rts
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MAN
|
|
|
|
|
SAVE /A2OSX.SRC/SYS/KERNEL.S.STRING
|
|
|
|
|
LOAD /A2OSX.SRC/SYS/KERNEL.S
|
|
|
|
|
ASM
|