feat(libSceCesCs): implement the EUC-KR, UHC and Big5 scalar conversions #9107

Merged
jacob6769 merged 4 commits from upstream-pr/9107 into main 2026-10-23 18:26:40 +00:00
jacob6769 commented 2026-10-21 12:30:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jacob6769 on 2026-10-21T12:30:44Z.


What

Implements the 45 EUC-KR, UHC and Big5 scalar conversions that are still pending stubs in PendingExports.cpp. They use the profiles and CP949/CP950 tables from #7884:

  • sceCes{EucKr,Uhc,Big5}To{Ucs2,Utf16,Utf16be,Utf16le,Utf32,Utf32be,Utf32le}
  • sceCes{Ucs2,Utf8,Utf16,Utf16be,Utf16le,Utf32,Utf32be,Utf32le}To{EucKr,Uhc,Big5}

Signatures follow the Orbital type database. All 45 names resolve in the aerolib table through tools/nid_names.py --nid.

  • One character per call: each call converts one character, including zero, as sceCes{EucKr,Uhc,Big5}ToUtf8 and the Shift-JIS and EUC-JP scalar conversions from #8967 do. No terminator is written and no byte order is detected.
  • Decoding: the decoders go through the existing decodeMbcs, with the argument checks of the *ToUtf8 forms in the same order: profile, source, source length, destination. The UTF-16 forms always write one unit, because both tables are BMP-only.
  • Encoding: the encoders go through the existing encodeMbcs.
    • A surrogate or a value above U+10FFFF passed as UCS-2 or UTF-32 answers INVALID_ENCODE.
    • A malformed UTF-8 or UTF-16 source answers INVALID_ENCODE, or SRC_BUFFER_END when it is cut short.
    • A supplementary character answers UNASSIGNED_CODE.
  • Byte order: the forms without a suffix use host byte order, like #7848.
  • Failure: the output and the length pointers are left unchanged.
  • Code: each export is one line. It calls the scalar helpers from #8967 and #8976 (profiledToUcs2, profiledToUtf16, profiledToUtf32, scalarToProfiled, utf32ToProfiled and bufferToProfiled) with isEucKr, isUhc or isBig5 as the profile check. No helper is added.
  • Unverified: console errors are not measured. The existing EUC-KR, UHC and Big5 entry in docs/dev/debt/libSceCesCs.md now covers the scalar forms. The pending-export count there goes from 121 to 76.

tools/progress.py --module libSceCesCs: 166 to 211 of 287.

Not included: the KS X 1003 profiles (sceCesRefersUcsProfileKsX1003, sceCesRefersUcsProfileKsX1003Tilde0x7e) and sceCes{EucKr,Uhc}UcsProfileSetSbcs still throw. KS X 1003 is a 7-bit set, so what the console does with bytes 0x80-0xFF would be a guess, and the tilde variant's mapping has no public source. #8923 leaves these profiles out for the same reason.

Overlap:

  • Nine open PRs also edit the libSceCesCs sources and the debt file: #9175 (encoding into any MBCS profile), #9204 (strict JIS X 0208 profiles), #9210 (GB18030 profiles), #9912 (Windows-1253, 1255 and 1257 profiles), #10056 (sparse single-byte profiles) and the four PS5 measurement fixes #10183, #10184, #10185 and #10186. None of them adds these exports. They conflict with this PR only on neighbouring lines, so whichever PR lands second rebases.
  • #10185 and #10186 switch the other sceCesUtf8To* scalar forms to the measured UTF-8 decoder (decodeScalarUtf8). They also make the MBCS string conversions write a terminator. If they land first, sceCesUtf8To{EucKr,Uhc,Big5} should use the same decoder, and the string-conversion reference in guest_ces_dbcs needs room for the terminator.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release, BUILD_TESTING=ON.

guest_ces_dbcs and guest_ces_dbcs_module are extended:

  • Decoding: every two-byte input (65,536 per profile) goes through the seven new decoders. Result, consumed length and code point must match the hash-pinned *ToUtf8 export, in the requested byte order. On failure, the outputs must be unchanged.
  • Encoding: every BMP code point except the surrogates goes through all eight encoders of each profile. Each must return the same result and bytes as sceCesUcs2StrToMbcsStr through a context, report the right source length, and leave its outputs unchanged on failure. Zero, U+20000 and U+10FFFF are checked too.
  • Explicit cases: byte orders written as literal bytes, argument-check order, surrogates, values above U+10FFFF, cut and malformed UTF-8/UTF-16, the destination too small, and a profile mismatch. Also U+B620, which UHC encodes and EUC-KR does not, and the Big5 duplicates U+2550 and U+5341.
  • Mutation checks: each of these changes to the shared helpers makes guest_ces_dbcs fail, and restoring the code makes it pass again:
    • flipping the UTF-16 byte order in profiledToUtf16;
    • dropping the surrogate check in scalarToProfiled;
    • writing the source length before a failure in bufferToProfiled.

