Give a choice a signal
Light and restore a panel, give it a note, then use the same cue routine for all four choices.
A board gives the player four places to look. A cue tells them which place matters now. We’ll make a panel brighten and gain an asterisk, then sound a note and return it to rest. Its digit will stay visible throughout.
Continue with the final program from Four choices on the screen.
Keep it in memory, or load your saved spark tape. If arriving here directly,
that lesson supplies and explains the complete board; no other game is needed.
Keyboard notes for this lesson
For IF, press U after the line number; THEN is left Option/Alt+G.
In extended mode, left Option/Alt+B gives BRIGHT and +Z gives BEEP.
PAUSE is M after a line number.
Let a panel number choose the drawing values
The board currently supplies coordinates and colour before every call. Now we want to say “panel 2” and let the drawing routine select that panel’s values. We also need to say whether to draw it resting or active.
Use two shared variables: p for the panel number, and lit for its state.
lit=0 means resting; lit=1 means active. These are numbers whose meanings
we have chosen, not special BASIC words.
Delete the existing lines 100–290. Enter the following main program in their place, keeping lines 10–50:
100 LET lit=0
110 FOR p=1 TO 4
120 GO SUB 500
130 NEXT p
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;"Watch panel 2."
300 LET p=2
310 LET lit=1
320 GO SUB 500
330 STOP
The loop calls the drawing routine with p equal to 1, 2, 3 and 4, keeping
lit=0. After drawing the labels, lines 300–320 select panel 2 and redraw it
with lit=1. This first experiment leaves it active so we can examine it.
Delete line 540. Replace the other old routine lines at 500–550 with this routine, adding the higher-numbered lines shown:
500 LET pr=3
510 LET pc=2
520 LET colour=2
530 LET inkcol=7
550 IF p=2 THEN LET pc=18
560 IF p=2 THEN LET colour=1
580 IF p=3 THEN LET pr=12
590 IF p=3 THEN LET colour=4
600 IF p=3 THEN LET inkcol=0
620 IF p=4 THEN LET pr=12
630 IF p=4 THEN LET pc=18
640 IF p=4 THEN LET colour=6
650 IF p=4 THEN LET inkcol=0
670 PAPER colour
680 INK inkcol
690 BRIGHT lit
700 FOR r=pr TO pr+5
710 PRINT AT r,pc;" "
720 NEXT r
770 IF lit=1 THEN PRINT AT pr+2,pc+5;"*"
780 PAPER 0
790 INK 7
800 BRIGHT 0
810 RETURN
The routine begins with panel 1’s values. The IF lines change the values
needed by panels 2, 3 and 4. For example, panel 2 changes the column and paper
colour, but keeps row 3 and white ink. Panel 4 changes all four drawing values.
IF tests a condition; the instruction after THEN runs only when it is true.
Each call starts from those defaults again. Without that reset, a previous call could leave the next panel with its ink or coordinates. Foundations: Making a Choice develops the idea of choosing work according to a condition. Here several conditions select the parts of one drawing description.
inkcol is the foreground colour. Red and blue use white; green and yellow
use black. We did not need a foreground for blank spaces, but the asterisk
needs to contrast with its background.
Brightness belongs to printing
BRIGHT lit selects ordinary brightness for 0 and increased brightness for 1.
Like PAPER, this selects an attribute for characters printed afterwards.
It does not brighten an existing rectangle by itself. The loop repaints the
panel using the selected state. Line 770 adds an asterisk only when lit=1.
Returning to rest will paint spaces over it.
The Spectrum stores foreground, background and brightness attributes for each 8-by-8-pixel character cell. Our panels fit that grid: each printed space replaces one cell’s picture and colour attributes. We do not need individual pixel drawing for these large, clear signals.
Lines 780–800 restore black paper, white ink and ordinary brightness for later
text. The routine changes pr, pc, colour, inkcol and the drawing counter
r. It leaves p and lit unchanged. The caller’s FOR p and renderer’s
FOR r need different counters, or the inner drawing work would disturb which
panel comes next.
Why does the number 2 survive when its panel is repainted?
Show the explanation
The digit is on row 2. Its rectangle occupies rows 3–8, so the renderer never prints over the digit’s cells. Colour and brightness may change; the identity stays in the same place.
Run it. Panel 2 should be brighter and contain an asterisk. The other three
panels should stay at rest. The 9 STOP statement report is intentional.

