Classic Computer Magazine Archive COMPUTE! ISSUE 32 / JANUARY 1983 / PAGE 146

Automate Your Atari

Joseph J. Wrobel, Rochester, NY

The Atari Disk Operating System (DOS) supports the use of a file named AUTORUN.SYS that has a very special characteristic. At system start-up, the DOS loads and runs this file automatically if it exists on the mounted diskette. This allows you to arrange for your Atari to come up smart.

The Potential

The AUTORUN.SYS file could contain a machine language program that loads and runs. It could also contain just a short program to do some routine operations like setting the screen margins or color before passing control to BASIC. However, the major use I've seen for AUTORUN. SYS is to direct the system to load and run a BASIC program. Not only does this type of operation save you some time and effort, but it also allows an unskilled operator, like a student, to turn on the machine and interact with an application program without getting into the details of the LOAD or RUN instructions.

The Problem

So far, so good. Why doesn't everyone use the AUTORUN.SYS file? Apparently the major obstacle to its more widespread use is the fact that it is a machine language routine. Thus, it requires knowledge of 6502 machine language and, for complex operations, some knowledge of the intricacies of the Atari Operating System to create a functional AUTORUN.SYS file. Unless someone were to come up with a program to do it for you.

Automate (Program 1) is just such a program. If you key in this program correctly and run it, Automate will help you create your own personal AUTORUN.SYS file, and it won't hurt a bit. The program starts by asking you to input the series of commands you wish to be executed at start-up. You enter the commands exactly as you would if the machine came up in its normal ready state. The only limit on the number of commands is that the total number of characters entered may not exceed 196 (including the Atari end-of-line character added each time you hit RETURN). The program keeps track of the number of characters entered and will prevent you from exceeding this limit. After you've entered the final command in the sequence, the program will create an AUTORUN.SYS file on the mounted diskette. Note that any previous AUTORUN.SYS file will be overwritten by this operation.

The next time you boot up from the diskette bearing the AUTORUN.SYS file, the AUTORUN.SYS program will be run. This will cause the commands you entered to be executed in the order they were entered (although they will not be displayed), then control will be returned to the system. The commands, of course, must be compatible with the cartridge in use (BASIC, Assembler Editor, etc.) or an error will result. If at any time you wish to boot up from a diskette and circumvent the AUTORUN.SYS file, just hold the OPTION key down until system initialization is complete. The AUTORUN.SYS file created by Automate checks that key and, if it finds it depressed, the command list will not be executed.

A BASIC Example

