Kernel version 0.9 : SHELL, enhancement in Batch mode....(Cont.)

This commit is contained in:
Rémy GIBERT 2017-07-13 17:22:13 +02:00
parent 37c8230d5c
commit 417fcfe9aa
5 changed files with 321 additions and 193 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5,19 +5,46 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
TXT.Reset ldy #CSH.SEPStack CSH.Reset ldy #CSH.hStack
tya lda (pData),y
bne .1
>LDYAI 256
>SYSCALL GetMemYA
bcs .9
txa
ldy #CSH.hStack
sta (pData),y sta (pData),y
rts
.1 lda #0
ldy #CSH.StackPtr
sta (pData),y
* clc
.9 rts
*-------------------------------------- *--------------------------------------
TXT.Exec jsr TXT.GetBuffer CSH.Exec jsr CSH.GetBuffer
ldy #CSH.hStack
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPCSHStack
ldy #0 ldy #0
jsr TXT.GetCharNB jsr CSH.GetCharNB
bcs .9 bcs .9
jsr TXT.SavePtr Save Ptr, in case of while,for.... cmp #'}' End of block ?
bne .10
jsr CSH.CheckStack must be on stack....
bcs .9
jsr CSH.Pop was expected, get stacked Cmd...
tax
jmp (J.CSHCMDS.END,x)
.10 jsr CSH.SavePtr Save Ptr, in case of while,for....
cmp #$0D cmp #$0D
beq .6 empty line...skip... beq .6 empty line...skip...
@ -26,50 +53,51 @@ TXT.Exec jsr TXT.GetBuffer
sta (pData),y sta (pData),y
cpy #CmdLine.MAX cpy #CmdLine.MAX
beq .7 Buffer full, try execute... beq .8 Buffer full, try execute...
jsr TXT.GetNextChar jsr CSH.GetNextChar
bcs .7 EOF, try execute... bcs .8 EOF, try execute...
cmp #$0D EOL, skip CR and exec... cmp #$0D EOL, skip CR and exec...
beq .6 beq .6
jsr TXT.CheckCharNB jsr CSH.CheckCharNB
bcc .1 still in keyword....loop bcc .1 still in keyword....loop
tya tya
sta (pData) sta (pData)
jsr TXT.CheckKeyword jsr CSH.CheckKeyword
bcs .5 not an internal SCRipt keyword.... bcs .5 not an internal SCRipt keyword....
lda #0 lda #0
sta (pData) Reset Cmdline sta (pData) Reset Cmdline
jmp (J.TXTCMDS,x) stx CSH.CmdSave
jmp (J.CSHCMDS,x)
.5 lda (ZPBufPtr) restore char.... .5 lda (ZPBufPtr) restore char....
bra .1 bra .1
.6 jsr TXT.GetNextChar Skip last char... .6 jsr CSH.GetNextChar Skip last char...
.7 tya .8 tya
beq .8 empty line....nothing to do.. beq .80 empty line....nothing to do..
sta (pData) sta (pData)
ldy #bEcho ldy #bEcho
lda (pData),y lda (pData),y
beq .8 beq .80
>PUSHW pData >PUSHW pData
>LDYA L.MSG.ECHO >LDYA L.MSG.ECHO
>SYSCALL PPrintFYA >SYSCALL PPrintFYA
.8 clc .80 clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
TXT.CheckKeyword CSH.CheckKeyword
phy phy
>LDYA L.TXTCMDS >LDYA L.CSHCMDS
>STYA ZPPtr2 >STYA ZPPtr2
ldx #0 ldx #0
@ -114,12 +142,12 @@ TXT.CheckKeyword
sec sec
rts rts
*-------------------------------------- *--------------------------------------
TXT.GetBuffer ldy #hBatchFile CSH.GetBuffer ldy #CSH.hBuf
lda (pData),y lda (pData),y
>SYSCALL GetMemPtrA >SYSCALL GetMemPtrA
>STYA ZPBufBase >STYA ZPBufBase
ldy #BatchFileLen ldy #CSH.BufLen
lda (pData),y lda (pData),y
clc clc
adc ZPBufBase adc ZPBufBase
@ -130,7 +158,7 @@ TXT.GetBuffer ldy #hBatchFile
adc ZPBufBase+1 adc ZPBufBase+1
sta ZPBufEnd+1 sta ZPBufEnd+1
TXT.SetBufPtr ldy #BatchFilePtr CSH.SetBufPtr ldy #CSH.BufPtr
lda (pData),y lda (pData),y
clc clc
adc ZPBufBase adc ZPBufBase
@ -142,28 +170,202 @@ TXT.SetBufPtr ldy #BatchFilePtr
sta ZPBufPtr+1 sta ZPBufPtr+1
rts rts
*-------------------------------------- *--------------------------------------
TXT.SavePtr ldx ZPBufPtr CSH.SavePtr ldx ZPBufPtr
stx CSH.SavePtr stx CSH.BufPtrSave
ldx ZPBufPtr+1 ldx ZPBufPtr+1
stx CSH.SavePtr+1 stx CSH.BufPtrSave+1
rts rts
*-------------------------------------- *--------------------------------------
TXT.PushPtr rts CSH.WHILE
CSH.IF jsr CSH.GetCharNB
bcs .9
cmp #'('
bne .9
jsr CSH.GetNextCharNB
bcs .9
jsr CSH.ExpEval
bcs .99
jsr CSH.GetCharNB
bcs .99
cmp #')'
bne .9
jsr CSH.GetNextCharNB
bcs .99
cmp #'{'
bne .9
lda CSH.ACC
ora CSH.ACC+1
ora CSH.ACC+2
ora CSH.ACC+3
beq .6 eval returned false, skip {{....}}
jsr CSH.GetNextCharNB Skip '{'
lda CSH.CmdSave Push "IF" or "WHILE"
beq .1 if "IF", no need to push Saved Ptr
pha
lda CSH.BufPtrSave+1 WHILE : push loop address...
jsr CSH.Push
lda CSH.BufPtrSave
jsr CSH.Push
pla
.1 jsr CSH.Push
bcs .99
lda #'}' Tell '}' is expected at the end of block
jsr CSH.Push
bcs .99
rts
.6 ldx #1 expecting 1 '}' for now....
.7 jsr CSH.GetNextChar
bcs .9
cmp #'{'
bne .71
inx
bra .7
.71 cmp #'}'
bne .7
txa
beq .9
dex
bne .7
jsr CSH.GetNextChar
clc
rts
.9 lda #CSHERR.SYNTAX
sec
.99 rts
*-------------------------------------- *--------------------------------------
TXT.GetCharNB jsr TXT.GetChar CSH.IF.END jsr CSH.GetNextChar just skip ending '}'
bcs TXT.GetNextCharNB.RTS clc
jsr TXT.CheckCharNB
bcc TXT.GetNextCharNB.RTS
*--------------------------------------
TXT.GetNextCharNB
jsr TXT.GetNextChar
bcs TXT.GetNextCharNB.RTS
jsr TXT.CheckCharNB
bcs TXT.GetNextCharNB
TXT.GetNextCharNB.RTS
rts rts
*-------------------------------------- *--------------------------------------
TXT.CheckCharNB cmp #32 SPACE CSH.WHILE.END jsr CSH.Pop
ldy #CSH.BufPtr
sta (pData),y
jsr CSH.Pop
ldy #CSH.BufPtr+1
sta (pData),y
clc
rts
*--------------------------------------
CSH.BREAK
*--------------------------------------
CSH.CONTINUE
lda #CSHERR.SYNTAX
sec
rts
*--------------------------------------
CSH.Push pha
ldy #CSH.StackPtr
lda (pData),y
tay
pla
sta (ZPCSHStack),y
iny
beq .9
tya
ldy #CSH.StackPtr
sta (pData),y
clc
rts
.9 lda #CSHERR.SOVERFLW
sec
rts
*--------------------------------------
CSH.Pop ldy #CSH.StackPtr
lda (pData),y
beq .9
dec
tay
sta (pData),y
lda (ZPCSHStack),y
clc
rts
.9 lda #CSHERR.SYNTAX
sec
rts
*--------------------------------------
CSH.CheckStack pha
ldy #CSH.StackPtr
lda (pData),y
beq .9
dec
tay
pla
cmp (ZPCSHStack),y
bne .9
tya
ldy #CSH.StackPtr
sta (pData),y
clc
rts
.9 lda #CSHERR.SYNTAX
sec
rts
*--------------------------------------
CSH.ExpEval stz CSH.ACC
stz CSH.ACC+1
stz CSH.ACC+2
stz CSH.ACC+3
jsr CSH.GetCharNB
bcs .9
cmp #')'
beq .8
jsr CSH.IsLetter Fnc or Var ?
bne .1
.1
.8 clc
rts
.9 lda #CSHERR.SYNTAX
sec
rts
*---------------------------------------
CSH.IsLetterOrDigit
jsr CSH.IsDigit
bcc CSH.IsLetterRTS
*--------------------------------------
CSH.GetCharNB jsr CSH.GetChar
bcs CSH.GetNextCharNB.RTS
jsr CSH.CheckCharNB
bcc CSH.GetNextCharNB.RTS
*--------------------------------------
CSH.GetNextCharNB
jsr CSH.GetNextChar
bcs CSH.GetNextCharNB.RTS
jsr CSH.CheckCharNB
bcs CSH.GetNextCharNB
CSH.GetNextCharNB.RTS
rts
*--------------------------------------
CSH.CheckCharNB cmp #32 SPACE
beq .9 beq .9
cmp #13 CR cmp #13 CR
beq .9 beq .9
@ -174,8 +376,8 @@ TXT.CheckCharNB cmp #32 SPACE
clc clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
TXT.GetNextChar phy CSH.GetNextChar phy
ldy #BatchFilePtr ldy #CSH.BufPtr
lda (pData),y lda (pData),y
inc inc
sta (pData),y sta (pData),y
@ -189,10 +391,10 @@ TXT.GetNextChar phy
.1 ply .1 ply
inc ZPBufPtr inc ZPBufPtr
bne TXT.GetChar bne CSH.GetChar
inc ZPBufPtr+1 inc ZPBufPtr+1
*-------------------------------------- *--------------------------------------
TXT.GetChar lda ZPBufPtr CSH.GetChar lda ZPBufPtr
eor ZPBufEnd eor ZPBufEnd
bne .1 bne .1
@ -208,15 +410,11 @@ TXT.GetChar lda ZPBufPtr
clc clc
rts rts
*--------------------------------------- *---------------------------------------
TXT.IsLetterOrDigit CSH.IsLetter cmp #'A'
jsr TXT.IsDigit
bcc TXT.IsLetterRTS
*---------------------------------------
TXT.IsLetter cmp #'A'
bcc .9 bcc .9
cmp #'Z'+1 cmp #'Z'+1
bcc TXT.IsLetterRTS bcc CSH.IsLetterRTS
cmp #'a' cmp #'a'
bcc .9 bcc .9
@ -225,9 +423,9 @@ TXT.IsLetter cmp #'A'
.9 sec .9 sec
TXT.IsLetterRTS rts CSH.IsLetterRTS rts
*--------------------------------------- *---------------------------------------
TXT.IsDigit cmp #'0' CSH.IsDigit cmp #'0'
bcc .9 bcc .9
cmp #'9'+1 cmp #'9'+1
rts cc if ok, cs if not rts cc if ok, cs if not
@ -235,117 +433,7 @@ TXT.IsDigit cmp #'0'
.9 sec .9 sec
rts rts
*-------------------------------------- *--------------------------------------
TXT.Exec.IF jsr TXT.GetCharNB
bcs .9
cmp #'('
bne .9
jsr TXT.ExpEval
bcs .99
jsr TXT.GetCharNB
bcs .99
cmp #')'
bne .9
jsr TXT.GetNextCharNB
bcs .99
cmp #'{'
bne .9
lda CSH.ACC
ora CSH.ACC+1
ora CSH.ACC+2
ora CSH.ACC+3
beq .6 eval returned false, skip {{....}}
jsr TXT.GetNextCharNB Skip '{'
lda #'}' Tell '}' is expected at the end of block
jsr TXT.PushSEP
bcs .99
rts
.6 ldx #1 expecting 1 '}'
.7 jsr TXT.GetNextChar
bcs .9
cmp #'{'
bne .71
inx
bra .7
.71 cmp #'}'
bne .7
dex
bne .7
clc
rts
.9 lda #SYSMGR.ERRSYN
sec
.99 rts
*--------------------------------------
TXT.PushSEP tax
ldy #CSH.SEPStack
lda (pData),y
cmp #CSH.SEPStack+CSH.Stack.MAX
beq .9
pha
inc
sta (pData),y
ply
txa
sta (pData),y
clc
rts
.9 lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
TXT.PopSEP ldy #CSH.SEPStack
lda (pData),y
cmp #CSH.SEPStack
beq .9
dec
sta (pData),y
clc
rts
.9 lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
TXT.CheckSEP tax
ldy #CSH.SEPStack
lda (pData),y
cmp #CSH.SEPStack
beq .9
tay
txa
cmp (pData),y
bne .9
clc
rts
.9 lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
TXT.ExpEval jsr TXT.GetNextCharNB
bcs .9
lda #1
sta CSH.ACC
clc
.9 rts
*--------------------------------------
MAN MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.TXT SAVE /A2OSX.SRC/SBIN/SHELL.S.CSH
LOAD /A2OSX.SRC/SBIN/SHELL.S LOAD /A2OSX.SRC/SBIN/SHELL.S
ASM ASM

