From 53191d2068770348e93c0648f7c82ee7a0a64dd0 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 7 Feb 2016 21:50:29 -0800 Subject: [PATCH] Core: Add mCore.getGameTitle --- src/core/core.h | 2 ++ src/gb/core.c | 5 +++++ src/gb/gb.c | 18 ++++++++++++++++++ src/gb/gb.h | 1 + src/gba/core.c | 5 +++++ src/platform/qt/ROMInfo.cpp | 7 ++++--- src/platform/qt/Window.cpp | 5 +++-- 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/core/core.h b/src/core/core.h index 891918daf..b3a66d541 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -74,6 +74,8 @@ struct mCore { int32_t (*frameCycles)(struct mCore*); int32_t (*frequency)(struct mCore*); + void (*getGameTitle)(struct mCore*, char* title); + void (*setRTC)(struct mCore*, struct mRTCSource*); }; diff --git a/src/gb/core.c b/src/gb/core.c index 07af91ce8..0a1a1f161 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -190,6 +190,10 @@ static int32_t _GBCoreFrequency(struct mCore* core) { return DMG_LR35902_FREQUENCY; } +static void _GBCoreGetGameTitle(struct mCore* core, char* title) { + GBGetGameTitle(core->board, title); +} + static void _GBCoreSetRTC(struct mCore* core, struct mRTCSource* rtc) { struct GB* gb = core->board; gb->memory.rtc = rtc; @@ -226,6 +230,7 @@ struct mCore* GBCoreCreate(void) { core->frameCounter = _GBCoreFrameCounter; core->frameCycles = _GBCoreFrameCycles; core->frequency = _GBCoreFrequency; + core->getGameTitle = _GBCoreGetGameTitle; core->setRTC = _GBCoreSetRTC; return core; } diff --git a/src/gb/gb.c b/src/gb/gb.c index 82cb03bfe..7acc7de64 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -307,3 +307,21 @@ bool GBIsROM(struct VFile* vf) { } return true; } + +void GBGetGameTitle(struct GB* gb, char* out) { + const struct GBCartridge* cart = NULL; + if (gb->memory.rom) { + cart = (const struct GBCartridge*) &gb->memory.rom[0x100]; + } + if (gb->pristineRom) { + cart = (const struct GBCartridge*) &gb->pristineRom[0x100]; + } + if (!cart) { + return; + } + if (cart->oldLicensee != 0x33) { + memcpy(out, cart->titleLong, 16); + } else { + memcpy(out, cart->titleShort, 11); + } +} diff --git a/src/gb/gb.h b/src/gb/gb.h index 672a8dfc2..99b605e2e 100644 --- a/src/gb/gb.h +++ b/src/gb/gb.h @@ -107,6 +107,7 @@ struct Patch; void GBApplyPatch(struct GB* gb, struct Patch* patch); bool GBIsROM(struct VFile* vf); +void GBGetGameTitle(struct GB* gba, char* out); void GBFrameStarted(struct GB* gb); void GBFrameEnded(struct GB* gb); diff --git a/src/gba/core.c b/src/gba/core.c index ea0d349aa..cce530d21 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -238,6 +238,10 @@ static int32_t _GBACoreFrequency(struct mCore* core) { return GBA_ARM7TDMI_FREQUENCY; } +static void _GBACoreGetGameTitle(struct mCore* core, char* title) { + GBAGetGameTitle(core->board, title); +} + static void _GBACoreSetRTC(struct mCore* core, struct mRTCSource* rtc) { struct GBA* gba = core->board; gba->rtcSource = rtc; @@ -276,6 +280,7 @@ struct mCore* GBACoreCreate(void) { core->frameCounter = _GBACoreFrameCounter; core->frameCycles = _GBACoreFrameCycles; core->frequency = _GBACoreFrequency; + core->getGameTitle = _GBACoreGetGameTitle; core->setRTC = _GBACoreSetRTC; return core; } diff --git a/src/platform/qt/ROMInfo.cpp b/src/platform/qt/ROMInfo.cpp index b50314b4d..5341727bd 100644 --- a/src/platform/qt/ROMInfo.cpp +++ b/src/platform/qt/ROMInfo.cpp @@ -26,11 +26,12 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) const NoIntroDB* db = GBAApp::app()->gameDB(); controller->threadInterrupt(); - GBA* gba = static_cast(controller->thread()->core->board); - char title[13] = {}; + mCore* core = controller->thread()->core; + GBA* gba = static_cast(core->board); + char title[17] = {}; GBAGetGameCode(gba, title); m_ui.id->setText(QLatin1String(title)); - GBAGetGameTitle(gba, 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)); diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 801046f31..a856ad1ec 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -718,8 +718,9 @@ void Window::updateTitle(float fps) { if (db && NoIntroDBLookupGameByCRC(db, static_cast(m_controller->thread()->core->board)->romCrc32, &game)) { title = QLatin1String(game.name); } else { - char gameTitle[13] = { '\0' }; - GBAGetGameTitle(static_cast(m_controller->thread()->core->board), gameTitle); + char gameTitle[17] = { '\0' }; + mCore* core = m_controller->thread()->core; + core->getGameTitle(core, gameTitle); title = gameTitle; } }