From 3491c2613244b541f21910ca574bccf9e8a625ef Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 13 Jul 2019 11:29:06 -0400 Subject: [PATCH] apps/ed: start implementing I/O --- apps/ed/glue.asm | 3 +++ apps/ed/io.asm | 43 +++++++++++++++++++++++++++++++++++++ apps/ed/main.asm | 24 +++++++++++++++++---- tools/emul/shell/shell_.asm | 2 ++ tools/emul/shell/user.h | 2 ++ 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 apps/ed/io.asm diff --git a/apps/ed/glue.asm b/apps/ed/glue.asm index 568d6cf..9ba9bec 100644 --- a/apps/ed/glue.asm +++ b/apps/ed/glue.asm @@ -1,7 +1,10 @@ #include "user.h" +#include "err.h" .org USER_CODE jp edMain +.equ IO_RAMSTART USER_RAMSTART +#include "ed/io.asm" #include "ed/main.asm" diff --git a/apps/ed/io.asm b/apps/ed/io.asm new file mode 100644 index 0000000..4e582d4 --- /dev/null +++ b/apps/ed/io.asm @@ -0,0 +1,43 @@ +; io - handle ed's I/O + +; *** Consts *** +; +; Max length of a line +.equ IO_MAXLEN 0x7f + +; *** Variables *** +; Buffer for lines read from I/O. +.equ IO_LINE IO_RAMSTART +.equ IO_RAMEND IO_LINE+IO_MAXLEN+1 ; +1 for null +; *** Code *** + +; Given an offset HL, read the line in IO_LINE, without LF and null terminates +; it. Make HL point to IO_LINE. +ioGetLine: + push af + push de + push bc + ld de, 0 ; limit ourselves to 16-bit for now + xor a ; absolute seek + call blkSeek + ld hl, IO_LINE + ld b, IO_MAXLEN +.loop: + call blkGetC + jr nz, .loopend + or a ; null? hum, weird. same as LF + jr z, .loopend + cp 0x0a + jr z, .loopend + ld (hl), a + inc hl + djnz .loop +.loopend: + ; null-terminate the string + xor a + ld (hl), a + ld hl, IO_LINE + pop bc + pop de + pop af + ret diff --git a/apps/ed/main.asm b/apps/ed/main.asm index 6a7761c..2b3862c 100644 --- a/apps/ed/main.asm +++ b/apps/ed/main.asm @@ -19,23 +19,39 @@ ; memory usage. ; ; So here's what we do. First, we have two scratchpads. The first one is the -; file being read itself. The second one is is memory, for modifications we +; file being read itself. The second one is memory, for modifications we ; make to the file. When reading the file, we note the offset at which it ends. ; All offsets under this limit refer to the first scratchpad. Other offsets ; refer to the second. ; -; Then, our line list if just an array of 16-bit offsets. This means that we +; Then, our line list is just an array of 16-bit offsets. This means that we ; don't have an easy access to line length and we have to move a lot of memory ; around whenever we add or delete lines. Hopefully, "LDIR" will be our friend ; here... ; +; *** Usage *** +; +; ed takes no argument. It reads from the currently selected blkdev and writes +; to it. It repeatedly presents a prompt, waits for a command, execute the +; command. 'q' to quit. +; ; *** Requirements *** +; BLOCKDEV_SIZE +; blkGetC +; blkSeek ; printstr ; printcrlf ; stdioReadC ; stdioGetLine edMain: + ; Dummy test. Read first line of file + ld hl, 0 + call ioGetLine + call printstr + call printcrlf + ; Continue to loop + edLoop: ld hl, .prompt call printstr @@ -45,7 +61,7 @@ edLoop: ; We're done. Process line. call printcrlf call stdioGetLine - call edProcessLine + call .processLine ret z jr edLoop @@ -53,7 +69,7 @@ edLoop: .db ":", 0 ; Sets Z if we need to quit -edProcessLine: +.processLine: call printstr ld a, (hl) cp 'q' diff --git a/tools/emul/shell/shell_.asm b/tools/emul/shell/shell_.asm index d10785c..97df063 100644 --- a/tools/emul/shell/shell_.asm +++ b/tools/emul/shell/shell_.asm @@ -37,6 +37,8 @@ jp printcrlf jp stdioReadC jp stdioGetLine + jp blkGetC + jp blkSeek #include "core.asm" #include "err.h" diff --git a/tools/emul/shell/user.h b/tools/emul/shell/user.h index 792cb9e..6f42a14 100644 --- a/tools/emul/shell/user.h +++ b/tools/emul/shell/user.h @@ -30,3 +30,5 @@ .equ printcrlf 0x48 .equ stdioReadC 0x4b .equ stdioGetLine 0x4e +.equ blkGetC 0x51 +.equ blkSeek 0x54