CHAPTER 20

Tape storage

Summary

LOAD, SAVE, VERIFY, MERGE

The basic method for using the cassette recorder to SAVE, LOAD and VERIFY programs are given in the Introductory booklet. This section should be read, and the procedures tried out before reading any further.

We have seen that LOAD deletes the old program and variables in the computer before loading in the new ones from tape; there is another, MERGE, that does not. MERGE only deletes an old program line or variable if it has to because there is a new one with the same line number or name. Type inthe 'dice' program in Chapter 11 and save it on tape, as "dice". Now enter and run the following:

	1 PRINT 1
	2 PRINT 2
       10 PRINT 10
       20 LET x=20

and then proceed as for the verification, but replacing VERIFY "dice" with

	MERGE"dice"

If you list the program you can see that lines 1 and 2 have survived, but lines 10 and 20 have been replaced by those from the dice program. x has also survuved (try PRINT x).

You have now seen simple forms of the four statements used with the cassette tape:

SAVE records the program and variables on to cassette.

VERIFY checks the program variables on cassette against those already in the computer.

LOAD clears the computer of all its program and variables, and replaces them with new ones read in from cassette.

MERGE is like LOAD except that it does not clear out an old program line or variable unless it has to because its line number or name is the same as that as that of a new one from cassette.

In each of these, the keyword is followed by a string: for SAVE this provides a name for the program on tape, while for the other three it tells the computer which program to search for. While it is searching, it prints up the name of each program it comes across. There are a coupl of twists to all this.

For VERIFY, LOAD and MERGE you can provide the empty string as the name to search for; then the computer does not care about the name, but takes the first program it comes across.

A variant on SAVE takes the form

SAVE string LINE number

A program saved using this is recorded in such a way that when it is read back by LOAD (but not MERGE) it automatically jumps to the line with the given number, thus running itself.

So far, the only kins of information we have stored on cassette have been programs together with their variables. There are two other kinds as well, called arrays and bytes.

Arrays are dealt with slightly differently:

You can save arrayson tape using DATA in a SAVE statement by

	SAVE string DATA arrayname()

String is the name that the information will have on tape and works in exactly the same way as when you save a program or plain bytes.

The array name specifies the array you want to save, so it is just a letter or a letter followed by $. Remember the brackets afterwards; you might think they are logically unnecessary but you still have to put them in to make it easier for the computer.

Be cleaar about the separate roles of string and array name. If you say (for instance)

SAVE "Bloggs" DATA b()

then SAVE takes the array b from the computer ans stores it on tape under the name "Bloggs". When you type

VERIFY "Bloggs" DATA b()

the computer will look for a number array stored on tape under the name "Bloggs" (when it finds it will write up 'Number array: Bloggs') and check it against the array b in the computer.

LOAD "Bloggs" DATA b()

finds the array on tape, and then - if there is room for it in the computer - delete any array already existing called b and loads in the new arrat from tape, calling it b.

You cannot use MERGE with saved arrays

You can save character (string) arrays in exactly the same way. When the computer is searching the tape and finds one of these it writes up 'Character array:' followed by the name. When you load in a character array, it will delete not only any previous character array with the same name, but also any string with the same name.

Byte storage is used for pieces of information without any reference to what the information is used for - it could be television pictures, or used-defined graphics, or something you have made up yourself. It is shown using the word CODE, as in

SAVE "picture" CODE 16384,6912

The unit of storage in memory is the byte (a number between 0 and 255), and each byte has an address (which is a number between 0 and 65535). The first number after CODE is the address of the first byte to be stored on tape, and the second is the number of bytes to be stored. In our case, 16384 is the address of the first byte in the display file (which contains the television picture) and 6912 is the number of bytes in it, so we are saving a copy of the television screen - try it. The name "picture" works just like the names for programs.

To load it back, use

LOAD "picture" CODE

You can put numbers after CODE in the form

LOAD name CODE start,length

Here length is just a safety measure; wjen the computer has found the bytes on taoe with the right name, it will still refuse to load them in if there are more than length of them - since there is obviously more data than you expected it could otherwise overwrite something you had not intended to be overwritten. It gives the error report R Tape loading error. You can miss out length, and then the computer will read in the bytes however many there are.

Start shows the addreswhere the first byte is to be loaded back to - thuis can be different frmo the address it was saved from, although if they are the same you can miss out the start in the LOAD statement.

CODE 16384,6912 is so useful for saving and loading the picture that you can replace it with SCREEN$ - for instance.

SAVE "picture" SCREEN$
LOAD "picture" SCREEN$

This is a rare case for which VERIFY will not work - VERIFY writes up the names of what it finds on tape, so that by the time it gets round to the verification the display file has been changed and the verification fails. In all other cases you should use VERIFY whenever you use SAVE.

