rem: KillThread (pMS->flash_task);
add: Task_SetState (pMS->flash_task, TASK_EXIT);
context: DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS){	if (GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))	{		pMS->CurState = DEPART_BASE;		goto ExitStarBase;	}	if (!pMS->Initialized)	{		STAMP s;		LastActivity &= ~CHECK_LOAD;		pMS->InputFunc = DoStarBase;		SetSemaphore (GraphicsSem);		SetFlashRect (NULL_PTR, (FRAME)0);		if (pMS->hMusic)		{			StopMusic ();			DestroyMusic (pMS->hMusic);			pMS->hMusic = 0;		}		if (pMS->flash_task)		{			KillThread (pMS->flash_task);			pMS->flash_task = 0;		}		pMS->Initialized = TRUE;		SetContext (ScreenContext);		SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);		ClearSemaphore (GraphicsSem);		s.origin.x = s.origin.y = 0;s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;		s.frame = CaptureDrawable (LoadGraphic (STARBASE_ANIM));		pMS->CurFrame = s.frame;		pMS->hMusic = LoadMusicInstance (STARBASE_MUSIC);		SetSemaphore (GraphicsSem);		BatchGraphics ();		SetContextBackGroundColor (BLACK_COLOR);		ClearDrawable ();		DrawStamp (&s);		DrawBaseStateStrings ((STARBASE_STATE)~0, pMS->CurState);{	RECT r;	r.corner.x = 0;	r.corner.y = 0;	r.extent.width = SCREEN_WIDTH;	r.extent.height = SCREEN_HEIGHT;	ScreenTransition (3, &r);}		PlayMusic (pMS->hMusic, TRUE, 1);		UnbatchGraphics ();		pMS->flash_task = CreateThread (rotate_starbase, NULL, 4096,				"rotate starbase");		ClearSemaphore (GraphicsSem);	}	else if ((InputState & DEVICE_BUTTON1)			|| GET_GAME_STATE (MOONBASE_ON_SHIP)			|| GET_GAME_STATE (CHMMR_BOMB_STATE) == 2)	{ExitStarBase:		SetSemaphore (GraphicsSem);		if (pMS->flash_task)		{			KillThread (pMS->flash_task);			pMS->flash_task = 0;		}		DestroyDrawable (ReleaseDrawable (pMS->CurFrame));		pMS->CurFrame = 0;		ClearSemaphore (GraphicsSem);		StopMusic ();		if (pMS->hMusic)		{			DestroyMusic (pMS->hMusic);			pMS->hMusic = 0;		}		if (pMS->CurState == DEPART_BASE)		{			if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))			{				SET_GAME_STATE (STARBASE_VISITED, 0);			}			return (FALSE);		}		pMS->Initialized = FALSE;		if (pMS->CurState == TALK_COMMANDER)		{			InitCommunication (COMMANDER_CONVERSATION);			SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, (BYTE)~0);		}		else		{			BYTE OldState;			switch (OldState = pMS->CurState)			{				case OUTFIT_STARSHIP:					pMS->InputFunc = DoOutfit;					break;				case SHIPYARD:					pMS->InputFunc = DoShipyard;					break;			}			DoInput ((PVOID)pMS);			pMS->Initialized = FALSE;			pMS->CurState = OldState;			pMS->InputFunc = DoStarBase;		}	}	else	{		STARBASE_STATE NewState;		NewState = pMS->CurState;		if (GetInputXComponent (InputState) < 0				|| GetInputYComponent (InputState) < 0)		{			if (NewState-- == TALK_COMMANDER)				NewState = DEPART_BASE;		}		else if (GetInputXComponent (InputState) > 0				|| GetInputYComponent (InputState) > 0)		{			if (NewState++ == DEPART_BASE)				NewState = TALK_COMMANDER;		}		if (NewState != pMS->CurState)		{			SetSemaphore (GraphicsSem);			DrawBaseStateStrings (pMS->CurState, NewState);			ClearSemaphore (GraphicsSem);			pMS->CurState = NewState;		}	}	return (TRUE);}