Added Game Settings class, with removing the global of tlb use

This commit is contained in:
zilmar 2012-09-24 11:14:02 +10:00
parent fe2b8eae9b
commit f2a5df90f9
13 changed files with 112 additions and 46 deletions

View File

@ -4,7 +4,7 @@
#include "Logging.h"
//settings
BOOL g_ShowCPUPer = false, g_ShowTLBMisses = false, g_UseTlb = true,
BOOL g_ShowCPUPer = false, g_ShowTLBMisses = false,
g_HaveDebugger = false, g_AudioSignal = false,
g_UseLinking = false,
g_LogX86Code = false;
@ -27,7 +27,6 @@ void CC_Core::SetSettings ( )
g_HaveDebugger = _Settings->LoadBool(Debugger_Enabled);
g_ShowCPUPer = _Settings->LoadBool(UserInterface_ShowCPUPer);
g_ShowTLBMisses = false;
g_UseTlb = _Settings->LoadBool(Game_UseTlb);
g_CPU_Type = (CPU_TYPE)_Settings->LoadDword(Game_CpuType);
g_SaveUsing = (SAVE_CHIP_TYPE)_Settings->LoadDword(Game_SaveChip);
g_AudioSignal = _Settings->LoadBool(Game_RspAudioSignal);

View File

@ -62,7 +62,7 @@ DWORD StartTimer ( DWORD Address );
DWORD StopTimer ( void );
//settings
extern BOOL g_ShowCPUPer, g_ShowTLBMisses, g_UseTlb,
extern BOOL g_ShowCPUPer, g_ShowTLBMisses,
g_HaveDebugger, g_AudioSignal,
g_UseLinking, g_LogX86Code;
extern DWORD g_RomFileSize, g_CountPerOp;

View File

@ -1845,22 +1845,22 @@ void R4300iOp::COP0_MT (void) {
/************************** COP0 CO functions ***********************/
void R4300iOp::COP0_CO_TLBR (void) {
if (!g_UseTlb) { return; }
if (!bUseTlb) { return; }
_TLB->ReadEntry();
}
void R4300iOp::COP0_CO_TLBWI (void) {
if (!g_UseTlb) { return; }
if (!bUseTlb) { return; }
_TLB->WriteEntry(_Reg->INDEX_REGISTER & 0x1F,FALSE);
}
void R4300iOp::COP0_CO_TLBWR (void) {
if (!g_UseTlb) { return; }
if (!bUseTlb) { return; }
_TLB->WriteEntry(_Reg->RANDOM_REGISTER & 0x1F,true);
}
void R4300iOp::COP0_CO_TLBP (void) {
if (!g_UseTlb) { return; }
if (!bUseTlb) { return; }
_TLB->Probe();
}

View File

@ -1,4 +1,5 @@
class R4300iOp :
protected CGameSettings,
protected CSystemRegisters
{
public:

View File

@ -1264,7 +1264,7 @@ void CMipsMemoryVM::ResetMemoryStack ( void)
if (Reg != x86_Unknown) { UnMap_X86reg(Reg); }
Reg = Map_TempReg(x86_Any, 29, FALSE);
if (_Settings->LoadBool(Game_UseTlb))
if (bUseTlb())
{
TempReg = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(Reg,TempReg);
@ -2352,7 +2352,7 @@ void CMipsMemoryVM::Compile_LB (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2397,7 +2397,7 @@ void CMipsMemoryVM::Compile_LBU (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2442,7 +2442,7 @@ void CMipsMemoryVM::Compile_LH (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2487,7 +2487,7 @@ void CMipsMemoryVM::Compile_LHU (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2525,7 +2525,7 @@ void CMipsMemoryVM::Compile_LW (void)
Map_GPR_32bit(Opcode.rt,TRUE,-1);
Compile_LW(cMipsRegMapLo(Opcode.rt),Address);
} else {
if (g_UseTlb) {
if (bUseTlb()) {
if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); }
if (IsMapped(Opcode.base) && Opcode.offset == 0) {
ProtectGPR(Opcode.base);
@ -2608,7 +2608,7 @@ void CMipsMemoryVM::Compile_LWC1 (void)
return;
}
if (IsMapped(Opcode.base) && Opcode.offset == 0) {
if (g_UseTlb) {
if (bUseTlb()) {
ProtectGPR(Opcode.base);
TempReg1 = cMipsRegMapLo(Opcode.base);
} else {
@ -2637,7 +2637,7 @@ void CMipsMemoryVM::Compile_LWC1 (void)
}
}
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TempReg2,TempReg2,4);
@ -2692,7 +2692,7 @@ void CMipsMemoryVM::Compile_LWL (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2708,7 +2708,7 @@ void CMipsMemoryVM::Compile_LWL (void)
Map_GPR_32bit(Opcode.rt,TRUE,Opcode.rt);
AndVariableDispToX86Reg((void *)LWL_MASK,"LWL_MASK",cMipsRegMapLo(Opcode.rt),OffsetReg,Multip_x4);
MoveVariableDispToX86Reg((void *)LWL_SHIFT,"LWL_SHIFT",shift,OffsetReg,4);
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg1);
} else {
AndConstToX86Reg(TempReg1,0x1FFFFFFF);
@ -2756,7 +2756,7 @@ void CMipsMemoryVM::Compile_LWR (void)
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2772,7 +2772,7 @@ void CMipsMemoryVM::Compile_LWR (void)
Map_GPR_32bit(Opcode.rt,TRUE,Opcode.rt);
AndVariableDispToX86Reg((void *)LWR_MASK,"LWR_MASK",cMipsRegMapLo(Opcode.rt),OffsetReg,Multip_x4);
MoveVariableDispToX86Reg((void *)LWR_SHIFT,"LWR_SHIFT",shift,OffsetReg,4);
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg1);
} else {
AndConstToX86Reg(TempReg1,0x1FFFFFFF);
@ -2810,7 +2810,7 @@ void CMipsMemoryVM::Compile_LWU (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2847,7 +2847,7 @@ void CMipsMemoryVM::Compile_LD (void)
}
if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); }
if (IsMapped(Opcode.base) && Opcode.offset == 0) {
if (g_UseTlb) {
if (bUseTlb()) {
ProtectGPR(Opcode.base);
TempReg1 = cMipsRegMapLo(Opcode.base);
} else {
@ -2867,7 +2867,7 @@ void CMipsMemoryVM::Compile_LD (void)
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -2920,7 +2920,7 @@ void CMipsMemoryVM::Compile_LDC1 (void)
return;
}
if (IsMapped(Opcode.base) && Opcode.offset == 0) {
if (g_UseTlb) {
if (bUseTlb()) {
ProtectGPR(Opcode.base);
TempReg1 = cMipsRegMapLo(Opcode.base);
} else {
@ -2949,7 +2949,7 @@ void CMipsMemoryVM::Compile_LDC1 (void)
}
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TempReg2,TempReg2,4);
@ -3043,7 +3043,7 @@ void CMipsMemoryVM::Compile_SB (void)
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
Compile_StoreInstructClean(TempReg1,4);
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3108,7 +3108,7 @@ void CMipsMemoryVM::Compile_SH (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3184,7 +3184,7 @@ void CMipsMemoryVM::Compile_SW (void)
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
Compile_StoreInstructClean(TempReg1,4);
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3254,7 +3254,7 @@ void CMipsMemoryVM::Compile_SWC1 (void)
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3316,7 +3316,7 @@ void CMipsMemoryVM::Compile_SWL (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3333,7 +3333,7 @@ void CMipsMemoryVM::Compile_SWL (void)
AndConstToX86Reg(TempReg1,~3);
Value = Map_TempReg(x86_Any,-1,FALSE);
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86regPointerToX86reg(TempReg1, TempReg2,Value);
} else {
AndConstToX86Reg(TempReg1,0x1FFFFFFF);
@ -3354,7 +3354,7 @@ void CMipsMemoryVM::Compile_SWL (void)
AddX86RegToX86Reg(Value,OffsetReg);
}
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4);
@ -3399,7 +3399,7 @@ void CMipsMemoryVM::Compile_SWR (void)
TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3416,7 +3416,7 @@ void CMipsMemoryVM::Compile_SWR (void)
AndConstToX86Reg(TempReg1,~3);
Value = Map_TempReg(x86_Any,-1,FALSE);
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86regPointerToX86reg(TempReg1, TempReg2,Value);
} else {
AndConstToX86Reg(TempReg1,0x1FFFFFFF);
@ -3437,7 +3437,7 @@ void CMipsMemoryVM::Compile_SWR (void)
AddX86RegToX86Reg(Value,OffsetReg);
}
if (g_UseTlb) {
if (bUseTlb()) {
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4);
@ -3538,7 +3538,7 @@ void CMipsMemoryVM::Compile_SD (void)
Compile_StoreInstructClean(TempReg1,8);
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -3643,7 +3643,7 @@ void CMipsMemoryVM::Compile_SDC1 (void)
AddConstToX86Reg(TempReg1,(short)Opcode.immediate);
}
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);

View File

@ -296,7 +296,7 @@ void CRecompiler::RecompilerMain_Lookup( void )
DWORD PhysicalAddr;
CInterpreterCPU::BuildCPU();
if (g_UseTlb)
if (bUseTlb())
{
while(!m_EndEmulation)
{
@ -389,7 +389,7 @@ void CRecompiler::RecompilerMain_Lookup( void )
while(!m_EndEmulation)
{
/*if (g_UseTlb)
/*if (bUseTlb())
{
_Notify->BreakPoint(__FILE__,__LINE__);
#ifdef tofix
@ -829,7 +829,7 @@ void CRecompiler::ClearRecompCode_Phys(DWORD Address, int length, REMOVE_REASON
ClearRecompCode_Virt(Address + 0x80000000,length,Reason);
ClearRecompCode_Virt(Address + 0xA0000000,length,Reason);
if (g_UseTlb)
if (bUseTlb())
{
DWORD VAddr, Index = 0;
while (_TLB->PAddrToVAddr(Address,VAddr,Index))

View File

@ -1,5 +1,6 @@
class CRecompiler :
public CRecompilerSettings,
protected CGameSettings,
public CFunctionMap,
private CRecompMemory,
private CSystemRegisters
@ -58,6 +59,7 @@ private:
void RecompilerMain_VirtualTable_validate ( void );
void RecompilerMain_ChangeMemory ( void );
void RecompilerMain_Lookup ( void );
void RecompilerMain_Lookup_TLB ( void );
void RemoveFunction (CCompiledFunc * FunInfo, bool DelaySlot, REMOVE_REASON Reason );
};

View File

@ -1658,7 +1658,7 @@ void CRecompilerOps::LL (void) {
MoveConstToVariable(Address,_LLAddr,"LLAddr");
return;
}
if (g_UseTlb) {
if (bUseTlb()) {
if (IsMapped(m_Opcode.rt)) { ProtectGPR(m_Opcode.rt); }
if (IsMapped(m_Opcode.base) && m_Opcode.offset == 0) {
ProtectGPR(m_Opcode.base);
@ -1749,7 +1749,7 @@ void CRecompilerOps::SC (void){
TempReg1 = Map_TempReg(x86_Any,m_Opcode.base,FALSE);
AddConstToX86Reg(TempReg1,(short)m_Opcode.immediate);
}
if (g_UseTlb) {
if (bUseTlb()) {
TempReg2 = Map_TempReg(x86_Any,-1,FALSE);
MoveX86RegToX86Reg(TempReg1, TempReg2);
ShiftRightUnsignImmed(TempReg2,12);
@ -4090,7 +4090,7 @@ void CRecompilerOps::COP0_MT (void) {
/************************** COP0 CO functions ***********************/
void CRecompilerOps::COP0_CO_TLBR( void) {
CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(m_Opcode.Hex,m_CompilePC));
if (!g_UseTlb) { return; }
if (!bUseTlb()) { return; }
BeforeCallDirect(m_RegWorkingSet);
MoveConstToX86reg((DWORD)_TLB,x86_ECX);
Call_Direct(AddressOf(&CTLB::ReadEntry),"CTLB::ReadEntry");
@ -4099,7 +4099,7 @@ void CRecompilerOps::COP0_CO_TLBR( void) {
void CRecompilerOps::COP0_CO_TLBWI( void) {
CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(m_Opcode.Hex,m_CompilePC));
if (!g_UseTlb) { return; }
if (!bUseTlb()) { return; }
BeforeCallDirect(m_RegWorkingSet);
PushImm32("FALSE",FALSE);
MoveVariableToX86reg(&_Reg->INDEX_REGISTER,"INDEX_REGISTER",x86_ECX);
@ -4114,7 +4114,7 @@ void CRecompilerOps::COP0_CO_TLBWR( void) {
_Notify->BreakPoint(__FILE__,__LINE__);
#ifdef tofix
CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(m_Opcode.Hex,m_CompilePC));
if (!g_UseTlb) { return; }
if (!bUseTlb()) { return; }
UpdateCounters(&m_RegWorkingSet.BlockCycleCount(),&m_RegWorkingSet.BlockRandomModifier(),FALSE);
m_RegWorkingSet.BlockCycleCount() = 0;
@ -4134,7 +4134,7 @@ void CRecompilerOps::COP0_CO_TLBWR( void) {
void CRecompilerOps::COP0_CO_TLBP( void) {
CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(m_Opcode.Hex,m_CompilePC));
if (!g_UseTlb) { return; }
if (!bUseTlb()) { return; }
BeforeCallDirect(m_RegWorkingSet);
MoveConstToX86reg((DWORD)_TLB,x86_ECX);
Call_Direct(AddressOf(&CTLB::Probe), "CTLB::TLB_Probe");

View File

@ -4,7 +4,8 @@ class CRecompilerOps :
protected CX86Ops,
protected CSystemRegisters,
protected CN64SystemSettings,
protected CRecompilerSettings
protected CRecompilerSettings,
protected CGameSettings
{
protected:
enum BRANCH_TYPE

View File

@ -446,6 +446,10 @@
<Filter
Name="Settings Files"
>
<File
RelativePath=".\Settings\Game Settings.cpp"
>
</File>
<File
RelativePath="Settings\N64System Settings.cpp"
>
@ -3852,6 +3856,10 @@
<Filter
Name="Settings Headers"
>
<File
RelativePath=".\Settings\Game Settings.h"
>
</File>
<File
RelativePath="Settings\Gui Settings.h"
>

View File

@ -238,6 +238,7 @@ enum SettingID {
#include "Support.h"
#include "./Settings/Settings Class.h"
#include "./Settings/Game Settings.h"
#include "./Settings/Recompiler Settings.h"
#include "./Settings/N64System Settings.h"
#include "./Settings/Gui Settings.h"

View File

@ -0,0 +1,30 @@
#include "stdafx.h"
int CGameSettings::m_RefCount = 0;
bool CGameSettings::m_bUseTlb;
CGameSettings::CGameSettings()
{
m_RefCount += 1;
if (m_RefCount == 1)
{
_Settings->RegisterChangeCB(Game_UseTlb,this,(CSettings::SettingChangedFunc)StaticRefreshSettings);
RefreshSettings();
}
}
CGameSettings::~CGameSettings()
{
m_RefCount -= 1;
if (m_RefCount == 0)
{
_Settings->UnregisterChangeCB(Game_UseTlb,this,(CSettings::SettingChangedFunc)StaticRefreshSettings);
}
}
void CGameSettings::RefreshSettings()
{
m_bUseTlb = _Settings->LoadBool(Game_UseTlb);
}

View File

@ -0,0 +1,24 @@
#include <N64 System/N64 Types.h>
class CGameSettings
{
public:
CGameSettings();
virtual ~CGameSettings();
static inline bool bUseTlb ( void ) { return m_bUseTlb; }
private:
static void StaticRefreshSettings (CGameSettings * _this)
{
_this->RefreshSettings();
}
void RefreshSettings ( void );
//Settings that can be changed on the fly
static bool m_bUseTlb;
static int m_RefCount;
};