To demonstrate the use of the program, a single command BASIC example will be presented. Let us suppose there exists a BASIC program entitled BEGIN which you would like to run automatically at start up. Using AUTOMATE, you enter (as Command #) the statement:

GR.0:?"Autoboot in progress." : RUN"D : BEGIN"

then press RETURN. Assuming you entered the command correctly, you respond to the question:

Is that correct (Y/N)?

by pressing Y. When the program asks if there are:

More commands (Y/N)?

respond by pressing N. The program then creates the AUTORUN.SYS file and displays READY when it's done. If you now turn off your computer and switch it on again, you will find that it "comes up" running program BEGIN. How simple can you get?

Description Of Operation

This section is for those who are not satisfied with just running the program, but are also interested in knowing how it works. Let's first take another look at Program 1. Automate consists of three major sections. The first section (lines 50 through 130) are for documentation and initialization. The program employs two key numeric variables: I, which counts the number of commands entered, and L, which counts the total number of characters in the command list. The second program section (lines 140 through 350) INPUTs the commands one at a time. As each command is entered, the program allows for error correction, checks command list size, packs the command into B$ and tacks on an Atari end-of-line (EOL) character, namely CHR$(155). The third section of the program (lines 360 through 600) actually creates the AUTORUN.SYS file.

Before this third section is discussed, I direct your attention to Program 2. This is the assembly listing for the core of the AUTORUN.SYS program. What this machine language program does, in a nutshell, is to temporarily take over the task of supplying screen editor data by substituting a new device handler table and "get character" routine for the default ones provided by the operating system. At system start-up while the AUTORUN.SYS program is active, it intercepts all the keyboard entry requests and feeds out, one character at a time, the commands which you have entered. When it has sent out the last character of the last command in the list, it re-installs the default screen editor handler table, and the system takes over from there.

Returning to the section of the BASIC program which creates the AUTORUN.SYS file, you will find that it consists primarily of three loops. Loop one (lines 490 through 510) PUTs the core program and its associated six byte header into the file as READ from the DATA statements in lines 430 through 480.

Note that in line 500 of Automate, two numbers are changed from the values shown in the DATA statements before putting them into the AUTORUN.SYS file. The first is a byte in the AUTORUN.SYS file header which gives the end of the program when loaded in memory. This is the sum of the core program length and the number of bytes in the command list. Automate also alters the value of the immediate argument of the CPY instruction in line 370 of Program 2. This byte is set equal to the total number of characters (including EOL's) in the command list. Loop two (lines 530 through 550) PUTs in the command list which resides in B$. Finally, loop three (lines 580 through 590) adds a twelve byte postscript to the file which provides the system with the initialization and run locations for the routine.

The BASIC program here provides an easy way to create a useful AUTORUN.SYS file. There are dozens of ways this file can be used. It doesn't necessarily have to be a serious application. For example, it's sort of fun just to start up my machine, listen to it go through its disk machinations, then see it automatically display the personalized greeting:

READY WHEN YOU ARE, J.W.!

Program 1.

50 I = 0 : L = 0 : MAX = 196
60 DIM A$ (MAX), B$ (MAX), R$ (1)
70 OPEN #1, 4, 0, "E : " : OPEN #2, 4, 0, "K : "
80 ? "This program helps you to create"
90 ? " a personalized AUTORUN.SYS file"
100 ? " which, following the disk boot"
110 ? " {3 SPACES} process, automatical1y issues"
120 ? " {4 SPACES} a set of commands that "
130 ? " {5 SPACES} specify."
140 I = I + 1
150 ? : ? "Please enter command #" ; I ;".
160 ? : INPUT #1 ; A$
170 POKE 766, 1 : ? : ? "Command #" ; I ; ":" ; A$ : POKE 766, 0
180 ? : ? "IS THAT CORRECT (Y/N)? " ; : GET #2, X : ? : R$ = CHR$ (X)
190 IF R$ = "y" OR R$ = "y" THEN 220
200 IF R$ = "N" OR R$ = "n" THEN 150
210 GOTO 170
220 X = L + LEN (A$) + 1 - MAX
230 IF X < = 0 THEN 260
240 ? : ? "Command # " ; I ;" ; " X ;" Character (s)"
250 ? "too long." : I = I - 1 : GOTO 270
260 B$ (L + 1) = A$ : L = LEN (BS) : BS (L + 1) = CHR$ (155) : L = L + 1
270 ? : ? "Current command list :"
280 POKE 766, 1 : ? : ? B$ : POKE 766, 0
290 IF L > = MAX - 1 THEN ? "Command list is full." : ? : GOTO 370
300 ? "Command list can hold " ; MAX - L - 1 ; " more"
310 ? " character (S)."
320 ?  : ? "More commands (Y/N)? " ; : GET #2, X : R$ = CHR$ (X)
330 IF R$ = "Y" OR R$ = "y" THEN 140
340 IF R$ = "N" OR R$ = "n" THEN 360
350 GOTO 300
360 ? CHR$ (125);
370 ? "Mount diskette which is to bear"
380 ? " the AUTORUN . SYS file, then"
390 ? " press RETURN. " ; : GET #2, X : CLOSE #1 : CLOSE #2
400 ? CHR$ (125) ; : ? "Writing AUTORUN.SYS file."
410 OPEN #1, 8, 0, "D : AUTORUN.SYS"
420 REM PUT OUT THE HEADER AND THE CORE MACHINE LANGUAGE PROGRAM
430 DATA 255, 255, 0, 6, 59, 6
440 DATA 173, 31, 208, 41, 4, 240, 10, 169, 18, 141, 33, 3
450 DATA 169, 6, 141, 34, 3, 96, 251, 243, 51, 246, 33, 6
460 DATA 163, 246, 51, 246, 60, 246, 76, 228, 243, 0, 238, 33
470 DATA 6, 172, 33, 6, 192, 0, 208, 10, 169, 0, 141, 33
480 DATA 3, 169, 228, 141, 34, 3, 185, 59, 6, 160, 1, 96
490 FOR I = 1 TO 66 : READ X
500 IF I = 5 OR I = 48 THEN X = X + L
510 PUT #1, X : NEXT I
520 REM ADD THE COMMAND LIST
530 FOR I = 1 TO L
540 X = ASC (B$ (I, I))
550 PUT #1, X : NEXT I
560 REM APPEND INITIALIZE AND RUN VECTORS
570 DATA 226, 2, 227, 2, 0, 6, 224, 2, 225, 2, 17, 6
580 FOR I = 1 TO 12 : READ X
590 PUT #1, X : NEXT I
600 CLOSE #1 : ? CHR$ (125) ; : END

Program 2.

D01F	0100 CONSOL = 	$D01F
0320	0110 DEVTAB = 	$0320
E400	0120 OLDDHT =	$E400