git.y1.nz

SameBoy

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

commit f866441481dbec7e32fdd9dc3a3785a2f9027cba
parent e9629407a5d64a9fa3b65edec8f0f05727248d6f
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sun, 19 Dec 2021 19:27:01 +0200

Improved emulation of channel 3 wave RAM read glitch

Diffstat:
MCore/apu.c22+++++++++++++++++-----
MCore/apu.h2+-
2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/Core/apu.c b/Core/apu.c @@ -598,10 +598,19 @@ void GB_apu_run(GB_gameboy_t *gb) gb->apu.apu_cycles = 0; if (!cycles) return; - if (unlikely(gb->apu.wave_channel.delayed_bugged_read)) { - gb->apu.wave_channel.delayed_bugged_read = false; - gb->apu.wave_channel.current_sample_byte = - gb->io_registers[GB_IO_WAV_START + (gb->address_bus & 0xF)]; + if (unlikely(gb->apu.wave_channel.bugged_read_countdown)) { + uint8_t cycles_left = cycles; + while (cycles_left) { + cycles_left--; + if (--gb->apu.wave_channel.bugged_read_countdown == 0) { + gb->apu.wave_channel.current_sample_byte = + gb->io_registers[GB_IO_WAV_START + (gb->address_bus & 0xF)]; + if (gb->apu.is_active[GB_WAVE]) { + update_wave_sample(gb, 0); + } + break; + } + } } bool start_ch4 = false; @@ -707,12 +716,15 @@ void GB_apu_run(GB_gameboy_t *gb) gb->io_registers[GB_IO_WAV_START + (gb->address_bus & 0xF)]; } else { - gb->apu.wave_channel.delayed_bugged_read = true; + gb->apu.wave_channel.bugged_read_countdown = 1; } } if (cycles_left) { gb->apu.wave_channel.sample_countdown -= cycles_left; } + if (gb->apu.wave_channel.sample_countdown == 0) { + gb->apu.wave_channel.bugged_read_countdown = 2; + } } // The noise channel can step even if inactive on the DMG diff --git a/Core/apu.h b/Core/apu.h @@ -102,7 +102,7 @@ typedef struct uint8_t current_sample_byte; // Current sample byte. bool wave_form_just_read; bool pulsed; - bool delayed_bugged_read; + uint8_t bugged_read_countdown; } wave_channel; struct {

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