feat(libSceCesCs): implement Shift-JIS CP932 and CP1250 encoding conversions #7091
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7091"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Bl4ckk01 on 2026-10-17T11:02:29Z.
What
Implement Shift-JIS (CP932 / Windows-31J) multibyte decoding and encoding conversions mapped to JIS X 0208, and implement Windows-1250 (Central European) profile and single-byte conversions for libSceCesCs. Add exhaustive unit tests covering all 7336 assigned Shift-JIS cells and CP1250 round-trips.
Tested
Built and verified unit tests in
core/libs/tests/GuestCes.cppcovering ASCII, half-width katakana, full-width Japanese text, UCS-2 conversions, buffer boundary errors, and exhaustive 7336-character round-trip verification.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T11:22:01Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceCesCs/Export.cppL251, L278docs/dev/debt/libSceCesCs.mdL6-7Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/tests/GuestCes.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T12:09:42Z.
Thanks for this. Review of 5b34c486e: two small changes, everything else checks out against Python's codecs.
Change requests
decodeMbcsaccepts leads up to 0xFC but maps only JIS rows 1-94. So the 388 IBM-extension cells (FA40-FC4B) answerUNASSIGNED_CODE, although they are assigned in CP932: Pythoncp932decodes all 388. All 388 characters are already inJisX0208::TO_UCS2(as NEC-selected rows 89-92 or row 2), so decoding them needs no new data beyond an FA40-FC4B → Unicode (or → NEC cell) redirect. A common case:FBFC= 髙 (U+9AD9), a frequent kanji in names. Encoding is unaffected: it picks the lowest cell (EEE0for 髙), which matches Python's cp932 encoder for every one of the 7336 characters. Ask: decode FA40-FC4B, and update the test'ssjisAssigned == 7336(it now pins the gap; it would become 7724). At minimum, if the author prefers not to, the debt entry must say that leads 0xF0-0xFC answerUNASSIGNED_CODE(the user-defined area F040-F9FC, which CP932 maps to PUA, and the IBM extensions). Today it implies the full CP932 lead range.if (lead == 0x8F) NotImplemented_nid_no_patch(...)→ plainthrow std::runtime_error).NotImplemented_nid_no_patchalready throws (libc/src/General.cpp:617), so the behaviour is the same apart from the message. But it drops the project's marker for unimplemented paths, which the PR checklist itself names ("Unimplemented paths throw (NotImplemented_nid_no_patch)"), and it's off-topic for this PR.Verified
cp1250: all 128 high bytes match, except the 5 undefined bytes (0x81, 0x83, 0x88, 0x90, 0x98), which map to the same C1 code point. That's the existing CP1251/CP1252 convention, and Microsoft's best-fit does the same. Reverse lookup is a linear scan of 128 entries, fine.cp932exactly. The only divergences are F040-F9FC (PUA, 1880 cells; acceptable, the console's handling is unknown) and FA40-FC4B (CR 1). Trail validity (0x40-0x7E, 0x80-0xFC), the row/cell arithmetic and theSRC_BUFFER_ENDon a cut pair are correct.cp932over all 7336 table characters (lowest-cell choice). Half-width katakana U+FF61-FF9F ↔ A1-DF and ASCII identity are right.Once fixed, full CI on the new head with guest_ces and guest_ces_module passing on Linux and Windows.
Imported from boykopovar/AnyPS5. Originally posted by Bonjourcestmatt on 2026-10-17T23:43:06Z.
Windows run of this head, plus an independent check of the tables against Python's codecs.
Setup: Windows 11, MinGW-w64 GCC 15.2.0 UCRT, full configure with submodules, head
21be453ef(onmain673f7406c),ctest -R guest_ces.1.
guest_cesaborts on this head.guest_ces_modulepasses. InGuestCes.cpp, the Shift-JIS block expects"Go \xEF\xBD\xB1!"(G, o, space, half-width katakana A,!) to convert to 4 bytes, but that is 5 characters and the library returns 5:47 6F 20 B1 21(used=7 produced=5). SoRequire(used == 7 && produced == 4 && std::memcmp(mbcs, "Go \xB1!", 4) == 0)fails first (the memcmp over 4 bytes would pass;produced == 4does not). The same off-by-one is in the lines that follow:sceCesUtf8StrGetMbcsLen ... produced == 4, and the three round-trip calls that passmbcs, 4and expectused == 4. The EUC-JP block just above uses the same string and correctly expects 6 bytes for 6 characters. With those five expectations changed to 5 in a scratch copy (no library change), the whole test passes, so the implementation looks right and only the expected counts are off. The mismatch does not depend on the host, so I expect the same on Linux, but I only ran Windows.2. Differential check against Python
cp932. I did not change the library; I called it through the exports, for every double-byte code (leads 0x81-0x9F and 0xE0-0xFC, trails 0x40-0xFC except 0x7F: 11280 pairs) and for every BMP code point:sceCesMbcsStrToUcs2Str: 7724 codes decode to exactly the same code point asbytes.decode('cp932'), 1676 are rejected by both, and 0 differ in value. The only codescp932decodes and the library rejects are the 1880 user-defined ones (leads 0xF0-0xF9, U+E000-U+E757).sceCesUcs2StrToMbcsStr: 7389 code points encode to the same bytes aschr(cp).encode('cp932')and none to different bytes. The 1891 that Python encodes and the library rejects are those 1880 user-defined code points plus U+0080 and U+00A2, U+00A3, U+00AC, U+2016, U+2212, U+301C (mappings Python'scp932codec accepts for compatibility; the canonical decodes of 0x8191, 0x8192, 0x81CA, 0x8161, 0x817C, 0x8160 do match).cp1250; Python leaves 0x81, 0x83, 0x88, 0x90 and 0x98 undefined and the table maps them to U+0081, U+0083, U+0088, U+0090 and U+0098.Whether the console maps the user-defined area, those code points or those five bytes is not something I can tell from this, and I am not asking for a change; if useful, the debt entry could list them.
Not checked: Linux, macOS, PS5 hardware or a title.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by peeldealer on 2026-10-18T06:01:22Z.
Linux confirmation of @Bonjourcestmatt's point 1, which was only run on Windows.
21be453ef, run on its own and merged into currentmaina86577e46.guest_cesandguest_ces_moduleboth abort, and both pass onmainwithout this PR.GuestCes.cpp:219. There the library returnsused=7 produced=5with bytes47 6F 20 B1 21, so the failure is in the expected counts, not the library, the same as on Windows.Correcting the counts as described there should fix both platforms. oneandonlydean's two requests (FA40-FC4B, and keeping
NotImplemented_nid_no_patchfor0x8F) still apply.Imported from boykopovar/AnyPS5. Originally posted by Bl4ckk01 on 2026-10-18T11:22:28Z.
thank you @Bonjourcestmatt and @peeldealer
Fixed in 1ff25ef: corrected the Shift-JIS half-width katakana string expectation in
GuestCes.cppfrom 4 to 5 bytes (47 6F 20 B1 21). Compiled and verified the full test suite locally;guest_cesnow passes with exit code 0.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:51:23Z.
Checked the new head against the earlier requests: IBM extensions FA40-FC4B now decode (first 28 cells via the head table, the rest through NEC rows 89-92; FBFC → U+9AD9, FC4B ok, FC4C unassigned), the test pins 7724 cells with round-trip to the lowest cell, the unrelated EUC-JP hunk is gone, the half-width katakana counts are 5, and the debt entry lists the user-defined area as
UNASSIGNED_CODE; merged.