AgonConsole8 / agon-mos

Official AGON QUARK Firmware for Console8: eZ80 MOS
MIT License
25 stars 10 forks source link

Need more file system syscalls, in particular opendir/readdir #42

Open lennart-benschop opened 5 months ago

lennart-benschop commented 5 months ago

Apparently it is still not possible for a program to obtain the list of files in a directory. We can call the CAT command but this prints the directory on the screen. If we need to get the list of files in a program,. so we can make our own file load/save dialogue or Midnight Commander clone we are SOL.

I will try to implement this.

lennart-benschop commented 5 months ago

There are system calls defined in mos_api.inc, ffs_dopen, ffs_dclose, ffs_dread, but they are NOT implemented currently. Implementing seems very straightforward.

The only thing is: they need DIR and FILINFO structures. For the DIR struct your application only needs to reserve a memory area of the appropriate size, for the FILINFO struct, it is fairly clear what goes inside it and this contains the very stuff (file size, data, file name, attribs) that your application wants to read from the directory.

An alternative could be to statically reserve a single DIR struct and allow for one directory to be open at a time and then have mosopendir/closedir/readdir functions to work on that single DIR struct. For now I think I will go for the simple straightforward fs functions that require applications to reserve their own DIR struct.

I only consider it done if I have an example program that lists a directory based on these system calls.

HeathenUK commented 5 months ago

@tomm implemented these calls in his "Rainbow" MOS build. Here's the commit.

This is a simple shim, but since all three functions work via being passed a reference to a DIR/FILINFO struct there's no need to implement anything more. The user can do it themselves.

I'm using these functions happily enough in AgDev now, and if/when they ever get mainstreamed I will offer up the changes to mos_api.h and mos_api.src that match Tom's shim.

stevesims commented 5 months ago

the new calls implemented in @tomm 's "rainbow" MOS build have been integrated and released as part of the 2.2.0 release

there are however still several filesystem sys calls that are missing