all repos — mgba @ 3f71924c344a6a417f2087af9482dfb8317c3133

mGBA Game Boy Advance Emulator

Merge branch 'master' into medusa
Vicki Pfau vi@endrift.com
Sun, 09 Apr 2017 23:36:26 -0700
commit

3f71924c344a6a417f2087af9482dfb8317c3133

parent

c3a19ddb8c40c543bff4b537062aa16821ea1e30

M CHANGESCHANGES

@@ -92,6 +92,7 @@ - Qt: Re-enable QtMultimedia on Windows

- FFmpeg: Return false if a file fails to open - FFmpeg: Force MP4 files to YUV420P - Qt: Make "Mute" able to be bound to a key + - Core: Restore sleep callback medusa alpha 1: (2017-04-08) Features:
M include/mgba/core/core.hinclude/mgba/core/core.h

@@ -117,8 +117,7 @@

void (*getGameTitle)(const struct mCore*, char* title); void (*getGameCode)(const struct mCore*, char* title); - void (*setRotation)(struct mCore*, struct mRotationSource*); - void (*setRumble)(struct mCore*, struct mRumble*); + void (*setPeripheral)(struct mCore*, int type, void*); uint32_t (*busRead8)(struct mCore*, uint32_t address); uint32_t (*busRead16)(struct mCore*, uint32_t address);
M include/mgba/core/interface.hinclude/mgba/core/interface.h

@@ -38,6 +38,7 @@ void* context;

void (*videoFrameStarted)(void* context); void (*videoFrameEnded)(void* context); void (*coreCrashed)(void* context); + void (*sleep)(void* context); }; DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);

