[Project64] Clean up plugin classes

This commit is contained in:
zilmar 2015-11-08 17:08:15 +11:00
parent 9f87dbf30d
commit 3b8e03b570
12 changed files with 1313 additions and 1256 deletions

View File

@ -11,177 +11,179 @@
#include "stdafx.h" #include "stdafx.h"
CAudioPlugin::CAudioPlugin() : CAudioPlugin::CAudioPlugin() :
AiLenChanged(NULL), AiLenChanged(NULL),
AiReadLength(NULL), AiReadLength(NULL),
ProcessAList(NULL), ProcessAList(NULL),
m_hAudioThread(NULL), m_hAudioThread(NULL),
AiUpdate(NULL), AiUpdate(NULL),
AiDacrateChanged(NULL) AiDacrateChanged(NULL)
{ {
} }
CAudioPlugin::~CAudioPlugin() CAudioPlugin::~CAudioPlugin()
{ {
Close(); Close();
UnloadPlugin(); UnloadPlugin();
} }
bool CAudioPlugin::LoadFunctions ( void ) bool CAudioPlugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
void (__cdecl *InitiateAudio) ( void ); void(__cdecl *InitiateAudio) (void);
LoadFunction(InitiateAudio); LoadFunction(InitiateAudio);
LoadFunction(AiDacrateChanged); LoadFunction(AiDacrateChanged);
LoadFunction(AiLenChanged); LoadFunction(AiLenChanged);
LoadFunction(AiReadLength); LoadFunction(AiReadLength);
LoadFunction(AiUpdate); LoadFunction(AiUpdate);
LoadFunction(ProcessAList); LoadFunction(ProcessAList);
// Make sure dll has all needed functions // Make sure dll has all needed functions
if (AiDacrateChanged == NULL) { UnloadPlugin(); return false; } if (AiDacrateChanged == NULL) { UnloadPlugin(); return false; }
if (AiLenChanged == NULL) { UnloadPlugin(); return false; } if (AiLenChanged == NULL) { UnloadPlugin(); return false; }
if (AiReadLength == NULL) { UnloadPlugin(); return false; } if (AiReadLength == NULL) { UnloadPlugin(); return false; }
if (InitiateAudio == NULL) { UnloadPlugin(); return false; } if (InitiateAudio == NULL) { UnloadPlugin(); return false; }
if (ProcessAList == NULL) { UnloadPlugin(); return false; } if (ProcessAList == NULL) { UnloadPlugin(); return false; }
if (m_PluginInfo.Version >= 0x0102) if (m_PluginInfo.Version >= 0x0102)
{ {
if (PluginOpened == NULL) { UnloadPlugin(); return false; } if (PluginOpened == NULL) { UnloadPlugin(); return false; }
} }
return true; return true;
} }
bool CAudioPlugin::Initiate(CN64System * System, CMainGui * RenderWindow) bool CAudioPlugin::Initiate(CN64System * System, CMainGui * RenderWindow)
{ {
struct AUDIO_INFO { struct AUDIO_INFO
HWND hwnd; {
HINSTANCE hinst; HWND hwnd;
HINSTANCE hinst;
BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre
// bswap on a dword (32 bits) boundry
// eg. the first 8 bytes are stored like this:
// 4 3 2 1 8 7 6 5
BYTE * HEADER; // This is the rom header (first 40h bytes of the rom
// This will be in the same memory format as the rest of the memory.
BYTE * RDRAM;
BYTE * DMEM;
BYTE * IMEM;
DWORD * MI__INTR_REG; // bswap on a dword (32 bits) boundry
// eg. the first 8 bytes are stored like this:
// 4 3 2 1 8 7 6 5
uint8_t * HEADER; // This is the rom header (first 40h bytes of the rom
// This will be in the same memory format as the rest of the memory.
uint8_t * RDRAM;
uint8_t * DMEM;
uint8_t * IMEM;
DWORD * AI__DRAM_ADDR_REG; uint32_t * MI__INTR_REG;
DWORD * AI__LEN_REG;
DWORD * AI__CONTROL_REG;
DWORD * AI__STATUS_REG;
DWORD * AI__DACRATE_REG;
DWORD * AI__BITRATE_REG;
void (__cdecl *CheckInterrupts)( void ); uint32_t * AI__DRAM_ADDR_REG;
}; uint32_t * AI__LEN_REG;
uint32_t * AI__CONTROL_REG;
uint32_t * AI__STATUS_REG;
uint32_t * AI__DACRATE_REG;
uint32_t * AI__BITRATE_REG;
//Get Function from DLL void(__cdecl *CheckInterrupts)(void);
BOOL (__cdecl *InitiateAudio)( AUDIO_INFO Audio_Info ); };
LoadFunction(InitiateAudio);
if (InitiateAudio == NULL) { return false; }
AUDIO_INFO Info = { 0 }; //Get Function from DLL
int32_t(__cdecl *InitiateAudio)(AUDIO_INFO Audio_Info);
LoadFunction(InitiateAudio);
if (InitiateAudio == NULL) { return false; }
AUDIO_INFO Info = { 0 };
Info.hwnd = (HWND)RenderWindow->m_hMainWindow;; Info.hwnd = (HWND)RenderWindow->m_hMainWindow;;
Info.hinst = GetModuleHandle(NULL); Info.hinst = GetModuleHandle(NULL);
Info.MemoryBswaped = TRUE; Info.MemoryBswaped = TRUE;
Info.CheckInterrupts = DummyCheckInterrupts; Info.CheckInterrupts = DummyCheckInterrupts;
// We are initializing the plugin before any rom is loaded so we do not have any correct // We are initializing the plugin before any rom is loaded so we do not have any correct
// parameters here.. just needed to we can config the DLL. // parameters here.. just needed to we can config the DLL.
if (System == NULL) if (System == NULL)
{ {
BYTE Buffer[100]; uint8_t Buffer[100];
DWORD Value = 0; uint32_t Value = 0;
Info.HEADER = Buffer; Info.HEADER = Buffer;
Info.RDRAM = Buffer; Info.RDRAM = Buffer;
Info.DMEM = Buffer; Info.DMEM = Buffer;
Info.IMEM = Buffer; Info.IMEM = Buffer;
Info.MI__INTR_REG = &Value; Info.MI__INTR_REG = &Value;
Info.AI__DRAM_ADDR_REG = &Value; Info.AI__DRAM_ADDR_REG = &Value;
Info.AI__LEN_REG = &Value; Info.AI__LEN_REG = &Value;
Info.AI__CONTROL_REG = &Value; Info.AI__CONTROL_REG = &Value;
Info.AI__STATUS_REG = &Value; Info.AI__STATUS_REG = &Value;
Info.AI__DACRATE_REG = &Value; Info.AI__DACRATE_REG = &Value;
Info.AI__BITRATE_REG = &Value; Info.AI__BITRATE_REG = &Value;
} }
// Send initialization information to the DLL // Send initialization information to the DLL
else else
{ {
Info.HEADER = g_Rom->GetRomAddress(); Info.HEADER = g_Rom->GetRomAddress();
Info.RDRAM = g_MMU->Rdram(); Info.RDRAM = g_MMU->Rdram();
Info.DMEM = g_MMU->Dmem(); Info.DMEM = g_MMU->Dmem();
Info.IMEM = g_MMU->Imem(); Info.IMEM = g_MMU->Imem();
Info.MI__INTR_REG = &g_Reg->m_AudioIntrReg; Info.MI__INTR_REG = (uint32_t *)&g_Reg->m_AudioIntrReg;
Info.AI__DRAM_ADDR_REG = &g_Reg->AI_DRAM_ADDR_REG; Info.AI__DRAM_ADDR_REG = (uint32_t *)&g_Reg->AI_DRAM_ADDR_REG;
Info.AI__LEN_REG = &g_Reg->AI_LEN_REG; Info.AI__LEN_REG = (uint32_t *)&g_Reg->AI_LEN_REG;
Info.AI__CONTROL_REG = &g_Reg->AI_CONTROL_REG; Info.AI__CONTROL_REG = (uint32_t *)&g_Reg->AI_CONTROL_REG;
Info.AI__STATUS_REG = &g_Reg->AI_STATUS_REG; Info.AI__STATUS_REG = (uint32_t *)&g_Reg->AI_STATUS_REG;
Info.AI__DACRATE_REG = &g_Reg->AI_DACRATE_REG; Info.AI__DACRATE_REG = (uint32_t *)&g_Reg->AI_DACRATE_REG;
Info.AI__BITRATE_REG = &g_Reg->AI_BITRATE_REG; Info.AI__BITRATE_REG = (uint32_t *)&g_Reg->AI_BITRATE_REG;
} }
m_Initialized = InitiateAudio(Info) != 0; m_Initialized = InitiateAudio(Info) != 0;
//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);
if (System != NULL) if (System != NULL)
{ {
if (AiUpdate) if (AiUpdate)
{ {
if (m_hAudioThread) if (m_hAudioThread)
{ {
WriteTraceF(TraceAudio, __FUNCTION__ ": Terminate Audio Thread"); WriteTraceF(TraceAudio, __FUNCTION__ ": Terminate Audio Thread");
TerminateThread(m_hAudioThread, 0); TerminateThread(m_hAudioThread, 0);
} }
m_hAudioThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AudioThread, (LPVOID)this, 0, &ThreadID); m_hAudioThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AudioThread, (LPVOID)this, 0, &ThreadID);
} }
if (g_Reg->AI_DACRATE_REG != 0) if (g_Reg->AI_DACRATE_REG != 0)
{ {
DacrateChanged(System->SystemType()); DacrateChanged(System->SystemType());
} }
} }
return m_Initialized; return m_Initialized;
} }
void CAudioPlugin::UnloadPluginDetails(void) void CAudioPlugin::UnloadPluginDetails(void)
{ {
if (m_hAudioThread) if (m_hAudioThread)
{ {
WriteTraceF(TraceAudio, __FUNCTION__ ": Terminate Audio Thread"); WriteTraceF(TraceAudio, __FUNCTION__ ": Terminate Audio Thread");
TerminateThread(m_hAudioThread, 0); TerminateThread(m_hAudioThread, 0);
m_hAudioThread = NULL; m_hAudioThread = NULL;
} }
AiDacrateChanged = NULL; AiDacrateChanged = NULL;
AiLenChanged = NULL; AiLenChanged = NULL;
AiReadLength = NULL; AiReadLength = NULL;
AiUpdate = NULL; AiUpdate = NULL;
ProcessAList = NULL; ProcessAList = NULL;
} }
void CAudioPlugin::DacrateChanged(SYSTEM_TYPE Type) void CAudioPlugin::DacrateChanged(SYSTEM_TYPE Type)
{ {
if (!Initialized()) { return; } if (!Initialized()) { return; }
WriteTraceF(TraceAudio, __FUNCTION__ ": SystemType: %s", Type == SYSTEM_NTSC ? "SYSTEM_NTSC" : "SYSTEM_PAL"); WriteTraceF(TraceAudio, __FUNCTION__ ": SystemType: %s", Type == SYSTEM_NTSC ? "SYSTEM_NTSC" : "SYSTEM_PAL");
//DWORD Frequency = g_Reg->AI_DACRATE_REG * 30; //uint32_t Frequency = g_Reg->AI_DACRATE_REG * 30;
//DWORD CountsPerSecond = (g_Reg->VI_V_SYNC_REG != 0 ? (g_Reg->VI_V_SYNC_REG + 1) * g_Settings->LoadDword(Game_ViRefreshRate) : 500000) * 60; //uint32_t CountsPerSecond = (g_Reg->VI_V_SYNC_REG != 0 ? (g_Reg->VI_V_SYNC_REG + 1) * g_Settings->LoadDword(Game_ViRefreshRate) : 500000) * 60;
AiDacrateChanged(Type); AiDacrateChanged(Type);
} }
void CAudioPlugin::AudioThread(CAudioPlugin * _this) { void CAudioPlugin::AudioThread(CAudioPlugin * _this) {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
for (;;) for (;;)
{ {
_this->AiUpdate(true); _this->AiUpdate(true);
} }
} }

View File

@ -13,32 +13,32 @@
class CAudioPlugin : public CPlugin class CAudioPlugin : public CPlugin
{ {
public: public:
CAudioPlugin(void); CAudioPlugin(void);
~CAudioPlugin(); ~CAudioPlugin();
void DacrateChanged(SYSTEM_TYPE Type); void DacrateChanged(SYSTEM_TYPE Type);
bool Initiate(CN64System * System, CMainGui * RenderWindow); bool Initiate(CN64System * System, CMainGui * RenderWindow);
void(__cdecl *AiLenChanged)(void); void(__cdecl *AiLenChanged)(void);
DWORD(__cdecl *AiReadLength)(void); uint32_t(__cdecl *AiReadLength)(void);
void(__cdecl *ProcessAList)(void); void(__cdecl *ProcessAList)(void);
private: private:
CAudioPlugin(const CAudioPlugin&); // Disable copy constructor CAudioPlugin(const CAudioPlugin&); // Disable copy constructor
CAudioPlugin& operator=(const CAudioPlugin&); // Disable assignment CAudioPlugin& operator=(const CAudioPlugin&); // Disable assignment
virtual int GetDefaultSettingStartRange() const { return FirstAudioDefaultSet; } virtual int32_t GetDefaultSettingStartRange() const { return FirstAudioDefaultSet; }
virtual int GetSettingStartRange() const { return FirstAudioSettings; } virtual int32_t GetSettingStartRange() const { return FirstAudioSettings; }
PLUGIN_TYPE type() { return PLUGIN_TYPE_AUDIO; } PLUGIN_TYPE type() { return PLUGIN_TYPE_AUDIO; }
void * m_hAudioThread; void * m_hAudioThread;
bool LoadFunctions ( void );
void UnloadPluginDetails ( void );
void(__cdecl *AiUpdate) (BOOL Wait); bool LoadFunctions(void);
void(__cdecl *AiDacrateChanged)(SYSTEM_TYPE Type); void UnloadPluginDetails(void);
// Function used in a thread for using audio void(__cdecl *AiUpdate) (int32_t Wait);
static void AudioThread(CAudioPlugin * _this); void(__cdecl *AiDacrateChanged)(SYSTEM_TYPE Type);
// Function used in a thread for using audio
static void AudioThread(CAudioPlugin * _this);
}; };

View File

