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

@ -339,8 +339,6 @@ COUT.ExecEscSeq stz EscSeqParamCnt
.5 jmp (J.EscSequences,x) .5 jmp (J.EscSequences,x)
*-------------------------------------- *--------------------------------------
* PRIVATE
*--------------------------------------
RESET jsr CLRSCR RESET jsr CLRSCR
lda #0 lda #0
sta SCROLLTOP sta SCROLLTOP

View File

@ -114,6 +114,15 @@ AUTO 6
.EM .EM
*-------------------------------------- *--------------------------------------
* Global DATA Segment Access * Global DATA Segment Access
*--------------------------------------
.MA LEA.G
lda #]1
clc
adc pData
tay
lda pData+1
adc /]1
.EM
*-------------------------------------- *--------------------------------------
.MA LDA.G .MA LDA.G
ldy #]1 ldy #]1

View File

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

View File

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

View File

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