A2osX/SYS/KERNEL.S.STRING.txt

272 lines
4.3 KiB
Plaintext
Raw Normal View History

2017-12-22 22:24:30 +01:00
NEW
2019-05-25 21:24:07 +02:00
AUTO 3,1
*/--------------------------------------
2018-06-18 08:22:50 +02:00
* # StrLen
* Returns Length of C-String
2018-06-18 08:22:50 +02:00
* ## C
2018-06-19 17:08:22 +02:00
* `int strlen ( char * str);`
2018-06-18 08:22:50 +02:00
* ## ASM
2018-06-19 17:08:22 +02:00
* `>LDYAI str`
* `>SYSCALL strlen`
2018-10-11 17:23:06 +02:00
* ## RETURN VALUE
2018-06-18 08:22:50 +02:00
* Y,A = String length
*\--------------------------------------
2018-10-12 17:47:57 +02:00
K.StrLen >STYA .1+1
ldy #0
2018-10-12 17:47:57 +02:00
tya
2021-04-29 13:56:34 +02:00
2018-10-12 17:47:57 +02:00
.1 ldx $ffff,y SELF MODIFIED
beq .8
2021-04-29 13:56:34 +02:00
iny
bne .1
2021-04-29 13:56:34 +02:00
2018-10-12 17:47:57 +02:00
inc
inc .1+2
bra .1
2021-04-29 13:56:34 +02:00
2019-05-04 23:13:50 +02:00
.8 clc
rts
*/--------------------------------------
* # StrCat
2018-06-18 10:44:02 +02:00
* Concatenate strings
* ## C
* `char * strcat ( char * destination, const char * source );`
* ## ASM
2021-05-04 19:31:21 +02:00
* `>PUSHWI destination`
2018-06-18 10:44:02 +02:00
* `>PUSHWI source`
* `>SYSCALL strcat`
2018-10-11 17:23:06 +02:00
* ## RETURN VALUE
2018-06-18 10:44:02 +02:00
* Y,A = destination
*\--------------------------------------
2018-06-18 10:44:02 +02:00
K.StrCat sec
.HS 90 BCC
*/--------------------------------------
* # StrCpy
* Copy string
2018-06-18 08:22:50 +02:00
* ## C
* `char * strcpy ( char * destination, const char * source );`
* ## ASM
2021-05-04 19:31:21 +02:00
* `>PUSHWI destination`
2018-06-18 10:44:02 +02:00
* `>PUSHWI source`
* `>SYSCALL strcpy`
2018-10-11 17:23:06 +02:00
* ## RETURN VALUE
2018-06-18 10:44:02 +02:00
* Y,A = destination
*\--------------------------------------
2018-06-18 10:44:02 +02:00
K.StrCpy clc
2018-11-21 14:08:11 +01:00
phy
2020-06-05 21:26:34 +02:00
pha
2021-05-04 19:31:21 +02:00
jsr SHARED.PullP2P1
2018-06-18 10:44:02 +02:00
bcc .2
2021-05-04 19:31:21 +02:00
.1 jsr SHARED.GetCP1
2018-06-18 10:44:02 +02:00
bne .1
2019-10-03 08:25:27 +02:00
2018-06-18 10:44:02 +02:00
.2 ldy #0
2021-04-29 13:56:34 +02:00
2018-06-18 10:44:02 +02:00
.3 lda (ZPPtr2),y
sta (ZPPtr1),y
2019-07-17 17:49:23 +02:00
beq K.StrDup.8
2021-04-29 13:56:34 +02:00
iny
2018-06-18 10:44:02 +02:00
bne .3
2021-04-29 13:56:34 +02:00
inc ZPPtr2+1
inc ZPPtr1+1
2018-06-18 10:44:02 +02:00
bra .3
2018-12-20 17:23:43 +01:00
*/--------------------------------------
* # StrDup
* Create a new copy of this C-String
2020-08-02 14:19:43 +02:00
* ## C
* `char * strdup ( char * str);`
* ## ASM
2018-12-20 17:23:43 +01:00
* Y,A = Ptr to source C-String
* CC : success
* Y,A = PTR to String
2019-11-25 08:05:07 +01:00
* X = hMem (C-String)
2018-12-20 17:23:43 +01:00
* CS : error
* A = SYS error code
*\--------------------------------------
STRING.DupBuf256
>LDYAI K.Buf256
2018-12-20 17:23:43 +01:00
K.StrDup >STYA .1+1
>STYA .4+1
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
lda #0
2019-07-19 08:41:33 +02:00
tay
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
.1 ldx $ffff,y
beq .2
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
iny
bne .1
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
inc
inc .1+2
bne .1
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
.2 iny Add one for ending 0
bne .3
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
inc
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
.3 jsr K.GetMem
2019-07-17 17:49:23 +02:00
bcs K.StrDup.RTS
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
>STYA .5+1
phy
pha
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
ldy #0
2019-10-12 16:20:09 +02:00
.4 lda $ffff,y
2018-12-20 17:23:43 +01:00
.5 sta $ffff,y
beq K.StrDup.8
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
iny
bne .4
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
inc .4+2
inc .5+2
bne .4
2019-10-12 16:20:09 +02:00
2018-12-20 17:23:43 +01:00
K.StrDup.8 pla
ply
2019-05-04 23:13:50 +02:00
clc
2019-10-03 08:25:27 +02:00
K.StrDup.RTS rts
*/--------------------------------------
2018-06-18 08:22:50 +02:00
* # StrUpr/StrLwr
* Convert string to UPPERCASE/lowercase
2018-09-06 14:27:37 +02:00
* ## C
* `int strupr ( char * str);`
* `int strlwr ( char * str);`
* ## ASM
* `>LDYAI str`
* `>SYSCALL strupr`
* `>SYSCALL strlwr`
2018-10-11 17:23:06 +02:00
* ## RETURN VALUE
2018-06-18 08:22:50 +02:00
* Uppercased/lowercased String in Buffer
2018-09-06 14:27:37 +02:00
* Y,A = str
*\--------------------------------------
2018-06-22 16:59:24 +02:00
K.StrUpr ldx #0
.HS 2C bit abs
2018-06-22 16:59:24 +02:00
K.StrLwr ldx #2
>STYA ZPPtr1
phy
2018-12-20 17:23:43 +01:00
pha save Y,A to restore them at exit
2021-04-29 13:56:34 +02:00
ldy #0
2021-04-29 13:56:34 +02:00
.1 lda (ZPPtr1),y
2018-12-20 17:23:43 +01:00
beq K.StrDup.8
2023-05-30 19:13:23 +02:00
cmp .9,x
bcc .2
2021-04-29 13:56:34 +02:00
cmp .9+1,x
bcs .2
2021-04-29 13:56:34 +02:00
eor #$20
sta (ZPPtr1),y
2021-04-29 13:56:34 +02:00
.2 iny
bne .1
2021-04-29 13:56:34 +02:00
inc ZPPtr1+1
bra .1
*--------------------------------------
2023-05-30 19:13:23 +02:00
.9 .AS "a{A["
2018-01-15 16:51:44 +00:00
*/--------------------------------------
* # StrCmp
* Compare 2 strings
2018-09-06 14:27:37 +02:00
* ## C
* `int strcmp(const char *s1, const char *s2);`
* ## ASM
2021-05-04 19:31:21 +02:00
* `>PUSHWI s1`
2018-09-06 14:27:37 +02:00
* `>PUSHWI s2`
* `>SYSCALL strcmp`
2018-10-11 17:23:06 +02:00
* ## RETURN VALUE
2018-09-06 14:27:37 +02: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 14:27:37 +02:00
* # StrCaseCmp
* Compare 2 strings, ignoring case
* ## C
* `int strcasecmp(const char *s1, const char *s2);`
* ## ASM
2021-05-04 19:31:21 +02:00
* `>PUSHWI s1`
2018-09-06 14:27:37 +02:00
* `>PUSHWI s2`
* `>SYSCALL strcasecmp`
2018-10-11 17:23:06 +02:00
* ## RETURN VALUE
2018-09-06 14:27:37 +02: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 14:27:37 +02:00
K.StrCaseCmp clc
2021-05-04 19:31:21 +02:00
jsr SHARED.PullP2P1
2018-01-15 16:51:44 +00:00
ldy #0
2021-04-29 13:56:34 +02:00
2018-01-15 16:51:44 +00:00
.1 lda (ZPPtr1),y
beq .7
2021-04-29 13:56:34 +02:00
2021-05-04 19:31:21 +02:00
jsr .80
sta .2+1
2018-01-15 16:51:44 +00:00
lda (ZPPtr2),y
beq .9
2021-04-29 13:56:34 +02:00
2021-05-04 19:31:21 +02:00
jsr .80
2021-04-29 13:56:34 +02:00
2018-01-15 16:51:44 +00:00
.2 eor #$ff SELF MODIFIED
bne .9
2021-04-29 13:56:34 +02:00
2018-01-15 16:51:44 +00:00
iny
bne .1
2021-04-29 13:56:34 +02: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 13:56:34 +02:00
2018-01-15 16:51:44 +00:00
tay
2021-04-29 13:56:34 +02: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 08:25:27 +02:00
sec
2018-01-15 16:51:44 +00:00
rts
*--------------------------------------
2021-05-04 19:31:21 +02:00
.80 bcs .99
2018-01-15 16:51:44 +00:00
cmp #'a'
2021-05-04 19:31:21 +02:00
bcc .99
2018-01-15 16:51:44 +00:00
cmp #'z'+1
2021-05-04 19:31:21 +02:00
bcs .81
2018-01-15 16:51:44 +00:00
eor #$20
2021-05-04 19:31:21 +02:00
.81 clc
2018-09-06 14:27:37 +02:00
2021-05-04 19:31:21 +02:00
.99 rts
2020-07-02 23:17:57 +02:00
*--------------------------------------
MAN
2020-12-15 14:23:22 +01:00
SAVE usr/src/sys/kernel.s.string
LOAD usr/src/sys/kernel.s
ASM