A2osX/SBIN/SHELL.S.CMD.txt

619 lines
11 KiB
Plaintext
Raw Normal View History

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
2015-10-19 20:35:00 +00:00
.LIST OFF
*--------------------------------------
CMD.Init >LDYAI CmdLine.MAX+1
2018-07-13 14:38:24 +00:00
>SYSCALL GetMem
bcs .9
>STYA ZPCMDBuf
txa
>STA.G hCmdBuf
.9 rts
*--------------------------------------
CMD.Quit >LDA.G hCmdBuf
beq .9
2018-07-13 14:38:24 +00:00
>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)
2016-08-17 06:25:58 +00:00
*--------------------------------------
Cmd.Exec lda #0
>STA.G CMD.bStartProc
>STA.G CMD.hFullpath
2018-07-20 11:51:08 +00:00
* SET +X
2018-07-26 06:03:49 +00:00
* >LDYA ZPCMDBuf
* >SYSCALL puts
2018-07-16 05:52:52 +00:00
2018-07-26 06:03:49 +00:00
* sta $C055
* >DEBUG
2018-07-25 15:26:14 +00:00
2018-07-16 05:52:52 +00:00
>LDYA ZPCMDBuf
2018-07-13 14:38:24 +00:00
>SYSCALL ExpandStr
>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
2018-07-13 14:38:24 +00:00
>SYSCALL FreeMem
>LDA.G CMD.hFullpath
beq .1
2018-07-13 14:38:24 +00:00
>SYSCALL FreeMem
2018-08-11 10:57:57 +00:00
>STZ.G CMD.hFullpath
.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
2018-07-20 11:51:08 +00:00
>LDYA ZPPtr1
>SYSCALL STAT
bcs Cmd.Exec.Done
>LDYA ZPPtr1
bra .4
.1 >LDYA L.ENV.PATH push ENVNAME=PATH for search
2018-07-13 14:38:24 +00:00
>SYSCALL GetEnv 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
2018-07-13 14:38:24 +00:00
>SYSCALL GetMemPtr
jsr Cmd.Exec.EXT.Search
2016-08-17 06:25:58 +00:00
bcs .99
.3 >LDYA ZPCMDBuf
2017-12-14 16:25:03 +00:00
2018-07-13 14:38:24 +00:00
.4 >SYSCALL NewStr
bcs .99
txa
>STA.G CMD.hFullpath
2017-12-14 16:25:03 +00:00
lda #0
sta (ZPCMDBuf) reset ZPCMDBuf for final CMD
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
2017-12-14 16:25:03 +00:00
2018-07-13 14:38:24 +00:00
>SYSCALL GetArg
>PUSHYA
2018-07-16 05:52:52 +00:00
>LDYA ZPCMDBuf
2017-12-14 16:25:03 +00:00
>SYSCALL StrCat
2016-08-17 06:25:58 +00:00
jsr Cmd.Exec.EXT.SEP Add a space....
2017-12-14 16:25:03 +00:00
*--------------------------------------
* BIN : Launch "/PATH/CMD ARGS"
*--------------------------------------
Cmd.Exec.EXT.BIN
>LDA.G CMD.hFullpath
2018-07-13 14:38:24 +00:00
>SYSCALL GetMemPtr
>PUSHYA
2018-07-16 05:52:52 +00:00
>LDYA ZPCMDBuf
>SYSCALL StrCat
2017-12-14 16:25:03 +00:00
lda (ZPPTR2) Some ARGS ?
beq .1
jsr Cmd.Exec.EXT.SEP Add a space....
2016-08-17 06:25:58 +00:00
>PUSHW ZPPTR2
2018-07-16 05:52:52 +00:00
>LDYA ZPCMDBuf
>SYSCALL StrCat
.1 >LDA.G CMD.bStartProc
asl
>LDYA ZPCMDBuf
bcs .2 startproc
2016-03-13 21:53:55 +00:00
2018-07-13 14:38:24 +00:00
>SYSCALL ExecPSNewEnv
jmp Cmd.Exec.Done
2018-07-13 14:38:24 +00:00
.2 >SYSCALL CreatePSNewEnv
jmp Cmd.Exec.Done
2016-08-17 06:25:58 +00:00
*--------------------------------------
Cmd.Exec.EXT.Search
2018-07-16 05:52:52 +00:00
pha
phy
>PUSHEA.G CMD.Stat
2018-07-16 05:52:52 +00:00
>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
*--------------------------------------
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
2018-07-13 14:38:24 +00:00
>SYSCALL GetMemPtr
2018-08-22 15:23:27 +00:00
>SYSCALL puts
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.CD lda (ZPPTR2)
bne .1
2018-08-11 10:57:57 +00:00
>LDYA L.ENV.HOME
2018-07-13 14:38:24 +00:00
>SYSCALL GetEnv
bcs Cmd.Exec.PWD
2018-07-13 14:38:24 +00:00
>SYSCALL ExpandStr
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
.3 >LDYA ZPPTR2 Get ARG
2018-07-13 14:38:24 +00:00
>SYSCALL RealPath
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
2018-07-20 11:51:08 +00:00
>LDYA 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
2018-07-13 14:38:24 +00:00
>SYSCALL NewStr
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
2018-07-13 14:38:24 +00:00
>SYSCALL FreeMem
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
2018-07-13 14:38:24 +00:00
>SYSCALL GetMemPtr
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
2018-08-22 15:23:27 +00:00
>PUSHBI 4
>LDYA L.MSG.PRINTENV
2018-06-21 15:12:10 +00:00
>SYSCALL printf
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...
2018-07-13 14:38:24 +00:00
>SYSCALL PutEnv
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"...
2018-07-13 14:38:24 +00:00
>SYSCALL UnsetEnv
jmp Cmd.Exec.Done
* Print requested VAR
2016-08-17 06:25:58 +00:00
.3 >LDYA ZPPTR2
2018-07-13 14:38:24 +00:00
>SYSCALL GetEnv
2016-08-17 06:25:58 +00:00
bcs .8
>PUSHYA push value
>PUSHW ZPPTR2 push name
>LDYA L.MSG.PRINTENV
2018-08-22 15:23:27 +00:00
>PUSHBI 4
2018-06-21 15:12:10 +00:00
>SYSCALL printf
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
2018-07-13 14:38:24 +00:00
>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
2018-08-22 15:23:27 +00:00
>SYSCALL puts
jmp Cmd.Exec.Done
2015-10-19 20:35:00 +00:00
*--------------------------------------
2018-08-22 15:23:27 +00:00
Cmd.Exec.ECHO >LDYA ZPPtr2
>SYSCALL puts
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
2018-07-13 14:38:24 +00:00
>SYSCALL PutChar
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