From b50d8e35e98906e446701dbf3973e799306f13ed Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 25 Nov 2020 20:09:54 -0800 Subject: [PATCH] GB I/O: Implement preliminary support for PCM12/PCM34 (#1468) --- CHANGES | 1 + src/gb/io.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 40acf4c1a..400c429fd 100644 --- a/CHANGES +++ b/CHANGES @@ -84,6 +84,7 @@ Misc: - Core: Rework thread state synchronization - GB: Allow pausing event loop while CPU is blocked - GB: Add support for sleep and shutdown callbacks + - GB I/O: Implement preliminary support for PCM12/PCM34 (closes mgba.io/i/1468) - GBA: Allow pausing event loop while CPU is blocked - GBA BIOS: Division by zero should emit a FATAL error - GBA Video: Convert OpenGL VRAM texture to integer diff --git a/src/gb/io.c b/src/gb/io.c index c0a2d36cc..0e3a70eca 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -216,7 +216,7 @@ void GBIOReset(struct GB* gb) { GBIOWrite(gb, GB_REG_HDMA4, 0xFF); gb->memory.io[GB_REG_HDMA5] = 0xFF; } else { - memset(&gb->memory.io[GB_REG_KEY0], 0xFF, GB_REG_PCM34 - GB_REG_KEY0); + memset(&gb->memory.io[GB_REG_KEY0], 0xFF, GB_REG_PCM34 - GB_REG_KEY0 + 1); } if (gb->model & GB_MODEL_SGB) { @@ -622,6 +622,20 @@ uint8_t GBIORead(struct GB* gb, unsigned address) { return gb->audio.ch3.wavedata8[address - GB_REG_WAVE_0]; } break; + case GB_REG_PCM12: + if (gb->model < GB_MODEL_CGB) { + mLOG(GB_IO, GAME_ERROR, "Reading from CGB register FF%02X in DMG mode", address); + } else if (gb->audio.enable) { + return (gb->audio.ch1.sample) | (gb->audio.ch2.sample << 4); + } + break; + case GB_REG_PCM34: + if (gb->model < GB_MODEL_CGB) { + mLOG(GB_IO, GAME_ERROR, "Reading from CGB register FF%02X in DMG mode", address); + } else if (gb->audio.enable) { + return (gb->audio.ch3.sample) | (gb->audio.ch4.sample << 4); + } + break; case GB_REG_SB: case GB_REG_SC: case GB_REG_IF: