apps/ed: start implementing I/O

This commit is contained in:
Virgil Dupras 2019-07-13 11:29:06 -04:00
parent 3d474c9121
commit 3491c26132
5 changed files with 70 additions and 4 deletions

View File

@ -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"

43
apps/ed/io.asm Normal file
View File

@ -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

View File

@ -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'

View File

@ -37,6 +37,8 @@
jp printcrlf
jp stdioReadC
jp stdioGetLine
jp blkGetC
jp blkSeek
#include "core.asm"
#include "err.h"

View File

@ -30,3 +30,5 @@
.equ printcrlf 0x48
.equ stdioReadC 0x4b
.equ stdioGetLine 0x4e
.equ blkGetC 0x51
.equ blkSeek 0x54