Vector games 32c3
From Trammell Hudson's Projects
This is our talk for 32c3 on vector retro-gaming and interfacing MAME with XY displays. The talk is the result of a collaboration with Adelle Lin, another NYC Resistor member who is a digital designer with a focus on building playful spaces, games and interaction. If you prefer to watch, the half hour video is online.
- 1 History of Vector Graphics
- 2 Vector Generating Hardware
- 3 Vector Display Hardware
- 4 MAME
- 5 Taking it further
History of Vector Graphics
The earliest analog computers used oscilloscopes or plotters to output their results. This EAI680 is displaying the result of a differential equation modeling a dampened pendulum on its Tektronix XY monitor.
The first video game, Tennis for Two in 1958, was built with a similar analog computer and displayed on an oscillograph. The bounce of the ball was implemented as a differential equation, very similar to the one shown on the EAI680.
There is no "source code" for Tennis for Two since it was implemented entirely in hardware. There are relays that control the direction of the ball, comparators that detect when it hits the ground or the net, opamps that implement the differential equation, resistors that simulate drag, and so on.
Adelle worked on a modern recreation of it for Silicon City in collaboration with producer Jeanne Angel, games studio Dozen Eyes and physicist Peter Takacs. Due to the pressure of keeping something running maintenance-free for the five months of the museum exhibit, they used a 4K monitor and emulated the game. During the real demo of Tennis for Two at Brookhaven there were technicians replacing parts as they broke, something that the NYHS wanted to avoid.
Spacewar! from 1962 was one of the first digital video games and used the XY display of the PDP-1 to display the players' ships and weapons, as well as the starfield background. The controls were knobs and buttons on the front panel of the system, although many sites built custom controls to avoid wearing out the official ones.
Storage tube vector displays were very popular for engineering applications since they could draw very high resolution lines and maintain a stable image. They are not well suited for games, however, but allowed very low memory computers to draw incredibly complex images over low bandwidth links.
Why Vector Games?
“In 1978 when the Digital Vector Generator was developed for Lunar Lander, memory was much too expensive for a frame buffer in a video game. […] Two frame buffers of 512x512x4 would have required 128 memory devices costing [a total of] $614.”
-- Jed Margolin, Atari engineer
This is why is was worth going through all of this effort to draw vectors when most displays are raster-scan. The cost of building a raster version of Asteroids with a frame buffer than could hold the screen resolution of 1024x1024 would have been thousands of dollars in hardware. It also requires a display that could draw that many vertical lines: most CRTs were being built for television use and only had a few hundred vertical lines of resolution.
Compare the blocky, pixelated bitmap Starwars game to the vector vesion. It's really stunning how much more detail the vector lines can resolve and how well they can represent the circle of the Death Star.
Additionally, vectors make it easier to do 3D animation. Here's a comparison of a bitmap game attempting to simulate a 3D world with the Starwars scaled and rotated 3D model of a Tie-Fighter. Which would you rather play?
Vector Generating Hardware
How vectors are drawn
In a vector display the beam doesn't draw horizontal "raster" or "scan lines" like a conventional CRT. Instead the beam can be steered to any point on the screen and creates a bright dot at that location. With non-storage vector displays, the longer the beam remains on that point, the brighter it becomes. By varying the X and Y inputs, it is possible to draw lines or other shapes. By moving quickly or by varying the brightness ("Z") input, disconnected lines can be drawn. In this case I've disabled the Z input so that we can see the drawing order of the objects on screen. Lunar Lander shown here uses a "digital vector generator", which directly drives the beam.
Tempest uses an "analog vector generator", which always returns to center since that is the only defined point. In either case it is a "hard real time problem" to generate these vectors -- if the system pauses even for a few nanoseconds there is an appreciable change in the brightness of the line.
Analog vs digital vector generation
I'm indebited to Jed Margolin's guide to vector displays for this section.
One way to generate the vectors is with a Digital-to-analog converter (DAC) that directly drives the X or Y input to the display. This is called a "Digital Vector Generator" and was used on the early games like Asteroids and Lunar Lander. They used 10-bit DACs and an opamp configured as a buffer, but required that the CPU spend most of its time updating the inputs to the DAC and also limited the resolution to roughly 1024x768.
Another technique was developed for later games like Starwars. The "Analog Vector Generator" uses an opamp configured as an integrator by the addition of the capacitor on the feedback path. This means that the input to the DAC is the slope of the line to be generated and the analog nature of the opamp ensures that an "infinitely" smooth line will be drawn.
With modern hardware we can generate 12-bit lines that far exceed the resolution of the small vector displays and we can take advantage of the DMA engines on modern microcontrollers to offload sending the data to the DAC. This board is a prototype of my opensource hardware v.st boards and is easy enough to build on a breadboard for you own hacking.
And since we have far more CPU power than when many of these games were created, I've also patched the vector generation code to sort the vectors to reduce the overall travel time. This makes a big difference for vector displays with lower bandwidth.
Vector Display Hardware
Modern digital oscilloscopes are not very good for displaying vector data. The LCD might emulate phosphor persistence, but they typically only have 8-bit ADC and very low resolution. They are still super useful for general signal measuring, just not in this application!
Instead go to ebay or craigslist and find a $50 analog CRT two-channel scope with an X-Y mode. Anything with 5 MHz or more of bandwidth is fine -- the DACs on the v.st boards are less than 2 MHz anyway.
Storage tube displays are great for very detailed static vector images, but won't work well for games with high framerates. So save your money and don't spend it on a Tek 4014.
Vectorscopes like the Tek 1720 were used by TV stations to calibrate their colorbars and being phased out as the stations go digital. As a result these analog displays are plentiful and inexpensive on ebay. They use very fast electrostatic deflection and typically have small screens, but they tend to be super sharp. They also have differential inputs, so that you can don't need a negative output on the DAC.
The Vectrex home game console has a nice large, sharp B&W screen. It is fairly easy to disconnect the original motherboard from the analog CRT driver and route it to the outside of the case to allow a v.st board to be plugged in.
The Vectrex has a somewhat slow magnetic deflection system, which prevents it from drawing as many vectors as the faster electrostatic displays. It is much larger, however, and also offers a Z-input that allows the brightness to be controller without varying the line drawing speed.
You can use a laser projector as well, but the results are really suboptimal. The physical mirrors have quite a bit of inertia and turning the beam on and off requires time. The refresh rates tend to be low and the images very flickery. Some specialized games might work with very fast (45-60Kpps) galvos, but most arcade games required too many vectors.
The LazyMame project appeared to be making good progress, but I can't find any details or source code since 2008. OpenLase-Mame had some development in 2013, but nothing for three years. Other people have tried a custom Unity plugin to create new laser games, with some success.
MAME is the Multiple Arcade Machine Emulator and it really lives up to its name: it can emulate thousands of games and cabinets, including nearly every vector arcade game ever made.
Emulating Vector Displays
The "bloom" effect caused by the bright vector lines is one of the features that is most desired by game players. MAME has support for HLSL shaders that blur the bright lines and creates an approximation of the effect. On the left you can see a real Vectrex display and on the right MAME's emulation of a similar effect.
Patches for head
Unfortunately my patch to add support for exporting the vectors to MAME was closed as "an unacceptably hacky way to achieve the intended result". Instead you'll need to clone my tree and follow my instructions on building vector MAME. The majority of the changes are in src/emu/video/vector.cpp and take advantage of the clipping windows that MAME is using to limit the vectors to the onscreen area.
Patches for Raspberry Pi
I've also ported the changes to the stripped-down MAME4AllPi build for the Raspberry Pi. The instructions for Pi vector MAME are similar; you'll need to clone my tree and build it on the Pi. There are quite a few issues that need to be fixed related to joysticks unfortunately.
You can play one of the original arcade games, Space Wars from 1977.
Asteroids (1979) is always popular as well. One of the highest grossing games of its era!
There are lots of vector games to emulate. All of the ones in Atari games are there.
Taking it further
Custom input devices
Once you have your vector display hooked up the MAME, you'll probably want to take it to the next level. It is fairly easy to build custom USB HID joysticks using Adafruit arcade joysticks, buttons and even coin acceptors.
Tim Bartlett's Raspberry Pi Asteroids console looks great and he has published all of the design files if you want to build your own.
Juergen Mueller build a marvelous Asteroids cabinet with Vectrex display that uses a real Asteroids logicboard, which is just above and beyond.
Creative coding with vectors
If you're tired of playing games, you can always turn the display into a Scope Clock. The Teensy 3 has through-holes for a 32.768KHz clock crystal and backup battery that lets it keep decent time.
Some folks are really taking it to the next level -- vec9 is the first full-scale vector arcade game in decades and has a custom cabinet with a real tank controller.
We've written a simple Processing library to show how to write things that interact with the displays. Sample code is at vst/processingDemo and also available as ProcessingJS, demoed in Swarm and Random Walk.
If this is of interest to you we'll be having a class at NYC Resistor in collaboration with Code Liberation and an exhibition at Baby Castles in early 2016.