Kernel 0.9.1 : Code reorganization & move to CSTR (SHELL)

This commit is contained in:
Rémy GIBERT 2017-09-15 17:16:04 +02:00
parent 3ceb61c354
commit 16d47d5902
7 changed files with 199 additions and 185 deletions

Binary file not shown.

Binary file not shown.

View File

@ -12,7 +12,7 @@ AUTO 6
.INB /A2OSX.BUILD/INC/A2OSX.I
.INB /A2OSX.BUILD/INC/IO.I
.INB /A2OSX.BUILD/INC/MLI.ERR.I
.INB /A2OSX.BUILD/INC/NET.TELNET.I
.INB /A2OSX.BUILD/INC/NET.TELNET.I
*--------------------------------------
CURSOR.BLINK.SPEED .EQ 8
ESCSEQ.MAXLEN .EQ 16
@ -199,7 +199,7 @@ FSOUT ldx CH
inc CH
.8 clc
rts
rts
*--------------------------------------
COUT.Ctrl ldx #CtrlChars.Cnt-1
@ -217,11 +217,11 @@ COUT.Ctrl ldx #CtrlChars.Cnt-1
*--------------------------------------
COUT.IACMode tax
bmi .8 go store 2nd byte (WILL, WONT....)
* 3rd byte...option...
* ignore all for now
* reset bIACMode
.8 sta bIACMode
clc
rts
@ -230,7 +230,7 @@ COUT.EscMode bit bEscModeCSI
bmi COUT.EscModeCSI
cmp #'['
bne .1
dec bEscModeCSI
stz EscSeq
clc
@ -250,7 +250,7 @@ COUT.EscMode bit bEscModeCSI
bne .2
clc
rts
.3 jmp (J.EscCodes,x)
*--------------------------------------
COUT.EscModeCSI inc EscSeq
@ -272,12 +272,12 @@ COUT.ExecEscSeq stz EscSeqParamCnt
.10 stz EscSeqParamTmp
stz EscSeqParamTmp+1
.1 inx
lda EscSeq,x
jsr IsDigit
bcs .2
dec bEscSeqInNum
and #$0F
pha
@ -303,24 +303,24 @@ COUT.ExecEscSeq stz EscSeqParamCnt
bcc .1
inc EscSeqParamTmp+1
bra .1
.2 bit bEscSeqInNum
bpl .3
stz bEscSeqInNum
lda #255
ldy EscSeqParamTmp+1
bne .21
lda EscSeqParamTmp
.21 ldy EscSeqParamCnt
sta EscSeqParam,y
inc EscSeqParamCnt
.3 lda EscSeq,x
cmp #';'
beq .10
stz bEscModeCSI
stz bEscMode
@ -336,11 +336,9 @@ COUT.ExecEscSeq stz EscSeqParamCnt
bne .4
clc
rts
.5 jmp (J.EscSequences,x)
*--------------------------------------
* PRIVATE
*--------------------------------------
RESET jsr CLRSCR
lda #0
sta SCROLLTOP
@ -372,16 +370,16 @@ BS ldx CH
beq .1
dec CH
bra .3
.1 ldy CV
bne .2
clc
rts
.2 lda #79
sta CH
dec CV
.3 lda #$20
ora INVFLG
ldx CH
@ -392,18 +390,18 @@ ClrScr stz CH
stz CV
ldx #23
.1 lda BASEL,x
sta ZPBaseL1
lda BASEH,x
sta ZPBaseL1+1
lda #" "
php
sei
sta SETWRITEAUX
ldy #39
.2 sta (ZPBaseL1),y
dey
@ -436,7 +434,7 @@ LF ldy CV
rts
*--------------------------------------
SCROLL.UP ldx SCROLLTOP
.1 lda BASEL,x
sta ZPBaseL1
lda BASEH,x
@ -446,7 +444,7 @@ SCROLL.UP ldx SCROLLTOP
sta ZPBaseL2
lda BASEH,x
sta ZPBaseL2+1
jsr COPY.L2toL1
cpx SCROLLBOT
@ -455,14 +453,14 @@ SCROLL.UP ldx SCROLLTOP
CLREOL ldx CH
ldy #80
bra CLR
CLRLINE ldx #0
ldy #80
bra CLR
CLRSOL ldx #0
ldy CH
CLR sty .2+1
.1 lda #" "
@ -475,7 +473,7 @@ CLR sty .2+1
rts
*--------------------------------------
SCROLL.DN ldx SCROLLBOT
.1 lda BASEL,x
sta ZPBaseL1
lda BASEH,x
@ -485,30 +483,30 @@ SCROLL.DN ldx SCROLLBOT
sta ZPBaseL2
lda BASEH,x
sta ZPBaseL2+1
jsr COPY.L2toL1
cpx SCROLLTOP
bne .1
clc
rts
*--------------------------------------
Esc.DispAttr ldx EscSeqParamCnt
beq .8
.1 lda EscSeqParam-1,x
bne .2
jsr RESETATTR
bra .7
.2 cmp #7
bne .8
stz INVFLG
.7 dex
bne .1
.8 clc
rts
*--------------------------------------

