[Project64] Get System timing to use a local reference to registers

This commit is contained in:
zilmar 2017-04-28 08:09:04 +10:00
parent 7a193e5e56
commit f1530f6a05
3 changed files with 111 additions and 105 deletions

View File

@ -16,10 +16,14 @@
#include <Project64-core/N64System/N64Class.h>
#include <Project64-core/3rdParty/zip.h>
CSystemTimer::CSystemTimer(int32_t & NextTimer) :
CSystemTimer::CSystemTimer(CRegisters &Reg, int32_t & NextTimer) :
m_LastUpdate(0),
m_NextTimer(NextTimer),
m_inFixTimer(false)
m_Current(UnknownTimer),
m_inFixTimer(false),
m_Reg(Reg)
{
memset(m_TimerDetatils, 0, sizeof(m_TimerDetatils));
}
void CSystemTimer::Reset()
@ -163,9 +167,9 @@ void CSystemTimer::UpdateTimers()
{
int32_t random, wired;
m_LastUpdate = m_NextTimer;
g_Reg->COUNT_REGISTER += TimeTaken;
random = g_Reg->RANDOM_REGISTER - (TimeTaken / g_System->CountPerOp());
wired = g_Reg->WIRED_REGISTER;
m_Reg.COUNT_REGISTER += TimeTaken;
random = m_Reg.RANDOM_REGISTER - (TimeTaken / g_System->CountPerOp());
wired = m_Reg.WIRED_REGISTER;
if (random < wired)
{
if (wired == 0)
@ -178,7 +182,7 @@ void CSystemTimer::UpdateTimers()
random += ((wired - random + increment - 1) / increment) * increment;
}
}
g_Reg->RANDOM_REGISTER = random;
m_Reg.RANDOM_REGISTER = random;
}
}
@ -189,8 +193,8 @@ void CSystemTimer::TimerDone()
switch (m_Current)
{
case CSystemTimer::CompareTimer:
g_Reg->FAKE_CAUSE_REGISTER |= CAUSE_IP7;
g_Reg->CheckInterrupts();
m_Reg.FAKE_CAUSE_REGISTER |= CAUSE_IP7;
m_Reg.CheckInterrupts();
UpdateCompareTimer();
break;
case CSystemTimer::SoftResetTimer:
@ -199,22 +203,22 @@ void CSystemTimer::TimerDone()
break;
case CSystemTimer::SiTimer:
g_SystemTimer->StopTimer(CSystemTimer::SiTimer);
g_Reg->MI_INTR_REG |= MI_INTR_SI;
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
g_Reg->CheckInterrupts();
m_Reg.MI_INTR_REG |= MI_INTR_SI;
m_Reg.SI_STATUS_REG |= SI_STATUS_INTERRUPT;
m_Reg.CheckInterrupts();
break;
case CSystemTimer::PiTimer:
g_SystemTimer->StopTimer(CSystemTimer::PiTimer);
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
g_Reg->CheckInterrupts();
m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
m_Reg.MI_INTR_REG |= MI_INTR_PI;
m_Reg.CheckInterrupts();
break;
case CSystemTimer::DDPiTimer:
g_SystemTimer->StopTimer(CSystemTimer::DDPiTimer);
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
DiskBMUpdate();
g_Reg->MI_INTR_REG |= MI_INTR_PI;
g_Reg->CheckInterrupts();
m_Reg.MI_INTR_REG |= MI_INTR_PI;
m_Reg.CheckInterrupts();
break;
case CSystemTimer::ViTimer:
try
@ -225,8 +229,8 @@ void CSystemTimer::TimerDone()
{
WriteTrace(TraceN64System, TraceError, "Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__);
}
g_Reg->MI_INTR_REG |= MI_INTR_VI;
g_Reg->CheckInterrupts();
m_Reg.MI_INTR_REG |= MI_INTR_VI;
m_Reg.CheckInterrupts();
break;
case CSystemTimer::RspTimer:
g_SystemTimer->StopTimer(CSystemTimer::RspTimer);
@ -241,8 +245,8 @@ void CSystemTimer::TimerDone()
break;
case CSystemTimer::RSPTimerDlist:
g_SystemTimer->StopTimer(CSystemTimer::RSPTimerDlist);
g_Reg->m_GfxIntrReg |= MI_INTR_DP;
g_Reg->CheckInterrupts();
m_Reg.m_GfxIntrReg |= MI_INTR_DP;
m_Reg.CheckInterrupts();
break;
case CSystemTimer::AiTimerInterrupt:
g_SystemTimer->StopTimer(CSystemTimer::AiTimerInterrupt);
@ -267,7 +271,7 @@ void CSystemTimer::SetCompareTimer()
uint32_t NextCompare = 0x7FFFFFFF;
if (g_Reg)
{
NextCompare = g_Reg->COMPARE_REGISTER - g_Reg->COUNT_REGISTER;
NextCompare = m_Reg.COMPARE_REGISTER - m_Reg.COUNT_REGISTER;
if ((NextCompare & 0x80000000) != 0)
{
NextCompare = 0x7FFFFFFF;

View File

@ -12,6 +12,7 @@
#include <Common/LogClass.h>
#include <Project64-core/N64System/N64Types.h>
#include <Project64-core/N64System/Mips/RegisterClass.h>
#include <Project64-core/3rdParty/zip.h>
class CSystemTimer
@ -45,7 +46,7 @@ public:
};
public:
CSystemTimer(int32_t & NextTimer);
CSystemTimer(CRegisters &Reg, int32_t & NextTimer);
void SetTimer(TimerType Type, uint32_t Cycles, bool bRelative);
uint32_t GetTimer(TimerType Type);
void StopTimer(TimerType Type);
@ -77,6 +78,7 @@ private:
int32_t & m_NextTimer;
TimerType m_Current;
bool m_inFixTimer;
CRegisters & m_Reg;
void SetCompareTimer();
void FixTimers();

View File

@ -43,7 +43,7 @@ m_Reg(this, this),
m_Recomp(NULL),
m_InReset(false),
m_NextTimer(0),
m_SystemTimer(m_NextTimer),
m_SystemTimer(m_Reg, m_NextTimer),
m_bCleanFrameBox(true),
m_bInitialized(false),
m_RspBroke(true),