Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ee/rpc/memorycard/include/libmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

/*
NOTE: These functions will work with the MCMAN/MCSERV or XMCMAN/XMCSERV
modules stored in rom0. To determine which one you are using, send the
appropriate arg to the mcInit() function (MC_TYPE_MC or MC_TYPE_XMC)
modules stored in rom0. The library will automatically detect which
module is used and will use the appropriate RPC commands accordingly.

NOTE: These functions seem to work for both psx and ps2 memcards

Expand Down Expand Up @@ -193,6 +193,7 @@ typedef struct
} mcTable __attribute__((deprecated, aligned (64)));

// values to send to mcInit() to use either mcserv or xmcserv
// These definitions are retained for backwards compatibility
#define MC_TYPE_MC 0
#define MC_TYPE_XMC 1

Expand All @@ -202,7 +203,7 @@ extern "C" {

/** init memcard lib
*
* @param type MC_TYPE_MC = use MCSERV/MCMAN; MC_TYPE_XMC = use XMCSERV/XMCMAN
* @param type Retained for backwards compatibility. Nominally specify MC_TYPE_MC.
* @return 0 = successful; < 0 = error
*/
extern int mcInit(int type);
Expand Down
102 changes: 67 additions & 35 deletions ee/rpc/memorycard/src/libmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ static void mcStoreDir(void* arg)
int mcInit(int type)
{
int ret=0;
int err=0;
mcRpcStat_t *rpcStat = (mcRpcStat_t*)UNCACHED_SEG(&g_rdata.rpcStat);
static int _rb_count = 0;

(void)type;
if(_rb_count != _iop_reboot_count)
{
_rb_count = _iop_reboot_count;
Expand All @@ -244,9 +246,6 @@ int mcInit(int type)

sceSifInitRpc(0);

// set which modules to use
g_mcType = type;

// bind to mc rpc on iop
do
{
Expand All @@ -266,65 +265,98 @@ int mcInit(int type)
// for some reason calling this init sif function with 'mcserv' makes all other
// functions not work properly. although NOT calling it means that detecting
// whether or not cards are formatted doesnt seem to work :P
if(g_mcType == MC_TYPE_MC)
{

// Start with calling flush with an invalid fd (so it sets the return value to
// sceMcResDeniedPermit, which MC_RPCCMD_INIT will not return)
g_descParam.fd = 0xFFFFFFFF;
sceSifCallRpc(&g_cdata, mcRpcCmd[MC_TYPE_XMC][MC_RPCCMD_FLUSH], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 4, NULL, NULL);
sceSifCallRpc(&g_cdata, mcRpcCmd[MC_TYPE_MC][MC_RPCCMD_FLUSH], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 4, NULL, NULL);
#ifdef MC_DEBUG
printf("libmc: using MCMAN & MCSERV\n");
printf("libmc: using XMCMAN & XMCSERV\n");
#endif

// Try XMCSERV RPC
g_mcType = MC_TYPE_XMC;
// call init function
if((ret = sceSifCallRpc(&g_cdata, mcRpcCmd[g_mcType][MC_RPCCMD_INIT], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 12, NULL, NULL)) < 0)
{
// init error
#ifdef MC_DEBUG
printf("libmc: initialisation error\n");
#endif
g_descParam.offset = -217;
err = ret - 100;
}

// call init function
if((ret = sceSifCallRpc(&g_cdata, mcRpcCmd[g_mcType][MC_RPCCMD_INIT], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 4, NULL, NULL))>=0)
// If result was sceMcResDeniedPermit, RPC was unhandled
if (!err && rpcStat->result == sceMcResDeniedPermit)
{
err = -122;
}

if (!err)
{
// check if old version of mcserv loaded
if (rpcStat->mcserv_version < 0x205)
{
ret = g_rdata.result;
#ifdef MC_DEBUG
printf("libmc: mcserv is too old (%x)\n", rpcStat->mcserv_version);
#endif
err = -120;
}
else{
// init error

// check if old version of mcman loaded
if (rpcStat->mcman_version < 0x206)
{
#ifdef MC_DEBUG
printf("libmc: initialisation error\n");
printf("libmc: mcman is too old (%x)\n", rpcStat->mcman_version);
#endif
g_mclibInited = 0;
return g_rdata.result - 100;
err = -121;
}
}
else if(g_mcType == MC_TYPE_XMC)

if (!err)
{
ret = rpcStat->result;
}

if (err && rpcStat->result == sceMcResDeniedPermit)
{
err = 0;

// Try MCSERV RPC
g_mcType = MC_TYPE_MC;
#ifdef MC_DEBUG
printf("libmc: using XMCMAN & XMCSERV\n");
printf("libmc: using MCMAN & MCSERV\n");
#endif

g_descParam.offset = -217;

// call init function
if((ret = sceSifCallRpc(&g_cdata, mcRpcCmd[g_mcType][MC_RPCCMD_INIT], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 12, NULL, NULL)) < 0)
if((ret = sceSifCallRpc(&g_cdata, mcRpcCmd[g_mcType][MC_RPCCMD_INIT], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 4, NULL, NULL)) < 0)
{
// init error
#ifdef MC_DEBUG
printf("libmc: initialisation error\n");
#endif
g_mclibInited = 0;
return ret - 100;
err = ret - 100;
}

// check if old version of mcserv loaded
if(rpcStat->mcserv_version < 0x205)
// If result was sceMcResDeniedPermit, RPC was unhandled
if (!err && rpcStat->result == sceMcResDeniedPermit)
{
#ifdef MC_DEBUG
printf("libmc: mcserv is too old (%x)\n", rpcStat->mcserv_version);
#endif
g_mclibInited = 0;
return -120;
err = -122;
}

// check if old version of mcman loaded
if(rpcStat->mcman_version < 0x206)
if (!err)
{
#ifdef MC_DEBUG
printf("libmc: mcman is too old (%x)\n", rpcStat->mcman_version);
#endif
g_mclibInited = 0;
return -121;
ret = g_rdata.result;
}
ret = rpcStat->result;
}

if (err)
{
g_mclibInited = 0;
return err;
}

// successfully inited
Expand Down
Loading