code cleanup

added Light Gun to docs
This commit is contained in:
thrust26 2019-12-30 23:00:49 +01:00
parent 86e01bc8b9
commit 8bf1f0c404
3 changed files with 28 additions and 37 deletions

View File

@ -275,7 +275,7 @@
<li>Emulates <a href="http://en.wikipedia.org/wiki/CompuMate">Spectravideo CompuMate</a> system using your computer's keyboard,
including mapping of CompuMate 'Backspace', 'Space' and 'Enter' functionality to
to the actual keys on your keyboard</li>
<li>Emulates the Mindlink Controller using your computer's mouse</li>
<li>Emulates the Mindlink Controller and the Light Gun using your computer's mouse</li>
<li>Supports autodetection for most common controller types</li>
<li>Support for real Atari 2600 controllers using the
<a href="http://www.grandideastudio.com/portfolio/stelladaptor-2600">Stelladaptor</a> and
@ -1784,6 +1784,14 @@
<td> &#x2715;</td>
<td> &#x2715;</td>
</tr>
<tr>
<th> Light Gun</th>
<td> &#x2715;</td>
<td> &#x2715;</td>
<td> &#x2713;</td>
<td> &#x2715;</td>
<td> &#x2715;</td>
</tr>
<tr>
<th> Mindlink</th>
<td> &#x2715;</td>
@ -3817,6 +3825,7 @@ Ms Pac-Man (Stella extended codes):
<tr><td>SaveKey</td><td>A 32K EEPROM for saving high scores, etc. (the EEPROM portion of an AtariVox).</td></tr>
<tr><td>Genesis </td><td>Sega Genesis controller, which can be used similar to a BoosterGrip, giving an extra button.</td></tr>
<tr><td>CompuMate &#185</td><td>Spectravideo CompuMate (if either left or right is set, CompuMate is used for both).</td></tr>
<tr><td>Lightgun</td><td>Atari XG-1 compatible Light Gun</td></tr>
<tr><td>Mindlink &#185</td><td>Mindlink controller.</td></tr>
</table></td>
</tr>

View File

@ -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));
}

View File

@ -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;