Access Key Details
Previous Page || Next Page

Book index page

CHAPTER FIVE: FILE PROCESSING

PROGRAMS are saved to tape using SAVE CS1, and loaded back into the computer with OLD CS1 (if you are using a tape recorder).

See also previous chapter on Cassette use and using Emulators. There is a shortage of text on using disk files, due to the small number of disk systems sold.

The values of the program variables are not saved with the program, and will initially have a value of zero when the program is loaded.

If you wish to save a high score, or other data, you must use file processing operations as described below.

Tape files can take a few minutes to load, but form an inexpensive introduction for the novice programmer to the field of data management. Fortunately, TI have provided a fairly simple operating system.

Before you can save or load data, you must 'open a file'. This operation describes to the computer the format of the data on your tape, and allows you to refer to the tape by a simple label, called the file number.

When the computer comes to an OPEN statement, a section of tape is wound on, with no signal. This is to clear any leader on the tape. You will find it easier if you always start your data files at the beginning of the tape, then you can be sure the computer will find the data where it expects to.

A cassette file may be to load data or to save it, and this is defined in the opening statement. The usual cassette operation instructions are given when the OPEN statement is operated on. Please keep this in mind and ensure that you do not open a file after a complex screen display has been created!

If your printer prints a pound sign below, it means hash.CHR(35).

The OPEN statement is in the form:
OPEN #N:"CS1",INTERNAL or DISPLAY,INPUT or OUTPUT,FIXED NUM

The number N must be a number and not a variable, and lie between 1 and 255. It is possible to have several files open at once (eg to CS2, a printer, the speech synthesiser if using Terminal Emulator 2 module & so on), and the file number is used to instruct the computer which peripheral it is to use.

The choice between INTERNAL and DISPLAY is one of coding : in DISPLAY format, the computer data is recoded to printable ASCI code. DISPLAY format can sometimes be of advantage in DISK processing when greater speed is sometimes possible, but for TAPE files, it uses more tape and also requires more complex program writing.

Using TAPE files, use the INTERNAL format.

File organisation with tape files is always SEQUENTIAL and this word is not required in the opening statement. This means that the second item of data read from the tape is the second item of data which has been recorded on the tape. It is not possible to 'skip' to say the 6th item of data without reading everything in between.

As mentioned, you MUST indicate if the file is for INPUT or OUTPUT. You use INPUT to read data from a tape, and OUTPUT to place data onto the tape.

You should only have one file open to CS1 at a time, otherwise the computer will lose track of the data on the tape.

FIXED means that every time the computer writes data to the tape, the same amount of tape is used no matter how long the data. Any unused tape is filled with nuls. If no number follows the word FIXED, the data field is 64 bytes long. A number always occupies 9 bytes, and a string one byte more than the string has characters.

To save data once the file has been opened, you use the PRINT command, but add the file identification: PRINT #1: (If your printer printed a pound one it means CHR(35) then 1.)

There is ALWAYS a colon (:) after the file number.

To save a single variable value, you would use: PRINT #1:A

To make the most of the 64 byte field length, you may save 7 variables at once, each separated in the PRINT statement by a semi colon:
PRINT #1:A;B;C;D;E;F;G

Strings are saved in a similar way:
PRINT #1:A$;B$
or
PRINT #1:"THIS STRING IS TO BE SAVED"

If the standard field length of 64 bytes is too short, you may specify one of two alternative field lengths, 128 or 192. You do this by placing these numbers after the word FIXED (with a space beween).

When you have finished saving data to the tape, remember to close the file with eg CLOSE #1
This will generate the message "PRESS CASSETTE STOP & PRESS ENTER", so as before ensure that there is no screen display to be disrupted.

When the computer is saving data, it does so one field at a time, amd it is essential the computer has control of the cassette motor. If your remote control does not function, fit the polarity reverser (provided with the TI Tape Cable) between the remote socket on your tape recorder (the small one: 2.5mm) and the small jack plug on the lead from the computer. If you have purchased a third party lead and require the polarity reversing, you should ask your supplier to do so. It is possible to swop the wires yourself, but with some systems there may be problems as the screening may be broken.

To load your saved data, you must reopen the file, this time specified as an INPUT file. If you used long field lengths when saving the data, you MUST specify the same length in the OPEN statement to load the data. Similarly if a file is saved in INTERNAL format, you MUST read it in the same format.

If you have placed several values in one field, you must read them in the same way- if you have used:
PRINT #1:A;B;C;D
then you MUST read four NUMERIC variables,although the names may differ:
INPUT #1:Z;X;R;T

If a numeric variable has been saved, you must read a numeric variable. A field containing string data must be input to a string variable.

Your tape files contain the values of the variables printed to them (or direct numbers or strings). The variable name is not saved, and the variable is not affected by saving its value.

Have a look at the file management program in Vince Apps book of Programs for the 99/4A for an example of using tape files.

Remember to CLOSE the file when you have finished with it.

Tape files can occupy large amounts of tape, and if you are saving a large number of items, you will need at least a C15 or C20 tape.

Retreiving the data that has been saved -

You may find that you need to slightly alter the volume level on your tape recorder to load data files correctly. It IS possible to load corrupted data if the volume is slightly incorrect, and this may result in your program 'crashing' with an error message such as 'BAD VALUE' which is not immediately caused by an incorrect volume setting.

NOTE: EOF is not available for tape files.

Typical routines to SAVE and LOAD high scores for a game:

TO SAVE a high score, which is in a variable called HISCORE

100 REM DO NOT OVERRECORD YO
UR PROGRAM
110 REM ONLY RECORD DATA ON 
BLANK TAPE
120 OPEN #1:"CS1",INTERNAL,O
UTPUT,FIXED
130 PRINT #1:HISCORE
140 CLOSE #1
TO LOAD this data back into the program:
200 REM TAPE MUST BE IN SAME
 POSITION
210 REM AS AT START OF ABOVE
 SAVE ROUTINE
220 OPEN #1:"CS1",INTERNAL,I
NPUT,FIXED
230 INPUT #1:HISCORE
240 CLOSE #1
             

If you graduate on to DISK BASED filing, the 99/4A offers many more options, to give you greater control and access. This includes variable length files for better use of disk space, update mode which allows you to read and write to a single open file, and relative files which allow you to read or write to a specific record within the file. The disk system also allows the use of named files, and of course greater speed.

If you insert the Mini Memory module, this has an internal battery (which may need replacing) and you are able to store data onto the module to move it easily from one console to another. If you are using a TI99/4a emulator, choose the Mini Memory module, THEN SELECT TI BASIC and the following will apply also:

You may use the MINI MEMORY MODULE as a file storage device.It is treated in a similar way to disk files except that only one file can be saved to the module, called "MINIMEM". For minimem or disk, if you use FIXED with no number, the file is padded to 80 bytes length.

For Minimem operation,your opening line may be as short as:
OPEN #1:"MINIMEM"
The file is assumed by the computer to be
FIXED 80,SEQUENTIAL,DISPLAY (care!),UPDATE.
Any of these assumptions (or defaults) can be altered by adding the definition you want to the OPEN statement. Minimem will retain its data files provided you switch the console off before inserting and removing the module and do not use it for anything else. Minimem also permits the memory expansion to be used for data storage (see Mini Memory Manual) but this data is lost when you disconnect the power.


Some TI Modules save data to tape in 'program format', using the normal SAVE CS1 and OLD CS1 routines. The advantage of this is that the data does not occupy so much tape, takes less time to load, and it is possible to use the CHECK option to verify the data is saved correctly.

It is possible for 99/4a owners to save and read their own data in this format if the Personal Record Keeping or Statistics modules were in the module slot.

These two modules add several new subprograms when TI BASIC is selected, but as this is not advertised may be amended in future. Their use is fairly technical, as memory has to be reserved by the programmer and is not covered here.

THE INFORMATION IN THIS BOOK IS FREE. It may be copied, distributed and/or modified under the conditions set down in the Design Science License published by Michael Stutz at http://dsl.org/copyleft/dsl.txt

Book index page
Access Key Details
Stephen's Entry Page | TI99/4a |Linux |Search | History St Thomas Church Heaton Chapel | Entertainment | Music Links
Light Reference | Educational Reference | Science Fiction | Travel | News Links | Anime


Note 1: AddFreeStats will try to set a cookie when this page is loaded. The cookie relates to "*.addfreestats.com/" only and records that your IP address looked at this page, for purposes of tracking re-visits. . The cookie can be safely refused without imparing your web enjoyment. At present I cannot locate a relevant privacy policy on their site. How to manage and delete cookies
Note 2: If you click this link to AddFreeStats you will need to have javascript enabled to use their website. Otherwise you will see a blank page! Again, their foolishness will not interfere with your enjoyment of THIS web site!