shared memory across processes (needs work)

This commit is contained in:
Aaron Robinson 2003-04-01 07:11:07 +00:00
parent 8fec9c1a07
commit b89510b700
11 changed files with 372 additions and 225 deletions

View File

@ -157,6 +157,10 @@ SOURCE=.\Include\Win32\Cxbx\EmuExe.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\CxbxKrnl\EmuShared.h
# End Source File
# Begin Source File
SOURCE=.\Include\Core\Error.h
# End Source File
# Begin Source File
@ -169,6 +173,10 @@ SOURCE=.\Include\Win32\InputConfig.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\Mutex.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\Cxbx\Prolog.h
# End Source File
# Begin Source File

View File

@ -181,6 +181,10 @@ SOURCE=.\Include\Win32\CxbxKrnl\HLEDataBase.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\Mutex.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\CxbxKrnl\OOVPA.h
# End Source File
# Begin Source File

View File

@ -68,8 +68,6 @@ namespace win32
#include <dinput.h>
};
#include "EmuShared.h"
// ******************************************************************
// * prevent name collisions
// ******************************************************************

View File

@ -34,9 +34,17 @@
#ifndef EMUSHARED_H
#define EMUSHARED_H
#include "Emu.h"
#include "Mutex.h"
#include "InputConfig.h"
using namespace win32;
// ******************************************************************
// * cxbxkrnl exports, others import
// ******************************************************************
#ifndef _CXBXKRNL_INTERNAL
#define CXBXKRNL_API DECLSPEC_IMPORT
#else
#define CXBXKRNL_API DECLSPEC_EXPORT
#endif
// ******************************************************************
// * func: EmuSharedInit
@ -51,9 +59,13 @@ CXBXKRNL_API void EmuSharedCleanup();
// ******************************************************************
// * shared memory
// ******************************************************************
extern CXBXKRNL_API struct EmuShared
extern CXBXKRNL_API class EmuShared : public Mutex
{
uint32 dwRandomData;
public:
InputConfig *GetInputConfiguration() { return &m_InputConfig; }
private:
InputConfig m_InputConfig;
}
*g_EmuShared;

View File

