Kernel version 0.9 : 'C-Style' Script Engine...

This commit is contained in:
Rémy GIBERT 2017-07-21 16:46:25 +02:00
parent 4d814cf75c
commit 76ffedf6de
5 changed files with 385 additions and 83 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5,9 +5,32 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
CSH.Reset ldy #CSH.hStack CSH.TYPE.CHAR .EQ 1
lda (pData),y CSH.TYPE.INT .EQ 2
bne .1 CSH.TYPE.LONG .EQ 3
CSH.TYPE.FLOAT .EQ 4
*--------------------------------------
CSH.Init >LDYAI 256
>SYSCALL GetMemYA
bcs .9
txa
ldy #CSH.hSymbols
sta (pData),y
lda #0
ldy #CSH.SymbolsPtr
sta (pData),y
>LDYAI 256
>SYSCALL GetMemYA
bcs .9
txa
ldy #CSH.hData
sta (pData),y
lda #0
ldy #CSH.DataPtr
sta (pData),y
>LDYAI 256 >LDYAI 256
>SYSCALL GetMemYA >SYSCALL GetMemYA
@ -16,18 +39,16 @@ CSH.Reset ldy #CSH.hStack
ldy #CSH.hStack ldy #CSH.hStack
sta (pData),y sta (pData),y
.1 lda #0 lda #0
ldy #CSH.StackPtr ldy #CSH.StackPtr
sta (pData),y sta (pData),y
* clc * clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CSH.Exec jsr CSH.GetBuffer CSH.Run jsr CSH.GetBuf
ldy #CSH.hStack jsr CSH.GetPtrs
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPCSHStack
ldy #0 ldy #0
@ -68,7 +89,7 @@ CSH.Exec jsr CSH.GetBuffer
sta (pData) sta (pData)
jsr CSH.CheckKeyword jsr CSH.CheckKeyword
bcs .5 not an internal SCRipt keyword.... bcs .5 not an internal CSH keyword....
lda #0 lda #0
sta (pData) Reset Cmdline sta (pData) Reset Cmdline
@ -95,6 +116,81 @@ CSH.Exec jsr CSH.GetBuffer
.80 clc .80 clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CSH.Quit ldy #CSH.hBuf
lda (pData),y
beq .1
>SYSCALL FreeMemA
.1 ldy #CSH.hStack
lda (pData),y
beq .2
>SYSCALL FreeMemA
.2 ldy #CSH.hData
lda (pData),y
beq .3
>SYSCALL FreeMemA
.3 ldy #CSH.hSymbols
lda (pData),y
beq .8
>SYSCALL FreeMemA
.8 rts
*--------------------------------------
CSH.GetBuf ldy #CSH.hBuf
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPBufBase
ldy #CSH.BufLen
lda (pData),y
clc
adc ZPBufBase
sta CSH.GetChar.LO+1
iny
lda (pData),y
adc ZPBufBase+1
sta CSH.GetChar.HI+1
CSH.SetBufPtr ldy #CSH.BufPtr
lda (pData),y
clc
adc ZPBufBase
sta ZPBufPtr
iny
lda (pData),y
adc ZPBufBase+1
sta ZPBufPtr+1
rts
*--------------------------------------
CSH.GetPtrs ldy #CSH.hSymbols
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPCSHSymbols
ldy #CSH.hData
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPCSHData
ldy #CSH.hStack
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPCSHStack
rts
*--------------------------------------
CSH.SavePtr ldx ZPBufPtr
stx CSH.BufPtrSave
ldx ZPBufPtr+1
stx CSH.BufPtrSave+1
rts
*--------------------------------------
CSH.CheckKeyword CSH.CheckKeyword
phy phy
>LDYA L.CSHCMDS >LDYA L.CSHCMDS
@ -142,40 +238,6 @@ CSH.CheckKeyword
sec sec
rts rts
*-------------------------------------- *--------------------------------------
CSH.GetBuffer ldy #CSH.hBuf
lda (pData),y
>SYSCALL GetMemPtrA
>STYA ZPBufBase
ldy #CSH.BufLen
lda (pData),y
clc
adc ZPBufBase
sta ZPBufEnd
iny
lda (pData),y
adc ZPBufBase+1
sta ZPBufEnd+1
CSH.SetBufPtr ldy #CSH.BufPtr
lda (pData),y
clc
adc ZPBufBase
sta ZPBufPtr
iny
lda (pData),y
adc ZPBufBase+1
sta ZPBufPtr+1
rts
*--------------------------------------
CSH.SavePtr ldx ZPBufPtr
stx CSH.BufPtrSave
ldx ZPBufPtr+1
stx CSH.BufPtrSave+1
rts
*--------------------------------------
CSH.WHILE CSH.WHILE
CSH.IF jsr CSH.GetCharNB CSH.IF jsr CSH.GetCharNB
bcs .9 bcs .9
@ -271,18 +333,69 @@ CSH.CONTINUE
sec sec
rts rts
*-------------------------------------- *--------------------------------------
CSH.ExpEval stz CSH.ACC CSH.CHAR lda #CSH.TYPE.CHAR
stz CSH.ACC+1 bra CSH.TYPE
stz CSH.ACC+2 CSH.INT lda #CSH.TYPE.INT
stz CSH.ACC+3 bra CSH.TYPE
CSH.LONG lda #CSH.TYPE.LONG
bra CSH.TYPE
CSH.FLOAT lda #CSH.TYPE.FLOAT
CSH.TYPE sta CSH.ACCT
jsr CSH.GetChar
bcs .9
cmp #' '
bne .9
jsr CSH.GetIdentInCMD
bcs .9
jsr CSH.GetCharNB
bcs .9
cmp #';'
beq .8 end of declaration, no value...
cmp #'='
bne .9
jsr CSH.GetNextCharNB
bcs .9
jsr CSH.ExpEval
bcs .9
jsr CSH.GetChar
bcs .9
cmp #';'
bne .9
.8 jsr CSH.AddVar
bcs .99
jsr CSH.GetNextCharNB Skip ;
clc
rts
.9 lda #CSHERR.SYNTAX
sec
.99 rts
*--------------------------------------
lda #CSHERR.SYNTAX
sec
rts
*--------------------------------------
CSH.ExpEval jsr CSH.ZeroACC
ldy #0 ldy #0
jsr CSH.GetCharNB jsr CSH.GetCharNB
>DEBUG
bcs .9 bcs .9
cmp #')' cmp #')'
beq .8 beq .8
cmp #';'
beq .8
jsr CSH.IsLetter Fnc or Var ? jsr CSH.IsLetter Fnc or Var ?
bcs .1 bcs .1
@ -303,24 +416,46 @@ CSH.ExpEval stz CSH.ACC
sec sec
.99 rts .99 rts
*-------------------------------------- *--------------------------------------
CSH.GetIdentInCMD
ldy #0
jsr CSH.GetNextCharNB
bcs .9
jsr CSH.IsLetter
bcs .9
.1 iny
sta CMD,y
jsr CSH.GetNextChar
bcs .8
jsr CSH.IsLetterOrDigit
bcc .1
.8 sty CMD
clc
rts
.9 lda #CSHERR.SYNTAX
sec
rts
*--------------------------------------
CSH.GetNumInACC ldy #0 CSH.GetNumInACC ldy #0
.1 iny .1 iny
cpy #10 cpy #10
beq .9 beq .9
sta (pData),y sta ARGS,y
jsr CSH.GetNextChar jsr CSH.GetNextChar
bcs .8 bcs .8
jsr CSH.IsDigit jsr CSH.IsDigit
bcc .1 bcc .1
.8 tya .8 sty ARGS
sta (pData)
>PUSHW pData
>PUSHW L.CSH.ACC >PUSHW L.CSH.ACC
>PUSHW L.ARGS
>SYSCALL AToI >SYSCALL AToI
bcs .9 bcs .9
rts rts
@ -329,6 +464,156 @@ CSH.GetNumInACC ldy #0
sec sec
rts rts
*-------------------------------------- *--------------------------------------
CSH.ZeroACC stz CSH.ACC
stz CSH.ACC+1
stz CSH.ACC+2
stz CSH.ACC+3
rts
*--------------------------------------
* Vars...
*--------------------------------------
CSH.AddVar jsr CSH.FindVar
bcc .97
ldy #CSH.SymbolsPtr
lda (pData),y
sec
adc ARGS
bcs .99
adc #2 TYPE + OFS
bcs .99
ldy #CSH.DataPtr
lda (pData),y
pha
ldx CSH.ACCT
* clc
adc CSH.TSIZE,x
bcs .98
ldx #$ff
ldy #CSH.SymbolsPtr
lda (pData),y
tay
.10 inx
lda CMD,x
sta (ZPCSHSymbols),y
iny
cpx CMD
bne .10
lda CSH.ACCT
sta (ZPCSHSymbols),y
iny
pla Get Back Data OFS
pha
sta (ZPCSHSymbols),y
iny
tya
ldy #CSH.SymbolsPtr
sta (pData),y
ply Get Back Data OFS again
ldx CSH.ACCT
lda CSH.TSIZE,x
ldx #0
.1 pha
lda CSH.ACC,x
sta (ZPCSHData),y
iny
inx
pla
dec
bne .1
tya
ldy #CSH.DataPtr
sta (pData),y
clc
rts
.97 lda #CSHERR.DUP
sec
rts
.98 pla
.99 lda #CSHERR.OOM
sec
rts
*--------------------------------------
CSH.SetVar
clc
rts
*--------------------------------------
CSH.GetVar
clc
rts
*--------------------------------------
CSH.FindVar >LDYA ZPCSHSymbols
>STYA ZPPTR1
.1 ldy #0
lda (ZPPTR1),y
beq .9
cmp CMD
bne .4
pha Save Name len...
ldx #0
.2 iny
inx
lda (ZPPTR1),y
cmp CMD,x
bne .3
cpx CMD
bne .2
pla
sec
adc ZPPTR1
sta ZPPTR1
bcc .8
inc ZPPTR1+1
clc
.8 rts
.3 pla
.4 sec
adc ZPPTR1
bcc .5
inc ZPPTR1+1
clc
.5 adc #2 Skip Type+OFS
sta ZPPTR1
bcc .1
inc ZPPTR1+1
bra .1
.9 sec
rts
*--------------------------------------
* Stack
*--------------------------------------
CSH.Push pha CSH.Push pha
ldy #CSH.StackPtr ldy #CSH.StackPtr
lda (pData),y lda (pData),y
@ -383,6 +668,8 @@ CSH.CheckStack pha
sec sec
rts rts
*-------------------------------------- *--------------------------------------
* CHAR related Subs.....
*--------------------------------------
CSH.GetCharNB jsr CSH.GetChar CSH.GetCharNB jsr CSH.GetChar
bcs CSH.GetNextCharNB.RTS bcs CSH.GetNextCharNB.RTS
jsr CSH.CheckCharNB jsr CSH.CheckCharNB
@ -426,18 +713,18 @@ CSH.GetNextChar phy
inc ZPBufPtr+1 inc ZPBufPtr+1
*-------------------------------------- *--------------------------------------
CSH.GetChar lda ZPBufPtr CSH.GetChar lda ZPBufPtr
eor ZPBufEnd CSH.GetChar.LO eor #$ff Self Modified
bne .1 bne CSH.GetChar.8
lda ZPBufPtr+1 lda ZPBufPtr+1
eor ZPBufEnd+1 CSH.GetChar.HI eor #$ff Self Modified
bne .1 bne CSH.GetChar.8
lda #MLI.ERR.EOF lda #MLI.ERR.EOF
sec sec
rts rts
.1 lda (ZPBufPtr) CSH.GetChar.8 lda (ZPBufPtr)
clc clc
rts rts
*--------------------------------------- *---------------------------------------

View File

@ -15,9 +15,10 @@ AUTO 6
ZPPTR1 .EQ ZPBIN ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2 ZPPTR2 .EQ ZPBIN+2
ZPPTR3 .EQ ZPBIN+4 ZPPTR3 .EQ ZPBIN+4
ZPBufBase .EQ ZPBIN+8 ZPBufBase .EQ ZPBIN+6
ZPBufPtr .EQ ZPBIN+10 ZPBufPtr .EQ ZPBIN+8
ZPBufEnd .EQ ZPBIN+12 ZPCSHSymbols .EQ ZPBIN+10
ZPCSHData .EQ ZPBIN+12
ZPCSHStack .EQ ZPBIN+14 ZPCSHStack .EQ ZPBIN+14
*-------------------------------------- *--------------------------------------
CmdLine.MAX .EQ 127 CmdLine.MAX .EQ 127
@ -26,6 +27,9 @@ CSH.Stack.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.DUP .EQ $7B
CSHERR.UNDEF .EQ $7A
*-------------------------------------- *--------------------------------------
* File Header (16 Bytes) * File Header (16 Bytes)
*-------------------------------------- *--------------------------------------
@ -78,6 +82,10 @@ J.CSHCMDS .DA CSH.IF
.DA CSH.WHILE .DA CSH.WHILE
.DA CSH.BREAK .DA CSH.BREAK
.DA CSH.CONTINUE .DA CSH.CONTINUE
.DA CSH.CHAR
.DA CSH.INT
.DA CSH.LONG
.DA CSH.FLOAT
J.CSHCMDS.END .DA CSH.IF.END J.CSHCMDS.END .DA CSH.IF.END
.DA CSH.WHILE.END .DA CSH.WHILE.END
L.CSH.ACC .DA CSH.ACC L.CSH.ACC .DA CSH.ACC
@ -121,7 +129,7 @@ CS.INIT jsr SetPWD
lda #$FF lda #$FF
sta (pData),y sta (pData),y
jmp CSH.Reset jmp CSH.Init
.1 jsr HIS.Init .1 jsr HIS.Init
bcs .9 bcs .9
@ -239,12 +247,15 @@ CS.RUN.READ lda #0
plp plp
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN.BATCH jsr CSH.Exec CS.RUN.BATCH jsr CSH.Run
bcs .9 bcs .9
lda (pData)
beq .8 Empty line....nothing to do....
jsr Cmd.Normalize jsr Cmd.Normalize
lda (pData) lda (pData)
beq .8 Empty line....nothing to do.... beq .8
>LDYA pData >LDYA pData
jsr Cmd.ExecYA jsr Cmd.ExecYA
@ -255,9 +266,12 @@ CS.RUN.BATCH jsr CSH.Exec
rts rts
.9 cmp #MLI.ERR.EOF .9 cmp #MLI.ERR.EOF
beq .98 bne .7
lda #0
sec
rts
pha .7 pha
ldy #CSH.BufPtr+1 ldy #CSH.BufPtr+1
>PUSHB (pData),y >PUSHB (pData),y
@ -454,18 +468,9 @@ CS.CHARIN.CTRL cpx #13 CR
*-------------------------------------- *--------------------------------------
CS.QUIT jsr HIS.Quit CS.QUIT jsr HIS.Quit
ldy #CSH.hBuf jsr CSH.Quit
lda (pData),y
beq .1
>SYSCALL FreeMemA
.1 ldy #CSH.hStack clc
lda (pData),y
beq .8
>SYSCALL FreeMemA
.8 clc
rts rts
*-------------------------------------- *--------------------------------------
CheckSleep ldy #Sleep+3 CheckSleep ldy #Sleep+3
@ -541,6 +546,10 @@ CSHCMDS >PSTR "IF"
>PSTR "WHILE" >PSTR "WHILE"
>PSTR "BREAK" >PSTR "BREAK"
>PSTR "CONTINUE" >PSTR "CONTINUE"
>PSTR "CHAR"
>PSTR "INT"
>PSTR "LONG"
>PSTR "FLOAT"
.HS 00 .HS 00
*-------------------------------------- *--------------------------------------
MSG.GREETINGS >PSTR "\r\nA2osX-Shell\r\n\r\n" MSG.GREETINGS >PSTR "\r\nA2osX-Shell\r\n\r\n"
@ -561,8 +570,11 @@ ARGS .BS 256
TIME .BS S.TIME TIME .BS S.TIME
STAT .BS S.STAT STAT .BS S.STAT
bStartProc .BS 1 bStartProc .BS 1
CSH.ACC .BS 4 CSH.TSIZE .HS 0001020405 00,CHAR,INT,LONG,FLOAT....
CSH.ARG .BS 4 CSH.ACCT .BS 1
CSH.ACC .BS 5
CSH.ARGT .BS 1
CSH.ARG .BS 5
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
.OR 0 .OR 0
@ -582,11 +594,14 @@ Sleep .BS 4
CSH.hBuf .BS 1 CSH.hBuf .BS 1
CSH.BufPtr .BS 2 CSH.BufPtr .BS 2
CSH.BufLen .BS 2 CSH.BufLen .BS 2
CSH.CmdSave .BS 1
CSH.SepSave .BS 1
CSH.BufPtrSave .BS 2 CSH.BufPtrSave .BS 2
CSH.hSymbols .BS 1
CSH.SymbolsPtr .BS 1
CSH.hData .BS 1
CSH.DataPtr .BS 1
CSH.hStack .BS 1 CSH.hStack .BS 1
CSH.StackPtr .BS 1 CSH.StackPtr .BS 1
CSH.CmdSave .BS 1
DS.END .ED DS.END .ED
*-------------------------------------- *--------------------------------------
MAN MAN