define light gun offsets using game's md5 sum

This commit is contained in:
thrust26 2020-01-06 20:10:35 +01:00
parent bbac4a3034
commit f746300d6b
3 changed files with 55 additions and 20 deletions

View File

@ -873,7 +873,7 @@ unique_ptr<Controller> Console::getControllerPort(const Controller::Type type,
break;
case Controller::Type::Lightgun:
controller = make_unique<Lightgun>(port, myEvent, *mySystem, myOSystem.frameBuffer());
controller = make_unique<Lightgun>(port, myEvent, *mySystem, romMd5, myOSystem.frameBuffer());
break;
default:

View File

@ -26,10 +26,51 @@
// | Detect light | INPT4 bit 7 | INPT5 bit 7 | DP:6
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Lightgun::Lightgun(Jack jack, const Event& event, const System& system, const FrameBuffer& frameBuffer)
Lightgun::Lightgun(Jack jack, const Event& event, const System& system,
const string& romMd5, const FrameBuffer& frameBuffer)
: Controller(jack, event, system, Controller::Type::Lightgun),
myFrameBuffer(frameBuffer)
{
// Right now, there are only three games and a test ROM that use the light gun
if (romMd5 == "8da51e0c4b6b46f7619425119c7d018e" ||
romMd5 == "7e5ee26bc31ae8e4aa61388c935b9332")
{
// Sentinel
myOfsX = -24;
myOfsY = -5;
}
else if (romMd5 == "10c47acca2ecd212b900ad3cf6942dbb" ||
romMd5 == "15c11ab6e4502b2010b18366133fc322" ||
romMd5 == "557e893616648c37a27aab5a47acbf10" ||
romMd5 == "5d7293f1892b66c014e8d222e06f6165" ||
romMd5 == "b2ab209976354ad4a0e1676fc1fe5a82" ||
romMd5 == "b5a1a189601a785bdb2f02a424080412" ||
romMd5 == "c5bf03028b2e8f4950ec8835c6811d47" ||
romMd5 == "f0ef9a1e5d4027a157636d7f19952bb5")
{
// Shooting Arcade
myOfsX = -21;
myOfsY = 5;
}
else if (romMd5 == "2559948f39b91682934ea99d90ede631" ||
romMd5 == "e75ab446017448045b152eea78bf7910")
{
// Booby is Hungry
myOfsX = -21;
myOfsY = 5;
}
else if (romMd5 == "d65900fefa7dc18ac3ad99c213e2fa4e")
{
// Guntest
myOfsX = -25;
myOfsY = 1;
}
else
{
// average values
myOfsX = -23;
myOfsY = 1;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -56,8 +97,8 @@ bool Lightgun::read(DigitalPin pin)
* tia.height() / rect.h();
// get adjusted TIA coordinates
Int32 xTia = tia.clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + X_OFS;
Int32 yTia = tia.scanlines() - tia.startLine() + Y_OFS;
Int32 xTia = tia.clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + myOfsX;
Int32 yTia = tia.scanlines() - tia.startLine() + myOfsY;
if (xTia < 0)
xTia += TIAConstants::H_CLOCKS;
@ -77,7 +118,4 @@ void Lightgun::update()
// we allow left and right mouse buttons for fire button
setPin(DigitalPin::One, myEvent.get(Event::MouseButtonLeftValue)
|| myEvent.get(Event::MouseButtonRightValue));
cerr << mySystem.tia().startLine() << endl;
}

View File

@ -30,11 +30,15 @@ public:
/**
Create a new lightgun controller plugged into the specified jack
@param jack The jack the controller is plugged into
@param event The event object to use for events
@param system The system using this controller
@param jack The jack the controller is plugged into
@param event The event object to use for events
@param system The system using this controller
@param romMd5 The md5 of the ROM using this controller
@param frameBuffer The frame buffer
*/
Lightgun(Jack jack, const Event& event, const System& system, const FrameBuffer& frameBuffer);
Lightgun(Jack jack, const Event& event, const System& system,
const string& romMd5, const FrameBuffer& frameBuffer);
virtual ~Lightgun() = default;
public:
@ -62,15 +66,8 @@ public:
private:
const FrameBuffer& myFrameBuffer;
// Shooting Arcade:
static constexpr Int32 X_OFS = -21;
static constexpr Int32 Y_OFS = 5; // 260 scanlines
// Guntest:
//static constexpr Int32 X_OFS = -25;
//static constexpr Int32 Y_OFS = 1; // 262 scanlines
// Sentinel:
//static constexpr Int32 X_OFS = -24;
//static constexpr Int32 Y_OFS = -5; // 268 scanlines
// targetting compensation values
Int32 myOfsX{0}, myOfsY{0};
private:
// Following constructors and assignment operators not supported