Native SPU2 interrupt; IOP sceSifCheckStatRpc and sceSifSetDChain

- Mixer: a core's IRQ address and enable (setIrqAddress / setIrqEnabled).
  A voice reading the 16-byte block that holds the address (a block
  decoded, a key on) or a transfer writing over it calls the IRQ
  callback once. The core then stays disabled until it is enabled again,
  as the SPU2's IRQ flag is cleared. Both are saved with the mixer's
  state.
- libsd: SD_A_IRQA (0x1F00) and SD_CORE_IRQ_ENABLE (0x4) drive the mixer.
  sceSdSetSpu2IntrHandler (27) keeps its handler, which the interrupt
  calls as handler(1 << core, argument) through the host's interrupt
  calls, like the transfer handlers. It was a no-op before.
- IRX host: sifcmd 18 (sceSifCheckStatRpc) answers 0, since IOP calls to
  EE services complete within sceSifCallRpc. sifman 6 (sceSifSetDChain)
  does nothing, as no chain mode needs arming.

Capcom's SNDDRVCD (Onimusha: Warlords) plays its voice streams (ADS)
through the SPU2 interrupt and reports a stream busy until it ends. Its
room events wait for that, so the first room's opening never started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Thomas MartinandClaude Opus 5.5 committed 2026-11-23 16:31:28 +01:00
1 parent 9c3b610937
commit 3b7973008b
6 files changed
+93 -5

No files matched your search

