*** empty log message ***

This commit is contained in:
Aaron Robinson 2003-04-16 19:06:20 +00:00
parent 35b36a3a1c
commit ffb39b86ad
15 changed files with 522 additions and 180 deletions

View File

@ -165,6 +165,10 @@ SOURCE=.\Include\Win32\CxbxKrnl\EmuShared.h
# End Source File
# Begin Source File
SOURCE=.\Include\Win32\CxbxKrnl\EmuXapi.h
# End Source File
# Begin Source File
SOURCE=.\Include\Core\Error.h
# End Source File
# Begin Source File

View File

@ -1,7 +1,5 @@
Cxbx Todo:
Encapsulate XBController. Remove all relevent old implementation modules.
Batch config all buttons (should be very easy..just click one by one)
Encapsulate RecentFiles into a nice little class
@ -12,8 +10,6 @@ Cxbx Todo:
Closing a console should not terminate the entire process.
Everything that is initialized should be cleaned up before termination.
If possible, Direct3D Rendering window should inherit from Wnd.
Try to add compatibility with Windows ME using LLDT assembly.

View File

@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by C:\Aaron\Projects\OpenXDK\cxbx\Resource\Cxbx.rc
// Used by D:\OpenXDK\cxbx\Resource\Cxbx.rc
//
#define IDI_CXBX 101
#define IDB_SPLASH 102

View File

@ -49,6 +49,11 @@ extern "C" CXBXKRNL_API void NTAPI EmuNoFunc();
// ******************************************************************
extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)());
// ******************************************************************
// * func: EmuCleanup
// ******************************************************************
extern "C" CXBXKRNL_API void NTAPI EmuCleanup();
// ******************************************************************
// * func: EmuPanic
// ******************************************************************

View File

@ -47,8 +47,13 @@
extern HWND g_EmuWindow; // Rendering Window
// ******************************************************************
// * func: EmuInitD3D
// * func: EmuD3DInit
// ******************************************************************
void EmuInitD3D(Xbe::Header *XbeHeader, uint32 XbeHeaderSize);
void EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize);
// ******************************************************************
// * func: EmuD3DCleanup
// ******************************************************************
void EmuD3DCleanup();
#endif

View File

@ -48,14 +48,19 @@ namespace xapi
extern xapi::XINPUT_STATE g_EmuController1; // Input Controller
// ******************************************************************
// * func: EmuPollInput
// * func: EmuDInputInit
// ******************************************************************
extern void EmuPollController();
extern void EmuDInputInit();
// ******************************************************************
// * func: EmuInitDInput
// * func: EmuDInputCleanup
// ******************************************************************
extern void EmuInitDInput();
extern void EmuDInputCleanup();
// ******************************************************************
// * func: EmuDInputPoll
// ******************************************************************
extern void EmuDInputPoll();
// ******************************************************************
// * offsets into analog button array

View File

@ -93,6 +93,16 @@ enum XBCtrlObject
XBCTRL_OBJECT_COUNT
};
// ******************************************************************
// * DirectInput Enumeration Types
// ******************************************************************
enum XBCtrlState
{
XBCTRL_STATE_NONE = 0,
XBCTRL_STATE_CONFIG,
XBCTRL_STATE_LISTEN
};
// ******************************************************************
// * Maximum number of devices allowed
// ******************************************************************
@ -111,14 +121,14 @@ struct XBCtrlObjectCfg
// ******************************************************************
// * class: XBController
// ******************************************************************
class XBController : public Error, Mutex
class XBController : public Error
{
public:
// ******************************************************************
// * Initialization
// ******************************************************************
XBController();
~XBController() {};
~XBController();
// ******************************************************************
// * Registry Load/Save
@ -136,9 +146,20 @@ class XBController : public Error, Mutex
// ******************************************************************
// * Listening
// ******************************************************************
void ListeningBegin(HWND hwnd);
void ListeningPoll(xapi::XINPUT_STATE &Controller);
void ListeningEnd();
void ListenBegin(HWND hwnd);
void ListenPoll(xapi::XINPUT_STATE *Controller);
void ListenEnd();
// ******************************************************************
// * DirectInput Init / Cleanup
// ******************************************************************
void DInputInit(HWND hwnd);
void DInputCleanup();
// ******************************************************************
// * Check if a device is currently in the configuration
// ******************************************************************
bool DeviceIsUsed(const char *szDeviceName);
// ******************************************************************
// * Input Device Name Lookup Table
@ -193,10 +214,15 @@ class XBController : public Error, Mutex
}
m_InputDevice[XBCTRL_MAX_DEVICES];
// ******************************************************************
// * Current State
// ******************************************************************
XBCtrlState m_CurrentState;
// ******************************************************************
// * Config State Variables
// ******************************************************************
LONG LastMouse_lX, LastMouse_lY, LastMouse_lZ;
LONG lPrevMouseX, lPrevMouseY, lPrevMouseZ;
XBCtrlObject CurConfigObject;
// ******************************************************************

