fix for corrupted graphics when manipulating config files
[open-ps2-loader.git] / modules / mcemu / mcemu.h
blobe7c5eda9c064c5a08214ca5eb1d7ff7103bb6ca9
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 #ifdef HDD_DRIVER
70 /* Apa partitions informations */
71 typedef struct {
72 u32 start;
73 u32 length;
74 } apa_parts;
76 /* Block number/count pair (used in inodes) */
77 typedef struct {
78 u32 number;
79 u16 subpart;
80 u16 count;
81 } pfs_blocks;
82 #endif
84 /* Memory Card Spec (do not change this structure) */
85 typedef
86 struct _McSpec
88 u16 PageSize; /* Page size in bytes (user data only) */
89 u16 BlockSize; /* Block size in pages */
90 u32 CardSize; /* Total number of pages */
91 } McSpec;
93 /* Virtual Memory Card Image File Spec */
94 typedef
95 struct _McImageSpec
97 int active; /* Activation flag */
99 #ifdef USB_DRIVER
100 u32 stsec; /* Vmc file start sector */
101 #endif
103 #ifdef HDD_DRIVER
104 apa_parts parts[5]; /* Vmc file Apa partitions */
105 pfs_blocks blocks[10]; /* Vmc file Pfs inode blocks */
106 #endif
108 #ifdef SMB_DRIVER
109 char fname[64]; /* Vmc file name (memorycard?.bin) */
110 u16 fid; /* SMB Vmc file id */
111 #endif
113 int flags; /* Memory Card Flags */
114 McSpec cspec; /* Memory Card Spec */
115 } McImageSpec;
117 /* Descriptor for a virtual memory card */
118 typedef
119 struct _MemoryCard
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 */
133 } MemoryCard;
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);
159 /* mcemu_io.c */
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);
167 /* mcemu_rpc.c */
169 /* EE RPC id for libmc calls */
170 #define LIBMC_RPCNO 0x80000400
172 /* size of RPC buffer */
173 #define LIBMC_RPC_BUFFER_SIZE 0x80
175 int hookMcman62();
176 int hookMcman63(int fd, u32 eeaddr, int nbyte);
177 int hookMcman68(int fd, u32 eeaddr, int nbyte);
181 /* mcemu_sys.c */
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);
195 #ifdef HDD_DRIVER
196 u32 Mcpage_to_Apasector(int mc_num, u32 mc_page);
197 #endif
199 /* mcemu_var.c */
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;
222 #endif //_MCEMU_H_