Save States - Proof of concept

Here you can discuss the development of patches.

Save States - Proof of concept

Postby ZenJu » 2010-7-04 @ 14:50

Hi,

general support for save states would be an awesome feature. Currently there doesn't seem to be a timeline when this feature will be in the official release. As I can't wait that long (there are a couple of die-hard dosgames without ingame save support I need to finish since the 90s) I gave it a shot at my own solution: Yesterday evening I downloaded the sources and made it compile. I'll spare you the details of my little "compiling adventure", but just present you a first "working" version in the attachment.

It's based on the latest official Dosbox sources 0.74.

Default Keyboard bindings: (I suggest using the keyboard mapper CTRL+F1 to reassign them to something more convenient)


Left ALT + F5 -> Save state
Left ALT + F9 -> Load state

I've tested with a couple of games and my success rate surprisingly already was about 70%! (Doom, Keen, Bio Menace were working fine.)

Note however that I have no detailed knowledge about Dosbox in general. Actually I know the sourcecode for one day by now. Therefore it is possible that I have missed something. This first version should be seen as a proof of concept for now. I mean: don't blame me if it's not working for every game ;) I'm going to further revise it.

PS: If someone is interested I'll release the sourcecode at some time. My implementation strategy can be easily expanded. In the hands of a *real* dosbox developer, this save state feature may turn out to be easier than expected.

Best regards, ZenJu

Update 2012-12-15: PPS: Here's a link to a further enhanced version of DOSBox with save states and xBRZ high quality image filter:
link
Last edited by ZenJu on 2015-1-11 @ 20:24, edited 14 times in total.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: Save States - Proof of concept

Postby Calvero » 2010-7-04 @ 15:15

Thanks, I finally made it past the swinging rope in level 2 of The Jetsons: By George, in Trouble Again. It's a game without ingame save support and I just need to finish it since the 90s :).
Calvero
Member
 
Posts: 102
Joined: 2007-8-02 @ 13:30

Re: Save States - Proof of concept

Postby ripsaw8080 » 2010-7-04 @ 16:02

ZenJu wrote:without ingame save support I need to finish since the 90s
Calvero wrote:without ingame save support and I just need to finish it since the 90s

Just a coincidence that both use the same turn of phrase?
User avatar
ripsaw8080
DOSBox Author
 
Posts: 4011
Joined: 2006-4-25 @ 23:24

Re: Save States - Proof of concept

Postby ripa » 2010-7-04 @ 18:04

Cool! Worked in Duke Nukem 2, Keen 5, Supaplex (woohoo!), Prince 1 and Prince 2. Some observations: in Nukem2, it got stuck when loading a savestace once. Also, the graphics palette isn't restored, so for example in Supaplex if you save in a level and load when in the blue "you failed" screen, the graphics are corrupted. Also, the bottom menu is corrupted if you load when you're in the main menu (but it's easy to restore by pressing enter twice).

In Prince 1 and 2 sometimes after loading the game speed is changed. For example, I saved in Prince1 during the level and loaded when the prince goes up the stairs to the next level. The game speed was very fast until I drank a potion. In Prince 2 on the other hand, the game played very slow after loading (didn't happen very often though and game speed restored after the music looped from end to beginning). Also, in Prince2 after I'd loaded a game and I finished a level, it didn't advance to the cutscene until I paused the game and resumed it (esc is pause). Also, palette bug in Prince2 also (palette gets fixed when you advance to the next screen).

Thumbs up for this patch regardless!
ripa
Oldbie
 
Posts: 539
Joined: 2005-4-18 @ 00:53
Location: Finland

Re: Save States - Proof of concept

Postby Calvero » 2010-7-04 @ 18:10

@ripsaw8080 No :-)

Again: Thanks, I've finally finished this stupid Jetsons game :cool:
Calvero
Member
 
Posts: 102
Joined: 2007-8-02 @ 13:30

Re: Save States - Proof of concept

Postby ADDiCT » 2010-7-04 @ 21:28

Very interesting. Keep up the good work, I'm pretty sure lots of people will find this patch useful. Maybe you can even convince Mr. "No Savestates, Ever!" wd that savestates are feasible for mainline DOSBox (; .
User avatar
ADDiCT
Oldbie
 
Posts: 1170
Joined: 2007-2-02 @ 15:07
Location: Retroland

Re: Save States - Proof of concept

Postby ZenJu » 2010-7-04 @ 21:53

> game speed is changed
Yes I've noticed that too (on Arkanoid)

Currently I'm saving complete RAM, CPU Register, Segment pointer, Video Ram, Flags and Paging. I haven't yet systematically analyzed the sourcecode, but merely saved the minimum parts I figured that represent a "state". So there definitively is room for improvement.
I guess one part which makes an official save state feature harder is that there is potentially quite a lot that can go wrong, most notably if persistent state is not in sync with the save state. This is a problem that doesn't occur e.g. with ZSNES where there is no such dependency.
Luckily this isn't a problem with "small and simple games".

PS: Just finished Arkanoid ;) I remember never going further than level 8. Now I beat all 32 ones.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: Save States - Proof of concept

