mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-03 12:06:05 +00:00
777 lines
12 KiB
Plaintext
777 lines
12 KiB
Plaintext
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
|
||
*--------------------------------------
|
||
* in:
|
||
* ZPCMDBuf : CString command line
|
||
* out:
|
||
* ZPCMDBuf : Remove extra SPACE & comment
|
||
* ZPCMDBuf : cmd\0 arg1\0 arg2\0 ... \0
|
||
*--------------------------------------
|
||
Cmd.Parse >LDYA ZPCMDBuf
|
||
>SYSCALL ExpandStr
|
||
bcs .99
|
||
|
||
phx save expanded string
|
||
pha
|
||
>PUSHW ZPCMDBuf
|
||
pla
|
||
>SYSCALL Args2ArgV
|
||
plx
|
||
>SYSCALL FreeMem
|
||
|
||
.99 rts
|
||
*--------------------------------------
|
||
* ZPCMDBuf-> argv[] (formatted & not empty)
|
||
*--------------------------------------
|
||
CMD.Exec lda #S.PS.F.HOLD+S.PS.F.DUPENV
|
||
>STA.G CMD.PSFlags
|
||
|
||
>LDYA L.CMD.INT
|
||
>STYA ZPPtr2
|
||
|
||
ldx #0
|
||
|
||
.1 phx
|
||
|
||
>PUSHW ZPPtr2
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL StrCaseCmp
|
||
bcs .2
|
||
|
||
ldx #0
|
||
jsr Cmd.RemoveStrAtX Remove CMD...
|
||
|
||
plx
|
||
jmp (J.CMD.INT,x) Found an internal Cmd...
|
||
|
||
.2 jsr Cmd.NextStrPtr2
|
||
>STYA ZPPtr2
|
||
plx
|
||
inx
|
||
inx
|
||
|
||
lda (ZPPtr2) Array Ending 0, must be an external Cmd....
|
||
bne .1
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT ldy #0
|
||
|
||
.10 lda (ZPCMDBuf),y
|
||
beq .1 no / found, search...
|
||
cmp #'/'
|
||
beq .11 found /, some path specified, no search
|
||
iny
|
||
bra .10
|
||
|
||
.11 >LDYA ZPCMDBuf
|
||
>SYSCALL realpath
|
||
bcs .99
|
||
|
||
phy
|
||
pha
|
||
txa
|
||
>STA.G CMD.hCmdLine
|
||
pla
|
||
ply
|
||
>PUSHEA.G CMD.Stat Command line is already full path, no search
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL STAT
|
||
bcc .2
|
||
rts
|
||
|
||
.1 >LDYAI 256 Get a buffer for found path
|
||
>SYSCALL GetMem
|
||
bcs .99
|
||
txa
|
||
>STA.G CMD.hCmdLine
|
||
|
||
>LDYA L.ENV.PATH push ENVNAME=PATH for search
|
||
>SYSCALL GetEnv get value for ENV=PATH
|
||
bcs .99 No PATH, try in CD
|
||
|
||
jsr Cmd.Exec.EXT.Search
|
||
bcc .2
|
||
|
||
ldy #S.PS.hPREFIX not found, try in CD
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr
|
||
jsr Cmd.Exec.EXT.Search
|
||
bcc .2
|
||
|
||
pha
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL FreeMem
|
||
pla
|
||
|
||
sec
|
||
.99 rts
|
||
|
||
* CMD.hCmdLine = /path/bin
|
||
|
||
.2 >DEBUG
|
||
|
||
ldx #0
|
||
jsr Cmd.RemoveStrAtX
|
||
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL GetMemPtr
|
||
ldx #0
|
||
jsr CMD.InsertStrYAAtX
|
||
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL FreeMem
|
||
|
||
ldy #CMD.Stat+S.STAT.P.TYPE
|
||
lda (pData),y
|
||
cmp #S.FI.T.TXT
|
||
beq Cmd.Exec.EXT.TXT
|
||
cmp #S.FI.T.BIN
|
||
beq Cmd.Exec.EXT.BIN
|
||
cmp #S.FI.T.SYS
|
||
bne .9
|
||
|
||
bra *
|
||
|
||
.9 lda #K.E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT.Search
|
||
pha
|
||
phy
|
||
>PUSHEA.G CMD.Stat
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL GetMemPtr
|
||
>PUSHYA push dest full path
|
||
ply
|
||
pla
|
||
>PUSHYA push search list
|
||
>LDYA ZPCMDBuf push CMD
|
||
>SYSCALL FileSearch
|
||
rts
|
||
*--------------------------------------
|
||
* TXT : Launch "/PATH/SHELL /PATH/CMD ARGS"
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT.TXT
|
||
lda #0
|
||
>SYSCALL ArgV
|
||
ldx #0
|
||
jsr Cmd.InsertStrYAAtX
|
||
*--------------------------------------
|
||
* BIN : Launch "/PATH/CMD ARGS"
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT.BIN
|
||
>PUSHB.G CMD.PSFlags
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL Exec
|
||
rts
|
||
*--------------------------------------
|
||
* Internal Commands
|
||
*--------------------------------------
|
||
Cmd.INT.PWD ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr
|
||
>SYSCALL puts
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.CD lda (ZPCMDBuf)
|
||
bne .1
|
||
|
||
>LDYA L.ENV.HOME
|
||
>SYSCALL GetEnv
|
||
bcs Cmd.INT.PWD
|
||
|
||
>SYSCALL ExpandStr
|
||
bcs .9
|
||
|
||
bra .4
|
||
|
||
.1 ldy #0
|
||
|
||
.2 lda (ZPCMDBuf),y
|
||
tax
|
||
iny
|
||
lda (ZPCMDBuf),y
|
||
bne .2
|
||
cpx #'/'
|
||
beq .3
|
||
|
||
lda #'/'
|
||
sta (ZPCMDBuf),y
|
||
iny
|
||
lda #0
|
||
sta (ZPCMDBuf),y
|
||
|
||
.3 >LDYA ZPCMDBuf Get ARG0
|
||
>SYSCALL RealPath
|
||
bcs .9
|
||
|
||
.4 >STYA ZPCMDBuf
|
||
txa
|
||
>STA.G CMD.hCmdLine
|
||
|
||
ldy #1
|
||
lda (ZPCMDBuf),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 ZPCMDBuf
|
||
>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 rts
|
||
*--------------------------------------
|
||
Cmd.Exec.ERRSYN lda #K.E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.STARTPROC
|
||
lda (ZPCMDBuf)
|
||
beq Cmd.Exec.ERRSYN
|
||
|
||
>LDA.G CMD.PSFlags
|
||
and #$ff^S.PS.F.HOLD
|
||
sta (pData),y
|
||
|
||
jmp Cmd.Exec.EXT
|
||
*--------------------------------------
|
||
Cmd.INT.SET lda (ZPCMDBuf)
|
||
bne Cmd.INT.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.INT.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 rts
|
||
*--------------------------------------
|
||
Cmd.INT.SETVAR cmp #'=' string is '=value' ?
|
||
beq .99 syntax error
|
||
|
||
ldy #0
|
||
|
||
.1 iny
|
||
lda (ZPCMDBuf),y
|
||
beq .3 no =, GetEnv
|
||
|
||
cmp #'=' ARGS contains =, PutEnv
|
||
bne .1
|
||
|
||
iny
|
||
lda (ZPCMDBuf),y
|
||
beq .2 "VAR=" go UnsetEnv
|
||
|
||
>LDYA ZPCMDBuf String is VAR=VALUE...
|
||
>SYSCALL PutEnv
|
||
rts
|
||
|
||
.2 dey String is "VAR=", Remove ending '='
|
||
lda #0
|
||
sta (ZPCMDBuf),y
|
||
|
||
>LDYA ZPCMDBuf String is "VAR"...
|
||
>SYSCALL UnsetEnv
|
||
rts
|
||
|
||
* Print requested VAR
|
||
|
||
.3 >LDYA ZPCMDBuf
|
||
>SYSCALL GetEnv
|
||
bcs .8
|
||
|
||
>PUSHYA push value
|
||
>PUSHW ZPCMDBuf push name
|
||
jsr Cmd.INT.SET.PRINT
|
||
|
||
.8 clc
|
||
.9 rts
|
||
|
||
.99 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.INT.SET.PRINT
|
||
>PUSHBI 4
|
||
>LDYA L.MSG.PRINTENV
|
||
>SYSCALL printf
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.DATE sec
|
||
.HS 90 bcc
|
||
Cmd.INT.TIME clc
|
||
php
|
||
>LEA.G CMD.Time
|
||
>SYSCALL Time
|
||
|
||
>PUSHEA.G CMD.Time
|
||
|
||
plp
|
||
bcc .1
|
||
>PUSHW L.FMT.DATE
|
||
bra .2
|
||
.1 >PUSHW L.FMT.TIME
|
||
|
||
.2 >LDYA ZPCMDBuf
|
||
>SYSCALL StrFTime
|
||
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL puts
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.ECHO >PUSHW ZPCMDBuf
|
||
ldy #S.PS.hStdOut
|
||
lda (pPs),y
|
||
>SYSCALL fputs
|
||
bcs .9
|
||
|
||
ldx #1
|
||
|
||
.1 phx
|
||
jsr Cmd.GetStrAtX
|
||
bcs .7
|
||
>PUSHYA
|
||
|
||
lda #C.SPACE
|
||
>SYSCALL putchar
|
||
|
||
ldy #S.PS.hStdOut
|
||
lda (pPs),y
|
||
>SYSCALL fputs
|
||
plx
|
||
inx
|
||
bcc .1
|
||
|
||
rts
|
||
|
||
.7 plx
|
||
>LDA.G bECHO.N
|
||
bmi .8
|
||
|
||
>PUSHBI 0
|
||
>LDYA L.MSG.ECHOCRLF
|
||
>SYSCALL printf
|
||
rts
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.INT.READ lda (ZPCMDBuf)
|
||
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.NextCharPtr2
|
||
bra .1
|
||
|
||
.11 cmp #'-'
|
||
bne .7
|
||
|
||
jsr Cmd.NextCharPtr2
|
||
beq .9
|
||
|
||
cmp #'S'
|
||
bne .2
|
||
|
||
lda #$80
|
||
>STA.G bSecureRead
|
||
|
||
jsr Cmd.NextCharPtr2
|
||
beq .8
|
||
cmp #' '
|
||
bne .9
|
||
|
||
bra .1
|
||
|
||
.2 cmp #'P'
|
||
bne .9
|
||
|
||
jsr Cmd.NextCharPtr2
|
||
beq .9
|
||
|
||
cmp #' '
|
||
bne .9
|
||
|
||
jsr Cmd.NextCharPtr2
|
||
beq .9
|
||
|
||
cmp #'"'
|
||
bne .9
|
||
|
||
.3 jsr Cmd.NextCharPtr2
|
||
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.NextCharPtr2
|
||
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 rts
|
||
*--------------------------------------
|
||
Cmd.INT.SLEEP lda (ZPCMDBuf)
|
||
beq .9
|
||
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL AToL
|
||
bcs .9
|
||
|
||
>PULLL.G Sleep
|
||
clc
|
||
rts
|
||
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.INT.PAUSE lda #$FF
|
||
>STA.G bPause
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.EXIT lda #$FF
|
||
>STA.G bExit
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.IF >STZ.G CMD.IFNOT
|
||
|
||
lda (ZPCMDBuf)
|
||
beq .9
|
||
|
||
cmp #'!'
|
||
bne .1
|
||
|
||
lda #$ff
|
||
sta (pData),y Y = #CMD.IFNOT
|
||
|
||
jsr Cmd.NextCharPtr2NB
|
||
beq .9
|
||
|
||
cmp #'('
|
||
bne .9
|
||
|
||
jsr Cmd.NextCharPtr2NB
|
||
beq .9
|
||
|
||
cmp #'-' -d -e -f
|
||
bne .1
|
||
|
||
jsr Cmd.NextCharPtr2NB
|
||
beq .9
|
||
|
||
|
||
|
||
.1 >DEBUG
|
||
|
||
|
||
|
||
|
||
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL puts
|
||
|
||
rts
|
||
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.InsertStrYAAtX
|
||
>STYA ZPPtr3 new string to insert
|
||
|
||
>LDYA ZPCMDBuf
|
||
>STYA ZPPtr1
|
||
|
||
.1 dex
|
||
bmi .2
|
||
|
||
jsr Cmd.NextStrPtr1
|
||
>STYA ZPPtr1
|
||
bra .1
|
||
|
||
.2 >LDYA ZPPtr1
|
||
>STYA ZPPtr4 Save Arg[x] ptr
|
||
|
||
>LDYA ZPPtr3
|
||
>SYSCALL strlen
|
||
pha
|
||
tya
|
||
sec +1
|
||
adc ZPPtr1
|
||
sta ZPPtr2
|
||
|
||
pla
|
||
adc ZPPtr1+1
|
||
lda ZPPtr2+1
|
||
|
||
ldy #0
|
||
|
||
.3 lda (ZPPtr1),y
|
||
sta (ZPPtr2),y
|
||
beq .4
|
||
iny
|
||
bne .3
|
||
|
||
.4 tay
|
||
beq .5
|
||
|
||
jsr Cmd.NextStrPtr1
|
||
>STYA ZPPtr1
|
||
jsr Cmd.NextStrPtr2
|
||
>STYA ZPPtr2
|
||
bra .3
|
||
|
||
.5 ldy #0
|
||
|
||
.6 lda (ZPPtr3),y
|
||
sta (ZPPtr4),y
|
||
beq .8
|
||
iny
|
||
bne .6
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.RemoveStrAtX
|
||
>LDYA ZPCMDBuf
|
||
>STYA ZPPtr1
|
||
|
||
.1 dex
|
||
bmi .2
|
||
|
||
jsr Cmd.NextStrPtr1
|
||
>STYA ZPPtr1
|
||
bra .1
|
||
|
||
.2 jsr Cmd.NextStrPtr1
|
||
>STYA ZPPtr2
|
||
|
||
.3 ldy #0
|
||
|
||
.4 lda (ZPPtr2),y
|
||
sta (ZPPtr1),y
|
||
beq .5
|
||
iny
|
||
bra .4
|
||
|
||
.5 tya we moved the ending \0
|
||
beq .8
|
||
|
||
sec
|
||
adc ZPPtr2
|
||
sta ZPPtr2
|
||
bcc .6
|
||
|
||
inc ZPPtr2+1
|
||
|
||
.6 tya
|
||
|
||
sec
|
||
adc ZPPtr1
|
||
sta ZPPtr1
|
||
bcc .3
|
||
|
||
inc ZPPtr2+1
|
||
bra .3
|
||
|
||
.8 rts
|
||
*--------------------------------------
|
||
Cmd.GetStrAtX >LDYA ZPCMDBuf
|
||
|
||
.1 dex
|
||
bmi .8
|
||
|
||
>STYA ZPPtr1
|
||
|
||
jsr Cmd.NextStrPtr1
|
||
bcc .1
|
||
rts
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.NextStrPtr1 lda (ZPPtr1)
|
||
beq .9
|
||
|
||
phx
|
||
>LDYA ZPPtr1
|
||
>SYSCALL strlen
|
||
pha
|
||
tya
|
||
sec +1
|
||
adc ZPPtr1
|
||
tay
|
||
|
||
pla
|
||
adc ZPPtr1+1
|
||
plx
|
||
* clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.NextStrPtr2 lda (ZPPtr2)
|
||
beq .9
|
||
|
||
>LDYA ZPPtr2
|
||
>SYSCALL strlen
|
||
pha
|
||
tya
|
||
sec +1
|
||
adc ZPPtr2
|
||
tay
|
||
|
||
pla
|
||
adc ZPPtr2+1
|
||
* clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.NextCharPtr1
|
||
lda (ZPPtr1)
|
||
beq .8
|
||
|
||
inc ZPPtr1
|
||
bne .8
|
||
inc ZPPtr1+1 never Z
|
||
.8 rts
|
||
*--------------------------------------
|
||
Cmd.NextCharPtr2NB
|
||
.1 jsr Cmd.NextCharPtr2
|
||
beq .9
|
||
cmp #C.SPACE
|
||
beq .1
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.NextCharPtr2
|
||
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
|