From c26f0a12751e79a46c9a0299b76c2848d2a9b38a Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 8 Jan 2012 18:23:51 +0000 Subject: [PATCH] Make sure AtariVox and SaveKey controllers aren't messed up when the Console runs autodetection routines at startup. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2344 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/emucore/AtariVox.cxx | 9 ++++++++- src/emucore/AtariVox.hxx | 12 +++++++++++- src/emucore/Console.cxx | 19 ++++++------------- src/emucore/Control.cxx | 23 ++--------------------- src/emucore/Control.hxx | 7 +++++++ src/emucore/SaveKey.cxx | 9 ++++++++- src/emucore/SaveKey.hxx | 10 ++++++++++ 7 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/emucore/AtariVox.cxx b/src/emucore/AtariVox.cxx index 9472984e7..90ebd2ec8 100644 --- a/src/emucore/AtariVox.cxx +++ b/src/emucore/AtariVox.cxx @@ -31,7 +31,8 @@ AtariVox::AtariVox(Jack jack, const Event& event, const System& system, myEEPROM(NULL), myShiftCount(0), myShiftRegister(0), - myLastDataWriteCycle(0) + myLastDataWriteCycle(0), + myIsEnabled(false) { if(mySerialPort.openPort(portname)) myAboutString = " (using serial port \'" + portname + "\')"; @@ -56,6 +57,9 @@ AtariVox::~AtariVox() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool AtariVox::read(DigitalPin pin) { + if(!myIsEnabled) + return Controller::read(pin); + // We need to override the Controller::read() method, since the timing // of the actual read is important for the EEPROM (we can't just read // 60 times per second in the ::update() method) @@ -79,6 +83,9 @@ bool AtariVox::read(DigitalPin pin) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AtariVox::write(DigitalPin pin, bool value) { + if(!myIsEnabled) + return; + // Change the pin state based on value switch(pin) { diff --git a/src/emucore/AtariVox.hxx b/src/emucore/AtariVox.hxx index 31ee0c025..b862a01dc 100644 --- a/src/emucore/AtariVox.hxx +++ b/src/emucore/AtariVox.hxx @@ -89,7 +89,14 @@ class AtariVox : public Controller */ void systemCyclesReset(); - virtual string about() const; + /** + Notification to controllers that they should enable or disable + reads and writes on their pins. Most controllers do not + implement this. + */ + void enable(bool state) { myIsEnabled = state; } + + string about() const; private: void clockDataIn(bool value); @@ -119,6 +126,9 @@ class AtariVox : public Controller // "close enough". uInt32 myLastDataWriteCycle; + // Whether we should process reads and writes + bool myIsEnabled; + // Holds information concerning serial port usage string myAboutString; }; diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 409e6290e..ae3d17140 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -92,20 +92,8 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) // Construct the system and components mySystem = new System(13, 6); -#if 0 - // The real controllers for this console will be added later - // For now, we just add dummy joystick controllers, since autodetection - // runs the emulation for a while, and this may interfere with 'smart' - // controllers such as the AVox and SaveKey - // Note that the controllers must be added directly after the system - // has been created, and before any other device is added - // (particularly the M6532) - myControllers[0] = new Joystick(Controller::Left, *myEvent, *mySystem); - myControllers[1] = new Joystick(Controller::Right, *myEvent, *mySystem); -#endif + // Add the controllers for this system const string& md5 = myProperties.get(Cartridge_MD5); - - // Add the real controllers for this system setControllers(md5); // Bumper Bash always requires all 4 directions @@ -214,6 +202,8 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) // Reset the system to its power-on state mySystem->reset(); + myControllers[0]->enable(true); + myControllers[1]->enable(true); // Finally, add remaining info about the console myConsoleInfo.CartName = myProperties.get(Cartridge_Name); @@ -755,6 +745,9 @@ void Console::setControllers(const string& rommd5) { myControllers[rightPort] = new Joystick(Controller::Right, *myEvent, *mySystem); } + + myControllers[leftPort]->enable(false); + myControllers[rightPort]->enable(false); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 0ea34c0f7..f9400fa3f 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -106,32 +106,13 @@ uInt8 Controller::read() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Controller::read(DigitalPin pin) { - switch(pin) - { - case One: - case Two: - case Three: - case Four: - case Six: - return myDigitalPinState[pin]; - - default: - return true; - } + return myDigitalPinState[pin]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Int32 Controller::read(AnalogPin pin) { - switch(pin) - { - case Five: - case Nine: - return myAnalogPinValue[pin]; - - default: - return maximumResistance; - } + return myAnalogPinValue[pin]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index b19c2f6ac..ffc718043 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -188,6 +188,13 @@ class Controller : public Serializable */ virtual void systemCyclesReset() { }; + /** + Notification to controllers that they should enable or disable + reads and writes on their pins. Most controllers do not + implement this. + */ + virtual void enable(bool state) { }; + /** Determines how this controller will treat values received from the X and Y axis of the mouse. Since not all controllers use the mouse, diff --git a/src/emucore/SaveKey.cxx b/src/emucore/SaveKey.cxx index 75e842f61..41f59ed7c 100644 --- a/src/emucore/SaveKey.cxx +++ b/src/emucore/SaveKey.cxx @@ -25,7 +25,8 @@ SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const string& eepromfile) : Controller(jack, event, system, Controller::SaveKey), - myEEPROM(NULL) + myEEPROM(NULL), + myIsEnabled(false) { myEEPROM = new MT24LC256(eepromfile, system); @@ -42,6 +43,9 @@ SaveKey::~SaveKey() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool SaveKey::read(DigitalPin pin) { + if(!myIsEnabled) + return Controller::read(pin); + // We need to override the Controller::read() method, since the timing // of the actual read is important for the EEPROM (we can't just read // 60 times per second in the ::update() method) @@ -60,6 +64,9 @@ bool SaveKey::read(DigitalPin pin) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SaveKey::write(DigitalPin pin, bool value) { + if(!myIsEnabled) + return; + // Change the pin state based on value switch(pin) { diff --git a/src/emucore/SaveKey.hxx b/src/emucore/SaveKey.hxx index 32e7b9ddc..1563e8db2 100644 --- a/src/emucore/SaveKey.hxx +++ b/src/emucore/SaveKey.hxx @@ -85,9 +85,19 @@ class SaveKey : public Controller */ void systemCyclesReset(); + /** + Notification to controllers that they should enable or disable + reads and writes on their pins. Most controllers do not + implement this. + */ + void enable(bool state) { myIsEnabled = state; } + private: // The EEPROM used in the SaveKey MT24LC256* myEEPROM; + + // Whether we should process reads and writes + bool myIsEnabled; }; #endif