A2osX/SBIN/SHELL.S.txt
2015-12-10 19:53:30 +01:00

485 lines
8.6 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/SBIN/SHELL
*--------------------------------------
.INB INC/MACROS.I
.INB INC/PRODOS.I
.INB INC/A2OSX.I
.INB INC/LIBSTR.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2
ZPPTR3 .EQ ZPBIN+4
*--------------------------------------
CmdBuffer.MAX .EQ 127
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.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
*--------------------------------------
.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
L.ENV.PATH .DA ENV.PATH
J.INTCMDS .DA EXEC.CMD.CD
.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
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBSTR
>SYSCALL SYS.LoadLibYA
bcs .9
sta hLIBSTR
ldy #S.PS.hARGS Batch file ?
lda (pPs),y
beq CS.INIT.INTERACTIVE no,continue starting interactive
jsr OpenTxtFileA
bcs .9
ldy #bExitOnEOF
lda #$FF
sta (pData),y
clc
.9 rts
*--------------------------------------
CS.INIT.INTERACTIVE
jsr History.Init
bcs .9
ldy #S.PS.hINDEV
lda (pPs),y
>PUSHA
>LDYA L.MSG.GREETINGS
>SYSCALL SYS.PSTROutYA
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN lda #0
sta (pData)
ldy #bPause
lda (pData),y
bpl .10
clc
rts
.10 ldy #hInputFile batch mode ?
lda (pData),y
bne .2
jsr PrintPrompt
bcs .99
.1 >SYSCALL SYS.Sleep
lda (pData)
bpl .1
and #$7F
sta (pData)
bra .3
.2 jsr ReadTxtFile
bcs .81
.3 lda (pData)
beq CS.RUN Empty line
ldy #1
lda (pData),y
cmp #'#' Comment
beq CS.RUN
ldy #hInputFile
lda (pData),y
bne .32
ldy #bEchoOff
lda (pData),y
beq .31
>LDYA pData
>SYSCALL SYS.PSTROutYA
.31 jsr History.Add
.32 >LDYA pData
>SYSCALL SYS.NewPStrYA
bcs .99
ldy #hCmdLine
sta (pData),y
jsr EXEC.CMD
bcc .4
jsr PrintError
.4 ldy #hCmdLine
lda (pData),y
>SYSCALL SYS.FreeMemA
ldy #hCmdLine
lda #0
sta (pData),y
.8 ldy #bEXIT
lda (pData),y
bne .99
clc
rts
.81 jsr CloseTxtFile
ldy #bExitOnEOF
lda (pData),y
beq .8
lda #0
.99 sec
rts
*--------------------------------------
CS.DOEVENT ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
cmp (pPs),y
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
tax
ldy #bPause
lda (pData),y
bpl .11
lda #0
sta (pData),y
bra .8
.11 ldy #hInputFile Batch mode ?
lda (pData),y
beq .10
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
bra .8
.10 cpx #$20
bcs .1
jsr CS.EVENT.CTRL.CHAR
bra .8
.1 cpx #$7f
bne .2
jsr CmdBuffer.DEL
bra .8
.2 lda (pData) CmdBuffer
cmp #CmdBuffer.MAX
beq .8
inc
sta (pData)
tay
txa
sta (pData),y
>SYSCALL SYS.COutA
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.EVENT.CTRL.CHAR
cpx #13 CR
bne .10
txa
>SYSCALL SYS.COutA
lda (pData) CmdBuffer
ora #$80
sta (pData)
clc
rts
.10 cpx #3 Ctrl-C
bne .1
jsr CmdBuffer.CLR
clc
rts
.1 cpx #8 BS (left arrow)
bne .2
jsr CmdBuffer.DEL
clc
rts
.2 cpx #10 LF (down arrow)
bne .3
jsr HISTORY.GETNEXT
clc
rts
.3 cpx #11 VT (up arrow)
bne .4
jsr HISTORY.GETPREV
clc
rts
.4 cpx #21 NAK (right arrow)
bne .8
clc
rts
.8 clc
rts
*--------------------------------------
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
>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
*--------------------------------------
CmdBuffer.PRINT ldy #0
.1 iny
lda (pData),y
>SYSCALL SYS.COutA
tya
cmp (pData)
bne .1
rts
*--------------------------------------
CmdBuffer.CLR jsr CmdBuffer.DEL
bne CmdBuffer.CLR
rts
*--------------------------------------
CmdBuffer.DEL lda (pData)
beq .9
lda #8
>SYSCALL SYS.COutA
lda (pData)
dec
sta (pData)
.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
pla
sec
.9 rts
*--------------------------------------
ReadTxtFile >PUSHWI 127
>PUSHWI TmpBuffer256+1
ldy #hInputFile
lda (pData),y
>PUSHA
>SYSCALL SYS.MLIRead
bcs .9
lda TmpBuffer256,y Y,A=Bytes read
cmp #$0D
bne .10
dey
.10 tya
sta (pData)
.1 lda TmpBuffer256,y
sta (pData),y
dey
bne .1
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
*--------------------------------------
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
rts
*--------------------------------------
.INB SBIN/SHELL.S.CMD
.INB SBIN/SHELL.S.HIS
*--------------------------------------
CS.END
*--------------------------------------
ENV.PATH >PSTRING "PATH"
CMDS >PSTRING "CD"
>PSTRING "DATE"
>PSTRING "ECHO"
>PSTRING "EXIT"
>PSTRING "PAUSE"
>PSTRING "READ"
>PSTRING "SET"
>PSTRING "TIME"
>PSTRING "TYPE"
.HS 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"
hLIBSTR .BS 1
hNEWPATH .BS 1
hExecCmd .BS 1
hExecArgs .BS 1
hEnvPath .BS 1
hFullCmd .BS 1
hVarName .BS 1
hVarValue .BS 1
ExecCmdIdx .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
CmdBuffer .BS CmdBuffer.MAX+1
bPause .BS 1
bExit .BS 1
bEchoOff .BS 1
hCmdLine .BS 1
hCmdHistory .BS 1
CmdHistory.IDX .BS 1
bExitOnEOF .BS 1
hInputFile .BS 1
hInputArgs .BS 1
hInputBuffer .BS 1
CmdHistory.END .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE SBIN/SHELL.S
ASM