Kernel 0.92+

This commit is contained in:
Rémy GIBERT 2019-03-13 11:37:05 +00:00
parent 902af27470
commit c0c16c4215
4 changed files with 355 additions and 27 deletions

Binary file not shown.

View File

@ -24,6 +24,7 @@ hBuf .BS 1
FieldNum .BS 1
StartChar .BS 1
EndChar .BS 1
Separator .BS 1
ZS.END
.ED
*--------------------------------------
@ -55,14 +56,12 @@ CS.INIT clc
rts
*--------------------------------------
CS.RUN stz ArgCount
lda #C.SPACE
sta Separator
.10 inc ArgCount
lda ArgCount
>SYSCALL ArgV
.10 jsr CS.RUN.NextArg
bcs .8
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
beq .1
@ -84,12 +83,20 @@ CS.RUN stz ArgCount
.3 txa
lsr
beq .98 HELP
sta OptionIdx
beq .98 -H
cmp #4 -S
bne .4
inc ArgCount
lda ArgCount
>SYSCALL ArgV
jsr CS.RUN.NextArg
bcs .97
lda (ZPPtr1)
sta Separator
bra .10
.4 sta OptionIdx
jsr CS.RUN.NextArg
bcs .97
>SYSCALL atoi
@ -160,7 +167,7 @@ CS.RUN.OUT lda FieldNum
lda (ZPBufPtr),y
beq CS.RUN.PRINTCR
cmp #C.SPACE
cmp Separator
beq .1
dec FieldNum
@ -170,7 +177,7 @@ CS.RUN.OUT lda FieldNum
lda (ZPBufPtr),y
beq CS.RUN.PRINTCR
eor #C.SPACE
eor Separator
bne .2
bra .1
@ -181,7 +188,7 @@ CS.RUN.OUT lda FieldNum
.6 iny
lda (ZPBufPtr),y
beq .8
eor #C.SPACE
eor Separator
bne .6
sta (ZPBufPtr),y
@ -236,6 +243,15 @@ CS.RUN.OUT.MN ldy #$ff
sec
rts
*--------------------------------------
CS.RUN.NextArg inc ArgCount
lda ArgCount
>SYSCALL ArgV
bcs .9
>STYA ZPPtr1
.9 rts
*--------------------------------------
CS.RUN.AddYToBufPtr
tya
clc
@ -259,13 +275,14 @@ CS.DOEVENT sec
*--------------------------------------
CS.END
*--------------------------------------
OptionList >PSTR "HhFfMmNn"
OptionList >PSTR "HhFfMmNnSs"
*--------------------------------------
MSG.USAGE .AS "Usage : CUT "line of text"\r\n"
.AS " -H : This help screen\r\n"
.AS "-F nn : Output field nn, sep=SPACE\r\n"
.AS "-F nn : Output field nn\r\n"
.AS "-M nn : Output starting at nn\r\n"
.AS "-N nn : Output Ending at nn"
.AS "-N nn : Output Ending at nn\r\n"
.AS "-S ch : Change default SPACE separator to 'ch'"
MSG.CRLF .AZ "\r\n"
*--------------------------------------
.DUMMY

289
BIN/GREP.S.txt Normal file
View File

