<NME> GAMEFLOW.C
<BEF> #include "GAMEFLOW.H"

#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif

#if !PC_VERSION
#include "3D_GEN.H"
#include "TITSEQ.H"
#include "TYPEDEFS.H"
#endif
#include "CDTRACKS.H"
#include "CODEWAD.H"
#include "CONTROL.H"
#include "DELTAPAK.H"
#include "DRAW.H"

#include "FILE.H"
#if PSX_VERSION || PSXPC_VERSION || PSXPC_TEST
#include "CD.H"
#include "MOVIE.H"
#include "MEMCARD.H"
#include "SPUSOUND.H"
#include "MISC.H"
#include "SFX.H"
#include "GPU.H"
#include "DRAWPHAS.H"
#include "ROOMLOAD.H"
#include "PROFILE.H"
#include <LIBAPI.H>
#include <LIBGTE.H>
#elif SAT_VERSION
#include "CD.H"
#include "MOVIE.H"
#include "MEMCARD.H"
#include "SPUSOUND.H"
#include "MISC.H"
#include "SFX.H"
#include "GPU.H"
#include "DRAWPHAS.H"
#include "ROOMLOAD.H"
#endif

#if PC_VERSION
#include "SPECIFIC.H"
#include "DRAWPRIMITIVE.H"
#include "DISPLAY.H"
#include "GAME.H"
#include "INIT.H"
#endif

#include "HEALTH.H"
#include "ITEMS.H"
#include "LARA.H"
#include "MALLOC.H"
#include "NEWINV2.H"
#include INPUT_H

#include "SAVEGAME.H"
#include "SOUND.H"

#include "SPECIFIC.H"
#include "SPOTCAM.H"
#include "TOMB4FX.H"

#include <assert.h>
#if PSXPC_VERSION || PSXPC_TEST
	#include <stdint.h>
#if DEBUG_VERSION
#include "PROFILE.H"
#endif
#endif

#if (PSX_VERSION || SAT_VERSION) && !PSXPC_TEST
typedef unsigned int uintptr_t;
#endif

#if PSX_VERSION || SAT_VERSION
#include "FXTRIG.H"
#include "TEXT_S.H"
#endif

#if PSXPC_TEST
#include <LIBETC.H>
#endif

#if !SAT_VERSION
#include <string.h>
#endif
#include "LOT.H"
#include "TEXT.H"

#define GF_SCRIPT_FILENAME "SCRIPT.DAT"

unsigned char gfGameMode = 1;
unsigned char gfNumMips;
int scroll_pos;
char DEL_playingamefmv = 0;
char num_fmvs = 0;
char fmv_to_play[2];
unsigned short dels_cutseq_selector_flag;
unsigned short dels_cutseq_player = 0;
char Chris_Menu;
unsigned char gfLegendTime = 0;
unsigned char bDoCredits = 0;
static unsigned char gfCutNumber = 0;
unsigned char gfInitialiseGame = 1;
long nframes = 1;
unsigned char gfNumPickups = 0;
unsigned char gfNumTakeaways = 0;
char CanLoad;
struct GAMEFLOW* Gameflow;
unsigned short* gfStringOffset = 0;
char* gfStringWad;
unsigned short* gfFilenameOffset;
char* gfFilenameWad;
unsigned char gfCurrentLevel;
unsigned char gfLevelComplete;
unsigned char gfRequiredStartPos;
unsigned short gfLevelFlags;
unsigned char gfLevelNames[40];
unsigned char gfResidentCut[4];
unsigned char gfResetHubDest;
char gfUVRotate;
char gfLayer1Vel;
char gfLayer2Vel;
CVECTOR gfLayer1Col;
CVECTOR gfLayer2Col;
unsigned long GameTimer;
struct PHD_VECTOR gfLensFlare;
CVECTOR gfLensFlareColour;
unsigned char gfMirrorRoom;
unsigned char gfMips[8];
char title_controls_locked_out;
long gfScriptLen = 0;
unsigned char gfLegend;
unsigned char gfWadNames[40];
static unsigned short* gfScriptOffset;
static unsigned char* gfScriptWad;
static char* gfExtensions;
static int gfStatus;
static unsigned long OldSP;
unsigned char gfPickups[16];
unsigned char gfTakeaways[16];
int special_features_num = -1;
#if PC_VERSION
char* gfScriptFile;

const char* screens[5] =
{
	"SCREENS\\STORY1.STR", "SCREENS\\NXG.STR", "SCREENS\\STORY2.STR", "SCREENS\\GALLERY.STR", "SCREENS\\SCREENS.STR"
};
#endif

