mirror of https://github.com/stella-emu/stella.git
apply screen scaling to lightgun controller
This commit is contained in:
parent
1295bd5cf6
commit
86e01bc8b9
|
@ -873,7 +873,7 @@ unique_ptr<Controller> Console::getControllerPort(const Controller::Type type,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Controller::Type::Lightgun:
|
case Controller::Type::Lightgun:
|
||||||
controller = make_unique<Lightgun>(port, myEvent, *mySystem);
|
controller = make_unique<Lightgun>(port, myEvent, *mySystem, myOSystem.frameBuffer());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
|
|
||||||
#include "TIA.hxx"
|
#include "TIA.hxx"
|
||||||
#include "System.hxx"
|
#include "System.hxx"
|
||||||
|
#include "FrameBuffer.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, const FrameBuffer& frameBuffer)
|
||||||
: Controller(jack, event, system, Controller::Type::Lightgun)
|
: Controller(jack, event, system, Controller::Type::Lightgun),
|
||||||
|
myFrameBuffer(frameBuffer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,22 +41,16 @@ bool Lightgun::read(DigitalPin pin)
|
||||||
// Pin 6: INPT4/5
|
// Pin 6: INPT4/5
|
||||||
case DigitalPin::Six:
|
case DigitalPin::Six:
|
||||||
{
|
{
|
||||||
// TODO: scale correctly, current code assumes 2x zoom and no vertical scaling
|
const Common::Rect& rect = myFrameBuffer.imageRect();
|
||||||
Int32 xpos = myMouseX / 4;
|
// scale mouse coordinates into TIA coordinates
|
||||||
Int32 ypos = myMouseY / 2;
|
Int32 xpos = (myMouseX - rect.x()) * TIAConstants::H_PIXEL / rect.w();
|
||||||
uInt32 ux;
|
Int32 ypos = (myMouseY - rect.y()) * 210 / rect.h(); // TODO: replace "magic number"
|
||||||
uInt32 uy;
|
// get adjusted TIA coordinates
|
||||||
|
|
||||||
mySystem.tia().electronBeamPos(ux, uy);
|
|
||||||
Int32 x = mySystem.tia().clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS;
|
Int32 x = mySystem.tia().clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS;
|
||||||
|
Int32 y = mySystem.tia().scanlines() - mySystem.tia().startLine() + Y_OFS;
|
||||||
|
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
x += TIAConstants::H_CLOCKS;
|
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);
|
bool enable = !((x - xpos) >= 0 && (x - xpos) < 15 && (y - ypos) >= 0);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
@param event The event object to use for events
|
@param event The event object to use for events
|
||||||
@param system The system using this controller
|
@param system The system using this controller
|
||||||
*/
|
*/
|
||||||
Lightgun(Jack jack, const Event& event, const System& system);
|
Lightgun(Jack jack, const Event& event, const System& system, const FrameBuffer& frameBuffer);
|
||||||
virtual ~Lightgun() = default;
|
virtual ~Lightgun() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -69,10 +69,11 @@ public:
|
||||||
bool isAnalog() const override { return true; }
|
bool isAnalog() const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const FrameBuffer& myFrameBuffer;
|
||||||
Int32 myMouseX{0}, myMouseY{0};
|
Int32 myMouseX{0}, myMouseY{0};
|
||||||
|
|
||||||
static constexpr Int32 X_OFS = -21;
|
static constexpr Int32 X_OFS = -21;
|
||||||
static constexpr Int32 Y_OFS = 10;
|
static constexpr Int32 Y_OFS = 5;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
Loading…
Reference in New Issue