A2osX/SBIN/SHELL.S.CSH.txt

811 lines
13 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.BUILD
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 >PUSHWI 0 Aux type
>PUSHBI 4 S.FILEINFO.TYPE.TXT
>PUSHBI SYS.FOpen.R
lda #1
>SYSCALL GetArg.A
>PUSHYA
>SYSCALL LoadFile
bcs .9
>STYA.G CSH.BufLen
txa
>STA.G CSH.hBuf
lda #$FF
>STA.G bExitOnEOF
>LDYAI 256
>SYSCALL GetMem0.YA
bcs .9
txa
>STA.G CSH.hSymbols
lda #0
>STA.G CSH.SymbolsPtr
>LDYAI 256
>SYSCALL GetMem.YA
bcs .9
txa
>STA.G CSH.hData
lda #0
>STA.G CSH.DataPtr
>LDYAI 256
>SYSCALL GetMem.YA
bcs .9
txa
>STA.G CSH.hStack
lda #0
>STA.G CSH.StackPtr
* clc
.9 rts
*--------------------------------------
CSH.Run jsr CSH.GetBuf
jsr CSH.GetPtrs
lda #0
>STA.G CmdBuflen Reset Cmdline
jsr CSH.GetCharNB
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
.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
jsr CSH.SetVar
bcs .9
jmp CSH.GetNextCharNB Skip ;
.99 lda #CSH.E.SYNTAX
sec
.9 rts
.5
jsr CSH.RestorePtr Restore ptr to get full cmd line to execute
>LDA.G hCmdBuf Get the buffer
>SYSCALL GetMemPtr.A
>STYA ZPCMDBuf
jsr CSH.GetCharNB
ldy #0
.6 cmp #13
beq .7
sta (ZPCMDBuf),y
iny
cpy #CmdLine.MAX
beq .8
jsr CSH.GetNextChar
bcc .6
bra .8
.7 jsr CSH.GetNextCharNB Skip CR
.8 lda #0
sta (ZPCMDBuf),y
tya
>STA.G CmdBuflen
lda #$ff
>STA.G bCmdBufexec
>LDA.G bEcho
beq .80
>PUSHW ZPCMDBuf
>LDYA L.MSG.ECHO
>SYSCALL PrintF.YA
.80 clc
rts
*--------------------------------------
CSH.Quit >LDA.G CSH.hBuf
beq .1
>SYSCALL FreeMem.A
.1 >LDA.G CSH.hStack
beq .2
>SYSCALL FreeMem.A
.2 >LDA.G CSH.hData
beq .3
>SYSCALL FreeMem.A
.3 >LDA.G CSH.hSymbols
beq .8
>SYSCALL FreeMem.A
.8 rts
*--------------------------------------
CSH.GetBuf >LDA.G CSH.hBuf
>SYSCALL GetMemPtr.A
>STYA ZPCSHBufBase
>LDA.G CSH.BufLen
clc
adc ZPCSHBufBase
sta CSH.GetChar.LO+1
iny
lda (pData),y
adc ZPCSHBufBase+1
sta CSH.GetChar.HI+1
CSH.SetBufPtr >LDA.G CSH.BufPtr
clc
adc ZPCSHBufBase
sta ZPCSHBufPtr
iny
lda (pData),y
adc ZPCSHBufBase+1
sta ZPCSHBufPtr+1
rts
*--------------------------------------
CSH.GetPtrs >LDA.G CSH.hSymbols
>SYSCALL GetMemPtr.A
>STYA ZPCSHSymbols
>LDA.G CSH.hData
>SYSCALL GetMemPtr.A
>STYA ZPCSHData
>LDA.G CSH.hStack
>SYSCALL GetMemPtr.A
>STYA ZPCSHStack
rts
*--------------------------------------
CSH.SavePtr phy
>LDA.G CSH.BufPtr
sta CSH.BufPtrSave
iny
lda (pData),y
sta CSH.BufPtrSave+1
ply
rts
*--------------------------------------
CSH.RestorePtr phy
lda CSH.BufPtrSave
>STA.G CSH.BufPtr
clc
adc ZPCSHBufBase
sta ZPCSHBufPtr
iny
lda CSH.BufPtrSave+1
sta (pData),y
adc ZPCSHBufBase+1
sta ZPCSHBufPtr+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 #CSH.E.SYNTAX
sec
.99 rts
*--------------------------------------
CSH.IF.END jsr CSH.GetNextChar just skip ending '}'
clc
rts
*--------------------------------------
CSH.WHILE.END jsr CSH.Pop
>STA.G CSH.BufPtr
jsr CSH.Pop
>STA.G CSH.BufPtr+1
clc
rts
*--------------------------------------
CSH.BREAK
*--------------------------------------
CSH.CONTINUE
lda #CSH.E.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 #CSH.E.SYNTAX
sec
.99 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 #CSH.E.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 #CSH.E.TOOLONG
sec
rts
.8 sty CSH.Name
clc
rts
.9 lda #CSH.E.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 AToL
* bcs .9
* rts
.9 lda #CSH.E.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
>LDA.G CSH.SymbolsPtr
sec
adc CSH.Name
bcs .99
adc #2 TYPE + OFS
bcs .99
>LDA.G CSH.DataPtr
pha
ldx CSH.ACCT
* clc
adc CSH.TSIZE,x
bcs .98
ldx #$ff
>LDA.G CSH.SymbolsPtr
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
>STA.G CSH.SymbolsPtr
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
>STA.G CSH.DataPtr
clc
rts
.97 lda #CSH.E.DUP
sec
rts
.98 pla
.99 lda #CSH.E.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
>LDA.G CSH.StackPtr
tay
pla
sta (ZPCSHStack),y
iny
beq .9
tya
>STA.G CSH.StackPtr
sta (pData),y
clc
rts
.9 lda #CSH.E.SOVERFLW
sec
rts
*--------------------------------------
CSH.Pop >LDA.G CSH.StackPtr
beq .9
dec
tay
sta (pData),y
lda (ZPCSHStack),y
clc
rts
.9 lda #CSH.E.SYNTAX
sec
rts
*--------------------------------------
CSH.CheckStack pha
>LDA.G CSH.StackPtr
beq .9
dec
tay
pla
cmp (ZPCSHStack),y
bne .9
tya
>STA.G CSH.StackPtr
clc
rts
.9 lda #CSH.E.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
>INCW.G CSH.BufPtr
ply
inc ZPCSHBufPtr
bne CSH.GetChar
inc ZPCSHBufPtr+1
*--------------------------------------
CSH.GetChar lda ZPCSHBufPtr
CSH.GetChar.LO eor #$ff Self Modified
bne CSH.GetChar.8
lda ZPCSHBufPtr+1
CSH.GetChar.HI eor #$ff Self Modified
bne CSH.GetChar.8
lda #MLI.ERR.EOF
sec
rts
CSH.GetChar.8 lda (ZPCSHBufPtr)
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
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CSH
LOAD /A2OSX.SRC/SBIN/SHELL.S
ASM