@ -39,15 +39,22 @@
// ******************************************************************
#define MAX_INPUT_DEVICES 0x20
// ******************************************************************
// * InputMapping flags
// ******************************************************************
#define INPUT_MAPPING_AXIS_POSITIVE (1 << 0)
#define INPUT_MAPPING_AXIS_NEGATIVE (1 << 1)
// ******************************************************************
// * Input mapping information
// ******************************************************************
struct InputMapping
{
InputMapping() : dwDevice(-1), dwType(-1) {}
InputMapping() : dwDevice(-1), dwType(-1), dwFlags(0) {}
int dwDevice; // lookup into m_Devices
int dwType; // used to locate the data inside GetDeviceState's return data
int dwDevice; // lookup into m_Devices
int dwType; // used to locate the data inside GetDeviceState's return data
int dwFlags; // flags giving more precise information about the data format
};
// ******************************************************************
@ -69,32 +76,32 @@ class InputConfig
// ******************************************************************
// * Mapping Accessors
// ******************************************************************
void MapLThumbX(const char *DeviceName, int dwType) { Map(m_LThumbX, DeviceName, dwType); }
void MapLThumbY(const char *DeviceName, int dwType) { Map(m_LThumbY, DeviceName, dwType); }
void MapRThumbX(const char *DeviceName, int dwType) { Map(m_RThumbX, DeviceName, dwType); }
void MapRThumbY(const char *DeviceName, int dwType) { Map(m_RThumbY, DeviceName, dwType); }
void MapX(const char *DeviceName, int dwType) { Map(m_X, DeviceName, dwType); }
void MapY(const char *DeviceName, int dwType) { Map(m_Y, DeviceName, dwType); }
void MapA(const char *DeviceName, int dwType) { Map(m_A, DeviceName, dwType); }
void MapB(const char *DeviceName, int dwType) { Map(m_B, DeviceName, dwType); }
void MapWhite(const char *DeviceName, int dwType) { Map(m_White, DeviceName, dwType); }
void MapBlack(const char *DeviceName, int dwType) { Map(m_Black, DeviceName, dwType); }
void MapLTrigger(const char *DeviceName, int dwType) { Map(m_LTrigger, DeviceName, dwType); }
void MapRTrigger(const char *DeviceName, int dwType) { Map(m_RTrigger, DeviceName, dwType); }
void MapDPadUp(const char *DeviceName, int dwType) { Map(m_DPadUp, DeviceName, dwType); }
void MapDPadDown(const char *DeviceName, int dwType) { Map(m_DPadDown, DeviceName, dwType); }
void MapDPadLeft(const char *DeviceName, int dwType) { Map(m_DPadLeft, DeviceName, dwType); }
void MapDPadRight(const char *DeviceName, int dwType) { Map(m_DPadRight, DeviceName, dwType); }
void MapBack(const char *DeviceName, int dwType) { Map(m_Back, DeviceName, dwType); }
void MapStart(const char *DeviceName, int dwType) { Map(m_Start, DeviceName, dwType); }
void MapLThumb(const char *DeviceName, int dwType) { Map(m_LThumb, DeviceName, dwType); }
void MapRThumb(const char *DeviceName, int dwType) { Map(m_RThumb, DeviceName, dwType); }
void MapLThumbX(const char *DeviceName, int dwType, int dwFlags) { Map(m_LThumbX, DeviceName, dwType, dwFlags); }
void MapLThumbY(const char *DeviceName, int dwType, int dwFlags) { Map(m_LThumbY, DeviceName, dwType, dwFlags); }
void MapRThumbX(const char *DeviceName, int dwType, int dwFlags) { Map(m_RThumbX, DeviceName, dwType, dwFlags); }
void MapRThumbY(const char *DeviceName, int dwType, int dwFlags) { Map(m_RThumbY, DeviceName, dwType, dwFlags); }
void MapX(const char *DeviceName, int dwType, int dwFlags) { Map(m_X, DeviceName, dwType, dwFlags); }
void MapY(const char *DeviceName, int dwType, int dwFlags) { Map(m_Y, DeviceName, dwType, dwFlags); }
void MapA(const char *DeviceName, int dwType, int dwFlags) { Map(m_A, DeviceName, dwType, dwFlags); }
void MapB(const char *DeviceName, int dwType, int dwFlags) { Map(m_B, DeviceName, dwType, dwFlags); }
void MapWhite(const char *DeviceName, int dwType, int dwFlags) { Map(m_White, DeviceName, dwType, dwFlags); }
void MapBlack(const char *DeviceName, int dwType, int dwFlags) { Map(m_Black, DeviceName, dwType, dwFlags); }
void MapLTrigger(const char *DeviceName, int dwType, int dwFlags) { Map(m_LTrigger, DeviceName, dwType, dwFlags); }
void MapRTrigger(const char *DeviceName, int dwType, int dwFlags) { Map(m_RTrigger, DeviceName, dwType, dwFlags); }
void MapDPadUp(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadUp, DeviceName, dwType, dwFlags); }
void MapDPadDown(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadDown, DeviceName, dwType, dwFlags); }
void MapDPadLeft(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadLeft, DeviceName, dwType, dwFlags); }
void MapDPadRight(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadRight, DeviceName, dwType, dwFlags); }
void MapBack(const char *DeviceName, int dwType, int dwFlags) { Map(m_Back, DeviceName, dwType, dwFlags); }
void MapStart(const char *DeviceName, int dwType, int dwFlags) { Map(m_Start, DeviceName, dwType, dwFlags); }
void MapLThumb(const char *DeviceName, int dwType, int dwFlags) { Map(m_LThumb, DeviceName, dwType, dwFlags); }
void MapRThumb(const char *DeviceName, int dwType, int dwFlags) { Map(m_RThumb, DeviceName, dwType, dwFlags); }
private:
// ******************************************************************
// * Map a given input control mapping
// ******************************************************************
void Map(InputMapping &IM, const char *DeviceName, int dwType);
void Map(InputMapping &IM, const char *DeviceName, int dwType, int dwFlags);
// ******************************************************************
// * Find the look-up value for a DeviceName (creates if needed)
@ -104,7 +111,7 @@ class InputConfig
// ******************************************************************
// * Devices used by one or more input mappings
// ******************************************************************
char *m_DeviceName[MAX_INPUT_DEVICES];
char m_DeviceName[260][MAX_INPUT_DEVICES];
// ******************************************************************
// * Analog Axis

72
Include/Win32/Mutex.h Normal file
View File

@ -0,0 +1,72 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Win32->Mutex.h
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#ifndef MUTEX_H
#define MUTEX_H
#include <windows.h>
// ******************************************************************
// * Mutex object (intended to be inherited from)
// ******************************************************************
class Mutex
{
public:
// ******************************************************************
// * Constructor
// ******************************************************************
Mutex() { InitializeCriticalSection(&m_CS); }
// ******************************************************************
// * Deconstructor
// ******************************************************************
~Mutex() { DeleteCriticalSection(&m_CS); }
// ******************************************************************
// * Lock critical section
// ******************************************************************
void Lock() { EnterCriticalSection(&m_CS); }
// ******************************************************************
// * Unlock critical section
// ******************************************************************
void Unlock() { LeaveCriticalSection(&m_CS); }
private:
// ******************************************************************
// * Critical section
// ******************************************************************
CRITICAL_SECTION m_CS;
};
#endif

View File

@ -34,7 +34,7 @@
#include "Cxbx.h"
#include "ResCxbx.h"
#include "DlgControllerConfig.h"
#include "InputConfig.h"
#include "EmuShared.h"
#include <stdio.h>
@ -56,6 +56,7 @@ InputConfig g_InputConfig;
static INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
static BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
static void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(const char *, int, int));
// ******************************************************************
// * Show Controller configuration dialog window
@ -71,10 +72,147 @@ void ShowControllerConfig(HWND hwnd)
);
}
// ******************************************************************
// * Controller configuration dialog procedure
// ******************************************************************
INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX)));
break;
case WM_CLOSE:
EndDialog(hWndDlg, wParam);
break;
case WM_COMMAND:
{
HWND hWndButton = GetDlgItem(hWndDlg, LOWORD(wParam));
switch(LOWORD(wParam))
{
case IDC_INPUT_CONFIG_CANCEL:
EndDialog(hWndDlg, wParam);
break;
case IDC_INPUT_CONFIG_ACCEPT:
{
g_EmuShared->Lock();
InputConfig *g_InputConfig = g_EmuShared->GetInputConfiguration();
g_EmuShared->Unlock();
}
break;
case IDC_SET_LEFT_X:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLThumbX);
break;
case IDC_SET_LEFT_Y:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLThumbY);
break;
case IDC_SET_RIGHT_X:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRThumbX);
break;
case IDC_SET_RIGHT_Y:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRThumbY);
break;
case IDC_SET_X:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapX);
break;
case IDC_SET_Y:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapY);
break;
case IDC_SET_A:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapA);
break;
case IDC_SET_B:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapB);
break;
case IDC_SET_WHITE:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapWhite);
break;
case IDC_SET_BLACK:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapBlack);
break;
case IDC_SET_LTRIGGER:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLTrigger);
break;
case IDC_SET_RTRIGGER:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRTrigger);
break;
case IDC_SET_DPAD_UP:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadUp);
break;
case IDC_SET_DPAD_DOWN:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadDown);
break;
case IDC_SET_DPAD_LEFT:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadLeft);
break;
case IDC_SET_DPAD_RIGHT:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadRight);
break;
case IDC_SET_BACK:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapBack);
break;
case IDC_SET_START:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapStart);
break;
case IDC_SET_LTHUMB:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLThumb);
break;
case IDC_SET_RTHUMB:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRThumb);
break;
}
}
break;
}
return FALSE;
}
// ******************************************************************
// * Enumerate all game controllers
// ******************************************************************
BOOL CALLBACK EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
HRESULT hRet = g_pDirectInput8->CreateDevice(lpddi->guidInstance, &g_pInputDev[g_pInputCur], NULL);
if(FAILED(hRet))
return DIENUM_CONTINUE;
g_pInputDev[g_pInputCur++]->SetDataFormat(&c_dfDIJoystick);
return DIENUM_CONTINUE;
}
// ******************************************************************
// * Enumerate all game controller objects
// ******************************************************************
BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
if(lpddoi->dwType & DIDFT_AXIS)
{
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = lpddoi->dwType;
diprg.lMin = -32768;
diprg.lMax = 32767;
// set axis range
HRESULT hRet = g_pInputDev[(int)pvRef]->SetProperty(DIPROP_RANGE, &diprg.diph);
if(FAILED(hRet))
return DIENUM_STOP;
}
return DIENUM_CONTINUE;
}
// ******************************************************************
// * ConfigureInput
// ******************************************************************
void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(const char *, int))
void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(const char *, int, int))
{
if(!g_bConfigDone)
return;
@ -191,6 +329,7 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
}
DWORD dwHow = -1;
DWORD dwFlags = 0;
g_pInputDev[v]->GetDeviceState(sizeof(DIJOYSTATE), &tInputState);
@ -201,26 +340,44 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
int v=0;
if(abs(tInputState.lX) > JOYSTICK_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, lX);
if(abs(tInputState.lY) > JOYSTICK_DETECT_SENSITIVITY)
{
dwHow = FIELD_OFFSET(DIJOYSTATE, lX);
dwFlags = (tInputState.lX > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
}
else if(abs(tInputState.lY) > JOYSTICK_DETECT_SENSITIVITY)
{
dwHow = FIELD_OFFSET(DIJOYSTATE, lY);
if(abs(tInputState.lZ) > JOYSTICK_DETECT_SENSITIVITY)
dwFlags = (tInputState.lY > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
}
else if(abs(tInputState.lZ) > JOYSTICK_DETECT_SENSITIVITY)
{
dwHow = FIELD_OFFSET(DIJOYSTATE, lZ);
if(abs(tInputState.lRx) > JOYSTICK_DETECT_SENSITIVITY)
dwFlags = (tInputState.lZ > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
}
else if(abs(tInputState.lRx) > JOYSTICK_DETECT_SENSITIVITY)
{
dwHow = FIELD_OFFSET(DIJOYSTATE, lRx);
if(abs(tInputState.lRy) > JOYSTICK_DETECT_SENSITIVITY)
dwFlags = (tInputState.lRx > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
}
else if(abs(tInputState.lRy) > JOYSTICK_DETECT_SENSITIVITY)
{
dwHow = FIELD_OFFSET(DIJOYSTATE, lRy);
if(abs(tInputState.lRz) > JOYSTICK_DETECT_SENSITIVITY)
dwFlags = (tInputState.lRy > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
}
else if(abs(tInputState.lRz) > JOYSTICK_DETECT_SENSITIVITY)
{
dwHow = FIELD_OFFSET(DIJOYSTATE, lRz);
for(v=0;v<2;v++)
if(abs(tInputState.rglSlider[v]) > JOYSTICK_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, rglSlider[v]);
for(v=0;v<4;v++)
if(abs(tInputState.rgdwPOV[v]) > POV_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, rgdwPOV[v]);
for(v=0;v<32;v++)
if(tInputState.rgbButtons[v] > BUTTON_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, rgbButtons[v]);
dwFlags = (tInputState.lRz > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
}
else for(v=0;v<2;v++)
if(abs(tInputState.rglSlider[v]) > JOYSTICK_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, rglSlider[v]);
else for(v=0;v<4;v++)
if(abs(tInputState.rgdwPOV[v]) > POV_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, rgdwPOV[v]);
else for(v=0;v<32;v++)
if(tInputState.rgbButtons[v] > BUTTON_DETECT_SENSITIVITY)
dwHow = FIELD_OFFSET(DIJOYSTATE, rgbButtons[v]);
}
// ******************************************************************
@ -232,16 +389,17 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
g_pInputDev[v]->GetObjectInfo(&ObjectInstance, dwHow, DIPH_BYOFFSET);
(g_InputConfig.*MapFunc)(DeviceInstance.tszInstanceName, ObjectInstance.dwType);
(g_InputConfig.*MapFunc)(DeviceInstance.tszInstanceName, ObjectInstance.dwType, dwFlags);
printf("Cxbx: Detected %s on %s (dwType : %.08X)\n", ObjectInstance.tszName, DeviceInstance.tszInstanceName, ObjectInstance.dwType);
sprintf(szNewText, "%s Successfully Mapped To %s On %s!", szOrgText, ObjectInstance.tszName, DeviceInstance.tszInstanceName);
g_bConfigDone = true;
}
}
Sleep(10);
Sleep(20);
}
}
@ -271,136 +429,3 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
g_bConfigDone = true;
}
// ******************************************************************
// * Controller configuration dialog procedure
// ******************************************************************
INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX)));
break;
case WM_CLOSE:
EndDialog(hWndDlg, wParam);
break;
case WM_COMMAND:
{
HWND hWndButton = GetDlgItem(hWndDlg, LOWORD(wParam));
switch(LOWORD(wParam))
{
case IDC_INPUT_CONFIG_CANCEL:
EndDialog(hWndDlg, wParam);
break;
case IDC_INPUT_CONFIG_ACCEPT:
MessageBox(hWndDlg, "Not yet implemented...", "Cxbx", MB_OK);
break;
case IDC_SET_LEFT_X:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLThumbX);
break;
case IDC_SET_LEFT_Y:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLThumbY);
break;
case IDC_SET_RIGHT_X:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRThumbX);
break;
case IDC_SET_RIGHT_Y:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRThumbY);
break;
case IDC_SET_X:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapX);
break;
case IDC_SET_Y:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapY);
break;
case IDC_SET_A:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapA);
break;
case IDC_SET_B:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapB);
break;
case IDC_SET_WHITE:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapWhite);
break;
case IDC_SET_BLACK:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapBlack);
break;
case IDC_SET_LTRIGGER:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLTrigger);
break;
case IDC_SET_RTRIGGER:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRTrigger);
break;
case IDC_SET_DPAD_UP:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadUp);
break;
case IDC_SET_DPAD_DOWN:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadDown);
break;
case IDC_SET_DPAD_LEFT:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadLeft);
break;
case IDC_SET_DPAD_RIGHT:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapDPadRight);
break;
case IDC_SET_BACK:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapBack);
break;
case IDC_SET_START:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapStart);
break;
case IDC_SET_LTHUMB:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapLThumb);
break;
case IDC_SET_RTHUMB:
ConfigureInput(hWndDlg, hWndButton, InputConfig::MapRThumb);
break;
}
}
break;
}
return FALSE;
}
// ******************************************************************
// * Enumerate all game controllers
// ******************************************************************
BOOL CALLBACK EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
HRESULT hRet = g_pDirectInput8->CreateDevice(lpddi->guidInstance, &g_pInputDev[g_pInputCur], NULL);
if(FAILED(hRet))
return DIENUM_CONTINUE;
g_pInputDev[g_pInputCur++]->SetDataFormat(&c_dfDIJoystick);
return DIENUM_CONTINUE;
}
// ******************************************************************
// * Enumerate all game controller objects
// ******************************************************************
BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
if(lpddoi->dwType & DIDFT_AXIS)
{
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = lpddoi->dwType;
diprg.lMin = -32768;
diprg.lMax = 32767;
// set axis range
HRESULT hRet = g_pInputDev[(int)pvRef]->SetProperty(DIPROP_RANGE, &diprg.diph);
if(FAILED(hRet))
return DIENUM_STOP;
}
return DIENUM_CONTINUE;
}

