2 Copyright 2006-2008, Romz
4 Licenced under Academic Free License version 3.0
5 Review OpenUsbLd README & LICENSE files for further details.
10 /* PS2 Memory Card cluster size */
11 /* do NOT change this value unless you are absolutely sure what you are doing */
12 #define MC2_CLUSTER_SIZE 0x400
14 /* size of memory to allocate for FastIO support */
15 #define FIO_ALLOC_SIZE (MC2_CLUSTER_SIZE + LIBMC_RPC_BUFFER_SIZE + sizeof(SifRpcClientData_t))
17 /* Replacement for MCMAN's library function #62 */
22 /* checking if the memory block had been allocated */
25 /* allocating memory for Fast I/O buffer, RPC buffer and RPC client data structure */
26 ptr
= (char*)_SysAlloc((FIO_ALLOC_SIZE
+ 0xFF) & ~(u64
)0xFF);
29 DPRINTF("Not enough memory for FastIO support.\n");
33 /* initializing buffer pointers */
35 pFastRpcBuf
= &ptr
[MC2_CLUSTER_SIZE
];
36 pClientData
= (SifRpcClientData_t
*)&ptr
[MC2_CLUSTER_SIZE
+ LIBMC_RPC_BUFFER_SIZE
];
40 /* binding to EE libmc's RPC server */
41 if (SifBindRpc(pClientData
, LIBMC_RPCNO
, 0) < 0)
45 /* freeing memory on RPC bind error */
50 DPRINTF("libmc RPC bind error.\n");
57 /* Reads file to EE memory for sceMcReadFast() support */
58 int hookMcman63(int fd
, u32 eeaddr
, int nbyte
)
66 register char *rpcbuf
, *fiobuf
;
67 SifRpcClientData_t
*cldata
;
69 // DPRINTF("sceMcReadFast(%d, 0x%X, 0x%X)\n", fd, eeaddr, nbyte);
72 rpcbuf
= (char*)pFastRpcBuf
;
73 fiobuf
= (char*)pFastBuf
;
75 for (rlen
= nbyte
; rlen
> 0; rlen
-= size
)
77 size
= (rlen
> MC2_CLUSTER_SIZE
) ? MC2_CLUSTER_SIZE
: rlen
;
79 /* reading file with MCMAN's sceMcRead() call */
80 rval
= pMcRead(fd
, fiobuf
, size
);
81 if (rval
< 0) return rval
;
83 /* preparing to transfer data to libmc */
84 sdd
.dest
= (void*)((u32
)fiobuf
);
85 sdd
.src
= (void*)eeaddr
;
86 sdd
.size
= MC2_CLUSTER_SIZE
;
89 *(int*)(&rpcbuf
[0xC]) = size
;
91 /* sending data to EE */
92 CpuSuspendIntr(&oldstate
);
93 id
= sceSifSetDma(&sdd
, 1);
94 CpuResumeIntr(oldstate
);
96 /* informing libmc on new data */
97 sceSifCallRpc(cldata
, 2, 0, rpcbuf
, LIBMC_RPC_BUFFER_SIZE
, rpcbuf
, LIBMC_RPC_BUFFER_SIZE
, NULL
, NULL
);
103 /* Write file from EE memory for sceMcWriteFast() support */
104 int hookMcman68(int fd
, u32 eeaddr
, int nbyte
)
106 SifRpcReceiveData_t od
;
111 register char *fiobuf
;
113 // DPRINTF("sceMcWriteFast(%d, 0x%X, 0x%X)\n", fd, eeaddr, nbyte);
115 fiobuf
= (char*)pFastBuf
;
120 /* check for EE address alignment (64 bytes) */
124 /* getting unaligned data from EE side */
125 SifRpcGetOtherData(&od
, (void*)(ea
& ~(u32
)0x3F), fiobuf
, MC2_CLUSTER_SIZE
, 0);
127 size
= MC2_CLUSTER_SIZE
- rval
;
128 if (wlen
< size
) size
= wlen
;
130 /* writing unaligned data to a file */
131 rval
= pMcWrite(fd
, &fiobuf
[rval
], size
);
134 DPRINTF("sceMcWrite error %d\n", rval
);
142 for (; wlen
> 0; wlen
-= size
, ea
+= size
)
144 size
= (wlen
> MC2_CLUSTER_SIZE
) ? MC2_CLUSTER_SIZE
: wlen
;
146 /* receiving data from EE */
147 SifRpcGetOtherData(&od
, (void*)ea
, fiobuf
, MC2_CLUSTER_SIZE
, 0);
149 /* writing data to a file */
150 rval
= pMcWrite(fd
, fiobuf
, size
);
153 DPRINTF("sceMcWrite error %d\n", rval
);