A2osX/SBIN/SHELL.S.CMD.txt

634 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.

PR#3
PREFIX /A2OSX.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
CMD.Init >LDYAI CmdLine.MAX+1
>SYSCALL GetMem.YA
bcs .9
txa
>STA.G hCmdBuf
.9 rts
*--------------------------------------
* ZPCMDBuf : Remove extra SPACE & comment
*--------------------------------------
Cmd.Parse >LDYA ZPCMDBuf
>STYA ZPPtr1
lda (ZPCMDBuf) empty line...quit
beq .9
ldy #0
.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 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 stz bStartProc
>LDYA ZPCMDBuf
>SYSCALL ExpandStr.YA
>STYA ZPPtr1 Ptr to CMD ARGS
txa
>STA.G CMD.hCmdLine
Cmd.Exec.2 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
.2 phy Y=CMD len
>LDYA L.INTCMDS
>STYA ZPPtr2
ldx #0
.3 lda (ZPPtr2)
beq Cmd.Exec.EXT Array Ending 0, must be an external Cmd....
pla get back CMD len
pha
cmp (ZPPtr2) Same Len ?
beq .51
.4 inx
inx
lda ZPPtr2
sec
adc (ZPPtr2)
sta ZPPtr2
bcc .3
inc ZPPtr2+1
bra .3
.51 tay
.5 dey
lda (ZPPtr1),y
cmp #'a' To Uppercase
bcc .6
cmp #'z'+1
bcs .6
eor #$20
.6 iny
cmp (ZPPtr2),y
bne .4
dey
bne .5
ply get back Cmd Len
lda (ZPPtr1),y
beq .7 ARGS = ""
iny skip " "
.7 tya
clc
adc ZPPtr1
sta ZPPtr2
lda #0
adc ZPPtr1+1
sta ZPPtr2+1 ZPPtr2->ARGS
jsr Cmd.Exec.INT Found an internal Cmd...
Cmd.Exec.Done php
pha
>LDA.G CMD.hCmdLine
>SYSCALL FreeMem.A
pla
plp
rts
*--------------------------------------
Cmd.Exec.INT jmp (J.INTCMDS,x)
*--------------------------------------
Cmd.Exec.EXT pla Discard CMD len
lda (ZPPtr1)
cmp #'/' Command line is already full path, no search
bne .1
>PUSHW L.STAT
>PUSHW ZPPtr1
>SYSCALL STAT
bcs .99
>LDYAI UsrBuf256
>STYA ZPPtr1
bra .3
.1 >LDYA L.ENV.PATH push ENVNAME=PATH for search
>SYSCALL GetEnv.YA get value for ENV=PATH
bcs .2 No PATH, try in CD
jsr Cmd.Exec.Search
bcc .3
.2 ldy #S.PS.hPREFIX not found, try in CD
lda (pPs),y
>SYSCALL GetMemPtr.A
jsr Cmd.Exec.Search
bcs .99
.3 lda STAT+S.STAT.P.TYPE
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 #SYSMGR.ERRSYN
sec
.99 jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.Search >PUSHYA push search list
>PUSHW ZPPtr1
>PUSHWI UsrBuf256
>PUSHW L.STAT
>SYSCALL FileSearch
rts
*--------------------------------------
* TXT : Launch "/PATH/SHELL /PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.TXT
lda #0 Get arg[0] = /PATH/SHELL
>SYSCALL GetArg.A
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL StrCpy
inc UsrBuf256 Add a space....
ldy UsrBuf256
lda #' '
sta UsrBuf256,y
*--------------------------------------
* BIN : Launch "/PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.BIN
>PUSHW L.CMD
>PUSHWI UsrBuf256
>SYSCALL StrCat
lda (ZPPTR2)
beq .1
inc UsrBuf256 Add a space....
ldy UsrBuf256
lda #' '
sta UsrBuf256,y
>PUSHW ZPPTR2
>PUSHWI UsrBuf256
>SYSCALL StrCat
.1 >LDYAI UsrBuf256
bit bStartProc
bmi .2 startproc
>SYSCALL ExecProcessNewEnvYA
jmp Cmd.Exec.Done
.2 >SYSCALL CreateProcessYA
jmp Cmd.Exec.Done
*--------------------------------------
* Internal Commands
*--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
bne Cmd.Exec.CD1
Cmd.Exec.PWD ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtr.A
>SYSCALL PrintF.YA
rts
Cmd.Exec.CD1 stz UsrBuf256
cmp #'/' Full Path?
beq .1
ldy #S.PS.hPREFIX no, init target prefix with actual prefix
lda (pPs),y
>SYSCALL GetMemPtr.A
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL StrCpy
.1 >PUSHW ZPPTR2 Append ARG to buffer
>PUSHWI UsrBuf256
>SYSCALL StrCat
lda #'/'
ldx UsrBuf256
cmp UsrBuf256,x Ending '/' ?
beq .2
sta UsrBuf256+1,x no, add one...
inc UsrBuf256
.2 ldx #0 path is something like : /dir1/../dir2/
.3 ldy #0 reset char counter
.4 cpx UsrBuf256
beq .8
inx
lda UsrBuf256,x
cmp #'/'
beq .5
iny char=char+1!!!
bra .4
.5 tya any char count?
beq .4 no, start counting...
cpy #2 do we have /xx/?
bne .3 no, skip this token
lda #'.'
cmp UsrBuf256-1,x /yy/x./ ?
bne .3
cmp UsrBuf256-2,x /yy/../ ?
bne .3
cpx #4 /../ ?
beq Cmd.Exec.ERRSYN illegal
txa
tay save end of /../
sec
sbc #3 remove ../
tax
.6 dex
lda UsrBuf256,x Found beginning of dir before /../
cmp #'/'
bne .6
.7 lda UsrBuf256,y strip dir/../
sta UsrBuf256,x
cpy UsrBuf256
beq .71
iny
inx
bra .7
.71 stx UsrBuf256
bra .2 Start over...
.8 cpx #1
beq .80 we have '/' go change prefix
>PUSHW L.STAT
>PUSHWI UsrBuf256
>SYSCALL STAT
bcs .9
lda STAT+S.STAT.P.TYPE
cmp #$0F Directory ?
bne Cmd.Exec.ERRSYN
.80 >LDYAI UsrBuf256
>SYSCALL NewStr.YA
bcs .9
phx
ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL FreeMem.A
pla
ldy #S.PS.hPREFIX
sta (pPs),y
jsr SetPWD
clc
.9 rts
*--------------------------------------
Cmd.Exec.ERRSYN lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
Cmd.Exec.STARTPROC
lda (ZPPTR2)
beq Cmd.Exec.ERRSYN
sec
ror bStartProc
>LDYA ZPPTR2
>STYA ZPPTR1
jmp Cmd.Exec.2
*--------------------------------------
Cmd.Exec.SET lda (ZPPTR2)
bne Cmd.Exec.SETVAR
* No arg, print all ENV
ldy #S.PS.hENV
lda (pPs),y
>SYSCALL GetMemPtr.A
>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
>LDYA L.MSG.PRINTENV
>SYSCALL PrintF.YA
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
Cmd.Exec.SETVAR ldy #0
lda (ZPPTR2),y
iny
cmp #'=' string is '=value' ?
beq .99 syntax error
.1 lda (ZPPTR2),y
iny
beq .3 no =, GetEnv
cmp #'=' ARGS contains =, PutEnv
bne .1
lda (ZPPTR2),y
beq .2 "VAR=" go UnsetEnv
>LDYA ZPPTR2 String is VAR=VALUE...
>SYSCALL PutEnv.YA
rts
.2 dey String is "VAR=", Remove endig '='
sta (ZPPTR2),y
>LDYA ZPPTR2 String is "VAR"...
>SYSCALL UnsetEnv.YA
rts
* Print requested VAR
.3 >LDYA ZPPTR2
>SYSCALL GetEnv.YA
bcs .8
>PUSHYA push value
>PUSHW ZPPTR2 push name
>LDYA L.MSG.PRINTENV
>SYSCALL PrintF.YA
.8 clc
.9 rts
.99 jmp Cmd.Exec.ERRSYN
*--------------------------------------
Cmd.Exec.DATE sec
.HS 90 bcc
Cmd.Exec.TIME clc
php
>LDYA L.TIME
>SYSCALL TimeYA
>PUSHWI UsrBuf256
plp
bcc .1
>PUSHW L.FMT.DATE
bra .2
.1 >PUSHW L.FMT.TIME
.2 >PUSHW L.TIME
>SYSCALL StrFTime
>LDYAI UsrBuf256
>SYSCALL PrintF.YA
bcs Cmd.Exec.ECHO.RTS
bra Cmd.Exec.ECHO.CR
*--------------------------------------
Cmd.Exec.ECHO lda (ZPPtr2)
beq Cmd.Exec.ECHO.CR
>LDYA ZPPtr2
>SYSCALL PrintF.YA
Cmd.Exec.ECHO.CR
lda #13
>SYSCALL PutChar.A
bcs Cmd.Exec.ECHO.RTS
lda #10
>SYSCALL PutChar.A
Cmd.Exec.ECHO.RTS
rts
*--------------------------------------
Cmd.Exec.READ lda (ZPPtr2)
beq .9
lda #0
>STA.G bSecureRead
lda pData
clc
adc #CMD.VarName
sta ZPPTR1
lda pData+1
adc #0
sta ZPPTR1+1
ldy #0
.1 lda (ZPPtr2),y
beq .8
iny
cmp #' '
beq .1
cmp #'-'
bne .7
lda (ZPPtr2),y
beq .9
iny
cmp #'S'
bne .2
lda #$80
>STA.G bSecureRead
bra .1
.2 cmp #'P'
bne .9
lda (ZPPtr2),y
beq .9
iny
cmp #' '
bne .9
lda (ZPPtr2),y
beq .9
iny
cmp #'"'
bne .9
.3 lda (ZPPtr2),y
beq .9
iny
cmp #'"'
beq .1
phy
>SYSCALL PutChar.A
ply
bcs .99
bra .3
.9 jmp Cmd.Exec.ERRSYN
.70 lda (ZPPtr2),y
cmp #' '
beq .1
.7 lda (ZPPTR1)
cmp #VarLen.MAX
beq .9
inc
sta (ZPPTR1)
tay
lda (ZPPtr2),y
sta (ZPPTR1),y
bne .70
.8 lda (ZPPTR1) No var name ? SYNERR
beq .9
clc
.99 rts
*--------------------------------------
Cmd.Exec.SLEEP lda (ZPPtr2)
beq .9
lda #Sleep
clc
adc pData
tay
lda /Sleep
adc pData+1
>PUSHYA
>PUSHW ZPPtr2
>SYSCALL AToI.YA
bcs .9
rts
.9 jmp Cmd.Exec.ERRSYN
*--------------------------------------
Cmd.Exec.PAUSE lda #$FF
>STA.G bPause
clc
rts
*--------------------------------------
Cmd.Exec.EXIT lda #$FF
>STA.G bExit
clc
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
LOAD /A2OSX.SRC/SBIN/SHELL.S
ASM