Randomize PI and SI DMA timing
This should help with randomization while FAT is on.
This commit is contained in:
parent
b5c8a0f4c5
commit
23c1007aa0
|
@ -0,0 +1,48 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* *
|
||||||
|
* Project64 - A Nintendo 64 emulator. *
|
||||||
|
* http://www.pj64-emu.com/ *
|
||||||
|
* Copyright (C) 2017 Project64. All rights reserved. *
|
||||||
|
* *
|
||||||
|
* License: *
|
||||||
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
/*
|
||||||
|
* Implements the CRandom class.
|
||||||
|
*
|
||||||
|
* This class implements the Lehmer Random Number Generator.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Random.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
CRandom::CRandom()
|
||||||
|
{
|
||||||
|
state = (uint32_t)time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
CRandom::CRandom(uint32_t seed_value)
|
||||||
|
{
|
||||||
|
state = seed_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t randomizer(uint32_t val)
|
||||||
|
{
|
||||||
|
return ((uint64_t)val * 279470273UL) % 4294967291UL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t CRandom::next()
|
||||||
|
{
|
||||||
|
state = randomizer(state);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRandom::seed(uint32_t seed_value)
|
||||||
|
{
|
||||||
|
if (seed_value == 0)
|
||||||
|
state == 1;
|
||||||
|
else
|
||||||
|
state = seed_value;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* *
|
||||||
|
* Project64 - A Nintendo 64 emulator. *
|
||||||
|
* http://www.pj64-emu.com/ *
|
||||||
|
* Copyright (C) 2017 Project64. All rights reserved. *
|
||||||
|
* *
|
||||||
|
* License: *
|
||||||
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
/*
|
||||||
|
* Defines the CRandom class.
|
||||||
|
*
|
||||||
|
* This class implements the Lehmer Random Number Generator.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Common/stdtypes.h>
|
||||||
|
|
||||||
|
class CRandom
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CRandom();
|
||||||
|
CRandom(uint32_t seed_value);
|
||||||
|
uint32_t next();
|
||||||
|
void seed(uint32_t seed_value);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint32_t randomizer(uint32_t val);
|
||||||
|
uint32_t state;
|
||||||
|
};
|
|
@ -458,9 +458,11 @@ void CDMA::PI_DMA_WRITE()
|
||||||
{
|
{
|
||||||
g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA);
|
g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA);
|
||||||
}
|
}
|
||||||
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
|
g_SystemTimer->SetTimer(g_SystemTimer->PiTimer, PI_WR_LEN_REG/8 + (g_Random->next() % 0x40), false);
|
||||||
g_Reg->MI_INTR_REG |= MI_INTR_PI;
|
|
||||||
g_Reg->CheckInterrupts();
|
//g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
|
||||||
|
//g_Reg->MI_INTR_REG |= MI_INTR_PI;
|
||||||
|
//g_Reg->CheckInterrupts();
|
||||||
//ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9) + 50);
|
//ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9) + 50);
|
||||||
//ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9));
|
//ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -358,13 +358,14 @@ void CPifRam::SI_DMA_READ()
|
||||||
|
|
||||||
if (g_System->bDelaySI())
|
if (g_System->bDelaySI())
|
||||||
{
|
{
|
||||||
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900, false);
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900 + (g_Random->next() % 0x40), false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, g_Random->next() % 0x40, false);
|
||||||
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
//g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
||||||
g_Reg->CheckInterrupts();
|
//g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
||||||
|
//g_Reg->CheckInterrupts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -716,6 +716,7 @@ void CN64System::Reset(bool bInitReg, bool ClearMenory)
|
||||||
m_SyncCPU->Reset(bInitReg, ClearMenory);
|
m_SyncCPU->Reset(bInitReg, ClearMenory);
|
||||||
}
|
}
|
||||||
g_Settings->SaveBool(GameRunning_InReset, true);
|
g_Settings->SaveBool(GameRunning_InReset, true);
|
||||||
|
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Done");
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,6 +764,7 @@ bool CN64System::SetActiveSystem(bool bActive)
|
||||||
R4300iOp::m_TestTimer = m_TestTimer;
|
R4300iOp::m_TestTimer = m_TestTimer;
|
||||||
R4300iOp::m_NextInstruction = m_NextInstruction;
|
R4300iOp::m_NextInstruction = m_NextInstruction;
|
||||||
R4300iOp::m_JumpToLocation = m_JumpToLocation;
|
R4300iOp::m_JumpToLocation = m_JumpToLocation;
|
||||||
|
g_Random = &m_Random;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -782,6 +784,7 @@ bool CN64System::SetActiveSystem(bool bActive)
|
||||||
g_Plugins = m_Plugins;
|
g_Plugins = m_Plugins;
|
||||||
g_TLBLoadAddress = NULL;
|
g_TLBLoadAddress = NULL;
|
||||||
g_TLBStoreAddress = NULL;
|
g_TLBStoreAddress = NULL;
|
||||||
|
g_Random = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <Project64-core/Settings/DebugSettings.h>
|
#include <Project64-core/Settings/DebugSettings.h>
|
||||||
#include <Project64-core/Plugin.h>
|
#include <Project64-core/Plugin.h>
|
||||||
#include <Project64-core/Logging.h>
|
#include <Project64-core/Logging.h>
|
||||||
|
#include <Project64-core/3rdParty/Random.h>
|
||||||
|
|
||||||
#include "Mips/TLBClass.h"
|
#include "Mips/TLBClass.h"
|
||||||
#include "CheatClass.h"
|
#include "CheatClass.h"
|
||||||
|
@ -164,6 +165,7 @@ private:
|
||||||
uint32_t m_SyncCount;
|
uint32_t m_SyncCount;
|
||||||
bool m_SyncCpu;
|
bool m_SyncCpu;
|
||||||
bool m_CheatsSlectionChanged;
|
bool m_CheatsSlectionChanged;
|
||||||
|
CRandom m_Random;
|
||||||
|
|
||||||
//When Syncing cores this is the PC where it last Sync'ed correctly
|
//When Syncing cores this is the PC where it last Sync'ed correctly
|
||||||
uint32_t m_LastSuccessSyncPC[10];
|
uint32_t m_LastSuccessSyncPC[10];
|
||||||
|
|
|
@ -62,4 +62,7 @@ extern CDebugger * g_Debugger;
|
||||||
extern uint8_t ** g_RecompPos;
|
extern uint8_t ** g_RecompPos;
|
||||||
|
|
||||||
class CMempak;
|
class CMempak;
|
||||||
extern CMempak * g_Mempak;
|
extern CMempak * g_Mempak;
|
||||||
|
|
||||||
|
class CRandom;
|
||||||
|
extern CRandom * g_Random;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
<ClCompile Include="3rdParty\7zip.cpp">
|
<ClCompile Include="3rdParty\7zip.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="3rdParty\Random.cpp" />
|
||||||
<ClCompile Include="AppInit.cpp" />
|
<ClCompile Include="AppInit.cpp" />
|
||||||
<ClCompile Include="Logging.cpp" />
|
<ClCompile Include="Logging.cpp" />
|
||||||
<ClCompile Include="MemoryExceptionFilter.cpp" />
|
<ClCompile Include="MemoryExceptionFilter.cpp" />
|
||||||
|
@ -126,6 +127,7 @@
|
||||||
<ClInclude Include="..\3rdParty\zlib\zconf.h" />
|
<ClInclude Include="..\3rdParty\zlib\zconf.h" />
|
||||||
<ClInclude Include="..\3rdParty\zlib\zlib.h" />
|
<ClInclude Include="..\3rdParty\zlib\zlib.h" />
|
||||||
<ClInclude Include="3rdParty\7zip.h" />
|
<ClInclude Include="3rdParty\7zip.h" />
|
||||||
|
<ClInclude Include="3rdParty\Random.h" />
|
||||||
<ClInclude Include="3rdParty\zip.h" />
|
<ClInclude Include="3rdParty\zip.h" />
|
||||||
<ClInclude Include="AppInit.h" />
|
<ClInclude Include="AppInit.h" />
|
||||||
<ClInclude Include="Debugger.h" />
|
<ClInclude Include="Debugger.h" />
|
||||||
|
|
|
@ -339,6 +339,9 @@
|
||||||
<ClCompile Include="N64System\Recompiler\Arm\ArmRegInfo.cpp">
|
<ClCompile Include="N64System\Recompiler\Arm\ArmRegInfo.cpp">
|
||||||
<Filter>Source Files\N64 System\Recompiler\Arm</Filter>
|
<Filter>Source Files\N64 System\Recompiler\Arm</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="3rdParty\Random.cpp">
|
||||||
|
<Filter>Source Files\3rd Party</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="stdafx.h">
|
<ClInclude Include="stdafx.h">
|
||||||
|
@ -659,6 +662,9 @@
|
||||||
<ClInclude Include="Debugger.h">
|
<ClInclude Include="Debugger.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="3rdParty\Random.h">
|
||||||
|
<Filter>Header Files\3rd Party</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="ClassDiagram.cd" />
|
<None Include="ClassDiagram.cd" />
|
||||||
|
|
Loading…
Reference in New Issue