Skip to content

feat(libSceFont): build and search word dictionaries as the console does - #9731

Merged
adriadam10 merged 6 commits into
boykopovar:mainfrom
hypermoist:feat/font-words
Oct 26, 2026
Merged

adriadam10 merged 6 commits into
boykopovar:mainfrom
hypermoist:feat/font-words

Conversation

@hypermoist

@hypermoist hypermoist commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

libSceFont's word dictionary calls threw: sceFontCreateWords, sceFontDestroyWords and sceFontWordsFindWordCharacters. They only need the text source, the caller's allocator and the character list that upstream already models, so they can work now.

This PR implements them in a new src/Words.cpp. Their exported entry points stay where the stubs were, in the existing export block of Unimplemented.cpp, and call into it, so no new visibility pragma is needed. They follow the decrypted PS5 13.60 libSceFont.sprx (read from disassembly, not measured on a console):

Call Behaviour
CreateWords Rewinds the source and reads words from its parser. A terminate result with a non-zero code ends a word; code 0 ends the list. Words must arrive in sorted order: a code below the one at the same depth of the previous path, or a code that is not positive, returns SCE_FONT_ERROR_NO_SUPPORT_CODE. A parser error passes on its negative code, and anything else returns INVALID_TEXT_SOURCE. A character at depth 128 stops reading and keeps what was read. The result is a header plus one array of nodes, both from the caller's FontMemory. It is a trie laid out by depth, so each node's children are a sorted contiguous run. The source is rewound again on every exit.
DestroyWords Checks the handle, frees both blocks through the memory it was built with, and clears the caller's pointer.
WordsFindWordCharacters Walks the characters from the first one, skipping synthetic characters, and binary-searches each level. A word ends only where the next character starts a new cluster and is not marked as joined. It returns the longest word, unless the characters are in a segmented run. Then it prefers a word after which another word starts, falls back to the longest, and rejects a first word that a word starting inside it would overrun. nextCharacter is the next rendered character.

Error codes are the existing SCE_FONT_ERROR_* constants: INVALID_PARAMETER, INVALID_MEMORY, INVALID_TEXT_SOURCE, INVALID_WORDS, ALLOCATION_FAILED, NO_SUPPORT_CODE and FUNCTIONAL_LIMIT.

The firmware's CreateWords returns the result of sceFontTextSourceRewind. That export, SetDefaultFont and SetWritingForm return INVALID_TEXT_SOURCE (0x80460008) for an object that is not a text source, not INVALID_PARAMETER, so this PR corrects those three checks in Text.cpp. A null source still returns INVALID_PARAMETER.

Differences, listed in the new debt entry:

  • The source is parsed once instead of twice.
  • More than 65535 nodes return FUNCTIONAL_LIMIT, where the native 16-bit indices would wrap.
  • The next character's shape-entry test is skipped, since strings built here have no shape entry.
  • The segmented-run byte and joined-class bits are tested as read. Strings built here leave them clear, so the names are ours.

The code is written from the observed behaviour; nothing from the module is copied.

Tested

New guest_font_words test. It checks:

  • every argument and memory error, the parser error pass-through, sort violations (including after a shorter prefix word), allocation failure, and that nothing leaks;
  • the three text-source error codes;
  • longest match, the end character, joined and breakable classes, cluster continuations, synthetic characters with and without a leading cluster kind;
  • the segmented-run choices: next word, shorter word, fallback and overrun rejection;
  • an empty list, and the depth limit at 128 and 129 characters.

On main all three calls throw.

  • Linux (CachyOS, GCC, Release): guest_font_words, guest_font and guest_font_writing_line pass.
  • Windows build: cross-built with MinGW-w64 GCC 16.2 and run under Wine 11.19; guest_font_words and guest_font pass.
  • Not run: a title.
  • After merging main 2e0c925 (7e3a978): guest_font_words passes on Linux and on Windows (WinLibs GCC 15.2.0, Release, under Wine), with the NID-patched libSceFont.prx built on both.

