Fix timing inaccuracy

This commit is contained in:
Lior Halphon
2026-02-16 01:10:07 +02:00
parent 9c23f0d685
commit 9450eb9575
+11 -6
View File
@@ -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;