mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-27 04:49:20 +00:00
816 lines
12 KiB
Plaintext
816 lines
12 KiB
Plaintext
NEW
|
||
PREFIX /A2OSX.BUILD
|
||
AUTO 4,1
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
CMD.Init >LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
>STYA ZPCLBuf
|
||
|
||
txa
|
||
>STA.G CMD.hCLBuf
|
||
|
||
>LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
>STYA ZPArgVBuf
|
||
txa
|
||
>STA.G CMD.hArgVBuf
|
||
|
||
lda #CMD.STACK.PTR
|
||
tay
|
||
sta (pData),y
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
CMD.Quit >LDA.G CMD.hArgVBuf
|
||
beq .1
|
||
>SYSCALL FreeMem
|
||
|
||
.1 >LDA.G CMD.hCLBuf
|
||
beq .9
|
||
>SYSCALL FreeMem
|
||
.9 rts
|
||
*--------------------------------------
|
||
* Input : ZPArgVBuf
|
||
*--------------------------------------
|
||
Cmd.Exec >LDA.G CMD.IntCmd
|
||
bmi .2 External
|
||
|
||
tax
|
||
cpx #C.ELSE
|
||
bcs .1
|
||
|
||
>LDA.G CMD.STACK.PTR
|
||
|
||
cmp #CMD.STACK.PTR
|
||
beq .1 no IF pending...
|
||
|
||
tay
|
||
lda (pData),y
|
||
bpl .8 FALSE
|
||
|
||
.1 jmp (J.CMD.INT,x)
|
||
|
||
.2 >PUSHB.G CMD.PSFlags
|
||
>LDYA ZPArgVBuf
|
||
>SYSCALL execv
|
||
bcs .9
|
||
|
||
tax CPID
|
||
|
||
>LDA.G CMD.PSFlags
|
||
and #S.PS.F.HOLD
|
||
bne .3
|
||
|
||
txa
|
||
>PUSHA
|
||
>PUSHBI 1
|
||
>LDYA L.MSG.PID
|
||
>SYSCALL printf
|
||
rts
|
||
|
||
.3 >SLEEP Suspend this PID
|
||
|
||
ldy #S.PS.RC
|
||
lda (pPs),y
|
||
bne .9
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
* STARTPROC : intcmd = 0
|
||
*--------------------------------------
|
||
Cmd.INT.STARTPROC
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.PWD ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr
|
||
>SYSCALL puts
|
||
Cmd.INT.PWD.RTS rts
|
||
*--------------------------------------
|
||
Cmd.INT.CD ldx #1
|
||
jsr Cmd.GetArgX
|
||
bcc .1
|
||
|
||
>LDYA L.ENV.HOME
|
||
>SYSCALL GetEnv
|
||
bcs Cmd.INT.PWD
|
||
|
||
>SYSCALL ExpandStr
|
||
bcs Cmd.INT.PWD.RTS
|
||
bra .4
|
||
|
||
.1 >SYSCALL RealPath
|
||
bcs .9
|
||
|
||
.4 >STYA ZPPtr1
|
||
txa
|
||
>STA.G CMD.hCmdLine
|
||
|
||
ldy #1
|
||
lda (ZPPtr1),y
|
||
beq .8 we have '/'
|
||
|
||
>PUSHEA.G CMD.Stat
|
||
>LDYA ZPPtr1
|
||
>SYSCALL STAT
|
||
bcs .90
|
||
|
||
>LDA.G CMD.Stat+S.STAT.P.TYPE
|
||
cmp #S.FI.T.DIR
|
||
bne Cmd.Exec.ERRSYN
|
||
|
||
ldy #0
|
||
|
||
.5 iny
|
||
lda (ZPPtr1),y
|
||
bne .5
|
||
|
||
dey
|
||
lda #'/'
|
||
cmp (ZPPtr1),y
|
||
beq .8
|
||
|
||
iny
|
||
sta (ZPPtr1),y
|
||
iny
|
||
lda #0
|
||
sta (ZPPtr1),y
|
||
|
||
.8 >LDYA ZPPtr1
|
||
>SYSCALL NewStr
|
||
bcs .90
|
||
phx
|
||
|
||
ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL FreeMem
|
||
|
||
pla
|
||
|
||
ldy #S.PS.hPREFIX
|
||
sta (pPs),y
|
||
jsr SetPWD.I
|
||
|
||
.90 php
|
||
pha
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL FreeMem
|
||
pla
|
||
plp
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.Exec.ERRSYN lda #E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.SET ldx #1
|
||
jsr Cmd.GetArgX
|
||
bcc 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 jsr CMD.IsSwitch
|
||
bcs .10
|
||
|
||
cmp #'X'
|
||
bne .99
|
||
|
||
lda #$ff
|
||
>EOR.G bSET.X
|
||
sta (pData),y
|
||
.8 clc
|
||
rts
|
||
|
||
.10 lda (ZPPTR1) set by CMD.IsSwitch
|
||
cmp #'=' string is '=value' ?
|
||
beq .99 syntax error
|
||
|
||
ldy #0
|
||
|
||
.1 iny
|
||
lda (ZPPTR1),y
|
||
beq .3 no =, GetEnv
|
||
|
||
cmp #'=' ARGS contains =, PutEnv
|
||
bne .1
|
||
|
||
iny
|
||
lda (ZPPTR1),y
|
||
beq .2 "VAR=" go UnsetEnv
|
||
|
||
>LDYA ZPPTR1 String is VAR=VALUE...
|
||
>SYSCALL PutEnv
|
||
rts
|
||
|
||
.2 dey String is "VAR=", Remove ending '='
|
||
lda #0
|
||
sta (ZPPTR1),y
|
||
|
||
>LDYA ZPPTR1 String is "VAR"...
|
||
>SYSCALL UnsetEnv
|
||
rts
|
||
|
||
.99 lda #E.SYN
|
||
sec
|
||
rts
|
||
* Print requested VAR
|
||
|
||
.3 >LDYA ZPPTR1
|
||
>SYSCALL GetEnv
|
||
bcs .8
|
||
|
||
>PUSHYA push value
|
||
>PUSHW ZPPTR1 push name
|
||
*--------------------------------------
|
||
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 ZPCLBuf
|
||
>SYSCALL StrFTime
|
||
|
||
>LDYA ZPCLBuf
|
||
>SYSCALL puts
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.ECHO lda #1
|
||
>STA.G CMD.ArgIndex
|
||
|
||
tax
|
||
jsr Cmd.GetArgX
|
||
bcs .7
|
||
|
||
pha
|
||
>PUSHBI 0
|
||
pla
|
||
>SYSCALL printf
|
||
bcs .9
|
||
|
||
>INC.G CMD.ArgIndex
|
||
tax
|
||
|
||
jsr Cmd.GetArgX
|
||
bcs .7
|
||
|
||
.1 lda #C.SPACE
|
||
>SYSCALL putchar
|
||
bcs .9
|
||
|
||
>PUSHBI 0
|
||
|
||
>LDA.G CMD.ArgIndex
|
||
tax
|
||
jsr Cmd.GetArgX
|
||
|
||
>SYSCALL printf
|
||
bcs .9
|
||
|
||
>INC.G CMD.ArgIndex
|
||
tax
|
||
|
||
jsr Cmd.GetArgX
|
||
bcc .1
|
||
|
||
.7 >LDA.G bECHO.N
|
||
bmi .8
|
||
|
||
>PUSHBI 0
|
||
>LDYA L.MSG.ECHOCRLF
|
||
>SYSCALL printf
|
||
rts
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.INT.READ lda #1
|
||
>STA.G CMD.ArgIndex
|
||
|
||
tax
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
.1 jsr CMD.IsSwitch
|
||
bcs .4
|
||
cmp #'S'
|
||
bne .2
|
||
|
||
lda #$ff
|
||
>STA.G bREAD.S
|
||
|
||
bra .7
|
||
|
||
.2 cmp #'P'
|
||
bne .9
|
||
|
||
>INC.G CMD.ArgIndex
|
||
tax
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
pha
|
||
>PUSHBI 0
|
||
pla
|
||
>SYSCALL printf
|
||
bcs .99
|
||
bra .7
|
||
|
||
.4 >SYSCALL newstr
|
||
txa
|
||
>STA.G hVarName
|
||
|
||
.7 >INC.G CMD.ArgIndex
|
||
tax
|
||
jsr Cmd.GetArgX
|
||
bcc .1
|
||
|
||
>LDA.G hVarName
|
||
beq .9
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
Cmd.INT.SLEEP ldx #1
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
>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.MD ldx #1
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
>SYSCALL MKDir
|
||
rts
|
||
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.INT.REN ldx #2
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
>PUSHYA
|
||
ldx #1
|
||
jsr Cmd.GetArgX
|
||
|
||
>SYSCALL Rename
|
||
rts
|
||
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.INT.RD ldx #1
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
phy
|
||
pha
|
||
>PUSHEA.G CMD.Stat
|
||
pla
|
||
ply
|
||
>SYSCALL STAT
|
||
bcs .99
|
||
|
||
>LDA.G CMD.Stat+S.STAT.P.TYPE
|
||
cmp #S.FI.T.DIR
|
||
bne .9
|
||
|
||
ldx #1
|
||
jsr Cmd.GetArgX
|
||
>SYSCALL Remove
|
||
.99 rts
|
||
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.INT.IF >LDA.G CMD.STACK.PTR
|
||
cmp #CMD.STACK.PTR+CMD.STACK.MAX
|
||
beq .9
|
||
inc
|
||
sta (pData),y
|
||
|
||
ldx #1
|
||
jsr Cmd.GetArgX
|
||
beq .9
|
||
|
||
>PUSHYA
|
||
>LDYA L.CMD.IF.TOKEN1
|
||
jsr Lookup
|
||
|
||
bcs .9
|
||
|
||
cpx #4 [ or ![
|
||
bcs .9
|
||
dex
|
||
dex 1 or $ff
|
||
|
||
>LDA.G CMD.STACK.PTR
|
||
tay
|
||
txa
|
||
sta (pData),y true or false
|
||
|
||
ldx #2
|
||
jsr Cmd.GetArgX
|
||
beq .9
|
||
|
||
>PUSHYA
|
||
>LDYA L.CMD.IF.TOKEN2 -d -e -f ?
|
||
jsr Lookup
|
||
|
||
bcs .1
|
||
|
||
txa
|
||
>STA.G CMD.Operator
|
||
|
||
jsr CMD.IF.UNARY
|
||
bcs .9
|
||
|
||
>LDA.G CMD.STACK.PTR
|
||
tay
|
||
txa
|
||
eor (pData),y
|
||
sta (pData),y
|
||
|
||
ldx #4 go check ]
|
||
bra .8
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
|
||
.1 ldx #3
|
||
jsr Cmd.GetArgX
|
||
beq .9
|
||
|
||
>PUSHYA
|
||
>LDYA L.CMD.IF.TOKEN3 -eq -ne .... ?
|
||
jsr Lookup
|
||
bcs .9
|
||
txa
|
||
>STA.G CMD.Operator
|
||
|
||
jsr CMD.IF.BINARY
|
||
bcs .9
|
||
|
||
>LDA.G CMD.STACK.PTR
|
||
tay
|
||
txa
|
||
eor (pData),y
|
||
sta (pData),y
|
||
|
||
ldx #5 go check ]
|
||
|
||
.8 jsr Cmd.GetArgX
|
||
beq .9
|
||
|
||
>STYA ZPPTR1
|
||
|
||
lda (ZPPTR1)
|
||
cmp #']'
|
||
bne .9
|
||
|
||
ldy #1
|
||
lda (ZPPTR1),y
|
||
bne .9
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CMD.IF.UNARY ldx #3
|
||
jsr Cmd.GetArgX
|
||
bcs .9 we need one arg
|
||
|
||
>LDA.G CMD.Operator
|
||
tax
|
||
jmp (J.CMD.IF.TOKEN2,x)
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
|
||
CMD.IF.D jsr CMD.IF.DEF.7
|
||
bcs CMD.IF.DEF.9
|
||
>LDA.G CMD.Stat+S.STAT.P.TYPE
|
||
cmp #S.FI.T.DIR
|
||
bne CMD.IF.DEF.9
|
||
bra CMD.IF.DEF.8
|
||
|
||
CMD.IF.E jsr CMD.IF.DEF.7
|
||
bcs CMD.IF.DEF.9
|
||
bra CMD.IF.DEF.8 DIR or FILE exist
|
||
|
||
CMD.IF.F jsr CMD.IF.DEF.7
|
||
bcs CMD.IF.DEF.9
|
||
|
||
>LDA.G CMD.Stat+S.STAT.P.TYPE
|
||
cmp #S.FI.T.DIR
|
||
beq CMD.IF.DEF.9
|
||
bra CMD.IF.DEF.8
|
||
|
||
CMD.IF.DEF.7 >PUSHEA.G CMD.Stat
|
||
ldx #3
|
||
jsr Cmd.GetArgX
|
||
>SYSCALL STAT
|
||
rts
|
||
|
||
CMD.IF.DEF.8 ldx #$ff true
|
||
clc
|
||
rts
|
||
|
||
CMD.IF.DEF.9 ldx #0 false
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CMD.IF.BINARY ldx #2
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
ldx #4
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
>LDA.G CMD.Operator
|
||
beq .1 =
|
||
|
||
cmp #2 !=
|
||
bne CMD.IF.BINARY.NUM
|
||
lda #$ff
|
||
>STA.G CMD.Operator
|
||
|
||
.1 ldx #2
|
||
jsr Cmd.GetArgX
|
||
>PUSHYA
|
||
ldx #4
|
||
jsr Cmd.GetArgX
|
||
>SYSCALL strcmp
|
||
lsr CS if !=
|
||
>EOR.G CMD.Operator
|
||
sta (pData),y
|
||
tax
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
|
||
CMD.IF.BINARY.NUM
|
||
ldx #2
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
>SYSCALL AToL
|
||
bcs .9
|
||
|
||
>PULLL.G CMD.NumArg1
|
||
|
||
ldx #4
|
||
jsr Cmd.GetArgX
|
||
bcs .9
|
||
|
||
>SYSCALL AToL
|
||
bcs .9
|
||
|
||
>PULLL.G CMD.NumArg2
|
||
|
||
ldx #4
|
||
ldy #CMD.NumArg2+3
|
||
|
||
.1 lda (pData),y
|
||
pha
|
||
dey
|
||
dex
|
||
bne .1
|
||
|
||
ldx #4
|
||
ldy #CMD.NumArg1
|
||
|
||
sec
|
||
|
||
.2 pla
|
||
sbc (pData),y
|
||
sta (pData),y
|
||
iny
|
||
dex
|
||
bne .2
|
||
|
||
bcc .5 CC if Arg1 < Arg2
|
||
|
||
ldy #CMD.NumArg1
|
||
|
||
lda (pData),y
|
||
iny
|
||
ora (pData),y
|
||
iny
|
||
ora (pData),y
|
||
iny
|
||
ora (pData),y Z if Arg1 = Arg2
|
||
|
||
bne .4
|
||
|
||
.3 lda #%001 001 arg1 = arg2
|
||
bra .6
|
||
.4 lda #%010 010 arg1 > arg2
|
||
bra .6
|
||
.5 lda #%100 100 Arg1 < Arg2
|
||
|
||
.6 pha
|
||
|
||
>LDA.G CMD.Operator
|
||
lsr
|
||
tax
|
||
pla
|
||
eor CMD.IF.TOKEN3.BITS,x
|
||
bne .80
|
||
|
||
ldx #$ff true
|
||
clc
|
||
rts
|
||
|
||
.80 ldx #0 false
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.ELSE >LDA.G CMD.STACK.PTR
|
||
|
||
cmp #CMD.STACK.PTR
|
||
beq .9
|
||
|
||
tay
|
||
lda (pData),y
|
||
eor #$ff
|
||
sta (pData),y
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.FI >LDA.G CMD.STACK.PTR
|
||
cmp #CMD.STACK.PTR
|
||
beq .9
|
||
|
||
dec
|
||
>STA.G CMD.STACK.PTR
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.GetArgX >LDYA ZPArgVBuf
|
||
|
||
dex
|
||
bmi .8
|
||
|
||
>STYA ZPPtr1
|
||
|
||
.1 lda (ZPPtr1)
|
||
beq .9
|
||
|
||
.2 inc ZPPtr1
|
||
bne .3
|
||
inc ZPPtr1+1
|
||
.3 lda (ZPPtr1)
|
||
bne .2
|
||
|
||
inc ZPPtr1
|
||
bne .4
|
||
inc ZPPtr1+1
|
||
|
||
.4 lda (ZPPtr1)
|
||
beq .9
|
||
|
||
dex
|
||
bpl .1
|
||
|
||
>LDYA ZPPtr1
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
CMD.IsSwitch >STYA ZPPtr1
|
||
lda (ZPPtr1)
|
||
cmp #'-'
|
||
bne .9
|
||
|
||
ldy #1
|
||
lda (ZPPtr1),y
|
||
beq .9
|
||
|
||
iny
|
||
lda (ZPPtr1),y
|
||
bne .9
|
||
|
||
dey
|
||
lda (ZPPtr1),y
|
||
cmp #'a'
|
||
bcc .8
|
||
cmp #'z'+1
|
||
bcs .8
|
||
eor #$20
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 >LDYA ZPPtr1
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
|
||
LOAD /A2OSX.SRC/SBIN/SHELL.S
|
||
ASM
|