get lightgun working preliminary

This commit is contained in:
thrust26 2019-12-30 17:27:28 +01:00
parent 24faa4955c
commit 1295bd5cf6
14 changed files with 91 additions and 83 deletions

View File

@ -99,8 +99,8 @@ void BoosterGrip::update()
{ {
// The following code was taken from z26 // The following code was taken from z26
#define MJ_Threshold 2 #define MJ_Threshold 2
int mousex = myEvent.get(Event::MouseAxisXValue), int mousex = myEvent.get(Event::MouseAxisXMove),
mousey = myEvent.get(Event::MouseAxisYValue); mousey = myEvent.get(Event::MouseAxisYMove);
if(mousex || mousey) if(mousex || mousey)
{ {
if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold))

View File

@ -62,7 +62,7 @@ void Driving::update()
// Mouse motion and button events // Mouse motion and button events
if(myControlID > -1) if(myControlID > -1)
{ {
int m_axis = myEvent.get(Event::MouseAxisXValue); int m_axis = myEvent.get(Event::MouseAxisXMove);
if(m_axis < -2) --myCounter; if(m_axis < -2) --myCounter;
else if(m_axis > 2) ++myCounter; else if(m_axis > 2) ++myCounter;
if(myEvent.get(Event::MouseButtonLeftValue) || if(myEvent.get(Event::MouseButtonLeftValue) ||
@ -75,7 +75,7 @@ void Driving::update()
// mapped to a separate driving controller // mapped to a separate driving controller
if(myControlIDX > -1) if(myControlIDX > -1)
{ {
int m_axis = myEvent.get(Event::MouseAxisXValue); int m_axis = myEvent.get(Event::MouseAxisXMove);
if(m_axis < -2) --myCounter; if(m_axis < -2) --myCounter;
else if(m_axis > 2) ++myCounter; else if(m_axis > 2) ++myCounter;
if(myEvent.get(Event::MouseButtonLeftValue)) if(myEvent.get(Event::MouseButtonLeftValue))
@ -83,7 +83,7 @@ void Driving::update()
} }
if(myControlIDY > -1) if(myControlIDY > -1)
{ {
int m_axis = myEvent.get(Event::MouseAxisYValue); int m_axis = myEvent.get(Event::MouseAxisYMove);
if(m_axis < -2) --myCounter; if(m_axis < -2) --myCounter;
else if(m_axis > 2) ++myCounter; else if(m_axis > 2) ++myCounter;
if(myEvent.get(Event::MouseButtonRightValue)) if(myEvent.get(Event::MouseButtonRightValue))

View File

@ -68,7 +68,7 @@ class Event
Combo1, Combo2, Combo3, Combo4, Combo5, Combo6, Combo7, Combo8, Combo1, Combo2, Combo3, Combo4, Combo5, Combo6, Combo7, Combo8,
Combo9, Combo10, Combo11, Combo12, Combo13, Combo14, Combo15, Combo16, Combo9, Combo10, Combo11, Combo12, Combo13, Combo14, Combo15, Combo16,
MouseAxisXValue, MouseAxisYValue, MouseAxisXMove, MouseAxisYMove,
MouseButtonLeftValue, MouseButtonRightValue, MouseButtonLeftValue, MouseButtonRightValue,
ChangeState, LoadState, SaveState, TakeSnapshot, Quit, ChangeState, LoadState, SaveState, TakeSnapshot, Quit,
@ -121,7 +121,7 @@ class Event
CompuMateSlash, CompuMateSlash,
ToggleInter, ToggleInter,
LightgunZeroFire, LightgunZeroPos, LightgunOneFire, LightgunOnePos, MouseAxisXValue, MouseAxisYValue,
LastType LastType
}; };

View File

@ -95,7 +95,6 @@ void EventHandler::initialize()
Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff")); Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff"));
Paddles::setDigitalSensitivity(myOSystem.settings().getInt("dsense")); Paddles::setDigitalSensitivity(myOSystem.settings().getInt("dsense"));
Paddles::setMouseSensitivity(myOSystem.settings().getInt("msense")); Paddles::setMouseSensitivity(myOSystem.settings().getInt("msense"));
Lightgun::setMouseSensitivity(myOSystem.settings().getInt("msense"));
PointingDevice::setSensitivity(myOSystem.settings().getInt("tsense")); PointingDevice::setSensitivity(myOSystem.settings().getInt("tsense"));
#ifdef GUI_SUPPORT #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 // Turn off all mouse-related items; if they haven't been taken care of
// in the previous ::update() methods, they're now invalid // in the previous ::update() methods, they're now invalid
myEvent.set(Event::MouseAxisXValue, 0); myEvent.set(Event::MouseAxisXMove, 0);
myEvent.set(Event::MouseAxisYValue, 0); myEvent.set(Event::MouseAxisYMove, 0);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -271,8 +270,10 @@ void EventHandler::handleMouseMotionEvent(int x, int y, int xrel, int yrel)
{ {
if(!mySkipMouseMotion) if(!mySkipMouseMotion)
{ {
myEvent.set(Event::MouseAxisXValue, xrel); myEvent.set(Event::MouseAxisXValue, x); // required for Lightgun controller
myEvent.set(Event::MouseAxisYValue, yrel); myEvent.set(Event::MouseAxisYValue, y); // required for Lightgun controller
myEvent.set(Event::MouseAxisXMove, xrel);
myEvent.set(Event::MouseAxisYMove, yrel);
} }
mySkipMouseMotion = false; mySkipMouseMotion = false;
} }
@ -1954,7 +1955,7 @@ const Event::EventSet EventHandler::MiscEvents = {
Event::Quit, Event::ReloadConsole, Event::Fry, Event::StartPauseMode, Event::Quit, Event::ReloadConsole, Event::Fry, Event::StartPauseMode,
Event::TogglePauseMode, Event::OptionsMenuMode, Event::CmdMenuMode, Event::ExitMode, Event::TogglePauseMode, Event::OptionsMenuMode, Event::CmdMenuMode, Event::ExitMode,
Event::TakeSnapshot, Event::ToggleContSnapshots, Event::ToggleContSnapshotsFrame, Event::TakeSnapshot, Event::ToggleContSnapshots, Event::ToggleContSnapshotsFrame,
// Event::MouseAxisXValue, Event::MouseAxisYValue, // Event::MouseAxisXMove, Event::MouseAxisYMove,
// Event::MouseButtonLeftValue, Event::MouseButtonRightValue, // Event::MouseButtonLeftValue, Event::MouseButtonRightValue,
Event::HandleMouseControl, Event::ToggleGrabMouse, Event::HandleMouseControl, Event::ToggleGrabMouse,
Event::ToggleSAPortOrder, Event::ToggleSAPortOrder,

View File

@ -841,13 +841,17 @@ void FrameBuffer::setCursorState()
bool analog = myOSystem.hasConsole() ? bool analog = myOSystem.hasConsole() ?
(myOSystem.console().leftController().isAnalog() || (myOSystem.console().leftController().isAnalog() ||
myOSystem.console().rightController().isAnalog()) : false; myOSystem.console().rightController().isAnalog()) : false;
bool lightgun = emulation && myOSystem.hasConsole() ? bool usesLightgun = emulation && myOSystem.hasConsole() ?
myOSystem.console().leftController().type() == Controller::Type::Lightgun || myOSystem.console().leftController().type() == Controller::Type::Lightgun ||
myOSystem.console().rightController().type() == Controller::Type::Lightgun : false; myOSystem.console().rightController().type() == Controller::Type::Lightgun : false;
bool alwaysUseMouse = BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse")); bool alwaysUseMouse = BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse"));
// Show/hide cursor in UI/emulation mode based on 'cursor' setting // Show/hide cursor in UI/emulation mode based on 'cursor' setting
int cursor = myOSystem.settings().getInt("cursor"); int cursor = myOSystem.settings().getInt("cursor");
// always enable cursor in lightgun games
if (usesLightgun)
cursor |= 1;
switch(cursor) switch(cursor)
{ {
case 0: case 0:

View File

@ -67,8 +67,8 @@ void Genesis::update()
{ {
// The following code was taken from z26 // The following code was taken from z26
#define MJ_Threshold 2 #define MJ_Threshold 2
int mousex = myEvent.get(Event::MouseAxisXValue), int mousex = myEvent.get(Event::MouseAxisXMove),
mousey = myEvent.get(Event::MouseAxisYValue); mousey = myEvent.get(Event::MouseAxisYMove);
if(mousex || mousey) if(mousex || mousey)
{ {
if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold))

View File

@ -81,8 +81,8 @@ void Joystick::update()
{ {
// The following code was taken from z26 // The following code was taken from z26
#define MJ_Threshold 2 #define MJ_Threshold 2
int mousex = myEvent.get(Event::MouseAxisXValue), int mousex = myEvent.get(Event::MouseAxisXMove),
mousey = myEvent.get(Event::MouseAxisYValue); mousey = myEvent.get(Event::MouseAxisYMove);
if(mousex || mousey) if(mousex || mousey)
{ {
if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold))

View File

@ -15,29 +15,55 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#include "TIA.hxx"
#include "System.hxx"
#include "Lightgun.hxx" #include "Lightgun.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Lightgun::Lightgun(Jack jack, const Event& event, const System& system) Lightgun::Lightgun(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::Type::Lightgun) : 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); bool Lightgun::read(DigitalPin pin)
//setPin(DigitalPin::Two, true); {
//setPin(DigitalPin::Six, true);
// 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 // | Fire button | SWCHA bit 4 | SWCHA bit 0 | DP:1
// | Detect light | INPT4 bit 7 | INPT5 bit 7 | DP:6 // | 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) myMouseX = xVal ? xVal : myMouseX;
{ myMouseY = yVal ? yVal : myMouseY;
setPin(DigitalPin::Six, Int32(MAX_RESISTANCE * (myCharge / double(TRIGMAX))));
myLastCharge = myCharge;
}
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

View File

@ -23,7 +23,7 @@
#include "Event.hxx" #include "Event.hxx"
/** /**
This class handles the lighgun controller This class handles the lightgun controller
@author Thomas Jentzsch @author Thomas Jentzsch
*/ */
@ -42,7 +42,15 @@ public:
virtual ~Lightgun() = default; virtual ~Lightgun() = default;
public: 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 Update the entire digital and analog pin state according to the
@ -60,26 +68,11 @@ public:
*/ */
bool isAnalog() const override { return true; } 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: private:
// Pre-compute the events we care about based on given port Int32 myMouseX{0}, myMouseY{0};
// This will eliminate test for left or right port in update()
Event::Type myPosValue, myFireEvent;
int myCharge, myLastCharge; static constexpr Int32 X_OFS = -21;
static constexpr Int32 Y_OFS = 10;
static constexpr int TRIGMIN = 1;
static constexpr int TRIGMAX = 4096;
static int MOUSE_SENSITIVITY;
// Lookup table for associating paddle buttons with controller pins // Lookup table for associating paddle buttons with controller pins
static const Controller::DigitalPin ourButtonPin; static const Controller::DigitalPin ourButtonPin;

View File

@ -40,7 +40,7 @@ void MindLink::update()
return; return;
myMindlinkPos = (myMindlinkPos & 0x3fffffff) + myMindlinkPos = (myMindlinkPos & 0x3fffffff) +
(myEvent.get(Event::MouseAxisXValue) << 3); (myEvent.get(Event::MouseAxisXMove) << 3);
if(myMindlinkPos < 0x2800) if(myMindlinkPos < 0x2800)
myMindlinkPos = 0x2800; myMindlinkPos = 0x2800;
if(myMindlinkPos >= 0x3800) if(myMindlinkPos >= 0x3800)

View File

@ -162,13 +162,13 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
abs(MOUSE_SENSITIVITY); abs(MOUSE_SENSITIVITY);
if(!swapaxis) if(!swapaxis)
{ {
myAxisMouseMotion = Event::MouseAxisXValue; myAxisMouseMotion = Event::MouseAxisXMove;
myAxisDigitalZero = 0; myAxisDigitalZero = 0;
myAxisDigitalOne = 1; myAxisDigitalOne = 1;
} }
else else
{ {
myAxisMouseMotion = Event::MouseAxisYValue; myAxisMouseMotion = Event::MouseAxisYMove;
myAxisDigitalZero = 1; myAxisDigitalZero = 1;
myAxisDigitalOne = 0; myAxisDigitalOne = 0;
} }
@ -277,7 +277,7 @@ void Paddles::update()
if(myMPaddleIDX > -1) if(myMPaddleIDX > -1)
{ {
myCharge[myMPaddleIDX] = BSPF::clamp(myCharge[myMPaddleIDX] - myCharge[myMPaddleIDX] = BSPF::clamp(myCharge[myMPaddleIDX] -
(myEvent.get(Event::MouseAxisXValue) * MOUSE_SENSITIVITY), (myEvent.get(Event::MouseAxisXMove) * MOUSE_SENSITIVITY),
TRIGMIN, TRIGRANGE); TRIGMIN, TRIGRANGE);
if(myEvent.get(Event::MouseButtonLeftValue)) if(myEvent.get(Event::MouseButtonLeftValue))
setPin(ourButtonPin[myMPaddleIDX], false); setPin(ourButtonPin[myMPaddleIDX], false);
@ -285,7 +285,7 @@ void Paddles::update()
if(myMPaddleIDY > -1) if(myMPaddleIDY > -1)
{ {
myCharge[myMPaddleIDY] = BSPF::clamp(myCharge[myMPaddleIDY] - myCharge[myMPaddleIDY] = BSPF::clamp(myCharge[myMPaddleIDY] -
(myEvent.get(Event::MouseAxisYValue) * MOUSE_SENSITIVITY), (myEvent.get(Event::MouseAxisYMove) * MOUSE_SENSITIVITY),
TRIGMIN, TRIGRANGE); TRIGMIN, TRIGRANGE);
if(myEvent.get(Event::MouseButtonRightValue)) if(myEvent.get(Event::MouseButtonRightValue))
setPin(ourButtonPin[myMPaddleIDY], false); setPin(ourButtonPin[myMPaddleIDY], false);

View File

@ -79,11 +79,11 @@ void PointingDevice::update()
return; return;
// Update horizontal direction // Update horizontal direction
updateDirection( myEvent.get(Event::MouseAxisXValue), myHCounterRemainder, updateDirection( myEvent.get(Event::MouseAxisXMove), myHCounterRemainder,
myTrackBallLeft, myTrackBallLinesH, myScanCountH, myFirstScanOffsetH); myTrackBallLeft, myTrackBallLinesH, myScanCountH, myFirstScanOffsetH);
// Update vertical direction // Update vertical direction
updateDirection(-myEvent.get(Event::MouseAxisYValue), myVCounterRemainder, updateDirection(-myEvent.get(Event::MouseAxisYMove), myVCounterRemainder,
myTrackBallDown, myTrackBallLinesV, myScanCountV, myFirstScanOffsetV); myTrackBallDown, myTrackBallLinesV, myScanCountV, myFirstScanOffsetV);
// Get mouse button state // Get mouse button state

View File

@ -66,6 +66,7 @@ MODULE_OBJS := \
src/emucore/Joystick.o \ src/emucore/Joystick.o \
src/emucore/Keyboard.o \ src/emucore/Keyboard.o \
src/emucore/KidVid.o \ src/emucore/KidVid.o \
src/emucore/Lightgun.o \
src/emucore/MindLink.o \ src/emucore/MindLink.o \
src/emucore/M6502.o \ src/emucore/M6502.o \
src/emucore/M6532.o \ src/emucore/M6532.o \

View File

@ -21,7 +21,6 @@
#include "EventHandler.hxx" #include "EventHandler.hxx"
#include "Joystick.hxx" #include "Joystick.hxx"
#include "Paddles.hxx" #include "Paddles.hxx"
#include "Lightgun.hxx"
#include "PointingDevice.hxx" #include "PointingDevice.hxx"
#include "SaveKey.hxx" #include "SaveKey.hxx"
#include "AtariVox.hxx" #include "AtariVox.hxx"
@ -350,8 +349,6 @@ void InputDialog::saveConfig()
sensitivity = myMPaddleSpeed->getValue(); sensitivity = myMPaddleSpeed->getValue();
instance().settings().setValue("msense", sensitivity); instance().settings().setValue("msense", sensitivity);
Paddles::setMouseSensitivity(sensitivity); Paddles::setMouseSensitivity(sensitivity);
Lightgun::setMouseSensitivity(sensitivity);
// Trackball speed // Trackball speed
sensitivity = myTrackBallSpeed->getValue(); sensitivity = myTrackBallSpeed->getValue();