libOGC  1.0
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
Data Structures | Macros | Typedefs | Functions
card.h File Reference

Memory card subsystem. More...

#include <gctypes.h>

Data Structures

struct  _card_dir
 
struct  _card_file
 
struct  _card_stat
 

Macros

#define CARD_ANIM_BOUNCE   0x04
 
#define CARD_ANIM_LOOP   0x00
 
#define CARD_ANIM_MASK   0x04
 
#define CARD_ATTRIB_NOCOPY   0x08
 
#define CARD_ATTRIB_NOMOVE   0x10
 
#define CARD_ATTRIB_PUBLIC   0x04
 
#define CARD_BANNER_CI   0x01
 
#define CARD_BANNER_H   32
 
#define CARD_BANNER_MASK   0x03
 
#define CARD_BANNER_NONE   0x00
 
#define CARD_BANNER_RGB   0x02
 
#define CARD_BANNER_W   96
 
#define CARD_ERROR_BROKEN   -6
 
#define CARD_ERROR_BUSY   -1
 
#define CARD_ERROR_CANCELED   -14
 
#define CARD_ERROR_ENCODING   -13
 
#define CARD_ERROR_EXIST   -7
 
#define CARD_ERROR_FATAL_ERROR   -128
 
#define CARD_ERROR_INSSPACE   -9
 
#define CARD_ERROR_IOERROR   -5
 
#define CARD_ERROR_LIMIT   -11
 
#define CARD_ERROR_NAMETOOLONG   -12
 
#define CARD_ERROR_NOCARD   -3
 
#define CARD_ERROR_NOENT   -8
 
#define CARD_ERROR_NOFILE   -4
 
#define CARD_ERROR_NOPERM   -10
 
#define CARD_ERROR_READY   0
 
#define CARD_ERROR_UNLOCKED   1
 
#define CARD_ERROR_WRONGDEVICE   -2
 
#define CARD_FILENAMELEN   32
 
#define CARD_GetBannerFmt(stat)   (((stat)->banner_fmt)&CARD_BANNER_MASK)
 
#define CARD_GetIconFmt(stat, n)   (((stat)->icon_fmt>>(2*(n)))&CARD_ICON_MASK)
 
#define CARD_GetIconSpeed(stat, n)   (((stat)->icon_speed>>(2*(n)))&~CARD_SPEED_MASK);
 
#define CARD_ICON_CI   0x01
 
#define CARD_ICON_H   32
 
#define CARD_ICON_MASK   0x03
 
#define CARD_ICON_NONE   0x00
 
#define CARD_ICON_RGB   0x02
 
#define CARD_ICON_W   32
 
#define CARD_MAXFILES   128
 
#define CARD_MAXICONS   8
 
#define CARD_READSIZE   512
 
#define CARD_SetBannerFmt(stat, fmt)   ((stat)->banner_fmt = (u8)(((stat)->banner_fmt&~CARD_BANNER_MASK)|(fmt)))
 
#define CARD_SetCommentAddr(stat, addr)   ((stat)->comment_addr = (u32)(addr))
 
#define CARD_SetIconAddr(stat, addr)   ((stat)->icon_addr = (u32)(addr))
 
#define CARD_SetIconFmt(stat, n, fmt)   ((stat)->icon_fmt = (u16)(((stat)->icon_fmt&~(CARD_ICON_MASK<<(2*(n))))|((fmt)<<(2*(n)))))
 
#define CARD_SetIconSpeed(stat, n, speed)   ((stat)->icon_speed = (u16)(((stat)->icon_fmt&~(CARD_SPEED_MASK<<(2*(n))))|((speed)<<(2*(n)))))
 
#define CARD_SLOTA   0
 
#define CARD_SLOTB   1
 
#define CARD_SPEED_END   0x00
 
#define CARD_SPEED_FAST   0x01
 
#define CARD_SPEED_MASK   0x03
 
#define CARD_SPEED_MIDDLE   0x02
 
#define CARD_SPEED_SLOW   0x03
 
