Tutorial Subroutines

by Ian Finlayson


Issue 32

Mar/Apr 88

Next Article >>

<< Prev Article





Ian Finlayson continues his series with a longer routine for disk users that can be used as shown or expanded further

For the fifth in this series I have chosen a rather longer subroutine which, I hope, will be very useful. Some of you will already have a `Minidos' of some sort but those who are newer to Atari should find the technique interesting as it uses Basic's special I/O function XIO which is not mentioned in the Basic Reference Guide!

This routine allows access to some of the functions of the Disk Operating System from Basic so you can carry out disk file manipulations without leaving your program. It may be appended to your program during the development phase and then removed if it is no longer needed once the program is complete. If you are ever stuck with a program to save and no formatted disk available this subroutine can be ENTERed into your program and used to format a disk.


The XIO function format is: XIO A,#B,C,D,Filespec

A is the command number. We will be using 32 (rename), 33 (delete), 35 (lock), 36 (unlock) and 254 (format). Other available commands are 5 (get record), 7 (get character), 9 (put record), 11 (put character), 12 (close), 13 (status request), 17 (draw line), 18 (fill), 37 (note) and 38 (point).

#B is the device number as used in an OPEN command. In most applications it is ignored but it must be included and must have a # sign. Do not use the number of an I/O channel which is already open.

C and D are auxiliary control bytes. They are set to zero for most applications and we do not need to consider them for this routine.

Filespec is the name of the file being operated on, or in the case of Rename the name of the old and new files with a "," separator. If it is typed in it must be in quotation marks but in the subroutine we will use a string variable for the file name.


Lines 31400 31470 are secondary subroutines called by the main subroutine which follows. These are adapted from the keyboard input subroutines in Issue 31. The strange set of conditions in line 31440 is designed to allow input of A-Z 0-9 and also . , * and ? so that all file names including wild cards can be input.

Line 31480 - Enter the subroutine here, i.e. GOSUB to this line. This clears the screen, then checks the value of TT15. TT15 is zero if the subroutine is being run for the first time, otherwise it will have been set to 1 in line 31490 and line 31490 is skipped to avoid an error through trying to dimension the variables a second time.

Line 31490 - dimensions the variables needed in the subroutine and sets a trap to line 31500 for any I/O error during execution of the subroutine (such as a wrong file name).

Line 31500 - The destination for trapped errors, provides a suitable re-entry into the program, an error message and resetting of the trap for further errors.

Lines 31510 31540 get the directory from the disk and print it on the screen.

Line 31550 - asks which function you wish to carry out and goes to the subroutine at 31400 for a single character input.

Line 31560 - if C was selected (to change disks) a prompt is given to change the disk. The program then waits for a key press and returns to the start of the subroutine.

Lines 31570 31580 - If L or U were selected these lines are implemented otherwise the program skips to 31600. TT16 is the command number needed in the XIO function, for example, 35 for Lock and 36 for Unlock. A prompt is made for the filename and this is obtained from the subroutine at line 31420. "D:" is added to the front of the file name and the program jumps to line 31710.

Lines 31590 31610 - These lines carry out a similar routine for Renaming a file (Command No 32), but in this case the old filename is retrieved first and then the new name. The latter is appended to the former after a comma, so that TT11$ is of the form D:oldfile.ext, newfile.ext. The program then goes straight to the XIO function in line 31710.

Lines 31620 31640 are for Erase (Command number 33). As this is a destructive routine a prompt for a Y input is included to make doubly certain that it is intentional, then the program steps to 31480.

Lines 31650 31670 - This is similar to the erase routine but for Format (Command 254). Again a cautionary prompt is used.

Line 31680 - if Q is selected we quit the subroutine and return to the main program. This is the only way out of this minidos subroutine.

Line 31690 - if this line is reached then the original letter selected was not an active letter so the subroutine is started again, prompting for one of C,L,U,R,E,F or Q.

Line 31700 - this line is used by the Erase and Format selections to check for the Y response to the prompt. Any other key returns to the beginning of the subroutine.

Line 31710 - at last the XIO function! It operates as described above. Once the operation is complete the program returns to the start of the subroutine and displays the disk contents anew so that the change can be seen immediately. From there another operation can be selected or Q to return to the main program.



This subroutine has been put together rather quickly and could, I'm sure, be compacted and improved. It was developed in this form to enable you to follow it easily. There are three obvious possibilities for development of the subroutine - first add more XIO functions, second improve the disk contents display to fit more files on the screen (see Issue 28) and third provide for multiple disk drive configurations.

That's it for this issue. As always any comments or suggestions for other routines are welcome. Write to Ian Finlayson, 60, Roundstone Crescent, East Preston, West Sussex.


  AtariLister - requires Java