Conversation
Implements the remaining savestate features to achieve complete emulator
state preservation:
**WRAM Banking (CGB)**
- Add SVBK register (0xFF70) to CgbController for WRAM bank switching
- Expand WRAM from 8KB to 32KB (8 banks × 4KB each)
- Bank 0 (0xC000-0xCFFF) is fixed, banks 1-7 (0xD000-0xDFFF) are switchable
- SavestateManager now saves all 8 WRAM banks separately
- Maintains backward compatibility with 8KB flat format
**OAM DMA Transfer State**
- Add getter/setter methods for DMA transfer progress
- Save: dmaActive, dmaProgress, dmaDelay, dmaSource
- Preserves mid-frame DMA state (rare edge case)
**HDMA Transfer State**
- Add getter/setter methods for HDMA transfer state
- Save: hdmaActive, hblankMode, remainingBlocks
- Preserves H-Blank DMA progress for CGB games
**APU Channel Internal State**
- Save complete internal state for all 4 audio channels:
- Channel 1: lengthCounter, currentVolume, envelopeTimer, frequencyTimer,
dutyPosition, enabled, dacEnabled, sweepTimer, sweepShadow, sweepEnabled
- Channel 2: lengthCounter, currentVolume, envelopeTimer, frequencyTimer,
dutyPosition, enabled, dacEnabled
- Channel 3: lengthCounter, frequencyTimer, samplePosition, enabled, dacEnabled
- Channel 4: lengthCounter, currentVolume, envelopeTimer, frequencyTimer,
enabled, dacEnabled, **lfsr** (critical for noise pattern preservation)
- Add channel accessor methods to Apu class
- Eliminates audio glitches and timing drift after savestate restore
**SavestateManager Updates**
- Bump version from 1.0.0 to 1.1.0
- Maintain backward compatibility with version 1.0.0 savestates
- Update serialization to include all new state
- Add serializeOamDma/deserializeOamDma methods
- Add serializeHdma/deserializeHdma methods
- Enhance serializeApu/deserializeApu with channel state
**Testing**
- Update CgbControllerTest to pass Wram instance to constructor
- Update SavestateManagerTest to expect version 1.1.0
- Fix Wram address masking for backward compatibility
- All unit tests passing
This completes the savestate implementation with full accuracy for:
✅ WRAM Banking (CGB) - All 8 banks × 4KB
✅ OAM DMA Transfer Progress
✅ HDMA Transfer State
✅ Full APU Channel Internal State
Closes the savestate feature gap and enables perfect emulator state
restoration for both DMG and CGB games.
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.
Implements the remaining savestate features to achieve complete emulator
state preservation:
WRAM Banking (CGB)
OAM DMA Transfer State
HDMA Transfer State
APU Channel Internal State
dutyPosition, enabled, dacEnabled, sweepTimer, sweepShadow, sweepEnabled
dutyPosition, enabled, dacEnabled
enabled, dacEnabled, lfsr (critical for noise pattern preservation)
SavestateManager Updates
Testing
This completes the savestate implementation with full accuracy for:
✅ WRAM Banking (CGB) - All 8 banks × 4KB
✅ OAM DMA Transfer Progress
✅ HDMA Transfer State
✅ Full APU Channel Internal State
Closes the savestate feature gap and enables perfect emulator state
restoration for both DMG and CGB games.