Background

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Demo

This program generates randomized full-screen text-pattern backgrounds by repeating a short string until it floods the display. The subroutine at line 960 doubles a string variable six times (from length 11 to 704 characters) using a loop with `LET K$=K$+K$`, which is enough to fill the 32×22 Spectrum display when printed at AT 0,0. Each background is printed with randomly chosen INK color (1–6) and randomly toggled INVERSE attribute, producing varied visual effects. The demo sequence cycles through several block-graphic characters and then prompts the user to enter their own word or phrase to use as the tile pattern.


Program Analysis

Program Structure

The program is organized into a linear demo sequence followed by an interactive loop, with two shared subroutines:

  1. Lines 800–860: Initialization and animated title sequence — four text phrases are displayed one by one as tiled backgrounds.
  2. Lines 870–895: Five block-graphic characters are each used to generate a tiled background, demonstrating the visual variety possible.
  3. Lines 900–920: Interactive loop — the user presses any key, then types a word or phrase, which is used as the tile pattern. GO TO 900 returns to the prompt.
  4. Lines 930–950: Helper subroutine — builds an 11-character string from a single character A$ by appending it 10 times.
  5. Lines 960–990: Core tiling subroutine — doubles K$ six times, then prints it at AT 0,0 with random INK and INVERSE attributes.

Key Algorithm: String Doubling

The central technique is the string-doubling loop at lines 960–970:

FOR N=1 TO 6: LET K$=K$+K$: NEXT N

Starting with a string of length 11 (set up by the K$=" CREATE " style assignments or the helper subroutine), each iteration doubles the length: 11 → 22 → 44 → 88 → 176 → 352 → 704. The Spectrum display holds 32×22 = 704 characters, so after exactly six doublings an 11-character seed fills the screen precisely. This is an efficient O(log n) string construction strategy, requiring only 6 concatenation operations instead of 63.

Two-Stage Subroutine Chain

For the block-graphic demo (lines 870–895), a single character is stored in A$, then the subroutine at line 930 is called. This subroutine copies A$ into K$ and appends A$ ten more times, building the required 11-character seed before falling through directly into the tiling subroutine at line 960. This fall-through from line 930 into line 960 is intentional — the subroutine at 930 does not RETURN itself but relies on the RETURN at line 990 to unwind the single stack frame for both.

User Input Handling

The DIM X$(1,11) at line 800 allocates a one-element string array with a fixed length of 11 characters. INPUT X$(1) at line 915 reads the user’s text into this slot, which automatically pads with spaces or truncates to exactly 11 characters — neatly matching the seed length required by the doubling algorithm without any explicit padding code. The result is assigned directly to K$ before calling the tiling subroutine.

Display Attributes

Line 980 applies randomized display attributes:

  • INVERSE INT (RND*2) — randomly selects INVERSE 0 or INVERSE 1.
  • INK INT (RND*6)+1 — selects a random ink color from 1 to 6, avoiding black (0) to ensure visibility against the white PAPER 7 background.
  • AT 0,0 — positions the print cursor at the top-left so the entire 704-character string floods every cell of the display.

Block Graphics Usage

The demo sequence at lines 870–895 uses five of the Spectrum’s block graphic characters to illustrate pattern variety:

LineCharacterGlyph
870char 131 (▀)Top half block
880char 138 (▐)Right half block
885char 132 (▗)Bottom-right quadrant
890char 141 (▚)Diagonal blocks
895char 143 (▜)Top and right blocks

Notable Idioms

  • PAUSE 0 followed by LET A$=INKEY$ at line 905 is the standard efficient keypress-wait idiom.
  • RANDOMIZE at line 800 with no argument seeds the random number generator from the system clock, ensuring different color patterns on each run.
  • Line numbering uses gaps (810, 820, 840, 860) suggesting the program may be an excerpt from a larger listing where intervening lines were removed.

Potential Anomaly

In the interactive path, line 920 calls GO SUB 930 with K$ set to the user’s input from X$(1), but the subroutine at line 930 immediately overwrites K$ with A$ — which at that point still holds the last value set in the block-graphic demo or from line 905. This means the user’s entered text is actually passed via line 915’s LET K$=X$(1) and then line 920 calls GO SUB 960 (not 930), so the path is: line 920 calls 960 directly. Re-reading line 920: GO SUB 930: PRINT AT 10,8;... — actually line 920 is GO SUB 930: GO TO 900, meaning it does call 930 first, clobbering K$ with the old A$. This is a minor bug: the user’s typed word is set in K$ at line 915, but line 920 calls the subroutine at 930 which overwrites K$ before 960 ever sees the user’s input. The user’s text background therefore never actually appears; instead the last block-graphic pattern repeats.

Content

Appears On

Capital Area Timex Sinclair User Group’s Library Tape.

Related Products

Related Articles

Related Content

Image Gallery

Background

Source Code

  800 BORDER 7: PAPER 7: CLS : DIM X$(1,11): RANDOMIZE 
  810 LET K$=" CREATE    ": GO SUB 960: PAUSE 50
  820 LET K$="YOUR OWN   ": GO SUB 960: PAUSE 50
  840 LET K$="BACKGROUND ": GO SUB 960: PAUSE 50
  860 LET K$="FAST!!!    ": GO SUB 960: PAUSE 50
  870 LET A$="▀": GO SUB 930: PAUSE 50
  880 LET A$="▐": GO SUB 930: PAUSE 50
  885 LET A$="▗": GO SUB 930: PAUSE 50
  890 LET A$="▚": GO SUB 930: PAUSE 50
  895 LET A$="▜": GO SUB 930: PAUSE 50
  900 PRINT AT 10,8;" PRESS ANY KEY "
  905 PAUSE 0: LET A$=INKEY$
  910 GO SUB 930: PRINT AT 10,4;" KEY ANY WORD AND ENTER "
  915 INPUT X$(1): LET K$=X$(1)
  920 GO SUB 960: GO TO 900
  930 LET K$=A$
  940 FOR N=1 TO 10
  950 LET K$=K$+A$: NEXT N
  960 FOR N=1 TO 6
  970 LET K$=K$+K$: NEXT N
  980 PRINT INVERSE INT (RND*2); INK INT (RND*6)+1;AT 0,0;K$
  990 RETURN 
 9998 SAVE "BACKGROUND" LINE 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top