From 9e23fa3c7279c4b85e77c7ac9a9b81bf99de935c Mon Sep 17 00:00:00 2001 From: estolberg Date: Mon, 3 Mar 2008 16:27:16 +0000 Subject: [PATCH] Fixed a bug that was preventing driving controllers on the Stelladaptor to coexist peacefully with other PC inputs. Also corrected the driving controller movement drection for the Stelladaptor. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1416 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/Driving.cxx | 37 +++++++++++++++++++++------------- stella/src/emucore/Driving.hxx | 11 ++++++++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/stella/src/emucore/Driving.cxx b/stella/src/emucore/Driving.cxx index 84ca8b227..28e82421a 100644 --- a/stella/src/emucore/Driving.cxx +++ b/stella/src/emucore/Driving.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Driving.cxx,v 1.15 2008-03-02 19:20:50 stephena Exp $ +// $Id: Driving.cxx,v 1.16 2008-03-03 16:27:16 estolberg Exp $ //============================================================================ #include "Event.hxx" @@ -58,8 +58,10 @@ Driving::~Driving() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Driving::update() { - int grayIndex = 0; - + // Make sure direct gray codes from Stelladaptor stay in sync with + // simulated gray codes generated by PC keyboard or PC joystick + myCounter = (myGrayIndex << 2) | (myCounter & 3); + // Digital events (from keyboard or joystick hats & buttons) myDigitalPinState[Six] = (myEvent.get(myFireEvent) == 0); @@ -69,24 +71,31 @@ void Driving::update() // Only consider the lower-most bits (corresponding to pins 1 & 2) myCounter &= 0x0f; - grayIndex = myCounter >> 2; + myGrayIndex = myCounter >> 2; // Stelladaptor is the only controller that should set this int yaxis = myEvent.get(myYAxisValue); - if(yaxis <= -16384-4096) - grayIndex = 2; - else if(yaxis > 16384+4096) - grayIndex = 1; - else if(yaxis >= 16384-4096) - grayIndex = 0; - else if(yaxis < -16384+4096) - grayIndex = 3; - + + // Only overwrite gray code when Stelladaptor input has changed + // (that means real changes, not just analog signal jitter) + if((yaxis < (myLastYaxis - 1024)) || (yaxis > (myLastYaxis + 1024))) + { + myLastYaxis = yaxis; + if(yaxis <= -16384-4096) + myGrayIndex = 3; // up + else if(yaxis > 16384+4096) + myGrayIndex = 1; // down + else if(yaxis >= 16384-4096) + myGrayIndex = 2; // up + down + else if(yaxis < 16384-4096) + myGrayIndex = 0; // no movement + } + // Gray codes for rotation static const uInt8 graytable[] = { 0x03, 0x01, 0x00, 0x02 }; // Determine which bits are set - uInt8 gray = graytable[grayIndex]; + uInt8 gray = graytable[myGrayIndex]; myDigitalPinState[One] = (gray & 0x1) != 0; myDigitalPinState[Two] = (gray & 0x2) != 0; } diff --git a/stella/src/emucore/Driving.hxx b/stella/src/emucore/Driving.hxx index 3d89d0e13..990308613 100644 --- a/stella/src/emucore/Driving.hxx +++ b/stella/src/emucore/Driving.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Driving.hxx,v 1.9 2008-03-02 19:20:50 stephena Exp $ +// $Id: Driving.hxx,v 1.10 2008-03-03 16:27:16 estolberg Exp $ //============================================================================ #ifndef DRIVING_HXX @@ -27,7 +27,7 @@ The standard Atari 2600 Indy 500 driving controller. @author Bradford W. Mott - @version $Id: Driving.hxx,v 1.9 2008-03-02 19:20:50 stephena Exp $ + @version $Id: Driving.hxx,v 1.10 2008-03-03 16:27:16 estolberg Exp $ */ class Driving : public Controller { @@ -57,6 +57,13 @@ class Driving : public Controller // Counter to iterate through the gray codes uInt32 myCounter; + // Index into the gray code table + uInt32 myGrayIndex; + + // Y axis value from last yaxis event that was used to generate a new + // gray code + int myLastYaxis; + // Pre-compute the events we care about based on given port // This will eliminate test for left or right port in update() Event::Type myCWEvent, myCCWEvent, myFireEvent, myXAxisValue, myYAxisValue;