Sinclair ZX81 BASIC Programming

Peter Kitson

ISBN : B0006Y0GYA

Order a printed copy of this book from Amazon.


Cover Design - Sinclair ZX81 BASIC Programming
 

For your free electronic copy of this book please verify the numbers below. 

(We need to do this to make sure you're a person and not a malicious script)

Numbers

 




Sample Chapter From Sinclair ZX81 BASIC Programming
     Copyright © Steven Vickers



Chapter 2 - Telling the computer what to do

Turn the computer on (by plugging it in) and get the blank screen with the write-on-black K, as in the picture in chapter 1. To make it do something, you have to type in a message that it understands; for instance the message

       PRINT 2+2

tells it to work out the sum 2+2 and display the answer on the TV screen.

    A message like this, telling the computer to do something straight away, is a command; this particular one is a PRINT command, but also a PRINT statement. Calling it a PRINT statement just specifies its form without referring to how the computer is going to use it. Thus every command takes the form of a statement, but so do some other things - program lines do, as we shall see in chapter 8.

    To type in this command,

1. First type PRINT. But, although as you can see the keyboard has a key for each letter, you do not spell the word out P, R, I, N, T. As soon as you press P the whole word will come up on the screen, tohether with a space to make things look nice, and the screen will look like this:

    The reason for this is that at the beginning of each command the computer is expecting a keyword - a word that specifies what kind of command it is. The keywords are written above the keys, and you will see that \'PRINT\' appears above the P key, so that to get \'PRINT\' you have to press P.

    The computer lets you know that it expects a keyword by the  that you had to start off with. There is almost always some white-on-black (inverse video) letter, either  or  (or, we shall see later,  or ), called the cursor. The  means \'whatever key you press, I shall interpret it as a keyword\'. As you saw, after you had pressed P for PRINT, the  changed to an .

    This system of pressing just one key to get more than one symbol is used a lot on the ZX81. In the rest of this manual, words with their own keys are printed in BOLD TYPE.

    You must remember that it is useless trying to spell these words out in full, because the computer just won\'t understand.

2. Now type 2. This should cause no problems. Again, you should see 2 appear on the screen, and the L move along one place.

    Note also how much space is automatically put in between PRINT & 2 to make it look neat. This is done as much as possible, so that you hardly ever have to type a space. If you do type a space, it will appear on the screen, but it will not affect the meaning of the message at all.

3. Now type +. This is a shifted character (they are marked in red - the colour of SHIFT itself on its key - in the top right hand corner of each key), and to get \'+\' you must hold down the key  and while you are still doing that, press the key .

4. Now type 2 again. The screen will look like this:

5. Now - and you must always remember this - press NEWLINE, the key . This means \'message complete\', or \'all right, computer, lets see some action\'. The computer will now read the message, work out what has to be done, and do it. In this case, the screen will change to

    4 is the answer - but of course you do not need to buy a computer to work that out.

    0/0 (Note how zero is written with a slash to distinguish it from capital O. This is fairly common in computing circles.) is the report in which the computer tells you how it got on. The first 0 means \'OK, no problems\'. (In appendix B there is a list of the other report codes that can arise, for instance if something goes wrong.) The second 0 means \'the last thing I did was line 0\'. You will see later - when you come to write programs - that a statement can be given a number & stored away for execution later: it is then a program line. Commands do not actually have numbers, but for the sake of reports the computer pretends that they are line 0.

    You should imagine a report as hiding a  cursor - if you press P for PRINT now, the report will disappear and the screen will change to

    The cursor can also be used for correcting mistakes: type ++2, to get

        PRINT ++2

on the bottom line, Pretty incomprehensible stuff, and when you press NEWLINE you get

    The  is the syntax error marker (the syntax is the grammar of the message, saying which are allowed and which are not), and shows that the computer got as far as \'PRINT\', but after that decided that it was not a proper message.

    What you want to do of course is rub out the first +, and replace it by - let us say - 3. First you have to move the cursor so that it is just to the right of the first +; there are two keys,  and  (shifted 5 and shifted 8), that move the cursor left and right. Holding SHIFT down, press the  key twice. This moves the cursor left two places to give you

       PRINT ++2

    Now press the RUBOUT key (shifted 0), and you will get

       PRINT+2

RUBOUT rubs out the character (or keyword) immediately to the left of the cursor.

    If you now press 3 this will insert a \'3\', again immediately to the left of the cursor, giving

       PRINT 3+2

and pressing NEWLINE gives the answer (5).

    The  key (shifted 8) works just like the  key, except that it moves the cursor right instead of left.
 
 

Summary

    This chapter has covered how to type messages in for the ZX81, explaining the single keystroke system for words,

    the  cursors,

    reports,

    the syntax error marker, 

    & how to correct mistakes using  and RUBOUT.
 
 

The keyboard

    Here is a picture of the keyboard.

    Remember that to use SHIFT, you have to hold it down at the same time as you press another key. Do not confuse digit 0 with letter O.