Postby frobme » 2010-7-05 @ 04:31

Currently I'm saving complete RAM, CPU Register, Segment pointer, Video Ram, Flags and Paging.


Awesome, great to see somebody talking this.

Are you saving the framebuffer along with video RAM?

You would probably need to save some meta data associated with Dosbox itself, for instance the CPU emulation type.

Various sound cards have some small buffers as well...I imagine for some games that might be important.

-Frob
frobme
Member
 
Posts: 137
Joined: 2007-1-09 @ 09:03

Re: Save States - Proof of concept

Postby Kippesoep » 2010-7-05 @ 05:17

Another biggie is open files. This is also one of the toughest, since you must maintain a list of mountings, current directory, names of files that are open, with the correct file handle, I/O buffer and file pointer. To do it right, there should even be a check whether any open file has not been altered since saving state (and basically refuse to restore state in case it was altered).
My site: Ramblings on mostly tech stuff.
User avatar
Kippesoep
Oldbie
 
Posts: 1014
Joined: 2005-5-04 @ 22:36
Location: Netherlands

Re: Save States - Proof of concept

Postby wd » 2010-7-05 @ 06:27

Maybe you can even convince Mr. "No Savestates, Ever!" wd that savestates are feasible for mainline DOSBox (; .

What stupid comment of yours is that?
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: Save States - Proof of concept

Postby Xelasarg » 2010-7-05 @ 09:23

Amazing :happyhappy:

I can confirm this feature working in Wing Commander, Links386 and Strike Commander.

Still buggy in some games, but after all, it's a beta version.

Great work!
"What's a paladin?!"
User avatar
Xelasarg
Member
 
Posts: 255
Joined: 2003-9-19 @ 09:10
Location: In the middle of something

Re: Save States - Proof of concept

Postby ADDiCT » 2010-7-05 @ 09:32

Ah, glad this has been reopened.

wd: my mistake. I had a vague memory of someone writing that savestates would be impossible to do in DOSBox and i thought it was you. I've searched through the relevant posts but couldn't find a comment like that from you, so my memory probably failed me. I would've appreciated a different wording in your reply though. "Silly" maybe. (;

Anyway, I hope this patch gets the attention it deserves. The feature has been asked for many times (actually so many times that threads about it got closed immediately in the past), so I guess a fully working implementation of this functionality would be a great step forwards for DOSBox.
User avatar
ADDiCT
Oldbie
 
Posts: 1170
Joined: 2007-2-02 @ 15:07
Location: Retroland

Re: Save States - Proof of concept

Postby wd » 2010-7-05 @ 09:44

wd: my mistake. I had a vague memory of someone writing that savestates would be impossible to do in DOSBox and i thought it was you. I've searched through the relevant posts but couldn't find a comment like that from you, so my memory probably failed me. I would've appreciated a different wording in your reply though. "Silly" maybe. (;

I doubt anybody said it was impossible, there has already been done a lot
of work to make things more straightforward (which the OP possibly benefits of)
but the main points like reentrant machine calls and general file handling are
still open.
Also would have preferred if the OP had contacted somebody before making
something like that public.
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: Save States - Proof of concept

Postby eL_PuSHeR » 2010-7-05 @ 12:23

Someone suggested to move this thread to the DOSBox Development Section. Is it publicly accessable?
Intel i7 5960X
Gigabye GA-X99-Gaming 5
8 GB DDR4 (2100)
8 GB GeForce GTX 1070 G1 Gaming (Gigabyte)
User avatar
eL_PuSHeR
Moderator
 
Posts: 6433
Joined: 2003-6-20 @ 16:39

Re: Save States - Proof of concept

Postby ZenJu » 2010-7-05 @ 18:42

> stuck when loading a savestace
I had the same issue with Turrican 2. After I added the keyboard state it worked fine. Maybe this was the issue in this case too. Problems in Tyrian2k were fixed by adding IRQ and PIC states.

> sometimes after loading the game speed is changed
Added the timer to the save state. Didn't face this issue anymore. Hopefully fixed.

> graphics palette isn't restored
Still open. But doesn't seem to be a big problem (=crash) as long as video mode isn't changed.

> Are you saving the framebuffer along with video RAM?
I'm just saving the RAM currently. There is a lot of state related to Video. I'm not entirely sure what is really needed.

> Another biggie is open files.
> You would probably need to save some meta data associated with Dosbox itself, for instance the CPU emulation type.
Hm, my approach is to restrict saving state only to parts that belong to the emulated computer. My naive(?) expectation is that the Dosbox framework does not depend on the current state (whatever that exactly is, I'm still finding out...) of the virtual computer. If this is true, I needn't worry about open files or other issues external to the virt. computer. This is probably where you tell me that my assumption is not correct ;)

> Various sound cards have some small buffers as well...I imagine for some games that might be important.
Not sure if it's important to include this into the save state. Worst that can happen is a short sound distortion???

I've uploaded Beta 2: It is much more stable now. I think it already is a quite useful tool to finish some of the really hard games. But it is no 100% solution. But this isn't exactly what I'm after. Although I'm usually the perfectionist type, in this case my approach is VERY pragmatic ;) It's fun.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: Save States - Proof of concept

Postby VisitntX » 2010-7-06 @ 01:27

F-A-N-T-A-S-T-I-C

Great work my friend ;)
User avatar
VisitntX
Member
 
Posts: 131
Joined: 2005-12-18 @ 07:44

Re: Save States - Proof of concept

Postby IIGS_User » 2010-7-06 @ 06:01

ZenJu wrote:> graphics palette isn't restored
Still open. But doesn't seem to be a big problem (=crash) as long as video mode isn't changed.

May save the video mode setting along, overwriting the current setting (at start of db) or displaying a warning msg if not match with current setting, if the save state will be opened while db is already running.

ZenJu wrote:> Are you saving the framebuffer along with video RAM?
I'm just saving the RAM currently. There is a lot of state related to Video. I'm not entirely sure what is really needed.

All what possible. :wink:
Klimawandel.
User avatar
IIGS_User
Oldbie
 
Posts: 863
Joined: 2007-3-14 @ 19:59
Location: native_lang=ger

Re: Save States - Proof of concept

Postby VisitntX » 2010-7-06 @ 14:43

I have a question, I made a savestate using the game "Avoid the noid" and it worked perfectly, but when I closed the dosbox and reopen it, when I wanted to load the savestate would not let me.
What is the problem?
User avatar
VisitntX
Member
 
Posts: 131
Joined: 2005-12-18 @ 07:44

Re: Save States - Proof of concept

Postby Xelasarg » 2010-7-06 @ 16:04

As far as I see (by looking to all directories that seem relevant to me), no image/savestate file is actually stored on the hard drive. I guess all the saved data is stored in memory and therefore lost when you quit DOSBox.

@ZenJu:
Another (probably dumb) question: wouldn't it be possible to just store everything that's currently in DOSBox's emulated memory? So that if you set memsize=8, the save file would have exactly that size, i.e. 8 MB.
"What's a paladin?!"
User avatar
Xelasarg
Member
 
Posts: 255
Joined: 2003-9-19 @ 09:10
Location: In the middle of something

Re: Save States - Proof of concept

Postby ZenJu » 2010-7-06 @ 16:19

> I closed the dosbox and reopened[...] load the savestate would not let me.
The save state is not written to disk, therefore it is lost when you exit dosbox. Implementing this feature would be trivial. But it seems kind of risky to keep a state over a longer period of time. Right now I do not yet save everything that "represents" the emulated computer, most importantly the (complete) video state. Therefore it think it's too early to allow saving and loading across dosbox sessions.
But perhaps I should be brave and give it a try :)
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Next

Return to DOSBox Patches

Who is online

Users browsing this forum: No registered users and 2 guests