vogons - very old games on new systems Last Visit : never :: 2013-5-22 @ 10:40 pm : Now
?FAQ sSearch mMemberlist uUsergroups
rRegister pProfile "Messages lLog in
View posts : unanswered
Forum Index :: DOSBox Patches ::
up Save States - Proof of concept
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Reply with quote Re: Save States - Proof of concept :: 2010-10-13 @ 02:28 pm
jal
Member
[avatar]
Joined: 2004-01-02
Posts: 485
Location: Amersfoort, Netherlands
Manwe wrote:
Thanks for your answer, JAL, but I already read the thread


Not well enough, e.g. on page 3 there's mentioning of saving to disk, to which I replied:

jal wrote:
As I understand it, ZenJu is perfectly capable of writing the states to disk, but since he does not save the entire state of DOSBox (especially hardware, whose state is usually rather static while a game is running, but definitely not while, say, another game is), saving to disk would not allow restoring the game again (at least not without first starting the game again).


That should've answered your question, right?


JAL
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2010-12-16 @ 06:14 pm
ykhwong
Oldbie
no avatar
Joined: 2004-03-17
Posts: 588
This can save state to disk, specifically to directory /save/1 to 10. It simply works only in current DOSBox instance though. Still experimental.

In save_state.cpp
Code:
#include <fstream>

void SaveState::save(size_t slot) { //throw (Error)
    if (slot >= SLOT_COUNT)  return;

    try {
        for (CompEntry::iterator i = components.begin(); i != components.end(); ++i) {
            std::ostringstream ss;
            i->second.comp.getBytes(ss);
            i->second.rawBytes[slot].set(ss.str());
            char temp[20] = "./save/";
            int realslot = slot+1;
            char realslot_str[20];
            itoa(realslot,realslot_str,10);
            strcat(temp,realslot_str);
            strcat(temp,"/");
            strcat(temp,i->first.c_str());
            std::ofstream outfile (temp, std::ofstream::binary);
            outfile << ss.str();
            //compress all other saved states except position "slot"
            const std::vector<RawBytes>& rb = i->second.rawBytes;
            std::for_each(rb.begin(), rb.begin() + slot, std::mem_fun_ref(&RawBytes::compress));
            std::for_each(rb.begin() + slot + 1, rb.end(), std::mem_fun_ref(&RawBytes::compress));
            outfile.close();
        }
    }
    catch (const std::bad_alloc&)
    {
        throw Error("Save failed! Out of Memory!");
    }
}


void SaveState::load(size_t slot) const { //throw (Error)
//    if (isEmpty(slot)) return;
    for (CompEntry::const_iterator i = components.begin(); i != components.end(); ++i) {
        std::filebuf * fb;
        std::ifstream ss;
        std::ifstream check_file;
        fb = ss.rdbuf();
        char temp[20] = "./save/";
        int realslot = slot+1;
        char realslot_str[20];
        itoa(realslot,realslot_str,10);
        strcat(temp,realslot_str);
        strcat(temp,"/");
        strcat(temp,i->first.c_str());

        check_file.open(temp, std::ifstream::in);
        check_file.close();
        if(check_file.fail()) throw Error("No saved file for this slot. Aborted.");

        fb->open(temp,std::ios::in | std::ios::binary);
        i->second.comp.setBytes(ss);
        if (fb->in_avail() != 0 || ss.eof()) { //basic consistency check
            throw Error("Save state corrupted! Program in inconsistent state!") + " - " + i->first;
        }
        //compress all other saved states except position "slot"
        const std::vector<RawBytes>& rb = i->second.rawBytes;
        std::for_each(rb.begin(), rb.begin() + slot, std::mem_fun_ref(&RawBytes::compress));
        std::for_each(rb.begin() + slot + 1, rb.end(), std::mem_fun_ref(&RawBytes::compress));
        fb->close();
    }
}

Post new topicReply to topic
Hidden
Reply with quote Re: Save States - Proof of concept :: 2010-12-16 @ 06:29 pm
Neville
Oldbie
[avatar]
Joined: 2004-08-09
Posts: 765
Interesting... are you adding this patch to your unofficial version of DOSBox?
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2010-12-16 @ 06:31 pm
ykhwong
Oldbie
no avatar
Joined: 2004-03-17
Posts: 588
Neville wrote:
Interesting... are you adding this patch to your unofficial version of DOSBox?

