A2osX/BIN/SH.S.CMD.txt
2019-02-12 16:47:34 +00:00

636 lines
10 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
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
lda (ZPArgVBufPtr)
bne 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 lda (ZPArgVBufPtr)
bne 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.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 ?
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
.1 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
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
jsr EXP.GET
bcs .99
>PUSHYA
>LDYA ZPVarNamePtr
>SYSCALL SetEnv
rts
.8 clc
rts
.99 jmp CMD.Exec.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.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
lda (ZPArgVBufPtr)
beq .8
.1 jsr CMD.IsSwitch
bcs .2
cmp #'N'
bne .99
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
bit ZPPtr1
bmi .8
>PUSHBI 0
>LDYA L.MSG.ECHOCRLF
>SYSCALL printf
rts
.8 clc
.9 rts
.99 lda #E.CSYN
sec
rts
*--------------------------------------
CMD.GETKEY lda (ZPArgVBufPtr)
beq .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
>LDYA ZPArgVBufPtr
>SYSCALL SetEnv
.9 rts
.99 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.READ lda (ZPArgVBufPtr)
beq .9
.1 jsr CMD.IsSwitch
bcs .4
cmp #'S'
bne .2
lda #$ff
>STA.G bREAD.S
bra .7
.2 cmp #'P'
bne .9
jsr CORE.ArgV.Next
beq .9
>PUSHBI 0
>LDYA ZPArgVBufPtr
>SYSCALL printf
bcs .99
bra .7
.4 >STYA ZPVarNamePtr
>SYSCALL strdup
txa
>STA.G hVarName
.7 jsr CORE.ArgV.Next
lda (ZPArgVBufPtr)
bne .1
>LDA.G hVarName
beq .9
clc
.99 rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.SLEEP lda (ZPArgVBufPtr)
beq .9
>LDYA ZPArgVBufPtr
>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 lda (ZPArgVBufPtr)
beq .8 no arg, exit 0
>LDYA ZPArgVBufPtr
>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 lda (ZPArgVBufPtr)
beq .9
>LDYA ZPArgVBufPtr
>SYSCALL MKDir
rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.REN lda (ZPArgVBufPtr)
beq .9
>PUSHW ZPArgVBufPtr
jsr CORE.ArgV.Next
lda (ZPArgVBufPtr)
beq .90
>LDYA ZPArgVBufPtr
>SYSCALL Rename
rts
.90 >PULLYA
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.RD lda (ZPArgVBufPtr)
beq .9
>PUSHEA.G StatBuf
>LDYA ZPArgVBufPtr
>SYSCALL STAT
bcs .99
>LDA.G StatBuf+S.STAT.P.TYPE
cmp #S.FI.T.DIR
bne .9
>LDYA ZPArgVBufPtr
>SYSCALL Remove
.99 rts
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.BREAK
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.CONTINUE
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.FOR
.9 jmp CMD.Exec.CSYN
*--------------------------------------
CMD.NEXT
.9 jmp CMD.Exec.CSYN
*--------------------------------------
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.TEST
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 lda (ZPArgVBufPtr)
cmp #'-'
bne .9
ldy #1
lda (ZPArgVBufPtr),y
beq .9
tax
iny
lda (ZPArgVBufPtr),y
bne .9
txa
cmp #'a'
bcc .8
cmp #'z'+1
bcs .8
eor #$20
jsr CORE.ArgV.NextChar
jsr CORE.ArgV.NextChar
.8 clc
rts
.9 sec
rts
*--------------------------------------
MAN
SAVE USR/SRC/BIN/SH.S.CMD
LOAD USR/SRC/BIN/SH.S
ASM