CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
FAT16/FAT32 files

A read-only FAT16/FAT32 reader on top of sd::read(): a file name in, the file's runs of card blocks out. More...

Namespaces

namespace  fat
 The FAT16/FAT32 reader (CHSd).
 

Classes

struct  fat::Run
 A run of consecutive card blocks holding part of a file (see runs()). More...
 
struct  fat::File
 A file or folder found in a directory: where it starts and how long it is. More...
 

Detailed Description

A read-only FAT16/FAT32 reader on top of sd::read(): a file name in, the file's runs of card blocks out.

Written from the Microsoft FAT specification (BPB fields, FAT type from the cluster count, 8.3 directory entries, end-of-chain marks) and the MBR partition table layout. It only turns a file name into LBA runs: after that a file is read as raw card blocks through its run list, so there is no FAT write code, no cache and no file object. Every call borrows the caller's 512 B buffer (4-byte aligned) and clobbers it; the volume state is 24 B. What a game does not call is left out of its image by the linker.

Names are 8.3 short names as the directory stores them: 11 characters, capitals, the name and the extension padded with spaces ("WORDS DIC" for WORDS.DIC), and ? stands for any character. Long-name entries, volume labels and hidden entries are skipped; a file never matches a folder name, nor a folder a file name. Files are looked for in the root directory or in a folder of it.

// Once, after gfx_wait() (the card shares SPI1 with the panel):
fat::Run run[4];
uint8_t nRuns = fat::open("WORDS DIC", run, 4, gfx_chunkScratch());
// ... then any block of the file, any time after gfx_wait():
if (!fat::read(run, nRuns, k, gfx_chunkScratch())) { /* the card has gone */ }
uint8_t * gfx_chunkScratch(void)
1 KB of word-aligned scratch memory: the flush's chunk buffers.
uint8_t open(const char *name, Run *out, uint8_t maxRuns, uint8_t *buf)
The usual way in: sd::init(), mount(), find() and runs() in one go.
bool read(const Run *run, uint32_t nRuns, uint32_t k, uint8_t *dst)
Reads block k of a file through its runs.
A run of consecutive card blocks holding part of a file (see runs()).
Definition Fat.h:62
Warning
Bus rule. Every call reads the card over SPI1, which the panel shares: call them only between gfx_wait() and the next flush. CHGfx's gfx_chunkScratch() is idle at exactly that time and makes a good buffer.