diff --git a/Externals/Memcard Manager/Memcard Manager.sln b/Externals/Memcard Manager/Memcard Manager.sln
new file mode 100644
index 0000000000..37a17fe460
--- /dev/null
+++ b/Externals/Memcard Manager/Memcard Manager.sln
@@ -0,0 +1,23 @@
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemCardManager", "Memcard Manager.vcproj", "{413653C3-59A4-4E3A-ABB0-56558B323DFE}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Release|Win32 = Release|Win32
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {413653C3-59A4-4E3A-ABB0-56558B323DFE}.Release|Win32.Build.0 = Release|Win32
+ {413653C3-59A4-4E3A-ABB0-56558B323DFE}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ AMDCaProjectFile = D:\Dev\Dolphin\trunk\Source\CodeAnalyst\Dolphin.caw
+ EndGlobalSection
+ GlobalSection(DPCodeReviewSolutionGUID) = preSolution
+ DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
+ EndGlobalSection
+EndGlobal
diff --git a/Externals/Memcard Manager/Memcard Manager.vcproj b/Externals/Memcard Manager/Memcard Manager.vcproj
new file mode 100644
index 0000000000..0157afd266
--- /dev/null
+++ b/Externals/Memcard Manager/Memcard Manager.vcproj
@@ -0,0 +1,535 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Externals/Memcard Manager/src/MCMdebug.h b/Externals/Memcard Manager/src/MCMdebug.h
new file mode 100644
index 0000000000..11a6cbae2b
--- /dev/null
+++ b/Externals/Memcard Manager/src/MCMdebug.h
@@ -0,0 +1,111 @@
+// 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/
+
+#ifndef __MCM_H__
+#define __MCM_H__
+
+#include "MemcardManager.h"
+#include
+#include
+
+
+class CMemcardManagerDebug : public wxFrame
+{
+ public:
+
+ CMemcardManagerDebug(wxFrame* parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
+ virtual ~CMemcardManagerDebug(){};
+ void updatePanels(GCMemcard ** memCard,int card);
+
+ private:
+ enum
+ {
+ ID_NOTEBOOK_MAIN,
+ ID_TAB_HDR,
+ ID_TAB_DIR,
+ ID_TAB_DIR_B,
+ ID_TAB_BAT,
+ ID_TAB_BAT_B,
+ };
+
+
+
+ GCMemcard **memoryCard;
+
+ wxNotebook *m_Notebook_MCMD;
+
+ wxPanel *m_Tab_HDR,
+ *m_Tab_DIR,
+ *m_Tab_DIR_b,
+ *m_Tab_BAT,
+ *m_Tab_BAT_b;
+
+ wxBoxSizer *sMain,
+ *sDebug,
+ *sDebug2;
+
+ wxStaticText *t_HDR_ser[2],
+ *t_HDR_fmtTime[2],
+ *t_HDR_SRAMBIAS[2],
+ *t_HDR_SRAMLANG[2],
+ *t_HDR_Unk2[2],
+ *t_HDR_devID[2],
+ *t_HDR_Size[2],
+ *t_HDR_Encoding[2],
+ *t_HDR_UpdateCounter[2],
+ *t_HDR_CheckSum1[2],
+ *t_HDR_CheckSum2[2],
+
+ *t_DIR_UpdateCounter[2],
+ *t_DIR_CheckSum1[2],
+ *t_DIR_CheckSum2[2],
+
+ *t_DIR_b_UpdateCounter[2],
+ *t_DIR_b_CheckSum1[2],
+ *t_DIR_b_CheckSum2[2],
+
+ *t_BAT_CheckSum1[2],
+ *t_BAT_CheckSum2[2],
+ *t_BAT_UpdateCounter[2],
+ *t_BAT_FreeBlocks[2],
+ *t_BAT_LastAllocated[2],
+ *t_BAT_map[256][2],
+
+ *t_BAT_b_CheckSum1[2],
+ *t_BAT_b_CheckSum2[2],
+ *t_BAT_b_UpdateCounter[2],
+ *t_BAT_b_FreeBlocks[2],
+ *t_BAT_b_LastAllocated[2];
+
+ DECLARE_EVENT_TABLE();
+ void Init_ChildControls();
+ void OnClose(wxCloseEvent& event);
+
+ void Init_HDR();
+ void Init_DIR();
+ void Init_DIR_b();
+ void Init_BAT();
+ void Init_BAT_b();
+ void updateHDRtab(int card);
+ void updateDIRtab(int card);
+ void updateDIRBtab(int card);
+ void updateBATtab(int card);
+ void updateBATBtab(int card);
+
+};
+
+#endif
diff --git a/Externals/Memcard Manager/src/mcmMain.cpp b/Externals/Memcard Manager/src/mcmMain.cpp
new file mode 100644
index 0000000000..bf99273e8c
--- /dev/null
+++ b/Externals/Memcard Manager/src/mcmMain.cpp
@@ -0,0 +1,56 @@
+// 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/
+
+void __Log(int logNumber, const char* text, ...){logNumber; text;}
+void __Logv(int log, int v, const char *format, ...){log; v; format;}
+
+#include "MemcardManager.h"
+class MCMApp
+ : public wxApp
+{
+ public:
+ bool OnInit();
+
+};
+
+IMPLEMENT_APP(MCMApp)
+
+CMemcardManager *main_frame;
+
+#if defined HAVE_WX && HAVE_WX
+bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int Style)
+{
+ return wxYES == wxMessageBox(wxString::FromAscii(text),
+ wxString::FromAscii(caption),
+ (yes_no)?wxYES_NO:wxOK);
+}
+#endif
+
+bool MCMApp::OnInit()
+{
+ // Register message box handler
+ #if defined(HAVE_WX) && HAVE_WX
+ RegisterMsgAlertHandler(&wxMsgAlert);
+ #endif
+
+ main_frame = new CMemcardManager((wxFrame*) NULL, wxID_ANY, wxString::FromAscii("Memcard Manager"),
+ wxPoint(100, 100), wxSize(800, 600));
+ main_frame->Show();
+ SetTopWindow(main_frame);
+ return true;
+}
+
diff --git a/Source/Core/Core/Core.vcproj b/Source/Core/Core/Core.vcproj
index f6f387087f..f4bcec8d88 100644
--- a/Source/Core/Core/Core.vcproj
+++ b/Source/Core/Core/Core.vcproj
@@ -750,6 +750,10 @@
RelativePath=".\Src\HW\EXI_DeviceMic.h"
>
+
+
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;
}
diff --git a/Source/Core/DolphinWX/Src/MemcardManager.h b/Source/Core/DolphinWX/Src/MemcardManager.h
index d5672a21c9..ec67a895d9 100644
--- a/Source/Core/DolphinWX/Src/MemcardManager.h
+++ b/Source/Core/DolphinWX/Src/MemcardManager.h
@@ -18,6 +18,7 @@
#ifndef __MEMCARD_MANAGER_h__
#define __MEMCARD_MANAGER_h__
+#include
#include
#include
#include
@@ -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,
diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp
index d8c216867b..3be64ad090 100644
--- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp
+++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp
@@ -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;
+}
+
diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h
index 2345822de4..c0289fb89b 100644
--- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h
+++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h
@@ -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
+