← All articles

How Twilight Zone Spots the Powerball

Twilight Zone has a ball that is not like the others. Five of its six balls are ordinary steel. The sixth is the Powerball, made of white ceramic. When the machine kicks the Powerball into the shooter lane, the display lights up with "POWERBALL" and tells you where to shoot it, before you have even pulled the plunger.

The balls look alike to the machine. It has no camera and nothing that sees colour. So how does it know which one it just served? This article follows the answer through the original program, the 9.2 game ROM.

A metal detector in the trough

Drained balls collect in the trough under the bottom of the playfield and wait their turn. Each place in the trough has a switch that a resting ball holds down, and when a new ball is needed, a coil kicks the ball at the exit end over to the shooter lane.

Under that exit spot sits one more switch with no moving parts. The manual calls it a steel ball sensor, and the switch list calls it Trough Proximity, switch 26. It is a proximity sensor of the kind used to detect metal: a steel ball resting above it closes the switch, a ceramic ball does not. A second one, switch 57, sits by the slot machine kicker.

The trough exit and the proximity sensor under it Two side views of the trough exit. On the left a steel ball rests over the proximity sensor and switch 26 reads closed, meaning steel. On the right the ceramic Powerball rests in the same place and switch 26 stays open. Balls roll toward the exit, where the ball release coil kicks them to the shooter lane. Steel ball Powerball sensor (26) rolls toward the exit exit switch 26 closed a steel ball is about to be served sensor (26) exit switch 26 open ceramic is invisible to the sensor
The trough exit with the proximity sensor beneath it: a steel ball closes switch 26, the ceramic Powerball leaves it open.

So the basic test is simple. Just before the game fires the coil that serves a ball, it looks at switch 26. Closed means a steel ball is about to go out. Open means the ball at the exit is not steel, and the only ball that is not steel is the Powerball.

The code that asks this, in program page 18, is short:

JSR  $7D27         ; are Powerball rules on at all?
JSR  $83B6         ; has this switch worked within its last six balls?
FCB  $16           ;   which switch: 26, as the program numbers them
JSR  $8396         ; is this switch closed right now?
FCB  $16           ;   again switch 26
BCC  not_power     ; closed: steel
ANDCC #$FE         ; open, and the sensor is trusted: the Powerball

The byte after each call is an argument for it: the switch number, 26, written the way the program counts switches. The second line is where the interesting part starts.

An open switch proves nothing

A sensor that sees nothing has two explanations: there is nothing to see, or it is broken. A dead proximity sensor reads open all the time, exactly like a Powerball. If the game took every open reading at face value, a failed sensor would turn every ball into a Powerball.

The program guards against this in two ways.

It keeps a count. For every switch on the playfield, the game keeps a small number: how many more balls it will play before it decides that switch is broken. Every time the switch closes, its number is refilled from a table in the ROM. For switch 26 that refill value is 6. Every time a new ball starts, the number goes down by one for every switch at once. A switch that keeps working never gets near zero. One that stops closing runs out after six balls, and the second line of the code above says no: if the sensor has not closed in six balls, its silence means nothing, and no ball is called the Powerball.

It asks for proof. The game also remembers whether switch 26 has closed at all since the machine was switched on. If it has, the open reading is believed straight away. If it has not, the game serves the ball and then waits about a second. In that time, presumably, the next ball in the trough rolls down into the exit spot, and if it is steel, the sensor should close. If it does, the sensor works and the ball just served really was the Powerball. If it stays open, the game decides it served a steel ball after all.

How the game decides whether the ball it serves is the Powerball A flowchart. Just before serving, if Powerball rules are off the ball is treated as steel. If switch 26 has not closed in its last six balls it is not trusted and the ball is steel. If switch 26 is closed now the ball is steel. If it is open and the sensor has closed since switch-on, the ball is the Powerball. Otherwise the game serves the ball, waits about a second, and calls it the Powerball only if switch 26 closes in that time. About to serve a ball Powerball rules on? adjustment A.2 26 and others no yes Switch 26 closed in its last 6 balls? no yes Switch 26 open now? no yes Has switch 26 ever closed since switch-on? yes no Serve it, wait about a second: does switch 26 close meanwhile? yes no Steel no message POWERBALL on the display Steel Measured in MAME 0.289; first question read from ROM only.
How the game decides, just before a ball is served, whether it is the Powerball.

Serving pretend balls

The original program was run under a test script, and since the emulator has no balls and no playfield, the script stood in for them: it kept three balls in the trough, closed switch 26 whenever a steel ball sat at the exit, moved the exit ball to the shooter lane when the game fired the ball release coil, and put balls back through the outhole. The sound board ROMs were zero-filled stand-ins, so the game duly complains about its sound board. Breakpoints on the code above recorded each decision.

SetupWhat the game did
Powerball at the trough exit"POWERBALL" on the display before the plunge
Steel ball at the exitNothing
Three games, Powerball every third ballAnnounced on exactly those three serves out of nine
Sensor dead from switch-onNever announced, not even for the real Powerball: each time it waited a second, saw no proof, and settled on steel
Sensor working at switch-on, dead before the first gameThe next five balls, steel or not, were all announced as the Powerball. On the sixth the count reached zero and the announcements stopped
Sensor stuck closedNever announced. The count still ran out after six balls, because only a fresh closing refills it

The fifth row is the one a player could meet on a real machine: a sensor that fails during the day turns a handful of ordinary balls into "Powerballs" before the game catches on. After that the game simply stops playing the Powerball rules from the trough.

It also tells the operator. In the runs where the sensor died, opening the coin door and asking for the test report showed "CHECK SWITCH 26 / TROUGH PROXIMITY". After two games with a working sensor, it did not. (That the message comes from the same count is likely but was not traced in the code.)

What the operator can do

The manual has a setting for this, adjustment A.2 26 "No Powerball". It says that if the white ball is missing, or one of the two steel ball sensors is broken, the operator can swap the Powerball for a sixth steel ball and set the adjustment to YES, and the game will pretend that every second ball from the gumball machine is the Powerball. The code above checks an adjustment numbered 26 in its first step, which fits, though changing the setting was not tried.

For anyone fixing one of these machines, the program's behaviour gives a few clues:

  • "CHECK SWITCH 26" in the test report appeared every time the trough sensor stopped closing, so start there.
  • Ordinary balls being greeted with "POWERBALL" after the machine has been on for a while points the same way, before the test report catches it.
  • A Powerball that is never announced can mean the sensor is dead or stuck, or that the machine was switched on with the sensor already dead.

What is still open

The slot machine sensor, switch 57, gets the same kind of count, refilled to 12, but it is handled differently: at the start of every ball the game takes one off and gives it straight back, so in these tests it never went down. What the game decides from the slot sensor was not traced. The full detail, with addresses, is on the Powerball detection page of the case study.

Credits and further reading

  • The MAME project's WPC drivers by Olivier Galibert, Miodrag Milanovic and Barry Rodewald, for the memory map, the paged ROM and the switch inputs, read at version 0.289.
  • The Twilight Zone manual (Midway Manufacturing Company, April 1993) for the switch numbers, the ball count and adjustment A.2 26, and the Operators Handbook for the switch and coil lists.