Kernel 0.9.1 : SHELL, CSH style scripting.....(wip)

This commit is contained in:
Rémy GIBERT 2017-10-20 17:42:24 +02:00
parent cd31830346
commit a4d5f42fda
5 changed files with 212 additions and 168 deletions

Binary file not shown.

Binary file not shown.

View File

@ -27,8 +27,6 @@ CSH.Init lda #$FF
>STA.G CSH.hBuf
>SYSCALL GetMemPtr.A
>STYA ZPCSHBufPtr
>STYA.G CSH.BufBase
>LDYAI 256
>SYSCALL GetMem0.YA
@ -89,18 +87,19 @@ CSH.Run lda #0
bra .9 error, todo : PREOPS ++ --.....
.3 jsr CSH.GetLen Get the len of this possible keyword/var
.3 >LDYA L.CSHCMDS
jsr CSH.IsKeyword
bcs .4 not an internal CSH keyword....
stx CSH.CmdSave
txa
>STA.G CSH.CmdSave
jmp (J.CSHCMDS,x)
.4 jsr CSH.GetVar
.4 jsr CSH.GetVar Y=Ptr To Value
bcs .5
jsr CSH.GetCharNB
bcs .9
cmp #'='
@ -109,17 +108,16 @@ CSH.Run lda #0
jsr CSH.GetNextCharNB Skip =
bcs .99
phy
jsr CSH.ExpEval
ply
bcs .9
jsr CSH.GetChar
jsr CSH.SetVarValueAtY
bcs .9
cmp #';'
bne .99
jsr CSH.SetVar
bcs .9
jmp CSH.GetNextCharNB Skip ;
.99 lda #CSH.E.SYNTAX
@ -195,68 +193,56 @@ CSH.RestorePtr phy
ply
rts
*--------------------------------------
CSH.GetLen ldy #0 we have already a letter
.1 iny
lda (ZPCSHBufPtr),y
beq .8
jsr CSH.IsLetterOrDigit
bcc .1
CSH.IsKeyword >STYA ZPPtr1
.8 tya
>STA.G CSH.IdentLen
rts
*--------------------------------------
CSH.IsKeyword >LDYA L.CSHCMDS
>STYA ZPPtr2
jsr CSH.GetIdentLen
phy Y = kw len
ldx #0
.1 lda (ZPPtr2)
.1 lda (ZPPtr1)
beq .9 Ending 0, not found....
>LDA.G CSH.IdentLen
pla
pha Get Back Len
cmp (ZPPtr2) Same Len ?
cmp (ZPPtr1) Same Len ?
bne .4
tay
.2 lda (ZPCSHBufPtr),y
.2 lda (ZPPtr1),y
cmp #'a' To Uppercase
bcc .3
cmp #'z'+1
bcs .3
eor #$20
.3 cmp (ZPPtr2),y
.3 dey
cmp (ZPCSHBufPtr),y
bne .4
dey
tya
bne .2
>LDA.G CSH.IdentLen
pla Found keyword...
clc
adc ZPCSHBufPtr
adc ZPCSHBufPtr ..advance Ptr to char after it..
sta ZPCSHBufPtr
bcc .8
inc ZPCSHBufPtr+1
clc Found an internal Cmd...
clc
.8 rts
.4 inx
inx
lda ZPPtr2
lda ZPPtr1
sec
adc (ZPPtr2)
sta ZPPtr2
adc (ZPPtr1)
sta ZPPtr1
bcc .1
inc ZPPtr2+1
inc ZPPtr1+1
bra .1
.9 sec
.9 pla
sec
rts
*--------------------------------------
CSH.WHILE
@ -292,13 +278,13 @@ CSH.IF jsr CSH.GetCharNB
jsr CSH.GetNextCharNB Skip '{'
lda CSH.CmdSave Push "IF" or "WHILE"
>LDA.G 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...
>LDA.G CSH.BufPtrSave+1 WHILE : push loop address...
jsr CSH.Push
lda CSH.BufPtrSave
>LDA.G CSH.BufPtrSave
jsr CSH.Push
pla
@ -376,10 +362,13 @@ CSH.TYPE >STA.G CSH.ACCT
jsr CSH.IsLetter
bcs .9
jsr CSH.GetLen
jsr CSH.FindVar
jsr CSH.GetVar Already exists ?
bcc .90
jsr CSH.AddVar No, add with undefined value...
bcs .99
* Y=Ptr in DATA to Value
jsr CSH.GetCharNB
bcs .9
cmp #';'
@ -391,32 +380,33 @@ CSH.TYPE >STA.G CSH.ACCT
jsr CSH.GetNextCharNB
bcs .9
phy Save Ptr To Value
jsr CSH.ExpEval
ply
bcs .9
jsr CSH.SetVarValueAtY Update value to this var
jsr CSH.GetChar
bcs .9
cmp #';'
bne .9
.8 jsr CSH.AddVar
bcs .99
jsr CSH.GetNextCharNB Skip ;
.8 jsr CSH.GetNextCharNB Skip ;
clc
rts
.90 lda #CSH.E.DUP
sec
rts
.9 lda #CSH.E.SYNTAX
sec
.99 rts
*--------------------------------------
CSH.ExpEval jsr CSH.ZeroACC
ldy #0
jsr CSH.GetCharNB
bcs .9
cmp #')'
@ -433,6 +423,7 @@ CSH.ExpEval jsr CSH.ZeroACC
bcs .9
jsr CSH.GetNumInACC
bcs .9
@ -443,41 +434,45 @@ CSH.ExpEval jsr CSH.ZeroACC
sec
.99 rts
*--------------------------------------
CSH.GetNumInACC
CSH.GetNumInACC >LDA.G CSH.ACCT
cmp #CSH.TYPE.FLOAT
bcc .1
>PUSHWI ZPCSHBufPtr
>PUSHW ZPCSHBufPtr
>PUSHEA.G CSH.ACC
>SYSCALL StrToF
rts
.1 >PUSHBI 10
>LDA.G CSH.ACCT
* >SYSCALL StrToL
* bcs .9
* rts
.9 lda #CSH.E.SYNTAX
sec
>PUSHWI ZPCSHBufPtr
>PUSHW ZPCSHBufPtr
>PUSHEA.G CSH.ACC
>DEBUG
>SYSCALL StrToL
rts
*--------------------------------------
CSH.ZeroACC lda #0
>STA.G CSH.ACC
ldx #5
ldy #CSH.ACC
.1 sta (pData),y
iny
sta (pData),y
iny
sta (pData),y
iny
sta (pData),y
dex
bne .1
rts
*--------------------------------------
* Vars...
*--------------------------------------
CSH.AddVar jsr CSH.FindVar
bcc .97
>LDA.G CSH.SymbolsPtr
CSH.AddVar jsr CSH.GetIdentLen
sec
>ADC.G CSH.IdentLen
>ADC.G CSH.SymbolsPtr
bcs .99
adc #2 TYPE + OFS
adc #1 OFS
bcs .99
>LDA.G CSH.DataPtr
@ -485,7 +480,7 @@ CSH.AddVar jsr CSH.FindVar
>LDA.G CSH.ACCT
tax
* clc
sec +1 for Type
adc CSH.TSIZE,x
bcs .98 Out of memory
@ -494,17 +489,13 @@ CSH.AddVar jsr CSH.FindVar
jsr CSH.GetChar
.10 sta (ZPCSHSymbols),y
.1 sta (ZPCSHSymbols),y
iny
jsr CSH.GetNextChar
jsr CSH.IsLetterOrDigit
bcc .10
bcc .1
lda CSH.ACCT
sta (ZPCSHSymbols),y
iny
pla Get Back Data OFS
pha
sta (ZPCSHSymbols),y
@ -513,94 +504,98 @@ CSH.AddVar jsr CSH.FindVar
tya
>STA.G CSH.SymbolsPtr
>LEA.G CSH.ACCT
>STYA ZPPtr1 ACCT/ACC in ZPPtr1
ply Get Back Data OFS again
phy
>LDA.G CSH.ACCT
lda (ZPPtr1)
sta (ZPCSHSymbols),y Add Type to Data
iny
tax
lda CSH.TSIZE,x
lda CSH.TSIZE,x A = byte count to store
ldx #0
.1 pha
>LDA.G CSH.ACC
tax
.2 inc ZPPtr1
bne .3
inc ZPPtr1+1
.3 lda (ZPPtr1)
sta (ZPCSHData),y
iny
inx
pla
dec
bne .1
dex
bne .2
tya
>STA.G CSH.DataPtr
ply Exit with Y=Data Offset
clc
rts
.97 lda #CSH.E.DUP
sec
rts
.98 pla
.99 lda #CSH.E.OOM
sec
rts
*--------------------------------------
CSH.SetVar
CSH.SetVarValueAtY
clc
rts
*--------------------------------------
CSH.GetVar jsr CSH.FindVar
bcs .9
CSH.GetVar >LDYA ZPCSHSymbols
>STYA ZPPtr1
clc
.9 rts
*--------------------------------------
CSH.FindVar >LDYA ZPCSHSymbols
>STYA ZPPTR1
jsr CSH.GetIdentLen
phy
.1 lda (ZPPTR1)
.1 lda (ZPPtr1)
beq .9
>CMP.G CSH.IdentLen
bne .4
pla
pha
cmp (ZPPtr1)
bne .3
tay
.2 lda (ZPPTR1),y
.2 lda (ZPPtr1),y
dey
cmp (ZPCSHBufPtr),y
bne .3
dey
tya
bne .2
lda (ZPPTR1)
sec
adc ZPPTR1
sta ZPPTR1
bcc .8
inc ZPPTR1+1
pla
jsr CSH.VarSkipName
clc
.8 rts
.3 lda (ZPPTR1) skip Name
.4 sec
adc ZPPTR1
bcc .5
inc ZPPTR1+1
clc
.3 jsr CSH.VarSkipName
.5 adc #2 Skip Type+OFS
sta ZPPTR1
bcc .1
inc ZPPTR1+1
.5 inc ZPPtr1 Skip Pointer to TYPE/DATA
bne .1
inc ZPPtr1+1
bra .1
.9 sec
.9 pla
sec
rts
*--------------------------------------
CSH.VarSkipName lda (ZPPtr1)
sec
adc ZPPtr1
sta ZPPtr1
bcc .8
inc ZPPtr1+1
.8 rts
*--------------------------------------
* Stack
*--------------------------------------
CSH.Push pha
@ -655,6 +650,16 @@ CSH.CheckStack pha
*--------------------------------------
* CHAR related Subs.....
*--------------------------------------
CSH.GetIdentLen ldy #0
.1 iny
lda (ZPCSHBufPtr),y
beq .8
jsr CSH.IsLetterOrDigit
bcc .1
.8 rts
*--------------------------------------
CSH.GetCharNB jsr CSH.GetChar
bcs CSH.GetNextCharNB.RTS
jsr CSH.CheckCharNB
@ -724,6 +729,72 @@ CSH.IsDigit10 cmp #'0'
.9 sec
rts
*--------------------------------------
CSH.ErrorMsg >LDA.G CSH.hBuf
>SYSCALL GetMemPtr.A
>STYA ZPPtr1
lda #0
>STA.G CSH.LineNum
iny
>STA.G CSH.LineNum+1
.1 >LDYA ZPPtr1
>STYA ZPPtr2 Save actual line start
>INCW.G CSH.LineNum
.2 lda (ZPPtr1)
beq .6 EoF
inc ZPPtr1
bne .3
inc ZPPtr1+1
.3 cmp #$0D
bne .2 Scan until EoL
ldx ZPPtr1
cpx ZPCSHBufPtr
lda ZPPtr1+1
sbc ZPCSHBufPtr+1
bcc .1 not this line....
.4 ldy #0
.5 lda (ZPPtr2),y
beq .6
iny
cmp #$0D
beq .6
phy
>SYSCALL PutChar.A
ply
bra .5
.6 lda #$0D
>SYSCALL PutChar.A
lda #$0A
>SYSCALL PutChar.A
lda ZPCSHBufPtr
sec
sbc ZPPtr2
beq .8
tay
.7 phy
lda #'-'
>SYSCALL PutChar.A
ply
dey
bne .7
.8 >PUSHW.G CSH.LineNum
>LDYA L.MSG.CSHERR
>SYSCALL PrintF.YA
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CSH
LOAD /A2OSX.SRC/SBIN/SHELL.S

