Core: Add mCore.getGameTitle

This commit is contained in:
Jeffrey Pfau 2016-02-07 21:50:29 -08:00
parent d0771b78e2
commit 53191d2068
7 changed files with 38 additions and 5 deletions

View File

@ -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*);
};

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;
}

View File

@ -26,11 +26,12 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent)
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));

View File

@ -718,8 +718,9 @@ void Window::updateTitle(float fps) {
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;
}
}