feat(libSceAgc): implement sceAgcCbCondWrite #975

Merged
hugodearaujo merged 1 commit from upstream-pr/975 into main 2026-10-07 02:17:27 +00:00
hugodearaujo commented 2026-10-06 20:58:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-06T20:58:10Z.


What

sceAgcCbCondWrite and sceAgcCbCondWriteGetSize threw. sceAgcCbCondWrite(buf, compareFunction, writeSpace, writeAddress, writeData, pollAddress, reference, mask) now writes the 9-dword COND_WRITE packet (opcode 0x45):

  • control: poll space memory (0x10), the compare function and the write space at bit 8;
  • the poll address, the reference and the mask;
  • the write address and the data.

sceAgcCbCondWriteGetSize returns 36.

Sources:

  • Argument order and layout: OpenAGC and sharpemu map each register and stack argument to the same packet dword. OpenAGC names the arguments differently, but the mapping is identical.
  • Header: OpenAGC gives the header the module emits, 0xc0074500, which is what Emit(0x45, ...) produces here.
  • Disagreement: SharpProspero declares a different order (poll address in the fourth argument). It was not followed, since the two implementations agree against it.

Validation follows sceAgcDcbWaitRegMem: compare function 0-6, 4-byte aligned non-null 48-bit addresses. The write space is accepted only as 1 (memory): OpenAGC shifts the raw value into bits 8-9, while sharpemu maps 2 to a register write, so 0 and 2 throw. Invalid input leaves the buffer untouched.

On main the AGC driver rejects a submitted COND_WRITE as an unknown opcode. #977 adds its validation and execution; the two PRs are independent. The sources and the write space limit are under "Unknown function info" in TechnicalDebt.

Tested

Linux (Arch, GCC), Release with BUILD_TESTING=ON, on current main. New agc_cb_cond_write_tests, built from sources like agc_cond_exec_patch_tests:

  • For compare functions 0-6, every packet dword is checked, the header against 0xc0074500, and the cursor advances 9 dwords.
  • GetSize returns 9 dwords.
  • These throw without touching the buffer: compare 7, write space 0 or 2, a null, misaligned or beyond-48-bit write or poll address.

Seven mutations each make the test fail: compare 7 allowed, other write spaces allowed, addresses swapped, reference and mask swapped, the 48-bit check removed, the wrong size, and the poll-memory bit dropped.

Full ctest: 360/360 passed. A simulated merge with every open PR shows no conflict caused by this branch. Not tested with a title.

tools/progress.py --compare against main: System libraries 87.07% (+0.07%, +2 implemented functions).

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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4764568183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/975). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-06T20:58:10Z. --- ### What `sceAgcCbCondWrite` and `sceAgcCbCondWriteGetSize` threw. `sceAgcCbCondWrite(buf, compareFunction, writeSpace, writeAddress, writeData, pollAddress, reference, mask)` now writes the 9-dword COND_WRITE packet (opcode 0x45): - control: poll space memory (0x10), the compare function and the write space at bit 8; - the poll address, the reference and the mask; - the write address and the data. `sceAgcCbCondWriteGetSize` returns 36. Sources: - **Argument order and layout:** [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/main/src/game_compat.c) and [sharpemu](https://github.com/sharpemu/sharpemu/blob/main/src/SharpEmu.Libs/Agc/AgcExports.CommandPackets.cs) map each register and stack argument to the same packet dword. OpenAGC names the arguments differently, but the mapping is identical. - **Header:** OpenAGC gives the header the module emits, 0xc0074500, which is what `Emit(0x45, ...)` produces here. - **Disagreement:** SharpProspero declares a different order (poll address in the fourth argument). It was not followed, since the two implementations agree against it. Validation follows `sceAgcDcbWaitRegMem`: compare function 0-6, 4-byte aligned non-null 48-bit addresses. The write space is accepted only as 1 (memory): OpenAGC shifts the raw value into bits 8-9, while sharpemu maps 2 to a register write, so 0 and 2 throw. Invalid input leaves the buffer untouched. On `main` the AGC driver rejects a submitted COND_WRITE as an unknown opcode. #977 adds its validation and execution; the two PRs are independent. The sources and the write space limit are under "Unknown function info" in TechnicalDebt. ### Tested Linux (Arch, GCC), Release with `BUILD_TESTING=ON`, on current `main`. New `agc_cb_cond_write_tests`, built from sources like `agc_cond_exec_patch_tests`: - For compare functions 0-6, every packet dword is checked, the header against 0xc0074500, and the cursor advances 9 dwords. - `GetSize` returns 9 dwords. - These throw without touching the buffer: compare 7, write space 0 or 2, a null, misaligned or beyond-48-bit write or poll address. Seven mutations each make the test fail: compare 7 allowed, other write spaces allowed, addresses swapped, reference and mask swapped, the 48-bit check removed, the wrong size, and the poll-memory bit dropped. Full `ctest`: 360/360 passed. A simulated merge with every open PR shows no conflict caused by this branch. Not tested with a title. `tools/progress.py --compare` against `main`: System libraries 87.07% (+0.07%, +2 implemented functions). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hugodearaujo commented 2026-10-06 21:41:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-06T21:41:42Z.


