A2osX/SBIN/SHELL.S.CMD.txt

615 lines
11 KiB
Plaintext
Raw Normal View History

2015-10-19 20:35:00 +00:00
PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
2015-10-19 20:35:00 +00:00
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
CMD.Init >LDYAI CmdLine.MAX+1
>SYSCALL GetMem.YA
bcs .9
>STYA ZPCMDBuf
txa
>STA.G hCmdBuf
.9 rts
*--------------------------------------
CMD.Quit >LDA.G hCmdBuf
beq .9
>SYSCALL FreeMem.A
.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)
2016-08-17 06:25:58 +00:00
*--------------------------------------
Cmd.Exec lda #0
>STA.G CMD.bStartProc
>STA.G CMD.hFullpath
>LDYA ZPCMDBuf
>SYSCALL ExpandStr.YA
>STYA ZPPtr1 Ptr to CMD ARGS
2016-08-17 06:25:58 +00:00
txa
>STA.G CMD.hCmdLine
>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
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....
2016-08-17 06:25:58 +00:00
.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
2015-10-19 20:35:00 +00:00
tya
sec
adc ZPPtr2
sta ZPPtr2
bcc .3
inc ZPPtr2+1
bra .3
.8 jsr Cmd.Exec.Split X unmodified
jmp (J.INTCMDS,x) Found an internal Cmd...
*--------------------------------------
Cmd.Exec.Done php
pha
>LDA.G CMD.hCmdLine
>SYSCALL FreeMem.A
>LDA.G CMD.hFullpath
beq .1
>SYSCALL FreeMem.A
.1 pla
2017-08-23 11:33:51 +00:00
plp
rts
*--------------------------------------
Cmd.Exec.EXT jsr Cmd.Exec.Split
lda (ZPPtr1)
2016-08-17 06:25:58 +00:00
cmp #'/' Command line is already full path, no search
bne .1
>PUSHEA.G CMD.Stat
>PUSHW ZPPtr1
>SYSCALL STAT
bcs Cmd.Exec.Done
>LDYA ZPPtr1
bra .4
.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
2015-10-19 20:35:00 +00:00
jsr Cmd.Exec.EXT.Search
bcc .3
2015-10-19 20:35:00 +00:00
.2 ldy #S.PS.hPREFIX not found, try in CD
2015-10-19 20:35:00 +00:00
lda (pPs),y
>SYSCALL GetMemPtr.A
jsr Cmd.Exec.EXT.Search
2016-08-17 06:25:58 +00:00
bcs .99
.3 >LDYA ZPCMDBuf
.4 >SYSCALL NewStr.YA
bcs .99
txa
>STA.G CMD.hFullpath
ldy #CMD.Stat+S.STAT.P.TYPE
lda (pData),y
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
.9 lda #K.E.SYN
2016-08-17 06:25:58 +00:00
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
>PUSHYA
>PUSHW ZPCMDBuf
>SYSCALL StrCpy
2016-08-17 06:25:58 +00:00
jsr Cmd.Exec.EXT.SEP Add a space....
>LDA.G CMD.hFullpath
>SYSCALL GetMemPtr.A
>PUSHYA
>PUSHW ZPCMDBuf
>SYSCALL StrCat
2016-08-17 06:25:58 +00:00
*--------------------------------------
* BIN : Launch "/PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.BIN
lda (ZPPTR2) Some ARGS ?
beq .1
jsr Cmd.Exec.EXT.SEP Add a space....
2016-08-17 06:25:58 +00:00
>PUSHW ZPPTR2
>PUSHW ZPCMDBuf
>SYSCALL StrCat
.1 >LDA.G CMD.bStartProc
asl
>LDYA ZPCMDBuf
bcs .2 startproc
2016-03-13 21:53:55 +00:00
>SYSCALL ExecPSNewEnv.YA
jmp Cmd.Exec.Done
.2 >SYSCALL CreatePSNewEnv.YA
jmp Cmd.Exec.Done
2016-08-17 06:25:58 +00:00
*--------------------------------------
Cmd.Exec.EXT.Search
>PUSHYA push search list
>PUSHW ZPPtr1 push CMD
>PUSHW ZPCMDBuf push dest full path
>PUSHEA.G CMD.Stat
>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
*--------------------------------------
2016-08-17 06:25:58 +00:00
* Internal Commands
2015-10-19 20:35:00 +00:00
*--------------------------------------
Cmd.Exec.PWD ldy #S.PS.hPREFIX
2015-10-19 20:35:00 +00:00
lda (pPs),y
>SYSCALL GetMemPtr.A
>SYSCALL PrintF.YA
jmp Cmd.Exec.ECHO.CR
*--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
bne .1
2015-10-19 20:35:00 +00:00
>LDYA L.ENV.HOME
>SYSCALL GetEnv.YA
bcs Cmd.Exec.PWD
>SYSCALL ExpandStr.YA
bcs .9
2016-08-17 06:25:58 +00:00
bra .4
2015-10-19 20:35:00 +00:00
.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
2016-08-17 06:25:58 +00:00
.3 >LDYA ZPPTR2 Get ARG
>SYSCALL RealPath.YA
bcs .9
2016-08-17 06:25:58 +00:00
.4 >STYA ZPPTR2
txa
>STA.G CMD.hFullpath
ldy #1
lda (ZPPTR2),y
beq .8 we have '/'
>PUSHEA.G CMD.Stat
>PUSHW ZPPTR2
>SYSCALL STAT
2016-08-17 06:25:58 +00:00
bcs .9
ldy #CMD.Stat+S.STAT.P.TYPE
lda (pData),y
cmp #$0F Directory ?
bne Cmd.Exec.ERRSYN
.8 >LDYA ZPPTR2
>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 jmp Cmd.Exec.Done
2016-08-17 06:25:58 +00:00
*--------------------------------------
Cmd.Exec.ERRSYN lda #K.E.SYN
sec
jmp Cmd.Exec.Done
*--------------------------------------
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
lda #$ff
>STA.G CMD.bStartProc
2016-03-13 21:53:55 +00:00
>LDYA ZPPTR2
>STYA ZPPTR1
jmp Cmd.Exec.EXT
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
* 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
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
.9 jmp Cmd.Exec.Done
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
jmp Cmd.Exec.Done
2016-08-17 06:25:58 +00:00
.2 dey String is "VAR=", Remove endig '='
sta (ZPPTR2),y
>LDYA ZPPTR2 String is "VAR"...
>SYSCALL UnsetEnv.YA
jmp Cmd.Exec.Done
* 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
.9 jmp Cmd.Exec.Done
.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
>LEA.G CMD.Time
>SYSCALL Time.YA
>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 PrintF.YA
bcs Cmd.Exec.ECHO.END
bra Cmd.Exec.ECHO.CR
2015-10-19 20:35:00 +00:00
*--------------------------------------
Cmd.Exec.ECHO lda (ZPPtr2)
beq Cmd.Exec.ECHO.CR
>LDYA ZPPtr2
>SYSCALL PrintF.YA
2015-10-19 20:35:00 +00:00
Cmd.Exec.ECHO.CR
lda #13
>SYSCALL PutChar.A
bcs Cmd.Exec.ECHO.END
lda #10
>SYSCALL PutChar.A
Cmd.Exec.ECHO.END
jmp Cmd.Exec.Done
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 jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.SLEEP lda (ZPPtr2)
beq .9
>PUSHW ZPPtr2
>PUSHEA.G Sleep
>SYSCALL AToL
bcs .9
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
2015-10-19 20:35:00 +00:00
clc
jmp Cmd.Exec.Done
2015-10-19 20:35:00 +00:00
*--------------------------------------
Cmd.Exec.Split 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
rts
*--------------------------------------
2015-10-19 20:35:00 +00:00
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
LOAD /A2OSX.SRC/SBIN/SHELL.S
2015-10-19 20:35:00 +00:00
ASM