mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-09 00:54:29 +00:00
310 lines
5.3 KiB
Plaintext
310 lines
5.3 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
LOMEM $A00
|
||
INC 1
|
||
AUTO 6
|
||
*/--------------------------------------
|
||
* # AToF
|
||
* Convert String to 40 bits Float
|
||
* ## In:
|
||
* PUSHW PTR to target buffer (5 Bytes)
|
||
* PUSHW Source String (PSTR)
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.AToF
|
||
*/--------------------------------------
|
||
* # AToI.YA
|
||
* Convert String to 16 bits int
|
||
* ## In:
|
||
* Y,A = Source String (C-String)
|
||
* ## Out:
|
||
* Y,A = Int
|
||
*\--------------------------------------
|
||
K.AToI.YA
|
||
*/--------------------------------------
|
||
* # AToL
|
||
* Convert String to 32 bits int
|
||
* ## In:
|
||
* PUSHW PTR to target buffer DWORD
|
||
* PUSHW Source String (PSTR)
|
||
* ## Out:
|
||
*\--------------------------------------
|
||
K.AToL jsr PullPtr1Ptr2 PSTR in Ptr1,buffer in Ptr2
|
||
|
||
stz ASCBUF
|
||
|
||
ldx #0
|
||
|
||
lda (ZPPtr1)
|
||
beq .2
|
||
|
||
ldy #0
|
||
|
||
.1 iny
|
||
lda (ZPPtr1),y
|
||
|
||
cmp #'0'
|
||
bcc .2
|
||
cmp #'9'+1
|
||
bcs .2
|
||
|
||
inx
|
||
sta ASCBUF,x
|
||
cpx #10
|
||
beq .2
|
||
tya
|
||
cmp (ZPPtr1)
|
||
bne .1
|
||
|
||
.2 stx ASCBUF
|
||
jsr DEC2HEX
|
||
|
||
ldy #3
|
||
|
||
.3 lda HEXBUF,y
|
||
sta (ZPPtr2),y
|
||
dey
|
||
bpl .3
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
TYPES .AS "-dbclssp"
|
||
ACCESS .AS "rwxrwxrwx"
|
||
SIGN .BS 1
|
||
PADLEN .BS 1
|
||
PADCHAR .BS 1
|
||
*--------------------------------------
|
||
* Convert HEXBUF to ASCBUF decimal padded with 0
|
||
*--------------------------------------
|
||
HEX2DEC ldx #4
|
||
|
||
.1 stz BCDBUF,x Clear all 5 bytes
|
||
dex
|
||
bpl .1
|
||
|
||
sed switch to BCD mode
|
||
|
||
ldx #32 let's roll 32 bits
|
||
|
||
.2 jsr HEXBUF.ROL
|
||
|
||
ldy #4
|
||
|
||
.3 lda BCDBUF,y
|
||
adc BCDBUF,y
|
||
sta BCDBUF,y
|
||
dey
|
||
bpl .3
|
||
|
||
dex
|
||
bne .2
|
||
|
||
cld
|
||
|
||
ldy #4
|
||
ldx #9
|
||
|
||
.4 lda BCDBUF,y
|
||
pha
|
||
and #$0F
|
||
ora #$30
|
||
sta ASCBUF,x
|
||
dex
|
||
pla
|
||
lsr
|
||
lsr
|
||
lsr
|
||
lsr
|
||
ora #$30
|
||
sta ASCBUF,x
|
||
dey
|
||
dex
|
||
bpl .4
|
||
|
||
rts
|
||
*--------------------------------------
|
||
* Convert ASCBUF decimal to HEXBUF
|
||
*--------------------------------------
|
||
DEC2HEX stz HEXBUF
|
||
stz HEXBUF+1
|
||
stz HEXBUF+2
|
||
stz HEXBUF+3
|
||
|
||
lda ASCBUF
|
||
beq .8
|
||
|
||
ldx #0
|
||
|
||
.1 lda HEXBUF+3 save HEXBUF for 4+1
|
||
pha
|
||
lda HEXBUF+2
|
||
pha
|
||
lda HEXBUF+1
|
||
pha
|
||
lda HEXBUF
|
||
pha
|
||
|
||
jsr HEXBUF.ROL HEXBUF * 2 -> HEXBUF
|
||
* bcs .9 overflow!!!
|
||
|
||
jsr HEXBUF.ROL HEXBUF * 4 -> HEXBUF
|
||
* bcs .9 overflow!!!
|
||
|
||
pla HEXBUF * 4 + HEXBUF -> HEXBUF
|
||
adc HEXBUF
|
||
sta HEXBUF
|
||
pla
|
||
adc HEXBUF+1
|
||
sta HEXBUF+1
|
||
pla
|
||
adc HEXBUF+2
|
||
sta HEXBUF+2
|
||
pla
|
||
adc HEXBUF+3
|
||
sta HEXBUF+3
|
||
* bcs .99 overflow!!!
|
||
|
||
jsr HEXBUF.ROL HEXBUF * 10 -> HEXBUF
|
||
* bcs .99 overflow!!!
|
||
|
||
inx
|
||
lda ASCBUF,x
|
||
and #$0F
|
||
|
||
adc HEXBUF
|
||
sta HEXBUF
|
||
bcc .2
|
||
inc HEXBUF+1
|
||
bne .2
|
||
inc HEXBUF+2
|
||
bne .2
|
||
inc HEXBUF+3
|
||
|
||
.2 cpx ASCBUF
|
||
bne .1
|
||
|
||
.8 rts
|
||
|
||
*.9 pla discard saved HEXBUF
|
||
* pla
|
||
* pla
|
||
* pla
|
||
*.99 rts
|
||
*--------------------------------------
|
||
HEXBUF.ROL asl HEXBUF
|
||
rol HEXBUF+1
|
||
rol HEXBUF+2
|
||
rol HEXBUF+3
|
||
rts
|
||
*--------------------------------------
|
||
HEXBUF .BS 4 32 bits max
|
||
BCDBUF .BS 5 5, enough to handle 10 digits (32bits)
|
||
ASCBUF .BS 12 LEN + sign + 10 digits ($FFFFFFFF=4.294.967.295)
|
||
*/--------------------------------------
|
||
* # 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 .10
|
||
|
||
cmp #'/' full path starting with '/'?
|
||
beq .2 yes, do not append to current prefix
|
||
|
||
.10 ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
jsr K.GetMemPtr.A
|
||
>STYA ZPPtr2
|
||
|
||
ldy #$ff
|
||
|
||
.1 iny
|
||
lda (ZPPtr2),y
|
||
beq .2
|
||
inx
|
||
sta K.Buf256,x
|
||
bra .1
|
||
|
||
.2 ldy #$ff
|
||
|
||
.3 iny
|
||
inx
|
||
lda (ZPPtr1),y
|
||
sta K.Buf256,x
|
||
bne .3 X=LEN, K.Buf256 = /dir1..../file(/) /x0
|
||
*\--------------------------------------
|
||
.4 dex
|
||
beq .89 we have '/'....nothing to do...
|
||
lda K.Buf256,x
|
||
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
|
||
ldy #0
|
||
|
||
.7 dex
|
||
bra .6 always, should end with a '/'
|
||
|
||
.8 dey we found "/." ?
|
||
bmi .80
|
||
bne .9
|
||
|
||
|
||
bra .80
|
||
|
||
.9 dey we found "/.." ?
|
||
bne .90 "/......" ...mmm...syntax error
|
||
|
||
|
||
|
||
|
||
|
||
.80 txa
|
||
beq .89
|
||
dex
|
||
bra .5
|
||
|
||
.89 >LDYAI K.Buf256
|
||
>SYSCALL PrintF.YA
|
||
lda #'@'
|
||
>SYSCALL PutChar.A
|
||
lda #13
|
||
>SYSCALL PutChar.A
|
||
lda #10
|
||
>SYSCALL PutChar.A
|
||
|
||
>DEBUG
|
||
|
||
>LDYAI K.Buf256
|
||
jmp K.NewStr.YA
|
||
|
||
.90 lda #SYSMGR.ERRSYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SYS/KERNEL.S.STDLIB
|
||
LOAD /A2OSX.SRC/SYS/KERNEL.S
|
||
ASM
|