mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-23 07:35:19 +00:00
617 lines
9.5 KiB
Plaintext
617 lines
9.5 KiB
Plaintext
NEW
|
||
PREFIX /A2OSX.BUILD
|
||
AUTO 4,1
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
CMD.Init >LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
>STYA ZPCMDBuf
|
||
txa
|
||
>STA.G CMD.hCmdBuf
|
||
|
||
>LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
>STYA ZPArgVBuf
|
||
txa
|
||
>STA.G CMD.hArgVBuf
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
CMD.Quit >LDA.G CMD.hArgVBuf
|
||
beq .1
|
||
>SYSCALL FreeMem
|
||
|
||
.1 >LDA.G CMD.hCmdBuf
|
||
beq .9
|
||
>SYSCALL FreeMem
|
||
.9 rts
|
||
*--------------------------------------
|
||
* Input : ZPArgVBuf
|
||
*--------------------------------------
|
||
Cmd.Exec >LDA.G CMD.IntCmd
|
||
bmi .1
|
||
tax
|
||
jmp (J.CMD.INT,x)
|
||
|
||
.1 >PUSHB.G CMD.PSFlags
|
||
>LDYA ZPArgVBuf
|
||
>SYSCALL execv
|
||
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 >STYA ZPPTR1
|
||
|
||
lda (ZPPTR1)
|
||
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
|
||
|
||
* Print requested VAR
|
||
|
||
.3 >LDYA ZPPTR1
|
||
>SYSCALL GetEnv
|
||
bcs .8
|
||
|
||
>PUSHYA push value
|
||
>PUSHW ZPPTR1 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 ldx #1
|
||
jsr Cmd.GetArgX
|
||
bcs .71
|
||
|
||
>PUSHYA
|
||
ldy #S.PS.hStdOut
|
||
lda (pPs),y
|
||
>SYSCALL fputs
|
||
bcs .9
|
||
|
||
ldx #2
|
||
|
||
.1 phx
|
||
jsr Cmd.GetArgX
|
||
bcs .7
|
||
>PUSHYA
|
||
|
||
lda #C.SPACE
|
||
>SYSCALL putchar
|
||
|
||
ldy #S.PS.hStdOut
|
||
lda (pPs),y
|
||
>SYSCALL fputs
|
||
plx
|
||
inx
|
||
bcc .1
|
||
clc
|
||
rts
|
||
|
||
.7 plx
|
||
.71 >LDA.G bECHO.N
|
||
bmi .8
|
||
|
||
>PUSHBI 0
|
||
>LDYA L.MSG.ECHOCRLF
|
||
>SYSCALL printf
|
||
rts
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.INT.READ ldx #1
|
||
jsr Cmd.GetArgX
|
||
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 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.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.IF.PTR
|
||
cmp #CMD.IF.PTR+CMD.IF.STACK.MAX
|
||
beq .90
|
||
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.IF.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
|
||
|
||
jsr CMD.IF.UNARY
|
||
bcs .99
|
||
|
||
>LDA.G CMD.IF.PTR
|
||
tay
|
||
txa
|
||
eor #$ff
|
||
eor (pData),y
|
||
sta (pData),y
|
||
|
||
ldx #4
|
||
jsr Cmd.GetArgX
|
||
beq .9
|
||
|
||
>STYA ZPPTR1
|
||
|
||
lda (ZPPTR1)
|
||
cmp #']'
|
||
bne .9
|
||
|
||
ldy #1
|
||
lda (ZPPTR1),y
|
||
bne .9
|
||
.1
|
||
|
||
clc
|
||
.99 rts
|
||
|
||
.9 >LDA.G CMD.IF.PTR
|
||
.90 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
CMD.IF.UNARY jmp (J.CMD.IF.TOKEN2,x)
|
||
|
||
CMD.IF.D
|
||
CMD.IF.E
|
||
CMD.IF.F
|
||
ldx #1 true
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.INT.ELSE >LDA.G CMD.IF.PTR
|
||
cmp #CMD.IF.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.IF.PTR
|
||
cmp #CMD.IF.PTR
|
||
beq .9
|
||
|
||
dec
|
||
>STA.G CMD.IF.PTR
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.GetArgX >LDYA ZPArgVBuf
|
||
|
||
dex
|
||
bmi .8
|
||
|
||
>STYA ZPPtr1
|
||
|
||
.1 jsr Cmd.NextArgPtr1
|
||
bcs .9
|
||
dex
|
||
bpl .1
|
||
|
||
>LDYA ZPPtr1
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.NextArgPtr1 lda (ZPPtr1)
|
||
beq .9
|
||
|
||
.1 inc ZPPtr1
|
||
bne .2
|
||
inc ZPPtr1+1
|
||
.2 lda (ZPPtr1)
|
||
bne .1
|
||
|
||
inc ZPPtr1
|
||
bne .3
|
||
inc ZPPtr1+1
|
||
|
||
.3 lda (ZPPtr1)
|
||
beq .9
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 sec
|
||
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
|