Classic Computer Magazine Archive START VOL. 4 NO. 6 / JANUARY 1990


Programming In BASIC

GFA BASIC Printer Driver

By Ed Frank

Print it right, print it neat, print it just the way you want with DRIVER.ARC on Side 1 of your START disk.

While the Atari ST line is compatible across the board, printers are another story. How do you make sure that users of your great new application are able to print out decent hard copies of their reports? I work for a company that programs for the IBM-compatible market; they solve the problem with a printer-driver utility that's a part of a $20,000 compiler. The end user either picks from a list of available printers or calls on us to make a custom driver for them. The GFA BASIC Printer Driver has all of the features of the "professional" driver utility, but is far easier to use. Now you can be sure that your GFA BASIC programs will work with virtually any printer.

A Printer Driver is ...

A printer driver is nothing more than a look-up table of printer control codes. Every printer accepts special character strings to tell it to print in bold face, condensed print and so forth. The GFA BASIC Printer Driver lets you create lists of any printer's control codes and read them into a set of previously defined GFA BASIC variables. As a GFA BASIC programmer, you can now treat printers in a standardized manner. As long as the user has a compatible printer driver, you can be assured that printer output will be acceptable.

The GFA BASIC Printer Driver is limited to controlling text output, since graphic output control codes can vary greatly from one printer to another. Besides, device drivers are readily available for GDOS graphic output. (Editor's Note: See this issue's companion "Programming in BASIC" column on GDOS and GFA BASIC if you want to use GDOS in your program.)

Running the Program

To run GFA BASIC Printer Driver, boot this month's START disk; the START menu program runs automatically. At the main screen, click on Prepare, then select "GFA BASIC Printer Driver." The program will un-ARC directly onto the destination disk you specify. You will find the files DRIVER.PRG, DRIVER.LST, DRLOAD.LST, DRIVERH.RSC, DRIVERM.RSC and several files with a ".PDX" extension. GFA BASIC Printer Driver was written in GFA BASIC 2.0 and runs in either medium or high resolution. DRIVERH.RSC (high resolution) or DRIVERM.RSC (medium resolution) must be in the same folder as DRIVER.PRG.

Double-click on DRIVER.PRG. When GFA BASIC Printer Driver finishes loading, you'll see the title screen. Click on the exit bar or press [Return] to bring up the main menu.

Menu Options

CREATE: Click on CREATE to bring up the Printer Parameters dialog box. Here you can enter the control codes for a particular printer in decimal, hexadecimal or character format, depending on the display setting. A separate line is provided for most of the major functions of the average dot-matrix printer.

To enter a code, select the appropriate line by using the cursor arrow keys or by clicking on the line with the mouse. The usual GEM editing functions are supported ([Esc] to clear a line, [Backspace] and [Delete] to remove characters). Separate the control codes with commas as delimiters. For example, type in "ESC," (without the quotes) if that is your printer's code for reset.

