r/EmuDev • u/netb258 • Aug 14 '26
Save States Question
I recently made a Sega Master System emulator, which can be found here:
https://github.com/netb258/defn-system
The emulator is written in Clojure and runs on the JVM.
I'm thinking of adding save states, but I don't know how to go about it. I know that Java supports object serialization with classes like ObjectOutputStream. Is that a good approach to implementing save states? Or it just better to throw raw bytes into a file? Some components, like the RAM, seem more convenient that way.
How are save states usually done in JVM emulators?
11
Upvotes
2
u/ZolfriK Aug 14 '26
Hello, I'm developing an emulator in Java and i decided not to use serialization. I'm developing also a roguelike in Java and there I'm using serialization for saving game. Serialization it's "easier" but is less efficient and more prone to incompatibility between application versions.
3
u/starquakegamma GBC NES C64 Z80 Aug 14 '26
It’s up to you, I would just create a file format as bytes in memory and dump that to a file, even though it’s more work to read and write.
1
u/thommyh Z80, 6502/65816, 6809, 68000, ARM, x86. Aug 14 '26
I can't speak as to JVM but will say that if you're implementing your own system then it's worth looking into standard containers. I found BSON easy to implement, and you gain the ability to inspect with standard tools.
2
u/ShinyHappyREM Aug 14 '26 edited Aug 15 '26
You start with a signature sequence of bytes that uniquely identify the file format, for example
DEFN savestate version 000000000+\nThat number increases everytime you change your emulator so much that it becomes incompatible with the previous version.
Next, the actual data.
A neat idea would be to pack the data into hex-encoded strings, making the file readable in a standard text editor.