all repos — mgba @ c0818c3a0c68b872441d0f4b6ddf491f47736bc1

mGBA Game Boy Advance Emulator

GBA: Ensure proper audio timing in savestates
Jeffrey Pfau jeffrey@endrift.com
Tue, 02 Jun 2015 22:13:29 -0700
commit

c0818c3a0c68b872441d0f4b6ddf491f47736bc1

parent

cd43d075617ad2d5172afd82213ee09f072d0f76

1 files changed, 16 insertions(+), 0 deletions(-)

jump to
M src/gba/serialize.csrc/gba/serialize.c

@@ -90,6 +90,22 @@ if (state->timers[0].overflowInterval < 0 || state->timers[1].overflowInterval < 0 || state->timers[2].overflowInterval < 0 || state->timers[3].overflowInterval < 0) {

GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: overflowInterval is negative"); return; } + if (state->audio.ch1.envelopeNextStep < 0 || state->audio.ch1.waveNextStep < 0 || state->audio.ch1.sweepNextStep < 0 || state->audio.ch1.nextEvent < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: audio channel 1 register is negative"); + return; + } + if (state->audio.ch2.envelopeNextStep < 0 || state->audio.ch2.waveNextStep < 0 || state->audio.ch2.nextEvent < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: audio channel 2 register is negative"); + return; + } + if (state->audio.ch3.nextEvent < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: audio channel 3 register is negative"); + return; + } + if (state->audio.ch4.envelopeNextStep < 0 || state->audio.ch4.nextEvent < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: audio channel 4 register is negative"); + return; + } if (state->cpu.gprs[ARM_PC] == BASE_CART0 || (state->cpu.gprs[ARM_PC] & SIZE_CART0) >= gba->memory.romSize) { GBALog(gba, GBA_LOG_WARN, "Savestate created using a differently sized version of the ROM"); return;