Classic Computer Magazine Archive COMPUTE! ISSUE 34 / MARCH 1983 / PAGE 168

Part I:
COLOR COMPUTER GENERAL PURPOSE DATA BASE

Jeffrey S. Yohay

For TRS-80 Color Computer, this tutorial can serve as a model for creating a data base manager. Among the most useful of computer applications, data bases can manipulate and process lists, catalogs, and thousands of other kinds of information. This article concludes next month with a discussion of screen displays, program structure, and the data base program itself.

As a personal information manager, the TRS-80 Color Computer is often overlooked in favor of its more expensive counterparts. This may be because of the machine's somewhat cramped screen format or its calculator-like keyboard.

Whatever the reason, it is a serious mistake to relegate the Color Computer to a back seat in information handling. This is because the Color Computer offers as standard equipment a fast and reliable cassette tape storage system with many disk-like features for data storage. This allows even the lowest priced Color Computer to store and retrieve personal data quickly and efficiently — an important consideration in a machine that is likely to be purchased by computer novices who won't be starting right away with a disk drive.

Using the TRS-80 Color Computer's powerful cassette system, this program is a model for a personal information management system. It is called the "Videotape Movie Data Base Program" (VMDP), because it was designed to catalog and manage a collection of movies on videotape. While the VMDP is designed around the Color Computer's powerful cassette storage format, it also makes good use of the limited 16 line × 32 character text screen to display a great deal of information about the cataloged movies. The program is written in Extended Color BASIC and requires at least 16K of RAM.

As more and more video enthusiasts are discovering, the TRS-80 Color Computer is a good microcomputer to include as part of a home video system. It is easily connected to any television or videorecorder, and it combines all the features of a ROM-based video game system and a powerful microcomputer system. The high-resolution color graphics can be used to produce spectacular video displays for games and simulations. Those same graphics, combined with the Color Computer's innovative cassette-to-television audio channel, can be used for numerous educational applications. And the CPU itself, the Motorola 6809, is a powerful one that can support many applications.

How The VMDP Can Help

Let's take a look at a typical video enthusiast's collection of movies on videotape. Chances are that the joy of possessing a recording of some rare old movie will quickly fade the first time the intrepid video buff goes to find the recording and can't! Scribbled labels, out-of-order index cards, and frazzled nerves are typical of a videotape cataloging system. Yet those video hobbyists who are organized enough to develop an accurate and useful catalog of their videotapes can find themselves spending as much time on the record-keeping as on the collecting.

The VMDP offers a cure to these ills. For each movie in your collection, the VMDP will allow you to store:

  1. The title.
  2. The year of release.
  3. The type of movie (comedy, mystery, etc.).
  4. The name of the director.
  5. The names of up to three actors/actresses.
  6. The videotape you recorded it on.
  7. The location on videotape by VCR counter number.
  8. The recording speed.
  9. The approximate viewing time.
  10. The time remaining on the videotape.
  11. The date you recorded it.
  12. The channel you recorded it from.
  13. Whether the movie is in color or black-and-white.
  14. Whether you recorded it with or without commercials.

Once you've cataloged your movies, the VMDP will let you:

  1. Display all data for any movie or movies.
  2. Display all movies by title and type.
  3. Search for and display data for a particular movie.
  4. Print all movie data or only title and type.
  5. Enter data for a new movie.
  6. Delete data for an existing movie.
  7. Sort the movie data by title, type, or videotape number.

Using the VMDP, your Color Computer can organize even the most haphazard collection of videotape movies and let you choose the movie you're in the mood to see, when you're in the mood to see it. Feel a little low? Just have the VMDP sort your movie collection by type, and pick out a good comedy. Or let the VMDP search through your collection for that particular movie you haven't seen in months. Finding entertainment to suit your mood couldn't be easier.

Data Storage Concepts

The most important consideration in the design of the VMDP was the Color Computer's cassette tape storage system. Before I tell you how I decided on the VMDP's tape data storage format, let's take a look at how this cassette system works.

For those of you who are new to data storage concepts, let me first define a few terms. Data is stored on a magnetic device (cassette tape or floppy disk) in groups of related information called "files." Files themselves are collections of related data items called "records," which are usually the smallest units of data read or written to a cassette tape or disk at one time. Within each record, the data is further organized into "fields." This is done so that once you read the record from the tape or disk into the computer, you'll know where to find any particular subset of data that you're looking for.

If all you want from the record is the title of the movie being described, knowing the location of the field containing the title makes it easy to find. Remember, too, that though the computer handles the storage of records and files, the storage of the data within the records is completely up to you. So it's a good idea to do what the computer does, and organize your data fields so you'll always know how to get your data back quickly and easily.

Files can be stored by the computer in two different ways: sequential-access or random-access files. For tape storage, however, we can use only sequential-access files. These have to be read or saved one record after another; thus, you can reach a record in the middle of a file only by reading in all the records that come before it. Random-access files have records that can be read or saved no matter where they are in the file, but that can only be done if you have a disk.

The biggest advantage of random-access is that you don't have to read an entire file into memory before you start extracting the information you want from it. Just read in the records that you want and get the data out of the fields in those records. Of course, you could do that with sequential-access files, but you'd have to go through the entire file every time you wanted a particular group of records. For cassette files, that would be too slow to be practical.

The Color Computer Cassette

The Color Computer's cassette tape system has many improvements over those of earlier TRS-80 models. The most important of these improvements is the speed at which programs and data are saved on tape: 1500 baud (bits per second), or about 11,000 characters per minute. There are also many disk-like features; one of these is the use of a file structure for all data stored on cassette. Instead of simply PRINTing data to cassette directly from a variable as in the Model I/III, the Color Computer opens a file on tape, stores the data, then closes the file when you're done. This is the same way sequential-access data files are stored on disk.

Central to this data file storage method is the use of "buffers." A file buffer is an area of RAM memory reserved for data that is to be read from, or written to, cassette. When you want to read or write cassette data, you use the Color Computer's OPEN command to initialize a file buffer in memory. This buffer is used to hold cassette data during cassette I/O operations.

When you have data to save on tape, the buffer is filled before the data is written to tape, keeping data transfer time to a minimum since the tape doesn't have to be moved for every variable value that your program tells the computer to save. This also enables data to be stored on tape very efficiently, since the computer "saves it up" until it can write one buffer's worth of data to tape. Similar use is made of the file buffer when loading data (i.e., assigning tape data to a variable) to minimize tape movement and data transfer time.

Using the OPEN command when saving data also causes BASIC to write a block of data onto tape called the "NAMEFILE" block. (These block names and descriptions are all from the Radio Shack TRS-80 Color Computer Technical Reference Manual. ) The NAMEFILE block consists of 15 bytes of BASIC-generated data that describe your data file in several ways, including the name of the file and how it is recorded.

OPENing a data file to load data tells BASIC to read this NAMEFILE block to see if this is the data file you wanted; if not, the cassette will be searched until the file you wanted is found. This lets you store several independent data files (perhaps collections of movies by certain directors or with certain actors/actresses) on the same tape.

Similarly, use of the CLOSE command tells BASIC to delete the file buffer and write an "END-OF-FILE" block to tape. When reading in the data file, BASIC can then use the END-OF-FILE block to tell when it has reached the end of your data file. The EOF(-1) function will be "true" (equal to -1) if the END-OF-FILE block has been reached; use it when loading a data file to check whether all of the data you wanted has been read in from tape.

In between the NAMEFILE and END-OF-FILE blocks are your actual data. These are stored in "DATA" blocks that both describe the data and contain up to 255 bytes of the data itself.

Building Your Data Base

Using my knowledge of the Color Computer cassette system, I decided to store the data for each movie in 127-byte records. This would allow my movie data to make the best use of the 255-byte tape data blocks, and would make it simple for BASIC to read and write data to and from the tape buffer and the tape itself. And, since Color Disk BASIC stores data on disk in multiples of 256 bytes, I would get the added benefit of movie data that could be easily adapted to a random-access disk system in the future.

Once I had chosen the 127-byte length for the movie records, I decided that this would be the record size no matter how few bytes were actually required to describe a particular movie. This "fixed length" record format has a big advantage over "variable length" records (where each record is only as long as required to describe each movie adequately).

Though it takes more tape to store a file with records that may be filled with a lot of blanks, a fixed record length insures that the locations of all movie data within a record (the fields) are the same in every record. This makes it easy to get the data for displaying, printing, and sorting. And no matter what the future brings (e.g., a disk drive!), my videotape data would be consistent and easily accessed by any program on cassette or disk.

I then had to decide how to place the movie data within the record. From experience with a pencil-and-paper system, I knew what information I wanted to have for each movie, and I could see that I would need 17 individual fields within each record to store this information. So, after deciding on the size of each field and its location within the record, I came up with the record format illustrated in Table 1 next month.

I chose the size of each field so that each was just large enough for the data it was to contain, but not so large that it would be filled with blanks most of the time (because of the fixed record length). This was particularly important for the director and actor/actress fields, where the names could vary widely in length. Since my favorite director's name (Alfred Hitchcock) is 16 characters long, I thought that would be a good length to start with. As it turned out, that length was ideal, and left more than enough bytes for the rest of the data, with two bytes left over for future use (they're filled with a slash "/" for now). Note that some fields had to be only long enough for a one-byte or two-byte code that the VMDP can recognize and expand into usable information.

There was a method to my madness in the ordering of the fields within the record, too. If you BREAK the program after loading data and then PRINT some values from the movie record array R$, each 127-byte record will fit neatly on four of the Color Computer's 32-character screen lines. The title and year will be on the first line, the director and actors/actresses will be on the second and third lines, and the remaining information will be on the fourth line, separated for easier readability by the slashes I placed in the "future use" fields. This bit of clever record formatting makes it easy to check the contents of any movie record in the R$ array.

However, my real purpose in organizing the records to fit neatly onto the Color Computer screen was to make it easier to enter data into the R$ array directly. This can be a real boon to those who already have large videotape movie collections who want a fast way to enter numerous movie records into the VMDP without repeatedly running the "add record" routine.

For example, if N is the number of movie records, then just set R$(N +1) equal to the four lines of movie data to enter a new record into the movie array directly (a good screen editor, such as Datasoft's S.E.C.S., makes this a lot easier). Do this in "command mode" (i.e., without a line number), and then restart the program with "GOTO 50" to avoid the CLEAR statement in line 40. (Note that because a RUN statement contains its own CLEAR, you must use a GOTO when you want to restart the program with your data intact.)