Below, is a complete summary of the four statemnts used in this chapter.

Name stands for any string expression, and refers to the name under which the information is stored on cassette. It should consistof ASCII printing chracters, of which only the first 10 are used.

There are four sorts of information that can be stored on tape: program and variables (together), number arrays, character arrays and straight bytes.

When VERIFY, LOAD and MERGE are searching the tape for information with a given name and of a given sort, they print up on the screen the sort and name of all the information they fnid. The sort is shown by 'Program:', 'Number array:', 'Character arrat:' or 'Bytes:'. If name was the empty stringm they take the first lot if information of the right sort, regardless of its name.

SAVE

Saves information on tape under the given name. Error F occurs when name is empty or has 11 or more characters.

SAVE always puts up a messaeg Start tape, then press any key, and waits for a key to be pressed before saving anything.

  1. Program and variables:

    SAVE name LINE line number
    saves the program and variables in such a way that LOAD automatically follows with
    GO TO line number

  2. Bytes:

    SAVE name CODE start, length
    saves length bytes starting at address start.
    SAVE name SCREEN$
    is equivalent to
    SAVE name CODE 16384,6912
    and saves the television picture.

  3. Arrays:

    SAVE name DATA letter()
    or
    SAVE name DATA letter()$
    saves the array whose name is letter or letter$ (this need bear no relation to name).

  4. Verify:

    Checks the information against on tape against the information already in memory. Failure to verify gives error R Tape loading error.

    1. Program and variables:

      VERIFY name

    2. Bytes:

      VERIFY name CODE start,length
      If the bytes name on tape are more than length in number, then gives error R. Otherwise, checks them against those in memory starting at address start.
      VERIFY name CODE start
      checks the bytes name on tape against those in memory starting at the address from which the first cassette byte was saved.
      VERIFY name SCREEN$
      is equivalent to VERIFY name CODE 16384,6912
      but will almost certainly fail to verify.

    3. Arrays:

      VERIFY name DATA letter()
      or
      VERIFY name DATA letter$()
      checks the array name on tape against the array letter or letter$ in memory.

LOAD

Loads new information fron tape, deleting old information from memory.

  1. Program and variables.

    LOAD name
    deletes the old program and variables and loads in program and variables name from cassette; if the program was saved using SAVE name LINE it performs an automatic jump.

    Error 4 Out of memory occurs if there is no room for the new program and variables. In this case the old program and variables are not deleted.

  2. Bytes:

    LOAD name CODE start, length
    If the bytes name from tape are more than length in number then gives error R. Other wise, loads them into memory starting at address start and overwriting whatever was there previously.

    LOAD name CODE start
    loads the bytes name from tape into memory, starting at address start and overwriting whatever was there previously.

    LOAD name CODE
    loads the bytes name from tape into memory starting at the address from which the first tape byte was saved and overwriting the bytes that were there in memory before.

  3. Arrays:

    LOAD name DATA letter()
    or

    LOAD name DATA letter$()
    deletes any array called letter or letter$ (as appropriate) and forms a new one from the array stored on cassette.

    Error 4 out of memory occurs if no room for new arrays. Old arrays are not deleted.

MERGE

Loads new information from cassette without deleteing old information from memory.

  1. Program and variables:
    MERGE name
    merges the program name in with the one already in memory, overwriting any program lines or variables in the old program whose line numbers or names conflict with ones in the new program.

    Error 4 Out of memory occurs unless there is enough room in memory for all of the old program and variables and all of the new program and variables being loaded from tape.

  2. Bytes:
    Not possible
  3. Arrays:
    Not possible

Exercises

  1. Make a cassette on which the first program, when loaded, prints a menu ( alist of the other programs on the cassette), asks you to choose a program, and then loads it.
  2. Get the chess piece graphics from Chapter 14, and then type NEW: they will survive this. However, they will not survive having the computer turned off; if you want to keep then, you mst save them on tape, using SAVE with CODE. The easiest way is to save all twenty-one user defined graphics by

    SAVE "chess" CODE USR "a",21*8

    followed by

    VERIFY "chess" CODE

    This is the system of bytes saving that was used for saving the picture. The address of the first byte to be saved is USR "a", the address of the first of the eight bytes that determine the pattern of the first user-defined grpahics, and the number of bytes to be saves is 21*8 - eight bytes for each of 21 grpahics.

    To load back you would normally use LOAD "chess" CODE

    However, if you are loading back into a Spectrum with a different amount of memory, or if you have moved the user-defined graphics to a different address (you have to do this deliberately using more advanced techniques), you hav to be more careful and use

    LOAD "chess" CODE USR "a"

    USR allows for the fact that the graphics must be loaded back to a different address.

[Back] [Contents] [Next]