System File
Volume Number: 3
Issue Number: 8
Column Tag: Resource Roundup
Sleuthing the New System File
By Joel West, Contributing Editor
This month, I’m going to talk about the new traps available in System 4.1 under
the Macintosh Plus -- and, to a lesser extent, the 512, SE and Macintosh II. (When I
sat down to write this article, I wanted to call it “Trapping System Compatibility”, or
“Seeking the Compatibility Trap,” but finally decide to give up on the puns.)
This all started when I was working on my book, Programming with Macintosh
Programmer’s Workshop (due to be published by Bantam this month.) I wanted to
include an up-to-date list of traps; in particular, I wanted to pull together all the
traps and indicate exactly when it was safe to use them. (If you have the book already,
I’m referring to Appendix E.)
At the time I was writing the appendix, all I had was the APDA draft for Inside
Macintosh, Volume V, which described new features developed for the Macintosh II.
After the draft was published, many of the features described for Mac II were
retrofitted for the Plus. For the Macintosh SE, some of the new stuff made it before the
SE ROM was frozen (several months before the II), while other stuff also had to be
retrofitted.
I have a fastidious pre-occupation for detail, and sometimes I get carried away.
In this case, what started out as a simple exercise ended up being a rather elaborate
endeavor. I probably spent 10-15 working days over three months trying to get the
exact answer to exactly which trap is available when. I ended up testing five different
System files on the Mac 512, Mac Plus, Prodigy 4, Macintosh SE and Macintosh II. I
didn’t test all possible combinations, but all the valid ones for the Mac Plus, SE and II,
and all but one (System 3.3, very similar to System 4.0) for the Macintosh 512.
My work was assisted by the generous help of Silicon Beach Software, who
supplied an SE and a prototype Mac II. Neil Rhodes also lent his production Mac II,
while my former employer coughed up the prehistoric 512. I’ve ignored the
Macintosh XL, aka Lisa 2, since most developers traded theirs in when the opportunity
presented itself and it never sold that well, anyway.
Educated Guessing
First let me note (standard disclaimer follows) that I am not privy to any
confidential Apple information regarding the ROM or trap patches. If I were, I
probably couldn’t share my thoughts on the subject.
However, I like to consider myself clever and resourceful, and I felt that a
studied application of documented techniques would produce valuable results. Those of
you who are regular readers of MacTutor will recognize this as “sleuthing.”
In this case, I know the availability of each by trap word ($A000-AFFF) with
certainty, both the traps that have names, and those that do not. However, some of the
OS traps share the same trap number and use high-order bits to distinguish between
the traps, but my analysis of the trap dispatch table can’t distinguish this. Also, for
the dispatched traps, I can’t tell which new traps are added that share the same
dispatch word.
There are also some problems with occasional ROM traps looking like RAM traps,
since some other interloper (like a development system or application) may have
patched a perfectly good ROM trap. From a compatibility standpoint, it’s not as
important to know which ROM-based traps are patched, so although there might be a
glitch or two here, it’s not worth losing sleep over.
After pouring over all the information and asking a few sources for help, I know
the trap names with a strong degree of certainty. I’ve left off a few traps for which I
have discerned names because Apple has not told anyone (including me) how to call
them, nor guaranteed that they will work in the future. There are quite a few traps
that are defined but not named at all (at least, outside Apple), but presumably those
are called from within the ROM only and subject to change at any time.
Finally, when we get down to why a particular trap was added or modified, all I
can do is make an educated guess. But since I’ve spent so much time studying trap
compatibility, I thought people might be interested in the results of my education.
The Format of a Trap
A trap is an unimplemented Motorola 68000 instruction that generates a
standard 68000 exception vector interrupt, which is used by the Macintosh to
transfer control to the appropriate code.
The 68000 uses instructions that are a multiple of 16 bits, with many
instructions contained in a single 16-bit word. In the case of Macintosh traps, the
instructions are 16-bit words (trap words) in which the first hex digit is A, so these
are sometimes referred to as “A-line” traps. All 4096 A-line traps are considered
illegal instructions.
(I heard a story that Motorola wanted to use A-line traps someday for a future
processor, but with Apple machines now holding the majority of the chips out there,
that possibility is gone. However, Motorola has reserved the 4096 F-line traps for
coprocessor calls, such as for the MC68881 and MC68851 of the Macintosh II.)
When it sees an illegal instruction in the range $A000 to $AFFF, the MC68000
(or MC68020) transfers control to the exception handling routine pointed to by
location $028. For a Macintosh, this transfers control to the trap dispatcher.
As shown by Figure 1, the range of possible traps is split into two groups, with
$A000 to $A7FF allocated to OS traps, and $A800 to $AFFF for Toolbox traps. The
lowest bits of the trap word are the trap number.
All traps from $A000-$A7FF are OS traps that accept any parameters in
low-numbered registers, such as A0 and D0, returning any results similarly in
registers.
Most of the traps from $A800 on are Toolbox traps, which have parameters
passed on the stack along the lines of the standard Lisa (now MPW) Pascal calling
sequence. There are also a number of stack-based traps for OS managers above
$A800, and a handful of register-based OS traps as well, but for our purposes, these
are numbered and treated as Toolbox traps.
The basic OS traps are numbered $A000 to $A0FF, with the upper 3 bits are
used for other indicator flags. The figure summarizes what these flags are used for,
and their hex mask equivalents are:
$100 trap returns a value in A0
$200 HFS traps
$400 asynchronous I/O call; or
allocate in system heap
The $200 and $400 bits are also used by some other traps, including
_GetTrapAddress.
There can be two (usually related) OS traps with the same OS trap number,
differing only in their indicator bits. For example, _PostEvent is $A02F and
_PPostEvent is $A12F. More significantly, _Open is $A000, while its HFS
counterpart is _HOpen at $A200, and their are many similar HFS pairs.
Trap Tables
The trap dispatcher transfers control to the correct routine using a trap table,
which contains the address (possibly encoded) of the corresponding routine. The trap
table is always in RAM, because it is possible for a program to modify the entry for
any trap, as we’ll see.
The trap table on the original Macintosh was compressed, with only 16 bits for
the trap address. Using the 68000 restriction that instructions begin on even
addresses, this allowed 64K of ROM addressability, plus patches in the first 64K of
low memory, presumably in the System Heap.
The Macintosh 512, of course, is just a Macintosh (128) with more RAM; same
connectors, maybe (as noted in earlier MacTutor articles) a better power supply --
but the same ROM, traps and trap table. I’ll talk about the 512 from now on, since
presumably everyone has at least 512K.
The 64K ROM also cheated by overlapping the OS and Toolbox trap tables into a
single table. As shown in Table 1, this limits a Mac 512 to 512 of both kinds of traps.
More significantly, certain trap words are not available on the Macintosh 512 --
since that spot in the trap table is taken for the opposite (Toolbox or OS) purpose.
Generally, the first 80 slots (A000 to A04F) in the 64K ROM are allocated to OS
traps, and the last 432 slots (A850 to A9FF) are allocated for the Toolbox. But a few
stragglers from the OS take slots allowed for the Toolbox, although the ROM doesn’t
seem to care which type of trap is in the slot .
The Plus and SE split the two trap tables. A full 256 OS traps are defined, and
512 Toolbox traps -- $A800 to $A9FF -- are allowed for the Plus and SE. When you
get to the Macintosh II, the maximum 1024 Toolbox traps are provided, with the
extended traps -- $AA00 to $ABFF -- used for Color QuickDraw.
Inherent Limits
Some people have told me that they have a certain machine and wish they could
have a certain new capability, typically offered with the next machine up.
For example, many folks want Color QuickDraw on their SE or Plus. While I
can’t say it won’t happen, it would require some changes to the trap dispatcher,
because the necessary traps are not possible using the built-in SE or Plus trap tables.
(There’s also the question of how to get the code itself, but if there are BIOS clones in
the IBM world, certainly the Mac world will inspire color clone conversions of the SE
if there’s enough demand.)
More significantly, many people will find that there are certain things they
cannot do and never will do with their old-ROM machine. The gap between the 64K
ROM and the rest of the world is now huge and largely unbridgable; if you’re not aware
of the differences, then read on.
First, bridging this gap would require throwing out the trap dispatch mechanism
on the 512 to allow for more traps, with separate OS & Toolbox traps. However, 512K
is at the low end nowadays for dynamic memory in the Macintosh world, and that’s the
largest configuration Apple ever offered in the 64K ROM world. Apple could have gone
to a lot of trouble to try to improve marginally adequate machines (or third-party
upgraded machines), but they didn’t, perhaps wisely so. The clincher is that these
old-ROM machines now form 20% (my estimate) of the installed base, and that
number is getting smaller every day.
The Good Ol’ Days
Once upon a time, things were much simpler. There were only traps and glue.
There was one list of available traps. Occasionally, the glue got more elaborate in a
new release of Lisa Pascal, but this was strictly a compile-time decision. When your
program ran, you knew it would face only one set of traps.
Along came the 128K ROM of the Macintosh Plus, and the world was never the
same again. The 128K ROM had a whole list of new traps not available on the 64K
ROM. All of a sudden, the Macintosh software architecture was not a fixed target, but
an evolving one.
(Its smaller sibling, the Mac 512K enhanced, has the exact same ROM as the
Plus, with less memory and different peripheral interfaces, but these differences are
uninteresting for our purposes and the 512Ke will be treated as a Plus for the
remainder of this article.)
To make matters worse, a certain subset of the 128K ROM traps -- those
involving the File Manager -- were also available on 64K ROM machines using trap
patches. All you have to do is place the file “Hard Disk 20” on your boot disk and
you’re all set, with full access to the Hierarchical File System of the 128K ROM.
The traps patched by “Hard Disk 20” to 64K ROM machines are shown in Table
2. A total of 13 traps are analogous to existing traps, most of which add an “H” to
their corresponding 64K trap, such as _HOpen vs. _Open.