Improved emulation of channel 3 wave RAM read glitch

This commit is contained in:
Lior Halphon 2021-12-19 19:27:01 +02:00
parent e9629407a5
commit f866441481
2 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -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 {