A2osX/SBIN/SHELL.S.txt

474 lines
8.8 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
2015-10-19 20:35:00 +00:00
.LIST OFF
2015-03-14 21:48:35 +00:00
.OP 65C02
.OR $2000
2018-07-23 15:28:42 +00:00
.TF SBIN/SHELL
2015-03-14 21:48:35 +00:00
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
2018-10-15 06:25:40 +00:00
.INB INC/MLI.I
2018-10-02 15:52:30 +00:00
.INB INC/MLI.E.I
2015-03-14 21:48:35 +00:00
*--------------------------------------
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
2018-10-15 06:25:40 +00:00
ZPPtr3 .EQ ZPBIN+4
2018-10-19 15:26:21 +00:00
ZPCMDBuf .EQ ZPBIN+6
ZPArgVBuf .EQ ZPBIN+8
2018-09-17 06:16:45 +00:00
ZPCSHBufPtr .EQ ZPBIN+10
ZPCSHSymbols .EQ ZPBIN+12
ZPCSHData .EQ ZPBIN+14
ZPCSHValue .EQ ZPBIN+16
ZPCSHStack .EQ ZPBIN+18
2015-03-14 21:48:35 +00:00
*--------------------------------------
2018-10-19 15:26:21 +00:00
CmdLine.MAX .EQ 127
VarLen.MAX .EQ 15
History.MAX .EQ 256
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
* File Header (16 Bytes)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.START cld
jmp (.1,x)
2015-06-03 18:30:57 +00:00
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2018-09-17 06:16:45 +00:00
.DA #S.PS.F.EVENT S.PS.F
.DA #0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
2018-09-17 06:16:45 +00:00
.DA #20 ZP
2015-06-03 18:30:57 +00:00
.DA 0
*--------------------------------------
* Relocation Table
2015-10-19 20:35:00 +00:00
*--------------------------------------
2015-03-14 21:48:35 +00:00
.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
2018-09-09 08:11:42 +00:00
L.MSG.ECHOCRLF .DA MSG.ECHOCRLF
L.MSG.ERROR .DA MSG.ERROR
L.MSG.PRINTENV .DA MSG.PRINTENV
L.MSG.CSHERR .DA MSG.CSHERR
2015-10-19 20:35:00 +00:00
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 CL.BS left arrow
.DA HIS.GetNext
.DA HIS.GetPrev
.DA CL.NAK right arow
2018-09-17 06:16:45 +00:00
L.CMD.INT .DA CMD.INT
2018-10-21 20:54:07 +00:00
J.CMD.INT .DA Cmd.INT.STARTPROC
.DA Cmd.INT.CD
2018-10-15 06:25:40 +00:00
.DA Cmd.INT.DATE
.DA Cmd.INT.ECHO
.DA Cmd.INT.EXIT
.DA Cmd.INT.IF
.DA Cmd.INT.PAUSE
.DA Cmd.INT.PWD
.DA Cmd.INT.READ
.DA Cmd.INT.SET
.DA Cmd.INT.SLEEP
.DA Cmd.INT.TIME
2018-10-21 20:54:07 +00:00
L.CMD.IO .DA CMD.IO
2018-11-06 16:31:13 +00:00
J.CMD.IO .DA CMD.IO.AMP
.DA CMD.IO.PIPE
.DA CMD.IO.IN
.DA CMD.IO.OUTA
.DA CMD.IO.OUT
.DA CMD.IO.1OUTA
.DA CMD.IO.1OUT
.DA CMD.IO.2OUTA
.DA CMD.IO.2OUT
L.CSH.BOPS .DA CSH.BOPS
J.CSH.BOPS .DA CSH.BOPS.ADD
.DA CSH.BOPS.SUB
.DA CSH.BOPS.MUL
.DA CSH.BOPS.DIV
.DA CSH.BOPS.MOD
.DA CSH.BOPS.SHL
.DA CSH.BOPS.SHR
.DA CSH.BOPS.L
.DA CSH.BOPS.G
.DA CSH.BOPS.LE
.DA CSH.BOPS.GE
.DA CSH.BOPS.EQ
.DA CSH.BOPS.NE
.DA CSH.BOPS.AND
.DA CSH.BOPS.OR
.DA CSH.BOPS.EOR
.DA CSH.BOPS.LAND
.DA CSH.BOPS.LOR
L.CSH.FN .DA CSH.FN
L.CSH.KW .DA CSH.KW
2017-11-14 16:57:34 +00:00
L.CSH.STYPES .DA CSH.STYPES
J.CSH.KW .DA CSH.IF
.DA CSH.WHILE
.DA CSH.ELSE
.DA CSH.DO
.DA CSH.FOR
.DA CSH.SWITCH
.DA CSH.CASE
.DA CSH.BREAK
.DA CSH.CONTINUE
.DA CSH.FLOAT
.DA CSH.SIGNED
.DA CSH.UNSIGNED
J.CSH.STYPES .DA CSH.CHAR
.DA CSH.INT
.DA CSH.LONG
J.CSH.UTYPES .DA CSH.UCHAR
.DA CSH.UINT
.DA CSH.ULONG
J.CSH.KW.START .DA CSH.IF.START
.DA CSH.WHILE.START
J.CSH.KW.END .DA CSH.IF.END
.DA CSH.WHILE.END
L.ERR.Codes .DA ERR.Codes
L.ERR.Messages .DA ERR.Messages
2015-03-14 21:48:35 +00:00
.DA 0
*--------------------------------------
2018-10-16 15:48:03 +00:00
CS.INIT jsr SetPWD
jsr CMD.Init
bcs .9
ldy #S.PS.ARGC
lda (pPs),y
2018-10-17 15:31:29 +00:00
cmp #1
beq .1 no arg, continue starting interactive
jmp CSH.Init
.1 jsr HIS.Init
2015-10-19 20:35:00 +00:00
bcs .9
2018-08-25 11:23:59 +00:00
>PUSHWI K.VER
2018-08-22 15:23:27 +00:00
>PUSHBI 2
>LDYA L.MSG.GREETINGS
2018-06-21 15:12:10 +00:00
>SYSCALL printf
.9 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.RUN >LDA.G bReadMode READ Command ?
2018-10-24 15:36:45 +00:00
beq .22
jmp CS.RUN.READ
2018-10-17 15:31:29 +00:00
2018-10-24 15:36:45 +00:00
.22 ldy #S.PS.RC
lda (pPs),y
beq .11
jsr IO.PrintErrMsg
bcs .9
.11 >LDA.G bPause
bpl .13
>SYSCALL GetChar
bcs .8
2018-08-08 15:13:37 +00:00
>STZ.G bPause
.13 jsr CheckSleep
bne .8
>LDA.G CSH.hBuf batch mode ?
beq .10
jmp CS.RUN.BATCH
*--------------------------------------
.10 jsr CL.RESET reset CmdBuf
2018-11-07 16:11:02 +00:00
jsr IO.Reset
2018-10-24 15:36:45 +00:00
>STZ.G bSecureRead Clear password mode
2018-09-17 06:16:45 +00:00
2018-09-25 06:25:32 +00:00
jsr CL.PrintPrompt
bcs .9
.1 >SLEEP
>SYSCALL GetChar
2018-09-19 15:25:42 +00:00
bcc .21 no char
2018-07-18 15:30:42 +00:00
2018-09-19 15:25:42 +00:00
tay
beq .1
2018-10-24 15:36:45 +00:00
2018-09-19 15:25:42 +00:00
rts
2018-09-19 15:25:42 +00:00
.21 cmp #C.EOF
beq .9
2018-07-19 15:33:55 +00:00
jsr CL.CHARIN
2017-01-12 17:43:45 +00:00
>LDA.G bCmdBufExec Something to execute ?
2015-06-24 20:41:38 +00:00
bpl .1
2018-10-29 08:41:10 +00:00
lda (ZPCMDBuf)
beq .10 Empty line
2018-10-23 15:36:57 +00:00
jsr HIS.Add
2018-10-23 15:36:57 +00:00
jsr CMD.Parse
bcs .2
2018-10-21 20:54:07 +00:00
lda (ZPArgVBuf)
beq .10 Empty line
jsr CMD.Exec
bcs .2
lda #0
.2 ldy #S.PS.RC
sta (pPs),y
>LDA.G bExit
bne .80
.8 clc
2015-03-14 21:48:35 +00:00
rts
.80 lda #0
sec
.9 rts
*--------------------------------------
2018-09-17 06:16:45 +00:00
CS.RUN.READ jsr CL.RESET reset CmdBuf
2018-11-07 16:11:02 +00:00
jsr IO.Reset
2018-09-17 06:16:45 +00:00
.1 >SLEEP
>SYSCALL GetChar
bcs .1 no char
jsr CL.CHARIN
>LDA.G bCmdBufExec
bpl .1
2018-09-17 06:16:45 +00:00
>STZ.G bReadMode
lda (ZPCMDBuf)
beq .8
>PUSHW ZPCMDBuf
2018-09-06 15:36:44 +00:00
>LEA.G CMD.VarName
>SYSCALL SetEnv
rts
2018-09-17 06:16:45 +00:00
.8 clc
rts
*--------------------------------------
CS.RUN.BATCH >SYSCALL GetChar
bcs .2
cmp #3 test Ctrl-c
bne .1
sec
rts
.1 cmp #19 test Ctrl-s
bne .2
lda #$80
>STA.G bPause
clc
rts
.2 jsr CSH.Run
bcc .7
cmp #MLI.E.EOF
beq .9
pha
jsr CSH.ErrorMsg
pla
ldy #S.PS.RC
sta (pPs),y
sec
rts
.7 >LDA.G bCmdBufExec
bpl .8 Empty line....nothing to do....
2018-10-29 08:41:10 +00:00
lda (ZPCMDBuf)
beq .8
2018-09-17 06:16:45 +00:00
jsr CMD.Parse
2018-10-23 15:36:57 +00:00
bcs .8
2018-10-21 20:54:07 +00:00
lda (ZPArgVBuf)
beq .8
2018-09-17 06:16:45 +00:00
jsr CMD.Exec
bcs .8
lda #0
.8 ldy #S.PS.RC
sta (pPs),y
clc
rts
.9 lda #0
sec
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
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
2015-12-13 21:29:51 +00:00
rts
2017-01-12 17:43:45 +00:00
*--------------------------------------
2016-08-17 06:25:58 +00:00
CS.QUIT jsr HIS.Quit
jsr CSH.Quit
jsr CMD.Quit
clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
CheckSleep ldy #Sleep+3
lda (pData),y
dey
ora (pData),y
dey
ora (pData),y
dey
ora (pData),y
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
SetPWD ldy #S.PS.hPREFIX
lda (pPs),y
2018-11-08 14:23:06 +00:00
SetPWD.I >SYSCALL GetMemPtr
>PUSHYA
2018-09-06 15:36:44 +00:00
>LDYA L.ENV.PWD
>SYSCALL SetEnv
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
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.END
*--------------------------------------
2018-09-17 06:16:45 +00:00
MSG.GREETINGS .AZ "\r\nA2osX-Shell %d.%d\r\n\r\n"
MSG.PROMPT .AZ "\e[7h$ "
MSG.ECHO .AS ">%s"
MSG.ECHOCRLF .AZ "\r\n"
MSG.ERROR .AZ "[$%h]:%S.\r\n"
MSG.PRINTENV .AZ "%s=%s\r\n"
MSG.CSHERR .AZ "^\r\nLine #%D:"
FMT.DATE .AZ "%A (%w), %B %d %Y"
FMT.TIME .AZ "%H:%M:%S (%I:%M:%S%p)"
*--------------------------------------
ENV.PATH .AZ "PATH"
ENV.PWD .AZ "PWD"
ENV.PS1 .AZ "PS1"
ENV.HOME .AZ "HOME"
*--------------------------------------
2018-09-14 14:29:47 +00:00
* https://www.tldp.org/LDP/abs/html/io-redirection.html
*--------------------------------------
2018-10-21 20:54:07 +00:00
CMD.INT .AZ "STARTPROC"
.AZ "CD"
.AZ "DATE"
.AZ "ECHO"
.AZ "EXIT"
2018-09-17 06:16:45 +00:00
.AZ "IF"
.AZ "PAUSE"
.AZ "PWD"
.AZ "READ"
.AZ "SET"
.AZ "SLEEP"
.AZ "TIME"
2015-10-19 20:35:00 +00:00
.HS 00
*--------------------------------------
2018-11-06 16:31:13 +00:00
CMD.IO .AZ "&"
.AZ "|"
.AZ "<"
.AZ ">>"
.AZ ">"
.AZ "1>>"
.AZ "1>"
.AZ "2>>"
.AZ "2>"
.HS 00
*--------------------------------------
2018-09-17 06:16:45 +00:00
CMD.IF.Chars .AS "def"
CMD.IF.Chars.Cnt .EQ *-CMD.IF.Chars
*--------------------------------------
.INB /A2OSX.SRC/SBIN/SHELL.C.CSH
.INB /A2OSX.SRC/X.ERRORS.S
*--------------------------------------
EscChars .AS 'DBAC'
2018-09-14 13:08:30 +00:00
EscChars.Cnt .EQ *-EscChars
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
.DUMMY
.OR 0
2015-03-14 21:48:35 +00:00
DS.START
CmdBufPtr .BS 1
CmdBuflen .BS 1
bCmdBufexec .BS 1
2015-12-13 21:29:51 +00:00
bEscMode .BS 1
bPause .BS 1
bExit .BS 1
2018-10-16 15:48:03 +00:00
bSET.X .BS 1
bECHO.N .BS 1
bReadMode .BS 1
bSecureRead .BS 1
Sleep .BS 4
2018-10-29 08:41:10 +00:00
CMD.IntCmd .BS 1
CMD.hCmdLine .BS 1
2018-10-29 08:41:10 +00:00
CMD.hCmdBuf .BS 1
2018-10-19 15:26:21 +00:00
CMD.hArgVBuf .BS 1
2018-10-15 06:25:40 +00:00
CMD.PSFlags .BS 1
2018-09-17 06:16:45 +00:00
CMD.VarName.LEN .BS 1
CMD.VarName .BS VarLen.MAX+1
CMD.Stat .BS S.STAT
CMD.Time .BS S.TIME
2018-09-17 06:16:45 +00:00
CMD.IFNOT .BS 1
HIS.hBuf .BS 1
HIS.Count .BS 1
HIS.Index .BS 1
IO.hIn .BS 1
IO.hOut .BS 1
IO.hErr .BS 1
.INB /A2OSX.SRC/SBIN/SHELL.G.CSH
DS.END .ED
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S
2015-03-14 21:48:35 +00:00
ASM