Kernel 0.9.1 : Code reorganization & move to CSTR (SHELL)

This commit is contained in:
Rémy GIBERT 2017-09-07 17:32:27 +02:00
parent 07fb258787
commit 4d2aab3e63
6 changed files with 183 additions and 172 deletions

Binary file not shown.

Binary file not shown.

View File

@ -5,17 +5,24 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
* Remove extra SPACE & comment CMD.Init >LDYAI CmdLine.MAX+1
>SYSCALL GetMem.YA
bcs .9
txa
>SETG.A hCmdBuf
.9 rts
*-------------------------------------- *--------------------------------------
Cmd.Normalize >LDYA ZPBufBase * ZPCMDBuf : Remove extra SPACE & comment
*--------------------------------------
Cmd.Parse >LDYA ZPCMDBuf
>STYA ZPPtr1 >STYA ZPPtr1
lda (ZPBufBase) empty line...quit lda (ZPCMDBuf) empty line...quit
beq .9 beq .9
ldy #0 ldy #0
.1 jsr Cmd.Normalize.Next .1 jsr Cmd.Parse.NextC
beq .8 no more char, exit beq .8 no more char, exit
cmp #' ' skip leading spaces cmp #' ' skip leading spaces
@ -24,19 +31,19 @@ Cmd.Normalize >LDYA ZPBufBase
cmp #'#' Comment ? cmp #'#' Comment ?
beq .8 ignore remaining chars beq .8 ignore remaining chars
.3 sta (ZPBufBase),y add char to buffer .3 sta (ZPCMDBuf),y add char to buffer
iny iny
jsr Cmd.Normalize.Next jsr Cmd.Parse.NextC
beq .8 beq .8
cmp #' ' cmp #' '
bne .3 bne .3
sta (ZPBufBase),y add One SPACE to buffer sta (ZPCMDBuf),y add One SPACE to buffer
iny iny
.5 jsr Cmd.Normalize.Next .5 jsr Cmd.Parse.NextC
beq .8 beq .8
cmp #' ' cmp #' '
@ -44,12 +51,11 @@ Cmd.Normalize >LDYA ZPBufBase
bne .3 no more space, add next word... bne .3 no more space, add next word...
.8 lda #0 .8 lda #0
sta (ZPBufBase),y sta (ZPCMDBuf),y
.9 rts .9 rts
Cmd.Normalize.Next Cmd.Parse.NextC lda (ZPPtr1)
lda (ZPPtr1)
beq .8 beq .8
inc ZPPtr1 inc ZPPtr1
@ -57,51 +63,56 @@ Cmd.Normalize.Next
inc ZPPtr1+1 never Z inc ZPPtr1+1 never Z
.8 rts .8 rts
*-------------------------------------- *--------------------------------------
* Y,A -> Command line (formatted & not empty) * ZPCMDBuf-> Command line (formatted & not empty)
*-------------------------------------- *--------------------------------------
Cmd.ExecYA stz bStartProc Cmd.Exec stz bStartProc
>LDYA ZPCMDBuf
Cmd.ExecYA >SYSCALL ExpandStr.YA
>STYA ZPPtr1 Ptr to CMD
txa
>SETG.A CMD.hCmdLine
Cmd.ExecYA.1 >SYSCALL ExpandStr.YA ldy #$ff CMD Len
>STYA ZPPtr1
>STYA ZPPtr2
stx Cmd.ExecYA.Exit.1+1
ldy #0 CMD len
lda (ZPPtr2) .1 iny
tax ARGS len=Total Len lda (ZPPtr1),y Get CMD char...
beq .2
.1 inc ZPPtr2 Next Cmd Char
bne .2
inc ZPPtr2+1
.2 lda (ZPPtr2)
cmp #" " we reached blank between CMD ARGS cmp #" " we reached blank between CMD ARGS
beq .3
iny CMD+1
dex Total=0
bne .1 bne .1
.3 tya .2 phy Y=CMD len
sta (ZPPtr1) Cut CMD
txa
sta (ZPPtr2) Cut ARGS
>LDYA L.INTCMDS >LDYA L.INTCMDS
>STYA ZPPtr3 >STYA ZPPtr2
ldx #0 ldx #0
.4 lda (ZPPtr3) .3 lda (ZPPtr2)
beq Cmd.Exec.EXT Ending 0, must be an external Cmd.... beq Cmd.Exec.EXT Array Ending 0, must be an external Cmd....
cmp (ZPPtr1) Same Len ? pla get back CMD len
bne .8 pha
tay cmp (ZPPtr2) Same Len ?
beq .5
.5 lda (ZPPtr1),y .4 inx
inx
lda ZPPtr2
sec
adc (ZPPtr2)
sta ZPPtr2
bcc .3
inc ZPPtr2+1
bra .3
.5 tay
dey
lda (ZPPtr1),y
cmp #'a' To Uppercase cmp #'a' To Uppercase
bcc .6 bcc .6
@ -109,36 +120,37 @@ Cmd.ExecYA.1 >SYSCALL ExpandStr.YA
bcs .6 bcs .6
eor #$20 eor #$20
.6 cmp (ZPPtr3),y .6 iny
bne .8 cmp (ZPPtr2),y
bne .4
dey dey
bne .6 dey
bne .5
ply get back Cmd Len
lda (ZPPtr1),y
beq .7 ARGS = ""
iny skip " "
.7 tya
clc
adc ZPPtr1
sta ZPPtr2
lda #0
adc ZPPtr1+1
sta ZPPtr2+1 ZPPtr2->ARGS
jsr Cmd.Exec.INT Found an internal Cmd... jsr Cmd.Exec.INT Found an internal Cmd...
bcs .7 bcs .9
lda #0 lda #0
.7 ldy #S.PS.RC .9 ldy #S.PS.RC
sta (pPS),y sta (pPS),y
bra Cmd.ExecYA.Exit
.8 inx Cmd.Exec.Done php
inx pha
>GETG.A CMD.hCmdLine
lda ZPPtr3
sec
adc (ZPPtr3)
sta ZPPtr3
bcc .4
inc ZPPtr3+1
bra .4
*--------------------------------------
Cmd.ExecYA.Exit php
pha
Cmd.ExecYA.Exit.1
lda #$ff
>SYSCALL FreeMem.A >SYSCALL FreeMem.A
pla pla
plp plp
@ -146,8 +158,9 @@ Cmd.ExecYA.Exit.1
*-------------------------------------- *--------------------------------------
Cmd.Exec.INT jmp (J.INTCMDS,x) Cmd.Exec.INT jmp (J.INTCMDS,x)
*-------------------------------------- *--------------------------------------
Cmd.Exec.EXT ldy #1 Cmd.Exec.EXT pla Discard CMD len
lda (ZPPtr1),y
lda (ZPPtr1)
cmp #'/' Command line is already full path, no search cmp #'/' Command line is already full path, no search
bne .10 bne .10
jmp .3 jmp .3
@ -201,7 +214,7 @@ Cmd.Exec.EXT ldy #1
.9 lda #SYSMGR.ERRSYN .9 lda #SYSMGR.ERRSYN
sec sec
.99 jmp Cmd.ExecYA.Exit .99 jmp Cmd.Exec.Done
*-------------------------------------- *--------------------------------------
* TXT : Launch "/PATH/SHELL /PATH/CMD ARGS" * TXT : Launch "/PATH/SHELL /PATH/CMD ARGS"
*-------------------------------------- *--------------------------------------
@ -241,10 +254,10 @@ Cmd.Exec.EXT.BIN
bmi .2 startproc bmi .2 startproc
>SYSCALL ExecProcessNewEnvYA >SYSCALL ExecProcessNewEnvYA
jmp Cmd.ExecYA.Exit jmp Cmd.Exec.Done
.2 >SYSCALL CreateProcessYA .2 >SYSCALL CreateProcessYA
jmp Cmd.ExecYA.Exit jmp Cmd.Exec.Done
*-------------------------------------- *--------------------------------------
* Internal Commands * Internal Commands
*-------------------------------------- *--------------------------------------
@ -374,7 +387,7 @@ Cmd.Exec.STARTPROC
ror bStartProc ror bStartProc
>LDYA L.ARGS >LDYA L.ARGS
jmp Cmd.ExecYA.1 jmp Cmd.ExecYA
*-------------------------------------- *--------------------------------------
Cmd.Exec.SET lda ARGS Cmd.Exec.SET lda ARGS
bne Cmd.Exec.SETVAR bne Cmd.Exec.SETVAR
@ -505,12 +518,11 @@ Cmd.Exec.READ lda ARGS
beq .9 beq .9
lda #0 lda #0
ldy #bSecureRead >SETG.A bSecureRead
sta (pData),y
lda pData lda pData
clc clc
adc #VarBuffer adc #CMD.VarName
sta ZPPTR1 sta ZPPTR1
lda pData+1 lda pData+1
adc #0 adc #0
@ -534,9 +546,8 @@ Cmd.Exec.READ lda ARGS
cmp #'S' cmp #'S'
bne .2 bne .2
ldy #bSecureRead
lda #$80 lda #$80
sta (pData),y >SETG.A bSecureRead
bra .1 bra .1
.2 cmp #'P' .2 cmp #'P'
@ -612,15 +623,13 @@ Cmd.Exec.SLEEP lda ARGS
rts rts
.9 jmp Cmd.Exec.ERRSYN .9 jmp Cmd.Exec.ERRSYN
*-------------------------------------- *--------------------------------------
Cmd.Exec.PAUSE ldy #bPause Cmd.Exec.PAUSE lda #$FF
lda #$80 >SETG.A bPause
sta (pData),y
clc clc
rts rts
*-------------------------------------- *--------------------------------------
Cmd.Exec.EXIT ldy #bEXIT Cmd.Exec.EXIT lda #$FF
lda #$FF >SETG.A bExit
sta (pData),y
clc clc
rts rts
*-------------------------------------- *--------------------------------------

View File

@ -12,7 +12,24 @@ CSH.TYPE.INT .EQ 2
CSH.TYPE.LONG .EQ 3 CSH.TYPE.LONG .EQ 3
CSH.TYPE.FLOAT .EQ 4 CSH.TYPE.FLOAT .EQ 4
*-------------------------------------- *--------------------------------------
CSH.Init >LDYAI 256 CSH.Init >PUSHWI 0 Aux type
>PUSHBI 4 S.FILEINFO.TYPE.TXT
>PUSHBI SYS.FOpen.R
lda #1
>SYSCALL GetArg.A
>PUSHYA
>SYSCALL LoadFile
bcs .9
>SETG.YA CSH.BufLen
txa
>SETG.A CSH.hBuf
lda #$FF
>SETG.A bExitOnEOF
>LDYAI 256
>SYSCALL GetMem0.YA >SYSCALL GetMem0.YA
bcs .9 bcs .9
txa txa
@ -123,11 +140,11 @@ CSH.Run jsr CSH.GetBuf
.5 .5
jsr CSH.RestorePtr Restore ptr to get full cmd line to execute jsr CSH.RestorePtr Restore ptr to get full cmd line to execute
>GETG.A hCmdBuf Get the buffer >GETG.A hCmdBuf Get the buffer
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>STYA ZPCMDBuf
jsr CSH.GetCharNB jsr CSH.GetCharNB
@ -135,8 +152,8 @@ CSH.Run jsr CSH.GetBuf
.6 cmp #13 .6 cmp #13
beq .7 beq .7
sta (ZPCMDBuf),y
iny iny
sta (pData),y
cpy #CmdLine.MAX cpy #CmdLine.MAX
beq .8 beq .8
@ -146,14 +163,18 @@ CSH.Run jsr CSH.GetBuf
.7 jsr CSH.GetNextCharNB Skip CR .7 jsr CSH.GetNextCharNB Skip CR
.8 tya .8 lda #0
sta (pData) sta (ZPCMDBuf),y
tya
>SETG.A CmdBuflen
lda #$ff
>SETG.A bCmdBufexec
ldy #bEcho ldy #bEcho
lda (pData),y lda (pData),y
beq .80 beq .80
>PUSHW pData >PUSHW ZPCMDBuf
>LDYA L.MSG.ECHO >LDYA L.MSG.ECHO
>SYSCALL PrintF.YA >SYSCALL PrintF.YA
@ -185,29 +206,29 @@ CSH.Quit ldy #CSH.hBuf
CSH.GetBuf ldy #CSH.hBuf CSH.GetBuf ldy #CSH.hBuf
lda (pData),y lda (pData),y
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>STYA ZPBufBase >STYA ZPCSHBufBase
ldy #CSH.BufLen ldy #CSH.BufLen
lda (pData),y lda (pData),y
clc clc
adc ZPBufBase adc ZPCSHBufBase
sta CSH.GetChar.LO+1 sta CSH.GetChar.LO+1
iny iny
lda (pData),y lda (pData),y
adc ZPBufBase+1 adc ZPCSHBufBase+1
sta CSH.GetChar.HI+1 sta CSH.GetChar.HI+1
CSH.SetBufPtr ldy #CSH.BufPtr CSH.SetBufPtr ldy #CSH.BufPtr
lda (pData),y lda (pData),y
clc clc
adc ZPBufBase adc ZPCSHBufBase
sta ZPBufPtr sta ZPCSHBufPtr
iny iny
lda (pData),y lda (pData),y
adc ZPBufBase+1 adc ZPCSHBufBase+1
sta ZPBufPtr+1 sta ZPCSHBufPtr+1
rts rts
*-------------------------------------- *--------------------------------------
CSH.GetPtrs ldy #CSH.hSymbols CSH.GetPtrs ldy #CSH.hSymbols
@ -242,14 +263,14 @@ CSH.RestorePtr phy
lda CSH.BufPtrSave lda CSH.BufPtrSave
sta (pData),y sta (pData),y
clc clc
adc ZPBufBase adc ZPCSHBufBase
sta ZPBufPtr sta ZPCSHBufPtr
iny iny
lda CSH.BufPtrSave+1 lda CSH.BufPtrSave+1
sta (pData),y sta (pData),y
adc ZPBufBase+1 adc ZPCSHBufBase+1
sta ZPBufPtr+1 sta ZPCSHBufPtr+1
ply ply
rts rts
*-------------------------------------- *--------------------------------------
@ -776,15 +797,15 @@ CSH.GetNextChar phy
.1 ply .1 ply
inc ZPBufPtr inc ZPCSHBufPtr
bne CSH.GetChar bne CSH.GetChar
inc ZPBufPtr+1 inc ZPCSHBufPtr+1
*-------------------------------------- *--------------------------------------
CSH.GetChar lda ZPBufPtr CSH.GetChar lda ZPCSHBufPtr
CSH.GetChar.LO eor #$ff Self Modified CSH.GetChar.LO eor #$ff Self Modified
bne CSH.GetChar.8 bne CSH.GetChar.8
lda ZPBufPtr+1 lda ZPCSHBufPtr+1
CSH.GetChar.HI eor #$ff Self Modified CSH.GetChar.HI eor #$ff Self Modified
bne CSH.GetChar.8 bne CSH.GetChar.8
@ -792,7 +813,7 @@ CSH.GetChar.HI eor #$ff Self Modified
sec sec
rts rts
CSH.GetChar.8 lda (ZPBufPtr) CSH.GetChar.8 lda (ZPCSHBufPtr)
clc clc
rts rts
*--------------------------------------- *---------------------------------------

View File

@ -16,9 +16,9 @@ UsrBuf256 .EQ $200
*-------------------------------------- *--------------------------------------
ZPPTR1 .EQ ZPBIN ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2 ZPPTR2 .EQ ZPBIN+2
ZPPTR3 .EQ ZPBIN+4 ZPCMDBuf .EQ ZPBIN+4
ZPBufBase .EQ ZPBIN+6 ZPCSHBufBase .EQ ZPBIN+6
ZPBufPtr .EQ ZPBIN+8 ZPCSHBufPtr .EQ ZPBIN+8
ZPCSHSymbols .EQ ZPBIN+10 ZPCSHSymbols .EQ ZPBIN+10
ZPCSHData .EQ ZPBIN+12 ZPCSHData .EQ ZPBIN+12
ZPCSHStack .EQ ZPBIN+14 ZPCSHStack .EQ ZPBIN+14
@ -102,32 +102,17 @@ L.ERR.Messages .DA ERR.Messages
*-------------------------------------- *--------------------------------------
CS.INIT jsr SetPWD CS.INIT jsr SetPWD
jsr CMD.Init
bcs .9
lda (pPs) lda (pPs)
ora #S.PS.F.EVENT Now accept events ora #S.PS.F.EVENT Now accept events
sta (pPs) sta (pPs)
ldy #S.PS.ARGC ldy #S.PS.ARGC
lda (pPs),y lda (pPs),y
beq .1 no arg, continue starting interactive beq .1 no arg, continue starting interactive
>PUSHWI 0 Aux type
>PUSHBI 4 S.FILEINFO.TYPE.TXT
>PUSHBI SYS.FOpen.R
lda #1
>SYSCALL GetArg.A
>PUSHYA
>SYSCALL LoadFile
bcs .9
>DEBUG
>SETG.YA CSH.BufLen+1
txa
>SETG.A CSH.hBuf
lda #$FF
>SETG.A bExitOnEOF
jmp CSH.Init jmp CSH.Init
@ -155,7 +140,9 @@ CS.RUN >GETG.A bReadMode READ Command ?
>SYSCALL GetChar >SYSCALL GetChar
bcs .8 bcs .8
.13 jsr CheckSleep .13 >DEBUG
jsr CheckSleep
bne .8 bne .8
>GETG.A CSH.hBuf batch mode ? >GETG.A CSH.hBuf batch mode ?
@ -167,10 +154,10 @@ CS.RUN >GETG.A bReadMode READ Command ?
.10 >GETG.A hCmdBuf Get the buffer .10 >GETG.A hCmdBuf Get the buffer
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>STYA ZPBufBase >STYA ZPCMDBuf
lda #0 reset it lda #0 reset it
sta (ZPBufBase) sta (ZPCMDBuf)
>SETG.A bSecureRead Clear password mode >SETG.A bSecureRead Clear password mode
@ -186,21 +173,19 @@ CS.RUN >GETG.A bReadMode READ Command ?
>GETG.A bCmdBufexec Something to execute ? >GETG.A bCmdBufexec Something to execute ?
bpl .1 bpl .1
jsr Cmd.Normalize jsr Cmd.Parse
>GETG.A CmdBuflen >GETG.A CmdBuflen
beq .12 Empty line beq .12 Empty line
jsr HIS.Add jsr HIS.Add
>LDYA ZPBufBase jsr Cmd.Exec
jsr Cmd.ExecYA
ldy #S.PS.RC ldy #S.PS.RC
sta (pPs),y sta (pPs),y
ldy #bEXIT >GETG.A bExit
lda (pData),y
bne CS.RUN.EXIT bne CS.RUN.EXIT
.8 clc .8 clc
@ -212,10 +197,10 @@ CS.RUN.EXIT.RTS rts
*-------------------------------------- *--------------------------------------
CS.RUN.READ >GETG.A hCmdBuf Get the buffer CS.RUN.READ >GETG.A hCmdBuf Get the buffer
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>STYA ZPBufBase >STYA ZPCMDBuf
lda #0 reset it lda #0 reset it
sta (ZPBufBase) sta (ZPCMDBuf)
.1 >SYSCALL Sleep .1 >SYSCALL Sleep
>SYSCALL GetChar >SYSCALL GetChar
@ -226,9 +211,9 @@ CS.RUN.READ >GETG.A hCmdBuf Get the buffer
>GETG.A bCmdBufexec >GETG.A bCmdBufexec
bpl .1 bpl .1
>PUSHW ZPBufBase >PUSHW ZPCMDBuf
lda #VarBuffer lda #CMD.VarName
clc clc
adc pData adc pData
tay tay
@ -236,15 +221,6 @@ CS.RUN.READ >GETG.A hCmdBuf Get the buffer
adc #0 adc #0
>PUSHYA >PUSHYA
>SYSCALL SetEnv >SYSCALL SetEnv
php
pha
ldy #VarBuffer
lda #0
sta (pData),y
pla
plp
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN.BATCH >DEBUG CS.RUN.BATCH >DEBUG
@ -252,15 +228,14 @@ CS.RUN.BATCH >DEBUG
jsr CSH.Run jsr CSH.Run
bcs .9 bcs .9
lda (pData) >GETG.A bCmdBufexec
beq .8 Empty line....nothing to do.... bpl .8 Empty line....nothing to do....
jsr Cmd.Normalize jsr Cmd.Parse
lda (pData) >GETG.A CmdBuflen
beq .8 beq .8
>LDYA pData jsr Cmd.Exec
jsr Cmd.ExecYA
.8 ldy #S.PS.RC .8 ldy #S.PS.RC
sta (pPs),y sta (pPs),y
@ -355,7 +330,7 @@ CS.CHARIN tax Save Char
* interactive mode * interactive mode
.10 >GETG.A hCmdBuf .10 >GETG.A hCmdBuf
>SYSCALL GetMemPtr.A >SYSCALL GetMemPtr.A
>STYA ZPBufBase >STYA ZPCMDBuf
>GETG.A bEscMode >GETG.A bEscMode
beq .13 beq .13
@ -389,20 +364,20 @@ CS.CHARIN tax Save Char
clc clc
rts rts
.2 lda (pData) CmdBuffer .2 >GETG.A CmdBuflen
cmp #CmdLine.MAX cmp #CmdLine.MAX
beq .8 beq .8
pha
inc inc
sta (pData)
tay
txa
sta (pData),y sta (pData),y
txa
ply
sta (ZPCMDBuf),y
tax >GETG.A bSecureRead
ldy #bSecureRead
lda (pData),y
bne .8 bne .8
txa txa
@ -508,33 +483,38 @@ PrintPrompt >LDYA L.ENV.PS1
plp plp
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CmdLine.CLR lda (pData) CmdLine.CLR ldy #0
.1 lda (ZPCMDBuf),y
beq .9 beq .9
tay
lda #8 lda #8
.1 sta (pData),y sta (pData),y
dey iny
bne .1 bne .1
jsr CmdLine.SET jsr CmdLine.SET
lda #0 lda #0
sta (pData) sta (ZPCMDBuf)
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CmdLine.DEL lda (pData) CmdLine.DEL >GETG.A CmdBuflen
beq .9 beq .9
dec
sta (pData),y
tay
lda #0
sta (pData),y
lda #8 lda #8
>SYSCALL PutChar.A >SYSCALL PutChar.A
lda (pData)
dec
sta (pData)
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CmdLine.SET >PUSHW pData CmdLine.SET >PUSHW ZPCMDBuf
>LDYA L.MSG.PSTR >LDYA L.MSG.PSTR
>SYSCALL PrintF.YA >SYSCALL PrintF.YA
rts rts
@ -615,7 +595,8 @@ bSecureRead .BS 1
Sleep .BS 4 Sleep .BS 4
VarBuffer .BS 16 CMD.hCmdLine .BS 1
CMD.VarName .BS VarLen.MAX+1
HIS.hBuf .BS 1 HIS.hBuf .BS 1
HIS.BufIndex .BS 1 HIS.BufIndex .BS 1

View File

@ -103,7 +103,7 @@ CORE.ScreenSelect
.8 rts .8 rts
*-------------------------------------- *--------------------------------------
SYS.CPULOADI .BS 1 SYS.CPULOADI .BS 1
SYS.CPULOADC .AS "|/-\" SYS.CPULOADC .AS '\|/-'
*-------------------------------------- *--------------------------------------
CORE.TskMgrRun >LDYAI TskMgr.Table+S.PS skip PS 0 CORE.TskMgrRun >LDYAI TskMgr.Table+S.PS skip PS 0
>STYA pPs >STYA pPs