home *** CD-ROM | disk | FTP | other *** search
- /*
- StubMod.c
- This file creates the 68k 'ADgm' resource to call your PPC module.
- Its designed to be compiled as a code resource and then included in your PPC shared libary project.
-
- Created by Steve Zellers
- 6/2/95 aea (Andrew Armstrong) Modifed for CodeWarrior & proper CPU checking.
- */
-
- #define GENERATING68K 1
- #include <ConditionalMacros.h>
- #include <CodeFragments.h>
- #include <MixedMode.h>
- #include <Types.h>
- #include <OSUtils.h>
- #include <Resources.h>
- #include <Memory.h>
- #include <A4Stuff.h>
- #include <Quickdraw.h>
- #include <LowMem.h>
- #include <GestaltEqu.h>
-
- // 6/2/95 aea NewRoutineDescriptor is allready defined in MixedMode.h as 68k code.
- // By declaring MyNewRoutineDescriptor, I am able to call the MixedModeManager trap.
- extern pascal UniversalProcPtr MyNewRoutineDescriptor(ProcPtr theProc, ProcInfoType theProcInfo, ISAType theISA) = {0x7000, 0xAA59};
-
- #include "GraphicsModule_Types.h"
-
- #define kFragmentName "\pmain"
- #define kEntryPointName "\pmain"
-
- ConnectionID theConnectionID;
- Ptr theEntryPoint;
- typedef pascal OSErr (*ModuleProcPtr)(Handle* storage, RgnHandle rgn, short msg, GMParamBlockPtr params);
-
- ModuleProcPtr theDescriptor = 0l;
-
- enum {
- eModuleDispatchSelector = 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( GMParamBlock*)))
- };
-
-
- static OSErr LocateFile(short refNum, FSSpec* location, long* fileLen)
- {
- FCBPBRec fcbPB;
- OSErr result;
-
- fcbPB.ioNamePtr = (StringPtr)location->name;
- fcbPB.ioCompletion = nil;
- fcbPB.ioFCBIndx = 0;
- fcbPB.ioRefNum = refNum;
- result = PBGetFCBInfo(&fcbPB, false);
- if (result == noErr) {
- location->vRefNum = fcbPB.ioFCBVRefNum;
- location->parID = fcbPB.ioFCBParID;
- *fileLen = fcbPB.ioFCBPLen;
- }
-
- return result;
- }
-
- pascal OSErr main(Handle* storage, RgnHandle rgn, short msg, GMParamBlockPtr params)
- {
- OSErr err = noErr;
- long nativeCPUtype;
- long oldA4;
-
- oldA4 = SetCurrentA4();
- // 6/2/95 aea Were going to assume that Apple will only produce PPC processors for awhile.
- // so instead of chekcing for the code fragment manager (which can exist on 68k machines)
- // we will simply look for anything after gestaltCPU601
- err = Gestalt('cput', &nativeCPUtype);
- if ((err != noErr) || (nativeCPUtype < gestaltCPU601))
- {
- Handle errorHandle;
-
- errorHandle = Get1Resource('STR ', 150);
-
- if (!errorHandle)
- BlockMove("\pSorry, this module only runs on a PowerMacintosh.", params->errorMessage, 255);
- else
- {
- HLock(errorHandle);
- BlockMove(*errorHandle, params->errorMessage, 255);
- ReleaseResource(errorHandle);
- }
-
- ExitCodeResource();
- return -1;
- }
-
- // open the fragment
- if (msg == Initialize) {
- Ptr exportedEntryPoint;
- SymClass theClass;
- FSSpec thisSpec;
- long thisLen;
-
- LocateFile(LMGetCurMap(), &thisSpec, &thisLen);
- err = GetDiskFragment(&thisSpec, 0, kWholeFork, kFragmentName, kLoadNewCopy, &theConnectionID, (Ptr*) &exportedEntryPoint, params->errorMessage);
-
- if (err == noErr)
- err = FindSymbol(theConnectionID, kEntryPointName, &theEntryPoint, &theClass);
-
- if (err == noErr)
- theDescriptor = (ModuleProcPtr) MyNewRoutineDescriptor((ProcPtr) theEntryPoint, eModuleDispatchSelector, kPowerPCISA);
- }
-
- if (theDescriptor && (err == noErr)) {
- err = (*theDescriptor)(storage, rgn, msg, params);
- }
-
- if (msg == Close || err != noErr) {
- DisposeRoutineDescriptor((UniversalProcPtr) theDescriptor);
- CloseConnection(&theConnectionID);
-
- }
-
- ExitCodeResource();
- return err;
- }
-