/************************************************
Copyright © Simon Fraser 1994Ð5
All rights reserved.

This file contains the main AfterDark functions for initialization, drawing
and closing the module.

************************************************/

#include "Starter.h"

#define ErrorMsg(m) BlockMove(CtoPstr(m), params->errorMessage, 1 + m##[0]);


//--------------------CleanUp--------------------
void CleanUp(ModStore** storage)
{	
	if (storage)
	{	
		/*dispose of other memory allocated by your module here*/	
		DisposeHandle((Handle)storage);
	}
}

//---------------------DoInitialize--------------------
OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params)
{
	Handle storeHand;
	ModStorePtr ModStorage;

//Allocate memory and initialize variables here}
	storeHand = NewHandle(sizeof(ModStore));

	 if (!storeHand)
	{
		ErrorMsg("Sorry, couldnÕt allocate memory");
		return ModuleError;
	}

	*storage = storeHand; 	/* store a reference to our storage where After Darkª can keep it. */
	
/*lock down our storage so we can refer to it by pointer.*/
	HLockHi(storeHand);
	ModStorage = (ModStorePtr)*storeHand;
	
/*Initialize the fields in your structure*/
	ModStorage->frames = 0;

	HUnlock(storeHand);
	return noErr;
}


//--------------------DoBlank--------------------
OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
{	

	/*Fill the screen(s) with black*/
	ForeColor(blackColor);
	FillRgn(blankRgn, ¶ms->qdGlobalsCopy->qdBlack);

	return noErr;
}

//--------------------DoDrawFrame--------------------
OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
{
	ModStorePtr	ModStorage;
	
	/*Lock the storage handle, so we can refer to it by pointer (for speed)*/
	HLock(storage);
	
	/*Make a pointer reference to storage*/
	ModStorage = (ModStorePtr)*storage;
	
	ModStorage->frames ++;
	
	/*We're done -- unlock the storage handle*/
	HUnlock(storage);
	return  noErr;
}

//--------------------DoClose--------------------
OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
{
	/*Dispose of all the memory that we have allocated*/
	CleanUp((ModStore**)storage);
	return noErr;
}



//-----------------------------DoSetup-----------------------------------
OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params)
{
	/*I don't handle this message*/
	return noErr;
}


//------------------------------DoAbout---------------------------------
OSErr DoAbout(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
{
	/*I don't handle this message*/
	
	/*Beware! If you do write your own About box routines here, the
	storage parameter that is passed is NOT allocated or initialized.
	You have to do all this yourself (as in DoInitialize). */
	return noErr;
}



//--------------------------DoSelected------------------------------
OSErr DoSelected(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
{
	/*I don't handle this message*/
	return noErr;
}