git.y1.nz

SameBoy

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

commit 8809d8ac2f16d160d3989d9ac6394afe2e39ba17
parent 71c88323b7d1a4f69cc41411d11429cf1bfa9cb1
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Mon, 22 Feb 2021 15:27:17 +0200

More correct emulation of manual clocking of channels 1 and 2

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

diff --git a/Core/apu.c b/Core/apu.c @@ -1000,16 +1000,17 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) else { unsigned extra_delay = 0; if (gb->model == GB_MODEL_CGB_E /* || gb->model == GB_MODEL_CGB_D */) { - if ((!(value & 4) && ((gb->io_registers[reg] & 4) || old_sample_length == 0x3FF)) || - (old_sample_length == 0x7FF && gb->apu.square_channels[index].sample_length != 0x7FF)) { + if (!(value & 4) && !(((gb->apu.square_channels[index].sample_countdown - 1) / 2) & 0x400)) { gb->apu.square_channels[index].current_sample_index++; gb->apu.square_channels[index].current_sample_index &= 0x7; - } - else if (gb->apu.square_channels[index].sample_length == 0x7FF && - old_sample_length != 0x7FF && - (gb->apu.square_channels[index].current_sample_index & 0x80)) { - extra_delay += 2; - } + gb->apu.is_active[index] = true; + } + /* Todo: verify with the schematics what's going on in here */ + else if (gb->apu.square_channels[index].sample_length == 0x7FF && + old_sample_length != 0x7FF && + (gb->apu.square_channels[index].current_sample_index & 0x80)) { + extra_delay += 2; + } } /* 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 + extra_delay;

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