rem: for (;;)
add: while (!Task_ReadState (task, TASK_EXIT))
context: int ambient_anim_task(void* blah){	SIZE TalkAlarm;	FRAME TalkFrame;	COUNT i;	DWORD LastTime;	FRAME CommFrame;	register PPRIMITIVE pBatch;	SEQUENCE Sequencer[MAX_ANIMATIONS];	PSEQUENCE pSeq;	ANIMATION_DESCPTR ADPtr;	DWORD ActiveMask;DWORD LastOscillTime;	while ((CommFrame = CommData.AlienFrame) == 0)		TaskSwitch ();	SetSemaphore (GraphicsSem);	memset ((PSTR)&DisplayArray[0], 0, sizeof (DisplayArray));	SetUpSequence (Sequencer);	ClearSemaphore (GraphicsSem);	ActiveMask = 0;	TalkAlarm = 0;	TalkFrame = 0;	LastTime = GetTimeCounter ();LastOscillTime = LastTime;	for (;;)	{		BOOLEAN Change, CanTalk;		DWORD CurTime, ElapsedTicks;		SleepThreadUntil (LastTime + 1);		SetSemaphore (GraphicsSem);		BatchGraphics ();		CurTime = GetTimeCounter ();		ElapsedTicks = CurTime - LastTime;		LastTime = CurTime;		Change = FALSE;		i = CommData.NumAnimations;		if (CommData.AlienFrame)			CanTalk = TRUE;		else		{			i = 0;			CanTalk = FALSE;		}		pBatch = &DisplayArray[MAX_ANIMATIONS + 1];		pSeq = &Sequencer[i];		ADPtr = &CommData.AlienAmbientArray[i];		while (i--)		{			--ADPtr;			--pSeq;			if (ADPtr->AnimFlags & ANIM_DISABLED)				continue;			else if (pSeq->Direction == NO_DIR)			{				if (!(ADPtr->AnimFlags						& CommData.AlienTalkDesc.AnimFlags & WAIT_TALKING))					pSeq->Direction = UP_DIR;			}			else if ((DWORD)pSeq->Alarm > ElapsedTicks)				pSeq->Alarm -= (COUNT)ElapsedTicks;			else			{				if (!(ActiveMask & ADPtr->BlockMask)						&& (--pSeq->FramesLeft						|| ((ADPtr->AnimFlags & YOYO_ANIM)						&& pSeq->Direction == UP_DIR)))				{					ActiveMask |= 1L << i;					pSeq->Alarm =							ADPtr->BaseFrameRate							+ ((COUNT)Random ()							% (ADPtr->RandomFrameRate + 1))							+ 1;				}				else				{					ActiveMask &= ~(1L << i);					pSeq->Alarm =							ADPtr->BaseRestartRate							+ ((COUNT)Random ()							% (ADPtr->RandomRestartRate + 1))							+ 1;					if (ActiveMask & ADPtr->BlockMask)						continue;				}				if (pSeq->AnimType == COLOR_ANIM)				{					XFormPLUT (							GetColorMapAddress (pSeq->AnimObj.CurCMap),							pSeq->Alarm - 1							);				}				else				{					Change = TRUE;					--pBatch;					SetPrimNextLink (pBatch, (pBatch - &DisplayArray[0]) + 1);					SetPrimType (pBatch, STAMP_PRIM);pBatch->Object.Stamp.origin.x = -SAFE_X;					pBatch->Object.Stamp.frame = pSeq->AnimObj.CurFrame;				}				if (pSeq->FramesLeft == 0)				{					pSeq->FramesLeft = (BYTE)(ADPtr->NumFrames - 1);					if (pSeq->Direction == DOWN_DIR)						pSeq->Direction = UP_DIR;					else if (ADPtr->AnimFlags & YOYO_ANIM)						pSeq->Direction = DOWN_DIR;					else					{						++pSeq->FramesLeft;						if (pSeq->AnimType == COLOR_ANIM)							pSeq->AnimObj.CurCMap = SetRelColorMapIndex (									pSeq->AnimObj.CurCMap,									-pSeq->FramesLeft									);						else							pSeq->AnimObj.CurFrame = SetRelFrameIndex (									pSeq->AnimObj.CurFrame,									-pSeq->FramesLeft									);					}				}				if (ADPtr->AnimFlags & RANDOM_ANIM)				{					if (pSeq->AnimType == COLOR_ANIM)						pSeq->AnimObj.CurCMap =								SetAbsColorMapIndex (pSeq->AnimObj.CurCMap,								ADPtr->StartIndex								+ ((COUNT)Random ()								% ADPtr->NumFrames));					else						pSeq->AnimObj.CurFrame =								SetAbsFrameIndex (pSeq->AnimObj.CurFrame,								ADPtr->StartIndex								+ ((COUNT)Random ()								% ADPtr->NumFrames));				}				else if (pSeq->AnimType == COLOR_ANIM)				{					if (pSeq->Direction == UP_DIR)						pSeq->AnimObj.CurCMap = SetRelColorMapIndex (								pSeq->AnimObj.CurCMap, 1								);					else						pSeq->AnimObj.CurCMap = SetRelColorMapIndex (								pSeq->AnimObj.CurCMap, -1								);				}				else				{					if (pSeq->Direction == UP_DIR)						pSeq->AnimObj.CurFrame =								IncFrameIndex (pSeq->AnimObj.CurFrame);					else						pSeq->AnimObj.CurFrame =								DecFrameIndex (pSeq->AnimObj.CurFrame);				}			}			if (pSeq->AnimType == PICTURE_ANIM					&& (ADPtr->AnimFlags					& CommData.AlienTalkDesc.AnimFlags & WAIT_TALKING)					&& pSeq->Direction != NO_DIR)			{				COUNT index;				CanTalk = FALSE;				if (!(pSeq->Direction != UP_DIR						|| (index = GetFrameIndex (pSeq->AnimObj.CurFrame)) >						ADPtr->StartIndex + 1						|| (index == ADPtr->StartIndex + 1						&& (ADPtr->AnimFlags & CIRCULAR_ANIM))))					pSeq->Direction = NO_DIR;			}		}		ADPtr = &CommData.AlienTalkDesc;		if (CanTalk				&& ADPtr->NumFrames				&& (ADPtr->AnimFlags & WAIT_TALKING)				&& !(CommData.AlienTransitionDesc.AnimFlags & PAUSE_TALKING))		{			if ((long)TalkAlarm > (long)ElapsedTicks)				TalkAlarm -= (SIZE)ElapsedTicks;			else			{				BYTE AFlags;				SIZE FrameRate;				if (TalkAlarm > 0)					TalkAlarm = 0;				else					TalkAlarm = -1;				AFlags = ADPtr->AnimFlags;				if (!(AFlags & (TALK_INTRO | TALK_DONE)))				{					FrameRate =							ADPtr->BaseFrameRate							+ ((COUNT)Random ()							% (ADPtr->RandomFrameRate + 1));					if (TalkAlarm < 0							|| GetFrameIndex (TalkFrame) ==							ADPtr->StartIndex)					{						TalkFrame = SetAbsFrameIndex (CommFrame,								ADPtr->StartIndex + 1								+ ((COUNT)Random ()								% (ADPtr->NumFrames - 1)));						FrameRate +=								ADPtr->BaseRestartRate								+ ((COUNT)Random ()								% (ADPtr->RandomRestartRate + 1));					}					else					{						TalkFrame = SetAbsFrameIndex (CommFrame,								ADPtr->StartIndex);						if (ADPtr->AnimFlags & PAUSE_TALKING)						{							if (!(CommData.AlienTransitionDesc.AnimFlags									& TALK_DONE))							{								CommData.AlienTransitionDesc.AnimFlags |=										PAUSE_TALKING;								ADPtr->AnimFlags &=										~PAUSE_TALKING;							}							else if (CommData.AlienTransitionDesc.NumFrames)								ADPtr->AnimFlags |=										TALK_DONE;							else								ADPtr->AnimFlags &=										~(WAIT_TALKING | PAUSE_TALKING);							FrameRate = 0;						}					}				}				else				{					ADPtr = &CommData.AlienTransitionDesc;					if (AFlags & TALK_INTRO)					{						FrameRate =								ADPtr->BaseFrameRate								+ ((COUNT)Random ()								% (ADPtr->RandomFrameRate + 1));						if (TalkAlarm < 0)							TalkFrame = SetAbsFrameIndex (CommFrame,									ADPtr->StartIndex);						else							TalkFrame = IncFrameIndex (TalkFrame);						if ((BYTE)(GetFrameIndex (TalkFrame)								- ADPtr->StartIndex + 1) ==								ADPtr->NumFrames)							CommData.AlienTalkDesc.AnimFlags &= ~TALK_INTRO;					}					else /* if (AFlags & TALK_DONE) */					{						FrameRate =								ADPtr->BaseFrameRate								+ ((COUNT)Random ()								% (ADPtr->RandomFrameRate + 1));						if (TalkAlarm < 0)							TalkFrame = SetAbsFrameIndex (CommFrame,									ADPtr->StartIndex									+ ADPtr->NumFrames									- 1);						else							TalkFrame = DecFrameIndex (TalkFrame);						if (GetFrameIndex (TalkFrame) ==								ADPtr->StartIndex)						{							CommData.AlienTalkDesc.AnimFlags &=									~(PAUSE_TALKING | TALK_DONE);							if (ADPtr->AnimFlags & TALK_INTRO)								CommData.AlienTalkDesc.AnimFlags &= ~WAIT_TALKING;							else							{								ADPtr->AnimFlags |=										PAUSE_TALKING;								ADPtr->AnimFlags &= ~TALK_DONE;							}							FrameRate = 0;						}					}				}				Change = TRUE;				--pBatch;				SetPrimNextLink (pBatch, (pBatch - &DisplayArray[0]) + 1);				SetPrimType (pBatch, STAMP_PRIM);pBatch->Object.Stamp.origin.x = -SAFE_X;				pBatch->Object.Stamp.frame = TalkFrame;				TalkAlarm = FrameRate;			}		}		if (Change |= ColorChange)		{			CONTEXT OldContext;			OldContext = SetContext (TaskContext);			if (ColorChange)			{				FRAME F;								F = CommData.AlienFrame;				CommData.AlienFrame = CommFrame;				DrawAlienFrame (TalkFrame, &Sequencer[CommData.NumAnimations - 1]);				CommData.AlienFrame = F;				ColorChange = FALSE;			}			else			{				COUNT StartIndex;				SetPrimNextLink (&DisplayArray[MAX_ANIMATIONS], END_OF_LIST);				StartIndex = pBatch - &DisplayArray[0];				DrawBatch (&DisplayArray[0], StartIndex, 0);				Change = FALSE;			}			if (subtitle_state >= SPACE_SUBTITLE)			{				TEXT t;				t = CommData.AlienTextTemplate;				add_text (1, &t);			}			SetContext (OldContext);		}if (LastOscillTime + (ONE_SECOND / 32) < CurTime){	LastOscillTime = CurTime;	UpdateSpeechGraphics (FALSE);}		UnbatchGraphics ();		ClearSemaphore (GraphicsSem);	}	(void) blah;  /* Satisfying compiler (unused parameter) */	return(0);}