Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
memcard.h File Reference

Memory card saves (memcard/) More...

#include "common.h"
#include <sys/types.h>
#include <libgte.h>
#include <libgpu.h>
Include dependency graph for memcard.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CardClut
 Memory card save header (first CARD_SECTOR_SIZE bytes of a save) More...
 
struct  CardHeader
 
struct  CardDirEntry
 Same layout as the kernel's struct DIRENTRY. More...
 
struct  MemCard
 Memory card access (MEMCARD), one step per call: every operation returns 0 while it runs, 1 when it succeeds and result + 1 when it fails. More...
 
struct  MemCardFuncs
 The memory card functions (MEMCARD_FUNCS); like MemCard's operations, the card ones return 0 while they run. More...
 

Macros

#define CARD_SECTOR_SIZE   0x80
 The bytes the card reads or writes at once: one sector.
 
#define SAVE_BLOCKS   4
 The blocks of the save file.
 
#define SAVE_MAX_ICONS   3
 The icon frames a save may have.
 
#define CARD_HEADER_ICONS   0x10
 CardHeader.type: this flag plus the icon frame count.
 
#define CARD_MAX_FILES   15
 The files MEMCARD lists from a card's directory.
 
#define CARD_ERR_NONE   0
 MemCard.result, as libmcrd's MemCardSync reports it (McErr*), plus CARD_ERR_NOT_STARTED when the command could not even be sent.
 
#define CARD_ERR_NO_CARD   1
 
#define CARD_ERR_INVALID   2
 McErrCardInvalid: "Cannot access Memory Card".
 
#define CARD_ERR_NEW_CARD   3
 
#define CARD_ERR_UNFORMATTED   4
 
#define CARD_ERR_NO_FILE   5
 McErrFileNotExist: "File cannot be found".
 
#define CARD_ERR_FILE_EXISTS   6
 McErrAlreadyExist: "File already exists".
 
#define CARD_ERR_FULL   7
 McErrBlockFull: "There are not enough blocks".
 
#define CARD_ERR_NOT_STARTED   8
 

Enumerations

enum  MemCardState {
  MEMCARD_IDLE , MEMCARD_CHECKING , MEMCARD_ACCEPTING , MEMCARD_READING ,
  MEMCARD_WRITING , MEMCARD_COMMAND
}
 MemCard.state: idle, or waiting for the command each operation sent. More...
 
enum  SaveSection { SAVE_SECTION_HEADER , SAVE_SECTION_INFO , SAVE_SECTION_DATA }
 readSave and writeSave's sections: the header, the info, then the data copies More...
 
enum  MemCardOp { MEMCARD_OP_LIST , MEMCARD_OP_CREATE , MEMCARD_OP_FORMAT , MEMCARD_OP_UNFORMAT }
 memCardCommand's operations More...
 

Functions

void initMemCard (void)
 Starts libmcrd and sets up MEMCARD: the save file name and the section sizes.
 
void setSaveFileName (void)
 
void setSaveHeader (char *title, CardClut *clut, s32 count, void **icons)
 The save file header: title (Shift-JIS), icon CLUT and 1-3 icon frames.
 
s32 memCardCommand (s32 port, s32 op)
 Reads the directory, creates the save file, formats or unformats (MEMCARD_OP_*)
 
s32 listSaves (s32 port)
 Reads the card's directory into MEMCARD.files.
 
s32 createSave (s32 port)
 Creates the save file on the card.
 
s32 formatMemCard (s32 port)
 Formats an unformatted card.
 
s32 unformatMemCard (void)
 memCardCommand's MEMCARD_OP_UNFORMAT, left out: always fails as if there were no card
 
s32 verifyChecksum (void *data, s32 size, char expected)
 XOR of every byte.
 
u8 computeChecksum (void *data, s32 size)
 The XOR of every byte, which verifyChecksum checks.
 
s32 checkMemCard (s32 port)
 Checks whether a card is in port port (MemCardExist)
 
s32 acceptMemCard (s32 port)
 Checks a card in port port in full, finding out whether it is new or unformatted (MemCardAccept)
 
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.
 
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)
 
s32 syncMemCard (void)
 MemCardSync, retrying a failed command up to maxRetries times.
 
void MemCardInit (long val)
 The memory card library, declared here rather than from libmcrd.h, which takes the buffers as u_long * and MemCardSync's result as a long *, where the game passes u8 buffers and compares the result unsigned.
 
void MemCardStart (void)
 
long MemCardSync (long mode, long *cmds, u_long *result)
 
long MemCardExist (long chan)
 
long MemCardAccept (long chan)
 
long MemCardCreateFile (long chan, const char *file, long blocks)
 
long MemCardFormat (long chan)
 
long MemCardReadFile (long chan, const char *file, void *adrs, long ofs, long bytes)
 
long MemCardWriteFile (long chan, const char *file, void *adrs, long ofs, long bytes)
 