View File

@ -235,9 +235,10 @@ BEGIN
GROUPBOX "Digital Buttons",IDC_STATIC,2,51,220,46
GROUPBOX "Analog Thumbstick (Left)",IDC_STATIC,226,1,115,47
GROUPBOX "Analog Thumbstick (Right)",IDC_STATIC,227,51,114,46
PUSHBUTTON "Load Configuration...",IDC_BUTTON1,6,102,104,14,BS_FLAT
PUSHBUTTON "Load Configuration...",IDC_BUTTON1,6,102,104,14,BS_FLAT |
WS_DISABLED
PUSHBUTTON "Save Configuration...",IDC_BUTTON2,113,102,104,14,
BS_FLAT
BS_FLAT | WS_DISABLED
CTEXT "Please choose one of the controller components from above...",
IDC_CONFIG_STATUS,6,121,329,12,SS_CENTERIMAGE,
WS_EX_STATICEDGE

View File

@ -230,7 +230,7 @@ cleanup:
// ******************************************************************
{
if(g_XBController.GetError())
strcpy(szNewText, g_XBController.GetError());
sprintf(szNewText, "%s", g_XBController.GetError());
SetWindowText(hWndButton, szOrgText);

View File

@ -229,7 +229,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion
printf("Skipped\n");
}
EmuInitD3D(XbeHeader, XbeHeaderSize);
EmuD3DInit(XbeHeader, XbeHeaderSize);
}
printf("Emu (0x%.08X): Initial thread starting.\n", GetCurrentThreadId());
@ -260,6 +260,21 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion
return;
}
// ******************************************************************
// * func: EmuCleanup
// ******************************************************************
extern "C" CXBXKRNL_API void NTAPI EmuCleanup()
{
if(EmuIsXboxFS())
EmuSwapFS(); // Win2k/XP FS
EmuD3DCleanup();
ExitProcess(0);
return;
}
// ******************************************************************
// * func: EmuPanic
// ******************************************************************
@ -277,7 +292,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuPanic()
MessageBox(NULL, "Kernel Panic! Process will now terminate.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION);
#endif
ExitProcess(1);
EmuCleanup();
EmuSwapFS(); // XBox FS
}
@ -439,16 +454,7 @@ void EmuInstallWrappers(OOVPATable *OovpaTable, uint32 OovpaTableSize, void (*En
// ******************************************************************
int EmuException(LPEXCEPTION_POINTERS e)
{
static int count = 0;
count++;
if(count < 20000)
return EXCEPTION_CONTINUE_EXECUTION;
else
count = 0;
int ret = MessageBox(NULL, "ERROR: Maximum exception count reached.\n\nPress 'OK' to terminate emulation.\nPress 'Cancel' to debug.", "Cxbx", MB_ICONSTOP | MB_OKCANCEL);
int ret = MessageBox(NULL, "ERROR: Recieved Exception.\n\nPress 'OK' to terminate emulation.\nPress 'Cancel' to debug.", "Cxbx", MB_ICONSTOP | MB_OKCANCEL);
if(ret == IDOK)
ExitProcess(1);

View File

@ -78,9 +78,9 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
static void EmuRenderWindow(PVOID);
// ******************************************************************
// * func: EmuInitD3D
// * func: EmuD3DInit
// ******************************************************************
VOID EmuInitD3D(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
VOID EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
{
// ******************************************************************
// * store XbeHeader and XbeHeaderSize for further use
@ -90,6 +90,8 @@ VOID EmuInitD3D(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
g_XbeHeaderSize = XbeHeaderSize;
}
g_ThreadInitialized = false;
// ******************************************************************
// * spark up a new thread to handle window message processing
// ******************************************************************
@ -113,6 +115,16 @@ VOID EmuInitD3D(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
}
}
// ******************************************************************
// * func: EmuD3DCleanup
// ******************************************************************
VOID EmuD3DCleanup()
{
EmuDInputCleanup();
return;
}
// ******************************************************************
// * func: EmuRenderWindow
// ******************************************************************
@ -187,7 +199,7 @@ void EmuRenderWindow(PVOID)
// ******************************************************************
// * initialize direct input
// ******************************************************************
EmuInitDInput();
EmuDInputInit();
// ******************************************************************
// * the other thread can continue now
@ -213,7 +225,7 @@ void EmuRenderWindow(PVOID)
Sleep(10);
}
ExitProcess(0);
EmuCleanup();
}
}
@ -228,50 +240,24 @@ LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0);
return 0;
case WM_CREATE:
{
/* We aren't using a menu anymore
HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll");
HMENU hMenu = LoadMenu(hCxbxDll, MAKEINTRESOURCE(IDR_RENDERMENU));
SetMenu(hWnd, hMenu);
*/
}
break;
/*
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_EMULATION_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0);
break;
}
}
break;
*/
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
}
if(wParam == VK_ESCAPE)
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
/*
case WM_SETCURSOR:
SetCursor(NULL);
break;
*/
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return DefWindowProc(hWnd, msg, wParam, lParam);
return 0;
}
// ******************************************************************

