2019-07-14 01:29:06 +10:00
|
|
|
; io - handle ed's I/O
|
|
|
|
|
|
|
|
; *** Consts ***
|
|
|
|
;
|
|
|
|
; Max length of a line
|
|
|
|
.equ IO_MAXLEN 0x7f
|
|
|
|
|
|
|
|
; *** Variables ***
|
2019-07-21 09:35:19 +10:00
|
|
|
; Handle of the target file
|
|
|
|
.equ IO_FILE_HDL IO_RAMSTART
|
|
|
|
; block device targeting IO_FILE_HDL
|
2019-10-31 07:59:35 +11:00
|
|
|
.equ IO_BLK @+FS_HANDLE_SIZE
|
2019-07-14 01:29:06 +10:00
|
|
|
; Buffer for lines read from I/O.
|
2019-10-31 07:59:35 +11:00
|
|
|
.equ IO_LINE @+BLOCKDEV_SIZE
|
|
|
|
.equ IO_RAMEND @+IO_MAXLEN+1 ; +1 for null
|
2019-07-14 01:29:06 +10:00
|
|
|
; *** Code ***
|
|
|
|
|
2019-07-21 09:35:19 +10:00
|
|
|
; 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
|
2019-10-31 07:59:35 +11:00
|
|
|
.fsGetB:
|
2019-07-21 09:35:19 +10:00
|
|
|
ld ix, IO_FILE_HDL
|
2019-10-31 07:59:35 +11:00
|
|
|
jp fsGetB
|
|
|
|
.fsPutB:
|
2019-07-21 09:35:19 +10:00
|
|
|
ld ix, IO_FILE_HDL
|
2019-10-31 07:59:35 +11:00
|
|
|
jp fsPutB
|
2019-07-21 09:35:19 +10:00
|
|
|
.blkdev:
|
2019-10-31 07:59:35 +11:00
|
|
|
.dw .fsGetB, .fsPutB
|
2019-07-21 09:35:19 +10:00
|
|
|
|
2019-10-31 07:59:35 +11:00
|
|
|
ioGetB:
|
2019-07-21 09:35:19 +10:00
|
|
|
push ix
|
|
|
|
ld ix, IO_BLK
|
2019-10-31 07:59:35 +11:00
|
|
|
call _blkGetB
|
2019-07-21 09:35:19 +10:00
|
|
|
pop ix
|
|
|
|
ret
|
|
|
|
|
2019-10-31 07:59:35 +11:00
|
|
|
ioPutB:
|
2019-07-21 09:35:19 +10:00
|
|
|
push ix
|
|
|
|
ld ix, IO_BLK
|
2019-10-31 07:59:35 +11:00
|
|
|
call _blkPutB
|
2019-07-21 09:35:19 +10:00
|
|
|
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
|
2019-07-22 01:39:00 +10:00
|
|
|
|
|
|
|
ioSetSize:
|
|
|
|
push ix
|
|
|
|
ld ix, IO_FILE_HDL
|
|
|
|
call fsSetSize
|
|
|
|
pop ix
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Write string (HL) in current file. Ends line with LF.
|
|
|
|
ioPutLine:
|
|
|
|
push hl
|
|
|
|
.loop:
|
|
|
|
ld a, (hl)
|
|
|
|
or a
|
|
|
|
jr z, .loopend ; null, we're finished
|
2019-10-31 07:59:35 +11:00
|
|
|
call ioPutB
|
2019-07-22 01:39:00 +10:00
|
|
|
jr nz, .error
|
|
|
|
inc hl
|
|
|
|
jr .loop
|
|
|
|
.loopend:
|
|
|
|
; Wrote the whole line, write ending LF
|
|
|
|
ld a, 0x0a
|
2019-10-31 07:59:35 +11:00
|
|
|
call ioPutB
|
2019-07-22 01:39:00 +10:00
|
|
|
jr z, .end ; success
|
|
|
|
; continue to error
|
|
|
|
.error:
|
|
|
|
call unsetZ
|
|
|
|
.end:
|
|
|
|
pop hl
|
|
|
|
ret
|