rem: ClearSemaphore (&GraphicsSem);
add: ClearSemaphore (GraphicsSem);
context: int IPtask_func(void* blah){#define IP_FRAME_RATE 4#define DEBOUNCE_DELAY ((ONE_SECOND >> 1) / IP_FRAME_RATE)	BYTE MenuTransition;	DWORD NextTime;	INPUT_STATE InputState;	TaskSwitch ();	if (LastActivity != CHECK_LOAD)		InputState = 0;	else		InputState = DEVICE_BUTTON2;	MenuTransition = 0;	NextTime = GetTimeCounter ();	for (;;)	{		CONTEXT OldContext;		BOOLEAN InnerSystem;		RECT r;		InnerSystem = FALSE;		SetSemaphore (&GraphicsSem);		while (pSolarSysState->MenuState.Initialized > 1				|| (GLOBAL (CurrentActivity)				& (START_ENCOUNTER | END_INTERPLANETARY				| CHECK_ABORT | CHECK_LOAD))				|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0)		{			InputState = 0;			ClearSemaphore (&GraphicsSem);			TaskSwitch ();			NextTime = SetSemaphore (&GraphicsSem);		}		OldContext = SetContext (StatusContext);		if (pSolarSysState->MenuState.CurState				|| pSolarSysState->MenuState.Initialized == 0)		{			InputState = 0;			if (draw_sys_flags & DRAW_REFRESH)				goto TheMess;		}		else		{			if (MenuTransition)			{				if (MenuTransition < DEBOUNCE_DELAY						&& !(InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)))					MenuTransition = 0;				else				{					--MenuTransition;					InputState &= ~(DEVICE_BUTTON1 | DEVICE_BUTTON2);				}			}TheMess:			// this is a mess:			// we have to treat things slightly differently depending on the			// situation (note that DRAW_REFRESH means we had gone to the			// menu)			InnerSystem = (BOOLEAN) (pSolarSysState->pBaseDesc !=					pSolarSysState->PlanetDesc);			if (InnerSystem)			{				BatchGraphics ();				if (draw_sys_flags & DRAW_REFRESH)				{					InnerSystem = FALSE;					DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE);				}			}			else if (draw_sys_flags & DRAW_REFRESH)			{				BatchGraphics ();				DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);			}						if (MenuTransition < DEBOUNCE_DELAY)				UndrawShip (InputState);			if (pSolarSysState->MenuState.Initialized != 1)				InputState = 0;		}				if (old_radius)			ScaleSystem ();		BatchGraphics ();				if (!(draw_sys_flags & DRAW_REFRESH)) // don't repair from Extra or draw ship if forcing repair		{			CONTEXT OldContext;				OldContext = SetContext (SpaceContext);			GetContextClipRect (&r);			DrawFromExtraScreen (&r);			SetContext (OldContext);			// Don't redraw if entering/exiting inner system			// this screws up ScreenTransition by leaving an image of the			// ship in the ExtraScreen (which we use for repair)			if (pSolarSysState->MenuState.CurState == 0					&& (InnerSystem ^ (BOOLEAN)(pSolarSysState->pBaseDesc != pSolarSysState->PlanetDesc)))				;			else				RedrawQueue (FALSE);		}				if (InnerSystem)		{			if (pSolarSysState->pBaseDesc == pSolarSysState->PlanetDesc)			{				// transition screen if we left inner system (if going				// from outer to inner, ScreenTransition happens elsewhere)				r.corner.x = SIS_ORG_X;				r.corner.y = SIS_ORG_Y;				r.extent.width = SIS_SCREEN_WIDTH;				r.extent.height = SIS_SCREEN_HEIGHT;				ScreenTransition (3, &r);			}			UnbatchGraphics ();		}		else if (draw_sys_flags & DRAW_REFRESH)		{			// must set rect for LoadInto... below			r.corner.x = SIS_ORG_X;			r.corner.y = SIS_ORG_Y;			r.extent.width = SIS_SCREEN_WIDTH;			r.extent.height = SIS_SCREEN_HEIGHT;			ScreenTransition (3, &r);			UnbatchGraphics ();		}				UnbatchGraphics ();				if (draw_sys_flags & UNBATCH_SYS)		{			// means we're forcing a redraw/transition from Init- & ChangeSolarSys			draw_sys_flags &= ~UNBATCH_SYS;			UnbatchGraphics ();		}				// LoadInto Extra if we left inner system, or we forced a redraw		if ((InnerSystem && pSolarSysState->pBaseDesc == pSolarSysState->PlanetDesc)				|| (draw_sys_flags & DRAW_REFRESH))		{			LoadIntoExtraScreen (&r);			draw_sys_flags &= ~DRAW_REFRESH;		}		SetContext (OldContext);		ClearSemaphore (&GraphicsSem);		if (!(InputState & DEVICE_BUTTON2))		{			NextTime = SleepTask (NextTime + IP_FRAME_RATE);			if (pSolarSysState->MenuState.CurState					|| pSolarSysState->MenuState.Initialized != 1)				InputState = 0;			else				InputState = GetInputState (NormalInput);			JournalInput (InputState);						if (InputState & DEVICE_EXIT)				InputState = ConfirmExit ();		}		else		{			MenuTransition = DEBOUNCE_DELAY;			SuspendGameClock ();			SetSemaphore (&GraphicsSem);			DrawStatusMessage (NULL_PTR);			if (LastActivity == CHECK_LOAD)				pSolarSysState->MenuState.CurState = (ROSTER + 1) + 1;			else			{				ClearSemaphore (&GraphicsSem);				DrawMenuStateStrings (PM_SCAN, STARMAP);				SetSemaphore (&GraphicsSem);				pSolarSysState->MenuState.CurState = STARMAP + 1;			}			SetFlashRect ((PRECT)~0L, (FRAME)0);			FlushInput ();			ClearSemaphore (&GraphicsSem);		}	}	(void) blah;  /* Satisfying compiler (unused parameter) */	return(0);}