From ca59aca4a6cab2a256d60f62d585b0a91936ce1c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 13 Aug 2017 20:26:35 +0300 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20bug=20where=20writing=20to=20NR52?= =?UTF-8?q?=20affected=20channels=201=20and=202=E2=80=99s=20duty=20pattern?= =?UTF-8?q?=20in=20DMG=20mode.=20Fixed=20NR43=20being=20written=20to=20NR4?= =?UTF-8?q?4=20as=20well.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/apu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/apu.c b/Core/apu.c index a44b466..9d78cef 100755 --- a/Core/apu.c +++ b/Core/apu.c @@ -423,13 +423,15 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) } memset(&gb->apu, 0, sizeof(gb->apu)); memset(gb->io_registers + GB_IO_NR10, 0, GB_IO_WAV_START - GB_IO_NR10); + old_nrx1[0] &= 0x3F; + old_nrx1[1] &= 0x3F; gb->apu.global_enable = false; } if (!gb->is_cgb && (value & 0x80)) { - GB_apu_write(gb, GB_IO_NR11, old_nrx1[0] & 0x3F); - GB_apu_write(gb, GB_IO_NR21, old_nrx1[1] & 0x3F); + GB_apu_write(gb, GB_IO_NR11, old_nrx1[0]); + GB_apu_write(gb, GB_IO_NR21, old_nrx1[1]); GB_apu_write(gb, GB_IO_NR31, old_nrx1[2]); GB_apu_write(gb, GB_IO_NR41, old_nrx1[3]); } @@ -638,6 +640,7 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) due to how the frequency is actually calculated in the noise channel, which is probably not by calculating the effective sample length and counting simiarly to the other channels. This is not emulated correctly. */ + break; } case GB_IO_NR44: {