--- title: "Microworld" id: 57333 type: "computer_media" slug: "microworld" url: "http://localhost/computer_media/microworld/" markdown_url: "http://localhost/computer_media/microworld.md" published_at: "2024-10-04T08:22:10+00:00" modified_at: "2026-03-30T21:18:32+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/09/181_MW.png" excerpt: "A procedurally generated pixel landscape with a scrolling animated header and a customisable inverse-video title — all in a compact BASIC program." 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: 56735 title: "Timex Sinclair Public Domain Library Tape 1004" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1004/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/09/181_MW.png" media_type_tags: "Demo" --- # Microworld This program generates a randomly seeded landscape of vertical bar-chart columns across the screen, then overlays a scrolling animated border and a title in inverse video. The landscape is drawn in FAST mode using PLOT to render columns of pixels, with each column reaching a random height between 1 and 41 pixels. The title string T$ (defaulting to “MICROWORLD”) is printed in inverse video by adding 128 to each character code, centred on line 21. The scrolling effect is created by repeatedly printing a four-character string S$ (built from CHR$ 0, 9, 8, 9) across row 0 in an infinite loop, producing a moving pattern of ZX81 block-graphic characters. *** ## Program Analysis ### Program Structure The program divides into four logical phases: 1. **Initialisation (lines 10–50):** Dimensions a three-character string `E$`, builds the scrolling pattern string `S$`, and sets the title `T$`. 2. **Landscape generation (lines 60–130):** Runs in `FAST` mode, iterating over 61 columns (M = 0 to 60) and plotting a random-height column of pixels in each. 3. **Title and border setup (lines 140–210):** Prints the title in inverse video on row 21, then enters the scroll loop for row 0. 4. **Scrolling loop (lines 180–220):** An infinite `GOTO` loop that sweeps `S$` across positions 0–28 of row 0, creating a marquee-like animation. ### Landscape Generation The outer loop (`M = 0 TO 60`) steps through horizontal pixel columns. For each column, the inner loop plots from pixel row 0 up to `INT(RND*40)+1`, giving a random height of 1–41 pixels. Using `FAST` mode suppresses the display driver during drawing, dramatically speeding up the `PLOT` calls. The `RAND` at line 70 (no argument) seeds the random number generator from the system clock, so each run produces a different landscape. ### Inverse-Video Title The ZX81 encodes inverse characters as the normal character code plus 128. Lines 150–170 loop over each character of `T$`, printing `CHR$(CODE T$(N)+128)` to produce each letter in inverse video. The `AT 21, 15-(LEN T$/2)` at line 140 attempts to horizontally centre the title; because `LEN T$/2` uses integer division the centering is approximate, and for a 10-character title like “MICROWORLD” it evaluates to column 10 — one cell left of true centre on a 32-column display. ### Scrolling Header The string `S$` is assembled as `CHR$ 0 + CHR$ 9 + CHR$ 8 + CHR$ 9`. On the ZX81, character codes 0–10 are space and graphic block characters; this four-character sequence forms a small animated pattern. Printing it at successive columns 0–28 of row 0 in a tight `FOR/NEXT`/`GOTO` loop creates a leftward-sweeping marquee. `E$` (three spaces, from `DIM E$(3)`) is printed at column 29 to clear the tail end of row 0 each cycle. ### Key Variables | Variable | Purpose | | --- | --- | | `T$` | Customisable title string, printed in inverse video | | `S$` | Four-char graphic pattern used for the scrolling header | | `E$` | Three-space string used to blank the trailing characters of row 0 | | `M` | Horizontal pixel column counter (0–60) for landscape drawing | | `N` | Reused: pixel row counter during plotting; character index during title print; scroll position during animation | ### Notable Techniques and Observations - Reusing loop variable `N` for three distinct purposes (plotting height, title character index, scroll position) is a common ZX81 memory-saving idiom. - The landscape is drawn with `PLOT` rather than character-cell graphics, giving pixel-level resolution on the 64×44 pixel grid. - The title is user-customisable via the `REM`-documented `T$` assignment at line 50, a common convention for configurable BASIC programs of this era. - The scroll loop has no exit condition; the program runs indefinitely until interrupted by the user. - The centering formula `15-(LEN T$/2)` performs integer division, so for odd-length titles the result is biased one column to the right. ## Source Code ``` 10 DIM E$(3) 20 LET S$=CHR$ 0+CHR$ 9+CHR$ 8+CHR$ 9 30 REM T$ IS THE TITLE. 40 REM IT CAN BE CHANGED. 50 LET T$="MICROWORLD" 60 FAST 70 RAND 80 FOR M=0 TO 60 90 FOR N=0 TO INT (RND*40)+1 100 PLOT M,N 110 NEXT N 120 NEXT M 130 SLOW 140 PRINT AT 21,15-(LEN T$/2); 150 FOR N=1 TO LEN T$ 160 PRINT CHR$ (CODE T$(N)+128); 170 NEXT N 180 FOR N=1 TO 28 190 PRINT AT 0,N;S$ 200 NEXT N 210 PRINT AT 0,29;E$ 220 GOTO 180 230 SAVE "1018%1" 240 RUN ```