@ -11,164 +11,170 @@
#include "stdafx.h" #include "stdafx.h"
CControl_Plugin::CControl_Plugin(void) : CControl_Plugin::CControl_Plugin(void) :
WM_KeyDown(NULL), WM_KeyDown(NULL),
WM_KeyUp(NULL), WM_KeyUp(NULL),
RumbleCommand(NULL), RumbleCommand(NULL),
GetKeys(NULL), GetKeys(NULL),
ReadController(NULL), ReadController(NULL),
ControllerCommand(NULL), ControllerCommand(NULL),
m_AllocatedControllers(false) m_AllocatedControllers(false)
{ {
memset(&m_PluginControllers, 0, sizeof(m_PluginControllers)); memset(&m_PluginControllers, 0, sizeof(m_PluginControllers));
memset(&m_Controllers, 0, sizeof(m_Controllers)); memset(&m_Controllers, 0, sizeof(m_Controllers));
} }
CControl_Plugin::~CControl_Plugin() CControl_Plugin::~CControl_Plugin()
{ {
Close(); Close();
UnloadPlugin(); UnloadPlugin();
} }
bool CControl_Plugin::LoadFunctions ( void ) bool CControl_Plugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
void (__cdecl *InitiateControllers)( void ); void(__cdecl *InitiateControllers)(void);
LoadFunction(InitiateControllers); LoadFunction(InitiateControllers);
LoadFunction(ControllerCommand); LoadFunction(ControllerCommand);
LoadFunction(GetKeys); LoadFunction(GetKeys);
LoadFunction(ReadController); LoadFunction(ReadController);
LoadFunction(WM_KeyDown); LoadFunction(WM_KeyDown);
LoadFunction(WM_KeyUp); LoadFunction(WM_KeyUp);
LoadFunction(RumbleCommand); LoadFunction(RumbleCommand);
//Make sure dll had all needed functions //Make sure dll had all needed functions
if (InitiateControllers == NULL) { UnloadPlugin(); return false; } if (InitiateControllers == NULL) { UnloadPlugin(); return false; }
if (m_PluginInfo.Version >= 0x0102) if (m_PluginInfo.Version >= 0x0102)
{ {
if (PluginOpened == NULL) { UnloadPlugin(); return false; } if (PluginOpened == NULL) { UnloadPlugin(); return false; }
} }
// Allocate our own controller // Allocate our own controller
m_AllocatedControllers = true; m_AllocatedControllers = true;
for (int i = 0; i < 4; i++) for (int32_t i = 0; i < 4; i++)
{ {
m_Controllers[i] = new CCONTROL(m_PluginControllers[i].Present, m_PluginControllers[i].RawData, m_PluginControllers[i].Plugin); m_Controllers[i] = new CCONTROL(m_PluginControllers[i].Present, m_PluginControllers[i].RawData, m_PluginControllers[i].Plugin);
} }
return true; return true;
} }
bool CControl_Plugin::Initiate(CN64System * System, CMainGui * RenderWindow) bool CControl_Plugin::Initiate(CN64System * System, CMainGui * RenderWindow)
{ {
for (int i = 0; i < 4; i++) for (int32_t i = 0; i < 4; i++)
{ {
m_PluginControllers[i].Present = FALSE; m_PluginControllers[i].Present = FALSE;
m_PluginControllers[i].RawData = FALSE; m_PluginControllers[i].RawData = FALSE;
m_PluginControllers[i].Plugin = PLUGIN_NONE; m_PluginControllers[i].Plugin = PLUGIN_NONE;
} }
// Test Plugin version // Test Plugin version
if (m_PluginInfo.Version == 0x0100) if (m_PluginInfo.Version == 0x0100)
{ {
//Get Function from DLL //Get Function from DLL
void (__cdecl *InitiateControllers_1_0)( HWND hMainWindow, CONTROL Controls[4] ); void(__cdecl *InitiateControllers_1_0)(HWND hMainWindow, CONTROL Controls[4]);
InitiateControllers_1_0 = (void (__cdecl *)(HWND, CONTROL *))GetProcAddress( (HMODULE)m_hDll, "InitiateControllers" ); InitiateControllers_1_0 = (void(__cdecl *)(HWND, CONTROL *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
if (InitiateControllers_1_0 == NULL) { return false; } if (InitiateControllers_1_0 == NULL) { return false; }
InitiateControllers_1_0((HWND)RenderWindow->m_hMainWindow,m_PluginControllers); InitiateControllers_1_0((HWND)RenderWindow->m_hMainWindow,m_PluginControllers);
m_Initialized = true; m_Initialized = true;
} }
else if (m_PluginInfo.Version >= 0x0101) else if (m_PluginInfo.Version >= 0x0101)
{ {
typedef struct { typedef struct
HWND hMainWindow; {
HINSTANCE hinst; HWND hMainWindow;
HINSTANCE hinst;
BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre
// bswap on a dword (32 bits) boundry, only effects header. // bswap on a dword (32 bits) boundry, only effects header.
// eg. the first 8 bytes are stored like this: // eg. the first 8 bytes are stored like this:
// 4 3 2 1 8 7 6 5 // 4 3 2 1 8 7 6 5
BYTE * HEADER; // This is the rom header (first 40h bytes of the rom) uint8_t * HEADER; // This is the rom header (first 40h bytes of the rom)
CONTROL *Controls; // A pointer to an array of 4 controllers .. eg: CONTROL *Controls; // A pointer to an array of 4 controllers .. eg:
// CONTROL Controls[4]; // CONTROL Controls[4];
} CONTROL_INFO; } CONTROL_INFO;
//Get Function from DLL //Get Function from DLL
void (__cdecl *InitiateControllers_1_1)( CONTROL_INFO * ControlInfo ); void(__cdecl *InitiateControllers_1_1)(CONTROL_INFO * ControlInfo);
InitiateControllers_1_1 = (void (__cdecl *)(CONTROL_INFO *))GetProcAddress( (HMODULE)m_hDll, "InitiateControllers" ); InitiateControllers_1_1 = (void(__cdecl *)(CONTROL_INFO *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
if (InitiateControllers_1_1 == NULL) { return false; } if (InitiateControllers_1_1 == NULL) { return false; }
CONTROL_INFO ControlInfo;
BYTE Buffer[100];
ControlInfo.Controls = m_PluginControllers; CONTROL_INFO ControlInfo;
ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress()); uint8_t Buffer[100];
ControlInfo.hinst = GetModuleHandle(NULL);
ControlInfo.Controls = m_PluginControllers;
ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress());
ControlInfo.hinst = GetModuleHandle(NULL);
ControlInfo.hMainWindow = (HWND)RenderWindow->m_hMainWindow; ControlInfo.hMainWindow = (HWND)RenderWindow->m_hMainWindow;
ControlInfo.MemoryBswaped = TRUE; ControlInfo.MemoryBswaped = TRUE;
InitiateControllers_1_1(&ControlInfo); InitiateControllers_1_1(&ControlInfo);
m_Initialized = true; m_Initialized = 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);
return m_Initialized; return m_Initialized;
} }
void CControl_Plugin::UnloadPluginDetails(void) void CControl_Plugin::UnloadPluginDetails(void)
{ {
if (m_AllocatedControllers)
{
for (int32_t count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
{
delete m_Controllers[count];
m_Controllers[count] = NULL;
}
}
if (m_AllocatedControllers) m_AllocatedControllers = false;
{ ControllerCommand = NULL;
for (int count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++) GetKeys = NULL;
{ ReadController = NULL;
delete m_Controllers[count]; WM_KeyDown = NULL;
m_Controllers[count] = NULL; WM_KeyUp = NULL;
}
}
m_AllocatedControllers = false;
ControllerCommand = NULL;
GetKeys = NULL;
ReadController = NULL;
WM_KeyDown = NULL;
WM_KeyUp = NULL;
} }
void CControl_Plugin::UpdateKeys (void) void CControl_Plugin::UpdateKeys(void)
{ {
if (!m_AllocatedControllers) { return; } if (!m_AllocatedControllers) { return; }
for (int cont = 0; cont < sizeof(m_Controllers) / sizeof(m_Controllers[0]); cont++) for (int32_t cont = 0; cont < sizeof(m_Controllers) / sizeof(m_Controllers[0]); cont++)
{ {
if (!m_Controllers[cont]->m_Present) { continue; } if (!m_Controllers[cont]->m_Present) { continue; }
if (!m_Controllers[cont]->m_RawData) { if (!m_Controllers[cont]->m_RawData)
GetKeys(cont,&m_Controllers[cont]->m_Buttons); {
} else { GetKeys(cont, &m_Controllers[cont]->m_Buttons);
g_Notify->BreakPoint(__FILEW__,__LINE__); }
} else
} {
if (ReadController) { ReadController(-1, NULL); } g_Notify->BreakPoint(__FILEW__, __LINE__);
}
}
if (ReadController) { ReadController(-1, NULL); }
} }
void CControl_Plugin::SetControl(CControl_Plugin const * const Plugin) void CControl_Plugin::SetControl(CControl_Plugin const * const Plugin)
{ {
if (m_AllocatedControllers) { if (m_AllocatedControllers)
for (int count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++) { {
delete m_Controllers[count]; for (int32_t count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
m_Controllers[count] = NULL; {
} delete m_Controllers[count];
} m_Controllers[count] = NULL;
m_AllocatedControllers = false; }
for (int count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++) { }
m_Controllers[count] = Plugin->m_Controllers[count]; m_AllocatedControllers = false;
} for (int32_t count = 0; count < sizeof(m_Controllers) / sizeof(m_Controllers[0]); count++)
{
m_Controllers[count] = Plugin->m_Controllers[count];
}
} }
CCONTROL::CCONTROL(DWORD &Present, DWORD &RawData, int &PlugType) : CCONTROL::CCONTROL(uint32_t &Present, uint32_t &RawData, int32_t &PlugType) :
m_Present(Present), m_RawData(RawData), m_PlugType(PlugType) m_Present(Present), m_RawData(RawData), m_PlugType(PlugType)
{ {
m_Buttons.Value = 0; m_Buttons.Value = 0;
} }

View File

@ -10,95 +10,110 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
typedef union { #pragma warning(push)
DWORD Value; #pragma warning(disable : 4201) // warning C4201: nonstandard extension used : nameless struct/union
struct {
unsigned R_DPAD : 1;
unsigned L_DPAD : 1;
unsigned D_DPAD : 1;
unsigned U_DPAD : 1;
unsigned START_BUTTON : 1;
unsigned Z_TRIG : 1;
unsigned B_BUTTON : 1;
unsigned A_BUTTON : 1;
unsigned R_CBUTTON : 1; typedef union
unsigned L_CBUTTON : 1; {
unsigned D_CBUTTON : 1; uint32_t Value;
unsigned U_CBUTTON : 1; struct
unsigned R_TRIG : 1; {
unsigned L_TRIG : 1; unsigned R_DPAD : 1;
unsigned Reserved1 : 1; unsigned L_DPAD : 1;
unsigned Reserved2 : 1; unsigned D_DPAD : 1;
unsigned U_DPAD : 1;
unsigned START_BUTTON : 1;
unsigned Z_TRIG : 1;
unsigned B_BUTTON : 1;
unsigned A_BUTTON : 1;
signed Y_AXIS : 8; unsigned R_CBUTTON : 1;
unsigned L_CBUTTON : 1;
unsigned D_CBUTTON : 1;
unsigned U_CBUTTON : 1;
unsigned R_TRIG : 1;
unsigned L_TRIG : 1;
unsigned Reserved1 : 1;
unsigned Reserved2 : 1;
signed X_AXIS : 8; signed Y_AXIS : 8;
};
signed X_AXIS : 8;
};
} BUTTONS; } BUTTONS;
#pragma warning(pop)
typedef struct { typedef struct
DWORD Present; {
DWORD RawData; uint32_t Present;
int Plugin; uint32_t RawData;
int32_t Plugin;
} CONTROL; } CONTROL;
enum PluginType { enum PluginType
PLUGIN_NONE = 1, {
PLUGIN_MEMPAK = 2, PLUGIN_NONE = 1,
PLUGIN_RUMBLE_PAK = 3, PLUGIN_MEMPAK = 2,
PLUGIN_TANSFER_PAK = 4, // not implemeted for non raw data PLUGIN_RUMBLE_PAK = 3,
PLUGIN_RAW = 5, // the controller plugin is passed in raw data PLUGIN_TANSFER_PAK = 4, // not implemeted for non raw data
PLUGIN_RAW = 5, // the controller plugin is passed in raw data
}; };
class CCONTROL { class CControl_Plugin;
friend CControl_Plugin; //controller plugin class has full access
DWORD & m_Present;
DWORD & m_RawData;
int & m_PlugType;
BUTTONS m_Buttons;
class CCONTROL
{
public: public:
CCONTROL(DWORD &Present, DWORD &RawData, int &PlugType); CCONTROL(uint32_t &Present, uint32_t &RawData, int32_t &PlugType);
inline bool Present(void) const { return m_Present != 0; } inline bool Present(void) const { return m_Present != 0; }
inline DWORD Buttons(void) const { return m_Buttons.Value; } inline uint32_t Buttons(void) const { return m_Buttons.Value; }
inline PluginType Plugin(void) const { return static_cast<PluginType>(m_PlugType); } inline PluginType Plugin(void) const { return static_cast<PluginType>(m_PlugType); }
private:
friend CControl_Plugin; //controller plugin class has full access
uint32_t & m_Present;
uint32_t & m_RawData;
int32_t & m_PlugType;
BUTTONS m_Buttons;
CCONTROL(void); // Disable default constructor
CCONTROL(const CCONTROL&); // Disable copy constructor
CCONTROL& operator=(const CCONTROL&); // Disable assignment
}; };
class CControl_Plugin : public CPlugin class CControl_Plugin : public CPlugin
{ {
public: public:
CControl_Plugin(void); CControl_Plugin(void);
~CControl_Plugin(); ~CControl_Plugin();
bool Initiate(CN64System * System, CMainGui * RenderWindow); bool Initiate(CN64System * System, CMainGui * RenderWindow);
void SetControl(CControl_Plugin const * const Plugin); void SetControl(CControl_Plugin const * const Plugin);
void UpdateKeys(void); void UpdateKeys(void);
void(__cdecl *WM_KeyDown) (DWORD wParam, DWORD lParam); void(__cdecl *WM_KeyDown) (uint32_t wParam, uint32_t lParam);
void(__cdecl *WM_KeyUp) (DWORD wParam, DWORD lParam); void(__cdecl *WM_KeyUp) (uint32_t wParam, uint32_t lParam);
void(__cdecl *RumbleCommand) (int Control, BOOL bRumble); void(__cdecl *RumbleCommand) (int32_t Control, int32_t bRumble);
void(__cdecl *GetKeys) (int Control, BUTTONS * Keys); void(__cdecl *GetKeys) (int32_t Control, BUTTONS * Keys);
void(__cdecl *ReadController) (int Control, BYTE * Command); void(__cdecl *ReadController) (int32_t Control, uint8_t * Command);
void(__cdecl *ControllerCommand)(int Control, BYTE * Command); void(__cdecl *ControllerCommand)(int32_t Control, uint8_t * Command);
inline CCONTROL const * Controller(int control) { return m_Controllers[control]; } inline CCONTROL const * Controller(int32_t control) { return m_Controllers[control]; }
inline CONTROL * PluginControllers(void) { return m_PluginControllers; } inline CONTROL * PluginControllers(void) { return m_PluginControllers; }
private: private:
CControl_Plugin(const CControl_Plugin&); // Disable copy constructor CControl_Plugin(const CControl_Plugin&); // Disable copy constructor
CControl_Plugin& operator=(const CControl_Plugin&); // Disable assignment CControl_Plugin& operator=(const CControl_Plugin&); // Disable assignment
virtual int GetDefaultSettingStartRange() const { return FirstCtrlDefaultSet; } virtual int32_t GetDefaultSettingStartRange() const { return FirstCtrlDefaultSet; }
virtual int GetSettingStartRange() const { return FirstCtrlSettings; } virtual int32_t GetSettingStartRange() const { return FirstCtrlSettings; }
PLUGIN_TYPE type() { return PLUGIN_TYPE_CONTROLLER; } PLUGIN_TYPE type() { return PLUGIN_TYPE_CONTROLLER; }
bool LoadFunctions ( void ); bool LoadFunctions(void);
void UnloadPluginDetails ( void ); void UnloadPluginDetails(void);
bool m_AllocatedControllers; bool m_AllocatedControllers;
// What the different controls are set up as // What the different controls are set up as
CONTROL m_PluginControllers[4]; CONTROL m_PluginControllers[4];
CCONTROL * m_Controllers[4]; CCONTROL * m_Controllers[4];
}; };

View File

@ -10,250 +10,254 @@
****************************************************************************/ ****************************************************************************/
#include "stdafx.h" #include "stdafx.h"
CGfxPlugin::CGfxPlugin() : CGfxPlugin::CGfxPlugin() :
CaptureScreen(NULL), CaptureScreen(NULL),
ChangeWindow(NULL), ChangeWindow(NULL),
DrawScreen(NULL), DrawScreen(NULL),
DrawStatus(NULL), DrawStatus(NULL),
MoveScreen(NULL), MoveScreen(NULL),
ProcessDList(NULL), ProcessDList(NULL),
ProcessRDPList(NULL), ProcessRDPList(NULL),
ShowCFB(NULL), ShowCFB(NULL),
UpdateScreen(NULL), UpdateScreen(NULL),
ViStatusChanged(NULL), ViStatusChanged(NULL),
ViWidthChanged(NULL), ViWidthChanged(NULL),
SoftReset(NULL), SoftReset(NULL),
GetRomBrowserMenu(NULL), GetRomBrowserMenu(NULL),
OnRomBrowserMenuItem(NULL), OnRomBrowserMenuItem(NULL),
GetDebugInfo(NULL), GetDebugInfo(NULL),
InitiateDebugger(NULL) InitiateDebugger(NULL)
{ {
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug)); memset(&m_GFXDebug, 0, sizeof(m_GFXDebug));
} }
CGfxPlugin::~CGfxPlugin() CGfxPlugin::~CGfxPlugin()
{ {
Close(); Close();
UnloadPlugin(); UnloadPlugin();
} }
bool CGfxPlugin::LoadFunctions ( void ) bool CGfxPlugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
BOOL (__cdecl *InitiateGFX) ( void * Gfx_Info ); int32_t(__cdecl *InitiateGFX) (void * Gfx_Info);
LoadFunction(InitiateGFX); LoadFunction(InitiateGFX);
LoadFunction(ChangeWindow); LoadFunction(ChangeWindow);
LoadFunction(DrawScreen); LoadFunction(DrawScreen);
LoadFunction(MoveScreen); LoadFunction(MoveScreen);
LoadFunction(ProcessDList); LoadFunction(ProcessDList);
LoadFunction(UpdateScreen); LoadFunction(UpdateScreen);
LoadFunction(ViStatusChanged); LoadFunction(ViStatusChanged);
LoadFunction(ViWidthChanged); LoadFunction(ViWidthChanged);
LoadFunction(SoftReset); LoadFunction(SoftReset);
// version 0x104 functions // version 0x104 functions
_LoadFunction("DrawFullScreenStatus", DrawStatus); _LoadFunction("DrawFullScreenStatus", DrawStatus);
// Rom Browser // Rom Browser
LoadFunction(GetRomBrowserMenu); LoadFunction(GetRomBrowserMenu);
LoadFunction(OnRomBrowserMenuItem); LoadFunction(OnRomBrowserMenuItem);
//Make sure dll had all needed functions //Make sure dll had all needed functions
if (ChangeWindow == NULL) { UnloadPlugin(); return false; } if (ChangeWindow == NULL) { UnloadPlugin(); return false; }
if (DrawScreen == NULL) { DrawScreen = DummyDrawScreen; } if (DrawScreen == NULL) { DrawScreen = DummyDrawScreen; }
if (InitiateGFX == NULL) { UnloadPlugin(); return false; } if (InitiateGFX == NULL) { UnloadPlugin(); return false; }
if (MoveScreen == NULL) { MoveScreen = DummyMoveScreen; } if (MoveScreen == NULL) { MoveScreen = DummyMoveScreen; }
if (ProcessDList == NULL) { UnloadPlugin(); return false; } if (ProcessDList == NULL) { UnloadPlugin(); return false; }
if (UpdateScreen == NULL) { UnloadPlugin(); return false; } if (UpdateScreen == NULL) { UnloadPlugin(); return false; }
if (ViStatusChanged == NULL) { ViStatusChanged = DummyViStatusChanged; } if (ViStatusChanged == NULL) { ViStatusChanged = DummyViStatusChanged; }
if (ViWidthChanged == NULL) { ViWidthChanged = DummyViWidthChanged; } if (ViWidthChanged == NULL) { ViWidthChanged = DummyViWidthChanged; }
if (SoftReset == NULL) { SoftReset = DummySoftReset; } if (SoftReset == NULL) { SoftReset = DummySoftReset; }
if (m_PluginInfo.Version >= 0x0103) if (m_PluginInfo.Version >= 0x0103)
{ {
LoadFunction(ProcessRDPList); LoadFunction(ProcessRDPList);
LoadFunction(CaptureScreen); LoadFunction(CaptureScreen);
LoadFunction(ShowCFB); LoadFunction(ShowCFB);
LoadFunction(GetDebugInfo); LoadFunction(GetDebugInfo);
_LoadFunction("InitiateGFXDebugger", InitiateDebugger); _LoadFunction("InitiateGFXDebugger", InitiateDebugger);
if (ProcessRDPList == NULL) { UnloadPlugin(); return false; } if (ProcessRDPList == NULL) { UnloadPlugin(); return false; }
if (CaptureScreen == NULL) { UnloadPlugin(); return false; } if (CaptureScreen == NULL) { UnloadPlugin(); return false; }
if (ShowCFB == NULL) { UnloadPlugin(); return false; } if (ShowCFB == NULL) { UnloadPlugin(); return false; }
} }
if (m_PluginInfo.Version >= 0x0104) if (m_PluginInfo.Version >= 0x0104)
{ {
if (PluginOpened == NULL) { UnloadPlugin(); return false; } if (PluginOpened == NULL) { UnloadPlugin(); return false; }
} }
if (GetDebugInfo != NULL) if (GetDebugInfo != NULL)
GetDebugInfo(&m_GFXDebug); GetDebugInfo(&m_GFXDebug);
return true; return true;
} }
bool CGfxPlugin::Initiate(CN64System * System, CMainGui * RenderWindow) bool CGfxPlugin::Initiate(CN64System * System, CMainGui * RenderWindow)
{ {
if (m_Initialized) if (m_Initialized)
Close(); {
Close();
}
typedef struct { typedef struct
HWND hWnd; /* Render window */ {
HWND hStatusBar; /* if render window does not have a status bar then this is NULL */ HWND hWnd; /* Render window */
HWND hStatusBar; /* if render window does not have a status bar then this is NULL */
BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre
// bswap on a dword (32 bits) boundry // bswap on a dword (32 bits) boundry
// eg. the first 8 bytes are stored like this: // eg. the first 8 bytes are stored like this:
// 4 3 2 1 8 7 6 5 // 4 3 2 1 8 7 6 5
BYTE * HEADER; // This is the rom header (first 40h bytes of the rom uint8_t * HEADER; // This is the rom header (first 40h bytes of the rom
// This will be in the same memory format as the rest of the memory. // This will be in the same memory format as the rest of the memory.
BYTE * RDRAM; uint8_t * RDRAM;
BYTE * DMEM; uint8_t * DMEM;
BYTE * IMEM; uint8_t * IMEM;
DWORD * MI__INTR_REG; uint32_t * MI__INTR_REG;
DWORD * DPC__START_REG; uint32_t * DPC__START_REG;
DWORD * DPC__END_REG; uint32_t * DPC__END_REG;
DWORD * DPC__CURRENT_REG; uint32_t * DPC__CURRENT_REG;
DWORD * DPC__STATUS_REG; uint32_t * DPC__STATUS_REG;
DWORD * DPC__CLOCK_REG; uint32_t * DPC__CLOCK_REG;
DWORD * DPC__BUFBUSY_REG; uint32_t * DPC__BUFBUSY_REG;
DWORD * DPC__PIPEBUSY_REG; uint32_t * DPC__PIPEBUSY_REG;
DWORD * DPC__TMEM_REG; uint32_t * DPC__TMEM_REG;
DWORD * VI__STATUS_REG; uint32_t * VI__STATUS_REG;
DWORD * VI__ORIGIN_REG; uint32_t * VI__ORIGIN_REG;
DWORD * VI__WIDTH_REG; uint32_t * VI__WIDTH_REG;
DWORD * VI__INTR_REG; uint32_t * VI__INTR_REG;
DWORD * VI__V_CURRENT_LINE_REG; uint32_t * VI__V_CURRENT_LINE_REG;
DWORD * VI__TIMING_REG; uint32_t * VI__TIMING_REG;
DWORD * VI__V_SYNC_REG; uint32_t * VI__V_SYNC_REG;
DWORD * VI__H_SYNC_REG; uint32_t * VI__H_SYNC_REG;
DWORD * VI__LEAP_REG; uint32_t * VI__LEAP_REG;
DWORD * VI__H_START_REG; uint32_t * VI__H_START_REG;
DWORD * VI__V_START_REG; uint32_t * VI__V_START_REG;
DWORD * VI__V_BURST_REG; uint32_t * VI__V_BURST_REG;
DWORD * VI__X_SCALE_REG; uint32_t * VI__X_SCALE_REG;
DWORD * VI__Y_SCALE_REG; uint32_t * VI__Y_SCALE_REG;
void (__cdecl *CheckInterrupts)( void ); void(__cdecl *CheckInterrupts)(void);
} GFX_INFO; } GFX_INFO;
//Get Function from DLL //Get Function from DLL
BOOL (__cdecl *InitiateGFX)( GFX_INFO Gfx_Info ); int32_t(__cdecl *InitiateGFX)(GFX_INFO Gfx_Info);
InitiateGFX = (BOOL (__cdecl *)(GFX_INFO))GetProcAddress( (HMODULE)m_hDll, "InitiateGFX" ); InitiateGFX = (int32_t(__cdecl *)(GFX_INFO))GetProcAddress((HMODULE)m_hDll, "InitiateGFX");
if (InitiateGFX == NULL) { return false; } if (InitiateGFX == NULL) { return false; }
GFX_INFO Info = { 0 }; GFX_INFO Info = { 0 };
Info.MemoryBswaped = TRUE; Info.MemoryBswaped = TRUE;
Info.hWnd = (HWND)RenderWindow->m_hMainWindow; Info.hWnd = (HWND)RenderWindow->m_hMainWindow;
Info.hStatusBar = (HWND)RenderWindow->m_hStatusWnd; Info.hStatusBar = (HWND)RenderWindow->m_hStatusWnd;
Info.CheckInterrupts = DummyCheckInterrupts; Info.CheckInterrupts = DummyCheckInterrupts;
// We are initializing the plugin before any rom is loaded so we do not have any correct // We are initializing the plugin before any rom is loaded so we do not have any correct
// parameters here.. it's just needed so we can config the DLL. // parameters here.. it's just needed so we can config the DLL.
if (System == NULL) if (System == NULL)
{ {
BYTE Buffer[100]; uint8_t Buffer[100];
DWORD Value = 0; uint32_t Value = 0;
Info.HEADER = Buffer; Info.HEADER = Buffer;
Info.RDRAM = Buffer; Info.RDRAM = Buffer;
Info.DMEM = Buffer; Info.DMEM = Buffer;
Info.IMEM = Buffer; Info.IMEM = Buffer;
Info.MI__INTR_REG = &Value; Info.MI__INTR_REG = &Value;
Info.VI__STATUS_REG = &Value; Info.VI__STATUS_REG = &Value;
Info.VI__ORIGIN_REG = &Value; Info.VI__ORIGIN_REG = &Value;
Info.VI__WIDTH_REG = &Value; Info.VI__WIDTH_REG = &Value;
Info.VI__INTR_REG = &Value; Info.VI__INTR_REG = &Value;
Info.VI__V_CURRENT_LINE_REG = &Value; Info.VI__V_CURRENT_LINE_REG = &Value;
Info.VI__TIMING_REG = &Value; Info.VI__TIMING_REG = &Value;
Info.VI__V_SYNC_REG = &Value; Info.VI__V_SYNC_REG = &Value;
Info.VI__H_SYNC_REG = &Value; Info.VI__H_SYNC_REG = &Value;
Info.VI__LEAP_REG = &Value; Info.VI__LEAP_REG = &Value;
Info.VI__H_START_REG = &Value; Info.VI__H_START_REG = &Value;
Info.VI__V_START_REG = &Value; Info.VI__V_START_REG = &Value;
Info.VI__V_BURST_REG = &Value; Info.VI__V_BURST_REG = &Value;
Info.VI__X_SCALE_REG = &Value; Info.VI__X_SCALE_REG = &Value;
Info.VI__Y_SCALE_REG = &Value; Info.VI__Y_SCALE_REG = &Value;
} }
// Send initialization information to the DLL // Send initialization information to the DLL
else else
{ {
Info.HEADER = g_Rom->GetRomAddress(); Info.HEADER = g_Rom->GetRomAddress();
Info.RDRAM = g_MMU->Rdram(); Info.RDRAM = g_MMU->Rdram();
Info.DMEM = g_MMU->Dmem(); Info.DMEM = g_MMU->Dmem();
Info.IMEM = g_MMU->Imem(); Info.IMEM = g_MMU->Imem();
Info.MI__INTR_REG = &g_Reg->m_GfxIntrReg; Info.MI__INTR_REG = (uint32_t *)&g_Reg->m_GfxIntrReg;
Info.DPC__START_REG = &g_Reg->DPC_START_REG; Info.DPC__START_REG = (uint32_t *)&g_Reg->DPC_START_REG;
Info.DPC__END_REG = &g_Reg->DPC_END_REG; Info.DPC__END_REG = (uint32_t *)&g_Reg->DPC_END_REG;
Info.DPC__CURRENT_REG = &g_Reg->DPC_CURRENT_REG; Info.DPC__CURRENT_REG = (uint32_t *)&g_Reg->DPC_CURRENT_REG;
Info.DPC__STATUS_REG = &g_Reg->DPC_STATUS_REG; Info.DPC__STATUS_REG = (uint32_t *)&g_Reg->DPC_STATUS_REG;
Info.DPC__CLOCK_REG = &g_Reg->DPC_CLOCK_REG; Info.DPC__CLOCK_REG = (uint32_t *)&g_Reg->DPC_CLOCK_REG;
Info.DPC__BUFBUSY_REG = &g_Reg->DPC_BUFBUSY_REG; Info.DPC__BUFBUSY_REG = (uint32_t *)&g_Reg->DPC_BUFBUSY_REG;
Info.DPC__PIPEBUSY_REG = &g_Reg->DPC_PIPEBUSY_REG; Info.DPC__PIPEBUSY_REG = (uint32_t *)&g_Reg->DPC_PIPEBUSY_REG;
Info.DPC__TMEM_REG = &g_Reg->DPC_TMEM_REG; Info.DPC__TMEM_REG = (uint32_t *)&g_Reg->DPC_TMEM_REG;
Info.VI__STATUS_REG = &g_Reg->VI_STATUS_REG; Info.VI__STATUS_REG = (uint32_t *)&g_Reg->VI_STATUS_REG;
Info.VI__ORIGIN_REG = &g_Reg->VI_ORIGIN_REG; Info.VI__ORIGIN_REG = (uint32_t *)&g_Reg->VI_ORIGIN_REG;
Info.VI__WIDTH_REG = &g_Reg->VI_WIDTH_REG; Info.VI__WIDTH_REG = (uint32_t *)&g_Reg->VI_WIDTH_REG;
Info.VI__INTR_REG = &g_Reg->VI_INTR_REG; Info.VI__INTR_REG = (uint32_t *)&g_Reg->VI_INTR_REG;
Info.VI__V_CURRENT_LINE_REG = &g_Reg->VI_CURRENT_REG; Info.VI__V_CURRENT_LINE_REG = (uint32_t *)&g_Reg->VI_CURRENT_REG;
Info.VI__TIMING_REG = &g_Reg->VI_TIMING_REG; Info.VI__TIMING_REG = (uint32_t *)&g_Reg->VI_TIMING_REG;
Info.VI__V_SYNC_REG = &g_Reg->VI_V_SYNC_REG; Info.VI__V_SYNC_REG = (uint32_t *)&g_Reg->VI_V_SYNC_REG;
Info.VI__H_SYNC_REG = &g_Reg->VI_H_SYNC_REG; Info.VI__H_SYNC_REG = (uint32_t *)&g_Reg->VI_H_SYNC_REG;
Info.VI__LEAP_REG = &g_Reg->VI_LEAP_REG; Info.VI__LEAP_REG = (uint32_t *)&g_Reg->VI_LEAP_REG;
Info.VI__H_START_REG = &g_Reg->VI_H_START_REG; Info.VI__H_START_REG = (uint32_t *)&g_Reg->VI_H_START_REG;
Info.VI__V_START_REG = &g_Reg->VI_V_START_REG; Info.VI__V_START_REG = (uint32_t *)&g_Reg->VI_V_START_REG;
Info.VI__V_BURST_REG = &g_Reg->VI_V_BURST_REG; Info.VI__V_BURST_REG = (uint32_t *)&g_Reg->VI_V_BURST_REG;
Info.VI__X_SCALE_REG = &g_Reg->VI_X_SCALE_REG; Info.VI__X_SCALE_REG = (uint32_t *)&g_Reg->VI_X_SCALE_REG;
Info.VI__Y_SCALE_REG = &g_Reg->VI_Y_SCALE_REG; Info.VI__Y_SCALE_REG = (uint32_t *)&g_Reg->VI_Y_SCALE_REG;
} }
m_Initialized = InitiateGFX(Info) != 0; m_Initialized = InitiateGFX(Info) != 0;
//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);
return m_Initialized; return m_Initialized;
} }
void CGfxPlugin::UnloadPluginDetails(void) void CGfxPlugin::UnloadPluginDetails(void)
{ {
if (m_hDll != NULL ) { if (m_hDll != NULL)
FreeLibrary((HMODULE)m_hDll); {
m_hDll = NULL; FreeLibrary((HMODULE)m_hDll);
} m_hDll = NULL;
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug)); }
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug));
// CaptureScreen = NULL; // CaptureScreen = NULL;
ChangeWindow = NULL; ChangeWindow = NULL;
GetDebugInfo = NULL; GetDebugInfo = NULL;
DrawScreen = NULL; DrawScreen = NULL;
DrawStatus = NULL; DrawStatus = NULL;
// FrameBufferRead = NULL; // FrameBufferRead = NULL;
// FrameBufferWrite = NULL; // FrameBufferWrite = NULL;
InitiateDebugger = NULL; InitiateDebugger = NULL;
MoveScreen = NULL; MoveScreen = NULL;
ProcessDList = NULL; ProcessDList = NULL;
ProcessRDPList = NULL; ProcessRDPList = NULL;
ShowCFB = NULL; ShowCFB = NULL;
UpdateScreen = NULL; UpdateScreen = NULL;
ViStatusChanged = NULL; ViStatusChanged = NULL;
ViWidthChanged = NULL; ViWidthChanged = NULL;
GetRomBrowserMenu = NULL; GetRomBrowserMenu = NULL;
OnRomBrowserMenuItem = NULL; OnRomBrowserMenuItem = NULL;
} }
void CGfxPlugin::ProcessMenuItem(int id) void CGfxPlugin::ProcessMenuItem(int32_t id)
{ {
if (m_GFXDebug.ProcessMenuItem) if (m_GFXDebug.ProcessMenuItem)
{ {
m_GFXDebug.ProcessMenuItem(id); m_GFXDebug.ProcessMenuItem(id);
} }
} }

