PostScript
Volume Number: 2
Issue Number: 9
Column Tag: Networking
A PostScript Driver in LightSpeed C 
By Bob Denny, Alisa Systems, Editorial Board
[This article by Bob Denny, a distinguished member of the MacTutor Editorial
Board of Directors, presents a driver that allows simple writeln statements from a high
level language to output directly to a LaserWriter in Postscript over AppleTalk, which
makes the laser a quick and convenient printer device the same way you might use an
ImageWriter! To do this, we "steal" Apple's code from the LaserWriter file that already
knows how to talk to the Laser and simply provide a machine language interface to it.
Then we write a device driver in LightSpeed C, and finally, our Pascal application can
simply open the driver and print to it. An example of how to open and write to a device
driver is given in MacPascal and TML Pascal. Finally, calling drivers is explained by
presenting examples using standard file I/O, the high level device manager calls, and
the low level device manager calls. This article is a significant contribution to both
device drivers in general, and the LaserWriter in particular. Thank you , Bob! -Ed.]
A PAP Driver for the LaserWriter
Alan Wootton played a dirty trick on me for my birthday last month. He bought
me a copy of SmallTalk-80 for the Macintosh. I had made some comment about being
interested in it, trying to learn about it from the Addison-Wesley books (and failing
miserably), and just getting a Mac+ so I could run it, etc. Well, I ended up getting
totally sucked in.
I soon became frustrated at my inability to print to our LaserWriter from
SmallTalk-80. I wanted to catalog the message protocols for some of the most common
classes (“numbers”, for instance). I thought, “Here is a reason to learn
SmallTalk-80 and PostScript all at once!" Alan knows how my mind works, because he
called me up moaning about not being able to print to his LaserWriter. That did it. My
aging brain needed a good workout, so
It seemed hopeless to try to interface to the Print Manager from SmallTalk-80.
Rather, I decided to build a driver which would support direct communication with the
LaserWriter via the Appletalk Printer Access Protocol (PAP). Once the driver was
done, I could then go into SmallTalk-80 and modify it to print using PostScript. The
Mac implementation of SmallTalk-80 has an interface to the device manager and it could
be used to send PostScript to the “chosen” LaserWriter via the driver. In fact the
driver could be used from other interpretive languages such as MS Basic or MacPascal.
This article reviews the PAP manager, including an enhancement in the newest
version, and describes the “PAP Driver” along with an example using Mac Pascal. It
does not describe PAP itself (that will be the subject of a future article).
The PAP Manager Revisited
Refer to the "Laser Print DA for Postscript" by Mike Schuster, in the March
1986 issue of Mac Tutor. In that article, Mike describes the PAP manager and how to
build a desk accessory that will transmit the contents of a file to the LaserWriter.
PAP, or Printer Access Protocol, is a combined application and session level
protocol which is used to communicate with the LaserWriter over Appletalk. It uses
ATP (Appletalk Transaction Protocol) for error and flow control.
On the Macintosh, PAP is implemented in a “code” resource, not as a driver. The
original Inside LaserWriter describes an interface to PAP that was apparently never
released. Last year, Bill Parkhurst and Mike Schuster dove into the “LaserWriter”
resource file and found that the PDEF-10 resource contains the code that handles PAP
communications, the PAP Manager. It turned out that the interfaces to the routines in
the PAP Manager look just like those described in Inside LaserWriter, except that the
routines are vectored through a list of jumps at the beginning of the code resource.
The interface is quite straightforward. There are basic calls for “open”,
“close”, “read” and “write”. These functions operate in the context of a session, a
private connection between the client (Mac) and the server (LaserWriter) that may
last for the duration of several jobs.
There is a “status” call that generates a one-shot status request to the server, to