From f0e9d39f29b88e8affb1e14b05dcd3051631eb97 Mon Sep 17 00:00:00 2001 From: Fredrik Noring Date: Wed, 15 Jan 2025 18:33:37 +0100 Subject: [PATCH] Provisional check for RAM writes during STE DMA sound playback --- include/atari/sound.h | 2 ++ lib/atari/ram.c | 5 +++++ lib/atari/sound.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/atari/sound.h b/include/atari/sound.h index 30005e2..2a2d42d 100644 --- a/include/atari/sound.h +++ b/include/atari/sound.h @@ -78,4 +78,6 @@ extern const struct device sound_device; void sound_sample(sound_sample_f sample, void *sample_arg); +void sound_check(u32 bus_address); + #endif /* ATARI_SOUND_H */ diff --git a/lib/atari/ram.c b/lib/atari/ram.c index bf7c8be..ec17c8b 100644 --- a/lib/atari/ram.c +++ b/lib/atari/ram.c @@ -9,6 +9,7 @@ #include "atari/device.h" #include "atari/exception-vector.h" #include "atari/ram.h" +#include "atari/sound.h" #include "atari/system-variable.h" static u8 ram[4 * 1024 * 1024]; /* 4 MiB of RAM */ @@ -31,12 +32,16 @@ static u16 ram_rd_u16(const struct device *device, u32 dev_address) static void ram_wr_u8(const struct device *device, u32 dev_address, u8 data) { + sound_check(dev_address); + ram[dev_address] = data; } static void ram_wr_u16(const struct device *device, u32 dev_address, u16 data) { + sound_check(dev_address); + ram[dev_address] = data >> 8; ram[dev_address + 1] = data & 0xff; } diff --git a/lib/atari/sound.c b/lib/atari/sound.c index a32c1b2..86be270 100644 --- a/lib/atari/sound.c +++ b/lib/atari/sound.c @@ -320,6 +320,21 @@ void sound_sample(sound_sample_f sample, void *sample_arg) output.sample_arg = sample_arg; } +void sound_check(u32 bus_address) +{ + /* + * FIXME: Provisional check for Quartet files such as Spaz that + * write to RAM during DMA playback. + */ + extern const struct device sound_device; + const struct device *device = &sound_device; + + if (state.regs.ctrl.dma && + state.start <= bus_address && + bus_address < state.end) + sound_emit(device_cycle(device)); +} + const struct device sound_device = { .name = "snd", .frequency = SOUND_FREQUENCY,