rem: SetSemaphore (&GraphicsSem);
add: SetSemaphore (GraphicsSem);
context: DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS){	STARSHIPPTR StarShipPtr;	if (InputState & DEVICE_EXIT)		return (FALSE);	if (pMS->Initialized <= 0)	{		if (pMS->CurIndex == (BYTE)~0 && pMS->Initialized == 0)			pMS->CurIndex = 0;		else if (pMS->CurIndex != (BYTE)~0)		{			RECT r;			HSTARSHIP hStarShip;			hStarShip = GetStarShipFromIndex (&master_q, pMS->CurIndex);			StarShipPtr = LockStarShip (&master_q, hStarShip);			pMS->star_bucks[pMS->side] -=					StarShipPtr->RaceDescPtr->ship_info.ship_cost;			UnlockStarShip (&master_q, hStarShip);			pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = (BYTE)~0;			SetSemaphore (&GraphicsSem);			GetShipBox (&r, pMS->side, pMS->row, pMS->col);			RepairMeleeFrame (&r);			DrawTeamString (pMS, 4);			ClearSemaphore (&GraphicsSem);		}		if (pMS->Initialized == 0)		{			SetSemaphore (&GraphicsSem);			Deselect (EDIT_MELEE);			pMS->InputFunc = DoPickShip;			DrawPickFrame (pMS);			pMS->Initialized = TRUE;			ClearSemaphore (&GraphicsSem);		}		else		{			SetSemaphore (&GraphicsSem);			Deselect (EDIT_MELEE);			pMS->Initialized = TRUE;			if (++pMS->col == NUM_MELEE_COLUMNS)			{				if (++pMS->row < NUM_MELEE_ROWS)					pMS->col = 0;				else				{					pMS->col = NUM_MELEE_COLUMNS - 1;					pMS->row = NUM_MELEE_ROWS - 1;				}			}			pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col];			ClearSemaphore (&GraphicsSem);			DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex));		}	}	else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))	{		pMS->InputFunc = 0; /* disable ship flashing */		if (!(InputState & DEVICE_BUTTON2))		{			HSTARSHIP hStarShip;						hStarShip = GetStarShipFromIndex (&master_q, pMS->CurIndex);			StarShipPtr = LockStarShip (&master_q, hStarShip);			pMS->star_bucks[pMS->side] +=					StarShipPtr->RaceDescPtr->ship_info.ship_cost;			UnlockStarShip (&master_q, hStarShip);			pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = pMS->CurIndex;			SetSemaphore (&GraphicsSem);			DrawTeamString (pMS, 4);			DrawShipBox (pMS, FALSE);			ClearSemaphore (&GraphicsSem);			if (++pMS->col == NUM_MELEE_COLUMNS)			{				if (++pMS->row < NUM_MELEE_ROWS)					pMS->col = 0;				else				{					pMS->col = NUM_MELEE_COLUMNS - 1;					pMS->row = NUM_MELEE_ROWS - 1;				}			}		}		{			RECT r;						GetFrameRect (SetAbsFrameIndex (MeleeFrame, 27), &r);			SetSemaphore (&GraphicsSem);			RepairMeleeFrame (&r);			ClearSemaphore (&GraphicsSem);		}		pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col];		DrawMeleeShipStrings (pMS, (BYTE)pMS->CurIndex);		pMS->InputFunc = DoEdit;		return (TRUE);	}	else if (InputState & DEVICE_BUTTON3)	{		DoShipSpin (pMS->CurIndex, (MUSIC_REF)0);			return (TRUE);	}	{		BYTE NewStarShip;		NewStarShip = pMS->CurIndex;		if (GetInputXComponent (InputState) < 0)		{			if (NewStarShip-- % NUM_PICK_COLS == 0)				NewStarShip += NUM_PICK_COLS;		}		else if (GetInputXComponent (InputState) > 0)		{			if (++NewStarShip % NUM_PICK_COLS == 0)				NewStarShip -= NUM_PICK_COLS;		}				if (GetInputYComponent (InputState) < 0)		{			if (NewStarShip >= NUM_PICK_COLS)				NewStarShip -= NUM_PICK_COLS;			else				NewStarShip += NUM_PICK_COLS * (NUM_PICK_ROWS - 1);		}		else if (GetInputYComponent (InputState) > 0)		{			if (NewStarShip < NUM_PICK_COLS * (NUM_PICK_ROWS - 1))				NewStarShip += NUM_PICK_COLS;			else				NewStarShip -= NUM_PICK_COLS * (NUM_PICK_ROWS - 1);		}		if (NewStarShip != pMS->CurIndex)		{			SetSemaphore (&GraphicsSem);			Deselect (EDIT_MELEE);			pMS->CurIndex = NewStarShip;			ClearSemaphore (&GraphicsSem);			DrawMeleeShipStrings (pMS, NewStarShip);		}	}	return (TRUE);}