A2osX/SBIN/SHELL.S.txt

528 lines
9.2 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
2015-10-19 20:35:00 +00:00
.LIST OFF
2015-03-14 21:48:35 +00:00
.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
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-10-19 20:35:00 +00:00
*--------------------------------------
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.ERROR .DA MSG.ERROR
2015-10-19 20:35:00 +00:00
L.ENV.PATH .DA ENV.PATH
J.INTCMDS .DA EXEC.CMD.CD
2015-03-14 21:48:35 +00:00
.DA EXEC.CMD.DATE
.DA EXEC.CMD.ECHO
.DA EXEC.CMD.EXIT
.DA EXEC.CMD.PAUSE
.DA EXEC.CMD.READ
.DA EXEC.CMD.SET
.DA EXEC.CMD.TIME
.DA EXEC.CMD.TYPE
2015-03-14 21:48:35 +00:00
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBSTR
>SYSCALL SYS.LoadLibYA
2015-10-19 20:35:00 +00:00
bcs .9
2015-03-14 21:48:35 +00:00
sta hLIBSTR
ldy #S.PS.hARGS Batch file ?
2015-10-19 20:35:00 +00:00
lda (pPs),y
beq CS.INIT.INTERACTIVE no,continue starting interactive
jsr OpenTxtFileA
bcs .9
2015-10-19 20:35:00 +00:00
ldy #bExitOnEOF
lda #$FF
sta (pData),y
2015-10-19 20:35:00 +00:00
clc
.9 rts
*--------------------------------------
CS.INIT.INTERACTIVE
jsr History.Init
bcs .9
2015-03-14 21:48:35 +00:00
ldy #S.PS.hINDEV
2015-06-03 18:30:57 +00:00
lda (pPs),y
2015-03-14 21:48:35 +00:00
>PUSHA
>LDYA L.MSG.GREETINGS
>SYSCALL SYS.PSTROutYA
2015-03-14 21:48:35 +00:00
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-10-19 20:35:00 +00:00
2015-03-14 21:48:35 +00:00
clc
2015-10-19 20:35:00 +00:00
.9 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.RUN lda #0
sta (pData)
ldy #bPause
lda (pData),y
bpl .10
clc
rts
2015-03-14 21:48:35 +00:00
.10 ldy #hInputFile batch mode ?
lda (pData),y
bne .2
jsr PrintPrompt
bcs .99
.1 >SYSCALL SYS.Sleep
2015-06-24 20:41:38 +00:00
lda (pData)
bpl .1
2015-03-14 21:48:35 +00:00
and #$7F
2015-06-03 18:30:57 +00:00
sta (pData)
bra .3
.2 jsr ReadTxtFile
bcs .81
.3 lda (pData)
2015-03-14 21:48:35 +00:00
beq CS.RUN Empty line
2015-10-19 20:35:00 +00:00
ldy #1
lda (pData),y
cmp #'#' Comment
beq CS.RUN
ldy #hInputFile
lda (pData),y
bne .32
ldy #bEchoOff
lda (pData),y
beq .31
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
>LDYA pData
>SYSCALL SYS.PSTROutYA
.31 jsr History.Add
.32 >LDYA pData
2015-06-03 18:30:57 +00:00
>SYSCALL SYS.NewPStrYA
2015-03-14 21:48:35 +00:00
bcs .99
2015-06-03 18:30:57 +00:00
2015-10-19 20:35:00 +00:00
ldy #hCmdLine
2015-06-03 18:30:57 +00:00
sta (pData),y
2015-03-14 21:48:35 +00:00
jsr EXEC.CMD
bcc .4
2015-03-14 21:48:35 +00:00
jsr PrintError
2015-03-14 21:48:35 +00:00
.4 ldy #hCmdLine
2015-06-03 18:30:57 +00:00
lda (pData),y
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.FreeMemA
2015-10-19 20:35:00 +00:00
ldy #hCmdLine
2015-06-03 18:30:57 +00:00
lda #0
sta (pData),y
2015-03-14 21:48:35 +00:00
.8 ldy #bEXIT
2015-06-03 18:30:57 +00:00
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
.81 jsr CloseTxtFile
ldy #bExitOnEOF
lda (pData),y
beq .8
lda #0
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
2015-03-14 21:48:35 +00:00
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
ldy #bPause
lda (pData),y
bpl .11
lda #0
sta (pData),y
2015-12-13 21:29:51 +00:00
clc
rts
.9 sec
rts
.11 ldy #hInputFile Batch mode ?
lda (pData),y
beq .10
2015-12-13 21:29:51 +00:00
* Batch Mode
cpx #3 test Ctrl-c
bne .12
jsr CloseTxtFile
ldy #bExitOnEOF
lda (pData),y
ldy #bExit
sta (pData),y
clc
rts
.12 cpx #19 test Ctrl-s
bne .8
ldy #bPause
lda #$80
sta (pData),y
2015-12-13 21:29:51 +00:00
clc
rts
* interactive mode
.10 ldy #bEscMode
lda (pData),y
beq .13
cpx #'['
beq .8
lda #0
sta (pData),y
txa
ldx EscChars
.17 cmp EscChars,x
beq .18
dex
bne .17
bra .8
2015-12-13 21:29:51 +00:00
.18 lda EscAscii,x
tax
.13 cpx #$20
2015-06-03 18:30:57 +00:00
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
2015-12-13 21:29:51 +00:00
clc
rts
2015-03-14 21:48:35 +00:00
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
>SYSCALL SYS.COutA
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
.8 clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
CS.EVENT.CTRL.CHAR
cpx #13 CR
2015-03-14 21:48:35 +00:00
bne .10
txa
>SYSCALL SYS.COutA
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
2015-12-13 21:29:51 +00:00
.10 cpx #$1B esc
bne .11
ldy #bEscMode
lda #$ff
sta (pData),y
clc
rts
.11 cpx #3 Ctrl-C
2015-03-14 21:48:35 +00:00
bne .1
2015-03-14 21:48:35 +00:00
jsr CmdBuffer.CLR
clc
rts
.1 cpx #8 BS (left arrow)
2015-03-14 21:48:35 +00:00
bne .2
jsr CmdBuffer.DEL
clc
rts
.2 cpx #10 LF (down arrow)
2015-03-14 21:48:35 +00:00
bne .3
2015-06-24 20:41:38 +00:00
jsr HISTORY.GETNEXT
2015-03-14 21:48:35 +00:00
clc
rts
.3 cpx #11 VT (up arrow)
2015-03-14 21:48:35 +00:00
bne .4
2015-06-24 20:41:38 +00:00
jsr HISTORY.GETPREV
2015-03-14 21:48:35 +00:00
clc
rts
.4 cpx #21 NAK (right arrow)
2015-03-14 21:48:35 +00:00
bne .8
clc
rts
.8 clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
2015-10-19 20:35:00 +00:00
CS.QUIT jsr History.Quit
ldy #hInputFile
lda (pData),y
beq .1
>SYSCALL SYS.MLICloseA
.1 ldy #hInputBuffer
lda (pData),y
beq .2
>SYSCALL SYS.FreeMemA
.2 lda hLIBSTR
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.UnloadLibA
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
PrintPrompt lda #'$'
>SYSCALL SYS.COutA
bcs .9
lda #' '
>SYSCALL SYS.COutA
.9 rts
*--------------------------------------
PrintError pha
>PUSHA
>LDYA L.MSG.ERROR
>SYSCALL SYS.PSTROutYA
pla
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CmdBuffer.PRINT ldy #0
.1 iny
lda (pData),y
>SYSCALL SYS.COutA
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
2015-10-19 20:35:00 +00:00
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
CmdBuffer.DEL lda (pData)
2015-03-14 21:48:35 +00:00
beq .9
lda #8
>SYSCALL SYS.COutA
2015-06-03 18:30:57 +00:00
lda (pData)
dec
sta (pData)
2015-03-14 21:48:35 +00:00
.9 rts
*--------------------------------------
OpenTxtFileA >SYSCALL SYS.MLIOpenA
bcs .9
ldy #hInputFile
sta (pData),y
pha
txa
ldy #hInputBuffer
sta (pData),y
>PUSHBI $0D Line separator for TXT file
>PUSHBI $FF
pla
>PUSHA
>SYSCALL SYS.MLINewLine
bcc .9
pha
jsr CloseTxtFile
2015-03-14 21:48:35 +00:00
pla
sec
.9 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
ReadTxtFile >PUSHWI 127
>PUSHWI TmpBuffer256+1
ldy #hInputFile
lda (pData),y
>PUSHA
>SYSCALL SYS.MLIRead
bcs .9
tya
beq .10
lda TmpBuffer256,y Y,A=Bytes read
cmp #$0D
bne .10
dey
.10 tya
sta (pData)
beq .2
.1 lda TmpBuffer256,y
sta (pData),y
dey
bne .1
.2 lda #'>'
>SYSCALL SYS.COutA
lda #'"'
>SYSCALL SYS.COutA
>LDYA pData
>SYSCALL SYS.PSTROutYA
lda #'"'
>SYSCALL SYS.COutA
lda #13
>SYSCALL SYS.COutA
clc
.9 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
CloseTxtFile ldy #hInputArgs
lda (pData),y
beq .1
>SYSCALL SYS.FreeMemA
.1 ldy #hInputFile
lda (pData),y
beq .9
>SYSCALL SYS.MLICloseA
ldy #hInputBuffer
lda (pData),y
>SYSCALL SYS.FreeMemA
.9 lda #0
ldy #hInputArgs
sta (pData),y
ldy #hInputFile
sta (pData),y
ldy #hInputBuffer
sta (pData),y
2015-03-14 21:48:35 +00:00
rts
2015-10-19 20:35:00 +00:00
*--------------------------------------
.INB SBIN/SHELL.S.CMD
.INB SBIN/SHELL.S.HIS
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.END
*--------------------------------------
2015-10-19 20:35:00 +00:00
ENV.PATH >PSTRING "PATH"
2015-03-14 21:48:35 +00:00
CMDS >PSTRING "CD"
2015-10-19 20:35:00 +00:00
>PSTRING "DATE"
>PSTRING "ECHO"
>PSTRING "EXIT"
>PSTRING "PAUSE"
>PSTRING "READ"
>PSTRING "SET"
>PSTRING "TIME"
>PSTRING "TYPE"
2015-10-19 20:35:00 +00:00
.HS 00
2015-03-14 21:48:35 +00:00
*--------------------------------------
LIBSTR >PSTRING "libstr.o"
MSG.GREETINGS >PSTRING "\nA2osX-Shell on Dev=%h\n\n"
MSG.ERROR >PSTRING "[%h]\n"
*MSG.NOTFOUND >CSTRING "Command Not Found\n"
*MSG.SYNERR >CSTRING "Syntax Error Or Invalid Pathname\n"
2015-12-13 21:29:51 +00:00
EscChars >PSTRING "DBAC"
EscAscii .HS 04080A0B15
2015-06-03 18:30:57 +00:00
hLIBSTR .BS 1
hNEWPATH .BS 1
2015-10-19 20:35:00 +00:00
hExecCmd .BS 1
hExecArgs .BS 1
hEnvPath .BS 1
hFullCmd .BS 1
hVarName .BS 1
hVarValue .BS 1
ExecCmdIdx .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-12-13 21:29:51 +00:00
CmdBuffer .BS CmdBuffer.MAX+1 (pData)
bEscMode .BS 1
bPause .BS 1
bExit .BS 1
bEchoOff .BS 1
2015-12-13 21:29:51 +00:00
bExitOnEOF .BS 1
2015-10-19 20:35:00 +00:00
hCmdLine .BS 1
2015-06-24 20:41:38 +00:00
hCmdHistory .BS 1
2015-10-19 20:35:00 +00:00
CmdHistory.IDX .BS 1
2015-12-13 21:29:51 +00:00
CmdHistory.END .BS 1
hInputFile .BS 1
hInputArgs .BS 1
hInputBuffer .BS 1
2015-03-14 21:48:35 +00:00
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