mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-19 12:31:56 +00:00
248 lines
4.3 KiB
Plaintext
248 lines
4.3 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
*/--------------------------------------
|
||
* # StrLen
|
||
* Returns Length of C-String
|
||
* ## C
|
||
* `int strlen ( char * str);`
|
||
* ## ASM
|
||
* `>LDYAI str`
|
||
* `>SYSCALL strlen`
|
||
* ## RETURN VALUE
|
||
* Y,A = String length
|
||
*\--------------------------------------
|
||
K.StrLen >STYA .1+1
|
||
|
||
ldy #0
|
||
tya
|
||
.1 ldx $ffff,y SELF MODIFIED
|
||
beq .8
|
||
iny
|
||
bne .1
|
||
inc
|
||
inc .1+2
|
||
bra .1
|
||
.8 clc
|
||
rts
|
||
*/--------------------------------------
|
||
* # StrCat
|
||
* Concatenate strings
|
||
* ## C
|
||
* `char * strcat ( char * destination, const char * source );`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHWI source`
|
||
* `>LDYAI destination`
|
||
* `>SYSCALL strcat`
|
||
* ## RETURN VALUE
|
||
* Y,A = destination
|
||
*\--------------------------------------
|
||
K.StrCat sec
|
||
.HS 90 BCC
|
||
*/--------------------------------------
|
||
* # StrCpy
|
||
* Copy string
|
||
* ## C
|
||
* `char * strcpy ( char * destination, const char * source );`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHWI source`
|
||
* `>LDYAI destination`
|
||
* `>SYSCALL strcpy`
|
||
* ## RETURN VALUE
|
||
* Y,A = destination
|
||
*\--------------------------------------
|
||
K.StrCpy clc
|
||
phy
|
||
pha
|
||
jsr SHARED.SPtr1PPtr2
|
||
|
||
bcc .2
|
||
|
||
.1 jsr SHARED.GetCharPtr1
|
||
bne .1
|
||
|
||
.2 ldy #0
|
||
.3 lda (ZPPtr2),y
|
||
sta (ZPPtr1),y
|
||
beq K.StrDup.8
|
||
iny
|
||
bne .3
|
||
inc ZPPtr2+1
|
||
inc ZPPtr1+1
|
||
bra .3
|
||
*/--------------------------------------
|
||
* # 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 (C-String)
|
||
* CS : error
|
||
* A = SYS error code
|
||
*\--------------------------------------
|
||
K.StrDup >STYA .1+1
|
||
>STYA .4+1
|
||
|
||
lda #0
|
||
tay
|
||
|
||
.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.StrDup.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
|
||
clc
|
||
K.StrDup.RTS rts
|
||
*/--------------------------------------
|
||
* # StrUpr/StrLwr
|
||
* Convert string to UPPERCASE/lowercase
|
||
* ## C
|
||
* `int strupr ( char * str);`
|
||
* `int strlwr ( char * str);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>LDYAI str`
|
||
* `>SYSCALL strupr`
|
||
* `>SYSCALL strlwr`
|
||
* ## RETURN VALUE
|
||
* Uppercased/lowercased String in Buffer
|
||
* Y,A = str
|
||
*\--------------------------------------
|
||
K.StrUpr ldx #0
|
||
.HS 2C bit abs
|
||
K.StrLwr ldx #2
|
||
>STYA ZPPtr1
|
||
phy
|
||
pha save Y,A to restore them at exit
|
||
ldy #0
|
||
.1 lda (ZPPtr1),y
|
||
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"
|
||
*/--------------------------------------
|
||
* # StrCmp
|
||
* Compare 2 strings
|
||
* ## C
|
||
* `int strcmp(const char *s1, const char *s2);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHWI s2`
|
||
* `>LDYAI s1`
|
||
* `>SYSCALL strcmp`
|
||
* ## RETURN VALUE
|
||
* CC : match
|
||
* CS : no match
|
||
* CC, Y,A=0
|
||
* CS, Y,A > 0 or < 0
|
||
*\--------------------------------------
|
||
K.StrCmp sec
|
||
.HS 90 BCC
|
||
*/--------------------------------------
|
||
* # StrCaseCmp
|
||
* Compare 2 strings, ignoring case
|
||
* ## C
|
||
* `int strcasecmp(const char *s1, const char *s2);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHWI s2`
|
||
* `>LDYAI s1`
|
||
* `>SYSCALL strcasecmp`
|
||
* ## RETURN VALUE
|
||
* CC : match
|
||
* CS : no match
|
||
* CC, Y,A=0
|
||
* CS, Y,A > 0 or < 0
|
||
*\--------------------------------------
|
||
K.StrCaseCmp clc
|
||
jsr SHARED.SPtr1PPtr2
|
||
|
||
ldy #0
|
||
.1 lda (ZPPtr1),y
|
||
beq .7
|
||
jsr K.StrCaseCmp.toUpper
|
||
sta .2+1
|
||
lda (ZPPtr2),y
|
||
beq .9
|
||
jsr K.StrCaseCmp.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.StrCaseCmp.toUpper
|
||
bcs .9
|
||
cmp #'a'
|
||
bcc .9
|
||
cmp #'z'+1
|
||
bcs .1
|
||
eor #$20
|
||
|
||
.1 clc
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE USR/SRC/SYS/KERNEL.S.STRING
|
||
LOAD USR/SRC/SYS/KERNEL.S
|
||
ASM
|