From 5c744a3f133da81e5d825760849b597596631f33 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 20 Sep 2016 16:33:56 -0700 Subject: [PATCH] Qt: Fix saving overrides --- CHANGES | 1 + src/platform/qt/GBAOverride.cpp | 9 +++++++++ src/platform/qt/GBAOverride.h | 1 + src/platform/qt/GBOverride.cpp | 13 +++++++++++++ src/platform/qt/GBOverride.h | 1 + src/platform/qt/GameController.cpp | 10 ++++++++++ src/platform/qt/GameController.h | 2 +- src/platform/qt/Override.h | 1 + 8 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 4e8acd20b..3e7d01f24 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Bugfixes: - 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 diff --git a/src/platform/qt/GBAOverride.cpp b/src/platform/qt/GBAOverride.cpp index cee2e4850..1181162e2 100644 --- a/src/platform/qt/GBAOverride.cpp +++ b/src/platform/qt/GBAOverride.cpp @@ -18,6 +18,15 @@ void GBAOverride::apply(struct mCore* core) { GBAOverrideApply(static_cast(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); } diff --git a/src/platform/qt/GBAOverride.h b/src/platform/qt/GBAOverride.h index 56d018489..71d67f90d 100644 --- a/src/platform/qt/GBAOverride.h +++ b/src/platform/qt/GBAOverride.h @@ -17,6 +17,7 @@ namespace QGBA { 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; diff --git a/src/platform/qt/GBOverride.cpp b/src/platform/qt/GBOverride.cpp index 17c1c0661..d04e90082 100644 --- a/src/platform/qt/GBOverride.cpp +++ b/src/platform/qt/GBOverride.cpp @@ -7,6 +7,8 @@ extern "C" { #include "core/core.h" +#include "gb/gb.h" +#include "util/crc32.h" } using namespace QGBA; @@ -18,6 +20,17 @@ void GBOverride::apply(struct mCore* core) { GBOverrideApply(static_cast(core->board), &override); } +void GBOverride::identify(const struct mCore* core) { + if (core->platform(core) != PLATFORM_GB) { + return; + } + GB* gb = static_cast(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 { GBOverrideSave(config, &override); } diff --git a/src/platform/qt/GBOverride.h b/src/platform/qt/GBOverride.h index 67a50a001..5fb7c057d 100644 --- a/src/platform/qt/GBOverride.h +++ b/src/platform/qt/GBOverride.h @@ -17,6 +17,7 @@ namespace QGBA { 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; diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 8af14813f..2a76c0c8f 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -284,6 +284,15 @@ void GameController::clearMultiplayerController() { 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 @@ void GameController::openGame(bool biosOnly) { m_vf = nullptr; if (m_override) { + m_override->identify(m_threadContext.core); m_override->apply(m_threadContext.core); } diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index bf1e6d840..721e2809d 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -72,7 +72,7 @@ public: 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(); diff --git a/src/platform/qt/Override.h b/src/platform/qt/Override.h index 1907a62b8..a7bdacce3 100644 --- a/src/platform/qt/Override.h +++ b/src/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; };