From a834f8b1f69bc62fb8f56dc529860ed8c7f5bd54 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 2 Oct 2013 00:46:51 -0700 Subject: [PATCH] Sample FIFOs with sound DMA timer --- src/gba/gba-audio.h | 20 ++++++++++---------- src/gba/gba-io.c | 4 +--- src/gba/gba.c | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/gba/gba-audio.h b/src/gba/gba-audio.h index 210f57aed..bf56a4643 100644 --- a/src/gba/gba-audio.h +++ b/src/gba/gba-audio.h @@ -138,17 +138,17 @@ struct GBAAudio { union { struct { unsigned volume : 2; - unsigned volumeDmaA : 1; - unsigned volumeDmaB : 1; + unsigned volumeChA : 1; + unsigned volumeChB : 1; unsigned : 4; - unsigned dmaARight : 1; - unsigned dmaALeft : 1; - unsigned dmaATimer : 1; - unsigned dmaAReset : 1; - unsigned dmaBRight : 1; - unsigned dmaBLeft : 1; - unsigned dmaBTimer : 1; - unsigned dmaBReset : 1; + unsigned chARight : 1; + unsigned chALeft : 1; + unsigned chATimer : 1; + unsigned chAReset : 1; + unsigned chBRight : 1; + unsigned chBLeft : 1; + unsigned chBTimer : 1; + unsigned chBReset : 1; }; uint16_t soundcntHi; }; diff --git a/src/gba/gba-io.c b/src/gba/gba-io.c index 524814745..22fa4fb77 100644 --- a/src/gba/gba-io.c +++ b/src/gba/gba-io.c @@ -209,10 +209,8 @@ void GBAIOWrite32(struct GBA* gba, uint32_t address, uint32_t value) { GBAAudioWriteWaveRAM(&gba->audio, 3, value); break; case REG_FIFO_A_LO: - GBAAudioWriteFIFO(&gba->audio, 0, value); - break; case REG_FIFO_B_LO: - GBAAudioWriteFIFO(&gba->audio, 1, value); + GBAAudioWriteFIFO(&gba->audio, address, value); break; case REG_DMA0SAD_LO: GBAMemoryWriteDMASAD(&gba->memory, 0, value); diff --git a/src/gba/gba.c b/src/gba/gba.c index 79b9d5e4f..88e8159b8 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -136,6 +136,16 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) { GBARaiseIRQ(gba, IRQ_TIMER0); } + if (gba->audio.enable) { + if ((gba->audio.chALeft || gba->audio.chARight) && gba->audio.chATimer == 0) { + GBAAudioSampleFIFO(&gba->audio, 0); + } + + if ((gba->audio.chBLeft || gba->audio.chBRight) && gba->audio.chBTimer == 0) { + GBAAudioSampleFIFO(&gba->audio, 1); + } + } + nextTimer = &gba->timers[1]; if (nextTimer->countUp) { ++gba->memory.io[REG_TM1CNT_LO >> 1]; @@ -161,6 +171,16 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) { GBARaiseIRQ(gba, IRQ_TIMER1); } + if (gba->audio.enable) { + if ((gba->audio.chALeft || gba->audio.chARight) && gba->audio.chATimer == 1) { + GBAAudioSampleFIFO(&gba->audio, 0); + } + + if ((gba->audio.chBLeft || gba->audio.chBRight) && gba->audio.chBTimer == 1) { + GBAAudioSampleFIFO(&gba->audio, 1); + } + } + if (timer->countUp) { timer->nextEvent = INT_MAX; }