Kernel version 0.9 : SHELL, 'C-Style' Script Engine...(Cont.)

This commit is contained in:
Rémy GIBERT 2017-07-25 16:37:19 +02:00
parent 76ffedf6de
commit 3e69e89751
4 changed files with 137 additions and 64 deletions

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,8 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
*--------------------------------------
CSH.TYPE.CHAR .EQ 1 CSH.TYPE.CHAR .EQ 1
CSH.TYPE.INT .EQ 2 CSH.TYPE.INT .EQ 2
CSH.TYPE.LONG .EQ 3 CSH.TYPE.LONG .EQ 3
@ -50,13 +52,14 @@ CSH.Run jsr CSH.GetBuf
jsr CSH.GetPtrs jsr CSH.GetPtrs
ldy #0 lda #0
sta (pData) Reset Cmdline
jsr CSH.GetCharNB jsr CSH.GetCharNB
bcs .9 bcs .9
cmp #'}' End of block ? cmp #'}' End of block ?
bne .10 bne .1
jsr CSH.CheckStack must be on stack.... jsr CSH.CheckStack must be on stack....
bcs .9 bcs .9
@ -65,45 +68,79 @@ CSH.Run jsr CSH.GetBuf
tax tax
jmp (J.CSHCMDS.END,x) jmp (J.CSHCMDS.END,x)
.10 jsr CSH.SavePtr Save Ptr, in case of while,for.... .1 cmp #$0D
bne .2
cmp #$0D jmp CSH.GetNextCharNB Skip CR
beq .6 empty line...skip...
.1 iny .2 pha
sta (pData),y jsr CSH.SavePtr Save Ptr, in case of while,for....
pla
jsr CSH.IsLetter
bcc .3
cpy #CmdLine.MAX cmp #'#'
beq .8 Buffer full, try execute... beq .5 comments : pass line to shell
jsr CSH.GetNextChar bra .9 error, todo : PREOPS ++ --.....
bcs .8 EOF, try execute...
cmp #$0D EOL, skip CR and exec... .3 jsr CSH.GetName
beq .6 bcs .9
jsr CSH.CheckCharNB jsr CSH.IsKeyword
bcc .1 still in keyword....loop bcs .4 not an internal CSH keyword....
tya
sta (pData)
jsr CSH.CheckKeyword
bcs .5 not an internal CSH keyword....
lda #0
sta (pData) Reset Cmdline
stx CSH.CmdSave stx CSH.CmdSave
jmp (J.CSHCMDS,x) jmp (J.CSHCMDS,x)
.5 lda (ZPBufPtr) restore char.... .4 jsr CSH.GetVar
bra .1 bcs .5
.6 jsr CSH.GetNextChar Skip last char... jsr CSH.GetCharNB
bcs .9
cmp #'='
bne .99
jsr CSH.ExpEval
bcs .9
jsr CSH.GetChar
bcs .9
cmp #';'
bne .99
jsr CSH.SetVar
bcs .9
jmp CSH.GetNextCharNB Skip ;
.99 lda #CSHERR.SYNTAX
sec
.9 rts
.5
jsr CSH.RestorePtr Restore ptr to get full cmd line to execute
jsr CSH.GetCharNB
ldy #0
.6 cmp #13
beq .7
iny
sta (pData),y
cpy #CmdLine.MAX
beq .8
jsr CSH.GetNextChar
bcc .6
bra .8
.7 jsr CSH.GetNextCharNB Skip CR
.8 tya .8 tya
beq .80 empty line....nothing to do..
sta (pData) sta (pData)
ldy #bEcho ldy #bEcho
@ -113,8 +150,9 @@ CSH.Run jsr CSH.GetBuf
>PUSHW pData >PUSHW pData
>LDYA L.MSG.ECHO >LDYA L.MSG.ECHO
>SYSCALL PPrintFYA >SYSCALL PPrintFYA
.80 clc .80 clc
.9 rts rts
*-------------------------------------- *--------------------------------------
CSH.Quit ldy #CSH.hBuf CSH.Quit ldy #CSH.hBuf
lda (pData),y lda (pData),y
@ -185,14 +223,34 @@ CSH.GetPtrs ldy #CSH.hSymbols
>STYA ZPCSHStack >STYA ZPCSHStack
rts rts
*-------------------------------------- *--------------------------------------
CSH.SavePtr ldx ZPBufPtr CSH.SavePtr phy
stx CSH.BufPtrSave ldy #CSH.BufPtr
ldx ZPBufPtr+1 lda (pData),y
stx CSH.BufPtrSave+1 sta CSH.BufPtrSave
iny
lda (pData),y
sta CSH.BufPtrSave+1
ply
rts rts
*-------------------------------------- *--------------------------------------
CSH.CheckKeyword CSH.RestorePtr phy
phy ldy #CSH.BufPtr
lda CSH.BufPtrSave
sta (pData),y
clc
adc ZPBufBase
sta ZPBufPtr
iny
lda CSH.BufPtrSave+1
sta (pData),y
adc ZPBufBase+1
sta ZPBufPtr+1
ply
rts
*--------------------------------------
CSH.IsKeyword phy
>LDYA L.CSHCMDS >LDYA L.CSHCMDS
>STYA ZPPtr2 >STYA ZPPtr2
@ -201,12 +259,12 @@ CSH.CheckKeyword
.1 lda (ZPPtr2) .1 lda (ZPPtr2)
beq .9 Ending 0, not found.... beq .9 Ending 0, not found....
cmp (pData) Same Len ? cmp CSH.Name Same Len ?
bne .4 bne .4
tay tay
.2 lda (pData),y .2 lda CSH.Name,y
cmp #'a' To Uppercase cmp #'a' To Uppercase
bcc .3 bcc .3
@ -348,7 +406,13 @@ CSH.TYPE sta CSH.ACCT
cmp #' ' cmp #' '
bne .9 bne .9
jsr CSH.GetIdentInCMD jsr CSH.GetNextCharNB
bcs .9
jsr CSH.IsLetter
bcs .9
jsr CSH.GetName
bcs .9 bcs .9
jsr CSH.GetCharNB jsr CSH.GetCharNB
@ -402,7 +466,7 @@ CSH.ExpEval jsr CSH.ZeroACC
bra .9 bra .9
.1 jsr CSH.IsDigit number ? .1 jsr CSH.IsDigit10 number ?
bcs .9 bcs .9
jsr CSH.GetNumInACC jsr CSH.GetNumInACC
@ -416,23 +480,23 @@ CSH.ExpEval jsr CSH.ZeroACC
sec sec
.99 rts .99 rts
*-------------------------------------- *--------------------------------------
CSH.GetIdentInCMD CSH.GetName ldy #0
ldy #0
jsr CSH.GetNextCharNB
bcs .9
jsr CSH.IsLetter
bcs .9
.1 iny .1 iny
sta CMD,y sta CSH.Name,y
jsr CSH.GetNextChar jsr CSH.GetNextChar
bcs .8 bcs .8
jsr CSH.IsLetterOrDigit jsr CSH.IsLetterOrDigit
bcs .8
cpy #CSH.Name.MAX
bcc .1 bcc .1
.8 sty CMD lda #CSHERR.TOOLONG
sec
rts
.8 sty CSH.Name
clc clc
rts rts
@ -449,7 +513,7 @@ CSH.GetNumInACC ldy #0
sta ARGS,y sta ARGS,y
jsr CSH.GetNextChar jsr CSH.GetNextChar
bcs .8 bcs .8
jsr CSH.IsDigit jsr CSH.IsDigit10
bcc .1 bcc .1
.8 sty ARGS .8 sty ARGS
@ -479,7 +543,7 @@ CSH.AddVar jsr CSH.FindVar
lda (pData),y lda (pData),y
sec sec
adc ARGS adc CSH.Name
bcs .99 bcs .99
adc #2 TYPE + OFS adc #2 TYPE + OFS
@ -501,10 +565,10 @@ CSH.AddVar jsr CSH.FindVar
tay tay
.10 inx .10 inx
lda CMD,x lda CSH.Name,x
sta (ZPCSHSymbols),y sta (ZPCSHSymbols),y
iny iny
cpx CMD cpx CSH.Name
bne .10 bne .10
lda CSH.ACCT lda CSH.ACCT
@ -557,10 +621,11 @@ CSH.SetVar
clc clc
rts rts
*-------------------------------------- *--------------------------------------
CSH.GetVar CSH.GetVar jsr CSH.FindVar
bcs .9
clc clc
rts .9 rts
*-------------------------------------- *--------------------------------------
CSH.FindVar >LDYA ZPCSHSymbols CSH.FindVar >LDYA ZPCSHSymbols
>STYA ZPPTR1 >STYA ZPPTR1
@ -570,7 +635,7 @@ CSH.FindVar >LDYA ZPCSHSymbols
lda (ZPPTR1),y lda (ZPPTR1),y
beq .9 beq .9
cmp CMD cmp CSH.Name
bne .4 bne .4
pha Save Name len... pha Save Name len...
@ -580,10 +645,10 @@ CSH.FindVar >LDYA ZPCSHSymbols
.2 iny .2 iny
inx inx
lda (ZPPTR1),y lda (ZPPTR1),y
cmp CMD,x cmp CSH.Name,x
bne .3 bne .3
cpx CMD cpx CSH.Name
bne .2 bne .2
pla pla
@ -729,10 +794,15 @@ CSH.GetChar.8 lda (ZPBufPtr)
rts rts
*--------------------------------------- *---------------------------------------
CSH.IsLetterOrDigit CSH.IsLetterOrDigit
jsr CSH.IsDigit jsr CSH.IsDigit10
bcc CSH.IsLetterRTS bcc CSH.IsLetterRTS
*--------------------------------------- *---------------------------------------
CSH.IsLetter cmp #'A' CSH.IsLetter cmp #'_'
bne .1
clc
rts
.1 cmp #'A'
bcc .9 bcc .9
cmp #'Z'+1 cmp #'Z'+1
@ -747,7 +817,7 @@ CSH.IsLetter cmp #'A'
CSH.IsLetterRTS rts CSH.IsLetterRTS rts
*--------------------------------------- *---------------------------------------
CSH.IsDigit cmp #'0' CSH.IsDigit10 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

