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 */
69 /* Apa partitions informations */
75 /* Block number/count pair (used in inodes) */
82 /* Memory Card Spec (do not change this structure) */
86 u16 PageSize
; /* Page size in bytes (user data only) */
87 u16 BlockSize
; /* Block size in pages */
88 u32 CardSize
; /* Total number of pages */
91 /* Virtual Memory Card Image File Spec */
95 int active
; /* Activation flag */
98 u32 stsec
; /* Vmc file start sector */
102 apa_parts parts
[5]; /* Vmc file Apa partitions */
103 pfs_blocks blocks
[10]; /* Vmc file Pfs inode blocks */
107 char fname
[32]; /* Vmc file name (memorycard?.bin) */
108 u16 fid
; /* SMB Vmc file id */
111 int flags
; /* Memory Card Flags */
112 McSpec cspec
; /* Memory Card Spec */
115 /* Descriptor for a virtual memory card */
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 */
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
);
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
);
167 /* EE RPC id for libmc calls */
168 #define LIBMC_RPCNO 0x80000400
170 /* size of RPC buffer */
171 #define LIBMC_RPC_BUFFER_SIZE 0x80
174 int hookMcman63(int fd
, u32 eeaddr
, int nbyte
);
175 int hookMcman68(int fd
, u32 eeaddr
, int nbyte
);
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
);
194 u32
Mcpage_to_Apasector(int mc_num
, u32 mc_page
);
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
;