The Addams Family Teaches Itself One Shot
Roll the ball through the far left inlane on The Addams Family and the display says "SHOOT RAMP FOR THING FLIPS". Make the center ramp and the ball does not come back to you. It drops onto the little flipper on the upper left, and that flipper fires on its own, with Thing taking the shot at the swamp.
The operator's manual makes a bold claim for this feature. It says the game learns the shot: the slope of the machine, the dirt on the playfield, the strength of the flipper. It promises the game will make it more than half the time once it has learned, and that it keeps adjusting as things change.
That is a lot to ask of a 1992 pinball machine with an 8-bit processor. This article opens the original program and follows Thing through one shot, then through the learning.
A clock that ticks every millisecond
Just above the upper left flipper is an opto: a small light beam across the ball's path, with a sensor on the other side. When a ball rolls through, it blocks the beam for a moment. A fast ball blocks it briefly, a slow ball for longer.
The game's main program cannot watch that beam closely enough. It looks at switches in its own time, and a ball crosses the beam in a few hundredths of a second. So Thing Flips is not run by the main program at all. It is run from the processor's interrupt, a small routine the hardware triggers about 976 times a second (in the emulator), which the code uses as a clock. Each tick, Thing Flips reads the opto directly from the switch hardware:
LDA #$10 ; pick the column of switches the opto is on
STA $3FEA
INC <$DC ; the ball is still in the beam: one more tick
LDA $3FE9 ; read that column
ANDA #$40 ; is the opto's beam whole again?
It waits for three clear readings in a row, so one flicker does not end the count. The number of ticks is the game's measure of how fast this ball is moving.
Choosing the moment
Now the game has to decide when to flip. It keeps three numbers in a part of its memory it guards against stray writes: an average beam time, a base delay, and a scaler. (The manual says what the game learns stays with it, even through a move to a new location.) From them it works out a delay for this ball:
- start from the base delay,
- add how much longer than average this ball was in the beam,
- but scaled down: multiplied by the scaler, which is counted in 256ths.
On a machine fresh from the factory those numbers are 160 ticks for the base delay and 197 for the scaler, so each extra tick a ball spends in the beam adds about three quarters of a tick of delay. A slow ball gets a later flip.
When the countdown ends, the game does not drive the flipper coil itself. It presses the upper left flipper button, as far as the flipper code is concerned. The Fliptronics flipper code has a back door for this: two bytes in memory that let the game hold any flipper button down. Thing holds the upper left one for 75 ticks and lets go.
Learning the shot
After the flip, the game waits a few seconds to see where the ball went. There are four places it can learn from: the swamp itself (the switch inside the swamp hole), and three targets beside it, upper, center and lower. A ball that hits the upper target was flipped too early; the center and lower targets mean too late, the lower one by more.
What the game does with that depends on how well it knows the machine.
First, it only watches. On a fresh machine there is no average yet. The first four center ramp shots are diverted and timed, but Thing does not flip. The fourth sets the average. Shots up the side ramp are always just timed, never flipped, which is why the manual's setup procedure starts with four side ramp throws.
Then it searches. The first real flips use 160 ticks, adjusted for the ball's speed. An upper target hit adds 5 ticks; a center target takes off 4; a lower target takes off 10. Two flips in a row that touch nothing move to the next delay in a fixed list that works outward from the middle: 150, 170, 140, 180, and so on out to 110 and 200.
The first ball into the swamp ends the search. That delay is now the base.
Then it fine tunes. From here on the game keeps tallies: hits, early shots and late shots. Balls close to the average speed count towards the base delay; balls clearly faster or slower count towards the scaler, which is what decides how much the speed matters. After a handful of shots it nudges the value towards whichever side it is missing on, the base delay by a single tick at a time, and it asks for more shots between nudges as it goes. That is the manual's "quickly in the ballpark, then slowly refines".
It also keeps measuring speed. Every timed ball goes into the average, first in groups of four, later in groups of 8, 16 and 32. When the average shifts, the base delay is shifted to match, so a ball of a given speed keeps the same delay.
And it knows when it is lost. Six flips in a row that touch nothing at all, and the game throws away its base delay and starts the search again from 160.
Thing learns a pretend ball
The original program was run under a test script, and since an emulator has no playfield and no ball, the script played the part. It started a game, rolled through the inlane, made the center ramp, and held the opto beam broken for somewhere between 12 and 29 milliseconds. When the game flipped, the script decided where the ball went using an invented rule: the shot scores if the flip comes within 8 milliseconds of a "right" moment that depends on the ball's speed, and hits a swamp target if it is a little early or late. The rule is invented. The point is to watch what the game does with the results, not to model a real flipper.
Starting from the factory settings:
| Shots | What the game did | What it learned |
|---|---|---|
| 1-4 | Diverted and timed the ball, no flip | average beam time 21 ticks |
| 5-7 | Flipped early each time; upper target | base delay 160, then 165, 170, 175 |
| 8 | Swamp | search over, base delay 176 |
| 9-30 | 19 of 22 into the swamp | base delay settled at 178 |
The arithmetic matched to the tick. A ball that spent 29 ticks in the beam, with an average of 20, a base of 160 and the scaler at 197, should get 160 + 9 x 197/256, which is 166.9; the game chose 167.
When Thing misses
For an owner, the useful part is what the code does when something on the playfield is not working. The manual lists the switches the calibration relies on. Faking each failure in the test shows what it looks like.
| Fault | What the game does |
|---|---|
| Opto 57 reads blocked all the time | drops Thing Flips the moment it arms, so the flipper never moves |
| Opto 57 never sees the ball | waits about four seconds, gives up, learns nothing |
| Swamp switch 71 dead | never knows it scored, so it never stops searching; its aim jumps between 110 and 200 ticks every couple of shots |
That last one is the sneaky one. With the swamp switch dead, every good shot looks like a miss, and Thing Flips does not stop working. It just looks erratic, sometimes perfect and then wildly off, because the game keeps moving on through its search list.
After fixing a switch, the manual's New Location utility (U.12) wipes what was learned and starts over. The code has the routine that does it; it was not run from the menu in these tests.
Credits and further reading
- Midway Manufacturing Company, The Addams Family Operations Manual (January 1992, 16-20017-101): the Thing Flips rules (page D), "Thing Flips Automatic Calibration" (page B), New Location (page 1-27), and the switch and solenoid tables (pages 2-39 and 3-6).
- The MAME team, the WPC Fliptronics driver
wpc_flip1.cppand its WPC support code at MAME 0.289, for the machine's memory map, clock and switch inputs. - The full notes behind this article, with addresses, the learning tables and the script used: Thing Flips in the Addams Family case study.