Classic Computer Magazine Archive COMPUTE! ISSUE 79 / DECEMBER 1986 / PAGE 10

Readers’ Feedback

If you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.

LIBRARY In Amiga BASIC

After two months of minor frustration trying to use the command LIBRARY "graphics.library" in Amiga BASIC, I have come to two conclusions. Any program using this command must be in the BasicDemos directory of the system disk, and the file graphics.bmap must be in the same directory. I have found no other way to use programs which include that LIBRARY statement.

- David Hoke

Although the location of graphics.bmap is important, you need not put every program using that file in the BasicDemos directory. The LIBRARY statement, which allows you to access Amiga system routines from BASIC, always looks in the current directory for the designated .bmap file. If you load and run a program from the BasicDemos directory, the computer looks in BasicDemos for graphics.bmap when you execute the LIBRARY "graphics.library" statement. But the program should also load and run if you copy both files to a different directory. The key is to keep the program and the .bmap file it needs in the same directory. Unfortunately, you can't redirect the LIBRARY statement by supplying a directory name in front of the .bmap filename. For instance, you can't use LIBRARY "maps/graphics.library" to access graphics.bmap in the maps subdirectory. However, you can change the current directory with CHDIR. These statements change the current directory to maps and access graphics.bmap from that directory:

CHDIR ":maps"

LIBRARY "graphics.library"

The disadvantage of using CHDIR is that the directory change affects subsequent disk operations as well. If you resave the program after executing this command, the program goes into the maps directory instead of the directory in which you began. One solution is to CHDIR back to the previous directory, but that assumes a certain directory structure which may not be present if you copy the program to a new disk. A less complicated solution is to keep the program and the .bmap file in the root directory of the disk (not inside any directory). Regardless of where you put the files, the program should be able to recover gracefully if, for sotne reason, it can't find the .bmap file. To illustrate, this code sets up an error trap before it executes LIBRARY:

ON ERROR GOTO LibTrap

LIBRARY "graphics.library"

ON ERROR GOTO 0

After the first ON ERROR statement, the computer goes to the LibTrap routine when any error occurs. The statement ON ERROR GOTO 0 turns off the error trap if no error occurs. The LibTrap routine might look something like this:

LibTrap:

IF ERR=5 3 THEN

PRINT "Can't find graphics.bmap file."

PRINT "Aborting.":END

END IF

PRINT "Error #";ERR:END

Error trapping is particularly important in Amiga BASIC because of its ability to open custom display windows. If an untrapped error occurs after you open a custom window, the error message may appear behind the window, giving you no clue as to what went wrong. Chapter 9 of Advanced Amiga BASIC,available from COMPUTE! Books, is devoted entirely to the subject of making library calls from Amiga BASIC.