feat(libSceMouse): implement the absolute position calls as firmware 13.42 does #12958

Merged
zaryabzip merged 5 commits from upstream-pr/12958 into main 2026-11-02 17:25:58 +00:00
zaryabzip commented 2026-10-29 17:30:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-29T17:30:16Z.


What

Implements the three libSceMouse absolute-position calls that stop Mewgenics (PPSA37318) at mouse init, plus a storing sceMouseResetAbsolutePosition. The library side follows firmware 13.42's libSceMouse.sprx, which @BunnyFl read and ran natively with the driver stubbed (#11477 comment). The host-side design follows @XatiX's version tested with the title, which gets past mouse init to the first battle. The title's arguments are from XatiX's call sites.

From the firmware run:

  • sceMouseSetAbsoluteVirtualScreenSize(handle, size): picks 1280×720, 1920×1080 (the size after open), 2560×1440 or 3840×2160. Anything above 3, compared unsigned, is INVALID_ARG, checked before the handle. Changing the size rescales the stored position with truncation, so (1000, 500) becomes (2000, 1000), then (666, 333).
  • sceMouseSetAbsoluteHighPrecisionMode(handle, mode): stores the low byte of mode.
    • Off: each sample moves the pointer one for one.
    • On: each sample's length goes through the module's piecewise curve. The move is truncated, and the fraction is kept. The curve reproduces the measured totals 0.57, 1.28, 10.62, 32.62 and 247.54.
  • sceMouseReadAbsolutePosition(handle, buf, num):
    • INVALID_ARG for a null buffer or num outside 1–64, checked before the handle.
    • Each sample moves the clamped pointer, and records are 40 bytes: timestamp, 1 at +0x08, buttons, u16 x/y at +0x10/+0x12, wheel and tilt. Bytes +0x09–0x0B and +0x1C–0x27 are left alone, as the module does.
  • sceMouseResetAbsolutePosition: checks against the current size and stores the position, which starts at (0, 0) after open.

Host choices (the driver wasn't measured; listed in the debt entry):

  • Raw counts: each host motion event is one absolute sample, carrying the unscaled counts. MouseInput now passes xrel/yrel alongside the window-scaled deltas that sceMouseRead keeps.
  • A queue of its own: absolute samples queue apart from #9982's merged sceMouseRead reports. So the curve and the clamp see every sample, and neither kind of read takes the other's samples.
  • Draining: a read takes every pending sample. When there are more than num, neighbours with the same buttons share a record, and each still moves the pointer. Only the last num records are kept, as the module keeps the last num driver samples.
  • No driver data: the pointer speed is taken as 4, the hand swap and flagged button bit never apply, and a disconnected mouse stands in for the driver's zero status word.

Tests:

  • tests/MouseAbsolute.cpp looks the calls up at runtime, because the base declares them without parameters. It covers the checks, sizes, mode byte, curve, records and merging (BunnyFl's 101/103/107).
  • It also compares queued against one-at-a-time samples: precision, carry, edge clamping, size and reset changes while samples are queued, and interleaved relative and absolute reads.
  • tests/Mouse.cpp drives MouseInput at a 2× presentation scale. sceMouseRead gets the scaled delta, while the absolute pointer moves by the raw count.

Stacked on #9982 (Tamalero, approved): both change mouse_impl.cpp's includes and Publish, and the debt file's Functional section. The branch is #9982's head merged with main, plus one commit.

Tested

Windows 11 Home 10.0.26200 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) at 26d7585cfb, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1) with it merged into main bb04a4f1ea. With the title: @XatiX ran Mewgenics (PPSA37318 01.121.220) at this head on Windows 11 with a physical mouse. The game gets past mouse init with no libSceMouse errors, the cursor follows at the right speed, and hovers and clicks work through the menus to the first battle. Entering the battle then stops on the AGC refusal #7048 addresses, which happens on main too.

  • No warnings anywhere in the build on either host. tests/Mouse.cpp's function-pointer cast is also clean under -Wextra -Wcast-function-type.
  • ctest -R "^mouse_": mouse_absolute_position and mouse_input (with #9982's cases) pass on both hosts, and each passes 3 of 3 on --repeat until-fail:3. video_out_mouse passes too.
  • Everything that includes the changed headers rebuilds with no warnings on both hosts: libSceMouse, both mouse tests, libSceVideoOut's MouseInput.cpp/PadInput.cpp and its mouse test. Each changed header also builds on its own.
  • Baseline: on dbd29271bf (#9982 merged with main) with only the two test files and the CMakeLists.txt block, both tests build. mouse_absolute_position then aborts with sceMouseSetAbsoluteVirtualScreenSize not implemented. mouse_input passes all of #9982's checks and aborts at its first absolute read with sceMouseReadAbsolutePosition not implemented. Both happen on both hosts (Windows exit 0xc0000409, Linux SIGABRT).
  • tools/check_conventions.py passes. Overlap: #9982 (stacked on, see above). #12379 changes the mouse test's link line and MouseInput.cpp's motion condition, and merges cleanly with this branch.

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 under Silent stubs in their library's technical debt file
  • 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: #9982
  • Fixes: none
  • Unblocks: PPSA37318 #11477
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5072657174 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12958). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-29T17:30:16Z. --- ### What Implements the three libSceMouse absolute-position calls that stop Mewgenics (PPSA37318) at mouse init, plus a storing `sceMouseResetAbsolutePosition`. The library side follows firmware 13.42's `libSceMouse.sprx`, which @BunnyFl read and ran natively with the driver stubbed ([#11477 comment](https://github.com/boykopovar/AnyPS5/issues/11477#issuecomment-6502712241)). The host-side design follows @XatiX's [version tested with the title](https://github.com/boykopovar/AnyPS5/issues/11477#issuecomment-6503782633), which gets past mouse init to the first battle. The title's arguments are from [XatiX's call sites](https://github.com/boykopovar/AnyPS5/pull/11482#issuecomment-6422613769). **From the firmware run:** - **`sceMouseSetAbsoluteVirtualScreenSize(handle, size)`:** picks 1280×720, 1920×1080 (the size after open), 2560×1440 or 3840×2160. Anything above 3, compared unsigned, is `INVALID_ARG`, checked before the handle. Changing the size rescales the stored position with truncation, so (1000, 500) becomes (2000, 1000), then (666, 333). - **`sceMouseSetAbsoluteHighPrecisionMode(handle, mode)`:** stores the low byte of `mode`. - Off: each sample moves the pointer one for one. - On: each sample's length goes through the module's piecewise curve. The move is truncated, and the fraction is kept. The curve reproduces the measured totals 0.57, 1.28, 10.62, 32.62 and 247.54. - **`sceMouseReadAbsolutePosition(handle, buf, num)`:** - `INVALID_ARG` for a null buffer or `num` outside 1–64, checked before the handle. - Each sample moves the clamped pointer, and records are 40 bytes: timestamp, 1 at +0x08, buttons, `u16` x/y at +0x10/+0x12, wheel and tilt. Bytes +0x09–0x0B and +0x1C–0x27 are left alone, as the module does. - **`sceMouseResetAbsolutePosition`:** checks against the current size and stores the position, which starts at (0, 0) after open. **Host choices** (the driver wasn't measured; listed in the debt entry): - **Raw counts:** each host motion event is one absolute sample, carrying the unscaled counts. `MouseInput` now passes `xrel`/`yrel` alongside the window-scaled deltas that `sceMouseRead` keeps. - **A queue of its own:** absolute samples queue apart from #9982's merged `sceMouseRead` reports. So the curve and the clamp see every sample, and neither kind of read takes the other's samples. - **Draining:** a read takes every pending sample. When there are more than `num`, neighbours with the same buttons share a record, and each still moves the pointer. Only the last `num` records are kept, as the module keeps the last `num` driver samples. - **No driver data:** the pointer speed is taken as 4, the hand swap and flagged button bit never apply, and a disconnected mouse stands in for the driver's zero status word. **Tests:** - `tests/MouseAbsolute.cpp` looks the calls up at runtime, because the base declares them without parameters. It covers the checks, sizes, mode byte, curve, records and merging (BunnyFl's 101/103/107). - It also compares queued against one-at-a-time samples: precision, carry, edge clamping, size and reset changes while samples are queued, and interleaved relative and absolute reads. - `tests/Mouse.cpp` drives `MouseInput` at a 2× presentation scale. `sceMouseRead` gets the scaled delta, while the absolute pointer moves by the raw count. Stacked on #9982 (Tamalero, approved): both change `mouse_impl.cpp`'s includes and `Publish`, and the debt file's Functional section. The branch is #9982's head merged with `main`, plus one commit. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Home 10.0.26200 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) at 26d7585cfb, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1) with it merged into `main` bb04a4f1ea. With the title: @XatiX [ran Mewgenics (PPSA37318 01.121.220) at this head](https://github.com/boykopovar/AnyPS5/pull/12958#issuecomment-6504654748) on Windows 11 with a physical mouse. The game gets past mouse init with no libSceMouse errors, the cursor follows at the right speed, and hovers and clicks work through the menus to the first battle. Entering the battle then stops on the AGC refusal #7048 addresses, which happens on `main` too. - No warnings anywhere in the build on either host. `tests/Mouse.cpp`'s function-pointer cast is also clean under `-Wextra -Wcast-function-type`. - `ctest -R "^mouse_"`: `mouse_absolute_position` and `mouse_input` (with #9982's cases) pass on both hosts, and each passes 3 of 3 on `--repeat until-fail:3`. `video_out_mouse` passes too. - Everything that includes the changed headers rebuilds with no warnings on both hosts: libSceMouse, both mouse tests, libSceVideoOut's `MouseInput.cpp`/`PadInput.cpp` and its mouse test. Each changed header also builds on its own. - Baseline: on dbd29271bf (#9982 merged with `main`) with only the two test files and the `CMakeLists.txt` block, both tests build. `mouse_absolute_position` then aborts with `sceMouseSetAbsoluteVirtualScreenSize not implemented`. `mouse_input` passes all of #9982's checks and aborts at its first absolute read with `sceMouseReadAbsolutePosition not implemented`. Both happen on both hosts (Windows exit 0xc0000409, Linux SIGABRT). - `tools/check_conventions.py` passes. Overlap: #9982 (stacked on, see above). #12379 changes the mouse test's link line and `MouseInput.cpp`'s motion condition, and merges cleanly with this branch. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: <!-- #PR, or none --> #9982 - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> PPSA37318 #11477 - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
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!12958
No description provided.