A2osX/SBIN/SHELL.S.CMD.txt

660 lines
12 KiB
Plaintext
Raw Normal View History

2015-10-19 20:35:00 +00:00
PR#3
PREFIX /A2OSX.BUILD
2015-10-19 20:35:00 +00:00
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)
2016-08-17 06:25:58 +00:00
*--------------------------------------
Cmd.Exec stz bStartProc
>LDYA ZPCMDBuf
>SYSCALL PrintF.YA
jsr Cmd.Exec.ECHO.CR
>LDYA ZPCMDBuf
>SYSCALL ExpandStr.YA
>STYA ZPPtr1 Ptr to CMD
2016-08-17 06:25:58 +00:00
txa
>STA.G CMD.hCmdLine
Cmd.ExecYA >LDYA ZPPtr1
>SYSCALL PrintF.YA
jsr Cmd.Exec.ECHO.CR
>DEBUG
ldy #$ff CMD Len
2016-08-17 06:25:58 +00:00
.1 iny
lda (ZPPtr1),y Get CMD char...
beq .2
cmp #' ' we reached blank between CMD ARGS
2017-08-23 11:33:51 +00:00
bne .1
2016-08-17 06:25:58 +00:00
.2 phy Y=CMD len
2016-08-17 06:25:58 +00:00
>LDYA L.INTCMDS
>STYA ZPPtr2
2016-08-17 06:25:58 +00:00
ldx #0
.3 lda (ZPPtr2)
beq Cmd.Exec.EXT Array Ending 0, must be an external Cmd....
2016-08-17 06:25:58 +00:00
pla get back CMD len
pha
2016-08-17 06:25:58 +00:00
cmp (ZPPtr2) Same Len ?
beq .51
.4 inx
inx
2016-08-17 06:25:58 +00:00
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
2017-08-23 11:33:51 +00:00
bcc .6
cmp #'z'+1
2017-08-23 11:33:51 +00:00
bcs .6
eor #$20
.6 iny
cmp (ZPPtr2),y
bne .4
2016-08-17 06:25:58 +00:00
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
2015-10-19 20:35:00 +00:00
2017-08-23 11:33:51 +00:00
jsr Cmd.Exec.INT Found an internal Cmd...
bcs .9
lda #0
.9 ldy #S.PS.RC
sta (pPS),y
Cmd.Exec.Done php
pha
>LDA.G CMD.hCmdLine
>SYSCALL FreeMem.A
2017-08-23 11:33:51 +00:00
pla
plp
rts
*--------------------------------------
Cmd.Exec.INT jmp (J.INTCMDS,x)
*--------------------------------------
Cmd.Exec.EXT pla Discard CMD len
lda (ZPPtr1)
2016-08-17 06:25:58 +00:00
cmp #'/' Command line is already full path, no search
bne .10
jmp .3
.10 >LDYA L.ENV.PATH push ENVNAME=PATH for search
>SYSCALL GetEnv.YA get value for ENV=PATH
2016-08-17 06:25:58 +00:00
bcs .1 No PATH, try in CD
2015-10-19 20:35:00 +00:00
2016-08-17 06:25:58 +00:00
>PUSHYA push search list
>PUSHW ZPPtr1 push filename
>PUSHWI UsrBuf256
>PUSHW L.STAT
>SYSCALL FileSearch
2016-08-17 06:25:58 +00:00
bcc .2
2015-10-19 20:35:00 +00:00
2016-08-17 06:25:58 +00:00
.1 ldy #S.PS.hPREFIX not found, try in CD
2015-10-19 20:35:00 +00:00
lda (pPs),y
>SYSCALL GetMemPtr.A
2016-08-17 06:25:58 +00:00
>PUSHYA push search list
2017-08-23 11:33:51 +00:00
>PUSHW ZPPtr1
>PUSHWI UsrBuf256
>PUSHW L.STAT
>SYSCALL FileSearch
2016-08-17 06:25:58 +00:00
bcs .99
2015-10-19 20:35:00 +00:00
2016-08-17 06:25:58 +00:00
.2 phx save X=hMem, Y,A = Filename
>PUSHYA
2016-08-17 06:25:58 +00:00
>PUSHW L.CMD replace CMD in TmpBuffer with full path
>SYSCALL StrCpy
2016-08-17 06:25:58 +00:00
pla
>SYSCALL FreeMem.A Discard this string...
2016-08-17 06:25:58 +00:00
.3 stz UsrBuf256 reset UsrBuf256 for final CMDLINE
2015-10-19 20:35:00 +00:00
>PUSHW L.STAT
>PUSHW L.CMD
>SYSCALL STAT
2016-08-17 06:25:58 +00:00
bcs .99
2015-10-19 20:35:00 +00:00
lda STAT+S.STAT.P.TYPE
2015-10-19 20:35:00 +00:00
cmp #$04 TXT File ?
2016-08-17 06:25:58 +00:00
beq Cmd.Exec.EXT.TXT
cmp #$06 BIN File ?
beq Cmd.Exec.EXT.BIN
cmp #$ff SYS File ?
bne .9
2015-10-19 20:35:00 +00:00
2016-08-17 06:25:58 +00:00
bra *
2015-10-19 20:35:00 +00:00
2016-08-17 06:25:58 +00:00
.9 lda #SYSMGR.ERRSYN
sec
.99 jmp Cmd.Exec.Done
2016-08-17 06:25:58 +00:00
*--------------------------------------
* TXT : Launch "/PATH/SHELL /PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.TXT
lda #0 Get arg[0] = /PATH/SHELL
>SYSCALL GetArg.A
2016-08-17 06:25:58 +00:00
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL StrCpy
2016-08-17 06:25:58 +00:00
inc UsrBuf256 Add a space....
ldy UsrBuf256
2016-08-17 06:25:58 +00:00
lda #' '
sta UsrBuf256,y
2016-08-17 06:25:58 +00:00
*--------------------------------------
* BIN : Launch "/PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.BIN
>PUSHW L.CMD
>PUSHWI UsrBuf256
>SYSCALL StrCat
2015-10-19 20:35:00 +00:00
lda (ZPPTR2)
2016-08-17 06:25:58 +00:00
beq .1
inc UsrBuf256 Add a space....
ldy UsrBuf256
2016-08-17 06:25:58 +00:00
lda #' '
sta UsrBuf256,y
2016-08-17 06:25:58 +00:00
>PUSHW ZPPTR2
>PUSHWI UsrBuf256
>SYSCALL StrCat
2016-08-17 06:25:58 +00:00
.1 >LDYAI UsrBuf256
bit bStartProc
2016-08-17 06:25:58 +00:00
bmi .2 startproc
2016-03-13 21:53:55 +00:00
>SYSCALL ExecProcessNewEnvYA
jmp Cmd.Exec.Done
.2 >SYSCALL CreateProcessYA
jmp Cmd.Exec.Done
2016-08-17 06:25:58 +00:00
*--------------------------------------
* Internal Commands
2015-10-19 20:35:00 +00:00
*--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
2016-08-17 06:25:58 +00:00
bne Cmd.Exec.CD1
Cmd.Exec.PWD ldy #S.PS.hPREFIX
2015-10-19 20:35:00 +00:00
lda (pPs),y
>SYSCALL GetMemPtr.A
>PUSHYA
>LDYA L.MSG.PSTRCR
>SYSCALL PrintF.YA
rts
2015-10-19 20:35:00 +00:00
Cmd.Exec.CD1 stz UsrBuf256
2016-08-17 06:25:58 +00:00
cmp #'/' Full Path?
beq .1
2016-08-17 06:25:58 +00:00
ldy #S.PS.hPREFIX no, init target prefix with actual prefix
2015-10-19 20:35:00 +00:00
lda (pPs),y
>SYSCALL GetMemPtr.A
2016-08-17 06:25:58 +00:00
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL StrCpy
2015-10-19 20:35:00 +00:00
.1 >PUSHW ZPPTR2 Append ARG to buffer
>PUSHWI UsrBuf256
>SYSCALL StrCat
2016-08-17 06:25:58 +00:00
lda #'/'
ldx UsrBuf256
cmp UsrBuf256,x Ending '/' ?
beq .2
2016-08-17 06:25:58 +00:00
sta UsrBuf256+1,x no, add one...
inc UsrBuf256
.2 ldx #0 path is something like : /dir1/../dir2/
2016-08-17 06:25:58 +00:00
.3 ldy #0 reset char counter
2016-08-17 06:25:58 +00:00
.4 cpx UsrBuf256
beq .8
2016-08-17 06:25:58 +00:00
inx
lda UsrBuf256,x
2015-10-19 20:35:00 +00:00
cmp #'/'
beq .5
iny char=char+1!!!
bra .4
2016-08-17 06:25:58 +00:00
.5 tya any char count?
beq .4 no, start counting...
2016-08-17 06:25:58 +00:00
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
2016-08-17 06:25:58 +00:00
txa
tay save end of /../
2015-10-19 20:35:00 +00:00
sec
sbc #3 remove ../
tax
2016-08-17 06:25:58 +00:00
.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
2016-08-17 06:25:58 +00:00
bra .2 Start over...
2016-08-17 06:25:58 +00:00
.8 cpx #1
beq .80 we have '/' go change prefix
>PUSHW L.STAT
>PUSHWI UsrBuf256
>SYSCALL STAT
2016-08-17 06:25:58 +00:00
bcs .9
lda STAT+S.STAT.P.TYPE
cmp #$0F Directory ?
bne Cmd.Exec.ERRSYN
.80 >LDYAI UsrBuf256
>SYSCALL NewStr.YA
2016-08-17 06:25:58 +00:00
bcs .9
2016-03-13 21:53:55 +00:00
phx
2016-08-17 06:25:58 +00:00
ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL FreeMem.A
2016-08-17 06:25:58 +00:00
2016-03-13 21:53:55 +00:00
pla
2016-08-17 06:25:58 +00:00
ldy #S.PS.hPREFIX
sta (pPs),y
jsr SetPWD
2016-08-17 06:25:58 +00:00
clc
.9 rts
*--------------------------------------
Cmd.Exec.ERRSYN lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
2016-08-17 06:25:58 +00:00
Cmd.Exec.STARTPROC
lda (ZPPTR2)
2016-08-17 06:25:58 +00:00
beq Cmd.Exec.ERRSYN
2016-03-13 21:53:55 +00:00
sec
ror bStartProc
2016-03-13 21:53:55 +00:00
>LDYA ZPPTR2
>STYA ZPPTR1
jmp Cmd.ExecYA
2016-03-13 21:53:55 +00:00
*--------------------------------------
Cmd.Exec.SET lda (ZPPTR2)
2016-08-17 06:25:58 +00:00
bne Cmd.Exec.SETVAR
2015-10-19 20:35:00 +00:00
* No arg, print all ENV
2015-10-19 20:35:00 +00:00
ldy #S.PS.hENV
lda (pPs),y
>SYSCALL GetMemPtr.A
2015-10-19 20:35:00 +00:00
>STYA ZPPTR1
2015-10-19 20:35:00 +00:00
.1 lda (ZPPTR1)
beq .8 Ending 0 ?
ldy #$ff
.2 iny
lda (ZPPTR1),y
bne .2
tya
2016-08-17 06:25:58 +00:00
sec
adc ZPPTR1
sta ZPPTR2
lda #0
adc ZPPTR1+1
sta ZPPTR2+1
>PUSHW ZPPTR2 Push value
>PUSHW ZPPTR1 Push name
2016-08-17 06:25:58 +00:00
>LDYA L.MSG.PRINTENV
>SYSCALL PrintF.YA
>DEBUG
2016-08-17 06:25:58 +00:00
bcs .9
2015-10-19 20:35:00 +00:00
ldy #$ff
.3 iny
lda (ZPPTR2),y
bne .3
tya
2015-10-19 20:35:00 +00:00
sec
adc ZPPTR2
2015-10-19 20:35:00 +00:00
sta ZPPTR1
lda #0
adc ZPPTR2+1
sta ZPPTR1+1
2015-10-19 20:35:00 +00:00
bra .1
2015-10-19 20:35:00 +00:00
.8 clc
2016-08-17 06:25:58 +00:00
.9 rts
2015-10-19 20:35:00 +00:00
Cmd.Exec.SETVAR ldy #0
lda (ZPPTR2),y
iny
cmp #'=' string is '=value' ?
beq .99 syntax error
2015-10-19 20:35:00 +00:00
.1 lda (ZPPTR2),y
iny
2016-08-17 06:25:58 +00:00
beq .3 no =, GetEnv
2016-08-17 06:25:58 +00:00
cmp #'=' ARGS contains =, PutEnv
bne .1
2015-10-19 20:35:00 +00:00
lda (ZPPTR2),y
beq .2 "VAR=" go UnsetEnv
2016-08-17 06:25:58 +00:00
>LDYA ZPPTR2 String is VAR=VALUE...
>SYSCALL PutEnv.YA
2016-08-17 06:25:58 +00:00
rts
.2 dey String is "VAR=", Remove endig '='
sta (ZPPTR2),y
>LDYA ZPPTR2 String is "VAR"...
>SYSCALL UnsetEnv.YA
2016-08-17 06:25:58 +00:00
rts
* Print requested VAR
2016-08-17 06:25:58 +00:00
.3 >LDYA ZPPTR2
>SYSCALL GetEnv.YA
2016-08-17 06:25:58 +00:00
bcs .8
>PUSHYA push value
>PUSHW ZPPTR2 push name
>LDYA L.MSG.PRINTENV
>SYSCALL PrintF.YA
2016-08-17 06:25:58 +00:00
.8 clc
2016-08-17 06:25:58 +00:00
.9 rts
.99 jmp Cmd.Exec.ERRSYN
2015-10-19 20:35:00 +00:00
*--------------------------------------
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
2015-10-19 20:35:00 +00:00
*--------------------------------------
Cmd.Exec.ECHO lda (ZPPtr2)
beq Cmd.Exec.ECHO.CR
>PUSHW ZPPtr2
>LDYA L.MSG.PSTRCR
>SYSCALL PrintF.YA
rts
2015-10-19 20:35:00 +00:00
Cmd.Exec.ECHO.CR
lda #13
>SYSCALL PutChar.A
bcs Cmd.Exec.ECHO.RTS
lda #10
>SYSCALL PutChar.A
Cmd.Exec.ECHO.RTS
rts
2015-10-19 20:35:00 +00:00
*--------------------------------------
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
2015-10-19 20:35:00 +00:00
clc
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
LOAD /A2OSX.SRC/SBIN/SHELL.S
2015-10-19 20:35:00 +00:00
ASM