GB Audio: Fix channel 1/2 reseting edge cases (fixes #1925)

This commit is contained in:
Vicki Pfau 2022-03-07 18:36:24 -08:00
parent eddd518a2c
commit 739d842129
2 changed files with 9 additions and 6 deletions

View File

@ -18,6 +18,7 @@ Features:
Emulation fixes:
- ARM7: Fix unsigned multiply timing
- GB: Copy logo from ROM if not running the BIOS intro (fixes mgba.io/i/2378)
- GB Audio: Fix channel 1/2 reseting edge cases (fixes mgba.io/i/1925)
- GB Memory: Add cursory cartridge open bus emulation (fixes mgba.io/i/2032)
- GB Serialize: Fix loading MBC1 states that affect bank 0 (fixes mgba.io/i/2402)
- GB Video: Draw SGB border pieces that overlap GB graphics (fixes mgba.io/i/1339)

View File

@ -204,6 +204,7 @@ void GBAudioWriteNR14(struct GBAudio* audio, uint8_t value) {
}
}
if (GBAudioRegisterControlIsRestart(value << 8)) {
bool wasDead = !audio->playingCh1;
audio->playingCh1 = _resetEnvelope(&audio->ch1.envelope);
audio->ch1.sweep.realFrequency = audio->ch1.control.frequency;
_resetSweep(&audio->ch1.sweep);
@ -216,10 +217,10 @@ void GBAudioWriteNR14(struct GBAudio* audio, uint8_t value) {
--audio->ch1.control.length;
}
}
if (audio->playingCh1 && audio->ch1.envelope.dead != 2) {
_updateSquareChannel(&audio->ch1);
mTimingDeschedule(audio->timing, &audio->ch1Event);
if (wasDead && audio->playingCh1) {
mTimingSchedule(audio->timing, &audio->ch1Event, 0);
} else if (!audio->playingCh1) {
mTimingDeschedule(audio->timing, &audio->ch1Event);
}
}
*audio->nr52 &= ~0x0001;
@ -257,6 +258,7 @@ void GBAudioWriteNR24(struct GBAudio* audio, uint8_t value) {
}
}
if (GBAudioRegisterControlIsRestart(value << 8)) {
bool wasDead = !audio->playingCh2;
audio->playingCh2 = _resetEnvelope(&audio->ch2.envelope);
if (!audio->ch2.control.length) {
@ -265,10 +267,10 @@ void GBAudioWriteNR24(struct GBAudio* audio, uint8_t value) {
--audio->ch2.control.length;
}
}
if (audio->playingCh2 && audio->ch2.envelope.dead != 2) {
_updateSquareChannel(&audio->ch2);
mTimingDeschedule(audio->timing, &audio->ch2Event);
if (wasDead && audio->playingCh2) {
mTimingSchedule(audio->timing, &audio->ch2Event, 0);
} else if (!audio->playingCh2) {
mTimingDeschedule(audio->timing, &audio->ch2Event);
}
}
*audio->nr52 &= ~0x0002;