Merge pull request #1398 from Azimer/Randomize_SI_PI
Randomize SI and PI DMAs to improve COUNT randomization with FAT
This commit is contained in:
commit
3b1406a0a7
|
@ -43,6 +43,7 @@
|
||||||
<ClCompile Include="MemTest.cpp" />
|
<ClCompile Include="MemTest.cpp" />
|
||||||
<ClCompile Include="path.cpp" />
|
<ClCompile Include="path.cpp" />
|
||||||
<ClCompile Include="Platform.cpp" />
|
<ClCompile Include="Platform.cpp" />
|
||||||
|
<ClCompile Include="Random.cpp" />
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -64,6 +65,7 @@
|
||||||
<ClInclude Include="MemTest.h" />
|
<ClInclude Include="MemTest.h" />
|
||||||
<ClInclude Include="path.h" />
|
<ClInclude Include="path.h" />
|
||||||
<ClInclude Include="Platform.h" />
|
<ClInclude Include="Platform.h" />
|
||||||
|
<ClInclude Include="Random.h" />
|
||||||
<ClInclude Include="SmartPointer.h" />
|
<ClInclude Include="SmartPointer.h" />
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
<ClInclude Include="StdString.h" />
|
<ClInclude Include="StdString.h" />
|
||||||
|
|
|
@ -62,6 +62,9 @@
|
||||||
<ClCompile Include="DateTimeClass.cpp">
|
<ClCompile Include="DateTimeClass.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Random.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="stdafx.h">
|
<ClInclude Include="stdafx.h">
|
||||||
|
@ -124,5 +127,8 @@
|
||||||
<ClInclude Include="DateTimeClass.h">
|
<ClInclude Include="DateTimeClass.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Random.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,54 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* *
|
||||||
|
* 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 "stdafx.h"
|
||||||
|
#include "Random.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
CRandom::CRandom()
|
||||||
|
{
|
||||||
|
m_state = (uint32_t)time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
CRandom::CRandom(uint32_t state_value)
|
||||||
|
{
|
||||||
|
m_state = state_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t CRandom::randomizer(uint32_t val)
|
||||||
|
{
|
||||||
|
return ((uint64_t)val * 279470273UL) % 4294967291UL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t CRandom::next()
|
||||||
|
{
|
||||||
|
m_state = randomizer(m_state);
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRandom::set_state(uint32_t state_value)
|
||||||
|
{
|
||||||
|
if (state_value == 0)
|
||||||
|
m_state = 1;
|
||||||
|
else
|
||||||
|
m_state = state_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t CRandom::get_state()
|
||||||
|
{
|
||||||
|
return m_state;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* *
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <Common/stdtypes.h>
|
||||||
|
|
||||||
|
class CRandom
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CRandom();
|
||||||
|
CRandom(uint32_t seed_value);
|
||||||
|
uint32_t next();
|
||||||
|
uint32_t get_state();
|
||||||
|
void set_state(uint32_t state_value);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint32_t randomizer(uint32_t val);
|
||||||
|
uint32_t m_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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
#pragma warning(disable:4355) // Disable 'this' : used in base member initializer list
|
#pragma warning(disable:4355) // Disable 'this' : used in base member initializer list
|
||||||
|
|
||||||
CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem) :
|
CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem) :
|
||||||
CSystemEvents(this, Plugins),
|
CSystemEvents(this, Plugins),
|
||||||
m_EndEmulation(false),
|
m_EndEmulation(false),
|
||||||
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
|
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
|
||||||
|
@ -57,7 +57,8 @@ CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem)
|
||||||
m_thread(NULL),
|
m_thread(NULL),
|
||||||
m_hPauseEvent(true),
|
m_hPauseEvent(true),
|
||||||
m_CheatsSlectionChanged(false),
|
m_CheatsSlectionChanged(false),
|
||||||
m_SyncCpu(SyncSystem)
|
m_SyncCpu(SyncSystem),
|
||||||
|
m_Random(randomizer_seed)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Start");
|
WriteTrace(TraceN64System, TraceDebug, "Start");
|
||||||
memset(m_LastSuccessSyncPC, 0, sizeof(m_LastSuccessSyncPC));
|
memset(m_LastSuccessSyncPC, 0, sizeof(m_LastSuccessSyncPC));
|
||||||
|
@ -110,7 +111,7 @@ CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem)
|
||||||
g_Plugins->CopyPlugins(g_Settings->LoadStringVal(Directory_PluginSync));
|
g_Plugins->CopyPlugins(g_Settings->LoadStringVal(Directory_PluginSync));
|
||||||
m_SyncPlugins = new CPlugins(Directory_PluginSync, true);
|
m_SyncPlugins = new CPlugins(Directory_PluginSync, true);
|
||||||
m_SyncPlugins->SetRenderWindows(g_Plugins->SyncWindow(), NULL);
|
m_SyncPlugins->SetRenderWindows(g_Plugins->SyncWindow(), NULL);
|
||||||
m_SyncCPU = new CN64System(m_SyncPlugins, true, true);
|
m_SyncCPU = new CN64System(m_SyncPlugins, randomizer_seed, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reset(true, true);
|
Reset(true, true);
|
||||||
|
@ -359,7 +360,7 @@ bool CN64System::RunFileImage(const char * FileLoc)
|
||||||
void CN64System::RunLoadedImage(void)
|
void CN64System::RunLoadedImage(void)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Start");
|
WriteTrace(TraceN64System, TraceDebug, "Start");
|
||||||
g_BaseSystem = new CN64System(g_Plugins, false, false);
|
g_BaseSystem = new CN64System(g_Plugins, (uint32_t)time(NULL), false, false);
|
||||||
if (g_BaseSystem)
|
if (g_BaseSystem)
|
||||||
{
|
{
|
||||||
g_BaseSystem->StartEmulation(true);
|
g_BaseSystem->StartEmulation(true);
|
||||||
|
@ -716,6 +717,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 +765,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 +785,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Common/Random.h>
|
||||||
#include <Common/SyncEvent.h>
|
#include <Common/SyncEvent.h>
|
||||||
#include <Common/Thread.h>
|
#include <Common/Thread.h>
|
||||||
#include <Project64-core/Settings/N64SystemSettings.h>
|
#include <Project64-core/Settings/N64SystemSettings.h>
|
||||||
|
@ -48,7 +49,7 @@ class CN64System :
|
||||||
protected CDebugSettings
|
protected CDebugSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem);
|
CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem);
|
||||||
virtual ~CN64System(void);
|
virtual ~CN64System(void);
|
||||||
|
|
||||||
CCheats m_Cheats;
|
CCheats m_Cheats;
|
||||||
|
@ -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];
|
||||||
|
|
|
@ -32,5 +32,6 @@ uint32_t * g_TLBStoreAddress = NULL;
|
||||||
CDebugger * g_Debugger = NULL;
|
CDebugger * g_Debugger = NULL;
|
||||||
uint8_t ** g_RecompPos = NULL;
|
uint8_t ** g_RecompPos = NULL;
|
||||||
CMempak * g_Mempak = NULL;
|
CMempak * g_Mempak = NULL;
|
||||||
|
CRandom * g_Random = NULL;
|
||||||
|
|
||||||
int * g_NextTimer;
|
int * g_NextTimer;
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue