Classic Computer Magazine Archive COMPUTE! ISSUE 47 / APRIL 1984 / PAGE 170

Super Directory

Michael Contino

"Super Directory" is an invaluable utility which displays the disk directory on the screen and allows you to use the cursor control keys to automatically select, LOAD, and RUN any program. Originally written for 64 and PETs with Upgrade and 4.0 ROM; versions are also included for VIC, Atari, and IBM PC/PCjr.

As much as we might not want to admit it, there are still many people who have had little or no experience with computers. And many of them still harbor a fear of the machines. In writing programs, most of us keep this in mind and attempt to make the programs as friendly as possible. Of course, there is still the problem of getting the program loaded and running.

Since menus are the standard solution for friendly programs, it is natural to write a menu program that will: present the user with the choice of programs; allow for the selection of a program, usually by number; and then load the program. Problems with this approach include the updating of disks every so often and typing all those names into DATA lines.

"Super Directory" solves these problems, providing menu selection using the cursor controls, with an automatic LOAD and RUN of the selected program.

I developed the program on my CBM 8032 with an 8050 disk. However, it also works on PETs with Upgrade and 4.0 BASIC, with any of the three Commodore disk formats, and with the 64.

This program must be the first program on the disk. If you don't know how to do that, simply COPY the first file or program on the disk back to the same disk under another name, and then save this program. Don't forget to then rename the copied file back to its correct name (or do another copy).

Once the program is properly located, a simple <shift RUN> (on the PET) will load and execute the program. If you do not have the 4.0 PET, you will have to LOAD "*",8 and then type RUN for other Commodore machines. The program will read through the entire disk and store all PRG files into an array, skipping all nonprogram files. It then presents a menu in two columns (four on the 8032) of all programs on that disk. The first option is "next page," in case there are more programs than can fit on one page. If this choice is continually taken until there are no more selections, you're offered a choice to go back to the beginning, to access a different disk, or to end the process.

Selection By Cursor

It is in selecting your choice that this menu program is different from most. I have often seen students hesitate for a long time in converting their choice to a number, pressing the correct number, and then pressing RETURN. I have also seen the opposite problem: people moving quickly, watching the screen, and hitting the wrong number. To correct for this in another program, I developed a subroutine which allows for menu selection by control of the cursor keys. When the menu appears, one default choice is highlighted (in RVS reverse print). Pressing the cursor control keys causes the highlight to move up or down, right or left, through the list. I added a wraparound, so that a cursor down from the last item in a column will send the highlight to the top of that column. This provides an almost fool-proof method of input. To make it just about perfect you might want to also disable the STOP key.

I like to refer to this subroutine as a light pen—without the pen. I have used it in many programs, and I encourage you to excerpt the subroutine for use in your programs. After we have looked at the program in some detail, I will explain the initialization steps needed before calling the routine.

Simulated WHILE Loop

Before we look at the details of the program, a word about another interesting feature you may want to use in your programs. In structured programming, WHILE and UNTIL loops are considered very nice. Unfortunately, the FOR/NEXT loop does not quite fill the gap in BASIC. It controls a loop where a variable is counting for a specified number of executions, but it does not work as well when some other condition is meant to control the repetition. We usually settle this problem by adding a line such as: IF condition THEN GOTO line nn. That works, but can lead to an unclosed FOR/NEXT loop, which brings on its own problems. You can simulate the WHILE structure by a line such as

300 FOR I = 0 TO 1 STEP 0

which will count by zeros for a very long time, until it reaches one. The real way out is tested for in the body of the loop. When discovered, simply set I equal to 1. For example,


In this 64 directory, the cursor is on "TINDCAD.VIC". Pressing RETURN will load and run that program.

Getting Around GET

As the program was originally written, the GET statement was used to retrieve the characters of the program names one at a time from the directory sectors of the disk. This made the program rather slow. In a worst case, a Commodore 8050 disk drive containing the maximum 224 programs for that format took almost two minutes to read the directory. I tried writing RETURN characters, CHR$(13), into the directory so that I could use the faster INPUT statement instead. However, this caused funny-looking directories and created problems where there were 13's in the directory that were not RETURNs (such as references to track 13 or sector 13).

