all repos — mgba @ 5c744a3f133da81e5d825760849b597596631f33

mGBA Game Boy Advance Emulator

Qt: Fix saving overrides
Jeffrey Pfau jeffrey@endrift.com
Tue, 20 Sep 2016 16:33:56 -0700
commit

5c744a3f133da81e5d825760849b597596631f33

parent

bea6235c0a7a0c99362564eeda357d7109886211

M CHANGESCHANGES

@@ -4,6 +4,7 @@ - GB MBC: Fix MBC7 when size is incorrectly specified

- GB Video: Setting LYC=LY during mode 2 should trigger an IRQ - GBA Cheats: Fix holding onto pointers that may get invalidated - Qt: Fix "close" button on Overrides view + - Qt: Fix saving overrides Misc: - All: Only update version info if needed
M src/platform/qt/GBAOverride.cppsrc/platform/qt/GBAOverride.cpp

@@ -18,6 +18,15 @@ }

GBAOverrideApply(static_cast<GBA*>(core->board), &override); } +void GBAOverride::identify(const struct mCore* core) { + if (core->platform(core) != PLATFORM_GBA) { + return; + } + char gameId[8]; + core->getGameCode(core, gameId); + memcpy(override.id, &gameId[4], 4); +} + void GBAOverride::save(struct Configuration* config) const { GBAOverrideSave(config, &override); }
M src/platform/qt/GBAOverride.hsrc/platform/qt/GBAOverride.h

@@ -17,6 +17,7 @@

class GBAOverride : public Override { public: void apply(struct mCore*) override; + void identify(const struct mCore*) override; void save(struct Configuration*) const override; struct GBACartridgeOverride override;
M src/platform/qt/GBOverride.cppsrc/platform/qt/GBOverride.cpp

@@ -7,6 +7,8 @@ #include "GBOverride.h"

extern "C" { #include "core/core.h" +#include "gb/gb.h" +#include "util/crc32.h" } using namespace QGBA;

@@ -16,6 +18,17 @@ if (core->platform(core) != PLATFORM_GB) {

return; } GBOverrideApply(static_cast<GB*>(core->board), &override); +} + +void GBOverride::identify(const struct mCore* core) { + if (core->platform(core) != PLATFORM_GB) { + return; + } + GB* gb = static_cast<GB*>(core->board); + if (!gb->memory.rom || gb->memory.romSize < sizeof(struct GBCartridge) + 0x100) { + return; + } + override.headerCrc32 = doCrc32(&gb->memory.rom[0x100], sizeof(struct GBCartridge)); } void GBOverride::save(struct Configuration* config) const {
M src/platform/qt/GBOverride.hsrc/platform/qt/GBOverride.h

@@ -17,6 +17,7 @@

class GBOverride : public Override { public: void apply(struct mCore*) override; + void identify(const struct mCore*) override; void save(struct Configuration*) const override; struct GBCartridgeOverride override;
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -284,6 +284,15 @@ m_multiplayer->detachGame(this);

m_multiplayer = nullptr; } +void GameController::setOverride(Override* override) { + m_override = override; + if (isLoaded()) { + threadInterrupt(); + m_override->identify(m_threadContext.core); + threadContinue(); + } +} + void GameController::clearOverride() { delete m_override; m_override = nullptr;

@@ -437,6 +446,7 @@ }

m_vf = nullptr; if (m_override) { + m_override->identify(m_threadContext.core); m_override->apply(m_threadContext.core); }
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -72,7 +72,7 @@ void setMultiplayerController(MultiplayerController* controller);

MultiplayerController* multiplayerController() { return m_multiplayer; } void clearMultiplayerController(); - void setOverride(Override* override) { m_override = override; } + void setOverride(Override* override); Override* override() { return m_override; } void clearOverride();
M src/platform/qt/Override.hsrc/platform/qt/Override.h

@@ -16,6 +16,7 @@ public:

virtual ~Override() {} virtual void apply(struct mCore*) = 0; + virtual void identify(const struct mCore*) = 0; virtual void save(struct Configuration*) const = 0; };