Jump to content
PvtLewis

Save states for Virtual Jaguar (patch)

Recommended Posts

Thanks to Shamus et al.
I was not sure where to send this, so I will post it here.
 
Attached is a patch against the current git version. Tested only on Linux/x86-64/Qt4.
[attachment=412794:virtualjaguar-savestates.diff.txt]
 
There is a new 'Tools' menu, with Dump/Load and the option to choose from 10 save slots per game.
 
Notes:
Sometimes the audio will be screwed up after loading the save state.
Try loading the state several times, by holding down the load button/key for a second or two.
 
The escape key toggles full screen mode. (It was F9 ...)
F5/F8 are mapped to Dump/Load.
 
Fixed sample buffer overrun in DSPSampleCallback.
 
Should compile with either Qt4 or Qt5.
 
Stopped randomizing RAM contents on startup, in order to better compress the state file.

Share this post


Link to post
Share on other sites

Stopped randomizing RAM contents on startup, in order to better compress the state file.


This is a good feature yo have for game development. Perhaps it could be toggled on/off in some way?

Share this post


Link to post
Share on other sites

This is a good feature yo have for game development. Perhaps it could be toggled on/off in some way?

 

For now if you compile it with the patch, just change the two "#if 1" to "#if 0" in jaguar.cpp

 

It should not be hard to add an option to the config file.

 

The whole first 8MB of jagMemSpace is saved in the state file.

Maybe only the first 2MB of actual RAM is necessary, but if everything is zeroed at startup then state files can be compressed to about 1-1.5MB

 

I just checked, and if you zero everything at startup, then randomize the 2MB of RAM, it only adds a few hundred KB to the state file.

Share this post


Link to post
Share on other sites

Update:

I finally realized that SDL audio is running in its own thread.

This new patch adds a hack to sync dump/load of the state to the audio thread.

Now it seems that the chance of audio being broken on load has been drastically reduced.

 

[attachment=412813:virtualjaguar-savestates-2-20150927.diff.txt]

 

Also, with this patch RAM contents are randomized as in stock Virtual Jaguar.

 

Share this post


Link to post
Share on other sites

This patch is quite large, and it will take some time to properly vet it; but overall, it looks good. Judging by the size of the patch, one can get an idea why I put this off for so long. ;) The second reason that I put it off is that there's no guarantee that the internal structure of the various pieces of VJ will be stable over the long term, which means that save states *may* break between official releases. :)

 

Thanks for contributing! BTW, I have to ask, why the conditional compilation for Qt 4? Is there a real need for it that I'm not seeing? I understand the transition from Qt 3 to Qt 4 was a disaster, but it seems they learned from that as the transition from Qt 4 to Qt 5 was dead simple.

Share this post


Link to post
Share on other sites

This patch is quite large, and it will take some time to properly vet it; but overall, it looks good. Judging by the size of the patch, one can get an idea why I put this off for so long. ;) The second reason that I put it off is that there's no guarantee that the internal structure of the various pieces of VJ will be stable over the long term, which means that save states *may* break between official releases. :)

 

Thanks for contributing! BTW, I have to ask, why the conditional compilation for Qt 4? Is there a real need for it that I'm not seeing? I understand the transition from Qt 3 to Qt 4 was a disaster, but it seems they learned from that as the transition from Qt 4 to Qt 5 was dead simple.

 

There is no real need for it, but the debian system that I am using only has Qt4 installed.

 

All I did was include QtGui for Qt4 if the version is less than 5, like this:

#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
 
I tried to make the save state file format flexible enough to handle slight variations between releases.
No guarantee this will work in practice...
 
The same save state files should be usable on both big endian/little endian machines, but this has not been tested.

Share this post


Link to post
Share on other sites
If you put a version number in the save state file it can be decoded correctly by all future versions of VJ and VJ can use safe defaults for things the save state format didn't support at the time.

Share this post


Link to post
Share on other sites

If you put a version number in the save state file it can be decoded correctly by all future versions of VJ and VJ can use safe defaults for things the save state format didn't support at the time.

There is a version number near the beginning of the file, but it is not intended to be incremented upon each release.

With the current patch, VJ will refuse to load files with version number greater than 1.

 

Data is stored in chunks with type/size fields at the beginning of each chunk.

 

New releases of VJ can use default values for new types that aren't found in a file, while old releases of VJ will skip over new types of data.

 

But if things change too much, it may be cumbersome to handle everything correctly.

In that case you can increment the version number and be done with it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...