I considered storing the directory entries in a sequential file on the disk, and then having my program read the file instead of the directory sectors. This approach would have required an additional program to create the sequential file and to update the file whenever a new program was saved on the disk. In addition to these complications, it seemed unappealing to use up disk space with a file containing information that was already on the disk.

The only other approach in BASIC was to read in the directory sectors and create DATA statements to be added to the Super Directory program, but this again required a second program to generate the DATA statements and update them as new programs were saved to the disk.

Atari "Super Directory" allows you to store descriptions along with the program names.

The only way to achieve a truly significant increase in speed was to read the directory information from the disk with machine language. Fortunately, I did not have to write the machine language program to do this. Jim Butterfield's "String Thing" (COMPUTE!, November 1982) is a machine language (ML) routine which reads information from the disk into a variable. It functions like a very fast INPUT#. I modified the routine to read the entire contents of a disk sector into a string variable (lines 6000–6100). Lines 6000–6010 create a 254 character-long variable called IN$. The ML routine puts data into the first variable in the program, so it's important that IN$ be set up before any other variables are mentioned. Lines 6020–6030 let the program know whether it's operating in a 64 or a PET/CBM, then lines 6040–6060 load the DATA for the modified String Thing, adjusting it as necessary for the particular computer.

The increase in speed using this approach is dramatic. With a typical PET disk, the time required to load the directory was cut from about 45 seconds to only 8 seconds. The worst case (full 8050 disk) time dropped from 2 minutes to less than 15 seconds. Loading times are slightly longer for the 1541 disk used with the 64, due to its serial communications, but the increase in speed provided by the machine language is even more significant.

On To The Directory

First a quick run-through of the program blocks. The first line jumps to line 1000. This is designed as a time-saver, allowing room at the top for frequently used subroutines. It also mimics the Pascal requirement that all routines and procedures be defined before the body of the program. The most common routine, lines 1 and 2, is the get-character routine. Disk error check, lines 10–20, is next and uses the error channel, not DS$, in order to be compatible with earlier versions.

The main video selector (or penless light) starts at line 100. It in turn calls supportive routines at line 500 and line 600. Before this can be used, the clear display routine at line 900 is called by the main program.

Two other routines are called only once and they have been placed after the program body, to help with readability. The routine at line 2000 reads the disk header and determines the type of disk being used. It then goes to the beginning of the directory and reads the program names into an array. If you have an 8050 disk drive, you'll need to replace the following lines:

2040 FO=ASC (IN$):IF (FO AND 3)=3 THEN 2100
2100 HE$=MID$ (IN$, 5, 16)+", 8050 FORMAT"
2110 SYS 896:SYS 896
2120 SE=28

Line 2900 allows you to define the disk drive to be used. This defaults to drive 0, unit 8. If you delete line 2910, lines 2920–2940 will then allow you to select the device and drive number each time the program is run.

The program has two possible outcomes, and thus concludes in the sections beginning at either line 3000 or line 5000. If the search was unsuccessful, lines 3000–3050 give the options of restarting the current disk (the directory does not have to be read again from disk, as the array with program names has not been disturbed); of starting over with a new disk; or of quitting the search. A successful search takes us to line 5000, which loads and runs the chosen program via the dynamic keyboard method.

Super Directory For Atari

Charles Brannon, Program Editor

"Super Directory" is an easy-to-use menu program for selecting and running BASIC programs from disk. In addition, it alleviates the limitations of Atari's eight-character filename by storing a 20-character description of each filename.

Type in Program 3 and SAVE a copy of Super Directory on every disk you want to use it with (you may want to call it MENU). You can change line 107 to name your disk. This name will appear at the top of the menu program when RUN.

When you first RUN Super Directory, it will read in the disk directory and display it on the screen. A large, wide cursor will be resting on top of the first filename in the directory. You can move the cursor up or down with the arrow keys, but you do not have to hold down CTRL. You can also use a joystick to move the cursor up or down.

If the directory will not fit on one screen, it will scroll upward as you push the cursor "past" the bottom of the screen. You can also scroll the screen down when the cursor is at the top of the screen. Press any key to select the file, or use the joystick trigger button.

You will switch to another screen, where you are given three choices: press START to RUN the program, press SELECT to change the description, and OPTION to save the descriptions. You can also press RETURN to skip these choices and return to the menu.

Making Sense Of Filenames

