diff --git a/apps/ed/README.md b/apps/ed/README.md index 2ea0bf9..6db9de6 100644 --- a/apps/ed/README.md +++ b/apps/ed/README.md @@ -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. diff --git a/apps/ed/buf.asm b/apps/ed/buf.asm index 65cc517..f5226e1 100644 --- a/apps/ed/buf.asm +++ b/apps/ed/buf.asm @@ -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 diff --git a/apps/ed/io.asm b/apps/ed/io.asm index 4e582d4..eecd5ec 100644 --- a/apps/ed/io.asm +++ b/apps/ed/io.asm @@ -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 diff --git a/apps/ed/main.asm b/apps/ed/main.asm index 5582b01..5e8acad 100644 --- a/apps/ed/main.asm +++ b/apps/ed/main.asm @@ -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 diff --git a/tools/emul/shell/shell_.asm b/tools/emul/shell/shell_.asm index 74ef5f5..a522124 100644 --- a/tools/emul/shell/shell_.asm +++ b/tools/emul/shell/shell_.asm @@ -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" diff --git a/tools/emul/shell/user.h b/tools/emul/shell/user.h index 2eab1c8..c2d1379 100644 --- a/tools/emul/shell/user.h +++ b/tools/emul/shell/user.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