diff --git a/stella/src/emucore/AtariVox.cxx b/stella/src/emucore/AtariVox.cxx index 6a3bf3fee..a89c2d94c 100644 --- a/stella/src/emucore/AtariVox.cxx +++ b/stella/src/emucore/AtariVox.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: AtariVox.cxx,v 1.19 2008-05-06 16:39:10 stephena Exp $ +// $Id: AtariVox.cxx,v 1.20 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #ifdef SPEAKJET_EMULATION @@ -25,8 +25,6 @@ #include "System.hxx" #include "AtariVox.hxx" -#define DEBUG_ATARIVOX 0 - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AtariVox::AtariVox(Jack jack, const Event& event, const System& system, const SerialPort& port, const string& portname, @@ -93,9 +91,6 @@ bool AtariVox::read(DigitalPin pin) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AtariVox::write(DigitalPin pin, bool value) { - if(DEBUG_ATARIVOX) - cerr << "AtariVox: write to SWCHA" << endl; - // Change the pin state based on value switch(pin) { @@ -109,12 +104,6 @@ void AtariVox::write(DigitalPin pin, bool value) // Pin 3: EEPROM SDA // output data to the 24LC256 EEPROM using the I2C protocol case Three: - if(DEBUG_ATARIVOX) - cerr << "AtariVox: value " - << value - << " written to SDA line at cycle " - << mySystem.cycles() - << endl; myDigitalPinState[Three] = value; myEEPROM->writeSDA(value); break; @@ -122,12 +111,6 @@ void AtariVox::write(DigitalPin pin, bool value) // Pin 4: EEPROM SCL // output clock data to the 24LC256 EEPROM using the I2C protocol case Four: - if(DEBUG_ATARIVOX) - cerr << "AtariVox: value " - << value - << " written to SCLK line at cycle " - << mySystem.cycles() - << endl; myDigitalPinState[Four] = value; myEEPROM->writeSCL(value); break; @@ -141,25 +124,9 @@ void AtariVox::write(DigitalPin pin, bool value) void AtariVox::clockDataIn(bool value) { uInt32 cycle = mySystem.cycles(); - if(DEBUG_ATARIVOX) - cerr << "AtariVox: value " - << value - << " written to DATA line at " - << mySystem.cycles() - << " (-" - << myLastDataWriteCycle - << "==" - << (mySystem.cycles() - myLastDataWriteCycle) - << ")" - << endl; if(value && (myShiftCount == 0)) - { - if(DEBUG_ATARIVOX) - cerr << "value && (myShiftCount == 0), returning" << endl; -//cerr << "!!!!! INVALID START BIT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; return; - } // If this is the first write this frame, or if it's been a long time // since the last write, start a new data byte. @@ -167,25 +134,17 @@ void AtariVox::clockDataIn(bool value) { myShiftRegister = 0; myShiftCount = 0; -//cerr << "!!!!! START NEW BYTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; } else if(cycle > myLastDataWriteCycle + 1000) { myShiftRegister = 0; myShiftCount = 0; -//cerr << "!!!!! DELAY TOO LONG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; } -//cerr << "value = " << value << " (" << (int)myShiftCount << ")" << endl; - // If this is the first write this frame, or if it's been 62 cycles // since the last write, shift this bit into the current byte. if(cycle < myLastDataWriteCycle || cycle >= myLastDataWriteCycle + 62) { - if(DEBUG_ATARIVOX) - cerr << "cycle >= myLastDataWriteCycle + 62, shiftIn(" - << value << ")" << endl; - myShiftRegister >>= 1; myShiftRegister |= (value << 15); if(++myShiftCount == 10) @@ -204,8 +163,6 @@ void AtariVox::clockDataIn(bool value) #else mySpeakJet->write(data); #endif -//cerr << " ==> " << (int)data << endl; -//cerr << "----------------------------------------------------------\n"; } myShiftRegister = 0; } @@ -214,6 +171,16 @@ void AtariVox::clockDataIn(bool value) myLastDataWriteCycle = cycle; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void AtariVox::systemCyclesReset() +{ + myLastDataWriteCycle -= mySystem.cycles(); + + // The EEPROM keeps track of cycle counts, and needs to know when the + // cycles are reset + myEEPROM->systemCyclesReset(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string AtariVox::about() const { diff --git a/stella/src/emucore/AtariVox.hxx b/stella/src/emucore/AtariVox.hxx index a126c5ea7..2095cbc2d 100644 --- a/stella/src/emucore/AtariVox.hxx +++ b/stella/src/emucore/AtariVox.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: AtariVox.hxx,v 1.13 2008-04-20 19:52:33 stephena Exp $ +// $Id: AtariVox.hxx,v 1.14 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #ifndef ATARIVOX_HXX @@ -33,7 +33,7 @@ class MT24LC256; driver code. @author B. Watson - @version $Id: AtariVox.hxx,v 1.13 2008-04-20 19:52:33 stephena Exp $ + @version $Id: AtariVox.hxx,v 1.14 2008-05-19 02:53:57 stephena Exp $ */ class AtariVox : public Controller { @@ -82,6 +82,13 @@ class AtariVox : public Controller */ virtual void update() { } + /** + Notification method invoked by the system right before the + system resets its cycle counter to zero. It may be necessary + to override this method for devices that remember cycle counts. + */ + virtual void systemCyclesReset(); + virtual string about() const; #ifdef SPEAKJET_EMULATION diff --git a/stella/src/emucore/Console.cxx b/stella/src/emucore/Console.cxx index 10c9df1a3..f2d9945a3 100644 --- a/stella/src/emucore/Console.cxx +++ b/stella/src/emucore/Console.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: Console.cxx,v 1.142 2008-05-16 12:04:34 stephena Exp $ +// $Id: Console.cxx,v 1.143 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #include @@ -88,6 +88,16 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) // Construct the system and components mySystem = new System(13, 6); + // 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); + M6502* m6502; if(myOSystem->settings().getString("cpu") == "low") m6502 = new M6502Low(1); @@ -111,13 +121,6 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) myCart = cart; myRiot = m6532; - // 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 - myControllers[0] = new Joystick(Controller::Left, *myEvent, *mySystem); - myControllers[1] = new Joystick(Controller::Right, *myEvent, *mySystem); - // Query some info about this console ostringstream about, vidinfo; diff --git a/stella/src/emucore/Control.hxx b/stella/src/emucore/Control.hxx index ac747a8cf..091234da6 100644 --- a/stella/src/emucore/Control.hxx +++ b/stella/src/emucore/Control.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: Control.hxx,v 1.16 2008-05-15 15:07:29 stephena Exp $ +// $Id: Control.hxx,v 1.17 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #ifndef CONTROLLER_HXX @@ -57,7 +57,7 @@ class System; of the controller from the perspective of the controller's jack. @author Bradford W. Mott - @version $Id: Control.hxx,v 1.16 2008-05-15 15:07:29 stephena Exp $ + @version $Id: Control.hxx,v 1.17 2008-05-19 02:53:57 stephena Exp $ */ class Controller : public Serializable { @@ -157,6 +157,13 @@ class Controller : public Serializable */ virtual void update() = 0; + /** + Notification method invoked by the system right before the + system resets its cycle counter to zero. It may be necessary + to override this method for devices that remember cycle counts. + */ + virtual void systemCyclesReset() { }; + /** Saves the current state of this controller to the given Serializer. diff --git a/stella/src/emucore/M6532.cxx b/stella/src/emucore/M6532.cxx index 68adb2c01..481924869 100644 --- a/stella/src/emucore/M6532.cxx +++ b/stella/src/emucore/M6532.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: M6532.cxx,v 1.25 2008-05-16 23:56:30 stephena Exp $ +// $Id: M6532.cxx,v 1.26 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #include @@ -73,6 +73,10 @@ void M6532::systemCyclesReset() // System cycles are being reset to zero so we need to adjust // the cycle count we remembered when the timer was last set myCyclesWhenTimerSet -= mySystem->cycles(); + + // We should also inform any 'smart' controllers as well + myConsole.controller(Controller::Left).systemCyclesReset(); + myConsole.controller(Controller::Right).systemCyclesReset(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/MT24LC256.cxx b/stella/src/emucore/MT24LC256.cxx index f2dfc38cb..de9a4ec63 100644 --- a/stella/src/emucore/MT24LC256.cxx +++ b/stella/src/emucore/MT24LC256.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: MT24LC256.cxx,v 1.12 2008-05-17 15:16:45 stephena Exp $ +// $Id: MT24LC256.cxx,v 1.13 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #include @@ -140,13 +140,24 @@ void MT24LC256::update() { #if DEBUG_EEPROM cerr << endl << " I2C_PIN_WRITE(SCL = " << mySCL - << ", SDA = " << mySDA << ")" << endl; + << ", SDA = " << mySDA << ")" << " @ " << mySystem.cycles() << endl; #endif jpee_clock(mySCL); jpee_data(mySDA); } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void MT24LC256::systemCyclesReset() +{ + // System cycles are being reset to zero so we need to adjust + // the cycle counts we remembered + uInt32 cycles = mySystem.cycles(); + myCyclesWhenSDASet -= cycles; + myCyclesWhenSCLSet -= cycles; + myCyclesWhenTimerSet -= cycles; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::jpee_init() { diff --git a/stella/src/emucore/MT24LC256.hxx b/stella/src/emucore/MT24LC256.hxx index 8111fba2c..9071ae1cf 100644 --- a/stella/src/emucore/MT24LC256.hxx +++ b/stella/src/emucore/MT24LC256.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: MT24LC256.hxx,v 1.5 2008-05-11 21:18:35 stephena Exp $ +// $Id: MT24LC256.hxx,v 1.6 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #ifndef MT24LC256_HXX @@ -30,7 +30,7 @@ class System; (aka Supercat) for the bulk of this code. @author Stephen Anthony & J. Payson - @version $Id: MT24LC256.hxx,v 1.5 2008-05-11 21:18:35 stephena Exp $ + @version $Id: MT24LC256.hxx,v 1.6 2008-05-19 02:53:57 stephena Exp $ */ class MT24LC256 { @@ -56,6 +56,13 @@ class MT24LC256 void writeSDA(bool state); void writeSCL(bool state); + /** + Notification method invoked by the system right before the + system resets its cycle counter to zero. It may be necessary + to override this method for devices that remember cycle counts. + */ + void systemCyclesReset(); + private: // I2C access code provided by Supercat void jpee_init(); diff --git a/stella/src/emucore/SaveKey.cxx b/stella/src/emucore/SaveKey.cxx index 99595ef99..69c355d6c 100644 --- a/stella/src/emucore/SaveKey.cxx +++ b/stella/src/emucore/SaveKey.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: SaveKey.cxx,v 1.2 2008-05-06 16:39:12 stephena Exp $ +// $Id: SaveKey.cxx,v 1.3 2008-05-19 02:53:57 stephena Exp $ //============================================================================ #include "MT24LC256.hxx" @@ -80,3 +80,11 @@ void SaveKey::write(DigitalPin pin, bool value) break; } } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SaveKey::systemCyclesReset() +{ + // The EEPROM keeps track of cycle counts, and needs to know when the + // cycles are reset + myEEPROM->systemCyclesReset(); +} diff --git a/stella/src/emucore/SaveKey.hxx b/stella/src/emucore/SaveKey.hxx index 205fa1c38..d2f05ab42 100644 --- a/stella/src/emucore/SaveKey.hxx +++ b/stella/src/emucore/SaveKey.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: SaveKey.hxx,v 1.1 2008-04-29 15:49:34 stephena Exp $ +// $Id: SaveKey.hxx,v 1.2 2008-05-19 02:53:58 stephena Exp $ //============================================================================ #ifndef SAVEKEY_HXX @@ -31,7 +31,7 @@ class MT24LC256; driver code. @author Stephen Anthony - @version $Id: SaveKey.hxx,v 1.1 2008-04-29 15:49:34 stephena Exp $ + @version $Id: SaveKey.hxx,v 1.2 2008-05-19 02:53:58 stephena Exp $ */ class SaveKey : public Controller { @@ -77,6 +77,13 @@ class SaveKey : public Controller */ virtual void update() { } + /** + Notification method invoked by the system right before the + system resets its cycle counter to zero. It may be necessary + to override this method for devices that remember cycle counts. + */ + virtual void systemCyclesReset(); + private: // The EEPROM used in the SaveKey MT24LC256* myEEPROM;