Friday, July 5, 2019

Playable emulation, and more!

It's July already! 2019 is half over! My last progress update was several months ago back in March. I meant to post an earlier update, but I waited until I had playable pong to show and share. Yes, I finally have a complete verilog description based on die photos of the AY-3-8500, and it can be run on a physical FPGA. Along with that, I have other exciting news related to the project. Let's get started.

First, the recap. For the past few months I've been working on creating accurate emulations of 1st generation video game systems. These games may be deceptively simple, a large chunk of them are just clones of pong, but the
game logic is burned into specialized integrated circuits. As detailed documentation is scarce, I've been recreating their behavior by converting photos of the internal circuitry into a verilog description of the logic circuits.

The first chip being emulated is the AY-3-8500 "Pong on a chip" circuit. It formed the heart of over 200 different types of pong consoles produced in the later 1970s and early '80s, which were produced in the millions. As you'd expect, it contains the digital circuitry to play a few different pong-like games (plus two games with light guns) on a home TV set.


Above is a video I recorded of the AY-3-8500 being emulated on a FPGA chip. The paddles move, the ball bounces, and the score increases each time a goal is achieved. Grounding certain pins selects the different games, while others modify the gameplay slightly, just like on the real thing. Everything has been tested except for the rifle circuits, as I didn't setup the external hardware needed to support a light gun.

Overall it accurately recreates the behavior of a real AY-3-8500 chip. The only major difference is that the ball doesn't always hit the paddles when I want it to; this is probably caused by the bad controls I used and definitely not due to lack of skill or anything like that.

Screenshot of nextpnr showing the placed & routed components

You can find the source files here The folder contains the verilog description of the AY-3-8500-1, a top.v file specific for the tinyFPGA BX, and a compiled bitstream. If you have a tinyFPGA board, or another FPGA with the necessary tools, then you should be able to play it yourself (note: there are issues with the place & route, see below). If not, you'll have to wait until it is ported to a MiSTer core or made into a software emulation.

Next things tor the AY-3-8500

Although the vast majority of it completed, some work related to the AY-3-8500 still needs to be done. First off, the verilog has about a dozen manual patches in it which need to be worked into DLAET. There is also a decent possibility that an error or two made it into the verilog without being noticed or patched. Eventually DLAET's output should be as accurate as the FPGA allows without any patching.

There are also problems concerning the design's reliability upon being placed and routed. As I've talked about before, there are many "nasty tricks" which hardware designers used long ago which are difficult to translate to modern hardware. I've written code to recognize and handle most examples of these, however the verilog still breaks a few hardware design "no-nos". Because of this, a large number of generated bitstreams (the file that is loaded onto the FPGA) will work incorrectly. This can be overcome by changing the random seed for the place & route algorithm until it works correctly, a little tedious, but OK in lieu of a better solution for the time being.
The breadboard game setup I used isn't very convenient, especially with the composite plugs dangling off of it. I also used a pair of cheap potentiometers from an Arduino kit. Because of that, non-recommended values, and unsoldered connections, the paddles jitter like crazy. Not a long term solution. As said before, I'm going to port it to the DE-10 board which runs the MiSTer project. This should be a fairly straightforward process, and will make playing it MUCH easier.
The DE-10 Nano board that MiSTer uses.
Software only emulation is also straightforward. Originally when I started writing my netlist processor (DLAET), It was going to output C++ code. Later I learned about Verilator which does much of the work for me once the netlist has been converted into verilog The verilog (actually an older version of it) was already successfully converted into a C++ file. C code to display the signals and poll user inputs will need to be written to make the simulated chip playable. After doing some thinking I decided that the best way to proceed would be to create a standalone emulator, then porting the code over to MAME (possibly a fork). I should have screenshots or source code of a software emulator not too far in the future.

Sea battle!

Those of you who haven't been following along may wonder why is this such a big deal, and why did it take months to complete something so simple? After all, pong is a common project for people learning FPGAs. The AY-3-8500 has also been reproduced before because very detailed documentation is available. The importance of this implementation is that the process developed is based on die photos instead of datasheets/observed behavior, and much of it is done automatically. The process and tools pioneered here can, will, and are being used on other game chips with less documentation. In fact, another chip has been simulated in the visual6502 engine since last time.
2777 Simulated transistors
The AY-3-8605 chip (aka Naval Battle, Sea Battle, Warfare, Bataille Navale) generated a fairly unique skill game pitting (very blocky) ships against a submarine, or (also blocky) spaceships against one another. Games were either two-player or single-player versus an extremely basic AI. Here's a video of an original system in action.

A screenshot generated from the JS simulation

It took about a month to highlight the images of the chip, which I started doing in April. Once that was done, I spent a few days in mid-May correcting errors in the highlighting and learning a little about how the chip works. Just like the Wipeout chip had a post detailing some of it's internal workings after it was simulated, the same will be done for the AY-3-8605. Its circuitry is somewhat different from the two chips covered so far because it's not a moving ball based game.
So when will it actually be playable? As said before, the AY-3-8500 is pioneering the die photo -> netlist -> emulation process. Most of the work needed to turn the JavaScript simulations into playable FPGA cores has already been done, however because of shortcuts and edge cases the '06 and '05 netlists can't run through DLAET fully yet. I've already spent a few days working on this issue and will work on it more now that the AY-3-8500 has reached the playable stage.

Even more chips

What else is on the journey to emulation? Only three more game chips have been photographed but not highlighted: the AY-3-8600 (improved AY-3-8500), the MM57105 (a competitor pong chip), and the MPS7600 (responsible for these games.) The MPS7600 and SP0256 sound chip are comparatively quite complex, so I want to gain experience and improve debugging tools on the less complex chips first. And since the only chips I've done so far were made by General Instruments, I decided that the MM57105 will be the next target for highlighting. I haven't had time to start highlighting due to my summer schedule, but I'll pick it up again sometime soon. Also, as I've said before, highlighting isn't a difficult process and you can contribute if you want to help.
The MM57105's surface

Other chips are on the way to be decapped and photographed soon. David Viens has collected a few more specimens to be sent to the acid bath. The ICs he has acquired are the AY-3-8603 (a vertically scrolling racing game), the AY-3-8607 (several games to be played with a light gun), the AY-3-8610 (slightly more features than the AY-3-8600), and the AY-3-8765 (a one-chip implementation of Atari's stunt cycle arcade game.

That's plenty of new chips already, but thanks to donations from some of my readers, I purchased some vintage 1st generation game systems online. These systems will be gutted to remove the custom chips for decapping. Another very important thing that can be done is document the PCBs to figure out the pinouts, as many game chips did not have public documentation like the AY-3-XXXX ones do. I'll also get some good pictures of the internals/externals as well as play footage if none exists so far. Last thing I plan to do before removing the chips is figure out how to composite mod them, useful information for anyone wanting to improve video quality on their own systems.

So far I've acquired four different systems. First is Atari's video pinball dedicated system. You may have heard of video pinball for the 2600, but you may not know that they made a system (and thus a chip) hardwired to play electronic pinball as well as Breakout and a basketball game. In many ways the dedicated version is better than the 2600 version. Sometime I'll make a blog post showing the internals, as well as how to composite mod it (composite mod has been completed.)

Such detailed graphics! (for 1977)

Next up are the Coleco Telstar Combat! and Phillips Odyssey 2100. Combat! uses the AY-3-8700 to play two tank battle games, like Atari/Kee's Tank arcades or the 2600 Combat cartridge. Matches were between two players or against a simple "robot" mode. The Odyssey 2100 used the MM57186 chip to play a few color games based on the ball & paddle concept. Actually I didn't get the Odyssey, I got a sample of the chip by itself (the chip wasn't exclusive to the Odyssey.)

A PNG of the CTVG's PCB (say that three times fast), showing the M58816P custom chip
The purchase I'm most excited about wasn't sold here in the USA, despite it's maker later selling tens of millions of other videogame consoles worldwide. It's the Color TV game 15, Nintendo's first console! Technically the TV game 6 (probably) came out before it, however they used the same custom game chip so emulating one will emulate the other. Despite holding such historical significance, no attempts at emulation have been made (other than a very inaccurate re-creation.) Time to change that. First though, I want to try out a guess I have on how to composite mod it.

A highly inaccurate re-creation of the Color TV game made by Nintendo
Hopefully good die photos will show up after these chips are shipped off. I say hopefully because, surprising as it may seem, dissolving microscopic circuits in boiling acids is not a completely predictable process. There's a decent chance that something will prevent usable images from being obtained. You can see an example a few paragraphs back; a bit of the MM57105 has broken off in the lower-right of the die (this isn't severe enough to require new photos though.)

I took several pictures already of the consoles, all of the good ones have been dumped here. They're all public domain, so use them for whatever you want (provided it's not illegal.) I'm not a professional, but I tried to get some good-looking shots.

Wrap Up

This project took a lot of time and work, so it's good to see playable results from it. This project wasn't me alone though. I want to thank Sean Riddle for decapping and photographing the AY-3-8500, David Viens for sending the other game chips his way, and the people who gave me money to acquire even more specimens. Also thanks to Greg Davill and Adam Courchesne for answering some verilog-related questions.

Lastly, thanks to the people who organized Latch-Up. For those who don't know, Latch-Up is a open source hardware conference that ran for the first time in May. I gave a talk on this project, met new people, and learned a lot. Hopefully next year will be even better!

There are a lot of different things to work on. I'll keep you all updated on what's happening on this blog, so be sure to check it every once and a while. You can also follow me on Twitter for smaller updates and pictures of progress. Now that one chip has been converted into a FPGA, the rest of 2019 is sure to bring some great things!