@@ -53,8 +54,10 @@ struct mKeyCallback {

uint16_t (*readKeys)(struct mKeyCallback*); }; -struct mStopCallback { - void (*stop)(struct mStopCallback*); +enum mPeripheral { + mPERIPH_ROTATION = 1, + mPERIPH_RUMBLE, + mPERIPH_CUSTOM = 0x1000 }; struct mRotationSource {
M include/mgba/core/thread.hinclude/mgba/core/thread.h

@@ -62,6 +62,7 @@ ThreadCallback startCallback;

ThreadCallback resetCallback; ThreadCallback cleanCallback; ThreadCallback frameCallback; + ThreadCallback sleepCallback; void* userData; void (*run)(struct mCoreThread*);
M include/mgba/gba/interface.hinclude/mgba/gba/interface.h

@@ -28,6 +28,10 @@ struct GBAVideoRenderer;

extern const int GBA_LUX_LEVELS[10]; +enum { + mPERIPH_GBA_LUMINANCE = 0x1000 +}; + struct GBALuminanceSource { void (*sample)(struct GBALuminanceSource*);
M include/mgba/internal/gba/gba.hinclude/mgba/internal/gba/gba.h

@@ -99,7 +99,6 @@ struct VFile* biosVf;

struct mAVStream* stream; struct mKeyCallback* keyCallback; - struct mStopCallback* stopCallback; struct mCoreCallbacksList coreCallbacks; enum GBAIdleLoopOptimization idleOptimization;
M src/core/thread.csrc/core/thread.c

@@ -120,6 +120,16 @@ }

_changeState(thread, THREAD_CRASHED, true); } +void _coreSleep(void* context) { + struct mCoreThread* thread = context; + if (!thread) { + return; + } + if (thread->sleepCallback) { + thread->sleepCallback(thread); + } +} + static THREAD_ENTRY _mCoreThreadRun(void* context) { struct mCoreThread* threadContext = context; #ifdef USE_PTHREADS

@@ -143,6 +153,7 @@ struct mCoreCallbacks callbacks = {

.videoFrameStarted = _frameStarted, .videoFrameEnded = _frameEnded, .coreCrashed = _crashed, + .sleep = _coreSleep, .context = threadContext }; core->addCoreCallbacks(core, &callbacks);
M src/ds/core.csrc/ds/core.c

@@ -393,12 +393,15 @@ static void _DSCoreGetGameCode(const struct mCore* core, char* title) {

DSGetGameCode(core->board, title); } -static void _DSCoreSetRotation(struct mCore* core, struct mRotationSource* rotation) { -} - -static void _DSCoreSetRumble(struct mCore* core, struct mRumble* rumble) { +static void _DSCoreSetPeripheral(struct mCore* core, int type, void* periph) { struct DS* ds = core->board; - ds->rumble = rumble; + switch (type) { + case mPERIPH_RUMBLE: + ds->rumble = periph; + break; + default: + break; + } } static uint32_t _DSCoreBusRead8(struct mCore* core, uint32_t address) {

@@ -558,8 +561,7 @@ core->frameCycles = _DSCoreFrameCycles;

core->frequency = _DSCoreFrequency; core->getGameTitle = _DSCoreGetGameTitle; core->getGameCode = _DSCoreGetGameCode; - core->setRotation = _DSCoreSetRotation; - core->setRumble = _DSCoreSetRumble; + core->setPeripheral = _DSCoreSetPeripheral; core->busRead8 = _DSCoreBusRead8; core->busRead16 = _DSCoreBusRead16; core->busRead32 = _DSCoreBusRead32;
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -298,7 +298,7 @@ GUIShowMessageBox(&runner->params, GUI_MESSAGE_BOX_OK, 240, "Load failed!");

return; } if (runner->core->platform(runner->core) == PLATFORM_GBA) { - ((struct GBA*) runner->core->board)->luminanceSource = &runner->luminanceSource.d; + runner->core->setPeripheral(runner->core, mPERIPH_GBA_LUMINANCE, &runner->luminanceSource.d); } mLOG(GUI_RUNNER, DEBUG, "Loading config..."); mCoreLoadForeignConfig(runner->core, &runner->config);
M src/gb/core.csrc/gb/core.c

@@ -428,14 +428,18 @@ static void _GBCoreGetGameCode(const struct mCore* core, char* title) {

GBGetGameCode(core->board, title); } -static void _GBCoreSetRotation(struct mCore* core, struct mRotationSource* rotation) { +static void _GBCoreSetPeripheral(struct mCore* core, int type, void* periph) { struct GB* gb = core->board; - gb->memory.rotation = rotation; -} - -static void _GBCoreSetRumble(struct mCore* core, struct mRumble* rumble) { - struct GB* gb = core->board; - gb->memory.rumble = rumble; + switch (type) { + case mPERIPH_ROTATION: + gb->memory.rotation = periph; + break; + case mPERIPH_RUMBLE: + gb->memory.rumble = periph; + break; + default: + return; + } } static uint32_t _GBCoreBusRead8(struct mCore* core, uint32_t address) {

@@ -642,8 +646,7 @@ core->frameCycles = _GBCoreFrameCycles;

core->frequency = _GBCoreFrequency; core->getGameTitle = _GBCoreGetGameTitle; core->getGameCode = _GBCoreGetGameCode; - core->setRotation = _GBCoreSetRotation; - core->setRumble = _GBCoreSetRumble; + core->setPeripheral = _GBCoreSetPeripheral; core->busRead8 = _GBCoreBusRead8; core->busRead16 = _GBCoreBusRead16; core->busRead32 = _GBCoreBusRead32;
M src/gba/core.csrc/gba/core.c

@@ -424,14 +424,21 @@ static void _GBACoreGetGameCode(const struct mCore* core, char* title) {

GBAGetGameCode(core->board, title); } -static void _GBACoreSetRotation(struct mCore* core, struct mRotationSource* rotation) { +static void _GBACoreSetPeripheral(struct mCore* core, int type, void* periph) { struct GBA* gba = core->board; - gba->rotationSource = rotation; -} - -static void _GBACoreSetRumble(struct mCore* core, struct mRumble* rumble) { - struct GBA* gba = core->board; - gba->rumble = rumble; + switch (type) { + case mPERIPH_ROTATION: + gba->rotationSource = periph; + break; + case mPERIPH_RUMBLE: + gba->rumble = periph; + break; + case mPERIPH_GBA_LUMINANCE: + gba->luminanceSource = periph; + break; + default: + return; + } } static uint32_t _GBACoreBusRead8(struct mCore* core, uint32_t address) {

@@ -640,8 +647,7 @@ core->frameCycles = _GBACoreFrameCycles;

core->frequency = _GBACoreFrequency; core->getGameTitle = _GBACoreGetGameTitle; core->getGameCode = _GBACoreGetGameCode; - core->setRotation = _GBACoreSetRotation; - core->setRumble = _GBACoreSetRumble; + core->setPeripheral = _GBACoreSetPeripheral; core->busRead8 = _GBACoreBusRead8; core->busRead16 = _GBACoreBusRead16; core->busRead32 = _GBACoreBusRead32;
M src/gba/gba.csrc/gba/gba.c

@@ -89,8 +89,6 @@ gba->biosVf = 0;

gba->stream = NULL; gba->keyCallback = NULL; - gba->stopCallback = NULL; - gba->stopCallback = NULL; mCoreCallbacksListInit(&gba->coreCallbacks, 0); gba->biosChecksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);

@@ -449,11 +447,14 @@ ARMHalt(gba->cpu);

} void GBAStop(struct GBA* gba) { - if (!gba->stopCallback) { - return; + size_t c; + for (c = 0; c < mCoreCallbacksListSize(&gba->coreCallbacks); ++c) { + struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&gba->coreCallbacks, c); + if (callbacks->sleep) { + callbacks->sleep(callbacks->context); + } } gba->cpu->nextEvent = gba->cpu->cycles; - gba->stopCallback->stop(gba->stopCallback); } void GBADebug(struct GBA* gba, uint16_t flags) {
M src/platform/3ds/main.csrc/platform/3ds/main.c

@@ -242,7 +242,7 @@ mCoreConfigSetDefaultIntValue(&runner->config, "threadedVideo", 1);

mCoreLoadForeignConfig(runner->core, &runner->config); } - runner->core->setRotation(runner->core, &rotation.d); + runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation.d); if (hasSound != NO_SOUND) { runner->core->setAVStream(runner->core, &stream); }
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -398,7 +398,7 @@

blip_set_rates(core->getAudioChannel(core, 0), core->frequency(core), 32768); blip_set_rates(core->getAudioChannel(core, 1), core->frequency(core), 32768); - core->setRumble(core, &rumble); + core->setPeripheral(core, mPERIPH_RUMBLE, &rumble); savedata = anonymousMemoryMap(SIZE_CART_FLASH1M); struct VFile* save = VFileFromMemory(savedata, SIZE_CART_FLASH1M);

@@ -409,8 +409,7 @@ core->loadSave(core, save);

#ifdef M_CORE_GBA if (core->platform(core) == PLATFORM_GBA) { - struct GBA* gba = core->board; - gba->luminanceSource = &lux; + core->setPeripheral(core, mPERIPH_GBA_LUMINANCE, &lux); const char* sysDir = 0; if (core->opts.useBios && environCallback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sysDir)) {
M src/platform/psp2/psp2-context.csrc/platform/psp2/psp2-context.c

@@ -203,11 +203,11 @@ rotation.d.sample = _sampleRotation;

rotation.d.readTiltX = _readTiltX; rotation.d.readTiltY = _readTiltY; rotation.d.readGyroZ = _readGyroZ; - runner->core->setRotation(runner->core, &rotation.d); + runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation.d); rumble.d.setRumble = _setRumble; CircleBufferInit(&rumble.history, RUMBLE_PWM); - runner->core->setRumble(runner->core, &rumble.d); + runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d); frameLimiter = true; backdrop = vita2d_load_PNG_buffer(_binary_backdrop_png_start);
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -87,8 +87,8 @@ #endif

m_threadContext.startCallback = [](mCoreThread* context) { GameController* controller = static_cast<GameController*>(context->userData); - context->core->setRotation(context->core, controller->m_inputController->rotationSource()); - context->core->setRumble(context->core, controller->m_inputController->rumble()); + context->core->setPeripheral(context->core, mPERIPH_ROTATION, controller->m_inputController->rotationSource()); + context->core->setPeripheral(context->core, mPERIPH_RUMBLE, controller->m_inputController->rumble()); #ifdef M_CORE_GBA GBA* gba = static_cast<GBA*>(context->core->board);

@@ -99,7 +99,7 @@ #endif

switch (context->core->platform(context->core)) { #ifdef M_CORE_GBA case PLATFORM_GBA: - gba->luminanceSource = &controller->m_lux; + context->core->setPeripheral(context->core, mPERIPH_GBA_LUMINANCE, &controller->m_lux); gba->audio.psg.forceDisableCh[0] = !controller->m_audioChannels[0]; gba->audio.psg.forceDisableCh[1] = !controller->m_audioChannels[1]; gba->audio.psg.forceDisableCh[2] = !controller->m_audioChannels[2];

@@ -217,18 +217,16 @@ QMetaObject::invokeMethod(controller, "gamePaused", Q_ARG(mCoreThread*, context));

} }; - // TODO: Put back - /*m_threadContext.stopCallback = [](mCoreThread* context) { + m_threadContext.sleepCallback = [](mCoreThread* context) { if (!context) { - return false; + return; } GameController* controller = static_cast<GameController*>(context->userData); if (!mCoreSaveState(context->core, 0, controller->m_saveStateFlags)) { - return false; + return; } QMetaObject::invokeMethod(controller, "closeGame"); - return true; - };*/ + }; m_threadContext.logger.d.log = [](mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) { mThreadLogger* logContext = reinterpret_cast<mThreadLogger*>(logger);

@@ -643,6 +641,8 @@ void GameController::cleanGame() {

if (!m_gameOpen || mCoreThreadIsActive(&m_threadContext)) { return; } + + m_audioProcessor->pause(); mCoreThreadJoin(&m_threadContext); if (m_tileCache) {
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -130,7 +130,7 @@ mSDLAttachPlayer(&renderer.events, &renderer.player);

mSDLPlayerLoadConfig(&renderer.player, mCoreConfigGetInput(&renderer.core->config)); #if SDL_VERSION_ATLEAST(2, 0, 0) - renderer.core->setRumble(renderer.core, &renderer.player.rumble.d); + renderer.core->setPeripheral(renderer.core, mPERIPH_RUMBLE, &renderer.player.rumble.d); #endif int ret;
M src/platform/wii/main.csrc/platform/wii/main.c

@@ -641,8 +641,8 @@ _reproj2(vmode->fbWidth * guiScale * wAdjust, vmode->efbHeight * guiScale * hAdjust);

} void _setup(struct mGUIRunner* runner) { - runner->core->setRotation(runner->core, &rotation); - runner->core->setRumble(runner->core, &rumble); + runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation); + runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble); _mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_A, GBA_KEY_A); _mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_B, GBA_KEY_B);