Classic Computer Magazine Archive COMPUTE! ISSUE 73 / JUNE 1986 / PAGE 82

Hints Tips

George Miller, Assistant Technical Editor

Here are some interesting tricks for setting up autobooting programs, customizing your GEM desktop, reading a joystick from ST BASIC, and souping up BASIC's performance with machine language subroutines. All the techniques work on the 520ST and 1040ST.

The Atari ST series computers are extremely powerful and complex machines. The numerous demo programs which are widely available offer only small peeks at the true capabilities of these computers. For programmers, however, the ST's power can be frustrating because it's so elusive. Virtually no technical documentation is supplied with the ST, and the two languages it comes with-Logo and ST BASIC-have their shortcomings.
    If you invest $300 for an Atari development system package, you receive an assembler, a C compiler, and a huge mass of documentation on the Graphics Environment Manager (GEM), but most of it is not even ST-specific-it refers to GEM as implemented on the IBM PC.
    However, careful study of this mountain of paper can reveal quite a few "secrets" about the ST. We'll let you in on a few of these tricks which enhance the power of your computer.

Autobooting Programs
How you ever wished that a certain program-perhaps a RAM disk utility, or an application, or a language-could run automatically when you start up your ST? This feature would be especially handy if you need to set up a disk for someone who wants to run a program without understanding anything more than how to turn on the computer.
    The eight-bit Atari computers can automatically load and run programs by using AUTORUN.SYS files. Apple has the HELLO program, PC-DOS and AmigaDOS have batch files, and the Commodore 128 has provision for autobooting. Although it's not documented, so does your ST. Clues on how to create an autoexecute file can be found in GEMDOS.
    As part of the initialization sequence, the ST looks for a folder called AUTO on the boot disk. Any files with a .PRG extender found in the AUTO folder are executed in sequence. These files are known as COMMAND.PRG files.
    It's very easy to set up an autoboot program. Place your boot disk in your drive, then point to the File heading on the menu bar. Select the New Folder option and create a folder named AUTO.
    Move any program you want to autoboot into this folder. Any time you boot your ST from this disk, the program you placed in the AUTO folder will automatically run. This technique works with TOS in ROM or with the earlier disk-loaded TOS. There may be a problem, however, with autobooting some programs when using the high-resolution monochrome mode. Otherwise, it's the most foolproof autorun system yet.

Customizing The Desktop
Have you ever tried renaming your disk icons using the Install Drive option from the Options menu? Some characters can't be used. For instance, it isn't possible to name an icon Disk A because lowercase letters and spaces are not permitted. Also, you can't do anything with the trash can.
    However, there is a way to change the names to anything you want. After saving your desktop, you can edit the file which stores the information for these options-DESKTOP.INF. For now we'll only change the icon names using this technique. Be careful to not change any other characters in the file.
    First, you'll need a text editor such as Mince or EMACS, or even a word processor, like ST Writer. If you're using a word processor, set the left and top margins to zero.
    The job itself is rather easy. Load the file DESKTOP.INF. It should look something like Figure 1.


#E 9B 03
#W 00 00 0C 01 1D 16 08 A:\*.*@
#W 00 00 28 01 1F 17 00 @
#W 00 00 0E 09 2A 0B 00 @
#W 00 00 0F 0A 2A 0B 00 @
#M 00 02 00 FF A FLOPPY DISK@ @
#M 00 03 00 FF B FLOPPY DISK@ @
#T 00 07 02 FF TRASH CAN@ @
#F FF 04 @ *.*@
#D FF 01 @ *.*@
#G 03 FF *.PRG@ @
#F 03 04 *.TOS@ @
#P 03 04 *.TTP@ @

    Each character in this file is information about your desktop. Any change will affect what you see on the desktop and even how your ST functions to a certain extent. Use caution, since some changes might not yield the results you expect. To be safe, make sure you're working with a backup copy of your boot disk. Store the original in a safe location. This is always a good idea when experimenting with any file on a disk, and especially when modifying files that control the operation of your ST.
    Now, move the cursor to the first line which begins with #M. Change the text, replacing the words FLOPPY DISK, so the line reads like this:

#M 00 02 00 FF A Disk A@ @

Then change the next line to:

#M 00 02 00 FF B Disk B@ @

    If you want, you may change the name of the trash can icon. I called mine Black Hole! as a con stant reminder that unlike the Amiga or Macintosh, the ST trash can does not let you easily recover files which are deleted. (There are some disk utilities available which allow you to recover trashed files, under limited conditions.)
    To change the trash can icon, modify the next line to read:

#T 00 07 02 FF Black Hole!@ @

    The revised DESKTOP.INF file should be similar to Figure 2.

Figure 2: Revised DESKTOP.INF

#E 9B 03
#W 00 00 OC 01 1D 16 08 A:\*.*@
#W 00 00 28 01 1F 17 00 @
#W 00 00 OE 09 2A 0B 00 @
#W 00 00 0F 0A 2A 0B 00 @
#M 00 02 00 FF A Disk A@ @
#M 00 03 00 FF B Disk B@ @
#T 00 07 02 FF Black Hole!@ @
#F FF 04 @ *.*@
#D FF 01 @ *.*@
#G 03 FF *.PRG@ @
#F 03 04 *.TOS@ @
#P 03 04 *.TTP@ @

    Finally, save the file back to the disk as DESKTOP.INF. The file must be saved in ASCII format, so make sure your text editor or word processor has this feature. If you're using ST Writer or some other word processors, it may be necessary to print the file to the disk in order to save it in ASCII format.

