Classic Computer Magazine Archive ANTIC VOL. 2, NO. 9 / DECEMBER 1983

AUTORUN.SYS

Build your own in BASIC

by CHUCK HOSICK

When you power-up your computer, it automatically goes through an initialization process called "coldstart". This invalves step-by-step, byte-by-byte checking and setting of various statuses and values in the central processor and other chips used by the ATARI 400/800 system. Is there a cartridge in the slot? How much RAM is available? Is a cassette recorder attached? Is a disk drive attached and turned on? These questions (and more) are asked and answered and default values such as screen margins are set. Memory pointers are established and data about attached devices (the device handlers) are stored away in RAM for future reference. This initialization process is commonly known as "booting up" your computer.

If a disk drive is attached when you power up, the Disk Operating System (DOS) will be booted into the computer's memory from drive number one. If you have a binary file on your disk named AUTORUN.SYS, DOS automatically loads this file into RAM (and executes it if appropriate) at this time. With an AUTORUN.SYS file on your disk you can power up your computer and automatically run a disk-resident program ... without typing LOAD or RUN.

There are basically two different types ofAUTORUN.SYS files used in the Atari programming community. One is found on the DOS Version 2.0S Master Diskette II supplied by Atari (CX8104). It boots the RS-232 device handler from the 850 Interface Module and then returns control to the Operating System. The second type of AUTORUN.SYS program executes immediate mode BASIC commands such as RUN "D:MENU'. In an AUTORUN.SYS file this command would cause a program named "MENU" to be automatically LOADed from the disk and RUN. The first type boots the interface while the second type executes BASIC commands.

Well, what if your BASIC program also needs to use the RS-232 interface! Too bad - only one AUTORUN.SYS file will be loaded from your diskette! You cold boot the RS-232 interface handler, then load the program manually. But that takes extra effort. So the logical solution is to create an AUTORUN.SYS file that does both!

The BOOTBILD program listed below creates an AUTORUN.SYS file which boots the interface and also executes whatever BASIC commands you enter.

BOOTBILD Program Explanation

Statement 10 is a quick way to save typing time during program development. When you want to SAVE what you have typed, simply LIST line 10, position the cursor over the 1 and type 6 spaces and a return. The program will be SAVEd with line 10 intact (thanks to Atari's screen editor)

Lines 600 through 720 display a message prompting you to turn on the 850 Interface Module and to enter the BASIC command(s) that you desire to be executed on booting up the system.

Line 40 is the INPUT statement for your BASIC command(s). You may separate your BASIC commands with a colon, but you cannot exceed the length of a BASIC logical line (about three physical screen lines).

Lines 50 through 130 contain a checksum routine. Since it is easy to make errors when entering machine language programs in the form of DATA statements, this routine REAds the data and computes a checksum for each DATA statement. The last entry in each DATA statement is the checksum which must be equal to the computed sum. If the values are not equal, the program will automatically list the offending line so that it may be corrected. Once you have the program "up and running", this routine and the checksum data may be eliminated from the program to save execution time and memory.

Lines 140 through 370 write the AUTORUN.SYS binary file onto your disk with the desired BASIC command(s) embedded in the file.

Lines 150 through 180 set up a two-byte hex FF binary header and the starting address (hex 3800, decimal 56*256).

Lines 190 through 205 compute and write the ending address by adding the length of your BASIC command(s) to the length of the machine language program.

Lines 210 through 280 write the machine language program and the BASIC statement.

Lines 290 through 370 write the initialization address with two-byte hex FF header.

Lines 400 through 540 contain the machine language program which performs the booting and BASIC command execution.

The assembled machine language program which is reduced to DATA statements in BOOTBILD is presented below. Instead of using line numbers, it is often times more instructive to discuss machine language programs in terms of memorp locations. Thus the following program explanation refers to hexadecimal memory locations, not to line numbers!

AUTBUILD Program Explanation

Locations 3800 to 3836 attempt to OPEN the "R" handler file. If the OPEN is unsuccessful for any reason (the interface module is not turned on or not attached), the program jumps to the BASIC loader section.

Locations 3837 through 3849 load the "R:" handler from the interface module into memory. If the load is successful -- and it should always be if the interface module is alive and well - the next section is executed. If the load is not successful, then the next section is skipped.

Locations 384A through 3856 set up an indirect jump to Subroutine (JSR) -- the 6502 microprocessor does not have one of its own. Locations OC & OD hold the DOS initialization vector, DOSINI. By loading from OC & OD and storing the contents in 3855 and 3856, an indirect JSR is "manufactured". This JSR through DOSINI then initializes DOS and returns to the next section.

Locations 3857 through 38D6 are the BASIC command executor. Execution of the BASIC command(s) is performed by "stealing" the screen editor handler vector table and substituting our own. The table substituted is identical to the original except for the GET character vector. The GET character vector now points to location 3876. The substitute vector table is stored at locations 3867 through 3875.

The GET character routine (locations 3876 through 3884) writes the BASIC command onto the screen in the immediate read mode. This command will be executed as soon as control is returned to the operating system. Locations 3885 through 3891 set up values for a RETURN to the operating system and then RETURNs. This RETURN causes the BASIC command to be executed and away we go!

A useful modification to this program would be to warn the user if the interface was not booted successfully or to print a reminder and then attempt the boot again -- but that will be left as an exercise for the more serious student.

Type in the BOOTBTLD program (and SAVE it to disk!) RUN it. Enter your desired BASIC command(s) and you now have an AUTORUN.SYS file on your disk which boots the interface and then executes your BASIC command(s).

Chuck Hosick is an electronics engineer involved with microcomputers for more than ten years. His pet project is modification of the 810 Disk Drive to double density.

Requires 16K and disk

Listing 1: BOOTBILD.BAS Download

Listing 2: BOOTBILD.ASM Download / View