A2osX/SYS/KERNEL.S.STDLIB.txt
2019-11-25 08:05:07 +01:00

302 lines
5.6 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
*/--------------------------------------
* # strtof
* Convert String to 40 bits Float
* ## C
* `float strtof (const char* str, char** endptr);`
* ## ASM
* **In:**
* `>PUSHWI EndPtr`
* `>LDYA str`
* `>SYSCALL strtof`
* ## RETURN VALUE
* On stack (float)
*\--------------------------------------
K.strtof pha
>PULLW ZPPtr1
pla
jsr K.AToF
lda TXTPTR
sta (ZPPtr1)
ldy #1
lda TXTPTR+1
sta (ZPPtr1),y
rts
*/--------------------------------------
* # AToF
* Convert String to 40 bits Float
* ## C
* `float atof (const char* str);`
* ## ASM
* **In:**
* `>LDYA str`
* `>SYSCALL atof`
* ## RETURN VALUE
* On stack (float)
*\--------------------------------------
K.AToF >STYA TXTPTR Ptr to source string
lda pStack
sec
sbc #5
sta pStack
jsr CHARGOT
ldx #FPU.FIN
jmp GP.RomCallGetFacOnStack
*/--------------------------------------
* # StrToL/StrToUL
* Convert String to 32 bits (unsigned) int
* ## C
* `long strtol (const char* str, char** endptr, int base);`
* `unsigned long strtoul (const char* str, char** endptr, int base);`
* ## ASM
* **In:**
* `>PUSHB Base`
* `>PUSHWI EndPtr`
* `>LDYAI str`
* `>SYSCALL strtol`
* ## RETURN VALUE
* On stack (long)
*\--------------------------------------
K.StrToL sec Signed
.HS 90 BCC
K.StrToUL clc Unsigned
jsr SHARED.SPtr2PPtr1
>PULLA Base
jsr K.AToL.I
bcs K.StrToUL.rts
* clc
adc ZPPtr2
sta (ZPPtr1)
lda #0
adc ZPPtr2+1
ldy #1
sta (ZPPtr1),y
K.StrToUL.rts rts
*/--------------------------------------
* # atol
* Convert String to 32 bits long
* ## C
* `long atol ( const char * str );`
* ## ASM
* **In:**
* `>LDYA str`
* `>SYSCALL atol`
* ## RETURN VALUE
* On stack (long)
*\--------------------------------------
K.AToL >STYA ZPPtr2 C-String in Ptr2, Dst buffer in Ptr1
* lda #10 base 10
sec signed
K.AToL.I jsr MATH.Dec2ACC32
bcs .9
ldx #3
.3 lda ACC32,x
>PUSHA
dex
bpl .3
tya Y = A = Count processed
* clc
.9
rts
*/--------------------------------------
* # atoi
* Convert String to 16 bits int
* ## C
* `int atoi ( const char * str );`
* ## ASM
* **In:**
* `>LDYAI str`
* `>SYSCALL atoi`
* ## RETURN VALUE
* Y,A = int
*\--------------------------------------
K.atoi >STYA ZPPtr2
* lda #10 base 10
sec signed
jsr MATH.Dec2ACC32
bcs .9
>LDYA ACC32
.9
K.atoi.RTS rts
*/--------------------------------------
* # RealPath
* Return the canonicalized absolute pathname
* ## C
* `unsigned short int realpath (const char* str, char *resolvedpath);`
* ## ASM
* **In:**
* `>PUSHWI resolvedpath`
* `>LDYA str`
* `>SYSCALL realpath`
* ## RETURN VALUE
* CC : success
* Y,A = Ptr to Full Path (C-String Buffer, MLI.MAXPATH+1)
* X = hMem of Full Path
* CS : A = Error Code
*\--------------------------------------
K.realpath sec
.HS 90 BCC
STDLIB.realpath.I
clc
ror .82+1
ldx #SYS.ExpandStr
jsr K.SYSCALL2
bcs K.atoi.RTS
>STYA ZPPtr1
stx .99+1 save expanded buffer hMem
ldx #$ff
lda (ZPPtr1)
cmp #'/' full path starting with '/'?
beq .3 yes, do not append to current prefix
.1 ldy #S.PS.hCWD
lda (pPs),y
jsr K.GetMemPtr
>STYA ZPPtr2
ldy #$ff
.2 iny
inx
lda (ZPPtr2),y
sta K.Buf256,x
bne .2
dex
.3 ldy #$ff
.4 iny
inx
lda (ZPPtr1),y
sta K.Buf256,x
bne .4
dex
beq .81 we have '/'....nothing to do...
*--------------------------------------
* X=LEN, K.Buf256 = /dir1/./../file(/)\0
*--------------------------------------
ldx #0 will skip leading /
.5 ldy #0 reset dot counter=0
.6 inx
lda K.Buf256,x
beq .8
.7 cmp #'/'
beq .8
cmp #'.'
bne .5
iny
bra .6
.8 tya
beq .80 Y was 0....nothing to do...
dey one dot ?
bne .9 no..
dex
dex
jsr K.RealPath.RemoveAtX we found "/.", remove,useless....
bra .80
.9 dey "/.." ?
bne .99 "/..." ??!!...syntax error
dex
dex
dex
txa we found "/.."
beq .99 at the beginning of string...cannot remove /dir/..
jsr K.RealPath.RemoveAtX remove "/.."
.10 dex
lda K.Buf256,x go to "/dir"
cmp #'/'
bne .10
jsr K.RealPath.RemoveAtX ...remove "/dir"
.80 lda K.Buf256,x was / or \0 ?
bne .5
*--------------------------------------
.81 jsr .99
.82 lda #$ff SELF MODIFIED
bpl .88
>LDYAI MLI.MAXPATH+1
jsr K.getmem
bcs .90
>STYA ZPPtr1
ldy #$ff
.83 iny
lda K.Buf256,y
sta (ZPPtr1),y
bne .83
>LDYA ZPPtr1
.88 clc
rts
.99 lda #$ff SELF MODIFIED
jsr K.FreeMem
lda #E.BADPATH
sec
.90 rts
*--------------------------------------
K.RealPath.RemoveAtX
txa X = "/something"
tay
.1 iny
lda K.Buf256,y
beq .2 found /something\0
cmp #'/'
bne .1 found /something/
.2 phx save X for exit
.3 iny K.Buf256,y=/ or 0
inx
lda K.Buf256-1,y
sta K.Buf256-1,x
bne .3
txa
bne .8
lda #'/' Make sure we have a least '/' in the buffer
sta K.Buf256
stz K.Buf256+1
.8 plx restore X
rts
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.STDLIB
LOAD USR/SRC/SYS/KERNEL.S
ASM