mirror of https://github.com/stella-emu/stella.git
Added DirectInput 8 joystick support. For now, up to 8
joysticks are used (the limit in the Stella core). I only have a single joystick on my development system so I haven't yet actually checked if it works with multiple sticks. I see no reason why it wouldn't. Since remapping is now in the Stella core, we automatically get joystick remapping. The core GUI for changing events hasn't been done yet (quite simple, but I'm waiting for the FrameBuffer rewrite), but I've been successful in changing the remapping directly in the stellarc file. So one huge feature request has been completed (multiple joysticks and event remapping), Next I'll work on the remaining oft-requested feature (windowed and fullscreen mode in the same program, without a recompile). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@210 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
35db4988ad
commit
77477bd297
|
@ -13,7 +13,7 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: DirectInput.cxx,v 1.4 2003-11-14 00:47:35 stephena Exp $
|
// $Id: DirectInput.cxx,v 1.5 2003-11-16 19:32:50 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include "pch.hxx"
|
#include "pch.hxx"
|
||||||
|
@ -26,9 +26,10 @@ DirectInput::DirectInput()
|
||||||
mylpdi(NULL),
|
mylpdi(NULL),
|
||||||
myKeyboard(NULL),
|
myKeyboard(NULL),
|
||||||
myMouse(NULL),
|
myMouse(NULL),
|
||||||
myLeftJoystick(NULL),
|
myJoystickCount(0)
|
||||||
myRightJoystick(NULL)
|
|
||||||
{
|
{
|
||||||
|
for(uInt32 i = 0; i < 8; i++)
|
||||||
|
myJoystick[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectInput::~DirectInput()
|
DirectInput::~DirectInput()
|
||||||
|
@ -87,6 +88,70 @@ bool DirectInput::initialize(HWND hwnd)
|
||||||
if(FAILED(myMouse->Acquire()))
|
if(FAILED(myMouse->Acquire()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Initialize all joysticks
|
||||||
|
// Since a joystick isn't absolutely required, we won't return
|
||||||
|
// false if there are none found
|
||||||
|
if(FAILED(mylpdi->EnumDevices(DI8DEVCLASS_GAMECTRL,
|
||||||
|
EnumJoysticksCallback,
|
||||||
|
this, DIEDFL_ATTACHEDONLY)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for(uInt32 i = 0; i < myJoystickCount; i++)
|
||||||
|
{
|
||||||
|
LPDIRECTINPUTDEVICE8 joystick = myJoystick[i];
|
||||||
|
|
||||||
|
if(FAILED(joystick->SetDataFormat(&c_dfDIJoystick2 )))
|
||||||
|
return true;
|
||||||
|
if(FAILED(joystick->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Set the size of the buffer for buffered data
|
||||||
|
DIPROPDWORD j_dipdw;
|
||||||
|
j_dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||||
|
j_dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||||
|
j_dipdw.diph.dwObj = 0;
|
||||||
|
j_dipdw.diph.dwHow = DIPH_DEVICE;
|
||||||
|
j_dipdw.dwData = 64;
|
||||||
|
joystick->SetProperty(DIPROP_BUFFERSIZE, &j_dipdw.diph);
|
||||||
|
|
||||||
|
// Set X-axis range to (-1000 ... +1000)
|
||||||
|
DIPROPRANGE dipr;
|
||||||
|
dipr.diph.dwSize = sizeof(dipr);
|
||||||
|
dipr.diph.dwHeaderSize = sizeof(dipr.diph);
|
||||||
|
dipr.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
dipr.lMin = -1000;
|
||||||
|
dipr.lMax = +1000;
|
||||||
|
dipr.diph.dwObj = DIJOFS_X;
|
||||||
|
joystick->SetProperty(DIPROP_RANGE, &dipr.diph);
|
||||||
|
|
||||||
|
// And again for Y-axis range
|
||||||
|
dipr.diph.dwSize = sizeof(dipr);
|
||||||
|
dipr.diph.dwHeaderSize = sizeof(dipr.diph);
|
||||||
|
dipr.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
dipr.lMin = -1000;
|
||||||
|
dipr.lMax = +1000;
|
||||||
|
dipr.diph.dwObj = DIJOFS_Y;
|
||||||
|
joystick->SetProperty(DIPROP_RANGE, &dipr.diph);
|
||||||
|
|
||||||
|
// Set dead zone to 50%
|
||||||
|
DIPROPDWORD dipdw;
|
||||||
|
dipdw.diph.dwSize = sizeof(dipdw);
|
||||||
|
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
|
||||||
|
dipdw.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
dipdw.dwData = 5000;
|
||||||
|
dipdw.diph.dwObj = DIJOFS_X;
|
||||||
|
joystick->SetProperty(DIPROP_DEADZONE, &dipdw.diph);
|
||||||
|
|
||||||
|
dipdw.diph.dwSize = sizeof(dipdw);
|
||||||
|
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
|
||||||
|
dipdw.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
dipdw.dwData = 5000;
|
||||||
|
dipdw.diph.dwObj = DIJOFS_Y;
|
||||||
|
joystick->SetProperty(DIPROP_DEADZONE, &dipdw.diph);
|
||||||
|
|
||||||
|
joystick->Acquire();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,8 +207,52 @@ bool DirectInput::getMouseEvents(DIDEVICEOBJECTDATA* mouseEvents,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DirectInput::getJoystickEvents(uInt32 stick, DIDEVICEOBJECTDATA* joyEvents,
|
||||||
|
DWORD* numJoyEvents)
|
||||||
|
{
|
||||||
|
LPDIRECTINPUTDEVICE8 joystick;
|
||||||
|
|
||||||
|
// Make sure the joystick exists and has been initialized
|
||||||
|
if(stick >= 0 && stick <= 8)
|
||||||
|
{
|
||||||
|
joystick = myJoystick[stick];
|
||||||
|
if(joystick == NULL)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check for joystick events
|
||||||
|
joystick->Poll();
|
||||||
|
HRESULT hr = joystick->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),
|
||||||
|
joyEvents, numJoyEvents, 0 );
|
||||||
|
|
||||||
|
if(hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)
|
||||||
|
{
|
||||||
|
hr = joystick->Acquire();
|
||||||
|
if(hr == DIERR_OTHERAPPHASPRIO)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
joystick->Poll();
|
||||||
|
hr = joystick->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),
|
||||||
|
joyEvents, numJoyEvents, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void DirectInput::cleanup()
|
void DirectInput::cleanup()
|
||||||
{
|
{
|
||||||
|
for(uInt32 i = 0; i < myJoystickCount; i++)
|
||||||
|
{
|
||||||
|
if(myJoystick[i])
|
||||||
|
{
|
||||||
|
myJoystick[i]->Unacquire();
|
||||||
|
myJoystick[i]->Release();
|
||||||
|
myJoystick[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(myMouse)
|
if(myMouse)
|
||||||
{
|
{
|
||||||
myMouse->Unacquire();
|
myMouse->Unacquire();
|
||||||
|
@ -165,396 +274,28 @@ void DirectInput::cleanup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
BOOL CALLBACK DirectInput::EnumJoysticksCallback(
|
||||||
BOOL CALLBACK DirectInput::EnumDevicesProc
|
const DIDEVICEINSTANCE* inst,
|
||||||
(
|
LPVOID pvRef)
|
||||||
const DIDEVICEINSTANCE* lpddi,
|
|
||||||
LPVOID pvRef
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DirectInput* pThis = (DirectInput*)pvRef;
|
DirectInput* pThis = (DirectInput*) pvRef;
|
||||||
ASSERT(pThis);
|
if(!pThis)
|
||||||
|
return DIENUM_STOP;
|
||||||
|
|
||||||
const DIDATAFORMAT* pdidf = NULL;
|
// If we can't store any more joysticks, then stop enumeration.
|
||||||
|
// The limit is set to 8, since the Stella eventhandler core
|
||||||
|
// can use up to 8 joysticks.
|
||||||
|
if(pThis->myJoystickCount > 8)
|
||||||
|
return DIENUM_STOP;
|
||||||
|
|
||||||
switch(pThis->m_dwDevType)
|
// Obtain an interface to the enumerated joystick.
|
||||||
{
|
HRESULT hr = pThis->mylpdi->CreateDevice(inst->guidInstance,
|
||||||
case DIDEVTYPE_MOUSE:
|
(LPDIRECTINPUTDEVICE8*) &pThis->myJoystick[pThis->myJoystickCount], NULL );
|
||||||
TRACE("EnumDevicesProc (mouse)");
|
|
||||||
pdidf = &c_dfDIMouse;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DIDEVTYPE_KEYBOARD:
|
// Indicate that we've found one more joystick
|
||||||
TRACE("EnumDevicesProc (keyboard)");
|
if(!FAILED(hr))
|
||||||
pdidf = &c_dfDIKeyboard;
|
pThis->myJoystickCount++;
|
||||||
break;
|
|
||||||
|
|
||||||
case DIDEVTYPE_JOYSTICK:
|
// And continue enumeration for more joysticks
|
||||||
TRACE("EnumDevicesProc (joystick)");
|
return DIENUM_CONTINUE;
|
||||||
pdidf = &c_dfDIJoystick;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ASSERT(FALSE);
|
|
||||||
return DIENUM_STOP;
|
|
||||||
};
|
|
||||||
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
IDirectInputDevice* piDID;
|
|
||||||
hr = pThis->m_piDI->CreateDevice(lpddi->guidInstance, &piDID,
|
|
||||||
NULL);
|
|
||||||
ASSERT(hr == DI_OK && "IDI::CreateDevice failed");
|
|
||||||
if (hr != DI_OK)
|
|
||||||
{
|
|
||||||
return DIENUM_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = piDID->SetDataFormat(pdidf);
|
|
||||||
ASSERT(hr == DI_OK && "IDID::SetDataFormat failed");
|
|
||||||
if (hr != DI_OK)
|
|
||||||
{
|
|
||||||
piDID->Release();
|
|
||||||
return DIENUM_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = piDID->QueryInterface(IID_IDirectInputDevice2,
|
|
||||||
(void**)&(pThis->m_piDID));
|
|
||||||
if (hr != S_OK)
|
|
||||||
{
|
|
||||||
piDID->Release();
|
|
||||||
return DIENUM_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// undo the addref that QI did (CreateDevice did an addref)
|
|
||||||
|
|
||||||
pThis->m_piDID->Release();
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
DIDEVICEINSTANCE didi;
|
|
||||||
didi.dwSize = sizeof(didi);
|
|
||||||
piDID->GetDeviceInfo(&didi);
|
|
||||||
TRACE("Using device: %s", didi.tszProductName);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return DIENUM_STOP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DirectInput::IsButtonPressed
|
|
||||||
(
|
|
||||||
int nButton
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
if ( nButton > GetButtonCount() )
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( m_pButtons[nButton] ) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
DirectJoystick::DirectJoystick(
|
|
||||||
HWND hwnd
|
|
||||||
) : \
|
|
||||||
DirectInput( hwnd, DIDEVTYPE_JOYSTICK, 32 )
|
|
||||||
{
|
|
||||||
TRACE( "DirectJoystick::DirectJoystick" );
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT DirectJoystick::Initialize(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
|
||||||
TRACE( "DirectJoystick::Initialize" );
|
|
||||||
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
hr = DirectInput::Initialize();
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( GetDevice() == NULL )
|
|
||||||
{
|
|
||||||
TRACE("No joystick was found");
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set X-axis range to (-1000 ... +1000)
|
|
||||||
// This lets us test against 0 to see which way the stick is pointed.
|
|
||||||
|
|
||||||
DIPROPRANGE dipr;
|
|
||||||
|
|
||||||
dipr.diph.dwSize = sizeof(dipr);
|
|
||||||
dipr.diph.dwHeaderSize = sizeof(dipr.diph);
|
|
||||||
dipr.diph.dwHow = DIPH_BYOFFSET;
|
|
||||||
dipr.lMin = -1000;
|
|
||||||
dipr.lMax = +1000;
|
|
||||||
dipr.diph.dwObj = DIJOFS_X;
|
|
||||||
hr = GetDevice()->SetProperty( DIPROP_RANGE, &dipr.diph );
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
TRACE( "SetProperty(DIPROP_RANGE,x) failed, hr=%X", hr );
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// And again for Y-axis range
|
|
||||||
|
|
||||||
dipr.diph.dwSize = sizeof(dipr);
|
|
||||||
dipr.diph.dwHeaderSize = sizeof(dipr.diph);
|
|
||||||
dipr.diph.dwHow = DIPH_BYOFFSET;
|
|
||||||
dipr.lMin = -1000;
|
|
||||||
dipr.lMax = +1000;
|
|
||||||
dipr.diph.dwObj = DIJOFS_Y;
|
|
||||||
hr = GetDevice()->SetProperty( DIPROP_RANGE, &dipr.diph );
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
TRACE( "SetProperty(DIPROP_RANGE,y) failed, hr=%X", hr );
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// set dead zone to 50%
|
|
||||||
|
|
||||||
DIPROPDWORD dipdw;
|
|
||||||
|
|
||||||
dipdw.diph.dwSize = sizeof(dipdw);
|
|
||||||
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
|
|
||||||
dipdw.diph.dwHow = DIPH_BYOFFSET;
|
|
||||||
dipdw.dwData = 5000;
|
|
||||||
dipdw.diph.dwObj = DIJOFS_X;
|
|
||||||
hr = GetDevice()->SetProperty( DIPROP_DEADZONE, &dipdw.diph );
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
TRACE( "SetProperty(DIPROP_DEADZONE,x) failed, hr=%X", hr );
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
dipdw.diph.dwSize = sizeof(dipdw);
|
|
||||||
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
|
|
||||||
dipdw.diph.dwHow = DIPH_BYOFFSET;
|
|
||||||
dipdw.dwData = 5000;
|
|
||||||
dipdw.diph.dwObj = DIJOFS_Y;
|
|
||||||
hr = GetDevice()->SetProperty( DIPROP_DEADZONE, &dipdw.diph );
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
TRACE( "SetProperty(DIPROP_DEADZONE,y) failed, hr=%X", hr );
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT DirectJoystick::Update(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if ( GetDevice() == NULL )
|
|
||||||
{
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
DIJOYSTATE dijs;
|
|
||||||
|
|
||||||
GetDevice()->Poll();
|
|
||||||
|
|
||||||
hr = GetDevice()->GetDeviceState( sizeof(dijs), &dijs );
|
|
||||||
if ( hr == DIERR_INPUTLOST ||
|
|
||||||
hr == DIERR_NOTACQUIRED )
|
|
||||||
{
|
|
||||||
hr = GetDevice()->Acquire();
|
|
||||||
if ( hr == DIERR_OTHERAPPHASPRIO )
|
|
||||||
{
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetDevice()->Poll();
|
|
||||||
hr = GetDevice()->GetDeviceState( sizeof(dijs), &dijs );
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(hr == DI_OK && "Joystick GetDeviceState failed");
|
|
||||||
|
|
||||||
if ( hr == DI_OK )
|
|
||||||
{
|
|
||||||
m_lX = dijs.lX;
|
|
||||||
m_lY = dijs.lY;
|
|
||||||
|
|
||||||
memcpy( m_pButtons,
|
|
||||||
dijs.rgbButtons,
|
|
||||||
sizeof(dijs.rgbButtons) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
CDisabledJoystick::CDisabledJoystick(
|
|
||||||
HWND hwnd
|
|
||||||
) : \
|
|
||||||
DirectInput( NULL, 0, 0 )
|
|
||||||
{
|
|
||||||
UNUSED_ALWAYS( hwnd );
|
|
||||||
|
|
||||||
TRACE( "CDisabledJoystick::CDisabledJoystick" );
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT CDisabledJoystick::Update(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
DirectMouse::DirectMouse(
|
|
||||||
HWND hwnd
|
|
||||||
) : \
|
|
||||||
DirectInput( hwnd, DIDEVTYPE_MOUSE, 4 )
|
|
||||||
{
|
|
||||||
TRACE( "DirectMouse::DirectMouse" );
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT DirectMouse::Update(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (GetDevice() == NULL)
|
|
||||||
{
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
DIMOUSESTATE dims;
|
|
||||||
|
|
||||||
GetDevice()->Poll();
|
|
||||||
|
|
||||||
hr = GetDevice()->GetDeviceState( sizeof(dims), &dims );
|
|
||||||
if ( hr == DIERR_INPUTLOST ||
|
|
||||||
hr == DIERR_NOTACQUIRED )
|
|
||||||
{
|
|
||||||
hr = GetDevice()->Acquire();
|
|
||||||
if ( hr == DIERR_OTHERAPPHASPRIO )
|
|
||||||
{
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetDevice()->Poll();
|
|
||||||
hr = GetDevice()->GetDeviceState( sizeof(dims), &dims );
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT( hr == DI_OK && "Mouse GetDeviceState failed" );
|
|
||||||
|
|
||||||
if ( hr == DI_OK )
|
|
||||||
{
|
|
||||||
// Because the mouse is returning relative positions,
|
|
||||||
// force X and Y to go between 0 ... 999
|
|
||||||
|
|
||||||
m_lX += dims.lX;
|
|
||||||
|
|
||||||
if (m_lX < 0)
|
|
||||||
{
|
|
||||||
m_lX = 0;
|
|
||||||
}
|
|
||||||
else if (m_lX > 999)
|
|
||||||
{
|
|
||||||
m_lX = 999;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_lY += dims.lY;
|
|
||||||
|
|
||||||
if (m_lY < 0)
|
|
||||||
{
|
|
||||||
m_lY = 0;
|
|
||||||
}
|
|
||||||
else if (m_lY > 999)
|
|
||||||
{
|
|
||||||
m_lY = 999;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy( m_pButtons,
|
|
||||||
dims.rgbButtons,
|
|
||||||
sizeof(dims.rgbButtons) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
|
||||||
// The following was part of initialize
|
|
||||||
///////////////////////////////////////
|
|
||||||
/*
|
|
||||||
// initialize the mouse
|
|
||||||
if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &m_mouse, NULL)))
|
|
||||||
return false;
|
|
||||||
if (FAILED(m_mouse->SetCooperativeLevel(hWnd, DISCL_BACKGROUND |
|
|
||||||
DISCL_NONEXCLUSIVE)))
|
|
||||||
return false;
|
|
||||||
if (FAILED(m_mouse->SetDataFormat(&c_dfDIMouse)))
|
|
||||||
return false;
|
|
||||||
if (FAILED(m_mouse->Acquire()))
|
|
||||||
return false;
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
//
|
|
||||||
// enumerate to find proper device
|
|
||||||
// The callback will set m_piDID
|
|
||||||
//
|
|
||||||
|
|
||||||
TRACE("\tCalling EnumDevices");
|
|
||||||
|
|
||||||
hr = m_piDI->EnumDevices( m_dwDevType,
|
|
||||||
EnumDevicesProc,
|
|
||||||
this,
|
|
||||||
DIEDFL_ATTACHEDONLY );
|
|
||||||
if ( m_piDID )
|
|
||||||
{
|
|
||||||
TRACE("\tGot a device!");
|
|
||||||
|
|
||||||
(void)m_piDID->SetCooperativeLevel( m_hwnd,
|
|
||||||
DISCL_NONEXCLUSIVE
|
|
||||||
| DISCL_FOREGROUND);
|
|
||||||
|
|
||||||
hr = GetDevice()->Acquire();
|
|
||||||
if ( hr == DIERR_OTHERAPPHASPRIO )
|
|
||||||
{
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pButtons = new BYTE[GetButtonCount()];
|
|
||||||
if ( m_pButtons == NULL )
|
|
||||||
{
|
|
||||||
hr = E_OUTOFMEMORY;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_fInitialized = TRUE;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
Cleanup();
|
|
||||||
|
|
||||||
if ( uMsg != 0 )
|
|
||||||
{
|
|
||||||
MessageBox( hInstance, m_hwnd, uMsg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hr;
|
|
||||||
*/
|
|
||||||
|
|
|
@ -13,12 +13,14 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: DirectInput.hxx,v 1.5 2003-11-14 00:47:35 stephena Exp $
|
// $Id: DirectInput.hxx,v 1.6 2003-11-16 19:32:51 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#ifndef DIRECT_INPUT_HXX
|
#ifndef DIRECT_INPUT_HXX
|
||||||
#define DIRECT_INPUT_HXX
|
#define DIRECT_INPUT_HXX
|
||||||
|
|
||||||
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "dinput.h"
|
#include "dinput.h"
|
||||||
|
|
||||||
|
@ -30,23 +32,28 @@ class DirectInput
|
||||||
|
|
||||||
bool getKeyEvents(DIDEVICEOBJECTDATA* keyEvents, DWORD* numKeyEvents);
|
bool getKeyEvents(DIDEVICEOBJECTDATA* keyEvents, DWORD* numKeyEvents);
|
||||||
bool getMouseEvents(DIDEVICEOBJECTDATA* mouseEvents, DWORD* numMouseEvents);
|
bool getMouseEvents(DIDEVICEOBJECTDATA* mouseEvents, DWORD* numMouseEvents);
|
||||||
|
bool getJoystickEvents(uInt32 stick, DIDEVICEOBJECTDATA* joyEvents,
|
||||||
|
DWORD* numJoyEvents);
|
||||||
|
|
||||||
bool initialize(HWND hwnd);
|
bool initialize(HWND hwnd);
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
uInt32 numJoysticks() { return myJoystickCount; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
static BOOL CALLBACK EnumDevicesProc(const DIDEVICEINSTANCE* lpddi, LPVOID pvRef );
|
static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* inst,
|
||||||
|
LPVOID pvRef);
|
||||||
|
|
||||||
HWND myHWND;
|
HWND myHWND;
|
||||||
|
|
||||||
LPDIRECTINPUT8 mylpdi;
|
LPDIRECTINPUT8 mylpdi;
|
||||||
LPDIRECTINPUTDEVICE8 myKeyboard;
|
LPDIRECTINPUTDEVICE8 myKeyboard;
|
||||||
LPDIRECTINPUTDEVICE8 myMouse;
|
LPDIRECTINPUTDEVICE8 myMouse;
|
||||||
LPDIRECTINPUTDEVICE8 myLeftJoystick;
|
LPDIRECTINPUTDEVICE8 myJoystick[8];
|
||||||
LPDIRECTINPUTDEVICE8 myRightJoystick;
|
uInt32 myJoystickCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: FrameBufferWin32.cxx,v 1.3 2003-11-14 00:47:35 stephena Exp $
|
// $Id: FrameBufferWin32.cxx,v 1.4 2003-11-16 19:32:52 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -48,14 +48,12 @@ FrameBufferWin32::FrameBufferWin32()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
FrameBufferWin32::~FrameBufferWin32()
|
FrameBufferWin32::~FrameBufferWin32()
|
||||||
{
|
{
|
||||||
OutputDebugString("got here FrameBufferWin32::~FrameBufferWin32()");
|
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void FrameBufferWin32::cleanup()
|
void FrameBufferWin32::cleanup()
|
||||||
{
|
{
|
||||||
OutputDebugString("got here FrameBufferWin32::cleanup()");
|
|
||||||
if(m_piDDPalette)
|
if(m_piDDPalette)
|
||||||
{
|
{
|
||||||
m_piDDPalette->Release();
|
m_piDDPalette->Release();
|
||||||
|
@ -83,7 +81,7 @@ OutputDebugString("got here FrameBufferWin32::cleanup()");
|
||||||
if(myHWND)
|
if(myHWND)
|
||||||
{
|
{
|
||||||
::DestroyWindow( myHWND );
|
::DestroyWindow( myHWND );
|
||||||
OutputDebugString("got here destroyed window");
|
|
||||||
//
|
//
|
||||||
// Remove the WM_QUIT which will be in the message queue
|
// Remove the WM_QUIT which will be in the message queue
|
||||||
// so that the main window doesn't exit
|
// so that the main window doesn't exit
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: MainWin32.cxx,v 1.2 2003-11-14 00:47:35 stephena Exp $
|
// $Id: MainWin32.cxx,v 1.3 2003-11-16 19:32:52 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#define STRICT
|
#define STRICT
|
||||||
|
@ -89,11 +89,13 @@ MainWin32::MainWin32(const uInt8* image, uInt32 size, const char* filename,
|
||||||
myIsInitialized = true;
|
myIsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
MainWin32::~MainWin32()
|
MainWin32::~MainWin32()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void MainWin32::cleanup()
|
void MainWin32::cleanup()
|
||||||
{
|
{
|
||||||
ShowCursor(TRUE);
|
ShowCursor(TRUE);
|
||||||
|
@ -113,6 +115,7 @@ void MainWin32::cleanup()
|
||||||
myIsInitialized = false;
|
myIsInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
DWORD MainWin32::run()
|
DWORD MainWin32::run()
|
||||||
{
|
{
|
||||||
if(!myIsInitialized)
|
if(!myIsInitialized)
|
||||||
|
@ -200,6 +203,7 @@ DWORD MainWin32::run()
|
||||||
return msg.wParam;
|
return msg.wParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void MainWin32::UpdateEvents()
|
void MainWin32::UpdateEvents()
|
||||||
{
|
{
|
||||||
DIDEVICEOBJECTDATA eventArray[64];
|
DIDEVICEOBJECTDATA eventArray[64];
|
||||||
|
@ -281,66 +285,55 @@ void MainWin32::UpdateEvents()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
//
|
|
||||||
// Update joystick
|
|
||||||
//
|
|
||||||
|
|
||||||
FIXME - add multiple joysticks
|
// Check for joystick events
|
||||||
if (m_pDirectJoystick->Update() == S_OK)
|
for(uInt32 joystick = 0; joystick < theInput->numJoysticks(); joystick++)
|
||||||
{
|
{
|
||||||
rgEventState[Event::JoystickZeroFire] |=
|
numEvents = 64;
|
||||||
m_pDirectJoystick->IsButtonPressed(0);
|
if(theInput->getJoystickEvents(joystick, eventArray, &numEvents))
|
||||||
|
{
|
||||||
LONG x;
|
StellaEvent::JoyStick stick = joyList[joystick];
|
||||||
LONG y;
|
StellaEvent::JoyCode code;
|
||||||
m_pDirectJoystick->GetPos( &x, &y );
|
|
||||||
|
for(uInt32 i = 0; i < numEvents; i++ )
|
||||||
if (x < 0)
|
{
|
||||||
{
|
Event::Type type = Event::LastType;
|
||||||
rgEventState[Event::JoystickZeroLeft] = 1;
|
Int32 state, value;
|
||||||
}
|
|
||||||
else if (x > 0)
|
if(eventArray[i].dwOfs == DIJOFS_X) // left-right motion
|
||||||
{
|
{
|
||||||
rgEventState[Event::JoystickZeroRight] = 1;
|
value = (Int32) eventArray[i].dwData;
|
||||||
}
|
|
||||||
if (y < 0)
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_LEFT,
|
||||||
{
|
(value < 0) ? 1 : 0);
|
||||||
rgEventState[Event::JoystickZeroUp] = 1;
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_RIGHT,
|
||||||
}
|
(value > 0) ? 1 : 0);
|
||||||
else if (y > 0)
|
}
|
||||||
{
|
else if(eventArray[i].dwOfs == DIJOFS_Y) // up-down motion
|
||||||
rgEventState[Event::JoystickZeroDown] = 1;
|
{
|
||||||
}
|
value = (Int32) eventArray[i].dwData;
|
||||||
}
|
|
||||||
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_UP,
|
||||||
//
|
(value < 0) ? 1 : 0);
|
||||||
// Update mouse
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_DOWN,
|
||||||
//
|
(value > 0) ? 1 : 0);
|
||||||
|
}
|
||||||
if (m_pDirectMouse->Update() == S_OK)
|
else // Check for button press and release
|
||||||
{
|
{
|
||||||
// NOTE: Mouse::GetPos returns a value from 0..999
|
for(uInt32 j = 0; j < StellaEvent::LastJCODE-4; j++)
|
||||||
|
{
|
||||||
LONG x;
|
if(eventArray[i].dwOfs == DIJOFS_BUTTON(j))
|
||||||
m_pDirectMouse->GetPos( &x, NULL );
|
{
|
||||||
|
code = joyButtonList[j];
|
||||||
// Mouse resistance is measured between 0...1000000
|
state = (Int32) eventArray[i].dwData & 0x80 ? 1 : 0;
|
||||||
|
|
||||||
// rgEventState[ m_rGlobalData->PaddleResistanceEvent() ] = (999-x)*1000;
|
theConsole->eventHandler().sendJoyEvent(stick, code, state);
|
||||||
|
}
|
||||||
// rgEventState[ m_rGlobalData->PaddleFireEvent() ] |= m_pDirectMouse->IsButtonPressed(0);
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//
|
}
|
||||||
// Write new event state
|
}
|
||||||
//
|
|
||||||
|
|
||||||
// for (i = 0; i < nEventCount; ++i)
|
|
||||||
// {
|
|
||||||
// m_rEvent.set( (Event::Type)i, rgEventState[i] );
|
|
||||||
// }
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -457,3 +450,22 @@ MainWin32::Switches MainWin32::keyList[StellaEvent::LastKCODE] = {
|
||||||
{ DIK_END, StellaEvent::KCODE_END },
|
{ DIK_END, StellaEvent::KCODE_END },
|
||||||
{ DIK_NEXT, StellaEvent::KCODE_PAGEDOWN }
|
{ DIK_NEXT, StellaEvent::KCODE_PAGEDOWN }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
StellaEvent::JoyStick MainWin32::joyList[StellaEvent::LastJSTICK] = {
|
||||||
|
StellaEvent::JSTICK_0, StellaEvent::JSTICK_1,
|
||||||
|
StellaEvent::JSTICK_2, StellaEvent::JSTICK_3,
|
||||||
|
StellaEvent::JSTICK_4, StellaEvent::JSTICK_5,
|
||||||
|
StellaEvent::JSTICK_6, StellaEvent::JSTICK_7
|
||||||
|
};
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
StellaEvent::JoyCode MainWin32::joyButtonList[StellaEvent::LastJCODE-4] = {
|
||||||
|
StellaEvent::JBUTTON_0, StellaEvent::JBUTTON_1, StellaEvent::JBUTTON_2,
|
||||||
|
StellaEvent::JBUTTON_3, StellaEvent::JBUTTON_4, StellaEvent::JBUTTON_5,
|
||||||
|
StellaEvent::JBUTTON_6, StellaEvent::JBUTTON_7, StellaEvent::JBUTTON_8,
|
||||||
|
StellaEvent::JBUTTON_9, StellaEvent::JBUTTON_10, StellaEvent::JBUTTON_11,
|
||||||
|
StellaEvent::JBUTTON_12, StellaEvent::JBUTTON_13, StellaEvent::JBUTTON_14,
|
||||||
|
StellaEvent::JBUTTON_15, StellaEvent::JBUTTON_16, StellaEvent::JBUTTON_17,
|
||||||
|
StellaEvent::JBUTTON_18, StellaEvent::JBUTTON_19
|
||||||
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: MainWin32.hxx,v 1.2 2003-11-14 00:47:35 stephena Exp $
|
// $Id: MainWin32.hxx,v 1.3 2003-11-16 19:32:52 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#ifndef MAIN_WIN32_HXX
|
#ifndef MAIN_WIN32_HXX
|
||||||
|
@ -41,7 +41,7 @@ class DirectInput;
|
||||||
in the Porting.txt document
|
in the Porting.txt document
|
||||||
|
|
||||||
@author Stephen Anthony
|
@author Stephen Anthony
|
||||||
@version $Id: MainWin32.hxx,v 1.2 2003-11-14 00:47:35 stephena Exp $
|
@version $Id: MainWin32.hxx,v 1.3 2003-11-16 19:32:52 stephena Exp $
|
||||||
*/
|
*/
|
||||||
class MainWin32
|
class MainWin32
|
||||||
{
|
{
|
||||||
|
@ -96,6 +96,10 @@ class MainWin32
|
||||||
};
|
};
|
||||||
static Switches keyList[StellaEvent::LastKCODE];
|
static Switches keyList[StellaEvent::LastKCODE];
|
||||||
|
|
||||||
|
// Lookup tables for joystick numbers and events
|
||||||
|
static StellaEvent::JoyStick joyList[StellaEvent::LastJSTICK];
|
||||||
|
static StellaEvent::JoyCode joyButtonList[StellaEvent::LastJCODE-4];
|
||||||
|
|
||||||
const CGlobalData* m_rGlobalData;
|
const CGlobalData* m_rGlobalData;
|
||||||
|
|
||||||
// Indicates the current mouse position in the X direction
|
// Indicates the current mouse position in the X direction
|
||||||
|
|
Loading…
Reference in New Issue