Skip to content

libmpeg (SDK layout): stream callback entries in the work area, nothing from the game's heap - #161

Merged
boubou666 merged 1 commit into
masterfrom
amp/mpeg-entries-in-work
Nov 27, 2026
Merged

boubou666 merged 1 commit into
masterfrom
amp/mpeg-entries-in-work

Conversation

@boubou666

Copy link
Copy Markdown
Contributor

What

With MpegOptions::referenceLayout off (the SDK's layout), each stream callback's 32-byte entry now comes from the end of the work area the game gave sceMpegCreate. Before, it came from the engine's heap.

  • The pool is 64 entries (2 KB): libmpeg's own memory, which the game never reads.
  • An entry is freed as its handler ends.
  • If the work area is too small, or every entry is still waiting, it falls back to the heap.

The reference's layout (TMB) is unchanged: entries still come from the heap, at the same addresses.

Why

The engine's heap defaults to the region from SetupHeap's result to the end of RAM, which is where a game's own allocator works. In Amplitude, libmpeg's entries and the game's own blocks shared the same memory. The task manager's list header was overwritten from the movie's first frame, and the task run after the intro had a null command. The port had to move the engine's heap into .text to avoid it.

With this change, off the reference layout, libmpeg takes nothing from the game's heap, so a port doesn't need that workaround for its movies.

Save states

The in-use mask is appended to the "mpeg" section. A state written before has no mask and loads with no entry waiting: its waiting entries are heap addresses, still freed to the heap.

Testing

Amplitude, with this branch merged locally with #150 and #160, and the port's heap move turned off:

  • It boots through the logos and the intro movie, sound included, to the title and the main menu.
  • Before this change, that run broke right after the intro.

Onimusha and Shinobido also run off the reference layout: their entries now come from their work areas too. I haven't run those ports.

🤖 Generated with Claude Code

…ng 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 <noreply@anthropic.com>
@boubou666
boubou666 merged commit a12742f into master Nov 27, 2026
4 checks passed
@boubou666
boubou666 deleted the amp/mpeg-entries-in-work branch November 27, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant