Classic Computer Magazine Archive COMPUTE! ISSUE 87 / AUGUST 1987 / PAGE 81

BASIC Batch Files With Atari DOS

Bill Bodenstein

Now any Atari BASIC programmer can write batch files to configure the computer, run programs, or execute any BASIC command automatically when you power up. For the Atari 400, 800, XL, and XE.

Every computer user has his or her favorite computer setup. When Atari wrote the operating system for their eight-bit computers, they decided that a default screen of 38 characters per line with a light blue background would be most popular among Atari users. But what if you prefer a black background or a 40-column screen? With a disk drive and Atari DOS, you need only make an AUTORUN.SYS file to change the screen settings at power-up. But what if you don't know machine language or even know how to create a binary file? Constructing an AUTORUN.SYS file, even one that simply changes the screen color to black, can be tricky, especially for beginning computerists. This program provides an easy way to make your computer execute any series of BASIC commands when you flip on the power switch.

To begin, type in and save the program included with this article. With the aid of this program, you can create a special AUTORUN.SYS file that executes any BASIC commands which you want to perform at boot-up time.

Let's start with a simple example. Say that you want to change the screen color to black when you turn on the computer. Run the program, inserting a disk in the drive when prompted. When the program prompts you to enter a BASIC statement, type this line and press RETURN:

POKE 710, 0

When that's done, press RETURN without typing anything. The program writes the statement to disk and closes the disk file. To test the AUTORUN.SYS file, simply reboot the computer. If you didn't make any typing mistakes, the screen color should automatically turn black. To correct a typing error or enter a new statement, simply rerun the program.

The same method can be used to execute any BASIC statements that would be legal in direct mode. The special AUTORUN.SYS file can reconfigure the computer in any way, or even load and run programs. For instance, say that you want to automatically load and run a BASIC program named GAME-.BAS when the system boots. Instead of the POKE statement shown above, you can type this command when prompted by the program:

RUN "D : GAME.BAS"

When this AUTORUN.SYS file is on the disk, the computer automatically searches for GAME.BAS when you boot up, loading and running it just as if you had typed the command from the keyboard.

Batch Files

This program allows you to use batch files, a feature common to many computers. A batch file is a text file containing a batch, or collection, of commands which the computer executes automatically. Batch files are an integral part of systems like MS-DOS/PC-DOS or AmigaDOS, but Atari DOS makes no provision for them. However, Atari DOS does include a feature known as the AUTORUN.SYS file, a machine language file which, if present, is executed automatically when the system boots.

The program accompanying this article simply creates an AUTORUN.SYS program that emulates the batch processor found in other systems. The BASIC statements that you type when running this program are written to a text file called AUTORUN.BAT. The AUTORUN.SYS file reads the commands from AUTORUN.BAT, executing whatever it finds there.

That process may sound more complex than it is in fact. All we need is a few machine language instructions to perform the effect of the following statement:

ENTER "D : AUTORUN.BAT"

The key to this technique is the ENTER command. Under normal circumstances, you enter BASIC program lines and direct-mode commands into memory with the screen editor device (E:). The screen editor lets you type commands on the keyboard, displaying them on the screen as you type. When you press RETURN, the editor reads the current line from the screen and performs it. If the line starts with a number, it is stored in BASIC memory; otherwise, it is performed as a direct-mode command.

ENTER lets you tell the computer to get its input from some device other than the screen editor. The most common use of this command is to ENTER a program from cassette (device C:) or disk (device D:). When you ENTER a program from disk, the computer reads the indicated text file from disk and stores it in memory with the same result as if you were typing each line into memory by hand. The end product is exactly the same—the computer sees only the input data, without caring where it comes from.

The same technique can be used to enter direct-mode statements into memory. Type and run the following program to create a text file named DOSTUFF:

10 OPEN #1, 8, 0, "D : DOSTUFF"
20 PRINT #1; "POKE 710, 0"
30 PRINT #1; "POKE 82, 0"
40 CLOSE #1

Line 10 of this program opens the file DOSTUFF for output. Lines 20-30 write two POKE statements into that file. Line 40 closes the file. At this point we have a test file on disk containing two direct-mode commands: POKE 710,0 and POKE 82,0. To make the computer execute this file, type this line in direct mode and press RETURN:

ENTER "D : DOSTUFF"

The computer changes the background color to black and moves the left margin over two columns, just as if you had typed the two POKEs on the keyboard.

Thus, ENTER allows you to change BASIC's input device. The command ENTER "D:filename" makes the disk drive the input device. The computer reads and executes instructions from the disk file until it reaches the end of the file, at which point it automatically receives input from the screen editor again.

The machine language part of this program redirects input to a disk file by means of the IOCB (Input/Output Control Block). It performs the equivalent of these two BASIC lines:

OPEN #7, 4, 0, "D : AUTORUN.BAT"
POKE 180, 7

Location 180 ordinarily contains a zero, referring the IOCB 0, which the operating system reserves for the screen editor. Replacing the zero with a 7 fools the system into using the previously opened channel (7) for input rather than the editor. Each time a READY prompt appears and BASIC looks for input, it extracts and performs a line from the batch file instead.

BASIC Batch Files

For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" elsewhere in this issue.

AK 5 REM Copyright 1987 Compute! Publications, Inc.
BC 6 REM All Rights Reserved.
IB 7 PRINT "{CLEAR} {5 SPACES} Copyright 198 7" : PRINT "Compute! Publications, Inc."
AB 8 PRINT "{3 SPACES} All Rights Reserved."
ED 10 FOR X=1 TO 1000 : NEXT X
LC 20 DIM A$(1), LINE$ (120) : O PEN #2, 12, 0, "E" : POKE 82, 0 : ? "{TAB} BASIC BATCH FILE MAKER" : ?
JC 30 ? "This program will allow you to create" : ? "an AUTORUN.SYS & AUTO RUN.BAT file that"
MN 40 ? "will execute a series of BASIC commands" : ? "whenever you turn your system on."
LP 50 ? : ? "Insert a diskette and HIT <RETURN> to" : ? "create the AUTORUN.SYS file.";
PN 60 INPUT A$ : TRAP 100 : OPEN #1, 4, 0, "D : AUTORUN.SYS" : GOTO 80
CA 80 CLOSE #1 : ? "AUTORUN.SYS ALREADY EXISTS!" : ? "Would you like to over write it (Y/N)";
CP 85 INPUT A$ : IF A$ = "Y" THE N 150
AA 90 IF A$ < > "N" THEN 80
AM 95 GOTO 50
AK 100 IF PEEK (195) < > 170 THE N 400
DA 150 ? "Creating AUTORUN.SYS…" : TRAP 400
II 160 CLOSE #1 : OPEN #1, 8, 0, "D : AUTORUN.SYS" : RESTORE
LG 170 READ N : IF N >-1 THEN PUT #1, N : GOTO 170
BO 200 CLOSE #1 : OPEN #1, 8, 0, "D : AUTORUN.BAT" : ? : ? : ? "AUTORUN.BAT ready for input…" : ?
FN 210 ? "Now enter any stataments/commands you'd" : ? "like executed at start-up."
GM 220 ? "(Enter just a <RETURN> when done.)"
BM 250 POKE 694, 0 : POKE 702, 64 : ? "ENTER A LINE : " : INPUT #2 ; LINE$ : PRINT #1; LINE$ : IF LINE$ < > "" THEN 250
EK 260 CLOSE #1 : CLOSE #2 : ? : ? "BATCH file created!" : ? "Boot disk to try it out." : END
CE 400 ? "{BELL} ERROR - "; PEEK (195) : CLOSE #1 : CLOSE #2 : STOP
PK 500 DATA 255, 255, 0, 6, 219, 6, 169, 1, 133, 9, 169, 0, 1, 41, 68, 2, 169
KG 510 DATA 130, 32, 109, 6, 165, 106, 201, 161, 176, 7, 173, 96, 160, 201, 165, 240
LJ 520 DATA 5, 169, 156, 76, 109, 6, 173, 70, 3, 133, 204, 1, 73, 71, 3, 133, 205
BJ 530 DATA 169, 54, 141, 70, 3, 169, 6, 141, 71, 3, 108, 250, 191, 165, 204, 141
LJ 540 DATA 70, 3, 165, 205, 141, 71, 3, 162, 112, 169, 3, 1, 57, 66, 3, 169, 206
BJ 550 DATA 157, 68, 3, 169, 6, 1, 57, 69, 3, 169, 4, 157, 74, 3, 32, 86, 228
FM 560 DATA 16, 10, 192, 170, 208, 212, 169, 184, 32, 109, 6, 96, 169, 7, 133, 180
BD 570 DATA 76, 96, 160, 162, 0, 157, 68, 3, 169, 6, 157, 69, 3, 157, 73, 3
DC 580 DATA 169, 9, 157, 66, 3, 7, 6, 86, 228, 125, 80, 114, 111, 99, 101, 115, 115
HK 590 DATA 105, 110, 103, 32, 98, 97, 116, 99, 104, 32, 102, 105, 108, 101, 46, 46
NM 600 DATA 46, 155, 78, 101, 101, 100, 32, 66, 65, 83, 73, 67, 32, 40, 114, 101
JG 610 DATA 118, 46, 32, 65, 44, 66, 44, 111, 114, 32, 67, 41, 46, 155, 66, 97
OE 620 DATA 116, 99, 104, 32, 102, 105, 108, 101, 32, 110, 111, 116, 32, 102, 111, 117
IF 630 DATA 110, 100, 46, 155, 68, 58, 65, 85, 84, 79, 82, 85, 78, 46, 66, 65
HE 640 DATA 84, 155, 224, 2, 225, 2, 0, 6, -1