#define CARD_WORKAREA   (5*8*1024)
 

Typedefs

typedef struct _card_dir card_dir
 structure to hold the information of a directory entry More...
 
typedef struct _card_file card_file
 structure to hold the fileinformations upon open and for later use. More...
 
typedef struct _card_stat card_stat
 structure to hold the additional statistical informations. More...
 
typedef void(* cardcallback )(s32 chan, s32 result)
 function pointer typedef for the user's operation callback More...
 

Functions

s32 CARD_Close (card_file *file)
 Closes the file with the given card_file structure and releases the handle. More...
 
s32 CARD_Create (s32 chn, const char *filename, u32 size, card_file *file)
 Creates a new file with the given filename and fills in the fileinformations. Synchronous version. More...
 
s32 CARD_CreateAsync (s32 chn, const char *filename, u32 size, card_file *file, cardcallback callback)
 Creates a new file with the given filename and fills in the fileinformations. This function returns immediately. Asynchronous version. More...
 
s32 CARD_CreateEntry (s32 chn, card_dir *direntry, card_file *file)
 Creates a new file with the given filename and fills in the fileinformations. Synchronous version. More...
 
s32 CARD_CreateEntryAsync (s32 chn, card_dir *direntry, card_file *file, cardcallback callback)
 Creates a new file with the given filename and fills in the fileinformations. This function returns immediately. Asynchronous version. More...
 
s32 CARD_Delete (s32 chn, const char *filename)
 Deletes a file with the given filename. Synchronous version. More...
 
s32 CARD_DeleteAsync (s32 chn, const char *filename, cardcallback callback)
 Deletes a file with the given filename. This function returns immediately. Asynchronous version. More...
 
s32 CARD_DeleteEntry (s32 chn, card_dir *dir_entry)
 Deletes a file with the given directory entry informations. More...
 
s32 CARD_DeleteEntryAsync (s32 chn, card_dir *dir_entry, cardcallback callback)
 Deletes a file with the given directory entry informations. This function returns immediately. Asynchronous version. More...
 
s32 CARD_FindFirst (s32 chn, card_dir *dir, bool showall)
 Start to iterate thru the memory card's directory structure and returns the first directory entry. More...
 
s32 CARD_FindNext (card_dir *dir)
 Returns the next directory entry from the memory cards directory structure. More...
 
s32 CARD_Format (s32 chn)
 
s32 CARD_FormatAsync (s32 chn, cardcallback callback)
 
s32 CARD_GetAttributes (s32 chn, s32 fileno, u8 *attr)
 Get additional file attributes. Synchronous version. More...
 
s32 CARD_GetBlockCount (s32 chn, u32 *block_count)
 Returns the next directory entry from the memory cards directory structure. More...
 
s32 CARD_GetDirectory (s32 chn, card_dir *dir_entries, s32 *count, bool showall)
 Returns the directory entries. size of entries is max. 128. More...
 
s32 CARD_GetErrorCode (s32 chn)
 Returns the result code from the last operation. More...
 
s32 CARD_GetSectorSize (s32 chn, u32 *sector_size)
 Returns the next directory entry from the memory cards directory structure. More...
 
s32 CARD_GetStatus (s32 chn, s32 fileno, card_stat *stats)
 Get additional file statistic informations. More...
 
s32 CARD_Init (const char *gamecode, const char *company)
 Performs the initialization of the memory card subsystem. More...
 
s32 CARD_Mount (s32 chn, void *workarea, cardcallback detach_cb)
 Mounts the memory card in the slot CHN. Synchronous version. More...
 
s32 CARD_MountAsync (s32 chn, void *workarea, cardcallback detach_cb, cardcallback attach_cb)
 Mounts the memory card in the slot CHN. This function returns immediately. Asynchronous version. More...
 
s32 CARD_Open (s32 chn, const char *filename, card_file *file)
 Opens the file with the given filename and fills in the fileinformations. More...
 
s32 CARD_OpenEntry (s32 chn, card_dir *entry, card_file *file)
 Opens the file with the given filename and fills in the fileinformations. More...
 
