Repository navigation
Save states and audio mute - #9
Merged
Merged
Conversation
Snapshot and restore the whole machine (CPU, memory, PPU, timer, sound, cartridge banking and RAM). States carry a versioned header and the cartridge checksums, and a rejected load leaves the game untouched. FFI: save_state(path), load_state(path) and set_audio_muted(bool), for hosts that fast-forward. Also silences the release-only unused-variable warnings in the cpal player.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds save states to the core and two FFI helpers a host needs for save states and fast-forward.
Save states
Gameboy::save_state()/load_state()snapshot the whole machine: CPU, WRAM/HRAM, PPU (including CGB palettes and VRAM banks), HDMA, timer, joypad, serial, sound channels, and the cartridge's banking registers, RAM and RTC.src/state.rsholds a small binary format, with no new dependencies. Each component lists its fields in order through animpl_state!macro.FFI
save_state(path)writes through a temp file plus rename (reusing the save-file writer, whose temp name now works for any extension).load_state(path)restores a state.set_audio_muted(bool)drops samples while set, and clears the queue when muting starts. Hosts use it to fast-forward without building up seconds of audio lag.Other
CpalPlayer::new, which appear in release builds because the errors are only printed with debug assertions.Tests