2017-12-22 21:24:30 +00:00
|
|
|
|
NEW
|
2019-05-25 19:24:07 +00:00
|
|
|
|
AUTO 3,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-19 15:08:22 +00:00
|
|
|
|
* `>LDYAI str`
|
|
|
|
|
* `>SYSCALL strlen`
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* Y,A = String length
|
2017-08-24 06:47:31 +00:00
|
|
|
|
*\--------------------------------------
|
2018-10-12 15:47:57 +00:00
|
|
|
|
K.StrLen >STYA .1+1
|
2017-08-24 06:47:31 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
2018-10-12 15:47:57 +00:00
|
|
|
|
tya
|
2017-08-24 06:47:31 +00:00
|
|
|
|
|
2018-10-12 15:47:57 +00:00
|
|
|
|
.1 ldx $ffff,y SELF MODIFIED
|
2017-08-24 06:47:31 +00:00
|
|
|
|
beq .8
|
|
|
|
|
iny
|
|
|
|
|
bne .1
|
2018-10-12 15:47:57 +00:00
|
|
|
|
inc
|
|
|
|
|
inc .1+2
|
2017-08-24 06:47:31 +00:00
|
|
|
|
bra .1
|
|
|
|
|
|
2019-05-04 21:13:50 +00:00
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
2017-08-24 06:47:31 +00:00
|
|
|
|
*/--------------------------------------
|
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-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
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-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
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
|
2018-11-21 13:08:11 +00:00
|
|
|
|
pha
|
|
|
|
|
phy
|
|
|
|
|
|
2018-10-11 15:23:06 +00:00
|
|
|
|
jsr MEM.SPtr1PPtr2
|
2018-06-18 08:44:02 +00:00
|
|
|
|
|
|
|
|
|
bcc .2
|
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
.1 jsr MEM.GetCharPtr1
|
2018-06-18 08:44:02 +00:00
|
|
|
|
bne .1
|
2018-12-20 16:23:43 +00:00
|
|
|
|
|
2018-06-18 08:44:02 +00:00
|
|
|
|
.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
|
|
|
|
|
2018-11-21 13:08:11 +00:00
|
|
|
|
.8 ply
|
|
|
|
|
pla
|
2019-05-04 21:13:50 +00:00
|
|
|
|
K.StrCpy.RTS clc
|
|
|
|
|
rts
|
2018-12-20 16:23:43 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrDup
|
|
|
|
|
* Create a new copy of this C-String
|
|
|
|
|
* Y,A = Ptr to source C-String
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* CC : success
|
|
|
|
|
* Y,A = PTR to String
|
|
|
|
|
* X = hMem (PSTR)
|
|
|
|
|
* CS : error
|
|
|
|
|
* A = SYS error code
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
K.StrDup >STYA .1+1
|
|
|
|
|
>STYA .4+1
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
lda #0
|
|
|
|
|
|
|
|
|
|
.1 ldx $ffff,y
|
|
|
|
|
beq .2
|
|
|
|
|
iny
|
|
|
|
|
bne .1
|
|
|
|
|
inc
|
|
|
|
|
inc .1+2
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
.2 iny Add one for ending 0
|
|
|
|
|
bne .3
|
|
|
|
|
inc
|
|
|
|
|
|
|
|
|
|
.3 jsr K.GetMem
|
|
|
|
|
bcs K.StrCpy.RTS
|
|
|
|
|
>STYA .5+1
|
|
|
|
|
|
|
|
|
|
phy
|
|
|
|
|
pha
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.4 lda $ffff,y
|
|
|
|
|
.5 sta $ffff,y
|
|
|
|
|
beq K.StrDup.8
|
|
|
|
|
iny
|
|
|
|
|
bne .4
|
|
|
|
|
|
|
|
|
|
inc .4+2
|
|
|
|
|
inc .5+2
|
|
|
|
|
bne .4
|
|
|
|
|
|
|
|
|
|
K.StrDup.8 pla
|
|
|
|
|
ply
|
2019-05-04 21:13:50 +00:00
|
|
|
|
clc
|
2018-12-20 16:23:43 +00:00
|
|
|
|
rts
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # StrUpr/StrLwr
|
2017-08-23 15:05:29 +00:00
|
|
|
|
* Convert string to UPPERCASE/lowercase
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* ## C
|
|
|
|
|
* `int strupr ( char * str);`
|
|
|
|
|
* `int strlwr ( char * str);`
|
|
|
|
|
* ## ASM
|
|
|
|
|
* **In:**
|
|
|
|
|
* `>LDYAI str`
|
|
|
|
|
* `>SYSCALL strupr`
|
|
|
|
|
* `>SYSCALL strlwr`
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* Uppercased/lowercased String in Buffer
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* Y,A = str
|
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
|
|
|
|
|
|
|
|
|
|
phy
|
2018-12-20 16:23:43 +00:00
|
|
|
|
pha save Y,A to restore them at exit
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtr1),y
|
2018-12-20 16:23:43 +00:00
|
|
|
|
beq K.StrDup.8
|
2017-08-23 15:05:29 +00:00
|
|
|
|
|
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
|
|
|
|
|
*--------------------------------------
|
2017-08-24 12:46:48 +00:00
|
|
|
|
.9 .AS "azAZ"
|
2018-01-15 16:51:44 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrCmp
|
|
|
|
|
* Compare 2 strings
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* ## C
|
|
|
|
|
* `int strcmp(const char *s1, const char *s2);`
|
|
|
|
|
* ## ASM
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* `>PUSHWI s2`
|
|
|
|
|
* `>LDYAI s1`
|
|
|
|
|
* `>SYSCALL strcmp`
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* CC : match
|
|
|
|
|
* CS : no match
|
|
|
|
|
* CC, Y,A=0
|
|
|
|
|
* CS, Y,A > 0 or < 0
|
2018-01-15 16:51:44 +00:00
|
|
|
|
*\--------------------------------------
|
|
|
|
|
K.StrCmp sec
|
|
|
|
|
.HS 90 BCC
|
|
|
|
|
*/--------------------------------------
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* # StrCaseCmp
|
|
|
|
|
* Compare 2 strings, ignoring case
|
|
|
|
|
* ## C
|
|
|
|
|
* `int strcasecmp(const char *s1, const char *s2);`
|
|
|
|
|
* ## ASM
|
2018-06-14 15:31:36 +00:00
|
|
|
|
* **In:**
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* `>PUSHWI s2`
|
|
|
|
|
* `>LDYAI s1`
|
|
|
|
|
* `>SYSCALL strcasecmp`
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* CC : match
|
|
|
|
|
* CS : no match
|
2018-01-15 16:51:44 +00:00
|
|
|
|
* CC, Y,A=0
|
|
|
|
|
* CS, Y,A > 0 or < 0
|
|
|
|
|
*\--------------------------------------
|
2018-09-06 12:27:37 +00:00
|
|
|
|
K.StrCaseCmp clc
|
2018-10-11 15:23:06 +00:00
|
|
|
|
jsr MEM.SPtr1PPtr2
|
2018-01-15 16:51:44 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPPtr1),y
|
|
|
|
|
beq .7
|
2018-09-06 12:27:37 +00:00
|
|
|
|
jsr K.StrCaseCmp.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
|
2018-09-06 12:27:37 +00:00
|
|
|
|
jsr K.StrCaseCmp.toUpper
|
2018-01-15 16:51:44 +00:00
|
|
|
|
|
|
|
|
|
.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
|
|
|
|
|
*--------------------------------------
|
2018-09-06 12:27:37 +00:00
|
|
|
|
K.StrCaseCmp.toUpper
|
2018-01-15 16:51:44 +00:00
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
cmp #'a'
|
2018-09-06 12:27:37 +00:00
|
|
|
|
bcc .9
|
2018-01-15 16:51:44 +00:00
|
|
|
|
cmp #'z'+1
|
|
|
|
|
bcs .1
|
|
|
|
|
eor #$20
|
|
|
|
|
|
2018-09-06 12:27:37 +00:00
|
|
|
|
.1 clc
|
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
.9 rts
|
2017-08-23 15:05:29 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MAN
|
2018-11-17 17:17:13 +00:00
|
|
|
|
SAVE USR/SRC/SYS/KERNEL.S.STRING
|
|
|
|
|
LOAD USR/SRC/SYS/KERNEL.S
|
2017-08-23 15:05:29 +00:00
|
|
|
|
ASM
|