From 265a090cc18bb11fa4ca66560dde143bb1088cc7 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Fri, 6 Jan 2023 00:43:38 +0100 Subject: [PATCH] improved driving controller responsiveness to digital input --- src/emucore/Driving.cxx | 11 +++++++++-- src/emucore/Driving.hxx | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/emucore/Driving.cxx b/src/emucore/Driving.cxx index 4b6f62560..1cab7b75a 100644 --- a/src/emucore/Driving.cxx +++ b/src/emucore/Driving.cxx @@ -115,21 +115,28 @@ void Driving::updateControllerAxes() // Digital events (from keyboard or joystick hats & buttons) const int d_axis = myEvent.get(myXAxisValue); - if(myEvent.get(myCCWEvent) != 0 || d_axis < -16384) + if(myEvent.get(myCCWEvent) != 0 && myLastCCWEvent == 0) + myCounterHires = ((myGrayIndex + 4) * 256.0F) / SENSITIVITY - 1; // set to end of previous counter interval + else if(myEvent.get(myCWEvent) != 0 && myLastCWEvent == 0) + myCounterHires = ((myGrayIndex + 1) * 256.0F) / SENSITIVITY; // set to begin of next counter interval + else if(myEvent.get(myCCWEvent) != 0 || d_axis < -16384) myCounterHires -= 64; else if(myEvent.get(myCWEvent) != 0 || d_axis > 16384) myCounterHires += 64; + myLastCCWEvent = myEvent.get(myCCWEvent); + myLastCWEvent = myEvent.get(myCWEvent); // Analog events (from joystick axes) const int a_axis = myEvent.get(myAnalogEvent); - if( abs(a_axis) > Controller::analogDeadZone()) + if(abs(a_axis) > Controller::analogDeadZone()) { /* a_axis is in -2^15 to +2^15-1; adding 1 when non-negative and dividing by 2^9 gives us -2^6 to +2^6, which gives us the same range as digital inputs. */ myCounterHires += (a_axis/512) + (a_axis >= 0); + cerr << "! "; } // Only consider the lower-most bits (corresponding to pins 1 & 2) diff --git a/src/emucore/Driving.hxx b/src/emucore/Driving.hxx index ec4d11544..0cec7cd9d 100644 --- a/src/emucore/Driving.hxx +++ b/src/emucore/Driving.hxx @@ -97,6 +97,12 @@ class Driving : public Controller // Higher resolution counter for analog (non-Stelladaptor) inputs uInt32 myCounterHires{0}; + // Previous digital CCW event + Int32 myLastCCWEvent{0}; + + // Previous digital CW event + Int32 myLastCWEvent{0}; + // Index into the gray code table uInt32 myGrayIndex{0};