View File

@ -34,7 +34,6 @@ CSH.E.NOVERFLW .EQ $7D
CSH.E.OOM .EQ $7C
CSH.E.DUP .EQ $7B
CSH.E.UNDEF .EQ $7A
CSH.E.TOOLONG .EQ $79
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
@ -214,33 +213,9 @@ CS.RUN.BATCH jsr CSH.Run
pha
lda ZPCSHBufPtr
sec
>SBC.G CSH.BufBase
tay
jsr CSH.ErrorMsg
lda ZPCSHBufPtr+1
>SBC.G CSH.BufBase+1
>PUSHYA
>LDYA L.MSG.CSHERR
>SYSCALL PrintF.YA
jsr CSH.RestorePtr
jsr CSH.GetChar
bcs .2
>SYSCALL PutChar.A
.1 jsr CSH.GetNextChar
bcs .2
cmp #13
beq .2
>SYSCALL PutChar.A
bra .1
.2 pla
pla
ldy #S.PS.RC
sta (pPs),y
@ -510,7 +485,7 @@ MSG.PROMPT >CSTR "$ "
MSG.ECHO >CSTR ">%s\r\n"
MSG.ERROR >CSTR "[$%h]:%S.\r\n"
MSG.PRINTENV >CSTR "%s=%s\r\n"
MSG.CSHERR >CSTR "Pos %D:"
MSG.CSHERR >CSTR "^\r\nLine #%D:"
FMT.DATE >CSTR "%A, %B %d %Y"
FMT.TIME >CSTR "%H:%M:%S (%I:%M:%S%p)"
*--------------------------------------
@ -556,9 +531,10 @@ IO.hOut .BS 1
IO.hErr .BS 1
CSH.hBuf .BS 1
CSH.BufBase .BS 2
CSH.BufPtrSave .BS 2
CSH.LineNum .BS 2
CSH.hSymbols .BS 1
CSH.SymbolsPtr .BS 1
@ -568,7 +544,6 @@ CSH.DataPtr .BS 1
CSH.hStack .BS 1
CSH.StackPtr .BS 1
CSH.IdentLen .BS 1
CSH.CmdSave .BS 1
CSH.ACCT .BS 1
CSH.ACC .BS 5

View File

@ -14,16 +14,13 @@ AUTO 6
* Target buffer filled with a FLOAT (packed)
*\--------------------------------------
K.StrToF jsr K.AToF
bcs .9
>PULLW ZPPtr3
lda TXTPTR
sta (ZPPtr3)
ldy #1
lda TXTPTR
lda TXTPTR+1
sta (ZPPtr3),y
.9 rts
rts
*/--------------------------------------
* # AToF
* Convert String to 40 bits Float
@ -71,10 +68,11 @@ K.StrToUL clc Unsigned
* clc
K.StrToUL.Exit adc ZPPtr2
sta ZPPtr3
sta (ZPPtr3)
lda #0
adc ZPPtr2+1
sta ZPPtr3+1
ldy #1
sta (ZPPtr3),y
K.StrToUL.rts rts
*/--------------------------------------