February 22nd, 2025
Growing up, I spent a lot of time gaming. Countless hours playing Mario Kart 64 and Mario Kart Wii. Could I use JavaScript to play retro games like these online?
This project started with an old 2014 Mac Mini I had lying around. It wasn't good for much else anymore, but it was still powerful enough to run anything from the Wii backwards. Why not make it a retro gaming console!
Over the course of a few months, I installed a bunch of emulators, mapped the controller inputs to the keyboard, and started hacking away. At first, I thought I could just use desktop automation frameworks with Node.js to simulate key presses to control the players. I tried Cypress/Puppeteer/Robot.js - The key presses they emitted seemed to be synthetic — they only exist for a brief moment after being triggered and don't hold down like a real keypress would. The result of this was that the emulator would ignore their inputs.
I almost gave up at this point, but decided to try a different approach. There were a few command-line tools that seemed they might do what I needed. I also tried Apple Automator. No luck with either of those!
While searching for a solution, I stumbled across a StackOverflow post where someone recommended a Teensy board. These boards designed for creating USB devices that run your custom code, perfect for simulating keyboards and joysticks. I bought one and uploaded some basic code that would allow it to receive instructions from Node.js on which keydown and keyup presses it should emit over serial. These would be fed into Mac Mini, which would not know the difference as it would see the Teensy as a real USB device.
Success! The setup worked exactly as I wanted 🎉
The next step was creating some way to provide the user inputs to the Mac Mini. I used Socket.io to create a websocket server with express.js, using the socket.io-client library to roll a simple controller UI to emit key presses. This meant I could now play from any internet-connected device I wanted, without needing to connect anything to the Mac Mini.
This has been a fun journey, and I'm excited to see how far it can go. It needs a lot of work to provide a good gaming experience, but I'd like to be able to play classic games together with others over the internet - possibly on Twitch.
I'll provide more updates for this project in the future!