libdragon
|
Files | |
file | mempak.c |
Controller Pak Filesystem Routine. | |
file | mempak.h |
Controller Pak Filesystem Routines. | |
Data Structures | |
struct | entry_structure_t |
Structure representing a save entry on a Controller Pak. More... | |
Macros | |
#define | MEMPAK_BLOCK_SIZE 256 |
Size in bytes of a Controller Pak block. | |
Functions | |
int | read_mempak_sector (int controller, int sector, uint8_t *sector_data) |
Read a sector from a Controller Pak. More... | |
int | write_mempak_sector (int controller, int sector, uint8_t *sector_data) |
Write a sector to a Controller Pak. More... | |
int | validate_mempak (int controller) |
Return whether a Controller Pak is valid. More... | |
int | get_mempak_free_space (int controller) |
Return the number of free blocks on a Controller Pak. More... | |
int | get_mempak_entry (int controller, int entry, entry_structure_t *entry_data) |
Read an entry on a Controller Pak. More... | |
int | format_mempak (int controller) |
Format a Controller Pak. More... | |
int | read_mempak_entry_data (int controller, entry_structure_t *entry, uint8_t *data) |
Read the data associated with an entry on a Controller Pak. More... | |
int | write_mempak_entry_data (int controller, entry_structure_t *entry, uint8_t *data) |
Write associated data to a Controller Pak entry. More... | |
int | delete_mempak_entry (int controller, entry_structure_t *entry) |
Delete a Controller Pak entry and associated data. More... | |
struct entry_structure_t |
Structure representing a save entry on a Controller Pak.
Data Fields | ||
---|---|---|
uint32_t | vendor | Vendor ID. |
uint16_t | game_id | Game ID. |
uint16_t | inode | Inode pointer. |
uint8_t | region | Intended region. |
uint8_t | blocks |
Number of blocks used by this entry.
|
uint8_t | valid | Validity of this entry. |
uint8_t | entry_id | ID of this entry. |
char | name[19] |
Name of this entry. The complete list of valid ASCII characters in a note name is: ABCDEFGHIJKLMNOPQRSTUVWXYZ!"#`*+,-./:=?@ The space character is also allowed. Any other character will be converted to a space before writing to the Controller Pak. |
int read_mempak_sector | ( | int | controller, |
int | sector, | ||
uint8_t * | sector_data | ||
) |
Read a sector from a Controller Pak.
This will read a sector from a Controller Pak. Sectors on Controller Paks are always 256 bytes in size.
[in] | controller | The controller (0-3) to read a sector from |
[in] | sector | The sector (0-127) to read from |
[out] | sector_data | Buffer to place 256 read bytes of data |
0 | if reading was successful |
-1 | if the sector was out of bounds or sector_data was null |
-2 | if there was an error reading part of a sector |
int write_mempak_sector | ( | int | controller, |
int | sector, | ||
uint8_t * | sector_data | ||
) |
Write a sector to a Controller Pak.
This will write a sector to a Controller Pak. Sectors on Controller Paks are always 256 bytes in size.
[in] | controller | The controller (0-3) to write a sector to |
[in] | sector | The sector (0-127) to write to |
[out] | sector_data | Buffer containing 256 bytes of data to write to sector |
0 | if writing was successful |
-1 | if the sector was out of bounds or sector_data was null |
-2 | if there was an error writing part of a sector |
int validate_mempak | ( | int | controller | ) |
Return whether a Controller Pak is valid.
This function will return whether the Controller Pak in a particular controller is formatted and valid.
[in] | controller | The controller (0-3) to validate |
0 | if the Controller Pak is valid and ready to be used |
-2 | if the Controller Pak is not present or couldn't be read |
-3 | if the Controller Pak is bad or unformatted |
int get_mempak_free_space | ( | int | controller | ) |
Return the number of free blocks on a Controller Pak.
Note that a block is identical in size to a sector. To calculate the number of bytes free, multiply the return of this function by MEMPAK_BLOCK_SIZE.
[in] | controller | The controller (0-3) to read the free space from |
int get_mempak_entry | ( | int | controller, |
int | entry, | ||
entry_structure_t * | entry_data | ||
) |
Read an entry on a Controller Pak.
Given an entry index (0-15), return the entry as found on the Controller Pak. If the entry is blank or invalid, the valid flag is cleared.
[in] | controller | The controller (0-3) from which the entry should be read |
[in] | entry | The entry index (0-15) to read |
[out] | entry_data | Structure containing information on the entry |
0 | if the entry was read successfully |
-1 | if the entry is out of bounds or entry_data is null |
-2 | if the Controller Pak is bad or not present |
int format_mempak | ( | int | controller | ) |
Format a Controller Pak.
Formats a Controller Pak. Should only be done to wipe a Controller Pak or to initialize the filesystem in case of a blank or corrupt Controler Pak.
[in] | controller | The controller (0-3) to format the Controller Pak on |
0 | if the Controller Pak was formatted successfully |
-2 | if the Controller Pak was not present or couldn't be formatted |
int read_mempak_entry_data | ( | int | controller, |
entry_structure_t * | entry, | ||
uint8_t * | data | ||
) |
Read the data associated with an entry on a Controller Pak.
Given a valid Controller Pak entry fetched by get_mempak_entry, retrieves the contents of the entry. The calling function must ensure that enough room is available in the passed in buffer for the entire entry. The entry structure itself contains the number of blocks used to store the data which can be multiplied by MEMPAK_BLOCK_SIZE to calculate the size of the buffer needed.
[in] | controller | The controller (0-3) to read the entry data from |
[in] | entry | The entry structure associated with the data to be read. An entry structure can be fetched based on index using get_mempak_entry |
[out] | data | The data associated with an entry |
0 | if the entry was successfully read |
-1 | if input parameters were out of bounds or the entry was corrupted somehow |
-2 | if the Controller Pak was not present or bad |
-3 | if the data couldn't be read |
int write_mempak_entry_data | ( | int | controller, |
entry_structure_t * | entry, | ||
uint8_t * | data | ||
) |
Write associated data to a Controller Pak entry.
Given a Controller Pak entry structure with a valid region, name and block count, writes the entry and associated data to the Controller Pak. This function will not overwrite any existing user data. To update an existing entry, use delete_mempak_entry followed by write_mempak_entry_data with the same entry structure.
[in] | controller | The controller (0-3) to write the entry and data to |
[in] | entry | The entry structure containing a region, name and block count |
[in] | data | The associated data to write to to the created entry |
0 | if the entry was created and written successfully |
-1 | if the parameters were invalid or the note has no length |
-2 | if the Controller Pak wasn't present or was bad |
-3 | if there was an error writing to the Controller Pak |
-4 | if there wasn't enough space to store the note |
-5 | if there is no room in the TOC to add a new entry |
int delete_mempak_entry | ( | int | controller, |
entry_structure_t * | entry | ||
) |
Delete a Controller Pak entry and associated data.
Given a valid Controller Pak entry fetched by get_mempak_entry, removes the entry and frees all associated blocks.
[in] | controller | The controller (0-3) to delete the note from |
[in] | entry | The entry structure that is to be deleted from the Controller Pak |
0 | if the entry was deleted successfully |
-1 | if the entry was invalid |
-2 | if the Controller Pak was bad or not present |