mirror of
https://github.com/A2osX/A2osX.git
synced 2024-08-14 13:29:02 +00:00
631 lines
11 KiB
Plaintext
631 lines
11 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* Remove extra SPACE & comment
|
||
*--------------------------------------
|
||
Cmd.Normalize >LDYA ZPBufBase
|
||
>STYA ZPPtr1
|
||
|
||
lda (ZPBufBase) empty line...quit
|
||
beq .9
|
||
|
||
ldy #0
|
||
|
||
.1 jsr Cmd.Normalize.Next
|
||
beq .8 no more char, exit
|
||
|
||
cmp #' ' skip leading spaces
|
||
beq .1
|
||
|
||
cmp #'#' Comment ?
|
||
beq .8 ignore remaining chars
|
||
|
||
.3 sta (ZPBufBase),y add char to buffer
|
||
iny
|
||
|
||
jsr Cmd.Normalize.Next
|
||
beq .8
|
||
|
||
cmp #' '
|
||
bne .3
|
||
|
||
sta (ZPBufBase),y add One SPACE to buffer
|
||
iny
|
||
|
||
.5 jsr Cmd.Normalize.Next
|
||
beq .8
|
||
|
||
cmp #' '
|
||
beq .5 skip additional spaces
|
||
bne .3 no more space, add next word...
|
||
|
||
.8 lda #0
|
||
sta (ZPBufBase),y
|
||
|
||
.9 rts
|
||
|
||
Cmd.Normalize.Next
|
||
lda (ZPPtr1)
|
||
beq .8
|
||
|
||
inc ZPPtr1
|
||
bne .8
|
||
inc ZPPtr1+1 never Z
|
||
.8 rts
|
||
*--------------------------------------
|
||
* Y,A -> Command line (formatted & not empty)
|
||
*--------------------------------------
|
||
Cmd.ExecYA stz bStartProc
|
||
|
||
Cmd.ExecYA.1 >SYSCALL ExpandStr.YA
|
||
>STYA ZPPtr1
|
||
>STYA ZPPtr2
|
||
stx Cmd.ExecYA.Exit.1+1
|
||
|
||
ldy #0 CMD len
|
||
|
||
lda (ZPPtr2)
|
||
tax ARGS len=Total Len
|
||
|
||
.1 inc ZPPtr2 Next Cmd Char
|
||
bne .2
|
||
inc ZPPtr2+1
|
||
|
||
.2 lda (ZPPtr2)
|
||
cmp #" " we reached blank between CMD ARGS
|
||
beq .3
|
||
|
||
iny CMD+1
|
||
dex Total=0
|
||
bne .1
|
||
|
||
.3 tya
|
||
sta (ZPPtr1) Cut CMD
|
||
txa
|
||
sta (ZPPtr2) Cut ARGS
|
||
|
||
>LDYA L.INTCMDS
|
||
>STYA ZPPtr3
|
||
|
||
ldx #0
|
||
|
||
.4 lda (ZPPtr3)
|
||
beq Cmd.Exec.EXT Ending 0, must be an external Cmd....
|
||
|
||
cmp (ZPPtr1) Same Len ?
|
||
bne .8
|
||
|
||
tay
|
||
|
||
.5 lda (ZPPtr1),y
|
||
|
||
cmp #'a' To Uppercase
|
||
bcc .6
|
||
cmp #'z'+1
|
||
bcs .6
|
||
eor #$20
|
||
|
||
.6 cmp (ZPPtr3),y
|
||
bne .8
|
||
dey
|
||
bne .6
|
||
|
||
jsr Cmd.Exec.INT Found an internal Cmd...
|
||
|
||
bcs .7
|
||
|
||
lda #0
|
||
|
||
.7 ldy #S.PS.RC
|
||
sta (pPS),y
|
||
bra Cmd.ExecYA.Exit
|
||
|
||
.8 inx
|
||
inx
|
||
|
||
lda ZPPtr3
|
||
sec
|
||
adc (ZPPtr3)
|
||
sta ZPPtr3
|
||
bcc .4
|
||
inc ZPPtr3+1
|
||
bra .4
|
||
*--------------------------------------
|
||
Cmd.ExecYA.Exit php
|
||
pha
|
||
Cmd.ExecYA.Exit.1
|
||
lda #$ff
|
||
>SYSCALL FreeMem.A
|
||
pla
|
||
plp
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.Exec.INT jmp (J.INTCMDS,x)
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT ldy #1
|
||
lda (ZPPtr1),y
|
||
cmp #'/' Command line is already full path, no search
|
||
bne .10
|
||
jmp .3
|
||
|
||
.10 >LDYA L.ENV.PATH push ENVNAME=PATH for search
|
||
>SYSCALL GetEnv.YA get value for ENV=PATH
|
||
bcs .1 No PATH, try in CD
|
||
|
||
>PUSHYA push search list
|
||
|
||
>PUSHW ZPPtr1 push filename
|
||
>PUSHWI UsrBuf256
|
||
>PUSHW L.STAT
|
||
>SYSCALL FileSearch
|
||
bcc .2
|
||
|
||
.1 ldy #S.PS.hPREFIX not found, try in CD
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr.A
|
||
>PUSHYA push search list
|
||
>PUSHW ZPPtr1
|
||
>PUSHWI UsrBuf256
|
||
>PUSHW L.STAT
|
||
>SYSCALL FileSearch
|
||
bcs .99
|
||
|
||
.2 phx save X=hMem, Y,A = Filename
|
||
>PUSHYA
|
||
|
||
>PUSHW L.CMD replace CMD in TmpBuffer with full path
|
||
>SYSCALL StrCpy
|
||
pla
|
||
>SYSCALL FreeMem.A Discard this string...
|
||
|
||
.3 stz UsrBuf256 reset UsrBuf256 for final CMDLINE
|
||
|
||
>PUSHW L.STAT
|
||
>PUSHW L.CMD
|
||
>SYSCALL STAT
|
||
bcs .99
|
||
|
||
lda STAT+S.STAT.P.TYPE
|
||
cmp #$04 TXT File ?
|
||
beq Cmd.Exec.EXT.TXT
|
||
cmp #$06 BIN File ?
|
||
beq Cmd.Exec.EXT.BIN
|
||
cmp #$ff SYS File ?
|
||
bne .9
|
||
|
||
bra *
|
||
|
||
.9 lda #SYSMGR.ERRSYN
|
||
sec
|
||
.99 jmp Cmd.ExecYA.Exit
|
||
*--------------------------------------
|
||
* TXT : Launch "/PATH/SHELL /PATH/CMD ARGS"
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT.TXT
|
||
lda #0 Get arg[0] = /PATH/SHELL
|
||
>SYSCALL GetArg.A
|
||
>PUSHYA
|
||
>PUSHWI UsrBuf256
|
||
>SYSCALL StrCpy
|
||
|
||
inc UsrBuf256 Add a space....
|
||
ldy UsrBuf256
|
||
lda #' '
|
||
sta UsrBuf256,y
|
||
*--------------------------------------
|
||
* BIN : Launch "/PATH/CMD ARGS"
|
||
*--------------------------------------
|
||
Cmd.Exec.EXT.BIN
|
||
>PUSHW L.CMD
|
||
>PUSHWI UsrBuf256
|
||
>SYSCALL StrCat
|
||
|
||
lda ARGS
|
||
beq .1
|
||
|
||
inc UsrBuf256 Add a space....
|
||
ldy UsrBuf256
|
||
lda #' '
|
||
sta UsrBuf256,y
|
||
|
||
>PUSHW L.ARGS
|
||
>PUSHWI UsrBuf256
|
||
>SYSCALL StrCat
|
||
|
||
.1 >LDYAI UsrBuf256
|
||
bit bStartProc
|
||
bmi .2 startproc
|
||
|
||
>SYSCALL ExecProcessNewEnvYA
|
||
jmp Cmd.ExecYA.Exit
|
||
|
||
.2 >SYSCALL CreateProcessYA
|
||
jmp Cmd.ExecYA.Exit
|
||
*--------------------------------------
|
||
* Internal Commands
|
||
*--------------------------------------
|
||
Cmd.Exec.CD lda ARGS
|
||
bne Cmd.Exec.CD1
|
||
|
||
Cmd.Exec.PWD ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr.A
|
||
>PUSHYA
|
||
>LDYA L.MSG.PSTRCR
|
||
>SYSCALL PrintF.YA
|
||
rts
|
||
|
||
Cmd.Exec.CD1 stz UsrBuf256
|
||
lda ARGS+1
|
||
cmp #'/' Full Path?
|
||
beq .1
|
||
|
||
ldy #S.PS.hPREFIX no, init target prefix with actual prefix
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr.A
|
||
>PUSHYA
|
||
>PUSHWI UsrBuf256
|
||
>SYSCALL StrCpy
|
||
|
||
.1 >PUSHW L.ARGS Append ARG to buffer
|
||
>PUSHWI UsrBuf256
|
||
>SYSCALL StrCat
|
||
|
||
lda #'/'
|
||
ldx UsrBuf256
|
||
cmp UsrBuf256,x Ending '/' ?
|
||
beq .2
|
||
|
||
sta UsrBuf256+1,x no, add one...
|
||
inc UsrBuf256
|
||
|
||
.2 ldx #0 path is something like : /dir1/../dir2/
|
||
|
||
.3 ldy #0 reset char counter
|
||
|
||
.4 cpx UsrBuf256
|
||
beq .8
|
||
|
||
inx
|
||
lda UsrBuf256,x
|
||
cmp #'/'
|
||
beq .5
|
||
iny char=char+1!!!
|
||
bra .4
|
||
|
||
.5 tya any char count?
|
||
beq .4 no, start counting...
|
||
|
||
cpy #2 do we have /xx/?
|
||
bne .3 no, skip this token
|
||
|
||
lda #'.'
|
||
cmp UsrBuf256-1,x /yy/x./ ?
|
||
bne .3
|
||
cmp UsrBuf256-2,x /yy/../ ?
|
||
bne .3
|
||
cpx #4 /../ ?
|
||
beq Cmd.Exec.ERRSYN illegal
|
||
|
||
txa
|
||
tay save end of /../
|
||
sec
|
||
sbc #3 remove ../
|
||
tax
|
||
|
||
.6 dex
|
||
lda UsrBuf256,x Found beginning of dir before /../
|
||
cmp #'/'
|
||
bne .6
|
||
|
||
.7 lda UsrBuf256,y strip dir/../
|
||
sta UsrBuf256,x
|
||
cpy UsrBuf256
|
||
beq .71
|
||
iny
|
||
inx
|
||
bra .7
|
||
|
||
.71 stx UsrBuf256
|
||
|
||
bra .2 Start over...
|
||
|
||
.8 cpx #1
|
||
beq .80 we have '/' go change prefix
|
||
|
||
>PUSHW L.STAT
|
||
>PUSHWI UsrBuf256
|
||
>SYSCALL STAT
|
||
bcs .9
|
||
|
||
lda STAT+S.STAT.P.TYPE
|
||
cmp #$0F Directory ?
|
||
bne Cmd.Exec.ERRSYN
|
||
|
||
.80 >LDYAI UsrBuf256
|
||
>SYSCALL NewStr.YA
|
||
bcs .9
|
||
phx
|
||
|
||
ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL FreeMem.A
|
||
|
||
pla
|
||
|
||
ldy #S.PS.hPREFIX
|
||
sta (pPs),y
|
||
jsr SetPWD
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
Cmd.Exec.ERRSYN lda #SYSMGR.ERRSYN
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.Exec.STARTPROC
|
||
lda ARGS
|
||
beq Cmd.Exec.ERRSYN
|
||
sec
|
||
ror bStartProc
|
||
|
||
>LDYA L.ARGS
|
||
jmp Cmd.ExecYA.1
|
||
*--------------------------------------
|
||
Cmd.Exec.SET lda ARGS
|
||
bne Cmd.Exec.SETVAR
|
||
|
||
ldy #S.PS.hENV
|
||
lda (pPs),y
|
||
>SYSCALL GetMemPtr.A
|
||
>STYA ZPPTR1
|
||
|
||
* No arg, print all ENV
|
||
|
||
.1 lda (ZPPTR1)
|
||
beq .8 Ending 0 ?
|
||
|
||
lda ZPPTR1 get next for value
|
||
sec
|
||
adc (ZPPTR1) Add len+1 to PTR
|
||
sta ZPPTR2
|
||
lda ZPPTR1+1
|
||
adc #0
|
||
sta ZPPTR2+1
|
||
|
||
lda (ZPPTR2) just in case...
|
||
beq .8
|
||
|
||
>PUSHW ZPPTR2 Push value
|
||
>PUSHW ZPPTR1 Push name
|
||
|
||
>LDYA L.MSG.PRINTENV
|
||
>SYSCALL PrintF.YA
|
||
bcs .9
|
||
|
||
lda ZPPTR2
|
||
sec
|
||
adc (ZPPTR2) Add len+1 to PTR
|
||
sta ZPPTR1
|
||
lda ZPPTR2+1
|
||
adc #0
|
||
sta ZPPTR1+1
|
||
bra .1
|
||
|
||
.8 clc
|
||
.9 rts
|
||
|
||
Cmd.Exec.SETVAR tax
|
||
lda ARGS,x
|
||
cmp #'=' ARGS ends with =, UnsetEnv
|
||
beq .2
|
||
|
||
.1 dex
|
||
beq .3 no =, GetEnv
|
||
|
||
lda ARGS,x
|
||
cmp #'=' ARGS contains =, PutEnv
|
||
bne .1
|
||
|
||
cpx #1 string is '=value' ?
|
||
beq .99 syntax error
|
||
|
||
>LDYA L.ARGS String is VAR=VALUE...
|
||
>SYSCALL PutEnv.YA
|
||
rts
|
||
|
||
.2 dec ARGS String is "VAR=", Remove endig '='
|
||
>LDYA L.ARGS String is "VAR"...
|
||
>SYSCALL UnsetEnv.YA
|
||
rts
|
||
|
||
* Print requested VAR
|
||
|
||
.3 >LDYA L.ARGS
|
||
>SYSCALL GetEnv.YA
|
||
bcs .8
|
||
|
||
>PUSHYA push value
|
||
>PUSHW L.ARGS push name
|
||
>LDYA L.MSG.PRINTENV
|
||
>SYSCALL PrintF.YA
|
||
|
||
.8 clc
|
||
.9 rts
|
||
|
||
.99 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.Exec.DATE sec
|
||
.HS 90 bcc
|
||
|
||
Cmd.Exec.TIME clc
|
||
php
|
||
>LDYA L.TIME
|
||
>SYSCALL TimeYA
|
||
|
||
>PUSHWI UsrBuf256
|
||
plp
|
||
bcc .1
|
||
>PUSHW L.FMT.DATE
|
||
bra .2
|
||
.1 >PUSHW L.FMT.TIME
|
||
|
||
.2 >PUSHW L.TIME
|
||
>SYSCALL StrFTime
|
||
|
||
>LDYAI UsrBuf256
|
||
>SYSCALL PrintF.YA
|
||
bcs Cmd.Exec.ECHO.RTS
|
||
bra Cmd.Exec.ECHO.CR
|
||
*--------------------------------------
|
||
Cmd.Exec.ECHO lda ARGS
|
||
beq Cmd.Exec.ECHO.CR
|
||
|
||
>PUSHW L.ARGS
|
||
>LDYA L.MSG.PSTRCR
|
||
>SYSCALL PrintF.YA
|
||
rts
|
||
|
||
Cmd.Exec.ECHO.CR
|
||
lda #13
|
||
>SYSCALL PutChar.A
|
||
bcs Cmd.Exec.ECHO.RTS
|
||
|
||
lda #10
|
||
>SYSCALL PutChar.A
|
||
|
||
Cmd.Exec.ECHO.RTS
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.Exec.READ lda ARGS
|
||
beq .9
|
||
|
||
lda #0
|
||
ldy #bSecureRead
|
||
sta (pData),y
|
||
|
||
lda pData
|
||
clc
|
||
adc #VarBuffer
|
||
sta ZPPTR1
|
||
lda pData+1
|
||
adc #0
|
||
sta ZPPTR1+1
|
||
|
||
ldx #0
|
||
|
||
.1 cpx ARGS
|
||
beq .8
|
||
inx
|
||
lda ARGS,x
|
||
cmp #' '
|
||
beq .1
|
||
cmp #'-'
|
||
bne .7
|
||
|
||
cpx ARGS
|
||
beq .9
|
||
inx
|
||
lda ARGS,x
|
||
cmp #'S'
|
||
bne .2
|
||
|
||
ldy #bSecureRead
|
||
lda #$80
|
||
sta (pData),y
|
||
bra .1
|
||
|
||
.2 cmp #'P'
|
||
bne .9
|
||
|
||
cpx ARGS
|
||
beq .9
|
||
inx
|
||
lda ARGS,x
|
||
cmp #' '
|
||
bne .9
|
||
|
||
cpx ARGS
|
||
beq .9
|
||
|
||
inx
|
||
lda ARGS,x
|
||
cmp #'"'
|
||
bne .9
|
||
|
||
.3 cpx ARGS
|
||
beq .9
|
||
|
||
inx
|
||
lda ARGS,x
|
||
cmp #'"'
|
||
beq .1
|
||
phx
|
||
>SYSCALL PutChar.A
|
||
plx
|
||
bcs .99
|
||
bra .3
|
||
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
|
||
.70 inx
|
||
lda ARGS,x
|
||
cmp #' '
|
||
beq .1
|
||
|
||
.7 lda (ZPPTR1)
|
||
cmp #VarLen.MAX
|
||
beq .9
|
||
inc
|
||
sta (ZPPTR1)
|
||
tay
|
||
lda ARGS,x
|
||
sta (ZPPTR1),y
|
||
cpx ARGS
|
||
bne .70
|
||
|
||
.8 lda (ZPPTR1) No var name ? SYNERR
|
||
beq .9
|
||
|
||
clc
|
||
.99 rts
|
||
*--------------------------------------
|
||
Cmd.Exec.SLEEP lda ARGS
|
||
beq .9
|
||
|
||
lda #Sleep
|
||
clc
|
||
adc pData
|
||
tay
|
||
lda /Sleep
|
||
adc pData+1
|
||
>PUSHYA
|
||
>PUSHW L.ARGS
|
||
>SYSCALL AToI.YA
|
||
|
||
bcs .9
|
||
|
||
rts
|
||
.9 jmp Cmd.Exec.ERRSYN
|
||
*--------------------------------------
|
||
Cmd.Exec.PAUSE ldy #bPause
|
||
lda #$80
|
||
sta (pData),y
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Cmd.Exec.EXIT ldy #bEXIT
|
||
lda #$FF
|
||
sta (pData),y
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
|
||
LOAD /A2OSX.SRC/SBIN/SHELL.S
|
||
ASM
|