View File

@ -12,84 +12,86 @@
class CGfxPlugin : public CPlugin class CGfxPlugin : public CPlugin
{ {
typedef struct { typedef struct
/* Menu */ {
/* Items should have an ID between 5101 and 5200 */ /* Menu */
HMENU hGFXMenu; /* Items should have an ID between 5101 and 5200 */
void(__cdecl *ProcessMenuItem) (int ID); void * hGFXMenu;
void(__cdecl *ProcessMenuItem) (int32_t ID);
/* Break Points */ /* Break Points */
BOOL UseBPoints; int32_t UseBPoints;
char BPPanelName[20]; char BPPanelName[20];
void(__cdecl *Add_BPoint) (void); void(__cdecl *Add_BPoint) (void);
void(__cdecl *CreateBPPanel) (HWND hDlg, RECT_STRUCT rcBox); void(__cdecl *CreateBPPanel) (void * hDlg, void * rcBox);
void(__cdecl *HideBPPanel) (void); void(__cdecl *HideBPPanel) (void);
void(__cdecl *PaintBPPanel) (WINDOWS_PAINTSTRUCT ps); void(__cdecl *PaintBPPanel) (void * ps);
void(__cdecl *ShowBPPanel) (void); void(__cdecl *ShowBPPanel) (void);
void(__cdecl *RefreshBpoints) (HWND hList); void(__cdecl *RefreshBpoints) (void * hList);
void(__cdecl *RemoveBpoint) (HWND hList, int index); void(__cdecl *RemoveBpoint) (void * hList, int32_t index);
void(__cdecl *RemoveAllBpoint) (void); void(__cdecl *RemoveAllBpoint) (void);
/* GFX command Window */ /* GFX command Window */
void(__cdecl *Enter_GFX_Commands_Window) (void); void(__cdecl *Enter_GFX_Commands_Window) (void);
} GFXDEBUG_INFO; } GFXDEBUG_INFO;
typedef struct { typedef struct
void(__cdecl *UpdateBreakPoints)(void); {
void(__cdecl *UpdateMemory)(void); void(__cdecl *UpdateBreakPoints)(void);
void(__cdecl *UpdateR4300iRegisters)(void); void(__cdecl *UpdateMemory)(void);
void(__cdecl *Enter_BPoint_Window)(void); void(__cdecl *UpdateR4300iRegisters)(void);
void(__cdecl *Enter_R4300i_Commands_Window)(void); void(__cdecl *Enter_BPoint_Window)(void);
void(__cdecl *Enter_R4300i_Register_Window)(void); void(__cdecl *Enter_R4300i_Commands_Window)(void);
void(__cdecl *Enter_RSP_Commands_Window) (void); void(__cdecl *Enter_R4300i_Register_Window)(void);
void(__cdecl *Enter_Memory_Window)(void); void(__cdecl *Enter_RSP_Commands_Window) (void);
} DEBUG_INFO; void(__cdecl *Enter_Memory_Window)(void);
} DEBUG_INFO;
public: public:
CGfxPlugin(void); CGfxPlugin(void);
~CGfxPlugin(); ~CGfxPlugin();
bool LoadFunctions ( void ); bool LoadFunctions(void);
bool Initiate(CN64System * System, CMainGui * RenderWindow); bool Initiate(CN64System * System, CMainGui * RenderWindow);
void(__cdecl *CaptureScreen) (const char *); void(__cdecl *CaptureScreen) (const char *);
void(__cdecl *ChangeWindow) (void); void(__cdecl *ChangeWindow) (void);
void(__cdecl *DrawScreen) (void); void(__cdecl *DrawScreen) (void);
void(__cdecl *DrawStatus) (const char * lpString, BOOL RightAlign); void(__cdecl *DrawStatus) (const char * lpString, int32_t RightAlign);
void(__cdecl *MoveScreen) (int xpos, int ypos); void(__cdecl *MoveScreen) (int32_t xpos, int32_t ypos);
void(__cdecl *ProcessDList) (void); void(__cdecl *ProcessDList) (void);
void(__cdecl *ProcessRDPList) (void); void(__cdecl *ProcessRDPList) (void);
void(__cdecl *ShowCFB) (void); void(__cdecl *ShowCFB) (void);
void(__cdecl *UpdateScreen) (void); void(__cdecl *UpdateScreen) (void);
void(__cdecl *ViStatusChanged) (void); void(__cdecl *ViStatusChanged) (void);
void(__cdecl *ViWidthChanged) (void); void(__cdecl *ViWidthChanged) (void);
void(__cdecl *SoftReset) (void); void(__cdecl *SoftReset) (void);
//Rom Browser //Rom Browser
HMENU(__cdecl * GetRomBrowserMenu) (void); /* Items should have an ID between 4101 and 4200 */ void *(__cdecl * GetRomBrowserMenu) (void); /* Items should have an ID between 4101 and 4200 */
void(__cdecl * OnRomBrowserMenuItem) (int MenuID, HWND hParent, BYTE * HEADER); void(__cdecl * OnRomBrowserMenuItem) (int32_t MenuID, void * hParent, uint8_t * HEADER);
HMENU GetDebugMenu(void) { return m_GFXDebug.hGFXMenu; } void * GetDebugMenu(void) { return m_GFXDebug.hGFXMenu; }
void ProcessMenuItem(int id); void ProcessMenuItem(int32_t id);
private: private:
CGfxPlugin(const CGfxPlugin&); // Disable copy constructor CGfxPlugin(const CGfxPlugin&); // Disable copy constructor
CGfxPlugin& operator=(const CGfxPlugin&); // Disable assignment CGfxPlugin& operator=(const CGfxPlugin&); // Disable assignment
virtual int GetDefaultSettingStartRange() const { return FirstGfxDefaultSet; } virtual int32_t GetDefaultSettingStartRange() const { return FirstGfxDefaultSet; }
virtual int GetSettingStartRange() const { return FirstGfxSettings; } virtual int32_t GetSettingStartRange() const { return FirstGfxSettings; }
PLUGIN_TYPE type() { return PLUGIN_TYPE_GFX; } PLUGIN_TYPE type() { return PLUGIN_TYPE_GFX; }
void UnloadPluginDetails ( void ); void UnloadPluginDetails(void);
GFXDEBUG_INFO m_GFXDebug; GFXDEBUG_INFO m_GFXDebug;
void(__cdecl *GetDebugInfo) (GFXDEBUG_INFO * GFXDebugInfo); void(__cdecl *GetDebugInfo) (GFXDEBUG_INFO * GFXDebugInfo);
void(__cdecl *InitiateDebugger)(DEBUG_INFO DebugInfo); void(__cdecl *InitiateDebugger)(DEBUG_INFO DebugInfo);
static void __cdecl DummyDrawScreen(void) {} static void __cdecl DummyDrawScreen(void) {}
static void __cdecl DummyMoveScreen(int /*xpos*/, int /*ypos*/) {} static void __cdecl DummyMoveScreen(int32_t /*xpos*/, int32_t /*ypos*/) {}
static void __cdecl DummyViStatusChanged(void) {} static void __cdecl DummyViStatusChanged(void) {}
static void __cdecl DummyViWidthChanged(void) {} static void __cdecl DummyViWidthChanged(void) {}
static void __cdecl DummySoftReset(void) {} static void __cdecl DummySoftReset(void) {}
}; };

View File

@ -11,214 +11,245 @@
#include "stdafx.h" #include "stdafx.h"
CPlugin::CPlugin() : CPlugin::CPlugin() :
DllAbout(NULL), DllAbout(NULL),
DllConfig(NULL), DllConfig(NULL),
CloseDLL(NULL), CloseDLL(NULL),
RomOpen(NULL), RomOpen(NULL),
RomClosed(NULL), RomClosed(NULL),
PluginOpened(NULL), PluginOpened(NULL),
SetSettingInfo(NULL), SetSettingInfo(NULL),
SetSettingInfo2(NULL), SetSettingInfo2(NULL),
SetSettingInfo3(NULL), SetSettingInfo3(NULL),
m_hDll(NULL), m_hDll(NULL),
m_Initialized(false), m_Initialized(false),
m_RomOpen(false) m_RomOpen(false)
{ {
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo)); memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
} }
CPlugin::~CPlugin() CPlugin::~CPlugin()
{ {
UnloadPlugin(); UnloadPlugin();
} }
bool CPlugin::Load (const char * FileName) bool CPlugin::Load (const char * FileName)
{ {
// Already loaded, so unload first. // Already loaded, so unload first.
if (m_hDll != NULL) if (m_hDll != NULL)
{ {
UnloadPlugin(); UnloadPlugin();
} }
// Try to load the plugin DLL // Try to load the plugin DLL
//Try to load the DLL library //Try to load the DLL library
if (bHaveDebugger()) if (bHaveDebugger())
{ {
m_hDll = LoadLibrary(FileName); m_hDll = LoadLibrary(FileName);
} }
else else
{ {
UINT LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); UINT LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
m_hDll = LoadLibrary(FileName); m_hDll = LoadLibrary(FileName);
SetErrorMode(LastErrorMode); SetErrorMode(LastErrorMode);
} }
if (m_hDll == NULL) if (m_hDll == NULL)
{ {
return false; return false;
} }
// Get DLL information // Get DLL information
void(__cdecl *GetDllInfo) (PLUGIN_INFO * PluginInfo); void(__cdecl *GetDllInfo) (PLUGIN_INFO * PluginInfo);
LoadFunction(GetDllInfo); LoadFunction(GetDllInfo);
if (GetDllInfo == NULL) { return false; } if (GetDllInfo == NULL) { return false; }
GetDllInfo(&m_PluginInfo); GetDllInfo(&m_PluginInfo);
if (!CPluginList::ValidPluginVersion(m_PluginInfo)) { return false; } if (!ValidPluginVersion(m_PluginInfo)) { return false; }
if (m_PluginInfo.Type != type()) { return false; } if (m_PluginInfo.Type != type()) { return false; }
CloseDLL = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "CloseDLL" ); CloseDLL = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "CloseDLL" );
RomOpen = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomOpen" ); RomOpen = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomOpen" );
RomClosed = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomClosed" ); RomClosed = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "RomClosed" );
PluginOpened = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "PluginLoaded" ); PluginOpened = (void (__cdecl *)(void)) GetProcAddress( (HMODULE)m_hDll, "PluginLoaded" );
DllConfig = (void (__cdecl *)(DWORD)) GetProcAddress( (HMODULE)m_hDll, "DllConfig" ); DllConfig = (void (__cdecl *)(uint32_t)) GetProcAddress( (HMODULE)m_hDll, "DllConfig" );
DllAbout = (void (__cdecl *)(HWND)) GetProcAddress( (HMODULE)m_hDll, "DllAbout" ); DllAbout = (void (__cdecl *)(void *)) GetProcAddress( (HMODULE)m_hDll, "DllAbout" );
SetSettingInfo3 = (void (__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo3" ); SetSettingInfo3 = (void (__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo3" );
if (SetSettingInfo3) if (SetSettingInfo3)
{ {
PLUGIN_SETTINGS3 info; PLUGIN_SETTINGS3 info;
info.FlushSettings = (void (*)( void * handle))CSettings::FlushSettings; info.FlushSettings = (void (*)( void * handle))CSettings::FlushSettings;
SetSettingInfo3(&info); SetSettingInfo3(&info);
} }
SetSettingInfo2 = (void (__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo2" ); SetSettingInfo2 = (void (__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo2" );
if (SetSettingInfo2) if (SetSettingInfo2)
{ {
PLUGIN_SETTINGS2 info; PLUGIN_SETTINGS2 info;
info.FindSystemSettingId = (unsigned int (*)( void * handle, const char * ))CSettings::FindSetting; info.FindSystemSettingId = (uint32_t (*)( void * handle, const char * ))CSettings::FindSetting;
SetSettingInfo2(&info); SetSettingInfo2(&info);
} }
SetSettingInfo = (void (__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo" ); SetSettingInfo = (void (__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress( (HMODULE)m_hDll, "SetSettingInfo" );
if (SetSettingInfo) if (SetSettingInfo)
{ {
PLUGIN_SETTINGS info; PLUGIN_SETTINGS info;
info.dwSize = sizeof(PLUGIN_SETTINGS); info.dwSize = sizeof(PLUGIN_SETTINGS);
info.DefaultStartRange = GetDefaultSettingStartRange(); info.DefaultStartRange = GetDefaultSettingStartRange();
info.SettingStartRange = GetSettingStartRange(); info.SettingStartRange = GetSettingStartRange();
info.MaximumSettings = MaxPluginSetting; info.MaximumSettings = MaxPluginSetting;
info.NoDefault = Default_None; info.NoDefault = Default_None;
info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile; info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile;
info.handle = g_Settings; info.handle = g_Settings;
info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, DWORD))&CSettings::RegisterSetting; info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, uint32_t))&CSettings::RegisterSetting;
info.GetSetting = (unsigned int(*)(void *, int))&CSettings::GetSetting; info.GetSetting = (uint32_t(*)(void *, int))&CSettings::GetSetting;
info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz; info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz;
info.SetSetting = (void(*)(void *, int, unsigned int))&CSettings::SetSetting; info.SetSetting = (void(*)(void *, int, uint32_t))&CSettings::SetSetting;
info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz; info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz;
info.UseUnregisteredSetting = NULL; info.UseUnregisteredSetting = NULL;
SetSettingInfo(&info); SetSettingInfo(&info);
} }
if (RomClosed == NULL) if (RomClosed == NULL)
return false; return false;
if (!LoadFunctions()) if (!LoadFunctions())
{ {
return false; return false;
} }
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Functions loaded",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Functions loaded",PluginType());
if (PluginOpened) if (PluginOpened)
{ {
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Plugin Opened",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Plugin Opened",PluginType());
PluginOpened(); PluginOpened();
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Plugin Opened",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Plugin Opened",PluginType());
} }
return true; return true;
} }
void CPlugin::RomOpened() void CPlugin::RomOpened()
{ {
if (m_RomOpen) if (m_RomOpen)
return; return;
if(RomOpen != NULL){ if(RomOpen != NULL){
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Open",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Open",PluginType());
RomOpen(); RomOpen();
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Open",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Open",PluginType());
} }
m_RomOpen = true; m_RomOpen = true;
} }
void CPlugin::RomClose() void CPlugin::RomClose()
{ {
if (!m_RomOpen) if (!m_RomOpen)
return; return;
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Close",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Before Rom Close",PluginType());
RomClosed(); RomClosed();
m_RomOpen = false; m_RomOpen = false;
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Close",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): After Rom Close",PluginType());
} }
void CPlugin::GameReset() void CPlugin::GameReset()
{ {
if (m_RomOpen) if (m_RomOpen)
{ {
RomClose(); RomClose();
if (RomOpen) if (RomOpen)
{ {
RomOpen(); RomOpen();
} }
} }
} }
void CPlugin::Close() void CPlugin::Close()
{ {
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Start",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Start",PluginType());
RomClose(); RomClose();
if (m_Initialized) if (m_Initialized)
{ {
CloseDLL(); CloseDLL();
m_Initialized = false; m_Initialized = false;
} }
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Done",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): Done",PluginType());
} }
void CPlugin::UnloadPlugin() void CPlugin::UnloadPlugin()
{ {
WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): unloading",PluginType()); WriteTraceF(PluginTraceType(),__FUNCTION__ "(%s): unloading",PluginType());
memset(&m_PluginInfo, 0, sizeof(m_PluginInfo)); memset(&m_PluginInfo, 0, sizeof(m_PluginInfo));
if (m_hDll != NULL) if (m_hDll != NULL)
{ {
UnloadPluginDetails(); UnloadPluginDetails();
FreeLibrary((HMODULE)m_hDll); FreeLibrary((HMODULE)m_hDll);
m_hDll = NULL; m_hDll = NULL;
} }
DllAbout = NULL; DllAbout = NULL;
CloseDLL = NULL; CloseDLL = NULL;
RomOpen = NULL; RomOpen = NULL;
RomClosed = NULL; RomClosed = NULL;
PluginOpened = NULL; PluginOpened = NULL;
DllConfig = NULL; DllConfig = NULL;
SetSettingInfo = NULL; SetSettingInfo = NULL;
SetSettingInfo2 = NULL; SetSettingInfo2 = NULL;
SetSettingInfo3 = NULL; SetSettingInfo3 = NULL;
} }
const char * CPlugin::PluginType () const const char * CPlugin::PluginType () const
{ {
switch (m_PluginInfo.Type) switch (m_PluginInfo.Type)
{ {
case PLUGIN_TYPE_RSP: return "RSP"; case PLUGIN_TYPE_RSP: return "RSP";
case PLUGIN_TYPE_GFX: return "GFX"; case PLUGIN_TYPE_GFX: return "GFX";
case PLUGIN_TYPE_AUDIO: return "Audio"; case PLUGIN_TYPE_AUDIO: return "Audio";
case PLUGIN_TYPE_CONTROLLER: return "Control"; case PLUGIN_TYPE_CONTROLLER: return "Control";
} }
return "Unknown"; return "Unknown";
} }
TraceType CPlugin::PluginTraceType () const TraceType CPlugin::PluginTraceType () const
{ {
switch (m_PluginInfo.Type) switch (m_PluginInfo.Type)
{ {
case PLUGIN_TYPE_RSP: return TraceRSP; case PLUGIN_TYPE_RSP: return TraceRSP;
case PLUGIN_TYPE_GFX: return TraceGfxPlugin; case PLUGIN_TYPE_GFX: return TraceGfxPlugin;
case PLUGIN_TYPE_AUDIO: return TraceDebug; case PLUGIN_TYPE_AUDIO: return TraceDebug;
case PLUGIN_TYPE_CONTROLLER: return TraceDebug; case PLUGIN_TYPE_CONTROLLER: return TraceDebug;
} }
return TraceDebug; return TraceDebug;
}
bool CPlugin::ValidPluginVersion ( PLUGIN_INFO & PluginInfo )
{
switch (PluginInfo.Type)
{
case PLUGIN_TYPE_RSP:
if (!PluginInfo.MemoryBswaped) { return false; }
if (PluginInfo.Version == 0x0001) { return true; }
if (PluginInfo.Version == 0x0100) { return true; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
break;
case PLUGIN_TYPE_GFX:
if (!PluginInfo.MemoryBswaped) { return false; }
if (PluginInfo.Version == 0x0102) { return true; }
if (PluginInfo.Version == 0x0103) { return true; }
if (PluginInfo.Version == 0x0104) { return true; }
break;
case PLUGIN_TYPE_AUDIO:
if (!PluginInfo.MemoryBswaped) { return false; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
break;
case PLUGIN_TYPE_CONTROLLER:
if (PluginInfo.Version == 0x0100) { return true; }
if (PluginInfo.Version == 0x0101) { return true; }
if (PluginInfo.Version == 0x0102) { return true; }
break;
}
return FALSE;
} }

View File

@ -11,55 +11,56 @@
#pragma once #pragma once
class CPlugin : class CPlugin :
private CDebugSettings private CDebugSettings
{ {
public: public:
CPlugin(); CPlugin();
virtual ~CPlugin(); virtual ~CPlugin();
inline const char * PluginName() const { return m_PluginInfo.Name; } inline const char * PluginName() const { return m_PluginInfo.Name; }
inline bool Initialized() { return m_Initialized; } inline bool Initialized() { return m_Initialized; }
virtual int GetDefaultSettingStartRange() const = 0; virtual int32_t GetDefaultSettingStartRange() const = 0;
virtual int GetSettingStartRange() const = 0; virtual int32_t GetSettingStartRange() const = 0;
bool Load ( const char * FileName ); bool Load(const char * FileName);
void RomOpened(); void RomOpened();
void RomClose(); void RomClose();
void GameReset(); void GameReset();
void Close(); void Close();
void(__cdecl *DllAbout) (HWND hWnd); void(__cdecl *DllAbout) (void * hWnd);
void(__cdecl *DllConfig) (DWORD hParent); void(__cdecl *DllConfig) (uint32_t hParent);
static bool ValidPluginVersion ( PLUGIN_INFO & PluginInfo );
protected: protected:
void UnloadPlugin();
const char * PluginType() const;
TraceType PluginTraceType() const;
virtual void UnloadPluginDetails() = 0;
virtual PLUGIN_TYPE type() = 0;
virtual bool LoadFunctions(void) = 0;
void UnloadPlugin(); void(__cdecl *CloseDLL) (void);
const char * PluginType () const; void(__cdecl *RomOpen) (void);
TraceType PluginTraceType () const; void(__cdecl *RomClosed) (void);
virtual void UnloadPluginDetails() = 0; void(__cdecl *PluginOpened)(void);
virtual PLUGIN_TYPE type() = 0; void(__cdecl *SetSettingInfo) (PLUGIN_SETTINGS *);
virtual bool LoadFunctions ( void ) = 0; void(__cdecl *SetSettingInfo2) (PLUGIN_SETTINGS2 *);
void(__cdecl *SetSettingInfo3) (PLUGIN_SETTINGS3 *);
void(__cdecl *CloseDLL) (void); void * m_hDll;
void(__cdecl *RomOpen) (void); bool m_Initialized, m_RomOpen;
void(__cdecl *RomClosed) (void); PLUGIN_INFO m_PluginInfo;
void(__cdecl *PluginOpened)(void);
void(__cdecl *SetSettingInfo) (PLUGIN_SETTINGS *);
void(__cdecl *SetSettingInfo2) (PLUGIN_SETTINGS2 *);
void(__cdecl *SetSettingInfo3) (PLUGIN_SETTINGS3 *);
void * m_hDll; // Loads a function pointer from the currently loaded DLL
bool m_Initialized, m_RomOpen; template <typename T>
PLUGIN_INFO m_PluginInfo; void _LoadFunction(const char * szFunctionName, T & functionPointer) {
functionPointer = (T)GetProcAddress((HMODULE)m_hDll, szFunctionName);
}
// Loads a function pointer from the currently loaded DLL // Simple wrapper around _LoadFunction() to avoid having to specify the same two arguments
template <typename T> // i.e. _LoadFunction("CloseDLL", CloseDLL);
void _LoadFunction(const char * szFunctionName, T & functionPointer) {
functionPointer = (T)GetProcAddress((HMODULE)m_hDll, szFunctionName);
}
// Simple wrapper around _LoadFunction() to avoid having to specify the same two arguments
// i.e. _LoadFunction("CloseDLL", CloseDLL);
#define LoadFunction(functionName) _LoadFunction(#functionName, functionName) #define LoadFunction(functionName) _LoadFunction(#functionName, functionName)
}; };

View File

@ -10,36 +10,39 @@
****************************************************************************/ ****************************************************************************/
#include "stdafx.h" #include "stdafx.h"
CPlugins::CPlugins (const stdstr & PluginDir): CPlugins::CPlugins(const stdstr & PluginDir) :
m_RenderWindow(NULL), m_DummyWindow(NULL), m_RenderWindow(NULL), m_DummyWindow(NULL),
m_PluginDir(PluginDir), m_Gfx(NULL), m_Audio(NULL), m_PluginDir(PluginDir),
m_RSP(NULL), m_Control(NULL) m_Gfx(NULL),
m_Audio(NULL),
m_RSP(NULL),
m_Control(NULL)
{ {
CreatePlugins(); CreatePlugins();
g_Settings->RegisterChangeCB(Plugin_RSP_Current,this,(CSettings::SettingChangedFunc)PluginChanged); g_Settings->RegisterChangeCB(Plugin_RSP_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Plugin_GFX_Current,this,(CSettings::SettingChangedFunc)PluginChanged); g_Settings->RegisterChangeCB(Plugin_GFX_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Plugin_AUDIO_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_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(Plugin_UseHleAudio, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_Gfx,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_Audio, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_Contr,this,(CSettings::SettingChangedFunc)PluginChanged); g_Settings->RegisterChangeCB(Game_EditPlugin_Contr, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->RegisterChangeCB(Game_EditPlugin_RSP,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_RSP_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_GFX_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_AUDIO_Current, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Plugin_CONT_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(Plugin_UseHleAudio, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_Gfx,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_Audio, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_Contr,this,(CSettings::SettingChangedFunc)PluginChanged); g_Settings->UnregisterChangeCB(Game_EditPlugin_Contr, this, (CSettings::SettingChangedFunc)PluginChanged);
g_Settings->UnregisterChangeCB(Game_EditPlugin_RSP,this,(CSettings::SettingChangedFunc)PluginChanged); g_Settings->UnregisterChangeCB(Game_EditPlugin_RSP, this, (CSettings::SettingChangedFunc)PluginChanged);
DestroyGfxPlugin(); DestroyGfxPlugin();
DestroyAudioPlugin(); DestroyAudioPlugin();
@ -47,18 +50,18 @@ CPlugins::~CPlugins (void)
DestroyControlPlugin(); DestroyControlPlugin();
} }
void CPlugins::PluginChanged ( CPlugins * _this ) void CPlugins::PluginChanged(CPlugins * _this)
{ {
if (g_Settings->LoadBool(Game_TempLoaded) == true) if (g_Settings->LoadBool(Game_TempLoaded) == true)
{ {
return; return;
} }
bool bGfxChange = _stricmp(_this->m_GfxFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()) != 0; bool bGfxChange = _stricmp(_this->m_GfxFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()) != 0;
bool bAudioChange = _stricmp(_this->m_AudioFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()) != 0; bool bAudioChange = _stricmp(_this->m_AudioFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()) != 0;
bool bRspChange = _stricmp(_this->m_RSPFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0; bool bRspChange = _stricmp(_this->m_RSPFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0;
bool bContChange = _stricmp(_this->m_ControlFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0; bool bContChange = _stricmp(_this->m_ControlFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0;
if ( bGfxChange || bAudioChange || bRspChange || bContChange ) if (bGfxChange || bAudioChange || bRspChange || bContChange)
{ {
if (g_Settings->LoadBool(GameRunning_CPU_Running)) if (g_Settings->LoadBool(GameRunning_CPU_Running))
{ {
@ -77,38 +80,38 @@ void CPlugins::PluginChanged ( CPlugins * _this )
} }
template <typename plugin_type> template <typename plugin_type>
static void LoadPlugin (SettingID PluginSettingID, SettingID PluginVerSettingID, plugin_type * & plugin, const char * PluginDir, stdstr & FileName, TraceType TraceLevel, const char * type) static void LoadPlugin(SettingID PluginSettingID, SettingID PluginVerSettingID, plugin_type * & plugin, const char * PluginDir, stdstr & FileName, TraceType TraceLevel, const char * type)
{ {
if (plugin != NULL) if (plugin != NULL)
{ {
return; return;
} }
FileName = g_Settings->LoadStringVal(PluginSettingID); FileName = g_Settings->LoadStringVal(PluginSettingID);
CPath PluginFileName(PluginDir,FileName.c_str()); CPath PluginFileName(PluginDir, FileName.c_str());
plugin = new plugin_type(); plugin = new plugin_type();
if (plugin) if (plugin)
{ {
WriteTraceF(TraceLevel,__FUNCTION__ ": %s Loading (%s): Starting",type,(LPCTSTR)PluginFileName); WriteTraceF(TraceLevel, __FUNCTION__ ": %s Loading (%s): Starting", type, (const char *)PluginFileName);
if (plugin->Load(PluginFileName)) if (plugin->Load(PluginFileName))
{ {
WriteTraceF(TraceLevel,__FUNCTION__ ": %s Current Ver: %s",type,plugin->PluginName()); WriteTraceF(TraceLevel, __FUNCTION__ ": %s Current Ver: %s", type, plugin->PluginName());
g_Settings->SaveString(PluginVerSettingID,plugin->PluginName()); g_Settings->SaveString(PluginVerSettingID, plugin->PluginName());
} }
else else
{ {
WriteTraceF(TraceError,__FUNCTION__ ": Failed to load %s",(LPCTSTR)PluginFileName); WriteTraceF(TraceError, __FUNCTION__ ": Failed to load %s", (const char *)PluginFileName);
delete plugin; delete plugin;
plugin = NULL; plugin = NULL;
} }
WriteTraceF(TraceLevel,__FUNCTION__ ": %s Loading Done",type); WriteTraceF(TraceLevel, __FUNCTION__ ": %s Loading Done", type);
} }
else else
{ {
WriteTraceF(TraceError,__FUNCTION__ ": Failed to allocate %s plugin",type); WriteTraceF(TraceError, __FUNCTION__ ": Failed to allocate %s plugin", type);
} }
} }
void CPlugins::CreatePlugins( void ) void CPlugins::CreatePlugins(void)
{ {
LoadPlugin(Game_Plugin_Gfx, Plugin_GFX_CurVer, m_Gfx, m_PluginDir.c_str(), m_GfxFile, TraceGfxPlugin, "GFX"); LoadPlugin(Game_Plugin_Gfx, Plugin_GFX_CurVer, m_Gfx, m_PluginDir.c_str(), m_GfxFile, TraceGfxPlugin, "GFX");
LoadPlugin(Game_Plugin_Audio, Plugin_AUDIO_CurVer, m_Audio, m_PluginDir.c_str(), m_AudioFile, TraceDebug, "Audio"); LoadPlugin(Game_Plugin_Audio, Plugin_AUDIO_CurVer, m_Audio, m_PluginDir.c_str(), m_AudioFile, TraceDebug, "Audio");
@ -118,9 +121,9 @@ void CPlugins::CreatePlugins( void )
//Enable debugger //Enable debugger
if (m_RSP != NULL && m_RSP->EnableDebugging) if (m_RSP != NULL && m_RSP->EnableDebugging)
{ {
WriteTrace(TraceRSP,__FUNCTION__ ": EnableDebugging starting"); WriteTrace(TraceRSP, __FUNCTION__ ": EnableDebugging starting");
m_RSP->EnableDebugging(bHaveDebugger()); m_RSP->EnableDebugging(bHaveDebugger());
WriteTrace(TraceRSP,__FUNCTION__ ": EnableDebugging done"); WriteTrace(TraceRSP, __FUNCTION__ ": EnableDebugging done");
} }
if (bHaveDebugger()) if (bHaveDebugger())
@ -129,7 +132,7 @@ void CPlugins::CreatePlugins( void )
} }
} }
void CPlugins::GameReset ( void ) void CPlugins::GameReset(void)
{ {
if (m_Gfx) if (m_Gfx)
{ {
@ -149,67 +152,67 @@ void CPlugins::GameReset ( void )
} }
} }
void CPlugins::DestroyGfxPlugin( void ) void CPlugins::DestroyGfxPlugin(void)
{ {
if (m_Gfx == NULL) if (m_Gfx == NULL)
{ {
return; return;
} }
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": before delete m_Gfx"); WriteTrace(TraceGfxPlugin, __FUNCTION__ ": before delete m_Gfx");
delete m_Gfx; delete m_Gfx;
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": after delete m_Gfx"); WriteTrace(TraceGfxPlugin, __FUNCTION__ ": after delete m_Gfx");
m_Gfx = NULL; m_Gfx = NULL;
// g_Settings->UnknownSetting_GFX = NULL; // g_Settings->UnknownSetting_GFX = NULL;
DestroyRspPlugin(); DestroyRspPlugin();
} }
void CPlugins::DestroyAudioPlugin( void ) void CPlugins::DestroyAudioPlugin(void)
{ {
if (m_Audio == NULL) if (m_Audio == NULL)
{ {
return; return;
} }
WriteTrace(TraceDebug,__FUNCTION__ ": 5"); WriteTrace(TraceDebug, __FUNCTION__ ": 5");
m_Audio->Close(); m_Audio->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 6"); WriteTrace(TraceDebug, __FUNCTION__ ": 6");
delete m_Audio; delete m_Audio;
WriteTrace(TraceDebug,__FUNCTION__ ": 7"); WriteTrace(TraceDebug, __FUNCTION__ ": 7");
m_Audio = NULL; m_Audio = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 8"); WriteTrace(TraceDebug, __FUNCTION__ ": 8");
// g_Settings->UnknownSetting_AUDIO = NULL; // g_Settings->UnknownSetting_AUDIO = NULL;
DestroyRspPlugin(); DestroyRspPlugin();
} }
void CPlugins::DestroyRspPlugin( void ) void CPlugins::DestroyRspPlugin(void)
{ {
if (m_RSP == NULL) if (m_RSP == NULL)
{ {
return; return;
} }
WriteTrace(TraceDebug,__FUNCTION__ ": 9"); WriteTrace(TraceDebug, __FUNCTION__ ": 9");
m_RSP->Close(); m_RSP->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 10"); WriteTrace(TraceDebug, __FUNCTION__ ": 10");
delete m_RSP; delete m_RSP;
WriteTrace(TraceDebug,__FUNCTION__ ": 11"); WriteTrace(TraceDebug, __FUNCTION__ ": 11");
m_RSP = NULL; m_RSP = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 12"); WriteTrace(TraceDebug, __FUNCTION__ ": 12");
// g_Settings->UnknownSetting_RSP = NULL; // g_Settings->UnknownSetting_RSP = NULL;
} }
void CPlugins::DestroyControlPlugin( void ) void CPlugins::DestroyControlPlugin(void)
{ {
if (m_Control == NULL) if (m_Control == NULL)
{ {
return; return;
} }
WriteTrace(TraceDebug,__FUNCTION__ ": 13"); WriteTrace(TraceDebug, __FUNCTION__ ": 13");
m_Control->Close(); m_Control->Close();
WriteTrace(TraceDebug,__FUNCTION__ ": 14"); WriteTrace(TraceDebug, __FUNCTION__ ": 14");
delete m_Control; delete m_Control;
WriteTrace(TraceDebug,__FUNCTION__ ": 15"); WriteTrace(TraceDebug, __FUNCTION__ ": 15");
m_Control = NULL; m_Control = NULL;
WriteTrace(TraceDebug,__FUNCTION__ ": 16"); WriteTrace(TraceDebug, __FUNCTION__ ": 16");
// g_Settings->UnknownSetting_CTRL = NULL; // g_Settings->UnknownSetting_CTRL = NULL;
} }
void CPlugins::SetRenderWindows( CMainGui * RenderWindow, CMainGui * DummyWindow ) void CPlugins::SetRenderWindows( CMainGui * RenderWindow, CMainGui * DummyWindow )
@ -218,7 +221,7 @@ void CPlugins::SetRenderWindows( CMainGui * RenderWindow, CMainGui * DummyWindow
m_DummyWindow = DummyWindow; m_DummyWindow = DummyWindow;
} }
void CPlugins::RomOpened ( void ) void CPlugins::RomOpened(void)
{ {
m_Gfx->RomOpened(); m_Gfx->RomOpened();
m_RSP->RomOpened(); m_RSP->RomOpened();
@ -226,7 +229,7 @@ void CPlugins::RomOpened ( void )
m_Control->RomOpened(); m_Control->RomOpened();
} }
void CPlugins::RomClosed ( void ) void CPlugins::RomClosed(void)
{ {
m_Gfx->RomClose(); m_Gfx->RomClose();
m_RSP->RomClose(); m_RSP->RomClose();
@ -234,32 +237,32 @@ void CPlugins::RomClosed ( void )
m_Control->RomClose(); m_Control->RomClose();
} }
bool CPlugins::Initiate ( CN64System * System ) bool CPlugins::Initiate(CN64System * System)
{ {
WriteTrace(TraceDebug,__FUNCTION__ ": Start"); WriteTrace(TraceDebug, __FUNCTION__ ": Start");
//Check to make sure we have the plugin available to be used //Check to make sure we have the plugin available to be used
if (m_Gfx == NULL) { return false; } if (m_Gfx == NULL) { return false; }
if (m_Audio == NULL) { return false; } if (m_Audio == NULL) { return false; }
if (m_RSP == NULL) { return false; } if (m_RSP == NULL) { return false; }
if (m_Control == NULL) { return false; } if (m_Control == NULL) { return false; }
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Initiate Starting"); WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Gfx Initiate Starting");
if (!m_Gfx->Initiate(System,m_RenderWindow)) { return false; } if (!m_Gfx->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Initiate Done"); WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Gfx Initiate Done");
WriteTrace(TraceDebug,__FUNCTION__ ": Audio Initiate Starting"); WriteTrace(TraceDebug, __FUNCTION__ ": Audio Initiate Starting");
if (!m_Audio->Initiate(System,m_RenderWindow)) { return false; } if (!m_Audio->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceDebug,__FUNCTION__ ": Audio Initiate Done"); WriteTrace(TraceDebug, __FUNCTION__ ": Audio Initiate Done");
WriteTrace(TraceDebug, __FUNCTION__ ": Control Initiate Starting"); WriteTrace(TraceDebug, __FUNCTION__ ": Control Initiate Starting");
if (!m_Control->Initiate(System,m_RenderWindow)) { return false; } if (!m_Control->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceDebug, __FUNCTION__ ": Control Initiate Done"); WriteTrace(TraceDebug, __FUNCTION__ ": Control Initiate Done");
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Initiate Starting"); WriteTrace(TraceRSP, __FUNCTION__ ": RSP Initiate Starting");
if (!m_RSP->Initiate(this,System)) { return false; } if (!m_RSP->Initiate(this, System)) { return false; }
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Initiate Done"); WriteTrace(TraceRSP, __FUNCTION__ ": RSP Initiate Done");
WriteTrace(TraceDebug,__FUNCTION__ ": Done"); WriteTrace(TraceDebug, __FUNCTION__ ": Done");
return true; return true;
} }
bool CPlugins::ResetInUiThread ( CN64System * System ) bool CPlugins::ResetInUiThread(CN64System * System)
{ {
#if defined(WINDOWS_UI) #if defined(WINDOWS_UI)
return m_RenderWindow->ResetPlugins(this, System); return m_RenderWindow->ResetPlugins(this, System);
@ -269,14 +272,14 @@ bool CPlugins::ResetInUiThread ( CN64System * System )
#endif #endif
} }
bool CPlugins::Reset ( CN64System * System ) bool CPlugins::Reset(CN64System * System)
{ {
WriteTrace(TraceDebug,__FUNCTION__ ": Start"); WriteTrace(TraceDebug, __FUNCTION__ ": Start");
bool bGfxChange = _stricmp(m_GfxFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()) != 0; bool bGfxChange = _stricmp(m_GfxFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()) != 0;
bool bAudioChange = _stricmp(m_AudioFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()) != 0; bool bAudioChange = _stricmp(m_AudioFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()) != 0;
bool bRspChange = _stricmp(m_RSPFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0; bool bRspChange = _stricmp(m_RSPFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0;
bool bContChange = _stricmp(m_ControlFile.c_str(),g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0; bool bContChange = _stricmp(m_ControlFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0;
//if GFX and Audio has changed we also need to force reset of RSP //if GFX and Audio has changed we also need to force reset of RSP
if (bGfxChange || bAudioChange) if (bGfxChange || bAudioChange)
@ -289,17 +292,17 @@ bool CPlugins::Reset ( CN64System * System )
CreatePlugins(); CreatePlugins();
if (m_Gfx && bGfxChange) if (m_Gfx && bGfxChange)
{ {
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Initiate Starting"); WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Gfx Initiate Starting");
if (!m_Gfx->Initiate(System,m_RenderWindow)) { return false; } if (!m_Gfx->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Gfx Initiate Done"); WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Gfx Initiate Done");
} }
if (m_Audio && bAudioChange) if (m_Audio && bAudioChange)
{ {
WriteTrace(TraceDebug,__FUNCTION__ ": Audio Initiate Starting"); WriteTrace(TraceDebug, __FUNCTION__ ": Audio Initiate Starting");
if (!m_Audio->Initiate(System,m_RenderWindow)) { return false; } if (!m_Audio->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceDebug,__FUNCTION__ ": Audio Initiate Done"); WriteTrace(TraceDebug, __FUNCTION__ ": Audio Initiate Done");
} }
if (m_Control && bContChange) if (m_Control && bContChange)
{ {
@ -307,22 +310,26 @@ bool CPlugins::Reset ( CN64System * System )
if (!m_Control->Initiate(System,m_RenderWindow)) { return false; } if (!m_Control->Initiate(System,m_RenderWindow)) { return false; }
WriteTrace(TraceDebug, __FUNCTION__ ": Control Initiate Done"); WriteTrace(TraceDebug, __FUNCTION__ ": Control Initiate Done");
} }
if (m_RSP && bRspChange) if (m_RSP && bRspChange)
{ {
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Initiate Starting"); WriteTrace(TraceRSP, __FUNCTION__ ": RSP Initiate Starting");
if (!m_RSP->Initiate(this,System)) { return false; } if (!m_RSP->Initiate(this, System)) { return false; }
WriteTrace(TraceRSP,__FUNCTION__ ": RSP Initiate Done"); WriteTrace(TraceRSP, __FUNCTION__ ": RSP Initiate Done");
} }
WriteTrace(TraceDebug,__FUNCTION__ ": Done"); WriteTrace(TraceDebug, __FUNCTION__ ": Done");
return true; return true;
} }
void CPlugins::ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ) { void CPlugins::ConfigPlugin(uint32_t hParent, PLUGIN_TYPE Type)
switch (Type) { {
switch (Type)
{
case PLUGIN_TYPE_RSP: case PLUGIN_TYPE_RSP:
if (m_RSP == NULL || m_RSP->DllConfig == NULL) { break; } if (m_RSP == NULL || m_RSP->DllConfig == NULL) { break; }
if (!m_RSP->Initialized()) { if (!m_RSP->Initialized())
if (!m_RSP->Initiate(NULL,NULL)) { {
if (!m_RSP->Initiate(NULL, NULL))
{
break; break;
} }
} }
@ -330,8 +337,10 @@ void CPlugins::ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ) {
break; break;
case PLUGIN_TYPE_GFX: case PLUGIN_TYPE_GFX:
if (m_Gfx == NULL || m_Gfx->DllConfig == NULL) { break; } if (m_Gfx == NULL || m_Gfx->DllConfig == NULL) { break; }
if (!m_Gfx->Initialized()) { if (!m_Gfx->Initialized())
if (!m_Gfx->Initiate(NULL,m_DummyWindow)) { {
if (!m_Gfx->Initiate(NULL, NULL))
{
break; break;
} }
} }
@ -339,8 +348,10 @@ void CPlugins::ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ) {
break; break;
case PLUGIN_TYPE_AUDIO: case PLUGIN_TYPE_AUDIO:
if (m_Audio == NULL || m_Audio->DllConfig == NULL) { break; } if (m_Audio == NULL || m_Audio->DllConfig == NULL) { break; }
if (!m_Audio->Initialized()) { if (!m_Audio->Initialized())
if (!m_Audio->Initiate(NULL,m_DummyWindow)) { {
if (!m_Audio->Initiate(NULL, NULL))
{
break; break;
} }
} }
@ -348,8 +359,10 @@ void CPlugins::ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ) {
break; break;
case PLUGIN_TYPE_CONTROLLER: case PLUGIN_TYPE_CONTROLLER:
if (m_Control == NULL || m_Control->DllConfig == NULL) { break; } if (m_Control == NULL || m_Control->DllConfig == NULL) { break; }
if (!m_Control->Initialized()) { if (!m_Control->Initialized())
if (!m_Control->Initiate(NULL,m_DummyWindow)) { {
if (!m_Control->Initiate(NULL, NULL))
{
break; break;
} }
} }
@ -358,76 +371,63 @@ void CPlugins::ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ) {
} }
} }
void DummyCheckInterrupts ( void ) { void DummyCheckInterrupts(void)
{
} }
void DummyFunction (void) { void DummyFunction(void)
{
} }
#include <windows.h> bool CPlugins::CopyPlugins(const stdstr & DstDir) const
{
void CPlugins::CreatePluginDir ( const stdstr & DstDir ) const {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR],
fname[_MAX_FNAME], ext[_MAX_EXT];
_splitpath(DstDir.c_str(), drive, dir, fname, ext );
_makepath(path_buffer, drive, dir, "", "" );
if (CreateDirectory(path_buffer,NULL) == 0 && GetLastError() == ERROR_PATH_NOT_FOUND)
{
path_buffer[strlen(path_buffer) - 1] = 0;
CreatePluginDir(stdstr(path_buffer));
CreateDirectory(path_buffer,NULL);
}
}
bool CPlugins::CopyPlugins ( const stdstr & DstDir ) const
{
//Copy GFX Plugin //Copy GFX Plugin
CPath srcGfxPlugin(m_PluginDir.c_str(),g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()); CPath srcGfxPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str());
CPath dstGfxPlugin(DstDir.c_str(),g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str()); CPath dstGfxPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Gfx).c_str());
if (CopyFile(srcGfxPlugin,dstGfxPlugin,false) == 0) if (!dstGfxPlugin.DirectoryExists())
{ {
if (GetLastError() == ERROR_PATH_NOT_FOUND) { dstGfxPlugin.DirectoryCreate(); } dstGfxPlugin.DirectoryCreate();
if (!CopyFile(srcGfxPlugin,dstGfxPlugin,false)) }
{ if (!srcGfxPlugin.CopyTo(dstGfxPlugin))
return false; {
} return false;
} }
//Copy m_Audio Plugin //Copy m_Audio Plugin
CPath srcAudioPlugin(m_PluginDir.c_str(),g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()); CPath srcAudioPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str());
CPath dstAudioPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str()); CPath dstAudioPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Audio).c_str());
if (CopyFile(srcAudioPlugin,dstAudioPlugin,false) == 0) { if (!dstAudioPlugin.DirectoryExists())
if (GetLastError() == ERROR_PATH_NOT_FOUND) { dstAudioPlugin.DirectoryCreate(); } {
if (!CopyFile(srcAudioPlugin,dstAudioPlugin,false)) dstAudioPlugin.DirectoryCreate();
{ }
return false; if (!srcAudioPlugin.CopyTo(dstAudioPlugin))
} {
return false;
} }
//Copy RSP Plugin //Copy RSP Plugin
CPath srcRSPPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()); CPath srcRSPPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str());
CPath dstRSPPlugin(DstDir.c_str(),g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()); CPath dstRSPPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str());
if (CopyFile(srcRSPPlugin,dstRSPPlugin,false) == 0) { if (!dstRSPPlugin.DirectoryExists())
if (GetLastError() == ERROR_PATH_NOT_FOUND) { dstRSPPlugin.DirectoryCreate(); } {
if (!CopyFile(srcRSPPlugin,dstRSPPlugin,false)) dstRSPPlugin.DirectoryCreate();
{ }
return false; if (!srcRSPPlugin.CopyTo(dstRSPPlugin))
} {
return false;
} }
//Copy Controller Plugin //Copy Controller Plugin
CPath srcContPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()); CPath srcContPlugin(m_PluginDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str());
CPath dstContPlugin(DstDir.c_str(),g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()); CPath dstContPlugin(DstDir.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str());
if (!dstContPlugin.DirectoryExists())
{
dstContPlugin.DirectoryCreate();
}
if (!srcContPlugin.CopyTo(dstContPlugin)) if (!srcContPlugin.CopyTo(dstContPlugin))
{ {
if (GetLastError() == ERROR_PATH_NOT_FOUND) { dstContPlugin.DirectoryCreate(); } return false;
if (!CopyFile(srcContPlugin,dstContPlugin,false))
{
DWORD dwError = GetLastError();
dwError = dwError;
return false;
}
} }
return true; return true;
} }

