Permalink
Browse files

GB Audio: Fix NRx2 writes while active (fixes #866)

  • Loading branch information...
endrift committed Sep 6, 2017
1 parent aa350ea commit f5bf85448932d4b22f5aa8b450f551589a7bb0ee
Showing with 7 additions and 7 deletions.
  1. +1 −0 CHANGES
  2. +6 −7 src/gb/audio.c
View
@@ -21,6 +21,7 @@ Bugfixes:
- 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
View
@@ -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 @@ void GBAudioWriteNR11(struct GBAudio* audio, uint8_t value) {
}
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 @@ void GBAudioWriteNR21(struct GBAudio* audio, uint8_t value) {
}
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 @@ void GBAudioWriteNR41(struct GBAudio* audio, uint8_t value) {
}
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 @@ void _writeDuty(struct GBAudioEnvelope* envelope, uint8_t 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;
}

0 comments on commit f5bf854

Please sign in to comment.