From d7d8dacaa86c8d39cd63fc728f7dd13f9fe5e4aa Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 16 Feb 2016 22:18:09 -0800 Subject: [PATCH] Qt: Update ROMInfo dialog --- src/core/core.h | 1 + src/gb/core.c | 5 +++++ src/gb/gb.c | 17 ++++++++++++++++ src/gb/gb.h | 1 + src/gba/core.c | 5 +++++ src/platform/qt/ROMInfo.cpp | 39 +++++++++++++++++++++++++++++-------- 6 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/core/core.h b/src/core/core.h index b8cc04dff..1432b37d3 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -88,6 +88,7 @@ struct mCore { int32_t (*frequency)(struct mCore*); void (*getGameTitle)(struct mCore*, char* title); + void (*getGameCode)(struct mCore*, char* title); void (*setRTC)(struct mCore*, struct mRTCSource*); }; diff --git a/src/gb/core.c b/src/gb/core.c index fcb60ddf8..386f46222 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -230,6 +230,10 @@ static void _GBCoreGetGameTitle(struct mCore* core, char* title) { GBGetGameTitle(core->board, title); } +static void _GBCoreGetGameCode(struct mCore* core, char* title) { + GBGetGameCode(core->board, title); +} + static void _GBCoreSetRTC(struct mCore* core, struct mRTCSource* rtc) { struct GB* gb = core->board; gb->memory.rtc = rtc; @@ -272,6 +276,7 @@ struct mCore* GBCoreCreate(void) { core->frameCycles = _GBCoreFrameCycles; core->frequency = _GBCoreFrequency; core->getGameTitle = _GBCoreGetGameTitle; + core->getGameCode = _GBCoreGetGameCode; core->setRTC = _GBCoreSetRTC; return core; } diff --git a/src/gb/gb.c b/src/gb/gb.c index 2a8bdc8b1..519971303 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -342,3 +342,20 @@ void GBGetGameTitle(struct GB* gb, char* out) { memcpy(out, cart->titleShort, 11); } } + +void GBGetGameCode(struct GB* gb, char* out) { + memset(out, 0, 4); + 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->maker, 11); + } +} diff --git a/src/gb/gb.h b/src/gb/gb.h index cbf57ebcf..8f29389ac 100644 --- a/src/gb/gb.h +++ b/src/gb/gb.h @@ -113,6 +113,7 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch); bool GBIsROM(struct VFile* vf); void GBGetGameTitle(struct GB* gba, char* out); +void GBGetGameCode(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 ec5582c21..0540c1fd1 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -263,6 +263,10 @@ static void _GBACoreGetGameTitle(struct mCore* core, char* title) { GBAGetGameTitle(core->board, title); } +static void _GBACoreGetGameCode(struct mCore* core, char* title) { + GBAGetGameCode(core->board, title); +} + static void _GBACoreSetRTC(struct mCore* core, struct mRTCSource* rtc) { struct GBA* gba = core->board; gba->rtcSource = rtc; @@ -305,6 +309,7 @@ struct mCore* GBACoreCreate(void) { core->frameCycles = _GBACoreFrameCycles; core->frequency = _GBACoreFrequency; core->getGameTitle = _GBACoreGetGameTitle; + core->getGameCode = _GBACoreGetGameCode; core->setRTC = _GBACoreSetRTC; return core; } diff --git a/src/platform/qt/ROMInfo.cpp b/src/platform/qt/ROMInfo.cpp index 70eca4fbb..17a5caf73 100644 --- a/src/platform/qt/ROMInfo.cpp +++ b/src/platform/qt/ROMInfo.cpp @@ -10,7 +10,12 @@ extern "C" { #include "core/core.h" +#ifdef M_CORE_GB +#include "gb/gb.h" +#endif +#ifdef M_CORE_GBA #include "gba/gba.h" +#endif #include "util/nointro.h" } @@ -32,12 +37,19 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) char title[17] = {}; core->getGameTitle(core, title); m_ui.title->setText(QLatin1String(title)); - - if (controller->thread()->core->platform(controller->thread()->core) == PLATFORM_GBA) { - GBA* gba = static_cast(core->board); - GBAGetGameCode(gba, title); + core->getGameCode(core, title); + title[4] = '\0'; + if (title[0]) { m_ui.id->setText(QLatin1String(title)); - m_ui.size->setText(QString::number(gba->pristineRomSize)); + } else { + m_ui.id->setText(tr("(unknown)")); + } + + switch (controller->thread()->core->platform(controller->thread()->core)) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: { + GBA* gba = static_cast(core->board); + m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes")); m_ui.crc->setText(QString::number(gba->romCrc32, 16)); if (db) { NoIntroGame game; @@ -49,12 +61,23 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) } else { m_ui.name->setText(tr("(no database present)")); } - } else { - // TODO: GB - m_ui.id->setText(tr("(unknown)")); + break; + } +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: { + GB* gb = static_cast(core->board); + m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes")); + m_ui.crc->setText(QString::number(gb->romCrc32, 16)); + m_ui.name->setText(tr("(unknown)")); + break; + } +#endif + default: m_ui.size->setText(tr("(unknown)")); m_ui.crc->setText(tr("(unknown)")); m_ui.name->setText(tr("(unknown)")); + } controller->threadContinue(); }