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