The System Timer
Read the Spectrum's built-in clock using PEEK to measure time.
Games need timers — countdowns, speed bonuses, time limits. The Spectrum has a built-in clock that ticks 50 times per second. You can read it with PEEK.
The Program
10 CLS
20 PRINT "Timer demo"
30 PRINT
40 PRINT "The Spectrum counts time in"
50 PRINT "50ths of a second at address"
60 PRINT "23672 (low) and 23673 (high)."
70 PRINT
80 PRINT "Press a key to start timing..."
90 IF INKEY$ = "" THEN GO TO 90
100 LET t = PEEK 23672 + 256 * PEEK 23673
110 PRINT
120 PRINT "Timing... press a key to stop"
130 IF INKEY$ <> "" THEN GO TO 130
140 IF INKEY$ = "" THEN GO TO 140
150 LET e = PEEK 23672 + 256 * PEEK 23673
160 LET d = (e - t) / 50
170 PRINT
180 PRINT "Elapsed: "; d; " seconds"

How It Works
The Spectrum stores a frame counter at memory addresses 23672 (low byte) and 23673 (high byte). It increments 50 times per second (PAL).
Reading the timer:
LET t = PEEK 23672 + 256 * PEEK 23673
This combines the two bytes into a single number. The low byte counts 0-255, then the high byte increases by 1. Multiplying the high byte by 256 and adding the low byte gives the total tick count.
Calculating seconds:
LET d = (e - t) / 50
Subtract the start time from the end time, divide by 50 (ticks per second), and you get elapsed seconds.
PEEK
PEEK reads a single byte from memory. The Spectrum’s RAM contains the program, the screen, system variables, and more. Address 23672 is one of the system variables — the frame counter.
You’ll use PEEK mainly for the timer, but it can read any memory address. It’s your window into the machine’s internals.
Why Not PAUSE?
PAUSE stops the program for a set time. But in a game loop, you can’t stop — the game needs to keep running. Instead, you record the start time, and on each loop iteration you calculate how much time has passed. The game keeps moving while the clock ticks.
Try This
Reaction timer. Clear the screen, wait a random time (PAUSE INT(RND*100)+50), print “NOW!”, record the start time, wait for a keypress, and show the reaction time in 50ths of a second.
Precision. Don’t divide by 50. Show the raw tick count instead. Each tick is 20 milliseconds.
What You’ve Learnt
- PEEK — reads a byte from a memory address
- System timer — addresses 23672/23673, ticks at 50Hz
- Two-byte values —
low + 256 * highcombines two bytes - Elapsed time — subtract start from current, divide by 50