@ -0,0 +1,289 @@
NEW
PREFIX
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/GREP
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/KERNEL.I
.INB INC/MLI.I
.INB INC/MLI.E.I
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ArgIndex .BS 1
ArgPattern .BS 1
ZPPTR1 .BS 2
ZPPatternPtr .BS 2
ZPBufPtr .BS 2
hFile .BS 1
hBuf .BS 1
LineNum .BS 2
char .BS 1
bIgnoreCase .BS 1
bLineNum .BS 1
ZS.END
.ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0 S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
.DA #16 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.CRLF .DA MSG.CRLF
L.MSG.NUMLINE .DA MSG.NUMLINE
.DA 0
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
CS.RUN stz ArgIndex
stz ArgPattern
stz hFile
.10 jsr CS.RUN.NextArg
bcs .8
lda (ZPPtr1)
cmp #'-'
beq .1
lda ArgPattern
bne .11
lda ArgIndex
sta ArgPattern
>LDYA ZPPtr1
>STYA ZPPatternPtr
bra .10
.11 lda hFile
bne .97
>LDYA ZPPtr1
jsr CS.RUN.OPEN
bcs .9
sta hFile
bra .10
.1 ldy #1
lda (ZPPtr1),y
ldx #OptionList.Cnt-1
.2 cmp OptionList,x
beq .3
dex
bpl .2
bra .97
.3 txa
beq .98
lsr
tax
lda #$80
sta bIgnoreCase-1,x
bra .10 scan for any other args
.97 lda #E.SYN
.98 pha
>PUSHBI 0
>LDYA L.MSG.USAGE
>SYSCALL printf
pla
sec
.9 rts
.8 lda hFile
bne .80
ldy #S.PS.hStdIn
lda (pPS),y
tax
lda OF.Table.hFD-1,x
>SYSCALL GetMemPtr
>STYA ZPPtr1
lda (ZPPtr1)
cmp #S.FD.T.PIPE
bne .97
.80 >LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA ZPBufPtr
stx hBuf
stz LineNum
stz LineNum+1
CS.RUN.LOOP >SLEEP
>PUSHWI 256
>PUSHW ZPBufPtr
lda hFile
bne .1
ldy #S.PS.hStdIn
lda (pPS),y
.1 >SYSCALL fgets
bcs .9
inc LineNum
bne .2
inc LineNum+1
.2 jsr CS.RUN.PRINT
bcc CS.RUN.LOOP
rts
.9 cmp #MLI.E.EOF
bne .99
lda #0 Exit with no Error
.99 sec
rts
*--------------------------------------
CS.RUN.OPEN pha
>PUSHWI 0 Aux type
>PUSHBI S.FI.T.TXT
>PUSHBI O.RDONLY+O.TEXT
pla
>SYSCALL FOpen
bcs .9
sta hFile
.9 rts
*--------------------------------------
CS.RUN.PRINT >LDYA ZPBufPtr
>STYA ZPPtr1
.1 lda (ZPPtr1)
beq .8
ldy #$ff
.2 iny
lda (ZPPtr1),y
bne .3
lda (ZPPatternPtr),y
bne .8
.3 lda (ZPPatternPtr),y
beq .6
jsr CS.RUN.toUpper
sta char
lda (ZPPtr1),y
jsr CS.RUN.toUpper
cmp char
beq .2
inc ZPPtr1
bne .1
inc ZPPtr1+1
bra .1
.6 lda bLineNum
bpl .7
>PUSHW LineNum
>PUSHBI 2
>LDYA L.MSG.NUMLINE
>SYSCALL printf
bcs .9
.7 >LDYA ZPBufPtr
>SYSCALL puts
rts
.8 clc
.9 rts
*--------------------------------------
CS.RUN.NextArg inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs .9
>STYA ZPPtr1
.9 rts
*--------------------------------------
CS.RUN.toUpper bit bIgnoreCase
bpl .9
cmp #'a'
bcc .9
cmp #'z'+1
bcs .9
eor #$20
.9 rts
*--------------------------------------
CS.QUIT lda hBuf
beq .1
>SYSCALL FreeMem
.1 lda hFILE
beq .2
>SYSCALL FClose
.2
.8 clc
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.END
*--------------------------------------
OptionList .AZ "HhIiNn"
OptionList.Cnt .EQ *-OptionList
*--------------------------------------
MSG.USAGE .AS "Usage : GREP <pattern> <File> or CMD|GREP <pattern>\r\n"
.AS " -H : This help screen\r\n"
.AS " -I : Ignore Case\r\n"
.AS " -N : Print line Number"
MSG.CRLF .AZ "\r\n"
MSG.NUMLINE .AZ "%5D:"
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END
.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/GREP.S
ASM

View File

