git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 9450eb9575b8fbf7ff22efbcac473fc3a8c4d91a
parent 9c23f0d685dcac856d9b3520a4f9894710442bad
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Mon, 16 Feb 2026 01:10:07 +0200

Fix timing inaccuracy

Diffstat:
MCore/apu.c17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/Core/apu.c b/Core/apu.c @@ -1248,14 +1248,19 @@ static void prepare_noise_start(GB_gameboy_t *gb) divisor = 8; } else if (divisor == 1) { - /* TODO: I'm not 100% sure this only affects NR43 = 1X */ - if ((gb->io_registers[GB_IO_NR43] & 0xf0) == 0x10 && (gb->apu.noise_channel.counter & 1)) { - instant_step = true; - } - /* TODO: needs further research, the conditions are very odd. What if NR43 changes before stepping? */ - if ((gb->io_registers[GB_IO_NR43] & 0xf0) == 0x10 && !gb->apu.noise_channel.did_step_counter) { + if (!gb->apu.noise_channel.did_step_counter) { div_1_glitch = true; } + + uint16_t mask = 1 << (gb->io_registers[GB_IO_NR43] >> 4); + bool old_bit = gb->apu.noise_channel.counter & mask; + gb->apu.noise_channel.counter++; + gb->apu.noise_channel.counter &= 0x3FFF; + bool new_bit = gb->apu.noise_channel.counter & mask; + + if ((new_bit && !old_bit)) { + instant_step = true; + } } } gb->apu.noise_channel.counter_countdown = divisor == 0? 6 : divisor * 4 + 6;

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.