diskio: added several diskio routines to list only the files or dir entries on the disk

uses CBM DOS filtering $:*=c and $:*=p
This commit is contained in:
Irmen de Jong 2025-02-02 02:44:23 +01:00
parent 0864b0a1b7
commit a96defab86
4 changed files with 49 additions and 9 deletions

View File

@ -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.

View File

@ -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++

View File

@ -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)

View File

@ -14,10 +14,10 @@
<keywords keywords="&amp;;&amp;&lt;;&amp;&gt;;-&gt;;@;alias;and;as;asmsub;break;clobbers;continue;do;downto;else;extsub;false;for;goto;if;if_cc;if_cs;if_eq;if_mi;if_ne;if_neg;if_nz;if_pl;if_pos;if_vc;if_vs;if_z;in;inline;not;or;repeat;return;step;sub;to;true;unroll;until;when;while;xor;~" ignore_case="false" />
<keywords2 keywords="%address;%align;%asm;%asmbinary;%asminclude;%breakpoint;%encoding;%import;%ir;%launcher;%memtop;%option;%output;%zeropage;%zpallowed;%zpreserved;@align64;@alignpage;@alignword;@bank;@dirty;@nosplit;@nozp;@requirezp;@shared;@split;@zp;atascii:;c64os:;cp437:;default:;iso16:;iso5:;iso:;kata:;petscii:;sc:" />
<keywords3 keywords="bool;byte;const;float;long;str;ubyte;uword;void;word" />
<keywords4 keywords="abs;call;callfar;callfar2;clamp;cmp;defer;divmod;len;lsb;lsw;max;memory;min;mkword;msb;msw;peek;peekf;peekw;poke;pokef;pokew;rol;rol2;ror;ror2;rrestore;rrestorex;rsave;rsavex;setlsb;setmsb;sgn;sizeof;sqrt" />
<keywords4 keywords="abs;bmx;call;callfar;callfar2;cbm;clamp;cmp;conv;cx16;defer;divmod;floats;len;lsb;lsw;math;max;memory;min;mkword;msb;msw;peek;peekf;peekw;poke;pokef;pokew;psg;rol;rol2;ror;ror2;rrestore;rrestorex;rsave;rsavex;setlsb;setmsb;sgn;sizeof;sqrt;strings;sys;txt;verafx" />
</highlighting>
<extensionMap>
<mapping ext="p8" />
<mapping ext="prog8" />
</extensionMap>
</filetype>
</filetype>