mirror of
https://github.com/A2osX/A2osX.git
synced 2024-08-15 04:29:35 +00:00
574 lines
10 KiB
Plaintext
574 lines
10 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
LOMEM $A00
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF /A2OSX.BUILD/SBIN/SHELL
|
||
*--------------------------------------
|
||
.INB /A2OSX.BUILD/INC/MACROS.I
|
||
.INB /A2OSX.BUILD/INC/A2OSX.I
|
||
.INB /A2OSX.BUILD/INC/MLI.ERR.I
|
||
*--------------------------------------
|
||
ZPPTR1 .EQ ZPBIN
|
||
ZPPTR2 .EQ ZPBIN+2
|
||
ZPCMDBuf .EQ ZPBIN+4
|
||
ZPCSHBufBase .EQ ZPBIN+6
|
||
ZPCSHBufPtr .EQ ZPBIN+8
|
||
ZPCSHSymbols .EQ ZPBIN+10
|
||
ZPCSHData .EQ ZPBIN+12
|
||
ZPCSHStack .EQ ZPBIN+14
|
||
*--------------------------------------
|
||
CmdLine.MAX .EQ 255
|
||
VarLen.MAX .EQ 15
|
||
History.MAX .EQ 256
|
||
|
||
CSH.Stack.MAX .EQ 15
|
||
CSH.Name.MAX .EQ 15
|
||
CSH.E.SYNTAX .EQ $7F
|
||
CSH.E.SOVERFLW .EQ $7E
|
||
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)
|
||
*--------------------------------------
|
||
CS.START cld
|
||
jmp (.1,x)
|
||
.DA #$61 6502,Level 1 (65c02)
|
||
.DA #1 BIN Layout Version 1
|
||
.DA 0
|
||
.DA CS.END-CS.START CS
|
||
.DA DS.END-DS.START DS
|
||
.DA #64 SS
|
||
.DA #16 ZP
|
||
.DA 0
|
||
*--------------------------------------
|
||
* Relocation Table
|
||
*--------------------------------------
|
||
.1 .DA CS.INIT
|
||
.DA CS.RUN
|
||
.DA CS.DOEVENT
|
||
.DA CS.QUIT
|
||
*--------------------------------------
|
||
L.MSG.GREETINGS .DA MSG.GREETINGS
|
||
L.MSG.PROMPT .DA MSG.PROMPT
|
||
L.MSG.ECHO .DA MSG.ECHO
|
||
L.MSG.ERROR .DA MSG.ERROR
|
||
L.MSG.PRINTENV .DA MSG.PRINTENV
|
||
L.MSG.CSHERR .DA MSG.CSHERR
|
||
L.ENV.PATH .DA ENV.PATH
|
||
L.ENV.PWD .DA ENV.PWD
|
||
L.ENV.PS1 .DA ENV.PS1
|
||
L.ENV.HOME .DA ENV.HOME
|
||
L.FMT.DATE .DA FMT.DATE
|
||
L.FMT.TIME .DA FMT.TIME
|
||
J.ESC .DA CmdLine.BS left arrow
|
||
.DA HIS.GetNext
|
||
.DA HIS.GetPrev
|
||
.DA CmdLine.NAK right arow
|
||
L.INTCMDS .DA INTCMDS
|
||
J.INTCMDS .DA Cmd.Exec.CD
|
||
.DA Cmd.Exec.DATE
|
||
.DA Cmd.Exec.ECHO
|
||
.DA Cmd.Exec.EXIT
|
||
.DA Cmd.Exec.PAUSE
|
||
.DA Cmd.Exec.PWD
|
||
.DA Cmd.Exec.READ
|
||
.DA Cmd.Exec.SET
|
||
.DA Cmd.Exec.SLEEP
|
||
.DA Cmd.Exec.STARTPROC
|
||
.DA Cmd.Exec.TIME
|
||
L.CSHCMDS .DA CSHCMDS
|
||
J.CSHCMDS .DA CSH.IF
|
||
.DA CSH.WHILE
|
||
.DA CSH.BREAK
|
||
.DA CSH.CONTINUE
|
||
.DA CSH.CHAR
|
||
.DA CSH.INT
|
||
.DA CSH.LONG
|
||
.DA CSH.FLOAT
|
||
J.CSHCMDS.END .DA CSH.IF.END
|
||
.DA CSH.WHILE.END
|
||
L.CSH.ACC .DA CSH.ACC
|
||
L.ERR.Codes .DA ERR.Codes
|
||
L.ERR.Messages .DA ERR.Messages
|
||
.DA 0
|
||
*--------------------------------------
|
||
CS.INIT jsr SetPWD
|
||
|
||
jsr CMD.Init
|
||
bcs .9
|
||
|
||
lda (pPs)
|
||
ora #S.PS.F.EVENT Now accept events
|
||
sta (pPs)
|
||
|
||
ldy #S.PS.ARGC
|
||
lda (pPs),y
|
||
|
||
beq .1 no arg, continue starting interactive
|
||
|
||
jmp CSH.Init
|
||
|
||
.1 jsr HIS.Init
|
||
bcs .9
|
||
|
||
>LDYA L.MSG.GREETINGS
|
||
>SYSCALL PrintF.YA
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.RUN >LDA.G bReadMode READ Command ?
|
||
bne CS.RUN.READ
|
||
|
||
ldy #S.PS.RC
|
||
lda (pPs),y
|
||
beq .11
|
||
jsr IO.PrintErrMsg
|
||
bcs CS.RUN.EXIT.RTS
|
||
|
||
.11 >LDA.G bPause
|
||
bpl .13
|
||
|
||
>SYSCALL GetChar
|
||
bcs .8
|
||
|
||
.13 jsr CheckSleep
|
||
bne .8
|
||
|
||
>LDA.G CSH.hBuf batch mode ?
|
||
beq .10
|
||
|
||
jmp CS.RUN.BATCH
|
||
*--------------------------------------
|
||
.10 jsr CmdLine.RESET reset CmdBuf
|
||
|
||
.12 jsr PrintPrompt
|
||
bcs CS.RUN.EXIT.RTS
|
||
|
||
.1 >SYSCALL Sleep
|
||
>SYSCALL GetChar
|
||
bcs .1 no char
|
||
|
||
jsr CS.CHARIN
|
||
|
||
>LDA.G bCmdBufExec Something to execute ?
|
||
bpl .1
|
||
|
||
>LDA.G CmdBuflen
|
||
beq .10 Empty line
|
||
|
||
jsr CMD.Parse
|
||
|
||
>LDA.G CmdBuflen
|
||
beq .10 Empty line
|
||
|
||
jsr HIS.Add
|
||
|
||
jsr CMD.Exec
|
||
bcs .2
|
||
|
||
lda #0
|
||
|
||
.2 ldy #S.PS.RC
|
||
sta (pPs),y
|
||
|
||
>LDA.G bExit
|
||
bne CS.RUN.EXIT
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
CS.RUN.EXIT lda #0
|
||
CS.RUN.EXIT.ERR sec
|
||
CS.RUN.EXIT.RTS rts
|
||
*--------------------------------------
|
||
CS.RUN.READ lda #0 reset Buffer
|
||
sta (ZPCMDBuf)
|
||
|
||
.1 >SYSCALL Sleep
|
||
>SYSCALL GetChar
|
||
bcs .1 no char
|
||
|
||
jsr CS.CHARIN
|
||
|
||
>LDA.G bCmdBufExec
|
||
bpl .1
|
||
|
||
>PUSHW ZPCMDBuf
|
||
|
||
>PUSHEA.G CMD.VarName
|
||
>SYSCALL SetEnv
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.BATCH jsr CSH.Run
|
||
bcc .7
|
||
|
||
cmp #MLI.ERR.EOF
|
||
beq .9
|
||
|
||
pha
|
||
|
||
ldy #CSH.BufPtr+1
|
||
>PUSHB (pData),y
|
||
dey
|
||
>PUSHB (pData),y
|
||
|
||
>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
|
||
|
||
ldy #S.PS.RC
|
||
sta (pPs),y
|
||
pha
|
||
|
||
ldy #bExitOnEOF
|
||
lda (pData),y
|
||
asl CS if bExitOnEOF
|
||
|
||
pla
|
||
rts
|
||
|
||
.7 >LDA.G bCmdBufExec
|
||
bpl .8 Empty line....nothing to do....
|
||
|
||
jsr Cmd.Parse
|
||
|
||
lda (ZPCMDBuf)
|
||
beq .8
|
||
|
||
jsr Cmd.Exec
|
||
bcs .8
|
||
|
||
lda #0
|
||
|
||
.8 ldy #S.PS.RC
|
||
sta (pPs),y
|
||
clc
|
||
rts
|
||
|
||
.9 lda #0
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.DOEVENT lda (pEvent)
|
||
bpl .9
|
||
|
||
jsr CheckSleep
|
||
beq .9
|
||
|
||
* ldy #Sleep already set by CheckSleep
|
||
clc
|
||
ldx #4
|
||
|
||
.1 lda (pData),y
|
||
sbc #0
|
||
sta (pData),y
|
||
iny
|
||
dex
|
||
bne .1
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.CHARIN tax Save Char
|
||
>LDA.G CSH.hBuf Batch mode ?
|
||
beq .10
|
||
* Batch Mode
|
||
cpx #3 test Ctrl-c
|
||
bne .12
|
||
|
||
>LDA.G bExitOnEOF
|
||
>STA.G bExit
|
||
clc
|
||
rts
|
||
|
||
.12 cpx #19 test Ctrl-s
|
||
bne .8
|
||
|
||
lda #$80
|
||
>STA.G bPause
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* interactive mode
|
||
.10 >LDA.G bEscMode
|
||
beq .13
|
||
|
||
cpx #'['
|
||
beq .8
|
||
|
||
lda #0
|
||
sta (pData),y Y=bEscMode
|
||
txa
|
||
|
||
ldx #EscChars.count-1
|
||
|
||
.17 cmp EscChars,x
|
||
beq .18
|
||
dex
|
||
bpl .17
|
||
clc
|
||
rts
|
||
|
||
.18 txa
|
||
asl
|
||
tax
|
||
jmp (J.ESC,x)
|
||
*--------------------------------------
|
||
.13 cpx #$20
|
||
bcc CS.CHARIN.CTRL
|
||
|
||
.1 cpx #$7f
|
||
bne .2
|
||
jmp CmdLine.DEL
|
||
|
||
.2 >LDA.G CmdBuflen
|
||
cmp #CmdLine.MAX
|
||
beq .8 Buffer full, discard...
|
||
|
||
inc
|
||
sta (pData),y
|
||
|
||
clc Len-1-Ptr !!!!!
|
||
>SBC.G CmdBufPtr
|
||
beq .30
|
||
|
||
phx
|
||
tax
|
||
>LDA.G CmdBuflen
|
||
tay
|
||
|
||
.3 lda (ZPCMDBuf),y Move from Ptr To end of buffer forward...
|
||
iny
|
||
sta (ZPCMDBuf),y
|
||
dey
|
||
dey
|
||
dex
|
||
bne .3
|
||
plx
|
||
|
||
.30 >LDA.G CmdBufPtr Insert char at Ptr
|
||
tay
|
||
txa
|
||
sta (ZPCMDBuf),y
|
||
>SYSCALL PutChar.A
|
||
|
||
>INC.G CmdBufPtr
|
||
>CMP.G CmdBuflen
|
||
bne .8
|
||
|
||
tay
|
||
lda #0
|
||
sta (ZPCMDBuf),y
|
||
|
||
clc
|
||
rts
|
||
|
||
.8 jmp CmdLine.PRINTPTR
|
||
*--------------------------------------
|
||
CS.CHARIN.CTRL
|
||
cpx #13 CR
|
||
bne .10
|
||
|
||
txa
|
||
>SYSCALL PutChar.A
|
||
lda #10
|
||
>SYSCALL PutChar.A
|
||
|
||
>LDA.G CmdBufPtr
|
||
tay
|
||
lda #0
|
||
sta (ZPCMDBuf),y
|
||
tya
|
||
>STA.G CmdBuflen
|
||
|
||
lda #$ff
|
||
>STA.G bCmdBufexec
|
||
clc
|
||
rts
|
||
|
||
.10 cpx #$1B esc
|
||
bne .11
|
||
|
||
lda #$ff
|
||
>STA.G bEscMode
|
||
clc
|
||
rts
|
||
|
||
.11 cpx #3 Ctrl-C
|
||
bne .8
|
||
|
||
jsr CmdLine.CLR
|
||
clc
|
||
rts
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.QUIT jsr HIS.Quit
|
||
jsr CSH.Quit
|
||
jsr CMD.Quit
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CheckSleep ldy #Sleep+3
|
||
lda (pData),y
|
||
dey
|
||
ora (pData),y
|
||
dey
|
||
ora (pData),y
|
||
dey
|
||
ora (pData),y
|
||
rts
|
||
*--------------------------------------
|
||
SetPWD ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr.A
|
||
>PUSHYA
|
||
>PUSHW L.ENV.PWD
|
||
>SYSCALL SetEnv
|
||
rts
|
||
*--------------------------------------
|
||
PrintPrompt >LDYA L.ENV.PS1
|
||
>SYSCALL GetEnv.YA
|
||
>SYSCALL ExpandStr.YA
|
||
phx
|
||
>PUSHYA
|
||
>LDYA L.MSG.PROMPT
|
||
>SYSCALL PrintF.YA
|
||
plx
|
||
php
|
||
pha
|
||
txa
|
||
>SYSCALL FreeMem.A
|
||
pla
|
||
plp
|
||
rts
|
||
*--------------------------------------
|
||
.INB /A2OSX.SRC/SBIN/SHELL.S.CL
|
||
.INB /A2OSX.SRC/SBIN/SHELL.S.CMD
|
||
.INB /A2OSX.SRC/SBIN/SHELL.S.CSH
|
||
.INB /A2OSX.SRC/SBIN/SHELL.S.IO
|
||
.INB /A2OSX.SRC/SBIN/SHELL.S.HIS
|
||
*--------------------------------------
|
||
CS.END
|
||
*--------------------------------------
|
||
ENV.PATH >CSTR "PATH"
|
||
ENV.PWD >CSTR "PWD"
|
||
ENV.PS1 >CSTR "PS1"
|
||
ENV.HOME >CSTR "HOME"
|
||
*--------------------------------------
|
||
INTCMDS >CSTR "CD"
|
||
>CSTR "DATE"
|
||
>CSTR "ECHO"
|
||
>CSTR "EXIT"
|
||
>CSTR "PAUSE"
|
||
>CSTR "PWD"
|
||
>CSTR "READ"
|
||
>CSTR "SET"
|
||
>CSTR "SLEEP"
|
||
>CSTR "STARTPROC"
|
||
>CSTR "TIME"
|
||
.HS 00
|
||
CSHCMDS >PSTR "IF"
|
||
>PSTR "WHILE"
|
||
>PSTR "BREAK"
|
||
>PSTR "CONTINUE"
|
||
>PSTR "CHAR"
|
||
>PSTR "INT"
|
||
>PSTR "LONG"
|
||
>PSTR "FLOAT"
|
||
.HS 00
|
||
*--------------------------------------
|
||
MSG.GREETINGS >CSTR "\r\nA2osX-Shell 0.9.1\r\n\r\n"
|
||
MSG.PROMPT >CSTR "%s$ "
|
||
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:"
|
||
FMT.DATE >CSTR "%A, %B %d %Y"
|
||
FMT.TIME >CSTR "%H:%M:%S (%I:%M:%S%p)"
|
||
*--------------------------------------
|
||
.INB /A2OSX.SRC/X.ERRORS.S
|
||
*--------------------------------------
|
||
EscChars.Count .EQ 4
|
||
EscChars .AS 'DBAC'
|
||
|
||
CSH.TSIZE .HS 0001020405 00,CHAR,INT,LONG,FLOAT....
|
||
CSH.ACCT .BS 1
|
||
CSH.ACC .BS 5
|
||
CSH.ARGT .BS 1
|
||
CSH.ARG .BS 5
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR 0
|
||
DS.START
|
||
hCmdBuf .BS 1
|
||
CmdBufPtr .BS 1
|
||
CmdBuflen .BS 1
|
||
bCmdBufexec .BS 1
|
||
|
||
bEscMode .BS 1
|
||
bPause .BS 1
|
||
bExit .BS 1
|
||
bEcho .BS 1
|
||
bExitOnEOF .BS 1
|
||
|
||
bReadMode .BS 1
|
||
bSecureRead .BS 1
|
||
|
||
Sleep .BS 4
|
||
|
||
CMD.hCmdLine .BS 1
|
||
CMD.hFullpath .BS 1
|
||
CMD.bStartProc .BS 1
|
||
CMD.VarName .BS VarLen.MAX+1
|
||
CMD.Stat .BS S.STAT
|
||
CMD.Time .BS S.TIME
|
||
|
||
HIS.hBuf .BS 1
|
||
HIS.Count .BS 1
|
||
HIS.Index .BS 1
|
||
|
||
IO.hIn .BS 1
|
||
IO.hOut .BS 1
|
||
IO.hErr .BS 1
|
||
|
||
CSH.hBuf .BS 1
|
||
CSH.BufPtr .BS 2
|
||
CSH.BufLen .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.StackPtr .BS 1
|
||
CSH.CmdSave .BS 1
|
||
CSH.Name .BS CSH.Name.MAX+1
|
||
DS.END .ED
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SBIN/SHELL.S
|
||
ASM
|