Classic Computer Magazine Archive ANTIC VOL. 2, NO. 1 / APRIL 1983

PILOT YOUR ATARI

Auto Pilot

by Ken Harms

In our grand tradition, we again present you avid Pilots with something from the wide blue yonder-a previously unreported program to make your flights of fancy easier. Our Auto Pilot is a self-loading menu program that you can put on every Pilot disk. It is so easy to use, even young children can do it-in fact, that's why I designed it and they like the animated face that tells them what to do. Nevertheless, the menu is sophisticated and makes use of previously unpublished aspects of Pilot that allow it to call other programs from itself.

With Auto Pilot on your disk, powering up the ATARI automatically loads a short program which draws a face and animates its mouth to form the words "Please wait half a minute." That program loads another program which displays the menu (the first 20 files on the disk, each with a "program number") and animates the mouth to ask "Please type number for the program you wish to run." When the number, followed by a [RETURN], is entered, the chosen program is automatically loaded and run. When the operator wishes to change programs, [SYSTEM RESET] restarts the menu programs.

The system requires no changes to your existing Pilot programs. If the three files we will create are on the disk, they will run any Pilot programs automatically. After you've built the three files, using this article, a process which should take only an hour or two, you merely copy them using DOS option O to any disks you wish, which takes only a few minutes.

Every Pilot Your Atari tries to present a tutorial in the form of useful programs. This article demonstrates the*Pilot variable table and the use of one program to LOAD and RUN another. Tape users could find these concepts useful but won't be able to use the system. (Although it isn't possible to make an efficient tape-based menu system, the Pilot Primer presents one which you may try.)

Start with an empty, formatted disk. The first program is PUTTER. Power up under BASIC and enter PUTTER. SAVE the program under the name PUTTER and RUN it to produce an AUTORUN.SYS file on the new disk. If the number check doesn't check, examine your typing and redo. Finally, test the AUTORUN.SYS program by powering off and on. You should hear DOS booting and then see several valid Pilot commands displayed with error messages. That's okay since you have the BASIC cartridge loaded and it won't recognize Pilot commands.

So far, we've typed in a program called PUTTER which runs under BASIC to produce a "binary file" under the name AUTORUN.SYS. A binary file is a string of numbers which the ATARI will read as an Assembly Language program. Since the program is in the name AUTORUN.SYS, it will be read and executed each time the computer i5 powered up (see DOS manual for more information). Part of this Assembly Language program fools the ATARI into accepting data from the disk as if they came from the keyboard, and attempting to execute them under direction from the cartridge. This program includes five Pilot commands. You saw them when you tested it under BASIC. First, a one is C:omputed into position 580. That tells the ATARI to reboot DOS whenever the RESET button is pushed. Next, the screen colors are changed to turn the borders red and the letters to blue so that the "Ready" prompt won't display while the menu programs are being loaded. Last, two instructions load a program called MENU.SYS and run it.

The AUTORUN.SYS program will load any Pilot program which has been saved in a file called MENU.SYS. You can SAVE your favorite program under that name and it will load and execute whenever the ATARI is booted or RESET is pushed. Be sure to add a GR:QUIT or other GR:aphic call to the front of your program to reset the screen colors.

On to the next task. Pull out the BASIC cartridge and insert PILOT. When you turn power back on you'll get an error 170 since the computer was looking for a file called MENU.SYS and, naturally, didn't find it. Type in the MENU.SYS program. When you get to the FACE and later modules, you'll see some T:ype lines with graphics characters exactly as they appear in the listing, so that the face will appear on the screen as it will appear when the program runs. Now SAVE the program in a file called MENU.SYS. RUN the program to see if it draws a face and moves the mouth. If everything works right it'll fail with an error 170 since it looks for a file called DIRECT.SYS which you haven't typed yet.

MENU.SYS includes some interesting commands. Lines 60 and 70 are "C:ompute at byte" instructions. The number following the "B" is an "address" of a character (or "byte") of memory. The ATARI uses values in certain addresses to control features of the system. The address 752 turns the cursor off (1) or on (0) . Location 709 controls the color of text characters. These commands are used later (see lines 2120 & 2130) to control the cursor position.

The next interesting command is the LOAD D:DIRECT. SYS at line 200. When you give a LOAD command from the keyboard, it loads the new program over the old. You then have to type RUN. When a program issues a LOAD command, however, Pilot first NEWs memory, then LOADs the program and proceeds to RUN it. Neat! (At this time, there appears to be no way to overlay programs- aarrgh! )

'Nuff said about MENU.SYS. Except that you should also issue a SAVE D:FACE,1480,2210 command to save the routines which you'd have to type later when you enter DIRECT.SYS.

Onward! We're ready to enter DIRECT.SYS. Type it in (remembering to enter the control characters in line 280) up to line 1480. LOAD the FACE file to get lines 1480 through 2210 into DIRECT.SYS. Last, type lines 2220 through 2410 (remember control characters in line 2360). SAVE everything in a file called DIRECT.SYS. You can RUN this program to test it and see an animated mouth without a face (the face will be drawn by MENU.SYS). You should see a directory list down the right side of the screen.

