From a96defab862c9423612890487b3776b306c6adec Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 2 Feb 2025 02:44:23 +0100 Subject: [PATCH] diskio: added several diskio routines to list only the files or dir entries on the disk uses CBM DOS filtering $:*=c and $:*=p --- compiler/res/prog8lib/shared_cbm_diskio.p8 | 34 +++++++++++++++++++++- examples/cx16/fileselector.p8 | 14 +++++---- examples/test.p8 | 6 ++++ syntax-files/IDEA/Prog8.xml | 4 +-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/compiler/res/prog8lib/shared_cbm_diskio.p8 b/compiler/res/prog8lib/shared_cbm_diskio.p8 index f00fb216f..dae193c14 100644 --- a/compiler/res/prog8lib/shared_cbm_diskio.p8 +++ b/compiler/res/prog8lib/shared_cbm_diskio.p8 @@ -27,6 +27,7 @@ diskio { ; -- Prints the directory contents to the screen. Returns success. cbm.SETNAM(1, "$") +internal_dir: cbm.SETLFS(READ_IO_CHANNEL, drivenumber, 0) ubyte status = 1 void cbm.OPEN() ; open 12,8,0,"$" @@ -81,6 +82,19 @@ io_error: return true } + sub directory_dirs() -> bool { + ; -- Prints all entries on the disk to the screen, but only directories. Returns success. + cbm.SETNAM(5, "$:*=c") ; on C64 (1581 diskdrive) the type for directories is CBM + goto diskio.directory.internal_dir + } + + sub directory_files() -> bool { + ; -- Prints all entries on the disk to the screen, but only actual files. Returns success. + cbm.SETNAM(5, "$:*=p") + goto diskio.directory.internal_dir + } + + sub diskname() -> uword { ; -- Returns pointer to disk name string or 0 if failure. @@ -170,12 +184,14 @@ io_error: sub lf_start_list(uword pattern_ptr) -> bool { ; -- start an iterative file listing with optional pattern matching. ; note: only a single iteration loop can be active at a time! + cbm.SETNAM(1, "$") + +start_list_internal: lf_end_list() list_pattern = pattern_ptr list_skip_disk_name = true iteration_in_progress = true - cbm.SETNAM(1, "$") cbm.SETLFS(READ_IO_CHANNEL, drivenumber, 0) void cbm.OPEN() ; open 12,8,0,"$" if_cs @@ -195,6 +211,22 @@ io_error: return false } + sub lf_start_list_dirs(uword pattern_ptr) -> bool { + ; -- start an iterative directory contents listing with optional pattern matching. + ; this version it only returns directory entries! + ; note: only a single iteration loop can be active at a time! + cbm.SETNAM(5, "$:*=c") ; on C64 (1581 diskdrive) the type for directories is CBM + goto diskio.lf_start_list.start_list_internal + } + + sub lf_start_list_files(uword pattern_ptr) -> bool { + ; -- start an iterative directory contents listing with optional pattern matching. + ; this version only returns actual file entries! + ; note: only a single iteration loop can be active at a time! + cbm.SETNAM(5, "$:*=p") + goto diskio.lf_start_list.start_list_internal + } + sub lf_next_entry() -> bool { ; -- retrieve the next entry from an iterative file listing session. ; results will be found in list_blocks, list_filename, and list_filetype. diff --git a/examples/cx16/fileselector.p8 b/examples/cx16/fileselector.p8 index a40d4fd39..a21cc15ee 100644 --- a/examples/cx16/fileselector.p8 +++ b/examples/cx16/fileselector.p8 @@ -9,8 +9,6 @@ ; Functions in PETSCII mode and in ISO mode as well (no case folding in ISO mode!) ; Depends a lot on diskio routines, and uses the drive set in the diskio.drivenumber variable (usually just 8) -; Q: should case folding be done in diskio already? A: no, it doesn't know if you are in iso mode or not. - ; TODO joystick control? mouse control? ; TODO keyboard typing; jump to the first entry that starts with that character? (but 'q' for quit stops working then, plus scrolling with pageup/down is already pretty fast) @@ -76,10 +74,13 @@ fileselector { } sub select(str pattern) -> uword { - ubyte old_bank = cx16.getrambank() - cx16.rambank(buffer_rambank) - defer cx16.rambank(old_bank) + sys.push(cx16.getrambank()) + cx16.r0 = internal_select(pattern) + cx16.rambank(sys.pop()) + return cx16.r0 + } + sub internal_select(str pattern) -> uword { num_visible_files = 0 diskio.list_filename[0] = 0 name_ptr = diskio.diskname() @@ -243,7 +244,8 @@ fileselector { while @(name_ptr)!=0 name_ptr++ } else { - ; case-folding to avoid petscii shifted characters coming out as symbols TODO should diskio do this already? + ; case-folding to avoid petscii shifted characters coming out as symbols + ; Q: should diskio do this already? A: no, diskio doesn't know or care about the current charset mode name_ptr += strings.lower(name_ptr) } name_ptr++ diff --git a/examples/test.p8 b/examples/test.p8 index fb4cdc8cb..d7a78da13 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -7,6 +7,12 @@ main { sub start() { txt.lowercase() + diskio.directory_dirs() + txt.nl() + + diskio.directory_files() + txt.nl() + diskio.lf_start_list_dirs(0) while diskio.lf_next_entry() { txt.print(diskio.list_filetype) diff --git a/syntax-files/IDEA/Prog8.xml b/syntax-files/IDEA/Prog8.xml index 07deb63e1..f824838b9 100644 --- a/syntax-files/IDEA/Prog8.xml +++ b/syntax-files/IDEA/Prog8.xml @@ -14,10 +14,10 @@ - + - + \ No newline at end of file