void DoGameflow()//10F5C(<), 10FD8(<)
{
	unsigned char* gf; // $a3
	unsigned char n; // $a1

#if PC_VERSION
	do_boot_screen(Gameflow->Language);
#else
	LoadGameflow();
#endif

#if DISC_VERSION && PSX_VERSION && PLAY_FMVS
	S_PlayFMV(FMV_COPYRIGHT_INTRO, 0);
	S_PlayFMV(FMV_GAME_INTRO, 0);
#endif

	num_fmvs = 0;
	fmv_to_play[1] = 0;
	fmv_to_play[0] = 0;

	gfCurrentLevel = Gameflow->TitleEnabled == 0;
	gf = &gfScriptWad[gfScriptOffset[gfCurrentLevel]];

	while (1)
	{
		switch (n = *gf++)
		{
		case GF_FMV:
#if PLAY_FMVS
			fmv_to_play[num_fmvs++] = *gf++;
#else
			gf++;
#endif
			break;
		case GF_LEVEL:

			gfLevelFlags = gf[1] | (gf[2] << 8);

			if ((gfLevelFlags & 0x8000))
			{
				gfStatus = 999;
				gfCurrentLevel++;
			}
			else
			{
				//loc_112E4
				DoLevel(gf[3], gf[4]);
			}
			//loc_112F8

			gfLegendTime = 0;
			LaserSight = 0;
			BinocularRange = 0;
			gfResidentCut[0] = 0;///@CHECK in asm it's *(int*)&gfResidentCut[0] = 0, check if optimised to this
			gfResidentCut[1] = 0;
			gfResidentCut[2] = 0;
			gfResidentCut[3] = 0;
			gfUVRotate = 0;
			gfNumMips = 0;
			gfNumPickups = 0;
			gfMirrorRoom = 255;

			if (gfStatus != 2)
			{
				if (gfStatus < 3)
				{
					if (gfStatus == 1)
					{
						//loc_11364
						gfInitialiseGame = 1;
						gfCurrentLevel = Gameflow->TitleEnabled == 0;
					}
				}
				else
				{
					//loc_11348
					if (gfStatus == 3)
					{
						//loc_1138C
						if (!Gameflow->DemoDisc && Gameflow->nLevels != 2 && gfLevelComplete <= Gameflow->nLevels)
						{
							//loc_11460
							gfCurrentLevel = gfLevelComplete;
						}
						//loc_113CC
						gfCurrentLevel = 0;
					}
					else if (gfStatus == 4)
					{
						//loc_115DC
						return;
					}
				}
			}
			else
			{
				//loc_1146C
				gfGameMode = 4;
				gfCurrentLevel = savegame.CurrentLevel;
			}
			//loc_11480
			gf = &gfScriptWad[gfScriptOffset[gfCurrentLevel]];
			break;
		case GF_TITLE_LEVEL:

			gfLevelFlags = gf[0] | (gf[1] << 8);
			DoTitle(gf[2], gf[3]);

			gfMirrorRoom = 255;
			gfResidentCut[0] = 0;///@CHECK in asm it's *(int*)&gfResidentCut[0] = 0, check if optimised to this
			gfResidentCut[1] = 0;
			gfResidentCut[2] = 0;
			gfResidentCut[3] = 0;
			gfUVRotate = 0;
			gfNumMips = 0;
			gfNumPickups = 0;

			if (gfStatus == 3)
			{
				//loc_11450
				gfGameMode = 0;
				gfInitialiseGame = 1;
				gfCurrentLevel = gfLevelComplete;
			}
			else if (gfStatus < 4)
			{
				if (gfStatus == 2)
				{
					//loc_11470
					gfGameMode = 4;
					gfCurrentLevel = savegame.CurrentLevel;
				}
			}
			else if (gfStatus == 4)
			{
				//loc_115DC
				return;
			}
			//loc_11480
			gf = &gfScriptWad[gfScriptOffset[gfCurrentLevel]];
			break;
		case GF_LEVEL_DATA_END:
			continue;
			break;
		case GF_CUT:
			gfCutNumber = *gf++;
			break;
		case GF_RESIDENTCUT1:
			gfResidentCut[0] = *gf++;
			break;
		case GF_RESIDENTCUT2:
			gfResidentCut[1] = *gf++;
			break;
		case GF_RESIDENTCUT3:
			gfResidentCut[2] = *gf++;
			break;
		case GF_RESIDENTCUT4:
			gfResidentCut[3] = *gf++;
			break;
		case GF_LAYER1:
			LightningRGB[0] = *gf;
			LightningRGBs[0] = *gf;
			gfLayer1Col.r = *gf++;

			LightningRGB[1] = *gf;
			LightningRGBs[1] = *gf;
			gfLayer1Col.g = *gf++;

			gfLayer1Col.cd = 44;
			LightningRGB[2] = *gf;
			LightningRGBs[2] = *gf;
			gfLayer1Col.b = *gf++;

			gfLayer1Vel = *gf++;
			break;
		case GF_LAYER2:
			LightningRGB[0] = *gf;
			LightningRGBs[0] = *gf;
			gfLayer2Col.r = *gf++;

			LightningRGB[1] = *gf;
			LightningRGBs[1] = *gf;
			gfLayer2Col.g = *gf++;

			gfLayer2Col.cd = 46;
			LightningRGB[2] = *gf;
			LightningRGBs[2] = *gf;
			gfLayer2Col.b = *gf++;

			gfLayer2Vel = *gf++;
			break;
		case GF_UV_ROTATE:
			gfUVRotate = *gf++;
			break;
		case GF_LEGEND:
			gfLegend = *gf++;
			if (gfGameMode != 4)
			{
				gfLegendTime = 150;
			}
			break;
		case GF_LENS_FLARE:

			gfLensFlare.x = ((gf[1] << 8) | gf[0]) << 8;
			gfLensFlare.y = ((gf[2] | (gf[3] << 8)) << 16) >> 8;
			gfLensFlare.z = ((gf[5] << 8) | gf[4]) << 8;

			gfLensFlareColour.r = gf[6];
			gfLensFlareColour.g = gf[7];
			gfLensFlareColour.b = gf[8];

			gf += 9;
			break;
		case GF_MIRROR:
			gfMirrorRoom = *gf;
			gfMirrorZPlane = (gf[4] << 24) | (gf[3] << 16) | (gf[2] << 8) | gf[1];
			gf += 5;
			break;
		case GF_FOG:
			gf += 3;
			break;
		case GF_ANIMATING_MIP:
			//loc_111DC:
			gfMips[gfNumMips++] = *gf++;
			break;
		case GF_RESET_HUB:
			//loc_11290:
			gfResetHubDest = *gf++;
			break;
		case GF_KEY_ITEM1:
		case GF_KEY_ITEM2:
		case GF_KEY_ITEM3:
		case GF_KEY_ITEM4:
		case GF_KEY_ITEM5:
		case GF_KEY_ITEM6:
		case GF_KEY_ITEM7:
		case GF_KEY_ITEM8:
		case GF_KEY_ITEM9:
		case GF_KEY_ITEM10:
		case GF_KEY_ITEM11:
		case GF_KEY_ITEM12:
		case GF_PUZZLE_ITEM1:
		case GF_PUZZLE_ITEM2:
		case GF_PUZZLE_ITEM3:
		case GF_PUZZLE_ITEM4:
		case GF_PUZZLE_ITEM5:
		case GF_PUZZLE_ITEM6:
		case GF_PUZZLE_ITEM7:
		case GF_PUZZLE_ITEM8:
		case GF_PUZZLE_ITEM9:
		case GF_PUZZLE_ITEM10:
		case GF_PUZZLE_ITEM11:
		case GF_PUZZLE_ITEM12:
		case GF_PICKUP_ITEM1:
		case GF_PICKUP_ITEM2:
		case GF_PICKUP_ITEM3:
		case GF_PICKUP_ITEM4:
		case GF_EXAMINE1:
		case GF_EXAMINE2:
		case GF_EXAMINE3:
		case GF_KEY_ITEM1_COMBO1:
		case GF_KEY_ITEM1_COMBO2:
		case GF_KEY_ITEM2_COMBO1:
		case GF_KEY_ITEM2_COMBO2:
		case GF_KEY_ITEM3_COMBO1:
		case GF_KEY_ITEM3_COMBO2:
		case GF_KEY_ITEM4_COMBO1:
		case GF_KEY_ITEM4_COMBO2:
		case GF_KEY_ITEM5_COMBO1:
		case GF_KEY_ITEM5_COMBO2:
		case GF_KEY_ITEM6_COMBO1:
		case GF_KEY_ITEM6_COMBO2:
		case GF_KEY_ITEM7_COMBO1:
		case GF_KEY_ITEM7_COMBO2:
		case GF_KEY_ITEM8_COMBO1:
		case GF_KEY_ITEM8_COMBO2:
		case GF_PUZZLE_ITEM1_COMBO1:
		case GF_PUZZLE_ITEM1_COMBO2:
		case GF_PUZZLE_ITEM2_COMBO1:
		case GF_PUZZLE_ITEM2_COMBO2:
		case GF_PUZZLE_ITEM3_COMBO1:
		case GF_PUZZLE_ITEM3_COMBO2:
		case GF_PUZZLE_ITEM4_COMBO1:
		case GF_PUZZLE_ITEM4_COMBO2:
		case GF_PUZZLE_ITEM5_COMBO1:
		case GF_PUZZLE_ITEM5_COMBO2:
		case GF_PUZZLE_ITEM6_COMBO1:
		case GF_PUZZLE_ITEM6_COMBO2:
		case GF_PUZZLE_ITEM7_COMBO1:
		case GF_PUZZLE_ITEM7_COMBO2:
		case GF_PUZZLE_ITEM8_COMBO1:
		case GF_PUZZLE_ITEM8_COMBO2:
		case GF_PICKUP_ITEM1_COMBO1:
		case GF_PICKUP_ITEM1_COMBO2:
		case GF_PICKUP_ITEM2_COMBO1:
		case GF_PICKUP_ITEM2_COMBO2:
		case GF_PICKUP_ITEM3_COMBO1:
		case GF_PICKUP_ITEM3_COMBO2:
		case GF_PICKUP_ITEM4_COMBO1:
		case GF_PICKUP_ITEM4_COMBO2:
		default:
			//def_10FE0
			if (((n + 0x6E) & 0xFF) < 8)
			{
				inventry_objects_list[(n + 0xA3) & 0xFF].objname = gf[0] | (gf[1] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].yoff = gf[2] | (gf[3] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].scale1 = gf[4] | (gf[5] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].yrot = gf[6] | (gf[7] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].xrot = gf[8] | (gf[9] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].zrot = gf[10] | (gf[11] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].flags = gf[12] | (gf[13] << 8);
			}
			else if (((n + 0x62) & 0xFF) < 8)
			{
				inventry_objects_list[(n + 0x7F) & 0xFF].objname = gf[0] | (gf[1] << 8);
				inventry_objects_list[(n + 0x7F) & 0xFF].yoff = gf[2] | (gf[3] << 8);
				inventry_objects_list[(n + 0x7F) & 0xFF].scale1 = gf[4] | (gf[5] << 8);
				inventry_objects_list[(n + 0x7F) & 0xFF].yrot = gf[6] | (gf[7] << 8);
				inventry_objects_list[(n + 0x7F) & 0xFF].xrot = gf[8] | (gf[9] << 8);
				inventry_objects_list[(n + 0x7F) & 0xFF].zrot = gf[10] | (gf[11] << 8);
				inventry_objects_list[(n + 0x7F) & 0xFF].flags = gf[12] | (gf[13] << 8);
			}
			else if (((n + 0x56) & 0xFF) < 4)
			{
				inventry_objects_list[(n + 0xA3) & 0xFF].objname = gf[0] | (gf[1] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].yoff = gf[2] | (gf[3] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].scale1 = gf[4] | (gf[5] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].yrot = gf[6] | (gf[7] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].xrot = gf[8] | (gf[9] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].zrot = gf[10] | (gf[11] << 8);
				inventry_objects_list[(n + 0xA3) & 0xFF].flags = gf[12] | (gf[13] << 8);
			}
			else if (((n + 0x52) & 0xFF) < 3)
			{
				inventry_objects_list[(n + 0xAD) & 0xFF].objname = gf[0] | (gf[1] << 8);
				inventry_objects_list[(n + 0xAD) & 0xFF].yoff = gf[2] | (gf[3] << 8);
				inventry_objects_list[(n + 0xAD) & 0xFF].scale1 = gf[4] | (gf[5] << 8);
				inventry_objects_list[(n + 0xAD) & 0xFF].yrot = gf[6] | (gf[7] << 8);
				inventry_objects_list[(n + 0xAD) & 0xFF].xrot = gf[8] | (gf[9] << 8);
#if DEBUG_VERSION
	ProfileRGB(255, 255, 255);
#endif

	OldSP = SetSp(0x1F8003E0);
#endif

	gfStatus = ControlPhase(nframes, (gfGameMode ^ 2) < 1 ? 1 : 0);

#if PSX_VERSION
#if DEBUG_VERSION
	SetSp(OldSP);
	ProfileRGB(0, 0, 0);
#endif
#endif
			{
				inventry_objects_list[(n + 0x64) & 0xFF].objname = gf[0] | (gf[1] << 8);
				inventry_objects_list[(n + 0x64) & 0xFF].yoff = gf[2] | (gf[3] << 8);
				inventry_objects_list[(n + 0x64) & 0xFF].scale1 = gf[4] | (gf[5] << 8);
				inventry_objects_list[(n + 0x64) & 0xFF].yrot = gf[6] | (gf[7] << 8);
				inventry_objects_list[(n + 0x64) & 0xFF].xrot = gf[8] | (gf[9] << 8);
				inventry_objects_list[(n + 0x64) & 0xFF].zrot = gf[10] | (gf[11] << 8);
				inventry_objects_list[(n + 0x64) & 0xFF].flags = gf[12] | (gf[13] << 8);
			}
			else if (((n + 0x2F) & 0xFF) < 8)
			{
				inventry_objects_list[(n + 0x80) & 0xFF].objname = gf[0] | (gf[1] << 8);
				inventry_objects_list[(n + 0x80) & 0xFF].yoff = gf[2] | (gf[3] << 8);
				inventry_objects_list[(n + 0x80) & 0xFF].scale1 = gf[4] | (gf[5] << 8);
				inventry_objects_list[(n + 0x80) & 0xFF].yrot = gf[6] | (gf[7] << 8);
				inventry_objects_list[(n + 0x80) & 0xFF].xrot = gf[8] | (gf[9] << 8);
				inventry_objects_list[(n + 0x80) & 0xFF].zrot = gf[10] | (gf[11] << 8);
				inventry_objects_list[(n + 0x80) & 0xFF].flags = gf[12] | (gf[13] << 8);
			}
			gf += 14;
			break;
		case GF_GIVE_ITEM_AT_STARTUP:
			//loc_11198
			gfPickups[gfNumPickups++] = *gf;
			gf += 2;
			break;
		case GF_LOSE_ITEM_AT_STARTUP:
			//loc_111BC
			gfTakeaways[gfNumTakeaways++] = *gf;
			gf += 2;
			break;
		}

		//loc_10FB4
	}
}

void LoadGameflow()//102E0(<), 102B0(<) (F)
{
	int i;
	int len;
	unsigned char* s = NULL;
	struct STRINGHEADER sh;
	int j;
	int flag;

#if PSX_VERSION || PSXPC_VERSION
	len = FILE_Length(GF_SCRIPT_FILENAME);
	s = (unsigned char*)game_malloc(len);
	FILE_Load(GF_SCRIPT_FILENAME, s);
#endif

#if PC_VERSION
	LoadFile(GF_SCRIPT_FILENAME, (void**)&s);
	gfScriptFile = (char*)s;
#endif

	Gameflow = (struct GAMEFLOW*)s;
	s += sizeof(struct GAMEFLOW);

	gfExtensions = (char*)s;
	s += 40;

	gfFilenameOffset = (unsigned short*)s;
	s += Gameflow->nFileNames * sizeof(unsigned short);

	gfFilenameWad = (char*)s;
	s += Gameflow->FileNameLen;

	gfScriptOffset = (unsigned short*)s;

#if !PC_VERSION
	gfScriptLen = (len + 3) & -4;
#endif
	s += Gameflow->nLevels * sizeof(unsigned short);

	gfScriptWad = s;
	s += Gameflow->ScriptLen;

	//loc_103A8
#if PC_VERSION
	for(gfStringOffset = NULL, i = 0; !LoadFile((char*)s, (void**)&gfStringOffset); i++, gfScriptOffset = NULL)
#else
	gfStringOffset = (unsigned short*)(((uintptr_t)s + 3) & -4);

	for(i = 0; FILE_Length((char*)s) == -1; i++)
#endif
	{
		s += strlen((char*)s) + 1;
	}

	Gameflow->Language = i;

#if !PC_VERSION
	FILE_Load((char*)s, gfStringOffset);
#endif

	memcpy(&sh, &gfStringOffset[0], sizeof(struct STRINGHEADER));

#if PSX_VERSION || PSXPC_VERSION

	memcpy(&gfStringOffset[0], &gfStringOffset[sizeof(struct STRINGHEADER) / sizeof(unsigned short)], (sh.nStrings + sh.nPSXStrings) * sizeof(unsigned short));

	gfStringWad = (char*)&gfStringOffset[sh.nStrings + sh.nPSXStrings];

#if BETA_VERSION
	memcpy(&gfStringOffset[sh.nStrings + sh.nPSXStrings], &gfStringOffset[317], sh.StringWadLen + sh.PSXStringWadLen);
#else
	memcpy(&gfStringOffset[sh.nStrings + sh.nPSXStrings], &gfStringOffset[315], sh.StringWadLen + sh.PSXStringWadLen);
#endif

	gfScriptLen += (((sh.nStrings + sh.nPSXStrings * sizeof(unsigned short)) + sh.StringWadLen + sh.PSXStringWadLen + 3) & -4);

#else
	memcpy(&gfStringOffset[0], &gfStringOffset[sizeof(struct STRINGHEADER) / sizeof(unsigned short)], (sh.nStrings + sh.nPSXStrings + sh.nPCStrings) * sizeof(unsigned short));

	gfStringWad = (char*)&gfStringOffset[sh.nStrings + sh.nPSXStrings + sh.nPCStrings];

	memcpy(&gfStringOffset[sh.nStrings + sh.nPSXStrings + sh.nPCStrings], &gfStringOffset[315], sh.StringWadLen + sh.PSXStringWadLen + sh.PCStringWadLen);///@TODO check 315 const for PC

#endif

	//loc_10490
#if PSX_VERSION || PSXPC_VERSION
	for (i = 0; i < sh.nStrings + sh.nPSXStrings; i++)
#else
	for (i = 0; i < sh.nStrings + sh.nPSXStrings + sh.nPCStrings - 1; i++)
#endif
	{
		for (j = 0; j < gfStringOffset[i + 1] - gfStringOffset[i] - 1; j++)
		{
			gfStringWad[gfStringOffset[i] + j] ^= 0xA5;
		}
		//loc_104DC
	}//loc_104F8

	if (Gameflow->nLevels != 0)
	{
		//loc_10510
		for (i = 0; i + 1 < Gameflow->nLevels; i++)
		{
			flag = 0;
			s = &gfScriptWad[gfScriptOffset[i]];

			//loc_10530
			do
			{
				switch (*s++)
				{
				case GF_FMV:
				case GF_CUT:
				case GF_RESIDENTCUT1:
				case GF_RESIDENTCUT2:
				case GF_RESIDENTCUT3:
				case GF_RESIDENTCUT4:
				case GF_UV_ROTATE:
				case GF_LEGEND:
				case GF_ANIMATING_MIP:
				case GF_RESET_HUB:
					//loc_10568
					s += 1;
					break;
				case GF_LEVEL:
					//loc_10588
					gfLevelNames[i] = *s;
					gfWadNames[i] = s[3];
					s += 5;
					break;
				case GF_TITLE_LEVEL:
				case GF_LAYER1:
				case GF_LAYER2:
					//loc_10578
					s += 4;
					break;
				case GF_LEVEL_DATA_END:
					//loc_105BC
					flag = 1;
					break;
				case GF_LENS_FLARE:
					//loc_105B4
					s += 9;
					break;
				case GF_MIRROR:
					//loc_10580
					s += 5;
					break;
				case GF_FOG:
					//loc_10570
					s += 3;
					break;
				case GF_KEY_ITEM1:
				case GF_KEY_ITEM2:
				case GF_KEY_ITEM3:
				case GF_KEY_ITEM4:
				case GF_KEY_ITEM5:
				case GF_KEY_ITEM6:
				case GF_KEY_ITEM7:
				case GF_KEY_ITEM8:
				case GF_KEY_ITEM9:
				case GF_KEY_ITEM10:
				case GF_KEY_ITEM11:
				case GF_KEY_ITEM12:
				case GF_PUZZLE_ITEM1:
				case GF_PUZZLE_ITEM2:
				case GF_PUZZLE_ITEM3:
				case GF_PUZZLE_ITEM4:
				case GF_PUZZLE_ITEM5:
				case GF_PUZZLE_ITEM6:
				case GF_PUZZLE_ITEM7:
				case GF_PUZZLE_ITEM8:
				case GF_PUZZLE_ITEM9:
				case GF_PUZZLE_ITEM10:
				case GF_PUZZLE_ITEM11:
				case GF_PUZZLE_ITEM12:
				case GF_PICKUP_ITEM1:
				case GF_PICKUP_ITEM2:
				case GF_PICKUP_ITEM3:
				case GF_PICKUP_ITEM4:
				case GF_EXAMINE1:
				case GF_EXAMINE2:
				case GF_EXAMINE3:
				case GF_KEY_ITEM1_COMBO1:
				case GF_KEY_ITEM1_COMBO2:
				case GF_KEY_ITEM2_COMBO1:
				case GF_KEY_ITEM2_COMBO2:
				case GF_KEY_ITEM3_COMBO1:
				case GF_KEY_ITEM3_COMBO2:
				case GF_KEY_ITEM4_COMBO1:
				case GF_KEY_ITEM4_COMBO2:
				case GF_KEY_ITEM5_COMBO1:
				case GF_KEY_ITEM5_COMBO2:
				case GF_KEY_ITEM6_COMBO1:
				case GF_KEY_ITEM6_COMBO2:
				case GF_KEY_ITEM7_COMBO1:
				case GF_KEY_ITEM7_COMBO2:
				case GF_KEY_ITEM8_COMBO1:
				case GF_KEY_ITEM8_COMBO2:
				case GF_PUZZLE_ITEM1_COMBO1:
				case GF_PUZZLE_ITEM1_COMBO2:
				case GF_PUZZLE_ITEM2_COMBO1:
				case GF_PUZZLE_ITEM2_COMBO2:
				case GF_PUZZLE_ITEM3_COMBO1:
				case GF_PUZZLE_ITEM3_COMBO2:
				case GF_PUZZLE_ITEM4_COMBO1:
				case GF_PUZZLE_ITEM4_COMBO2:
				case GF_PUZZLE_ITEM5_COMBO1:
				case GF_PUZZLE_ITEM5_COMBO2:
				case GF_PUZZLE_ITEM6_COMBO1:
				case GF_PUZZLE_ITEM6_COMBO2:
				case GF_PUZZLE_ITEM7_COMBO1:
				case GF_PUZZLE_ITEM7_COMBO2:
				case GF_PUZZLE_ITEM8_COMBO1:
				case GF_PUZZLE_ITEM8_COMBO2:
				case GF_PICKUP_ITEM1_COMBO1:
				case GF_PICKUP_ITEM1_COMBO2:
				case GF_PICKUP_ITEM2_COMBO1:
				case GF_PICKUP_ITEM2_COMBO2:
				case GF_PICKUP_ITEM3_COMBO1:
				case GF_PICKUP_ITEM3_COMBO2:
				case GF_PICKUP_ITEM4_COMBO1:
				case GF_PICKUP_ITEM4_COMBO2:
				case GF_GIVE_ITEM_AT_STARTUP:///@CHECKME
				case GF_LOSE_ITEM_AT_STARTUP:///@CHECKME
				default:
					//def_10560
					s += 2;
					break;
				}

			} while (flag == 0);
		}
	}
	//loc_105EC
}

void QuickControlPhase()//10274(<), 10264(<) (F) (*) (D) (ND)
{
#if PSX_VERSION
#if DEBUG_VERSION
	ProfileRGB(255, 255, 255);
#endif
	OldSP = SetSp(0x1F8003E0);
#endif

#if PSX_VERSION || PSXPC_VERSION
	gfStatus = ControlPhase(nframes, gfGameMode == 2);
#else
	gfStatus = ControlPhase(nframes, 0);
#endif

#if PSX_VERSION
	SetSp(OldSP);
#if DEBUG_VERSION
	ProfileRGB(0, 0, 0);
#endif
#endif
}

#if PC_VERSION
bool initial_fmv_played = false;

void DoFrontEndOneShotStuff()
{
	if (!initial_fmv_played)
	{
		PlayFmvNow(0);
		PlayFmvNow(1);
		initial_fmv_played = true;
	}
}
#endif

#if defined(__EMSCRIPTEN__)
void DoTitleGameLoop(void* arg)
{
	int i;
	unsigned char Name = ((unsigned char*)arg)[0];
	printf("Name %d\n", Name);
	if (gfStatus == 0)
	{
		GPU_BeginScene();

		if (bDoCredits)
		{
#if !PSXPC_VERSION && RELOC
			if (!((INTFUNCVOID*)RelocPtr[MOD_TITSEQ][1])())
			{
				bDoCredits = 0;
				SetFadeClip(0, 2);
			}
#endif
			//loc_10800
			if (bDoCredits)
				goto loc_10890;

		}
		printf("GLOBAL_PLAYING_CUTSEQ: %d\n", GLOBAL_playing_cutseq);
		//loc_10810
		if (GLOBAL_playing_cutseq == 0)
		{
			if (ScreenFading == 0 && cutseq_num == 0)
			{
#if DEBUG_VERSION
				if ((RawPad & (IN_R2 | 1)) == (IN_R2 | 1))
				{
					dels_cutseq_selector_flag = 1;
				}
#endif
				//loc_10868
				CreditsDone = 1;
#if RELOC
				gfStatus = ((INTFUNCINT*)RelocPtr[MOD_TITSEQ][0])(Name);
#else
				gfStatus = TitleOptions(Name);
				printf("EMSCRIPTEN TITLE OPTS! %d\n", gfStatus);
#endif
				//Early out
				if (gfStatus != 0)
					goto breakLoop;

			}//loc_10890

		loc_10890:
			if (GLOBAL_playing_cutseq == 0)
				goto loc_108EC;
		}
		//loc_108A4
		if (bDoCredits == 0 && CreditsDone)
		{
			PrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 20, 1, &gfStringWad[gfStringOffset[STR_DEMO_MODE]], FF_CENTER);
		}
		//loc_108EC
	loc_108EC:
		nframes = DrawPhaseGame();

		if (!PadConnected)
		{

			PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) + 8, 3, &gfStringWad[gfStringOffset[STR_CONTROLLER_REMOVED]], (FF_BLINK | FF_CENTER));
		}
		//loc_1092C
		handle_cutseq_triggering(Name);

		if (gfGameMode == 2)
		{
			if ((dbinput & 0x100))
				goto loc_10970;

			if (GLOBAL_enterinventory == -1)
				goto loc_109A8;

			//loc_10970
		loc_10970:
			if (cutseq_trig == 0 && lara_item->hit_points > 0)
			{
				S_CallInventory2();
			}//loc_109A8
		}//loc_109A8
	loc_109A8:
		QuickControlPhase();

		if (gfGameMode == 2 && ScreenFadedOut != 0)
		{
			InitialiseItemArray(256);

			for (i = 0; i < number_rooms; i++)
			{
				room[i].item_number = -1;
			}
			//loc_10A10
			gfGameMode = 1;

		}//loc_10A14
	}
	else
	{
	breakLoop:
		emscripten_cancel_main_loop();
		printf("Cancelling main loop!\n");
	}
}
#endif

