Sony's libmpeg calls the stream callbacks inside sceMpegDemuxPss / sceMpegDemuxPssRing and Nodata inside
sceMpegGetPicture, on the caller's thread. The native library queued them for whichever thread ran next, which
deadlocks Steambot Chronicles' player (Sony's sample): its video callback waits on the IPU input ring's lock held by
the thread it was stacked on. With the option on (off by default), each callback is a handler bound to the calling
thread and the call is made again after it: the demux going on from where it was, GetPicture calling Nodata again
until a picture is there.
- Kernel::queue(handler, thread): a handler that runs only on that thread; handlerQueuedFor(thread) for the
dispatcher's checks; the bindings saved in an optional section (older states load with none).
- Libraries::queueHandlerOn and restartCall: the free host stops the thread at the call's own address.
- MpegState::demuxResuming / demuxBytes, saved as an optional tail of the mpeg section.
- Tests: thread-bound handlers (handler_stacks), the demux and Nodata loop (mpeg_callbacks).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 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]>
Conflicts: libmpeg's Nodata end becomes a Resume record that keeps TTA's SDK callback (a[2] flags:
1 work area, 2 SDK callback; 0 is the reference's behaviour); cdvdman keeps JC2's drive commands and
TTA's sceCdSearchFile. TTA's state the archive did not have: libpad2's sockets, the IOP software
registers and libmpeg's inputEnded.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A state is taken at the top of Dispatcher::run's loop, where no guest code is on
the host stack: memory, the dispatcher, the kernel (threads, frames, queues,
deadlines), every library's state, the native IOP host (memory, tasks, kernel
objects, RPC servers, mixer, libsd) and sections ports add (state::Sections).
Parked library lambdas become data: Resume records and native deadline kinds,
rebuilt from tables on load; ports can add their own kinds. FreeHost serves
requestSave / requestLoad from any thread, rolls back a failed load, and takes
FreeOptions (gameTag, loadState[Frame], saveState[Frame]). Windows get ten slots:
F5 save, F7 load, F6 / Shift+F6 select, and a Save states tab in F2.
989SND's engine and a playing movie are not covered: a save waits, saying why.
docs/save-states.md tells a port how to use and check it; tests/runtime/state_tests.cpp
covers the archive, files and a dispatcher round trip.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
QueryMaxFreeMemSize (7) and QueryTotalFreeMemSize (8) answer from the native
heap. sceSifGetOtherData (23) copies from EE RAM when called.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
For games on a later SDK that read their controllers through libpad2 over
libdbc (The Third Age): scePad2Init/End, scePad2CreateSocket/DeleteSocket,
scePad2GetState (1 with a controller), scePad2GetButtonProfile (the DualShock
2's, four bytes), scePad2Read (the 18-byte report: buttons active low, sticks
RX RY LX LY, the twelve pressures in the controller's order), and
scePad2GetButtonInfo; libvib's sceVibGetProfile (0x03) and sceVibSetActParam
(the motors as libvib packs them, to the input's rumble); sceDbcInit/End.
The controllers are libpad's: the same ports, players and PadInput, so the
PC's devices and the frame-keyed scripts drive both libraries. Behaviour read
from The Third Age's libpad2 and how its pad manager uses each answer.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
SIF (sif): RPC bind and call with the reference's client and server-data words,
CheckStat, the SIF registers, module loading (ids only), reboot and sync, the
IOP heap (16-byte blocks, first fit, from 0x7fe60), SIF DMA ids.
989SND (snd), the IOP side of RPC service 0x123456: command batches (0x4a) and
direct calls decoded, the reply (-1, results, -1, a command with no result
leaving the driver's last one), banks loaded by sector from the disc image and
placed in IOP memory as the reference did, master volumes, reverb, stops,
streams, the movie buffer, handles and their liveness where it is certain. What
the reference's IOP time decided (one-shot sounds' lifetimes, the handler slots
they free) a pinned run takes from the log's reply (Function::logReply,
Pin::logWord); free mode has native models. The driver follows the 989SND calls
of port overrides answered from the log, and sends what should play to a
SoundSink for the future mixer.
boot and match1p --pinned: every frame and record, 0 divergences; sif 7,212 /
245,108 calls native; 989SND 3,591 / 119,225 replies native, 1 / 3,294 pinned.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
sceMpegInit, Create, Delete, Reset, AddCallback, AddStrCallback, DemuxPssRing, GetPicture, IsEnd and the reference's
stub of TMB's videoCallback, native, with the decoder-feeding protocol the reference had, call for call: the demux a
sector at a time up to 8 starts ahead of the game, its callbacks queued as RPC-callback handlers with 32-byte data from
the game's heap; GetPicture delivering at once, waiting for the vblank its picture is due at (two fields a picture),
or queueing the game's nodata callback and waiting for data (the handler's end or a demux wakes it); the empty
delivery and IsEnd's end of display time. Pictures are decoded by FFmpeg's mpeg2video (libavcodec, libavutil:
optional, BOZO_FFMPEG_ROOT else pkg-config; without it libmpeg stays answered from the log) and converted bit-exact
into the game's RGBA32 column-major macroblocks. The movie's PCM goes to a MovieSoundSink. The IPU transfer's
completion now follows the native libmpeg.
bozo-run: library handler completions made natively (Libraries::queueHandler), waits of any reason with a
continuation (Libraries::waitFor), and the memory check's run lookup by binary search (a picture meets thousands of
runs).
boot: 6,822 libmpeg calls native, match1p: 8,224, 0 divergences; both match on every frame and record.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every io-load and io-store of the logs answered by a model of only what the game observes (io.h, io.cpp): timer 0
(the count from EE time, a poll that reads the same count again leaves a period pending), the DMA channels (VIF0, VIF1
and GIF transfers complete at once with their D_STAT bit and DMAC interrupt; a GIF chain that draws is dropped as the
reference drops it; IPU_TO completes at the game's first store after libmpeg's decoder took it, and stops when STR is
cleared), D_CTRL, D_STAT, D_PCR (CPCOND0), D_ENABLER (0) and D_ENABLEW, and the GS's privileged registers (kept for
the renderer). The kernel's EnableDmac question (is D_STAT still set) is answered by the model.
Two points still live inside calls the logs answer whole and are followed: timer 0 restarted inside the port's frame
boundary (re-based on the log's next count), and the IPU's completion following libmpeg's nodata callbacks.
boot: 855,098 accesses native, match1p: 17,605,351, 0 divergences; both match on every frame and record.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The hierarchy image's eight programs (0x278 hierFovTest2Asm, 0x3a8, 0x410 hierMulEoForObjAsm, 0x450 hierCsUpdateAsm,
0x5a8 hier, 0x670 vu0HierRotateAsm, 0x808 hierTraverseAsm, 0xab0 hdHatSphereTestAsm) as native C++ on the calling
context's VU0 state and VU0 data memory, written from their microcode in the ELF and checked on every call of the logs
(every register word and data memory byte they change). The arithmetic is the reference's: single precision rounded
toward zero, VU0's adder dropping the smaller operand's bits below the larger one's last mantissa bit, MULA/MADDA/MADD
chains in the microcode's order, ADDbc vf0 moves turning -0 into +0, flags untouched (vu0.cpp is compiled with
-frounding-math -ffp-contract=off).
The image VU0 holds is the hierarchy one until a kick of the 2D chain (debug draws only) is seen.
boot: 374,583 calls native, match1p: 24,047,924, 0 divergences; both match on every frame and record.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
sceCdInit, sceCdMmode, sceCdDiskReady, sceFsReset, sceCdReadClock, sceCdRead, sceCdSync, sceCdGetError and the
stream (sceCdStInit, sceCdStStart, sceCdStRead, sceCdStStop) answered from an ISO 9660 image (bozo-run --iso, or
BOZO_ISO). Every sector a call or a stream continuation wrote in boot and match1p equals the image's.
Timed calls: a read takes a PS2 drive's time (114,400 EE cycles a sector) and a stream read waits for the vblank by
which its sectors have arrived (free mode). In a pinned run the reference's points (its IOP's) come from the log:
the call's EE time, whether it waited and until which vblank, and how much of a stream read had arrived (Libraries::pin).
A native library's wait with a completion (waitVblank) is finished by the library as its thread resumes; bozo-run
checks it against the log's MEM records of that point.
boot: 378 calls and 9 continuations native, match1p: 587 and 33, 0 divergences; both match on every frame and record.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
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]>