Kernel 0.92 : SHELL, Added IF ELSE FI and I/O redirection

This commit is contained in:
Rémy GIBERT 2018-11-12 22:34:55 +01:00
parent 4a42278c60
commit 597d56d4ff
10 changed files with 134 additions and 77 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -156,7 +156,6 @@ CS.RUN.PRINT sty BytesRead Y,A = Bytes read
>INCW.G LineNum
>LDA.G bSuppressBlankLine
lda (pData),y
bpl .10
lda BytesRead

View File

@ -35,6 +35,7 @@ CS.START cld
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.CR .DA MSG.CR
L.MSG.LINENUM .DA MSG.LINENUM
L.MSG.Pause .DA MSG.Pause
.DA 0
@ -142,6 +143,8 @@ CS.RUN.LOOP >SLEEP
>SYSCALL fgets
bcs .13
>INCW.G LineNum
>LDA.G LineCount
bne .22
>LDA.G bPage
@ -150,9 +153,8 @@ CS.RUN.LOOP >SLEEP
lda #C.FF
>SYSCALL putchar
.22 >LDYA ZPBufPtr
>SYSCALL puts
.22 jsr CS.RUN.PRINT
>INC.G LineCount
cmp #23
bne .8
@ -188,16 +190,26 @@ CS.RUN.OPEN pha
.9 rts
*--------------------------------------
CS.RUN.PRINTNUM clc
CS.RUN.PRINT clc
>LDA.G bLineNum
bpl .8
bpl .1
>PUSHW.G LineNum
>PUSHBI 2
>LDYA L.MSG.LINENUM
>SYSCALL printf
.8 rts
bcs .9
.1 >PUSHBI 0
>LDYA ZPBufPtr
>SYSCALL printf
bcs .9
>PUSHBI 0
>LDYA L.MSG.CR
>SYSCALL printf
.9 rts
*--------------------------------------
CS.QUIT >LDA.G hBuf
beq .1
@ -224,7 +236,8 @@ OptionVars .DA #bLineNum,#bLineNum,#bHelp,#bHelp,#bPage,#bPage
MSG.USAGE .AS "Usage : MORE <File>\r\n"
.AS " -H : This help screen\r\n"
.AS " -N : Number all output lines\r\n"
.AZ " -P : Page mode, no scroll\r\n"
.AS " -P : Page mode, no scroll"
MSG.CR .AZ "\r\n"
MSG.LINENUM .AZ "%5D:"
MSG.Pause .AZ "\e[7m --- More --- \e[0m\r"
*--------------------------------------

View File

@ -32,13 +32,9 @@ CS.START cld
L.MSG.USAGE .DA MSG.USAGE
L.MSG.DIR .DA MSG.DIR
L.MSG.FILE .DA MSG.FILE
.DO X.COPY.TO.DEST=1
L.MSG.OVERWRITE .DA MSG.OVERWRITE
.FIN
L.MSG.OK .DA MSG.OK
L.MSG.ERR .DA MSG.ERR
L.MSG.DONE .DA MSG.DONE
@ -524,9 +520,7 @@ CS.RUN.CR lda #13
.9 rts
*--------------------------------------
.DO X.COPY.TO.DEST=1
.DO X.DELETE.SOURCE=1
CS.RUN.Rename ldy #hDstFullPath
jsr CS.RUN.GetPathY
@ -536,14 +530,14 @@ CS.RUN.Rename ldy #hDstFullPath
jsr CS.RUN.GetPathY
>SYSCALL Rename
rts
bcs .9
jsr CS.RUN.IncCount
.9 rts
.FIN
.FIN
*--------------------------------------
.DO X.COPY.TO.DEST=1
CS.RUN.CopyStart
ldy #hSrcFullPath
lda #O.RDONLY
@ -650,34 +644,26 @@ CS.RUN.CopyEnd >LDA.G hSrcFile
>SYSCALL fclose
>LDA.G hDstFile
lda (pData),y
>SYSCALL fclose
ldy #bCopy
lda #$0
sta (pData),y
>STZ.G bCopy
clc
rts
.FIN
*--------------------------------------
CS.RUN.CheckErr bcs .1
ldy #bQuiet
lda (pData),y
>LDA.G bQuiet
bmi .8
>LDYA L.MSG.OK
>SYSCALL puts
.8 rts
.1 ldy #RC
sta (pData),y
.1 >LDA.G RC
pha
ldy #bContinue
lda (pData),y
>LDA.G bContinue
bpl .2
pla
@ -732,34 +718,22 @@ CS.RUN.BuildFilePath
.2 >LDYA ZPPtr1
>SYSCALL StrCat
.FIN
rts
*--------------------------------------
CS.RUN.GetPathY lda (pData),y
>SYSCALL GetMemPtr
rts
*--------------------------------------
CS.RUN.IncCount ldy #Count
lda (pData),y
inc
sta (pData),y
bne .9
iny
lda (pData),y
inc
sta (pData),y
.9 rts
CS.RUN.IncCount >INCW.G Count
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT jsr LeaveSubDir
bcc CS.QUIT
.DO X.COPY.TO.DEST=1
>LDA.G bCopy
bpl .1
@ -774,9 +748,7 @@ CS.QUIT jsr LeaveSubDir
ldy #hDstFilename
jsr CS.QUIT.FREE
.FIN
ldy #hSrcFullPath
jsr CS.QUIT.FREE

View File

@ -349,7 +349,7 @@ CL.Parse >STZ.G CMD.IntCmd
beq .8 yes, ignore remaining
>LDA.G CMD.IntCmd
bne .6 we already have Cmd, go check args
bne .3 we already have Cmd, go check args
ldy #2
lda (ZPCMDBuf),y only one char ?
@ -363,23 +363,23 @@ CL.Parse >STZ.G CMD.IntCmd
>LDA.G CMD.PSFlags yes, child process will run in same ENV
and #$ff^S.PS.F.DUPENV
sta (pData),y
bra .7 and skip this token
bra .6 and skip this token
.2 jsr CL.CheckCmd
bcc .7 success, skip token, already added by CheckCmd
bcc .6 success, skip token, already added by CheckCmd
rts
.6 jsr CL.CheckIO
bcc .7
tay
bne .9
.3 jsr CL.CheckIO
bcc .7 IO token & related args processed
tay an error ?
bne .9 yes...I/O error...
jsr CL.AddCmdBufTokenToArgV
jsr CL.AddCmdBufTokenToArgV no...add as an arg
bcs .9
.7 jsr CL.NextCmdBufToken
lda (ZPCMDBuf)
.6 jsr CL.NextCmdBufToken
.7 lda (ZPCMDBuf)
bne .1
.8 clc

View File

