fix(libSceCesCs): encode EUC-JP and Shift-JIS as measured on a PS5 #10186

Merged
orezraey merged 32 commits from upstream-pr/10186 into main 2026-10-25 01:21:32 +00:00
orezraey commented 2026-10-23 12:13:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T12:13:08Z.


What

The EUC-JP and Shift-JIS encoders rejected the JIS forms of characters that CP932 maps to Microsoft forms, and they treated U+0080–U+009F like any other unassigned value.

I measured both encoders on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loading libSceCesCs.sprx. Every UCS-2 value from U+0000 to U+FFFF went through sceCesUcs2StrToMbcsStr, and the probe hashed the result, both lengths and the output bytes. Then I dumped the 256-value blocks whose hash differed from AnyPS5's. The sources and console logs are in this gist (pces10, pces11, pces12).

Only blocks 00, 20, 22, 30 and FE differed. On the console:

  • JIS forms map to the Microsoft cells.

    Code point EUC-JP Shift-JIS
    U+00A2 A1F1 8191
    U+00A3 A1F2 8192
    U+00A5 A1EF 818F
    U+00AC A2CC 81CA
    U+2014 A1BD 815C
    U+2016 A1C2 8161
    U+203E A1B1 8150
    U+2212 A1DD 817C
    U+301C A1C1 8160

    Each code point lands on the cell of its Microsoft form, which is what those cells decode to.

  • C1 controls. EUC-JP writes U+0080–U+009F as single bytes, except U+008E and U+008F, which answer 0x805C0020. It answers 0x805C0020 for U+000E. Shift-JIS answers 0x805C0024 for U+0080–U+009F and writes U+000E.

  • Byte order mark. U+FEFF is consumed and writes nothing in both profiles.

With the change, the full sweep matches the console for both profiles. The probe also swept every two-byte Shift-JIS input through sceCesMbcsStrToUcs2Str (pces13); decoding already matched for all of them, and the test now pins that sweep too, so the debt entry no longer calls Shift-JIS decoding unverified. The NEC-selected preference, such as U+2170 → FCF1 / EEEF, was already right.

Depends on the MBCS string PR, whose conversion loop this sweep runs through. That branch, and the two scalar PRs under it, are carried until they merge.

On top of #8967. sceCesUcs2ToSJis, sceCesUcs2ToEucJp and the other scalar encoders from #8967 share the encoder, so they take the measured mappings too. The guest_ces_japanese round trip skips the forms that encode to Microsoft cells, since they decode back to the Microsoft code point.

