Master the fundamental concepts of emulation through this focused micro-challenge.
Save states serialize entire machine RAM, registers, and peripheral state so players jump backward instantly. Unlike battery saves (just game SRAM), snapshots freeze the full hardware at one instant.
Minimum payload:
Load must restore bit-identical state or games desync. Version your snapshot format for when you add new chips.
For example, saving mid-jump in Super Mario Bros. requires capturing PPU scroll latch and OAM positions, not just CPU registers.
\`\`\`c fwrite(cpu, sizeof(cpu), 1, fp); fwrite(ram, ram_size, 1, fp); fwrite(&ppu, sizeof(ppu), 1, fp); \`\`\`
Include a hash of the loaded ROM in snapshots so loading state against the wrong game fails fast. Silent mismatches produce ghosts that are miserable to debug.
This exercise asks you to design save/load for your emulator's CPU and memory subsystems. You will implement serialization that restores identical execution state across save and load cycles.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Implement save state serialization for a simple emulator in C.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github