View File

@ -11,137 +11,133 @@
#pragma once #pragma once
#include <list> #include <list>
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned __int64 QWORD;
#ifndef PLUGIN_INFO_STRUCT #ifndef PLUGIN_INFO_STRUCT
#define PLUGIN_INFO_STRUCT #define PLUGIN_INFO_STRUCT
typedef struct { typedef struct
WORD Version; /* Should be set to 1 */ {
WORD Type; /* Set to PLUGIN_TYPE_GFX */ uint16_t Version; /* Should be set to 1 */
char Name[100]; /* Name of the DLL */ uint16_t Type; /* Set to PLUGIN_TYPE_GFX */
char Name[100]; /* Name of the DLL */
/* If DLL supports memory these memory options then set them to TRUE or FALSE /* If DLL supports memory these memory options then set them to TRUE or FALSE
if it does not support it */ if it does not support it */
BOOL NormalMemory; /* a normal BYTE array */ int32_t NormalMemory; /* a normal BYTE array */
BOOL MemoryBswaped; /* a normal BYTE array where the memory has been pre int32_t MemoryBswaped; /* a normal BYTE array where the memory has been pre
bswap on a dword (32 bits) boundry */ bswap on a dword (32 bits) boundry */
} PLUGIN_INFO; } PLUGIN_INFO;
#endif #endif
// enum's // enum's
enum SETTING_DATA_TYPE { enum SETTING_DATA_TYPE
Data_DWORD_General = 0, // A unsigned int setting used anywhere {
Data_String_General = 1, // A string setting used anywhere Data_DWORD_General = 0, // A uint32_t setting used anywhere
Data_DWORD_Game = 2, // A unsigned int associated with the current game Data_String_General = 1, // A string setting used anywhere
Data_String_Game = 3, // A string associated with the current game Data_DWORD_Game = 2, // A uint32_t associated with the current game
Data_DWORD_RDB = 4, // A unsigned int associated with the current game in the rom database Data_String_Game = 3, // A string associated with the current game
Data_String_RDB = 5, // A string associated with the current game in the rom database Data_DWORD_RDB = 4, // A uint32_t associated with the current game in the rom database
Data_DWORD_RDB_Setting = 6, // A unsigned int read from the rom database, with config file Data_String_RDB = 5, // A string associated with the current game in the rom database
Data_String_RDB_Setting = 7, // A string read from the rom database, with config file Data_DWORD_RDB_Setting = 6, // A uint32_t read from the rom database, with config file
Data_String_RDB_Setting = 7, // A string read from the rom database, with config file
}; };
typedef struct { typedef struct
DWORD dwSize; {
int DefaultStartRange; uint32_t dwSize;
int SettingStartRange; int32_t DefaultStartRange;
int MaximumSettings; int32_t SettingStartRange;
int NoDefault; int32_t MaximumSettings;
int DefaultLocation; int32_t NoDefault;
void * handle; int32_t DefaultLocation;
unsigned int (*GetSetting) ( void * handle, int ID ); void * handle;
const char * (*GetSettingSz) ( void * handle, int ID, char * Buffer, int BufferLen ); uint32_t(*GetSetting) (void * handle, int32_t ID);
void (*SetSetting) ( void * handle, int ID, unsigned int Value ); const char * (*GetSettingSz) (void * handle, int32_t ID, char * Buffer, int32_t BufferLen);
void (*SetSettingSz) ( void * handle, int ID, const char * Value ); void(*SetSetting) (void * handle, int32_t ID, uint32_t Value);
void (*RegisterSetting) ( void * handle, int ID, int DefaultID, SettingDataType Type, void(*SetSettingSz) (void * handle, int32_t ID, const char * Value);
SettingType Location, const char * Category, const char * DefaultStr, DWORD Value ); void(*RegisterSetting) (void * handle, int32_t ID, int32_t DefaultID, SettingDataType Type,
void (*UseUnregisteredSetting) (int ID); SettingType Location, const char * Category, const char * DefaultStr, uint32_t Value);
void(*UseUnregisteredSetting) (int32_t ID);
} PLUGIN_SETTINGS; } PLUGIN_SETTINGS;
typedef struct { typedef struct
unsigned int (*FindSystemSettingId) ( void * handle, const char * Name ); {
uint32_t(*FindSystemSettingId) (void * handle, const char * Name);
} PLUGIN_SETTINGS2; } PLUGIN_SETTINGS2;
typedef struct { typedef struct
void (*FlushSettings) ( void * handle ); {
void(*FlushSettings) (void * handle);
} PLUGIN_SETTINGS3; } PLUGIN_SETTINGS3;
enum PLUGIN_TYPE { enum PLUGIN_TYPE
PLUGIN_TYPE_NONE = 0, {
PLUGIN_TYPE_RSP = 1, PLUGIN_TYPE_NONE = 0,
PLUGIN_TYPE_GFX = 2, PLUGIN_TYPE_RSP = 1,
PLUGIN_TYPE_AUDIO = 3, PLUGIN_TYPE_GFX = 2,
PLUGIN_TYPE_CONTROLLER = 4, PLUGIN_TYPE_AUDIO = 3,
PLUGIN_TYPE_CONTROLLER = 4,
}; };
class CSettings; class CSettings;
class CMainGui; class CMainGui;
class CGfxPlugin; class CAudioPlugin; class CRSP_Plugin; class CControl_Plugin; class CGfxPlugin; class CAudioPlugin; class CRSP_Plugin; class CControl_Plugin;
class CPlugins : class CPlugins :
private CDebugSettings private CDebugSettings
{ {
public: public:
//Functions //Functions
CPlugins (const stdstr & PluginDir ); CPlugins(const stdstr & PluginDir);
~CPlugins (); ~CPlugins();
bool Initiate ( CN64System * System ); bool Initiate(CN64System * System);
void RomOpened ( void ); void RomOpened(void);
void RomClosed ( void ); void RomClosed(void);
void SetRenderWindows ( CMainGui * RenderWindow, CMainGui * DummyWindow ); void SetRenderWindows ( CMainGui * RenderWindow, CMainGui * DummyWindow );
void ConfigPlugin ( DWORD hParent, PLUGIN_TYPE Type ); void ConfigPlugin(uint32_t hParent, PLUGIN_TYPE Type);
bool CopyPlugins ( const stdstr & DstDir ) const; bool CopyPlugins(const stdstr & DstDir) const;
void CreatePlugins ( void ); void CreatePlugins(void);
bool Reset ( CN64System * System ); bool Reset(CN64System * System);
bool ResetInUiThread ( CN64System * System ); bool ResetInUiThread(CN64System * System);
void GameReset ( void ); void GameReset(void);
inline CGfxPlugin * Gfx(void) const { return m_Gfx; }
inline CAudioPlugin * Audio(void) const { return m_Audio; }
inline CRSP_Plugin * RSP(void) const { return m_RSP; }
inline CControl_Plugin * Control(void) const { return m_Control; }
inline CGfxPlugin * Gfx ( void) const { return m_Gfx; };
inline CAudioPlugin * Audio ( void) const { return m_Audio; };
inline CRSP_Plugin * RSP ( void) const { return m_RSP; };
inline CControl_Plugin * Control ( void) const { return m_Control; };
private: private:
CPlugins(void); // Disable default constructor CPlugins(void); // Disable default constructor
CPlugins(const CPlugins&); // Disable copy constructor CPlugins(const CPlugins&); // Disable copy constructor
CPlugins& operator=(const CPlugins&); // Disable assignment CPlugins& operator=(const CPlugins&); // Disable assignment
// void Reset ( PLUGIN_TYPE Type ); void DestroyGfxPlugin(void);
void DestroyAudioPlugin(void);
void DestroyRspPlugin(void);
void DestroyControlPlugin(void);
void CreatePluginDir ( const stdstr & DstDir ) const; static void PluginChanged(CPlugins * _this);
void DestroyGfxPlugin ( void );
void DestroyAudioPlugin ( void );
void DestroyRspPlugin ( void );
void DestroyControlPlugin ( void );
static void PluginChanged ( CPlugins * _this );
//Common Classes
CMainGui * m_RenderWindow; CMainGui * m_RenderWindow;
CMainGui * m_DummyWindow; CMainGui * m_DummyWindow;
stdstr const m_PluginDir; stdstr const m_PluginDir;
//Plugins //Plugins
CGfxPlugin * m_Gfx; CGfxPlugin * m_Gfx;
CAudioPlugin * m_Audio; CAudioPlugin * m_Audio;
CRSP_Plugin * m_RSP; CRSP_Plugin * m_RSP;
CControl_Plugin * m_Control; CControl_Plugin * m_Control;
stdstr m_GfxFile; stdstr m_GfxFile;
stdstr m_AudioFile; stdstr m_AudioFile;
stdstr m_RSPFile; stdstr m_RSPFile;
stdstr m_ControlFile; stdstr m_ControlFile;
}; };
//Dummy Functions //Dummy Functions
void DummyCheckInterrupts ( void ); void DummyCheckInterrupts(void);
void DummyFunction (void); void DummyFunction(void);

View File

@ -10,202 +10,202 @@
****************************************************************************/ ****************************************************************************/
#include "stdafx.h" #include "stdafx.h"
void DummyFunc1(BOOL /*a*/) {} void DummyFunc1(int a) { a += 1;}
CRSP_Plugin::CRSP_Plugin(void) : CRSP_Plugin::CRSP_Plugin(void) :
DoRspCycles(NULL), DoRspCycles(NULL),
EnableDebugging(NULL), EnableDebugging(NULL),
m_CycleCount(0), m_CycleCount(0),
GetDebugInfo(NULL), GetDebugInfo(NULL),
InitiateDebugger(NULL) InitiateDebugger(NULL)
{ {
memset(&m_RSPDebug, 0, sizeof(m_RSPDebug)); memset(&m_RSPDebug, 0, sizeof(m_RSPDebug));
} }
CRSP_Plugin::~CRSP_Plugin() CRSP_Plugin::~CRSP_Plugin()
{ {
Close(); Close();
UnloadPlugin(); UnloadPlugin();
} }
bool CRSP_Plugin::LoadFunctions ( void ) bool CRSP_Plugin::LoadFunctions(void)
{ {
// Find entries for functions in DLL // Find entries for functions in DLL
void (__cdecl *InitiateRSP)( void ); void(__cdecl *InitiateRSP)(void);
LoadFunction(InitiateRSP); LoadFunction(InitiateRSP);
LoadFunction(DoRspCycles); LoadFunction(DoRspCycles);
_LoadFunction("GetRspDebugInfo", GetDebugInfo); _LoadFunction("GetRspDebugInfo", GetDebugInfo);
_LoadFunction("InitiateRSPDebugger", InitiateDebugger); _LoadFunction("InitiateRSPDebugger", InitiateDebugger);
LoadFunction(EnableDebugging); LoadFunction(EnableDebugging);
if (EnableDebugging == NULL) { EnableDebugging = DummyFunc1; } if (EnableDebugging == NULL) { EnableDebugging = DummyFunc1; }
//Make sure dll had all needed functions //Make sure dll had all needed functions
if (DoRspCycles == NULL) { UnloadPlugin(); return false; } if (DoRspCycles == NULL) { UnloadPlugin(); return false; }
if (InitiateRSP == NULL) { UnloadPlugin(); return false; } if (InitiateRSP == NULL) { UnloadPlugin(); return false; }
if (RomClosed == NULL) { UnloadPlugin(); return false; } if (RomClosed == NULL) { UnloadPlugin(); return false; }
if (CloseDLL == NULL) { UnloadPlugin(); return false; } if (CloseDLL == NULL) { UnloadPlugin(); return false; }
if (m_PluginInfo.Version >= 0x0102) if (m_PluginInfo.Version >= 0x0102)
{ {
if (PluginOpened == NULL) { UnloadPlugin(); return false; } if (PluginOpened == NULL) { UnloadPlugin(); return false; }
} }
// Get debug info if able // Get debug info if able
if (GetDebugInfo != NULL) if (GetDebugInfo != NULL)
GetDebugInfo(&m_RSPDebug); GetDebugInfo(&m_RSPDebug);
return true; return true;
} }
bool CRSP_Plugin::Initiate(CPlugins * Plugins, CN64System * System) bool CRSP_Plugin::Initiate(CPlugins * Plugins, CN64System * System)
{ {
if (m_PluginInfo.Version == 1 || m_PluginInfo.Version == 0x100) if (m_PluginInfo.Version == 1 || m_PluginInfo.Version == 0x100)
{ {
return false; return false;
} }
typedef struct typedef struct
{ {
HINSTANCE hInst; HINSTANCE hInst;
BOOL MemoryBswaped; /* If this is set to TRUE, then the memory has been pre int MemoryBswaped; /* If this is set to TRUE, then the memory has been pre
bswap on a dword (32 bits) boundry */ bswap on a dword (32 bits) boundry */
BYTE * RDRAM; uint8_t * RDRAM;
BYTE * DMEM; uint8_t * DMEM;
BYTE * IMEM; uint8_t * IMEM;
DWORD * MI__INTR_REG; uint32_t * MI__INTR_REG;
DWORD * SP__MEM_ADDR_REG; uint32_t * SP__MEM_ADDR_REG;
DWORD * SP__DRAM_ADDR_REG; uint32_t * SP__DRAM_ADDR_REG;
DWORD * SP__RD_LEN_REG; uint32_t * SP__RD_LEN_REG;
DWORD * SP__WR_LEN_REG; uint32_t * SP__WR_LEN_REG;
DWORD * SP__STATUS_REG; uint32_t * SP__STATUS_REG;
DWORD * SP__DMA_FULL_REG; uint32_t * SP__DMA_FULL_REG;
DWORD * SP__DMA_BUSY_REG; uint32_t * SP__DMA_BUSY_REG;
DWORD * SP__PC_REG; uint32_t * SP__PC_REG;
DWORD * SP__SEMAPHORE_REG; uint32_t * SP__SEMAPHORE_REG;
DWORD * DPC__START_REG; uint32_t * DPC__START_REG;
DWORD * DPC__END_REG; uint32_t * DPC__END_REG;
DWORD * DPC__CURRENT_REG; uint32_t * DPC__CURRENT_REG;
DWORD * DPC__STATUS_REG; uint32_t * DPC__STATUS_REG;
DWORD * DPC__CLOCK_REG; uint32_t * DPC__CLOCK_REG;
DWORD * DPC__BUFBUSY_REG; uint32_t * DPC__BUFBUSY_REG;
DWORD * DPC__PIPEBUSY_REG; uint32_t * DPC__PIPEBUSY_REG;
DWORD * DPC__TMEM_REG; uint32_t * DPC__TMEM_REG;
void ( __cdecl *CheckInterrupts)( void ); void(__cdecl *CheckInterrupts)(void);
void (__cdecl *ProcessDlist)( void ); void(__cdecl *ProcessDlist)(void);
void (__cdecl *ProcessAlist)( void ); void(__cdecl *ProcessAlist)(void);
void (__cdecl *ProcessRdpList)( void ); void(__cdecl *ProcessRdpList)(void);
void (__cdecl *ShowCFB)( void ); void(__cdecl *ShowCFB)(void);
} RSP_INFO_1_1; } RSP_INFO_1_1;
RSP_INFO_1_1 Info = { 0 }; RSP_INFO_1_1 Info = { 0 };
Info.hInst = GetModuleHandle(NULL); Info.hInst = GetModuleHandle(NULL);
Info.CheckInterrupts = DummyCheckInterrupts; Info.CheckInterrupts = DummyCheckInterrupts;
Info.MemoryBswaped = (System == NULL); // only true when the system's not yet loaded Info.MemoryBswaped = (System == NULL); // only true when the system's not yet loaded
//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, uint32_t * Cycles);
LoadFunction(InitiateRSP); LoadFunction(InitiateRSP);
if (InitiateRSP == NULL) { return false; } if (InitiateRSP == NULL) { return false; }
// We are initializing the plugin before any rom is loaded so we do not have any correct // We are initializing the plugin before any rom is loaded so we do not have any correct
// parameters here.. just needed to we can config the DLL. // parameters here.. just needed to we can config the DLL.
if (System == NULL) if (System == NULL)
{ {
BYTE Buffer[100]; uint8_t Buffer[100];
DWORD Value = 0; uint32_t Value = 0;
Info.ProcessDlist = DummyCheckInterrupts; Info.ProcessDlist = DummyCheckInterrupts;
Info.ProcessRdpList = DummyCheckInterrupts; Info.ProcessRdpList = DummyCheckInterrupts;
Info.ShowCFB = DummyCheckInterrupts; Info.ShowCFB = DummyCheckInterrupts;
Info.ProcessAlist = DummyCheckInterrupts; Info.ProcessAlist = DummyCheckInterrupts;
Info.RDRAM = Buffer; Info.RDRAM = Buffer;
Info.DMEM = Buffer; Info.DMEM = Buffer;
Info.IMEM = Buffer; Info.IMEM = Buffer;
Info.MI__INTR_REG = &Value; Info.MI__INTR_REG = &Value;
Info.SP__MEM_ADDR_REG = &Value; Info.SP__MEM_ADDR_REG = &Value;
Info.SP__DRAM_ADDR_REG = &Value; Info.SP__DRAM_ADDR_REG = &Value;
Info.SP__RD_LEN_REG = &Value; Info.SP__RD_LEN_REG = &Value;
Info.SP__WR_LEN_REG = &Value; Info.SP__WR_LEN_REG = &Value;
Info.SP__STATUS_REG = &Value; Info.SP__STATUS_REG = &Value;
Info.SP__DMA_FULL_REG = &Value; Info.SP__DMA_FULL_REG = &Value;
Info.SP__DMA_BUSY_REG = &Value; Info.SP__DMA_BUSY_REG = &Value;
Info.SP__PC_REG = &Value; Info.SP__PC_REG = &Value;
Info.SP__SEMAPHORE_REG = &Value; Info.SP__SEMAPHORE_REG = &Value;
Info.DPC__START_REG = &Value; Info.DPC__START_REG = &Value;
Info.DPC__END_REG = &Value; Info.DPC__END_REG = &Value;
Info.DPC__CURRENT_REG = &Value; Info.DPC__CURRENT_REG = &Value;
Info.DPC__STATUS_REG = &Value; Info.DPC__STATUS_REG = &Value;
Info.DPC__CLOCK_REG = &Value; Info.DPC__CLOCK_REG = &Value;
Info.DPC__BUFBUSY_REG = &Value; Info.DPC__BUFBUSY_REG = &Value;
Info.DPC__PIPEBUSY_REG = &Value; Info.DPC__PIPEBUSY_REG = &Value;
Info.DPC__TMEM_REG = &Value; Info.DPC__TMEM_REG = &Value;
} }
// Send initialization information to the DLL // Send initialization information to the DLL
else else
{ {
Info.ProcessDlist = Plugins->Gfx()->ProcessDList; Info.ProcessDlist = Plugins->Gfx()->ProcessDList;
Info.ProcessRdpList = Plugins->Gfx()->ProcessRDPList; Info.ProcessRdpList = Plugins->Gfx()->ProcessRDPList;
Info.ShowCFB = Plugins->Gfx()->ShowCFB; Info.ShowCFB = Plugins->Gfx()->ShowCFB;
Info.ProcessAlist = Plugins->Audio()->ProcessAList; Info.ProcessAlist = Plugins->Audio()->ProcessAList;
Info.RDRAM = g_MMU->Rdram(); Info.RDRAM = g_MMU->Rdram();
Info.DMEM = g_MMU->Dmem(); Info.DMEM = g_MMU->Dmem();
Info.IMEM = g_MMU->Imem(); Info.IMEM = g_MMU->Imem();
Info.MI__INTR_REG = &g_Reg->m_RspIntrReg; Info.MI__INTR_REG = (uint32_t *)&g_Reg->m_RspIntrReg;
Info.SP__MEM_ADDR_REG = &g_Reg->SP_MEM_ADDR_REG; Info.SP__MEM_ADDR_REG = (uint32_t *)&g_Reg->SP_MEM_ADDR_REG;
Info.SP__DRAM_ADDR_REG = &g_Reg->SP_DRAM_ADDR_REG; Info.SP__DRAM_ADDR_REG = (uint32_t *)&g_Reg->SP_DRAM_ADDR_REG;
Info.SP__RD_LEN_REG = &g_Reg->SP_RD_LEN_REG; Info.SP__RD_LEN_REG = (uint32_t *)&g_Reg->SP_RD_LEN_REG;
Info.SP__WR_LEN_REG = &g_Reg->SP_WR_LEN_REG; Info.SP__WR_LEN_REG = (uint32_t *)&g_Reg->SP_WR_LEN_REG;
Info.SP__STATUS_REG = &g_Reg->SP_STATUS_REG; Info.SP__STATUS_REG = (uint32_t *)&g_Reg->SP_STATUS_REG;
Info.SP__DMA_FULL_REG = &g_Reg->SP_DMA_FULL_REG; Info.SP__DMA_FULL_REG = (uint32_t *)&g_Reg->SP_DMA_FULL_REG;
Info.SP__DMA_BUSY_REG = &g_Reg->SP_DMA_BUSY_REG; Info.SP__DMA_BUSY_REG = (uint32_t *)&g_Reg->SP_DMA_BUSY_REG;
Info.SP__PC_REG = &g_Reg->SP_PC_REG; Info.SP__PC_REG = (uint32_t *)&g_Reg->SP_PC_REG;
Info.SP__SEMAPHORE_REG = &g_Reg->SP_SEMAPHORE_REG; Info.SP__SEMAPHORE_REG = (uint32_t *)&g_Reg->SP_SEMAPHORE_REG;
Info.DPC__START_REG = &g_Reg->DPC_START_REG; Info.DPC__START_REG = (uint32_t *)&g_Reg->DPC_START_REG;
Info.DPC__END_REG = &g_Reg->DPC_END_REG; Info.DPC__END_REG = (uint32_t *)&g_Reg->DPC_END_REG;
Info.DPC__CURRENT_REG = &g_Reg->DPC_CURRENT_REG; Info.DPC__CURRENT_REG = (uint32_t *)&g_Reg->DPC_CURRENT_REG;
Info.DPC__STATUS_REG = &g_Reg->DPC_STATUS_REG; Info.DPC__STATUS_REG = (uint32_t *)&g_Reg->DPC_STATUS_REG;
Info.DPC__CLOCK_REG = &g_Reg->DPC_CLOCK_REG; Info.DPC__CLOCK_REG = (uint32_t *)&g_Reg->DPC_CLOCK_REG;
Info.DPC__BUFBUSY_REG = &g_Reg->DPC_BUFBUSY_REG; Info.DPC__BUFBUSY_REG = (uint32_t *)&g_Reg->DPC_BUFBUSY_REG;
Info.DPC__PIPEBUSY_REG = &g_Reg->DPC_PIPEBUSY_REG; Info.DPC__PIPEBUSY_REG = (uint32_t *)&g_Reg->DPC_PIPEBUSY_REG;
Info.DPC__TMEM_REG = &g_Reg->DPC_TMEM_REG; Info.DPC__TMEM_REG = (uint32_t *)&g_Reg->DPC_TMEM_REG;
} }
InitiateRSP(Info, &m_CycleCount); InitiateRSP(Info, &m_CycleCount);
m_Initialized = true; m_Initialized = 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);
return m_Initialized; return m_Initialized;
} }
void CRSP_Plugin::UnloadPluginDetails(void) void CRSP_Plugin::UnloadPluginDetails(void)
{ {
memset(&m_RSPDebug, 0, sizeof(m_RSPDebug)); memset(&m_RSPDebug, 0, sizeof(m_RSPDebug));
DoRspCycles = NULL; DoRspCycles = NULL;
EnableDebugging = NULL; EnableDebugging = NULL;
GetDebugInfo = NULL; GetDebugInfo = NULL;
InitiateDebugger = NULL; InitiateDebugger = NULL;
} }
void CRSP_Plugin::ProcessMenuItem(int id) void CRSP_Plugin::ProcessMenuItem(int id)
{ {
if (m_RSPDebug.ProcessMenuItem) if (m_RSPDebug.ProcessMenuItem)
{ {
m_RSPDebug.ProcessMenuItem(id); m_RSPDebug.ProcessMenuItem(id);
} }
} }

