From: zben@ni.umd.edu (Charles B. Cranston)
Subject: Re: PAP - where is programming info?
Organization: UM Home for the Terminally Analytical
Date: Mon, 6 Apr 1992 21:21:51 GMT

In article <5880@uakari.primate.wisc.edu>, bin@primate.wisc.edu
(Brain in Neutral) writes:
 
> What do I read to find out how to use Printer Access Protocol?
> Inside Macintosh doesn't say much about it.  Inside AppleTalk (2nd
> edition) discusses it at length, but from an abstract viewpoint (e.g.,
> no data structure listings or function call prototypes).  I grepped
> through my THINK C *.h files for "PAP" to no avail.

There were several articles in the first and second year of MacTutor
that convered the programming interface.  Here's some C I recently
wrote that (klugily) calls them:


/* Printer Access Protocol (PAP) routines.
 * Note: there is one extra argument at the end of each argument list.
 * The actual call passes a pointer to the locked code and the assembly
 * (actually hex) code here pops it off and jumps to it.
 */

/* Open connection to PAP printer over the (appletalk) network.
 */
pascal OSErr PAPOpen(
	short *refnum,			/* PAP refnum returned here */
	char *printername,		/* NBP entity name of printer to open */
	short flowquantum,		/* Max data in flight (512 byte blocks) */
	struct papstatus *statusbuf,	/* Monitor status */
	short *compstate,		/* Monitor status */
	Ptr papptr			/* Artifact of calling scheme */
       ) = {
	0x205F,				/* Move.L (A7)+,A0  ; Get pap pointer */
	0x4E90				/* JSr    (A0)      ; Call at offset 0 */
};

/* Read a block of readback data from the printer.
 * Even though we don't look at the data we still must do this
 * lest the printer drive protocol hang on returning us data.
 * We are interested in the EOF because this means the last page got out.
 */
pascal OSErr PAPRead(
	short refnum,			/* PAP refnum */
	char *buffer,			/* Pointer to buffer for incoming data */
	short *length,			/* Length of data returned here */
	short *eof,			/* EOF flag returned here */
	short *compstate,		/* Monitor status */
	Ptr papptr			/* Artifact of calling scheme */
       ) = {
	0x205F,				/* Move.L (A7)+,A0  ; Get pap pointer */
	0x4EA8, 0x0004			/* JSr    4(A0)     ; Call at offset 4 */
};

/* Write a block of data to the printer
 */
pascal OSErr PAPWrite(
	short refnum,			/* PAP refnum */
	char *buffer,			/* Pointer to outgoing data */
	short length,			/* Length of outgoing data */
	short eof,			/* EOF flag */
	short *compstate,		/* Monitor status */
	Ptr papptr			/* Artifact of calling scheme */
       ) = {
	0x205F,				/* Move.L (A7)+,A0  ; Get pap pointer */
	0x4EA8, 0x0008			/* JSr    8(A0)     ; Call at offset 8 */
};

/* Asynchronously probe status of printer
 * (unused here, just included for completeness
 */
pascal OSErr PAPStatus(
	char *printername,		/* NBP entity name of printer to check */
	struct papstatus *statusbuf,	/* Monitor status */
	struct addrblock *netaddr,	/* "Hint"network address to try */
	Ptr papptr			/* Artifact of calling scheme */
       ) = {
	0x205F,				/* Move.L (A7)+,A0  ; Get pap pointer */
	0x4EA8, 0x000C			/* JSr    12(A0)    ; Call at offset 12 */
};

/* Close connection to the printer
 */
pascal OSErr PAPClose(
	short refnum,			/* PAP refnum */
	Ptr papptr			/* Artifact of calling scheme */
       ) = {
	0x205F,				/* Move.L (A7)+,A0  ; Get pap pointer */
	0x4EA8, 0x0010			/* JSr    16(A0)    ; Call at offset 16 */
};

/* Close all connections and prepare for unload of PAP code.
 */
pascal OSErr PAPUnload(
	Ptr papptr			/* Artifact of calling scheme */
       ) = {
	0x205F,				/* Move.L (A7)+,A0  ; Get pap pointer */
	0x4EA8, 0x0014			/* JSr    20(A0)    ; Call at offset 20 */
};