A2osX/SYS/KERNEL.S.STRING.txt

248 lines
4.3 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-25 19:24:07 +00:00
AUTO 3,1
*/--------------------------------------
2018-06-18 06:22:50 +00:00
* # StrLen
* 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
*\--------------------------------------
2018-10-12 15:47:57 +00:00
K.StrLen >STYA .1+1
ldy #0
2018-10-12 15:47:57 +00:00
tya
.1 ldx $ffff,y SELF MODIFIED
beq .8
iny
bne .1
2018-10-12 15:47:57 +00:00
inc
inc .1+2
bra .1
2019-05-04 21:13:50 +00:00
.8 clc
rts
*/--------------------------------------
* # 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
*\--------------------------------------
2018-06-18 08:44:02 +00:00
K.StrCat sec
.HS 90 BCC
*/--------------------------------------
* # 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
*\--------------------------------------
2018-06-18 08:44:02 +00:00
K.StrCpy clc
2018-11-21 13:08:11 +00:00
pha
phy
2019-07-28 20:39:30 +00:00
jsr SHARED.SPtr1PPtr2
2018-06-18 08:44:02 +00:00
bcc .2
2019-07-28 20:39:30 +00:00
.1 jsr SHARED.GetCharPtr1
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
.3 lda (ZPPtr2),y
sta (ZPPtr1),y
2019-07-17 15:49:23 +00:00
beq K.StrDup.8
iny
2018-06-18 08:44:02 +00:00
bne .3
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
* Y,A = Ptr to source C-String
* ## RETURN VALUE
* 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
*\--------------------------------------
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
*/--------------------------------------
2018-06-18 06:22:50 +00:00
* # StrUpr/StrLwr
* 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
*\--------------------------------------
2018-06-22 14:59:24 +00:00
K.StrUpr ldx #0
.HS 2C bit abs
2018-06-22 14:59:24 +00:00
K.StrLwr ldx #2
>STYA ZPPtr1
phy
2018-12-20 16:23:43 +00:00
pha save Y,A to restore them at exit
ldy #0
.1 lda (ZPPtr1),y
2018-12-20 16:23:43 +00:00
beq K.StrDup.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
*--------------------------------------
.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
2019-07-28 20:39:30 +00:00
jsr SHARED.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
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
2019-10-03 06:25:27 +00:00
sec
2018-01-15 16:51:44 +00:00
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
2019-10-03 06:25:27 +00:00
.9 rts
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.STRING
LOAD USR/SRC/SYS/KERNEL.S
ASM