s32 CARD_Probe (s32 chn)
 Performs a check against the desired EXI channel if a device is inserted. More...
 
s32 CARD_ProbeEx (s32 chn, s32 *mem_size, s32 *sect_size)
 Performs a check against the desired EXI channel if a memory card is inserted or mounted. More...
 
s32 CARD_Read (card_file *file, void *buffer, u32 len, u32 offset)
 Reads the data from the file into the buffer from the given offset with the given length. Synchronous version. More...
 
s32 CARD_ReadAsync (card_file *file, void *buffer, u32 len, u32 offset, cardcallback callback)
 Reads the data from the file into the buffer from the given offset with the given length. This function returns immediately. Asynchronous version. More...
 
s32 CARD_SetAttributes (s32 chn, s32 fileno, u8 attr)
 Set additional file attributes. Synchronous version. More...
 
s32 CARD_SetAttributesAsync (s32 chn, s32 fileno, u8 attr, cardcallback callback)
 Set additional file attributes. This function returns immediately. Asynchronous version. More...
 
s32 CARD_SetCompany (const char *company)
 Set additional file attributes. This function returns immediately. Asynchronous version. More...
 
s32 CARD_SetGamecode (const char *gamecode)
 Set additional file attributes. This function returns immediately. Asynchronous version. More...
 
s32 CARD_SetStatus (s32 chn, s32 fileno, card_stat *stats)
 Set additional file statistic informations. Synchronous version. More...
 
s32 CARD_SetStatusAsync (s32 chn, s32 fileno, card_stat *stats, cardcallback callback)
 Set additional file statistic informations. This function returns immediately. Asynchronous version. More...
 
s32 CARD_Unmount (s32 chn)
 Unmounts the memory card in the slot CHN and releases the EXI bus. More...
 
s32 CARD_Write (card_file *file, void *buffer, u32 len, u32 offset)
 Writes the data to the file from the buffer to the given offset with the given length. Synchronous version. More...
 
s32 CARD_WriteAsync (card_file *file, void *buffer, u32 len, u32 offset, cardcallback callback)
 Writes the data to the file from the buffer to the given offset with the given length. This function returns immediately. Asynchronous version. More...
 

Detailed Description

Memory card subsystem.

Macro Definition Documentation

#define CARD_FILENAMELEN   32

maximum filename length

#define CARD_MAXFILES   128

maximum number of files on the memory card

#define CARD_READSIZE   512

minimum size of block to read from memory card

#define CARD_WORKAREA   (5*8*1024)

minimum size of the workarea passed to Mount[Async]()

Typedef Documentation

struct card_dir

structure to hold the information of a directory entry

Parameters
chnCARD slot.
filenofile index in the card directory structure.
filelenlength of file.
filename[CARD_FILENAMELEN]name of the file on card.
gamecode[4]string identifier <=4.
company[2]string identifier <=2.
showallboolean flag whether to showall entries or ony those identified by card_gamecode and card_company, previously set within the call to CARD_Init()

structure to hold the fileinformations upon open and for later use.

Parameters
chnCARD slot.
filenumfile index in the card directory structure.
offsetoffset into the file.
lenlength of file.
iblockblock index on memory card.
struct card_stat

structure to hold the additional statistical informations.

Parameters
filename[CARD_FILENAMELEN]name of the file on card.
lenlength of file.
gamecode[4]string identifier <=4.
company[2]string identifier <=2.
banner_fmtformat of banner.
icon_addricon image address in file.
icon_speedspeed of an animated icon.
comment_addraddress in file of the comment block.
offset_banneroffset in file to the banner's image data.
offset_banner_tlutoffset in file to the banner's texture lookup table.
offset_icon[CARD_MAXICONS]array of offsets in file to the icon's image data <CARD_MAXICONS.
offset_icon_tlutoffset in file to the icons's texture lookup table.
offset_dataoffset to additional data.
void(* cardcallback)(s32 chan, s32 result)

function pointer typedef for the user's operation callback

Parameters
chanCARD slot
resultresult of operation upon call of callback.

Function Documentation

s32 CARD_Close ( card_file file)

Closes the file with the given card_file structure and releases the handle.

Parameters
[in]filepointer to the card_file structure to close.
Returns
card error codes
s32 CARD_Create ( s32  chn,
const char *  filename,
u32  size,
card_file file 
)

Creates a new file with the given filename and fills in the fileinformations. Synchronous version.

Parameters
[in]chnCARD slot
[in]filenamename of the file to create.
[in]sizesize of the newly created file.
[out]filepointer to the card_file structure. It receives the fileinformations for later usage.
Returns
card error codes
s32 CARD_CreateAsync ( s32  chn,
const char *  filename,
u32  size,
card_file file,
cardcallback  callback 
)

Creates a new file with the given filename and fills in the fileinformations. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot
[in]filenamename of the file to create.
[in]sizesize of the newly created file.
[out]filepointer to the card_file structure. It receives the fileinformations for later usage.
[in]callbackpointer to a callback function. This callback will be called when the create process has finished.
Returns
card error codes
s32 CARD_CreateEntry ( s32  chn,
card_dir entry,
card_file file 
)

Creates a new file with the given filename and fills in the fileinformations. Synchronous version.

Parameters
[in]chnCARD slot
[in]entrypointer to the directory entry to create.
[out]filepointer to the card_file structure. It receives the fileinformations for later usage.
Returns
card error codes
s32 CARD_CreateEntryAsync ( s32  chn,
card_dir entry,
card_file file,
cardcallback  callback 
)

Creates a new file with the given filename and fills in the fileinformations. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot
[in]entrypointer to the directory entry to create
[out]filepointer to the card_file structure. It receives the fileinformations for later usage.
[in]callbackpointer to a callback function. This callback will be called when the create process has finished.
Returns
card error codes
s32 CARD_Delete ( s32  chn,
const char *  filename 
)

Deletes a file with the given filename. Synchronous version.

Parameters
[in]chnCARD slot
[in]filenamename of the file to delete.
Returns
card error codes
s32 CARD_DeleteAsync ( s32  chn,
const char *  filename,
cardcallback  callback 
)

Deletes a file with the given filename. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot
[in]filenamename of the file to delete.
[in]callbackpointer to a callback function. This callback will be called when the delete process has finished.
Returns
card error codes
s32 CARD_DeleteEntry ( s32  chn,
card_dir dir_entry 
)

Deletes a file with the given directory entry informations.

Parameters
[in]chnCARD slot
[in]dir_entrypointer to the card_dir structure which holds the informations for the delete operation.
Returns
card error codes
s32 CARD_DeleteEntryAsync ( s32  chn,
card_dir dir_entry,
cardcallback  callback 
)

Deletes a file with the given directory entry informations. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot
[in]dir_entrypointer to the card_dir structure which holds the informations for the delete operation.
[in]callbackpointer to a callback function. This callback will be called when the delete process has finished.
Returns
card error codes
s32 CARD_FindFirst ( s32  chn,
card_dir dir,
bool  showall 
)

Start to iterate thru the memory card's directory structure and returns the first directory entry.

Parameters
[in]chnCARD slot
[out]dirpointer to card_dir structure to receive the result set.
[in]showallWhether to show all files of the memory card or only those which are identified by the company and gamecode string.
Returns
card error codes
s32 CARD_FindNext ( card_dir dir)

Returns the next directory entry from the memory cards directory structure.

Parameters
[out]dirpointer to card_dir structure to receive the result set.
Returns
card error codes
s32 CARD_Format ( s32  chn)

Not finished function

s32 CARD_FormatAsync ( s32  chn,
cardcallback  callback 
)

Not finished function

s32 CARD_GetAttributes ( s32  chn,
s32  fileno,
u8 attr 
)

Get additional file attributes. Synchronous version.