View File

@ -45,6 +45,7 @@
// * exported globals
// ******************************************************************
xapi::XINPUT_STATE g_EmuController1;
XBController g_XBController;
// ******************************************************************
// * prevent name collisions
@ -55,17 +56,30 @@ namespace xapi
};
// ******************************************************************
// * func: EmuInitDInput
// * func: EmuDInputInit
// ******************************************************************
void EmuInitDInput()
void EmuDInputInit()
{
g_EmuShared->GetXBController(&g_XBController);
g_XBController.ListenBegin(g_EmuWindow);
return;
}
// ******************************************************************
// * func: EmuDInputCleanup
// ******************************************************************
void EmuDInputCleanup()
{
g_XBController.ListenEnd();
}
// ******************************************************************
// * func: EmuPollController
// ******************************************************************
void EmuPollController()
void EmuDInputPoll()
{
g_XBController.ListenPoll(&g_EmuController1);
return;
}

View File

@ -276,7 +276,7 @@ DWORD WINAPI xapi::EmuXInputGetState
// and they are always normal Controllers
if((int)hDevice >= 1 && (int)hDevice <= 4)
{
EmuPollController();
EmuDInputPoll();
if((int)hDevice == 1)
memcpy(pState, &g_EmuController1, sizeof(XINPUT_STATE));

View File

@ -52,8 +52,8 @@ void Mutex::Lock()
while(true)
{
// Grab the lock, letting us look at the variables
// while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
while(InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
// while(InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
Sleep(1);
// Are we the the new owner?
@ -99,8 +99,8 @@ void Mutex::Lock()
void Mutex::Unlock()
{
// Grab the lock, letting us look at the variables
// while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
while (InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
// while (InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
Sleep(1);
// Decrement the lock count

View File

@ -40,17 +40,39 @@
// ******************************************************************
XBController::XBController()
{
m_CurrentState = XBCTRL_STATE_NONE;
int v=0;
for(v=0;v<XBCTRL_MAX_DEVICES;v++)
{
m_DeviceName[v][0] = '\0';
m_InputDevice[v].m_Device = NULL;
m_InputDevice[v].m_Flags = 0;
}
for(v=0;v<XBCTRL_OBJECT_COUNT;v++)
{
m_ObjectConfig[v].dwDevice = -1;
m_ObjectConfig[v].dwInfo = -1;
m_ObjectConfig[v].dwFlags = 0;
}
m_pDirectInput8 = NULL;
m_dwInputDeviceCount = 0;
}
// ******************************************************************
// * func: XBController::~XBController
// ******************************************************************
XBController::~XBController()
{
if(m_CurrentState == XBCTRL_STATE_CONFIG)
ConfigEnd();
else if(m_CurrentState == XBCTRL_STATE_LISTEN)
ListenEnd();
}
// ******************************************************************
@ -58,7 +80,11 @@ XBController::XBController()
// ******************************************************************
void XBController::Load(const char *szRegistryKey)
{
Lock();
if(m_CurrentState != XBCTRL_STATE_NONE)
{
SetError("Invalid State", false);
return;
}
// ******************************************************************
// * Load Configuration from Registry
@ -112,8 +138,6 @@ void XBController::Load(const char *szRegistryKey)
RegCloseKey(hKey);
}
}
Unlock();
}
// ******************************************************************
@ -121,7 +145,11 @@ void XBController::Load(const char *szRegistryKey)
// ******************************************************************
void XBController::Save(const char *szRegistryKey)
{
Lock();
if(m_CurrentState != XBCTRL_STATE_NONE)
{
SetError("Invalid State", false);
return;
}
// ******************************************************************
// * Save Configuration to Registry
@ -146,7 +174,9 @@ void XBController::Save(const char *szRegistryKey)
dwType = REG_SZ; dwSize = 260;
if(m_DeviceName[v][0] != '\0')
if(m_DeviceName[v][0] == '\0')
RegDeleteValue(hKey, szValueName);
else
RegSetValueEx(hKey, szValueName, NULL, dwType, (PBYTE)m_DeviceName[v], dwSize);
}
}
@ -171,8 +201,6 @@ void XBController::Save(const char *szRegistryKey)
RegCloseKey(hKey);
}
}
Unlock();
}
// ******************************************************************
@ -180,101 +208,25 @@ void XBController::Save(const char *szRegistryKey)
// ******************************************************************
void XBController::ConfigBegin(HWND hwnd, XBCtrlObject object)
{
// ******************************************************************
// * Create DirectInput Object
// ******************************************************************
if(m_CurrentState != XBCTRL_STATE_NONE)
{
HRESULT hRet = DirectInput8Create
(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&m_pDirectInput8,
NULL
);
if(FAILED(hRet))
{
SetError("Could not initialized DirectInput8", true);
goto cleanup;
}
SetError("Invalid State", false);
return;
}
// ******************************************************************
// * Create all the devices available (well...most of them)
// ******************************************************************
if(m_pDirectInput8 != 0)
{
HRESULT hRet = m_pDirectInput8->EnumDevices
(
DI8DEVCLASS_GAMECTRL,
WrapEnumGameCtrlCallback,
this,
DIEDFL_ATTACHEDONLY
);
m_CurrentState = XBCTRL_STATE_CONFIG;
hRet = m_pDirectInput8->CreateDevice(GUID_SysKeyboard, &m_InputDevice[m_dwInputDeviceCount].m_Device, NULL);
DInputInit(hwnd);
if(!FAILED(hRet))
{
m_InputDevice[m_dwInputDeviceCount].m_Flags = DEVICE_FLAG_KEYBOARD;
if(GetError() != 0)
return;
m_InputDevice[m_dwInputDeviceCount++].m_Device->SetDataFormat(&c_dfDIKeyboard);
}
hRet = m_pDirectInput8->CreateDevice(GUID_SysMouse, &m_InputDevice[m_dwInputDeviceCount].m_Device, NULL);
if(!FAILED(hRet))
{
m_InputDevice[m_dwInputDeviceCount].m_Flags = DEVICE_FLAG_MOUSE;
m_InputDevice[m_dwInputDeviceCount++].m_Device->SetDataFormat(&c_dfDIMouse2);
}
}
// ******************************************************************
// * Set cooperative level and acquire
// ******************************************************************
{
for(int v=m_dwInputDeviceCount-1;v>=0;v--)
{
m_InputDevice[v].m_Device->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
m_InputDevice[v].m_Device->Acquire();
HRESULT hRet = m_InputDevice[v].m_Device->Poll();
if(FAILED(hRet))
{
hRet = m_InputDevice[v].m_Device->Acquire();
while(hRet == DIERR_INPUTLOST)
hRet = m_InputDevice[v].m_Device->Acquire();
if(hRet != DIERR_INPUTLOST)
break;
}
}
}
// ******************************************************************
// * Enumerate Controller objects
// ******************************************************************
{
for(m_dwCurObject=0;m_dwCurObject<m_dwInputDeviceCount;m_dwCurObject++)
m_InputDevice[m_dwCurObject].m_Device->EnumObjects(WrapEnumObjectsCallback, this, DIDFT_ALL);
}
// ******************************************************************
// * Last Mouse Input for Delta Calculations
// ******************************************************************
LastMouse_lX = -1;
LastMouse_lY = -1;
LastMouse_lZ = -1;
lPrevMouseX = -1;
lPrevMouseY = -1;
lPrevMouseZ = -1;
CurConfigObject = object;
cleanup:
return;
}
@ -283,6 +235,12 @@ cleanup:
// ******************************************************************
bool XBController::ConfigPoll(char *szStatus)
{
if(m_CurrentState != XBCTRL_STATE_CONFIG)
{
SetError("Invalid State", false);
return false;
}
DIDEVICEINSTANCE DeviceInstance;
DIDEVICEOBJECTINSTANCE ObjectInstance;
@ -392,7 +350,154 @@ bool XBController::ConfigPoll(char *szStatus)
return true;
}
}
// ******************************************************************
// * Detect Keyboard Input
// ******************************************************************
else if(m_InputDevice[v].m_Flags & DEVICE_FLAG_KEYBOARD)
{
BYTE KeyState[256];
m_InputDevice[v].m_Device->GetDeviceState(256, KeyState);
dwFlags = DEVICE_FLAG_KEYBOARD;
// ******************************************************************
// * Check for Mouse Key State Change
// ******************************************************************
for(int r=0;r<256;r++)
{
if(KeyState[r] != 0)
{
dwHow = r;
break;
}
}
// ******************************************************************
// * Check for Success
// ******************************************************************
if(dwHow != -1)
{
Map(CurConfigObject, "SysKeyboard", dwHow, dwFlags);
printf("Cxbx: Detected Key %d on SysKeyboard\n", dwHow);
sprintf(szStatus, "Success: %s Mapped to Key %d on SysKeyboard", m_DeviceNameLookup[CurConfigObject], dwHow);
return true;
}
}
// ******************************************************************
// * Detect Mouse Input
// ******************************************************************
else if(m_InputDevice[v].m_Flags & DEVICE_FLAG_MOUSE)
{
DIMOUSESTATE2 MouseState;
m_InputDevice[v].m_Device->GetDeviceState(sizeof(MouseState), &MouseState);
dwFlags = DEVICE_FLAG_MOUSE;
// ******************************************************************
// * Detect Button State Change
// ******************************************************************
for(int r=0;r<8;r++)
{
// 0x80 is the mask for button push
if(MouseState.rgbButtons[r] & 0x80)
{
dwHow = r;
dwFlags |= DEVICE_FLAG_MOUSE_CLICK;
break;
}
}
// ******************************************************************
// * Check for Success
// ******************************************************************
if(dwHow != -1)
{
Map(CurConfigObject, "SysMouse", dwHow, dwFlags);
printf("Cxbx: Detected Button %d on SysMouse\n", dwHow);
sprintf(szStatus, "Success: %s Mapped to Button %d on SysMouse", m_DeviceNameLookup[CurConfigObject], dwHow);
return true;
}
// ******************************************************************
// * Check for Mouse Movement
// ******************************************************************
else
{
LONG lAbsDeltaX=0, lAbsDeltaY=0, lAbsDeltaZ=0;
LONG lDeltaX=0, lDeltaY=0, lDeltaZ=0;
if(lPrevMouseX == -1 || lPrevMouseY == -1 || lPrevMouseZ == -1)
lDeltaX = lDeltaY = lDeltaZ = 0;
else
{
lDeltaX = MouseState.lX - lPrevMouseX;
lDeltaY = MouseState.lY - lPrevMouseY;
lDeltaZ = MouseState.lZ - lPrevMouseZ;
lAbsDeltaX = abs(lDeltaX);
lAbsDeltaY = abs(lDeltaY);
lAbsDeltaZ = abs(lDeltaZ);
}
LONG lMax = (lAbsDeltaX > lAbsDeltaY) ? lAbsDeltaX : lAbsDeltaY;
if(lAbsDeltaZ > lMax)
lMax = lAbsDeltaZ;
lPrevMouseX = MouseState.lX;
lPrevMouseY = MouseState.lY;
lPrevMouseZ = MouseState.lZ;
if(lMax > DETECT_SENSITIVITY_MOUSE)
{
dwFlags |= DEVICE_FLAG_AXIS;
if(lMax == lAbsDeltaX)
{
dwHow = DIMOFS_X;
dwFlags |= (lDeltaX > 0) ? DEVICE_FLAG_POSITIVE : DEVICE_FLAG_NEGATIVE;
}
else if(lMax == lAbsDeltaY)
{
dwHow = DIMOFS_Y;
dwFlags |= (lDeltaY > 0) ? DEVICE_FLAG_POSITIVE : DEVICE_FLAG_NEGATIVE;
}
else if(lMax == lAbsDeltaZ)
{
dwHow = DIMOFS_Z;
dwFlags |= (lDeltaZ > 0) ? DEVICE_FLAG_POSITIVE : DEVICE_FLAG_NEGATIVE;
}
}
// ******************************************************************
// * Check for Success
// ******************************************************************
if(dwHow != -1)
{
char *szDirection = (dwFlags & DEVICE_FLAG_POSITIVE) ? "Positive" : "Negative";
char *szObjName = "Unknown";
ObjectInstance.dwSize = sizeof(ObjectInstance);
if(m_InputDevice[v].m_Device->GetObjectInfo(&ObjectInstance, dwHow, DIPH_BYOFFSET) == DI_OK)
szObjName = ObjectInstance.tszName;
Map(CurConfigObject, "SysMouse", dwHow, dwFlags);
printf("Cxbx: Detected Movement on the %s %s on SysMouse\n", szDirection, szObjName);
sprintf(szStatus, "Success: %s Mapped to %s %s on SysMouse", m_DeviceNameLookup[CurConfigObject], szDirection, szObjName);
return true;
}
}
}
}
@ -403,27 +508,207 @@ bool XBController::ConfigPoll(char *szStatus)
// * func: XBController::ConfigEnd
// ******************************************************************
void XBController::ConfigEnd()
{
if(m_CurrentState != XBCTRL_STATE_CONFIG)
{
SetError("Invalid State", false);
return;
}
DInputCleanup();
m_CurrentState = XBCTRL_STATE_NONE;
return;
}
// ******************************************************************
// * func: XBController::ListenBegin
// ******************************************************************
void XBController::ListenBegin(HWND hwnd)
{
if(m_CurrentState != XBCTRL_STATE_NONE)
{
SetError("Invalid State", false);
return;
}
m_CurrentState = XBCTRL_STATE_LISTEN;
DInputInit(hwnd);
return;
}
// ******************************************************************
// * func: XBController::ListenPoll
// ******************************************************************
void XBController::ListenPoll(xapi::XINPUT_STATE *Controller)
{
// TODO: For each device with a configured input device, update changes
static int step = 500;
Controller->Gamepad.sThumbLX += step;
if(Controller->Gamepad.sThumbLX < 0 - 32768 - 2*step ||
Controller->Gamepad.sThumbLX > 0 + 32767 - 2*step)
{
step = -step;
Controller->Gamepad.sThumbLX += step;
}
return;
}
// ******************************************************************
// * func: XBController::ListenEnd
// ******************************************************************
void XBController::ListenEnd()
{
if(m_CurrentState != XBCTRL_STATE_LISTEN)
{
SetError("Invalid State", false);
return;
}
DInputCleanup();
m_CurrentState = XBCTRL_STATE_NONE;
return;
}
// ******************************************************************
// * func: XBController::DeviceIsUsed
// ******************************************************************
bool XBController::DeviceIsUsed(const char *szDeviceName)
{
for(int v=0;v<XBCTRL_MAX_DEVICES;v++)
{
if(m_DeviceName[v][0] != '\0')
{
if(strncmp(m_DeviceName[v], szDeviceName, 255) == 0)
return true;
}
}
return false;
}
// ******************************************************************
// * func: XBController::DInputInit
// ******************************************************************
void XBController::DInputInit(HWND hwnd)
{
// ******************************************************************
// * Cleanup DirectInput
// * Create DirectInput Object
// ******************************************************************
{
HRESULT hRet = DirectInput8Create
(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&m_pDirectInput8,
NULL
);
if(FAILED(hRet))
{
SetError("Could not initialized DirectInput8", true);
return;
}
}
// ******************************************************************
// * Create all the devices available (well...most of them)
// ******************************************************************
if(m_pDirectInput8 != 0)
{
HRESULT hRet = m_pDirectInput8->EnumDevices
(
DI8DEVCLASS_GAMECTRL,
WrapEnumGameCtrlCallback,
this,
DIEDFL_ATTACHEDONLY
);
if(m_CurrentState == XBCTRL_STATE_CONFIG || DeviceIsUsed("SysKeyboard"))
{
hRet = m_pDirectInput8->CreateDevice(GUID_SysKeyboard, &m_InputDevice[m_dwInputDeviceCount].m_Device, NULL);
if(!FAILED(hRet))
{
m_InputDevice[m_dwInputDeviceCount].m_Flags = DEVICE_FLAG_KEYBOARD;
m_InputDevice[m_dwInputDeviceCount++].m_Device->SetDataFormat(&c_dfDIKeyboard);
}
}
if(m_CurrentState == XBCTRL_STATE_CONFIG || DeviceIsUsed("SysMouse"))
{
hRet = m_pDirectInput8->CreateDevice(GUID_SysMouse, &m_InputDevice[m_dwInputDeviceCount].m_Device, NULL);
if(!FAILED(hRet))
{
m_InputDevice[m_dwInputDeviceCount].m_Flags = DEVICE_FLAG_MOUSE;
m_InputDevice[m_dwInputDeviceCount++].m_Device->SetDataFormat(&c_dfDIMouse2);
}
}
}
// ******************************************************************
// * Set cooperative level and acquire
// ******************************************************************
{
for(int v=m_dwInputDeviceCount-1;v>=0;v--)
{
m_InputDevice[v].m_Device->Unacquire();
m_InputDevice[v].m_Device->Release();
m_InputDevice[v].m_Device = 0;
}
m_InputDevice[v].m_Device->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
m_InputDevice[v].m_Device->Acquire();
m_dwInputDeviceCount = 0;
HRESULT hRet = m_InputDevice[v].m_Device->Poll();
if(m_pDirectInput8 != 0)
{
m_pDirectInput8->Release();
m_pDirectInput8 = 0;
if(FAILED(hRet))
{
hRet = m_InputDevice[v].m_Device->Acquire();
while(hRet == DIERR_INPUTLOST)
hRet = m_InputDevice[v].m_Device->Acquire();
if(hRet != DIERR_INPUTLOST)
break;
}
}
}
// ******************************************************************
// * Enumerate Controller objects
// ******************************************************************
for(m_dwCurObject=0;m_dwCurObject<m_dwInputDeviceCount;m_dwCurObject++)
m_InputDevice[m_dwCurObject].m_Device->EnumObjects(WrapEnumObjectsCallback, this, DIDFT_ALL);
}
// ******************************************************************
// * func: XBController::DInputCleanup
// ******************************************************************
void XBController::DInputCleanup()
{
for(int v=m_dwInputDeviceCount-1;v>=0;v--)
{
m_InputDevice[v].m_Device->Unacquire();
m_InputDevice[v].m_Device->Release();
m_InputDevice[v].m_Device = 0;
}
m_dwInputDeviceCount = 0;
if(m_pDirectInput8 != 0)
{
m_pDirectInput8->Release();
m_pDirectInput8 = 0;
}
return;
}
@ -443,8 +728,10 @@ void XBController::Map(XBCtrlObject object, const char *szDeviceName, int dwInfo
bool inuse = false;
for(int r=0;r<XBCTRL_OBJECT_COUNT;r++)
{
if(m_ObjectConfig[r].dwDevice == v)
inuse=true;
}
if(!inuse)
m_DeviceName[v][0] = '\0';
@ -459,8 +746,10 @@ int XBController::Insert(const char *szDeviceName)
int v=0;
for(v=0;v<XBCTRL_MAX_DEVICES;v++)
{
if(strcmp(m_DeviceName[v], szDeviceName) == 0)
return v;
}
for(v=0;v<XBCTRL_MAX_DEVICES;v++)
{
@ -484,6 +773,9 @@ int XBController::Insert(const char *szDeviceName)
// ******************************************************************
BOOL XBController::EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi)
{
if(m_CurrentState == XBCTRL_STATE_LISTEN && DeviceIsUsed(lpddi->tszInstanceName))
return DIENUM_CONTINUE;
HRESULT hRet = m_pDirectInput8->CreateDevice(lpddi->guidInstance, &m_InputDevice[m_dwInputDeviceCount].m_Device, NULL);
if(!FAILED(hRet))
@ -493,6 +785,8 @@ BOOL XBController::EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi)
m_InputDevice[m_dwInputDeviceCount++].m_Device->SetDataFormat(&c_dfDIJoystick);
}
printf("Emu: Monitoring Device %s\n", lpddi->tszInstanceName);
return DIENUM_CONTINUE;
}