git.y1.nz

SameBoy

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

commit 9bf7e0b4dffc20941e4dfadffc6899ae19463844
parent 95773b9538b5b85de95bdc06ab568b1a833386f0
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sun, 14 Aug 2022 17:43:28 +0300

More accurate sample repeat glitch, fixes #483

Diffstat:
MCore/apu.c21++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/Core/apu.c b/Core/apu.c @@ -1111,19 +1111,6 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) case GB_IO_NR13: case GB_IO_NR23: { unsigned index = reg == GB_IO_NR23? GB_SQUARE_2: GB_SQUARE_1; - if (gb->apu.is_active[index]) { - /* On an AGB, as well as on CGB C and earlier (TODO: Tested: 0, B and C), it behaves slightly different on - double speed. */ - if (gb->model == GB_MODEL_CGB_E || gb->model == GB_MODEL_CGB_D || gb->apu.square_channels[index].sample_countdown & 1) { - if (gb->apu.square_channels[index].did_tick && - gb->apu.square_channels[index].sample_countdown >> 1 == (gb->apu.square_channels[index].sample_length ^ 0x7FF)) { - gb->apu.square_channels[index].current_sample_index--; - gb->apu.square_channels[index].current_sample_index &= 7; - gb->apu.square_channels[index].sample_surpressed = false; - } - } - } - gb->apu.square_channels[index].sample_length &= ~0xFF; gb->apu.square_channels[index].sample_length |= value & 0xFF; break; @@ -1133,10 +1120,10 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) case GB_IO_NR24: { unsigned index = reg == GB_IO_NR24? GB_SQUARE_2: GB_SQUARE_1; bool was_active = gb->apu.is_active[index]; - /* TODO: When the sample length changes right before being updated, the countdown should change to the - old length, but the current sample should not change. Because our write timing isn't accurate to - the T-cycle, we hack around it by stepping the sample index backwards. */ - if ((value & 0x80) == 0 && gb->apu.is_active[index]) { + /* TODO: When the sample length changes right before being updated from ≥$700 to <$700, the countdown + should change to the old length, but the current sample should not change. Because our write + timing isn't accurate to the T-cycle, we hack around it by stepping the sample index backwards. */ + if ((value & 0x80) == 0 && gb->apu.is_active[index] && (gb->io_registers[reg] & 0x7) == 7 && (value & 7) != 7) { /* On an AGB, as well as on CGB C and earlier (TODO: Tested: 0, B and C), it behaves slightly different on double speed. */ if (gb->model == GB_MODEL_CGB_E || gb->model == GB_MODEL_CGB_D || gb->apu.square_channels[index].sample_countdown & 1) {

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