GFA BASIC SOURCE CODE PRINTER OR COLUMN-AID
by Travis E. Guy
GFA BASIC Source Code Printer (SCP for short) is a simple utility I wrote after first seeing the lengths of some of the listings made by GFA BASIC. Since GFA BASIC programs are restricted to one command per line, their listings tend to be narrow and long, hugging the left-hand side of the printout. A tad wasteful, it would seem.
Why not put all that clean white space on the right-hand side of the paper to use? I wondered. Saving paper has both an economical and an ecological angle to it. "No doubt about it," my programming alter ego said, "this calls for a program. SCP!"
SCP is quite straightforward, and fairly modular in design but not overly so. All it does is read in lines from GFA BASIC source code files (the ones listed as ASCII files, with .LST extensions) from disk, store them in a string array and print them out in a one-, two- or three-column format. And at no extra charge, it'll even do it in up to any one of three type sizes. No whiz-bang displays here—SCP's not graphics dependant—so it should work in all resolutions. Just load the GFA BASIC interpreter, type in the listing, save it to disk, then select "Run" from the GFA menu bar.
What SCP does and what you should do
After a few strings are defined and cheerful greeting extended, a file-selector box asks you for the name of the file you wish to print. SCP checks for three things here:
- that you did enter a filename,
- that the file requested is on the drive specified,
- that the file has a .LST extension.
No other checks are made on the validity of the file. SCP cannot tell if it is being asked to print a non-text file. Any attempts to make it do so may cause grievous trouble to befall you and your loved ones. The best that could happen is that you'll end up with pages filled with gibberish. So please don't try it, okay?
Next, the program calls a procedure to check whether a printer (attached to the ST's parallel port) is online and ready to accept data. If not, an alert box will notify you to check connections and ask whether to recheck or abort the listing. Some housekeeping chores are then performed, and its off to. . .
Alert boxes will prompt you for the desired number of columns and, following that, the size of the characters of the listing. SCP was written to run on a Star Micronics SG-10 printer in IBM mode, and the three size choices here are pica (10 cpi), elite (12 cpi) and condensed print (17 cpi). The size of each column is calculated via a procedure, and the correct initialization codes are sent to the printer.
The number of characters per line for the different type sizes used at this point in the program reflect a ten-inch printer carriage. For those of you with carriages of different sizes, change the values assigned to Length % in all three occurrences.
If you are using single-sheet paper instead of fanfold, you may opt to pause the listing between pages. Saying yes sends a command to the printer to ignore out-of-paper signals. This frees you from pesky bells, beeps, chirps and whatever else printers do when they unexpectedly run out of paper.
Some final fiddling bits are then taken care of before the program starts earning its keep. The string array that holds each page of the listing, Page$( ), is dimensioned, counting variables are set, and the program tells the world it is going to work on the first page. For those fascinated with GEMs, the mouse pointer is changed to the Busy Bee.
The heart of the matter
Now you've arrived at SCP's main section; a three-function loop that should be no trouble to follow. Simply put, it reads in lines from the file, chops them up if needed to fit the columns and calls a procedure to print the array. This cycle continues for each page of the listing, until the end of file is reached.
To avoid confusion over where each program line ends, SCP appends an end-of-line delimiter (a character that isn't normally entered from the keyboard) to show exactly where the carriage return falls. In the same vein, the columns are bracketed with marks to indicate where each column line begins and ends.
When the main loop fails its end-of-file check, the printing procedure is called one last time, and then control jumps to a clean-up routine. A reset code is sent to the printer, the file is closed, and you are asked if you want to print anything else. If not, SCP comes to a gracious halt.
Watch it flex
SCP doesn't require any external printer driver, but does rely on certain assumptions. It is set up for 66 lines per page, out of which it uses 60 lines for the listing, allowing it to skip perforations. However these figures can be easily changed; SCP is very flexible when it comes to printers.
The printer codes to change type size, to reset the printer when finished, to switch off out-of-paper detection and to choose the characters used for carriage return marks and column separators are all located at the beginning of the program, and can be altered to suit individual needs and tastes. And, yes, even the number of columns and lines and the width of each column can be changed without much difficulty. I have used descriptive variable names throughout SCP, as well as descriptive labels, procedure names and the odd comment or two, in an attempt to try and convey a sense of what is going on.
Writing SCP was a breeze with GFA BASIC. Hopefully, you will find the program useful and as easy to use as it was to create.