mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-10 22:54:59 +00:00
391 lines
6.7 KiB
Plaintext
391 lines
6.7 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
*--------------------------------------
|
||
EXEC.CMD stz hFullCmd
|
||
stz hEnvPath
|
||
|
||
ldy #hCmdLine
|
||
>PUSHB (pData),y
|
||
>PUSHBI $20 Push SEP=' '
|
||
>PUSHBI 0 Push 0 for getting CMD & ARGS
|
||
>SYSCALL SYS.PStrGetTkn
|
||
bcs .99
|
||
|
||
sta hExecCmd
|
||
stx hExecArgs
|
||
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPtr1
|
||
|
||
ldx #0
|
||
stz ExecCmdIdx
|
||
|
||
.1 lda CMDS,x
|
||
beq EXEC.CMD.EXT
|
||
cmp (ZPPtr1)
|
||
bne .5
|
||
|
||
phx
|
||
ldy #0
|
||
|
||
.2 iny
|
||
inx
|
||
lda (ZPPtr1),y
|
||
cmp #'a'
|
||
bcc .3
|
||
cmp #'{'
|
||
bcs .3
|
||
eor #$20 to Uppercase
|
||
.3 cmp CMDS,x
|
||
bne .4
|
||
tya
|
||
cmp (ZPPtr1)
|
||
bne .2
|
||
plx
|
||
|
||
jsr EXEC.CMD.INT
|
||
jmp EXEC.CMD.ClnUp
|
||
|
||
.4 plx
|
||
.5 txa
|
||
sec
|
||
adc CMDS,x
|
||
tax
|
||
inc ExecCmdIdx
|
||
inc ExecCmdIdx
|
||
bra .1
|
||
.99 rts
|
||
|
||
EXEC.CMD.EXT ldy #1
|
||
lda (ZPPtr1),y
|
||
cmp #'/'
|
||
bne .2
|
||
ldy #hCmdLine
|
||
lda (pPs),y
|
||
bra .11
|
||
|
||
.2 >PUSHW L.ENV.PATH push ENVNAME=PATH
|
||
ldy #S.PS.hENV
|
||
lda (pPs),y
|
||
>PUSHA
|
||
>SYSCALL SYS.GetEnvVarP get value for ENV=PATH
|
||
|
||
bcs EXEC.CMD.ClnUp
|
||
|
||
sta hEnvPath
|
||
>PUSHB hExecCmd
|
||
>PUSHB hEnvPath
|
||
>SYSCALL SYS.FileSearch
|
||
bcc .10
|
||
|
||
>PUSHB hExecCmd
|
||
ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>PUSHA
|
||
>SYSCALL SYS.FileSearch
|
||
|
||
bcs EXEC.CMD.ClnUp
|
||
|
||
.10 sta hFullCmd
|
||
.11 >SYSCALL SYS.MLIGetFileInfoA
|
||
bcs EXEC.CMD.ClnUp
|
||
|
||
>STYA ZPPTR1
|
||
ldy #1 Get File Type
|
||
lda (ZPPTR1),y
|
||
cmp #$04 TXT File ?
|
||
bne .1
|
||
|
||
bra *
|
||
|
||
.1 jsr EXEC.CMD.ClnUp Discard CMD & ARGS
|
||
ldy #hCmdLine
|
||
lda (pData),y
|
||
>SYSCALL SYS.ExecProcessNewEnvA
|
||
|
||
rts
|
||
|
||
EXEC.CMD.ClnUp pha
|
||
php
|
||
lda hFullCmd
|
||
beq .1
|
||
>SYSCALL SYS.FreeMemA
|
||
|
||
.1 lda hEnvPath
|
||
beq .2
|
||
>SYSCALL SYS.FreeMemA
|
||
|
||
.2 lda hExecArgs
|
||
beq .3
|
||
>SYSCALL SYS.FreeMemA
|
||
|
||
.3 lda hExecCmd
|
||
beq .8
|
||
>SYSCALL SYS.FreeMemA
|
||
.8 plp
|
||
pla
|
||
rts
|
||
*--------------------------------------
|
||
EXEC.CMD.INT ldx ExecCmdIdx
|
||
jmp (J.INTCMDS,x)
|
||
*--------------------------------------
|
||
EXEC.CMD.CD lda hExecArgs
|
||
bne EXEC.CMD.CD.C
|
||
ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>PUSHYA
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTP
|
||
jsr CROUT
|
||
clc
|
||
rts
|
||
|
||
EXEC.CMD.CD.C >SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPTR2
|
||
ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPTR1
|
||
>PUSHWI MLI.MAXPATH+1 Get a buffer for new PATH
|
||
>PUSHBI 0 no particular Option
|
||
>SYSCALL SYS.GetMem
|
||
bcs .99
|
||
>STYA ZPPTR3
|
||
stx hNEWPATH
|
||
|
||
lda #0
|
||
sta (ZPPTR3)
|
||
ldy #1
|
||
lda (ZPPTR2),y
|
||
cmp #'/' Full Path?
|
||
beq .3
|
||
cmp #'.' ".." ?
|
||
bne .2
|
||
lda (ZPPTR2)
|
||
cmp #2
|
||
bne .97
|
||
iny
|
||
lda (ZPPTR2),y
|
||
cmp #'.'
|
||
bne .97
|
||
lda (ZPPTR1)
|
||
tay
|
||
.1 dey
|
||
beq .97
|
||
lda (ZPPTR1),y
|
||
cmp #'/'
|
||
bne .1
|
||
tya
|
||
sta (ZPPTR3)
|
||
.11 lda (ZPPTR1),y
|
||
sta (ZPPTR3),y
|
||
dey
|
||
bne .11
|
||
bra .4
|
||
.97 lda #SYSMGR.ERRSYN
|
||
.98 pha
|
||
lda hNEWPATH
|
||
>SYSCALL SYS.FreeMemA
|
||
pla
|
||
sec
|
||
.99 rts
|
||
|
||
.2 >PUSHW ZPPTR1
|
||
>PUSHW ZPPTR3
|
||
>LIBCALL hLIBSTR,LIBSTR.STRCPYP
|
||
.3 >PUSHW ZPPTR2
|
||
>PUSHW ZPPTR3
|
||
>LIBCALL hLIBSTR,LIBSTR.STRCATP
|
||
lda (ZPPTR3)
|
||
tay
|
||
lda #'/' Ending with '/'?
|
||
cmp (ZPPTR3),y
|
||
beq .4
|
||
iny
|
||
sta (ZPPTR3),y
|
||
tya
|
||
sta (ZPPTR3)
|
||
.4 lda hNEWPATH
|
||
>SYSCALL SYS.CheckPrefixA
|
||
bcs .98
|
||
ldy #S.PS.hPREFIX
|
||
lda (pPs),y
|
||
pha
|
||
lda hNEWPATH
|
||
sta (pPs),y
|
||
pla
|
||
>SYSCALL SYS.FreeMemA
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
EXEC.CMD.SET lda hExecArgs
|
||
bne .2
|
||
|
||
ldy #S.PS.hENV
|
||
lda (pPs),y
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPTR1
|
||
|
||
.1 lda (ZPPTR1)
|
||
beq .8 Ending 0 ?
|
||
>PUSHW ZPPTR1
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTP
|
||
jsr CROUT
|
||
|
||
lda ZPPTR1
|
||
sec
|
||
adc (ZPPTR1) Add len+1 to PTR
|
||
sta ZPPTR1
|
||
bcc .1
|
||
inc ZPPTR1
|
||
bra .1
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.2 >PUSHA Push Cmd Line
|
||
>PUSHBI $3D Push SEP='='
|
||
>PUSHBI 0 Push Token IDX
|
||
>SYSCALL SYS.PStrGetTkn
|
||
bcc .3
|
||
lda #SYSMGR.ERRSYN
|
||
rts
|
||
|
||
.3 sta hVarName
|
||
stx hVarValue
|
||
txa
|
||
bne .7
|
||
|
||
lda hExecArgs
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPTR1
|
||
lda (ZPPTR1)
|
||
tay
|
||
lda (ZPPTR1),y
|
||
cmp #'='
|
||
beq .7
|
||
|
||
>PUSHB hVarName
|
||
ldy #S.PS.hENV
|
||
>PUSHB (pPs),y
|
||
>SYSCALL SYS.GetEnvVarH
|
||
bcs .97
|
||
sta hVarValue
|
||
|
||
lda hVarName
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>PUSHYA
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTP
|
||
|
||
lda #'='
|
||
jsr COUT
|
||
|
||
lda hVarValue
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>PUSHYA
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTP
|
||
jsr CROUT
|
||
|
||
bra .97
|
||
|
||
.7 >PUSHB hVarValue
|
||
>PUSHB hVarName
|
||
ldy #S.PS.hENV
|
||
>PUSHB (pPs),y
|
||
>SYSCALL SYS.SetEnvVarH
|
||
|
||
.97 php
|
||
pha
|
||
lda hVarValue
|
||
beq .98
|
||
>SYSCALL SYS.FreeMemA
|
||
.98 lda hVarName
|
||
>SYSCALL SYS.FreeMemA
|
||
pla
|
||
php
|
||
rts
|
||
*--------------------------------------
|
||
EXEC.CMD.DATE >SYSCALL SYS.MLIGetTime
|
||
bcs .9
|
||
>PUSHW DATELO
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTDATE
|
||
jsr CROUT
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
EXEC.CMD.TIME >SYSCALL SYS.MLIGetTime
|
||
bcs .9
|
||
>PUSHW TIMELO
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTTIME
|
||
jsr CROUT
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
EXEC.CMD.ECHO lda hExecArgs
|
||
beq .98
|
||
>SYSCALL SYS.ExpandPStrA
|
||
bcs .99
|
||
|
||
pha
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>PUSHYA
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTP
|
||
jsr CROUT
|
||
pla
|
||
>SYSCALL SYS.FreeMemA
|
||
clc
|
||
rts
|
||
|
||
.98 lda #SYSMGR.ERRSYN
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
EXEC.CMD.TYPE lda hExecArgs
|
||
beq .98
|
||
>SYSCALL SYS.LoadFileA
|
||
bcs .99
|
||
|
||
>STYA ZPPTR2 store file len
|
||
phx
|
||
txa
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPTR1
|
||
.1 lda ZPPTR2
|
||
bne .2
|
||
lda ZPPTR2+1
|
||
beq .3
|
||
dec ZPPTR2+1
|
||
.2 dec ZPPTR2
|
||
|
||
lda (ZPPTR1)
|
||
jsr COUT
|
||
inc ZPPTR1
|
||
bne .1
|
||
inc ZPPTR1+1
|
||
bra .1
|
||
|
||
.3 pla
|
||
>SYSCALL SYS.FreeMemA
|
||
clc
|
||
rts
|
||
|
||
.98 lda #SYSMGR.ERRSYN
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
EXEC.CMD.EXIT ldy #bEXIT
|
||
lda #$FF
|
||
sta (pData),y
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE SBIN/SHELL.S.CMD
|
||
LOAD SBIN/SHELL.S
|
||
ASM
|