joypad savestate

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
joypad savestate
by on (#48431)
- When a savestate is done, should I include the current joypad data / shifting? Is this really required when a savestate is loaded?

- I did a quick optimization here, but it might fail on saves:

Code:
-pseudo-code-
value = joypad_read << 1;

-then, on 4016/7 reads:

value >>= 1;
return value & 1;-


- It replaces the usual code:
Code:
-pseudo-code-
value = joypad_read;

-then, on 4016/7 reads:

unsigned char temp = value & 1;
value >>= 1;
return temp;


- What do you think about it?

by on (#48443)
Quote:
- When a savestate is done, should I include the current joypad data / shifting? Is this really required when a savestate is loaded?


I would. It would only add a few bytes to the size of the savestate, and it gets you a more precise state. I try to make savestates as "perfect" as possible to ensure that movies won't desync, or other oddities relating to imperfect savestates.

But I suppose you don't HAVE to.

Quote:
- I did a quick optimization here, but it might fail on saves: [snip]- What do you think about it?


Looks fine.

It doesn't matter how you manage the data in your emulator, as long as it is saved/loaded to the savestate in a consistent way. There's no reason your approach wouldn't work with savestates.

by on (#48444)
If you want to make your save-state code more correct real fast, add a debugging mode that does a save and a restore after every frame, and try playing through a few games that way.

by on (#48547)
- With that optimization, I'll have to save an extra byte. The value now has 0x1FE as maximum, instead of 0xFF.

by on (#48549)
or you could right shift on save and left shift on load.

by on (#48550)
Disch wrote:
or you could right shift on save and left shift on load.


- Yes, but one bit would be lost anyway.
EDIT: nevermind, I got it. >_<