A2osX/SBIN/SHELL.S.CSH.txt

831 lines
13 KiB
Plaintext
Raw Normal View History

2016-08-17 06:25:58 +00:00
PR#3
PREFIX /A2OSX.BUILD
2016-08-17 06:25:58 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
*--------------------------------------
CSH.TYPE.CHAR .EQ 1
CSH.TYPE.INT .EQ 2
CSH.TYPE.LONG .EQ 3
CSH.TYPE.FLOAT .EQ 4
*--------------------------------------
CSH.Init >LDYAI 256
>SYSCALL GetMem0YA
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
>SYSCALL GetMemYA
bcs .9
txa
ldy #CSH.hStack
sta (pData),y
lda #0
ldy #CSH.StackPtr
sta (pData),y
* clc
.9 rts
*--------------------------------------
CSH.Run jsr CSH.GetBuf
jsr CSH.GetPtrs
lda #0
sta (pData) Reset Cmdline
jsr CSH.GetCharNB
2016-08-17 06:25:58 +00:00
bcs .9
cmp #'}' End of block ?
bne .1
jsr CSH.CheckStack must be on stack....
bcs .9
jsr CSH.Pop was expected, get stacked Cmd...
tax
jmp (J.CSHCMDS.END,x)
.1 cmp #$0D
bne .2
jmp CSH.GetNextCharNB Skip CR
2016-08-17 06:25:58 +00:00
.2 pha
jsr CSH.SavePtr Save Ptr, in case of while,for....
pla
jsr CSH.IsLetter
bcc .3
cmp #'#'
beq .5 comments : pass line to shell
bra .9 error, todo : PREOPS ++ --.....
.3 jsr CSH.GetName
bcs .9
jsr CSH.IsKeyword
bcs .4 not an internal CSH keyword....
stx CSH.CmdSave
jmp (J.CSHCMDS,x)
.4 jsr CSH.GetVar
bcs .5
jsr CSH.GetCharNB
bcs .9
cmp #'='
bne .99
jsr CSH.GetNextCharNB Skip =
bcs .99
jsr CSH.ExpEval
bcs .9
jsr CSH.GetChar
bcs .9
cmp #';'
bne .99
2016-08-17 06:25:58 +00:00
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
sta (pData)
ldy #bEcho
2016-08-17 06:25:58 +00:00
lda (pData),y
beq .80
2016-08-17 06:25:58 +00:00
>PUSHW pData
>LDYA L.MSG.ECHO
>SYSCALL PrintFYA
.80 clc
rts
2016-08-17 06:25:58 +00:00
*--------------------------------------
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 phy
ldy #CSH.BufPtr
lda (pData),y
sta CSH.BufPtrSave
iny
lda (pData),y
sta CSH.BufPtrSave+1
ply
rts
*--------------------------------------
CSH.RestorePtr 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
>STYA ZPPtr2
ldx #0
.1 lda (ZPPtr2)
beq .9 Ending 0, not found....
cmp CSH.Name Same Len ?
bne .4
tay
.2 lda CSH.Name,y
cmp #'a' To Uppercase
bcc .3
cmp #'z'+1
bcs .3
eor #$20
.3 cmp (ZPPtr2),y
bne .4
dey
bne .2
ply
clc Found an internal Cmd...
rts
.4 inx
inx
lda ZPPtr2
sec
adc (ZPPtr2)
sta ZPPtr2
bcc .1
inc ZPPtr2+1
bra .1
.9 ply
sec
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
*--------------------------------------
CSH.IF.END jsr CSH.GetNextChar just skip ending '}'
clc
rts
*--------------------------------------
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.CHAR lda #CSH.TYPE.CHAR
bra CSH.TYPE
CSH.INT lda #CSH.TYPE.INT
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.GetNextCharNB
bcs .9
jsr CSH.IsLetter
bcs .9
jsr CSH.GetName
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
jsr CSH.GetCharNB
bcs .9
cmp #')'
beq .8
cmp #';'
beq .8
jsr CSH.IsLetter Fnc or Var ?
bcs .1
bra .9
.1 jsr CSH.IsDigit10 number ?
bcs .9
jsr CSH.GetNumInACC
bcs .9
.8 clc
rts
.9 lda #CSHERR.SYNTAX
sec
.99 rts
*--------------------------------------
CSH.GetName ldy #0
.1 iny
sta CSH.Name,y
jsr CSH.GetNextChar
bcs .8
jsr CSH.IsLetterOrDigit
bcs .8
cpy #CSH.Name.MAX
bcc .1
lda #CSHERR.TOOLONG
sec
rts
.8 sty CSH.Name
clc
rts
.9 lda #CSHERR.SYNTAX
sec
rts
*--------------------------------------
CSH.GetNumInACC ldy #0
.1 iny
cpy #10
beq .9
sta ARGS,y
jsr CSH.GetNextChar
bcs .8
jsr CSH.IsDigit10
bcc .1
.8 sty ARGS
>PUSHW L.CSH.ACC
>PUSHW L.ARGS
>SYSCALL AToI
bcs .9
rts
.9 lda #CSHERR.SYNTAX
sec
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 CSH.Name
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 CSH.Name,x
sta (ZPCSHSymbols),y
iny
cpx CSH.Name
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 jsr CSH.FindVar
bcs .9
clc
.9 rts
*--------------------------------------
CSH.FindVar >LDYA ZPCSHSymbols
>STYA ZPPTR1
.1 ldy #0
lda (ZPPTR1),y
beq .9
cmp CSH.Name
bne .4
pha Save Name len...
ldx #0
.2 iny
inx
lda (ZPPTR1),y
cmp CSH.Name,x
bne .3
cpx CSH.Name
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
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
*--------------------------------------
* CHAR related Subs.....
*--------------------------------------
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
cmp #13 CR
beq .9
cmp #10 LF
beq .9
cmp #8 TAB
beq .9
clc
.9 rts
*--------------------------------------
CSH.GetNextChar phy
ldy #CSH.BufPtr
lda (pData),y
inc
sta (pData),y
bne .1
iny
lda (pData),y
inc
sta (pData),y
.1 ply
inc ZPBufPtr
bne CSH.GetChar
inc ZPBufPtr+1
*--------------------------------------
CSH.GetChar lda ZPBufPtr
CSH.GetChar.LO eor #$ff Self Modified
bne CSH.GetChar.8
lda ZPBufPtr+1
CSH.GetChar.HI eor #$ff Self Modified
bne CSH.GetChar.8
lda #MLI.ERR.EOF
sec
rts
CSH.GetChar.8 lda (ZPBufPtr)
clc
rts
*---------------------------------------
CSH.IsLetterOrDigit
jsr CSH.IsDigit10
bcc CSH.IsLetterRTS
*---------------------------------------
CSH.IsLetter cmp #'_'
bne .1
clc
rts
.1 cmp #'A'
bcc .9
cmp #'Z'+1
bcc CSH.IsLetterRTS
cmp #'a'
bcc .9
cmp #'z'+1
rts CC if lowercase
.9 sec
CSH.IsLetterRTS rts
*---------------------------------------
CSH.IsDigit10 cmp #'0'
bcc .9
cmp #'9'+1
rts cc if ok, cs if not
.9 sec
rts
2016-08-17 06:25:58 +00:00
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CSH
LOAD /A2OSX.SRC/SBIN/SHELL.S
2016-08-17 06:25:58 +00:00
ASM