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 )
{
m_Gfx->RomOpened();
m_RSP->RomOpened();
m_Audio->RomOpened();
m_Control->RomOpened();
}
@ -226,6 +227,7 @@ void CPlugins::RomOpened ( void )
void CPlugins::RomClosed ( void )
{
m_Gfx->RomClose();
m_RSP->RomClose();
m_Audio->RomClose();
m_Control->RomClose();
}

View File

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

View File

@ -10,56 +10,40 @@
****************************************************************************/
#pragma once
class CRSP_Plugin {
typedef struct {
/* Menu */
/* Items should have an ID between 5001 and 5100 */
MENU_HANDLE hRSPMenu;
void (__cdecl *ProcessMenuItem) ( int ID );
class CRSP_Plugin
{
typedef struct {
/* Menu */
/* Items should have an ID between 5001 and 5100 */
MENU_HANDLE hRSPMenu;
void (__cdecl *ProcessMenuItem) ( int ID );
/* Break Points */
BOOL UseBPoints;
char BPPanelName[20];
void (__cdecl *Add_BPoint) ( void );
void (__cdecl *CreateBPPanel) ( MENU_HANDLE hDlg, RECT_STRUCT rcBox );
void (__cdecl *HideBPPanel) ( void );
void (__cdecl *PaintBPPanel) ( WINDOWS_PAINTSTRUCT ps );
void (__cdecl *ShowBPPanel) ( void );
void (__cdecl *RefreshBpoints) ( MENU_HANDLE hList );
void (__cdecl *RemoveBpoint) ( MENU_HANDLE hList, int index );
void (__cdecl *RemoveAllBpoint) ( void );
/* RSP command Window */
void (__cdecl *Enter_RSP_Commands_Window) ( void );
} RSPDEBUG_INFO;
/* Break Points */
BOOL UseBPoints;
char BPPanelName[20];
void (__cdecl *Add_BPoint) ( void );
void (__cdecl *CreateBPPanel) ( MENU_HANDLE hDlg, RECT_STRUCT rcBox );
void (__cdecl *HideBPPanel) ( void );
void (__cdecl *PaintBPPanel) ( WINDOWS_PAINTSTRUCT ps );
void (__cdecl *ShowBPPanel) ( void );
void (__cdecl *RefreshBpoints) ( MENU_HANDLE hList );
void (__cdecl *RemoveBpoint) ( MENU_HANDLE hList, int index );
void (__cdecl *RemoveAllBpoint) ( void );
/* RSP command Window */
void (__cdecl *Enter_RSP_Commands_Window) ( void );
} RSPDEBUG_INFO;
typedef struct {
void (__cdecl *UpdateBreakPoints)( void );
void (__cdecl *UpdateMemory)( void );
void (__cdecl *UpdateR4300iRegisters)( void );
void (__cdecl *Enter_BPoint_Window)( void );
void (__cdecl *Enter_R4300i_Commands_Window)( void );
void (__cdecl *Enter_R4300i_Register_Window)( void );
void (__cdecl *Enter_RSP_Commands_Window) ( void );
void (__cdecl *Enter_Memory_Window)( void );
} 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 );
typedef struct {
void (__cdecl *UpdateBreakPoints)( void );
void (__cdecl *UpdateMemory)( void );
void (__cdecl *UpdateR4300iRegisters)( void );
void (__cdecl *Enter_BPoint_Window)( void );
void (__cdecl *Enter_R4300i_Commands_Window)( void );
void (__cdecl *Enter_R4300i_Register_Window)( void );
void (__cdecl *Enter_RSP_Commands_Window) ( void );
void (__cdecl *Enter_Memory_Window)( void );
} DEBUG_INFO;
public:
CRSP_Plugin ( const char * FileName);
@ -68,6 +52,8 @@ public:
bool Initiate ( CPlugins * Plugins, CN64System * System );
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; }
@ -76,12 +62,29 @@ public:
void (__cdecl *EnableDebugging) ( BOOL Enable );
MENU_HANDLE GetDebugMenu (void ) { return m_RSPDebug.hRSPMenu; }
void ProcessMenuItem (int id )
{
if (m_RSPDebug.ProcessMenuItem)
{
m_RSPDebug.ProcessMenuItem(id);
}
}
void ProcessMenuItem (int 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 );
};