A game may load a module into another's span (JC2: a battle effect at
0x96B000 over the tail of the Arena's lesson script at 0x96A800). Both
headers then match and moduleAt threw "ambiguous native module identity",
ending the run. Where two resident modules cover an address, the one
starting higher wins; each module keeps the lowest other start inside its
span as the limit of the last-module fast path. Same-start ambiguity still
throws. Runtime test added.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- vblank 7 (WaitNonVblank) returns at once: there is no display, so never a
vblank to wait out (Jade Cocoon 2's M2SOUND).
- FunctionTable::moduleAt scanned every module on every lookup (JC2
registers 1,383 overlay modules, 559 of them sharing 0x940000, so each call
into a slot compared up to 559 headers). It now rejects addresses outside
the span all modules cover at once, and asks the module found last first,
identity checked; the full scan with its ambiguity check is unchanged when
that misses.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Allow ports to replace output instructions and completion tests before MMIO, including delay slots. Keep original instructions and store PCs for reference checkers, and guard retired graphics I/O in native mode. Native draws no longer need GS environment register mirroring.
Validation: five CTest checks pass, including all 146 instruction cases and six new native replacement/completion cases; TMB windowed movies and four-player gameplay pass with the graphics guard enabled.
Co-Authored-By: Codex <[email protected]>
What match1p's overrides reached that only ran inside them before, each settled on its record:
- kernel.md 3b: a call that blocks inside an override leaves it right after the call (#16897525, the thread going on at
its return address); a recursive call's return leaves it (#17531043, texmInit's _M_erase); where the reference's
override left with the transfer flag is pinned at the first checkpoint at its pc once every traced call was made and,
unless a timed call inside took a time the log lacks, at its end cycle; a timed call inside waits when its traced
entry blocked.
- Generated code: the check after each call also leaves when ctx->leaving (a call that blocked at its own return
address); a recursive call's return inside an override calls bozo_leave.
- VU0: a result below the smallest normal is zero without the U flag (the reference never sets U: #41542199,
vu0MulMatrix3x3's mul; the capture samples still match).
- I/O: CPCOND0 counts completions from the last FlushCache (#17540836, hierCheckVifComplete; only with the port's
overrides native in bozo-run); a port's own T0 write keeps the last read (#34736003); the EE time a port charges
takes the pending poll cycles (#17538393, #17541951); a port's store patch leaves the store an out-call without its
effect (#62516600, TMB's dialog kick).
- GS: sceGsExecStoreImage reads zeros (no GS memory; TMB's flares outside a match, frame 13736); the H formats' image
tags (#16897863).
- The free host's watchdog (no frame for 600 fields ends the run, saying where the loop waits).
Docs: kernel.md 3b, libraries.md 5 and 11, r5900.md Q11, tools/run/README, phase4-m0-notes.md, PLAN phase 4 status.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
TMB_Recomp's runtime builds on BozoEngine (its branch bozo/m0, cmake -DTMB_BOZO=ON): its overrides run natively, each
call checked against the reference's log (tmb-check), and with no log at all (tmb-headless).
- Port API (runtime/include/bozo/port.h, bozo_port): Registry::registerFunction, BOZO_PORT, the startup check that
every registered override is an external of the generated code (port::undeclared), and what overrides use: the
kernel (changePriority, rotateReadyQueue, transfer), the EE clock (now, accountCycles), vblankCount, the hardware
registers (ioRead32 / ioWrite32: a port's own access), frameEnd, callLibrary, scratchpad, libraries, deterministic,
realTime, setStorePatch. A port::Host is behind them.
- Overrides that run guest code (kernel.md section 3b): checkpoints charge, no event is taken in place; an event due,
a call that blocks, a jump through a register, an inner call's return and a recursive call's return make guest code
leave the override there, the stop deferred to its end (Dispatcher::beginOutcall / leave / takeDeferredStop); the
override's own code runs on, as the reference's did; no exception goes through it. Every rule settled on a record.
- Generated code: bozo::checkpoint and bozo::innerReturn return true when guest code leaves, the check after each
call tests ctx->leaving, a recursive call's return inside an override calls bozo_leave; ctx->outcall,
ctx->leaving; the externals table (<prefix>_external_table); "store 0xADDR" externals (the store sets ctx->pc first).
- bozo-externals (tools/externals): the --externals list from the ELF's symbols BozoEngine answers, a port's stub names
and its override list; --check compares the stubs with a call log's.
- bozo-run as a library (bozo_run, run_main.h): a port's checker links it with its generated code and overrides,
which run natively (--overrides native|log); LogHost checks each call (context words, memory runs, traced calls, the
operations and frame end inside, where it left) and pins where the reference's override left and whether a timed
call inside it waited. The renderer's draw lists fill the record's draws (reported).
- The free host (runtime/host/free_host.cpp, bozo_host): every out-call native, libraries bound by the ELF's symbols,
free timing, a watchdog when no frame ends.
- Moved from the team's fork code (phase4-inventory.md 2.1, MIT headers): the renderer's game side
(bozo/render/renderer.h, renderer.cpp: headless, recording the published lists and their hash), Texture,
the texture and mesh packs, mesh_draw, the movie picture hook, the FramePacer (unpaced off real time) and
determinism.h (settable by the host).
- Libraries, from what only ran inside overrides before: sceGsExecLoadImage (0, no upload), T8H/T4HL/T4HH image tags as
32-bit texels, the GS CSR's FIELD, sceSifSetDma raising SIF0's DMAC interrupt, CPCOND0 counting completions from
the last FlushCache, a port's own register accesses, RotateThreadReadyQueue returning 0, libmpeg calling the movie
picture hook, PadState::multitap.
- BOZO_BUILD_TOOLS (zlib-free configure for a port), the tests only when top level.
Results: TMB boot --pinned with every override native, 3000 of 3000 frames and 4,650,558 of 4,650,558 records (ram,
scratchpad, calls, threads); match1p: see docs/phase4-m0-notes.md. bozo-run without a port still matches.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
runtime/ee: BozoEngine's own EE kernel (threads, ready queues, semaphores, INTC and DMAC handlers and their
queue, the vblank, the kernel calls TMB makes) and dispatcher (runs guest code on the kernel's threads and stacked
handlers, the reference's cycle model, stops by unwinding and resumes through the resume entries, time slices).
runtime/harness: the PS2XREF1 record (writer, reader, the calls and threads hashes). bozo/hash.h: XXH64, FNV-1a.
tools/run: bozo-run, TMB's generated code on that kernel with every other out-call answered from a call log and
every decision checked record by record against it; bozo-calllog-tool lists a log's external addresses for the
generator. Recompiler: jumps through a register go through bozo_jump (the reference's dispatcher), except the jump
tables it resolves itself (built in place); direct tail jumps are not charged; tail calls to externals go through
bozo_tail_call (the reference's record of calls only has jal and jalr).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Checkpoints now charge what calllog.md section 2 says the reference charges: 32 cycles at a taken backward branch or
jump to a label of the same function, 8 at a call or jump leaving the function (made before the transfer, with the
transfer's target in ctx->pc, so a thread stopped there resumes at the target), nothing at function entry or at a
return. A return leaves its target in ctx->pc.
Every function is now entered through a body taking an entry pc: its start, its extra entries, every label and the
return address after each call. The resume table (<prefix>_resume_table: each function's range and resume_0x<start>,
which enters it at ctx->pc) is how the phase 2 dispatcher runs a thread on from where it stopped, as the reference
does after a thread switch or a handler. bozo_resume_failed reports a pc that is not a label.
Phase 1's replay still matches 9,232 of 9,232 samples; the 139 instruction tests pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- runtime/: the runtime core (bozo/runtime.h): guest memory as the flat space (RAM, scratchpad, VU0 data), the
function table with an override table looked up first (ctx->pc holds the address an override was reached at),
COP0 Status (ei/di toggle EIE), and every other runtime_api.h request routed to a RuntimeServices interface.
- bozo-recomp: --externals <file> ("stub 0xADDR" / "override 0xADDR"): transfers to those addresses go through
bozo_call_indirect (stubs: any transfer; overrides: calls only, a direct jump runs the guest code); --files <n>
splits the output into exactly n files; a generated file is rewritten only when its contents change.
- tools/replay: a C++ PS2XCAP1 reader (zlib, XXH64), bozo-capture-tool (the externals list from the captures),
bozo-replay (one worker process per capture, every out-call answered from the log and checked, exit context and
every byte of the flat space compared, a crashed sample marked and skipped, a report per run and function).
- TMB's code is generated and compiled under the build folder when BOZO_TMB_ELF and BOZO_CAPTURES are set.
Co-Authored-By: Claude Opus 5.5 <[email protected]>