Progress report.
TLDR: linked 3rd party c++ library on device, reading files in c is straight forward but needs to be taken in smallish 4000 byte chunks when on device) (wrong, you need to alloc & malloc to free space on the stack)
I bumped into my fair share of sharp edges and minor setbacks the last few days trying to get my development environment linking the game-music-emu c++ library on device at runtime. Everything worked ok in the simulator, but no dice on the actual
I've never used CMakeLists before and learning the basics took me the better part of a day just to get the libraries to build and link.
I sent a desperation message to community member @MrBZapp and he graciously helped me through my CMakeLists.txt issues. (modify_target_for_playdate does something magic!)
Once I was successfully running on the device, I decided it was time to read some bytes off disk and open a file. For now, I have embedded a 40KB test NSF file into my pdx, so that's the file i'm going to read (and hopefully playback soon).
SDK API's that I've used today:
- int playdate->file->stat(const char* path, FileStat* stat); - straight forward, check the return int to see if the file exists and can be stat'd, get the file size using stat->size
- SDFile* playdate->file->open(const char* path, FileOptions mode); - open the file
- int playdate->file->read(SDFile* file, void* buf, unsigned int len); - read some bytes...admittedly this one bit me. I had to make a loop with repeated read calls taking 4000 byte nibbles to read the entire file into memory. I tried 6000 bytes and my playdate would crash. (bad form here, much better to alloc on the heap then load as demonstrated here
- int playdate->file->close(SDFile* file); - done reading, closer the file (I haven't actually used this one yet...but I will!)
Once I read the byte array, I printed it all out to the console with pd->system->logToConsole()
and compared with xxd dump from my terminal on my mac...it matches!
That's about it for a progress report, next up I'm going to send my bytes to the game music library and see if it can determine if it's a music file.