A2osX/BIN/SH.S.CMD.txt
2019-08-15 14:48:58 +02:00

1425 lines
23 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.

NEW
AUTO 3,1
.LIST OFF
*--------------------------------------
CMD.. lda (ZPArgVBufPtr)
beq .9
>LDYA ZPArgVBufPtr
jsr IO.Load
bcs CMD.SHIFTA.RTS
>LDYA ZPArgVBufPtr
jsr CORE.Load.YAX Exec . file
bcs CMD.SHIFTA.RTS
lda #$C0+C..
jmp CORE.StkPush
.9 jmp CMD.E.CSYN
*--------------------------------------
CMD.NOHUP lda #S.PS.F.NOHUP
tsb CORE.PSFlags
>LDYA ZPArgVBuf
jmp CORE.ExecExtCmd
*--------------------------------------
CMD.SHIFT lda #1
CMD.SHIFTA >SYSCALL ArgV
bcs .8
jsr RemoveStrFromArgV
.7 ldy #S.PS.ARGC
lda (pPS),y
dec
sta (pPS),y
.8 clc
CMD.SHIFTA.RTS rts
*--------------------------------------
CMD.PUSHD >LDA.G PUSHD.STACK
cmp #PUSHD.STACK+PUSHD.STACK.MAX
beq CMD.POPD.CSYN
ldy #S.PS.hCWD
lda (pPs),y
>SYSCALL GetMemPtr
>SYSCALL strdup
bcs CMD.POPD.CSYN
>INC.G PUSHD.STACK
tay
txa
sta (pData),y
lda (ZPArgVBufPtr)
bne CMD.CD.0
.8 clc
.9 rts
*--------------------------------------
CMD.POPD >LDA.G PUSHD.STACK
cmp #PUSHD.STACK
beq CMD.POPD.CSYN
tay
lda (pData),y
jsr CMD.SetCWDA
>DEC.G PUSHD.STACK
clc
CMD.POPD.RTS
rts
CMD.POPD.CSYN jmp CMD.E.CSYN
*--------------------------------------
CMD.PWD ldy #S.PS.hCWD
lda (pPs),y
>SYSCALL GetMemPtr
>SYSCALL puts
rts
*--------------------------------------
CMD... lda (ZPArgVBufPtr)
bne CMD.POPD.CSYN
>LDYA L.CMD
bra CMD.CD.YA
*--------------------------------------
CMD.CD lda (ZPArgVBufPtr)
beq CMD.CD.HOME
CMD.CD.0 >LDYA ZPArgVBufPtr
bra CMD.CD.YA
CMD.CD.HOME >LDYA L.HOME
CMD.CD.YA >SYSCALL realpath
bcs CMD.POPD.RTS
>STYA ZPPtr1
stx ZPTmpW Save hMem
ldy #1
lda (ZPPtr1),y
bne .12
txa
jmp CMD.SetCWDA we have '/'
.12 >PUSHEA.G StatBuf
>LDYA ZPPtr1
>SYSCALL STAT
bcs .19
.10 >LDA.G StatBuf+S.STAT.P.TYPE
cmp #S.FI.T.DIR
beq .11
lda #MLI.E.INVPATH
.19 pha
lda ZPTmpW
>SYSCALL freemem
pla
sec
rts
.11 jsr GetPtr1LenY
dey
lda (ZPPtr1),y
cmp #'/'
bne .14
lda ZPTmpW
jmp CMD.SetCWDA already ends with a /
.14 iny
iny
lda #0
>SYSCALL getmem
bcs .19
>STYA ZPPtr2
jsr StrCpyPtr1Ptr2
lda #'/'
sta (ZPPtr2),y
iny
lda #0
sta (ZPPtr2),y
phx
lda ZPTmpW
>SYSCALL freemem
pla
*--------------------------------------
CMD.SetCWDA pha
ldy #S.PS.hCWD
lda (pPs),y
>SYSCALL FreeMem
pla
ldy #S.PS.hCWD
sta (pPs),y
lda #0
* clc
rts
*--------------------------------------
CMD.Exec.CSYN lda #E.CSYN
sec
rts
*--------------------------------------
CMD.SET lda (ZPArgVBufPtr)
bne CMD.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 ?
jsr GetPtr1LenY
tya
sec
adc ZPPTR1
sta ZPPTR2
lda #0
adc ZPPTR1+1
sta ZPPTR2+1
>PUSHW ZPPTR2 Push value
>PUSHW ZPPTR1 Push name
jsr CMD.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.SET.1
.1 jsr CMD.IsSwitch
bcs .6
cmp #'C'
bne .2
ldy #bSET.C
bra .5
.2 cmp #'X'
bne .3
ldy #bSET.X
bra .5
.3 cmp #'E'
bne .4
ldy #bSET.E
bra .5
.4 cmp #'F'
bne .99
jsr CORE.FUNCRESET
bra .50
.5 lda (pData),y
eor #$ff
sta (pData),y
.50 jsr CORE.ArgV.Next
bne .1
clc
rts
.6 >LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
jsr CORE.ArgV.Next
beq CMD.SET.GET
cmp #'='
bne .99
ldy #1
lda (ZPArgVBufPtr),y
bne .99
jsr CORE.ArgV.Next
beq CMD.SET.UNSET
cmp #'`'
beq CMD.SET.EXEC
jsr EXP.GET
bcs .9
>PUSHYA
>LDYA ZPVarNamePtr
>SYSCALL SetEnv
rts
.8 clc
.9 rts
.99 jmp CMD.E.CSYN
CMD.SET.UNSET >LDYA ZPVarNamePtr
>SYSCALL UnsetEnv
rts
CMD.SET.GET >LDYA ZPVarNamePtr
>SYSCALL GetEnv
bcc .1
clc
rts
.1 >PUSHYA push value
>LDYA ZPVarNamePtr
>PUSHYA push name
*--------------------------------------
CMD.SET.PRINT >PUSHBI 4
>LDYA L.MSG.PRINTENV
>SYSCALL printf
rts
*--------------------------------------
CMD.SET.EXEC jsr CORE.ArgV.NextChar skip "`"
jsr IO.Pipe.Out
bcs .9
>PUSHBI S.PS.F.CLOSEONX
>LDYA ZPArgVBufPtr
>SYSCALL execl
bcs .9
jsr IO.Pipe.In
bcs .9
lda #255
>STA.G READ.N
>STA.G bREAD.S
jmp CMD.READ.VAR
.9 rts
*--------------------------------------
CMD.DATE sec
.HS 90 BCC
CMD.TIME clc
php
>LEA.G TimeBuf
>SYSCALL Time
>PUSHEA.G TimeBuf
plp
bcc .1
>PUSHW L.FMT.DATE
bra .2
.1 >PUSHW L.FMT.TIME
.2 >LEA.G StatBuf
>SYSCALL StrFTime
>LEA.G StatBuf
>SYSCALL puts
rts
*--------------------------------------
CMD.ECHO stz ZPPtr1 echo -N
stz ZPPtr1+1 Token Cnt
lda (ZPArgVBufPtr)
beq .7
.1 jsr CMD.IsSwitch
bcs .2
cmp #'N'
bne CMD.ECHO.CSYN
lda #$ff
eor ZPPtr1
sta ZPPtr1
bra .4
.2 lda ZPPtr1+1
beq .3
lda #C.SPACE
>SYSCALL putchar
.3 >PUSHBI 0
>LDYA ZPArgVBufPtr
>SYSCALL printf
bcs .9
inc ZPPtr1+1
.4 jsr CORE.ArgV.Next
bne .1
.7 bit ZPPtr1
bmi .8
>PUSHBI 0
>LDYA L.MSG.ECHOCRLF
>SYSCALL printf
.9 rts
.8 clc
rts
CMD.ECHO.CSYN lda #E.CSYN
sec
rts
*--------------------------------------
CMD.GETKEY lda (ZPArgVBufPtr)
beq CMD.ECHO.CSYN
ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL feof
bcs .9
tay
beq .1
.10 lda #'0'
>STA.G M32.BUF
iny
lda #0
sta (pData),y
bra .8
.1 >SYSCALL getchar
bcs .9
cmp #'['
bne .4
>SYSCALL getchar
bcs .9
ldx #EscChars.Cnt-1
.2 cmp EscChars,x
beq .3
dex
bpl .2
bra .10
.3 lda EscChars.Remap,x
.4 >PUSHA
>PUSHBI 1
>PUSHW L.FMT.GETKEY
>LEA.G M32.BUF
>SYSCALL sprintf
bcs .9
.8 >PUSHEA.G M32.BUF
>LDYA ZPArgVBufPtr
>SYSCALL SetEnv
.9
CMD.GETKEY.RTS rts
*--------------------------------------
CMD.READ lda (ZPArgVBufPtr)
beq .9
stz ZPVarNamePtr+1
>STZ.G bREAD.S
dec
>STA.G READ.N
.1 jsr CMD.IsSwitch
bcs .4
cmp #'S'
bne .2
lda #$ff
>STA.G bREAD.S
bra .5
.2 cmp #'P'
bne .3
jsr CORE.ArgV.Next
beq .9
>PUSHBI 0
>LDYA ZPArgVBufPtr
>SYSCALL printf
bcs CMD.GETKEY.RTS
bra .5
.9 jmp CMD.E.CSYN
.3 cmp #'N'
bne .9
jsr CORE.ArgV.Next
beq .9
>LDYA ZPArgVBufPtr
>SYSCALL AToL
bcs CMD.GETKEY.RTS
>PULLA
>STA.G READ.N
inc pStack
inc pStack
inc pStack
bra .5
.4 >LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
.5 jsr CORE.ArgV.Next
bne .1
lda ZPVarNamePtr+1
beq .9
CMD.READ.VAR jsr CL.Reset
.1 >SYSCALL GetChar
bcs .9
jsr CL.CHARIN
>LDA.G CL.bReady
bpl .1
lda (ZPCLBuf)
bne .2
>LDYA ZPVarNamePtr
>SYSCALL UnSetEnv
rts
.2 >PUSHW ZPCLBuf
>LDYA ZPVarNamePtr
>SYSCALL SetEnv
.9 rts
*--------------------------------------
CMD.SLEEP lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
>LDYA ZPArgVBufPtr
>SYSCALL AToL
bcs CMD.REN.CSYN
>PULLL.G Sleep
clc
rts
*--------------------------------------
CMD.PAUSE lda #$FF
>STA.G bPause
clc
rts
*--------------------------------------
CMD.MD lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
>LDYA ZPArgVBufPtr
>SYSCALL MKDir
rts
*--------------------------------------
CMD.REN lda (ZPArgVBufPtr)
beq .9
>PUSHW ZPArgVBufPtr
jsr CORE.ArgV.Next
lda (ZPArgVBufPtr)
beq .90
>LDYA ZPArgVBufPtr
>SYSCALL Rename
rts
.90 >PULLYA
.9
CMD.REN.CSYN jmp CMD.E.CSYN
*--------------------------------------
CMD.RD lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
>PUSHEA.G StatBuf
>LDYA ZPArgVBufPtr
>SYSCALL STAT
bcs .99
>LDA.G StatBuf+S.STAT.P.TYPE
cmp #S.FI.T.DIR
bne CMD.REN.CSYN
>LDYA ZPArgVBufPtr
>SYSCALL Remove
.99 rts
*--------------------------------------
CMD.FUNCTION lda (ZPArgVBufPtr)
beq .9
jsr CORE.StkGetCtx
bcc .9 No context allowed
>LDA.G hFuncList
bne .1
>SYSCALL SListNew
bcs .99
>STA.G hFuncList
.1 >PUSHW ZPArgVBufPtr
>LDA.G hFuncList
>SYSCALL SListNewKey
bcs .99
>STYA ZPTmpW Save KeyID
jsr CORE.ArgV.Next nothing after function name
beq .10
cmp #'{'
bne .9
ldy #1
lda (ZPArgVBufPtr),y
beq .11
.9 jmp CMD.E.CSYN
.99 rts
*--------------------------------------
.10 jsr CORE.GetCharNB
bcs .9
cmp #'{'
bne .9
jsr CORE.GetNextCharNB
bcs .9
.11 stz M32.ACC '{' counter
>LDYA ZPInputBufPtr
>STYA ZPPtr1
ldy #0
ldx #0
lda (ZPInputBufPtr)
beq .6
.12 cmp #'{'
bne .13
inc M32.ACC
bra .14
.13 cmp #'}'
bne .14
dec M32.ACC
bmi .7
.14 iny
bne .15
inx
.15 jsr CORE.GetNextChar
bne .12
.6 lda M32.ACC
bpl .9
.7 jsr CORE.GetNextChar skip ending '}'
txa
>PUSHYA DataLen
>PUSHW ZPPtr1 DataPtr
>PUSHW ZPTmpW KeyID
>LDA.G hFuncList
>SYSCALL SListAddData
rts
*--------------------------------------
CMD.CALL.UNDEF lda #E.FUNDEF
sec
CMD.CALL.RTS rts
*--------------------------------------
CMD.CALL >LDA.G hFuncList
beq CMD.CALL.UNDEF
>PUSHW ZPArgVBufPtr
>LDA.G hFuncList
>SYSCALL SListLookup
bcs CMD.CALL.UNDEF
>STYA ZPTmpW KeyID
>PUSHWZ From Start
>PUSHWI $ffff all
>PUSHWZ Allocate..
>PUSHW ZPTmpW KeyID
>LDA.G hFuncList
>SYSCALL SListGetData
bcs CMD.CALL.RTS
>LDYA ZPArgVBufPtr FUNC PARAM1 PARAM2...
jsr CORE.Load.YAX Exec FUNC
bcs CMD.CALL.RTS
lda #$C0+C.CALL
jmp CORE.StkPush
*--------------------------------------
CMD.EXIT lda (ZPArgVBufPtr)
beq .1 no arg, exit 0
>LDYA ZPArgVBufPtr
jsr EXP.GET
bcs .9
>SYSCALL AToL
bcs .99
>PULLA
inc pStack
inc pStack
inc pStack
.1 sta M32.ACC
.2 jsr CORE.StkPull Pull everything until CALL . CL...
bcs .9
cmp #$C0+C.. in CALL . CL context ?
beq CMD.EXIT.FILE
cmp #$C0+C.CALL
beq CMD.EXIT.FILE
cmp #$C0+C.CLEXEC
beq CMD.EXIT.SH
jsr CMD.EXIT.POP
bcc .2
.9 rts
.99 lda #E.ESYN
* sec
rts
*--------------------------------------
CMD.EXIT.SH jsr CMD.EXIT.FILE
lda #$ff
>STA.G bExitOnEOF
clc
rts
*--------------------------------------
CMD.EXIT.FILE jsr CORE.StkPull
>SYSCALL freemem Code buffer
ldy #S.PS.hARGV
lda (pPS),y
>SYSCALL freemem ArgV buffer
jsr CORE.StkPull
ldy #S.PS.hARGV
sta (pPS),y
jsr CORE.StkPull
ldy #S.PS.ARGC
sta (pPS),y
jsr CORE.StkPullInputBufPtr
jsr CORE.StkPull
sta ZPInputBuf+1
jsr CORE.StkPull
sta ZPInputBuf
lda M32.ACC
CMD.EXIT.CLCRTS clc
CMD.EXIT.RTS rts
*--------------------------------------
CMD.EXIT.POP and #$3F
cmp #C.IF
beq CMD.EXIT.CLCRTS IF : Nothing
ldx #2
cmp #C.WHILE WHILE : One Ptr = 2 bytes
beq CMD.EXIT.POPX
cmp #C.SWITCH SWITCH : hValue
beq .2
ldx #1
cmp #C.CASE CASE : C.CASE + hValue
beq .1
cmp #C.DEFAULT DEFAULT : C.DEFAULT + hValue
bne .9
.1 jsr CMD.EXIT.POPX
.2 jsr CORE.StkPull
>SYSCALL freemem
rts
.9 lda #E.STACKERROR
sec
rts
*--------------------------------------
CMD.EXIT.POPX lda (pData)
.1 dec
dex
bne .1
sta (pData)
clc
rts
*--------------------------------------
CMD.BREAK jsr CORE.StkGetCtx Get context in CORE.TestResult
bcs .9
tax
and #$3F
cmp #C.CASE
bne .9
txa
bpl .8
jsr CORE.StkPull remove C.CASE
jsr CORE.StkGet
and #$7F
sta (pDATA),y
.8 clc
rts
.9 jmp CMD.E.CSYN
*--------------------------------------
* stack-1 hVALUE
* stack SWITCH TOKEN
*--------------------------------------
CMD.SWITCH jsr CORE.StkGetCtx
lda #2
jsr CORE.StkCheck
bcs .9
jsr EXP.GET
bcs .9
>SYSCALL strdup
bcs .9
txa
jsr CORE.StkPush Push EXP hVALUE
lda CORE.TestResult
beq .1
ora #$80
.1 ora #C.SWITCH
jmp CORE.StkPush
.9 rts
*--------------------------------------
CMD.CASE jsr CORE.StkGetCtx Get context in CORE.TestResult
bcs .9
tax
and #$3F
cmp #C.SWITCH
beq .1
cmp #C.CASE
bne .9
txa previous case was true ?
bpl .10
jsr EXP.GET skip expression
bcs .9
rts keep existing context
.10 jsr CORE.StkPull remove previous C.CASE
bra CMD.CASE
.1 jsr EXP.GET
bcs .9
>PUSHYA
lda (pDATA)
tay
dey get hVALUE
lda (pDATA),y
>SYSCALL GetMemPtr
>SYSCALL strcmp
ror CS if !=
and #$80
eor #$80
ora CORE.TestResult
ora #C.CASE
jmp CORE.StkPush
.9
CMD.E.CSYN lda #E.CSYN
sec
rts
*--------------------------------------
CMD.DEFAULT jsr CORE.StkGetCtx Get context in CORE.TestResult
bcs CMD.E.CSYN
and #$3F
cmp #C.SWITCH
beq .1
cmp #C.CASE
bne CMD.E.CSYN
jsr CORE.StkPull remove C.CASE
.1 jsr CORE.StkGet
and #$C0
ora #C.DEFAULT
jmp CORE.StkPush
*--------------------------------------
CMD.END jsr CORE.StkGetCtx Get context in CORE.TestResult
bcs CMD.E.CSYN
and #$3F
cmp #C.SWITCH
beq .3
cmp #C.CASE
beq .2
cmp #C.DEFAULT
bne CMD.E.CSYN
.2 jsr CORE.StkPull remove C.CASE or C.DEFAULT
.3 jsr CORE.StkPull remove C.SWITCH
jsr CORE.StkPull get hVALUE
>SYSCALL freemem
rts
*--------------------------------------
CMD.FOR jsr CORE.StkGetCtx
lda (ZPArgVBufPtr)
beq CMD.E.CSYN
>LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
jsr CORE.ArgV.Next
beq CMD.E.CSYN
>PUSHW ZPArgVBufPtr
>LDYA L.IN
>SYSCALL StrCaseCmp
bcs CMD.E.CSYN
jsr CORE.ArgV.Next
beq CMD.E.CSYN
lda #8 Make sure 8 bytes free on stack
jsr CORE.StkCheck
bcs .9
>LDYA ZPInputBufPtr
jsr CORE.StkPushYA Push CmdPtr AFTER FOR
lda (ZPArgVBufPtr)
cmp #'('
beq CMD.FOR.FILE
cmp #'`'
bne CMD.FOR.LIST
jmp CMD.FOR.EXEC
.9 rts
*--------------------------------------
CMD.FOR.LIST >LDYA ZPArgVBufPtr
>SYSCALL strdup
bcs FOR.FILE.9
jsr CORE.StkPushYAX Push listPtr,hList
>LDYA ZPVarNamePtr
>SYSCALL strdup
bcs FOR.FILE.9
txa
jsr CORE.StkPush Push hVARNAME
lda #C.FOR.LIST
jsr CORE.StkPush
lda #C.FOR
jsr CORE.StkPush
jsr CMD.NEXT.LIST.1
bcs FOR.FILE.9
jmp CMD.FOR.LOOP
*--------------------------------------
CMD.FOR.FILE jsr CORE.ArgV.NextChar skip "("
>LDYA ZPArgVBufPtr
ldx #O.RDONLY+O.TEXT
jsr IO.FOpenYAX
bcs FOR.FILE.9
jsr CORE.StkPush push hFILE
>LDYA ZPVarNamePtr
>SYSCALL strdup
bcs FOR.FILE.9
txa
jsr CORE.StkPush Push hVARNAME
lda #C.FOR.FILE
jsr CORE.StkPush
lda #C.FOR
jsr CORE.StkPush
jsr CMD.NEXT.LINE
bcs FOR.FILE.9
bra CMD.FOR.LOOP
FOR.FILE.9 rts
*--------------------------------------
CMD.FOR.EXEC jsr CORE.ArgV.NextChar skip "`"
jsr IO.Pipe.Out
bcs FOR.FILE.9
>PUSHBI S.PS.F.CLOSEONX
>LDYA ZPArgVBufPtr
>SYSCALL execl
bcs FOR.FILE.9
jsr IO.Pipe.In
bcs FOR.FILE.9
jsr CORE.StkPush push hPIPE
>LDYA ZPVarNamePtr
>SYSCALL strdup
bcs FOR.FILE.9
txa
jsr CORE.StkPush Push hVARNAME
lda #C.FOR.EXEC
jsr CORE.StkPush
lda #C.FOR
jsr CORE.StkPush
jsr CMD.NEXT.LINE
bcs FOR.FILE.9
CMD.FOR.LOOP ora CORE.TestResult
ora #C.FOR Push FOR
pha
lda (pData)
tay
pla
sta (pData),y
rts
*--------------------------------------
CMD.NEXT jsr CORE.StkGet Y = StkPtr
bcs .9
and #$3F
cmp #C.FOR
bne .9
dey
lda (pData),y
tax
iny
jmp (J.NEXT,x)
.9 lda #E.NOFOR
sec
rts
*--------------------------------------
* stack-6 CmdPtr
* stack-4 ListPtr
* stack-3 hLIST
* stack-2 hVARNAME
* stack-1 FOR SUB TOKEN
* stack FOR TOKEN
*--------------------------------------
CMD.NEXT.LIST lda (pData),y Y = StkPtr
bpl .1
jsr CMD.NEXT.LIST.1
bcs .9
bpl .1
lda (pData)
sec
sbc #6
tay
lda (pData),y
sta ZPInputBufPtr
dey
lda (pData),y
sta ZPInputBufPtr+1
clc
rts
.1 lda (pData)
tay
sec
sbc #8
sta (pData)
dey
dey
lda (pData),y hVARNAME
pha
dey
lda (pData),y hLIST
>SYSCALL freemem
pla
>SYSCALL freemem
clc
.9 rts
*--------------------------------------
CMD.NEXT.LIST.1 lda (pData)
dec skip FOR
dec skip SUB TOKEN
tay
lda (pData),y
phy
>SYSCALL GetMemPtr hVARNAME
>STYA ZPVarNamePtr
ply
dey skip hLIST
dey
lda (pData),y
sta ZPPtr1
dey
lda (pData),y
sta ZPPtr1+1
ldy #0
.10 jsr GetPtr1Next
beq .3
cmp #C.SPACE
beq .10
sta (ZPCLBuf),y
iny
.1 jsr GetPtr1Next
beq .3
cmp #C.SPACE
beq .3
sta (ZPCLBuf),y
iny
bra .1
.3 lda #0
sta (ZPCLBuf),y
tya
beq .8
>PUSHW ZPCLBuf
>LDYA ZPVarNamePtr
>SYSCALL SetEnv
bcs .9
lda (pData)
sec
sbc #4
tay
lda ZPPtr1
sta (pData),y
dey
lda ZPPtr1+1
sta (pData),y
lda #$80
clc
rts
.8 >LDYA ZPVarNamePtr
>SYSCALL UnSetEnv
bcs .9
lda #0
* clc
.9 rts
*--------------------------------------
* stack-4 CmdPtr
* stack-3 hFILE
* stack-2 hVARNAME
* stack-1 FOR SUB TOKEN
* stack FOR TOKEN
*--------------------------------------
CMD.NEXT.FILE
*--------------------------------------
* stack-4 CmdPtr
* stack-3 hPIPE
* stack-2 hVARNAME
* stack-1 FOR SUB TOKEN
* stack FOR TOKEN
*--------------------------------------
CMD.NEXT.EXEC lda (pData),y Y = StkPtr
bpl .1
jsr CMD.NEXT.LINE
bcs .9
bpl .1 end of file/pipe
lda (pData)
sec
sbc #4
tay
lda (pData),y
sta ZPInputBufPtr
dey
lda (pData),y
sta ZPInputBufPtr+1
clc
rts
.1 lda (pData)
tay
sec
sbc #6
sta (pData)
dey
dey
lda (pData),y hVARNAME
pha
dey
lda (pData),y hFILE/hPIPE
>SYSCALL fclose
pla
>SYSCALL freemem
* clc
.9 rts
*--------------------------------------
CMD.NEXT.LINE lda (pData)
dec skip FOR
dec skip SUB TOKEN
tay
lda (pData),y
phy
>SYSCALL GetMemPtr hVARNAME
>STYA ZPVarNamePtr
>PUSHWI 256
>PUSHW ZPCLBuf
ply
dey
lda (pData),y hFILE/hPIPE
>SYSCALL fgets
bcs .8
>PUSHW ZPCLBuf
>LDYA ZPVarNamePtr
>SYSCALL SetEnv
bcs .9
lda #$80
* clc
rts
.8 >LDYA ZPVarNamePtr
>SYSCALL UnSetEnv
bcs .9
lda #0
* clc
.9 rts
*--------------------------------------
CMD.WHILE
CMD.IF jsr CORE.StkGetCtx
bit #$40 Parent is true ?
beq .3
jsr EXP.TEST
bcs .9
.3 lda CORE.IntCmd
cmp #C.WHILE
bne .8
>LDYA ZPInputCmdPtr
jsr CORE.StkPushYA Push BEFORE WHILE/IF
bcs .9
.8 lda CORE.TestResult
ora CORE.IntCmd
jsr CORE.StkPush
clc
.9 rts
*--------------------------------------
CMD.LOOP jsr CORE.StkPull
bcs .9
tax
and #$3F
cmp #C.WHILE
bne .9
txa
bmi .8
lda (pData)
dec
dec Discard loop Ptr
sta (pData)
clc
rts
.8 jmp CORE.StkPullInputBufPtr
.9 lda #E.NOWHILE
sec
rts
*--------------------------------------
CMD.ELSE jsr CORE.StkGet
bcs .9
bit #$40 parent is true ?
beq .8 no, skip
tax
and #$3F
cmp #C.IF
bne .9
txa
eor #$80 toggle and store at stack ptr
sta (pData),y
.8 clc
rts
.9 lda #E.NOIF
sec
rts
*--------------------------------------
CMD.FI jsr CORE.StkPull
bcs .9
and #$3F
cmp #C.IF
bne .9
clc
rts
.9 lda #E.NOIF
sec
rts
*--------------------------------------
CMD.IsSwitch lda (ZPArgVBufPtr)
cmp #'-'
bne .9
ldy #1
lda (ZPArgVBufPtr),y
beq .9
cmp #'0' is -0 ... -9 ?
bcc .9
cmp #'9'+1
bcc .9
.1 tax
iny
lda (ZPArgVBufPtr),y
bne .9
txa
jmp ToUpperCase
.9 sec
rts
*--------------------------------------
MAN
SAVE USR/SRC/BIN/SH.S.CMD
LOAD USR/SRC/BIN/SH.S
ASM