|TALKING TO THE ZX-80|
Set up the computer as described in chapter 2 and switch on. You will see a sign appear at the bottom left hand comer of the screen. This is the cursor and shows you where you are on the screen.
If you look at the keyboard you will see that it looks quite like a typewriter keyboard but there are some differences. There is no carriage return key (instead there's a key called NEW LINE) and the space bar is replaced by a key labelled SPACE. All the letters are upper case (capitals) so that if you use the SHIFT key you get the symbol printed on the top right hand corner of the key. You'll also notice that quite a lot of keys have labels above them - such as NEW above the Q key. These will save you a lot of time from now on.
One vital point: it is very important to distinguish between the letter O and figure 0 or Zero. In the book we will use O to mean letter O and 0 to mean zero. On the screen the computer uses a square O [O] for letter O and a hexagonal 0  for zero. (The reason that we've used 0 in the book is because it is easier for printing and because all other books on programming use it).
SINGLE-KEY KEYWORD SYSTEM
Hit the Q key. Amazing! The computer writes NEW on the screen. Now hit NEWLINE. You have cleared the computer ready to accept a new program. This illustrates the single-key keyword system. Most of the words you'll have to use with ZX-80 BASIC can be typed with only one keystroke in this way. In all this may save you up to 40% of the typing you'd otherwise have to do. Some BASIC'S allow you to use single keystrokes to input words like NEW, PRINT, RUN etc but only the ZX-80 prints out the word in full. This makes it much easier to keep track of what's going on in programs. You'll see how it works as you go along.
The labels above the numeral keys NOT, AND etc are not keywords. They are called tokens and, when needed, are obtained by using the SHIFT key. This also applies to EDIT on the NEWLINE key.
Getting data in and out of the ZX-80 computer.
The PRINT statement allows you to get data out of the computer. This can be done while a program is running or afterwards.
10THIS IS A STRING
using SHIFT Y for
That should have come out as
10 PRINT "THIS IS A STRING"
The computer provided the word PRINT, as well as the space between 10 and PRINT. Did you notice what happened to the cursor?. First of all, it followed what you were typing in, appearing just after the last character typed. After PRINT it changed to a sign - this showed that the computer was not expecting any more single-key keywords just then. After you typed " you may have noticed that another character appeared as well a sign. What was actually on the screen was
10 PRINT "
This is the syntax error marker and occurs if there is a syntax error in the line being typed in. In this case it came up because the line needs the closing quotation marks if it is to be correct. The followed the cursor as you typed in THIS IS A STRING and vanished when you typed the second ". Now erase the " by using the RUBOUT key. The reappears. Try hitting the NEWLINE key nothing happens because the computer won't accept a line containing a syntax error.
Type " and hit the NEWLINE key.
The computer accepts the line and displays it at the top of the screen together with a [>] cursor which shows that it is the last (and in this case the first) line entered. The [>] points to the current line.
Although there is only one line entered it is a program consisting of only one instruction. Type R (RUN) and NEWLINE and the program will run after a brief flicker on the screen the words
THIS IS A STRING
appear at the top of the screen. At the bottom you'll see 0/10 which tells you that the program ran successfully with no errors.
Type any key to get back into command mode.
What the computer did was to print all the characters between the quotation marks. Any character (except for quotation marks) is legal when PRINT is used in this way.
In general this form of the PRINT statement is useful for things like titles which only have to be printed once in a program. There are other forms which allow more complicated things to be done; you'll come across these the whole way through this book.
Now let's try getting some data into the computer. This is done by using the INPUT statement, which is basically of the form:
INPUT variable name.
Hit NEW (key Q) and NEWLINE. This tells the computer that a new program is being entered.
Type in the following program, using NEWLINE at the end of each line. (If you make a mistake, use SHIFT 0 (RUBOUT) to delete the mistake; every time you hit RUBOUT the character, keyword, or token to the left of the cursor is deleted).
10 PRINT "ENTER YOUR STRING"
20 INPUT A$ (A$ is the name of a string variable)
30 PRINT A$ (You can use PRINT to print out a variable)
Now run the program by typing RUN (key R) and NEWLINE. The computer responds with
ENTER YOUR STRING
and waits. The "L" means that it is waiting for you to do something; in this case the quotation marks show that is is expecting you to enter a string variable.
Type in a short message or random string of letters (don't use quote marks) and press NEWLINE. The computer prints out what you have just put in, which was a string variable called A$.
Get back into command mode by pressing any key. Try running the program several times using more and more characters in your string. Keep an eye on the cursor. On the 15th line it will vanish. RUBOUT (shift 0) - the cursor will reappear. Now carry on adding characters the display will gradually get SMALLER as you use up the storage capacity of the processor. Now hit NEWLINEa 4/20 error message appears. The 4 tells you that the ZX-80 ran out of space to put the string variable into, and the 20 tells you that this happened at line 20 of the program.
Get back into command mode.
You may have wondered why the line numbers have been 10, 20, 30 instead of. (say) 1,2. 3.
This is because you may want to add bits to the middle of your program.
For instance, enter
22 PRINT "ENTER A NUMBER"
24 INPUT A
40 PRINT A
The program displayed at the top of the screen now reads
10 PRINT "ENTER YOUR STRING"
20 INPUT A$
22 PRINT "ENTER A NUMBER"
24 INPUT A
30 PRINT A$
40 PRINT A
because the computer always sorts out the lines in numerical order. By leaving gaps between line numbers you can always do this. It also makes it easy to see how you've altered the program since the original lines will have line numbers in multiples of 10 (unless the lines were added at the end of the program, like statement 40). Now try running the program again.
FIRST it asks you for a string. Enter a string.
THEN it asks you for a number. Notice that when the ZX-80 is waiting for you to enter a number it displays and not "". Enter a number.
FINALLY it prints out what you put in.
In chapter 3 the difference between string variables and integer variables is mentioned. The program has two variables in it a string variable A$ and an integer variable A. How does the computer react when you give it a different sort of variable to the one that it's expecting?
Easy enough to find out just run the program again. When the computer asks you for a string, give it a number. What happened?. It was accepted numbers are acceptable inside strings. Now when it asks you for a number, type in a letter. Nothing much happened except that 2/24 appeared at the lower left hand corner of the screen. This is another error code. The 2 stands for the type of error VARIABLE NAME NOT FOUND - because the computer knew that the letter was the name of an integer variable and you hadn't assigned a value to it. The 24 stands for the line number at which the error was found.
Suppose that you want to alter something in a program that you've already entered. (This is called editing a program.)
It's easy on a ZX-80.
Get into command mode.
Look at the listing at the top of the screen. The [>] cursor (current line pointer) is at line 40. Now see what happens when you hit SHIFT 7 () a few times - the cursor moves up line by line. SHIFT 6 () moves it down line by line. These keys allow you to select any line in your program to edit.
A further key, HOME (SHIFT 9) sets the line pointer to line 0. Because there isn't a line 0 the cursor will vanish if you use HOME but when you hit SHIFT 6 the cursor will jump to the next line in this case line 10 and reappear.
Select a line line 22 for example.
Now hit SHIFT NEWLINE. Line 22 (or any other one you might have selected) appears at the bottom of the screen.
Try SHIFT 8 () you'll see the cursor jump past PRINT. SHIFTS (?) moves the cursor left, to where it was before. Try moving the cursor right a few times say to the position after ENTER. Now type a few A's they are inserted into the string to the immediate left of the cursor. A few RUBOUTS and you can erase them again.
This editing facility is very useful if you want to alter individual characters within lines. However, if you want to delete a whole line it would be rather tedious to go through the procedure mentioned above. There is a simpler way to delete lines, though.
Type the line number, then NEWLINE and you'll see the line vanish from the listing at the top of the screen. The cursor [>] will also vanish. It will not reappear until you type a new line, use the control keys ? and ?, or use the LIST command.
THE LIST COMMAND
As you get more experienced with the ZX-80 you'll want to write programs longer than the 24 lines which will fit onto the screen. This could pose a problem or could it? We can find out by writing a really long program.
Type NEW then NEWLINE.
Enter the following program (which prints a large number of blank lines).
40 PRINT ... and so on to ...
230 PRINT (keep an eye on the listing in the upper part of the screen)
We seem to have lost the first few lines. Or have we?
Hit LIST (key A) followed by NEWLINE - the program is now displayed from line 10 down.
Now try LIST 200 the program is displayed from line 200. You can list the program starting from any line you want in this way. Notice that the current line cursor is altered to the line you selected.
Try using the up/down cursor control keys go on hitting the key and see what happens. In this way you can display any part of the program you want.
By now you will have realised that the ZX-80 has some powerful (and very convenient) facilities to help you write programs.
From now on we can concentrate on how to write programs which actually do something like solving arithmetic problems, for instance.