<!-- PDF page 122 -->

```
210 PAUSE wait
220 PLOT 128,88: DRAW OVER 1;
    sx,sy: REM erase 2nd hand
400 NEXT t
```

This clock will run down after about 55.5 hours because of line 60, but you can easily make it run longer. Note how the timing is controlled by line 20. When running in *50Hz* mode, you might expect **PAUSE 50** to make it tick one a second, but the computing takes a bit of time as well and has to be allowed for. This is best done by trial and error, timing the computer clock against a real one, and adjusting line 20 until they agree. (You can't do this very accurately; an adjustment of one frame in one second is 1.67% or less than half an hour in a day.)

### Using POKE and PEEK at the System Variables

There is a much more accurate way of measuring time. This uses the contents of certain memory locations. The data stored is retrieved by using **PEEK**. *Chapter 24 – The System Variables*, explains what we're looking at in detail. The expression used is:

**(65536*PEEK 23674+256*PEEK 23673+PEEK 23672)/50**

which gives the number of seconds since the computer was turned on (up to about **3** days and **21** hours, when it goes back to **0**). That being said *System Variables* are not guaranteed to be in the same location or even accessible with succesive versions of *NextBASIC* and *NextZXOS*. For that reason, we are provided with one hybrid command/function which does the exact same thing removing uncessecary calculations and non-standard access to the system variables. The keyword in question is **TIME** and we'll examine it below.

### TIME (command/function)

When used as a command, TIME takes no arguments and simply resets the frame counter (*System Variable* **FRAMES** – See *Chapter 24* for details) to **0**. Intended for use with the corresponding **TIME** function which returns how many frames have passed since bootup or since the **FRAMES** counter was reset. For example here's a silly program to verify **PAUSE** and **TIME** measure the same thing:

```
10 INPUT "How many PAUSE
   frames? ";f
20 TIME
30 PROC perftest(f)
40 PRINT '"perftest() took
   ";TIME;" frames against
   desired ";f;" frames."
50 STOP
60 DEFPROC perftest(frames)
70 PAUSE frames
80 ENDPROC
```

### Retrieving information from the RTC

Your ZX Spectrum Next has a DS1307 *Real Time Clock* (*RTC*) installed, which allows you to use a more accurate way of retrieving timekeeping data; one that doesn't involve any calculations as described above; nor one that can be affected by clock speed changes.

There are two ways to retrieve time (or date) information from the *RTC*. The first is not very straightforward owning to the fact that it's triggered via a *dot command*. The second how-

