NEW PREFIX AUTO 4,1 .LIST OFF *-------------------------------------- CMD.Init >LDYAI 256 >SYSCALL GetMem bcs .9 >STYA ZPCLBuf txa >STA.G CMD.hCLBuf >LDYAI 256 >SYSCALL GetMem bcs .9 >STYA ZPArgVBuf txa >STA.G CMD.hArgVBuf .9 rts *-------------------------------------- CMD.Quit ldy #CMD.hArgVBuf jsr .8 ldy #CMD.hCLBuf jsr .8 ldy #hFileBuf .8 lda (pData),y beq .9 >SYSCALL FreeMem .9 rts *-------------------------------------- * Input : ZPArgVBuf *-------------------------------------- Cmd.Exec >LDA.G CMD.IntCmd bmi .2 External tax cpx #C.ELSE always execute ELSE,FI bcs .1 jsr CMD.StkGet IF,WHILE,FOR ? bcs .1 no particular context bpl .8 context is FALSE, skip line .1 jmp (J.CMD.INT,x) .2 >PUSHB.G CMD.PSFlags >LDYA ZPArgVBuf >SYSCALL execv bcs .9 tax CPID >LDA.G CMD.PSFlags and #S.PS.F.HOLD bne .4 txa >PUSHA >PUSHBI 1 >LDYA L.MSG.PID >SYSCALL printf rts .4 >SLEEP Suspend this PID ldy #S.PS.RC lda (pPs),y bne .99 .8 clc .9 rts .99 sec rts *-------------------------------------- * STARTPROC : intcmd = 0 *-------------------------------------- Cmd.INT.STARTPROC clc rts *-------------------------------------- Cmd.INT.SHIFT lda #1 jmp ShiftA *-------------------------------------- Cmd.INT.PWD ldy #S.PS.hPREFIX lda (pPs),y >SYSCALL GetMemPtr >SYSCALL puts rts *-------------------------------------- Cmd.INT.CD ldx #1 jsr Cmd.GetArgX bcs Cmd.INT.CD.HOME >SYSCALL RealPath bcc Cmd.INT.CD.1 Cmd.INT.CD.RTS rts Cmd.INT.CD.HOME >LDYA L.ENV.HOME >SYSCALL GetEnv bcc .1 >LDYA L.ENV.ROOT >SYSCALL GetEnv bcs Cmd.INT.PWD .1 >SYSCALL ExpandStr bcs Cmd.INT.CD.RTS Cmd.INT.CD.1 >STYA ZPPtr1 txa >STA.G CMD.hCmdLine ldy #1 lda (ZPPtr1),y beq .8 we have '/' >PUSHEA.G CMD.Stat >LDYA ZPPtr1 >SYSCALL STAT bcs .90 >LDA.G CMD.Stat+S.STAT.P.TYPE cmp #S.FI.T.DIR bne Cmd.Exec.ERRSYN ldy #0 .5 iny lda (ZPPtr1),y bne .5 dey lda #'/' cmp (ZPPtr1),y beq .8 iny sta (ZPPtr1),y iny lda #0 sta (ZPPtr1),y .8 >LDYA ZPPtr1 >SYSCALL NewStr bcs .90 phx ldy #S.PS.hPREFIX lda (pPs),y >SYSCALL FreeMem pla ldy #S.PS.hPREFIX sta (pPs),y jsr SetPWD.I .90 php pha >LDA.G CMD.hCmdLine >SYSCALL FreeMem pla plp .9 rts *-------------------------------------- Cmd.Exec.ERRSYN lda #E.SYN sec rts *-------------------------------------- Cmd.INT.SET ldx #1 jsr Cmd.GetArgX bcc Cmd.INT.SET.1 * No arg, print all ENV ldy #S.PS.hENV lda (pPs),y >SYSCALL GetMemPtr >STYA ZPPTR1 .1 lda (ZPPTR1) beq .8 Ending 0 ? ldy #$ff .2 iny lda (ZPPTR1),y bne .2 tya sec adc ZPPTR1 sta ZPPTR2 lda #0 adc ZPPTR1+1 sta ZPPTR2+1 >PUSHW ZPPTR2 Push value >PUSHW ZPPTR1 Push name jsr Cmd.INT.SET.PRINT bcs .9 ldy #$ff .3 iny lda (ZPPTR2),y bne .3 tya sec adc ZPPTR2 sta ZPPTR1 lda #0 adc ZPPTR2+1 sta ZPPTR1+1 bra .1 .8 clc .9 rts *-------------------------------------- * SET +X VAR = VALUE1 op VALUE2 op VALUE3 ... *-------------------------------------- Cmd.INT.SET.1 >STZ.G CMD.Varname lda #1 >STA.G CMD.ArgIndex .1 tax jsr Cmd.GetArgX bcs .8 jsr CMD.IsSwitch bcs .2 cmp #'X' bne .99 lda #$ff >EOR.G bSET.X sta (pData),y >INC.G CMD.ArgIndex tax bra .1 .2 >LDA.G CMD.ArgIndex >STA.G CMD.Varname >INC.G CMD.ArgIndex tax jsr Cmd.GetArgX bcs Cmd.INT.SET.GET >STYA ZPPTR1 lda (ZPPTR1) cmp #'=' bne .99 ldy #1 lda (ZPPTR1),y bne .99 >INC.G CMD.ArgIndex tax jsr Cmd.GetArgX bcs Cmd.INT.SET.UNSET >PUSHYA >LDA.G CMD.Varname tax jsr Cmd.GetArgX >SYSCALL SetEnv rts .8 clc rts .99 lda #E.SYN sec rts Cmd.INT.SET.UNSET >LDA.G CMD.Varname tax jsr Cmd.GetArgX >SYSCALL UnsetEnv rts Cmd.INT.SET.GET >LDA.G CMD.Varname tax jsr Cmd.GetArgX >SYSCALL GetEnv rts >PUSHYA push value >LDA.G CMD.Varname tax jsr Cmd.GetArgX >PUSHYA push name *-------------------------------------- Cmd.INT.SET.PRINT >PUSHBI 4 >LDYA L.MSG.PRINTENV >SYSCALL printf rts *-------------------------------------- Cmd.INT.DATE sec .HS 90 bcc Cmd.INT.TIME clc php >LEA.G CMD.Time >SYSCALL Time >PUSHEA.G CMD.Time plp bcc .1 >PUSHW L.FMT.DATE bra .2 .1 >PUSHW L.FMT.TIME .2 >LDYA ZPCLBuf >SYSCALL StrFTime >LDYA ZPCLBuf >SYSCALL puts rts *-------------------------------------- Cmd.INT.ECHO lda #1 >STA.G CMD.ArgIndex tax jsr Cmd.GetArgX bcs .7 pha >PUSHBI 0 pla >SYSCALL printf bcs .9 >INC.G CMD.ArgIndex tax jsr Cmd.GetArgX bcs .7 .1 lda #C.SPACE >SYSCALL putchar bcs .9 >PUSHBI 0 >LDA.G CMD.ArgIndex tax jsr Cmd.GetArgX >SYSCALL printf bcs .9 >INC.G CMD.ArgIndex tax jsr Cmd.GetArgX bcc .1 .7 >LDA.G bECHO.N bmi .8 >PUSHBI 0 >LDYA L.MSG.ECHOCRLF >SYSCALL printf rts .8 clc .9 rts *-------------------------------------- Cmd.INT.READ lda #1 >STA.G CMD.ArgIndex tax jsr Cmd.GetArgX bcs .9 .1 jsr CMD.IsSwitch bcs .4 cmp #'S' bne .2 lda #$ff >STA.G bREAD.S bra .7 .2 cmp #'P' bne .9 >INC.G CMD.ArgIndex tax jsr Cmd.GetArgX bcs .9 pha >PUSHBI 0 pla >SYSCALL printf bcs .99 bra .7 .4 >SYSCALL newstr txa >STA.G hVarName .7 >INC.G CMD.ArgIndex tax jsr Cmd.GetArgX bcc .1 >LDA.G hVarName beq .9 clc .99 rts .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.SLEEP ldx #1 jsr Cmd.GetArgX bcs .9 >SYSCALL AToL bcs .9 >PULLL.G Sleep clc rts .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.PAUSE lda #$FF >STA.G bPause clc rts *-------------------------------------- Cmd.INT.EXIT lda #$FF >STA.G bExit clc rts *-------------------------------------- Cmd.INT.MD ldx #1 jsr Cmd.GetArgX bcs .9 >SYSCALL MKDir rts .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.REN ldx #2 jsr Cmd.GetArgX bcs .9 >PUSHYA ldx #1 jsr Cmd.GetArgX >SYSCALL Rename rts .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.RD ldx #1 jsr Cmd.GetArgX bcs .9 phy pha >PUSHEA.G CMD.Stat pla ply >SYSCALL STAT bcs .99 >LDA.G CMD.Stat+S.STAT.P.TYPE cmp #S.FI.T.DIR bne .9 ldx #1 jsr Cmd.GetArgX >SYSCALL Remove .99 rts .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.FOR .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.WHILE Cmd.INT.IF ldx #1 jsr Cmd.GetArgX beq .9 >PUSHYA >LDYA L.CMD.IF.TOKEN1 jsr Lookup bcs .9 cpx #4 [ or ![ bcs .9 dex dex 1 or $ff txa and #$80 true or false eor #$80 >STA.G CMD.Test ldx #2 jsr Cmd.GetArgX beq .9 >PUSHYA >LDYA L.CMD.IF.TOKEN2 -d -e -f ? jsr Lookup bcs .1 txa >STA.G CMD.Operator jsr CMD.IF.UNARY bcs .9 >LDA.G CMD.Test eor #$80 sta (pData),y ldx #4 go check ] bra .8 .9 lda #E.SYN sec .99 rts .1 ldx #3 jsr Cmd.GetArgX beq .9 >PUSHYA >LDYA L.CMD.IF.TOKEN3 -eq -ne .... ? jsr Lookup bcs .9 txa >STA.G CMD.Operator jsr CMD.IF.BINARY bcs .9 ldx #5 go check ] .8 jsr Cmd.GetArgX beq .9 >STYA ZPPTR1 lda (ZPPTR1) cmp #']' bne .9 ldy #1 lda (ZPPTR1),y bne .9 >LDA.G CMD.IntCmd cmp #C.WHILE bne .81 tax jsr CMD.StkPushPtr bcs .99 txa .81 >ORA.G CMD.Test jmp CMD.StkPush *-------------------------------------- CMD.IF.UNARY ldx #3 jsr Cmd.GetArgX bcs .9 we need one arg >LDA.G CMD.Operator tax jmp (J.CMD.IF.TOKEN2,x) .9 lda #E.SYN sec rts 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 #$80 true clc rts CMD.IF.DEF.9 ldx #0 false clc rts *-------------------------------------- CMD.IF.BINARY ldx #2 jsr Cmd.GetArgX bcs .9 ldx #4 jsr Cmd.GetArgX bcs .9 >LDA.G CMD.Operator beq .1 = cmp #2 != bne CMD.IF.BINARY.NUM lda #$80 >STA.G CMD.Operator .1 ldx #2 jsr Cmd.GetArgX >PUSHYA ldx #4 jsr Cmd.GetArgX >SYSCALL strcmp lsr CS if != >EOR.G CMD.Operator sta (pData),y tax clc rts .9 lda #E.SYN sec rts CMD.IF.BINARY.NUM ldx #2 jsr Cmd.GetArgX bcs .9 >SYSCALL AToL bcs .9 >PULLL.G M32.ACC ldx #4 jsr Cmd.GetArgX bcs .9 >SYSCALL AToL bcs .9 >PULLL.G M32.ARG ldx #4 ldy #M32.ARG+3 .1 lda (pData),y pha dey dex bne .1 ldx #4 ldy #M32.ACC sec .2 pla sbc (pData),y sta (pData),y iny dex bne .2 bcc .5 CC if Arg1 < Arg2 ldy #M32.ACC lda (pData),y iny ora (pData),y iny ora (pData),y iny ora (pData),y Z if Arg1 = Arg2 bne .4 .3 lda #%001 001 arg1 = arg2 bra .6 .4 lda #%010 010 arg1 > arg2 bra .6 .5 lda #%100 100 Arg1 < Arg2 .6 pha >LDA.G CMD.Operator lsr tax pla eor CMD.IF.TOKEN3.BITS,x bne .80 ldx #$80 true clc rts .80 ldx #0 false clc rts .9 lda #E.SYN sec rts *-------------------------------------- Cmd.INT.ELSE jsr CMD.StkGet bcs .9 pha and #$7F cmp #C.IF bne .9 pla eor #$80 sta (pData),y clc rts .9 pla lda #E.SYN sec rts *-------------------------------------- Cmd.INT.FI jsr CMD.StkPull bcs .9 and #$7F cmp #C.IF bne .9 clc rts .9 lda #E.SYN sec rts *-------------------------------------- Cmd.INT.NEXT .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.BREAK .9 jmp Cmd.Exec.ERRSYN *-------------------------------------- Cmd.INT.LOOP jsr CMD.StkPull bcs .9 tax and #$7F cmp #C.WHILE bne .9 txa bpl .1 jmp CMD.StkPullPtr .1 jsr CMD.StkPull bcs .99 jmp CMD.StkPull .9 lda #E.NOWHILE sec .99 rts *-------------------------------------- Cmd.GetArgX >LDYA ZPArgVBuf dex bmi .8 >STYA ZPPtr1 .1 lda (ZPPtr1) beq .9 .2 inc ZPPtr1 bne .3 inc ZPPtr1+1 .3 lda (ZPPtr1) bne .2 inc ZPPtr1 bne .4 inc ZPPtr1+1 .4 lda (ZPPtr1) beq .9 dex bpl .1 >LDYA ZPPtr1 .8 clc rts .9 sec rts *-------------------------------------- CMD.IsSwitch >STYA ZPPtr1 lda (ZPPtr1) cmp #'-' bne .9 ldy #1 lda (ZPPtr1),y beq .9 iny lda (ZPPtr1),y bne .9 dey lda (ZPPtr1),y cmp #'a' bcc .8 cmp #'z'+1 bcs .8 eor #$20 .8 clc rts .9 >LDYA ZPPtr1 sec rts *-------------------------------------- CMD.StkPushPtr >LDA.G CMD.FileBufPtr jsr CMD.StkPush bcs .9 >LDA.G CMD.FileBufPtr+1 jmp CMD.StkPush .9 rts *-------------------------------------- CMD.StkPullPtr jsr CMD.StkPull bcs .9 sta ZPFileBufPtr+1 jsr CMD.StkPull bcs .9 sta ZPFileBufPtr .9 rts *-------------------------------------- CMD.StkGetPtr lda (pData) StackPtr beq .9 dec beq .9 tay lda (pData),y sta ZPFileBufPtr iny lda (pData),y sta ZPFileBufPtr+1 clc rts .9 lda #E.SYNTAX sec rts *-------------------------------------- CMD.StkPush pha lda (pData) StackPtr inc cmp #CMD.STACK.MAX beq .9 sta (pData) StackPtr tay pla sta (pData),y * clc rts .9 pla lda #E.STKOVERFLOW * sec rts *-------------------------------------- CMD.StkPull jsr CMD.StkGet bcs .9 dey pha tya sta (pData) StackPtr pla .9 rts *-------------------------------------- CMD.StkGet lda (pData) StackPtr beq .9 tay lda (pData),y clc rts .9 lda #E.SYNTAX sec rts *-------------------------------------- MAN SAVE USR/SRC/SBIN/SHELL.S.CMD LOAD USR/SRC/SBIN/SHELL.S ASM