Merge pull request #739 from cxd4/contr-1_1-specs

"fixed" implementation of Controller 1.1 specifications
This commit is contained in:
zilmar 2015-11-17 13:19:45 +11:00
commit c218d17eac
5 changed files with 88 additions and 40 deletions

View File

@ -60,6 +60,9 @@ bool CControl_Plugin::LoadFunctions(void)
bool CControl_Plugin::Initiate(CN64System * System, RenderWindow * Window)
{
CONTROL_INFO ControlInfo;
uint8_t Buffer[100];
for (int32_t i = 0; i < 4; i++)
{
m_PluginControllers[i].Present = FALSE;
@ -67,47 +70,43 @@ bool CControl_Plugin::Initiate(CN64System * System, RenderWindow * Window)
m_PluginControllers[i].Plugin = PLUGIN_NONE;
}
if (m_PluginInfo.Version >= 0x0101)
{
ControlInfo.Controls = m_PluginControllers;
ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress());
ControlInfo.hinst = GetModuleHandle(NULL);
ControlInfo.hMainWindow = Window ? (HWND)Window->GetWindowHandle() : NULL;
ControlInfo.MemoryBswaped = TRUE;
}
// Test Plugin version
if (m_PluginInfo.Version == 0x0100)
{
//Get Function from DLL
void(__cdecl *InitiateControllers_1_0)(HWND hMainWindow, CONTROL Controls[4]);
InitiateControllers_1_0 = (void(__cdecl *)(HWND, CONTROL *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
if (InitiateControllers_1_0 == NULL) { return false; }
InitiateControllers_1_0((HWND)Window->GetWindowHandle(), m_PluginControllers);
if (InitiateControllers_1_0 == NULL) { return false; }
InitiateControllers_1_0((HWND)Window->GetWindowHandle(), m_PluginControllers);
m_Initialized = true;
}
else if (m_PluginInfo.Version >= 0x0101)
else if (m_PluginInfo.Version == 0x0101)
{
typedef struct
{
HWND hMainWindow;
HINSTANCE hinst;
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.
// 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)
CONTROL *Controls; // A pointer to an array of 4 controllers .. eg:
// CONTROL Controls[4];
} CONTROL_INFO;
//Get Function from DLL
void(__cdecl *InitiateControllers_1_1)(CONTROL_INFO * ControlInfo);
InitiateControllers_1_1 = (void(__cdecl *)(CONTROL_INFO *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
void(__cdecl *InitiateControllers_1_1)(CONTROL_INFO ControlInfo);
InitiateControllers_1_1 = (void(__cdecl *)(CONTROL_INFO))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
if (InitiateControllers_1_1 == NULL) { return false; }
InitiateControllers_1_1(ControlInfo);
m_Initialized = true;
}
else if (m_PluginInfo.Version >= 0x0102)
{
//Get Function from DLL
void(__cdecl *InitiateControllers_1_2)(CONTROL_INFO * ControlInfo);
InitiateControllers_1_2 = (void(__cdecl *)(CONTROL_INFO *))GetProcAddress((HMODULE)m_hDll, "InitiateControllers");
if (InitiateControllers_1_2 == NULL) { return false; }
CONTROL_INFO ControlInfo;
uint8_t Buffer[100];
ControlInfo.Controls = m_PluginControllers;
ControlInfo.HEADER = (System == NULL ? Buffer : g_Rom->GetRomAddress());
ControlInfo.hinst = GetModuleHandle(NULL);
ControlInfo.hMainWindow = Window ? (HWND)Window->GetWindowHandle() : NULL;
ControlInfo.MemoryBswaped = TRUE;
InitiateControllers_1_1(&ControlInfo);
InitiateControllers_1_2(&ControlInfo);
m_Initialized = true;
}
@ -177,4 +176,4 @@ CCONTROL::CCONTROL(int32_t &Present, int32_t &RawData, int32_t &PlugType) :
m_Present(Present), m_RawData(RawData), m_PlugType(PlugType)
{
m_Buttons.Value = 0;
}
}

View File

@ -51,6 +51,16 @@ typedef struct
int32_t Plugin;
} CONTROL;
typedef struct
{
void * hMainWindow;
void * hinst;
int32_t MemoryBswaped; // memory in client- or server-native endian
uint8_t * HEADER; // the ROM header (first 40h bytes of the ROM)
CONTROL * Controls; // pointer to array of 4 controllers, i.e.: CONTROL Controls[4];
} CONTROL_INFO;
enum PluginType
{
PLUGIN_NONE = 1,

View File

@ -16,6 +16,10 @@ extern "C" {
#define PLUGIN_TYPE_CONTROLLER 4
#ifndef SPECS_VERSION
#define SPECS_VERSION 0x0101
#endif
/*** Conteroller plugin's ****/
#define PLUGIN_NONE 1
#define PLUGIN_MEMPAK 2
@ -181,7 +185,14 @@ extern "C" {
the emulator to know how to handle each controller.
output: none
*******************************************************************/
EXPORT void CALL InitiateControllers(CONTROL_INFO * ControlInfo);
#if (SPECS_VERSION < 0x0101)
EXPORT void CALL InitiateControllers(void * hMainWindow, CONTROL Controls[4]);
#elif (SPECS_VERSION == 0x0101)
EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo);
/* Typo in the official specs, but it works! */
#else
EXPORT void CALL InitiateControllers(CONTROL_INFO * ControlInfo);
#endif
/******************************************************************
Function: ReadController

View File

@ -36,7 +36,7 @@
// ProtoTypes //
bool prepareHeap();
void FillControls(CONTROL Controls[]);
void FillControls(CONTROL * Controls);
void InitiatePaks( bool bInitialize );
void DoShortcut( int iPlayer, int iShortcut );
DWORD WINAPI MsgThreadFunction( LPVOID lpParam );
@ -156,7 +156,7 @@ EXPORT void CALL GetDllInfo ( PLUGIN_INFO* PluginInfo )
sprintf(PluginInfo->Name,"N-Rage For PJ64: %s",VER_FILE_VERSION_STR);
#endif
PluginInfo->Type = PLUGIN_TYPE_CONTROLLER;
PluginInfo->Version = 0x0101;
PluginInfo->Version = SPECS_VERSION;
}
/******************************************************************
@ -311,15 +311,36 @@ EXPORT void CALL DllTest ( HWND hParent )
the emulator to know how to handle each controller.
output: none
*******************************************************************/
EXPORT void CALL InitiateControllers (CONTROL_INFO * ControlInfo)
EXPORT void CALL InitiateControllers(
#if (SPECS_VERSION < 0x0101)
void * hMainWindow, CONTROL Controls[4]
#elif (SPECS_VERSION == 0x0101)
CONTROL_INFO ControlInfo
#else
CONTROL_INFO * ControlInfo
#endif
)
{
DebugWriteA("CALLED: InitiateControllers\n");
if( !prepareHeap())
return;
g_strEmuInfo.hMainWindow = ControlInfo->hMainWindow;
// g_strEmuInfo.MemoryBswaped = ControlInfo->MemoryBswaped;
// g_strEmuInfo.HEADER = ControlInfo->HEADER;
#if (SPECS_VERSION < 0x0101)
g_strEmuInfo.controllers = &Controls[0];
g_strEmuInfo.hMainWindow = hMainWindow;
// g_strEmuInfo.MemoryBswaped = TRUE; // Or FALSE. Really does not matter.
// g_strEmuInfo.HEADER = NULL;
#elif (SPECS_VERSION == 0x0101)
g_strEmuInfo.controllers = ControlInfo.Controls;
g_strEmuInfo.hMainWindow = ControlInfo.hMainWindow;
// g_strEmuInfo.MemoryBswaped = ControlInfo.MemoryBswaped;
// g_strEmuInfo.HEADER = ControlInfo.HEADER;
#else
g_strEmuInfo.controllers = ControlInfo->Controls;
g_strEmuInfo.hMainWindow = ControlInfo->hMainWindow;
// g_strEmuInfo.MemoryBswaped = ControlInfo->MemoryBswaped;
// g_strEmuInfo.HEADER = ControlInfo->HEADER;
#endif
// UNDONE: Instead of just storing the header, figure out what ROM we're running and save that information somewhere
// The emulator expects us to tell what controllers are plugged in and what their paks are at this point.
@ -430,8 +451,7 @@ EXPORT void CALL InitiateControllers (CONTROL_INFO * ControlInfo)
LeaveCriticalSection( &g_critical );
FillControls(ControlInfo->Controls);
FillControls(g_strEmuInfo.controllers);
return;
} // end InitiateControllers
@ -884,7 +904,7 @@ void InitiatePaks( bool bInitialize )
// Unfortunately the spec doesn't work that way. Fixed the func and changed the func name to something that makes more sense.
// FillControls takes a Controls array from InitiateControllers and fills it with what we know about whether
// a controller is plugged in, accepting raw data, and what type of pak is plugged in.
void FillControls(CONTROL Controls[4])
void FillControls(CONTROL * Controls)
{
for( int i = 4-1; i >= 0; i-- )
{

View File

@ -62,6 +62,14 @@ typedef struct _EMULATOR_INFO
LANGID Language;
bool fDisplayShortPop; // do we display shortcut message popups?
/*
* 2015.11.09 cxd4
* Added to keep the real address of the CONTROL array stored.
*
* This became necessary due to conflicts between specs #1.0, #1.1 and #1.2.
*/
CONTROL * controllers;
// BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre
// bswap on a dword (32 bits) boundry, only effects header.
// eg. the first 8 bytes are stored like this: