Plugin: Add rom open and clean up rsp plugin handling

This commit is contained in:
zilmar 2013-02-11 19:27:00 +11:00
parent 05e4f22dcf
commit 229be28668
3 changed files with 156 additions and 109 deletions

View File

@ -219,6 +219,7 @@ void CPlugins::SetRenderWindows( CMainGui * RenderWindow, CMainGui * DummyWindow
void CPlugins::RomOpened ( void ) void CPlugins::RomOpened ( void )
{ {
m_Gfx->RomOpened(); m_Gfx->RomOpened();
m_RSP->RomOpened();
m_Audio->RomOpened(); m_Audio->RomOpened();
m_Control->RomOpened(); m_Control->RomOpened();
} }
@ -226,6 +227,7 @@ void CPlugins::RomOpened ( void )
void CPlugins::RomClosed ( void ) void CPlugins::RomClosed ( void )
{ {
m_Gfx->RomClose(); m_Gfx->RomClose();
m_RSP->RomClose();
m_Audio->RomClose(); m_Audio->RomClose();
m_Control->RomClose(); m_Control->RomClose();
} }

View File

@ -13,28 +13,44 @@
void FixUPXIssue ( BYTE * ProgramLocation ); void FixUPXIssue ( BYTE * ProgramLocation );
void DummyFunc1 ( BOOL /*a*/) {} void DummyFunc1 ( BOOL /*a*/) {}
CRSP_Plugin::CRSP_Plugin ( const char * FileName) { CRSP_Plugin::CRSP_Plugin ( const char * FileName) :
//Make sure all parts of the class are initialized Config(NULL),
m_Initilized = false; DoRspCycles(NULL),
m_RomOpen = false; EnableDebugging(NULL),
hDll = NULL; CloseDLL(NULL),
CycleCount = NULL; RomOpen(NULL),
UnloadPlugin(); RomClosed(NULL),
GetDebugInfo(NULL),
InitiateDebugger(NULL),
PluginOpened(NULL),
SetSettingInfo(NULL),
SetSettingInfo2(NULL),
m_hDll(NULL),
m_Initilized(false),
m_RomOpen(false),
m_CycleCount(0)
{
memset(&m_RSPDebug,0,sizeof(m_RSPDebug));
memset(&m_PluginInfo,0,sizeof(m_PluginInfo));
Init(FileName);
}
void CRSP_Plugin::Init ( const char * FileName )
{
//Try to load the DLL library //Try to load the DLL library
UINT LastErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS ); UINT LastErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
hDll = LoadLibrary(FileName); m_hDll = LoadLibrary(FileName);
SetErrorMode(LastErrorMode); SetErrorMode(LastErrorMode);
if (hDll == NULL) { if (m_hDll == NULL) {
UnloadPlugin(); UnloadPlugin();
return; return;
} }
FixUPXIssue((BYTE *)hDll); FixUPXIssue((BYTE *)m_hDll);
//Get DLL information //Get DLL information
void (__cdecl *GetDllInfo) ( PLUGIN_INFO * PluginInfo ); void (__cdecl *GetDllInfo) ( PLUGIN_INFO * PluginInfo );
GetDllInfo = (void (__cdecl *)(PLUGIN_INFO *))GetProcAddress( (HMODULE)hDll, "GetDllInfo" ); GetDllInfo = (void (__cdecl *)(PLUGIN_INFO *))GetProcAddress( (HMODULE)m_hDll, "GetDllInfo" );
if (GetDllInfo == NULL) { UnloadPlugin(); return; } if (GetDllInfo == NULL) { UnloadPlugin(); return; }
GetDllInfo(&m_PluginInfo); GetDllInfo(&m_PluginInfo);
@ -42,18 +58,19 @@ CRSP_Plugin::CRSP_Plugin ( const char * FileName) {
//Find entries for functions in DLL //Find entries for functions in DLL
void (__cdecl *InitFunc)( void ); void (__cdecl *InitFunc)( void );
DoRspCycles = (DWORD (__cdecl *)(DWORD))GetProcAddress( (HMODULE)hDll, "DoRspCycles" ); DoRspCycles = (DWORD (__cdecl *)(DWORD))GetProcAddress( (HMODULE)m_hDll, "DoRspCycles" );
InitFunc = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)hDll, "InitiateRSP" ); InitFunc = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "InitiateRSP" );
RomClosed = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)hDll, "RomClosed" ); RomClosed = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomClosed" );
CloseDLL = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)hDll, "CloseDLL" ); RomOpen = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomOpen" );
Config = (void (__cdecl *)(DWORD)) GetProcAddress( (HMODULE)hDll, "DllConfig" ); CloseDLL = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "CloseDLL" );
GetDebugInfo = (void (__cdecl *)(RSPDEBUG_INFO *))GetProcAddress( (HMODULE)hDll, "GetRspDebugInfo" ); Config = (void (__cdecl *)(DWORD)) GetProcAddress( (HMODULE)m_hDll, "DllConfig" );
InitiateDebugger = (void (__cdecl *)(DEBUG_INFO))GetProcAddress( (HMODULE)hDll, "InitiateRSPDebugger" ); GetDebugInfo = (void (__cdecl *)(RSPDEBUG_INFO *))GetProcAddress( (HMODULE)m_hDll, "GetRspDebugInfo" );
EnableDebugging = (void (__cdecl *)(BOOL))GetProcAddress( (HMODULE)hDll, "EnableDebugging" ); InitiateDebugger = (void (__cdecl *)(DEBUG_INFO))GetProcAddress( (HMODULE)m_hDll, "InitiateRSPDebugger" );
EnableDebugging = (void (__cdecl *)(BOOL))GetProcAddress( (HMODULE)m_hDll, "EnableDebugging" );
if (EnableDebugging == NULL) { EnableDebugging = DummyFunc1; } if (EnableDebugging == NULL) { EnableDebugging = DummyFunc1; }
//version 102 functions //version 102 functions
PluginOpened = (void (__cdecl *)(void))GetProcAddress( (HMODULE)hDll, "PluginLoaded" ); PluginOpened = (void (__cdecl *)(void))GetProcAddress( (HMODULE)m_hDll, "PluginLoaded" );
//Make sure dll had all needed functions //Make sure dll had all needed functions
if (DoRspCycles == NULL) { UnloadPlugin(); return; } if (DoRspCycles == NULL) { UnloadPlugin(); return; }
@ -61,7 +78,7 @@ CRSP_Plugin::CRSP_Plugin ( const char * FileName) {
if (RomClosed == NULL) { UnloadPlugin(); return; } if (RomClosed == NULL) { UnloadPlugin(); return; }
if (CloseDLL == NULL) { UnloadPlugin(); return; } if (CloseDLL == NULL) { UnloadPlugin(); return; }
SetSettingInfo2 = (void (__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress( (HMODULE)hDll, "SetSettingInfo2" ); SetSettingInfo2 = (void (__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo2" );
if (SetSettingInfo2) if (SetSettingInfo2)
{ {
PLUGIN_SETTINGS2 info; PLUGIN_SETTINGS2 info;
@ -69,7 +86,7 @@ CRSP_Plugin::CRSP_Plugin ( const char * FileName) {
SetSettingInfo2(&info); SetSettingInfo2(&info);
} }
SetSettingInfo = (void (__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress( (HMODULE)hDll, "SetSettingInfo" ); SetSettingInfo = (void (__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo" );
if (SetSettingInfo) if (SetSettingInfo)
{ {
PLUGIN_SETTINGS info; PLUGIN_SETTINGS info;
@ -108,31 +125,11 @@ CRSP_Plugin::~CRSP_Plugin (void) {
UnloadPlugin(); UnloadPlugin();
} }
void CRSP_Plugin::Close(void) {
if (m_RomOpen) {
RomClosed();
m_RomOpen = false;
}
if (m_Initilized) {
CloseDLL();
m_Initilized = false;
}
}
void CRSP_Plugin::GameReset(void)
{
if (m_RomOpen)
{
RomClosed();
//RomOpen();
}
}
bool CRSP_Plugin::Initiate ( CPlugins * Plugins, CN64System * System ) bool CRSP_Plugin::Initiate ( CPlugins * Plugins, CN64System * System )
{ {
//Get DLL information //Get DLL information
void (__cdecl *GetDllInfo) ( PLUGIN_INFO * PluginInfo ); void (__cdecl *GetDllInfo) ( PLUGIN_INFO * PluginInfo );
GetDllInfo = (void (__cdecl *)(PLUGIN_INFO *))GetProcAddress( (HMODULE)hDll, "GetDllInfo" ); GetDllInfo = (void (__cdecl *)(PLUGIN_INFO *))GetProcAddress( (HMODULE)m_hDll, "GetDllInfo" );
if (GetDllInfo == NULL) { return false; } if (GetDllInfo == NULL) { return false; }
PLUGIN_INFO PluginInfo; PLUGIN_INFO PluginInfo;
@ -181,7 +178,7 @@ bool CRSP_Plugin::Initiate ( CPlugins * Plugins, CN64System * System )
//Get Function from DLL //Get Function from DLL
void (__cdecl *InitiateRSP) ( RSP_INFO_1_1 Audio_Info,DWORD * Cycles ); void (__cdecl *InitiateRSP) ( RSP_INFO_1_1 Audio_Info,DWORD * Cycles );
InitiateRSP = (void (__cdecl *)(RSP_INFO_1_1,DWORD *))GetProcAddress( (HMODULE)hDll, "InitiateRSP" ); InitiateRSP = (void (__cdecl *)(RSP_INFO_1_1,DWORD *))GetProcAddress( (HMODULE)m_hDll, "InitiateRSP" );
if (InitiateRSP == NULL) { return false; } if (InitiateRSP == NULL) { return false; }
RSP_INFO_1_1 Info; RSP_INFO_1_1 Info;
@ -227,7 +224,7 @@ bool CRSP_Plugin::Initiate ( CPlugins * Plugins, CN64System * System )
Info.DPC__PIPEBUSY_REG = &Value; Info.DPC__PIPEBUSY_REG = &Value;
Info.DPC__TMEM_REG = &Value; Info.DPC__TMEM_REG = &Value;
InitiateRSP(Info,&CycleCount); InitiateRSP(Info,&m_CycleCount);
m_Initilized = TRUE; m_Initilized = TRUE;
//jabo had a bug so I call CreateThread so his dllmain gets called again //jabo had a bug so I call CreateThread so his dllmain gets called again
DWORD ThreadID; DWORD ThreadID;
@ -271,25 +268,63 @@ bool CRSP_Plugin::Initiate ( CPlugins * Plugins, CN64System * System )
Info.DPC__PIPEBUSY_REG = &g_Reg->DPC_PIPEBUSY_REG; Info.DPC__PIPEBUSY_REG = &g_Reg->DPC_PIPEBUSY_REG;
Info.DPC__TMEM_REG = &g_Reg->DPC_TMEM_REG; Info.DPC__TMEM_REG = &g_Reg->DPC_TMEM_REG;
InitiateRSP(Info,&CycleCount); InitiateRSP(Info,&m_CycleCount);
m_Initilized = true; m_Initilized = true;
//jabo had a bug so I call CreateThread so his dllmain gets called again //jabo had a bug so I call CreateThread so his dllmain gets called again
DWORD ThreadID; DWORD ThreadID;
HANDLE hthread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)DummyFunction,NULL,0, &ThreadID); HANDLE hthread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)DummyFunction,NULL,0, &ThreadID);
CloseHandle(hthread); CloseHandle(hthread);
//Real system ... then make the file as open
//RomOpen();
m_RomOpen = true;
return m_Initilized; return m_Initilized;
} }
void CRSP_Plugin::Close(void) {
if (m_RomOpen)
{
RomClose();
}
if (m_Initilized)
{
CloseDLL();
m_Initilized = false;
}
}
void CRSP_Plugin::RomOpened ( void )
{
//Real system ... then make the file as open
if (!m_RomOpen)
{
if (RomOpen)
{
RomOpen();
}
m_RomOpen = true;
}
}
void CRSP_Plugin::RomClose ( void )
{
if (m_RomOpen)
{
RomClosed();
m_RomOpen = false;
}
}
void CRSP_Plugin::GameReset(void)
{
if (m_RomOpen)
{
RomClose();
RomOpened();
}
}
void CRSP_Plugin::UnloadPlugin(void) { void CRSP_Plugin::UnloadPlugin(void) {
if (hDll != NULL ) { if (m_hDll != NULL ) {
FreeLibrary((HMODULE)hDll); FreeLibrary((HMODULE)m_hDll);
hDll = NULL; m_hDll = NULL;
} }
memset(&m_RSPDebug,0,sizeof(m_RSPDebug)); memset(&m_RSPDebug,0,sizeof(m_RSPDebug));
memset(&m_PluginInfo,0,sizeof(m_PluginInfo)); memset(&m_PluginInfo,0,sizeof(m_PluginInfo));
@ -304,3 +339,10 @@ void CRSP_Plugin::UnloadPlugin(void) {
InitiateDebugger = NULL; InitiateDebugger = NULL;
} }
void CRSP_Plugin::ProcessMenuItem (int id )
{
if (m_RSPDebug.ProcessMenuItem)
{
m_RSPDebug.ProcessMenuItem(id);
}
}

View File

@ -10,56 +10,40 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
class CRSP_Plugin { class CRSP_Plugin
typedef struct { {
/* Menu */ typedef struct {
/* Items should have an ID between 5001 and 5100 */ /* Menu */
MENU_HANDLE hRSPMenu; /* Items should have an ID between 5001 and 5100 */
void (__cdecl *ProcessMenuItem) ( int ID ); MENU_HANDLE hRSPMenu;
void (__cdecl *ProcessMenuItem) ( int ID );
/* Break Points */ /* Break Points */
BOOL UseBPoints; BOOL UseBPoints;
char BPPanelName[20]; char BPPanelName[20];
void (__cdecl *Add_BPoint) ( void ); void (__cdecl *Add_BPoint) ( void );
void (__cdecl *CreateBPPanel) ( MENU_HANDLE hDlg, RECT_STRUCT rcBox ); void (__cdecl *CreateBPPanel) ( MENU_HANDLE hDlg, RECT_STRUCT rcBox );
void (__cdecl *HideBPPanel) ( void ); void (__cdecl *HideBPPanel) ( void );
void (__cdecl *PaintBPPanel) ( WINDOWS_PAINTSTRUCT ps ); void (__cdecl *PaintBPPanel) ( WINDOWS_PAINTSTRUCT ps );
void (__cdecl *ShowBPPanel) ( void ); void (__cdecl *ShowBPPanel) ( void );
void (__cdecl *RefreshBpoints) ( MENU_HANDLE hList ); void (__cdecl *RefreshBpoints) ( MENU_HANDLE hList );
void (__cdecl *RemoveBpoint) ( MENU_HANDLE hList, int index ); void (__cdecl *RemoveBpoint) ( MENU_HANDLE hList, int index );
void (__cdecl *RemoveAllBpoint) ( void ); void (__cdecl *RemoveAllBpoint) ( void );
/* RSP command Window */ /* RSP command Window */
void (__cdecl *Enter_RSP_Commands_Window) ( void ); void (__cdecl *Enter_RSP_Commands_Window) ( void );
} RSPDEBUG_INFO; } RSPDEBUG_INFO;
typedef struct { typedef struct {
void (__cdecl *UpdateBreakPoints)( void ); void (__cdecl *UpdateBreakPoints)( void );
void (__cdecl *UpdateMemory)( void ); void (__cdecl *UpdateMemory)( void );
void (__cdecl *UpdateR4300iRegisters)( void ); void (__cdecl *UpdateR4300iRegisters)( void );
void (__cdecl *Enter_BPoint_Window)( void ); void (__cdecl *Enter_BPoint_Window)( void );
void (__cdecl *Enter_R4300i_Commands_Window)( void ); void (__cdecl *Enter_R4300i_Commands_Window)( void );
void (__cdecl *Enter_R4300i_Register_Window)( void ); void (__cdecl *Enter_R4300i_Register_Window)( void );
void (__cdecl *Enter_RSP_Commands_Window) ( void ); void (__cdecl *Enter_RSP_Commands_Window) ( void );
void (__cdecl *Enter_Memory_Window)( void ); void (__cdecl *Enter_Memory_Window)( void );
} DEBUG_INFO; } DEBUG_INFO;
RSPDEBUG_INFO m_RSPDebug;
void * hDll;
bool m_Initilized, m_RomOpen;
DWORD CycleCount;
PLUGIN_INFO m_PluginInfo;
void UnloadPlugin ( void );
bool Initiate_1_0 ( CPlugins * Plugins, CN64System * System );
void (__cdecl *CloseDLL) ( void );
void (__cdecl *RomClosed) ( void );
void (__cdecl *GetDebugInfo) ( RSPDEBUG_INFO * GFXDebugInfo );
void (__cdecl *InitiateDebugger) ( DEBUG_INFO DebugInfo);
void (__cdecl *PluginOpened) ( void );
void (__cdecl *SetSettingInfo) ( PLUGIN_SETTINGS * info );
void (__cdecl *SetSettingInfo2) ( PLUGIN_SETTINGS2 * info );
public: public:
CRSP_Plugin ( const char * FileName); CRSP_Plugin ( const char * FileName);
@ -68,6 +52,8 @@ public:
bool Initiate ( CPlugins * Plugins, CN64System * System ); bool Initiate ( CPlugins * Plugins, CN64System * System );
bool Initilized ( void ) { return m_Initilized; } bool Initilized ( void ) { return m_Initilized; }
void Close ( void ); void Close ( void );
void RomOpened ( void );
void RomClose ( void );
void GameReset ( void ); void GameReset ( void );
stdstr PluginName ( void ) const { return m_PluginInfo.Name; } stdstr PluginName ( void ) const { return m_PluginInfo.Name; }
@ -76,12 +62,29 @@ public:
void (__cdecl *EnableDebugging) ( BOOL Enable ); void (__cdecl *EnableDebugging) ( BOOL Enable );
MENU_HANDLE GetDebugMenu (void ) { return m_RSPDebug.hRSPMenu; } MENU_HANDLE GetDebugMenu (void ) { return m_RSPDebug.hRSPMenu; }
void ProcessMenuItem (int id ) void ProcessMenuItem (int id );
{
if (m_RSPDebug.ProcessMenuItem)
{
m_RSPDebug.ProcessMenuItem(id);
}
}
private:
CRSP_Plugin(void); // Disable default constructor
CRSP_Plugin(const CRSP_Plugin&); // Disable copy constructor
CRSP_Plugin& operator=(const CRSP_Plugin&); // Disable assignment
void Init ( const char * FileName );
bool Initiate_1_0 ( CPlugins * Plugins, CN64System * System );
void UnloadPlugin ( void );
RSPDEBUG_INFO m_RSPDebug;
void * m_hDll;
bool m_Initilized, m_RomOpen;
DWORD m_CycleCount;
PLUGIN_INFO m_PluginInfo;
void (__cdecl *CloseDLL) ( void );
void (__cdecl *RomOpen) ( void );
void (__cdecl *RomClosed) ( void );
void (__cdecl *GetDebugInfo) ( RSPDEBUG_INFO * GFXDebugInfo );
void (__cdecl *InitiateDebugger) ( DEBUG_INFO DebugInfo);
void (__cdecl *PluginOpened) ( void );
void (__cdecl *SetSettingInfo) ( PLUGIN_SETTINGS * info );
void (__cdecl *SetSettingInfo2) ( PLUGIN_SETTINGS2 * info );
}; };