void DoTitle(unsigned char Name, unsigned char Audio)//10604(<), 105C4(<) (F) (*) (D) (ND)
{
/*#if PC_VERSION
	S_Warn("DoTitle PC");
	gfCurrentLevel = LVL5_STREETS_OF_ROME;
	DoLevel(LVL5_STREETS_OF_ROME, Audio);
	return;
#endif*/

	int i;

	CreditsDone = 0;

#if PC_VERSION
	DoFrontEndOneShotStuff();
#endif

	CanLoad = 0;

#if PC_VERSION
	SetFade(255, 0);
#else
	if (Gameflow->LoadSaveEnabled)
	{
		mcOpen(1);
	}
#endif

	//loc_10648
	num_fmvs = 0;
	fmv_to_play[1] = 0;
	fmv_to_play[0] = 0;

#if PSX_VERSION || PSXPC_VERSION
	XAMasterVolume = savegame.VolumeCD;
#endif

	S_MemSet((char*)&savegame.Level, 0, sizeof(struct STATS));
	S_MemSet((char*)&savegame.Game, 0, sizeof(struct STATS));

	S_LoadLevelFile(Name);
	
	GLOBAL_lastinvitem = -1;
	dels_cutseq_player = 0;

	InitSpotCamSequences();
	
	title_controls_locked_out = 0;

#if PC_VERSION
	InitialiseFXArray(1);
	InitialiseLOTarray(1);

	// TODO fog

	ClearFXFogBulbs();
#endif

	InitialisePickUpDisplay();

#if PSX_VERSION || PSXPC_VERSION
	phd_InitWindow(90);
#endif

#if PC_VERSION
	S_InitialiseScreen();
#endif
	
#if !PSXPC_TEST//Im sure this causes an infinite loop for PSXPC_N, disable for now.
	SOUND_Stop();
#endif
	IsAtmospherePlaying = 0;
	
	S_SetReverbType(1);

	InitialiseCamera();

#if PC_VERSION
	dword_51CE58 = 1;
#endif

	if (!bDoCredits)
	{
		trigger_title_spotcam(1);
		ScreenFadedOut = 0;
		ScreenFade = 0;
		dScreenFade = 0;
		ScreenFadeBack = 0;
		ScreenFadeSpeed = 8;
		ScreenFading = 0;
	}
	else
	{
		//loc_10730
		cutseq_num = CUT_SPECIAL1;
		SetFadeClip(32, 1);
		ScreenFadedOut = 1;
		ScreenFade = 255;
		dScreenFade = 255;
#if !BETA_VERSION
		S_CDPlay(CDA_XA14_ECREDITS, 1);
#endif
	}

	//loc_10764
	bUseSpotCam = 1;
	lara_item->mesh_bits = 0;
	gfGameMode = 1;

#if DEBUG_VERSION
	show_game_malloc_totals();
#endif

	gfLevelComplete = 0;
	nframes = 2;
	gfStatus = ControlPhase(2, 0);
	JustLoaded = 0;

#if PC_VERSION
	while (gfStatus == 0)
	{
		GPU_BeginScene();
		SkyDrawPhase();
		gfStatus = TitleOptions();
		if (gfStatus != 0)
			break;
		handle_cutseq_triggering(Name);
		nframes = DrawPhaseGame();
		gfStatus = ControlPhase(nframes, 0);
		DoSpecialFeaturesServer();
	}
#else
#if !defined(__EMSCRIPTEN__)
	if (gfStatus == 0)
	{
		//loc_107BC
		while (gfStatus == 0)
		{
			GPU_BeginScene();

			if (bDoCredits)
			{
#if !PSXPC_VERSION && RELOC
				if (!((INTFUNCVOID*)RelocPtr[MOD_TITSEQ][1])())
				{
					bDoCredits = 0;
					SetFadeClip(0, 2);
				}
#endif
				//loc_10800
				if (bDoCredits)
					goto loc_10890;
					
			}
			printf("GLOBAL_PLAYING_CUTSEQ: %d\n", GLOBAL_playing_cutseq);
			//loc_10810
			if (GLOBAL_playing_cutseq == 0)
			{
				if (ScreenFading == 0 && cutseq_num == 0)
				{
#if DEBUG_VERSION
					if ((RawPad & (IN_R2 | 1)) == (IN_R2 | 1))
					{
						dels_cutseq_selector_flag = 1;
					}
#endif
					//loc_10868
					CreditsDone = 1;
#if RELOC
					gfStatus = ((INTFUNCINT*)RelocPtr[MOD_TITSEQ][0])(Name);
#else
					gfStatus = TitleOptions(Name);
#endif
					//Early out
					if (gfStatus != 0)
						break;

				}//loc_10890

			loc_10890:
				if (GLOBAL_playing_cutseq == 0)
					goto loc_108EC;
			}
			//loc_108A4
			if (bDoCredits == 0 && CreditsDone)
			{
				PrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 20, 1, &gfStringWad[gfStringOffset[STR_DEMO_MODE]], FF_CENTER);
			}
			//loc_108EC
		loc_108EC:
			nframes = DrawPhaseGame();

			if (!PadConnected)
			{
				
				PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) + 8, 3, &gfStringWad[gfStringOffset[STR_CONTROLLER_REMOVED]], (FF_BLINK | FF_CENTER));
			}
			//loc_1092C
			handle_cutseq_triggering(Name);

			if (gfGameMode == 2)
			{
				if ((dbinput & 0x100))
					goto loc_10970;

				if (GLOBAL_enterinventory == -1)
					goto loc_109A8;

				//loc_10970
			loc_10970:
				if (cutseq_trig == 0 && lara_item->hit_points > 0)
				{
					S_CallInventory2();
				}//loc_109A8
			}//loc_109A8
		loc_109A8:
			QuickControlPhase();

			if (gfGameMode == 2 && ScreenFadedOut != 0)
			{
				InitialiseItemArray(256);

				for (i = 0; i < number_rooms; i++)
				{
					room[i].item_number = -1;
				}
				//loc_10A10
				gfGameMode = 1;

			}//loc_10A14
		}
	}
#else
	printf("Name %d\n", Name);
	emscripten_set_main_loop_arg(DoTitleGameLoop, &Name, 0, 1);
#endif

	//loc_10A24
	Motors[1] = 0;
	Motors[0] = 0;

	if (Gameflow->LoadSaveEnabled)
	{
		mcClose();
	}


	//loc_10A58
	do
	{
#if PSXPC_TEST
		//Because emulator doesn't call this every Vblank
		VSync(0);
#endif
		XAReqVolume = 0;
		
	} while (XAVolume != 0);

#endif

	NoInput = 0;
	S_SoundStopAllSamples(); //Bug, infinite loop on PSX?
	S_CDStop();
	bUseSpotCam = 0;
	bDisableLaraControl = 0;

#if PSX_VERSION || PSXPC_VERSION
	input = 0;
#elif PC_VERSION
	if (gfLevelComplete == 1 && gfStatus != 2)
		PlayFmvNow(2);

	if (gfStatus != 4)
		input = 0;
#endif

}

