fixed QuadTari handling for controller types != joysticks

This commit is contained in:
thrust26 2021-03-02 14:01:57 +01:00
parent 852205edf8
commit 75527ca670
14 changed files with 200 additions and 57 deletions

View File

@ -17,6 +17,7 @@
#include "OSystem.hxx"
#include "Console.hxx"
#include "PropsSet.hxx"
#include "EventHandler.hxx"
#include "PKeyboardHandler.hxx"
#include "json_lib.hxx"
@ -202,38 +203,72 @@ void PhysicalKeyboardHandler::setDefaultMapping(Event::Type event, EventMode mod
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::defineControllerMappings(
const Controller::Type type, Controller::Jack port)
const Controller::Type type, Controller::Jack port, const string& md5)
{
// determine controller events to use
switch(type)
{
case Controller::Type::QuadTari:
if(port == Controller::Jack::Left)
{
myLeftMode = getMode(md5, PropType::Controller_Left1);
myLeft2ndMode = getMode(md5, PropType::Controller_Left2);
}
else
{
myRightMode = getMode(md5, PropType::Controller_Right1);
myRight2ndMode = getMode(md5, PropType::Controller_Right2);
}
break;
default:
{
EventMode mode = getMode(type);
if(port == Controller::Jack::Left)
myLeftMode = mode;
else
myRightMode = mode;
break;
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventMode PhysicalKeyboardHandler::getMode(const string& md5, const PropType propType)
{
Properties properties;
if(myOSystem.propSet().getMD5(md5, properties))
{
const string& propName = properties.get(propType);
if(!propName.empty())
return getMode(Controller::getType(propName));
}
return getMode(Controller::Type::Joystick);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventMode PhysicalKeyboardHandler::getMode(const Controller::Type type)
{
switch(type)
{
case Controller::Type::Keyboard:
case Controller::Type::KidVid:
if(port == Controller::Jack::Left)
myLeftMode = EventMode::kKeypadMode;
else
myRightMode = EventMode::kKeypadMode;
break;
return EventMode::kKeypadMode;
case Controller::Type::Paddles:
case Controller::Type::PaddlesIAxDr:
case Controller::Type::PaddlesIAxis:
if(port == Controller::Jack::Left)
myLeftMode = EventMode::kPaddlesMode;
else
myRightMode = EventMode::kPaddlesMode;
break;
return EventMode::kPaddlesMode;
case Controller::Type::CompuMate:
myLeftMode = myRightMode = EventMode::kCompuMateMode;
break;
return EventMode::kCompuMateMode;
default:
// let's use joystick then
if(port == Controller::Jack::Left)
myLeftMode = EventMode::kJoystickMode;
else
myRightMode = EventMode::kJoystickMode;
return EventMode::kJoystickMode;
}
}
@ -244,9 +279,31 @@ void PhysicalKeyboardHandler::enableEmulationMappings()
myKeyMap.eraseMode(EventMode::kEmulationMode);
enableCommonMappings();
// enable right mode first, so that in case of mapping clashes the left
// controller has preference
switch (myRightMode)
// Process in increasing priority order, so that in case of mapping clashes
// the higher priority controller has preference
switch(myRight2ndMode)
{
case EventMode::kPaddlesMode:
enableMappings(Right2PaddlesEvents, EventMode::kPaddlesMode);
break;
default:
enableMappings(Right2JoystickEvents, EventMode::kJoystickMode);
break;
}
switch(myLeft2ndMode)
{
case EventMode::kPaddlesMode:
enableMappings(Left2PaddlesEvents, EventMode::kPaddlesMode);
break;
default:
enableMappings(Left2JoystickEvents, EventMode::kJoystickMode);
break;
}
switch(myRightMode)
{
case EventMode::kPaddlesMode:
enableMappings(RightPaddlesEvents, EventMode::kPaddlesMode);
@ -265,7 +322,7 @@ void PhysicalKeyboardHandler::enableEmulationMappings()
break;
}
switch (myLeftMode)
switch(myLeftMode)
{
case EventMode::kPaddlesMode:
enableMappings(LeftPaddlesEvents, EventMode::kPaddlesMode);
@ -276,7 +333,7 @@ void PhysicalKeyboardHandler::enableEmulationMappings()
break;
case EventMode::kCompuMateMode:
for (const auto& item : CompuMateMapping)
for(const auto& item : CompuMateMapping)
enableMapping(item.event, EventMode::kCompuMateMode);
break;
@ -343,14 +400,18 @@ EventMode PhysicalKeyboardHandler::getEventMode(const Event::Type event,
bool PhysicalKeyboardHandler::isJoystickEvent(const Event::Type event) const
{
return LeftJoystickEvents.find(event) != LeftJoystickEvents.end()
|| RightJoystickEvents.find(event) != RightJoystickEvents.end();
|| Left2JoystickEvents.find(event) != Left2JoystickEvents.end()
|| RightJoystickEvents.find(event) != RightJoystickEvents.end()
|| Right2JoystickEvents.find(event) != Right2JoystickEvents.end();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalKeyboardHandler::isPaddleEvent(const Event::Type event) const
{
return LeftPaddlesEvents.find(event) != LeftPaddlesEvents.end()
|| RightPaddlesEvents.find(event) != RightPaddlesEvents.end();
|| Left2PaddlesEvents.find(event) != Left2PaddlesEvents.end()
|| RightPaddlesEvents.find(event) != RightPaddlesEvents.end()
|| Right2PaddlesEvents.find(event) != Right2PaddlesEvents.end();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -412,7 +473,8 @@ bool PhysicalKeyboardHandler::addMapping(Event::Type event, EventMode mode,
}
myKeyMap.add(event, evMode, key, mod);
if (evMode == myLeftMode || evMode == myRightMode)
if (evMode == myLeftMode || evMode == myRightMode ||
evMode == myLeft2ndMode || evMode == myRight2ndMode)
myKeyMap.add(event, mode, key, mod);
}
@ -858,6 +920,7 @@ PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultJoyst
{Event::JoystickOneFire5, KBDK_6},
{Event::JoystickOneFire9, KBDK_7},
// Same as Joysticks Zero & One + SHIFT
{Event::JoystickTwoUp, KBDK_UP, KBDM_SHIFT},
{Event::JoystickTwoDown, KBDK_DOWN, KBDM_SHIFT},
{Event::JoystickTwoLeft, KBDK_LEFT, KBDM_SHIFT},
@ -896,6 +959,12 @@ PhysicalKeyboardHandler::DefaultPaddleMapping = {
{Event::PaddleThreeDecrease, KBDK_H},
{Event::PaddleThreeIncrease, KBDK_Y},
{Event::PaddleThreeFire, KBDK_6},
// Same as Paddles Zero..Three Fire + SHIFT
{Event::PaddleFourFire, KBDK_SPACE, KBDM_SHIFT},
{Event::PaddleFiveFire, KBDK_4, KBDM_SHIFT},
{Event::PaddleSixFire, KBDK_F, KBDM_SHIFT},
{Event::PaddleSevenFire, KBDK_6, KBDM_SHIFT},
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -26,6 +26,7 @@ class EventHandler;
#include "bspf.hxx"
#include "Event.hxx"
#include "EventHandlerConstants.hxx"
#include "Props.hxx"
#include "KeyMap.hxx"
/**
@ -50,7 +51,8 @@ class PhysicalKeyboardHandler
void setDefaultMapping(Event::Type type, EventMode mode, bool updateDefaults = false);
/** define mappings for current controllers */
void defineControllerMappings(const Controller::Type type, Controller::Jack port);
void defineControllerMappings(const Controller::Type type, Controller::Jack port,
const string& md5);
/** enable mappings for emulation mode */
void enableEmulationMappings();
@ -110,6 +112,11 @@ class PhysicalKeyboardHandler
void enableMappings(const Event::EventSet& events, EventMode mode);
void enableMapping(const Event::Type event, EventMode mode);
/** return event mode for given property */
EventMode getMode(const string& md5, const PropType propType);
/** return event mode for given controller type */
EventMode getMode(const Controller::Type type);
private:
OSystem& myOSystem;
EventHandler& myHandler;
@ -119,6 +126,9 @@ class PhysicalKeyboardHandler
EventMode myLeftMode{EventMode::kEmulationMode};
EventMode myRightMode{EventMode::kEmulationMode};
// Additional modes for QuadTari controller
EventMode myLeft2ndMode{EventMode::kEmulationMode};
EventMode myRight2ndMode{EventMode::kEmulationMode};
#ifdef BSPF_UNIX
// Sometimes key combos with the Alt key become 'stuck' after the

View File

@ -18,7 +18,7 @@
#ifndef VERSION_HXX
#define VERSION_HXX
#define STELLA_VERSION "6.5.2"
#define STELLA_VERSION "6.6_pre"
#define STELLA_BUILD "6719"
#endif

View File

@ -112,6 +112,10 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Event::Type, {
{Event::PaddleThreeIncrease, "PaddleThreeIncrease"},
{Event::PaddleThreeAnalog, "PaddleThreeAnalog"},
{Event::PaddleThreeFire, "PaddleThreeFire"},
{Event::PaddleFourFire, "PaddleFourFire"},
{Event::PaddleFiveFire, "PaddleFiveFire"},
{Event::PaddleSixFire, "PaddleSixFire"},
{Event::PaddleSevenFire, "PaddleSevenFire"},
{Event::KeyboardZero1, "KeyboardZero1"},
{Event::KeyboardZero2, "KeyboardZero2"},
{Event::KeyboardZero3, "KeyboardZero3"},

View File

@ -35,7 +35,7 @@ class Thumbulator;
IN A FUTURE RELEASE.
There are seven 4K program banks, a 4K Display Data RAM,
1K C Varaible and Stack, and the BUS chip.
1K C Variable and Stack, and the BUS chip.
BUS chip access is mapped to $1000 - $103F.
@authors: Darrell Spice Jr, Chris Walton, Fred Quimby,

View File

@ -806,7 +806,7 @@ void Console::setControllers(const string& romMd5)
myLeftControl = std::move(myCMHandler->leftController());
myRightControl = std::move(myCMHandler->rightController());
myOSystem.eventHandler().defineKeyControllerMappings(
Controller::Type::CompuMate, Controller::Jack::Left);
Controller::Type::CompuMate, Controller::Jack::Left, romMd5);
myOSystem.eventHandler().defineJoyControllerMappings(
Controller::Type::CompuMate, Controller::Jack::Left);
}
@ -898,7 +898,7 @@ unique_ptr<Controller> Console::getControllerPort(const Controller::Type type,
{
unique_ptr<Controller> controller;
myOSystem.eventHandler().defineKeyControllerMappings(type, port);
myOSystem.eventHandler().defineKeyControllerMappings(type, port, romMd5);
myOSystem.eventHandler().defineJoyControllerMappings(type, port);
switch(type)

View File

@ -73,7 +73,7 @@ class Controller : public Serializable
/**
Enumeration of the controller jacks
*/
enum class Jack { Left = 0, Right = 1 };
enum class Jack { Left = 0, Right = 1, Left2 = 2, Right2 = 3 };
/**
Enumeration of the digital pins of a controller port

View File

@ -165,7 +165,9 @@ class Event
DecreasePaddleCenterY, IncreasePaddleCenterY,
PreviousMouseControl,
DecreaseMouseAxesRange, IncreaseMouseAxesRange,
SALeftAxis0Value, SALeftAxis1Value, SARightAxis0Value, SARightAxis1Value,
PaddleFourFire, PaddleFiveFire, PaddleSixFire, PaddleSevenFire,
LastType
};
@ -255,13 +257,20 @@ class Event
static const Event::EventSet LeftJoystickEvents = {
Event::JoystickZeroUp, Event::JoystickZeroDown, Event::JoystickZeroLeft, Event::JoystickZeroRight,
Event::JoystickZeroFire, Event::JoystickZeroFire5, Event::JoystickZeroFire9,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet Left2JoystickEvents = {
Event::JoystickTwoUp, Event::JoystickTwoDown, Event::JoystickTwoLeft, Event::JoystickTwoRight,
Event::JoystickTwoFire
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet RightJoystickEvents = {
Event::JoystickOneUp, Event::JoystickOneDown, Event::JoystickOneLeft, Event::JoystickOneRight,
Event::JoystickOneFire, Event::JoystickOneFire5, Event::JoystickOneFire9,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet Right2JoystickEvents = {
Event::JoystickThreeUp, Event::JoystickThreeDown, Event::JoystickThreeLeft, Event::JoystickThreeRight,
Event::JoystickThreeFire
};
@ -271,12 +280,22 @@ static const Event::EventSet LeftPaddlesEvents = {
Event::PaddleZeroDecrease, Event::PaddleZeroIncrease, Event::PaddleZeroAnalog, Event::PaddleZeroFire,
Event::PaddleOneDecrease, Event::PaddleOneIncrease, Event::PaddleOneAnalog, Event::PaddleOneFire,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet Left2PaddlesEvents = {
// Only fire buttons supported by QuadTari
Event::PaddleFourFire, Event::PaddleFiveFire
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet RightPaddlesEvents = {
Event::PaddleTwoDecrease, Event::PaddleTwoIncrease, Event::PaddleTwoAnalog, Event::PaddleTwoFire,
Event::PaddleThreeDecrease, Event::PaddleThreeIncrease, Event::PaddleThreeAnalog, Event::PaddleThreeFire,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet Right2PaddlesEvents = {
// Only fire buttons supported by QuadTari
Event::PaddleSixFire, Event::PaddleSevenFire
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static const Event::EventSet LeftKeypadEvents = {

View File

@ -3110,6 +3110,11 @@ EventHandler::EmulActionList EventHandler::ourEmulActionList = { {
{ Event::PaddleThreeDecrease, "Paddle 3 Turn Right", "" },
{ Event::PaddleThreeFire, "Paddle 3 Fire", "" },
{ Event::PaddleFourFire, "Paddle 4 Fire", "" },
{ Event::PaddleFiveFire, "Paddle 5 Fire", "" },
{ Event::PaddleSixFire, "Paddle 6 Fire", "" },
{ Event::PaddleSevenFire, "Paddle 7 Fire", "" },
{ Event::KeyboardZero1, "P0 Keyboard 1", "" },
{ Event::KeyboardZero2, "P0 Keyboard 2", "" },
{ Event::KeyboardZero3, "P0 Keyboard 3", "" },
@ -3378,6 +3383,7 @@ const Event::EventSet EventHandler::PaddlesEvents = {
Event::PaddleOneDecrease, Event::PaddleOneIncrease, Event::PaddleOneAnalog, Event::PaddleOneFire,
Event::PaddleTwoDecrease, Event::PaddleTwoIncrease, Event::PaddleTwoAnalog, Event::PaddleTwoFire,
Event::PaddleThreeDecrease, Event::PaddleThreeIncrease, Event::PaddleThreeAnalog, Event::PaddleThreeFire,
Event::PaddleFourFire, Event::PaddleFiveFire,Event::PaddleSixFire,Event::PaddleSevenFire,
};
const Event::EventSet EventHandler::KeyboardEvents = {

View File

@ -217,8 +217,9 @@ class EventHandler
/**
Enable controller specific keyboard event mappings.
*/
void defineKeyControllerMappings(const Controller::Type type, Controller::Jack port) {
myPKeyHandler->defineControllerMappings(type, port);
void defineKeyControllerMappings(const Controller::Type type, Controller::Jack port,
const string& md5) {
myPKeyHandler->defineControllerMappings(type, port, md5);
}
/**
@ -644,7 +645,7 @@ class EventHandler
#else
REFRESH_SIZE = 0,
#endif
EMUL_ACTIONLIST_SIZE = 207 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE,
EMUL_ACTIONLIST_SIZE = 211 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE,
MENU_ACTIONLIST_SIZE = 18
;

View File

@ -22,7 +22,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paddles::Paddles(Jack jack, const Event& event, const System& system,
bool swappaddle, bool swapaxis, bool swapdir)
bool swappaddle, bool swapaxis, bool swapdir, bool altmap)
: Controller(jack, event, system, Controller::Type::Paddles)
{
// We must start with minimum resistance; see commit
@ -47,31 +47,57 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
// Consider whether this is the left or right port
if(myJack == Jack::Left)
{
// First paddle is 0, second is 1
myP0AxisValue = Event::PaddleZeroAnalog;
myP1AxisValue = Event::PaddleOneAnalog;
myP0FireEvent = Event::PaddleZeroFire;
myP1FireEvent = Event::PaddleOneFire;
if(!altmap)
{
// First paddle is 0, second is 1
myP0AxisValue = Event::PaddleZeroAnalog;
myP1AxisValue = Event::PaddleOneAnalog;
myP0FireEvent = Event::PaddleZeroFire;
myP1FireEvent = Event::PaddleOneFire;
// These can be affected by changes in axis orientation
myP0DecEvent = Event::PaddleZeroDecrease;
myP0IncEvent = Event::PaddleZeroIncrease;
myP1DecEvent = Event::PaddleOneDecrease;
myP1IncEvent = Event::PaddleOneIncrease;
// These can be affected by changes in axis orientation
myP0DecEvent = Event::PaddleZeroDecrease;
myP0IncEvent = Event::PaddleZeroIncrease;
myP1DecEvent = Event::PaddleOneDecrease;
myP1IncEvent = Event::PaddleOneIncrease;
}
else
{
// First paddle is 4, second is 5 (fire buttons only)
myP0FireEvent = Event::PaddleFourFire;
myP1FireEvent = Event::PaddleFiveFire;
myP0AxisValue = myP1AxisValue =
myP0DecEvent = myP0IncEvent =
myP1DecEvent = myP1IncEvent = Event::NoType;
}
}
else // Jack is right port
{
// First paddle is 2, second is 3
myP0AxisValue = Event::PaddleTwoAnalog;
myP1AxisValue = Event::PaddleThreeAnalog;
myP0FireEvent = Event::PaddleTwoFire;
myP1FireEvent = Event::PaddleThreeFire;
if(!altmap)
{
// First paddle is 2, second is 3
myP0AxisValue = Event::PaddleTwoAnalog;
myP1AxisValue = Event::PaddleThreeAnalog;
myP0FireEvent = Event::PaddleTwoFire;
myP1FireEvent = Event::PaddleThreeFire;
// These can be affected by changes in axis orientation
myP0DecEvent = Event::PaddleTwoDecrease;
myP0IncEvent = Event::PaddleTwoIncrease;
myP1DecEvent = Event::PaddleThreeDecrease;
myP1IncEvent = Event::PaddleThreeIncrease;
// These can be affected by changes in axis orientation
myP0DecEvent = Event::PaddleTwoDecrease;
myP0IncEvent = Event::PaddleTwoIncrease;
myP1DecEvent = Event::PaddleThreeDecrease;
myP1IncEvent = Event::PaddleThreeIncrease;
}
else
{
// First paddle is 6, second is 7 (fire buttons only)
myP0FireEvent = Event::PaddleSixFire;
myP1FireEvent = Event::PaddleSevenFire;
myP0AxisValue = myP1AxisValue =
myP0DecEvent = myP0IncEvent =
myP1DecEvent = myP1IncEvent = Event::NoType;
}
}
// Some games swap the paddles

View File

@ -44,7 +44,7 @@ class Paddles : public Controller
resistance to decrease instead of increase)
*/
Paddles(Jack jack, const Event& event, const System& system,
bool swappaddle, bool swapaxis, bool swapdir);
bool swappaddle, bool swapaxis, bool swapdir, bool altmap = false);
~Paddles() override = default;
public:

View File

@ -82,7 +82,8 @@ unique_ptr<Controller> QuadTari::addController(const Controller::Type type, bool
// Check if we should swap the paddles plugged into a jack
bool swapPaddles = myProperties.get(PropType::Controller_SwapPaddles) == "YES";
return make_unique<Paddles>(myJack, myEvent, mySystem, swapPaddles, false, false);
return make_unique<Paddles>(myJack, myEvent, mySystem, swapPaddles,
false, false, second);
}
case Controller::Type::Driving:
return make_unique<Driving>(myJack, myEvent, mySystem, second);

View File

@ -24,6 +24,13 @@ class Event;
/**
The QuadTari controller.
Supported controllers:
- Joystick
- Driving
- Paddles (buttons only)
- AtariVox
- SaveKey
@author Thomas Jentzsch
*/
class QuadTari : public Controller