View File

@ -18,10 +18,14 @@ ZPPTR3 .EQ ZPBIN+4
ZPBufBase .EQ ZPBIN+8 ZPBufBase .EQ ZPBIN+8
ZPBufPtr .EQ ZPBIN+10 ZPBufPtr .EQ ZPBIN+10
ZPBufEnd .EQ ZPBIN+12 ZPBufEnd .EQ ZPBIN+12
ZPCSHStack .EQ ZPBIN+14
*-------------------------------------- *--------------------------------------
CmdLine.MAX .EQ 127 CmdLine.MAX .EQ 127
VarLen.MAX .EQ 15 VarLen.MAX .EQ 15
CSH.Stack.MAX .EQ 15 CSH.Stack.MAX .EQ 15
CSHERR.SYNTAX .EQ $7F
CSHERR.SOVERFLW .EQ $7E
CSHERR.NOVERFLW .EQ $7D
*-------------------------------------- *--------------------------------------
* File Header (16 Bytes) * File Header (16 Bytes)
*-------------------------------------- *--------------------------------------
@ -47,6 +51,7 @@ L.MSG.PROMPT .DA MSG.PROMPT
L.MSG.ECHO .DA MSG.ECHO L.MSG.ECHO .DA MSG.ECHO
L.MSG.ERROR .DA MSG.ERROR L.MSG.ERROR .DA MSG.ERROR
L.MSG.PRINTENV .DA MSG.PRINTENV L.MSG.PRINTENV .DA MSG.PRINTENV
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
@ -67,18 +72,27 @@ J.INTCMDS .DA Cmd.Exec.CD
.DA Cmd.Exec.SET .DA Cmd.Exec.SET
.DA Cmd.Exec.STARTPROC .DA Cmd.Exec.STARTPROC
.DA Cmd.Exec.TIME .DA Cmd.Exec.TIME
L.TXTCMDS .DA TXTCMDS L.CSHCMDS .DA CSHCMDS
J.TXTCMDS .DA TXT.Exec.IF J.CSHCMDS .DA CSH.IF
.DA CSH.WHILE
.DA CSH.BREAK
.DA CSH.CONTINUE
J.CSHCMDS.END .DA CSH.IF.END
.DA CSH.WHILE.END
L.ERR.Codes .DA ERR.Codes L.ERR.Codes .DA ERR.Codes
L.ERR.Messages .DA ERR.Messages L.ERR.Messages .DA ERR.Messages
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
CS.INIT jsr SetPWD CS.INIT jsr SetPWD
* lda (pPs)
* ora #S.PS.F.EVENT Now accept events
* sta (pPs)
>SYSCALL GetArgC >SYSCALL GetArgC
cmp #1 cmp #1
beq CS.INIT.INTERACTIVE no arg, continue starting interactive beq .1 no arg, continue starting interactive
>PUSHWI 0 Aux type >PUSHWI 0 Aux type
>PUSHBI 4 S.FILEINFO.TYPE.TXT >PUSHBI 4 S.FILEINFO.TYPE.TXT
@ -91,37 +105,29 @@ CS.INIT jsr SetPWD
bcs .9 bcs .9
phy phy
ldy #BatchFileLen+1 ldy #CSH.BufLen+1
sta (pData),y sta (pData),y
dey dey
pla pla
sta (pData),y sta (pData),y
txa txa
ldy #hBatchFile ldy #CSH.hBuf
sta (pData),y sta (pData),y
ldy #bExitOnEOF ldy #bExitOnEOF
lda #$FF lda #$FF
sta (pData),y sta (pData),y
jsr TXT.Reset jmp CSH.Reset
clc .1 jsr HIS.Init
.9 rts
*--------------------------------------
CS.INIT.INTERACTIVE
jsr HIS.Init
bcs .9 bcs .9
>LDYA L.MSG.GREETINGS >LDYA L.MSG.GREETINGS
>SYSCALL PPrintFYA >SYSCALL PPrintFYA
lda (pPs) * clc
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CS.RUN ldy #bPause CS.RUN ldy #bPause
@ -139,7 +145,7 @@ CS.RUN ldy #bPause
jsr ERR.Print jsr ERR.Print
bcs CS.RUN.EXIT.RTS bcs CS.RUN.EXIT.RTS
.11 ldy #hBatchFile batch mode ? .11 ldy #CSH.hBuf batch mode ?
lda (pData),y lda (pData),y
beq .10 beq .10
@ -225,7 +231,7 @@ CS.RUN.READ lda #0
plp plp
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN.BATCH jsr TXT.Exec CS.RUN.BATCH jsr CSH.Exec
bcs .9 bcs .9
jsr CmdBuffer.Normalize jsr CmdBuffer.Normalize
@ -241,25 +247,50 @@ CS.RUN.BATCH jsr TXT.Exec
rts rts
.9 cmp #MLI.ERR.EOF .9 cmp #MLI.ERR.EOF
bne .8 beq .98
lda #0 pha
ldy #S.PS.RC ldy #CSH.BufPtr+1
>PUSHB (pData),y
dey
>PUSHB (pData),y
>LDYA L.MSG.CSHERR
>SYSCALL PPrintFYA
.90 jsr CSH.GetChar
bcs .91
>SYSCALL PutCA
jsr CSH.GetNextChar
bcs .91
cmp #13
beq .91
>SYSCALL PutCA
bra .90
.91 pla
bra .99
.98 lda #0
.99 ldy #S.PS.RC
sta (pPs),y sta (pPs),y
pha
ldy #bExitOnEOF ldy #bExitOnEOF
lda (pData),y lda (pData),y
asl CS if bExitOnEOF asl CS if bExitOnEOF
lda #0
pla
rts rts
*-------------------------------------- *--------------------------------------
CS.DOEVENT sec CS.DOEVENT sec
rts rts
*-------------------------------------- *--------------------------------------
CS.CHARIN tax CS.CHARIN tax
ldy #hBatchFile Batch mode ? ldy #CSH.hBuf Batch mode ?
lda (pData),y lda (pData),y
beq .10 beq .10
* Batch Mode * Batch Mode
@ -397,12 +428,17 @@ CS.CHARIN.CTRL cpx #13 CR
*-------------------------------------- *--------------------------------------
CS.QUIT jsr HIS.Quit CS.QUIT jsr HIS.Quit
ldy #hBatchFile ldy #CSH.hBuf
lda (pData),y lda (pData),y
beq .1 beq .1
>SYSCALL FreeMemA >SYSCALL FreeMemA
.1 .1 ldy #CSH.hStack
lda (pData),y
beq .8
>SYSCALL FreeMemA
.8 clc .8 clc
rts rts
*-------------------------------------- *--------------------------------------
@ -501,9 +537,9 @@ CmdBuffer.DEL lda (pData)
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
.INB /A2OSX.SRC/SBIN/SHELL.S.CMD .INB /A2OSX.SRC/SBIN/SHELL.S.CMD
.INB /A2OSX.SRC/SBIN/SHELL.S.CSH
.INB /A2OSX.SRC/SBIN/SHELL.S.ERR .INB /A2OSX.SRC/SBIN/SHELL.S.ERR
.INB /A2OSX.SRC/SBIN/SHELL.S.HIS .INB /A2OSX.SRC/SBIN/SHELL.S.HIS
.INB /A2OSX.SRC/SBIN/SHELL.S.TXT
*-------------------------------------- *--------------------------------------
CS.END CS.END
*-------------------------------------- *--------------------------------------
@ -521,7 +557,7 @@ INTCMDS >PSTR "CD"
>PSTR "STARTPROC" >PSTR "STARTPROC"
>PSTR "TIME" >PSTR "TIME"
.HS 00 .HS 00
TXTCMDS >PSTR "IF" CSHCMDS >PSTR "IF"
>PSTR "WHILE" >PSTR "WHILE"
>PSTR "BREAK" >PSTR "BREAK"
>PSTR "CONTINUE" >PSTR "CONTINUE"
@ -532,6 +568,7 @@ MSG.PROMPT >PSTR "%S$ "
MSG.ECHO >PSTR ">%S\r\n" MSG.ECHO >PSTR ">%S\r\n"
MSG.ERROR >PSTR "Err:%S [%h]\r\n" MSG.ERROR >PSTR "Err:%S [%h]\r\n"
MSG.PRINTENV >PSTR "%S=%S\r\n" MSG.PRINTENV >PSTR "%S=%S\r\n"
MSG.CSHERR >PSTR "Pos %D:"
FMT.DATE >PSTR "%A, %B %d %Y" FMT.DATE >PSTR "%A, %B %d %Y"
FMT.TIME >PSTR "%H:%M:%S (%I:%M:%S%p)" FMT.TIME >PSTR "%H:%M:%S (%I:%M:%S%p)"
*-------------------------------------- *--------------------------------------
@ -561,11 +598,14 @@ bExitOnEOF .BS 1
hCmdHistory .BS 1 hCmdHistory .BS 1
CmdHistory.IDX .BS 1 CmdHistory.IDX .BS 1
CmdHistory.END .BS 1 CmdHistory.END .BS 1
hBatchFile .BS 1 CSH.hBuf .BS 1
BatchFilePtr .BS 2 CSH.BufPtr .BS 2
BatchFileLen .BS 2 CSH.BufLen .BS 2
CSH.SavePtr .BS 2 CSH.CmdSave .BS 1
CSH.SEPStack .BS CSH.Stack.MAX+1 CSH.SepSave .BS 1
CSH.BufPtrSave .BS 2
CSH.hStack .BS 1
CSH.StackPtr .BS 1
DS.END .ED DS.END .ED
*-------------------------------------- *--------------------------------------
MAN MAN