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
|
2021-04-29 11:56:34 +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
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-24 06:47:31 +00:00
|
|
|
|
iny
|
|
|
|
|
bne .1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-10-12 15:47:57 +00:00
|
|
|
|
inc
|
|
|
|
|
inc .1+2
|
2017-08-24 06:47:31 +00:00
|
|
|
|
bra .1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
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
|
2021-05-04 17:31:21 +00:00
|
|
|
|
* `>PUSHWI destination`
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* `>PUSHWI source`
|
|
|
|
|
* `>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
|
2021-05-04 17:31:21 +00:00
|
|
|
|
* `>PUSHWI destination`
|
2018-06-18 08:44:02 +00:00
|
|
|
|
* `>PUSHWI source`
|
|
|
|
|
* `>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
|
|
|
|
phy
|
2020-06-05 19:26:34 +00:00
|
|
|
|
pha
|
2021-05-04 17:31:21 +00:00
|
|
|
|
jsr SHARED.PullP2P1
|
2018-06-18 08:44:02 +00:00
|
|
|
|
|
|
|
|
|
bcc .2
|
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.1 jsr SHARED.GetCP1
|
2018-06-18 08:44:02 +00:00
|
|
|
|
bne .1
|
2019-10-03 06:25:27 +00:00
|
|
|
|
|
2018-06-18 08:44:02 +00:00
|
|
|
|
.2 ldy #0
|
2021-04-29 11:56:34 +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
|
2019-07-17 15:49:23 +00:00
|
|
|
|
beq K.StrDup.8
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
iny
|
2018-06-18 08:44:02 +00:00
|
|
|
|
bne .3
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
inc ZPPtr2+1
|
|
|
|
|
inc ZPPtr1+1
|
2018-06-18 08:44:02 +00:00
|
|
|
|
bra .3
|
2018-12-20 16:23:43 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # StrDup
|
|
|
|
|
* Create a new copy of this C-String
|
2020-08-02 12:19:43 +00:00
|
|
|
|
* ## C
|
|
|
|
|
* `char * strdup ( char * str);`
|
|
|
|
|
* ## ASM
|
2018-12-20 16:23:43 +00:00
|
|
|
|
* Y,A = Ptr to source C-String
|
|
|
|
|
* CC : success
|
|
|
|
|
* Y,A = PTR to String
|
2019-11-25 07:05:07 +00:00
|
|
|
|
* X = hMem (C-String)
|
2018-12-20 16:23:43 +00:00
|
|
|
|
* CS : error
|
|
|
|
|
* A = SYS error code
|
|
|
|
|
*\--------------------------------------
|
2021-08-01 13:45:15 +00:00
|
|
|
|
STRING.DupBuf256
|
|
|
|
|
>LDYAI K.Buf256
|
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
K.StrDup >STYA .1+1
|
|
|
|
|
>STYA .4+1
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
lda #0
|
2019-07-19 06:41:33 +00:00
|
|
|
|
tay
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
.1 ldx $ffff,y
|
|
|
|
|
beq .2
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
iny
|
|
|
|
|
bne .1
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
inc
|
|
|
|
|
inc .1+2
|
|
|
|
|
bne .1
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
.2 iny Add one for ending 0
|
|
|
|
|
bne .3
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
inc
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
.3 jsr K.GetMem
|
2019-07-17 15:49:23 +00:00
|
|
|
|
bcs K.StrDup.RTS
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
>STYA .5+1
|
|
|
|
|
phy
|
|
|
|
|
pha
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
ldy #0
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
|
|
|
|
.4 lda $ffff,y
|
2018-12-20 16:23:43 +00:00
|
|
|
|
.5 sta $ffff,y
|
|
|
|
|
beq K.StrDup.8
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
iny
|
|
|
|
|
bne .4
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
inc .4+2
|
|
|
|
|
inc .5+2
|
|
|
|
|
bne .4
|
2019-10-12 14:20:09 +00:00
|
|
|
|
|
2018-12-20 16:23:43 +00:00
|
|
|
|
K.StrDup.8 pla
|
|
|
|
|
ply
|
2019-05-04 21:13:50 +00:00
|
|
|
|
clc
|
2019-10-03 06:25:27 +00:00
|
|
|
|
K.StrDup.RTS 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
|
|
|
|
|
* `>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
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
ldy #0
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
.1 lda (ZPPtr1),y
|
2018-12-20 16:23:43 +00:00
|
|
|
|
beq K.StrDup.8
|
2023-05-30 17:13:23 +00:00
|
|
|
|
|
2017-08-24 12:46:48 +00:00
|
|
|
|
cmp .9,x
|
2017-08-23 15:05:29 +00:00
|
|
|
|
bcc .2
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-24 12:46:48 +00:00
|
|
|
|
cmp .9+1,x
|
2017-08-23 15:05:29 +00:00
|
|
|
|
bcs .2
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
eor #$20
|
|
|
|
|
sta (ZPPtr1),y
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
.2 iny
|
|
|
|
|
bne .1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2017-08-23 15:05:29 +00:00
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
bra .1
|
|
|
|
|
*--------------------------------------
|
2023-05-30 17:13:23 +00:00
|
|
|
|
.9 .AS "a{A["
|
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
|
2021-05-04 17:31:21 +00:00
|
|
|
|
* `>PUSHWI s1`
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* `>PUSHWI s2`
|
|
|
|
|
* `>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
|
2021-05-04 17:31:21 +00:00
|
|
|
|
* `>PUSHWI s1`
|
2018-09-06 12:27:37 +00:00
|
|
|
|
* `>PUSHWI s2`
|
|
|
|
|
* `>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
|
2021-05-04 17:31:21 +00:00
|
|
|
|
jsr SHARED.PullP2P1
|
2018-01-15 16:51:44 +00:00
|
|
|
|
|
|
|
|
|
ldy #0
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
.1 lda (ZPPtr1),y
|
|
|
|
|
beq .7
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
jsr .80
|
2018-01-19 07:14:38 +00:00
|
|
|
|
sta .2+1
|
2018-01-15 16:51:44 +00:00
|
|
|
|
lda (ZPPtr2),y
|
|
|
|
|
beq .9
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
jsr .80
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
.2 eor #$ff SELF MODIFIED
|
|
|
|
|
bne .9
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
iny
|
|
|
|
|
bne .1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
inc ZPPtr1+1
|
|
|
|
|
inc ZPPtr2+1
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.7 lda (ZPPtr2),y
|
|
|
|
|
bne .9
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
tay
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
.8 clc
|
|
|
|
|
rts
|
|
|
|
|
.9 sec
|
|
|
|
|
|
|
|
|
|
lda (ZPPtr1),y
|
|
|
|
|
sbc (ZPPtr2),y
|
|
|
|
|
ldy #0
|
2019-10-03 06:25:27 +00:00
|
|
|
|
sec
|
2018-01-15 16:51:44 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.80 bcs .99
|
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
cmp #'a'
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bcc .99
|
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
cmp #'z'+1
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bcs .81
|
|
|
|
|
|
2018-01-15 16:51:44 +00:00
|
|
|
|
eor #$20
|
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.81 clc
|
2018-09-06 12:27:37 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.99 rts
|
2020-07-02 21:17:57 +00:00
|
|
|
|
*--------------------------------------
|
2017-08-23 15:05:29 +00:00
|
|
|
|
MAN
|
2020-12-15 13:23:22 +00:00
|
|
|
|
SAVE usr/src/sys/kernel.s.string
|
|
|
|
|
LOAD usr/src/sys/kernel.s
|
2017-08-23 15:05:29 +00:00
|
|
|
|
ASM
|