PrLink
Volume Number: 1
Issue Number: 9
Column Tag: Programmer's Forum
"PrLink Source for MacAsm
By Paul F. Snively, MacTutor Contributing Editor
Well, if you have been following MacTutor for any length of time, you are
probably aware that we are dedicated to the proposition that the Mac can be
programmed with any of a number of languages that are available for the Mac, on the
Mac.
What does it mean to program the Mac, though? Much has been made of the
"standard user interface guidelines," which is a fancy way of saying that Apple
Computer, Inc. thinks that all Mac applications should bear at least a passing
resemblance to each other. From the user's point of view, this is a Godsend.
If you have read Inside Macintosh you are aware that there are at least three
things that Apple says should be consistent from application to application: the apple
menu, the file menu, and the edit menu.
Several people have gone into detail as to how to create a full-featured apple
menu and edit menu for Mac applications. More recently, the "Open..." option (i.e. the
standard file interface) has gotten a close look. Until now, however, no one has really
looked at the obvious remaining element in a Mac application, namely, the "Print...
option.
I'm going to dodge the menu setup; I detest reinventing the wheel. If you are
unsure as to how to create a "Print..." menu option which prints the current document
associated with your application, I suggest that you get some MacTutor back issues and
start reading. I am only going to concern myself here with the actual printing of text
and graphics from within an assembly language application.
PrLink Source Missing
If you are using the release version of MDS, you are probably wondering what the
big deal is. After all, MDS includes a file called PrLink.Rel which can simply be linked
into your application and provides support for all of the printing manager routines.
This is entirely true. If you are using MDS, don't bother to continue reading unless the
theory behind the printing manager interface interests you, because the code is
written for MacASM owners, who weren't blessed with a canned interface to the
printing manager. [Note that Apple did not supply the source code to PrLink.Rel. How
come? -Ed.]
Allow me to editorialize for a moment here. (Contributing editors can do that,
can't they)? There is probably no area of the toolbox (if it can properly be called
"part of the toolbox") that is so shrouded in mystery as the printing manager. The
only program that I own that actually works through the printing manager is
MacWrite (well, perhaps MacPaint does too, although I think it works at a lower level
than MacWrite does). Of all of the development tools that I own, NOT ONE of them uses
the printing manager -they simply open the serial port and start sending ASCII codes
out. This is hardly the most device- independent way of doing things; as David Smith
has noticed, that technique tends not to work with the LaserWriter, for example. So, it
is important to work through the printing manager for reasons of compatibility, as
well as to have the ability to use the font manager and Quickdraw to create graphics on
the printer.
The primary reason that the printing manager is so neglected is that, unlike most
areas of the toolbox, there is virtually no correlation between how the printing
manager is accessed in PASCAL and how it is accessed in assembler (once again, unless
you are using MDS - but even at that PrLink.Rel won't win any awards for being
well-documented). In PASCAL, you simply use the appropriate functions and/or
procedures, giving the proper parameters - no big deal. In assembly, though, you
must deal with the printing resource file, overlays, dialog boxes, and so on - right
down at the nuts and bolts level. The code that follows is my attempt to provide much
the same easy access to the printing manager routines as PrLink.Rel does for MDS
users.
Code Resources
If you have been following the whole discussion about resources, you have
probably become aware that they are found (for the most part) in two places: within
the application's file and within the system resource file (called, aptly, "System").
What you may or may not be aware of is that your application can also open other
resource files to draw needed resources from. Opening resource files creates entries
in a linked list - the most recently opened resource file is the first one searched, with
the application itself being second to last, and the system resource file last.
The printing manager routines exist as resources in the printing resource file.
Since resources can be executable code, Apple decided to use that approach (probably
in order to allow for device independence as far as printers go - it'd be mighty hard to
support a laser printer if the printing manager routines were in ROM). Interfacing to
the printing manager consist of loading these resources as necessary and executing the
code within them.
My Own PrLink Source
The "Print.Asm" code takes care of all of the dirty work for us by giving us the
same routines as PASCAL users have. These routines can be described as follows:
The PrOpen routine opens the printing resource file and also opens the printer
driver for us. We can then use the driver directly or through the high-level printing
manager routines.
The PrStlDialog function is most commonly associated with the "Page Setup...
menu option. It allows the user to describe the page to the computer.
The PrJobDialog function is the one that is actually invoked upon choosing