This program implements a simple bat-and-ball game on the ZX81/TS1000, where a ball bounces horizontally across the screen and the player controls a bat using keys. The ball’s position is tracked by column variable D, which reverses direction when it hits the screen edges (columns 7 and 17), while the bat is drawn at row A using inverse-video space characters for solid blocks. The SCROLL command at line 80 is used to erase the previous ball position before redrawing, a common ZX81 screen-update trick. Key codes 50 and 63 correspond to the ‘2’ and ‘/’ keys respectively, used for left/right bat movement. Line 140 uses RETURN to exit the game loop when no key is pressed, serving as a termination condition.
Program Analysis
Program Structure
The program is a short bat-and-ball game contained in a single loop from lines 60 to 150. Initialization occupies lines 10–50, and lines 160–180 handle save/restart. The main game loop redraws the ball, reads the keyboard, moves the bat, updates the ball’s horizontal position, and repeats.
Variable Roles
| Variable | Initial Value | Role |
|---|---|---|
K | 2 | Ball direction multiplier (+2 or −2) |
A | 10 | Bat row (fixed vertical position) |
B | 10 | Bat column (player-controlled) |
C | 20 (A+A) | Ball row (fixed at row 20) |
D | 6 | Ball column (moves each frame) |
Game Loop Mechanics
Each iteration of the loop (lines 60–150) performs the following steps in order:
- Draw the ball at row
C, columnD(line 60). - Erase the bat’s previous position by printing a space at row
A, columnB(line 70). SCROLLthe screen up one line (line 80), which also erases the top ball row indirectly.- Read the keyboard: key code 50 (‘2’) moves the bat right; key code 63 (‘/’) moves it left (lines 90–100).
- Redraw the bat at its new position (line 110).
- Bounce the ball if it reaches column boundaries (lines 120–130).
- Exit via
RETURNif no key is held (line 140), otherwise loop back (line 150).
Key BASIC Idioms and Techniques
- Inverse-video blocks: The
%sequences in PRINT statements render as solid inverse-video space characters, creating visible bat and ball sprites without UDGs or machine code. - Direction flip:
LET K=-Kat line 120 neatly reverses the ball’s horizontal direction by negating the step value between +2 and −2. - RND* *K: Line 130 uses
RND**K—RND*on the ZX81 gives a random integer, and multiplying byK(±2) adds a variable-speed horizontal step each frame. - RETURN as exit: Line 140 uses
RETURNwhen no key is pressed. Since the main loop is not called viaGOSUB, this will cause an error or jump to a calling context, effectively acting as a game-over or halt mechanism. - SCROLL for animation: The
SCROLLat line 80 shifts the entire display up, functioning as a crude erase for the ball row rather than blanking individual positions.
Bugs and Anomalies
- The bat movement keys are asymmetric: code 50 (‘2’) increases
B(moves right), while code 63 (‘/’) decreases it (moves left). On a standard keyboard layout this is non-intuitive; ‘5’ and ‘8’ would be more natural for left/right. - There is no collision detection between the bat (row 10) and the ball (row 20); the game has no win/lose condition based on interception.
- The bat column
Bis never clamped, so it can move off-screen without restriction. SCROLLunconditionally shifts the whole display each frame, causing the entire screen to scroll upward continuously, which distorts any persistent display elements.- Lines 160–180 (
CLEAR,SAVE,RUN) are unreachable from the main loop and appear to be leftover development/save boilerplate.
Content
Source Code
10 LET K=2
20 LET A=10
30 LET B=A
40 LET C=A+A
50 LET D=6
60 PRINT AT C,D;"% % % % % % "
70 PRINT AT A,B;"% "
80 SCROLL
90 IF CODE INKEY$=50 THEN LET B=B+1
100 IF CODE INKEY$=63 THEN LET B=B-1
110 PRINT AT A,B;"% "
120 IF D>17 OR D<7 THEN LET K=-K
130 LET D=D+RND**K
140 IF NOT CODE INKEY$ THEN RETURN
150 GOTO 60
160 CLEAR
170 SAVE "1032%3"
180 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
