Files
Thomas MartinandClaude Opus 5.5 504146fa8c In game: the first map in 3D, models drawn natively (rigid, prelit, skinned) with their lighting
BozoEngine d937cae (TheBozos/BozoEngine#170, native sceSifGetOtherData): the game's file loader takes every file back
from its IOP buffer, so the map's models and textures load (they were zeros) and the opening scene goes on.
runtime/sbc_3d.cpp: IMD types 72 and 73 answered (strip flags, a prelit colour for 73), type 88 skinned at a native
site after the driver's bone matrices, the VU program's lights applied where the primitive asks, alpha test and TCC.
The kick no longer marks a FINISH as missed. Probes print the game's debug messages and loader requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 14:51:31 +01:00

110 lines
4.7 KiB
C++

// Steambot Chronicles' IOP modules: Sony's modular synthesizer, the CD streamer CDVDSTM and Irem's IREMSND, statically
// compiled from the player's disc (tools/sbc_bozo_audio.py) and run by BozoEngine's native IRX host. The game reaches
// them through SIF RPC (IREMSND's server 0x12346) exactly as on the console's IOP; no IOP is modelled.
// (From Onimusha_Recomp's oni_audio.cpp.)
//
// The game's loader 0x25fd40 walks IOP/IOP.DAT's table, sends each module's bytes to an IOP heap block with
// sceSifSetDma and starts it with sceSifLoadModuleBuffer(block, 0, 0). The override below finds which module the block
// holds (its size and FNV-1a hash, listed by the generator) and starts the compiled image of that name.
#include "sbc_audio_modules.h"
#include "sbc_port.h"
#include "bozo/libs/guest.h"
#include "bozo/libs/libraries.h"
#include "bozo/state.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <memory>
#include <string>
namespace sbc
{
namespace
{
std::unique_ptr<bozo::native::irx::CompiledLibraries> sound;
uint64_t fnv1a(const uint8_t *p, size_t n)
{
uint64_t h = 0xCBF29CE484222325ull;
for (size_t i = 0; i < n; ++i)
h = (h ^ p[i]) * 0x100000001B3ull;
return h;
}
// The IOP.DAT module in the IOP block at `address`, or nullptr.
const SbcIopModule *moduleAt(uint32_t address)
{
for (const SbcIopModule &m : kSbcIopModules)
{
try
{
const std::span<uint8_t> view = sound->allocatedBuffer(address, m.size);
if (view.size() == m.size && fnv1a(view.data(), view.size()) == m.hash)
return &m;
}
catch (const std::exception &)
{
// Smaller than this module: not it.
}
}
return nullptr;
}
// sceSifLoadModuleBuffer(iopAddress, argLength, args) and its ...Start form (a3: int *result).
template <bool Start> void loadModuleBuffer(uint8_t *, R5900Context *ctx, Runtime *rt)
{
bozo::libs::Guest g(*rt, ctx);
const uint32_t address = g.arg(0), result = Start ? g.arg(3) : 0;
const SbcIopModule *m = moduleAt(address);
int32_t id;
std::string name = m ? m->name : "?";
// Answered at their EE APIs by BozoEngine's native pad and memory-card libraries.
if (m && (name == "SIO2MAN.IRX" || name == "PADMAN.IRX" || name == "MCMAN.IRX" || name == "MCSERV.IRX"))
id = 1;
else if (m)
id = sound->startImage(name + ";1");
else
id = -1;
static const bool trace = std::getenv("SBC_TRACE_MODULES") != nullptr;
if (trace || id < 0)
std::printf("[sbc:iop] sceSifLoadModuleBuffer(%x) = %s -> %d\n", address, name.c_str(), id);
if (result)
g.write32(result, 0);
ctx->r[2].sd[0] = id;
ctx->pc = ctx->r[31].uw[0];
}
} // namespace
void installAudio(bozo::libs::Libraries &libraries, bozo::port::Registry &r)
{
sound = std::make_unique<bozo::native::irx::CompiledLibraries>(libraries, kSbcAudioHeapStart);
addSbcAudioImages(*sound);
// IREMSND and CDVDSTM read the disc through cdvdman: the ISO's bytes, copied synchronously.
sound->useNativeDiscFiles();
libraries.audioProvider = [](uint64_t cycle) { return sound->advanceTo(cycle); };
libraries.sif.transfer = [](uint32_t address, const uint8_t *bytes, uint32_t count)
{ sound->writeBuffer(address, bytes, count); };
libraries.sif.allocateBuffer = [](uint32_t bytes) { return sound->allocateBuffer(bytes); };
// sceSifGetOtherData: the game's file loader reads the disc into an IOP buffer (sceCdReadIOPm) and takes each
// file back from it.
libraries.sif.receive = [](uint32_t address, uint8_t *out, uint32_t bytes)
{
try
{
const std::span<uint8_t> view = sound->allocatedBuffer(address, bytes);
std::memcpy(out, view.data(), bytes);
return true;
}
catch (const std::exception &)
{
return false;
}
};
libraries.sif.freeBuffer = [](uint32_t address) { return sound->freeBuffer(address); };
libraries.sif.resetProvider = [] { sound->reset(); };
r.registerFunction(0x254578, loadModuleBuffer<false>); // sceSifLoadModuleBuffer
r.registerFunction(0x254598, loadModuleBuffer<true>); // sceSifLoadStartModuleBuffer
}
} // namespace sbc