long MemCardUnformat (long chan)
 
long MemCardGetDirentry (long chan, char *name, CardDirEntry *dir, long *files, long ofs, long max)
 

Variables

MemCard MEMCARD
 
MemCardFuncs MEMCARD_FUNCS
 
s32 MEMCARD_SYNC_CMDS []
 the MemCardSync command of each MEMCARD_OP_*
 
char STR_ALL_FILES []
 the directory pattern that matches every file
 

Detailed Description

Memory card saves (memcard/)

Definition in file memcard.h.

Macro Definition Documentation

◆ CARD_SECTOR_SIZE

#define CARD_SECTOR_SIZE   0x80

The bytes the card reads or writes at once: one sector.

Definition at line 12 of file memcard.h.

◆ SAVE_BLOCKS

#define SAVE_BLOCKS   4

The blocks of the save file.

Definition at line 15 of file memcard.h.

◆ SAVE_MAX_ICONS

#define SAVE_MAX_ICONS   3

The icon frames a save may have.

Definition at line 18 of file memcard.h.

◆ CARD_HEADER_ICONS

#define CARD_HEADER_ICONS   0x10

CardHeader.type: this flag plus the icon frame count.

Definition at line 21 of file memcard.h.

◆ CARD_MAX_FILES

#define CARD_MAX_FILES   15

The files MEMCARD lists from a card's directory.

Definition at line 24 of file memcard.h.

◆ CARD_ERR_NONE

#define CARD_ERR_NONE   0

MemCard.result, as libmcrd's MemCardSync reports it (McErr*), plus CARD_ERR_NOT_STARTED when the command could not even be sent.

Definition at line 30 of file memcard.h.

◆ CARD_ERR_NO_CARD

#define CARD_ERR_NO_CARD   1

Definition at line 31 of file memcard.h.

◆ CARD_ERR_INVALID

#define CARD_ERR_INVALID   2

McErrCardInvalid: "Cannot access Memory Card".

Definition at line 32 of file memcard.h.

◆ CARD_ERR_NEW_CARD

#define CARD_ERR_NEW_CARD   3

Definition at line 33 of file memcard.h.

◆ CARD_ERR_UNFORMATTED

#define CARD_ERR_UNFORMATTED   4

Definition at line 34 of file memcard.h.

◆ CARD_ERR_NO_FILE

#define CARD_ERR_NO_FILE   5

McErrFileNotExist: "File cannot be found".

Definition at line 35 of file memcard.h.

◆ CARD_ERR_FILE_EXISTS

#define CARD_ERR_FILE_EXISTS   6

McErrAlreadyExist: "File already exists".

Definition at line 36 of file memcard.h.

◆ CARD_ERR_FULL

#define CARD_ERR_FULL   7

McErrBlockFull: "There are not enough blocks".

Definition at line 37 of file memcard.h.

◆ CARD_ERR_NOT_STARTED

#define CARD_ERR_NOT_STARTED   8

Definition at line 38 of file memcard.h.

Enumeration Type Documentation

◆ MemCardState

MemCard.state: idle, or waiting for the command each operation sent.

Enumerator
MEMCARD_IDLE 
MEMCARD_CHECKING 
MEMCARD_ACCEPTING 
MEMCARD_READING 
MEMCARD_WRITING 
MEMCARD_COMMAND 

Definition at line 41 of file memcard.h.

◆ SaveSection

readSave and writeSave's sections: the header, the info, then the data copies

Enumerator
SAVE_SECTION_HEADER 
SAVE_SECTION_INFO 
SAVE_SECTION_DATA 

Definition at line 51 of file memcard.h.

◆ MemCardOp

enum MemCardOp

memCardCommand's operations

Enumerator
MEMCARD_OP_LIST 
MEMCARD_OP_CREATE 
MEMCARD_OP_FORMAT 
MEMCARD_OP_UNFORMAT 

Definition at line 54 of file memcard.h.

Function Documentation

◆ initMemCard()

void initMemCard ( void  )

Starts libmcrd and sets up MEMCARD: the save file name and the section sizes.

Definition at line 7 of file memcard.c.

Here is the call graph for this function:

◆ setSaveFileName()

void setSaveFileName ( void  )

Definition at line 57 of file memcard.c.

Referenced by initMemCard().

Here is the caller graph for this function:

◆ setSaveHeader()

void setSaveHeader ( char *  title,
CardClut *  clut,
s32  count,
void **  icons 
)

The save file header: title (Shift-JIS), icon CLUT and 1-3 icon frames.

Definition at line 86 of file memcard.c.

Here is the call graph for this function:

◆ memCardCommand()

s32 memCardCommand ( s32  port,
s32  op 
)

Reads the directory, creates the save file, formats or unformats (MEMCARD_OP_*)

Definition at line 351 of file memcard.c.

Referenced by createSave(), formatMemCard(), and listSaves().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ listSaves()

s32 listSaves ( s32  port)

Reads the card's directory into MEMCARD.files.

Definition at line 408 of file memcard.c.

Here is the call graph for this function:

◆ createSave()

s32 createSave ( s32  port)

Creates the save file on the card.

Definition at line 418 of file memcard.c.

Here is the call graph for this function:

◆ formatMemCard()

s32 formatMemCard ( s32  port)

Formats an unformatted card.

Definition at line 428 of file memcard.c.

Here is the call graph for this function:

◆ unformatMemCard()

s32 unformatMemCard ( void  )

memCardCommand's MEMCARD_OP_UNFORMAT, left out: always fails as if there were no card

Definition at line 438 of file memcard.c.

◆ verifyChecksum()

s32 verifyChecksum ( void *  data,
s32  size,
char  expected 
)

XOR of every byte.

Definition at line 443 of file memcard.c.

◆ computeChecksum()

u8 computeChecksum ( void *  data,
s32  size 
)

The XOR of every byte, which verifyChecksum checks.

Definition at line 455 of file memcard.c.

◆ checkMemCard()

s32 checkMemCard ( s32  port)

Checks whether a card is in port port (MemCardExist)

Definition at line 128 of file memcard.c.

Referenced by readSave(), and writeSave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ acceptMemCard()

s32 acceptMemCard ( s32  port)

Checks a card in port port in full, finding out whether it is new or unformatted (MemCardAccept)

Definition at line 160 of file memcard.c.

Referenced by memCardCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readSave()

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.

Definition at line 189 of file memcard.c.

Here is the call graph for this function:

◆ writeSave()

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)

Definition at line 270 of file memcard.c.

Here is the call graph for this function:

◆ syncMemCard()

s32 syncMemCard ( void  )

MemCardSync, retrying a failed command up to maxRetries times.

Definition at line 105 of file memcard.c.

Referenced by acceptMemCard(), checkMemCard(), readSave(), and writeSave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MemCardInit()

void MemCardInit ( long  val)

The memory card library, declared here rather than from libmcrd.h, which takes the buffers as u_long * and MemCardSync's result as a long *, where the game passes u8 buffers and compares the result unsigned.

Referenced by initMemCard().

Here is the caller graph for this function:

◆ MemCardStart()

void MemCardStart ( void  )

Referenced by initMemCard().

Here is the caller graph for this function:

◆ MemCardSync()

long MemCardSync ( long  mode,
long *  cmds,
u_long *  result 
)

Referenced by syncMemCard().

Here is the caller graph for this function:

◆ MemCardExist()

long MemCardExist ( long  chan)

Referenced by checkMemCard().

Here is the caller graph for this function:

◆ MemCardAccept()

long MemCardAccept ( long  chan)

Referenced by acceptMemCard().

Here is the caller graph for this function:

◆ MemCardCreateFile()

long MemCardCreateFile ( long  chan,
const char *  file,
long  blocks 
)

Referenced by memCardCommand().

Here is the caller graph for this function:

◆ MemCardFormat()

long MemCardFormat ( long  chan)

Referenced by memCardCommand().

Here is the caller graph for this function:

◆ MemCardReadFile()

long MemCardReadFile ( long  chan,
const char *  file,
void *  adrs,
long  ofs,
long  bytes 
)

Referenced by readSave().

Here is the caller graph for this function:

◆ MemCardWriteFile()

long MemCardWriteFile ( long  chan,
const char *  file,
void *  adrs,
long  ofs,
long  bytes 
)

Referenced by writeSave().

Here is the caller graph for this function:

◆ MemCardUnformat()

long MemCardUnformat ( long  chan)

Referenced by memCardCommand().

Here is the caller graph for this function:

◆ MemCardGetDirentry()

long MemCardGetDirentry ( long  chan,
char *  name,
CardDirEntry *  dir,
long *  files,
long  ofs,
long  max 
)

Referenced by memCardCommand().

Here is the caller graph for this function:

Variable Documentation

◆ MEMCARD

◆ MEMCARD_FUNCS

◆ MEMCARD_SYNC_CMDS

s32 MEMCARD_SYNC_CMDS[]
extern

the MemCardSync command of each MEMCARD_OP_*

the MemCardSync command of each MEMCARD_OP_*

Definition at line 474 of file memcard.c.

Referenced by memCardCommand().

◆ STR_ALL_FILES

char STR_ALL_FILES[]
extern

the directory pattern that matches every file

the directory pattern that matches every file

memcard/memcard.c reads STR_ALL_FILES through its address, so it is not its small data; and 16 bytes are too many for one small variable, so the original had more than one here: "*", 8 bytes of zeros and an unread grey (128, 128, 128). The attribute puts the 16 bytes where they were.

Definition at line 11 of file all_files_pattern.c.

Referenced by memCardCommand().