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 
38 #define MC_WAIT 0
39 #define MC_NOWAIT 1
40 
41 #define MC_TYPE_PSX sceMcTypePS1
42 #define MC_TYPE_PS2 sceMcTypePS2
43 #define MC_TYPE_POCKET sceMcTypePDA
44 #define MC_TYPE_NONE sceMcTypeNoCard
45 
46 #define MC_FORMATTED 1
47 #define MC_UNFORMATTED 0
48 
49 // Valid bits in memcard file attributes (mctable.AttrFile)
50 #define MC_ATTR_READABLE sceMcFileAttrReadable
51 #define MC_ATTR_WRITEABLE sceMcFileAttrWriteable
52 #define MC_ATTR_EXECUTABLE sceMcFileAttrExecutable
53 #define MC_ATTR_PROTECTED sceMcFileAttrDupProhibit
54 #define MC_ATTR_FILE sceMcFileAttrFile
55 #define MC_ATTR_SUBDIR sceMcFileAttrSubdir
56 
57 #define MC_ATTR_OBJECT (sceMcFileAttrFile|sceMcFileAttrSubdir)
58 #define MC_ATTR_CLOSED sceMcFileAttrClosed
59 #define MC_ATTR_PDAEXEC sceMcFileAttrPDAExec
60 #define MC_ATTR_PSX sceMcFileAttrPS1
61 
62 #define MC_ATTR_HIDDEN sceMcFileAttrHidden
63 
66  MC_FUNC_NONE = 0x00,
67  MC_FUNC_GET_INFO,
68  MC_FUNC_OPEN,
69  MC_FUNC_CLOSE,
70  MC_FUNC_SEEK,
71  MC_FUNC_READ,
72  MC_FUNC_WRITE,
73  MC_FUNC_FLUSH = 0x0A,
74  MC_FUNC_MK_DIR,
75  MC_FUNC_CH_DIR,
76  MC_FUNC_GET_DIR,
77  MC_FUNC_SET_INFO,
78  MC_FUNC_DELETE,
79  MC_FUNC_FORMAT,
80  MC_FUNC_UNFORMAT,
81  MC_FUNC_GET_ENT,
82  MC_FUNC_RENAME,
83  MC_FUNC_CHG_PRITY,
84  MC_FUNC_ERASE_BLOCK = 0x5A,
85  MC_FUNC_READ_PAGE,
86  MC_FUNC_WRITE_PAGE,
87 };
88 
96  MCICON_TYPE_SAVED_DATA = 0, // "Saved Data (PlayStation(r)2)"
97  MCICON_TYPE_SOFTWARE_PS2, // "Software (PlayStation(r)2)"
98  MCICON_TYPE_SOFTWARE_PKT, // "Software (PocketStation(r))"
99  MCICON_TYPE_SETTINGS_DATA, // "Settings File (PlayStation(r)2)"
100  MCICON_TYPE_SYSTEM_DRIVER // "System driver"; Implemented on SCPH-5XXXX, previous models can't recognize it unless HDD-OSD is active
101 };
102 
103 typedef int iconIVECTOR[4];
104 typedef float iconFVECTOR[4];
105 
106 typedef struct
107 {
109  unsigned char head[4];
111  unsigned short type;
113  unsigned short nlOffset;
115  unsigned unknown2;
117  unsigned trans;
119  iconIVECTOR bgCol[4];
121  iconFVECTOR lightDir[3];
123  iconFVECTOR lightCol[3];
125  iconFVECTOR lightAmbient;
127  unsigned short title[34];
129  unsigned char view[64];
131  unsigned char copy[64];
133  unsigned char del[64];
135  unsigned char unknown3[512];
136 } mcIcon;
137 
138 typedef struct _sceMcTblGetDir { // size = 64
139  sceMcStDateTime _Create; // 0
140  sceMcStDateTime _Modify; // 8
141  u32 FileSizeByte; // 16
142  u16 AttrFile; // 20
143  u16 Reserve1; // 22
144  u32 Reserve2; // 24
145  u32 PdaAplNo; // 28
146  unsigned char EntryName[32]; // 32
148 
149 typedef struct
150 {
151  struct
152  {
153  unsigned char unknown1;
155  unsigned char sec;
157  unsigned char min;
159  unsigned char hour;
161  unsigned char day;
163  unsigned char month;
165  unsigned short year;
166  } _create;
167 
168  struct
169  {
170  unsigned char unknown2;
172  unsigned char sec;
174  unsigned char min;
176  unsigned char hour;
178  unsigned char day;
180  unsigned char month;
182  unsigned short year;
183  } _modify;
184 
186  unsigned fileSizeByte;
188  unsigned short attrFile;
189  unsigned short unknown3;
190  unsigned unknown4[2];
192  unsigned char name[32];
193 } mcTable __attribute__((deprecated, aligned (64)));
194 
195 // values to send to mcInit() to use either mcserv or xmcserv
196 // These definitions are retained for backwards compatibility
197 #define MC_TYPE_MC 0
198 #define MC_TYPE_XMC 1
199 
200 #ifdef __cplusplus
201 extern "C" {
202 #endif
203 
209 extern int mcInit(int type);
210 
224 extern int mcGetInfo(int port, int slot, int* type, int* free, int* format);
225 
236 extern int mcOpen(int port, int slot, const char *name, int mode);
237 
245 extern int mcClose(int fd);
246 
256 extern int mcSeek(int fd, int offset, int origin);
257 
258 
268 extern int mcRead(int fd, void *buffer, int size);
269 
279 extern int mcWrite(int fd, const void *buffer, int size);
280 
288 extern int mcFlush(int fd);
289 
299 extern int mcMkDir(int port, int slot, const char* name);
300 
312 extern int mcChdir(int port, int slot, const char* newDir, char* currentDir);
313 
327 extern int mcGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir* table);
328 
340 extern int mcSetFileInfo(int port, int slot, const char* name, const sceMcTblGetDir* info, unsigned flags);
341 
351 extern int mcDelete(int port, int slot, const char *name);
352 
361 extern int mcFormat(int port, int slot);
362 
371 extern int mcUnformat(int port, int slot);
372 
382 extern int mcGetEntSpace(int port, int slot, const char* path);
383 
395 extern int mcRename(int port, int slot, const char* oldName, const char* newName);
396 
408 extern int mcEraseBlock(int port, int slot, int block, int mode);
409 
421 extern int mcReadPage(int port, int slot, unsigned int page, void *buffer);
422 
434 extern int mcWritePage(int port, int slot, int page, const void *buffer);
435 
445 extern int mcChangeThreadPriority(int level);
446 
454 extern int mcSync(int mode, int *cmd, int *result);
455 
460 extern int mcReset(void);
461 
462 #ifdef __cplusplus
463 }
464 #endif
465 
466 #endif /* __LIBMC_H__ */
mcSync
int mcSync(int mode, int *cmd, int *result)
Definition: libmc.c:898
mcRename
int mcRename(int port, int slot, const char *oldName, const char *newName)
Definition: libmc.c:749
mcTable
Definition: libmc.h:149
s_info
Definition: xprintf.c:78
mcTable::attrFile
unsigned short attrFile
Definition: libmc.h:188
mcChdir
int mcChdir(int port, int slot, const char *newDir, char *currentDir)
Definition: libmc.c:573
MC_FUNC_NUMBERS
MC_FUNC_NUMBERS
Definition: libmc.h:65
mcIcon::nlOffset
unsigned short nlOffset
Definition: libmc.h:113
mcIcon::trans
unsigned trans
Definition: libmc.h:117
mcReadPage
int mcReadPage(int port, int slot, unsigned int page, void *buffer)
Definition: libmc.c:821
mcGetDir
int mcGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir *table)
Definition: libmc.c:599
_sceMcTblGetDir
Definition: libmc.h:138
mcClose
int mcClose(int fd)
Definition: libmc.c:435
mcReset
int mcReset(void)
Definition: libmc.c:940
mcWrite
int mcWrite(int fd, const void *buffer, int size)
Definition: libmc.c:505
mcGetEntSpace
int mcGetEntSpace(int port, int slot, const char *path)
Definition: libmc.c:725
mcSetFileInfo
int mcSetFileInfo(int port, int slot, const char *name, const sceMcTblGetDir *info, unsigned flags)
Definition: libmc.c:627
mcFormat
int mcFormat(int port, int slot)
Definition: libmc.c:681
mcDelete
int mcDelete(int port, int slot, const char *name)
Definition: libmc.c:656
mcUnformat
int mcUnformat(int port, int slot)
Definition: libmc.c:703
mcIcon::unknown2
unsigned unknown2
Definition: libmc.h:115
mcSeek
int mcSeek(int fd, int offset, int origin)
Definition: libmc.c:456
MCICON_TYPES
MCICON_TYPES
Definition: libmc.h:95
mcOpen
int mcOpen(int port, int slot, const char *name, int mode)
Definition: libmc.c:410
mcGetInfo
int mcGetInfo(int port, int slot, int *type, int *free, int *format)
Definition: libmc.c:368
mcRead
int mcRead(int fd, void *buffer, int size)
Definition: libmc.c:479
mcChangeThreadPriority
int mcChangeThreadPriority(int level)
Definition: libmc.c:875
__attribute__
Definition: gif_registers.h:38
mcTable::fileSizeByte
unsigned fileSizeByte
Definition: libmc.h:186
_sceMcStDateTime
Definition: libmc-common.h:22
mcEraseBlock
int mcEraseBlock(int port, int slot, int block, int mode)
Definition: libmc.c:778
mcIcon::type
unsigned short type
Definition: libmc.h:111
mcIcon
Definition: libmc.h:106
mcInit
int mcInit(int type)
Definition: libmc.c:230
libmc-common.h
mcFlush
int mcFlush(int fd)
Definition: libmc.c:543
mcWritePage
int mcWritePage(int port, int slot, int page, const void *buffer)
Definition: libmc.c:846
mcMkDir
int mcMkDir(int port, int slot, const char *name)
Definition: libmc.c:564