Parameters
[in]chnCARD slot.
[in]filenofile index. returned by a previous call to CARD_Open().
[out]attrpointer to receive attribute value.
Returns
card error codes
s32 CARD_GetBlockCount ( s32  chn,
u32 block_count 
)

Returns the next directory entry from the memory cards directory structure.

Parameters
[in]chnCARD slot.
[out]sector_sizepointer to receive the result.
Returns
card error codes
s32 CARD_GetDirectory ( s32  chn,
card_dir dir_entries,
s32 count,
bool  showall 
)

Returns the directory entries. size of entries is max. 128.

Parameters
[in]chnCARD slot
[out]dir_entriespointer to card_dir structure to receive the result set.
[out]countpointer to an integer to receive the counted entries.
[in]showallWhether to show all files of the memory card or only those which are identified by the company and gamecode string.
Returns
card error codes
s32 CARD_GetErrorCode ( s32  chn)

Returns the result code from the last operation.

Parameters
[in]chnCARD slot
Returns
card error codes of last operation
s32 CARD_GetSectorSize ( s32  chn,
u32 sector_size 
)

Returns the next directory entry from the memory cards directory structure.

Parameters
[in]chnCARD slot.
[out]sector_sizepointer to receive the result.
Returns
card error codes
s32 CARD_GetStatus ( s32  chn,
s32  fileno,
card_stat stats 
)

Get additional file statistic informations.

Parameters
[in]chnCARD slot.
[in]filenofile index. returned by a previous call to CARD_Open().
[out]statspointer to receive the result set.
Returns
card error codes
s32 CARD_Init ( const char *  gamecode,
const char *  company 
)

Performs the initialization of the memory card subsystem.

Parameters
[in]gamecodepointer to a 4byte long string to specify the vendors game code. May be NULL
[in]companypointer to a 2byte long string to specify the vendors company code. May be NULL
Returns
card error codes
s32 CARD_Mount ( s32  chn,
void *  workarea,
cardcallback  detach_cb 
)

Mounts the memory card in the slot CHN. Synchronous version.

Parameters
[in]chnCARD slot
[in]workareapointer to memory area to hold the cards system area. The startaddress of the workdarea should be aligned on a 32byte boundery
[in]detach_cbpointer to a callback function. This callback function will be called when the card is removed from the slot.
Returns
card error codes
s32 CARD_MountAsync ( s32  chn,
void *  workarea,
cardcallback  detach_cb,
cardcallback  attach_cb 
)

Mounts the memory card in the slot CHN. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot
[in]workareapointer to memory area to hold the cards system area. The startaddress of the workdarea should be aligned on a 32byte boundery
[in]detach_cbpointer to a callback function. This callback function will be called when the card is removed from the slot.
[in]attach_cbpointer to a callback function. This callback function will be called when the mount process has finished.
Returns
card error codes
s32 CARD_Open ( s32  chn,
const char *  filename,
card_file file 
)

Opens the file with the given filename and fills in the fileinformations.

Parameters
[in]chnCARD slot
[in]filenamename of the file to open.
[out]filepointer to the card_file structure. It receives the fileinformations for later usage.
Returns
card error codes
s32 CARD_OpenEntry ( s32  chn,
card_dir entry,
card_file file 
)

Opens the file with the given filename and fills in the fileinformations.

Parameters
[in]chnCARD slot
[in]entrypointer to the directory entry to open.
[out]filepointer to the card_file structure. It receives the fileinformations for later usage.
Returns
card error codes
s32 CARD_Probe ( s32  chn)

Performs a check against the desired EXI channel if a device is inserted.

Parameters
[in]chnCARD slot
Returns
card error codes
s32 CARD_ProbeEx ( s32  chn,
s32 mem_size,
s32 sect_size 
)

Performs a check against the desired EXI channel if a memory card is inserted or mounted.

Parameters
[in]chnCARD slot
[out]mem_sizepointer to a integer variable, ready to take the resulting value (this param is optional and can be NULL)
[out]sect_sizepointer to a integer variable, ready to take the resulting value (this param is optional and can be NULL)
Returns
card error codes
s32 CARD_Read ( card_file file,
void *  buffer,
u32  len,
u32  offset 
)

