diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index 9cad7a3e8..bca92b1ff 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -68,6 +68,7 @@ struct mCore { void (*setSync)(struct mCore*, struct mCoreSync*); void (*loadConfig)(struct mCore*, const struct mCoreConfig*); + void (*reloadConfigOption)(struct mCore*, const char* option, const struct mCoreConfig*); void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height); void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride); diff --git a/src/gb/core.c b/src/gb/core.c index 87eedfd40..655449eaf 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -224,6 +224,59 @@ static void _GBCoreLoadConfig(struct mCore* core, const struct mCoreConfig* conf #endif } +static void _GBCoreReloadConfigOption(struct mCore* core, const char* option, const struct mCoreConfig* config) { + struct GB* gb = core->board; + if (!config) { + config = &core->config; + } + + if (!option) { + // Reload options from opts + if (core->opts.mute) { + gb->audio.masterVolume = 0; + } else { + gb->audio.masterVolume = core->opts.volume; + } + gb->video.frameskip = core->opts.frameskip; + return; + } + + int fakeBool; + if (strcmp("mute", option) == 0) { + if (mCoreConfigGetIntValue(config, "mute", &fakeBool)) { + core->opts.mute = fakeBool; + + if (core->opts.mute) { + gb->audio.masterVolume = 0; + } else { + gb->audio.masterVolume = core->opts.volume; + } + } + return; + } + if (strcmp("volume", option) == 0) { + if (mCoreConfigGetIntValue(config, "volume", &core->opts.volume) && !core->opts.mute) { + gb->audio.masterVolume = core->opts.volume; + } + return; + } + if (strcmp("frameskip", option) == 0) { + if (mCoreConfigGetIntValue(config, "frameskip", &core->opts.frameskip)) { + gb->video.frameskip = core->opts.frameskip; + } + return; + } + if (strcmp("allowOpposingDirections", option) == 0) { + if (config != &core->config) { + mCoreConfigCopyValue(&core->config, config, "allowOpposingDirections"); + } + if (mCoreConfigGetIntValue(config, "allowOpposingDirections", &fakeBool)) { + gb->allowOpposingDirections = fakeBool; + } + return; + } +} + static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) { struct GB* gb = core->board; if (gb && (!(gb->model & GB_MODEL_SGB) || !gb->video.sgbBorders)) { @@ -901,6 +954,7 @@ struct mCore* GBCoreCreate(void) { core->supportsFeature = _GBCoreSupportsFeature; core->setSync = _GBCoreSetSync; core->loadConfig = _GBCoreLoadConfig; + core->reloadConfigOption = _GBCoreReloadConfigOption; core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions; core->setVideoBuffer = _GBCoreSetVideoBuffer; core->setVideoGLTex = _GBCoreSetVideoGLTex; diff --git a/src/gba/core.c b/src/gba/core.c index 20c08779e..c6cadd233 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -296,6 +296,59 @@ static void _GBACoreLoadConfig(struct mCore* core, const struct mCoreConfig* con mCoreConfigCopyValue(&core->config, config, "videoScale"); } +static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, const struct mCoreConfig* config) { + struct GBA* gba = core->board; + if (!config) { + config = &core->config; + } + + if (!option) { + // Reload options from opts + if (core->opts.mute) { + gba->audio.masterVolume = 0; + } else { + gba->audio.masterVolume = core->opts.volume; + } + gba->video.frameskip = core->opts.frameskip; + return; + } + + int fakeBool; + if (strcmp("mute", option) == 0) { + if (mCoreConfigGetIntValue(config, "mute", &fakeBool)) { + core->opts.mute = fakeBool; + + if (core->opts.mute) { + gba->audio.masterVolume = 0; + } else { + gba->audio.masterVolume = core->opts.volume; + } + } + return; + } + if (strcmp("volume", option) == 0) { + if (mCoreConfigGetIntValue(config, "volume", &core->opts.volume) && !core->opts.mute) { + gba->audio.masterVolume = core->opts.volume; + } + return; + } + if (strcmp("frameskip", option) == 0) { + if (mCoreConfigGetIntValue(config, "frameskip", &core->opts.frameskip)) { + gba->video.frameskip = core->opts.frameskip; + } + return; + } + if (strcmp("allowOpposingDirections", option) == 0) { + if (config != &core->config) { + mCoreConfigCopyValue(&core->config, config, "allowOpposingDirections"); + } + if (mCoreConfigGetIntValue(config, "allowOpposingDirections", &fakeBool)) { + gba->allowOpposingDirections = fakeBool; + } + return; + } +} + static void _GBACoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) { #if defined(BUILD_GLES2) || defined(BUILD_GLES3) struct GBACore* gbacore = (struct GBACore*) core; @@ -1021,6 +1074,7 @@ struct mCore* GBACoreCreate(void) { core->supportsFeature = _GBACoreSupportsFeature; core->setSync = _GBACoreSetSync; core->loadConfig = _GBACoreLoadConfig; + core->reloadConfigOption = _GBACoreReloadConfigOption; core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions; core->setVideoBuffer = _GBACoreSetVideoBuffer; core->setVideoGLTex = _GBACoreSetVideoGLTex; diff --git a/src/platform/qt/CoreController.cpp b/src/platform/qt/CoreController.cpp index fecc36ccc..f0e29584d 100644 --- a/src/platform/qt/CoreController.cpp +++ b/src/platform/qt/CoreController.cpp @@ -922,33 +922,8 @@ void CoreController::updateFastForward() { m_threadContext.impl->sync.fpsTarget = m_fpsTarget; setSync(true); } - // XXX: Have a way of just updating volume - switch (platform()) { -#ifdef M_CORE_GBA - case PLATFORM_GBA: { - GBA* gba = static_cast(m_threadContext.core->board); - if (m_threadContext.core->opts.mute) { - gba->audio.masterVolume = 0; - } else { - gba->audio.masterVolume = m_threadContext.core->opts.volume; - } - break; - } -#endif -#ifdef M_CORE_GB - case PLATFORM_GB: { - GB* gb = static_cast(m_threadContext.core->board); - if (m_threadContext.core->opts.mute) { - gb->audio.masterVolume = 0; - } else { - gb->audio.masterVolume = m_threadContext.core->opts.volume; - } - break; - } -#endif - default: - break; - } + + m_threadContext.core->reloadConfigOption(m_threadContext.core, NULL, NULL); } CoreController::Interrupter::Interrupter(CoreController* parent, bool fromThread)