Classic Computer Magazine Archive A.N.A.L.O.G. ISSUE 66 / NOVEMBER 1988 / PAGE 68

UTORUN.SYS

Secrets
    by LeRoy Baxter


Ever wondered how the AUTO RUN.SYS file worked with BASIC? Ever wanted to automatically run a BASIC program that wasn't named MENU? Ever had a conflict between the autorun loader and a machine-language routine that the program needed? How about a two-stage LOAD and ENTER situation? Or an AUTORUN.SYS for a language other than BASIC?
    I've seen a lot of AUTORUN.SYS makers, but none have resolved all the questions and few that will let you autorun any program but MENU.
    I disassembled one of my AUTORUN.SYS files and delved into its secrets. I made some changes and eliminated some potential problems. The result is Listing 1, an AUTORUN.SYS maker that is more flexible than any you've ever seen. It works with any Ataritype DOS (DOS 2.5, MyDOS, etc.) and with any language.

The secrets revealed
    Normally, when BASIC comes up, it prints the READY prompt on the screen and then calls the editor to accept a line from the keyboard. While all the editor routines are in OS ROM, the designers of the Atari have allowed us unlimited flexibility by putting the address of the editor routines in a RAM table called HATABS. By replacing the editor address in HATABS, we can supply new routines that make the computer do what we want.
    The program is divided into three parts. The first part finds the vector for the editor and replaces it with our own. The handler table is searched from the bottom up just in case a new E: handler has been loaded. The second part is our new (and temporary) E: handler routine. It passes back a command line to BASIC without waiting for keyboard input, and then resets the E: handler vector to its original value. The last part is the BASIC command line itself. This can be anything that you could type on one line from the keyboard. You can change screen margins, change screen colors, play music, generate a graphics display, load one program and enter another (and then run them), set up password security, call DOS-the list is endless and limited only by your imagination.

Getting started
    Using MAC/65 or the Atari Assembler Editor, type in Listing 1 and save it. (You'll want to use it again many times.) Note that you can just list Line 10 and edit off the line number and semicolon to cause the program to be listed to disk. Next, change CMDLIN to reflect the BASIC command line you want executed. In Listing 1, the command line is: ? "Loading... MYPROG":RUN D:MY PROG.BAS." To insert the quote mark into the BASIC command line, it must be specified by its ATASCII value ($22) as a separate byte. Your command line can be a maximum of 119 characters.
    To write the AUTORUN.SYS file, load the destination disk into your drive and assemble Listing 1 to disk with the command: ASM.,#D:AUTORUN.SYS

I've seen a lot o f AUTORUN.SYS makers, but
none that have resolved all the questions
and few that will let you autorun any program
but MENU.



10 ;LIST #D:AUTOBAS.SRC
20 ;
30 ;for creating AUTORUN.SYS
40 ;
50 ;MAC65 source code with
60 ;conversions to Atari Assembler
65 ;Editor
70 ;
80 ;Equates:
90 HATABS = $031A
0100 TEMP = $CB
0110 ;
0120     *= $4000    ;or anywhere
0130 ;
0140 ;Modify the Handler table
0150 MAIN
0160     LDX #36    ;search from END
0165 ;               of table
0170 ELOOP LDA HATABS,X
0180     CMP #'E    ;for 'E:' handler
0190     BEQ CHANGE
0200     DEX
0210     DEX
0220     DEX
0230     BPL ELOOP
0240 CHANGE ;        the table address
0250     INX
0260     STX EDEX    ;save HATABS loc
0270     LDA HATABS,X ;and E: vector
0280     STA TEMP
0290     LDA # <NEWTAB ;or NEWTAB&$FF
0300     STA HATABS,X
0310     INX
0320     LDA HATABS,X
0330     STA TEMP+1
0340     LDA # >NEWTAB ;or NEWTAB/256
0350     STA HATABS,X
0360 ;now transfer ROM table to RAM
0370     LDY #$00
0380     STY YSAV
0390 KLOOP LDA (TEMP),Y
0400     STA NEWTAB,Y
0410     INY
0420     CPY #$10    ;16 BYTES
0430     BCC XLOOP   ;branch if <16
0440 ;now setup new getbyte routine
0450     LDA # <NEWGET-1
0455     ;           or (NEWGET-1)&$FF
0460     STA GETBYTE
0470     LDA # >NEWGET-1
0475     ;           or (NEWGET-1)/256
0480     STA GETBYTE+1
0490     RTS
0500 ;Handler table space
0510 NEWTAB
0520 OPEN .WORD 0    ;see Atari OS
0530 CLOSE .WORD 0   ;Manual,
0540 GETBYTE .WORD 0 ;DeRe Atari, or
0550 PUTBYTE .WORD 0 ;Mappng the Atari
0560 STATUS .WORD 0
0570 SPECIAL .WORD 0
0580 JUMP .BYTE 0,0,0
0590     .BYTE 0,0   ;16th byte
0595     ;           & insurance
0600 YSAV .BYTE 0
0610 EDEX .BYTE 0
0620 ;
0629 ;Our new GETBYTE routine
0630 NEWGET
0640     LDY YSAV
0650     LDA CMDLIN,Y ;get 1 char
0660     CMP #$9B    ;if C/R then done
0670     BEQ DONE
0680     INC YSAV    ;indx next char
0690     LDY #$01    ;tell O.S. OK
0700     RTS
0710 DONE
0720     PHA         ;save C/R
0730     TXA         ;save X register
0740     PHA
0750     LDX EDEX    ;find 'E:' entry
0760     LDA TEMP    ;in HATABS
0770     STA HATABS,X ;replace our
0775     ;           routine
0780     INX         ;with the real
0785     ;           vector
0790     LDA TEMP+1
0800     STA HATABS,X
0810     PLA         ;restore X reg
0820     TAX
0830     PLA         ;restore C/R to A
0840     LDY #$01    ;set status OK
0850     RTS
0860 ;
0870 CMDLIN ;        passed to BASIC
0880     .BYTE "? ",$22,"Loading... MY
PROG",$22
0890     .BYTE ":RUN ",$22,"D:myprog.b
as",$22
0900     .BYTE $9B   ; C/R!!
0918 ;
0920 ;set to execute when loaded
0930     *= $02E2
0940     .WORD MAIN