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
This commit is contained in:
stephena 2012-01-08 18:23:51 +00:00
parent 293a8a69b4
commit c26f0a1275
7 changed files with 52 additions and 37 deletions

View File

@ -31,7 +31,8 @@ AtariVox::AtariVox(Jack jack, const Event& event, const System& system,
myEEPROM(NULL), myEEPROM(NULL),
myShiftCount(0), myShiftCount(0),
myShiftRegister(0), myShiftRegister(0),
myLastDataWriteCycle(0) myLastDataWriteCycle(0),
myIsEnabled(false)
{ {
if(mySerialPort.openPort(portname)) if(mySerialPort.openPort(portname))
myAboutString = " (using serial port \'" + portname + "\')"; myAboutString = " (using serial port \'" + portname + "\')";
@ -56,6 +57,9 @@ AtariVox::~AtariVox()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AtariVox::read(DigitalPin pin) bool AtariVox::read(DigitalPin pin)
{ {
if(!myIsEnabled)
return Controller::read(pin);
// We need to override the Controller::read() method, since the timing // 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 // of the actual read is important for the EEPROM (we can't just read
// 60 times per second in the ::update() method) // 60 times per second in the ::update() method)
@ -79,6 +83,9 @@ bool AtariVox::read(DigitalPin pin)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVox::write(DigitalPin pin, bool value) void AtariVox::write(DigitalPin pin, bool value)
{ {
if(!myIsEnabled)
return;
// Change the pin state based on value // Change the pin state based on value
switch(pin) switch(pin)
{ {

View File

@ -89,7 +89,14 @@ class AtariVox : public Controller
*/ */
void systemCyclesReset(); 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: private:
void clockDataIn(bool value); void clockDataIn(bool value);
@ -119,6 +126,9 @@ class AtariVox : public Controller
// "close enough". // "close enough".
uInt32 myLastDataWriteCycle; uInt32 myLastDataWriteCycle;
// Whether we should process reads and writes
bool myIsEnabled;
// Holds information concerning serial port usage // Holds information concerning serial port usage
string myAboutString; string myAboutString;
}; };

View File

@ -92,20 +92,8 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props)
// Construct the system and components // Construct the system and components
mySystem = new System(13, 6); mySystem = new System(13, 6);
#if 0 // Add the controllers for this system
// 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
const string& md5 = myProperties.get(Cartridge_MD5); const string& md5 = myProperties.get(Cartridge_MD5);
// Add the real controllers for this system
setControllers(md5); setControllers(md5);
// Bumper Bash always requires all 4 directions // 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 // Reset the system to its power-on state
mySystem->reset(); mySystem->reset();
myControllers[0]->enable(true);
myControllers[1]->enable(true);
// Finally, add remaining info about the console // Finally, add remaining info about the console
myConsoleInfo.CartName = myProperties.get(Cartridge_Name); 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[rightPort] = new Joystick(Controller::Right, *myEvent, *mySystem);
} }
myControllers[leftPort]->enable(false);
myControllers[rightPort]->enable(false);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -106,32 +106,13 @@ uInt8 Controller::read()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Controller::read(DigitalPin pin) bool Controller::read(DigitalPin pin)
{ {
switch(pin) return myDigitalPinState[pin];
{
case One:
case Two:
case Three:
case Four:
case Six:
return myDigitalPinState[pin];
default:
return true;
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Int32 Controller::read(AnalogPin pin) Int32 Controller::read(AnalogPin pin)
{ {
switch(pin) return myAnalogPinValue[pin];
{
case Five:
case Nine:
return myAnalogPinValue[pin];
default:
return maximumResistance;
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -188,6 +188,13 @@ class Controller : public Serializable
*/ */
virtual void systemCyclesReset() { }; 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 Determines how this controller will treat values received from the
X and Y axis of the mouse. Since not all controllers use the mouse, X and Y axis of the mouse. Since not all controllers use the mouse,

View File

@ -25,7 +25,8 @@
SaveKey::SaveKey(Jack jack, const Event& event, const System& system, SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile) const string& eepromfile)
: Controller(jack, event, system, Controller::SaveKey), : Controller(jack, event, system, Controller::SaveKey),
myEEPROM(NULL) myEEPROM(NULL),
myIsEnabled(false)
{ {
myEEPROM = new MT24LC256(eepromfile, system); myEEPROM = new MT24LC256(eepromfile, system);
@ -42,6 +43,9 @@ SaveKey::~SaveKey()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SaveKey::read(DigitalPin pin) bool SaveKey::read(DigitalPin pin)
{ {
if(!myIsEnabled)
return Controller::read(pin);
// We need to override the Controller::read() method, since the timing // 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 // of the actual read is important for the EEPROM (we can't just read
// 60 times per second in the ::update() method) // 60 times per second in the ::update() method)
@ -60,6 +64,9 @@ bool SaveKey::read(DigitalPin pin)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SaveKey::write(DigitalPin pin, bool value) void SaveKey::write(DigitalPin pin, bool value)
{ {
if(!myIsEnabled)
return;
// Change the pin state based on value // Change the pin state based on value
switch(pin) switch(pin)
{ {

View File

@ -85,9 +85,19 @@ class SaveKey : public Controller
*/ */
void systemCyclesReset(); 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: private:
// The EEPROM used in the SaveKey // The EEPROM used in the SaveKey
MT24LC256* myEEPROM; MT24LC256* myEEPROM;
// Whether we should process reads and writes
bool myIsEnabled;
}; };
#endif #endif