From 77e956a29f7936d502504c07c55dd822828d6087 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 20 Nov 2022 23:27:22 +0100 Subject: [PATCH] API change: diskio.list_files doesn't have an internal buffer anymore, you now have to supply a buffer + size yourself. Renamed to list_filenames --- compiler/res/prog8lib/diskio.p8 | 27 ++++++++++++++------------- docs/source/libraries.rst | 1 + docs/source/todo.rst | 1 - 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 79935c4d9..e3ec8e3f8 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -114,30 +114,31 @@ io_error: ; ----- get a list of files (uses iteration functions internally) ----- - sub list_files(ubyte drivenumber, uword pattern_ptr, uword name_ptrs, ubyte max_names) -> ubyte { - ; -- fill the array 'name_ptrs' with (pointers to) the names of the files requested. - ; Returns number of files. Skips 'dir' entries (subdirs). - const uword filenames_buf_size = 800 - uword filenames_buffer = memory("filenames", filenames_buf_size, 0) + sub list_filenames(ubyte drivenumber, uword pattern_ptr, uword filenames_buffer, uword filenames_buf_size) -> ubyte { + ; -- fill the provided buffer with the names of the files on the disk (until buffer is full). + ; Files in the buffer are separeted by a 0 byte. You can provide an optional pattern to match against. + ; After the last filename one additional 0 byte is placed to indicate the end of the list. + ; Returns number of files (it skips 'dir' entries i.e. subdirectories). + ; Also sets carry on exit: Carry clear = all files returned, Carry set = directory has more files that didn't fit in the buffer. uword buffer_start = filenames_buffer ubyte files_found = 0 if lf_start_list(drivenumber, pattern_ptr) { while lf_next_entry() { if list_filetype!="dir" { - @(name_ptrs) = lsb(filenames_buffer) - name_ptrs++ - @(name_ptrs) = msb(filenames_buffer) - name_ptrs++ filenames_buffer += string.copy(diskio.list_filename, filenames_buffer) + 1 files_found++ - if filenames_buffer - buffer_start > filenames_buf_size-18 - break - if files_found == max_names - break + if filenames_buffer - buffer_start > filenames_buf_size-20 { + @(filenames_buffer)=0 + lf_end_list() + sys.set_carry() + return files_found + } } } lf_end_list() } + @(filenames_buffer)=0 + sys.clear_carry() return files_found } diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 543b70be7..026d9ede1 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -364,6 +364,7 @@ diskio module, to deal with loading of potentially large files in to banked ram Routines to directly load data into video ram are also present (vload and vload_raw). Also contains a helper function to calculate the file size of a loaded file (although that is truncated to 16 bits, 64Kb) +Als contains routines for operating on subdirectories (chdir, mkdir, rmdir) and to relabel the disk. psg (cx16 only) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 59fc6a824..7d4f73dc6 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- make diskio.list_files not use an internal buffer itself but change names_ptr meaning to user supplied buffer. - ir/vm: allow label in block scope (correct order of block nodes!) - regression test the various projects - attempt to fix the expression codegen bug with reused temp vars (github #89)