Porting the software

Now, having Pinball Fantasies running on a PC is nice, but it already could that, and it's not enough if you want a tiny pinball machine. I needed to port it to a microcontroller, and as stated before, an ESP32-type chip would be just the thing. I work for Espressif, so I have enough of those lying around.

My first attempt was to run it on an ESP32-Wrover-Kit development board. This is an older development board with an ESP32 with flash and PSRAM, programming/debugging hardware and a 320x240 SPI LCD on it. As I kept the bindings for the graphics, audio and input separate from the emulator and other logic, it was quite easy to modify those to output to the ESPs DAC and the SPI LCD, and take input from some buttons connected to GPIOs. The end result wasn't optimal (for instance, the LCD runs at 30FPS while the game itself runs at 60FPS). Which is okay, as the ESP32 and the SPI LCD weren't the intended final target.

So, what was the final intended target? Well, if I were to create an actual table, I'd need a display that could show the 320x620 table all at one time, and preferably at 60FPS. There are nice large viewing angle 3" 360x640 displays; these are small enough to go into a tiny pinball table and have a resolution that fits the table without having to do weird scaling tricks. These displays are parallel RGB, though... which is a nice excuse to upgrade to an ESP32S3, as that chip has an integrated parallel LCD interface. I imagined it would also solve the slight performance issue: while the core still runs on the same speed as the ESP32, the cache is more advanced and it can be coupled with faster PSRAM.

As I lived in Shanghai at the time of building this, and we had to cope with a lockdown, I couldn't immediately design and order a PCB and use that as a base for software development. So instead, I hacked something together on prototype PCBs that I had anyway. This is the hardware I ended up with:

The hardware has all the things to replicate the inputs and outputs Pinball Fantasies has: the 360x640 LCD to show the table, an amplifier and speaker for the audio, buttons for input. You may see that the hardware also has some functions that aren't supported by the actual Pinball Fantasies game itself: there's a second LCD to act as the backboard for the pinball table, a miniature plunger to shoot the ball into the table, and if you look closely there's a linear actuator (the small metal box on the brown PCB) to simulate the feeling of an actual ball bouncing around in the pinball machine.

To add support for those, there are hooks that allow external code to peek into the emulated code and set and get variables. Having the source here makes locating those and finding out how they work extremely easy: I grab the velocity of the ball to see if that changes rapidly and trigger a haptic feedback event accordingly; if the real-life plunger is pulled and released, the velocity is set in the emulated games plunger velocity variable.

Not shown in the picture: I later also added an 1.5" 240x240 pixels LCD to act as the backboard of the table. It's not a very complicated thing to integrate in the codebase: it works by loading static images and by rendering the portion of video memory that contains the dot matrix display. This gives you a backbox with an illustration of the currently selected pinball table on top while the dot-matrix display is shown on the bottom of the backbox, where it would be on an actual pinball table.

With all the pinball functionality in place, I could design the PCB, so I could order it when the lockdown lightened up.

« Prev 3 Next »

© 2006-2022 Sprite_tm - Contact