Savestates: More refactoring + bug fixes from the last changes (breaks compatibility again)
This commit is contained in:
parent
d04551b0ae
commit
618c8e0b5e
12 changed files with 43 additions and 51 deletions
16
Core/APU.cpp
16
Core/APU.cpp
|
@ -226,14 +226,14 @@ void APU::StreamState(bool saving)
|
|||
_currentCycle = 0;
|
||||
}
|
||||
|
||||
Stream(_nesModel);
|
||||
Stream(_squareChannel[0].get());
|
||||
Stream(_squareChannel[1].get());
|
||||
Stream(_triangleChannel.get());
|
||||
Stream(_noiseChannel.get());
|
||||
Stream(_deltaModulationChannel.get());
|
||||
Stream(_frameCounter.get());
|
||||
Stream(_mixer.get());
|
||||
SnapshotInfo squareChannel0{ _squareChannel[0].get() };
|
||||
SnapshotInfo squareChannel1{ _squareChannel[1].get() };
|
||||
SnapshotInfo triangleChannel{ _triangleChannel.get() };
|
||||
SnapshotInfo noiseChannel{ _noiseChannel.get() };
|
||||
SnapshotInfo deltaModulationChannel{ _deltaModulationChannel.get() };
|
||||
SnapshotInfo frameCounter{ _frameCounter.get() };
|
||||
SnapshotInfo mixer{ _mixer.get() };
|
||||
Stream(_nesModel, squareChannel0, squareChannel1, triangleChannel, noiseChannel, deltaModulationChannel, frameCounter, mixer);
|
||||
}
|
||||
|
||||
void APU::AddExpansionAudioDelta(AudioChannel channel, int8_t delta)
|
||||
|
|
|
@ -345,9 +345,9 @@ void Console::SaveState(ostream &saveStream)
|
|||
Instance->_cpu->SaveSnapshot(&saveStream);
|
||||
Instance->_ppu->SaveSnapshot(&saveStream);
|
||||
Instance->_memoryManager->SaveSnapshot(&saveStream);
|
||||
Instance->_mapper->SaveSnapshot(&saveStream);
|
||||
Instance->_apu->SaveSnapshot(&saveStream);
|
||||
Instance->_controlManager->SaveSnapshot(&saveStream);
|
||||
Instance->_mapper->SaveSnapshot(&saveStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,9 +357,9 @@ void Console::LoadState(istream &loadStream)
|
|||
Instance->_cpu->LoadSnapshot(&loadStream);
|
||||
Instance->_ppu->LoadSnapshot(&loadStream);
|
||||
Instance->_memoryManager->LoadSnapshot(&loadStream);
|
||||
Instance->_mapper->LoadSnapshot(&loadStream);
|
||||
Instance->_apu->LoadSnapshot(&loadStream);
|
||||
Instance->_controlManager->LoadSnapshot(&loadStream);
|
||||
Instance->_mapper->LoadSnapshot(&loadStream);
|
||||
|
||||
MessageManager::SendNotification(ConsoleNotificationType::StateLoaded);
|
||||
}
|
||||
|
|
|
@ -237,12 +237,9 @@ void ControlManager::StreamState(bool saving)
|
|||
UpdateControlDevices();
|
||||
}
|
||||
|
||||
if(GetControlDevice(0)) {
|
||||
Stream(GetControlDevice(0).get());
|
||||
}
|
||||
if(GetControlDevice(1)) {
|
||||
Stream(GetControlDevice(1).get());
|
||||
}
|
||||
SnapshotInfo device0{ GetControlDevice(0).get() };
|
||||
SnapshotInfo device1{ GetControlDevice(1).get() };
|
||||
Stream(device0, device1);
|
||||
}
|
||||
|
||||
void ControlManager::SetMousePosition(double x, double y)
|
||||
|
|
|
@ -315,12 +315,11 @@ void FDS::StreamState(bool saving)
|
|||
{
|
||||
BaseMapper::StreamState(saving);
|
||||
|
||||
SnapshotInfo audio{ _audio.get() };
|
||||
Stream(_irqReloadValue, _irqCounter, _irqEnabled, _irqReloadEnabled, _diskRegEnabled, _soundRegEnabled, _writeDataReg, _motorOn, _resetTransfer,
|
||||
_readMode, _crcControl, _diskReady, _diskIrqEnabled, _extConWriteReg, _badCrc, _endOfHead, _readWriteEnabled, _readDataReg, _diskWriteProtected,
|
||||
_diskNumber, _newDiskNumber, _newDiskInsertDelay, _diskPosition, _delay, _previousCrcControlFlag, _gapEnded, _scanningDisk, _needIrq,
|
||||
_transferComplete, _isDirty);
|
||||
|
||||
Stream(_audio.get());
|
||||
_transferComplete, _isDirty, audio);
|
||||
}
|
||||
|
||||
FDS::FDS()
|
||||
|
|
|
@ -34,12 +34,11 @@ private:
|
|||
protected:
|
||||
void StreamState(bool saving)
|
||||
{
|
||||
Stream(&_volume);
|
||||
Stream(&_mod);
|
||||
|
||||
ArrayInfo<uint8_t> waveTable = { _waveTable, 64 };
|
||||
SnapshotInfo volume{ &_volume };
|
||||
SnapshotInfo mod{ &_mod };
|
||||
|
||||
Stream(_waveWriteEnabled, _disableEnvelopes, _haltWaveform, _masterVolume, _waveOverflowCounter, _wavePitch, _wavePosition, _lastOutput, waveTable);
|
||||
Stream(volume, mod, _waveWriteEnabled, _disableEnvelopes, _haltWaveform, _masterVolume, _waveOverflowCounter, _wavePitch, _wavePosition, _lastOutput, waveTable);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -8,7 +8,7 @@ private:
|
|||
static string GetStateFilepath(int stateIndex);
|
||||
|
||||
public:
|
||||
static const uint32_t FileFormatVersion = 3;
|
||||
static const uint32_t FileFormatVersion = 4;
|
||||
|
||||
static uint64_t GetStateInfo(int stateIndex);
|
||||
static void SaveState(int stateIndex);
|
||||
|
|
|
@ -52,19 +52,15 @@ void Snapshotable::Stream(Snapshotable* snapshotable)
|
|||
uint32_t size = 0;
|
||||
InternalStream(size);
|
||||
|
||||
if(_position + size <= _streamSize) {
|
||||
uint8_t *buffer = new uint8_t[size];
|
||||
ArrayInfo<uint8_t> arrayInfo = { buffer, size };
|
||||
InternalStream(arrayInfo);
|
||||
uint8_t *buffer = new uint8_t[size];
|
||||
ArrayInfo<uint8_t> arrayInfo = { buffer, size };
|
||||
InternalStream(arrayInfo);
|
||||
|
||||
stream.write((char*)buffer, size);
|
||||
stream.seekg(0, ios::beg);
|
||||
stream.seekp(0, ios::beg);
|
||||
snapshotable->LoadSnapshot(&stream);
|
||||
delete[] buffer;
|
||||
} else {
|
||||
_position = _streamSize;
|
||||
}
|
||||
stream.write((char*)buffer, size);
|
||||
stream.seekg(0, ios::beg);
|
||||
stream.seekp(0, ios::beg);
|
||||
snapshotable->LoadSnapshot(&stream);
|
||||
delete[] buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,9 @@ private:
|
|||
template<>
|
||||
void InternalStream(SnapshotInfo &info)
|
||||
{
|
||||
Stream(info.Entity);
|
||||
if(info.Entity != nullptr) {
|
||||
Stream(info.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
void RecursiveStream()
|
||||
|
|
|
@ -8,11 +8,9 @@
|
|||
void StandardController::StreamState(bool saving)
|
||||
{
|
||||
BaseControlDevice::StreamState(saving);
|
||||
Stream(_stateBuffer, _stateBufferFamicom);
|
||||
|
||||
if(_additionalController) {
|
||||
Stream(_additionalController.get());
|
||||
}
|
||||
|
||||
SnapshotInfo additionalController{ _additionalController.get() };
|
||||
Stream(_stateBuffer, _stateBufferFamicom, additionalController);
|
||||
}
|
||||
|
||||
uint8_t StandardController::GetButtonState()
|
||||
|
|
|
@ -191,6 +191,7 @@ class VRC2_4 : public BaseMapper
|
|||
BaseMapper::StreamState(saving);
|
||||
ArrayInfo<uint8_t> loChrRegs = { _loCHRRegs, 8 };
|
||||
ArrayInfo<uint8_t> hiChrRegs = { _hiCHRRegs, 8 };
|
||||
Stream(_prgReg0, _prgReg1, _prgMode, loChrRegs, hiChrRegs, _hasIRQ, _irq);
|
||||
SnapshotInfo irq{ &_irq };
|
||||
Stream(_prgReg0, _prgReg1, _prgMode, loChrRegs, hiChrRegs, _hasIRQ, irq);
|
||||
}
|
||||
};
|
12
Core/VRC6.h
12
Core/VRC6.h
|
@ -46,12 +46,12 @@ protected:
|
|||
{
|
||||
BaseMapper::StreamState(saving);
|
||||
ArrayInfo<uint8_t> chrRegisters = { _chrRegisters, 8 };
|
||||
Stream(_bankingMode, chrRegisters, _lastOutput, _haltAudio);
|
||||
|
||||
Stream(&_irq);
|
||||
Stream(&_pulse1);
|
||||
Stream(&_pulse2);
|
||||
Stream(&_saw);
|
||||
SnapshotInfo irq{ &_irq };
|
||||
SnapshotInfo pulse1{ &_pulse1 };
|
||||
SnapshotInfo pulse2{ &_pulse2 };
|
||||
SnapshotInfo saw{ &_saw };
|
||||
|
||||
Stream(_bankingMode, chrRegisters, _lastOutput, _haltAudio, irq, pulse1, pulse2, saw);
|
||||
|
||||
if(!saving) {
|
||||
UpdatePrgRamAccess();
|
||||
|
|
|
@ -31,9 +31,9 @@ protected:
|
|||
virtual void StreamState(bool saving)
|
||||
{
|
||||
BaseMapper::StreamState(saving);
|
||||
Stream(_irq);
|
||||
SnapshotInfo irq{ &_irq };
|
||||
ArrayInfo<uint8_t> chrRegisters = { _chrRegisters, 8 };
|
||||
Stream(_controlFlags, chrRegisters);
|
||||
Stream(_controlFlags, chrRegisters, irq);
|
||||
|
||||
if(!saving) {
|
||||
UpdatePrgRamAccess();
|
||||
|
|
Loading…
Add table
Reference in a new issue