all repos — mgba @ c52a5d2859a535cd439f914beffeb1f2eb49e9f6

mGBA Game Boy Advance Emulator

GBA Audio: Support 16-bit writes to FIFO audio
Jeffrey Pfau jeffrey@endrift.com
Sun, 21 Dec 2014 03:19:56 -0800
commit

c52a5d2859a535cd439f914beffeb1f2eb49e9f6

parent

ce0ad004e4acb88b3f1a0716caccf5eb1ac743db

3 files changed, 31 insertions(+), 3 deletions(-)

jump to
M src/gba/gba-audio.csrc/gba/gba-audio.c

@@ -453,6 +453,30 @@ }

} } +void GBAAudioWriteFIFO16(struct GBAAudio* audio, int address, uint16_t value) { + struct CircleBuffer* fifo; + switch (address) { + case REG_FIFO_A_LO: + case REG_FIFO_A_HI: + fifo = &audio->chA.fifo; + break; + case REG_FIFO_B_LO: + case REG_FIFO_B_HI: + fifo = &audio->chB.fifo; + break; + default: + GBALog(audio->p, GBA_LOG_ERROR, "Bad FIFO write to address 0x%03x", address); + return; + } + int i; + for (i = 0; i < 2; ++i) { + while (!CircleBufferWrite8(fifo, value >> (8 * i))) { + int8_t dummy; + CircleBufferRead8(fifo, &dummy); + } + } +} + void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles) { struct GBAAudioFIFO* channel; if (fifoId == 0) {
M src/gba/gba-audio.hsrc/gba/gba-audio.h

@@ -252,6 +252,7 @@ void GBAAudioWriteSOUNDCNT_X(struct GBAAudio* audio, uint16_t value);

void GBAAudioWriteSOUNDBIAS(struct GBAAudio* audio, uint16_t value); void GBAAudioWriteWaveRAM(struct GBAAudio* audio, int address, uint32_t value); +void GBAAudioWriteFIFO16(struct GBAAudio* audio, int address, uint16_t value); void GBAAudioWriteFIFO(struct GBAAudio* audio, int address, uint32_t value); void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles);
M src/gba/gba-io.csrc/gba/gba-io.c

@@ -356,8 +356,6 @@ case REG_WAVE_RAM0_LO:

case REG_WAVE_RAM1_LO: case REG_WAVE_RAM2_LO: case REG_WAVE_RAM3_LO: - case REG_FIFO_A_LO: - case REG_FIFO_B_LO: GBAIOWrite32(gba, address, (gba->memory.io[(address >> 1) + 1] << 16) | value); break;

@@ -365,9 +363,14 @@ case REG_WAVE_RAM0_HI:

case REG_WAVE_RAM1_HI: case REG_WAVE_RAM2_HI: case REG_WAVE_RAM3_HI: + GBAIOWrite32(gba, address - 2, gba->memory.io[(address >> 1) - 1] | (value << 16)); + break; + + case REG_FIFO_A_LO: + case REG_FIFO_B_LO: case REG_FIFO_A_HI: case REG_FIFO_B_HI: - GBAIOWrite32(gba, address - 2, gba->memory.io[(address >> 1) - 1] | (value << 16)); + GBAAudioWriteFIFO16(&gba->audio, address, value); break; // DMA