Yes, you can find save directory in my current release.

Several files are genereated in the location and their names explain what they mean. I can make it a single saved file by flushing buffer when saving but loading states procedure will become more complex.
Post new topicReply to topic
Hidden
Reply with quote Re: Save States - Proof of concept :: 2010-12-17 @ 08:32 pm
Xelasarg
Member
[avatar]
Joined: 2003-09-19
Posts: 239
Location: In the middle of something
Nice one, ykhwong!

This works surprisingly well. Maybe it'll never be stable enough to be integrated into an official release, but it's a fine addition to your experimental builds.

_________________
"What's a paladin?!
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2010-12-31 @ 09:18 pm
ykhwong
Oldbie
no avatar
Joined: 2004-03-17
Posts: 588
Tiny updates for saving to disk. All credits go to ZenJu.
- States can be saved to or loaded from disk.
- Added a verification code to check if states are properly saved to disk.
- Creates a save directory if it does not exist.
- Saves a name of program running in DOSBox.
- Does not save CPU paging part and does not register POD of memory function as they disturb loading states in another instance.

Saved state files are reusable even after DOSBox exits.

Special key review:
Left ALT + F5 -> Save state / Left ALT + F9 -> Load state
Left Alt + F6 -> Previous slot / Left ALT + F7 -> Next slot
Post new topicReply to topic
Hidden
Reply with quote Re: Save States - Proof of concept :: 2011-1-23 @ 12:43 pm
Bisqwit
coder
no avatar
Joined: 2007-04-02
Posts: 13
Location: Kerava, Finland
For reference, here is a link to the savestate patch that I created a few years back. http://vogons.zetafleet.com/viewtopic.php?t=15047

My savestates could be saved on the disk, and loaded from there, even across dosbox close & open, and it had movie recording support, but movies tended to desync if loaded in a computer with different speed specifications.
It addressed the re-entrancy problem by disabling save&load function while re-entrant (during DOS input wait INT 21h for example), and it addressed the file I/O consistency by implementing an emulation layer over the I/O which virtualizes the whole I/O layer, preserving a delta over the state where files where when dosbox was started (no actual files are thus modified). I don't remember how I solved the dilemma with callback function pointers.

Just providing it here to allow possibly some insight that might help develop this currently studied candidate further.

_________________
user image
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2011-1-28 @ 12:35 am
wd
DOSBox Author
no avatar
Joined: 2003-12-03
Posts: 10817
At around that time i committed several changes to avoid machine recursions, but the
main ones remain (paging and shells, the latter being the more relevant since it can block
saving and loading completely).

There are some bits and pieces that i wasn't too happy about back then, like having some
layers over existing code rather than some more integrated solution, but that may or may
not be relevant.
Post new topicReply to topic
Hidden
Reply with quote Re: Save States - Proof of concept :: 2011-2-27 @ 01:26 pm
al3xmeister
Newbie
no avatar
Joined: 2010-07-12
Posts: 9
I've tried to install dosbox but with the save state proof it displays the "sdl_net not installed" error. any suggestions?
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2011-2-27 @ 04:52 pm
ripa
Member
no avatar
Joined: 2005-04-18
Posts: 383
Location: Finland
Do you have SDL_net.dll in the same directory as dosbox.exe? It should work just fine if you install regular dosbox, then put the new exe into the directory. You can rename the exe so you can have vanilla dosbox and save-state dosbox installed in the same directory.
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2011-2-27 @ 06:18 pm
al3xmeister
Newbie
no avatar
Joined: 2010-07-12
Posts: 9
I've done it, it works, thanks
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-07 @ 02:22 pm
jez
Member
[avatar]
Joined: 2002-09-24
Posts: 159
Any updates on whether something like this might make it into the main build anytime soon? There are some games with dodgy save/load mechanisms that can cause corruption; a solid DOSBox save state mechanism would be awesome as a save/load replacement for these games (yeah yeah, the quality of some DOS programmers' code sucked...)

_________________
== Jez ==
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-14 @ 10:29 pm
Geektastic
Newbie

Joined: 2012-04-14
Posts: 1
ask wd. Really though, no probably not anytime soon. ZenJu was only here for about a month, and his last post was almost two years ago. He may have gotten dismayed that wd didn't want save states in the mainline code (at that time). Kind of like Bisqwit's position, in that he was quite motivated to code this at one time, but that post above was his last post here, too. Still, ZenJu's implementation is certainly usable for most games and goes beyond a "proof of concept"! If you require save-to-disk saved states, wkhwong patched the code for this, linked above. So I guess I should ask: What software did you try that didn't work with beta9? If you haven't tried, please do. Do not assume because it's "old" it doesn't work anymore - it does.
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-18 @ 02:51 am
tikalat
Member
no avatar
Joined: 2012-04-13
Posts: 148
Thank you for the experimental save states code.

I think they are really practical for me (even if a temporary solution at this stage).


I'm (very slowly) going through some of the ykhwong save state version. To make it a little more useful for what I play.



This one adds palette states. Example is (sometimes) loading up states from the Gobliiins series (random incorrect colors).

Patch seems to fix this up atm.

Code:

ykhwong svn-daum 2012-02-20


gui/render.cpp

(add to end of file)
#include "../save_state.h"

//save state support
namespace
{
class SerializeRender : public SerializeGlobalPOD
{
public:
    SerializeRender() : SerializeGlobalPOD("Render")
    {
         registerPOD(render.pal);
    }
} dummy;
}

Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-18 @ 05:11 pm
tikalat
Member
no avatar
Joined: 2012-04-13
Posts: 148
Another small improvement. This time for mouse cursor.

Sometimes Lemmings 2 can act goofy with the mouse, allowing restricted cursor movement on loadstate.

This will resize the 'mouse window' on savestate.

Code:

ykhwong svn-daum 2012-02-20

(ints/mouse.cpp)

(add to end of file)
#include "../save_state.h"


//save state support
namespace
{
class SerializeMouse : public SerializeGlobalPOD
{
public:
    SerializeMouse() : SerializeGlobalPOD("Mouse")
    {
         registerPOD(mouse.min_x);
         registerPOD(mouse.min_y);
         registerPOD(mouse.max_x);
         registerPOD(mouse.max_y);
         registerPOD(mouse.clipx);
         registerPOD(mouse.clipy);
    }
} dummy;
}

Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-18 @ 05:25 pm
Jorpho
l33t
[avatar]
Joined: 2003-02-14
Posts: 2773
Location: Canada
jez wrote:
There are some games with dodgy save/load mechanisms that can cause corruption
Can you be more specific?
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-18 @ 05:28 pm
Dominus
DOSBox Moderator
[avatar]
Joined: 2002-10-03
Posts: 4632
Location: Vienna
Isn't tikalat giving enough examples?Wink

_________________
Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for OS X (10.4-10.8 ppc/intel) codesigned for gatekeeper
Post new topicReply to topic
Hidden
Reply with quote Re: Save States - Proof of concept :: 2012-4-18 @ 06:01 pm
Jorpho
l33t
[avatar]
Joined: 2003-02-14
Posts: 2773
Location: Canada
Tikalat is giving examples of games that have problems with the DOSBox savestate code. I understood Jez as referring to games whose own internal code has problems loading and saving games using their own mechanisms.
Post new topicReply to topic
Offline
Reply with quote Re: Save States - Proof of concept :: 2012-4-18 @ 06:32 pm
Dominus
DOSBox Moderator
[avatar]
Joined: 2002-10-03
Posts: 4632
Location: Vienna
Sorry, you are right Wink
I can't name any now but I know I wished for a savestate feature in a couple of games.
But I can't think of one where the savegames were prone to corruption.

_________________
Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for OS X (10.4-10.8 ppc/intel) codesigned for gatekeeper
Post new topicReply to topic
Hidden
Reply with quote Re: Save States - Proof of concept :: 2012-4-19 @ 02:42 am
ykhwong
Oldbie
no avatar
Joined: 2004-03-17
Posts: 588
Hi, tikalat. Thanks for the patches. I think one of the important things to investigate is palette corruption that still needs to be fixed.
Post new topicReply to topic
Hidden
page 5 of 10
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
All times are GMT
Moderate
Quick Reply & Options
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Powered by phpBB © 2001-2003 phpBB Group.
vogons and vogons site design and content herein is under a creative commons license 2002-2003 zetafleet.dom.
This site hosts no abandonware. There is no material that is knowingly illegal here.
zetafleet.dom will not be held responsible for users' posts.
This disclaimer is brought to you thanks to the BSA.