GB Audio: length counters can be written when audio off

This commit is contained in:
Jeffrey Pfau 2016-02-14 23:55:21 -08:00
parent ecdcef283b
commit d6a45781f0
2 changed files with 22 additions and 8 deletions

View File

@ -286,10 +286,10 @@ void GBAudioWriteNR34(struct GBAudio* audio, uint8_t value) {
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 @@ void GBAudioWriteNR52(struct GBAudio* audio, uint8_t value) {
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 @@ void GBAudioWriteNR52(struct GBAudio* audio, uint8_t value) {
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) {

View File

@ -96,6 +96,7 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
if (gb->audio.enable) {
GBAudioWriteNR11(&gb->audio, value);
} else {
GBAudioWriteNR11(&gb->audio, value & _registerMask[REG_NR11]);
value = 0;
}
break;
@ -124,6 +125,7 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
if (gb->audio.enable) {
GBAudioWriteNR21(&gb->audio, value);
} else {
GBAudioWriteNR21(&gb->audio, value & _registerMask[REG_NR21]);
value = 0;
}
break;
@ -156,7 +158,7 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
}
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 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
}
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) {