Reading The ST Joystick
ST BASIC is a fairly generic BASIC that has very few ST-specific commands. One of the most noticeably missing commands when you're trying to write a game is a function for reading the joystick. The ST works with any of the joysticks sold for the eight-bit Atari and Commodore computers, but there's no STICK or STRIG functions as in eight-bit Atari BASIC.
    Actually, a joystick command does exist in the ST, but it's hidden deep within GEMDOS in the BIOS (Basic Input/Output System). This is an area not readily available from ST BASIC without using a few special techniques.
    One easy way to find out what the joystick is doing is to ask the Intelligent Keyboard Device (IKBD). The keyboard has its own microprocessor, a 6301 chip, which is a member of the 6800 family. The keyboard processor is really a small computer system, with input/output lines, RAM, ROM, and even a serial interface which handles traffic to and from the 68000 central processing unit. The 68000 is not responsible for polling the keyboard continuously for activity. The 6301 notifies the 68000 via an interrupt when anything needs processing. In addition to reading the keyboard, the 6301 also reads the mouse, the joystick, and performs other functions.
    The ST's link to the keyboard processor is through a chip called an ACIA (Asynchronous Commu nications Interface Adapter). The control register for the keyboard ACIA is located at memory address $FFFC00 in the ST, and the data register is at location $FFFC02. If you've moved to the ST from an earlier eight-bit computer, those may be the biggest hexadecimal numbers you've ever seen. Remember that the 68000 microprocessor in the ST has 24 address lines, enough for over 16,000,000 bytes of memory, as compared to the 65,536-byte maximum for eariler computers with only 16 address lines. For the ST you must become accustomed to seeing hexadecimal addresses that are six digits long.
    The following program is a short ST BASIC routine to read the values of the joystick plugged into port 1 (the rear joystick connector).

70 POKE &hfffc02,&h0012 'turn off
80 POKE &hfffc02,&h0014:joystick =
90 IF joystick = 511 THEN ? "north"
100 IF joystick = 2559 THEN ?
110 IF joystick = 2303 THEN ? "east"
120 IF joystick = 2815 THEN ?
130 IF joystick = 767 THEN ? "south"
140 IF joystick = 1791 THEN ?
150 IF joystick = 1279 THEN ? "west"
160 IF joystick = 1535 THEN ?
170 IF joystick < 0 THEN ? "fire button"
180 POKE &hfffc02,&h0008 'turn on
190 GOTO 70

    Line 70 sends a command to the IKBD, via the data register at $FFFC02, instructing it to turn off the mouse. (Note that ST BASIC uses &h to indicate hexadecimal numbers.)
    Line 80 sends a command via the same address to turn on the joystick. Every movement of the joystick is reported to the processor. The joystick position is read by PEEKing the value returned in $FFFC02.
    Lines 90-170 interpret the values returned from the IKBD.
    Line 180 turns the mouse back on again. This should be done before exiting the program so the user will have control of the mouse when returning to BASIC or the desktop.
    Line 190 makes the routine an infinite loop, so you'll need to press CTRL-C to stop this demonstration. If the mouse pointer isn't visible on the screen when the program stops, enter the following line and press RETURN to make the pointer reappear:

POKE &hfffc02,&h0008

    To adapt this routine for use in your own programs, replace line 190 with 190 RETURN, then use GOSUB 70 to call the routine. Replace the PRINT statements in lines 90-170 with statements to perform the desired actions when the joystick is pressed in the indicated direction.

Mixing BASIC And Machine Language
To add real speed and power to any BASIC, it's often necessary to use machine language routines for certain tasks. In ST BASIC, machine language routines can be run using j the CALL statement. The syntax for CALL is:

CALL address variable,parameter list

    The address variable is a variable which holds the memory address of the beginning of the machine language routine. This location may be the address where the routine was loaded using the BLOAD command, or the address where the ML routine was POKEd. The parameter list is a list of values which can be passed to the ML routine. Some routines don't require any values to be passed, so this is optional.
    The program below demonstrates how to POKE an ML routine into a variable, then use the VARPTR function to find the address to CALL.
    As your library of ML routines expands, you'll find this method useful. Although the example program does nothing but print the letter A on the left side of the menu bar, it does demonstrate that ML routines give you full access to the ST, since the menu bar is usually off-limits to BASIC.

120 GOSUB init
130 'ML opcodes in DATA statements
140 DATA &h3f3c,&h0041,&h3f3c,
150 DATA &h3f3c,&h000d,&h3f3c,
160 DATA &h3f3c,&h000a,&h3f3c,
170 FOR i = 1 TO 19: READ a:POKE
    x+(i*2),a:NEXT:'POKE ml into
180 CALL x
190 END
200 init:ml$="This is a dummy
210 x = VARPTR (ml$)

    These tricks demonstrate only a small part of the ST's potential. Carefully studying the documentation reveals that some extremely powerful programming techniques are lurking just below the surface. If you're a curious programmer, explore GEM for ways to use the ST's features from within the tight BASIC framework.