From 2b3bb70052349452f6bc4b2b37b5be457542342d Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Thu, 9 Sep 2021 10:21:26 +0200 Subject: [PATCH] fixed MindLink controller (resolves #821) --- Changes.txt | 2 ++ src/common/PJoystickHandler.cxx | 2 ++ src/emucore/EventHandler.cxx | 2 ++ src/emucore/MindLink.cxx | 32 +++++++++++++++++--------------- src/emucore/MindLink.hxx | 23 +++++++++++++++++++++-- src/gui/InputDialog.cxx | 2 ++ 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Changes.txt b/Changes.txt index 75d014b70..327c2a9e5 100644 --- a/Changes.txt +++ b/Changes.txt @@ -21,6 +21,8 @@ * Added web links for many games + * Fixe MindLink controller + * Debugger: enhanced prompt's auto complete and history * Debugger: added optional logging of breaks and traps diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index de3bf4eac..422eb1717 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -20,6 +20,7 @@ #include "Console.hxx" #include "Joystick.hxx" #include "Paddles.hxx" +#include "MindLink.hxx" #include "PointingDevice.hxx" #include "Driving.hxx" #include "Settings.hxx" @@ -1074,6 +1075,7 @@ void PhysicalJoystickHandler::changeMousePaddleSensitivity(int direction) myOSystem.settings().setValue("msense", sense); Paddles::setMouseSensitivity(sense); + MindLink::setMouseSensitivity(sense); ostringstream ss; ss << sense * 10 << "%"; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index da2714945..e66f7b5e1 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -28,6 +28,7 @@ #include "OSystem.hxx" #include "Joystick.hxx" #include "Paddles.hxx" +#include "MindLink.hxx" #include "Lightgun.hxx" #include "PointingDevice.hxx" #include "Driving.hxx" @@ -106,6 +107,7 @@ void EventHandler::initialize() Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff")); Paddles::setDigitalSensitivity(myOSystem.settings().getInt("dsense")); Paddles::setMouseSensitivity(myOSystem.settings().getInt("msense")); + MindLink::setMouseSensitivity(myOSystem.settings().getInt("msense")); PointingDevice::setSensitivity(myOSystem.settings().getInt("tsense")); Driving::setSensitivity(myOSystem.settings().getInt("dcsense")); Controller::setAutoFireRate(myOSystem.settings().getInt("autofirerate")); diff --git a/src/emucore/MindLink.cxx b/src/emucore/MindLink.cxx index 94b39c1b3..007d6a2bd 100644 --- a/src/emucore/MindLink.cxx +++ b/src/emucore/MindLink.cxx @@ -22,10 +22,6 @@ MindLink::MindLink(Jack jack, const Event& event, const System& system) : Controller(jack, event, system, Controller::Type::MindLink) { - setPin(DigitalPin::One, true); - setPin(DigitalPin::Two, true); - setPin(DigitalPin::Three, true); - setPin(DigitalPin::Four, true); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -39,19 +35,16 @@ void MindLink::update() if(!myMouseEnabled) return; - myMindlinkPos = (myMindlinkPos & 0x3fffffff) + - (myEvent.get(Event::MouseAxisXMove) << 3); - if(myMindlinkPos < 0x2800) - myMindlinkPos = 0x2800; - if(myMindlinkPos >= 0x3800) - myMindlinkPos = 0x3800; - - myMindlinkShift = 1; - nextMindlinkBit(); + myMindlinkPos = BSPF::clamp((myMindlinkPos & ~CALIBRATE_FLAG) + + myEvent.get(Event::MouseAxisXMove) * MOUSE_SENSITIVITY, + MIN_POS, MAX_POS); if(myEvent.get(Event::MouseButtonLeftValue) || myEvent.get(Event::MouseButtonRightValue)) - myMindlinkPos |= 0x4000; // this bit starts a game + myMindlinkPos = CALIBRATE_FLAG; // flag starts game & calibates + + myMindlinkShift = 1; // start transfer with least significant bit + nextMindlinkBit(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -63,7 +56,7 @@ void MindLink::nextMindlinkBit() setPin(DigitalPin::Four, false); if(myMindlinkPos & myMindlinkShift) setPin(DigitalPin::Four, true); - myMindlinkShift <<= 1; + myMindlinkShift <<= 1; // next bit } } @@ -79,3 +72,12 @@ bool MindLink::setMouseControl( (xid != -1 || yid != -1); return true; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void MindLink::setMouseSensitivity(int sensitivity) +{ + MOUSE_SENSITIVITY = BSPF::clamp(sensitivity, MIN_MOUSE_SENSE, MAX_MOUSE_SENSE); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int MindLink::MOUSE_SENSITIVITY = -1; diff --git a/src/emucore/MindLink.hxx b/src/emucore/MindLink.hxx index e4bd2b23f..eaef64f57 100644 --- a/src/emucore/MindLink.hxx +++ b/src/emucore/MindLink.hxx @@ -35,7 +35,7 @@ the Stella core actually stores this information in boolean arrays addressable by DigitalPin number. - @author Stephen Anthony & z26 team + @author Stephen Anthony, Thomas Jentzsch & z26 team */ class MindLink : public Controller { @@ -101,13 +101,32 @@ class MindLink : public Controller bool setMouseControl( Controller::Type xtype, int xid, Controller::Type ytype, int yid) override; + /** + Sets the sensitivity for analog emulation of MindLink movement + using a mouse. + + @param sensitivity Value from 1 to MAX_MOUSE_SENSE, with larger + values causing more movement + */ + static void setMouseSensitivity(int sensitivity); + private: void nextMindlinkBit(); + // Range of valid values + static constexpr int MIN_POS = 0x2700; + static constexpr int MAX_POS = 0x3e00; + static constexpr int CALIBRATE_FLAG = 0x8000; // this causes a left side calibration + + static constexpr int MIN_MOUSE_SENSE = 1; + static constexpr int MAX_MOUSE_SENSE = 20; + + static int MOUSE_SENSITIVITY; + private: // Position value in Mindlink controller // Gets transferred bitwise (16 bits) - int myMindlinkPos{0x2800}; + int myMindlinkPos{MIN_POS}; // Which bit to transfer next int myMindlinkShift{1}; diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 25adb16ab..2c5eca3e7 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -21,6 +21,7 @@ #include "EventHandler.hxx" #include "Joystick.hxx" #include "Paddles.hxx" +#include "MindLink.hxx" #include "PointingDevice.hxx" #include "Driving.hxx" #include "SaveKey.hxx" @@ -487,6 +488,7 @@ void InputDialog::saveConfig() sensitivity = myMPaddleSpeed->getValue(); settings.setValue("msense", sensitivity); Paddles::setMouseSensitivity(sensitivity); + MindLink::setMouseSensitivity(sensitivity); // Trackball speed sensitivity = myTrackBallSpeed->getValue();