Skip to content

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

Closed
p3n1cillin wants to merge 2 commits into
boykopovar:mainfrom
p3n1cillin:codex/font-text-code-iteration
Closed

p3n1cillin wants to merge 2 commits into
boykopovar:mainfrom
p3n1cillin:codex/font-text-code-iteration

Conversation

@p3n1cillin

@p3n1cillin p3n1cillin commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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 fix(libkernel): restore Windows select build for Demons Souls testing #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 fix(libkernel): restore Windows select build for Demons Souls testing #4021
  • AI-assisted: yes

@fma-rc

fma-rc commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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.

RINNECODER added a commit to RINNECODER/AnyPS5 that referenced this pull request Oct 17, 2026
* fix(libkernel): answer a second scePthreadJoin with ESRCH

* fix(libkernel): answer pthread_getname_np for a joined thread with ESRCH

* fix(libc): create noreplace streams exclusively

* fix(pad): read controller commands from Unicode paths

* feat(libSceVideoOut): register PS4 display buffers

Add the PS4 functions sceVideoOutSetBufferAttribute and
sceVideoOutRegisterBuffers on top of the existing registration. The PS4
call uses the first free attribute set and returns its index. It
accepts linear A8R8G8B8_SRGB and A8B8G8R8_SRGB buffers, which map to the
PS5 B8G8R8A8 and R8G8B8A8 formats. It throws for tiled buffers, whose
PS4 layout differs from the PS5 one. Linear PS4 buffers may be 4 KiB
aligned: the OpenOrbis graphics sample places its second 1920x1080
buffer 8,294,400 bytes after the first. PS5 buffers keep the 64 KiB
rule. A handle with PS4 buffers writes the PS4 flip status (64 bytes)
and vblank status (32 bytes). Writing the 128-byte PS5 flip status into
the sample's stack structure overwrote its saved frame pointer.

* fix(agc): release sampled views after storage eviction

* fix(shader): translate f32 compares in f32 denormal modes 1 and 2

v_cmp_X_f32 and v_cmpx_X_f32 flush their denormal inputs by bit 0 of the
FLOAT_MODE f32 denormal field, as measured on RDNA2 (gfx1030): mode 1
keeps them and mode 2 flushes them. Both modes threw before.

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

* fix(shader): translate v_ldexp_f32 in f32 denormal modes 1 and 2

Mode 1 keeps subnormal inputs and flushes a result below 2^-126 to a
zero of its sign; mode 2 flushes subnormal inputs and rounds a subnormal
result in the f32 round mode, as measured on RDNA2 (gfx1030) in every
f32 round mode at IEEE=0 and IEEE=1. Both modes threw before.

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

* feat(libSceFont): implement sceFontCharactersRefersTextCodes and text code stepping

sceFontCharactersRefersTextCodes fills a 64-byte FontTextCodes with the
order and code of a text character and keeps the current, start and
term characters at +0x28, +0x30 and +0x38. The traversal follows the
PS4 11.00 libSceFont.sprx disassembly posted in the review of boykopovar#4050,
which implemented the same rules: Refers never compares the character
with the term and returns null for a clustered or synthetic character,
sceFontTextCodesStepNext returns null at the term after visiting it,
sceFontTextCodesStepBack returns null at the start character, and both
steps skip synthetic characters. Null from StepNext at the end of the
chain and from StepBack at the head of the chain is assumed and not
covered by the report.

The signatures follow Orbital's IDA type database and SharpProspero. A
null cursor or output returns null as in KytyPS5; a null text character
throws. guest_font_tests gets configure_windows_unwind so the expected
exception reaches the test on Windows.

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

* fix(libSceFiber): run a fiber on its own context when the context is large

Since 7947149 every fiber ran on an mmap'd host stack so that host calls
cannot overrun the small contexts PPSA01341 packs next to each other. A
title that derives state from the stack pointer then reads the wrong
memory: PPSA05684's job fibers have 512 KiB contexts at 1 MiB-aligned
addresses and find their job record by masking rsp with ~0xfffff, so the
job system lost track of a GameInit job and the game waited forever
right after loading big4r/actor76.txt. Its 64 KiB fibers fault later on
a host stack too.

A fiber now gets a host stack only when its context is smaller than
64 KiB; a larger context is the stack again, as on the console. The
limit sits between the 16 KiB contexts that need protection and the
64 KiB ones that need the guest stack (technical debt entry). The fiber
test runs a 512 KiB fiber and checks that its stack is in its context;
it fails without this change.