Reads the data from the file into the buffer from the given offset with the given length. Synchronous version.

Parameters
[in]filepointer to the card_file structure. It holds the fileinformations to read from.
[out]bufferpointer to memory area read-in the data. The startaddress of the buffer should be aligned to a 32byte boundery.
[in]lenlength of data to read.
[in]offsetoffset into the file to read from.
Returns
card error codes
s32 CARD_ReadAsync ( card_file file,
void *  buffer,
u32  len,
u32  offset,
cardcallback  callback 
)

Reads the data from the file into the buffer from the given offset with the given length. This function returns immediately. Asynchronous version.

Parameters
[in]filepointer to the card_file structure. It holds the fileinformations to read from.
[out]bufferpointer to memory area read-in the data. The startaddress of the buffer should be aligned to a 32byte boundery.
[in]lenlength of data to read.
[in]offsetoffset into the file to read from.
[in]callbackpointer to a callback function. This callback will be called when the read process has finished.
Returns
card error codes
s32 CARD_SetAttributes ( s32  chn,
s32  fileno,
u8  attr 
)

Set additional file attributes. Synchronous version.

Parameters
[in]chnCARD slot.
[in]filenofile index. returned by a previous call to CARD_Open().
[in]attrattribute value to set.
Returns
card error codes
s32 CARD_SetAttributesAsync ( s32  chn,
s32  fileno,
u8  attr,
cardcallback  callback 
)

Set additional file attributes. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot.
[in]filenofile index. returned by a previous call to CARD_Open().
[in]attrattribute value to set.
[in]callbackpointer to a callback function. This callback will be called when the setattributes process has finished.
Returns
card error codes
s32 CARD_SetCompany ( const char *  company)

Set additional file attributes. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot.
Returns
card error codes
s32 CARD_SetGamecode ( const char *  gamecode)

Set additional file attributes. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot.
Returns
card error codes
s32 CARD_SetStatus ( s32  chn,
s32  fileno,
card_stat stats 
)

Set additional file statistic informations. Synchronous version.

Parameters
[in]chnCARD slot.
[in]filenofile index. returned by a previous call to CARD_Open().
[out]statspointer which holds the informations to set.
Returns
card error codes
s32 CARD_SetStatusAsync ( s32  chn,
s32  fileno,
card_stat stats,
cardcallback  callback 
)

Set additional file statistic informations. This function returns immediately. Asynchronous version.

Parameters
[in]chnCARD slot.
[in]filenofile index. returned by a previous call to CARD_Open().
[out]statspointer which holds the informations to set.
[in]callbackpointer to a callback function. This callback will be called when the setstatus process has finished.
Returns
card error codes
s32 CARD_Unmount ( s32  chn)

Unmounts the memory card in the slot CHN and releases the EXI bus.

Parameters
[in]chnCARD slot
Returns
card error codes
s32 CARD_Write ( card_file file,
void *  buffer,
u32  len,
u32  offset 
)

Writes the data to the file from the buffer to the given offset with the given length. Synchronous version.

Parameters
[in]filepointer to the card_file structure which holds the fileinformations.
[in]bufferpointer to the memory area to read from. The startaddress of the buffer should be aligned on a 32byte boundery.
[in]lenlength of data to write.
[in]offsetstarting point in the file to start writing.
Returns
card error codes
s32 CARD_WriteAsync ( card_file file,
void *  buffer,
u32  len,
u32  offset,
cardcallback  callback 
)

Writes the data to the file from the buffer to the given offset with the given length. This function returns immediately. Asynchronous version.

Parameters
[in]filepointer to the card_file structure which holds the fileinformations.
[in]bufferpointer to the memory area to read from. The startaddress of the buffer should be aligned on a 32byte boundery.
[in]lenlength of data to write.
[in]offsetstarting point in the file to start writing.
[in]callbackpointer to a callback function. This callback will be called when the write process has finished.
Returns
card error codes