mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 16:28: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
|
||||
|
||||
`ed` is invoked from the shell with no argument. ed takes no argument.
|
||||
It reads from the currently selected blkdev and writes to it.
|
||||
`ed` is invoked from the shell with a single argument: the name of the file to
|
||||
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
|
||||
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 bc, 0 ; line count
|
||||
.loop:
|
||||
call blkTell ; --> HL
|
||||
call blkGetC
|
||||
call ioTell ; --> HL
|
||||
call ioGetC
|
||||
jr nz, .loopend
|
||||
ld (ix), l
|
||||
inc ix
|
||||
|
@ -6,11 +6,62 @@
|
||||
.equ IO_MAXLEN 0x7f
|
||||
|
||||
; *** 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.
|
||||
.equ IO_LINE IO_RAMSTART
|
||||
.equ IO_LINE IO_BLK+BLOCKDEV_SIZE
|
||||
.equ IO_RAMEND IO_LINE+IO_MAXLEN+1 ; +1 for null
|
||||
; *** 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
|
||||
; it. Make HL point to IO_LINE.
|
||||
ioGetLine:
|
||||
@ -19,11 +70,11 @@ ioGetLine:
|
||||
push bc
|
||||
ld de, 0 ; limit ourselves to 16-bit for now
|
||||
xor a ; absolute seek
|
||||
call blkSeek
|
||||
call ioSeek
|
||||
ld hl, IO_LINE
|
||||
ld b, IO_MAXLEN
|
||||
.loop:
|
||||
call blkGetC
|
||||
call ioGetC
|
||||
jr nz, .loopend
|
||||
or a ; null? hum, weird. same as LF
|
||||
jr z, .loopend
|
||||
|
@ -31,11 +31,17 @@
|
||||
;
|
||||
; *** Requirements ***
|
||||
; BLOCKDEV_SIZE
|
||||
; FS_HANDLE_SIZE
|
||||
; _blkGetC
|
||||
; _blkPutC
|
||||
; _blkSeek
|
||||
; _blkTell
|
||||
; addHL
|
||||
; blkGetC
|
||||
; blkSeek
|
||||
; blkTell
|
||||
; cpHLDE
|
||||
; fsFindFN
|
||||
; fsOpen
|
||||
; fsGetC
|
||||
; fsPutC
|
||||
; intoHL
|
||||
; printstr
|
||||
; printcrlf
|
||||
@ -49,6 +55,9 @@
|
||||
.equ ED_RAMEND ED_CURLINE+2
|
||||
|
||||
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
|
||||
ld hl, 0
|
||||
ld (ED_CURLINE), hl
|
||||
|
@ -27,6 +27,7 @@
|
||||
jp fsFindFN
|
||||
jp fsOpen
|
||||
jp fsGetC
|
||||
jp fsPutC
|
||||
jp cpHLDE
|
||||
jp parseArgs
|
||||
jp printstr
|
||||
@ -37,9 +38,6 @@
|
||||
jp printcrlf
|
||||
jp stdioPutC
|
||||
jp stdioReadLine
|
||||
jp blkGetC
|
||||
jp blkSeek
|
||||
jp blkTell
|
||||
|
||||
#include "core.asm"
|
||||
#include "err.h"
|
||||
|
@ -20,16 +20,14 @@
|
||||
.equ fsFindFN 0x2a
|
||||
.equ fsOpen 0x2d
|
||||
.equ fsGetC 0x30
|
||||
.equ cpHLDE 0x33
|
||||
.equ parseArgs 0x36
|
||||
.equ printstr 0x39
|
||||
.equ _blkGetC 0x3c
|
||||
.equ _blkPutC 0x3f
|
||||
.equ _blkSeek 0x42
|
||||
.equ _blkTell 0x45
|
||||
.equ printcrlf 0x48
|
||||
.equ stdioPutC 0x4b
|
||||
.equ stdioReadLine 0x4e
|
||||
.equ blkGetC 0x51
|
||||
.equ blkSeek 0x54
|
||||
.equ blkTell 0x57
|
||||
.equ fsPutC 0x33
|
||||
.equ cpHLDE 0x36
|
||||
.equ parseArgs 0x39
|
||||
.equ printstr 0x3c
|
||||
.equ _blkGetC 0x3f
|
||||
.equ _blkPutC 0x42
|
||||
.equ _blkSeek 0x45
|
||||
.equ _blkTell 0x48
|
||||
.equ printcrlf 0x4b
|
||||
.equ stdioPutC 0x4e
|
||||
.equ stdioReadLine 0x51
|
||||
|
Loading…
Reference in New Issue
Block a user