feat(ampr): implement the command buffer markers #538

Merged
DotDebian merged 1 commit from upstream-pr/538 into main 2026-10-04 21:23:03 +00:00
DotDebian commented 2026-10-04 16:10:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-04T16:10:56Z.


What

Implements the AMPR command buffer markers, which threw not implemented:

  • sceAmprCommandBufferPushMarker, PushMarkerWithColor, PopMarker, SetMarker, SetMarkerWithColor append a marker command (header, then the NUL-terminated text padded to 8 bytes; pop is the header alone).
  • sceAmprMeasureCommandSizePushMarker, PushMarkerWithColor, PopMarker, SetMarker, SetMarkerWithColor return the size the matching call appends.
  • The APR executor skips the three marker opcodes, as it does a nop. In the console encoding, as ampr_emu packs it, a marker is a typed nop record, so it has no effect on execution there either.

A null text, a null buffer object and a null color pointer return SCE_KERNEL_ERROR_EINVAL; the measure functions return it zero-extended. A buffer without room returns the error the other commands of this file already return, and leaves the offset and command count untouched.

Source for the signatures and the argument checks: the ampr_emu reimplementation of libSceAmpr (src/sceampr_exports.cpp, src/ampr_emu_command_buffer.cpp, commit cfa85df). No code is taken from it: the command encoding here is AnyPS5's own, as AprCommandBuffer.hpp states.

Limits, recorded in TechnicalDebt:

  • The signatures are not confirmed on a title. sceAmprCommandBufferSetMarkerWithColor takes the color by pointer while the push and measure variants take it by value; the pointer is checked for null but not read.
  • Colors are not recorded, as for the Agc markers.

Not in this PR: sceAmprCommandBufferConstructMarker, the nop functions and the _04_00 variants stay unimplemented. A marker is one command here whatever its length; on the console a text longer than 60 bytes spans several records.

The test needed a CMakeLists.txt for libSceAmpr; the library is built as before.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, ctest: 184/184 pass. New test guest_ampr_markers (core/libs/tests/GuestAmpr.cpp): each call advances the offset by the measured size and adds one command, the recorded text is intact, the rejected arguments and the full buffer leave the buffer unchanged, and sceKernelAprSubmitCommandBuffer runs a buffer that mixes markers with WriteAddress commands. The test fails on main with sceAmprCommandBufferPushMarker not implemented.

