rem: SetSemaphore (&GraphicsSem);
add: SetSemaphore (GraphicsSem);
context: DoPickBattleShip (INPUT_STATE InputState, PMENU_STATE pMS){	if (GLOBAL (CurrentActivity) & CHECK_ABORT)	{		pMS->CurFrame = 0;		return (FALSE);	}				if (!pMS->Initialized)	{		pMS->Initialized = TRUE;		pMS->InputFunc = DoPickBattleShip;		SetSemaphore (&GraphicsSem);		goto ChangeSelection;	}	else if (InputState & DEVICE_BUTTON1)	{		if ((HSTARSHIP)pMS->CurFrame)			return (FALSE);	}	else	{		COORD new_row, new_col;		new_col = pMS->first_item.x + GetInputXComponent (InputState);		new_row = pMS->first_item.y + GetInputYComponent (InputState);		if (new_row != pMS->first_item.y				|| new_col != pMS->first_item.x)		{			RECT r;			TEXT t;			COUNT crew_level, max_crew;			COUNT ship_index;			HSTARSHIP hBattleShip, hNextShip;			STARSHIPPTR StarShipPtr;			if (new_col < 0)				new_col = NUM_PICK_SHIP_COLUMNS;			else if (new_col > NUM_PICK_SHIP_COLUMNS)				new_col = 0;			if (new_row < 0)				new_row = NUM_PICK_SHIP_ROWS - 1;			else if (new_row == NUM_PICK_SHIP_ROWS)				new_row = 0;			SetSemaphore (&GraphicsSem);#ifdef NEVER			SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x1D));			DrawRectangle (&pMS->flash_rect0);#endif /* NEVER */			pMS->first_item.y = new_row;			pMS->first_item.x = new_col;ChangeSelection:			if (pMS->first_item.x == (NUM_PICK_SHIP_COLUMNS >> 1))			{				pMS->flash_rect0.corner.x = pMS->flash_rect1.corner.x - 2 + FLAGSHIP_X_OFFS;				pMS->flash_rect0.corner.y = pMS->flash_rect1.corner.y - 2 + FLAGSHIP_Y_OFFS;				pMS->flash_rect0.extent.width = FLAGSHIP_WIDTH + 4;				pMS->flash_rect0.extent.height = FLAGSHIP_HEIGHT + 4;				hBattleShip = GetTailLink (&race_q[0]); /* Flagship */			}			else			{				new_col = pMS->first_item.x;				pMS->flash_rect0.corner.x = 5 + pMS->flash_rect1.corner.x - 2						+ ((ICON_WIDTH + 4) * new_col);				if (new_col > (NUM_PICK_SHIP_COLUMNS >> 1))				{					--new_col;					pMS->flash_rect0.corner.x += FLAGSHIP_WIDTH - ICON_WIDTH;				}				pMS->flash_rect0.corner.y = 16 + pMS->flash_rect1.corner.y - 2						+ ((ICON_HEIGHT + 4) * pMS->first_item.y);				pMS->flash_rect0.extent.width = ICON_WIDTH + 4;				pMS->flash_rect0.extent.height = ICON_HEIGHT + 4;				ship_index = (pMS->first_item.y * NUM_PICK_SHIP_COLUMNS)						+ new_col;				for (hBattleShip = GetHeadLink (&race_q[0]);						hBattleShip != GetTailLink (&race_q[0]);						hBattleShip = hNextShip)				{					StarShipPtr = LockStarShip (&race_q[0], hBattleShip);					if ((COUNT)LONIBBLE (							StarShipPtr->RaceDescPtr->ship_info.var2							) == ship_index && StarShipPtr->RaceResIndex)					{						UnlockStarShip (&race_q[0], hBattleShip);						break;					}					hNextShip = _GetSuccLink (StarShipPtr);					UnlockStarShip (&race_q[0], hBattleShip);				}				if (hBattleShip == GetTailLink (&race_q[0]))					hBattleShip = 0;			}			pMS->CurFrame = (FRAME)hBattleShip;			SetContextForeGroundColor (BLACK_COLOR);			r.corner.x = pMS->flash_rect1.corner.x + 6;			r.corner.y = pMS->flash_rect1.corner.y + 5;			r.extent.width = ((ICON_WIDTH + 4) * 3) - 4;			r.extent.height = 7;			DrawFilledRectangle (&r);			if (hBattleShip == 0)				crew_level = 0;			else			{				SetContextFont (TinyFont);				t.baseline.x = r.corner.x + (r.extent.width >> 1);				t.baseline.y = r.corner.y + (r.extent.height - 1);				t.align = ALIGN_CENTER;				StarShipPtr = LockStarShip (&race_q[0], hBattleShip);				if (StarShipPtr->captains_name_index == 0)				{					t.pStr = GLOBAL_SIS (CommanderName);					t.CharCount = (COUNT)~0;					crew_level = GLOBAL_SIS (CrewEnlisted);					max_crew = GetCPodCapacity (NULL_PTR);				}				else				{					STRING locString;					locString = SetAbsStringTableIndex (							StarShipPtr->RaceDescPtr->ship_info.race_strings,							StarShipPtr->captains_name_index							);					t.pStr = (UNICODE *)GetStringAddress (locString);					t.CharCount = GetStringLength (locString);					crew_level = StarShipPtr->RaceDescPtr->ship_info.crew_level;					max_crew = StarShipPtr->RaceDescPtr->ship_info.max_crew;				}				UnlockStarShip (&race_q[0], hBattleShip);				SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x14, 0x0A, 0x00), 0x0C));				DrawText (&t);				SetContextForeGroundColor (BLACK_COLOR);			}			r.corner.x += (ICON_WIDTH + 4)					* ((NUM_PICK_SHIP_COLUMNS >> 1) + 1)					+ FLAGSHIP_WIDTH - ICON_WIDTH;			DrawFilledRectangle (&r);			if (crew_level)			{				char buf[20];				t.baseline.x = r.corner.x + (r.extent.width >> 1);				t.pStr = buf;				t.CharCount = (COUNT)~0;				if (crew_level >= max_crew)					wsprintf (buf, "%u", crew_level);				else					wsprintf (buf, "%u/%u", crew_level, max_crew);				SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02));				DrawText (&t);			}			SetFlashRect (&pMS->flash_rect0, (FRAME)0);			ClearSemaphore (&GraphicsSem);		}	}	return (TRUE);}