EXI: grab the FlashID from the memory card headers and update sram to include correct id and chksum

allows using any (valid) memorycard.raw in any slot (including real memcard dumps)

Fixes issue 684.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6576 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99 2010-12-14 01:25:50 +00:00
parent b5ba9b3479
commit 18e95ecdfa
9 changed files with 75 additions and 26 deletions

View File

@ -55,6 +55,7 @@ set(SRCS Src/ActionReplay.cpp
Src/HW/SI_Device.cpp Src/HW/SI_Device.cpp
Src/HW/SI_DeviceGBA.cpp Src/HW/SI_DeviceGBA.cpp
Src/HW/SI_DeviceGCController.cpp Src/HW/SI_DeviceGCController.cpp
Src/HW/Sram.cpp
Src/HW/StreamADPCM.cpp Src/HW/StreamADPCM.cpp
Src/HW/SystemTimers.cpp Src/HW/SystemTimers.cpp
Src/HW/VideoInterface.cpp Src/HW/VideoInterface.cpp

View File

@ -601,6 +601,10 @@
RelativePath=".\Src\HW\EXI_DeviceMic.h" RelativePath=".\Src\HW\EXI_DeviceMic.h"
> >
</File> </File>
<File
RelativePath=".\Src\HW\Sram.cpp"
>
</File>
<File <File
RelativePath=".\Src\HW\Sram.h" RelativePath=".\Src\HW\Sram.h"
> >

View File

@ -24,6 +24,8 @@
#include "../PowerPC/PowerPC.h" #include "../PowerPC/PowerPC.h"
#include "EXI.h" #include "EXI.h"
#include "sram.h"
SRAM g_SRAM;
namespace ExpansionInterface namespace ExpansionInterface
{ {
@ -36,9 +38,9 @@ enum
}; };
CEXIChannel *g_Channels[NUM_CHANNELS]; CEXIChannel *g_Channels[NUM_CHANNELS];
void Init() void Init()
{ {
initSRAM();
for (u32 i = 0; i < NUM_CHANNELS; i++) for (u32 i = 0; i < NUM_CHANNELS; i++)
g_Channels[i] = new CEXIChannel(i); g_Channels[i] = new CEXIChannel(i);

View File

@ -176,22 +176,9 @@ CEXIIPL::CEXIIPL() :
// Clear RTC // Clear RTC
memset(m_RTC, 0, sizeof(m_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 // 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); WriteProtectMemory(m_pIPL, ROM_SIZE);
m_uAddress = 0; m_uAddress = 0;
@ -214,7 +201,7 @@ CEXIIPL::~CEXIIPL()
FILE *file = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "wb"); FILE *file = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "wb");
if (file) if (file)
{ {
fwrite(&m_SRAM, 1, 64, file); fwrite(&g_SRAM, 1, 64, file);
fclose(file); fclose(file);
} }
} }
@ -357,9 +344,9 @@ void CEXIIPL::TransferByte(u8& _uByte)
else if ((m_uAddress & 0x7FFFFF00) == 0x20000100) else if ((m_uAddress & 0x7FFFFF00) == 0x20000100)
{ {
if (m_uAddress & 0x80000000) 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 else
_uByte = m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset]; _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
} }
// --- UART --- // --- UART ---
else if ((m_uAddress & 0x7FFFFF00) == 0x20010000) 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 // WII only RTC flags... afaik just the wii menu initialize it
// if (m_uAddress & 0x80000000) // 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 // else
// _uByte = m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset]; // _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
} }
m_uRWOffset++; m_uRWOffset++;
} }

View File

@ -53,9 +53,6 @@ private:
//! RealTimeClock //! RealTimeClock
u8 m_RTC[4]; u8 m_RTC[4];
//! SRam
SRAM m_SRAM;
//! Helper //! Helper
u32 m_uPosition; u32 m_uPosition;
u32 m_uAddress; u32 m_uAddress;

View File

@ -25,6 +25,7 @@
#include "EXI.h" #include "EXI.h"
#include "EXI_Device.h" #include "EXI_Device.h"
#include "EXI_DeviceMemoryCard.h" #include "EXI_DeviceMemoryCard.h"
#include "Sram.h"
#define MC_STATUS_BUSY 0x80 #define MC_STATUS_BUSY 0x80
#define MC_STATUS_UNLOCKED 0x40 #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()); INFO_LOG(EXPANSIONINTERFACE, "Reading memory card %s", m_strFilename.c_str());
fread(memory_card_content, 1, memory_card_size, pFile); fread(memory_card_content, 1, memory_card_size, pFile);
fclose(pFile); fclose(pFile);
SetCardFlashID(memory_card_content, card_index);
} }
else else
{ {

View File

@ -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;
}

View File

@ -71,10 +71,14 @@ union SRAM
u16 wirelessPad_id[4]; // 16bit device ID of last connected pad. u16 wirelessPad_id[4]; // 16bit device ID of last connected pad.
u8 dvderr_code; // last non-recoverable error from DVD interface u8 dvderr_code; // last non-recoverable error from DVD interface
u8 __padding0; // reserved u8 __padding0; // reserved
u16 flashID_chksum[2]; // 16bit checksum of unlock flash ID u8 flashID_chksum[2]; // 8bit checksum of unlock flash ID
u16 __padding1; // padding u32 __padding1; // padding
}; };
}; };
#pragma pack(pop) #pragma pack(pop)
void initSRAM();
void SetCardFlashID(u8* buffer, u8 card_index);
extern SRAM sram_dump; extern SRAM sram_dump;
extern SRAM g_SRAM;
#endif #endif

View File

@ -72,6 +72,7 @@ files = [
"HW/SI_DeviceAMBaseboard.cpp", "HW/SI_DeviceAMBaseboard.cpp",
"HW/SI_DeviceGBA.cpp", "HW/SI_DeviceGBA.cpp",
"HW/SI_DeviceGCController.cpp", "HW/SI_DeviceGCController.cpp",
"HW/Sram.cpp",
"HW/StreamADPCM.cpp", "HW/StreamADPCM.cpp",
"HW/SystemTimers.cpp", "HW/SystemTimers.cpp",
"HW/VideoInterface.cpp", "HW/VideoInterface.cpp",