Dot Printer
Volume Number: 5
Issue Number: 10
Column Tag: Advanced Mac'ing
Dot Matrix Printer Driver 
By Earle Horton, Hanover, NH
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
A Dot-Matrix Graphics Printer Driver
This article describes a Macintosh printer driver for use with a Tandy DMP-110
dot-matrix printer. The printer resource file is written to be device-dependent, but
it can serve as a skeleton for creating printer files for other devices. The routines to
translate QuickDraw BitMaps to DMP-110 graphics codes are localized, so that one
would only have to rewrite a few routines to create a driver for another dot-matrix
printer. The printing code is in a combination of assembler and C, and may be
compiled with either MPW C and Asm, v 2.0.2 or Aztec cc and as, v 3.6c. All files
necessary for compilation with either system are included, but the Aztec-specific files
assume that you have the MPW Shell, MPW Make, and Rez.
This driver implements the Print Manager high level printing calls, so that any
Macintosh application which uses them can print on this printer. I attempt to emulate
as closely as possible the ImageWriter driver in high-resolution (Best) mode, subject
to the physical limitations of the printer. I provide portrait mode printing only, with
a choice of scaling factors. Anyone who has taken a college math course will recognize
the spirit of the following sentence: “I leave Landscape Mode printing as an exercise
for the reader.” The driver also implements two low-level procedures to dump
BitMaps to the printer, so that command-shift-4 will work.
The printer file is missing some features which can be found in Apple printer
files. It does not implement the driver’s low-level BitMap proc or, indeed, any of the
low level printing calls. Users of most applications will not notice this lack, since few
applications use low level printing. It does not participate in text positioning and
measuring or “line layout” as do Apple printer drivers. This means that although the
printer file works well with screen fonts like Geneva and New York, LaserWriter fonts
like Times and Courier sometimes give it problems. This is a feature which should be
added, but it might take lots of code to do it right.
The code used in the printer file does not access low memory globals, except as
these are used in library routines. It does not use any development- system-specific
tricks to obtain “global” variables for the driver or for any of the code resources used
in the driver. It does not use hard-coded numbers for the ioRefNum of the serial port
or of the printer driver, but rather opens drivers by name. Any access to the Print
Manager, e.g. to set or detect a printer error condition, is done through glue routines
or through the PrGlue trap. In view of these precautions, the code should be fully
capable of being used with other development systems, and should be compatible with
future releases of Apple System Software, providing Apple does not change the
interface to printer files too much.
The Printer File:
This section describes the resources you must create in order to implement a
driver of this type. The structure of a printer resource file was described in my
previous article (MacTutor Volume 3, Number 11 and 12), so I will give the
resource list here, arranged roughly by function, and only describe the contents
briefly. (You can get a list like this using MPW Rezdet with the “-l” command line
option.)
DMP-110 Resource List
‘PDEF’ (0, Purgeable, Locked) # Code resources
‘PDEF’ (4, “Dialogs”, Purgeable, Locked)
‘PACK’ (-4096, “Chooser Device”, Purgeable, Locked)
‘DRVR’ (-8192, “.XPrint”, Purgeable, Locked)
‘HEXA’ (-8192, “Printer Settings”) # Port settings
‘ICN#’ (128, “DMP-110”) # Bundle
‘FREF’ (128)
‘Dmp1’ (0)
‘BNDL’ (128)
‘STR ‘ (-4092, “Right Button”) # For device package
‘STR ‘ (-4093, “Left Button”)
‘STR ‘ (-4091, “List label”)
‘STR#’ (-4080, “Baud Rates”)
‘DITL’ (-8191, “Job dialog tempplate”) # Style and Job dialogs
‘DITL’ (-8192, “Style Dialog Template”)
‘DLOG’ (-8191, “Job Dialog”)
‘DLOG’ (-8192, “Style Dialog”)
‘DLOG’ (-8190, “Next Page Box”) # Miscellaneous
‘DITL’ (-8190, “Next Page Template”) # dialogs and alerts
‘ALRT’ (-4079, “Sys41Alert”)
‘DITL’ (-4079, “Sys41 Items”)
‘ALRT’ (-4078, “ATalk is on!”)
‘DITL’ (-4078, “ATalk Items”)
‘ICON’ (-4080, “DMP-110”)
‘PREC’ (0, “Default Scale”) # Print Records
‘PREC’ (1, “Last Used Print Record”)
‘PREC’ (2, “Shrink To Fit”)
‘PREC’ (3, “Exact BitMap”)
‘PREC’ (4, “Compatible”)
Four code resources are included. The printer driver (‘DRVR’ -8192) and the
dialog code (‘PDEF’ 4) are necessary to any printer resource file. At least one type of
printing code (‘PDEF’ 0, here) is also necessary. The Chooser device package,
(‘PACK’ -4096) is necessary if we wish to have adjustable settings which are not
logically part of the standard Style and Job dialogs. A ‘HEXA’ resource is included to
save global settings; it is quite small.
The Chooser device package uses both buttons, and displays a string list of baud
rate names in the Chooser’s list box.
Four unique Print Record resources (‘PREC’) are used here, for four different
printing styles. The same paper style is used in all four of them, but different scaling
methods are used to obtain different printing effects. ‘PREC’ number 1 is used to store
the last-used Print Record.
The rest of the resources are used in the dialogs and alerts, and the
Bundle-associated information is used by the Chooser to display our printer file.
Informative alerts and dialogs are provided for sheet feeding and for problem
situations. An ICON resource containing the printer file icon is used to assure user
identification of exactly who is putting up an alert. Alerts which might be displayed by
the Chooser device package are given resource numbers which are in the legal range
for the device package to use. Other Alerts and Dialog resources are given resource
numbers belonging to ‘PDEF’ #0.
Cast of Characters: The Files
This section shows the source files used to build the printer resource file, and
the icon used by my printer file.
The files with the ‘Manx’ icon (“Z”) are used in creating the Aztec version of the
printer file. The files with the MPW icon are for use with MPW C and Asm. The
“Anonymous” files are for use with both systems. All are ‘TEXT’ files, with the
exception of the printer file. Intermediate object, code and resource files are not
shown.
Different source files exist for Aztec and for MPW for a number of reasons.
Assembler syntax is different, so each system has its own “Glue” source file.
Compiler and linker options, as well as mechanics of making the project, differ. Thus
the two Make files. (Both use MPW Make, however.) The “Final.r” file is different
between the two systems because the Aztec linker refuses to create a non-’CODE’
resource with ID zero, and it is more convenient to change this ID using the resource
compiler. Finally, the file “AZHeaders.c” is used to create a precompiled header file
for the Aztec C compiler. MPW C v 2.0.2 has no such feature.
Common files include two C language header files, a resource definition file, and
four C language source files. The bulk of the project code is in C; the assembler files
provide necessary headers for code resources, as discussed in the 1987 article.
This project uses the Pascal interface to all ToolBox routines, as introduced in
MPW C, version 2, and as described in Appendix H of the MPW C manual. An esthetic
problem with this approach is that it requires the programmer to type in certain