Core: Add Pif Ram Handler
This commit is contained in:
parent
653e15a296
commit
e9d2b9793f
|
@ -32,7 +32,6 @@ void CLogging::Log_LW(uint32_t PC, uint32_t VAddr)
|
|||
VAddr = PAddr + 0xA0000000;
|
||||
}
|
||||
|
||||
uint32_t Value;
|
||||
if ((VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) ||
|
||||
(VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) ||
|
||||
(VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC) ||
|
||||
|
@ -42,21 +41,11 @@ void CLogging::Log_LW(uint32_t PC, uint32_t VAddr)
|
|||
(VAddr >= 0xA4400000 && VAddr <= 0xA4400034) ||
|
||||
(VAddr >= 0xA4500000 && VAddr <= 0xA4500014) ||
|
||||
(VAddr == 0xA4800000 && VAddr <= 0xA4800018) ||
|
||||
(VAddr >= 0xBFC00000 && VAddr <= 0xBFC007C0) ||
|
||||
(VAddr >= 0xB0000000 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize())))
|
||||
(VAddr >= 0xB0000000 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize())) ||
|
||||
(VAddr >= 0xBFC00000 && VAddr <= 0xBFC007FC))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC)
|
||||
{
|
||||
if (!LogPRDirectMemLoads())
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_MMU->LW_VAddr(VAddr, Value);
|
||||
LogMessage("%08X: read word from PIF RAM at 0x%X (%08X)", PC, VAddr - 0xBFC007C0, Value);
|
||||
return;
|
||||
}
|
||||
if (!LogUnknown())
|
||||
{
|
||||
return;
|
||||
|
@ -85,17 +74,6 @@ void CLogging::Log_SW(uint32_t PC, uint32_t VAddr, uint32_t Value)
|
|||
VAddr = PAddr + 0xA0000000;
|
||||
}
|
||||
|
||||
if ((VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) ||
|
||||
(VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) ||
|
||||
(VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC) ||
|
||||
(VAddr >= 0xA4040000 && VAddr <= 0xA404001C) ||
|
||||
(VAddr == 0xA4080000) ||
|
||||
(VAddr >= 0xA4100000 && VAddr <= 0xA410001C))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (VAddr >= 0xA4200000 && VAddr <= 0xA420000C)
|
||||
{
|
||||
if (!LogDPSRegisters())
|
||||
|
@ -111,23 +89,21 @@ void CLogging::Log_SW(uint32_t PC, uint32_t VAddr, uint32_t Value)
|
|||
}
|
||||
}
|
||||
|
||||
if ((VAddr >= 0xA4300000 && VAddr <= 0xA430000C) ||
|
||||
if ((VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) ||
|
||||
(VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) ||
|
||||
(VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC) ||
|
||||
(VAddr >= 0xA4040000 && VAddr <= 0xA404001C) ||
|
||||
(VAddr == 0xA4080000) ||
|
||||
(VAddr >= 0xA4100000 && VAddr <= 0xA410001C) ||
|
||||
(VAddr >= 0xA4300000 && VAddr <= 0xA430000C) ||
|
||||
(VAddr >= 0xA4400000 && VAddr <= 0xA4400034) ||
|
||||
(VAddr >= 0xA4500000 && VAddr <= 0xA4500014) ||
|
||||
(VAddr >= 0xA4800000 && VAddr <= 0xA4800018))
|
||||
(VAddr >= 0xA4800000 && VAddr <= 0xA4800018) ||
|
||||
(VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC)
|
||||
{
|
||||
if (!LogPRDirectMemStores())
|
||||
{
|
||||
return;
|
||||
}
|
||||
LogMessage("%08X: Writing 0x%08X to PIF RAM at 0x%X", PC, Value, VAddr - 0xBFC007C0);
|
||||
return;
|
||||
}
|
||||
if (!LogUnknown())
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -36,7 +36,7 @@ bool MIPSInterfaceHandler::Read32(uint32_t Address, uint32_t & Value)
|
|||
}
|
||||
}
|
||||
|
||||
if (LogMIPSInterface())
|
||||
if (GenerateLog() && LogMIPSInterface())
|
||||
{
|
||||
switch (Address & 0x1FFFFFFF)
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ bool MIPSInterfaceHandler::Read32(uint32_t Address, uint32_t & Value)
|
|||
|
||||
bool MIPSInterfaceHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask)
|
||||
{
|
||||
if (LogMIPSInterface())
|
||||
if (GenerateLog() && LogMIPSInterface())
|
||||
{
|
||||
switch (Address & 0x1FFFFFFF)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#include "stdafx.h"
|
||||
#include "PifRamHandler.h"
|
||||
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
|
||||
#include <Project64-core\N64System\SystemGlobals.h>
|
||||
|
||||
PifRamHandler::PifRamHandler(CMipsMemoryVM & MMU, CRegisters & Reg) :
|
||||
m_MMU(MMU),
|
||||
m_PifRam(MMU.PifRam()),
|
||||
m_PC(Reg.m_PROGRAM_COUNTER)
|
||||
{
|
||||
}
|
||||
|
||||
bool PifRamHandler::Read32(uint32_t Address, uint32_t & Value)
|
||||
{
|
||||
Address &= 0x1FFFFFFF;
|
||||
if (Address < 0x1FC007C0)
|
||||
{
|
||||
//Value = swap32by8(*(uint32_t *)(&PifRom[PAddr - 0x1FC00000]));
|
||||
Value = 0;
|
||||
if (HaveDebugger())
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
else if (Address < 0x1FC00800)
|
||||
{
|
||||
Value = *(uint32_t *)(&m_PifRam[Address - 0x1FC007C0]);
|
||||
Value = swap32by8(Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = 0;
|
||||
if (HaveDebugger())
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
if (GenerateLog() && LogPRDirectMemLoads() && Address >= 0x1FC007C0 && Address <= 0x1FC007FC)
|
||||
{
|
||||
LogMessage("%08X: read word from PIF RAM at 0x%X (%08X)", m_PC, Address - 0x1FC007C0, Value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PifRamHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask)
|
||||
{
|
||||
Address &= 0x1FFFFFFF;
|
||||
if (GenerateLog() && LogPRDirectMemStores() && Address >= 0x1FC007C0 && Address <= 0x1FC007FC)
|
||||
{
|
||||
LogMessage("%08X: Writing 0x%08X to PIF RAM at 0x%X", m_PC, Value, Address - 0x1FC007C0);
|
||||
}
|
||||
|
||||
if (Address < 0x1FC007C0)
|
||||
{
|
||||
if (HaveDebugger())
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
else if (Address < 0x1FC00800)
|
||||
{
|
||||
uint32_t SwappedMask = swap32by8(Mask);
|
||||
Value = ((*(uint32_t *)(&m_PifRam[Address - 0x1FC007C0])) & ~SwappedMask) | (Value & SwappedMask);
|
||||
*(uint32_t *)(&m_PifRam[Address - 0x1FC007C0]) = Value;
|
||||
if (Address == 0x1FC007FC)
|
||||
{
|
||||
m_MMU.PifRamWrite();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t PifRamHandler::swap32by8(uint32_t word)
|
||||
{
|
||||
const uint32_t swapped =
|
||||
#if defined(_MSC_VER)
|
||||
_byteswap_ulong(word)
|
||||
#elif defined(__GNUC__)
|
||||
__builtin_bswap32(word)
|
||||
#else
|
||||
(word & 0x000000FFul) << 24
|
||||
| (word & 0x0000FF00ul) << 8
|
||||
| (word & 0x00FF0000ul) >> 8
|
||||
| (word & 0xFF000000ul) >> 24
|
||||
#endif
|
||||
;
|
||||
return (swapped & 0xFFFFFFFFul);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include "MemoryHandler.h"
|
||||
#include <Project64-core\Settings\DebugSettings.h>
|
||||
#include <Project64-core\Logging.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class CMipsMemoryVM;
|
||||
class CRegisters;
|
||||
|
||||
class PifRamHandler :
|
||||
public MemoryHandler,
|
||||
private CDebugSettings,
|
||||
private CLogging
|
||||
{
|
||||
public:
|
||||
PifRamHandler(CMipsMemoryVM & MMU, CRegisters & Reg);
|
||||
bool Read32(uint32_t Address, uint32_t & Value);
|
||||
bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask);
|
||||
|
||||
private:
|
||||
PifRamHandler();
|
||||
PifRamHandler(const PifRamHandler &);
|
||||
PifRamHandler & operator=(const PifRamHandler &);
|
||||
|
||||
static uint32_t swap32by8(uint32_t word);
|
||||
|
||||
CMipsMemoryVM & m_MMU;
|
||||
uint8_t * m_PifRam;
|
||||
uint32_t & m_PC;
|
||||
};
|
|
@ -8,9 +8,8 @@
|
|||
#include <Project64-core\N64System\Mips\OpcodeName.h>
|
||||
#include <Project64-core\N64System\Mips\Disk.h>
|
||||
#include <Project64-core\ExceptionHandler.h>
|
||||
|
||||
#include <Common\MemoryManagement.h>
|
||||
#include <stdio.h>
|
||||
#include <Common/MemoryManagement.h>
|
||||
|
||||
uint8_t * CMipsMemoryVM::m_Reserve1 = nullptr;
|
||||
uint8_t * CMipsMemoryVM::m_Reserve2 = nullptr;
|
||||
|
@ -33,6 +32,7 @@ CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) :
|
|||
m_DPCommandRegistersHandler(System, System.GetPlugins(), System.m_Reg),
|
||||
m_MIPSInterfaceHandler(System.m_Reg),
|
||||
m_PeripheralInterfaceHandler(*this, System.m_Reg),
|
||||
m_PifRamHandler(*this, System.m_Reg),
|
||||
m_RDRAMInterfaceHandler(System.m_Reg),
|
||||
m_RomMemoryHandler(System, System.m_Reg, *g_Rom),
|
||||
m_SerialInterfaceHandler(*this, System.m_Reg),
|
||||
|
@ -52,23 +52,6 @@ CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) :
|
|||
g_Settings->RegisterChangeCB(Game_RDRamSize, this, (CSettings::SettingChangedFunc)RdramChanged);
|
||||
}
|
||||
|
||||
uint32_t swap32by8(uint32_t word)
|
||||
{
|
||||
const uint32_t swapped =
|
||||
#if defined(_MSC_VER)
|
||||
_byteswap_ulong(word)
|
||||
#elif defined(__GNUC__)
|
||||
__builtin_bswap32(word)
|
||||
#else
|
||||
(word & 0x000000FFul) << 24
|
||||
| (word & 0x0000FF00ul) << 8
|
||||
| (word & 0x00FF0000ul) >> 8
|
||||
| (word & 0xFF000000ul) >> 24
|
||||
#endif
|
||||
;
|
||||
return (swapped & 0xFFFFFFFFul);
|
||||
}
|
||||
|
||||
CMipsMemoryVM::~CMipsMemoryVM()
|
||||
{
|
||||
g_Settings->UnregisterChangeCB(Game_RDRamSize, this, (CSettings::SettingChangedFunc)RdramChanged);
|
||||
|
@ -561,7 +544,7 @@ bool CMipsMemoryVM::LW_NonMemory(uint32_t PAddr, uint32_t* Value)
|
|||
case 0x05000000: m_CartridgeDomain2Address1Handler.Read32(PAddr, m_MemLookupValue.UW[0]); break;
|
||||
case 0x06000000: Load32CartridgeDomain1Address1(); break;
|
||||
case 0x08000000: Load32CartridgeDomain2Address2(); break;
|
||||
case 0x1FC00000: Load32PifRam(); break;
|
||||
case 0x1FC00000: m_PifRamHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break;
|
||||
case 0x1FF00000: Load32CartridgeDomain1Address3(); break;
|
||||
default:
|
||||
if (PAddr >= 0x10000000 && PAddr < 0x16000000)
|
||||
|
@ -672,7 +655,7 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t PAddr, uint32_t Value)
|
|||
case 0x04800000: m_SerialInterfaceHandler.Write32(PAddr, Value, 0xFFFFFFFF); break;
|
||||
case 0x05000000: m_CartridgeDomain2Address1Handler.Write32(PAddr, Value, 0xFFFFFFFF); break;
|
||||
case 0x08000000: Write32CartridgeDomain2Address2(); break;
|
||||
case 0x1FC00000: Write32PifRam(); break;
|
||||
case 0x1FC00000: m_PifRamHandler.Write32(PAddr, Value, 0xFFFFFFFF); break;
|
||||
default:
|
||||
if (PAddr >= 0x10000000 && PAddr < 0x16000000)
|
||||
{
|
||||
|
@ -1045,33 +1028,6 @@ void CMipsMemoryVM::Load32CartridgeDomain2Address2(void)
|
|||
}
|
||||
}
|
||||
|
||||
void CMipsMemoryVM::Load32PifRam(void)
|
||||
{
|
||||
if ((m_MemLookupAddress & 0x1FFFFFFF) < 0x1FC007C0)
|
||||
{
|
||||
//m_MemLookupValue.UW[0] = swap32by8(*(uint32_t *)(&PifRom[PAddr - 0x1FC00000]));
|
||||
m_MemLookupValue.UW[0] = 0;
|
||||
if (HaveDebugger())
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
else if ((m_MemLookupAddress & 0x1FFFFFFF) < 0x1FC00800)
|
||||
{
|
||||
uint8_t * PIF_Ram = g_MMU->PifRam();
|
||||
m_MemLookupValue.UW[0] = *(uint32_t *)(&PIF_Ram[(m_MemLookupAddress & 0x1FFFFFFF) - 0x1FC007C0]);
|
||||
m_MemLookupValue.UW[0] = swap32by8(m_MemLookupValue.UW[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MemLookupValue.UW[0] = 0;
|
||||
if (HaveDebugger())
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMipsMemoryVM::Write32CartridgeDomain2Address2(void)
|
||||
{
|
||||
uint32_t offset = (m_MemLookupAddress & 0x1FFFFFFF) - 0x08000000;
|
||||
|
@ -1106,23 +1062,3 @@ void CMipsMemoryVM::Write32CartridgeDomain2Address2(void)
|
|||
g_MMU->WriteToFlashCommand(m_MemLookupValue.UW[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void CMipsMemoryVM::Write32PifRam(void)
|
||||
{
|
||||
if ((m_MemLookupAddress & 0x1FFFFFFF) < 0x1FC007C0)
|
||||
{
|
||||
if (HaveDebugger())
|
||||
{
|
||||
g_Notify->BreakPoint(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
else if ((m_MemLookupAddress & 0x1FFFFFFF) < 0x1FC00800)
|
||||
{
|
||||
uint32_t Value = swap32by8(m_MemLookupValue.UW[0]);
|
||||
*(uint32_t *)(&g_MMU->m_PifRam[(m_MemLookupAddress & 0x1FFFFFFF) - 0x1FC007C0]) = Value;
|
||||
if ((m_MemLookupAddress & 0x1FFFFFFF) == 0x1FC007FC)
|
||||
{
|
||||
g_MMU->PifRamWrite();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,9 +12,11 @@
|
|||
#include <Project64-core\N64System\MemoryHandler\DisplayControlRegHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\MIPSInterfaceHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\PeripheralInterfaceHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\PifRamHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\RDRAMInterfaceHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\RDRAMRegistersHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\RomMemoryHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\SerialInterfaceHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\SPRegistersHandler.h>
|
||||
#include <Project64-core\N64System\MemoryHandler\VideoInterfaceHandler.h>
|
||||
#include <Project64-core\Settings\GameSettings.h>
|
||||
|
@ -136,10 +138,8 @@ private:
|
|||
static void Load32CartridgeDomain1Address1(void);
|
||||
static void Load32CartridgeDomain1Address3(void);
|
||||
static void Load32CartridgeDomain2Address2(void);
|
||||
static void Load32PifRam(void);
|
||||
|
||||
static void Write32CartridgeDomain2Address2(void);
|
||||
static void Write32PifRam(void);
|
||||
|
||||
#if defined(__i386__) || defined(_M_IX86)
|
||||
|
||||
|
@ -171,6 +171,7 @@ private:
|
|||
DisplayControlRegHandler m_DPCommandRegistersHandler;
|
||||
MIPSInterfaceHandler m_MIPSInterfaceHandler;
|
||||
PeripheralInterfaceHandler m_PeripheralInterfaceHandler;
|
||||
PifRamHandler m_PifRamHandler;
|
||||
RomMemoryHandler m_RomMemoryHandler;
|
||||
RDRAMInterfaceHandler m_RDRAMInterfaceHandler;
|
||||
RDRAMRegistersHandler m_RDRAMRegistersHandler;
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
<ClCompile Include="N64System\MemoryHandler\DisplayControlRegHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\MIPSInterfaceHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\PeripheralInterfaceHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\PifRamHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\RDRAMInterfaceHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\RDRAMRegistersHandler.cpp" />
|
||||
<ClCompile Include="N64System\MemoryHandler\RomMemoryHandler.cpp" />
|
||||
|
@ -164,6 +165,7 @@
|
|||
<ClInclude Include="N64System\MemoryHandler\MemoryHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\MIPSInterfaceHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\PeripheralInterfaceHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\PifRamHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\RDRAMInterfaceHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\RDRAMRegistersHandler.h" />
|
||||
<ClInclude Include="N64System\MemoryHandler\RomMemoryHandler.h" />
|
||||
|
|
|
@ -387,6 +387,9 @@
|
|||
<ClCompile Include="N64System\MemoryHandler\RomMemoryHandler.cpp">
|
||||
<Filter>Source Files\N64 System\MemoryHandler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="N64System\MemoryHandler\PifRamHandler.cpp">
|
||||
<Filter>Source Files\N64 System\MemoryHandler</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
|
@ -740,6 +743,9 @@
|
|||
<ClInclude Include="N64System\MemoryHandler\RomMemoryHandler.h">
|
||||
<Filter>Header Files\N64 System\MemoryHandler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="N64System\MemoryHandler\PifRamHandler.h">
|
||||
<Filter>Header Files\N64 System\MemoryHandler</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Version.h.in">
|
||||
|
|
Loading…
Reference in New Issue