feat(libSceFont): implement text-code cursor iteration #4050

Closed
p3n1cillin wants to merge 2 commits from upstream-pr/4050 into main
p3n1cillin commented 2026-10-11 22:10:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-11T22:10:26Z.


What

Implement sceFontCharactersRefersTextCodes, sceFontTextCodesStepNext, and sceFontTextCodesStepBack over the existing font-string character links. The cursor exposes the source ordering token and Unicode code, includes the supplied terminator, stops backward traversal at its starting character, and preserves the last valid step when an end is reached. This replaces three throwing exports, raising the source count from 2,946 to 2,949 of 3,437 on base 2c8122c9f (85.71% to 85.80%).

Signatures follow Orbital's type database and SharpProspero's bindings. The 64-byte cursor and public order/code fields follow SharpProspero's structure. Traversal rules and private current/start/terminator offsets follow the PS4 11.00 behavior reported in review. Initial clustered or synthetic characters are rejected; traversal skips synthetic characters but keeps cluster continuations. PS5 behavior, null-input results, lifetime requirements, and console error precedence remain unverified and are recorded in TechnicalDebt. No PS5 hardware or title validation of these exports is claimed.

Tested

  • Windows, WinLibs GCC 15.2 UCRT POSIX SEH, Release/Ninja: built the four font test targets; guest_font, guest_system_font, guest_font_writing_line, and the new guest_font_text_codes passed.
  • Current main fails to compile Socket.cpp on Windows because HostPoll is undeclared. Windows validation temporarily applied the existing fix from #4021; that patch is not included here.
  • WSL Ubuntu 24.04, GCC 13.3, Release/Ninja: built the same four test targets and passed all four font tests.
  • The new test creates and parses a string using a synthetic TrueType font, checks ordering tokens, forward/backward traversal, an inclusive terminator, equal start/end pointers, backward start bounds, synthetic-character skipping, cluster-continuation traversal, end-state preservation, non-ASCII/combining codes, and null inputs.
  • Progress report/encoding, import audit, function-body conventions, test registration, tools/check_conventions.py --base origin/main, and git diff --check origin/main...HEAD passed.
  • The expanded Linux regression test fails against the previous PR library at the backward start-boundary assertion and passes with this fix.
  • Full suite and game runs were not performed on this PR branch.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none; Windows validation used the separate build fix #4021
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822756398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4050). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-11T22:10:26Z. --- ### What Implement `sceFontCharactersRefersTextCodes`, `sceFontTextCodesStepNext`, and `sceFontTextCodesStepBack` over the existing font-string character links. The cursor exposes the source ordering token and Unicode code, includes the supplied terminator, stops backward traversal at its starting character, and preserves the last valid step when an end is reached. This replaces three throwing exports, raising the source count from 2,946 to 2,949 of 3,437 on base `2c8122c9f` (85.71% to 85.80%). Signatures follow [Orbital's type database](https://github.com/AlexAltea/orbital/blob/cc408367da6a6ebbf5ac1ac559fefeadc73b2831/tools/ida/db_types.json) and [SharpProspero's bindings](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Font/SceFont.Engine.cs). The 64-byte cursor and public order/code fields follow [SharpProspero's structure](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Font/SceFontStructs.cs). Traversal rules and private current/start/terminator offsets follow the [PS4 11.00 behavior reported in review](https://github.com/boykopovar/AnyPS5/pull/4050#issuecomment-6114504202). Initial clustered or synthetic characters are rejected; traversal skips synthetic characters but keeps cluster continuations. PS5 behavior, null-input results, lifetime requirements, and console error precedence remain unverified and are recorded in TechnicalDebt. No PS5 hardware or title validation of these exports is claimed. ### Tested - Windows, WinLibs GCC 15.2 UCRT POSIX SEH, Release/Ninja: built the four font test targets; `guest_font`, `guest_system_font`, `guest_font_writing_line`, and the new `guest_font_text_codes` passed. - Current main fails to compile `Socket.cpp` on Windows because `HostPoll` is undeclared. Windows validation temporarily applied the existing fix from #4021; that patch is not included here. - WSL Ubuntu 24.04, GCC 13.3, Release/Ninja: built the same four test targets and passed all four font tests. - The new test creates and parses a string using a synthetic TrueType font, checks ordering tokens, forward/backward traversal, an inclusive terminator, equal start/end pointers, backward start bounds, synthetic-character skipping, cluster-continuation traversal, end-state preservation, non-ASCII/combining codes, and null inputs. - Progress report/encoding, import audit, function-body conventions, test registration, `tools/check_conventions.py --base origin/main`, and `git diff --check origin/main...HEAD` passed. - The expanded Linux regression test fails against the previous PR library at the backward start-boundary assertion and passes with this fix. - Full suite and game runs were not performed on this PR branch. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none; Windows validation used the separate build fix #4021 - [x] AI-assisted: yes
fma-rc commented 2026-10-11 22:18:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T22:18:28Z.


