2 Copyright 2006-2008, Romz
4 Licenced under Academic Free License version 3.0
5 Review OpenUsbLd README & LICENSE files for further details.
24 #include "mcemu_utils.h"
26 #define MODNAME "mcemu"
28 // debug output is handled elsewhere
30 #define DPRINTF(format, args...) \
31 printf(MODNAME ": " format, ## args)
33 #define DPRINTF(format, args...) \
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 */
70 /* Apa partitions informations */
76 /* Block number/count pair (used in inodes) */
84 /* Memory Card Spec (do not change this structure) */
88 u16 PageSize
; /* Page size in bytes (user data only) */
89 u16 BlockSize
; /* Block size in pages */
90 u32 CardSize
; /* Total number of pages */
93 /* Virtual Memory Card Image File Spec */
97 int active
; /* Activation flag */
100 u32 stsec
; /* Vmc file start sector */
104 apa_parts parts
[5]; /* Vmc file Apa partitions */
105 pfs_blocks blocks
[10]; /* Vmc file Pfs inode blocks */
109 char fname
[64]; /* Vmc file name (memorycard?.bin) */
110 u16 fid
; /* SMB Vmc file id */
113 int flags
; /* Memory Card Flags */
114 McSpec cspec
; /* Memory Card Spec */
117 /* Descriptor for a virtual memory card */
121 int mcnum
; /* Memory Card Number (-1 if inactive) */
122 int rpage
; /* Read page index */
123 int rdoff
; /* Read offset in rpage */
124 int wpage
; /* Write page index */
125 int wroff
; /* Write offset in wpage */
126 u8
*dbufp
; /* Pointer to a user-data buffer */
127 u8
*cbufp
; /* Pointer to a ECC buffer */
128 int rcoff
; /* Read ECC offset */
129 int wcoff
; /* Write ECC offset */
130 int tcode
; /* Termination code */
131 McSpec cspec
; /* Memory Card Spec */
132 int flags
; /* Memory Card Flags */
135 /* type for a pointer to SIO2MAN's entries */
136 typedef void (*Sio2McProc
)(Sio2Packet
*arg
);
138 int DummySecrAuthCard(int port
, int slot
, int cnum
);
139 void Sio2McEmu(Sio2Packet
*sd
);
141 int hookSecrAuthCard(int port
, int slot
, int cnum
);
142 void hookSio2man25(Sio2Packet
*sd
);
143 void hookSio2man51(Sio2Packet
*sd
);
144 u32
*hookSio2man67();
145 void hookSio2man(Sio2Packet
*sd
, Sio2McProc sio2proc
);
146 int hookRegisterLibraryEntires(iop_library_t
*lib
);
148 void InstallSecrmanHook(void *exp
);
149 void InstallSio2manHook(void *exp
);
150 void InstallMcmanHook(void *exp
);
152 void SioResponse(MemoryCard
*mcd
, void *buf
, int length
);
153 int MceEraseBlock(MemoryCard
*mcd
, int page
);
154 int MceStartRead(MemoryCard
*mcd
, int page
);
155 int MceStartWrite(MemoryCard
*mcd
, int page
);
156 int MceRead(MemoryCard
*mcd
, void *buf
, u32 size
);
157 int MceWrite(MemoryCard
*mcd
, void *buf
, u32 size
);
161 int mc_configure(MemoryCard
*mcs
);
162 int mc_read(int mc_num
, void *buf
, u32 page_num
);
163 int mc_write(int mc_num
, void *buf
, u32 page_num
);
169 /* EE RPC id for libmc calls */
170 #define LIBMC_RPCNO 0x80000400
172 /* size of RPC buffer */
173 #define LIBMC_RPC_BUFFER_SIZE 0x80
176 int hookMcman63(int fd
, u32 eeaddr
, int nbyte
);
177 int hookMcman68(int fd
, u32 eeaddr
, int nbyte
);
183 void *GetExportTable(char *libname
, int version
);
184 u32
GetExportTableSize(void *table
);
185 void *GetExportEntry(void *table
, u32 entry
);
186 void *HookExportEntry(void *table
, u32 entry
, void *func
);
188 void *_SysAlloc(u64 size
);
189 int _SysFree(void *area
);
191 int GetInt(void *ptr
);
192 u32
CalculateEDC(u8
*buf
, u32 size
);
193 void CalculateECC(u8
*buf
, void *chk
);
196 u32
Mcpage_to_Apasector(int mc_num
, u32 mc_page
);
201 #define MCEMU_PORTS 2
203 extern const u8 xortable
[256];
205 extern PtrSecrAuthCard pSecrAuthCard
[MCEMU_PORTS
];
206 extern McImageSpec vmcSpec
[MCEMU_PORTS
];
207 extern MemoryCard memcards
[MCEMU_PORTS
];
208 extern void *pFastBuf
;
210 extern PtrRegisterLibraryEntires pRegisterLibraryEntires
;
211 extern Sio2McProc pSio2man25
, pSio2man51
;
212 extern void (*pSio2man67
)();
214 extern u8 mceccbuf
[MCEMU_PORTS
][0x20];
215 extern u8 mcdatabuf
[0x200];
217 extern SifRpcClientData_t
*pClientData
;
218 extern void *pFastRpcBuf
;
220 extern PtrMcIo pMcRead
, pMcWrite
;