Friday, September 14, 2018

Games and Field Generation in the AY-3-8500

The AY-3-8500 system on a chip powered millions of PONG clone consoles made during the later 1970s. It's internal circuitry is made up of over 2000 transistors, all on an area smaller than a fingernail. A few days ago I reverse-engineered the game select and field generation logic, and found a few interesting things to share. Lets have a look inside this antique circuit.

To recap, the AY-3-8500 was first made by General Instruments (now defunct) in 1975 to allow anyone to make a cheap PONG clone console. The chip has no ROM or micro-controller, it contains specialized circuitry that allows it to play five variants of PONG at multiple difficulty levels. In 2017 Sean Riddle decapped a specimen with acid and photographed the interior. Over this year, I built an online simulation of it based on the work of the Visual6502 team, which I released about a month ago. Now I'm analyzing the components to figure out what makes this thing tick.

The Telstar Ranger, a standard system made with the chip. Image used with permission from PONGstory

Above is a quick video showing all the games (except Handicap) running on an original console called the Telstar Ranger. Coleco's Telstar series of 1st generation consoles made use of high-integration game chips in its many incarnations. In the console, selecting different games changes the internal logic, turning game field elements on or off to create a (then) realistic play field. We'll be looking at just how this process is carried out. If you want to, you can follow along in the simulation. I've updated it since my last post.1

Games on the System

As the chip has no ROM, different games are achieved by turning parts of the circuitry on and off, according to the game select logic. All video games systems prior to Fairchild's channel F had "canned" specialized circuitry and sometimes interchangeable cartridges containing additional circuitry. The AY-3-8500's design allows it to play five variants of PONG-like games; plus two light-gun shooting games. The light-gun games were only possible with a gun peripheral and supporting circuitry. In addition to the games, there were three difficulty switches which could change the paddle size, along with the ball speed and rebound angle. Many consoles made with the chip didn't support all the available games or difficulty settings, possibly to force consumers to buy multiple systems.

The datasheet describes six of the games. First game on the system is Tennis, which is a standard two-paddle game of PONG. Soccer, which features a narrower goal and forward paddles. That's american soccer which most of the world would call football. The manuals I found refer to it as Soccer, so I'll use I'll call it that from now on. Its also been referred to as "Hockey", on some consoles. Next up is Handicap, an undocumented form of Soccer where the right player has another defensive paddle. Squash, (sometimes called Ali-je) where players take turns bouncing the ball against a wall, and last of the ball games; practice, a one-player variant of Squash. Rifle game 1 involves a shooting target bouncing around the screen, each hit and miss is counted. Rifle game 2 is similar, but the ball/target travels from left to right and must be shot before leaving the screen.

List of system game variants (Pong Story)
Each game has a pin dedicated to it, which, when connected to ground, selects the game.2 The hidden Handicap mode is triggered when no games are selected. Most consoles built with the chip used a slider or rotating switch to select which game is played. I wondered what would happen if you selected multiple games at once. Lets look inside to find out!

Selection Logic

Game select pads (blue) and
score/field output (red)

The six game select pins are connected to six pads in the lower left corner of the chip's die. If you're following along with the simulation, you can use the game select check-boxes on the control panel to turn the pins on or off. The pins are active-low, so they will become dark/grounded when activated. The pads have thin traces connecting them to game select logic. These traces go pass a special transistor (green) called a ggNMOS to protect the circuits from ESD.

The game select logic is in the lower left corner. In the center is a simple binary decoder fed with inverted (active high) game select signals as inputs. By default, the "tennis" wire should be lit up (this is not pinTennis) Seven control signals leave the decoder and travel upward. A transistor connecting a game select and control line will activate that control line.

Output signals from left to right; disableGoalPaddles, leftWallDisable, disableP2Forward (which also disables the goal walls), isRifleGame, disableP1Squash, disableP2Squash, and lastly closedGoals. The names are pretty self explanatory, these signals serve to disable internal circuit's based on the selected games. The Practice, Squash, and Rifle2 game signals also directly disable some components. For example, the "practice" signal alone grounds the 5th horizontal control signal, which normally would trigger the drawing of player 2's score. If your wondering how the horizontal and vertical signals are generated you can read my last post.

Game combinations

A generated frame of Handicap

