mirror of
https://github.com/TheBozos/Steambot_Chronicles_Recomp.git
synced 2026-12-01 21:33:22 -10:00
The town minimap is built each frame by 0x301e70 in the GS's memory, through textures 27 and 28: the map drawn into 27, its upper halves copied into 28 through a PSMCT16S view, multiplied there by a soft disc (ALPHA (Cd - Cs) x As), copied back. The port drew those work sprites on the screen (a white box at the top left) and had nothing for texture 27 (a white minimap). Native sites at 0x301e70 and its end 0x30238c now keep the sprites drawn in between, the picture is composed from them on the CPU (the map's colours, alpha = map alpha x disc alpha >> 7) and drawn wherever texture 27 is (SBC_NO_MINIMAP=1 the old way). Diagnostics: SBC_TRACE_2D prints each sprite's caller, SBC_DUMP_2D_TEXTURE=<id>,.. writes 2D textures out. Notes: the build's steps and the game's GS-state helpers (FRAME, SCISSOR, ALPHA, TEST, ZBUF, TEXA, TEX1, CLAMP, COLCLAMP/FBA). README: a Nefroburg screenshot. Co-authored-by: Thomas Martin <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
147 lines
8.5 KiB
C++
147 lines
8.5 KiB
C++
// Steambot Chronicles' native port boundary. No hardware execution or interpreter fallback.
|
|
//
|
|
// Overrides: each registerFunction(0x...) below is listed for bozo-externals by tools/sbc_overrides_list.py, so a direct
|
|
// call in the generated code reaches the port's function. Native instruction sites: each `case 0x...u: // native site`
|
|
// line is listed as a "native 0xADDR" external: the instruction is replaced by the handler, inline.
|
|
// docs/RECOMP_NOTES.md says why each one is there.
|
|
#include "sbc_port.h"
|
|
#include "bozo/ee/dispatcher.h"
|
|
#include "bozo/libs/guest.h"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
|
|
namespace sbc
|
|
{
|
|
namespace
|
|
{
|
|
bozo::libs::Libraries *gLibraries = nullptr;
|
|
|
|
// The file system's calls (sceOpen, sceCdSearchFile): the engine's own answer; SBC_TRACE_FILES=1 prints each
|
|
// one's path and result.
|
|
template <const char *Name> void traceFile(uint8_t *, R5900Context *ctx, Runtime *rt)
|
|
{
|
|
const bozo::libs::Function *f = gLibraries ? gLibraries->find(Name) : nullptr;
|
|
bozo::libs::Guest g(*rt, ctx);
|
|
const bool search = std::strcmp(Name, "sceCdSearchFile") == 0;
|
|
const std::string path = g.string(search ? g.arg(1) : g.arg(0));
|
|
const uint32_t ra = ctx->r[31].uw[0];
|
|
if (f)
|
|
f->handler(*gLibraries, g);
|
|
static const bool on = std::getenv("SBC_TRACE_FILES") != nullptr;
|
|
if (on)
|
|
std::printf("[sbc:file] %s(\"%s\") = %d (from %x)\n", Name, path.c_str(), ctx->r[2].sw[0], ra);
|
|
ctx->pc = ra;
|
|
}
|
|
[[maybe_unused]] constexpr char kSceOpen[] = "sceOpen", kSceCdSearchFile[] = "sceCdSearchFile";
|
|
|
|
[[maybe_unused]] void returnZero(uint8_t *, R5900Context *ctx, Runtime *)
|
|
{
|
|
ctx->r[2].ud[0] = 0;
|
|
ctx->pc = ctx->r[31].uw[0];
|
|
}
|
|
|
|
// The movie player (0x271390: Sony's sample, threads 0x2711b0 reading and demuxing, 0x273390 decoding) plays
|
|
// each movie to its end (runtime/sbc_movie.cpp shows the pictures); SBC_SKIP_MOVIES=1 skips them: its caller
|
|
// (the scene 0x143010) uses no result (docs/RECOMP_NOTES.md, "Movies").
|
|
void skipMovie(uint8_t *, R5900Context *ctx, Runtime *)
|
|
{
|
|
static const bool trace = std::getenv("SBC_TRACE_MOVIES") != nullptr;
|
|
if (trace)
|
|
std::printf("[sbc:movie] skipped (from %x)\n", ctx->r[31].uw[0]);
|
|
ctx->r[2].ud[0] = 0;
|
|
ctx->pc = ctx->r[31].uw[0];
|
|
}
|
|
|
|
bool nativeInstruction(uint8_t *rdram, R5900Context *ctx, Runtime *rt, uint32_t pc)
|
|
{
|
|
switch (pc)
|
|
{
|
|
case 0x0025f0dcu: // native site: sw a0,-0x7000(v1): VIF1 CHCR = 0x145, the frame's chain (sbc_render.cpp)
|
|
return render::kick(rdram, ctx, rt);
|
|
// The graphics registers the game's own code touches (sbc_render.cpp registerSite): no DMAC, VIF or GS.
|
|
case 0x0025f09cu: // native site: sw zero,-0x6fe0(v0): the kick's D1_QWC
|
|
case 0x0025f0a4u: // native site: sw v1,-0x6fd0(v0): the kick's D1_TADR
|
|
case 0x00264438u: // native site: sd v1,0x1000(v0): CSR = 2 (FINISH cleared) before the kick
|
|
case 0x002644ccu: // native site: ld v1,0x1000(v0): CSR in the vblank handler (FIELD)
|
|
case 0x0026471cu: // native site: ld v1,0x1000(v0): CSR in the GS handler (FINISH)
|
|
case 0x0026479cu: // native site: sd v1,0x1000(v0): CSR = 2 in the GS handler
|
|
case 0x0026f494u: // native site: ld a0,0x1000(v0): CSR (FIELD)
|
|
case 0x002633ccu: // native site: lw a0,(s0): D2_CHCR before the draw environment's sceDmaSend (0x263060)
|
|
case 0x002633e4u: // native site: sw v0,(s0): D2_CHCR (TTE off)
|
|
case 0x00264be0u: // native site: lw a0,(s1): D2_CHCR before the clear's sceDmaSend
|
|
case 0x00264bf8u: // native site: sw v0,(s1): D2_CHCR (TTE off)
|
|
// The display mode functions (0x263790, 0x263b34, 0x263ec4): PMODE, DISPFB1/2, DISPLAY1/2, EXTWRITE.
|
|
case 0x00263790u: // native site: sd a0,(v1): PMODE
|
|
case 0x002637a8u: // native site: sd a0,0x90(v1): DISPFB2
|
|
case 0x002637ccu: // native site: sd a1,0xa0(v1): DISPLAY2
|
|
case 0x002637d4u: // native site: sd a1,0x70(v1): DISPFB1
|
|
case 0x002637d8u: // native site: sd a0,0x80(v1): DISPLAY1
|
|
case 0x002637dcu: // native site: sd zero,0xd0(v1): EXTWRITE
|
|
case 0x00263b34u: // native site: sd: PMODE
|
|
case 0x00263b4cu: // native site: sd: DISPFB2
|
|
case 0x00263b70u: // native site: sd: DISPLAY2
|
|
case 0x00263b78u: // native site: sd: DISPFB1
|
|
case 0x00263b7cu: // native site: sd: DISPLAY1
|
|
case 0x00263b80u: // native site: sd: EXTWRITE
|
|
case 0x00263ec4u: // native site: sd: PMODE
|
|
case 0x00263edcu: // native site: sd: DISPFB2
|
|
case 0x00263f00u: // native site: sd: DISPLAY2
|
|
case 0x00263f08u: // native site: sd: DISPFB1
|
|
case 0x00263f0cu: // native site: sd: DISPLAY1
|
|
case 0x00263f10u: // native site: sd: EXTWRITE
|
|
return render::registerSite(rdram, ctx, rt, pc);
|
|
case 0x00238a90u: // native site: addiu sp,sp,-0x110, the type-72 prelight's lit bake (a trace)
|
|
return draw3d::bakeSite(rdram, ctx, rt, pc);
|
|
case 0x00238c80u: // native site: ld ra,0xa0(sp), the lit bake's end (a trace)
|
|
return draw3d::bakeEndSite(rdram, ctx, rt, pc);
|
|
case 0x001af6a0u: // native site: addiu sp,sp,-0xb0, ScrnEffHueAdd's first instruction (the haze's place)
|
|
return draw3d::hazeSite(rdram, ctx, rt, pc);
|
|
case 0x0025ec40u: // native site: addiu sp,sp,-0x10, DmaBeginPacket's first instruction (a bucket switch)
|
|
return draw3d::bucketSite(rdram, ctx, rt, pc);
|
|
case 0x00238d80u: // native site: lw v0,-0x7c60(gp) in the IMD type-32 material driver (s0 the primitive)
|
|
return draw3d::colourMaterialSite(rdram, ctx, rt, pc);
|
|
case 0x002390fcu: // native site: lw v0,-0x7c60(gp) in the IMD type-33 material driver: its TEXimage (s1)
|
|
return draw3d::materialSite(rdram, ctx, rt, pc);
|
|
case 0x0023a898u: // native site: lw a0,-0x7d5c(gp) in the IMD type-88 driver, after its bone matrices (0x23aea0)
|
|
return draw3d::skinnedSite(rdram, ctx, rt, pc);
|
|
case 0x0013eec0u: // native site: lw v1,0x1b4(s5) in the water plane's draw 0x13ed10, after its TexGetTEXimage
|
|
return draw3d::waterImageSite(rdram, ctx, rt, pc);
|
|
case 0x0013f1fcu: // native site: lw v0,0x44c(sp) in 0x13ed10, its material and lights staged
|
|
return draw3d::waterSite(rdram, ctx, rt, pc);
|
|
case 0x0023bc28u: // native site: lw v1,-0x7d5c(gp) in the IMD type-100 driver, after its morph set-up (0x23c0b0)
|
|
return draw3d::morphSite(rdram, ctx, rt, pc);
|
|
case 0x00301e70u: // native site: addiu sp,sp,-0x110, the town minimap's build (its sprites into textures 27, 28)
|
|
case 0x0030238cu: // native site: ld ra,0x90(sp), the minimap build's end (both of its paths)
|
|
return draw2d::minimapSite(rdram, ctx, rt, pc);
|
|
default: return probe::site(rdram, ctx, rt, pc);
|
|
}
|
|
}
|
|
} // namespace
|
|
|
|
void setLibraries(bozo::libs::Libraries *libraries) { gLibraries = libraries; }
|
|
bozo::libs::Libraries *libraries() { return gLibraries; }
|
|
|
|
void install(Runtime &, bozo::port::Registry &r)
|
|
{
|
|
// The boot's stops, answered one by one (docs/RECOMP_NOTES.md, "Boot").
|
|
// sceVpu0Reset (libvu0): resets VU0 and VIF0 through VIF0_FBRST (0x10003830) and VU0's registers. No VU0 or VIF0
|
|
// hardware is modelled, so there is nothing to reset. Called once, by the game's graphics init 0x263fc0
|
|
// between sceGsResetPath and sceGsResetGraph.
|
|
r.registerFunction(0x2405f0, returnZero);
|
|
if (std::getenv("SBC_SKIP_MOVIES"))
|
|
r.registerFunction(0x271390, skipMovie);
|
|
// SBC_TRACE_FILES=1: the file system's opens and searches with their results (the engine answers them).
|
|
if (std::getenv("SBC_TRACE_FILES"))
|
|
{
|
|
r.registerFunction(0x250968, traceFile<kSceOpen>); // sceOpen
|
|
r.registerFunction(0x259608, traceFile<kSceCdSearchFile>); // sceCdSearchFile
|
|
}
|
|
draw2d::install(r);
|
|
draw3d::install(r);
|
|
movie::install(r);
|
|
r.nativeGraphics(&nativeInstruction);
|
|
}
|
|
} // namespace sbc
|