SELECTOR
A REVVED-UP REPLACEMENT FOR YOUR FILE SELECTOR
by CHARLES JOHNSON
The ST's file selector is that box that pops up to let you choose a file. It's a lot like the weather-everyone complains, but no one does anything about it. Until now, that is. Slip the START Disk into your drive, turn on your ST and trade in that old, tired, worn-out file selector for this year's racier model-the START Selector!
You'll find the program STSELECT.PRG in the AUTO folder and the source code in the file STSELECT.ARC on your START Disk.
When I first got my ST, one of the most confusing things about it was the strange "Item Selector" box that kept popping up in every program I used. It was pretty obvious that the Item Selector was used to save and load files, and was some kind of standard GEM object, but many aspects of its operation were extremely mysterious. To complicate matters, the manual that came with my computer made no mention of it at all!
For instance, how could I get the thing to read drive B: in my two-drive system? After a few hundred unnecessary disk swaps, I finally noticed the line labelled "Directory:"; there was a drive letter on that line! 1 moved the edit cursor to that line with the Up arrow key typed in a new drive letter, and, indoctrinated by years of computer use, pressed the Return key. Hey, where'd that Item Selector go? After lots of frustration, I realized that I needed to type in the drive letter, and then click the mouse somewhere inside the file window instead of pressing Return. Sheesh.
Giving GEM An Overhaul
The START Selector is a complete replacement for the standard ST file
selector, maintaining total compatibility with the original while adding
many new and useful features. After you install it, any program that calls
the dreaded Item Selector box will automatically use the START Selector
instead. This includes just about every major program written for the ST-including
1st Word, ST BASIC, GFA BASIC, Flash, DEGAS Elite, CAD-3D, Spectrum 512
and Cyber Paint. Of course, the START Selector won't work with programs
that use their own file selector instead of calling the built-in one. But
I've tested it with literally hundreds of ST programs, public domain and
commercial, and haven't found one incompatibility.
The START Selector program's name is STSELECT.PRG. You'll find it on your START Disk in the folder named AUTO. To install the Selector, simply slip the disk in Drive A and turn on your ST. The START Selector is now installed, but you will want to copy STSELECT.PRG to the AUTO folder in the boot disk you usually use so that it will be installed every time you power up your computer. Unlike some programs, it doesn't matter whether STSELECT.PRG runs first, last, or somewhere in the middle of your list of AUTO programs.
You can also run START Selector from the GEM desktop by double-clicking on its program name in a file window. If you use this method, a copyright notice will appear, and you'll be asked whether you really want to install the START Selector. Click on the button marked "Install" and say goodbye to the Item Selector! The START Selector will remain installed until you press the Reset button or turn your ST off.
The START Selector works on all models of ST computer, including the Megas, in all three resolutions. It's also compatible with GDOS.
What's So Good About It?
The START Selector makes it very easy to look at the files on a different
disk drive- no more jumping from mouse to keyboard to mouse. There's a
convenient array of buttons labelled A through P, representing the 16 possible
logical drives which can be connected to the ST. Changing to another drive
is as simple as single-clicking one of the 16 buttons. The START Selector
determines how many drives are actually installed, and the inactive drive
buttons are greyed-out ("disabled"). To get the current directory after
you have swapped disks, click on that drive's letter. If you double-click
one of the drive buttons, the START Selector will display the amount of
free space left on the disk in that drive.
One of the first things you'll notice about the START Selector is that it's quite a bit larger than the system's selector. The file window now shows up to 16 files at once, instead of the 9 files allowed by the GEM Item Selector. The up and down arrows, slider and scroll bar all work in exactly the same way as before. Selecting files in the window is exactly the same as before. You may either single-click a filename and then click the OK button, or double-click a filename to select it in one step. Subdirectories (folders) are entered with a single click. To back out of folders, click on the close box in the upper left of the file window.
There's another shortcut for backing out of nested subdirectories to any level or to the main directory. If you double-click on a folder name on the "Path Specification" line at the bottom of the START Selector, you will instantly back out to that level, without having to step through the folders one at a time. To back out all the way to the main directory, double-click on the drive letter or anywhere before the first backslash ("\") on that line. And, if you prefer, you may still edit the "Path Specification" line directly.
At the bottom of the START Selector's file window, you'll see a box showing the number of files in the current directory, with right and left arrows at either end. Clicking on these arrows will cause the file window to scroll through and display the size, time of last change (in 24-hour format) and date of last change for each file in the window. The file window is fully active when you're showing the size, time, or date; you can scroll up or down, enter and back out of subdirectories, or select files. Whenever you change drives or re-read a directory the file window is reset to show filenames again.
Underneath the drive buttons on the right side of the START Selector is a button labelled "*.*". Clicking on this button causes the current search specification (such as "*.DOC" or "*.PRG") to be replaced by "*.*". This is a quick way to show all files in the current directory. The previous search spec is saved in the button, so it can be replaced simply by clicking on it again.
If you try to read a directory in the GEM Item Selector that contains more than 100 files, you'll only see the first 100. For hard disk users especially, this limit can be frustrating- it's easy to accumulate more than 100 files in a hard disk subdirectory! The START Selector expands this limit to 300 files, which should be more than enough. After all, the desktop itself can only display 256 files in a window.
There is one Item Selector bug that START Selector shares - because it's a bug in the ST's operating system, not in the file selector code. If you type an underscore character on the "Path Specification" line, the system will die a horrible death. Solution? Don't type an underscore on that line! You can type underscores on the "Selection" line all you want, however. This bug is fixed in the version of TOS in the Megas (the "blitter ROMs").
Tricking The Operating System
The START Selector is written entirely in assembly language for maximum
speed and compactness. A very fast implementation of the Quick Sort algorithm
is used to sort the filenames alphabetically much faster than the Item
Selector does. If you're not a programmer, or you're not interested in
how the START Selector performs its prestidigitation, you can stop reading
now and experiment with STSELECT.PRG.
To understand how the START Selector works, we have to look at what happens at the lowest level of the system when an ST application calls an AES or VDI function. The application prepares for the call by placing various parameters into a set of arrays (one of the parameters is the number of the call), and putting the address of a table of pointers to these arrays in register D1, and a magic word ($C8 for AES, $73 for VDI) in register D0. Then the application executes a TRAP #2 instruction, which is vectored through address $88. In other words, when the 68000 encounters a TRAP #2, it jumps to the address contained in memory location $88. This address is normally somewhere in the ST'S ROM. where the system processes all AES/VD1 calls.
This is where the START Selector finds a hook to intercept the calls to the file selector. The ROM address in location $88 is replaced by the address of the START Selector code. The selector code then checks each AES call as it comes through the TRAP #2 vector, looking in each application's parameter arrays for the number of the AES fsel_input call and letting any other AES calls and all VDI calls fall through to the ROM routines.
This seemed to be a fairly straightforward procedure, but when I first began programming the START Selector, I couldn't seem to keep it installed, it would work fine for a little while and then suddenly the old Item Selector would return, with no warning, in all its hideous mediocrity. When I checked the TRAP #2 vector, it was indeed pointing at the ROM address again! Obviously GEM was occasionally replacing its address in the TRAP vector for some reason.
So out came the debugger for some very lengthy and tedious tracing through TRAPs and ROM code I finally found (three weeks later) that GEM replaced the TRAP #2 vector immediately before using a Bios call to reset the critical error vector (at $404). Therefore I decided to steal the Bios trap as well, and watch for that call to come through (setexec, #5). Now when I detect that call, I check first to make sure it's coming from the ROM (so it's not a program's call), and then replace the address of the START Selector code in $88, since I know the system has just tried to take the TRAP #2 vector back before making the setexec call. Simple and elegant? Well, no, but it passes my main criterion for evaluating software performance: it works.
If you want to examine the techniques I've used in more depth, the assembly listing for the START Selector is included on this issue's disk in the compressed file STSELECT.ARC. (Refer to the disk instructions page if you are unsure about how to unarc a file.) This code is written for the Atari macro assembler, MAD MAC, but if you wish to re-assemble it with another package it shouldn't be too hard to convert to your assembler's format.
The Wrap-Up
With its speed and convenience, the START Selector may just change
the way you use your ST forever. In fact, I predict that after you use
the START Selector just once, you'll go back to using the standard file
selector only under threat of having your ST replaced with a Commodore
64. Happy selecting!
If you'd like to see more articles like this, circle 201 on the Reader Service Card.
Charles Johnson is a professional musician. He became interested in computer programming after buying an Atari 400 back in 1980.