Skip to content

PS5: native homebrew title, and a packed ROM cache for it - #410

Open
Darkatek7 wants to merge 5 commits into
UNDERdecoded:mainfrom
Darkatek7:ps5-port
Open

Darkatek7 wants to merge 5 commits into
UNDERdecoded:mainfrom
Darkatek7:ps5-port

Conversation

@Darkatek7

@Darkatek7 Darkatek7 commented Nov 21, 2026 •

Copy link
Copy Markdown

Runs the game on a jailbroken PS5 as its own homebrew title (PPSA42002, registered by ShadowMountPlus). Experimental, and there is no release asset yet.

What's in it

  • Runtime (ports/ps5/, scripts/build_ps5.sh, scripts/ps5/):
    • LÖVE 11.5 on the ps5-opengl SDK (Mesa on AGC, GL 4.6 core), SDL with ScePad / SceAudioOut, and LuaJIT with FFI.
    • Built in WSL and deployed over FTP. Details are in ports/ps5/BUILD.md.
  • Console fixes the runtime needed:
    • lstat returns EPERM, so it is wrapped onto stat.
    • The system readdir returns nothing under /data, so a getdents-based directory API replaces it.
    • LuaJIT's os.clock ran 7812× too fast, because Sony's clock() counts microseconds.
    • PhysFS created 0700 folders that ftpsrv cannot enter, so they are now created open to everyone (patch 0002 plus a chmod in the launcher).
    • A relative io.open fails with EINVAL there, so the ROM queue passes the real path.
  • Game side:
    • Platform.isPS5 and a TV-console profile: pad only, no file picker, update notice only, FTP hints.
    • 1080p fullscreen.
    • A README section.
  • Packed ROM cache (src/import/CachePack.lua, CacheFs, the import worker):
    • On the PS5 a Platinum import took 44 minutes. Creating each of the ~18,400 files on /data costs about 11 ms, and after that a create stalls for 0.5–0.9 s about once a second. Appending the same bytes to one file took 8 s.
    • So on the PS5 (or anywhere with POKEPORT_PACKED_CACHE=1) the import writes each version's generated trees into one store-only zip, <prefix>rom-cache.zip, and the game reads it through PhysFS.
    • Loose files still win over the archive, so mods and runtime writes keep working.
    • Every other platform keeps writing loose files exactly as before.
  • Translation: the worker reads a packed cache through the archive's mount. The online hub still only offers games that have a loose cache.

Testing

  • PS5 (FW 13.00, etaHEN):
    • A Platinum re-import takes about 54 s instead of 44 min.
    • The pack was downloaded and checked: 18,432 entries, all CRCs correct.
    • Played from the pack: intro and title screen, a new game into the overworld, a stair warp, outdoors, a save, then quitting and Continue.
  • Desktop with POKEPORT_PACKED_CACHE=1:
    • The pack is byte-identical to a loose import (same 18,432 files, no differences).
    • The scripted boot reaches the overworld with screenshots identical to the loose boot.
    • An import killed midway is not reported ready.
    • Re-importing over an existing pack works.
  • Checks:
    • New: tools/cache_pack_check.lua, 77/77 (CRC, round trip, in-progress reads, the 65,534-entry limit, overflow to loose files, loose wins, abort, clear).
    • Existing ones pass: nds_import_verification_check, tools/translation/check.lua, gen4_cache_wiring_check, and the Switch path, launcher and import-recovery checks.

Known gaps

  • No battle has been played on the console yet. Audio has been checked on the console and works.
  • Re-importing after playing in the same session now works: the launcher closes the Gen 4 ground's range files before unmounting the pack, and a ground that draws again reopens them. This is verified on the desktop with a packed cache, not yet on the console.

The game now runs on a jailbroken PS5 as its own title (PPSA42002, loaded by
ShadowMountPlus): LOVE 11.5 on the ps5-opengl SDK (Mesa on AGC, GL 4.6 core),
SDL with ScePad / SceAudioOut, LuaJIT with FFI. scripts/build_ps5.sh builds
the runtime in WSL and deploys over FTP; ports/ps5/BUILD.md has the details.

Runtime fixes the console needed: lstat answers EPERM (wrapped onto stat),
the system readdir returns nothing under /data (getdents-based dir API),
LuaJIT's os.clock ran 7812x fast (Sony clock() counts microseconds), and
PhysFS made 0700 folders that ftpsrv cannot enter (patch 0002 + launcher
chmod). A relative io.open is EINVAL there, so the ROM queue passes the
real path.

Game side: Platform.isPS5, a TV-console profile (pad only, no picker,
notify-only updates, FTP hints), and 1080p fullscreen.

PACKED CACHE. Creating ~18,400 files on /data took 44 minutes for a
Platinum import (each create ~11 ms, then 0.5-0.9 s stalls about once a
second); the same bytes appended to one file took 8 s. On the PS5 (or with
POKEPORT_PACKED_CACHE=1) the import now writes each version's generated
trees into one store-only zip, <prefix>rom-cache.zip, and the game reads it
through PhysFS; loose files still win over the archive. Measured on the
console: re-import ~54 s, pack verified (18,432 entries, CRCs ok), title,
overworld, warps, save and reload all from the pack. Other platforms keep
writing loose files exactly as before.

The translation worker reads a packed cache through the archive's mount.
The online hub still only offers games with a loose cache.

tools/cache_pack_check.lua: 77 checks (CRC, round trip, in-progress reads,
65,534-entry limit, overflow to loose, loose wins, abort, clear).
…only

Re-importing a version after walking its overworld was refused with "still
in use; restart the game and import again". The last map's ground outlives
the game that drew it (the session just left, a launcher preview) with its
chunk, height and permission files still open, and PhysFS will not unmount
an archive with open files. Gen4RangeFile now records the handles it opens
(weakly) and closeAll() closes them; the launcher calls it before taking the
old pack off the read path. A ground that draws again reopens its file on
the next read (Gen4RangeFile.isLive) instead of failing silently.

Checked on the desktop with a packed Platinum cache: after reaching the
overworld and returning to the launcher, the pack unmounts and can be moved
(it could not before). With all three files closed under a live ground,
store / bdhcFor / permBlockFor reopen and return data.

The "live coverage" line was keyed on the raw reach in view rows, which moves
with the camera, so it logged two lines a frame while the player walked -- a
file write each, which the PS5 pays for. It now keys on covered / short by N
rows.
The PS5 title had no HTTPS client reachable from Lua, so the mod catalog,
launcher news, the update notice and the translation glossary all reported
"no network transport". The runtime now has love.system.httpDownload(url,
absPath, userAgent, accept) -> true | nil, reason, the same bridge Android
has, backed by PacBrew's static libcurl 8.18 (OpenSSL).

- ports/ps5/launcher/http.c: plain C, one easy handle per call, global init
  once. Follows redirects (GitHub release assets), http/https only, fails on
  HTTP >= 400 as "HTTP 404", 15 s connect / 300 s total, writes <path>.part
  and renames on success. IPv4 only: the SDK's getaddrinfo answers v4 only.
- Patch 0003 registers it in love.system's own table, so every Lua state,
  love.thread workers included, gets it.
- CA trust: a pinned Mozilla bundle (cacert-2026-11-05) compiled into the
  eboot and used through CURLOPT_CAINFO_BLOB; libcurl's compiled-in
  /user/homebrew paths are cleared, peer and host verification stay on.
- Link fixes: a real fnmatch and the zstd trace hooks in compat.c,
  --wrap=dladdr. check_imports: 396 symbols (15 new, all resolve).
- HostShell treats the PS5 like Android's bridge and passes on its reason.
  Check.lua keeps the PS5 notify-only: a newer release shows "Copy the new
  release to your PS5" instead of an Update button that can only refuse.

Built and smoke-tested on Linux against the same source (GitHub, release
redirect, Pages mod feed, PokeAPI, 404, expired/self-signed/wrong-host TLS,
DNS and connect timeouts); not yet run on the console.
Tested on the console (13.00): the update check, the release list in the
launcher and the news feed now download; each GitHub request takes about
0.3 s (lookup ~20 ms, TLS ~90 ms).

- http.c resolves the host itself (getaddrinfo, IPv4) and hands curl the
  answer through CURLOPT_RESOLVE.  libcurl's own lookup thread could not
  start in a title ("getaddrinfo() thread failed to start"), so every
  download failed before it connected.  Redirects are followed hop by hop
  so each new host goes through the same lookup.  A hop slower than 3 s
  logs where its time went.
- compat.c wraps fcntl: the kernel refuses F_SETFD/FD_CLOEXEC on a socket
  with EINVAL and curl dropped the connection over it ("fcntl set CLOEXEC:
  Invalid argument").  A title never execs, so the refusal is treated as
  done; every other call and failure passes through.
- The update check's worker calls the bridge itself on the PS5
  (HostShell.bridgeAnyThread) instead of handing each request to the main
  thread as Android must: the launcher stayed black for ~25 s at every
  start while the main thread waited on GitHub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant