Paddle 1:
Paddle 2:
Recording

The position of the ball is controlled by a series of counters. There are two 4-bit counters and a JK flip flop, which act as a 9-bit counter that keeps track of the horizontal position. The phase of the counter determines the horizontal position of the ball. The counter only counts when HBLANK is low, and counts at the same rate as the main horizontal counter. When it reaches 508, that is the left side of the ball; HVID is brought low. When it reaches 511, that is the right side. After that, it normally gets reloaded with the value 138. So it counts 512-138=374 times and then resets. That is equal to the number of rising edges of the clock when HBLANK is low. At the end of every line, during the horizontal blanking interval, the counter will have the same value.

To move the ball horizontally, we load a value other than 138 into the counter. The "Horizontal Ball Control" portion of the circuit takes care of this at the end of every frame.

There are 2 more 4-bit counters, acting as a 8-bit counter, that keep track of the vertical position of the ball. This counter counts horizontal lines (positive transitions of HSYNC) and only counts when VBLANK is low. It resets after it hits 255. When the counter has a value 252 or greater, that means the ball is located on the current horizontal scanline (VVID is high).

There are 246 visible lines on the screen, so if we want the vertical ball counter to have the same value each frame, we should load it with 10 when it resets. But when the simulation starts, the load inputs are equal to 7. So, at the end of every frame the counter's value will be 3 less (which you can verify by reducing the simulation speed). This will make the ball move down by 3 pixels each frame. When the ball hits the bottom of the screen, then the counter gets loaded with 13, which makes the ball move up by 3 pixels each frame. The "Vertical Ball Control" portion of the circuit takes care of this.

Since the simulation is so slow, you can click on the screen to reposition the ball.

At the top of the screen, in the circuit that generates HBLANK, there is a buffer which introduces a small delay. This is not there in the original circuit, but is needed to emulate some delays in the real counters and gates. If we didn't do this, then the horizontal ball counter would be out of sync with the main counter. See Edwards 1.4.

In this example, the vertical ball counters have a CLR V input (instead of +5V like the original circuit) in order to implement the ball repositioning.

Next: Horizontal Ball Control.

Index