mirror of https://github.com/bsnes-emu/bsnes.git
Corrected behavior for channel 1 and 2 restart
This commit is contained in:
parent
882b141478
commit
8f4cd5c412
14
Core/apu.c
14
Core/apu.c
|
@ -267,7 +267,6 @@ void GB_apu_run(GB_gameboy_t *gb)
|
|||
duties[gb->apu.square_channels[i].current_sample_index + duty * 8]?
|
||||
gb->apu.square_channels[i].current_volume : 0,
|
||||
cycles - cycles_left);
|
||||
gb->apu.square_channels[i].sample_emitted = true;
|
||||
}
|
||||
if (cycles_left) {
|
||||
gb->apu.square_channels[i].sample_countdown -= cycles_left;
|
||||
|
@ -530,22 +529,15 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
|
|||
gb->apu.square_channels[0].sample_length;
|
||||
}
|
||||
if (value & 0x80) {
|
||||
gb->apu.square_channels[index].current_sample_index = 7;
|
||||
|
||||
if (!gb->apu.is_active[index]) {
|
||||
gb->apu.square_channels[index].current_sample_index = 7;
|
||||
gb->apu.square_channels[index].sample_countdown = (gb->apu.square_channels[index].sample_length ^ 0x7FF) * 2 + 6 - gb->apu.lf_div;
|
||||
}
|
||||
else {
|
||||
/* Timing quirk: if already active, sound starts 2 (2MHz) ticks earlier.
|
||||
if both active AND already emitted a sample, sound starts the next 1MHz tick,
|
||||
and one sample is skipped */
|
||||
if (!gb->apu.square_channels[index].sample_emitted) {
|
||||
gb->apu.square_channels[index].sample_countdown = (gb->apu.square_channels[index].sample_length ^ 0x7FF) * 2 + 4 - gb->apu.lf_div;
|
||||
}
|
||||
else {
|
||||
gb->apu.square_channels[index].sample_countdown = gb->apu.lf_div;
|
||||
gb->apu.square_channels[index].current_sample_index = 0;
|
||||
}
|
||||
The current sample index remains unchanged! */
|
||||
gb->apu.square_channels[index].sample_countdown = (gb->apu.square_channels[index].sample_length ^ 0x7FF) * 2 + 4 - gb->apu.lf_div;
|
||||
}
|
||||
gb->apu.square_channels[index].current_volume = gb->io_registers[index == GB_SQUARE_1 ? GB_IO_NR12 : GB_IO_NR22] >> 4;
|
||||
gb->apu.square_channels[index].volume_countdown = gb->io_registers[index == GB_SQUARE_1 ? GB_IO_NR12 : GB_IO_NR22] & 7;
|
||||
|
|
|
@ -59,7 +59,6 @@ typedef struct
|
|||
uint8_t current_volume; // Reloaded from NRX2
|
||||
uint8_t volume_countdown; // Reloaded from NRX2
|
||||
uint8_t current_sample_index;
|
||||
bool sample_emitted;
|
||||
|
||||
uint16_t sample_countdown; // in APU ticks (Reloaded from sample_length, xorred $7FF)
|
||||
uint16_t sample_length; // From NRX3, NRX4, in APU ticks
|
||||
|
|
Loading…
Reference in New Issue