12#define CARD_SECTOR_SIZE 0x80
18#define SAVE_MAX_ICONS 3
21#define CARD_HEADER_ICONS 0x10
24#define CARD_MAX_FILES 15
30#define CARD_ERR_NONE 0
31#define CARD_ERR_NO_CARD 1
32#define CARD_ERR_INVALID 2
33#define CARD_ERR_NEW_CARD 3
34#define CARD_ERR_UNFORMATTED 4
35#define CARD_ERR_NO_FILE 5
36#define CARD_ERR_FILE_EXISTS 6
37#define CARD_ERR_FULL 7
38#define CARD_ERR_NOT_STARTED 8
long MemCardCreateFile(long chan, const char *file, long blocks)
long MemCardAccept(long chan)
u8 computeChecksum(void *data, s32 size)
The XOR of every byte, which verifyChecksum checks.
SaveSection
readSave and writeSave's sections: the header, the info, then the data copies
s32 writeSave(s32 port, void *buf, s32 size, s32 section)
Writes a section (as readSave; section 0 takes the offset from bits 8 and up)
MemCardFuncs MEMCARD_FUNCS
s32 memCardCommand(s32 port, s32 op)
Reads the directory, creates the save file, formats or unformats (MEMCARD_OP_*)
void MemCardInit(long val)
The memory card library, declared here rather than from libmcrd.h, which takes the buffers as u_long ...
long MemCardReadFile(long chan, const char *file, void *adrs, long ofs, long bytes)
void setSaveHeader(char *title, CardClut *clut, s32 count, void **icons)
The save file header: title (Shift-JIS), icon CLUT and 1-3 icon frames.
long MemCardGetDirentry(long chan, char *name, CardDirEntry *dir, long *files, long ofs, long max)
s32 checkMemCard(s32 port)
Checks whether a card is in port port (MemCardExist)
long MemCardUnformat(long chan)
s32 formatMemCard(s32 port)
Formats an unformatted card.
char STR_ALL_FILES[]
the directory pattern that matches every file
long MemCardExist(long chan)
s32 readSave(s32 port, void *buf, s32 size, s32 section)
Reads a section of the save (SAVE_SECTION_*, then 2-4 for the data), a sector a call.
#define SAVE_MAX_ICONS
The icon frames a save may have.
s32 listSaves(s32 port)
Reads the card's directory into MEMCARD.files.
void setSaveFileName(void)
void initMemCard(void)
Starts libmcrd and sets up MEMCARD: the save file name and the section sizes.
MemCardOp
memCardCommand's operations
s32 syncMemCard(void)
MemCardSync, retrying a failed command up to maxRetries times.
long MemCardWriteFile(long chan, const char *file, void *adrs, long ofs, long bytes)
#define CARD_MAX_FILES
The files MEMCARD lists from a card's directory.
long MemCardSync(long mode, long *cmds, u_long *result)
s32 MEMCARD_SYNC_CMDS[]
the MemCardSync command of each MEMCARD_OP_*
s32 verifyChecksum(void *data, s32 size, char expected)
XOR of every byte.
long MemCardFormat(long chan)
s32 unformatMemCard(void)
memCardCommand's MEMCARD_OP_UNFORMAT, left out: always fails as if there were no card
MemCardState
MemCard.state: idle, or waiting for the command each operation sent.
s32 acceptMemCard(s32 port)
Checks a card in port port in full, finding out whether it is new or unformatted (MemCardAccept)
s32 createSave(s32 port)
Creates the save file on the card.
Memory card save header (first CARD_SECTOR_SIZE bytes of a save)
Same layout as the kernel's struct DIRENTRY.
struct CardDirEntry * next
The memory card functions (MEMCARD_FUNCS); like MemCard's operations, the card ones return 0 while th...
void(* setHeader)(char *title, CardClut *clut, s32 count, void **icons)
s32(* write)(s32 port, void *buf, s32 size, s32 section)
s32(* verifyChecksum)(void *data, s32 size, char expected)
void(* setFileName)(void)
u8(* computeChecksum)(void *data, s32 size)
s32(* read)(s32 port, void *buf, s32 size, s32 section)
Memory card access (MEMCARD), one step per call: every operation returns 0 while it runs,...
s32 iconIndex
the icon a save is writing (STGMCARD_runSaves)
u8 pad4[8]
never read or written
long fileCount
long: MemCardGetDirentry writes it
s32 pad308
never read or written
void * icons[3]
each frame's image (setSaveHeader)
s32 restart
the command failed and must be reissued