Permalink
Browse files

mx sram: fix checksum calc; use Common::BigEndianValue for rtc field.

  • Loading branch information...
shuffle2 committed Oct 1, 2018
1 parent cd29cdb commit 2cd96aa5bbcf5a13381acf9b22ef08ca090deff6
Showing with 12 additions and 10 deletions.
  1. +2 −3 Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp
  2. +6 −4 Source/Core/Core/HW/Sram.cpp
  3. +4 −3 Source/Core/Core/HW/Sram.h
@@ -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
@@ -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<u16*>(&g_SRAM.settings.rtc_bias);
p != reinterpret_cast<u16*>(&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;
}
@@ -36,6 +36,7 @@ distribution.
#include <array>
#include "Common/CommonTypes.h"
#include "Common/Swap.h"
using CardFlashId = std::array<u8, 12>;
@@ -79,8 +80,8 @@ struct SramFlags
struct SramSettings
{
// checksum covers [rtc_bias, flags]
u16 checksum;
u16 checksum_inv;
Common::BigEndianValue<u16> checksum;
Common::BigEndianValue<u16> checksum_inv;
// Unknown attributes
u32 ead0;
@@ -119,7 +120,7 @@ union Sram
u8 raw[0x44];
struct
{
u8 rtc[4];
Common::BigEndianValue<u32> rtc;
SramSettings settings;
SramSettingsEx settings_ex;
};

0 comments on commit 2cd96aa

Please sign in to comment.