GB Audio: Fix crashes when audio->p is not set (e.g. GBA mode)
Jeffrey Pfau jeffrey@endrift.com
Sun, 14 Feb 2016 02:11:12 -0800
1 files changed,
18 insertions(+),
9 deletions(-)
jump to
M
src/gb/audio.c
→
src/gb/audio.c
@@ -157,10 +157,12 @@ if (audio->ch1.control.stop && !(audio->frame & 1)) {
--audio->ch1.control.length; } } - audio->nextEvent = audio->p->cpu->cycles; + // TODO: Don't need p if (audio->p) { - // TODO: Don't need p + audio->nextEvent = audio->p->cpu->cycles; audio->p->cpu->nextEvent = audio->nextEvent; + } else { + audio->nextEvent = 0; } } *audio->nr52 &= ~0x0001;@@ -213,10 +215,12 @@ if (audio->ch2.control.stop && !(audio->frame & 1)) {
--audio->ch2.control.length; } } - audio->nextEvent = audio->p->cpu->cycles; + // TODO: Don't need p if (audio->p) { - // TODO: Don't need p + audio->nextEvent = audio->p->cpu->cycles; audio->p->cpu->nextEvent = audio->nextEvent; + } else { + audio->nextEvent = 0; } } *audio->nr52 &= ~0x0002;@@ -282,12 +286,15 @@ if (audio->nextEvent == INT_MAX) {
audio->eventDiff = 0; } // TODO: Where does this cycle delay come from? - audio->nextCh3 = audio->eventDiff + audio->p->cpu->cycles + 4 + 2 * (2048 - audio->ch3.rate); audio->ch3.readable = false; - audio->nextEvent = audio->p->cpu->cycles; + // TODO: Don't need p if (audio->p) { - // TODO: Don't need p + 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; + } else { + audio->nextCh3 = audio->eventDiff + 4 + 2 * (2048 - audio->ch3.rate); + audio->nextEvent = 0; } } *audio->nr52 &= ~0x0004;@@ -344,10 +351,12 @@ if (audio->ch4.stop && !(audio->frame & 1)) {
--audio->ch4.length; } } - audio->nextEvent = audio->p->cpu->cycles; + // TODO: Don't need p if (audio->p) { - // TODO: Don't need p + audio->nextEvent = audio->p->cpu->cycles; audio->p->cpu->nextEvent = audio->nextEvent; + } else { + audio->nextEvent = 0; } } *audio->nr52 &= ~0x0008;