all repos — mgba @ f5bf85448932d4b22f5aa8b450f551589a7bb0ee

mGBA Game Boy Advance Emulator

GB Audio: Fix NRx2 writes while active (fixes #866)
Vicki Pfau vi@endrift.com
Tue, 05 Sep 2017 23:00:20 -0700
commit

f5bf85448932d4b22f5aa8b450f551589a7bb0ee

parent

aa350ea5b7a4048f98c128cae1644cedbfa5a65e

2 files changed, 7 insertions(+), 7 deletions(-)

jump to
M CHANGESCHANGES

@@ -21,6 +21,7 @@ - GB Video: Fix potential hang when ending mode 0

- GB Memory: Fix HDMA count starting in mode 0 (fixes mgba.io/i/855) - GB Memory: Actually load latch time from savestate - GB, GBA: Fix sync to video with frameskip + - GB Audio: Fix NRx2 writes while active (fixes mgba.io/i/866) Misc: - Qt: Don't rebuild library view if style hasn't changed - SDL: Fix 2.0.5 build on macOS under some circumstances
M src/gb/audio.csrc/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);

@@ -178,7 +178,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;

@@ -236,7 +236,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;

@@ -354,7 +354,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;

@@ -695,17 +695,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; }