MPW Partial Redirection

This example demonstrates the usefulness of named markers, combined with input/output redirection from/to part of the contents of an MPW window, to automate a complex program build. It dates from the days of Level 1 PostScript, when the printers all had Motorola 68K processors in them. This meant that you could use existing Macintosh compilers and assemblers to cross-compile code for loading into the printer, which let you commit some interesting hacks indeed.

The example involves compiling and linking a piece of code, then automatically inserting it into a testbed PostScript program, ready for the whole thing to be downloaded to the printer and executed. I'll go through the build commands step-by-step.

First is a relatively straightforward-looking Link command, to build the object files into a resource containing executable code:

This command constructs a resource of type "CEXE" and ID 128, named "Main" (the type, ID and name are all arbitrary). The first object file CexecHeader.o, contains the fixed-format header as required for loading into the printer, though some fields need to be computed and filled in later. The remaining .o files contain the actual code and common libraries.

The next command:

opens the testbed PostScript program, in the file NewCallsTest.ps. The "Target" command makes the window second from the front (which allows you to affect it by executing commands in the frontmost or active window).

This file has a marker previously set in it, called "Cexec", which identifies the portion of the contents which are to be replaced with the newest version of the machine code to be downloaded. This command

sets the current selection in the target window to the text delineated by that marker. Here is how the PostScript file appears at this point, with the current selection highlighted in green:

The last command runs a custom MPW tool I wrote, called Prepare. This takes three arguments: the name of a resource file, and the type and ID of a resource in that file. It reads the resource, fills in the checksum and length in the header fields, encodes the result as hex (including some simple PostScript wrapper code) and writes it to its standard output:

which, in this case, happens to be redirected to the current selection ("") in the target window!

Created by LDO 1997 August 7, last modified 1997 August 16.

Back to MPW Intro