diff --git a/Changes.txt b/Changes.txt index c280e0dc0..345a19140 100644 --- a/Changes.txt +++ b/Changes.txt @@ -37,6 +37,10 @@ then back again would pass a 'Tab' key event to the app, which in most cases would navigate to the next UI element. + * Fixed potential issue with state file saving and the debugger; under + certain circumstances a rewind would give a different state than + before (note that the state file format has changed because of this). + * Fixed lockups when entering the debugger under certain circumstances. * Reverted joystick changes for Decathlon ROMs from last release, as diff --git a/src/emucore/Random.hxx b/src/emucore/Random.hxx index 2170a599c..940e3fa90 100644 --- a/src/emucore/Random.hxx +++ b/src/emucore/Random.hxx @@ -22,6 +22,7 @@ #include "bspf.hxx" #include "OSystem.hxx" +#include "Serializable.hxx" /** This is a quick-and-dirty random number generator. It is based on @@ -30,7 +31,7 @@ @author Bradford W. Mott */ -class Random +class Random : public Serializable { public: /** @@ -57,6 +58,59 @@ class Random return (myValue = (myValue * 2416 + 374441) % 1771875); } + /** + Save the current state of this device to the given Serializer. + + @param out The Serializer object to use + @return False on any errors, else true + */ + bool save(Serializer& out) const override + { + try + { + out.putString(name()); + out.putInt(myValue); + } + catch(...) + { + cerr << "ERROR: Random::save" << endl; + return false; + } + + return true; + } + + /** + Load the current state of this device from the given Serializer. + + @param in The Serializer object to use + @return False on any errors, else true + */ + bool load(Serializer& in) override + { + try + { + if(in.getString() != name()) + return false; + + myValue = in.getInt(); + } + catch(...) + { + cerr << "ERROR: Random::load" << endl; + return false; + } + + return true; + } + + /** + Get a descriptor for the device name (used in error checking). + + @return The name of the object + */ + string name() const override { return "Random"; } + private: // Set the OSystem we're using const OSystem& myOSystem; diff --git a/src/emucore/StateManager.cxx b/src/emucore/StateManager.cxx index 8e3101fce..3a7b5ba0e 100644 --- a/src/emucore/StateManager.cxx +++ b/src/emucore/StateManager.cxx @@ -28,7 +28,7 @@ #include "StateManager.hxx" -#define STATE_HEADER "05000000state" +#define STATE_HEADER "05000200state" #define MOVIE_HEADER "03030000movie" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/System.cxx b/src/emucore/System.cxx index dfcf2f82a..688ba4ae3 100644 --- a/src/emucore/System.cxx +++ b/src/emucore/System.cxx @@ -221,6 +221,8 @@ bool System::save(Serializer& out) const return false; if(!myCart.save(out)) return false; + if(!randGenerator().save(out)) + return false; } catch(...) { @@ -251,6 +253,8 @@ bool System::load(Serializer& in) return false; if(!myCart.load(in)) return false; + if(!randGenerator().load(in)) + return false; } catch(...) {