View File

@ -9,68 +9,68 @@
* * * *
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "Plugin Base.h"
class CRSP_Plugin : public CPlugin class CRSP_Plugin : public CPlugin
{ {
typedef struct { typedef struct {
/* Menu */ /* Menu */
/* Items should have an ID between 5001 and 5100 */ /* Items should have an ID between 5001 and 5100 */
HMENU hRSPMenu; void * hRSPMenu;
void (__cdecl *ProcessMenuItem) ( int ID ); void(__cdecl *ProcessMenuItem) (int32_t ID);
/* Break Points */ /* Break Points */
BOOL UseBPoints; int32_t UseBPoints;
char BPPanelName[20]; char BPPanelName[20];
void (__cdecl *Add_BPoint) ( void ); void(__cdecl *Add_BPoint) (void);
void (__cdecl *CreateBPPanel) ( HMENU hDlg, RECT_STRUCT rcBox ); void(__cdecl *CreateBPPanel) (void);
void (__cdecl *HideBPPanel) ( void ); void(__cdecl *HideBPPanel) (void);
void (__cdecl *PaintBPPanel) ( WINDOWS_PAINTSTRUCT ps ); void(__cdecl *PaintBPPanel) (void);
void (__cdecl *ShowBPPanel) ( void ); void(__cdecl *ShowBPPanel) (void);
void (__cdecl *RefreshBpoints) ( HMENU hList ); void(__cdecl *RefreshBpoints) (void * hList);
void (__cdecl *RemoveBpoint) ( HMENU hList, int index ); void(__cdecl *RemoveBpoint) (void * hList, int32_t 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;
public: public:
CRSP_Plugin(void); CRSP_Plugin(void);
~CRSP_Plugin(); ~CRSP_Plugin();
bool Initiate(CPlugins * Plugins, CN64System * System); bool Initiate(CPlugins * Plugins, CN64System * System);
DWORD(__cdecl *DoRspCycles) (DWORD); uint32_t(__cdecl *DoRspCycles) (uint32_t);
void(__cdecl *EnableDebugging)(BOOL Enable); void(__cdecl *EnableDebugging)(int32_t Enable);
HMENU GetDebugMenu (void ) { return m_RSPDebug.hRSPMenu; } void * GetDebugMenu(void) { return m_RSPDebug.hRSPMenu; }
void ProcessMenuItem(int id); void ProcessMenuItem(int32_t id);
private: private:
CRSP_Plugin(const CRSP_Plugin&); // Disable copy constructor CRSP_Plugin(const CRSP_Plugin&); // Disable copy constructor
CRSP_Plugin& operator=(const CRSP_Plugin&); // Disable assignment CRSP_Plugin& operator=(const CRSP_Plugin&); // Disable assignment
PLUGIN_TYPE type() { return PLUGIN_TYPE_RSP; } PLUGIN_TYPE type() { return PLUGIN_TYPE_RSP; }
virtual int GetDefaultSettingStartRange() const { return FirstRSPDefaultSet; } virtual int32_t GetDefaultSettingStartRange() const { return FirstRSPDefaultSet; }
virtual int GetSettingStartRange() const { return FirstRSPSettings; } virtual int32_t GetSettingStartRange() const { return FirstRSPSettings; }
bool LoadFunctions ( void ); bool LoadFunctions(void);
void UnloadPluginDetails ( void ); void UnloadPluginDetails(void);
RSPDEBUG_INFO m_RSPDebug; RSPDEBUG_INFO m_RSPDebug;
DWORD m_CycleCount; uint32_t m_CycleCount;
void(__cdecl *GetDebugInfo) (RSPDEBUG_INFO * GFXDebugInfo); void(__cdecl *GetDebugInfo) (RSPDEBUG_INFO * GFXDebugInfo);
void(__cdecl *InitiateDebugger) (DEBUG_INFO DebugInfo); void(__cdecl *InitiateDebugger) (DEBUG_INFO DebugInfo);
}; };