Time And Motion - Sinclair ZX81 User Manual

Hide thumbs Also See for ZX81:
Table of Contents

Advertisement

Chapter 19 - Time & motion
Quite often you will want to make the program take a specified length of time, & for this you will find the
PAUSE statement useful (especially in fast mode):
PAUSE n
stops computing & displays the picture for n frames of the television (at 50 frames per second, or 60 in
America). n can be up to 32767, which gives you just under 11 minutes; if n is any bigger then it means
' PAUSE for ever'.
A pause can always be cut short by pressing a key (note that a space, or £, will cause a break as well).
You have to press the key down after the pause has started.
At the end of the pause, the screen will flash.
If a PAUSE statement is used in a program that will be run in FAST mode or on the old ZX80 with the
new 8K ROM, then the PAUSE statement must be followed by POKE 16437,355. The PAUSE will appear
to work without doing this, but it will probably result in your program being wiped out.
This program works the second hand (here just a single dot on the edge) of a clock.
5 REM FIRST WE DRAW THE CLOCK FACE
10 FOR N=1 TO 12
20 PRINT AT 10-10* COS (N/6* PI ),10+10* SIN (N/6* PI );N
30 NEXT N
35 REM NOW WE START THE CLOCK
40 FOR T=0 TO 10000
45 REM T IS THE TIME IN SECONDS
50 LET A=T/30* PI
60 LET SX=21+18* SIN A
70 LET SY=22+18* COS A
200 PLOT SX,SY
300 PAUSE 42
310 POKE 16437,255
320 UNPLOT SX,SY
400 NEXT T
(Miss out the REM statements unless you have a memory expansion board.)
This clock will run down after about 2 3/4 hours because of line 40, but you can easily make it run
longer. Note how the timing is controlled by line 300. You might expect PAUSE 50 to make it tick once a
second, but the computing takes a bit of time as well & has to be allowed for. This is best done by trial &
error, timing the computer clock against a real one, & adjusting line 300 until they agree. (You can't do this
very accurately; an adjustment of one frame in one second is 2% or half an hour a day.)
The function INKEY$ (which has no argument) reads the keyboard. If you are pressing exactly one key
(or the shift key and one other key) then the result is the character that the key gives in
the result is the empty string. The control characters do not have their usual effect, but give results like
CHR$ 118 for newline - they are printed as "?".
Try this program, which works like a typewriter.
10 IF INKEY$<> "" THEN GOTO 10
20 IF INKEY$ ="" THEN GOTO 20
30 PRINT INKEY$ ;
40 GOTO 10
Here line 10 waits for you to lift your finger off the keyboard & line 20 waits for you to press a new key.
Remember that unlike INPUT , INKEY$ doesn't wait for you. So you don't type newline, but on the other
hand if you don't type anything at all then you've missed your chance.
Exercises
1. What happens if you miss out line 10 in the typewriter program?
2. Why can you not type space or £ in the typewriter program?
Here is a modified program that gives you a space if you type cursor right (shifted 8).
mode; otherwise

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents