mirror of https://github.com/stella-emu/stella.git
- Added Stelladaptor support for joysticks and paddles. Since I don't
yet have a driving controller, I can't add support for it (donations would be welcome :) - The buttons/axis events seem to work, but I really have to push hard on the sticks for an event to register. It's probably because of the crappy controllers I have. I'll test on a real 2600 when I get a chance. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@243 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
861bf5a21a
commit
5719fa117a
|
@ -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: mainSDL.cxx,v 1.74 2004-05-06 00:06:20 stephena Exp $
|
// $Id: mainSDL.cxx,v 1.75 2004-05-11 19:42:55 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -90,6 +90,14 @@ static bool setupProperties(PropertiesSet& set);
|
||||||
};
|
};
|
||||||
|
|
||||||
static Stella_Joystick theJoysticks[StellaEvent::LastJSTICK];
|
static Stella_Joystick theJoysticks[StellaEvent::LastJSTICK];
|
||||||
|
|
||||||
|
// Static lookup tables for Stelladaptor axis support
|
||||||
|
static Event::Type SA_Axis[2][2][3] = {
|
||||||
|
Event::JoystickZeroLeft, Event::JoystickZeroRight, Event::PaddleZeroResistance,
|
||||||
|
Event::JoystickZeroUp, Event::JoystickZeroDown, Event::PaddleOneResistance,
|
||||||
|
Event::JoystickOneLeft, Event::JoystickOneRight, Event::PaddleTwoResistance,
|
||||||
|
Event::JoystickOneUp, Event::JoystickOneDown, Event::PaddleThreeResistance
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pointer to the console object or the null pointer
|
// Pointer to the console object or the null pointer
|
||||||
|
@ -300,7 +308,7 @@ bool setupJoystick()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Figure out what type of joystick this is
|
// Figure out what type of joystick this is
|
||||||
if(name.substr(0,12) == "Stelladaptor")
|
if(name.find("Stelladaptor", 0) != string::npos)
|
||||||
{
|
{
|
||||||
saCount++;
|
saCount++;
|
||||||
if(saCount > 2) // Ignore more than 2 Stelladaptors
|
if(saCount > 2) // Ignore more than 2 Stelladaptors
|
||||||
|
@ -310,7 +318,7 @@ bool setupJoystick()
|
||||||
}
|
}
|
||||||
else if(saCount == 1)
|
else if(saCount == 1)
|
||||||
{
|
{
|
||||||
name = "Left Stelladaptor (Left joystick, Paddles 0 and 1, Left driving controller)";
|
name = "Left Stelladaptor (Left joystick, Paddles 0 and 1, Left driving controller)";
|
||||||
theJoysticks[i].type = JT_STELLADAPTOR_1;
|
theJoysticks[i].type = JT_STELLADAPTOR_1;
|
||||||
}
|
}
|
||||||
else if(saCount == 2)
|
else if(saCount == 2)
|
||||||
|
@ -573,6 +581,8 @@ void handleEvents()
|
||||||
StellaEvent::JoyCode code;
|
StellaEvent::JoyCode code;
|
||||||
Int32 state;
|
Int32 state;
|
||||||
Uint8 axis;
|
Uint8 axis;
|
||||||
|
Uint8 button;
|
||||||
|
Int32 resistance;
|
||||||
Sint16 value;
|
Sint16 value;
|
||||||
JoyType type;
|
JoyType type;
|
||||||
|
|
||||||
|
@ -586,6 +596,9 @@ void handleEvents()
|
||||||
// Stelladaptors behave differently, and can't be remapped
|
// Stelladaptors behave differently, and can't be remapped
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
|
case JT_NONE:
|
||||||
|
break;
|
||||||
|
|
||||||
case JT_REGULAR:
|
case JT_REGULAR:
|
||||||
|
|
||||||
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
||||||
|
@ -621,28 +634,51 @@ void handleEvents()
|
||||||
break; // Regular joystick
|
break; // Regular joystick
|
||||||
|
|
||||||
case JT_STELLADAPTOR_1:
|
case JT_STELLADAPTOR_1:
|
||||||
|
|
||||||
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
|
||||||
{
|
|
||||||
cerr << "Stelladaptor 1 button activated\n";
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_JOYAXISMOTION)
|
|
||||||
{
|
|
||||||
cerr << "Stelladaptor 1 axis activated\n";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JT_STELLADAPTOR_2:
|
case JT_STELLADAPTOR_2:
|
||||||
|
|
||||||
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
||||||
{
|
{
|
||||||
cerr << "Stelladaptor 2 button activated\n";
|
button = event.jbutton.button;
|
||||||
|
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
|
||||||
|
|
||||||
|
// Send button events for the joysticks/paddles
|
||||||
|
if(button == 0)
|
||||||
|
{
|
||||||
|
if(type == JT_STELLADAPTOR_1)
|
||||||
|
{
|
||||||
|
theConsole->eventHandler().sendEvent(Event::JoystickZeroFire, state);
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleZeroFire, state);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
theConsole->eventHandler().sendEvent(Event::JoystickOneFire, state);
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleOneFire, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(button == 1)
|
||||||
|
{
|
||||||
|
if(type == JT_STELLADAPTOR_1)
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleTwoFire, state);
|
||||||
|
else
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleThreeFire, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(event.type == SDL_JOYAXISMOTION)
|
else if(event.type == SDL_JOYAXISMOTION)
|
||||||
{
|
{
|
||||||
cerr << "Stelladaptor 2 axis activated\n";
|
axis = event.jaxis.axis;
|
||||||
|
value = event.jaxis.value;
|
||||||
|
|
||||||
|
// Send axis events for the joysticks
|
||||||
|
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][0],
|
||||||
|
(value < -16384) ? 1 : 0);
|
||||||
|
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][1],
|
||||||
|
(value > 16384) ? 1 : 0);
|
||||||
|
|
||||||
|
// Send axis events for the paddles
|
||||||
|
resistance = (Int32) (1000000.0 * (32767 - value) / 65534);
|
||||||
|
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][2], resistance);
|
||||||
}
|
}
|
||||||
break;
|
break; // Stelladaptor joystick
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -704,6 +740,14 @@ bool setupProperties(PropertiesSet& set)
|
||||||
*/
|
*/
|
||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
|
#ifdef JOYSTICK_SUPPORT
|
||||||
|
for(uInt32 i = 0; i < StellaEvent::LastJSTICK; i++)
|
||||||
|
{
|
||||||
|
if(SDL_JoystickOpened(i))
|
||||||
|
SDL_JoystickClose(theJoysticks[i].stick);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(theSettings)
|
if(theSettings)
|
||||||
delete theSettings;
|
delete theSettings;
|
||||||
|
|
||||||
|
@ -716,18 +760,7 @@ void cleanup()
|
||||||
if(theDisplay)
|
if(theDisplay)
|
||||||
delete theDisplay;
|
delete theDisplay;
|
||||||
|
|
||||||
if(SDL_WasInit(SDL_INIT_EVERYTHING))
|
SDL_Quit();
|
||||||
{
|
|
||||||
#ifdef JOYSTICK_SUPPORT
|
|
||||||
for(uInt32 i = 0; i < StellaEvent::LastJSTICK; i++)
|
|
||||||
{
|
|
||||||
if(SDL_JoystickOpened(i))
|
|
||||||
SDL_JoystickClose(theJoysticks[i].stick);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue