mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-27 04:49:20 +00:00
642 lines
11 KiB
Plaintext
642 lines
11 KiB
Plaintext
NEW
|
||
PREFIX /A2OSX.BUILD
|
||
AUTO 4,1
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
CL.PrintPrompt >LDYA L.ENV.PS1
|
||
>SYSCALL GetEnv
|
||
bcs .1
|
||
|
||
>SYSCALL ExpandStr
|
||
bcs .9
|
||
|
||
phx
|
||
pha
|
||
>PUSHBI 0
|
||
pla
|
||
>SYSCALL printf
|
||
pla
|
||
>SYSCALL FreeMem
|
||
|
||
.1 >PUSHBI 0
|
||
>LDYA L.MSG.PROMPT
|
||
>SYSCALL printf
|
||
.9 rts
|
||
*--------------------------------------
|
||
CL.CHARIN tax
|
||
|
||
>LDA.G bEscMode
|
||
beq .13
|
||
|
||
cpx #'['
|
||
beq .9
|
||
|
||
lda #0
|
||
sta (pData),y Y=bEscMode
|
||
txa
|
||
|
||
ldx #EscChars.Cnt-1
|
||
|
||
.17 cmp EscChars,x
|
||
beq .18
|
||
dex
|
||
bpl .17
|
||
clc
|
||
rts
|
||
|
||
.18 txa
|
||
asl
|
||
tax
|
||
jmp (J.ESC,x)
|
||
*--------------------------------------
|
||
.13 cpx #$20
|
||
bcc CL.CHARIN.CTRL
|
||
|
||
.1 cpx #$7f
|
||
bne .2
|
||
jmp CL.DEL
|
||
|
||
.2 jmp CL.Insert
|
||
|
||
.9 clc
|
||
rts
|
||
*--------------------------------------
|
||
CL.CHARIN.CTRL cpx #C.CR
|
||
bne .10
|
||
|
||
>PUSHBI 0
|
||
>LDYA L.MSG.ECHOCRLF
|
||
>SYSCALL printf
|
||
|
||
>LDA.G CL.Ptr
|
||
tay
|
||
lda #0
|
||
sta (ZPCMDBuf),y
|
||
tya
|
||
>STA.G CL.Len
|
||
|
||
lda #$ff
|
||
>STA.G CL.bExec
|
||
clc
|
||
rts
|
||
|
||
.10 cpx #C.ESC
|
||
bne .11
|
||
|
||
lda #$ff
|
||
>STA.G bEscMode
|
||
clc
|
||
rts
|
||
|
||
.11 cpx #3 Ctrl-C
|
||
bne .12
|
||
|
||
jmp CL.CLR
|
||
|
||
.12 cpx #24 Ctrl-X
|
||
bne .13
|
||
|
||
jmp CL.SUPPR
|
||
|
||
.13 clc
|
||
rts
|
||
*--------------------------------------
|
||
CL.Insert >LDA.G CL.Len
|
||
cmp #CmdLine.MAX
|
||
beq .9 Buffer full, discard...
|
||
|
||
inc
|
||
sta (pData),y
|
||
|
||
pha
|
||
|
||
.1 ply
|
||
dey
|
||
lda (ZPCMDBuf),y Move from Ptr To end of buffer forward...
|
||
iny
|
||
sta (ZPCMDBuf),y
|
||
dey
|
||
phy
|
||
tya
|
||
>CMP.G CL.Ptr
|
||
bne .1
|
||
|
||
ply Y=CL.Ptr
|
||
|
||
* >LDA.G CL.Ptr
|
||
|
||
txa
|
||
sta (ZPCMDBuf),y
|
||
|
||
>LDA.G bSecureRead
|
||
bpl .2
|
||
ldx #'*'
|
||
|
||
.2 txa
|
||
>SYSCALL PutChar
|
||
|
||
>INC.G CL.Ptr
|
||
|
||
jmp CL.PrintEOL
|
||
|
||
.9 clc
|
||
rts
|
||
*--------------------------------------
|
||
CL.CLR ldy #0
|
||
|
||
.1 lda (ZPCMDBuf),y
|
||
beq CL.RESET
|
||
|
||
.2 lda #$7F
|
||
|
||
sta (ZPCMDBuf),y
|
||
iny
|
||
lda (ZPCMDBuf),y
|
||
bne .2
|
||
|
||
jsr CL.PrintCmdBuf
|
||
*--------------------------------------
|
||
CL.RESET lda #0
|
||
sta (ZPCMDBuf)
|
||
>STA.G CL.bExec
|
||
>STA.G CL.Ptr
|
||
>STA.G CL.Len
|
||
rts
|
||
*--------------------------------------
|
||
CL.BS >LDA.G CL.Ptr
|
||
beq .9
|
||
|
||
dec
|
||
sta (pData),y
|
||
|
||
lda #C.BS
|
||
>SYSCALL PutChar
|
||
.9 rts
|
||
*--------------------------------------
|
||
CL.NAK >LDA.G CL.Ptr
|
||
>CMP.G CL.Len
|
||
beq .9
|
||
|
||
inc
|
||
>STA.G CL.Ptr
|
||
|
||
lda #C.FS
|
||
>SYSCALL PutChar
|
||
.9 rts
|
||
*--------------------------------------
|
||
* Erase char UNDER cursor
|
||
*--------------------------------------
|
||
CL.SUPPR >LDA.G CL.Len
|
||
beq CL.PrintEOL.8
|
||
|
||
>LDA.G CL.Ptr
|
||
bra CL.DEL.1
|
||
*--------------------------------------
|
||
* Erase char BEFORE cursor
|
||
*--------------------------------------
|
||
CL.DEL >LDA.G CL.Len
|
||
beq CL.PrintEOL.8
|
||
|
||
>LDA.G CL.Ptr
|
||
beq CL.PrintEOL.8
|
||
|
||
lda #C.BS
|
||
>SYSCALL PutChar
|
||
|
||
>DEC.G CL.Ptr
|
||
|
||
CL.DEL.1 pha
|
||
|
||
.1 ply
|
||
iny
|
||
lda (ZPCMDBuf),y
|
||
dey
|
||
sta (ZPCMDBuf),y
|
||
iny
|
||
phy
|
||
tya
|
||
|
||
>CMP.G CL.Len
|
||
bne .1
|
||
|
||
pla
|
||
|
||
>DEC.G CL.Len
|
||
*--------------------------------------
|
||
CL.PrintEOL >LDA.G CL.Ptr
|
||
|
||
.1 >CMP.G CL.Len
|
||
beq .2
|
||
|
||
pha
|
||
tay
|
||
lda (ZPCMDBuf),y
|
||
>SYSCALL PutChar
|
||
pla
|
||
inc
|
||
bra .1
|
||
|
||
.2 lda #' '
|
||
>SYSCALL PutChar
|
||
|
||
>LDA.G CL.Ptr
|
||
|
||
.3 >CMP.G CL.Len
|
||
beq .4
|
||
|
||
pha
|
||
|
||
lda #C.BS
|
||
>SYSCALL PutChar
|
||
pla
|
||
inc
|
||
bra .3
|
||
|
||
.4 lda #C.BS
|
||
>SYSCALL PutChar
|
||
|
||
CL.PrintEOL.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
CL.PrintCmdBuf >LDYA ZPCMDBuf
|
||
>SYSCALL printf
|
||
rts
|
||
*--------------------------------------
|
||
CL.GetLine lda (ZPFileBufPtr)
|
||
beq .9
|
||
|
||
ldy #0
|
||
|
||
.1 lda (ZPFileBufPtr),y
|
||
beq .7
|
||
|
||
cmp #C.CR
|
||
beq .6
|
||
|
||
* cmp #';'
|
||
* beq .6
|
||
|
||
sta (ZPCMDBuf),y
|
||
iny
|
||
cpy #CmdLine.MAX
|
||
bne .1
|
||
|
||
lda #E.SYN Line Too long !!!
|
||
* sec
|
||
rts
|
||
|
||
.6 sec skip CR or ;
|
||
.HS 90 BCC
|
||
|
||
.7 clc
|
||
|
||
tya
|
||
adc ZPFileBufPtr
|
||
sta ZPFileBufPtr
|
||
bcc .8
|
||
inc ZPFileBufPtr+1
|
||
|
||
.8 lda #0
|
||
sta (ZPCMDBuf),y
|
||
|
||
tya
|
||
>STA.G CL.Len
|
||
lda #$ff
|
||
>STA.G CL.bExec
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #C.EOF
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
CL.Trace >LDA.G bSET.X
|
||
beq .8
|
||
|
||
>PUSHW ZPCMDBuf
|
||
>PUSHBI 2
|
||
>LDYA L.MSG.TRACE
|
||
>SYSCALL printf
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
* in:
|
||
* ZPCMDBuf : CString command line
|
||
* out:
|
||
* ZPArgVBuf :
|
||
* /path/excmd\0 arg1\0 arg2\0 ... \0
|
||
* - or -
|
||
* intcmd\0 arg1\0 arg2\0 ... \0
|
||
*--------------------------------------
|
||
CL.Parse >STZ.G CMD.IntCmd
|
||
|
||
lda #S.PS.F.HOLD+S.PS.F.DUPENV
|
||
>STA.G CMD.PSFlags
|
||
|
||
>PUSHW ZPCMDBuf
|
||
>LDYA ZPCMDBuf
|
||
|
||
>SYSCALL Args2ArgV
|
||
|
||
lda #0
|
||
sta (ZPArgVBuf)
|
||
|
||
lda (ZPCMDBuf)
|
||
beq .8
|
||
|
||
.1 cmp #'#' comment ?
|
||
beq .8 yes, ignore remaining
|
||
|
||
>LDA.G CMD.IntCmd
|
||
bne .6 we already have Cmd, go check args
|
||
|
||
ldy #2
|
||
lda (ZPCMDBuf),y only one char ?
|
||
bne .2
|
||
|
||
dey
|
||
lda (ZPCMDBuf),y
|
||
cmp #'.' leading dot ?
|
||
bne .2
|
||
|
||
>LDA.G CMD.PSFlags yes, child process will run in same ENV
|
||
and #$ff^S.PS.F.DUPENV
|
||
sta (pData),y
|
||
bra .7 and skip this token
|
||
|
||
.2 jsr CL.CheckCmd
|
||
bcc .7 success, skip token, already added by CheckCmd
|
||
|
||
rts
|
||
|
||
.6 jsr CL.CheckIO
|
||
bcc .7
|
||
tay
|
||
bne .9
|
||
|
||
jsr CL.AddCmdBufTokenToArgV
|
||
bcs .9
|
||
|
||
.7 jsr CL.NextCmdBufToken
|
||
lda (ZPCMDBuf)
|
||
bne .1
|
||
|
||
.8 clc
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
* ZPCMDBuf-> argv[] (formatted & not empty)
|
||
*--------------------------------------
|
||
CL.CheckCmd ldy #$ff
|
||
|
||
.1 iny
|
||
lda (ZPCMDBuf),y
|
||
beq .2
|
||
cmp #'/'
|
||
bne .1
|
||
|
||
>LDYA ZPCMDBuf found /, some path specified, External, no search
|
||
>SYSCALL realpath
|
||
bcs .9
|
||
|
||
txa
|
||
>STA.G CMD.hCmdLine
|
||
bra .6 go check type...
|
||
|
||
.2 >PUSHW ZPCMDBuf
|
||
>LDYA L.CMD.INT
|
||
jsr Lookup no / found, search internal...
|
||
bcs .4 not internal, search PATH
|
||
|
||
phx
|
||
plx
|
||
bne .3
|
||
|
||
>LDA.G CMD.PSFlags if STARTPROC, skip keyword...
|
||
and #$ff^S.PS.F.HOLD
|
||
sta (pData),y ...and toggle S.PS.F.HOLD flag
|
||
clc
|
||
.9 rts
|
||
|
||
.3 jsr CL.AddYAToArgV X unmodified
|
||
bcs .9
|
||
|
||
txa
|
||
>STA.G CMD.IntCmd
|
||
|
||
clc
|
||
rts
|
||
|
||
.4 >LDYAI 256 Get a buffer for found path
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
|
||
txa
|
||
>STA.G CMD.hCmdLine
|
||
|
||
>LDYA L.ENV.PATH push ENVNAME=PATH for search
|
||
>SYSCALL GetEnv get value for ENV=PATH
|
||
bcs .5 no PATH, try workdir
|
||
|
||
jsr CL.SearchExt
|
||
bcc .6 found in PATH, go check Type
|
||
|
||
.5 ldy #S.PS.hPREFIX not found, try in CD
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr
|
||
jsr CL.SearchExt
|
||
bcs CL.CheckCmd.90
|
||
|
||
.6 >PUSHEA.G CMD.Stat
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL GetMemPtr
|
||
>SYSCALL STAT
|
||
bcs CL.CheckCmd.90
|
||
|
||
lda #$ff
|
||
>STA.G CMD.IntCmd
|
||
|
||
ldy #CMD.Stat+S.STAT.P.TYPE
|
||
lda (pData),y
|
||
cmp #S.FI.T.TXT
|
||
beq CL.CheckCmd.TXT
|
||
cmp #S.FI.T.BIN
|
||
beq CL.CheckCmd.BIN
|
||
cmp #S.FI.T.SYS
|
||
beq CL.CheckCmd.SYS
|
||
|
||
lda #E.SYN
|
||
sec
|
||
|
||
CL.CheckCmd.90 php
|
||
pha
|
||
>LDA.G CMD.hCmdLine
|
||
>SYSCALL FreeMem
|
||
pla
|
||
|
||
plp
|
||
CL.CheckCmd.RTS
|
||
rts
|
||
*--------------------------------------
|
||
* TXT : add "/PATH/SHELL" "/PATH/CMD"
|
||
*--------------------------------------
|
||
CL.CheckCmd.TXT lda #0
|
||
>SYSCALL ArgV
|
||
jsr CL.AddYAToArgV
|
||
bcs CL.CheckCmd.90
|
||
*--------------------------------------
|
||
* BIN : add "/PATH/CMD"
|
||
*--------------------------------------
|
||
CL.CheckCmd.BIN >LDA.G CMD.hCmdLine
|
||
>SYSCALL GetMemPtr
|
||
jsr CL.AddYAToArgV
|
||
|
||
bra CL.CheckCmd.90
|
||
*--------------------------------------
|
||
CL.CheckCmd.SYS bra *
|
||
*--------------------------------------
|
||
CL.SearchExt 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
|
||
*--------------------------------------
|
||
CL.CheckIO >PUSHW ZPCMDBuf
|
||
>LDYA L.CL.IO
|
||
jsr Lookup
|
||
bcs .9 not a IO token...should be an arg....
|
||
phx
|
||
|
||
jsr CL.NextCmdBufToken skip this IO token
|
||
|
||
plx
|
||
jmp (J.CL.IO,x)
|
||
|
||
.9 lda #0
|
||
rts
|
||
*--------------------------------------
|
||
CL.IO.AMP >LDA.G CMD.PSFlags
|
||
and #$ff^S.PS.F.HOLD
|
||
sta (pData),y
|
||
clc
|
||
rts
|
||
|
||
CL.IO.PIPE
|
||
clc
|
||
rts
|
||
|
||
CL.IO.IN lda #O.RDONLY+O.TEXT
|
||
jsr CL.IO.Open
|
||
bcs .9
|
||
jsr IO.Set.In
|
||
|
||
jsr CL.NextCmdBufToken skip arg
|
||
clc
|
||
.9 rts
|
||
|
||
CL.IO.OUTA
|
||
CL.IO.1OUTA lda #O.WRONLY+O.APPEND+O.CREATE+O.TEXT
|
||
bra CL.IO.OUT.1
|
||
CL.IO.OUT
|
||
CL.IO.1OUT lda #O.WRONLY+O.TRUNC+O.CREATE+O.TEXT
|
||
|
||
CL.IO.OUT.1 jsr CL.IO.Open
|
||
bcs .9
|
||
jsr IO.Set.Out
|
||
|
||
jsr CL.NextCmdBufToken skip arg
|
||
clc
|
||
.9 rts
|
||
|
||
CL.IO.2OUTA lda #O.WRONLY+O.APPEND+O.CREATE+O.TEXT
|
||
bra CL.IO.2OUT.1
|
||
CL.IO.2OUT lda #O.WRONLY+O.TRUNC+O.CREATE+O.TEXT
|
||
|
||
CL.IO.2OUT.1 jsr CL.IO.Open
|
||
bcs .9
|
||
jsr IO.Set.Err
|
||
|
||
jsr CL.NextCmdBufToken skip arg
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
CL.IO.Open pha
|
||
lda (ZPCMDBuf)
|
||
beq .9 no arg left....
|
||
|
||
>PUSHWI 0 Aux type
|
||
>PUSHBI S.FI.T.TXT ftype
|
||
pla
|
||
>PUSHA flags
|
||
>LDYA ZPCMDBuf
|
||
>SYSCALL fopen
|
||
rts
|
||
|
||
.9 pla
|
||
lda #E.SYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
CL.NextCmdBufToken
|
||
lda (ZPCMDBuf)
|
||
inc ZPCMDBuf
|
||
bne .1
|
||
inc ZPCMDBuf+1
|
||
.1 tax
|
||
bne CL.NextCmdBufToken
|
||
rts
|
||
*--------------------------------------
|
||
CL.AddCmdBufTokenToArgV
|
||
>LDYA ZPCmdBuf
|
||
CL.AddYAToArgV >STYA ZPPtr1
|
||
|
||
>LDYA ZPArgVBuf
|
||
>STYA ZPPtr2
|
||
|
||
.1 lda (ZPPtr2) scan to end of argV
|
||
beq .6
|
||
|
||
.2 inc ZPPtr2
|
||
bne .3
|
||
inc ZPPtr2+1
|
||
.3 lda (ZPPtr2)
|
||
bne .2
|
||
|
||
inc ZPPtr2
|
||
bne .4
|
||
inc ZPPtr2+1
|
||
.4 lda (ZPPtr2)
|
||
bne .2
|
||
|
||
.6 ldy #$ff
|
||
|
||
.7 iny
|
||
* beq .9
|
||
lda (ZPPtr1),y
|
||
sta (ZPPtr2),y
|
||
bne .7 including str ending \0
|
||
|
||
iny
|
||
* beq .9
|
||
sta (ZPPtr2),y arg[] ending \0
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.BUF
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SBIN/SHELL.S.CL
|
||
LOAD /A2OSX.SRC/SBIN/SHELL.S
|
||
ASM
|