From ed94288902a67d9dd0fd86211e07cb27000ec826 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 14 Feb 2016 01:22:03 -0800 Subject: [PATCH] GB Audio: Fix write behavior on channel 3 --- src/gb/audio.c | 3 ++- src/gb/io.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gb/audio.c b/src/gb/audio.c index 4efca2901..3d3359e1e 100644 --- a/src/gb/audio.c +++ b/src/gb/audio.c @@ -281,7 +281,8 @@ void GBAudioWriteNR34(struct GBAudio* audio, uint8_t value) { if (audio->nextEvent == INT_MAX) { audio->eventDiff = 0; } - audio->nextCh3 = audio->eventDiff + audio->p->cpu->cycles + 2 + 2 * (2048 - audio->ch3.rate); + // TODO: Where does this cycle delay come from? + audio->nextCh3 = audio->eventDiff + audio->p->cpu->cycles + 4 + 2 * (2048 - audio->ch3.rate); audio->ch3.readable = false; audio->nextEvent = audio->p->cpu->cycles; if (audio->p) { diff --git a/src/gb/io.c b/src/gb/io.c index a20ed4948..fdfc77898 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -243,8 +243,10 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { case REG_WAVE_D: case REG_WAVE_E: case REG_WAVE_F: - if (!gb->audio.playingCh3 || gb->audio.ch3.readable) { + if (!gb->audio.playingCh3) { gb->audio.ch3.wavedata8[address - REG_WAVE_0] = value; + } else if(gb->audio.ch3.readable) { + gb->audio.ch3.wavedata8[gb->audio.ch3.window >> 1] = value; } break; case REG_JOYP: