GB Audio: Fix NRx2 writes while active (fixes #866)
Vicki Pfau vi@endrift.com
Tue, 05 Sep 2017 23:00:20 -0700
2 files changed,
7 insertions(+),
7 deletions(-)
M
CHANGES
→
CHANGES
@@ -35,6 +35,7 @@ - GB Memory: Fix HDMA count starting in mode 0 (fixes mgba.io/i/855)
- GB Memory: Actually load latch time from savestate - GB Serialize: Fix game title check - GB, GBA: Fix sync to video with frameskip + - GB Audio: Fix NRx2 writes while active (fixes mgba.io/i/866) Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
M
src/gb/audio.c
→
src/gb/audio.c
@@ -25,7 +25,7 @@ const int GB_AUDIO_VOLUME_MAX = 0x100;
static bool _writeSweep(struct GBAudioSweep* sweep, uint8_t value); static void _writeDuty(struct GBAudioEnvelope* envelope, uint8_t value); -static bool _writeEnvelope(struct GBAudioEnvelope* envelope, uint8_t value); +static bool _writeEnvelope(struct GBAudioEnvelope* envelope, uint8_t value, enum GBAudioStyle style); static void _resetSweep(struct GBAudioSweep* sweep); static bool _resetEnvelope(struct GBAudioEnvelope* sweep);@@ -182,7 +182,7 @@ audio->ch1.control.length = 64 - audio->ch1.envelope.length;
} void GBAudioWriteNR12(struct GBAudio* audio, uint8_t value) { - if (!_writeEnvelope(&audio->ch1.envelope, value)) { + if (!_writeEnvelope(&audio->ch1.envelope, value, audio->style)) { mTimingDeschedule(audio->timing, &audio->ch1Event); audio->playingCh1 = false; *audio->nr52 &= ~0x0001;@@ -240,7 +240,7 @@ audio->ch2.control.length = 64 - audio->ch2.envelope.length;
} void GBAudioWriteNR22(struct GBAudio* audio, uint8_t value) { - if (!_writeEnvelope(&audio->ch2.envelope, value)) { + if (!_writeEnvelope(&audio->ch2.envelope, value, audio->style)) { mTimingDeschedule(audio->timing, &audio->ch2Event); audio->playingCh2 = false; *audio->nr52 &= ~0x0002;@@ -358,7 +358,7 @@ audio->ch4.length = 64 - audio->ch4.envelope.length;
} void GBAudioWriteNR42(struct GBAudio* audio, uint8_t value) { - if (!_writeEnvelope(&audio->ch4.envelope, value)) { + if (!_writeEnvelope(&audio->ch4.envelope, value, audio->style)) { mTimingDeschedule(audio->timing, &audio->ch4Event); audio->playingCh4 = false; *audio->nr52 &= ~0x0008;@@ -700,17 +700,16 @@ envelope->length = GBAudioRegisterDutyGetLength(value);
envelope->duty = GBAudioRegisterDutyGetDuty(value); } -bool _writeEnvelope(struct GBAudioEnvelope* envelope, uint8_t value) { +bool _writeEnvelope(struct GBAudioEnvelope* envelope, uint8_t value, enum GBAudioStyle style) { envelope->stepTime = GBAudioRegisterSweepGetStepTime(value); envelope->direction = GBAudioRegisterSweepGetDirection(value); envelope->initialVolume = GBAudioRegisterSweepGetInitialVolume(value); - if (!envelope->stepTime) { + if (style == GB_AUDIO_DMG && !envelope->stepTime) { // TODO: Improve "zombie" mode ++envelope->currentVolume; envelope->currentVolume &= 0xF; } _updateEnvelopeDead(envelope); - envelope->nextStep = envelope->stepTime; return (envelope->initialVolume || envelope->direction) && envelope->dead != 2; }