Kernel 0.9.1 : Code reorganization & move to CSTR, new RealPath.YA API

This commit is contained in:
Rémy GIBERT 2017-09-28 17:39:12 +02:00
parent 98632f7a49
commit 399bdc0cae
13 changed files with 181 additions and 153 deletions

View File

@ -1,14 +1,5 @@
*** Auto generated by docgen.cmd *** *** Auto generated by docgen.cmd ***
# GetArgC
Returns argument count in the process command line.
## In:
+ none.
## Out:
+ A = Command line Arg Count (Including /path/cmd)
# GetArg.A # GetArg.A
## In: ## In:
@ -613,6 +604,18 @@ Convert String to 32 bits int
## Out: ## Out:
# 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
# StrLen.YA # StrLen.YA
Returns Length of C-String Returns Length of C-String

Binary file not shown.

Binary file not shown.

View File

@ -51,19 +51,12 @@ L.PRODOS.FT.TXT .DA PRODOS.FT.TXT
L.FMT.DateTime .DA FMT.DateTime L.FMT.DateTime .DA FMT.DateTime
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
CS.INIT ldy #S.PS.ARGC CS.INIT
lda (pPs),y .1 >INC.G ArgCount
beq .7 >SYSCALL GetArg.A
bcs .6
>STA.G ArgCount
.1 >SYSCALL GetArg.A
>STYA ZPPtr1 >STYA ZPPtr1
>SYSCALL PrintF.YA
lda #'|'
>SYSCALL PutChar.A
lda (ZPPtr1) lda (ZPPtr1)
cmp #'-' cmp #'-'
bne .4 bne .4
@ -84,16 +77,13 @@ CS.INIT ldy #S.PS.ARGC
.3 ldy OptionVars-1,x .3 ldy OptionVars-1,x
lda #$80 lda #$80
sta (pData),y sta (pData),y
bra .6 bra .1
.4 >LDYA ZPPtr1 .4 >LDYA ZPPtr1
jsr InitSrcDirYA jsr InitSrcDirYA
bcs .9 bcs .9
>LDA.G ArgCount bra .1 scan for any other args
dec
sta (pData),y
bne .1 scan for any other args
.6 >LDA.G index do we have a Source dir ? .6 >LDA.G index do we have a Source dir ?
bne .8 bne .8

View File

@ -21,7 +21,7 @@ CS.START cld
.DA CS.END-CS.START CS .DA CS.END-CS.START CS
.DA DS.END-DS.START DS .DA DS.END-DS.START DS
.DA #16 SS .DA #16 SS
.DA 0 ZP .DA #0 ZP
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
* Relocation Table * Relocation Table
@ -35,17 +35,18 @@ CS.START cld
CS.INIT clc CS.INIT clc
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN >SYSCALL GetArgC CS.RUN lda #1
cmp #1
beq .99
lda #1
>SYSCALL GetArg.A >SYSCALL GetArg.A
bcs .99
>SYSCALL GetFullPath.YA >SYSCALL GetFullPath.YA
bcs .9 bcs .9
phy
pha
txa txa
>STA.G hFullPath >STA.G hFullPath
pla
ply
>SYSCALL MKDir.YA >SYSCALL MKDir.YA
bcs .9 bcs .9

View File

@ -23,6 +23,15 @@ InitSrcDirYA >SYSCALL GetFullPath.YA
txa txa
>STA.G hFullPath >STA.G hFullPath
>LDYA ZPPtr1
>SYSCALL PrintF.YA
lda #'|'
>SYSCALL PutChar.A
lda #13
>SYSCALL PutChar.A
lda #10
>SYSCALL PutChar.A
ldy #1 ldy #1
lda (ZPPtr1),y lda (ZPPtr1),y
beq .5 we have '/' beq .5 we have '/'

View File

@ -163,7 +163,7 @@ SYS.AToL .EQ $74
* .EQ $76 * .EQ $76
* .EQ $78 * .EQ $78
* .EQ $7A * .EQ $7A
* .EQ $7C SYS.RealPath.YA .EQ $7C
* .EQ $7E * .EQ $7E
*-------------------------------------- *--------------------------------------
SYS.StrLen.YA .EQ $80 SYS.StrLen.YA .EQ $80

View File

