Printing Interface
Volume Number: 4
Issue Number: 8
Column Tag: Fortran World
Fortran Printing Interface
By Jay Lieske, La Canada, CA
In Absoft FORTRAN version 2.3 one usually must employ Absoft’s special routine
called PrPort.sub in order to use the Printing Manager on the Macintosh. PrPort.sub
employs the old RAM-based printing manager, but recent trends suggest that it would
be better to use the printing traps accessible through “_PrGlue” at $A8FD since these
routines are now in ROM and contain special routines such as PrGeneral that are
unavailable in the RAM-based printing manager. In addition, PrPort.sub, which is
written in assembly language, is limited to the hard-coded routines which existed at
the time Absoft developed the routine and is thus not extendible. Since usage of
PrPort.sub will undoubtedly limit the development of FORTRAN programs on the
Macintosh, it is of interest to see how one might use Absoft’s Toolbx.sub in order to
implement the new ROM-based printing manager traps.
The Toolbx.sub routine from Absoft employs an encoded ‘trap dispatch’ LongInt to
describe the toolbox or OS trap number, as well as to describe the parameters required
for the toolbox or OS calls. The new printing traps accessible through the _PrGlue
trap at $A8FD require that a special ‘routine selector’ be pushed onto the stack prior
to the $A8FD trap instruction. Hence, if we are to succeed in using the print traps, we
must be able to insert this routine selector number onto the stack.
By studying and disassembling Absoft’s Toolbx.sub it was found that the routine
selector parameter could be put into the Toolbx.sub call as the final parameter (i.e. the
parameter just before the final closing parenthesis) and that it would be pushed onto
the stack just before Toolbx.sub executed the trap number. In order to instruct
Toolbx.sub that there was another parameter for it to pass, however, the ‘trap
dispatch’ code had to be modified. That is where the disassembly of Toolbx.sub became
important because current Absoft documentation is not always correct on this matter.
We have developed the include files ‘prtrap.inc’ and ‘PrGenDefs.inc’ which can be
used with Absoft Fortran’s Toolbx.sub in order to implement the print traps. A
similar method could be employed for any other new traps (or traps and additional
routine selectors’) that Apple develops. The file ‘prtrap.inc’ contains the encoded trap
dispatch number and the routine selector for all the new print traps documented in
Inside Macintosh Volume V. The routine selector for PrGeneral, which inadvertently
was left out of Inside Mac, was found in Lightspeed Pascal’s equates as $70070480.
We also include a file ‘PrGenDefs.inc’ which contains the equates required for use of
the PrGeneral gateway, potentially a very useful new trap which enables one to check
and to set the resolution of the printer in use.
To demonstrate how the Toolbx.sub traps are implemented in a program, first
consider the Pascal calling-sequences as documented in Inside Mac. Suppose that a trap
‘PrRoutine’ is documented by Apple as being implemented like this in Pascal:
PrRoutine(Arg1, Arg2,...,Argn);
then the Toolbx.sub routine in Fortran would be employed as follows:
call Toolbx( PrRoutineCode, Arg1, Arg2,...,Argn,
xPrRoutineCode)
if the toolbox trap is a procedure. If the toolbox call is a function then the Pascal
version would be
Result := PrRoutine(Arg1, Arg2,...,Argn);
while the Toolbx.sub Fortran version would be
Result = Toolbx(PrRoutine,Arg1, Arg2,...,Argn,xPrRoutine).
The analogous calls using prport.sub for a subroutine would be: call
PrPort(Code, Arg1, Arg2,..., Argn). Programs which currently employ PrPort could
readily be changed simply by replacing PrPort with Toolbx and appending the
‘xPrRoutine’ parameter.
An example program ‘demotrap.for’ is included for implementing the new print
manager trap-based calls. The program does not actually do any printing, but shows
how one can access the print record and query the printer for variable resolutions.
Just use the Chooser to select your ‘printer’ and then the usual dialogs will come up on
screen to demonstrate that everything works as advertised. A colleague has employed
these new traps in a large plotting package which was ported over to the Mac from a
mainframe computer and the results are quite satisfactory.
Listing One: Demonstration Program
program demotrap
C See if can use ‘Printer traps’ via $A8FD PrGlue and TOOLBX.sub
C A simple sample program demonstrating its capability for Absoft
Fortran 2.3.
C This program does not actually do any printing.
C J. Lieske 12/87
C * * * * * * * * * *
* FUNCTION PTR (ANYTYPE) : PTR; ; A ‘funny’ trap.
INTEGER PTR ! from Absoft’s MISC.inc
PARAMETER (PTR=Z’C0000000')
integer NEWHANDLE
! from Absoft’s MEMORY.inc
parameter (NEWHANDLE=Z’122000A8')
integer iPrintSize
! The Print record size.[120 bytes]
parameter (iPrintSize=120)
! from Absoft’s PRDEFS.inc
C * * * * * * * * * *
C GRXMX0 : default x size (pixels). These will be taken from the
print record
C GRYMX0 : default y size (pixels)
C GRXPIN : pixels per inch in x
C GRYPIN : pixels per inch in y
REAL GRXPIN, GRYPIN
INTEGER GRXMX0, GRYMX0
INTEGER*4 TOOLBX
! MAC TOOLBOX INTERFACE
x integer*4 debugger
! just in case you want to use MacsBug
x parameter (debugger=z’9FF00000')
x call toolbx(debugger)
! put the call where it’s needed
*
* INITIALIZE THE PRINT RECORD FOR THE MACINTOSH
*
integer*2 iversion
integer*2 ernum
* PRINT MANAGER FUNCTION DEFINITIONS for toolbox-based traps
include prtrap.inc
include PrGenDefs.inc
INTEGER PRRECHDL
! HANDLE TO THE PRINT RECORD.
INTEGER POINT
! DEREFERENCED HANDLE
LOGICAL OK
write(*,*) ‘This program demonstrates printer traps in
Fortran.’
write(*,*) ‘It won’’t actually print anything, but shows how
to’
write(*,*) ‘access the printer traps in Absoft Fortran.’
write(*,*) ‘It will write the data out to ‘’output.fil’’’
write(*,*) ‘so you can read it.’
call toolbx(propen, xpropen) ! PrOpen
PRRECHDL = TOOLBX(NEWHANDLE, IPRINTSIZE) ! GET A PRINT RECORD
HANDLE.
call toolbx(printdefault,PRRECHDL,xprintdefault) ! get
defaults
C get printer version number