The PS4 11.00 libSceFont.sprx exports all three functions with the same NIDs, and its traversal rules differ from the inferred ones here in three places. This is PS4 behaviour, I have no PS5 source for it.

sceFontCharactersRefersTextCodes (0x15f80) never compares the character with the terminator, so equal pointers give a valid cursor. It keeps the start character at cursor +0x30, the current one at +0x28 and the terminator at +0x38.

sceFontTextCodesStepNext (0x15fd0) returns null only when the current character is the terminator (cmp 0x38(%rax),%rcx before advancing), so the terminator itself is visited: over A B C with C as terminator it yields B, then C, then null. This PR stops at B.

sceFontTextCodesStepBack (0x16020) returns null when the current character is the start character (cmp 0x30(%rax),%rcx), so a cursor created at B does not step back to A. This PR walks to the head of the string.

Both step functions also skip characters whose byte at +0x33 is set, and Refers returns null for a character with +0x31 or +0x33 set; sceFontCharacterRefersTextNext here already filters on those two fields (clusterIndex, synthetic).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114504202 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4050#issuecomment-6114504202). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-11T22:18:28Z. --- The PS4 11.00 `libSceFont.sprx` exports all three functions with the same NIDs, and its traversal rules differ from the inferred ones here in three places. This is PS4 behaviour, I have no PS5 source for it. `sceFontCharactersRefersTextCodes` (0x15f80) never compares the character with the terminator, so equal pointers give a valid cursor. It keeps the start character at cursor +0x30, the current one at +0x28 and the terminator at +0x38. `sceFontTextCodesStepNext` (0x15fd0) returns null only when the current character is the terminator (`cmp 0x38(%rax),%rcx` before advancing), so the terminator itself is visited: over A B C with C as terminator it yields B, then C, then null. This PR stops at B. `sceFontTextCodesStepBack` (0x16020) returns null when the current character is the start character (`cmp 0x30(%rax),%rcx`), so a cursor created at B does not step back to A. This PR walks to the head of the string. Both step functions also skip characters whose byte at +0x33 is set, and `Refers` returns null for a character with +0x31 or +0x33 set; `sceFontCharacterRefersTextNext` here already filters on those two fields (`clusterIndex`, `synthetic`).
oneandonlydean commented 2026-10-12 08:29:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:29:41Z.


Closing: no title is shown to call sceFontCharactersRefersTextCodes, sceFontTextCodesStepNext or sceFontTextCodesStepBack, and the behaviour comes from the PS4 library only. Reopen with the title ID and the log line when one stops on them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120599825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4050#issuecomment-6120599825). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T08:29:41Z. --- Closing: no title is shown to call `sceFontCharactersRefersTextCodes`, `sceFontTextCodesStepNext` or `sceFontTextCodesStepBack`, and the behaviour comes from the PS4 library only. Reopen with the title ID and the log line when one stops on them.

Pull request closed

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!4050
No description provided.