No title was run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (#407 appends to the same Export.cpp; the two merge cleanly)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4735769742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/538). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-04T16:10:56Z. --- ### What Implements the AMPR command buffer markers, which threw `not implemented`: - `sceAmprCommandBufferPushMarker`, `PushMarkerWithColor`, `PopMarker`, `SetMarker`, `SetMarkerWithColor` append a marker command (header, then the NUL-terminated text padded to 8 bytes; pop is the header alone). - `sceAmprMeasureCommandSizePushMarker`, `PushMarkerWithColor`, `PopMarker`, `SetMarker`, `SetMarkerWithColor` return the size the matching call appends. - The APR executor skips the three marker opcodes, as it does a nop. In the console encoding, as ampr_emu packs it, a marker is a typed nop record, so it has no effect on execution there either. A null text, a null buffer object and a null color pointer return `SCE_KERNEL_ERROR_EINVAL`; the measure functions return it zero-extended. A buffer without room returns the error the other commands of this file already return, and leaves the offset and command count untouched. Source for the signatures and the argument checks: the [ampr_emu](https://github.com/drakmor/ampr_emu) reimplementation of libSceAmpr (`src/sceampr_exports.cpp`, `src/ampr_emu_command_buffer.cpp`, commit cfa85df). No code is taken from it: the command encoding here is AnyPS5's own, as `AprCommandBuffer.hpp` states. Limits, recorded in TechnicalDebt: - The signatures are not confirmed on a title. `sceAmprCommandBufferSetMarkerWithColor` takes the color by pointer while the push and measure variants take it by value; the pointer is checked for null but not read. - Colors are not recorded, as for the Agc markers. Not in this PR: `sceAmprCommandBufferConstructMarker`, the nop functions and the `_04_00` variants stay unimplemented. A marker is one command here whatever its length; on the console a text longer than 60 bytes spans several records. The test needed a `CMakeLists.txt` for libSceAmpr; the library is built as before. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, `ctest`: 184/184 pass. New test `guest_ampr_markers` (`core/libs/tests/GuestAmpr.cpp`): each call advances the offset by the measured size and adds one command, the recorded text is intact, the rejected arguments and the full buffer leave the buffer unchanged, and `sceKernelAprSubmitCommandBuffer` runs a buffer that mixes markers with `WriteAddress` commands. The test fails on `main` with `sceAmprCommandBufferPushMarker not implemented`. No title was run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#407 appends to the same `Export.cpp`; the two merge cleanly) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-04 16:11:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T16:11:18Z.


Progress report (2cf901b → 638d380)

📈 System libraries: 77.66% (+0.31%, +10 implemented functions)

✅ 10 implemented
Library Name
libSceAmpr sceAmprCommandBufferPopMarker
libSceAmpr sceAmprCommandBufferPushMarker
libSceAmpr sceAmprCommandBufferPushMarkerWithColor
libSceAmpr sceAmprCommandBufferSetMarker
libSceAmpr sceAmprCommandBufferSetMarkerWithColor
libSceAmpr sceAmprMeasureCommandSizePopMarker
libSceAmpr sceAmprMeasureCommandSizePushMarker
libSceAmpr sceAmprMeasureCommandSizePushMarkerWithColor
libSceAmpr sceAmprMeasureCommandSizeSetMarker
libSceAmpr sceAmprMeasureCommandSizeSetMarkerWithColor
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5981950706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/538#issuecomment-5981950706). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T16:11:18Z. --- <!-- progress-report --> ### Progress report (2cf901b → 638d380) 📈 **System libraries**: 77.66% (+0.31%, +10 implemented functions) <details> <summary>✅ 10 implemented</summary> | Library | Name | | - | - | | libSceAmpr | `sceAmprCommandBufferPopMarker` | | libSceAmpr | `sceAmprCommandBufferPushMarker` | | libSceAmpr | `sceAmprCommandBufferPushMarkerWithColor` | | libSceAmpr | `sceAmprCommandBufferSetMarker` | | libSceAmpr | `sceAmprCommandBufferSetMarkerWithColor` | | libSceAmpr | `sceAmprMeasureCommandSizePopMarker` | | libSceAmpr | `sceAmprMeasureCommandSizePushMarker` | | libSceAmpr | `sceAmprMeasureCommandSizePushMarkerWithColor` | | libSceAmpr | `sceAmprMeasureCommandSizeSetMarker` | | libSceAmpr | `sceAmprMeasureCommandSizeSetMarkerWithColor` | </details>
oneandonlydean commented 2026-10-04 21:19:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:19:17Z.


Thanks. The measure functions return exactly what the append functions write, a full buffer leaves the offset and command count alone, and the executor skips the three opcodes like a nop. The new CMakeLists.txt builds the library the same way the generic rule in core/libs/CMakeLists.txt did.

About the TechnicalDebt line: PPSA21564 confirms the signatures. It imports these markers, and its wrapper for sceAmprCommandBufferSetMarkerWithColor (eboot offset 0x1d9e0) gets the color in edx, stores it on the stack, and passes a pointer to it in rdx. The PushMarkerWithColor, PushMarker and PopMarker wrappers are plain tail jumps, so the color goes by value there. That matches ampr_emu. You could change the line to say the signatures are confirmed and only the colors are dropped, but that's optional. Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984494397 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/538#issuecomment-5984494397). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:19:17Z. --- Thanks. The measure functions return exactly what the append functions write, a full buffer leaves the offset and command count alone, and the executor skips the three opcodes like a nop. The new `CMakeLists.txt` builds the library the same way the generic rule in `core/libs/CMakeLists.txt` did. About the TechnicalDebt line: PPSA21564 confirms the signatures. It imports these markers, and its wrapper for `sceAmprCommandBufferSetMarkerWithColor` (eboot offset 0x1d9e0) gets the color in `edx`, stores it on the stack, and passes a pointer to it in `rdx`. The `PushMarkerWithColor`, `PushMarker` and `PopMarker` wrappers are plain tail jumps, so the color goes by value there. That matches ampr_emu. You could change the line to say the signatures are confirmed and only the colors are dropped, but that's optional. Ready to merge from my side.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!538
No description provided.