all repos — mgba @ c61dcadac767b9e19cabc7fd3eb80700d5f2f93e

mGBA Game Boy Advance Emulator

GB Serialize: Fix timing bug loading channel 4 timing
Vicki Pfau vi@endrift.com
Sat, 01 Feb 2020 12:17:45 -0800
commit

c61dcadac767b9e19cabc7fd3eb80700d5f2f93e

parent

c79506746c19827d892730fae2ea1be267cf7823

2 files changed, 7 insertions(+), 2 deletions(-)

jump to
M CHANGESCHANGES

@@ -1,5 +1,6 @@

0.8.1: (Future) Emulation fixes: + - GB Serialize: Fix timing bug loading channel 4 timing - GBA Memory: Misaligned SRAM writes are ignored - GBA Serialize: Fix serializing DMA transfer register - GBA Serialize: Fix audio DMA timing deserialization
M src/gb/audio.csrc/gb/audio.c

@@ -1078,9 +1078,13 @@ LOAD_32LE(audio->ch4.lfsr, 0, &state->ch4.lfsr);

LOAD_32LE(audio->ch4.lastEvent, 0, &state->ch4.lastEvent); LOAD_32LE(when, 0, &state->ch4.nextEvent); if (audio->ch4.envelope.dead < 2 && audio->playingCh4) { - if (when - audio->ch4.lastEvent > (uint32_t) audio->sampleInterval) { + if (!audio->ch4.lastEvent) { // Back-compat: fake this value - audio->ch4.lastEvent = when - audio->sampleInterval; + uint32_t currentTime = mTimingCurrentTime(audio->timing); + int32_t cycles = audio->ch4.ratio ? 2 * audio->ch4.ratio : 1; + cycles <<= audio->ch4.frequency; + cycles *= 8 * audio->timingFactor; + audio->ch4.lastEvent = currentTime + (when & (cycles - 1)) - cycles; } mTimingSchedule(audio->timing, &audio->ch4Event, when); }