@ -211,15 +211,6 @@ Cmd.Exec.EXT.TXT
>PUSHYA >PUSHYA
>PUSHW ZPCMDBuf >PUSHW ZPCMDBuf
>SYSCALL StrCat >SYSCALL StrCat
>LDYA ZPCMDBuf
>SYSCALL PrintF.YA
lda #'!'
>SYSCALL PutChar.A
lda #13
>SYSCALL PutChar.A
lda #10
>SYSCALL PutChar.A
*-------------------------------------- *--------------------------------------
* BIN : Launch "/PATH/CMD ARGS" * BIN : Launch "/PATH/CMD ARGS"
*-------------------------------------- *--------------------------------------
@ -233,15 +224,6 @@ Cmd.Exec.EXT.BIN
>PUSHW ZPCMDBuf >PUSHW ZPCMDBuf
>SYSCALL StrCat >SYSCALL StrCat
>LDYA ZPCMDBuf
>SYSCALL PrintF.YA
lda #'!'
>SYSCALL PutChar.A
lda #13
>SYSCALL PutChar.A
lda #10
>SYSCALL PutChar.A
.1 >LDA.G CMD.bStartProc .1 >LDA.G CMD.bStartProc
asl asl
>LDYA ZPCMDBuf >LDYA ZPCMDBuf
@ -276,103 +258,54 @@ Cmd.Exec.EXT.SEP
*-------------------------------------- *--------------------------------------
* Internal Commands * Internal Commands
*-------------------------------------- *--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
bne Cmd.Exec.CD1
Cmd.Exec.PWD ldy #S.PS.hPREFIX Cmd.Exec.PWD ldy #S.PS.hPREFIX
lda (pPs),y lda (pPs),y
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>SYSCALL PrintF.YA >SYSCALL PrintF.YA
jmp Cmd.Exec.ECHO.CR jmp Cmd.Exec.ECHO.CR
*--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
bne .1
Cmd.Exec.CD1 lda (ZPPTR2) Get ARG >LDYA L.ENV.HOME
cmp #'/' Full Path? >SYSCALL GetEnv.YA
bne .20 bcs Cmd.Exec.PWD
sta (ZPCMDBuf) >SYSCALL ExpandStr.YA
bcs .9
ldy #1 strlen = 1 bra .4
lda #0
sta (ZPCMDBuf),y
bra .1
.20 ldy #S.PS.hPREFIX no, init target prefix with actual prefix .1 ldy #0
lda (pPs),y
>SYSCALL GetMemPtr.A
>PUSHYA
>PUSHW ZPCMDBuf
>SYSCALL StrCpy
ldy #0 .2 lda (ZPPTR2),y
tax
.10 iny
lda (ZPCMDBuf),y
bne .10 get strlen ...
.1 ldx #0 dot counter for /./ & /../ detection
.12 lda (ZPPTR2)
bne .21 last char...
dey
lda (ZPCMDBuf),y
iny iny
cmp #'/' lda (ZPPTR2),y
beq .8 bne .2
cpx #'/'
beq .3
lda #'/' lda #'/'
sta (ZPCMDBuf),y sta (ZPPTR2),y
iny iny
bra .13 lda #0
sta (ZPPTR2),y
.21 inc ZPPTR2 .3 >LDYA ZPPTR2 Get ARG
bne .11 >SYSCALL RealPath.YA
inc ZPPTR2+1 bcs .9
.11 sta (ZPCMDBuf),y .4 >STYA ZPPTR2
iny txa
cmp #'/' >STA.G CMD.hFullpath
beq .13
cmp #'.' a dot ? ldy #1
bne .1 no, reset counter... lda (ZPPTR2),y
inx beq .8 we have '/'
bra .12
.13 txa counting dot ?
beq .12
cpx #2 /../ ?
beq .14
dex /./ ?
bne Cmd.Exec.ERRSYN
dey
dey remove "./" at the end of path....
bra .1
.14 dey remove "../" at the end of path : "/dir1/../"
dey
dey
beq Cmd.Exec.ERRSYN path was "/../".....error....
.16 dey path is something like : /dir1/, skip ending '/'
lda (ZPCMDBuf),y path is something like : /dir1
cmp #'/'
bne .16
bra .1 Start over...
.8 lda #0
sta (ZPCMDBuf),y
cpy #1
beq .80 we have '/' go change prefix
>LDYA ZPCMDBuf
>SYSCALL PrintF.YA
lda #'!'
>SYSCALL PutChar.A
>PUSHEA.G CMD.Stat >PUSHEA.G CMD.Stat
>PUSHW ZPCMDBuf >PUSHW ZPPTR2
>SYSCALL STAT >SYSCALL STAT
bcs .9 bcs .9
@ -381,7 +314,7 @@ Cmd.Exec.CD1 lda (ZPPTR2) Get ARG
cmp #$0F Directory ? cmp #$0F Directory ?
bne Cmd.Exec.ERRSYN bne Cmd.Exec.ERRSYN
.80 >LDYA ZPCMDBuf .8 >LDYA ZPPTR2
>SYSCALL NewStr.YA >SYSCALL NewStr.YA
bcs .9 bcs .9
phx phx

