From b5dc5fc61552cdfbdaf6b5a4d032b10b5619fe43 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 10 Dec 2020 00:58:59 +0100 Subject: [PATCH] added iterative file loading to diskio --- compiler/res/prog8lib/diskio.p8 | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 43a6a05b1..cc9e21f6a 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -59,7 +59,7 @@ io_error: } - ; internal variables for the iterative file lister + ; internal variables for the iterative file lister / loader ubyte list_suffixmatch ubyte list_pattern_size ubyte list_skip_disk_name @@ -68,6 +68,9 @@ io_error: ubyte iteration_in_progress = false str list_filename = "????????????????" + + ; ----- iterative file lister functions ----- + sub lf_start_list(ubyte drivenumber, uword pattern, ubyte suffixmatch) -> ubyte { ; -- start an iterative file listing with optional prefix or suffix name matching. lf_end_list() @@ -171,6 +174,53 @@ close_end: } + ; ----- iterative file loader functions ----- + + sub f_open(ubyte drivenumber, uword filenameptr) -> ubyte { + f_close() + + c64.SETNAM(strlen(filenameptr), filenameptr) + c64.SETLFS(11, drivenumber, 0) + void c64.OPEN() ; open 11,8,0,"filename" + if_cc { + iteration_in_progress = true + void c64.CHKIN(11) ; use #2 as input channel + if_cc + return true + } + f_close() + return false + } + + sub f_read(uword bufferpointer, uword buffersize) -> uword { + if not iteration_in_progress + return 0 + + uword actual = 0 + repeat buffersize { + ubyte data = c64.CHRIN() + @(bufferpointer) = data + bufferpointer++ + actual++ + ubyte status = c64.READST() + if status==64 + f_close() ; end of file, close it + if status + return actual + } + return actual + } + + sub f_close() { + ; -- end an iterative file loading session (close channels). + if iteration_in_progress { + c64.CLRCHN() + c64.CLOSE(11) + iteration_in_progress = false + } + } + + sub status(ubyte drivenumber) -> uword { ; -- retrieve the disk drive's current status message uword messageptr = &filename