Mips: Refactor loading of plugins and how game is shut down

This commit is contained in:
zilmar 2013-01-03 19:51:00 +11:00
parent b8a0303674
commit 8c48ba4f70
23 changed files with 569 additions and 562 deletions

View File

@ -115,9 +115,9 @@ void CSystemEvents::ExecuteEvents ( void )
bLoadedSave = true;
}
break;
case SysEvent_ChangePlugins:
/*case SysEvent_ChangePlugins:
ChangePluginFunc();
break;
break;*/
case SysEvent_ChangingFullScreen:
g_Notify->ChangeFullScreen();
break;
@ -194,7 +194,7 @@ void CSystemEvents::ExecuteEvents ( void )
}
}
void CSystemEvents::ChangePluginFunc ( void )
/*void CSystemEvents::ChangePluginFunc ( void )
{
g_Notify->DisplayMessage(0,MSG_PLUGIN_INIT);
if (g_Settings->LoadBool(Plugin_GFX_Changed))
@ -226,4 +226,4 @@ void CSystemEvents::ChangePluginFunc ( void )
g_BaseSystem->m_EndEmulation = true;
}
g_Recompiler->ResetRecompCode();
}
}*/

View File

@ -33,7 +33,7 @@ enum SystemEvent {
SysEvent_ResumeCPU_DumpMemory,
SysEvent_ResumeCPU_SearchMemory,
SysEvent_ChangingFullScreen,
SysEvent_ChangePlugins,
// SysEvent_ChangePlugins,
SysEvent_SaveMachineState,
SysEvent_LoadMachineState,
SysEvent_Interrupt_SP,
@ -66,7 +66,7 @@ private:
CSystemEvents(const CSystemEvents&); // Disable copy constructor
CSystemEvents& operator=(const CSystemEvents&); // Disable assignment
void ChangePluginFunc( void );
//void ChangePluginFunc( void );
CN64System * m_System;
EventList m_Events;

View File

@ -16,6 +16,8 @@
CN64System::CN64System ( CPlugins * Plugins, bool SavesReadOnly ) :
CSystemEvents(this),
m_SyncPlugins(NULL),
m_SyncWindow(NULL),
m_Reg(this,this),
m_MMU_VM(this,SavesReadOnly),
m_TLB(this),
@ -57,7 +59,30 @@ CN64System::CN64System ( CPlugins * Plugins, bool SavesReadOnly ) :
}
}
CN64System::~CN64System ( void ) {
CN64System::~CN64System ( void )
{
SetActiveSystem(false);
if (m_SyncCPU)
{
m_SyncCPU->CpuStopped();
delete m_SyncCPU;
m_SyncCPU = NULL;
}
if (m_Recomp)
{
delete m_Recomp;
m_Recomp = NULL;
}
if (m_SyncPlugins)
{
delete m_SyncPlugins;
m_SyncPlugins = NULL;
}
if (m_SyncWindow)
{
delete m_SyncWindow;
m_SyncWindow = NULL;
}
}
void CN64System::ExternalEvent ( SystemEvent action )
@ -69,7 +94,6 @@ void CN64System::ExternalEvent ( SystemEvent action )
case SysEvent_ExecuteInterrupt:
case SysEvent_SaveMachineState:
case SysEvent_LoadMachineState:
case SysEvent_ChangePlugins:
case SysEvent_ChangingFullScreen:
case SysEvent_GSButtonPressed:
case SysEvent_ResetCPU_SoftDone:
@ -144,46 +168,73 @@ void CN64System::ExternalEvent ( SystemEvent action )
bool CN64System::RunFileImage ( const char * FileLoc )
{
CloseSystem();
if (g_Settings->LoadBool(GameRunning_LoadingInProgress))
{
return false;
}
g_Settings->SaveBool(GameRunning_LoadingInProgress,true);
HANDLE *hThread = new HANDLE;
*hThread = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": Mark Rom as loading");
//create the needed info into a structure to pass as one paramater
//for creating a thread
FileImageInfo * Info = new FileImageInfo;
Info->FileName = FileLoc;
Info->ThreadHandle = hThread;
*hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)stLoadFileImage,Info,0, &(Info->ThreadID));
if (*hThread == NULL)
//Mark the rom as loading
g_Settings->SaveBool(GameRunning_LoadingInProgress,true);
g_Notify->RefreshMenu();
//Try to load the passed N64 rom
if (g_Rom == NULL)
{
WriteTrace(TraceDebug,__FUNCTION__ ": Allocating global rom object");
g_Rom = new CN64Rom();
} else {
WriteTrace(TraceDebug,__FUNCTION__ ": Use existing global rom object");
}
WriteTraceF(TraceDebug,__FUNCTION__ ": Loading \"%s\"",FileLoc);
if (g_Rom->LoadN64Image(FileLoc))
{
g_System->RefreshGameSettings();
WriteTrace(TraceDebug,__FUNCTION__ ": Add Recent Rom");
g_Notify->AddRecentRom(FileLoc);
g_Notify->SetWindowCaption(g_Settings->LoadString(Game_GoodName).c_str());
if (g_Settings->LoadDword(Setting_AutoStart) != 0)
{
g_BaseSystem = new CN64System(g_Plugins,false);
if (g_BaseSystem)
{
g_BaseSystem->StartEmulation(true);
}
}
g_Settings->SaveBool(GameRunning_LoadingInProgress,false);
delete Info;
delete hThread;
g_Notify->RefreshMenu();
} else {
WriteTraceF(TraceError,__FUNCTION__ ": LoadN64Image failed (\"%s\")",FileLoc);
g_Notify->DisplayError(g_Rom->GetError());
delete g_Rom;
g_Rom = NULL;
g_Settings->SaveBool(GameRunning_LoadingInProgress,false);
g_Notify->RefreshMenu();
return false;
}
return true;
}
void CN64System::CloseSystem ( void )
{
if (g_BaseSystem)
{
g_BaseSystem->CloseCpu();
delete g_BaseSystem;
g_BaseSystem = NULL;
}
}
bool CN64System::EmulationStarting ( HANDLE hThread, DWORD ThreadId )
{
bool bRes = true;
if (g_BaseSystem)
{
WriteTrace(TraceDebug,__FUNCTION__ ": Destroying old N64 system");
delete g_BaseSystem;
g_BaseSystem = NULL;
}
WriteTrace(TraceDebug,__FUNCTION__ ": Hide Rom Browser");
g_Notify->HideRomBrowser();
WriteTrace(TraceDebug,__FUNCTION__ ": Creating N64 system");
g_BaseSystem = new CN64System(g_Plugins,false);
WriteTrace(TraceDebug, __FUNCTION__ ": Setting N64 system as active");
if (g_BaseSystem->SetActiveSystem(true))
{
@ -205,8 +256,6 @@ bool CN64System::EmulationStarting ( HANDLE hThread, DWORD ThreadId )
sprintf(Message,__FUNCTION__ ": Exception caught\nFile: %s\nLine: %d",__FILE__,__LINE__);
MessageBox(NULL,Message,"Exception",MB_OK);
}
g_BaseSystem->m_CPU_Handle = NULL;
g_BaseSystem->m_CPU_ThreadID = 0;
} else {
WriteTrace(TraceError,__FUNCTION__ ": SetActiveSystem failed");
g_Notify->DisplayError(__FUNCTION__ ": Failed to Initialize N64 System");
@ -214,127 +263,96 @@ bool CN64System::EmulationStarting ( HANDLE hThread, DWORD ThreadId )
g_Notify->RefreshMenu();
bRes = false;
}
if (g_BaseSystem)
{
delete g_BaseSystem;
g_BaseSystem = NULL;
}
return bRes;
}
void CN64System::stLoadFileImage ( FileImageInfo * Info )
{
CoInitialize(NULL);
WriteTrace(TraceDebug,__FUNCTION__ ": Copy thread Info");
FileImageInfo ImageInfo = *Info;
HANDLE ThreadHandle = *(ImageInfo.ThreadHandle);
delete ImageInfo.ThreadHandle;
ImageInfo.ThreadHandle = &ThreadHandle;
delete Info;
WriteTrace(TraceDebug,__FUNCTION__ ": Mark Rom as loading");
//Mark the rom as loading
g_Settings->SaveBool(GameRunning_LoadingInProgress,true);
g_Notify->RefreshMenu();
//Try to load the passed N64 rom
if (g_Rom == NULL)
{
WriteTrace(TraceDebug,__FUNCTION__ ": Allocating global rom object");
g_Rom = new CN64Rom();
} else {
WriteTrace(TraceDebug,__FUNCTION__ ": Use existing global rom object");
}
WriteTraceF(TraceDebug,__FUNCTION__ ": Loading \"%s\"",ImageInfo.FileName.c_str());
if (g_Rom->LoadN64Image(ImageInfo.FileName.c_str()))
{
g_System->RefreshGameSettings();
WriteTrace(TraceDebug,__FUNCTION__ ": Add Recent Rom");
g_Notify->AddRecentRom(ImageInfo.FileName.c_str());
g_Notify->SetWindowCaption(g_Settings->LoadString(Game_GoodName).c_str());
if (g_Settings->LoadDword(Setting_AutoStart) != 0)
{
EmulationStarting(*((HANDLE *)ImageInfo.ThreadHandle),ImageInfo.ThreadID);
}
g_Settings->SaveBool(GameRunning_LoadingInProgress,false);
g_Notify->RefreshMenu();
} else {
WriteTraceF(TraceError,__FUNCTION__ ": LoadN64Image failed (\"%s\")",ImageInfo.FileName.c_str());
g_Notify->DisplayError(g_Rom->GetError());
delete g_Rom;
g_Rom = NULL;
g_Settings->SaveBool(GameRunning_LoadingInProgress,false);
g_Notify->RefreshMenu();
return;
}
CoUninitialize();
WriteTrace(TraceDebug,__FUNCTION__ ": Done");
}
void CN64System::StartEmulation2 ( bool NewThread )
{
if (NewThread)
{
FileImageInfo * Info = new FileImageInfo;
WriteTrace(TraceDebug,__FUNCTION__ ": Starting");
g_Notify->HideRomBrowser();
#ifndef EXTERNAL_RELEASE
LogOptions.GenerateLog = g_Settings->LoadDword(Debugger_GenerateDebugLog);
LoadLogOptions(&LogOptions, FALSE);
StartLog();
#endif
CInterpreterCPU::BuildCPU();
DWORD CpuType = g_Settings->LoadDword(Game_CpuType);
if (CpuType == CPU_SyncCores)
{
g_Notify->DisplayMessage(5,"Copy Plugins");
g_Plugins->CopyPlugins(g_Settings->LoadString(Directory_PluginSync));
m_SyncWindow = new CMainGui(false);
m_SyncPlugins = new CPlugins( g_Settings->LoadString(Directory_PluginSync) );
m_SyncPlugins->SetRenderWindows(m_SyncWindow,m_SyncWindow);
m_SyncCPU = new CN64System(m_SyncPlugins, true);
}
if (CpuType == CPU_Recompiler || CpuType == CPU_SyncCores)
{
m_Recomp = new CRecompiler(m_Reg,m_Profile,m_EndEmulation);
}
bool bSetActive = true;
if (m_SyncCPU)
{
bSetActive = m_SyncCPU->SetActiveSystem();
}
if (bSetActive)
{
bSetActive = SetActiveSystem();
}
if (!bSetActive)
{
g_Settings->SaveBool(GameRunning_LoadingInProgress,false);
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
g_Notify->RefreshMenu();
g_Notify->ShowRomBrowser();
}
g_Notify->MakeWindowOnTop(g_Settings->LoadBool(UserInterface_AlwaysOnTop));
if (!g_Settings->LoadBool(Beta_IsValidExe))
{
return;
}
ThreadInfo * Info = new ThreadInfo;
HANDLE * hThread = new HANDLE;
*hThread = NULL;
//create the needed info into a structure to pass as one paramater
//for createing a thread
//Info->_this = this;
//create the needed info into a structure to pass as one parameter
//for creating a thread
Info->ThreadHandle = hThread;
*hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartEmulationThread,Info,0, &Info->ThreadID);
return;
}
WriteTrace(TraceDebug,__FUNCTION__ ": Starting");
*hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartEmulationThread,Info,0, &Info->ThreadID);
} else {
//mark the emulation as starting and fix up menus
g_Notify->DisplayMessage(5,MSG_EMULATION_STARTED);
g_Notify->HideRomBrowser();
//RefreshSettings();
if (!SetActiveSystem())
{
g_Settings->SaveBool(GameRunning_LoadingInProgress,false);
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
//Set handle to NULL so this thread is not terminated
m_CPU_Handle = NULL;
m_CPU_ThreadID = 0;
g_Notify->RefreshMenu();
g_Notify->ShowRomBrowser();
}
g_Notify->MakeWindowOnTop(g_Settings->LoadBool(UserInterface_AlwaysOnTop));
if (!g_Settings->LoadBool(Beta_IsValidExe))
{
return;
}
//mark the emulation as starting and fix up menus
g_Notify->DisplayMessage(5,MSG_EMULATION_STARTED);
if (g_Settings->LoadBool(Setting_AutoFullscreen))
{
WriteTrace(TraceDebug,__FUNCTION__ " 15");
CIniFile RomIniFile(g_Settings->LoadString(SupportFile_RomDatabase).c_str());
stdstr Status = g_Settings->LoadString(Rdb_Status);
char String[100];
RomIniFile.GetString("Rom Status",stdstr_f("%s.AutoFullScreen", Status.c_str()).c_str(),"true",String,sizeof(String));
if (_stricmp(String,"true") == 0)
if (g_Settings->LoadBool(Setting_AutoFullscreen))
{
g_Notify->ChangeFullScreen();
WriteTrace(TraceDebug,__FUNCTION__ " 15");
CIniFile RomIniFile(g_Settings->LoadString(SupportFile_RomDatabase).c_str());
stdstr Status = g_Settings->LoadString(Rdb_Status);
char String[100];
RomIniFile.GetString("Rom Status",stdstr_f("%s.AutoFullScreen", Status.c_str()).c_str(),"true",String,sizeof(String));
if (_stricmp(String,"true") == 0)
{
g_Notify->ChangeFullScreen();
}
}
ExecuteCPU();
}
ExecuteCPU();
}
void CN64System::StartEmulation ( bool NewThread )
@ -349,11 +367,11 @@ void CN64System::StartEmulation ( bool NewThread )
}
}
void CN64System::StartEmulationThread ( FileImageInfo * Info )
void CN64System::StartEmulationThread ( ThreadInfo * Info )
{
CoInitialize(NULL);
EmulationStarting(Info->ThreadHandle,Info->ThreadID);
EmulationStarting(*Info->ThreadHandle,Info->ThreadID);
delete Info->ThreadHandle;
delete Info;
@ -405,9 +423,9 @@ void CN64System::CloseCpu ( void )
if (ExitCode == STILL_ACTIVE)
{
TerminateThread(hThread,0);
CpuStopped();
}
}
CpuStopped();
}
void CN64System::SelectCheats ( WND_HANDLE hParent )
@ -534,6 +552,11 @@ bool CN64System::SetActiveSystem( bool bActive )
bool bReset = false;
bool bRes = true;
if (bActive && g_System == this)
{
return true;
}
if (bActive)
{
m_Reg.SetAsCurrentSystem();
@ -600,8 +623,8 @@ bool CN64System::SetActiveSystem( bool bActive )
{
WriteTrace(TraceDebug,__FUNCTION__ ": Reseting Plugins");
g_Notify->DisplayMessage(5,MSG_PLUGIN_INIT);
g_Plugins->Reset();
bRes = g_Plugins->Initiate();
m_Plugins->Reset();
bRes = m_Plugins->Initiate(this);
if (!bRes)
{
WriteTrace(TraceError, __FUNCTION__ ": g_Plugins->Initiate Failed");
@ -795,21 +818,24 @@ void CN64System::ExecuteCPU ( void )
m_EndEmulation = false;
g_Notify->RefreshMenu();
#ifndef EXTERNAL_RELEASE
LogOptions.GenerateLog = g_Settings->LoadDword(Debugger_GenerateDebugLog);
LoadLogOptions(&LogOptions, FALSE);
StartLog();
#endif
CInterpreterCPU::BuildCPU();
m_Plugins->RomOpened();
if (m_SyncCPU)
{
m_SyncCPU->m_Plugins->RomOpened();
}
switch ((CPU_TYPE)g_Settings->LoadDword(Game_CpuType)) {
case CPU_Recompiler: ExecuteRecompiler(); break;
case CPU_SyncCores: ExecuteSyncCPU(); break;
default: ExecuteInterpret(); break;
}
CpuStopped();
SetActiveSystem(false);
g_Settings->SaveBool(GameRunning_CPU_Running,(DWORD)false);
g_Notify->WindowMode();
m_Plugins->RomClosed();
if (m_SyncCPU)
{
m_SyncCPU->m_Plugins->RomClosed();
}
}
void CN64System::ExecuteInterpret () {
@ -819,46 +845,21 @@ void CN64System::ExecuteInterpret () {
void CN64System::ExecuteRecompiler ()
{
//execute opcodes while no errors
m_Recomp = new CRecompiler(m_Profile,m_EndEmulation);
SetActiveSystem();
m_Recomp->Run();
}
void CN64System::ExecuteSyncCPU ()
{
g_Notify->DisplayMessage(5,"Copy Plugins");
g_Plugins->CopyPlugins(g_Settings->LoadString(Directory_PluginSync));
CMainGui SyncWindow(false);
CPlugins SyncPlugins ( g_Settings->LoadString(Directory_PluginSync) );
SyncPlugins.SetRenderWindows(&SyncWindow,&SyncWindow);
m_SyncCPU = new CN64System(&SyncPlugins, true);
m_Recomp = new CRecompiler(m_Profile,m_EndEmulation);
g_Notify->BringToTop();
SetActiveSystem();
if (m_SyncCPU->SetActiveSystem())
{
SetActiveSystem();
m_Recomp->Run();
} else {
SetActiveSystem();
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
}
m_Recomp->Run();
}
void CN64System::CpuStopped ( void ) {
void CN64System::CpuStopped ( void )
{
g_Settings->SaveBool(GameRunning_CPU_Running,(DWORD)false);
g_Notify->WindowMode();
if (!m_InReset)
{
CloseCpu();
if (g_Plugins)
{
g_Plugins->ShutDownPlugins();
}
if (m_hPauseEvent)
{
CloseHandle(m_hPauseEvent);
@ -875,16 +876,7 @@ void CN64System::CpuStopped ( void ) {
if (m_SyncCPU)
{
m_SyncCPU->CpuStopped();
delete m_SyncCPU;
m_SyncCPU = NULL;
}
if (m_Recomp)
{
delete m_Recomp;
m_Recomp = NULL;
}
m_CPU_ThreadID = 0;
m_CPU_Handle = 0;
}
void CN64System::UpdateSyncCPU (CN64System * const SecondCPU, DWORD const Cycles) {
@ -1226,7 +1218,7 @@ bool CN64System::SaveState(void)
{
if (m_Recomp)
{
m_Recomp->ResetRecompCode();
m_Recomp->ResetRecompCode(true);
}
}
@ -1676,6 +1668,7 @@ void CN64System::RefreshScreen ( void ) {
if (g_Plugins->Control()->GetKeys)
{
BUTTONS Keys;
memset(&Keys,0,sizeof(Keys));
for (int Control = 0; Control < 4; Control++)
{

View File

@ -12,12 +12,6 @@
typedef std::list<SystemEvent> EVENT_LIST;
typedef struct {
stdstr FileName;
HANDLE * ThreadHandle;
DWORD ThreadID;
} FileImageInfo;
typedef std::map<DWORD, DWORD> FUNC_CALLS;
class CPlugins;
@ -38,6 +32,11 @@ public:
CN64System ( CPlugins * Plugins, bool SavesReadOnly );
virtual ~CN64System ( void );
typedef struct {
HANDLE * ThreadHandle;
DWORD ThreadID;
} ThreadInfo;
CProfiling m_Profile;
CCheats m_Cheats;
bool m_EndEmulation;
@ -45,7 +44,8 @@ public:
SystemType m_SystemType;
//Methods
static bool CN64System::RunFileImage ( const char * FileLoc );
static bool RunFileImage ( const char * FileLoc );
static void CloseSystem ( void );
void CloseCpu ( void );
void ExternalEvent ( SystemEvent action ); //covers gui interacting and timers etc..
@ -65,7 +65,7 @@ public:
bool SaveState ( void );
bool LoadState ( LPCSTR FileName );
bool LoadState ( void );
// inline CPlugins * Plugins ( void ) const { return m_Plugins; }
inline bool DmaUsed ( void ) const { return m_DMAUsed; }
inline void SetDmaUsed ( bool DMAUsed) { m_DMAUsed = DMAUsed; }
inline DWORD GetButtons ( int Control ) { return m_Buttons[Control]; }
@ -91,8 +91,7 @@ private:
friend CSystemTimer;
//Used for loading and potentialy executing the CPU in its own thread.
static void stLoadFileImage ( FileImageInfo * Info );
static void StartEmulationThread ( FileImageInfo * Info );
static void StartEmulationThread ( ThreadInfo * Info );
static bool EmulationStarting ( HANDLE hThread, DWORD ThreadId );
void ExecuteCPU ( void );
@ -127,6 +126,8 @@ private:
CPlugins * const m_Plugins; //The plugin container
CN64System * m_SyncCPU;
CPlugins * m_SyncPlugins;
CMainGui * m_SyncWindow;
CMipsMemoryVM m_MMU_VM; //Memory of the n64
CTLB m_TLB;
CRegisters m_Reg;

View File

@ -70,166 +70,12 @@ void CFunctionMap::CleanBuffers ( void )
}
}
void CFunctionMap::Reset ( void )
void CFunctionMap::Reset ( bool bAllocate )
{
bool bAllocate = (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable != NULL) ||
(g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable != NULL);
CleanBuffers();
if (bAllocate)
if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable != NULL) ||
(g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable != NULL))
{
AllocateMemory();
}
}
/*
CFunctionMap::~CFunctionMap()
{
Reset(false);
}
void * CFunctionMap::CompilerFindFunction( CFunctionMap * _this, DWORD vAddr )
{
return _this->FindFunction(vAddr);
}
CCompiledFunc * CFunctionMap::FindFunction( DWORD vAddr, int Length )
{
DWORD SectionEnd = (vAddr + Length + 0xFFF) >> 0xC;
for (DWORD Section = (vAddr >> 0x0C); Section < SectionEnd; Section++)
{
CCompiledFunc table = m_FunctionTable[Section];
if (table == NULL)
{
continue;
}
DWORD Start = 0;
/*if (Section == (vAddr >> 0x0C))
{
Start = ((vAddr & 0xFFF) >> 2);
}*/
/*int SearchEnd = (Length - ((Section - (vAddr >> 0x0C)) * (0x1000 >> 2))) >> 2;
if (Start + SearchEnd > (0x1000 >> 2))
{
SearchEnd = (0x1000 >> 2);
}
for (int i = Start; i < SearchEnd; i++)
{
PCCompiledFunc & info = table[i];
if (info)
{
if (info->VEndPC() < vAddr)
{
continue;
}
return info;
}
}
}
return NULL;
}
void CFunctionMap::Reset( bool AllocateMemory )
{
if (m_FunctionTable)
{
for (int i = 0; i < 0xFFFFF; i ++)
{
if (m_FunctionTable[i] == NULL)
{
continue;
}
CCompiledFunc table = m_FunctionTable[i];
for (int x = 0; x < (0x1000) >> 2; x++)
{
PCCompiledFunc info = table[x];
if (info == NULL)
{
continue;
}
while (info->Next)
{
PCCompiledFunc todelete = info;
info = info->Next;
delete todelete;
}
delete info;
}
delete table;
}
if (!AllocateMemory)
{
VirtualFree(m_FunctionTable,0,MEM_RELEASE);
m_FunctionTable = NULL;
}
}
if ( AllocateMemory)
{
if (m_FunctionTable == NULL)
{
m_FunctionTable = (CCompiledFunc *)VirtualAlloc(NULL,0xFFFFF * sizeof(CCompiledFunc *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
if (m_FunctionTable == NULL) {
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
}
}
memset(m_FunctionTable,0,0xFFFFF * sizeof(DWORD));
}
}
CCompiledFunc * CFunctionMap::AddFunctionInfo( DWORD vAddr, DWORD pAddr )
{
CCompiledFunc & table = m_FunctionTable[vAddr >> 0xC];
if (table == NULL)
{
table = new PCCompiledFunc[(0x1000 >> 2)];
if (table == NULL)
{
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
}
memset(table,0,sizeof(PCCompiledFunc) * (0x1000 >> 2));
}
PCCompiledFunc & info = table[(vAddr & 0xFFF) >> 2];
if (info != NULL)
{
PCCompiledFunc old_info = info;
info = new CCompiledFunc(vAddr,pAddr);
info->Next = old_info;
} else {
info = new CCompiledFunc(vAddr,pAddr);
}
return info;
}
void CFunctionMap::Remove(CCompiledFunc * info)
{
DWORD vAddr = info->VStartPC();
CCompiledFunc & table = m_FunctionTable[vAddr >> 0xC];
if (table == NULL)
{
return;
}
PCCompiledFunc & current_info = table[(vAddr & 0xFFF) >> 2];
if (current_info == NULL)
{
return;
}
if (current_info == info)
{
delete info;
table[(vAddr & 0xFFF) >> 2] = NULL;
} else {
g_Notify->BreakPoint(__FILE__,__LINE__);
}
}
*/
}

View File

@ -20,7 +20,7 @@ protected:
~CFunctionMap();
bool AllocateMemory ( void );
void Reset ( void );
void Reset ( bool bAllocate);
public:
inline PCCompiledFunc_TABLE * FunctionTable ( void ) const { return m_FunctionTable; }

View File

@ -10,17 +10,21 @@
****************************************************************************/
#include "stdafx.h"
CRecompiler::CRecompiler(CProfiling & Profile, bool & EndEmulation ) :
CRecompiler::CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & EndEmulation ) :
m_Registers(Registers),
m_Profile(Profile),
PROGRAM_COUNTER(g_Reg->m_PROGRAM_COUNTER),
PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER),
m_EndEmulation(EndEmulation)
{
ResetMemoryStackPos();
if (g_MMU != NULL)
{
ResetMemoryStackPos();
}
}
CRecompiler::~CRecompiler()
{
ResetRecompCode();
ResetRecompCode(false);
}
void CRecompiler::Run()
@ -95,7 +99,7 @@ void CRecompiler::RecompilerMain_VirtualTable ( void )
{
if (!g_TransVaddr->ValidVaddr(PC))
{
g_Reg->DoTLBReadMiss(false,PC);
m_Registers.DoTLBReadMiss(false,PC);
if (!g_TransVaddr->ValidVaddr(PC))
{
g_Notify->DisplayError("Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PC);
@ -514,7 +518,7 @@ void CRecompiler::RecompilerMain_Lookup_TLB( void )
{
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
{
g_Reg->DoTLBReadMiss(false,PROGRAM_COUNTER);
m_Registers.DoTLBReadMiss(false,PROGRAM_COUNTER);
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
{
g_Notify->DisplayError("Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
@ -614,7 +618,7 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB( void )
{
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
{
g_Reg->DoTLBReadMiss(false,PROGRAM_COUNTER);
m_Registers.DoTLBReadMiss(false,PROGRAM_COUNTER);
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
{
g_Notify->DisplayError("Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
@ -678,14 +682,14 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB( void )
void CRecompiler::Reset()
{
ResetRecompCode();
ResetRecompCode(true);
ResetMemoryStackPos();
}
void CRecompiler::ResetRecompCode()
void CRecompiler::ResetRecompCode( bool bAllocate )
{
CRecompMemory::Reset();
CFunctionMap::Reset();
CFunctionMap::Reset(bAllocate);
for (CCompiledFuncList::iterator iter = m_Functions.begin(); iter != m_Functions.end(); iter++)
{
@ -981,18 +985,19 @@ void CRecompiler::ClearRecompCode_Virt(DWORD Address, int length,REMOVE_REASON R
void CRecompiler::ResetMemoryStackPos( void )
{
if (g_Reg->m_GPR[29].UW[0] == 0)
if (g_MMU == NULL)
{
g_Notify->BreakPoint(__FILE__,__LINE__);
return;
}
if (m_Registers.m_GPR[29].UW[0] == 0)
{
m_MemoryStack = NULL;
return;
}
if (g_MMU == NULL || g_Reg == NULL)
if (m_Registers.m_GPR[29].UW[0] < 0x80000000 || m_Registers.m_GPR[29].UW[0] >= 0xC0000000)
{
g_Notify->BreakPoint(__FILE__,__LINE__);
}
if (g_Reg->m_GPR[29].UW[0] < 0x80000000 || g_Reg->m_GPR[29].UW[0] >= 0xC0000000)
{
g_Notify->BreakPoint(__FILE__,__LINE__);
}
m_MemoryStack = (DWORD)(g_MMU->Rdram() + (g_Reg->m_GPR[29].UW[0] & 0x1FFFFFFF));
m_MemoryStack = (DWORD)(g_MMU->Rdram() + (m_Registers.m_GPR[29].UW[0] & 0x1FFFFFFF));
}

View File

@ -32,12 +32,12 @@ public:
typedef void (* DelayFunc)(void);
public:
CRecompiler (CProfiling & Profile, bool & EndEmulation );
CRecompiler (CRegisters & Registers, CProfiling & Profile, bool & EndEmulation );
~CRecompiler (void);
void Run ( void );
void Reset ( void );
void ResetRecompCode ( void );
void ResetRecompCode ( bool bAllocate );
bool GenerateX86Code (CCodeBlock & BlockInfo, CCodeSection * Section, DWORD Test );
@ -50,13 +50,9 @@ public:
inline DWORD & MemoryStackPos ( void ) { return m_MemoryStack; }
private:
CCompiledFuncList m_Functions;
CProfiling & m_Profile;
bool & m_EndEmulation;
DWORD m_MemoryStack;
//Quick access to registers
DWORD & PROGRAM_COUNTER;
CRecompiler(void); // Disable default constructor
CRecompiler(const CRecompiler&); // Disable copy constructor
CRecompiler& operator=(const CRecompiler&); // Disable assignment
CCompiledFunc * CompilerCode ( void );
bool Compiler4300iBlock ( CCompiledFunc * info );
@ -75,4 +71,13 @@ private:
void RecompilerMain_Lookup_validate_TLB ( void );
void RemoveFunction (CCompiledFunc * FunInfo, bool DelaySlot, REMOVE_REASON Reason );
CCompiledFuncList m_Functions;
CRegisters & m_Registers;
CProfiling & m_Profile;
bool & m_EndEmulation;
DWORD m_MemoryStack;
//Quick access to registers
DWORD & PROGRAM_COUNTER;
};

View File

@ -60,7 +60,7 @@ void CRecompMemory::CheckRecompMem ( void )
}
if (m_RecompSize == MaxCompileBufferSize)
{
g_Recompiler->ResetRecompCode();
g_Recompiler->ResetRecompCode(true);
return;
}
LPVOID MemAddr = VirtualAlloc( m_RecompCode + m_RecompSize , IncreaseCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

View File

@ -233,6 +233,15 @@ void CAudioPlugin::RomOpened ( void )
}
}
void CAudioPlugin::RomClose ( void )
{
if (m_RomOpen)
{
RomClosed();
m_RomOpen = false;
}
}
void CAudioPlugin::Close(void) {
if (m_RomOpen) {
RomClosed();

View File

@ -21,6 +21,7 @@ public:
void Close ( void );
void GameReset ( void );
void RomOpened ( void );
void RomClose ( void );
stdstr PluginName ( void ) const { return m_PluginInfo.Name; }
inline bool Initilized ( void ) const { return m_Initilized; }

View File

@ -227,6 +227,15 @@ void CControl_Plugin::RomOpened ( void )
}
}
void CControl_Plugin::RomClose ( void )
{
if (m_RomOpen)
{
RomClosed();
m_RomOpen = false;
}
}
void CControl_Plugin::Close(void) {
if (m_RomOpen) {
RomClosed();

View File

@ -77,6 +77,7 @@ public:
void UpdateKeys ( void );
void Close ( void );
void RomOpened ( void );
void RomClose ( void );
void GameReset ( void );
stdstr PluginName ( void ) const { return m_PluginInfo.Name; }

View File

@ -165,7 +165,13 @@ CGfxPlugin::~CGfxPlugin (void) {
UnloadPlugin();
}
bool CGfxPlugin::Initiate ( CN64System * System, CMainGui * RenderWindow ) {
bool CGfxPlugin::Initiate ( CN64System * System, CMainGui * RenderWindow )
{
if (m_Initilized)
{
Close();
}
typedef struct {
HWND hWnd; /* Render window */
HWND hStatusBar; /* if render window does not have a status bar then this is NULL */
@ -298,11 +304,12 @@ bool CGfxPlugin::Initiate ( CN64System * System, CMainGui * RenderWindow ) {
}
void CGfxPlugin::Close(void) {
if (m_RomOpen) {
RomClosed();
m_RomOpen = false;
if (m_RomOpen)
{
RomClose();
}
if (m_Initilized) {
if (m_Initilized)
{
CloseDLL();
m_Initilized = false;
}
@ -313,21 +320,30 @@ void CGfxPlugin::RomOpened ( void )
//Real system ... then make the file as open
if (!m_RomOpen)
{
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Before RomOpen");
RomOpen();
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": After RomOpen");
m_RomOpen = true;
}
}
void CGfxPlugin::RomClose ( void )
{
if (m_RomOpen)
{
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Before RomClosed");
RomClosed();
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": After RomClosed");
m_RomOpen = false;
}
}
void CGfxPlugin::GameReset(void)
{
if (m_RomOpen)
{
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Starting");
RomClosed();
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Done");
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Starting");
RomOpen();
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Done");
RomClose();
RomOpened();
}
}

View File

@ -53,6 +53,7 @@ public:
bool Initilized ( void ) { return m_Initilized; }
void Close ( void );
void RomOpened ( void );
void RomClose ( void );
void GameReset ( void );
stdstr PluginName ( void ) const { return m_PluginInfo.Name; }

View File

@ -20,31 +20,41 @@ CPlugins::CPlugins (const stdstr & PluginDir):
g_Settings->RegisterChangeCB(Plugin_GFX_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Plugin_AUDIO_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Plugin_CONT_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Plugin_UseHleGfx,this,(CSettings::SettingChangedFunc)PluginChanged);
/*g_Settings->RegisterChangeCB(Plugin_UseHleGfx,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Plugin_UseHleAudio,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_Gfx,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_Audio,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_Contr,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_RSP,this,(CSettings::SettingChangedFunc)PluginChanged);
*/
}
CPlugins::~CPlugins (void) {
CPlugins::~CPlugins (void)
{
g_Settings->UnregisterChangeCB(Plugin_RSP_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_GFX_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_AUDIO_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_CONT_Current,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_UseHleGfx,this,(CSettings::SettingChangedFunc)PluginChanged);
/* g_Settings->UnregisterChangeCB(Plugin_UseHleGfx,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_UseHleAudio,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_Gfx,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_Audio,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_Contr,this,(CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_RSP,this,(CSettings::SettingChangedFunc)PluginChanged);
ShutDownPlugins();
*/
DestroyGfxPlugin();
DestroyAudioPlugin();
DestroyRspPlugin();
DestroyControlPlugin();
}
void CPlugins::PluginChanged ( CPlugins * _this )
{
if (g_Settings->LoadBool(GameRunning_CPU_Running))
{
return;
}
bool bGfxChange = _stricmp(_this->m_GfxFile.c_str(),g_Settings->LoadString(Game_Plugin_Gfx).c_str()) != 0;
bool bAudioChange = _stricmp(_this->m_AudioFile.c_str(),g_Settings->LoadString(Game_Plugin_Audio).c_str()) != 0;
bool bRspChange = _stricmp(_this->m_RSPFile.c_str(),g_Settings->LoadString(Game_Plugin_RSP).c_str()) != 0;
@ -52,21 +62,68 @@ void CPlugins::PluginChanged ( CPlugins * _this )
if ( bGfxChange || bAudioChange || bRspChange || bContChange )
{
if (g_Settings->LoadBool(GameRunning_CPU_Running) != 0)
{
if (g_BaseSystem) { g_BaseSystem->ExternalEvent(SysEvent_ChangePlugins); }
} else {
_this->Reset();
g_Notify->RefreshMenu();
}
_this->Reset();
g_Notify->RefreshMenu();
}
}
void CPlugins::CreatePlugins( void ) {
Reset(PLUGIN_TYPE_GFX);
void CPlugins::CreatePlugins( void )
{
if (m_Gfx == NULL)
{
m_GfxFile = g_Settings->LoadString(Game_Plugin_Gfx);
CPath GfxPluginFile(m_PluginDir.c_str(),m_GfxFile.c_str());
WriteTraceF(TraceGfxPlugin,__FUNCTION__ ": GFX Loading (%s): Starting",(LPCTSTR)GfxPluginFile);
m_Gfx = new CGfxPlugin(GfxPluginFile);
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": GFX Loading Done");
WriteTraceF(TraceGfxPlugin,__FUNCTION__ ": GFX Current Ver: %s",m_Gfx->PluginName().c_str());
g_Settings->SaveString(Plugin_GFX_CurVer,m_Gfx->PluginName().c_str());
}
if (m_Audio == NULL)
{
m_AudioFile = g_Settings->LoadString(Game_Plugin_Audio);
CPath PluginFile(m_PluginDir.c_str(),m_AudioFile.c_str());
WriteTraceF(TraceDebug,__FUNCTION__ ": Loading Audio Plugin (%s): Starting",(LPCTSTR)PluginFile);
m_Audio = new CAudioPlugin(PluginFile);
WriteTrace(TraceDebug,__FUNCTION__ ": Loading Audio Plugin Done");
g_Settings->SaveString(Plugin_AUDIO_CurVer,m_Audio->PluginName().c_str());
}
if (m_RSP == NULL)
{
m_RSPFile = g_Settings->LoadString(Plugin_RSP_Current);
CPath RspPluginFile(m_PluginDir.c_str(),m_RSPFile.c_str());
WriteTraceF(TraceRSP,__FUNCTION__ "(%s): RSP Loading",(LPCTSTR)RspPluginFile);
m_RSP = new CRSP_Plugin(RspPluginFile);
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Loading Done");
WriteTraceF(TraceRSP,__FUNCTION__ ": RSP Current Ver: %s",m_RSP->PluginName().c_str());
g_Settings->SaveString(Plugin_RSP_CurVer,m_RSP->PluginName().c_str());
//Enable debugger
if (m_RSP->EnableDebugging)
{
WriteTrace(TraceRSP,__FUNCTION__ ": EnableDebugging starting");
m_RSP->EnableDebugging(bHaveDebugger());
WriteTrace(TraceRSP,__FUNCTION__ ": EnableDebugging done");
}
}
if (m_Control == NULL)
{
m_ControlFile = g_Settings->LoadString(Game_Plugin_Controller);
CPath PluginFile(m_PluginDir.c_str(),m_ControlFile.c_str());
WriteTraceF(TraceDebug,__FUNCTION__ ": Loading (%s): Starting",(LPCTSTR)PluginFile);
m_Control = new CControl_Plugin(PluginFile);
WriteTrace(TraceDebug,__FUNCTION__ ": Loading Done");
g_Settings->SaveString(Plugin_CONT_CurVer,m_Control->PluginName().c_str());
}
/* Reset(PLUGIN_TYPE_GFX);
Reset(PLUGIN_TYPE_AUDIO);
Reset(PLUGIN_TYPE_RSP);
Reset(PLUGIN_TYPE_CONTROLLER);
Reset(PLUGIN_TYPE_CONTROLLER); */
if (bHaveDebugger())
{
@ -88,49 +145,69 @@ void CPlugins::GameReset ( void )
if (m_Control) {
m_Control->GameReset();
}
}
void CPlugins::ShutDownPlugins( void ) {
if (m_Gfx) {
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Close - Starting");
m_Gfx->Close();
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Close - Done");
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": deconstructor - Starting");
delete m_Gfx;
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": deconstructor -Done");
m_Gfx = NULL;
void CPlugins::DestroyGfxPlugin( void )
{
if (m_Gfx == NULL)
{
return;
}
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": before delete m_Gfx");
delete m_Gfx;
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": after delete m_Gfx");
m_Gfx = NULL;
// g_Settings->UnknownSetting_GFX = NULL;
DestroyRspPlugin();
}
void CPlugins::DestroyAudioPlugin( void )
{
if (m_Audio == NULL)
{
return;
}
if (m_Audio) {
WriteTrace(TraceDebug,__FUNCTION__ ": 5");
m_Audio->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 6");
delete m_Audio;
WriteTrace(TraceDebug,__FUNCTION__ ": 7");
m_Audio = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 8");
WriteTrace(TraceDebug,__FUNCTION__ ": 5");
m_Audio->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 6");
delete m_Audio;
WriteTrace(TraceDebug,__FUNCTION__ ": 7");
m_Audio = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 8");
// g_Settings->UnknownSetting_AUDIO = NULL;
DestroyRspPlugin();
}
void CPlugins::DestroyRspPlugin( void )
{
if (m_RSP == NULL)
{
return;
}
if (m_RSP) {
WriteTrace(TraceDebug,__FUNCTION__ ": 9");
m_RSP->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 10");
delete m_RSP;
WriteTrace(TraceDebug,__FUNCTION__ ": 11");
m_RSP = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 12");
WriteTrace(TraceDebug,__FUNCTION__ ": 9");
m_RSP->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 10");
delete m_RSP;
WriteTrace(TraceDebug,__FUNCTION__ ": 11");
m_RSP = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 12");
// g_Settings->UnknownSetting_RSP = NULL;
}
void CPlugins::DestroyControlPlugin( void )
{
if (m_Control == NULL)
{
return;
}
if (m_Control) {
WriteTrace(TraceDebug,__FUNCTION__ ": 13");
m_Control->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 14");
delete m_Control;
WriteTrace(TraceDebug,__FUNCTION__ ": 15");
m_Control = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 16");
WriteTrace(TraceDebug,__FUNCTION__ ": 13");
m_Control->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 14");
delete m_Control;
WriteTrace(TraceDebug,__FUNCTION__ ": 15");
m_Control = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 16");
// g_Settings->UnknownSetting_CTRL = NULL;
}
}
void CPlugins::SetRenderWindows( CMainGui * RenderWindow, CMainGui * DummyWindow )
@ -139,58 +216,59 @@ void CPlugins::SetRenderWindows( CMainGui * RenderWindow, CMainGui * DummyWindow
m_DummyWindow = DummyWindow;
}
bool CPlugins::Initiate ( void )
void CPlugins::RomOpened ( void )
{
bool bResult = m_RenderWindow->InitiatePlugins();
if (bResult)
{
m_Gfx->RomOpened();
m_Audio->RomOpened();
m_Control->RomOpened();
}
return bResult;
m_Gfx->RomOpened();
m_Audio->RomOpened();
m_Control->RomOpened();
}
bool CPlugins::InitiateMainThread( void )
void CPlugins::RomClosed ( void )
{
m_Gfx->RomClose();
m_Audio->RomClose();
m_Control->RomClose();
}
bool CPlugins::Initiate ( CN64System * System )
{
WriteTrace(TraceDebug,__FUNCTION__ ": Start");
//Check to make sure we have the plugin avaliable to be used
//Check to make sure we have the plugin available to be used
if (m_Gfx == NULL) { return false; }
if (m_Audio == NULL) { return false; }
if (m_RSP == NULL) { return false; }
if (m_Control == NULL) { return false; }
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Close Starting");
m_Gfx->Close();
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Close Done");
WriteTrace(TraceDebug,__FUNCTION__ ": 3");
m_Audio->Close();
WriteTrace(TraceRSP,__FUNCTION__ ": Rsp Close starting");
m_RSP->Close();
WriteTrace(TraceRSP,__FUNCTION__ ": Rsp Close done");
m_Control->Close();
WriteTrace(TraceDebug,__FUNCTION__ " 6");
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Initiate Starting");
if (!m_Gfx->Initiate(g_System,m_RenderWindow)) { return false; }
if (!m_Gfx->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Initiate Done");
WriteTrace(TraceDebug,__FUNCTION__ ": 7");
if (!m_Audio->Initiate(g_System,m_RenderWindow)) { return false; }
WriteTrace(TraceDebug,__FUNCTION__ ": 8");
if (!m_Control->Initiate(g_System,m_RenderWindow)) { return false; }
WriteTrace(TraceRSP,__FUNCTION__ ": 9");
if (!m_RSP->Initiate(this,g_System)) { return false; }
WriteTrace(TraceRSP,__FUNCTION__ ": 10");
WriteTrace(TraceDebug,__FUNCTION__ ": Audio Initiate Starting");
if (!m_Audio->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceDebug,__FUNCTION__ ": Audio Initiate Done");
if (!m_Control->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Initiate Starting");
if (!m_RSP->Initiate(this,System)) { return false; }
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Initiate Done");
WriteTrace(TraceDebug,__FUNCTION__ ": Done");
return true;
}
void CPlugins::Reset ( void ) {
ShutDownPlugins();
void CPlugins::Reset ( void )
{
bool bGfxChange = _stricmp(m_GfxFile.c_str(),g_Settings->LoadString(Game_Plugin_Gfx).c_str()) != 0;
bool bAudioChange = _stricmp(m_AudioFile.c_str(),g_Settings->LoadString(Game_Plugin_Audio).c_str()) != 0;
bool bRspChange = _stricmp(m_RSPFile.c_str(),g_Settings->LoadString(Game_Plugin_RSP).c_str()) != 0;
bool bContChange = _stricmp(m_ControlFile.c_str(),g_Settings->LoadString(Game_Plugin_Controller).c_str()) != 0;
if (bGfxChange) { DestroyGfxPlugin(); }
if (bAudioChange) { DestroyAudioPlugin(); }
if (bRspChange) { DestroyRspPlugin(); }
if (bContChange) { DestroyControlPlugin(); }
CreatePlugins();
}
void CPlugins::Reset ( PLUGIN_TYPE Type )
/*void CPlugins::Reset ( PLUGIN_TYPE Type )
{
switch (Type)
{
@ -284,7 +362,7 @@ void CPlugins::Reset ( PLUGIN_TYPE Type )
}
break;
}
}
}*/
void CPlugins::ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ) {
switch (Type) {

View File

@ -85,15 +85,14 @@ public:
CPlugins (const stdstr & PluginDir );
~CPlugins ();
bool Initiate ( void );
bool InitiateMainThread ( void );
bool Initiate ( CN64System * System );
void RomOpened ( void );
void RomClosed ( void );
void SetRenderWindows ( CMainGui * RenderWindow, CMainGui * DummyWindow );
void ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type );
bool CopyPlugins ( const stdstr & DstDir ) const;
void Reset ( void );
void Reset ( PLUGIN_TYPE Type );
void GameReset ( void );
void ShutDownPlugins ( void );
inline CGfxPlugin * Gfx ( void) const { return m_Gfx; };
inline CAudioPlugin * Audio ( void) const { return m_Audio; };
@ -105,9 +104,16 @@ private:
CPlugins(const CPlugins&); // Disable copy constructor
CPlugins& operator=(const CPlugins&); // Disable assignment
// void Reset ( PLUGIN_TYPE Type );
void CreatePlugins ( void );
void CreatePluginDir ( const stdstr & DstDir ) const;
void DestroyGfxPlugin ( void );
void DestroyAudioPlugin ( void );
void DestroyRspPlugin ( void );
void DestroyControlPlugin ( void );
static void PluginChanged ( CPlugins * _this );
//Common Classes

View File

@ -39,6 +39,7 @@ bool CMainGui::RegisterWinClass ( void ) {
CMainGui::CMainGui (bool bMainWindow, const char * WindowTitle ) :
CRomBrowser(m_hMainWindow,m_hStatusWnd),
m_ThreadId(GetCurrentThreadId()),
m_bMainWindow(bMainWindow)
{
m_hacked = false;
@ -271,7 +272,19 @@ DWORD CALLBACK AboutIniBoxProc (WND_HANDLE WndHandle, DWORD uMsg, DWORD wParam,
bool CMainGui::InitiatePlugins (void)
{
return SendMessage((HWND)m_hMainWindow,WM_INIATE_PLUGIN,0,0) != 0;
/*HANDLE hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
bool bRes = true;
if (hEvent)
{
PostMessage((HWND)m_hMainWindow,WM_INIATE_PLUGIN,(WPARAM)&bRes,(LPARAM)hEvent);
DWORD dwRes = WaitForSingleObject(hEvent,5000);
CloseHandle(hEvent);
} else {
WriteTrace(TraceError,__FUNCTION__ ": Failed to create event");
bRes = false;
}
return bRes;*/
return false;
}
void CMainGui::BringToTop (void) {
@ -419,7 +432,12 @@ void CMainGui::SetStatusText (int Panel,const char * Text) {
memset(Msg,0,sizeof(Message[0]));
_snprintf(Msg,sizeof(Message[0]),"%s",Text);
Msg[sizeof(Message[0]) - 1] = 0;
PostMessage( (HWND)m_hStatusWnd, SB_SETTEXT, Panel, (LPARAM)Msg );
if (GetCurrentThreadId() == m_ThreadId)
{
SendMessage( (HWND)m_hStatusWnd, SB_SETTEXT, Panel, (LPARAM)Msg );
} else {
PostMessage( (HWND)m_hStatusWnd, SB_SETTEXT, Panel, (LPARAM)Msg );
}
}
void CMainGui::ShowStatusBar ( bool ShowBar )
@ -734,11 +752,15 @@ DWORD CALLBACK CMainGui::MainGui_Proc (WND_HANDLE hWnd, DWORD uMsg, DWORD wParam
_this->RomBrowserToTop();
}
break;
case WM_INIATE_PLUGIN:
/*case WM_INIATE_PLUGIN:
{
return g_Plugins->InitiateMainThread();
bool * bRes = (bool *)wParam;
HANDLE hEvent = (HANDLE)lParam;
*bRes = g_Plugins->InitiateMainThread();
SetEvent(hEvent);
}
break;
break;*/
case WM_COMMAND:
{
CMainGui * _this = (CMainGui *)GetProp((HWND)hWnd,"Class");

View File

@ -21,7 +21,7 @@ class CriticalSection;
enum {
WM_HIDE_CUROSR = WM_USER + 10,
WM_MAKE_FOCUS = WM_USER + 17,
WM_INIATE_PLUGIN = WM_USER + 18,
//WM_INIATE_PLUGIN = WM_USER + 18,
WM_BORWSER_TOP = WM_USER + 40,
};
@ -29,41 +29,7 @@ class CMainGui :
public CRomBrowser,
private CGuiSettings
{
friend CGfxPlugin;
friend CAudioPlugin;
friend CControl_Plugin;
CBaseMenu * m_Menu;
enum { StatusBarID = 400 };
WND_HANDLE m_hMainWindow, m_hStatusWnd;
bool m_hacked;
const bool m_bMainWindow;
DWORD m_InvalidExeMsg;
CriticalSection m_CS;
bool m_SaveMainWindowPos;
LONG m_SaveMainWindowTop;
LONG m_SaveMainWindowLeft;
bool m_SaveRomBrowserPos;
LONG m_SaveRomBrowserTop;
LONG m_SaveRomBrowserLeft;
bool RegisterWinClass ( void );
void ChangeWinSize ( long width, long height );
void Create ( const char * WindowTitle );
void CreateStatusBar ( void );
void Resize ( DWORD fwSizeType, WORD nWidth, WORD nHeight ); //responding to WM_SIZE
friend DWORD CALLBACK AboutBoxProc ( HWND, DWORD, DWORD, DWORD );
friend DWORD CALLBACK AboutIniBoxProc ( WND_HANDLE, DWORD, DWORD, DWORD );
static DWORD CALLBACK MainGui_Proc ( WND_HANDLE, DWORD, DWORD, DWORD );
friend void RomBowserEnabledChanged (CMainGui * Gui);
friend void RomBowserColoumnsChanged (CMainGui * Gui);
friend void RomBrowserRecursiveChanged (CMainGui * Gui);
public:
CMainGui ( bool bMainWindow, const char * WindowTitle = "" );
@ -107,4 +73,44 @@ public:
//Get Window Handle
inline WND_HANDLE GetHandle ( void ) const { return m_hMainWindow; }
private:
CMainGui(void); // Disable default constructor
CMainGui(const CMainGui&); // Disable copy constructor
CMainGui& operator=(const CMainGui&); // Disable assignment
friend CGfxPlugin;
friend CAudioPlugin;
friend CControl_Plugin;
bool RegisterWinClass ( void );
void ChangeWinSize ( long width, long height );
void Create ( const char * WindowTitle );
void CreateStatusBar ( void );
void Resize ( DWORD fwSizeType, WORD nWidth, WORD nHeight ); //responding to WM_SIZE
friend DWORD CALLBACK AboutBoxProc ( HWND, DWORD, DWORD, DWORD );
friend DWORD CALLBACK AboutIniBoxProc ( WND_HANDLE, DWORD, DWORD, DWORD );
static DWORD CALLBACK MainGui_Proc ( WND_HANDLE, DWORD, DWORD, DWORD );
friend void RomBowserEnabledChanged (CMainGui * Gui);
friend void RomBowserColoumnsChanged (CMainGui * Gui);
friend void RomBrowserRecursiveChanged (CMainGui * Gui);
CBaseMenu * m_Menu;
WND_HANDLE m_hMainWindow, m_hStatusWnd;
DWORD m_ThreadId;
bool m_hacked;
const bool m_bMainWindow;
DWORD m_InvalidExeMsg;
CriticalSection m_CS;
bool m_SaveMainWindowPos;
LONG m_SaveMainWindowTop;
LONG m_SaveMainWindowLeft;
bool m_SaveRomBrowserPos;
LONG m_SaveRomBrowserTop;
LONG m_SaveRomBrowserLeft;
};

View File

@ -81,7 +81,7 @@ bool CMainMenu::ProcessMessage(WND_HANDLE hWnd, DWORD /*FromAccelerator*/, DWORD
break;
case ID_FILE_ENDEMULATION:
WriteTrace(TraceDebug,__FUNCTION__ ": ID_FILE_ENDEMULATION");
g_BaseSystem->CloseCpu();
CN64System::CloseSystem();
_Gui->SaveWindowLoc();
break;
case ID_FILE_ROMDIRECTORY:

View File

@ -8,14 +8,16 @@ CNotification & Notify ( void )
}
CNotification::CNotification ( ) :
m_NextMsg(0), _gfxPlugin(NULL)
m_NextMsg(0),
m_gfxPlugin(NULL),
m_hWnd(NULL)
{
_hWnd = NULL;
_tzset();
}
void CNotification::SetMainWindow ( CMainGui * Gui ) {
_hWnd = Gui;
void CNotification::SetMainWindow ( CMainGui * Gui )
{
m_hWnd = Gui;
}
void CNotification::WindowMode ( void ) const
@ -58,18 +60,20 @@ void CNotification::DisplayError ( const char * Message, va_list ap ) const {
WindowMode();
HWND Parent = NULL;
if (_hWnd) { Parent = reinterpret_cast<HWND>(_hWnd->GetHandle()); }
if (m_hWnd) { Parent = reinterpret_cast<HWND>(m_hWnd->GetHandle()); }
MessageBox(Parent,Msg,GS(MSG_MSGBOX_TITLE),MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
}
void CNotification::DisplayMessage ( int DisplayTime, const char * Message, ... ) const {
void CNotification::DisplayMessage ( int DisplayTime, const char * Message, ... ) const
{
va_list ap;
va_start( ap, Message );
DisplayMessage (DisplayTime, Message,ap);
}
void CNotification::DisplayMessage ( int DisplayTime, const char * Message, va_list ap ) const {
if (!_hWnd) { return; }
void CNotification::DisplayMessage ( int DisplayTime, const char * Message, va_list ap ) const
{
if (!m_hWnd) { return; }
if (m_NextMsg > 0 || DisplayTime > 0)
{
@ -96,14 +100,14 @@ void CNotification::DisplayMessage ( int DisplayTime, const char * Message, va_
if (InFullScreen())
{
if (_gfxPlugin && _gfxPlugin->DrawStatus)
if (m_gfxPlugin && m_gfxPlugin->DrawStatus)
{
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": DrawStatus - Starting");
_gfxPlugin->DrawStatus(Msg,FALSE);
m_gfxPlugin->DrawStatus(Msg,FALSE);
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": DrawStatus - Done");
}
} else {
_hWnd->SetStatusText(0,Msg);
m_hWnd->SetStatusText(0,Msg);
}
}
@ -114,25 +118,25 @@ void CNotification::DisplayMessage2 ( const char * Message, ... ) const {
}
void CNotification::DisplayMessage2 ( const char * Message, va_list ap ) const {
if (!_hWnd) { return; }
if (!m_hWnd) { return; }
char Msg[1000];
_vsnprintf( Msg,sizeof(Msg) - 1 ,Message, ap );
va_end( ap );
_hWnd->SetStatusText(1,Msg);
m_hWnd->SetStatusText(1,Msg);
}
void CNotification::SetGfxPlugin( CGfxPlugin * Plugin )
{
_gfxPlugin = Plugin;
m_gfxPlugin = Plugin;
}
void CNotification::SetWindowCaption (const char * Caption) {
char WinTitle[256];
_snprintf( WinTitle, sizeof(WinTitle), "%s - %s", Caption, g_Settings->LoadString(Setting_ApplicationName).c_str());
WinTitle[sizeof(WinTitle) - 1] = 0;
_hWnd->Caption(WinTitle);
m_hWnd->Caption(WinTitle);
}
void CNotification::FatalError ( const char * Message, ... ) const {
@ -145,7 +149,7 @@ void CNotification::FatalError ( const char * Message, ... ) const {
_vsnprintf( Msg,sizeof(Msg) - 1,Message, ap );
va_end( ap );
HWND Parent = NULL;
if (_hWnd) { Parent = reinterpret_cast<HWND>(_hWnd->GetHandle()); }
if (m_hWnd) { Parent = reinterpret_cast<HWND>(m_hWnd->GetHandle()); }
MessageBox(Parent,Msg,"Error",MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
ExitThread(0);
}
@ -232,44 +236,44 @@ void CNotification::AddRecentRom ( const char * ImagePath ) {
}
void CNotification::RefreshMenu ( void ) {
if (_hWnd == NULL) { return; }
_hWnd->RefreshMenu();
if (m_hWnd == NULL) { return; }
m_hWnd->RefreshMenu();
}
void CNotification::HideRomBrowser ( void ) {
if (_hWnd == NULL) { return; }
_hWnd->HideRomList();
if (m_hWnd == NULL) { return; }
m_hWnd->HideRomList();
}
void CNotification::ShowRomBrowser ( void ) {
if (_hWnd == NULL) { return; }
if (m_hWnd == NULL) { return; }
if (g_Settings->LoadDword(RomBrowser_Enabled)) {
//Display the rom browser
_hWnd->ShowRomList();
_hWnd->HighLightLastRom();
m_hWnd->ShowRomList();
m_hWnd->HighLightLastRom();
}
}
void CNotification::BringToTop ( void ) {
if (_hWnd == NULL) { return; }
_hWnd->BringToTop();
if (m_hWnd == NULL) { return; }
m_hWnd->BringToTop();
}
void CNotification::MakeWindowOnTop ( bool OnTop ) {
if (_hWnd == NULL) { return; }
_hWnd->MakeWindowOnTop(OnTop);
if (m_hWnd == NULL) { return; }
m_hWnd->MakeWindowOnTop(OnTop);
}
void CNotification::ChangeFullScreen ( void ) const
{
if (_hWnd == NULL) { return; }
SendMessage((HWND)(_hWnd->GetHandle()),WM_COMMAND,MAKELPARAM(ID_OPTIONS_FULLSCREEN2,false),0);
if (m_hWnd == NULL) { return; }
SendMessage((HWND)(m_hWnd->GetHandle()),WM_COMMAND,MAKELPARAM(ID_OPTIONS_FULLSCREEN2,false),0);
}
bool CNotification::ProcessGuiMessages ( void ) const
{
if (_hWnd == NULL) { return false; }
return _hWnd->ProcessGuiMessages();
if (m_hWnd == NULL) { return false; }
return m_hWnd->ProcessGuiMessages();
}
void CNotification::BreakPoint ( const char * File, const int LineNumber )

View File

@ -17,11 +17,6 @@ class CSettings;
class CNotification :
CNotificationSettings
{
CMainGui * _hWnd;
CGfxPlugin * _gfxPlugin;
mutable time_t m_NextMsg;
public:
CNotification ( void );
@ -63,6 +58,15 @@ public:
bool ProcessGuiMessages ( void ) const;
void ChangeFullScreen ( void ) const;
void SetGfxPlugin ( CGfxPlugin * Plugin );
private:
CNotification(const CNotification&); // Disable copy constructor
CNotification& operator=(const CNotification&); // Disable assignment
CMainGui * m_hWnd;
CGfxPlugin * m_gfxPlugin;
mutable time_t m_NextMsg;
};
CNotification & Notify ( void );

View File

@ -1337,7 +1337,7 @@ void CRomBrowser::RomList_OpenRom(DWORD /*pnmh*/) {
if (!pRomInfo) { return; }
m_StopRefresh = true;
g_BaseSystem->RunFileImage(pRomInfo->szFullFileName);
CN64System::RunFileImage(pRomInfo->szFullFileName);
}
void CRomBrowser::RomList_PopupMenu(DWORD /*pnmh*/)