tools/check_conventions.py is clean. Overlap:

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 (landing order with test: organize library tests and label CTest suites #6044: either; whichever lands second converts the guest_font_words registration, see Overlap)
  • Fixes: none
  • Unblocks: none known
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Progress report (f26434a → 6f4d796)

📈 System libraries: 48.82% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libSceFont sceFontCreateWords
libSceFont sceFontDestroyWords
libSceFont sceFontWordsFindWordCharacters

Changed libraries (implemented exports)

Library Before After Change
libSceFont 126/195 (64.62%) 129/195 (66.15%) +1.54 pp

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Some 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.

Pull request Shared files not compared
PR 5209 core/libs/prx/libSceFont/src/Text.cpp
docs/dev/debt/libSceFont.md
PR 8250 core/libs/prx/libSceFont/CMakeLists.txt
docs/dev/debt/libSceFont.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WordsFindWordCharacters has an empty-range boundary bug. The existing band test passes endCharacter == band[2] and expects the matcher to stop before that character, so the bound is exclusive. In MatchWords, the character == endCharacter check only happens after the first lookup and after advancing; when firstCharacter == endCharacter, it still reads firstCharacter and can return a match outside the requested range. Please check the bound before the initial FindCode and add a regression where the first and exclusive end pointers are equal (also assert both output pointers are null).

I checked the current source and test suite; this case is not covered. The current convention and whitespace checks pass, while product Linux/Windows CI jobs are skipped. Please rerun the focused font tests after the fix and refresh the branch to current main before merge.

hypermoist and others added 2 commits October 23, 2026 01:10
The firmware matcher at 0x1bb70 looks up the first character before it
compares any character with the end pointer, and the export at 0x1bd90
calls it without comparing the first and end pointers, so a range whose
first and end characters are the same still matches a word starting there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
@hypermoist

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks for checking the empty range. I went back to the firmware (libSceFont, 12.00) before changing it, and the console does the same as this PR:

  • sceFontWordsFindWordCharacters (0x1bd90) checks the words handle, firstCharacter and lastCharacter, then calls the matcher at 0x1bb70 directly. It never compares firstCharacter with endCharacter.
  • The matcher reads the first character's code (+0x28) and searches the root group straight away. It compares a character with the end pointer only after advancing to the next one, the same order as MatchWords.

So when the first and end characters are the same, the console still matches a word that starts there. Checking the bound first would make us differ from the console, so I kept the matcher as it is. Instead I added a regression for this case in GuestFontWords.cpp: dictionary an and ant be, text be, end == first. It pins the console result: last is the e and next is null. This is read from disassembly, not measured on a console.

I also merged current main (8b3a6ba). guest_font_words passes on Linux and under MinGW + Wine, and check_conventions passes.

@MarcZX10

Copy link
Copy Markdown
Contributor

Correction to my earlier review: based on your cited firmware disassembly and the new regression test, I withdraw the request to treat firstCharacter == endCharacter as an empty range. The existing band case only shows that matching stops when advancing reaches the end pointer; it does not establish that the initial character must be excluded. I accept the behavior you pinned as matching the console.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed current head 7518b87dea2049ca05274fc647b4cad4fb6923b4. I withdraw my earlier empty-range code finding: the firmware disassembly explanation and new regression support the behavior as written. No implementation defect is alleged in this review.

Local checks on the exact head: g++ -std=c++20 -fsyntax-only passed for Words.cpp and GuestFontWords.cpp (with the new header overlaid from the PR head); diff-check and conventions passed. I could not run guest_font_words because this checkout has no configured build. The reported Linux and Windows runtime tests are author-reported; current PR hosted product build/test jobs are skipped.

Two integration items remain before merge:

  • This branch is based on 8b3a6ba, 50 commits behind current main (b7d1d47a). Please refresh it and rerun the focused font tests on the current base.
  • Open #6044 rewrites the Font CTest registrations. Your description notes guest_font_words needs its add_library_test form when the branches are rebased, but this PR still says Depends on: none. Please coordinate landing order with #6044’s author and record the dependency/order in the checklist so the new test remains registered after both changes land.

I manually checked the #5209 overlap: its Text.cpp hunk is separate from this PR's changed text-source checks; no same-function duplicate was found there. #9722's Font graphics test addition is separate from the new words test.

@hypermoist

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks for the recheck and for withdrawing the empty-range point.

🤖 Generated with Claude Code

@hypermoist

Copy link
Copy Markdown
Contributor Author

Correction: I mislabelled the firmware. The decrypted modules I read are firmware 13.60, not 12.00 (each module's module-param segment records SDK 13.60). The behaviour described is unchanged; only the version label was wrong. I've updated the description.

Assisted With AI: Yes But all test done locally on actual hardware

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
hypermoist and others added 2 commits October 25, 2026 12:39
Kept main's Api.hpp declarations and dropped the duplicated struct block from Unimplemented.cpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@adriadam10 adriadam10 self-assigned this Oct 25, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 25, 2026 19:03

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@adriadam10
adriadam10 merged commit cbaacd2 into boykopovar:main Oct 26, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the trie build, the word matcher, the three Text.cpp error codes and guest_font_words (pins error codes, sort violations, depth 128/129 and segmented runs; the calls threw on main). Re-checked against current main after #9722: merges cleanly, no shared symbols, both test registrations kept; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants