fengb / fundude

Gameboy emulator: Zig -> wasm
https://fengb.github.io/fundude/
MIT License
181 stars 8 forks source link

Save/load state #41

Open fengb opened 4 years ago

fengb commented 4 years ago

Every other emulator does this. Why can't we?

Questions:

fengb commented 4 years ago

Format ideas:

  1. Custom binary dump. Let's do a simple "size: u16 - payload: []u8 — size: u16 - payload: []u8" for now. This is intentionally not standardized because Zig doesn't have a prebuilt one and I don't want to build one (yet)
  2. Header magic number:
    • 0xDC — busts ascii (high bit) + unicode (0xDC00 - 0xDC7F is illegal as first char for both UTF8 and UTF16)
    • 0x00 — version (increment this when the format changes)
    • 0x46F
    • 0x44D
    • the following are shamelessly stolen from PNG
    • 0x0D — CR
    • 0x0A — LF (DOS line)
    • 0x1A — DOS EOF
    • 0x0A — LF (Unix line)
  3. Cart checksum — copy of cartridge cart[0x134..][0..0x18] (24 bytes)
  4. Footer trailing checksum decided this is out of scope:
    • we have some simple redundancies already
    • adds a fair bit of complexity
    • compression will have its own (possibly better) checksum
fengb commented 4 years ago

Note: first pass will not do compression because Zig doesn't have a standard implementation yet.

fengb commented 4 years ago

Implemented via https://github.com/fengb/fundude/commit/053e8dcc4719b353bbe9b8212d371bdbb73c8fc9

Still iterating super quickly so maybe we shouldn't expose this to the frontend yet.