Fix a sweep regression in DMG/SGB mode and CGB-C mode

This commit is contained in:
Lior Halphon 2021-02-28 03:40:58 +02:00
parent e57b5dd57e
commit 1fdb4f09b4
1 changed files with 7 additions and 4 deletions

View File

@ -454,7 +454,7 @@ static void trigger_sweep_calculation(GB_gameboy_t *gb)
/* Recalculation and overflow check only occurs after a delay */ /* Recalculation and overflow check only occurs after a delay */
gb->apu.square_sweep_calculate_countdown = (gb->io_registers[GB_IO_NR10] & 0x7) * 2 + 5 - gb->apu.lf_div; gb->apu.square_sweep_calculate_countdown = (gb->io_registers[GB_IO_NR10] & 0x7) * 2 + 5 - gb->apu.lf_div;
if (gb->model <= GB_MODEL_CGB_C && gb->apu.lf_div) { if (gb->model <= GB_MODEL_CGB_C && gb->apu.lf_div) {
gb->apu.square_sweep_calculate_countdown += 2; // gb->apu.square_sweep_calculate_countdown += 2;
} }
gb->apu.enable_zombie_calculate_stepping = false; gb->apu.enable_zombie_calculate_stepping = false;
gb->apu.unshifted_sweep = !(gb->io_registers[GB_IO_NR10] & 0x7); gb->apu.unshifted_sweep = !(gb->io_registers[GB_IO_NR10] & 0x7);
@ -1102,7 +1102,10 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
/* APU bug: if shift is nonzero, overflow check also occurs on trigger */ /* APU bug: if shift is nonzero, overflow check also occurs on trigger */
gb->apu.square_sweep_calculate_countdown = (gb->io_registers[GB_IO_NR10] & 0x7) * 2 + 5 - gb->apu.lf_div; gb->apu.square_sweep_calculate_countdown = (gb->io_registers[GB_IO_NR10] & 0x7) * 2 + 5 - gb->apu.lf_div;
if (gb->model <= GB_MODEL_CGB_C && gb->apu.lf_div) { if (gb->model <= GB_MODEL_CGB_C && gb->apu.lf_div) {
gb->apu.square_sweep_calculate_countdown += 2; /* TODO: I used to think this is correct, but it caused several regressions.
More research is needed to figure how calculation time is different
in models prior to CGB-D */
// gb->apu.square_sweep_calculate_countdown += 2;
} }
gb->apu.enable_zombie_calculate_stepping = false; gb->apu.enable_zombie_calculate_stepping = false;
gb->apu.unshifted_sweep = false; gb->apu.unshifted_sweep = false;