Emulating All the Things Part 3: The System

Welcome to part 3 of my obsessive journey to emulate all the things. As one might expect this endeavor has plunged me into a deep darkness of unending despair. Just kidding it’s fun. Playing retro games is fun I mean. The emotional experience of reading about setting up retro games is up for debate. But this is the beginning of the cool part of the series. The part where I make things significantly harder on myself because the off-the-shelf options were not immediately what I wanted, even though I barely gave them a chance.

Before we get into the details, it’s important to point out there exists entire Linux distros that are focused on retro gaming, never mind the copious amounts of Open Source software available to organize and unify a diverse retro game system. I would recommend all of these options over following anything I have to offer. However, I have sussed out some edge cases in the retro gaming world that are not very well documented, if at all, and I wanted to have absolute control over as much of the system as possible. So here we are.

The base system is Debian unstable, configured to boot such that a user account is auto-logged in, Xorg is started via startx, and the arcade UI is launched full screen, all without any user interaction. Hardware accelerated graphics are supported out of the box for the AMD 780m, so that bit is easy for a change (looking at you NVIDIA). Everything is stored in a simple structure in /opt/arcade/. At least it was until I ran out of space and added some overflow storage. I wanted to build the kernel and some emulators from source so used apt to install the toolchains and support libs to do so.

The window manager for the primary display (where the games play) is Openbox. The secondary display has no window manager at all, since it just shows information about the current system/game on the main display. The 2 monitors are configured in Xorg as 2 independent screens, but by default that allows the mouse to travel to the second screen, which is not ideal.

Super cool hack #1:

You can use the xorg.conf file and absolute positioning to make the second screen entirely inaccessible to user focus. Just use the ServerLayout section to position the second xscreen > 0 pixels away from the edge of the main screen.

I ended up building all the glue that holds this system together in bash. Not surprising since I have been doing that same thing for dozens of projects over the last 2 decades. Part of what makes bash so powerful is the seamless integration of Linux userspace utilities, and for this project there are a few that are very handy. All of these are either installed by default, or just an apt install away

wmctrl

A tool to control windows via a script. The main use case for this project is to facilitate a unified exit process for different emulators tied to the same button on the arcade controls (without resorting to sending a kill signal)

xdotool

This program can send input events like keystrokes or mouse actions to windows from a script. These events are “pseudo input” and apps can choose to ignore them, but for the most part I have had no issue with that aspect. However when I first started testing xdotool to send keys to the active window I was not having any success.

Super cool hack #2

In its simplest form “xdotool key Return” should send the Enter key to the currently active window (depending on how it’s called you need to set the correct DISPLAY variable of course) but on my system this just flat out does not work. What I discovered is that if you chain “xdotool keydown Return” + “sleep .1” + “xdotool keyup Return” then it works like a champ every dang time.

gamescope

A program created by Valve that is sort of like a gaming oriented version of Xnest. You know Xnest, an Xorg client that then runs an Xorg server inside a window that can have it’s own Xorg clients. I mean, who doesn’t use Xnest all the time right? Well gamescope is not exactly that, and using it outside of Steam is hit or miss, but it creates a window with a specific size and properties (shaders even) that you can then run another program inside of. In this context it’s useful to run an emulated system at full-screen from the emulators point of view, but not full screen in the window manager.

xbindkeys

A window manager independent key binding program to tie inputs to scripts or programs. The system should be controlled by the arcade controls as much as possible, and xbindkeys fits the bill. I have been using this utility on all my machines forever.

dillo

Very lightweight minimalist web browser. I’m using this for the information display by dynamically creating a snippet of HTML, then loading it in dillo on the second X screen. This can be tricky as that screen has no window manager, but dillo works a treat for this. Fun fact: I used to use dillo as my main web browser. My favorite feature is its lack of JavaScript support.

btop

Very cool souped up version of top that has some nice GPU monitoring as well as all the system level stuff you would expect (process list, CPU core speed/temp, network throughput, memory/disk space, etc). And it has very nice looking customizable color schemes, which obviously is very important.

xrandr

A powerful utility to control monitor displays. Great for setting the display resolution and refresh rate, which makes it the ideal tool to toggle the display from portrait to landscape mode.

firefox

I tried a few retro game UIs (of which there are many) but for one reason or another they just did not have exactly what I wanted. So, I built my own as a web page rendered in firefox kiosk mode. How exactly does one create a retro game UI as a webpage in firefox you ask? Well I’m glad you did, since that will be explained in the next post!

Leave a comment