mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 15:08:05 +11:00
ed: take filename as an argument
This hard-binds ed to the filesystem (I liked the idea of working only with blockdevs though...), but this is necessary for the upcoming `w` command. We need some kind of way to tell the destination to write to truncate itself. This only has a meaning in the filesystem, but it's necessary to let the file know that its registered file size has possibly shrunk. I thought of alternatives that would have allowed me to keep ed blkdev-centered, but they were all too hackish to my own taste. Hence, this new hard-bind on files.
This commit is contained in:
parent
fe15bafeca
commit
942d2a952d
@ -22,8 +22,9 @@ not listed here are either bugs or simply aren't implemented yet.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
`ed` is invoked from the shell with no argument. ed takes no argument.
|
`ed` is invoked from the shell with a single argument: the name of the file to
|
||||||
It reads from the currently selected blkdev and writes to it.
|
edit. If the file doesn't exist, `ed` errors out. If it exists, a prompt is
|
||||||
|
shown.
|
||||||
|
|
||||||
In normal mode, `ed` waits for a command and executes it. If the command is
|
In normal mode, `ed` waits for a command and executes it. If the command is
|
||||||
invalid, a line with `?` is printed and `ed` goes back to waiting for a command.
|
invalid, a line with `?` is printed and `ed` goes back to waiting for a command.
|
||||||
|
@ -40,8 +40,8 @@ bufInit:
|
|||||||
ld ix, BUF_LINES
|
ld ix, BUF_LINES
|
||||||
ld bc, 0 ; line count
|
ld bc, 0 ; line count
|
||||||
.loop:
|
.loop:
|
||||||
call blkTell ; --> HL
|
call ioTell ; --> HL
|
||||||
call blkGetC
|
call ioGetC
|
||||||
jr nz, .loopend
|
jr nz, .loopend
|
||||||
ld (ix), l
|
ld (ix), l
|
||||||
inc ix
|
inc ix
|
||||||
|
@ -6,11 +6,62 @@
|
|||||||
.equ IO_MAXLEN 0x7f
|
.equ IO_MAXLEN 0x7f
|
||||||
|
|
||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
|
; Handle of the target file
|
||||||
|
.equ IO_FILE_HDL IO_RAMSTART
|
||||||
|
; block device targeting IO_FILE_HDL
|
||||||
|
.equ IO_BLK IO_FILE_HDL+FS_HANDLE_SIZE
|
||||||
; Buffer for lines read from I/O.
|
; Buffer for lines read from I/O.
|
||||||
.equ IO_LINE IO_RAMSTART
|
.equ IO_LINE IO_BLK+BLOCKDEV_SIZE
|
||||||
.equ IO_RAMEND IO_LINE+IO_MAXLEN+1 ; +1 for null
|
.equ IO_RAMEND IO_LINE+IO_MAXLEN+1 ; +1 for null
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
|
|
||||||
|
; Given a file name in (HL), open that file in (IO_FILE_HDL) and open a blkdev
|
||||||
|
; on it at (IO_BLK).
|
||||||
|
ioInit:
|
||||||
|
call fsFindFN
|
||||||
|
ret nz
|
||||||
|
ld ix, IO_FILE_HDL
|
||||||
|
call fsOpen
|
||||||
|
ld de, IO_BLK
|
||||||
|
ld hl, .blkdev
|
||||||
|
jp blkSet
|
||||||
|
.fsGetC:
|
||||||
|
ld ix, IO_FILE_HDL
|
||||||
|
jp fsGetC
|
||||||
|
.fsPutC:
|
||||||
|
ld ix, IO_FILE_HDL
|
||||||
|
jp fsPutC
|
||||||
|
.blkdev:
|
||||||
|
.dw .fsGetC, .fsPutC
|
||||||
|
|
||||||
|
ioGetC:
|
||||||
|
push ix
|
||||||
|
ld ix, IO_BLK
|
||||||
|
call _blkGetC
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
|
ioPutC:
|
||||||
|
push ix
|
||||||
|
ld ix, IO_BLK
|
||||||
|
call _blkPutC
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
|
ioSeek:
|
||||||
|
push ix
|
||||||
|
ld ix, IO_BLK
|
||||||
|
call _blkSeek
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
|
ioTell:
|
||||||
|
push ix
|
||||||
|
ld ix, IO_BLK
|
||||||
|
call _blkTell
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
; Given an offset HL, read the line in IO_LINE, without LF and null terminates
|
; Given an offset HL, read the line in IO_LINE, without LF and null terminates
|
||||||
; it. Make HL point to IO_LINE.
|
; it. Make HL point to IO_LINE.
|
||||||
ioGetLine:
|
ioGetLine:
|
||||||
@ -19,11 +70,11 @@ ioGetLine:
|
|||||||
push bc
|
push bc
|
||||||
ld de, 0 ; limit ourselves to 16-bit for now
|
ld de, 0 ; limit ourselves to 16-bit for now
|
||||||
xor a ; absolute seek
|
xor a ; absolute seek
|
||||||
call blkSeek
|
call ioSeek
|
||||||
ld hl, IO_LINE
|
ld hl, IO_LINE
|
||||||
ld b, IO_MAXLEN
|
ld b, IO_MAXLEN
|
||||||
.loop:
|
.loop:
|
||||||
call blkGetC
|
call ioGetC
|
||||||
jr nz, .loopend
|
jr nz, .loopend
|
||||||
or a ; null? hum, weird. same as LF
|
or a ; null? hum, weird. same as LF
|
||||||
jr z, .loopend
|
jr z, .loopend
|
||||||
|
@ -31,11 +31,17 @@
|
|||||||
;
|
;
|
||||||
; *** Requirements ***
|
; *** Requirements ***
|
||||||
; BLOCKDEV_SIZE
|
; BLOCKDEV_SIZE
|
||||||
|
; FS_HANDLE_SIZE
|
||||||
|
; _blkGetC
|
||||||
|
; _blkPutC
|
||||||
|
; _blkSeek
|
||||||
|
; _blkTell
|
||||||
; addHL
|
; addHL
|
||||||
; blkGetC
|
|
||||||
; blkSeek
|
|
||||||
; blkTell
|
|
||||||
; cpHLDE
|
; cpHLDE
|
||||||
|
; fsFindFN
|
||||||
|
; fsOpen
|
||||||
|
; fsGetC
|
||||||
|
; fsPutC
|
||||||
; intoHL
|
; intoHL
|
||||||
; printstr
|
; printstr
|
||||||
; printcrlf
|
; printcrlf
|
||||||
@ -49,6 +55,9 @@
|
|||||||
.equ ED_RAMEND ED_CURLINE+2
|
.equ ED_RAMEND ED_CURLINE+2
|
||||||
|
|
||||||
edMain:
|
edMain:
|
||||||
|
; because ed only takes a single string arg, we can use HL directly
|
||||||
|
call ioInit
|
||||||
|
ret nz
|
||||||
; diverge from UNIX: start at first line
|
; diverge from UNIX: start at first line
|
||||||
ld hl, 0
|
ld hl, 0
|
||||||
ld (ED_CURLINE), hl
|
ld (ED_CURLINE), hl
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
jp fsFindFN
|
jp fsFindFN
|
||||||
jp fsOpen
|
jp fsOpen
|
||||||
jp fsGetC
|
jp fsGetC
|
||||||
|
jp fsPutC
|
||||||
jp cpHLDE
|
jp cpHLDE
|
||||||
jp parseArgs
|
jp parseArgs
|
||||||
jp printstr
|
jp printstr
|
||||||
@ -37,9 +38,6 @@
|
|||||||
jp printcrlf
|
jp printcrlf
|
||||||
jp stdioPutC
|
jp stdioPutC
|
||||||
jp stdioReadLine
|
jp stdioReadLine
|
||||||
jp blkGetC
|
|
||||||
jp blkSeek
|
|
||||||
jp blkTell
|
|
||||||
|
|
||||||
#include "core.asm"
|
#include "core.asm"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
@ -20,16 +20,14 @@
|
|||||||
.equ fsFindFN 0x2a
|
.equ fsFindFN 0x2a
|
||||||
.equ fsOpen 0x2d
|
.equ fsOpen 0x2d
|
||||||
.equ fsGetC 0x30
|
.equ fsGetC 0x30
|
||||||
.equ cpHLDE 0x33
|
.equ fsPutC 0x33
|
||||||
.equ parseArgs 0x36
|
.equ cpHLDE 0x36
|
||||||
.equ printstr 0x39
|
.equ parseArgs 0x39
|
||||||
.equ _blkGetC 0x3c
|
.equ printstr 0x3c
|
||||||
.equ _blkPutC 0x3f
|
.equ _blkGetC 0x3f
|
||||||
.equ _blkSeek 0x42
|
.equ _blkPutC 0x42
|
||||||
.equ _blkTell 0x45
|
.equ _blkSeek 0x45
|
||||||
.equ printcrlf 0x48
|
.equ _blkTell 0x48
|
||||||
.equ stdioPutC 0x4b
|
.equ printcrlf 0x4b
|
||||||
.equ stdioReadLine 0x4e
|
.equ stdioPutC 0x4e
|
||||||
.equ blkGetC 0x51
|
.equ stdioReadLine 0x51
|
||||||
.equ blkSeek 0x54
|
|
||||||
.equ blkTell 0x57
|
|
||||||
|
Loading…
Reference in New Issue
Block a user