all repos — mgba @ d6a45781f0ea2c12e6e785f5b01a22c37e55c355

mGBA Game Boy Advance Emulator

GB Audio: length counters can be written when audio off
Jeffrey Pfau jeffrey@endrift.com
Sun, 14 Feb 2016 23:55:21 -0800
commit

d6a45781f0ea2c12e6e785f5b01a22c37e55c355

parent

ecdcef283b14a458521e80b714cb6d43da9965f6

2 files changed, 22 insertions(+), 8 deletions(-)

jump to
M src/gb/audio.csrc/gb/audio.c

@@ -286,10 +286,10 @@ if (audio->playingCh3) {

if (audio->nextEvent == INT_MAX) { audio->eventDiff = 0; } - // TODO: Where does this cycle delay come from? audio->ch3.readable = false; // TODO: Don't need p if (audio->p) { + // TODO: Where does this cycle delay come from? audio->nextCh3 = audio->eventDiff + audio->p->cpu->cycles + 4 + 2 * (2048 - audio->ch3.rate); audio->nextEvent = audio->p->cpu->cycles; audio->p->cpu->nextEvent = audio->nextEvent;

@@ -389,25 +389,28 @@ audio->playingCh2 = 0;

audio->playingCh3 = 0; audio->playingCh4 = 0; GBAudioWriteNR10(audio, 0); - GBAudioWriteNR11(audio, 0); GBAudioWriteNR12(audio, 0); GBAudioWriteNR13(audio, 0); GBAudioWriteNR14(audio, 0); - GBAudioWriteNR21(audio, 0); GBAudioWriteNR22(audio, 0); GBAudioWriteNR23(audio, 0); GBAudioWriteNR24(audio, 0); GBAudioWriteNR30(audio, 0); - GBAudioWriteNR31(audio, 0); GBAudioWriteNR32(audio, 0); GBAudioWriteNR33(audio, 0); GBAudioWriteNR34(audio, 0); - // Don't write to NR41 GBAudioWriteNR42(audio, 0); GBAudioWriteNR43(audio, 0); GBAudioWriteNR44(audio, 0); GBAudioWriteNR50(audio, 0); GBAudioWriteNR51(audio, 0); + if (audio->style != GB_AUDIO_DMG) { + GBAudioWriteNR11(audio, 0); + GBAudioWriteNR21(audio, 0); + GBAudioWriteNR31(audio, 0); + GBAudioWriteNR41(audio, 0); + } + if (audio->p) { audio->p->memory.io[REG_NR10] = 0; audio->p->memory.io[REG_NR11] = 0;

@@ -428,6 +431,12 @@ audio->p->memory.io[REG_NR43] = 0;

audio->p->memory.io[REG_NR44] = 0; audio->p->memory.io[REG_NR50] = 0; audio->p->memory.io[REG_NR51] = 0; + if (audio->style != GB_AUDIO_DMG) { + audio->p->memory.io[REG_NR11] = 0; + audio->p->memory.io[REG_NR21] = 0; + audio->p->memory.io[REG_NR31] = 0; + audio->p->memory.io[REG_NR41] = 0; + } } *audio->nr52 &= ~0x000F; } else if (!wasEnable) {
M src/gb/io.csrc/gb/io.c

@@ -96,6 +96,7 @@ case REG_NR11:

if (gb->audio.enable) { GBAudioWriteNR11(&gb->audio, value); } else { + GBAudioWriteNR11(&gb->audio, value & _registerMask[REG_NR11]); value = 0; } break;

@@ -124,6 +125,7 @@ case REG_NR21:

if (gb->audio.enable) { GBAudioWriteNR21(&gb->audio, value); } else { + GBAudioWriteNR21(&gb->audio, value & _registerMask[REG_NR21]); value = 0; } break;

@@ -156,7 +158,7 @@ value = 0;

} break; case REG_NR31: - if (gb->audio.enable) { + if (gb->audio.enable || gb->audio.style == GB_AUDIO_DMG) { GBAudioWriteNR31(&gb->audio, value); } else { value = 0;

@@ -184,8 +186,11 @@ value = 0;

} break; case REG_NR41: - // NR41 is exempt, for some reason - GBAudioWriteNR41(&gb->audio, value); + if (gb->audio.enable || gb->audio.style == GB_AUDIO_DMG) { + GBAudioWriteNR41(&gb->audio, value); + } else { + value = 0; + } break; case REG_NR42: if (gb->audio.enable) {