From ecace40fb06fa929cd27a22f5853fc2775e18f93 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 2 Jan 2021 18:27:21 +0200 Subject: [PATCH] Minor APU bug fix --- Core/apu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/apu.c b/Core/apu.c index 890ffe3..8ddb52b 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -846,6 +846,10 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) } else { /* Timing quirk: if already active, sound starts 2 (2MHz) ticks earlier.*/ + if (gb->apu.square_channels[index].sample_countdown <= 1) { + gb->apu.square_channels[index].current_sample_index++; + gb->apu.square_channels[index].current_sample_index &= 0x7; + } 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;