@ -27,9 +27,14 @@
| Name | Status | Comment |
| ---- | ------ | ------- |
| BREAK | | |
| CD | Working | Improved syntax : now, 'CD ../BIN' works |
| conditions | Working |[ -d direxists ] |
| \<value\> | Working | $VAR \| string \| "string with SPACE" \| 123 \| -456 |
| \<expression\> | Working | \<value\> [\<op\> \<value\>] ... |
| \<op\> | Working | \+ signed int32 add |
| | Working | \- signed int32 sub |
| | | \* |
| | | div |
| | | mod |
| \<condition\> | Working |[ -d direxists ] |
| | | [ -e fileordirexists ] |
| | | [ -f fileexists ] |
| | | [ -n $VAR variable is not empty ] |
@ -46,32 +51,39 @@
| | | [ int32 -le int32 ] |
| | | [ int32 -gt int32 ] |
| | | [ int32 -ge int32 ] |
| CONTINUE | | |
| FUNC | | FUNC fonction_name {body} |
| RETURN | | Exit function with return code |
| SWITCH | | SWITCH <expression> |
| CASE | | CASE <expression> |
| BREAK | | Exit SWITCH/CASE |
| DEFAULT | | |
| END | | End of SWITCH Statement |
| CD | Working | Improved syntax : now, 'CD ../BIN' works |
| DATE | Working | |
| ECHO | Working | \b,\e,\f,\n,\\\ and \\% supported |
| | | -N : Suppress \r\n |
| ELSE | Working | Optional branch for IF block |
| EXIT | Working | exit shell |
| FI | Working | Terminator for IF block |
| IF | Working | [ (condition) ] |
| IF | Working | [ \<condition\> ] |
| LOOP | Working | Terminator for WHILE block |
| MD | Working | Create a directory |
| NOHUP | Working | Start a process with PPID=PS0 (Daemon) |
| PAUSE | Working | Wait until CR |
| POPD | Working | Restore previously saved working directory |
| PUSHD | Working | Save actual working directory |
| | | PUSHD <dir> do aslo a CD to <dir> |
| | | PUSHD \<dir\> do also a CD to \<dir\> |
| PWD | Working | Print Working Directory |
| RD | Working | Delete an empty directory |
| READ | Working | -S : no echo (password) |
| | | -P : "prompt message" |
| REN | Working | Rename a file, directory or volume |
| SET | Working | -X toggle debug mode |
| | | -C toggle Control-C break mode |
| SET | Working | -X : toggle debug mode |
| | | -C : toggle Control-C break mode |
| SHIFT | Working | Remove $1 from cmd line |
| SLEEP | Working | Wait <count> 10th sec |
| SLEEP | Working | Wait \<count\> 10th sec |
| TIME | Working | |
| WHILE | Working | [ (condition) ] |
| WHILE | Working | [ \<ondition\> ] |
## Shell variables:
@ -126,6 +138,12 @@ note : '$VAR' does NOT expand Variable
| CAT | Working | -A : Show All non printable caracters | 0.92 |
| | | -N : Number all output lines | |
| | | -S : Suppress repeated empty output lines | |
| CUT | Working | CUT \<opt\> "line" or CMD\|CUT \<opt\> | 0.92 |
| | | -H : This help screen | |
| | | -F nn : Output field nn | |
| | | -M nn : Output starting at nn | |
| | | -N nn : Output Ending at nn | |
| | | -S ch : Change default SPACE separator to 'ch' | |
| CHGRP | In Progress | -C : Continue On Error | 0.9 |
| | | -R : Recurse subdirectories | |
| CHMOD | In Progress | -C : Continue On Error | 0.9 |
@ -142,6 +160,10 @@ note : '$VAR' does NOT expand Variable
| FORMAT | In Progress | FORMAT \<BLOCKDEV\> [VOLUME.NAME] | 0.92 |
| | | -L : Low-Level Format *not currently supported | |
| | | -1..9 : Catalog Size (block count) | |
| GREP | Working | GREP \<opt\> PATTERN FILE or CMD\|GREP \<opt\> PATTERN | 0.92 |
| | | -H : This help screen | |
| | | -I : Ignore Case | |
| | | -N : Print line Number | |
| KILL | Working | KILL \<signal\> PID | 0.92 |
| | | -0 : No Signal | |
| | | -1 : SIGQUIT | |
@ -155,7 +177,7 @@ note : '$VAR' does NOT expand Variable
| MD5 | Working | MD5 \[ -D : String \| file \] | 0.92 |
| MEM | Working | Old dump behavior is now MEMDUMP. New MEM command displays MEMSTAT (Main, Aux & Kernel Memory) | 0.92 |
| MKDIR | Working | Make Directory| 0.92 |
| MORE | Working | MORE \<File\> | 0.92 |
| MORE | Working | MORE \<File\> or CMD\|MORE \<opt\> | 0.92 |
| | | -H : This help screen | |
| | | -N : Number all output lines | |
| | | -P : Page mode, no scroll | |