A2osX/BIN/SHELL.S.CMD.txt
2019-02-06 16:20:51 +00:00

698 lines
11 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
PREFIX
AUTO 4,1
.LIST OFF
*--------------------------------------
CMD.NOHUP >LDA.G CORE.PSFlags
ora #S.PS.F.NOHUP
sta (pData),y
>LDYA ZPArgVBuf
jsr RemoveStrFromArgV
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
rts
*--------------------------------------
CMD.PUSHD >LDA.G PUSHD.STACK
cmp #PUSHD.STACK+PUSHD.STACK.MAX
beq CMD.POPD.CSYN
ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtr
>SYSCALL strdup
bcs CMD.POPD.CSYN
>INC.G PUSHD.STACK
tay
txa
sta (pData),y
ldx #1
jsr CORE.GetArgX
bcc CMD.CD.1
.8 clc
.9 rts
*--------------------------------------
CMD.POPD >LDA.G PUSHD.STACK
cmp #PUSHD.STACK
beq CMD.POPD.CSYN
tay
lda (pData),y
jsr CMD.SetPrefixA
>DEC.G PUSHD.STACK
clc
CMD.POPD.RTS
rts
CMD.POPD.CSYN jmp CMD.Exec.CSYN
*--------------------------------------
CMD.PWD ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtr
>SYSCALL puts
rts
*--------------------------------------
CMD.CD ldx #1
jsr CORE.GetArgX
bcc CMD.CD.1
CMD.CD.HOME >LDYA L.ENV.HOME
>SYSCALL GetEnv
bcc CMD.CD.1
>LDYA L.ENV.ROOT
>SYSCALL GetEnv
bcs CMD.PWD
CMD.CD.1 >SYSCALL realpath
bcs CMD.POPD.RTS
>STYA ZPPtr1
stx ZPPtr3 Save hMem
ldy #1
lda (ZPPtr1),y
bne .12
txa
jmp CMD.SetPrefixA 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 ZPPtr3
>SYSCALL freemem
pla
sec
rts
.11 ldy #$ff
.1 iny
lda (ZPPtr1),y
bne .1
dey
lda (ZPPtr1),y
cmp #'/'
bne .14
lda ZPPtr3
jmp CMD.SetPrefixA already ends with a /
.14 iny
iny
lda #0
>SYSCALL getmem
bcs .19
>STYA ZPPtr2
ldy #$ff
.2 iny
lda (ZPPtr1),y
lda (ZPPtr2),y
bne .2
iny
sta (ZPPtr2),y
dey
lda #'/'
sta (ZPPtr2),y
phx
lda ZPPtr3
>SYSCALL freemem
pla
*--------------------------------------
CMD.SetPrefixA pha
ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL FreeMem
pla
ldy #S.PS.hPREFIX
sta (pPs),y
lda #0
* clc
rts
*--------------------------------------
CMD.Exec.CSYN lda #E.CSYN
sec
rts
*--------------------------------------
CMD.Exec.SSYN lda #E.SSYN
sec
rts
*--------------------------------------
CMD.SET ldx #1
jsr CORE.GetArgX
bcc 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 ?
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.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 >STZ.G CORE.Varname
lda #1
>STA.G CORE.ArgIndex
.1 tax
jsr CORE.GetArgX
bcs .8
jsr CMD.IsSwitch
bcs .6
cmp #'C'
bne .2
>LDA.G bSET.C
bra .5
.2 cmp #'X'
bne .99
>LDA.G bSET.X
.5 eor #$ff
sta (pData),y
>INC.G CORE.ArgIndex
bra .1
.6 >LDA.G CORE.ArgIndex
>STA.G CORE.Varname
>INC.G CORE.ArgIndex
tax
jsr CORE.GetArgX
bcs CMD.SET.GET
>STYA ZPPTR1
lda (ZPPTR1)
cmp #'='
bne .99
ldy #1
lda (ZPPTR1),y
bne .99
>INC.G CORE.ArgIndex
tax
jsr CORE.GetArgX
bcs CMD.SET.UNSET
jsr EXP.GET
bcs .99
>PUSHYA
>LDA.G CORE.Varname
tax
jsr CORE.GetArgX
>SYSCALL SetEnv
rts
.8 clc
rts
.99 jmp CMD.Exec.CSYN
CMD.SET.UNSET >LDA.G CORE.Varname
tax
jsr CORE.GetArgX
>SYSCALL UnsetEnv
rts
CMD.SET.GET >LDA.G CORE.Varname
tax
jsr CORE.GetArgX
>SYSCALL GetEnv
bcc .1
clc
rts
.1 >PUSHYA push value
>LDA.G CORE.Varname
tax
jsr CORE.GetArgX
>PUSHYA push name
*--------------------------------------
CMD.SET.PRINT >PUSHBI 4
>LDYA L.MSG.PRINTENV
>SYSCALL printf
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.G bECHO.N
lda #1
>STA.G CORE.ArgIndex
.1 tax
jsr CORE.GetArgX
bcs .7
jsr CMD.IsSwitch
bcs .2
cmp #'N'
bne .99
lda #$ff
>EOR.G bECHO.N
sta (pData),y
>INC.G CORE.ArgIndex
bra .1
.2 pha
>PUSHBI 0
pla
>SYSCALL printf
bcs .9
>INC.G CORE.ArgIndex
tax
jsr CORE.GetArgX
bcs .7
.6 lda #C.SPACE
>SYSCALL putchar
bcs .9
>PUSHBI 0
>LDA.G CORE.ArgIndex
tax
jsr CORE.GetArgX
>SYSCALL printf
bcs .9
>INC.G CORE.ArgIndex
tax
jsr CORE.GetArgX
bcc .6
.7 >LDA.G bECHO.N
bmi .8
>PUSHBI 0
>LDYA L.MSG.ECHOCRLF
>SYSCALL printf
rts
.8 clc
.9 rts
.99 lda #E.CSYN
sec
rts
*--------------------------------------
CMD.GETKEY ldx #1
jsr CORE.GetArgX
bcs .99
>SYSCALL getchar
bcc .1
tay
bne .9
.1 >PUSHA
>PUSHBI 1
>PUSHW L.FMT.GETKEY
>LEA.G M32.BUF
>SYSCALL sprintf
bcs .9
>PUSHEA.G M32.BUF
ldx #1
jsr CORE.GetArgX
>SYSCALL SetEnv
.9 rts
.99 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.READ lda #1
>STA.G CORE.ArgIndex
tax
jsr CORE.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 CORE.ArgIndex
tax
jsr CORE.GetArgX
bcs .9
pha
>PUSHBI 0
pla
>SYSCALL printf
bcs .99
bra .7
.4 >STYA ZPVarNamePtr
>SYSCALL strdup
txa
>STA.G hVarName
.7 >INC.G CORE.ArgIndex
tax
jsr CORE.GetArgX
bcc .1
>LDA.G hVarName
beq .9
clc
.99 rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.SLEEP ldx #1
jsr CORE.GetArgX
bcs .9
>SYSCALL AToL
bcs .9
>PULLL.G Sleep
clc
rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.PAUSE lda #$FF
>STA.G bPause
clc
rts
*--------------------------------------
CMD.EXIT ldx #1
jsr CORE.GetArgX
bcs .8 no arg, exit 0
>SYSCALL AToL
bcs .9
>PULLL.G M32.ACC
lda #$FF
>STA.G bExit
>LDA.G M32.ACC
clc
rts
.8 lda #$FF
>STA.G bExit
inc
clc
.9 rts
*--------------------------------------
CMD.MD ldx #1
jsr CORE.GetArgX
bcs .9
>SYSCALL MKDir
rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.REN ldx #2
jsr CORE.GetArgX
bcs .9
>PUSHYA
ldx #1
jsr CORE.GetArgX
>SYSCALL Rename
rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.RD ldx #1
jsr CORE.GetArgX
bcs .9
phy
pha
>PUSHEA.G StatBuf
pla
ply
>SYSCALL STAT
bcs .99
>LDA.G StatBuf+S.STAT.P.TYPE
cmp #S.FI.T.DIR
bne .9
ldx #1
jsr CORE.GetArgX
>SYSCALL Remove
.99 rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.BREAK
.9 jmp CMD.Exec.SSYN
*--------------------------------------
CMD.CONTINUE
.9 jmp CMD.Exec.SSYN
*--------------------------------------
CMD.FOR
.9 jmp CMD.Exec.SSYN
*--------------------------------------
CMD.NEXT
.9 jmp CMD.Exec.SSYN
*--------------------------------------
CMD.WHILE
CMD.IF jsr CORE.StkGet
bcs .1 no context...
and #$80 get current..
lsr becomes parent
bra .2
.1 lda #$40 ...set Parent = true
.2 >STA.G CORE.Test
bit #$40 Parent is true ?
beq .3
jsr EXP.EVAL
bcs .9
.3 >LDA.G CORE.IntCmd
cmp #C.WHILE
bne .8
jsr CORE.StkPushPtr
bcs .9
.8 >LDA.G CORE.Test
>ORA.G CORE.IntCmd
jmp CORE.StkPush
clc
.9 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.LOOP jsr CORE.StkPull
bcs .9
tax
and #$3F
cmp #C.WHILE
bne .9
txa
bpl .1
jmp CORE.StkPullPtr
.1 jsr CORE.StkPull
bcs .99
jmp CORE.StkPull
.9 lda #E.NOWHILE
sec
.99 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
*--------------------------------------
MAN
SAVE USR/SRC/BIN/SHELL.S.CMD
LOAD USR/SRC/BIN/SHELL.S
ASM