View File

@ -114,6 +114,15 @@ AUTO 6
.EM
*--------------------------------------
* Global DATA Segment Access
*--------------------------------------
.MA LEA.G
lda #]1
clc
adc pData
tay
lda pData+1
adc /]1
.EM
*--------------------------------------
.MA LDA.G
ldy #]1
@ -141,7 +150,7 @@ AUTO 6
lda (pData),y
inc
sta (pData),y
:1 .EQ *
.EM
*--------------------------------------

View File

@ -17,11 +17,11 @@ CMD.Init >LDYAI CmdLine.MAX+1
Cmd.Parse >LDYA ZPCMDBuf
>STYA ZPPtr1
ldy #0
lda (ZPCMDBuf) empty line...quit
beq .9
ldy #0
.1 jsr Cmd.Parse.NextC
beq .8 no more char, exit
@ -52,8 +52,10 @@ Cmd.Parse >LDYA ZPCMDBuf
.8 lda #0
sta (ZPCMDBuf),y
.9 rts
.9 tya
>STA.G CmdBuflen
rts
Cmd.Parse.NextC lda (ZPPtr1)
beq .8
@ -68,7 +70,6 @@ Cmd.Parse.NextC lda (ZPPtr1)
Cmd.Exec lda #0
>STA.G CMD.bStartProc
>STA.G CMD.hFullpath
>STA.G CMD.hExtCmdLine
>LDYA ZPCMDBuf
>SYSCALL ExpandStr.YA
@ -77,27 +78,29 @@ Cmd.Exec lda #0
txa
>STA.G CMD.hCmdLine
jsr Cmd.Exec.Split
>LDYA L.INTCMDS
>STYA ZPCMDBuf we use ZPCMDBuf as a temp Ptr
>STYA ZPPtr2
ldx #0
.3 lda (ZPCMDBuf)
.3 lda (ZPPtr2)
beq Cmd.Exec.EXT Array Ending 0, must be an external Cmd....
ldy #$ff
.4 iny
lda (ZPCMDBuf),y
lda (ZPPtr2),y
bne .41 End of string in array
lda (ZPPtr1),y Get CMD char...
beq .8 both end with 0, found!
cmp #' '
beq .8 we reached space between CMD & ARGS....
.41 lda (ZPPtr1),y Get CMD char...
beq .61 end of CMD.....too short...
cmp #' '
beq .61 we reached space between CMD & ARGS....
cmp #'a' To Uppercase
bcc .5
@ -105,11 +108,11 @@ Cmd.Exec lda #0
bcs .5
eor #$20
.5 cmp (ZPCMDBuf),y
.5 cmp (ZPPtr2),y
beq .4
.61 iny
lda (ZPCMDBuf),y
lda (ZPPtr2),y
bne .61
.7 inx
@ -117,72 +120,36 @@ Cmd.Exec lda #0
tya
sec
adc ZPCMDBuf
sta ZPCMDBuf
adc ZPPtr2
sta ZPPtr2
bcc .3
inc ZPCMDBuf+1
inc ZPPtr2+1
bra .3
.8 jmp (J.INTCMDS,x) Found an internal Cmd...
.8 jsr Cmd.Exec.Split X unmodified
jmp (J.INTCMDS,x) Found an internal Cmd...
*--------------------------------------
Cmd.Exec.Done php
pha
>LDA.G CMD.hCmdLine
>SYSCALL FreeMem.A
>LDA.G CMD.hExtCmdLine
>LDA.G CMD.hFullpath
beq .1
>SYSCALL FreeMem.A
.1 >LDA.G CMD.hFullpath
beq .2
>SYSCALL FreeMem.A
.2 pla
.1 pla
plp
rts
*--------------------------------------
Cmd.Exec.Split ldy #$ff CMD Len
.1 iny
lda (ZPPtr1),y Get CMD char...
beq .2
cmp #' ' we reached blank between CMD ARGS
bne .1
lda #0
sta (ZPPtr1),y Cut CMD with the ending 0
iny
.2 tya Y=CMD len+0, if ARGS="" Y=
clc
adc ZPPtr1
sta ZPPtr2
lda ZPPtr1+1
adc #0
sta ZPPtr2+1 ZPPtr2->ARGS or CMD ending 0 if empty
rts
*--------------------------------------
* ZPPtr1->CMD
* ZPPtr2->ARGS
*--------------------------------------
Cmd.Exec.EXT >LDYAI 256
>SYSCALL GetMem.YA
bcs .99
>STYA ZPCMDBuf
txa
>STA.G CMD.hExtCmdLine
lda #0
sta (ZPCMDBuf)
Cmd.Exec.EXT jsr Cmd.Exec.Split
lda (ZPPtr1)
cmp #'/' Command line is already full path, no search
bne .1
>PUSHW L.STAT
>LEA.G CMD.Stat
>PUSHYA
>PUSHW ZPPtr1
>SYSCALL STAT
bcs Cmd.Exec.Done
@ -209,7 +176,8 @@ Cmd.Exec.EXT >LDYAI 256
txa
>STA.G CMD.hFullpath
lda STAT+S.STAT.P.TYPE
ldy #CMD.Stat+S.STAT.P.TYPE
lda (pData),y
cmp #$04 TXT File ?
beq Cmd.Exec.EXT.TXT
cmp #$06 BIN File ?
@ -264,7 +232,8 @@ Cmd.Exec.EXT.Search
>PUSHYA push search list
>PUSHW ZPPtr1 push CMD
>PUSHW ZPCMDBuf push dest full path
>PUSHW L.STAT
>LEA.G CMD.Stat
>PUSHYA
>SYSCALL FileSearch
rts
*--------------------------------------
@ -292,7 +261,8 @@ Cmd.Exec.PWD ldy #S.PS.hPREFIX
>SYSCALL PrintF.YA
jmp Cmd.Exec.Done
Cmd.Exec.CD1 stz UsrBuf256
Cmd.Exec.CD1 lda #0
sta (ZPCMDBuf)
cmp #'/' Full Path?
beq .1
@ -301,47 +271,57 @@ Cmd.Exec.CD1 stz UsrBuf256
lda (pPs),y
>SYSCALL GetMemPtr.A
>PUSHYA
>PUSHWI UsrBuf256
>PUSHW ZPCMDBuf
>SYSCALL StrCpy
.1 >PUSHW ZPPTR2 Append ARG to buffer
>PUSHWI UsrBuf256
>PUSHW ZPCMDBuf
>SYSCALL StrCat
lda #'/'
ldx UsrBuf256
cmp UsrBuf256,x Ending '/' ?
ldy #$ff
ldx #'/'
.10 tax
iny
lda (ZPCMDBuf),y
bne .10
cpx #'/'
beq .2
lda #'/'
sta UsrBuf256+1,x no, add one...
inc UsrBuf256
sta (ZPCMDBuf),y
iny
lda #0
sta (ZPCMDBuf),y
.2 ldx #0 path is something like : /dir1/../dir2/
.2 ldy #$ff path is something like : /dir1/../dir2/
.3 ldy #0 reset char counter
.3 ldx #0 reset char counter
.4 cpx UsrBuf256
.4 iny
lda (ZPCMDBuf),y
beq .8
inx
lda UsrBuf256,x
cmp #'/'
beq .5
iny char=char+1!!!
bne .4
.5 txa any char count?
bne .51 no, start counting...
inx
bra .4
.5 tya any char count?
beq .4 no, start counting...
cpy #2 do we have /xx/?
.51 inx
cpx #2 do we have /xx/?
bne .3 no, skip this token
lda #'.'
cmp UsrBuf256-1,x /yy/x./ ?
dey
lda (ZPCMDBuf),y /yy/x./ ?
dey
cmp (ZPCMDBuf),y /yy/../ ?
bne .3
cmp UsrBuf256-2,x /yy/../ ?
bne .3
cpx #4 /../ ?
cpy #3 /../ ?
beq Cmd.Exec.ERRSYN illegal
txa
@ -370,12 +350,14 @@ Cmd.Exec.CD1 stz UsrBuf256
.8 cpx #1
beq .80 we have '/' go change prefix
>PUSHW L.STAT
>LEA.G CMD.Stat
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL STAT
bcs .9
lda STAT+S.STAT.P.TYPE
ldy #CMD.Stat+S.STAT.P.TYPE
lda (pData),y
cmp #$0F Directory ?
bne Cmd.Exec.ERRSYN
@ -410,7 +392,6 @@ Cmd.Exec.STARTPROC
>LDYA ZPPTR2
>STYA ZPPTR1
jsr Cmd.Exec.Split
jmp Cmd.Exec.EXT
*--------------------------------------
Cmd.Exec.SET lda (ZPPTR2)
@ -511,23 +492,23 @@ Cmd.Exec.SETVAR ldy #0
*--------------------------------------
Cmd.Exec.DATE sec
.HS 90 bcc
Cmd.Exec.TIME clc
php
>LDYA L.TIME
>LEA.G CMD.Time
>SYSCALL TimeYA
>PUSHWI UsrBuf256
>PUSHWI ZPCMDBuf
plp
bcc .1
>PUSHW L.FMT.DATE
bra .2
.1 >PUSHW L.FMT.TIME
.2 >PUSHW L.TIME
.2 >LEA.G CMD.Time
>PUSHYA
>SYSCALL StrFTime
>LDYAI UsrBuf256
>LDYAI ZPCMDBuf
>SYSCALL PrintF.YA
bcs Cmd.Exec.ECHO.END
bra Cmd.Exec.ECHO.CR
@ -545,7 +526,6 @@ Cmd.Exec.ECHO.CR
lda #10
>SYSCALL PutChar.A
Cmd.Exec.ECHO.END
jmp Cmd.Exec.Done
*--------------------------------------
@ -661,6 +641,28 @@ Cmd.Exec.EXIT lda #$FF
clc
jmp Cmd.Exec.Done
*--------------------------------------
Cmd.Exec.Split ldy #$ff CMD Len
.1 iny
lda (ZPPtr1),y Get CMD char...
beq .2
cmp #' ' we reached blank between CMD ARGS
bne .1
lda #0
sta (ZPPtr1),y Cut CMD with the ending 0
iny
.2 tya Y=CMD len+0, if ARGS="" Y=
clc
adc ZPPtr1
sta ZPPtr2
lda ZPPtr1+1
adc #0
sta ZPPtr2+1 ZPPtr2->ARGS or CMD ending 0 if empty
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SBIN/SHELL.S.CMD
LOAD /A2OSX.SRC/SBIN/SHELL.S

View File

@ -156,7 +156,7 @@ HIS.SetBuf jsr CmdLine.CLR
sta (ZPCMDBuf),y
dey
bpl .1
jmp CmdLine.SET
jmp CmdLine.PRINT
*--------------------------------------
HIS.Quit >LDA.G HIS.hBuf
beq .9

View File

@ -23,7 +23,7 @@ ZPCSHSymbols .EQ ZPBIN+10
ZPCSHData .EQ ZPBIN+12
ZPCSHStack .EQ ZPBIN+14
*--------------------------------------
CmdLine.MAX .EQ 127
CmdLine.MAX .EQ 255
VarLen.MAX .EQ 15
CSH.Stack.MAX .EQ 15
@ -64,8 +64,6 @@ L.MSG.CSHERR .DA MSG.CSHERR
L.ENV.PATH .DA ENV.PATH
L.ENV.PWD .DA ENV.PWD
L.ENV.PS1 .DA ENV.PS1
L.TIME .DA TIME
L.STAT .DA STAT
L.FMT.DATE .DA FMT.DATE
L.FMT.TIME .DA FMT.TIME
L.INTCMDS .DA INTCMDS
@ -142,15 +140,12 @@ CS.RUN >LDA.G bReadMode READ Command ?
beq .10
jmp CS.RUN.BATCH
* Interactive Mode
*--------------------------------------
.10 >LDA.G hCmdBuf Get the buffer
>SYSCALL GetMemPtr.A
>STYA ZPCMDBuf
lda #0 reset it
sta (ZPCMDBuf)
>STA.G bCmdBufexec
jsr CmdLine.RESET reset it
>STA.G bSecureRead Clear password mode
.12 jsr PrintPrompt
@ -162,19 +157,22 @@ CS.RUN >LDA.G bReadMode READ Command ?
jsr CS.CHARIN
>LDA.G bCmdBufexec Something to execute ?
>LDA.G bCmdBufExec Something to execute ?
bpl .1
jsr Cmd.Parse
jsr CMD.Parse
>LDA.G CmdBuflen
beq .12 Empty line
jsr HIS.Add
jsr Cmd.Exec
jsr CMD.Exec
bcs .2
lda #0
ldy #S.PS.RC
.2 ldy #S.PS.RC
sta (pPs),y
>LDA.G bExit
@ -200,7 +198,7 @@ CS.RUN.READ >LDA.G hCmdBuf Get the buffer
jsr CS.CHARIN
>LDA.G bCmdBufexec
>LDA.G bCmdBufExec
bpl .1
>PUSHW ZPCMDBuf
@ -216,30 +214,12 @@ CS.RUN.READ >LDA.G hCmdBuf Get the buffer
rts
*--------------------------------------
CS.RUN.BATCH jsr CSH.Run
bcs .9
bcc .7
cmp #MLI.ERR.EOF
beq .9
>LDA.G bCmdBufexec
bpl .8 Empty line....nothing to do....
jsr Cmd.Parse
lda (ZPCMDBuf)
beq .8
jsr Cmd.Exec
.8 ldy #S.PS.RC
sta (pPs),y
clc
rts
.9 cmp #MLI.ERR.EOF
bne .7
lda #0
sec
rts
.7 pha
pha
ldy #CSH.BufPtr+1
>PUSHB (pData),y
@ -251,23 +231,20 @@ CS.RUN.BATCH jsr CSH.Run
jsr CSH.RestorePtr
.90 jsr CSH.GetChar
bcs .92
jsr CSH.GetChar
bcs .2
>SYSCALL PutChar.A
.91 jsr CSH.GetNextChar
bcs .92
.1 jsr CSH.GetNextChar
bcs .2
cmp #13
beq .92
beq .2
>SYSCALL PutChar.A
bra .91
bra .1
.92 pla
bra .99
.2 pla
.98 lda #0
.99 ldy #S.PS.RC
ldy #S.PS.RC
sta (pPs),y
pha
@ -277,6 +254,28 @@ CS.RUN.BATCH jsr CSH.Run
pla
rts
.7 >LDA.G bCmdBufExec
bpl .8 Empty line....nothing to do....
jsr Cmd.Parse
lda (ZPCMDBuf)
beq .8
jsr Cmd.Exec
bcs .8
lda #0
.8 ldy #S.PS.RC
sta (pPs),y
clc
rts
.9 lda #0
sec
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9
@ -363,6 +362,9 @@ CS.CHARIN tax Save Char
txa
ply
sta (ZPCMDBuf),y
iny
lda #0
sta (ZPCMDBuf),y
>LDA.G bSecureRead
bne .8
@ -481,10 +483,9 @@ CmdLine.CLR ldy #0
iny
bne .1
jsr CmdLine.SET
jsr CmdLine.PRINT
lda #0
sta (ZPCMDBuf)
jmp CmdLine.RESET
.9 rts
*--------------------------------------
@ -501,9 +502,15 @@ CmdLine.DEL >LDA.G CmdBuflen
>SYSCALL PutChar.A
.9 rts
*--------------------------------------
CmdLine.SET >LDYA ZPCMDBuf
CmdLine.PRINT >LDYA ZPCMDBuf
>SYSCALL PrintF.YA
rts
*--------------------------------------
CmdLine.RESET lda #0
sta (ZPCMDBuf)
>STA.G CmdBuflen
>STA.G bCmdBufExec
rts
*--------------------------------------
.INB /A2OSX.SRC/SBIN/SHELL.S.CMD
.INB /A2OSX.SRC/SBIN/SHELL.S.CSH
@ -551,8 +558,6 @@ FMT.TIME >CSTR "%H:%M:%S (%I:%M:%S%p)"
*--------------------------------------
EscChars >PSTR "DBAC"
EscAscii .HS 04080A0B15
TIME .BS S.TIME
STAT .BS S.STAT
CSH.TSIZE .HS 0001020405 00,CHAR,INT,LONG,FLOAT....
CSH.ACCT .BS 1
CSH.ACC .BS 5
@ -579,10 +584,10 @@ Sleep .BS 4
CMD.hCmdLine .BS 1
CMD.hFullpath .BS 1
CMD.hExtCmdLine .BS 1
CMD.bStartProc .BS 1
CMD.VarName .BS VarLen.MAX+1
CMD.Stat .BS S.STAT
CMD.Time .BS S.TIME
HIS.hBuf .BS 1
HIS.BufIndex .BS 1