diff --git a/src/emucore/Booster.cxx b/src/emucore/Booster.cxx index 3e931547c..26b6e276a 100644 --- a/src/emucore/Booster.cxx +++ b/src/emucore/Booster.cxx @@ -99,8 +99,8 @@ void BoosterGrip::update() { // The following code was taken from z26 #define MJ_Threshold 2 - int mousex = myEvent.get(Event::MouseAxisXValue), - mousey = myEvent.get(Event::MouseAxisYValue); + int mousex = myEvent.get(Event::MouseAxisXMove), + mousey = myEvent.get(Event::MouseAxisYMove); if(mousex || mousey) { if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) diff --git a/src/emucore/Driving.cxx b/src/emucore/Driving.cxx index 5b634b15d..bb24b9cb8 100644 --- a/src/emucore/Driving.cxx +++ b/src/emucore/Driving.cxx @@ -62,7 +62,7 @@ void Driving::update() // Mouse motion and button events if(myControlID > -1) { - int m_axis = myEvent.get(Event::MouseAxisXValue); + int m_axis = myEvent.get(Event::MouseAxisXMove); if(m_axis < -2) --myCounter; else if(m_axis > 2) ++myCounter; if(myEvent.get(Event::MouseButtonLeftValue) || @@ -75,7 +75,7 @@ void Driving::update() // mapped to a separate driving controller if(myControlIDX > -1) { - int m_axis = myEvent.get(Event::MouseAxisXValue); + int m_axis = myEvent.get(Event::MouseAxisXMove); if(m_axis < -2) --myCounter; else if(m_axis > 2) ++myCounter; if(myEvent.get(Event::MouseButtonLeftValue)) @@ -83,7 +83,7 @@ void Driving::update() } if(myControlIDY > -1) { - int m_axis = myEvent.get(Event::MouseAxisYValue); + int m_axis = myEvent.get(Event::MouseAxisYMove); if(m_axis < -2) --myCounter; else if(m_axis > 2) ++myCounter; if(myEvent.get(Event::MouseButtonRightValue)) diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index 41cbf7997..481689fab 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -68,7 +68,7 @@ class Event Combo1, Combo2, Combo3, Combo4, Combo5, Combo6, Combo7, Combo8, Combo9, Combo10, Combo11, Combo12, Combo13, Combo14, Combo15, Combo16, - MouseAxisXValue, MouseAxisYValue, + MouseAxisXMove, MouseAxisYMove, MouseButtonLeftValue, MouseButtonRightValue, ChangeState, LoadState, SaveState, TakeSnapshot, Quit, @@ -121,7 +121,7 @@ class Event CompuMateSlash, ToggleInter, - LightgunZeroFire, LightgunZeroPos, LightgunOneFire, LightgunOnePos, + MouseAxisXValue, MouseAxisYValue, LastType }; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 9da143eb0..3e26c3692 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -95,7 +95,6 @@ void EventHandler::initialize() Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff")); Paddles::setDigitalSensitivity(myOSystem.settings().getInt("dsense")); Paddles::setMouseSensitivity(myOSystem.settings().getInt("msense")); - Lightgun::setMouseSensitivity(myOSystem.settings().getInt("msense")); PointingDevice::setSensitivity(myOSystem.settings().getInt("tsense")); #ifdef GUI_SUPPORT @@ -249,8 +248,8 @@ void EventHandler::poll(uInt64 time) // Turn off all mouse-related items; if they haven't been taken care of // in the previous ::update() methods, they're now invalid - myEvent.set(Event::MouseAxisXValue, 0); - myEvent.set(Event::MouseAxisYValue, 0); + myEvent.set(Event::MouseAxisXMove, 0); + myEvent.set(Event::MouseAxisYMove, 0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -271,8 +270,10 @@ void EventHandler::handleMouseMotionEvent(int x, int y, int xrel, int yrel) { if(!mySkipMouseMotion) { - myEvent.set(Event::MouseAxisXValue, xrel); - myEvent.set(Event::MouseAxisYValue, yrel); + myEvent.set(Event::MouseAxisXValue, x); // required for Lightgun controller + myEvent.set(Event::MouseAxisYValue, y); // required for Lightgun controller + myEvent.set(Event::MouseAxisXMove, xrel); + myEvent.set(Event::MouseAxisYMove, yrel); } mySkipMouseMotion = false; } @@ -1954,7 +1955,7 @@ const Event::EventSet EventHandler::MiscEvents = { Event::Quit, Event::ReloadConsole, Event::Fry, Event::StartPauseMode, Event::TogglePauseMode, Event::OptionsMenuMode, Event::CmdMenuMode, Event::ExitMode, Event::TakeSnapshot, Event::ToggleContSnapshots, Event::ToggleContSnapshotsFrame, - // Event::MouseAxisXValue, Event::MouseAxisYValue, + // Event::MouseAxisXMove, Event::MouseAxisYMove, // Event::MouseButtonLeftValue, Event::MouseButtonRightValue, Event::HandleMouseControl, Event::ToggleGrabMouse, Event::ToggleSAPortOrder, diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index e07c8ad87..5ed99d6fb 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -841,13 +841,17 @@ void FrameBuffer::setCursorState() bool analog = myOSystem.hasConsole() ? (myOSystem.console().leftController().isAnalog() || myOSystem.console().rightController().isAnalog()) : false; - bool lightgun = emulation && myOSystem.hasConsole() ? + bool usesLightgun = emulation && myOSystem.hasConsole() ? myOSystem.console().leftController().type() == Controller::Type::Lightgun || myOSystem.console().rightController().type() == Controller::Type::Lightgun : false; bool alwaysUseMouse = BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse")); // Show/hide cursor in UI/emulation mode based on 'cursor' setting int cursor = myOSystem.settings().getInt("cursor"); + // always enable cursor in lightgun games + if (usesLightgun) + cursor |= 1; + switch(cursor) { case 0: diff --git a/src/emucore/Genesis.cxx b/src/emucore/Genesis.cxx index 30e4055db..8623b0ea6 100644 --- a/src/emucore/Genesis.cxx +++ b/src/emucore/Genesis.cxx @@ -67,8 +67,8 @@ void Genesis::update() { // The following code was taken from z26 #define MJ_Threshold 2 - int mousex = myEvent.get(Event::MouseAxisXValue), - mousey = myEvent.get(Event::MouseAxisYValue); + int mousex = myEvent.get(Event::MouseAxisXMove), + mousey = myEvent.get(Event::MouseAxisYMove); if(mousex || mousey) { if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) diff --git a/src/emucore/Joystick.cxx b/src/emucore/Joystick.cxx index 0a988eb73..4b08e843d 100644 --- a/src/emucore/Joystick.cxx +++ b/src/emucore/Joystick.cxx @@ -81,8 +81,8 @@ void Joystick::update() { // The following code was taken from z26 #define MJ_Threshold 2 - int mousex = myEvent.get(Event::MouseAxisXValue), - mousey = myEvent.get(Event::MouseAxisYValue); + int mousex = myEvent.get(Event::MouseAxisXMove), + mousey = myEvent.get(Event::MouseAxisYMove); if(mousex || mousey) { if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) diff --git a/src/emucore/Lightgun.cxx b/src/emucore/Lightgun.cxx index 43c582998..2b116a0ac 100644 --- a/src/emucore/Lightgun.cxx +++ b/src/emucore/Lightgun.cxx @@ -15,29 +15,55 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ + +#include "TIA.hxx" +#include "System.hxx" + #include "Lightgun.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Lightgun::Lightgun(Jack jack, const Event& event, const System& system) : Controller(jack, event, system, Controller::Type::Lightgun) { - if (myJack == Jack::Left) - { - myFireEvent = Event::JoystickZeroFire; - //myFireEvent = Event::LightgunZeroFire; - myPosValue = Event::LightgunZeroPos; - } - else - { - myFireEvent = Event::JoystickOneFire; - //myFireEvent = Event::LightgunOneFire; - myPosValue = Event::LightgunOnePos; - } +} - // Digital pins 1, 2 and 6 are not connected (TOOD: check) - //setPin(DigitalPin::One, true); - //setPin(DigitalPin::Two, true); - //setPin(DigitalPin::Six, true); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Lightgun::read(DigitalPin pin) +{ + + // We need to override the Controller::read() method, since the lightgun + // checks this multiple times per frame + // (we can't just read 60 times per second in the ::update() method) + switch (pin) + { + // Pin 6: INPT4/5 + case DigitalPin::Six: + { + // TODO: scale correctly, current code assumes 2x zoom and no vertical scaling + Int32 xpos = myMouseX / 4; + Int32 ypos = myMouseY / 2; + uInt32 ux; + uInt32 uy; + + mySystem.tia().electronBeamPos(ux, uy); + Int32 x = mySystem.tia().clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS; + + if (x < 0) + x += TIAConstants::H_CLOCKS; + Int32 y = uy + Y_OFS; + + //cerr << "mouse:" << xpos << " " << ypos << endl; + //cerr << " beam:" << x << " " << y << endl; + + + bool enable = !((x - xpos) >= 0 && (x - xpos) < 15 && (y - ypos) >= 0); + + return enable; + } + + default: + return Controller::read(pin); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -47,26 +73,12 @@ void Lightgun::update() // | Fire button | SWCHA bit 4 | SWCHA bit 0 | DP:1 // | Detect light | INPT4 bit 7 | INPT5 bit 7 | DP:6 - myCharge = BSPF::clamp(myEvent.get(Event::MouseAxisXValue) * MOUSE_SENSITIVITY, TRIGMIN, TRIGMAX); + Int32 xVal = myEvent.get(Event::MouseAxisXValue); + Int32 yVal = myEvent.get(Event::MouseAxisYValue); - if (myCharge != myLastCharge) - { - setPin(DigitalPin::Six, Int32(MAX_RESISTANCE * (myCharge / double(TRIGMAX)))); - myLastCharge = myCharge; - } + myMouseX = xVal ? xVal : myMouseX; + myMouseY = yVal ? yVal : myMouseY; - setPin(DigitalPin::One, myEvent.get(Event::MouseButtonLeftValue) ? false : true); + setPin(DigitalPin::One, myEvent.get(Event::MouseButtonLeftValue) || myEvent.get(Event::MouseButtonRightValue)); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Lightgun::setMouseSensitivity(int sensitivity) -{ - MOUSE_SENSITIVITY = BSPF::clamp(sensitivity, 1, MAX_MOUSE_SENSE); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Lightgun::MOUSE_SENSITIVITY = -1; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//const Controller::DigitalPin Lightgun::ourButtonPin = DigitalPin::One; // TODO - diff --git a/src/emucore/Lightgun.hxx b/src/emucore/Lightgun.hxx index 850c3deba..34de0f7a6 100644 --- a/src/emucore/Lightgun.hxx +++ b/src/emucore/Lightgun.hxx @@ -23,7 +23,7 @@ #include "Event.hxx" /** - This class handles the lighgun controller + This class handles the lightgun controller @author Thomas Jentzsch */ @@ -42,7 +42,15 @@ public: virtual ~Lightgun() = default; public: - static constexpr int MAX_MOUSE_SENSE = 20; + using Controller::read; + + /** + Read the value of the specified digital pin for this controller. + + @param pin The pin of the controller jack to read + @return The state of the pin + */ + bool read(DigitalPin pin) override; /** Update the entire digital and analog pin state according to the @@ -60,26 +68,11 @@ public: */ bool isAnalog() const override { return true; } - /** - Sets the sensitivity for analog emulation of lightgun 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: - // Pre-compute the events we care about based on given port - // This will eliminate test for left or right port in update() - Event::Type myPosValue, myFireEvent; + Int32 myMouseX{0}, myMouseY{0}; - int myCharge, myLastCharge; - - static constexpr int TRIGMIN = 1; - static constexpr int TRIGMAX = 4096; - - static int MOUSE_SENSITIVITY; + static constexpr Int32 X_OFS = -21; + static constexpr Int32 Y_OFS = 10; // Lookup table for associating paddle buttons with controller pins static const Controller::DigitalPin ourButtonPin; diff --git a/src/emucore/MindLink.cxx b/src/emucore/MindLink.cxx index bca8c92f1..50d43785a 100644 --- a/src/emucore/MindLink.cxx +++ b/src/emucore/MindLink.cxx @@ -40,7 +40,7 @@ void MindLink::update() return; myMindlinkPos = (myMindlinkPos & 0x3fffffff) + - (myEvent.get(Event::MouseAxisXValue) << 3); + (myEvent.get(Event::MouseAxisXMove) << 3); if(myMindlinkPos < 0x2800) myMindlinkPos = 0x2800; if(myMindlinkPos >= 0x3800) diff --git a/src/emucore/Paddles.cxx b/src/emucore/Paddles.cxx index 601850018..45e1398b6 100644 --- a/src/emucore/Paddles.cxx +++ b/src/emucore/Paddles.cxx @@ -162,13 +162,13 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system, abs(MOUSE_SENSITIVITY); if(!swapaxis) { - myAxisMouseMotion = Event::MouseAxisXValue; + myAxisMouseMotion = Event::MouseAxisXMove; myAxisDigitalZero = 0; myAxisDigitalOne = 1; } else { - myAxisMouseMotion = Event::MouseAxisYValue; + myAxisMouseMotion = Event::MouseAxisYMove; myAxisDigitalZero = 1; myAxisDigitalOne = 0; } @@ -277,7 +277,7 @@ void Paddles::update() if(myMPaddleIDX > -1) { myCharge[myMPaddleIDX] = BSPF::clamp(myCharge[myMPaddleIDX] - - (myEvent.get(Event::MouseAxisXValue) * MOUSE_SENSITIVITY), + (myEvent.get(Event::MouseAxisXMove) * MOUSE_SENSITIVITY), TRIGMIN, TRIGRANGE); if(myEvent.get(Event::MouseButtonLeftValue)) setPin(ourButtonPin[myMPaddleIDX], false); @@ -285,7 +285,7 @@ void Paddles::update() if(myMPaddleIDY > -1) { myCharge[myMPaddleIDY] = BSPF::clamp(myCharge[myMPaddleIDY] - - (myEvent.get(Event::MouseAxisYValue) * MOUSE_SENSITIVITY), + (myEvent.get(Event::MouseAxisYMove) * MOUSE_SENSITIVITY), TRIGMIN, TRIGRANGE); if(myEvent.get(Event::MouseButtonRightValue)) setPin(ourButtonPin[myMPaddleIDY], false); diff --git a/src/emucore/PointingDevice.cxx b/src/emucore/PointingDevice.cxx index 507998730..e23a4399e 100644 --- a/src/emucore/PointingDevice.cxx +++ b/src/emucore/PointingDevice.cxx @@ -79,11 +79,11 @@ void PointingDevice::update() return; // Update horizontal direction - updateDirection( myEvent.get(Event::MouseAxisXValue), myHCounterRemainder, + updateDirection( myEvent.get(Event::MouseAxisXMove), myHCounterRemainder, myTrackBallLeft, myTrackBallLinesH, myScanCountH, myFirstScanOffsetH); // Update vertical direction - updateDirection(-myEvent.get(Event::MouseAxisYValue), myVCounterRemainder, + updateDirection(-myEvent.get(Event::MouseAxisYMove), myVCounterRemainder, myTrackBallDown, myTrackBallLinesV, myScanCountV, myFirstScanOffsetV); // Get mouse button state diff --git a/src/emucore/module.mk b/src/emucore/module.mk index 7fd311126..e02fcdc2d 100644 --- a/src/emucore/module.mk +++ b/src/emucore/module.mk @@ -66,6 +66,7 @@ MODULE_OBJS := \ src/emucore/Joystick.o \ src/emucore/Keyboard.o \ src/emucore/KidVid.o \ + src/emucore/Lightgun.o \ src/emucore/MindLink.o \ src/emucore/M6502.o \ src/emucore/M6532.o \ diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index bbbb4e122..7a30b20a3 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -21,7 +21,6 @@ #include "EventHandler.hxx" #include "Joystick.hxx" #include "Paddles.hxx" -#include "Lightgun.hxx" #include "PointingDevice.hxx" #include "SaveKey.hxx" #include "AtariVox.hxx" @@ -350,8 +349,6 @@ void InputDialog::saveConfig() sensitivity = myMPaddleSpeed->getValue(); instance().settings().setValue("msense", sensitivity); Paddles::setMouseSensitivity(sensitivity); - Lightgun::setMouseSensitivity(sensitivity); - // Trackball speed sensitivity = myTrackBallSpeed->getValue();