mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-24 14:31:05 +00:00
272 lines
4.3 KiB
Plaintext
272 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
|
||
* `>PUSHWI destination`
|
||
* `>PUSHWI source`
|
||
* `>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
|
||
* `>PUSHWI destination`
|
||
* `>PUSHWI source`
|
||
* `>SYSCALL strcpy`
|
||
* ## RETURN VALUE
|
||
* Y,A = destination
|
||
*\--------------------------------------
|
||
K.StrCpy clc
|
||
phy
|
||
pha
|
||
jsr SHARED.PullP2P1
|
||
|
||
bcc .2
|
||
|
||
.1 jsr SHARED.GetCP1
|
||
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
|
||
* ## C
|
||
* `char * strdup ( char * str);`
|
||
* ## ASM
|
||
* Y,A = Ptr to source C-String
|
||
* CC : success
|
||
* Y,A = PTR to String
|
||
* X = hMem (C-String)
|
||
* CS : error
|
||
* A = SYS error code
|
||
*\--------------------------------------
|
||
STRING.DupBuf256
|
||
>LDYAI K.Buf256
|
||
|
||
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
|
||
* `>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 "a{A["
|
||
*/--------------------------------------
|
||
* # StrCmp
|
||
* Compare 2 strings
|
||
* ## C
|
||
* `int strcmp(const char *s1, const char *s2);`
|
||
* ## ASM
|
||
* `>PUSHWI s1`
|
||
* `>PUSHWI s2`
|
||
* `>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
|
||
* `>PUSHWI s1`
|
||
* `>PUSHWI s2`
|
||
* `>SYSCALL strcasecmp`
|
||
* ## RETURN VALUE
|
||
* CC : match
|
||
* CS : no match
|
||
* CC, Y,A=0
|
||
* CS, Y,A > 0 or < 0
|
||
*\--------------------------------------
|
||
K.StrCaseCmp clc
|
||
jsr SHARED.PullP2P1
|
||
|
||
ldy #0
|
||
|
||
.1 lda (ZPPtr1),y
|
||
beq .7
|
||
|
||
jsr .80
|
||
sta .2+1
|
||
lda (ZPPtr2),y
|
||
beq .9
|
||
|
||
jsr .80
|
||
|
||
.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
|
||
*--------------------------------------
|
||
.80 bcs .99
|
||
|
||
cmp #'a'
|
||
bcc .99
|
||
|
||
cmp #'z'+1
|
||
bcs .81
|
||
|
||
eor #$20
|
||
|
||
.81 clc
|
||
|
||
.99 rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE usr/src/sys/kernel.s.string
|
||
LOAD usr/src/sys/kernel.s
|
||
ASM
|