From 2cd96aa5bbcf5a13381acf9b22ef08ca090deff6 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 30 Sep 2018 17:58:37 -0700 Subject: [PATCH] mx sram: fix checksum calc; use Common::BigEndianValue for rtc field. --- Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp | 5 ++--- Source/Core/Core/HW/Sram.cpp | 10 ++++++---- Source/Core/Core/HW/Sram.h | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index cb827f5c7c..99c6e0cac4 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -127,7 +127,7 @@ CEXIIPL::CEXIIPL() } // Clear RTC - memset(g_SRAM.rtc, 0, sizeof(g_SRAM.rtc)); + g_SRAM.rtc = 0; // We Overwrite language selection here since it's possible on the GC to change the language as // you please @@ -250,8 +250,7 @@ void CEXIIPL::SetCS(int cs) void CEXIIPL::UpdateRTC() { - const u32 rtc = Common::swap32(GetEmulatedTime(GC_EPOCH)); - std::memcpy(g_SRAM.rtc, &rtc, sizeof(u32)); + g_SRAM.rtc = GetEmulatedTime(GC_EPOCH); } bool CEXIIPL::IsPresent() const diff --git a/Source/Core/Core/HW/Sram.cpp b/Source/Core/Core/HW/Sram.cpp index 155cafcfcd..cafc5e2f5c 100644 --- a/Source/Core/Core/HW/Sram.cpp +++ b/Source/Core/Core/HW/Sram.cpp @@ -78,14 +78,16 @@ void SetCardFlashID(const u8* buffer, u8 card_index) void FixSRAMChecksums() { + // 16bit big-endian additive checksum u16 checksum = 0; u16 checksum_inv = 0; for (auto p = reinterpret_cast(&g_SRAM.settings.rtc_bias); p != reinterpret_cast(&g_SRAM.settings_ex); p++) { - checksum += *p; - checksum_inv += ~*p; + u16 value = Common::FromBigEndian(*p); + checksum += value; + checksum_inv += ~value; } - g_SRAM.settings.checksum = Common::swap16(checksum); - g_SRAM.settings.checksum_inv = Common::swap16(checksum_inv); + g_SRAM.settings.checksum = checksum; + g_SRAM.settings.checksum_inv = checksum_inv; } diff --git a/Source/Core/Core/HW/Sram.h b/Source/Core/Core/HW/Sram.h index f088f8b614..ae2b156b4c 100644 --- a/Source/Core/Core/HW/Sram.h +++ b/Source/Core/Core/HW/Sram.h @@ -36,6 +36,7 @@ distribution. #include #include "Common/CommonTypes.h" +#include "Common/Swap.h" using CardFlashId = std::array; @@ -79,8 +80,8 @@ struct SramFlags struct SramSettings { // checksum covers [rtc_bias, flags] - u16 checksum; - u16 checksum_inv; + Common::BigEndianValue checksum; + Common::BigEndianValue checksum_inv; // Unknown attributes u32 ead0; @@ -119,7 +120,7 @@ union Sram u8 raw[0x44]; struct { - u8 rtc[4]; + Common::BigEndianValue rtc; SramSettings settings; SramSettingsEx settings_ex; };