home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-05 | 3.9 KB | 166 lines | [TEXT/CWIE] |
- //////////
- //
- // Refractor 1.0
- // ©1995 Steven J. Bushell
- //
- // This file is based on GraphicsModule_main.c, by Patrick Beard, Bruce Burkhalter
- // and Colin Glassey. It has been modified to check for the presence of a
- // floating-point coprocessor, and the PowerPC system architecture. If either of these
- // is present, the appropriate code resource is loaded and used instead of the original
- // 68k code resource.
- //
- // When the module is finished, the code resource is released from memory.
- //
- //////////
-
- #include "GraphicsModule_Types.h"
- #include <A4Stuff.h>
-
- pascal OSErr main (Handle *storage, RgnHandle blankRgn, short message, GMParamBlockPtr params);
- typedef pascal OSErr (* mainFuncType)(Handle *, RgnHandle, short, GMParamBlockPtr);
-
- #if powerc
-
- enum
- {
- uppADModuleProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle *)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(RgnHandle)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(GMParamBlockPtr)))
- };
- RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR (uppADModuleProcInfo, main);
- unsigned long __procinfo = uppADModuleProcInfo;
-
- #elif !__68881__
-
- static long type;
- static Handle code = nil;
- static Boolean isPowerPC = false;
-
- static Boolean IsPowerPC (void)
- {
- long result;
- OSErr err;
-
- err = Gestalt (gestaltSysArchitecture, &result);
- if (err)
- return false;
-
- return (result == gestaltPowerPC);
- }
-
- static Boolean hasFPU = false;
-
- static Boolean HasFPU (void)
- {
- long result;
- OSErr err;
-
- err = Gestalt (gestaltFPUType, &result);
- if (err)
- return false;
-
- return (result != gestaltNoFPU);
- }
-
- #endif
-
- // Prototypes for essential functions.
- OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
-
- pascal OSErr
- main (Handle *storage, RgnHandle blankRgn, short message, GMParamBlockPtr params)
- {
- OSErr err = noErr;
-
- EnterCodeResource ();
-
- #if !powerc && !__MC68881__
- // If we're a Power Mac, and we've got the code resource, and we're already initialized,
- // we jump right to the native code resource.
- // Ditto for a mac with an FPU.
- if ((isPowerPC || hasFPU) && code && (message != Initialize) && (message != Close))
- {
- err = ((mainFuncType)*code)(storage, blankRgn, message, params);
- ExitCodeResource ();
- return err;
- }
- #endif
-
- switch (message)
- {
- case Initialize:
- #if !powerc && !__MC68881__
- hasFPU = HasFPU ();
- isPowerPC = IsPowerPC();
-
- // Get the correct module type for either a PowerPC or a 68k w/FPU.
- type = isPowerPC ? 'Padm' : 'Fadm';
-
- if (isPowerPC || hasFPU)
- {
- code = GetResource (type, 0);
- if (code)
- {
- HLock (code);
- err = ((mainFuncType)*code)(storage, blankRgn, message, params);
- }
- else
- {
- err = DoInitialize (storage, blankRgn, params);
- }
- }
- else
- #endif
- err = DoInitialize (storage, blankRgn, params);
- break;
-
- case Close:
- #if !powerc && !__MC68881__
- if (code)
- {
- ReleaseResource (code);
- code = nil;
- isPowerPC = false;
- hasFPU = false;
- }
- #endif
- err = DoClose (*storage, blankRgn, params);
- break;
-
- case Blank:
- err = DoBlank (*storage, blankRgn, params);
- break;
-
- case DrawFrame:
- err = DoDrawFrame (*storage, blankRgn, params);
- break;
-
- case ModuleSelected:
- // err = DoSelected (*storage, blankRgn, params);
- break;
- case DoAbout:
- // err = DoAbout (*storage, blankRgn, params);
- break;
-
- default: // user may have hit a button
- if(message >= ButtonMessage)
- {
- // handle the button
- err = DoSetUp (blankRgn, message, params);
- }
-
- break;
- }
-
- ExitCodeResource ();
-
- return err;
- }
-