A2osX/SBIN/SHELL.S.txt

693 lines
13 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2015-03-14 21:48:35 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
2015-06-03 18:30:57 +00:00
.TF /A2OSX.BOOT/SBIN/SHELL
2015-03-14 21:48:35 +00:00
*--------------------------------------
.INB INC/MACROS.I
.INB INC/PRODOS.I
2015-06-03 18:30:57 +00:00
.INB INC/A2OSX.I
.INB INC/A2OSX.API.I
2015-03-14 21:48:35 +00:00
.INB INC/LIBSTR.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2
ZPPTR3 .EQ ZPBIN+4
*--------------------------------------
CmdBuffer.MAX .EQ 127
*--------------------------------------
2015-06-03 18:30:57 +00:00
* File Header (16 Bytes)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.START cld
jmp (.1,x)
2015-06-03 18:30:57 +00:00
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
2015-03-14 21:48:35 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
*--------------------------------------
L.LIBSTR .DA LIBSTR
L.MSG.GREETINGS .DA MSG.GREETINGS
L.MSG.UNKNOWN .DA MSG.UNKNOWN
L.MSG.SYNERR .DA MSG.SYNERR
L.CMDS .DA CMDS
T.INTCMDS .DA EXEC.CMD.CD
.DA EXEC.CMD.SET
.DA EXEC.CMD.DATE
.DA EXEC.CMD.TIME
.DA EXEC.CMD.ECHO
.DA EXEC.CMD.TYPE
.DA EXEC.CMD.EXIT
.DA 0
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.INIT lda #0
ldy #bEXIT
sta (pData),y
ldy #CmdHistory.IDX
sta (pData),y
ldy #CmdHistory.END
sta (pData),y
2015-03-14 21:48:35 +00:00
2015-06-24 20:41:38 +00:00
>PUSHWI 256 Get a buffer for History
>PUSHBI S.MEM.F.INIT0
>SYSCALL SYS.GetMem
bcs .99
stx hCmdHistory
2015-06-03 18:30:57 +00:00
>LDYA L.LIBSTR
>LOADLIBYA
2015-03-14 21:48:35 +00:00
bcs .99
sta hLIBSTR
ldy #S.PS.ID
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
>PUSHA
ldy #S.PS.hOUTDEV
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
>PUSHA
ldy #S.PS.hINDEV
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
>PUSHA
>PUSHW L.MSG.GREETINGS
>LIBCALL hLIBSTR,LIBSTR.PRINTF
2015-06-03 18:30:57 +00:00
lda (pPs)
2015-03-14 21:48:35 +00:00
ora #S.PS.F.EVENT Now accept events
2015-06-03 18:30:57 +00:00
sta (pPs)
2015-03-14 21:48:35 +00:00
clc
.99 rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.RUN lda #0
sta (pData)
2015-03-14 21:48:35 +00:00
lda #"$"
jsr COUT
lda #" "
jsr COUT
2015-06-24 20:41:38 +00:00
.1 jsr A2osX.SLEEP
lda (pData)
bpl .1
2015-03-14 21:48:35 +00:00
.2 and #$7F
2015-06-03 18:30:57 +00:00
sta (pData)
2015-03-14 21:48:35 +00:00
beq CS.RUN Empty line
2015-06-03 18:30:57 +00:00
>LDYA pData
>SYSCALL SYS.NewPStrYA
2015-03-14 21:48:35 +00:00
bcs .99
2015-06-03 18:30:57 +00:00
ldy #hCMDLINE
sta (pData),y
2015-06-24 20:41:38 +00:00
jsr HISTORY.ADD
2015-03-14 21:48:35 +00:00
jsr EXEC.CMD
bcc .3
pha
lda #"["
jsr COUT
pla
jsr PRBYTE
lda #"]"
jsr COUT
jsr CROUT
2015-06-03 18:30:57 +00:00
.3 ldy #hCMDLINE
lda (pData),y
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.FreeMemA
2015-06-03 18:30:57 +00:00
ldy #hCMDLINE
lda #0
sta (pData),y
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
ldy #bEXIT
lda (pData),y
2015-03-14 21:48:35 +00:00
bne .99
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
clc
rts
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
.99 sec
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT ldy #S.EVT.hDEV is Event from active IN device?
2015-03-14 21:48:35 +00:00
lda (pEvent),y
ldy #S.PS.hINDEV
2015-06-03 18:30:57 +00:00
cmp (pPs),y
2015-03-14 21:48:35 +00:00
bne .9
lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
2015-06-03 18:30:57 +00:00
tax
cpx #$20
bcs .1
2015-03-14 21:48:35 +00:00
jsr CS.EVENT.CTRL.CHAR
bra .8
2015-06-03 18:30:57 +00:00
.1 cpx #$7f
2015-03-14 21:48:35 +00:00
bne .2
jsr CmdBuffer.DEL
bra .8
2015-06-03 18:30:57 +00:00
.2 lda (pData) CmdBuffer
cmp #CmdBuffer.MAX
2015-03-14 21:48:35 +00:00
beq .8
2015-06-03 18:30:57 +00:00
inc
sta (pData)
tay
txa
sta (pData),y
2015-03-14 21:48:35 +00:00
ora #$80
jsr COUT
2015-06-03 18:30:57 +00:00
.8 clc
2015-03-14 21:48:35 +00:00
rts
.9 sec
rts
*--------------------------------------
CS.EVENT.CTRL.CHAR
cmp #13 CR
bne .10
jsr CROUT
2015-06-03 18:30:57 +00:00
lda (pData) CmdBuffer
2015-03-14 21:48:35 +00:00
ora #$80
2015-06-03 18:30:57 +00:00
sta (pData)
2015-03-14 21:48:35 +00:00
clc
rts
.10 cmp #3
bne .1
jsr CmdBuffer.CLR
clc
rts
.1 cmp #8 BS (left arrow)
bne .2
jsr CmdBuffer.DEL
clc
rts
.2 cmp #10 LF (down arrow)
bne .3
2015-06-24 20:41:38 +00:00
jsr HISTORY.GETNEXT
2015-03-14 21:48:35 +00:00
clc
rts
.3 cmp #11 VT (up arrow)
bne .4
2015-06-24 20:41:38 +00:00
jsr HISTORY.GETPREV
2015-03-14 21:48:35 +00:00
clc
rts
.4 cmp #21 NAK (right arrow)
bne .8
clc
rts
.8 jsr PRBYTE
clc
rts
*--------------------------------------
2015-06-24 20:41:38 +00:00
CS.QUIT lda hCmdHistory
beq .1
>SYSCALL SYS.FreeMemA
.1 lda hLIBSTR
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.UnloadLibA
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD ldy #hCMDLINE
>PUSHB (pData),y
2015-03-14 21:48:35 +00:00
>PUSHBI $20 Push SEP=' '
>PUSHBI 0 Push 0 for getting CMD & ARGS
>SYSCALL SYS.PStrGetTkn
bcs .99
2015-06-03 18:30:57 +00:00
ldy #hCMD
sta (pData),y
pha
txa
ldy #hARGS
sta (pData),y
pla
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.GetMemPtrA
>PUSHYA
>PUSHYA
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
>LIBCALL hLIBSTR,LIBSTR.UCASEP
>PUSHW L.CMDS
>SYSCALL SYS.GetPStrIndex
bcs .1 Not An internal command
jsr EXEC.CMD.INT
bcs .98
jsr .98
clc
rts
.1 jsr .98 Discard CMD & ARGS
2015-06-03 18:30:57 +00:00
ldy #hCMDLINE
lda (pData),y
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.ExecProcessA
rts
.98 pha
2015-06-03 18:30:57 +00:00
ldy #hCMD
lda (pData),y
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.FreeMemA
2015-06-03 18:30:57 +00:00
ldy #hARGS
lda (pData),y
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.FreeMemA
pla
sec
.99 rts
*--------------------------------------
EXEC.CMD.INT asl
tax
jmp (T.INTCMDS,x)
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.CD ldy #hARGS
lda (pData),y
2015-03-14 21:48:35 +00:00
bne EXEC.CMD.CD.C
ldy #S.PS.hPREFIX
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
>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
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
>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
2015-06-03 18:30:57 +00:00
stx hNEWPATH
2015-03-14 21:48:35 +00:00
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
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
.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
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
pha
lda hNEWPATH
2015-06-03 18:30:57 +00:00
sta (pPs),y
2015-03-14 21:48:35 +00:00
pla
>SYSCALL SYS.FreeMemA
clc
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.SET ldy #hARGS
lda (pData),y
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
.2 sec
2015-03-14 21:48:35 +00:00
rts
2015-06-03 18:30:57 +00:00
.8 clc
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.DATE >SYSCALL SYS.MLIGetTime
2015-03-14 21:48:35 +00:00
bcs .9
>PUSHW DATELO
>LIBCALL hLIBSTR,LIBSTR.PRINTDATE
jsr CROUT
clc
.9 rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.TIME >SYSCALL SYS.MLIGetTime
2015-03-14 21:48:35 +00:00
bcs .9
>PUSHW TIMELO
>LIBCALL hLIBSTR,LIBSTR.PRINTTIME
jsr CROUT
clc
.9 rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.ECHO ldy #hARGS
lda (pData),y
beq .98
>SYSCALL SYS.ExpandPStrA
bcs .99
pha
>SYSCALL SYS.GetMemPtrA
>PUSHYA
>LIBCALL hLIBSTR,LIBSTR.PRINTP
jsr CROUT
pla
>SYSCALL SYS.FreeMemA
clc
2015-03-14 21:48:35 +00:00
rts
2015-06-03 18:30:57 +00:00
.98 lda #SYSMGR.ERRSYN
sec
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.TYPE ldy #hARGS
lda (pData),y
2015-03-14 21:48:35 +00:00
beq .98
>SYSCALL SYS.LoadFileA
bcs .99
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
>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
2015-06-03 18:30:57 +00:00
sec
2015-03-14 21:48:35 +00:00
.99 rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
EXEC.CMD.EXIT ldy #bEXIT
lda #$FF
sta (pData),y
2015-03-14 21:48:35 +00:00
clc
rts
*--------------------------------------
2015-06-24 20:41:38 +00:00
HISTORY.ADD lda hCmdHistory
>SYSCALL SYS.GetMemPtrA
>STYA ZPPTR1
.10 lda CmdHistory.END ending 0
2015-03-14 21:48:35 +00:00
inc keep room for new ending 0
sec add len+1
2015-06-24 20:41:38 +00:00
adc (pData) CmdBuffer
2015-03-14 21:48:35 +00:00
bcc .2 enough room
2015-06-24 20:41:38 +00:00
lda (ZPPTR1) get len of oldest string
sec
adc ZPPTR1
sta ZPPTR2
lda ZPPTR1+1
adc #0
sta ZPPTR2+1
ldy #$FF
.1 iny
lda (ZPPTR2),y move back until 0 found
sta (ZPPTR1),y
2015-03-14 21:48:35 +00:00
bne .1
2015-06-24 20:41:38 +00:00
2015-03-14 21:48:35 +00:00
sty CmdHistory.END mark new end of history
2015-06-24 20:41:38 +00:00
bra .10 retry....
2015-03-14 21:48:35 +00:00
2015-06-24 20:41:38 +00:00
.2 ldy CmdHistory.END
lda (pData)
tax
lda pData
sta ZPPTR2
lda pData+1
sta ZPPTR2+1
.3 lda (ZPPTR2)
sta (ZPPTR1),y
inc ZPPTR2
bne .4
inc ZPPTR2+1
.4 iny
dex
bpl .3
lda #0
sta (ZPPTR1),y set ending 0
sty CmdHistory.IDX
sty CmdHistory.END
2015-03-14 21:48:35 +00:00
.9 rts
*--------------------------------------
HISTORY.GETPREV lda CmdHistory.END
beq HISTORY.RTS empty history,nothing to do
lda CmdHistory.IDX
beq HISTORY.RTS already oldest,nothing to do
2015-06-24 20:41:38 +00:00
lda hCmdHistory
>SYSCALL SYS.GetMemPtrA
>STYA ZPPTR1
2015-03-14 21:48:35 +00:00
lda #0
2015-06-24 20:41:38 +00:00
.1 tay save current index
2015-03-14 21:48:35 +00:00
sec
2015-06-24 20:41:38 +00:00
adc (ZPPTR1),y
2015-03-14 21:48:35 +00:00
cmp CmdHistory.IDX
bne .1 not yet reached current index
2015-06-24 20:41:38 +00:00
sty CmdHistory.IDX set new index
2015-03-14 21:48:35 +00:00
bra HISTORY.SETBUF
HISTORY.RTS rts
*--------------------------------------
HISTORY.GETNEXT ldx CmdHistory.END
beq HISTORY.RTS empty history,nothing to do
cpx CmdHistory.IDX
beq HISTORY.RTS
2015-06-24 20:41:38 +00:00
lda hCmdHistory
>SYSCALL SYS.GetMemPtrA
>STYA ZPPTR1
ldy CmdHistory.IDX
lda (ZPPTR1),y
2015-03-14 21:48:35 +00:00
sec
adc CmdHistory.IDX
cmp CmdHistory.END
sta CmdHistory.IDX
beq CmdBuffer.CLR end of history, just blank buffer
*--------------------------------------
HISTORY.SETBUF jsr CmdBuffer.CLR
2015-06-24 20:41:38 +00:00
lda pData
sta ZPPTR2
lda pData+1
sta ZPPTR2+1
ldy CmdHistory.IDX
lda (ZPPTR1),y
tax
.1 lda (ZPPTR1),y
sta (ZPPTR2)
inc ZPPTR2
bne .2
inc ZPPTR2+1
.2 iny
dex
bpl .1
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
CmdBuffer.PRINT ldy #0
.1 iny
lda (pData),y
2015-03-14 21:48:35 +00:00
ora #$80
jsr COUT
2015-06-03 18:30:57 +00:00
tya
cmp (pData)
2015-03-14 21:48:35 +00:00
bne .1
rts
*--------------------------------------
CmdBuffer.CLR jsr CmdBuffer.DEL
bne CmdBuffer.CLR
.9 rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CmdBuffer.DEL lda (pData)
2015-03-14 21:48:35 +00:00
beq .9
lda #8
jsr COUT
2015-06-03 18:30:57 +00:00
lda (pData)
dec
sta (pData)
2015-03-14 21:48:35 +00:00
.9 rts
*--------------------------------------
PRBYTE pha
lsr
lsr
lsr
lsr
ora #$B0
cmp #$BA
bcc .1
adc #6
.1 jsr COUT
pla
and #$0F
ora #$B0
cmp #$BA
bcc COUT
adc #6
bra COUT
*--------------------------------------
CROUT lda #13
*--------------------------------------
COUT phx
phy
2015-06-03 18:30:57 +00:00
ldx #DEVMGR.COUT
jsr pDevJmp
2015-03-14 21:48:35 +00:00
ply
plx
rts
2015-06-03 18:30:57 +00:00
pDevJmp jmp (pDev)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.END
*--------------------------------------
CMDS >PSTRING "CD"
CMDS1 >PSTRING "SET"
CMDS2 >PSTRING "DATE"
CMDS3 >PSTRING "TIME"
CMDS4 >PSTRING "ECHO"
CMDS5 >PSTRING "TYPE"
CMDS6 >PSTRING "EXIT"
.DA #0
*--------------------------------------
LIBSTR >PSTRING "libstr.o"
MSG.GREETINGS >CSTRING "\nA2osX-Shell on Dev=(%h:%h),PS=%h\n\n"
MSG.UNKNOWN >CSTRING "Command Not Found\n"
MSG.SYNERR >CSTRING "Syntax Error Or Invalid Pathname\n"
2015-06-03 18:30:57 +00:00
hLIBSTR .BS 1
hNEWPATH .BS 1
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
.DUMMY
.OR 0
2015-03-14 21:48:35 +00:00
DS.START
2015-06-03 18:30:57 +00:00
CmdBuffer .BS CmdBuffer.MAX+1
2015-03-14 21:48:35 +00:00
bEXIT .BS 1
hCMDLINE .BS 1
hCMD .BS 1
hARGS .BS 1
2015-06-24 20:41:38 +00:00
hCmdHistory .BS 1
2015-03-14 21:48:35 +00:00
CmdHistory.IDX .BS 1
CmdHistory.END .BS 1
DS.END
2015-06-03 18:30:57 +00:00
.ED
2015-03-14 21:48:35 +00:00
*--------------------------------------
MAN
SAVE SBIN/SHELL.S
ASM