diff --git a/Todo.txt b/Todo.txt index 0b6433342..e8ec27e6c 100644 --- a/Todo.txt +++ b/Todo.txt @@ -9,7 +9,7 @@ SSSS ttt eeeee llll llll aaaaa =============================================================================== - To Do List - June 2009 + To Do List - August 2009 =============================================================================== If you would like to contribute to Stella's development then find something diff --git a/src/common/SoundNull.cxx b/src/common/SoundNull.cxx index 419c015a8..f19e276d3 100644 --- a/src/common/SoundNull.cxx +++ b/src/common/SoundNull.cxx @@ -16,9 +16,6 @@ // $Id$ //============================================================================ -#include "Serializer.hxx" -#include "Deserializer.hxx" - #include "bspf.hxx" #include "OSystem.hxx" @@ -40,9 +37,9 @@ SoundNull::~SoundNull() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SoundNull::load(Deserializer& in) +bool SoundNull::load(Serializer& in) { - string soundDevice = "TIASound"; + const string& soundDevice = "TIASound"; if(in.getString() != soundDevice) return false; diff --git a/src/common/SoundNull.hxx b/src/common/SoundNull.hxx index 5b96206a9..9304d67ce 100644 --- a/src/common/SoundNull.hxx +++ b/src/common/SoundNull.hxx @@ -20,8 +20,6 @@ #define SOUND_NULL_HXX class OSystem; -class Serializer; -class Deserializer; #include "bspf.hxx" #include "Sound.hxx" @@ -138,12 +136,12 @@ class SoundNull : public Sound public: /** - Loads the current state of this device from the given Deserializer. + Loads the current state of this device from the given Serializer. - @param in The deserializer device to load from. + @param in The Serializer device to load from. @return The result of the load. True on success, false on failure. */ - bool load(Deserializer& in); + bool load(Serializer& in); /** Saves the current state of this device to the given Serializer. diff --git a/src/common/SoundSDL.cxx b/src/common/SoundSDL.cxx index 6685a686a..dc8de58c0 100644 --- a/src/common/SoundSDL.cxx +++ b/src/common/SoundSDL.cxx @@ -25,8 +25,6 @@ #include "TIASnd.hxx" #include "FrameBuffer.hxx" -#include "Serializer.hxx" -#include "Deserializer.hxx" #include "Settings.hxx" #include "System.hxx" #include "OSystem.hxx" @@ -198,12 +196,6 @@ void SoundSDL::mute(bool state) { if(myIsInitializedFlag) { - // Ignore multiple calls to do the same thing - if(myIsMuted == state) - { - return; - } - myIsMuted = state; SDL_PauseAudio(myIsMuted ? 1 : 0); @@ -435,58 +427,9 @@ void SoundSDL::callback(void* udata, uInt8* stream, int len) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SoundSDL::load(Deserializer& in) +bool SoundSDL::save(Serializer& out) const { - string device = "TIASound"; - - try - { - if(in.getString() != device) - return false; - - uInt8 reg1 = 0, reg2 = 0, reg3 = 0, reg4 = 0, reg5 = 0, reg6 = 0; - reg1 = (uInt8) in.getByte(); - reg2 = (uInt8) in.getByte(); - reg3 = (uInt8) in.getByte(); - reg4 = (uInt8) in.getByte(); - reg5 = (uInt8) in.getByte(); - reg6 = (uInt8) in.getByte(); - - myLastRegisterSetCycle = (Int32) in.getInt(); - - // Only update the TIA sound registers if sound is enabled - // Make sure to empty the queue of previous sound fragments - if(myIsInitializedFlag) - { - SDL_PauseAudio(1); - myRegWriteQueue.clear(); - myTIASound.set(0x15, reg1); - myTIASound.set(0x16, reg2); - myTIASound.set(0x17, reg3); - myTIASound.set(0x18, reg4); - myTIASound.set(0x19, reg5); - myTIASound.set(0x1a, reg6); - SDL_PauseAudio(0); - } - } - catch(char *msg) - { - cerr << msg << endl; - return false; - } - catch(...) - { - cerr << "Unknown error in load state for " << device << endl; - return false; - } - - return true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SoundSDL::save(Serializer& out) -{ - string device = "TIASound"; + const string& device = name(); try { @@ -528,6 +471,55 @@ bool SoundSDL::save(Serializer& out) return true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SoundSDL::load(Serializer& in) +{ + const string& device = name(); + + try + { + if(in.getString() != device) + return false; + + uInt8 reg1 = 0, reg2 = 0, reg3 = 0, reg4 = 0, reg5 = 0, reg6 = 0; + reg1 = (uInt8) in.getByte(); + reg2 = (uInt8) in.getByte(); + reg3 = (uInt8) in.getByte(); + reg4 = (uInt8) in.getByte(); + reg5 = (uInt8) in.getByte(); + reg6 = (uInt8) in.getByte(); + + myLastRegisterSetCycle = (Int32) in.getInt(); + + // Only update the TIA sound registers if sound is enabled + // Make sure to empty the queue of previous sound fragments + if(myIsInitializedFlag) + { + SDL_PauseAudio(1); + myRegWriteQueue.clear(); + myTIASound.set(0x15, reg1); + myTIASound.set(0x16, reg2); + myTIASound.set(0x17, reg3); + myTIASound.set(0x18, reg4); + myTIASound.set(0x19, reg5); + myTIASound.set(0x1a, reg6); + if(!myIsMuted) SDL_PauseAudio(0); + } + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in load state for " << device << endl; + return false; + } + + return true; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SoundSDL::RegWriteQueue::RegWriteQueue(uInt32 capacity) : myCapacity(capacity), diff --git a/src/common/SoundSDL.hxx b/src/common/SoundSDL.hxx index d7e4689ac..9b21b0b92 100644 --- a/src/common/SoundSDL.hxx +++ b/src/common/SoundSDL.hxx @@ -16,11 +16,11 @@ // $Id$ //============================================================================ +#ifdef SOUND_SUPPORT + #ifndef SOUND_SDL_HXX #define SOUND_SDL_HXX -#ifdef SOUND_SUPPORT - class OSystem; #include @@ -138,21 +138,28 @@ class SoundSDL : public Sound void adjustVolume(Int8 direction); public: - /** - Loads the current state of this device from the given Deserializer. - - @param in The deserializer device to load from. - @return The result of the load. True on success, false on failure. - */ - bool load(Deserializer& in); - /** Saves the current state of this device to the given Serializer. @param out The serializer device to save to. @return The result of the save. True on success, false on failure. */ - bool save(Serializer& out); + bool save(Serializer& out) const; + + /** + Loads the current state of this device from the given Serializer. + + @param in The Serializer device to load from. + @return The result of the load. True on success, false on failure. + */ + bool load(Serializer& in); + + /** + Get a descriptor for this console class (used in error checking). + + @return The name of the object + */ + string name() const { return "TIASound"; } protected: /** @@ -277,5 +284,6 @@ class SoundSDL : public Sound static void callback(void* udata, uInt8* stream, int len); }; -#endif // SOUND_SUPPORT #endif + +#endif // SOUND_SUPPORT diff --git a/src/gui/Stack.hxx b/src/common/Stack.hxx similarity index 93% rename from src/gui/Stack.hxx rename to src/common/Stack.hxx index ce3ce8604..a2b98ccb4 100644 --- a/src/gui/Stack.hxx +++ b/src/common/Stack.hxx @@ -22,10 +22,10 @@ #ifndef STACK_HXX #define STACK_HXX -#include +#include /** - * Extremly simple fixed size stack class. + * Simple fixed size stack class. */ template class FixedStack @@ -34,6 +34,7 @@ class FixedStack FixedStack() : _size(0) {} bool empty() const { return _size <= 0; } + bool full() const {return _size >= MAX_SIZE; } void clear() { _size = 0; } void push(const T& x) { diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index b17af7288..012072525 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -108,7 +108,8 @@ Debugger::Debugger(OSystem* osystem) myReadTraps(NULL), myWriteTraps(NULL), myWidth(1050), - myHeight(620) + myHeight(620), + myRewindManager(NULL) { // Get the dialog size int w, h; @@ -125,6 +126,8 @@ Debugger::Debugger(OSystem* osystem) myReadTraps = new PackedBitArray(0x10000); myWriteTraps = new PackedBitArray(0x10000); + myRewindManager = new RewindManager(*osystem); + // Allow access to this object from any class // Technically this violates pure OO programming, but since I know // there will only be ever one instance of debugger in Stella, @@ -146,6 +149,8 @@ Debugger::~Debugger() delete myBreakPoints; delete myReadTraps; delete myWriteTraps; + + delete myRewindManager; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -215,6 +220,9 @@ void Debugger::setConsole(Console* console) // Make sure cart RAM is added before this is called, // otherwise the debugger state won't know about it saveOldState(); + + // Empty the rewind list + myRewindManager->clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -656,6 +664,12 @@ void Debugger::nextFrame(int frames) lockBankswitchState(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Debugger::rewindState() +{ + return myRewindManager->rewindState(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Debugger::clearAllBreakPoints() { @@ -748,6 +762,9 @@ void Debugger::saveOldState() myRamDebug->saveOldState(); myRiotDebug->saveOldState(); myTiaDebug->saveOldState(); + + // Add another rewind level to the Undo list + myRewindManager->addState(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -755,6 +772,9 @@ void Debugger::setStartState() { // Lock the bus each time the debugger is entered, so we don't disturb anything lockBankswitchState(); + + // Start a new rewind list + myRewindManager->clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -931,3 +951,75 @@ void Debugger::unlockBankswitchState() mySystem->unlockDataBus(); myConsole->cartridge().unlockBank(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Debugger::RewindManager::RewindManager(OSystem& system) + : myOSystem(system), + mySize(0), + myTop(0) +{ + for(int i = 0; i < MAX_SIZE; ++i) + myStateList[i] = (Serializer*) NULL; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Debugger::RewindManager::~RewindManager() +{ + for(int i = 0; i < MAX_SIZE; ++i) + delete myStateList[i]; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Debugger::RewindManager::addState() +{ + // Are we still within the allowable size, or are we overwriting an item? + mySize++; if(mySize > MAX_SIZE) mySize = MAX_SIZE; + + // Create a new Serializer object if we need one + if(myStateList[myTop] == NULL) + myStateList[myTop] = new Serializer(); + Serializer& s = *(myStateList[myTop]); + + if(s.isValid()) + { + s.reset(); + myOSystem.state().saveState(s); + myOSystem.console().tia().saveDisplay(s); + myTop = (myTop + 1) % MAX_SIZE; + return true; + } + else + return false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Debugger::RewindManager::rewindState() +{ + if(mySize > 0) + { + mySize--; + myTop = myTop == 0 ? MAX_SIZE - 1 : myTop - 1; + Serializer& s = *(myStateList[myTop]); + + s.reset(); + myOSystem.state().loadState(s); + myOSystem.console().tia().loadDisplay(s); + return true; + } + else + return false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Debugger::RewindManager::isEmpty() +{ + return mySize == 0; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Debugger::RewindManager::clear() +{ + for(int i = 0; i < MAX_SIZE; ++i) + if(myStateList[i] != NULL) + myStateList[i]->reset(); +} diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 2fbd4ac95..9b0737d47 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -32,6 +32,7 @@ class TiaZoomWidget; class EditTextWidget; class RomWidget; class Expression; +class Serializer; #include @@ -43,6 +44,7 @@ class Expression; #include "PackedBitArray.hxx" #include "PromptWidget.hxx" #include "Rect.hxx" +#include "Stack.hxx" #include "bspf.hxx" typedef map FunctionMap; @@ -337,6 +339,7 @@ class Debugger : public DialogContainer int trace(); void nextScanline(int lines); void nextFrame(int frames); + bool rewindState(); void toggleBreakPoint(int bp); @@ -399,6 +402,29 @@ class Debugger : public DialogContainer // Dimensions of the entire debugger window uInt32 myWidth; uInt32 myHeight; + + // Class holding all rewind state functionality in the debugger + // Essentially, it's a modified circular array-based stack + // that cleverly deals with allocation/deallocation of memory + class RewindManager + { + public: + RewindManager(OSystem& system); + virtual ~RewindManager(); + + public: + bool addState(); + bool rewindState(); + bool isEmpty(); + void clear(); + + private: + enum { MAX_SIZE = 100 }; + OSystem& myOSystem; + Serializer* myStateList[MAX_SIZE]; + uInt32 mySize, myTop; + }; + RewindManager* myRewindManager; }; #endif diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index a67bc0462..ed750bbad 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -1117,6 +1117,16 @@ void DebuggerParser::executeReset() commandResult = "reset CPU"; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// "rewind" +void DebuggerParser::executeRewind() +{ + if(debugger->rewindState()) + commandResult = "rewind by one level"; + else + commandResult = "no states left to rewind"; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // "riot" void DebuggerParser::executeRiot() @@ -1671,6 +1681,15 @@ DebuggerParser::Command DebuggerParser::commands[kNumCommands] = { &DebuggerParser::executeReset }, + { + "rewind", + "Rewind state to last step/trace/scanline/frame advance", + false, + true, + { kARG_END_ARGS }, + &DebuggerParser::executeRewind + }, + { "riot", "Show RIOT timer/input status", diff --git a/src/debugger/DebuggerParser.hxx b/src/debugger/DebuggerParser.hxx index f1dee708b..83c448b7f 100644 --- a/src/debugger/DebuggerParser.hxx +++ b/src/debugger/DebuggerParser.hxx @@ -81,7 +81,7 @@ class DebuggerParser private: enum { - kNumCommands = 57, + kNumCommands = 58, kMAX_ARG_TYPES = 10 // TODO: put in separate header file Command.hxx }; @@ -169,6 +169,7 @@ class DebuggerParser void executePrint(); void executeRam(); // also implements 'poke' command void executeReset(); + void executeRewind(); void executeRiot(); void executeRom(); void executeRun(); diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index 7ffacb134..22a5b65bf 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -41,11 +41,12 @@ #include "DebuggerDialog.hxx" enum { - kDDStepCmd = 'DDst', - kDDTraceCmd = 'DDtr', - kDDAdvCmd = 'DDav', - kDDSAdvCmd = 'DDsv', - kDDExitCmd = 'DDex' + kDDStepCmd = 'DDst', + kDDTraceCmd = 'DDtr', + kDDAdvCmd = 'DDav', + kDDSAdvCmd = 'DDsv', + kDDRewindCmd = 'DDrw', + kDDExitCmd = 'DDex' }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -102,6 +103,9 @@ void DebuggerDialog::handleKeyDown(int ascii, int keycode, int modifiers) case 'l': doScanlineAdvance(); break; + case 'r': + doRewind(); + break; default: handled = false; break; @@ -135,6 +139,10 @@ void DebuggerDialog::handleCommand(CommandSender* sender, int cmd, doScanlineAdvance(); break; + case kDDRewindCmd: + doRewind(); + break; + case kDDExitCmd: doExit(); break; @@ -243,6 +251,8 @@ void DebuggerDialog::addRomArea() DataGridOpsWidget* ops = new DataGridOpsWidget(this, instance().consoleFont(), xpos, 20); +ops->setFlags(WIDGET_BORDER); + const int bwidth = instance().consoleFont().getStringWidth("Frame +1 "), bheight = instance().consoleFont().getLineHeight() + 2; int buttonX = r.right - bwidth - 5, buttonY = r.top + 5; @@ -297,6 +307,12 @@ void DebuggerDialog::doScanlineAdvance() instance().debugger().parser().run("scanline #1"); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DebuggerDialog::doRewind() +{ + instance().debugger().parser().run("rewind"); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DebuggerDialog::doExit() { diff --git a/src/debugger/gui/DebuggerDialog.hxx b/src/debugger/gui/DebuggerDialog.hxx index 1a6c59c4b..5e2d70ee2 100644 --- a/src/debugger/gui/DebuggerDialog.hxx +++ b/src/debugger/gui/DebuggerDialog.hxx @@ -77,6 +77,7 @@ class DebuggerDialog : public Dialog void doTrace(); void doScanlineAdvance(); void doAdvance(); + void doRewind(); void doExit(); }; diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index 9ac64877f..0bcd7e515 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -147,12 +147,12 @@ class Cartridge : public Device virtual bool save(Serializer& out) const = 0; /** - Load the current state of this device from the given Deserializer. + Load the current state of this device from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in) = 0; + virtual bool load(Serializer& in) = 0; /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Cart0840.cxx b/src/emucore/Cart0840.cxx index 46c1c5c26..700f49263 100644 --- a/src/emucore/Cart0840.cxx +++ b/src/emucore/Cart0840.cxx @@ -193,7 +193,7 @@ uInt8* Cartridge0840::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge0840::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -215,9 +215,9 @@ bool Cartridge0840::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge0840::load(Deserializer& in) +bool Cartridge0840::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/Cart0840.hxx b/src/emucore/Cart0840.hxx index 284f81f58..ec8b1f109 100644 --- a/src/emucore/Cart0840.hxx +++ b/src/emucore/Cart0840.hxx @@ -103,12 +103,12 @@ class Cartridge0840 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Cart2K.cxx b/src/emucore/Cart2K.cxx index f2c17d14c..2eab84f98 100644 --- a/src/emucore/Cart2K.cxx +++ b/src/emucore/Cart2K.cxx @@ -131,7 +131,7 @@ uInt8* Cartridge2K::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge2K::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -152,9 +152,9 @@ bool Cartridge2K::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge2K::load(Deserializer& in) +bool Cartridge2K::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/Cart2K.hxx b/src/emucore/Cart2K.hxx index df37f48bc..8dd7c3079 100644 --- a/src/emucore/Cart2K.hxx +++ b/src/emucore/Cart2K.hxx @@ -20,8 +20,6 @@ #define CARTRIDGE2K_HXX class System; -class Serializer; -class Deserializer; #include "bspf.hxx" #include "Cart.hxx" @@ -109,12 +107,12 @@ class Cartridge2K : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Cart3E.cxx b/src/emucore/Cart3E.cxx index 5f1496caf..4ce255126 100644 --- a/src/emucore/Cart3E.cxx +++ b/src/emucore/Cart3E.cxx @@ -243,7 +243,7 @@ uInt8* Cartridge3E::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge3E::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -270,9 +270,9 @@ bool Cartridge3E::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge3E::load(Deserializer& in) +bool Cartridge3E::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/Cart3E.hxx b/src/emucore/Cart3E.hxx index 8f6101360..1aaae7b7e 100644 --- a/src/emucore/Cart3E.hxx +++ b/src/emucore/Cart3E.hxx @@ -135,12 +135,12 @@ class Cartridge3E : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Cart3F.cxx b/src/emucore/Cart3F.cxx index 44c681596..a81101316 100644 --- a/src/emucore/Cart3F.cxx +++ b/src/emucore/Cart3F.cxx @@ -184,7 +184,7 @@ uInt8* Cartridge3F::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge3F::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -206,9 +206,9 @@ bool Cartridge3F::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge3F::load(Deserializer& in) +bool Cartridge3F::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/Cart3F.hxx b/src/emucore/Cart3F.hxx index ef326b943..578d8c706 100644 --- a/src/emucore/Cart3F.hxx +++ b/src/emucore/Cart3F.hxx @@ -112,12 +112,12 @@ class Cartridge3F : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Cart4A50.cxx b/src/emucore/Cart4A50.cxx index c58138c33..b411bdebe 100644 --- a/src/emucore/Cart4A50.cxx +++ b/src/emucore/Cart4A50.cxx @@ -320,7 +320,7 @@ uInt8* Cartridge4A50::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge4A50::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -360,9 +360,9 @@ bool Cartridge4A50::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge4A50::load(Deserializer& in) +bool Cartridge4A50::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/Cart4A50.hxx b/src/emucore/Cart4A50.hxx index 4720c9469..8e709c571 100644 --- a/src/emucore/Cart4A50.hxx +++ b/src/emucore/Cart4A50.hxx @@ -114,12 +114,12 @@ class Cartridge4A50 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Cart4K.cxx b/src/emucore/Cart4K.cxx index 6b82e1d11..9691b3acf 100644 --- a/src/emucore/Cart4K.cxx +++ b/src/emucore/Cart4K.cxx @@ -109,7 +109,7 @@ uInt8* Cartridge4K::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge4K::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -130,9 +130,9 @@ bool Cartridge4K::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge4K::load(Deserializer& in) +bool Cartridge4K::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/Cart4K.hxx b/src/emucore/Cart4K.hxx index 25fb0372d..eb0bd2add 100644 --- a/src/emucore/Cart4K.hxx +++ b/src/emucore/Cart4K.hxx @@ -105,12 +105,12 @@ class Cartridge4K : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartAR.cxx b/src/emucore/CartAR.cxx index 99fc7cb61..a69f7956e 100644 --- a/src/emucore/CartAR.cxx +++ b/src/emucore/CartAR.cxx @@ -425,7 +425,7 @@ uInt8* CartridgeAR::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeAR::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -490,9 +490,9 @@ bool CartridgeAR::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeAR::load(Deserializer& in) +bool CartridgeAR::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartAR.hxx b/src/emucore/CartAR.hxx index 20bfe260b..f4d411c17 100644 --- a/src/emucore/CartAR.hxx +++ b/src/emucore/CartAR.hxx @@ -121,12 +121,12 @@ class CartridgeAR : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartCV.cxx b/src/emucore/CartCV.cxx index 54bf935f0..35011afa1 100644 --- a/src/emucore/CartCV.cxx +++ b/src/emucore/CartCV.cxx @@ -168,7 +168,7 @@ uInt8* CartridgeCV::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeCV::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -194,9 +194,9 @@ bool CartridgeCV::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeCV::load(Deserializer& in) +bool CartridgeCV::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartCV.hxx b/src/emucore/CartCV.hxx index 4749d0e26..7a4b03daa 100644 --- a/src/emucore/CartCV.hxx +++ b/src/emucore/CartCV.hxx @@ -108,12 +108,12 @@ class CartridgeCV : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index 6a2a01675..0da4bba10 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -474,7 +474,7 @@ uInt8* CartridgeDPC::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeDPC::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -531,9 +531,9 @@ bool CartridgeDPC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeDPC::load(Deserializer& in) +bool CartridgeDPC::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartDPC.hxx b/src/emucore/CartDPC.hxx index f6cf9b253..0b021dea9 100644 --- a/src/emucore/CartDPC.hxx +++ b/src/emucore/CartDPC.hxx @@ -113,12 +113,12 @@ class CartridgeDPC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartE0.cxx b/src/emucore/CartE0.cxx index aeba44cec..8e49cf5d4 100644 --- a/src/emucore/CartE0.cxx +++ b/src/emucore/CartE0.cxx @@ -229,7 +229,7 @@ uInt8* CartridgeE0::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeE0::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -254,9 +254,9 @@ bool CartridgeE0::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeE0::load(Deserializer& in) +bool CartridgeE0::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartE0.hxx b/src/emucore/CartE0.hxx index 0f412d216..5b56e3e6a 100644 --- a/src/emucore/CartE0.hxx +++ b/src/emucore/CartE0.hxx @@ -110,12 +110,12 @@ class CartridgeE0 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartE7.cxx b/src/emucore/CartE7.cxx index e2f656a9b..c4258e576 100644 --- a/src/emucore/CartE7.cxx +++ b/src/emucore/CartE7.cxx @@ -240,7 +240,7 @@ uInt8* CartridgeE7::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeE7::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -274,9 +274,9 @@ bool CartridgeE7::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeE7::load(Deserializer& in) +bool CartridgeE7::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartE7.hxx b/src/emucore/CartE7.hxx index a60a5b40d..91f2daa5e 100644 --- a/src/emucore/CartE7.hxx +++ b/src/emucore/CartE7.hxx @@ -127,12 +127,12 @@ class CartridgeE7 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartEF.cxx b/src/emucore/CartEF.cxx index 007448c53..1228eb032 100644 --- a/src/emucore/CartEF.cxx +++ b/src/emucore/CartEF.cxx @@ -141,7 +141,7 @@ uInt8* CartridgeEF::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeEF::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -164,9 +164,9 @@ bool CartridgeEF::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeEF::load(Deserializer& in) +bool CartridgeEF::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartEF.hxx b/src/emucore/CartEF.hxx index 639894115..2a30269ff 100644 --- a/src/emucore/CartEF.hxx +++ b/src/emucore/CartEF.hxx @@ -109,12 +109,12 @@ class CartridgeEF : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartEFSC.cxx b/src/emucore/CartEFSC.cxx index 1c841163c..bf6de1808 100644 --- a/src/emucore/CartEFSC.cxx +++ b/src/emucore/CartEFSC.cxx @@ -181,7 +181,7 @@ uInt8* CartridgeEFSC::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeEFSC::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -204,9 +204,9 @@ bool CartridgeEFSC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeEFSC::load(Deserializer& in) +bool CartridgeEFSC::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartEFSC.hxx b/src/emucore/CartEFSC.hxx index b0d1c1835..772967324 100644 --- a/src/emucore/CartEFSC.hxx +++ b/src/emucore/CartEFSC.hxx @@ -109,12 +109,12 @@ class CartridgeEFSC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartF4.cxx b/src/emucore/CartF4.cxx index b214b4abd..d0670ad3f 100644 --- a/src/emucore/CartF4.cxx +++ b/src/emucore/CartF4.cxx @@ -146,7 +146,7 @@ uInt8* CartridgeF4::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF4::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -168,9 +168,9 @@ bool CartridgeF4::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF4::load(Deserializer& in) +bool CartridgeF4::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartF4.hxx b/src/emucore/CartF4.hxx index fd12c679f..0a31e7c4a 100644 --- a/src/emucore/CartF4.hxx +++ b/src/emucore/CartF4.hxx @@ -105,12 +105,12 @@ class CartridgeF4 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartF4SC.cxx b/src/emucore/CartF4SC.cxx index fd6824ec9..a462e6461 100644 --- a/src/emucore/CartF4SC.cxx +++ b/src/emucore/CartF4SC.cxx @@ -187,7 +187,7 @@ uInt8* CartridgeF4SC::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF4SC::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -215,9 +215,9 @@ bool CartridgeF4SC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF4SC::load(Deserializer& in) +bool CartridgeF4SC::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartF4SC.hxx b/src/emucore/CartF4SC.hxx index ddf008451..cd12adc17 100644 --- a/src/emucore/CartF4SC.hxx +++ b/src/emucore/CartF4SC.hxx @@ -105,12 +105,12 @@ class CartridgeF4SC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartF6.cxx b/src/emucore/CartF6.cxx index 4509188b7..d2cf212bc 100644 --- a/src/emucore/CartF6.cxx +++ b/src/emucore/CartF6.cxx @@ -20,8 +20,6 @@ #include #include "System.hxx" -#include "Serializer.hxx" -#include "Deserializer.hxx" #include "CartF6.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -189,7 +187,7 @@ uInt8* CartridgeF6::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF6::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -212,9 +210,9 @@ bool CartridgeF6::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF6::load(Deserializer& in) +bool CartridgeF6::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartF6.hxx b/src/emucore/CartF6.hxx index 39efba609..d4259b8ef 100644 --- a/src/emucore/CartF6.hxx +++ b/src/emucore/CartF6.hxx @@ -105,12 +105,12 @@ class CartridgeF6 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartF6SC.cxx b/src/emucore/CartF6SC.cxx index 163f33e21..69e5e4a5b 100644 --- a/src/emucore/CartF6SC.cxx +++ b/src/emucore/CartF6SC.cxx @@ -227,7 +227,7 @@ uInt8* CartridgeF6SC::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF6SC::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -256,9 +256,9 @@ bool CartridgeF6SC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF6SC::load(Deserializer& in) +bool CartridgeF6SC::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartF6SC.hxx b/src/emucore/CartF6SC.hxx index fe9693494..33aa88979 100644 --- a/src/emucore/CartF6SC.hxx +++ b/src/emucore/CartF6SC.hxx @@ -105,12 +105,12 @@ class CartridgeF6SC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartF8.cxx b/src/emucore/CartF8.cxx index 20c824ebb..6dcd5ca40 100644 --- a/src/emucore/CartF8.cxx +++ b/src/emucore/CartF8.cxx @@ -171,7 +171,7 @@ uInt8* CartridgeF8::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF8::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -194,9 +194,9 @@ bool CartridgeF8::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF8::load(Deserializer& in) +bool CartridgeF8::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartF8.hxx b/src/emucore/CartF8.hxx index 6a5398192..aa172ae47 100644 --- a/src/emucore/CartF8.hxx +++ b/src/emucore/CartF8.hxx @@ -106,12 +106,12 @@ class CartridgeF8 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartF8SC.cxx b/src/emucore/CartF8SC.cxx index 5e2254ab9..1b014c723 100644 --- a/src/emucore/CartF8SC.cxx +++ b/src/emucore/CartF8SC.cxx @@ -207,7 +207,7 @@ uInt8* CartridgeF8SC::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF8SC::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -235,9 +235,9 @@ bool CartridgeF8SC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF8SC::load(Deserializer& in) +bool CartridgeF8SC::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartF8SC.hxx b/src/emucore/CartF8SC.hxx index df07b19d4..e5eb01707 100644 --- a/src/emucore/CartF8SC.hxx +++ b/src/emucore/CartF8SC.hxx @@ -105,12 +105,12 @@ class CartridgeF8SC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartFASC.cxx b/src/emucore/CartFASC.cxx index 147cd3d28..c92a024ed 100644 --- a/src/emucore/CartFASC.cxx +++ b/src/emucore/CartFASC.cxx @@ -219,7 +219,7 @@ uInt8* CartridgeFASC::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeFASC::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -247,9 +247,9 @@ bool CartridgeFASC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeFASC::load(Deserializer& in) +bool CartridgeFASC::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartFASC.hxx b/src/emucore/CartFASC.hxx index c9b7d8c86..6997cdd0b 100644 --- a/src/emucore/CartFASC.hxx +++ b/src/emucore/CartFASC.hxx @@ -110,12 +110,12 @@ class CartridgeFASC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartFE.cxx b/src/emucore/CartFE.cxx index 36c6c7c02..821d3440f 100644 --- a/src/emucore/CartFE.cxx +++ b/src/emucore/CartFE.cxx @@ -112,7 +112,7 @@ uInt8* CartridgeFE::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeFE::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -133,9 +133,9 @@ bool CartridgeFE::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeFE::load(Deserializer& in) +bool CartridgeFE::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartFE.hxx b/src/emucore/CartFE.hxx index ea301e357..30b606927 100644 --- a/src/emucore/CartFE.hxx +++ b/src/emucore/CartFE.hxx @@ -117,12 +117,12 @@ class CartridgeFE : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartMB.cxx b/src/emucore/CartMB.cxx index 60cac656e..1692502ea 100644 --- a/src/emucore/CartMB.cxx +++ b/src/emucore/CartMB.cxx @@ -153,7 +153,7 @@ uInt8* CartridgeMB::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeMB::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -176,9 +176,9 @@ bool CartridgeMB::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeMB::load(Deserializer& in) +bool CartridgeMB::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartMB.hxx b/src/emucore/CartMB.hxx index 82ee1ff7c..a08477492 100644 --- a/src/emucore/CartMB.hxx +++ b/src/emucore/CartMB.hxx @@ -111,12 +111,12 @@ class CartridgeMB : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartMC.cxx b/src/emucore/CartMC.cxx index 3803a084f..e6a3c8696 100644 --- a/src/emucore/CartMC.cxx +++ b/src/emucore/CartMC.cxx @@ -231,7 +231,7 @@ uInt8* CartridgeMC::getImage(int& size) bool CartridgeMC::save(Serializer& out) const { uInt32 i; - string cart = name(); + const string& cart = name(); try { @@ -262,10 +262,10 @@ bool CartridgeMC::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeMC::load(Deserializer& in) +bool CartridgeMC::load(Serializer& in) { uInt32 i; - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartMC.hxx b/src/emucore/CartMC.hxx index aee389b38..f312ffd3d 100644 --- a/src/emucore/CartMC.hxx +++ b/src/emucore/CartMC.hxx @@ -212,12 +212,12 @@ class CartridgeMC : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartSB.cxx b/src/emucore/CartSB.cxx index 5a44d820d..8b9b7a643 100644 --- a/src/emucore/CartSB.cxx +++ b/src/emucore/CartSB.cxx @@ -172,7 +172,7 @@ uInt8* CartridgeSB::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeSB::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -194,9 +194,9 @@ bool CartridgeSB::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeSB::load(Deserializer& in) +bool CartridgeSB::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartSB.hxx b/src/emucore/CartSB.hxx index 1a7b445ec..43a4c5f5c 100644 --- a/src/emucore/CartSB.hxx +++ b/src/emucore/CartSB.hxx @@ -103,12 +103,12 @@ class CartridgeSB : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartUA.cxx b/src/emucore/CartUA.cxx index 30c35cddc..70bae3504 100644 --- a/src/emucore/CartUA.cxx +++ b/src/emucore/CartUA.cxx @@ -179,7 +179,7 @@ uInt8* CartridgeUA::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeUA::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -202,9 +202,9 @@ bool CartridgeUA::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeUA::load(Deserializer& in) +bool CartridgeUA::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartUA.hxx b/src/emucore/CartUA.hxx index f87157aa1..e4ba00062 100644 --- a/src/emucore/CartUA.hxx +++ b/src/emucore/CartUA.hxx @@ -106,12 +106,12 @@ class CartridgeUA : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/CartX07.cxx b/src/emucore/CartX07.cxx index cc4cfc472..9ed1e6029 100644 --- a/src/emucore/CartX07.cxx +++ b/src/emucore/CartX07.cxx @@ -165,7 +165,7 @@ uInt8* CartridgeX07::getImage(int& size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeX07::save(Serializer& out) const { - string cart = name(); + const string& cart = name(); try { @@ -187,9 +187,9 @@ bool CartridgeX07::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeX07::load(Deserializer& in) +bool CartridgeX07::load(Serializer& in) { - string cart = name(); + const string& cart = name(); try { diff --git a/src/emucore/CartX07.hxx b/src/emucore/CartX07.hxx index ce41bb526..7765643ce 100644 --- a/src/emucore/CartX07.hxx +++ b/src/emucore/CartX07.hxx @@ -115,12 +115,12 @@ class CartridgeX07 : public Cartridge virtual bool save(Serializer& out) const; /** - Load the current state of this cart from the given Deserializer. + Load the current state of this cart from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 99722b2ef..d95820537 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -219,7 +219,7 @@ bool Console::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Console::load(Deserializer& in) +bool Console::load(Serializer& in) { try { diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index e5fca8c03..dab61a0ac 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -142,12 +142,12 @@ class Console : public Serializable bool save(Serializer& out) const; /** - Loads the current state of this console class from the given Deserializer. + Loads the current state of this console class from the given Serializer. - @param in The deserializer device to load from. + @param in The Serializer device to load from. @return The result of the load. True on success, false on failure. */ - bool load(Deserializer& in); + bool load(Serializer& in); /** Get a descriptor for this console class (used in error checking). diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 9839ef61f..4a06da637 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -143,7 +143,7 @@ bool Controller::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Controller::load(Deserializer& in) +bool Controller::load(Serializer& in) { try { diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 528d70a4d..b0b669977 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -174,12 +174,12 @@ class Controller : public Serializable virtual bool save(Serializer& out) const; /** - Loads the current state of this controller from the given Deserializer. + Loads the current state of this controller from the given Serializer. - @param in The deserializer device to load from. + @param in The serializer device to load from. @return The result of the load. True on success, false on failure. */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Returns the name of this controller. diff --git a/src/emucore/M6532.cxx b/src/emucore/M6532.cxx index 11e991de8..bd56c5fdf 100644 --- a/src/emucore/M6532.cxx +++ b/src/emucore/M6532.cxx @@ -23,8 +23,6 @@ #include "Random.hxx" #include "Switches.hxx" #include "System.hxx" -#include "Serializer.hxx" -#include "Deserializer.hxx" #include "M6532.hxx" @@ -298,7 +296,7 @@ void M6532::setPinState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool M6532::save(Serializer& out) const { - string device = name(); + const string& device = name(); try { @@ -338,9 +336,9 @@ bool M6532::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool M6532::load(Deserializer& in) +bool M6532::load(Serializer& in) { - string device = name(); + const string& device = name(); try { diff --git a/src/emucore/M6532.hxx b/src/emucore/M6532.hxx index e8a414995..8a0eeea83 100644 --- a/src/emucore/M6532.hxx +++ b/src/emucore/M6532.hxx @@ -21,8 +21,6 @@ class Console; class RiotDebug; -class Serializer; -class Deserializer; #include "bspf.hxx" #include "Device.hxx" @@ -96,12 +94,12 @@ class M6532 : public Device virtual bool save(Serializer& out) const; /** - Load the current state of this device from the given Deserializer. + Load the current state of this device from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in); + virtual bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 335c960da..a0368ce18 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -16,6 +16,7 @@ // $Id$ //============================================================================ +#include #include #include diff --git a/src/emucore/Serializable.hxx b/src/emucore/Serializable.hxx index 874ab5895..06a66fd14 100644 --- a/src/emucore/Serializable.hxx +++ b/src/emucore/Serializable.hxx @@ -20,7 +20,6 @@ #define SERIALIZABLE_HXX #include "Serializer.hxx" -#include "Deserializer.hxx" /** This class provides an interface for (de)serializing objects. @@ -45,12 +44,12 @@ class Serializable virtual bool save(Serializer& out) const = 0; /** - Load the current state of the object from the given Deserializer. + Load the current state of the object from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in) = 0; + virtual bool load(Serializer& in) = 0; /** Get a descriptor for the object name (used in error checking). diff --git a/src/emucore/Serializer.cxx b/src/emucore/Serializer.cxx index 4437072da..97ebc5bb9 100644 --- a/src/emucore/Serializer.cxx +++ b/src/emucore/Serializer.cxx @@ -16,39 +16,125 @@ // $Id$ //============================================================================ +#include +#include + #include "Serializer.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Serializer::Serializer(void) +Serializer::Serializer(const string& filename) + : myStream(NULL), + myUseFilestream(true) { + // When using fstreams, we need to manually create the file first + // if we want to use it in read/write mode, since it won't be created + // if it doesn't already exist + // However, if it *does* exist, we don't want to overwrite it + // So we open in write and append mode - the write creates the file + // when necessary, and the append doesn't delete any data if it + // already exists + fstream temp(filename.c_str(), ios::out | ios::app); + temp.close(); + + fstream* str = new fstream(filename.c_str(), ios::in | ios::out | ios::binary); + if(str && str->is_open()) + { + myStream = str; + reset(); + } + else + delete str; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Serializer::Serializer(void) + : myStream(NULL), + myUseFilestream(false) +{ + myStream = new stringstream(ios::in | ios::out | ios::binary); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Serializer::~Serializer(void) { - close(); + if(myStream != NULL) + { + if(myUseFilestream) + ((fstream*)myStream)->close(); + + delete myStream; + myStream = NULL; + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Serializer::open(const string& fileName) +bool Serializer::isValid(void) { - close(); - myStream.open(fileName.c_str(), ios::out | ios::binary); - - return isOpen(); + return myStream != NULL; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Serializer::close(void) +void Serializer::reset(void) { - myStream.close(); - myStream.clear(); + myStream->seekg(ios_base::beg); + myStream->seekp(ios_base::beg); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Serializer::isOpen(void) +char Serializer::getByte(void) { - return myStream.is_open(); + if(myStream->eof()) + throw "Serializer::getByte() end of file"; + + char buf; + myStream->read(&buf, 1); + + return buf; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int Serializer::getInt(void) +{ + if(myStream->eof()) + throw "Serializer::getInt() end of file"; + + int val = 0; + unsigned char buf[4]; + myStream->read((char*)buf, 4); + for(int i = 0; i < 4; ++i) + val += (int)(buf[i]) << (i<<3); + + return val; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string Serializer::getString(void) +{ + int len = getInt(); + string str; + str.resize((string::size_type)len); + myStream->read(&str[0], (streamsize)len); + + if(myStream->bad()) + throw "Serializer::getString() file read failed"; + + return str; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Serializer::getBool(void) +{ + bool result = false; + + char b = getByte(); + if(b == (char)TruePattern) + result = true; + else if(b == (char)FalsePattern) + result = false; + else + throw "Serializer::getBool() data corruption"; + + return result; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -56,9 +142,9 @@ void Serializer::putByte(char value) { char buf[1]; buf[0] = value; - myStream.write(buf, 1); - if(myStream.bad()) - throw "Serializer: file write failed"; + myStream->write(buf, 1); + if(myStream->bad()) + throw "Serializer::putByte() file write failed"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -68,9 +154,9 @@ void Serializer::putInt(int value) for(int i = 0; i < 4; ++i) buf[i] = (value >> (i<<3)) & 0xff; - myStream.write((char*)buf, 4); - if(myStream.bad()) - throw "Serializer: file write failed"; + myStream->write((char*)buf, 4); + if(myStream->bad()) + throw "Serializer::putInt() file write failed"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -78,10 +164,10 @@ void Serializer::putString(const string& str) { int len = str.length(); putInt(len); - myStream.write(str.data(), (streamsize)len); + myStream->write(str.data(), (streamsize)len); - if(myStream.bad()) - throw "Serializer: file write failed"; + if(myStream->bad()) + throw "Serializer::putString() file write failed"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Serializer.hxx b/src/emucore/Serializer.hxx index ba866d8e4..4c27f66a5 100644 --- a/src/emucore/Serializer.hxx +++ b/src/emucore/Serializer.hxx @@ -19,18 +19,21 @@ #ifndef SERIALIZER_HXX #define SERIALIZER_HXX -#include +#include #include "bspf.hxx" /** - This class implements a Serializer device, whereby data is - serialized and sent to an output binary file in a system- - independent way. + This class implements a Serializer device, whereby data is serialized and + read from/written to a binary stream in a system-independent way. The + stream can be either an actual file, or an in-memory structure. Bytes are written as characters, integers are written as 4 characters (32-bit), strings are written as characters prepended by the length of the string, boolean values are written using a special character pattern. + All bytes and ints should be cast to their appropriate data type upon + method return. + @author Stephen Anthony @version $Id$ */ @@ -38,11 +41,15 @@ class Serializer { public: /** - Creates a new Serializer device. + Creates a new Serializer device for streaming binary data. - Open must be called with a valid file before this Serializer can - be used. + If a filename is provided, the stream will be to the given + filename. Otherwise, the stream will be in memory. + + The isValid() method must immediately be called to verify the stream + was correctly initialized. */ + Serializer(const string& filename); Serializer(void); /** @@ -52,23 +59,43 @@ class Serializer public: /** - Opens the given file for output. Multiple calls to this method - will close previously opened files. - - @param fileName The filename to send the serialized data to. - @return Result of opening the file. True on success, false on failure + Answers whether the serializer is currently initialized for reading + and writing. */ - bool open(const string& fileName); + bool isValid(void); /** - Closes the current output stream. + Resets the read/write location to the beginning of the stream. */ - void close(void); + void reset(void); /** - Answers whether the serializer is currently opened + Reads a byte value (8-bit) from the current input stream. + + @result The char value which has been read from the stream. */ - bool isOpen(void); + char getByte(void); + + /** + Reads an int value (32-bit) from the current input stream. + + @result The int value which has been read from the stream. + */ + int getInt(void); + + /** + Reads a string from the current input stream. + + @result The string which has been read from the stream. + */ + string getString(void); + + /** + Reads a boolean value from the current input stream. + + @result The boolean value which has been read from the stream. + */ + bool getBool(void); /** Writes an byte value (8-bit) to the current output stream. @@ -100,7 +127,8 @@ class Serializer private: // The stream to send the serialized data to. - fstream myStream; + iostream* myStream; + bool myUseFilestream; enum { TruePattern = 0xfe, diff --git a/src/emucore/Sound.hxx b/src/emucore/Sound.hxx index 8a523f6cd..38113c358 100644 --- a/src/emucore/Sound.hxx +++ b/src/emucore/Sound.hxx @@ -20,9 +20,8 @@ #define SOUND_HXX class OSystem; -class Serializer; -class Deserializer; +#include "Serializable.hxx" #include "bspf.hxx" /** @@ -32,7 +31,7 @@ class Deserializer; @author Stephen Anthony @version $Id$ */ -class Sound +class Sound : public Serializable { public: /** @@ -134,23 +133,6 @@ class Sound */ virtual void adjustVolume(Int8 direction) = 0; - public: - /** - Loads the current state of this device from the given Deserializer. - - @param in The deserializer device to load from. - @return The result of the load. True on success, false on failure. - */ - virtual bool load(Deserializer& in) = 0; - - /** - Saves the current state of this device to the given Serializer. - - @param out The serializer device to save to. - @return The result of the save. True on success, false on failure. - */ - virtual bool save(Serializer& out) = 0; - protected: // The OSystem for this sound object OSystem* myOSystem; diff --git a/src/emucore/StateManager.cxx b/src/emucore/StateManager.cxx index 757ac97da..41b56dffa 100644 --- a/src/emucore/StateManager.cxx +++ b/src/emucore/StateManager.cxx @@ -19,13 +19,12 @@ #include #include "OSystem.hxx" -#include "Serializer.hxx" -#include "Deserializer.hxx" #include "Settings.hxx" #include "Console.hxx" #include "Control.hxx" #include "Switches.hxx" #include "System.hxx" +#include "Serializable.hxx" #include "StateManager.hxx" @@ -56,6 +55,7 @@ bool StateManager::isActive() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool StateManager::toggleRecordMode() { +#if 0 if(myActiveMode != kMovieRecordMode) // Turn on movie record mode { myActiveMode = kOffMode; @@ -92,13 +92,15 @@ bool StateManager::toggleRecordMode() } return myActiveMode == kMovieRecordMode; +#endif + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool StateManager::toggleRewindMode() { // FIXME - For now, I'm going to use this to activate movie playback - +#if 0 // Close the writer, since we're about to re-open in read mode myMovieWriter.close(); @@ -139,11 +141,14 @@ bool StateManager::toggleRewindMode() } return myActiveMode == kMoviePlaybackMode; +#endif + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void StateManager::update() { +#if 0 switch(myActiveMode) { case kMovieRecordMode: @@ -161,6 +166,7 @@ void StateManager::update() default: break; } +#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -178,8 +184,8 @@ void StateManager::loadState(int slot) << name << ".st" << slot; // Make sure the file can be opened for reading - Deserializer in; - if(!in.open(buf.str())) + Serializer in(buf.str()); + if(!in.isValid()) { buf.str(""); buf << "Error loading state " << slot; @@ -198,7 +204,6 @@ void StateManager::loadState(int slot) else buf << "Invalid data in state " << slot << " file"; - in.close(); myOSystem->frameBuffer().showMessage(buf.str()); } } @@ -218,8 +223,8 @@ void StateManager::saveState(int slot) << name << ".st" << slot; // Make sure the file can be opened for writing - Serializer out; - if(!out.open(buf.str())) + Serializer out(buf.str()); + if(!out.isValid()) { myOSystem->frameBuffer().showMessage("Error saving state file"); return; @@ -246,7 +251,6 @@ void StateManager::saveState(int slot) else buf << "Error saving state " << slot; - out.close(); myOSystem->frameBuffer().showMessage(buf.str()); } } @@ -262,9 +266,52 @@ void StateManager::changeState() myOSystem->frameBuffer().showMessage(buf.str()); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool StateManager::loadState(Serializer& in) +{ + if(&myOSystem->console()) + { + // Make sure the file can be opened for reading + if(in.isValid()) + { + // First test if we have a valid header + // If so, do a complete state load using the Console + const string& md5 = myOSystem->console().properties().get(Cartridge_MD5); + if(in.getString() == STATE_HEADER && in.getString() == md5 && + myOSystem->console().load(in)) + return true; + } + } + return false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool StateManager::saveState(Serializer& out) +{ + if(&myOSystem->console()) + { + // Make sure the file can be opened for writing + if(out.isValid()) + { + // Add header so that if the state format changes in the future, + // we'll know right away, without having to parse the rest of the file + out.putString(STATE_HEADER); + + // Prepend the ROM md5 so this state file only works with that ROM + out.putString(myOSystem->console().properties().get(Cartridge_MD5)); + + // Do a complete state save using the Console + if(myOSystem->console().save(out)) + return true; + } + } + return false; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void StateManager::reset() { +#if 0 myCurrentSlot = 0; switch(myActiveMode) @@ -281,6 +328,7 @@ void StateManager::reset() break; } myActiveMode = kOffMode; +#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/StateManager.hxx b/src/emucore/StateManager.hxx index 2c20952b0..d015c04bf 100644 --- a/src/emucore/StateManager.hxx +++ b/src/emucore/StateManager.hxx @@ -21,7 +21,6 @@ class OSystem; -#include "Deserializer.hxx" #include "Serializer.hxx" /** @@ -78,6 +77,26 @@ class StateManager */ void changeState(); + /** + Load a state into the current system from the given Serializer. + No messages are printed to the screen. + + @param in The Serializer object to use + + @return False on any load errors, else true + */ + bool loadState(Serializer& in); + + /** + Save the current state from the system into the given Serializer. + No messages are printed to the screen. + + @param out The Serializer object to use + + @return False on any save errors, else true + */ + bool saveState(Serializer& out); + /** Resets manager to defaults */ @@ -119,8 +138,8 @@ class StateManager string myMD5; // Serializer classes used to save/load the eventstream - Serializer myMovieWriter; - Deserializer myMovieReader; + Serializer myMovieWriter; + Serializer myMovieReader; }; #endif diff --git a/src/emucore/Switches.cxx b/src/emucore/Switches.cxx index 1683aeb07..93578a55b 100644 --- a/src/emucore/Switches.cxx +++ b/src/emucore/Switches.cxx @@ -123,7 +123,7 @@ bool Switches::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Switches::load(Deserializer& in) +bool Switches::load(Serializer& in) { try { diff --git a/src/emucore/Switches.hxx b/src/emucore/Switches.hxx index 255eed102..71fdeef78 100644 --- a/src/emucore/Switches.hxx +++ b/src/emucore/Switches.hxx @@ -74,12 +74,12 @@ class Switches : public Serializable bool save(Serializer& out) const; /** - Load the current state of the switches from the given Deserializer. + Load the current state of the switches from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - bool load(Deserializer& in); + bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/TIA.cxx b/src/emucore/TIA.cxx index a404464c5..9806894d5 100644 --- a/src/emucore/TIA.cxx +++ b/src/emucore/TIA.cxx @@ -24,9 +24,8 @@ #include "Console.hxx" #include "Control.hxx" -#include "Deserializer.hxx" +#include "Device.hxx" #include "M6502.hxx" -#include "Serializer.hxx" #include "Settings.hxx" #include "Sound.hxx" #include "System.hxx" @@ -288,7 +287,7 @@ void TIA::install(System& system, Device& device) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::save(Serializer& out) const { - string device = name(); + const string& device = name(); try { @@ -338,12 +337,6 @@ bool TIA::save(Serializer& out) const out.putBool(myRESMP0); out.putBool(myRESMP1); out.putInt(myCollision); - out.putInt(myPOSP0); - out.putInt(myPOSP1); - out.putInt(myPOSM0); - out.putInt(myPOSM1); - out.putInt(myPOSBL); - out.putByte((char)myCurrentGRP0); out.putByte((char)myCurrentGRP1); @@ -358,9 +351,11 @@ bool TIA::save(Serializer& out) const out.putBool(myDumpEnabled); out.putInt(myDumpDisabledCycle); - out.putInt(myFrameCounter); - out.putBool(myPartialFrameFlag); - out.putBool(myFrameGreyed); + out.putInt(myPOSP0); + out.putInt(myPOSP1); + out.putInt(myPOSM0); + out.putInt(myPOSM1); + out.putInt(myPOSBL); out.putInt(myMotionClockP0); out.putInt(myMotionClockP1); @@ -378,6 +373,8 @@ bool TIA::save(Serializer& out) const out.putInt(myPreviousHMOVEPos); out.putBool(myHMOVEBlankEnabled); + out.putInt(myFrameCounter); + // Save the sound sample stuff ... mySound.save(out); } @@ -396,9 +393,9 @@ bool TIA::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool TIA::load(Deserializer& in) +bool TIA::load(Serializer& in) { - string device = name(); + const string& device = name(); try { @@ -449,12 +446,6 @@ bool TIA::load(Deserializer& in) myRESMP0 = in.getBool(); myRESMP1 = in.getBool(); myCollision = (uInt16) in.getInt(); - myPOSP0 = (Int16) in.getInt(); - myPOSP1 = (Int16) in.getInt(); - myPOSM0 = (Int16) in.getInt(); - myPOSM1 = (Int16) in.getInt(); - myPOSBL = (Int16) in.getInt(); - myCurrentGRP0 = (uInt8) in.getByte(); myCurrentGRP1 = (uInt8) in.getByte(); @@ -469,9 +460,11 @@ bool TIA::load(Deserializer& in) myDumpEnabled = in.getBool(); myDumpDisabledCycle = (Int32) in.getInt(); - myFrameCounter = (Int32) in.getInt(); - myPartialFrameFlag = in.getBool(); - myFrameGreyed = in.getBool(); + myPOSP0 = (Int16) in.getInt(); + myPOSP1 = (Int16) in.getInt(); + myPOSM0 = (Int16) in.getInt(); + myPOSM1 = (Int16) in.getInt(); + myPOSBL = (Int16) in.getInt(); myMotionClockP0 = (Int32) in.getInt(); myMotionClockP1 = (Int32) in.getInt(); @@ -489,6 +482,8 @@ bool TIA::load(Deserializer& in) myPreviousHMOVEPos = (Int32) in.getInt(); myHMOVEBlankEnabled = in.getBool(); + myFrameCounter = (Int32) in.getInt(); + // Load the sound sample stuff ... mySound.load(in); @@ -509,6 +504,67 @@ bool TIA::load(Deserializer& in) return true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool TIA::saveDisplay(Serializer& out) const +{ + try + { + out.putBool(myPartialFrameFlag); + out.putInt(myFramePointerClocks); + + for(int i = 0; i < 160*320; ++i) + out.putByte(myCurrentFrameBuffer[i]); + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in save state for TIA display" << endl; + return false; + } + + return true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool TIA::loadDisplay(Serializer& in) +{ + try + { + myPartialFrameFlag = in.getBool(); + myFramePointerClocks = (uInt32) in.getInt(); + + // Reset frame buffer pointer and data + clearBuffers(); + myFramePointer = myCurrentFrameBuffer; + for(int i = 0; i < 160*320; ++i) + myCurrentFrameBuffer[i] = (uInt8) in.getByte(); + + // If we're in partial frame mode, make sure to re-create the screen + // as it existed when the state was saved + if(myPartialFrameFlag) + { + myFramePointer += myFramePointerClocks; + myFrameGreyed = true; + } + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in load state for TIA display" << endl; + return false; + } + + return true; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::update() { @@ -563,6 +619,7 @@ inline void TIA::startFrame() // Reset frame buffer pointer myFramePointer = myCurrentFrameBuffer; + myFramePointerClocks = 0; // If color loss is enabled then update the color registers based on // the number of scanlines in the last frame that was generated @@ -700,6 +757,7 @@ inline void TIA::updateFrameScanline(uInt32 clocksToUpdate, uInt32 hpos) { // Calculate the ending frame pointer value uInt8* ending = myFramePointer + clocksToUpdate; + myFramePointerClocks += clocksToUpdate; // See if we're in the vertical blank region if(myVBLANK & 0x02) @@ -1441,8 +1499,13 @@ inline void TIA::waitHorizontalSync() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::greyOutFrame() { +cerr << "greyOutFrame(): scanlines = " << scanlines() << endl; uInt32 c = scanlines(); if(c < myFrameYStart) c = myFrameYStart; + if(c > (myFrameHeight + myFrameYStart)) + return; + +cerr << "greying frame from scanline " << c << endl; uInt8* buffer = myCurrentFrameBuffer + myFramePointerOffset; for(uInt32 s = c; s < (myFrameHeight + myFrameYStart); ++s) diff --git a/src/emucore/TIA.hxx b/src/emucore/TIA.hxx index 2092141db..52e081949 100644 --- a/src/emucore/TIA.hxx +++ b/src/emucore/TIA.hxx @@ -106,12 +106,34 @@ class TIA : public Device bool save(Serializer& out) const; /** - Load the current state of this device from the given Deserializer. + Load the current state of this device from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - bool load(Deserializer& in); + bool load(Serializer& in); + + /** + The following are very similar to save() and load(), except they + do a 'deeper' save of the display data itself. + + Normally, the internal framebuffer doesn't need to be saved to + a state file, since the file already contains all the information + needed to re-create it, starting from scanline 0. In effect, when a + state is loaded, the framebuffer is empty, and the next call to + update() generates valid framebuffer data. + + However, state files saved from the debugger need more information, + such as the exact state of the internal framebuffer itself *before* + we call update(), including if the display was in partial frame mode. + + Essentially, a normal state save has 'frame resolution', whereas + the debugger state save has 'cycle resolution', and hence needs + more information. The methods below save/load this extra info, + and eliminate having to save approx. 50K to normal state files. + */ + bool saveDisplay(Serializer& out) const; + bool loadDisplay(Serializer& in); /** Get a descriptor for the device name (used in error checking). @@ -302,6 +324,11 @@ class TIA : public Device // (the exported frame buffer is a vertical 'sliding window' of the actual buffer) uInt32 myFramePointerOffset; + // Indicates the number of 'colour clocks' offset from the base + // frame buffer pointer + // (this is used when loading state files with a 'partial' frame) + uInt32 myFramePointerClocks; + // Indicates the width of the visible scanline uInt32 myFrameWidth; diff --git a/src/emucore/TIASnd.cxx b/src/emucore/TIASnd.cxx index 7d599e522..5222b435c 100644 --- a/src/emucore/TIASnd.cxx +++ b/src/emucore/TIASnd.cxx @@ -107,7 +107,7 @@ void TIASound::set(uInt16 address, uInt8 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 TIASound::get(uInt16 address) +uInt8 TIASound::get(uInt16 address) const { switch(address) { diff --git a/src/emucore/TIASnd.hxx b/src/emucore/TIASnd.hxx index 5589713c5..6d3057177 100644 --- a/src/emucore/TIASnd.hxx +++ b/src/emucore/TIASnd.hxx @@ -82,7 +82,7 @@ class TIASound @param address Register address */ - uInt8 get(uInt16 address); + uInt8 get(uInt16 address) const; /** Create sound samples based on the current sound register settings diff --git a/src/emucore/m6502/src/Device.hxx b/src/emucore/m6502/src/Device.hxx index f6a490581..618084579 100644 --- a/src/emucore/m6502/src/Device.hxx +++ b/src/emucore/m6502/src/Device.hxx @@ -74,12 +74,12 @@ class Device : public Serializable virtual bool save(Serializer& out) const = 0; /** - Load the current state of this device from the given Deserializer. + Load the current state of this device from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - virtual bool load(Deserializer& in) = 0; + virtual bool load(Serializer& in) = 0; /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/m6502/src/M6502.cxx b/src/emucore/m6502/src/M6502.cxx index 784f19036..0a5832e0d 100644 --- a/src/emucore/m6502/src/M6502.cxx +++ b/src/emucore/m6502/src/M6502.cxx @@ -19,9 +19,6 @@ //#define DEBUG_OUTPUT #define debugStream cout -#include "Serializer.hxx" -#include "Deserializer.hxx" - #ifdef DEBUGGER_SUPPORT #include "Debugger.hxx" #include "Expression.hxx" @@ -334,9 +331,9 @@ void M6502::interruptHandler() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool M6502::save(Serializer& out) +bool M6502::save(Serializer& out) const { - string CPU = name(); + const string& CPU = name(); try { @@ -380,9 +377,9 @@ bool M6502::save(Serializer& out) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool M6502::load(Deserializer& in) +bool M6502::load(Serializer& in) { - string CPU = name(); + const string& CPU = name(); try { diff --git a/src/emucore/m6502/src/M6502.hxx b/src/emucore/m6502/src/M6502.hxx index 9b6bb7731..bc16aa6a3 100644 --- a/src/emucore/m6502/src/M6502.hxx +++ b/src/emucore/m6502/src/M6502.hxx @@ -21,8 +21,6 @@ class D6502; class M6502; -class Serializer; -class Deserializer; class Debugger; class CpuDebug; class Expression; @@ -32,6 +30,7 @@ class PackedBitArray; #include "System.hxx" #include "Array.hxx" #include "StringList.hxx" +#include "Serializable.hxx" typedef Common::Array ExpressionList; @@ -48,7 +47,7 @@ typedef Common::Array ExpressionList; @author Bradford W. Mott @version $Id$ */ -class M6502 +class M6502 : public Serializable { public: /** @@ -183,22 +182,22 @@ class M6502 @param out The serializer device to save to. @return The result of the save. True on success, false on failure. */ - bool save(Serializer& out); + bool save(Serializer& out) const; /** - Loads the current state of this device from the given Deserializer. + Loads the current state of this device from the given Serializer. - @param in The deserializer device to load from. + @param in The Serializer device to load from. @return The result of the load. True on success, false on failure. */ - bool load(Deserializer& in); + bool load(Serializer& in); /** Get a null terminated string which is the processor's name (i.e. "M6532") @return The name of the device */ - const char* name() const { return "M6502High"; } + string name() const { return "M6502"; } public: /** diff --git a/src/emucore/m6502/src/NullDev.cxx b/src/emucore/m6502/src/NullDev.cxx index f064b5b98..4ec739138 100644 --- a/src/emucore/m6502/src/NullDev.cxx +++ b/src/emucore/m6502/src/NullDev.cxx @@ -16,9 +16,8 @@ // $Id$ //============================================================================ -#include "NullDev.hxx" #include "Serializer.hxx" -#include "Deserializer.hxx" +#include "NullDev.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NullDevice::NullDevice() @@ -61,7 +60,7 @@ bool NullDevice::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool NullDevice::load(Deserializer& in) +bool NullDevice::load(Serializer& in) { return true; } diff --git a/src/emucore/m6502/src/NullDev.hxx b/src/emucore/m6502/src/NullDev.hxx index 96e849126..b592d32b6 100644 --- a/src/emucore/m6502/src/NullDev.hxx +++ b/src/emucore/m6502/src/NullDev.hxx @@ -20,8 +20,6 @@ #define NULLDEVICE_HXX class System; -class Serializer; -class Deserializer; #include "bspf.hxx" #include "Device.hxx" @@ -70,12 +68,12 @@ class NullDevice : public Device bool save(Serializer& out) const; /** - Load the current state of this device from the given Deserializer. + Load the current state of this device from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - bool load(Deserializer& in); + bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/m6502/src/System.cxx b/src/emucore/m6502/src/System.cxx index f21758617..aaf9e935b 100644 --- a/src/emucore/m6502/src/System.cxx +++ b/src/emucore/m6502/src/System.cxx @@ -274,7 +274,7 @@ bool System::save(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool System::load(Deserializer& in) +bool System::load(Serializer& in) { const string& device = name(); try diff --git a/src/emucore/m6502/src/System.hxx b/src/emucore/m6502/src/System.hxx index 4738d7fc7..86e3f3e99 100644 --- a/src/emucore/m6502/src/System.hxx +++ b/src/emucore/m6502/src/System.hxx @@ -307,12 +307,12 @@ class System : public Serializable bool save(Serializer& out) const; /** - Load the current state of this system from the given Deserializer. + Load the current state of this system from the given Serializer. - @param in The Deserializer object to use + @param in The Serializer object to use @return False on any errors, else true */ - bool load(Deserializer& in); + bool load(Serializer& in); /** Get a descriptor for the device name (used in error checking). diff --git a/src/emucore/module.mk b/src/emucore/module.mk index 432a954f7..6b6c96ffb 100644 --- a/src/emucore/module.mk +++ b/src/emucore/module.mk @@ -32,7 +32,6 @@ MODULE_OBJS := \ src/emucore/CartX07.o \ src/emucore/Console.o \ src/emucore/Control.o \ - src/emucore/Deserializer.o \ src/emucore/Driving.o \ src/emucore/Event.o \ src/emucore/EventHandler.o \ diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index e5596c75e..570d69791 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -98,7 +98,7 @@ bool EditableWidget::handleKeyDown(int ascii, int keycode, int modifiers) bool handled = true; bool dirty = false; - switch (keycode) + switch (ascii) { case '\n': // enter/return case '\r': diff --git a/src/wince/SoundWinCE.cxx b/src/wince/SoundWinCE.cxx index ed84769a2..35ee64920 100644 --- a/src/wince/SoundWinCE.cxx +++ b/src/wince/SoundWinCE.cxx @@ -21,8 +21,6 @@ #include "TIASnd.hxx" #include "FrameBuffer.hxx" -#include "Serializer.hxx" -#include "Deserializer.hxx" #include "Settings.hxx" #include "System.hxx" #include "OSystem.hxx" @@ -318,7 +316,7 @@ void SoundWinCE::update(void) } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SoundWinCE::load(Deserializer& in) +bool SoundWinCE::load(Serializer& in) { return true; } diff --git a/src/wince/SoundWinCE.hxx b/src/wince/SoundWinCE.hxx index 78d195758..304b937fe 100644 --- a/src/wince/SoundWinCE.hxx +++ b/src/wince/SoundWinCE.hxx @@ -53,7 +53,7 @@ class SoundWinCE : public Sound void set(uInt16 addr, uInt8 value, Int32 cycle); void setVolume(Int32 percent); void adjustVolume(Int8 direction); - bool load(Deserializer& in); + bool load(Serializer& in); bool save(Serializer& out); void update(void);