Tested

  • Head after #10185 landed and main (f4aabbb122) was merged in: 72a2187568. The diff against main is now only this PR's JIS encode change (4 files). The 14 guest_ces* tests pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); public_headers audit and check_conventions pass.
    Windows 11, MinGW (winlibs).
  • guest_ces pins the hash of the full U+0000–U+FFFF sweep for both profiles and of the Shift-JIS two-byte decoding sweep. It also checks the aliases, U+FEFF, U+0080 and U+000E in strings, and the yen sign in both profiles (it expected UNASSIGNED_CODE before).
  • It fails without the change and passes with it.
  • The ten guest_ces* tests pass three runs in a row.
  • tools/check_conventions.py passes. The Shift-JIS debt entry was shortened below the 1000-character limit.
  • tools/pr_overlap.py lists the same code-page PRs as the earlier CES changes (#8923, #9912, #9210) and #6044.

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: #10185, #9175, #10426, #10430, #10431; #9175, #10426, #10430, #10431 edit the same lines too (merge order only); #10718 rewrites the same EUC-JP decoder and debt entries, and #10706 removes the test declarations this PR adds to GuestCes.cpp (merge order only); #10722, #10739, #10751 edit the same lines too (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982541712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10186). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T12:13:08Z. --- ### What The EUC-JP and Shift-JIS encoders rejected the JIS forms of characters that CP932 maps to Microsoft forms, and they treated U+0080–U+009F like any other unassigned value. I measured both encoders on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loading `libSceCesCs.sprx`. Every UCS-2 value from U+0000 to U+FFFF went through `sceCesUcs2StrToMbcsStr`, and the probe hashed the result, both lengths and the output bytes. Then I dumped the 256-value blocks whose hash differed from AnyPS5's. The sources and console logs are in [this gist](https://gist.github.com/orezraey/bf3bdb52f9ad11cf83e9bb3f28dbfc21) (`pces10`, `pces11`, `pces12`). Only blocks 00, 20, 22, 30 and FE differed. On the console: - **JIS forms map to the Microsoft cells.** | Code point | EUC-JP | Shift-JIS | |---|---|---| | U+00A2 | `A1F1` | `8191` | | U+00A3 | `A1F2` | `8192` | | U+00A5 | `A1EF` | `818F` | | U+00AC | `A2CC` | `81CA` | | U+2014 | `A1BD` | `815C` | | U+2016 | `A1C2` | `8161` | | U+203E | `A1B1` | `8150` | | U+2212 | `A1DD` | `817C` | | U+301C | `A1C1` | `8160` | Each code point lands on the cell of its Microsoft form, which is what those cells decode to. - **C1 controls.** EUC-JP writes U+0080–U+009F as single bytes, except U+008E and U+008F, which answer `0x805C0020`. It answers `0x805C0020` for U+000E. Shift-JIS answers `0x805C0024` for U+0080–U+009F and writes U+000E. - **Byte order mark.** U+FEFF is consumed and writes nothing in both profiles. With the change, the full sweep matches the console for both profiles. The probe also swept every two-byte Shift-JIS input through `sceCesMbcsStrToUcs2Str` (`pces13`); decoding already matched for all of them, and the test now pins that sweep too, so the debt entry no longer calls Shift-JIS decoding unverified. The NEC-selected preference, such as U+2170 → `FCF1` / `EEEF`, was already right. **Depends on** the MBCS string PR, whose conversion loop this sweep runs through. That branch, and the two scalar PRs under it, are carried until they merge. **On top of #8967.** `sceCesUcs2ToSJis`, `sceCesUcs2ToEucJp` and the other scalar encoders from #8967 share the encoder, so they take the measured mappings too. The `guest_ces_japanese` round trip skips the forms that encode to Microsoft cells, since they decode back to the Microsoft code point. ### 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. --> - Head after #10185 landed and `main` (`f4aabbb122`) was merged in: `72a2187568`. The diff against `main` is now only this PR's JIS encode change (4 files). The 14 `guest_ces*` tests pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); `public_headers` audit and `check_conventions` pass. Windows 11, MinGW (winlibs). - `guest_ces` pins the hash of the full U+0000–U+FFFF sweep for both profiles and of the Shift-JIS two-byte decoding sweep. It also checks the aliases, U+FEFF, U+0080 and U+000E in strings, and the yen sign in both profiles (it expected `UNASSIGNED_CODE` before). - It fails without the change and passes with it. - The ten `guest_ces*` tests pass three runs in a row. - `tools/check_conventions.py` passes. The Shift-JIS debt entry was shortened below the 1000-character limit. - `tools/pr_overlap.py` lists the same code-page PRs as the earlier CES changes (#8923, #9912, #9210) and #6044. ### 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: #10185, #9175, #10426, #10430, #10431; #9175, #10426, #10430, #10431 edit the same lines too (merge order only); #10718 rewrites the same EUC-JP decoder and debt entries, and #10706 removes the test declarations this PR adds to `GuestCes.cpp` (merge order only); #10722, #10739, #10751 edit the same lines too (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 12:24:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:24:36Z.

Review: APPROVED


Reviewed the new encoding delta at head 567b164839, stacked on open #10185. The alias mapping and EUC-JP/Shift-JIS C1/BOM handling match the supplied firmware 13.60 measurements. The full-UCS-2 encoder hash sweeps, focused prefix/error checks, and full two-byte Shift-JIS decode sweep give useful regression coverage. Local C++20 syntax checks for the changed implementation and tests, conventions, and diff check pass. Product build jobs are skipped by the current path policy; I could not run the focused executable locally because full CMake configuration stops at the missing SDL2 development package. The declared dependency on #10185 is consistent with the branch stack.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628161486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10186#pullrequestreview-5628161486). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:24:36Z. **Review:** APPROVED --- Reviewed the new encoding delta at head 567b164839accc8c8a9c9861936b089e72567412, stacked on open #10185. The alias mapping and EUC-JP/Shift-JIS C1/BOM handling match the supplied firmware 13.60 measurements. The full-UCS-2 encoder hash sweeps, focused prefix/error checks, and full two-byte Shift-JIS decode sweep give useful regression coverage. Local C++20 syntax checks for the changed implementation and tests, conventions, and diff check pass. Product build jobs are skipped by the current path policy; I could not run the focused executable locally because full CMake configuration stops at the missing SDL2 development package. The declared dependency on #10185 is consistent with the branch stack.
MarcZX10 commented 2026-10-23 13:59:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T13:59:13Z.

Review: APPROVED


Re-review of exact current head 556b195d5966ee61e2a97d77aa242def53962a3b. The implementation/test/debt diff against current main is unchanged by the merge-main refresh. The checklist records #10185 as a prerequisite, following the agreed #10183/#10184 -> #10185 -> #10186 -> #10056 order. Exact-head conventions and git diff --check pass; GCC C++20 -Wall -Wextra -Werror -fsyntax-only on the CES export passes. Hosted eligibility, conventions, labels and report pass; product build/test jobs are skipped by path policy. The author reports the CES test matrix on the earlier identical source; I did not run full CMake tests here. Approving this exact head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5629283025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10186#pullrequestreview-5629283025). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T13:59:13Z. **Review:** APPROVED --- Re-review of exact current head `556b195d5966ee61e2a97d77aa242def53962a3b`. The implementation/test/debt diff against current main is unchanged by the merge-main refresh. The checklist records #10185 as a prerequisite, following the agreed #10183/#10184 -> #10185 -> #10186 -> #10056 order. Exact-head conventions and `git diff --check` pass; GCC C++20 `-Wall -Wextra -Werror -fsyntax-only` on the CES export passes. Hosted eligibility, conventions, labels and report pass; product build/test jobs are skipped by path policy. The author reports the CES test matrix on the earlier identical source; I did not run full CMake tests here. Approving this exact head.
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!10186
No description provided.