Apple Mash

By Mike Thyng

In the previous articles, we’ve discussed types of files – sequential and random – and general facts and figures about the PERSCI floppy disk drive. This issue I’d like to explore some of the actual commands necessary to get data to and from the diskettes.

Before you can write a file, you have to do something called “opening” it.  This defines to your program that some related data – let’s say names and addresses – is going to be available for your use and can be referenced by the name you give your file. If you want to access (either read or write) to your file you need to specify OPEN AFILE. (AFILE is the name I gave a file for example).

What if you want to write a whole new file that hasn’t existed in your system before. Fine, use the FILE statement. FILE BFILE opens a file called BFILE and makes it available to you to write sequential data.

FILE BFILE(130) opens a file called BFILE that hasn’t previously existed also. But the difference is that each record you write will be allowed to be a maximum size of 130 bytes. You would use the FILE BFILE(130) format whenever you wanted to deal with random files.

Personally I use the random file format exclusively. It gives me greater flexibility for file handling. You can always read a random file sequentially but the reverse isn’t true. So now we’ve gotten into 2 files; AFILE we’ll use for gaining previously stored information, and BFILE we’ll use to write new information.

To get the information from AFILE, you need to READ# 1; field 1, field 2, field 3 The READ is comparable to The READ command is to a disk (or tape) file what the INPUT command is to the keyboard. The #1 is a direct reference to AFILE – the first file opened. Fields 1, 2, and so on are the variables you output to AFILE when you wrote it.

To output data to BFILE we will do something a bit more familiar. PRINT #2, 14; field 1, field 2, field 3 …. The PRINT portion of this command works the same as for output to your CRT. The 112 means you are referencing BFILE – which was the second file you opened. 14 refers to the fourteenth record on the random file BFILE. Fields 1, 2, and 3 are the same as for AFILE.

Later in your program close to the end you must CLOSE files AFILE and BFILE. Why? To keep the data. Writing to and reading from disk files means you must get used to a discipline known as file handling. Errors in file handling can cost you a bundle in effort to recover lost files. If you’ve written data to a file but not closed the file when you’re through with it, you might lose all the data that you stored. I can’t say always because sometimes the operating system gives you a break. CLOSE 1, 2 will close AFILE and BFILE.

Not closing a file is like putting marbles in a box without a bottom. When you try to use it, your data isn’t where you can easily get to it.

Next time, some preliminary comments about the APPLE II disk.

Please follow and like us:

About the Author


A.P.P.L.E. Chairman of the Board and Club president — Bill worked for the founder, Val J. Golding and A.P.P.L.E. from 1981 to 1982. In 1999, he began archiving the materials which were distributed and sold by A.P.P.L.E.. That project led to the group that remained of A.P.P.L.E. Bill was involved in the financial industry in Tokyo and has over 20 major office infrastructure projects to his name. In March 2001, he retired to write books and to spend more time pursuing personal interests. As the president of the users group, Bill is in charge of distribution of Call-A.P.P.L.E. magazine as well as the organization of this web site. Bill currently resides in Tokyo, Japan and Shelton, Wa splitting time between the places.