The simulation allows us to see exactly what happens when we trigger a combination of pins. Since all the control signals act as inhibitors, not activating any game results in a game with every element except the full left wall. This is the undocumented "handicap" game. Player 2's extra defensive paddle is his/her own squash paddle, no longer disabled by an active soccer pin.

Squash directly activates a total of six transistors in various parts of the chip, for currently unknown reasons. Whatever effect this has on the game, you can experience in single-player mode by also triggering Practice. If you activate Squash or Practice along with Tennis, the game will "play" with no paddles or vertical lines.

Most combinations with soccer activated play regular soccer as the internal soccer signal forces the all the other internal signals off. There are three exceptions to this which are generated by a pair of AND gates to the left of the decoder (see picture above.) If soccer and squash are activated, the bottom AND gate activates the disable node, which freezes much of the chip's circuitry in place. This may function as a (no display) pause feature. Two things about this combination puzzle me, some (ball related?) circuitry still advances when this combination is activated. Also, in the manual's sample schematic, diodes connect these two pins to the reset pin, which means this "game" should trigger when a reset button is pressed for some reason.
Two diodes connecting squash and soccer games to reset

The top AND gate creates unique behavior for a soccer-practice combination, the aptly named soccerPractice node activates two transistors here in the ball circuitry while playing a regular two-player soccer game. I haven't analyzed the ball circuitry yet, so what exactly this does will remain a mystery for now.

The last game combination is Rifle2 and Soccer, which, once again plays a variant of soccer. The "r2andSoccer" node will ground the Tennis and Rifle1 input pins during certain parts of the screen drawing. This may seem pointless, but the AY-3-8500 (game logic) and AY-3-8515 (color adder) chips share game select inputs.3 If connected to color circuits, the color palette may change mid-screen, as seen on this trace below.

Yellow = Rifle1 grounded. Green = Tennis grounded. Blue = both grounded.
Every other line has been made normal for viewing purposes

Play field generation

The video signal of the AY-3-8500 comes out of five different pins. Each pin is dedicated to drawing a portion of the game (Score/Field, Left Player, Right Player, Ball, and Sync.) This allows each to be assigned a different brightness value with a resistor, or a color with a support chip. The score/field out pin receives it's signal from four internal circuits, the score-drawing, side-lines, the middle line, and goal wall circuits. Each component has been given a different color in the output below. Notice that the play-field is not symmetrical (look closely at the corners) due to the exact timing of the control signals.

Below is a schematic I made of the field generation circuitry. It may seem a little confusing as almost every gate has an inverted output (this is the nature of MOS.) Lets work our way in from the output pin. The schematic has a lot of NOR gates, because multiple input NOR gates are very easy to implement in MOS logic. In NMOS chips, NOR gates are achieved by having a pullup transistor which defaults the output to high, and any number of input transistors which may ground it. The majority of the NOR gates actually function as AND gates with inverted inputs. If every input of a NOR is low, then the gate outputs a logical 1. The circuitry is constructed NOR (yellow inputs) -> inverted AND (grey inputs) -> NOR -> inverted AND, so few additional inverter gates are necessary.

We can find the output pad in the lower right of the chip and the diagram. A large "J" shaped transistor inverts and drives the output. This driver transistor connects to a pair of large transistors over to the left. The lower of these two transistors connects to the score generation. The score circuitry is complex (it takes up about 1/8th of the die surface) and will be covered in its own post. For now we'll focus on the top transistor, which connects to the play-field circuits. The isRifleGame signal grounds the node powering this transistor, preventing the field from being drawn during rifle games. Importantly though, the walls and sidelines still exist. They're just invisible, and they control the target's behavior during the rifle games.

NOR SR latch
The sidelines, middle line, and goal wall circuits converge on a single NOR gate above here. Off to the right (in both the chip and diagram) is the sideline generation circuitry. The sidelines are simple, two dotted lines at the top and bottom of the screen. Vertical control signals 4 OR 9 must be active to enable drawing, and the "halfClock" signal must also be, which causes the lines to be dotted instead of solid. Lastly, a SR latch prevents the sidelines from being drawn, unless the electron gun is inside the play-field.

This SR latch is shown on the right,
in a powered state. This latch is a bistable flip-flop, meaning it has two stable states. Hrz. control 4 (left of play-field) sets the latch into a set state. Hrz. control 9 (right of play-field) resets the latch. One fundemental problem with a basic SR-latch is that if set and reset are triggered at the same time, the flip-flop will enter a random state. A basic SR latch is fine here, as the two control signals should never activate at the same time. The end result of these circuits? Two dotted horizontal lines at locations specified by the control signals.

