Welcome

Running Tetris

Obviously, 'just port SIMH to an ESP32' is a bit of a understatement for the effort that was needed. Even while SIMH is a pretty nice program when it comes to not using any unique APIs, it still is a system developed for a full-blown workstation and assumes RAM is cheap and plentiful. In order to get it running on an ESP32 and still have some memory left we can use as RAM for the emulated machine, I needed to strip it down first.

The major casualties here were the network stack and the configuration parser. Effectively, SIMH consists of multiple modules that each emulate one or more peripherals. For instance, each generalized disk type has a module. The same goes for network devices, teletype interfaces, printer ports etc. All these modules are connected together using a configuration specified using a command-line configuration interface. This configuration interface is used on startup to assemble the PDP11 configuration you require as well as act like a debug command line interface after.

While this operation model is very nice and allows you to dynamically create PDP11 configurations and even change things on the fly, it was also a pretty large part of the code, and on an ESP32 with limited resources, it's generally more feasible to hardcode the configuration. The network code had a different issue: while it offers a cornucopia of connectivity methods, none are compatible with anything running in the ESP32. As such, the file was gutted as well.

There were some minor cuts as well: all the non-necessary peripherals (tape drives, vector monitors, punch card readers, etc) were removed so they would not take up any room in RAM or on the flash. Debugging features were also cut: while SIMH has some pretty nifty features usable for debugging any PDP11 code running on it; we don't need those in this version, so they were removed.

All in all, I initially assembled the bare minimum to run Tetris. The specific russian hardware Tetris ran on was an ELEKTRONIKA 60M, which is a PDP11-23 clone sporting a maximum of 64KByte of RAM and outputting its serial port to an 15ИЭ-00-013 terminal, which is a Russian terminal loosely based on a DEC VT52 with Cyrillic text support. The machine ran the FOBOS operating system, which was the Russian equivalent of DECs RT-11 operating system.

As the specific Russian clone hardware and software isn't supported or available, the best I could do is to use the original Western stuff it was copied from: seems the Russians did a good job of keeping everything inter-compatible. As such, the ESP32 was configured to emulate an PDP11-23 with 256K of RAM and a RX01 floppy disk drive, giving me 256KB of disk space for the operating system and game files. I used SIMH on my laptop to create a blank disk and installed RT11 onto it. Next, I took the Russian games disk containing Tetris and copied the binary over. That disk image would get flashed alongside the emulator to the ESP32. I didn't bother with the terminal as of yet, instead opting to just pipe the console of the PDP11 out of the debug serial port of the ESP32.

This actually allowed me to get RT11 running and gave me a command line. However, running Tetris did not- give me anything usable: the game expects a Russian 15ИЭ terminal, and my modern terminal emulator does not even begin to try to emulate it.

Luckily, the terminal actually is emulated as part of Mame/MESS. After I tracked down the ROMs needed, I could emulate the old beast, and some configuration and socat magic later, I actually got to see the original Tetris running on my ESP32 for the first time:

Obviously, a solution like this is no fun; you'd want to view Tetris on a display that's connected to the ESP32. The ESP-Wrover-Kit I use has a 320x240 color display, perhaps I could use that? Well, the 15ИЭ, like the VT-50 terminal it's derived from, can display 24 colums of 80 rows of text, which would give us only 4x10 pixels to display a character... Looking at the original 15ИЭ ROM, the characters there were 8x8 pixels, meaning we would need to squash two horizontal pixels into one... Luckily, with some tricks (specifically making a LCD pixel that contains two lit up 'squashed' pixels brighter than a LCD pixel with only one lit up 'squashed' pixel), the effect is actually pretty readable.

The 15ИЭ terminal more-or-less contained an entire microprocessor built up from discrete logic. While I could emulate to get real close to the 'real thing', I decided to take the lazy way out and just model how it interprets the serial stream escape characters in C. The end result is an 15ИЭ simulator that is far from perfect, but good enough to show you the playing field of Tetris:

Obviously, just showing the playing field is not good enough, and the ESP-Wrover-Kit board does not really have enough buttons to be able to control the falling Tetrominoes properly. Luckily, the ESP32 has Bluetooth and someone going by the nickname of Rossum wrote an emulator for a bunch of 8-bit consoles that could use Bluetooth gamepads and keyboards as an input method. As this code is released under a public license, I could grab it, get rid of the Arduino-esque things (which unfortunately also killed Wiimote support) and plunk it into my code.

Now all I needed was a Bluetooth gamepad (which I found in the form of one of the Joy-Cons of my Switch) and I could happily play the original version of Tetris, all on my ESP32 devboard:

« Prev 2 Next »


© 2006-2022 Sprite_tm - Contact