GBA: Add "super-minimal" core configuration, useful for cores-as-plugins, e.g. for libretro

This commit is contained in:
Jeffrey Pfau 2016-01-01 17:54:37 -08:00
parent 3a7350c8d2
commit 29556f45a4
4 changed files with 24 additions and 5 deletions

View File

@ -37,7 +37,7 @@ file(GLOB GUI_SRC ${CMAKE_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_SOURCE_DIR}/src/g
file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/*.c) file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/*.c)
file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c) file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c)
file(GLOB THIRD_PARTY_SRC ${CMAKE_SOURCE_DIR}/src/third-party/inih/*.c) file(GLOB THIRD_PARTY_SRC ${CMAKE_SOURCE_DIR}/src/third-party/inih/*.c)
list(APPEND UTIL_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c) list(APPEND GBA_SV_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
set(CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-mem.c) set(CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-mem.c)
set(VFS_SRC) set(VFS_SRC)
source_group("ARM core" FILES ${ARM_SRC}) source_group("ARM core" FILES ${ARM_SRC})
@ -553,7 +553,7 @@ endif()
if(BUILD_LIBRETRO) if(BUILD_LIBRETRO)
file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c) file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC}) add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES}") set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=2")
target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB}) target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP) install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
endif() endif()

View File

@ -132,6 +132,7 @@ void GBAConfigDeinit(struct GBAConfig* config) {
free(config->port); free(config->port);
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
bool GBAConfigLoad(struct GBAConfig* config) { bool GBAConfigLoad(struct GBAConfig* config) {
char path[PATH_MAX]; char path[PATH_MAX];
GBAConfigDirectory(path, PATH_MAX); GBAConfigDirectory(path, PATH_MAX);
@ -231,6 +232,7 @@ void GBAConfigDirectory(char* out, size_t outLength) {
mkdir(out, 0755); mkdir(out, 0755);
#endif #endif
} }
#endif
const char* GBAConfigGetValue(const struct GBAConfig* config, const char* key) { const char* GBAConfigGetValue(const struct GBAConfig* config, const char* key) {
return _lookupValue(config, key); return _lookupValue(config, key);

View File

@ -52,6 +52,7 @@ struct GBAOptions {
void GBAConfigInit(struct GBAConfig*, const char* port); void GBAConfigInit(struct GBAConfig*, const char* port);
void GBAConfigDeinit(struct GBAConfig*); void GBAConfigDeinit(struct GBAConfig*);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
bool GBAConfigLoad(struct GBAConfig*); bool GBAConfigLoad(struct GBAConfig*);
bool GBAConfigSave(const struct GBAConfig*); bool GBAConfigSave(const struct GBAConfig*);
bool GBAConfigLoadPath(struct GBAConfig*, const char* path); bool GBAConfigLoadPath(struct GBAConfig*, const char* path);
@ -59,6 +60,7 @@ bool GBAConfigSavePath(const struct GBAConfig*, const char* path);
void GBAConfigMakePortable(const struct GBAConfig*); void GBAConfigMakePortable(const struct GBAConfig*);
void GBAConfigDirectory(char* out, size_t outLength); void GBAConfigDirectory(char* out, size_t outLength);
#endif
const char* GBAConfigGetValue(const struct GBAConfig*, const char* key); const char* GBAConfigGetValue(const struct GBAConfig*, const char* key);
bool GBAConfigGetIntValue(const struct GBAConfig*, const char* key, int* value); bool GBAConfigGetIntValue(const struct GBAConfig*, const char* key, int* value);

View File

@ -38,6 +38,7 @@ bool GBAContextInit(struct GBAContext* context, const char* port) {
ARMInit(context->cpu); ARMInit(context->cpu);
GBAConfigInit(&context->config, port); GBAConfigInit(&context->config, port);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
if (port) { if (port) {
if (!_logFile) { if (!_logFile) {
char logPath[PATH_MAX]; char logPath[PATH_MAX];
@ -60,6 +61,9 @@ bool GBAContextInit(struct GBAContext* context, const char* port) {
GBAConfigLoad(&context->config); GBAConfigLoad(&context->config);
GBAConfigLoadDefaults(&context->config, &opts); GBAConfigLoadDefaults(&context->config, &opts);
} }
#else
UNUSED(port);
#endif
context->gba->sync = 0; context->gba->sync = 0;
return true; return true;
@ -70,7 +74,9 @@ void GBAContextDeinit(struct GBAContext* context) {
GBADestroy(context->gba); GBADestroy(context->gba);
mappedMemoryFree(context->gba, 0); mappedMemoryFree(context->gba, 0);
mappedMemoryFree(context->cpu, 0); mappedMemoryFree(context->cpu, 0);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
GBAConfigDeinit(&context->config); GBAConfigDeinit(&context->config);
#endif
GBADirectorySetDeinit(&context->dirs); GBADirectorySetDeinit(&context->dirs);
} }
@ -81,15 +87,18 @@ bool GBAContextLoadROM(struct GBAContext* context, const char* path, bool autolo
} }
context->fname = path; context->fname = path;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
if (autoloadSave) { if (autoloadSave) {
char dirname[PATH_MAX]; char dirname[PATH_MAX];
char basename[PATH_MAX]; char basename[PATH_MAX];
separatePath(context->fname, dirname, basename, 0); separatePath(context->fname, dirname, basename, 0);
// TODO: Remove autoloadSave
GBADirectorySetAttachBase(&context->dirs, VDirOpen(dirname)); GBADirectorySetAttachBase(&context->dirs, VDirOpen(dirname));
strncat(basename, ".sav", PATH_MAX - strlen(basename) - 1); strncat(basename, ".sav", PATH_MAX - strlen(basename) - 1);
context->save = context->dirs.save->openFile(context->dirs.save, basename, O_RDWR | O_CREAT); context->save = context->dirs.save->openFile(context->dirs.save, basename, O_RDWR | O_CREAT);
} }
#else
UNUSED(autoloadSave);
#endif
return true; return true;
} }
@ -154,7 +163,9 @@ bool GBAContextStart(struct GBAContext* context) {
return false; return false;
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
GBAConfigMap(&context->config, &opts); GBAConfigMap(&context->config, &opts);
#endif
if (!context->bios && opts.bios) { if (!context->bios && opts.bios) {
GBAContextLoadBIOS(context, opts.bios); GBAContextLoadBIOS(context, opts.bios);
@ -175,10 +186,14 @@ bool GBAContextStart(struct GBAContext* context) {
struct GBACartridgeOverride override; struct GBACartridgeOverride override;
const struct GBACartridge* cart = (const struct GBACartridge*) context->gba->memory.rom; const struct GBACartridge* cart = (const struct GBACartridge*) context->gba->memory.rom;
memcpy(override.id, &cart->id, sizeof(override.id)); memcpy(override.id, &cart->id, sizeof(override.id));
if (GBAOverrideFind(GBAConfigGetOverrides(&context->config), &override)) { struct Configuration* overrides = 0;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
overrides = GBAConfigGetOverrides(&context->config);
GBAConfigFreeOpts(&opts);
#endif
if (GBAOverrideFind(overrides, &override)) {
GBAOverrideApply(context->gba, &override); GBAOverrideApply(context->gba, &override);
} }
GBAConfigFreeOpts(&opts);
return true; return true;
} }