A2osX/SBIN/SHELL.S.txt
Rémy GIBERT 92c34d5fde Kernel version 0.9 : ***new media dated 2017-04-04
-bugfix in SHELL batch mode, CP, FORMAT, ENV processing
-CHTYP Command running.
-Now, A2OSX.BOOT media is built from MAKEBOOT script from A2OSX.BUILD
2017-04-04 15:07:58 +02:00

533 lines
9.5 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.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BUILD/SBIN/SHELL
*--------------------------------------
.INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I
.INB /A2OSX.BUILD/INC/MLI.ERR.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2
ZPPTR3 .EQ ZPBIN+4
*--------------------------------------
CmdLine.MAX .EQ 127
VarLen.MAX .EQ 15
*--------------------------------------
* 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.MSG.GREETINGS .DA MSG.GREETINGS
L.MSG.PROMPT .DA MSG.PROMPT
L.MSG.ECHO .DA MSG.ECHO
L.MSG.ERROR .DA MSG.ERROR
L.MSG.PRINTENV .DA MSG.PRINTENV
L.ENV.PATH .DA ENV.PATH
L.ENV.PWD .DA ENV.PWD
L.ENV.PS1 .DA ENV.PS1
L.CMD .DA CMD
L.ARGS .DA ARGS
L.TIME .DA TIME
L.STAT .DA STAT
L.FMT.DATE .DA FMT.DATE
L.FMT.TIME .DA FMT.TIME
L.CMDS .DA CMDS
J.INTCMDS .DA Cmd.Exec.CD
.DA Cmd.Exec.DATE
.DA Cmd.Exec.ECHO
.DA Cmd.Exec.EXIT
.DA Cmd.Exec.PAUSE
.DA Cmd.Exec.PWD
.DA Cmd.Exec.READ
.DA Cmd.Exec.SET
.DA Cmd.Exec.STARTPROC
.DA Cmd.Exec.TIME
L.ERR.Codes .DA ERR.Codes
L.ERR.Messages .DA ERR.Messages
.DA 0
*--------------------------------------
CS.INIT jsr SetPWD
>SYSCALL GetArgC
cmp #1
beq CS.INIT.INTERACTIVE no arg, continue starting interactive
lda #1
>SYSCALL GetArgA
jsr TXT.OpenFileYA
bcs .9
ldy #bExitOnEOF
lda #$FF
sta (pData),y
clc
.9 rts
*--------------------------------------
CS.INIT.INTERACTIVE
jsr HIS.Init
bcs .9
>LDYA L.MSG.GREETINGS
>SYSCALL PPrintFYA
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN ldy #bPause
lda (pData),y
bmi .8
ldy #VarBuffer READ Command ?
lda (pData),y
bne CS.RUN.READ
ldy #S.PS.RC
lda (pPs),y
beq .11
jsr ERR.Print
bcs CS.RUN.EXIT.RTS
.11 ldy #hInputFile batch mode ?
lda (pData),y
beq .10
jmp CS.RUN.BATCH
.10 lda #0
sta (pData)
ldy #bSecureRead
sta (pData),y
.12 jsr PrintPrompt
bcs CS.RUN.EXIT.RTS
.1 >SYSCALL Sleep
>SYSCALL GetC
bcs .1 no char
jsr CS.CHARIN
lda (pData)
bpl .1
and #$7F
sta (pData)
jsr CmdBuffer.Normalize
lda (pData)
beq .12 Empty line
jsr HIS.Add
>LDYA pData
jsr Cmd.ExecYA
ldy #S.PS.RC
sta (pPs),y
.8 ldy #bEXIT
lda (pData),y
bne CS.RUN.EXIT
clc
rts
CS.RUN.EXIT lda #0
CS.RUN.EXIT.ERR sec
CS.RUN.EXIT.RTS rts
*--------------------------------------
CS.RUN.READ lda #0
sta (pData)
.1 >SYSCALL Sleep
>SYSCALL GetC
bcs .1 no char
jsr CS.CHARIN
lda (pData)
bpl .1
and #$7F
sta (pData)
>PUSHW pData
lda #VarBuffer
clc
adc pData
tay
lda pData+1
adc #0
>PUSHYA
>SYSCALL SetEnv
php
pha
ldy #VarBuffer
lda #0
sta (pData),y
pla
plp
rts
*--------------------------------------
CS.RUN.BATCH jsr TXT.ReadFile
bcs .9
jsr CmdBuffer.Normalize
lda (pData)
beq CS.RUN.BATCH Empty line
* jsr HIS.Add
>LDYA pData
jsr Cmd.ExecYA
ldy #S.PS.RC
sta (pPs),y
clc
rts
.9 jsr TXT.CloseFile
ldy #bExitOnEOF
lda (pData),y
bne CS.RUN.EXIT
clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.CHARIN tax
ldy #hInputFile Batch mode ?
lda (pData),y
beq .10
* Batch Mode
cpx #3 test Ctrl-c
bne .12
jsr TXT.CloseFile
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
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
.18 lda EscAscii,x
tax
.13 cpx #$20
bcs .1
jsr CS.CHARIN.CTRL
bra .8
.1 cpx #$7f
bne .2
jsr CmdBuffer.DEL
clc
rts
.2 lda (pData) CmdBuffer
cmp #CmdLine.MAX
beq .8
inc
sta (pData)
tay
txa
sta (pData),y
tax
ldy #bSecureRead
lda (pData),y
bne .8
txa
>SYSCALL PutCA
.8 clc
rts
*--------------------------------------
CS.CHARIN.CTRL cpx #13 CR
bne .10
txa
>SYSCALL PutCA
lda #10
>SYSCALL PutCA
lda (pData) CmdBuffer
ora #$80
sta (pData)
clc
rts
.10 cpx #$1B esc
bne .11
ldy #bEscMode
lda #$ff
sta (pData),y
clc
rts
.11 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 HIS.GetNext
clc
rts
.3 cpx #11 VT (up arrow)
bne .4
jsr HIS.GetPrev
clc
rts
.4 cpx #21 NAK (right arrow)
bne .8
clc
rts
.8 clc
rts
*--------------------------------------
CS.QUIT jsr HIS.Quit
ldy #hInputFile
lda (pData),y
beq .1
>SYSCALL FCloseA
.1
.8 clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
SetPWD ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtrA
>PUSHYA
>PUSHW L.ENV.PWD
>SYSCALL SetEnv
rts
*--------------------------------------
PrintPrompt >LDYA L.ENV.PS1
>SYSCALL GetEnvYA
>SYSCALL ExpandPStrYA
phx
>PUSHYA
pla
>SYSCALL FreeMemA
>LDYA L.MSG.PROMPT
>SYSCALL PPrintFYA
.9 rts
*--------------------------------------
* Remove extra SPACE & comment
*--------------------------------------
CmdBuffer.Normalize
>LDYA pData
>STYA ZPPtr1
lda (pData) empty line...quit
beq .9
tax Char count
ldy #0
.1 jsr CmdBuffer.Normalize.Next
beq .8 no more char, exit
cmp #' ' skip leading spaces
beq .1
cmp #'#' Comment ?
beq .8 ignore remaining chars
.3 iny add char to buffer
sta (pData),y
jsr CmdBuffer.Normalize.Next
beq .8
cmp #' '
bne .3
iny add One SPACE to buffer
sta (pData),y
.5 jsr CmdBuffer.Normalize.Next
beq .8
cmp #' '
beq .5 skip additional spaces
bne .3 no more space, add next word...
.8 tya
sta (pData)
.9 rts
CmdBuffer.Normalize.Next
txa
beq .8
dex
inc ZPPtr1
bne .1
inc ZPPtr1+1
.1 lda (ZPPtr1)
.8 rts
*--------------------------------------
CmdBuffer.CLR jsr CmdBuffer.DEL
bne CmdBuffer.CLR
rts
*--------------------------------------
CmdBuffer.DEL lda (pData)
beq .9
lda #8
>SYSCALL PutCA
lda (pData)
dec
sta (pData)
.9 rts
*--------------------------------------
.INB /A2OSX.SRC/SBIN/SHELL.S.CMD
.INB /A2OSX.SRC/SBIN/SHELL.S.ERR
.INB /A2OSX.SRC/SBIN/SHELL.S.HIS
.INB /A2OSX.SRC/SBIN/SHELL.S.TXT
*--------------------------------------
CS.END
*--------------------------------------
ENV.PATH >PSTR "PATH"
ENV.PWD >PSTR "PWD"
ENV.PS1 >PSTR "PS1"
CMDS >PSTR "CD"
>PSTR "DATE"
>PSTR "ECHO"
>PSTR "EXIT"
>PSTR "PAUSE"
>PSTR "PWD"
>PSTR "READ"
>PSTR "SET"
>PSTR "STARTPROC"
>PSTR "TIME"
.HS 00
*--------------------------------------
MSG.GREETINGS >PSTR "\r\nA2osX-Shell\r\n\r\n"
MSG.PROMPT >PSTR "%S$ "
MSG.ECHO >PSTR ">%S\r\n"
MSG.ERROR >PSTR "Err:%S [%h]\r\n"
MSG.PRINTENV >PSTR "%S=%S\r\n"
FMT.DATE >PSTR "%A, %B %d %Y"
FMT.TIME >PSTR "%H:%M:%S (%I:%M:%S%p)"
*--------------------------------------
.INB /A2OSX.SRC/X.ERRORS.S
*--------------------------------------
EscChars >PSTR "DBAC"
EscAscii .HS 04080A0B15
CMD .BS 256
ARGS .BS 256
TIME .BS S.TIME
STAT .BS S.STAT
hNEWPATH .BS 1
hCmdLine .BS 1
Cmd.Exec.Mode .BS 1
hFullPath .BS 1
hTextFile .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
CmdBuffer .BS CmdLine.MAX+1 (pData)
VarBuffer .BS VarLen.MAX+1
bEscMode .BS 1
bPause .BS 1
bExit .BS 1
bEcho .BS 1
bSecureRead .BS 1
bExitOnEOF .BS 1
hCmdHistory .BS 1
CmdHistory.IDX .BS 1
CmdHistory.END .BS 1
hInputFile .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S
ASM