From 5bcf56c5caccea4021abc92b461a0873978546f5 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 9 Feb 2016 22:03:31 -0800 Subject: [PATCH] Qt: GBA refactoring and cleanup --- src/core/core.h | 2 ++ src/gb/core.c | 6 +++++ src/gba/core.c | 6 +++++ src/platform/qt/GameController.cpp | 36 ++++++++++++++++-------------- src/platform/qt/ROMInfo.cpp | 31 ++++++++++++++++--------- src/platform/qt/Window.cpp | 6 +++-- 6 files changed, 57 insertions(+), 30 deletions(-) diff --git a/src/core/core.h b/src/core/core.h index dcb4fcf90..b8cc04dff 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -46,6 +46,8 @@ struct mCore { bool (*init)(struct mCore*); void (*deinit)(struct mCore*); + enum mPlatform (*platform)(struct mCore*); + void (*setSync)(struct mCore*, struct mCoreSync*); void (*loadConfig)(struct mCore*, const struct mCoreConfig*); diff --git a/src/gb/core.c b/src/gb/core.c index 026497594..ca7b06109 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -55,6 +55,11 @@ static void _GBCoreDeinit(struct mCore* core) { #endif } +static enum mPlatform _GBCorePlatform(struct mCore* core) { + UNUSED(core); + return PLATFORM_GB; +} + static void _GBCoreSetSync(struct mCore* core, struct mCoreSync* sync) { struct GB* gb = core->board; gb->sync = sync; @@ -229,6 +234,7 @@ struct mCore* GBCoreCreate(void) { core->board = 0; core->init = _GBCoreInit; core->deinit = _GBCoreDeinit; + core->platform = _GBCorePlatform; core->setSync = _GBCoreSetSync; core->loadConfig = _GBCoreLoadConfig; core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions; diff --git a/src/gba/core.c b/src/gba/core.c index bdc35d0dc..c210278b3 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -64,6 +64,11 @@ static void _GBACoreDeinit(struct mCore* core) { #endif } +static enum mPlatform _GBACorePlatform(struct mCore* core) { + UNUSED(core); + return PLATFORM_GBA; +} + static void _GBACoreSetSync(struct mCore* core, struct mCoreSync* sync) { struct GBA* gba = core->board; gba->sync = sync; @@ -265,6 +270,7 @@ struct mCore* GBACoreCreate(void) { core->board = 0; core->init = _GBACoreInit; core->deinit = _GBACoreDeinit; + core->platform = _GBACorePlatform; core->setSync = _GBACoreSetSync; core->loadConfig = _GBACoreLoadConfig; core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions; diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 477f85779..129ddecc5 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -86,21 +86,23 @@ GameController::GameController(QObject* parent) mRTCGenericSourceInit(&controller->m_rtc, context->core); context->core->setRTC(context->core, &controller->m_rtc.d); - /*GBA* gba = static_cast(context->core->board); - gba->luminanceSource = &controller->m_lux; - gba->rumble = controller->m_inputController->rumble(); - gba->rotationSource = controller->m_inputController->rotationSource(); - 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]; - gba->audio.psg.forceDisableCh[3] = !controller->m_audioChannels[3]; - gba->audio.forceDisableChA = !controller->m_audioChannels[4]; - gba->audio.forceDisableChB = !controller->m_audioChannels[5]; - gba->video.renderer->disableBG[0] = !controller->m_videoLayers[0]; - gba->video.renderer->disableBG[1] = !controller->m_videoLayers[1]; - gba->video.renderer->disableBG[2] = !controller->m_videoLayers[2]; - gba->video.renderer->disableBG[3] = !controller->m_videoLayers[3]; - gba->video.renderer->disableOBJ = !controller->m_videoLayers[4];*/ + if (context->core->platform(context->core) == PLATFORM_GBA) { + GBA* gba = static_cast(context->core->board); + gba->luminanceSource = &controller->m_lux; + gba->rumble = controller->m_inputController->rumble(); + gba->rotationSource = controller->m_inputController->rotationSource(); + 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]; + gba->audio.psg.forceDisableCh[3] = !controller->m_audioChannels[3]; + gba->audio.forceDisableChA = !controller->m_audioChannels[4]; + gba->audio.forceDisableChB = !controller->m_audioChannels[5]; + gba->video.renderer->disableBG[0] = !controller->m_videoLayers[0]; + gba->video.renderer->disableBG[1] = !controller->m_videoLayers[1]; + gba->video.renderer->disableBG[2] = !controller->m_videoLayers[2]; + gba->video.renderer->disableBG[3] = !controller->m_videoLayers[3]; + gba->video.renderer->disableOBJ = !controller->m_videoLayers[4]; + } controller->m_fpsTarget = context->sync.fpsTarget; if (mCoreLoadState(context->core, 0, controller->m_loadStateFlags)) { @@ -661,9 +663,9 @@ void GameController::setVideoLayerEnabled(int layer, bool enable) { if (layer > 4 || layer < 0) { return; } - GBA* gba = static_cast(m_threadContext.core->board); m_videoLayers[layer] = enable; - if (isLoaded()) { + if (isLoaded() && m_threadContext.core->platform(m_threadContext.core) == PLATFORM_GBA) { + GBA* gba = static_cast(m_threadContext.core->board); switch (layer) { case 0: case 1: diff --git a/src/platform/qt/ROMInfo.cpp b/src/platform/qt/ROMInfo.cpp index 8d41f5702..70eca4fbb 100644 --- a/src/platform/qt/ROMInfo.cpp +++ b/src/platform/qt/ROMInfo.cpp @@ -29,23 +29,32 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) controller->threadInterrupt(); mCore* core = controller->thread()->core; - GBA* gba = static_cast(core->board); char title[17] = {}; - GBAGetGameCode(gba, title); - m_ui.id->setText(QLatin1String(title)); core->getGameTitle(core, title); m_ui.title->setText(QLatin1String(title)); - m_ui.size->setText(QString::number(gba->pristineRomSize)); - m_ui.crc->setText(QString::number(gba->romCrc32, 16)); - if (db) { - NoIntroGame game; - if (NoIntroDBLookupGameByCRC(db, gba->romCrc32, &game)) { - m_ui.name->setText(game.name); + + if (controller->thread()->core->platform(controller->thread()->core) == PLATFORM_GBA) { + GBA* gba = static_cast(core->board); + GBAGetGameCode(gba, title); + m_ui.id->setText(QLatin1String(title)); + m_ui.size->setText(QString::number(gba->pristineRomSize)); + m_ui.crc->setText(QString::number(gba->romCrc32, 16)); + if (db) { + NoIntroGame game; + if (NoIntroDBLookupGameByCRC(db, gba->romCrc32, &game)) { + m_ui.name->setText(game.name); + } else { + m_ui.name->setText(tr("(unknown)")); + } } else { - m_ui.name->setText(tr("(unknown)")); + m_ui.name->setText(tr("(no database present)")); } } else { - m_ui.name->setText(tr("(no database present)")); + // TODO: GB + m_ui.id->setText(tr("(unknown)")); + m_ui.size->setText(tr("(unknown)")); + m_ui.crc->setText(tr("(unknown)")); + m_ui.name->setText(tr("(unknown)")); } controller->threadContinue(); } diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index ce8c41688..9c39030d9 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -153,7 +153,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) }); connect(&m_inputController, SIGNAL(profileLoaded(const QString&)), m_shortcutController, SLOT(loadProfile(const QString&))); - m_log.setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS); + m_log.setLevels(mLOG_WARN | mLOG_ERROR | mLOG_FATAL); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL); m_focusCheck.setInterval(200); @@ -295,6 +295,7 @@ void Window::selectROM() { void Window::replaceROM() { QStringList formats{ "*.gba", + "*.gb", #if defined(USE_LIBZIP) || defined(USE_ZLIB) "*.zip", #endif @@ -717,7 +718,8 @@ void Window::updateTitle(float fps) { if (m_controller->isLoaded()) { const NoIntroDB* db = GBAApp::app()->gameDB(); NoIntroGame game; - if (db && NoIntroDBLookupGameByCRC(db, static_cast(m_controller->thread()->core->board)->romCrc32, &game)) { + if (m_controller->thread()->core->platform(m_controller->thread()->core) == PLATFORM_GBA && db && + NoIntroDBLookupGameByCRC(db, static_cast(m_controller->thread()->core->board)->romCrc32, &game)) { title = QLatin1String(game.name); } else { char gameTitle[17] = { '\0' };