rcmolina / MaxDuino

Unified firmware for tzxduino and casduino
https://www.va-de-retro.com/foros/viewtopic.php?t=5541&start=9999
88 stars 21 forks source link

Sdfat use improved api #16

Closed stripwax closed 2 years ago

stripwax commented 2 years ago

There's quite a lot going on here

  1. Don't do a O(N) search each time to find the n'th file entry when seeking up. It's slow. Instead, use the alternative open method that takes a file index (defined by the filesystem), and change all the currentFile handling to use file indexes instead. As part of this change, also, don't use chdir at all - make everything relative to a directory object (currentDir). This complicates some of the handling, and greatly simplifies everything else, as well as speeding up. In addition, as a bonus, this actually requires slightly less firmware space. As another bonus, it is also compatible with sdfat 2.x (since chdir has been removed) . (but I still used sdfat 1.4.0 as a benchmark for consistency)
  2. Completely eliminate sFilename. Also eliminate arguments to UniPlay, seekFile, etc since the global currentFile and fileName are already the thing you want.
  3. Don't use strings to change directory, just use file indexes here too. Benefit: a file index takes two bytes, whereas a subdir string name has been defined to take 22 bytes.
  4. Reduce the size of PlayBytes since it now only needs to fit as much text as you fit on the screen, rather than needing to be as big as a subdirectory name length
  5. Using the above two points, actually increase the number of subdirectories that can be supported, from 3, to 10. You can increase it even more.
  6. Since we freed up a bit of ram anyway, extend the fileNameLength to the full 255 bytes long-filename-length supported by fat32

For simplicity, I also removed the support for the non-sdfat library (i.e. using SD when SDFat is not defined). It looks like all the hardware targets set #define SDFat so maybe there's no point keeping the SD code around.

Feel free to discuss and test - this is a bit work-in-progress as I don't yet have a Nano target to test on

stripwax commented 2 years ago

(Will mark as 'ready' once I've performed some further testing, which means I need to merge it locally with my SAMD21 changes and/or set up avr nano hardware)

rcmolina commented 2 years ago

Hi David,

Cause of your collaborative work, We'll move to to classical rolling version. So, I've removed version numbers from now in dir and files. Also, for version number it will show new maxduino to clarify the change.

stripwax commented 2 years ago

It seems that my changes are only working correctly when using 2.1.2 version of sdfat (probably >= 2.0.0) , and not working correctly using 1.1.4 version of sdfat (probably < 2.0.0) . I did not test using 1.1.4 version of sdfat yet ... I'll see if I can get it working!

Since this has already been merged and closed, I will create a new pull request for the corresponding changes/fixes.