Classic Computer Magazine Archive COMPUTE! ISSUE 53 / OCTOBER 1984 / PAGE 10

Atari Machine Language

I would like to know how to create an AUTORUN.SYS program in machine language using the Atari Assembler Editor cartridge. Also, how do you generate a random number in machine language?

Paul Stach

An AUTORUN.SYS file is much like any machine language binary object file. When DOS boots up, though, it checks for AUTORUN.SYS, and loads it during the boot process. But to make it run automatically, you must append a special run vector at the end of your file. Atari files can load in several stages, each stage going to a different part of memory. After a file is loaded, an attempt is made to execute it by jumping through the address found at $02E0/$02E1. In order to have your machine language run after it has been loaded, the starting address of your program must be loaded into $02E0. This is easily accomplished in the source code. At the end of your listing, include two lines:

* = $02E0

This * = is in addition to the original * = at the top of your program. When this is assembled, the assembler appends to your file the initialization address of your program. The label START should be assigned to the RUN address of your program.

Location 53770 ($D01A) is the hardware ran­dom number generator. A LOAD instruction (or a PEEK in BASIC) will return a random number from 0 to 255. In reality, 53770 is a very high speed counter. It goes so fast, the output seems random. If you need bigger numbers, get two bytes. For smaller ranges, you can chop off the unwanted portion with AND. For example, LDA $D01A/AND #$0F would give you a random number from 0 to 15. Another way to limit the random number is by rejecting unwanted values. For example, if you wanted a random number from 1 to 10, use a loop like:

REJECT LDA $D01A	;Get the random number
	BEQ REJECT	;If zero, get another
	CMP #11		;Is the number 11 or higher?
	BCS REJECT	;If so, the carry will be set
	RTS		;Return the number in the accumulator