Core: Add some utility functions

This commit is contained in:
Jeffrey Pfau 2016-08-27 00:56:25 -07:00
parent 93121d9319
commit 72fa184bac
3 changed files with 56 additions and 47 deletions

View File

@ -9,9 +9,6 @@
#include "core/serialize.h" #include "core/serialize.h"
#include "util/vfs.h" #include "util/vfs.h"
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#include "util/png-io.h"
#ifdef M_CORE_GB #ifdef M_CORE_GB
#include "gb/core.h" #include "gb/core.h"
#include "gb/gb.h" #include "gb/gb.h"
@ -21,26 +18,59 @@
#include "gba/gba.h" #include "gba/gba.h"
#endif #endif
static struct mCoreFilter {
bool (*filter)(struct VFile*);
struct mCore* (*open)(void);
enum mPlatform platform;
} _filters[] = {
#ifdef M_CORE_GBA
{ GBAIsROM, GBACoreCreate, PLATFORM_GBA },
#endif
#ifdef M_CORE_GB
{ GBIsROM, GBCoreCreate, PLATFORM_GB },
#endif
{ 0, 0, PLATFORM_NONE }
};
struct mCore* mCoreFindVF(struct VFile* vf) {
if (!vf) {
return NULL;
}
struct mCoreFilter* filter;
for (filter = &_filters[0]; filter->filter; ++filter) {
if (filter->filter(vf)) {
break;
}
}
if (filter->open) {
return filter->open();
}
return NULL;
}
enum mPlatform mCoreIsCompatible(struct VFile* vf) {
if (!vf) {
return false;
}
struct mCoreFilter* filter;
for (filter = &_filters[0]; filter->filter; ++filter) {
if (filter->filter(vf)) {
return filter->platform;
}
}
return PLATFORM_NONE;
}
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#include "util/png-io.h"
#ifdef PSP2 #ifdef PSP2
#include <psp2/photoexport.h> #include <psp2/photoexport.h>
#endif #endif
static struct mCoreFilter {
bool (*filter)(struct VFile*);
struct mCore* (*open)(void);
} _filters[] = {
#ifdef M_CORE_GBA
{ GBAIsROM, GBACoreCreate },
#endif
#ifdef M_CORE_GB
{ GBIsROM, GBCoreCreate },
#endif
{ 0, 0 }
};
struct mCore* mCoreFind(const char* path) { struct mCore* mCoreFind(const char* path) {
struct VDir* archive = VDirOpenArchive(path); struct VDir* archive = VDirOpenArchive(path);
struct mCore* (*open)(void) = NULL; struct mCore* core = NULL;
if (archive) { if (archive) {
struct VDirEntry* dirent = archive->listNext(archive); struct VDirEntry* dirent = archive->listNext(archive);
while (dirent) { while (dirent) {
@ -49,15 +79,9 @@ struct mCore* mCoreFind(const char* path) {
dirent = archive->listNext(archive); dirent = archive->listNext(archive);
continue; continue;
} }
struct mCoreFilter* filter; core = mCoreFindVF(vf);
for (filter = &_filters[0]; filter->filter; ++filter) {
if (filter->filter(vf)) {
break;
}
}
vf->close(vf); vf->close(vf);
if (filter->open) { if (core) {
open = filter->open;
break; break;
} }
dirent = archive->listNext(archive); dirent = archive->listNext(archive);
@ -68,19 +92,11 @@ struct mCore* mCoreFind(const char* path) {
if (!vf) { if (!vf) {
return NULL; return NULL;
} }
struct mCoreFilter* filter; core = mCoreFindVF(vf);
for (filter = &_filters[0]; filter->filter; ++filter) {
if (filter->filter(vf)) {
break;
}
}
vf->close(vf); vf->close(vf);
if (filter->open) {
open = filter->open;
}
} }
if (open) { if (core) {
return open(); return core;
} }
return NULL; return NULL;
} }

View File

@ -142,6 +142,9 @@ void mCoreDeleteState(struct mCore* core, int slot);
void mCoreTakeScreenshot(struct mCore* core); void mCoreTakeScreenshot(struct mCore* core);
#endif #endif
struct mCore* mCoreFindVF(struct VFile* vf);
enum mPlatform mCoreIsCompatible(struct VFile* vf);
void mCoreInitConfig(struct mCore* core, const char* port); void mCoreInitConfig(struct mCore* core, const char* port);
void mCoreLoadConfig(struct mCore* core); void mCoreLoadConfig(struct mCore* core);
void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config); void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);

View File

@ -294,17 +294,7 @@ bool retro_load_game(const struct retro_game_info* game) {
return false; return false;
} }
core = NULL; core = mCoreFindVF(rom);
#ifdef M_CORE_GBA
if (!core && GBAIsROM(rom)) {
core = GBACoreCreate();
}
#endif
#ifdef M_CORE_GB
if (!core && GBIsROM(rom)) {
core = GBCoreCreate();
}
#endif
if (!core) { if (!core) {
rom->close(rom); rom->close(rom);
mappedMemoryFree(data, game->size); mappedMemoryFree(data, game->size);