mirror of https://github.com/stella-emu/stella.git
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:
parent
98c94e4b24
commit
2f16788aaa
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -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());
|
||||||
|
|
|
@ -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();
|
||||||
myStreamWriter.putString("EventStream");
|
|
||||||
myStreamWriter.putInt(size);
|
try
|
||||||
for(int i = 0; i < size; ++i)
|
{
|
||||||
myStreamWriter.putInt(myEventHistory[i]);
|
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();
|
myStreamWriter.close();
|
||||||
return true;
|
return true;
|
||||||
|
@ -88,16 +103,30 @@ 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))
|
||||||
|
|
||||||
if(myStreamReader.getString() != "EventStream")
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Now load the event stream
|
try
|
||||||
myEventHistory.clear();
|
{
|
||||||
int size = myStreamReader.getInt();
|
if(myStreamReader.getString() != "EventStream")
|
||||||
for(int i = 0; i < size; ++i)
|
return false;
|
||||||
myEventHistory.push_back(myStreamReader.getInt());
|
|
||||||
|
// 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;
|
myEventWriteFlag = false;
|
||||||
myEventReadFlag = myEventHistory.size() > 0;
|
myEventReadFlag = myEventHistory.size() > 0;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -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,23 +209,36 @@ bool System::saveState(const string& md5sum, Serializer& out)
|
||||||
if(!out.isOpen())
|
if(!out.isOpen())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Prepend the state file with the md5sum of this cartridge
|
try
|
||||||
// This is the first defensive check for an invalid state file
|
{
|
||||||
out.putString(md5sum);
|
// 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
|
// First save state for this system
|
||||||
if(!save(out))
|
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;
|
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
|
return true; // success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,24 +249,37 @@ bool System::loadState(const string& md5sum, Deserializer& in)
|
||||||
if(!in.isOpen())
|
if(!in.isOpen())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Look at the beginning of the state file. It should contain the md5sum
|
try
|
||||||
// of the current cartridge. If it doesn't, this state file is invalid.
|
{
|
||||||
if(in.getString() != md5sum)
|
// Look at the beginning of the state file. It should contain the md5sum
|
||||||
return false;
|
// of the current cartridge. If it doesn't, this state file is invalid.
|
||||||
|
if(in.getString() != md5sum)
|
||||||
// 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;
|
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
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue