TALK TO YOUR PERIPHERALS
SYNOPSIS
This article's listing is a subroutine that you can add to your own BASIC programs to gain control of functions that are normally accessible only from DOS. The subroutine requires BASIC and Atari DOS, and runs on all Atari computers.
After spending hours typing in a BASIC program, have you ever tried to save it to disk, only to find that there wasn't enough room? And, of course, that there wasn't another formatted disk to be found for love or money? If this has happened to you, you're not the first. Atari's solution to this dilemma is the MEM.SAV feature of DOS. But what happens if you don't have MEM.SAV on your disk?
Recently, I worked on a progam that frequently wrote lengthy files to disk, and I ran into this problem more than once. I needed a way to access DOS commands from BASIC. Then it occurred to me that the long-forgotten XIO commands from the abandoned BASIC Reference Manual might be of service.
The program listing presented here is a subroutine you can add to any BASIC program that requires access to DOS functions. It allows you to use the Directory, Lock, Unlock, Erase, and Rename file functions, and it can even format a new disk.
PLANNING FOR EMERGENCIES
Keep a LISTed copy of the subroutine on your utilities disk. If you ever encounter the situation mentioned above, add the subroutine to your program with the ENTER command. Then type -- in immediate mode (with no line number) -- GOSUB 29700.
HOW TO USE THE PROGRAM
The subroutine is quite straightforward. I've used unusual line numbering to keep it "above" most user programs, but "below" other ENTER-type utilities, like renumbers, which commonly use a line range above 30000. Type in the subroutine, then LIST it to disk. Use ENTER to merge it with your program. When you want to use DOS functions, just insert the command GOSUB 29700 into your program.
PROGRAM DESCRIPTION
Line 29700 clears the screen and causes the DIM statements to be skipped if they've already been executed. Lines 29720 to 29740 contain the disk-directory routine. The POKE in line 29750 ensures that an upper-case response is provided to the prompt that asks you if you want to change the disk. If the answer to this prompt is "No," you're done. If it's "Yes," line 29790 prompts you to specify the function you need. Lines 29800 to 29840 set the command byte for the XIO statement, depending on the function you've selected. If you're using Rename, line 29820 prompts you for "Oldname,Newname." It's important to enter the names in this format. For the other functions - Lock, Unlock, and Erase -- we branch to line 29860, which prompts you for a filename. Line 29870 prefixes the "D".
Two of these functions, Erase and Format, have the potential to partially or completely destroy the data on your disk. Therefore, in lines 29890 to 29910, you're asked, "Do you really mean it?" Line 29880 skips this section if a non destructive function has been selected.
This leads us to line 29930, the promised XIO command. We've determined the command byte, CMD, and the filename, CHFILE$. The channel number (1) and the two auxiliary bytes (the two zeros) are unimportant here, but are required by BASIC. The TRAP in this line causes execution to branch to line 29950 in the event of a mistyped filename or other error. Lines 29780, 29850, and 29910 perform a similar function if you mistype a response to other prompts. Line 29950, which is essentially a one-line subroutine, causes the screen border to flash red and the computer to emit a nasty sound if you've made a mistake. If a change to the disk is successful, the altered directory is displayed. To exit the subroutine, simply answer "No" to the prompt "Do you want to change the disk?"
William W. Hough, an engineer with degrees from Northwestern and Stanford, has been interested in microcomputers for a relativly short time, but mastering the Atari has become a principal leisure-time activity for him. Bill also is the author of a logicgame, Brainboggle, which is available through Educational Software, Inc.