17 Commits
Author SHA1 Message Date
Thomas MartinandClaude Opus 5.5 fd67f9e899 libmpeg: callbacks on the caller's thread (MpegOptions::callbacksOnCaller)
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]>
2026-11-29 13:39:05 +01:00
boubou666 a12742f4ed Merge pull request #161 from TheBozos/amp/mpeg-entries-in-work
libmpeg (SDK layout): stream callback entries in the work area, nothing from the game's heap
2026-11-27 10:47:13 +01:00
Thomas MartinandClaude Opus 5.5 553cac12f5 libmpeg (SDK layout): stream callback entries in the work area, nothing from the game's heap
Off the reference's layout, each stream callback's 32-byte entry came from
the engine's heap, which by default starts after the game's .bss, where a
game's own allocator works. Both handed out the same memory: Amplitude's
task manager list header was overwritten from the movie's first frame.

The entries now come from the last 64 x 32 bytes of the work area the game
gave sceMpegCreate (libmpeg's own memory, never read by the game), freed
as each handler ends. The reference's layout keeps the heap as before. A
save state from before has no in-use mask: it loads as none waiting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 10:41:01 +01:00
Thomas MartinandClaude Opus 5.5 7b3f7dff26 libs: sceIoctl's status poll, sceSifInitCmd, sceSifSetDChain, sceIpuInit; whole stream reads (opt-in)
What Amplitude_Recomp answered in its port, generic SDK behaviour:
- sceIoctl: request 1, the status a file opened with O_NOWAIT is polled with, is "done" (*arg = 0): the native
  sceOpen / sceRead have finished as they return. Any other request: -1.
- sceSifInitCmd, sceSifSetDChain, isceSifSetDChain: nothing to set up or arm (Onimusha_Recomp answered
  sceSifSetDChain the same way in its port).
- sceIpuInit: no IPU to reset.
- CdState::wholeStreamReads (off by default): a sceCdStRead that does not wait brings all its sectors or none,
  as a console's drive fills the stream ring a bank at a time. Amplitude's movie player resumes its demux at
  buffer + 0x4000 - bytes left and skipped a sector after a short read.
- texture.h: Texture::rgba carries the GS's alpha (0x80 opaque); the comment said 255.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 10:16:20 +01:00
Thomas MartinandClaude Opus 5.5 fb1b3eac16 libmpeg (sdkDemux): a demux call after a refused sound packet costs 0.2 ms of EE time
With sdkDemux, a sound packet the game's callback refuses (its ring full) ends the
demux call, and the next call offers it again, as the SDK does. On the console the
player's turn between two calls takes time (the demux, the IPU); here none, so a
player spinning until its sound thread made room ran the callback about 9,000 times a
field. Shinobido's movies took 23 ms of host time a field and played at 60% speed in
the window (and headless 80%), their sound starved.

The call after a refusal now costs 0.2 ms (l.callCycles: a pinned time still wins).
Shinobido's intro: 102 handlers a field instead of 9,300, 1.4 ms of host time instead
of 23, 25 pictures a second in the window; the pictures' EE timing unchanged (30
every 60 vblanks) and the movie's sound without a gap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 01:26:13 +01:00
Thomas MartinandClaude Opus 5.5 87c86077dc libmpeg: demux copies the stream in runs, not byte by byte
demux() and demuxOn() fed the pending buffer one read8 at a time (0x800 bytes per
sector, a guest translation each). appendStream copies whole runs out of the ring
(wrapping once) or the linear buffer. Shinobido's ending and credits movies decode
in 44 s headless instead of 3 min; picture and flip counts unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 21:08:30 +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
Thomas MartinandClaude Opus 5.5 b6dc6cd44f Merge JC2's save states (jc2/native-irx-host b73692e) into TTA's integration
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]>
2026-11-18 18:30:24 +01:00
Thomas MartinandClaude Opus 5.5 b73692ed37 Save states: the whole runtime saved and loaded at the dispatcher's safe point
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]>
2026-11-18 18:22:15 +01:00
ArzarothandClaude Opus 5.5 75ecd9b107 [ffop/native-movies-tail-overrides] fix(libmpeg): sceMpegDemuxPss (ring 0) reads its data where it is
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 04:09:58 +01:00
Thomas MartinandClaude Opus 5.5 c5d6408199 libmpeg: sceMpegInit returns the SDK's 1 off the reference layout, and resets nothing
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-10 00:05:07 +01:00
Thomas MartinandClaude Opus 5.5 54b5eb7ea3 libmpeg: sceMpegAddBs and MpegOptions for games on the SDK's model
libmpeg answered as TMB's reference build does: its sceMpeg layout (with
TMB's addresses: 0x1717bc, the table at 0x171800, 0x171904), blocks from the
game's heap, its results and its pacing. The Third Age uses libmpeg the SDK's
way: raw MPEG-2 video added with sceMpegAddBs from its Nodata callback, its
own 29.97 pacing, the end when the callback returns 0.

- sceMpegAddBs(mp, data, bytes): ((bytes + 19) >> 4) << 4 bytes of coded
  video to the decoder (what the SDK sends to the IPU); wakes a thread
  waiting in sceMpegGetPicture once a picture is decodable; 1.
- MpegOptions (Libraries::mpegOptions, kept across sceMpegCreate), all
  defaulting to today's behaviour:
  - referenceLayout off: nothing written outside the game's work area (the
    Nodata data is its first 32 bytes), the SDK's results (Create/Delete 1,
    AddCallback the previous callback);
  - paced off: GetPicture gives each picture at once, IsEnd answers from the
    stream (input ended, all pictures out);
  - sdkNodata: the Nodata callback gets the data given to AddCallback in a2,
    and a 0 it returns ends the input.

Test mpegSdkModel in libs_tests. TMB's path is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-10 00:04:28 +01:00
Thomas MartinandCodex 52461cf5de Finish native timing diagnostics and heat haze default
Enable the original game's heat distortion by default, retaining BOZO_HEAT_HAZE=0 for comparisons.
Measure movie cadence, correct the FMAC overflow tests, and keep temporary-context timer/checkpoint accounting
separate from the running thread. Pin recursive events at their exact recorded cycle/checkpoint when the
reference's context pc retains an inner caller. Add Windows and Linux CI for the native test suite.

Co-Authored-By: Codex <[email protected]>
2026-11-05 22:47:44 +01:00
Thomas MartinandClaude Opus 5.5 4d362485ea Native libraries from the stage runs (phase 4 M5): libmpeg's demux counts a picture read ahead from its first header (the Suburbs movie stops at 0xd000 bytes, stage-level0 #11640007); sceSifCallRpc writes the server data's packet address, reply mode and id (0) too (a level load had overwritten them, #13052622); a T0 write by the game keeps the last read, as the port's does (#13062314: read 0, wrote 0, read 0 is a poll)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 18:56:55 +01:00
Thomas MartinandClaude Opus 5.5 918a91a56f libmpeg: a playback the port says was aborted ends (sceMpegIsEnd 1: story's skipped stage movie, #9723824, the stream's own end never comes); a last picture the game took late is not over before an empty delivery (story's seventh movie, played a picture a game frame: #11644213 0, #11644909 1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 17:50:43 +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 5f4dbe208b Native libraries: libmpeg, the movies (phase 3, batch B2)
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]>
2026-11-03 19:51:34 +01:00