From dee394f10f2fa2c665806bcb7fe5a96c142d8de7 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 15 Apr 2015 21:05:01 -0700 Subject: [PATCH] GBA: Allow disabling checksum verification --- src/gba/sharkport.c | 18 ++++++++++-------- src/gba/sharkport.h | 2 +- src/platform/qt/GameController.cpp | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/gba/sharkport.c b/src/gba/sharkport.c index 4a6f5ded2..3c9707abc 100644 --- a/src/gba/sharkport.c +++ b/src/gba/sharkport.c @@ -10,7 +10,7 @@ static const char* const SHARKPORT_HEADER = "SharkPortSave"; -bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf) { +bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf, bool testChecksum) { union { char c[0x1C]; int32_t i; @@ -100,14 +100,16 @@ bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf) { } LOAD_32(checksum, 0, &buffer.i); - uint32_t calcChecksum = 0; - int i; - for (i = 0; i < size; ++i) { - calcChecksum += payload[i] << (calcChecksum % 24); - } + if (testChecksum) { + uint32_t calcChecksum = 0; + int i; + for (i = 0; i < size; ++i) { + calcChecksum += ((int32_t) payload[i]) << (calcChecksum % 24); + } - if (calcChecksum != checksum) { - goto cleanup; + if (calcChecksum != checksum) { + goto cleanup; + } } uint32_t copySize = size - 0x1C; diff --git a/src/gba/sharkport.h b/src/gba/sharkport.h index 1c709b209..520ec246e 100644 --- a/src/gba/sharkport.h +++ b/src/gba/sharkport.h @@ -11,7 +11,7 @@ struct GBA; struct VFile; -bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf); +bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf, bool testChecksum); bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf); #endif diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index f29382f5b..6bf69f2c9 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -306,7 +306,7 @@ void GameController::importSharkport(const QString& path) { return; } threadInterrupt(); - GBASavedataImportSharkPort(m_threadContext.gba, vf); + GBASavedataImportSharkPort(m_threadContext.gba, vf, false); threadContinue(); vf->close(vf); }