Some codes, such as page length, quite often require a numerical value to be entered after the control string. Rather than convert this number into hex or character code, you can enter a decimal value by preceding it with the number sign (#). An 11-inch page setting in hexadecimal might therefore look like this: "1B,43,00,#11". This works only in hex or character display mode, since it's unnecessary in decimal mode. You aren't required to fill in every line with codes; in fact, you might like to enter the commands for other functions on otherwise unused lines, such as ringing the printer's bell or clearing its buffer.

At the top of the Parameters box is a line for the printer driver's name. This is restricted to eight characters, since it will also be the name of the driver file. GFA BASIC Printer Driver will append the default extension of .PDX when the file is saved. Click on the SAVE button to save the driver and return to the main control panel. The driver file will be saved in the folder indicated by the SEARCH PATH option, described below. If a driver file with the same name exists in that path, it will be renamed with a filename extender of .BAK. Click on RESTORE to erase all of the entries. Click on CANCEL to exit to the main menu without saving the driver.

GFA BASIC Printer Driver makes it easy to customize your GFA
BASIC programs to print text on virtually any printer. Now, that
custom database manager you've written can be easily adapted to take
advantage of almost any custom print function available.

EDIT: Select this button to open the GEM Item Selector to choose a printer driver to edit. The Parameters box will appear with the control codes displayed in the chosen mode. This is an easy way to create a new driver, since many printers use similar codes for certain functions. Save the modified driver under a different name. In the EDIT mode, the RESTORE button will restore the codes as they were prior to any changes.

DELETE: This choice opens an Item Selector in the folder chosen by the SEARCH PATH option and lets you delete any file.

HARD COPY: Click on this button to choose either a printout of a driver's parameters or for performing a print test of the current driver. If you choose to print a driver's parameters, the Item Selector will appear. Choose a driver file and click on OK. The printout is in the same format as the Parameters screen and is a convenient way to document drivers.

If you choose to test the current driver, GFA BASIC Printer Driver will make a two-page print-out using most of the control codes of the current driver. This will let you spot any errors or conflicts in the codes. Both of these HARD COPY alternatives will work on 80-column printers.

SEARCH PATH: This lets you choose the path for saving your drivers. It will display the current path and you can choose a default path or enter a new path. The exit buttons let you choose from any of the three displayed paths.

DISPLAY MODE: Click on one of the three buttons to present parameters in hexadecimal, decimal or character format.

MAKE ACTIVE: The active driver's codes will be used during any printer output from within GFA BASIC Printer Driver. Click on this box to select a driver. The program changes the filename extender of the active driver from .PDX to .PDA and all other drivers in the same folder are renamed with the .PDX extension. Drivers in different folders can be made active, but only the active driver in the Present Path (as designated by the SEARCH PATH option) will be used for HARD COPY.

SAVE SETTINGS: Click on this button to write the path and display settings to a disk file named DRIVER.CFG. This file must reside in the same folder as DRIVER.PRG itself. The SAVE SETTINGS command does this automatically. When GFA BASIC Printer Driver is first run, it creates the configuration file with the current drive and decimal display as defaults. Your saved settings will become the defaults the next time you run GFA BASIC Printer Driver.

Using Printer Drivers

DRLOAD.LST will work with any version of GFA BASIC. The file DRLOAD.LST is an easy way to make use of the drivers created with GFA BASIC Printer Driver. Merge DRLOAD.LST into your GFA BASIC program (any version) and call Get_driver as a subroutine prior to any printing. The driver with the .PDA extension will be read into a series of string variables, named to be easy to remember and use. See the accompanying table for details. To turn wide print on, for instance, simply write Lprint Wideon$;. Lprint Wideoff$; will turn off wide print. The string variable names can be changed to suit your needs or if there are already variables with the same names. Your program listing will be more readable, however, if the driver variable names are somehow related to the printer functions they call.

Driver Loader Variable Table

Align (Reset)
Line Feed
Form Feed
Page Length
Italic Print On
Italic Print Off
Bold Print On
Bold Print Off
Double Strike On
Double Strike Off
Underline On
Underline Off
Right Margin 1
Subscript On
Superscript On
Sub/Superscript Off
Wide Print On
Wide Print Off
Draft On
10 CPI
12 CPI
17 CPI
6 Lines/Inch
Right Margin 2

When you create
a printer driver
Printer Driver,
the program
saves all of the
settings into a
special file.
program and
call the proce-
dure Get_driver
early in your
program. This
will search for a
driver with the
extension .PDA
and load it into
memory. Each
printer attribute
has its own pre-
variable whose
value is set
when the driver
is loaded. Then
you simply use
the variable to
send a code to
the printer.
Easy, huh?

Additional Notes

The driver files created by GFA BASIC Printer Driver are stored in decimal characters and can be easily modified with any text editor that supports ASCII format. The parameters are written in the same order of the Parameters box with individual codes separated by commas within any given line. A few sample drivers are included to help get you started.

(There's no reason why GFA BASIC Printer Driver cannot be used with daisy-wheel or serial printers, although I haven't tested it with either.)

You'll find that each printer has its own idiosyncrasies. Even if two printers are claimed to be Epson/IBM compatible, there most likely will be small but important differences between them. Some printers have a separate top-of-form command, while others support only a full reset. It's impossible to combine certain print modes on some printers, such as bold print and condensed (17cpi) print. You can get around these conflicts with creative control codes and pessimistic programming.

For example, instead of sending a simple Lprint Align$; to set the top-of-form, you can add commands to be sure that any previously sent settings will still be in effect. Lprint Align$; Cpi12$;Boldon$;, for example, will set the top-of-form, 12cpi and bold print. Doublestrike print will often work in conjunction with print modes that refuse to operate with bold print.

To make your programs compatible with as many printers as possible, you'll find it best not to combine too many print characteristics at once and to cancel them and reset any original values when they're no longer needed.

We hope GFA BASIC programmers will see DRIVER.PRG as a new standard in printer drivers, and that they will support this format. You may use the code to load a printer driver (DRLOAD.LST) in any program you write (commercial or public domain) provided the Antic copyright notice remains on the program. Additionally, any printer driver you create using DRIVER.PRG may be freely distributed. End users: after you create a printer driver, make sure the file extension is .PDA. Now you can use your printer driver with any program that uses the DRIVER.PRG standard.

Ed Frank lives in New London, New Hampshire. This is his first program for START.