View File

@ -24,12 +24,14 @@ 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
CSH.Name.MAX .EQ 15
CSHERR.SYNTAX .EQ $7F CSHERR.SYNTAX .EQ $7F
CSHERR.SOVERFLW .EQ $7E CSHERR.SOVERFLW .EQ $7E
CSHERR.NOVERFLW .EQ $7D CSHERR.NOVERFLW .EQ $7D
CSHERR.OOM .EQ $7C CSHERR.OOM .EQ $7C
CSHERR.DUP .EQ $7B CSHERR.DUP .EQ $7B
CSHERR.UNDEF .EQ $7A CSHERR.UNDEF .EQ $7A
CSHERR.TOOLONG .EQ $79
*-------------------------------------- *--------------------------------------
* File Header (16 Bytes) * File Header (16 Bytes)
*-------------------------------------- *--------------------------------------
@ -602,6 +604,7 @@ CSH.DataPtr .BS 1
CSH.hStack .BS 1 CSH.hStack .BS 1
CSH.StackPtr .BS 1 CSH.StackPtr .BS 1
CSH.CmdSave .BS 1 CSH.CmdSave .BS 1
CSH.Name .BS CSH.Name.MAX+1
DS.END .ED DS.END .ED
*-------------------------------------- *--------------------------------------
MAN MAN