+2 -1
View File
@@ -19,7 +19,7 @@ namespace bozo::audio
{
for (Voice &v : g.voices)
pod(a, v);
fields(a, g.ended, g.dry, g.wet, g.mix);
fields(a, g.ended, g.dry, g.wet, g.mix, g.irqAddress, g.irqEnabled);
for (Volume &v : g.master)
pod(a, v);
for (Volume &v : g.effect)
@@ -59,6 +59,7 @@ namespace bozo::audio
pod(a, c);
for (Callback &c : s.transHandler)
pod(a, c);
pod(a, s.spu2Handler);
for (auto &e : s.effect)
pod(a, e);
a.end();
+26 -3
View File
@@ -23,9 +23,9 @@ namespace bozo::audio
constexpr uint32_t kKon = 0x1500u, kKoff = 0x1600u, kEndX = 0x1700u, kVMixL = 0x1800u, kVMixEL = 0x1900u,
kVMixR = 0x1A00u, kVMixER = 0x1B00u;
// Addresses.
constexpr uint32_t kEea = 0x1D00u, kTsa = 0x1E00u, kSsa = 0x2040u, kLsax = 0x2140u, kNax = 0x2240u;
constexpr uint32_t kEea = 0x1D00u, kTsa = 0x1E00u, kIrqa = 0x1F00u, kSsa = 0x2040u, kLsax = 0x2140u, kNax = 0x2240u;
// Core attributes.
constexpr uint32_t kEffectEnable = 0x2u;
constexpr uint32_t kEffectEnable = 0x2u, kIrqEnable = 0x4u; // SD_CORE_EFFECT_ENABLE, SD_CORE_IRQ_ENABLE
int coreOf(uint32_t entry)
{
@@ -59,11 +59,13 @@ namespace bozo::audio
{
m_mixer.setInputHalfCallback([this](int group, int half)
{ inputHalf(static_cast<uint32_t>(group), static_cast<uint32_t>(half)); });
m_mixer.setIrqCallback([this](int core) { spu2Interrupt(core); });
}
Libsd::~Libsd()
{
m_mixer.setInputHalfCallback({});
m_mixer.setIrqCallback({});
}
uint32_t Libsd::physical(uint32_t address)
@@ -226,6 +228,8 @@ namespace bozo::audio
}
if ((entry & 0xFF00u) == kTsa)
m_state.transferAddress[core] = value;
if ((entry & 0xFF00u) == kIrqa)
m_mixer.setIrqAddress(core, value);
if ((entry & 0xFF00u) == kEea)
m_state.effectEnd[core] = value | 0x1FFFFu;
m_state.addresses[entry & 0xFF01u] = value;
@@ -251,6 +255,8 @@ namespace bozo::audio
{
if ((entry & ~1u) == kEffectEnable)
m_mixer.setEffectEnable(coreOf(entry), value != 0u);
if ((entry & ~1u) == kIrqEnable)
m_mixer.setIrqEnabled(coreOf(entry), value != 0u);
m_state.coreAttributes[entry] = value;
}
@@ -455,6 +461,23 @@ namespace bozo::audio
return previous;
}
// sceSdSetSpu2IntrHandler(handler, argument): the SPU2's interrupt (a core's IRQ address reached) calls
// handler(1 << core, argument) as an interrupt handler.
uint32_t Libsd::setSpu2IntrHandler(uint32_t function, uint32_t argument, uint32_t gp)
{
sync();
const uint32_t previous = m_state.spu2Handler.function;
m_state.spu2Handler = Callback{function, argument, gp};
return previous;
}
void Libsd::spu2Interrupt(int core)
{
const Callback &handler = m_state.spu2Handler;
if (handler.function != 0u)
m_host.interruptCall(handler.function, 1u << core, handler.argument, handler.gp, kTransferDelay);
}
uint32_t Libsd::setIrqCallback(uint32_t function)
{
sync();
@@ -661,7 +684,7 @@ namespace bozo::audio
case 32u: result = setEffectMode(a[0], a[1]); return true;
case 33u: result = setEffectModeParams(a[0], a[1]); return true;
case 26u: result = setTransIntrHandler(a[0], a[1], a[2], gp); return true;
case 27u: sync(); return true; // sceSdSetSpu2IntrHandler
case 27u: result = setSpu2IntrHandler(a[0], a[1], gp); return true;
case 13u: result = note2Pitch(a[0], a[1], a[2], a[3]); return true;
case 14u: result = pitch2Note(a[0], a[1], a[2]); return true;
case 28u: result = transIntrHandlerArgument(a[0]); return true;
+38
View File
@@ -128,6 +128,7 @@ namespace bozo::audio
for (uint32_t i = 0; i < bytes; ++i)
m_memory[(address + i) % kSoundMemory] = data[i];
m_stats.uploaded += bytes;
reachIrq(address, bytes);
}
void Mixer::read(uint32_t address, uint8_t *data, uint32_t bytes) const
@@ -224,6 +225,7 @@ namespace bozo::audio
voice.loopSet = false;
g.ended &= ~(1u << index);
decode(voice);
reachIrq(voice.block, 16u);
++m_stats.keyOns;
}
}
@@ -492,6 +494,41 @@ namespace bozo::audio
m_inputHalf = std::move(half);
}
void Mixer::setIrqAddress(int group, uint32_t address)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_groups[group].irqAddress = address & (kSoundMemory - 1u);
}
void Mixer::setIrqEnabled(int group, bool enabled)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_groups[group].irqEnabled = enabled;
}
void Mixer::setIrqCallback(std::function<void(int group)> irq)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_irq = std::move(irq);
}
void Mixer::reachIrq(uint32_t address, uint32_t bytes)
{
address &= kSoundMemory - 1u;
for (int g = 0; g < 2; ++g)
{
Group &group = m_groups[g];
if (!group.irqEnabled)
continue;
const uint32_t offset = (group.irqAddress - address) & (kSoundMemory - 1u);
if (offset >= bytes)
continue;
group.irqEnabled = false;
if (m_irq)
m_irq(g);
}
}
void Mixer::decode(Voice &voice)
{
const uint8_t *block = &m_memory[voice.block & (kSoundMemory - 16u)];
@@ -582,6 +619,7 @@ namespace bozo::audio
else
voice.block = (voice.block + 16u) & (kSoundMemory - 1u);
decode(voice);
reachIrq(voice.block, 16u);
}
return value;
}
+4 -1
View File
@@ -77,7 +77,8 @@ namespace bozo::audio
uint32_t blockTransStatus(uint32_t channel);
uint32_t setTransCallback(uint32_t channel, uint32_t function, uint32_t gp); // 21
uint32_t setTransIntrHandler(uint32_t channel, uint32_t function, uint32_t argument, uint32_t gp); // 26
uint32_t setIrqCallback(uint32_t function); // 22
uint32_t setIrqCallback(uint32_t function);
uint32_t setSpu2IntrHandler(uint32_t function, uint32_t argument, uint32_t gp); // 27 // 22
uint32_t setEffectAttr(uint32_t core, uint32_t attr); // 23: attr {core, mode, depth L/R, delay, feedback}
uint32_t getEffectAttr(uint32_t core, uint32_t attr); // 24
uint32_t setEffectMode(uint32_t core, uint32_t attr); // 32: the mode, its delay, feedback and depth 0
@@ -101,6 +102,7 @@ namespace bozo::audio
uint32_t batchOne(uint32_t function, uint32_t entry, uint32_t value);
void transferDone(uint32_t channel);
void inputHalf(uint32_t channel, uint32_t half);
void spu2Interrupt(int core); // the mixer reached a core's IRQ address
uint32_t blockPosition(uint32_t channel);
uint32_t physical(uint32_t address);
@@ -123,6 +125,7 @@ namespace bozo::audio
uint32_t transferAddress[2] = {};
Callback transCallback[2], transHandler[2]; // per DMA channel
uint32_t irqCallback = 0;
Callback spu2Handler; // sceSdSetSpu2IntrHandler: handler(core bit, argument) at the SPU2's interrupt
uint32_t blockBuffer[2] = {}, blockSize[2] = {}; // the block transfer playing as each core's input
// The halves signalled and not yet read by sceSdBlockTransStatus (oldest first, at most two).
uint32_t halves[2][2] = {}, halvesPending[2] = {};
+10
View File
@@ -111,6 +111,12 @@ namespace bozo::audio
// Clocked: the IOP cycle at which the next input half ends (its half callback), 0 when no input plays.
uint64_t nextInputHalfCycle() const;
void setInputHalfCallback(std::function<void(int group, int half)> half);
// The SPU2's interrupt: a core's IRQ address (SD_A_IRQA) and its enable (SD_CORE_IRQ_ENABLE). Reached by a voice
// reading the 16-byte block that holds it (a block decoded, a key on) or a transfer writing over it, an enabled
// core calls irq(core) once and stays disabled until it is enabled again, as the SPU2's IRQ flag is cleared.
void setIrqAddress(int group, uint32_t address);
void setIrqEnabled(int group, bool enabled);
void setIrqCallback(std::function<void(int group)> irq);
// A port's stream, added to each output sample after the voices (null: none). It outlives its use here.
void setPortStream(PortStream *stream);
@@ -206,6 +212,8 @@ namespace bozo::audio
Reverb reverb;
uint16_t mix = 0xFF0u;
Input input;
uint32_t irqAddress = 0;
bool irqEnabled = false;
};
void decode(Voice &voice);
@@ -228,6 +236,8 @@ namespace bozo::audio
std::vector<uint8_t> m_memory = std::vector<uint8_t>(kSoundMemory, 0u);
Group m_groups[kGroups];
std::function<void(int group, int half)> m_inputHalf;
std::function<void(int group)> m_irq;
void reachIrq(uint32_t address, uint32_t bytes); // under m_mutex
PortStream *m_portStream = nullptr;
// takeMixed's digest.
std::mutex m_digestMutex;
+13
View File
@@ -1589,6 +1589,12 @@ namespace bozo::native::irx
// no pending operation; this is the SDK's terminal/error result.
ret(0xffffffffu);return;
}
// sceSifSetDChain (6): arms the SIF DMA's chain mode before a transfer; the native copies need nothing armed.
if (lib == "sifman" && n == 6)
{
ret();
return;
}
if (lib == "sifman" && (n == 5 || n == 29))
{
ret(1);
@@ -1691,6 +1697,13 @@ namespace bozo::native::irx
ret(a0);
return;
}
// sceSifCheckStatRpc(client): an IOP call to an EE service completes within sceSifCallRpc (below), so it is
// never in progress when asked: 0.
if (n == 18)
{
ret(0);
return;
}
if (n == 15)
{
const auto found = libraries.sif.eeServers.find(a1);