View File

@ -34,6 +34,7 @@
#include "Cxbx.h"
#include "EmuExe.h"
#include "WndMain.h"
#include "EmuShared.h"
#undef FIELD_OFFSET // prevent macro redefinition warnings
#include <windows.h>
@ -43,6 +44,8 @@
// ******************************************************************
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
EmuSharedInit();
WndMain *MainWindow = new WndMain(hInstance);
while(!MainWindow->isCreated() && MainWindow->ProcessMessages())
@ -63,5 +66,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
delete MainWindow;
EmuSharedCleanup();
return 0;
}

View File

@ -47,6 +47,8 @@ namespace xntdll
using namespace win32;
#include "EmuShared.h"
// ******************************************************************
// * global / static
// ******************************************************************

View File

@ -39,6 +39,8 @@
using namespace win32;
#include "EmuShared.h"
// ******************************************************************
// * shared memory
// ******************************************************************
@ -47,51 +49,68 @@ CXBXKRNL_API EmuShared *g_EmuShared = NULL;
// ******************************************************************
// * map object
// ******************************************************************
static HANDLE g_hMapObject = NULL;
HANDLE g_hMapObject = NULL;
// ******************************************************************
// * func: EmuSharedInit
// ******************************************************************
CXBXKRNL_API void EmuSharedInit()
{
// we should only initialize once
if(g_hMapObject != NULL)
return;
bool init = true;
g_hMapObject = CreateFileMapping
(
INVALID_HANDLE_VALUE, // Paging file
NULL, // default security attributes
PAGE_READWRITE, // read/write access
0, // size: high 32 bits
sizeof(EmuShared), // size: low 32 bits
"EmuShared" // name of map object
);
// ******************************************************************
// * Prevent multiple initializations
// ******************************************************************
{
if(g_hMapObject != NULL)
return;
}
if(g_hMapObject == NULL)
return; // TODO: Fail gracefully
// ******************************************************************
// * Create the shared memory "file"
// ******************************************************************
{
g_hMapObject = CreateFileMapping
(
INVALID_HANDLE_VALUE, // Paging file
NULL, // default security attributes
PAGE_READWRITE, // read/write access
0, // size: high 32 bits
sizeof(EmuShared), // size: low 32 bits
"Local\\EmuShared" // name of map object
);
if(GetLastError() == ERROR_ALREADY_EXISTS)
init = false;
if(g_hMapObject == NULL)
return; // TODO: Fail gracefully
g_EmuShared = (EmuShared*)MapViewOfFile
(
g_hMapObject, // object to map view of
FILE_MAP_WRITE, // read/write access
0, // high offset: map from
0, // low offset: beginning
0 // default: map entire file
);
if(GetLastError() == ERROR_ALREADY_EXISTS)
init = false;
}
if(g_EmuShared == NULL)
return; // TODO: Fail gracefully
// ******************************************************************
// * Memory map this file
// ******************************************************************
{
g_EmuShared = (EmuShared*)MapViewOfFile
(
g_hMapObject, // object to map view of
FILE_MAP_WRITE, // read/write access
0, // high offset: map from
0, // low offset: beginning
0 // default: map entire file
);
if(g_EmuShared == NULL)
return; // TODO: Fail gracefully
}
// ******************************************************************
// * Executed only on first initialization of shared memory
// ******************************************************************
if(init)
{
// initialization of shared data
g_EmuShared->dwRandomData = 0;
// this is where you would load the initial controller configuration, etc
}
}
@ -102,6 +121,4 @@ CXBXKRNL_API void EmuSharedInit()
CXBXKRNL_API void EmuSharedCleanup()
{
UnmapViewOfFile(g_EmuShared);
CloseHandle(g_hMapObject);
}

