[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) :
m_NextTimer(NextTimer),
m_inFixTimer(false)
CSystemTimer::CSystemTimer(CRegisters &Reg, int32_t & NextTimer) :
m_LastUpdate(0),
m_NextTimer(NextTimer),
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

@ -31,33 +31,33 @@
#pragma warning(disable:4355) // Disable 'this' : used in base member initializer list
CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem) :
CSystemEvents(this, Plugins),
m_EndEmulation(false),
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
m_Plugins(Plugins),
m_SyncCPU(NULL),
m_SyncPlugins(NULL),
m_MMU_VM(SavesReadOnly),
m_TLB(this),
m_Reg(this, this),
m_Recomp(NULL),
m_InReset(false),
m_NextTimer(0),
m_SystemTimer(m_NextTimer),
m_bCleanFrameBox(true),
m_bInitialized(false),
m_RspBroke(true),
m_DMAUsed(false),
m_TestTimer(false),
m_NextInstruction(0),
m_JumpToLocation(0),
m_TLBLoadAddress(0),
m_TLBStoreAddress(0),
m_SyncCount(0),
m_thread(NULL),
m_hPauseEvent(true),
m_CheatsSlectionChanged(false),
m_SyncCpu(SyncSystem)
CSystemEvents(this, Plugins),
m_EndEmulation(false),
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
m_Plugins(Plugins),
m_SyncCPU(NULL),
m_SyncPlugins(NULL),
m_MMU_VM(SavesReadOnly),
m_TLB(this),
m_Reg(this, this),
m_Recomp(NULL),
m_InReset(false),
m_NextTimer(0),
m_SystemTimer(m_Reg, m_NextTimer),
m_bCleanFrameBox(true),
m_bInitialized(false),
m_RspBroke(true),
m_DMAUsed(false),
m_TestTimer(false),
m_NextInstruction(0),
m_JumpToLocation(0),
m_TLBLoadAddress(0),
m_TLBStoreAddress(0),
m_SyncCount(0),
m_thread(NULL),
m_hPauseEvent(true),
m_CheatsSlectionChanged(false),
m_SyncCpu(SyncSystem)
{
WriteTrace(TraceN64System, TraceDebug, "Start");
uint32_t gameHertz = g_Settings->LoadDword(Game_ScreenHertz);
@ -1455,7 +1455,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
Error.LogF("TLB[%2d], %08X, %08X, %08X, %08X\r\n", count,
m_TLB.TlbEntry(count).EntryHi.Value, m_TLB.TlbEntry(count).PageMask.Value,
SecondCPU->m_TLB.TlbEntry(count).EntryHi.Value, SecondCPU->m_TLB.TlbEntry(count).PageMask.Value
);
);
}
Error.Log("\r\n");
Error.Log("Code at PC:\r\n");
@ -1548,21 +1548,21 @@ bool CN64System::SaveState()
zipWriteInFileInZip(file, g_Rom->GetRomAddress(), 0x40);
zipWriteInFileInZip(file, &NextViTimer, sizeof(uint32_t));
zipWriteInFileInZip(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER));
zipWriteInFileInZip(file, m_Reg.m_GPR, sizeof(int64_t)* 32);
zipWriteInFileInZip(file, m_Reg.m_FPR, sizeof(int64_t)* 32);
zipWriteInFileInZip(file, m_Reg.m_CP0, sizeof(uint32_t)* 32);
zipWriteInFileInZip(file, m_Reg.m_FPCR, sizeof(uint32_t)* 32);
zipWriteInFileInZip(file, m_Reg.m_GPR, sizeof(int64_t) * 32);
zipWriteInFileInZip(file, m_Reg.m_FPR, sizeof(int64_t) * 32);
zipWriteInFileInZip(file, m_Reg.m_CP0, sizeof(uint32_t) * 32);
zipWriteInFileInZip(file, m_Reg.m_FPCR, sizeof(uint32_t) * 32);
zipWriteInFileInZip(file, &m_Reg.m_HI, sizeof(int64_t));
zipWriteInFileInZip(file, &m_Reg.m_LO, sizeof(int64_t));
zipWriteInFileInZip(file, m_Reg.m_RDRAM_Registers, sizeof(uint32_t)* 10);
zipWriteInFileInZip(file, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t)* 10);
zipWriteInFileInZip(file, m_Reg.m_Display_ControlReg, sizeof(uint32_t)* 10);
zipWriteInFileInZip(file, m_Reg.m_Mips_Interface, sizeof(uint32_t)* 4);
zipWriteInFileInZip(file, m_Reg.m_Video_Interface, sizeof(uint32_t)* 14);
zipWriteInFileInZip(file, m_Reg.m_Audio_Interface, sizeof(uint32_t)* 6);
zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t)* 13);
zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t)* 8);
zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(uint32_t)* 4);
zipWriteInFileInZip(file, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10);
zipWriteInFileInZip(file, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10);
zipWriteInFileInZip(file, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10);
zipWriteInFileInZip(file, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4);
zipWriteInFileInZip(file, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14);
zipWriteInFileInZip(file, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6);
zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
zipWriteInFileInZip(file, (void *const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
zipWriteInFileInZip(file, m_MMU_VM.PifRam(), 0x40);
zipWriteInFileInZip(file, m_MMU_VM.Rdram(), RdramSize);
@ -1600,21 +1600,21 @@ bool CN64System::SaveState()
hSaveFile.Write(g_Rom->GetRomAddress(), 0x40);
hSaveFile.Write(&NextViTimer, sizeof(uint32_t));
hSaveFile.Write(&m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER));
hSaveFile.Write(m_Reg.m_GPR, sizeof(int64_t)* 32);
hSaveFile.Write(m_Reg.m_FPR, sizeof(int64_t)* 32);
hSaveFile.Write(m_Reg.m_CP0, sizeof(uint32_t)* 32);
hSaveFile.Write(m_Reg.m_FPCR, sizeof(uint32_t)* 32);
hSaveFile.Write(m_Reg.m_GPR, sizeof(int64_t) * 32);
hSaveFile.Write(m_Reg.m_FPR, sizeof(int64_t) * 32);
hSaveFile.Write(m_Reg.m_CP0, sizeof(uint32_t) * 32);
hSaveFile.Write(m_Reg.m_FPCR, sizeof(uint32_t) * 32);
hSaveFile.Write(&m_Reg.m_HI, sizeof(int64_t));
hSaveFile.Write(&m_Reg.m_LO, sizeof(int64_t));
hSaveFile.Write(m_Reg.m_RDRAM_Registers, sizeof(uint32_t)* 10);
hSaveFile.Write(m_Reg.m_SigProcessor_Interface, sizeof(uint32_t)* 10);
hSaveFile.Write(m_Reg.m_Display_ControlReg, sizeof(uint32_t)* 10);
hSaveFile.Write(m_Reg.m_Mips_Interface, sizeof(uint32_t)* 4);
hSaveFile.Write(m_Reg.m_Video_Interface, sizeof(uint32_t)* 14);
hSaveFile.Write(m_Reg.m_Audio_Interface, sizeof(uint32_t)* 6);
hSaveFile.Write(m_Reg.m_Peripheral_Interface, sizeof(uint32_t)* 13);
hSaveFile.Write(m_Reg.m_RDRAM_Interface, sizeof(uint32_t)* 8);
hSaveFile.Write(m_Reg.m_SerialInterface, sizeof(uint32_t)* 4);
hSaveFile.Write(m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10);
hSaveFile.Write(m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10);
hSaveFile.Write(m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10);
hSaveFile.Write(m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4);
hSaveFile.Write(m_Reg.m_Video_Interface, sizeof(uint32_t) * 14);
hSaveFile.Write(m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6);
hSaveFile.Write(m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
hSaveFile.Write(m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
hSaveFile.Write(m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
hSaveFile.Write(&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
hSaveFile.Write(g_MMU->PifRam(), 0x40);
hSaveFile.Write(g_MMU->Rdram(), RdramSize);
@ -1777,21 +1777,21 @@ bool CN64System::LoadState(const char * FileName)
g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize);
unzReadCurrentFile(file, &NextVITimer, sizeof(NextVITimer));
unzReadCurrentFile(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER));
unzReadCurrentFile(file, m_Reg.m_GPR, sizeof(int64_t)* 32);
unzReadCurrentFile(file, m_Reg.m_FPR, sizeof(int64_t)* 32);
unzReadCurrentFile(file, m_Reg.m_CP0, sizeof(uint32_t)* 32);
unzReadCurrentFile(file, m_Reg.m_FPCR, sizeof(uint32_t)* 32);
unzReadCurrentFile(file, m_Reg.m_GPR, sizeof(int64_t) * 32);
unzReadCurrentFile(file, m_Reg.m_FPR, sizeof(int64_t) * 32);
unzReadCurrentFile(file, m_Reg.m_CP0, sizeof(uint32_t) * 32);
unzReadCurrentFile(file, m_Reg.m_FPCR, sizeof(uint32_t) * 32);
unzReadCurrentFile(file, &m_Reg.m_HI, sizeof(int64_t));
unzReadCurrentFile(file, &m_Reg.m_LO, sizeof(int64_t));
unzReadCurrentFile(file, m_Reg.m_RDRAM_Registers, sizeof(uint32_t)* 10);
unzReadCurrentFile(file, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t)* 10);
unzReadCurrentFile(file, m_Reg.m_Display_ControlReg, sizeof(uint32_t)* 10);
unzReadCurrentFile(file, m_Reg.m_Mips_Interface, sizeof(uint32_t)* 4);
unzReadCurrentFile(file, m_Reg.m_Video_Interface, sizeof(uint32_t)* 14);
unzReadCurrentFile(file, m_Reg.m_Audio_Interface, sizeof(uint32_t)* 6);
unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t)* 13);
unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t)* 8);
unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(uint32_t)* 4);
unzReadCurrentFile(file, m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10);
unzReadCurrentFile(file, m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10);
unzReadCurrentFile(file, m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10);
unzReadCurrentFile(file, m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4);
unzReadCurrentFile(file, m_Reg.m_Video_Interface, sizeof(uint32_t) * 14);
unzReadCurrentFile(file, m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6);
unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
unzReadCurrentFile(file, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
unzReadCurrentFile(file, m_MMU_VM.PifRam(), 0x40);
unzReadCurrentFile(file, m_MMU_VM.Rdram(), SaveRDRAMSize);
@ -1844,21 +1844,21 @@ bool CN64System::LoadState(const char * FileName)
hSaveFile.Read(&NextVITimer, sizeof(NextVITimer));
hSaveFile.Read(&m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER));
hSaveFile.Read(m_Reg.m_GPR, sizeof(int64_t)* 32);
hSaveFile.Read(m_Reg.m_FPR, sizeof(int64_t)* 32);
hSaveFile.Read(m_Reg.m_CP0, sizeof(uint32_t)* 32);
hSaveFile.Read(m_Reg.m_FPCR, sizeof(uint32_t)* 32);
hSaveFile.Read(m_Reg.m_GPR, sizeof(int64_t) * 32);
hSaveFile.Read(m_Reg.m_FPR, sizeof(int64_t) * 32);
hSaveFile.Read(m_Reg.m_CP0, sizeof(uint32_t) * 32);
hSaveFile.Read(m_Reg.m_FPCR, sizeof(uint32_t) * 32);
hSaveFile.Read(&m_Reg.m_HI, sizeof(int64_t));
hSaveFile.Read(&m_Reg.m_LO, sizeof(int64_t));
hSaveFile.Read(m_Reg.m_RDRAM_Registers, sizeof(uint32_t)* 10);
hSaveFile.Read(m_Reg.m_SigProcessor_Interface, sizeof(uint32_t)* 10);
hSaveFile.Read(m_Reg.m_Display_ControlReg, sizeof(uint32_t)* 10);
hSaveFile.Read(m_Reg.m_Mips_Interface, sizeof(uint32_t)* 4);
hSaveFile.Read(m_Reg.m_Video_Interface, sizeof(uint32_t)* 14);
hSaveFile.Read(m_Reg.m_Audio_Interface, sizeof(uint32_t)* 6);
hSaveFile.Read(m_Reg.m_Peripheral_Interface, sizeof(uint32_t)* 13);
hSaveFile.Read(m_Reg.m_RDRAM_Interface, sizeof(uint32_t)* 8);
hSaveFile.Read(m_Reg.m_SerialInterface, sizeof(uint32_t)* 4);
hSaveFile.Read(m_Reg.m_RDRAM_Registers, sizeof(uint32_t) * 10);
hSaveFile.Read(m_Reg.m_SigProcessor_Interface, sizeof(uint32_t) * 10);
hSaveFile.Read(m_Reg.m_Display_ControlReg, sizeof(uint32_t) * 10);
hSaveFile.Read(m_Reg.m_Mips_Interface, sizeof(uint32_t) * 4);
hSaveFile.Read(m_Reg.m_Video_Interface, sizeof(uint32_t) * 14);
hSaveFile.Read(m_Reg.m_Audio_Interface, sizeof(uint32_t) * 6);
hSaveFile.Read(m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
hSaveFile.Read(m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
hSaveFile.Read(m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
hSaveFile.Read((void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
hSaveFile.Read(m_MMU_VM.PifRam(), 0x40);
hSaveFile.Read(m_MMU_VM.Rdram(), SaveRDRAMSize);
@ -2206,4 +2206,4 @@ void CN64System::TLB_Changed()
{
g_Debugger->TLBChanged();
}
}
}