This program generates a continuous starfield scrolling effect by filling a 32-character string with inverse space characters (CHR$ 128) and then printing a randomly positioned star character (CHR$ 155) on the bottom line. The SLOW command engages the ZX81’s SLOW mode, which allows the display driver to run simultaneously with the program, enabling smooth screen output. Each iteration uses SCROLL to move the display up one line, then PRINT with AT to place a new star at a random column position on row 21. The RND*31 expression produces a random column from 0 to 30, giving a non-uniform star distribution across the width of the screen.
Program Analysis
Program Structure
The program is compact, consisting of an initialisation phase (lines 10–50) and a continuous display loop (lines 60–80). Line 5 contains a REM statement spelling “SPACESCAP” in inverse video, serving as a program title. The main loop never terminates; GOTO 60 causes indefinite repetition.
- Lines 10–50: Initialisation — dimensions a 32-character string
S$and fills every position withCHR$ 128(inverse space), forming a solid black line. - Line 60: Scrolls the entire display up by one character row.
- Line 70: Prints the filled string
S$(effectively a blank/inverse line), then overlays a star character (CHR$ 155) at a random column on row 21. - Line 80: Loops back to
SCROLL, creating the animation.
Key BASIC Idioms and Techniques
- CHR$ 128 — Inverse space on the ZX81, producing a filled black cell. Filling
S$with this character creates a solid background line against which the star stands out. - CHR$ 155 — A block graphic character used as the “star” pixel. Its exact appearance depends on the character set, but it renders as a bright spot distinct from the inverse-space background.
- SLOW mode (line 20) — Activates the ZX81’s SLOW display mode, which interleaves CPU execution with display refresh. This prevents the screen from blanking during computation and gives smoother visual output.
- PRINT S$;AT 21,RND*31;CHR$ 155 — A single PRINT statement combining the background string and star placement. The semicolon suppresses the newline after
S$, andATrepositions the cursor mid-statement for efficient star rendering.
Star Distribution
RND*31 produces a value in the range [0, 31), so column 31 (the rightmost) is never selected. This means stars are distributed across columns 0–30 only, leaving the rightmost column perpetually empty. This is a minor cosmetic anomaly rather than a functional bug.
Notable Observations
- The 32-character
DIM S$(32)matches the ZX81’s 32-column display width exactly, ensuring the inverse-space line spans the full row. - Because
S$is printed first and then the star is placed withAT, the bottom line always shows exactly one star per scroll cycle, giving a sparse but consistent starfield density. - There is no frame-rate control; animation speed depends entirely on SLOW mode timing and the speed of BASIC interpretation.
Line Reference Table
| Line | Purpose |
|---|---|
5 | REM title “SPACESCAP” in inverse video |
10 | Dimension 32-character string S$ |
20 | Enable SLOW display mode |
30–50 | Fill S$ with inverse-space characters |
60 | Scroll display up one row |
70 | Print background line and random star |
80 | Loop back to line 60 |
Content
Source Code
5 REM %S%P%A%C%E%S%C%A%P%E
10 DIM S$(32)
20 SLOW
30 FOR N=1 TO 32
40 LET S$(N)=CHR$ 128
50 NEXT N
60 SCROLL
70 PRINT S$;AT 21,RND*31;CHR$ 155
80 GOTO 60
100 SAVE "1006%6"
110 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