AI-assisted: yes

* fix(agc): write nothing for an empty register list

sceAgcCbSetShRegistersDirect and the other register list writers threw on
a count of 0 although the matching size functions report 0 words for it.
PPSA05684 calls the writer with an empty list at its main menu and
terminated. An empty list now writes no packet and returns the cursor,
as its size says; a null buffer still throws.

AI-assisted: yes

* feat(libc): export the fmin and fmax family

Adds fmin, fminf, fminl, fmax, fmaxf and fmaxl, the remaining
missing members of the C99 minimum/maximum family, with the NaN
propagation and signed-zero handling guest_fminf pins down (host
std::fmin does not guarantee the sign of a zero result). The
previous libSceLibcInternal copy of fminf is removed so the export
stays single-owner. PPSA28319 imports fmaxf from libc.prx; the
other five names were exported by nothing.

* feat(libSceVideoOut): capture the host cursor for guest mice and scale their deltas

The console's mouse reports relative motion, so the host cursor can never line
up with the cursor a title draws. While a title has a mouse open and the
window is focused the host cursor is hidden and captured, released on focus
loss or while the pad's mouse-to-stick toggle is on. Motion deltas are scaled
from the presented image's size in window units to the title's display
resolution with sub-pixel carry, so the title's cursor travels as far as the
host pointer would, on scaled desktops and letterboxed windows alike.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(libSceVideoOut): preserve relative mouse mode for mouse-to-stick

* test(agc): an empty register list into a null buffer still throws

AI-assisted: yes

* fix(agc): copy an indirect draw's vertex buffer only up to its last element

For an indirect draw, whose counts only the GPU knows, the driver copies
the whole range a vertex buffer descriptor covers, records * stride from
the descriptor's address. The last record's element ends sooner when the
attribute sits at an offset in its record, and the fetch can read at most
(records - 1) * stride plus the element.

Forspoken (PPSA03984) draws instances from a 48 MiB buffer of 96-byte
records with six attributes at offsets 0 to 0x50 in each record. The copy
for the attribute at 0x50 ran 0x50 bytes past the buffer into the
unmapped page after it, and the draw stopped with "guest memory is not
readable".

VertexBufferExtent now ends at the last record's element, as
VertexBufferReadSize does for the last record of a direct draw.

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

* fix(libScePlayGo): let users answer unlisted chunks

* test(agc): align indirect argument storage at runtime

* test(libc): cover the whole fmin and fmax family in guest_fminf

* fix(agc): treat a view past a depth surface's first level as memory

A depth surface is one level: the driver rejects draws that render a
depth mip. A sampled or storage view at the surface's address and extent
that starts at a later level, or a storage access to a later level, does
not touch that level, so it is not the depth plane. DepthSurfaceTexture
and DepthSurfaceStorage still sent such views to the surface, which
rejected the level. Forspoken (PPSA03984) builds a depth pyramid from its
1984x1116 D32 depth surface with a compute shader that samples one level
of a five-level R32F view and stores the next, and stopped there.

Both now leave such views to the texture and storage caches, as they
already do for a view of another extent or format.

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

* fix(libc): ignore noreplace for read-only streams

* feat(libSceAudio3d): report supported port attributes

* fix(libc): run guest finalizers before driver shutdown

* test(libc): verify nested exit shutdown ordering

* test(libc): keep firstArgument parsing for the exit-order and relaunch modes

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(libSceNgs2): implement a minimal sceNgs2GeomApply pass-through

Implement sceNgs2GeomApply, which was previously an unimplemented
throwing stub and was blocking Dead Cells (PPSA15552).

The implementation validates null handles/output addresses and writes a
minimal Ngs2GeomAttribute: pitch_ratio 1.0, source position, source
volume/level maxima, and diagonal channel levels for the source's channel
count. It does not implement source attenuation, distance rolloff, panning
or Doppler.

The export lives in Geom.cpp's internal Ngs2GeomApply and is exposed through
the existing default-visibility wrapper in Voice.cpp. Unimplemented.cpp no
longer defines the stub. A passing test was added to Ngs2Geom.cpp.

Unblocks: PPSA15552 #<Game bring-up discussion number>
Depends on: none
AI assistance: yes

* fix(libSceSystemService): report the host time zone and summer time

sceSystemServiceParamGetInt answered 0 for the time zone (parameter 4)
and summer time (parameter 5), so the console looked set to UTC while
libSceRtc and libc convert local time with the host's zone. Titles add
the time zone in minutes and 60 more minutes when summer time is 1 to
UTC to get the local time (Apollo, GoldHEN's frame logger). Both now
follow the host's local time zone: summer time is whether it is in
effect, and the time zone is the current offset east of UTC less the
summer time shift while it is.

On Windows that shift is the C runtime's own summer time bias
(_get_dstbias), the one localtime_s applied, not a fixed 60 minutes.
The UCRT reads the system zone when libc.prx loads and keeps that
zone's bias after TZ is set later, so on a host whose system zone has
no summer time (the CI runner's UTC) a TZ of CET-1CEST shifted by 0 and
the time zone came out as 0. The cause and the change are screamm's,
from the review.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(libSceMouse): implement sceMouseResetAbsolutePosition

* fix(libSceMouse): take the position arguments of sceMouseResetAbsolutePosition

A call site passes the handle and then x and y as zero-extended 16-bit values (the centre of the display size), and ignores the result.

* fix: correct audio-video playback timing and sync

* fix(avplayer): preserve caller-paced delivery in no-sync mode

* fix(libScePad): return measured status for unknown Pad export

* docs(libScePad): record unknown NID probe limits

* fix(libScePad): refuse unknown NID calls with open controller

* test(libScePad): remove obsolete stub-only export check

* fix(libSceRazorCpu): add sceRazorCpuNamedSync export

Resolve the XCuZoBSVFG8 import required by Killzone Liberation by adding sceRazorCpuNamedSync as a no-op returning success when capture is inactive.

Extend the RazorCpu behavior test and document the NID source and unverified console signature and capture behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(libSceRazorCpu): take the label argument of sceRazorCpuNamedSync

* fix(tests): end Windows test processes through libc before DLL detach

On Windows a test that returns from main ends through exit and ExitProcess,
which kills every other thread before the prx static destructors run at
DLL_PROCESS_DETACH. Detached host threads (the driver's async log thread,
libkernel's file watch thread, ...) die holding winpthreads and queue locks,
and a destructor that then locks a mutex, waits for the dead logger or
destroys a condition variable never returns: the test prints its last line
and hangs until the CTest timeout (boykopovar#6791).

Every test executable now wraps main on MinGW. After main returns the
wrapper runs the executable's own exit handlers and static destructors
(_cexit), as exit does today, flushes the streams and ends the process with
LibcTerminate_nid_no_patch, the path the guest exit already takes. That
flushes the driver log while its thread is alive and calls TerminateProcess,
so no DLL_PROCESS_DETACH work runs after the threads are gone. The libc
shutdown callbacks are not run, as on a plain return from main on Linux. A
test that does not load libc.prx returns as before.

* docs(debt): record sceRazorCpuNamedSync silent stub

* fix(agc): forward declare StorageTexture in DepthSurface.hpp

* fix(libkernel): answer scePthreadCancel for joined thread with ESRCH

* fix(metal): align sample position pass check and depth target test parameters

* perf(metal): clamp resident texture view samples under forced 1x MSAA

---------

Co-authored-by: Rujul Talekar <113801876+Roojool@users.noreply.github.com>
Co-authored-by: Ondra97 <47064087+Ondra97@users.noreply.github.com>
Co-authored-by: Get-fix <100056769+Get-fix@users.noreply.github.com>
Co-authored-by: zmeizy <meiz.mzk@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: KernelPanicNT <76663133+KernelPanicNT@users.noreply.github.com>
Co-authored-by: XairRrR <dev910382@gmail.com>
Co-authored-by: akkadbakkad89 <best.dv1996@gmail.com>
Co-authored-by: Mouad-Scriptz-0 <mouadscriptz@gmail.com>
Co-authored-by: MarcZX100 <marczxrr@gmail.com>
Co-authored-by: milescoviello <kitslayer29@gmail.com>
Co-authored-by: fogydes <zeherop2@gmail.com>
Co-authored-by: Romans Pokrovskis <motivated.it@gmail.com>
Co-authored-by: Adrià Franch <adriadam10@gmail.com>
Co-authored-by: alosta <mohammadalosta02@gmail.com>
Co-authored-by: Rick <99503318+0xRickx@users.noreply.github.com>
Co-authored-by: Masud <sheikhmasudhassann@gmail.com>
Co-authored-by: Dean Galvin <dean.galvin@live.com>
Co-authored-by: Leonardo Baldazzi <leonardo.baldazzi2003@gmail.com>
Co-authored-by: MarcZX100 <MarcZX100@users.noreply.github.com>
Co-authored-by: julienlgy <julien.legay2@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants