rem: ClearSemaphore (&GraphicsSem);
add: ClearSemaphore (GraphicsSem);
context: DoPickGame (INPUT_STATE InputState, PMENU_STATE pMS){	BYTE NewState;	STAMP s;	SUMMARY_DESC *pSD;	BOOLEAN first_time;	if (GLOBAL (CurrentActivity) & CHECK_ABORT)	{		pMS->ModuleFrame = 0;				return (FALSE);	}	first_time = (BOOLEAN)(pMS->Initialized == 0);	if (!pMS->Initialized)	{		pMS->delta_item = (SIZE)pMS->CurState;		pMS->CurState = NewState = 0;		pMS->InputFunc = DoPickGame;		SleepTask ((DWORD)pMS->CurFrame);		pMS->CurFrame = 0;		PauseMusic ();		StopSound ();		FadeMusic (128, 0);		{			extern FRAME PlayFrame;			pMS->ModuleFrame = SetAbsFrameIndex (PlayFrame, 38);		}		SetSemaphore (&GraphicsSem);		BatchGraphics ();Restart:		SetContext (SpaceContext);		LoadGameDescriptions ((SUMMARY_DESC *)pMS->CurString);		DrawCargo (1);		pMS->Initialized = TRUE;		goto ChangeGameSelection;	}	else if (InputState & DEVICE_BUTTON2)	{		SetSemaphore (&GraphicsSem);		SetFlashRect (NULL_PTR, (FRAME)0);		s.origin.x = s.origin.y = 0;		s.frame = SetRelFrameIndex (pMS->ModuleFrame, pMS->CurState);		DrawStamp (&s);		SetFlashRect ((PRECT)~0L, (FRAME)0);		ClearSemaphore (&GraphicsSem);pMS->ModuleFrame = 0;		pMS->CurState = (BYTE)pMS->delta_item;ResumeMusic ();if (pSolarSysState){#define DRAW_REFRESH (1 << 5)#define REPAIR_SCAN (1 << 6)	extern BYTE draw_sys_flags;	if (pSolarSysState->MenuState.Initialized < 3)		draw_sys_flags |= DRAW_REFRESH;	else if (pSolarSysState->MenuState.Initialized == 4)		draw_sys_flags |= REPAIR_SCAN;}		return (FALSE);	}	else if (InputState & DEVICE_BUTTON1)	{		pSD = &((SUMMARY_DESC *)pMS->CurString)[pMS->CurState];		if (pMS->delta_item == SAVE_GAME || pSD->year_index)		{RetrySave:			SetSemaphore (&GraphicsSem);			if (pMS->delta_item == SAVE_GAME)			{				STAMP MsgStamp;				extern BOOLEAN SaveGame (COUNT						which_game, SUMMARY_DESC						*summary_desc);				ConfirmSaveLoad (&MsgStamp);				if (SaveGame ((COUNT)pMS->CurState, pSD))				{					DestroyDrawable (ReleaseDrawable (MsgStamp.frame));					GLOBAL (CurrentActivity) |= CHECK_LOAD;				}				else				{					SetFlashRect (NULL_PTR, (FRAME)0);					DrawStamp (&MsgStamp);					DestroyDrawable (ReleaseDrawable (MsgStamp.frame));					ClearSemaphore (&GraphicsSem);										if (SaveProblem ())						goto RetrySave;					pMS->Initialized = FALSE;					NewState = pMS->CurState;					SetSemaphore (&GraphicsSem);					BatchGraphics ();					goto Restart;				}				ResumeMusic ();if (pSolarSysState){#define DRAW_REFRESH (1 << 5)#define REPAIR_SCAN (1 << 6)	extern BYTE draw_sys_flags;	if (pSolarSysState->MenuState.Initialized < 3)		draw_sys_flags |= DRAW_REFRESH;	else if (pSolarSysState->MenuState.Initialized == 4)		draw_sys_flags |= REPAIR_SCAN;}			}			else			{				extern BOOLEAN						LoadGame						(COUNT						which_game,						SUMMARY_DESC						*summary_desc);				ConfirmSaveLoad (0);				if (LoadGame ((COUNT)pMS->CurState, NULL_PTR))					GLOBAL (CurrentActivity) |= CHECK_LOAD;			}			SetFlashRect (NULL_PTR, (FRAME)0);			ClearSemaphore (&GraphicsSem);pMS->ModuleFrame = 0;			pMS->CurState = (BYTE)pMS->delta_item;			return (FALSE);		}	}	else	{		NewState = pMS->CurState;		if (GetInputXComponent (InputState) < 0)		{			if (NewState-- == 0)				NewState = MAX_SAVED_GAMES - 1;		}		else if (GetInputXComponent (InputState) > 0)		{			if (++NewState == MAX_SAVED_GAMES)				NewState = 0;		}		if (NewState != pMS->CurState)		{			SetSemaphore (&GraphicsSem);			BatchGraphics ();			if (((SUMMARY_DESC *)pMS->CurString)[NewState].year_index != 0)			{				if (!(((SUMMARY_DESC *)pMS->CurString)[NewState].Flags						& AFTER_BOMB_INSTALLED))				{					if (((SUMMARY_DESC *)pMS->CurString)[pMS->CurState].year_index == 0)						DrawCargo (1);					else if (((SUMMARY_DESC *)pMS->CurString)[pMS->CurState].Flags							& AFTER_BOMB_INSTALLED)						DrawCargo (2);				}				else if (((SUMMARY_DESC *)pMS->CurString)[pMS->CurState].year_index == 0)					DrawCargo (3);			}			SetFlashRect (NULL_PTR, (FRAME)0);			s.origin.x = s.origin.y = 0;			s.frame = SetRelFrameIndex (pMS->ModuleFrame, pMS->CurState);			DrawStamp (&s);ChangeGameSelection:			pMS->CurState = NewState;			ShowSummary (&((SUMMARY_DESC *)pMS->CurString)[pMS->CurState]);			s.origin.x = s.origin.y = 0;			s.frame = SetRelFrameIndex (pMS->ModuleFrame, pMS->CurState + MAX_SAVED_GAMES);			DrawStamp (&s);			if (LastActivity == CHECK_LOAD)			{				BYTE clut_buf[] = {FadeAllToColor};				UnbatchGraphics ();				LastActivity = 0;				XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2);			}			else			{				if (first_time)				{					RECT r;						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 ();			}			{				RECT r;								r.corner.x = 3 + (NewState * 21);				r.corner.y = 176;				r.extent.width = 18;				r.extent.height = 18;				SetFlashRect (&r, (FRAME)0);			}			ClearSemaphore (&GraphicsSem);		}	}	return (TRUE);}