Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
73 changes: 17 additions & 56 deletions src/mmcesupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

static char mmcePrefix[40]; // Contains the full path to the folder where all the games are.
static char mmceArtPrimary[40];
static char mmceArtFallback[40];
static int mmceULSizePrev = -2;
static time_t mmceModifiedCDPrev;
static time_t mmceModifiedDVDPrev;
Expand All @@ -35,21 +34,6 @@ static base_game_info_t *mmceGames;
// forward declaration
static item_list_t mmceGameList;

static int mmceHasArtFolder(const char *prefix)
{
char path[sizeof(mmcePrefix) + 4];
struct stat st;

if (prefix == NULL || prefix[0] == '\0')
return 0;

snprintf(path, sizeof(path), "%sART", prefix);
if (stat(path, &st) != 0)
return 0;

return S_ISDIR(st.st_mode);
}

static void mmceGetDeviceRoot(char *root, size_t size)
{
const char *separator = strstr(mmcePrefix, ":/");
Expand Down Expand Up @@ -78,35 +62,22 @@ static void mmceGetDeviceRoot(char *root, size_t size)

static void mmceRefreshArtRoots(void)
{
char deviceRoot[sizeof(mmcePrefix)];
int primaryHasArt;
int fallbackHasArt;
int len;

mmceArtPrimary[0] = '\0';
mmceArtFallback[0] = '\0';

if (mmcePrefix[0] == '\0')
return;

snprintf(mmceArtPrimary, sizeof(mmceArtPrimary), "%s", mmcePrefix);

mmceGetDeviceRoot(deviceRoot, sizeof(deviceRoot));
if (deviceRoot[0] != '\0' && strcmp(deviceRoot, mmceArtPrimary) != 0)
snprintf(mmceArtFallback, sizeof(mmceArtFallback), "%s", deviceRoot);

primaryHasArt = mmceHasArtFolder(mmceArtPrimary);
fallbackHasArt = mmceHasArtFolder(mmceArtFallback);
if (!primaryHasArt && fallbackHasArt) {
char primary[sizeof(mmceArtPrimary)];

snprintf(primary, sizeof(primary), "%s", mmceArtPrimary);
snprintf(mmceArtPrimary, sizeof(mmceArtPrimary), "%s", mmceArtFallback);
snprintf(mmceArtFallback, sizeof(mmceArtFallback), "%s", primary);
primaryHasArt = 1;
/* Ensure mmcePrefix always ends with '/' so path concatenation is correct
* (e.g. "mmce0:/CD" -> "mmce0:/CD/" prevents "mmce0:/CDART" paths). */
len = strlen(mmcePrefix);
if (len < (int)sizeof(mmcePrefix) - 1 && mmcePrefix[len - 1] != '/') {
mmcePrefix[len] = '/';
mmcePrefix[len + 1] = '\0';
}

if (primaryHasArt || !fallbackHasArt)
mmceArtFallback[0] = '\0';
snprintf(mmceArtPrimary, sizeof(mmceArtPrimary), "%s", mmcePrefix);
}

static int mmceTryLoadImage(const char *prefix, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex)
Expand Down Expand Up @@ -161,7 +132,6 @@ void mmceInit(item_list_t *itemList)
LOG("MMCESUPPORT Init\n");
mmcePrefix[0] = '\0';
mmceArtPrimary[0] = '\0';
mmceArtFallback[0] = '\0';
mmceULSizePrev = -2;
mmceModifiedCDPrev = 0;
mmceModifiedDVDPrev = 0;
Expand Down Expand Up @@ -193,7 +163,7 @@ static int mmceNeedsUpdate(item_list_t *itemList)
int result = 0;
struct stat st;

//Hacky: check if slot was changed, update prefix if needed
// Hacky: check if slot was changed, update prefix if needed
mmceSetPrefix();

if (mmcePrefix[0] == '\0') {
Expand Down Expand Up @@ -418,7 +388,7 @@ void mmceLaunchGame(item_list_t *itemList, int id, config_set_t *configSet)
strcpy(filename, game->startup);


//MMCEDRV settings
// MMCEDRV settings
if (gMMCESlot == 0)
settings->port = 2;
else if (gMMCESlot == 1)
Expand All @@ -435,8 +405,8 @@ void mmceLaunchGame(item_list_t *itemList, int id, config_set_t *configSet)
settings->ack_wait_cycles = gMMCEAckWaitCycles;
settings->use_alarms = gMMCEUseAlarms;

//TEMP: The fd given by sd2psx is not the same one we see here on the EE
//and ps2sdk_get_iop_fd does not seem to return the right value either
// TEMP: The fd given by sd2psx is not the same one we see here on the EE
// and ps2sdk_get_iop_fd does not seem to return the right value either
settings->iso_fd = fileXioIoctl2(iso_file, 0x80, NULL, 0, NULL, 0);

LOG("name: %s\n", game->name);
Expand Down Expand Up @@ -464,8 +434,8 @@ void mmceLaunchGame(item_list_t *itemList, int id, config_set_t *configSet)
}
}

//mcReset();
//mcInit(MC_TYPE_XMC);
// mcReset();
// mcInit(MC_TYPE_XMC);

if (gAutoLaunchBDMGame == NULL) {
deinit(NO_EXCEPTION, MMCE_MODE); // CAREFUL: deinit will call mmceCleanUp, so mmceGames/game will be freed
Expand All @@ -491,16 +461,7 @@ static config_set_t *mmceGetConfig(item_list_t *itemList, int id)

static int mmceGetImage(item_list_t *itemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
{
int result;

result = mmceTryLoadImage(mmceArtPrimary, folder, isRelative, value, suffix, resultTex);
if (result >= 0 || result == ERR_LOAD_ABORTED || !isRelative)
return result;

if (mmceArtFallback[0] != '\0')
return mmceTryLoadImage(mmceArtFallback, folder, isRelative, value, suffix, resultTex);

return result;
return mmceTryLoadImage(mmceArtPrimary, folder, isRelative, value, suffix, resultTex);
}

static int mmceGetTextId(item_list_t *itemList)
Expand Down Expand Up @@ -540,7 +501,7 @@ static void mmceShutdown(item_list_t *itemList)
}

// As required by some (typically 2.5") HDDs, issue the SCSI STOP UNIT command to avoid causing an emergency park.
//fileXioDevctl("mass:", USBMASS_DEVCTL_STOP_ALL, NULL, 0, NULL, 0);
// fileXioDevctl("mass:", USBMASS_DEVCTL_STOP_ALL, NULL, 0, NULL, 0);
}

static int mmceCheckVMC(item_list_t *itemList, char *name, int createSize)
Expand All @@ -561,7 +522,7 @@ static item_list_t mmceGameList = {
void mmceInitSemaphore()
{
// Create a semaphore so only one thread can load IOP modules at a time.
//if (mmceLoadModuleLock < 0) {
// if (mmceLoadModuleLock < 0) {
// mmceLoadModuleLock = sbCreateSemaphore();
//}
}
5 changes: 4 additions & 1 deletion src/texcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,10 @@ static GSTEXTURE *cacheGetTextureInternal(image_cache_t *cache, item_list_t *lis
if (queuedMmceReq != NULL && (queuedMmceReq->cache != cache || strcmp(queuedMmceReq->value, value) != 0))
cacheDropQueuedRequestLocked(queuedMmceReq);

if (cacheHasActiveInteractiveModeLocked(MMCE_MODE) || cacheHasQueuedInteractiveModeLocked(MMCE_MODE)) {
/* cacheHasActiveInteractiveModeLocked() checks gArtCurrentReq != NULL, so
* dereferencing abortRequested is safe here while the cache lock is held. */
if ((cacheHasActiveInteractiveModeLocked(MMCE_MODE) && !gArtCurrentReq->abortRequested) ||
cacheHasQueuedInteractiveModeLocked(MMCE_MODE)) {
cacheUnlock();
return NULL;
}
Expand Down
Loading