More refactoring of the remaining C code

This commit is contained in:
Emmet Young 2012-09-30 22:24:07 +10:00
parent 5c8cad4b5d
commit 90b0f6d60d
10 changed files with 56 additions and 56 deletions

View File

@ -5,7 +5,7 @@
//settings //settings
BOOL g_HaveDebugger = false, g_AudioSignal = false; BOOL g_HaveDebugger = false, g_AudioSignal = false;
DWORD g_RomFileSize = 0, g_CountPerOp = 2, g_ViRefreshRate = 1500; DWORD g_CountPerOp = 2, g_ViRefreshRate = 1500;
enum CPU_TYPE g_CPU_Type; enum CPU_TYPE g_CPU_Type;
enum SAVE_CHIP_TYPE g_SaveUsing; enum SAVE_CHIP_TYPE g_SaveUsing;

View File

@ -26,7 +26,7 @@ void CloseSaveChips ( void );
//settings //settings
extern BOOL g_HaveDebugger, g_AudioSignal; extern BOOL g_HaveDebugger, g_AudioSignal;
extern DWORD g_RomFileSize, g_CountPerOp; extern DWORD g_CountPerOp;
extern enum CPU_TYPE g_CPU_Type; extern enum CPU_TYPE g_CPU_Type;
extern enum SAVE_CHIP_TYPE g_SaveUsing; extern enum SAVE_CHIP_TYPE g_SaveUsing;

View File

