From 2f16788aaa4fe3a1e74c86bed72899d0eb4707a6 Mon Sep 17 00:00:00 2001 From: stephena Date: Thu, 29 Dec 2005 21:16:28 +0000 Subject: [PATCH] Fixed errors in state/eventstream loading and saving; it should now be much more robust. Updated VC.net project with latest files. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@934 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/Deserializer.cxx | 3 +- stella/src/emucore/EventHandler.cxx | 10 ++- stella/src/emucore/EventStreamer.cxx | 57 +++++++++++---- stella/src/emucore/Serializer.cxx | 3 +- stella/src/emucore/m6502/src/System.cxx | 94 ++++++++++++++++--------- stella/src/win32/Stella.vcproj | 6 ++ 6 files changed, 121 insertions(+), 52 deletions(-) diff --git a/stella/src/emucore/Deserializer.cxx b/stella/src/emucore/Deserializer.cxx index 3cc0b92c7..b65dedbc0 100644 --- a/stella/src/emucore/Deserializer.cxx +++ b/stella/src/emucore/Deserializer.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: Deserializer.cxx,v 1.9 2005-12-18 22:28:05 stephena Exp $ +// $Id: Deserializer.cxx,v 1.10 2005-12-29 21:16:26 stephena Exp $ //============================================================================ #include "Deserializer.hxx" @@ -42,6 +42,7 @@ bool Deserializer::open(const string& fileName) void Deserializer::close(void) { myStream.close(); + myStream.clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index 679fd9fda..870d11cc7 100644 --- a/stella/src/emucore/EventHandler.cxx +++ b/stella/src/emucore/EventHandler.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: EventHandler.cxx,v 1.137 2005-12-29 01:40:41 stephena Exp $ +// $Id: EventHandler.cxx,v 1.138 2005-12-29 21:16:26 stephena Exp $ //============================================================================ #include @@ -452,13 +452,15 @@ void EventHandler::poll(uInt32 time) { if(myEventStreamer->stopRecording()) myOSystem->frameBuffer().showMessage("Recording stopped"); + else + myOSystem->frameBuffer().showMessage("Stop recording error"); } else { if(myEventStreamer->startRecording()) myOSystem->frameBuffer().showMessage("Recording started"); else - myOSystem->frameBuffer().showMessage("Error opening eventstream"); + myOSystem->frameBuffer().showMessage("Start recording error"); } return; break; @@ -466,6 +468,8 @@ void EventHandler::poll(uInt32 time) case SDLK_l: // Alt-l loads a recording if(myEventStreamer->loadRecording()) myOSystem->frameBuffer().showMessage("Playing recording"); + else + myOSystem->frameBuffer().showMessage("Playing recording error"); return; break; //////////////////////////////////////////////////////////////////////// @@ -1572,7 +1576,7 @@ void EventHandler::saveState() if(myOSystem->console().system().saveState(md5, out)) buf << "State " << myLSState << " saved"; else - buf << "Invalid state " << myLSState << " file"; + buf << "Error saving state " << myLSState; out.close(); myOSystem->frameBuffer().showMessage(buf.str()); diff --git a/stella/src/emucore/EventStreamer.cxx b/stella/src/emucore/EventStreamer.cxx index 635871cf8..23b2b4881 100644 --- a/stella/src/emucore/EventStreamer.cxx +++ b/stella/src/emucore/EventStreamer.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: EventStreamer.cxx,v 1.2 2005-12-29 01:25:07 stephena Exp $ +// $Id: EventStreamer.cxx,v 1.3 2005-12-29 21:16:28 stephena Exp $ //============================================================================ #include "bspf.hxx" @@ -53,7 +53,8 @@ bool EventStreamer::startRecording() // And save the current state to it string md5 = myOSystem->console().properties().get("Cartridge.MD5"); - myOSystem->console().system().saveState(md5, myStreamWriter); + if(!myOSystem->console().system().saveState(md5, myStreamWriter)) + return false; myEventHistory.clear(); myEventWriteFlag = true; @@ -70,10 +71,24 @@ bool EventStreamer::stopRecording() // Append the event history to the eventstream int size = myEventHistory.size(); - myStreamWriter.putString("EventStream"); - myStreamWriter.putInt(size); - for(int i = 0; i < size; ++i) - myStreamWriter.putInt(myEventHistory[i]); + + try + { + myStreamWriter.putString("EventStream"); + myStreamWriter.putInt(size); + for(int i = 0; i < size; ++i) + myStreamWriter.putInt(myEventHistory[i]); + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Error saving eventstream" << endl; + return false; + } myStreamWriter.close(); return true; @@ -88,16 +103,30 @@ bool EventStreamer::loadRecording() // Load ROM state string md5 = myOSystem->console().properties().get("Cartridge.MD5"); - myOSystem->console().system().loadState(md5, myStreamReader); - - if(myStreamReader.getString() != "EventStream") + if(!myOSystem->console().system().loadState(md5, myStreamReader)) return false; - // Now load the event stream - myEventHistory.clear(); - int size = myStreamReader.getInt(); - for(int i = 0; i < size; ++i) - myEventHistory.push_back(myStreamReader.getInt()); + try + { + if(myStreamReader.getString() != "EventStream") + return false; + + // Now load the event stream + myEventHistory.clear(); + int size = myStreamReader.getInt(); + for(int i = 0; i < size; ++i) + myEventHistory.push_back(myStreamReader.getInt()); + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Error loading eventstream" << endl; + return false; + } myEventWriteFlag = false; myEventReadFlag = myEventHistory.size() > 0; diff --git a/stella/src/emucore/Serializer.cxx b/stella/src/emucore/Serializer.cxx index a4d182a2c..14129fc20 100644 --- a/stella/src/emucore/Serializer.cxx +++ b/stella/src/emucore/Serializer.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: Serializer.cxx,v 1.8 2005-12-17 22:48:24 stephena Exp $ +// $Id: Serializer.cxx,v 1.9 2005-12-29 21:16:28 stephena Exp $ //============================================================================ #include "Serializer.hxx" @@ -42,6 +42,7 @@ bool Serializer::open(const string& fileName) void Serializer::close(void) { myStream.close(); + myStream.clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/m6502/src/System.cxx b/stella/src/emucore/m6502/src/System.cxx index dffd83a56..39b95373e 100644 --- a/stella/src/emucore/m6502/src/System.cxx +++ b/stella/src/emucore/m6502/src/System.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: System.cxx,v 1.15 2005-12-17 01:23:07 stephena Exp $ +// $Id: System.cxx,v 1.16 2005-12-29 21:16:28 stephena Exp $ //============================================================================ #include @@ -209,23 +209,36 @@ bool System::saveState(const string& md5sum, Serializer& out) if(!out.isOpen()) return false; - // Prepend the state file with the md5sum of this cartridge - // This is the first defensive check for an invalid state file - out.putString(md5sum); + try + { + // Prepend the state file with the md5sum of this cartridge + // This is the first defensive check for an invalid state file + out.putString(md5sum); - // First save state for this system - if(!save(out)) - return false; - - // Next, save state for the CPU - if(!myM6502->save(out)) - return false; - - // Now save the state of each device - for(uInt32 i = 0; i < myNumberOfDevices; ++i) - if(!myDevices[i]->save(out)) + // First save state for this system + if(!save(out)) return false; + // Next, save state for the CPU + if(!myM6502->save(out)) + return false; + + // Now save the state of each device + for(uInt32 i = 0; i < myNumberOfDevices; ++i) + if(!myDevices[i]->save(out)) + return false; + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in save state for \'System\'" << endl; + return false; + } + return true; // success } @@ -236,24 +249,37 @@ bool System::loadState(const string& md5sum, Deserializer& in) if(!in.isOpen()) return false; - // Look at the beginning of the state file. It should contain the md5sum - // of the current cartridge. If it doesn't, this state file is invalid. - if(in.getString() != md5sum) - return false; - - // First load state for this system - if(!load(in)) - return false; - - // Next, load state for the CPU - if(!myM6502->load(in)) - return false; - - // Now load the state of each device - for(uInt32 i = 0; i < myNumberOfDevices; ++i) - if(!myDevices[i]->load(in)) + try + { + // Look at the beginning of the state file. It should contain the md5sum + // of the current cartridge. If it doesn't, this state file is invalid. + if(in.getString() != md5sum) return false; + // First load state for this system + if(!load(in)) + return false; + + // Next, load state for the CPU + if(!myM6502->load(in)) + return false; + + // Now load the state of each device + for(uInt32 i = 0; i < myNumberOfDevices; ++i) + if(!myDevices[i]->load(in)) + return false; + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in load state for \'System\'" << endl; + return false; + } + return true; // success } @@ -318,12 +344,14 @@ void System::poke(uInt16 addr, uInt8 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void System::lockDataBus() { +void System::lockDataBus() +{ myDataBusLocked = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void System::unlockDataBus() { +void System::unlockDataBus() +{ myDataBusLocked = false; } diff --git a/stella/src/win32/Stella.vcproj b/stella/src/win32/Stella.vcproj index d35a4caba..4d8718076 100755 --- a/stella/src/win32/Stella.vcproj +++ b/stella/src/win32/Stella.vcproj @@ -322,6 +322,9 @@ opengl32.lib" + + @@ -807,6 +810,9 @@ opengl32.lib" + +