all repos — mgba @ 72fa184bac4f7eee1a07b6deba3147f1fa976c92

mGBA Game Boy Advance Emulator

Core: Add some utility functions
Jeffrey Pfau jeffrey@endrift.com
Sat, 27 Aug 2016 00:56:25 -0700
commit

72fa184bac4f7eee1a07b6deba3147f1fa976c92

parent

93121d93197489ef26c254e9f9bf9fa743b47195

3 files changed, 50 insertions(+), 41 deletions(-)

jump to
M src/core/core.csrc/core/core.c

@@ -9,9 +9,6 @@ #include "core/log.h"

#include "core/serialize.h" #include "util/vfs.h" -#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -#include "util/png-io.h" - #ifdef M_CORE_GB #include "gb/core.h" #include "gb/gb.h"

@@ -21,26 +18,59 @@ #include "gba/core.h"

#include "gba/gba.h" #endif -#ifdef PSP2 -#include <psp2/photoexport.h> -#endif - static struct mCoreFilter { bool (*filter)(struct VFile*); struct mCore* (*open)(void); + enum mPlatform platform; } _filters[] = { #ifdef M_CORE_GBA - { GBAIsROM, GBACoreCreate }, + { GBAIsROM, GBACoreCreate, PLATFORM_GBA }, #endif #ifdef M_CORE_GB - { GBIsROM, GBCoreCreate }, + { GBIsROM, GBCoreCreate, PLATFORM_GB }, #endif - { 0, 0 } + { 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 +#include <psp2/photoexport.h> +#endif + struct mCore* mCoreFind(const char* path) { struct VDir* archive = VDirOpenArchive(path); - struct mCore* (*open)(void) = NULL; + struct mCore* core = NULL; if (archive) { struct VDirEntry* dirent = archive->listNext(archive); while (dirent) {

@@ -49,15 +79,9 @@ if (!vf) {

dirent = archive->listNext(archive); continue; } - struct mCoreFilter* filter; - for (filter = &_filters[0]; filter->filter; ++filter) { - if (filter->filter(vf)) { - break; - } - } + core = mCoreFindVF(vf); vf->close(vf); - if (filter->open) { - open = filter->open; + if (core) { break; } dirent = archive->listNext(archive);

@@ -68,19 +92,11 @@ struct VFile* vf = VFileOpen(path, O_RDONLY);

if (!vf) { return NULL; } - struct mCoreFilter* filter; - for (filter = &_filters[0]; filter->filter; ++filter) { - if (filter->filter(vf)) { - break; - } - } + core = mCoreFindVF(vf); vf->close(vf); - if (filter->open) { - open = filter->open; - } } - if (open) { - return open(); + if (core) { + return core; } return NULL; }
M src/core/core.hsrc/core/core.h

@@ -142,6 +142,9 @@

void mCoreTakeScreenshot(struct mCore* core); #endif +struct mCore* mCoreFindVF(struct VFile* vf); +enum mPlatform mCoreIsCompatible(struct VFile* vf); + void mCoreInitConfig(struct mCore* core, const char* port); void mCoreLoadConfig(struct mCore* core); void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -294,17 +294,7 @@ if (!rom) {

return false; } - core = NULL; -#ifdef M_CORE_GBA - if (!core && GBAIsROM(rom)) { - core = GBACoreCreate(); - } -#endif -#ifdef M_CORE_GB - if (!core && GBIsROM(rom)) { - core = GBCoreCreate(); - } -#endif + core = mCoreFindVF(rom); if (!core) { rom->close(rom); mappedMemoryFree(data, game->size);