From 75db33559a5a1580ca47024c69ea1c9e5ddefaf7 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 22 Sep 2017 02:25:06 +0300 Subject: [PATCH] Current sample index (Channel 1 and 2) is only reset after turning the APU off --- Core/apu.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Core/apu.c b/Core/apu.c index 1f262d1..43f2da8 100755 --- a/Core/apu.c +++ b/Core/apu.c @@ -7,10 +7,10 @@ #define unlikely(x) __builtin_expect((x), 0) static const uint8_t duties[] = { - 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 0, }; static void refresh_channel(GB_gameboy_t *gb, unsigned index, unsigned cycles_offset) @@ -529,14 +529,13 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) gb->apu.square_channels[0].sample_length; } if (value & 0x80) { - + /* Current sample index remains unchanged when restarting channels 1 or 2. It is only reset by + turning the APU off. */ if (!gb->apu.is_active[index]) { - gb->apu.square_channels[index].current_sample_index = 7; gb->apu.square_channels[index].sample_countdown = (gb->apu.square_channels[index].sample_length ^ 0x7FF) * 2 + 6 - gb->apu.lf_div; } else { - /* Timing quirk: if already active, sound starts 2 (2MHz) ticks earlier. - The current sample index remains unchanged! */ + /* Timing quirk: if already active, sound starts 2 (2MHz) ticks earlier.*/ gb->apu.square_channels[index].sample_countdown = (gb->apu.square_channels[index].sample_length ^ 0x7FF) * 2 + 4 - gb->apu.lf_div; } gb->apu.square_channels[index].current_volume = gb->io_registers[index == GB_SQUARE_1 ? GB_IO_NR12 : GB_IO_NR22] >> 4;