[Project64] Make the mempak belong to the n64 system
This commit is contained in:
parent
35c64e5d16
commit
676be8fcdc
|
@ -10,13 +10,17 @@
|
|||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
class Mempak
|
||||
class CMempak
|
||||
{
|
||||
public:
|
||||
static uint8_t CalculateCrc(uint8_t * DataToCrc);
|
||||
static void ReadFrom(int32_t Control, uint32_t address, uint8_t * data);
|
||||
static void WriteTo(int32_t Control, uint32_t address, uint8_t * data);
|
||||
void ReadFrom(int32_t Control, uint32_t address, uint8_t * data);
|
||||
void WriteTo(int32_t Control, uint32_t address, uint8_t * data);
|
||||
|
||||
private:
|
||||
static void LoadMempak(int32_t Control);
|
||||
static void Format(int32_t Control);
|
||||
void LoadMempak(int32_t Control);
|
||||
void Format(int32_t Control);
|
||||
|
||||
uint8_t m_Mempaks[4][128 * 256]; /* [CONTROLLERS][PAGES][BYTES_PER_PAGE] */
|
||||
CFile m_MempakHandle[4];
|
||||
};
|
|
@ -14,10 +14,7 @@
|
|||
#include <stdio.h>
|
||||
#include <Common/path.h>
|
||||
|
||||
uint8_t Mempaks[4][128 * 256]; /* [CONTROLLERS][PAGES][BYTES_PER_PAGE] */
|
||||
CFile MempakHandle[4];
|
||||
|
||||
void Mempak::LoadMempak(int32_t Control)
|
||||
void CMempak::LoadMempak(int32_t Control)
|
||||
{
|
||||
stdstr MempakName;
|
||||
MempakName.Format("%s_Cont_%d", g_Settings->LoadStringVal(Game_GameName).c_str(), Control + 1);
|
||||
|
@ -35,21 +32,21 @@ void Mempak::LoadMempak(int32_t Control)
|
|||
|
||||
bool formatMempak = !MempakPath.Exists();
|
||||
|
||||
MempakHandle[Control].Open(MempakPath, CFileBase::modeReadWrite | CFileBase::modeNoTruncate | CFileBase::modeCreate);
|
||||
MempakHandle[Control].SeekToBegin();
|
||||
m_MempakHandle[Control].Open(MempakPath, CFileBase::modeReadWrite | CFileBase::modeNoTruncate | CFileBase::modeCreate);
|
||||
m_MempakHandle[Control].SeekToBegin();
|
||||
|
||||
if (formatMempak)
|
||||
{
|
||||
Mempak::Format(Control);
|
||||
MempakHandle[Control].Write(Mempaks[Control], 0x8000);
|
||||
CMempak::Format(Control);
|
||||
m_MempakHandle[Control].Write(m_Mempaks[Control], 0x8000);
|
||||
}
|
||||
else
|
||||
{
|
||||
MempakHandle[Control].Read(Mempaks[Control], 0x8000);
|
||||
m_MempakHandle[Control].Read(m_Mempaks[Control], 0x8000);
|
||||
}
|
||||
}
|
||||
|
||||
void Mempak::Format(int32_t Control)
|
||||
void CMempak::Format(int32_t Control)
|
||||
{
|
||||
static const uint8_t Initialize[] = {
|
||||
0x81, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
|
@ -71,16 +68,16 @@ void Mempak::Format(int32_t Control)
|
|||
0x00, 0x71, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03,
|
||||
};
|
||||
|
||||
memcpy(&Mempaks[Control][0], &Initialize[0], sizeof(Initialize));
|
||||
memcpy(&m_Mempaks[Control][0], &Initialize[0], sizeof(Initialize));
|
||||
|
||||
for (size_t count = sizeof(Initialize); count < 128 * 256; count += 2)
|
||||
{
|
||||
Mempaks[Control][count + 0] = 0x00;
|
||||
Mempaks[Control][count + 1] = 0x03;
|
||||
m_Mempaks[Control][count + 0] = 0x00;
|
||||
m_Mempaks[Control][count + 1] = 0x03;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Mempak::CalculateCrc(uint8_t * DataToCrc)
|
||||
uint8_t CMempak::CalculateCrc(uint8_t * DataToCrc)
|
||||
{
|
||||
uint32_t Count;
|
||||
uint32_t XorTap;
|
||||
|
@ -113,16 +110,16 @@ uint8_t Mempak::CalculateCrc(uint8_t * DataToCrc)
|
|||
return CRC;
|
||||
}
|
||||
|
||||
void Mempak::ReadFrom(int32_t Control, uint32_t address, uint8_t * data)
|
||||
void CMempak::ReadFrom(int32_t Control, uint32_t address, uint8_t * data)
|
||||
{
|
||||
if (address < 0x8000)
|
||||
{
|
||||
if (!MempakHandle[Control].IsOpen())
|
||||
if (!m_MempakHandle[Control].IsOpen())
|
||||
{
|
||||
LoadMempak(Control);
|
||||
}
|
||||
|
||||
memcpy(data, &Mempaks[Control][address], 0x20);
|
||||
memcpy(data, &m_Mempaks[Control][address], 0x20);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -131,19 +128,19 @@ void Mempak::ReadFrom(int32_t Control, uint32_t address, uint8_t * data)
|
|||
}
|
||||
}
|
||||
|
||||
void Mempak::WriteTo(int32_t Control, uint32_t address, uint8_t * data)
|
||||
void CMempak::WriteTo(int32_t Control, uint32_t address, uint8_t * data)
|
||||
{
|
||||
if (address < 0x8000)
|
||||
{
|
||||
if (!MempakHandle[Control].IsOpen())
|
||||
if (!m_MempakHandle[Control].IsOpen())
|
||||
{
|
||||
LoadMempak(Control);
|
||||
}
|
||||
|
||||
memcpy(&Mempaks[Control][address], data, 0x20);
|
||||
memcpy(&m_Mempaks[Control][address], data, 0x20);
|
||||
|
||||
MempakHandle[Control].Seek(address, CFile::begin);
|
||||
MempakHandle[Control].Write(data, 0x20);
|
||||
m_MempakHandle[Control].Seek(address, CFile::begin);
|
||||
m_MempakHandle[Control].Write(data, 0x20);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -476,7 +476,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
|||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
||||
}
|
||||
}
|
||||
if (Controllers[Control].Present == true)
|
||||
if (Controllers[Control].Present != 0)
|
||||
{
|
||||
Command[3] = 0x05;
|
||||
Command[4] = 0x00;
|
||||
|
@ -520,7 +520,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
|||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
||||
}
|
||||
}
|
||||
if (Controllers[Control].Present == true)
|
||||
if (Controllers[Control].Present != 0)
|
||||
{
|
||||
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
|
||||
uint8_t* data = &Command[5];
|
||||
|
@ -528,7 +528,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
|||
switch (Controllers[Control].Plugin)
|
||||
{
|
||||
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(address, data); break;
|
||||
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, address, data); break;
|
||||
case PLUGIN_MEMPAK: g_Mempak->ReadFrom(Control, address, data); break;
|
||||
case PLUGIN_TANSFER_PAK: Transferpak::ReadFrom(address, data); break;
|
||||
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
||||
default:
|
||||
|
@ -537,7 +537,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
|||
|
||||
if (Controllers[Control].Plugin != PLUGIN_RAW)
|
||||
{
|
||||
Command[0x25] = Mempak::CalculateCrc(data);
|
||||
Command[0x25] = CMempak::CalculateCrc(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -568,7 +568,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
|||
|
||||
switch (Controllers[Control].Plugin)
|
||||
{
|
||||
case PLUGIN_MEMPAK: Mempak::WriteTo(Control, address, data); break;
|
||||
case PLUGIN_MEMPAK: g_Mempak->WriteTo(Control, address, data); break;
|
||||
case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, address, data); break;
|
||||
case PLUGIN_TANSFER_PAK: Transferpak::WriteTo(address, data); break;
|
||||
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
||||
|
@ -576,7 +576,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
|||
|
||||
if (Controllers[Control].Plugin != PLUGIN_RAW)
|
||||
{
|
||||
Command[0x25] = Mempak::CalculateCrc(data);
|
||||
Command[0x25] = CMempak::CalculateCrc(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -603,7 +603,7 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
|
|||
switch (Command[2])
|
||||
{
|
||||
case 0x01: // read controller
|
||||
if (Controllers[Control].Present == true)
|
||||
if (Controllers[Control].Present != 0)
|
||||
{
|
||||
if (bShowPifRamErrors())
|
||||
{
|
||||
|
@ -615,7 +615,7 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
|
|||
}
|
||||
break;
|
||||
case 0x02: //read from controller pack
|
||||
if (Controllers[Control].Present == true)
|
||||
if (Controllers[Control].Present != 0)
|
||||
{
|
||||
switch (Controllers[Control].Plugin)
|
||||
{
|
||||
|
@ -624,7 +624,7 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
|
|||
}
|
||||
break;
|
||||
case 0x03: //write controller pak
|
||||
if (Controllers[Control].Present == true)
|
||||
if (Controllers[Control].Present != 0)
|
||||
{
|
||||
switch (Controllers[Control].Plugin)
|
||||
{
|
||||
|
|
|
@ -697,6 +697,7 @@ bool CN64System::SetActiveSystem(bool bActive)
|
|||
g_MMU = &m_MMU_VM;
|
||||
g_TLB = &m_TLB;
|
||||
g_Reg = &m_Reg;
|
||||
g_Mempak = &m_Mempak;
|
||||
g_Audio = &m_Audio;
|
||||
g_SystemTimer = &m_SystemTimer;
|
||||
g_TransVaddr = &m_MMU_VM;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
||||
#include <Project64-core/N64System/Mips/SystemEvents.h>
|
||||
#include <Project64-core/N64System/Mips/SystemTiming.h>
|
||||
#include <Project64-core/N64System/Mips/Mempak.h>
|
||||
#include <Project64-core/Settings/DebugSettings.h>
|
||||
#include <Project64-core/Plugin.h>
|
||||
#include <Project64-core/Logging.h>
|
||||
|
@ -135,6 +136,7 @@ private:
|
|||
CMipsMemoryVM m_MMU_VM; //Memory of the n64
|
||||
CTLB m_TLB;
|
||||
CRegisters m_Reg;
|
||||
CMempak m_Mempak;
|
||||
CFramePerSecond m_FPS;
|
||||
CProfiling m_CPU_Usage; //used to track the cpu usage
|
||||
CRecompiler * m_Recomp;
|
||||
|
|
|
@ -31,5 +31,6 @@ uint32_t * g_TLBLoadAddress = NULL;
|
|||
uint32_t * g_TLBStoreAddress = NULL;
|
||||
CDebugger * g_Debugger = NULL;
|
||||
uint8_t ** g_RecompPos = NULL;
|
||||
CMempak * g_Mempak = NULL;
|
||||
|
||||
int * g_NextTimer;
|
|
@ -60,3 +60,6 @@ __interface CDebugger;
|
|||
extern CDebugger * g_Debugger;
|
||||
|
||||
extern uint8_t ** g_RecompPos;
|
||||
|
||||
class CMempak;
|
||||
extern CMempak * g_Mempak;
|
Loading…
Reference in New Issue