Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
cnfs.h File Reference

Detailed Description

Design Philosophy

Ths Swadge loads an assets "image" as cnfs_files and cnfs_data.

During the build, assets in the /assets/ folder, such as PNG images and MIDI songs, are processed into Swadge-friendly formats and written to the /assets_image/ folder. The contents of the /assets_image/ are then packaged into a matching cnfs_files and cnfs_data image which are stored as a C file and loaded alongside cnfs.c.

Usage

You don't need to call cnfsInit() or cnfsDeinit(). The system does that the appropriate time.

cnfsReadFile() may be used to read a file straight from cnfs, but this probably should not be done directly.

cnfsGetFile() gets a reference to the file in flash, to obviate need to "load it into RAM"

Each asset type has it's own file loader which handles things like decompression if the asset type is compressed, and writing values from the read file into a convenient struct. The loader functions are:

Assets may be loaded to either SPI RAM or normal RAM. There is more SPI RAM available, but it is slower to access than normal RAM. Swadge modes should use normal RAM if they can, and use SPI RAM if the mode is asset-heavy.

Example

// Declare and load a font
font_t ibm;
loadFont("ibm_vga8.font", &ibm, false);
// Draw some white text
drawText(&ibm, c555, "Hello World", 0, 0);
// Free the font
freeFont(&ibm);
// Declare and load an image
wsg_t king_donut;
loadWsg("kid0.wsg", &king_donut, true);
// Draw the image to the display
drawWsg(&king_donut, 100, 100, false, false, 0);
// Free the image
freeWsg(&king_donut);
int16_t drawText(const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff)
Draw text to a display with the given color and font.
Definition font.c:214
A font is a collection of font_ch_t for all ASCII characters. Each character has the same height and ...
Definition font.h:66
void freeFont(font_t *font)
Free the memory allocated for a font.
Definition fs_font.c:89
bool loadFont(const char *name, font_t *font, bool spiRam)
Load a font from ROM to RAM. Fonts are bitmapped image files that have a single height,...
Definition fs_font.c:32
bool loadWsg(const char *name, wsg_t *wsg, bool spiRam)
Load a WSG from ROM to RAM. WSGs placed in the assets_image folder before compilation will be automat...
Definition fs_wsg.c:34
void freeWsg(wsg_t *wsg)
Free the memory for a loaded WSG.
Definition fs_wsg.c:167
@ c555
r = 5, g = 5, b = 5
Definition palette.h:239
void drawWsg(const wsg_t *wsg, int16_t xOff, int16_t yOff, bool flipLR, bool flipUD, int16_t rotateDeg)
Draw a WSG to the display.
Definition wsg.c:105
A sprite using paletteColor_t colors that can be drawn to the display.
Definition wsg.h:57

Go to the source code of this file.

Functions

bool initCnfs (void)
 Initialize the CNFS file system. This is used to store assets like WSGs and fonts.
 
bool deinitCnfs (void)
 De-initialize the CNFS file system (right now a noop)
 
const uint8_t * cnfsGetFile (const char *fname, size_t *flen)
 Get a pointer to a file, without needing to read it. Same rules that apply to cnfsGetFile, and under the hood, cnfsGetFile uses this function.
 
uint8_t * cnfsReadFile (const char *fname, size_t *outsize, bool readToSpiRam)
 Read a file from CNFS into an output array. Files that are in the assets_image folder before compilation and flashing will automatically be included in the firmware.
 

Function Documentation

◆ initCnfs()

bool initCnfs ( void )

Initialize the CNFS file system. This is used to store assets like WSGs and fonts.

Returns
true if CNFS was initialized and can be used, false if it failed

◆ deinitCnfs()

bool deinitCnfs ( void )

De-initialize the CNFS file system (right now a noop)

Returns
true if de-initialize ok, false if it was not

◆ cnfsGetFile()

const uint8_t * cnfsGetFile ( const char * fname,
size_t * flen )

Get a pointer to a file, without needing to read it. Same rules that apply to cnfsGetFile, and under the hood, cnfsGetFile uses this function.

Parameters
fnameThe name of the file to find.
flenA pointer to a size_t to return the size of the file.
Returns
A pointer to the read data if successful, or NULL if there is a failure Do not free this pointer. It is pointing to flash.

◆ cnfsReadFile()

uint8_t * cnfsReadFile ( const char * fname,
size_t * outsize,
bool readToSpiRam )

Read a file from CNFS into an output array. Files that are in the assets_image folder before compilation and flashing will automatically be included in the firmware.

Parameters
fnameThe name of the file to load
outsizeA pointer to a size_t to return how much data was read
readToSpiRamtrue to use SPI RAM, false to use normal RAM
Returns
A pointer to the read data if successful, or NULL if there is a failure This data must be freed when done