From 3358d957043c726957ea6104d34f7b166195db5e Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Fri, 19 May 2023 14:52:15 -0700 Subject: [PATCH] scsp: zeroize dsp The Saturn BIOS does not (un)initialize the DSP. Without zeroizing the DSP program, the SCSP DSP appears to have a program that continuously writes to 0x30000 through 0x3ffff in sound RAM, which has the effect of destroying any samples stored there. --- common/copy.hpp | 9 +++++++++ scsp/sound_cpu__interrupt.cpp | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/copy.hpp b/common/copy.hpp index 4df90fc..d9c1274 100644 --- a/common/copy.hpp +++ b/common/copy.hpp @@ -8,3 +8,12 @@ inline void copy(T * dst, const T * src, int32_t n) noexcept n -= (sizeof (T)); } } + +template +inline void fill(T * dst, const T src, int32_t n) noexcept +{ + while (n > 0) { + *dst++ = src; + n -= (sizeof (T)); + } +} diff --git a/scsp/sound_cpu__interrupt.cpp b/scsp/sound_cpu__interrupt.cpp index 1cdc707..bccae66 100644 --- a/scsp/sound_cpu__interrupt.cpp +++ b/scsp/sound_cpu__interrupt.cpp @@ -15,23 +15,26 @@ void main() The document suggests that Sound RAM is (somewhat) preserved during SNDOFF. */ - + while ((smpc.reg.SF & 1) != 0); smpc.reg.SF = 1; smpc.reg.COMREG = COMREG__SNDOFF; while (smpc.reg.oreg[31] != OREG31__SNDOFF); scsp.reg.ctrl.MIXER = MIXER__MEM4MB; - + + reg32 * dsp_steps = reinterpret_cast(&(scsp.reg.dsp.STEP[0].MPRO[0])); + fill(dsp_steps, 0, (sizeof (scsp.reg.dsp.STEP))); + uint32_t * m68k_main_start = reinterpret_cast(&_m68k_start); uint32_t m68k_main_size = reinterpret_cast(&_m68k_size); copy(&scsp.ram.u32[0], m68k_main_start, m68k_main_size); - + while ((smpc.reg.SF & 1) != 0); smpc.reg.SF = 1; smpc.reg.COMREG = COMREG__SNDON; while (smpc.reg.oreg[31] != OREG31__SNDON); - + // do nothing while the sound CPU manipulates the SCSP }