PS2SDK
PS2 Homebrew Libraries
libmc.h
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 /*
17  NOTE: These functions will work with the MCMAN/MCSERV or XMCMAN/XMCSERV
18  modules stored in rom0. The library will automatically detect which
19  module is used and will use the appropriate RPC commands accordingly.
20 
21  NOTE: These functions seem to work for both psx and ps2 memcards
22 
23  to use memcards:
24  1) first load modules (sio2man then mcman/mcserv)
25  2) call mcInit(MC_TYPE)
26  3) use mcGetInfo() to see if memcards are connected
27  4) use mcSync to check that the function has finished
28 
29  all mc* functions except mcInit() are asynchronous and require mcSync()
30  usage to test when they are done
31 */
32 
33 #ifndef __LIBMC_H__
34 #define __LIBMC_H__
35 
36 #include <libmc-common.h>
37 #include <sifrpc.h>
38 
39 #define MC_WAIT 0
40 #define MC_NOWAIT 1
41 
42 #define MC_TYPE_PSX sceMcTypePS1
43 #define MC_TYPE_PS2 sceMcTypePS2
44 #define MC_TYPE_POCKET sceMcTypePDA
45 #define MC_TYPE_NONE sceMcTypeNoCard
46 
47 #define MC_FORMATTED 1
48 #define MC_UNFORMATTED 0
49 
50 // Valid bits in memcard file attributes (mctable.AttrFile)
51 #define MC_ATTR_READABLE sceMcFileAttrReadable
52 #define MC_ATTR_WRITEABLE sceMcFileAttrWriteable
53 #define MC_ATTR_EXECUTABLE sceMcFileAttrExecutable
54 #define MC_ATTR_PROTECTED sceMcFileAttrDupProhibit
55 #define MC_ATTR_FILE sceMcFileAttrFile
56 #define MC_ATTR_SUBDIR sceMcFileAttrSubdir
57 
58 #define MC_ATTR_OBJECT (sceMcFileAttrFile|sceMcFileAttrSubdir)
59 #define MC_ATTR_CLOSED sceMcFileAttrClosed
60 #define MC_ATTR_PDAEXEC sceMcFileAttrPDAExec
61 #define MC_ATTR_PSX sceMcFileAttrPS1
62 
63 #define MC_ATTR_HIDDEN sceMcFileAttrHidden
64 
67  MC_FUNC_NONE = 0x00,
68  MC_FUNC_GET_INFO,
69  MC_FUNC_OPEN,
70  MC_FUNC_CLOSE,
71  MC_FUNC_SEEK,
72  MC_FUNC_READ,
73  MC_FUNC_WRITE,
74  MC_FUNC_FLUSH = 0x0A,
75  MC_FUNC_MK_DIR,
76  MC_FUNC_CH_DIR,
77  MC_FUNC_GET_DIR,
78  MC_FUNC_SET_INFO,
79  MC_FUNC_DELETE,
80  MC_FUNC_FORMAT,
81  MC_FUNC_UNFORMAT,
82  MC_FUNC_GET_ENT,
83  MC_FUNC_RENAME,
84  MC_FUNC_CHG_PRITY,
85  MC_FUNC_ERASE_BLOCK = 0x5A,
86  MC_FUNC_READ_PAGE,
87  MC_FUNC_WRITE_PAGE,
88 };
89 
97  MCICON_TYPE_SAVED_DATA = 0, // "Saved Data (PlayStation(r)2)"
98  MCICON_TYPE_SOFTWARE_PS2, // "Software (PlayStation(r)2)"
99  MCICON_TYPE_SOFTWARE_PKT, // "Software (PocketStation(r))"
100  MCICON_TYPE_SETTINGS_DATA, // "Settings File (PlayStation(r)2)"
101  MCICON_TYPE_SYSTEM_DRIVER // "System driver"; Implemented on SCPH-5XXXX, previous models can't recognize it unless HDD-OSD is active
102 };
103 
104 typedef int iconIVECTOR[4];
105 typedef float iconFVECTOR[4];
106 
107 typedef struct
108 {
110  unsigned char head[4];
112  unsigned short type;
114  unsigned short nlOffset;
116  unsigned unknown2;
118  unsigned trans;
120  iconIVECTOR bgCol[4];
122  iconFVECTOR lightDir[3];
124  iconFVECTOR lightCol[3];
126  iconFVECTOR lightAmbient;
128  unsigned short title[34];
130  unsigned char view[64];
132  unsigned char copy[64];
134  unsigned char del[64];
136  unsigned char unknown3[512];
137 } mcIcon;
138 
139 typedef struct _sceMcTblGetDir { // size = 64
140  sceMcStDateTime _Create; // 0
141  sceMcStDateTime _Modify; // 8
142  u32 FileSizeByte; // 16
143  u16 AttrFile; // 20
144  u16 Reserve1; // 22
145  u32 Reserve2; // 24
146  u32 PdaAplNo; // 28
147  unsigned char EntryName[32]; // 32
149 
150 typedef struct
151 {
152  struct
153  {
154  unsigned char unknown1;
156  unsigned char sec;
158  unsigned char min;
160  unsigned char hour;
162  unsigned char day;
164  unsigned char month;
166  unsigned short year;
167  } _create;
168 
169  struct
170  {
171  unsigned char unknown2;
173  unsigned char sec;
175  unsigned char min;
177  unsigned char hour;
179  unsigned char day;
181  unsigned char month;
183  unsigned short year;
184  } _modify;
185 
187  unsigned fileSizeByte;
189  unsigned short attrFile;
190  unsigned short unknown3;
191  unsigned unknown4[2];
193  unsigned char name[32];
194 } mcTable __attribute__((deprecated, aligned (64)));
195 
196 // values to send to mcInit() to use either mcserv or xmcserv
197 // These definitions are retained for backwards compatibility
198 #define MC_TYPE_MC 0
199 #define MC_TYPE_XMC 1
200 
201 #ifdef __cplusplus
202 extern "C" {
203 #endif
204 
210 extern int mcInit(int type);
211 
225 extern int mcGetInfo(int port, int slot, int* type, int* free, int* format);
226 
237 extern int mcOpen(int port, int slot, const char *name, int mode);
238 
246 extern int mcClose(int fd);
247 
257 extern int mcSeek(int fd, int offset, int origin);
258 
259 
269 extern int mcRead(int fd, void *buffer, int size);
270 
280 extern int mcWrite(int fd, const void *buffer, int size);
281 
289 extern int mcFlush(int fd);
290 
300 extern int mcMkDir(int port, int slot, const char* name);
301 
313 extern int mcChdir(int port, int slot, const char* newDir, char* currentDir);
314 
328 extern int mcGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir* table);
329 
341 extern int mcSetFileInfo(int port, int slot, const char* name, const sceMcTblGetDir* info, unsigned flags);
342 
352 extern int mcDelete(int port, int slot, const char *name);
353 
362 extern int mcFormat(int port, int slot);
363 
372 extern int mcUnformat(int port, int slot);
373 
383 extern int mcGetEntSpace(int port, int slot, const char* path);
384 
396 extern int mcRename(int port, int slot, const char* oldName, const char* newName);
397 
409 extern int mcEraseBlock(int port, int slot, int block, int mode);
410 
422 extern int mcReadPage(int port, int slot, unsigned int page, void *buffer);
423 
435 extern int mcWritePage(int port, int slot, int page, const void *buffer);
436 
446 extern int mcChangeThreadPriority(int level);
447 
455 extern int mcSync(int mode, int *cmd, int *result);
456 
461 extern int mcReset(void);
462 
467 extern int xfromInit(int type);
468 
482 extern int xfromGetInfo(int port, int slot, int* type, int* free, int* format);
483 
494 extern int xfromOpen(int port, int slot, const char *name, int mode);
495 
503 extern int xfromClose(int fd);
504 
514 extern int xfromSeek(int fd, int offset, int origin);
515 
516 
526 extern int xfromRead(int fd, void *buffer, int size);
527 
537 extern int xfromWrite(int fd, const void *buffer, int size);
538 
546 extern int xfromFlush(int fd);
547 
557 extern int xfromMkDir(int port, int slot, const char* name);
558 
570 extern int xfromChdir(int port, int slot, const char* newDir, char* currentDir);
571 
585 extern int xfromGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir* table);
586 
598 extern int xfromSetFileInfo(int port, int slot, const char* name, const sceMcTblGetDir* info, unsigned flags);
599 
609 extern int xfromDelete(int port, int slot, const char *name);
610 
619 extern int xfromFormat(int port, int slot);
620 
629 extern int xfromUnformat(int port, int slot);
630 
640 extern int xfromGetEntSpace(int port, int slot, const char* path);
641 
652 extern int xfromRename(int port, int slot, const char* oldName, const char* newName);
653 
665 extern int xfromEraseBlock(int port, int slot, int block, int mode);
666 
678 extern int xfromReadPage(int port, int slot, unsigned int page, void *buffer);
679 
691 extern int xfromWritePage(int port, int slot, int page, const void *buffer);
692 
701 extern int xfromChangeThreadPriority(int level);
702 
710 extern int xfromSync(int mode, int *cmd, int *result);
711 
716 extern int xfromReset(void);
717 
718 #ifdef __cplusplus
719 }
720 #endif
721 
722 #endif /* __LIBMC_H__ */
xfromReadPage
int xfromReadPage(int port, int slot, unsigned int page, void *buffer)
Definition: libmc.c:1178
mcSync
int mcSync(int mode, int *cmd, int *result)
Definition: libmc.c:1017
xfromDelete
int xfromDelete(int port, int slot, const char *name)
Definition: libmc.c:1130
mcRename
int mcRename(int port, int slot, const char *oldName, const char *newName)
Definition: libmc.c:977
mcTable
Definition: libmc.h:150
xfromEraseBlock
int xfromEraseBlock(int port, int slot, int block, int mode)
Definition: libmc.c:1170
s_info
Definition: xprintf.c:78
mcTable::attrFile
unsigned short attrFile
Definition: libmc.h:189
mcChdir
int mcChdir(int port, int slot, const char *newDir, char *currentDir)
Definition: libmc.c:921
xfromFlush
int xfromFlush(int fd)
Definition: libmc.c:1090
MC_FUNC_NUMBERS
MC_FUNC_NUMBERS
Definition: libmc.h:66
mcIcon::nlOffset
unsigned short nlOffset
Definition: libmc.h:114
mcIcon::trans
unsigned trans
Definition: libmc.h:118
xfromSync
int xfromSync(int mode, int *cmd, int *result)
Definition: libmc.c:1202
mcReadPage
int mcReadPage(int port, int slot, unsigned int page, void *buffer)
Definition: libmc.c:993
xfromClose
int xfromClose(int fd)
Definition: libmc.c:1058
mcGetDir
int mcGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir *table)
Definition: libmc.c:929
xfromWrite
int xfromWrite(int fd, const void *buffer, int size)
Definition: libmc.c:1082
_sceMcTblGetDir
Definition: libmc.h:139
mcClose
int mcClose(int fd)
Definition: libmc.c:873
mcReset
int mcReset(void)
Definition: libmc.c:1025
mcWrite
int mcWrite(int fd, const void *buffer, int size)
Definition: libmc.c:897
mcGetEntSpace
int mcGetEntSpace(int port, int slot, const char *path)
Definition: libmc.c:969
mcSetFileInfo
int mcSetFileInfo(int port, int slot, const char *name, const sceMcTblGetDir *info, unsigned flags)
Definition: libmc.c:937
xfromWritePage
int xfromWritePage(int port, int slot, int page, const void *buffer)
Definition: libmc.c:1186
xfromOpen
int xfromOpen(int port, int slot, const char *name, int mode)
Definition: libmc.c:1050
xfromGetDir
int xfromGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir *table)
Definition: libmc.c:1114
xfromFormat
int xfromFormat(int port, int slot)
Definition: libmc.c:1138
mcFormat
int mcFormat(int port, int slot)
Definition: libmc.c:953
mcDelete
int mcDelete(int port, int slot, const char *name)
Definition: libmc.c:945
mcUnformat
int mcUnformat(int port, int slot)
Definition: libmc.c:961
mcIcon::unknown2
unsigned unknown2
Definition: libmc.h:116
xfromSetFileInfo
int xfromSetFileInfo(int port, int slot, const char *name, const sceMcTblGetDir *info, unsigned flags)
Definition: libmc.c:1122
mcSeek
int mcSeek(int fd, int offset, int origin)
Definition: libmc.c:881
xfromInit
int xfromInit(int type)
Definition: libmc.c:1033
MCICON_TYPES
MCICON_TYPES
Definition: libmc.h:96
mcOpen
int mcOpen(int port, int slot, const char *name, int mode)
Definition: libmc.c:865
mcGetInfo
int mcGetInfo(int port, int slot, int *type, int *free, int *format)
Definition: libmc.c:857
xfromChangeThreadPriority
int xfromChangeThreadPriority(int level)
Definition: libmc.c:1194
xfromRename
int xfromRename(int port, int slot, const char *oldName, const char *newName)
Definition: libmc.c:1162
mcRead
int mcRead(int fd, void *buffer, int size)
Definition: libmc.c:889
mcChangeThreadPriority
int mcChangeThreadPriority(int level)
Definition: libmc.c:1009
xfromGetEntSpace
int xfromGetEntSpace(int port, int slot, const char *path)
Definition: libmc.c:1154
__attribute__
Definition: gif_registers.h:38
xfromRead
int xfromRead(int fd, void *buffer, int size)
Definition: libmc.c:1074
mcTable::fileSizeByte
unsigned fileSizeByte
Definition: libmc.h:187
xfromChdir
int xfromChdir(int port, int slot, const char *newDir, char *currentDir)
Definition: libmc.c:1106
xfromSeek
int xfromSeek(int fd, int offset, int origin)
Definition: libmc.c:1066
_sceMcStDateTime
Definition: libmc-common.h:22
mcEraseBlock
int mcEraseBlock(int port, int slot, int block, int mode)
Definition: libmc.c:985
mcIcon::type
unsigned short type
Definition: libmc.h:112
mcIcon
Definition: libmc.h:107
xfromGetInfo
int xfromGetInfo(int port, int slot, int *type, int *free, int *format)
Definition: libmc.c:1042
mcInit
int mcInit(int type)
Definition: libmc.c:848
libmc-common.h
xfromMkDir
int xfromMkDir(int port, int slot, const char *name)
Definition: libmc.c:1098
xfromReset
int xfromReset(void)
Definition: libmc.c:1210
mcFlush
int mcFlush(int fd)
Definition: libmc.c:905
mcWritePage
int mcWritePage(int port, int slot, int page, const void *buffer)
Definition: libmc.c:1001
mcMkDir
int mcMkDir(int port, int slot, const char *name)
Definition: libmc.c:913
xfromUnformat
int xfromUnformat(int port, int slot)
Definition: libmc.c:1146