From e2f5752d9a089915bf459b8e034c2e30a2ca64eb Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 1 May 2021 19:13:56 +0200 Subject: [PATCH] add f_open_w, f_write, f_close_w to diskio to be able to save parts of memory sequentially --- compiler/res/prog8lib/diskio.p8 | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index af22c62be..64a852222 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -336,6 +336,45 @@ _end rts } + ; ----- iterative file saver functions (uses io channel 14) ----- + + sub f_open_w(ubyte drivenumber, uword filenameptr) -> ubyte { + ; -- open a file for iterative writing with f_write + f_close_w() + + c64.SETNAM(string.length(filenameptr), filenameptr) + c64.SETLFS(14, drivenumber, 1) + void c64.OPEN() ; open 14,8,1,"filename" + if_cc { + void c64.CHKOUT(14) ; use #14 as input channel + return not c64.READST() + } + f_close_w() + return false + } + + sub f_write(uword bufferpointer, uword num_bytes) -> ubyte { + ; -- write the given umber of bytes to the currently open file + if num_bytes!=0 { + void c64.CHKOUT(14) ; use #14 as input channel again + repeat num_bytes { + c64.CHROUT(@(bufferpointer)) + bufferpointer++ + } + return not c64.READST() + } + return true + } + + sub f_close_w() { + ; -- end an iterative file writing session (close channels). + c64.CLRCHN() + c64.CLOSE(14) + } + + + ; ---- other functions ---- + sub status(ubyte drivenumber) -> uword { ; -- retrieve the disk drive's current status message uword messageptr = &filename @@ -364,7 +403,6 @@ io_error: goto done } - sub save(ubyte drivenumber, uword filenameptr, uword address, uword size) -> ubyte { c64.SETNAM(string.length(filenameptr), filenameptr) c64.SETLFS(1, drivenumber, 0)