#ifndef PW_CART_H #define PW_CART_H #include #include "fs.h" /** The maximum supported PICO-8 cart path size. */ #define PW_CART_PATH_MAX 960 /** The maximum supported PICO-8 cart name size. */ #define PW_CART_NAME_MAX 64 /** The maximum number of embedded PICO-8 carts. */ #define PW_CART_EMBEDDED_MAX 32 /** The size of a PICO-8 ROM. */ #define PW_CART_ROM_SIZE 32768 /** The width in pixels of a PICO-8 PNG. */ #define PW_CART_PNG_WIDTH 160 /** The height in pixels of a PICO-8 PNG. */ #define PW_CART_PNG_HEIGHT 205 /** * A PICO-8 cart file that can be loaded. */ struct pw_cart_file { char name[PW_CART_NAME_MAX]; char path[PW_CART_PATH_MAX]; }; /** * The list of carts read from the carts directory. */ struct pw_carts { size_t count; struct pw_cart_file files[]; }; /** * A loaded PICO-8 PNG cart, with both a texture for rendring the cart PNG * as well as its steganographically encoded ROM. */ struct pw_cart_png { SDL_Texture *texture; uint8_t rom[PW_CART_ROM_SIZE]; }; /** * PICO-8 cart data. */ struct pw_cart_data { char name[PW_CART_NAME_MAX]; uint8_t rom[PW_CART_ROM_SIZE]; }; /** * A PICO-8 cart, its loaded embedded ROMs and mounted storage. */ struct pw_cart { size_t count; struct pw_fs *storage; struct pw_cart_data embedded[]; }; /** * List all carts in the `dir`. Returns `NULL` on failure. */ struct pw_carts *pw_carts_list(char const *dir); /** * Free all memory associated with a carts list. */ void pw_carts_free(struct pw_carts *carts); /** * Initializes an empty cart PNG. */ struct pw_cart_png *pw_cart_png_init(SDL_Renderer *renderer); /** * Frees a cart and all of its resources. */ void pw_cart_png_free(struct pw_cart_png *png); /** * Loads the main cart PNG from a file. * * This will also decode and load the steganographically encoded ROM. */ bool pw_cart_png_load(struct pw_cart_file *file, struct pw_cart_png *png); /** * Resets a cart to its initial empty state. */ bool pw_cart_png_reset(struct pw_cart_png *png); /** * Loads a cart from a file, including mounting its user data file-system. * * Optionally specify a loaded cart PNG to copy the ROM from instead of * re-reading from disk. */ struct pw_cart *pw_cart_load(struct pw_cart_file *file, struct pw_cart_png *png); /** * Frees a multi-cart and all of its resources. */ void pw_cart_free(struct pw_cart *cart); #endif