Before we get into the details of DIRECT.SYS, let me explain a few design considerations. The whole system is designed to fit the non-typing, limitedreading user. Accordingly, I chose to turn on the red borders to keep interest up. The face is drawn in one program and the list in a second so that the first program will be very short and will load quickly. (If you want a single program, LOAD MENU.SYS then DIRECT.SYS. I numbered the two so that DIRECT.SYS will overlay and erase the unneeded commands in MENU.SYS. Although this will save a few seconds as you transfer files to a new disk, you'll wait a looong time before you see the list. ) The list will include the first 20 files which don't end in the letters "SYS_". I skip those files since one almost never RUNs them. This keeps unneeded information off the screen.

I chose to present the 20 files and a face rather than more files to make things easy and friendly. The face is a warm welcome to our friends who may still be a little intimidated by the computer. And if you try, you can almost always get the really important files into the first 20. Yes, one could scroll the screen to see more. It's a feature which would be nice for more experienced users but which may not be so easy for the new guys. If you add one, let me know. Last, the dot between a file name and its extender is omitted so that you can use all 11 letters to make more useful program titles.

Frankly, friends, Pilot is not a good language for menu systems. There is no way to directly manipulate individual characters in a string without adding unwanted spaces, spaces which cannot be included in file names. The 65 lines of code starting at line 800 can be done in about 10 lines in BASIC. (After saying this, some 10-year-old whiz will find a 3-line method next week!)

DIRECT.SYS starts off in tINITIALIZATION by specifying that the variable $FILENAME is filled with 15 characters. This variable must be defined before all others so that it is the first variable in the list of variables kept by Pilot. In essence, Pilot stores all variables in special memory locations beginning at an address which is stored in the "word" located at 178. To Pilot, a word is two adjacent memory cells. It interprets these by multiplying the second value by 256 and then adding the first number. This allows the ATARI to talk to up to 64,000 memory locations. Line 2270 sets the variable #P (pointer) equal to the start of string space.

Each string is stored in the following format:

First 2 bytes  Length of the variable
Next 1 byte    Length of the variable name
Next x bytes   The variable name itself
Next 1 byte    Length of the data
Next y bytes   The data itself

After C:omputing $FILENAME in line 2240, we should find that the address pointed to by word 178 has a value of 27 (the length of the entire item) made up as follows:

ADDRESS ABOVE 178     VALUE
0 - Length of item    27
1 - Length of item    00
2 - Length of name    08
2-10 Name             FILENAME
11- Length of data    15
12-27 Data            DUMMYSPACESTO15

We're going to manipulate the value of the "length of data" byte to fool Pilot into believing that there are only 13 spaces in the variable. This will cut off the "sectors used" data for each file so that the list is a bit neater. Line 2280, then, adds nine to #P to move that value to the length of data pointer. (I know that the table above says to move 11 bytes to #P. The nine works-perhaps the first variable in the table is pointed to somewhat differently?) Its work done, *INITIALIZATION returns to the main program.

Line 270 sets Auxiliary 1 byte to the value of two meaning "open the disk to read the file directory" (Auxiliary 1 is the equivalent to "aexpl" in the OPEN command described in the DOS Reference Manual). We then begin reading file names. The READ command will send a formatted file name with eight characters (or blanks), three characters (or blanks) for the extender, and three numbers for the number of sectors, into the variable $FILENAME. By A:ccepting $FILENAME, we can search for "FREE SECTORS", always the last entry in the directory, and for "SYS_" (lines 360 & 380). We J:ump to *FINI or to the loop, as appropriate, to skip the "SYS" items. This means that you can't end a file name in "SYS" (such as MYSYS.ONE) and still get it to show on the menu.

After we've found a good filename, line 420 does the magic. By C:omputing the data length byte to equal 13, we cut off the number-of-sectors data in positions 14, 15 and 16 and leave a formatted variable ready for T:yping in line 430 or 440. The extra blank between "#F" and " = " in line 430 compensates for the extra digit in file numbers greater than nine. Be sure to enter the control V before the #F and the control B after $FILENAME; they'll make a nice box around your list.

After getting your file number, DIRECT.SYS proceeds to read all the files again, skipping SYS files, to count to the number you requested. And the fun begins in *RUNNER at line 920. Basically, our problem is to insert a dot (period) between the file name and its extender, add the"D:" drive designation and then remove all blanks. This is a bear! First, we C:ompute the ASCII values for "D:" into the first two memory locations for the filename (see the BASIC Reference Manual, Appendix C).

Next, we make a space for the dot by moving the last character in the extender (position 13) to position 14, then position 12 to 13, and 11 to 12 (see *EXPANDLOOP). A simple C:ompute at position 11 (line 1170) inserts the dot.

The Atari Operating System requires that a valid file name contain no embedded blanks. Unless a file name is eight characters long, the file name read from disk will contain blanks. Your job, *DELETELOOP, should you care to accept it, is to locate the first blank space in the filename. Starting at line 1240, we inspect the values contained in the memory locations for the file name to see if any contain a blank (ASCII 32). If none do, the program J:umps to *LOADER. If a blank is found, the position is remembered and we move to the *MOVELEFTLOOP. This routine moves the value in position 11 (the dot from line 1170) into the blank space. It then moves the first extender value down, and loops until the entire extender is moved.

After all the moving is done, the program goes to *RUNNER which does only two things. The GR:aphic QUIT clears the screen and restores the borders to their usual color. LOAD loads the program you chose and runs it. Thereafter, any press of RESET will reload the menu programs and let you choose a new program by typing a simple number.

Looking through the string variable table can be a powerful (if complex) tool. One final point: strings are stored in ascending order by occurrence in the program. This means that the first string will have the lowest memory locations and will be pushed downward by later strings.

I hope you'll find the AUTO PILOT helpful and fun. My four-year-old calls the face "Bugs"--she likes her.

[code]