@ -35,11 +35,27 @@ CMD.Quit >LDA.G CMD.hArgVBuf
* Input : ZPArgVBuf
*--------------------------------------
Cmd.Exec >LDA.G CMD.IntCmd
bmi .1
tax
jmp (J.CMD.INT,x)
bmi .2 External
.1 >PUSHB.G CMD.PSFlags
tax
cpx #C.ELSE
bcs .1
>LDA.G CMD.IF.PTR
cmp #CMD.IF.PTR
beq .1 no IF pending...
tay
lda (pData),y
bpl .8 FALSE
.1 jmp (J.CMD.INT,x)
.8 clc
rts
.2 >PUSHB.G CMD.PSFlags
>LDYA ZPArgVBuf
>SYSCALL execv
rts
@ -456,7 +472,7 @@ Cmd.INT.RD ldx #1
*--------------------------------------
Cmd.INT.IF >LDA.G CMD.IF.PTR
cmp #CMD.IF.PTR+CMD.IF.STACK.MAX
beq .90
beq .9
inc
sta (pData),y
@ -490,18 +506,31 @@ Cmd.INT.IF >LDA.G CMD.IF.PTR
bcs .1
phx
ldx #3
jsr Cmd.GetArgX
plx
bcs .9 we need one arg
jsr CMD.IF.UNARY
bcs .99
bcs .9
>LDA.G CMD.IF.PTR
tay
txa
eor #$ff
eor (pData),y
sta (pData),y
ldx #4
jsr Cmd.GetArgX
ldx #4 go check ]
bra .8
.1
ldx #5
.8 jsr Cmd.GetArgX
beq .9
>STYA ZPPTR1
@ -513,25 +542,51 @@ Cmd.INT.IF >LDA.G CMD.IF.PTR
ldy #1
lda (ZPPTR1),y
bne .9
.1
clc
.99 rts
.9 >LDA.G CMD.IF.PTR
.90 jmp Cmd.Exec.ERRSYN
.9 lda #E.SYN
sec
rts
*--------------------------------------
CMD.IF.UNARY jmp (J.CMD.IF.TOKEN2,x)
CMD.IF.D
CMD.IF.E
CMD.IF.F
ldx #1 true
CMD.IF.D jsr CMD.IF.DEF.7
bcs CMD.IF.DEF.9
>LDA.G CMD.Stat+S.STAT.P.TYPE
cmp #S.FI.T.DIR
bne CMD.IF.DEF.9
bra CMD.IF.DEF.8
CMD.IF.E jsr CMD.IF.DEF.7
bcs CMD.IF.DEF.9
bra CMD.IF.DEF.8 DIR or FILE exist
CMD.IF.F jsr CMD.IF.DEF.7
bcs CMD.IF.DEF.9
>LDA.G CMD.Stat+S.STAT.P.TYPE
cmp #S.FI.T.DIR
beq CMD.IF.DEF.9
bra CMD.IF.DEF.8
CMD.IF.DEF.7 >PUSHEA.G CMD.Stat
ldx #3
jsr Cmd.GetArgX
>SYSCALL STAT
rts
CMD.IF.DEF.8 ldx #$ff true
clc
rts
CMD.IF.DEF.9 ldx #0 false
clc
rts
*--------------------------------------
Cmd.INT.ELSE >LDA.G CMD.IF.PTR
>DEBUG
cmp #CMD.IF.PTR
beq .9

View File

@ -7,6 +7,24 @@ AUTO 4,1
.TF SBIN/SHELL
*--------------------------------------
CSH .EQ 0
*--------------------------------------
C.STARTPROC .EQ 0
C.CD .EQ 2
C.DATE .EQ 4
C.ECHO .EQ 6
C.EXIT .EQ 8
C.IF .EQ 10
C.MD .EQ 12
C.PAUSE .EQ 14
C.PWD .EQ 16
C.RD .EQ 18
C.READ .EQ 20
C.SET .EQ 22
C.SLEEP .EQ 24
C.TIME .EQ 26
*--------------------------------------
C.ELSE .EQ 28
C.FI .EQ 30
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
@ -87,9 +105,7 @@ J.CMD.INT .DA Cmd.INT.STARTPROC
.DA Cmd.INT.CD
.DA Cmd.INT.DATE
.DA Cmd.INT.ECHO
.DA Cmd.INT.ELSE
.DA Cmd.INT.EXIT
.DA Cmd.INT.FI
.DA Cmd.INT.IF
.DA Cmd.INT.MD
.DA Cmd.INT.PAUSE
@ -99,6 +115,8 @@ J.CMD.INT .DA Cmd.INT.STARTPROC
.DA Cmd.INT.SET
.DA Cmd.INT.SLEEP
.DA Cmd.INT.TIME
.DA Cmd.INT.ELSE
.DA Cmd.INT.FI
L.CMD.IF.TOKEN1 .DA CMD.IF.TOKEN1
L.CMD.IF.TOKEN2 .DA CMD.IF.TOKEN2
J.CMD.IF.TOKEN2 .DA CMD.IF.D
@ -457,9 +475,7 @@ CMD.INT .AZ "STARTPROC"
.AZ "CD"
.AZ "DATE"
.AZ "ECHO"
.AZ "ELSE"
.AZ "EXIT"
.AZ "FI"
.AZ "IF"
.AZ "MD"
.AZ "PAUSE"
@ -469,6 +485,8 @@ CMD.INT .AZ "STARTPROC"
.AZ "SET"
.AZ "SLEEP"
.AZ "TIME"
.AZ "ELSE"
.AZ "FI"
.HS 00
*--------------------------------------
CMD.IF.TOKEN1 .AZ "["