all repos — mgba @ 53191d2068770348e93c0648f7c82ee7a0a64dd0

mGBA Game Boy Advance Emulator

Core: Add mCore.getGameTitle
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Feb 2016 21:50:29 -0800
commit

53191d2068770348e93c0648f7c82ee7a0a64dd0

parent

d0771b78e22e89b5523badee256ec6e15467dc54

M src/core/core.hsrc/core/core.h

@@ -74,6 +74,8 @@ int32_t (*frameCounter)(struct mCore*);

int32_t (*frameCycles)(struct mCore*); int32_t (*frequency)(struct mCore*); + void (*getGameTitle)(struct mCore*, char* title); + void (*setRTC)(struct mCore*, struct mRTCSource*); };
M src/gb/core.csrc/gb/core.c

@@ -190,6 +190,10 @@ // TODO: GB differences

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 @@ core->clearKeys = _GBCoreClearKeys;

core->frameCounter = _GBCoreFrameCounter; core->frameCycles = _GBCoreFrameCycles; core->frequency = _GBCoreFrequency; + core->getGameTitle = _GBCoreGetGameTitle; core->setRTC = _GBCoreSetRTC; return core; }
M src/gb/gb.csrc/gb/gb.c

@@ -307,3 +307,21 @@ return false;

} 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); + } +}
M src/gb/gb.hsrc/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);
M src/gba/core.csrc/gba/core.c

@@ -238,6 +238,10 @@ UNUSED(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 @@ core->clearKeys = _GBACoreClearKeys;

core->frameCounter = _GBACoreFrameCounter; core->frameCycles = _GBACoreFrameCycles; core->frequency = _GBACoreFrequency; + core->getGameTitle = _GBACoreGetGameTitle; core->setRTC = _GBACoreSetRTC; return core; }
M src/platform/qt/ROMInfo.cppsrc/platform/qt/ROMInfo.cpp

@@ -26,11 +26,12 @@

const NoIntroDB* db = GBAApp::app()->gameDB(); controller->threadInterrupt(); - GBA* gba = static_cast<GBA*>(controller->thread()->core->board); - char title[13] = {}; + mCore* core = controller->thread()->core; + GBA* gba = static_cast<GBA*>(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));
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -718,8 +718,9 @@ NoIntroGame game;

if (db && NoIntroDBLookupGameByCRC(db, static_cast<GBA*>(m_controller->thread()->core->board)->romCrc32, &game)) { title = QLatin1String(game.name); } else { - char gameTitle[13] = { '\0' }; - GBAGetGameTitle(static_cast<GBA*>(m_controller->thread()->core->board), gameTitle); + char gameTitle[17] = { '\0' }; + mCore* core = m_controller->thread()->core; + core->getGameTitle(core, gameTitle); title = gameTitle; } }