From 90b0f6d60dacf6128c1521cd76f3722ffa579971 Mon Sep 17 00:00:00 2001 From: Emmet Young Date: Sun, 30 Sep 2012 22:24:07 +1000 Subject: [PATCH] More refactoring of the remaining C code --- .../N64 System/C Core/C Core Interface.cpp | 2 +- .../N64 System/C Core/C Core Interface.h | 2 +- .../Project64/N64 System/C Core/Logging.cpp | 2 +- .../Interpreter/Interpreter CPU.cpp | 58 +++++++++---------- .../N64 System/Interpreter/Interpreter CPU.h | 2 +- .../Interpreter/Interpreter Ops 32.cpp | 13 ++--- .../Interpreter/Interpreter Ops.cpp | 12 ++-- Source/Project64/N64 System/Mips/Dma.cpp | 6 +- Source/Project64/N64 System/N64 Class.cpp | 3 +- .../N64 System/Recompiler/Code Section.cpp | 12 ++-- 10 files changed, 56 insertions(+), 56 deletions(-) diff --git a/Source/Project64/N64 System/C Core/C Core Interface.cpp b/Source/Project64/N64 System/C Core/C Core Interface.cpp index 55dfd7483..fa298ea8c 100644 --- a/Source/Project64/N64 System/C Core/C Core Interface.cpp +++ b/Source/Project64/N64 System/C Core/C Core Interface.cpp @@ -5,7 +5,7 @@ //settings 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 SAVE_CHIP_TYPE g_SaveUsing; diff --git a/Source/Project64/N64 System/C Core/C Core Interface.h b/Source/Project64/N64 System/C Core/C Core Interface.h index 1d083e82c..57d2724a8 100644 --- a/Source/Project64/N64 System/C Core/C Core Interface.h +++ b/Source/Project64/N64 System/C Core/C Core Interface.h @@ -26,7 +26,7 @@ void CloseSaveChips ( void ); //settings 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 SAVE_CHIP_TYPE g_SaveUsing; diff --git a/Source/Project64/N64 System/C Core/Logging.cpp b/Source/Project64/N64 System/C Core/Logging.cpp index 1d4249276..ec09ebbed 100644 --- a/Source/Project64/N64 System/C Core/Logging.cpp +++ b/Source/Project64/N64 System/C Core/Logging.cpp @@ -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); return; } - if ( VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < g_RomFileSize)) { return; } + if ( VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < _Rom->GetRomSize())) { return; } if ( VAddr >= 0xB0000000 && VAddr < 0xB0000040) { if (!LogOptions.LogRomHeader) { return; } diff --git a/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp b/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp index a40251318..ddb303a33 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp @@ -167,7 +167,32 @@ int DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { 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 ***/ //if (CPU_Type == CPU_SyncCores) { SyncRegisters.CP0[9] +=5; } @@ -191,37 +216,12 @@ void InPermLoop (void) { /* check RDP running */ if (*_NextTimer > 0) { - *_NextTimer = 0 - g_CountPerOp; + *_NextTimer = 0 - m_CountPerOp; _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 ) { bool & Done = _System->m_EndEmulation; @@ -282,7 +282,7 @@ void CInterpreterCPU::ExecuteCPU (void ) case PERMLOOP_DELAY_DONE: PROGRAM_COUNTER = JumpToLocation; R4300iOp::m_NextInstruction = NORMAL; - InPermLoop(); + CInterpreterCPU::InPermLoop(); _SystemTimer->TimerDone(); if (bDoSomething) { @@ -387,7 +387,7 @@ void CInterpreterCPU::ExecuteOps ( int Cycles ) case PERMLOOP_DELAY_DONE: PROGRAM_COUNTER = JumpToLocation; R4300iOp::m_NextInstruction = NORMAL; - InPermLoop(); + CInterpreterCPU::InPermLoop(); _SystemTimer->TimerDone(); if (DoSomething) { diff --git a/Source/Project64/N64 System/Interpreter/Interpreter CPU.h b/Source/Project64/N64 System/Interpreter/Interpreter CPU.h index 03a17b3c3..358d9651c 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter CPU.h +++ b/Source/Project64/N64 System/Interpreter/Interpreter CPU.h @@ -8,7 +8,7 @@ public: static void BuildCPU ( void ); static void ExecuteCPU ( void ); static void ExecuteOps ( int Cycles ); - + static void InPermLoop ( void ); private: static R4300iOp::Func * m_R4300i_Opcode; static DWORD m_CountPerOp; diff --git a/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp b/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp index 39b817ef1..66c4d8900 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" //#include "../C Core/Logging.h" -void InPermLoop ( void ); int DelaySlotEffectsCompare ( DWORD PC, DWORD Reg1, DWORD Reg2 ); #define ADDRESS_ERROR_EXCEPTION(Address,FromRead) \ @@ -1095,7 +1094,7 @@ void R4300iOp32::REGIMM_BLTZ (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1111,7 +1110,7 @@ void R4300iOp32::REGIMM_BGEZ (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1127,7 +1126,7 @@ void R4300iOp32::REGIMM_BLTZL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1144,7 +1143,7 @@ void R4300iOp32::REGIMM_BGEZL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1161,7 +1160,7 @@ void R4300iOp32::REGIMM_BLTZAL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1178,7 +1177,7 @@ void R4300iOp32::REGIMM_BGEZAL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { diff --git a/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp b/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp index 1ca922dce..c906a00f5 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp @@ -1689,7 +1689,7 @@ void R4300iOp::REGIMM_BLTZ (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1705,7 +1705,7 @@ void R4300iOp::REGIMM_BGEZ (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1721,7 +1721,7 @@ void R4300iOp::REGIMM_BLTZL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1738,7 +1738,7 @@ void R4300iOp::REGIMM_BGEZL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1755,7 +1755,7 @@ void R4300iOp::REGIMM_BLTZAL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { @@ -1772,7 +1772,7 @@ void R4300iOp::REGIMM_BGEZAL (void) { { if (!DelaySlotEffectsCompare((*_PROGRAM_COUNTER),m_Opcode.rs,0)) { - InPermLoop(); + CInterpreterCPU::InPermLoop(); } } } else { diff --git a/Source/Project64/N64 System/Mips/Dma.cpp b/Source/Project64/N64 System/Mips/Dma.cpp index 6580f87b6..e77c48270 100644 --- a/Source/Project64/N64 System/Mips/Dma.cpp +++ b/Source/Project64/N64 System/Mips/Dma.cpp @@ -117,20 +117,20 @@ void CDMA::PI_DMA_WRITE (void) { #ifdef ROM_IN_MAPSPACE if (WrittenToRom) { DWORD OldProtect; - VirtualProtect(ROM,g_RomFileSize,PAGE_READONLY, &OldProtect); + VirtualProtect(ROM,m_RomFileSize,PAGE_READONLY, &OldProtect); } #endif #endif BYTE * ROM = _Rom->GetRomAddress(); BYTE * RDRAM = _MMU->Rdram(); _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 ++) { *(RDRAM+((_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((_Reg->PI_CART_ADDR_REG + i) ^ 3)); } } else { DWORD Len; - Len = g_RomFileSize - _Reg->PI_CART_ADDR_REG; + Len = _Rom->GetRomSize() - _Reg->PI_CART_ADDR_REG; for (i = 0; i < Len; i ++) { *(RDRAM+((_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((_Reg->PI_CART_ADDR_REG + i) ^ 3)); } diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index bce03ae65..a34be37e9 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -778,7 +778,8 @@ void CN64System::ExecuteCPU ( void ) m_EndEmulation = false; _Notify->RefreshMenu(); - g_RomFileSize = _Rom->GetRomSize(); + //Check me + // _Rom->m_RomFileSize = _Rom->GetRomSize(); CC_Core C_Core; C_Core.SetSettings(); diff --git a/Source/Project64/N64 System/Recompiler/Code Section.cpp b/Source/Project64/N64 System/Recompiler/Code Section.cpp index 827b46f9b..ae772b478 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Section.cpp @@ -393,7 +393,7 @@ void CCodeSection::GenerateSectionLinkage (void) MoveConstToVariable(CompilePC(),_PROGRAM_COUNTER,"PROGRAM_COUNTER"); m_Jump.RegSet.WriteBackRegisters(); UpdateCounters(m_Jump.RegSet,false, true); - Call_Direct(InPermLoop,"InPermLoop"); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop"); MoveConstToX86reg((DWORD)_SystemTimer,x86_ECX); Call_Direct(AddressOf(&CSystemTimer::TimerDone),"CSystemTimer::TimerDone"); CPU_Message("CompileSystemCheck 3"); @@ -463,7 +463,7 @@ void CCodeSection::GenerateSectionLinkage (void) } if (JumpInfo[i]->TargetPC <= CompilePC()) { if (JumpInfo[i]->PermLoop) { - CPU_Message("PermLoop *** 1"); + CPU_Message("PermLoop *** 1"); MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); UpdateCounters(JumpInfo[i]->RegSet,false, true); if (_SyncSystem) { @@ -472,7 +472,7 @@ void CCodeSection::GenerateSectionLinkage (void) } //JumpInfo[i]->RegSet.BlockCycleCount() -= CountPerOp(); - Call_Direct(InPermLoop,"InPermLoop"); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop"); //JumpInfo[i]->RegSet.BlockCycleCount() += CountPerOp(); UpdateCounters(JumpInfo[i]->RegSet,true,true); CPU_Message("CompileSystemCheck 4"); @@ -509,7 +509,7 @@ void CCodeSection::GenerateSectionLinkage (void) CPU_Message("PermLoop *** 2"); MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); UpdateCounters(JumpInfo[i]->RegSet,false, true); - Call_Direct(InPermLoop,"InPermLoop"); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop"); UpdateCounters(JumpInfo[i]->RegSet,true,true); CPU_Message("CompileSystemCheck 6"); CompileSystemCheck(-1,JumpInfo[i]->RegSet); @@ -575,9 +575,9 @@ void CCodeSection::GenerateSectionLinkage (void) if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC) { UpdateCounters(JumpInfo[i]->RegSet,true,true); if (JumpInfo[i]->PermLoop) { - CPU_Message("PermLoop *** 3"); + CPU_Message("PermLoop *** 3"); MoveConstToVariable(JumpInfo[i]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); - Call_Direct(InPermLoop,"InPermLoop"); + Call_Direct(AddressOf(CInterpreterCPU::InPermLoop),"CInterpreterCPU::InPermLoop"); CPU_Message("CompileSystemCheck 8"); CompileSystemCheck(-1,JumpInfo[i]->RegSet); } else {