ctest -R "^guest_ces": 14/14 passed, including the Japanese, wide, Chinese and MBC tests from main. The full suite was not run. tools/check_conventions.py (with this title and body) and tools/check_test_registration.py build pass. tools/pr_overlap.py was run before opening, and the overlap is listed above. No console or 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 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951566661 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9107). Originally posted by [jacob6769](https://github.com/jacob6769) on 2026-10-21T12:30:44Z. --- ### What Implements the 45 EUC-KR, UHC and Big5 scalar conversions that are still pending stubs in `PendingExports.cpp`. They use the profiles and CP949/CP950 tables from #7884: - `sceCes{EucKr,Uhc,Big5}To{Ucs2,Utf16,Utf16be,Utf16le,Utf32,Utf32be,Utf32le}` - `sceCes{Ucs2,Utf8,Utf16,Utf16be,Utf16le,Utf32,Utf32be,Utf32le}To{EucKr,Uhc,Big5}` Signatures follow the [Orbital type database](https://github.com/AlexAltea/orbital/blob/b321fcdbd700cc02da1cb1ad25412781d5ec73c6/tools/ida/db_types.json). All 45 names resolve in the aerolib table through `tools/nid_names.py --nid`. - **One character per call:** each call converts one character, including zero, as `sceCes{EucKr,Uhc,Big5}ToUtf8` and the Shift-JIS and EUC-JP scalar conversions from #8967 do. No terminator is written and no byte order is detected. - **Decoding:** the decoders go through the existing `decodeMbcs`, with the argument checks of the `*ToUtf8` forms in the same order: profile, source, source length, destination. The UTF-16 forms always write one unit, because both tables are BMP-only. - **Encoding:** the encoders go through the existing `encodeMbcs`. - A surrogate or a value above U+10FFFF passed as UCS-2 or UTF-32 answers `INVALID_ENCODE`. - A malformed UTF-8 or UTF-16 source answers `INVALID_ENCODE`, or `SRC_BUFFER_END` when it is cut short. - A supplementary character answers `UNASSIGNED_CODE`. - **Byte order:** the forms without a suffix use host byte order, like #7848. - **Failure:** the output and the length pointers are left unchanged. - **Code:** each export is one line. It calls the scalar helpers from #8967 and #8976 (`profiledToUcs2`, `profiledToUtf16`, `profiledToUtf32`, `scalarToProfiled`, `utf32ToProfiled` and `bufferToProfiled`) with `isEucKr`, `isUhc` or `isBig5` as the profile check. No helper is added. - **Unverified:** console errors are not measured. The existing EUC-KR, UHC and Big5 entry in `docs/dev/debt/libSceCesCs.md` now covers the scalar forms. The pending-export count there goes from 121 to 76. `tools/progress.py --module libSceCesCs`: 166 to 211 of 287. Not included: the KS X 1003 profiles (`sceCesRefersUcsProfileKsX1003`, `sceCesRefersUcsProfileKsX1003Tilde0x7e`) and `sceCes{EucKr,Uhc}UcsProfileSetSbcs` still throw. KS X 1003 is a 7-bit set, so what the console does with bytes `0x80`-`0xFF` would be a guess, and the tilde variant's mapping has no public source. #8923 leaves these profiles out for the same reason. Overlap: - Nine open PRs also edit the libSceCesCs sources and the debt file: #9175 (encoding into any MBCS profile), #9204 (strict JIS X 0208 profiles), #9210 (GB18030 profiles), #9912 (Windows-1253, 1255 and 1257 profiles), #10056 (sparse single-byte profiles) and the four PS5 measurement fixes #10183, #10184, #10185 and #10186. None of them adds these exports. They conflict with this PR only on neighbouring lines, so whichever PR lands second rebases. - #10185 and #10186 switch the other `sceCesUtf8To*` scalar forms to the measured UTF-8 decoder (`decodeScalarUtf8`). They also make the MBCS string conversions write a terminator. If they land first, `sceCesUtf8To{EucKr,Uhc,Big5}` should use the same decoder, and the string-conversion reference in `guest_ces_dbcs` needs room for the terminator. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release, `BUILD_TESTING=ON`. `guest_ces_dbcs` and `guest_ces_dbcs_module` are extended: - **Decoding:** every two-byte input (65,536 per profile) goes through the seven new decoders. Result, consumed length and code point must match the hash-pinned `*ToUtf8` export, in the requested byte order. On failure, the outputs must be unchanged. - **Encoding:** every BMP code point except the surrogates goes through all eight encoders of each profile. Each must return the same result and bytes as `sceCesUcs2StrToMbcsStr` through a context, report the right source length, and leave its outputs unchanged on failure. Zero, U+20000 and U+10FFFF are checked too. - **Explicit cases:** byte orders written as literal bytes, argument-check order, surrogates, values above U+10FFFF, cut and malformed UTF-8/UTF-16, the destination too small, and a profile mismatch. Also U+B620, which UHC encodes and EUC-KR does not, and the Big5 duplicates U+2550 and U+5341. - **Mutation checks:** each of these changes to the shared helpers makes `guest_ces_dbcs` fail, and restoring the code makes it pass again: - flipping the UTF-16 byte order in `profiledToUtf16`; - dropping the surrogate check in `scalarToProfiled`; - writing the source length before a failure in `bufferToProfiled`. `ctest -R "^guest_ces"`: 14/14 passed, including the Japanese, wide, Chinese and MBC tests from `main`. The full suite was not run. `tools/check_conventions.py` (with this title and body) and `tools/check_test_registration.py build` pass. `tools/pr_overlap.py` was run before opening, and the overlap is listed above. No console or title was run. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/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!9107
No description provided.