Dynamic-Mess.com


"The world is a dynamic mess of jiggling things..."

The PTSD project: how to create mini 2D games on your Sega Dreamcast with PHP

Topic posted the 2025-11-04 in the category Jeux

Topic updated: 2025-11-04

A small post about one of my free-time useless and preposterous projects: running PHP on a 27-years old console in order to create mini video games.

As a software developer, I like to spend (waste) some of my free time on useless and preposterous projects. Most of them remain at the stage of a proof of concept (POC) but sometimes, I get committed to the matter that, in the end, I have learned a lot. It is also a good way to escape from the productive and "always learn about the same things" state of mind we might face at work every day.

In this short post, I am going to talk about one of those special projects. In the beginning, it was to be - properly - named "POC" (for PHP On Console) but after spending so much time on it and having lived it as a ride on a roller-coaster, I decided that the name PTSD (standing for PHP To Sega Dreamcast) would be more appropriate. Let's go.

Origin of the project

For years, I have been willing to learn about creating one of my favorite kinds of video games: 2D ones. After some research, I ended by reading a free but great book titled "2D game development, from zero to hero". In the meantime, coming from nowhere, I got the - absurd - idea of wanting to make a port of PHP on a video game console in order to make games. It remained in this state of wish for some years.

It's time for the ride

At the beginning of 2025, the idea came back, and this time I went through it. I won't write here about the various attempts and ideas I had, but I will go directly to the result. It is important to note, because in the beginning I had no plans, and this project is the typical "emerging architecture" one.

So, basically, what is it?

Let's give a basic reminder about one of my favorite consoles: the Sega Dreamcast. It runs on a 200Mhz 128/64 bits CPU and has 16MB of RAM. I put that here to put the technical context, which is very limiting in comparison with what we have on our modern computers.

My project is in two parts:
- the PTSD project;
- the PTSD-demo project.

PTSD

The first one is a fork of PHP 8.0.30 in order to be able to compile it for the Sega Dreamcast. I worked on this outdated version because I was not sure at all I would succeed, and I wanted to avoid as much as possible any potential issues. So no fibers, no file management, no opcache and no just-in-time, no network. Just basic PHP.

The project itself is about compiling the PHP Embed SAPI to be able to call it from a project written in C. I added a small layer of compatibility to add missing constants, add mocks and stubs to make the compilation possible. After that, when it became clear that the project might be successful, I added a new PHP extension simply named “Dreamcast” in order to add some logic to interact with the console hardware directly from some new PHP code.

This interaction with the console is done with the KallistiOS (KOS) SDK. I insist, it is an SDK, not an operating system. I wired it into my PHP extension, so I would be able to draw things on the screen, listen to the game controllers etc. In this extension, there are also some custom full C - not related to KOS - functions written to perform operations like opening files from the disc and loading them into memory.

PTSD-demo

The second part is a Dreamcast project that uses KOS too. I worked on a Linux setup, with VScode, Make and GCC. In a few words, it embeds all the PHP extensions I compiled, including PHP itself. The PTSD-demo is just a basic toolchain. You have one .c file which is a kind of loader: it starts KOS, calls PHP and injects the PHP script via calling the zend_eval_string() function, and that's it.

Around that I put some scripts that could be useful: converting textures, exporting the game to the emulator (Flycast) or for the console (CDI file) and also some documentation about tooling - that needs to be run on Windows - to create a proper CDI image for the console.

Current status of the project

The project works fine, I did some tests, and even a small - but ugly in terms of code - game.

As it is a POC, if I want one day to continue this project and make it more mature, a lot of things would need to be done.

- Support for the last version of PHP.
- Support for the last version of KOS.
- Usage of a debugger (C, PHP, Console).
- Implementing more features from KOS.
- Refactorization to make the existing code more efficient.
- Better resource handling...

A more detailed list is available on the Github repository.

I made a presentation at the Forum PHP 2025 in DisneyLand Paris in October 2025, and will put the same conclusion here: sometimes, doing absurd stuff and testing crazy things is good for the mind, and you will learn a lot.


Cet article vous a plu? Découvrez d'autres articles :


comments powered by Disqus