A2osX/SBIN/SHELL.S.CMD.txt
2018-09-17 08:16:45 +02:00

705 lines
12 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 /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
CMD.Init >LDYAI CmdLine.MAX+1
>SYSCALL GetMem
bcs .9
>STYA ZPCMDBuf
txa
>STA.G hCmdBuf
.9 rts
*--------------------------------------
CMD.Quit >LDA.G hCmdBuf
beq .9
>SYSCALL FreeMem
.9 rts
*--------------------------------------
* ZPCMDBuf : Remove extra SPACE & comment
*--------------------------------------
Cmd.Parse >LDYA ZPCMDBuf
>STYA ZPPtr1
ldy #0
lda (ZPCMDBuf) empty line...quit
beq .9
.1 jsr Cmd.Parse.NextC
beq .8 no more char, exit
cmp #' ' skip leading spaces
beq .1
cmp #'#' Comment ?
beq .8 ignore remaining chars
.3 sta (ZPCMDBuf),y add char to buffer
iny
jsr Cmd.Parse.NextC
beq .8
cmp #' '
bne .3
sta (ZPCMDBuf),y add One SPACE to buffer
iny
.5 jsr Cmd.Parse.NextC
beq .8
cmp #' '
beq .5 skip additional spaces
bne .3 no more space, add next word...
.8 lda #0
sta (ZPCMDBuf),y
.9 tya
>STA.G CmdBuflen
rts
Cmd.Parse.NextC lda (ZPPtr1)
beq .8
inc ZPPtr1
bne .8
inc ZPPtr1+1 never Z
.8 rts
*--------------------------------------
* ZPCMDBuf-> Command line (formatted & not empty)
*--------------------------------------
CMD.Exec lda #0
>STA.G CMD.bStartProc
>STA.G CMD.hFullpath
* SET +X
* >LDYA ZPCMDBuf
* >SYSCALL puts
* sta $C055
* >DEBUG
>LDYA ZPCMDBuf
>SYSCALL ExpandStr
>STYA ZPPtr1 Ptr to CMD ARGS
txa
>STA.G CMD.hCmdLine
>LDYA L.CMD.INT
>STYA ZPPtr2
ldx #0
.3 lda (ZPPtr2)
beq Cmd.Exec.EXT Array Ending 0, must be an external Cmd....
ldy #$ff
.4 iny
lda (ZPPtr2),y
bne .41 End of string in array
lda (ZPPtr1),y Get CMD char...
beq .8 both end with 0, found!
cmp #' '
beq .8 we reached space between CMD & ARGS....
.41 lda (ZPPtr1),y Get CMD char...
beq .61 end of CMD.....too short...
cmp #' '
beq .61 we reached space between CMD & ARGS....
cmp #'a' To Uppercase
bcc .5
cmp #'z'+1
bcs .5
eor #$20
.5 cmp (ZPPtr2),y
beq .4
.61 iny
lda (ZPPtr2),y
bne .61
.7 inx
inx
tya
sec
adc ZPPtr2
sta ZPPtr2
bcc .3
inc ZPPtr2+1
bra .3
.8 jsr Cmd.Exec.GetArgs X unmodified
jmp (J.CMD.INT,x) Found an internal Cmd...
*--------------------------------------
Cmd.Exec.Done php
pha
>LDA.G CMD.hCmdLine
>SYSCALL FreeMem
>LDA.G CMD.hFullpath
beq .1
>SYSCALL FreeMem
>STZ.G CMD.hFullpath
.1 pla
plp
rts
*--------------------------------------
Cmd.Exec.EXT jsr Cmd.Exec.GetArgs
lda (ZPPtr1)
cmp #'/' Command line is already full path, no search
bne .1
>PUSHEA.G CMD.Stat
>LDYA ZPPtr1
>SYSCALL STAT
bcs Cmd.Exec.Done
>LDYA ZPPtr1
bra .4
.1 >LDYA L.ENV.PATH push ENVNAME=PATH for search
>SYSCALL GetEnv get value for ENV=PATH
bcs .2 No PATH, try in CD
jsr Cmd.Exec.EXT.Search
bcc .3
.2 ldy #S.PS.hPREFIX not found, try in CD
lda (pPs),y
>SYSCALL GetMemPtr
jsr Cmd.Exec.EXT.Search
bcs .99
.3 >LDYA ZPCMDBuf
.4 >SYSCALL NewStr
bcs .99
txa
>STA.G CMD.hFullpath
lda #0
sta (ZPCMDBuf) reset ZPCMDBuf for final CMD
ldy #CMD.Stat+S.STAT.P.TYPE
lda (pData),y
cmp #$04 TXT File ?
beq Cmd.Exec.EXT.TXT
cmp #$06 BIN File ?
beq Cmd.Exec.EXT.BIN
cmp #$ff SYS File ?
bne .9
bra *
.9 lda #K.E.SYN
sec
.99 jmp Cmd.Exec.Done
*--------------------------------------
* TXT : Launch "/PATH/SHELL /PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.TXT
lda #0 Get arg[0] = /PATH/SHELL
>SYSCALL GetArg
>PUSHYA
>LDYA ZPCMDBuf
>SYSCALL StrCat
jsr Cmd.Exec.EXT.SEP Add a space....
*--------------------------------------
* BIN : Launch "/PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.BIN
>LDA.G CMD.hFullpath
>SYSCALL GetMemPtr
>PUSHYA
>LDYA ZPCMDBuf
>SYSCALL StrCat
lda (ZPPTR2) Some ARGS ?
beq .1
jsr Cmd.Exec.EXT.SEP Add a space....
>PUSHW ZPPTR2
>LDYA ZPCMDBuf
>SYSCALL StrCat
.1 >LDA.G CMD.bStartProc
asl
>LDYA ZPCMDBuf
bcs .2 startproc
>SYSCALL ExecPSNewEnv
jmp Cmd.Exec.Done
.2 >SYSCALL CreatePSNewEnv
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.EXT.Search
pha
phy
>PUSHEA.G CMD.Stat
>PUSHW ZPCMDBuf push dest full path
ply
pla
>PUSHYA push search list
>LDYA ZPPtr1 push CMD
>SYSCALL FileSearch
rts
*--------------------------------------
Cmd.Exec.EXT.SEP
ldy #$ff
.1 iny
lda (ZPCMDBuf),y
bne .1
lda #' '
sta (ZPCMDBuf),y
iny
lda #0
sta (ZPCMDBuf),y
rts
*--------------------------------------
* Internal Commands
*--------------------------------------
Cmd.Exec.PWD ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtr
>SYSCALL puts
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
bne .1
>LDYA L.ENV.HOME
>SYSCALL GetEnv
bcs Cmd.Exec.PWD
>SYSCALL ExpandStr
bcs .9
bra .4
.1 ldy #0
.2 lda (ZPPTR2),y
tax
iny
lda (ZPPTR2),y
bne .2
cpx #'/'
beq .3
lda #'/'
sta (ZPPTR2),y
iny
lda #0
sta (ZPPTR2),y
.3 >LDYA ZPPTR2 Get ARG
>SYSCALL RealPath
bcs .9
.4 >STYA ZPPTR2
txa
>STA.G CMD.hFullpath
ldy #1
lda (ZPPTR2),y
beq .8 we have '/'
>PUSHEA.G CMD.Stat
>LDYA ZPPTR2
>SYSCALL STAT
bcs .9
ldy #CMD.Stat+S.STAT.P.TYPE
lda (pData),y
cmp #$0F Directory ?
bne Cmd.Exec.ERRSYN
.8 >LDYA ZPPTR2
>SYSCALL NewStr
bcs .9
phx
ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL FreeMem
pla
ldy #S.PS.hPREFIX
sta (pPs),y
jsr SetPWD
clc
.9 jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.ERRSYN lda #K.E.SYN
sec
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.STARTPROC
lda (ZPPTR2)
beq Cmd.Exec.ERRSYN
lda #$ff
>STA.G CMD.bStartProc
>LDYA ZPPTR2
>STYA ZPPTR1
jmp Cmd.Exec.EXT
*--------------------------------------
Cmd.Exec.SET lda (ZPPTR2)
bne Cmd.Exec.SETVAR
* 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.Exec.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 jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.SETVAR cmp #'=' string is '=value' ?
beq .99 syntax error
ldy #0
.1 iny
lda (ZPPTR2),y
beq .3 no =, GetEnv
cmp #'=' ARGS contains =, PutEnv
bne .1
iny
lda (ZPPTR2),y
beq .2 "VAR=" go UnsetEnv
>LDYA ZPPTR2 String is VAR=VALUE...
>SYSCALL PutEnv
jmp Cmd.Exec.Done
.2 dey String is "VAR=", Remove ending '='
lda #0
sta (ZPPTR2),y
>LDYA ZPPTR2 String is "VAR"...
>SYSCALL UnsetEnv
jmp Cmd.Exec.Done
* Print requested VAR
.3 >LDYA ZPPTR2
>SYSCALL GetEnv
bcs .8
>PUSHYA push value
>PUSHW ZPPTR2 push name
jsr Cmd.Exec.SET.PRINT
.8 clc
.9 jmp Cmd.Exec.Done
.99 jmp Cmd.Exec.ERRSYN
*--------------------------------------
Cmd.Exec.SET.PRINT
>PUSHBI 4
>LDYA L.MSG.PRINTENV
>SYSCALL printf
rts
*--------------------------------------
Cmd.Exec.DATE sec
.HS 90 bcc
Cmd.Exec.TIME clc
php
>LEA.G CMD.Time
>SYSCALL Time
>PUSHW ZPCMDBuf
plp
bcc .1
>PUSHW L.FMT.DATE
bra .2
.1 >PUSHW L.FMT.TIME
.2 >PUSHEA.G CMD.Time
>SYSCALL StrFTime
>LDYA ZPCMDBuf
>SYSCALL puts
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.ECHO >LDYA ZPPtr2
>SYSCALL puts
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.READ lda (ZPPtr2)
beq .9
lda #0
>STA.G bSecureRead
>STA.G CMD.VarName.LEN
lda pData
clc
adc #CMD.VarName
sta ZPPTR1
lda pData+1
adc #0
sta ZPPTR1+1
.1 lda (ZPPtr2)
beq .8
cmp #' '
bne .11
jsr Cmd.Exec.GetNextP2
bra .1
.11 cmp #'-'
bne .7
jsr Cmd.Exec.GetNextP2
beq .9
cmp #'S'
bne .2
lda #$80
>STA.G bSecureRead
jsr Cmd.Exec.GetNextP2
beq .8
cmp #' '
bne .9
bra .1
.2 cmp #'P'
bne .9
jsr Cmd.Exec.GetNextP2
beq .9
cmp #' '
bne .9
jsr Cmd.Exec.GetNextP2
beq .9
cmp #'"'
bne .9
.3 jsr Cmd.Exec.GetNextP2
beq .9
cmp #'"'
beq .1
>SYSCALL PutChar
bcs .99
bra .3
.9 jmp Cmd.Exec.ERRSYN
.7 >LDA.G CMD.VarName.LEN
cmp #VarLen.MAX
beq .9
pha
inc
sta (pData),y
ply
lda (ZPPtr2)
sta (ZPPTR1),y
iny
lda #0
sta (ZPPTR1),y
jsr Cmd.Exec.GetNextP2
beq .1
cmp #' '
beq .1
bra .7
.8 >LDA.G CMD.VarName.LEN No var name ? SYNERR
beq .9
lda #$ff
>STA.G bReadMode
clc
.99 jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.SLEEP lda (ZPPtr2)
beq .9
>LDYA ZPPtr2
>SYSCALL AToL
bcs .9
>PULLL.G Sleep
jmp Cmd.Exec.Done
.9 jmp Cmd.Exec.ERRSYN
*--------------------------------------
Cmd.Exec.PAUSE lda #$FF
>STA.G bPause
clc
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.EXIT lda #$FF
>STA.G bExit
clc
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.IF >STZ.G CMD.IFNOT
lda (ZPPtr2)
beq .9
cmp #'!'
bne .1
lda #$ff
sta (pData),y Y = #CMD.IFNOT
jsr Cmd.Exec.GetNextP2NB
beq .9
cmp #'('
bne .9
jsr Cmd.Exec.GetNextP2NB
beq .9
cmp #'-' -d -e -f
bne .1
jsr Cmd.Exec.GetNextP2NB
beq .9
.1 >DEBUG
>LDYA ZPPtr2
>SYSCALL puts
jmp Cmd.Exec.Done
.9 jmp Cmd.Exec.ERRSYN
*--------------------------------------
Cmd.Exec.GetArgs
ldy #$ff CMD Len
.1 iny
lda (ZPPtr1),y Get CMD char...
beq .2
cmp #' ' we reached blank between CMD ARGS
bne .1
lda #0
sta (ZPPtr1),y Cut CMD with the ending 0
iny
.2 tya Y=CMD len+0, if ARGS="" Y=
clc
adc ZPPtr1
sta ZPPtr2
lda ZPPtr1+1
adc #0
sta ZPPtr2+1 ZPPtr2->ARGS or CMD ending 0 if empty
* >LDYA L.CMD.IOR
* >STYA ZPPtr2
* ldx #0
*.3 lda (ZPPtr2)
rts
*--------------------------------------
Cmd.Exec.GetArg1
*--------------------------------------
Cmd.Exec.GetNextP2NB
.1 jsr Cmd.Exec.GetNextP2
beq .9
cmp #C.SPACE
beq .1
.9 rts
*--------------------------------------
Cmd.Exec.GetNextP2
inc ZPPtr2
bne .1
inc ZPPtr2+1
.1 lda (ZPPtr2)
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
LOAD /A2OSX.SRC/SBIN/SHELL.S
ASM