diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt
index b5d25cc661..c7bfefe433 100644
--- a/Source/Core/Core/CMakeLists.txt
+++ b/Source/Core/Core/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SRCS Src/ActionReplay.cpp
Src/HW/SI_Device.cpp
Src/HW/SI_DeviceGBA.cpp
Src/HW/SI_DeviceGCController.cpp
+ Src/HW/Sram.cpp
Src/HW/StreamADPCM.cpp
Src/HW/SystemTimers.cpp
Src/HW/VideoInterface.cpp
diff --git a/Source/Core/Core/Core.vcproj b/Source/Core/Core/Core.vcproj
index 779540b73a..1cc020a70f 100644
--- a/Source/Core/Core/Core.vcproj
+++ b/Source/Core/Core/Core.vcproj
@@ -601,6 +601,10 @@
RelativePath=".\Src\HW\EXI_DeviceMic.h"
>
+
+
diff --git a/Source/Core/Core/Src/HW/EXI.cpp b/Source/Core/Core/Src/HW/EXI.cpp
index 44a1200146..ae0e936e69 100644
--- a/Source/Core/Core/Src/HW/EXI.cpp
+++ b/Source/Core/Core/Src/HW/EXI.cpp
@@ -24,6 +24,8 @@
#include "../PowerPC/PowerPC.h"
#include "EXI.h"
+#include "sram.h"
+SRAM g_SRAM;
namespace ExpansionInterface
{
@@ -36,9 +38,9 @@ enum
};
CEXIChannel *g_Channels[NUM_CHANNELS];
-
void Init()
{
+ initSRAM();
for (u32 i = 0; i < NUM_CHANNELS; i++)
g_Channels[i] = new CEXIChannel(i);
diff --git a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp
index c7e432aaf2..c95895d37d 100644
--- a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp
+++ b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp
@@ -176,22 +176,9 @@ CEXIIPL::CEXIIPL() :
// Clear RTC
memset(m_RTC, 0, sizeof(m_RTC));
- // SRAM
- FILE *file = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "rb");
- if (file != NULL)
- {
- if (fread(&m_SRAM, 1, 64, file) < 64) {
- ERROR_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: Could not read all of SRAM");
- m_SRAM = sram_dump;
- }
- fclose(file);
- }
- else
- {
- m_SRAM = sram_dump;
- }
+
// We Overwrite language selection here since it's possible on the GC to change the language as you please
- m_SRAM.lang = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage;
+ g_SRAM.lang = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage;
WriteProtectMemory(m_pIPL, ROM_SIZE);
m_uAddress = 0;
@@ -214,7 +201,7 @@ CEXIIPL::~CEXIIPL()
FILE *file = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "wb");
if (file)
{
- fwrite(&m_SRAM, 1, 64, file);
+ fwrite(&g_SRAM, 1, 64, file);
fclose(file);
}
}
@@ -357,9 +344,9 @@ void CEXIIPL::TransferByte(u8& _uByte)
else if ((m_uAddress & 0x7FFFFF00) == 0x20000100)
{
if (m_uAddress & 0x80000000)
- m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte;
+ g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte;
else
- _uByte = m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
+ _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
}
// --- UART ---
else if ((m_uAddress & 0x7FFFFF00) == 0x20010000)
@@ -393,9 +380,9 @@ void CEXIIPL::TransferByte(u8& _uByte)
{
// WII only RTC flags... afaik just the wii menu initialize it
// if (m_uAddress & 0x80000000)
-// m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte;
+// g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte;
// else
-// _uByte = m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
+// _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
}
m_uRWOffset++;
}
diff --git a/Source/Core/Core/Src/HW/EXI_DeviceIPL.h b/Source/Core/Core/Src/HW/EXI_DeviceIPL.h
index 77b26cade0..bcc04c2e8f 100644
--- a/Source/Core/Core/Src/HW/EXI_DeviceIPL.h
+++ b/Source/Core/Core/Src/HW/EXI_DeviceIPL.h
@@ -53,9 +53,6 @@ private:
//! RealTimeClock
u8 m_RTC[4];
- //! SRam
- SRAM m_SRAM;
-
//! Helper
u32 m_uPosition;
u32 m_uAddress;
diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp
index 73c0500a52..9ce534d5d1 100644
--- a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp
+++ b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp
@@ -25,6 +25,7 @@
#include "EXI.h"
#include "EXI_Device.h"
#include "EXI_DeviceMemoryCard.h"
+#include "Sram.h"
#define MC_STATUS_BUSY 0x80
#define MC_STATUS_UNLOCKED 0x40
@@ -85,6 +86,8 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
INFO_LOG(EXPANSIONINTERFACE, "Reading memory card %s", m_strFilename.c_str());
fread(memory_card_content, 1, memory_card_size, pFile);
fclose(pFile);
+ SetCardFlashID(memory_card_content, card_index);
+
}
else
{
diff --git a/Source/Core/Core/Src/HW/Sram.cpp b/Source/Core/Core/Src/HW/Sram.cpp
new file mode 100644
index 0000000000..244b10d7cf
--- /dev/null
+++ b/Source/Core/Core/Src/HW/Sram.cpp
@@ -0,0 +1,50 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
+
+#include "Sram.h"
+#include "../ConfigManager.h"
+
+void initSRAM()
+{
+ FILE *file = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "rb");
+ if (file != NULL)
+ {
+ if (fread(&g_SRAM, 1, 64, file) < 64) {
+ ERROR_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: Could not read all of SRAM");
+ g_SRAM = sram_dump;
+ }
+ fclose(file);
+ }
+ else
+ {
+ g_SRAM = sram_dump;
+ }
+}
+
+void SetCardFlashID(u8* buffer, u8 card_index)
+{
+ u64 rand = Common::swap64( *(u64*)&(buffer[12]));
+ u8 csum=0;
+ for(int i = 0; i < 12; i++)
+ {
+ rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16);
+ csum += g_SRAM.flash_id[card_index][i] = buffer[i] -(u8)rand&0xff;
+ rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16);
+ rand &= (u64)0x0000000000007fffULL;
+ }
+ g_SRAM.flashID_chksum[card_index] = csum^0xFF;
+}
diff --git a/Source/Core/Core/Src/HW/Sram.h b/Source/Core/Core/Src/HW/Sram.h
index c01b319f33..51cbefabb6 100644
--- a/Source/Core/Core/Src/HW/Sram.h
+++ b/Source/Core/Core/Src/HW/Sram.h
@@ -71,10 +71,14 @@ union SRAM
u16 wirelessPad_id[4]; // 16bit device ID of last connected pad.
u8 dvderr_code; // last non-recoverable error from DVD interface
u8 __padding0; // reserved
- u16 flashID_chksum[2]; // 16bit checksum of unlock flash ID
- u16 __padding1; // padding
+ u8 flashID_chksum[2]; // 8bit checksum of unlock flash ID
+ u32 __padding1; // padding
};
};
#pragma pack(pop)
+void initSRAM();
+void SetCardFlashID(u8* buffer, u8 card_index);
+
extern SRAM sram_dump;
+extern SRAM g_SRAM;
#endif
diff --git a/Source/Core/Core/Src/SConscript b/Source/Core/Core/Src/SConscript
index 7d6f27f08f..2ca53aee65 100644
--- a/Source/Core/Core/Src/SConscript
+++ b/Source/Core/Core/Src/SConscript
@@ -72,6 +72,7 @@ files = [
"HW/SI_DeviceAMBaseboard.cpp",
"HW/SI_DeviceGBA.cpp",
"HW/SI_DeviceGCController.cpp",
+ "HW/Sram.cpp",
"HW/StreamADPCM.cpp",
"HW/SystemTimers.cpp",
"HW/VideoInterface.cpp",