Complete program at this checkpoint
10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 LET lit=0
110 FOR p=1 TO 4
120 GO SUB 500
130 NEXT p
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;"Watch panel 2."
300 LET p=2
310 LET lit=1
320 GO SUB 500
330 STOP
500 LET pr=3
510 LET pc=2
520 LET colour=2
530 LET inkcol=7
550 IF p=2 THEN LET pc=18
560 IF p=2 THEN LET colour=1
580 IF p=3 THEN LET pr=12
590 IF p=3 THEN LET colour=4
600 IF p=3 THEN LET inkcol=0
620 IF p=4 THEN LET pr=12
630 IF p=4 THEN LET pc=18
640 IF p=4 THEN LET colour=6
650 IF p=4 THEN LET inkcol=0
670 PAPER colour
680 INK inkcol
690 BRIGHT lit
700 FOR r=pr TO pr+5
710 PRINT AT r,pc;" "
720 NEXT r
770 IF lit=1 THEN PRINT AT pr+2,pc+5;"*"
780 PAPER 0
790 INK 7
800 BRIGHT 0
810 RETURN
Add a note, then restore the panel
A lasting highlight identifies a choice, but a sequence needs separate events. We’ll wrap activation, sound and restoration into a second routine.
Replace 300, 310 and 320, delete 330, and add 540, 570, 610, 660 and 900–960:
300 LET p=2
310 GO SUB 900
320 STOP
540 LET note=0
570 IF p=2 THEN LET note=4
610 IF p=3 THEN LET note=7
660 IF p=4 THEN LET note=12
900 LET lit=1
910 GO SUB 500
920 BEEP 0.15,note
930 LET lit=0
940 GO SUB 500
950 PAUSE 10
960 RETURN
The drawing routine now sets note as well as the drawing values. Panel 1
starts at pitch 0; the conditions choose 4, 7 and 12 for the others. Every call
sets a note, so a panel cannot inherit the previous panel’s sound.
GO SUB 900 calls the cue routine. It sets lit=1 and calls the renderer,
which returns to line 920. Then BEEP 0.15,note sounds the selected note for
0.15 seconds.
Its first number is a duration in seconds; the second is pitch in semitones
above middle C. Twelve semitones make an octave. Pitch 0 is a note, not silence.
After the note, lines 930–940 repaint the panel at rest. The asterisk disappears and brightness returns to normal. Line 950 requests an extra ten display frames of silence. On our 50 Hz target, ten frames would be a fifth of a second, but a key can cut a PAUSE short. Printing and BASIC instructions take time too, so the whole cue is longer than its note.
We allow that extra wait to shorten. The cue still sounds its note and repaints the panel before another cue begins; a key does not jump over those instructions. For now, leave the keys alone when comparing the intended rhythm. This is readable pacing for a memory game, not a precision clock.
The cue’s RETURN goes back to its caller at line 320. Calls can be nested:
the renderer returns to the cue, then the cue returns to the main program.
Write the repeated job once
explores how one routine can return to different callers.
Run it. Watch panel 2 light, hear its note if sound is on, and check that the
panel rests again with its label intact. BEEP occupies the BASIC program
while sounding; it is not background music running alongside the next line.
Complete program with a returning cue
10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 LET lit=0
110 FOR p=1 TO 4
120 GO SUB 500
130 NEXT p
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;"Watch panel 2."
300 LET p=2
310 GO SUB 900
320 STOP
500 LET pr=3
510 LET pc=2
520 LET colour=2
530 LET inkcol=7
540 LET note=0
550 IF p=2 THEN LET pc=18
560 IF p=2 THEN LET colour=1
570 IF p=2 THEN LET note=4
580 IF p=3 THEN LET pr=12
590 IF p=3 THEN LET colour=4
600 IF p=3 THEN LET inkcol=0
610 IF p=3 THEN LET note=7
620 IF p=4 THEN LET pr=12
630 IF p=4 THEN LET pc=18
640 IF p=4 THEN LET colour=6
650 IF p=4 THEN LET inkcol=0
660 IF p=4 THEN LET note=12
670 PAPER colour
680 INK inkcol
690 BRIGHT lit
700 FOR r=pr TO pr+5
710 PRINT AT r,pc;" "
720 NEXT r
770 IF lit=1 THEN PRINT AT pr+2,pc+5;"*"
780 PAPER 0
790 INK 7
800 BRIGHT 0
810 RETURN
900 LET lit=1
910 GO SUB 500
920 BEEP 0.15,note
930 LET lit=0
940 GO SUB 500
950 PAUSE 10
960 RETURN
Try all four signals
Replace 280, 300 and 320, retain 310, and add 330:
280 PRINT AT 20,0;"Watch panels 1 to 4."
300 FOR p=1 TO 4
310 GO SUB 900
320 NEXT p
330 STOP
The main loop supplies panel numbers 1–4. Each cue finishes before the next call. Listen for four rising pitches, and watch that their positions agree with their digits. With the sound off, the asterisks must still make the order readable. Colour is helpful, but it is not the only clue.
| Panel | Pitch | Active marker |
|---|---|---|
| 1 | 0 | White asterisk on red |
| 2 | 4 | White asterisk on blue |
| 3 | 7 | Black asterisk on green |
| 4 | 12 | Black asterisk on yellow |
Run it again and concentrate on the return to rest between signals. That break will matter when the same panel appears twice in an order. If the final panel stays active, inspect lines 930–940. If later text becomes coloured or bright, inspect the attribute resets at 780–800.
Complete program to keep
10 BORDER 0
20 PAPER 0
30 INK 7
40 CLS
50 PRINT "BRIGHT SPARK"
100 LET lit=0
110 FOR p=1 TO 4
120 GO SUB 500
130 NEXT p
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;"Watch panels 1 to 4."
300 FOR p=1 TO 4
310 GO SUB 900
320 NEXT p
330 STOP
500 LET pr=3
510 LET pc=2
520 LET colour=2
530 LET inkcol=7
540 LET note=0
550 IF p=2 THEN LET pc=18
560 IF p=2 THEN LET colour=1
570 IF p=2 THEN LET note=4
580 IF p=3 THEN LET pr=12
590 IF p=3 THEN LET colour=4
600 IF p=3 THEN LET inkcol=0
610 IF p=3 THEN LET note=7
620 IF p=4 THEN LET pr=12
630 IF p=4 THEN LET pc=18
640 IF p=4 THEN LET colour=6
650 IF p=4 THEN LET inkcol=0
660 IF p=4 THEN LET note=12
670 PAPER colour
680 INK inkcol
690 BRIGHT lit
700 FOR r=pr TO pr+5
710 PRINT AT r,pc;" "
720 NEXT r
770 IF lit=1 THEN PRINT AT pr+2,pc+5;"*"
780 PAPER 0
790 INK 7
800 BRIGHT 0
810 RETURN
900 LET lit=1
910 GO SUB 500
920 BEEP 0.15,note
930 LET lit=0
940 GO SUB 500
950 PAUSE 10
960 RETURN
Save this version as spark when you finish. We now have a cue routine whose
input is p, whose work includes picture and sound, and whose result is a
resting panel. Next we’ll store an order for that routine to present, rather
than always choosing 1, 2, 3, 4.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 5 (subroutines), chapter 16 (colour attributes and BRIGHT), chapter 18, p. 129 (interruptible PAUSE), and chapter 19 (BEEP duration and pitch).