CHAPTER 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tape storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SummaryLOAD, SAVE, VERIFY, MERGEThe 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 in the '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 survived (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 couple 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 arrays on 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 and 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 address where the first byte is to be loaded back to - thus can be different from 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. SAVESaves 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.
VERIFY
LOADLoads new information fron tape, deleting old information from memory.
MERGELoads new information from cassette without deleteing old information from memory.
Exercises
|