Middle and Goal walls

The middle wall output is based on three conditions. First, horizontal control signal 6 (middle wall) must be present to draw the middle wall. Next, the middle wall will be disabled if the "disableGoalPaddles" signal is triggered by a game of squash or practice. The last bit of circuitry limits it's height to that of the play-field. Another SR flip-flop, (controlled by vertical signals 3 & 9) restricts it to between the two sidelines. This is important, as drawing anything for the entire height of the screen would interfere with the vertical sync signals, possibly making the video output unwatchable.

Last up are the goal walls. As seen in the video and pictures above, both walls are partially closed during a soccer or practice game, making it harder to score (the forward paddles balance this out.) The left wall is fully closed during squash or practice, while the right wall is entirely open.

For the walls to display, the electron gun has to be in the correct vertical range just like the middle wall (it shares this circuit.) To dot the walls, the everyOtherScanline signal is factored in (this signal is already generated by the vertical circuitry.) However the screen is drawn twice due to interlacing, because of this, every other pair of scanlines is drawn.

From here the two walls are generated by separate gates, each with their own inputs. The insideGoal signal must be off for either of these to draw. This is set and reset by vertical signals 6 & 5, goal start and goal end respectively. The closedGoal game control signal disables vertical signal 6, preventing the goals from ever starting. Each wall will be drawn in full, unless one of them is disabled (as in Squash and Practice.) The inside goal tracking flip-flop happens to always start in the state inside the simulation, causing the first field to be shaped in an anchor pattern. All of the field generation flip-flops are not reset by the reset signal, which means the first field after a reset may be drawn incorrectly.
Rifle game 1 ball trap

To detect a collision off of the sidelines, the ball circuitry uses the direct signal from vertical control 3 & 9, as the sidelines are always present. There is no circuitry to detect a middle wall collision, as the ball can never collide with the middle wall. The goal walls have multiple possible configurations, so their output also feeds into the collision circuitry (as indicated by the arrows in the schematic), even when the play-field is hidden during a rifle game. An interesting thing I found is that the right wall is closed during the 1st rifle game to trap the target inside, as seen trace of the fieldOut signal. In rifle game 2, the walls are open, allowing the ball to "escape" after about a second.

Wrap Up

Using the horizontal + vertical control signals and game inputs, the AY-8500 uses binary logic to decide when/where to draw the play-field. The game select logic revealed possible additional game variants, which might be playable on real hardware. Next time I plan to write about the score circuitry, which  is fairly large and takes up about 1/8th of the chip's surface.

Feel free to leave any questions or comments below. If your here from the RetroChallenge (9/2018) you can check out the other participant's projects here. If your not, why not check them out anyway?


1. The simulation has a few new features since the original upload. It will now display the paddles (green and blue) at the scanline set by the two text fields next to the score input. You can also toggle the four setting pins as well. I've labeled over 100 nodes while reverse-engineering this, and the node names file has been updated. Oh and one or two bugs have been squashed, which probably created a dozen more ;/

2. While doing a little research I found a few references to a Russian (Soviet) clone of the AY-3-8500 called the K145IK17. It apparently had an internal counter and de-bounce circuit so a single button could rotate through all (7) games. Not much about this, or most Soviet gaming systems for that matter, is documented online. The AY-3-8500 was also cloned into the TMS1965NLA by the guys on the opposite side of the world

3. While grounding the Tennis select pin may change the game's colors, the AY-3-8515 color chip does not use Rifle1's signal, which appears to only change outside of the visible screen. Also, Tennis signal is not grounded (green) during the right goal walls. There may be a small delay in the color chip which compensates for this. 

1 comment:

  1. Hi Cole, excellent work :) Regarding - "Squash directly activates a total of six transistors in various parts of the chip, for currently unknown reasons". When playing squash player 1 (left side) makes use of their soccer forward paddle. I wonder if part of what the transistors do is to switch the bounce mechanics for the player 1 paddle so that the ball does not pass through it when moving from left to right as it would when playing soccer. A change like this would not be required for player 2's (right side) dedicated squash paddle. As a consequence, it would also not be required for Practice as player 1 is not used at all.