From 78903884e50d1b11e74224087c5c51c554c1909a Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 8 Jun 2015 01:08:29 +0200 Subject: [PATCH 1/2] GameCube SRAM: Recalculate checksums after setting language. This fixes a minor bug where the IPL thinks the SRAM has been corrupted and forces you to re-set date/time and settings when you change language in Config -> GameCube while not skipping the IPL on boot. --- Source/Core/Core/HW/EXI_DeviceIPL.cpp | 1 + Source/Core/Core/HW/Sram.cpp | 13 +++++++++++++ Source/Core/Core/HW/Sram.h | 1 + 3 files changed, 15 insertions(+) diff --git a/Source/Core/Core/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI_DeviceIPL.cpp index 1a15b7de2a..fe6e00ccba 100644 --- a/Source/Core/Core/HW/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI_DeviceIPL.cpp @@ -116,6 +116,7 @@ CEXIIPL::CEXIIPL() : // We Overwrite language selection here since it's possible on the GC to change the language as you please g_SRAM.lang = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage; + FixSRAMChecksums(); WriteProtectMemory(m_pIPL, ROM_SIZE); m_uAddress = 0; diff --git a/Source/Core/Core/HW/Sram.cpp b/Source/Core/Core/HW/Sram.cpp index 7290819f5c..4cfb1d0282 100644 --- a/Source/Core/Core/HW/Sram.cpp +++ b/Source/Core/Core/HW/Sram.cpp @@ -89,3 +89,16 @@ void SetCardFlashID(u8* buffer, u8 card_index) g_SRAM.flashID_chksum[card_index] = csum^0xFF; } +void FixSRAMChecksums() +{ + u16 checksum = 0; + u16 checksum_inv = 0; + for (int i = 0x0C; i < 0x14; i += 2) + { + int value = (g_SRAM.p_SRAM[i] << 8) + g_SRAM.p_SRAM[i+1]; + checksum += value; + checksum_inv += value ^ 0xFFFF; + } + g_SRAM.checksum = Common::swap16(checksum); + g_SRAM.checksum_inv = Common::swap16(checksum_inv); +} diff --git a/Source/Core/Core/HW/Sram.h b/Source/Core/Core/HW/Sram.h index b2bb6e96ff..e0f8d68f94 100644 --- a/Source/Core/Core/HW/Sram.h +++ b/Source/Core/Core/HW/Sram.h @@ -66,6 +66,7 @@ union SRAM #pragma pack(pop) void InitSRAM(); void SetCardFlashID(u8* buffer, u8 card_index); +void FixSRAMChecksums(); extern SRAM sram_dump; extern SRAM g_SRAM; From 63064aeaaae13dcee1a943d371323cd80975548e Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 8 Jun 2015 02:03:16 +0200 Subject: [PATCH 2/2] GameCube SRAM: Add a struct for the "flags" parameter. --- Source/Core/Core/HW/Sram.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/Sram.h b/Source/Core/Core/HW/Sram.h index e0f8d68f94..d8328d4884 100644 --- a/Source/Core/Core/HW/Sram.h +++ b/Source/Core/Core/HW/Sram.h @@ -38,6 +38,20 @@ distribution. #include "Common/CommonTypes.h" #pragma pack(push,1) +union SRAMFlags +{ + u8 Hex; + struct + { + u8 : 2; + u8 sound : 1; // Audio settings; 0 = Mono, 1 = Stereo + u8 initialized : 1; // if 0, displays prompt to set language on boot and asks user to set options and time/date + u8 : 2; + u8 boot_menu : 1; // if 1, skips logo animation and boots into the system menu regardless of if there is a disc inserted + u8 progressive : 1; // if 1, automatically displays Progressive Scan prompt in games that support it + }; +}; + union SRAM { u8 p_SRAM[64]; @@ -51,7 +65,7 @@ union SRAM s8 display_offsetH; // Pixel offset for the VI u8 ntd; // Unknown attribute u8 lang; // Language of system - u8 flags; // Device and operations flag + SRAMFlags flags; // Device and operations flag // Stored configuration value from the extended SRAM area u8 flash_id[2][12]; // flash_id[2][12] 96bit memorycard unlock flash ID