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
This commit is contained in:
stephena 2005-12-29 21:16:28 +00:00
parent 98c94e4b24
commit 2f16788aaa
6 changed files with 121 additions and 52 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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" #include "Deserializer.hxx"
@ -42,6 +42,7 @@ bool Deserializer::open(const string& fileName)
void Deserializer::close(void) void Deserializer::close(void)
{ {
myStream.close(); myStream.close();
myStream.clear();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <sstream> #include <sstream>
@ -452,13 +452,15 @@ void EventHandler::poll(uInt32 time)
{ {
if(myEventStreamer->stopRecording()) if(myEventStreamer->stopRecording())
myOSystem->frameBuffer().showMessage("Recording stopped"); myOSystem->frameBuffer().showMessage("Recording stopped");
else
myOSystem->frameBuffer().showMessage("Stop recording error");
} }
else else
{ {
if(myEventStreamer->startRecording()) if(myEventStreamer->startRecording())
myOSystem->frameBuffer().showMessage("Recording started"); myOSystem->frameBuffer().showMessage("Recording started");
else else
myOSystem->frameBuffer().showMessage("Error opening eventstream"); myOSystem->frameBuffer().showMessage("Start recording error");
} }
return; return;
break; break;
@ -466,6 +468,8 @@ void EventHandler::poll(uInt32 time)
case SDLK_l: // Alt-l loads a recording case SDLK_l: // Alt-l loads a recording
if(myEventStreamer->loadRecording()) if(myEventStreamer->loadRecording())
myOSystem->frameBuffer().showMessage("Playing recording"); myOSystem->frameBuffer().showMessage("Playing recording");
else
myOSystem->frameBuffer().showMessage("Playing recording error");
return; return;
break; break;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -1572,7 +1576,7 @@ void EventHandler::saveState()
if(myOSystem->console().system().saveState(md5, out)) if(myOSystem->console().system().saveState(md5, out))
buf << "State " << myLSState << " saved"; buf << "State " << myLSState << " saved";
else else
buf << "Invalid state " << myLSState << " file"; buf << "Error saving state " << myLSState;
out.close(); out.close();
myOSystem->frameBuffer().showMessage(buf.str()); myOSystem->frameBuffer().showMessage(buf.str());

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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" #include "bspf.hxx"
@ -53,7 +53,8 @@ bool EventStreamer::startRecording()
// And save the current state to it // And save the current state to it
string md5 = myOSystem->console().properties().get("Cartridge.MD5"); 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(); myEventHistory.clear();
myEventWriteFlag = true; myEventWriteFlag = true;
@ -70,10 +71,24 @@ bool EventStreamer::stopRecording()
// Append the event history to the eventstream // Append the event history to the eventstream
int size = myEventHistory.size(); int size = myEventHistory.size();
try
{
myStreamWriter.putString("EventStream"); myStreamWriter.putString("EventStream");
myStreamWriter.putInt(size); myStreamWriter.putInt(size);
for(int i = 0; i < size; ++i) for(int i = 0; i < size; ++i)
myStreamWriter.putInt(myEventHistory[i]); myStreamWriter.putInt(myEventHistory[i]);
}
catch(char *msg)
{
cerr << msg << endl;
return false;
}
catch(...)
{
cerr << "Error saving eventstream" << endl;
return false;
}
myStreamWriter.close(); myStreamWriter.close();
return true; return true;
@ -88,8 +103,11 @@ bool EventStreamer::loadRecording()
// Load ROM state // Load ROM state
string md5 = myOSystem->console().properties().get("Cartridge.MD5"); string md5 = myOSystem->console().properties().get("Cartridge.MD5");
myOSystem->console().system().loadState(md5, myStreamReader); if(!myOSystem->console().system().loadState(md5, myStreamReader))
return false;
try
{
if(myStreamReader.getString() != "EventStream") if(myStreamReader.getString() != "EventStream")
return false; return false;
@ -98,6 +116,17 @@ bool EventStreamer::loadRecording()
int size = myStreamReader.getInt(); int size = myStreamReader.getInt();
for(int i = 0; i < size; ++i) for(int i = 0; i < size; ++i)
myEventHistory.push_back(myStreamReader.getInt()); myEventHistory.push_back(myStreamReader.getInt());
}
catch(char *msg)
{
cerr << msg << endl;
return false;
}
catch(...)
{
cerr << "Error loading eventstream" << endl;
return false;
}
myEventWriteFlag = false; myEventWriteFlag = false;
myEventReadFlag = myEventHistory.size() > 0; myEventReadFlag = myEventHistory.size() > 0;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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" #include "Serializer.hxx"
@ -42,6 +42,7 @@ bool Serializer::open(const string& fileName)
void Serializer::close(void) void Serializer::close(void)
{ {
myStream.close(); myStream.close();
myStream.clear();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <assert.h> #include <assert.h>
@ -209,6 +209,8 @@ bool System::saveState(const string& md5sum, Serializer& out)
if(!out.isOpen()) if(!out.isOpen())
return false; return false;
try
{
// Prepend the state file with the md5sum of this cartridge // Prepend the state file with the md5sum of this cartridge
// This is the first defensive check for an invalid state file // This is the first defensive check for an invalid state file
out.putString(md5sum); out.putString(md5sum);
@ -225,6 +227,17 @@ bool System::saveState(const string& md5sum, Serializer& out)
for(uInt32 i = 0; i < myNumberOfDevices; ++i) for(uInt32 i = 0; i < myNumberOfDevices; ++i)
if(!myDevices[i]->save(out)) if(!myDevices[i]->save(out))
return false; 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 return true; // success
} }
@ -236,6 +249,8 @@ bool System::loadState(const string& md5sum, Deserializer& in)
if(!in.isOpen()) if(!in.isOpen())
return false; return false;
try
{
// Look at the beginning of the state file. It should contain the md5sum // 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. // of the current cartridge. If it doesn't, this state file is invalid.
if(in.getString() != md5sum) if(in.getString() != md5sum)
@ -253,6 +268,17 @@ bool System::loadState(const string& md5sum, Deserializer& in)
for(uInt32 i = 0; i < myNumberOfDevices; ++i) for(uInt32 i = 0; i < myNumberOfDevices; ++i)
if(!myDevices[i]->load(in)) if(!myDevices[i]->load(in))
return false; 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 return true; // success
} }
@ -318,12 +344,14 @@ void System::poke(uInt16 addr, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void System::lockDataBus() { void System::lockDataBus()
{
myDataBusLocked = true; myDataBusLocked = true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void System::unlockDataBus() { void System::unlockDataBus()
{
myDataBusLocked = false; myDataBusLocked = false;
} }

View File

@ -322,6 +322,9 @@ opengl32.lib"
<File <File
RelativePath="..\gui\EventMappingWidget.cxx"> RelativePath="..\gui\EventMappingWidget.cxx">
</File> </File>
<File
RelativePath="..\emucore\EventStreamer.cxx">
</File>
<File <File
RelativePath="..\debugger\Expression.cxx"> RelativePath="..\debugger\Expression.cxx">
</File> </File>
@ -807,6 +810,9 @@ opengl32.lib"
<File <File
RelativePath="..\gui\EventMappingWidget.hxx"> RelativePath="..\gui\EventMappingWidget.hxx">
</File> </File>
<File
RelativePath="..\emucore\EventStreamer.hxx">
</File>
<File <File
RelativePath="..\debugger\Expression.hxx"> RelativePath="..\debugger\Expression.hxx">
</File> </File>