View File

@ -134,10 +134,6 @@ CSH.Run jsr CSH.GetBuf
jsr CSH.RestorePtr Restore ptr to get full cmd line to execute jsr CSH.RestorePtr Restore ptr to get full cmd line to execute
>LDA.G hCmdBuf Get the buffer
>SYSCALL GetMemPtr.A
>STYA ZPCMDBuf
jsr CSH.GetCharNB jsr CSH.GetCharNB
ldy #0 ldy #0

View File

@ -64,6 +64,7 @@ L.MSG.CSHERR .DA MSG.CSHERR
L.ENV.PATH .DA ENV.PATH L.ENV.PATH .DA ENV.PATH
L.ENV.PWD .DA ENV.PWD L.ENV.PWD .DA ENV.PWD
L.ENV.PS1 .DA ENV.PS1 L.ENV.PS1 .DA ENV.PS1
L.ENV.HOME .DA ENV.HOME
L.FMT.DATE .DA FMT.DATE L.FMT.DATE .DA FMT.DATE
L.FMT.TIME .DA FMT.TIME L.FMT.TIME .DA FMT.TIME
J.ESC .DA CmdLine.BS left arrow J.ESC .DA CmdLine.BS left arrow
@ -187,11 +188,7 @@ CS.RUN.EXIT lda #0
CS.RUN.EXIT.ERR sec CS.RUN.EXIT.ERR sec
CS.RUN.EXIT.RTS rts CS.RUN.EXIT.RTS rts
*-------------------------------------- *--------------------------------------
CS.RUN.READ >LDA.G hCmdBuf Get the buffer CS.RUN.READ lda #0 reset Buffer
>SYSCALL GetMemPtr.A
>STYA ZPCMDBuf
lda #0 reset it
sta (ZPCMDBuf) sta (ZPCMDBuf)
.1 >SYSCALL Sleep .1 >SYSCALL Sleep
@ -205,13 +202,7 @@ CS.RUN.READ >LDA.G hCmdBuf Get the buffer
>PUSHW ZPCMDBuf >PUSHW ZPCMDBuf
lda #CMD.VarName >PUSHEA.G CMD.VarName
clc
adc pData
tay
lda pData+1
adc #0
>PUSHYA
>SYSCALL SetEnv >SYSCALL SetEnv
rts rts
*-------------------------------------- *--------------------------------------
@ -480,6 +471,7 @@ CS.END
ENV.PATH >CSTR "PATH" ENV.PATH >CSTR "PATH"
ENV.PWD >CSTR "PWD" ENV.PWD >CSTR "PWD"
ENV.PS1 >CSTR "PS1" ENV.PS1 >CSTR "PS1"
ENV.HOME >CSTR "HOME"
*-------------------------------------- *--------------------------------------
INTCMDS >CSTR "CD" INTCMDS >CSTR "CD"
>CSTR "DATE" >CSTR "DATE"

View File

@ -39,7 +39,10 @@ K.GetArg.A pha save requested arg#
inc ZPPtr1+1 inc ZPPtr1+1
.5 dex .5 dex
bne .1 bne .1 stop here....
lda (ZPPtr1) at end of ARGS[] ?
beq .9
.8 >LDYA ZPPtr1 .8 >LDYA ZPPtr1
.80 clc .80 clc

View File

@ -77,7 +77,7 @@ K.SYSCALL.JMP .DA 0 $00
.DA 0 .DA 0
.DA 0 .DA 0
.DA 0 .DA 0
.DA 0 .DA K.RealPath.YA
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
* Bank 2 * Bank 2

View File

@ -201,6 +201,107 @@ HEXBUF.ROL asl HEXBUF
HEXBUF .BS 4 32 bits max HEXBUF .BS 4 32 bits max
BCDBUF .BS 5 5, enough to handle 10 digits (32bits) BCDBUF .BS 5 5, enough to handle 10 digits (32bits)
ASCBUF .BS 12 LEN + sign + 10 digits ($FFFFFFFF=4.294.967.295) 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 MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.STDLIB SAVE /A2OSX.SRC/SYS/KERNEL.S.STDLIB