void DoLevel(unsigned char Name, unsigned char Audio)//10ABC(<) 10A84(<) (F)
{
	char *d;

#if !BETA_VERSION
	int fmvStatus;
#endif
#if PSXENGINE
	if (gfGameMode == 4)
	{
		if (FromTitle == 1)
		{
			d = (char*) &GadwPolygonBuffers[49188];
			memcpy((void*) d, &MGSaveGamePtr[0], 8192);
			MGSaveGamePtr = d;
		}
	}

	//loc_10B24
	FromTitle = 0;


	XAMasterVolume = savegame.VolumeCD;
#endif

#if PC_VERSION
	SetFade(255, 0);
#endif

	if (gfGameMode == 4)
	{
		memset(&savegame.Level, 0, sizeof(struct STATS));
	}

	//loc_10B58
	S_LoadLevelFile(Name);

#if PC_VERSION
	//SetFogColor(...); todo

	InitialiseFXArray(TRUE);
	InitialiseLOTarray(TRUE);

	ClearFXFogBulbs();

	// todo
#endif

	InitSpotCamSequences();
	InitialisePickUpDisplay();

#if PC_VERSION
	S_InitialiseScreen();
#endif

#if PSX_VERSION || PSXPC_VERSION
	phd_InitWindow(90);
#endif
	SOUND_Stop();
	bDisableLaraControl = 0;

	if (gfGameMode == 4)
	{
		sgRestoreGame();
		gfRequiredStartPos = 0;
		gfInitialiseGame = 0;

#if PC_VERSION
		if (IsVolumetric())
		{
			//SetFogColor(...); todo
		}
#endif
	}
	else
	{
		//loc_10BAC
		gfRequiredStartPos = 0;

		if (gfInitialiseGame != 0)
		{
			GameTimer = 0;
			gfRequiredStartPos = 0;
			gfInitialiseGame = 0;
			FmvSceneTriggered = 0;
			InitCutPlayed();
		}

		//loc_10BD8
		CurrentAtmosphere = Audio;
		savegame.Level.Timer = 0;

		if (gfCurrentLevel == LVL5_STREETS_OF_ROME)
		{
			savegame.TLCount = 0;
		}
	}

	//loc_10BF8
	S_CDPlay(CurrentAtmosphere, 1);

	IsAtmospherePlaying = TRUE;
	ScreenFadedOut = FALSE;
	ScreenFading = FALSE;
	ScreenFadeBack = FALSE;
	dScreenFade = 255;
	ScreenFade = 255;

	if (dels_cutseq_player != 0)
	{
		gfCutNumber = 0;
	}//loc_10C50

	if (gfCutNumber == 0 || CheckCutPlayed(gfCutNumber) != 0)
	{
		//loc_10C7C
		if (dels_cutseq_player != 0)
		{
			cutseq_num = dels_cutseq_player;
			gfCutNumber = 0;
			ScreenFadedOut = 1;
		}
		else
		{
			cutseq_num = 0;
			gfCutNumber = 0;
			SetScreenFadeIn(16);
		}
	}
	else
	{
		//loc_10C90
		cutseq_num = gfCutNumber;
		gfCutNumber = 0;
		ScreenFadedOut = 1;
	}
	//loc_10CD8
	InitialiseCamera();
	bUseSpotCam = 0;

#if DEBUG_VERSION
	show_game_malloc_totals();
#endif

	gfGameMode = 0;
	gfLevelComplete = 0;
	nframes = 2;
	framecount = 0;

	gfStatus = ControlPhase(2, 0);

	dbinput = IN_NONE;
	JustLoaded = 0;

	//loc_10D30
	while (gfStatus == 0)
	{
		GPU_BeginScene();

		if (gfLegendTime != 0 && DestFadeScreenHeight == 0 && FadeScreenHeight == 0 && cutseq_num == 0)
		{
			PrintString(
#if PSX_VERSION || PSXPC_TEST || PSXPC_VERSION || SAT_VERSION
				0x100, 0xE8,
#else
				phd_winwidth / 2, phd_winymax - font_height,
#endif
				2, &gfStringWad[gfStringOffset[gfLegend]], FF_CENTER);
			gfLegendTime--;
		}

		//loc_10DC4
		nframes = DrawPhaseGame();
		handle_cutseq_triggering(Name);

		if (DEL_playingamefmv != 0)
		{
			DEL_playingamefmv = 0;
		}

		//loc_10DEC
		if (gfLevelComplete == 0)
		{
			if ((dbinput & IN_OPTION) || GLOBAL_enterinventory != -1)
			{
				//loc_10E28
 				if (cutseq_trig == 0 && lara_item->hit_points > 0 && ScreenFading == 0)
				{
					if (S_CallInventory2())
					{
						gfStatus = 2;
						break;
					}
				}
			}
			//loc_10E7C
			QuickControlPhase();
		}
		else
		{
			gfStatus = 3;
			break;
		}
	}

#if PSXENGINE
	//loc_10E94
	XAReqVolume = 0;
	Motors[1] = 0;
	Motors[0] = 0;


	if (XAVolume != 0)
	{
		//loc_10EBC
		do
		{
			XAReqVolume = 0;
		} while (XAVolume == 0);
	}


	//loc_10ED8
	reset_count = 0;
#endif

	S_SoundStopAllSamples();
	S_CDStop();

#if !BETA_VERSION

	if (gfStatus == 3)
	{
		fmvStatus = 0;

		if (fmv_to_play[0] & 0x80)
		{
			if ((fmv_to_play[0] & 0x7F) == 9 && gfLevelComplete != 10)
			{
				fmv_to_play[0] = 0;
			}
			
			//loc_10EF8
			if ((fmv_to_play[0] & 0x7F) == 8 && gfLevelComplete != 22)
			{
				fmv_to_play[0] = 0;
			}
		}
#if PSXENGINE	
		//loc_10F20
		if (fmv_to_play[0] != 0)
		{
			fmvStatus = S_PlayFMV(fmv_to_play[0] & 0x7F, 1);
		}//loc_10F3C

		if (fmvStatus != 2 && fmv_to_play[1] != 0)
		{
			S_PlayFMV(fmv_to_play[1] & 0x7F, 1);
		}
#endif
	}

	//loc_10F64
	num_fmvs = 0;
	fmv_to_play[1] = 0;
	fmv_to_play[0] = 0;
#endif

	lara.examine3 = 0;
	lara.examine2 = 0;
	lara.examine1 = 0;

	if (gfStatus == 3 && gfCurrentLevel == LVL5_RED_ALERT)
	{
		gfStatus = 1;
		bDoCredits = 1;
		scroll_pos = 0;
	}

	//loc_10F30
	input = 0;
	reset_flag = 0;
}

#if PC_VERSION
void SpecialFeaturesDisplayScreens(int num)
{
	UNIMPLEMENTED();
}

void DoSpecialFeaturesServer()// (F)
{
	switch(special_features_num)
	{
	case 0:
		SpecialFeaturesDisplayScreens(0);
		break;
	case 1:
		SpecialFeaturesDisplayScreens(1);
		break;
	case 2:
		SpecialFeaturesDisplayScreens(2);
		break;
	case 3:
		SpecialFeaturesDisplayScreens(3);
		break;
	}

	special_features_num = -1;
}
#endif
<MSG> Fix PSX ver.

<DFF> @@ -494,15 +494,14 @@ void QuickControlPhase()//10274(<), 10264(<) (F)
 #if DEBUG_VERSION
 	ProfileRGB(255, 255, 255);
 #endif
-
 	OldSP = SetSp(0x1F8003E0);
 #endif
 
 	gfStatus = ControlPhase(nframes, (gfGameMode ^ 2) < 1 ? 1 : 0);
 
 #if PSX_VERSION
-#if DEBUG_VERSION
 	SetSp(OldSP);
+#if DEBUG_VERSION
 	ProfileRGB(0, 0, 0);
 #endif
 #endif

{'commit': 'diff --git a/GAME/GAMEFLOW.C b/GAME/GAMEFLOW.C\nindex 03ff9345..1626502d 100644\n--- a/GAME/GAMEFLOW.C\n+++ b/GAME/GAMEFLOW.C\n@@ -494,15 +494,14 @@ void QuickControlPhase()//10274(<), 10264(<) (F)\n #if DEBUG_VERSION\n \tProfileRGB(255, 255, 255);\n #endif\n-\n \tOldSP = SetSp(0x1F8003E0);\n #endif\n \n \tgfStatus = ControlPhase(nframes, (gfGameMode ^ 2) < 1 ? 1 : 0);\n \n #if PSX_VERSION\n-#if DEBUG_VERSION\n \tSetSp(OldSP);\n+#if DEBUG_VERSION\n \tProfileRGB(0, 0, 0);\n #endif\n #endif\n', 'commit_subject': 'Fix PSX ver.', 'repo_name': 'TOMB5/TOMB5', 'committer': {'name': 'Gh0stBlade', 'email': '19ffcc48b5297ad4998e7ea4f40eaa34eefb03dd@users.noreply.github.com', 'time_sec': '1520286205', 'tz_offset': '0', 'date': {'seconds': '1520286205'}}, 'commit_tree': '963b7445abe39b831adef163972a57a6729f261d', 'commit_message': 'Fix PSX ver.\n', 'language_name': 'Java', 'license': 'mit', 'hunks': '@@ -494,15 +494,14 @@ void QuickControlPhase()//10274(<), 10264(<) (F)\n #if DEBUG_VERSION\n \tProfileRGB(255, 255, 255);\n #endif\n-\n \tOldSP = SetSp(0x1F8003E0);\n #endif\n \n \tgfStatus = ControlPhase(nframes, (gfGameMode ^ 2) < 1 ? 1 : 0);\n \n #if PSX_VERSION\n-#if DEBUG_VERSION\n \tSetSp(OldSP);\n+#if DEBUG_VERSION\n \tProfileRGB(0, 0, 0);\n #endif\n #endif\n', 'addition_count': 1, 'deletion_count': 2, 'src_file': 'a/GAME/GAMEFLOW.C', 'tgt_file': 'b/GAME/GAMEFLOW.C', 'file_extension': '.C', 'before_file': '#include "GAMEFLOW.H"\n\n#if defined(__EMSCRIPTEN__)\n#include <emscripten.h>\n#endif\n\n#if !PC_VERSION\n#include "3D_GEN.H"\n#include "TITSEQ.H"\n#include "TYPEDEFS.H"\n#endif\n#include "CDTRACKS.H"\n#include "CODEWAD.H"\n#include "CONTROL.H"\n#include "DELTAPAK.H"\n#include "DRAW.H"\n\n#include "FILE.H"\n#if PSX_VERSION || PSXPC_VERSION || PSXPC_TEST\n#include "CD.H"\n#include "MOVIE.H"\n#include "MEMCARD.H"\n#include "SPUSOUND.H"\n#include "MISC.H"\n#include "SFX.H"\n#include "GPU.H"\n#include "DRAWPHAS.H"\n#include "ROOMLOAD.H"\n#include "PROFILE.H"\n#include <LIBAPI.H>\n#include <LIBGTE.H>\n#elif SAT_VERSION\n#include "CD.H"\n#include "MOVIE.H"\n#include "MEMCARD.H"\n#include "SPUSOUND.H"\n#include "MISC.H"\n#include "SFX.H"\n#include "GPU.H"\n#include "DRAWPHAS.H"\n#include "ROOMLOAD.H"\n#endif\n\n#if PC_VERSION\n#include "SPECIFIC.H"\n#include "DRAWPRIMITIVE.H"\n#include "DISPLAY.H"\n#include "GAME.H"\n#include "INIT.H"\n#endif\n\n#include "HEALTH.H"\n#include "ITEMS.H"\n#include "LARA.H"\n#include "MALLOC.H"\n#include "NEWINV2.H"\n#include INPUT_H\n\n#include "SAVEGAME.H"\n#include "SOUND.H"\n\n#include "SPECIFIC.H"\n#include "SPOTCAM.H"\n#include "TOMB4FX.H"\n\n#include <assert.h>\n#if PSXPC_VERSION || PSXPC_TEST\n\t#include <stdint.h>\n#if DEBUG_VERSION\n#include "PROFILE.H"\n#endif\n#endif\n\n#if (PSX_VERSION || SAT_VERSION) && !PSXPC_TEST\ntypedef unsigned int uintptr_t;\n#endif\n\n#if PSX_VERSION || SAT_VERSION\n#include "FXTRIG.H"\n#include "TEXT_S.H"\n#endif\n\n#if PSXPC_TEST\n#include <LIBETC.H>\n#endif\n\n#if !SAT_VERSION\n#include <string.h>\n#endif\n#include "LOT.H"\n#include "TEXT.H"\n\n#define GF_SCRIPT_FILENAME "SCRIPT.DAT"\n\nunsigned char gfGameMode = 1;\nunsigned char gfNumMips;\nint scroll_pos;\nchar DEL_playingamefmv = 0;\nchar num_fmvs = 0;\nchar fmv_to_play[2];\nunsigned short dels_cutseq_selector_flag;\nunsigned short dels_cutseq_player = 0;\nchar Chris_Menu;\nunsigned char gfLegendTime = 0;\nunsigned char bDoCredits = 0;\nstatic unsigned char gfCutNumber = 0;\nunsigned char gfInitialiseGame = 1;\nlong nframes = 1;\nunsigned char gfNumPickups = 0;\nunsigned char gfNumTakeaways = 0;\nchar CanLoad;\nstruct GAMEFLOW* Gameflow;\nunsigned short* gfStringOffset = 0;\nchar* gfStringWad;\nunsigned short* gfFilenameOffset;\nchar* gfFilenameWad;\nunsigned char gfCurrentLevel;\nunsigned char gfLevelComplete;\nunsigned char gfRequiredStartPos;\nunsigned short gfLevelFlags;\nunsigned char gfLevelNames[40];\nunsigned char gfResidentCut[4];\nunsigned char gfResetHubDest;\nchar gfUVRotate;\nchar gfLayer1Vel;\nchar gfLayer2Vel;\nCVECTOR gfLayer1Col;\nCVECTOR gfLayer2Col;\nunsigned long GameTimer;\nstruct PHD_VECTOR gfLensFlare;\nCVECTOR gfLensFlareColour;\nunsigned char gfMirrorRoom;\nunsigned char gfMips[8];\nchar title_controls_locked_out;\nlong gfScriptLen = 0;\nunsigned char gfLegend;\nunsigned char gfWadNames[40];\nstatic unsigned short* gfScriptOffset;\nstatic unsigned char* gfScriptWad;\nstatic char* gfExtensions;\nstatic int gfStatus;\nstatic unsigned long OldSP;\nunsigned char gfPickups[16];\nunsigned char gfTakeaways[16];\nint special_features_num = -1;\n#if PC_VERSION\nchar* gfScriptFile;\n\nconst char* screens[5] =\n{\n\t"SCREENS\\\\STORY1.STR", "SCREENS\\\\NXG.STR", "SCREENS\\\\STORY2.STR", "SCREENS\\\\GALLERY.STR", "SCREENS\\\\SCREENS.STR"\n};\n#endif\n\nvoid DoGameflow()//10F5C(<), 10FD8(<)\n{\n\tunsigned char* gf; // $a3\n\tunsigned char n; // $a1\n\n#if PC_VERSION\n\tdo_boot_screen(Gameflow->Language);\n#else\n\tLoadGameflow();\n#endif\n\n#if DISC_VERSION && PSX_VERSION && PLAY_FMVS\n\tS_PlayFMV(FMV_COPYRIGHT_INTRO, 0);\n\tS_PlayFMV(FMV_GAME_INTRO, 0);\n#endif\n\n\tnum_fmvs = 0;\n\tfmv_to_play[1] = 0;\n\tfmv_to_play[0] = 0;\n\n\tgfCurrentLevel = Gameflow->TitleEnabled == 0;\n\tgf = &gfScriptWad[gfScriptOffset[gfCurrentLevel]];\n\n\twhile (1)\n\t{\n\t\tswitch (n = *gf++)\n\t\t{\n\t\tcase GF_FMV:\n#if PLAY_FMVS\n\t\t\tfmv_to_play[num_fmvs++] = *gf++;\n#else\n\t\t\tgf++;\n#endif\n\t\t\tbreak;\n\t\tcase GF_LEVEL:\n\n\t\t\tgfLevelFlags = gf[1] | (gf[2] << 8);\n\n\t\t\tif ((gfLevelFlags & 0x8000))\n\t\t\t{\n\t\t\t\tgfStatus = 999;\n\t\t\t\tgfCurrentLevel++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t//loc_112E4\n\t\t\t\tDoLevel(gf[3], gf[4]);\n\t\t\t}\n\t\t\t//loc_112F8\n\n\t\t\tgfLegendTime = 0;\n\t\t\tLaserSight = 0;\n\t\t\tBinocularRange = 0;\n\t\t\tgfResidentCut[0] = 0;///@CHECK in asm it\'s *(int*)&gfResidentCut[0] = 0, check if optimised to this\n\t\t\tgfResidentCut[1] = 0;\n\t\t\tgfResidentCut[2] = 0;\n\t\t\tgfResidentCut[3] = 0;\n\t\t\tgfUVRotate = 0;\n\t\t\tgfNumMips = 0;\n\t\t\tgfNumPickups = 0;\n\t\t\tgfMirrorRoom = 255;\n\n\t\t\tif (gfStatus != 2)\n\t\t\t{\n\t\t\t\tif (gfStatus < 3)\n\t\t\t\t{\n\t\t\t\t\tif (gfStatus == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\t//loc_11364\n\t\t\t\t\t\tgfInitialiseGame = 1;\n\t\t\t\t\t\tgfCurrentLevel = Gameflow->TitleEnabled == 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t//loc_11348\n\t\t\t\t\tif (gfStatus == 3)\n\t\t\t\t\t{\n\t\t\t\t\t\t//loc_1138C\n\t\t\t\t\t\tif (!Gameflow->DemoDisc && Gameflow->nLevels != 2 && gfLevelComplete <= Gameflow->nLevels)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t//loc_11460\n\t\t\t\t\t\t\tgfCurrentLevel = gfLevelComplete;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//loc_113CC\n\t\t\t\t\t\tgfCurrentLevel = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse if (gfStatus == 4)\n\t\t\t\t\t{\n\t\t\t\t\t\t//loc_115DC\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t//loc_1146C\n\t\t\t\tgfGameMode = 4;\n\t\t\t\tgfCurrentLevel = savegame.CurrentLevel;\n\t\t\t}\n\t\t\t//loc_11480\n\t\t\tgf = &gfScriptWad[gfScriptOffset[gfCurrentLevel]];\n\t\t\tbreak;\n\t\tcase GF_TITLE_LEVEL:\n\n\t\t\tgfLevelFlags = gf[0] | (gf[1] << 8);\n\t\t\tDoTitle(gf[2], gf[3]);\n\n\t\t\tgfMirrorRoom = 255;\n\t\t\tgfResidentCut[0] = 0;///@CHECK in asm it\'s *(int*)&gfResidentCut[0] = 0, check if optimised to this\n\t\t\tgfResidentCut[1] = 0;\n\t\t\tgfResidentCut[2] = 0;\n\t\t\tgfResidentCut[3] = 0;\n\t\t\tgfUVRotate = 0;\n\t\t\tgfNumMips = 0;\n\t\t\tgfNumPickups = 0;\n\n\t\t\tif (gfStatus == 3)\n\t\t\t{\n\t\t\t\t//loc_11450\n\t\t\t\tgfGameMode = 0;\n\t\t\t\tgfInitialiseGame = 1;\n\t\t\t\tgfCurrentLevel = gfLevelComplete;\n\t\t\t}\n\t\t\telse if (gfStatus < 4)\n\t\t\t{\n\t\t\t\tif (gfStatus == 2)\n\t\t\t\t{\n\t\t\t\t\t//loc_11470\n\t\t\t\t\tgfGameMode = 4;\n\t\t\t\t\tgfCurrentLevel = savegame.CurrentLevel;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (gfStatus == 4)\n\t\t\t{\n\t\t\t\t//loc_115DC\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t//loc_11480\n\t\t\tgf = &gfScriptWad[gfScriptOffset[gfCurrentLevel]];\n\t\t\tbreak;\n\t\tcase GF_LEVEL_DATA_END:\n\t\t\tcontinue;\n\t\t\tbreak;\n\t\tcase GF_CUT:\n\t\t\tgfCutNumber = *gf++;\n\t\t\tbreak;\n\t\tcase GF_RESIDENTCUT1:\n\t\t\tgfResidentCut[0] = *gf++;\n\t\t\tbreak;\n\t\tcase GF_RESIDENTCUT2:\n\t\t\tgfResidentCut[1] = *gf++;\n\t\t\tbreak;\n\t\tcase GF_RESIDENTCUT3:\n\t\t\tgfResidentCut[2] = *gf++;\n\t\t\tbreak;\n\t\tcase GF_RESIDENTCUT4:\n\t\t\tgfResidentCut[3] = *gf++;\n\t\t\tbreak;\n\t\tcase GF_LAYER1:\n\t\t\tLightningRGB[0] = *gf;\n\t\t\tLightningRGBs[0] = *gf;\n\t\t\tgfLayer1Col.r = *gf++;\n\n\t\t\tLightningRGB[1] = *gf;\n\t\t\tLightningRGBs[1] = *gf;\n\t\t\tgfLayer1Col.g = *gf++;\n\n\t\t\tgfLayer1Col.cd = 44;\n\t\t\tLightningRGB[2] = *gf;\n\t\t\tLightningRGBs[2] = *gf;\n\t\t\tgfLayer1Col.b = *gf++;\n\n\t\t\tgfLayer1Vel = *gf++;\n\t\t\tbreak;\n\t\tcase GF_LAYER2:\n\t\t\tLightningRGB[0] = *gf;\n\t\t\tLightningRGBs[0] = *gf;\n\t\t\tgfLayer2Col.r = *gf++;\n\n\t\t\tLightningRGB[1] = *gf;\n\t\t\tLightningRGBs[1] = *gf;\n\t\t\tgfLayer2Col.g = *gf++;\n\n\t\t\tgfLayer2Col.cd = 46;\n\t\t\tLightningRGB[2] = *gf;\n\t\t\tLightningRGBs[2] = *gf;\n\t\t\tgfLayer2Col.b = *gf++;\n\n\t\t\tgfLayer2Vel = *gf++;\n\t\t\tbreak;\n\t\tcase GF_UV_ROTATE:\n\t\t\tgfUVRotate = *gf++;\n\t\t\tbreak;\n\t\tcase GF_LEGEND:\n\t\t\tgfLegend = *gf++;\n\t\t\tif (gfGameMode != 4)\n\t\t\t{\n\t\t\t\tgfLegendTime = 150;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase GF_LENS_FLARE:\n\n\t\t\tgfLensFlare.x = ((gf[1] << 8) | gf[0]) << 8;\n\t\t\tgfLensFlare.y = ((gf[2] | (gf[3] << 8)) << 16) >> 8;\n\t\t\tgfLensFlare.z = ((gf[5] << 8) | gf[4]) << 8;\n\n\t\t\tgfLensFlareColour.r = gf[6];\n\t\t\tgfLensFlareColour.g = gf[7];\n\t\t\tgfLensFlareColour.b = gf[8];\n\n\t\t\tgf += 9;\n\t\t\tbreak;\n\t\tcase GF_MIRROR:\n\t\t\tgfMirrorRoom = *gf;\n\t\t\tgfMirrorZPlane = (gf[4] << 24) | (gf[3] << 16) | (gf[2] << 8) | gf[1];\n\t\t\tgf += 5;\n\t\t\tbreak;\n\t\tcase GF_FOG:\n\t\t\tgf += 3;\n\t\t\tbreak;\n\t\tcase GF_ANIMATING_MIP:\n\t\t\t//loc_111DC:\n\t\t\tgfMips[gfNumMips++] = *gf++;\n\t\t\tbreak;\n\t\tcase GF_RESET_HUB:\n\t\t\t//loc_11290:\n\t\t\tgfResetHubDest = *gf++;\n\t\t\tbreak;\n\t\tcase GF_KEY_ITEM1:\n\t\tcase GF_KEY_ITEM2:\n\t\tcase GF_KEY_ITEM3:\n\t\tcase GF_KEY_ITEM4:\n\t\tcase GF_KEY_ITEM5:\n\t\tcase GF_KEY_ITEM6:\n\t\tcase GF_KEY_ITEM7:\n\t\tcase GF_KEY_ITEM8:\n\t\tcase GF_KEY_ITEM9:\n\t\tcase GF_KEY_ITEM10:\n\t\tcase GF_KEY_ITEM11:\n\t\tcase GF_KEY_ITEM12:\n\t\tcase GF_PUZZLE_ITEM1:\n\t\tcase GF_PUZZLE_ITEM2:\n\t\tcase GF_PUZZLE_ITEM3:\n\t\tcase GF_PUZZLE_ITEM4:\n\t\tcase GF_PUZZLE_ITEM5:\n\t\tcase GF_PUZZLE_ITEM6:\n\t\tcase GF_PUZZLE_ITEM7:\n\t\tcase GF_PUZZLE_ITEM8:\n\t\tcase GF_PUZZLE_ITEM9:\n\t\tcase GF_PUZZLE_ITEM10:\n\t\tcase GF_PUZZLE_ITEM11:\n\t\tcase GF_PUZZLE_ITEM12:\n\t\tcase GF_PICKUP_ITEM1:\n\t\tcase GF_PICKUP_ITEM2:\n\t\tcase GF_PICKUP_ITEM3:\n\t\tcase GF_PICKUP_ITEM4:\n\t\tcase GF_EXAMINE1:\n\t\tcase GF_EXAMINE2:\n\t\tcase GF_EXAMINE3:\n\t\tcase GF_KEY_ITEM1_COMBO1:\n\t\tcase GF_KEY_ITEM1_COMBO2:\n\t\tcase GF_KEY_ITEM2_COMBO1:\n\t\tcase GF_KEY_ITEM2_COMBO2:\n\t\tcase GF_KEY_ITEM3_COMBO1:\n\t\tcase GF_KEY_ITEM3_COMBO2:\n\t\tcase GF_KEY_ITEM4_COMBO1:\n\t\tcase GF_KEY_ITEM4_COMBO2:\n\t\tcase GF_KEY_ITEM5_COMBO1:\n\t\tcase GF_KEY_ITEM5_COMBO2:\n\t\tcase GF_KEY_ITEM6_COMBO1:\n\t\tcase GF_KEY_ITEM6_COMBO2:\n\t\tcase GF_KEY_ITEM7_COMBO1:\n\t\tcase GF_KEY_ITEM7_COMBO2:\n\t\tcase GF_KEY_ITEM8_COMBO1:\n\t\tcase GF_KEY_ITEM8_COMBO2:\n\t\tcase GF_PUZZLE_ITEM1_COMBO1:\n\t\tcase GF_PUZZLE_ITEM1_COMBO2:\n\t\tcase GF_PUZZLE_ITEM2_COMBO1:\n\t\tcase GF_PUZZLE_ITEM2_COMBO2:\n\t\tcase GF_PUZZLE_ITEM3_COMBO1:\n\t\tcase GF_PUZZLE_ITEM3_COMBO2:\n\t\tcase GF_PUZZLE_ITEM4_COMBO1:\n\t\tcase GF_PUZZLE_ITEM4_COMBO2:\n\t\tcase GF_PUZZLE_ITEM5_COMBO1:\n\t\tcase GF_PUZZLE_ITEM5_COMBO2:\n\t\tcase GF_PUZZLE_ITEM6_COMBO1:\n\t\tcase GF_PUZZLE_ITEM6_COMBO2:\n\t\tcase GF_PUZZLE_ITEM7_COMBO1:\n\t\tcase GF_PUZZLE_ITEM7_COMBO2:\n\t\tcase GF_PUZZLE_ITEM8_COMBO1:\n\t\tcase GF_PUZZLE_ITEM8_COMBO2:\n\t\tcase GF_PICKUP_ITEM1_COMBO1:\n\t\tcase GF_PICKUP_ITEM1_COMBO2:\n\t\tcase GF_PICKUP_ITEM2_COMBO1:\n\t\tcase GF_PICKUP_ITEM2_COMBO2:\n\t\tcase GF_PICKUP_ITEM3_COMBO1:\n\t\tcase GF_PICKUP_ITEM3_COMBO2:\n\t\tcase GF_PICKUP_ITEM4_COMBO1:\n\t\tcase GF_PICKUP_ITEM4_COMBO2:\n\t\tdefault:\n\t\t\t//def_10FE0\n\t\t\tif (((n + 0x6E) & 0xFF) < 8)\n\t\t\t{\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].objname = gf[0] | (gf[1] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].yoff = gf[2] | (gf[3] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].scale1 = gf[4] | (gf[5] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].yrot = gf[6] | (gf[7] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].xrot = gf[8] | (gf[9] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].zrot = gf[10] | (gf[11] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].flags = gf[12] | (gf[13] << 8);\n\t\t\t}\n\t\t\telse if (((n + 0x62) & 0xFF) < 8)\n\t\t\t{\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].objname = gf[0] | (gf[1] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].yoff = gf[2] | (gf[3] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].scale1 = gf[4] | (gf[5] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].yrot = gf[6] | (gf[7] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].xrot = gf[8] | (gf[9] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].zrot = gf[10] | (gf[11] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x7F) & 0xFF].flags = gf[12] | (gf[13] << 8);\n\t\t\t}\n\t\t\telse if (((n + 0x56) & 0xFF) < 4)\n\t\t\t{\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].objname = gf[0] | (gf[1] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].yoff = gf[2] | (gf[3] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].scale1 = gf[4] | (gf[5] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].yrot = gf[6] | (gf[7] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].xrot = gf[8] | (gf[9] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].zrot = gf[10] | (gf[11] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xA3) & 0xFF].flags = gf[12] | (gf[13] << 8);\n\t\t\t}\n\t\t\telse if (((n + 0x52) & 0xFF) < 3)\n\t\t\t{\n\t\t\t\tinventry_objects_list[(n + 0xAD) & 0xFF].objname = gf[0] | (gf[1] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xAD) & 0xFF].yoff = gf[2] | (gf[3] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xAD) & 0xFF].scale1 = gf[4] | (gf[5] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xAD) & 0xFF].yrot = gf[6] | (gf[7] << 8);\n\t\t\t\tinventry_objects_list[(n + 0xAD) & 0xFF].xrot = gf[8] | (gf[9] << 8);\n#if DEBUG_VERSION\n\tProfileRGB(255, 255, 255);\n#endif\n\n\tOldSP = SetSp(0x1F8003E0);\n#endif\n\n\tgfStatus = ControlPhase(nframes, (gfGameMode ^ 2) < 1 ? 1 : 0);\n\n#if PSX_VERSION\n#if DEBUG_VERSION\n\tSetSp(OldSP);\n\tProfileRGB(0, 0, 0);\n#endif\n#endif\n\t\t\t{\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].objname = gf[0] | (gf[1] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].yoff = gf[2] | (gf[3] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].scale1 = gf[4] | (gf[5] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].yrot = gf[6] | (gf[7] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].xrot = gf[8] | (gf[9] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].zrot = gf[10] | (gf[11] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x64) & 0xFF].flags = gf[12] | (gf[13] << 8);\n\t\t\t}\n\t\t\telse if (((n + 0x2F) & 0xFF) < 8)\n\t\t\t{\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].objname = gf[0] | (gf[1] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].yoff = gf[2] | (gf[3] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].scale1 = gf[4] | (gf[5] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].yrot = gf[6] | (gf[7] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].xrot = gf[8] | (gf[9] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].zrot = gf[10] | (gf[11] << 8);\n\t\t\t\tinventry_objects_list[(n + 0x80) & 0xFF].flags = gf[12] | (gf[13] << 8);\n\t\t\t}\n\t\t\tgf += 14;\n\t\t\tbreak;\n\t\tcase GF_GIVE_ITEM_AT_STARTUP:\n\t\t\t//loc_11198\n\t\t\tgfPickups[gfNumPickups++] = *gf;\n\t\t\tgf += 2;\n\t\t\tbreak;\n\t\tcase GF_LOSE_ITEM_AT_STARTUP:\n\t\t\t//loc_111BC\n\t\t\tgfTakeaways[gfNumTakeaways++] = *gf;\n\t\t\tgf += 2;\n\t\t\tbreak;\n\t\t}\n\n\t\t//loc_10FB4\n\t}\n}\n\nvoid LoadGameflow()//102E0(<), 102B0(<) (F)\n{\n\tint i;\n\tint len;\n\tunsigned char* s = NULL;\n\tstruct STRINGHEADER sh;\n\tint j;\n\tint flag;\n\n#if PSX_VERSION || PSXPC_VERSION\n\tlen = FILE_Length(GF_SCRIPT_FILENAME);\n\ts = (unsigned char*)game_malloc(len);\n\tFILE_Load(GF_SCRIPT_FILENAME, s);\n#endif\n\n#if PC_VERSION\n\tLoadFile(GF_SCRIPT_FILENAME, (void**)&s);\n\tgfScriptFile = (char*)s;\n#endif\n\n\tGameflow = (struct GAMEFLOW*)s;\n\ts += sizeof(struct GAMEFLOW);\n\n\tgfExtensions = (char*)s;\n\ts += 40;\n\n\tgfFilenameOffset = (unsigned short*)s;\n\ts += Gameflow->nFileNames * sizeof(unsigned short);\n\n\tgfFilenameWad = (char*)s;\n\ts += Gameflow->FileNameLen;\n\n\tgfScriptOffset = (unsigned short*)s;\n\n#if !PC_VERSION\n\tgfScriptLen = (len + 3) & -4;\n#endif\n\ts += Gameflow->nLevels * sizeof(unsigned short);\n\n\tgfScriptWad = s;\n\ts += Gameflow->ScriptLen;\n\n\t//loc_103A8\n#if PC_VERSION\n\tfor(gfStringOffset = NULL, i = 0; !LoadFile((char*)s, (void**)&gfStringOffset); i++, gfScriptOffset = NULL)\n#else\n\tgfStringOffset = (unsigned short*)(((uintptr_t)s + 3) & -4);\n\n\tfor(i = 0; FILE_Length((char*)s) == -1; i++)\n#endif\n\t{\n\t\ts += strlen((char*)s) + 1;\n\t}\n\n\tGameflow->Language = i;\n\n#if !PC_VERSION\n\tFILE_Load((char*)s, gfStringOffset);\n#endif\n\n\tmemcpy(&sh, &gfStringOffset[0], sizeof(struct STRINGHEADER));\n\n#if PSX_VERSION || PSXPC_VERSION\n\n\tmemcpy(&gfStringOffset[0], &gfStringOffset[sizeof(struct STRINGHEADER) / sizeof(unsigned short)], (sh.nStrings + sh.nPSXStrings) * sizeof(unsigned short));\n\n\tgfStringWad = (char*)&gfStringOffset[sh.nStrings + sh.nPSXStrings];\n\n#if BETA_VERSION\n\tmemcpy(&gfStringOffset[sh.nStrings + sh.nPSXStrings], &gfStringOffset[317], sh.StringWadLen + sh.PSXStringWadLen);\n#else\n\tmemcpy(&gfStringOffset[sh.nStrings + sh.nPSXStrings], &gfStringOffset[315], sh.StringWadLen + sh.PSXStringWadLen);\n#endif\n\n\tgfScriptLen += (((sh.nStrings + sh.nPSXStrings * sizeof(unsigned short)) + sh.StringWadLen + sh.PSXStringWadLen + 3) & -4);\n\n#else\n\tmemcpy(&gfStringOffset[0], &gfStringOffset[sizeof(struct STRINGHEADER) / sizeof(unsigned short)], (sh.nStrings + sh.nPSXStrings + sh.nPCStrings) * sizeof(unsigned short));\n\n\tgfStringWad = (char*)&gfStringOffset[sh.nStrings + sh.nPSXStrings + sh.nPCStrings];\n\n\tmemcpy(&gfStringOffset[sh.nStrings + sh.nPSXStrings + sh.nPCStrings], &gfStringOffset[315], sh.StringWadLen + sh.PSXStringWadLen + sh.PCStringWadLen);///@TODO check 315 const for PC\n\n#endif\n\n\t//loc_10490\n#if PSX_VERSION || PSXPC_VERSION\n\tfor (i = 0; i < sh.nStrings + sh.nPSXStrings; i++)\n#else\n\tfor (i = 0; i < sh.nStrings + sh.nPSXStrings + sh.nPCStrings - 1; i++)\n#endif\n\t{\n\t\tfor (j = 0; j < gfStringOffset[i + 1] - gfStringOffset[i] - 1; j++)\n\t\t{\n\t\t\tgfStringWad[gfStringOffset[i] + j] ^= 0xA5;\n\t\t}\n\t\t//loc_104DC\n\t}//loc_104F8\n\n\tif (Gameflow->nLevels != 0)\n\t{\n\t\t//loc_10510\n\t\tfor (i = 0; i + 1 < Gameflow->nLevels; i++)\n\t\t{\n\t\t\tflag = 0;\n\t\t\ts = &gfScriptWad[gfScriptOffset[i]];\n\n\t\t\t//loc_10530\n\t\t\tdo\n\t\t\t{\n\t\t\t\tswitch (*s++)\n\t\t\t\t{\n\t\t\t\tcase GF_FMV:\n\t\t\t\tcase GF_CUT:\n\t\t\t\tcase GF_RESIDENTCUT1:\n\t\t\t\tcase GF_RESIDENTCUT2:\n\t\t\t\tcase GF_RESIDENTCUT3:\n\t\t\t\tcase GF_RESIDENTCUT4:\n\t\t\t\tcase GF_UV_ROTATE:\n\t\t\t\tcase GF_LEGEND:\n\t\t\t\tcase GF_ANIMATING_MIP:\n\t\t\t\tcase GF_RESET_HUB:\n\t\t\t\t\t//loc_10568\n\t\t\t\t\ts += 1;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_LEVEL:\n\t\t\t\t\t//loc_10588\n\t\t\t\t\tgfLevelNames[i] = *s;\n\t\t\t\t\tgfWadNames[i] = s[3];\n\t\t\t\t\ts += 5;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_TITLE_LEVEL:\n\t\t\t\tcase GF_LAYER1:\n\t\t\t\tcase GF_LAYER2:\n\t\t\t\t\t//loc_10578\n\t\t\t\t\ts += 4;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_LEVEL_DATA_END:\n\t\t\t\t\t//loc_105BC\n\t\t\t\t\tflag = 1;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_LENS_FLARE:\n\t\t\t\t\t//loc_105B4\n\t\t\t\t\ts += 9;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_MIRROR:\n\t\t\t\t\t//loc_10580\n\t\t\t\t\ts += 5;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_FOG:\n\t\t\t\t\t//loc_10570\n\t\t\t\t\ts += 3;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_KEY_ITEM1:\n\t\t\t\tcase GF_KEY_ITEM2:\n\t\t\t\tcase GF_KEY_ITEM3:\n\t\t\t\tcase GF_KEY_ITEM4:\n\t\t\t\tcase GF_KEY_ITEM5:\n\t\t\t\tcase GF_KEY_ITEM6:\n\t\t\t\tcase GF_KEY_ITEM7:\n\t\t\t\tcase GF_KEY_ITEM8:\n\t\t\t\tcase GF_KEY_ITEM9:\n\t\t\t\tcase GF_KEY_ITEM10:\n\t\t\t\tcase GF_KEY_ITEM11:\n\t\t\t\tcase GF_KEY_ITEM12:\n\t\t\t\tcase GF_PUZZLE_ITEM1:\n\t\t\t\tcase GF_PUZZLE_ITEM2:\n\t\t\t\tcase GF_PUZZLE_ITEM3:\n\t\t\t\tcase GF_PUZZLE_ITEM4:\n\t\t\t\tcase GF_PUZZLE_ITEM5:\n\t\t\t\tcase GF_PUZZLE_ITEM6:\n\t\t\t\tcase GF_PUZZLE_ITEM7:\n\t\t\t\tcase GF_PUZZLE_ITEM8:\n\t\t\t\tcase GF_PUZZLE_ITEM9:\n\t\t\t\tcase GF_PUZZLE_ITEM10:\n\t\t\t\tcase GF_PUZZLE_ITEM11:\n\t\t\t\tcase GF_PUZZLE_ITEM12:\n\t\t\t\tcase GF_PICKUP_ITEM1:\n\t\t\t\tcase GF_PICKUP_ITEM2:\n\t\t\t\tcase GF_PICKUP_ITEM3:\n\t\t\t\tcase GF_PICKUP_ITEM4:\n\t\t\t\tcase GF_EXAMINE1:\n\t\t\t\tcase GF_EXAMINE2:\n\t\t\t\tcase GF_EXAMINE3:\n\t\t\t\tcase GF_KEY_ITEM1_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM1_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM2_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM2_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM3_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM3_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM4_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM4_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM5_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM5_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM6_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM6_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM7_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM7_COMBO2:\n\t\t\t\tcase GF_KEY_ITEM8_COMBO1:\n\t\t\t\tcase GF_KEY_ITEM8_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM1_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM1_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM2_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM2_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM3_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM3_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM4_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM4_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM5_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM5_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM6_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM6_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM7_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM7_COMBO2:\n\t\t\t\tcase GF_PUZZLE_ITEM8_COMBO1:\n\t\t\t\tcase GF_PUZZLE_ITEM8_COMBO2:\n\t\t\t\tcase GF_PICKUP_ITEM1_COMBO1:\n\t\t\t\tcase GF_PICKUP_ITEM1_COMBO2:\n\t\t\t\tcase GF_PICKUP_ITEM2_COMBO1:\n\t\t\t\tcase GF_PICKUP_ITEM2_COMBO2:\n\t\t\t\tcase GF_PICKUP_ITEM3_COMBO1:\n\t\t\t\tcase GF_PICKUP_ITEM3_COMBO2:\n\t\t\t\tcase GF_PICKUP_ITEM4_COMBO1:\n\t\t\t\tcase GF_PICKUP_ITEM4_COMBO2:\n\t\t\t\tcase GF_GIVE_ITEM_AT_STARTUP:///@CHECKME\n\t\t\t\tcase GF_LOSE_ITEM_AT_STARTUP:///@CHECKME\n\t\t\t\tdefault:\n\t\t\t\t\t//def_10560\n\t\t\t\t\ts += 2;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t} while (flag == 0);\n\t\t}\n\t}\n\t//loc_105EC\n}\n\nvoid QuickControlPhase()//10274(<), 10264(<) (F) (*) (D) (ND)\n{\n#if PSX_VERSION\n#if DEBUG_VERSION\n\tProfileRGB(255, 255, 255);\n#endif\n\tOldSP = SetSp(0x1F8003E0);\n#endif\n\n#if PSX_VERSION || PSXPC_VERSION\n\tgfStatus = ControlPhase(nframes, gfGameMode == 2);\n#else\n\tgfStatus = ControlPhase(nframes, 0);\n#endif\n\n#if PSX_VERSION\n\tSetSp(OldSP);\n#if DEBUG_VERSION\n\tProfileRGB(0, 0, 0);\n#endif\n#endif\n}\n\n#if PC_VERSION\nbool initial_fmv_played = false;\n\nvoid DoFrontEndOneShotStuff()\n{\n\tif (!initial_fmv_played)\n\t{\n\t\tPlayFmvNow(0);\n\t\tPlayFmvNow(1);\n\t\tinitial_fmv_played = true;\n\t}\n}\n#endif\n\n#if defined(__EMSCRIPTEN__)\nvoid DoTitleGameLoop(void* arg)\n{\n\tint i;\n\tunsigned char Name = ((unsigned char*)arg)[0];\n\tprintf("Name %d\\n", Name);\n\tif (gfStatus == 0)\n\t{\n\t\tGPU_BeginScene();\n\n\t\tif (bDoCredits)\n\t\t{\n#if !PSXPC_VERSION && RELOC\n\t\t\tif (!((INTFUNCVOID*)RelocPtr[MOD_TITSEQ][1])())\n\t\t\t{\n\t\t\t\tbDoCredits = 0;\n\t\t\t\tSetFadeClip(0, 2);\n\t\t\t}\n#endif\n\t\t\t//loc_10800\n\t\t\tif (bDoCredits)\n\t\t\t\tgoto loc_10890;\n\n\t\t}\n\t\tprintf("GLOBAL_PLAYING_CUTSEQ: %d\\n", GLOBAL_playing_cutseq);\n\t\t//loc_10810\n\t\tif (GLOBAL_playing_cutseq == 0)\n\t\t{\n\t\t\tif (ScreenFading == 0 && cutseq_num == 0)\n\t\t\t{\n#if DEBUG_VERSION\n\t\t\t\tif ((RawPad & (IN_R2 | 1)) == (IN_R2 | 1))\n\t\t\t\t{\n\t\t\t\t\tdels_cutseq_selector_flag = 1;\n\t\t\t\t}\n#endif\n\t\t\t\t//loc_10868\n\t\t\t\tCreditsDone = 1;\n#if RELOC\n\t\t\t\tgfStatus = ((INTFUNCINT*)RelocPtr[MOD_TITSEQ][0])(Name);\n#else\n\t\t\t\tgfStatus = TitleOptions(Name);\n\t\t\t\tprintf("EMSCRIPTEN TITLE OPTS! %d\\n", gfStatus);\n#endif\n\t\t\t\t//Early out\n\t\t\t\tif (gfStatus != 0)\n\t\t\t\t\tgoto breakLoop;\n\n\t\t\t}//loc_10890\n\n\t\tloc_10890:\n\t\t\tif (GLOBAL_playing_cutseq == 0)\n\t\t\t\tgoto loc_108EC;\n\t\t}\n\t\t//loc_108A4\n\t\tif (bDoCredits == 0 && CreditsDone)\n\t\t{\n\t\t\tPrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 20, 1, &gfStringWad[gfStringOffset[STR_DEMO_MODE]], FF_CENTER);\n\t\t}\n\t\t//loc_108EC\n\tloc_108EC:\n\t\tnframes = DrawPhaseGame();\n\n\t\tif (!PadConnected)\n\t\t{\n\n\t\t\tPrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) + 8, 3, &gfStringWad[gfStringOffset[STR_CONTROLLER_REMOVED]], (FF_BLINK | FF_CENTER));\n\t\t}\n\t\t//loc_1092C\n\t\thandle_cutseq_triggering(Name);\n\n\t\tif (gfGameMode == 2)\n\t\t{\n\t\t\tif ((dbinput & 0x100))\n\t\t\t\tgoto loc_10970;\n\n\t\t\tif (GLOBAL_enterinventory == -1)\n\t\t\t\tgoto loc_109A8;\n\n\t\t\t//loc_10970\n\t\tloc_10970:\n\t\t\tif (cutseq_trig == 0 && lara_item->hit_points > 0)\n\t\t\t{\n\t\t\t\tS_CallInventory2();\n\t\t\t}//loc_109A8\n\t\t}//loc_109A8\n\tloc_109A8:\n\t\tQuickControlPhase();\n\n\t\tif (gfGameMode == 2 && ScreenFadedOut != 0)\n\t\t{\n\t\t\tInitialiseItemArray(256);\n\n\t\t\tfor (i = 0; i < number_rooms; i++)\n\t\t\t{\n\t\t\t\troom[i].item_number = -1;\n\t\t\t}\n\t\t\t//loc_10A10\n\t\t\tgfGameMode = 1;\n\n\t\t}//loc_10A14\n\t}\n\telse\n\t{\n\tbreakLoop:\n\t\temscripten_cancel_main_loop();\n\t\tprintf("Cancelling main loop!\\n");\n\t}\n}\n#endif\n\nvoid DoTitle(unsigned char Name, unsigned char Audio)//10604(<), 105C4(<) (F) (*) (D) (ND)\n{\n/*#if PC_VERSION\n\tS_Warn("DoTitle PC");\n\tgfCurrentLevel = LVL5_STREETS_OF_ROME;\n\tDoLevel(LVL5_STREETS_OF_ROME, Audio);\n\treturn;\n#endif*/\n\n\tint i;\n\n\tCreditsDone = 0;\n\n#if PC_VERSION\n\tDoFrontEndOneShotStuff();\n#endif\n\n\tCanLoad = 0;\n\n#if PC_VERSION\n\tSetFade(255, 0);\n#else\n\tif (Gameflow->LoadSaveEnabled)\n\t{\n\t\tmcOpen(1);\n\t}\n#endif\n\n\t//loc_10648\n\tnum_fmvs = 0;\n\tfmv_to_play[1] = 0;\n\tfmv_to_play[0] = 0;\n\n#if PSX_VERSION || PSXPC_VERSION\n\tXAMasterVolume = savegame.VolumeCD;\n#endif\n\n\tS_MemSet((char*)&savegame.Level, 0, sizeof(struct STATS));\n\tS_MemSet((char*)&savegame.Game, 0, sizeof(struct STATS));\n\n\tS_LoadLevelFile(Name);\n\t\n\tGLOBAL_lastinvitem = -1;\n\tdels_cutseq_player = 0;\n\n\tInitSpotCamSequences();\n\t\n\ttitle_controls_locked_out = 0;\n\n#if PC_VERSION\n\tInitialiseFXArray(1);\n\tInitialiseLOTarray(1);\n\n\t// TODO fog\n\n\tClearFXFogBulbs();\n#endif\n\n\tInitialisePickUpDisplay();\n\n#if PSX_VERSION || PSXPC_VERSION\n\tphd_InitWindow(90);\n#endif\n\n#if PC_VERSION\n\tS_InitialiseScreen();\n#endif\n\t\n#if !PSXPC_TEST//Im sure this causes an infinite loop for PSXPC_N, disable for now.\n\tSOUND_Stop();\n#endif\n\tIsAtmospherePlaying = 0;\n\t\n\tS_SetReverbType(1);\n\n\tInitialiseCamera();\n\n#if PC_VERSION\n\tdword_51CE58 = 1;\n#endif\n\n\tif (!bDoCredits)\n\t{\n\t\ttrigger_title_spotcam(1);\n\t\tScreenFadedOut = 0;\n\t\tScreenFade = 0;\n\t\tdScreenFade = 0;\n\t\tScreenFadeBack = 0;\n\t\tScreenFadeSpeed = 8;\n\t\tScreenFading = 0;\n\t}\n\telse\n\t{\n\t\t//loc_10730\n\t\tcutseq_num = CUT_SPECIAL1;\n\t\tSetFadeClip(32, 1);\n\t\tScreenFadedOut = 1;\n\t\tScreenFade = 255;\n\t\tdScreenFade = 255;\n#if !BETA_VERSION\n\t\tS_CDPlay(CDA_XA14_ECREDITS, 1);\n#endif\n\t}\n\n\t//loc_10764\n\tbUseSpotCam = 1;\n\tlara_item->mesh_bits = 0;\n\tgfGameMode = 1;\n\n#if DEBUG_VERSION\n\tshow_game_malloc_totals();\n#endif\n\n\tgfLevelComplete = 0;\n\tnframes = 2;\n\tgfStatus = ControlPhase(2, 0);\n\tJustLoaded = 0;\n\n#if PC_VERSION\n\twhile (gfStatus == 0)\n\t{\n\t\tGPU_BeginScene();\n\t\tSkyDrawPhase();\n\t\tgfStatus = TitleOptions();\n\t\tif (gfStatus != 0)\n\t\t\tbreak;\n\t\thandle_cutseq_triggering(Name);\n\t\tnframes = DrawPhaseGame();\n\t\tgfStatus = ControlPhase(nframes, 0);\n\t\tDoSpecialFeaturesServer();\n\t}\n#else\n#if !defined(__EMSCRIPTEN__)\n\tif (gfStatus == 0)\n\t{\n\t\t//loc_107BC\n\t\twhile (gfStatus == 0)\n\t\t{\n\t\t\tGPU_BeginScene();\n\n\t\t\tif (bDoCredits)\n\t\t\t{\n#if !PSXPC_VERSION && RELOC\n\t\t\t\tif (!((INTFUNCVOID*)RelocPtr[MOD_TITSEQ][1])())\n\t\t\t\t{\n\t\t\t\t\tbDoCredits = 0;\n\t\t\t\t\tSetFadeClip(0, 2);\n\t\t\t\t}\n#endif\n\t\t\t\t//loc_10800\n\t\t\t\tif (bDoCredits)\n\t\t\t\t\tgoto loc_10890;\n\t\t\t\t\t\n\t\t\t}\n\t\t\tprintf("GLOBAL_PLAYING_CUTSEQ: %d\\n", GLOBAL_playing_cutseq);\n\t\t\t//loc_10810\n\t\t\tif (GLOBAL_playing_cutseq == 0)\n\t\t\t{\n\t\t\t\tif (ScreenFading == 0 && cutseq_num == 0)\n\t\t\t\t{\n#if DEBUG_VERSION\n\t\t\t\t\tif ((RawPad & (IN_R2 | 1)) == (IN_R2 | 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tdels_cutseq_selector_flag = 1;\n\t\t\t\t\t}\n#endif\n\t\t\t\t\t//loc_10868\n\t\t\t\t\tCreditsDone = 1;\n#if RELOC\n\t\t\t\t\tgfStatus = ((INTFUNCINT*)RelocPtr[MOD_TITSEQ][0])(Name);\n#else\n\t\t\t\t\tgfStatus = TitleOptions(Name);\n#endif\n\t\t\t\t\t//Early out\n\t\t\t\t\tif (gfStatus != 0)\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t}//loc_10890\n\n\t\t\tloc_10890:\n\t\t\t\tif (GLOBAL_playing_cutseq == 0)\n\t\t\t\t\tgoto loc_108EC;\n\t\t\t}\n\t\t\t//loc_108A4\n\t\t\tif (bDoCredits == 0 && CreditsDone)\n\t\t\t{\n\t\t\t\tPrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 20, 1, &gfStringWad[gfStringOffset[STR_DEMO_MODE]], FF_CENTER);\n\t\t\t}\n\t\t\t//loc_108EC\n\t\tloc_108EC:\n\t\t\tnframes = DrawPhaseGame();\n\n\t\t\tif (!PadConnected)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tPrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) + 8, 3, &gfStringWad[gfStringOffset[STR_CONTROLLER_REMOVED]], (FF_BLINK | FF_CENTER));\n\t\t\t}\n\t\t\t//loc_1092C\n\t\t\thandle_cutseq_triggering(Name);\n\n\t\t\tif (gfGameMode == 2)\n\t\t\t{\n\t\t\t\tif ((dbinput & 0x100))\n\t\t\t\t\tgoto loc_10970;\n\n\t\t\t\tif (GLOBAL_enterinventory == -1)\n\t\t\t\t\tgoto loc_109A8;\n\n\t\t\t\t//loc_10970\n\t\t\tloc_10970:\n\t\t\t\tif (cutseq_trig == 0 && lara_item->hit_points > 0)\n\t\t\t\t{\n\t\t\t\t\tS_CallInventory2();\n\t\t\t\t}//loc_109A8\n\t\t\t}//loc_109A8\n\t\tloc_109A8:\n\t\t\tQuickControlPhase();\n\n\t\t\tif (gfGameMode == 2 && ScreenFadedOut != 0)\n\t\t\t{\n\t\t\t\tInitialiseItemArray(256);\n\n\t\t\t\tfor (i = 0; i < number_rooms; i++)\n\t\t\t\t{\n\t\t\t\t\troom[i].item_number = -1;\n\t\t\t\t}\n\t\t\t\t//loc_10A10\n\t\t\t\tgfGameMode = 1;\n\n\t\t\t}//loc_10A14\n\t\t}\n\t}\n#else\n\tprintf("Name %d\\n", Name);\n\temscripten_set_main_loop_arg(DoTitleGameLoop, &Name, 0, 1);\n#endif\n\n\t//loc_10A24\n\tMotors[1] = 0;\n\tMotors[0] = 0;\n\n\tif (Gameflow->LoadSaveEnabled)\n\t{\n\t\tmcClose();\n\t}\n\n\n\t//loc_10A58\n\tdo\n\t{\n#if PSXPC_TEST\n\t\t//Because emulator doesn\'t call this every Vblank\n\t\tVSync(0);\n#endif\n\t\tXAReqVolume = 0;\n\t\t\n\t} while (XAVolume != 0);\n\n#endif\n\n\tNoInput = 0;\n\tS_SoundStopAllSamples(); //Bug, infinite loop on PSX?\n\tS_CDStop();\n\tbUseSpotCam = 0;\n\tbDisableLaraControl = 0;\n\n#if PSX_VERSION || PSXPC_VERSION\n\tinput = 0;\n#elif PC_VERSION\n\tif (gfLevelComplete == 1 && gfStatus != 2)\n\t\tPlayFmvNow(2);\n\n\tif (gfStatus != 4)\n\t\tinput = 0;\n#endif\n\n}\n\nvoid DoLevel(unsigned char Name, unsigned char Audio)//10ABC(<) 10A84(<) (F)\n{\n\tchar *d;\n\n#if !BETA_VERSION\n\tint fmvStatus;\n#endif\n#if PSXENGINE\n\tif (gfGameMode == 4)\n\t{\n\t\tif (FromTitle == 1)\n\t\t{\n\t\t\td = (char*) &GadwPolygonBuffers[49188];\n\t\t\tmemcpy((void*) d, &MGSaveGamePtr[0], 8192);\n\t\t\tMGSaveGamePtr = d;\n\t\t}\n\t}\n\n\t//loc_10B24\n\tFromTitle = 0;\n\n\n\tXAMasterVolume = savegame.VolumeCD;\n#endif\n\n#if PC_VERSION\n\tSetFade(255, 0);\n#endif\n\n\tif (gfGameMode == 4)\n\t{\n\t\tmemset(&savegame.Level, 0, sizeof(struct STATS));\n\t}\n\n\t//loc_10B58\n\tS_LoadLevelFile(Name);\n\n#if PC_VERSION\n\t//SetFogColor(...); todo\n\n\tInitialiseFXArray(TRUE);\n\tInitialiseLOTarray(TRUE);\n\n\tClearFXFogBulbs();\n\n\t// todo\n#endif\n\n\tInitSpotCamSequences();\n\tInitialisePickUpDisplay();\n\n#if PC_VERSION\n\tS_InitialiseScreen();\n#endif\n\n#if PSX_VERSION || PSXPC_VERSION\n\tphd_InitWindow(90);\n#endif\n\tSOUND_Stop();\n\tbDisableLaraControl = 0;\n\n\tif (gfGameMode == 4)\n\t{\n\t\tsgRestoreGame();\n\t\tgfRequiredStartPos = 0;\n\t\tgfInitialiseGame = 0;\n\n#if PC_VERSION\n\t\tif (IsVolumetric())\n\t\t{\n\t\t\t//SetFogColor(...); todo\n\t\t}\n#endif\n\t}\n\telse\n\t{\n\t\t//loc_10BAC\n\t\tgfRequiredStartPos = 0;\n\n\t\tif (gfInitialiseGame != 0)\n\t\t{\n\t\t\tGameTimer = 0;\n\t\t\tgfRequiredStartPos = 0;\n\t\t\tgfInitialiseGame = 0;\n\t\t\tFmvSceneTriggered = 0;\n\t\t\tInitCutPlayed();\n\t\t}\n\n\t\t//loc_10BD8\n\t\tCurrentAtmosphere = Audio;\n\t\tsavegame.Level.Timer = 0;\n\n\t\tif (gfCurrentLevel == LVL5_STREETS_OF_ROME)\n\t\t{\n\t\t\tsavegame.TLCount = 0;\n\t\t}\n\t}\n\n\t//loc_10BF8\n\tS_CDPlay(CurrentAtmosphere, 1);\n\n\tIsAtmospherePlaying = TRUE;\n\tScreenFadedOut = FALSE;\n\tScreenFading = FALSE;\n\tScreenFadeBack = FALSE;\n\tdScreenFade = 255;\n\tScreenFade = 255;\n\n\tif (dels_cutseq_player != 0)\n\t{\n\t\tgfCutNumber = 0;\n\t}//loc_10C50\n\n\tif (gfCutNumber == 0 || CheckCutPlayed(gfCutNumber) != 0)\n\t{\n\t\t//loc_10C7C\n\t\tif (dels_cutseq_player != 0)\n\t\t{\n\t\t\tcutseq_num = dels_cutseq_player;\n\t\t\tgfCutNumber = 0;\n\t\t\tScreenFadedOut = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcutseq_num = 0;\n\t\t\tgfCutNumber = 0;\n\t\t\tSetScreenFadeIn(16);\n\t\t}\n\t}\n\telse\n\t{\n\t\t//loc_10C90\n\t\tcutseq_num = gfCutNumber;\n\t\tgfCutNumber = 0;\n\t\tScreenFadedOut = 1;\n\t}\n\t//loc_10CD8\n\tInitialiseCamera();\n\tbUseSpotCam = 0;\n\n#if DEBUG_VERSION\n\tshow_game_malloc_totals();\n#endif\n\n\tgfGameMode = 0;\n\tgfLevelComplete = 0;\n\tnframes = 2;\n\tframecount = 0;\n\n\tgfStatus = ControlPhase(2, 0);\n\n\tdbinput = IN_NONE;\n\tJustLoaded = 0;\n\n\t//loc_10D30\n\twhile (gfStatus == 0)\n\t{\n\t\tGPU_BeginScene();\n\n\t\tif (gfLegendTime != 0 && DestFadeScreenHeight == 0 && FadeScreenHeight == 0 && cutseq_num == 0)\n\t\t{\n\t\t\tPrintString(\n#if PSX_VERSION || PSXPC_TEST || PSXPC_VERSION || SAT_VERSION\n\t\t\t\t0x100, 0xE8,\n#else\n\t\t\t\tphd_winwidth / 2, phd_winymax - font_height,\n#endif\n\t\t\t\t2, &gfStringWad[gfStringOffset[gfLegend]], FF_CENTER);\n\t\t\tgfLegendTime--;\n\t\t}\n\n\t\t//loc_10DC4\n\t\tnframes = DrawPhaseGame();\n\t\thandle_cutseq_triggering(Name);\n\n\t\tif (DEL_playingamefmv != 0)\n\t\t{\n\t\t\tDEL_playingamefmv = 0;\n\t\t}\n\n\t\t//loc_10DEC\n\t\tif (gfLevelComplete == 0)\n\t\t{\n\t\t\tif ((dbinput & IN_OPTION) || GLOBAL_enterinventory != -1)\n\t\t\t{\n\t\t\t\t//loc_10E28\n \t\t\t\tif (cutseq_trig == 0 && lara_item->hit_points > 0 && ScreenFading == 0)\n\t\t\t\t{\n\t\t\t\t\tif (S_CallInventory2())\n\t\t\t\t\t{\n\t\t\t\t\t\tgfStatus = 2;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t//loc_10E7C\n\t\t\tQuickControlPhase();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tgfStatus = 3;\n\t\t\tbreak;\n\t\t}\n\t}\n\n#if PSXENGINE\n\t//loc_10E94\n\tXAReqVolume = 0;\n\tMotors[1] = 0;\n\tMotors[0] = 0;\n\n\n\tif (XAVolume != 0)\n\t{\n\t\t//loc_10EBC\n\t\tdo\n\t\t{\n\t\t\tXAReqVolume = 0;\n\t\t} while (XAVolume == 0);\n\t}\n\n\n\t//loc_10ED8\n\treset_count = 0;\n#endif\n\n\tS_SoundStopAllSamples();\n\tS_CDStop();\n\n#if !BETA_VERSION\n\n\tif (gfStatus == 3)\n\t{\n\t\tfmvStatus = 0;\n\n\t\tif (fmv_to_play[0] & 0x80)\n\t\t{\n\t\t\tif ((fmv_to_play[0] & 0x7F) == 9 && gfLevelComplete != 10)\n\t\t\t{\n\t\t\t\tfmv_to_play[0] = 0;\n\t\t\t}\n\t\t\t\n\t\t\t//loc_10EF8\n\t\t\tif ((fmv_to_play[0] & 0x7F) == 8 && gfLevelComplete != 22)\n\t\t\t{\n\t\t\t\tfmv_to_play[0] = 0;\n\t\t\t}\n\t\t}\n#if PSXENGINE\t\n\t\t//loc_10F20\n\t\tif (fmv_to_play[0] != 0)\n\t\t{\n\t\t\tfmvStatus = S_PlayFMV(fmv_to_play[0] & 0x7F, 1);\n\t\t}//loc_10F3C\n\n\t\tif (fmvStatus != 2 && fmv_to_play[1] != 0)\n\t\t{\n\t\t\tS_PlayFMV(fmv_to_play[1] & 0x7F, 1);\n\t\t}\n#endif\n\t}\n\n\t//loc_10F64\n\tnum_fmvs = 0;\n\tfmv_to_play[1] = 0;\n\tfmv_to_play[0] = 0;\n#endif\n\n\tlara.examine3 = 0;\n\tlara.examine2 = 0;\n\tlara.examine1 = 0;\n\n\tif (gfStatus == 3 && gfCurrentLevel == LVL5_RED_ALERT)\n\t{\n\t\tgfStatus = 1;\n\t\tbDoCredits = 1;\n\t\tscroll_pos = 0;\n\t}\n\n\t//loc_10F30\n\tinput = 0;\n\treset_flag = 0;\n}\n\n#if PC_VERSION\nvoid SpecialFeaturesDisplayScreens(int num)\n{\n\tUNIMPLEMENTED();\n}\n\nvoid DoSpecialFeaturesServer()// (F)\n{\n\tswitch(special_features_num)\n\t{\n\tcase 0:\n\t\tSpecialFeaturesDisplayScreens(0);\n\t\tbreak;\n\tcase 1:\n\t\tSpecialFeaturesDisplayScreens(1);\n\t\tbreak;\n\tcase 2:\n\t\tSpecialFeaturesDisplayScreens(2);\n\t\tbreak;\n\tcase 3:\n\t\tSpecialFeaturesDisplayScreens(3);\n\t\tbreak;\n\t}\n\n\tspecial_features_num = -1;\n}\n#endif', 'message': 'Fix PSX ver.\n', 'author_name': 'Gh0stBlade', 'lang': 'C'}