@ -357,7 +357,7 @@ void Log_LW (DWORD PC, DWORD VAddr) {
LogMessage("%08X: read word from Pif Ram at 0x%X (%08X)",PC,VAddr - 0xBFC007C0, Value); LogMessage("%08X: read word from Pif Ram at 0x%X (%08X)",PC,VAddr - 0xBFC007C0, Value);
return; return;
} }
if ( VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < g_RomFileSize)) { return; } if ( VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < _Rom->GetRomSize())) { return; }
if ( VAddr >= 0xB0000000 && VAddr < 0xB0000040) { if ( VAddr >= 0xB0000000 && VAddr < 0xB0000040) {
if (!LogOptions.LogRomHeader) { return; } if (!LogOptions.LogRomHeader) { return; }

View File

@ -167,7 +167,32 @@ int DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) {
return FALSE; return FALSE;
} }
void InPermLoop (void) { CInterpreterCPU::CInterpreterCPU ()
{
}
CInterpreterCPU::~CInterpreterCPU()
{
}
void CInterpreterCPU::BuildCPU (void )
{
R4300iOp::m_TestTimer = FALSE;
R4300iOp::m_NextInstruction = NORMAL;
R4300iOp::m_JumpToLocation = 0;
m_CountPerOp = _Settings->LoadDword(Game_CounterFactor);
if (_Settings->LoadBool(Game_32Bit))
{
m_R4300i_Opcode = R4300iOp32::BuildInterpreter();
} else {
m_R4300i_Opcode = R4300iOp::BuildInterpreter();
}
}
void CInterpreterCPU::InPermLoop (void) {
// *** Changed ***/ // *** Changed ***/
//if (CPU_Type == CPU_SyncCores) { SyncRegisters.CP0[9] +=5; } //if (CPU_Type == CPU_SyncCores) { SyncRegisters.CP0[9] +=5; }
@ -191,37 +216,12 @@ void InPermLoop (void) {
/* check RDP running */ /* check RDP running */
if (*_NextTimer > 0) { if (*_NextTimer > 0) {
*_NextTimer = 0 - g_CountPerOp; *_NextTimer = 0 - m_CountPerOp;
_SystemTimer->UpdateTimers(); _SystemTimer->UpdateTimers();
} }
} }
} }
CInterpreterCPU::CInterpreterCPU ()
{
}
CInterpreterCPU::~CInterpreterCPU()
{
}
void CInterpreterCPU::BuildCPU (void )
{
R4300iOp::m_TestTimer = FALSE;
R4300iOp::m_NextInstruction = NORMAL;
R4300iOp::m_JumpToLocation = 0;
m_CountPerOp = _Settings->LoadDword(Game_CounterFactor);
if (_Settings->LoadBool(Game_32Bit))
{
m_R4300i_Opcode = R4300iOp32::BuildInterpreter();
} else {
m_R4300i_Opcode = R4300iOp::BuildInterpreter();
}
}
void CInterpreterCPU::ExecuteCPU (void ) void CInterpreterCPU::ExecuteCPU (void )
{ {
bool & Done = _System->m_EndEmulation; bool & Done = _System->m_EndEmulation;
@ -282,7 +282,7 @@ void CInterpreterCPU::ExecuteCPU (void )
case PERMLOOP_DELAY_DONE: case PERMLOOP_DELAY_DONE:
PROGRAM_COUNTER = JumpToLocation; PROGRAM_COUNTER = JumpToLocation;
R4300iOp::m_NextInstruction = NORMAL; R4300iOp::m_NextInstruction = NORMAL;
InPermLoop(); CInterpreterCPU::InPermLoop();
_SystemTimer->TimerDone(); _SystemTimer->TimerDone();
if (bDoSomething) if (bDoSomething)
{ {
@ -387,7 +387,7 @@ void CInterpreterCPU::ExecuteOps ( int Cycles )
case PERMLOOP_DELAY_DONE: case PERMLOOP_DELAY_DONE:
PROGRAM_COUNTER = JumpToLocation; PROGRAM_COUNTER = JumpToLocation;
R4300iOp::m_NextInstruction = NORMAL; R4300iOp::m_NextInstruction = NORMAL;
InPermLoop(); CInterpreterCPU::InPermLoop();
_SystemTimer->TimerDone(); _SystemTimer->TimerDone();
if (DoSomething) if (DoSomething)
{ {

View File

@ -8,7 +8,7 @@ public:
static void BuildCPU ( void ); static void BuildCPU ( void );
static void ExecuteCPU ( void ); static void ExecuteCPU ( void );
static void ExecuteOps ( int Cycles ); static void ExecuteOps ( int Cycles );
static void InPermLoop ( void );
private: private:
static R4300iOp::Func * m_R4300i_Opcode; static R4300iOp::Func * m_R4300i_Opcode;
static DWORD m_CountPerOp; static DWORD m_CountPerOp;

View File

@ -1,7 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
//#include "../C Core/Logging.h" //#include "../C Core/Logging.h"
void InPermLoop ( void );
int DelaySlotEffectsCompare ( DWORD PC, DWORD Reg1, DWORD Reg2 ); int DelaySlotEffectsCompare ( DWORD PC, DWORD Reg1, DWORD Reg2 );
#define ADDRESS_ERROR_EXCEPTION(Address,FromRead) \ #define ADDRESS_ERROR_EXCEPTION(Address,FromRead) \
@ -1095,7 +1094,7 @@ void R4300iOp32::REGIMM_BLTZ (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1111,7 +1110,7 @@ void R4300iOp32::REGIMM_BGEZ (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1127,7 +1126,7 @@ void R4300iOp32::REGIMM_BLTZL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1144,7 +1143,7 @@ void R4300iOp32::REGIMM_BGEZL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1161,7 +1160,7 @@ void R4300iOp32::REGIMM_BLTZAL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1178,7 +1177,7 @@ void R4300iOp32::REGIMM_BGEZAL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {

View File

@ -1689,7 +1689,7 @@ void R4300iOp::REGIMM_BLTZ (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1705,7 +1705,7 @@ void R4300iOp::REGIMM_BGEZ (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1721,7 +1721,7 @@ void R4300iOp::REGIMM_BLTZL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1738,7 +1738,7 @@ void R4300iOp::REGIMM_BGEZL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1755,7 +1755,7 @@ void R4300iOp::REGIMM_BLTZAL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {
@ -1772,7 +1772,7 @@ void R4300iOp::REGIMM_BGEZAL (void) {
{ {
if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0))
{ {
InPermLoop(); CInterpreterCPU::InPermLoop();
} }
} }
} else { } else {

View File

@ -117,20 +117,20 @@ void CDMA::PI_DMA_WRITE (void) {
#ifdef ROM_IN_MAPSPACE #ifdef ROM_IN_MAPSPACE
if (WrittenToRom) { if (WrittenToRom) {
DWORD OldProtect; DWORD OldProtect;
VirtualProtect(ROM,g_RomFileSize,PAGE_READONLY, &OldProtect); VirtualProtect(ROM,m_RomFileSize,PAGE_READONLY, &OldProtect);
} }
#endif #endif
#endif #endif
BYTE * ROM = _Rom->GetRomAddress(); BYTE * ROM = _Rom->GetRomAddress();
BYTE * RDRAM = _MMU->Rdram(); BYTE * RDRAM = _MMU->Rdram();
_Reg->PI_CART_ADDR_REG -= 0x10000000; _Reg->PI_CART_ADDR_REG -= 0x10000000;
if (_Reg->PI_CART_ADDR_REG + _Reg->PI_WR_LEN_REG + 1 < g_RomFileSize) { if (_Reg->PI_CART_ADDR_REG + _Reg->PI_WR_LEN_REG + 1 < _Rom->GetRomSize()) {
for (i = 0; i < _Reg->PI_WR_LEN_REG + 1; i ++) { for (i = 0; i < _Reg->PI_WR_LEN_REG + 1; i ++) {
*(RDRAM+((_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((_Reg->PI_CART_ADDR_REG + i) ^ 3)); *(RDRAM+((_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((_Reg->PI_CART_ADDR_REG + i) ^ 3));
} }
} else { } else {
DWORD Len; DWORD Len;
Len = g_RomFileSize - _Reg->PI_CART_ADDR_REG; Len = _Rom->GetRomSize() - _Reg->PI_CART_ADDR_REG;
for (i = 0; i < Len; i ++) { for (i = 0; i < Len; i ++) {
*(RDRAM+((_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((_Reg->PI_CART_ADDR_REG + i) ^ 3)); *(RDRAM+((_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((_Reg->PI_CART_ADDR_REG + i) ^ 3));
} }

View File

@ -778,7 +778,8 @@ void CN64System::ExecuteCPU ( void )
m_EndEmulation = false; m_EndEmulation = false;
_Notify->RefreshMenu(); _Notify->RefreshMenu();
g_RomFileSize = _Rom->GetRomSize(); //Check me
// _Rom->m_RomFileSize = _Rom->GetRomSize();
CC_Core C_Core; CC_Core C_Core;
C_Core.SetSettings(); C_Core.SetSettings();

View File

@ -393,7 +393,7 @@ void CCodeSection::GenerateSectionLinkage (void)
MoveConstToVariable(CompilePC(),_PROGRAM_COUNTER,"PROGRAM_COUNTER"); MoveConstToVariable(CompilePC(),_PROGRAM_COUNTER,"PROGRAM_COUNTER");
m_Jump.RegSet.WriteBackRegisters(); m_Jump.RegSet.WriteBackRegisters();
UpdateCounters(m_Jump.RegSet,false, true); UpdateCounters(m_Jump.RegSet,false, true);
Call_Direct(InPermLoop,"InPermLoop"); Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop");
MoveConstToX86reg((DWORD)_SystemTimer,x86_ECX); MoveConstToX86reg((DWORD)_SystemTimer,x86_ECX);
Call_Direct(AddressOf(&CSystemTimer::TimerDone),"CSystemTimer::TimerDone"); Call_Direct(AddressOf(&CSystemTimer::TimerDone),"CSystemTimer::TimerDone");
CPU_Message("CompileSystemCheck 3"); CPU_Message("CompileSystemCheck 3");
@ -472,7 +472,7 @@ void CCodeSection::GenerateSectionLinkage (void)
} }
//JumpInfo[i]->RegSet.BlockCycleCount() -= CountPerOp(); //JumpInfo[i]->RegSet.BlockCycleCount() -= CountPerOp();
Call_Direct(InPermLoop,"InPermLoop"); Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop");
//JumpInfo[i]->RegSet.BlockCycleCount() += CountPerOp(); //JumpInfo[i]->RegSet.BlockCycleCount() += CountPerOp();
UpdateCounters(JumpInfo[i]->RegSet,true,true); UpdateCounters(JumpInfo[i]->RegSet,true,true);
CPU_Message("CompileSystemCheck 4"); CPU_Message("CompileSystemCheck 4");
@ -509,7 +509,7 @@ void CCodeSection::GenerateSectionLinkage (void)
CPU_Message("PermLoop *** 2"); CPU_Message("PermLoop *** 2");
MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
UpdateCounters(JumpInfo[i]->RegSet,false, true); UpdateCounters(JumpInfo[i]->RegSet,false, true);
Call_Direct(InPermLoop,"InPermLoop"); Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop");
UpdateCounters(JumpInfo[i]->RegSet,true,true); UpdateCounters(JumpInfo[i]->RegSet,true,true);
CPU_Message("CompileSystemCheck 6"); CPU_Message("CompileSystemCheck 6");
CompileSystemCheck(-1,JumpInfo[i]->RegSet); CompileSystemCheck(-1,JumpInfo[i]->RegSet);
@ -577,7 +577,7 @@ void CCodeSection::GenerateSectionLinkage (void)
if (JumpInfo[i]->PermLoop) { if (JumpInfo[i]->PermLoop) {
CPU_Message("PermLoop *** 3"); CPU_Message("PermLoop *** 3");
MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
Call_Direct(InPermLoop,"InPermLoop"); Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop");
CPU_Message("CompileSystemCheck 8"); CPU_Message("CompileSystemCheck 8");
CompileSystemCheck(-1,JumpInfo[i]->RegSet); CompileSystemCheck(-1,JumpInfo[i]->RegSet);
} else { } else {