all repos — mgba @ 22a36e0af9646f5c4456dd42d4dad039cb36d825

mGBA Game Boy Advance Emulator

Core: Add generic checksum function
Vicki Pfau vi@endrift.com
Tue, 17 Jan 2017 18:29:58 -0800
commit

22a36e0af9646f5c4456dd42d4dad039cb36d825

parent

e52001e406bd8d273ba887b2e0f5b347cc71af26

M CHANGESCHANGES

@@ -46,6 +46,7 @@ - Qt: Expose configuration directory

- 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:
M include/mgba/core/core.hinclude/mgba/core/core.h

@@ -33,6 +33,10 @@ PLATFORM_GB,

#endif }; +enum mCoreChecksumType { + CHECKSUM_CRC32, +}; + struct mRTCSource; struct mCoreConfig; struct mCoreSync;

@@ -77,6 +81,7 @@ bool (*loadROM)(struct mCore*, struct VFile* vf);

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

@@ -211,6 +211,16 @@ }

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 @@ core->loadSave = _GBCoreLoadSave;

core->loadTemporarySave = _GBCoreLoadTemporarySave; core->loadPatch = _GBCoreLoadPatch; core->unloadROM = _GBCoreUnloadROM; + core->checksum = _GBCoreChecksum; core->reset = _GBCoreReset; core->runFrame = _GBCoreRunFrame; core->runLoop = _GBCoreRunLoop;
M src/gba/core.csrc/gba/core.c

@@ -247,6 +247,16 @@ }

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 @@ core->loadSave = _GBACoreLoadSave;

core->loadTemporarySave = _GBACoreLoadTemporarySave; core->loadPatch = _GBACoreLoadPatch; core->unloadROM = _GBACoreUnloadROM; + core->checksum = _GBACoreChecksum; core->reset = _GBACoreReset; core->runFrame = _GBACoreRunFrame; core->runLoop = _GBACoreRunLoop;
M src/platform/qt/ROMInfo.cppsrc/platform/qt/ROMInfo.cpp

@@ -48,12 +48,13 @@ } else {

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<GBA*>(core->board); m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes")); - crc32 = gba->romCrc32; break; } #endif

@@ -61,7 +62,6 @@ #ifdef M_CORE_GB

case PLATFORM_GB: { GB* gb = static_cast<GB*>(core->board); m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes")); - crc32 = gb->romCrc32; break; } #endif
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -831,25 +831,7 @@ if (m_controller->isLoaded()) {

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<GBA*>(m_controller->thread()->core->board); - crc32 = gba->romCrc32; - break; - } - #endif - #ifdef M_CORE_GB - case PLATFORM_GB: { - GB* gb = static_cast<GB*>(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;