[comp.sys.mac.programmer] How to Know if You're Running Under MacWorks Plus

imp@crayview.msi.umn.edu (Chuck Lukaszewski) (09/30/88)

My posting on serial port trapping reminded me that everyone needs a way
to see if they're running on a Lisa.  There are two checks involved.  Do a
_SysEnvirons call.  This will return Lisa if you are running under the
original MacWorks.  However, if you call _SysEnvirons under MacWorks Plus
it will tell you that you are on a Plus, so we need something else.

An additional check is the following (in assembly):

	CMPI.L	#'MACW',$400040		;Test Macworks Plus environment
	BNE		NotLisa			;Branch if not

This test will be adequate for all releases of MacWorks Plus.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

AS LONG AS I HAVE THE STUMP, I am going to complain about programs that do
NONSTANDARD ENVIRONMENT TESTS.  This has been the single most frustrating
thing about developing Macworks Plus.  This comment is addressed specifically
to MICROSOFT and Broderbund and the Word Perfect people and the Insight
Accounting people, but I think that all can benefit because breaking the rules
now is going to mess you up with new Apples and not just old ones.

Unlike all other Macintoshes before the Mac IIx and AUX Mac II, the Lisa has
a MMU which gets upset when you reference unmapped memory, or memory you 
don't have access to (it also does real DMA transfer, but I'll stop there as
I don't want to upset anyone).  Specifically, it burps a bus error.  My original
memory design mapped all of the RAM in the $000000-$400000 range, as that is
what the Mac Plus provides.  Unfortunately, Mac memory management is dumb enough
to give you values from memory that doesn't exist.

When we began alpha testing several months ago, we discovered that the software
houses mentioned previously, among others, inevitably generated bus errors at
some point in their code.  In the first two cases (Microsoft/Broderbund) it
involved nonstandard environment checks.  Microsoft tests a bunch of memory
in the $500000 range as part of its startup code on all applications that
postdate Word 1.5.  I just got a bug report today that Microsoft BASIC 2.0
does the same thing when saving files.  In some ways, that is trivial compared
to what Broderbund does - they just replace 16 key page 0 vectors with their
own handlers (so Shanghai won't work with any 680x0 architecture or future
Motorola chip which puts those vectors elsewhere, nor will it work on the
Lisa.)  In the cases of Word Perfect and Insight, the programs actually copy
data with _BlockMove into perfectly illegal areas of memory and then try to
manipulate that data!

Still other programs not mentioned do their OWN checks for the alternate
ROM at $F80000.  This is completely unnecessary, in my opinion.

PLEASE PLEASE PLEASE use Apple defined methods of checking your environments.
My fix for these problems was to map the regions in question into an area
of RAM that was set aside just for this problem.  That means less memory is
available to the user, folks, because I have to compensate for the rule-
breaking that some of you do.

LISA COMPATIBILITY WARNING:  The only region of Lisa memory which cannot be
mapped elsewhere is from $FCC000 to $FFFFFF, or any 16-megabyte multiple of
that range.  CHANCES ARE EXCELLENT THAT YOU WILL BREAK MACWORKS PLUS
IF YOU REFERENCE THESE LOCATIONS DIRECTLY.  A good example is a program that
explicitly addresses the A register of the VIA chip - at $EF1FFE + $1E00.
This happens to map into the screen location register of the Lisa (yes, you
can put the Lisa screen on any 16K boundary you want) and is a source of
some very pretty crashes.

You can write off the Lisa if you want to, but you don't have to take it from
me.  Apple is very firm in its statements along this line, and I think it's a
safe bet that non-standard approaches will fail miserably on future machines.
If you still think it's a joke, I encourage you to find out about the Apple
machine in beta test now which tests the compatibility of programs with Apple
guidelines (i.e. it traps all references to low-memory, etc.).

---===---===---===---===--/* Chuck Lukaszewski */--===---===---===---===---
ARPAnet/NSFnet/MRnet:      AppleLink:  SnailMail:              Ma Bell:
imp@crayview.msi.umn.edu   UG0138      Minneapolis MN 55418    612/789-0931