mirror of https://github.com/stella-emu/stella.git
get lightgun working preliminary
This commit is contained in:
parent
24faa4955c
commit
1295bd5cf6
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue