13 Commits
Author SHA1 Message Date
Thomas MartinandClaude Opus 5.5 7678d91bad libs: sceGsSyncV waits for the next vblank (opt-in, syncVWaitsForVblank)
A game that paces itself on the EE's timers and then calls sceGsSyncV gets
the console's wait: the EE clock goes on to the next vblank's start, and
the result is that field's parity. Off (the default, the reference's), the
frame ends at once, held to the frame period, with the parity of the frames
ended.

Amplitude's movie player waits 500 hblanks on timer 0, then sceGsSyncV:
two fields a picture with the wait, three with a frame end held to a whole
period.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 10:16:38 +01:00
Thomas MartinandClaude Opus 5.5 0b961a4f92 Reference checker: sceGsExecStoreImage answered as the reference's stub
The pinned match1p check stopped at frame 13736 from 5030dbb on: TMB's lens
flares in the attract demo read back through sceGsExecStoreImage inside
particleDraw (#62543255, six traced calls, each 0, no memory run), and the
library now refuses readback. The log host alone sets
Libraries::storeImageAsReference: without native graphics the call returns 0
and writes nothing, as the reference's stub. Ports and the free host keep the
refusal; native_graphics_tests covers both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 10:32:46 +01:00
Thomas MartinandClaude Opus 5.5 b408e4a80b Save states: read the libraries section written before gsVideo
13cddc4 (#132) added Libraries::gsVideo to the "libraries" section, ahead
of its "waits" sub-section, so every state saved before it failed to load
("a container count is out of range") and the game started from the boot.

Archive::nextIs(name): whether the next thing read is that section. The
libraries reader takes gsVideo only when "waits" is not next; an older
state leaves it unknown (zero: its fourth byte is always 3 once
ResetGraph set it), and the GS library's SetDefDispEnv and Z buffer
address then read ResetGraph's parameters from scratchpad 0x100, as the
library did when that state was written. What is written does not change.

bozo-state-tests (nextIs) and bozo-libs-tests pass. TTA (engine at
b6a1980 plus this): all 33 regression captures from its saved states are
identical to the baselines; without it none of them loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 03:02:25 +01:00
Thomas MartinandClaude Opus 5.5 13cddc4904 GS library: sceGsResetGraph's display mode kept in the library, not read back from the scratchpad
5030dbb made sceGsSetDefDispEnv and the Z buffer's address read the display mode back from scratchpad 0x100, where
the reference also leaves ResetGraph's parameters. The game's own code reuses that scratchpad afterwards (TMB from its
fourth frame), so SMODE2 and DISPLAY came out non-interlaced where the reference's are interlaced. TMB's pinned boot
check (tmb-check, boot.clg) diverged there at frame 4; it passes again: 3000 frames, all 4,650,558 records, draw lists
on every checked frame. Libraries::gsVideo keeps them (saved in the states); the scratchpad still gets them.

sceGsExecStoreImage's refusal names its caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 00:15:35 +01:00
Thomas MartinandClaude Opus 5.5 ef902f605a libmpeg: the SDK's demux (sdkDemux), picturesAhead; PAL console; block transfer status ahead
- MpegOptions::picturesAhead (was kPicturesAhead, 8): how far the demux reads ahead of the game. Shinobido's first
  audio packet comes 14 pictures into the stream and its player waits for 0x6000 bytes of it.
- MpegOptions::sdkDemux: sceMpegDemuxPssRing as the SDK runs it. Each packet's callback runs before the demux goes
  on (the calling thread waits for it), and a 0 from the sound callback ends the call before that packet, which the
  next call gives again; only whole packets are taken. Shinobido's PCM callback refuses a packet when its ring is
  full: with the queued callbacks a refused packet was lost, and the sound after an odd-sized one (4073 bytes) was
  read a byte off (noise from 28 s into its intro). A video callback's 0 is not waited for: the decoder takes the
  video from the demux and the game's own IPU input is never drained. Off by default (TMB unchanged).
- Libraries::palConsole: sceGsResetGraph's video mode 0 (the console's own standard) at 50 Hz on a PAL console.
- CompiledLibraries::useBlockTransStatusAhead: sceSdBlockTransStatus one 1 KB block ahead of the sample playing, as
  the SPU2's input DMA reports it (a driver keeping its ring full by it). Off by default (TMB's logged answers kept).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 18:30:07 +01:00
ArzarothandClaude Opus 5.5 cb547b5e29 [sc3/kernel-syscalls] feat(kernel): SetVSyncFlag and the sync-V callback at the native frame boundary
The flag and the CSR word are written, and the callback queued, where a game
frame ends (FreeHost::endFrame), never on the field clock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 20:58:56 +01:00
Thomas Martin 5030dbbe43 Replace native graphics device state with SDK services 2026-11-06 12:57:31 +01:00
Thomas Martin 64f6b22309 Skip unused image packets for native graphics ports 2026-11-06 12:40:54 +01:00
Thomas MartinandCodex f715d57887 Replace selected hardware instructions with native port operations
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]>
2026-11-06 11:18:08 +01:00
Thomas MartinandClaude Opus 5.5 7e2135c6f5 Phase 4 M0: match1p --pinned matches with TMB's overrides native (16000 of 16000 frames, every record)
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]>
2026-11-04 12:12:48 +01:00
Thomas MartinandClaude Opus 5.5 60a8d50e1f Phase 4 M0: a port's overrides run natively (bozo/port.h), the free host, the renderer's game side and the packs moved
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]>
2026-11-04 11:02:09 +01:00
Thomas MartinandClaude Opus 5.5 7d352fd72d Native libraries: the GS library (phase 3, batch A 2-3)
sceGsResetGraph, ResetPath, SetDefDispEnv, SetDefDrawEnv/2, SetDefClear, SetDefLoadImage, SetDefStoreImage,
PutDrawEnv, SyncPath and SyncV answered natively: the packets built as the reference did (the game's libgraph's
layout, with the reference's own differences: DISPLAY's DX 652, SBW/DBW = 1, a NOP VIF code, results 0), the display
mode, environments and transfers kept in GsState for the renderer. sceGsSyncV returns the parity of the frames
ended; its wait and frame end stay the runtime's frame boundary (Function::frameBoundary). A call cut by the end of
the run stays the log's. No kernel-side call was left in the log (docs section 4).

boot: 20,982 GS calls native, match1p: 117,534, 0 divergences; both match every frame and record.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 17:36:09 +01:00
Thomas MartinandClaude Opus 5.5 163e472342 Native libraries: the C library and libm (phase 3, batch A 1)
runtime/libs (bozo/libs): native functions bound by the game's symbol names, on a Guest that journals every write.
bozo-run --native checks each native call against its record (result registers, every byte written, cycles,
operations) and keeps native state in step with the calls the log still answers.

libc: memcpy, memset, strlen, strchr, strcpy, strcmp, strncat, sprintf, printf, malloc/free (the reference's heap:
16-byte first fit from SetupHeap's result, no headers; the reference's libmpeg takes 0x600 per sceMpegCreate),
rand/srand (the reference's 64-bit LCG, not the ELF's newlib rand). libm: sqrt, __ieee754_rem_pio2f (the reference's
single-step reduction), __kernel_sinf/cosf (the Universal CRT's sinf/cosf of x + y; open point L1 elsewhere).

boot: 242,588 calls native, match1p: 10,840,985, 0 divergences; both still match every frame and record.
docs/specs/libraries.md sections 1-3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 17:14:34 +01:00