rem: ClearSemaphore (&GraphicsSem);
add: ClearSemaphore (GraphicsSem);
context: DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS){#define MIN_ACCEL_DELAY (ONE_SECOND / 60)#define MAX_ACCEL_DELAY (ONE_SECOND / 8)	STAMP s;	UNICODE buf[30];	static UNICODE last_buf;	pMS->MenuRepeatDelay = (COUNT)pMS->CurState;	if (!pMS->Initialized)	{		pMS->Initialized = MAKE_WORD (				KBDToUNICODE (SK_INSERT),				KBDToUNICODE (SK_DELETE)				);		pMS->InputFunc = DoMoveCursor;		pMS->flash_task = AddTask (flash_cursor_func, 2048);		s.origin.x = UNIVERSE_TO_DISPX (pMS->first_item.x);		s.origin.y = UNIVERSE_TO_DISPY (pMS->first_item.y);		last_buf = ~0;		buf[0] = '\0';		goto UpdateCursorInfo;	}	else if (InputState & DEVICE_BUTTON2)	{		SetSemaphore (&GraphicsSem);		if (pMS->flash_task)		{			DeleteTask (pMS->flash_task);			pMS->flash_task = 0;		}		ClearSemaphore (&GraphicsSem);		return (FALSE);	}	else if (InputState & DEVICE_BUTTON1)	{		GLOBAL (autopilot) = pMS->first_item;		DrawStarMap (0, NULL_PTR);	}	else	{		SBYTE sx, sy;		POINT pt;		SIZE ZoomIn, ZoomOut;		ZoomIn = ZoomOut = 0;		if (InputState & DEVICE_LEFTSHIFT)			ZoomIn = 1;		else if (InputState & DEVICE_RIGHTSHIFT)			ZoomOut = 1;		ZoomStarMap (ZoomOut - ZoomIn);		sx = GetInputXComponent (InputState);		sy = GetInputYComponent (InputState);		if (sx == 0 && sy == 0)		{			extern INPUT_STATE OldInputState;			if (OldInputState == 0)				pMS->CurState = MAX_ACCEL_DELAY;		}		else		{			if (pMS->CurState > MIN_ACCEL_DELAY)				--pMS->CurState;			pt.x = UNIVERSE_TO_DISPX (pMS->first_item.x);			pt.y = UNIVERSE_TO_DISPY (pMS->first_item.y);			s.origin.x = pt.x + sx;			s.origin.y = pt.y + sy;			buf[0] = '\0';			if (sx)			{				pMS->first_item.x =						DISP_TO_UNIVERSEX (s.origin.x) - sx;				while (UNIVERSE_TO_DISPX (pMS->first_item.x) == pt.x)				{					pMS->first_item.x += sx;					if (pMS->first_item.x < 0)					{						pMS->first_item.x = 0;						break;					}					else if (pMS->first_item.x > MAX_X_UNIVERSE)					{						pMS->first_item.x = MAX_X_UNIVERSE;						break;					}				}				s.origin.x = UNIVERSE_TO_DISPX (pMS->first_item.x);			}			if (sy)			{				pMS->first_item.y =						DISP_TO_UNIVERSEY (s.origin.y) + sy;				while (UNIVERSE_TO_DISPY (pMS->first_item.y) == pt.y)				{					pMS->first_item.y -= sy;					if (pMS->first_item.y < 0)					{						pMS->first_item.y = 0;						break;					}					else if (pMS->first_item.y > MAX_Y_UNIVERSE)					{						pMS->first_item.y = MAX_Y_UNIVERSE;						break;					}				}				s.origin.y = UNIVERSE_TO_DISPY (pMS->first_item.y);			}			if (s.origin.x < 0 || s.origin.y < 0					|| s.origin.x >= SIS_SCREEN_WIDTH					|| s.origin.y >= SIS_SCREEN_HEIGHT)			{				pMS->flash_rect1.corner = pMS->first_item;				DrawStarMap (0, NULL_PTR);				s.origin.x = UNIVERSE_TO_DISPX (pMS->first_item.x);				s.origin.y = UNIVERSE_TO_DISPY (pMS->first_item.y);			}			else			{				SetSemaphore (&GraphicsSem);				EraseCursor (pt.x, pt.y);				// ClearDrawable ();				DrawCursor (s.origin.x, s.origin.y);				ClearSemaphore (&GraphicsSem);			}UpdateCursorInfo:			{				STAR_DESCPTR SDPtr, BestSDPtr;				SDPtr = BestSDPtr = 0;				while ((SDPtr = FindStar (SDPtr, &pMS->first_item, 75, 75)))				{					if (UNIVERSE_TO_DISPX (SDPtr->star_pt.x) == s.origin.x							&& UNIVERSE_TO_DISPY (SDPtr->star_pt.y) == s.origin.y							&& (BestSDPtr == 0							|| STAR_TYPE (SDPtr->Type) >= STAR_TYPE (BestSDPtr->Type)))						BestSDPtr = SDPtr;				}				if (BestSDPtr)				{					pMS->first_item = BestSDPtr->star_pt;					GetClusterName (BestSDPtr, buf);				}			}			if (GET_GAME_STATE (ARILOU_SPACE))			{				if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)				{					pt.x = ARILOU_SPACE_X;					pt.y = ARILOU_SPACE_Y;				}				else				{					pt.x = QUASI_SPACE_X;					pt.y = QUASI_SPACE_Y;				}				if (UNIVERSE_TO_DISPX (pt.x) == s.origin.x						&& UNIVERSE_TO_DISPY (pt.y) == s.origin.y)				{					pMS->first_item = pt;					wstrcpy (buf, GAME_STRING (STAR_STRING_BASE + 132));				}			}			{				COUNT fuel_required;				DWORD f;				if (LOBYTE (GLOBAL (CurrentActivity)) != IN_HYPERSPACE)					pt = CurStarDescPtr->star_pt;				else				{					pt.x = LOGX_TO_UNIVERSE (GLOBAL_SIS (log_x));					pt.y = LOGY_TO_UNIVERSE (GLOBAL_SIS (log_y));				}				pt.x -= pMS->first_item.x;				pt.y -= pMS->first_item.y;				f = (DWORD)((long)pt.x * pt.x + (long)pt.y * pt.y);				if (f == 0 || GET_GAME_STATE (ARILOU_SPACE_SIDE) > 1)					fuel_required = 0;				else					fuel_required = square_root (f) + (FUEL_TANK_SCALE >> 1);				SetSemaphore (&GraphicsSem);				DrawHyperCoords (pMenuState->first_item);				if (last_buf == (UNICODE) ~0						|| (buf[0] && !last_buf) || (!buf[0] && last_buf))				{					last_buf = buf[0];					DrawSISMessage (buf);				}				wsprintf (buf, "%s %u.%u",						GAME_STRING (NAVIGATION_STRING_BASE + 4),						fuel_required / FUEL_TANK_SCALE,						(fuel_required % FUEL_TANK_SCALE) / 10);				DrawStatusMessage (buf);				ClearSemaphore (&GraphicsSem);			}		}	}	return (TRUE);}