View File

@ -43,7 +43,7 @@
InputConfig::InputConfig()
{
for(int v=0;v<MAX_INPUT_DEVICES;v++)
m_DeviceName[v] = 0;
m_DeviceName[v][0] = '\0';
}
// ******************************************************************
@ -51,17 +51,17 @@ InputConfig::InputConfig()
// ******************************************************************
InputConfig::~InputConfig()
{
for(int v=0;v<MAX_INPUT_DEVICES;v++)
delete m_DeviceName[v];
}
// ******************************************************************
// * Map a given input control mapping
// ******************************************************************
void InputConfig::Map(InputMapping &IM, const char *DeviceName, int dwType)
void InputConfig::Map(InputMapping &IM, const char *DeviceName, int dwType, int dwFlags)
{
// initialize IM
IM.dwDevice = Insert(DeviceName);
IM.dwType = dwType;
IM.dwType = dwType;
IM.dwFlags = dwFlags;
// purge unused slots
for(int v=0;v<MAX_INPUT_DEVICES;v++)
@ -77,8 +77,7 @@ void InputConfig::Map(InputMapping &IM, const char *DeviceName, int dwType)
m_Back.dwDevice != v && m_Start.dwDevice != v &&
m_LThumb.dwDevice != v && m_RThumb.dwDevice != v)
{
delete[] m_DeviceName[v];
m_DeviceName[v] = 0;
m_DeviceName[v][0] = '\0';
}
}
@ -92,15 +91,13 @@ int InputConfig::Insert(const char *DeviceName)
{
int v=0;
for(v=0;v<MAX_INPUT_DEVICES;v++)
if(m_DeviceName[v] != 0 && strcmp(DeviceName, m_DeviceName[v]) == 0)
if(m_DeviceName[v][0] != '\0' && strcmp(DeviceName, m_DeviceName[v]) == 0)
return v;
for(v=0;v<MAX_INPUT_DEVICES;v++)
{
if(m_DeviceName[v] == 0)
if(m_DeviceName[v][0] == '\0')
{
m_DeviceName[v] = new char[256];
strncpy(m_DeviceName[v], DeviceName, 255);
return v;