From 8bf1f0c4042b806f30121cdc964ed1e2419cb305 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 30 Dec 2019 23:00:49 +0100 Subject: [PATCH] code cleanup added Light Gun to docs --- docs/index.html | 11 ++++++++++- src/emucore/Lightgun.cxx | 41 ++++++++++++++++++---------------------- src/emucore/Lightgun.hxx | 13 ------------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/docs/index.html b/docs/index.html index 5ed085294..fd07a52f6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -275,7 +275,7 @@
  • Emulates Spectravideo CompuMate system using your computer's keyboard, including mapping of CompuMate 'Backspace', 'Space' and 'Enter' functionality to to the actual keys on your keyboard
  • -
  • Emulates the Mindlink Controller using your computer's mouse
  • +
  • Emulates the Mindlink Controller and the Light Gun using your computer's mouse
  • Supports autodetection for most common controller types
  • Support for real Atari 2600 controllers using the Stelladaptor and @@ -1784,6 +1784,14 @@ ✕ ✕ + + Light Gun + ✕ + ✕ + ✓ + ✕ + ✕ + Mindlink ✕ @@ -3817,6 +3825,7 @@ Ms Pac-Man (Stella extended codes): SaveKeyA 32K EEPROM for saving high scores, etc. (the EEPROM portion of an AtariVox). Genesis Sega Genesis controller, which can be used similar to a BoosterGrip, giving an extra button. CompuMate ¹Spectravideo CompuMate (if either left or right is set, CompuMate is used for both). + LightgunAtari XG-1 compatible Light Gun Mindlink ¹Mindlink controller. diff --git a/src/emucore/Lightgun.cxx b/src/emucore/Lightgun.cxx index 8f23f34d3..41fc5a882 100644 --- a/src/emucore/Lightgun.cxx +++ b/src/emucore/Lightgun.cxx @@ -16,12 +16,16 @@ //============================================================================ +#include "Event.hxx" #include "TIA.hxx" -#include "System.hxx" #include "FrameBuffer.hxx" #include "Lightgun.hxx" +// | | Left port | Right port | +// | Fire button | SWCHA bit 4 | SWCHA bit 0 | DP:1 +// | Detect light | INPT4 bit 7 | INPT5 bit 7 | DP:6 + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Lightgun::Lightgun(Jack jack, const Event& event, const System& system, const FrameBuffer& frameBuffer) : Controller(jack, event, system, Controller::Type::Lightgun), @@ -32,31 +36,30 @@ Lightgun::Lightgun(Jack jack, const Event& event, const System& system, const Fr // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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: + case DigitalPin::Six: // INPT4/5 { const Common::Rect& rect = myFrameBuffer.imageRect(); // scale mouse coordinates into TIA coordinates - Int32 xpos = (myMouseX - rect.x()) * TIAConstants::H_PIXEL / rect.w(); - Int32 ypos = (myMouseY - rect.y()) * 210 / rect.h(); // TODO: replace "magic number" + Int32 xMouse = (myEvent.get(Event::MouseAxisXValue) - rect.x()) + * TIAConstants::H_PIXEL / rect.w(); + Int32 yMouse = (myEvent.get(Event::MouseAxisYValue) - rect.y()) + * 210 / rect.h(); // TODO: replace "magic number" // get adjusted TIA coordinates - Int32 x = mySystem.tia().clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS; - Int32 y = mySystem.tia().scanlines() - mySystem.tia().startLine() + Y_OFS; + Int32 xTia = mySystem.tia().clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS; + Int32 yTia = mySystem.tia().scanlines() - mySystem.tia().startLine() + Y_OFS; - if (x < 0) - x += TIAConstants::H_CLOCKS; + if (xTia < 0) + xTia += TIAConstants::H_CLOCKS; - bool enable = !((x - xpos) >= 0 && (x - xpos) < 15 && (y - ypos) >= 0); + bool enable = !((xTia - xMouse) >= 0 && (xTia - xMouse) < 15 && (yTia - yMouse) >= 0); return enable; } - default: return Controller::read(pin); } @@ -65,16 +68,8 @@ bool Lightgun::read(DigitalPin pin) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Lightgun::update() { - // | | Left port | Right port | - // | Fire button | SWCHA bit 4 | SWCHA bit 0 | DP:1 - // | Detect light | INPT4 bit 7 | INPT5 bit 7 | DP:6 - - Int32 xVal = myEvent.get(Event::MouseAxisXValue); - Int32 yVal = myEvent.get(Event::MouseAxisYValue); - - myMouseX = xVal ? xVal : myMouseX; - myMouseY = yVal ? yVal : myMouseY; - - setPin(DigitalPin::One, myEvent.get(Event::MouseButtonLeftValue) || myEvent.get(Event::MouseButtonRightValue)); + // we allow left and right mouse buttons for fire button + setPin(DigitalPin::One, myEvent.get(Event::MouseButtonLeftValue) + || myEvent.get(Event::MouseButtonRightValue)); } diff --git a/src/emucore/Lightgun.hxx b/src/emucore/Lightgun.hxx index 739dcd22a..928f705b0 100644 --- a/src/emucore/Lightgun.hxx +++ b/src/emucore/Lightgun.hxx @@ -18,10 +18,6 @@ #ifndef LIGHTGUN_HXX #define LIGHTGUN_HXX -#include "bspf.hxx" -#include "Control.hxx" -#include "Event.hxx" - /** This class handles the lightgun controller @@ -63,21 +59,12 @@ public: */ string name() const override { return "Lightgun"; } - /** - Answers whether the controller is intrinsically an analog controller. - */ - bool isAnalog() const override { return true; } - private: const FrameBuffer& myFrameBuffer; - Int32 myMouseX{0}, myMouseY{0}; static constexpr Int32 X_OFS = -21; static constexpr Int32 Y_OFS = 5; - // Lookup table for associating paddle buttons with controller pins - static const Controller::DigitalPin ourButtonPin; - private: // Following constructors and assignment operators not supported Lightgun() = delete;