diff --git a/src/emucore/Driving.cxx b/src/emucore/Driving.cxx index 2d9e805d9..25680b601 100644 --- a/src/emucore/Driving.cxx +++ b/src/emucore/Driving.cxx @@ -8,7 +8,7 @@ // SS SS tt ee ll ll aa aa // SSSS ttt eeeee llll llll aaaaa // -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony +// Copyright (c) 1995-2023 by Bradford W. Mott, Stephen Anthony // and the Stella Team // // See the file "License.txt" for information on usage and redistribution of @@ -114,16 +114,23 @@ void Driving::updateControllerAxes() { // Digital events (from keyboard or joystick hats & buttons) const int d_axis = myEvent.get(myXAxisValue); + const Int32 oldCounterHires = myCounterHires; - 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 @@ -132,13 +139,15 @@ void Driving::updateControllerAxes() myCounterHires += (a_axis/512) + (a_axis >= 0); } - // Only consider the lower-most bits (corresponding to pins 1 & 2) - myGrayIndex = static_cast((myCounterHires / 256.0F) * SENSITIVITY) & 0b11; + if(oldCounterHires != myCounterHires) + // Only consider the lower-most bits (corresponding to pins 1 & 2) + myGrayIndex = static_cast((myCounterHires / 256.0F) * SENSITIVITY) & 0b11; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Driving::updateMouseAxes() { + const Int32 oldCounter = myCounter; static constexpr int MJ_Threshold = 2; // Mouse motion and button events @@ -171,6 +180,8 @@ void Driving::updateMouseAxes() ++myCounter; } } + if(myCounter != oldCounter) + myGrayIndex = (myCounter >> 2) & 0b11; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -199,6 +210,7 @@ void Driving::updateStelladaptorAxes() // simulated gray codes generated by PC keyboard or PC joystick // Must be rounded into the middle of the myCounter interval! myCounter = (myGrayIndex + 0.5F) * 4.0F / SENSITIVITY; + myCounterHires = myCounter * 256.0F / 4.0F; } } diff --git a/src/emucore/Driving.hxx b/src/emucore/Driving.hxx index 59560b9fe..c6c631567 100644 --- a/src/emucore/Driving.hxx +++ b/src/emucore/Driving.hxx @@ -8,7 +8,7 @@ // SS SS tt ee ll ll aa aa // SSSS ttt eeeee llll llll aaaaa // -// Copyright (c) 1995-2022 by Bradford W. Mott, Stephen Anthony +// Copyright (c) 1995-2023 by Bradford W. Mott, Stephen Anthony // and the Stella Team // // See the file "License.txt" for information on usage and redistribution of @@ -95,7 +95,13 @@ class Driving : public Controller Int32 myCounter{0}; // Higher resolution counter for analog (non-Stelladaptor) inputs - uInt32 myCounterHires{0}; + Int32 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};