rem: SetSemaphore (&GraphicsSem); DeleteTask (pMS->flash_task); ClearSemaphore (&GraphicsSem);
add: SetSemaphore (GraphicsSem); KillThread (pMS->flash_task); ClearSemaphore (GraphicsSem);
context: DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS){	if (InputState)	{		if (InputState & DEVICE_EXIT)			return (FALSE);		InTime = GetTimeCounter ();	}	if (!pMS->Initialized)	{		pMS->Initialized = TRUE;		pMS->MeleeOption = START_MELEE;		SetSemaphore (&GraphicsSem);		InitMelee (pMS);		ClearSemaphore (&GraphicsSem);		{			BYTE clut_buf[] = {FadeAllToColor};							XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2);		}		InTime = GetTimeCounter ();	}	else if ((InputState & DEVICE_BUTTON2)			|| GetInputXComponent (InputState) < 0)	{		SetSemaphore (&GraphicsSem);		Deselect (pMS->MeleeOption);		ClearSemaphore (&GraphicsSem);		pMS->MeleeOption = EDIT_MELEE;		pMS->Initialized = FALSE;		if (InputState & DEVICE_BUTTON2)			pMS->side = pMS->row = pMS->col = 0;		else			pMS->side = 0,			pMS->row = NUM_MELEE_ROWS - 1,			pMS->col = NUM_MELEE_COLUMNS - 1;		DoEdit (InputState, pMS);	}	else	{		MELEE_OPTIONS NewMeleeOption;		NewMeleeOption = pMS->MeleeOption;		if (GetInputYComponent (InputState) < 0)		{			if (NewMeleeOption-- == CONTROLS_TOP)				NewMeleeOption = CONTROLS_TOP;		}		else if (GetInputYComponent (InputState) > 0)		{			if (NewMeleeOption++ == CONTROLS_BOT)				NewMeleeOption = CONTROLS_BOT;		}		if ((PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL)				&& GetTimeCounter () - InTime > ONE_SECOND * 10)		{			InputState = DEVICE_BUTTON1;			NewMeleeOption = START_MELEE;		}		if (NewMeleeOption != pMS->MeleeOption)		{			SetSemaphore (&GraphicsSem);			Deselect (pMS->MeleeOption);			pMS->MeleeOption = NewMeleeOption;			Select (pMS->MeleeOption);			ClearSemaphore (&GraphicsSem);		}		if (InputState & DEVICE_BUTTON1)		{			switch (pMS->MeleeOption)			{				case START_MELEE:					if (pMS->star_bucks[0] == 0 || pMS->star_bucks[1] == 0)					{						PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 2),								0, GAME_SOUND_PRIORITY);						break;					}					if (pMS->flash_task)					{						SetSemaphore (&GraphicsSem);						DeleteTask (pMS->flash_task);						ClearSemaphore (&GraphicsSem);						pMS->flash_task = 0;					}										{						BYTE black_buf[] = {FadeAllToBlack};												SleepTask (XFormColorMap (								(COLORMAPPTR)black_buf, ONE_SECOND / 2								) + 2);						FlushColorXForms ();					}					do					{						COUNT i;						SetContext (OffScreenContext);						for (i = 0; i < NUM_SIDES; ++i)						{							COUNT j, side;							side = !i;							for (j = 0; j < NUM_MELEE_ROWS; ++j)							{								COUNT k;								for (k = 0; k < NUM_MELEE_COLUMNS; ++k)								{									BYTE StarShip;									if ((StarShip = pMS->TeamImage[i].ShipList[j][k]) != (BYTE)~0)									{										BYTE ship_cost;										HSTARSHIP hStarShip, hBuiltShip;										STARSHIPPTR StarShipPtr,														BuiltShipPtr;										hStarShip = GetStarShipFromIndex (&master_q, StarShip);										StarShipPtr = LockStarShip (												&master_q, hStarShip												);										hBuiltShip = Build (&race_q[side],												StarShipPtr->RaceResIndex,												1 << side,												NameCaptain (&race_q[side], StarShipPtr));										ship_cost = StarShipPtr->RaceDescPtr->												ship_info.ship_cost;										UnlockStarShip (												&master_q, hStarShip												);										BuiltShipPtr = LockStarShip (												&race_q[side], hBuiltShip												);										BuiltShipPtr->ShipFacing =												(j * NUM_MELEE_COLUMNS) + k;										BuiltShipPtr->special_counter = ship_cost;										BuiltShipPtr->captains_name_index =												StarShipCaptain (BuiltShipPtr);										BuiltShipPtr->RaceDescPtr =												StarShipPtr->RaceDescPtr;										UnlockStarShip (												&race_q[side], hBuiltShip												);									}								}							}						}						while (SoundPlaying ())							;						SeedRandomNumbers ();						load_gravity_well ((BYTE)((COUNT)Random () % NUMBER_OF_PLANET_TYPES));						Battle ();						free_gravity_well ();						if (GLOBAL (CurrentActivity) & CHECK_ABORT) return (FALSE);						{							BYTE black_buf[] = {FadeAllToBlack};													SleepTask (XFormColorMap (									(COLORMAPPTR)black_buf, ONE_SECOND / 2									) + 2);							FlushColorXForms ();						}					} while (0 /* !(GLOBAL (CurrentActivity) & CHECK_ABORT) */);					GLOBAL (CurrentActivity) = SUPER_MELEE;					pMS->Initialized = FALSE;					break;				case LOAD_TOP:				case LOAD_BOT:					pMS->Initialized = FALSE;					pMS->side = pMS->MeleeOption == LOAD_TOP ? 0 : 1;					DoLoadTeam (InputState, pMS);					break;				case SAVE_TOP:				case SAVE_BOT:					pMS->side = pMS->MeleeOption == SAVE_TOP ? 0 : 1;					if (pMS->star_bucks[pMS->side])						DoSaveTeam (pMS);					else						PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 2),								0, GAME_SOUND_PRIORITY);					break;				case CONTROLS_TOP:				case CONTROLS_BOT:				{					COUNT which_side;					which_side = pMS->MeleeOption == CONTROLS_TOP ? 1 : 0;					if (PlayerControl[which_side] & HUMAN_CONTROL)						PlayerControl[which_side] = COMPUTER_CONTROL | STANDARD_RATING;					else if (PlayerControl[which_side] & AWESOME_RATING)						PlayerControl[which_side] = HUMAN_CONTROL | STANDARD_RATING;					else						PlayerControl[which_side] = ((								PlayerControl[which_side]								& (STANDARD_RATING | GOOD_RATING | AWESOME_RATING)								) << 1) | COMPUTER_CONTROL;					SetPlayerInput ();					DrawControls (which_side, TRUE);					break;				}			}		}	}	return (TRUE);}