#include "Glue.h"
#include "ModA4Globals.h"


#if defined(powerc) || defined(__powerc)	// weĠre running on a Power Mac
	ProcInfoType	__procinfo = kPascalStackBased
		| RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
		| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSType)))
		| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ModParamsPtr)))
		| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(GluePtr)))
		| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(GluePtr)));
#endif

#if defined(powerc) || defined(__powerc)
	#define	availGlue	gluePPC
#else
	#define	availGlue	glue68k
#endif


pascal OSErr main(OSType message, ModParamsPtr modInfo, GluePtr glue68k, GluePtr gluePPC)
{
	ModSettingsHandle	prefs = 0L;
	long				world;
	OSErr				error;
	
	MAIN_SETUP_GLOBALS(world);
	
	switch (message)
	{
		case kMsgRun:
			error = GetModSettings(modInfo, availGlue, &prefs);
			if (error == noErr)
				error = effect(modInfo, availGlue, &prefs);
			break;
		case kMsgSettings:
			error = settings(modInfo, availGlue, &prefs);
			break;
		case kMsgSettingsRun:
			error = settings(modInfo, availGlue, &prefs);
			if (error == noErr || error == kModHasNoSettings)
				error = effect(modInfo, availGlue, &prefs);
			break;
		case kMsgHeadersVers:
			*(long *)glue68k = kHeadersVersion;
			error = noErr;
			break;
		case kMsgAbout:
			error = about((ModAboutPtr)modInfo);
			break;
		default:
			error = kModUnknownMessage;
	}
	
	if (prefs)
		DisposHandle((Handle)prefs);
	
	MAIN_RESTORE_GLOBALS(world);
	
	return error;
}


// GetModSettings and settings return, in prefs, either nil or a valid handle.
// effect must take care of disposing it.


long SetupEffectWorld(void)
{
	long	world;
	
	TEMP_SETUP_GLOBALS(world);
	return world;
}

void RestoreEffectWorld(long world)
{
	TEMP_RESTORE_GLOBALS(world);
}