One of the most important features of the ZX Spectrum Next is the ability to move things on screen fast, either via the usage of sprites or by quickly interchanging full screens to create animations and general visual effects. Motion (and animation) however, as on real life, is a function of time. In other words we need to precisely count time in order to display things and for this purpose this chapter will deal with these two seemingly unrelated subjects in one unit. We will begin with the whole idea of timekeeping on the computer and all the facilities the ZX Spectrum Next has in order for us to measure time.
Timekeeping is essential in computing as all devices work on the basis of a unit of time (in our case Hertz –or– Hz) but much of this happens behind the scenes. Here we will examine commands related to time together with the optional timing hardware, before we move into animation, scrolling, the Sprite Engine and eventually to the Copper.
While the general attitude in programming is to make things execute as fast as possible, we often find ourselves in need of making our program wait for a specific length of time or even indefinitely. There is a number of reasons why that would be the case; expecting user interaction is one; displaying warnings is another, timing precisely something is a third and for all the above and more you will find the PAUSE statement useful.
stops computing and displays the picture for n frames of the selected display mode.
In 50Hz mode, there are 50 frames-per-second (fps), so setting n to 50 would result in 1 sec. pause. Respectively in 60Hz mode which runs at 60 fps this figure would be 60 for 1 sec. pause.
These modes are set these at the Configuration boot menu or via the config.ini file which is located in the c:/machines/next/ folder. Generally speaking, almost all modern HDMI™ and VGA displays operate at 60Hz, while many also have 50Hz modes.
n can be up to 65535, which gives you just a little over 21 minutes at 50Hz and just under 19 minutes at 60Hz respectively; if n is set to 0 then it means PAUSE indefinitely.
A pause of any length (including the indefinite ones) can always be cut short by pressing a key (note that CAPS SHIFT + Space or BREAK will cause a break as well). You have to press the key down after the pause has started.
This program works the second hand of a clock:
10 REM We select the appropriate
pause
20 wait=52:REM 50Hz/50=1 sec.
30 REM First we draw the clock face
40 FOR n=1 TO 12
50 PRINT AT 10-10*COS(n/6*PI),
16+10*SIN(n/6*PI);n
60 NEXT n
70 REM Now we start the clock
80 FOR t=0 TO 200000: REM t is the
time in seconds
90 a=t/30*PI : REM a is the angle of
the second hand in rad.
100 sx,sy=80*SIN a,80*COS a
200 PLOT 128,88: DRAW OVER 1;
sx,sy: REM draw 2nd hand
ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.