* use alignment for clipped/wrapped text
[open-ps2-loader.git] / modules / mcemu / mcemu.h
blobc7a827cb1e824b6b5cae6544450c7dbdfc7748c1
1 /*
2 Copyright 2006-2008, Romz
3 Copyright 2010, Polo
4 Licenced under Academic Free License version 3.0
5 Review OpenUsbLd README & LICENSE files for further details.
6 */
8 #ifndef _MCEMU_H_
9 #define _MCEMU_H_
11 #include <ioman.h>
12 #include <intrman.h>
13 #include <loadcore.h>
14 #include <sifcmd.h>
15 #include <sifman.h>
16 #include <stdio.h>
17 #include <sysclib.h>
18 #include <sysmem.h>
19 #include <thbase.h>
20 #include <thsemap.h>
21 #include <iopmgr.h>
22 #include <dmacman.h>
24 #include "mcemu_utils.h"
26 #define MODNAME "mcemu"
28 // debug output is handled elsewhere
29 #ifdef DEBUG
30 #define DPRINTF(format, args...) \
31 printf(MODNAME ": " format, ## args)
32 #else
33 #define DPRINTF(format, args...) \
34 do {} while (0)
35 #endif
37 /* mcemu.c */
39 /* type for a pointer to the SECRMAN's entry SecrAuthCard */
40 typedef int (*PtrSecrAuthCard)(int port, int slot, int cnum);
42 /* type for a pointer to LOADCORE's entry RegisterLibraryEntires */
43 typedef int (*PtrRegisterLibraryEntires)(iop_library_t *lib);
45 typedef int (*PtrMcIo)(int fd, void *buf, int nbyte);
47 /* SIO2 Packet for SIO2MAN calls */
48 typedef
49 struct _Sio2Packet
51 u32 iostatus;
52 u32 data1[4];
53 u32 data2[4];
54 u32 data3;
55 u32 ctrl[16];
56 u32 data4;
57 u32 pwr_len;
58 u32 prd_len;
59 void *pwr_buf;
60 void *prd_buf;
61 void *wrmaddr;
62 u32 wrwords;
63 u32 wrcount;
64 void *rdmaddr;
65 u32 rdwords;
66 u32 rdcount;
67 } Sio2Packet;
69 /* Apa partitions informations */
70 typedef struct {
71 u32 start;
72 u32 length;
73 } apa_parts;
75 /* Block number/count pair (used in inodes) */
76 typedef struct {
77 u32 number;
78 u16 subpart;
79 u16 count;
80 } pfs_blocks;
82 /* Memory Card Spec (do not change this structure) */
83 typedef
84 struct _McSpec
86 u16 PageSize; /* Page size in bytes (user data only) */
87 u16 BlockSize; /* Block size in pages */
88 u32 CardSize; /* Total number of pages */
89 } McSpec;
91 /* Virtual Memory Card Image File Spec */
92 typedef
93 struct _McImageSpec
95 int active; /* Activation flag */
97 #ifdef USB_DRIVER
98 u32 stsec; /* Vmc file start sector */
99 #endif
101 #ifdef HDD_DRIVER
102 apa_parts parts[5]; /* Vmc file Apa partitions */
103 pfs_blocks blocks[10]; /* Vmc file Pfs inode blocks */
104 #endif
106 #ifdef SMB_DRIVER
107 char fname[32]; /* Vmc file name (memorycard?.bin) */
108 u16 fid; /* SMB Vmc file id */
109 #endif
111 int flags; /* Memory Card Flags */
112 McSpec cspec; /* Memory Card Spec */
113 } McImageSpec;
115 /* Descriptor for a virtual memory card */
116 typedef
117 struct _MemoryCard
119 int mcnum; /* Memory Card Number (-1 if inactive) */
120 int rpage; /* Read page index */
121 int rdoff; /* Read offset in rpage */
122 int wpage; /* Write page index */
123 int wroff; /* Write offset in wpage */
124 u8 *dbufp; /* Pointer to a user-data buffer */
125 u8 *cbufp; /* Pointer to a ECC buffer */
126 int rcoff; /* Read ECC offset */
127 int wcoff; /* Write ECC offset */
128 int tcode; /* Termination code */
129 McSpec cspec; /* Memory Card Spec */
130 int flags; /* Memory Card Flags */
131 } MemoryCard;
133 /* type for a pointer to SIO2MAN's entries */
134 typedef void (*Sio2McProc)(Sio2Packet *arg);
136 int DummySecrAuthCard(int port, int slot, int cnum);
137 void Sio2McEmu(Sio2Packet *sd);
139 int hookSecrAuthCard(int port, int slot, int cnum);
140 void hookSio2man25(Sio2Packet *sd);
141 void hookSio2man51(Sio2Packet *sd);
142 u32 *hookSio2man67();
143 void hookSio2man(Sio2Packet *sd, Sio2McProc sio2proc);
144 int hookRegisterLibraryEntires(iop_library_t *lib);
146 void InstallSecrmanHook(void *exp);
147 void InstallSio2manHook(void *exp);
148 void InstallMcmanHook(void *exp);
150 void SioResponse(MemoryCard *mcd, void *buf, int length);
151 int MceEraseBlock(MemoryCard *mcd, int page);
152 int MceStartRead(MemoryCard *mcd, int page);
153 int MceStartWrite(MemoryCard *mcd, int page);
154 int MceRead(MemoryCard *mcd, void *buf, u32 size);
155 int MceWrite(MemoryCard *mcd, void *buf, u32 size);
157 /* mcemu_io.c */
159 int mc_configure(MemoryCard *mcs);
160 int mc_read(int mc_num, void *buf, u32 page_num);
161 int mc_write(int mc_num, void *buf, u32 page_num);
165 /* mcemu_rpc.c */
167 /* EE RPC id for libmc calls */
168 #define LIBMC_RPCNO 0x80000400
170 /* size of RPC buffer */
171 #define LIBMC_RPC_BUFFER_SIZE 0x80
173 int hookMcman62();
174 int hookMcman63(int fd, u32 eeaddr, int nbyte);
175 int hookMcman68(int fd, u32 eeaddr, int nbyte);
179 /* mcemu_sys.c */
181 void *GetExportTable(char *libname, int version);
182 u32 GetExportTableSize(void *table);
183 void *GetExportEntry(void *table, u32 entry);
184 void *HookExportEntry(void *table, u32 entry, void *func);
186 void *_SysAlloc(u64 size);
187 int _SysFree(void *area);
189 int GetInt(void *ptr);
190 u32 CalculateEDC(u8 *buf, u32 size);
191 void CalculateECC(u8 *buf, void *chk);
193 #ifdef HDD_DRIVER
194 u32 Mcpage_to_Apasector(int mc_num, u32 mc_page);
195 #endif
197 /* mcemu_var.c */
199 #define MCEMU_PORTS 2
201 extern const u8 xortable[256];
203 extern PtrSecrAuthCard pSecrAuthCard[MCEMU_PORTS];
204 extern McImageSpec vmcSpec[MCEMU_PORTS];
205 extern MemoryCard memcards[MCEMU_PORTS];
206 extern void *pFastBuf;
208 extern PtrRegisterLibraryEntires pRegisterLibraryEntires;
209 extern Sio2McProc pSio2man25, pSio2man51;
210 extern void (*pSio2man67)();
212 extern u8 mceccbuf[MCEMU_PORTS][0x20];
213 extern u8 mcdatabuf[0x200];
215 extern SifRpcClientData_t *pClientData;
216 extern void *pFastRpcBuf;
218 extern PtrMcIo pMcRead, pMcWrite;
220 #endif //_MCEMU_H_