Skip to content
Game 1

Four choices on the screen

Build a labelled board from coloured character cells, then make one drawing routine serve four positions.

Bright Spark will show an order of lights and sounds for the player to repeat. First we need four choices that are easy to recognise. We’ll build their board from spaces, then give one drawing routine four jobs.

Use a 48K ZX Spectrum or Emu198x in its 48K configuration. Save any program you want to keep, then reset the Spectrum so we start with an empty program. The setup guide covers getting the emulator ready. These listings are Sinclair BASIC, entered on the Spectrum; no assembler or image editor is needed.

Enter each numbered line in BASIC. Reusing a line number replaces that line; entering only the number deletes it. The optional keyboard notes below are there if you need a reminder.

Keyboard notes

In Emu198x Host Keyboard mode, left Option/Alt is SYMBOL SHIFT. Enter extended mode with Shift+left Option/Alt, then release the keys before the next chord.

After a line number: B gives BORDER, V CLS, P PRINT, L LET, F FOR, N NEXT, H GO SUB and Y RETURN. At the prompt, R gives RUN.

Use left Option/Alt+I for AT, +F for TO and +A for STOP. In extended mode, left Option/Alt+C gives PAPER and +X gives INK.

For punctuation: left Option/Alt+4 gives $, +P a quote, +L =, and +O ;.

Colour a row of spaces

Enter this program. There are twelve spaces between the quotes on line 110.

10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 PAPER 2
110 PRINT AT 3,2;"            "
120 PAPER 0
130 PRINT AT 2,7;"1"
140 STOP

The first four lines choose a black border, black paper and white ink, then clear the display. The colour numbers we use are 0 black, 1 blue, 2 red, 4 green, 6 yellow and 7 white. PAPER selects the background of characters printed next; INK selects their foreground. A space has no visible foreground, but it still paints its background. Twelve printed spaces make a coloured strip.

AT selects a position: row first, column second. Row 3, column 2 is the fourth row and third column because counting starts at zero. Ordinary BASIC printing uses rows 0–21 and columns 0–31; the bottom two display rows are reserved for input and reports.

Line 120 returns to black paper before printing the digit. Its position above the strip makes the panel’s identity separate from its colour. Later, changing the panel must not make its number disappear.

Run the program. Expect a red strip with a white 1 above it. STOP ends the program deliberately: the 9 STOP statement report is expected here.

Give the panel a height

Replace lines 110–140, then add 150 and 160. The complete program becomes:

10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 PAPER 2
110 FOR r=3 TO 8
120 PRINT AT r,2;"            "
130 NEXT r
140 PAPER 0
150 PRINT AT 2,7;"1"
160 STOP

FOR r=3 TO 8 gives the variable r each value from 3 through 8. Each visit prints a strip on that row. NEXT r advances the counter and repeats the job until all six rows have been drawn. A Sinclair BASIC FOR counter uses a single-letter name.

The panel covers rows 3–8 and columns 2–13. Its width is the number of spaces; its height is the number of loop visits. The coordinate values choose its position, not its size.

Why are there six rows, rather than five?

Show the explanation

Both endpoints count: 3, 4, 5, 6, 7, 8. Subtracting 3 from 8 counts the gaps between those values. There is one more row than gap.

Foundations: Doing It Again explores how to trace repeated work. Here the changing counter has a visible use: it chooses the next row. Run the program and check that the strip has become a rectangle.

Give the repeated job its own home

We want four rectangles with the same dimensions. Give the drawing instructions a separate block, called a subroutine, and supply its position and colour through variables.

Replace 100–150, delete 160 by entering that number alone, and add 500–550. Keep lines 10–50:

10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 LET pr=3
110 LET pc=2
120 LET colour=2
130 GO SUB 500
140 PRINT AT 2,7;"1"
150 STOP
500 PAPER colour
510 FOR r=pr TO pr+5
520 PRINT AT r,pc;"            "
530 NEXT r
540 PAPER 0
550 RETURN

pr is the panel’s top row, pc its left column and colour its paper colour. LET stores a value in a variable. The renderer reads those values when called; changing a variable does not itself change the screen.

GO SUB 500 jumps to line 500 while remembering where to return. RETURN at line 550 takes us back to the instruction after that particular call. Line 150 stops the main program before it can fall into the routine without a call.

The routine paints six rows beginning at pr, then restores black paper. It changes r as it draws, but leaves pr, pc and colour alone. Run this version: the red rectangle should look the same. We have changed how the program is organised, not the picture it makes.

Foundations: Telling a Job What to Work On explains why routines need inputs. Its pseudocode gives routines local parameters. This Sinclair BASIC routine instead reads shared variables: the caller and routine use the same stored values. The 500 in GO SUB 500 is a line number to visit, not a panel number or a parameter.

Put the same job in four places

Replace 140 and 150, then add 160–290 as shown. Keep the routine at 500:

10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 LET pr=3
110 LET pc=2
120 LET colour=2
130 GO SUB 500
140 LET pc=18
150 LET colour=1
160 GO SUB 500
170 LET pr=12
180 LET pc=2
190 LET colour=4
200 GO SUB 500
210 LET pc=18
220 LET colour=6
230 GO SUB 500
240 PRINT AT 2,7;"1"
250 PRINT AT 2,23;"2"
260 PRINT AT 11,7;"3"
270 PRINT AT 11,23;"4"
280 PRINT AT 20,0;"Four choices: 1, 2, 3, 4."
290 STOP
500 PAPER colour
510 FOR r=pr TO pr+5
520 PRINT AT r,pc;"            "
530 NEXT r
540 PAPER 0
550 RETURN

The second call changes the column and colour but keeps row 3. The third changes to row 12 and column 2. The fourth keeps row 12 and changes the column to 18. Each call reads the values that exist at that moment.

Panel Top row Left column Paper
1 3 2 2 — red
2 3 18 1 — blue
3 12 2 4 — green
4 12 18 6 — yellow

The labels occupy rows 2 and 11; the instruction occupies row 20. None lies inside a rectangle. Position and number identify each choice even with the sound off or the colours removed.

Four rectangles arranged in two rows, with the digits 1 and 2 above the upper pair and 3 and 4 above the lower pair.
One drawing routine, called with four sets of values.

Run it and check all four digits. If a panel is one cell wide, count the spaces inside its string. If a panel appears in the wrong place, trace the last values assigned to pr and pc before its call. The numbered keys do not do anything yet; this program draws the board and stops.

Keep this program for Give a choice a signal. If you want to leave now, use SAVE "spark", then export the recorded BASIC tape from the emulator. Remember and save walks through that save-and-reopen process.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapters 4 (loops), 5 (subroutines), 15 (positioned printing) and 16 (colours).