rem: SetSemaphore (&GraphicsSem);
add: SetSemaphore (GraphicsSem);
context: DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS){	if (InputState & DEVICE_EXIT)		return (FALSE);	if (!pMS->Initialized)	{		pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col];		DrawMeleeShipStrings (pMS, (BYTE)pMS->CurIndex);		pMS->Initialized = TRUE;		pMS->InputFunc = DoEdit;	}	else if ((pMS->row < NUM_MELEE_ROWS || pMS->CurIndex == (BYTE)~0)			&& ((InputState & DEVICE_BUTTON2)			|| (GetInputXComponent (InputState) > 0			&& (pMS->col == NUM_MELEE_COLUMNS - 1 || pMS->row == NUM_MELEE_ROWS))))	{		SetSemaphore (&GraphicsSem);		Deselect (EDIT_MELEE);		pMS->CurIndex = (COUNT)~0;		pMS->MeleeOption = START_MELEE;		pMS->InputFunc = DoMelee;		ClearSemaphore (&GraphicsSem);		InTime = GetTimeCounter ();	}	else if (pMS->row < NUM_MELEE_ROWS			&& (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON3)))	{		if (InputState & DEVICE_BUTTON1)			pMS->Initialized = 0;		else			pMS->Initialized = -1;		DoPickShip (0, pMS);	}	else	{		COUNT side, row, col;		side = pMS->side;		row = pMS->row;		col = pMS->col;		if (row == NUM_MELEE_ROWS)		{			if (pMS->CurIndex != (BYTE)~0)			{				SetSemaphore (&GraphicsSem);				if (pMS->Initialized == 1 && SerialInput)				{					FlushInput ();					pMS->Initialized = 2;				}				else if ((SerialInput == 0 && (InputState & DEVICE_BUTTON2))						|| DoTextEntry (pMS, InputState) == '\n')				{					pMS->CurIndex = (BYTE)~0;					DrawTeamString (pMS, 4);					pMS->Initialized = 1;				}				ClearSemaphore (&GraphicsSem);				return (TRUE);			}			else if (InputState & DEVICE_BUTTON1)			{				pMS->CurIndex = 0;				SetSemaphore (&GraphicsSem);				DrawTeamString (pMS, 1);				ClearSemaphore (&GraphicsSem);				return (TRUE);			}		}		{			if (GetInputXComponent (InputState) < 0)			{				if (col-- == 0)					col = 0;			}			else if (GetInputXComponent (InputState) > 0)			{				if (++col == NUM_MELEE_COLUMNS)					col = NUM_MELEE_COLUMNS - 1;			}			if (GetInputYComponent (InputState) < 0)			{				if (row-- == 0)				{					if (side == 0)						row = 0;					else					{						row = NUM_MELEE_ROWS;						side = !side;					}				}			}			else if (GetInputYComponent (InputState) > 0)			{				if (row++ == NUM_MELEE_ROWS)				{					if (side == 1)						row = NUM_MELEE_ROWS;					else					{						row = 0;						side = !side;					}				}			}		}		if (col != pMS->col || row != pMS->row || side != pMS->side)		{			SetSemaphore (&GraphicsSem);			Deselect (EDIT_MELEE);			pMS->side = side;			pMS->row = row;			pMS->col = col;			if (row == NUM_MELEE_ROWS)				pMS->CurIndex = (BYTE)~0;			else				pMS->CurIndex = pMS->TeamImage[side].ShipList[row][col];			ClearSemaphore (&GraphicsSem);			DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex));		}	}	return (TRUE);}