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
// 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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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 <sstream>
@ -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());

View File

@ -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;

View File

@ -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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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 <assert.h>
@ -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;
}

View File

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