Skip to content
BrinooTkPublic

About

A Dreamcast emulator that runs natively on a jailbroken PlayStation 5, built on the Flycast core.

Resources

Contributing

Stars

22 stars

Watchers

0 watching

Forks

Repository files navigation

Castation

A Dreamcast emulator that runs natively on a jailbroken PlayStation 5.

Castation is a native x86-64 PS5 executable built around the Flycast core. It is not a port of a Linux build running under a compatibility layer: the shell, the video output, the audio path, the controller handling and the presentation are written against the console's own services, and the emulator is launched by the Homebrew Launcher like any other payload.

License: GPL-3.0-or-later

No BIOS and no games are included, and none will be. You supply your own disc images from discs you own. The emulator can run without a BIOS image through Flycast's HLE BIOS, or use a real one if you provide it.


What works

Verified on hardware, on a console running etaHEN with idlesauce's Homebrew Launcher:

  • Discs load and games run from .chd, .gdi, .cdi, .cue, .m3u and .zip, chosen from a library screen on the console.
  • DualSense: buttons, both sticks and both triggers. The touch pad opens the menu.
  • Sound through the console's audio output, resampled from the Dreamcast's 44100 Hz to the 48000 Hz the console wants. Emulation is paced by the audio clock rather than the display, because the sound chip is the honest clock.
  • Settings that persist across launches: internal resolution, texture filtering, region, language, broadcast standard, DSP, frame skipping, SH4 clock, fast GD-ROM loading and HLE BIOS.
  • Hot disc swapping without restarting the emulator.
  • The graphics processor draws the screen. Scaling the emulated picture to 1920x1080 and storing it in the console's tiled display format is done by a compute shader written in AMD GCN assembly and submitted through hand-built command packets, because the console exposes its command processor and no graphics API above it. Its output is byte-identical to the processor routine it replaced, checked across the whole framebuffer, and it costs about 55 microseconds a frame against several milliseconds before.

Rasterization itself is still done in software, on the processor. The graphics processor currently only presents.

What does not work yet

Stated plainly, because a release that hides this wastes your time:

  • Emulation runs at about 96% of full speed. Sound is correspondingly about 4% flat in pitch. This is a deliberate, measured trade made in exchange for doubling the visible frame rate; see the note on frame pacing below.
  • Hitching. Single emulated frames occasionally take 50 to 100 ms while the recompiler translates new code. It is worst shortly after a scene changes.
  • Heavy 3D scenes drop below 60. On Sonic Adventure 2 the display holds around 57 frames a second at native resolution; a demanding scene costs more.
  • Higher internal resolutions (720p, 960p, 1080p) work but are considerably more expensive, because the software rasterizer pays for every extra pixel.
  • Two-volume shadow modes, mipmap level selection and destination alpha in blending are not implemented in the software rasterizer.
  • Only tested by its authors, on their own consoles. Other firmware and loader combinations are unverified.

Installing

You need a jailbroken PS5 with a homebrew environment already set up, the Homebrew Launcher installed, and its FTP service running. Castation does not configure the console and this project will not help you jailbreak one.

  1. Download castation-<version>.zip from Releases.

  2. Extract it into /data/homebrew/ on the console. The archive carries its own Castation/ folder, so you end up with:

    /data/homebrew/Castation/eboot.elf
    /data/homebrew/Castation/homebrew.js
    /data/homebrew/Castation/sce_sys/icon0.png
    

    The launcher only lists directories containing eboot.elf or homebrew.js, so the names matter.

  3. Put your disc images in /data/homebrew/Castation/games/.

  4. Optionally put a Dreamcast BIOS in /data/homebrew/Castation/bios/. Without one, turn on HLE BIOS in the settings screen; it applies when a disc is loaded, so set it before choosing a game.

  5. Open the Homebrew Launcher and start Castation.

Save files and logs are written to /data/Castation/.

If you have ftp reachable from a computer, the repository's own installer does all of the above except the games:

python3 tools/deploy.py 192.168.1.100

Controls

The touch pad opens and closes the menu. Everything else is the Dreamcast controller mapped the obvious way. In the menu, the shoulder buttons move between the library, settings and system pages.

Frame pacing

Worth explaining, because it is the difference between the emulator feeling smooth and feeling broken, and because it is the reason for the 4% above.

A turn of the shell draws the screen once. The loop that runs the emulator was running it twice per turn, and the first of those two frames was overwritten before anyone saw it — six hundred frames emulated for every three hundred shown. It did that for a reason that fed itself: a turn running two frames takes longer than a display refresh, so it waits for the next one, and by then the audio clock is owed two frames again.

The loop now stops while the frames still fit inside a refresh. Measured on the same stretch of Sonic Adventure 2, that moved it from 33.4 ms a turn to 17.5, and from three hundred frames shown out of six hundred to three hundred out of three hundred and five. Thirty frames a second to about fifty-seven.

What it costs is that a turn which does overrun a refresh now produces one frame where it used to produce two, and nothing repays that; the emulator ends up running slightly slow. Buying that back means making a frame cheaper, which is what the work on moving rasterization to the graphics processor is for.

Building

Requires Docker. Everything else is fetched into an ignored .deps/ cache.

bash tools/build-payload.sh

That produces build/payload/castation.elf, which is what ships as eboot.elf. tools/build-castation.sh instead produces a native title directory and an .ffpkg, which is a separate and less finished route.

The presentation shader is assembled from src/shaders/present.s by LLVM's AMD GCN assembler and turned into a header the application compiles in. A machine without those tools still builds a working emulator: the shader comes out empty and the graphics processor is left alone.

Tests that need no console:

python3 tests/test_display_addressing.py

How it was built

If you want to port a different emulator to this console, the long-form account of what it took — executable memory for the recompiler, the tiled display format, the audio format constants, getting a command to the graphics processor at all — is in docs/PORTANDO_EMULADORES_PARA_PS5.md (Portuguese). The GPU bring-up is recorded step by step in docs/GPU_PRIMEIRO_COMANDO.md and docs/GPU_TRIANGULO_TEXTURIZADO.md, and the probes that produced those results are kept in tooling/probes/ so nobody has to repeat them.

Licence and attribution

Castation is GPL-3.0-or-later. See LICENSE.

  • Flycast by flyinghead and the reicast authors provides the emulation core, under GPL-2.0.
  • The application skeleton, build tooling and native executable converter come from ps5-native-app-boilerplate; its own documentation is kept at docs/BOILERPLATE.md.
  • The homebrew loader this runs under is idlesauce's PS5 Homebrew Launcher.
  • No proprietary Sony SDK file, header or runtime module is used or required.

Dreamcast is a trademark of Sega. This project is not affiliated with or endorsed by Sega or Sony.

About

A Dreamcast emulator that runs natively on a jailbroken PlayStation 5, built on the Flycast core.

Resources

Contributing

Stars

22 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages