mirror of https://github.com/mgba-emu/mgba.git
Core: Add mCoreFind
This commit is contained in:
parent
53191d2068
commit
533e96392b
|
@ -11,6 +11,75 @@
|
|||
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
|
||||
#include "util/png-io.h"
|
||||
|
||||
#ifdef M_CORE_GB
|
||||
#include "gb/core.h"
|
||||
#include "gb/gb.h"
|
||||
#endif
|
||||
#ifdef M_CORE_GBA
|
||||
#include "gba/core.h"
|
||||
#include "gba/gba.h"
|
||||
#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 VDir* archive = VDirOpenArchive(path);
|
||||
struct mCore* (*open)(void) = NULL;
|
||||
if (archive) {
|
||||
struct VDirEntry* dirent = archive->listNext(archive);
|
||||
while (dirent) {
|
||||
struct VFile* vf = archive->openFile(archive, dirent->name(dirent), O_RDONLY);
|
||||
if (!vf) {
|
||||
dirent = archive->listNext(archive);
|
||||
continue;
|
||||
}
|
||||
struct mCoreFilter* filter;
|
||||
for (filter = &_filters[0]; filter->filter; ++filter) {
|
||||
if (filter->filter(vf)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
vf->close(vf);
|
||||
if (filter->open) {
|
||||
open = filter->open;
|
||||
break;
|
||||
}
|
||||
dirent = archive->listNext(archive);
|
||||
}
|
||||
archive->close(archive);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
vf->close(vf);
|
||||
if (filter->open) {
|
||||
open = filter->open;
|
||||
}
|
||||
}
|
||||
if (open) {
|
||||
return open();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool mCoreLoadFile(struct mCore* core, const char* path) {
|
||||
struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM);
|
||||
if (!rom) {
|
||||
|
|
|
@ -17,7 +17,16 @@
|
|||
#endif
|
||||
#include "core/interface.h"
|
||||
|
||||
struct VFile;
|
||||
enum mPlatform {
|
||||
PLATFORM_NONE = -1,
|
||||
#ifdef M_CORE_GBA
|
||||
PLATFORM_GBA,
|
||||
#endif
|
||||
#ifdef M_CORE_GB
|
||||
PLATFORM_GB,
|
||||
#endif
|
||||
};
|
||||
|
||||
struct mRTCSource;
|
||||
struct mCoreConfig;
|
||||
struct mCoreSync;
|
||||
|
@ -80,6 +89,7 @@ struct mCore {
|
|||
};
|
||||
|
||||
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
|
||||
struct mCore* mCoreFind(const char* path);
|
||||
bool mCoreLoadFile(struct mCore* core, const char* path);
|
||||
|
||||
bool mCoreAutoloadSave(struct mCore* core);
|
||||
|
|
|
@ -41,13 +41,6 @@
|
|||
|
||||
#define PORT "sdl"
|
||||
|
||||
// TODO: Move somewhere
|
||||
enum mPlatform {
|
||||
PLATFORM_NONE = -1,
|
||||
PLATFORM_GBA,
|
||||
PLATFORM_GB
|
||||
};
|
||||
|
||||
static bool mSDLInit(struct mSDLRenderer* renderer);
|
||||
static void mSDLDeinit(struct mSDLRenderer* renderer);
|
||||
|
||||
|
@ -82,50 +75,21 @@ int main(int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
enum mPlatform platform = PLATFORM_NONE;
|
||||
|
||||
if (args.fname) {
|
||||
struct VFile* vf = VFileOpen(args.fname, O_RDONLY);
|
||||
if (!vf) {
|
||||
printf("Could not open game. Are you sure the file exists?\n");
|
||||
freeArguments(&args);
|
||||
return 1;
|
||||
}
|
||||
#ifdef M_CORE_GBA
|
||||
else if (GBAIsROM(vf)) {
|
||||
platform = PLATFORM_GBA;
|
||||
renderer.width = VIDEO_HORIZONTAL_PIXELS;
|
||||
renderer.height = VIDEO_VERTICAL_PIXELS;
|
||||
renderer.core = GBACoreCreate();
|
||||
#ifdef BUILD_GL
|
||||
mSDLGLCreate(&renderer);
|
||||
#elif defined(BUILD_GLES2) || defined(USE_EPOXY)
|
||||
mSDLGLES2Create(&renderer);
|
||||
#else
|
||||
mSDLSWCreate(&renderer);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef M_CORE_GB
|
||||
else if (GBIsROM(vf)) {
|
||||
platform = PLATFORM_GB;
|
||||
renderer.width = GB_VIDEO_HORIZONTAL_PIXELS;
|
||||
renderer.height = GB_VIDEO_VERTICAL_PIXELS;
|
||||
renderer.core = GBCoreCreate();
|
||||
#ifdef BUILD_GL
|
||||
mSDLGLCreate(&renderer);
|
||||
#elif defined(BUILD_GLES2) || defined(USE_EPOXY)
|
||||
mSDLGLES2CreateGB(&renderer);
|
||||
#else
|
||||
mSDLSWCreateGB(&renderer);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
renderer.core = mCoreFind(args.fname);
|
||||
if (!renderer.core) {
|
||||
printf("Could not run game. Are you sure the file exists and is a compatible game?\n");
|
||||
freeArguments(&args);
|
||||
return 1;
|
||||
}
|
||||
renderer.core->desiredVideoDimensions(renderer.core, &renderer.width, &renderer.height);
|
||||
#ifdef BUILD_GL
|
||||
mSDLGLCreate(&renderer);
|
||||
#elif defined(BUILD_GLES2) || defined(USE_EPOXY)
|
||||
mSDLGLES2Create(&renderer);
|
||||
#else
|
||||
mSDLSWCreate(&renderer);
|
||||
#endif
|
||||
}
|
||||
|
||||
renderer.ratio = graphicsOpts.multiplier;
|
||||
|
|
Loading…
Reference in New Issue