mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
adds some info about the memcard header, taken from libogc
wip real format function for GCMemcard class somewhat useful memcard debug window sram header taken from libogc git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2499 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -750,6 +750,10 @@
|
||||
RelativePath=".\Src\HW\EXI_DeviceMic.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\HW\Sram.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="SI - Serial Interface"
|
||||
|
78
Source/Core/Core/Src/HW/Sram.h
Normal file
78
Source/Core/Core/Src/HW/Sram.h
Normal file
@ -0,0 +1,78 @@
|
||||
// Copyright (C) 2003-2008 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/
|
||||
|
||||
// Modified code taken from libogc
|
||||
/*-------------------------------------------------------------
|
||||
|
||||
system.h -- OS functions and initialization
|
||||
|
||||
Copyright (C) 2004
|
||||
Michael Wiedenbauer (shagkur)
|
||||
Dave Murphy (WinterMute)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you
|
||||
must not claim that you wrote the original software. If you use
|
||||
this software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
|
||||
-------------------------------------------------------------*/
|
||||
#ifndef __SRAM_h__
|
||||
#define __SRAM_h__
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
struct SRAM
|
||||
{
|
||||
struct _syssram { // Stored configuration value from the system SRAM area
|
||||
u8 checksum[2]; // holds the block checksum.
|
||||
u8 checksum_inv[2]; // holds the inverse block checksum
|
||||
u8 ead0[4]; // unknown attribute
|
||||
u8 ead1[4]; // unknown attribute
|
||||
u8 counter_bias[4]; // bias value for the realtime clock
|
||||
s8 display_offsetH; // pixel offset for the VI
|
||||
u8 ntd; // unknown attribute
|
||||
u8 lang; // language of system
|
||||
u8 flags; // device and operations flag
|
||||
}syssram;
|
||||
|
||||
struct _syssramex { // Stored configuration value from the extended SRAM area
|
||||
u8 flash_id_1[12]; // flash_id[2][12] 96bit memorycard unlock flash ID
|
||||
u8 flash_id_2[12];
|
||||
u8 wirelessKbd_id[4]; // Device ID of last connected wireless keyboard
|
||||
u8 wirelessPad_id[8]; // 16bit device ID of last connected pad.
|
||||
u8 dvderr_code; // last non-recoverable error from DVD interface
|
||||
u8 __padding0; // padding
|
||||
u8 flashID_chksum[4]; // 16bit checksum of unlock flash ID
|
||||
u8 __padding1[4]; // padding
|
||||
}syssramex;
|
||||
};
|
||||
#endif
|
@ -15,11 +15,10 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Globals.h"
|
||||
#include "MemcardManager.h"
|
||||
#include "Common.h"
|
||||
#include "wx/mstream.h"
|
||||
//#define DEBUG_MCM true
|
||||
|
||||
#define DEFAULTS wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator
|
||||
#define ARROWS slot ? _T("") : ARROW[slot], slot ? ARROW[slot] : _T("")
|
||||
|
||||
@ -119,6 +118,9 @@ CMemcardManager::CMemcardManager(wxWindow* parent, wxWindowID id, const wxString
|
||||
}
|
||||
else itemsPerPage = 16;
|
||||
maxPages = (128 / itemsPerPage) - 1;
|
||||
#ifdef DEBUG_MCM
|
||||
MemcardManagerDebug = NULL;
|
||||
#endif
|
||||
CreateGUIControls();
|
||||
}
|
||||
|
||||
@ -134,6 +136,14 @@ CMemcardManager::~CMemcardManager()
|
||||
delete memoryCard[SLOT_B];
|
||||
memoryCard[SLOT_B] = NULL;
|
||||
}
|
||||
#ifdef DEBUG_MCM
|
||||
if (MemcardManagerDebug)
|
||||
{
|
||||
MemcardManagerDebug->Destroy();
|
||||
delete MemcardManagerDebug;
|
||||
MemcardManagerDebug = NULL;
|
||||
}
|
||||
#endif
|
||||
MemcardManagerIni.Load(CONFIG_FILE);
|
||||
MemcardManagerIni.Set("MemcardManager", "Items per page", itemsPerPage);
|
||||
|
||||
@ -834,6 +844,19 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
|
||||
memoryCard[card]->GetFreeBlocks(), DIRLEN - nFiles);
|
||||
t_Status[card]->SetLabel(wxLabel);
|
||||
|
||||
|
||||
#ifdef DEBUG_MCM
|
||||
if(MemcardManagerDebug == NULL)
|
||||
{
|
||||
MemcardManagerDebug = new CMemcardManagerDebug((wxFrame *)NULL, wxDefaultPosition, wxSize(950, 400));
|
||||
|
||||
}
|
||||
if (MemcardManagerDebug != NULL)
|
||||
{
|
||||
MemcardManagerDebug->Show();
|
||||
MemcardManagerDebug->updatePanels(memoryCard, card);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef __MEMCARD_MANAGER_h__
|
||||
#define __MEMCARD_MANAGER_h__
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/filepicker.h>
|
||||
#include <wx/statbmp.h>
|
||||
@ -46,8 +47,14 @@
|
||||
#define E_SAVEFAILED "File write failed"
|
||||
#define E_UNK "Unknown error"
|
||||
#define FIRSTPAGE 0
|
||||
#define SLOT_A 0
|
||||
#define SLOT_B 1
|
||||
|
||||
#ifdef MEMCMAN
|
||||
#undef CONFIG_FILE
|
||||
#define CONFIG_FILE "./MemcardManager.ini"
|
||||
#define DEBUG_MCM
|
||||
#include "MCMdebug.h"
|
||||
#endif
|
||||
|
||||
|
||||
class CMemcardManager
|
||||
: public wxDialog
|
||||
@ -67,6 +74,9 @@ class CMemcardManager
|
||||
std::string DefaultMemcard[2],
|
||||
DefaultIOPath;
|
||||
IniFile MemcardManagerIni;
|
||||
#ifdef DEBUG_MCM
|
||||
CMemcardManagerDebug * MemcardManagerDebug;
|
||||
#endif
|
||||
|
||||
wxBoxSizer *sMain,
|
||||
*sButtons,
|
||||
|
@ -84,6 +84,7 @@ GCMemcard::GCMemcard(const char *filename)
|
||||
}
|
||||
mcdFile = mcd;
|
||||
format(true);
|
||||
//formatWIP(0,true,false);
|
||||
fclose(mcd);
|
||||
mcd = fopen(filename, "r+b");
|
||||
}
|
||||
@ -1073,7 +1074,6 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays)
|
||||
return frames;
|
||||
}
|
||||
|
||||
|
||||
bool GCMemcard::format(bool New)
|
||||
{
|
||||
u32 data_size = 0x2000 * (0x80 * 0x10 - 5);
|
||||
@ -1092,31 +1092,31 @@ bool GCMemcard::format(bool New)
|
||||
memset(&bat, 0, 0x2000);
|
||||
memset(&bat_backup, 0, 0x2000);
|
||||
memset(mc_data, 0xFF, mc_data_size);
|
||||
hdr.Unk1[0] = 0xE3;
|
||||
hdr.Unk1[1] = 0x63;
|
||||
hdr.Unk1[2] = 0x27;
|
||||
hdr.Unk1[3] = 0xC1;
|
||||
hdr.Unk1[4] = 0x6B;
|
||||
hdr.Unk1[5] = 0x11;
|
||||
hdr.Unk1[6] = 0xEC;
|
||||
hdr.Unk1[7] = 0x47;
|
||||
hdr.Unk1[8] = 0xF0;
|
||||
hdr.Unk1[9] = 0x12;
|
||||
hdr.Unk1[10] = 0x99;
|
||||
hdr.Unk1[11] = 0x13;
|
||||
hdr.serial[0] = 0xE3;
|
||||
hdr.serial[1] = 0x63;
|
||||
hdr.serial[2] = 0x27;
|
||||
hdr.serial[3] = 0xC1;
|
||||
hdr.serial[4] = 0x6B;
|
||||
hdr.serial[5] = 0x11;
|
||||
hdr.serial[6] = 0xEC;
|
||||
hdr.serial[7] = 0x47;
|
||||
hdr.serial[8] = 0xF0;
|
||||
hdr.serial[9] = 0x12;
|
||||
hdr.serial[10] = 0x99;
|
||||
hdr.serial[11] = 0x13;
|
||||
hdr.fmtTime.low = 0x5CB62800;
|
||||
hdr.fmtTime.high = 0xA665E7A3;
|
||||
hdr.SramBias[3] = 0x40;
|
||||
hdr.SramLang[0] = 0;
|
||||
hdr.SramLang[1] = 0;
|
||||
hdr.SramLang[2] = 0;
|
||||
hdr.SramLang[3] = 0;
|
||||
hdr.Unk2[0] = 0;
|
||||
hdr.Unk2[1] = 0;
|
||||
hdr.Unk2[2] = 0;
|
||||
hdr.Unk2[3] = 0;
|
||||
hdr.Unk2[4] = 0;
|
||||
hdr.Unk2[5] = 0;
|
||||
hdr.Unk2[6] = 0;
|
||||
hdr.Unk2[7] = 0x01;
|
||||
hdr.Pad1[0] = 0;
|
||||
hdr.Pad1[1] = 0;
|
||||
hdr.Unk2[3] = 0x01;
|
||||
hdr.deviceID[0] = 0;
|
||||
hdr.deviceID[1] = 0;
|
||||
hdr.Size[0] = 0;
|
||||
hdr.Size[1] = 0x80;
|
||||
hdr.Encoding[0] = 0;
|
||||
@ -1154,3 +1154,94 @@ bool GCMemcard::format(bool New)
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GCMemcard::formatWIP(int slot, bool New, bool sjis)
|
||||
{//slot = 1;
|
||||
u32 data_size = 0x2000 * (0x80 * 0x10 - 5);
|
||||
u16 size = (((data_size / 0x2000) + 5) / 0x10);
|
||||
SRAM m_SRAM;
|
||||
FILE * pStream;
|
||||
u64 time, rand;
|
||||
|
||||
if (New)
|
||||
{
|
||||
mc_data_size = data_size;
|
||||
mc_data = new u8[mc_data_size];
|
||||
}
|
||||
|
||||
pStream = fopen(GC_SRAM_FILE, "rb");
|
||||
if (pStream == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fread(&m_SRAM, 1, 64, pStream);
|
||||
fclose(pStream);
|
||||
rand = time = 0XFAB12B2D9FD80700;//0x500;//gettime();
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
PanicAlert("%2x,%2x,%4x,%4x,%4x,%x,%x,lang%x,flahs%x",BE16(m_SRAM.syssram.checksum),
|
||||
BE16(m_SRAM.syssram.checksum_inv),
|
||||
BE32(m_SRAM.syssram.ead0),
|
||||
BE32(m_SRAM.syssram.ead1),
|
||||
BE32(m_SRAM.syssram.counter_bias),
|
||||
m_SRAM.syssram.display_offsetH,
|
||||
m_SRAM.syssram.ntd,
|
||||
m_SRAM.syssram.lang,
|
||||
m_SRAM.syssram.flags);
|
||||
|
||||
PanicAlert("%4x%4x%4x,%4x%4x%4x,%4x,%4x,%4x,%x,%x,%4x,%4x",
|
||||
BE32(m_SRAM.syssramex.flash_id_1),
|
||||
BE32(&(m_SRAM.syssramex.flash_id_1[4])),
|
||||
BE32(&(m_SRAM.syssramex.flash_id_1[8])),
|
||||
BE32(m_SRAM.syssramex.flash_id_2),
|
||||
BE32(&(m_SRAM.syssramex.flash_id_2[4])),
|
||||
BE32(&(m_SRAM.syssramex.flash_id_2[8])),
|
||||
BE32(m_SRAM.syssramex.wirelessKbd_id),
|
||||
BE32(m_SRAM.syssramex.wirelessPad_id),
|
||||
BE32(&(m_SRAM.syssramex.wirelessPad_id[4])),
|
||||
m_SRAM.syssramex.dvderr_code,
|
||||
m_SRAM.syssramex.__padding0,
|
||||
BE32(m_SRAM.syssramex.flashID_chksum),
|
||||
BE32(m_SRAM.syssramex.__padding1));
|
||||
|
||||
memset(&hdr, 0xFF, 0x2000);
|
||||
u8 * flash_id = slot ? m_SRAM.syssramex.flash_id_2 : m_SRAM.syssramex.flash_id_1;
|
||||
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
|
||||
rand = (((rand*(u64)0x0000000041c64e6d)+(u64)0x0000000000003039)>>16);
|
||||
// PanicAlert("%16x",rand);
|
||||
// PanicAlert("m_SRAM.syssramex.flash_id %16x",(flash_id[i]));
|
||||
// PanicAlert("%16x",(flash_id[i]+(u32)rand));
|
||||
// PanicAlert("%16x",(flash_id+Common::swap32((u32)rand)));
|
||||
hdr.serial[i] = (flash_id[i]+(u32)rand);
|
||||
rand = (((rand*(u64)0x0000000041c64e6d)+(u64)0x0000000000003039)>>16);
|
||||
rand &= (u64)0x0000000000007fff;
|
||||
}
|
||||
hdr.fmtTime.high = (time >> 32) & 0xFFFFFFFF;
|
||||
hdr.fmtTime.low = time & 0xFFFFFFFF;
|
||||
*(u32*)&(hdr.SramBias) = *(u32*)&(m_SRAM.syssram.counter_bias);
|
||||
*(u32*)&(hdr.SramLang) = m_SRAM.syssram.lang;
|
||||
*(u32*)&(hdr.Unk2) = 0;//tmp; tmp = _viReg[55]; static vu16* const _viReg = (u16*)0xCC002000;
|
||||
*(u16*)&(hdr.deviceID) = 0;
|
||||
*(u16*)&(hdr.Size) = Common::swap16(size);
|
||||
*(u16*)&(hdr.Encoding) = Common::swap16(sjis ? 1 : 0);
|
||||
|
||||
memset(&dir, 0xFF, 0x2000);
|
||||
memset(&dir_backup, 0xFF, 0x2000);
|
||||
*(u16*)&dir.UpdateCounter = 0;
|
||||
*(u16*)&dir_backup.UpdateCounter = Common::swap16(1);
|
||||
memset(&bat, 0, 0x2000);
|
||||
memset(&bat_backup, 0, 0x2000);
|
||||
*(u16*)&bat.UpdateCounter = 0;
|
||||
*(u16*)&bat_backup.UpdateCounter = Common::swap16(1);
|
||||
*(u16*)&bat.FreeBlocks = *(u16*)&bat_backup.FreeBlocks = Common::swap16(size * 0x10 - 5);
|
||||
*(u16*)&bat.LastAllocated = *(u16*)&bat_backup.LastAllocated = Common::swap16(4);
|
||||
memset(mc_data, 0xFF, mc_data_size);
|
||||
FixChecksums();
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,17 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#pragma once
|
||||
#ifndef __GCMEMCARD_h__
|
||||
#define __GCMEMCARD_h__
|
||||
|
||||
#include "Common.h"
|
||||
#include "../../../Core/Src/HW/Sram.h"
|
||||
#include "StringUtil.h"
|
||||
#define BE32(x) ((u32((x)[0])<<24) | (u32((x)[1])<<16) | (u32((x)[2])<<8) | u32((x)[3]))
|
||||
#define BE16(x) ((u16((x)[0])<<8) | u16((x)[1]))
|
||||
#define ArrayByteSwap(a) (ByteSwap(a, a+sizeof(u8)));
|
||||
#define SLOT_A 0
|
||||
#define SLOT_B 1
|
||||
|
||||
enum
|
||||
{
|
||||
@ -53,6 +57,7 @@ enum
|
||||
class GCMemcard
|
||||
{
|
||||
private:
|
||||
friend class CMemcardManagerDebug;
|
||||
void* mcdFile;
|
||||
|
||||
u32 maxBlock;
|
||||
@ -66,11 +71,14 @@ private:
|
||||
};
|
||||
|
||||
struct Header { //Offset Size Description
|
||||
u8 Unk1[12]; //0x0000 12 ?
|
||||
// Serial in libogc
|
||||
u8 serial[12]; //0x0000 12 ?
|
||||
OSTime fmtTime; //0x000c 8 time of format (OSTime value)
|
||||
u8 SramBias[4]; //0x0014 4 sram bias at time of format
|
||||
u8 Unk2[8]; //0x0018 8 ? almost always 0 or 1
|
||||
u8 Pad1[2]; //0x0020 2 padding zeroes
|
||||
u8 SramBias[4]; //0x0014 4 sram bias at time of format
|
||||
u8 SramLang[4]; //0x0018 4 sram language
|
||||
u8 Unk2[4]; //0x001c 4 ? almost always 0
|
||||
// end Serial in libogc
|
||||
u8 deviceID[2]; //0x0020 2 0 if formated in slot A 1 if formated in slot B
|
||||
u8 Size[2]; //0x0022 2 size of memcard in Mbits
|
||||
u8 Encoding[2]; //0x0024 2 encoding (ASCII or japanese)
|
||||
u8 Unused1[468]; //0x0026 468 unused (0xff)
|
||||
@ -155,6 +163,7 @@ public:
|
||||
bool IsOpen();
|
||||
bool Save();
|
||||
bool format(bool New);
|
||||
bool formatWIP(int slot, bool New, bool sjis);
|
||||
|
||||
void calc_checksumsBE(u16 *buf, u32 num, u16 *c1, u16 *c2);
|
||||
u32 TestChecksums();
|
||||
@ -228,3 +237,5 @@ public:
|
||||
// reads the animation frames
|
||||
u32 ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user