diff --git a/CHANGES b/CHANGES index bcdc43b50..b22b60175 100644 --- a/CHANGES +++ b/CHANGES @@ -46,6 +46,7 @@ Misc: - Feature: Move game database from flatfile to SQLite3 - GB Audio: Start implementing "zombie" audio (fixes mgba.io/i/389) - VFS: Fix some minor VFile issues with FILEs + - Core: Add generic checksum function 0.5.2: (2016-12-31) Bugfixes: diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index 473e6f876..06c7a7184 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -33,6 +33,10 @@ enum mPlatform { #endif }; +enum mCoreChecksumType { + CHECKSUM_CRC32, +}; + struct mRTCSource; struct mCoreConfig; struct mCoreSync; @@ -77,6 +81,7 @@ struct mCore { bool (*loadSave)(struct mCore*, struct VFile* vf); bool (*loadTemporarySave)(struct mCore*, struct VFile* vf); void (*unloadROM)(struct mCore*); + void (*checksum)(const struct mCore*, void* data, enum mCoreChecksumType type); bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID); bool (*selectBIOS)(struct mCore*, int biosID); diff --git a/src/gb/core.c b/src/gb/core.c index 6380f9ff1..a252102cd 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -211,6 +211,16 @@ static void _GBCoreUnloadROM(struct mCore* core) { return GBUnloadROM(core->board); } +static void _GBCoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) { + struct GB* gb = (struct GB*) core->board; + switch (type) { + case CHECKSUM_CRC32: + memcpy(data, &gb->romCrc32, sizeof(gb->romCrc32)); + break; + } + return; +} + static void _GBCoreReset(struct mCore* core) { struct GBCore* gbcore = (struct GBCore*) core; struct GB* gb = (struct GB*) core->board; @@ -543,6 +553,7 @@ struct mCore* GBCoreCreate(void) { core->loadTemporarySave = _GBCoreLoadTemporarySave; core->loadPatch = _GBCoreLoadPatch; core->unloadROM = _GBCoreUnloadROM; + core->checksum = _GBCoreChecksum; core->reset = _GBCoreReset; core->runFrame = _GBCoreRunFrame; core->runLoop = _GBCoreRunLoop; diff --git a/src/gba/core.c b/src/gba/core.c index 397cdcb7d..6d1944759 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -247,6 +247,16 @@ static void _GBACoreUnloadROM(struct mCore* core) { return GBAUnloadROM(core->board); } +static void _GBACoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) { + struct GBA* gba = (struct GBA*) core->board; + switch (type) { + case CHECKSUM_CRC32: + memcpy(data, &gba->romCrc32, sizeof(gba->romCrc32)); + break; + } + return; +} + static void _GBACoreReset(struct mCore* core) { struct GBACore* gbacore = (struct GBACore*) core; struct GBA* gba = (struct GBA*) core->board; @@ -562,6 +572,7 @@ struct mCore* GBACoreCreate(void) { core->loadTemporarySave = _GBACoreLoadTemporarySave; core->loadPatch = _GBACoreLoadPatch; core->unloadROM = _GBACoreUnloadROM; + core->checksum = _GBACoreChecksum; core->reset = _GBACoreReset; core->runFrame = _GBACoreRunFrame; core->runLoop = _GBACoreRunLoop; diff --git a/src/platform/qt/ROMInfo.cpp b/src/platform/qt/ROMInfo.cpp index f486c0ac0..d657731c0 100644 --- a/src/platform/qt/ROMInfo.cpp +++ b/src/platform/qt/ROMInfo.cpp @@ -48,12 +48,13 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) m_ui.id->setText(tr("(unknown)")); } + core->checksum(core, &crc32, CHECKSUM_CRC32); + 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")); - crc32 = gba->romCrc32; break; } #endif @@ -61,7 +62,6 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) case PLATFORM_GB: { GB* gb = static_cast(core->board); m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes")); - crc32 = gb->romCrc32; break; } #endif diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index f17afd02b..1195d9dd9 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -831,25 +831,7 @@ void Window::updateTitle(float fps) { const NoIntroDB* db = GBAApp::app()->gameDB(); NoIntroGame game{}; uint32_t crc32 = 0; - - switch (m_controller->thread()->core->platform(m_controller->thread()->core)) { - #ifdef M_CORE_GBA - case PLATFORM_GBA: { - GBA* gba = static_cast(m_controller->thread()->core->board); - crc32 = gba->romCrc32; - break; - } - #endif - #ifdef M_CORE_GB - case PLATFORM_GB: { - GB* gb = static_cast(m_controller->thread()->core->board); - crc32 = gb->romCrc32; - break; - } - #endif - default: - break; - } + m_controller->thread()->core->checksum(m_controller->thread()->core, &crc32, CHECKSUM_CRC32); char gameTitle[17] = { '\0' }; mCore* core = m_controller->thread()->core;