You probably noticed that the second column on the screen said "no description" for all the filenames. This is because you haven't entered any yet. If you press SELECT while you are on the other screen, you can enter a description, up to 20 characters. You can enter anything you want here that will help you make sense of filenames like ASKRD.TXT, WMAKER, HAWKMEN, or EASMD.COM.

The description file is saved to the disk under the filename DESCR.DIR. If you delete it, your descriptions are gone. Every time you RUN Super Directory, it will match up each description with each directory entry. If you move a file around on the directory, it will still be matched up with the proper description. Super Directory also has to skip over descriptions that once applied to deleted files. This correlation process takes a few seconds before the menu first appears.

Verify Your Update

You can press OPTION on the second screen to insure that the description file is updated after you change it. It will also be automatically written out if you press START to run a program.

There are some files, like DOS.SYS, that you cannot run, obviously. Super Directory only lets you run BASIC programs that have been SAVEd (not LISTed) to disk. If you try to run any other kind of file, or if there is some kind of disk error, Super Directory will so inform you, then reRUN itself.

Thanks to the description file, Super Directory is more than a mere menu program. It can help you catalog your disks, and get around the eight-character filename limitation.

IBM Notes: Super Directory

Charles Brannon, Program Editor

To use Super Directory, you'll need an IBM PC with at least 64K, and either a monochrome or color adaptor. Super Directory will also work on the Expanded PCjr with Cartridge BASIC.

If you're not a programmer, you may find working with your PC to be a bit perplexing at times. You turn on your system, wait 45 seconds, face the cryptic A> prompt, enter BASIC, then RUN "filename" to start a BASIC program. It would be much easier if you had a list of all the programs and could run any one by just pressing a function key.

Super Directory is your solution. When you RUN it, it will give you a list of all the files on your disk. To run any displayed program, press the appropriate function key, then press the enter key (designated with a crooked arrow). Super Directory only displays ten files at a time. If there are more than ten files, you can press Pg Dn (the number 3 on the numeric keypad, if you have NUMLOCK on) to go on to the next page. You can also page backwards with Pg Up.

There's more to Super Directory, though. The 11-character filename length offered by PC-DOS does not allow very descriptive names for your files. How can you make sense of names like QTESTV1.BAS? Using Super Directory, you can label each filename with a 61 character description. Super Directory keeps the description with the filename, and displays it every time you go back to Super Directory.

To enter a description, press the appropriate function key for the file you wish to describe, then press the SPACE bar. The last line of the screen will always tell you what to do. The first time you try to describe a file, you will be asked for the disk name. Once you've entered a descriptive name for the disk, Super Directory remembers it and will no longer ask you for it. You can then enter or edit the description.

After you enter a description, the screen will be re-drawn, and you will be able to see the description you've given to a file name. If you go back to redo a description, it will be displayed. You can type over it, or move the cursor to edit the description. Remember to put the cursor at the end of the line when you are through editing (you can use the END key to skip to the end of the line).

When you run a program from the menu, the descriptions will be written to disk first. If you just want to write out the descriptions without running a program, you can press ESC from the main menu. You will see the line:

1. Exit to BASIC 2. Exit to DOS 3. Re-Run 4. Save Descriptions 5. Menu

Press 4 to save the descriptions to disk. The descriptions will be saved to disk under the filename "DESCR.DIR". Don't DELete this or you will lose your descriptions. You can also use the other options to return to BASIC, DOS, or re-RUN Super Directory. Pressing 5 will take you back to the main menu (if you pressed ESC by mistake, say).

Super Directory will detect errors and prompts you to press ENTER. You'll usually be returned to the main menu. Don't try to run a program which is not BASIC, however. You'll probably get the message "Direct Statement in File" and find that Super Directory has disappeared.

You can make Super Directory completely automatic. If you don't have BASIC on your disk, you can use COPY from DOS. Then enter this one line command to have BASIC and Super Directory come up automatically when you turn on your PC:


This assumes that you've saved Super Directory to the same disk with the command SAVE "SUPERDIR". Super Directory will normally ask you which drive you want to list from. If you only have one drive, or want to always look at drive A:, remove the keyword REM from line 160. Leave the rest of the line in place. Now you can add a flexible, easy to use menu to any disk. Super Directory makes it easy enough for a child to use!