feat(libSceCesCs): implement sceCesJiscsToUcs and sceCesUcsToJiscs #12946
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12946"
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 KernelPanicNT on 2026-10-29T15:45:16Z.
What
Source of the behaviour
Measured with homebrew probes running as a payload process on a device. The probes loaded the system
libSceCesCs.sprx, built each profile in their own guarded static sheet, and logged every result and output word. The full sweeps logged an FNV-1a hash of the (result, output) pairs for each row of 94 cells or block of 256 code points. A model built from the in-tree tables reproduces all 2256 row hashes, all 2560 block hashes and all 4556 logged single results inside the implemented forms (probe output outside them is listed below as throwing).sceCesJiscsToUcs, each profile, every row and cell0x21-0x7Ewith bits 16-23 at 00x805C0020for an empty cell0x1RRCC,0x2RRCC)0x805C0015for every cell and profile0x00-0xFF, each profile0x00-0x9Funchanged (Shift_JIS X 0208:0x5CU+00A5,0x7EU+203E);0xA1-0xDFhalf-width katakana, except EUC-JP X 0208 without SS2; the rest0x805C0020sceCesUcsToJiscs, each profile, U+0000-U+FFFF; U+20000-U+2FFFF for the two 2004 profiles0x5Cand0x7E, U+005C to cell 1-32, U+007E unassigned); katakana to0xA1-0xDFwhere the profile has it; otherwise the lowest cell of the profile's table, with the CP932 aliases (U+2014 to cell 1-29), JIS X 0212 as0x0400RRCC(SS3 and EUC-JIS-2004 only) and JIS X 0213 plane 2 as0x0302RRCC; surrogates0x805C0015; the rest0x805C00200xFFFFFFFF, each profile and a null profile0x805C00150x805C0004, output 00x2422, U+3042)0x805C00300x805C0020), not0x805C00300x805C0030; inferred from this sheet only, not observed with a JIS profile or forsceCesUcsToJiscs, and not pinned by the test0x82A0,0xA4A2,0x8E21,0x8FA2AF,0xFFFF,0x02002422,0x10000,0x1002422and others0x02002422gives U+8CC3); a null profile with0x8FA2AFfaults0x02002422, each profile0x02reads the row and cell from 1 (row 36, cell 34), the same counting as the encoder's0x03PPRRCCand0x0400RRCC; those two forms were never sent tosceCesJiscsToUcs0x82A0,0xA4A2,0x30000,0x02002422,0xFFFF,0xFFFFFFFF0x805C0004;0x8FA2AFfaults0x805C0020(two samples)0x80converts)PendingExports.cpp#L96,#L201; declarationsApi.hpp#L229,#L265.jisX0208ToUnicode,jis2004Reverse,jisReverse,jisAlias; the profile notes inlibSceCesCs.md#L14and#L23.int sceCesJiscsToUcs(const union* prof, uint32_t jcode, uint32_t *ucode),int sceCesUcsToJiscs(uint32_t ucode, const union* prof, uint32_t *jcode)).REVERSE_ENGINEERING.md#L9.Implements
sceCesJiscsToUcs(const void* profile, uint32_t jiscs, uint32_t* ucs)andsceCesUcsToJiscs(uint32_t ucs, const void* profile, uint32_t* jiscs)for the eight JIS profiles (sceCesUcsProfileInitSJis1997X0208, SJis1997Cp932, EucJpX0208, EucJpX0208Ss2, EucJpX0208Ss2Ss3, EucJpCp51932, SJis2004X0213 and EucJis2004). Both calledNotImplemented_nid_no_patch.A JIS code is a byte or a row and cell
0x21-0x7E(0x2422is U+3042). Encoding returns a byte,0x03PPRRCC(plane, then row and cell counted from 1, so U+3042 is0x03010402) or0x0400RRCCfor JIS X 0212. The mapping reuses the profile tables already in the tree, and the measured sweeps confirm them for every cell and code point listed below. Everything else throwsstd::runtime_errorand is listed indocs/dev/debt/libSceCesCs.mdin two entries. The first covers forms the device answered but this PR does not implement, with what it returned: native Shift-JIS and EUC-JP codes,0x02002422(U+8CC3), the null-profile0x805C0004results for those codes and U+2000B and U+20B9F with a JIS X 0208 profile (0x805C0020). The second covers what was not measured at all, which also throws: planes 1 and 3-16, the0x03PPRRCCand0x0400RRCCcodes the encoder returns given back as input, and other profiles. It also lists two unverified points that do not throw: the inferred error precedence, and whethersce*UcsProfileSetSbcsprofiles (handled here as the base JIS profile) behave differently.Open questions and overlap
sce*UcsProfileSetSbcsis not measured. The second debt entry lists this.tools/pr_overlap.py --branch feat/cescs-jiscs: no open PR implements these exports. #10431 and #14085 touch neighbouring lines (the CMake variant list, stubs, declarations and the debt file). #9912, #11614, #13486, #13573, #14212 and #15409 conflict withmain, so they were not compared; they touch the same files and none adds these two functions.sceCesJisGetLevel, now inmain, sits next to these stubs and declarations; the conflict with it is resolved.Tested
Linux (GCC). The new test runs as
guest_ces_jiscsandguest_ces_jiscs_module(linked againstlibSceCesCsandlibSceCesCs-module). It repeats the device sweeps for the eight profiles: every row of planes 0-2, every BMP block and plane 2 for the 2004 profiles, hashed per row or block as the probes did. It then folds those hashes and compares them with the folds of the hashes the device logged, and compares hashes of both 256-value scans with the device's. It also checks samples and the measured null-profile, null-output and invalid-scalar cases; it does not require the forms left unimplemented to throw. All 24guest_cestests pass onmain(b11c7bf84f) with this branch applied. Both new tests fail withExport.cpp,PendingExports.cppandApi.hppfrommain(they do not build), and with the two functions reduced toNotImplemented_nid_no_patchstubs (both abort).tools/progress.py: +2 implemented functions (libSceCesCs 270/287 -> 272/287).tools/check_conventions.pypasses.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 rooklz on 2026-10-29T18:36:25Z.
Review: COMMENTED
Reviewed head
b8411fd070on macOS arm64. I built the PR'sExport.cpp,Unicode.cppandGuestCesJiscs.cppon their own, without the CMake tree, which needs submodules.Gates
git merge-treeagainstmainbb04a4f1eais clean, and so isgit diff --check.tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.py: text overlaps with #10431 and #10751 (CMake list, stubs, declarations). #9912 already conflicts with main. This matches what the body says.clang++ -arch x86_64 -O2: the new test passes in 0.6 s. With-fsanitize=address,undefinedit also passes, with no reports.x86_64-w64-mingw32-g++(16.2)-fsyntax-onlyonExport.cppand the test: 0 errors.(void)declarations), as the body says.Mutants (on
Export.cpp, each run against the PR test)26 mutants in total. 20 are killed by the PR test as it stands, including:
6 survive:
isJisGraphicupper bound0x7E→0x7F0x21→0x20sceCesJiscsToUcsaccepting a non-JIS profile (dropping the throw)sceCesJiscsToUcssceCesUcsToJiscsOf these, 4 and 5 are the "inferred, not pinned" precedence the body already discloses, so they are fine to leave. 6 is a deliberate choice: the device faults on
0x8FA2AFwith a null profile.1–3 are killed by the four optional rows below. Each one asserts something the code already does. Head stays green with them under ASan+UBSan.
Debt wording
I agree with @oneandonlydean. The new debt line opens with "throw where nothing was measured", but several of the listed forms were measured and are only not implemented:
0x02002422→ U+8CC30x805C0004results0x805C0020with X 0208Suggestion: split the line into "measured, not implemented (device result: …)" and "not measured" (planes 1 and 3–16,
0x03PPRRCC/0x0400RRCCinput,Set*Sbcsprofiles).Implementation looks right to me: it reuses the in-tree tables and generic profile tags, and has no title-specific values. I'd approve once the debt line is split.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:17Z.
Review: COMMENTED
Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (
Unblocks: noneis allowed), and it contained no code review.