Usage by titles:

  • OpenAGC game_compat.c, the AGC functions "identified from analysis of New Joe & Mac Caveman Ninja (PPSA02801) eboot.bin", contains sceAgcCbCondWrite and sceAgcCbCondWriteGetSize. The import analysis it cites is not published, so this rests on that header.
  • PS5PCEM agc_table.zig, "generated from the identifiers a shipped title imports", binds both, without naming the title.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6025978998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/975#issuecomment-6025978998). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-06T21:41:42Z. --- Usage by titles: - [OpenAGC `game_compat.c`](https://github.com/OpenAGC/OpenAGC/blob/main/src/game_compat.c), the AGC functions "identified from analysis of New Joe & Mac Caveman Ninja (PPSA02801) eboot.bin", contains `sceAgcCbCondWrite` and `sceAgcCbCondWriteGetSize`. The import analysis it cites is not published, so this rests on that header. - [PS5PCEM `agc_table.zig`](https://github.com/iStark/PS5PCEM/blob/main/src/hle/libs/agc_table.zig), "generated from the identifiers a shipped title imports", binds both, without naming the title.
oneandonlydean commented 2026-10-06 22:02:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T22:02:57Z.


Thanks. The argument mapping is well sourced (OpenAGC and sharpemu agree), and accepting only write space 1 while the others throw is the right call.

Which title calls sceAgcCbCondWrite, or submits COND_WRITE? The description and #977's both say it wasn't tested with a title. If you have one, please name it here; it would also give #977's drain ordering a real case to check against.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6026273267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/975#issuecomment-6026273267). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T22:02:57Z. --- Thanks. The argument mapping is well sourced (OpenAGC and sharpemu agree), and accepting only write space 1 while the others throw is the right call. Which title calls `sceAgcCbCondWrite`, or submits COND_WRITE? The description and #977's both say it wasn't tested with a title. If you have one, please name it here; it would also give #977's drain ordering a real case to check against.
oneandonlydean commented 2026-10-06 22:40:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T22:40:34Z.


Thanks, and sorry: I asked before I'd seen your note above. New Joe & Mac Caveman Ninja (PPSA02801) in OpenAGC's import list is enough of a caller for me, and the PS5PCEM table backs it up.

Next steps on my side: approve the CI run, then check it on Dreaming Sarah together with #977. No changes needed from you for now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6026765176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/975#issuecomment-6026765176). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T22:40:34Z. --- Thanks, and sorry: I asked before I'd seen your note above. New Joe & Mac Caveman Ninja (PPSA02801) in OpenAGC's import list is enough of a caller for me, and the PS5PCEM table backs it up. Next steps on my side: approve the CI run, then check it on Dreaming Sarah together with #977. No changes needed from you for now.
github-actions[bot] commented 2026-10-06 22:40:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T22:40:50Z.


Progress report (e323c1f → d8b775e)

📈 System libraries: 86.82% (+0.07%, +2 implemented functions)

✅ 2 implemented
Library Name
libSceAgc sceAgcCbCondWrite
libSceAgc sceAgcCbCondWriteGetSize
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6026768550 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/975#issuecomment-6026768550). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T22:40:50Z. --- <!-- progress-report --> ### Progress report (e323c1f → d8b775e) 📈 **System libraries**: 86.82% (+0.07%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libSceAgc | `sceAgcCbCondWrite` | | libSceAgc | `sceAgcCbCondWriteGetSize` | </details>
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!975
No description provided.