Printer Driver
Volume Number: 3
Issue Number: 11
Column Tag: Advanced Mac'ing
How to Write a Printer Driver 
By Earle Horton, Hanover, NH
Writing a Simple Macintosh Printer Driver
Part 1: Overview
A Macintosh Printer Resource File is a file containing resources to emulate
QuickDraw drawing commands on a printer or other remote device. This article
describes how to write a Printer Resource File which implements text-drawing
commands only on serial dot matrix and daisy wheel printers. The printer file is
installed using the Chooser in the same manner as one would install the ImageWriter
or LaserWriter file. The printers which are serviced by this printer driver are
assumed to be capable of printing in only one font, which is mono-spaced. An ability is
included in the printer driver to change serial port settings and printer control
strings, so that a large number of different types of printers may be used with one
driver. In addition, it is shown where more advanced drawing commands (graphics and
proportional fonts) would fit into the structure of the Printer Resource File. This
Printer Resource File was written, from scratch, by the author in two weeks. I am not
a professional programmer, or even a registered Macintosh developer. I feel that the
dearth of Printer Drivers for the Macintosh is due more to apparent, rather than real,
difficulties in writing them.
I wrote my Printer Resource, which I christened Daisy, using LightspeedC for
the code resources and RMaker for the data resources in the file. The table below
summarizes all the resources in my Printer Resource. Most of these follow the
standard types and IDs used by Apple, but some are particular to my implementation.
Printer File Resources and Function (Public)
Type ID Function
''DRVR’ -8192 Device driver: performs low-level
printer calls and maintains storage
‘PREC’ -8192 Driver’s private storage
‘PREC’ 0 Default print record
‘PREC’ 1 Copy of last used print record
‘PDEF’ 0 Draft mode printing routine
‘PDEF’ 1 Spooling routine (not used)
‘PDEF’ 2&3 Printer specific printing code (not used)
‘PDEF’ 4 Code for handling printing dialogs
‘PDEF’ 5 Spool file printing routine (not used)
‘PACK’ -4096 Chooser interface code, used for
device configuration
‘STR ‘ -8191 Default spool file name
‘STR ‘ -4096 Type name for AppleTalk devices (not used)
‘STR ‘ -4093 Title for Chooser left button (not used)
‘STR ‘ -4092 Title for Chooser right button
‘STR ‘ -4091 Chooser list label
‘STR ‘ -4090 Chooser reserved string (not used)
‘DLOG’ -8192 Paper Style dialog
‘DITL’ -8192 Paper Style dialog template
‘DLOG’ -8191 Paper Job dialog
‘DITL’ -8191 Paper Job dialog template (Private)
‘DLOG’ -4080 PACK resource installation dialog
‘DITL’ -4080 Installation dialog template
‘Stng’ -8192 Private type, printer settings
‘STR#’ -4080 Printer control string list
‘BNDL’ 128 For the file’s icon
‘DasY’ 0 File creator, resource is a ‘STR ‘
‘FREF’ 128 For the file’s icon
‘ICN#’ 128 Icon and mask
‘DLOG’ -8193 Sheet feed dialog
‘DITL’ -8193 Sheet feed dialog template
The Printer Resource file contains a fairly large number of resources, but each
one has a well defined function. All of the “public” resources have type names and ID
numbers rigidly defined by Apple, and also specific formats. The private resources
should have ID numbers of “owned” resources, owned by either the driver, one of the
‘PREC’ resources, or the ‘PACK’ resource so as not to conflict with any application
resources. The file must have a ‘BNDL’, ‘FREF’, ‘ICN#’, and creator resource in
order to appear in the Chooser display. This printer file uses the Chooser interface
code, ‘PACK’ -4096, so it therefore needs to be installed with the Chooser, and not
Choose Printer.
This printer resource file is of type ‘PRER’, or ‘non-serial printer’, so that it
can use the Chooser interface to query the user for application-independent
installation parameters. These include the baud rate, what kind of flow control to use,
and some printer control strings. If your printer resource does not need to use the
Chooser interface, then you can make it of type ‘PRES’, or serial printer, and the
Chooser will take care of all details of installation. If you do it this way, then the
Chooser will put the user’s choice of serial port in parameter RAM, so that your
printer driver can find it later.
The Printer Resource File contains a number of resources containing pure
68000 (or 68020) machine code. The ‘DRVR’ handles low-level Printing Manager
calls, while the ‘PDEF’ resources handle high level printing. It is possible to define up
to four different kinds of high level printing, but it is only necessary to provide one.
The ‘PACK’ resource contains a single routine to handle the printer installation
process. I wrote all of my code resources using LightspeedC, and used some InLine
assembly to format the headers of the resources where required. There are some
requirements which must be met by the development system used. The development
system must be capable of producing stand alone code resources, and must allow you to
specify the format of the code resource header. The development system must also be