--- title: "Space Scape" id: 57117 type: "computer_media" slug: "space-scape" url: "http://localhost/computer_media/space-scape/" markdown_url: "http://localhost/computer_media/space-scape.md" published_at: "2024-10-03T23:47:14+00:00" modified_at: "2026-03-30T21:19:50+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/66_Space.png" excerpt: "A minimalist scrolling starfield demo uses a clever string-fill trick and random character placement to simulate the illusion of flying through space." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_contents: - id: 56733 title: "Timex Sinclair Public Domain Library Tape 1002" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1002/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/66_Space.png" media_type_tags: "Demo" --- # Space Scape 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. 1. **Lines 10–50:** Initialisation — dimensions a 32-character string `S$` and fills every position with `CHR$ 128` (inverse space), forming a solid black line. 2. **Line 60:** Scrolls the entire display up by one character row. 3. **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. 4. **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$`, and `AT` repositions 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 with `AT`, 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 | ## 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 ```