mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-10 22:54:59 +00:00
407 lines
7.5 KiB
Plaintext
407 lines
7.5 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
LOMEM $A00
|
||
INC 1
|
||
AUTO 6
|
||
*/--------------------------------------
|
||
* # StrToF
|
||
* Convert String to 40 bits Float
|
||
* ## In:
|
||
* PUSHW PTR to EndPtr
|
||
* PUSHW Source String (C-Sring)
|
||
* PUSHW PTR to target buffer (5 bytes)
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.StrToF jsr PullPtr1Ptr2Ptr3
|
||
jsr K.AToF.I
|
||
bcc K.StrToUL.Exit
|
||
|
||
.9 rts
|
||
*/--------------------------------------
|
||
* # AToF
|
||
* Convert String to 40 bits Float
|
||
* ## In:
|
||
* PUSHW Source String (C-Sring)
|
||
* PUSHW PTR to target buffer (5 Bytes)
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.AToF jsr PullPtr1Ptr2 C-String in Ptr2, Dst buffer in Ptr1
|
||
|
||
K.AToF.I jsr MANTISSA.Clear
|
||
|
||
ldy #$ff
|
||
|
||
.1 iny
|
||
lda (ZPPtr2),y
|
||
beq .8
|
||
cmp #' '
|
||
beq .1
|
||
|
||
.2 iny
|
||
lda (ZPPtr2),y
|
||
beq .8
|
||
|
||
jsr STDIO.IsDigit
|
||
bcc .7
|
||
|
||
cmp #'+'
|
||
beq .3
|
||
cmp #'-'
|
||
bne .4
|
||
|
||
.3 jsr K.AToF.CheckSign
|
||
bcs .9
|
||
bra .1
|
||
|
||
.4 cmp #'.'
|
||
bne .5
|
||
ldx INEXP Decimal point not allowed in EXP
|
||
bne .9
|
||
ldx bDECPOINT ....and only one!
|
||
bne .9
|
||
inc bDECPOINT
|
||
bra .1
|
||
|
||
.5 cmp #'E'
|
||
beq .6
|
||
|
||
cmp #'e'
|
||
bne .8
|
||
.6
|
||
|
||
.7
|
||
|
||
.8 clc
|
||
|
||
.9 lda #SYSMGR.ERRSYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
K.AToF.CheckSign
|
||
ldy INEXP Get MANTSIGN or EXPSIGN
|
||
ldx MANTSIGN,y
|
||
bne .9 Already set, error
|
||
|
||
cmp #'-'
|
||
bne .1
|
||
lda #$ff
|
||
.1 sta MANTSIGN,y set '+' of $ff to test with BIT
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*/--------------------------------------
|
||
* # StrToL
|
||
* Convert String to 32 bits int
|
||
* ## In:
|
||
* PUSHB Base
|
||
* PUSHW PTR to EndPtr
|
||
* PUSHW Source String (C-Sring)
|
||
* PUSHW PTR to target buffer DWORD
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.StrToL sec Signed
|
||
.HS 90 BCC
|
||
*/--------------------------------------
|
||
* # StrToUL
|
||
* Convert String to 32 bits unsigned int
|
||
* ## In:
|
||
* PUSHB Base
|
||
* PUSHW PTR to EndPtr
|
||
* PUSHW Source String (C-Sring)
|
||
* PUSHW PTR to target buffer DWORD
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.StrToUL clc Unsigned
|
||
jsr PullPtr1Ptr2Ptr3
|
||
>PULLA Base
|
||
jsr K.AToL.I
|
||
bcs K.StrToUL.rts
|
||
|
||
* clc
|
||
|
||
K.StrToUL.Exit adc ZPPtr2
|
||
sta ZPPtr3
|
||
lda #0
|
||
adc ZPPtr2+1
|
||
sta ZPPtr3+1
|
||
|
||
K.StrToUL.rts rts
|
||
*/--------------------------------------
|
||
* # AToL
|
||
* Convert String to 32 bits int
|
||
* ## In:
|
||
* PUSHW Source String (C-Sring)
|
||
* PUSHW PTR to target buffer DWORD
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.AToL jsr PullPtr1Ptr2 C-String in Ptr2, Dst buffer in Ptr1
|
||
|
||
lda #10 base 10
|
||
sec signed
|
||
|
||
K.AToL.I jsr STDLIB.Dec2Hex
|
||
bcs .9
|
||
phy Save Count processed
|
||
ldy #3
|
||
|
||
.3 lda MANTISSA,y
|
||
sta (ZPPtr1),y
|
||
dey
|
||
bpl .3
|
||
pla
|
||
|
||
* clc
|
||
|
||
.9 rts
|
||
*/--------------------------------------
|
||
* # AToI.YA
|
||
* Convert String to 16 bits int
|
||
* ## In:
|
||
* Y,A = Source String (C-String)
|
||
* ## Out:
|
||
* Y,A = Int
|
||
*\--------------------------------------
|
||
K.AToI.YA >STYA ZPPtr2
|
||
lda #10 base 10
|
||
sec signed
|
||
|
||
jsr STDLIB.Dec2Hex
|
||
bcs .9
|
||
|
||
>LDYA MANTISSA
|
||
.9 rts
|
||
*--------------------------------------
|
||
* Convert ZPPtr1 to MANTISSA
|
||
*--------------------------------------
|
||
STDLIB.Dec2Hex jsr MANTISSA.Clear
|
||
|
||
ldy #$ff
|
||
|
||
.1 iny
|
||
lda (ZPPtr2),y
|
||
beq .8
|
||
|
||
jsr STDIO.IsDigit
|
||
bcs .8
|
||
|
||
jsr MANTISSA.T10
|
||
bcs .9
|
||
|
||
lda (ZPPtr2),y
|
||
and #$0F
|
||
|
||
adc MANTISSA
|
||
sta MANTISSA
|
||
bcc .1
|
||
inc MANTISSA+1
|
||
bne .1
|
||
inc MANTISSA+2
|
||
bne .1
|
||
inc MANTISSA+3
|
||
bne .1 overflow!!!
|
||
* sec
|
||
rts
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
MANTISSA.T10 ldx #3
|
||
|
||
.1 lda MANTISSA,x save MANTISSA for 4+1
|
||
pha
|
||
dex
|
||
bpl .1
|
||
|
||
jsr MANTISSA.ROL MANTISSA * 2 -> MANTISSA
|
||
bcs .9 overflow!!!
|
||
|
||
jsr MANTISSA.ROL MANTISSA * 4 -> MANTISSA
|
||
bcs .9 overflow!!!
|
||
|
||
ldx #0
|
||
ldy #4
|
||
|
||
* clc
|
||
|
||
.2 pla MANTISSA * 4 + MANTISSA -> MANTISSA
|
||
adc MANTISSA,x
|
||
sta MANTISSA,x
|
||
inx
|
||
dey
|
||
bne .2
|
||
|
||
bcs .99 overflow!!!
|
||
|
||
jsr MANTISSA.ROL MANTISSA * 10 -> MANTISSA
|
||
bcs .99 overflow!!!
|
||
|
||
.9 pla discard saved MANTISSA
|
||
pla
|
||
pla
|
||
pla
|
||
.99 rts
|
||
*--------------------------------------
|
||
MANTISSA.ROL asl MANTISSA
|
||
rol MANTISSA+1
|
||
rol MANTISSA+2
|
||
rol MANTISSA+3
|
||
rts
|
||
*--------------------------------------
|
||
MANTISSA.Clear ldx #8
|
||
.1 stz EXPSIGN,x
|
||
dex
|
||
bpl .1
|
||
rts
|
||
*--------------------------------------
|
||
bDECPOINT .BS 1
|
||
INEXP .BS 1
|
||
MANTSIGN .BS 1
|
||
EXPSIGN .BS 1
|
||
EXP .BS 1
|
||
MANTISSA .BS 4 32 bits max
|
||
*/--------------------------------------
|
||
* # RealPath.YA
|
||
* Return the canonicalized absolute pathname
|
||
* ## In :
|
||
* Y,A = Ptr to Relative Filename (C-String)
|
||
* ## Out :
|
||
* CC : success
|
||
* Y,A = Ptr to Full Path (C-String)
|
||
* X = hMem of Full Path
|
||
* CS : A = Error Code
|
||
*\--------------------------------------
|
||
K.RealPath.YA >STYA ZPPtr1
|
||
ldx #$ff
|
||
|
||
lda (ZPPtr1)
|
||
beq .1
|
||
|
||
cmp #'/' full path starting with '/'?
|
||
beq .3 yes, do not append to current prefix
|
||
|
||
.1 ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
jsr K.GetMemPtr.A
|
||
>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
|
||
*--------------------------------------
|
||
* X=LEN, K.Buf256 = /dir1../file(/) /x0
|
||
|
||
dex
|
||
beq .89 we have '/'....nothing to do...
|
||
|
||
lda K.Buf256,x Skip any / at the end of string....
|
||
cmp #'/'
|
||
bne .5
|
||
|
||
dex
|
||
|
||
.5 ldy #0 dot counter=0
|
||
|
||
.6 lda K.Buf256,x
|
||
cmp #'/'
|
||
beq .8
|
||
|
||
cmp #'.'
|
||
bne .7
|
||
|
||
iny
|
||
.HS 2C BIT ABS, skip "LDY #0"
|
||
.7 ldy #0 not a dot....reset dot counter
|
||
|
||
txa
|
||
beq .89
|
||
dex
|
||
bra .6 always, should end with a '/'
|
||
|
||
.8 tya
|
||
beq .80 Y was 0....nothing to do...
|
||
dey "/." ?
|
||
bne .9 no..
|
||
|
||
jsr K.RealPath.RemoveAtX we found "/.", remove,useless....
|
||
|
||
bra .80
|
||
|
||
.9 dey "/.." ?
|
||
bne .90 "/..." ??!!...mmm...syntax error
|
||
|
||
txa we found "/.."
|
||
beq .90 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 txa
|
||
beq .89 Empty path!!! go put back "/" an exit
|
||
dex
|
||
bra .5
|
||
|
||
.89 >LDYAI K.Buf256
|
||
jmp K.NewStr.YA
|
||
|
||
.90 lda #SYSMGR.ERRSYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
K.RealPath.RemoveAtX
|
||
txa X = "/something"
|
||
tay
|
||
|
||
.1 iny
|
||
lda K.Buf256,y
|
||
beq .2
|
||
cmp #'/'
|
||
bne .1
|
||
|
||
.2 phx
|
||
|
||
.3 lda K.Buf256,y
|
||
sta K.Buf256,x
|
||
beq .4
|
||
iny
|
||
inx
|
||
bne .3
|
||
|
||
.4 txa
|
||
bne .8
|
||
|
||
lda #'/' Make sure we have a least '/' in the buffer
|
||
sta K.Buf256
|
||
stz K.Buf256+1
|
||
|
||
.8 plx
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SYS/KERNEL.S.STDLIB
|
||
LOAD /A2OSX.SRC/SYS/KERNEL.S
|
||
ASM
|