[Scummvm-git-logs] scummvm master -> b3784db8d55bde5db17aeebfd526e24b7ede54f2

sev- sev at scummvm.org
Tue Feb 7 21:21:09 CET 2017


This automated email contains information about 183 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ecf0d04104 CRYO: Lost Eden game engine initial commit
59c90d21ad CRYO: Prettify code with AStyle
517bcad684 CRYO: Fix warnings
390c379385 CRYO: Fix line endings
0dfe251496 CRYO: Fix warnings
ea01120013 CRYO: Refactor to avoid nested includes
85ba17c475 CRYO: Added standard ScummVM headers
0fbe26e06a CRYO: Use standard ScummVM types
a7c9ae8039 CRYO: Introduction Direction, fix some warnings using it
fb6abe59c6 CRYO: Some renaming, remove a couple of useless variables
f77429abcf CRYO: Fix some compilation warnings, change some variables to boolean
c9681492a4 CRYO: Consistantly use SUB_LINE for frame initialization
801436e00d CRYO: Silent some compilation warnings
bb15a26179 CRYO: Some renaming
01f10cc4ee CRYO: Some more renaming
0e4d63d37c CRYO: Simplify loadFile, some renaming and variable type changes
6c6eff6c40 CRYO: Some renaming
2e8b3e9462 CRYO: Renaming, replace rect_t by Common::Rect
0c7e5d920d CRYO: Simplify some code using rect
2d3247aba9 CRYO: More renaming
28803f6687 CRYO: Fix compilation
1e430a26f5 CRYO: Some more renaming
ed4167832c CRYO: Some renaming in cryolib
ec7d67d5c3 CRYO: Remove CryoLib debugging functions
8c5b816841 CRYO: Remove (partially unimplemented) caching code, remove some useless functions, add back code erroneously removed in
2efacf0dfe CRYO: More renaming, get rid of CLMemory_Alloc and CLMemory_Free
8670f43973 CRYO: Some more renaming
4e62c341df CRYO: More renaming
1843ac254d CRYO: Fix warnings
4d33e2cc27 CRYO: C++-ify some code
cb9e1b0475 CRYO: Fix another warning in initialization
65d1e8db1f CRYO: Fix detection entries
73df962b76 CRYO: Zeroize engine's variables
2c1ccf4769 CRYO: Fix smearing cursor
495d943d00 CRYO: Replace long with portable int32
85bc7f820f CRYO: Zero remaining engine variables
9e7129f417 CRYO: Added isDemo()
19038b2bce CRYO: Initial work on DOS and Demo versions support
054b5f0bd0 CRYO: Support PC demo and retail versions
d87f5e176e CRYO: Add data file generator
5bc0695ce3 DEVTOOLS: Fix create_led_dat compilation
afd6e5dea5 JANITORIAL: Fix line endings
577bae3f3d JANITORIAL: Fix code formatting
5616897f2a CRYO: Zeroize even more vars
7e92fb0790 CRYO: Add sound playback
4caa6541cd CRYO: Add sound.cpp to compilation
f09d3a5873 CRYO: Lost Eden - Add detection for 2 PC DOS versions
a032005efb CRYO: Reduce some variable scopes, remove some useless variables
8ed2dbcee5 CRYO: Some renaming, reduce the scope of more variables
cb23ed0777 CRYO: Reduce some variable scopes
e0ad53224e CRYO: Simplify limitezonecurs
5abf6770b7 CRYO: Remove monbreak(), reduce some more scopes
399b1d8c8e CRYO: Remove several useless CryoLib functions
82bbbe0f2d CRYO: Change some variables from Byte to Boolean
acff7309a2 CRYO: Remove useless source file
4aa4460bc1 CRYO: Change some int16 to boolean, use nullptr for pointers
4cbea86922 CRYO: Fix PC cursor rotation and drawing
6704ceebf2 CRYO: remove some CryoLib functions, simplify some code
ae4dd71f6d CRYO: Fix regression in previous commit
4e8490fdb2 CRYO: Silent warning
38b676bc00 CRYO: Enforce the use of boolean values for _animateTalking
91de8658f5 CRYO: Remove unused function
bd9cabd2c9 CRYO: Remove two setPos functions
0c217c2e8c CRYO: Remove CLFILE_MakeStruct and filespec_t
0d094b7b7b CRYO: change some variables to boolean, some renaming
86c3cc3b84 CRYO: Reduce some variable scopes, move some variables to boolean
b54d76c41f CRYO: Some more cosmetic changes
f86c12a323 CRYO: Reduce variable scopes, change the return type of a function
e9b577f871 CRYO: Reduce more variable scopes, some renaming
31834c39fa CRYO: Rename class variables to avoid shadowing warnings
df8f48b023 CRYO: Fix warnings
1b34a02db7 CRYO: More cleaning and renaming
c62b719118 CRYO: Some more renaming and reducing of scope
d879ecdfb5 CRYO: Remove LempelZiv files
899d22805f CRYO: minor polishing
b735962436 CRYO: Move some functions from cryolib to HnmPlayer
61998c7a99 CRYO: Move some more functions to HnmPlayer
9410c8563b CRYO: Some cleanup in HnmPlayer
2b4b3a3daf CRYO: Move some more functions to HnmPlayer
488e681e84 CRYO: Renaming in HnmPlayer, remove a couple of useless things
944524be92 CRYO: Some renaming
c2deb3ee75 CRYO: Reduce some variable scopes
878a3c8515 CRYO: Remove clhnm.cpp
f3bb961fec CRYO: Turn soundgroup_t into a class
1e3e2b992b CRYO: Fix regression, get rid of CLScreenView_CenterIn
be3e748829 CRYO: Objectify View
6523e3bf9b CRYO: Silent some warnings
e482209bd3 CRYO: Reduce some variable scopes, silent several warnings
ae90f97f2b CRYO: Fix some more warnings
8e37c4af7a CRYO: Renaming
e06fc0c3df CRYO: More renaming
0c18e81ff2 CRYO: Get rid of PLE16
3b379c1834 CRYO: Get rid of PLE32, start using MKTAG16
7bf6e1e850 CRYO: Silent a warning, some renaming
1e1e90f8ec CRYO: Rewrite the way the HNM header is read.
e76e4c8136 CRYO: Replace file_t by Common::File
550d62b25a CRYO: rewrite the loading of pak file header
707df78d14 CRYO: Refactor more file reads
d55ef8162b CRYO: Renaming
d0cf36810a CRYO: Some more renaming
742b1add71 CRYO: Revert some order change in global_t, some renaming
71e43bb645 CRYO: Rename unknown variables in global_t
208e89f1e8 CRYO: Some more renaming
3ffe41750e CRYO: Rework Citadel structure, some renaming
6d1b1d072c CRYO: Make more use of the PERSO enum, some renaming
348762834d CRYO: More renaming
75f92ae3bf CRYO: More renaming in EdenGame
e9fe53d821 CRYO: Simplify clipping code, some renaming
e31f2f11f1 CRYO: Some renaming
02c2f4ba6d CRYO: Rename more functions
1ae917bda9 CRYO: Fix heap issue
f08b9f5f5b CRYO: Fix the loading of icons for the Mac version
2f5932503c CRYO: Fix regression in room loading of the MAC version
23edae42f5 CRYO: Remove useless convertion functions
31815f914a CRYO: Some renaming
b89844b451 CRYO: Some more renaming
38beb1f9a5 CRYO: Rename operations, move _codePtr to EdenGame
83d48c2cf2 CRYO: Start renaming actions
1d4454b2e7 CRYO: more renaming of action functions
c02890b42b CRYO: Some more renaming
939aa63583 CRYO: Fix some warnings reported by CppCheck
11b1d47638 CRYO: Turn _voiceSamplesBuffer into a byte*
c56486a43e CRYO: Fix speech in PC version
2d3bbebc6b CRYO: Simplify setSrcRect and setDestRect, some renaming
7b95465309 CRYO: change the definition of verifh and expand_hsq
670c73824b CRYO: More renaming
183ccf3ad9 CRYO: More renaming
c85bfafefc CRYO: rename more functions
f483b7c555 CRYO: Some more renaming
ff1f320980 CRYO: Move mouse and keyboard functions to CryoEngine, remove some useless functions
448fe6303b CRYO: Fix conditional compilation related to endianness, some renaming
c667702f2c CRYO: Change soundchannel_t into a class
b669a704e2 CRYO: rename SoundChannel, get rid of soundraw
d748674193 CRYO: Rename sound_t
b3fcb77053 CRYO: enforce private variables and function in SoundGroup and CSoundChannel
caec6a8de9 CRYO: Get rid of HnmContext, refactoring
ad0616688c CRYO: Some renaming in HnmPlayer, remove a couple of useless variables
e20f65e5ea CRYO: Get rid of sound's locked and forcewait, remove some dead code, renaming
05833d27e3 CRYO: Remove some useless variables
1fd1b79446 CRYO: Add missing headers
86b482012b CRYO: Remove useless fields in HNM Header, some renaming
3ad086ed70 CRYO: Some renaming
9c52ea3b26 CRYO: Remove a GOTO
3ee08c1ac3 CRYO: get rid of 3 GOTOs
9632149f62 CRYO: Some renaming
6c8cd5dc4d CRYO: More renaming, get rid of another GOTO
8b94ad15c0 CRYO: Fix palette during screen transitions
215b9d5c21 CRYO: fix warning
e4555b86db CRYO: Fix renaming/translation error
1e7779edd3 CRYO: Rename cube code
77a79e8da3 CRYO: Split sinus and cosinus tables
2b80514c0e CRYO: Refactor projection
49b9ffa6ef CRYO: Some renaming, move some static arrays to handleHNMSubtitles
3e07b86069 CRYO: Some more renaming
a4f5733330 CRYO: Fix regression in PC cube rotation
b163b8fdb9 CRYO: Some more renaming
862f22e72a CRYO: Add Lost Eden German version detection entry
b455532d34 CRYO: move tab_2CB1E to EdenGame
d23bb8860b CRYO: Fix regression in globals
9634091925 CRYO: Add sound playback to HNM files (buggy yet)
cedce56c42 CRYO: Replace direct script globals access with a switch
30eb57b4b2 CRYO: Actualize readme file
7e4043ec85 CRYO: Fix broken sound in FMV scenes
aeeaf9b9e6 CRYO: Fix crash during PC intro video
59212d9270 CRYO: Fix some warnings
0e34cec17a CRYO: Fix out of bounds access in cursor save/restore
a8a142cfe4 CRYO: Introduce debugger, remove console initialisation
46ead90784 CRYO: Move inventory debug hack to debugger
c4bec08886 CRYO: Remove last use of EDEN_DEBUG
37b6b0d16f CRYO: Update readme file to reflect removal of EDEN_DEBUG
47c44b4488 CRYO: Fix compilation
8f7c4fa8a5 DEVTOOLS: Added copyright headers to create_cryo
1e77941a35 DEVTOOLS: Added makefile for create_cryo
fad3f324a8 CRYO: Remove a couple of unused class members
dfa605b6b4 CRYO: Remove dead code
6c139b7afb CRYO: Remove double screen code (unused)
bf989df043 CRYO: Remove some dead code, small refactoring
c8af2442b6 CRYO: Remove an empty function
472f8b2b00 CRYO: Remove SoundGroup (no longer used)
dec6b171a6 CRYO: Remove some obsolete TODOs
1ac6270531 CRYO: Remove some commented code
de11872686 CRYO: Fix a null pointer
b3784db8d5 Merge pull request #892 from Retro-Junk/cryo


Commit: ecf0d041045214933b9ef10d490bf62f3c7add99
    https://github.com/scummvm/scummvm/commit/ecf0d041045214933b9ef10d490bf62f3c7add99
Author: Retro-Junk (bambarbee at yandex.ru)
Date: 2017-01-25T22:41:46+01:00

Commit Message:
CRYO: Lost Eden game engine initial commit

Changed paths:
  A engines/cryo/CLError.c
  A engines/cryo/CLHNM.c
  A engines/cryo/CLSouNdRaw.c
  A engines/cryo/CryoLib.h
  A engines/cryo/CryoLibStub.c
  A engines/cryo/LempelZiv.cpp
  A engines/cryo/LempelZiv.h
  A engines/cryo/ResourceManager.cpp
  A engines/cryo/ResourceManager.h
  A engines/cryo/bugs.txt
  A engines/cryo/clsoundgroup.c
  A engines/cryo/configure.engine
  A engines/cryo/cryo.cpp
  A engines/cryo/cryo.h
  A engines/cryo/defs.h
  A engines/cryo/detection.cpp
  A engines/cryo/eden.cpp
  A engines/cryo/eden.h
  A engines/cryo/gameflow.txt
  A engines/cryo/module.mk
  A engines/cryo/platdefs.h
  A engines/cryo/readme.txt


diff --git a/engines/cryo/CLError.c b/engines/cryo/CLError.c
new file mode 100644
index 0000000..85abfef
--- /dev/null
+++ b/engines/cryo/CLError.c
@@ -0,0 +1,3 @@
+#include "cryolib.h"
+
+short __debug, __libError, __osError;
diff --git a/engines/cryo/CLHNM.c b/engines/cryo/CLHNM.c
new file mode 100644
index 0000000..3ab3f65
--- /dev/null
+++ b/engines/cryo/CLHNM.c
@@ -0,0 +1,874 @@
+#include "cryolib.h"
+
+static short safe_palette = 0;
+static short pred_r = 0, pred_l = 0;
+static short use_adpcm = 0;
+static float hnm_rate = 0.0;
+static float next_frame_time = 0.0;
+static float expected_frame_time = 0.0;
+static float time_drift = 0.0;
+static short use_mono = 0;
+static short use_sound = 0;
+static short use_sound_sync = 0;
+static short pending_sounds = 0;
+static short sound_started = 0;
+static short preserve_color0 = 0;
+static soundchannel_t *soundChannel_adpcm = 0;
+static soundgroup_t *soundGroup_adpcm = 0;
+static soundchannel_t *soundChannel = 0;
+static soundgroup_t *soundGroup = 0;
+static void (*custom_chunk_handler)(unsigned char *buffer, int size, short id, char h6, char h7) = 0;
+static short use_preload = 0;
+static short decomp_table[256];
+
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
+
+void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output)
+{
+	unsigned char *inp = buffer;
+	unsigned char *out = output;
+
+	unsigned int queue = 0;
+	int qpos = -1;
+
+	//TODO: fix for BE
+#define GetBit() ( 1 & ( (qpos >= 0) ? (queue >> qpos--) : (queue = *(unsigned int*)((inp += 4) - 4)) >> ((qpos = 30) + 1) ) )
+
+	for (;;)
+	{
+		if (GetBit())
+		{
+			*out++ = *inp++;
+		}
+		else
+		{
+			int l, o;
+			if (GetBit())
+			{
+				l = *inp & 7;
+				o = *(unsigned short*)inp >> 3; inp += 2;
+				o -= 8192;
+				if (!l)
+					l = *inp++;
+				if (!l)
+					break;
+			}
+			else
+			{
+				l = GetBit() * 2 + GetBit();
+				o = *(inp++) - 256;
+			}
+			l += 2;
+			while (l--)
+			{
+				*out = *(out + o); out++;
+			}
+		}
+	}
+
+#undef GetBit
+
+	return;
+}
+
+void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
+					 unsigned char *input, int width, char flags)
+{
+	unsigned int code;
+	char mode, count, color;
+	unsigned short offs;
+	unsigned char *ref;
+	unsigned char *out_start = output;
+	unsigned char swap;
+	int shft1, shft2;
+//	return;
+	if((flags & 1) == 0)
+	{
+		//HNM4 classic
+		int twolinesabove = -(width * 2);
+		for(;;)
+		{
+			code = PLE32(input) & 0xFFFFFF; //input++;
+			count = code & 0x1F;
+			if(count)
+			{
+				input += 3;
+				mode = (code >> 5) & 0xF;
+				offs = code >> 9;
+				//
+				swap = mode >> 3;
+				ref = ((mode & 1) ? prev_buffer : curr_buffer) + (output - out_start) + (offs * 2) - 32768;
+				if (mode & 2)
+				{
+					//					ref += twolinesabove;
+					shft1 = twolinesabove + 1;
+					shft2 = 0;
+					//swap ^= 1;
+				}
+				else
+				{
+					shft1 = 0;
+					shft2 = 1;
+				}
+				while(count--)
+				{
+					unsigned char b0 = ref[shft1];
+					unsigned char b1 = ref[shft2];
+					output[swap] = b0;
+					output[swap ^ 1] = b1;
+					output += 2;
+					ref += (mode & 4) ? -2 : 2;
+				}
+			}
+			else
+			{
+				input++;
+				mode = code & 0xFF;	// bits 0..4 are zero
+				switch(mode)
+				{
+				case 0:
+					*(output++) = *(input++);
+					*(output++) = *(input++);
+					break;
+				case 0x20:
+					output += 2 * *(input++);
+					break;
+				case 0x40:
+					output += 2 * (code >> 8); input += 2;
+					break;
+				case 0x60:
+					count = *(input++);
+					color = *(input++);
+					while(count--)
+					{
+						*(output++) = color;
+						*(output++) = color;
+					}
+					break;
+				default:
+					return;
+				}
+			}
+		}
+	}
+	else
+	{
+		assert(0);
+		//HNM4 hires
+		for(;;)
+		{
+			code = PLE32(input) & 0xFFFFFF; input++;
+			count = code & 0x3F;
+			if(count)
+			{
+				mode = (code >> 5) & 0xF;
+				offs = code >> 9;
+				// 
+			}
+			else
+			{
+				mode = code & 0xFF;	// bits 0..5 are zero
+				switch(mode)
+				{
+				case 0x00:
+					output += *input++;
+					break;
+				case 0x40:
+					*output++ = *input++;
+					*(output++ + width) = *input++;
+					break;
+				case 0x80:
+					output += width;
+					break;
+				default:
+					return;
+				}
+			}
+		}
+	}
+}
+
+void CLHNM_Init()
+{
+	use_preload = 0;
+	custom_chunk_handler = 0;
+	preserve_color0 = 0;
+	CLNoError;
+}
+
+void CLHNM_Done()
+{
+	CLNoError;
+}
+
+void CLHNM_SetupTimer(float rate)
+{
+	hnm_rate = 100.0 / rate;
+	CLNoError;
+}
+
+void CLHNM_WaitLoop(hnm_t *hnm)
+{
+	expected_frame_time += hnm_rate;
+	next_frame_time = expected_frame_time - time_drift;
+	if(use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
+		use_sound = 0;
+	while(TimerTicks < next_frame_time) ;	// waste time
+	time_drift = TimerTicks - next_frame_time;
+}
+
+void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode)
+{
+	soundChannel = CLSoundChannel_New(mode);
+	soundGroup = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
+	if(sampleSize == 16)
+		CLSoundGroup_Reverse16All(soundGroup);
+}
+
+void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode)
+{
+	soundChannel_adpcm = CLSoundChannel_New(mode);
+	soundGroup_adpcm = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
+}
+
+void CLHNM_CloseSound()
+{
+	if(soundChannel)
+	{
+		CLSoundChannel_Stop(soundChannel);
+		CLSoundChannel_Free(soundChannel);
+		soundChannel = 0;
+	}
+	if(soundGroup)
+	{
+		CLSoundGroup_Free(soundGroup);
+		soundGroup = 0;
+	}
+	if(soundChannel_adpcm)
+	{
+		CLSoundChannel_Stop(soundChannel_adpcm);
+		CLSoundChannel_Free(soundChannel_adpcm);
+		soundChannel = 0;
+	}
+	if(soundGroup_adpcm)
+	{
+		CLSoundGroup_Free(soundGroup_adpcm);
+		soundGroup = 0;
+	}
+}
+
+void CLHNM_SetForceZero2Black(short forceblack)
+{
+	preserve_color0 = forceblack;
+}
+
+hnm_t* CLHNM_New(int preload_size)
+{
+	hnm_t *hnm;
+	short i;
+
+	preload_size = 0;	//TODO: let's ignore it for now
+
+	CLBeginCheck;
+	hnm = (hnm_t*)CLMemory_Alloc(sizeof(*hnm));
+	CLCheckError();
+	if(hnm)
+	{
+		if(preload_size)
+		{
+			use_preload = 1;
+			
+		}
+		if(!__libError)
+		{
+			hnm->frame = 0;
+			hnm->ff_4 = 0;
+			hnm->file = 0;
+			hnm->work_buffer[0] = 0;
+			hnm->work_buffer[1] = 0;
+			hnm->final_buffer = 0;
+			hnm->read_buffer = 0;
+			hnm->ff_896 = 0;
+			hnm->total_read = 0;
+			for(i = 0;i < 256;i++)
+			{
+				hnm->palette[i].a = 0;	
+				hnm->palette[i].r = 0;	
+				hnm->palette[i].g = 0;	
+				hnm->palette[i].b = 0;	
+			}
+		}
+		else
+			CLCheckError();
+	}
+	CLEndCheck;
+	return hnm;
+}
+
+void CLHNM_Dispose(hnm_t *hnm)
+{
+	CLBeginCheck;
+	
+	if(use_preload)
+	{
+
+	}
+
+	CLMemory_Free(hnm);
+	CLCheckError();
+	
+	CLEndCheck;
+}
+
+
+void CLHNM_SetFile(hnm_t *hnm, file_t* file)
+{
+	hnm->file = file;
+	CLNoError;
+}
+
+void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer)
+{
+	hnm->final_buffer = buffer;
+	CLNoError;
+}
+
+void CLHNM_AllocMemory(hnm_t *hnm)
+{
+	CLBeginCheck;
+
+	hnm->work_buffer[0] = (unsigned char*)CLMemory_Alloc(hnm->header.buffersize + 2);
+	CLCheckError();
+
+	if(!hnm->work_buffer[0])
+		goto fin;
+
+	hnm->work_buffer[1] = (unsigned char*)CLMemory_Alloc(hnm->header.buffersize + 2);
+	CLCheckError();
+
+	if(!hnm->work_buffer[1])
+	{
+		CLMemory_Free(hnm->work_buffer[0]);
+		CLCheckError();
+		hnm->work_buffer[0] = 0;
+		goto fin;
+	}
+
+	if(!use_preload)
+	{
+		hnm->read_buffer = (unsigned char*)CLMemory_Alloc(hnm->header.buffersize + 2);
+//		CLCheckError();
+		if(!hnm->read_buffer)
+		{
+			CLMemory_Free(hnm->work_buffer[0]);
+			CLCheckError();
+			hnm->work_buffer[0] = 0;
+			CLMemory_Free(hnm->work_buffer[1]);
+			CLCheckError();
+			hnm->work_buffer[1] = 0;
+		}
+	}
+fin:;
+	CLEndCheck;
+}
+
+void CLHNM_DeallocMemory(hnm_t *hnm)
+{
+	CLBeginCheck;
+	if(hnm->work_buffer[0])
+	{
+		CLMemory_Free(hnm->work_buffer[0]);
+		CLCheckError();
+		hnm->work_buffer[0] = 0;
+	}
+	if(hnm->work_buffer[1])
+	{
+		CLMemory_Free(hnm->work_buffer[1]);
+		CLCheckError();
+		hnm->work_buffer[1] = 0;
+	}
+
+	if(!use_preload)
+	{
+		if(hnm->read_buffer)
+		{
+			CLMemory_Free(hnm->read_buffer);
+			CLCheckError();
+			hnm->read_buffer = 0;
+		}
+	}
+
+	CLEndCheck;
+}
+
+void CLHNM_Read(hnm_t *hnm, int size)
+{
+	long _size = size;
+	if(!use_preload)
+	{
+		CLFile_Read(*hnm->file, hnm->read_buffer, &_size);
+	}
+	else
+	{
+	}
+}
+
+void CLHNM_GiveTime(hnm_t *hnm)
+{
+	if(use_preload)
+	{
+		//stuff preload_buffer from disk
+	}
+}
+
+void CLHNM_CanLoop(hnm_t *hnm, short can_loop)
+{
+	hnm->can_loop = can_loop;
+}
+
+void CLHNM_SelectBuffers(hnm_t *hnm)
+{
+	if(hnm->frame % 2)
+	{
+		hnm->new_frame_buffer = hnm->work_buffer[1];
+		hnm->old_frame_buffer = hnm->work_buffer[0];
+	}
+	else
+	{
+		hnm->new_frame_buffer = hnm->work_buffer[0];
+		hnm->old_frame_buffer = hnm->work_buffer[1];
+	}
+}
+
+void CLHNM_ChangePalette(hnm_t *hnm)
+{
+	short mincolor, maxcolor;
+	unsigned short fst, cnt;
+	unsigned char *pal;
+	color_t *color;
+	CLPalette_GetLastPalette(hnm->palette);
+	pal = hnm->data_ptr;
+	if(*(unsigned short*)pal == 0xFFFF)
+		return;
+	mincolor = 255;
+	maxcolor = 0;
+	do
+	{
+		fst = *pal++;
+		cnt = *pal++;
+		if(cnt == 0)
+			cnt = 256;
+		debug("hnm: setting palette, fst = %d, cnt = %d, last = %d", fst, cnt, fst + cnt - 1);
+		assert(fst + cnt <= 256);
+		if (mincolor > fst)
+			mincolor = fst;
+		if(maxcolor < fst + cnt)
+			maxcolor = fst + cnt;
+		color = hnm->palette + fst;
+		if(safe_palette)
+		{
+			while(cnt--)
+			{
+				unsigned char r = *pal++;
+				unsigned char g = *pal++;
+				unsigned char b = *pal++;
+				short rr = r << 10;
+				short gg = g << 10;
+				short bb = b << 10;
+				if(color->r != rr || color->g != gg || color->b != bb)
+					CLBlitter_OneBlackFlash();
+				color->r = rr;
+				color->g = gg;
+				color->b = bb;
+				color++;
+			}
+		}
+		else
+		{
+			while(cnt--)
+			{
+				unsigned char r = *pal++;
+				unsigned char g = *pal++;
+				unsigned char b = *pal++;
+				color->r = r << 10;
+				color->g = g << 10;
+				color->b = b << 10;
+				color++;
+			}
+		}
+		
+	}
+	while(*(unsigned short*)pal != 0xFFFF);
+#if 0
+	if(preserve_color0)
+	{
+		hnm->palette[0].r = 0;
+		hnm->palette[0].g = 0;
+		hnm->palette[0].b = 0;
+	}
+#endif
+//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);	
+	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);	
+}
+
+void CLHNM_Desentrelace(hnm_t *hnm)
+{
+	switch(hnm->header.width)
+	{
+	case 320:
+		CLHNM_Desentrelace320(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+		CLNoError;
+		break;
+//	case 480:
+//		CLHNM_Desentrelace480(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//		CLNoError;
+//		break;
+	default:
+		__libError = -5;
+		__osError = 0;
+		CLCheckError();
+	}
+}
+
+void CLHNM_FlushPreloadBuffer(hnm_t *hnm)
+{
+	if(use_preload)
+	{
+	}
+}
+
+soundchannel_t* CLHNM_GetSoundChannel()
+{
+	return soundChannel;
+}
+
+
+void CLHNM_TryRead(hnm_t *hnm, int size)
+{
+	short err;
+	do
+	{
+		CLHNM_Read(hnm, size);
+		err = __libError == -6;
+		if(err)
+			CLHNM_GiveTime(hnm);
+	}
+	while(err);
+}
+
+void CLHNM_ResetInternalTimer()
+{
+	time_drift = 0.0;
+	next_frame_time = expected_frame_time = TimerTicks;
+}
+
+void CLHNM_Reset(hnm_t *hnm)
+{
+	hnm->frame = 0;
+	hnm->ff_4 = 0;
+	hnm->total_read = 0;
+	sound_started = 0;
+	pending_sounds = 0;
+	CLHNM_ResetInternalTimer();
+	CLNoError;
+}
+
+short CLHNM_LoadFrame(hnm_t *hnm)
+{
+	int chunk;
+	CLBeginCheck;
+	CLHNM_TryRead(hnm, 4);
+	CLEndCheck;
+	chunk = *(int*)hnm->read_buffer;
+	chunk = LE32(chunk);
+	chunk &= 0xFFFFFF;	// upper bit - keyframe mark?
+	if(!chunk)
+		return 0;
+		
+	if(use_preload)
+	{
+	}
+	else
+	{
+		if(chunk - 4 > hnm->header.buffersize)
+		{
+			__libError = -3;
+			__osError = 0;
+			CLCheckError();
+		}
+		else
+		if(use_preload && chunk - 4 > 102400)
+		{
+			__libError = -3;
+			__osError = 0;
+			CLCheckError();
+		}
+	}
+	CLBeginCheck;
+	CLHNM_TryRead(hnm, chunk - 4);
+	CLEndCheck;
+	hnm->data_ptr = hnm->read_buffer;
+	hnm->total_read += chunk;
+	return 1;
+}
+
+void CLHNM_WantsSound(short sound)
+{
+	use_sound = sound;
+}
+
+void CLHNM_LoadDecompTable(short *buffer)
+{
+	short i;
+	short e;
+	for(i = 0;i < 256;i++)
+	{
+		e = *buffer++;
+		decomp_table[i] = LE16(e);
+	}
+}
+
+void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size)
+{
+	short l = pred_l, r = pred_r;
+	size &= ~1;
+	while(size--)
+	{
+		*output++ = l += decomp_table[*buffer++];
+		*output++ = r += decomp_table[*buffer++];
+		if(l > 512 || r > 512)
+			DebugStr(" coucou");
+	}
+	pred_l = l;
+	pred_r = r;
+}
+
+void CLHNM_SoundInADPCM(short is_adpcm)
+{
+	use_adpcm = is_adpcm;
+}
+
+void CLHNM_SoundMono(short is_mono)
+{
+	use_mono = is_mono;
+}
+
+short CLHNM_NextElement(hnm_t *hnm)
+{
+	int sz;
+	short id;
+	char h6, h7;
+	short i;
+	if(hnm->frame == 0)
+	{
+		CLHNM_ResetInternalTimer();
+		pred_l = pred_r = 0;
+	}
+	if(hnm->frame == hnm->header.nframe)
+		return 0;
+	if(!CLHNM_LoadFrame(hnm))
+		return 0;
+	for(;;)
+	{
+		sz = PLE32(hnm->data_ptr) & 0xFFFFFF; hnm->data_ptr += 4;
+		id = *(short*)hnm->data_ptr; hnm->data_ptr += 2;
+		h6 = *hnm->data_ptr; hnm->data_ptr += 1;
+		h7 = *hnm->data_ptr; hnm->data_ptr += 1;
+		hnm->chunk_id = id;
+		switch(id)
+		{
+		case BE16('PL'):
+			CLHNM_ChangePalette(hnm);
+			hnm->data_ptr += sz - 8;
+			break;
+		case BE16('IZ'):
+			hnm->frame++;
+			CLHNM_SelectBuffers(hnm);
+			CLHNM_DecompLempelZiv(hnm->data_ptr + 4, hnm->new_frame_buffer);
+			switch(hnm->header.width)
+			{
+//			case 320: CLBlitter_RawCopy320ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			case 480: CLBlitter_RawCopy480ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			case 640: CLBlitter_RawCopy640ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);	//TODO strange buffer size here
+			}
+			if(!(h6 & 1))
+				CLHNM_Desentrelace(hnm);
+			else
+			{
+//				if(hnm->header.width == 640)
+//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//				else
+					memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);	//TODO: wrong size?
+			}
+			if(use_adpcm)
+			{
+				if(!sound_started)
+				{
+					for(i = 0;i < pending_sounds;i++)
+						CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
+					sound_started = 1;
+				}
+			}
+			else
+			{
+				if(!sound_started)
+				{
+					for(i = 0;i < pending_sounds;i++)
+						CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
+					sound_started = 1;
+				}
+			}
+			goto end_frame;
+		case BE16('IU'):
+			hnm->frame++;
+			CLHNM_SelectBuffers(hnm);
+			CLHNM_DecompUBA(hnm->new_frame_buffer, hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->data_ptr, hnm->header.width, h6);
+			if(!(h6 & 1))
+				CLHNM_Desentrelace(hnm);
+			else
+			{
+//				if(hnm->header.width == 640)
+//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//				else
+					memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+			}
+			goto end_frame;
+		case BE16('sd'):
+		case BE16('SD'):
+			if(use_sound)
+			{
+				if(!h6)
+				{
+					int sound_size = sz - 8;
+					if(!use_adpcm)
+					{
+						CLSoundGroup_SetDatas(soundGroup, hnm->data_ptr, sound_size - 2, 0);
+						if(sound_started)
+							CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
+						else
+							pending_sounds++;
+					}
+					else
+					{
+						short *sound_buffer = (short*)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
+						if(!pending_sounds)
+						{
+							const int kDecompTableSize = 256 * sizeof(short);
+							CLHNM_LoadDecompTable((short*)hnm->data_ptr);
+							CLHNM_DecompADPCM(hnm->data_ptr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize);
+							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, 0);
+						}
+						else
+						{
+							CLHNM_DecompADPCM(hnm->data_ptr, sound_buffer, sound_size);
+							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, sound_size * 2, 0);
+						}
+						pending_sounds++;
+						if(sound_started)
+							CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
+					}
+				}
+				else
+				{
+					__libError = -3;
+					__osError = 0;
+					CLCheckError();
+				}
+			}
+			hnm->data_ptr += sz - 8;
+			break;
+		default:
+			if(custom_chunk_handler)
+				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7); 
+			hnm->data_ptr += sz - 8;
+		}
+	}
+end_frame:;
+	if(use_preload)
+	{
+	}
+	return 1;
+}
+
+void CLHNM_ReadHeader(hnm_t *hnm)
+{
+	CLBeginCheck;
+	if(!use_preload)
+	{
+		long size = sizeof(hnm->header);
+		CLFile_Read(*hnm->file, &hnm->header, &size);
+	}
+	else
+		;
+	CLCheckError();
+	CLEndCheck;
+	hnm->header.width = LE16(hnm->header.width);
+	hnm->header.height = LE16(hnm->header.height);
+	hnm->header.filesize = LE32(hnm->header.filesize);
+	hnm->header.nframe = LE32(hnm->header.nframe);
+	hnm->header.table_offset = LE32(hnm->header.table_offset);
+	hnm->header.speed = LE16(hnm->header.speed);
+	hnm->header.maxbuffer = LE16(hnm->header.maxbuffer);
+	hnm->header.buffersize = LE32(hnm->header.buffersize);
+	hnm->header.ff_20 = LE16(hnm->header.ff_20);
+	hnm->header.buffersize += 4096;	//TODO: checkme
+}
+
+short CLHNM_GetVersion(hnm_t *hnm)
+{
+	CLNoError;
+	if(hnm->header.id == BE32('HNM4'))
+		return 4;
+	return -1;
+}
+
+int CLHNM_GetFrameNum(hnm_t *hnm)
+{
+	return hnm->frame;
+}
+
+void CLHNM_DeactivatePreloadBuffer()
+{
+	use_preload = 0;
+}
+
+void CLHNM_Prepare2Read(hnm_t *hnm, int mode)
+{
+	if(use_preload)
+	{
+	}
+}
+
+void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos)
+{
+	CLFile_SetPosition(*hnm->file, 1, pos);
+}
+
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height)
+{
+	unsigned int *input = (unsigned int*)frame_buffer;
+	unsigned int *line0 = (unsigned int*)final_buffer;
+	unsigned int *line1 = (unsigned int*)(final_buffer + 320);
+	int count = (height) / 2;
+	while(count--)
+	{
+		short i;
+		for(i = 0;i < 320 / 4;i++)
+		{
+			unsigned int p0 = *input++;
+			unsigned int p4 = *input++;
+#if 0
+			*line0++ = ((p4 & 0xFF00) >> 8) | ((p4 & 0xFF000000) >> 16) | ((p0 & 0xFF00) << 8) | (p0 & 0xFF000000);
+//			*line0++ = (p0 & 0xFF000000) | ((p0 & 0xFF00) << 8) | ((p4 & 0xFF000000) >> 16) | ((p4 & 0xFF00) >> 8);
+			*line1++ = ((p0 & 0xFF0000) << 8) | ((p0 & 0xFF) << 16) | ((p4 & 0xFF0000) >> 8) | (p4 & 0xFF);
+#else
+			*line0++ = (p0 & 0xFF) | ((p0 & 0xFF0000) >> 8) | ((p4 & 0xFF) << 16) | ((p4 & 0xFF0000) << 8);
+			*line1++ = ((p0 & 0xFF00) >> 8) | ((p0 & 0xFF000000) >> 16) | ((p4 & 0xFF00) << 8) | (p4 & 0xFF000000);
+#endif
+		}
+		line0 += 320 / 4;
+		line1 += 320 / 4;
+	}
+}
diff --git a/engines/cryo/CLSouNdRaw.c b/engines/cryo/CLSouNdRaw.c
new file mode 100644
index 0000000..22bc908
--- /dev/null
+++ b/engines/cryo/CLSouNdRaw.c
@@ -0,0 +1,57 @@
+#include "cryolib.h"
+
+sound_t* CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode)
+{
+	sound_t *sound;
+	CLBeginCheck;
+	
+	sound = (sound_t*)CLMemory_Alloc(sizeof(*sound));
+	if(sound)
+	{
+		sound->ff_1A = arg1;
+		sound->rate = rate;
+		sound->sampleSize = sampleSize;
+		sound->buffer = 0;
+//		sound->sndHandle = CLMemory_AllocHandle(arg1 + 100);
+//		if(!sound->sndHandle)
+//		{
+//			__libError = -1;
+//			__osError = MemError();
+//			CLCheckError();
+//		}
+//		else
+		{
+			CLSound_PrepareSample(sound, mode);
+			CLNoError;
+		}
+	}
+	else
+	{
+		__libError = -1;
+		__osError = MemError();
+		CLCheckError();
+	}
+	
+	CLEndCheck;
+	return sound;
+}
+
+void CLSoundRaw_Free(sound_t *sound)
+{
+	while(sound->locked) ;
+//	CLMemory_FreeHandle(sound->sndHandle);
+	CLMemory_Free(sound);
+}
+
+void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length)
+{
+	char *buf;
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+	buf = bufferOffs + (char*)buffer;
+//	if(CLSound_GetWantsDesigned())
+//		CLSound_Signed2NonSigned(buf, length);
+	sound->buffer = buf;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buf, length);
+}
diff --git a/engines/cryo/CryoLib.h b/engines/cryo/CryoLib.h
new file mode 100644
index 0000000..5fe3e8c
--- /dev/null
+++ b/engines/cryo/CryoLib.h
@@ -0,0 +1,181 @@
+#pragma once
+#define SW16(n) ( (((n) & 0xFF) << 8) | (((n) >> 8) & 0xFF) )
+#define SW32(n) ( (((n) & 0xFF) << 24) | (((n) >> 24) & 0xFF) | (((n) & 0xFF00) << 8) | (((n) >> 8) & 0xFF00))
+#if 0
+//big-endian host
+#define LE16(n) SW16(n)
+#define LE32(n) SW32(n)
+#define BE16(n) (n)
+#define BE32(n) (n)
+#else
+//little-endian host
+#define LE16(n) (n)
+#define LE32(n) (n)
+#define BE16(n) SW16(n)
+#define BE32(n) SW32(n)
+#endif
+#define PLE16(p) ( (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
+#define PLE32(p) ( (((unsigned char*)(p))[3] << 24) | (((unsigned char*)(p))[2] << 16) | (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
+
+#include "audio/mixer.h"
+
+typedef void *SndChannel;
+typedef char *Handle;
+enum {
+	fsFromStart = 1
+};
+
+extern short __debug2;
+
+extern short __debug, __libError, __osError;
+
+#define CLBeginCheck	{ short __oldDebug = __debug; __debug = -1;
+#define CLEndCheck		__debug = __oldDebug; }
+#define CLNoError		__libError = 0;
+
+#define CLCheckError() if(__debug && __libError){	\
+	char buffer[260];			\
+	sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);	\
+	DebugStr(c2pstr(buffer));	\
+	};
+
+#define CLAssert(x) if(!(x)) {	\
+	char buffer[260];			\
+	sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);	\
+	DebugStr(c2pstr(buffer));	\
+	};
+
+struct rect_t {
+int	sy, sx, ey, ex;
+};
+typedef struct rect_t rect_t;
+
+struct view_t {
+unsigned char	*p_buffer;
+int		width;
+int		height;
+short	pitch;
+short	doubled;
+short	allocated;
+struct {
+int		src_left;
+int		src_top;
+int		dst_left;
+int		dst_top;
+int		width;
+int		height;
+} norm, zoom;
+};
+typedef struct view_t view_t;
+
+struct color3_t {
+short	r, g, b;
+};
+typedef struct color3_t color3_t;
+
+struct color_t {
+short	a, r, g, b;
+};
+typedef struct color_t color_t;
+
+struct palette_t {
+color_t	colors[256];
+};
+typedef struct palette_t palette_t;
+
+#pragma pack(push, 1)
+struct hnmheader_t {
+int				id;
+char			flag1;
+char			flag2;
+char			reseverd;
+char			bpp;
+unsigned short	width;
+unsigned short	height;
+int				filesize;
+int				nframe;
+int				table_offset;
+short			speed;
+short			maxbuffer;
+int				buffersize;
+short			ff_20;
+char			reserved2[14];
+char			copyright[16];
+};
+typedef struct hnmheader_t hnmheader_t;
+#pragma pack(pop)
+
+struct hnm_t {
+int				frame;
+int				ff_4;
+file_t*			file;
+hnmheader_t		header;
+unsigned char	*work_buffer[2];
+unsigned char	*final_buffer;
+unsigned char	*new_frame_buffer;
+unsigned char	*old_frame_buffer;
+unsigned char	*read_buffer;
+unsigned char	*data_ptr;
+color_t			palette[256];
+
+short			can_loop;
+
+short			ff_896;
+short			chunk_id;
+int				total_read;
+};
+typedef struct hnm_t hnm_t;
+
+//struct filespec_t {
+//char	puff;
+//};
+
+struct sound_t {
+Handle	sndHandle;
+short	headerLen;
+long	headerOffset;
+short	ff_A;
+
+char	*buffer;
+int		ff_16;
+short	ff_1A;
+float	rate;
+short	sampleSize;
+int		length;
+short	mode;
+volatile short	locked;
+long	loopStart;
+short	loopTimes;
+short	reversed;
+short	ff_32;
+short	volume;
+};
+typedef struct sound_t sound_t;
+
+#define CL_MAX_SOUNDS 64
+
+struct soundgroup_t {
+sound_t	*sound[CL_MAX_SOUNDS];
+short	numSounds;
+short	soundIndex;
+short	playIndex;
+short	ff_106;
+};
+typedef struct soundgroup_t soundgroup_t;
+
+#define CL_MAX_CH_SOUNDS 10
+
+struct soundchannel_t {
+Audio::SoundHandle ch;
+int		xx;
+
+short	volumeLeft;
+short	volumeRight;
+short	numSounds;
+
+sound_t	*sounds[CL_MAX_CH_SOUNDS];
+
+short	ff_536;
+};
+typedef struct soundchannel_t soundchannel_t;
+
diff --git a/engines/cryo/CryoLibStub.c b/engines/cryo/CryoLibStub.c
new file mode 100644
index 0000000..cabf2b5
--- /dev/null
+++ b/engines/cryo/CryoLibStub.c
@@ -0,0 +1,604 @@
+
+	///// Mac APIs
+	typedef short OSErr;
+
+	short MemError()
+	{
+		return 0;
+	}
+
+	void SysBeep(int x)
+	{
+	}
+
+	OSErr SetFPos(short handle, short mode, long pos)
+	{
+		return 0;
+	}
+
+	OSErr FSRead(short handle, long *size, void *buffer)
+	{
+		return 0;
+	}
+
+	void FlushEvents(short arg1, short arg2)
+	{
+	}
+
+	char* c2pstr(char *s)
+	{
+		return s;
+	}
+
+	void DebugStr(char *s)
+	{
+	}
+
+	// from mw lib???
+	long TickCount()
+	{
+		return g_system->getMillis();
+	}
+
+	///// CLMemory
+	void* CLMemory_Alloc(int size)
+	{
+		return malloc(size);
+	}
+	void CLMemory_Free(void *ptr)
+	{
+		//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
+		if (!ptr)
+			return;
+
+		free(ptr);
+	}
+
+
+	///// CLTimer
+	volatile long TimerTicks = 0;	// incremented in realtime
+
+	///// CLView
+	void CLView_SetSrcZoomValues(view_t *view, int x, int y)
+	{
+		view->zoom.src_left = x;
+		view->zoom.src_top = y;
+	}
+	void CLView_SetDisplayZoomValues(view_t *view, int w, int h)
+	{
+		view->zoom.width = w;
+		view->zoom.height = h;
+	}
+	void CLView_Free(view_t *view)
+	{
+		if (view->p_buffer && view->allocated)
+			CLMemory_Free(view->p_buffer);
+		if (view)
+			CLMemory_Free(view);
+	}
+	void CLView_InitDatas(view_t *view, int w, int h, void *buffer)
+	{
+		view->p_buffer = (unsigned char*)buffer;
+		view->width = w;
+		view->height = h;
+		view->pitch = w;
+		view->doubled = 0;
+		view->norm.src_left = 0;
+		view->norm.src_top = 0;
+		view->norm.dst_left = 0;
+		view->norm.dst_top = 0;
+		view->norm.width = w;
+		view->norm.height = h;
+		view->zoom.src_left = 0;
+		view->zoom.src_top = 0;
+		view->zoom.dst_left = 0;
+		view->zoom.dst_top = 0;
+		view->zoom.width = w;
+		view->zoom.height = h;
+	}
+	view_t* CLView_New(int w, int h)
+	{
+		view_t *view = (view_t*)CLMemory_Alloc(sizeof(view_t));
+		if (view)
+		{
+			void *buffer = (unsigned char*)CLMemory_Alloc(w * h);
+			if (buffer)
+			{
+				view->allocated = 1;
+				CLView_InitDatas(view, w, h, buffer);
+			}
+			else
+			{
+				CLMemory_Free(view);
+				view = 0;
+			}
+		}
+		return view;
+	}
+	void CLView_CenterIn(view_t *parent, view_t *child)
+	{
+		child->norm.dst_left = (parent->width - child->norm.width) / 2;
+		child->norm.dst_top = (parent->height - child->norm.height) / 2;
+		child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
+		child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
+	}
+
+	///// CLScreenView
+	view_t ScreenView;
+
+	void CLScreenView_Init()
+	{
+		// ScreenView is the game's target screen (a pc display)
+		// we use a dedicated surface for it, which at some point will be
+		// presented to user by System::copyRectToScreen call
+		CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
+	}
+
+	void CLScreenView_CenterIn(view_t *view)
+	{
+		CLView_CenterIn(&ScreenView, view);
+	}
+
+	///// CLPalette
+	unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
+	short gMacintize = 0;
+	color_t black_palette[256];
+	color_t last_palette[256];
+	void CLPalette_Init()
+	{
+		short i;
+		for (i = 0; i < 256; i++)
+			black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
+	}
+	void CLPalette_SetLastPalette(color_t *palette, short first, short count)
+	{
+		short i;
+		for (i = first; i < first + count; i++)
+			last_palette[i] = palette[i];
+	}
+	void CLPalette_GetLastPalette(color_t *palette)
+	{
+		short i;
+		for (i = 0; i < 256; i++)
+			palette[i] = last_palette[i];
+	}
+	void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb)
+	{
+		palette[index].r = rgb->r;
+		palette[index].g = rgb->g;
+		palette[index].b = rgb->b;
+		palette[index].a = 0;
+	}
+	void CLPalette_Macintize(short macintize)
+	{
+		gMacintize = macintize;
+	}
+	void CLPalette_SetInterval(unsigned short first, unsigned short last)
+	{
+		gIntervalFirst = first;
+		gIntervalSet = 1;
+		gIntervalLast = last;
+	}
+	void CLPalette_DeactivateInterval()
+	{
+		gIntervalSet = 0;
+	}
+	void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count)
+	{
+		OSErr err;
+		short i;
+		if (gMacintize)
+		{
+			palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
+			palette[255].r = palette[255].g = palette[255].b = 0;
+		}
+		if (gIntervalSet)
+		{
+			if (first < gIntervalFirst)
+				first = gIntervalFirst;
+			if (first + count > gIntervalLast)
+				count = gIntervalLast - first;
+		}
+
+		byte buffer[256 * 3];
+		for (i = 0; i < 256; i++)
+		{
+			buffer[i * 3] = palette[i].r >> 8;
+			buffer[i * 3 + 1] = palette[i].g >> 8;
+			buffer[i * 3 + 2] = palette[i].b >> 8;
+		}
+
+		g_system->getPaletteManager()->setPalette(buffer, first, count);
+		g_system->updateScreen();
+
+		CLPalette_SetLastPalette(palette, first, count);
+	}
+	void CLPalette_BeBlack()
+	{
+		CLPalette_Send2Screen(black_palette, 0, 256);
+	}
+	void CLPalette_BeSystem()
+	{
+	}
+
+	///// CLBlitter
+	static unsigned short newPaletteCount, newPaletteFirst;
+	static color_t *pNewPalette;
+	static unsigned short useNewPalette;
+
+	void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2)
+	{
+		int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
+		//	debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
+		//		rect1->sx, rect1->sy, rect1->ex, rect1->ey,
+		//		rect2->sx, rect2->sy, rect2->ex, rect2->ey,
+		//		(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
+		assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
+		for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++)
+		{
+			unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
+			unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
+			for (x = 0; x < w; x++)
+				*d++ = *s++;
+		}
+	}
+	void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count)
+	{
+		pNewPalette = palette;
+		useNewPalette = 1;
+		newPaletteFirst = first;
+		newPaletteCount = count;
+	}
+	void CLBlitter_OneBlackFlash()
+	{
+	}
+	void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
+		unsigned char *dst, short dstw, short dstp, short dsth)
+	{
+		short x, y;
+		for (y = 0; y < srch; y++)
+		{
+			for (x = 0; x < srcw; x++)
+				*dst++ = *src++;
+			src += srcp - srcw;
+			dst += dstp - dstw;
+		}
+	}
+	void CLBlitter_CopyView2ScreenCUSTOM(view_t *view)
+	{
+		view_t *dest = &ScreenView;
+		if (!view->doubled)
+		{
+			short srcpitch = view->pitch;
+			short dstpitch = dest->pitch;
+
+			//		this is not quite correct?
+			//		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+			//			dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+			CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+				dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+		}
+		else
+		{
+			assert(0);
+		}
+	}
+	void CLBlitter_CopyView2Screen(view_t *view)
+	{
+
+		if (useNewPalette)
+		{
+			color_t palette[256];
+			CLPalette_GetLastPalette(palette);
+			CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
+			useNewPalette = 0;
+		}
+
+		//TODO: quick hack to force screen update
+		if (view)
+			CLBlitter_CopyView2ScreenCUSTOM(view);
+
+		g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
+		g_system->updateScreen();
+	}
+	void CLBlitter_UpdateScreen()
+	{
+		CLBlitter_CopyView2Screen(nullptr);
+	}
+	void CLBlitter_FillView(view_t *view, unsigned int fill)
+	{
+		short x, y;
+		unsigned char *d = view->p_buffer;
+		assert((fill & 0xFF) * 0x01010101 == fill);
+		for (y = 0; y < view->height; y++)
+		{
+			for (x = 0; x < view->width; x++)
+				*d++ = fill;
+			d += view->pitch - view->width;
+		}
+	}
+	void CLBlitter_FillScreenView(unsigned int fill)
+	{
+		CLBlitter_FillView(&ScreenView, fill);
+	}
+
+
+	///// events wrapper
+	int _mouseButton;
+	byte _keyState[256];
+
+	void pollEvents()
+	{
+		g_system->delayMillis(10);
+
+		Common::Event event;
+		while (g_system->getEventManager()->pollEvent(event)) {
+			// Handle keypress
+			switch (event.type) {
+			case Common::EVENT_QUIT:
+			case Common::EVENT_RTL:
+				return;
+
+			case Common::EVENT_KEYDOWN:
+				//			_keyState[(byte)toupper(event.kbd.ascii)] = true;
+				return;
+			case Common::EVENT_KEYUP:
+				//			_keyState[(byte)toupper(event.kbd.ascii)] = false;
+				return;
+			case Common::EVENT_LBUTTONDOWN:
+				_mouseButton = 1;
+				return;
+			case Common::EVENT_RBUTTONDOWN:
+				_mouseButton = 2;
+				return;
+			case Common::EVENT_LBUTTONUP:
+			case Common::EVENT_RBUTTONUP:
+				_mouseButton = 0;
+				return;
+			default:
+				break;
+			}
+		}
+	}
+
+
+	///// CLKeyboard
+	short CLKeyboard_HasCmdDown()
+	{
+		return 0;
+	}
+	void CLKeyboard_Read()
+	{
+		pollEvents();
+	}
+	unsigned char CLKeyboard_GetLastASCII()
+	{
+		return 0;
+	}
+	short CLKeyboard_IsScanCodeDown(short scancode)
+	{
+		return 0;
+	}
+
+	///// CLMouse
+	void CLMouse_Hide()
+	{
+	}
+	void CLMouse_Show()
+	{
+	}
+	void CLMouse_GetPosition(short *x, short *y)
+	{
+		*x = g_system->getEventManager()->getMousePos().x;
+		*y = g_system->getEventManager()->getMousePos().y;
+	}
+	void CLMouse_SetPosition(short x, short y)
+	{
+		g_system->warpMouse(x, y);
+	}
+	unsigned short CLMouse_IsDown()
+	{
+		pollEvents();
+		return _mouseButton != 0;
+	}
+
+	///// CLFile
+	void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7)
+	{
+	}
+	void CLFile_SetFinderInfos(void *fs, int a4, int a5)
+	{
+	}
+	void CLFile_GetFullPath(void *a3, char *a4)
+	{
+	}
+	void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs)
+	{
+		strcpy(fs->name, name);
+		fs->create = 0;
+	}
+	void CLFile_Create(filespec_t *fs)
+	{
+		fs->create = 1;
+	}
+	void CLFile_Open(filespec_t *fs, short mode, file_t& handle)
+	{
+		handle.open(fs->name);
+	}
+	void CLFile_Close(file_t& handle)
+	{
+		handle.close();
+	}
+	void CLFile_SetPosition(file_t& handle, short mode, long pos)
+	{
+		assert(mode == 1);
+		handle.seek(pos, 0);
+	}
+	void CLFile_Read(file_t& handle, void *buffer, long *size)
+	{
+		handle.read(buffer, *size);
+	}
+	void CLFile_Write(file_t& handle, void *buffer, long *size)
+	{
+		assert(0);
+	}
+
+	///// CLSound
+	// base sound
+	void CLSound_PrepareSample(sound_t *sound, short mode)
+	{
+		sound->mode = mode;
+		sound->locked = 0;
+		sound->loopTimes = 0;
+		sound->reversed = 0;
+		sound->ff_32 = 0;
+		sound->volume = 255;
+	}
+	void CLSound_SetWantsDesigned(short designed)
+	{
+	}
+	void CLSound_SetLength(sound_t *sound, int length)
+	{
+	}
+
+	///// CLSoundRaw
+	// sound from memory buffer
+#include "CLSouNdRaw.c"
+
+	///// CLSoundChannel
+	/// sound output device that plays queue of sounds
+	soundchannel_t* CLSoundChannel_New(int arg1)
+	{
+		short i;
+		soundchannel_t *ch = (soundchannel_t*)CLMemory_Alloc(sizeof(*ch));
+		if (!ch)
+			return 0;
+
+		ch->volumeLeft = ch->volumeRight = 255;
+		ch->numSounds = 0;
+
+		for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
+			ch->sounds[i] = 0;
+
+		return ch;
+	}
+	void CLSoundChannel_Free(soundchannel_t *ch)
+	{
+		CLMemory_Free(ch);
+	}
+	void CLSoundChannel_Stop(soundchannel_t *ch)
+	{
+		//	g_ed->_mixer->stopHandle(ch->ch);
+	}
+	void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound)
+	{
+	}
+	short CLSoundChannel_GetVolume(soundchannel_t *ch)
+	{
+		return (ch->volumeLeft + ch->volumeRight) / 2;
+	}
+	void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume)
+	{
+		if (volume < 0 || volume > 255)
+			return;
+		ch->volumeLeft = volume;
+		ch->volumeRight = volume;
+	}
+	void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume)
+	{
+		if (volume < 0 || volume > 255)
+			return;
+		ch->volumeRight = volume;
+	}
+	void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume)
+	{
+		if (volume < 0 || volume > 255)
+			return;
+		ch->volumeLeft = volume;
+	}
+
+	///// CLSoundGroup
+	/// a queue of sounds of same format
+#include "CLSoundGroup.c"
+
+	///// CLTimer
+	void CLTimer_Action(void *arg)
+	{
+		//	long& counter = *((long*)arg);
+		//	counter++;
+		TimerTicks++;
+	}
+
+	void CLTimer_Init()
+	{
+		g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
+	}
+
+	void CLTimer_Done()
+	{
+		g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
+	}
+
+	///// CRYOLib
+	void CRYOLib_InstallExitPatch()
+	{
+	}
+	void CRYOLib_RemoveExitPatch()
+	{
+	}
+	void CRYOLib_Init()
+	{
+	}
+	void CRYOLib_Done()
+	{
+	}
+	void CRYOLib_MinimalInit()
+	{
+	}
+	void CRYOLib_ManagersInit()
+	{
+		CLTimer_Init();
+		CLScreenView_Init();
+	}
+	void CRYOLib_ManagersDone()
+	{
+		CLTimer_Done();
+	}
+	void CRYOLib_SetDebugMode(short enable)
+	{
+	}
+	void CRYOLib_InstallEmergencyExit(void(*proc)())
+	{
+	}
+	void CRYOLib_SetupEnvironment()
+	{
+	}
+	void CRYOLib_RestoreEnvironment()
+	{
+	}
+	void CRYOLib_TestConfig()
+	{
+	}
+
+	///// CLComputer
+	short CLComputer_Has68030()
+	{
+		return 0;
+	}
+	short CLComputer_Has68040()
+	{
+		return 0;
+	}
+
+	///// CLDesktop
+	void CLDesktop_TestOpenFileAtStartup()
+	{
+	}
+
+	///// CLHNM
+#include "CLHNM.c"
+
+	///// CLError
+#include "CLError.c"
diff --git a/engines/cryo/LempelZiv.cpp b/engines/cryo/LempelZiv.cpp
new file mode 100644
index 0000000..6020c96
--- /dev/null
+++ b/engines/cryo/LempelZiv.cpp
@@ -0,0 +1,7 @@
+#include "LempelZiv.h"
+
+namespace Cryo {
+
+
+
+}
\ No newline at end of file
diff --git a/engines/cryo/LempelZiv.h b/engines/cryo/LempelZiv.h
new file mode 100644
index 0000000..636d7af
--- /dev/null
+++ b/engines/cryo/LempelZiv.h
@@ -0,0 +1,102 @@
+#pragma once
+
+namespace Cryo {
+
+	class BitReaderBase {
+	public:
+		unsigned char *_data;	//NB! never override this - used by decompressor
+		unsigned int _queue;
+		unsigned int _queueLeft;
+	public:
+		BitReaderBase(void *data, unsigned int dataSize = 0)
+		{
+			_data = static_cast<unsigned char*>(data);
+			_queue = _queueLeft = 0;
+		}
+
+		unsigned char GetBit()
+		{
+			return 0;	// to be overriden
+		}
+	};
+
+	// used to decompress HSQ files
+	class BitReader16 : BitReaderBase {
+	public:
+		unsigned char GetBit()
+		{
+			if (!_queueLeft)
+			{
+				_queue = (_data[1] << 8) | _data[0];
+				_data += 2;
+				_queueLeft += 16;
+			}
+			unsigned char bit = _queue & 1;
+			_queue >>= 1;
+			_queueLeft--;
+			return bit;
+		}
+	};
+
+	// used by HNM decoder
+	class BitReader32 : BitReaderBase {
+	public:
+		unsigned char GetBit()
+		{
+			if (!_queueLeft)
+			{
+				_queue = (_data[3] << 24) | (_data[2] << 16) | (_data[1] << 8) | _data[0];
+				_data += 4;
+				_queueLeft += 32;
+			}
+			unsigned char bit = (_queue >> (_queueLeft - 1)) & 1;
+			_queueLeft--;
+			return bit;
+		}
+	};
+
+	template <class BitReader>
+	class LempelZivBase : BitReader
+	{
+	public:
+		LempelZivBase(void *input, unsigned int inputSize) : BitReader(input, inputSize)
+
+		unsigned int UnpackBuffer(void *output, unsigned int maxOutputSize)
+		{
+			unsigned char *out = static_cast<unsigned char*>(output);
+			for (;;)
+			{
+				if (GetBit())
+				{
+					*out++ = *_data++;
+				}
+				else
+				{
+					int length, offset;
+					if (GetBit())
+					{
+						length = *_data & 7;
+						offset = ((_data[1] << 8) | _data[0]) >> 3; _data += 2;
+						offset -= 8192;
+						if (!length)
+							length = *_data++;
+						if (!length)
+							break;
+					}
+					else
+					{
+						length = GetBit() * 2 + GetBit();
+						offset = *(_data++) - 256;
+					}
+					length += 2;
+					while (length--)
+					{
+						*out = *(out + offset); out++;
+					}
+				}
+			}
+			return out - static_cast<unsigned char*>(output);
+		}
+	};
+
+}
\ No newline at end of file
diff --git a/engines/cryo/ResourceManager.cpp b/engines/cryo/ResourceManager.cpp
new file mode 100644
index 0000000..7280443
--- /dev/null
+++ b/engines/cryo/ResourceManager.cpp
@@ -0,0 +1,116 @@
+#include "ResourceManager.h"
+
+namespace Cryo {
+
+	ResourceManager::ResourceManager()
+	{
+	}
+
+	ResourceManager::ResourceManager(const Common::String &datFileName)
+	{
+		LoadDatFile(datFileName);
+	}
+
+	ResourceManager::~ResourceManager()
+	{
+	}
+
+	bool ResourceManager::LoadDatFile(const Common::String &datFileName)
+	{
+		if (_datFile.isOpen())
+		{
+			_datFile.close();
+			_files.clear();
+		}
+
+		assert(_datFile.open(datFileName));
+
+		unsigned short numFiles = _datFile.readUint16LE();
+
+		for (unsigned short i = 0; i < numFiles; i++)
+		{
+			DatFileEntry entry;
+
+			_datFile.read(entry._name, sizeof(entry._name));
+			entry._size = _datFile.readUint32LE();
+			entry._offset = _datFile.readUint32LE();
+			entry._flag = _datFile.readByte();
+
+			_files.push_back(entry);
+		}
+
+		return true;
+	}
+
+	Common::SeekableReadStream *ResourceManager::GetFile(const Common::String &resName, unsigned int hintIndex)
+	{
+		// First, try raw disk file so we can support modding/patching
+
+		if (Common::File::exists(resName))
+		{
+			debug("Loading %s from disk", resName);
+
+			Common::File *resource = new Common::File();
+			resource->open(resName);
+			return resource;
+		}
+
+		// Look inside .dat file
+
+		if (_datFile.isOpen())
+		{
+			for (unsigned int i = hintIndex; i < _files.size(); i++)
+			{
+				if (!resName.compareToIgnoreCase(_files[i]._name))
+				{
+					debug("Loading %s from dat file", resName);
+					Common::SeekableSubReadStream *resource = new Common::SeekableSubReadStream(&_datFile, _files[i]._offset, _files[i]._offset + _files[i]._size);
+					return resource;
+				}
+			}
+		}
+
+		debug("Unable to load %s - does't exists", resName);
+		return nullptr;
+	}
+
+	Common::SeekableReadStream *ResourceManager::GetFile(unsigned int resIndex)
+	{
+		if (_files.size() > resIndex)
+		{
+			return GetFile(Common::String(_files[resIndex]._name), resIndex);
+		}
+
+		return nullptr;
+	}
+
+	void *ResourceManager::StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size)
+	{
+		if (!stream)
+			return nullptr;
+
+		unsigned int readSize = stream->size();
+		unsigned char *data = new unsigned char[readSize + 1];
+		readSize = stream->read(data, readSize);
+
+		if (size)
+			*size = readSize;
+		return data;
+	}
+
+	void* ResourceManager::GetData(const Common::String &resName, unsigned int *size)
+	{
+		Common::SeekableReadStream *resource = GetFile(resName);
+		void *data = StreamToBuffer(resource, size);
+		delete resource;
+		return data;
+	}
+
+	void* ResourceManager::GetData(int resIndex, unsigned int *size)
+	{
+		Common::SeekableReadStream *resource = GetFile(resIndex);
+		void *data = StreamToBuffer(resource, size);
+		delete resource;
+		return data;
+	}
+}
\ No newline at end of file
diff --git a/engines/cryo/ResourceManager.h b/engines/cryo/ResourceManager.h
new file mode 100644
index 0000000..1ef5776
--- /dev/null
+++ b/engines/cryo/ResourceManager.h
@@ -0,0 +1,77 @@
+#pragma once
+
+#include "common/array.h"
+#include "common/file.h"
+#include "common/fs.h"
+#include "common/str.h"
+#include "common/substream.h"
+#include "common/debug.h"
+
+namespace Cryo {
+
+	template<typename T>
+	class CryoArray {
+	private:
+		unsigned char *_data;
+		bool _ownData;
+		unsigned short ElementOffset(int num)
+		{
+			assert(_data && num < Count())
+			return (static_cast<unsigned short*>_data)[num];
+		}
+	public:
+		CryoArray(void* data, bool ownData) : _data(data), _ownData(ownData)
+		{
+		}
+		~CryoArray()
+		{
+			if (_ownData)
+				delete data;
+		}
+		unsigned short Count()
+		{
+			return ElementOffset(0) / 2;
+		}
+		const T* operator[](int index)
+		{
+			return static_cast<T*>(_data + ElementOffset(num));
+		}
+	};
+
+	class ResourceManager
+	{
+	private:
+		struct DatFileEntry {
+			char _name[16];
+			unsigned int _size;
+			unsigned int _offset;
+			unsigned char _flag;
+		};
+
+		Common::Array<DatFileEntry> _files;
+		Common::File _datFile;
+
+		static void *StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size);
+
+	public:
+		ResourceManager(const Common::String &datFileName);
+		ResourceManager();
+		~ResourceManager();
+
+		bool LoadDatFile(const Common::String &datFileName);
+
+		// Load resource as a seekable stream
+		Common::SeekableReadStream *GetFile(const Common::String &resName, unsigned int hintIndex = 0);
+		Common::SeekableReadStream *GetFile(unsigned int resIndex);
+
+		// Load resource as a buffer
+		void* GetData(const Common::String &resName, unsigned int *size = nullptr);
+		void* GetData(int resIndex, unsigned int *size = nullptr);
+		void* operator[](int resIndex)
+		{
+			return GetData(resIndex);
+		}
+
+	};
+
+}
\ No newline at end of file
diff --git a/engines/cryo/bugs.txt b/engines/cryo/bugs.txt
new file mode 100644
index 0000000..50b857e
--- /dev/null
+++ b/engines/cryo/bugs.txt
@@ -0,0 +1,10 @@
+
+1. Open menu and replay last dialog, then press stop. hover over buttons - hint text will be misplaced
+2. During valley location change some junk appears in the bottom half of screen for a brief time (broken transition effect?)
+3. Transitions often show a lot of red colors (bad palette fadein/out?)
+4. After game load in some areas (White Arch) top bar and inventory not redrawn due to (DrawFlags?) initialized incorrectly
+5. Mac reload feature uses hardcoded savefile from eden.dat
+6. First time in Tau's cave, try to take knife. When Dina objects, click on her - Tau's dialog will start (maybe it's original bug?)
+7. Mouse clipping may be lost during FMV scenes
+8. Screen doubling feature probably doesn't work (not really needed, can be replaced with built-in SCUMMVM scaler)
+9. Tons of debug messages spam when hover mouse over party icons or menu buttons
diff --git a/engines/cryo/clsoundgroup.c b/engines/cryo/clsoundgroup.c
new file mode 100644
index 0000000..ae347fc
--- /dev/null
+++ b/engines/cryo/clsoundgroup.c
@@ -0,0 +1,117 @@
+#include "cryolib.h"
+
+soundgroup_t* CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode)
+{
+	soundgroup_t *sg;
+	short i;
+	
+	sg = (soundgroup_t*)CLMemory_Alloc(sizeof(*sg));
+	if(numSounds < CL_MAX_SOUNDS)
+		sg->numSounds = numSounds;
+	else
+	{
+		__libError = -3;
+		__osError = 0;
+		CLCheckError();
+		sg->numSounds = CL_MAX_SOUNDS;
+	}
+	for(i = 0;i < sg->numSounds;i++)
+	{
+		sound_t *sound = CLSoundRaw_New(arg4, rate, sampleSize, mode);
+		sg->sound[i] = sound;
+		sound->ff_1A = arg4;
+	}
+	sg->soundIndex = 0;
+	sg->playIndex = 0;
+	sg->ff_106 = 1;
+	
+	return sg;
+}
+
+void CLSoundGroup_Free(soundgroup_t *sg)
+{
+	short i;
+	for(i = 0;i < sg->numSounds;i++)
+		CLSoundRaw_Free(sg->sound[i]);
+	CLMemory_Free(sg);
+}
+
+void CLSoundGroup_Reverse16All(soundgroup_t *sg)
+{
+	short i;
+	for(i = 0;i < sg->numSounds;i++)
+		sg->sound[i]->reversed = 1;
+}
+
+void* CLSoundGroup_GetNextBuffer(soundgroup_t *sg)
+{
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if(sg->ff_106)
+		while(sound->locked) ;
+	return ((char*)(*sound->sndHandle)) + sound->headerLen;
+}
+
+short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned)
+{
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if(sg->ff_106)
+		while(sound->locked) ;
+	else
+		if(sound->locked)
+			return 0;
+	sound->buffer = (char*)buffer;
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buffer, length);
+//	if(isSigned)
+//		CLSound_Signed2NonSigned(buffer, length);
+	if(sg->soundIndex == sg->numSounds - 1)
+		sg->soundIndex = 0;
+	else
+		sg->soundIndex++;
+		
+	return 1;
+}
+
+short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned)
+{
+	void *buffer;
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if(length >= sound->ff_1A)
+	{
+		__libError = -10;
+		__osError = 0;
+		CLCheckError();
+	}
+	if(sg->ff_106)
+		while(sound->locked) ;
+	else
+		if(sound->locked)
+			return 0;
+	buffer = ((char*)(*sound->sndHandle)) + sound->headerLen;
+	sound->buffer = (char*)buffer;
+	memcpy(buffer, data, length);
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buffer, length);
+//	if(isSigned)
+//		CLSound_Signed2NonSigned(buffer, length);
+	if(sg->soundIndex == sg->numSounds - 1)
+		sg->soundIndex = 0;
+	else
+		sg->soundIndex++;
+
+	return 1;
+}
+
+void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch)
+{
+	CLSoundChannel_Play(ch, sg->sound[sg->playIndex]);
+	if(sg->playIndex == sg->numSounds - 1)
+		sg->playIndex = 0;
+	else
+		sg->playIndex++;
+	
+}
diff --git a/engines/cryo/configure.engine b/engines/cryo/configure.engine
new file mode 100644
index 0000000..a0f5a04
--- /dev/null
+++ b/engines/cryo/configure.engine
@@ -0,0 +1,3 @@
+# This file is included from the main "configure" script
+# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps]
+add_engine cryo "Lost Eden" no "" "" ""
diff --git a/engines/cryo/cryo.cpp b/engines/cryo/cryo.cpp
new file mode 100644
index 0000000..425b055
--- /dev/null
+++ b/engines/cryo/cryo.cpp
@@ -0,0 +1,81 @@
+#include "common/scummsys.h"
+ 
+#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/error.h"
+#include "graphics/surface.h"
+#include "graphics/screen.h"
+#include "graphics/palette.h"
+#include "common/system.h"
+//#include "common/timer.h"
+
+#include "engines/util.h"
+ 
+#include "cryo/cryo.h"
+#include "cryo/eden.h"
+ 
+namespace Cryo {
+
+CryoEngine *g_ed = 0;
+
+CryoEngine::CryoEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _console(nullptr) {
+	// Put your engine in a sane state, but do nothing big yet;
+	// in particular, do not load data from files; rather, if you
+	// need to do such things, do them from run().
+ 
+	// Do not initialize graphics here
+	// Do not initialize audio devices here
+ 
+	// However this is the place to specify all default directories
+//	const Common::FSNode gameDataDir(ConfMan.get("path"));
+//	SearchMan.addSubDirectoryMatching(gameDataDir, "sound");
+ 
+	// Here is the right place to set up the engine specific debug channels
+	DebugMan.addDebugChannel(kCryoDebugExample, "example", "this is just an example for a engine specific debug channel");
+	DebugMan.addDebugChannel(kCryoDebugExample2, "example2", "also an example");
+ 
+	// Don't forget to register your random source
+	_rnd = new Common::RandomSource("cryo");
+ 
+	debug("CryoEngine::CryoEngine");
+
+	g_ed = this;
+}
+ 
+CryoEngine::~CryoEngine() {
+	debug("CryoEngine::~CryoEngine");
+ 
+	// Dispose your resources here
+	delete _rnd;
+ 
+	// Remove all of our debug levels here
+	DebugMan.clearAllDebugChannels();
+}
+ 
+Common::Error CryoEngine::run() {
+	// Initialize graphics using following:
+	initGraphics(320, 200, false);
+	_screen.create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
+
+	// Create debugger console. It requires GFX to be initialized
+	_console = new Console(this);
+ 
+	// Additional setup.
+	debug("CryoEngine::init");
+ 
+	// Your main even loop should be (invoked from) here.
+	debug("CryoEngine::go: Hello, World!");
+ 
+	// This test will show up if -d1 and --debugflags=example are specified on the commandline
+	debugC(1, kCryoDebugExample, "Example debug call");
+ 
+	// This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline
+	debugC(3, kCryoDebugExample | kCryoDebugExample2, "Example debug call two");
+ 
+	game.main();
+
+	return Common::kNoError;
+}
+ 
+} // End of namespace Cryo
diff --git a/engines/cryo/cryo.h b/engines/cryo/cryo.h
new file mode 100644
index 0000000..010e9f0
--- /dev/null
+++ b/engines/cryo/cryo.h
@@ -0,0 +1,62 @@
+#ifndef CRYO_H
+#define CRYO_H
+
+#include "common/scummsys.h"
+#include "common/config-manager.h"
+#include "engines/advancedDetector.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/error.h"
+#include "common/random.h"
+#include "engines/engine.h"
+#include "gui/debugger.h"
+#include "graphics/surface.h"
+#include "graphics/screen.h"
+#include "cryo/eden.h"
+ 
+namespace Cryo {
+ 
+class Console;
+ 
+// our engine debug channels
+enum {
+	kCryoDebugExample = 1 << 0,
+	kCryoDebugExample2 = 1 << 1
+	// next new channel must be 1 << 2 (4)
+	// the current limitation is 32 debug channels (1 << 31 is the last one)
+};
+ 
+class CryoEngine : public Engine {
+public:
+	CryoEngine(OSystem *syst, const ADGameDescription *gameDesc);
+	~CryoEngine();
+
+	virtual Common::Error run();
+
+	// Detection related functions
+	const ADGameDescription *_gameDescription;
+	const char *getGameId() const;
+	Common::Platform getPlatform() const;
+
+	// We need random numbers
+	Common::RandomSource *_rnd;
+
+	Graphics::Surface _screen;
+	EdenGame game;
+
+private:
+	Console *_console;
+};
+
+extern CryoEngine *g_ed;
+
+// Example console class
+class Console : public GUI::Debugger {
+public:
+	Console(CryoEngine *vm) {}
+	virtual ~Console(void) {}
+};
+ 
+} // End of namespace Cryo
+ 
+#endif
diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h
new file mode 100644
index 0000000..ff3642b
--- /dev/null
+++ b/engines/cryo/defs.h
@@ -0,0 +1,1399 @@
+#include <stddef.h>
+#include <stdlib.h>
+#include "cryolib.h"
+
+#define GetElem(array, idx) \
+	( (char*)(array) + PLE16((idx) * 2 + (char*)(array)) )
+/*
+static inline void* AGetElem(unsigned char *arr, short index)
+{
+	unsigned char *p = arr + num * 2;
+	unsigned char o0 = *p++;
+	unsigned char o1 = *p++;
+	unsigned short ofs = (o1 << 8) | o0;
+	return arr + ofs;
+}
+*/
+
+///////////////// Game defs
+
+#define FONT_HEIGHT	9
+
+
+/*
+Glossary
+  room      - a single game world's screen. referenced by 16-bit number 0xAALL, where AA - area# and LL - location#
+  area      - geographic area - Mo, Chamaar, etc
+  location  - coordinates of particular room in an area. usually in form of 0xXY, where X - map row, Y - map column
+  character - an unique character (human or dino.) Has their own voice/dialog lines
+  person    - instance of a character. Usually tied to specific room, but some may travel with you
+  party     - a group of characters that travel with you
+  object    - inventory item
+  icon      - clickable rectangle with some action tied to it
+  dialog    - a set of of dialog lines for character. further divided by categories and each entry may have associated
+              condition to be validated
+  global    - game-wide storage area. must be preserved when saving/loading
+  phase     - current story progress. Incremented by 1 for minor events, by 0x10 for major advancements
+*/
+
+enum Phases {
+	phNewGame = 0
+};
+
+namespace Areas { enum Areas {
+	arMo = 1,
+	arTausCave,
+	arChamaar,
+	arUluru,
+	arKoto,
+	arTamara,
+	arCantura,
+	arShandovra,
+	arNarimsCave,
+	arEmbalmersCave,
+	arWhiteArch,
+	arMoorkusLair
+}; };
+
+#define MKRM(a,l) (((a) << 8) | (l))
+
+enum OBJECT {
+	OBJ_0,
+	OBJ_1,
+	OBJ_2,
+	OBJ_3,
+	OBJ_4,
+	OBJ_PRISME,	// 5
+	OBJ_6,
+	OBJ_7,
+	OBJ_OEUF,	// 8
+	OBJ_9,
+	OBJ_10,
+	OBJ_CHAMPB,	// 11
+	OBJ_CHAMPM,	// 12
+	OBJ_COUTEAU,	// 13
+	OBJ_NIDV,	// 14
+	OBJ_NIDO,	// 15
+	OBJ_OR,		// 16
+	OBJ_17,
+	OBJ_18,
+	OBJ_SOLEIL,	// 19
+	OBJ_CORNE,	// 20
+	OBJ_21,
+	OBJ_22,
+	OBJ_23,
+	OBJ_24,
+	OBJ_25,
+	OBJ_26,
+	OBJ_27,
+	OBJ_28,
+	OBJ_29,
+	OBJ_30,
+	OBJ_31,
+	OBJ_32,
+	OBJ_33,
+	OBJ_34,
+	OBJ_35,
+	OBJ_36,		// 36 is 1st plaque, 6 total
+	OBJ_37,
+	OBJ_PLAQUE,	// 38
+	OBJ_39,
+	OBJ_40,
+	OBJ_41,
+};
+
+namespace Objects { enum Objects {
+	obNone,
+	obWayStone,
+	obShell,
+	obTalisman,
+	obTooth,
+	obPrism,	// 5
+	obFlute,
+	obApple,
+	obEgg,		// 8
+	obRoot,
+	obUnused10,
+	obShroom,	// 11
+	obBadShroom,	// 12
+	obKnife,	// 13
+	obNest,	// 14
+	obFullNest,	// 15
+	obGold,		// 16
+	obMoonStone,
+	obBag,
+	obSunStone,	// 19
+	obHorn,	// 20
+	obSword,
+
+	obMaskOfDeath,
+	obMaskOfBonding,
+	obMaskOfBirth,
+
+	obEyeInTheStorm,	// 25
+	obSkyHammer,
+	obFireInTheClouds,
+	obWithinAndWithout,
+	obEyeInTheCyclone,
+	obRiverThatWinds,
+
+	obTrumpet,		// 31
+	obUnused32,
+	obDrum,
+	obUnused34,
+	obUnused35,
+	obRing,
+
+	obTablet1,		// 37 is 1st plaque, 6 total
+	obTablet2,
+	obTablet3,	// 39
+	obTablet4,
+	obTablet5,
+	obTablet6
+}; };
+
+enum PERSO {
+	PER_ROI = 0,
+	PER_DINA,		// 0x12
+	PER_THOO,		// 0x24
+	PER_MONK,		// 0x36
+	PER_BOURREAU,	// 0x48
+	PER_MESSAGER,	// 0x5A
+	PER_MANGO,		// 0x6C
+	PER_EVE,		// 0x7E
+	PER_AZIA,		// 0x90
+	PER_MAMMI,		// 0xA2
+	PER_MAMMI_1,	// 0xB4
+	PER_MAMMI_2,	// 0xC6
+	PER_MAMMI_3,	// 0xD8
+	PER_MAMMI_4,	// 0xEA
+	PER_MAMMI_5,	// 0xFC
+	PER_MAMMI_6,	// 0x10E
+	PER_BAMBOO,		// 0x120
+	PER_KABUKA,		// 0x132
+	PER_GARDES,		// 0x144
+	PER_UNKN_156,	// 0x156
+	PER_FISHER,		// 0x168
+	PER_MORKUS,		// 0x17A
+	PER_UNKN_18C,	// 0x18C
+	PER_UNKN_19E,	// 0x19E
+	PER_UNKN_1B0,	// 0x1B0
+	PER_UNKN_1C2,	// 0x1C2
+	PER_UNKN_1D4,	// 0x1D4
+	PER_UNKN_1E6,	// 0x1E6
+	PER_UNKN_1F8,	// 0x1F8
+	PER_UNKN_20A,	// 0x20A
+	PER_UNKN_21C,	// 0x21C
+	PER_UNKN_22E,	// 0x22E
+	PER_UNKN_240,	// 0x240
+	PER_UNKN_252,	// 0x252
+	PER_UNKN_264,	// 0x264
+	PER_UNKN_276,	// 0x276
+	PER_UNKN_288,	// 0x288
+	PER_UNKN_29A,	// 0x29A
+	PER_UNKN_2AC,	// 0x2AC
+	PER_UNKN_2BE,	// 0x2BE
+	PER_UNKN_2D0,	// 0x2D0
+	PER_UNKN_2E2,	// 0x2E2
+	PER_UNKN_2F4,	// 0x2F4
+	PER_UNKN_306,	// 0x306
+	PER_UNKN_318,	// 0x318
+	PER_UNKN_32A,	// 0x32A
+	PER_UNKN_33C,	// 0x33C
+	PER_UNKN_34E,	// 0x34E
+	PER_UNKN_360,	// 0x360
+	PER_UNKN_372,	// 0x372
+	PER_UNKN_384,	// 0x384
+	PER_UNKN_396,	// 0x396
+	PER_UNKN_3A8,	// 0x3A8
+	PER_UNKN_3BA,	// 0x3BA
+	PER_UNKN_3CC,	// 0x3CC
+	PER_UNKN_3DE,	// 0x3DE
+	PER_UNKN_3F0,	// 0x3F0
+	PER_UNKN_402	// 0x402
+};
+
+namespace PersonId { enum PersonId {
+	pidGregor = 0,							// The King
+	pidDina,								// Pink dino
+	pidTau,									// Late grandpa
+	pidMonk,								// Old wizard
+	pidJabber,								// Executioner
+	pidEloi,								// Evergreen ptero
+	pidMungo,								// Dina's husband
+	pidEve,									// Blonde girl
+	pidShazia,								// Big boobs sis
+	pidLeadersBegin,						// 9
+	pidChongOfChamaar = pidLeadersBegin,	// Dogface
+	pidKommalaOfKoto,						// Clones
+	pidUlanOfUlele,							// Shaman
+	pidCabukaOfCantura,						// Stone people
+	pidMarindaOfEmbalmers,					// Gods
+	pidFuggOfTamara,						// Boar-like
+	pidThugg,								// Bodyguard
+	pidNarrator,							// 16, Old Eloi, also BGM
+	pidNarrim,								// Sea snake
+	pidMorkus,								// Vicious tyran
+	pidDinosaur,							// different species of friendly dino
+	pidEnemy								// different species of enemy dino
+}; };
+
+// person in room mask bits
+namespace PersonMask { enum PersonMask {
+	pmGregor = 1,
+	pmDina   = 2,
+	pmTau    = 4,
+	pmMonk   = 8,
+	pmJabber = 0x10,
+	pmEloi   = 0x20,
+	pmMungo  = 0x40,
+	pmEve    = 0x80,
+	pmShazia = 0x100,
+	pmLeader = 0x200,	// valley tribe leader
+	pmThugg  = 0x400,
+	pmQuest  = 0x800,	// special quest person
+	pmDino   = 0x1000,
+	pmEnemy  = 0x2000,
+	pmMorkus = 0x4000
+}; };
+
+namespace PersonFlags { enum PersonFlags {
+	pfType0 = 0,
+	pftTyrann,
+	pfType2,
+	pfType3,
+	pfType4,
+	pfType5,
+	pfType6,
+	pfType7,
+	pfType8,
+	pftMosasaurus,
+	pftTriceraptor,
+	pftVelociraptor,
+	pfType12,
+	pfType13,
+	pfType14,
+	pfType15,
+	pfTypeMask = 0xF,
+	pf10 = 0x10,
+	pf20 = 0x20,
+	pfInParty = 0x40,
+	pf80 = 0x80
+}; };
+
+#pragma pack(push, 1)
+struct perso_t {
+unsigned short	roomNum;	// room this person currently in
+unsigned short	actionId;	// TODO: checkme
+unsigned short	party;		// party bit mask
+unsigned char	id;			// character
+unsigned char	flags;		// flags and kind
+unsigned char	roomBankIdx;// index in kPersoRoomBankTable for specific room banks
+unsigned char	bank;		// sprite bank
+unsigned short	items;		// inventory
+unsigned short	powers;		// obj of power bitmask
+unsigned char	targetLoc;	// For party member this is mini sprite index
+unsigned char	lastLoc;	// For party member this is mini sprite x offset
+unsigned char	speed;		// num ticks per step
+unsigned char	steps;		// current ticks
+};
+typedef struct perso_t perso_t;
+
+struct phase_t {
+short			id;
+void			(EdenGameImpl::*disp)();
+};
+typedef struct phase_t phase_t;
+
+namespace ObjectFlags { enum ObjectFlags {
+	ofFlag1 = 1,
+	ofInHands = 2		// Currently holding this object in hands
+}; };
+
+#define MAX_OBJECTS	42
+struct object_t {
+unsigned char	id;
+unsigned char	flags;
+int				locations;		// index in kObjectLocations
+short			itemMask;
+short			powerMask;			// object of power bitmask
+short			count;
+};
+typedef struct object_t object_t;
+
+namespace DialogFlags { enum DialogFlags {
+	df20 = 0x20,
+	dfRepeatable = 0x40,
+	dfSpoken = 0x80
+}; };
+
+namespace DialogType { enum DialogType {
+	dtTalk = 0,
+	dtDinoAction,
+	dtDinoItem,
+	dtItem,
+	dtEvent,
+	dtInspect, 
+	dtHint
+}; };
+
+struct dial_t {
+char		flags;			// 0-3 - action index, 4 - highest bit of contidion index, rest is DialogFlags
+char		condNumLow;		// condition index low bits
+char		textCondHiMask;	// 0-1 text index hi bits, 2-5 - perso mask num, 6-7 condition index hi bits
+char		textNumLow;		// text line index low bits
+};
+typedef struct dial_t dial_t;
+
+struct tape_t {
+short		textNum;
+perso_t		*perso;
+short		party;
+short		roomNum;
+short		bgBankNum;
+dial_t		*dialog;
+};
+typedef struct tape_t tape_t;
+
+struct suiveur_t {		// Characters on Mirror screen
+char		id;			// character
+char		image;		// sprite number
+short		sx;
+short		sy;
+short		ex;
+short		ey;
+short		bank;
+short		ff_C;
+short		ff_E;
+};
+typedef struct suiveur_t suiveur_t;
+
+struct icon_t {
+short		sx;
+short		sy;
+short		ex;
+short		ey;
+unsigned short	cursor_id;			// & 0x8000 - inactive/hidden
+unsigned int	action_id;
+unsigned int	object_id;
+};
+typedef struct icon_t icon_t;
+
+struct goto_t {
+unsigned char	areaNum;	// target area
+unsigned char	curAreaNum;	// current area
+unsigned char	departVid;
+unsigned char	travelTime;		// time to skip while in travel
+unsigned char	arriveVid;
+};
+typedef struct goto_t goto_t;
+
+namespace RoomFlags { enum RoomFlags {
+	rf01 = 1,
+	rf02 = 2,
+	rf04 = 4,
+	rf08 = 8,
+	rfPanable = 0x10,
+	rfHasCitadel = 0x20,
+	rf40 = 0x40,
+	rf80 = 0x80
+}; };
+
+struct room_t {
+unsigned char	ff_0;
+unsigned char	exits[4];	//TODO: signed?
+unsigned char	flags;
+unsigned short	bank;
+unsigned short	party;
+unsigned char	level;		// Citadel level
+unsigned char	video;
+unsigned char	location;
+unsigned char	background;	// bg/mirror image number (relative)
+};
+typedef struct room_t room_t;
+
+namespace AreaFlags { enum AreaFlags {
+	afFlag1 = 1,
+	afFlag2 = 2,
+	afFlag4 = 4,
+	afFlag8 = 8,
+	afGaveGold = 0x10,
+	afFlag20 = 0x20,
+
+	HasTriceraptors = 0x100,
+	HasVelociraptors = 0x200,
+	HasTyrann = 0x400,
+
+	TyrannSighted = 0x4000,
+	afFlag8000 = 0x8000
+}; };
+
+namespace AreaType { enum AreaType {
+	atCitadel = 1,
+	atValley = 2,
+	atCave = 3
+}; };
+
+struct area_t {
+unsigned char	num;
+unsigned char	type;
+unsigned short	flags;
+unsigned short	firstRoomIndex;
+unsigned char	citadelLevel;
+unsigned char	salNum;
+room_t			*citadelRoom;
+short			visitCount;
+};
+typedef struct area_t area_t;
+
+namespace ValleyNews { enum ValleyNews {
+	vnAreaMask = 0xF,
+
+	vnTriceraptorsIn = 0x10,
+	vnVelociraptorsIn = 0x20,
+	vnTyrannIn = 0x30,
+	vnTyrannLost = 0x40,
+	vnCitadelLost = 0x50,
+	vnVelociraptorsLost = 0x60,
+
+	vnFree = 0,
+	vnHidden = 0x80,
+	vnEnd = 0xFF
+}; };
+
+namespace DisplayFlags { enum DisplayFlags {
+	dfFlag1 = 1,
+	dfFlag2 = 2,
+	dfMirror = 4,
+	dfPerson = 8,
+	dfFresques = 0x10,
+	dfPanable = 0x20,
+	dfFlag40 = 0x40,
+	dfFlag80 = 0x80
+}; };
+
+namespace DrawFlags { enum DrawFlags {
+	drDrawInventory = 1,
+	drDrawFlag2 = 2,
+	drDrawTopScreen = 4,
+	drDrawFlag8 = 8,
+	drDrawMenu = 0x10,
+	drDrawFlag20 = 0x20
+}; };
+
+namespace MenuFlags { enum MenuFlags {
+	mfFlag1 = 1,
+	mfFlag2 = 2,
+	mfFlag4 = 4,
+	mfFlag8 = 8,
+	mfFlag10 = 0x10
+}; };
+
+namespace MusicType { enum MusicType {	//TODO: same as DialogType?
+	mtDontChange = 0,
+	mtNormal = 1,
+	mt2 = 2,
+	mtEvent = 4,
+	mtFF = 0xFF
+}; };
+
+namespace EventType { enum EventType {
+	etEvent1 = 1,
+	etEvent2 = 2,
+	etEvent3 = 3,
+	etEvent4 = 4,
+	etEvent5 = 5,
+	etEvent6 = 6,
+	etEvent7 = 7,
+	etEvent8 = 8,
+	etEvent9 = 9,
+	etEventB = 11,
+	etEventC = 12,
+	etEventD = 13,
+	etEventE = 14,
+	etEventF = 15,
+	etEvent10 = 16,
+	etEvent12 = 18,
+	etGotoArea = 0x80	// + area id
+}; };
+
+namespace GameFlags { enum GameFlags {
+	gfMummyOpened = 1,
+	gfFlag2 = 2,
+	gfFlag4 = 4,
+	gfFlag8 = 8,
+	gfFlag10 = 0x10,
+	gfFlag20 = 0x20,
+	gfFlag40 = 0x40,
+	gfFlag80 = 0x80,
+	gfFlag100 = 0x100,
+	gfFlag200 = 0x200,
+	gfFlag400 = 0x400,
+	gfPrismAndMonk = 0x800,
+	gfFlag1000 = 0x1000,
+	gfFlag2000 = 0x2000,
+	gfFlag4000 = 0x4000,
+	gfFlag8000 = 0x8000
+}; };
+
+struct global_t {
+unsigned char	areaNum;
+unsigned char	areaVisitCount;
+unsigned char	menuItemIdLo;
+unsigned char	menuItemIdHi;	//TODO: pad?
+unsigned short	randomNumber;	//TODO: this is randomized in pc ver and used by some conds. always zero on mac
+unsigned short	gameTime;
+unsigned short	gameDays;
+unsigned short	chrono;
+unsigned short	eloiDepartureDay;
+unsigned short	roomNum;		// current room number
+unsigned short	newRoomNum;		// target room number selected on world map
+unsigned short	phaseNum;
+unsigned short	metPersonsMask1;
+unsigned short	party;
+unsigned short	partyOutside;
+unsigned short	metPersonsMask2;
+unsigned short	__UNUSED_1C;	//TODO: write-only?
+unsigned short	phaseActionsCount;
+unsigned short	curAreaFlags;
+unsigned short	curItemsMask;
+unsigned short	curPowersMask;
+unsigned short	curPersoItems;
+unsigned short	curPersoPowers;
+unsigned short	wonItemsMask;
+unsigned short	wonPowersMask;
+unsigned short	stepsToFindAppleFast;
+unsigned short	stepsToFindAppleNormal;
+unsigned short	roomPersoItems;	//TODO: write-only?
+unsigned short	roomPersoPowers;	//TODO: write-only?
+unsigned short	gameFlags;
+unsigned short	curVideoNum;
+unsigned short	morkusSpyVideoNum1;	//TODO: pad?
+unsigned short	morkusSpyVideoNum2;	//TODO: pad?
+unsigned short	morkusSpyVideoNum3;	//TODO: pad?
+unsigned short	morkusSpyVideoNum4;	//TODO: pad?
+unsigned char	newMusicType;
+unsigned char	ff_43;
+unsigned char	videoSubtitleIndex;
+unsigned char	partyInstruments;	// &1 - Bell for Monk, &2 - Drum for Thugg
+unsigned char	monkGotRing;
+unsigned char	chrono_on;
+unsigned char	curRoomFlags;
+unsigned char	endGameFlag;
+unsigned char	last_info;
+unsigned char	autoDialog;
+unsigned char	worldTyrannSighted;
+unsigned char	ff_4D;
+unsigned char	ff_4E;
+unsigned char	worldGaveGold;
+unsigned char	worldHasTriceraptors;
+unsigned char	worldHasVelociraptors;
+unsigned char	worldHasTyrann;
+unsigned char	ff_53;
+unsigned char	ff_54;
+unsigned char	ff_55;	//TODO: pad?
+unsigned char	ff_56;
+unsigned char	textToken1;
+unsigned char	textToken2;	//TODO: pad?
+unsigned char	eloiHaveNews;
+unsigned char	dialogFlags;
+unsigned char	curAreaType;
+unsigned char	curCitadelLevel;
+unsigned char	newLocation;
+unsigned char	prevLocation;
+unsigned char	curPersoFlags;
+unsigned char	ff_60;
+unsigned char	eventType;
+unsigned char	ff_62;	//TODO: pad?
+unsigned char	curObjectId;
+unsigned char	curObjectFlags;
+unsigned char	ff_65;	//TODO: pad?
+unsigned char	roomPersoType;
+unsigned char	roomPersoFlags;
+unsigned char	narratorSequence;
+unsigned char	ff_69;
+unsigned char	ff_6A;
+unsigned char	fresqNumber;
+unsigned char	ff_6C;	//TODO: pad?
+unsigned char	ff_6D;	//TODO: pad?
+unsigned char	labyrinthDirections;
+unsigned char	labyrinthRoom;
+void			*__UNUSED_70;	//TODO: pad?
+dial_t			*dialog_ptr;
+tape_t			*tape_ptr;
+dial_t			*next_dialog_ptr;
+dial_t			*narrator_dialog_ptr;
+dial_t			*last_dialog_ptr;
+icon_t			*nextRoomIcon;
+unsigned char	*phraseBufferPtr;
+unsigned char	*__UNUSED_90;	//TODO: write-only?
+unsigned char	*__UNUSED_94;	//TODO: write-only?
+room_t			*room_ptr;
+area_t			*area_ptr;
+area_t			*last_area_ptr;
+area_t			*cur_area_ptr;
+room_t			*cita_area_firstRoom;
+perso_t			*perso_ptr;
+perso_t			*room_perso;
+unsigned char	last_info_idx;
+unsigned char	next_info_idx;
+unsigned char	*persoSpritePtr;
+unsigned char	*persoSpritePtr2;
+unsigned char	*curPersoAnimPtr;
+unsigned char	*ff_C2;	//TODO: image desc arr
+short			iconsIndex;
+short			curObjectCursor;	// TODO: useless?
+short			ff_CA;
+short			__UNUSED_CC;		//TODO: unused/pad
+short			perso_img_bank;	//TODO: unsigned?
+unsigned short	roomImgBank;
+unsigned short	persoBackgroundBankIdx;
+unsigned short	ff_D4;	//TODO: unsigned?
+unsigned short	fresqWidth;
+unsigned short	fresqImgBank;
+unsigned short	ff_DA;	//TODO: pad?
+unsigned short	ff_DC;	//TODO: pad?
+unsigned short	room_x_base;
+unsigned short	ff_E0;	//TODO: pad?
+unsigned short	dialogType;
+unsigned short	ff_E4;	//TODO: pad?
+unsigned short	currentMusicNum;
+short			textNum;
+unsigned short	travelTime;
+unsigned short	ff_EC;	//TODO: pad?
+unsigned char	displayFlags;
+unsigned char	oldDisplayFlags;
+unsigned char	drawFlags;
+unsigned char	ff_F1;
+unsigned char	ff_F2;
+unsigned char	menuFlags;
+unsigned char	ff_F4;	//TODO: write-only?
+unsigned char	ff_F5;
+unsigned char	ff_F6;
+unsigned char	ff_F7;
+unsigned char	ff_F8;	//TODO: pad?
+unsigned char	ff_F9;	//TODO: pad?
+unsigned char	ff_FA;	//TODO: pad?
+unsigned char	animationFlags;
+unsigned char	__UNUSED_FC;	//TODO: pad?
+unsigned char	giveobj1;
+unsigned char	giveobj2;
+unsigned char	giveobj3;
+unsigned char	ff_100;
+unsigned char	roomVidNum;
+unsigned char	ff_102;
+unsigned char	ff_103;
+unsigned char	roomBgBankNum;
+unsigned char	valleyVidNum;
+unsigned char	updatePaletteFlag;
+unsigned char	inventoryScrollPos;
+unsigned char	obj_count;
+unsigned char	ff_109;	//TODO: write-only?
+unsigned char	textBankIndex;
+unsigned char	pref_language;
+unsigned char	pref_10C[2];	//TODO: volume
+unsigned char	pref_10E[2];	// -//-
+unsigned char	pref_110[2];	// -//-
+unsigned char	cita_area_num;
+unsigned char	ff_113;
+unsigned char	lastSalNum;
+unsigned char	save_end;
+short			textWidthLimit;
+unsigned char	numGiveObjs;
+unsigned char	ff_119;		// unused
+};
+typedef struct global_t global_t;
+
+struct pakfile_t {
+char			name[16];
+long			size;
+long			offs;
+char			flag;
+};
+typedef struct pakfile_t pakfile_t;
+
+struct pak_t {
+unsigned short	count;
+pakfile_t		files[10];
+};
+typedef struct pak_t pak_t;
+#pragma pack(pop)
+
+struct cita_t {
+short	ff_0;
+short	ff_2[8 * 2];
+};
+typedef struct cita_t cita_t;
+
+/////////////// vars
+
+suiveur_t suiveurs_list[] = {
+//            char,                 X,  sx, sy,  ex,  ey,bank,
+	{ PersonId::pidGregor,          5, 211,  9, 320, 176, 228,   0,  0 },
+	{ PersonId::pidEloi,            4, 162, 47, 223, 176, 228, 112, 78 },
+	{ PersonId::pidDina,            3,  55,  0, 172, 176, 228,  90, 16 },
+	{ PersonId::pidChongOfChamaar,  4,   0,  5, 114, 176, 229,   0, 16 },
+	{ PersonId::pidKommalaOfKoto,   3,   0, 15, 102, 176, 229,   0, 16 },
+	{ PersonId::pidUlanOfUlele,     1,   0,  0, 129, 176, 230,   0, 16 },
+	{ PersonId::pidCabukaOfCantura, 2,   0,  0, 142, 176, 230,   0, 16 },
+	{ PersonId::pidFuggOfTamara,    0,   0, 17, 102, 176, 230,   0, 16 },
+	{ PersonId::pidJabber,          2,   0,  6, 134, 176, 228,   0, 16 },
+	{ PersonId::pidShazia,          1,  90, 17, 170, 176, 228,  50, 22 },
+	{ PersonId::pidThugg,           0, 489,  8, 640, 176, 228, 160, 24 },
+	{ PersonId::pidMungo,           5, 361,  0, 517, 176, 229,   0, 16 },
+	{ PersonId::pidMonk,            0, 419, 22, 569, 176, 229, 100, 30 },
+	{ PersonId::pidEve,             1, 300, 28, 428, 176, 229,   0, 38 },
+	{ -1,                          -1,  -1, -1,  -1,  -1,  -1,  -1, -1 }
+};
+
+
+/*
+  Labyrinth of Mo
+
+  | | | | | | | |
+
+*/
+
+enum {
+	LAB_N = 1,
+	LAB_E,
+	LAB_S,
+	LAB_W
+};
+
+#define LAB(toCrypt, toThrone)	\
+	(((LAB_##toCrypt) << 4) | (LAB_##toThrone))
+
+unsigned char kLabyrinthPath[] = {
+// each nibble tells wich direction to choose to exit the labyrinth
+0x11, 0x11, 0x11, 0x22, 0x33, 0x55, 0x25, 0x44, 0x25, 0x11, 0x11, 0x11,
+0x11, 0x35, 0x55, 0x45, 0x45, 0x44, 0x44, 0x34, 0x44, 0x34, 0x32, 0x52,
+0x33, 0x23, 0x24, 0x44, 0x24, 0x22, 0x54, 0x22, 0x54, 0x54, 0x44, 0x22,
+0x22, 0x42, 0x45, 0x22, 0x42, 0x45, 0x35, 0x11, 0x44, 0x34, 0x52, 0x11,
+0x44, 0x32, 0x55, 0x11, 0x11, 0x33, 0x11, 0x11, 0x53, 0x11, 0x11, 0x53,
+0x54, 0x24, 0x11, 0x22, 0x25, 0x33, 0x53, 0x54, 0x23, 0x44
+};
+
+#undef LAB
+
+char kDinoSpeedForCitaLevel[16] = { 1, 2, 3, 4, 4, 5, 6, 7, 8, 9 };
+
+char kTabletView[] = {			//TODO: make as struct?
+	// opposite tablet id, video id
+	Objects::obUnused10, 83,
+	Objects::obUnused10, 84,
+	Objects::obTablet4, 85,
+	Objects::obTablet3, 86,
+	Objects::obTablet6, 87,
+	Objects::obTablet5, 85
+};
+
+// special character backgrounds for specific rooms
+char kPersoRoomBankTable[] = {
+	// first entry is default bank, then pairs of [roomNum, bankNum], terminated by -1
+	 0,  3, 33, -1,
+	21, 17, 35, -1,
+	 0,  2, 36, -1,
+	22,  9, 38,  3, 39, -1,
+	23,  8, 40, -1,
+	 0,  3, 41,  7, 42, -1,
+	25, -1,
+	27, 17, 45, -1,
+	28, 26, 46, -1,
+	29, 51, 48, -1,
+	30, 53, 49, -1,
+	 0, 27, 50, -1,
+	32, 17, 51, -1,
+	52,  2, 52, -1,
+	-3,  3, -3, -1,
+	31, -1,
+	24,  6, 43, -1,
+	47, -1,
+	 0,  2, 64, -1, 
+	54,  3, 54, -1,
+	27, -1,
+	26, 17, 45, -1
+};
+
+// area transition descriptors
+goto_t gotos[] = {
+// area, oldarea, vid, time, valleyVid
+	{  0,  1,   0,  2,  20 },
+	{  0,  1, 162,  3, 168 },
+	{  0,  2,   0,  2,  21 },
+	{  0,  6,   0,  3, 108 },
+	{  0,  9, 151,  3,   0 },
+	{  0,  7, 106,  2, 101 },
+	{  0, 10,  79,  3, 102 },
+	{  0, 12,   0,  3,   0 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  1,  3,  58,  2, 104 },
+	{  1,  4, 100,  4, 104 },
+	{  1,  5, 107,  6, 104 },
+	{  1,  6, 155,  8, 104 },
+	{  1,  7, 165,  6, 104 },
+	{  1,  8, 169,  6, 104 },
+	{  1, 10, 111,  2, 104 },
+	{  1, 11, 164,  4, 104 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  1,  3, 161,  3, 102 },
+	{  1,  4, 163,  6, 102 },
+	{  1,  5, 157,  9, 102 },
+	{  1,  9, 160,  9, 102 },
+	{  1, 10,  79,  3, 102 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  1,  3,   0,  3, 153 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  3,  1, 154,  2, 103 },
+	{  3,  4, 100,  2, 103 },
+	{  3,  5, 107,  4, 103 },
+	{  3,  6, 155,  6, 103 },
+	{  3,  7, 165,  8, 103 },
+	{  3,  8, 169,  6, 103 },
+	{  3, 10, 111,  4, 103 },
+	{  3, 11, 164,  6, 103 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  3,  1, 162,  3,  22 },
+	{  3,  4, 163,  6,  22 },
+	{  3,  5, 157,  9,  22 },
+	{  3,  9, 160,  9,  22 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  3,  1,   0,  3, 166 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  4,  1, 154,  4,  51 },
+	{  4,  3,  58,  2,  51 },
+	{  4,  5, 107,  2,  51 },
+	{  4,  6, 155,  4,  51 },
+	{  4,  7, 165,  6,  51 },
+	{  4,  8, 169,  8,  51 },
+	{  4, 10, 111,  6,  51 },
+	{  4, 11, 164,  8,  51 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  4,  1, 162,  3, 109 },
+	{  4,  3, 161,  6, 109 },
+	{  4,  5, 157,  9, 109 },
+	{  4,  9, 160,  9, 109 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  5,  1, 154,  6,  33 },
+	{  5,  3,  58,  4,  33 },
+	{  5,  4, 100,  2,  33 },
+	{  5,  6, 155,  2,  33 },
+	{  5,  7, 165,  4,  33 },
+	{  5,  8, 169,  8,  33 },
+	{  5, 10, 111,  8,  33 },
+	{  5, 11, 164,  8,  33 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  5,  1, 162,  3,  99 },
+	{  5,  3, 161,  6,  99 },
+	{  5,  4, 163,  9,  99 },
+	{  5,  9, 160,  9,  99 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  9,  1, 162,  3, 167 },
+	{  9,  3, 161,  6, 167 },
+	{  9,  4, 163,  9, 167 },
+	{  9,  5, 157,  9, 167 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  6,  1, 154,  8, 105 },
+	{  6,  3,  58,  6, 105 },
+	{  6,  4, 100,  4, 105 },
+	{  6,  5, 107,  2, 105 },
+	{  6,  7, 165,  2, 105 },
+	{  6,  8, 169, 10, 105 },
+	{  6, 10, 111,  6, 105 },
+	{  6, 11, 164,  8, 105 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  7,  1, 154,  4, 158 },
+	{  7,  3,  58,  6, 158 },
+	{  7,  4, 100,  6, 158 },
+	{  7,  5, 107,  4, 158 },
+	{  7,  6, 155,  2, 158 },
+	{  7,  8, 169,  8, 158 },
+	{  7, 10, 111,  4, 158 },
+	{  7, 11, 164,  6, 158 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  8,  1, 154,  2, 159 },
+	{  8,  3,  58,  4, 159 },
+	{  8,  4, 100,  6, 159 },
+	{  8,  5, 107,  8, 159 },
+	{  8,  6, 155, 10, 159 },
+	{  8,  7, 165,  8, 159 },
+	{  8, 10, 111,  6, 159 },
+	{  8, 11, 164,  4, 159 },
+	{ -1, -1,  -1, -1,  -1 },
+	{ 10,  1, 154,  2,  77 },
+	{ 10,  3,  58,  4,  77 },
+	{ 10,  4, 100,  6,  77 },
+	{ 10,  5, 107,  8,  77 },
+	{ 10,  6, 155,  6,  77 },
+	{ 10,  7, 165,  4,  77 },
+	{ 10,  8, 169,  6,  77 },
+	{ 10, 11, 164,  4,  77 },
+	{ -1, -1,  -1, -1,  -1 },
+	{ 11,  1, 154,  2,  80 },
+	{ 11,  3,  58,  4,  80 },
+	{ 11,  4, 100,  6,  80 },
+	{ 11,  5, 107,  8,  80 },
+	{ 11,  6, 155,  8,  80 },
+	{ 11,  7, 165,  6,  80 },
+	{ 11,  8, 169,  2,  80 },
+	{ 11, 10, 111,  4,  80 },
+	{ -1, -1,  -1, -1,  -1 },
+	{ 12,  1, 154,  8,  56 },
+	{ 12,  3,  58,  4,  56 },
+	{ 12,  4, 100,  4,  56 },
+	{ 12,  5, 107,  6,  56 },
+	{ 12,  6, 155,  8,  56 },
+	{ 12,  7, 165, 10,  56 },
+	{ 12,  8, 169,  4,  56 },
+	{ 12, 10, 111, 10,  56 },
+	{ 12, 11, 164,  6,  56 },
+	{ -1, -1,  -1, -1,  -1 }
+};
+
+#define SUB_LINE(start, end) \
+	(start), (end) | 0x8000
+
+short tab_2D24C[] = {
+	SUB_LINE( 68, 120 ),
+	 123, 32964,
+	 199, 33042,
+	 276, 33138,
+	 799, 33653,
+	 888, 33708,
+	 947, 33768,
+	1319, 34146,
+	1380, 34208,
+	1854, 34666,
+	1900, 34728,
+	2116, 34952,
+	2186, 35020,
+	2254, 35088,
+	3038, 35862,
+	3096, 35928,
+	-1
+};
+
+short tab_2D28E[] = {
+	 99, 32923,
+	157, 33024,
+	-1
+};
+
+short tab_2D298[] = {
+	106, 32941,
+	175, 33012,
+	246, 33118,
+	352, 33235,
+	-1
+};
+
+short tab_2D2AA[] = {
+	126, 32944,
+	178, 33035,
+	269, 33110,
+	344, 33166,
+	400, 33226,
+	460, 33326,
+	-1
+};
+
+short tab_2D2C4[] = {
+	101, 32981,
+	215, 33121,
+	355, 33223,
+	457, 33286,
+	520, 33428,
+	662, 33536,
+	-1
+};
+#undef SUB_LINE
+
+object_t objects[] = {
+	//id,fl,loc,masklow,maskhi,ct 
+	{  1, 0,  3,      1,     0, 0},		// Eve's Way Stone
+	{  2, 0,  3,      2,     0, 0},		// Thau's Seashell
+	{  3, 0,  3,      4,     0, 0},		// Talisman of bravery
+	{  4, 0,  3,      8,     0, 0},		// An old tooth. Very old! Whoever lost it most certainly has no further use for it!
+	{  5, 0,  0,   0x10,     0, 0},		// Prism
+	{  6, 0,  3,      0,     0, 0},		// Flute
+	{  7, 0,  3, 0x4000,     0, 0},		// Apple
+	{  8, 0,  4, 0x1000,     0, 0},		// Egg of Destiny
+	{  9, 0,  3,  0x800,     0, 0},		// Root
+	{ 10, 0,  3,      0,     0, 0},		// ???
+	{ 11, 0,  6,      0,     0, 0},		// Mushroom
+	{ 12, 0, 13,      0,     0, 0},		// Poisonous Mushroom
+	{ 13, 0,  2,  0x400,     0, 0},		// Graa's Knife
+	{ 14, 0, 22,      0,     0, 0},		// Empty Nest
+	{ 15, 0, 26,      0,     0, 0},		// Full Nest
+	{ 16, 0, 33,   0x20,     0, 0},		// Gold
+	{ 17, 0,  3,      0,     0, 0},		// Sign of Shadow Mistress	(moon stone)
+	{ 18, 0,  3,      0,     0, 0},		// Sign of Mother of all	(bag of soil)
+	{ 19, 0, 40,      0,     0, 0},		// Sign of the life-giving	(sun star)
+	{ 20, 0, 20,  0x200,     0, 0},		// King's Horn
+	{ 21, 0,  3,      0,     0, 0},		// Golden Sword of Mashaar
+										// Masks
+	{ 22, 0,  3,   0x40,     0, 0},		// Mask of Death
+	{ 23, 0,  3,   0x80,     0, 0},		// Mask of Bonding
+	{ 24, 0,  3,  0x100,     0, 0},		// Mask of Birth
+										// Objects of power
+	{ 25, 0,  3,      0,     1, 0},		// Eye in the Storm
+	{ 26, 0,  3,      0,     2, 0},		// Sky Hammer
+	{ 27, 0,  3,      0,     4, 0},		// Fire in the Clouds
+	{ 28, 0,  3,      0,     8, 0},		// Within and Without
+	{ 29, 0,  3,      0,  0x10, 0},		// Eye in the Cyclone
+	{ 30, 0,  3,      0,  0x20, 0},		// River that Winds
+										// Musical instruments
+	{ 31, 0,  3,      0,  0x40, 0},		// Trumpet
+	{ 32, 0,  3,      0,  0x80, 0},		// -- unused (but still has a dialog line)
+	{ 33, 0,  3,      0, 0x100, 0},		// Drum
+	{ 34, 0,  3,      0, 0x200, 0},		// -- unused (but still has a dialog line)
+	{ 35, 0,  3,      0, 0x400, 0},		// -- unused (but still has a dialog line)
+	{ 36, 0,  3,      0, 0x800, 0},		// Ring
+										// Tablets
+	{ 37, 0,  3,      0,     0, 0},		// Tablet #1 (Mo)
+	{ 38, 0, 42, 0x2000,     0, 0},		// Tablet #2 (Morkus' Lair)
+	{ 39, 0,  3,      0,     0, 0},		// Tablet #3 (White Arch?)
+	{ 40, 0,  3,      0,     0, 0},		// Tablet #4
+	{ 41, 0,  3,      0,     0, 0},		// Tablet #5
+	{ 42, 0,  3, 0x8000,     0, 0}		// Tablet #6 (Castra)
+};
+
+short kObjectLocations[100] = {
+	0x112, -1,
+	0x202, -1,
+	0x120, -1,
+	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
+	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
+	0, -1,
+	0x344, 0x53A, 0x831, -1,
+	0x331, 0x420, 0x54B, 0x637, 0x716, 0x840, -1,
+	0x834A, 0x8430, 0x8531, 0x644, 0x745, 0x838, -1,
+	0x510, -1,
+	0xC04, -1,
+	-1
+};
+
+perso_t kPersons[] = {
+	// room, aid, party mask,                            id,                                            flags,  X,bank,X, X,sprId,sprX,speed, X
+	{ 0x103, 230, PersonMask::pmGregor, PersonId::pidGregor            ,                                                0,  0,  1, 0, 0,  0,   0, 0, 0 },
+	{ 0x116, 231, PersonMask::pmDina  , PersonId::pidDina              ,                                                0,  4,  2, 0, 0,  3,   9, 0, 0 },
+	{ 0x202, 232, PersonMask::pmTau   , PersonId::pidTau               ,                                                0,  8,  3, 0, 0,  0,   0, 0, 0 },
+	{ 0x109, 233, PersonMask::pmMonk  , PersonId::pidMonk              ,                                                0, 12,  4, 0, 0,  6,  52, 0, 0 },
+	{ 0x108, 234, PersonMask::pmJabber, PersonId::pidJabber            ,                                                0, 18,  5, 0, 0,  2,   0, 0, 0 },
+	{ 0x103, 235, PersonMask::pmEloi  , PersonId::pidEloi              ,                                                0, 22,  6, 0, 0,  4,  20, 0, 0 },
+	{ 0x301, 236, PersonMask::pmMungo , PersonId::pidMungo             ,                                                0, 28,  8, 0, 0, 11,  45, 0, 0 },
+	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 30, 10, 0, 0,  7,  35, 0, 0 },
+	{ 0x81A, 238, PersonMask::pmShazia, PersonId::pidShazia            ,                                                0, 34, 11, 0, 0,  1,  11, 0, 0 },
+	{ 0x330, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
+	{ 0x41B, 239, PersonMask::pmLeader, PersonId::pidUlanOfUlele       ,                                                0, 46, 15, 0, 0, 13,   0, 0, 0 },
+	{ 0x53B, 239, PersonMask::pmLeader, PersonId::pidKommalaOfKoto     ,                                                0, 42, 14, 0, 0,  9,   0, 0, 0 },
+	{ 0x711, 239, PersonMask::pmLeader, PersonId::pidCabukaOfCantura   ,                                                0, 50, 16, 0, 0, 14,   0, 0, 0 },
+	{ 0xA02, 239, PersonMask::pmLeader, PersonId::pidMarindaOfEmbalmers,                                                0, 54, 17, 0, 0,  0,   0, 0, 0 },
+	{ 0x628, 239, PersonMask::pmLeader, PersonId::pidFuggOfTamara      ,                                                0, 62, 18, 0, 0, 12,   0, 0, 0 },
+	{ 0x801, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
+	{ 0x41B,  10, PersonMask::pmQuest , PersonId::pidUlanOfUlele       , PersonFlags::pfType2                            , 46, 15, 0, 0, 13,   0, 0, 0 },
+	{ 0x711,  11, PersonMask::pmQuest , PersonId::pidCabukaOfCantura   , PersonFlags::pfType2                            , 50, 16, 0, 0, 14,   0, 0, 0 },
+	{ 0x106, 240, PersonMask::pmThugg , PersonId::pidThugg             ,                                                0, 64,  7, 0, 0,  0,  61, 0, 0 },
+	{     0,  13,                    0, PersonId::pidNarrator          ,                                                0, 68, 12, 0, 0,  0,   0, 0, 0 },
+	{ 0x902, 241, PersonMask::pmQuest , PersonId::pidNarrim            ,                                                0, 70, 19, 0, 0,  0,   0, 0, 0 },
+	{ 0xC03, 244, PersonMask::pmMorkus, PersonId::pidMorkus            ,                                                0, 74, 20, 0, 0,  0,   0, 0, 0 },
+	// dinos in each valley
+	{ 0x332, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x329, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x33B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x317, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x320, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType12                           ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x349, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x429, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x43B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x422, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x432, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x522, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x534, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x515, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x533, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x622, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x630, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x643, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x63A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x737, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x739, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x74A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x726, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x842, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pfType8        ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x822, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x828, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x84B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0xB03, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            , 58,252, 0, 0,  0,   0, 0, 0 },
+	// enemy dinos
+	{ 0x311, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x410, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x51B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x618, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x71B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x81B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{    -1,  -1,                   -1,                              -1,                                               -1, -1, -1,-1,-1, -1,  -1,-1,-1 },
+	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 80,  9, 0, 0,  8,  35, 0, 0 },
+	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 78, 10, 0, 0,  7,  35, 0, 0 }
+};
+
+cita_t cita_list[] = {
+	{1,
+	{163, 182,   0, 0,
+	 124, 147, 193, 0,
+	   0,   0,   0, 0,
+	   0,   0,   0, 0}},
+	{48,
+	{285, 286,   0, 0,
+	 287, 288, 284, 0,
+	 114, 115,   0, 0,
+	 116, 117, 113, 0}},
+	{63,
+	{290, 291,   0, 0,
+	 292, 293, 289, 0,
+	 119, 120,   0, 0,
+	 121, 122, 118, 0}},
+	{95,
+	{295, 296,   0, 0,
+	 297, 298, 294, 0,
+	 124, 125,   0, 0,
+	 126, 127, 123, 0}},
+	{127,
+	{300, 301,   0, 0,
+	 302, 303, 299, 0,
+	 129, 130,   0, 0,
+	 131, 132, 128, 0}},
+	{159,
+	{305, 306,   0, 0,
+	 307, 308, 304, 0,
+	 134, 135,   0, 0,
+	 136, 137, 133, 0}},
+	{255,
+	{310, 311,   0, 0,
+	 312, 313, 309, 0,
+	 139, 140,   0, 0,
+	 141, 142, 138, 0}}
+};
+
+
+short tab_2CB16[] = { 2075, 2080, 2119, -1};
+
+char tab_2CB1E[8][4] = {
+	{ 0x10, 0x81,    1, 0x90},
+	{ 0x90,    1, 0x81, 0x10},
+	{    1, 0x90, 0x10, 0x81},
+	{    1, 0x10, 0x90, 0x81},
+	{    1, 0x90, 0x10, 0x81},
+	{ 0x81, 0x10, 0x90,    1},
+	{ 0x81, 0x10, 0x90,    1},
+	{ 0x81, 0x90,    1, 0x10}
+};
+
+struct prect_t {
+short	sx, sy, ex, ey;
+};
+typedef struct prect_t prect_t;
+
+prect_t perso_rects[] = {	//TODO: just an array of shorts?
+	{  93,  69, 223, 176},
+	{ 102,  86, 162, 126},
+	{  88, 103, 168, 163},
+	{ 116,  66, 192, 176},
+	{ 129,  92, 202, 153},
+	{  60,  95, 160, 176},
+	{ 155,  97, 230, 145},
+	{ 100,  77, 156, 145},
+	{ 110,  78, 170, 156},
+	{  84,  76, 166, 162},
+	{  57,  77, 125, 114},
+	{  93,  69, 223, 175},
+	{  93,  69, 223, 176},
+	{  93,  69, 223, 176},
+	{ 154,  54, 245, 138},
+	{ 200,  50, 261, 116},
+	{  70,  84, 162, 176},
+	{ 125, 101, 222, 172},
+	{ 188,  83, 251, 158}
+};
+
+unsigned char tab_persxx[][5] = {	//TODO: struc?
+	{  8, 15, 23, 25, -1},
+	{  0,  9, -1        },
+	{  0,  9, -1        },
+	{  0,  9, -1        },
+	{  0, 13, -1        },
+	{ 16, 21, -1        },
+	{ 11, 20, -1        },
+	{  0, 12, -1        },
+	{  0,  9, -1        },
+	{  0,  9, -1        },
+	{  5, 13, -1        },
+	{ -1                },
+	{  0,  8, -1        },
+	{ -1                },
+	{  0,  7, -1        },
+	{  0,  8, -1        },
+	{  8, 12, -1        },
+	{  0,  5, -1        },
+	{  0,  4, -1        },
+	{ -1                }
+};
+
+area_t kAreasTable[] = {
+	{ Areas::arMo           , AreaType::atCitadel,                           0,   0, 0,  1},
+	{ Areas::arTausCave     , AreaType::atCave   ,                           0, 112, 0,  2},
+	{ Areas::arChamaar      , AreaType::atValley ,                           0, 133, 0,  3},
+	{ Areas::arUluru        , AreaType::atValley ,                           0, 187, 0,  4},
+	{ Areas::arKoto         , AreaType::atValley , AreaFlags::HasVelociraptors, 236, 0,  5},
+	{ Areas::arTamara       , AreaType::atValley ,                           0, 288, 0,  6},
+	{ Areas::arCantura      , AreaType::atValley ,                           0, 334, 0,  7},
+	{ Areas::arShandovra    , AreaType::atValley ,                           0, 371, 0,  8},
+	{ Areas::arNarimsCave   , AreaType::atCave   ,                           0, 115, 0,  9},
+	{ Areas::arEmbalmersCave, AreaType::atCave   ,                           0, 118, 0, 10},
+	{ Areas::arWhiteArch    , AreaType::atCave   ,                           0, 122, 0, 11},
+	{ Areas::arMoorkusLair  , AreaType::atCave   ,                           0, 127, 0, 12}
+};
+
+short tab_2CEF0[64] = {
+	25, 257,  0,   0, 37, 258, 38, 259,  0,   0, 24, 260, 0, 0, 0, 0,
+	 0,   0, 53, 265,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
+	39, 261,  0,   0, 40, 262, 62, 263,  0,   0, 63, 264, 0, 0, 0, 0,
+	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0
+};
+
+short tab_2CF70[64] = {
+	65, 266,  0,   0, 66, 267, 67, 268,  0,   0, 68, 269, 0, 0, 0, 0,
+	 0,   0, 73, 274,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
+	69, 270,  0,   0, 70, 271, 71, 272,  0,   0, 72, 273, 0, 0, 0, 0,
+	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0,
+};
+
+short kActionCursors[299] = {
+	 3, 1, 2, 4, 5, 5, 5, 0, 5, 5,
+	 5, 5, 5, 3, 2, 5, 5, 5, 3, 2,
+	 4, 5, 7, 7, 4, 5, 5, 0, 0, 0,
+	 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+	 5, 5, 0, 0, 0, 0, 5, 5, 5, 5,
+	 5, 5, 5, 5, 5, 5, 5, 5, 0, 0,
+	 0, 0, 5, 5, 5, 5, 5, 5, 5, 5,
+	 5, 5, 5, 5, 0, 0, 0, 0, 5, 5,
+	 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+	 6, 6, 6, 6, 6, 6, 6, 0, 5, 6,
+	 6, 1, 6, 6, 0, 0, 6, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+	 8, 8, 8, 8, 8, 8, 0, 0, 6, 6,
+	53, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+struct cubeface_t {
+int				tri;
+char			ff_4;
+char			ff_5;
+
+unsigned char	*texptr;
+unsigned short	*indices;
+short			*uv;
+};
+typedef struct cubeface_t cubeface_t;
+
+struct cube_t {
+int				num;
+cubeface_t		**faces;
+short			*projection;	// projected XYZ coords
+short			*vertices;
+};
+typedef struct cube_t cube_t;
+
+float flt_2DF7C = -3400;
+float flt_2DF80 = -3400;
+float flt_2DF84 =   200;
+
+// Cube faces to texture coords mapping
+// each entry is num_polys(6) * num_faces_per_poly(2) * vertex_per_face(3) * uv(2)
+
+short cube_texcoords[3][6 * 2 * 3 * 2] = {
+	{
+		32, 32,  0, 32,  0,  0,
+		32, 32,  0,  0, 32,  0,
+
+		 0, 32,  0,  0, 32,  0,
+		 0, 32, 32,  0, 32, 32,
+
+		32, 32,  0, 32,  0,  0,
+		32, 32,  0,  0, 32,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		 0,  0, 32,  0, 32, 32,
+		 0,  0, 32, 32,  0, 32,
+
+		 0, 32,  0,  0, 32,  0,
+		 0, 32, 32,  0, 32, 32
+	}, {
+		32, 32,  0, 32,  0,  0,
+		32, 32,  0,  0, 32,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		 0, 32,  0,  0, 32,  0,
+		 0, 32, 32,  0, 32, 32,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0
+	}, {
+		30, 30,  2, 30,  2,  2,
+		30, 30,  2,  2, 30,  2,
+
+		 2, 30,  2,  2, 30,  2,
+		 2, 30, 30,  2, 30, 30,
+
+		30, 30,  2, 30,  2,  2,
+		30, 30,  2,  2, 30,  2,
+
+		30,  2, 30, 30,  2, 30,
+		30,  2,  2, 30,  2,  2,
+
+		 2,  2, 30,  2, 30, 30,
+		 2,  2, 30, 30,  2, 30,
+
+		 2, 30,  2,  2, 30,  2,
+		 2, 30, 30,  2, 30, 30
+	 }
+};
+
+char tab_2E138[4 * 3] = {
+	0, 0, 1, 1,
+	0, 0, 0, 1,
+	0, 0, 2, 0
+};
diff --git a/engines/cryo/detection.cpp b/engines/cryo/detection.cpp
new file mode 100644
index 0000000..1d6f145
--- /dev/null
+++ b/engines/cryo/detection.cpp
@@ -0,0 +1,131 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "base/plugins.h"
+
+#include "engines/advancedDetector.h"
+#include "common/file.h"
+
+#include "cryo/cryo.h"
+
+
+namespace Cryo {
+
+const char *CryoEngine::getGameId() const {
+	return _gameDescription->gameId;
+}
+
+}
+
+static const PlainGameDescriptor cryoGames[] = {
+	{"losteden", "Lost Eden"},
+	{0, 0}
+};
+
+namespace Cryo {
+
+static const ADGameDescription gameDescriptions[] = {
+
+	// Lost Eden PC non-interactive demo version
+	// Probably not worth it
+	{
+		"losteden",
+		0,
+		AD_ENTRY1s("EDEN6.HSQ", nullptr, 17093),
+		Common::EN_ANY,
+		Common::kPlatformDOS,
+		ADGF_DEMO,
+		GUIO1(GUIO_NONE)
+	},
+
+	// Lost Eden PC interactive demo version
+	{
+		"losteden",
+		0,
+		AD_ENTRY1s("EDEN.DAT", nullptr, 205473728),
+		Common::EN_ANY,
+		Common::kPlatformDOS,
+		ADGF_DEMO,
+		GUIO1(GUIO_NONE)
+	},
+
+	// Lost Eden PC version
+	{
+		"losteden",
+		0,
+		AD_ENTRY1s("EDEN.DAT", nullptr, 449853776),
+		Common::EN_ANY,
+		Common::kPlatformDOS,
+		ADGF_UNSTABLE,
+		GUIO1(GUIO_NONE)
+	},
+
+	// Lost Eden Mac version
+	{
+		"losteden",
+		0,
+		AD_ENTRY1s("EDEN.DAT", nullptr, 489739536),
+		Common::EN_ANY,
+		Common::kPlatformMacintosh,
+		ADGF_UNSTABLE,
+		GUIO1(GUIO_NONE)
+	},
+
+	AD_TABLE_END_MARKER
+};
+
+} // End of namespace Cryo
+
+class CryoMetaEngine : public AdvancedMetaEngine {
+public:
+	CryoMetaEngine() : AdvancedMetaEngine(Cryo::gameDescriptions, sizeof(ADGameDescription), cryoGames) {
+		_singleId = "losteden";
+	}
+
+	virtual const char *getName() const {
+		return "Cryo Engine";
+	}
+
+	virtual const char *getOriginalCopyright() const {
+		return "Cryo Engine (C) Cryo Interactive";
+	}
+
+	virtual bool hasFeature(MetaEngineFeature f) const;
+	virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
+};
+
+bool CryoMetaEngine::hasFeature(MetaEngineFeature f) const {
+	return false;
+}
+
+bool CryoMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
+	if (desc) {
+		*engine = new Cryo::CryoEngine(syst, desc);
+	}
+	return desc != 0;
+}
+
+#if PLUGIN_ENABLED_DYNAMIC(CRYO)
+	REGISTER_PLUGIN_DYNAMIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine);
+#else
+	REGISTER_PLUGIN_STATIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine);
+#endif
diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp
new file mode 100644
index 0000000..02fc66b
--- /dev/null
+++ b/engines/cryo/eden.cpp
@@ -0,0 +1,9457 @@
+//#include <stdint.h>
+
+#include "common/scummsys.h"
+
+#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/error.h"
+#include "gui/EventRecorder.h"
+#include "common/file.h"
+#include "common/savefile.h"
+#include "common/fs.h"
+#include "common/system.h"
+#include "graphics/surface.h"
+#include "graphics/screen.h"
+#include "graphics/palette.h"
+#include "common/timer.h"
+
+//#include "audio/audiostream.h"
+#include "audio/mixer.h"
+
+#include "cryo/cryo.h"
+#include "cryo/eden.h"
+
+namespace Cryo {
+
+#include "cryo/platdefs.h"
+#include "cryo/defs.h"
+#include "cryo/CryoLib.h"
+#include "cryo/CryoLibStub.c"
+
+short		word_2C300 = 0;
+short		word_2C302 = 0;
+short		word_2C304 = 0;
+
+unsigned char	allow_doubled = 1;
+int		curs_center = 11;
+
+struct {
+	short	x, y;
+} saved_repadam = { -1, -1 };
+
+class EdenGameImpl : EdenGame {
+private:
+
+short			old_scroll_pos, scroll_pos;
+short			word_2F514;
+unsigned char	fresqTalk;
+unsigned char	keep01, keep02, keep10, keep11, keep12, keep13, keep21, keep22;
+unsigned char	curs_keepbuf[2500];
+short			curs_keepy, curs_keepx;
+short			torchCursor;
+short			cur_bank_num;
+short			glow_h;
+short			glow_w;
+short			glow_y;
+short			glow_x;
+unsigned char	needPaletteUpdate;
+unsigned char	curs_saved;
+unsigned char	showBlackBars;
+unsigned char	fond_saved;
+unsigned char	*bank_data_ptr;
+color3_t		pal_entry;
+color_t			global_palette[256];	//TODO palette_t
+perso_t			*tyranPtr;
+int				last_anim_frame_num;
+int				cur_anim_frame_num;
+int				last_anim_ticks;
+prect_t			*cur_perso_rect;
+short			num_anim_frames;
+short			max_perso_desc;
+short			num_img_desc;
+unsigned char	restartAnimation;
+unsigned char	animationActive;
+unsigned char	animationDelay;
+unsigned char	animationIndex;
+unsigned char	lastAnimationIndex;
+
+unsigned char	*dword_30724;
+unsigned char	*dword_30728;	//TODO: rename - something amim-related
+unsigned char	*dword_3072C;	//TODO ditto
+unsigned char	*animationTable;
+unsigned char	imagedesc[512];
+unsigned char	*perso_img_bank_data_ptr;
+unsigned char	savedUnderSubtitles;
+short			num_text_lines;
+unsigned char	phraseBuffer[400];
+unsigned char	*text_ptr;
+unsigned char	phraseIconsBuffer[10];
+unsigned char	phraseCoordsBuffer[22];
+unsigned char	*textoutptr;
+unsigned char	*textout;
+object_t		*currentSpecialObject;
+short			word_30AFC;
+unsigned char	byte_30AFE;
+
+unsigned char	byte_30B00;
+int				dword_30B04;
+
+char			lastPhrasesFile;
+char			dialogSkipFlags;
+
+color3_t		newColor;
+color_t			oldPalette[256];	// TODO palette_t ?
+color_t			newPalette[256];
+rect_t			rect_dst, rect_src;
+void			*voiceSamplesBuffer;	//TODO: sound sample buffer
+file_t			h_bigfile;
+unsigned char	info_list[16];
+unsigned char	needToFade;
+unsigned char	lastMusicNum;
+unsigned char	*main_bank_buf;
+unsigned char	*music_buf;
+unsigned char	*gameLipsync;
+unsigned char	*gamePhrases;
+unsigned char	*gameDialogs;	//TODO: rename to dialogs?
+unsigned char	*gameConditions;
+void			*sal_buf;	//TODO: fixme
+unsigned char	*bank_data_buf;
+icon_t			*gameIcons;
+room_t			*gameRooms;
+pak_t			*bigfile_header;
+unsigned char	*glow_buffer;
+unsigned char	*p_mainview_buf;
+unsigned char	*p_view2_buf;
+unsigned char	*gameFont;	//TODO: rename to font?
+unsigned char	*p_subtitlesview_buf;
+unsigned char	*p_underSubtitlesView_buf;
+global_t		*p_global;
+unsigned short	mouse_y_center, mouse_x_center;
+int				quit_flag3;		//TODO: some obsolete error flag?
+unsigned short	machine_speed;
+unsigned char	quit_flag;
+
+unsigned char	gameStarted;
+
+unsigned char	quit_flag2;
+unsigned char	soundAllocated;
+soundchannel_t	*music_channel;
+soundchannel_t	*hnmsound_ch;
+sound_t			*voiceSound;
+
+view_t			*p_view2;
+view_t			*p_underSubtitlesView;
+view_t			*p_subtitlesview;
+view_t			*p_underBarsView;
+view_t			*p_mainview;
+view_t			*p_hnmview;
+hnm_t			*p_hnmcontext;
+filespec_t		bigfilespec;
+rect_t			underSubtitlesBackupRect, underSubtitlesScreenRect, underBottomBarBackupRect, underBottomBarScreenRect,
+				underTopBarBackupRect, underTopBarScreenRect, rect_31C7A;
+int				demoCurrentTicks;
+int				demoStartTicks;
+int				currentTime;
+short			mouse_y;
+short			mouse_x;
+short			doubled;
+short			curs_x_pan;
+short			inventoryScrollDelay;
+short			curs_y, curs_x;
+short			current_cursor;
+icon_t			*current_spot;
+icon_t			*current_spot2;
+unsigned char	pomme_q;
+unsigned char	keybd_held;
+unsigned char	mouse_held;
+unsigned char	normalCursor;
+unsigned char	*p_hnmview_buf;
+unsigned char	showVideoSubtitle;
+unsigned char	videoCanceled;	//TODO: hnm_canceled
+unsigned char	specialTextMode;
+int				hnm_position;
+int				voiceSamplesSize;	//TODO: perso vox sample data len
+short			mus_vol_right;
+short			mus_vol_left;
+
+
+unsigned char	animateTalking;
+unsigned char	personTalking;
+unsigned char	mus_fade_flags;
+
+char			musicSequencePos;
+unsigned char	musicPlaying;
+
+unsigned char	*mus_samples_ptr;
+unsigned char	*mus_patterns_ptr;	//TODO: sndblock_t ?
+unsigned char	*mus_sequence_ptr;
+soundgroup_t	*mus_queue_grp;
+short			*pCurrentObjectLocation;
+unsigned char	own_objects[128];
+unsigned char	byte_31D64;
+
+unsigned char	no_palette;
+unsigned char	gameLoaded;
+#define MAX_TAPES 16
+tape_t			tapes[MAX_TAPES];
+unsigned char	confirmMode;
+unsigned char	*cur_slider_value_ptr;
+unsigned char	lastMenuItemIdLo;
+short			lastTapeRoomNum;
+short			cur_slider_x;
+short			cur_slider_y;
+short			destinationRoom;
+short			word_31E7A;
+
+short			word_378CC;	//TODO: set by CLComputer_Init to 0
+short			word_378CE;
+
+void RemoveConsole()
+{
+}
+void scroll()
+{
+	restaurefrises();
+	p_mainview->norm.src_left = scroll_pos;
+	p_mainview->zoom.src_left = scroll_pos;
+	
+}
+void resetscroll()
+{
+	old_scroll_pos = scroll_pos;
+	scroll_pos = 0;
+	restaurefrises();	//TODO: inlined scroll() ?
+	p_mainview->norm.src_left = 0;
+	p_mainview->zoom.src_left = 0;
+}
+void scrollfresques()
+{
+	if(curs_y > 16 && curs_y < 176)
+	{
+		if(curs_x >= 0 && curs_x < 32 && scroll_pos > 3)
+		{
+			scroll_pos -= 4;
+		}
+		else if(curs_x > 288 && curs_x < 320 && scroll_pos < p_global->fresqWidth)
+		{
+			scroll_pos += 4;
+		}
+	}
+	scroll();
+	
+}
+void afffresques()
+{
+	use_bank(p_global->fresqImgBank);
+	noclipax(0, 0, 16);
+	use_bank(p_global->fresqImgBank + 1);
+	noclipax(0, 320, 16);
+	needPaletteUpdate = 1;
+}
+void gametofresques()
+{
+	fresqTalk = 0;
+	rundcurs();
+	sauvefrises();
+	afffresques();
+	p_global->displayFlags = DisplayFlags::dfFresques;
+}
+void dofresques()
+{
+	curs_saved = 0;
+	torchCursor = 1;
+	glow_x = -1;
+	glow_y = -1;
+	p_global->gameFlags |= GameFlags::gfFlag20;
+	p_global->ff_D4 = 0;
+	p_global->curObjectId = 0;
+	p_global->iconsIndex = 13;
+	p_global->autoDialog = 0;
+	gametofresques();
+	p_global->fresqNumber = 3;
+}
+void finfresques()
+{
+	torchCursor = 0;
+	curs_saved = 1;
+	p_global->displayFlags = DisplayFlags::dfFlag1;
+	resetscroll();
+	p_global->ff_100 = -1;
+	maj_salle(p_global->roomNum);
+	if(p_global->phaseNum == 114)
+		p_global->narratorSequence = 1;
+	p_global->eventType = EventType::etEvent8;
+	showevents();
+}
+void scrollmiroir()
+{
+	if(curs_y > 16 && curs_y < 165)
+	{
+		if(curs_x >= 0 && curs_x < 16)
+		{
+			if(scroll_pos > 3)
+			{
+				if(doubled)
+					scroll_pos -= 2;
+				else
+					scroll_pos -= 1;
+				scroll();
+			}
+		}
+		else if(curs_x > 290 && curs_x < 320)
+		{
+			if(scroll_pos < 320)
+			{
+				if(doubled)
+					scroll_pos += 2;
+				else
+					scroll_pos += 1;
+				scroll();
+			}
+		}
+	}
+}
+void scrollpano()
+{
+	if(curs_y > 16 && curs_y < 165)
+	{
+		if(curs_x >= 0 && curs_x < 16)
+		{
+			if(scroll_pos > 3)
+			{
+				if(doubled)
+					scroll_pos -= 2;
+				else
+					scroll_pos -= 1;
+			}		                         	
+		}
+		else if(curs_x > 290 && curs_x < 320)
+		{
+			if(scroll_pos < 320)
+			{
+				if(doubled)
+					scroll_pos += 2;
+				else
+					scroll_pos += 1;
+			}
+		}
+	}
+	scroll();
+}    
+void affsuiveur(suiveur_t *suiveur, short x, short y)
+{
+	use_bank(suiveur->bank);
+	noclipax(suiveur->image, x, y + 16);	
+}
+void persoinmiroir()
+{
+	icon_t	*icon1 = &gameIcons[3];
+	icon_t	*icon = &gameIcons[28];
+	suiveur_t *suiveur = suiveurs_list;
+	short num = 1;
+	int i;
+	for(i = 0;i < 16;i++)
+	{
+		if(p_global->party & (1 << i))
+			num++;
+	}
+	icon += num;
+	icon->sx = -1;
+	icon--;
+	icon->sx = icon1->sx;
+	icon->sy = icon1->sy;
+	icon->ex = icon1->ex;
+	icon->ey = 170;
+	icon->cursor_id = icon1->cursor_id;
+	icon->action_id = icon1->action_id;
+	icon->object_id = icon1->object_id;
+	icon--;
+	affsuiveur(suiveur, suiveur->sx, suiveur->sy);
+	for(;suiveur->id != -1;suiveur++)
+	{
+		perso_t *perso;
+		for(perso = kPersons;perso != &kPersons[PER_UNKN_156];perso++)
+		{
+			if (perso->id != suiveur->id)						continue;
+			if (perso->flags & PersonFlags::pf80)				continue;
+			if ((perso->flags & PersonFlags::pfInParty) == 0)	continue;
+			if (perso->roomNum != p_global->roomNum)			continue;
+			icon->sx = suiveur->sx;
+			icon->sy = suiveur->sy;
+			icon->ex = suiveur->ex;
+			icon->ey = suiveur->ey;
+			icon->cursor_id = 8;
+			icon->action_id = perso->actionId;
+			icon--;
+			affsuiveur(suiveur, suiveur->sx, suiveur->sy);
+			break;
+		}
+	}
+}
+void gametomiroir(unsigned char arg1)
+{
+	short bank;
+	if(p_global->displayFlags != DisplayFlags::dfFlag2)
+	{
+		rundcurs();
+		restaurefrises();
+		afftopscr();
+		showobjects();
+		sauvefrises();
+	}
+	bank = p_global->roomBgBankNum;
+	if(bank == 76 || bank == 128)
+		bank = 2161;
+	use_bank(bank + 326);
+	noclipax(0, 0, 16);
+	use_bank(bank + 327);
+	noclipax(0, 320, 16);
+	persoinmiroir();
+	needPaletteUpdate = 1;
+	p_global->iconsIndex = 16;
+	p_global->autoDialog = 0;
+	p_global->displayFlags = DisplayFlags::dfMirror;
+	p_global->ff_102 = arg1;
+}
+void flipmode()
+{
+	if(personTalking)
+	{
+		endpersovox();
+		if(p_global->displayFlags == DisplayFlags::dfPerson)
+		{
+			if(p_global->perso_ptr == &kPersons[PER_THOO] && p_global->phaseNum >= 80)
+				af_subtitle();
+			else
+			{
+				getdatasync();
+				load_perso_cour();
+				addanim();
+				restartAnimation = 1;
+				anim_perso();
+			}
+		}
+		else
+			af_subtitle();
+		persovox();
+	}
+	else
+	{
+		if(p_global->displayFlags != DisplayFlags::dfFresques && p_global->displayFlags != DisplayFlags::dfFlag2)
+		{
+			closesalle();
+			if(p_global->displayFlags & DisplayFlags::dfFlag1)
+				gametomiroir(1);
+			else
+			{
+				quitmiroir();
+				maj_salle(p_global->roomNum);
+				if(byte_31D64)
+				{
+					dialautoon();
+					parle_moi();
+				}
+				byte_31D64 = 0;
+			}
+		}
+	}
+}
+void quitmiroir()
+{
+	rundcurs();
+	afficher();
+	resetscroll();
+	sauvefrises();
+	p_global->displayFlags = DisplayFlags::dfFlag1;
+	p_global->ff_100 = -1;
+	p_global->eventType = EventType::etEventC;
+	p_global->ff_102 = 1;
+}
+void clictimbre()
+{
+	flipmode();
+}
+void clicplanval()
+{
+	if((p_global->partyOutside & PersonMask::pmDina) && p_global->phaseNum == 371)
+	{
+		quitmiroir();
+		maj_salle(p_global->roomNum);
+		return;
+	}
+	if(p_global->roomNum == 8 || p_global->roomNum < 16)
+		return;
+	rundcurs();
+	afficher();
+	if(p_global->displayFlags == DisplayFlags::dfMirror)
+		quitmiroir();
+	deplaval((p_global->roomNum & 0xFF00) | 1);	//TODO: check me
+}
+void gotolieu(goto_t *go)
+{
+	p_global->valleyVidNum = go->arriveVid;
+	p_global->travelTime = go->travelTime * 256;
+	p_global->stepsToFindAppleFast = 0;
+	p_global->eventType = EventType::etEvent2;
+	init_oui();
+	showevents();
+	if(!verif_oui())
+		return;
+	if(p_global->ff_113)
+	{
+		waitendspeak();
+		if(!pomme_q)
+			close_perso();
+	}
+	if(go->departVid)
+	{
+		bars_out();
+		playhnm(go->departVid);
+		needToFade = 1;
+	}
+	initlieu(p_global->newRoomNum);
+	specialoutside();
+	faire_suivre(p_global->newRoomNum);
+	closesalle();
+	saved_repadam.x = -1;
+	saved_repadam.y = -1;
+	temps_passe(p_global->travelTime);
+	p_global->ff_100 = p_global->room_ptr->ff_0;
+	p_global->roomNum = p_global->newRoomNum;
+	p_global->areaNum = p_global->roomNum >> 8;
+	p_global->eventType = EventType::etEvent5;
+	p_global->newMusicType = MusicType::mt2;
+	setpersohere();
+	musique();
+	majsalle1(p_global->roomNum);
+	afftopscr();
+	saved_repadam.x = -1;
+	saved_repadam.y = -1;
+}
+void deplaval(unsigned short roomNum)
+{
+	unsigned char c1, newAreaNum, curAreaNum;
+	short newRoomNum;
+	p_global->newLocation = roomNum & 0xFF;
+	p_global->valleyVidNum = 0;
+	p_global->phaseActionsCount++;
+	closesalle();
+	endpersovox();
+	c1 = roomNum & 0xFF;
+	if(c1 == 0)
+		return;
+	if(c1 < 0x80)
+	{
+		p_global->displayFlags = DisplayFlags::dfFlag1;
+		init_oui();
+		p_global->eventType = EventType::etEvent1;
+		showevents();
+		if(!verif_oui())
+			return;
+		if(p_global->ff_113)
+		{
+			waitendspeak();
+			if(!pomme_q)
+				close_perso();
+		}
+		specialout();
+		if(p_global->area_ptr->type == AreaType::atValley)
+		{
+			temps_passe(32);
+			p_global->stepsToFindAppleFast++;
+			p_global->stepsToFindAppleNormal++;
+		}
+		faire_suivre((roomNum & 0xFF00) | p_global->newLocation);
+		p_global->ff_100 = p_global->room_ptr->ff_0;
+		p_global->roomNum = roomNum;
+		p_global->areaNum = roomNum >> 8;
+		p_global->eventType = EventType::etEvent5;
+		setpersohere();
+		p_global->newMusicType = MusicType::mtNormal;
+		musique();
+		majsalle1(roomNum);
+		p_global->chrono_on = 0;
+		p_global->chrono = 0;
+		p_global->ff_54 = 0;
+		if(p_global->roomPersoType == PersonFlags::pftTyrann)
+			chronoon(3000);
+		return;
+	}
+	if(c1 == 0xFF)
+	{
+		p_global->eventType = EventType::etEventE;
+		showevents();
+		if(!kPersons[PER_MESSAGER].roomNum)
+		{
+			if(eloirevientq())
+				chronoon(800);
+		}
+		return;
+	}
+	p_global->stepsToFindAppleFast = 0;
+	newAreaNum = c1 & 0x7F;
+	curAreaNum = p_global->roomNum >> 8;
+	newRoomNum = newAreaNum << 8;
+	if(curAreaNum == Areas::arTausCave && newAreaNum == Areas::arMo)
+		newRoomNum |= 0x16;
+	else if(curAreaNum == Areas::arMoorkusLair)
+		newRoomNum |= 4;
+	else
+		newRoomNum |= 1;
+	p_global->newRoomNum = newRoomNum;
+	if(newAreaNum == Areas::arTausCave)
+		gotolieu(&gotos[0]);
+	else
+	{
+		goto_t *go;
+		for(go = gotos + 1;go->curAreaNum != 0xFF;go++)
+			if(go->curAreaNum == curAreaNum)
+			{
+				gotolieu(go);
+				break;
+			}
+	}
+}
+void deplacement(short dir)
+{
+	room_t *room = p_global->room_ptr;
+	short roomNum = p_global->roomNum;
+	debug("deplacement: from room %4X", roomNum);
+	char newLoc;
+	rundcurs();
+	afficher();
+	p_global->prevLocation = roomNum & 0xFF;
+	switch(dir)
+	{
+	case 0: newLoc = room->exits[0]; break;
+	case 1: newLoc = room->exits[1]; break;
+	case 2: newLoc = room->exits[2]; break;
+	case 3: newLoc = room->exits[3]; break;
+	}
+	deplaval((roomNum & 0xFF00) | newLoc);
+}    
+void deplacement2(short dir)
+{
+	room_t *room = p_global->room_ptr;
+	short roomNum = p_global->roomNum;
+	char newLoc;
+	p_global->prevLocation = roomNum & 0xFF;
+	switch(dir)
+	{
+	case 0: newLoc = room->exits[0]; break;
+	case 1: newLoc = room->exits[1]; break;
+	case 2: newLoc = room->exits[2]; break;
+	case 3: newLoc = room->exits[3]; break;
+	}
+	deplaval((roomNum & 0xFF00) | newLoc);
+
+}
+void dinosoufle()
+{
+	if(p_global->curObjectId == 0)
+	{
+		bars_out();
+		playhnm(148);
+		maj2();
+	}
+}
+void plaquemonk()
+{
+	if(p_global->curObjectId != 0)
+	{
+		if(p_global->curObjectId == Objects::obPrism)
+		{
+			loseobject(Objects::obPrism);
+			bars_out();
+			specialTextMode = 1;
+			playhnm(89);
+			word_2F514 |= 0x8000;
+			maj2();
+			p_global->eventType = EventType::etEventB;
+			showevents();
+		}
+	}
+	else
+	{
+		bars_out();
+		playhnm(7);
+		maj2();
+		p_global->eventType = EventType::etEvent4;
+		showevents();
+	}
+}
+void fresquesgraa()
+{
+	if(p_global->curObjectId == 0)
+	{
+		p_global->fresqWidth = 320;
+		p_global->fresqImgBank = 113;
+		dofresques();
+		dinaparle();
+	}
+}
+void fresqueslasc()
+{
+	if(p_global->curObjectId == 0)
+	{
+		p_global->fresqWidth = 112;
+		p_global->fresqImgBank = 315;
+		dofresques();
+	}
+}
+void pushpierre()
+{
+	if(p_global->curObjectId == 0)
+	{
+		gameRooms[22].exits[0] = 17;
+		gameRooms[26].exits[2] = 9;
+		deplacement(0);
+	}
+}
+void tetemomie()
+{
+	if(p_global->curObjectId == Objects::obTooth)
+	{
+		p_global->gameFlags |= GameFlags::gfMummyOpened;
+		deplacement(0);
+	}
+	else if(p_global->curObjectId == 0)
+	{
+		if(p_global->gameFlags & GameFlags::gfMummyOpened)
+			deplacement(0);
+		else
+		{
+			p_global->eventType = EventType::etEvent6;
+			persoparle(PersonId::pidMonk);
+			p_global->eventType = 0;
+		}
+	}
+}
+void tetesquel()
+{
+	if(p_global->curObjectId == Objects::obTooth)
+	{
+		gameRooms[22].exits[0] = 16;
+		gameRooms[26].exits[2] = 13;
+		gameIcons[16].cursor_id |= 0x8000;
+		loseobject(Objects::obTooth);
+		deplacement(0);
+	}
+}
+void squelmoorkong()
+{
+	p_global->eventType = EventType::etEvent9;
+	showevents();
+}
+void choisir()
+{
+	unsigned char obj, objid = current_spot2->object_id;
+	switch(objid)
+	{
+	case 0: obj = p_global->giveobj1; break;
+	case 1: obj = p_global->giveobj2; break;
+	case 2: obj = p_global->giveobj3; break;
+	}
+	objectmain(obj);
+	winobject(obj);
+	p_global->iconsIndex = 16;
+	p_global->autoDialog = 0;
+	p_global->ff_60 = 0;
+	parle_moi();
+}
+void dinaparle()
+{
+	short num;
+	char res;
+	perso_t *perso = &kPersons[PER_DINA];
+	if(perso->party & (p_global->party | p_global->partyOutside))
+	{
+		if(p_global->fresqNumber < 3)
+			p_global->fresqNumber = 3;
+		p_global->fresqNumber++;
+		if(p_global->fresqNumber < 15)
+		{
+			endpersovox();
+			if(p_global->fresqNumber == 7 && p_global->phaseNum == 113)
+				incphase1();
+			p_global->perso_ptr = perso;
+			p_global->dialogType = DialogType::dtInspect;
+			num = (perso->id << 3) | DialogType::dtInspect;	//TODO: combine
+			res = dialoscansvmas((dial_t*)GetElem(gameDialogs, num));
+			fresqTalk = 0;
+			if(res)
+			{
+				restaurefondbulle();
+				fresqTalk = 1;
+				persovox();
+			}
+			p_global->ff_CA = 0;
+			p_global->dialogType = 0;
+		}
+		else
+			finfresques();
+	}
+}
+void roiparle()
+{
+	if(p_global->phaseNum <= 400)
+		persoparle(0);
+}
+void roiparle1()
+{
+	if(p_global->curObjectId == Objects::obSword)
+	{
+		p_global->gameFlags |= GameFlags::gfFlag80;
+		bars_out();
+		playhnm(76);
+		deplacement2(0);
+	}
+	else
+	{
+		p_global->fresqNumber = 1;
+		roiparle();
+	}
+}
+void roiparle2()
+{
+	p_global->fresqNumber = 2;
+	roiparle();
+}
+void roiparle3()
+{
+	p_global->fresqNumber = 3;
+	roiparle();
+}
+void getcouteau()
+{
+	if(p_global->phaseNum >= 80)
+	{
+		gameRooms[113].video = 0;
+		getobject(Objects::obKnife);
+	}
+	p_global->eventType = EventType::etEvent7;
+	showevents();
+}
+void getprisme()
+{
+	getobject(Objects::obPrism);
+	p_global->eventType = EventType::etEvent7;
+	showevents();
+}
+void getchampb()
+{
+	getobject(Objects::obShroom);
+}
+void getchampm()
+{
+	getobject(Objects::obBadShroom);
+}
+void getor()
+{
+	getobject(Objects::obGold);
+}
+void getnido()
+{
+	if(p_global->curObjectId != 0)
+		return;
+	p_global->room_ptr->bank = 282;	//TODO: fix me
+	p_global->room_ptr--;
+	p_global->room_ptr->bank = 281;	//TODO: fix me
+	p_global->room_ptr->ff_0 = 3;
+	getobject(Objects::obFullNest);
+}
+void getnidv()
+{
+	if(p_global->curObjectId != 0)
+		return;
+	p_global->room_ptr->bank = 282;	//TODO: fix me
+	p_global->room_ptr--;
+	p_global->room_ptr->bank = 281;	//TODO: fix me
+	p_global->room_ptr->ff_0 = 3;
+	getobject(Objects::obNest);
+}
+void getcorne()
+{
+	if(p_global->curObjectId != 0)
+		return;
+	getobject(Objects::obHorn);
+	p_global->eventType = EventType::etEvent7;
+	showevents();
+	bigphase1();
+	setpersohere();
+	p_global->room_ptr = getsalle(p_global->roomNum);
+}
+void getsoleil()
+{
+	if(p_global->curObjectId != 0)
+		return;
+	gameRooms[238].video = 0;
+	gameRooms[238].flags = RoomFlags::rf80;
+	getobject(Objects::obSunStone);
+}
+void getoeuf()
+{
+	if(p_global->curObjectId != 0)
+		return;
+	p_global->room_ptr->flags = 0;
+	p_global->room_ptr->video = 0;
+	getobject(Objects::obEgg);
+}
+void getplaque()
+{
+	int i;
+	if(p_global->curObjectId != 0 && p_global->curObjectId < Objects::obTablet1)
+		return;
+	p_global->curObjectId = 0;
+	getobject(Objects::obTablet2);
+	putobject();
+	for(i = 0;i < 6;i++)
+		objects[Objects::obTablet1 - 1 + i].count = 0;
+	p_global->curObjectFlags = 0;
+	p_global->inventoryScrollPos = 0;
+	p_global->curObjectCursor = 9;
+	gameIcons[16].cursor_id |= 0x8000;
+	showobjects();
+	gameRooms[131].video = 0;
+	bars_out();
+	playhnm(149);
+	p_global->ff_F1 = RoomFlags::rf04;
+	p_global->drawFlags = DrawFlags::drDrawFlag20;
+	normalCursor = 1;
+	maj2();
+}
+void voirlac()
+{
+	perso_t *perso = &kPersons[PER_MORKUS];
+	room_t *room = p_global->room_ptr;
+	area_t *area = p_global->area_ptr;
+	short vid = p_global->curObjectId == Objects::obApple ? 81 : 54;
+	for(++perso;perso->roomNum != 0xFFFF;perso++)
+	{
+		if(perso->roomNum != p_global->roomNum)
+			continue;
+		vid++;
+		if (p_global->curObjectId != Objects::obApple)
+			continue;					//TODO: pc breaks here
+		if((perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftMosasaurus)
+			continue;
+		if (!(perso->flags & PersonFlags::pf80))
+			return;
+		perso->flags &= ~PersonFlags::pf80;	//TODO: useless? see above
+		area->flags |= AreaFlags::afFlag8;
+		p_global->curAreaFlags |= AreaFlags::afFlag8;
+		room->ff_0 = 3;
+	}
+	debug("sea monster: room = %X, d0 = %X\n", p_global->roomNum, p_global->roomImgBank);
+	bars_out();
+	playhnm(vid);
+	maj_salle(p_global->roomNum);			//TODO: getting memory trashed here?
+	if (p_global->curObjectId == Objects::obApple)
+		loseobject(Objects::obApple);
+	p_global->eventType = EventType::etEventF;
+	showevents();
+}
+void gotohall()
+{
+	p_global->prevLocation = p_global->roomNum & 0xFF;
+	deplaval((p_global->roomNum & 0xFF00) | 6);
+}
+void demitourlabi()
+{
+	unsigned short target;
+	p_global->prevLocation = p_global->roomNum & 0xFF;
+	p_global->ff_100 = -1;
+	target = (p_global->roomNum & 0xFF00) | p_global->room_ptr->exits[2];
+	faire_suivre(target);
+	p_global->roomNum = target;
+	p_global->eventType = EventType::etEvent5;
+	maj_salle(p_global->roomNum);
+}
+void gotonido()
+{
+	p_global->room_ptr++;
+	p_global->eventType = 0;
+	p_global->roomImgBank = p_global->room_ptr->bank;
+	p_global->roomVidNum = p_global->room_ptr->video;
+	p_global->curRoomFlags = p_global->room_ptr->flags;
+	p_global->ff_F1 = p_global->room_ptr->flags;
+	animpiece();
+	p_global->ff_100 = 0;
+	maj2();	
+}
+void gotoval()
+{
+	unsigned short target = p_global->roomNum;
+	char obj;
+	rundcurs();
+	afficher();
+	scroll_pos = 0;
+	obj = current_spot2->object_id - 14;	//TODO
+	p_global->prevLocation = target & 0xFF;
+	deplaval((target & 0xFF00) | obj);	//TODO careful!
+}
+void visiter()
+{
+	bars_out();
+	playhnm(144);
+	p_global->ff_F1 = RoomFlags::rf04;
+	maj2();
+}
+void final()
+{
+	if(p_global->curObjectId != 0)
+		return;
+	bars_out();
+	*(short*)(gameRooms + 0x6DC) = 319;	//TODO
+	p_global->roomImgBank = 319;
+	playhnm(97);
+	maj2();
+	p_global->eventType = EventType::etEvent12;
+	showevents();
+	p_global->narratorSequence = 54;
+}
+void goto_nord()
+{
+	if(p_global->curObjectId == 0)
+		deplacement(0);
+}
+void goto_est()
+{
+	if(p_global->curObjectId == 0)
+		deplacement(1);
+}
+void goto_sud()
+{
+	if(p_global->curObjectId == 0)
+		deplacement(2);
+}
+void goto_ouest()
+{
+	if(p_global->curObjectId == 0)
+		deplacement(3);
+}
+void afficher()
+{
+	if(!p_global->ff_102 && !p_global->ff_103)
+	{
+		if(needPaletteUpdate)
+		{
+			needPaletteUpdate = 0;
+			CLPalette_Send2Screen(global_palette, 0, 256);
+		}
+		CLBlitter_CopyView2Screen(p_mainview);
+	}
+	else
+	{
+		if(p_global->ff_102)
+			effet3();
+		else
+			effet2();
+		p_global->ff_103 = 0;
+		p_global->ff_102 = 0;
+	}
+}
+void afficher128()
+{
+	if(p_global->updatePaletteFlag == 16)
+	{
+		CLPalette_Send2Screen(global_palette, 0, 129);
+		CLBlitter_CopyView2Screen(p_mainview);
+		p_global->updatePaletteFlag = 0;
+	}
+	else
+	{
+		ClearScreen();
+		fadetoblack128(1);
+		if(showBlackBars)
+			blackbars();
+		CLBlitter_CopyView2Screen(p_mainview);
+		fadefromblack128(1);
+	}
+}
+void sauvefrises()
+{
+	sauvefriseshaut(0);
+	sauvefrisesbas();
+}
+void sauvefriseshaut(short x)	// Save top bar
+{
+	underTopBarScreenRect.sy = 0;		//TODO: wrong fields order?
+	underTopBarScreenRect.sx = x;
+	underTopBarScreenRect.ex = x + 320 - 1;
+	underTopBarScreenRect.ey = 15;
+	underTopBarBackupRect.sy = 0;
+	underTopBarBackupRect.sx = 0;
+	underTopBarBackupRect.ex = 320 - 1;
+	underTopBarBackupRect.ey = 15;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
+}
+void sauvefrisesbas()			// Save bottom bar
+{
+	underBottomBarScreenRect.sx = 0;
+	underBottomBarScreenRect.ex = 320 - 1;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
+}
+void restaurefrises()
+{
+	restaurefriseshaut();
+	restaurefrisesbas();
+}
+void restaurefriseshaut()
+{
+	underTopBarScreenRect.sx = scroll_pos;
+	underTopBarScreenRect.ex = scroll_pos + 320 - 1;
+	CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarBackupRect, &underTopBarScreenRect);
+}
+void restaurefrisesbas()
+{
+	underBottomBarScreenRect.sx = scroll_pos;
+	underBottomBarScreenRect.ex = scroll_pos + 320 - 1;
+	CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underBottomBarBackupRect, &underBottomBarScreenRect);
+}
+void use_main_bank()
+{
+	bank_data_ptr = main_bank_buf;
+}
+void use_bank(short bank)
+{
+	if (bank > 2500)
+		debug("attempt to load bad bank %d", bank);
+	bank_data_ptr = bank_data_buf;
+	if(cur_bank_num != bank)
+	{
+		loadfile(bank, bank_data_buf);
+		verifh(bank_data_buf);
+		cur_bank_num = bank;
+	}
+}    
+void sundcurs(short x, short y)
+{
+	unsigned char *scr, *keep = curs_keepbuf;
+	short w, h;
+	curs_keepx = x - 4;
+	curs_keepy = y - 4;
+	scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
+	for(h = 48;h--;)
+	{
+		for(w = 48;w--;)
+			*keep++ = *scr++;
+		scr += 640 - 48;
+	}
+	curs_saved = 1;
+}
+void rundcurs()
+{
+	unsigned char *scr, *keep = curs_keepbuf;
+	short w, h;
+	scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
+	if(!curs_saved || (curs_keepx == -1 && curs_keepy == -1))	//TODO ...
+		return;
+	for(h = 48;h--;)
+	{
+		for(w = 48;w--;)
+			*scr++ = *keep++;
+		scr += 640 - 48;
+	}
+	
+}
+void noclipax(short index, short x, short y)
+{
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr = p_mainview_buf + x + y * 640;
+	unsigned char h0, h1, mode;
+	short w, h;
+	if(cur_bank_num != 117 && !no_palette)
+	{
+		if(PLE16(pix) > 2)
+			readpalette(pix + 2);
+	}
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//	short	height:9
+	//	short	pad:6;
+	//	short	flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	debug("- draw sprite %d at %d:%d, %dx%d", index, x, y, w, h);
+	if (mode != 0xFF && mode != 0xFE)
+		return;
+	if(y + h > 200)
+		h -= (y + h - 200);
+	if(h1 & 0x80)
+	{
+	// compressed
+		for(;h-- > 0;)
+		{
+			short ww;
+			for(ww = w;ww > 0;)
+			{
+				unsigned char c = *pix++;
+				if(c >= 0x80)
+				{
+					if(c == 0x80)
+					{
+						unsigned char fill = *pix++;
+						if(fill == 0)
+						{
+							scr += 128 + 1;
+							ww -= 128 + 1;
+						}
+						else
+						{
+							unsigned char run;
+							*scr++ = fill;	//TODO: wha?
+							*scr++ = fill;
+							ww -= 128 + 1;
+							for(run = 127;run--;)
+								*scr++ = fill;
+						}
+					}
+					else
+					{
+						unsigned char fill = *pix++;
+						unsigned char run = 255 - c + 2;
+						ww -= run;
+						if(fill == 0)
+							scr += run;
+						else
+							for(;run--;)
+								*scr++ = fill;
+					}
+				}
+				else
+				{
+					unsigned char run = c + 1;
+					ww -= run;
+					for(;run--;)
+					{
+						unsigned char p = *pix++;
+						if(p == 0)
+							scr++;
+						else
+							*scr++ = p;
+					}
+				}
+			}
+			scr += 640 - w;
+		}
+	}
+	else
+	{
+		// uncompressed
+		for(;h--;)
+		{
+			short ww;
+			for(ww = w;ww--;)
+			{
+				unsigned char p = *pix++;
+				if(p == 0)
+					scr++;
+				else
+					*scr++ = p;
+			}
+			scr += 640 - w;
+		}
+	}
+}
+void noclipax_avecnoir(short index, short x, short y)
+{
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr = p_mainview_buf + x + y * 640;
+	unsigned char h0, h1, mode;
+	short w, h;
+	if(cur_bank_num != 117)
+	{
+		if(PLE16(pix) > 2)
+			readpalette(pix + 2);
+	}
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//	short	height:9
+	//	short	pad:6;
+	//	short	flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	if(mode != 0xFF && mode != 0xFE)
+		return;
+	if(y + h > 200)
+		h -= (y + h - 200);
+	if(h1 & 0x80)
+	{
+	// compressed
+		for(;h-- > 0;)
+		{
+			short ww;
+			for(ww = w;ww > 0;)
+			{
+				unsigned char c = *pix++;
+				if(c >= 0x80)
+				{
+					if(c == 0x80)
+					{
+						unsigned char fill = *pix++;
+						unsigned char run;
+						*scr++ = fill;	//TODO: wha?
+						*scr++ = fill;
+						ww -= 128 + 1;
+						for(run = 127;run--;)
+							*scr++ = fill;
+					}
+					else
+					{
+						unsigned char fill = *pix++;
+						unsigned char run = 255 - c + 2;
+						ww -= run;
+						for(;run--;)
+							*scr++ = fill;
+					}
+				}
+				else
+				{
+					unsigned char run = c + 1;
+					ww -= run;
+					for(;run--;)
+					{
+						unsigned char p = *pix++;
+						*scr++ = p;
+					}
+				}
+			}
+			scr += 640 - w;
+		}
+	}
+	else
+	{
+		// uncompressed
+		for(;h--;)
+		{
+			short ww;
+			for(ww = w;ww--;)
+			{
+				unsigned char p = *pix++;
+				*scr++ = p;
+			}
+			scr += 640 - w;
+		}
+	}
+}
+void getglow(short x, short y, short w, short h)
+{
+	unsigned char *scr = p_mainview_buf + x + y * 640;
+	unsigned char *gl = glow_buffer;
+	glow_x = x;
+	glow_y = y;
+	glow_w = w;
+	glow_h = h;
+	for(;h--;)
+	{
+		short ww;
+		for(ww = w;ww--;)
+			*gl++ = *scr++;
+		scr += 640 - w;
+	}
+}
+void unglow()
+{
+	unsigned char *gl = glow_buffer;
+	unsigned char *scr = p_mainview_buf + glow_x + glow_y * 640;
+	if(glow_x < 0 || glow_y < 0)	//TODO: move it up
+		return;
+	for(;glow_h--;)
+	{
+		short ww;
+		for(ww = glow_w;ww--;)
+			*scr++ = *gl++;
+		scr += 640 - glow_w;
+	}
+}
+void glow(short index)
+{
+	unsigned char pixbase;
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr;
+	unsigned char h0, h1, mode;
+	short w, h, x, y, ex, dx, dy, pstride, sstride;
+	index += 9;
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//	short	height:9
+	//	short	pad:6;
+	//	short	flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	if(mode != 0xFF && mode != 0xFE)
+		return;
+
+	x = curs_x + scroll_pos - 38;
+	y = curs_y - 28;
+	ex = p_global->fresqWidth + 320;
+
+	if(x + w <= 0 || x >= ex || y + h <= 0 || y >= 176)
+		return;
+
+	if(x < 0)
+	{
+		dx = -x;
+		x = 0;
+	}
+	else if(x + w > ex)
+		dx = x + w - ex;
+	else
+		dx = 0;
+
+	if(y < 16)
+	{
+		dy = 16 - y;
+		y = 16;
+	}
+	else if(y + h > 175)
+		dy = y + h - 175;
+	else
+		dy = 0;
+	pstride = dx;
+	sstride = 640 - (w - dx);
+	if(y == 16)
+		pix += w * dy;
+	if(x == 0)
+		pix += dx;
+
+	scr = p_mainview_buf + x + y * 640;
+
+	w -= dx;
+	h -= dy;
+
+	getglow(x, y, w, h);
+
+	for(;h--;)
+	{
+		short ww;
+		for(ww = w;ww--;)
+		{
+			unsigned char p = *pix++;
+			if(p == 0)
+				scr++;
+			else
+				*scr++ += p << 4;
+		}
+		pix += pstride;
+		scr += sstride;
+	}
+}
+void readpalette(unsigned char *ptr)
+{
+	int doit = 1;
+	while(doit)
+	{
+		unsigned short idx = *ptr++;
+		if(idx != 0xFF)
+		{
+			unsigned short cnt = *ptr++;
+			while(cnt--)
+			{
+				if(idx == 0)
+				{
+					pal_entry.r = 0;
+					pal_entry.g = 0;
+					pal_entry.b = 0;
+					ptr += 3;
+				}
+				else
+				{
+					pal_entry.r = *ptr++ << 10;
+					pal_entry.g = *ptr++ << 10;
+					pal_entry.b = *ptr++ << 10;
+				}
+				CLPalette_SetRGBColor(global_palette, idx, &pal_entry);
+				idx++;
+			}
+		}
+		else
+			doit = 0;
+	}
+}
+void spritesurbulle(short index, short x, short y)
+{
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr = p_subtitlesview_buf + x + y * subtitles_x_width;
+	unsigned char h0, h1, mode;
+	short w, h;
+	if(cur_bank_num != 117)
+	{
+		if(PLE16(pix) > 2)
+			readpalette(pix + 2);
+	}
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//	short	height:9
+	//	short	pad:6;
+	//	short	flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	if(mode != 0xFF && mode != 0xFE)
+		return;
+	if(h1 & 0x80)
+	{
+	// compressed
+		for(;h-- > 0;)
+		{
+			short ww;
+			for(ww = w;ww > 0;)
+			{
+				unsigned char c = *pix++;
+				if(c >= 0x80)
+				{
+					if(c == 0x80)
+					{
+						unsigned char fill = *pix++;
+						if(fill == 0)
+						{
+							scr += 128 + 1;
+							ww -= 128 + 1;
+						}
+						else
+						{
+							unsigned char run;
+							*scr++ = fill;	//TODO: wha?
+							*scr++ = fill;
+							ww -= 128 + 1;
+							for(run = 127;run--;)
+								*scr++ = fill;
+						}
+					}
+					else
+					{
+						unsigned char fill = *pix++;
+						unsigned char run = 255 - c + 2;
+						ww -= run;
+						if(fill == 0)
+							scr += run;
+						else
+							for(;run--;)
+								*scr++ = fill;
+					}
+				}
+				else
+				{
+					unsigned char run = c + 1;
+					ww -= run;
+					for(;run--;)
+					{
+						unsigned char p = *pix++;
+						if(p == 0)
+							scr++;
+						else
+							*scr++ = p;
+					}
+				}
+			}
+			scr += subtitles_x_width - w;
+		}
+	}
+	else
+	{
+		// uncompressed
+		for(;h--;)
+		{
+			short ww;
+			for(ww = w;ww--;)
+			{
+				unsigned char p = *pix++;
+				if(p == 0)
+					scr++;
+				else
+					*scr++ = p;
+			}
+			scr += subtitles_x_width - w;
+		}
+	}
+}
+void bars_out()
+{
+	short i, r19, r20, r25, r24;
+	unsigned int *scr40, *scr41, *scr42;
+	if(showBlackBars)
+		return;
+	afficher();
+	underTopBarScreenRect.sx = scroll_pos;
+	underTopBarScreenRect.ex = scroll_pos + 320 - 1;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
+	underBottomBarScreenRect.sx = underTopBarScreenRect.sx;
+	underBottomBarScreenRect.ex = underTopBarScreenRect.ex;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
+	r19 = 14;	// TODO - init in decl?
+	r20 = 176;
+	r25 = 14;
+	r24 = 21;
+	underTopBarScreenRect.sx = 0;
+	underTopBarScreenRect.ex = 320 - 1;
+	underTopBarBackupRect.sx = scroll_pos;
+	underTopBarBackupRect.ex = scroll_pos + 320 - 1;
+	while(r24 > 0)
+	{
+		if(r25 > 0)
+		{
+			underTopBarScreenRect.sy = 16 - r25;
+			underTopBarScreenRect.ey = 16 - 1;
+			underTopBarBackupRect.sy = 0;
+			underTopBarBackupRect.ey = r25 - 1;
+			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+			scr40 = ((unsigned int*)p_mainview_buf) + r19 * 640 / 4;
+			scr41 = scr40 + 640 / 4;
+			for(i = 0;i < 320;i += 4)
+			{
+				*scr40++ = 0;
+				*scr41++ = 0;
+			}
+		}
+		underTopBarScreenRect.sy = 16;
+		underTopBarScreenRect.ey = r24 + 16 - 1;
+		underTopBarBackupRect.sy = 200 - r24;
+		underTopBarBackupRect.ey = 200 - 1;
+		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+		scr40 = ((unsigned int*)p_mainview_buf) + r20 * 640 / 4;
+		scr41 = scr40 + 640 / 4;
+		scr42 = scr41 + 640 / 4;
+		for(i = 0;i < 320;i += 4)
+		{
+			*scr40++ = 0;
+			*scr41++ = 0;
+			*scr42++ = 0;
+		}
+		r19 -= 2;
+		r20 += 3;
+		r25 -= 2;
+		r24 -= 3;
+		afficher();
+	}
+	scr40 = (unsigned int*)p_mainview_buf;
+	scr41 = scr40 + 640 / 4;
+	for(i = 0;i < 320;i += 4)
+	{
+		*scr40++ = 0;
+		*scr41++ = 0;
+	}
+	scr40 = ((unsigned int*)p_mainview_buf) + r20 * 640 / 4;
+	scr41 = scr40 + 640 / 4;
+	scr42 = scr41 + 640 / 4;
+	for(i = 0;i < 320;i += 4)
+	{
+		*scr40++ = 0;
+		*scr41++ = 0;
+		*scr42++ = 0;
+	}
+	afficher();
+	initrect();
+	showBlackBars = 1;
+}
+void bars_in()
+{
+	short r29, r28;
+	if(!showBlackBars)
+		return;
+	blackbars();
+	r29 = 2;
+	r28 = 2;
+	underTopBarScreenRect.sx = 0;
+	underTopBarScreenRect.ex = 320 - 1;
+	underTopBarBackupRect.sx = scroll_pos;
+	underTopBarBackupRect.ex = scroll_pos + 320 - 1;
+	while(r28 < 24)
+	{
+		if(r29 <= 16)
+		{
+			underTopBarScreenRect.sy = 16 - r29;
+			underTopBarScreenRect.ey = 16 - 1;
+			underTopBarBackupRect.sy = 0;
+			underTopBarBackupRect.ey = r29 - 1;
+			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+		}
+		underTopBarScreenRect.sy = 16;
+		underTopBarScreenRect.ey = 16 + r28;
+		underTopBarBackupRect.sy = 200 - 1 - r28;
+		underTopBarBackupRect.ey = 200 - 1;
+		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+		r29 += 2;
+		r28 += 3;
+		afficher();
+	}
+	initrect();
+	showBlackBars = 0;
+}
+void sauvefondbouche()
+{
+	rect_src.sx = cur_perso_rect->sx;
+	rect_src.sy = cur_perso_rect->sy;
+	rect_src.ex = cur_perso_rect->ex;
+	rect_src.ey = cur_perso_rect->ey;
+	rect_dst.sx = cur_perso_rect->sx + 320;
+	rect_dst.sy = cur_perso_rect->sy;
+	rect_dst.ex = cur_perso_rect->ex + 320;
+	rect_dst.ey = cur_perso_rect->ey;
+	CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_src, &rect_dst);
+	fond_saved = 1;
+}
+void restaurefondbouche()
+{
+	rect_src.sx = cur_perso_rect->sx;
+	rect_src.sy = cur_perso_rect->sy;
+	rect_src.ex = cur_perso_rect->ex;
+	rect_src.ey = cur_perso_rect->ey;
+	rect_dst.sx = cur_perso_rect->sx + 320;
+	rect_dst.sy = cur_perso_rect->sy;
+	rect_dst.ex = cur_perso_rect->ex + 320;
+	rect_dst.ey = cur_perso_rect->ey;
+	CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_dst, &rect_src);
+}
+void blackbars()
+{
+	unsigned char *scr = p_mainview_buf;
+	short x, y;
+	for(y = 0;y < 16;y++)
+		for(x = 0;x < 640;x++)
+			*scr++ = 0;
+	scr += 640 * (200 - 16 - 24);
+	for(y = 0;y < 24;y++)
+		for(x = 0;x < 640;x++)
+			*scr++ = 0;
+}
+void afftopscr()	// Draw  top bar (location / party / map)
+{
+	perso_t *perso;
+	p_global->drawFlags &= ~DrawFlags::drDrawTopScreen;
+	use_bank(314);
+	noclipax(36, 83, 0);
+	noclipax(p_global->area_ptr->num - 1, 0, 0);
+	noclipax(23, 145, 0);
+	for(perso = &kPersons[PER_DINA];perso != &kPersons[PER_UNKN_156];perso++)
+	{
+		if ((perso->flags & PersonFlags::pfInParty) && !(perso->flags & PersonFlags::pf80))
+			noclipax(perso->targetLoc + 18, perso->lastLoc + 120, 0);
+	}
+	saved_repadam.x = -1;
+	saved_repadam.y = -1;
+	affplanval();
+	needPaletteUpdate = 1;
+}
+void affplanval()	// Draw mini-map
+{
+	short loc;
+	perso_t *perso;
+	if(p_global->area_ptr->type == AreaType::atValley)
+	{
+		noclipax(p_global->area_ptr->num + 9, 266, 1);
+		for(perso = &kPersons[PER_UNKN_18C];perso->roomNum != 0xFFFF;perso++)
+		{
+			if(((perso->roomNum >> 8) == p_global->areaNum)
+				&& !(perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pf20))
+				affrepere(33, perso->roomNum & 0xFF);
+		}
+		if(p_global->area_ptr->citadelLevel)
+			affrepere(34, p_global->area_ptr->citadelRoom->location);
+		sauvefriseshaut(0);
+		loc = p_global->roomNum & 0xFF;
+		if(loc >= 16)
+			affrepereadam(loc);
+		restaurefriseshaut();
+	}
+	else
+	{
+		sauvefriseshaut(0);
+		restaurefriseshaut();
+	}
+}
+void affrepere(short index, short location)
+{
+	noclipax(index, 269 + location % 16 * 4, 2 + (location - 16) / 16 * 3);
+}
+void affrepereadam(short location)
+{
+	short x = 269;
+	short y = 2;
+	short w;
+	unsigned char *pix;
+	rest_repadam();
+	if(location > 15 && location < 76)
+	{
+		x += (location & 15) * 4;
+		y += ((location - 16) >> 4) * 3;
+		save_repadam(x, y);
+		pix = p_underBarsView->p_buffer;
+		w = p_underBarsView->width;
+		pix += x + w * y;
+		pix[1] = 0xC3;
+		pix[2] = 0xC3;
+		pix += w;
+		pix[0] = 0xC3;
+		pix[1] = 0xC3;
+		pix[2] = 0xC3;
+		pix[3] = 0xC3;
+		pix += w;
+		pix[1] = 0xC3;
+		pix[2] = 0xC3;
+	}
+}
+void rest_repadam()
+{
+	short x, y, w;
+	unsigned char *pix;
+	if(saved_repadam.x == -1 && saved_repadam.y == -1)
+		return;
+	x = saved_repadam.x;
+	y = saved_repadam.y;
+	pix = p_underBarsView->p_buffer;
+	w = p_underBarsView->width;
+	pix += x + w * y;
+	pix[1] = keep01;	//TODO keep is array?
+	pix[2] = keep02;
+	pix += w;
+	pix[0] = keep10;
+	pix[1] = keep11;
+	pix[2] = keep12;
+	pix[3] = keep13;
+	pix += w;
+	pix[1] = keep21;
+	pix[2] = keep22;
+}
+void save_repadam(short x, short y)
+{
+	short w;
+	unsigned char *pix;
+	saved_repadam.x = x;
+	saved_repadam.y = y;
+	pix = p_underBarsView->p_buffer;
+	w = p_underBarsView->width;
+	pix += x + w * y;
+	keep01 = pix[1];
+	keep02 = pix[2];
+	pix += w;
+	keep10 = pix[0];
+	keep11 = pix[1];
+	keep12 = pix[2];
+	keep13 = pix[3];
+	pix += w;
+	keep21 = pix[1];
+	keep22 = pix[2];
+}
+char istrice(short roomNum)
+{
+	char loc = roomNum & 0xFF;
+	short area = roomNum & 0xFF00;
+	perso_t *perso;
+	for(perso = &kPersons[PER_UNKN_18C];perso != &kPersons[PER_UNKN_372];perso++)
+	{
+		if ((perso->flags & PersonFlags::pf80) || (perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftTriceraptor)
+			continue;
+		if(perso->roomNum == (area | (loc - 16)))
+			return 1;
+		if(perso->roomNum == (area | (loc + 16)))
+			return 1;
+		if(perso->roomNum == (area | (loc - 1)))
+			return 1;
+		if(perso->roomNum == (area | (loc + 1)))
+			return 1;
+	}
+	return 0;
+}
+char istyran(short roomNum)
+{
+	char loc = roomNum & 0xFF;
+	short area = roomNum & 0xFF00;
+	// TODO: orig bug: this ptr is not initialized when first called from getsalle
+	// PC version scans kPersons[] directly and is not affected
+	if (!tyranPtr)
+		return 0;
+
+	for(;tyranPtr->roomNum != 0xFFFF;tyranPtr++) 
+	{
+		if (tyranPtr->flags & PersonFlags::pf80)
+			continue;
+		if(tyranPtr->roomNum == (area | (loc - 16)))
+			return 1;
+		if(tyranPtr->roomNum == (area | (loc + 16)))
+			return 1;
+		if(tyranPtr->roomNum == (area | (loc - 1)))
+			return 1;
+		if(tyranPtr->roomNum == (area | (loc + 1)))
+			return 1;
+	}
+	return 0;
+}
+void istyranval(area_t *area)
+{
+	perso_t *perso;
+	unsigned char areaNum = area->num;
+	area->flags &= ~AreaFlags::HasTyrann;
+	for(perso = &kPersons[PER_UNKN_372];perso->roomNum != 0xFFFF;perso++)
+	{
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if((perso->roomNum >> 8) == areaNum)
+		{
+			area->flags |= AreaFlags::HasTyrann;
+			break;
+		}
+	}
+}
+char getdirection(perso_t *perso)
+{
+	char dir = -1;
+	unsigned char trgLoc = perso->targetLoc;
+	unsigned char curLoc = perso->roomNum & 0xFF;	//TODO name
+	if(curLoc != trgLoc)
+	{
+		curLoc &= 0xF;
+		trgLoc &= 0xF;
+		if (curLoc != trgLoc)
+		{
+			dir = 2;
+			if (curLoc > trgLoc)
+				dir = 5;
+		}
+		trgLoc = perso->targetLoc;
+		curLoc = perso->roomNum & 0xFF;
+		curLoc &= 0xF0;
+		trgLoc &= 0xF0;
+		if (curLoc != trgLoc)
+		{
+			if (curLoc > trgLoc)
+				dir++;
+			dir++;
+		}
+	}
+	return dir;
+};
+char caselibre(char loc, perso_t *perso)
+{
+	short roomNum;
+	room_t *room = p_global->cita_area_firstRoom;
+	if(loc <= 0x10 || loc > 76 || (loc & 0xF) >= 12 || loc == perso->lastLoc)
+		return 0;
+	roomNum = (perso->roomNum & ~0xFF) | loc;	//TODO: danger! signed
+	if(roomNum == p_global->roomNum)
+		return 0;
+	for(;room->ff_0 != 0xFF;room++)
+	{
+		if(room->location != loc)
+			continue;
+		if(!(room->flags & RoomFlags::rf01))
+			return 0;
+		for(perso = &kPersons[PER_UNKN_18C];perso->roomNum != 0xFFFF;perso++)
+		{
+			if (perso->flags & PersonFlags::pf80)
+				continue;
+			if(perso->roomNum == roomNum)
+				break;
+		}
+		if(perso->roomNum != 0xFFFF)
+			return 0;
+		return 1;
+	}
+	return 0;	
+}
+void melange1(char elem[4])
+{
+	if (g_ed->_rnd->getRandomNumber(1) & 1)
+	{
+		char e1 = elem[1];
+		char e2 = elem[2];
+		elem[1] = e2;
+		elem[2] = e1;
+	}
+}
+void melange2(char elem[4])
+{
+	if (g_ed->_rnd->getRandomNumber(1) & 1)
+	{
+		char e0 = elem[0];
+		char e1 = elem[1];
+		elem[0] = e1;
+		elem[1] = e0;
+	}
+	if (g_ed->_rnd->getRandomNumber(1) & 1)
+	{
+		char e2 = elem[2];
+		char e3 = elem[3];
+		elem[2] = e3;
+		elem[3] = e2;
+	}
+}
+void melangedir()
+{
+	melange1(tab_2CB1E[0]);
+	melange1(tab_2CB1E[1]);
+	melange1(tab_2CB1E[2]);
+	melange2(tab_2CB1E[3]);
+	melange2(tab_2CB1E[4]);
+	melange1(tab_2CB1E[5]);
+	melange2(tab_2CB1E[6]);
+	melange2(tab_2CB1E[7]);
+}
+char naitredino(char persoType)
+{
+	perso_t *perso;
+	for(perso = &kPersons[PER_MORKUS];(++perso)->roomNum != 0xFFFF;)
+	{
+		char areaNum = perso->roomNum >> 8;
+		if(areaNum != p_global->cita_area_num)
+			continue;
+		if ((perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pfTypeMask) == persoType)
+		{
+			perso->flags &= ~PersonFlags::pf80;
+			return 1;
+		}
+	}
+	return 0;
+}
+void newcita(char arg1, short arg2, room_t *room)
+{
+	unsigned short index;
+	short *ptr;
+	cita_t *cita = cita_list;
+	while(cita->ff_0 < arg2)
+		cita++;
+	index = ((room->flags & 0xC0) >> 6);	//TODO: this is very wrong
+	ptr = cita->ff_2 + index * 2;
+	if(arg1 == 4 || arg1 == 6)
+		ptr++;
+	room->bank = ptr[0];
+	room->video = ptr[8];
+	room->flags |= RoomFlags::rf02;
+}
+void citaevol(short level)
+{
+	room_t *room = p_global->cur_area_ptr->citadelRoom;
+	perso_t *perso = &kPersons[PER_UNKN_372];
+	unsigned char speed, loc = room->location;
+	if (level >= 80 && !istrice((p_global->cita_area_num << 8) | room->location))  //TODO: loc ?
+	{
+		room->level = 79;
+		return;
+	}
+	if(level > 160)
+		level = 160;
+	if(room->level < 64 && level >= 64 && naitredino(PersonFlags::pftTriceraptor))
+	{
+		p_global->cur_area_ptr->flags |= AreaFlags::HasTriceraptors;
+		ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+	}
+	if(room->level < 40 && level >= 40 && naitredino(PersonFlags::pftVelociraptor))
+	{
+		p_global->cur_area_ptr->flags |= AreaFlags::HasVelociraptors;
+		ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsIn);
+	}
+	room->level = level;
+	newcita(p_global->cita_area_num, level, room);
+	speed = kDinoSpeedForCitaLevel[room->level >> 4];
+	for(;perso->roomNum != 0xFFFF;perso++)
+	{
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if ((perso->roomNum >> 8) == p_global->cita_area_num && perso->targetLoc == loc)
+			perso->speed = speed;
+	}	
+}
+void citacapoute(short roomNum)
+{
+	perso_t *perso = &kPersons[PER_UNKN_18C];
+	room_t *room = p_global->cur_area_ptr->citadelRoom;
+	room->flags |= RoomFlags::rf01;
+	room->flags &= ~RoomFlags::rfHasCitadel;
+	room->bank = 193;
+	room->video = 0;
+	room->level = 0;
+	p_global->cur_area_ptr->citadelLevel = 0;
+	p_global->cur_area_ptr->citadelRoom = 0;
+	roomNum = (roomNum & ~0xFF) | room->location;
+	for(;perso->roomNum != 0xFFFF;perso++)
+	{
+		if(perso->roomNum == roomNum)
+		{
+			perso->flags &= ~PersonFlags::pf80;
+			delinfo((roomNum >> 8) + ValleyNews::vnTyrannIn);
+			break;
+		}
+	}	
+}
+void buildcita()
+{
+	area_t *area = p_global->area_ptr;
+	p_global->cur_area_ptr = p_global->area_ptr;
+	if(area->citadelRoom)
+		citacapoute(p_global->roomNum);
+	p_global->ff_6A = p_global->ff_69;
+	p_global->narratorSequence = p_global->ff_69 | 0x80;
+	area->citadelRoom = p_global->room_ptr;
+	p_global->room_ptr->flags &= ~RoomFlags::rf01;
+	p_global->room_ptr->flags |= RoomFlags::rfHasCitadel;
+	p_global->room_ptr->level = 32;
+	newcita(p_global->areaNum, 32, p_global->room_ptr);
+	area->flags &= ~AreaFlags::TyrannSighted;
+	if (!(area->flags & AreaFlags::afFlag8000))
+	{
+		if(p_global->phaseNum == 304 || p_global->phaseNum != 384) //TODO: wha
+			eloirevient();
+		area->flags |= AreaFlags::afFlag8000;
+	}
+	p_global->room_perso->flags |= PersonFlags::pf80;
+	p_global->cita_area_num = p_global->areaNum;
+	naitredino(1);
+	delinfo(p_global->areaNum + ValleyNews::vnCitadelLost);
+	delinfo(p_global->areaNum + ValleyNews::vnTyrannLost);
+	if(p_global->phaseNum == 193 && p_global->areaNum == Areas::arUluru)
+		bigphase1();
+}
+void citatombe(char level)
+{
+	if(level)
+		newcita(p_global->cita_area_num, level, p_global->cur_area_ptr->citadelRoom);
+	else
+	{
+		citacapoute(p_global->cita_area_num << 8);
+		ajouinfo(p_global->cita_area_num + ValleyNews::vnCitadelLost);
+	}
+}
+void constcita()
+{
+	unsigned char level;
+	room_t *room;
+	unsigned char loc;
+//	room_t *room = p_global->cur_area_ptr->room_ptr;	//TODO: wrong? chk below
+//	unsigned char id = room->ff_C;
+	if(!p_global->cur_area_ptr->citadelLevel || !p_global->cur_area_ptr->citadelRoom)
+		return;
+	room = p_global->cur_area_ptr->citadelRoom;	//TODO: copied here by me
+	loc = room->location;
+	tyranPtr = &kPersons[PER_UNKN_372];
+	if(istyran((p_global->cita_area_num << 8) | loc))
+	{
+		if(!(p_global->cur_area_ptr->flags & AreaFlags::TyrannSighted))
+		{
+			ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
+			p_global->cur_area_ptr->flags |= AreaFlags::TyrannSighted;
+		}
+		level = room->level - 1;
+		if(level < 32)
+			level = 32;
+		room->level = level;
+		citatombe(level);
+	}
+	else
+	{
+		p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+		citaevol(room->level + 1);
+	}
+}
+void depladino(perso_t *perso)
+{
+	char *dirs, dir, dir2;
+	unsigned char loc;
+	dir = getdirection(perso);
+	if(dir != -1)
+	{
+		melangedir();
+		dirs = tab_2CB1E[dir];
+		loc = perso->roomNum & 0xFF;
+		dir2 = *dirs++;
+		if(dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if(caselibre(dir2, perso))
+			goto ok;
+		dir2 = *dirs++;
+		if(dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = *dirs++;
+		if(dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = *dirs++;
+		if(dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = perso->lastLoc;
+		perso->lastLoc = 0;
+		if(!caselibre(dir2, perso))
+			return;
+ok:;
+		perso->lastLoc = perso->roomNum & 0xFF;
+		perso->roomNum &= ~0xFF;
+		perso->roomNum |= dir2 & 0xFF;
+		if(perso->targetLoc - 16 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+		if(perso->targetLoc + 16 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+		if(perso->targetLoc - 1 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+		if(perso->targetLoc + 1 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+	}
+	else
+		perso->targetLoc = 0;
+}
+void deplaalldino()
+{
+	perso_t *perso = &kPersons[PER_UNKN_18C - 1];	//TODO fix this
+	while((++perso)->roomNum != 0xFFFF)
+	{
+		if(((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
+			continue;
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if(!perso->targetLoc)
+			continue;
+		if(--perso->steps)
+			continue;
+		perso->steps = 1;
+		if(perso->roomNum == p_global->roomNum)
+			continue;
+		perso->steps = perso->speed;
+		depladino(perso);
+	}
+}
+void newvallee()
+{
+	perso_t *perso = &kPersons[PER_UNKN_372];
+	short *ptr = tab_2CB16;
+	short roomNum;
+	while((roomNum = *ptr++) != -1)
+	{
+		perso->roomNum = roomNum;
+		perso->flags &= ~PersonFlags::pf80;
+		perso->flags &= ~PersonFlags::pf20;	//TODO: combine?
+		perso++;
+	}
+	perso->roomNum = -1;
+	kAreasTable[7].flags |= AreaFlags::HasTyrann;
+	p_global->worldHasTyrann = 32;	
+}
+char whereiscita()
+{
+	room_t *room = p_global->cita_area_firstRoom;
+	char res = -1;
+	for(;room->ff_0 != 0xFF;room++)
+	{
+		if(!(room->flags & RoomFlags::rfHasCitadel))
+			continue;
+		res = room->location;
+		break;
+	}
+	return res;
+}
+char iscita(short loc)
+{
+	room_t *room = p_global->cita_area_firstRoom;
+	loc &= 0xFF;	
+	for(;room->ff_0 != 0xFF;room++)
+	{
+		if(!(room->flags & RoomFlags::rfHasCitadel))
+			continue;
+		if(room->location == loc + 16)
+			return 1;
+		if(room->location == loc - 16)
+			return 1;
+		if(room->location == loc - 1)
+			return 1;
+		if(room->location == loc + 1)
+			return 1;
+	}
+	return 0;
+}
+void lieuvava(area_t *area)
+{
+	unsigned char mask;
+	if(area->type == AreaType::atValley)
+	{
+		istyranval(area);
+		area->citadelLevel = 0;
+		if(area->citadelRoom)
+			area->citadelLevel = p_global->cita_area_firstRoom->level;	//TODO: no search?
+		mask = ~(1 << (area->num - Areas::arChamaar));
+		p_global->worldTyrannSighted &= mask;
+		p_global->ff_4E &= mask;
+		p_global->worldGaveGold &= mask;
+		p_global->worldHasVelociraptors &= mask;
+		p_global->worldHasTriceraptors &= mask;
+		p_global->worldHasTyrann &= mask;
+		p_global->ff_53 &= mask;
+		mask = ~mask;
+		if(area->flags & AreaFlags::TyrannSighted)
+			p_global->worldTyrannSighted |= mask;
+		if(area->flags & AreaFlags::afFlag4)
+			p_global->ff_4E |= mask;
+		if(area->flags & AreaFlags::HasTriceraptors)
+			p_global->worldHasTriceraptors |= mask;
+		if(area->flags & AreaFlags::afGaveGold)
+			p_global->worldGaveGold |= mask;
+		if(area->flags & AreaFlags::HasVelociraptors)
+			p_global->worldHasVelociraptors |= mask;
+		if(area->flags & AreaFlags::HasTyrann)
+			p_global->worldHasTyrann |= mask;
+		if(area->flags & AreaFlags::afFlag20)
+			p_global->ff_53 |= mask;
+		if(area == p_global->area_ptr)
+		{
+			p_global->curAreaFlags = area->flags;
+			p_global->curCitadelLevel = area->citadelLevel;
+		}
+	}
+	p_global->ff_4D &= p_global->worldTyrannSighted;
+}
+void vivredino()
+{
+	char cita;
+	perso_t *perso = &kPersons[PER_UNKN_18C];
+	for(;perso->roomNum != 0xFFFF;perso++)
+	{
+		if(((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
+			continue;
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		switch(perso->flags & PersonFlags::pfTypeMask)
+		{
+		case PersonFlags::pftTyrann:
+			if(iscita(perso->roomNum))
+				perso->targetLoc = 0;
+			else if(!perso->targetLoc)
+			{
+				cita = whereiscita();
+				if(cita != -1)
+				{
+					perso->targetLoc = cita;
+					perso->speed = 2;
+					perso->steps = 1;
+				}
+			}
+			break;
+		case PersonFlags::pftTriceraptor:
+			if (perso->flags & PersonFlags::pfInParty)
+			{
+				if(iscita(perso->roomNum))
+					perso->targetLoc = 0;
+				else if(!perso->targetLoc)
+				{
+					cita = whereiscita();
+					if(cita != -1)
+					{
+						perso->targetLoc = cita;
+						perso->speed = 3;
+						perso->steps = 1;
+					}
+				}
+			}
+			break;
+		case PersonFlags::pftVelociraptor:
+			if (perso->flags & PersonFlags::pf10)
+			{
+				if(perso->roomNum == p_global->roomNum)
+				{
+					perso_t *perso2 = &kPersons[PER_UNKN_372];
+					char found = 0;
+					for(;perso2->roomNum != 0xFFFF;perso2++)
+					{
+						if((perso->roomNum & ~0xFF) == (perso2->roomNum & ~0xFF))
+						{
+							if (perso2->flags & PersonFlags::pf80)
+								continue;
+							perso->targetLoc = perso2->roomNum & 0xFF;
+							perso->steps = 1;
+							found = 1;
+							break;
+						}
+					}
+					if(found)
+						continue;
+				}
+				else
+				{
+					tyranPtr = &kPersons[PER_UNKN_372];
+					if(istyran(perso->roomNum))
+					{
+						if(p_global->phaseNum < 481 && (perso->powers & (1 << (p_global->cita_area_num - 3))))
+						{
+							tyranPtr->flags |= PersonFlags::pf80;
+							tyranPtr->roomNum = 0;
+							perso->flags &= ~PersonFlags::pf10;
+							perso->flags |= PersonFlags::pfInParty;
+							ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannLost);
+							delinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
+							if(naitredino(PersonFlags::pftTriceraptor))
+								ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+							constcita();
+							p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+						}
+						else
+						{
+							perso->flags &= ~PersonFlags::pf10;
+							perso->flags &= ~PersonFlags::pfInParty;
+							ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsLost);
+						}
+						continue;
+					}
+				}
+			}
+			if(!perso->targetLoc)
+			{
+				short loc;
+				perso->lastLoc = 0;
+				do
+				{
+					loc = (g_ed->_rnd->getRandomNumber(63) & 63) + 16;
+					if((loc & 0xF) >= 12)
+						loc &= ~4;	//TODO: ??? same as -= 4
+				}
+				while(!caselibre(loc, perso));
+				perso->targetLoc = loc;
+				perso->steps = 1;
+			}
+			break;
+		}
+	}
+}
+void vivreval(short areaNum)
+{
+	p_global->cita_area_num = areaNum;
+	p_global->cur_area_ptr = &kAreasTable[areaNum - 1];
+	p_global->cita_area_firstRoom = &gameRooms[p_global->cur_area_ptr->firstRoomIndex];
+	deplaalldino();
+	constcita();
+	vivredino();
+	newchampi();
+	newnido();
+	newnidv();
+	if(p_global->phaseNum >= 226)
+		newor();
+	lieuvava(p_global->cur_area_ptr);
+}
+void chaquejour()
+{
+	vivreval(3);
+	vivreval(4);
+	vivreval(5);
+	vivreval(6);
+	vivreval(7);
+	vivreval(8);
+	p_global->drawFlags |= DrawFlags::drDrawTopScreen;
+}
+void temps_passe(short t)
+{
+	short days = p_global->gameDays;
+	short lo = p_global->ff_56;
+	lo += t;
+	if(lo > 255)
+	{
+		days++;
+		lo &= 0xFF;
+	}
+	p_global->ff_56 = lo;
+	t = ((t >> 8) & 0xFF) + days;
+	t -= p_global->gameDays;
+	if(t)
+	{
+		p_global->gameDays += t;
+		while(t--)
+			chaquejour();
+	}
+}
+void heurepasse()
+{
+	temps_passe(5);
+}
+void anim_perso()
+{
+	if(cur_bank_num != p_global->perso_img_bank)
+		load_perso(p_global->perso_ptr);
+	restaurefondbulle();
+	if(restartAnimation)
+	{
+		last_anim_ticks = TimerTicks;
+		restartAnimation = 0;
+	}
+	cur_anim_frame_num = (TimerTicks - last_anim_ticks) >> 2;	// TODO: check me!!!
+	if(cur_anim_frame_num > num_anim_frames)				// TODO: bug?
+		animateTalking = 0;
+	if(p_global->curPersoAnimPtr && !p_global->animationFlags && cur_anim_frame_num != last_anim_frame_num)
+	{
+		last_anim_frame_num = cur_anim_frame_num;
+		if(*p_global->curPersoAnimPtr == 0xFF)
+			getanimrnd();
+		bank_data_ptr = perso_img_bank_data_ptr;
+		num_img_desc = 0;
+		perso_spr(p_global->curPersoAnimPtr);
+		p_global->curPersoAnimPtr += num_img_desc + 1;
+		dword_3072C = imagedesc + 200;
+		virespritebouche();
+		if(*dword_3072C)
+			af_image();
+		animationDelay--;
+		if(!animationDelay)	//TODO: combine
+		{
+			p_global->animationFlags = 1;
+			animationDelay = 8;
+		}
+	}
+
+	animationDelay--;
+	if(!animationDelay)	//TODO: combine
+	{
+		getanimrnd();
+		//TODO: no reload?
+	}
+	if(animateTalking)
+	{
+		if(!animationTable)
+		{
+			animationTable = gameLipsync + 7262;	//TODO: fix me
+			if(!fond_saved)
+				sauvefondbouche();
+		}
+		if(!personTalking)
+			cur_anim_frame_num = num_anim_frames - 1;
+		animationIndex = animationTable[cur_anim_frame_num];
+		if(animationIndex == 0xFF)
+			animateTalking = 0;
+		else if(animationIndex != lastAnimationIndex)
+		{
+			bank_data_ptr = perso_img_bank_data_ptr;
+			restaurefondbouche();
+//			debug("perso spr %d", animationIndex);
+			perso_spr(p_global->persoSpritePtr2 + animationIndex * 2);	//TODO: shorts?
+			dword_3072C = imagedesc + 200;
+			if(*dword_3072C)
+				af_image();
+			lastAnimationIndex = animationIndex;
+		}
+	}
+	af_subtitle();		
+}
+void getanimrnd()
+{
+	short rnd;
+	animationDelay = 8;
+	rnd = g_ed->_rnd->getRandomNumber(65535) & (unsigned char)~0x18;	//TODO
+	dword_30724 = p_global->persoSpritePtr + 16;	//TODO
+	p_global->curPersoAnimPtr = p_global->persoSpritePtr + ((dword_30724[1] << 8) + dword_30724[0]);
+	p_global->animationFlags = 1;
+	if(rnd >= 8)
+		return;
+	p_global->animationFlags = 0;
+	if(rnd <= 0)
+		return;
+	for(rnd *= 8;rnd > 0;rnd--)
+	{
+		while(*p_global->curPersoAnimPtr)
+			p_global->curPersoAnimPtr++;
+		p_global->curPersoAnimPtr++;
+	}
+}
+void addanim()
+{
+	lastAnimationIndex = -1;
+	last_anim_ticks = 0;
+	p_global->animationFlags = 0xC0;
+	p_global->curPersoAnimPtr = p_global->persoSpritePtr;
+	getanimrnd();
+	animationActive = 1;
+	if(p_global->perso_ptr == &kPersons[PER_ROI])
+		return;
+	perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));	//TODO: GetElem(0)
+	dword_3072C = imagedesc + 200;
+	if (p_global->perso_ptr->id != PersonId::pidCabukaOfCantura && p_global->perso_ptr->targetLoc != 7)	//TODO: targetLoc is minisprite idx
+		virespritebouche();
+	if(*dword_3072C)
+		af_image();
+}
+void virespritebouche()
+{
+	unsigned char *src = dword_3072C + 2;
+	unsigned char *dst = src;
+	char cnt = dword_3072C[0];
+	while(cnt--)
+	{
+		unsigned char a = *src++;
+		unsigned char b = *src++;
+		unsigned char c = *src++;
+		dst[0] = a;
+		dst[1] = b;
+		dst[2] = c;
+		if(dword_30728[0] != 0xFF)
+		{
+			if((a < dword_30728[0] || a > dword_30728[1])
+			&& (a < dword_30728[2] || a > dword_30728[3]))
+				dst += 3;
+			else
+				dword_3072C[0]--;
+		}
+		else
+			dst += 3;
+	}
+}
+void anim_perfin()
+{
+	p_global->animationFlags &= ~0x80;
+	animationDelay = 0;
+	animationActive = 0;
+}
+void perso_spr(unsigned char *spr)
+{
+	unsigned char *img = imagedesc + 200 + 2;
+	short count = 0;
+	unsigned char c, cc;
+	while((c = *spr++))
+	{
+		unsigned char *src;
+		short index;
+		cc = 0;
+		if(c == 1)
+		{
+			cc = index;
+			c = *spr++;
+		}
+		num_img_desc++;
+		index = (cc << 8) | c;
+		index -= 2;
+//	debug("anim sprite %d", index);
+
+		if(index > max_perso_desc)
+			index = max_perso_desc;
+		index *= 2;			//TODO: src = GetElem(ff_C2, index)
+		src = p_global->ff_C2;
+		src = src + PLE16(src + index);
+		while((c = *src++))
+		{
+			*img++ = c;
+			*img++ = *src++;
+			*img++ = *src++;
+			count++;
+		}
+	}
+	imagedesc[200] = count & 0xFF;
+	imagedesc[201] = count >> 8;
+}
+void af_image()
+{
+	unsigned char *img = imagedesc + 200, *img_start, *curimg = imagedesc;
+	short count;
+
+	count = PLE16(img);
+	if(!count)
+		return;
+	img_start = img;
+	img += 2;
+	count *= 3;
+	while(count--)
+		*curimg++ = *img++;
+	img = img_start;
+	count = PLE16(img); img += 2;
+/////// draw it
+	while(count--)
+	{
+		unsigned short index = *img++;
+		unsigned short x = *img++ + gameIcons[0].sx;
+		unsigned short y = *img++ + gameIcons[0].sy;
+		unsigned char *pix = bank_data_ptr;
+		unsigned char *scr = p_mainview_buf + x + y * 640;
+		unsigned char h0, h1, mode;
+		short w, h;
+		index--;
+		if(PLE16(pix) > 2)
+			readpalette(pix + 2);
+		pix += PLE16(pix);
+		pix += PLE16(pix + index * 2);
+		//	short	height:9
+		//	short	pad:6;
+		//	short	flag:1;
+		h0 = *pix++;
+		h1 = *pix++;
+		w = ((h1 & 1) << 8) | h0;
+		h = *pix++;
+		mode = *pix++;
+		if(mode != 0xFF && mode != 0xFE)
+			continue;	//TODO: enclosing block?
+		if(h1 & 0x80)
+		{
+		// compressed
+			for(;h-- > 0;)
+			{
+				short ww;
+				for(ww = w;ww > 0;)
+				{
+					unsigned char c = *pix++;
+					if(c >= 0x80)
+					{
+						if(c == 0x80)
+						{
+							unsigned char fill = *pix++;
+							if(fill == 0)
+							{
+								scr += 128 + 1;
+								ww -= 128 + 1;
+							}
+							else
+							{
+								unsigned char run;
+								*scr++ = fill;	//TODO: wha?
+								*scr++ = fill;
+								ww -= 128 + 1;
+								for(run = 127;run--;)
+									*scr++ = fill;
+							}
+						}
+						else
+						{
+							unsigned char fill = *pix++;
+							unsigned char run = 255 - c + 2;
+							ww -= run;
+							if(fill == 0)
+								scr += run;
+							else
+								for(;run--;)
+									*scr++ = fill;
+						}
+					}
+					else
+					{
+						unsigned char run = c + 1;
+						ww -= run;
+						for(;run--;)
+						{
+							unsigned char p = *pix++;
+							if(p == 0)
+								scr++;
+							else
+								*scr++ = p;
+						}
+					}
+				}
+				scr += 640 - w;
+			}
+		}
+		else
+		{
+			// uncompressed
+			for(;h--;)
+			{
+				short ww;
+				for(ww = w;ww--;)
+				{
+					unsigned char p = *pix++;
+					if(p == 0)
+						scr++;
+					else
+						*scr++ = p;
+				}
+				scr += 640 - w;
+			}
+		}
+	}
+}
+void af_perso1()
+{
+	perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));
+	af_image();
+}
+void af_perso()
+{
+	load_perso_cour();
+	af_perso1();
+}
+void ef_perso()
+{
+	p_global->animationFlags &= 0x3F;
+}
+void load_perso(perso_t *perso)
+{
+	unsigned char *ptr, *baseptr;
+	perso_img_bank_data_ptr = 0;
+	if(!perso->bank)
+		return;
+	if(perso->bank != p_global->perso_img_bank)
+	{
+		cur_perso_rect = &perso_rects[perso->id];	//TODO: array of short?
+		dword_30728 = tab_persxx[perso->id];
+		ef_perso();
+		p_global->perso_img_bank = perso->bank;
+		use_bank(p_global->perso_img_bank);
+		perso_img_bank_data_ptr = bank_data_ptr;
+		ptr = bank_data_ptr;
+		ptr += PLE16(ptr);
+		baseptr = ptr;
+		ptr += PLE16(ptr) - 2;
+		ptr = baseptr + PLE16(ptr) + 4;
+		gameIcons[0].sx = PLE16(ptr);
+		gameIcons[0].sy = PLE16(ptr + 2);
+		gameIcons[0].ex = PLE16(ptr + 4);
+		gameIcons[0].ey = PLE16(ptr + 6);
+		ptr += 8;
+		p_global->ff_C2 = ptr + 2;
+		max_perso_desc = PLE16(ptr) / 2;
+		ptr += PLE16(ptr);
+		baseptr = ptr;
+		ptr += PLE16(ptr) - 2;
+		p_global->persoSpritePtr = baseptr;
+		p_global->persoSpritePtr2 = baseptr + PLE16(ptr);
+		debug("load perso: b6 len is %d", p_global->persoSpritePtr2 - p_global->persoSpritePtr);
+	}
+	else
+	{
+		use_bank(p_global->perso_img_bank);
+		perso_img_bank_data_ptr = bank_data_ptr;
+	}
+}
+void load_perso_cour()
+{
+	load_perso(p_global->perso_ptr);
+}
+void fin_perso()
+{
+	p_global->animationFlags &= 0x3F;
+	p_global->curPersoAnimPtr = 0;
+	p_global->ff_CA = 0;
+	p_global->perso_img_bank = -1;
+	anim_perfin();
+}
+void no_perso()
+{
+	if(p_global->displayFlags == DisplayFlags::dfPerson)
+	{
+		p_global->displayFlags = p_global->oldDisplayFlags;
+		fin_perso();
+	}
+	endpersovox();
+}
+void close_perso()
+{
+	char old;
+	endpersovox();
+	if (p_global->displayFlags == DisplayFlags::dfPerson && p_global->perso_ptr->id != PersonId::pidNarrator && p_global->eventType != EventType::etEventE)
+	{
+		rundcurs();
+		savedUnderSubtitles = 1;
+		restaurefondbulle();
+		afficher();
+		p_global->ff_103 = 16;
+	}
+	if(p_global->perso_ptr->id == PersonId::pidNarrator)
+		p_global->ff_103 = 69;
+	p_global->eloiHaveNews &= 1;
+	p_global->ff_CA = 0;
+	p_global->ff_F6 = 0;
+	if (p_global->displayFlags == DisplayFlags::dfPerson)
+	{
+		p_global->displayFlags = p_global->oldDisplayFlags;
+		p_global->animationFlags &= 0x3F;
+		p_global->curPersoAnimPtr = 0;
+		anim_perfin();
+		if(p_global->displayFlags & DisplayFlags::dfMirror)
+		{
+			gametomiroir(1);
+			scroll_pos = old_scroll_pos;
+			scroll();
+			return;
+		}
+		if(p_global->numGiveObjs)
+		{
+			if(!(p_global->displayFlags & DisplayFlags::dfFlag2))
+				showobjects();
+			p_global->numGiveObjs = 0;
+		}
+		if(p_global->ff_F2 & 1)
+		{
+			p_global->ff_102 = 6;
+			p_global->ff_F2 &= ~1;
+		}
+		old = p_global->newLocation;
+		p_global->newLocation = 0;
+		if(!(p_global->narratorSequence & 0x80))
+			p_global->ff_100 = -1;
+		maj_salle(p_global->roomNum);
+		p_global->newLocation = old;
+	}
+	if(p_global->chrono)
+		p_global->chrono_on = 1;
+}
+void af_fondsuiveur()
+{
+	char id = p_global->perso_ptr->id;
+	suiveur_t *suiveur = suiveurs_list;
+	for(;suiveur->id != -1;suiveur++)
+	{
+		if(suiveur->id == id)
+		{
+			int bank = 326;
+			if(suiveur->sx >= 320)
+				bank = 327;
+			use_bank(bank + p_global->roomBgBankNum);
+			noclipax_avecnoir(0, 0, 16);
+			break;
+		}
+	}
+}
+void af_fondperso1()
+{
+	unsigned char bank;
+	char *ptab;
+	if(p_global->perso_ptr == &kPersons[PER_MESSAGER])
+	{
+		gameIcons[0].sx = 0;
+		perso_rects[PER_MESSAGER].sx = 2;
+		bank = p_global->persoBackgroundBankIdx;
+		if(p_global->eventType == EventType::etEventE)
+		{
+			p_global->ff_103 = 1;
+			goto no_suiveur;
+		}
+		gameIcons[0].sx = 60;
+		perso_rects[PER_MESSAGER].sx = 62;
+	}
+	if(p_global->perso_ptr == &kPersons[PER_THOO])
+	{
+		bank = 37;
+		if(p_global->curObjectId == Objects::obShell)
+			goto no_suiveur;
+	}
+	ptab = kPersoRoomBankTable + p_global->perso_ptr->roomBankIdx;
+	bank = *ptab++;
+	if(!(p_global->perso_ptr->party & p_global->party))
+	{
+		while((bank = *ptab++) != 0xFF)
+		{
+			if(bank == (p_global->roomNum & 0xFF))	//TODO: signed vs unsigned - chg r31 to uns?
+			{
+				bank = *ptab;
+				break;
+			}
+			ptab++;
+		}
+		if(bank != 0xFF)
+			goto no_suiveur;
+		ptab = kPersoRoomBankTable + p_global->perso_ptr->roomBankIdx;
+		bank = *ptab++;
+	}
+	af_fondsuiveur();
+no_suiveur:;
+	if(!bank)
+		return;
+	use_bank(bank);
+	if(p_global->perso_ptr == &kPersons[PER_UNKN_156])
+		noclipax_avecnoir(0, 0, 16);
+	else
+		noclipax(0, 0, 16);
+}
+void af_fondperso()
+{
+	if(p_global->perso_ptr->bank)
+	{
+		fond_saved = 0;
+		af_fondperso1();
+	}
+}
+void setpersoicon()
+{
+	icon_t *icon = gameIcons, *icon2 = &gameIcons[28];
+	if(p_global->iconsIndex == 4)
+		return;
+	if(p_global->perso_ptr == &kPersons[PER_MESSAGER] && p_global->eventType == EventType::etEventE)
+	{
+		p_global->iconsIndex = 123;
+		return;
+	}
+	*icon2++ = *icon++;	//TODO: is this ok?
+	*icon2++ = *icon++;
+	icon2->sx = -1;	
+}
+void show_perso()
+{
+	perso_t *perso = p_global->perso_ptr;
+	if(perso->bank)
+	{
+		closesalle();
+		if(p_global->displayFlags != DisplayFlags::dfPerson)
+		{
+			if(p_global->displayFlags & DisplayFlags::dfMirror)
+				resetscroll();
+			p_global->oldDisplayFlags = p_global->displayFlags;
+			p_global->displayFlags = DisplayFlags::dfPerson;
+			load_perso(perso);
+			setpersoicon();
+			af_fondperso();
+			if(perso == &kPersons[PER_THOO] && p_global->curObjectId == Objects::obShell)
+			{
+				af_subtitle();
+				update_cursor();
+				needPaletteUpdate = 1;
+				afficher();
+				rundcurs();
+				return;
+			}
+		}
+		load_perso_cour();
+		addanim();
+		if(!p_global->curPersoAnimPtr)
+		{
+			af_perso();
+			af_subtitle();
+		}
+		restartAnimation = 1;
+		anim_perso();
+		if(perso != &kPersons[PER_UNKN_156])
+			update_cursor();
+		needPaletteUpdate = 1;
+		if(perso != &kPersons[PER_UNKN_156])
+			rundcurs();
+		afficher();
+	}
+	else
+	{
+		aflieu();
+		af_subtitle();
+	}
+}
+void showpersopanel()
+{
+	perso_t *perso = p_global->perso_ptr;
+	load_perso_cour();
+	addanim();
+	if(!p_global->curPersoAnimPtr)
+	{
+		af_perso();
+		af_subtitle();
+	}
+	restartAnimation = 1;
+	needPaletteUpdate = 1;
+	if(p_global->drawFlags & DrawFlags::drDrawFlag8)
+		return;
+	anim_perso();
+	if(perso != &kPersons[PER_UNKN_156])
+		update_cursor();
+	afficher();
+	if(perso != &kPersons[PER_UNKN_156])
+		rundcurs();
+	p_global->drawFlags |= DrawFlags::drDrawFlag8;
+	p_global->iconsIndex = 112;
+}
+void getdatasync()
+{
+	short num = p_global->textNum;
+	if(p_global->textBankIndex != 1)
+		num += 565;
+	if(p_global->textBankIndex == 3)
+		num += 707;
+	if(num == 144)
+		num = 142;
+	animateTalking = ReadDataSync(num - 1);
+	if(animateTalking)
+		num_anim_frames = ReadNombreFrames();
+	else
+		num_anim_frames = 0;
+	if(p_global->textNum == 144)
+		num_anim_frames = 48;
+	animationTable = 0;
+}
+short ReadNombreFrames()
+{
+	short num = 0;
+	animationTable = gameLipsync + 7262;	//TODO: fix me
+	while(*animationTable++ != 0xFF)
+		num++;
+	return num;
+}
+void waitendspeak()
+{
+	for(;;)
+	{
+		if(animationActive)
+			anim_perso();
+		musicspy();
+		afficher();
+		CLKeyboard_Read();
+		testPommeQ();
+		if(pomme_q)
+		{
+			close_perso();
+			PommeQ();
+			break;
+		}
+		if(!mouse_held)
+			if(CLMouse_IsDown())
+				break;
+		if(mouse_held)
+			if(!CLMouse_IsDown())
+				mouse_held = 0;
+	}
+	mouse_held = 1;
+}
+void my_bulle()
+{
+	unsigned char c;
+	unsigned char i;
+	short words_on_line, word_width, line_width;
+	unsigned char *icons = phraseIconsBuffer;
+	unsigned char *lines = phraseCoordsBuffer;
+	unsigned char *phrasePtr = phraseBuffer;
+	if(!p_global->textNum)
+		return;
+	p_global->numGiveObjs = 0;
+	p_global->giveobj1 = 0;
+	p_global->giveobj2 = 0;
+	p_global->giveobj3 = 0;
+	p_global->textWidthLimit = subtitles_x_width;
+	text_ptr = gettxtad(p_global->textNum);
+	num_text_lines = 0;
+	words_on_line = 0;
+	word_width = 0;
+	line_width = 0;
+	while((c = *text_ptr++) != 0xFF)
+	{
+		if(c == 0x11 || c == 0x13)
+		{
+			if(p_global->phaseNum <= 272 || p_global->phaseNum == 386)
+			{
+				p_global->eloiHaveNews = c & 0xF;
+				p_global->ff_4D = p_global->worldTyrannSighted;
+			}
+		}
+		else if(c >= 0x80 && c < 0x90)
+			SysBeep(1);
+		else if(c >= 0x90 && c < 0xA0)
+		{
+			while(*text_ptr++ != 0xFF) ;
+			text_ptr--;
+		}
+		else if(c >= 0xA0 && c < 0xC0)
+			p_global->textToken1 = c & 0xF;
+		else if(c >= 0xC0 && c < 0xD0)
+			p_global->textToken2 = c & 0xF;
+		else if(c >= 0xD0 && c < 0xE0)
+		{
+			unsigned char c1 = *text_ptr++;
+			if(c == 0xD2)
+#ifdef FAKE_DOS_VERSION
+				p_global->textWidthLimit = c1 + 160;
+#else
+				p_global->textWidthLimit = c1 + subtitles_x_center;	//TODO: signed? 160 in pc ver
+#endif
+			else
+			{
+				unsigned char c2 = *text_ptr++;
+				switch(p_global->numGiveObjs)
+				{
+				case 0: p_global->giveobj1 = c2; break;
+				case 1: p_global->giveobj2 = c2; break;
+				case 2: p_global->giveobj3 = c2; break;
+				}
+				p_global->numGiveObjs++;
+				*icons++ = *text_ptr++;
+				*icons++ = *text_ptr++;
+				*icons++ = c2;
+			}
+		}
+		else if(c >= 0xE0 && c < 0xFF)
+			SysBeep(1);
+		else if(c != '\r')
+		{
+			unsigned char width;
+			short overrun;
+			*phrasePtr++ = c;
+			width = gameFont[c];
+#ifdef FAKE_DOS_VERSION
+			if (c == ' ')
+				width = space_width;
+#endif
+			word_width += width;
+			line_width += width;
+			overrun = line_width - p_global->textWidthLimit;
+			if(overrun > 0)
+			{
+				num_text_lines++;
+				if(c != ' ')
+				{
+					*lines++ = words_on_line;
+					*lines++ = word_width + space_width - overrun;
+					line_width = word_width;
+				}
+				else
+				{
+					*lines++ = words_on_line + 1;
+					*lines++ = space_width - overrun;	//TODO: checkme
+					line_width = 0;
+				}
+				word_width = 0;
+				words_on_line = 0;
+			}
+			else
+			{
+				if(c == ' ')
+				{
+					words_on_line++;
+					word_width = 0;
+				}
+			}
+		}
+	}
+	num_text_lines++;
+	*lines++ = words_on_line + 1;
+	*lines++ = word_width;
+	*phrasePtr = c;
+	if(p_global->textBankIndex == 2 && p_global->textNum == 101 && p_global->pref_language == 1)
+		patchphrase();
+	my_pr_bulle();
+	if(!p_global->numGiveObjs)
+		return;
+	use_main_bank();
+	if(num_text_lines < 3)
+		num_text_lines = 3;
+	icons = phraseIconsBuffer;
+	for(i = 0;i < p_global->numGiveObjs;i++)
+	{
+		unsigned char x = *icons++;
+		unsigned char y = *icons++;
+		unsigned char s = *icons++;
+		spritesurbulle(52, x + subtitles_x_center, y - 1);
+		spritesurbulle(s + 9, x + subtitles_x_center + 1, y);
+	}
+}
+void my_pr_bulle()
+{
+	unsigned char *cur_out;
+	unsigned char *coo = phraseCoordsBuffer;
+	short extra_spacing, lines;
+	char done = 0;
+	CLBlitter_FillView(p_subtitlesview, 0);
+	if(p_global->pref_language == 0)
+		return;
+	textout = p_subtitlesview_buf;
+	text_ptr = phraseBuffer;
+	lines = 1;
+	while(!done)
+	{
+		unsigned char c;
+		short num_words = *coo++;		// num words on line
+		short pad_size = *coo++;		// amount of extra spacing
+		cur_out = textout;
+		extra_spacing = num_words > 1 ? pad_size / (num_words - 1) + 1 : 0;
+		if(lines == num_text_lines)
+			extra_spacing = 0;
+		c = *text_ptr++;
+		while(!done & (num_words > 0))	//TODO: bug - missed & ?
+		{
+			if(c < 0x80 && c != '\r')
+			{
+				if(c == ' ')
+				{
+					num_words--;
+					if (pad_size >= extra_spacing)
+					{
+						textout += extra_spacing + space_width;
+						pad_size -= extra_spacing;
+					}
+					else
+					{
+						textout += pad_size + space_width;
+						pad_size = 0;
+					}
+				}
+				else
+				{
+					short char_width = gameFont[c];
+					if(!(p_global->drawFlags & DrawFlags::drDrawMenu))
+					{
+						textout += subtitles_x_width;
+						if(!specialTextMode)
+							charsurbulle(c, 195, char_width);
+						textout++;
+						if(!specialTextMode)
+							charsurbulle(c, 195, char_width);
+						textout -= subtitles_x_width + 1;
+					}
+					if(specialTextMode)
+						charsurbulle(c, 250, char_width);
+					else
+						charsurbulle(c, 230, char_width);
+					textout += char_width;
+				}
+			}
+			else
+				monbreak();
+			c = *text_ptr++;
+			if(c == 0xFF)
+				done = 1;
+		}
+		textout = cur_out + subtitles_x_width * FONT_HEIGHT;
+		lines++;
+		text_ptr--;
+	}
+}
+void charsurbulle(unsigned char c, unsigned char color, short width)
+{
+	short w, h;
+	unsigned char *glyph = gameFont + 256 + c * FONT_HEIGHT;
+	textoutptr = textout;
+	for(h = 0;h < FONT_HEIGHT;h++)
+	{
+		unsigned char bits = *glyph++;
+		short mask = 0x80;
+		for(w = 0;w < width;w++)
+		{
+			if(bits & mask)
+				*textoutptr = color;
+			textoutptr++;
+			mask >>= 1;
+		}
+		textoutptr += subtitles_x_width - width;
+	}
+}
+void af_subtitle()
+{
+	short w, h, y;
+	unsigned char *src = p_subtitlesview_buf, *dst = p_mainview_buf;
+	if(p_global->displayFlags & DisplayFlags::dfFlag2)
+	{
+		y = 174;
+		if((p_global->drawFlags & DrawFlags::drDrawMenu) && num_text_lines == 1)
+			y = 167;
+		dst += 640 * (y - num_text_lines * FONT_HEIGHT) + subtitles_x_scr_margin;
+	}
+	else
+	{
+		y = 174;
+		dst += 640 * (y - num_text_lines * FONT_HEIGHT) + scroll_pos + subtitles_x_scr_margin;
+	}
+	if(animationActive && !personTalking)
+		return;
+	sauvefondbulle(y);
+	for(h = 0;h < num_text_lines * FONT_HEIGHT + 1;h++)
+	{
+		for(w = 0;w < subtitles_x_width;w++)
+		{
+			unsigned char c = *src++;
+			if(c)
+				*dst = c;
+			dst++;
+		}
+		dst += 640 - subtitles_x_width;
+	}
+}
+void sauvefondbulle(short y)
+{
+	underSubtitlesScreenRect.sy = y - num_text_lines * FONT_HEIGHT;
+	underSubtitlesScreenRect.sx = scroll_pos + subtitles_x_scr_margin;
+	underSubtitlesScreenRect.ex = scroll_pos + subtitles_x_scr_margin + subtitles_x_width - 1;
+	underSubtitlesScreenRect.ey = y;
+	underSubtitlesBackupRect.sy = 0;
+	underSubtitlesBackupRect.ey = num_text_lines * FONT_HEIGHT;
+	CLBlitter_CopyViewRect(p_mainview, p_underSubtitlesView, &underSubtitlesScreenRect, &underSubtitlesBackupRect);
+	savedUnderSubtitles = 1;
+}
+void restaurefondbulle()
+{
+	if(!savedUnderSubtitles)
+		return;
+	CLBlitter_CopyViewRect(p_underSubtitlesView, p_mainview, &underSubtitlesBackupRect, &underSubtitlesScreenRect);
+	savedUnderSubtitles = 0;
+}
+void af_subtitlehnm()
+{
+	short x, y;
+	unsigned char *src = p_subtitlesview_buf;
+	unsigned char *dst = p_hnmview_buf + subtitles_x_scr_margin + (158 - num_text_lines * FONT_HEIGHT) * 320;
+	for(y = 0;y < num_text_lines * FONT_HEIGHT;y++)
+	{
+		for(x = 0;x < subtitles_x_width;x++)
+		{
+			char c = *src++;
+			if(c)
+				*dst = c;
+			dst++;
+		}
+		dst += 320 - subtitles_x_width;
+	}
+}
+void patchphrase()
+{
+	phraseBuffer[36] = 'c';
+}
+void vavapers()
+{
+	perso_t *perso = p_global->perso_ptr;
+	p_global->curPersoFlags = perso->flags;
+	p_global->curPersoItems = perso->items;
+	p_global->curPersoPowers = perso->powers;
+}
+void citadelle()
+{
+	p_global->ff_69++;
+	p_global->ff_F6++;
+	byte_30AFE = 1;
+	byte_30B00 = 1;
+}
+void choixzone()
+{
+	if(p_global->giveobj3)
+		p_global->iconsIndex = 6;
+	else
+		p_global->iconsIndex = 10;
+	p_global->autoDialog = 0;
+	putobject();
+}
+void showevents1()
+{
+	p_global->ff_113 = 0;
+	perso_ici(3);
+}
+void showevents()
+{
+	if(p_global->eventType && p_global->displayFlags != DisplayFlags::dfPerson)
+		showevents1();
+}
+void parle_mfin()
+{
+	char curobj;
+	object_t *obj;
+	perso_t *perso = p_global->perso_ptr;
+	if(p_global->curObjectId)
+	{
+		curobj = p_global->curObjectId;
+		if(p_global->dialogType == DialogType::dtHint)
+			return;
+		obj = getobjaddr(p_global->curObjectId);
+		if(p_global->dialogType == DialogType::dtDinoItem)
+			perso = p_global->room_perso;
+		if(verif_oui())
+		{
+			loseobject(p_global->curObjectId);
+			perso->powers |= obj->powerMask;
+		}
+		perso->items |= obj->itemMask;
+		SpecialObjets(perso, curobj);
+		return;
+	}
+	if(!verif_oui())
+		return;
+	nextinfo();
+	if(!p_global->last_info)
+		byte_30B00 = 1;
+	else
+	{
+		p_global->next_dialog_ptr = 0;
+		byte_30B00 = 0;
+	}
+}
+void parlemoi_normal()
+{
+	char ok;
+	dial_t *dial;
+	if(!p_global->next_dialog_ptr)
+	{
+		perso_t *perso = p_global->perso_ptr;
+		if(perso)
+		{
+			short num = (perso->id << 3) | p_global->dialogType;
+			dial = (dial_t*)GetElem(gameDialogs, num);
+		}
+		else
+		{
+			close_perso();
+			return;
+		}
+	}
+	else
+	{
+		if(byte_30B00)
+		{
+			close_perso();
+			return;
+		}
+		dial = p_global->next_dialog_ptr;
+	}
+	ok = dial_scan(dial);
+	p_global->next_dialog_ptr = p_global->dialog_ptr;
+	byte_30B00 = 0;
+	if(!ok)
+		close_perso();
+	else
+		parle_mfin();
+}
+void parle_moi()
+{
+	unsigned char r28;
+	char ok;
+	dial_t *dial;
+	endpersovox();
+	r28 = p_global->ff_F6;
+	p_global->ff_F6 = 0;
+	if(!r28)
+	{
+		init_non();
+		if(p_global->drawFlags & DrawFlags::drDrawInventory)
+			showobjects();
+		if(p_global->drawFlags & DrawFlags::drDrawTopScreen)
+			afftopscr();
+		if(p_global->curObjectId)
+		{
+			if(p_global->dialogType == DialogType::dtTalk)
+			{
+				p_global->dialogType = DialogType::dtItem;
+				p_global->next_dialog_ptr = 0;
+				byte_30B00 = 0;
+			}
+			parlemoi_normal();
+			return;
+		}
+		if(p_global->dialogType == DialogType::dtItem)
+		{
+			p_global->dialogType = DialogType::dtTalk;
+			if(!byte_30B00)
+				p_global->next_dialog_ptr = 0;
+		}
+		if(byte_30AFE)
+		{
+			parlemoi_normal();
+			return;
+		}
+		if(!p_global->last_dialog_ptr)
+		{
+			short num = 160;
+			if(p_global->phaseNum >= 400)
+				num++;
+			dial = (dial_t*)GetElem(gameDialogs, num);
+		}
+		else
+			dial = p_global->last_dialog_ptr;
+		ok = dial_scan(dial);
+		p_global->last_dialog_ptr = p_global->dialog_ptr;
+		byte_30AFE = 0;
+		if(!ok)
+		{
+			byte_30AFE = 1;
+			if(p_global->ff_60)
+			{
+				if(p_global->perso_ptr == &kPersons[PER_MESSAGER])
+				{
+					p_global->dialogType = 0;
+					if(p_global->eloiHaveNews)
+						parlemoi_normal();
+					else
+						close_perso();
+				}
+				else
+					close_perso();
+			}
+			else
+				parlemoi_normal();
+		}
+		else
+			parle_mfin();
+	}
+	else
+		close_perso();
+}
+void init_perso_ptr(perso_t *perso)
+{
+	p_global->metPersonsMask1 |= perso->party;
+	p_global->metPersonsMask2 |= perso->party;
+	p_global->next_dialog_ptr = 0;
+	byte_30B00 = 0;
+	dialogSkipFlags = DialogFlags::dfSpoken;
+	p_global->ff_60 = 0;
+	p_global->textToken1 = 0;
+}    
+void perso1(perso_t *perso)
+{
+	p_global->phaseActionsCount++;
+	if(perso == &kPersons[PER_THOO])
+		p_global->phaseActionsCount--;
+	p_global->perso_ptr = perso;
+	init_perso_ptr(perso);
+	parle_moi();	
+}    
+void perso_normal(perso_t *perso)
+{
+	p_global->last_dialog_ptr = 0;
+	p_global->dialogType = 0;
+	byte_30AFE = 0;
+	perso1(perso);
+}
+void persoparle(short pers)
+{
+	char res;
+	unsigned short idx;
+	unsigned char *ptr;
+	perso_t *perso = &kPersons[pers];
+	p_global->perso_ptr = perso;
+	p_global->dialogType = DialogType::dtInspect;
+	idx = perso->id * 8 | p_global->dialogType;
+	res = dialoscansvmas((dial_t*)GetElem(gameDialogs, idx));
+	aflieu();
+	af_subtitle();
+	persovox();
+	p_global->ff_CA = 0;
+	p_global->dialogType = 0;
+}
+void roi()	{ perso_normal(&kPersons[PER_ROI]); }
+void dina()	{ perso_normal(&kPersons[PER_DINA]); }
+void thoo()	{ perso_normal(&kPersons[PER_THOO]); }
+void monk()	{ perso_normal(&kPersons[PER_MONK]); }
+void bourreau()	{ perso_normal(&kPersons[PER_BOURREAU]); }
+void messager()	{ perso_normal(&kPersons[PER_MESSAGER]); }
+void mango()	{ perso_normal(&kPersons[PER_MANGO]); }
+void eve()	{ perso_normal(&kPersons[PER_EVE]); }
+void azia()	{ perso_normal(&kPersons[PER_AZIA]); }
+void mammi()
+{
+	perso_t *perso;
+	for(perso = &kPersons[PER_MAMMI];perso->party == PersonMask::pmLeader;perso++)
+	{
+		if(perso->roomNum == p_global->roomNum)
+		{
+			perso_normal(perso);
+			break;
+		}
+	}
+}
+void gardes()	{ perso_normal(&kPersons[PER_GARDES]); }
+void bambou()	{ perso_normal(&kPersons[PER_BAMBOO]); }
+void kabuka()	{ if(p_global->roomNum == 0x711) perso_normal(&kPersons[PER_KABUKA]); else bambou(); }
+void fisher()	{ if(p_global->roomNum == 0x902) perso_normal(&kPersons[PER_FISHER]); else kabuka(); }
+void dino()
+{
+	perso_t *perso = p_global->room_perso;
+	if(!perso)
+		return;
+	byte_30AFE = 1;
+	p_global->dialogType = 0;
+	p_global->roomPersoFlags = perso->flags;
+	p_global->roomPersoItems = perso->items;
+	p_global->roomPersoPowers = perso->powers;
+	p_global->perso_ptr = perso;
+	init_perso_ptr(perso);
+	debug("beg dino talk");
+	parle_moi();
+	debug("end dino talk");
+	if (p_global->areaNum == Areas::arWhiteArch)
+		return;
+	if(p_global->ff_60)
+		waitendspeak();
+	if(pomme_q)
+		return;
+	perso = &kPersons[PER_MANGO];
+	if(!(p_global->party & PersonMask::pmMungo))
+	{
+		perso = &kPersons[PER_DINA];
+		if(!(p_global->party & PersonMask::pmDina))
+		{
+			perso = &kPersons[PER_EVE];
+			if(!(p_global->party & PersonMask::pmEve))
+			{
+				perso = &kPersons[PER_GARDES];
+			}
+		}
+	}
+	p_global->dialogType = DialogType::dtDinoAction;
+	if(p_global->curObjectId)
+		p_global->dialogType = DialogType::dtDinoItem;
+	perso1(perso);
+	if(p_global->roomPersoType == PersonFlags::pftMosasaurus && !p_global->curObjectId)
+	{
+		p_global->area_ptr->flags |= AreaFlags::afFlag20;
+		lieuvava(p_global->area_ptr);
+	}
+}
+void tyran()
+{
+	perso_t *perso = p_global->room_perso;
+	if(!perso)
+		return;
+	byte_30AFE = 1;
+	p_global->dialogType = 0;
+	p_global->roomPersoFlags = perso->flags;
+	p_global->perso_ptr = perso;
+	init_perso_ptr(perso);
+	perso = &kPersons[PER_MANGO];
+	if(!(p_global->party & PersonMask::pmMungo))
+	{
+		perso = &kPersons[PER_DINA];
+		if(!(p_global->party & PersonMask::pmDina))
+		{
+			perso = &kPersons[PER_EVE];
+			if(!(p_global->party & PersonMask::pmEve))
+			{
+				perso = &kPersons[PER_GARDES];
+			}
+		}
+	}
+	p_global->dialogType = DialogType::dtDinoAction;
+	if(p_global->curObjectId)
+		p_global->dialogType = DialogType::dtDinoItem;
+	perso1(perso);
+}
+void morkus()	{ perso_normal(&kPersons[PER_MORKUS]); }
+void comment()
+{
+	perso_t *perso;
+	perso = &kPersons[PER_DINA];
+	if(!(p_global->party & PersonMask::pmDina))
+	{
+		perso = &kPersons[PER_EVE];
+		if(!(p_global->party & PersonMask::pmEve))
+		{
+			perso = &kPersons[PER_GARDES];
+			if(!(p_global->party & PersonMask::pmThugg))
+			{
+				return;
+			}
+		}
+	}
+	p_global->dialogType = DialogType::dtHint;
+	perso1(perso);
+}
+void adam()
+{
+	char *objvid;
+	object_t *object;
+	short vid;
+	resetscroll();
+	switch(p_global->curObjectId)
+	{
+	case Objects::obNone:
+		gotopanel();
+		break;
+	case Objects::obRoot:
+		if (p_global->roomNum == 2817
+		&& p_global->phaseNum > 496 && p_global->phaseNum < 512)
+		{
+			bigphase1();
+			loseobject(Objects::obRoot);
+			p_global->ff_100 = -1;
+			quitmiroir();
+			maj_salle(p_global->roomNum);
+			reste_ici(5);
+			p_global->eventType = EventType::etEvent3;
+			showevents();
+			waitendspeak();
+			if(pomme_q)
+				return;
+			close_perso();
+			reste_ici(5);
+			p_global->roomNum = 2818;
+			p_global->areaNum = Areas::arWhiteArch;
+			p_global->eventType = EventType::etEvent5;
+			p_global->valleyVidNum = 0;
+			p_global->ff_102 = 6;
+			p_global->newMusicType = MusicType::mtNormal;
+			maj_salle(p_global->roomNum);
+		}
+		else
+		{
+			p_global->dialogType = DialogType::dtHint;
+			perso1(&kPersons[PER_EVE]);
+		}
+		break;
+	case Objects::obShell: 
+		p_global->dialogType = DialogType::dtHint;
+		perso1(&kPersons[PER_THOO]);
+		break;
+	case Objects::obFlute:
+	case Objects::obTrumpet:
+		if(p_global->roomPersoType)
+		{
+			quitmiroir();
+			maj_salle(p_global->roomNum);
+			dino();
+		}
+		else
+			comment();
+		break;
+	case Objects::obTablet1:
+	case Objects::obTablet2:
+	case Objects::obTablet3:
+	case Objects::obTablet4:
+	case Objects::obTablet5:
+	case Objects::obTablet6:
+		if((p_global->partyOutside & PersonMask::pmDina)
+		&& p_global->curObjectId == Objects::obTablet1 && p_global->phaseNum == 370)
+			incphase1();
+		objvid = &kTabletView[(p_global->curObjectId - Objects::obTablet1) * 2];
+		object = getobjaddr(*objvid++);
+		vid = 84;
+		if(!object->count)
+			vid = *objvid;
+		bars_out();
+		specialTextMode = 1;
+		playhnm(vid);
+		needPaletteUpdate = 1;
+		p_global->ff_102 = 16;
+		bars_in();
+		gametomiroir(0);
+		break;
+	case Objects::obApple:
+	case Objects::obShroom:
+	case Objects::obBadShroom:
+	case Objects::obNest:
+	case Objects::obFullNest:
+	case Objects::obDrum:
+		if(p_global->party & PersonMask::pmThugg)
+		{
+			p_global->dialogType = DialogType::dtHint;
+			perso1(&kPersons[PER_GARDES]);
+		}
+		break;
+	default:
+		comment();
+	}
+}
+void init_oui()	{ word_30AFC = -1; }
+void init_non()	{ word_30AFC =  0; }
+void oui()	{ word_30AFC = -1; }
+void non()	{ word_30AFC =  0; }
+char verif_oui(){ return word_30AFC == -1; }
+void SpcChampi(perso_t *perso)
+{
+	perso->flags |= PersonFlags::pf10;
+	p_global->area_ptr->flags |= AreaFlags::afFlag2;
+	p_global->curAreaFlags |= AreaFlags::afFlag2;
+}
+void SpcNidv(perso_t *perso)
+{
+	if(!verif_oui())
+		return;
+	perso->flags |= PersonFlags::pf10;
+	p_global->roomPersoFlags |= PersonFlags::pf10;
+	p_global->gameFlags |= GameFlags::gfFlag400;
+	if(p_global->perso_ptr == &kPersons[PER_EVE])
+	{
+		p_global->area_ptr->flags |= AreaFlags::afFlag4;
+		p_global->curAreaFlags |= AreaFlags::afFlag4;
+		perso->flags |= PersonFlags::pfInParty;
+		p_global->roomPersoFlags |= PersonFlags::pfInParty;
+		lieuvava(p_global->area_ptr);		
+	}
+	else
+	{
+		perso->flags &= ~PersonFlags::pf10;
+		p_global->roomPersoFlags &= ~PersonFlags::pf10;
+	}
+}
+void SpcNido(perso_t *perso)
+{
+	if(perso == &kPersons[PER_GARDES])
+		giveobject();
+}
+void SpcPomme(perso_t *perso)
+{
+	perso->flags |= PersonFlags::pf10;
+	p_global->area_ptr->flags |= AreaFlags::afFlag8;
+	p_global->curAreaFlags |= AreaFlags::afFlag8;
+	p_global->gameFlags |= GameFlags::gfFlag200;
+}
+void SpcOr(perso_t *perso)
+{
+	if(!verif_oui())
+		return;
+	perso->items = currentSpecialObject->itemMask;
+	p_global->roomPersoItems = currentSpecialObject->itemMask;
+	perso->flags |= PersonFlags::pf10;
+	perso->flags &= ~PersonFlags::pfInParty;
+	perso->targetLoc = 0;
+	p_global->area_ptr->flags |= AreaFlags::afGaveGold;
+	p_global->curAreaFlags |= AreaFlags::afGaveGold;
+	if(p_global->phaseNum == 226)
+		incphase1();
+}
+void SpcPrisme(perso_t *perso)
+{
+	if(perso == &kPersons[PER_DINA])
+	{
+		if(p_global->partyOutside & PersonMask::pmMonk)
+			p_global->gameFlags |= GameFlags::gfPrismAndMonk;
+	}
+}
+void SpcTalisman(perso_t *perso)
+{
+	if(perso == &kPersons[PER_DINA])
+		suis_moi(1);
+}
+void SpcMasque(perso_t *perso)
+{
+	if(perso == &kPersons[PER_BAMBOO])
+	{
+		dialautoon();
+		byte_30AFE = 1;
+	}
+}
+void SpcSac(perso_t *perso)
+{
+	if(p_global->textToken1 != 3)
+		return;
+	if(perso == &kPersons[PER_KABUKA] || perso == &kPersons[PER_MAMMI_3])
+		loseobject(currentSpecialObject->id);
+}
+void SpcTrompet(perso_t *perso)
+{
+	if(!verif_oui())
+		return;
+	p_global->ff_54 = 4;
+	winobject(Objects::obTrumpet);
+	p_global->drawFlags |= DrawFlags::drDrawInventory;
+	byte_30B00 = 1;
+	TyranMeurt(p_global->room_perso);
+}
+void SpcArmes(perso_t *perso)
+{
+	if(!verif_oui())
+		return;
+	perso->powers = currentSpecialObject->powerMask;
+	p_global->roomPersoPowers = currentSpecialObject->powerMask;
+	giveobject();
+}
+void SpcInstru(perso_t *perso)
+{
+	if(!verif_oui())
+		return;
+	if(perso == &kPersons[PER_MONK])
+	{
+		p_global->partyInstruments &= ~1;	//TODO: check me
+		if(currentSpecialObject->id == Objects::obRing)
+		{
+			p_global->partyInstruments |= 1;
+			p_global->monkGotRing++;				//TODO: |= 1 ?
+		}
+	}
+	if(perso == &kPersons[PER_GARDES])
+	{
+		p_global->partyInstruments &= ~2;
+		if(currentSpecialObject->id == Objects::obDrum)
+			p_global->partyInstruments |= 2;
+	}
+	perso->powers = currentSpecialObject->powerMask;
+	p_global->curPersoPowers = currentSpecialObject->powerMask;
+	giveobject();
+}
+void SpcOeuf(perso_t *perso)
+{
+	if(!verif_oui())
+		return;
+	gameIcons[131].cursor_id &= ~0x8000;
+	p_global->persoBackgroundBankIdx = 62;
+	dialautoon();
+}
+void TyranMeurt(perso_t *perso)
+{
+	perso->flags |= PersonFlags::pf80;
+	perso->roomNum = 0;
+	delinfo(p_global->areaNum + ValleyNews::vnTyrannIn);
+	p_global->roomPersoType = 0;
+	p_global->roomPersoFlags = 0;
+	p_global->chrono_on = 0;
+}
+void SpecialObjets(perso_t *perso, char objid)
+{
+	typedef void (EdenGameImpl::*disp_t)(perso_t *perso);
+	struct spcobj_t {
+		char	persoType;
+		char	objectId;
+//		void	(EdenGameImpl::*disp)(perso_t *perso);
+		disp_t	disp;
+	};
+
+	static spcobj_t kSpecialObjectActions[] = {
+		//    perso, obj, disp
+			{ PersonFlags::pfType8, Objects::obShroom, &EdenGameImpl::SpcChampi },
+			{ PersonFlags::pftTriceraptor, Objects::obNest, &EdenGameImpl::SpcNidv },
+			{ PersonFlags::pfType0, Objects::obFullNest, &EdenGameImpl::SpcNido },
+			{ PersonFlags::pftMosasaurus, Objects::obApple, &EdenGameImpl::SpcPomme },
+			{ PersonFlags::pftVelociraptor, Objects::obGold, &EdenGameImpl::SpcOr },
+			{ PersonFlags::pfType0, Objects::obPrism, &EdenGameImpl::SpcPrisme },
+			{ PersonFlags::pfType0, Objects::obTalisman, &EdenGameImpl::SpcTalisman },
+			{ PersonFlags::pfType2, Objects::obMaskOfDeath, &EdenGameImpl::SpcMasque },
+			{ PersonFlags::pfType2, Objects::obMaskOfBonding, &EdenGameImpl::SpcMasque },
+			{ PersonFlags::pfType2, Objects::obMaskOfBirth, &EdenGameImpl::SpcMasque },
+			{ PersonFlags::pfType0, Objects::obBag, &EdenGameImpl::SpcSac },
+			{ PersonFlags::pfType2, Objects::obBag, &EdenGameImpl::SpcSac },
+			{ PersonFlags::pftTyrann, Objects::obTrumpet, &EdenGameImpl::SpcTrompet },
+			{ PersonFlags::pftVelociraptor, Objects::obEyeInTheStorm, &EdenGameImpl::SpcArmes },
+			{ PersonFlags::pftVelociraptor, Objects::obSkyHammer, &EdenGameImpl::SpcArmes },
+			{ PersonFlags::pftVelociraptor, Objects::obFireInTheClouds, &EdenGameImpl::SpcArmes },
+			{ PersonFlags::pftVelociraptor, Objects::obWithinAndWithout, &EdenGameImpl::SpcArmes },
+			{ PersonFlags::pftVelociraptor, Objects::obEyeInTheCyclone, &EdenGameImpl::SpcArmes },
+			{ PersonFlags::pftVelociraptor, Objects::obRiverThatWinds, &EdenGameImpl::SpcArmes },
+			{ PersonFlags::pfType0, Objects::obTrumpet, &EdenGameImpl::SpcInstru },
+			{ PersonFlags::pfType0, Objects::obDrum, &EdenGameImpl::SpcInstru },
+			{ PersonFlags::pfType0, Objects::obRing, &EdenGameImpl::SpcInstru },
+			{ PersonFlags::pfType0, Objects::obEgg, &EdenGameImpl::SpcOeuf },
+			{ -1, -1, nullptr }
+	};
+	spcobj_t *spcobj = kSpecialObjectActions;
+	char persoType = perso->flags & PersonFlags::pfTypeMask;
+	currentSpecialObject = &objects[objid - 1];
+	for (; spcobj->persoType != -1; spcobj++)
+	{
+		if (spcobj->objectId == objid && spcobj->persoType == persoType)
+		{
+			(this->*spcobj->disp)(perso);
+			break;
+		}
+	}
+}
+
+void dialautoon()
+{
+	p_global->iconsIndex = 4;
+	p_global->autoDialog = -1;
+	putobject();
+}
+void dialautooff()
+{
+	p_global->iconsIndex = 0x10;
+	p_global->autoDialog = 0;
+}
+void follow()
+{
+	if(p_global->roomPersoType == PersonFlags::pfType12)
+	{
+		debug("follow: hiding person %d", p_global->room_perso - kPersons);
+		p_global->room_perso->flags |= PersonFlags::pf80;
+		p_global->room_perso->roomNum = 0;
+		p_global->gameFlags |= GameFlags::gfFlag8;
+		gameIcons[123].object_id = 18;
+		gameIcons[124].object_id = 35;
+		gameIcons[125].cursor_id &= ~0x8000;
+		p_global->persoBackgroundBankIdx = 56;
+	}
+	else
+		suis_moi5();
+}
+void dialonfollow()
+{
+	p_global->iconsIndex = 4;
+	p_global->autoDialog = -1;
+	follow();
+}
+void abortdial()
+{
+	p_global->ff_F6++;
+	if(p_global->roomPersoType != PersonFlags::pftTriceraptor || p_global->perso_ptr != &kPersons[PER_EVE])
+		return;
+	p_global->area_ptr->flags |= AreaFlags::afFlag4;
+	p_global->curAreaFlags |= AreaFlags::afFlag4;
+	p_global->room_perso->flags |= PersonFlags::pfInParty;
+	p_global->roomPersoFlags |= PersonFlags::pfInParty;
+	lieuvava(p_global->area_ptr);
+}
+void narrateur()
+{
+	if(!(p_global->displayFlags & DisplayFlags::dfFlag1))
+		return;
+	if(!p_global->narratorSequence)
+	{
+		if(p_global->ff_6A == p_global->ff_69)
+			goto skip;
+		buildcita();
+	}
+	p_global->ff_F5 |= 0x80;
+	p_global->ff_F2 &= ~1;	//TODO: check me
+	p_global->perso_ptr = &kPersons[PER_UNKN_156];
+	p_global->ff_60 = 0;
+	p_global->eventType = 0;
+	p_global->ff_103 = 69;
+	if(dialo_even(&kPersons[PER_UNKN_156]))
+	{
+		p_global->narrator_dialog_ptr = p_global->dialog_ptr;
+		dialautoon();
+		p_global->ff_F2 |= 1;
+		waitendspeak();
+		if(pomme_q)
+			return;
+		endpersovox();
+		while(dialoscansvmas(p_global->narrator_dialog_ptr))
+		{
+			p_global->narrator_dialog_ptr = p_global->dialog_ptr;
+			waitendspeak();
+			if(pomme_q)
+				return;
+			endpersovox();
+		}
+		p_global->narrator_dialog_ptr = p_global->dialog_ptr;
+		p_global->ff_102 = 0;
+		p_global->ff_103 = 0;
+		close_perso();
+		lieuvava(p_global->area_ptr);
+		if(p_global->narratorSequence == 8)
+			deplaval(134);
+	}
+	p_global->ff_103 = 0;
+	if(p_global->narratorSequence == 10)
+	{
+		suis_moi(5);
+		suis_moi(7);
+		suis_moi(3);
+		suis_moi(18);
+		reste_ici(6);
+		p_global->eloiHaveNews = 0;
+		deplaval(139);
+	}
+	p_global->eventType = EventType::etEventD;
+	showevents();
+	p_global->ff_F5 &= ~0x80;
+skip:;
+	p_global->ff_F2 &= ~1;	//TODO: check me
+	if(p_global->narratorSequence > 50 && p_global->narratorSequence <= 80)
+		p_global->endGameFlag = 50;
+	if(p_global->narratorSequence == 3)
+		chronoon(1200);
+	p_global->narratorSequence = 0;
+	
+}
+void vrf_phrases_file()
+{
+	short num = 3;
+	if(p_global->dialog_ptr < (dial_t*)GetElem(gameDialogs, 48))
+		num = 1;
+	else if(p_global->dialog_ptr < (dial_t*)GetElem(gameDialogs, 128))
+		num = 2;
+	p_global->textBankIndex = num;
+	if(p_global->pref_language)
+		num += (p_global->pref_language - 1) * 3;
+	if(num == lastPhrasesFile)
+		return;
+	lastPhrasesFile = num;
+	num += 404;
+	loadfile(num, gamePhrases);
+	verifh(gamePhrases);
+}
+unsigned char* gettxtad(short id)
+{
+	vrf_phrases_file();
+	return (unsigned char*)GetElem(gamePhrases, id - 1);
+}
+void gotocarte()
+{
+	char newArea, curArea;
+	goto_t *go = &gotos[current_spot2->object_id];
+	endpersovox();
+	newArea = go->areaNum;
+	p_global->newRoomNum = (go->areaNum << 8) | 1;
+	p_global->newLocation = 1;
+	p_global->prevLocation = p_global->roomNum & 0xFF;
+	curArea = p_global->roomNum >> 8;
+	if(curArea == go->areaNum)
+		newArea = 0;
+	else
+	{
+		for(;go->curAreaNum != 0xFF;go++)
+			if(go->curAreaNum == curArea)
+				break;
+		if(go->areaNum == 0xFF)
+			return;
+	}
+	p_global->eventType = EventType::etGotoArea | newArea;
+	init_oui();
+	showevents1();
+	waitendspeak();
+	if(pomme_q)
+		return;
+	close_perso();
+	if(verif_oui())
+		gotolieu(go);
+}
+void record()
+{
+	short i;
+	tape_t *tape;
+	perso_t *perso;
+	if(p_global->curObjectId)
+		return;
+	if(p_global->perso_ptr >= &kPersons[PER_UNKN_18C])
+		return;
+	if(p_global->eventType == EventType::etEventE || p_global->eventType >= EventType::etGotoArea)
+		return;
+	for(tape = tapes;tape != tapes + MAX_TAPES;tape++)
+		if(tape->textNum == p_global->textNum)
+			return;
+	for(tape = tapes, i = 0;i < MAX_TAPES - 1;i++)
+	{
+		tape->textNum = tape[+1].textNum;
+		tape->perso = tape[+1].perso;
+		tape->party = tape[+1].party;
+		tape->roomNum = tape[+1].roomNum;
+		tape->bgBankNum = tape[+1].bgBankNum;
+		tape->dialog = tape[+1].dialog;
+		tape++;
+	}
+	perso = p_global->perso_ptr;
+	if(perso == &kPersons[PER_EVE])
+		perso = p_global->phaseNum >= 352 ? &kPersons[PER_UNKN_372]
+						  : &kPersons[PER_UNKN_402];
+	tape->textNum = p_global->textNum;
+	tape->perso = perso;
+	tape->party = p_global->party;
+	tape->roomNum = p_global->roomNum;
+	tape->bgBankNum = p_global->roomBgBankNum;
+	tape->dialog = p_global->dialog_ptr;
+}
+char dial_scan(dial_t *dial)
+{
+	unsigned char flags;
+	unsigned char hidx, lidx;
+	char bidx, pnum;
+	short i;
+	unsigned short mask;
+	perso_t *perso;
+	if(p_global->numGiveObjs)
+	{
+		if(!(p_global->displayFlags & DisplayFlags::dfFlag2))
+			showobjects();
+		p_global->numGiveObjs = 0;
+	}
+	p_global->dialog_ptr = dial;
+	vavapers();
+	p_global->phraseBufferPtr = phraseBuffer;
+	for(;;p_global->dialog_ptr++)
+	{
+		for(;;p_global->dialog_ptr++)
+		{
+			if (p_global->dialog_ptr->flags == -1 && p_global->dialog_ptr->condNumLow == -1)
+				return 0;
+			flags = p_global->dialog_ptr->flags;
+			p_global->dialogFlags = flags;
+			if (!(flags & DialogFlags::dfSpoken) || (flags & DialogFlags::dfRepeatable))
+			{
+				hidx = (p_global->dialog_ptr->textCondHiMask >> 6) & 3;
+				lidx = p_global->dialog_ptr->condNumLow;
+				if(flags & 0x10)
+					hidx |= 4;
+				if(testcondition(((hidx << 8) | lidx) & 0x7FF))
+					break;
+			}
+			else
+			{
+				if(flags & dialogSkipFlags)
+					continue;
+				hidx = (p_global->dialog_ptr->textCondHiMask >> 6) & 3;
+				lidx = p_global->dialog_ptr->condNumLow;
+				if(flags & 0x10)
+					hidx |= 4;
+				if(testcondition(((hidx << 8) | lidx) & 0x7FF))
+					break;
+			}
+		}
+		bidx = (p_global->dialog_ptr->textCondHiMask >> 2) & 0xF;
+		if(!bidx)
+			goto no_perso;	//TODO: rearrange
+		mask = (p_global->party | p_global->partyOutside) & (1 << (bidx - 1));
+		if(mask)
+			break;
+	}
+	for(perso = kPersons;!(perso->party == mask && perso->roomNum == p_global->roomNum);perso++) ;	//Find matching
+	p_global->perso_ptr = perso;
+	init_perso_ptr(perso);
+	no_perso();
+no_perso:;
+	hidx = p_global->dialog_ptr->textCondHiMask;
+	lidx = p_global->dialog_ptr->textNumLow;
+	p_global->textNum = ((hidx << 8) | lidx) & 0x3FF;
+	if(p_global->phraseBufferPtr != phraseBuffer)
+	{
+		for(i = 0;i < 32;i++)
+			SysBeep(1);
+	}
+	else
+		my_bulle();
+	if(!dword_30B04)
+	{
+		static void (EdenGameImpl::*talk_subject[])() = {
+			&EdenGameImpl::oui,
+			&EdenGameImpl::non,
+			&EdenGameImpl::eloipart,
+			&EdenGameImpl::dialautoon,
+			&EdenGameImpl::dialautooff,
+			&EdenGameImpl::stay_here,
+			&EdenGameImpl::follow,
+			&EdenGameImpl::citadelle,
+			&EdenGameImpl::dialonfollow,
+			&EdenGameImpl::abortdial,
+			&EdenGameImpl::incphase,
+			&EdenGameImpl::bigphase,
+			&EdenGameImpl::giveobject,
+			&EdenGameImpl::choixzone,
+			&EdenGameImpl::lostobject
+		};
+		pnum = p_global->dialog_ptr->flags & 0xF;
+		if(pnum)
+			(this->*talk_subject[pnum - 1])();
+		p_global->ff_60 = -1;
+		p_global->dialog_ptr->flags |= DialogFlags::dfSpoken;
+		p_global->dialog_ptr++;
+	}
+	if(p_global->dialogType != DialogType::dtInspect)
+	{
+		record();
+		getdatasync();
+		show_perso();
+		persovox();
+	}
+	return 1;
+}
+char dialoscansvmas(dial_t *dial)
+{
+	char res;
+	char old = dialogSkipFlags;
+	dialogSkipFlags = DialogFlags::df20;
+	res = dial_scan(dial);
+	dialogSkipFlags = old;
+	return res;
+}
+char dialo_even(perso_t *perso)
+{
+	char res;
+	int num;
+	dial_t *dial;
+	p_global->perso_ptr = perso;
+	num = (perso->id << 3) | DialogType::dtEvent;
+	dial = (dial_t*)GetElem(gameDialogs, num);
+	res = dialoscansvmas(dial);
+	p_global->last_dialog_ptr = 0;
+	byte_30AFE = 0;
+	return res;	
+}
+void stay_here()
+{
+	if(p_global->perso_ptr == &kPersons[PER_DINA] && p_global->roomNum == 260)
+		p_global->gameFlags |= GameFlags::gfFlag1000;
+	reste_ici5();
+}
+void mort(short vid)
+{
+	bars_out();
+	playhnm(vid);
+	fadetoblack(2);
+	CLBlitter_FillScreenView(0);
+	CLBlitter_FillView(p_mainview, 0);
+	bars_in();
+	p_global->narratorSequence = 51;
+	p_global->newMusicType = MusicType::mtNormal;
+	musique();
+	musicspy();
+}
+void evenchrono()
+{
+	unsigned short old;
+	if(!(p_global->displayFlags & DisplayFlags::dfFlag1))
+		return;
+	old = p_global->gameTime;
+	currentTime = TimerTicks / 100;
+	p_global->gameTime = currentTime;
+	if(p_global->gameTime <= old)
+		return;
+	heurepasse();
+	if(!(p_global->chrono_on & 1))
+		return;
+	p_global->chrono -= 200;
+	if(p_global->chrono == 0)
+		p_global->chrono_on |= 2;
+	if(!(p_global->chrono_on & 2))
+		return;
+	p_global->chrono_on = 0;
+	p_global->chrono = 0;
+	if(p_global->roomPersoType == PersonFlags::pftTyrann)
+	{
+		short vid = 272;
+		if(p_global->curRoomFlags & 0xC0)
+		{
+			vid += 2;
+			if((p_global->curRoomFlags & 0xC0) != 0x80)
+			{
+				vid += 2;
+				mort(vid);
+				return;
+			}
+		}
+		if(p_global->areaNum == Areas::arUluru || p_global->areaNum == Areas::arTamara)
+		{
+			mort(vid);
+			return;
+		}
+		vid++;
+		mort(vid);
+		return;
+	}
+	if(p_global->roomNum == 2817)
+	{
+		suis_moi(5);
+		p_global->gameFlags |= GameFlags::gfFlag40;
+		dialautoon();
+	}
+	else
+		eloirevient();
+	p_global->eventType = EventType::etEvent10;
+	showevents();
+}
+void chronoon(short t)
+{
+	p_global->chrono = t;
+	p_global->chrono_on = 1;
+}
+void prechargephrases(short vid)
+{
+	int num;
+	dial_t *dial;
+	perso_t *perso = &kPersons[PER_MORKUS];
+	if(vid == 170)
+		perso = &kPersons[PER_UNKN_156];
+	p_global->perso_ptr = perso;
+	p_global->dialogType = DialogType::dtInspect;
+	num = (perso->id << 3) | p_global->dialogType;
+	dial = (dial_t*)GetElem(gameDialogs, num);
+	dialoscansvmas(dial);
+}
+void effet1()
+{
+	debug(__FUNCTION__);
+	int x, y;
+	short i;
+	short dy, ny;
+	rectanglenoir32();
+	if(!doubled)
+	{
+		setRS1(0, 0, 16 - 1, 4 - 1);
+		y = p_mainview->norm.dst_top;
+		for(i = 16;i <= 96;i += 4)
+		{
+			for(x = p_mainview->norm.dst_left;x < p_mainview->norm.dst_left + 320;x += 16)
+			{
+				setRD1(x, y + i, x + 16 - 1, y + i + 4 - 1);
+				CLBlitter_CopyViewRect(p_view2, &ScreenView, &rect_src, &rect_dst);
+				setRD1(x, y + 192 - i, x + 16 - 1, y + 192 - i + 4 - 1);
+				CLBlitter_CopyViewRect(p_view2, &ScreenView, &rect_src, &rect_dst);
+			}
+			CLBlitter_UpdateScreen();
+			wait(1);
+		}
+	}
+	else
+	{
+		setRS1(0, 0, 16 * 2 - 1, 4 * 2 - 1);
+		y = p_mainview->zoom.dst_top;
+		for(i = 16 * 2;i <= 96 * 2;i += 4 * 2)
+		{
+			for(x = p_mainview->zoom.dst_left;x < p_mainview->zoom.dst_left + 320 * 2;x += 16 * 2)
+			{
+				setRD1(x, y + i, x + 16 * 2 - 1, y + i + 4 * 2 - 1);
+				CLBlitter_CopyViewRect(p_view2, &ScreenView, &rect_src, &rect_dst);
+				setRD1(x, y + 192 * 2 - i, x + 16 * 2 - 1, y + 192 * 2 - i + 4 * 2 - 1);
+				CLBlitter_CopyViewRect(p_view2, &ScreenView, &rect_src, &rect_dst);
+			}
+			wait(1);
+		}
+	}
+	CLPalette_Send2Screen(global_palette, 0, 256);
+	p_mainview->norm.height = 2;
+	p_mainview->zoom.height = 4;
+	ny = p_mainview->norm.dst_top;
+	dy = p_mainview->zoom.dst_top;
+	for(i = 0;i < 100;i += 2)
+	{
+		p_mainview->norm.src_top = 99 - i;
+		p_mainview->zoom.src_top = 99 - i;
+		p_mainview->norm.dst_top = 99 - i + ny;
+		p_mainview->zoom.dst_top = (99 - i) * 2 + dy;
+		CLBlitter_CopyView2Screen(p_mainview);
+		p_mainview->norm.src_top = 100 + i;
+		p_mainview->zoom.src_top = 100 + i;
+		p_mainview->norm.dst_top = 100 + i + ny;
+		p_mainview->zoom.dst_top = (100 + i) * 2 + dy;
+		CLBlitter_CopyView2Screen(p_mainview);
+		CLBlitter_UpdateScreen();
+		wait(1);
+	}
+	p_mainview->norm.height = 200;
+	p_mainview->zoom.height = 400;
+	p_mainview->norm.src_top = 0;
+	p_mainview->zoom.src_top = 0;
+	p_mainview->norm.dst_top = ny;
+	p_mainview->zoom.dst_top = dy;
+	p_global->ff_F1 = 0;
+}
+void effet2()
+{
+	debug(__FUNCTION__);
+	static int eff2pat = 0;
+	if(p_global->ff_103 == 69)
+	{
+		effet4();
+		return;
+	}
+	switch(++eff2pat)
+	{
+	case 1:
+		{
+			static short pattern[] = {0, 1, 2, 3, 7, 11, 15, 14, 13, 12, 8, 4, 5, 6, 10, 9};
+			colimacon(pattern);
+			break;
+		}
+	case 2:
+		{
+			static short pattern[] = {0, 15, 1, 14, 2, 13, 3, 12, 7, 8, 11, 4, 5, 10, 6, 9};
+			colimacon(pattern);
+			break;
+		}
+	case 3:
+		{
+			static short pattern[] = {0, 2, 5, 7, 8, 10, 13, 15, 1, 3, 4, 6, 9, 11, 12, 14};
+			colimacon(pattern);
+			break;
+		}
+	case 4:
+		{
+			static short pattern[] = {0, 3, 15, 12, 1, 7, 14, 8, 2, 11, 13, 4, 5, 6, 10, 9};
+			colimacon(pattern);
+			eff2pat = 0;
+			break;
+		}
+	}
+}
+void effet3()
+{
+	debug(__FUNCTION__);
+	unsigned short i, c;
+	CLPalette_GetLastPalette(oldPalette);
+	for(i = 0;i < 6;i++)
+	{
+		for(c = 0;c < 256;c++)
+		{
+			newColor.r = oldPalette[c].r >> i;
+			newColor.g = oldPalette[c].g >> i;
+			newColor.b = oldPalette[c].b >> i;
+			CLPalette_SetRGBColor(newPalette, c, &newColor);
+		}
+		CLPalette_Send2Screen(newPalette, 0, 256);
+		wait(1);
+	}
+	CLBlitter_CopyView2Screen(p_mainview);
+	for(i = 0;i < 6;i++)
+	{
+		for(c = 0;c < 256;c++)
+		{
+			newColor.r = global_palette[c].r >> (5 - i);
+			newColor.g = global_palette[c].g >> (5 - i);
+			newColor.b = global_palette[c].b >> (5 - i);
+			CLPalette_SetRGBColor(newPalette, c, &newColor);
+		}
+		CLPalette_Send2Screen(newPalette, 0, 256);
+		wait(1);
+	}
+}
+void effet4()
+{
+	debug(__FUNCTION__);
+	unsigned char *scr, *pix, *r24, *r25, *r30, c;
+	short i;
+	short x, y;
+	short w, h, ww;
+	short r17, r23, r16, r18, r19, r22, r27, r31;
+	CLPalette_Send2Screen(global_palette, 0, 256);
+	w = ScreenView.width;
+	h = ScreenView.height;
+	ww = ScreenView.pitch;
+	if(!doubled)
+	{
+		x = p_mainview->norm.dst_left;
+		y = p_mainview->norm.dst_top;
+		for(i = 32;i > 0;i -= 2)
+		{
+			scr = ScreenView.p_buffer;
+			scr += (y + 16) * ww + x;
+			pix = p_mainview->p_buffer + 16 * 640;
+			r17 = 320 / i;
+			r23 = 320 - 320 / i * i;  //TODO: 320 % i ?
+			r16 = 160 / i;
+			r18 = 160 - 160 / i * i;  //TODO: 160 % i ?
+			for(r19 = r16;r19 > 0;r19--)
+			{
+				r24 = scr;
+				r25 = pix;
+				for(r22 = r17;r22 > 0;r22--)
+				{
+					c = *r25;
+					r25 += i;
+					r30 = r24;
+					for(r27 = i;r27 > 0;r27--)
+					{
+						for(r31 = i;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - i;
+					}
+					r24 += i;
+				}
+				if(r23)
+				{
+					c = *r25;
+					r30 = r24;
+					for(r27 = i;r27 > 0;r27--)
+					{
+						for(r31 = r23;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - r23;
+					}
+				}
+				scr += i * ww;
+				pix += i * 640;
+			}
+			if(r18)
+			{
+				r24 = scr;
+				r25 = pix;
+				for(r22 = r17;r22 > 0;r22--)
+				{
+					c = *r25;
+					r25 += i;
+					r30 = r24;
+					for(r27 = r18;r27 > 0;r27--)
+					{
+						for(r31 = i;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - i;
+					}
+					r24 += i;
+				}
+				if(r23)
+				{
+					c = *r25;
+					r30 = r24;
+					for(r27 = r18;r27 > 0;r27--)
+					{
+						for(r31 = r23;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - r23;
+					}
+				}
+			}
+			CLBlitter_UpdateScreen();
+			wait(3);
+		}
+	}
+	else
+	{
+		x = p_mainview->zoom.dst_left;
+		y = p_mainview->zoom.dst_top;
+		for(i = 32;i > 0;i -= 2)
+		{
+			scr = ScreenView.p_buffer;
+			scr += (y + 16 * 2) * ww + x;
+			pix = p_mainview->p_buffer + 16 * 640;
+			r17 = 320 / i;
+			r23 = 320 % i;
+			r16 = 160 / i;
+			r18 = 160 % i;
+			for(r19 = r16;r19 > 0;r19--)
+			{
+				r24 = scr;
+				r25 = pix;
+				for(r22 = r17;r22 > 0;r22--)
+				{
+					c = *r25;
+					r25 += i;
+					r30 = r24;
+					for(r27 = i * 2;r27 > 0;r27--)
+					{
+						for(r31 = i * 2;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - i * 2;
+					}
+					r24 += i * 2;
+				}
+				if(r23)
+				{
+					c = *r25;
+					r30 = r24;
+					for(r27 = i * 2;r27 > 0;r27--)
+					{
+						for(r31 = r23 * 2;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - r23 * 2;
+					}
+				}
+				scr += i * ww * 2;
+				pix += i * 640;
+			}
+			if(r18)
+			{
+				r24 = scr;
+				r25 = pix;
+				for(r22 = r17;r22 > 0;r22--)
+				{
+					c = *r25;
+					r25 += i;
+					r30 = r24;
+					for(r27 = r18 * 2;r27 > 0;r27--)
+					{
+						for(r31 = i * 2;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - i * 2;
+					}
+					r24 += i * 2;
+				}
+				if(r23)
+				{
+					c = *r25;
+					r30 = r24;
+					for(r27 = i * 2;r27 > 0;r27--)
+					{
+						for(r31 = r23 * 2;r31 > 0;r31--)
+							*r30++ = c;
+						r30 += ww - r23 * 2;
+					}
+				}
+			}
+			wait(3);
+		}
+	}
+	CLBlitter_CopyView2Screen(p_mainview);
+}
+void ClearScreen()
+{
+	unsigned char *scr;
+	short x, y, xx, yy;
+	short w, h, ww;
+	w = ScreenView.width;
+	h = ScreenView.height;
+	ww = ScreenView.pitch;
+	if(!doubled)
+	{
+		x = p_mainview->norm.dst_left;
+		y = p_mainview->norm.dst_top;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16) * ww + x;
+		for(yy = 0;yy < 160;yy++)
+		{
+			for(xx = 0;xx < 320;xx++)
+				*scr++ = 0;
+			scr += ww - 320;
+		}
+	}
+	else
+	{
+		x = p_mainview->zoom.dst_left;
+		y = p_mainview->zoom.dst_top;
+		scr = ScreenView.p_buffer;
+		scr += (y + 32) * ww + x;
+		for(yy = 0;yy < 160;yy++)
+		{
+			for(xx = 0;xx < 320;xx++)
+			{
+				scr[0] = 0;
+				scr[1] = 0;
+				scr[ww] = 0;
+				scr[ww + 1] = 0;
+				scr += 2;
+			}
+			scr += (ww - 320) * 2;
+		}
+	}
+	CLBlitter_UpdateScreen();
+}
+void colimacon(short pattern[16])
+{
+	unsigned char *scr, *pix;
+	short x, y, xx, yy;
+	short w, h, ww;
+	short i, j, p, r27, r25;
+	w = ScreenView.width;
+	h = ScreenView.height;
+	ww = ScreenView.pitch;
+	if(!doubled)
+	{
+		x = p_mainview->norm.dst_left;
+		y = p_mainview->norm.dst_top;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16) * ww + x;
+		for(i = 0;i < 16;i++)
+		{
+			p = pattern[i];
+			r27 = p % 4 + p / 4 * ww;
+			for(j = 0;j < 320 * 160 / 16;j++)
+				scr[j / (320 / 4) * ww * 4 + j % (320 / 4) * 4 + r27] = 0;
+			CLBlitter_UpdateScreen();
+			wait(1);
+		}
+	}
+	else
+	{
+		x = p_mainview->zoom.dst_left;
+		y = p_mainview->zoom.dst_top;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16 * 2) * ww + x;
+		for(i = 0;i < 16;i++)
+		{
+			p = pattern[i];
+			r27 = p % 4 * 2 + p / 4 * ww * 2;
+			for(j = 0;j < 320 * 160 / 16;j++)
+			{
+				unsigned char *sc = &scr[j / (320 / 4) * ww * 4 * 2 + j % (320 / 4) * 4 * 2 + r27];
+				sc[0] = 0;
+				sc[1] = 0;
+				sc[ww] = 0;
+				sc[ww + 1] = 0;
+			}
+			wait(1);
+		}
+	}
+	CLPalette_Send2Screen(global_palette, 0, 256);
+	if(!doubled)
+	{
+		pix = p_mainview->p_buffer;
+		x = p_mainview->norm.dst_left;
+		y = p_mainview->norm.dst_top;
+		pix += 640 * 16;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16) * ww + x;
+		for(i = 0;i < 16;i++)
+		{
+			p = pattern[i];
+			r25 = p % 4 + p / 4 * 640;
+			r27 = p % 4 + p / 4 * ww;
+			for(j = 0;j < 320 * 160 / 16;j++)
+				scr[j / (320 / 4) * ww * 4 + j % (320 / 4) * 4 + r27] = 
+					pix[j / (320 / 4) * 640 * 4 + j % (320 / 4) * 4 + r25];
+			CLBlitter_UpdateScreen();
+			wait(1);
+		}
+	}
+	else
+	{
+		pix = p_mainview->p_buffer;
+		x = p_mainview->zoom.dst_left;
+		y = p_mainview->zoom.dst_top;
+		pix += 640 * 16;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16 * 2) * ww + x;
+		for(i = 0;i < 16;i++)
+		{
+			p = pattern[i];
+			r25 = p % 4 + p / 4 * 640;
+			r27 = p % 4 * 2 + p / 4 * ww * 2;
+			for(j = 0;j < 320 * 160 / 16;j++)
+			{
+				unsigned char c = pix[j / (320 / 4) * 640 * 4 + j % (320 / 4) * 4 + r25];
+				unsigned char *sc = &scr[j / (320 / 4) * ww * 4 * 2 + j % (320 / 4) * 4 * 2 + r27];
+				sc[0] = c;
+				sc[1] = c;
+				sc[ww] = c;
+				sc[ww + 1] = c;
+			}
+			wait(1);
+		}
+	}
+}
+void fadetoblack(int delay)
+{
+	short i, j;
+	CLPalette_GetLastPalette(oldPalette);
+	for(i = 0;i < 6;i++)
+	{
+		for(j = 0;j < 256;j++)
+		{
+			newColor.r = oldPalette[j].r >> i;
+			newColor.g = oldPalette[j].g >> i;
+			newColor.b = oldPalette[j].b >> i;
+			CLPalette_SetRGBColor(newPalette, j, &newColor);
+		}
+		CLPalette_Send2Screen(newPalette, 0, 256);
+		wait(delay);
+	}
+}
+void fadetoblack128(int delay)
+{
+	short i, j;
+	CLPalette_GetLastPalette(oldPalette);
+	for(i = 0;i < 6;i++)
+	{
+		for(j = 0;j < 129;j++)	//TODO: wha?
+		{
+			newColor.r = oldPalette[j].r >> i;
+			newColor.g = oldPalette[j].g >> i;
+			newColor.b = oldPalette[j].b >> i;
+			CLPalette_SetRGBColor(newPalette, j, &newColor);
+		}
+		CLPalette_Send2Screen(newPalette, 0, 128);
+		wait(delay);
+	}
+}
+void fadefromblack128(int delay)
+{
+	short i, j;
+	for(i = 0;i < 6;i++)
+	{
+		for(j = 0;j < 129;j++)	//TODO: wha?
+		{
+			newColor.r = global_palette[j].r >> (5 - i);
+			newColor.g = global_palette[j].g >> (5 - i);
+			newColor.b = global_palette[j].b >> (5 - i);
+			CLPalette_SetRGBColor(newPalette, j, &newColor);
+		}
+		CLPalette_Send2Screen(newPalette, 0, 128);
+		wait(delay);
+	}
+}
+void rectanglenoir32()
+{
+	// blacken 32x32 rectangle
+	int i;
+	int *pix = (int*)p_view2_buf;
+	for(i = 0;i < 32;i++)
+	{
+		pix[0] = 0;
+		pix[1] = 0;
+		pix[2] = 0;
+		pix[3] = 0;
+		pix[4] = 0;
+		pix[5] = 0;
+		pix[6] = 0;
+		pix[7] = 0;
+		pix += 32 / 4;
+	}
+}
+void setRS1(short sx, short sy, short ex, short ey)
+{
+	rect_src.sx = sx;
+	rect_src.sy = sy;
+	rect_src.ex = ex;
+	rect_src.ey = ey;
+}
+void setRD1(short sx, short sy, short ex, short ey)
+{
+	rect_dst.sx = sx;
+	rect_dst.sy = sy;
+	rect_dst.ex = ex;
+	rect_dst.ey = ey;
+}
+void wait(int howlong)
+{
+	int t2, t = TickCount();
+#ifdef EDEN_DEBUG
+	howlong *= 10;
+#endif
+	for (t2 = t; t2 - t < howlong; t2 = TickCount()) g_system->delayMillis(10); // waste time
+}
+void effetpix()
+{
+	debug(__FUNCTION__);
+	unsigned char *scr, *pix;
+	short x, y, xx, yy;
+	short w, h, ww;
+	short i, j, p, r25, r18, r31, r30;	//TODO: change to xx/yy
+	unsigned char r24, r23;			//TODO: change to p0/p1
+	short r26, r27, r20;
+	w = ScreenView.width;
+	h = ScreenView.height;
+	ww = ScreenView.pitch;
+	r25 = ww * 80;
+	r18 = 640 * 80;
+	pix = p_mainview->p_buffer + 16 * 640;
+	if(!doubled)
+	{
+		x = p_mainview->norm.dst_left;
+		y = p_mainview->norm.dst_top;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16) * ww + x;
+	}
+	else
+	{
+		x = p_mainview->zoom.dst_left;
+		y = p_mainview->zoom.dst_top;
+		scr = ScreenView.p_buffer;
+		scr += (y + 16 * 2) * ww + x;
+		r25 *= 2;
+	}
+	r20 = 0x4400;	//TODO
+	r27 = 1;
+	r26 = 0;
+	do
+	{
+		char r8 = r27 & 1;
+		r27 >>= 1;
+		if(r8)
+			r27 ^= r20;
+		if(r27 < 320 * 80)
+		{
+			r31 = r27 / 320;
+			r30 = r27 % 320;
+			if(doubled)
+			{
+			        r31 *= 2;
+				r30 *= 2;
+				scr[r31 * ww + r30] = 0;
+				scr[r31 * ww + r30 + 1] = 0;
+				scr[r31 * ww + r25 + r30] = 0;
+				scr[r31 * ww + r25 + r30 + 1] = 0;
+				r31++;
+				scr[r31 * ww + r30] = 0;
+				scr[r31 * ww + r30 + 1] = 0;
+				scr[r31 * ww + r25 + r30] = 0;
+				scr[r31 * ww + r25 + r30 + 1] = 0;
+				if(++r26 == 960)
+				{
+					wait(1);
+					r26 = 0;
+				}
+			}
+			else
+			{
+				scr[r31 * ww + r30] = 0;
+				scr[r31 * ww + r25 + r30] = 0;
+				if(++r26 == 960)
+				{
+					CLBlitter_UpdateScreen();
+					wait(1);
+					r26 = 0;
+				}
+			}
+		}
+	}
+	while(r27 != 1);
+	CLPalette_Send2Screen(global_palette, 0, 256);
+	r20 = 0x4400;
+	r27 = 1;
+	r26 = 0;
+	do
+	{
+		char r8 = r27 & 1;
+		r27 >>= 1;
+		if(r8)
+			r27 ^= r20;
+		if(r27 < 320 * 80)
+		{
+			r31 = r27 / 320;
+			r30 = r27 % 320;
+			r24 = pix[r31 * 640 + r30];
+			r23 = pix[r31 * 640 + r18 + r30];
+			if(doubled)
+			{
+		        r31 *= 2;
+				r30 *= 2;
+				scr[r31 * ww + r30] = r24;
+				scr[r31 * ww + r30 + 1] = r24;
+				scr[r31 * ww + r25 + r30] = r23;
+				scr[r31 * ww + r25 + r30 + 1] = r23;
+				r31++;
+				scr[r31 * ww + r30] = r24;
+				scr[r31 * ww + r30 + 1] = r24;
+				scr[r31 * ww + r25 + r30] = r23;
+				scr[r31 * ww + r25 + r30 + 1] = r23;
+				if(++r26 == 960)
+				{
+					wait(1);
+					r26 = 0;
+				}
+			}
+			else
+			{
+				scr[r31 * ww + r30] = r24;
+				scr[r31 * ww + r25 + r30] = r23;
+				if(++r26 == 960)
+				{
+					CLBlitter_UpdateScreen();
+					wait(1);
+					r26 = 0;
+				}
+			}
+		}
+	}
+	while(r27 != 1);
+	assert(ScreenView.pitch == 320);
+}
+////// datfile.c
+void verifh(void *ptr)
+{
+	unsigned char sum = 0;
+	unsigned char *data;
+	unsigned char *head = (unsigned char*)ptr;
+	unsigned short h0, h3;
+	short i;
+	char h2;
+	for(i = 0;i < 6;i++)
+		sum += *head++;
+	if(sum != 0xAB)
+		return;
+	debug("* Begin unpacking resource");
+	head -= 6;
+	h0 = PLE16(head); head += 2;
+	h2 = *head++;
+	h3 = PLE16(head); head += 2;
+	data = h0 + head + 26;
+	h3 -= 6;
+	head += h3;
+	for(;h3;h3--)
+		*data-- = *head--;
+	head = data + 1;
+	data = (unsigned char*)ptr;
+	Expand_hsq(head, data);
+}    
+void openbigfile()
+{
+	assert(sizeof(pakfile_t) == 25);
+	long size = 0x10000;
+	CLFile_MakeStruct(0, 0, "EDEN.DAT", &bigfilespec);
+	CLFile_Open(&bigfilespec, 1, h_bigfile);
+	CLFile_Read(h_bigfile, bigfile_header, &size);
+	p_hnmcontext = CLHNM_New(128);
+	CLHNM_SetFile(p_hnmcontext, &h_bigfile);
+}
+void closebigfile()
+{
+	CLFile_Close(h_bigfile);
+}
+void loadfile(unsigned short num, void *buffer)
+{
+	short retry, res = 1;
+	assert(num < bigfile_header->count);
+	for(retry = 0;res && retry < 5;retry++)
+	{
+		pakfile_t *file = &bigfile_header->files[num];
+		long size = PLE32(&file->size);
+		long offs = PLE32(&file->offs);
+		debug("* Loading resource %d (%s) at 0x%X, %d bytes", num, file->name, offs, size);
+		CLFile_SetPosition(h_bigfile, fsFromStart, offs);
+		CLFile_Read(h_bigfile, buffer, &size);
+		res = 0;
+	}
+	if(res)
+		quit_flag = 1;
+}
+void shnmfl(unsigned short num)
+{
+	int res;
+	assert(num + 484 < bigfile_header->count);
+	pakfile_t *file = &bigfile_header->files[num + 484];
+	int size = PLE32(&file->size);
+	int offs = PLE32(&file->offs);
+	debug("* Loading movie %d (%s) at 0x%X, %d bytes", num, file->name, offs, size);
+	CLHNM_SetPosIntoFile(p_hnmcontext, offs);
+}
+int ssndfl(unsigned short num)
+{
+	int res;
+	assert(num + 660 < bigfile_header->count);
+	pakfile_t *file = &bigfile_header->files[num + 660];
+	long size = PLE32(&file->size);
+	long offs = PLE32(&file->offs);
+	if(soundAllocated)
+	{
+		CLMemory_Free(voiceSamplesBuffer);
+		soundAllocated = 0;	//TODO: bug??? no alloc
+	}
+	else
+	{
+		voiceSamplesBuffer = CLMemory_Alloc(size);
+		soundAllocated = 1;
+	}
+	CLFile_SetPosition(h_bigfile, 1, offs);
+	CLFile_Read(h_bigfile, voiceSamplesBuffer, &size);
+	return size;
+
+}
+#if 1
+void ConvertIcons(icon_t *icon, int count)
+{
+	int i;
+	for (i = 0; i < count; i++, icon++)
+	{
+		icon->sx = BE16(icon->sx);
+		icon->sy = BE16(icon->sy);
+		icon->ex = BE16(icon->ex);
+		icon->ey = BE16(icon->ey);
+		icon->cursor_id = BE16(icon->cursor_id);
+		icon->object_id = BE32(icon->object_id);
+		icon->action_id = BE32(icon->action_id);
+	}
+}
+
+void ConvertLinks(room_t *room, int count)
+{
+	int i;
+	for (i = 0; i < count; i++, room++)
+	{
+		room->bank = BE16(room->bank);
+		room->party = BE16(room->party);
+	}
+}
+
+void ConvertMacToPC()
+{
+	// Conert all mac (big-endian) resources to native format
+	ConvertIcons(gameIcons, 136);
+	ConvertLinks(gameRooms, 424);
+	// Array of longs
+	int *p = (int*)gameLipsync;
+	for(int i = 0;i < 7240 / 4;i++)
+		p[i] = BE32(p[i]);
+}
+#endif
+
+void loadpermfiles()
+{
+	loadfile(2498, gameIcons);
+	loadfile(2497, gameRooms);
+	loadfile(2486, gameLipsync);
+	loadfile(0, main_bank_buf);
+	loadfile(402, gameFont);
+	loadfile(404, gameDialogs);
+	loadfile(403, gameConditions);
+#if 1
+	ConvertMacToPC();
+#endif
+}
+char ReadDataSync(unsigned short num)
+{
+	long pos, len;
+	pos = PLE32(gameLipsync + num * 4);
+	len = 1024;
+	if(pos != -1)
+	{
+		loadpartoffile(1936, gameLipsync + 7260, pos, len);
+		return 1;
+	}
+	return 0;
+}
+void loadpartoffile(unsigned short num, void *buffer, long pos, long len)
+{
+	short res;
+	assert(num < bigfile_header->count);
+	pakfile_t *file = &bigfile_header->files[num];
+	long offs = PLE32(&file->offs);
+	debug("* Loading partial resource %d (%s) at 0x%X(+0x%X), %d bytes", num, file->name, offs, pos, len);
+	CLFile_SetPosition(h_bigfile, 1, offs + pos);
+	CLFile_Read(h_bigfile, buffer, &len);
+}
+void Expand_hsq(void *input, void *output)
+{
+	unsigned char	*src = (unsigned char*)input;
+	unsigned char	*dst = (unsigned char*)output;
+	unsigned char	*ptr;
+	unsigned short	bit;		// bit
+	unsigned short	queue = 0;	// queue
+	unsigned short	len = 0;
+	short		ofs;
+#define GetBit							\
+	bit = queue & 1;					\
+	queue >>= 1;						\
+	if(!queue)							\
+	{									\
+		queue = (src[1] << 8) | src[0]; src += 2;	\
+		bit = queue & 1;							\
+		queue = (queue >> 1) | 0x8000;				\
+	}
+
+	for(;;)
+	{
+		GetBit;
+		if(bit)
+			*dst++ = *src++;
+		else
+		{
+			len = 0;
+			GetBit;
+			if(!bit)
+			{
+				GetBit;
+				len = (len << 1) | bit;
+				GetBit;
+				len = (len << 1) | bit;
+				ofs = 0xFF00 | *src++;		//TODO: -256
+			}
+			else
+			{
+				ofs = (src[1] << 8) | src[0]; src += 2;
+				len = ofs & 7;
+				ofs = (ofs >> 3) | 0xE000;
+				if(!len)
+				{
+					len = *src++;
+					if(!len)
+						break;
+				}
+			}
+			ptr = dst + ofs;
+			len += 2;
+			while(len--)
+				*dst++ = *ptr++;
+		}
+	}
+}
+//////
+void ajouinfo(unsigned char info)
+{
+	unsigned char idx = p_global->next_info_idx;
+	if(kPersons[PER_MESSAGER].roomNum)
+		info |= 0x80;
+	info_list[idx] = info;
+	if(idx == p_global->last_info_idx)
+		p_global->last_info = info;
+	idx++; if(idx == 16) idx = 0;
+	p_global->next_info_idx = idx;
+}
+void unlockinfo()
+{
+	unsigned char idx;
+	for(idx = 0;idx < 16;idx++)
+	{
+		if(info_list[idx] != 0xFF)
+			info_list[idx] &= ~0x80;
+	}
+	p_global->last_info &= ~0x80;
+}    
+void nextinfo()
+{
+	do
+	{
+		unsigned char idx = p_global->last_info_idx;
+		info_list[idx] = 0;
+		idx++; if(idx == 16) idx = 0;
+		p_global->last_info_idx = idx;
+		p_global->last_info = info_list[idx];
+	}
+	while(p_global->last_info == 0xFF);
+}
+void delinfo(unsigned char info)
+{
+	unsigned char idx;
+	for(idx = 0;idx < 16;idx++)
+	{
+		if((info_list[idx] & ~0x80) == info)
+		{
+			info_list[idx] = 0xFF;
+			if(idx == p_global->last_info_idx)
+				nextinfo();
+			break;
+		}
+	}
+}
+void updateinfolist()
+{
+	int idx;
+	for(idx = 0;idx < 16;idx++)
+		info_list[idx] = 0;
+}
+void init_globals()
+{
+	gameIcons[16].cursor_id |= 0x8000;
+
+	p_global->areaNum = Areas::arMo;
+	p_global->areaVisitCount = 1;
+	p_global->menuItemIdLo = 0;
+	p_global->menuItemIdHi = 0;
+	p_global->randomNumber = 0;
+	p_global->gameTime = 0;
+	p_global->gameDays = 0;
+	p_global->chrono = 0;
+	p_global->eloiDepartureDay = 0;
+	p_global->roomNum = 259;
+	p_global->newRoomNum = 0;
+	p_global->phaseNum = 0;
+	p_global->metPersonsMask1 = 0;
+	p_global->party = 0;
+	p_global->partyOutside = 0;
+	p_global->metPersonsMask2 = 0;
+	p_global->__UNUSED_1C = 0;
+	p_global->phaseActionsCount = 0;
+	p_global->curAreaFlags = 0;
+	p_global->curItemsMask = 0;
+	p_global->curPowersMask = 0;
+	p_global->curPersoItems = 0;
+	p_global->curPersoPowers = 0;
+	p_global->wonItemsMask = 0;
+	p_global->wonPowersMask = 0;
+	p_global->stepsToFindAppleFast = 0;
+	p_global->stepsToFindAppleNormal = 0;
+	p_global->roomPersoItems = 0;
+	p_global->roomPersoPowers = 0;
+	p_global->gameFlags = 0;
+	p_global->curVideoNum = 0;
+	p_global->morkusSpyVideoNum1 = 89;
+	p_global->morkusSpyVideoNum2 = 88;
+	p_global->morkusSpyVideoNum3 = 83;
+	p_global->morkusSpyVideoNum4 = 94;
+	p_global->newMusicType = MusicType::mtDontChange;
+	p_global->ff_43 = 0;
+	p_global->videoSubtitleIndex = 0;
+	p_global->partyInstruments = 0;
+	p_global->monkGotRing = 0;
+	p_global->chrono_on = 0;
+	p_global->curRoomFlags = 0;
+	p_global->endGameFlag = 0;
+	p_global->last_info = 0;
+	p_global->autoDialog = 0;
+	p_global->worldTyrannSighted = 0;
+	p_global->ff_4D = 0;
+	p_global->ff_4E = 0;
+	p_global->worldGaveGold = 0;
+	p_global->worldHasTriceraptors = 0;
+	p_global->worldHasVelociraptors = 0;
+	p_global->worldHasTyrann = 0;
+	p_global->ff_53 = 0;
+	p_global->ff_54 = 0;
+	p_global->ff_55 = 0;
+	p_global->ff_56 = 0;
+	p_global->textToken1 = 0;
+	p_global->textToken2 = 0;
+	p_global->eloiHaveNews = 0;
+	p_global->dialogFlags = 0;
+	p_global->curAreaType = 0;
+	p_global->curCitadelLevel = 0;
+	p_global->newLocation = 0;
+	p_global->prevLocation = 0;
+	p_global->curPersoFlags = 0;
+	p_global->ff_60 = 0;
+	p_global->eventType = EventType::etEvent5;
+	p_global->ff_62 = 0;
+	p_global->curObjectId = 0;
+	p_global->curObjectFlags = 0;
+	p_global->ff_65 = 1;
+	p_global->roomPersoType = 0;
+	p_global->roomPersoFlags = 0;
+	p_global->narratorSequence = 0;
+	p_global->ff_69 = 0;
+	p_global->ff_6A = 0;
+	p_global->fresqNumber = 0;
+	p_global->ff_6C = 0;
+	p_global->ff_6D = 0;
+	p_global->labyrinthDirections = 0;
+	p_global->labyrinthRoom = 0;
+	p_global->curPersoAnimPtr = 0;
+	p_global->perso_img_bank = 0;
+	p_global->roomImgBank = 0;
+	p_global->persoBackgroundBankIdx = 55;
+	p_global->ff_D4 = 0;
+	p_global->fresqWidth = 0;
+	p_global->fresqImgBank = 0;
+	p_global->ff_DA = 0;
+	p_global->ff_DC = 0;
+	p_global->room_x_base = 0;
+	p_global->ff_E0 = 0;
+	p_global->dialogType = 0;
+	p_global->ff_E4 = 0;
+	p_global->currentMusicNum = 0;
+	p_global->textNum = 0;
+	p_global->travelTime = 0;
+	p_global->ff_EC = 0;
+	p_global->displayFlags = DisplayFlags::dfFlag1;
+	p_global->oldDisplayFlags = 1;
+	p_global->drawFlags = 0;
+	p_global->ff_F1 = 0;
+	p_global->ff_F2 = 0;
+	p_global->menuFlags = 0;
+	p_global->ff_F5 = 0;
+	p_global->ff_F6 = 0;
+	p_global->ff_F7 = 0;
+	p_global->ff_F8 = 0;
+	p_global->ff_F9 = 0;
+	p_global->ff_FA = 0;
+	p_global->animationFlags = 0;
+	p_global->__UNUSED_FC = 0;
+	p_global->giveobj1 = 0;
+	p_global->giveobj2 = 0;
+	p_global->giveobj3 = 0;
+	p_global->ff_100 = 0;
+	p_global->roomVidNum = 0;
+	p_global->ff_102 = 0;
+	p_global->ff_103 = 0;
+	p_global->roomBgBankNum = 0;
+	p_global->valleyVidNum = 0;
+	p_global->updatePaletteFlag = 0;
+	p_global->inventoryScrollPos = 0;
+	p_global->obj_count = 0;
+	p_global->ff_109 = 0;
+	p_global->textBankIndex = 69;
+	p_global->cita_area_num = 0;
+	p_global->ff_113 = 0;
+	p_global->lastSalNum = 0;
+	p_global->__UNUSED_70 = 0;
+	p_global->dialog_ptr = 0;
+	p_global->tape_ptr = tapes;
+	p_global->next_dialog_ptr = 0;
+	p_global->narrator_dialog_ptr = 0;
+	p_global->last_dialog_ptr = 0;
+	p_global->nextRoomIcon = 0;
+	p_global->phraseBufferPtr = 0;
+	p_global->__UNUSED_90 = 0;
+	p_global->__UNUSED_94 = 0;
+	p_global->room_ptr = 0;
+	p_global->area_ptr = 0;
+	p_global->last_area_ptr = 0;
+	p_global->cur_area_ptr = 0;
+	p_global->cita_area_firstRoom = 0;
+	p_global->perso_ptr = 0;
+	p_global->room_perso = 0;
+	p_global->last_info_idx = 0;
+	p_global->next_info_idx = 0;
+	p_global->iconsIndex = 16;
+	p_global->persoSpritePtr = 0;
+	p_global->numGiveObjs = 0;
+
+	rect_31C7A.sy = 0;			//TODO: unused?
+	rect_31C7A.sx = 0;
+	rect_31C7A.ex = 320 - 1;
+	rect_31C7A.ey = 200 - 1;
+
+	initrect();
+
+	underSubtitlesScreenRect.sy = 0;
+	underSubtitlesScreenRect.sx = subtitles_x_scr_margin;
+	underSubtitlesScreenRect.ex = subtitles_x_scr_margin + subtitles_x_width - 1;
+	underSubtitlesScreenRect.ey = 176 - 1;
+
+	underSubtitlesBackupRect.sy = 0;
+	underSubtitlesBackupRect.sx = subtitles_x_scr_margin;
+	underSubtitlesBackupRect.ex = subtitles_x_scr_margin + subtitles_x_width - 1;
+	underSubtitlesBackupRect.ey = 60 - 1;
+}
+void initrect()
+{
+	underTopBarScreenRect.sy = 0;
+	underTopBarScreenRect.sx = 0;
+	underTopBarScreenRect.ex = 320 - 1;
+	underTopBarScreenRect.ey = 16 - 1;
+
+	underTopBarBackupRect.sy = 0;
+	underTopBarBackupRect.sx = 0;
+	underTopBarBackupRect.ex = 320 - 1;
+	underTopBarBackupRect.ey = 16 - 1;
+
+	underBottomBarScreenRect.sy = 176;
+	underBottomBarScreenRect.sx = 0;
+	underBottomBarScreenRect.ex = 320 - 1;
+	underBottomBarScreenRect.ey = 200 - 1;	//TODO: original bug? this cause crash in copyrect (this, underBottomBarBackupRect)
+
+	underBottomBarBackupRect.sy = 16;
+	underBottomBarBackupRect.sx = 0;
+	underBottomBarBackupRect.ex = 320 - 1;
+	underBottomBarBackupRect.ey = 40 - 1;
+}    
+void closesalle()
+{
+	if(p_global->displayFlags & DisplayFlags::dfPanable)
+	{
+		p_global->displayFlags &= ~DisplayFlags::dfPanable;
+		resetscroll();
+	}
+}
+void afsalle1(room_t *room)
+{
+	unsigned char *ptr = (unsigned char*)GetElem(sal_buf, room->ff_0 - 1);
+	ptr++;
+	for(;;)
+	{
+		unsigned char b0, b1;
+		short index, x, y, ex, ey;
+		b0 = *ptr++;
+		b1 = *ptr++;
+		index = (b1 << 8) | b0;
+		if(index == -1)
+			break;
+		if(index > 0)
+		{
+			x = *ptr++ | (((b1 & 0x2) >> 1) << 8);		//TODO: check me
+			y = *ptr++;
+			ptr++;
+			index &= 0x1FF;
+			if(!(p_global->displayFlags & 0x80))
+			{
+				if(index == 1 || p_global->ff_F7)
+					noclipax_avecnoir(index - 1, x, y);
+			}
+			p_global->ff_F7 = 0;
+			continue;
+		}
+		if(b1 & 0x40)
+		{
+			if(b1 & 0x20)
+			{
+				char addIcon = 0;
+				icon_t *icon = p_global->nextRoomIcon;
+				if(b0 < 4)
+				{
+					if(p_global->room_ptr->exits[b0])
+						addIcon = 1;
+				}
+				else if(b0 > 229)
+				{
+					if(p_global->partyOutside & (1 << (b0 - 230)))
+						addIcon = 1;
+				}
+				else if(b0 >= 100)
+				{
+debug("add object %d", b0 - 100);
+					if(objecthere(b0 - 100))
+					{
+						addIcon = 1;
+						p_global->ff_F7 = -1;
+					}
+				}
+				else
+					addIcon = 1;
+				if(addIcon)
+				{
+					icon->action_id = b0;
+					icon->object_id = b0;
+					icon->cursor_id = kActionCursors[b0];
+					x = PLE16(ptr); ptr += 2;
+					y = PLE16(ptr); ptr += 2;
+					ex = PLE16(ptr); ptr += 2;
+					ey = PLE16(ptr); ptr += 2;
+					x += p_global->room_x_base;
+					ex += p_global->room_x_base;
+					debug("add hotspot at %3d:%3d - %3d:%3d, action = %d", x, y, ex, ey, b0);
+#ifdef EDEN_DEBUG
+					for (int iii = x; iii < ex; iii++) p_mainview_buf[y * 640 + iii] = p_mainview_buf[ey * 640 + iii] = (iii % 2) ? 0 : 255;
+					for (int iii = y; iii < ey; iii++) p_mainview_buf[iii * 640 + x] = p_mainview_buf[iii * 640 + ex] = (iii % 2) ? 0 : 255;
+#endif
+					icon->sx = x;
+					icon->sy = y;
+					icon->ex = ex;
+					icon->ey = ey;
+					p_global->nextRoomIcon = ++icon;
+					icon->sx = -1;
+				}
+				else
+					ptr += 8;
+			}
+			else
+				ptr += 8;
+		}
+		else
+			ptr += 8;
+	}
+}
+void afsalle()
+{
+	room_t *room = p_global->room_ptr;
+	p_global->displayFlags = DisplayFlags::dfFlag1;
+	p_global->room_x_base = 0;
+	p_global->roomBgBankNum = room->background;
+	if(room->flags & RoomFlags::rf08)
+	{
+		p_global->displayFlags |= DisplayFlags::dfFlag80;
+		if(room->flags & RoomFlags::rfPanable)
+		{
+			p_global->displayFlags |= DisplayFlags::dfPanable;
+			p_global->ff_F4 = 0;
+			rundcurs();
+			sauvefrises();
+			use_bank(room->bank - 1);
+			noclipax_avecnoir(0, 0, 16);
+			use_bank(room->bank);
+			noclipax_avecnoir(0, 320, 16);
+			afsalle1(room);
+			p_global->room_x_base = 320;
+			afsalle1(room + 1);
+		}
+		else
+			afsalle1(room);
+	}
+	else
+	{
+		//TODO: roomImgBank is garbage here!
+		debug("drawroom: room 0x%X using bank %d", p_global->roomNum, p_global->roomImgBank);
+		use_bank(p_global->roomImgBank);
+		afsalle1(room);
+		assert(ScreenView.pitch == 320);
+	}
+}
+void aflieu()
+{
+	no_perso();
+	if(!pomme_q)
+	{
+		p_global->iconsIndex = 16;
+		p_global->autoDialog = 0;
+	}
+	p_global->nextRoomIcon = &gameIcons[28];
+	afsalle();
+	needPaletteUpdate = 1;
+}
+void loadsal(short num)
+{
+	if(num == p_global->lastSalNum)
+		return;
+	p_global->lastSalNum = num;
+	loadfile(num + 419, sal_buf);
+}
+void specialoutside()
+{
+	if(p_global->last_area_ptr->type == AreaType::atValley && (p_global->party & PersonMask::pmLeader))
+		perso_ici(5);
+}
+void specialout()
+{
+	if(p_global->gameDays - p_global->eloiDepartureDay > 2)
+	{
+		if(eloirevientq() == 1)
+			eloirevient();
+	}
+	if(p_global->phaseNum >= 32 && p_global->phaseNum < 48)
+		if(p_global->newLocation == 9 || p_global->newLocation == 4 || p_global->newLocation == 24)
+		{
+			kPersons[PER_MESSAGER].roomNum = 263;
+			return;
+		}
+	if(p_global->phaseNum == 434)
+		if(p_global->newLocation == 5)
+		{
+			reste_ici(4);
+			kPersons[PER_BOURREAU].roomNum = 264;
+			return;
+		}
+	if(p_global->phaseNum < 400)
+		if((p_global->gameFlags & GameFlags::gfFlag4000) && p_global->prevLocation == 1
+			&& (p_global->party & PersonMask::pmEloi) && p_global->curAreaType == AreaType::atValley)
+			eloipart();
+	if(p_global->phaseNum == 386)
+		if(p_global->prevLocation == 1
+			&& (p_global->party & PersonMask::pmEloi) && p_global->areaNum == Areas::arCantura)
+			eloipart();
+}
+void specialin()
+{
+	if(!(p_global->party & PersonMask::pmEloi) && (p_global->partyOutside & PersonMask::pmEloi) && (p_global->roomNum & 0xFF) == 1)
+	{
+		suis_moi(5);
+		p_global->eloiHaveNews = 1;
+	}
+	if (p_global->roomNum == 288)
+		p_global->gameFlags |= GameFlags::gfFlag100 | GameFlags::gfFlag2000;
+	if(p_global->roomNum == 3075 && p_global->phaseNum == 546)
+	{
+		incphase1();
+		if(p_global->curItemsMask & 0x2000)	// Morkus' tablet
+		{
+			bars_out();
+			playhnm(92);
+			gameRooms[129].exits[0] = 0;
+			gameRooms[129].exits[2] = 1;
+			p_global->roomNum = 3074;
+			kPersons[PER_MANGO].roomNum = 3074;
+			p_global->eventType = EventType::etEvent5;
+			maj_salle(p_global->roomNum);
+			return;
+		}
+		p_global->narratorSequence = 53;
+	}
+	if(p_global->roomNum == 1793 && p_global->phaseNum == 336)
+		eloipart();
+	if(p_global->roomNum == 259 && p_global->phaseNum == 129)
+		p_global->narratorSequence = 12;
+	if(p_global->roomNum >= 289 && p_global->roomNum < 359)
+		p_global->labyrinthDirections = kLabyrinthPath[(p_global->roomNum & 0xFF) - 33];
+	if(p_global->roomNum == 305 && p_global->prevLocation == 103)
+		p_global->gameFlags &= ~GameFlags::gfFlag2000;
+	if(p_global->roomNum == 304 && p_global->prevLocation == 105)
+		p_global->gameFlags &= ~GameFlags::gfFlag2000;
+	if(p_global->phaseNum < 226)
+	{
+		if(p_global->roomNum == 842)
+			p_global->gameFlags |= GameFlags::gfFlag2;
+		if(p_global->roomNum == 1072)
+			p_global->gameFlags |= GameFlags::gfFlag4;
+		if(p_global->roomNum == 1329)
+			p_global->gameFlags |= GameFlags::gfFlag8000;
+	}
+}
+void animpiece()
+{
+	room_t *room = p_global->room_ptr;
+	if(p_global->roomVidNum && p_global->ff_100 != 0xFF)
+	{
+		if(p_global->valleyVidNum || !room->level || (room->flags & RoomFlags::rfHasCitadel)
+		|| room->level == p_global->ff_100)
+		{
+			bars_out();
+			p_global->updatePaletteFlag = 16;
+			if(!p_global->narratorSequence & 0x80)	//TODO: bug? !() @ 100DC
+				p_global->ff_102 = 0;
+			if(!needToFade)
+				needToFade = room->flags & RoomFlags::rf02;
+			playhnm(p_global->roomVidNum);
+			return;
+		}
+	}
+	p_global->ff_F1 &= ~RoomFlags::rf04;
+}
+void getdino(room_t *room)
+{
+	assert(tab_2CEF0[4] == 0x25);
+	perso_t *perso = &kPersons[PER_UNKN_18C];
+	short *tab;
+	unsigned char persoType, r27;
+	short bank;
+	room->flags &= ~0xC;
+	for(;perso->roomNum != 0xFFFF;perso++)
+	{
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if(perso->roomNum != p_global->roomNum)
+			continue;
+		persoType = perso->flags & PersonFlags::pfTypeMask;
+		if (persoType == PersonFlags::pftVelociraptor)
+			delinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsIn);
+		if (persoType == PersonFlags::pftTriceraptor)
+			delinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+		perso->flags |= PersonFlags::pf20;
+		tab = tab_2CF70;
+		if(p_global->areaNum != Areas::arUluru && p_global->areaNum != Areas::arTamara)
+			tab = tab_2CEF0;
+		r27 = (room->flags & 0xC0) >> 2;	//TODO: check me (like pc)
+		persoType = perso->flags & PersonFlags::pfTypeMask;
+		if (persoType == PersonFlags::pftTyrann)
+			persoType = 13;
+		r27 |= (persoType & 7) << 1;	//TODO: check me 13 & 7 = ???
+		tab += r27;
+		p_global->roomVidNum = *tab++;
+		bank = *tab;
+		if(bank & 0x8000)
+		{
+			bank &= ~0x8000;
+			room->flags |= RoomFlags::rf08;
+		}
+		room->flags |= RoomFlags::rf04 | RoomFlags::rf02;
+		p_global->roomImgBank = bank;
+		break;
+	}
+}
+room_t* getsalle(short loc)	//TODO: unsigned char?
+{
+	debug("get room for %X, starting from %d, looking for %X", loc, p_global->area_ptr->firstRoomIndex, p_global->partyOutside);
+	room_t *room = &gameRooms[p_global->area_ptr->firstRoomIndex];
+	loc &= 0xFF;
+	for(;;room++)
+	{
+		for(;room->location != loc;room++)
+		{
+			if(room->ff_0 == 0xFF)
+				return 0;
+		}
+		if(p_global->partyOutside == room->party || room->party == 0xFFFF)
+			break;
+	}
+	debug("found room: party = %X, bank = %X", room->party, room->bank);
+	p_global->roomImgBank = room->bank;
+	p_global->labyrinthRoom = 0;
+	if(p_global->roomImgBank > 104 && p_global->roomImgBank <= 112)
+		p_global->labyrinthRoom = p_global->roomImgBank - 103;
+	if(p_global->valleyVidNum)
+		p_global->roomVidNum = p_global->valleyVidNum;
+	else
+		p_global->roomVidNum = room->video;
+	if((room->flags & 0xC0) == RoomFlags::rf40 || (room->flags & RoomFlags::rf01))
+		getdino(room);
+	if(room->flags & RoomFlags::rfHasCitadel)
+	{
+		delinfo(p_global->areaNum + ValleyNews::vnCitadelLost);
+		delinfo(p_global->areaNum + ValleyNews::vnTyrannIn);
+		delinfo(p_global->areaNum + ValleyNews::vnTyrannLost);
+		delinfo(p_global->areaNum + ValleyNews::vnVelociraptorsLost);
+	}
+	if(istyran(p_global->roomNum))
+		p_global->gameFlags |= GameFlags::gfFlag10;
+	else
+		p_global->gameFlags &= ~GameFlags::gfFlag10;
+	return room;
+}
+void initlieu(short roomNum)
+{
+	area_t *area;
+	p_global->gameFlags |= GameFlags::gfFlag4000;
+	gameIcons[18].cursor_id |= 0x8000;
+	p_global->last_area_ptr = p_global->area_ptr;
+	p_global->area_ptr = &kAreasTable[((roomNum >> 8) & 0xFF) - 1];
+	area = p_global->area_ptr;
+	area->visitCount++;
+	p_global->areaVisitCount = area->visitCount;
+	p_global->curAreaFlags = area->flags;
+	p_global->curAreaType = area->type;
+	p_global->curCitadelLevel = area->citadelLevel;
+	if(p_global->curAreaType == AreaType::atValley)
+		gameIcons[18].cursor_id &= ~0x8000;
+	loadsal(area->salNum);
+}
+void maj2()
+{
+	char r9, r30;
+	room_t *room = p_global->room_ptr;	//TODO: unused
+	aflieu();
+	assert(ScreenView.pitch == 320);
+	if(p_global->roomNum == 273 && p_global->prevLocation == 18)
+		p_global->ff_102 = 1;
+	if(p_global->eventType == EventType::etEventC)
+	{
+		afftopscr();
+		showobjects();
+	}
+	FRDevents();
+	assert(ScreenView.pitch == 320);
+	r9 = 0;
+	if (p_global->curAreaType == AreaType::atValley && !(p_global->displayFlags & DisplayFlags::dfPanable))
+		r9 = 1;
+	r30 = r9;	//TODO: ^^ inlined func?
+	if(p_global->ff_102 || p_global->ff_103)
+		afficher();
+	else if (p_global->ff_F1 == (RoomFlags::rf40 | RoomFlags::rf04 | RoomFlags::rf01))
+	{
+		blackbars();
+		effet1();
+	}
+	else if(p_global->ff_F1 && !(p_global->ff_F1 & RoomFlags::rf04) && !r30)
+	{
+		if (!(p_global->displayFlags & DisplayFlags::dfPanable))
+			blackbars();
+		else if(p_global->valleyVidNum)
+			blackbars();
+		effet1();
+	}
+	else if(r30 && !(p_global->ff_F1 & RoomFlags::rf04))
+		effetpix();
+	else
+		afficher128();
+	musique();
+	if(p_global->eventType != EventType::etEventC)
+	{
+		afftopscr();
+		showobjects();
+	}
+	bars_in();
+	showevents();
+	p_global->labyrinthDirections = 0;
+	specialin();
+}
+void majsalle1(short roomNum)
+{
+	room_t *room = getsalle(roomNum & 0xFF);
+	p_global->room_ptr = room;
+	debug("DrawRoom: room 0x%X, arg = 0x%X", p_global->roomNum, roomNum);
+	p_global->curRoomFlags = room->flags;
+	p_global->ff_F1 = room->flags;
+	animpiece();
+	p_global->ff_100 = 0;
+	maj2();
+}
+void maj_salle(unsigned short roomNum)
+{
+	setpersohere();
+	majsalle1(roomNum);
+}
+void initbuf()
+{
+#define ALLOC(ptr, size, typ) if(!((ptr) = (typ*)malloc(size))) quit_flag = 1;
+	ALLOC(bigfile_header, 0x10000, pak_t);
+	ALLOC(gameRooms, 0x4000, room_t);
+	ALLOC(gameIcons, 0x4000, icon_t);
+	ALLOC(bank_data_buf, 0x10000, unsigned char);
+	ALLOC(p_global, sizeof(*p_global), global_t);
+	ALLOC(sal_buf, 2048, void);
+	ALLOC(gameConditions, 0x4800, unsigned char);
+	ALLOC(gameDialogs, 0x2800, unsigned char);
+	ALLOC(gamePhrases, 0x10000, unsigned char);
+	ALLOC(main_bank_buf, 0x9400, unsigned char);
+	ALLOC(glow_buffer, 0x2800, unsigned char);
+	ALLOC(gameFont, 0x900, unsigned char);
+	ALLOC(gameLipsync, 0x205C, unsigned char);
+	ALLOC(music_buf, 0x140000, unsigned char);
+#undef ALLOC
+}
+void freebuf()
+{
+	free(bigfile_header);
+	free(gameRooms);
+	free(gameIcons);
+	free(bank_data_buf);
+	free(p_global);
+	free(sal_buf);
+	free(gameConditions);
+	free(gameDialogs);
+	free(gamePhrases);
+	free(main_bank_buf);
+	free(glow_buffer);
+	free(gameFont);
+	free(gameLipsync);
+	free(music_buf);
+}
+void openwindow()
+{
+	p_underBarsView = CLView_New(320, 40);
+	p_underBarsView->norm.width = 320;
+
+	p_view2 = CLView_New(32, 32);
+	p_view2_buf = p_view2->p_buffer;
+
+	p_subtitlesview = CLView_New(subtitles_x_width, 60);
+	p_subtitlesview_buf = p_subtitlesview->p_buffer;
+
+	p_underSubtitlesView = CLView_New(subtitles_x_width, 60);
+	p_underSubtitlesView_buf = p_underSubtitlesView->p_buffer;
+
+	p_mainview = CLView_New(640, 200);
+	p_mainview->norm.width = 320;
+	CLBlitter_FillView(p_mainview, 0xFFFFFFFF);
+	CLView_SetSrcZoomValues(p_mainview, 0, 0);
+	CLView_SetDisplayZoomValues(p_mainview, 640, 400);
+	CLScreenView_CenterIn(p_mainview);
+	p_mainview_buf = p_mainview->p_buffer;
+
+	mouse_x_center = p_mainview->norm.dst_left + p_mainview->norm.width / 2;
+	mouse_y_center = p_mainview->norm.dst_top + p_mainview->norm.height / 2;
+	CLMouse_SetPosition(mouse_x_center, mouse_y_center);
+	CLMouse_Hide();
+
+	curs_x = 320 / 2;
+	curs_y = 200 / 2;
+}
+void EmergencyExit()
+{
+	SysBeep(1);
+}
+public:
+void main()
+{
+	debug("global size is %X", (size_t)(&((global_t*)0)->save_end));
+	if ((size_t)(&((global_t*)0)->__UNUSED_70) != 0x70)	// let's be more optimistic
+	{
+		// great, you broke the dialog system. expect all nasty stuff now
+		assert(0);
+	}
+
+
+
+	CRYOLib_Init();
+	CRYOLib_InstallExitPatch();
+	CRYOLib_SetDebugMode(0);
+	word_378CE = 0;
+	CRYOLib_MinimalInit();
+	CRYOLib_TestConfig();
+	CRYOLib_ManagersInit();	
+	CLFile_SetFilter(1, 'EDNS', 0, 0, 0);
+//	CRYOLib_InstallEmergencyExit(EmergencyExit);
+	CRYOLib_SetupEnvironment();
+	CLHNM_SetupSound(5, 0x2000, 8, 11025 * 65536.0 , 0);
+	CLHNM_SetForceZero2Black(1);
+	CLHNM_SetupTimer(12.5);
+	voiceSound = CLSoundRaw_New(0, 11025 * 65536.0, 8, 0);
+	hnmsound_ch = CLHNM_GetSoundChannel();
+	music_channel = CLSoundChannel_New(0);
+	CLSound_SetWantsDesigned(1);
+
+	initbuf();
+	openbigfile();
+	openwindow();
+	loadpermfiles();
+
+	if(!quit_flag)
+	{
+		LostEdenMac_InitPrefs();
+		init_cube();
+		p_mainview->doubled = doubled;


Commit: 59c90d21ad8f1f1e741cfb4bed3e9e099b37766a
    https://github.com/scummvm/scummvm/commit/59c90d21ad8f1f1e741cfb4bed3e9e099b37766a
Author: Retro-Junk (bambarbee at yandex.ru)
Date: 2017-01-25T22:41:53+01:00

Commit Message:
CRYO: Prettify code with AStyle

Changed paths:
    engines/cryo/CLHNM.c
    engines/cryo/CLSouNdRaw.c
    engines/cryo/CryoLib.h
    engines/cryo/CryoLibStub.c
    engines/cryo/LempelZiv.h
    engines/cryo/ResourceManager.cpp
    engines/cryo/ResourceManager.h
    engines/cryo/clsoundgroup.c
    engines/cryo/cryo.cpp
    engines/cryo/cryo.h
    engines/cryo/defs.h
    engines/cryo/detection.cpp
    engines/cryo/eden.cpp
    engines/cryo/platdefs.h


diff --git a/engines/cryo/CLHNM.c b/engines/cryo/CLHNM.c
index 3ab3f65..9b30c50 100644
--- a/engines/cryo/CLHNM.c
+++ b/engines/cryo/CLHNM.c
@@ -23,8 +23,7 @@ static short decomp_table[256];
 
 void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
 
-void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output)
-{
+void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output) {
 	unsigned char *inp = buffer;
 	unsigned char *out = output;
 
@@ -34,34 +33,28 @@ void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output)
 	//TODO: fix for BE
 #define GetBit() ( 1 & ( (qpos >= 0) ? (queue >> qpos--) : (queue = *(unsigned int*)((inp += 4) - 4)) >> ((qpos = 30) + 1) ) )
 
-	for (;;)
-	{
-		if (GetBit())
-		{
+	for (;;) {
+		if (GetBit()) {
 			*out++ = *inp++;
-		}
-		else
-		{
+		} else {
 			int l, o;
-			if (GetBit())
-			{
+			if (GetBit()) {
 				l = *inp & 7;
-				o = *(unsigned short*)inp >> 3; inp += 2;
+				o = *(unsigned short *)inp >> 3;
+				inp += 2;
 				o -= 8192;
 				if (!l)
 					l = *inp++;
 				if (!l)
 					break;
-			}
-			else
-			{
+			} else {
 				l = GetBit() * 2 + GetBit();
 				o = *(inp++) - 256;
 			}
 			l += 2;
-			while (l--)
-			{
-				*out = *(out + o); out++;
+			while (l--) {
+				*out = *(out + o);
+				out++;
 			}
 		}
 	}
@@ -72,8 +65,7 @@ void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output)
 }
 
 void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
-					 unsigned char *input, int width, char flags)
-{
+                     unsigned char *input, int width, char flags) {
 	unsigned int code;
 	char mode, count, color;
 	unsigned short offs;
@@ -82,36 +74,29 @@ void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned
 	unsigned char swap;
 	int shft1, shft2;
 //	return;
-	if((flags & 1) == 0)
-	{
+	if ((flags & 1) == 0) {
 		//HNM4 classic
 		int twolinesabove = -(width * 2);
-		for(;;)
-		{
+		for (;;) {
 			code = PLE32(input) & 0xFFFFFF; //input++;
 			count = code & 0x1F;
-			if(count)
-			{
+			if (count) {
 				input += 3;
 				mode = (code >> 5) & 0xF;
 				offs = code >> 9;
 				//
 				swap = mode >> 3;
 				ref = ((mode & 1) ? prev_buffer : curr_buffer) + (output - out_start) + (offs * 2) - 32768;
-				if (mode & 2)
-				{
-					//					ref += twolinesabove;
+				if (mode & 2) {
+					//                  ref += twolinesabove;
 					shft1 = twolinesabove + 1;
 					shft2 = 0;
 					//swap ^= 1;
-				}
-				else
-				{
+				} else {
 					shft1 = 0;
 					shft2 = 1;
 				}
-				while(count--)
-				{
+				while (count--) {
 					unsigned char b0 = ref[shft1];
 					unsigned char b1 = ref[shft2];
 					output[swap] = b0;
@@ -119,13 +104,10 @@ void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned
 					output += 2;
 					ref += (mode & 4) ? -2 : 2;
 				}
-			}
-			else
-			{
+			} else {
 				input++;
-				mode = code & 0xFF;	// bits 0..4 are zero
-				switch(mode)
-				{
+				mode = code & 0xFF; // bits 0..4 are zero
+				switch (mode) {
 				case 0:
 					*(output++) = *(input++);
 					*(output++) = *(input++);
@@ -134,13 +116,13 @@ void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned
 					output += 2 * *(input++);
 					break;
 				case 0x40:
-					output += 2 * (code >> 8); input += 2;
+					output += 2 * (code >> 8);
+					input += 2;
 					break;
 				case 0x60:
 					count = *(input++);
 					color = *(input++);
-					while(count--)
-					{
+					while (count--) {
 						*(output++) = color;
 						*(output++) = color;
 					}
@@ -150,26 +132,20 @@ void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned
 				}
 			}
 		}
-	}
-	else
-	{
+	} else {
 		assert(0);
 		//HNM4 hires
-		for(;;)
-		{
-			code = PLE32(input) & 0xFFFFFF; input++;
+		for (;;) {
+			code = PLE32(input) & 0xFFFFFF;
+			input++;
 			count = code & 0x3F;
-			if(count)
-			{
+			if (count) {
 				mode = (code >> 5) & 0xF;
 				offs = code >> 9;
-				// 
-			}
-			else
-			{
-				mode = code & 0xFF;	// bits 0..5 are zero
-				switch(mode)
-				{
+				//
+			} else {
+				mode = code & 0xFF; // bits 0..5 are zero
+				switch (mode) {
 				case 0x00:
 					output += *input++;
 					break;
@@ -188,99 +164,83 @@ void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned
 	}
 }
 
-void CLHNM_Init()
-{
+void CLHNM_Init() {
 	use_preload = 0;
 	custom_chunk_handler = 0;
 	preserve_color0 = 0;
 	CLNoError;
 }
 
-void CLHNM_Done()
-{
+void CLHNM_Done() {
 	CLNoError;
 }
 
-void CLHNM_SetupTimer(float rate)
-{
+void CLHNM_SetupTimer(float rate) {
 	hnm_rate = 100.0 / rate;
 	CLNoError;
 }
 
-void CLHNM_WaitLoop(hnm_t *hnm)
-{
+void CLHNM_WaitLoop(hnm_t *hnm) {
 	expected_frame_time += hnm_rate;
 	next_frame_time = expected_frame_time - time_drift;
-	if(use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
+	if (use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
 		use_sound = 0;
-	while(TimerTicks < next_frame_time) ;	// waste time
+	while (TimerTicks < next_frame_time) ;  // waste time
 	time_drift = TimerTicks - next_frame_time;
 }
 
-void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode)
-{
+void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode) {
 	soundChannel = CLSoundChannel_New(mode);
 	soundGroup = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
-	if(sampleSize == 16)
+	if (sampleSize == 16)
 		CLSoundGroup_Reverse16All(soundGroup);
 }
 
-void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode)
-{
+void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode) {
 	soundChannel_adpcm = CLSoundChannel_New(mode);
 	soundGroup_adpcm = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
 }
 
-void CLHNM_CloseSound()
-{
-	if(soundChannel)
-	{
+void CLHNM_CloseSound() {
+	if (soundChannel) {
 		CLSoundChannel_Stop(soundChannel);
 		CLSoundChannel_Free(soundChannel);
 		soundChannel = 0;
 	}
-	if(soundGroup)
-	{
+	if (soundGroup) {
 		CLSoundGroup_Free(soundGroup);
 		soundGroup = 0;
 	}
-	if(soundChannel_adpcm)
-	{
+	if (soundChannel_adpcm) {
 		CLSoundChannel_Stop(soundChannel_adpcm);
 		CLSoundChannel_Free(soundChannel_adpcm);
 		soundChannel = 0;
 	}
-	if(soundGroup_adpcm)
-	{
+	if (soundGroup_adpcm) {
 		CLSoundGroup_Free(soundGroup_adpcm);
 		soundGroup = 0;
 	}
 }
 
-void CLHNM_SetForceZero2Black(short forceblack)
-{
+void CLHNM_SetForceZero2Black(short forceblack) {
 	preserve_color0 = forceblack;
 }
 
-hnm_t* CLHNM_New(int preload_size)
-{
+hnm_t *CLHNM_New(int preload_size) {
 	hnm_t *hnm;
 	short i;
 
-	preload_size = 0;	//TODO: let's ignore it for now
+	preload_size = 0;   //TODO: let's ignore it for now
 
 	CLBeginCheck;
-	hnm = (hnm_t*)CLMemory_Alloc(sizeof(*hnm));
+	hnm = (hnm_t *)CLMemory_Alloc(sizeof(*hnm));
 	CLCheckError();
-	if(hnm)
-	{
-		if(preload_size)
-		{
+	if (hnm) {
+		if (preload_size) {
 			use_preload = 1;
-			
+
 		}
-		if(!__libError)
-		{
+		if (!__libError) {
 			hnm->frame = 0;
 			hnm->ff_4 = 0;
 			hnm->file = 0;
@@ -290,76 +250,66 @@ hnm_t* CLHNM_New(int preload_size)
 			hnm->read_buffer = 0;
 			hnm->ff_896 = 0;
 			hnm->total_read = 0;
-			for(i = 0;i < 256;i++)
-			{
-				hnm->palette[i].a = 0;	
-				hnm->palette[i].r = 0;	
-				hnm->palette[i].g = 0;	
-				hnm->palette[i].b = 0;	
+			for (i = 0; i < 256; i++) {
+				hnm->palette[i].a = 0;
+				hnm->palette[i].r = 0;
+				hnm->palette[i].g = 0;
+				hnm->palette[i].b = 0;
 			}
-		}
-		else
+		} else
 			CLCheckError();
 	}
 	CLEndCheck;
 	return hnm;
 }
 
-void CLHNM_Dispose(hnm_t *hnm)
-{
+void CLHNM_Dispose(hnm_t *hnm) {
 	CLBeginCheck;
-	
-	if(use_preload)
-	{
+
+	if (use_preload) {
 
 	}
 
 	CLMemory_Free(hnm);
 	CLCheckError();
-	
+
 	CLEndCheck;
 }
 
 
-void CLHNM_SetFile(hnm_t *hnm, file_t* file)
-{
+void CLHNM_SetFile(hnm_t *hnm, file_t *file) {
 	hnm->file = file;
 	CLNoError;
 }
 
-void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer)
-{
+void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer) {
 	hnm->final_buffer = buffer;
 	CLNoError;
 }
 
-void CLHNM_AllocMemory(hnm_t *hnm)
-{
+void CLHNM_AllocMemory(hnm_t *hnm) {
 	CLBeginCheck;
 
-	hnm->work_buffer[0] = (unsigned char*)CLMemory_Alloc(hnm->header.buffersize + 2);
+	hnm->work_buffer[0] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
 	CLCheckError();
 
-	if(!hnm->work_buffer[0])
+	if (!hnm->work_buffer[0])
 		goto fin;
 
-	hnm->work_buffer[1] = (unsigned char*)CLMemory_Alloc(hnm->header.buffersize + 2);
+	hnm->work_buffer[1] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
 	CLCheckError();
 
-	if(!hnm->work_buffer[1])
-	{
+	if (!hnm->work_buffer[1]) {
 		CLMemory_Free(hnm->work_buffer[0]);
 		CLCheckError();
 		hnm->work_buffer[0] = 0;
 		goto fin;
 	}
 
-	if(!use_preload)
-	{
-		hnm->read_buffer = (unsigned char*)CLMemory_Alloc(hnm->header.buffersize + 2);
+	if (!use_preload) {
+		hnm->read_buffer = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
 //		CLCheckError();
-		if(!hnm->read_buffer)
-		{
+		if (!hnm->read_buffer) {
 			CLMemory_Free(hnm->work_buffer[0]);
 			CLCheckError();
 			hnm->work_buffer[0] = 0;
@@ -368,30 +318,26 @@ void CLHNM_AllocMemory(hnm_t *hnm)
 			hnm->work_buffer[1] = 0;
 		}
 	}
-fin:;
+fin:
+	;
 	CLEndCheck;
 }
 
-void CLHNM_DeallocMemory(hnm_t *hnm)
-{
+void CLHNM_DeallocMemory(hnm_t *hnm) {
 	CLBeginCheck;
-	if(hnm->work_buffer[0])
-	{
+	if (hnm->work_buffer[0]) {
 		CLMemory_Free(hnm->work_buffer[0]);
 		CLCheckError();
 		hnm->work_buffer[0] = 0;
 	}
-	if(hnm->work_buffer[1])
-	{
+	if (hnm->work_buffer[1]) {
 		CLMemory_Free(hnm->work_buffer[1]);
 		CLCheckError();
 		hnm->work_buffer[1] = 0;
 	}
 
-	if(!use_preload)
-	{
-		if(hnm->read_buffer)
-		{
+	if (!use_preload) {
+		if (hnm->read_buffer) {
 			CLMemory_Free(hnm->read_buffer);
 			CLCheckError();
 			hnm->read_buffer = 0;
@@ -401,92 +347,74 @@ void CLHNM_DeallocMemory(hnm_t *hnm)
 	CLEndCheck;
 }
 
-void CLHNM_Read(hnm_t *hnm, int size)
-{
+void CLHNM_Read(hnm_t *hnm, int size) {
 	long _size = size;
-	if(!use_preload)
-	{
+	if (!use_preload) {
 		CLFile_Read(*hnm->file, hnm->read_buffer, &_size);
-	}
-	else
-	{
+	} else {
 	}
 }
 
-void CLHNM_GiveTime(hnm_t *hnm)
-{
-	if(use_preload)
-	{
+void CLHNM_GiveTime(hnm_t *hnm) {
+	if (use_preload) {
 		//stuff preload_buffer from disk
 	}
 }
 
-void CLHNM_CanLoop(hnm_t *hnm, short can_loop)
-{
+void CLHNM_CanLoop(hnm_t *hnm, short can_loop) {
 	hnm->can_loop = can_loop;
 }
 
-void CLHNM_SelectBuffers(hnm_t *hnm)
-{
-	if(hnm->frame % 2)
-	{
+void CLHNM_SelectBuffers(hnm_t *hnm) {
+	if (hnm->frame % 2) {
 		hnm->new_frame_buffer = hnm->work_buffer[1];
 		hnm->old_frame_buffer = hnm->work_buffer[0];
-	}
-	else
-	{
+	} else {
 		hnm->new_frame_buffer = hnm->work_buffer[0];
 		hnm->old_frame_buffer = hnm->work_buffer[1];
 	}
 }
 
-void CLHNM_ChangePalette(hnm_t *hnm)
-{
+void CLHNM_ChangePalette(hnm_t *hnm) {
 	short mincolor, maxcolor;
 	unsigned short fst, cnt;
 	unsigned char *pal;
 	color_t *color;
 	CLPalette_GetLastPalette(hnm->palette);
 	pal = hnm->data_ptr;
-	if(*(unsigned short*)pal == 0xFFFF)
+	if (*(unsigned short *)pal == 0xFFFF)
 		return;
 	mincolor = 255;
 	maxcolor = 0;
-	do
-	{
+	do {
 		fst = *pal++;
 		cnt = *pal++;
-		if(cnt == 0)
+		if (cnt == 0)
 			cnt = 256;
 		debug("hnm: setting palette, fst = %d, cnt = %d, last = %d", fst, cnt, fst + cnt - 1);
 		assert(fst + cnt <= 256);
 		if (mincolor > fst)
 			mincolor = fst;
-		if(maxcolor < fst + cnt)
+		if (maxcolor < fst + cnt)
 			maxcolor = fst + cnt;
 		color = hnm->palette + fst;
-		if(safe_palette)
-		{
-			while(cnt--)
-			{
+		if (safe_palette) {
+			while (cnt--) {
 				unsigned char r = *pal++;
 				unsigned char g = *pal++;
 				unsigned char b = *pal++;
 				short rr = r << 10;
 				short gg = g << 10;
 				short bb = b << 10;
-				if(color->r != rr || color->g != gg || color->b != bb)
+				if (color->r != rr || color->g != gg || color->b != bb)
 					CLBlitter_OneBlackFlash();
 				color->r = rr;
 				color->g = gg;
 				color->b = bb;
 				color++;
 			}
-		}
-		else
-		{
-			while(cnt--)
-			{
+		} else {
+			while (cnt--) {
 				unsigned char r = *pal++;
 				unsigned char g = *pal++;
 				unsigned char b = *pal++;
@@ -496,25 +424,21 @@ void CLHNM_ChangePalette(hnm_t *hnm)
 				color++;
 			}
 		}
-		
-	}
-	while(*(unsigned short*)pal != 0xFFFF);
+
+	} while (*(unsigned short *)pal != 0xFFFF);
 #if 0
-	if(preserve_color0)
-	{
+	if (preserve_color0) {
 		hnm->palette[0].r = 0;
 		hnm->palette[0].g = 0;
 		hnm->palette[0].b = 0;
 	}
 #endif
-//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);	
-	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);	
+//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);
+	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);
 }
 
-void CLHNM_Desentrelace(hnm_t *hnm)
-{
-	switch(hnm->header.width)
-	{
+void CLHNM_Desentrelace(hnm_t *hnm) {
+	switch (hnm->header.width) {
 	case 320:
 		CLHNM_Desentrelace320(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
 		CLNoError;
@@ -530,40 +454,32 @@ void CLHNM_Desentrelace(hnm_t *hnm)
 	}
 }
 
-void CLHNM_FlushPreloadBuffer(hnm_t *hnm)
-{
-	if(use_preload)
-	{
+void CLHNM_FlushPreloadBuffer(hnm_t *hnm) {
+	if (use_preload) {
 	}
 }
 
-soundchannel_t* CLHNM_GetSoundChannel()
-{
+soundchannel_t *CLHNM_GetSoundChannel() {
 	return soundChannel;
 }
 
 
-void CLHNM_TryRead(hnm_t *hnm, int size)
-{
+void CLHNM_TryRead(hnm_t *hnm, int size) {
 	short err;
-	do
-	{
+	do {
 		CLHNM_Read(hnm, size);
 		err = __libError == -6;
-		if(err)
+		if (err)
 			CLHNM_GiveTime(hnm);
-	}
-	while(err);
+	} while (err);
 }
 
-void CLHNM_ResetInternalTimer()
-{
+void CLHNM_ResetInternalTimer() {
 	time_drift = 0.0;
 	next_frame_time = expected_frame_time = TimerTicks;
 }
 
-void CLHNM_Reset(hnm_t *hnm)
-{
+void CLHNM_Reset(hnm_t *hnm) {
 	hnm->frame = 0;
 	hnm->ff_4 = 0;
 	hnm->total_read = 0;
@@ -573,32 +489,24 @@ void CLHNM_Reset(hnm_t *hnm)
 	CLNoError;
 }
 
-short CLHNM_LoadFrame(hnm_t *hnm)
-{
+short CLHNM_LoadFrame(hnm_t *hnm) {
 	int chunk;
 	CLBeginCheck;
 	CLHNM_TryRead(hnm, 4);
 	CLEndCheck;
-	chunk = *(int*)hnm->read_buffer;
+	chunk = *(int *)hnm->read_buffer;
 	chunk = LE32(chunk);
-	chunk &= 0xFFFFFF;	// upper bit - keyframe mark?
-	if(!chunk)
+	chunk &= 0xFFFFFF;  // upper bit - keyframe mark?
+	if (!chunk)
 		return 0;
-		
-	if(use_preload)
-	{
-	}
-	else
-	{
-		if(chunk - 4 > hnm->header.buffersize)
-		{
+
+	if (use_preload) {
+	} else {
+		if (chunk - 4 > hnm->header.buffersize) {
 			__libError = -3;
 			__osError = 0;
 			CLCheckError();
-		}
-		else
-		if(use_preload && chunk - 4 > 102400)
-		{
+		} else if (use_preload && chunk - 4 > 102400) {
 			__libError = -3;
 			__osError = 0;
 			CLCheckError();
@@ -612,71 +520,64 @@ short CLHNM_LoadFrame(hnm_t *hnm)
 	return 1;
 }
 
-void CLHNM_WantsSound(short sound)
-{
+void CLHNM_WantsSound(short sound) {
 	use_sound = sound;
 }
 
-void CLHNM_LoadDecompTable(short *buffer)
-{
+void CLHNM_LoadDecompTable(short *buffer) {
 	short i;
 	short e;
-	for(i = 0;i < 256;i++)
-	{
+	for (i = 0; i < 256; i++) {
 		e = *buffer++;
 		decomp_table[i] = LE16(e);
 	}
 }
 
-void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size)
-{
+void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size) {
 	short l = pred_l, r = pred_r;
 	size &= ~1;
-	while(size--)
-	{
+	while (size--) {
 		*output++ = l += decomp_table[*buffer++];
 		*output++ = r += decomp_table[*buffer++];
-		if(l > 512 || r > 512)
+		if (l > 512 || r > 512)
 			DebugStr(" coucou");
 	}
 	pred_l = l;
 	pred_r = r;
 }
 
-void CLHNM_SoundInADPCM(short is_adpcm)
-{
+void CLHNM_SoundInADPCM(short is_adpcm) {
 	use_adpcm = is_adpcm;
 }
 
-void CLHNM_SoundMono(short is_mono)
-{
+void CLHNM_SoundMono(short is_mono) {
 	use_mono = is_mono;
 }
 
-short CLHNM_NextElement(hnm_t *hnm)
-{
+short CLHNM_NextElement(hnm_t *hnm) {
 	int sz;
 	short id;
 	char h6, h7;
 	short i;
-	if(hnm->frame == 0)
-	{
+	if (hnm->frame == 0) {
 		CLHNM_ResetInternalTimer();
 		pred_l = pred_r = 0;
 	}
-	if(hnm->frame == hnm->header.nframe)
+	if (hnm->frame == hnm->header.nframe)
 		return 0;
-	if(!CLHNM_LoadFrame(hnm))
+	if (!CLHNM_LoadFrame(hnm))
 		return 0;
-	for(;;)
-	{
-		sz = PLE32(hnm->data_ptr) & 0xFFFFFF; hnm->data_ptr += 4;
-		id = *(short*)hnm->data_ptr; hnm->data_ptr += 2;
-		h6 = *hnm->data_ptr; hnm->data_ptr += 1;
-		h7 = *hnm->data_ptr; hnm->data_ptr += 1;
+	for (;;) {
+		sz = PLE32(hnm->data_ptr) & 0xFFFFFF;
+		hnm->data_ptr += 4;
+		id = *(short *)hnm->data_ptr;
+		hnm->data_ptr += 2;
+		h6 = *hnm->data_ptr;
+		hnm->data_ptr += 1;
+		h7 = *hnm->data_ptr;
+		hnm->data_ptr += 1;
 		hnm->chunk_id = id;
-		switch(id)
-		{
+		switch (id) {
 		case BE16('PL'):
 			CLHNM_ChangePalette(hnm);
 			hnm->data_ptr += sz - 8;
@@ -685,37 +586,31 @@ short CLHNM_NextElement(hnm_t *hnm)
 			hnm->frame++;
 			CLHNM_SelectBuffers(hnm);
 			CLHNM_DecompLempelZiv(hnm->data_ptr + 4, hnm->new_frame_buffer);
-			switch(hnm->header.width)
-			{
+			switch (hnm->header.width) {
 //			case 320: CLBlitter_RawCopy320ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
 //			case 480: CLBlitter_RawCopy480ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
 //			case 640: CLBlitter_RawCopy640ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
 //			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
-			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);	//TODO strange buffer size here
+			default:
+				memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);  //TODO strange buffer size here
 			}
-			if(!(h6 & 1))
+			if (!(h6 & 1))
 				CLHNM_Desentrelace(hnm);
-			else
-			{
+			else {
 //				if(hnm->header.width == 640)
 //					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
 //				else
-					memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);	//TODO: wrong size?
+				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);   //TODO: wrong size?
 			}
-			if(use_adpcm)
-			{
-				if(!sound_started)
-				{
-					for(i = 0;i < pending_sounds;i++)
+			if (use_adpcm) {
+				if (!sound_started) {
+					for (i = 0; i < pending_sounds; i++)
 						CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
 					sound_started = 1;
 				}
-			}
-			else
-			{
-				if(!sound_started)
-				{
-					for(i = 0;i < pending_sounds;i++)
+			} else {
+				if (!sound_started) {
+					for (i = 0; i < pending_sounds; i++)
 						CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
 					sound_started = 1;
 				}
@@ -725,53 +620,42 @@ short CLHNM_NextElement(hnm_t *hnm)
 			hnm->frame++;
 			CLHNM_SelectBuffers(hnm);
 			CLHNM_DecompUBA(hnm->new_frame_buffer, hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->data_ptr, hnm->header.width, h6);
-			if(!(h6 & 1))
+			if (!(h6 & 1))
 				CLHNM_Desentrelace(hnm);
-			else
-			{
+			else {
 //				if(hnm->header.width == 640)
 //					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
 //				else
-					memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
 			}
 			goto end_frame;
 		case BE16('sd'):
 		case BE16('SD'):
-			if(use_sound)
-			{
-				if(!h6)
-				{
+			if (use_sound) {
+				if (!h6) {
 					int sound_size = sz - 8;
-					if(!use_adpcm)
-					{
+					if (!use_adpcm) {
 						CLSoundGroup_SetDatas(soundGroup, hnm->data_ptr, sound_size - 2, 0);
-						if(sound_started)
+						if (sound_started)
 							CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
 						else
 							pending_sounds++;
-					}
-					else
-					{
-						short *sound_buffer = (short*)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
-						if(!pending_sounds)
-						{
+					} else {
+						short *sound_buffer = (short *)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
+						if (!pending_sounds) {
 							const int kDecompTableSize = 256 * sizeof(short);
-							CLHNM_LoadDecompTable((short*)hnm->data_ptr);
+							CLHNM_LoadDecompTable((short *)hnm->data_ptr);
 							CLHNM_DecompADPCM(hnm->data_ptr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize);
 							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, 0);
-						}
-						else
-						{
+						} else {
 							CLHNM_DecompADPCM(hnm->data_ptr, sound_buffer, sound_size);
 							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, sound_size * 2, 0);
 						}
 						pending_sounds++;
-						if(sound_started)
+						if (sound_started)
 							CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
 					}
-				}
-				else
-				{
+				} else {
 					__libError = -3;
 					__osError = 0;
 					CLCheckError();
@@ -780,27 +664,24 @@ short CLHNM_NextElement(hnm_t *hnm)
 			hnm->data_ptr += sz - 8;
 			break;
 		default:
-			if(custom_chunk_handler)
-				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7); 
+			if (custom_chunk_handler)
+				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7);
 			hnm->data_ptr += sz - 8;
 		}
 	}
-end_frame:;
-	if(use_preload)
-	{
+end_frame:
+	;
+	if (use_preload) {
 	}
 	return 1;
 }
 
-void CLHNM_ReadHeader(hnm_t *hnm)
-{
+void CLHNM_ReadHeader(hnm_t *hnm) {
 	CLBeginCheck;
-	if(!use_preload)
-	{
+	if (!use_preload) {
 		long size = sizeof(hnm->header);
 		CLFile_Read(*hnm->file, &hnm->header, &size);
-	}
-	else
+	} else
 		;
 	CLCheckError();
 	CLEndCheck;
@@ -813,50 +694,41 @@ void CLHNM_ReadHeader(hnm_t *hnm)
 	hnm->header.maxbuffer = LE16(hnm->header.maxbuffer);
 	hnm->header.buffersize = LE32(hnm->header.buffersize);
 	hnm->header.ff_20 = LE16(hnm->header.ff_20);
-	hnm->header.buffersize += 4096;	//TODO: checkme
+	hnm->header.buffersize += 4096; //TODO: checkme
 }
 
-short CLHNM_GetVersion(hnm_t *hnm)
-{
+short CLHNM_GetVersion(hnm_t *hnm) {
 	CLNoError;
-	if(hnm->header.id == BE32('HNM4'))
+	if (hnm->header.id == BE32('HNM4'))
 		return 4;
 	return -1;
 }
 
-int CLHNM_GetFrameNum(hnm_t *hnm)
-{
+int CLHNM_GetFrameNum(hnm_t *hnm) {
 	return hnm->frame;
 }
 
-void CLHNM_DeactivatePreloadBuffer()
-{
+void CLHNM_DeactivatePreloadBuffer() {
 	use_preload = 0;
 }
 
-void CLHNM_Prepare2Read(hnm_t *hnm, int mode)
-{
-	if(use_preload)
-	{
+void CLHNM_Prepare2Read(hnm_t *hnm, int mode) {
+	if (use_preload) {
 	}
 }
 
-void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos)
-{
+void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos) {
 	CLFile_SetPosition(*hnm->file, 1, pos);
 }
 
-void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height)
-{
-	unsigned int *input = (unsigned int*)frame_buffer;
-	unsigned int *line0 = (unsigned int*)final_buffer;
-	unsigned int *line1 = (unsigned int*)(final_buffer + 320);
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height) {
+	unsigned int *input = (unsigned int *)frame_buffer;
+	unsigned int *line0 = (unsigned int *)final_buffer;
+	unsigned int *line1 = (unsigned int *)(final_buffer + 320);
 	int count = (height) / 2;
-	while(count--)
-	{
+	while (count--) {
 		short i;
-		for(i = 0;i < 320 / 4;i++)
-		{
+		for (i = 0; i < 320 / 4; i++) {
 			unsigned int p0 = *input++;
 			unsigned int p4 = *input++;
 #if 0
diff --git a/engines/cryo/CLSouNdRaw.c b/engines/cryo/CLSouNdRaw.c
index 22bc908..c29ca93 100644
--- a/engines/cryo/CLSouNdRaw.c
+++ b/engines/cryo/CLSouNdRaw.c
@@ -1,13 +1,11 @@
 #include "cryolib.h"
 
-sound_t* CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode)
-{
+sound_t *CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode) {
 	sound_t *sound;
 	CLBeginCheck;
-	
-	sound = (sound_t*)CLMemory_Alloc(sizeof(*sound));
-	if(sound)
-	{
+
+	sound = (sound_t *)CLMemory_Alloc(sizeof(*sound));
+	if (sound) {
 		sound->ff_1A = arg1;
 		sound->rate = rate;
 		sound->sampleSize = sampleSize;
@@ -24,31 +22,27 @@ sound_t* CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode)
 			CLSound_PrepareSample(sound, mode);
 			CLNoError;
 		}
-	}
-	else
-	{
+	} else {
 		__libError = -1;
 		__osError = MemError();
 		CLCheckError();
 	}
-	
+
 	CLEndCheck;
 	return sound;
 }
 
-void CLSoundRaw_Free(sound_t *sound)
-{
-	while(sound->locked) ;
+void CLSoundRaw_Free(sound_t *sound) {
+	while (sound->locked) ;
 //	CLMemory_FreeHandle(sound->sndHandle);
 	CLMemory_Free(sound);
 }
 
-void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length)
-{
+void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
 	char *buf;
 	CLSound_SetLength(sound, length);
 	sound->length = length;
-	buf = bufferOffs + (char*)buffer;
+	buf = bufferOffs + (char *)buffer;
 //	if(CLSound_GetWantsDesigned())
 //		CLSound_Signed2NonSigned(buf, length);
 	sound->buffer = buf;
diff --git a/engines/cryo/CryoLib.h b/engines/cryo/CryoLib.h
index 5fe3e8c..5825a13 100644
--- a/engines/cryo/CryoLib.h
+++ b/engines/cryo/CryoLib.h
@@ -29,153 +29,153 @@ extern short __debug2;
 
 extern short __debug, __libError, __osError;
 
-#define CLBeginCheck	{ short __oldDebug = __debug; __debug = -1;
-#define CLEndCheck		__debug = __oldDebug; }
-#define CLNoError		__libError = 0;
-
-#define CLCheckError() if(__debug && __libError){	\
-	char buffer[260];			\
-	sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);	\
-	DebugStr(c2pstr(buffer));	\
+#define CLBeginCheck    { short __oldDebug = __debug; __debug = -1;
+#define CLEndCheck      __debug = __oldDebug; }
+#define CLNoError       __libError = 0;
+
+#define CLCheckError() if(__debug && __libError){   \
+		char buffer[260];           \
+		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer));   \
 	};
 
-#define CLAssert(x) if(!(x)) {	\
-	char buffer[260];			\
-	sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);	\
-	DebugStr(c2pstr(buffer));	\
+#define CLAssert(x) if(!(x)) {  \
+		char buffer[260];           \
+		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer));   \
 	};
 
 struct rect_t {
-int	sy, sx, ey, ex;
+	int sy, sx, ey, ex;
 };
 typedef struct rect_t rect_t;
 
 struct view_t {
-unsigned char	*p_buffer;
-int		width;
-int		height;
-short	pitch;
-short	doubled;
-short	allocated;
-struct {
-int		src_left;
-int		src_top;
-int		dst_left;
-int		dst_top;
-int		width;
-int		height;
-} norm, zoom;
+	unsigned char   *p_buffer;
+	int     width;
+	int     height;
+	short   pitch;
+	short   doubled;
+	short   allocated;
+	struct {
+		int     src_left;
+		int     src_top;
+		int     dst_left;
+		int     dst_top;
+		int     width;
+		int     height;
+	} norm, zoom;
 };
 typedef struct view_t view_t;
 
 struct color3_t {
-short	r, g, b;
+	short   r, g, b;
 };
 typedef struct color3_t color3_t;
 
 struct color_t {
-short	a, r, g, b;
+	short   a, r, g, b;
 };
 typedef struct color_t color_t;
 
 struct palette_t {
-color_t	colors[256];
+	color_t colors[256];
 };
 typedef struct palette_t palette_t;
 
 #pragma pack(push, 1)
 struct hnmheader_t {
-int				id;
-char			flag1;
-char			flag2;
-char			reseverd;
-char			bpp;
-unsigned short	width;
-unsigned short	height;
-int				filesize;
-int				nframe;
-int				table_offset;
-short			speed;
-short			maxbuffer;
-int				buffersize;
-short			ff_20;
-char			reserved2[14];
-char			copyright[16];
+	int             id;
+	char            flag1;
+	char            flag2;
+	char            reseverd;
+	char            bpp;
+	unsigned short  width;
+	unsigned short  height;
+	int             filesize;
+	int             nframe;
+	int             table_offset;
+	short           speed;
+	short           maxbuffer;
+	int             buffersize;
+	short           ff_20;
+	char            reserved2[14];
+	char            copyright[16];
 };
 typedef struct hnmheader_t hnmheader_t;
 #pragma pack(pop)
 
 struct hnm_t {
-int				frame;
-int				ff_4;
-file_t*			file;
-hnmheader_t		header;
-unsigned char	*work_buffer[2];
-unsigned char	*final_buffer;
-unsigned char	*new_frame_buffer;
-unsigned char	*old_frame_buffer;
-unsigned char	*read_buffer;
-unsigned char	*data_ptr;
-color_t			palette[256];
-
-short			can_loop;
-
-short			ff_896;
-short			chunk_id;
-int				total_read;
+	int             frame;
+	int             ff_4;
+	file_t         *file;
+	hnmheader_t     header;
+	unsigned char   *work_buffer[2];
+	unsigned char   *final_buffer;
+	unsigned char   *new_frame_buffer;
+	unsigned char   *old_frame_buffer;
+	unsigned char   *read_buffer;
+	unsigned char   *data_ptr;
+	color_t         palette[256];
+
+	short           can_loop;
+
+	short           ff_896;
+	short           chunk_id;
+	int             total_read;
 };
 typedef struct hnm_t hnm_t;
 
 //struct filespec_t {
-//char	puff;
+//char  puff;
 //};
 
 struct sound_t {
-Handle	sndHandle;
-short	headerLen;
-long	headerOffset;
-short	ff_A;
-
-char	*buffer;
-int		ff_16;
-short	ff_1A;
-float	rate;
-short	sampleSize;
-int		length;
-short	mode;
-volatile short	locked;
-long	loopStart;
-short	loopTimes;
-short	reversed;
-short	ff_32;
-short	volume;
+	Handle  sndHandle;
+	short   headerLen;
+	long    headerOffset;
+	short   ff_A;
+
+	char    *buffer;
+	int     ff_16;
+	short   ff_1A;
+	float   rate;
+	short   sampleSize;
+	int     length;
+	short   mode;
+	volatile short  locked;
+	long    loopStart;
+	short   loopTimes;
+	short   reversed;
+	short   ff_32;
+	short   volume;
 };
 typedef struct sound_t sound_t;
 
 #define CL_MAX_SOUNDS 64
 
 struct soundgroup_t {
-sound_t	*sound[CL_MAX_SOUNDS];
-short	numSounds;
-short	soundIndex;
-short	playIndex;
-short	ff_106;
+	sound_t *sound[CL_MAX_SOUNDS];
+	short   numSounds;
+	short   soundIndex;
+	short   playIndex;
+	short   ff_106;
 };
 typedef struct soundgroup_t soundgroup_t;
 
 #define CL_MAX_CH_SOUNDS 10
 
 struct soundchannel_t {
-Audio::SoundHandle ch;
-int		xx;
+	Audio::SoundHandle ch;
+	int     xx;
 
-short	volumeLeft;
-short	volumeRight;
-short	numSounds;
+	short   volumeLeft;
+	short   volumeRight;
+	short   numSounds;
 
-sound_t	*sounds[CL_MAX_CH_SOUNDS];
+	sound_t *sounds[CL_MAX_CH_SOUNDS];
 
-short	ff_536;
+	short   ff_536;
 };
 typedef struct soundchannel_t soundchannel_t;
 
diff --git a/engines/cryo/CryoLibStub.c b/engines/cryo/CryoLibStub.c
index cabf2b5..e79ac64 100644
--- a/engines/cryo/CryoLibStub.c
+++ b/engines/cryo/CryoLibStub.c
@@ -1,604 +1,504 @@
 
-	///// Mac APIs
-	typedef short OSErr;
-
-	short MemError()
-	{
-		return 0;
-	}
-
-	void SysBeep(int x)
-	{
-	}
-
-	OSErr SetFPos(short handle, short mode, long pos)
-	{
-		return 0;
-	}
-
-	OSErr FSRead(short handle, long *size, void *buffer)
-	{
-		return 0;
-	}
-
-	void FlushEvents(short arg1, short arg2)
-	{
-	}
-
-	char* c2pstr(char *s)
-	{
-		return s;
-	}
-
-	void DebugStr(char *s)
-	{
-	}
-
-	// from mw lib???
-	long TickCount()
-	{
-		return g_system->getMillis();
-	}
-
-	///// CLMemory
-	void* CLMemory_Alloc(int size)
-	{
-		return malloc(size);
-	}
-	void CLMemory_Free(void *ptr)
-	{
-		//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
-		if (!ptr)
-			return;
-
-		free(ptr);
-	}
-
-
-	///// CLTimer
-	volatile long TimerTicks = 0;	// incremented in realtime
-
-	///// CLView
-	void CLView_SetSrcZoomValues(view_t *view, int x, int y)
-	{
-		view->zoom.src_left = x;
-		view->zoom.src_top = y;
-	}
-	void CLView_SetDisplayZoomValues(view_t *view, int w, int h)
-	{
-		view->zoom.width = w;
-		view->zoom.height = h;
-	}
-	void CLView_Free(view_t *view)
-	{
-		if (view->p_buffer && view->allocated)
-			CLMemory_Free(view->p_buffer);
-		if (view)
+///// Mac APIs
+typedef short OSErr;
+
+short MemError() {
+	return 0;
+}
+
+void SysBeep(int x) {
+}
+
+OSErr SetFPos(short handle, short mode, long pos) {
+	return 0;
+}
+
+OSErr FSRead(short handle, long *size, void *buffer) {
+	return 0;
+}
+
+void FlushEvents(short arg1, short arg2) {
+}
+
+char *c2pstr(char *s) {
+	return s;
+}
+
+void DebugStr(char *s) {
+}
+
+// from mw lib???
+long TickCount() {
+	return g_system->getMillis();
+}
+
+///// CLMemory
+void *CLMemory_Alloc(int size) {
+	return malloc(size);
+}
+void CLMemory_Free(void *ptr) {
+	//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
+	if (!ptr)
+		return;
+
+	free(ptr);
+}
+
+
+///// CLTimer
+volatile long TimerTicks = 0;   // incremented in realtime
+
+///// CLView
+void CLView_SetSrcZoomValues(view_t *view, int x, int y) {
+	view->zoom.src_left = x;
+	view->zoom.src_top = y;
+}
+void CLView_SetDisplayZoomValues(view_t *view, int w, int h) {
+	view->zoom.width = w;
+	view->zoom.height = h;
+}
+void CLView_Free(view_t *view) {
+	if (view->p_buffer && view->allocated)
+		CLMemory_Free(view->p_buffer);
+	if (view)
+		CLMemory_Free(view);
+}
+void CLView_InitDatas(view_t *view, int w, int h, void *buffer) {
+	view->p_buffer = (unsigned char *)buffer;
+	view->width = w;
+	view->height = h;
+	view->pitch = w;
+	view->doubled = 0;
+	view->norm.src_left = 0;
+	view->norm.src_top = 0;
+	view->norm.dst_left = 0;
+	view->norm.dst_top = 0;
+	view->norm.width = w;
+	view->norm.height = h;
+	view->zoom.src_left = 0;
+	view->zoom.src_top = 0;
+	view->zoom.dst_left = 0;
+	view->zoom.dst_top = 0;
+	view->zoom.width = w;
+	view->zoom.height = h;
+}
+view_t *CLView_New(int w, int h) {
+	view_t *view = (view_t *)CLMemory_Alloc(sizeof(view_t));
+	if (view) {
+		void *buffer = (unsigned char *)CLMemory_Alloc(w * h);
+		if (buffer) {
+			view->allocated = 1;
+			CLView_InitDatas(view, w, h, buffer);
+		} else {
 			CLMemory_Free(view);
-	}
-	void CLView_InitDatas(view_t *view, int w, int h, void *buffer)
-	{
-		view->p_buffer = (unsigned char*)buffer;
-		view->width = w;
-		view->height = h;
-		view->pitch = w;
-		view->doubled = 0;
-		view->norm.src_left = 0;
-		view->norm.src_top = 0;
-		view->norm.dst_left = 0;
-		view->norm.dst_top = 0;
-		view->norm.width = w;
-		view->norm.height = h;
-		view->zoom.src_left = 0;
-		view->zoom.src_top = 0;
-		view->zoom.dst_left = 0;
-		view->zoom.dst_top = 0;
-		view->zoom.width = w;
-		view->zoom.height = h;
-	}
-	view_t* CLView_New(int w, int h)
-	{
-		view_t *view = (view_t*)CLMemory_Alloc(sizeof(view_t));
-		if (view)
-		{
-			void *buffer = (unsigned char*)CLMemory_Alloc(w * h);
-			if (buffer)
-			{
-				view->allocated = 1;
-				CLView_InitDatas(view, w, h, buffer);
-			}
-			else
-			{
-				CLMemory_Free(view);
-				view = 0;
-			}
-		}
-		return view;
-	}
-	void CLView_CenterIn(view_t *parent, view_t *child)
-	{
-		child->norm.dst_left = (parent->width - child->norm.width) / 2;
-		child->norm.dst_top = (parent->height - child->norm.height) / 2;
-		child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
-		child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
-	}
-
-	///// CLScreenView
-	view_t ScreenView;
-
-	void CLScreenView_Init()
-	{
-		// ScreenView is the game's target screen (a pc display)
-		// we use a dedicated surface for it, which at some point will be
-		// presented to user by System::copyRectToScreen call
-		CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
-	}
-
-	void CLScreenView_CenterIn(view_t *view)
-	{
-		CLView_CenterIn(&ScreenView, view);
-	}
-
-	///// CLPalette
-	unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
-	short gMacintize = 0;
-	color_t black_palette[256];
-	color_t last_palette[256];
-	void CLPalette_Init()
-	{
-		short i;
-		for (i = 0; i < 256; i++)
-			black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
-	}
-	void CLPalette_SetLastPalette(color_t *palette, short first, short count)
-	{
-		short i;
-		for (i = first; i < first + count; i++)
-			last_palette[i] = palette[i];
-	}
-	void CLPalette_GetLastPalette(color_t *palette)
-	{
-		short i;
-		for (i = 0; i < 256; i++)
-			palette[i] = last_palette[i];
-	}
-	void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb)
-	{
-		palette[index].r = rgb->r;
-		palette[index].g = rgb->g;
-		palette[index].b = rgb->b;
-		palette[index].a = 0;
-	}
-	void CLPalette_Macintize(short macintize)
-	{
-		gMacintize = macintize;
-	}
-	void CLPalette_SetInterval(unsigned short first, unsigned short last)
-	{
-		gIntervalFirst = first;
-		gIntervalSet = 1;
-		gIntervalLast = last;
-	}
-	void CLPalette_DeactivateInterval()
-	{
-		gIntervalSet = 0;
-	}
-	void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count)
-	{
-		OSErr err;
-		short i;
-		if (gMacintize)
-		{
-			palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
-			palette[255].r = palette[255].g = palette[255].b = 0;
-		}
-		if (gIntervalSet)
-		{
-			if (first < gIntervalFirst)
-				first = gIntervalFirst;
-			if (first + count > gIntervalLast)
-				count = gIntervalLast - first;
-		}
-
-		byte buffer[256 * 3];
-		for (i = 0; i < 256; i++)
-		{
-			buffer[i * 3] = palette[i].r >> 8;
-			buffer[i * 3 + 1] = palette[i].g >> 8;
-			buffer[i * 3 + 2] = palette[i].b >> 8;
-		}
-
-		g_system->getPaletteManager()->setPalette(buffer, first, count);
-		g_system->updateScreen();
-
-		CLPalette_SetLastPalette(palette, first, count);
-	}
-	void CLPalette_BeBlack()
-	{
-		CLPalette_Send2Screen(black_palette, 0, 256);
-	}
-	void CLPalette_BeSystem()
-	{
-	}
-
-	///// CLBlitter
-	static unsigned short newPaletteCount, newPaletteFirst;
-	static color_t *pNewPalette;
-	static unsigned short useNewPalette;
-
-	void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2)
-	{
-		int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
-		//	debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
-		//		rect1->sx, rect1->sy, rect1->ex, rect1->ey,
-		//		rect2->sx, rect2->sy, rect2->ex, rect2->ey,
-		//		(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
-		assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
-		for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++)
-		{
-			unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
-			unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
-			for (x = 0; x < w; x++)
-				*d++ = *s++;
+			view = 0;
 		}
 	}
-	void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count)
-	{
-		pNewPalette = palette;
-		useNewPalette = 1;
-		newPaletteFirst = first;
-		newPaletteCount = count;
-	}
-	void CLBlitter_OneBlackFlash()
-	{
-	}
-	void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
-		unsigned char *dst, short dstw, short dstp, short dsth)
-	{
-		short x, y;
-		for (y = 0; y < srch; y++)
-		{
-			for (x = 0; x < srcw; x++)
-				*dst++ = *src++;
-			src += srcp - srcw;
-			dst += dstp - dstw;
-		}
-	}
-	void CLBlitter_CopyView2ScreenCUSTOM(view_t *view)
-	{
-		view_t *dest = &ScreenView;
-		if (!view->doubled)
-		{
-			short srcpitch = view->pitch;
-			short dstpitch = dest->pitch;
-
-			//		this is not quite correct?
-			//		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
-			//			dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
-
-			CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
-				dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
-
-		}
-		else
-		{
-			assert(0);
-		}
-	}
-	void CLBlitter_CopyView2Screen(view_t *view)
-	{
-
-		if (useNewPalette)
-		{
-			color_t palette[256];
-			CLPalette_GetLastPalette(palette);
-			CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
-			useNewPalette = 0;
-		}
-
-		//TODO: quick hack to force screen update
-		if (view)
-			CLBlitter_CopyView2ScreenCUSTOM(view);
-
-		g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
-		g_system->updateScreen();
-	}
-	void CLBlitter_UpdateScreen()
-	{
-		CLBlitter_CopyView2Screen(nullptr);
-	}
-	void CLBlitter_FillView(view_t *view, unsigned int fill)
-	{
-		short x, y;
-		unsigned char *d = view->p_buffer;
-		assert((fill & 0xFF) * 0x01010101 == fill);
-		for (y = 0; y < view->height; y++)
-		{
-			for (x = 0; x < view->width; x++)
-				*d++ = fill;
-			d += view->pitch - view->width;
-		}
-	}
-	void CLBlitter_FillScreenView(unsigned int fill)
-	{
-		CLBlitter_FillView(&ScreenView, fill);
-	}
-
-
-	///// events wrapper
-	int _mouseButton;
-	byte _keyState[256];
-
-	void pollEvents()
-	{
-		g_system->delayMillis(10);
-
-		Common::Event event;
-		while (g_system->getEventManager()->pollEvent(event)) {
-			// Handle keypress
-			switch (event.type) {
-			case Common::EVENT_QUIT:
-			case Common::EVENT_RTL:
-				return;
-
-			case Common::EVENT_KEYDOWN:
-				//			_keyState[(byte)toupper(event.kbd.ascii)] = true;
-				return;
-			case Common::EVENT_KEYUP:
-				//			_keyState[(byte)toupper(event.kbd.ascii)] = false;
-				return;
-			case Common::EVENT_LBUTTONDOWN:
-				_mouseButton = 1;
-				return;
-			case Common::EVENT_RBUTTONDOWN:
-				_mouseButton = 2;
-				return;
-			case Common::EVENT_LBUTTONUP:
-			case Common::EVENT_RBUTTONUP:
-				_mouseButton = 0;
-				return;
-			default:
-				break;
-			}
-		}
-	}
-
-
-	///// CLKeyboard
-	short CLKeyboard_HasCmdDown()
-	{
-		return 0;
-	}
-	void CLKeyboard_Read()
-	{
-		pollEvents();
-	}
-	unsigned char CLKeyboard_GetLastASCII()
-	{
-		return 0;
-	}
-	short CLKeyboard_IsScanCodeDown(short scancode)
-	{
-		return 0;
-	}
-
-	///// CLMouse
-	void CLMouse_Hide()
-	{
-	}
-	void CLMouse_Show()
-	{
-	}
-	void CLMouse_GetPosition(short *x, short *y)
-	{
-		*x = g_system->getEventManager()->getMousePos().x;
-		*y = g_system->getEventManager()->getMousePos().y;
-	}
-	void CLMouse_SetPosition(short x, short y)
-	{
-		g_system->warpMouse(x, y);
-	}
-	unsigned short CLMouse_IsDown()
-	{
-		pollEvents();
-		return _mouseButton != 0;
-	}
-
-	///// CLFile
-	void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7)
-	{
-	}
-	void CLFile_SetFinderInfos(void *fs, int a4, int a5)
-	{
-	}
-	void CLFile_GetFullPath(void *a3, char *a4)
-	{
-	}
-	void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs)
-	{
-		strcpy(fs->name, name);
-		fs->create = 0;
-	}
-	void CLFile_Create(filespec_t *fs)
-	{
-		fs->create = 1;
-	}
-	void CLFile_Open(filespec_t *fs, short mode, file_t& handle)
-	{
-		handle.open(fs->name);
-	}
-	void CLFile_Close(file_t& handle)
-	{
-		handle.close();
-	}
-	void CLFile_SetPosition(file_t& handle, short mode, long pos)
-	{
-		assert(mode == 1);
-		handle.seek(pos, 0);
-	}
-	void CLFile_Read(file_t& handle, void *buffer, long *size)
-	{
-		handle.read(buffer, *size);
-	}
-	void CLFile_Write(file_t& handle, void *buffer, long *size)
-	{
+	return view;
+}
+void CLView_CenterIn(view_t *parent, view_t *child) {
+	child->norm.dst_left = (parent->width - child->norm.width) / 2;
+	child->norm.dst_top = (parent->height - child->norm.height) / 2;
+	child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
+	child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
+}
+
+///// CLScreenView
+view_t ScreenView;
+
+void CLScreenView_Init() {
+	// ScreenView is the game's target screen (a pc display)
+	// we use a dedicated surface for it, which at some point will be
+	// presented to user by System::copyRectToScreen call
+	CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
+}
+
+void CLScreenView_CenterIn(view_t *view) {
+	CLView_CenterIn(&ScreenView, view);
+}
+
+///// CLPalette
+unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
+short gMacintize = 0;
+color_t black_palette[256];
+color_t last_palette[256];
+void CLPalette_Init() {
+	short i;
+	for (i = 0; i < 256; i++)
+		black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
+}
+void CLPalette_SetLastPalette(color_t *palette, short first, short count) {
+	short i;
+	for (i = first; i < first + count; i++)
+		last_palette[i] = palette[i];
+}
+void CLPalette_GetLastPalette(color_t *palette) {
+	short i;
+	for (i = 0; i < 256; i++)
+		palette[i] = last_palette[i];
+}
+void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb) {
+	palette[index].r = rgb->r;
+	palette[index].g = rgb->g;
+	palette[index].b = rgb->b;
+	palette[index].a = 0;
+}
+void CLPalette_Macintize(short macintize) {
+	gMacintize = macintize;
+}
+void CLPalette_SetInterval(unsigned short first, unsigned short last) {
+	gIntervalFirst = first;
+	gIntervalSet = 1;
+	gIntervalLast = last;
+}
+void CLPalette_DeactivateInterval() {
+	gIntervalSet = 0;
+}
+void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count) {
+	OSErr err;
+	short i;
+	if (gMacintize) {
+		palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
+		palette[255].r = palette[255].g = palette[255].b = 0;
+	}
+	if (gIntervalSet) {
+		if (first < gIntervalFirst)
+			first = gIntervalFirst;
+		if (first + count > gIntervalLast)
+			count = gIntervalLast - first;
+	}
+
+	byte buffer[256 * 3];
+	for (i = 0; i < 256; i++) {
+		buffer[i * 3] = palette[i].r >> 8;
+		buffer[i * 3 + 1] = palette[i].g >> 8;
+		buffer[i * 3 + 2] = palette[i].b >> 8;
+	}
+
+	g_system->getPaletteManager()->setPalette(buffer, first, count);
+	g_system->updateScreen();
+
+	CLPalette_SetLastPalette(palette, first, count);
+}
+void CLPalette_BeBlack() {
+	CLPalette_Send2Screen(black_palette, 0, 256);
+}
+void CLPalette_BeSystem() {
+}
+
+///// CLBlitter
+static unsigned short newPaletteCount, newPaletteFirst;
+static color_t *pNewPalette;
+static unsigned short useNewPalette;
+
+void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2) {
+	int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
+	//  debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
+	//      rect1->sx, rect1->sy, rect1->ex, rect1->ey,
+	//      rect2->sx, rect2->sy, rect2->ex, rect2->ey,
+	//      (rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
+	assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
+	for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++) {
+		unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
+		unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
+		for (x = 0; x < w; x++)
+			*d++ = *s++;
+	}
+}
+void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count) {
+	pNewPalette = palette;
+	useNewPalette = 1;
+	newPaletteFirst = first;
+	newPaletteCount = count;
+}
+void CLBlitter_OneBlackFlash() {
+}
+void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
+                                       unsigned char *dst, short dstw, short dstp, short dsth) {
+	short x, y;
+	for (y = 0; y < srch; y++) {
+		for (x = 0; x < srcw; x++)
+			*dst++ = *src++;
+		src += srcp - srcw;
+		dst += dstp - dstw;
+	}
+}
+void CLBlitter_CopyView2ScreenCUSTOM(view_t *view) {
+	view_t *dest = &ScreenView;
+	if (!view->doubled) {
+		short srcpitch = view->pitch;
+		short dstpitch = dest->pitch;
+
+		//      this is not quite correct?
+		//      CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+		//          dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+		                                  dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+	} else {
 		assert(0);
 	}
+}
+void CLBlitter_CopyView2Screen(view_t *view) {
+
+	if (useNewPalette) {
+		color_t palette[256];
+		CLPalette_GetLastPalette(palette);
+		CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
+		useNewPalette = 0;
+	}
+
+	//TODO: quick hack to force screen update
+	if (view)
+		CLBlitter_CopyView2ScreenCUSTOM(view);
+
+	g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
+	g_system->updateScreen();
+}
+void CLBlitter_UpdateScreen() {
+	CLBlitter_CopyView2Screen(nullptr);
+}
+void CLBlitter_FillView(view_t *view, unsigned int fill) {
+	short x, y;
+	unsigned char *d = view->p_buffer;
+	assert((fill & 0xFF) * 0x01010101 == fill);
+	for (y = 0; y < view->height; y++) {
+		for (x = 0; x < view->width; x++)
+			*d++ = fill;
+		d += view->pitch - view->width;
+	}
+}
+void CLBlitter_FillScreenView(unsigned int fill) {
+	CLBlitter_FillView(&ScreenView, fill);
+}
+
+
+///// events wrapper
+int _mouseButton;
+byte _keyState[256];
+
+void pollEvents() {
+	g_system->delayMillis(10);
+
+	Common::Event event;
+	while (g_system->getEventManager()->pollEvent(event)) {
+		// Handle keypress
+		switch (event.type) {
+		case Common::EVENT_QUIT:
+		case Common::EVENT_RTL:
+			return;
 
-	///// CLSound
-	// base sound
-	void CLSound_PrepareSample(sound_t *sound, short mode)
-	{
-		sound->mode = mode;
-		sound->locked = 0;
-		sound->loopTimes = 0;
-		sound->reversed = 0;
-		sound->ff_32 = 0;
-		sound->volume = 255;
-	}
-	void CLSound_SetWantsDesigned(short designed)
-	{
-	}
-	void CLSound_SetLength(sound_t *sound, int length)
-	{
-	}
-
-	///// CLSoundRaw
-	// sound from memory buffer
-#include "CLSouNdRaw.c"
-
-	///// CLSoundChannel
-	/// sound output device that plays queue of sounds
-	soundchannel_t* CLSoundChannel_New(int arg1)
-	{
-		short i;
-		soundchannel_t *ch = (soundchannel_t*)CLMemory_Alloc(sizeof(*ch));
-		if (!ch)
-			return 0;
-
-		ch->volumeLeft = ch->volumeRight = 255;
-		ch->numSounds = 0;
-
-		for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
-			ch->sounds[i] = 0;
-
-		return ch;
-	}
-	void CLSoundChannel_Free(soundchannel_t *ch)
-	{
-		CLMemory_Free(ch);
-	}
-	void CLSoundChannel_Stop(soundchannel_t *ch)
-	{
-		//	g_ed->_mixer->stopHandle(ch->ch);
-	}
-	void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound)
-	{
-	}
-	short CLSoundChannel_GetVolume(soundchannel_t *ch)
-	{
-		return (ch->volumeLeft + ch->volumeRight) / 2;
-	}
-	void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume)
-	{
-		if (volume < 0 || volume > 255)
+		case Common::EVENT_KEYDOWN:
+			//          _keyState[(byte)toupper(event.kbd.ascii)] = true;
 			return;
-		ch->volumeLeft = volume;
-		ch->volumeRight = volume;
-	}
-	void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume)
-	{
-		if (volume < 0 || volume > 255)
+		case Common::EVENT_KEYUP:
+			//          _keyState[(byte)toupper(event.kbd.ascii)] = false;
 			return;
-		ch->volumeRight = volume;
-	}
-	void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume)
-	{
-		if (volume < 0 || volume > 255)
+		case Common::EVENT_LBUTTONDOWN:
+			_mouseButton = 1;
 			return;
-		ch->volumeLeft = volume;
-	}
-
-	///// CLSoundGroup
-	/// a queue of sounds of same format
-#include "CLSoundGroup.c"
-
-	///// CLTimer
-	void CLTimer_Action(void *arg)
-	{
-		//	long& counter = *((long*)arg);
-		//	counter++;
-		TimerTicks++;
-	}
-
-	void CLTimer_Init()
-	{
-		g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
-	}
-
-	void CLTimer_Done()
-	{
-		g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
-	}
-
-	///// CRYOLib
-	void CRYOLib_InstallExitPatch()
-	{
-	}
-	void CRYOLib_RemoveExitPatch()
-	{
-	}
-	void CRYOLib_Init()
-	{
-	}
-	void CRYOLib_Done()
-	{
-	}
-	void CRYOLib_MinimalInit()
-	{
-	}
-	void CRYOLib_ManagersInit()
-	{
-		CLTimer_Init();
-		CLScreenView_Init();
-	}
-	void CRYOLib_ManagersDone()
-	{
-		CLTimer_Done();
-	}
-	void CRYOLib_SetDebugMode(short enable)
-	{
-	}
-	void CRYOLib_InstallEmergencyExit(void(*proc)())
-	{
-	}
-	void CRYOLib_SetupEnvironment()
-	{
-	}
-	void CRYOLib_RestoreEnvironment()
-	{
-	}
-	void CRYOLib_TestConfig()
-	{
+		case Common::EVENT_RBUTTONDOWN:
+			_mouseButton = 2;
+			return;
+		case Common::EVENT_LBUTTONUP:
+		case Common::EVENT_RBUTTONUP:
+			_mouseButton = 0;
+			return;
+		default:
+			break;
+		}
 	}
+}
+
+
+///// CLKeyboard
+short CLKeyboard_HasCmdDown() {
+	return 0;
+}
+void CLKeyboard_Read() {
+	pollEvents();
+}
+unsigned char CLKeyboard_GetLastASCII() {
+	return 0;
+}
+short CLKeyboard_IsScanCodeDown(short scancode) {
+	return 0;
+}
+
+///// CLMouse
+void CLMouse_Hide() {
+}
+void CLMouse_Show() {
+}
+void CLMouse_GetPosition(short *x, short *y) {
+	*x = g_system->getEventManager()->getMousePos().x;
+	*y = g_system->getEventManager()->getMousePos().y;
+}
+void CLMouse_SetPosition(short x, short y) {
+	g_system->warpMouse(x, y);
+}
+unsigned short CLMouse_IsDown() {
+	pollEvents();
+	return _mouseButton != 0;
+}
+
+///// CLFile
+void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7) {
+}
+void CLFile_SetFinderInfos(void *fs, int a4, int a5) {
+}
+void CLFile_GetFullPath(void *a3, char *a4) {
+}
+void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs) {
+	strcpy(fs->name, name);
+	fs->create = 0;
+}
+void CLFile_Create(filespec_t *fs) {
+	fs->create = 1;
+}
+void CLFile_Open(filespec_t *fs, short mode, file_t &handle) {
+	handle.open(fs->name);
+}
+void CLFile_Close(file_t &handle) {
+	handle.close();
+}
+void CLFile_SetPosition(file_t &handle, short mode, long pos) {
+	assert(mode == 1);
+	handle.seek(pos, 0);
+}
+void CLFile_Read(file_t &handle, void *buffer, long *size) {
+	handle.read(buffer, *size);
+}
+void CLFile_Write(file_t &handle, void *buffer, long *size) {
+	assert(0);
+}
+
+///// CLSound
+// base sound
+void CLSound_PrepareSample(sound_t *sound, short mode) {
+	sound->mode = mode;
+	sound->locked = 0;
+	sound->loopTimes = 0;
+	sound->reversed = 0;
+	sound->ff_32 = 0;
+	sound->volume = 255;
+}
+void CLSound_SetWantsDesigned(short designed) {
+}
+void CLSound_SetLength(sound_t *sound, int length) {
+}
+
+///// CLSoundRaw
+// sound from memory buffer
+#include "CLSouNdRaw.c"
 
-	///// CLComputer
-	short CLComputer_Has68030()
-	{
+///// CLSoundChannel
+/// sound output device that plays queue of sounds
+soundchannel_t *CLSoundChannel_New(int arg1) {
+	short i;
+	soundchannel_t *ch = (soundchannel_t *)CLMemory_Alloc(sizeof(*ch));
+	if (!ch)
 		return 0;
-	}
-	short CLComputer_Has68040()
-	{
-		return 0;
-	}
 
-	///// CLDesktop
-	void CLDesktop_TestOpenFileAtStartup()
-	{
-	}
+	ch->volumeLeft = ch->volumeRight = 255;
+	ch->numSounds = 0;
+
+	for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
+		ch->sounds[i] = 0;
+
+	return ch;
+}
+void CLSoundChannel_Free(soundchannel_t *ch) {
+	CLMemory_Free(ch);
+}
+void CLSoundChannel_Stop(soundchannel_t *ch) {
+	//  g_ed->_mixer->stopHandle(ch->ch);
+}
+void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound) {
+}
+short CLSoundChannel_GetVolume(soundchannel_t *ch) {
+	return (ch->volumeLeft + ch->volumeRight) / 2;
+}
+void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeLeft = volume;
+	ch->volumeRight = volume;
+}
+void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeRight = volume;
+}
+void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeLeft = volume;
+}
+
+///// CLSoundGroup
+/// a queue of sounds of same format
+#include "CLSoundGroup.c"
 
-	///// CLHNM
+///// CLTimer
+void CLTimer_Action(void *arg) {
+	//  long& counter = *((long*)arg);
+	//  counter++;
+	TimerTicks++;
+}
+
+void CLTimer_Init() {
+	g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
+}
+
+void CLTimer_Done() {
+	g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
+}
+
+///// CRYOLib
+void CRYOLib_InstallExitPatch() {
+}
+void CRYOLib_RemoveExitPatch() {
+}
+void CRYOLib_Init() {
+}
+void CRYOLib_Done() {
+}
+void CRYOLib_MinimalInit() {
+}
+void CRYOLib_ManagersInit() {
+	CLTimer_Init();
+	CLScreenView_Init();
+}
+void CRYOLib_ManagersDone() {
+	CLTimer_Done();
+}
+void CRYOLib_SetDebugMode(short enable) {
+}
+void CRYOLib_InstallEmergencyExit(void(*proc)()) {
+}
+void CRYOLib_SetupEnvironment() {
+}
+void CRYOLib_RestoreEnvironment() {
+}
+void CRYOLib_TestConfig() {
+}
+
+///// CLComputer
+short CLComputer_Has68030() {
+	return 0;
+}
+short CLComputer_Has68040() {
+	return 0;
+}
+
+///// CLDesktop
+void CLDesktop_TestOpenFileAtStartup() {
+}
+
+///// CLHNM
 #include "CLHNM.c"
 
-	///// CLError
+///// CLError
 #include "CLError.c"
diff --git a/engines/cryo/LempelZiv.h b/engines/cryo/LempelZiv.h
index 636d7af..85279b3 100644
--- a/engines/cryo/LempelZiv.h
+++ b/engines/cryo/LempelZiv.h
@@ -2,101 +2,87 @@
 
 namespace Cryo {
 
-	class BitReaderBase {
-	public:
-		unsigned char *_data;	//NB! never override this - used by decompressor
-		unsigned int _queue;
-		unsigned int _queueLeft;
-	public:
-		BitReaderBase(void *data, unsigned int dataSize = 0)
-		{
-			_data = static_cast<unsigned char*>(data);
-			_queue = _queueLeft = 0;
-		}
+class BitReaderBase {
+public:
+	unsigned char *_data;   //NB! never override this - used by decompressor
+	unsigned int _queue;
+	unsigned int _queueLeft;
+public:
+	BitReaderBase(void *data, unsigned int dataSize = 0) {
+		_data = static_cast<unsigned char *>(data);
+		_queue = _queueLeft = 0;
+	}
 
-		unsigned char GetBit()
-		{
-			return 0;	// to be overriden
-		}
-	};
+	unsigned char GetBit() {
+		return 0;   // to be overriden
+	}
+};
 
-	// used to decompress HSQ files
-	class BitReader16 : BitReaderBase {
-	public:
-		unsigned char GetBit()
-		{
-			if (!_queueLeft)
-			{
-				_queue = (_data[1] << 8) | _data[0];
-				_data += 2;
-				_queueLeft += 16;
-			}
-			unsigned char bit = _queue & 1;
-			_queue >>= 1;
-			_queueLeft--;
-			return bit;
+// used to decompress HSQ files
+class BitReader16 : BitReaderBase {
+public:
+	unsigned char GetBit() {
+		if (!_queueLeft) {
+			_queue = (_data[1] << 8) | _data[0];
+			_data += 2;
+			_queueLeft += 16;
 		}
-	};
+		unsigned char bit = _queue & 1;
+		_queue >>= 1;
+		_queueLeft--;
+		return bit;
+	}
+};
 
-	// used by HNM decoder
-	class BitReader32 : BitReaderBase {
-	public:
-		unsigned char GetBit()
-		{
-			if (!_queueLeft)
-			{
-				_queue = (_data[3] << 24) | (_data[2] << 16) | (_data[1] << 8) | _data[0];
-				_data += 4;
-				_queueLeft += 32;
-			}
-			unsigned char bit = (_queue >> (_queueLeft - 1)) & 1;
-			_queueLeft--;
-			return bit;
+// used by HNM decoder
+class BitReader32 : BitReaderBase {
+public:
+	unsigned char GetBit() {
+		if (!_queueLeft) {
+			_queue = (_data[3] << 24) | (_data[2] << 16) | (_data[1] << 8) | _data[0];
+			_data += 4;
+			_queueLeft += 32;
 		}
-	};
+		unsigned char bit = (_queue >> (_queueLeft - 1)) & 1;
+		_queueLeft--;
+		return bit;
+	}
+};
 
-	template <class BitReader>
-	class LempelZivBase : BitReader
-	{
-	public:
-		LempelZivBase(void *input, unsigned int inputSize) : BitReader(input, inputSize)
+template <class BitReader>
+class LempelZivBase : BitReader {
+public:
+	LempelZivBase(void *input, unsigned int inputSize) : BitReader(input, inputSize)
 
-		unsigned int UnpackBuffer(void *output, unsigned int maxOutputSize)
-		{
-			unsigned char *out = static_cast<unsigned char*>(output);
-			for (;;)
-			{
-				if (GetBit())
-				{
-					*out++ = *_data++;
+		unsigned int UnpackBuffer(void *output, unsigned int maxOutputSize) {
+		unsigned char *out = static_cast<unsigned char *>(output);
+		for (;;) {
+			if (GetBit()) {
+				*out++ = *_data++;
+			} else {
+				int length, offset;
+				if (GetBit()) {
+					length = *_data & 7;
+					offset = ((_data[1] << 8) | _data[0]) >> 3;
+					_data += 2;
+					offset -= 8192;
+					if (!length)
+						length = *_data++;
+					if (!length)
+						break;
+				} else {
+					length = GetBit() * 2 + GetBit();
+					offset = *(_data++) - 256;
 				}
-				else
-				{
-					int length, offset;
-					if (GetBit())
-					{
-						length = *_data & 7;
-						offset = ((_data[1] << 8) | _data[0]) >> 3; _data += 2;
-						offset -= 8192;
-						if (!length)
-							length = *_data++;
-						if (!length)
-							break;
-					}
-					else
-					{
-						length = GetBit() * 2 + GetBit();
-						offset = *(_data++) - 256;
-					}
-					length += 2;
-					while (length--)
-					{
-						*out = *(out + offset); out++;
-					}
+				length += 2;
+				while (length--) {
+					*out = *(out + offset);
+					out++;
 				}
 			}
-			return out - static_cast<unsigned char*>(output);
 		}
-	};
+		return out - static_cast<unsigned char *>(output);
+	}
+};
 
-}
\ No newline at end of file
+}
diff --git a/engines/cryo/ResourceManager.cpp b/engines/cryo/ResourceManager.cpp
index 7280443..dd541f7 100644
--- a/engines/cryo/ResourceManager.cpp
+++ b/engines/cryo/ResourceManager.cpp
@@ -2,115 +2,99 @@
 
 namespace Cryo {
 
-	ResourceManager::ResourceManager()
-	{
-	}
+ResourceManager::ResourceManager() {
+}
 
-	ResourceManager::ResourceManager(const Common::String &datFileName)
-	{
-		LoadDatFile(datFileName);
-	}
+ResourceManager::ResourceManager(const Common::String &datFileName) {
+	LoadDatFile(datFileName);
+}
+
+ResourceManager::~ResourceManager() {
+}
 
-	ResourceManager::~ResourceManager()
-	{
+bool ResourceManager::LoadDatFile(const Common::String &datFileName) {
+	if (_datFile.isOpen()) {
+		_datFile.close();
+		_files.clear();
 	}
 
-	bool ResourceManager::LoadDatFile(const Common::String &datFileName)
-	{
-		if (_datFile.isOpen())
-		{
-			_datFile.close();
-			_files.clear();
-		}
+	assert(_datFile.open(datFileName));
 
-		assert(_datFile.open(datFileName));
+	unsigned short numFiles = _datFile.readUint16LE();
 
-		unsigned short numFiles = _datFile.readUint16LE();
+	for (unsigned short i = 0; i < numFiles; i++) {
+		DatFileEntry entry;
 
-		for (unsigned short i = 0; i < numFiles; i++)
-		{
-			DatFileEntry entry;
+		_datFile.read(entry._name, sizeof(entry._name));
+		entry._size = _datFile.readUint32LE();
+		entry._offset = _datFile.readUint32LE();
+		entry._flag = _datFile.readByte();
 
-			_datFile.read(entry._name, sizeof(entry._name));
-			entry._size = _datFile.readUint32LE();
-			entry._offset = _datFile.readUint32LE();
-			entry._flag = _datFile.readByte();
+		_files.push_back(entry);
+	}
 
-			_files.push_back(entry);
-		}
+	return true;
+}
 
-		return true;
-	}
+Common::SeekableReadStream *ResourceManager::GetFile(const Common::String &resName, unsigned int hintIndex) {
+	// First, try raw disk file so we can support modding/patching
 
-	Common::SeekableReadStream *ResourceManager::GetFile(const Common::String &resName, unsigned int hintIndex)
-	{
-		// First, try raw disk file so we can support modding/patching
+	if (Common::File::exists(resName)) {
+		debug("Loading %s from disk", resName);
 
-		if (Common::File::exists(resName))
-		{
-			debug("Loading %s from disk", resName);
+		Common::File *resource = new Common::File();
+		resource->open(resName);
+		return resource;
+	}
 
-			Common::File *resource = new Common::File();
-			resource->open(resName);
-			return resource;
-		}
+	// Look inside .dat file
 
-		// Look inside .dat file
-
-		if (_datFile.isOpen())
-		{
-			for (unsigned int i = hintIndex; i < _files.size(); i++)
-			{
-				if (!resName.compareToIgnoreCase(_files[i]._name))
-				{
-					debug("Loading %s from dat file", resName);
-					Common::SeekableSubReadStream *resource = new Common::SeekableSubReadStream(&_datFile, _files[i]._offset, _files[i]._offset + _files[i]._size);
-					return resource;
-				}
+	if (_datFile.isOpen()) {
+		for (unsigned int i = hintIndex; i < _files.size(); i++) {
+			if (!resName.compareToIgnoreCase(_files[i]._name)) {
+				debug("Loading %s from dat file", resName);
+				Common::SeekableSubReadStream *resource = new Common::SeekableSubReadStream(&_datFile, _files[i]._offset, _files[i]._offset + _files[i]._size);
+				return resource;
 			}
 		}
-
-		debug("Unable to load %s - does't exists", resName);
-		return nullptr;
 	}
 
-	Common::SeekableReadStream *ResourceManager::GetFile(unsigned int resIndex)
-	{
-		if (_files.size() > resIndex)
-		{
-			return GetFile(Common::String(_files[resIndex]._name), resIndex);
-		}
+	debug("Unable to load %s - does't exists", resName);
+	return nullptr;
+}
 
-		return nullptr;
+Common::SeekableReadStream *ResourceManager::GetFile(unsigned int resIndex) {
+	if (_files.size() > resIndex) {
+		return GetFile(Common::String(_files[resIndex]._name), resIndex);
 	}
 
-	void *ResourceManager::StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size)
-	{
-		if (!stream)
-			return nullptr;
+	return nullptr;
+}
 
-		unsigned int readSize = stream->size();
-		unsigned char *data = new unsigned char[readSize + 1];
-		readSize = stream->read(data, readSize);
-
-		if (size)
-			*size = readSize;
-		return data;
-	}
-
-	void* ResourceManager::GetData(const Common::String &resName, unsigned int *size)
-	{
-		Common::SeekableReadStream *resource = GetFile(resName);
-		void *data = StreamToBuffer(resource, size);
-		delete resource;
-		return data;
-	}
+void *ResourceManager::StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size) {
+	if (!stream)
+		return nullptr;
 
-	void* ResourceManager::GetData(int resIndex, unsigned int *size)
-	{
-		Common::SeekableReadStream *resource = GetFile(resIndex);
-		void *data = StreamToBuffer(resource, size);
-		delete resource;
-		return data;
-	}
+	unsigned int readSize = stream->size();
+	unsigned char *data = new unsigned char[readSize + 1];
+	readSize = stream->read(data, readSize);
+
+	if (size)
+		*size = readSize;
+	return data;
+}
+
+void *ResourceManager::GetData(const Common::String &resName, unsigned int *size) {
+	Common::SeekableReadStream *resource = GetFile(resName);
+	void *data = StreamToBuffer(resource, size);
+	delete resource;
+	return data;
+}
+
+void *ResourceManager::GetData(int resIndex, unsigned int *size) {
+	Common::SeekableReadStream *resource = GetFile(resIndex);
+	void *data = StreamToBuffer(resource, size);
+	delete resource;
+	return data;
+}
 }
\ No newline at end of file
diff --git a/engines/cryo/ResourceManager.h b/engines/cryo/ResourceManager.h
index 1ef5776..9bba1d3 100644
--- a/engines/cryo/ResourceManager.h
+++ b/engines/cryo/ResourceManager.h
@@ -9,69 +9,62 @@
 
 namespace Cryo {
 
-	template<typename T>
-	class CryoArray {
-	private:
-		unsigned char *_data;
-		bool _ownData;
-		unsigned short ElementOffset(int num)
-		{
-			assert(_data && num < Count())
-			return (static_cast<unsigned short*>_data)[num];
-		}
-	public:
-		CryoArray(void* data, bool ownData) : _data(data), _ownData(ownData)
-		{
-		}
-		~CryoArray()
-		{
-			if (_ownData)
-				delete data;
-		}
-		unsigned short Count()
-		{
-			return ElementOffset(0) / 2;
-		}
-		const T* operator[](int index)
-		{
-			return static_cast<T*>(_data + ElementOffset(num));
-		}
-	};
+template<typename T>
+class CryoArray {
+private:
+	unsigned char *_data;
+	bool _ownData;
+	unsigned short ElementOffset(int num) {
+		assert(_data && num < Count())
+		return (static_cast<unsigned short *>_data)[num];
+	}
+public:
+	CryoArray(void *data, bool ownData) : _data(data), _ownData(ownData) {
+	}
+	~CryoArray() {
+		if (_ownData)
+			delete data;
+	}
+	unsigned short Count() {
+		return ElementOffset(0) / 2;
+	}
+	const T *operator[](int index) {
+		return static_cast<T *>(_data + ElementOffset(num));
+	}
+};
 
-	class ResourceManager
-	{
-	private:
-		struct DatFileEntry {
-			char _name[16];
-			unsigned int _size;
-			unsigned int _offset;
-			unsigned char _flag;
-		};
+class ResourceManager {
+private:
+	struct DatFileEntry {
+		char _name[16];
+		unsigned int _size;
+		unsigned int _offset;
+		unsigned char _flag;
+	};
 
-		Common::Array<DatFileEntry> _files;
-		Common::File _datFile;
+	Common::Array<DatFileEntry> _files;
+	Common::File _datFile;
 
-		static void *StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size);
+	static void *StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size);
 
-	public:
-		ResourceManager(const Common::String &datFileName);
-		ResourceManager();
-		~ResourceManager();
+public:
+	ResourceManager(const Common::String &datFileName);
+	ResourceManager();
+	~ResourceManager();
 
-		bool LoadDatFile(const Common::String &datFileName);
+	bool LoadDatFile(const Common::String &datFileName);
 
-		// Load resource as a seekable stream
-		Common::SeekableReadStream *GetFile(const Common::String &resName, unsigned int hintIndex = 0);
-		Common::SeekableReadStream *GetFile(unsigned int resIndex);
+	// Load resource as a seekable stream
+	Common::SeekableReadStream *GetFile(const Common::String &resName, unsigned int hintIndex = 0);
+	Common::SeekableReadStream *GetFile(unsigned int resIndex);
 
-		// Load resource as a buffer
-		void* GetData(const Common::String &resName, unsigned int *size = nullptr);
-		void* GetData(int resIndex, unsigned int *size = nullptr);
-		void* operator[](int resIndex)
-		{
-			return GetData(resIndex);
-		}
+	// Load resource as a buffer
+	void *GetData(const Common::String &resName, unsigned int *size = nullptr);
+	void *GetData(int resIndex, unsigned int *size = nullptr);
+	void *operator[](int resIndex) {
+		return GetData(resIndex);
+	}
 
-	};
+};
 
 }
\ No newline at end of file
diff --git a/engines/cryo/clsoundgroup.c b/engines/cryo/clsoundgroup.c
index ae347fc..e7e40b7 100644
--- a/engines/cryo/clsoundgroup.c
+++ b/engines/cryo/clsoundgroup.c
@@ -1,22 +1,19 @@
 #include "cryolib.h"
 
-soundgroup_t* CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode)
-{
+soundgroup_t *CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode) {
 	soundgroup_t *sg;
 	short i;
-	
-	sg = (soundgroup_t*)CLMemory_Alloc(sizeof(*sg));
-	if(numSounds < CL_MAX_SOUNDS)
+
+	sg = (soundgroup_t *)CLMemory_Alloc(sizeof(*sg));
+	if (numSounds < CL_MAX_SOUNDS)
 		sg->numSounds = numSounds;
-	else
-	{
+	else {
 		__libError = -3;
 		__osError = 0;
 		CLCheckError();
 		sg->numSounds = CL_MAX_SOUNDS;
 	}
-	for(i = 0;i < sg->numSounds;i++)
-	{
+	for (i = 0; i < sg->numSounds; i++) {
 		sound_t *sound = CLSoundRaw_New(arg4, rate, sampleSize, mode);
 		sg->sound[i] = sound;
 		sound->ff_1A = arg4;
@@ -24,73 +21,65 @@ soundgroup_t* CLSoundGroup_New(short numSounds, short arg4, short sampleSize, fl
 	sg->soundIndex = 0;
 	sg->playIndex = 0;
 	sg->ff_106 = 1;
-	
+
 	return sg;
 }
 
-void CLSoundGroup_Free(soundgroup_t *sg)
-{
+void CLSoundGroup_Free(soundgroup_t *sg) {
 	short i;
-	for(i = 0;i < sg->numSounds;i++)
+	for (i = 0; i < sg->numSounds; i++)
 		CLSoundRaw_Free(sg->sound[i]);
 	CLMemory_Free(sg);
 }
 
-void CLSoundGroup_Reverse16All(soundgroup_t *sg)
-{
+void CLSoundGroup_Reverse16All(soundgroup_t *sg) {
 	short i;
-	for(i = 0;i < sg->numSounds;i++)
+	for (i = 0; i < sg->numSounds; i++)
 		sg->sound[i]->reversed = 1;
 }
 
-void* CLSoundGroup_GetNextBuffer(soundgroup_t *sg)
-{
+void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg) {
 	sound_t *sound = sg->sound[sg->soundIndex];
-	if(sg->ff_106)
-		while(sound->locked) ;
-	return ((char*)(*sound->sndHandle)) + sound->headerLen;
+	if (sg->ff_106)
+		while (sound->locked) ;
+	return ((char *)(*sound->sndHandle)) + sound->headerLen;
 }
 
-short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned)
-{
+short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned) {
 	sound_t *sound = sg->sound[sg->soundIndex];
-	if(sg->ff_106)
-		while(sound->locked) ;
-	else
-		if(sound->locked)
-			return 0;
-	sound->buffer = (char*)buffer;
+	if (sg->ff_106)
+		while (sound->locked) ;
+	else if (sound->locked)
+		return 0;
+	sound->buffer = (char *)buffer;
 	CLSound_SetLength(sound, length);
 	sound->length = length;
 //	if(sound->reversed && sound->sampleSize == 16)
 //		ReverseBlock16(buffer, length);
 //	if(isSigned)
 //		CLSound_Signed2NonSigned(buffer, length);
-	if(sg->soundIndex == sg->numSounds - 1)
+	if (sg->soundIndex == sg->numSounds - 1)
 		sg->soundIndex = 0;
 	else
 		sg->soundIndex++;
-		
+
 	return 1;
 }
 
-short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned)
-{
+short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned) {
 	void *buffer;
 	sound_t *sound = sg->sound[sg->soundIndex];
-	if(length >= sound->ff_1A)
-	{
+	if (length >= sound->ff_1A) {
 		__libError = -10;
 		__osError = 0;
 		CLCheckError();
 	}
-	if(sg->ff_106)
-		while(sound->locked) ;
-	else
-		if(sound->locked)
-			return 0;
-	buffer = ((char*)(*sound->sndHandle)) + sound->headerLen;
-	sound->buffer = (char*)buffer;
+	if (sg->ff_106)
+		while (sound->locked) ;
+	else if (sound->locked)
+		return 0;
+	buffer = ((char *)(*sound->sndHandle)) + sound->headerLen;
+	sound->buffer = (char *)buffer;
 	memcpy(buffer, data, length);
 	CLSound_SetLength(sound, length);
 	sound->length = length;
@@ -98,7 +87,7 @@ short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSi
 //		ReverseBlock16(buffer, length);
 //	if(isSigned)
 //		CLSound_Signed2NonSigned(buffer, length);
-	if(sg->soundIndex == sg->numSounds - 1)
+	if (sg->soundIndex == sg->numSounds - 1)
 		sg->soundIndex = 0;
 	else
 		sg->soundIndex++;
@@ -106,12 +95,11 @@ short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSi
 	return 1;
 }
 
-void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch)
-{
+void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch) {
 	CLSoundChannel_Play(ch, sg->sound[sg->playIndex]);
-	if(sg->playIndex == sg->numSounds - 1)
+	if (sg->playIndex == sg->numSounds - 1)
 		sg->playIndex = 0;
 	else
 		sg->playIndex++;
-	
+
 }
diff --git a/engines/cryo/cryo.cpp b/engines/cryo/cryo.cpp
index 425b055..9eb22b6 100644
--- a/engines/cryo/cryo.cpp
+++ b/engines/cryo/cryo.cpp
@@ -1,5 +1,5 @@
 #include "common/scummsys.h"
- 
+
 #include "common/config-manager.h"
 #include "common/debug.h"
 #include "common/debug-channels.h"
@@ -11,10 +11,10 @@
 //#include "common/timer.h"
 
 #include "engines/util.h"
- 
+
 #include "cryo/cryo.h"
 #include "cryo/eden.h"
- 
+
 namespace Cryo {
 
 CryoEngine *g_ed = 0;
@@ -23,36 +23,36 @@ CryoEngine::CryoEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engin
 	// Put your engine in a sane state, but do nothing big yet;
 	// in particular, do not load data from files; rather, if you
 	// need to do such things, do them from run().
- 
+
 	// Do not initialize graphics here
 	// Do not initialize audio devices here
- 
+
 	// However this is the place to specify all default directories
 //	const Common::FSNode gameDataDir(ConfMan.get("path"));
 //	SearchMan.addSubDirectoryMatching(gameDataDir, "sound");
- 
+
 	// Here is the right place to set up the engine specific debug channels
 	DebugMan.addDebugChannel(kCryoDebugExample, "example", "this is just an example for a engine specific debug channel");
 	DebugMan.addDebugChannel(kCryoDebugExample2, "example2", "also an example");
- 
+
 	// Don't forget to register your random source
 	_rnd = new Common::RandomSource("cryo");
- 
+
 	debug("CryoEngine::CryoEngine");
 
 	g_ed = this;
 }
- 
+
 CryoEngine::~CryoEngine() {
 	debug("CryoEngine::~CryoEngine");
- 
+
 	// Dispose your resources here
 	delete _rnd;
- 
+
 	// Remove all of our debug levels here
 	DebugMan.clearAllDebugChannels();
 }
- 
+
 Common::Error CryoEngine::run() {
 	// Initialize graphics using following:
 	initGraphics(320, 200, false);
@@ -60,22 +60,22 @@ Common::Error CryoEngine::run() {
 
 	// Create debugger console. It requires GFX to be initialized
 	_console = new Console(this);
- 
+
 	// Additional setup.
 	debug("CryoEngine::init");
- 
+
 	// Your main even loop should be (invoked from) here.
 	debug("CryoEngine::go: Hello, World!");
- 
+
 	// This test will show up if -d1 and --debugflags=example are specified on the commandline
 	debugC(1, kCryoDebugExample, "Example debug call");
- 
+
 	// This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline
 	debugC(3, kCryoDebugExample | kCryoDebugExample2, "Example debug call two");
- 
+
 	game.main();
 
 	return Common::kNoError;
 }
- 
+
 } // End of namespace Cryo
diff --git a/engines/cryo/cryo.h b/engines/cryo/cryo.h
index 010e9f0..1e3acb9 100644
--- a/engines/cryo/cryo.h
+++ b/engines/cryo/cryo.h
@@ -3,7 +3,7 @@
 
 #include "common/scummsys.h"
 #include "common/config-manager.h"
-#include "engines/advancedDetector.h"
+#include "engines/advancedDetector.h"
 #include "common/debug.h"
 #include "common/debug-channels.h"
 #include "common/error.h"
@@ -13,19 +13,19 @@
 #include "graphics/surface.h"
 #include "graphics/screen.h"
 #include "cryo/eden.h"
- 
+
 namespace Cryo {
- 
+
 class Console;
- 
+
 // our engine debug channels
 enum {
 	kCryoDebugExample = 1 << 0,
 	kCryoDebugExample2 = 1 << 1
-	// next new channel must be 1 << 2 (4)
-	// the current limitation is 32 debug channels (1 << 31 is the last one)
+	                     // next new channel must be 1 << 2 (4)
+	                     // the current limitation is 32 debug channels (1 << 31 is the last one)
 };
- 
+
 class CryoEngine : public Engine {
 public:
 	CryoEngine(OSystem *syst, const ADGameDescription *gameDesc);
@@ -56,7 +56,7 @@ public:
 	Console(CryoEngine *vm) {}
 	virtual ~Console(void) {}
 };
- 
+
 } // End of namespace Cryo
- 
+
 #endif
diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h
index ff3642b..4c9a202 100644
--- a/engines/cryo/defs.h
+++ b/engines/cryo/defs.h
@@ -7,17 +7,17 @@
 /*
 static inline void* AGetElem(unsigned char *arr, short index)
 {
-	unsigned char *p = arr + num * 2;
-	unsigned char o0 = *p++;
-	unsigned char o1 = *p++;
-	unsigned short ofs = (o1 << 8) | o0;
-	return arr + ofs;
+    unsigned char *p = arr + num * 2;
+    unsigned char o0 = *p++;
+    unsigned char o1 = *p++;
+    unsigned short ofs = (o1 << 8) | o0;
+    return arr + ofs;
 }
 */
 
 ///////////////// Game defs
 
-#define FONT_HEIGHT	9
+#define FONT_HEIGHT 9
 
 
 /*
@@ -40,7 +40,8 @@ enum Phases {
 	phNewGame = 0
 };
 
-namespace Areas { enum Areas {
+namespace Areas {
+enum Areas {
 	arMo = 1,
 	arTausCave,
 	arChamaar,
@@ -53,7 +54,8 @@ namespace Areas { enum Areas {
 	arEmbalmersCave,
 	arWhiteArch,
 	arMoorkusLair
-}; };
+};
+};
 
 #define MKRM(a,l) (((a) << 8) | (l))
 
@@ -63,22 +65,22 @@ enum OBJECT {
 	OBJ_2,
 	OBJ_3,
 	OBJ_4,
-	OBJ_PRISME,	// 5
+	OBJ_PRISME, // 5
 	OBJ_6,
 	OBJ_7,
-	OBJ_OEUF,	// 8
+	OBJ_OEUF,   // 8
 	OBJ_9,
 	OBJ_10,
-	OBJ_CHAMPB,	// 11
-	OBJ_CHAMPM,	// 12
-	OBJ_COUTEAU,	// 13
-	OBJ_NIDV,	// 14
-	OBJ_NIDO,	// 15
-	OBJ_OR,		// 16
+	OBJ_CHAMPB, // 11
+	OBJ_CHAMPM, // 12
+	OBJ_COUTEAU,    // 13
+	OBJ_NIDV,   // 14
+	OBJ_NIDO,   // 15
+	OBJ_OR,     // 16
 	OBJ_17,
 	OBJ_18,
-	OBJ_SOLEIL,	// 19
-	OBJ_CORNE,	// 20
+	OBJ_SOLEIL, // 19
+	OBJ_CORNE,  // 20
 	OBJ_21,
 	OBJ_22,
 	OBJ_23,
@@ -94,152 +96,157 @@ enum OBJECT {
 	OBJ_33,
 	OBJ_34,
 	OBJ_35,
-	OBJ_36,		// 36 is 1st plaque, 6 total
+	OBJ_36,     // 36 is 1st plaque, 6 total
 	OBJ_37,
-	OBJ_PLAQUE,	// 38
+	OBJ_PLAQUE, // 38
 	OBJ_39,
 	OBJ_40,
 	OBJ_41,
 };
 
-namespace Objects { enum Objects {
+namespace Objects {
+enum Objects {
 	obNone,
 	obWayStone,
 	obShell,
 	obTalisman,
 	obTooth,
-	obPrism,	// 5
+	obPrism,    // 5
 	obFlute,
 	obApple,
-	obEgg,		// 8
+	obEgg,      // 8
 	obRoot,
 	obUnused10,
-	obShroom,	// 11
-	obBadShroom,	// 12
-	obKnife,	// 13
-	obNest,	// 14
-	obFullNest,	// 15
-	obGold,		// 16
+	obShroom,   // 11
+	obBadShroom,    // 12
+	obKnife,    // 13
+	obNest, // 14
+	obFullNest, // 15
+	obGold,     // 16
 	obMoonStone,
 	obBag,
-	obSunStone,	// 19
-	obHorn,	// 20
+	obSunStone, // 19
+	obHorn, // 20
 	obSword,
 
 	obMaskOfDeath,
 	obMaskOfBonding,
 	obMaskOfBirth,
 
-	obEyeInTheStorm,	// 25
+	obEyeInTheStorm,    // 25
 	obSkyHammer,
 	obFireInTheClouds,
 	obWithinAndWithout,
 	obEyeInTheCyclone,
 	obRiverThatWinds,
 
-	obTrumpet,		// 31
+	obTrumpet,      // 31
 	obUnused32,
 	obDrum,
 	obUnused34,
 	obUnused35,
 	obRing,
 
-	obTablet1,		// 37 is 1st plaque, 6 total
+	obTablet1,      // 37 is 1st plaque, 6 total
 	obTablet2,
-	obTablet3,	// 39
+	obTablet3,  // 39
 	obTablet4,
 	obTablet5,
 	obTablet6
-}; };
+};
+};
 
 enum PERSO {
 	PER_ROI = 0,
-	PER_DINA,		// 0x12
-	PER_THOO,		// 0x24
-	PER_MONK,		// 0x36
-	PER_BOURREAU,	// 0x48
-	PER_MESSAGER,	// 0x5A
-	PER_MANGO,		// 0x6C
-	PER_EVE,		// 0x7E
-	PER_AZIA,		// 0x90
-	PER_MAMMI,		// 0xA2
-	PER_MAMMI_1,	// 0xB4
-	PER_MAMMI_2,	// 0xC6
-	PER_MAMMI_3,	// 0xD8
-	PER_MAMMI_4,	// 0xEA
-	PER_MAMMI_5,	// 0xFC
-	PER_MAMMI_6,	// 0x10E
-	PER_BAMBOO,		// 0x120
-	PER_KABUKA,		// 0x132
-	PER_GARDES,		// 0x144
-	PER_UNKN_156,	// 0x156
-	PER_FISHER,		// 0x168
-	PER_MORKUS,		// 0x17A
-	PER_UNKN_18C,	// 0x18C
-	PER_UNKN_19E,	// 0x19E
-	PER_UNKN_1B0,	// 0x1B0
-	PER_UNKN_1C2,	// 0x1C2
-	PER_UNKN_1D4,	// 0x1D4
-	PER_UNKN_1E6,	// 0x1E6
-	PER_UNKN_1F8,	// 0x1F8
-	PER_UNKN_20A,	// 0x20A
-	PER_UNKN_21C,	// 0x21C
-	PER_UNKN_22E,	// 0x22E
-	PER_UNKN_240,	// 0x240
-	PER_UNKN_252,	// 0x252
-	PER_UNKN_264,	// 0x264
-	PER_UNKN_276,	// 0x276
-	PER_UNKN_288,	// 0x288
-	PER_UNKN_29A,	// 0x29A
-	PER_UNKN_2AC,	// 0x2AC
-	PER_UNKN_2BE,	// 0x2BE
-	PER_UNKN_2D0,	// 0x2D0
-	PER_UNKN_2E2,	// 0x2E2
-	PER_UNKN_2F4,	// 0x2F4
-	PER_UNKN_306,	// 0x306
-	PER_UNKN_318,	// 0x318
-	PER_UNKN_32A,	// 0x32A
-	PER_UNKN_33C,	// 0x33C
-	PER_UNKN_34E,	// 0x34E
-	PER_UNKN_360,	// 0x360
-	PER_UNKN_372,	// 0x372
-	PER_UNKN_384,	// 0x384
-	PER_UNKN_396,	// 0x396
-	PER_UNKN_3A8,	// 0x3A8
-	PER_UNKN_3BA,	// 0x3BA
-	PER_UNKN_3CC,	// 0x3CC
-	PER_UNKN_3DE,	// 0x3DE
-	PER_UNKN_3F0,	// 0x3F0
-	PER_UNKN_402	// 0x402
-};
-
-namespace PersonId { enum PersonId {
-	pidGregor = 0,							// The King
-	pidDina,								// Pink dino
-	pidTau,									// Late grandpa
-	pidMonk,								// Old wizard
-	pidJabber,								// Executioner
-	pidEloi,								// Evergreen ptero
-	pidMungo,								// Dina's husband
-	pidEve,									// Blonde girl
-	pidShazia,								// Big boobs sis
-	pidLeadersBegin,						// 9
-	pidChongOfChamaar = pidLeadersBegin,	// Dogface
-	pidKommalaOfKoto,						// Clones
-	pidUlanOfUlele,							// Shaman
-	pidCabukaOfCantura,						// Stone people
-	pidMarindaOfEmbalmers,					// Gods
-	pidFuggOfTamara,						// Boar-like
-	pidThugg,								// Bodyguard
-	pidNarrator,							// 16, Old Eloi, also BGM
-	pidNarrim,								// Sea snake
-	pidMorkus,								// Vicious tyran
-	pidDinosaur,							// different species of friendly dino
-	pidEnemy								// different species of enemy dino
-}; };
+	PER_DINA,       // 0x12
+	PER_THOO,       // 0x24
+	PER_MONK,       // 0x36
+	PER_BOURREAU,   // 0x48
+	PER_MESSAGER,   // 0x5A
+	PER_MANGO,      // 0x6C
+	PER_EVE,        // 0x7E
+	PER_AZIA,       // 0x90
+	PER_MAMMI,      // 0xA2
+	PER_MAMMI_1,    // 0xB4
+	PER_MAMMI_2,    // 0xC6
+	PER_MAMMI_3,    // 0xD8
+	PER_MAMMI_4,    // 0xEA
+	PER_MAMMI_5,    // 0xFC
+	PER_MAMMI_6,    // 0x10E
+	PER_BAMBOO,     // 0x120
+	PER_KABUKA,     // 0x132
+	PER_GARDES,     // 0x144
+	PER_UNKN_156,   // 0x156
+	PER_FISHER,     // 0x168
+	PER_MORKUS,     // 0x17A
+	PER_UNKN_18C,   // 0x18C
+	PER_UNKN_19E,   // 0x19E
+	PER_UNKN_1B0,   // 0x1B0
+	PER_UNKN_1C2,   // 0x1C2
+	PER_UNKN_1D4,   // 0x1D4
+	PER_UNKN_1E6,   // 0x1E6
+	PER_UNKN_1F8,   // 0x1F8
+	PER_UNKN_20A,   // 0x20A
+	PER_UNKN_21C,   // 0x21C
+	PER_UNKN_22E,   // 0x22E
+	PER_UNKN_240,   // 0x240
+	PER_UNKN_252,   // 0x252
+	PER_UNKN_264,   // 0x264
+	PER_UNKN_276,   // 0x276
+	PER_UNKN_288,   // 0x288
+	PER_UNKN_29A,   // 0x29A
+	PER_UNKN_2AC,   // 0x2AC
+	PER_UNKN_2BE,   // 0x2BE
+	PER_UNKN_2D0,   // 0x2D0
+	PER_UNKN_2E2,   // 0x2E2
+	PER_UNKN_2F4,   // 0x2F4
+	PER_UNKN_306,   // 0x306
+	PER_UNKN_318,   // 0x318
+	PER_UNKN_32A,   // 0x32A
+	PER_UNKN_33C,   // 0x33C
+	PER_UNKN_34E,   // 0x34E
+	PER_UNKN_360,   // 0x360
+	PER_UNKN_372,   // 0x372
+	PER_UNKN_384,   // 0x384
+	PER_UNKN_396,   // 0x396
+	PER_UNKN_3A8,   // 0x3A8
+	PER_UNKN_3BA,   // 0x3BA
+	PER_UNKN_3CC,   // 0x3CC
+	PER_UNKN_3DE,   // 0x3DE
+	PER_UNKN_3F0,   // 0x3F0
+	PER_UNKN_402    // 0x402
+};
+
+namespace PersonId {
+enum PersonId {
+	pidGregor = 0,                          // The King
+	pidDina,                                // Pink dino
+	pidTau,                                 // Late grandpa
+	pidMonk,                                // Old wizard
+	pidJabber,                              // Executioner
+	pidEloi,                                // Evergreen ptero
+	pidMungo,                               // Dina's husband
+	pidEve,                                 // Blonde girl
+	pidShazia,                              // Big boobs sis
+	pidLeadersBegin,                        // 9
+	pidChongOfChamaar = pidLeadersBegin,    // Dogface
+	pidKommalaOfKoto,                       // Clones
+	pidUlanOfUlele,                         // Shaman
+	pidCabukaOfCantura,                     // Stone people
+	pidMarindaOfEmbalmers,                  // Gods
+	pidFuggOfTamara,                        // Boar-like
+	pidThugg,                               // Bodyguard
+	pidNarrator,                            // 16, Old Eloi, also BGM
+	pidNarrim,                              // Sea snake
+	pidMorkus,                              // Vicious tyran
+	pidDinosaur,                            // different species of friendly dino
+	pidEnemy                                // different species of enemy dino
+};
+};
 
 // person in room mask bits
-namespace PersonMask { enum PersonMask {
+namespace PersonMask {
+enum PersonMask {
 	pmGregor = 1,
 	pmDina   = 2,
 	pmTau    = 4,
@@ -249,15 +256,17 @@ namespace PersonMask { enum PersonMask {
 	pmMungo  = 0x40,
 	pmEve    = 0x80,
 	pmShazia = 0x100,
-	pmLeader = 0x200,	// valley tribe leader
+	pmLeader = 0x200,   // valley tribe leader
 	pmThugg  = 0x400,
-	pmQuest  = 0x800,	// special quest person
+	pmQuest  = 0x800,   // special quest person
 	pmDino   = 0x1000,
 	pmEnemy  = 0x2000,
 	pmMorkus = 0x4000
-}; };
+};
+};
 
-namespace PersonFlags { enum PersonFlags {
+namespace PersonFlags {
+enum PersonFlags {
 	pfType0 = 0,
 	pftTyrann,
 	pfType2,
@@ -279,116 +288,124 @@ namespace PersonFlags { enum PersonFlags {
 	pf20 = 0x20,
 	pfInParty = 0x40,
 	pf80 = 0x80
-}; };
+};
+};
 
 #pragma pack(push, 1)
 struct perso_t {
-unsigned short	roomNum;	// room this person currently in
-unsigned short	actionId;	// TODO: checkme
-unsigned short	party;		// party bit mask
-unsigned char	id;			// character
-unsigned char	flags;		// flags and kind
-unsigned char	roomBankIdx;// index in kPersoRoomBankTable for specific room banks
-unsigned char	bank;		// sprite bank
-unsigned short	items;		// inventory
-unsigned short	powers;		// obj of power bitmask
-unsigned char	targetLoc;	// For party member this is mini sprite index
-unsigned char	lastLoc;	// For party member this is mini sprite x offset
-unsigned char	speed;		// num ticks per step
-unsigned char	steps;		// current ticks
+	unsigned short  roomNum;    // room this person currently in
+	unsigned short  actionId;   // TODO: checkme
+	unsigned short  party;      // party bit mask
+	unsigned char   id;         // character
+	unsigned char   flags;      // flags and kind
+	unsigned char   roomBankIdx;// index in kPersoRoomBankTable for specific room banks
+	unsigned char   bank;       // sprite bank
+	unsigned short  items;      // inventory
+	unsigned short  powers;     // obj of power bitmask
+	unsigned char   targetLoc;  // For party member this is mini sprite index
+	unsigned char   lastLoc;    // For party member this is mini sprite x offset
+	unsigned char   speed;      // num ticks per step
+	unsigned char   steps;      // current ticks
 };
 typedef struct perso_t perso_t;
 
 struct phase_t {
-short			id;
-void			(EdenGameImpl::*disp)();
+	short           id;
+	void (EdenGameImpl::*disp)();
 };
 typedef struct phase_t phase_t;
 
-namespace ObjectFlags { enum ObjectFlags {
+namespace ObjectFlags {
+enum ObjectFlags {
 	ofFlag1 = 1,
-	ofInHands = 2		// Currently holding this object in hands
-}; };
+	ofInHands = 2       // Currently holding this object in hands
+};
+};
 
-#define MAX_OBJECTS	42
+#define MAX_OBJECTS 42
 struct object_t {
-unsigned char	id;
-unsigned char	flags;
-int				locations;		// index in kObjectLocations
-short			itemMask;
-short			powerMask;			// object of power bitmask
-short			count;
+	unsigned char   id;
+	unsigned char   flags;
+	int             locations;      // index in kObjectLocations
+	short           itemMask;
+	short           powerMask;          // object of power bitmask
+	short           count;
 };
 typedef struct object_t object_t;
 
-namespace DialogFlags { enum DialogFlags {
+namespace DialogFlags {
+enum DialogFlags {
 	df20 = 0x20,
 	dfRepeatable = 0x40,
 	dfSpoken = 0x80
-}; };
+};
+};
 
-namespace DialogType { enum DialogType {
+namespace DialogType {
+enum DialogType {
 	dtTalk = 0,
 	dtDinoAction,
 	dtDinoItem,
 	dtItem,
 	dtEvent,
-	dtInspect, 
+	dtInspect,
 	dtHint
-}; };
+};
+};
 
 struct dial_t {
-char		flags;			// 0-3 - action index, 4 - highest bit of contidion index, rest is DialogFlags
-char		condNumLow;		// condition index low bits
-char		textCondHiMask;	// 0-1 text index hi bits, 2-5 - perso mask num, 6-7 condition index hi bits
-char		textNumLow;		// text line index low bits
+	char        flags;          // 0-3 - action index, 4 - highest bit of contidion index, rest is DialogFlags
+	char        condNumLow;     // condition index low bits
+	char        textCondHiMask; // 0-1 text index hi bits, 2-5 - perso mask num, 6-7 condition index hi bits
+	char        textNumLow;     // text line index low bits
 };
 typedef struct dial_t dial_t;
 
 struct tape_t {
-short		textNum;
-perso_t		*perso;
-short		party;
-short		roomNum;
-short		bgBankNum;
-dial_t		*dialog;
+	short       textNum;
+	perso_t     *perso;
+	short       party;
+	short       roomNum;
+	short       bgBankNum;
+	dial_t      *dialog;
 };
 typedef struct tape_t tape_t;
 
-struct suiveur_t {		// Characters on Mirror screen
-char		id;			// character
-char		image;		// sprite number
-short		sx;
-short		sy;
-short		ex;
-short		ey;
-short		bank;
-short		ff_C;
-short		ff_E;
+struct suiveur_t {      // Characters on Mirror screen
+	char        id;         // character
+	char        image;      // sprite number
+	short       sx;
+	short       sy;
+	short       ex;
+	short       ey;
+	short       bank;
+	short       ff_C;
+	short       ff_E;
 };
 typedef struct suiveur_t suiveur_t;
 
 struct icon_t {
-short		sx;
-short		sy;
-short		ex;
-short		ey;
-unsigned short	cursor_id;			// & 0x8000 - inactive/hidden
-unsigned int	action_id;
-unsigned int	object_id;
+	short       sx;
+	short       sy;
+	short       ex;
+	short       ey;
+	unsigned short  cursor_id;          // & 0x8000 - inactive/hidden
+	unsigned int    action_id;
+	unsigned int    object_id;
 };
 typedef struct icon_t icon_t;
 
 struct goto_t {
-unsigned char	areaNum;	// target area
-unsigned char	curAreaNum;	// current area
-unsigned char	departVid;
-unsigned char	travelTime;		// time to skip while in travel
-unsigned char	arriveVid;
+	unsigned char   areaNum;    // target area
+	unsigned char   curAreaNum; // current area
+	unsigned char   departVid;
+	unsigned char   travelTime;     // time to skip while in travel
+	unsigned char   arriveVid;
 };
 typedef struct goto_t goto_t;
 
-namespace RoomFlags { enum RoomFlags {
+namespace RoomFlags {
+enum RoomFlags {
 	rf01 = 1,
 	rf02 = 2,
 	rf04 = 4,
@@ -397,22 +414,24 @@ namespace RoomFlags { enum RoomFlags {
 	rfHasCitadel = 0x20,
 	rf40 = 0x40,
 	rf80 = 0x80
-}; };
+};
+};
 
 struct room_t {
-unsigned char	ff_0;
-unsigned char	exits[4];	//TODO: signed?
-unsigned char	flags;
-unsigned short	bank;
-unsigned short	party;
-unsigned char	level;		// Citadel level
-unsigned char	video;
-unsigned char	location;
-unsigned char	background;	// bg/mirror image number (relative)
+	unsigned char   ff_0;
+	unsigned char   exits[4];   //TODO: signed?
+	unsigned char   flags;
+	unsigned short  bank;
+	unsigned short  party;
+	unsigned char   level;      // Citadel level
+	unsigned char   video;
+	unsigned char   location;
+	unsigned char   background; // bg/mirror image number (relative)
 };
 typedef struct room_t room_t;
 
-namespace AreaFlags { enum AreaFlags {
+namespace AreaFlags {
+enum AreaFlags {
 	afFlag1 = 1,
 	afFlag2 = 2,
 	afFlag4 = 4,
@@ -426,27 +445,31 @@ namespace AreaFlags { enum AreaFlags {
 
 	TyrannSighted = 0x4000,
 	afFlag8000 = 0x8000
-}; };
+};
+};
 
-namespace AreaType { enum AreaType {
+namespace AreaType {
+enum AreaType {
 	atCitadel = 1,
 	atValley = 2,
 	atCave = 3
-}; };
+};
+};
 
 struct area_t {
-unsigned char	num;
-unsigned char	type;
-unsigned short	flags;
-unsigned short	firstRoomIndex;
-unsigned char	citadelLevel;
-unsigned char	salNum;
-room_t			*citadelRoom;
-short			visitCount;
+	unsigned char   num;
+	unsigned char   type;
+	unsigned short  flags;
+	unsigned short  firstRoomIndex;
+	unsigned char   citadelLevel;
+	unsigned char   salNum;
+	room_t          *citadelRoom;
+	short           visitCount;
 };
 typedef struct area_t area_t;
 
-namespace ValleyNews { enum ValleyNews {
+namespace ValleyNews {
+enum ValleyNews {
 	vnAreaMask = 0xF,
 
 	vnTriceraptorsIn = 0x10,
@@ -459,9 +482,11 @@ namespace ValleyNews { enum ValleyNews {
 	vnFree = 0,
 	vnHidden = 0x80,
 	vnEnd = 0xFF
-}; };
+};
+};
 
-namespace DisplayFlags { enum DisplayFlags {
+namespace DisplayFlags {
+enum DisplayFlags {
 	dfFlag1 = 1,
 	dfFlag2 = 2,
 	dfMirror = 4,
@@ -470,34 +495,42 @@ namespace DisplayFlags { enum DisplayFlags {
 	dfPanable = 0x20,
 	dfFlag40 = 0x40,
 	dfFlag80 = 0x80
-}; };
+};
+};
 
-namespace DrawFlags { enum DrawFlags {
+namespace DrawFlags {
+enum DrawFlags {
 	drDrawInventory = 1,
 	drDrawFlag2 = 2,
 	drDrawTopScreen = 4,
 	drDrawFlag8 = 8,
 	drDrawMenu = 0x10,
 	drDrawFlag20 = 0x20
-}; };
+};
+};
 
-namespace MenuFlags { enum MenuFlags {
+namespace MenuFlags {
+enum MenuFlags {
 	mfFlag1 = 1,
 	mfFlag2 = 2,
 	mfFlag4 = 4,
 	mfFlag8 = 8,
 	mfFlag10 = 0x10
-}; };
+};
+};
 
-namespace MusicType { enum MusicType {	//TODO: same as DialogType?
+namespace MusicType {
+enum MusicType {  //TODO: same as DialogType?
 	mtDontChange = 0,
 	mtNormal = 1,
 	mt2 = 2,
 	mtEvent = 4,
 	mtFF = 0xFF
-}; };
+};
+};
 
-namespace EventType { enum EventType {
+namespace EventType {
+enum EventType {
 	etEvent1 = 1,
 	etEvent2 = 2,
 	etEvent3 = 3,
@@ -514,10 +547,12 @@ namespace EventType { enum EventType {
 	etEventF = 15,
 	etEvent10 = 16,
 	etEvent12 = 18,
-	etGotoArea = 0x80	// + area id
-}; };
+	etGotoArea = 0x80   // + area id
+};
+};
 
-namespace GameFlags { enum GameFlags {
+namespace GameFlags {
+enum GameFlags {
 	gfMummyOpened = 1,
 	gfFlag2 = 2,
 	gfFlag4 = 4,
@@ -534,194 +569,195 @@ namespace GameFlags { enum GameFlags {
 	gfFlag2000 = 0x2000,
 	gfFlag4000 = 0x4000,
 	gfFlag8000 = 0x8000
-}; };
+};
+};
 
 struct global_t {
-unsigned char	areaNum;
-unsigned char	areaVisitCount;
-unsigned char	menuItemIdLo;
-unsigned char	menuItemIdHi;	//TODO: pad?
-unsigned short	randomNumber;	//TODO: this is randomized in pc ver and used by some conds. always zero on mac
-unsigned short	gameTime;
-unsigned short	gameDays;
-unsigned short	chrono;
-unsigned short	eloiDepartureDay;
-unsigned short	roomNum;		// current room number
-unsigned short	newRoomNum;		// target room number selected on world map
-unsigned short	phaseNum;
-unsigned short	metPersonsMask1;
-unsigned short	party;
-unsigned short	partyOutside;
-unsigned short	metPersonsMask2;
-unsigned short	__UNUSED_1C;	//TODO: write-only?
-unsigned short	phaseActionsCount;
-unsigned short	curAreaFlags;
-unsigned short	curItemsMask;
-unsigned short	curPowersMask;
-unsigned short	curPersoItems;
-unsigned short	curPersoPowers;
-unsigned short	wonItemsMask;
-unsigned short	wonPowersMask;
-unsigned short	stepsToFindAppleFast;
-unsigned short	stepsToFindAppleNormal;
-unsigned short	roomPersoItems;	//TODO: write-only?
-unsigned short	roomPersoPowers;	//TODO: write-only?
-unsigned short	gameFlags;
-unsigned short	curVideoNum;
-unsigned short	morkusSpyVideoNum1;	//TODO: pad?
-unsigned short	morkusSpyVideoNum2;	//TODO: pad?
-unsigned short	morkusSpyVideoNum3;	//TODO: pad?
-unsigned short	morkusSpyVideoNum4;	//TODO: pad?
-unsigned char	newMusicType;
-unsigned char	ff_43;
-unsigned char	videoSubtitleIndex;
-unsigned char	partyInstruments;	// &1 - Bell for Monk, &2 - Drum for Thugg
-unsigned char	monkGotRing;
-unsigned char	chrono_on;
-unsigned char	curRoomFlags;
-unsigned char	endGameFlag;
-unsigned char	last_info;
-unsigned char	autoDialog;
-unsigned char	worldTyrannSighted;
-unsigned char	ff_4D;
-unsigned char	ff_4E;
-unsigned char	worldGaveGold;
-unsigned char	worldHasTriceraptors;
-unsigned char	worldHasVelociraptors;
-unsigned char	worldHasTyrann;
-unsigned char	ff_53;
-unsigned char	ff_54;
-unsigned char	ff_55;	//TODO: pad?
-unsigned char	ff_56;
-unsigned char	textToken1;
-unsigned char	textToken2;	//TODO: pad?
-unsigned char	eloiHaveNews;
-unsigned char	dialogFlags;
-unsigned char	curAreaType;
-unsigned char	curCitadelLevel;
-unsigned char	newLocation;
-unsigned char	prevLocation;
-unsigned char	curPersoFlags;
-unsigned char	ff_60;
-unsigned char	eventType;
-unsigned char	ff_62;	//TODO: pad?
-unsigned char	curObjectId;
-unsigned char	curObjectFlags;
-unsigned char	ff_65;	//TODO: pad?
-unsigned char	roomPersoType;
-unsigned char	roomPersoFlags;
-unsigned char	narratorSequence;
-unsigned char	ff_69;
-unsigned char	ff_6A;
-unsigned char	fresqNumber;
-unsigned char	ff_6C;	//TODO: pad?
-unsigned char	ff_6D;	//TODO: pad?
-unsigned char	labyrinthDirections;
-unsigned char	labyrinthRoom;
-void			*__UNUSED_70;	//TODO: pad?
-dial_t			*dialog_ptr;
-tape_t			*tape_ptr;
-dial_t			*next_dialog_ptr;
-dial_t			*narrator_dialog_ptr;
-dial_t			*last_dialog_ptr;
-icon_t			*nextRoomIcon;
-unsigned char	*phraseBufferPtr;
-unsigned char	*__UNUSED_90;	//TODO: write-only?
-unsigned char	*__UNUSED_94;	//TODO: write-only?
-room_t			*room_ptr;
-area_t			*area_ptr;
-area_t			*last_area_ptr;
-area_t			*cur_area_ptr;
-room_t			*cita_area_firstRoom;
-perso_t			*perso_ptr;
-perso_t			*room_perso;
-unsigned char	last_info_idx;
-unsigned char	next_info_idx;
-unsigned char	*persoSpritePtr;
-unsigned char	*persoSpritePtr2;
-unsigned char	*curPersoAnimPtr;
-unsigned char	*ff_C2;	//TODO: image desc arr
-short			iconsIndex;
-short			curObjectCursor;	// TODO: useless?
-short			ff_CA;
-short			__UNUSED_CC;		//TODO: unused/pad
-short			perso_img_bank;	//TODO: unsigned?
-unsigned short	roomImgBank;
-unsigned short	persoBackgroundBankIdx;
-unsigned short	ff_D4;	//TODO: unsigned?
-unsigned short	fresqWidth;
-unsigned short	fresqImgBank;
-unsigned short	ff_DA;	//TODO: pad?
-unsigned short	ff_DC;	//TODO: pad?
-unsigned short	room_x_base;
-unsigned short	ff_E0;	//TODO: pad?
-unsigned short	dialogType;
-unsigned short	ff_E4;	//TODO: pad?
-unsigned short	currentMusicNum;
-short			textNum;
-unsigned short	travelTime;
-unsigned short	ff_EC;	//TODO: pad?
-unsigned char	displayFlags;
-unsigned char	oldDisplayFlags;
-unsigned char	drawFlags;
-unsigned char	ff_F1;
-unsigned char	ff_F2;
-unsigned char	menuFlags;
-unsigned char	ff_F4;	//TODO: write-only?
-unsigned char	ff_F5;
-unsigned char	ff_F6;
-unsigned char	ff_F7;
-unsigned char	ff_F8;	//TODO: pad?
-unsigned char	ff_F9;	//TODO: pad?
-unsigned char	ff_FA;	//TODO: pad?
-unsigned char	animationFlags;
-unsigned char	__UNUSED_FC;	//TODO: pad?
-unsigned char	giveobj1;
-unsigned char	giveobj2;
-unsigned char	giveobj3;
-unsigned char	ff_100;
-unsigned char	roomVidNum;
-unsigned char	ff_102;
-unsigned char	ff_103;
-unsigned char	roomBgBankNum;
-unsigned char	valleyVidNum;
-unsigned char	updatePaletteFlag;
-unsigned char	inventoryScrollPos;
-unsigned char	obj_count;
-unsigned char	ff_109;	//TODO: write-only?
-unsigned char	textBankIndex;
-unsigned char	pref_language;
-unsigned char	pref_10C[2];	//TODO: volume
-unsigned char	pref_10E[2];	// -//-
-unsigned char	pref_110[2];	// -//-
-unsigned char	cita_area_num;
-unsigned char	ff_113;
-unsigned char	lastSalNum;
-unsigned char	save_end;
-short			textWidthLimit;
-unsigned char	numGiveObjs;
-unsigned char	ff_119;		// unused
+	unsigned char   areaNum;
+	unsigned char   areaVisitCount;
+	unsigned char   menuItemIdLo;
+	unsigned char   menuItemIdHi;   //TODO: pad?
+	unsigned short  randomNumber;   //TODO: this is randomized in pc ver and used by some conds. always zero on mac
+	unsigned short  gameTime;
+	unsigned short  gameDays;
+	unsigned short  chrono;
+	unsigned short  eloiDepartureDay;
+	unsigned short  roomNum;        // current room number
+	unsigned short  newRoomNum;     // target room number selected on world map
+	unsigned short  phaseNum;
+	unsigned short  metPersonsMask1;
+	unsigned short  party;
+	unsigned short  partyOutside;
+	unsigned short  metPersonsMask2;
+	unsigned short  __UNUSED_1C;    //TODO: write-only?
+	unsigned short  phaseActionsCount;
+	unsigned short  curAreaFlags;
+	unsigned short  curItemsMask;
+	unsigned short  curPowersMask;
+	unsigned short  curPersoItems;
+	unsigned short  curPersoPowers;
+	unsigned short  wonItemsMask;
+	unsigned short  wonPowersMask;
+	unsigned short  stepsToFindAppleFast;
+	unsigned short  stepsToFindAppleNormal;
+	unsigned short  roomPersoItems; //TODO: write-only?
+	unsigned short  roomPersoPowers;    //TODO: write-only?
+	unsigned short  gameFlags;
+	unsigned short  curVideoNum;
+	unsigned short  morkusSpyVideoNum1; //TODO: pad?
+	unsigned short  morkusSpyVideoNum2; //TODO: pad?
+	unsigned short  morkusSpyVideoNum3; //TODO: pad?
+	unsigned short  morkusSpyVideoNum4; //TODO: pad?
+	unsigned char   newMusicType;
+	unsigned char   ff_43;
+	unsigned char   videoSubtitleIndex;
+	unsigned char   partyInstruments;   // &1 - Bell for Monk, &2 - Drum for Thugg
+	unsigned char   monkGotRing;
+	unsigned char   chrono_on;
+	unsigned char   curRoomFlags;
+	unsigned char   endGameFlag;
+	unsigned char   last_info;
+	unsigned char   autoDialog;
+	unsigned char   worldTyrannSighted;
+	unsigned char   ff_4D;
+	unsigned char   ff_4E;
+	unsigned char   worldGaveGold;
+	unsigned char   worldHasTriceraptors;
+	unsigned char   worldHasVelociraptors;
+	unsigned char   worldHasTyrann;
+	unsigned char   ff_53;
+	unsigned char   ff_54;
+	unsigned char   ff_55;  //TODO: pad?
+	unsigned char   ff_56;
+	unsigned char   textToken1;
+	unsigned char   textToken2; //TODO: pad?
+	unsigned char   eloiHaveNews;
+	unsigned char   dialogFlags;
+	unsigned char   curAreaType;
+	unsigned char   curCitadelLevel;
+	unsigned char   newLocation;
+	unsigned char   prevLocation;
+	unsigned char   curPersoFlags;
+	unsigned char   ff_60;
+	unsigned char   eventType;
+	unsigned char   ff_62;  //TODO: pad?
+	unsigned char   curObjectId;
+	unsigned char   curObjectFlags;
+	unsigned char   ff_65;  //TODO: pad?
+	unsigned char   roomPersoType;
+	unsigned char   roomPersoFlags;
+	unsigned char   narratorSequence;
+	unsigned char   ff_69;
+	unsigned char   ff_6A;
+	unsigned char   fresqNumber;
+	unsigned char   ff_6C;  //TODO: pad?
+	unsigned char   ff_6D;  //TODO: pad?
+	unsigned char   labyrinthDirections;
+	unsigned char   labyrinthRoom;
+	void            *__UNUSED_70;   //TODO: pad?
+	dial_t          *dialog_ptr;
+	tape_t          *tape_ptr;
+	dial_t          *next_dialog_ptr;
+	dial_t          *narrator_dialog_ptr;
+	dial_t          *last_dialog_ptr;
+	icon_t          *nextRoomIcon;
+	unsigned char   *phraseBufferPtr;
+	unsigned char   *__UNUSED_90;   //TODO: write-only?
+	unsigned char   *__UNUSED_94;   //TODO: write-only?
+	room_t          *room_ptr;
+	area_t          *area_ptr;
+	area_t          *last_area_ptr;
+	area_t          *cur_area_ptr;
+	room_t          *cita_area_firstRoom;
+	perso_t         *perso_ptr;
+	perso_t         *room_perso;
+	unsigned char   last_info_idx;
+	unsigned char   next_info_idx;
+	unsigned char   *persoSpritePtr;
+	unsigned char   *persoSpritePtr2;
+	unsigned char   *curPersoAnimPtr;
+	unsigned char   *ff_C2; //TODO: image desc arr
+	short           iconsIndex;
+	short           curObjectCursor;    // TODO: useless?
+	short           ff_CA;
+	short           __UNUSED_CC;        //TODO: unused/pad
+	short           perso_img_bank; //TODO: unsigned?
+	unsigned short  roomImgBank;
+	unsigned short  persoBackgroundBankIdx;
+	unsigned short  ff_D4;  //TODO: unsigned?
+	unsigned short  fresqWidth;
+	unsigned short  fresqImgBank;
+	unsigned short  ff_DA;  //TODO: pad?
+	unsigned short  ff_DC;  //TODO: pad?
+	unsigned short  room_x_base;
+	unsigned short  ff_E0;  //TODO: pad?
+	unsigned short  dialogType;
+	unsigned short  ff_E4;  //TODO: pad?
+	unsigned short  currentMusicNum;
+	short           textNum;
+	unsigned short  travelTime;
+	unsigned short  ff_EC;  //TODO: pad?
+	unsigned char   displayFlags;
+	unsigned char   oldDisplayFlags;
+	unsigned char   drawFlags;
+	unsigned char   ff_F1;
+	unsigned char   ff_F2;
+	unsigned char   menuFlags;
+	unsigned char   ff_F4;  //TODO: write-only?
+	unsigned char   ff_F5;
+	unsigned char   ff_F6;
+	unsigned char   ff_F7;
+	unsigned char   ff_F8;  //TODO: pad?
+	unsigned char   ff_F9;  //TODO: pad?
+	unsigned char   ff_FA;  //TODO: pad?
+	unsigned char   animationFlags;
+	unsigned char   __UNUSED_FC;    //TODO: pad?
+	unsigned char   giveobj1;
+	unsigned char   giveobj2;
+	unsigned char   giveobj3;
+	unsigned char   ff_100;
+	unsigned char   roomVidNum;
+	unsigned char   ff_102;
+	unsigned char   ff_103;
+	unsigned char   roomBgBankNum;
+	unsigned char   valleyVidNum;
+	unsigned char   updatePaletteFlag;
+	unsigned char   inventoryScrollPos;
+	unsigned char   obj_count;
+	unsigned char   ff_109; //TODO: write-only?
+	unsigned char   textBankIndex;
+	unsigned char   pref_language;
+	unsigned char   pref_10C[2];    //TODO: volume
+	unsigned char   pref_10E[2];    // -//-
+	unsigned char   pref_110[2];    // -//-
+	unsigned char   cita_area_num;
+	unsigned char   ff_113;
+	unsigned char   lastSalNum;
+	unsigned char   save_end;
+	short           textWidthLimit;
+	unsigned char   numGiveObjs;
+	unsigned char   ff_119;     // unused
 };
 typedef struct global_t global_t;
 
 struct pakfile_t {
-char			name[16];
-long			size;
-long			offs;
-char			flag;
+	char            name[16];
+	long            size;
+	long            offs;
+	char            flag;
 };
 typedef struct pakfile_t pakfile_t;
 
 struct pak_t {
-unsigned short	count;
-pakfile_t		files[10];
+	unsigned short  count;
+	pakfile_t       files[10];
 };
 typedef struct pak_t pak_t;
 #pragma pack(pop)
 
 struct cita_t {
-short	ff_0;
-short	ff_2[8 * 2];
+	short   ff_0;
+	short   ff_2[8 * 2];
 };
 typedef struct cita_t cita_t;
 
@@ -761,24 +797,24 @@ enum {
 	LAB_W
 };
 
-#define LAB(toCrypt, toThrone)	\
+#define LAB(toCrypt, toThrone)  \
 	(((LAB_##toCrypt) << 4) | (LAB_##toThrone))
 
 unsigned char kLabyrinthPath[] = {
 // each nibble tells wich direction to choose to exit the labyrinth
-0x11, 0x11, 0x11, 0x22, 0x33, 0x55, 0x25, 0x44, 0x25, 0x11, 0x11, 0x11,
-0x11, 0x35, 0x55, 0x45, 0x45, 0x44, 0x44, 0x34, 0x44, 0x34, 0x32, 0x52,
-0x33, 0x23, 0x24, 0x44, 0x24, 0x22, 0x54, 0x22, 0x54, 0x54, 0x44, 0x22,
-0x22, 0x42, 0x45, 0x22, 0x42, 0x45, 0x35, 0x11, 0x44, 0x34, 0x52, 0x11,
-0x44, 0x32, 0x55, 0x11, 0x11, 0x33, 0x11, 0x11, 0x53, 0x11, 0x11, 0x53,
-0x54, 0x24, 0x11, 0x22, 0x25, 0x33, 0x53, 0x54, 0x23, 0x44
+	0x11, 0x11, 0x11, 0x22, 0x33, 0x55, 0x25, 0x44, 0x25, 0x11, 0x11, 0x11,
+	0x11, 0x35, 0x55, 0x45, 0x45, 0x44, 0x44, 0x34, 0x44, 0x34, 0x32, 0x52,
+	0x33, 0x23, 0x24, 0x44, 0x24, 0x22, 0x54, 0x22, 0x54, 0x54, 0x44, 0x22,
+	0x22, 0x42, 0x45, 0x22, 0x42, 0x45, 0x35, 0x11, 0x44, 0x34, 0x52, 0x11,
+	0x44, 0x32, 0x55, 0x11, 0x11, 0x33, 0x11, 0x11, 0x53, 0x11, 0x11, 0x53,
+	0x54, 0x24, 0x11, 0x22, 0x25, 0x33, 0x53, 0x54, 0x23, 0x44
 };
 
 #undef LAB
 
 char kDinoSpeedForCitaLevel[16] = { 1, 2, 3, 4, 4, 5, 6, 7, 8, 9 };
 
-char kTabletView[] = {			//TODO: make as struct?
+char kTabletView[] = {          //TODO: make as struct?
 	// opposite tablet id, video id
 	Objects::obUnused10, 83,
 	Objects::obUnused10, 84,
@@ -791,25 +827,25 @@ char kTabletView[] = {			//TODO: make as struct?
 // special character backgrounds for specific rooms
 char kPersoRoomBankTable[] = {
 	// first entry is default bank, then pairs of [roomNum, bankNum], terminated by -1
-	 0,  3, 33, -1,
+	0,  3, 33, -1,
 	21, 17, 35, -1,
-	 0,  2, 36, -1,
+	0,  2, 36, -1,
 	22,  9, 38,  3, 39, -1,
 	23,  8, 40, -1,
-	 0,  3, 41,  7, 42, -1,
+	0,  3, 41,  7, 42, -1,
 	25, -1,
 	27, 17, 45, -1,
 	28, 26, 46, -1,
 	29, 51, 48, -1,
 	30, 53, 49, -1,
-	 0, 27, 50, -1,
+	0, 27, 50, -1,
 	32, 17, 51, -1,
 	52,  2, 52, -1,
 	-3,  3, -3, -1,
 	31, -1,
 	24,  6, 43, -1,
 	47, -1,
-	 0,  2, 64, -1, 
+	0,  2, 64, -1,
 	54,  3, 54, -1,
 	27, -1,
 	26, 17, 45, -1
@@ -954,13 +990,13 @@ goto_t gotos[] = {
 	(start), (end) | 0x8000
 
 short tab_2D24C[] = {
-	SUB_LINE( 68, 120 ),
-	 123, 32964,
-	 199, 33042,
-	 276, 33138,
-	 799, 33653,
-	 888, 33708,
-	 947, 33768,
+	SUB_LINE(68, 120),
+	123, 32964,
+	199, 33042,
+	276, 33138,
+	799, 33653,
+	888, 33708,
+	947, 33768,
 	1319, 34146,
 	1380, 34208,
 	1854, 34666,
@@ -974,7 +1010,7 @@ short tab_2D24C[] = {
 };
 
 short tab_2D28E[] = {
-	 99, 32923,
+	99, 32923,
 	157, 33024,
 	-1
 };
@@ -1009,53 +1045,53 @@ short tab_2D2C4[] = {
 #undef SUB_LINE
 
 object_t objects[] = {
-	//id,fl,loc,masklow,maskhi,ct 
-	{  1, 0,  3,      1,     0, 0},		// Eve's Way Stone
-	{  2, 0,  3,      2,     0, 0},		// Thau's Seashell
-	{  3, 0,  3,      4,     0, 0},		// Talisman of bravery
-	{  4, 0,  3,      8,     0, 0},		// An old tooth. Very old! Whoever lost it most certainly has no further use for it!
-	{  5, 0,  0,   0x10,     0, 0},		// Prism
-	{  6, 0,  3,      0,     0, 0},		// Flute
-	{  7, 0,  3, 0x4000,     0, 0},		// Apple
-	{  8, 0,  4, 0x1000,     0, 0},		// Egg of Destiny
-	{  9, 0,  3,  0x800,     0, 0},		// Root
-	{ 10, 0,  3,      0,     0, 0},		// ???
-	{ 11, 0,  6,      0,     0, 0},		// Mushroom
-	{ 12, 0, 13,      0,     0, 0},		// Poisonous Mushroom
-	{ 13, 0,  2,  0x400,     0, 0},		// Graa's Knife
-	{ 14, 0, 22,      0,     0, 0},		// Empty Nest
-	{ 15, 0, 26,      0,     0, 0},		// Full Nest
-	{ 16, 0, 33,   0x20,     0, 0},		// Gold
-	{ 17, 0,  3,      0,     0, 0},		// Sign of Shadow Mistress	(moon stone)
-	{ 18, 0,  3,      0,     0, 0},		// Sign of Mother of all	(bag of soil)
-	{ 19, 0, 40,      0,     0, 0},		// Sign of the life-giving	(sun star)
-	{ 20, 0, 20,  0x200,     0, 0},		// King's Horn
-	{ 21, 0,  3,      0,     0, 0},		// Golden Sword of Mashaar
-										// Masks
-	{ 22, 0,  3,   0x40,     0, 0},		// Mask of Death
-	{ 23, 0,  3,   0x80,     0, 0},		// Mask of Bonding
-	{ 24, 0,  3,  0x100,     0, 0},		// Mask of Birth
-										// Objects of power
-	{ 25, 0,  3,      0,     1, 0},		// Eye in the Storm
-	{ 26, 0,  3,      0,     2, 0},		// Sky Hammer
-	{ 27, 0,  3,      0,     4, 0},		// Fire in the Clouds
-	{ 28, 0,  3,      0,     8, 0},		// Within and Without
-	{ 29, 0,  3,      0,  0x10, 0},		// Eye in the Cyclone
-	{ 30, 0,  3,      0,  0x20, 0},		// River that Winds
-										// Musical instruments
-	{ 31, 0,  3,      0,  0x40, 0},		// Trumpet
-	{ 32, 0,  3,      0,  0x80, 0},		// -- unused (but still has a dialog line)
-	{ 33, 0,  3,      0, 0x100, 0},		// Drum
-	{ 34, 0,  3,      0, 0x200, 0},		// -- unused (but still has a dialog line)
-	{ 35, 0,  3,      0, 0x400, 0},		// -- unused (but still has a dialog line)
-	{ 36, 0,  3,      0, 0x800, 0},		// Ring
-										// Tablets
-	{ 37, 0,  3,      0,     0, 0},		// Tablet #1 (Mo)
-	{ 38, 0, 42, 0x2000,     0, 0},		// Tablet #2 (Morkus' Lair)
-	{ 39, 0,  3,      0,     0, 0},		// Tablet #3 (White Arch?)
-	{ 40, 0,  3,      0,     0, 0},		// Tablet #4
-	{ 41, 0,  3,      0,     0, 0},		// Tablet #5
-	{ 42, 0,  3, 0x8000,     0, 0}		// Tablet #6 (Castra)
+	//id,fl,loc,masklow,maskhi,ct
+	{  1, 0,  3,      1,     0, 0},     // Eve's Way Stone
+	{  2, 0,  3,      2,     0, 0},     // Thau's Seashell
+	{  3, 0,  3,      4,     0, 0},     // Talisman of bravery
+	{  4, 0,  3,      8,     0, 0},     // An old tooth. Very old! Whoever lost it most certainly has no further use for it!
+	{  5, 0,  0,   0x10,     0, 0},     // Prism
+	{  6, 0,  3,      0,     0, 0},     // Flute
+	{  7, 0,  3, 0x4000,     0, 0},     // Apple
+	{  8, 0,  4, 0x1000,     0, 0},     // Egg of Destiny
+	{  9, 0,  3,  0x800,     0, 0},     // Root
+	{ 10, 0,  3,      0,     0, 0},     // ???
+	{ 11, 0,  6,      0,     0, 0},     // Mushroom
+	{ 12, 0, 13,      0,     0, 0},     // Poisonous Mushroom
+	{ 13, 0,  2,  0x400,     0, 0},     // Graa's Knife
+	{ 14, 0, 22,      0,     0, 0},     // Empty Nest
+	{ 15, 0, 26,      0,     0, 0},     // Full Nest
+	{ 16, 0, 33,   0x20,     0, 0},     // Gold
+	{ 17, 0,  3,      0,     0, 0},     // Sign of Shadow Mistress  (moon stone)
+	{ 18, 0,  3,      0,     0, 0},     // Sign of Mother of all    (bag of soil)
+	{ 19, 0, 40,      0,     0, 0},     // Sign of the life-giving  (sun star)
+	{ 20, 0, 20,  0x200,     0, 0},     // King's Horn
+	{ 21, 0,  3,      0,     0, 0},     // Golden Sword of Mashaar
+	// Masks
+	{ 22, 0,  3,   0x40,     0, 0},     // Mask of Death
+	{ 23, 0,  3,   0x80,     0, 0},     // Mask of Bonding
+	{ 24, 0,  3,  0x100,     0, 0},     // Mask of Birth
+	// Objects of power
+	{ 25, 0,  3,      0,     1, 0},     // Eye in the Storm
+	{ 26, 0,  3,      0,     2, 0},     // Sky Hammer
+	{ 27, 0,  3,      0,     4, 0},     // Fire in the Clouds
+	{ 28, 0,  3,      0,     8, 0},     // Within and Without
+	{ 29, 0,  3,      0,  0x10, 0},     // Eye in the Cyclone
+	{ 30, 0,  3,      0,  0x20, 0},     // River that Winds
+	// Musical instruments
+	{ 31, 0,  3,      0,  0x40, 0},     // Trumpet
+	{ 32, 0,  3,      0,  0x80, 0},     // -- unused (but still has a dialog line)
+	{ 33, 0,  3,      0, 0x100, 0},     // Drum
+	{ 34, 0,  3,      0, 0x200, 0},     // -- unused (but still has a dialog line)
+	{ 35, 0,  3,      0, 0x400, 0},     // -- unused (but still has a dialog line)
+	{ 36, 0,  3,      0, 0x800, 0},     // Ring
+	// Tablets
+	{ 37, 0,  3,      0,     0, 0},     // Tablet #1 (Mo)
+	{ 38, 0, 42, 0x2000,     0, 0},     // Tablet #2 (Morkus' Lair)
+	{ 39, 0,  3,      0,     0, 0},     // Tablet #3 (White Arch?)
+	{ 40, 0,  3,      0,     0, 0},     // Tablet #4
+	{ 41, 0,  3,      0,     0, 0},     // Tablet #5
+	{ 42, 0,  3, 0x8000,     0, 0}      // Tablet #6 (Castra)
 };
 
 short kObjectLocations[100] = {
@@ -1130,7 +1166,7 @@ perso_t kPersons[] = {
 	{ 0x828, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
 	{ 0x84B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
 
-	{ 0xB03, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            , 58,252, 0, 0,  0,   0, 0, 0 },
+	{ 0xB03, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            , 58, 252, 0, 0,  0,   0, 0, 0 },
 	// enemy dinos
 	{ 0x311, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
 	{ 0x410, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
@@ -1138,47 +1174,75 @@ perso_t kPersons[] = {
 	{ 0x618, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
 	{ 0x71B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
 	{ 0x81B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{    -1,  -1,                   -1,                              -1,                                               -1, -1, -1,-1,-1, -1,  -1,-1,-1 },
+	{    -1,  -1,                   -1,                              -1,                                               -1, -1, -1, -1, -1, -1,  -1, -1, -1 },
 	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 80,  9, 0, 0,  8,  35, 0, 0 },
 	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 78, 10, 0, 0,  7,  35, 0, 0 }
 };
 
 cita_t cita_list[] = {
-	{1,
-	{163, 182,   0, 0,
-	 124, 147, 193, 0,
-	   0,   0,   0, 0,
-	   0,   0,   0, 0}},
-	{48,
-	{285, 286,   0, 0,
-	 287, 288, 284, 0,
-	 114, 115,   0, 0,
-	 116, 117, 113, 0}},
-	{63,
-	{290, 291,   0, 0,
-	 292, 293, 289, 0,
-	 119, 120,   0, 0,
-	 121, 122, 118, 0}},
-	{95,
-	{295, 296,   0, 0,
-	 297, 298, 294, 0,
-	 124, 125,   0, 0,
-	 126, 127, 123, 0}},
-	{127,
-	{300, 301,   0, 0,
-	 302, 303, 299, 0,
-	 129, 130,   0, 0,
-	 131, 132, 128, 0}},
-	{159,
-	{305, 306,   0, 0,
-	 307, 308, 304, 0,
-	 134, 135,   0, 0,
-	 136, 137, 133, 0}},
-	{255,
-	{310, 311,   0, 0,
-	 312, 313, 309, 0,
-	 139, 140,   0, 0,
-	 141, 142, 138, 0}}
+	{
+		1,
+		{
+			163, 182,   0, 0,
+			124, 147, 193, 0,
+			0,   0,   0, 0,
+			0,   0,   0, 0
+		}
+	},
+	{
+		48,
+		{
+			285, 286,   0, 0,
+			287, 288, 284, 0,
+			114, 115,   0, 0,
+			116, 117, 113, 0
+		}
+	},
+	{
+		63,
+		{
+			290, 291,   0, 0,
+			292, 293, 289, 0,
+			119, 120,   0, 0,
+			121, 122, 118, 0
+		}
+	},
+	{
+		95,
+		{
+			295, 296,   0, 0,
+			297, 298, 294, 0,
+			124, 125,   0, 0,
+			126, 127, 123, 0
+		}
+	},
+	{
+		127,
+		{
+			300, 301,   0, 0,
+			302, 303, 299, 0,
+			129, 130,   0, 0,
+			131, 132, 128, 0
+		}
+	},
+	{
+		159,
+		{
+			305, 306,   0, 0,
+			307, 308, 304, 0,
+			134, 135,   0, 0,
+			136, 137, 133, 0
+		}
+	},
+	{
+		255,
+		{
+			310, 311,   0, 0,
+			312, 313, 309, 0,
+			139, 140,   0, 0,
+			141, 142, 138, 0
+		}
+	}
 };
 
 
@@ -1196,11 +1260,11 @@ char tab_2CB1E[8][4] = {
 };
 
 struct prect_t {
-short	sx, sy, ex, ey;
+	short   sx, sy, ex, ey;
 };
 typedef struct prect_t prect_t;
 
-prect_t perso_rects[] = {	//TODO: just an array of shorts?
+prect_t perso_rects[] = {   //TODO: just an array of shorts?
 	{  93,  69, 223, 176},
 	{ 102,  86, 162, 126},
 	{  88, 103, 168, 163},
@@ -1222,7 +1286,7 @@ prect_t perso_rects[] = {	//TODO: just an array of shorts?
 	{ 188,  83, 251, 158}
 };
 
-unsigned char tab_persxx[][5] = {	//TODO: struc?
+unsigned char tab_persxx[][5] = {   //TODO: struc?
 	{  8, 15, 23, 25, -1},
 	{  0,  9, -1        },
 	{  0,  9, -1        },
@@ -1262,68 +1326,68 @@ area_t kAreasTable[] = {
 
 short tab_2CEF0[64] = {
 	25, 257,  0,   0, 37, 258, 38, 259,  0,   0, 24, 260, 0, 0, 0, 0,
-	 0,   0, 53, 265,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
+	0,   0, 53, 265,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
 	39, 261,  0,   0, 40, 262, 62, 263,  0,   0, 63, 264, 0, 0, 0, 0,
 	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0
 };
 
 short tab_2CF70[64] = {
 	65, 266,  0,   0, 66, 267, 67, 268,  0,   0, 68, 269, 0, 0, 0, 0,
-	 0,   0, 73, 274,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
+	0,   0, 73, 274,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
 	69, 270,  0,   0, 70, 271, 71, 272,  0,   0, 72, 273, 0, 0, 0, 0,
 	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0,
 };
 
 short kActionCursors[299] = {
-	 3, 1, 2, 4, 5, 5, 5, 0, 5, 5,
-	 5, 5, 5, 3, 2, 5, 5, 5, 3, 2,
-	 4, 5, 7, 7, 4, 5, 5, 0, 0, 0,
-	 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-	 5, 5, 0, 0, 0, 0, 5, 5, 5, 5,
-	 5, 5, 5, 5, 5, 5, 5, 5, 0, 0,
-	 0, 0, 5, 5, 5, 5, 5, 5, 5, 5,
-	 5, 5, 5, 5, 0, 0, 0, 0, 5, 5,
-	 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-	 6, 6, 6, 6, 6, 6, 6, 0, 5, 6,
-	 6, 1, 6, 6, 0, 0, 6, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-	 8, 8, 8, 8, 8, 8, 0, 0, 6, 6,
+	3, 1, 2, 4, 5, 5, 5, 0, 5, 5,
+	5, 5, 5, 3, 2, 5, 5, 5, 3, 2,
+	4, 5, 7, 7, 4, 5, 5, 0, 0, 0,
+	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+	5, 5, 0, 0, 0, 0, 5, 5, 5, 5,
+	5, 5, 5, 5, 5, 5, 5, 5, 0, 0,
+	0, 0, 5, 5, 5, 5, 5, 5, 5, 5,
+	5, 5, 5, 5, 0, 0, 0, 0, 5, 5,
+	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+	6, 6, 6, 6, 6, 6, 6, 0, 5, 6,
+	6, 1, 6, 6, 0, 0, 6, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+	8, 8, 8, 8, 8, 8, 0, 0, 6, 6,
 	53, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	 0, 0, 0, 0, 0, 0, 0, 0, 0
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
 
 struct cubeface_t {
-int				tri;
-char			ff_4;
-char			ff_5;
+	int             tri;
+	char            ff_4;
+	char            ff_5;
 
-unsigned char	*texptr;
-unsigned short	*indices;
-short			*uv;
+	unsigned char   *texptr;
+	unsigned short  *indices;
+	short           *uv;
 };
 typedef struct cubeface_t cubeface_t;
 
 struct cube_t {
-int				num;
-cubeface_t		**faces;
-short			*projection;	// projected XYZ coords
-short			*vertices;
+	int             num;
+	cubeface_t      **faces;
+	short           *projection;    // projected XYZ coords
+	short           *vertices;
 };
 typedef struct cube_t cube_t;
 
@@ -1339,8 +1403,8 @@ short cube_texcoords[3][6 * 2 * 3 * 2] = {
 		32, 32,  0, 32,  0,  0,
 		32, 32,  0,  0, 32,  0,
 
-		 0, 32,  0,  0, 32,  0,
-		 0, 32, 32,  0, 32, 32,
+		0, 32,  0,  0, 32,  0,
+		0, 32, 32,  0, 32, 32,
 
 		32, 32,  0, 32,  0,  0,
 		32, 32,  0,  0, 32,  0,
@@ -1348,11 +1412,11 @@ short cube_texcoords[3][6 * 2 * 3 * 2] = {
 		32,  0, 32, 32,  0, 32,
 		32,  0,  0, 32,  0,  0,
 
-		 0,  0, 32,  0, 32, 32,
-		 0,  0, 32, 32,  0, 32,
+		0,  0, 32,  0, 32, 32,
+		0,  0, 32, 32,  0, 32,
 
-		 0, 32,  0,  0, 32,  0,
-		 0, 32, 32,  0, 32, 32
+		0, 32,  0,  0, 32,  0,
+		0, 32, 32,  0, 32, 32
 	}, {
 		32, 32,  0, 32,  0,  0,
 		32, 32,  0,  0, 32,  0,
@@ -1363,8 +1427,8 @@ short cube_texcoords[3][6 * 2 * 3 * 2] = {
 		32,  0, 32, 32,  0, 32,
 		32,  0,  0, 32,  0,  0,
 
-		 0, 32,  0,  0, 32,  0,
-		 0, 32, 32,  0, 32, 32,
+		0, 32,  0,  0, 32,  0,
+		0, 32, 32,  0, 32, 32,
 
 		32,  0, 32, 32,  0, 32,
 		32,  0,  0, 32,  0,  0,
@@ -1375,8 +1439,8 @@ short cube_texcoords[3][6 * 2 * 3 * 2] = {
 		30, 30,  2, 30,  2,  2,
 		30, 30,  2,  2, 30,  2,
 
-		 2, 30,  2,  2, 30,  2,
-		 2, 30, 30,  2, 30, 30,
+		2, 30,  2,  2, 30,  2,
+		2, 30, 30,  2, 30, 30,
 
 		30, 30,  2, 30,  2,  2,
 		30, 30,  2,  2, 30,  2,
@@ -1384,12 +1448,12 @@ short cube_texcoords[3][6 * 2 * 3 * 2] = {
 		30,  2, 30, 30,  2, 30,
 		30,  2,  2, 30,  2,  2,
 
-		 2,  2, 30,  2, 30, 30,
-		 2,  2, 30, 30,  2, 30,
+		2,  2, 30,  2, 30, 30,
+		2,  2, 30, 30,  2, 30,
 
-		 2, 30,  2,  2, 30,  2,
-		 2, 30, 30,  2, 30, 30
-	 }
+		2, 30,  2,  2, 30,  2,
+		2, 30, 30,  2, 30, 30
+	}
 };
 
 char tab_2E138[4 * 3] = {
diff --git a/engines/cryo/detection.cpp b/engines/cryo/detection.cpp
index 1d6f145..1acdbff 100644
--- a/engines/cryo/detection.cpp
+++ b/engines/cryo/detection.cpp
@@ -125,7 +125,7 @@ bool CryoMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGame
 }
 
 #if PLUGIN_ENABLED_DYNAMIC(CRYO)
-	REGISTER_PLUGIN_DYNAMIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine);
+REGISTER_PLUGIN_DYNAMIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine);
 #else
-	REGISTER_PLUGIN_STATIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine);
+REGISTER_PLUGIN_STATIC(CRYO, PLUGIN_TYPE_ENGINE, CryoMetaEngine);
 #endif
diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp
index 02fc66b..d5253d3 100644
--- a/engines/cryo/eden.cpp
+++ b/engines/cryo/eden.cpp
@@ -29,3953 +29,3487 @@ namespace Cryo {
 #include "cryo/CryoLib.h"
 #include "cryo/CryoLibStub.c"
 
-short		word_2C300 = 0;
-short		word_2C302 = 0;
-short		word_2C304 = 0;
+short       word_2C300 = 0;
+short       word_2C302 = 0;
+short       word_2C304 = 0;
 
-unsigned char	allow_doubled = 1;
-int		curs_center = 11;
+unsigned char   allow_doubled = 1;
+int     curs_center = 11;
 
 struct {
-	short	x, y;
+	short   x, y;
 } saved_repadam = { -1, -1 };
 
 class EdenGameImpl : EdenGame {
 private:
 
-short			old_scroll_pos, scroll_pos;
-short			word_2F514;
-unsigned char	fresqTalk;
-unsigned char	keep01, keep02, keep10, keep11, keep12, keep13, keep21, keep22;
-unsigned char	curs_keepbuf[2500];
-short			curs_keepy, curs_keepx;
-short			torchCursor;
-short			cur_bank_num;
-short			glow_h;
-short			glow_w;
-short			glow_y;
-short			glow_x;
-unsigned char	needPaletteUpdate;
-unsigned char	curs_saved;
-unsigned char	showBlackBars;
-unsigned char	fond_saved;
-unsigned char	*bank_data_ptr;
-color3_t		pal_entry;
-color_t			global_palette[256];	//TODO palette_t
-perso_t			*tyranPtr;
-int				last_anim_frame_num;
-int				cur_anim_frame_num;
-int				last_anim_ticks;
-prect_t			*cur_perso_rect;
-short			num_anim_frames;
-short			max_perso_desc;
-short			num_img_desc;
-unsigned char	restartAnimation;
-unsigned char	animationActive;
-unsigned char	animationDelay;
-unsigned char	animationIndex;
-unsigned char	lastAnimationIndex;
+	short           old_scroll_pos, scroll_pos;
+	short           word_2F514;
+	unsigned char   fresqTalk;
+	unsigned char   keep01, keep02, keep10, keep11, keep12, keep13, keep21, keep22;
+	unsigned char   curs_keepbuf[2500];
+	short           curs_keepy, curs_keepx;
+	short           torchCursor;
+	short           cur_bank_num;
+	short           glow_h;
+	short           glow_w;
+	short           glow_y;
+	short           glow_x;
+	unsigned char   needPaletteUpdate;
+	unsigned char   curs_saved;
+	unsigned char   showBlackBars;
+	unsigned char   fond_saved;
+	unsigned char   *bank_data_ptr;
+	color3_t        pal_entry;
+	color_t         global_palette[256];    //TODO palette_t
+	perso_t         *tyranPtr;
+	int             last_anim_frame_num;
+	int             cur_anim_frame_num;
+	int             last_anim_ticks;
+	prect_t         *cur_perso_rect;
+	short           num_anim_frames;
+	short           max_perso_desc;
+	short           num_img_desc;
+	unsigned char   restartAnimation;
+	unsigned char   animationActive;
+	unsigned char   animationDelay;
+	unsigned char   animationIndex;
+	unsigned char   lastAnimationIndex;
 
-unsigned char	*dword_30724;
-unsigned char	*dword_30728;	//TODO: rename - something amim-related
-unsigned char	*dword_3072C;	//TODO ditto
-unsigned char	*animationTable;
-unsigned char	imagedesc[512];
-unsigned char	*perso_img_bank_data_ptr;
-unsigned char	savedUnderSubtitles;
-short			num_text_lines;
-unsigned char	phraseBuffer[400];
-unsigned char	*text_ptr;
-unsigned char	phraseIconsBuffer[10];
-unsigned char	phraseCoordsBuffer[22];
-unsigned char	*textoutptr;
-unsigned char	*textout;
-object_t		*currentSpecialObject;
-short			word_30AFC;
-unsigned char	byte_30AFE;
+	unsigned char   *dword_30724;
+	unsigned char   *dword_30728;   //TODO: rename - something amim-related
+	unsigned char   *dword_3072C;   //TODO ditto
+	unsigned char   *animationTable;
+	unsigned char   imagedesc[512];
+	unsigned char   *perso_img_bank_data_ptr;
+	unsigned char   savedUnderSubtitles;
+	short           num_text_lines;
+	unsigned char   phraseBuffer[400];
+	unsigned char   *text_ptr;
+	unsigned char   phraseIconsBuffer[10];
+	unsigned char   phraseCoordsBuffer[22];
+	unsigned char   *textoutptr;
+	unsigned char   *textout;
+	object_t        *currentSpecialObject;
+	short           word_30AFC;
+	unsigned char   byte_30AFE;
 
-unsigned char	byte_30B00;
-int				dword_30B04;
+	unsigned char   byte_30B00;
+	int             dword_30B04;
 
-char			lastPhrasesFile;
-char			dialogSkipFlags;
+	char            lastPhrasesFile;
+	char            dialogSkipFlags;
 
-color3_t		newColor;
-color_t			oldPalette[256];	// TODO palette_t ?
-color_t			newPalette[256];
-rect_t			rect_dst, rect_src;
-void			*voiceSamplesBuffer;	//TODO: sound sample buffer
-file_t			h_bigfile;
-unsigned char	info_list[16];
-unsigned char	needToFade;
-unsigned char	lastMusicNum;
-unsigned char	*main_bank_buf;
-unsigned char	*music_buf;
-unsigned char	*gameLipsync;
-unsigned char	*gamePhrases;
-unsigned char	*gameDialogs;	//TODO: rename to dialogs?
-unsigned char	*gameConditions;
-void			*sal_buf;	//TODO: fixme
-unsigned char	*bank_data_buf;
-icon_t			*gameIcons;
-room_t			*gameRooms;
-pak_t			*bigfile_header;
-unsigned char	*glow_buffer;
-unsigned char	*p_mainview_buf;
-unsigned char	*p_view2_buf;
-unsigned char	*gameFont;	//TODO: rename to font?
-unsigned char	*p_subtitlesview_buf;
-unsigned char	*p_underSubtitlesView_buf;
-global_t		*p_global;
-unsigned short	mouse_y_center, mouse_x_center;
-int				quit_flag3;		//TODO: some obsolete error flag?
-unsigned short	machine_speed;
-unsigned char	quit_flag;
+	color3_t        newColor;
+	color_t         oldPalette[256];    // TODO palette_t ?
+	color_t         newPalette[256];
+	rect_t          rect_dst, rect_src;
+	void            *voiceSamplesBuffer;    //TODO: sound sample buffer
+	file_t          h_bigfile;
+	unsigned char   info_list[16];
+	unsigned char   needToFade;
+	unsigned char   lastMusicNum;
+	unsigned char   *main_bank_buf;
+	unsigned char   *music_buf;
+	unsigned char   *gameLipsync;
+	unsigned char   *gamePhrases;
+	unsigned char   *gameDialogs;   //TODO: rename to dialogs?
+	unsigned char   *gameConditions;
+	void            *sal_buf;   //TODO: fixme
+	unsigned char   *bank_data_buf;
+	icon_t          *gameIcons;
+	room_t          *gameRooms;
+	pak_t           *bigfile_header;
+	unsigned char   *glow_buffer;
+	unsigned char   *p_mainview_buf;
+	unsigned char   *p_view2_buf;
+	unsigned char   *gameFont;  //TODO: rename to font?
+	unsigned char   *p_subtitlesview_buf;
+	unsigned char   *p_underSubtitlesView_buf;
+	global_t        *p_global;
+	unsigned short  mouse_y_center, mouse_x_center;
+	int             quit_flag3;     //TODO: some obsolete error flag?
+	unsigned short  machine_speed;
+	unsigned char   quit_flag;
 
-unsigned char	gameStarted;
+	unsigned char   gameStarted;
 
-unsigned char	quit_flag2;
-unsigned char	soundAllocated;
-soundchannel_t	*music_channel;
-soundchannel_t	*hnmsound_ch;
-sound_t			*voiceSound;
+	unsigned char   quit_flag2;
+	unsigned char   soundAllocated;
+	soundchannel_t  *music_channel;
+	soundchannel_t  *hnmsound_ch;
+	sound_t         *voiceSound;
 
-view_t			*p_view2;
-view_t			*p_underSubtitlesView;
-view_t			*p_subtitlesview;
-view_t			*p_underBarsView;
-view_t			*p_mainview;
-view_t			*p_hnmview;
-hnm_t			*p_hnmcontext;
-filespec_t		bigfilespec;
-rect_t			underSubtitlesBackupRect, underSubtitlesScreenRect, underBottomBarBackupRect, underBottomBarScreenRect,
-				underTopBarBackupRect, underTopBarScreenRect, rect_31C7A;
-int				demoCurrentTicks;
-int				demoStartTicks;
-int				currentTime;
-short			mouse_y;
-short			mouse_x;
-short			doubled;
-short			curs_x_pan;
-short			inventoryScrollDelay;
-short			curs_y, curs_x;
-short			current_cursor;
-icon_t			*current_spot;
-icon_t			*current_spot2;
-unsigned char	pomme_q;
-unsigned char	keybd_held;
-unsigned char	mouse_held;
-unsigned char	normalCursor;
-unsigned char	*p_hnmview_buf;
-unsigned char	showVideoSubtitle;
-unsigned char	videoCanceled;	//TODO: hnm_canceled
-unsigned char	specialTextMode;
-int				hnm_position;
-int				voiceSamplesSize;	//TODO: perso vox sample data len
-short			mus_vol_right;
-short			mus_vol_left;
+	view_t          *p_view2;
+	view_t          *p_underSubtitlesView;
+	view_t          *p_subtitlesview;
+	view_t          *p_underBarsView;
+	view_t          *p_mainview;
+	view_t          *p_hnmview;
+	hnm_t           *p_hnmcontext;
+	filespec_t      bigfilespec;
+	rect_t          underSubtitlesBackupRect, underSubtitlesScreenRect, underBottomBarBackupRect, underBottomBarScreenRect,
+	                underTopBarBackupRect, underTopBarScreenRect, rect_31C7A;
+	int             demoCurrentTicks;
+	int             demoStartTicks;
+	int             currentTime;
+	short           mouse_y;
+	short           mouse_x;
+	short           doubled;
+	short           curs_x_pan;
+	short           inventoryScrollDelay;
+	short           curs_y, curs_x;
+	short           current_cursor;
+	icon_t          *current_spot;
+	icon_t          *current_spot2;
+	unsigned char   pomme_q;
+	unsigned char   keybd_held;
+	unsigned char   mouse_held;
+	unsigned char   normalCursor;
+	unsigned char   *p_hnmview_buf;
+	unsigned char   showVideoSubtitle;
+	unsigned char   videoCanceled;  //TODO: hnm_canceled
+	unsigned char   specialTextMode;
+	int             hnm_position;
+	int             voiceSamplesSize;   //TODO: perso vox sample data len
+	short           mus_vol_right;
+	short           mus_vol_left;
 
 
-unsigned char	animateTalking;
-unsigned char	personTalking;
-unsigned char	mus_fade_flags;
+	unsigned char   animateTalking;
+	unsigned char   personTalking;
+	unsigned char   mus_fade_flags;
 
-char			musicSequencePos;
-unsigned char	musicPlaying;
+	char            musicSequencePos;
+	unsigned char   musicPlaying;
 
-unsigned char	*mus_samples_ptr;
-unsigned char	*mus_patterns_ptr;	//TODO: sndblock_t ?
-unsigned char	*mus_sequence_ptr;
-soundgroup_t	*mus_queue_grp;
-short			*pCurrentObjectLocation;
-unsigned char	own_objects[128];
-unsigned char	byte_31D64;
+	unsigned char   *mus_samples_ptr;
+	unsigned char   *mus_patterns_ptr;  //TODO: sndblock_t ?
+	unsigned char   *mus_sequence_ptr;
+	soundgroup_t    *mus_queue_grp;
+	short           *pCurrentObjectLocation;
+	unsigned char   own_objects[128];
+	unsigned char   byte_31D64;
 
-unsigned char	no_palette;
-unsigned char	gameLoaded;
+	unsigned char   no_palette;
+	unsigned char   gameLoaded;
 #define MAX_TAPES 16
-tape_t			tapes[MAX_TAPES];
-unsigned char	confirmMode;
-unsigned char	*cur_slider_value_ptr;
-unsigned char	lastMenuItemIdLo;
-short			lastTapeRoomNum;
-short			cur_slider_x;
-short			cur_slider_y;
-short			destinationRoom;
-short			word_31E7A;
+	tape_t          tapes[MAX_TAPES];
+	unsigned char   confirmMode;
+	unsigned char   *cur_slider_value_ptr;
+	unsigned char   lastMenuItemIdLo;
+	short           lastTapeRoomNum;
+	short           cur_slider_x;
+	short           cur_slider_y;
+	short           destinationRoom;
+	short           word_31E7A;
 
-short			word_378CC;	//TODO: set by CLComputer_Init to 0
-short			word_378CE;
+	short           word_378CC; //TODO: set by CLComputer_Init to 0
+	short           word_378CE;
 
-void RemoveConsole()
-{
-}
-void scroll()
-{
-	restaurefrises();
-	p_mainview->norm.src_left = scroll_pos;
-	p_mainview->zoom.src_left = scroll_pos;
-	
-}
-void resetscroll()
-{
-	old_scroll_pos = scroll_pos;
-	scroll_pos = 0;
-	restaurefrises();	//TODO: inlined scroll() ?
-	p_mainview->norm.src_left = 0;
-	p_mainview->zoom.src_left = 0;
-}
-void scrollfresques()
-{
-	if(curs_y > 16 && curs_y < 176)
-	{
-		if(curs_x >= 0 && curs_x < 32 && scroll_pos > 3)
-		{
-			scroll_pos -= 4;
-		}
-		else if(curs_x > 288 && curs_x < 320 && scroll_pos < p_global->fresqWidth)
-		{
-			scroll_pos += 4;
+	void RemoveConsole() {
+	}
+	void scroll() {
+		restaurefrises();
+		p_mainview->norm.src_left = scroll_pos;
+		p_mainview->zoom.src_left = scroll_pos;
+
+	}
+	void resetscroll() {
+		old_scroll_pos = scroll_pos;
+		scroll_pos = 0;
+		restaurefrises();   //TODO: inlined scroll() ?
+		p_mainview->norm.src_left = 0;
+		p_mainview->zoom.src_left = 0;
+	}
+	void scrollfresques() {
+		if (curs_y > 16 && curs_y < 176) {
+			if (curs_x >= 0 && curs_x < 32 && scroll_pos > 3) {
+				scroll_pos -= 4;
+			} else if (curs_x > 288 && curs_x < 320 && scroll_pos < p_global->fresqWidth) {
+				scroll_pos += 4;
+			}
 		}
+		scroll();
+
 	}
-	scroll();
-	
-}
-void afffresques()
-{
-	use_bank(p_global->fresqImgBank);
-	noclipax(0, 0, 16);
-	use_bank(p_global->fresqImgBank + 1);
-	noclipax(0, 320, 16);
-	needPaletteUpdate = 1;
-}
-void gametofresques()
-{
-	fresqTalk = 0;
-	rundcurs();
-	sauvefrises();
-	afffresques();
-	p_global->displayFlags = DisplayFlags::dfFresques;
-}
-void dofresques()
-{
-	curs_saved = 0;
-	torchCursor = 1;
-	glow_x = -1;
-	glow_y = -1;
-	p_global->gameFlags |= GameFlags::gfFlag20;
-	p_global->ff_D4 = 0;
-	p_global->curObjectId = 0;
-	p_global->iconsIndex = 13;
-	p_global->autoDialog = 0;
-	gametofresques();
-	p_global->fresqNumber = 3;
-}
-void finfresques()
-{
-	torchCursor = 0;
-	curs_saved = 1;
-	p_global->displayFlags = DisplayFlags::dfFlag1;
-	resetscroll();
-	p_global->ff_100 = -1;
-	maj_salle(p_global->roomNum);
-	if(p_global->phaseNum == 114)
-		p_global->narratorSequence = 1;
-	p_global->eventType = EventType::etEvent8;
-	showevents();
-}
-void scrollmiroir()
-{
-	if(curs_y > 16 && curs_y < 165)
-	{
-		if(curs_x >= 0 && curs_x < 16)
-		{
-			if(scroll_pos > 3)
-			{
-				if(doubled)
-					scroll_pos -= 2;
-				else
-					scroll_pos -= 1;
-				scroll();
+	void afffresques() {
+		use_bank(p_global->fresqImgBank);
+		noclipax(0, 0, 16);
+		use_bank(p_global->fresqImgBank + 1);
+		noclipax(0, 320, 16);
+		needPaletteUpdate = 1;
+	}
+	void gametofresques() {
+		fresqTalk = 0;
+		rundcurs();
+		sauvefrises();
+		afffresques();
+		p_global->displayFlags = DisplayFlags::dfFresques;
+	}
+	void dofresques() {
+		curs_saved = 0;
+		torchCursor = 1;
+		glow_x = -1;
+		glow_y = -1;
+		p_global->gameFlags |= GameFlags::gfFlag20;
+		p_global->ff_D4 = 0;
+		p_global->curObjectId = 0;
+		p_global->iconsIndex = 13;
+		p_global->autoDialog = 0;
+		gametofresques();
+		p_global->fresqNumber = 3;
+	}
+	void finfresques() {
+		torchCursor = 0;
+		curs_saved = 1;
+		p_global->displayFlags = DisplayFlags::dfFlag1;
+		resetscroll();
+		p_global->ff_100 = -1;
+		maj_salle(p_global->roomNum);
+		if (p_global->phaseNum == 114)
+			p_global->narratorSequence = 1;
+		p_global->eventType = EventType::etEvent8;
+		showevents();
+	}
+	void scrollmiroir() {
+		if (curs_y > 16 && curs_y < 165) {
+			if (curs_x >= 0 && curs_x < 16) {
+				if (scroll_pos > 3) {
+					if (doubled)
+						scroll_pos -= 2;
+					else
+						scroll_pos -= 1;
+					scroll();
+				}
+			} else if (curs_x > 290 && curs_x < 320) {
+				if (scroll_pos < 320) {
+					if (doubled)
+						scroll_pos += 2;
+					else
+						scroll_pos += 1;
+					scroll();
+				}
 			}
 		}
-		else if(curs_x > 290 && curs_x < 320)
-		{
-			if(scroll_pos < 320)
-			{
-				if(doubled)
-					scroll_pos += 2;
-				else
-					scroll_pos += 1;
-				scroll();
+	}
+	void scrollpano() {
+		if (curs_y > 16 && curs_y < 165) {
+			if (curs_x >= 0 && curs_x < 16) {
+				if (scroll_pos > 3) {
+					if (doubled)
+						scroll_pos -= 2;
+					else
+						scroll_pos -= 1;
+				}
+			} else if (curs_x > 290 && curs_x < 320) {
+				if (scroll_pos < 320) {
+					if (doubled)
+						scroll_pos += 2;
+					else
+						scroll_pos += 1;
+				}
 			}
 		}
+		scroll();
 	}
-}
-void scrollpano()
-{
-	if(curs_y > 16 && curs_y < 165)
-	{
-		if(curs_x >= 0 && curs_x < 16)
-		{
-			if(scroll_pos > 3)
-			{
-				if(doubled)
-					scroll_pos -= 2;
-				else
-					scroll_pos -= 1;
-			}		                         	
+	void affsuiveur(suiveur_t *suiveur, short x, short y) {
+		use_bank(suiveur->bank);
+		noclipax(suiveur->image, x, y + 16);
+	}
+	void persoinmiroir() {
+		icon_t  *icon1 = &gameIcons[3];
+		icon_t  *icon = &gameIcons[28];
+		suiveur_t *suiveur = suiveurs_list;
+		short num = 1;
+		int i;
+		for (i = 0; i < 16; i++) {
+			if (p_global->party & (1 << i))
+				num++;
 		}
-		else if(curs_x > 290 && curs_x < 320)
-		{
-			if(scroll_pos < 320)
-			{
-				if(doubled)
-					scroll_pos += 2;
-				else
-					scroll_pos += 1;
+		icon += num;
+		icon->sx = -1;
+		icon--;
+		icon->sx = icon1->sx;
+		icon->sy = icon1->sy;
+		icon->ex = icon1->ex;
+		icon->ey = 170;
+		icon->cursor_id = icon1->cursor_id;
+		icon->action_id = icon1->action_id;
+		icon->object_id = icon1->object_id;
+		icon--;
+		affsuiveur(suiveur, suiveur->sx, suiveur->sy);
+		for (; suiveur->id != -1; suiveur++) {
+			perso_t *perso;
+			for (perso = kPersons; perso != &kPersons[PER_UNKN_156]; perso++) {
+				if (perso->id != suiveur->id)                       continue;
+				if (perso->flags & PersonFlags::pf80)               continue;
+				if ((perso->flags & PersonFlags::pfInParty) == 0)   continue;
+				if (perso->roomNum != p_global->roomNum)            continue;
+				icon->sx = suiveur->sx;
+				icon->sy = suiveur->sy;
+				icon->ex = suiveur->ex;
+				icon->ey = suiveur->ey;
+				icon->cursor_id = 8;
+				icon->action_id = perso->actionId;
+				icon--;
+				affsuiveur(suiveur, suiveur->sx, suiveur->sy);
+				break;
 			}
 		}
 	}
-	scroll();
-}    
-void affsuiveur(suiveur_t *suiveur, short x, short y)
-{
-	use_bank(suiveur->bank);
-	noclipax(suiveur->image, x, y + 16);	
-}
-void persoinmiroir()
-{
-	icon_t	*icon1 = &gameIcons[3];
-	icon_t	*icon = &gameIcons[28];
-	suiveur_t *suiveur = suiveurs_list;
-	short num = 1;
-	int i;
-	for(i = 0;i < 16;i++)
-	{
-		if(p_global->party & (1 << i))
-			num++;
-	}
-	icon += num;
-	icon->sx = -1;
-	icon--;
-	icon->sx = icon1->sx;
-	icon->sy = icon1->sy;
-	icon->ex = icon1->ex;
-	icon->ey = 170;
-	icon->cursor_id = icon1->cursor_id;
-	icon->action_id = icon1->action_id;
-	icon->object_id = icon1->object_id;
-	icon--;
-	affsuiveur(suiveur, suiveur->sx, suiveur->sy);
-	for(;suiveur->id != -1;suiveur++)
-	{
-		perso_t *perso;
-		for(perso = kPersons;perso != &kPersons[PER_UNKN_156];perso++)
-		{
-			if (perso->id != suiveur->id)						continue;
-			if (perso->flags & PersonFlags::pf80)				continue;
-			if ((perso->flags & PersonFlags::pfInParty) == 0)	continue;
-			if (perso->roomNum != p_global->roomNum)			continue;
-			icon->sx = suiveur->sx;
-			icon->sy = suiveur->sy;
-			icon->ex = suiveur->ex;
-			icon->ey = suiveur->ey;
-			icon->cursor_id = 8;
-			icon->action_id = perso->actionId;
-			icon--;
-			affsuiveur(suiveur, suiveur->sx, suiveur->sy);
-			break;
+	void gametomiroir(unsigned char arg1) {
+		short bank;
+		if (p_global->displayFlags != DisplayFlags::dfFlag2) {
+			rundcurs();
+			restaurefrises();
+			afftopscr();
+			showobjects();
+			sauvefrises();
 		}
+		bank = p_global->roomBgBankNum;
+		if (bank == 76 || bank == 128)
+			bank = 2161;
+		use_bank(bank + 326);
+		noclipax(0, 0, 16);
+		use_bank(bank + 327);
+		noclipax(0, 320, 16);
+		persoinmiroir();
+		needPaletteUpdate = 1;
+		p_global->iconsIndex = 16;
+		p_global->autoDialog = 0;
+		p_global->displayFlags = DisplayFlags::dfMirror;
+		p_global->ff_102 = arg1;
 	}
-}
-void gametomiroir(unsigned char arg1)
-{
-	short bank;
-	if(p_global->displayFlags != DisplayFlags::dfFlag2)
-	{
-		rundcurs();
-		restaurefrises();
-		afftopscr();
-		showobjects();
-		sauvefrises();
-	}
-	bank = p_global->roomBgBankNum;
-	if(bank == 76 || bank == 128)
-		bank = 2161;
-	use_bank(bank + 326);
-	noclipax(0, 0, 16);
-	use_bank(bank + 327);
-	noclipax(0, 320, 16);
-	persoinmiroir();
-	needPaletteUpdate = 1;
-	p_global->iconsIndex = 16;
-	p_global->autoDialog = 0;
-	p_global->displayFlags = DisplayFlags::dfMirror;
-	p_global->ff_102 = arg1;
-}
-void flipmode()
-{
-	if(personTalking)
-	{
-		endpersovox();
-		if(p_global->displayFlags == DisplayFlags::dfPerson)
-		{
-			if(p_global->perso_ptr == &kPersons[PER_THOO] && p_global->phaseNum >= 80)
+	void flipmode() {
+		if (personTalking) {
+			endpersovox();
+			if (p_global->displayFlags == DisplayFlags::dfPerson) {
+				if (p_global->perso_ptr == &kPersons[PER_THOO] && p_global->phaseNum >= 80)
+					af_subtitle();
+				else {
+					getdatasync();
+					load_perso_cour();
+					addanim();
+					restartAnimation = 1;
+					anim_perso();
+				}
+			} else
 				af_subtitle();
-			else
-			{
-				getdatasync();
-				load_perso_cour();
-				addanim();
-				restartAnimation = 1;
-				anim_perso();
-			}
-		}
-		else
-			af_subtitle();
-		persovox();
-	}
-	else
-	{
-		if(p_global->displayFlags != DisplayFlags::dfFresques && p_global->displayFlags != DisplayFlags::dfFlag2)
-		{
-			closesalle();
-			if(p_global->displayFlags & DisplayFlags::dfFlag1)
-				gametomiroir(1);
-			else
-			{
-				quitmiroir();
-				maj_salle(p_global->roomNum);
-				if(byte_31D64)
-				{
-					dialautoon();
-					parle_moi();
+			persovox();
+		} else {
+			if (p_global->displayFlags != DisplayFlags::dfFresques && p_global->displayFlags != DisplayFlags::dfFlag2) {
+				closesalle();
+				if (p_global->displayFlags & DisplayFlags::dfFlag1)
+					gametomiroir(1);
+				else {
+					quitmiroir();
+					maj_salle(p_global->roomNum);
+					if (byte_31D64) {
+						dialautoon();
+						parle_moi();
+					}
+					byte_31D64 = 0;
 				}
-				byte_31D64 = 0;
 			}
 		}
 	}
-}
-void quitmiroir()
-{
-	rundcurs();
-	afficher();
-	resetscroll();
-	sauvefrises();
-	p_global->displayFlags = DisplayFlags::dfFlag1;
-	p_global->ff_100 = -1;
-	p_global->eventType = EventType::etEventC;
-	p_global->ff_102 = 1;
-}
-void clictimbre()
-{
-	flipmode();
-}
-void clicplanval()
-{
-	if((p_global->partyOutside & PersonMask::pmDina) && p_global->phaseNum == 371)
-	{
-		quitmiroir();
-		maj_salle(p_global->roomNum);
-		return;
+	void quitmiroir() {
+		rundcurs();
+		afficher();
+		resetscroll();
+		sauvefrises();
+		p_global->displayFlags = DisplayFlags::dfFlag1;
+		p_global->ff_100 = -1;
+		p_global->eventType = EventType::etEventC;
+		p_global->ff_102 = 1;
 	}
-	if(p_global->roomNum == 8 || p_global->roomNum < 16)
-		return;
-	rundcurs();
-	afficher();
-	if(p_global->displayFlags == DisplayFlags::dfMirror)
-		quitmiroir();
-	deplaval((p_global->roomNum & 0xFF00) | 1);	//TODO: check me
-}
-void gotolieu(goto_t *go)
-{
-	p_global->valleyVidNum = go->arriveVid;
-	p_global->travelTime = go->travelTime * 256;
-	p_global->stepsToFindAppleFast = 0;
-	p_global->eventType = EventType::etEvent2;
-	init_oui();
-	showevents();
-	if(!verif_oui())
-		return;
-	if(p_global->ff_113)
-	{
-		waitendspeak();
-		if(!pomme_q)
-			close_perso();
+	void clictimbre() {
+		flipmode();
 	}
-	if(go->departVid)
-	{
-		bars_out();
-		playhnm(go->departVid);
-		needToFade = 1;
-	}
-	initlieu(p_global->newRoomNum);
-	specialoutside();
-	faire_suivre(p_global->newRoomNum);
-	closesalle();
-	saved_repadam.x = -1;
-	saved_repadam.y = -1;
-	temps_passe(p_global->travelTime);
-	p_global->ff_100 = p_global->room_ptr->ff_0;
-	p_global->roomNum = p_global->newRoomNum;
-	p_global->areaNum = p_global->roomNum >> 8;
-	p_global->eventType = EventType::etEvent5;
-	p_global->newMusicType = MusicType::mt2;
-	setpersohere();
-	musique();
-	majsalle1(p_global->roomNum);
-	afftopscr();
-	saved_repadam.x = -1;
-	saved_repadam.y = -1;
-}
-void deplaval(unsigned short roomNum)
-{
-	unsigned char c1, newAreaNum, curAreaNum;
-	short newRoomNum;
-	p_global->newLocation = roomNum & 0xFF;
-	p_global->valleyVidNum = 0;
-	p_global->phaseActionsCount++;
-	closesalle();
-	endpersovox();
-	c1 = roomNum & 0xFF;
-	if(c1 == 0)
-		return;
-	if(c1 < 0x80)
-	{
-		p_global->displayFlags = DisplayFlags::dfFlag1;
+	void clicplanval() {
+		if ((p_global->partyOutside & PersonMask::pmDina) && p_global->phaseNum == 371) {
+			quitmiroir();
+			maj_salle(p_global->roomNum);
+			return;
+		}
+		if (p_global->roomNum == 8 || p_global->roomNum < 16)
+			return;
+		rundcurs();
+		afficher();
+		if (p_global->displayFlags == DisplayFlags::dfMirror)
+			quitmiroir();
+		deplaval((p_global->roomNum & 0xFF00) | 1); //TODO: check me
+	}
+	void gotolieu(goto_t *go) {
+		p_global->valleyVidNum = go->arriveVid;
+		p_global->travelTime = go->travelTime * 256;
+		p_global->stepsToFindAppleFast = 0;
+		p_global->eventType = EventType::etEvent2;
 		init_oui();
-		p_global->eventType = EventType::etEvent1;
 		showevents();
-		if(!verif_oui())
+		if (!verif_oui())
 			return;
-		if(p_global->ff_113)
-		{
+		if (p_global->ff_113) {
 			waitendspeak();
-			if(!pomme_q)
+			if (!pomme_q)
 				close_perso();
 		}
-		specialout();
-		if(p_global->area_ptr->type == AreaType::atValley)
-		{
-			temps_passe(32);
-			p_global->stepsToFindAppleFast++;
-			p_global->stepsToFindAppleNormal++;
+		if (go->departVid) {
+			bars_out();
+			playhnm(go->departVid);
+			needToFade = 1;
 		}
-		faire_suivre((roomNum & 0xFF00) | p_global->newLocation);
+		initlieu(p_global->newRoomNum);
+		specialoutside();
+		faire_suivre(p_global->newRoomNum);
+		closesalle();
+		saved_repadam.x = -1;
+		saved_repadam.y = -1;
+		temps_passe(p_global->travelTime);
 		p_global->ff_100 = p_global->room_ptr->ff_0;
-		p_global->roomNum = roomNum;
-		p_global->areaNum = roomNum >> 8;
+		p_global->roomNum = p_global->newRoomNum;
+		p_global->areaNum = p_global->roomNum >> 8;
 		p_global->eventType = EventType::etEvent5;
+		p_global->newMusicType = MusicType::mt2;
 		setpersohere();
-		p_global->newMusicType = MusicType::mtNormal;
 		musique();
-		majsalle1(roomNum);
-		p_global->chrono_on = 0;
-		p_global->chrono = 0;
-		p_global->ff_54 = 0;
-		if(p_global->roomPersoType == PersonFlags::pftTyrann)
-			chronoon(3000);
-		return;
-	}
-	if(c1 == 0xFF)
-	{
-		p_global->eventType = EventType::etEventE;
-		showevents();
-		if(!kPersons[PER_MESSAGER].roomNum)
-		{
-			if(eloirevientq())
-				chronoon(800);
+		majsalle1(p_global->roomNum);
+		afftopscr();
+		saved_repadam.x = -1;
+		saved_repadam.y = -1;
+	}
+	void deplaval(unsigned short roomNum) {
+		unsigned char c1, newAreaNum, curAreaNum;
+		short newRoomNum;
+		p_global->newLocation = roomNum & 0xFF;
+		p_global->valleyVidNum = 0;
+		p_global->phaseActionsCount++;
+		closesalle();
+		endpersovox();
+		c1 = roomNum & 0xFF;
+		if (c1 == 0)
+			return;
+		if (c1 < 0x80) {
+			p_global->displayFlags = DisplayFlags::dfFlag1;
+			init_oui();
+			p_global->eventType = EventType::etEvent1;
+			showevents();
+			if (!verif_oui())
+				return;
+			if (p_global->ff_113) {
+				waitendspeak();
+				if (!pomme_q)
+					close_perso();
+			}
+			specialout();
+			if (p_global->area_ptr->type == AreaType::atValley) {
+				temps_passe(32);
+				p_global->stepsToFindAppleFast++;
+				p_global->stepsToFindAppleNormal++;
+			}
+			faire_suivre((roomNum & 0xFF00) | p_global->newLocation);
+			p_global->ff_100 = p_global->room_ptr->ff_0;
+			p_global->roomNum = roomNum;
+			p_global->areaNum = roomNum >> 8;
+			p_global->eventType = EventType::etEvent5;
+			setpersohere();
+			p_global->newMusicType = MusicType::mtNormal;
+			musique();
+			majsalle1(roomNum);
+			p_global->chrono_on = 0;
+			p_global->chrono = 0;
+			p_global->ff_54 = 0;
+			if (p_global->roomPersoType == PersonFlags::pftTyrann)
+				chronoon(3000);
+			return;
 		}
-		return;
-	}
-	p_global->stepsToFindAppleFast = 0;
-	newAreaNum = c1 & 0x7F;
-	curAreaNum = p_global->roomNum >> 8;
-	newRoomNum = newAreaNum << 8;
-	if(curAreaNum == Areas::arTausCave && newAreaNum == Areas::arMo)
-		newRoomNum |= 0x16;
-	else if(curAreaNum == Areas::arMoorkusLair)
-		newRoomNum |= 4;
-	else
-		newRoomNum |= 1;
-	p_global->newRoomNum = newRoomNum;
-	if(newAreaNum == Areas::arTausCave)
-		gotolieu(&gotos[0]);
-	else
-	{
-		goto_t *go;
-		for(go = gotos + 1;go->curAreaNum != 0xFF;go++)
-			if(go->curAreaNum == curAreaNum)
-			{
-				gotolieu(go);
-				break;
+		if (c1 == 0xFF) {
+			p_global->eventType = EventType::etEventE;
+			showevents();
+			if (!kPersons[PER_MESSAGER].roomNum) {
+				if (eloirevientq())
+					chronoon(800);
 			}
+			return;
+		}
+		p_global->stepsToFindAppleFast = 0;
+		newAreaNum = c1 & 0x7F;
+		curAreaNum = p_global->roomNum >> 8;
+		newRoomNum = newAreaNum << 8;
+		if (curAreaNum == Areas::arTausCave && newAreaNum == Areas::arMo)
+			newRoomNum |= 0x16;
+		else if (curAreaNum == Areas::arMoorkusLair)
+			newRoomNum |= 4;
+		else
+			newRoomNum |= 1;
+		p_global->newRoomNum = newRoomNum;
+		if (newAreaNum == Areas::arTausCave)
+			gotolieu(&gotos[0]);
+		else {
+			goto_t *go;
+			for (go = gotos + 1; go->curAreaNum != 0xFF; go++)
+				if (go->curAreaNum == curAreaNum) {
+					gotolieu(go);
+					break;
+				}
+		}
 	}
-}
-void deplacement(short dir)
-{
-	room_t *room = p_global->room_ptr;
-	short roomNum = p_global->roomNum;
-	debug("deplacement: from room %4X", roomNum);
-	char newLoc;
-	rundcurs();
-	afficher();
-	p_global->prevLocation = roomNum & 0xFF;
-	switch(dir)
-	{
-	case 0: newLoc = room->exits[0]; break;
-	case 1: newLoc = room->exits[1]; break;
-	case 2: newLoc = room->exits[2]; break;
-	case 3: newLoc = room->exits[3]; break;
-	}
-	deplaval((roomNum & 0xFF00) | newLoc);
-}    
-void deplacement2(short dir)
-{
-	room_t *room = p_global->room_ptr;
-	short roomNum = p_global->roomNum;
-	char newLoc;
-	p_global->prevLocation = roomNum & 0xFF;
-	switch(dir)
-	{
-	case 0: newLoc = room->exits[0]; break;
-	case 1: newLoc = room->exits[1]; break;
-	case 2: newLoc = room->exits[2]; break;
-	case 3: newLoc = room->exits[3]; break;
-	}
-	deplaval((roomNum & 0xFF00) | newLoc);
+	void deplacement(short dir) {
+		room_t *room = p_global->room_ptr;
+		short roomNum = p_global->roomNum;
+		debug("deplacement: from room %4X", roomNum);
+		char newLoc;
+		rundcurs();
+		afficher();
+		p_global->prevLocation = roomNum & 0xFF;
+		switch (dir) {
+		case 0:
+			newLoc = room->exits[0];
+			break;
+		case 1:
+			newLoc = room->exits[1];
+			break;
+		case 2:
+			newLoc = room->exits[2];
+			break;
+		case 3:
+			newLoc = room->exits[3];
+			break;
+		}
+		deplaval((roomNum & 0xFF00) | newLoc);
+	}
+	void deplacement2(short dir) {
+		room_t *room = p_global->room_ptr;
+		short roomNum = p_global->roomNum;
+		char newLoc;
+		p_global->prevLocation = roomNum & 0xFF;
+		switch (dir) {
+		case 0:
+			newLoc = room->exits[0];
+			break;
+		case 1:
+			newLoc = room->exits[1];
+			break;
+		case 2:
+			newLoc = room->exits[2];
+			break;
+		case 3:
+			newLoc = room->exits[3];
+			break;
+		}
+		deplaval((roomNum & 0xFF00) | newLoc);
 
-}
-void dinosoufle()
-{
-	if(p_global->curObjectId == 0)
-	{
-		bars_out();
-		playhnm(148);
-		maj2();
 	}
-}
-void plaquemonk()
-{
-	if(p_global->curObjectId != 0)
-	{
-		if(p_global->curObjectId == Objects::obPrism)
-		{
-			loseobject(Objects::obPrism);
+	void dinosoufle() {
+		if (p_global->curObjectId == 0) {
 			bars_out();
-			specialTextMode = 1;
-			playhnm(89);
-			word_2F514 |= 0x8000;
+			playhnm(148);
+			maj2();
+		}
+	}
+	void plaquemonk() {
+		if (p_global->curObjectId != 0) {
+			if (p_global->curObjectId == Objects::obPrism) {
+				loseobject(Objects::obPrism);
+				bars_out();
+				specialTextMode = 1;
+				playhnm(89);
+				word_2F514 |= 0x8000;
+				maj2();
+				p_global->eventType = EventType::etEventB;
+				showevents();
+			}
+		} else {
+			bars_out();
+			playhnm(7);
 			maj2();
-			p_global->eventType = EventType::etEventB;
+			p_global->eventType = EventType::etEvent4;
 			showevents();
 		}
 	}
-	else
-	{
-		bars_out();
-		playhnm(7);
-		maj2();
-		p_global->eventType = EventType::etEvent4;
-		showevents();
+	void fresquesgraa() {
+		if (p_global->curObjectId == 0) {
+			p_global->fresqWidth = 320;
+			p_global->fresqImgBank = 113;
+			dofresques();
+			dinaparle();
+		}
 	}
-}
-void fresquesgraa()
-{
-	if(p_global->curObjectId == 0)
-	{
-		p_global->fresqWidth = 320;
-		p_global->fresqImgBank = 113;
-		dofresques();
-		dinaparle();
+	void fresqueslasc() {
+		if (p_global->curObjectId == 0) {
+			p_global->fresqWidth = 112;
+			p_global->fresqImgBank = 315;
+			dofresques();
+		}
 	}
-}
-void fresqueslasc()
-{
-	if(p_global->curObjectId == 0)
-	{
-		p_global->fresqWidth = 112;
-		p_global->fresqImgBank = 315;
-		dofresques();
+	void pushpierre() {
+		if (p_global->curObjectId == 0) {
+			gameRooms[22].exits[0] = 17;
+			gameRooms[26].exits[2] = 9;
+			deplacement(0);
+		}
 	}
-}
-void pushpierre()
-{
-	if(p_global->curObjectId == 0)
-	{
-		gameRooms[22].exits[0] = 17;
-		gameRooms[26].exits[2] = 9;
-		deplacement(0);
+	void tetemomie() {
+		if (p_global->curObjectId == Objects::obTooth) {
+			p_global->gameFlags |= GameFlags::gfMummyOpened;
+			deplacement(0);
+		} else if (p_global->curObjectId == 0) {
+			if (p_global->gameFlags & GameFlags::gfMummyOpened)
+				deplacement(0);
+			else {
+				p_global->eventType = EventType::etEvent6;
+				persoparle(PersonId::pidMonk);
+				p_global->eventType = 0;
+			}
+		}
 	}
-}
-void tetemomie()
-{
-	if(p_global->curObjectId == Objects::obTooth)
-	{
-		p_global->gameFlags |= GameFlags::gfMummyOpened;
-		deplacement(0);
-	}
-	else if(p_global->curObjectId == 0)
-	{
-		if(p_global->gameFlags & GameFlags::gfMummyOpened)
+	void tetesquel() {
+		if (p_global->curObjectId == Objects::obTooth) {
+			gameRooms[22].exits[0] = 16;
+			gameRooms[26].exits[2] = 13;
+			gameIcons[16].cursor_id |= 0x8000;
+			loseobject(Objects::obTooth);
 			deplacement(0);
-		else
-		{
-			p_global->eventType = EventType::etEvent6;
-			persoparle(PersonId::pidMonk);
-			p_global->eventType = 0;
 		}
 	}
-}
-void tetesquel()
-{
-	if(p_global->curObjectId == Objects::obTooth)
-	{
-		gameRooms[22].exits[0] = 16;
-		gameRooms[26].exits[2] = 13;
-		gameIcons[16].cursor_id |= 0x8000;
-		loseobject(Objects::obTooth);
-		deplacement(0);
+	void squelmoorkong() {
+		p_global->eventType = EventType::etEvent9;
+		showevents();
 	}
-}
-void squelmoorkong()
-{
-	p_global->eventType = EventType::etEvent9;
-	showevents();
-}
-void choisir()
-{
-	unsigned char obj, objid = current_spot2->object_id;
-	switch(objid)
-	{
-	case 0: obj = p_global->giveobj1; break;
-	case 1: obj = p_global->giveobj2; break;
-	case 2: obj = p_global->giveobj3; break;
-	}
-	objectmain(obj);
-	winobject(obj);
-	p_global->iconsIndex = 16;
-	p_global->autoDialog = 0;
-	p_global->ff_60 = 0;
-	parle_moi();
-}
-void dinaparle()
-{
-	short num;
-	char res;
-	perso_t *perso = &kPersons[PER_DINA];
-	if(perso->party & (p_global->party | p_global->partyOutside))
-	{
-		if(p_global->fresqNumber < 3)
-			p_global->fresqNumber = 3;
-		p_global->fresqNumber++;
-		if(p_global->fresqNumber < 15)
-		{
-			endpersovox();
-			if(p_global->fresqNumber == 7 && p_global->phaseNum == 113)
-				incphase1();
-			p_global->perso_ptr = perso;
-			p_global->dialogType = DialogType::dtInspect;
-			num = (perso->id << 3) | DialogType::dtInspect;	//TODO: combine
-			res = dialoscansvmas((dial_t*)GetElem(gameDialogs, num));
-			fresqTalk = 0;
-			if(res)
-			{
-				restaurefondbulle();
-				fresqTalk = 1;
-				persovox();
-			}
-			p_global->ff_CA = 0;
-			p_global->dialogType = 0;
+	void choisir() {
+		unsigned char obj, objid = current_spot2->object_id;
+		switch (objid) {
+		case 0:
+			obj = p_global->giveobj1;
+			break;
+		case 1:
+			obj = p_global->giveobj2;
+			break;
+		case 2:
+			obj = p_global->giveobj3;
+			break;
 		}
-		else
-			finfresques();
+		objectmain(obj);
+		winobject(obj);
+		p_global->iconsIndex = 16;
+		p_global->autoDialog = 0;
+		p_global->ff_60 = 0;
+		parle_moi();
 	}
-}
-void roiparle()
-{
-	if(p_global->phaseNum <= 400)
-		persoparle(0);
-}
-void roiparle1()
-{
-	if(p_global->curObjectId == Objects::obSword)
-	{
-		p_global->gameFlags |= GameFlags::gfFlag80;
-		bars_out();
-		playhnm(76);
-		deplacement2(0);
+	void dinaparle() {
+		short num;
+		char res;
+		perso_t *perso = &kPersons[PER_DINA];
+		if (perso->party & (p_global->party | p_global->partyOutside)) {
+			if (p_global->fresqNumber < 3)
+				p_global->fresqNumber = 3;
+			p_global->fresqNumber++;
+			if (p_global->fresqNumber < 15) {
+				endpersovox();
+				if (p_global->fresqNumber == 7 && p_global->phaseNum == 113)
+					incphase1();
+				p_global->perso_ptr = perso;
+				p_global->dialogType = DialogType::dtInspect;
+				num = (perso->id << 3) | DialogType::dtInspect; //TODO: combine
+				res = dialoscansvmas((dial_t *)GetElem(gameDialogs, num));
+				fresqTalk = 0;
+				if (res) {
+					restaurefondbulle();
+					fresqTalk = 1;
+					persovox();
+				}
+				p_global->ff_CA = 0;
+				p_global->dialogType = 0;
+			} else
+				finfresques();
+		}
+	}
+	void roiparle() {
+		if (p_global->phaseNum <= 400)
+			persoparle(0);
+	}
+	void roiparle1() {
+		if (p_global->curObjectId == Objects::obSword) {
+			p_global->gameFlags |= GameFlags::gfFlag80;
+			bars_out();
+			playhnm(76);
+			deplacement2(0);
+		} else {
+			p_global->fresqNumber = 1;
+			roiparle();
+		}
 	}
-	else
-	{
-		p_global->fresqNumber = 1;
+	void roiparle2() {
+		p_global->fresqNumber = 2;
 		roiparle();
 	}
-}
-void roiparle2()
-{
-	p_global->fresqNumber = 2;
-	roiparle();
-}
-void roiparle3()
-{
-	p_global->fresqNumber = 3;
-	roiparle();
-}
-void getcouteau()
-{
-	if(p_global->phaseNum >= 80)
-	{
-		gameRooms[113].video = 0;
-		getobject(Objects::obKnife);
+	void roiparle3() {
+		p_global->fresqNumber = 3;
+		roiparle();
 	}
-	p_global->eventType = EventType::etEvent7;
-	showevents();
-}
-void getprisme()
-{
-	getobject(Objects::obPrism);
-	p_global->eventType = EventType::etEvent7;
-	showevents();
-}
-void getchampb()
-{
-	getobject(Objects::obShroom);
-}
-void getchampm()
-{
-	getobject(Objects::obBadShroom);
-}
-void getor()
-{
-	getobject(Objects::obGold);
-}
-void getnido()
-{
-	if(p_global->curObjectId != 0)
-		return;
-	p_global->room_ptr->bank = 282;	//TODO: fix me
-	p_global->room_ptr--;
-	p_global->room_ptr->bank = 281;	//TODO: fix me
-	p_global->room_ptr->ff_0 = 3;
-	getobject(Objects::obFullNest);
-}
-void getnidv()
-{
-	if(p_global->curObjectId != 0)
-		return;
-	p_global->room_ptr->bank = 282;	//TODO: fix me
-	p_global->room_ptr--;
-	p_global->room_ptr->bank = 281;	//TODO: fix me
-	p_global->room_ptr->ff_0 = 3;
-	getobject(Objects::obNest);
-}
-void getcorne()
-{
-	if(p_global->curObjectId != 0)
-		return;
-	getobject(Objects::obHorn);
-	p_global->eventType = EventType::etEvent7;
-	showevents();
-	bigphase1();
-	setpersohere();
-	p_global->room_ptr = getsalle(p_global->roomNum);
-}
-void getsoleil()
-{
-	if(p_global->curObjectId != 0)
-		return;
-	gameRooms[238].video = 0;
-	gameRooms[238].flags = RoomFlags::rf80;
-	getobject(Objects::obSunStone);
-}
-void getoeuf()
-{
-	if(p_global->curObjectId != 0)
-		return;
-	p_global->room_ptr->flags = 0;
-	p_global->room_ptr->video = 0;
-	getobject(Objects::obEgg);
-}
-void getplaque()
-{
-	int i;
-	if(p_global->curObjectId != 0 && p_global->curObjectId < Objects::obTablet1)
-		return;
-	p_global->curObjectId = 0;
-	getobject(Objects::obTablet2);
-	putobject();
-	for(i = 0;i < 6;i++)
-		objects[Objects::obTablet1 - 1 + i].count = 0;
-	p_global->curObjectFlags = 0;
-	p_global->inventoryScrollPos = 0;
-	p_global->curObjectCursor = 9;
-	gameIcons[16].cursor_id |= 0x8000;
-	showobjects();
-	gameRooms[131].video = 0;
-	bars_out();
-	playhnm(149);
-	p_global->ff_F1 = RoomFlags::rf04;
-	p_global->drawFlags = DrawFlags::drDrawFlag20;
-	normalCursor = 1;
-	maj2();
-}
-void voirlac()
-{
-	perso_t *perso = &kPersons[PER_MORKUS];
-	room_t *room = p_global->room_ptr;
-	area_t *area = p_global->area_ptr;
-	short vid = p_global->curObjectId == Objects::obApple ? 81 : 54;
-	for(++perso;perso->roomNum != 0xFFFF;perso++)
-	{
-		if(perso->roomNum != p_global->roomNum)
-			continue;
-		vid++;
-		if (p_global->curObjectId != Objects::obApple)
-			continue;					//TODO: pc breaks here
-		if((perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftMosasaurus)
-			continue;
-		if (!(perso->flags & PersonFlags::pf80))
+	void getcouteau() {
+		if (p_global->phaseNum >= 80) {
+			gameRooms[113].video = 0;
+			getobject(Objects::obKnife);
+		}
+		p_global->eventType = EventType::etEvent7;
+		showevents();
+	}
+	void getprisme() {
+		getobject(Objects::obPrism);
+		p_global->eventType = EventType::etEvent7;
+		showevents();
+	}
+	void getchampb() {
+		getobject(Objects::obShroom);
+	}
+	void getchampm() {
+		getobject(Objects::obBadShroom);
+	}
+	void getor() {
+		getobject(Objects::obGold);
+	}
+	void getnido() {
+		if (p_global->curObjectId != 0)
 			return;
-		perso->flags &= ~PersonFlags::pf80;	//TODO: useless? see above
-		area->flags |= AreaFlags::afFlag8;
-		p_global->curAreaFlags |= AreaFlags::afFlag8;
-		room->ff_0 = 3;
-	}
-	debug("sea monster: room = %X, d0 = %X\n", p_global->roomNum, p_global->roomImgBank);
-	bars_out();
-	playhnm(vid);
-	maj_salle(p_global->roomNum);			//TODO: getting memory trashed here?
-	if (p_global->curObjectId == Objects::obApple)
-		loseobject(Objects::obApple);
-	p_global->eventType = EventType::etEventF;
-	showevents();
-}
-void gotohall()
-{
-	p_global->prevLocation = p_global->roomNum & 0xFF;
-	deplaval((p_global->roomNum & 0xFF00) | 6);
-}
-void demitourlabi()
-{
-	unsigned short target;
-	p_global->prevLocation = p_global->roomNum & 0xFF;
-	p_global->ff_100 = -1;
-	target = (p_global->roomNum & 0xFF00) | p_global->room_ptr->exits[2];
-	faire_suivre(target);
-	p_global->roomNum = target;
-	p_global->eventType = EventType::etEvent5;
-	maj_salle(p_global->roomNum);
-}
-void gotonido()
-{
-	p_global->room_ptr++;
-	p_global->eventType = 0;
-	p_global->roomImgBank = p_global->room_ptr->bank;
-	p_global->roomVidNum = p_global->room_ptr->video;
-	p_global->curRoomFlags = p_global->room_ptr->flags;
-	p_global->ff_F1 = p_global->room_ptr->flags;
-	animpiece();
-	p_global->ff_100 = 0;
-	maj2();	
-}
-void gotoval()
-{
-	unsigned short target = p_global->roomNum;
-	char obj;
-	rundcurs();
-	afficher();
-	scroll_pos = 0;
-	obj = current_spot2->object_id - 14;	//TODO
-	p_global->prevLocation = target & 0xFF;
-	deplaval((target & 0xFF00) | obj);	//TODO careful!
-}
-void visiter()
-{
-	bars_out();
-	playhnm(144);
-	p_global->ff_F1 = RoomFlags::rf04;
-	maj2();
-}
-void final()
-{
-	if(p_global->curObjectId != 0)
-		return;
-	bars_out();
-	*(short*)(gameRooms + 0x6DC) = 319;	//TODO
-	p_global->roomImgBank = 319;
-	playhnm(97);
-	maj2();
-	p_global->eventType = EventType::etEvent12;
-	showevents();
-	p_global->narratorSequence = 54;
-}
-void goto_nord()
-{
-	if(p_global->curObjectId == 0)
-		deplacement(0);
-}
-void goto_est()
-{
-	if(p_global->curObjectId == 0)
-		deplacement(1);
-}
-void goto_sud()
-{
-	if(p_global->curObjectId == 0)
-		deplacement(2);
-}
-void goto_ouest()
-{
-	if(p_global->curObjectId == 0)
-		deplacement(3);
-}
-void afficher()
-{
-	if(!p_global->ff_102 && !p_global->ff_103)
-	{
-		if(needPaletteUpdate)
-		{
-			needPaletteUpdate = 0;
-			CLPalette_Send2Screen(global_palette, 0, 256);
+		p_global->room_ptr->bank = 282; //TODO: fix me
+		p_global->room_ptr--;
+		p_global->room_ptr->bank = 281; //TODO: fix me
+		p_global->room_ptr->ff_0 = 3;
+		getobject(Objects::obFullNest);
+	}
+	void getnidv() {
+		if (p_global->curObjectId != 0)
+			return;
+		p_global->room_ptr->bank = 282; //TODO: fix me
+		p_global->room_ptr--;
+		p_global->room_ptr->bank = 281; //TODO: fix me
+		p_global->room_ptr->ff_0 = 3;
+		getobject(Objects::obNest);
+	}
+	void getcorne() {
+		if (p_global->curObjectId != 0)
+			return;
+		getobject(Objects::obHorn);
+		p_global->eventType = EventType::etEvent7;
+		showevents();
+		bigphase1();
+		setpersohere();
+		p_global->room_ptr = getsalle(p_global->roomNum);
+	}
+	void getsoleil() {
+		if (p_global->curObjectId != 0)
+			return;
+		gameRooms[238].video = 0;
+		gameRooms[238].flags = RoomFlags::rf80;
+		getobject(Objects::obSunStone);
+	}
+	void getoeuf() {
+		if (p_global->curObjectId != 0)
+			return;
+		p_global->room_ptr->flags = 0;
+		p_global->room_ptr->video = 0;
+		getobject(Objects::obEgg);
+	}
+	void getplaque() {
+		int i;
+		if (p_global->curObjectId != 0 && p_global->curObjectId < Objects::obTablet1)
+			return;
+		p_global->curObjectId = 0;
+		getobject(Objects::obTablet2);
+		putobject();
+		for (i = 0; i < 6; i++)
+			objects[Objects::obTablet1 - 1 + i].count = 0;
+		p_global->curObjectFlags = 0;
+		p_global->inventoryScrollPos = 0;
+		p_global->curObjectCursor = 9;
+		gameIcons[16].cursor_id |= 0x8000;
+		showobjects();
+		gameRooms[131].video = 0;
+		bars_out();
+		playhnm(149);
+		p_global->ff_F1 = RoomFlags::rf04;
+		p_global->drawFlags = DrawFlags::drDrawFlag20;
+		normalCursor = 1;
+		maj2();
+	}
+	void voirlac() {
+		perso_t *perso = &kPersons[PER_MORKUS];
+		room_t *room = p_global->room_ptr;
+		area_t *area = p_global->area_ptr;
+		short vid = p_global->curObjectId == Objects::obApple ? 81 : 54;
+		for (++perso; perso->roomNum != 0xFFFF; perso++) {
+			if (perso->roomNum != p_global->roomNum)
+				continue;
+			vid++;
+			if (p_global->curObjectId != Objects::obApple)
+				continue;                   //TODO: pc breaks here
+			if ((perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftMosasaurus)
+				continue;
+			if (!(perso->flags & PersonFlags::pf80))
+				return;
+			perso->flags &= ~PersonFlags::pf80; //TODO: useless? see above
+			area->flags |= AreaFlags::afFlag8;
+			p_global->curAreaFlags |= AreaFlags::afFlag8;
+			room->ff_0 = 3;
 		}
-		CLBlitter_CopyView2Screen(p_mainview);
+		debug("sea monster: room = %X, d0 = %X\n", p_global->roomNum, p_global->roomImgBank);
+		bars_out();
+		playhnm(vid);
+		maj_salle(p_global->roomNum);           //TODO: getting memory trashed here?
+		if (p_global->curObjectId == Objects::obApple)
+			loseobject(Objects::obApple);
+		p_global->eventType = EventType::etEventF;
+		showevents();
 	}
-	else
-	{
-		if(p_global->ff_102)
-			effet3();
-		else
-			effet2();
-		p_global->ff_103 = 0;
-		p_global->ff_102 = 0;
+	void gotohall() {
+		p_global->prevLocation = p_global->roomNum & 0xFF;
+		deplaval((p_global->roomNum & 0xFF00) | 6);
 	}
-}
-void afficher128()
-{
-	if(p_global->updatePaletteFlag == 16)
-	{
-		CLPalette_Send2Screen(global_palette, 0, 129);
-		CLBlitter_CopyView2Screen(p_mainview);
-		p_global->updatePaletteFlag = 0;
+	void demitourlabi() {
+		unsigned short target;
+		p_global->prevLocation = p_global->roomNum & 0xFF;
+		p_global->ff_100 = -1;
+		target = (p_global->roomNum & 0xFF00) | p_global->room_ptr->exits[2];
+		faire_suivre(target);
+		p_global->roomNum = target;
+		p_global->eventType = EventType::etEvent5;
+		maj_salle(p_global->roomNum);
 	}
-	else
-	{
-		ClearScreen();
-		fadetoblack128(1);
-		if(showBlackBars)
-			blackbars();
-		CLBlitter_CopyView2Screen(p_mainview);
-		fadefromblack128(1);
+	void gotonido() {
+		p_global->room_ptr++;
+		p_global->eventType = 0;
+		p_global->roomImgBank = p_global->room_ptr->bank;
+		p_global->roomVidNum = p_global->room_ptr->video;
+		p_global->curRoomFlags = p_global->room_ptr->flags;
+		p_global->ff_F1 = p_global->room_ptr->flags;
+		animpiece();
+		p_global->ff_100 = 0;
+		maj2();
 	}
-}
-void sauvefrises()
-{
-	sauvefriseshaut(0);
-	sauvefrisesbas();
-}
-void sauvefriseshaut(short x)	// Save top bar
-{
-	underTopBarScreenRect.sy = 0;		//TODO: wrong fields order?
-	underTopBarScreenRect.sx = x;
-	underTopBarScreenRect.ex = x + 320 - 1;
-	underTopBarScreenRect.ey = 15;
-	underTopBarBackupRect.sy = 0;
-	underTopBarBackupRect.sx = 0;
-	underTopBarBackupRect.ex = 320 - 1;
-	underTopBarBackupRect.ey = 15;
-	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
-}
-void sauvefrisesbas()			// Save bottom bar
-{
-	underBottomBarScreenRect.sx = 0;
-	underBottomBarScreenRect.ex = 320 - 1;
-	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
-}
-void restaurefrises()
-{
-	restaurefriseshaut();
-	restaurefrisesbas();
-}
-void restaurefriseshaut()
-{
-	underTopBarScreenRect.sx = scroll_pos;
-	underTopBarScreenRect.ex = scroll_pos + 320 - 1;
-	CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarBackupRect, &underTopBarScreenRect);
-}
-void restaurefrisesbas()
-{
-	underBottomBarScreenRect.sx = scroll_pos;
-	underBottomBarScreenRect.ex = scroll_pos + 320 - 1;
-	CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underBottomBarBackupRect, &underBottomBarScreenRect);
-}
-void use_main_bank()
-{
-	bank_data_ptr = main_bank_buf;
-}
-void use_bank(short bank)
-{
-	if (bank > 2500)
-		debug("attempt to load bad bank %d", bank);
-	bank_data_ptr = bank_data_buf;
-	if(cur_bank_num != bank)
-	{
-		loadfile(bank, bank_data_buf);
-		verifh(bank_data_buf);
-		cur_bank_num = bank;
-	}
-}    
-void sundcurs(short x, short y)
-{
-	unsigned char *scr, *keep = curs_keepbuf;
-	short w, h;
-	curs_keepx = x - 4;
-	curs_keepy = y - 4;
-	scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
-	for(h = 48;h--;)
-	{
-		for(w = 48;w--;)
-			*keep++ = *scr++;
-		scr += 640 - 48;
-	}
-	curs_saved = 1;
-}
-void rundcurs()
-{
-	unsigned char *scr, *keep = curs_keepbuf;
-	short w, h;
-	scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
-	if(!curs_saved || (curs_keepx == -1 && curs_keepy == -1))	//TODO ...
-		return;
-	for(h = 48;h--;)
-	{
-		for(w = 48;w--;)
-			*scr++ = *keep++;
-		scr += 640 - 48;
+	void gotoval() {
+		unsigned short target = p_global->roomNum;
+		char obj;
+		rundcurs();
+		afficher();
+		scroll_pos = 0;
+		obj = current_spot2->object_id - 14;    //TODO
+		p_global->prevLocation = target & 0xFF;
+		deplaval((target & 0xFF00) | obj);  //TODO careful!
 	}
-	
-}
-void noclipax(short index, short x, short y)
-{
-	unsigned char *pix = bank_data_ptr;
-	unsigned char *scr = p_mainview_buf + x + y * 640;
-	unsigned char h0, h1, mode;
-	short w, h;
-	if(cur_bank_num != 117 && !no_palette)
-	{
-		if(PLE16(pix) > 2)
-			readpalette(pix + 2);
-	}
-	pix += PLE16(pix);
-	pix += PLE16(pix + index * 2);
-	//	short	height:9
-	//	short	pad:6;
-	//	short	flag:1;
-	h0 = *pix++;
-	h1 = *pix++;
-	w = ((h1 & 1) << 8) | h0;
-	h = *pix++;
-	mode = *pix++;
-	debug("- draw sprite %d at %d:%d, %dx%d", index, x, y, w, h);
-	if (mode != 0xFF && mode != 0xFE)
-		return;
-	if(y + h > 200)
-		h -= (y + h - 200);
-	if(h1 & 0x80)
-	{
-	// compressed
-		for(;h-- > 0;)
-		{
-			short ww;
-			for(ww = w;ww > 0;)
-			{
-				unsigned char c = *pix++;
-				if(c >= 0x80)
-				{
-					if(c == 0x80)
-					{
-						unsigned char fill = *pix++;
-						if(fill == 0)
-						{
-							scr += 128 + 1;
-							ww -= 128 + 1;
-						}
-						else
-						{
-							unsigned char run;
-							*scr++ = fill;	//TODO: wha?
-							*scr++ = fill;
-							ww -= 128 + 1;
-							for(run = 127;run--;)
+	void visiter() {
+		bars_out();
+		playhnm(144);
+		p_global->ff_F1 = RoomFlags::rf04;
+		maj2();
+	}
+	void final() {
+		if (p_global->curObjectId != 0)
+			return;
+		bars_out();
+		*(short *)(gameRooms + 0x6DC) = 319; //TODO
+		p_global->roomImgBank = 319;
+		playhnm(97);
+		maj2();
+		p_global->eventType = EventType::etEvent12;
+		showevents();
+		p_global->narratorSequence = 54;
+	}
+	void goto_nord() {
+		if (p_global->curObjectId == 0)
+			deplacement(0);
+	}
+	void goto_est() {
+		if (p_global->curObjectId == 0)
+			deplacement(1);
+	}
+	void goto_sud() {
+		if (p_global->curObjectId == 0)
+			deplacement(2);
+	}
+	void goto_ouest() {
+		if (p_global->curObjectId == 0)
+			deplacement(3);
+	}
+	void afficher() {
+		if (!p_global->ff_102 && !p_global->ff_103) {
+			if (needPaletteUpdate) {
+				needPaletteUpdate = 0;
+				CLPalette_Send2Screen(global_palette, 0, 256);
+			}
+			CLBlitter_CopyView2Screen(p_mainview);
+		} else {
+			if (p_global->ff_102)
+				effet3();
+			else
+				effet2();
+			p_global->ff_103 = 0;
+			p_global->ff_102 = 0;
+		}
+	}
+	void afficher128() {
+		if (p_global->updatePaletteFlag == 16) {
+			CLPalette_Send2Screen(global_palette, 0, 129);
+			CLBlitter_CopyView2Screen(p_mainview);
+			p_global->updatePaletteFlag = 0;
+		} else {
+			ClearScreen();
+			fadetoblack128(1);
+			if (showBlackBars)
+				blackbars();
+			CLBlitter_CopyView2Screen(p_mainview);
+			fadefromblack128(1);
+		}
+	}
+	void sauvefrises() {
+		sauvefriseshaut(0);
+		sauvefrisesbas();
+	}
+	void sauvefriseshaut(short x) { // Save top bar
+		underTopBarScreenRect.sy = 0;       //TODO: wrong fields order?
+		underTopBarScreenRect.sx = x;
+		underTopBarScreenRect.ex = x + 320 - 1;
+		underTopBarScreenRect.ey = 15;
+		underTopBarBackupRect.sy = 0;
+		underTopBarBackupRect.sx = 0;
+		underTopBarBackupRect.ex = 320 - 1;
+		underTopBarBackupRect.ey = 15;
+		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
+	}
+	void sauvefrisesbas() {         // Save bottom bar
+		underBottomBarScreenRect.sx = 0;
+		underBottomBarScreenRect.ex = 320 - 1;
+		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
+	}
+	void restaurefrises() {
+		restaurefriseshaut();
+		restaurefrisesbas();
+	}
+	void restaurefriseshaut() {
+		underTopBarScreenRect.sx = scroll_pos;
+		underTopBarScreenRect.ex = scroll_pos + 320 - 1;
+		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarBackupRect, &underTopBarScreenRect);
+	}
+	void restaurefrisesbas() {
+		underBottomBarScreenRect.sx = scroll_pos;
+		underBottomBarScreenRect.ex = scroll_pos + 320 - 1;
+		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underBottomBarBackupRect, &underBottomBarScreenRect);
+	}
+	void use_main_bank() {
+		bank_data_ptr = main_bank_buf;
+	}
+	void use_bank(short bank) {
+		if (bank > 2500)
+			debug("attempt to load bad bank %d", bank);
+		bank_data_ptr = bank_data_buf;
+		if (cur_bank_num != bank) {
+			loadfile(bank, bank_data_buf);
+			verifh(bank_data_buf);
+			cur_bank_num = bank;
+		}
+	}
+	void sundcurs(short x, short y) {
+		unsigned char *scr, *keep = curs_keepbuf;
+		short w, h;
+		curs_keepx = x - 4;
+		curs_keepy = y - 4;
+		scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
+		for (h = 48; h--;) {
+			for (w = 48; w--;)
+				*keep++ = *scr++;
+			scr += 640 - 48;
+		}
+		curs_saved = 1;
+	}
+	void rundcurs() {
+		unsigned char *scr, *keep = curs_keepbuf;
+		short w, h;
+		scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
+		if (!curs_saved || (curs_keepx == -1 && curs_keepy == -1))  //TODO ...
+			return;
+		for (h = 48; h--;) {
+			for (w = 48; w--;)
+				*scr++ = *keep++;
+			scr += 640 - 48;
+		}
+
+	}
+	void noclipax(short index, short x, short y) {
+		unsigned char *pix = bank_data_ptr;
+		unsigned char *scr = p_mainview_buf + x + y * 640;
+		unsigned char h0, h1, mode;
+		short w, h;
+		if (cur_bank_num != 117 && !no_palette) {
+			if (PLE16(pix) > 2)
+				readpalette(pix + 2);
+		}
+		pix += PLE16(pix);
+		pix += PLE16(pix + index * 2);
+		//  short   height:9
+		//  short   pad:6;
+		//  short   flag:1;
+		h0 = *pix++;
+		h1 = *pix++;
+		w = ((h1 & 1) << 8) | h0;
+		h = *pix++;
+		mode = *pix++;
+		debug("- draw sprite %d at %d:%d, %dx%d", index, x, y, w, h);
+		if (mode != 0xFF && mode != 0xFE)
+			return;
+		if (y + h > 200)
+			h -= (y + h - 200);
+		if (h1 & 0x80) {
+			// compressed
+			for (; h-- > 0;) {
+				short ww;
+				for (ww = w; ww > 0;) {
+					unsigned char c = *pix++;
+					if (c >= 0x80) {
+						if (c == 0x80) {
+							unsigned char fill = *pix++;
+							if (fill == 0) {
+								scr += 128 + 1;
+								ww -= 128 + 1;
+							} else {
+								unsigned char run;
+								*scr++ = fill;  //TODO: wha?
 								*scr++ = fill;
+								ww -= 128 + 1;
+								for (run = 127; run--;)
+									*scr++ = fill;
+							}
+						} else {
+							unsigned char fill = *pix++;
+							unsigned char run = 255 - c + 2;
+							ww -= run;
+							if (fill == 0)
+								scr += run;
+							else
+								for (; run--;)
+									*scr++ = fill;
 						}
-					}
-					else
-					{
-						unsigned char fill = *pix++;
-						unsigned char run = 255 - c + 2;
+					} else {
+						unsigned char run = c + 1;
 						ww -= run;
-						if(fill == 0)
-							scr += run;
-						else
-							for(;run--;)
-								*scr++ = fill;
+						for (; run--;) {
+							unsigned char p = *pix++;
+							if (p == 0)
+								scr++;
+							else
+								*scr++ = p;
+						}
 					}
 				}
-				else
-				{
-					unsigned char run = c + 1;
-					ww -= run;
-					for(;run--;)
-					{
-						unsigned char p = *pix++;
-						if(p == 0)
-							scr++;
-						else
-							*scr++ = p;
-					}
+				scr += 640 - w;
+			}
+		} else {
+			// uncompressed
+			for (; h--;) {
+				short ww;
+				for (ww = w; ww--;) {
+					unsigned char p = *pix++;
+					if (p == 0)
+						scr++;
+					else
+						*scr++ = p;
 				}
+				scr += 640 - w;
 			}
-			scr += 640 - w;
 		}
 	}
-	else
-	{
-		// uncompressed
-		for(;h--;)
-		{
-			short ww;
-			for(ww = w;ww--;)
-			{
-				unsigned char p = *pix++;
-				if(p == 0)
-					scr++;
-				else
-					*scr++ = p;
-			}
-			scr += 640 - w;
+	void noclipax_avecnoir(short index, short x, short y) {
+		unsigned char *pix = bank_data_ptr;
+		unsigned char *scr = p_mainview_buf + x + y * 640;
+		unsigned char h0, h1, mode;
+		short w, h;
+		if (cur_bank_num != 117) {
+			if (PLE16(pix) > 2)
+				readpalette(pix + 2);
 		}
-	}
-}
-void noclipax_avecnoir(short index, short x, short y)
-{
-	unsigned char *pix = bank_data_ptr;
-	unsigned char *scr = p_mainview_buf + x + y * 640;
-	unsigned char h0, h1, mode;
-	short w, h;
-	if(cur_bank_num != 117)
-	{
-		if(PLE16(pix) > 2)
-			readpalette(pix + 2);
-	}
-	pix += PLE16(pix);
-	pix += PLE16(pix + index * 2);
-	//	short	height:9
-	//	short	pad:6;
-	//	short	flag:1;
-	h0 = *pix++;
-	h1 = *pix++;
-	w = ((h1 & 1) << 8) | h0;
-	h = *pix++;
-	mode = *pix++;
-	if(mode != 0xFF && mode != 0xFE)
-		return;
-	if(y + h > 200)
-		h -= (y + h - 200);
-	if(h1 & 0x80)
-	{
-	// compressed
-		for(;h-- > 0;)
-		{
-			short ww;
-			for(ww = w;ww > 0;)
-			{
-				unsigned char c = *pix++;
-				if(c >= 0x80)
-				{
-					if(c == 0x80)
-					{
-						unsigned char fill = *pix++;
-						unsigned char run;
-						*scr++ = fill;	//TODO: wha?
-						*scr++ = fill;
-						ww -= 128 + 1;
-						for(run = 127;run--;)
+		pix += PLE16(pix);
+		pix += PLE16(pix + index * 2);
+		//  short   height:9
+		//  short   pad:6;
+		//  short   flag:1;
+		h0 = *pix++;
+		h1 = *pix++;
+		w = ((h1 & 1) << 8) | h0;
+		h = *pix++;
+		mode = *pix++;
+		if (mode != 0xFF && mode != 0xFE)
+			return;
+		if (y + h > 200)
+			h -= (y + h - 200);
+		if (h1 & 0x80) {
+			// compressed
+			for (; h-- > 0;) {
+				short ww;
+				for (ww = w; ww > 0;) {
+					unsigned char c = *pix++;
+					if (c >= 0x80) {
+						if (c == 0x80) {
+							unsigned char fill = *pix++;
+							unsigned char run;
+							*scr++ = fill;  //TODO: wha?
 							*scr++ = fill;
-					}
-					else
-					{
-						unsigned char fill = *pix++;
-						unsigned char run = 255 - c + 2;
+							ww -= 128 + 1;
+							for (run = 127; run--;)
+								*scr++ = fill;
+						} else {
+							unsigned char fill = *pix++;
+							unsigned char run = 255 - c + 2;
+							ww -= run;
+							for (; run--;)
+								*scr++ = fill;
+						}
+					} else {
+						unsigned char run = c + 1;
 						ww -= run;
-						for(;run--;)
-							*scr++ = fill;
+						for (; run--;) {
+							unsigned char p = *pix++;
+							*scr++ = p;
+						}
 					}
 				}
-				else
-				{
-					unsigned char run = c + 1;
-					ww -= run;
-					for(;run--;)
-					{
-						unsigned char p = *pix++;
-						*scr++ = p;
-					}
+				scr += 640 - w;
+			}
+		} else {
+			// uncompressed
+			for (; h--;) {
+				short ww;
+				for (ww = w; ww--;) {
+					unsigned char p = *pix++;
+					*scr++ = p;
 				}
+				scr += 640 - w;
 			}
-			scr += 640 - w;
 		}
 	}
-	else
-	{
-		// uncompressed
-		for(;h--;)
-		{
+	void getglow(short x, short y, short w, short h) {
+		unsigned char *scr = p_mainview_buf + x + y * 640;
+		unsigned char *gl = glow_buffer;
+		glow_x = x;
+		glow_y = y;
+		glow_w = w;
+		glow_h = h;
+		for (; h--;) {
 			short ww;
-			for(ww = w;ww--;)
-			{
-				unsigned char p = *pix++;
-				*scr++ = p;
-			}
+			for (ww = w; ww--;)
+				*gl++ = *scr++;
 			scr += 640 - w;
 		}
 	}
-}
-void getglow(short x, short y, short w, short h)
-{
-	unsigned char *scr = p_mainview_buf + x + y * 640;
-	unsigned char *gl = glow_buffer;
-	glow_x = x;
-	glow_y = y;
-	glow_w = w;
-	glow_h = h;
-	for(;h--;)
-	{
-		short ww;
-		for(ww = w;ww--;)
-			*gl++ = *scr++;
-		scr += 640 - w;
-	}
-}
-void unglow()
-{
-	unsigned char *gl = glow_buffer;
-	unsigned char *scr = p_mainview_buf + glow_x + glow_y * 640;
-	if(glow_x < 0 || glow_y < 0)	//TODO: move it up
-		return;
-	for(;glow_h--;)
-	{
-		short ww;
-		for(ww = glow_w;ww--;)
-			*scr++ = *gl++;
-		scr += 640 - glow_w;
+	void unglow() {
+		unsigned char *gl = glow_buffer;
+		unsigned char *scr = p_mainview_buf + glow_x + glow_y * 640;
+		if (glow_x < 0 || glow_y < 0)   //TODO: move it up
+			return;
+		for (; glow_h--;) {
+			short ww;
+			for (ww = glow_w; ww--;)
+				*scr++ = *gl++;
+			scr += 640 - glow_w;
+		}
 	}
-}
-void glow(short index)
-{
-	unsigned char pixbase;
-	unsigned char *pix = bank_data_ptr;
-	unsigned char *scr;
-	unsigned char h0, h1, mode;
-	short w, h, x, y, ex, dx, dy, pstride, sstride;
-	index += 9;
-	pix += PLE16(pix);
-	pix += PLE16(pix + index * 2);
-	//	short	height:9
-	//	short	pad:6;
-	//	short	flag:1;
-	h0 = *pix++;
-	h1 = *pix++;
-	w = ((h1 & 1) << 8) | h0;
-	h = *pix++;
-	mode = *pix++;
-	if(mode != 0xFF && mode != 0xFE)
-		return;
+	void glow(short index) {
+		unsigned char pixbase;
+		unsigned char *pix = bank_data_ptr;
+		unsigned char *scr;
+		unsigned char h0, h1, mode;
+		short w, h, x, y, ex, dx, dy, pstride, sstride;
+		index += 9;
+		pix += PLE16(pix);
+		pix += PLE16(pix + index * 2);
+		//  short   height:9
+		//  short   pad:6;
+		//  short   flag:1;
+		h0 = *pix++;
+		h1 = *pix++;
+		w = ((h1 & 1) << 8) | h0;
+		h = *pix++;
+		mode = *pix++;
+		if (mode != 0xFF && mode != 0xFE)
+			return;
 
-	x = curs_x + scroll_pos - 38;
-	y = curs_y - 28;
-	ex = p_global->fresqWidth + 320;
+		x = curs_x + scroll_pos - 38;
+		y = curs_y - 28;
+		ex = p_global->fresqWidth + 320;
 
-	if(x + w <= 0 || x >= ex || y + h <= 0 || y >= 176)
-		return;
+		if (x + w <= 0 || x >= ex || y + h <= 0 || y >= 176)
+			return;
 
-	if(x < 0)
-	{
-		dx = -x;
-		x = 0;
-	}
-	else if(x + w > ex)
-		dx = x + w - ex;
-	else
-		dx = 0;
+		if (x < 0) {
+			dx = -x;
+			x = 0;
+		} else if (x + w > ex)
+			dx = x + w - ex;
+		else
+			dx = 0;
 
-	if(y < 16)
-	{
-		dy = 16 - y;
-		y = 16;
-	}
-	else if(y + h > 175)
-		dy = y + h - 175;
-	else
-		dy = 0;
-	pstride = dx;
-	sstride = 640 - (w - dx);
-	if(y == 16)
-		pix += w * dy;
-	if(x == 0)
-		pix += dx;
+		if (y < 16) {
+			dy = 16 - y;
+			y = 16;
+		} else if (y + h > 175)
+			dy = y + h - 175;
+		else
+			dy = 0;
+		pstride = dx;
+		sstride = 640 - (w - dx);
+		if (y == 16)
+			pix += w * dy;
+		if (x == 0)
+			pix += dx;
 
-	scr = p_mainview_buf + x + y * 640;
+		scr = p_mainview_buf + x + y * 640;
 
-	w -= dx;
-	h -= dy;
+		w -= dx;
+		h -= dy;
 
-	getglow(x, y, w, h);
+		getglow(x, y, w, h);
 
-	for(;h--;)
-	{
-		short ww;
-		for(ww = w;ww--;)
-		{
-			unsigned char p = *pix++;
-			if(p == 0)
-				scr++;
-			else
-				*scr++ += p << 4;
-		}
-		pix += pstride;
-		scr += sstride;
-	}
-}
-void readpalette(unsigned char *ptr)
-{
-	int doit = 1;
-	while(doit)
-	{
-		unsigned short idx = *ptr++;
-		if(idx != 0xFF)
-		{
-			unsigned short cnt = *ptr++;
-			while(cnt--)
-			{
-				if(idx == 0)
-				{
-					pal_entry.r = 0;
-					pal_entry.g = 0;
-					pal_entry.b = 0;
-					ptr += 3;
-				}
+		for (; h--;) {
+			short ww;
+			for (ww = w; ww--;) {
+				unsigned char p = *pix++;
+				if (p == 0)
+					scr++;
 				else
-				{
-					pal_entry.r = *ptr++ << 10;
-					pal_entry.g = *ptr++ << 10;
-					pal_entry.b = *ptr++ << 10;
-				}
-				CLPalette_SetRGBColor(global_palette, idx, &pal_entry);
-				idx++;
+					*scr++ += p << 4;
 			}
+			pix += pstride;
+			scr += sstride;
+		}
+	}
+	void readpalette(unsigned char *ptr) {
+		int doit = 1;
+		while (doit) {
+			unsigned short idx = *ptr++;
+			if (idx != 0xFF) {
+				unsigned short cnt = *ptr++;
+				while (cnt--) {
+					if (idx == 0) {
+						pal_entry.r = 0;
+						pal_entry.g = 0;
+						pal_entry.b = 0;
+						ptr += 3;
+					} else {
+						pal_entry.r = *ptr++ << 10;
+						pal_entry.g = *ptr++ << 10;
+						pal_entry.b = *ptr++ << 10;
+					}
+					CLPalette_SetRGBColor(global_palette, idx, &pal_entry);
+					idx++;
+				}
+			} else
+				doit = 0;
 		}
-		else
-			doit = 0;
 	}
-}
-void spritesurbulle(short index, short x, short y)
-{
-	unsigned char *pix = bank_data_ptr;
-	unsigned char *scr = p_subtitlesview_buf + x + y * subtitles_x_width;
-	unsigned char h0, h1, mode;
-	short w, h;
-	if(cur_bank_num != 117)
-	{
-		if(PLE16(pix) > 2)
-			readpalette(pix + 2);
-	}
-	pix += PLE16(pix);
-	pix += PLE16(pix + index * 2);
-	//	short	height:9
-	//	short	pad:6;
-	//	short	flag:1;
-	h0 = *pix++;
-	h1 = *pix++;
-	w = ((h1 & 1) << 8) | h0;
-	h = *pix++;
-	mode = *pix++;
-	if(mode != 0xFF && mode != 0xFE)
-		return;
-	if(h1 & 0x80)
-	{
-	// compressed
-		for(;h-- > 0;)
-		{
-			short ww;
-			for(ww = w;ww > 0;)
-			{
-				unsigned char c = *pix++;
-				if(c >= 0x80)
-				{
-					if(c == 0x80)
-					{
-						unsigned char fill = *pix++;
-						if(fill == 0)
-						{
-							scr += 128 + 1;
-							ww -= 128 + 1;
-						}
-						else
-						{
-							unsigned char run;
-							*scr++ = fill;	//TODO: wha?
-							*scr++ = fill;
-							ww -= 128 + 1;
-							for(run = 127;run--;)
+	void spritesurbulle(short index, short x, short y) {
+		unsigned char *pix = bank_data_ptr;
+		unsigned char *scr = p_subtitlesview_buf + x + y * subtitles_x_width;
+		unsigned char h0, h1, mode;
+		short w, h;
+		if (cur_bank_num != 117) {
+			if (PLE16(pix) > 2)
+				readpalette(pix + 2);
+		}
+		pix += PLE16(pix);
+		pix += PLE16(pix + index * 2);
+		//  short   height:9
+		//  short   pad:6;
+		//  short   flag:1;
+		h0 = *pix++;
+		h1 = *pix++;
+		w = ((h1 & 1) << 8) | h0;
+		h = *pix++;
+		mode = *pix++;
+		if (mode != 0xFF && mode != 0xFE)
+			return;
+		if (h1 & 0x80) {
+			// compressed
+			for (; h-- > 0;) {
+				short ww;
+				for (ww = w; ww > 0;) {
+					unsigned char c = *pix++;
+					if (c >= 0x80) {
+						if (c == 0x80) {
+							unsigned char fill = *pix++;
+							if (fill == 0) {
+								scr += 128 + 1;
+								ww -= 128 + 1;
+							} else {
+								unsigned char run;
+								*scr++ = fill;  //TODO: wha?
 								*scr++ = fill;
+								ww -= 128 + 1;
+								for (run = 127; run--;)
+									*scr++ = fill;
+							}
+						} else {
+							unsigned char fill = *pix++;
+							unsigned char run = 255 - c + 2;
+							ww -= run;
+							if (fill == 0)
+								scr += run;
+							else
+								for (; run--;)
+									*scr++ = fill;
 						}
-					}
-					else
-					{
-						unsigned char fill = *pix++;
-						unsigned char run = 255 - c + 2;
+					} else {
+						unsigned char run = c + 1;
 						ww -= run;
-						if(fill == 0)
-							scr += run;
-						else
-							for(;run--;)
-								*scr++ = fill;
+						for (; run--;) {
+							unsigned char p = *pix++;
+							if (p == 0)
+								scr++;
+							else
+								*scr++ = p;
+						}
 					}
 				}
-				else
-				{
-					unsigned char run = c + 1;
-					ww -= run;
-					for(;run--;)
-					{
-						unsigned char p = *pix++;
-						if(p == 0)
-							scr++;
-						else
-							*scr++ = p;
-					}
+				scr += subtitles_x_width - w;
+			}
+		} else {
+			// uncompressed
+			for (; h--;) {
+				short ww;
+				for (ww = w; ww--;) {
+					unsigned char p = *pix++;
+					if (p == 0)
+						scr++;
+					else
+						*scr++ = p;
 				}
+				scr += subtitles_x_width - w;
 			}
-			scr += subtitles_x_width - w;
 		}
 	}
-	else
-	{
-		// uncompressed
-		for(;h--;)
-		{
-			short ww;
-			for(ww = w;ww--;)
-			{
-				unsigned char p = *pix++;
-				if(p == 0)
-					scr++;
-				else
-					*scr++ = p;
+	void bars_out() {
+		short i, r19, r20, r25, r24;
+		unsigned int *scr40, *scr41, *scr42;
+		if (showBlackBars)
+			return;
+		afficher();
+		underTopBarScreenRect.sx = scroll_pos;
+		underTopBarScreenRect.ex = scroll_pos + 320 - 1;
+		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
+		underBottomBarScreenRect.sx = underTopBarScreenRect.sx;
+		underBottomBarScreenRect.ex = underTopBarScreenRect.ex;
+		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
+		r19 = 14;   // TODO - init in decl?
+		r20 = 176;
+		r25 = 14;
+		r24 = 21;
+		underTopBarScreenRect.sx = 0;
+		underTopBarScreenRect.ex = 320 - 1;
+		underTopBarBackupRect.sx = scroll_pos;
+		underTopBarBackupRect.ex = scroll_pos + 320 - 1;
+		while (r24 > 0) {
+			if (r25 > 0) {
+				underTopBarScreenRect.sy = 16 - r25;
+				underTopBarScreenRect.ey = 16 - 1;
+				underTopBarBackupRect.sy = 0;
+				underTopBarBackupRect.ey = r25 - 1;
+				CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+				scr40 = ((unsigned int *)p_mainview_buf) + r19 * 640 / 4;
+				scr41 = scr40 + 640 / 4;
+				for (i = 0; i < 320; i += 4) {
+					*scr40++ = 0;
+					*scr41++ = 0;
+				}
 			}
-			scr += subtitles_x_width - w;
-		}
-	}
-}
-void bars_out()
-{
-	short i, r19, r20, r25, r24;
-	unsigned int *scr40, *scr41, *scr42;
-	if(showBlackBars)
-		return;
-	afficher();
-	underTopBarScreenRect.sx = scroll_pos;
-	underTopBarScreenRect.ex = scroll_pos + 320 - 1;
-	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
-	underBottomBarScreenRect.sx = underTopBarScreenRect.sx;
-	underBottomBarScreenRect.ex = underTopBarScreenRect.ex;
-	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
-	r19 = 14;	// TODO - init in decl?
-	r20 = 176;
-	r25 = 14;
-	r24 = 21;
-	underTopBarScreenRect.sx = 0;
-	underTopBarScreenRect.ex = 320 - 1;
-	underTopBarBackupRect.sx = scroll_pos;
-	underTopBarBackupRect.ex = scroll_pos + 320 - 1;
-	while(r24 > 0)
-	{
-		if(r25 > 0)
-		{
-			underTopBarScreenRect.sy = 16 - r25;
-			underTopBarScreenRect.ey = 16 - 1;
-			underTopBarBackupRect.sy = 0;
-			underTopBarBackupRect.ey = r25 - 1;
+			underTopBarScreenRect.sy = 16;
+			underTopBarScreenRect.ey = r24 + 16 - 1;
+			underTopBarBackupRect.sy = 200 - r24;
+			underTopBarBackupRect.ey = 200 - 1;
 			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-			scr40 = ((unsigned int*)p_mainview_buf) + r19 * 640 / 4;
+			scr40 = ((unsigned int *)p_mainview_buf) + r20 * 640 / 4;
 			scr41 = scr40 + 640 / 4;
-			for(i = 0;i < 320;i += 4)
-			{
+			scr42 = scr41 + 640 / 4;
+			for (i = 0; i < 320; i += 4) {
 				*scr40++ = 0;
 				*scr41++ = 0;
+				*scr42++ = 0;
 			}
+			r19 -= 2;
+			r20 += 3;
+			r25 -= 2;
+			r24 -= 3;
+			afficher();
+		}
+		scr40 = (unsigned int *)p_mainview_buf;
+		scr41 = scr40 + 640 / 4;
+		for (i = 0; i < 320; i += 4) {
+			*scr40++ = 0;
+			*scr41++ = 0;
 		}
-		underTopBarScreenRect.sy = 16;
-		underTopBarScreenRect.ey = r24 + 16 - 1;
-		underTopBarBackupRect.sy = 200 - r24;
-		underTopBarBackupRect.ey = 200 - 1;
-		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-		scr40 = ((unsigned int*)p_mainview_buf) + r20 * 640 / 4;
+		scr40 = ((unsigned int *)p_mainview_buf) + r20 * 640 / 4;
 		scr41 = scr40 + 640 / 4;
 		scr42 = scr41 + 640 / 4;
-		for(i = 0;i < 320;i += 4)
-		{
+		for (i = 0; i < 320; i += 4) {
 			*scr40++ = 0;
 			*scr41++ = 0;
 			*scr42++ = 0;
 		}
-		r19 -= 2;
-		r20 += 3;
-		r25 -= 2;
-		r24 -= 3;
 		afficher();
+		initrect();
+		showBlackBars = 1;
 	}
-	scr40 = (unsigned int*)p_mainview_buf;
-	scr41 = scr40 + 640 / 4;
-	for(i = 0;i < 320;i += 4)
-	{
-		*scr40++ = 0;
-		*scr41++ = 0;
-	}
-	scr40 = ((unsigned int*)p_mainview_buf) + r20 * 640 / 4;
-	scr41 = scr40 + 640 / 4;
-	scr42 = scr41 + 640 / 4;
-	for(i = 0;i < 320;i += 4)
-	{
-		*scr40++ = 0;
-		*scr41++ = 0;
-		*scr42++ = 0;
-	}
-	afficher();
-	initrect();
-	showBlackBars = 1;
-}
-void bars_in()
-{
-	short r29, r28;
-	if(!showBlackBars)
-		return;
-	blackbars();
-	r29 = 2;
-	r28 = 2;
-	underTopBarScreenRect.sx = 0;
-	underTopBarScreenRect.ex = 320 - 1;
-	underTopBarBackupRect.sx = scroll_pos;
-	underTopBarBackupRect.ex = scroll_pos + 320 - 1;
-	while(r28 < 24)
-	{
-		if(r29 <= 16)
-		{
-			underTopBarScreenRect.sy = 16 - r29;
-			underTopBarScreenRect.ey = 16 - 1;
-			underTopBarBackupRect.sy = 0;
-			underTopBarBackupRect.ey = r29 - 1;
+	void bars_in() {
+		short r29, r28;
+		if (!showBlackBars)
+			return;
+		blackbars();
+		r29 = 2;
+		r28 = 2;
+		underTopBarScreenRect.sx = 0;
+		underTopBarScreenRect.ex = 320 - 1;
+		underTopBarBackupRect.sx = scroll_pos;
+		underTopBarBackupRect.ex = scroll_pos + 320 - 1;
+		while (r28 < 24) {
+			if (r29 <= 16) {
+				underTopBarScreenRect.sy = 16 - r29;
+				underTopBarScreenRect.ey = 16 - 1;
+				underTopBarBackupRect.sy = 0;
+				underTopBarBackupRect.ey = r29 - 1;
+				CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+			}
+			underTopBarScreenRect.sy = 16;
+			underTopBarScreenRect.ey = 16 + r28;
+			underTopBarBackupRect.sy = 200 - 1 - r28;
+			underTopBarBackupRect.ey = 200 - 1;
 			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+			r29 += 2;
+			r28 += 3;
+			afficher();
 		}
-		underTopBarScreenRect.sy = 16;
-		underTopBarScreenRect.ey = 16 + r28;
-		underTopBarBackupRect.sy = 200 - 1 - r28;
-		underTopBarBackupRect.ey = 200 - 1;
-		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-		r29 += 2;
-		r28 += 3;
-		afficher();
-	}
-	initrect();
-	showBlackBars = 0;
-}
-void sauvefondbouche()
-{
-	rect_src.sx = cur_perso_rect->sx;
-	rect_src.sy = cur_perso_rect->sy;
-	rect_src.ex = cur_perso_rect->ex;
-	rect_src.ey = cur_perso_rect->ey;
-	rect_dst.sx = cur_perso_rect->sx + 320;
-	rect_dst.sy = cur_perso_rect->sy;
-	rect_dst.ex = cur_perso_rect->ex + 320;
-	rect_dst.ey = cur_perso_rect->ey;
-	CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_src, &rect_dst);
-	fond_saved = 1;
-}
-void restaurefondbouche()
-{
-	rect_src.sx = cur_perso_rect->sx;
-	rect_src.sy = cur_perso_rect->sy;
-	rect_src.ex = cur_perso_rect->ex;
-	rect_src.ey = cur_perso_rect->ey;
-	rect_dst.sx = cur_perso_rect->sx + 320;
-	rect_dst.sy = cur_perso_rect->sy;
-	rect_dst.ex = cur_perso_rect->ex + 320;
-	rect_dst.ey = cur_perso_rect->ey;
-	CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_dst, &rect_src);
-}
-void blackbars()
-{
-	unsigned char *scr = p_mainview_buf;
-	short x, y;
-	for(y = 0;y < 16;y++)
-		for(x = 0;x < 640;x++)
-			*scr++ = 0;
-	scr += 640 * (200 - 16 - 24);
-	for(y = 0;y < 24;y++)
-		for(x = 0;x < 640;x++)
-			*scr++ = 0;
-}
-void afftopscr()	// Draw  top bar (location / party / map)
-{
-	perso_t *perso;
-	p_global->drawFlags &= ~DrawFlags::drDrawTopScreen;
-	use_bank(314);
-	noclipax(36, 83, 0);
-	noclipax(p_global->area_ptr->num - 1, 0, 0);
-	noclipax(23, 145, 0);
-	for(perso = &kPersons[PER_DINA];perso != &kPersons[PER_UNKN_156];perso++)
-	{
-		if ((perso->flags & PersonFlags::pfInParty) && !(perso->flags & PersonFlags::pf80))
-			noclipax(perso->targetLoc + 18, perso->lastLoc + 120, 0);
-	}
-	saved_repadam.x = -1;
-	saved_repadam.y = -1;
-	affplanval();
-	needPaletteUpdate = 1;
-}
-void affplanval()	// Draw mini-map
-{
-	short loc;
-	perso_t *perso;
-	if(p_global->area_ptr->type == AreaType::atValley)
-	{
-		noclipax(p_global->area_ptr->num + 9, 266, 1);
-		for(perso = &kPersons[PER_UNKN_18C];perso->roomNum != 0xFFFF;perso++)
-		{
-			if(((perso->roomNum >> 8) == p_global->areaNum)
-				&& !(perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pf20))
-				affrepere(33, perso->roomNum & 0xFF);
-		}
-		if(p_global->area_ptr->citadelLevel)
-			affrepere(34, p_global->area_ptr->citadelRoom->location);
-		sauvefriseshaut(0);
-		loc = p_global->roomNum & 0xFF;
-		if(loc >= 16)
-			affrepereadam(loc);
-		restaurefriseshaut();
+		initrect();
+		showBlackBars = 0;
+	}
+	void sauvefondbouche() {
+		rect_src.sx = cur_perso_rect->sx;
+		rect_src.sy = cur_perso_rect->sy;
+		rect_src.ex = cur_perso_rect->ex;
+		rect_src.ey = cur_perso_rect->ey;
+		rect_dst.sx = cur_perso_rect->sx + 320;
+		rect_dst.sy = cur_perso_rect->sy;
+		rect_dst.ex = cur_perso_rect->ex + 320;
+		rect_dst.ey = cur_perso_rect->ey;
+		CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_src, &rect_dst);
+		fond_saved = 1;
+	}
+	void restaurefondbouche() {
+		rect_src.sx = cur_perso_rect->sx;
+		rect_src.sy = cur_perso_rect->sy;
+		rect_src.ex = cur_perso_rect->ex;
+		rect_src.ey = cur_perso_rect->ey;
+		rect_dst.sx = cur_perso_rect->sx + 320;
+		rect_dst.sy = cur_perso_rect->sy;
+		rect_dst.ex = cur_perso_rect->ex + 320;
+		rect_dst.ey = cur_perso_rect->ey;
+		CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_dst, &rect_src);
+	}
+	void blackbars() {
+		unsigned char *scr = p_mainview_buf;
+		short x, y;
+		for (y = 0; y < 16; y++)
+			for (x = 0; x < 640; x++)
+				*scr++ = 0;
+		scr += 640 * (200 - 16 - 24);
+		for (y = 0; y < 24; y++)
+			for (x = 0; x < 640; x++)
+				*scr++ = 0;
 	}
-	else
-	{
-		sauvefriseshaut(0);
-		restaurefriseshaut();
+	void afftopscr() {  // Draw  top bar (location / party / map)
+		perso_t *perso;
+		p_global->drawFlags &= ~DrawFlags::drDrawTopScreen;
+		use_bank(314);
+		noclipax(36, 83, 0);
+		noclipax(p_global->area_ptr->num - 1, 0, 0);
+		noclipax(23, 145, 0);
+		for (perso = &kPersons[PER_DINA]; perso != &kPersons[PER_UNKN_156]; perso++) {
+			if ((perso->flags & PersonFlags::pfInParty) && !(perso->flags & PersonFlags::pf80))
+				noclipax(perso->targetLoc + 18, perso->lastLoc + 120, 0);
+		}
+		saved_repadam.x = -1;
+		saved_repadam.y = -1;
+		affplanval();
+		needPaletteUpdate = 1;
 	}
-}
-void affrepere(short index, short location)
-{
-	noclipax(index, 269 + location % 16 * 4, 2 + (location - 16) / 16 * 3);
-}
-void affrepereadam(short location)
-{
-	short x = 269;
-	short y = 2;
-	short w;
-	unsigned char *pix;
-	rest_repadam();
-	if(location > 15 && location < 76)
-	{
-		x += (location & 15) * 4;
-		y += ((location - 16) >> 4) * 3;
-		save_repadam(x, y);
+	void affplanval() { // Draw mini-map
+		short loc;
+		perso_t *perso;
+		if (p_global->area_ptr->type == AreaType::atValley) {
+			noclipax(p_global->area_ptr->num + 9, 266, 1);
+			for (perso = &kPersons[PER_UNKN_18C]; perso->roomNum != 0xFFFF; perso++) {
+				if (((perso->roomNum >> 8) == p_global->areaNum)
+				        && !(perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pf20))
+					affrepere(33, perso->roomNum & 0xFF);
+			}
+			if (p_global->area_ptr->citadelLevel)
+				affrepere(34, p_global->area_ptr->citadelRoom->location);
+			sauvefriseshaut(0);
+			loc = p_global->roomNum & 0xFF;
+			if (loc >= 16)
+				affrepereadam(loc);
+			restaurefriseshaut();
+		} else {
+			sauvefriseshaut(0);
+			restaurefriseshaut();
+		}
+	}
+	void affrepere(short index, short location) {
+		noclipax(index, 269 + location % 16 * 4, 2 + (location - 16) / 16 * 3);
+	}
+	void affrepereadam(short location) {
+		short x = 269;
+		short y = 2;
+		short w;
+		unsigned char *pix;
+		rest_repadam();
+		if (location > 15 && location < 76) {
+			x += (location & 15) * 4;
+			y += ((location - 16) >> 4) * 3;
+			save_repadam(x, y);
+			pix = p_underBarsView->p_buffer;
+			w = p_underBarsView->width;
+			pix += x + w * y;
+			pix[1] = 0xC3;
+			pix[2] = 0xC3;
+			pix += w;
+			pix[0] = 0xC3;
+			pix[1] = 0xC3;
+			pix[2] = 0xC3;
+			pix[3] = 0xC3;
+			pix += w;
+			pix[1] = 0xC3;
+			pix[2] = 0xC3;
+		}
+	}
+	void rest_repadam() {
+		short x, y, w;
+		unsigned char *pix;
+		if (saved_repadam.x == -1 && saved_repadam.y == -1)
+			return;
+		x = saved_repadam.x;
+		y = saved_repadam.y;
 		pix = p_underBarsView->p_buffer;
 		w = p_underBarsView->width;
 		pix += x + w * y;
-		pix[1] = 0xC3;
-		pix[2] = 0xC3;
+		pix[1] = keep01;    //TODO keep is array?
+		pix[2] = keep02;
 		pix += w;
-		pix[0] = 0xC3;
-		pix[1] = 0xC3;
-		pix[2] = 0xC3;
-		pix[3] = 0xC3;
+		pix[0] = keep10;
+		pix[1] = keep11;
+		pix[2] = keep12;
+		pix[3] = keep13;
 		pix += w;
-		pix[1] = 0xC3;
-		pix[2] = 0xC3;
-	}
-}
-void rest_repadam()
-{
-	short x, y, w;
-	unsigned char *pix;
-	if(saved_repadam.x == -1 && saved_repadam.y == -1)
-		return;
-	x = saved_repadam.x;
-	y = saved_repadam.y;
-	pix = p_underBarsView->p_buffer;
-	w = p_underBarsView->width;
-	pix += x + w * y;
-	pix[1] = keep01;	//TODO keep is array?
-	pix[2] = keep02;
-	pix += w;
-	pix[0] = keep10;
-	pix[1] = keep11;
-	pix[2] = keep12;
-	pix[3] = keep13;
-	pix += w;
-	pix[1] = keep21;
-	pix[2] = keep22;
-}
-void save_repadam(short x, short y)
-{
-	short w;
-	unsigned char *pix;
-	saved_repadam.x = x;
-	saved_repadam.y = y;
-	pix = p_underBarsView->p_buffer;
-	w = p_underBarsView->width;
-	pix += x + w * y;
-	keep01 = pix[1];
-	keep02 = pix[2];
-	pix += w;
-	keep10 = pix[0];
-	keep11 = pix[1];
-	keep12 = pix[2];
-	keep13 = pix[3];
-	pix += w;
-	keep21 = pix[1];
-	keep22 = pix[2];
-}
-char istrice(short roomNum)
-{
-	char loc = roomNum & 0xFF;
-	short area = roomNum & 0xFF00;
-	perso_t *perso;
-	for(perso = &kPersons[PER_UNKN_18C];perso != &kPersons[PER_UNKN_372];perso++)
-	{
-		if ((perso->flags & PersonFlags::pf80) || (perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftTriceraptor)
-			continue;
-		if(perso->roomNum == (area | (loc - 16)))
-			return 1;
-		if(perso->roomNum == (area | (loc + 16)))
-			return 1;
-		if(perso->roomNum == (area | (loc - 1)))
-			return 1;
-		if(perso->roomNum == (area | (loc + 1)))
-			return 1;
+		pix[1] = keep21;
+		pix[2] = keep22;
+	}
+	void save_repadam(short x, short y) {
+		short w;
+		unsigned char *pix;
+		saved_repadam.x = x;
+		saved_repadam.y = y;
+		pix = p_underBarsView->p_buffer;
+		w = p_underBarsView->width;
+		pix += x + w * y;
+		keep01 = pix[1];
+		keep02 = pix[2];
+		pix += w;
+		keep10 = pix[0];
+		keep11 = pix[1];
+		keep12 = pix[2];
+		keep13 = pix[3];
+		pix += w;
+		keep21 = pix[1];
+		keep22 = pix[2];
 	}
-	return 0;
-}
-char istyran(short roomNum)
-{
-	char loc = roomNum & 0xFF;
-	short area = roomNum & 0xFF00;
-	// TODO: orig bug: this ptr is not initialized when first called from getsalle
-	// PC version scans kPersons[] directly and is not affected
-	if (!tyranPtr)
+	char istrice(short roomNum) {
+		char loc = roomNum & 0xFF;
+		short area = roomNum & 0xFF00;
+		perso_t *perso;
+		for (perso = &kPersons[PER_UNKN_18C]; perso != &kPersons[PER_UNKN_372]; perso++) {
+			if ((perso->flags & PersonFlags::pf80) || (perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftTriceraptor)
+				continue;
+			if (perso->roomNum == (area | (loc - 16)))
+				return 1;
+			if (perso->roomNum == (area | (loc + 16)))
+				return 1;
+			if (perso->roomNum == (area | (loc - 1)))
+				return 1;
+			if (perso->roomNum == (area | (loc + 1)))
+				return 1;
+		}
 		return 0;
+	}
+	char istyran(short roomNum) {
+		char loc = roomNum & 0xFF;
+		short area = roomNum & 0xFF00;
+		// TODO: orig bug: this ptr is not initialized when first called from getsalle
+		// PC version scans kPersons[] directly and is not affected
+		if (!tyranPtr)
+			return 0;
 
-	for(;tyranPtr->roomNum != 0xFFFF;tyranPtr++) 
-	{
-		if (tyranPtr->flags & PersonFlags::pf80)
-			continue;
-		if(tyranPtr->roomNum == (area | (loc - 16)))
-			return 1;
-		if(tyranPtr->roomNum == (area | (loc + 16)))
-			return 1;
-		if(tyranPtr->roomNum == (area | (loc - 1)))
-			return 1;
-		if(tyranPtr->roomNum == (area | (loc + 1)))
-			return 1;
+		for (; tyranPtr->roomNum != 0xFFFF; tyranPtr++) {
+			if (tyranPtr->flags & PersonFlags::pf80)
+				continue;
+			if (tyranPtr->roomNum == (area | (loc - 16)))
+				return 1;
+			if (tyranPtr->roomNum == (area | (loc + 16)))
+				return 1;
+			if (tyranPtr->roomNum == (area | (loc - 1)))
+				return 1;
+			if (tyranPtr->roomNum == (area | (loc + 1)))
+				return 1;
+		}
+		return 0;
 	}
-	return 0;
-}
-void istyranval(area_t *area)
-{
-	perso_t *perso;
-	unsigned char areaNum = area->num;
-	area->flags &= ~AreaFlags::HasTyrann;
-	for(perso = &kPersons[PER_UNKN_372];perso->roomNum != 0xFFFF;perso++)
-	{
-		if (perso->flags & PersonFlags::pf80)
-			continue;
-		if((perso->roomNum >> 8) == areaNum)
-		{
-			area->flags |= AreaFlags::HasTyrann;
-			break;
+	void istyranval(area_t *area) {
+		perso_t *perso;
+		unsigned char areaNum = area->num;
+		area->flags &= ~AreaFlags::HasTyrann;
+		for (perso = &kPersons[PER_UNKN_372]; perso->roomNum != 0xFFFF; perso++) {
+			if (perso->flags & PersonFlags::pf80)
+				continue;
+			if ((perso->roomNum >> 8) == areaNum) {
+				area->flags |= AreaFlags::HasTyrann;
+				break;
+			}
 		}
 	}
-}
-char getdirection(perso_t *perso)
-{
-	char dir = -1;
-	unsigned char trgLoc = perso->targetLoc;
-	unsigned char curLoc = perso->roomNum & 0xFF;	//TODO name
-	if(curLoc != trgLoc)
-	{
-		curLoc &= 0xF;
-		trgLoc &= 0xF;
-		if (curLoc != trgLoc)
-		{
-			dir = 2;
-			if (curLoc > trgLoc)
-				dir = 5;
-		}
-		trgLoc = perso->targetLoc;
-		curLoc = perso->roomNum & 0xFF;
-		curLoc &= 0xF0;
-		trgLoc &= 0xF0;
-		if (curLoc != trgLoc)
-		{
-			if (curLoc > trgLoc)
+	char getdirection(perso_t *perso) {
+		char dir = -1;
+		unsigned char trgLoc = perso->targetLoc;
+		unsigned char curLoc = perso->roomNum & 0xFF;   //TODO name
+		if (curLoc != trgLoc) {
+			curLoc &= 0xF;
+			trgLoc &= 0xF;
+			if (curLoc != trgLoc) {
+				dir = 2;
+				if (curLoc > trgLoc)
+					dir = 5;
+			}
+			trgLoc = perso->targetLoc;
+			curLoc = perso->roomNum & 0xFF;
+			curLoc &= 0xF0;
+			trgLoc &= 0xF0;
+			if (curLoc != trgLoc) {
+				if (curLoc > trgLoc)
+					dir++;
 				dir++;
-			dir++;
+			}
+		}
+		return dir;
+	};
+	char caselibre(char loc, perso_t *perso) {
+		short roomNum;
+		room_t *room = p_global->cita_area_firstRoom;
+		if (loc <= 0x10 || loc > 76 || (loc & 0xF) >= 12 || loc == perso->lastLoc)
+			return 0;
+		roomNum = (perso->roomNum & ~0xFF) | loc;   //TODO: danger! signed
+		if (roomNum == p_global->roomNum)
+			return 0;
+		for (; room->ff_0 != 0xFF; room++) {
+			if (room->location != loc)
+				continue;
+			if (!(room->flags & RoomFlags::rf01))
+				return 0;
+			for (perso = &kPersons[PER_UNKN_18C]; perso->roomNum != 0xFFFF; perso++) {
+				if (perso->flags & PersonFlags::pf80)
+					continue;
+				if (perso->roomNum == roomNum)
+					break;
+			}
+			if (perso->roomNum != 0xFFFF)
+				return 0;
+			return 1;
 		}
-	}
-	return dir;
-};
-char caselibre(char loc, perso_t *perso)
-{
-	short roomNum;
-	room_t *room = p_global->cita_area_firstRoom;
-	if(loc <= 0x10 || loc > 76 || (loc & 0xF) >= 12 || loc == perso->lastLoc)
 		return 0;
-	roomNum = (perso->roomNum & ~0xFF) | loc;	//TODO: danger! signed
-	if(roomNum == p_global->roomNum)
+	}
+	void melange1(char elem[4]) {
+		if (g_ed->_rnd->getRandomNumber(1) & 1) {
+			char e1 = elem[1];
+			char e2 = elem[2];
+			elem[1] = e2;
+			elem[2] = e1;
+		}
+	}
+	void melange2(char elem[4]) {
+		if (g_ed->_rnd->getRandomNumber(1) & 1) {
+			char e0 = elem[0];
+			char e1 = elem[1];
+			elem[0] = e1;
+			elem[1] = e0;
+		}
+		if (g_ed->_rnd->getRandomNumber(1) & 1) {
+			char e2 = elem[2];
+			char e3 = elem[3];
+			elem[2] = e3;
+			elem[3] = e2;
+		}
+	}
+	void melangedir() {
+		melange1(tab_2CB1E[0]);
+		melange1(tab_2CB1E[1]);
+		melange1(tab_2CB1E[2]);
+		melange2(tab_2CB1E[3]);
+		melange2(tab_2CB1E[4]);
+		melange1(tab_2CB1E[5]);
+		melange2(tab_2CB1E[6]);
+		melange2(tab_2CB1E[7]);
+	}
+	char naitredino(char persoType) {
+		perso_t *perso;
+		for (perso = &kPersons[PER_MORKUS]; (++perso)->roomNum != 0xFFFF;) {
+			char areaNum = perso->roomNum >> 8;
+			if (areaNum != p_global->cita_area_num)
+				continue;
+			if ((perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pfTypeMask) == persoType) {
+				perso->flags &= ~PersonFlags::pf80;
+				return 1;
+			}
+		}
 		return 0;
-	for(;room->ff_0 != 0xFF;room++)
-	{
-		if(room->location != loc)
-			continue;
-		if(!(room->flags & RoomFlags::rf01))
-			return 0;
-		for(perso = &kPersons[PER_UNKN_18C];perso->roomNum != 0xFFFF;perso++)
-		{
+	}
+	void newcita(char arg1, short arg2, room_t *room) {
+		unsigned short index;
+		short *ptr;
+		cita_t *cita = cita_list;
+		while (cita->ff_0 < arg2)
+			cita++;
+		index = ((room->flags & 0xC0) >> 6);    //TODO: this is very wrong
+		ptr = cita->ff_2 + index * 2;
+		if (arg1 == 4 || arg1 == 6)
+			ptr++;
+		room->bank = ptr[0];
+		room->video = ptr[8];
+		room->flags |= RoomFlags::rf02;
+	}
+	void citaevol(short level) {
+		room_t *room = p_global->cur_area_ptr->citadelRoom;
+		perso_t *perso = &kPersons[PER_UNKN_372];
+		unsigned char speed, loc = room->location;
+		if (level >= 80 && !istrice((p_global->cita_area_num << 8) | room->location)) { //TODO: loc ?
+			room->level = 79;
+			return;
+		}
+		if (level > 160)
+			level = 160;
+		if (room->level < 64 && level >= 64 && naitredino(PersonFlags::pftTriceraptor)) {
+			p_global->cur_area_ptr->flags |= AreaFlags::HasTriceraptors;
+			ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+		}
+		if (room->level < 40 && level >= 40 && naitredino(PersonFlags::pftVelociraptor)) {
+			p_global->cur_area_ptr->flags |= AreaFlags::HasVelociraptors;
+			ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsIn);
+		}
+		room->level = level;
+		newcita(p_global->cita_area_num, level, room);
+		speed = kDinoSpeedForCitaLevel[room->level >> 4];
+		for (; perso->roomNum != 0xFFFF; perso++) {
 			if (perso->flags & PersonFlags::pf80)
 				continue;
-			if(perso->roomNum == roomNum)
+			if ((perso->roomNum >> 8) == p_global->cita_area_num && perso->targetLoc == loc)
+				perso->speed = speed;
+		}
+	}
+	void citacapoute(short roomNum) {
+		perso_t *perso = &kPersons[PER_UNKN_18C];
+		room_t *room = p_global->cur_area_ptr->citadelRoom;
+		room->flags |= RoomFlags::rf01;
+		room->flags &= ~RoomFlags::rfHasCitadel;
+		room->bank = 193;
+		room->video = 0;
+		room->level = 0;
+		p_global->cur_area_ptr->citadelLevel = 0;
+		p_global->cur_area_ptr->citadelRoom = 0;
+		roomNum = (roomNum & ~0xFF) | room->location;
+		for (; perso->roomNum != 0xFFFF; perso++) {
+			if (perso->roomNum == roomNum) {
+				perso->flags &= ~PersonFlags::pf80;
+				delinfo((roomNum >> 8) + ValleyNews::vnTyrannIn);
 				break;
+			}
 		}
-		if(perso->roomNum != 0xFFFF)
-			return 0;
-		return 1;
 	}
-	return 0;	
-}
-void melange1(char elem[4])
-{
-	if (g_ed->_rnd->getRandomNumber(1) & 1)
-	{
-		char e1 = elem[1];
-		char e2 = elem[2];
-		elem[1] = e2;
-		elem[2] = e1;
-	}
-}
-void melange2(char elem[4])
-{
-	if (g_ed->_rnd->getRandomNumber(1) & 1)
-	{
-		char e0 = elem[0];
-		char e1 = elem[1];
-		elem[0] = e1;
-		elem[1] = e0;
-	}
-	if (g_ed->_rnd->getRandomNumber(1) & 1)
-	{
-		char e2 = elem[2];
-		char e3 = elem[3];
-		elem[2] = e3;
-		elem[3] = e2;
+	void buildcita() {
+		area_t *area = p_global->area_ptr;
+		p_global->cur_area_ptr = p_global->area_ptr;
+		if (area->citadelRoom)
+			citacapoute(p_global->roomNum);
+		p_global->ff_6A = p_global->ff_69;
+		p_global->narratorSequence = p_global->ff_69 | 0x80;
+		area->citadelRoom = p_global->room_ptr;
+		p_global->room_ptr->flags &= ~RoomFlags::rf01;
+		p_global->room_ptr->flags |= RoomFlags::rfHasCitadel;
+		p_global->room_ptr->level = 32;
+		newcita(p_global->areaNum, 32, p_global->room_ptr);
+		area->flags &= ~AreaFlags::TyrannSighted;
+		if (!(area->flags & AreaFlags::afFlag8000)) {
+			if (p_global->phaseNum == 304 || p_global->phaseNum != 384) //TODO: wha
+				eloirevient();
+			area->flags |= AreaFlags::afFlag8000;
+		}
+		p_global->room_perso->flags |= PersonFlags::pf80;
+		p_global->cita_area_num = p_global->areaNum;
+		naitredino(1);
+		delinfo(p_global->areaNum + ValleyNews::vnCitadelLost);
+		delinfo(p_global->areaNum + ValleyNews::vnTyrannLost);
+		if (p_global->phaseNum == 193 && p_global->areaNum == Areas::arUluru)
+			bigphase1();
 	}
-}
-void melangedir()
-{
-	melange1(tab_2CB1E[0]);
-	melange1(tab_2CB1E[1]);
-	melange1(tab_2CB1E[2]);
-	melange2(tab_2CB1E[3]);
-	melange2(tab_2CB1E[4]);
-	melange1(tab_2CB1E[5]);
-	melange2(tab_2CB1E[6]);
-	melange2(tab_2CB1E[7]);
-}
-char naitredino(char persoType)
-{
-	perso_t *perso;
-	for(perso = &kPersons[PER_MORKUS];(++perso)->roomNum != 0xFFFF;)
-	{
-		char areaNum = perso->roomNum >> 8;
-		if(areaNum != p_global->cita_area_num)
-			continue;
-		if ((perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pfTypeMask) == persoType)
-		{
-			perso->flags &= ~PersonFlags::pf80;
-			return 1;
+	void citatombe(char level) {
+		if (level)
+			newcita(p_global->cita_area_num, level, p_global->cur_area_ptr->citadelRoom);
+		else {
+			citacapoute(p_global->cita_area_num << 8);
+			ajouinfo(p_global->cita_area_num + ValleyNews::vnCitadelLost);
 		}
 	}
-	return 0;
-}
-void newcita(char arg1, short arg2, room_t *room)
-{
-	unsigned short index;
-	short *ptr;
-	cita_t *cita = cita_list;
-	while(cita->ff_0 < arg2)
-		cita++;
-	index = ((room->flags & 0xC0) >> 6);	//TODO: this is very wrong
-	ptr = cita->ff_2 + index * 2;
-	if(arg1 == 4 || arg1 == 6)
-		ptr++;
-	room->bank = ptr[0];
-	room->video = ptr[8];
-	room->flags |= RoomFlags::rf02;
-}
-void citaevol(short level)
-{
-	room_t *room = p_global->cur_area_ptr->citadelRoom;
-	perso_t *perso = &kPersons[PER_UNKN_372];
-	unsigned char speed, loc = room->location;
-	if (level >= 80 && !istrice((p_global->cita_area_num << 8) | room->location))  //TODO: loc ?
-	{
-		room->level = 79;
-		return;
+	void constcita() {
+		unsigned char level;
+		room_t *room;
+		unsigned char loc;
+//	room_t *room = p_global->cur_area_ptr->room_ptr; //TODO: wrong? chk below
+//	unsigned char id = room->ff_C;
+		if (!p_global->cur_area_ptr->citadelLevel || !p_global->cur_area_ptr->citadelRoom)
+			return;
+		room = p_global->cur_area_ptr->citadelRoom; //TODO: copied here by me
+		loc = room->location;
+		tyranPtr = &kPersons[PER_UNKN_372];
+		if (istyran((p_global->cita_area_num << 8) | loc)) {
+			if (!(p_global->cur_area_ptr->flags & AreaFlags::TyrannSighted)) {
+				ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
+				p_global->cur_area_ptr->flags |= AreaFlags::TyrannSighted;
+			}
+			level = room->level - 1;
+			if (level < 32)
+				level = 32;
+			room->level = level;
+			citatombe(level);
+		} else {
+			p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+			citaevol(room->level + 1);
+		}
+	}
+	void depladino(perso_t *perso) {
+		char *dirs, dir, dir2;
+		unsigned char loc;
+		dir = getdirection(perso);
+		if (dir != -1) {
+			melangedir();
+			dirs = tab_2CB1E[dir];
+			loc = perso->roomNum & 0xFF;
+			dir2 = *dirs++;
+			if (dir2 & 0x80)
+				dir2 = -(dir2 & ~0x80);
+			dir2 += loc;
+			if (caselibre(dir2, perso))
+				goto ok;
+			dir2 = *dirs++;
+			if (dir2 & 0x80)
+				dir2 = -(dir2 & ~0x80);
+			dir2 += loc;
+			if (caselibre(dir2, perso))
+				goto ok;
+			dir2 = *dirs++;
+			if (dir2 & 0x80)
+				dir2 = -(dir2 & ~0x80);
+			dir2 += loc;
+			if (caselibre(dir2, perso))
+				goto ok;
+			dir2 = *dirs++;
+			if (dir2 & 0x80)
+				dir2 = -(dir2 & ~0x80);
+			dir2 += loc;
+			if (caselibre(dir2, perso))
+				goto ok;
+			dir2 = perso->lastLoc;
+			perso->lastLoc = 0;
+			if (!caselibre(dir2, perso))
+				return;
+ok:
+			;
+			perso->lastLoc = perso->roomNum & 0xFF;
+			perso->roomNum &= ~0xFF;
+			perso->roomNum |= dir2 & 0xFF;
+			if (perso->targetLoc - 16 == (perso->roomNum & 0xFF))
+				perso->targetLoc = 0;
+			if (perso->targetLoc + 16 == (perso->roomNum & 0xFF))
+				perso->targetLoc = 0;
+			if (perso->targetLoc - 1 == (perso->roomNum & 0xFF))
+				perso->targetLoc = 0;
+			if (perso->targetLoc + 1 == (perso->roomNum & 0xFF))
+				perso->targetLoc = 0;
+		} else
+			perso->targetLoc = 0;
 	}
-	if(level > 160)
-		level = 160;
-	if(room->level < 64 && level >= 64 && naitredino(PersonFlags::pftTriceraptor))
-	{
-		p_global->cur_area_ptr->flags |= AreaFlags::HasTriceraptors;
-		ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
-	}
-	if(room->level < 40 && level >= 40 && naitredino(PersonFlags::pftVelociraptor))
-	{
-		p_global->cur_area_ptr->flags |= AreaFlags::HasVelociraptors;
-		ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsIn);
-	}
-	room->level = level;
-	newcita(p_global->cita_area_num, level, room);
-	speed = kDinoSpeedForCitaLevel[room->level >> 4];
-	for(;perso->roomNum != 0xFFFF;perso++)
-	{
-		if (perso->flags & PersonFlags::pf80)
-			continue;
-		if ((perso->roomNum >> 8) == p_global->cita_area_num && perso->targetLoc == loc)
-			perso->speed = speed;
-	}	
-}
-void citacapoute(short roomNum)
-{
-	perso_t *perso = &kPersons[PER_UNKN_18C];
-	room_t *room = p_global->cur_area_ptr->citadelRoom;
-	room->flags |= RoomFlags::rf01;
-	room->flags &= ~RoomFlags::rfHasCitadel;
-	room->bank = 193;
-	room->video = 0;
-	room->level = 0;
-	p_global->cur_area_ptr->citadelLevel = 0;
-	p_global->cur_area_ptr->citadelRoom = 0;
-	roomNum = (roomNum & ~0xFF) | room->location;
-	for(;perso->roomNum != 0xFFFF;perso++)
-	{
-		if(perso->roomNum == roomNum)
-		{
+	void deplaalldino() {
+		perso_t *perso = &kPersons[PER_UNKN_18C - 1];   //TODO fix this
+		while ((++perso)->roomNum != 0xFFFF) {
+			if (((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
+				continue;
+			if (perso->flags & PersonFlags::pf80)
+				continue;
+			if (!perso->targetLoc)
+				continue;
+			if (--perso->steps)
+				continue;
+			perso->steps = 1;
+			if (perso->roomNum == p_global->roomNum)
+				continue;
+			perso->steps = perso->speed;
+			depladino(perso);
+		}
+	}
+	void newvallee() {
+		perso_t *perso = &kPersons[PER_UNKN_372];
+		short *ptr = tab_2CB16;
+		short roomNum;
+		while ((roomNum = *ptr++) != -1) {
+			perso->roomNum = roomNum;
 			perso->flags &= ~PersonFlags::pf80;
-			delinfo((roomNum >> 8) + ValleyNews::vnTyrannIn);
+			perso->flags &= ~PersonFlags::pf20; //TODO: combine?
+			perso++;
+		}
+		perso->roomNum = -1;
+		kAreasTable[7].flags |= AreaFlags::HasTyrann;
+		p_global->worldHasTyrann = 32;
+	}
+	char whereiscita() {
+		room_t *room = p_global->cita_area_firstRoom;
+		char res = -1;
+		for (; room->ff_0 != 0xFF; room++) {
+			if (!(room->flags & RoomFlags::rfHasCitadel))
+				continue;
+			res = room->location;
 			break;
 		}
-	}	
-}
-void buildcita()
-{
-	area_t *area = p_global->area_ptr;
-	p_global->cur_area_ptr = p_global->area_ptr;
-	if(area->citadelRoom)
-		citacapoute(p_global->roomNum);
-	p_global->ff_6A = p_global->ff_69;
-	p_global->narratorSequence = p_global->ff_69 | 0x80;
-	area->citadelRoom = p_global->room_ptr;
-	p_global->room_ptr->flags &= ~RoomFlags::rf01;
-	p_global->room_ptr->flags |= RoomFlags::rfHasCitadel;
-	p_global->room_ptr->level = 32;
-	newcita(p_global->areaNum, 32, p_global->room_ptr);
-	area->flags &= ~AreaFlags::TyrannSighted;
-	if (!(area->flags & AreaFlags::afFlag8000))
-	{
-		if(p_global->phaseNum == 304 || p_global->phaseNum != 384) //TODO: wha
-			eloirevient();
-		area->flags |= AreaFlags::afFlag8000;
-	}
-	p_global->room_perso->flags |= PersonFlags::pf80;
-	p_global->cita_area_num = p_global->areaNum;
-	naitredino(1);
-	delinfo(p_global->areaNum + ValleyNews::vnCitadelLost);
-	delinfo(p_global->areaNum + ValleyNews::vnTyrannLost);
-	if(p_global->phaseNum == 193 && p_global->areaNum == Areas::arUluru)
-		bigphase1();
-}
-void citatombe(char level)
-{
-	if(level)
-		newcita(p_global->cita_area_num, level, p_global->cur_area_ptr->citadelRoom);
-	else
-	{
-		citacapoute(p_global->cita_area_num << 8);
-		ajouinfo(p_global->cita_area_num + ValleyNews::vnCitadelLost);
+		return res;
 	}
-}
-void constcita()
-{
-	unsigned char level;
-	room_t *room;
-	unsigned char loc;
-//	room_t *room = p_global->cur_area_ptr->room_ptr;	//TODO: wrong? chk below
-//	unsigned char id = room->ff_C;
-	if(!p_global->cur_area_ptr->citadelLevel || !p_global->cur_area_ptr->citadelRoom)
-		return;
-	room = p_global->cur_area_ptr->citadelRoom;	//TODO: copied here by me
-	loc = room->location;
-	tyranPtr = &kPersons[PER_UNKN_372];
-	if(istyran((p_global->cita_area_num << 8) | loc))
-	{
-		if(!(p_global->cur_area_ptr->flags & AreaFlags::TyrannSighted))
-		{
-			ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
-			p_global->cur_area_ptr->flags |= AreaFlags::TyrannSighted;
+	char iscita(short loc) {
+		room_t *room = p_global->cita_area_firstRoom;
+		loc &= 0xFF;
+		for (; room->ff_0 != 0xFF; room++) {
+			if (!(room->flags & RoomFlags::rfHasCitadel))
+				continue;
+			if (room->location == loc + 16)
+				return 1;
+			if (room->location == loc - 16)
+				return 1;
+			if (room->location == loc - 1)
+				return 1;
+			if (room->location == loc + 1)
+				return 1;
 		}
-		level = room->level - 1;
-		if(level < 32)
-			level = 32;
-		room->level = level;
-		citatombe(level);
-	}
-	else
-	{
-		p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
-		citaevol(room->level + 1);
-	}
-}
-void depladino(perso_t *perso)
-{
-	char *dirs, dir, dir2;
-	unsigned char loc;
-	dir = getdirection(perso);
-	if(dir != -1)
-	{
-		melangedir();
-		dirs = tab_2CB1E[dir];
-		loc = perso->roomNum & 0xFF;
-		dir2 = *dirs++;
-		if(dir2 & 0x80)
-			dir2 = -(dir2 & ~0x80);
-		dir2 += loc;
-		if(caselibre(dir2, perso))
-			goto ok;
-		dir2 = *dirs++;
-		if(dir2 & 0x80)
-			dir2 = -(dir2 & ~0x80);
-		dir2 += loc;
-		if (caselibre(dir2, perso))
-			goto ok;
-		dir2 = *dirs++;
-		if(dir2 & 0x80)
-			dir2 = -(dir2 & ~0x80);
-		dir2 += loc;
-		if (caselibre(dir2, perso))
-			goto ok;
-		dir2 = *dirs++;
-		if(dir2 & 0x80)
-			dir2 = -(dir2 & ~0x80);
-		dir2 += loc;
-		if (caselibre(dir2, perso))
-			goto ok;
-		dir2 = perso->lastLoc;
-		perso->lastLoc = 0;
-		if(!caselibre(dir2, perso))
-			return;
-ok:;
-		perso->lastLoc = perso->roomNum & 0xFF;
-		perso->roomNum &= ~0xFF;
-		perso->roomNum |= dir2 & 0xFF;
-		if(perso->targetLoc - 16 == (perso->roomNum & 0xFF))
-			perso->targetLoc = 0;
-		if(perso->targetLoc + 16 == (perso->roomNum & 0xFF))
-			perso->targetLoc = 0;
-		if(perso->targetLoc - 1 == (perso->roomNum & 0xFF))
-			perso->targetLoc = 0;
-		if(perso->targetLoc + 1 == (perso->roomNum & 0xFF))
-			perso->targetLoc = 0;
+		return 0;
 	}
-	else
-		perso->targetLoc = 0;
-}
-void deplaalldino()
-{
-	perso_t *perso = &kPersons[PER_UNKN_18C - 1];	//TODO fix this
-	while((++perso)->roomNum != 0xFFFF)
-	{
-		if(((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
-			continue;
-		if (perso->flags & PersonFlags::pf80)
-			continue;
-		if(!perso->targetLoc)
-			continue;
-		if(--perso->steps)
-			continue;
-		perso->steps = 1;
-		if(perso->roomNum == p_global->roomNum)
-			continue;
-		perso->steps = perso->speed;
-		depladino(perso);
+	void lieuvava(area_t *area) {
+		unsigned char mask;
+		if (area->type == AreaType::atValley) {
+			istyranval(area);
+			area->citadelLevel = 0;
+			if (area->citadelRoom)
+				area->citadelLevel = p_global->cita_area_firstRoom->level;  //TODO: no search?
+			mask = ~(1 << (area->num - Areas::arChamaar));
+			p_global->worldTyrannSighted &= mask;
+			p_global->ff_4E &= mask;
+			p_global->worldGaveGold &= mask;
+			p_global->worldHasVelociraptors &= mask;
+			p_global->worldHasTriceraptors &= mask;
+			p_global->worldHasTyrann &= mask;
+			p_global->ff_53 &= mask;
+			mask = ~mask;
+			if (area->flags & AreaFlags::TyrannSighted)
+				p_global->worldTyrannSighted |= mask;
+			if (area->flags & AreaFlags::afFlag4)
+				p_global->ff_4E |= mask;
+			if (area->flags & AreaFlags::HasTriceraptors)
+				p_global->worldHasTriceraptors |= mask;
+			if (area->flags & AreaFlags::afGaveGold)
+				p_global->worldGaveGold |= mask;
+			if (area->flags & AreaFlags::HasVelociraptors)
+				p_global->worldHasVelociraptors |= mask;
+			if (area->flags & AreaFlags::HasTyrann)
+				p_global->worldHasTyrann |= mask;
+			if (area->flags & AreaFlags::afFlag20)
+				p_global->ff_53 |= mask;
+			if (area == p_global->area_ptr) {
+				p_global->curAreaFlags = area->flags;
+				p_global->curCitadelLevel = area->citadelLevel;
+			}
+		}
+		p_global->ff_4D &= p_global->worldTyrannSighted;
 	}
-}
-void newvallee()
-{
-	perso_t *perso = &kPersons[PER_UNKN_372];
-	short *ptr = tab_2CB16;
-	short roomNum;
-	while((roomNum = *ptr++) != -1)
-	{
-		perso->roomNum = roomNum;
-		perso->flags &= ~PersonFlags::pf80;
-		perso->flags &= ~PersonFlags::pf20;	//TODO: combine?
-		perso++;
-	}
-	perso->roomNum = -1;
-	kAreasTable[7].flags |= AreaFlags::HasTyrann;
-	p_global->worldHasTyrann = 32;	
-}
-char whereiscita()
-{
-	room_t *room = p_global->cita_area_firstRoom;
-	char res = -1;
-	for(;room->ff_0 != 0xFF;room++)
-	{
-		if(!(room->flags & RoomFlags::rfHasCitadel))
-			continue;
-		res = room->location;
-		break;
-	}
-	return res;
-}
-char iscita(short loc)
-{
-	room_t *room = p_global->cita_area_firstRoom;
-	loc &= 0xFF;	
-	for(;room->ff_0 != 0xFF;room++)
-	{
-		if(!(room->flags & RoomFlags::rfHasCitadel))
-			continue;
-		if(room->location == loc + 16)
-			return 1;
-		if(room->location == loc - 16)
-			return 1;
-		if(room->location == loc - 1)
-			return 1;
-		if(room->location == loc + 1)
-			return 1;
-	}
-	return 0;
-}
-void lieuvava(area_t *area)
-{
-	unsigned char mask;
-	if(area->type == AreaType::atValley)
-	{
-		istyranval(area);
-		area->citadelLevel = 0;
-		if(area->citadelRoom)
-			area->citadelLevel = p_global->cita_area_firstRoom->level;	//TODO: no search?
-		mask = ~(1 << (area->num - Areas::arChamaar));
-		p_global->worldTyrannSighted &= mask;
-		p_global->ff_4E &= mask;
-		p_global->worldGaveGold &= mask;
-		p_global->worldHasVelociraptors &= mask;
-		p_global->worldHasTriceraptors &= mask;
-		p_global->worldHasTyrann &= mask;
-		p_global->ff_53 &= mask;
-		mask = ~mask;
-		if(area->flags & AreaFlags::TyrannSighted)
-			p_global->worldTyrannSighted |= mask;
-		if(area->flags & AreaFlags::afFlag4)
-			p_global->ff_4E |= mask;
-		if(area->flags & AreaFlags::HasTriceraptors)
-			p_global->worldHasTriceraptors |= mask;
-		if(area->flags & AreaFlags::afGaveGold)
-			p_global->worldGaveGold |= mask;
-		if(area->flags & AreaFlags::HasVelociraptors)
-			p_global->worldHasVelociraptors |= mask;
-		if(area->flags & AreaFlags::HasTyrann)
-			p_global->worldHasTyrann |= mask;
-		if(area->flags & AreaFlags::afFlag20)
-			p_global->ff_53 |= mask;
-		if(area == p_global->area_ptr)
-		{
-			p_global->curAreaFlags = area->flags;
-			p_global->curCitadelLevel = area->citadelLevel;
-		}
-	}
-	p_global->ff_4D &= p_global->worldTyrannSighted;
-}
-void vivredino()
-{
-	char cita;
-	perso_t *perso = &kPersons[PER_UNKN_18C];
-	for(;perso->roomNum != 0xFFFF;perso++)
-	{
-		if(((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
-			continue;
-		if (perso->flags & PersonFlags::pf80)
-			continue;
-		switch(perso->flags & PersonFlags::pfTypeMask)
-		{
-		case PersonFlags::pftTyrann:
-			if(iscita(perso->roomNum))
-				perso->targetLoc = 0;
-			else if(!perso->targetLoc)
-			{
-				cita = whereiscita();
-				if(cita != -1)
-				{
-					perso->targetLoc = cita;
-					perso->speed = 2;
-					perso->steps = 1;
-				}
-			}
-			break;
-		case PersonFlags::pftTriceraptor:
-			if (perso->flags & PersonFlags::pfInParty)
-			{
-				if(iscita(perso->roomNum))
+	void vivredino() {
+		char cita;
+		perso_t *perso = &kPersons[PER_UNKN_18C];
+		for (; perso->roomNum != 0xFFFF; perso++) {
+			if (((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
+				continue;
+			if (perso->flags & PersonFlags::pf80)
+				continue;
+			switch (perso->flags & PersonFlags::pfTypeMask) {
+			case PersonFlags::pftTyrann:
+				if (iscita(perso->roomNum))
 					perso->targetLoc = 0;
-				else if(!perso->targetLoc)
-				{
+				else if (!perso->targetLoc) {
 					cita = whereiscita();
-					if(cita != -1)
-					{
+					if (cita != -1) {
 						perso->targetLoc = cita;
-						perso->speed = 3;
+						perso->speed = 2;
 						perso->steps = 1;
 					}
 				}
-			}
-			break;
-		case PersonFlags::pftVelociraptor:
-			if (perso->flags & PersonFlags::pf10)
-			{
-				if(perso->roomNum == p_global->roomNum)
-				{
-					perso_t *perso2 = &kPersons[PER_UNKN_372];
-					char found = 0;
-					for(;perso2->roomNum != 0xFFFF;perso2++)
-					{
-						if((perso->roomNum & ~0xFF) == (perso2->roomNum & ~0xFF))
-						{
-							if (perso2->flags & PersonFlags::pf80)
-								continue;
-							perso->targetLoc = perso2->roomNum & 0xFF;
+				break;
+			case PersonFlags::pftTriceraptor:
+				if (perso->flags & PersonFlags::pfInParty) {
+					if (iscita(perso->roomNum))
+						perso->targetLoc = 0;
+					else if (!perso->targetLoc) {
+						cita = whereiscita();
+						if (cita != -1) {
+							perso->targetLoc = cita;
+							perso->speed = 3;
 							perso->steps = 1;
-							found = 1;
-							break;
 						}
 					}
-					if(found)
-						continue;
 				}
-				else
-				{
-					tyranPtr = &kPersons[PER_UNKN_372];
-					if(istyran(perso->roomNum))
-					{
-						if(p_global->phaseNum < 481 && (perso->powers & (1 << (p_global->cita_area_num - 3))))
-						{
-							tyranPtr->flags |= PersonFlags::pf80;
-							tyranPtr->roomNum = 0;
-							perso->flags &= ~PersonFlags::pf10;
-							perso->flags |= PersonFlags::pfInParty;
-							ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannLost);
-							delinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
-							if(naitredino(PersonFlags::pftTriceraptor))
-								ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
-							constcita();
-							p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+				break;
+			case PersonFlags::pftVelociraptor:
+				if (perso->flags & PersonFlags::pf10) {
+					if (perso->roomNum == p_global->roomNum) {
+						perso_t *perso2 = &kPersons[PER_UNKN_372];
+						char found = 0;
+						for (; perso2->roomNum != 0xFFFF; perso2++) {
+							if ((perso->roomNum & ~0xFF) == (perso2->roomNum & ~0xFF)) {
+								if (perso2->flags & PersonFlags::pf80)
+									continue;
+								perso->targetLoc = perso2->roomNum & 0xFF;
+								perso->steps = 1;
+								found = 1;
+								break;
+							}
 						}
-						else
-						{
-							perso->flags &= ~PersonFlags::pf10;
-							perso->flags &= ~PersonFlags::pfInParty;
-							ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsLost);
+						if (found)
+							continue;
+					} else {
+						tyranPtr = &kPersons[PER_UNKN_372];
+						if (istyran(perso->roomNum)) {
+							if (p_global->phaseNum < 481 && (perso->powers & (1 << (p_global->cita_area_num - 3)))) {
+								tyranPtr->flags |= PersonFlags::pf80;
+								tyranPtr->roomNum = 0;
+								perso->flags &= ~PersonFlags::pf10;
+								perso->flags |= PersonFlags::pfInParty;
+								ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannLost);
+								delinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
+								if (naitredino(PersonFlags::pftTriceraptor))
+									ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+								constcita();
+								p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+							} else {
+								perso->flags &= ~PersonFlags::pf10;
+								perso->flags &= ~PersonFlags::pfInParty;
+								ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsLost);
+							}
+							continue;
 						}
-						continue;
 					}
 				}
-			}
-			if(!perso->targetLoc)
-			{
-				short loc;
-				perso->lastLoc = 0;
-				do
-				{
-					loc = (g_ed->_rnd->getRandomNumber(63) & 63) + 16;
-					if((loc & 0xF) >= 12)
-						loc &= ~4;	//TODO: ??? same as -= 4
+				if (!perso->targetLoc) {
+					short loc;
+					perso->lastLoc = 0;
+					do {
+						loc = (g_ed->_rnd->getRandomNumber(63) & 63) + 16;
+						if ((loc & 0xF) >= 12)
+							loc &= ~4;  //TODO: ??? same as -= 4
+					} while (!caselibre(loc, perso));
+					perso->targetLoc = loc;
+					perso->steps = 1;
 				}
-				while(!caselibre(loc, perso));
-				perso->targetLoc = loc;
-				perso->steps = 1;
+				break;
 			}
-			break;
 		}
 	}
-}
-void vivreval(short areaNum)
-{
-	p_global->cita_area_num = areaNum;
-	p_global->cur_area_ptr = &kAreasTable[areaNum - 1];
-	p_global->cita_area_firstRoom = &gameRooms[p_global->cur_area_ptr->firstRoomIndex];
-	deplaalldino();
-	constcita();
-	vivredino();
-	newchampi();
-	newnido();
-	newnidv();
-	if(p_global->phaseNum >= 226)
-		newor();
-	lieuvava(p_global->cur_area_ptr);
-}
-void chaquejour()
-{
-	vivreval(3);
-	vivreval(4);
-	vivreval(5);
-	vivreval(6);
-	vivreval(7);
-	vivreval(8);
-	p_global->drawFlags |= DrawFlags::drDrawTopScreen;
-}
-void temps_passe(short t)
-{
-	short days = p_global->gameDays;
-	short lo = p_global->ff_56;
-	lo += t;
-	if(lo > 255)
-	{
-		days++;
-		lo &= 0xFF;
-	}
-	p_global->ff_56 = lo;
-	t = ((t >> 8) & 0xFF) + days;
-	t -= p_global->gameDays;
-	if(t)
-	{
-		p_global->gameDays += t;
-		while(t--)
-			chaquejour();
-	}
-}
-void heurepasse()
-{
-	temps_passe(5);
-}
-void anim_perso()
-{
-	if(cur_bank_num != p_global->perso_img_bank)
-		load_perso(p_global->perso_ptr);
-	restaurefondbulle();
-	if(restartAnimation)
-	{
-		last_anim_ticks = TimerTicks;
-		restartAnimation = 0;
-	}
-	cur_anim_frame_num = (TimerTicks - last_anim_ticks) >> 2;	// TODO: check me!!!
-	if(cur_anim_frame_num > num_anim_frames)				// TODO: bug?
-		animateTalking = 0;
-	if(p_global->curPersoAnimPtr && !p_global->animationFlags && cur_anim_frame_num != last_anim_frame_num)
-	{
-		last_anim_frame_num = cur_anim_frame_num;
-		if(*p_global->curPersoAnimPtr == 0xFF)
-			getanimrnd();
-		bank_data_ptr = perso_img_bank_data_ptr;
-		num_img_desc = 0;
-		perso_spr(p_global->curPersoAnimPtr);
-		p_global->curPersoAnimPtr += num_img_desc + 1;
-		dword_3072C = imagedesc + 200;
-		virespritebouche();
-		if(*dword_3072C)
-			af_image();
-		animationDelay--;
-		if(!animationDelay)	//TODO: combine
-		{
-			p_global->animationFlags = 1;
-			animationDelay = 8;
+	void vivreval(short areaNum) {
+		p_global->cita_area_num = areaNum;
+		p_global->cur_area_ptr = &kAreasTable[areaNum - 1];
+		p_global->cita_area_firstRoom = &gameRooms[p_global->cur_area_ptr->firstRoomIndex];
+		deplaalldino();
+		constcita();
+		vivredino();
+		newchampi();
+		newnido();
+		newnidv();
+		if (p_global->phaseNum >= 226)
+			newor();
+		lieuvava(p_global->cur_area_ptr);
+	}
+	void chaquejour() {
+		vivreval(3);
+		vivreval(4);
+		vivreval(5);
+		vivreval(6);
+		vivreval(7);
+		vivreval(8);
+		p_global->drawFlags |= DrawFlags::drDrawTopScreen;
+	}
+	void temps_passe(short t) {
+		short days = p_global->gameDays;
+		short lo = p_global->ff_56;
+		lo += t;
+		if (lo > 255) {
+			days++;
+			lo &= 0xFF;
+		}
+		p_global->ff_56 = lo;
+		t = ((t >> 8) & 0xFF) + days;
+		t -= p_global->gameDays;
+		if (t) {
+			p_global->gameDays += t;
+			while (t--)
+				chaquejour();
+		}
+	}
+	void heurepasse() {
+		temps_passe(5);
+	}
+	void anim_perso() {
+		if (cur_bank_num != p_global->perso_img_bank)
+			load_perso(p_global->perso_ptr);
+		restaurefondbulle();
+		if (restartAnimation) {
+			last_anim_ticks = TimerTicks;
+			restartAnimation = 0;
 		}
-	}
-
-	animationDelay--;
-	if(!animationDelay)	//TODO: combine
-	{
-		getanimrnd();
-		//TODO: no reload?
-	}
-	if(animateTalking)
-	{
-		if(!animationTable)
-		{
-			animationTable = gameLipsync + 7262;	//TODO: fix me
-			if(!fond_saved)
-				sauvefondbouche();
-		}
-		if(!personTalking)
-			cur_anim_frame_num = num_anim_frames - 1;
-		animationIndex = animationTable[cur_anim_frame_num];
-		if(animationIndex == 0xFF)
+		cur_anim_frame_num = (TimerTicks - last_anim_ticks) >> 2;   // TODO: check me!!!
+		if (cur_anim_frame_num > num_anim_frames)               // TODO: bug?
 			animateTalking = 0;
-		else if(animationIndex != lastAnimationIndex)
-		{
+		if (p_global->curPersoAnimPtr && !p_global->animationFlags && cur_anim_frame_num != last_anim_frame_num) {
+			last_anim_frame_num = cur_anim_frame_num;
+			if (*p_global->curPersoAnimPtr == 0xFF)
+				getanimrnd();
 			bank_data_ptr = perso_img_bank_data_ptr;
-			restaurefondbouche();
-//			debug("perso spr %d", animationIndex);
-			perso_spr(p_global->persoSpritePtr2 + animationIndex * 2);	//TODO: shorts?
+			num_img_desc = 0;
+			perso_spr(p_global->curPersoAnimPtr);
+			p_global->curPersoAnimPtr += num_img_desc + 1;
 			dword_3072C = imagedesc + 200;
-			if(*dword_3072C)
+			virespritebouche();
+			if (*dword_3072C)
 				af_image();
-			lastAnimationIndex = animationIndex;
+			animationDelay--;
+			if (!animationDelay) { //TODO: combine
+				p_global->animationFlags = 1;
+				animationDelay = 8;
+			}
+		}
+
+		animationDelay--;
+		if (!animationDelay) { //TODO: combine
+			getanimrnd();
+			//TODO: no reload?
+		}
+		if (animateTalking) {
+			if (!animationTable) {
+				animationTable = gameLipsync + 7262;    //TODO: fix me
+				if (!fond_saved)
+					sauvefondbouche();
+			}
+			if (!personTalking)
+				cur_anim_frame_num = num_anim_frames - 1;
+			animationIndex = animationTable[cur_anim_frame_num];
+			if (animationIndex == 0xFF)
+				animateTalking = 0;
+			else if (animationIndex != lastAnimationIndex) {
+				bank_data_ptr = perso_img_bank_data_ptr;
+				restaurefondbouche();
+//			debug("perso spr %d", animationIndex);
+				perso_spr(p_global->persoSpritePtr2 + animationIndex * 2);  //TODO: shorts?
+				dword_3072C = imagedesc + 200;
+				if (*dword_3072C)
+					af_image();
+				lastAnimationIndex = animationIndex;
+			}
 		}
+		af_subtitle();
 	}
-	af_subtitle();		
-}
-void getanimrnd()
-{
-	short rnd;
-	animationDelay = 8;
-	rnd = g_ed->_rnd->getRandomNumber(65535) & (unsigned char)~0x18;	//TODO
-	dword_30724 = p_global->persoSpritePtr + 16;	//TODO
-	p_global->curPersoAnimPtr = p_global->persoSpritePtr + ((dword_30724[1] << 8) + dword_30724[0]);
-	p_global->animationFlags = 1;
-	if(rnd >= 8)
-		return;
-	p_global->animationFlags = 0;
-	if(rnd <= 0)
-		return;
-	for(rnd *= 8;rnd > 0;rnd--)
-	{
-		while(*p_global->curPersoAnimPtr)
+	void getanimrnd() {
+		short rnd;
+		animationDelay = 8;
+		rnd = g_ed->_rnd->getRandomNumber(65535) & (unsigned char)~0x18;    //TODO
+		dword_30724 = p_global->persoSpritePtr + 16;    //TODO
+		p_global->curPersoAnimPtr = p_global->persoSpritePtr + ((dword_30724[1] << 8) + dword_30724[0]);
+		p_global->animationFlags = 1;
+		if (rnd >= 8)
+			return;
+		p_global->animationFlags = 0;
+		if (rnd <= 0)
+			return;
+		for (rnd *= 8; rnd > 0; rnd--) {
+			while (*p_global->curPersoAnimPtr)
+				p_global->curPersoAnimPtr++;
 			p_global->curPersoAnimPtr++;
-		p_global->curPersoAnimPtr++;
+		}
 	}
-}
-void addanim()
-{
-	lastAnimationIndex = -1;
-	last_anim_ticks = 0;
-	p_global->animationFlags = 0xC0;
-	p_global->curPersoAnimPtr = p_global->persoSpritePtr;
-	getanimrnd();
-	animationActive = 1;
-	if(p_global->perso_ptr == &kPersons[PER_ROI])
-		return;
-	perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));	//TODO: GetElem(0)
-	dword_3072C = imagedesc + 200;
-	if (p_global->perso_ptr->id != PersonId::pidCabukaOfCantura && p_global->perso_ptr->targetLoc != 7)	//TODO: targetLoc is minisprite idx
-		virespritebouche();
-	if(*dword_3072C)
-		af_image();
-}
-void virespritebouche()
-{
-	unsigned char *src = dword_3072C + 2;
-	unsigned char *dst = src;
-	char cnt = dword_3072C[0];
-	while(cnt--)
-	{
-		unsigned char a = *src++;
-		unsigned char b = *src++;
-		unsigned char c = *src++;
-		dst[0] = a;
-		dst[1] = b;
-		dst[2] = c;
-		if(dword_30728[0] != 0xFF)
-		{
-			if((a < dword_30728[0] || a > dword_30728[1])
-			&& (a < dword_30728[2] || a > dword_30728[3]))
+	void addanim() {
+		lastAnimationIndex = -1;
+		last_anim_ticks = 0;
+		p_global->animationFlags = 0xC0;
+		p_global->curPersoAnimPtr = p_global->persoSpritePtr;
+		getanimrnd();
+		animationActive = 1;
+		if (p_global->perso_ptr == &kPersons[PER_ROI])
+			return;
+		perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));  //TODO: GetElem(0)
+		dword_3072C = imagedesc + 200;
+		if (p_global->perso_ptr->id != PersonId::pidCabukaOfCantura && p_global->perso_ptr->targetLoc != 7) //TODO: targetLoc is minisprite idx
+			virespritebouche();
+		if (*dword_3072C)
+			af_image();
+	}
+	void virespritebouche() {
+		unsigned char *src = dword_3072C + 2;
+		unsigned char *dst = src;
+		char cnt = dword_3072C[0];
+		while (cnt--) {
+			unsigned char a = *src++;
+			unsigned char b = *src++;
+			unsigned char c = *src++;
+			dst[0] = a;
+			dst[1] = b;
+			dst[2] = c;
+			if (dword_30728[0] != 0xFF) {
+				if ((a < dword_30728[0] || a > dword_30728[1])
+				        && (a < dword_30728[2] || a > dword_30728[3]))
+					dst += 3;
+				else
+					dword_3072C[0]--;
+			} else
 				dst += 3;
-			else
-				dword_3072C[0]--;
 		}
-		else
-			dst += 3;
 	}
-}
-void anim_perfin()
-{
-	p_global->animationFlags &= ~0x80;
-	animationDelay = 0;
-	animationActive = 0;
-}
-void perso_spr(unsigned char *spr)
-{
-	unsigned char *img = imagedesc + 200 + 2;
-	short count = 0;
-	unsigned char c, cc;
-	while((c = *spr++))
-	{
-		unsigned char *src;
-		short index;
-		cc = 0;
-		if(c == 1)
-		{
-			cc = index;
-			c = *spr++;
-		}
-		num_img_desc++;
-		index = (cc << 8) | c;
-		index -= 2;
+	void anim_perfin() {
+		p_global->animationFlags &= ~0x80;
+		animationDelay = 0;
+		animationActive = 0;
+	}
+	void perso_spr(unsigned char *spr) {
+		unsigned char *img = imagedesc + 200 + 2;
+		short count = 0;
+		unsigned char c, cc;
+		while ((c = *spr++)) {
+			unsigned char *src;
+			short index;
+			cc = 0;
+			if (c == 1) {
+				cc = index;
+				c = *spr++;
+			}
+			num_img_desc++;
+			index = (cc << 8) | c;
+			index -= 2;
 //	debug("anim sprite %d", index);
 
-		if(index > max_perso_desc)
-			index = max_perso_desc;
-		index *= 2;			//TODO: src = GetElem(ff_C2, index)
-		src = p_global->ff_C2;
-		src = src + PLE16(src + index);
-		while((c = *src++))
-		{
-			*img++ = c;
-			*img++ = *src++;
-			*img++ = *src++;
-			count++;
+			if (index > max_perso_desc)
+				index = max_perso_desc;
+			index *= 2;         //TODO: src = GetElem(ff_C2, index)
+			src = p_global->ff_C2;
+			src = src + PLE16(src + index);
+			while ((c = *src++)) {
+				*img++ = c;
+				*img++ = *src++;
+				*img++ = *src++;
+				count++;
+			}
 		}
+		imagedesc[200] = count & 0xFF;
+		imagedesc[201] = count >> 8;
 	}
-	imagedesc[200] = count & 0xFF;
-	imagedesc[201] = count >> 8;
-}
-void af_image()
-{
-	unsigned char *img = imagedesc + 200, *img_start, *curimg = imagedesc;
-	short count;
+	void af_image() {
+		unsigned char *img = imagedesc + 200, *img_start, *curimg = imagedesc;
+		short count;
 
-	count = PLE16(img);
-	if(!count)
-		return;
-	img_start = img;
-	img += 2;
-	count *= 3;
-	while(count--)
-		*curimg++ = *img++;
-	img = img_start;
-	count = PLE16(img); img += 2;
+		count = PLE16(img);
+		if (!count)
+			return;
+		img_start = img;
+		img += 2;
+		count *= 3;
+		while (count--)
+			*curimg++ = *img++;
+		img = img_start;
+		count = PLE16(img);
+		img += 2;
 /////// draw it
-	while(count--)
-	{
-		unsigned short index = *img++;
-		unsigned short x = *img++ + gameIcons[0].sx;
-		unsigned short y = *img++ + gameIcons[0].sy;
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char h0, h1, mode;
-		short w, h;
-		index--;
-		if(PLE16(pix) > 2)
-			readpalette(pix + 2);
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//	short	height:9
-		//	short	pad:6;
-		//	short	flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		if(mode != 0xFF && mode != 0xFE)
-			continue;	//TODO: enclosing block?
-		if(h1 & 0x80)
-		{
-		// compressed
-			for(;h-- > 0;)
-			{
-				short ww;
-				for(ww = w;ww > 0;)
-				{
-					unsigned char c = *pix++;
-					if(c >= 0x80)
-					{
-						if(c == 0x80)
-						{
-							unsigned char fill = *pix++;
-							if(fill == 0)
-							{
-								scr += 128 + 1;
-								ww -= 128 + 1;
-							}
-							else
-							{
-								unsigned char run;
-								*scr++ = fill;	//TODO: wha?
-								*scr++ = fill;
-								ww -= 128 + 1;
-								for(run = 127;run--;)
+		while (count--) {
+			unsigned short index = *img++;
+			unsigned short x = *img++ + gameIcons[0].sx;
+			unsigned short y = *img++ + gameIcons[0].sy;
+			unsigned char *pix = bank_data_ptr;
+			unsigned char *scr = p_mainview_buf + x + y * 640;
+			unsigned char h0, h1, mode;
+			short w, h;
+			index--;
+			if (PLE16(pix) > 2)
+				readpalette(pix + 2);
+			pix += PLE16(pix);
+			pix += PLE16(pix + index * 2);
+			//  short   height:9
+			//  short   pad:6;
+			//  short   flag:1;
+			h0 = *pix++;
+			h1 = *pix++;
+			w = ((h1 & 1) << 8) | h0;
+			h = *pix++;
+			mode = *pix++;
+			if (mode != 0xFF && mode != 0xFE)
+				continue;   //TODO: enclosing block?
+			if (h1 & 0x80) {
+				// compressed
+				for (; h-- > 0;) {
+					short ww;
+					for (ww = w; ww > 0;) {
+						unsigned char c = *pix++;
+						if (c >= 0x80) {
+							if (c == 0x80) {
+								unsigned char fill = *pix++;
+								if (fill == 0) {
+									scr += 128 + 1;
+									ww -= 128 + 1;
+								} else {
+									unsigned char run;
+									*scr++ = fill;  //TODO: wha?
 									*scr++ = fill;
+									ww -= 128 + 1;
+									for (run = 127; run--;)
+										*scr++ = fill;
+								}
+							} else {
+								unsigned char fill = *pix++;
+								unsigned char run = 255 - c + 2;
+								ww -= run;
+								if (fill == 0)
+									scr += run;
+								else
+									for (; run--;)
+										*scr++ = fill;
 							}
-						}
-						else
-						{
-							unsigned char fill = *pix++;
-							unsigned char run = 255 - c + 2;
+						} else {
+							unsigned char run = c + 1;
 							ww -= run;
-							if(fill == 0)
-								scr += run;
-							else
-								for(;run--;)
-									*scr++ = fill;
-						}
-					}
-					else
-					{
-						unsigned char run = c + 1;
-						ww -= run;
-						for(;run--;)
-						{
-							unsigned char p = *pix++;
-							if(p == 0)
-								scr++;
-							else
-								*scr++ = p;
+							for (; run--;) {
+								unsigned char p = *pix++;
+								if (p == 0)
+									scr++;
+								else
+									*scr++ = p;
+							}
 						}
 					}
+					scr += 640 - w;
 				}
-				scr += 640 - w;
-			}
-		}
-		else
-		{
-			// uncompressed
-			for(;h--;)
-			{
-				short ww;
-				for(ww = w;ww--;)
-				{
-					unsigned char p = *pix++;
-					if(p == 0)
-						scr++;
-					else
-						*scr++ = p;
+			} else {
+				// uncompressed
+				for (; h--;) {
+					short ww;
+					for (ww = w; ww--;) {
+						unsigned char p = *pix++;
+						if (p == 0)
+							scr++;
+						else
+							*scr++ = p;
+					}
+					scr += 640 - w;
 				}
-				scr += 640 - w;
 			}
 		}
 	}
-}
-void af_perso1()
-{
-	perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));
-	af_image();
-}
-void af_perso()
-{
-	load_perso_cour();
-	af_perso1();
-}
-void ef_perso()
-{
-	p_global->animationFlags &= 0x3F;
-}
-void load_perso(perso_t *perso)
-{
-	unsigned char *ptr, *baseptr;
-	perso_img_bank_data_ptr = 0;
-	if(!perso->bank)
-		return;
-	if(perso->bank != p_global->perso_img_bank)
-	{
-		cur_perso_rect = &perso_rects[perso->id];	//TODO: array of short?
-		dword_30728 = tab_persxx[perso->id];
-		ef_perso();
-		p_global->perso_img_bank = perso->bank;
-		use_bank(p_global->perso_img_bank);
-		perso_img_bank_data_ptr = bank_data_ptr;
-		ptr = bank_data_ptr;
-		ptr += PLE16(ptr);
-		baseptr = ptr;
-		ptr += PLE16(ptr) - 2;
-		ptr = baseptr + PLE16(ptr) + 4;
-		gameIcons[0].sx = PLE16(ptr);
-		gameIcons[0].sy = PLE16(ptr + 2);
-		gameIcons[0].ex = PLE16(ptr + 4);
-		gameIcons[0].ey = PLE16(ptr + 6);
-		ptr += 8;
-		p_global->ff_C2 = ptr + 2;
-		max_perso_desc = PLE16(ptr) / 2;
-		ptr += PLE16(ptr);
-		baseptr = ptr;
-		ptr += PLE16(ptr) - 2;
-		p_global->persoSpritePtr = baseptr;
-		p_global->persoSpritePtr2 = baseptr + PLE16(ptr);
-		debug("load perso: b6 len is %d", p_global->persoSpritePtr2 - p_global->persoSpritePtr);
-	}
-	else
-	{
-		use_bank(p_global->perso_img_bank);
-		perso_img_bank_data_ptr = bank_data_ptr;
+	void af_perso1() {
+		perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));
+		af_image();
 	}
-}
-void load_perso_cour()
-{
-	load_perso(p_global->perso_ptr);
-}
-void fin_perso()
-{
-	p_global->animationFlags &= 0x3F;
-	p_global->curPersoAnimPtr = 0;
-	p_global->ff_CA = 0;
-	p_global->perso_img_bank = -1;
-	anim_perfin();
-}
-void no_perso()
-{
-	if(p_global->displayFlags == DisplayFlags::dfPerson)
-	{
-		p_global->displayFlags = p_global->oldDisplayFlags;
-		fin_perso();
+	void af_perso() {
+		load_perso_cour();
+		af_perso1();
 	}
-	endpersovox();
-}
-void close_perso()
-{
-	char old;
-	endpersovox();
-	if (p_global->displayFlags == DisplayFlags::dfPerson && p_global->perso_ptr->id != PersonId::pidNarrator && p_global->eventType != EventType::etEventE)
-	{
-		rundcurs();
-		savedUnderSubtitles = 1;
-		restaurefondbulle();
-		afficher();
-		p_global->ff_103 = 16;
+	void ef_perso() {
+		p_global->animationFlags &= 0x3F;
 	}
-	if(p_global->perso_ptr->id == PersonId::pidNarrator)
-		p_global->ff_103 = 69;
-	p_global->eloiHaveNews &= 1;
-	p_global->ff_CA = 0;
-	p_global->ff_F6 = 0;
-	if (p_global->displayFlags == DisplayFlags::dfPerson)
-	{
-		p_global->displayFlags = p_global->oldDisplayFlags;
+	void load_perso(perso_t *perso) {
+		unsigned char *ptr, *baseptr;
+		perso_img_bank_data_ptr = 0;
+		if (!perso->bank)
+			return;
+		if (perso->bank != p_global->perso_img_bank) {
+			cur_perso_rect = &perso_rects[perso->id];   //TODO: array of short?
+			dword_30728 = tab_persxx[perso->id];
+			ef_perso();
+			p_global->perso_img_bank = perso->bank;
+			use_bank(p_global->perso_img_bank);
+			perso_img_bank_data_ptr = bank_data_ptr;
+			ptr = bank_data_ptr;
+			ptr += PLE16(ptr);
+			baseptr = ptr;
+			ptr += PLE16(ptr) - 2;
+			ptr = baseptr + PLE16(ptr) + 4;
+			gameIcons[0].sx = PLE16(ptr);
+			gameIcons[0].sy = PLE16(ptr + 2);
+			gameIcons[0].ex = PLE16(ptr + 4);
+			gameIcons[0].ey = PLE16(ptr + 6);
+			ptr += 8;
+			p_global->ff_C2 = ptr + 2;
+			max_perso_desc = PLE16(ptr) / 2;
+			ptr += PLE16(ptr);
+			baseptr = ptr;
+			ptr += PLE16(ptr) - 2;
+			p_global->persoSpritePtr = baseptr;
+			p_global->persoSpritePtr2 = baseptr + PLE16(ptr);
+			debug("load perso: b6 len is %d", p_global->persoSpritePtr2 - p_global->persoSpritePtr);
+		} else {
+			use_bank(p_global->perso_img_bank);
+			perso_img_bank_data_ptr = bank_data_ptr;
+		}
+	}
+	void load_perso_cour() {
+		load_perso(p_global->perso_ptr);
+	}
+	void fin_perso() {
 		p_global->animationFlags &= 0x3F;
 		p_global->curPersoAnimPtr = 0;
+		p_global->ff_CA = 0;
+		p_global->perso_img_bank = -1;
 		anim_perfin();
-		if(p_global->displayFlags & DisplayFlags::dfMirror)
-		{
-			gametomiroir(1);
-			scroll_pos = old_scroll_pos;
-			scroll();
-			return;
-		}
-		if(p_global->numGiveObjs)
-		{
-			if(!(p_global->displayFlags & DisplayFlags::dfFlag2))
-				showobjects();
-			p_global->numGiveObjs = 0;
-		}
-		if(p_global->ff_F2 & 1)
-		{
-			p_global->ff_102 = 6;
-			p_global->ff_F2 &= ~1;
-		}
-		old = p_global->newLocation;
-		p_global->newLocation = 0;
-		if(!(p_global->narratorSequence & 0x80))
-			p_global->ff_100 = -1;
-		maj_salle(p_global->roomNum);
-		p_global->newLocation = old;
 	}
-	if(p_global->chrono)
-		p_global->chrono_on = 1;
-}
-void af_fondsuiveur()
-{
-	char id = p_global->perso_ptr->id;
-	suiveur_t *suiveur = suiveurs_list;
-	for(;suiveur->id != -1;suiveur++)
-	{
-		if(suiveur->id == id)
-		{
-			int bank = 326;
-			if(suiveur->sx >= 320)
-				bank = 327;
-			use_bank(bank + p_global->roomBgBankNum);
-			noclipax_avecnoir(0, 0, 16);
-			break;
+	void no_perso() {
+		if (p_global->displayFlags == DisplayFlags::dfPerson) {
+			p_global->displayFlags = p_global->oldDisplayFlags;
+			fin_perso();
 		}
+		endpersovox();
 	}
-}
-void af_fondperso1()
-{
-	unsigned char bank;
-	char *ptab;
-	if(p_global->perso_ptr == &kPersons[PER_MESSAGER])
-	{
-		gameIcons[0].sx = 0;
-		perso_rects[PER_MESSAGER].sx = 2;
-		bank = p_global->persoBackgroundBankIdx;
-		if(p_global->eventType == EventType::etEventE)
-		{
-			p_global->ff_103 = 1;
-			goto no_suiveur;
-		}
-		gameIcons[0].sx = 60;
-		perso_rects[PER_MESSAGER].sx = 62;
-	}
-	if(p_global->perso_ptr == &kPersons[PER_THOO])
-	{
-		bank = 37;
-		if(p_global->curObjectId == Objects::obShell)
-			goto no_suiveur;
-	}
-	ptab = kPersoRoomBankTable + p_global->perso_ptr->roomBankIdx;
-	bank = *ptab++;
-	if(!(p_global->perso_ptr->party & p_global->party))
-	{
-		while((bank = *ptab++) != 0xFF)
-		{
-			if(bank == (p_global->roomNum & 0xFF))	//TODO: signed vs unsigned - chg r31 to uns?
-			{
-				bank = *ptab;
+	void close_perso() {
+		char old;
+		endpersovox();
+		if (p_global->displayFlags == DisplayFlags::dfPerson && p_global->perso_ptr->id != PersonId::pidNarrator && p_global->eventType != EventType::etEventE) {
+			rundcurs();
+			savedUnderSubtitles = 1;
+			restaurefondbulle();
+			afficher();
+			p_global->ff_103 = 16;
+		}
+		if (p_global->perso_ptr->id == PersonId::pidNarrator)
+			p_global->ff_103 = 69;
+		p_global->eloiHaveNews &= 1;
+		p_global->ff_CA = 0;
+		p_global->ff_F6 = 0;
+		if (p_global->displayFlags == DisplayFlags::dfPerson) {
+			p_global->displayFlags = p_global->oldDisplayFlags;
+			p_global->animationFlags &= 0x3F;
+			p_global->curPersoAnimPtr = 0;
+			anim_perfin();
+			if (p_global->displayFlags & DisplayFlags::dfMirror) {
+				gametomiroir(1);
+				scroll_pos = old_scroll_pos;
+				scroll();
+				return;
+			}
+			if (p_global->numGiveObjs) {
+				if (!(p_global->displayFlags & DisplayFlags::dfFlag2))
+					showobjects();
+				p_global->numGiveObjs = 0;
+			}
+			if (p_global->ff_F2 & 1) {
+				p_global->ff_102 = 6;
+				p_global->ff_F2 &= ~1;
+			}
+			old = p_global->newLocation;
+			p_global->newLocation = 0;
+			if (!(p_global->narratorSequence & 0x80))
+				p_global->ff_100 = -1;
+			maj_salle(p_global->roomNum);
+			p_global->newLocation = old;
+		}
+		if (p_global->chrono)
+			p_global->chrono_on = 1;
+	}


Commit: 517bcad68420855b09d52f64dc67637b260f9b45
    https://github.com/scummvm/scummvm/commit/517bcad68420855b09d52f64dc67637b260f9b45
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-25T22:41:53+01:00

Commit Message:
CRYO: Fix warnings

Changed paths:
    engines/cryo/defs.h
    engines/cryo/eden.cpp
    engines/cryo/eden.h
    engines/cryo/module.mk


diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h
index 4c9a202..ae6ce7f 100644
--- a/engines/cryo/defs.h
+++ b/engines/cryo/defs.h
@@ -55,7 +55,7 @@ enum Areas {
 	arWhiteArch,
 	arMoorkusLair
 };
-};
+}
 
 #define MKRM(a,l) (((a) << 8) | (l))
 
@@ -154,7 +154,7 @@ enum Objects {
 	obTablet5,
 	obTablet6
 };
-};
+}
 
 enum PERSO {
 	PER_ROI = 0,
@@ -242,7 +242,7 @@ enum PersonId {
 	pidDinosaur,                            // different species of friendly dino
 	pidEnemy                                // different species of enemy dino
 };
-};
+}
 
 // person in room mask bits
 namespace PersonMask {
@@ -263,7 +263,7 @@ enum PersonMask {
 	pmEnemy  = 0x2000,
 	pmMorkus = 0x4000
 };
-};
+}
 
 namespace PersonFlags {
 enum PersonFlags {
@@ -289,7 +289,7 @@ enum PersonFlags {
 	pfInParty = 0x40,
 	pf80 = 0x80
 };
-};
+}
 
 #pragma pack(push, 1)
 struct perso_t {
@@ -320,7 +320,7 @@ enum ObjectFlags {
 	ofFlag1 = 1,
 	ofInHands = 2       // Currently holding this object in hands
 };
-};
+}
 
 #define MAX_OBJECTS 42
 struct object_t {
@@ -339,7 +339,7 @@ enum DialogFlags {
 	dfRepeatable = 0x40,
 	dfSpoken = 0x80
 };
-};
+}
 
 namespace DialogType {
 enum DialogType {
@@ -351,7 +351,7 @@ enum DialogType {
 	dtInspect,
 	dtHint
 };
-};
+}
 
 struct dial_t {
 	char        flags;          // 0-3 - action index, 4 - highest bit of contidion index, rest is DialogFlags
@@ -415,7 +415,7 @@ enum RoomFlags {
 	rf40 = 0x40,
 	rf80 = 0x80
 };
-};
+}
 
 struct room_t {
 	unsigned char   ff_0;
@@ -446,7 +446,7 @@ enum AreaFlags {
 	TyrannSighted = 0x4000,
 	afFlag8000 = 0x8000
 };
-};
+}
 
 namespace AreaType {
 enum AreaType {
@@ -454,7 +454,7 @@ enum AreaType {
 	atValley = 2,
 	atCave = 3
 };
-};
+}
 
 struct area_t {
 	unsigned char   num;
@@ -483,7 +483,7 @@ enum ValleyNews {
 	vnHidden = 0x80,
 	vnEnd = 0xFF
 };
-};
+}
 
 namespace DisplayFlags {
 enum DisplayFlags {
@@ -496,7 +496,7 @@ enum DisplayFlags {
 	dfFlag40 = 0x40,
 	dfFlag80 = 0x80
 };
-};
+}
 
 namespace DrawFlags {
 enum DrawFlags {
@@ -507,7 +507,7 @@ enum DrawFlags {
 	drDrawMenu = 0x10,
 	drDrawFlag20 = 0x20
 };
-};
+}
 
 namespace MenuFlags {
 enum MenuFlags {
@@ -517,7 +517,7 @@ enum MenuFlags {
 	mfFlag8 = 8,
 	mfFlag10 = 0x10
 };
-};
+}
 
 namespace MusicType {
 enum MusicType {  //TODO: same as DialogType?
@@ -527,7 +527,7 @@ enum MusicType {  //TODO: same as DialogType?
 	mtEvent = 4,
 	mtFF = 0xFF
 };
-};
+}
 
 namespace EventType {
 enum EventType {
@@ -549,7 +549,7 @@ enum EventType {
 	etEvent12 = 18,
 	etGotoArea = 0x80   // + area id
 };
-};
+}
 
 namespace GameFlags {
 enum GameFlags {
@@ -570,7 +570,7 @@ enum GameFlags {
 	gfFlag4000 = 0x4000,
 	gfFlag8000 = 0x8000
 };
-};
+}
 
 struct global_t {
 	unsigned char   areaNum;
diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp
index d5253d3..98b45d7 100644
--- a/engines/cryo/eden.cpp
+++ b/engines/cryo/eden.cpp
@@ -7698,7 +7698,7 @@ skip:
 			return;
 
 #define CLFile_Write(h, ptr, size) \
-	debug("writing 0x%X bytes", *size); \
+	debug("writing 0x%lX bytes", *size); \
 	h->write(ptr, *size);
 
 		vavaoffsetout();
diff --git a/engines/cryo/eden.h b/engines/cryo/eden.h
index c24f77a..ae7afe3 100644
--- a/engines/cryo/eden.h
+++ b/engines/cryo/eden.h
@@ -11,4 +11,4 @@ public:
 
 class EdenGameImpl;
 
-}
\ No newline at end of file
+}
diff --git a/engines/cryo/module.mk b/engines/cryo/module.mk
index 4cda964..b7a81fa 100644
--- a/engines/cryo/module.mk
+++ b/engines/cryo/module.mk
@@ -1,8 +1,8 @@
 MODULE := engines/cryo
 
 MODULE_OBJS = \
-	cryo.o \
 	eden.o \
+	cryo.o \
 	detection.o
 
 # This module can be built as a plugin


Commit: 390c3793854a1c6b9c188112be3d8f293ae4475d
    https://github.com/scummvm/scummvm/commit/390c3793854a1c6b9c188112be3d8f293ae4475d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-25T22:41:53+01:00

Commit Message:
CRYO: Fix line endings

Changed paths:
    engines/cryo/CLError.c
    engines/cryo/CLHNM.c
    engines/cryo/CLSouNdRaw.c
    engines/cryo/CryoLib.h
    engines/cryo/CryoLibStub.c
    engines/cryo/LempelZiv.cpp
    engines/cryo/LempelZiv.h
    engines/cryo/ResourceManager.cpp
    engines/cryo/ResourceManager.h
    engines/cryo/bugs.txt
    engines/cryo/clsoundgroup.c
    engines/cryo/cryo.cpp
    engines/cryo/cryo.h
    engines/cryo/defs.h
    engines/cryo/eden.cpp
    engines/cryo/eden.h
    engines/cryo/gameflow.txt
    engines/cryo/platdefs.h
    engines/cryo/readme.txt


diff --git a/engines/cryo/CLError.c b/engines/cryo/CLError.c
index 85abfef..d9f8bad 100644
--- a/engines/cryo/CLError.c
+++ b/engines/cryo/CLError.c
@@ -1,3 +1,3 @@
-#include "cryolib.h"
-
-short __debug, __libError, __osError;
+#include "cryolib.h"
+
+short __debug, __libError, __osError;
diff --git a/engines/cryo/CLHNM.c b/engines/cryo/CLHNM.c
index 9b30c50..d459489 100644
--- a/engines/cryo/CLHNM.c
+++ b/engines/cryo/CLHNM.c
@@ -1,746 +1,746 @@
-#include "cryolib.h"
-
-static short safe_palette = 0;
-static short pred_r = 0, pred_l = 0;
-static short use_adpcm = 0;
-static float hnm_rate = 0.0;
-static float next_frame_time = 0.0;
-static float expected_frame_time = 0.0;
-static float time_drift = 0.0;
-static short use_mono = 0;
-static short use_sound = 0;
-static short use_sound_sync = 0;
-static short pending_sounds = 0;
-static short sound_started = 0;
-static short preserve_color0 = 0;
-static soundchannel_t *soundChannel_adpcm = 0;
-static soundgroup_t *soundGroup_adpcm = 0;
-static soundchannel_t *soundChannel = 0;
-static soundgroup_t *soundGroup = 0;
-static void (*custom_chunk_handler)(unsigned char *buffer, int size, short id, char h6, char h7) = 0;
-static short use_preload = 0;
-static short decomp_table[256];
-
-void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
-
-void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output) {
-	unsigned char *inp = buffer;
-	unsigned char *out = output;
-
-	unsigned int queue = 0;
-	int qpos = -1;
-
-	//TODO: fix for BE
-#define GetBit() ( 1 & ( (qpos >= 0) ? (queue >> qpos--) : (queue = *(unsigned int*)((inp += 4) - 4)) >> ((qpos = 30) + 1) ) )
-
-	for (;;) {
-		if (GetBit()) {
-			*out++ = *inp++;
-		} else {
-			int l, o;
-			if (GetBit()) {
-				l = *inp & 7;
-				o = *(unsigned short *)inp >> 3;
-				inp += 2;
-				o -= 8192;
-				if (!l)
-					l = *inp++;
-				if (!l)
-					break;
-			} else {
-				l = GetBit() * 2 + GetBit();
-				o = *(inp++) - 256;
-			}
-			l += 2;
-			while (l--) {
-				*out = *(out + o);
-				out++;
-			}
-		}
-	}
-
-#undef GetBit
-
-	return;
-}
-
-void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
-                     unsigned char *input, int width, char flags) {
-	unsigned int code;
-	char mode, count, color;
-	unsigned short offs;
-	unsigned char *ref;
-	unsigned char *out_start = output;
-	unsigned char swap;
-	int shft1, shft2;
-//	return;
-	if ((flags & 1) == 0) {
-		//HNM4 classic
-		int twolinesabove = -(width * 2);
-		for (;;) {
-			code = PLE32(input) & 0xFFFFFF; //input++;
-			count = code & 0x1F;
-			if (count) {
-				input += 3;
-				mode = (code >> 5) & 0xF;
-				offs = code >> 9;
-				//
-				swap = mode >> 3;
-				ref = ((mode & 1) ? prev_buffer : curr_buffer) + (output - out_start) + (offs * 2) - 32768;
-				if (mode & 2) {
-					//                  ref += twolinesabove;
-					shft1 = twolinesabove + 1;
-					shft2 = 0;
-					//swap ^= 1;
-				} else {
-					shft1 = 0;
-					shft2 = 1;
-				}
-				while (count--) {
-					unsigned char b0 = ref[shft1];
-					unsigned char b1 = ref[shft2];
-					output[swap] = b0;
-					output[swap ^ 1] = b1;
-					output += 2;
-					ref += (mode & 4) ? -2 : 2;
-				}
-			} else {
-				input++;
-				mode = code & 0xFF; // bits 0..4 are zero
-				switch (mode) {
-				case 0:
-					*(output++) = *(input++);
-					*(output++) = *(input++);
-					break;
-				case 0x20:
-					output += 2 * *(input++);
-					break;
-				case 0x40:
-					output += 2 * (code >> 8);
-					input += 2;
-					break;
-				case 0x60:
-					count = *(input++);
-					color = *(input++);
-					while (count--) {
-						*(output++) = color;
-						*(output++) = color;
-					}
-					break;
-				default:
-					return;
-				}
-			}
-		}
-	} else {
-		assert(0);
-		//HNM4 hires
-		for (;;) {
-			code = PLE32(input) & 0xFFFFFF;
-			input++;
-			count = code & 0x3F;
-			if (count) {
-				mode = (code >> 5) & 0xF;
-				offs = code >> 9;
-				//
-			} else {
-				mode = code & 0xFF; // bits 0..5 are zero
-				switch (mode) {
-				case 0x00:
-					output += *input++;
-					break;
-				case 0x40:
-					*output++ = *input++;
-					*(output++ + width) = *input++;
-					break;
-				case 0x80:
-					output += width;
-					break;
-				default:
-					return;
-				}
-			}
-		}
-	}
-}
-
-void CLHNM_Init() {
-	use_preload = 0;
-	custom_chunk_handler = 0;
-	preserve_color0 = 0;
-	CLNoError;
-}
-
-void CLHNM_Done() {
-	CLNoError;
-}
-
-void CLHNM_SetupTimer(float rate) {
-	hnm_rate = 100.0 / rate;
-	CLNoError;
-}
-
-void CLHNM_WaitLoop(hnm_t *hnm) {
-	expected_frame_time += hnm_rate;
-	next_frame_time = expected_frame_time - time_drift;
-	if (use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
-		use_sound = 0;
-	while (TimerTicks < next_frame_time) ;  // waste time
-	time_drift = TimerTicks - next_frame_time;
-}
-
-void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode) {
-	soundChannel = CLSoundChannel_New(mode);
-	soundGroup = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
-	if (sampleSize == 16)
-		CLSoundGroup_Reverse16All(soundGroup);
-}
-
-void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode) {
-	soundChannel_adpcm = CLSoundChannel_New(mode);
-	soundGroup_adpcm = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
-}
-
-void CLHNM_CloseSound() {
-	if (soundChannel) {
-		CLSoundChannel_Stop(soundChannel);
-		CLSoundChannel_Free(soundChannel);
-		soundChannel = 0;
-	}
-	if (soundGroup) {
-		CLSoundGroup_Free(soundGroup);
-		soundGroup = 0;
-	}
-	if (soundChannel_adpcm) {
-		CLSoundChannel_Stop(soundChannel_adpcm);
-		CLSoundChannel_Free(soundChannel_adpcm);
-		soundChannel = 0;
-	}
-	if (soundGroup_adpcm) {
-		CLSoundGroup_Free(soundGroup_adpcm);
-		soundGroup = 0;
-	}
-}
-
-void CLHNM_SetForceZero2Black(short forceblack) {
-	preserve_color0 = forceblack;
-}
-
-hnm_t *CLHNM_New(int preload_size) {
-	hnm_t *hnm;
-	short i;
-
-	preload_size = 0;   //TODO: let's ignore it for now
-
-	CLBeginCheck;
-	hnm = (hnm_t *)CLMemory_Alloc(sizeof(*hnm));
-	CLCheckError();
-	if (hnm) {
-		if (preload_size) {
-			use_preload = 1;
-
-		}
-		if (!__libError) {
-			hnm->frame = 0;
-			hnm->ff_4 = 0;
-			hnm->file = 0;
-			hnm->work_buffer[0] = 0;
-			hnm->work_buffer[1] = 0;
-			hnm->final_buffer = 0;
-			hnm->read_buffer = 0;
-			hnm->ff_896 = 0;
-			hnm->total_read = 0;
-			for (i = 0; i < 256; i++) {
-				hnm->palette[i].a = 0;
-				hnm->palette[i].r = 0;
-				hnm->palette[i].g = 0;
-				hnm->palette[i].b = 0;
-			}
-		} else
-			CLCheckError();
-	}
-	CLEndCheck;
-	return hnm;
-}
-
-void CLHNM_Dispose(hnm_t *hnm) {
-	CLBeginCheck;
-
-	if (use_preload) {
-
-	}
-
-	CLMemory_Free(hnm);
-	CLCheckError();
-
-	CLEndCheck;
-}
-
-
-void CLHNM_SetFile(hnm_t *hnm, file_t *file) {
-	hnm->file = file;
-	CLNoError;
-}
-
-void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer) {
-	hnm->final_buffer = buffer;
-	CLNoError;
-}
-
-void CLHNM_AllocMemory(hnm_t *hnm) {
-	CLBeginCheck;
-
-	hnm->work_buffer[0] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
-	CLCheckError();
-
-	if (!hnm->work_buffer[0])
-		goto fin;
-
-	hnm->work_buffer[1] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
-	CLCheckError();
-
-	if (!hnm->work_buffer[1]) {
-		CLMemory_Free(hnm->work_buffer[0]);
-		CLCheckError();
-		hnm->work_buffer[0] = 0;
-		goto fin;
-	}
-
-	if (!use_preload) {
-		hnm->read_buffer = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
-//		CLCheckError();
-		if (!hnm->read_buffer) {
-			CLMemory_Free(hnm->work_buffer[0]);
-			CLCheckError();
-			hnm->work_buffer[0] = 0;
-			CLMemory_Free(hnm->work_buffer[1]);
-			CLCheckError();
-			hnm->work_buffer[1] = 0;
-		}
-	}
-fin:
-	;
-	CLEndCheck;
-}
-
-void CLHNM_DeallocMemory(hnm_t *hnm) {
-	CLBeginCheck;
-	if (hnm->work_buffer[0]) {
-		CLMemory_Free(hnm->work_buffer[0]);
-		CLCheckError();
-		hnm->work_buffer[0] = 0;
-	}
-	if (hnm->work_buffer[1]) {
-		CLMemory_Free(hnm->work_buffer[1]);
-		CLCheckError();
-		hnm->work_buffer[1] = 0;
-	}
-
-	if (!use_preload) {
-		if (hnm->read_buffer) {
-			CLMemory_Free(hnm->read_buffer);
-			CLCheckError();
-			hnm->read_buffer = 0;
-		}
-	}
-
-	CLEndCheck;
-}
-
-void CLHNM_Read(hnm_t *hnm, int size) {
-	long _size = size;
-	if (!use_preload) {
-		CLFile_Read(*hnm->file, hnm->read_buffer, &_size);
-	} else {
-	}
-}
-
-void CLHNM_GiveTime(hnm_t *hnm) {
-	if (use_preload) {
-		//stuff preload_buffer from disk
-	}
-}
-
-void CLHNM_CanLoop(hnm_t *hnm, short can_loop) {
-	hnm->can_loop = can_loop;
-}
-
-void CLHNM_SelectBuffers(hnm_t *hnm) {
-	if (hnm->frame % 2) {
-		hnm->new_frame_buffer = hnm->work_buffer[1];
-		hnm->old_frame_buffer = hnm->work_buffer[0];
-	} else {
-		hnm->new_frame_buffer = hnm->work_buffer[0];
-		hnm->old_frame_buffer = hnm->work_buffer[1];
-	}
-}
-
-void CLHNM_ChangePalette(hnm_t *hnm) {
-	short mincolor, maxcolor;
-	unsigned short fst, cnt;
-	unsigned char *pal;
-	color_t *color;
-	CLPalette_GetLastPalette(hnm->palette);
-	pal = hnm->data_ptr;
-	if (*(unsigned short *)pal == 0xFFFF)
-		return;
-	mincolor = 255;
-	maxcolor = 0;
-	do {
-		fst = *pal++;
-		cnt = *pal++;
-		if (cnt == 0)
-			cnt = 256;
-		debug("hnm: setting palette, fst = %d, cnt = %d, last = %d", fst, cnt, fst + cnt - 1);
-		assert(fst + cnt <= 256);
-		if (mincolor > fst)
-			mincolor = fst;
-		if (maxcolor < fst + cnt)
-			maxcolor = fst + cnt;
-		color = hnm->palette + fst;
-		if (safe_palette) {
-			while (cnt--) {
-				unsigned char r = *pal++;
-				unsigned char g = *pal++;
-				unsigned char b = *pal++;
-				short rr = r << 10;
-				short gg = g << 10;
-				short bb = b << 10;
-				if (color->r != rr || color->g != gg || color->b != bb)
-					CLBlitter_OneBlackFlash();
-				color->r = rr;
-				color->g = gg;
-				color->b = bb;
-				color++;
-			}
-		} else {
-			while (cnt--) {
-				unsigned char r = *pal++;
-				unsigned char g = *pal++;
-				unsigned char b = *pal++;
-				color->r = r << 10;
-				color->g = g << 10;
-				color->b = b << 10;
-				color++;
-			}
-		}
-
-	} while (*(unsigned short *)pal != 0xFFFF);
-#if 0
-	if (preserve_color0) {
-		hnm->palette[0].r = 0;
-		hnm->palette[0].g = 0;
-		hnm->palette[0].b = 0;
-	}
-#endif
-//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);
-	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);
-}
-
-void CLHNM_Desentrelace(hnm_t *hnm) {
-	switch (hnm->header.width) {
-	case 320:
-		CLHNM_Desentrelace320(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-		CLNoError;
-		break;
-//	case 480:
-//		CLHNM_Desentrelace480(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-//		CLNoError;
-//		break;
-	default:
-		__libError = -5;
-		__osError = 0;
-		CLCheckError();
-	}
-}
-
-void CLHNM_FlushPreloadBuffer(hnm_t *hnm) {
-	if (use_preload) {
-	}
-}
-
-soundchannel_t *CLHNM_GetSoundChannel() {
-	return soundChannel;
-}
-
-
-void CLHNM_TryRead(hnm_t *hnm, int size) {
-	short err;
-	do {
-		CLHNM_Read(hnm, size);
-		err = __libError == -6;
-		if (err)
-			CLHNM_GiveTime(hnm);
-	} while (err);
-}
-
-void CLHNM_ResetInternalTimer() {
-	time_drift = 0.0;
-	next_frame_time = expected_frame_time = TimerTicks;
-}
-
-void CLHNM_Reset(hnm_t *hnm) {
-	hnm->frame = 0;
-	hnm->ff_4 = 0;
-	hnm->total_read = 0;
-	sound_started = 0;
-	pending_sounds = 0;
-	CLHNM_ResetInternalTimer();
-	CLNoError;
-}
-
-short CLHNM_LoadFrame(hnm_t *hnm) {
-	int chunk;
-	CLBeginCheck;
-	CLHNM_TryRead(hnm, 4);
-	CLEndCheck;
-	chunk = *(int *)hnm->read_buffer;
-	chunk = LE32(chunk);
-	chunk &= 0xFFFFFF;  // upper bit - keyframe mark?
-	if (!chunk)
-		return 0;
-
-	if (use_preload) {
-	} else {
-		if (chunk - 4 > hnm->header.buffersize) {
-			__libError = -3;
-			__osError = 0;
-			CLCheckError();
-		} else if (use_preload && chunk - 4 > 102400) {
-			__libError = -3;
-			__osError = 0;
-			CLCheckError();
-		}
-	}
-	CLBeginCheck;
-	CLHNM_TryRead(hnm, chunk - 4);
-	CLEndCheck;
-	hnm->data_ptr = hnm->read_buffer;
-	hnm->total_read += chunk;
-	return 1;
-}
-
-void CLHNM_WantsSound(short sound) {
-	use_sound = sound;
-}
-
-void CLHNM_LoadDecompTable(short *buffer) {
-	short i;
-	short e;
-	for (i = 0; i < 256; i++) {
-		e = *buffer++;
-		decomp_table[i] = LE16(e);
-	}
-}
-
-void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size) {
-	short l = pred_l, r = pred_r;
-	size &= ~1;
-	while (size--) {
-		*output++ = l += decomp_table[*buffer++];
-		*output++ = r += decomp_table[*buffer++];
-		if (l > 512 || r > 512)
-			DebugStr(" coucou");
-	}
-	pred_l = l;
-	pred_r = r;
-}
-
-void CLHNM_SoundInADPCM(short is_adpcm) {
-	use_adpcm = is_adpcm;
-}
-
-void CLHNM_SoundMono(short is_mono) {
-	use_mono = is_mono;
-}
-
-short CLHNM_NextElement(hnm_t *hnm) {
-	int sz;
-	short id;
-	char h6, h7;
-	short i;
-	if (hnm->frame == 0) {
-		CLHNM_ResetInternalTimer();
-		pred_l = pred_r = 0;
-	}
-	if (hnm->frame == hnm->header.nframe)
-		return 0;
-	if (!CLHNM_LoadFrame(hnm))
-		return 0;
-	for (;;) {
-		sz = PLE32(hnm->data_ptr) & 0xFFFFFF;
-		hnm->data_ptr += 4;
-		id = *(short *)hnm->data_ptr;
-		hnm->data_ptr += 2;
-		h6 = *hnm->data_ptr;
-		hnm->data_ptr += 1;
-		h7 = *hnm->data_ptr;
-		hnm->data_ptr += 1;
-		hnm->chunk_id = id;
-		switch (id) {
-		case BE16('PL'):
-			CLHNM_ChangePalette(hnm);
-			hnm->data_ptr += sz - 8;
-			break;
-		case BE16('IZ'):
-			hnm->frame++;
-			CLHNM_SelectBuffers(hnm);
-			CLHNM_DecompLempelZiv(hnm->data_ptr + 4, hnm->new_frame_buffer);
-			switch (hnm->header.width) {
-//			case 320: CLBlitter_RawCopy320ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
-//			case 480: CLBlitter_RawCopy480ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
-//			case 640: CLBlitter_RawCopy640ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
-//			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
-			default:
-				memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);  //TODO strange buffer size here
-			}
-			if (!(h6 & 1))
-				CLHNM_Desentrelace(hnm);
-			else {
-//				if(hnm->header.width == 640)
-//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-//				else
-				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);   //TODO: wrong size?
-			}
-			if (use_adpcm) {
-				if (!sound_started) {
-					for (i = 0; i < pending_sounds; i++)
-						CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
-					sound_started = 1;
-				}
-			} else {
-				if (!sound_started) {
-					for (i = 0; i < pending_sounds; i++)
-						CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
-					sound_started = 1;
-				}
-			}
-			goto end_frame;
-		case BE16('IU'):
-			hnm->frame++;
-			CLHNM_SelectBuffers(hnm);
-			CLHNM_DecompUBA(hnm->new_frame_buffer, hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->data_ptr, hnm->header.width, h6);
-			if (!(h6 & 1))
-				CLHNM_Desentrelace(hnm);
-			else {
-//				if(hnm->header.width == 640)
-//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-//				else
-				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
-			}
-			goto end_frame;
-		case BE16('sd'):
-		case BE16('SD'):
-			if (use_sound) {
-				if (!h6) {
-					int sound_size = sz - 8;
-					if (!use_adpcm) {
-						CLSoundGroup_SetDatas(soundGroup, hnm->data_ptr, sound_size - 2, 0);
-						if (sound_started)
-							CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
-						else
-							pending_sounds++;
-					} else {
-						short *sound_buffer = (short *)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
-						if (!pending_sounds) {
-							const int kDecompTableSize = 256 * sizeof(short);
-							CLHNM_LoadDecompTable((short *)hnm->data_ptr);
-							CLHNM_DecompADPCM(hnm->data_ptr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize);
-							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, 0);
-						} else {
-							CLHNM_DecompADPCM(hnm->data_ptr, sound_buffer, sound_size);
-							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, sound_size * 2, 0);
-						}
-						pending_sounds++;
-						if (sound_started)
-							CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
-					}
-				} else {
-					__libError = -3;
-					__osError = 0;
-					CLCheckError();
-				}
-			}
-			hnm->data_ptr += sz - 8;
-			break;
-		default:
-			if (custom_chunk_handler)
-				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7);
-			hnm->data_ptr += sz - 8;
-		}
-	}
-end_frame:
-	;
-	if (use_preload) {
-	}
-	return 1;
-}
-
-void CLHNM_ReadHeader(hnm_t *hnm) {
-	CLBeginCheck;
-	if (!use_preload) {
-		long size = sizeof(hnm->header);
-		CLFile_Read(*hnm->file, &hnm->header, &size);
-	} else
-		;
-	CLCheckError();
-	CLEndCheck;
-	hnm->header.width = LE16(hnm->header.width);
-	hnm->header.height = LE16(hnm->header.height);
-	hnm->header.filesize = LE32(hnm->header.filesize);
-	hnm->header.nframe = LE32(hnm->header.nframe);
-	hnm->header.table_offset = LE32(hnm->header.table_offset);
-	hnm->header.speed = LE16(hnm->header.speed);
-	hnm->header.maxbuffer = LE16(hnm->header.maxbuffer);
-	hnm->header.buffersize = LE32(hnm->header.buffersize);
-	hnm->header.ff_20 = LE16(hnm->header.ff_20);
-	hnm->header.buffersize += 4096; //TODO: checkme
-}
-
-short CLHNM_GetVersion(hnm_t *hnm) {
-	CLNoError;
-	if (hnm->header.id == BE32('HNM4'))
-		return 4;
-	return -1;
-}
-
-int CLHNM_GetFrameNum(hnm_t *hnm) {
-	return hnm->frame;
-}
-
-void CLHNM_DeactivatePreloadBuffer() {
-	use_preload = 0;
-}
-
-void CLHNM_Prepare2Read(hnm_t *hnm, int mode) {
-	if (use_preload) {
-	}
-}
-
-void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos) {
-	CLFile_SetPosition(*hnm->file, 1, pos);
-}
-
-void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height) {
-	unsigned int *input = (unsigned int *)frame_buffer;
-	unsigned int *line0 = (unsigned int *)final_buffer;
-	unsigned int *line1 = (unsigned int *)(final_buffer + 320);
-	int count = (height) / 2;
-	while (count--) {
-		short i;
-		for (i = 0; i < 320 / 4; i++) {
-			unsigned int p0 = *input++;
-			unsigned int p4 = *input++;
-#if 0
-			*line0++ = ((p4 & 0xFF00) >> 8) | ((p4 & 0xFF000000) >> 16) | ((p0 & 0xFF00) << 8) | (p0 & 0xFF000000);
-//			*line0++ = (p0 & 0xFF000000) | ((p0 & 0xFF00) << 8) | ((p4 & 0xFF000000) >> 16) | ((p4 & 0xFF00) >> 8);
-			*line1++ = ((p0 & 0xFF0000) << 8) | ((p0 & 0xFF) << 16) | ((p4 & 0xFF0000) >> 8) | (p4 & 0xFF);
-#else
-			*line0++ = (p0 & 0xFF) | ((p0 & 0xFF0000) >> 8) | ((p4 & 0xFF) << 16) | ((p4 & 0xFF0000) << 8);
-			*line1++ = ((p0 & 0xFF00) >> 8) | ((p0 & 0xFF000000) >> 16) | ((p4 & 0xFF00) << 8) | (p4 & 0xFF000000);
-#endif
-		}
-		line0 += 320 / 4;
-		line1 += 320 / 4;
-	}
-}
+#include "cryolib.h"
+
+static short safe_palette = 0;
+static short pred_r = 0, pred_l = 0;
+static short use_adpcm = 0;
+static float hnm_rate = 0.0;
+static float next_frame_time = 0.0;
+static float expected_frame_time = 0.0;
+static float time_drift = 0.0;
+static short use_mono = 0;
+static short use_sound = 0;
+static short use_sound_sync = 0;
+static short pending_sounds = 0;
+static short sound_started = 0;
+static short preserve_color0 = 0;
+static soundchannel_t *soundChannel_adpcm = 0;
+static soundgroup_t *soundGroup_adpcm = 0;
+static soundchannel_t *soundChannel = 0;
+static soundgroup_t *soundGroup = 0;
+static void (*custom_chunk_handler)(unsigned char *buffer, int size, short id, char h6, char h7) = 0;
+static short use_preload = 0;
+static short decomp_table[256];
+
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
+
+void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output) {
+	unsigned char *inp = buffer;
+	unsigned char *out = output;
+
+	unsigned int queue = 0;
+	int qpos = -1;
+
+	//TODO: fix for BE
+#define GetBit() ( 1 & ( (qpos >= 0) ? (queue >> qpos--) : (queue = *(unsigned int*)((inp += 4) - 4)) >> ((qpos = 30) + 1) ) )
+
+	for (;;) {
+		if (GetBit()) {
+			*out++ = *inp++;
+		} else {
+			int l, o;
+			if (GetBit()) {
+				l = *inp & 7;
+				o = *(unsigned short *)inp >> 3;
+				inp += 2;
+				o -= 8192;
+				if (!l)
+					l = *inp++;
+				if (!l)
+					break;
+			} else {
+				l = GetBit() * 2 + GetBit();
+				o = *(inp++) - 256;
+			}
+			l += 2;
+			while (l--) {
+				*out = *(out + o);
+				out++;
+			}
+		}
+	}
+
+#undef GetBit
+
+	return;
+}
+
+void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
+                     unsigned char *input, int width, char flags) {
+	unsigned int code;
+	char mode, count, color;
+	unsigned short offs;
+	unsigned char *ref;
+	unsigned char *out_start = output;
+	unsigned char swap;
+	int shft1, shft2;
+//	return;
+	if ((flags & 1) == 0) {
+		//HNM4 classic
+		int twolinesabove = -(width * 2);
+		for (;;) {
+			code = PLE32(input) & 0xFFFFFF; //input++;
+			count = code & 0x1F;
+			if (count) {
+				input += 3;
+				mode = (code >> 5) & 0xF;
+				offs = code >> 9;
+				//
+				swap = mode >> 3;
+				ref = ((mode & 1) ? prev_buffer : curr_buffer) + (output - out_start) + (offs * 2) - 32768;
+				if (mode & 2) {
+					//                  ref += twolinesabove;
+					shft1 = twolinesabove + 1;
+					shft2 = 0;
+					//swap ^= 1;
+				} else {
+					shft1 = 0;
+					shft2 = 1;
+				}
+				while (count--) {
+					unsigned char b0 = ref[shft1];
+					unsigned char b1 = ref[shft2];
+					output[swap] = b0;
+					output[swap ^ 1] = b1;
+					output += 2;
+					ref += (mode & 4) ? -2 : 2;
+				}
+			} else {
+				input++;
+				mode = code & 0xFF; // bits 0..4 are zero
+				switch (mode) {
+				case 0:
+					*(output++) = *(input++);
+					*(output++) = *(input++);
+					break;
+				case 0x20:
+					output += 2 * *(input++);
+					break;
+				case 0x40:
+					output += 2 * (code >> 8);
+					input += 2;
+					break;
+				case 0x60:
+					count = *(input++);
+					color = *(input++);
+					while (count--) {
+						*(output++) = color;
+						*(output++) = color;
+					}
+					break;
+				default:
+					return;
+				}
+			}
+		}
+	} else {
+		assert(0);
+		//HNM4 hires
+		for (;;) {
+			code = PLE32(input) & 0xFFFFFF;
+			input++;
+			count = code & 0x3F;
+			if (count) {
+				mode = (code >> 5) & 0xF;
+				offs = code >> 9;
+				//
+			} else {
+				mode = code & 0xFF; // bits 0..5 are zero
+				switch (mode) {
+				case 0x00:
+					output += *input++;
+					break;
+				case 0x40:
+					*output++ = *input++;
+					*(output++ + width) = *input++;
+					break;
+				case 0x80:
+					output += width;
+					break;
+				default:
+					return;
+				}
+			}
+		}
+	}
+}
+
+void CLHNM_Init() {
+	use_preload = 0;
+	custom_chunk_handler = 0;
+	preserve_color0 = 0;
+	CLNoError;
+}
+
+void CLHNM_Done() {
+	CLNoError;
+}
+
+void CLHNM_SetupTimer(float rate) {
+	hnm_rate = 100.0 / rate;
+	CLNoError;
+}
+
+void CLHNM_WaitLoop(hnm_t *hnm) {
+	expected_frame_time += hnm_rate;
+	next_frame_time = expected_frame_time - time_drift;
+	if (use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
+		use_sound = 0;
+	while (TimerTicks < next_frame_time) ;  // waste time
+	time_drift = TimerTicks - next_frame_time;
+}
+
+void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode) {
+	soundChannel = CLSoundChannel_New(mode);
+	soundGroup = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
+	if (sampleSize == 16)
+		CLSoundGroup_Reverse16All(soundGroup);
+}
+
+void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode) {
+	soundChannel_adpcm = CLSoundChannel_New(mode);
+	soundGroup_adpcm = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
+}
+
+void CLHNM_CloseSound() {
+	if (soundChannel) {
+		CLSoundChannel_Stop(soundChannel);
+		CLSoundChannel_Free(soundChannel);
+		soundChannel = 0;
+	}
+	if (soundGroup) {
+		CLSoundGroup_Free(soundGroup);
+		soundGroup = 0;
+	}
+	if (soundChannel_adpcm) {
+		CLSoundChannel_Stop(soundChannel_adpcm);
+		CLSoundChannel_Free(soundChannel_adpcm);
+		soundChannel = 0;
+	}
+	if (soundGroup_adpcm) {
+		CLSoundGroup_Free(soundGroup_adpcm);
+		soundGroup = 0;
+	}
+}
+
+void CLHNM_SetForceZero2Black(short forceblack) {
+	preserve_color0 = forceblack;
+}
+
+hnm_t *CLHNM_New(int preload_size) {
+	hnm_t *hnm;
+	short i;
+
+	preload_size = 0;   //TODO: let's ignore it for now
+
+	CLBeginCheck;
+	hnm = (hnm_t *)CLMemory_Alloc(sizeof(*hnm));
+	CLCheckError();
+	if (hnm) {
+		if (preload_size) {
+			use_preload = 1;
+
+		}
+		if (!__libError) {
+			hnm->frame = 0;
+			hnm->ff_4 = 0;
+			hnm->file = 0;
+			hnm->work_buffer[0] = 0;
+			hnm->work_buffer[1] = 0;
+			hnm->final_buffer = 0;
+			hnm->read_buffer = 0;
+			hnm->ff_896 = 0;
+			hnm->total_read = 0;
+			for (i = 0; i < 256; i++) {
+				hnm->palette[i].a = 0;
+				hnm->palette[i].r = 0;
+				hnm->palette[i].g = 0;
+				hnm->palette[i].b = 0;
+			}
+		} else
+			CLCheckError();
+	}
+	CLEndCheck;
+	return hnm;
+}
+
+void CLHNM_Dispose(hnm_t *hnm) {
+	CLBeginCheck;
+
+	if (use_preload) {
+
+	}
+
+	CLMemory_Free(hnm);
+	CLCheckError();
+
+	CLEndCheck;
+}
+
+
+void CLHNM_SetFile(hnm_t *hnm, file_t *file) {
+	hnm->file = file;
+	CLNoError;
+}
+
+void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer) {
+	hnm->final_buffer = buffer;
+	CLNoError;
+}
+
+void CLHNM_AllocMemory(hnm_t *hnm) {
+	CLBeginCheck;
+
+	hnm->work_buffer[0] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
+	CLCheckError();
+
+	if (!hnm->work_buffer[0])
+		goto fin;
+
+	hnm->work_buffer[1] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
+	CLCheckError();
+
+	if (!hnm->work_buffer[1]) {
+		CLMemory_Free(hnm->work_buffer[0]);
+		CLCheckError();
+		hnm->work_buffer[0] = 0;
+		goto fin;
+	}
+
+	if (!use_preload) {
+		hnm->read_buffer = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
+//		CLCheckError();
+		if (!hnm->read_buffer) {
+			CLMemory_Free(hnm->work_buffer[0]);
+			CLCheckError();
+			hnm->work_buffer[0] = 0;
+			CLMemory_Free(hnm->work_buffer[1]);
+			CLCheckError();
+			hnm->work_buffer[1] = 0;
+		}
+	}
+fin:
+	;
+	CLEndCheck;
+}
+
+void CLHNM_DeallocMemory(hnm_t *hnm) {
+	CLBeginCheck;
+	if (hnm->work_buffer[0]) {
+		CLMemory_Free(hnm->work_buffer[0]);
+		CLCheckError();
+		hnm->work_buffer[0] = 0;
+	}
+	if (hnm->work_buffer[1]) {
+		CLMemory_Free(hnm->work_buffer[1]);
+		CLCheckError();
+		hnm->work_buffer[1] = 0;
+	}
+
+	if (!use_preload) {
+		if (hnm->read_buffer) {
+			CLMemory_Free(hnm->read_buffer);
+			CLCheckError();
+			hnm->read_buffer = 0;
+		}
+	}
+
+	CLEndCheck;
+}
+
+void CLHNM_Read(hnm_t *hnm, int size) {
+	long _size = size;
+	if (!use_preload) {
+		CLFile_Read(*hnm->file, hnm->read_buffer, &_size);
+	} else {
+	}
+}
+
+void CLHNM_GiveTime(hnm_t *hnm) {
+	if (use_preload) {
+		//stuff preload_buffer from disk
+	}
+}
+
+void CLHNM_CanLoop(hnm_t *hnm, short can_loop) {
+	hnm->can_loop = can_loop;
+}
+
+void CLHNM_SelectBuffers(hnm_t *hnm) {
+	if (hnm->frame % 2) {
+		hnm->new_frame_buffer = hnm->work_buffer[1];
+		hnm->old_frame_buffer = hnm->work_buffer[0];
+	} else {
+		hnm->new_frame_buffer = hnm->work_buffer[0];
+		hnm->old_frame_buffer = hnm->work_buffer[1];
+	}
+}
+
+void CLHNM_ChangePalette(hnm_t *hnm) {
+	short mincolor, maxcolor;
+	unsigned short fst, cnt;
+	unsigned char *pal;
+	color_t *color;
+	CLPalette_GetLastPalette(hnm->palette);
+	pal = hnm->data_ptr;
+	if (*(unsigned short *)pal == 0xFFFF)
+		return;
+	mincolor = 255;
+	maxcolor = 0;
+	do {
+		fst = *pal++;
+		cnt = *pal++;
+		if (cnt == 0)
+			cnt = 256;
+		debug("hnm: setting palette, fst = %d, cnt = %d, last = %d", fst, cnt, fst + cnt - 1);
+		assert(fst + cnt <= 256);
+		if (mincolor > fst)
+			mincolor = fst;
+		if (maxcolor < fst + cnt)
+			maxcolor = fst + cnt;
+		color = hnm->palette + fst;
+		if (safe_palette) {
+			while (cnt--) {
+				unsigned char r = *pal++;
+				unsigned char g = *pal++;
+				unsigned char b = *pal++;
+				short rr = r << 10;
+				short gg = g << 10;
+				short bb = b << 10;
+				if (color->r != rr || color->g != gg || color->b != bb)
+					CLBlitter_OneBlackFlash();
+				color->r = rr;
+				color->g = gg;
+				color->b = bb;
+				color++;
+			}
+		} else {
+			while (cnt--) {
+				unsigned char r = *pal++;
+				unsigned char g = *pal++;
+				unsigned char b = *pal++;
+				color->r = r << 10;
+				color->g = g << 10;
+				color->b = b << 10;
+				color++;
+			}
+		}
+
+	} while (*(unsigned short *)pal != 0xFFFF);
+#if 0
+	if (preserve_color0) {
+		hnm->palette[0].r = 0;
+		hnm->palette[0].g = 0;
+		hnm->palette[0].b = 0;
+	}
+#endif
+//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);
+	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);
+}
+
+void CLHNM_Desentrelace(hnm_t *hnm) {
+	switch (hnm->header.width) {
+	case 320:
+		CLHNM_Desentrelace320(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+		CLNoError;
+		break;
+//	case 480:
+//		CLHNM_Desentrelace480(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//		CLNoError;
+//		break;
+	default:
+		__libError = -5;
+		__osError = 0;
+		CLCheckError();
+	}
+}
+
+void CLHNM_FlushPreloadBuffer(hnm_t *hnm) {
+	if (use_preload) {
+	}
+}
+
+soundchannel_t *CLHNM_GetSoundChannel() {
+	return soundChannel;
+}
+
+
+void CLHNM_TryRead(hnm_t *hnm, int size) {
+	short err;
+	do {
+		CLHNM_Read(hnm, size);
+		err = __libError == -6;
+		if (err)
+			CLHNM_GiveTime(hnm);
+	} while (err);
+}
+
+void CLHNM_ResetInternalTimer() {
+	time_drift = 0.0;
+	next_frame_time = expected_frame_time = TimerTicks;
+}
+
+void CLHNM_Reset(hnm_t *hnm) {
+	hnm->frame = 0;
+	hnm->ff_4 = 0;
+	hnm->total_read = 0;
+	sound_started = 0;
+	pending_sounds = 0;
+	CLHNM_ResetInternalTimer();
+	CLNoError;
+}
+
+short CLHNM_LoadFrame(hnm_t *hnm) {
+	int chunk;
+	CLBeginCheck;
+	CLHNM_TryRead(hnm, 4);
+	CLEndCheck;
+	chunk = *(int *)hnm->read_buffer;
+	chunk = LE32(chunk);
+	chunk &= 0xFFFFFF;  // upper bit - keyframe mark?
+	if (!chunk)
+		return 0;
+
+	if (use_preload) {
+	} else {
+		if (chunk - 4 > hnm->header.buffersize) {
+			__libError = -3;
+			__osError = 0;
+			CLCheckError();
+		} else if (use_preload && chunk - 4 > 102400) {
+			__libError = -3;
+			__osError = 0;
+			CLCheckError();
+		}
+	}
+	CLBeginCheck;
+	CLHNM_TryRead(hnm, chunk - 4);
+	CLEndCheck;
+	hnm->data_ptr = hnm->read_buffer;
+	hnm->total_read += chunk;
+	return 1;
+}
+
+void CLHNM_WantsSound(short sound) {
+	use_sound = sound;
+}
+
+void CLHNM_LoadDecompTable(short *buffer) {
+	short i;
+	short e;
+	for (i = 0; i < 256; i++) {
+		e = *buffer++;
+		decomp_table[i] = LE16(e);
+	}
+}
+
+void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size) {
+	short l = pred_l, r = pred_r;
+	size &= ~1;
+	while (size--) {
+		*output++ = l += decomp_table[*buffer++];
+		*output++ = r += decomp_table[*buffer++];
+		if (l > 512 || r > 512)
+			DebugStr(" coucou");
+	}
+	pred_l = l;
+	pred_r = r;
+}
+
+void CLHNM_SoundInADPCM(short is_adpcm) {
+	use_adpcm = is_adpcm;
+}
+
+void CLHNM_SoundMono(short is_mono) {
+	use_mono = is_mono;
+}
+
+short CLHNM_NextElement(hnm_t *hnm) {
+	int sz;
+	short id;
+	char h6, h7;
+	short i;
+	if (hnm->frame == 0) {
+		CLHNM_ResetInternalTimer();
+		pred_l = pred_r = 0;
+	}
+	if (hnm->frame == hnm->header.nframe)
+		return 0;
+	if (!CLHNM_LoadFrame(hnm))
+		return 0;
+	for (;;) {
+		sz = PLE32(hnm->data_ptr) & 0xFFFFFF;
+		hnm->data_ptr += 4;
+		id = *(short *)hnm->data_ptr;
+		hnm->data_ptr += 2;
+		h6 = *hnm->data_ptr;
+		hnm->data_ptr += 1;
+		h7 = *hnm->data_ptr;
+		hnm->data_ptr += 1;
+		hnm->chunk_id = id;
+		switch (id) {
+		case BE16('PL'):
+			CLHNM_ChangePalette(hnm);
+			hnm->data_ptr += sz - 8;
+			break;
+		case BE16('IZ'):
+			hnm->frame++;
+			CLHNM_SelectBuffers(hnm);
+			CLHNM_DecompLempelZiv(hnm->data_ptr + 4, hnm->new_frame_buffer);
+			switch (hnm->header.width) {
+//			case 320: CLBlitter_RawCopy320ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			case 480: CLBlitter_RawCopy480ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			case 640: CLBlitter_RawCopy640ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+			default:
+				memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);  //TODO strange buffer size here
+			}
+			if (!(h6 & 1))
+				CLHNM_Desentrelace(hnm);
+			else {
+//				if(hnm->header.width == 640)
+//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//				else
+				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);   //TODO: wrong size?
+			}
+			if (use_adpcm) {
+				if (!sound_started) {
+					for (i = 0; i < pending_sounds; i++)
+						CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
+					sound_started = 1;
+				}
+			} else {
+				if (!sound_started) {
+					for (i = 0; i < pending_sounds; i++)
+						CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
+					sound_started = 1;
+				}
+			}
+			goto end_frame;
+		case BE16('IU'):
+			hnm->frame++;
+			CLHNM_SelectBuffers(hnm);
+			CLHNM_DecompUBA(hnm->new_frame_buffer, hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->data_ptr, hnm->header.width, h6);
+			if (!(h6 & 1))
+				CLHNM_Desentrelace(hnm);
+			else {
+//				if(hnm->header.width == 640)
+//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//				else
+				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+			}
+			goto end_frame;
+		case BE16('sd'):
+		case BE16('SD'):
+			if (use_sound) {
+				if (!h6) {
+					int sound_size = sz - 8;
+					if (!use_adpcm) {
+						CLSoundGroup_SetDatas(soundGroup, hnm->data_ptr, sound_size - 2, 0);
+						if (sound_started)
+							CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
+						else
+							pending_sounds++;
+					} else {
+						short *sound_buffer = (short *)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
+						if (!pending_sounds) {
+							const int kDecompTableSize = 256 * sizeof(short);
+							CLHNM_LoadDecompTable((short *)hnm->data_ptr);
+							CLHNM_DecompADPCM(hnm->data_ptr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize);
+							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, 0);
+						} else {
+							CLHNM_DecompADPCM(hnm->data_ptr, sound_buffer, sound_size);
+							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, sound_size * 2, 0);
+						}
+						pending_sounds++;
+						if (sound_started)
+							CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
+					}
+				} else {
+					__libError = -3;
+					__osError = 0;
+					CLCheckError();
+				}
+			}
+			hnm->data_ptr += sz - 8;
+			break;
+		default:
+			if (custom_chunk_handler)
+				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7);
+			hnm->data_ptr += sz - 8;
+		}
+	}
+end_frame:
+	;
+	if (use_preload) {
+	}
+	return 1;
+}
+
+void CLHNM_ReadHeader(hnm_t *hnm) {
+	CLBeginCheck;
+	if (!use_preload) {
+		long size = sizeof(hnm->header);
+		CLFile_Read(*hnm->file, &hnm->header, &size);
+	} else
+		;
+	CLCheckError();
+	CLEndCheck;
+	hnm->header.width = LE16(hnm->header.width);
+	hnm->header.height = LE16(hnm->header.height);
+	hnm->header.filesize = LE32(hnm->header.filesize);
+	hnm->header.nframe = LE32(hnm->header.nframe);
+	hnm->header.table_offset = LE32(hnm->header.table_offset);
+	hnm->header.speed = LE16(hnm->header.speed);
+	hnm->header.maxbuffer = LE16(hnm->header.maxbuffer);
+	hnm->header.buffersize = LE32(hnm->header.buffersize);
+	hnm->header.ff_20 = LE16(hnm->header.ff_20);
+	hnm->header.buffersize += 4096; //TODO: checkme
+}
+
+short CLHNM_GetVersion(hnm_t *hnm) {
+	CLNoError;
+	if (hnm->header.id == BE32('HNM4'))
+		return 4;
+	return -1;
+}
+
+int CLHNM_GetFrameNum(hnm_t *hnm) {
+	return hnm->frame;
+}
+
+void CLHNM_DeactivatePreloadBuffer() {
+	use_preload = 0;
+}
+
+void CLHNM_Prepare2Read(hnm_t *hnm, int mode) {
+	if (use_preload) {
+	}
+}
+
+void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos) {
+	CLFile_SetPosition(*hnm->file, 1, pos);
+}
+
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height) {
+	unsigned int *input = (unsigned int *)frame_buffer;
+	unsigned int *line0 = (unsigned int *)final_buffer;
+	unsigned int *line1 = (unsigned int *)(final_buffer + 320);
+	int count = (height) / 2;
+	while (count--) {
+		short i;
+		for (i = 0; i < 320 / 4; i++) {
+			unsigned int p0 = *input++;
+			unsigned int p4 = *input++;
+#if 0
+			*line0++ = ((p4 & 0xFF00) >> 8) | ((p4 & 0xFF000000) >> 16) | ((p0 & 0xFF00) << 8) | (p0 & 0xFF000000);
+//			*line0++ = (p0 & 0xFF000000) | ((p0 & 0xFF00) << 8) | ((p4 & 0xFF000000) >> 16) | ((p4 & 0xFF00) >> 8);
+			*line1++ = ((p0 & 0xFF0000) << 8) | ((p0 & 0xFF) << 16) | ((p4 & 0xFF0000) >> 8) | (p4 & 0xFF);
+#else
+			*line0++ = (p0 & 0xFF) | ((p0 & 0xFF0000) >> 8) | ((p4 & 0xFF) << 16) | ((p4 & 0xFF0000) << 8);
+			*line1++ = ((p0 & 0xFF00) >> 8) | ((p0 & 0xFF000000) >> 16) | ((p4 & 0xFF00) << 8) | (p4 & 0xFF000000);
+#endif
+		}
+		line0 += 320 / 4;
+		line1 += 320 / 4;
+	}
+}
diff --git a/engines/cryo/CLSouNdRaw.c b/engines/cryo/CLSouNdRaw.c
index c29ca93..0294dfe 100644
--- a/engines/cryo/CLSouNdRaw.c
+++ b/engines/cryo/CLSouNdRaw.c
@@ -1,51 +1,51 @@
-#include "cryolib.h"
-
-sound_t *CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode) {
-	sound_t *sound;
-	CLBeginCheck;
-
-	sound = (sound_t *)CLMemory_Alloc(sizeof(*sound));
-	if (sound) {
-		sound->ff_1A = arg1;
-		sound->rate = rate;
-		sound->sampleSize = sampleSize;
-		sound->buffer = 0;
-//		sound->sndHandle = CLMemory_AllocHandle(arg1 + 100);
-//		if(!sound->sndHandle)
-//		{
-//			__libError = -1;
-//			__osError = MemError();
-//			CLCheckError();
-//		}
-//		else
-		{
-			CLSound_PrepareSample(sound, mode);
-			CLNoError;
-		}
-	} else {
-		__libError = -1;
-		__osError = MemError();
-		CLCheckError();
-	}
-
-	CLEndCheck;
-	return sound;
-}
-
-void CLSoundRaw_Free(sound_t *sound) {
-	while (sound->locked) ;
-//	CLMemory_FreeHandle(sound->sndHandle);
-	CLMemory_Free(sound);
-}
-
-void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
-	char *buf;
-	CLSound_SetLength(sound, length);
-	sound->length = length;
-	buf = bufferOffs + (char *)buffer;
-//	if(CLSound_GetWantsDesigned())
-//		CLSound_Signed2NonSigned(buf, length);
-	sound->buffer = buf;
-//	if(sound->reversed && sound->sampleSize == 16)
-//		ReverseBlock16(buf, length);
-}
+#include "cryolib.h"
+
+sound_t *CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode) {
+	sound_t *sound;
+	CLBeginCheck;
+
+	sound = (sound_t *)CLMemory_Alloc(sizeof(*sound));
+	if (sound) {
+		sound->ff_1A = arg1;
+		sound->rate = rate;
+		sound->sampleSize = sampleSize;
+		sound->buffer = 0;
+//		sound->sndHandle = CLMemory_AllocHandle(arg1 + 100);
+//		if(!sound->sndHandle)
+//		{
+//			__libError = -1;
+//			__osError = MemError();
+//			CLCheckError();
+//		}
+//		else
+		{
+			CLSound_PrepareSample(sound, mode);
+			CLNoError;
+		}
+	} else {
+		__libError = -1;
+		__osError = MemError();
+		CLCheckError();
+	}
+
+	CLEndCheck;
+	return sound;
+}
+
+void CLSoundRaw_Free(sound_t *sound) {
+	while (sound->locked) ;
+//	CLMemory_FreeHandle(sound->sndHandle);
+	CLMemory_Free(sound);
+}
+
+void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
+	char *buf;
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+	buf = bufferOffs + (char *)buffer;
+//	if(CLSound_GetWantsDesigned())
+//		CLSound_Signed2NonSigned(buf, length);
+	sound->buffer = buf;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buf, length);
+}
diff --git a/engines/cryo/CryoLib.h b/engines/cryo/CryoLib.h
index 5825a13..628ba29 100644
--- a/engines/cryo/CryoLib.h
+++ b/engines/cryo/CryoLib.h
@@ -1,181 +1,181 @@
-#pragma once
-#define SW16(n) ( (((n) & 0xFF) << 8) | (((n) >> 8) & 0xFF) )
-#define SW32(n) ( (((n) & 0xFF) << 24) | (((n) >> 24) & 0xFF) | (((n) & 0xFF00) << 8) | (((n) >> 8) & 0xFF00))
-#if 0
-//big-endian host
-#define LE16(n) SW16(n)
-#define LE32(n) SW32(n)
-#define BE16(n) (n)
-#define BE32(n) (n)
-#else
-//little-endian host
-#define LE16(n) (n)
-#define LE32(n) (n)
-#define BE16(n) SW16(n)
-#define BE32(n) SW32(n)
-#endif
-#define PLE16(p) ( (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
-#define PLE32(p) ( (((unsigned char*)(p))[3] << 24) | (((unsigned char*)(p))[2] << 16) | (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
-
-#include "audio/mixer.h"
-
-typedef void *SndChannel;
-typedef char *Handle;
-enum {
-	fsFromStart = 1
-};
-
-extern short __debug2;
-
-extern short __debug, __libError, __osError;
-
-#define CLBeginCheck    { short __oldDebug = __debug; __debug = -1;
-#define CLEndCheck      __debug = __oldDebug; }
-#define CLNoError       __libError = 0;
-
-#define CLCheckError() if(__debug && __libError){   \
-		char buffer[260];           \
-		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
-		DebugStr(c2pstr(buffer));   \
-	};
-
-#define CLAssert(x) if(!(x)) {  \
-		char buffer[260];           \
-		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
-		DebugStr(c2pstr(buffer));   \
-	};
-
-struct rect_t {
-	int sy, sx, ey, ex;
-};
-typedef struct rect_t rect_t;
-
-struct view_t {
-	unsigned char   *p_buffer;
-	int     width;
-	int     height;
-	short   pitch;
-	short   doubled;
-	short   allocated;
-	struct {
-		int     src_left;
-		int     src_top;
-		int     dst_left;
-		int     dst_top;
-		int     width;
-		int     height;
-	} norm, zoom;
-};
-typedef struct view_t view_t;
-
-struct color3_t {
-	short   r, g, b;
-};
-typedef struct color3_t color3_t;
-
-struct color_t {
-	short   a, r, g, b;
-};
-typedef struct color_t color_t;
-
-struct palette_t {
-	color_t colors[256];
-};
-typedef struct palette_t palette_t;
-
-#pragma pack(push, 1)
-struct hnmheader_t {
-	int             id;
-	char            flag1;
-	char            flag2;
-	char            reseverd;
-	char            bpp;
-	unsigned short  width;
-	unsigned short  height;
-	int             filesize;
-	int             nframe;
-	int             table_offset;
-	short           speed;
-	short           maxbuffer;
-	int             buffersize;
-	short           ff_20;
-	char            reserved2[14];
-	char            copyright[16];
-};
-typedef struct hnmheader_t hnmheader_t;
-#pragma pack(pop)
-
-struct hnm_t {
-	int             frame;
-	int             ff_4;
-	file_t         *file;
-	hnmheader_t     header;
-	unsigned char   *work_buffer[2];
-	unsigned char   *final_buffer;
-	unsigned char   *new_frame_buffer;
-	unsigned char   *old_frame_buffer;
-	unsigned char   *read_buffer;
-	unsigned char   *data_ptr;
-	color_t         palette[256];
-
-	short           can_loop;
-
-	short           ff_896;
-	short           chunk_id;
-	int             total_read;
-};
-typedef struct hnm_t hnm_t;
-
-//struct filespec_t {
-//char  puff;
-//};
-
-struct sound_t {
-	Handle  sndHandle;
-	short   headerLen;
-	long    headerOffset;
-	short   ff_A;
-
-	char    *buffer;
-	int     ff_16;
-	short   ff_1A;
-	float   rate;
-	short   sampleSize;
-	int     length;
-	short   mode;
-	volatile short  locked;
-	long    loopStart;
-	short   loopTimes;
-	short   reversed;
-	short   ff_32;
-	short   volume;
-};
-typedef struct sound_t sound_t;
-
-#define CL_MAX_SOUNDS 64
-
-struct soundgroup_t {
-	sound_t *sound[CL_MAX_SOUNDS];
-	short   numSounds;
-	short   soundIndex;
-	short   playIndex;
-	short   ff_106;
-};
-typedef struct soundgroup_t soundgroup_t;
-
-#define CL_MAX_CH_SOUNDS 10
-
-struct soundchannel_t {
-	Audio::SoundHandle ch;
-	int     xx;
-
-	short   volumeLeft;
-	short   volumeRight;
-	short   numSounds;
-
-	sound_t *sounds[CL_MAX_CH_SOUNDS];
-
-	short   ff_536;
-};
-typedef struct soundchannel_t soundchannel_t;
-
+#pragma once
+#define SW16(n) ( (((n) & 0xFF) << 8) | (((n) >> 8) & 0xFF) )
+#define SW32(n) ( (((n) & 0xFF) << 24) | (((n) >> 24) & 0xFF) | (((n) & 0xFF00) << 8) | (((n) >> 8) & 0xFF00))
+#if 0
+//big-endian host
+#define LE16(n) SW16(n)
+#define LE32(n) SW32(n)
+#define BE16(n) (n)
+#define BE32(n) (n)
+#else
+//little-endian host
+#define LE16(n) (n)
+#define LE32(n) (n)
+#define BE16(n) SW16(n)
+#define BE32(n) SW32(n)
+#endif
+#define PLE16(p) ( (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
+#define PLE32(p) ( (((unsigned char*)(p))[3] << 24) | (((unsigned char*)(p))[2] << 16) | (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
+
+#include "audio/mixer.h"
+
+typedef void *SndChannel;
+typedef char *Handle;
+enum {
+	fsFromStart = 1
+};
+
+extern short __debug2;
+
+extern short __debug, __libError, __osError;
+
+#define CLBeginCheck    { short __oldDebug = __debug; __debug = -1;
+#define CLEndCheck      __debug = __oldDebug; }
+#define CLNoError       __libError = 0;
+
+#define CLCheckError() if(__debug && __libError){   \
+		char buffer[260];           \
+		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer));   \
+	};
+
+#define CLAssert(x) if(!(x)) {  \
+		char buffer[260];           \
+		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer));   \
+	};
+
+struct rect_t {
+	int sy, sx, ey, ex;
+};
+typedef struct rect_t rect_t;
+
+struct view_t {
+	unsigned char   *p_buffer;
+	int     width;
+	int     height;
+	short   pitch;
+	short   doubled;
+	short   allocated;
+	struct {
+		int     src_left;
+		int     src_top;
+		int     dst_left;
+		int     dst_top;
+		int     width;
+		int     height;
+	} norm, zoom;
+};
+typedef struct view_t view_t;
+
+struct color3_t {
+	short   r, g, b;
+};
+typedef struct color3_t color3_t;
+
+struct color_t {
+	short   a, r, g, b;
+};
+typedef struct color_t color_t;
+
+struct palette_t {
+	color_t colors[256];
+};
+typedef struct palette_t palette_t;
+
+#pragma pack(push, 1)
+struct hnmheader_t {
+	int             id;
+	char            flag1;
+	char            flag2;
+	char            reseverd;
+	char            bpp;
+	unsigned short  width;
+	unsigned short  height;
+	int             filesize;
+	int             nframe;
+	int             table_offset;
+	short           speed;
+	short           maxbuffer;
+	int             buffersize;
+	short           ff_20;
+	char            reserved2[14];
+	char            copyright[16];
+};
+typedef struct hnmheader_t hnmheader_t;
+#pragma pack(pop)
+
+struct hnm_t {
+	int             frame;
+	int             ff_4;
+	file_t         *file;
+	hnmheader_t     header;
+	unsigned char   *work_buffer[2];
+	unsigned char   *final_buffer;
+	unsigned char   *new_frame_buffer;
+	unsigned char   *old_frame_buffer;
+	unsigned char   *read_buffer;
+	unsigned char   *data_ptr;
+	color_t         palette[256];
+
+	short           can_loop;
+
+	short           ff_896;
+	short           chunk_id;
+	int             total_read;
+};
+typedef struct hnm_t hnm_t;
+
+//struct filespec_t {
+//char  puff;
+//};
+
+struct sound_t {
+	Handle  sndHandle;
+	short   headerLen;
+	long    headerOffset;
+	short   ff_A;
+
+	char    *buffer;
+	int     ff_16;
+	short   ff_1A;
+	float   rate;
+	short   sampleSize;
+	int     length;
+	short   mode;
+	volatile short  locked;
+	long    loopStart;
+	short   loopTimes;
+	short   reversed;
+	short   ff_32;
+	short   volume;
+};
+typedef struct sound_t sound_t;
+
+#define CL_MAX_SOUNDS 64
+
+struct soundgroup_t {
+	sound_t *sound[CL_MAX_SOUNDS];
+	short   numSounds;
+	short   soundIndex;
+	short   playIndex;
+	short   ff_106;
+};
+typedef struct soundgroup_t soundgroup_t;
+
+#define CL_MAX_CH_SOUNDS 10
+
+struct soundchannel_t {
+	Audio::SoundHandle ch;
+	int     xx;
+
+	short   volumeLeft;
+	short   volumeRight;
+	short   numSounds;
+
+	sound_t *sounds[CL_MAX_CH_SOUNDS];
+
+	short   ff_536;
+};
+typedef struct soundchannel_t soundchannel_t;
+
diff --git a/engines/cryo/CryoLibStub.c b/engines/cryo/CryoLibStub.c
index e79ac64..ae6e48b 100644
--- a/engines/cryo/CryoLibStub.c
+++ b/engines/cryo/CryoLibStub.c
@@ -1,504 +1,504 @@
-
-///// Mac APIs
-typedef short OSErr;
-
-short MemError() {
-	return 0;
-}
-
-void SysBeep(int x) {
-}
-
-OSErr SetFPos(short handle, short mode, long pos) {
-	return 0;
-}
-
-OSErr FSRead(short handle, long *size, void *buffer) {
-	return 0;
-}
-
-void FlushEvents(short arg1, short arg2) {
-}
-
-char *c2pstr(char *s) {
-	return s;
-}
-
-void DebugStr(char *s) {
-}
-
-// from mw lib???
-long TickCount() {
-	return g_system->getMillis();
-}
-
-///// CLMemory
-void *CLMemory_Alloc(int size) {
-	return malloc(size);
-}
-void CLMemory_Free(void *ptr) {
-	//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
-	if (!ptr)
-		return;
-
-	free(ptr);
-}
-
-
-///// CLTimer
-volatile long TimerTicks = 0;   // incremented in realtime
-
-///// CLView
-void CLView_SetSrcZoomValues(view_t *view, int x, int y) {
-	view->zoom.src_left = x;
-	view->zoom.src_top = y;
-}
-void CLView_SetDisplayZoomValues(view_t *view, int w, int h) {
-	view->zoom.width = w;
-	view->zoom.height = h;
-}
-void CLView_Free(view_t *view) {
-	if (view->p_buffer && view->allocated)
-		CLMemory_Free(view->p_buffer);
-	if (view)
-		CLMemory_Free(view);
-}
-void CLView_InitDatas(view_t *view, int w, int h, void *buffer) {
-	view->p_buffer = (unsigned char *)buffer;
-	view->width = w;
-	view->height = h;
-	view->pitch = w;
-	view->doubled = 0;
-	view->norm.src_left = 0;
-	view->norm.src_top = 0;
-	view->norm.dst_left = 0;
-	view->norm.dst_top = 0;
-	view->norm.width = w;
-	view->norm.height = h;
-	view->zoom.src_left = 0;
-	view->zoom.src_top = 0;
-	view->zoom.dst_left = 0;
-	view->zoom.dst_top = 0;
-	view->zoom.width = w;
-	view->zoom.height = h;
-}
-view_t *CLView_New(int w, int h) {
-	view_t *view = (view_t *)CLMemory_Alloc(sizeof(view_t));
-	if (view) {
-		void *buffer = (unsigned char *)CLMemory_Alloc(w * h);
-		if (buffer) {
-			view->allocated = 1;
-			CLView_InitDatas(view, w, h, buffer);
-		} else {
-			CLMemory_Free(view);
-			view = 0;
-		}
-	}
-	return view;
-}
-void CLView_CenterIn(view_t *parent, view_t *child) {
-	child->norm.dst_left = (parent->width - child->norm.width) / 2;
-	child->norm.dst_top = (parent->height - child->norm.height) / 2;
-	child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
-	child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
-}
-
-///// CLScreenView
-view_t ScreenView;
-
-void CLScreenView_Init() {
-	// ScreenView is the game's target screen (a pc display)
-	// we use a dedicated surface for it, which at some point will be
-	// presented to user by System::copyRectToScreen call
-	CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
-}
-
-void CLScreenView_CenterIn(view_t *view) {
-	CLView_CenterIn(&ScreenView, view);
-}
-
-///// CLPalette
-unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
-short gMacintize = 0;
-color_t black_palette[256];
-color_t last_palette[256];
-void CLPalette_Init() {
-	short i;
-	for (i = 0; i < 256; i++)
-		black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
-}
-void CLPalette_SetLastPalette(color_t *palette, short first, short count) {
-	short i;
-	for (i = first; i < first + count; i++)
-		last_palette[i] = palette[i];
-}
-void CLPalette_GetLastPalette(color_t *palette) {
-	short i;
-	for (i = 0; i < 256; i++)
-		palette[i] = last_palette[i];
-}
-void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb) {
-	palette[index].r = rgb->r;
-	palette[index].g = rgb->g;
-	palette[index].b = rgb->b;
-	palette[index].a = 0;
-}
-void CLPalette_Macintize(short macintize) {
-	gMacintize = macintize;
-}
-void CLPalette_SetInterval(unsigned short first, unsigned short last) {
-	gIntervalFirst = first;
-	gIntervalSet = 1;
-	gIntervalLast = last;
-}
-void CLPalette_DeactivateInterval() {
-	gIntervalSet = 0;
-}
-void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count) {
-	OSErr err;
-	short i;
-	if (gMacintize) {
-		palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
-		palette[255].r = palette[255].g = palette[255].b = 0;
-	}
-	if (gIntervalSet) {
-		if (first < gIntervalFirst)
-			first = gIntervalFirst;
-		if (first + count > gIntervalLast)
-			count = gIntervalLast - first;
-	}
-
-	byte buffer[256 * 3];
-	for (i = 0; i < 256; i++) {
-		buffer[i * 3] = palette[i].r >> 8;
-		buffer[i * 3 + 1] = palette[i].g >> 8;
-		buffer[i * 3 + 2] = palette[i].b >> 8;
-	}
-
-	g_system->getPaletteManager()->setPalette(buffer, first, count);
-	g_system->updateScreen();
-
-	CLPalette_SetLastPalette(palette, first, count);
-}
-void CLPalette_BeBlack() {
-	CLPalette_Send2Screen(black_palette, 0, 256);
-}
-void CLPalette_BeSystem() {
-}
-
-///// CLBlitter
-static unsigned short newPaletteCount, newPaletteFirst;
-static color_t *pNewPalette;
-static unsigned short useNewPalette;
-
-void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2) {
-	int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
-	//  debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
-	//      rect1->sx, rect1->sy, rect1->ex, rect1->ey,
-	//      rect2->sx, rect2->sy, rect2->ex, rect2->ey,
-	//      (rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
-	assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
-	for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++) {
-		unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
-		unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
-		for (x = 0; x < w; x++)
-			*d++ = *s++;
-	}
-}
-void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count) {
-	pNewPalette = palette;
-	useNewPalette = 1;
-	newPaletteFirst = first;
-	newPaletteCount = count;
-}
-void CLBlitter_OneBlackFlash() {
-}
-void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
-                                       unsigned char *dst, short dstw, short dstp, short dsth) {
-	short x, y;
-	for (y = 0; y < srch; y++) {
-		for (x = 0; x < srcw; x++)
-			*dst++ = *src++;
-		src += srcp - srcw;
-		dst += dstp - dstw;
-	}
-}
-void CLBlitter_CopyView2ScreenCUSTOM(view_t *view) {
-	view_t *dest = &ScreenView;
-	if (!view->doubled) {
-		short srcpitch = view->pitch;
-		short dstpitch = dest->pitch;
-
-		//      this is not quite correct?
-		//      CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
-		//          dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
-
-		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
-		                                  dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
-
-	} else {
-		assert(0);
-	}
-}
-void CLBlitter_CopyView2Screen(view_t *view) {
-
-	if (useNewPalette) {
-		color_t palette[256];
-		CLPalette_GetLastPalette(palette);
-		CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
-		useNewPalette = 0;
-	}
-
-	//TODO: quick hack to force screen update
-	if (view)
-		CLBlitter_CopyView2ScreenCUSTOM(view);
-
-	g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
-	g_system->updateScreen();
-}
-void CLBlitter_UpdateScreen() {
-	CLBlitter_CopyView2Screen(nullptr);
-}
-void CLBlitter_FillView(view_t *view, unsigned int fill) {
-	short x, y;
-	unsigned char *d = view->p_buffer;
-	assert((fill & 0xFF) * 0x01010101 == fill);
-	for (y = 0; y < view->height; y++) {
-		for (x = 0; x < view->width; x++)
-			*d++ = fill;
-		d += view->pitch - view->width;
-	}
-}
-void CLBlitter_FillScreenView(unsigned int fill) {
-	CLBlitter_FillView(&ScreenView, fill);
-}
-
-
-///// events wrapper
-int _mouseButton;
-byte _keyState[256];
-
-void pollEvents() {
-	g_system->delayMillis(10);
-
-	Common::Event event;
-	while (g_system->getEventManager()->pollEvent(event)) {
-		// Handle keypress
-		switch (event.type) {
-		case Common::EVENT_QUIT:
-		case Common::EVENT_RTL:
-			return;
-
-		case Common::EVENT_KEYDOWN:
-			//          _keyState[(byte)toupper(event.kbd.ascii)] = true;
-			return;
-		case Common::EVENT_KEYUP:
-			//          _keyState[(byte)toupper(event.kbd.ascii)] = false;
-			return;
-		case Common::EVENT_LBUTTONDOWN:
-			_mouseButton = 1;
-			return;
-		case Common::EVENT_RBUTTONDOWN:
-			_mouseButton = 2;
-			return;
-		case Common::EVENT_LBUTTONUP:
-		case Common::EVENT_RBUTTONUP:
-			_mouseButton = 0;
-			return;
-		default:
-			break;
-		}
-	}
-}
-
-
-///// CLKeyboard
-short CLKeyboard_HasCmdDown() {
-	return 0;
-}
-void CLKeyboard_Read() {
-	pollEvents();
-}
-unsigned char CLKeyboard_GetLastASCII() {
-	return 0;
-}
-short CLKeyboard_IsScanCodeDown(short scancode) {
-	return 0;
-}
-
-///// CLMouse
-void CLMouse_Hide() {
-}
-void CLMouse_Show() {
-}
-void CLMouse_GetPosition(short *x, short *y) {
-	*x = g_system->getEventManager()->getMousePos().x;
-	*y = g_system->getEventManager()->getMousePos().y;
-}
-void CLMouse_SetPosition(short x, short y) {
-	g_system->warpMouse(x, y);
-}
-unsigned short CLMouse_IsDown() {
-	pollEvents();
-	return _mouseButton != 0;
-}
-
-///// CLFile
-void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7) {
-}
-void CLFile_SetFinderInfos(void *fs, int a4, int a5) {
-}
-void CLFile_GetFullPath(void *a3, char *a4) {
-}
-void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs) {
-	strcpy(fs->name, name);
-	fs->create = 0;
-}
-void CLFile_Create(filespec_t *fs) {
-	fs->create = 1;
-}
-void CLFile_Open(filespec_t *fs, short mode, file_t &handle) {
-	handle.open(fs->name);
-}
-void CLFile_Close(file_t &handle) {
-	handle.close();
-}
-void CLFile_SetPosition(file_t &handle, short mode, long pos) {
-	assert(mode == 1);
-	handle.seek(pos, 0);
-}
-void CLFile_Read(file_t &handle, void *buffer, long *size) {
-	handle.read(buffer, *size);
-}
-void CLFile_Write(file_t &handle, void *buffer, long *size) {
-	assert(0);
-}
-
-///// CLSound
-// base sound
-void CLSound_PrepareSample(sound_t *sound, short mode) {
-	sound->mode = mode;
-	sound->locked = 0;
-	sound->loopTimes = 0;
-	sound->reversed = 0;
-	sound->ff_32 = 0;
-	sound->volume = 255;
-}
-void CLSound_SetWantsDesigned(short designed) {
-}
-void CLSound_SetLength(sound_t *sound, int length) {
-}
-
-///// CLSoundRaw
-// sound from memory buffer
-#include "CLSouNdRaw.c"
-
-///// CLSoundChannel
-/// sound output device that plays queue of sounds
-soundchannel_t *CLSoundChannel_New(int arg1) {
-	short i;
-	soundchannel_t *ch = (soundchannel_t *)CLMemory_Alloc(sizeof(*ch));
-	if (!ch)
-		return 0;
-
-	ch->volumeLeft = ch->volumeRight = 255;
-	ch->numSounds = 0;
-
-	for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
-		ch->sounds[i] = 0;
-
-	return ch;
-}
-void CLSoundChannel_Free(soundchannel_t *ch) {
-	CLMemory_Free(ch);
-}
-void CLSoundChannel_Stop(soundchannel_t *ch) {
-	//  g_ed->_mixer->stopHandle(ch->ch);
-}
-void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound) {
-}
-short CLSoundChannel_GetVolume(soundchannel_t *ch) {
-	return (ch->volumeLeft + ch->volumeRight) / 2;
-}
-void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume) {
-	if (volume < 0 || volume > 255)
-		return;
-	ch->volumeLeft = volume;
-	ch->volumeRight = volume;
-}
-void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume) {
-	if (volume < 0 || volume > 255)
-		return;
-	ch->volumeRight = volume;
-}
-void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume) {
-	if (volume < 0 || volume > 255)
-		return;
-	ch->volumeLeft = volume;
-}
-
-///// CLSoundGroup
-/// a queue of sounds of same format
-#include "CLSoundGroup.c"
-
-///// CLTimer
-void CLTimer_Action(void *arg) {
-	//  long& counter = *((long*)arg);
-	//  counter++;
-	TimerTicks++;
-}
-
-void CLTimer_Init() {
-	g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
-}
-
-void CLTimer_Done() {
-	g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
-}
-
-///// CRYOLib
-void CRYOLib_InstallExitPatch() {
-}
-void CRYOLib_RemoveExitPatch() {
-}
-void CRYOLib_Init() {
-}
-void CRYOLib_Done() {
-}
-void CRYOLib_MinimalInit() {
-}
-void CRYOLib_ManagersInit() {
-	CLTimer_Init();
-	CLScreenView_Init();
-}
-void CRYOLib_ManagersDone() {
-	CLTimer_Done();
-}
-void CRYOLib_SetDebugMode(short enable) {
-}
-void CRYOLib_InstallEmergencyExit(void(*proc)()) {
-}
-void CRYOLib_SetupEnvironment() {
-}
-void CRYOLib_RestoreEnvironment() {
-}
-void CRYOLib_TestConfig() {
-}
-
-///// CLComputer
-short CLComputer_Has68030() {
-	return 0;
-}
-short CLComputer_Has68040() {
-	return 0;
-}
-
-///// CLDesktop
-void CLDesktop_TestOpenFileAtStartup() {
-}
-
-///// CLHNM
-#include "CLHNM.c"
-
-///// CLError
-#include "CLError.c"
+
+///// Mac APIs
+typedef short OSErr;
+
+short MemError() {
+	return 0;
+}
+
+void SysBeep(int x) {
+}
+
+OSErr SetFPos(short handle, short mode, long pos) {
+	return 0;
+}
+
+OSErr FSRead(short handle, long *size, void *buffer) {
+	return 0;
+}
+
+void FlushEvents(short arg1, short arg2) {
+}
+
+char *c2pstr(char *s) {
+	return s;
+}
+
+void DebugStr(char *s) {
+}
+
+// from mw lib???
+long TickCount() {
+	return g_system->getMillis();
+}
+
+///// CLMemory
+void *CLMemory_Alloc(int size) {
+	return malloc(size);
+}
+void CLMemory_Free(void *ptr) {
+	//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
+	if (!ptr)
+		return;
+
+	free(ptr);
+}
+
+
+///// CLTimer
+volatile long TimerTicks = 0;   // incremented in realtime
+
+///// CLView
+void CLView_SetSrcZoomValues(view_t *view, int x, int y) {
+	view->zoom.src_left = x;
+	view->zoom.src_top = y;
+}
+void CLView_SetDisplayZoomValues(view_t *view, int w, int h) {
+	view->zoom.width = w;
+	view->zoom.height = h;
+}
+void CLView_Free(view_t *view) {
+	if (view->p_buffer && view->allocated)
+		CLMemory_Free(view->p_buffer);
+	if (view)
+		CLMemory_Free(view);
+}
+void CLView_InitDatas(view_t *view, int w, int h, void *buffer) {
+	view->p_buffer = (unsigned char *)buffer;
+	view->width = w;
+	view->height = h;
+	view->pitch = w;
+	view->doubled = 0;
+	view->norm.src_left = 0;
+	view->norm.src_top = 0;
+	view->norm.dst_left = 0;
+	view->norm.dst_top = 0;
+	view->norm.width = w;
+	view->norm.height = h;
+	view->zoom.src_left = 0;
+	view->zoom.src_top = 0;
+	view->zoom.dst_left = 0;
+	view->zoom.dst_top = 0;
+	view->zoom.width = w;
+	view->zoom.height = h;
+}
+view_t *CLView_New(int w, int h) {
+	view_t *view = (view_t *)CLMemory_Alloc(sizeof(view_t));
+	if (view) {
+		void *buffer = (unsigned char *)CLMemory_Alloc(w * h);
+		if (buffer) {
+			view->allocated = 1;
+			CLView_InitDatas(view, w, h, buffer);
+		} else {
+			CLMemory_Free(view);
+			view = 0;
+		}
+	}
+	return view;
+}
+void CLView_CenterIn(view_t *parent, view_t *child) {
+	child->norm.dst_left = (parent->width - child->norm.width) / 2;
+	child->norm.dst_top = (parent->height - child->norm.height) / 2;
+	child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
+	child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
+}
+
+///// CLScreenView
+view_t ScreenView;
+
+void CLScreenView_Init() {
+	// ScreenView is the game's target screen (a pc display)
+	// we use a dedicated surface for it, which at some point will be
+	// presented to user by System::copyRectToScreen call
+	CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
+}
+
+void CLScreenView_CenterIn(view_t *view) {
+	CLView_CenterIn(&ScreenView, view);
+}
+
+///// CLPalette
+unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
+short gMacintize = 0;
+color_t black_palette[256];
+color_t last_palette[256];
+void CLPalette_Init() {
+	short i;
+	for (i = 0; i < 256; i++)
+		black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
+}
+void CLPalette_SetLastPalette(color_t *palette, short first, short count) {
+	short i;
+	for (i = first; i < first + count; i++)
+		last_palette[i] = palette[i];
+}
+void CLPalette_GetLastPalette(color_t *palette) {
+	short i;
+	for (i = 0; i < 256; i++)
+		palette[i] = last_palette[i];
+}
+void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb) {
+	palette[index].r = rgb->r;
+	palette[index].g = rgb->g;
+	palette[index].b = rgb->b;
+	palette[index].a = 0;
+}
+void CLPalette_Macintize(short macintize) {
+	gMacintize = macintize;
+}
+void CLPalette_SetInterval(unsigned short first, unsigned short last) {
+	gIntervalFirst = first;
+	gIntervalSet = 1;
+	gIntervalLast = last;
+}
+void CLPalette_DeactivateInterval() {
+	gIntervalSet = 0;
+}
+void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count) {
+	OSErr err;
+	short i;
+	if (gMacintize) {
+		palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
+		palette[255].r = palette[255].g = palette[255].b = 0;
+	}
+	if (gIntervalSet) {
+		if (first < gIntervalFirst)
+			first = gIntervalFirst;
+		if (first + count > gIntervalLast)
+			count = gIntervalLast - first;
+	}
+
+	byte buffer[256 * 3];
+	for (i = 0; i < 256; i++) {
+		buffer[i * 3] = palette[i].r >> 8;
+		buffer[i * 3 + 1] = palette[i].g >> 8;
+		buffer[i * 3 + 2] = palette[i].b >> 8;
+	}
+
+	g_system->getPaletteManager()->setPalette(buffer, first, count);
+	g_system->updateScreen();
+
+	CLPalette_SetLastPalette(palette, first, count);
+}
+void CLPalette_BeBlack() {
+	CLPalette_Send2Screen(black_palette, 0, 256);
+}
+void CLPalette_BeSystem() {
+}
+
+///// CLBlitter
+static unsigned short newPaletteCount, newPaletteFirst;
+static color_t *pNewPalette;
+static unsigned short useNewPalette;
+
+void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2) {
+	int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
+	//  debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
+	//      rect1->sx, rect1->sy, rect1->ex, rect1->ey,
+	//      rect2->sx, rect2->sy, rect2->ex, rect2->ey,
+	//      (rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
+	assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
+	for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++) {
+		unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
+		unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
+		for (x = 0; x < w; x++)
+			*d++ = *s++;
+	}
+}
+void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count) {
+	pNewPalette = palette;
+	useNewPalette = 1;
+	newPaletteFirst = first;
+	newPaletteCount = count;
+}
+void CLBlitter_OneBlackFlash() {
+}
+void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
+                                       unsigned char *dst, short dstw, short dstp, short dsth) {
+	short x, y;
+	for (y = 0; y < srch; y++) {
+		for (x = 0; x < srcw; x++)
+			*dst++ = *src++;
+		src += srcp - srcw;
+		dst += dstp - dstw;
+	}
+}
+void CLBlitter_CopyView2ScreenCUSTOM(view_t *view) {
+	view_t *dest = &ScreenView;
+	if (!view->doubled) {
+		short srcpitch = view->pitch;
+		short dstpitch = dest->pitch;
+
+		//      this is not quite correct?
+		//      CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+		//          dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+		                                  dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+	} else {
+		assert(0);
+	}
+}
+void CLBlitter_CopyView2Screen(view_t *view) {
+
+	if (useNewPalette) {
+		color_t palette[256];
+		CLPalette_GetLastPalette(palette);
+		CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
+		useNewPalette = 0;
+	}
+
+	//TODO: quick hack to force screen update
+	if (view)
+		CLBlitter_CopyView2ScreenCUSTOM(view);
+
+	g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
+	g_system->updateScreen();
+}
+void CLBlitter_UpdateScreen() {
+	CLBlitter_CopyView2Screen(nullptr);
+}
+void CLBlitter_FillView(view_t *view, unsigned int fill) {
+	short x, y;
+	unsigned char *d = view->p_buffer;
+	assert((fill & 0xFF) * 0x01010101 == fill);
+	for (y = 0; y < view->height; y++) {
+		for (x = 0; x < view->width; x++)
+			*d++ = fill;
+		d += view->pitch - view->width;
+	}
+}
+void CLBlitter_FillScreenView(unsigned int fill) {
+	CLBlitter_FillView(&ScreenView, fill);
+}
+
+
+///// events wrapper
+int _mouseButton;
+byte _keyState[256];
+
+void pollEvents() {
+	g_system->delayMillis(10);
+
+	Common::Event event;
+	while (g_system->getEventManager()->pollEvent(event)) {
+		// Handle keypress
+		switch (event.type) {
+		case Common::EVENT_QUIT:
+		case Common::EVENT_RTL:
+			return;
+
+		case Common::EVENT_KEYDOWN:
+			//          _keyState[(byte)toupper(event.kbd.ascii)] = true;
+			return;
+		case Common::EVENT_KEYUP:
+			//          _keyState[(byte)toupper(event.kbd.ascii)] = false;
+			return;
+		case Common::EVENT_LBUTTONDOWN:
+			_mouseButton = 1;
+			return;
+		case Common::EVENT_RBUTTONDOWN:
+			_mouseButton = 2;
+			return;
+		case Common::EVENT_LBUTTONUP:
+		case Common::EVENT_RBUTTONUP:
+			_mouseButton = 0;
+			return;
+		default:
+			break;
+		}
+	}
+}
+
+
+///// CLKeyboard
+short CLKeyboard_HasCmdDown() {
+	return 0;
+}
+void CLKeyboard_Read() {
+	pollEvents();
+}
+unsigned char CLKeyboard_GetLastASCII() {
+	return 0;
+}
+short CLKeyboard_IsScanCodeDown(short scancode) {
+	return 0;
+}
+
+///// CLMouse
+void CLMouse_Hide() {
+}
+void CLMouse_Show() {
+}
+void CLMouse_GetPosition(short *x, short *y) {
+	*x = g_system->getEventManager()->getMousePos().x;
+	*y = g_system->getEventManager()->getMousePos().y;
+}
+void CLMouse_SetPosition(short x, short y) {
+	g_system->warpMouse(x, y);
+}
+unsigned short CLMouse_IsDown() {
+	pollEvents();
+	return _mouseButton != 0;
+}
+
+///// CLFile
+void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7) {
+}
+void CLFile_SetFinderInfos(void *fs, int a4, int a5) {
+}
+void CLFile_GetFullPath(void *a3, char *a4) {
+}
+void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs) {
+	strcpy(fs->name, name);
+	fs->create = 0;
+}
+void CLFile_Create(filespec_t *fs) {
+	fs->create = 1;
+}
+void CLFile_Open(filespec_t *fs, short mode, file_t &handle) {
+	handle.open(fs->name);
+}
+void CLFile_Close(file_t &handle) {
+	handle.close();
+}
+void CLFile_SetPosition(file_t &handle, short mode, long pos) {
+	assert(mode == 1);
+	handle.seek(pos, 0);
+}
+void CLFile_Read(file_t &handle, void *buffer, long *size) {
+	handle.read(buffer, *size);
+}
+void CLFile_Write(file_t &handle, void *buffer, long *size) {
+	assert(0);
+}
+
+///// CLSound
+// base sound
+void CLSound_PrepareSample(sound_t *sound, short mode) {
+	sound->mode = mode;
+	sound->locked = 0;
+	sound->loopTimes = 0;
+	sound->reversed = 0;
+	sound->ff_32 = 0;
+	sound->volume = 255;
+}
+void CLSound_SetWantsDesigned(short designed) {
+}
+void CLSound_SetLength(sound_t *sound, int length) {
+}
+
+///// CLSoundRaw
+// sound from memory buffer
+#include "CLSouNdRaw.c"
+
+///// CLSoundChannel
+/// sound output device that plays queue of sounds
+soundchannel_t *CLSoundChannel_New(int arg1) {
+	short i;
+	soundchannel_t *ch = (soundchannel_t *)CLMemory_Alloc(sizeof(*ch));
+	if (!ch)
+		return 0;
+
+	ch->volumeLeft = ch->volumeRight = 255;
+	ch->numSounds = 0;
+
+	for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
+		ch->sounds[i] = 0;
+
+	return ch;
+}
+void CLSoundChannel_Free(soundchannel_t *ch) {
+	CLMemory_Free(ch);
+}
+void CLSoundChannel_Stop(soundchannel_t *ch) {
+	//  g_ed->_mixer->stopHandle(ch->ch);
+}
+void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound) {
+}
+short CLSoundChannel_GetVolume(soundchannel_t *ch) {
+	return (ch->volumeLeft + ch->volumeRight) / 2;
+}
+void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeLeft = volume;
+	ch->volumeRight = volume;
+}
+void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeRight = volume;
+}
+void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeLeft = volume;
+}
+
+///// CLSoundGroup
+/// a queue of sounds of same format
+#include "CLSoundGroup.c"
+
+///// CLTimer
+void CLTimer_Action(void *arg) {
+	//  long& counter = *((long*)arg);
+	//  counter++;
+	TimerTicks++;
+}
+
+void CLTimer_Init() {
+	g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
+}
+
+void CLTimer_Done() {
+	g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
+}
+
+///// CRYOLib
+void CRYOLib_InstallExitPatch() {
+}
+void CRYOLib_RemoveExitPatch() {
+}
+void CRYOLib_Init() {
+}
+void CRYOLib_Done() {
+}
+void CRYOLib_MinimalInit() {
+}
+void CRYOLib_ManagersInit() {
+	CLTimer_Init();
+	CLScreenView_Init();
+}
+void CRYOLib_ManagersDone() {
+	CLTimer_Done();
+}
+void CRYOLib_SetDebugMode(short enable) {
+}
+void CRYOLib_InstallEmergencyExit(void(*proc)()) {
+}
+void CRYOLib_SetupEnvironment() {
+}
+void CRYOLib_RestoreEnvironment() {
+}
+void CRYOLib_TestConfig() {
+}
+
+///// CLComputer
+short CLComputer_Has68030() {
+	return 0;
+}
+short CLComputer_Has68040() {
+	return 0;
+}
+
+///// CLDesktop
+void CLDesktop_TestOpenFileAtStartup() {
+}
+
+///// CLHNM
+#include "CLHNM.c"
+
+///// CLError
+#include "CLError.c"
diff --git a/engines/cryo/LempelZiv.cpp b/engines/cryo/LempelZiv.cpp
index 6020c96..ac2b5f0 100644
--- a/engines/cryo/LempelZiv.cpp
+++ b/engines/cryo/LempelZiv.cpp
@@ -1,7 +1,7 @@
-#include "LempelZiv.h"
-
-namespace Cryo {
-
-
-
+#include "LempelZiv.h"
+
+namespace Cryo {
+
+
+
 }
\ No newline at end of file
diff --git a/engines/cryo/LempelZiv.h b/engines/cryo/LempelZiv.h
index 85279b3..fa68397 100644
--- a/engines/cryo/LempelZiv.h
+++ b/engines/cryo/LempelZiv.h
@@ -1,88 +1,88 @@
-#pragma once
-
-namespace Cryo {
-
-class BitReaderBase {
-public:
-	unsigned char *_data;   //NB! never override this - used by decompressor
-	unsigned int _queue;
-	unsigned int _queueLeft;
-public:
-	BitReaderBase(void *data, unsigned int dataSize = 0) {
-		_data = static_cast<unsigned char *>(data);
-		_queue = _queueLeft = 0;
-	}
-
-	unsigned char GetBit() {
-		return 0;   // to be overriden
-	}
-};
-
-// used to decompress HSQ files
-class BitReader16 : BitReaderBase {
-public:
-	unsigned char GetBit() {
-		if (!_queueLeft) {
-			_queue = (_data[1] << 8) | _data[0];
-			_data += 2;
-			_queueLeft += 16;
-		}
-		unsigned char bit = _queue & 1;
-		_queue >>= 1;
-		_queueLeft--;
-		return bit;
-	}
-};
-
-// used by HNM decoder
-class BitReader32 : BitReaderBase {
-public:
-	unsigned char GetBit() {
-		if (!_queueLeft) {
-			_queue = (_data[3] << 24) | (_data[2] << 16) | (_data[1] << 8) | _data[0];
-			_data += 4;
-			_queueLeft += 32;
-		}
-		unsigned char bit = (_queue >> (_queueLeft - 1)) & 1;
-		_queueLeft--;
-		return bit;
-	}
-};
-
-template <class BitReader>
-class LempelZivBase : BitReader {
-public:
-	LempelZivBase(void *input, unsigned int inputSize) : BitReader(input, inputSize)
-
-		unsigned int UnpackBuffer(void *output, unsigned int maxOutputSize) {
-		unsigned char *out = static_cast<unsigned char *>(output);
-		for (;;) {
-			if (GetBit()) {
-				*out++ = *_data++;
-			} else {
-				int length, offset;
-				if (GetBit()) {
-					length = *_data & 7;
-					offset = ((_data[1] << 8) | _data[0]) >> 3;
-					_data += 2;
-					offset -= 8192;
-					if (!length)
-						length = *_data++;
-					if (!length)
-						break;
-				} else {
-					length = GetBit() * 2 + GetBit();
-					offset = *(_data++) - 256;
-				}
-				length += 2;
-				while (length--) {
-					*out = *(out + offset);
-					out++;
-				}
-			}
-		}
-		return out - static_cast<unsigned char *>(output);
-	}
-};
-
-}
+#pragma once
+
+namespace Cryo {
+
+class BitReaderBase {
+public:
+	unsigned char *_data;   //NB! never override this - used by decompressor
+	unsigned int _queue;
+	unsigned int _queueLeft;
+public:
+	BitReaderBase(void *data, unsigned int dataSize = 0) {
+		_data = static_cast<unsigned char *>(data);
+		_queue = _queueLeft = 0;
+	}
+
+	unsigned char GetBit() {
+		return 0;   // to be overriden
+	}
+};
+
+// used to decompress HSQ files
+class BitReader16 : BitReaderBase {
+public:
+	unsigned char GetBit() {
+		if (!_queueLeft) {
+			_queue = (_data[1] << 8) | _data[0];
+			_data += 2;
+			_queueLeft += 16;
+		}
+		unsigned char bit = _queue & 1;
+		_queue >>= 1;
+		_queueLeft--;
+		return bit;
+	}
+};
+
+// used by HNM decoder
+class BitReader32 : BitReaderBase {
+public:
+	unsigned char GetBit() {
+		if (!_queueLeft) {
+			_queue = (_data[3] << 24) | (_data[2] << 16) | (_data[1] << 8) | _data[0];
+			_data += 4;
+			_queueLeft += 32;
+		}
+		unsigned char bit = (_queue >> (_queueLeft - 1)) & 1;
+		_queueLeft--;
+		return bit;
+	}
+};
+
+template <class BitReader>
+class LempelZivBase : BitReader {
+public:
+	LempelZivBase(void *input, unsigned int inputSize) : BitReader(input, inputSize)
+
+		unsigned int UnpackBuffer(void *output, unsigned int maxOutputSize) {
+		unsigned char *out = static_cast<unsigned char *>(output);
+		for (;;) {
+			if (GetBit()) {
+				*out++ = *_data++;
+			} else {
+				int length, offset;
+				if (GetBit()) {
+					length = *_data & 7;
+					offset = ((_data[1] << 8) | _data[0]) >> 3;
+					_data += 2;
+					offset -= 8192;
+					if (!length)
+						length = *_data++;
+					if (!length)
+						break;
+				} else {
+					length = GetBit() * 2 + GetBit();
+					offset = *(_data++) - 256;
+				}
+				length += 2;
+				while (length--) {
+					*out = *(out + offset);
+					out++;
+				}
+			}
+		}
+		return out - static_cast<unsigned char *>(output);
+	}
+};
+
+}
diff --git a/engines/cryo/ResourceManager.cpp b/engines/cryo/ResourceManager.cpp
index dd541f7..6de5b62 100644
--- a/engines/cryo/ResourceManager.cpp
+++ b/engines/cryo/ResourceManager.cpp
@@ -1,100 +1,100 @@
-#include "ResourceManager.h"
-
-namespace Cryo {
-
-ResourceManager::ResourceManager() {
-}
-
-ResourceManager::ResourceManager(const Common::String &datFileName) {
-	LoadDatFile(datFileName);
-}
-
-ResourceManager::~ResourceManager() {
-}
-
-bool ResourceManager::LoadDatFile(const Common::String &datFileName) {
-	if (_datFile.isOpen()) {
-		_datFile.close();
-		_files.clear();
-	}
-
-	assert(_datFile.open(datFileName));
-
-	unsigned short numFiles = _datFile.readUint16LE();
-
-	for (unsigned short i = 0; i < numFiles; i++) {
-		DatFileEntry entry;
-
-		_datFile.read(entry._name, sizeof(entry._name));
-		entry._size = _datFile.readUint32LE();
-		entry._offset = _datFile.readUint32LE();
-		entry._flag = _datFile.readByte();
-
-		_files.push_back(entry);
-	}
-
-	return true;
-}
-
-Common::SeekableReadStream *ResourceManager::GetFile(const Common::String &resName, unsigned int hintIndex) {
-	// First, try raw disk file so we can support modding/patching
-
-	if (Common::File::exists(resName)) {
-		debug("Loading %s from disk", resName);
-
-		Common::File *resource = new Common::File();
-		resource->open(resName);
-		return resource;
-	}
-
-	// Look inside .dat file
-
-	if (_datFile.isOpen()) {
-		for (unsigned int i = hintIndex; i < _files.size(); i++) {
-			if (!resName.compareToIgnoreCase(_files[i]._name)) {
-				debug("Loading %s from dat file", resName);
-				Common::SeekableSubReadStream *resource = new Common::SeekableSubReadStream(&_datFile, _files[i]._offset, _files[i]._offset + _files[i]._size);
-				return resource;
-			}
-		}
-	}
-
-	debug("Unable to load %s - does't exists", resName);
-	return nullptr;
-}
-
-Common::SeekableReadStream *ResourceManager::GetFile(unsigned int resIndex) {
-	if (_files.size() > resIndex) {
-		return GetFile(Common::String(_files[resIndex]._name), resIndex);
-	}
-
-	return nullptr;
-}
-
-void *ResourceManager::StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size) {
-	if (!stream)
-		return nullptr;
-
-	unsigned int readSize = stream->size();
-	unsigned char *data = new unsigned char[readSize + 1];
-	readSize = stream->read(data, readSize);
-
-	if (size)
-		*size = readSize;
-	return data;
-}
-
-void *ResourceManager::GetData(const Common::String &resName, unsigned int *size) {
-	Common::SeekableReadStream *resource = GetFile(resName);
-	void *data = StreamToBuffer(resource, size);
-	delete resource;
-	return data;
-}
-
-void *ResourceManager::GetData(int resIndex, unsigned int *size) {
-	Common::SeekableReadStream *resource = GetFile(resIndex);
-	void *data = StreamToBuffer(resource, size);
-	delete resource;
-	return data;
-}
+#include "ResourceManager.h"
+
+namespace Cryo {
+
+ResourceManager::ResourceManager() {
+}
+
+ResourceManager::ResourceManager(const Common::String &datFileName) {
+	LoadDatFile(datFileName);
+}
+
+ResourceManager::~ResourceManager() {
+}
+
+bool ResourceManager::LoadDatFile(const Common::String &datFileName) {
+	if (_datFile.isOpen()) {
+		_datFile.close();
+		_files.clear();
+	}
+
+	assert(_datFile.open(datFileName));
+
+	unsigned short numFiles = _datFile.readUint16LE();
+
+	for (unsigned short i = 0; i < numFiles; i++) {
+		DatFileEntry entry;
+
+		_datFile.read(entry._name, sizeof(entry._name));
+		entry._size = _datFile.readUint32LE();
+		entry._offset = _datFile.readUint32LE();
+		entry._flag = _datFile.readByte();
+
+		_files.push_back(entry);
+	}
+
+	return true;
+}
+
+Common::SeekableReadStream *ResourceManager::GetFile(const Common::String &resName, unsigned int hintIndex) {
+	// First, try raw disk file so we can support modding/patching
+
+	if (Common::File::exists(resName)) {
+		debug("Loading %s from disk", resName);
+
+		Common::File *resource = new Common::File();
+		resource->open(resName);
+		return resource;
+	}
+
+	// Look inside .dat file
+
+	if (_datFile.isOpen()) {
+		for (unsigned int i = hintIndex; i < _files.size(); i++) {
+			if (!resName.compareToIgnoreCase(_files[i]._name)) {
+				debug("Loading %s from dat file", resName);
+				Common::SeekableSubReadStream *resource = new Common::SeekableSubReadStream(&_datFile, _files[i]._offset, _files[i]._offset + _files[i]._size);
+				return resource;
+			}
+		}
+	}
+
+	debug("Unable to load %s - does't exists", resName);
+	return nullptr;
+}
+
+Common::SeekableReadStream *ResourceManager::GetFile(unsigned int resIndex) {
+	if (_files.size() > resIndex) {
+		return GetFile(Common::String(_files[resIndex]._name), resIndex);
+	}
+
+	return nullptr;
+}
+
+void *ResourceManager::StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size) {
+	if (!stream)
+		return nullptr;
+
+	unsigned int readSize = stream->size();
+	unsigned char *data = new unsigned char[readSize + 1];
+	readSize = stream->read(data, readSize);
+
+	if (size)
+		*size = readSize;
+	return data;
+}
+
+void *ResourceManager::GetData(const Common::String &resName, unsigned int *size) {
+	Common::SeekableReadStream *resource = GetFile(resName);
+	void *data = StreamToBuffer(resource, size);
+	delete resource;
+	return data;
+}
+
+void *ResourceManager::GetData(int resIndex, unsigned int *size) {
+	Common::SeekableReadStream *resource = GetFile(resIndex);
+	void *data = StreamToBuffer(resource, size);
+	delete resource;
+	return data;
+}
 }
\ No newline at end of file
diff --git a/engines/cryo/ResourceManager.h b/engines/cryo/ResourceManager.h
index 9bba1d3..da38c9d 100644
--- a/engines/cryo/ResourceManager.h
+++ b/engines/cryo/ResourceManager.h
@@ -1,70 +1,70 @@
-#pragma once
-
-#include "common/array.h"
-#include "common/file.h"
-#include "common/fs.h"
-#include "common/str.h"
-#include "common/substream.h"
-#include "common/debug.h"
-
-namespace Cryo {
-
-template<typename T>
-class CryoArray {
-private:
-	unsigned char *_data;
-	bool _ownData;
-	unsigned short ElementOffset(int num) {
-		assert(_data && num < Count())
-		return (static_cast<unsigned short *>_data)[num];
-	}
-public:
-	CryoArray(void *data, bool ownData) : _data(data), _ownData(ownData) {
-	}
-	~CryoArray() {
-		if (_ownData)
-			delete data;
-	}
-	unsigned short Count() {
-		return ElementOffset(0) / 2;
-	}
-	const T *operator[](int index) {
-		return static_cast<T *>(_data + ElementOffset(num));
-	}
-};
-
-class ResourceManager {
-private:
-	struct DatFileEntry {
-		char _name[16];
-		unsigned int _size;
-		unsigned int _offset;
-		unsigned char _flag;
-	};
-
-	Common::Array<DatFileEntry> _files;
-	Common::File _datFile;
-
-	static void *StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size);
-
-public:
-	ResourceManager(const Common::String &datFileName);
-	ResourceManager();
-	~ResourceManager();
-
-	bool LoadDatFile(const Common::String &datFileName);
-
-	// Load resource as a seekable stream
-	Common::SeekableReadStream *GetFile(const Common::String &resName, unsigned int hintIndex = 0);
-	Common::SeekableReadStream *GetFile(unsigned int resIndex);
-
-	// Load resource as a buffer
-	void *GetData(const Common::String &resName, unsigned int *size = nullptr);
-	void *GetData(int resIndex, unsigned int *size = nullptr);
-	void *operator[](int resIndex) {
-		return GetData(resIndex);
-	}
-
-};
-
+#pragma once
+
+#include "common/array.h"
+#include "common/file.h"
+#include "common/fs.h"
+#include "common/str.h"
+#include "common/substream.h"
+#include "common/debug.h"
+
+namespace Cryo {
+
+template<typename T>
+class CryoArray {
+private:
+	unsigned char *_data;
+	bool _ownData;
+	unsigned short ElementOffset(int num) {
+		assert(_data && num < Count())
+		return (static_cast<unsigned short *>_data)[num];
+	}
+public:
+	CryoArray(void *data, bool ownData) : _data(data), _ownData(ownData) {
+	}
+	~CryoArray() {
+		if (_ownData)
+			delete data;
+	}
+	unsigned short Count() {
+		return ElementOffset(0) / 2;
+	}
+	const T *operator[](int index) {
+		return static_cast<T *>(_data + ElementOffset(num));
+	}
+};
+
+class ResourceManager {
+private:
+	struct DatFileEntry {
+		char _name[16];
+		unsigned int _size;
+		unsigned int _offset;
+		unsigned char _flag;
+	};
+
+	Common::Array<DatFileEntry> _files;
+	Common::File _datFile;
+
+	static void *StreamToBuffer(Common::SeekableReadStream *stream, unsigned int *size);
+
+public:
+	ResourceManager(const Common::String &datFileName);
+	ResourceManager();
+	~ResourceManager();
+
+	bool LoadDatFile(const Common::String &datFileName);
+
+	// Load resource as a seekable stream
+	Common::SeekableReadStream *GetFile(const Common::String &resName, unsigned int hintIndex = 0);
+	Common::SeekableReadStream *GetFile(unsigned int resIndex);
+
+	// Load resource as a buffer
+	void *GetData(const Common::String &resName, unsigned int *size = nullptr);
+	void *GetData(int resIndex, unsigned int *size = nullptr);
+	void *operator[](int resIndex) {
+		return GetData(resIndex);
+	}
+
+};
+
 }
\ No newline at end of file
diff --git a/engines/cryo/bugs.txt b/engines/cryo/bugs.txt
index 50b857e..19d1e8e 100644
--- a/engines/cryo/bugs.txt
+++ b/engines/cryo/bugs.txt
@@ -1,10 +1,10 @@
-
-1. Open menu and replay last dialog, then press stop. hover over buttons - hint text will be misplaced
-2. During valley location change some junk appears in the bottom half of screen for a brief time (broken transition effect?)
-3. Transitions often show a lot of red colors (bad palette fadein/out?)
-4. After game load in some areas (White Arch) top bar and inventory not redrawn due to (DrawFlags?) initialized incorrectly
-5. Mac reload feature uses hardcoded savefile from eden.dat
-6. First time in Tau's cave, try to take knife. When Dina objects, click on her - Tau's dialog will start (maybe it's original bug?)
-7. Mouse clipping may be lost during FMV scenes
-8. Screen doubling feature probably doesn't work (not really needed, can be replaced with built-in SCUMMVM scaler)
-9. Tons of debug messages spam when hover mouse over party icons or menu buttons
+
+1. Open menu and replay last dialog, then press stop. hover over buttons - hint text will be misplaced
+2. During valley location change some junk appears in the bottom half of screen for a brief time (broken transition effect?)
+3. Transitions often show a lot of red colors (bad palette fadein/out?)
+4. After game load in some areas (White Arch) top bar and inventory not redrawn due to (DrawFlags?) initialized incorrectly
+5. Mac reload feature uses hardcoded savefile from eden.dat
+6. First time in Tau's cave, try to take knife. When Dina objects, click on her - Tau's dialog will start (maybe it's original bug?)
+7. Mouse clipping may be lost during FMV scenes
+8. Screen doubling feature probably doesn't work (not really needed, can be replaced with built-in SCUMMVM scaler)
+9. Tons of debug messages spam when hover mouse over party icons or menu buttons
diff --git a/engines/cryo/clsoundgroup.c b/engines/cryo/clsoundgroup.c
index e7e40b7..a1abaf4 100644
--- a/engines/cryo/clsoundgroup.c
+++ b/engines/cryo/clsoundgroup.c
@@ -1,105 +1,105 @@
-#include "cryolib.h"
-
-soundgroup_t *CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode) {
-	soundgroup_t *sg;
-	short i;
-
-	sg = (soundgroup_t *)CLMemory_Alloc(sizeof(*sg));
-	if (numSounds < CL_MAX_SOUNDS)
-		sg->numSounds = numSounds;
-	else {
-		__libError = -3;
-		__osError = 0;
-		CLCheckError();
-		sg->numSounds = CL_MAX_SOUNDS;
-	}
-	for (i = 0; i < sg->numSounds; i++) {
-		sound_t *sound = CLSoundRaw_New(arg4, rate, sampleSize, mode);
-		sg->sound[i] = sound;
-		sound->ff_1A = arg4;
-	}
-	sg->soundIndex = 0;
-	sg->playIndex = 0;
-	sg->ff_106 = 1;
-
-	return sg;
-}
-
-void CLSoundGroup_Free(soundgroup_t *sg) {
-	short i;
-	for (i = 0; i < sg->numSounds; i++)
-		CLSoundRaw_Free(sg->sound[i]);
-	CLMemory_Free(sg);
-}
-
-void CLSoundGroup_Reverse16All(soundgroup_t *sg) {
-	short i;
-	for (i = 0; i < sg->numSounds; i++)
-		sg->sound[i]->reversed = 1;
-}
-
-void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg) {
-	sound_t *sound = sg->sound[sg->soundIndex];
-	if (sg->ff_106)
-		while (sound->locked) ;
-	return ((char *)(*sound->sndHandle)) + sound->headerLen;
-}
-
-short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned) {
-	sound_t *sound = sg->sound[sg->soundIndex];
-	if (sg->ff_106)
-		while (sound->locked) ;
-	else if (sound->locked)
-		return 0;
-	sound->buffer = (char *)buffer;
-	CLSound_SetLength(sound, length);
-	sound->length = length;
-//	if(sound->reversed && sound->sampleSize == 16)
-//		ReverseBlock16(buffer, length);
-//	if(isSigned)
-//		CLSound_Signed2NonSigned(buffer, length);
-	if (sg->soundIndex == sg->numSounds - 1)
-		sg->soundIndex = 0;
-	else
-		sg->soundIndex++;
-
-	return 1;
-}
-
-short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned) {
-	void *buffer;
-	sound_t *sound = sg->sound[sg->soundIndex];
-	if (length >= sound->ff_1A) {
-		__libError = -10;
-		__osError = 0;
-		CLCheckError();
-	}
-	if (sg->ff_106)
-		while (sound->locked) ;
-	else if (sound->locked)
-		return 0;
-	buffer = ((char *)(*sound->sndHandle)) + sound->headerLen;
-	sound->buffer = (char *)buffer;
-	memcpy(buffer, data, length);
-	CLSound_SetLength(sound, length);
-	sound->length = length;
-//	if(sound->reversed && sound->sampleSize == 16)
-//		ReverseBlock16(buffer, length);
-//	if(isSigned)
-//		CLSound_Signed2NonSigned(buffer, length);
-	if (sg->soundIndex == sg->numSounds - 1)
-		sg->soundIndex = 0;
-	else
-		sg->soundIndex++;
-
-	return 1;
-}
-
-void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch) {
-	CLSoundChannel_Play(ch, sg->sound[sg->playIndex]);
-	if (sg->playIndex == sg->numSounds - 1)
-		sg->playIndex = 0;
-	else
-		sg->playIndex++;
-
-}
+#include "cryolib.h"
+
+soundgroup_t *CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode) {
+	soundgroup_t *sg;
+	short i;
+
+	sg = (soundgroup_t *)CLMemory_Alloc(sizeof(*sg));
+	if (numSounds < CL_MAX_SOUNDS)
+		sg->numSounds = numSounds;
+	else {
+		__libError = -3;
+		__osError = 0;
+		CLCheckError();
+		sg->numSounds = CL_MAX_SOUNDS;
+	}
+	for (i = 0; i < sg->numSounds; i++) {
+		sound_t *sound = CLSoundRaw_New(arg4, rate, sampleSize, mode);
+		sg->sound[i] = sound;
+		sound->ff_1A = arg4;
+	}
+	sg->soundIndex = 0;
+	sg->playIndex = 0;
+	sg->ff_106 = 1;
+
+	return sg;
+}
+
+void CLSoundGroup_Free(soundgroup_t *sg) {
+	short i;
+	for (i = 0; i < sg->numSounds; i++)
+		CLSoundRaw_Free(sg->sound[i]);
+	CLMemory_Free(sg);
+}
+
+void CLSoundGroup_Reverse16All(soundgroup_t *sg) {
+	short i;
+	for (i = 0; i < sg->numSounds; i++)
+		sg->sound[i]->reversed = 1;
+}
+
+void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg) {
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if (sg->ff_106)
+		while (sound->locked) ;
+	return ((char *)(*sound->sndHandle)) + sound->headerLen;
+}
+
+short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned) {
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if (sg->ff_106)
+		while (sound->locked) ;
+	else if (sound->locked)
+		return 0;
+	sound->buffer = (char *)buffer;
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buffer, length);
+//	if(isSigned)
+//		CLSound_Signed2NonSigned(buffer, length);
+	if (sg->soundIndex == sg->numSounds - 1)
+		sg->soundIndex = 0;
+	else
+		sg->soundIndex++;
+
+	return 1;
+}
+
+short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned) {
+	void *buffer;
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if (length >= sound->ff_1A) {
+		__libError = -10;
+		__osError = 0;
+		CLCheckError();
+	}
+	if (sg->ff_106)
+		while (sound->locked) ;
+	else if (sound->locked)
+		return 0;
+	buffer = ((char *)(*sound->sndHandle)) + sound->headerLen;
+	sound->buffer = (char *)buffer;
+	memcpy(buffer, data, length);
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buffer, length);
+//	if(isSigned)
+//		CLSound_Signed2NonSigned(buffer, length);
+	if (sg->soundIndex == sg->numSounds - 1)
+		sg->soundIndex = 0;
+	else
+		sg->soundIndex++;
+
+	return 1;
+}
+
+void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch) {
+	CLSoundChannel_Play(ch, sg->sound[sg->playIndex]);
+	if (sg->playIndex == sg->numSounds - 1)
+		sg->playIndex = 0;
+	else
+		sg->playIndex++;
+
+}
diff --git a/engines/cryo/cryo.cpp b/engines/cryo/cryo.cpp
index 9eb22b6..7aed601 100644
--- a/engines/cryo/cryo.cpp
+++ b/engines/cryo/cryo.cpp
@@ -1,81 +1,81 @@
-#include "common/scummsys.h"
-
-#include "common/config-manager.h"
-#include "common/debug.h"
-#include "common/debug-channels.h"
-#include "common/error.h"
-#include "graphics/surface.h"
-#include "graphics/screen.h"
-#include "graphics/palette.h"
-#include "common/system.h"
-//#include "common/timer.h"
-
-#include "engines/util.h"
-
-#include "cryo/cryo.h"
-#include "cryo/eden.h"
-
-namespace Cryo {
-
-CryoEngine *g_ed = 0;
-
-CryoEngine::CryoEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _console(nullptr) {
-	// Put your engine in a sane state, but do nothing big yet;
-	// in particular, do not load data from files; rather, if you
-	// need to do such things, do them from run().
-
-	// Do not initialize graphics here
-	// Do not initialize audio devices here
-
-	// However this is the place to specify all default directories
-//	const Common::FSNode gameDataDir(ConfMan.get("path"));
-//	SearchMan.addSubDirectoryMatching(gameDataDir, "sound");
-
-	// Here is the right place to set up the engine specific debug channels
-	DebugMan.addDebugChannel(kCryoDebugExample, "example", "this is just an example for a engine specific debug channel");
-	DebugMan.addDebugChannel(kCryoDebugExample2, "example2", "also an example");
-
-	// Don't forget to register your random source
-	_rnd = new Common::RandomSource("cryo");
-
-	debug("CryoEngine::CryoEngine");
-
-	g_ed = this;
-}
-
-CryoEngine::~CryoEngine() {
-	debug("CryoEngine::~CryoEngine");
-
-	// Dispose your resources here
-	delete _rnd;
-
-	// Remove all of our debug levels here
-	DebugMan.clearAllDebugChannels();
-}
-
-Common::Error CryoEngine::run() {
-	// Initialize graphics using following:
-	initGraphics(320, 200, false);
-	_screen.create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
-
-	// Create debugger console. It requires GFX to be initialized
-	_console = new Console(this);
-
-	// Additional setup.
-	debug("CryoEngine::init");
-
-	// Your main even loop should be (invoked from) here.
-	debug("CryoEngine::go: Hello, World!");
-
-	// This test will show up if -d1 and --debugflags=example are specified on the commandline
-	debugC(1, kCryoDebugExample, "Example debug call");
-
-	// This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline
-	debugC(3, kCryoDebugExample | kCryoDebugExample2, "Example debug call two");
-
-	game.main();
-
-	return Common::kNoError;
-}
-
-} // End of namespace Cryo
+#include "common/scummsys.h"
+
+#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/error.h"
+#include "graphics/surface.h"
+#include "graphics/screen.h"
+#include "graphics/palette.h"
+#include "common/system.h"
+//#include "common/timer.h"
+
+#include "engines/util.h"
+
+#include "cryo/cryo.h"
+#include "cryo/eden.h"
+
+namespace Cryo {
+
+CryoEngine *g_ed = 0;
+
+CryoEngine::CryoEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _console(nullptr) {
+	// Put your engine in a sane state, but do nothing big yet;
+	// in particular, do not load data from files; rather, if you
+	// need to do such things, do them from run().
+
+	// Do not initialize graphics here
+	// Do not initialize audio devices here
+
+	// However this is the place to specify all default directories
+//	const Common::FSNode gameDataDir(ConfMan.get("path"));
+//	SearchMan.addSubDirectoryMatching(gameDataDir, "sound");
+
+	// Here is the right place to set up the engine specific debug channels
+	DebugMan.addDebugChannel(kCryoDebugExample, "example", "this is just an example for a engine specific debug channel");
+	DebugMan.addDebugChannel(kCryoDebugExample2, "example2", "also an example");
+
+	// Don't forget to register your random source
+	_rnd = new Common::RandomSource("cryo");
+
+	debug("CryoEngine::CryoEngine");
+
+	g_ed = this;
+}
+
+CryoEngine::~CryoEngine() {
+	debug("CryoEngine::~CryoEngine");
+
+	// Dispose your resources here
+	delete _rnd;
+
+	// Remove all of our debug levels here
+	DebugMan.clearAllDebugChannels();
+}
+
+Common::Error CryoEngine::run() {
+	// Initialize graphics using following:
+	initGraphics(320, 200, false);
+	_screen.create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
+
+	// Create debugger console. It requires GFX to be initialized
+	_console = new Console(this);
+
+	// Additional setup.
+	debug("CryoEngine::init");
+
+	// Your main even loop should be (invoked from) here.
+	debug("CryoEngine::go: Hello, World!");
+
+	// This test will show up if -d1 and --debugflags=example are specified on the commandline
+	debugC(1, kCryoDebugExample, "Example debug call");
+
+	// This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline
+	debugC(3, kCryoDebugExample | kCryoDebugExample2, "Example debug call two");
+
+	game.main();
+
+	return Common::kNoError;
+}
+
+} // End of namespace Cryo
diff --git a/engines/cryo/cryo.h b/engines/cryo/cryo.h
index 1e3acb9..9a0d48b 100644
--- a/engines/cryo/cryo.h
+++ b/engines/cryo/cryo.h
@@ -1,62 +1,62 @@
-#ifndef CRYO_H
-#define CRYO_H
-
-#include "common/scummsys.h"
-#include "common/config-manager.h"
-#include "engines/advancedDetector.h"
-#include "common/debug.h"
-#include "common/debug-channels.h"
-#include "common/error.h"
-#include "common/random.h"
-#include "engines/engine.h"
-#include "gui/debugger.h"
-#include "graphics/surface.h"
-#include "graphics/screen.h"
-#include "cryo/eden.h"
-
-namespace Cryo {
-
-class Console;
-
-// our engine debug channels
-enum {
-	kCryoDebugExample = 1 << 0,
-	kCryoDebugExample2 = 1 << 1
-	                     // next new channel must be 1 << 2 (4)
-	                     // the current limitation is 32 debug channels (1 << 31 is the last one)
-};
-
-class CryoEngine : public Engine {
-public:
-	CryoEngine(OSystem *syst, const ADGameDescription *gameDesc);
-	~CryoEngine();
-
-	virtual Common::Error run();
-
-	// Detection related functions
-	const ADGameDescription *_gameDescription;
-	const char *getGameId() const;
-	Common::Platform getPlatform() const;
-
-	// We need random numbers
-	Common::RandomSource *_rnd;
-
-	Graphics::Surface _screen;
-	EdenGame game;
-
-private:
-	Console *_console;
-};
-
-extern CryoEngine *g_ed;
-
-// Example console class
-class Console : public GUI::Debugger {
-public:
-	Console(CryoEngine *vm) {}
-	virtual ~Console(void) {}
-};
-
-} // End of namespace Cryo
-
-#endif
+#ifndef CRYO_H
+#define CRYO_H
+
+#include "common/scummsys.h"
+#include "common/config-manager.h"
+#include "engines/advancedDetector.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/error.h"
+#include "common/random.h"
+#include "engines/engine.h"
+#include "gui/debugger.h"
+#include "graphics/surface.h"
+#include "graphics/screen.h"
+#include "cryo/eden.h"
+
+namespace Cryo {
+
+class Console;
+
+// our engine debug channels
+enum {
+	kCryoDebugExample = 1 << 0,
+	kCryoDebugExample2 = 1 << 1
+	                     // next new channel must be 1 << 2 (4)
+	                     // the current limitation is 32 debug channels (1 << 31 is the last one)
+};
+
+class CryoEngine : public Engine {
+public:
+	CryoEngine(OSystem *syst, const ADGameDescription *gameDesc);
+	~CryoEngine();
+
+	virtual Common::Error run();
+
+	// Detection related functions
+	const ADGameDescription *_gameDescription;
+	const char *getGameId() const;
+	Common::Platform getPlatform() const;
+
+	// We need random numbers
+	Common::RandomSource *_rnd;
+
+	Graphics::Surface _screen;
+	EdenGame game;
+
+private:
+	Console *_console;
+};
+
+extern CryoEngine *g_ed;
+
+// Example console class
+class Console : public GUI::Debugger {
+public:
+	Console(CryoEngine *vm) {}
+	virtual ~Console(void) {}
+};
+
+} // End of namespace Cryo
+
+#endif
diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h
index ae6ce7f..ed6fff2 100644
--- a/engines/cryo/defs.h
+++ b/engines/cryo/defs.h
@@ -1,1463 +1,1463 @@
-#include <stddef.h>
-#include <stdlib.h>
-#include "cryolib.h"
-
-#define GetElem(array, idx) \
-	( (char*)(array) + PLE16((idx) * 2 + (char*)(array)) )
-/*
-static inline void* AGetElem(unsigned char *arr, short index)
-{
-    unsigned char *p = arr + num * 2;
-    unsigned char o0 = *p++;
-    unsigned char o1 = *p++;
-    unsigned short ofs = (o1 << 8) | o0;
-    return arr + ofs;
-}
-*/
-
-///////////////// Game defs
-
-#define FONT_HEIGHT 9
-
-
-/*
-Glossary
-  room      - a single game world's screen. referenced by 16-bit number 0xAALL, where AA - area# and LL - location#
-  area      - geographic area - Mo, Chamaar, etc
-  location  - coordinates of particular room in an area. usually in form of 0xXY, where X - map row, Y - map column
-  character - an unique character (human or dino.) Has their own voice/dialog lines
-  person    - instance of a character. Usually tied to specific room, but some may travel with you
-  party     - a group of characters that travel with you
-  object    - inventory item
-  icon      - clickable rectangle with some action tied to it
-  dialog    - a set of of dialog lines for character. further divided by categories and each entry may have associated
-              condition to be validated
-  global    - game-wide storage area. must be preserved when saving/loading
-  phase     - current story progress. Incremented by 1 for minor events, by 0x10 for major advancements
-*/
-
-enum Phases {
-	phNewGame = 0
-};
-
-namespace Areas {
-enum Areas {
-	arMo = 1,
-	arTausCave,
-	arChamaar,
-	arUluru,
-	arKoto,
-	arTamara,
-	arCantura,
-	arShandovra,
-	arNarimsCave,
-	arEmbalmersCave,
-	arWhiteArch,
-	arMoorkusLair
-};
-}
-
-#define MKRM(a,l) (((a) << 8) | (l))
-
-enum OBJECT {
-	OBJ_0,
-	OBJ_1,
-	OBJ_2,
-	OBJ_3,
-	OBJ_4,
-	OBJ_PRISME, // 5
-	OBJ_6,
-	OBJ_7,
-	OBJ_OEUF,   // 8
-	OBJ_9,
-	OBJ_10,
-	OBJ_CHAMPB, // 11
-	OBJ_CHAMPM, // 12
-	OBJ_COUTEAU,    // 13
-	OBJ_NIDV,   // 14
-	OBJ_NIDO,   // 15
-	OBJ_OR,     // 16
-	OBJ_17,
-	OBJ_18,
-	OBJ_SOLEIL, // 19
-	OBJ_CORNE,  // 20
-	OBJ_21,
-	OBJ_22,
-	OBJ_23,
-	OBJ_24,
-	OBJ_25,
-	OBJ_26,
-	OBJ_27,
-	OBJ_28,
-	OBJ_29,
-	OBJ_30,
-	OBJ_31,
-	OBJ_32,
-	OBJ_33,
-	OBJ_34,
-	OBJ_35,
-	OBJ_36,     // 36 is 1st plaque, 6 total
-	OBJ_37,
-	OBJ_PLAQUE, // 38
-	OBJ_39,
-	OBJ_40,
-	OBJ_41,
-};
-
-namespace Objects {
-enum Objects {
-	obNone,
-	obWayStone,
-	obShell,
-	obTalisman,
-	obTooth,
-	obPrism,    // 5
-	obFlute,
-	obApple,
-	obEgg,      // 8
-	obRoot,
-	obUnused10,
-	obShroom,   // 11
-	obBadShroom,    // 12
-	obKnife,    // 13
-	obNest, // 14
-	obFullNest, // 15
-	obGold,     // 16
-	obMoonStone,
-	obBag,
-	obSunStone, // 19
-	obHorn, // 20
-	obSword,
-
-	obMaskOfDeath,
-	obMaskOfBonding,
-	obMaskOfBirth,
-
-	obEyeInTheStorm,    // 25
-	obSkyHammer,
-	obFireInTheClouds,
-	obWithinAndWithout,
-	obEyeInTheCyclone,
-	obRiverThatWinds,
-
-	obTrumpet,      // 31
-	obUnused32,
-	obDrum,
-	obUnused34,
-	obUnused35,
-	obRing,
-
-	obTablet1,      // 37 is 1st plaque, 6 total
-	obTablet2,
-	obTablet3,  // 39
-	obTablet4,
-	obTablet5,
-	obTablet6
-};
-}
-
-enum PERSO {
-	PER_ROI = 0,
-	PER_DINA,       // 0x12
-	PER_THOO,       // 0x24
-	PER_MONK,       // 0x36
-	PER_BOURREAU,   // 0x48
-	PER_MESSAGER,   // 0x5A
-	PER_MANGO,      // 0x6C
-	PER_EVE,        // 0x7E
-	PER_AZIA,       // 0x90
-	PER_MAMMI,      // 0xA2
-	PER_MAMMI_1,    // 0xB4
-	PER_MAMMI_2,    // 0xC6
-	PER_MAMMI_3,    // 0xD8
-	PER_MAMMI_4,    // 0xEA
-	PER_MAMMI_5,    // 0xFC
-	PER_MAMMI_6,    // 0x10E
-	PER_BAMBOO,     // 0x120
-	PER_KABUKA,     // 0x132
-	PER_GARDES,     // 0x144
-	PER_UNKN_156,   // 0x156
-	PER_FISHER,     // 0x168
-	PER_MORKUS,     // 0x17A
-	PER_UNKN_18C,   // 0x18C
-	PER_UNKN_19E,   // 0x19E
-	PER_UNKN_1B0,   // 0x1B0
-	PER_UNKN_1C2,   // 0x1C2
-	PER_UNKN_1D4,   // 0x1D4
-	PER_UNKN_1E6,   // 0x1E6
-	PER_UNKN_1F8,   // 0x1F8
-	PER_UNKN_20A,   // 0x20A
-	PER_UNKN_21C,   // 0x21C
-	PER_UNKN_22E,   // 0x22E
-	PER_UNKN_240,   // 0x240
-	PER_UNKN_252,   // 0x252
-	PER_UNKN_264,   // 0x264
-	PER_UNKN_276,   // 0x276
-	PER_UNKN_288,   // 0x288
-	PER_UNKN_29A,   // 0x29A
-	PER_UNKN_2AC,   // 0x2AC
-	PER_UNKN_2BE,   // 0x2BE
-	PER_UNKN_2D0,   // 0x2D0
-	PER_UNKN_2E2,   // 0x2E2
-	PER_UNKN_2F4,   // 0x2F4
-	PER_UNKN_306,   // 0x306
-	PER_UNKN_318,   // 0x318
-	PER_UNKN_32A,   // 0x32A
-	PER_UNKN_33C,   // 0x33C
-	PER_UNKN_34E,   // 0x34E
-	PER_UNKN_360,   // 0x360
-	PER_UNKN_372,   // 0x372
-	PER_UNKN_384,   // 0x384
-	PER_UNKN_396,   // 0x396
-	PER_UNKN_3A8,   // 0x3A8
-	PER_UNKN_3BA,   // 0x3BA
-	PER_UNKN_3CC,   // 0x3CC
-	PER_UNKN_3DE,   // 0x3DE
-	PER_UNKN_3F0,   // 0x3F0
-	PER_UNKN_402    // 0x402
-};
-
-namespace PersonId {
-enum PersonId {
-	pidGregor = 0,                          // The King
-	pidDina,                                // Pink dino
-	pidTau,                                 // Late grandpa
-	pidMonk,                                // Old wizard
-	pidJabber,                              // Executioner
-	pidEloi,                                // Evergreen ptero
-	pidMungo,                               // Dina's husband
-	pidEve,                                 // Blonde girl
-	pidShazia,                              // Big boobs sis
-	pidLeadersBegin,                        // 9
-	pidChongOfChamaar = pidLeadersBegin,    // Dogface
-	pidKommalaOfKoto,                       // Clones
-	pidUlanOfUlele,                         // Shaman
-	pidCabukaOfCantura,                     // Stone people
-	pidMarindaOfEmbalmers,                  // Gods
-	pidFuggOfTamara,                        // Boar-like
-	pidThugg,                               // Bodyguard
-	pidNarrator,                            // 16, Old Eloi, also BGM
-	pidNarrim,                              // Sea snake
-	pidMorkus,                              // Vicious tyran
-	pidDinosaur,                            // different species of friendly dino
-	pidEnemy                                // different species of enemy dino
-};
-}
-
-// person in room mask bits
-namespace PersonMask {
-enum PersonMask {
-	pmGregor = 1,
-	pmDina   = 2,
-	pmTau    = 4,
-	pmMonk   = 8,
-	pmJabber = 0x10,
-	pmEloi   = 0x20,
-	pmMungo  = 0x40,
-	pmEve    = 0x80,
-	pmShazia = 0x100,
-	pmLeader = 0x200,   // valley tribe leader
-	pmThugg  = 0x400,
-	pmQuest  = 0x800,   // special quest person
-	pmDino   = 0x1000,
-	pmEnemy  = 0x2000,
-	pmMorkus = 0x4000
-};
-}
-
-namespace PersonFlags {
-enum PersonFlags {
-	pfType0 = 0,
-	pftTyrann,
-	pfType2,
-	pfType3,
-	pfType4,
-	pfType5,
-	pfType6,
-	pfType7,
-	pfType8,
-	pftMosasaurus,
-	pftTriceraptor,
-	pftVelociraptor,
-	pfType12,
-	pfType13,
-	pfType14,
-	pfType15,
-	pfTypeMask = 0xF,
-	pf10 = 0x10,
-	pf20 = 0x20,
-	pfInParty = 0x40,
-	pf80 = 0x80
-};
-}
-
-#pragma pack(push, 1)
-struct perso_t {
-	unsigned short  roomNum;    // room this person currently in
-	unsigned short  actionId;   // TODO: checkme
-	unsigned short  party;      // party bit mask
-	unsigned char   id;         // character
-	unsigned char   flags;      // flags and kind
-	unsigned char   roomBankIdx;// index in kPersoRoomBankTable for specific room banks
-	unsigned char   bank;       // sprite bank
-	unsigned short  items;      // inventory
-	unsigned short  powers;     // obj of power bitmask
-	unsigned char   targetLoc;  // For party member this is mini sprite index
-	unsigned char   lastLoc;    // For party member this is mini sprite x offset
-	unsigned char   speed;      // num ticks per step
-	unsigned char   steps;      // current ticks
-};
-typedef struct perso_t perso_t;
-
-struct phase_t {
-	short           id;
-	void (EdenGameImpl::*disp)();
-};
-typedef struct phase_t phase_t;
-
-namespace ObjectFlags {
-enum ObjectFlags {
-	ofFlag1 = 1,
-	ofInHands = 2       // Currently holding this object in hands
-};
-}
-
-#define MAX_OBJECTS 42
-struct object_t {
-	unsigned char   id;
-	unsigned char   flags;
-	int             locations;      // index in kObjectLocations
-	short           itemMask;
-	short           powerMask;          // object of power bitmask
-	short           count;
-};
-typedef struct object_t object_t;
-
-namespace DialogFlags {
-enum DialogFlags {
-	df20 = 0x20,
-	dfRepeatable = 0x40,
-	dfSpoken = 0x80
-};
-}
-
-namespace DialogType {
-enum DialogType {
-	dtTalk = 0,
-	dtDinoAction,
-	dtDinoItem,
-	dtItem,
-	dtEvent,
-	dtInspect,
-	dtHint
-};
-}
-
-struct dial_t {
-	char        flags;          // 0-3 - action index, 4 - highest bit of contidion index, rest is DialogFlags
-	char        condNumLow;     // condition index low bits
-	char        textCondHiMask; // 0-1 text index hi bits, 2-5 - perso mask num, 6-7 condition index hi bits
-	char        textNumLow;     // text line index low bits
-};
-typedef struct dial_t dial_t;
-
-struct tape_t {
-	short       textNum;
-	perso_t     *perso;
-	short       party;
-	short       roomNum;
-	short       bgBankNum;
-	dial_t      *dialog;
-};
-typedef struct tape_t tape_t;
-
-struct suiveur_t {      // Characters on Mirror screen
-	char        id;         // character
-	char        image;      // sprite number
-	short       sx;
-	short       sy;
-	short       ex;
-	short       ey;
-	short       bank;
-	short       ff_C;
-	short       ff_E;
-};
-typedef struct suiveur_t suiveur_t;
-
-struct icon_t {
-	short       sx;
-	short       sy;
-	short       ex;
-	short       ey;
-	unsigned short  cursor_id;          // & 0x8000 - inactive/hidden
-	unsigned int    action_id;
-	unsigned int    object_id;
-};
-typedef struct icon_t icon_t;
-
-struct goto_t {
-	unsigned char   areaNum;    // target area
-	unsigned char   curAreaNum; // current area
-	unsigned char   departVid;
-	unsigned char   travelTime;     // time to skip while in travel
-	unsigned char   arriveVid;
-};
-typedef struct goto_t goto_t;
-
-namespace RoomFlags {
-enum RoomFlags {
-	rf01 = 1,
-	rf02 = 2,
-	rf04 = 4,
-	rf08 = 8,
-	rfPanable = 0x10,
-	rfHasCitadel = 0x20,
-	rf40 = 0x40,
-	rf80 = 0x80
-};
-}
-
-struct room_t {
-	unsigned char   ff_0;
-	unsigned char   exits[4];   //TODO: signed?
-	unsigned char   flags;
-	unsigned short  bank;
-	unsigned short  party;
-	unsigned char   level;      // Citadel level
-	unsigned char   video;
-	unsigned char   location;
-	unsigned char   background; // bg/mirror image number (relative)
-};
-typedef struct room_t room_t;
-
-namespace AreaFlags {
-enum AreaFlags {
-	afFlag1 = 1,
-	afFlag2 = 2,
-	afFlag4 = 4,
-	afFlag8 = 8,
-	afGaveGold = 0x10,
-	afFlag20 = 0x20,
-
-	HasTriceraptors = 0x100,
-	HasVelociraptors = 0x200,
-	HasTyrann = 0x400,
-
-	TyrannSighted = 0x4000,
-	afFlag8000 = 0x8000
-};
-}
-
-namespace AreaType {
-enum AreaType {
-	atCitadel = 1,
-	atValley = 2,
-	atCave = 3
-};
-}
-
-struct area_t {
-	unsigned char   num;
-	unsigned char   type;
-	unsigned short  flags;
-	unsigned short  firstRoomIndex;
-	unsigned char   citadelLevel;
-	unsigned char   salNum;
-	room_t          *citadelRoom;
-	short           visitCount;
-};
-typedef struct area_t area_t;
-
-namespace ValleyNews {
-enum ValleyNews {
-	vnAreaMask = 0xF,
-
-	vnTriceraptorsIn = 0x10,
-	vnVelociraptorsIn = 0x20,
-	vnTyrannIn = 0x30,
-	vnTyrannLost = 0x40,
-	vnCitadelLost = 0x50,
-	vnVelociraptorsLost = 0x60,
-
-	vnFree = 0,
-	vnHidden = 0x80,
-	vnEnd = 0xFF
-};
-}
-
-namespace DisplayFlags {
-enum DisplayFlags {
-	dfFlag1 = 1,
-	dfFlag2 = 2,
-	dfMirror = 4,
-	dfPerson = 8,
-	dfFresques = 0x10,
-	dfPanable = 0x20,
-	dfFlag40 = 0x40,
-	dfFlag80 = 0x80
-};
-}
-
-namespace DrawFlags {
-enum DrawFlags {
-	drDrawInventory = 1,
-	drDrawFlag2 = 2,
-	drDrawTopScreen = 4,
-	drDrawFlag8 = 8,
-	drDrawMenu = 0x10,
-	drDrawFlag20 = 0x20
-};
-}
-
-namespace MenuFlags {
-enum MenuFlags {
-	mfFlag1 = 1,
-	mfFlag2 = 2,
-	mfFlag4 = 4,
-	mfFlag8 = 8,
-	mfFlag10 = 0x10
-};
-}
-
-namespace MusicType {
-enum MusicType {  //TODO: same as DialogType?
-	mtDontChange = 0,
-	mtNormal = 1,
-	mt2 = 2,
-	mtEvent = 4,
-	mtFF = 0xFF
-};
-}
-
-namespace EventType {
-enum EventType {
-	etEvent1 = 1,
-	etEvent2 = 2,
-	etEvent3 = 3,
-	etEvent4 = 4,
-	etEvent5 = 5,
-	etEvent6 = 6,
-	etEvent7 = 7,
-	etEvent8 = 8,
-	etEvent9 = 9,
-	etEventB = 11,
-	etEventC = 12,
-	etEventD = 13,
-	etEventE = 14,
-	etEventF = 15,
-	etEvent10 = 16,
-	etEvent12 = 18,
-	etGotoArea = 0x80   // + area id
-};
-}
-
-namespace GameFlags {
-enum GameFlags {
-	gfMummyOpened = 1,
-	gfFlag2 = 2,
-	gfFlag4 = 4,
-	gfFlag8 = 8,
-	gfFlag10 = 0x10,
-	gfFlag20 = 0x20,
-	gfFlag40 = 0x40,
-	gfFlag80 = 0x80,
-	gfFlag100 = 0x100,
-	gfFlag200 = 0x200,
-	gfFlag400 = 0x400,
-	gfPrismAndMonk = 0x800,
-	gfFlag1000 = 0x1000,
-	gfFlag2000 = 0x2000,
-	gfFlag4000 = 0x4000,
-	gfFlag8000 = 0x8000
-};
-}
-
-struct global_t {
-	unsigned char   areaNum;
-	unsigned char   areaVisitCount;
-	unsigned char   menuItemIdLo;
-	unsigned char   menuItemIdHi;   //TODO: pad?
-	unsigned short  randomNumber;   //TODO: this is randomized in pc ver and used by some conds. always zero on mac
-	unsigned short  gameTime;
-	unsigned short  gameDays;
-	unsigned short  chrono;
-	unsigned short  eloiDepartureDay;
-	unsigned short  roomNum;        // current room number
-	unsigned short  newRoomNum;     // target room number selected on world map
-	unsigned short  phaseNum;
-	unsigned short  metPersonsMask1;
-	unsigned short  party;
-	unsigned short  partyOutside;
-	unsigned short  metPersonsMask2;
-	unsigned short  __UNUSED_1C;    //TODO: write-only?
-	unsigned short  phaseActionsCount;
-	unsigned short  curAreaFlags;
-	unsigned short  curItemsMask;
-	unsigned short  curPowersMask;
-	unsigned short  curPersoItems;
-	unsigned short  curPersoPowers;
-	unsigned short  wonItemsMask;
-	unsigned short  wonPowersMask;
-	unsigned short  stepsToFindAppleFast;
-	unsigned short  stepsToFindAppleNormal;
-	unsigned short  roomPersoItems; //TODO: write-only?
-	unsigned short  roomPersoPowers;    //TODO: write-only?
-	unsigned short  gameFlags;
-	unsigned short  curVideoNum;
-	unsigned short  morkusSpyVideoNum1; //TODO: pad?
-	unsigned short  morkusSpyVideoNum2; //TODO: pad?
-	unsigned short  morkusSpyVideoNum3; //TODO: pad?
-	unsigned short  morkusSpyVideoNum4; //TODO: pad?
-	unsigned char   newMusicType;
-	unsigned char   ff_43;
-	unsigned char   videoSubtitleIndex;
-	unsigned char   partyInstruments;   // &1 - Bell for Monk, &2 - Drum for Thugg
-	unsigned char   monkGotRing;
-	unsigned char   chrono_on;
-	unsigned char   curRoomFlags;
-	unsigned char   endGameFlag;
-	unsigned char   last_info;
-	unsigned char   autoDialog;
-	unsigned char   worldTyrannSighted;
-	unsigned char   ff_4D;
-	unsigned char   ff_4E;
-	unsigned char   worldGaveGold;
-	unsigned char   worldHasTriceraptors;
-	unsigned char   worldHasVelociraptors;
-	unsigned char   worldHasTyrann;
-	unsigned char   ff_53;
-	unsigned char   ff_54;
-	unsigned char   ff_55;  //TODO: pad?
-	unsigned char   ff_56;
-	unsigned char   textToken1;
-	unsigned char   textToken2; //TODO: pad?
-	unsigned char   eloiHaveNews;
-	unsigned char   dialogFlags;
-	unsigned char   curAreaType;
-	unsigned char   curCitadelLevel;
-	unsigned char   newLocation;
-	unsigned char   prevLocation;
-	unsigned char   curPersoFlags;
-	unsigned char   ff_60;
-	unsigned char   eventType;
-	unsigned char   ff_62;  //TODO: pad?
-	unsigned char   curObjectId;
-	unsigned char   curObjectFlags;
-	unsigned char   ff_65;  //TODO: pad?
-	unsigned char   roomPersoType;
-	unsigned char   roomPersoFlags;
-	unsigned char   narratorSequence;
-	unsigned char   ff_69;
-	unsigned char   ff_6A;
-	unsigned char   fresqNumber;
-	unsigned char   ff_6C;  //TODO: pad?
-	unsigned char   ff_6D;  //TODO: pad?
-	unsigned char   labyrinthDirections;
-	unsigned char   labyrinthRoom;
-	void            *__UNUSED_70;   //TODO: pad?
-	dial_t          *dialog_ptr;
-	tape_t          *tape_ptr;
-	dial_t          *next_dialog_ptr;
-	dial_t          *narrator_dialog_ptr;
-	dial_t          *last_dialog_ptr;
-	icon_t          *nextRoomIcon;
-	unsigned char   *phraseBufferPtr;
-	unsigned char   *__UNUSED_90;   //TODO: write-only?
-	unsigned char   *__UNUSED_94;   //TODO: write-only?
-	room_t          *room_ptr;
-	area_t          *area_ptr;
-	area_t          *last_area_ptr;
-	area_t          *cur_area_ptr;
-	room_t          *cita_area_firstRoom;
-	perso_t         *perso_ptr;
-	perso_t         *room_perso;
-	unsigned char   last_info_idx;
-	unsigned char   next_info_idx;
-	unsigned char   *persoSpritePtr;
-	unsigned char   *persoSpritePtr2;
-	unsigned char   *curPersoAnimPtr;
-	unsigned char   *ff_C2; //TODO: image desc arr
-	short           iconsIndex;
-	short           curObjectCursor;    // TODO: useless?
-	short           ff_CA;
-	short           __UNUSED_CC;        //TODO: unused/pad
-	short           perso_img_bank; //TODO: unsigned?
-	unsigned short  roomImgBank;
-	unsigned short  persoBackgroundBankIdx;
-	unsigned short  ff_D4;  //TODO: unsigned?
-	unsigned short  fresqWidth;
-	unsigned short  fresqImgBank;
-	unsigned short  ff_DA;  //TODO: pad?
-	unsigned short  ff_DC;  //TODO: pad?
-	unsigned short  room_x_base;
-	unsigned short  ff_E0;  //TODO: pad?
-	unsigned short  dialogType;
-	unsigned short  ff_E4;  //TODO: pad?
-	unsigned short  currentMusicNum;
-	short           textNum;
-	unsigned short  travelTime;
-	unsigned short  ff_EC;  //TODO: pad?
-	unsigned char   displayFlags;
-	unsigned char   oldDisplayFlags;
-	unsigned char   drawFlags;
-	unsigned char   ff_F1;
-	unsigned char   ff_F2;
-	unsigned char   menuFlags;
-	unsigned char   ff_F4;  //TODO: write-only?
-	unsigned char   ff_F5;
-	unsigned char   ff_F6;
-	unsigned char   ff_F7;
-	unsigned char   ff_F8;  //TODO: pad?
-	unsigned char   ff_F9;  //TODO: pad?
-	unsigned char   ff_FA;  //TODO: pad?
-	unsigned char   animationFlags;
-	unsigned char   __UNUSED_FC;    //TODO: pad?
-	unsigned char   giveobj1;
-	unsigned char   giveobj2;
-	unsigned char   giveobj3;
-	unsigned char   ff_100;
-	unsigned char   roomVidNum;
-	unsigned char   ff_102;
-	unsigned char   ff_103;
-	unsigned char   roomBgBankNum;
-	unsigned char   valleyVidNum;
-	unsigned char   updatePaletteFlag;
-	unsigned char   inventoryScrollPos;
-	unsigned char   obj_count;
-	unsigned char   ff_109; //TODO: write-only?
-	unsigned char   textBankIndex;
-	unsigned char   pref_language;
-	unsigned char   pref_10C[2];    //TODO: volume
-	unsigned char   pref_10E[2];    // -//-
-	unsigned char   pref_110[2];    // -//-
-	unsigned char   cita_area_num;
-	unsigned char   ff_113;
-	unsigned char   lastSalNum;
-	unsigned char   save_end;
-	short           textWidthLimit;
-	unsigned char   numGiveObjs;
-	unsigned char   ff_119;     // unused
-};
-typedef struct global_t global_t;
-
-struct pakfile_t {
-	char            name[16];
-	long            size;
-	long            offs;
-	char            flag;
-};
-typedef struct pakfile_t pakfile_t;
-
-struct pak_t {
-	unsigned short  count;
-	pakfile_t       files[10];
-};
-typedef struct pak_t pak_t;
-#pragma pack(pop)
-
-struct cita_t {
-	short   ff_0;
-	short   ff_2[8 * 2];
-};
-typedef struct cita_t cita_t;
-
-/////////////// vars
-
-suiveur_t suiveurs_list[] = {
-//            char,                 X,  sx, sy,  ex,  ey,bank,
-	{ PersonId::pidGregor,          5, 211,  9, 320, 176, 228,   0,  0 },
-	{ PersonId::pidEloi,            4, 162, 47, 223, 176, 228, 112, 78 },
-	{ PersonId::pidDina,            3,  55,  0, 172, 176, 228,  90, 16 },
-	{ PersonId::pidChongOfChamaar,  4,   0,  5, 114, 176, 229,   0, 16 },
-	{ PersonId::pidKommalaOfKoto,   3,   0, 15, 102, 176, 229,   0, 16 },
-	{ PersonId::pidUlanOfUlele,     1,   0,  0, 129, 176, 230,   0, 16 },
-	{ PersonId::pidCabukaOfCantura, 2,   0,  0, 142, 176, 230,   0, 16 },
-	{ PersonId::pidFuggOfTamara,    0,   0, 17, 102, 176, 230,   0, 16 },
-	{ PersonId::pidJabber,          2,   0,  6, 134, 176, 228,   0, 16 },
-	{ PersonId::pidShazia,          1,  90, 17, 170, 176, 228,  50, 22 },
-	{ PersonId::pidThugg,           0, 489,  8, 640, 176, 228, 160, 24 },
-	{ PersonId::pidMungo,           5, 361,  0, 517, 176, 229,   0, 16 },
-	{ PersonId::pidMonk,            0, 419, 22, 569, 176, 229, 100, 30 },
-	{ PersonId::pidEve,             1, 300, 28, 428, 176, 229,   0, 38 },
-	{ -1,                          -1,  -1, -1,  -1,  -1,  -1,  -1, -1 }
-};
-
-
-/*
-  Labyrinth of Mo
-
-  | | | | | | | |
-
-*/
-
-enum {
-	LAB_N = 1,
-	LAB_E,
-	LAB_S,
-	LAB_W
-};
-
-#define LAB(toCrypt, toThrone)  \
-	(((LAB_##toCrypt) << 4) | (LAB_##toThrone))
-
-unsigned char kLabyrinthPath[] = {
-// each nibble tells wich direction to choose to exit the labyrinth
-	0x11, 0x11, 0x11, 0x22, 0x33, 0x55, 0x25, 0x44, 0x25, 0x11, 0x11, 0x11,
-	0x11, 0x35, 0x55, 0x45, 0x45, 0x44, 0x44, 0x34, 0x44, 0x34, 0x32, 0x52,
-	0x33, 0x23, 0x24, 0x44, 0x24, 0x22, 0x54, 0x22, 0x54, 0x54, 0x44, 0x22,
-	0x22, 0x42, 0x45, 0x22, 0x42, 0x45, 0x35, 0x11, 0x44, 0x34, 0x52, 0x11,
-	0x44, 0x32, 0x55, 0x11, 0x11, 0x33, 0x11, 0x11, 0x53, 0x11, 0x11, 0x53,
-	0x54, 0x24, 0x11, 0x22, 0x25, 0x33, 0x53, 0x54, 0x23, 0x44
-};
-
-#undef LAB
-
-char kDinoSpeedForCitaLevel[16] = { 1, 2, 3, 4, 4, 5, 6, 7, 8, 9 };
-
-char kTabletView[] = {          //TODO: make as struct?
-	// opposite tablet id, video id
-	Objects::obUnused10, 83,
-	Objects::obUnused10, 84,
-	Objects::obTablet4, 85,
-	Objects::obTablet3, 86,
-	Objects::obTablet6, 87,
-	Objects::obTablet5, 85
-};
-
-// special character backgrounds for specific rooms
-char kPersoRoomBankTable[] = {
-	// first entry is default bank, then pairs of [roomNum, bankNum], terminated by -1
-	0,  3, 33, -1,
-	21, 17, 35, -1,
-	0,  2, 36, -1,
-	22,  9, 38,  3, 39, -1,
-	23,  8, 40, -1,
-	0,  3, 41,  7, 42, -1,
-	25, -1,
-	27, 17, 45, -1,
-	28, 26, 46, -1,
-	29, 51, 48, -1,
-	30, 53, 49, -1,
-	0, 27, 50, -1,
-	32, 17, 51, -1,
-	52,  2, 52, -1,
-	-3,  3, -3, -1,
-	31, -1,
-	24,  6, 43, -1,
-	47, -1,
-	0,  2, 64, -1,
-	54,  3, 54, -1,
-	27, -1,
-	26, 17, 45, -1
-};
-
-// area transition descriptors
-goto_t gotos[] = {
-// area, oldarea, vid, time, valleyVid
-	{  0,  1,   0,  2,  20 },
-	{  0,  1, 162,  3, 168 },
-	{  0,  2,   0,  2,  21 },
-	{  0,  6,   0,  3, 108 },
-	{  0,  9, 151,  3,   0 },
-	{  0,  7, 106,  2, 101 },
-	{  0, 10,  79,  3, 102 },
-	{  0, 12,   0,  3,   0 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  1,  3,  58,  2, 104 },
-	{  1,  4, 100,  4, 104 },
-	{  1,  5, 107,  6, 104 },
-	{  1,  6, 155,  8, 104 },
-	{  1,  7, 165,  6, 104 },
-	{  1,  8, 169,  6, 104 },
-	{  1, 10, 111,  2, 104 },
-	{  1, 11, 164,  4, 104 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  1,  3, 161,  3, 102 },
-	{  1,  4, 163,  6, 102 },
-	{  1,  5, 157,  9, 102 },
-	{  1,  9, 160,  9, 102 },
-	{  1, 10,  79,  3, 102 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  1,  3,   0,  3, 153 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  3,  1, 154,  2, 103 },
-	{  3,  4, 100,  2, 103 },
-	{  3,  5, 107,  4, 103 },
-	{  3,  6, 155,  6, 103 },
-	{  3,  7, 165,  8, 103 },
-	{  3,  8, 169,  6, 103 },
-	{  3, 10, 111,  4, 103 },
-	{  3, 11, 164,  6, 103 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  3,  1, 162,  3,  22 },
-	{  3,  4, 163,  6,  22 },
-	{  3,  5, 157,  9,  22 },
-	{  3,  9, 160,  9,  22 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  3,  1,   0,  3, 166 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  4,  1, 154,  4,  51 },
-	{  4,  3,  58,  2,  51 },
-	{  4,  5, 107,  2,  51 },
-	{  4,  6, 155,  4,  51 },
-	{  4,  7, 165,  6,  51 },
-	{  4,  8, 169,  8,  51 },
-	{  4, 10, 111,  6,  51 },
-	{  4, 11, 164,  8,  51 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  4,  1, 162,  3, 109 },
-	{  4,  3, 161,  6, 109 },
-	{  4,  5, 157,  9, 109 },
-	{  4,  9, 160,  9, 109 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  5,  1, 154,  6,  33 },
-	{  5,  3,  58,  4,  33 },
-	{  5,  4, 100,  2,  33 },
-	{  5,  6, 155,  2,  33 },
-	{  5,  7, 165,  4,  33 },
-	{  5,  8, 169,  8,  33 },
-	{  5, 10, 111,  8,  33 },
-	{  5, 11, 164,  8,  33 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  5,  1, 162,  3,  99 },
-	{  5,  3, 161,  6,  99 },
-	{  5,  4, 163,  9,  99 },
-	{  5,  9, 160,  9,  99 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  9,  1, 162,  3, 167 },
-	{  9,  3, 161,  6, 167 },
-	{  9,  4, 163,  9, 167 },
-	{  9,  5, 157,  9, 167 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  6,  1, 154,  8, 105 },
-	{  6,  3,  58,  6, 105 },
-	{  6,  4, 100,  4, 105 },
-	{  6,  5, 107,  2, 105 },
-	{  6,  7, 165,  2, 105 },
-	{  6,  8, 169, 10, 105 },
-	{  6, 10, 111,  6, 105 },
-	{  6, 11, 164,  8, 105 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  7,  1, 154,  4, 158 },
-	{  7,  3,  58,  6, 158 },
-	{  7,  4, 100,  6, 158 },
-	{  7,  5, 107,  4, 158 },
-	{  7,  6, 155,  2, 158 },
-	{  7,  8, 169,  8, 158 },
-	{  7, 10, 111,  4, 158 },
-	{  7, 11, 164,  6, 158 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  8,  1, 154,  2, 159 },
-	{  8,  3,  58,  4, 159 },
-	{  8,  4, 100,  6, 159 },
-	{  8,  5, 107,  8, 159 },
-	{  8,  6, 155, 10, 159 },
-	{  8,  7, 165,  8, 159 },
-	{  8, 10, 111,  6, 159 },
-	{  8, 11, 164,  4, 159 },
-	{ -1, -1,  -1, -1,  -1 },
-	{ 10,  1, 154,  2,  77 },
-	{ 10,  3,  58,  4,  77 },
-	{ 10,  4, 100,  6,  77 },
-	{ 10,  5, 107,  8,  77 },
-	{ 10,  6, 155,  6,  77 },
-	{ 10,  7, 165,  4,  77 },
-	{ 10,  8, 169,  6,  77 },
-	{ 10, 11, 164,  4,  77 },
-	{ -1, -1,  -1, -1,  -1 },
-	{ 11,  1, 154,  2,  80 },
-	{ 11,  3,  58,  4,  80 },
-	{ 11,  4, 100,  6,  80 },
-	{ 11,  5, 107,  8,  80 },
-	{ 11,  6, 155,  8,  80 },
-	{ 11,  7, 165,  6,  80 },
-	{ 11,  8, 169,  2,  80 },
-	{ 11, 10, 111,  4,  80 },
-	{ -1, -1,  -1, -1,  -1 },
-	{ 12,  1, 154,  8,  56 },
-	{ 12,  3,  58,  4,  56 },
-	{ 12,  4, 100,  4,  56 },
-	{ 12,  5, 107,  6,  56 },
-	{ 12,  6, 155,  8,  56 },
-	{ 12,  7, 165, 10,  56 },
-	{ 12,  8, 169,  4,  56 },
-	{ 12, 10, 111, 10,  56 },
-	{ 12, 11, 164,  6,  56 },
-	{ -1, -1,  -1, -1,  -1 }
-};
-
-#define SUB_LINE(start, end) \
-	(start), (end) | 0x8000
-
-short tab_2D24C[] = {
-	SUB_LINE(68, 120),
-	123, 32964,
-	199, 33042,
-	276, 33138,
-	799, 33653,
-	888, 33708,
-	947, 33768,
-	1319, 34146,
-	1380, 34208,
-	1854, 34666,
-	1900, 34728,
-	2116, 34952,
-	2186, 35020,
-	2254, 35088,
-	3038, 35862,
-	3096, 35928,
-	-1
-};
-
-short tab_2D28E[] = {
-	99, 32923,
-	157, 33024,
-	-1
-};
-
-short tab_2D298[] = {
-	106, 32941,
-	175, 33012,
-	246, 33118,
-	352, 33235,
-	-1
-};
-
-short tab_2D2AA[] = {
-	126, 32944,
-	178, 33035,
-	269, 33110,
-	344, 33166,
-	400, 33226,
-	460, 33326,
-	-1
-};
-
-short tab_2D2C4[] = {
-	101, 32981,
-	215, 33121,
-	355, 33223,
-	457, 33286,
-	520, 33428,
-	662, 33536,
-	-1
-};
-#undef SUB_LINE
-
-object_t objects[] = {
-	//id,fl,loc,masklow,maskhi,ct
-	{  1, 0,  3,      1,     0, 0},     // Eve's Way Stone
-	{  2, 0,  3,      2,     0, 0},     // Thau's Seashell
-	{  3, 0,  3,      4,     0, 0},     // Talisman of bravery
-	{  4, 0,  3,      8,     0, 0},     // An old tooth. Very old! Whoever lost it most certainly has no further use for it!
-	{  5, 0,  0,   0x10,     0, 0},     // Prism
-	{  6, 0,  3,      0,     0, 0},     // Flute
-	{  7, 0,  3, 0x4000,     0, 0},     // Apple
-	{  8, 0,  4, 0x1000,     0, 0},     // Egg of Destiny
-	{  9, 0,  3,  0x800,     0, 0},     // Root
-	{ 10, 0,  3,      0,     0, 0},     // ???
-	{ 11, 0,  6,      0,     0, 0},     // Mushroom
-	{ 12, 0, 13,      0,     0, 0},     // Poisonous Mushroom
-	{ 13, 0,  2,  0x400,     0, 0},     // Graa's Knife
-	{ 14, 0, 22,      0,     0, 0},     // Empty Nest
-	{ 15, 0, 26,      0,     0, 0},     // Full Nest
-	{ 16, 0, 33,   0x20,     0, 0},     // Gold
-	{ 17, 0,  3,      0,     0, 0},     // Sign of Shadow Mistress  (moon stone)
-	{ 18, 0,  3,      0,     0, 0},     // Sign of Mother of all    (bag of soil)
-	{ 19, 0, 40,      0,     0, 0},     // Sign of the life-giving  (sun star)
-	{ 20, 0, 20,  0x200,     0, 0},     // King's Horn
-	{ 21, 0,  3,      0,     0, 0},     // Golden Sword of Mashaar
-	// Masks
-	{ 22, 0,  3,   0x40,     0, 0},     // Mask of Death
-	{ 23, 0,  3,   0x80,     0, 0},     // Mask of Bonding
-	{ 24, 0,  3,  0x100,     0, 0},     // Mask of Birth
-	// Objects of power
-	{ 25, 0,  3,      0,     1, 0},     // Eye in the Storm
-	{ 26, 0,  3,      0,     2, 0},     // Sky Hammer
-	{ 27, 0,  3,      0,     4, 0},     // Fire in the Clouds
-	{ 28, 0,  3,      0,     8, 0},     // Within and Without
-	{ 29, 0,  3,      0,  0x10, 0},     // Eye in the Cyclone
-	{ 30, 0,  3,      0,  0x20, 0},     // River that Winds
-	// Musical instruments
-	{ 31, 0,  3,      0,  0x40, 0},     // Trumpet
-	{ 32, 0,  3,      0,  0x80, 0},     // -- unused (but still has a dialog line)
-	{ 33, 0,  3,      0, 0x100, 0},     // Drum
-	{ 34, 0,  3,      0, 0x200, 0},     // -- unused (but still has a dialog line)
-	{ 35, 0,  3,      0, 0x400, 0},     // -- unused (but still has a dialog line)
-	{ 36, 0,  3,      0, 0x800, 0},     // Ring
-	// Tablets
-	{ 37, 0,  3,      0,     0, 0},     // Tablet #1 (Mo)
-	{ 38, 0, 42, 0x2000,     0, 0},     // Tablet #2 (Morkus' Lair)
-	{ 39, 0,  3,      0,     0, 0},     // Tablet #3 (White Arch?)
-	{ 40, 0,  3,      0,     0, 0},     // Tablet #4
-	{ 41, 0,  3,      0,     0, 0},     // Tablet #5
-	{ 42, 0,  3, 0x8000,     0, 0}      // Tablet #6 (Castra)
-};
-
-short kObjectLocations[100] = {
-	0x112, -1,
-	0x202, -1,
-	0x120, -1,
-	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
-	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
-	0, -1,
-	0x344, 0x53A, 0x831, -1,
-	0x331, 0x420, 0x54B, 0x637, 0x716, 0x840, -1,
-	0x834A, 0x8430, 0x8531, 0x644, 0x745, 0x838, -1,
-	0x510, -1,
-	0xC04, -1,
-	-1
-};
-
-perso_t kPersons[] = {
-	// room, aid, party mask,                            id,                                            flags,  X,bank,X, X,sprId,sprX,speed, X
-	{ 0x103, 230, PersonMask::pmGregor, PersonId::pidGregor            ,                                                0,  0,  1, 0, 0,  0,   0, 0, 0 },
-	{ 0x116, 231, PersonMask::pmDina  , PersonId::pidDina              ,                                                0,  4,  2, 0, 0,  3,   9, 0, 0 },
-	{ 0x202, 232, PersonMask::pmTau   , PersonId::pidTau               ,                                                0,  8,  3, 0, 0,  0,   0, 0, 0 },
-	{ 0x109, 233, PersonMask::pmMonk  , PersonId::pidMonk              ,                                                0, 12,  4, 0, 0,  6,  52, 0, 0 },
-	{ 0x108, 234, PersonMask::pmJabber, PersonId::pidJabber            ,                                                0, 18,  5, 0, 0,  2,   0, 0, 0 },
-	{ 0x103, 235, PersonMask::pmEloi  , PersonId::pidEloi              ,                                                0, 22,  6, 0, 0,  4,  20, 0, 0 },
-	{ 0x301, 236, PersonMask::pmMungo , PersonId::pidMungo             ,                                                0, 28,  8, 0, 0, 11,  45, 0, 0 },
-	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 30, 10, 0, 0,  7,  35, 0, 0 },
-	{ 0x81A, 238, PersonMask::pmShazia, PersonId::pidShazia            ,                                                0, 34, 11, 0, 0,  1,  11, 0, 0 },
-	{ 0x330, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
-	{ 0x41B, 239, PersonMask::pmLeader, PersonId::pidUlanOfUlele       ,                                                0, 46, 15, 0, 0, 13,   0, 0, 0 },
-	{ 0x53B, 239, PersonMask::pmLeader, PersonId::pidKommalaOfKoto     ,                                                0, 42, 14, 0, 0,  9,   0, 0, 0 },
-	{ 0x711, 239, PersonMask::pmLeader, PersonId::pidCabukaOfCantura   ,                                                0, 50, 16, 0, 0, 14,   0, 0, 0 },
-	{ 0xA02, 239, PersonMask::pmLeader, PersonId::pidMarindaOfEmbalmers,                                                0, 54, 17, 0, 0,  0,   0, 0, 0 },
-	{ 0x628, 239, PersonMask::pmLeader, PersonId::pidFuggOfTamara      ,                                                0, 62, 18, 0, 0, 12,   0, 0, 0 },
-	{ 0x801, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
-	{ 0x41B,  10, PersonMask::pmQuest , PersonId::pidUlanOfUlele       , PersonFlags::pfType2                            , 46, 15, 0, 0, 13,   0, 0, 0 },
-	{ 0x711,  11, PersonMask::pmQuest , PersonId::pidCabukaOfCantura   , PersonFlags::pfType2                            , 50, 16, 0, 0, 14,   0, 0, 0 },
-	{ 0x106, 240, PersonMask::pmThugg , PersonId::pidThugg             ,                                                0, 64,  7, 0, 0,  0,  61, 0, 0 },
-	{     0,  13,                    0, PersonId::pidNarrator          ,                                                0, 68, 12, 0, 0,  0,   0, 0, 0 },
-	{ 0x902, 241, PersonMask::pmQuest , PersonId::pidNarrim            ,                                                0, 70, 19, 0, 0,  0,   0, 0, 0 },
-	{ 0xC03, 244, PersonMask::pmMorkus, PersonId::pidMorkus            ,                                                0, 74, 20, 0, 0,  0,   0, 0, 0 },
-	// dinos in each valley
-	{ 0x332, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x329, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x33B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x317, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x320, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType12                           ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x349, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x429, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x43B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x422, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x432, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x522, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x534, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x515, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x533, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x622, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x630, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x643, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x63A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x737, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x739, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x74A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x726, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x842, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pfType8        ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x822, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x828, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x84B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0xB03, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            , 58, 252, 0, 0,  0,   0, 0, 0 },
-	// enemy dinos
-	{ 0x311, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x410, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x51B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x618, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x71B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x81B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{    -1,  -1,                   -1,                              -1,                                               -1, -1, -1, -1, -1, -1,  -1, -1, -1 },
-	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 80,  9, 0, 0,  8,  35, 0, 0 },
-	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 78, 10, 0, 0,  7,  35, 0, 0 }
-};
-
-cita_t cita_list[] = {
-	{
-		1,
-		{
-			163, 182,   0, 0,
-			124, 147, 193, 0,
-			0,   0,   0, 0,
-			0,   0,   0, 0
-		}
-	},
-	{
-		48,
-		{
-			285, 286,   0, 0,
-			287, 288, 284, 0,
-			114, 115,   0, 0,
-			116, 117, 113, 0
-		}
-	},
-	{
-		63,
-		{
-			290, 291,   0, 0,
-			292, 293, 289, 0,
-			119, 120,   0, 0,
-			121, 122, 118, 0
-		}
-	},
-	{
-		95,
-		{
-			295, 296,   0, 0,
-			297, 298, 294, 0,
-			124, 125,   0, 0,
-			126, 127, 123, 0
-		}
-	},
-	{
-		127,
-		{
-			300, 301,   0, 0,
-			302, 303, 299, 0,
-			129, 130,   0, 0,
-			131, 132, 128, 0
-		}
-	},
-	{
-		159,
-		{
-			305, 306,   0, 0,
-			307, 308, 304, 0,
-			134, 135,   0, 0,
-			136, 137, 133, 0
-		}
-	},
-	{
-		255,
-		{
-			310, 311,   0, 0,
-			312, 313, 309, 0,
-			139, 140,   0, 0,
-			141, 142, 138, 0
-		}
-	}
-};
-
-
-short tab_2CB16[] = { 2075, 2080, 2119, -1};
-
-char tab_2CB1E[8][4] = {
-	{ 0x10, 0x81,    1, 0x90},
-	{ 0x90,    1, 0x81, 0x10},
-	{    1, 0x90, 0x10, 0x81},
-	{    1, 0x10, 0x90, 0x81},
-	{    1, 0x90, 0x10, 0x81},
-	{ 0x81, 0x10, 0x90,    1},
-	{ 0x81, 0x10, 0x90,    1},
-	{ 0x81, 0x90,    1, 0x10}
-};
-
-struct prect_t {
-	short   sx, sy, ex, ey;
-};
-typedef struct prect_t prect_t;
-
-prect_t perso_rects[] = {   //TODO: just an array of shorts?
-	{  93,  69, 223, 176},
-	{ 102,  86, 162, 126},
-	{  88, 103, 168, 163},
-	{ 116,  66, 192, 176},
-	{ 129,  92, 202, 153},
-	{  60,  95, 160, 176},
-	{ 155,  97, 230, 145},
-	{ 100,  77, 156, 145},
-	{ 110,  78, 170, 156},
-	{  84,  76, 166, 162},
-	{  57,  77, 125, 114},
-	{  93,  69, 223, 175},
-	{  93,  69, 223, 176},
-	{  93,  69, 223, 176},
-	{ 154,  54, 245, 138},
-	{ 200,  50, 261, 116},
-	{  70,  84, 162, 176},
-	{ 125, 101, 222, 172},
-	{ 188,  83, 251, 158}
-};
-
-unsigned char tab_persxx[][5] = {   //TODO: struc?
-	{  8, 15, 23, 25, -1},
-	{  0,  9, -1        },
-	{  0,  9, -1        },
-	{  0,  9, -1        },
-	{  0, 13, -1        },
-	{ 16, 21, -1        },
-	{ 11, 20, -1        },
-	{  0, 12, -1        },
-	{  0,  9, -1        },
-	{  0,  9, -1        },
-	{  5, 13, -1        },
-	{ -1                },
-	{  0,  8, -1        },
-	{ -1                },
-	{  0,  7, -1        },
-	{  0,  8, -1        },
-	{  8, 12, -1        },
-	{  0,  5, -1        },
-	{  0,  4, -1        },
-	{ -1                }
-};
-
-area_t kAreasTable[] = {
-	{ Areas::arMo           , AreaType::atCitadel,                           0,   0, 0,  1},
-	{ Areas::arTausCave     , AreaType::atCave   ,                           0, 112, 0,  2},
-	{ Areas::arChamaar      , AreaType::atValley ,                           0, 133, 0,  3},
-	{ Areas::arUluru        , AreaType::atValley ,                           0, 187, 0,  4},
-	{ Areas::arKoto         , AreaType::atValley , AreaFlags::HasVelociraptors, 236, 0,  5},
-	{ Areas::arTamara       , AreaType::atValley ,                           0, 288, 0,  6},
-	{ Areas::arCantura      , AreaType::atValley ,                           0, 334, 0,  7},
-	{ Areas::arShandovra    , AreaType::atValley ,                           0, 371, 0,  8},
-	{ Areas::arNarimsCave   , AreaType::atCave   ,                           0, 115, 0,  9},
-	{ Areas::arEmbalmersCave, AreaType::atCave   ,                           0, 118, 0, 10},
-	{ Areas::arWhiteArch    , AreaType::atCave   ,                           0, 122, 0, 11},
-	{ Areas::arMoorkusLair  , AreaType::atCave   ,                           0, 127, 0, 12}
-};
-
-short tab_2CEF0[64] = {
-	25, 257,  0,   0, 37, 258, 38, 259,  0,   0, 24, 260, 0, 0, 0, 0,
-	0,   0, 53, 265,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
-	39, 261,  0,   0, 40, 262, 62, 263,  0,   0, 63, 264, 0, 0, 0, 0,
-	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0
-};
-
-short tab_2CF70[64] = {
-	65, 266,  0,   0, 66, 267, 67, 268,  0,   0, 68, 269, 0, 0, 0, 0,
-	0,   0, 73, 274,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
-	69, 270,  0,   0, 70, 271, 71, 272,  0,   0, 72, 273, 0, 0, 0, 0,
-	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0,
-};
-
-short kActionCursors[299] = {
-	3, 1, 2, 4, 5, 5, 5, 0, 5, 5,
-	5, 5, 5, 3, 2, 5, 5, 5, 3, 2,
-	4, 5, 7, 7, 4, 5, 5, 0, 0, 0,
-	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-	5, 5, 0, 0, 0, 0, 5, 5, 5, 5,
-	5, 5, 5, 5, 5, 5, 5, 5, 0, 0,
-	0, 0, 5, 5, 5, 5, 5, 5, 5, 5,
-	5, 5, 5, 5, 0, 0, 0, 0, 5, 5,
-	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-	6, 6, 6, 6, 6, 6, 6, 0, 5, 6,
-	6, 1, 6, 6, 0, 0, 6, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-	8, 8, 8, 8, 8, 8, 0, 0, 6, 6,
-	53, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-
-struct cubeface_t {
-	int             tri;
-	char            ff_4;
-	char            ff_5;
-
-	unsigned char   *texptr;
-	unsigned short  *indices;
-	short           *uv;
-};
-typedef struct cubeface_t cubeface_t;
-
-struct cube_t {
-	int             num;
-	cubeface_t      **faces;
-	short           *projection;    // projected XYZ coords
-	short           *vertices;
-};
-typedef struct cube_t cube_t;
-
-float flt_2DF7C = -3400;
-float flt_2DF80 = -3400;
-float flt_2DF84 =   200;
-
-// Cube faces to texture coords mapping
-// each entry is num_polys(6) * num_faces_per_poly(2) * vertex_per_face(3) * uv(2)
-
-short cube_texcoords[3][6 * 2 * 3 * 2] = {
-	{
-		32, 32,  0, 32,  0,  0,
-		32, 32,  0,  0, 32,  0,
-
-		0, 32,  0,  0, 32,  0,
-		0, 32, 32,  0, 32, 32,
-
-		32, 32,  0, 32,  0,  0,
-		32, 32,  0,  0, 32,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		0,  0, 32,  0, 32, 32,
-		0,  0, 32, 32,  0, 32,
-
-		0, 32,  0,  0, 32,  0,
-		0, 32, 32,  0, 32, 32
-	}, {
-		32, 32,  0, 32,  0,  0,
-		32, 32,  0,  0, 32,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		0, 32,  0,  0, 32,  0,
-		0, 32, 32,  0, 32, 32,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0
-	}, {
-		30, 30,  2, 30,  2,  2,
-		30, 30,  2,  2, 30,  2,
-
-		2, 30,  2,  2, 30,  2,
-		2, 30, 30,  2, 30, 30,
-
-		30, 30,  2, 30,  2,  2,
-		30, 30,  2,  2, 30,  2,
-
-		30,  2, 30, 30,  2, 30,
-		30,  2,  2, 30,  2,  2,
-
-		2,  2, 30,  2, 30, 30,
-		2,  2, 30, 30,  2, 30,
-
-		2, 30,  2,  2, 30,  2,
-		2, 30, 30,  2, 30, 30
-	}
-};
-
-char tab_2E138[4 * 3] = {
-	0, 0, 1, 1,
-	0, 0, 0, 1,
-	0, 0, 2, 0
-};
+#include <stddef.h>
+#include <stdlib.h>
+#include "cryolib.h"
+
+#define GetElem(array, idx) \
+	( (char*)(array) + PLE16((idx) * 2 + (char*)(array)) )
+/*
+static inline void* AGetElem(unsigned char *arr, short index)
+{
+    unsigned char *p = arr + num * 2;
+    unsigned char o0 = *p++;
+    unsigned char o1 = *p++;
+    unsigned short ofs = (o1 << 8) | o0;
+    return arr + ofs;
+}
+*/
+
+///////////////// Game defs
+
+#define FONT_HEIGHT 9
+
+
+/*
+Glossary
+  room      - a single game world's screen. referenced by 16-bit number 0xAALL, where AA - area# and LL - location#
+  area      - geographic area - Mo, Chamaar, etc
+  location  - coordinates of particular room in an area. usually in form of 0xXY, where X - map row, Y - map column
+  character - an unique character (human or dino.) Has their own voice/dialog lines
+  person    - instance of a character. Usually tied to specific room, but some may travel with you
+  party     - a group of characters that travel with you
+  object    - inventory item
+  icon      - clickable rectangle with some action tied to it
+  dialog    - a set of of dialog lines for character. further divided by categories and each entry may have associated
+              condition to be validated
+  global    - game-wide storage area. must be preserved when saving/loading
+  phase     - current story progress. Incremented by 1 for minor events, by 0x10 for major advancements
+*/
+
+enum Phases {
+	phNewGame = 0
+};
+
+namespace Areas {
+enum Areas {
+	arMo = 1,
+	arTausCave,
+	arChamaar,
+	arUluru,
+	arKoto,
+	arTamara,
+	arCantura,
+	arShandovra,
+	arNarimsCave,
+	arEmbalmersCave,
+	arWhiteArch,
+	arMoorkusLair
+};
+}
+
+#define MKRM(a,l) (((a) << 8) | (l))
+
+enum OBJECT {
+	OBJ_0,
+	OBJ_1,
+	OBJ_2,
+	OBJ_3,
+	OBJ_4,
+	OBJ_PRISME, // 5
+	OBJ_6,
+	OBJ_7,
+	OBJ_OEUF,   // 8
+	OBJ_9,
+	OBJ_10,
+	OBJ_CHAMPB, // 11
+	OBJ_CHAMPM, // 12
+	OBJ_COUTEAU,    // 13
+	OBJ_NIDV,   // 14
+	OBJ_NIDO,   // 15
+	OBJ_OR,     // 16
+	OBJ_17,
+	OBJ_18,
+	OBJ_SOLEIL, // 19
+	OBJ_CORNE,  // 20
+	OBJ_21,
+	OBJ_22,
+	OBJ_23,
+	OBJ_24,
+	OBJ_25,
+	OBJ_26,
+	OBJ_27,
+	OBJ_28,
+	OBJ_29,
+	OBJ_30,
+	OBJ_31,
+	OBJ_32,
+	OBJ_33,
+	OBJ_34,
+	OBJ_35,
+	OBJ_36,     // 36 is 1st plaque, 6 total
+	OBJ_37,
+	OBJ_PLAQUE, // 38
+	OBJ_39,
+	OBJ_40,
+	OBJ_41,
+};
+
+namespace Objects {
+enum Objects {
+	obNone,
+	obWayStone,
+	obShell,
+	obTalisman,
+	obTooth,
+	obPrism,    // 5
+	obFlute,
+	obApple,
+	obEgg,      // 8
+	obRoot,
+	obUnused10,
+	obShroom,   // 11
+	obBadShroom,    // 12
+	obKnife,    // 13
+	obNest, // 14
+	obFullNest, // 15
+	obGold,     // 16
+	obMoonStone,
+	obBag,
+	obSunStone, // 19
+	obHorn, // 20
+	obSword,
+
+	obMaskOfDeath,
+	obMaskOfBonding,
+	obMaskOfBirth,
+
+	obEyeInTheStorm,    // 25
+	obSkyHammer,
+	obFireInTheClouds,
+	obWithinAndWithout,
+	obEyeInTheCyclone,
+	obRiverThatWinds,
+
+	obTrumpet,      // 31
+	obUnused32,
+	obDrum,
+	obUnused34,
+	obUnused35,
+	obRing,
+
+	obTablet1,      // 37 is 1st plaque, 6 total
+	obTablet2,
+	obTablet3,  // 39
+	obTablet4,
+	obTablet5,
+	obTablet6
+};
+}
+
+enum PERSO {
+	PER_ROI = 0,
+	PER_DINA,       // 0x12
+	PER_THOO,       // 0x24
+	PER_MONK,       // 0x36
+	PER_BOURREAU,   // 0x48
+	PER_MESSAGER,   // 0x5A
+	PER_MANGO,      // 0x6C
+	PER_EVE,        // 0x7E
+	PER_AZIA,       // 0x90
+	PER_MAMMI,      // 0xA2
+	PER_MAMMI_1,    // 0xB4
+	PER_MAMMI_2,    // 0xC6
+	PER_MAMMI_3,    // 0xD8
+	PER_MAMMI_4,    // 0xEA
+	PER_MAMMI_5,    // 0xFC
+	PER_MAMMI_6,    // 0x10E
+	PER_BAMBOO,     // 0x120
+	PER_KABUKA,     // 0x132
+	PER_GARDES,     // 0x144
+	PER_UNKN_156,   // 0x156
+	PER_FISHER,     // 0x168
+	PER_MORKUS,     // 0x17A
+	PER_UNKN_18C,   // 0x18C
+	PER_UNKN_19E,   // 0x19E
+	PER_UNKN_1B0,   // 0x1B0
+	PER_UNKN_1C2,   // 0x1C2
+	PER_UNKN_1D4,   // 0x1D4
+	PER_UNKN_1E6,   // 0x1E6
+	PER_UNKN_1F8,   // 0x1F8
+	PER_UNKN_20A,   // 0x20A
+	PER_UNKN_21C,   // 0x21C
+	PER_UNKN_22E,   // 0x22E
+	PER_UNKN_240,   // 0x240
+	PER_UNKN_252,   // 0x252
+	PER_UNKN_264,   // 0x264
+	PER_UNKN_276,   // 0x276
+	PER_UNKN_288,   // 0x288
+	PER_UNKN_29A,   // 0x29A
+	PER_UNKN_2AC,   // 0x2AC
+	PER_UNKN_2BE,   // 0x2BE
+	PER_UNKN_2D0,   // 0x2D0
+	PER_UNKN_2E2,   // 0x2E2
+	PER_UNKN_2F4,   // 0x2F4
+	PER_UNKN_306,   // 0x306
+	PER_UNKN_318,   // 0x318
+	PER_UNKN_32A,   // 0x32A
+	PER_UNKN_33C,   // 0x33C
+	PER_UNKN_34E,   // 0x34E
+	PER_UNKN_360,   // 0x360
+	PER_UNKN_372,   // 0x372
+	PER_UNKN_384,   // 0x384
+	PER_UNKN_396,   // 0x396
+	PER_UNKN_3A8,   // 0x3A8
+	PER_UNKN_3BA,   // 0x3BA
+	PER_UNKN_3CC,   // 0x3CC
+	PER_UNKN_3DE,   // 0x3DE
+	PER_UNKN_3F0,   // 0x3F0
+	PER_UNKN_402    // 0x402
+};
+
+namespace PersonId {
+enum PersonId {
+	pidGregor = 0,                          // The King
+	pidDina,                                // Pink dino
+	pidTau,                                 // Late grandpa
+	pidMonk,                                // Old wizard
+	pidJabber,                              // Executioner
+	pidEloi,                                // Evergreen ptero
+	pidMungo,                               // Dina's husband
+	pidEve,                                 // Blonde girl
+	pidShazia,                              // Big boobs sis
+	pidLeadersBegin,                        // 9
+	pidChongOfChamaar = pidLeadersBegin,    // Dogface
+	pidKommalaOfKoto,                       // Clones
+	pidUlanOfUlele,                         // Shaman
+	pidCabukaOfCantura,                     // Stone people
+	pidMarindaOfEmbalmers,                  // Gods
+	pidFuggOfTamara,                        // Boar-like
+	pidThugg,                               // Bodyguard
+	pidNarrator,                            // 16, Old Eloi, also BGM
+	pidNarrim,                              // Sea snake
+	pidMorkus,                              // Vicious tyran
+	pidDinosaur,                            // different species of friendly dino
+	pidEnemy                                // different species of enemy dino
+};
+}
+
+// person in room mask bits
+namespace PersonMask {
+enum PersonMask {
+	pmGregor = 1,
+	pmDina   = 2,
+	pmTau    = 4,
+	pmMonk   = 8,
+	pmJabber = 0x10,
+	pmEloi   = 0x20,
+	pmMungo  = 0x40,
+	pmEve    = 0x80,
+	pmShazia = 0x100,
+	pmLeader = 0x200,   // valley tribe leader
+	pmThugg  = 0x400,
+	pmQuest  = 0x800,   // special quest person
+	pmDino   = 0x1000,
+	pmEnemy  = 0x2000,
+	pmMorkus = 0x4000
+};
+}
+
+namespace PersonFlags {
+enum PersonFlags {
+	pfType0 = 0,
+	pftTyrann,
+	pfType2,
+	pfType3,
+	pfType4,
+	pfType5,
+	pfType6,
+	pfType7,
+	pfType8,
+	pftMosasaurus,
+	pftTriceraptor,
+	pftVelociraptor,
+	pfType12,
+	pfType13,
+	pfType14,
+	pfType15,
+	pfTypeMask = 0xF,
+	pf10 = 0x10,
+	pf20 = 0x20,
+	pfInParty = 0x40,
+	pf80 = 0x80
+};
+}
+
+#pragma pack(push, 1)
+struct perso_t {
+	unsigned short  roomNum;    // room this person currently in
+	unsigned short  actionId;   // TODO: checkme
+	unsigned short  party;      // party bit mask
+	unsigned char   id;         // character
+	unsigned char   flags;      // flags and kind
+	unsigned char   roomBankIdx;// index in kPersoRoomBankTable for specific room banks
+	unsigned char   bank;       // sprite bank
+	unsigned short  items;      // inventory
+	unsigned short  powers;     // obj of power bitmask
+	unsigned char   targetLoc;  // For party member this is mini sprite index
+	unsigned char   lastLoc;    // For party member this is mini sprite x offset
+	unsigned char   speed;      // num ticks per step
+	unsigned char   steps;      // current ticks
+};
+typedef struct perso_t perso_t;
+
+struct phase_t {
+	short           id;
+	void (EdenGameImpl::*disp)();
+};
+typedef struct phase_t phase_t;
+
+namespace ObjectFlags {
+enum ObjectFlags {
+	ofFlag1 = 1,
+	ofInHands = 2       // Currently holding this object in hands
+};
+}
+
+#define MAX_OBJECTS 42
+struct object_t {
+	unsigned char   id;
+	unsigned char   flags;
+	int             locations;      // index in kObjectLocations
+	short           itemMask;
+	short           powerMask;          // object of power bitmask
+	short           count;
+};
+typedef struct object_t object_t;
+
+namespace DialogFlags {
+enum DialogFlags {
+	df20 = 0x20,
+	dfRepeatable = 0x40,
+	dfSpoken = 0x80
+};
+}
+
+namespace DialogType {
+enum DialogType {
+	dtTalk = 0,
+	dtDinoAction,
+	dtDinoItem,
+	dtItem,
+	dtEvent,
+	dtInspect,
+	dtHint
+};
+}
+
+struct dial_t {
+	char        flags;          // 0-3 - action index, 4 - highest bit of contidion index, rest is DialogFlags
+	char        condNumLow;     // condition index low bits
+	char        textCondHiMask; // 0-1 text index hi bits, 2-5 - perso mask num, 6-7 condition index hi bits
+	char        textNumLow;     // text line index low bits
+};
+typedef struct dial_t dial_t;
+
+struct tape_t {
+	short       textNum;
+	perso_t     *perso;
+	short       party;
+	short       roomNum;
+	short       bgBankNum;
+	dial_t      *dialog;
+};
+typedef struct tape_t tape_t;
+
+struct suiveur_t {      // Characters on Mirror screen
+	char        id;         // character
+	char        image;      // sprite number
+	short       sx;
+	short       sy;
+	short       ex;
+	short       ey;
+	short       bank;
+	short       ff_C;
+	short       ff_E;
+};
+typedef struct suiveur_t suiveur_t;
+
+struct icon_t {
+	short       sx;
+	short       sy;
+	short       ex;
+	short       ey;
+	unsigned short  cursor_id;          // & 0x8000 - inactive/hidden
+	unsigned int    action_id;
+	unsigned int    object_id;
+};
+typedef struct icon_t icon_t;
+
+struct goto_t {
+	unsigned char   areaNum;    // target area
+	unsigned char   curAreaNum; // current area
+	unsigned char   departVid;
+	unsigned char   travelTime;     // time to skip while in travel
+	unsigned char   arriveVid;
+};
+typedef struct goto_t goto_t;
+
+namespace RoomFlags {
+enum RoomFlags {
+	rf01 = 1,
+	rf02 = 2,
+	rf04 = 4,
+	rf08 = 8,
+	rfPanable = 0x10,
+	rfHasCitadel = 0x20,
+	rf40 = 0x40,
+	rf80 = 0x80
+};
+}
+
+struct room_t {
+	unsigned char   ff_0;
+	unsigned char   exits[4];   //TODO: signed?
+	unsigned char   flags;
+	unsigned short  bank;
+	unsigned short  party;
+	unsigned char   level;      // Citadel level
+	unsigned char   video;
+	unsigned char   location;
+	unsigned char   background; // bg/mirror image number (relative)
+};
+typedef struct room_t room_t;
+
+namespace AreaFlags {
+enum AreaFlags {
+	afFlag1 = 1,
+	afFlag2 = 2,
+	afFlag4 = 4,
+	afFlag8 = 8,
+	afGaveGold = 0x10,
+	afFlag20 = 0x20,
+
+	HasTriceraptors = 0x100,
+	HasVelociraptors = 0x200,
+	HasTyrann = 0x400,
+
+	TyrannSighted = 0x4000,
+	afFlag8000 = 0x8000
+};
+}
+
+namespace AreaType {
+enum AreaType {
+	atCitadel = 1,
+	atValley = 2,
+	atCave = 3
+};
+}
+
+struct area_t {
+	unsigned char   num;
+	unsigned char   type;
+	unsigned short  flags;
+	unsigned short  firstRoomIndex;
+	unsigned char   citadelLevel;
+	unsigned char   salNum;
+	room_t          *citadelRoom;
+	short           visitCount;
+};
+typedef struct area_t area_t;
+
+namespace ValleyNews {
+enum ValleyNews {
+	vnAreaMask = 0xF,
+
+	vnTriceraptorsIn = 0x10,
+	vnVelociraptorsIn = 0x20,
+	vnTyrannIn = 0x30,
+	vnTyrannLost = 0x40,
+	vnCitadelLost = 0x50,
+	vnVelociraptorsLost = 0x60,
+
+	vnFree = 0,
+	vnHidden = 0x80,
+	vnEnd = 0xFF
+};
+}
+
+namespace DisplayFlags {
+enum DisplayFlags {
+	dfFlag1 = 1,
+	dfFlag2 = 2,
+	dfMirror = 4,
+	dfPerson = 8,
+	dfFresques = 0x10,
+	dfPanable = 0x20,
+	dfFlag40 = 0x40,
+	dfFlag80 = 0x80
+};
+}
+
+namespace DrawFlags {
+enum DrawFlags {
+	drDrawInventory = 1,
+	drDrawFlag2 = 2,
+	drDrawTopScreen = 4,
+	drDrawFlag8 = 8,
+	drDrawMenu = 0x10,
+	drDrawFlag20 = 0x20
+};
+}
+
+namespace MenuFlags {
+enum MenuFlags {
+	mfFlag1 = 1,
+	mfFlag2 = 2,
+	mfFlag4 = 4,
+	mfFlag8 = 8,
+	mfFlag10 = 0x10
+};
+}
+
+namespace MusicType {
+enum MusicType {  //TODO: same as DialogType?
+	mtDontChange = 0,
+	mtNormal = 1,
+	mt2 = 2,
+	mtEvent = 4,
+	mtFF = 0xFF
+};
+}
+
+namespace EventType {
+enum EventType {
+	etEvent1 = 1,
+	etEvent2 = 2,
+	etEvent3 = 3,
+	etEvent4 = 4,
+	etEvent5 = 5,
+	etEvent6 = 6,
+	etEvent7 = 7,
+	etEvent8 = 8,
+	etEvent9 = 9,
+	etEventB = 11,
+	etEventC = 12,
+	etEventD = 13,
+	etEventE = 14,
+	etEventF = 15,
+	etEvent10 = 16,
+	etEvent12 = 18,
+	etGotoArea = 0x80   // + area id
+};
+}
+
+namespace GameFlags {
+enum GameFlags {
+	gfMummyOpened = 1,
+	gfFlag2 = 2,
+	gfFlag4 = 4,
+	gfFlag8 = 8,
+	gfFlag10 = 0x10,
+	gfFlag20 = 0x20,
+	gfFlag40 = 0x40,
+	gfFlag80 = 0x80,
+	gfFlag100 = 0x100,
+	gfFlag200 = 0x200,
+	gfFlag400 = 0x400,
+	gfPrismAndMonk = 0x800,
+	gfFlag1000 = 0x1000,
+	gfFlag2000 = 0x2000,
+	gfFlag4000 = 0x4000,
+	gfFlag8000 = 0x8000
+};
+}
+
+struct global_t {
+	unsigned char   areaNum;
+	unsigned char   areaVisitCount;
+	unsigned char   menuItemIdLo;
+	unsigned char   menuItemIdHi;   //TODO: pad?
+	unsigned short  randomNumber;   //TODO: this is randomized in pc ver and used by some conds. always zero on mac
+	unsigned short  gameTime;
+	unsigned short  gameDays;
+	unsigned short  chrono;
+	unsigned short  eloiDepartureDay;
+	unsigned short  roomNum;        // current room number
+	unsigned short  newRoomNum;     // target room number selected on world map
+	unsigned short  phaseNum;
+	unsigned short  metPersonsMask1;
+	unsigned short  party;
+	unsigned short  partyOutside;
+	unsigned short  metPersonsMask2;
+	unsigned short  __UNUSED_1C;    //TODO: write-only?
+	unsigned short  phaseActionsCount;
+	unsigned short  curAreaFlags;
+	unsigned short  curItemsMask;
+	unsigned short  curPowersMask;
+	unsigned short  curPersoItems;
+	unsigned short  curPersoPowers;
+	unsigned short  wonItemsMask;
+	unsigned short  wonPowersMask;
+	unsigned short  stepsToFindAppleFast;
+	unsigned short  stepsToFindAppleNormal;
+	unsigned short  roomPersoItems; //TODO: write-only?
+	unsigned short  roomPersoPowers;    //TODO: write-only?
+	unsigned short  gameFlags;
+	unsigned short  curVideoNum;
+	unsigned short  morkusSpyVideoNum1; //TODO: pad?
+	unsigned short  morkusSpyVideoNum2; //TODO: pad?
+	unsigned short  morkusSpyVideoNum3; //TODO: pad?
+	unsigned short  morkusSpyVideoNum4; //TODO: pad?
+	unsigned char   newMusicType;
+	unsigned char   ff_43;
+	unsigned char   videoSubtitleIndex;
+	unsigned char   partyInstruments;   // &1 - Bell for Monk, &2 - Drum for Thugg
+	unsigned char   monkGotRing;
+	unsigned char   chrono_on;
+	unsigned char   curRoomFlags;
+	unsigned char   endGameFlag;
+	unsigned char   last_info;
+	unsigned char   autoDialog;
+	unsigned char   worldTyrannSighted;
+	unsigned char   ff_4D;
+	unsigned char   ff_4E;
+	unsigned char   worldGaveGold;
+	unsigned char   worldHasTriceraptors;
+	unsigned char   worldHasVelociraptors;
+	unsigned char   worldHasTyrann;
+	unsigned char   ff_53;
+	unsigned char   ff_54;
+	unsigned char   ff_55;  //TODO: pad?
+	unsigned char   ff_56;
+	unsigned char   textToken1;
+	unsigned char   textToken2; //TODO: pad?
+	unsigned char   eloiHaveNews;
+	unsigned char   dialogFlags;
+	unsigned char   curAreaType;
+	unsigned char   curCitadelLevel;
+	unsigned char   newLocation;
+	unsigned char   prevLocation;
+	unsigned char   curPersoFlags;
+	unsigned char   ff_60;
+	unsigned char   eventType;
+	unsigned char   ff_62;  //TODO: pad?
+	unsigned char   curObjectId;
+	unsigned char   curObjectFlags;
+	unsigned char   ff_65;  //TODO: pad?
+	unsigned char   roomPersoType;
+	unsigned char   roomPersoFlags;
+	unsigned char   narratorSequence;
+	unsigned char   ff_69;
+	unsigned char   ff_6A;
+	unsigned char   fresqNumber;
+	unsigned char   ff_6C;  //TODO: pad?
+	unsigned char   ff_6D;  //TODO: pad?
+	unsigned char   labyrinthDirections;
+	unsigned char   labyrinthRoom;
+	void            *__UNUSED_70;   //TODO: pad?
+	dial_t          *dialog_ptr;
+	tape_t          *tape_ptr;
+	dial_t          *next_dialog_ptr;
+	dial_t          *narrator_dialog_ptr;
+	dial_t          *last_dialog_ptr;
+	icon_t          *nextRoomIcon;
+	unsigned char   *phraseBufferPtr;
+	unsigned char   *__UNUSED_90;   //TODO: write-only?
+	unsigned char   *__UNUSED_94;   //TODO: write-only?
+	room_t          *room_ptr;
+	area_t          *area_ptr;
+	area_t          *last_area_ptr;
+	area_t          *cur_area_ptr;
+	room_t          *cita_area_firstRoom;
+	perso_t         *perso_ptr;
+	perso_t         *room_perso;
+	unsigned char   last_info_idx;
+	unsigned char   next_info_idx;
+	unsigned char   *persoSpritePtr;
+	unsigned char   *persoSpritePtr2;
+	unsigned char   *curPersoAnimPtr;
+	unsigned char   *ff_C2; //TODO: image desc arr
+	short           iconsIndex;
+	short           curObjectCursor;    // TODO: useless?
+	short           ff_CA;
+	short           __UNUSED_CC;        //TODO: unused/pad
+	short           perso_img_bank; //TODO: unsigned?
+	unsigned short  roomImgBank;
+	unsigned short  persoBackgroundBankIdx;
+	unsigned short  ff_D4;  //TODO: unsigned?
+	unsigned short  fresqWidth;
+	unsigned short  fresqImgBank;
+	unsigned short  ff_DA;  //TODO: pad?
+	unsigned short  ff_DC;  //TODO: pad?
+	unsigned short  room_x_base;
+	unsigned short  ff_E0;  //TODO: pad?
+	unsigned short  dialogType;
+	unsigned short  ff_E4;  //TODO: pad?
+	unsigned short  currentMusicNum;
+	short           textNum;
+	unsigned short  travelTime;
+	unsigned short  ff_EC;  //TODO: pad?
+	unsigned char   displayFlags;
+	unsigned char   oldDisplayFlags;
+	unsigned char   drawFlags;
+	unsigned char   ff_F1;
+	unsigned char   ff_F2;
+	unsigned char   menuFlags;
+	unsigned char   ff_F4;  //TODO: write-only?
+	unsigned char   ff_F5;
+	unsigned char   ff_F6;
+	unsigned char   ff_F7;
+	unsigned char   ff_F8;  //TODO: pad?
+	unsigned char   ff_F9;  //TODO: pad?
+	unsigned char   ff_FA;  //TODO: pad?
+	unsigned char   animationFlags;
+	unsigned char   __UNUSED_FC;    //TODO: pad?
+	unsigned char   giveobj1;
+	unsigned char   giveobj2;
+	unsigned char   giveobj3;
+	unsigned char   ff_100;
+	unsigned char   roomVidNum;
+	unsigned char   ff_102;
+	unsigned char   ff_103;
+	unsigned char   roomBgBankNum;
+	unsigned char   valleyVidNum;
+	unsigned char   updatePaletteFlag;
+	unsigned char   inventoryScrollPos;
+	unsigned char   obj_count;
+	unsigned char   ff_109; //TODO: write-only?
+	unsigned char   textBankIndex;
+	unsigned char   pref_language;
+	unsigned char   pref_10C[2];    //TODO: volume
+	unsigned char   pref_10E[2];    // -//-
+	unsigned char   pref_110[2];    // -//-
+	unsigned char   cita_area_num;
+	unsigned char   ff_113;
+	unsigned char   lastSalNum;
+	unsigned char   save_end;
+	short           textWidthLimit;
+	unsigned char   numGiveObjs;
+	unsigned char   ff_119;     // unused
+};
+typedef struct global_t global_t;
+
+struct pakfile_t {
+	char            name[16];
+	long            size;
+	long            offs;
+	char            flag;
+};
+typedef struct pakfile_t pakfile_t;
+
+struct pak_t {
+	unsigned short  count;
+	pakfile_t       files[10];
+};
+typedef struct pak_t pak_t;
+#pragma pack(pop)
+
+struct cita_t {
+	short   ff_0;
+	short   ff_2[8 * 2];
+};
+typedef struct cita_t cita_t;
+
+/////////////// vars
+
+suiveur_t suiveurs_list[] = {
+//            char,                 X,  sx, sy,  ex,  ey,bank,
+	{ PersonId::pidGregor,          5, 211,  9, 320, 176, 228,   0,  0 },
+	{ PersonId::pidEloi,            4, 162, 47, 223, 176, 228, 112, 78 },
+	{ PersonId::pidDina,            3,  55,  0, 172, 176, 228,  90, 16 },
+	{ PersonId::pidChongOfChamaar,  4,   0,  5, 114, 176, 229,   0, 16 },
+	{ PersonId::pidKommalaOfKoto,   3,   0, 15, 102, 176, 229,   0, 16 },
+	{ PersonId::pidUlanOfUlele,     1,   0,  0, 129, 176, 230,   0, 16 },
+	{ PersonId::pidCabukaOfCantura, 2,   0,  0, 142, 176, 230,   0, 16 },
+	{ PersonId::pidFuggOfTamara,    0,   0, 17, 102, 176, 230,   0, 16 },
+	{ PersonId::pidJabber,          2,   0,  6, 134, 176, 228,   0, 16 },
+	{ PersonId::pidShazia,          1,  90, 17, 170, 176, 228,  50, 22 },
+	{ PersonId::pidThugg,           0, 489,  8, 640, 176, 228, 160, 24 },
+	{ PersonId::pidMungo,           5, 361,  0, 517, 176, 229,   0, 16 },
+	{ PersonId::pidMonk,            0, 419, 22, 569, 176, 229, 100, 30 },
+	{ PersonId::pidEve,             1, 300, 28, 428, 176, 229,   0, 38 },
+	{ -1,                          -1,  -1, -1,  -1,  -1,  -1,  -1, -1 }
+};
+
+
+/*
+  Labyrinth of Mo
+
+  | | | | | | | |
+
+*/
+
+enum {
+	LAB_N = 1,
+	LAB_E,
+	LAB_S,
+	LAB_W
+};
+
+#define LAB(toCrypt, toThrone)  \
+	(((LAB_##toCrypt) << 4) | (LAB_##toThrone))
+
+unsigned char kLabyrinthPath[] = {
+// each nibble tells wich direction to choose to exit the labyrinth
+	0x11, 0x11, 0x11, 0x22, 0x33, 0x55, 0x25, 0x44, 0x25, 0x11, 0x11, 0x11,
+	0x11, 0x35, 0x55, 0x45, 0x45, 0x44, 0x44, 0x34, 0x44, 0x34, 0x32, 0x52,
+	0x33, 0x23, 0x24, 0x44, 0x24, 0x22, 0x54, 0x22, 0x54, 0x54, 0x44, 0x22,
+	0x22, 0x42, 0x45, 0x22, 0x42, 0x45, 0x35, 0x11, 0x44, 0x34, 0x52, 0x11,
+	0x44, 0x32, 0x55, 0x11, 0x11, 0x33, 0x11, 0x11, 0x53, 0x11, 0x11, 0x53,
+	0x54, 0x24, 0x11, 0x22, 0x25, 0x33, 0x53, 0x54, 0x23, 0x44
+};
+
+#undef LAB
+
+char kDinoSpeedForCitaLevel[16] = { 1, 2, 3, 4, 4, 5, 6, 7, 8, 9 };
+
+char kTabletView[] = {          //TODO: make as struct?
+	// opposite tablet id, video id
+	Objects::obUnused10, 83,
+	Objects::obUnused10, 84,
+	Objects::obTablet4, 85,
+	Objects::obTablet3, 86,
+	Objects::obTablet6, 87,
+	Objects::obTablet5, 85
+};
+
+// special character backgrounds for specific rooms
+char kPersoRoomBankTable[] = {
+	// first entry is default bank, then pairs of [roomNum, bankNum], terminated by -1
+	0,  3, 33, -1,
+	21, 17, 35, -1,
+	0,  2, 36, -1,
+	22,  9, 38,  3, 39, -1,
+	23,  8, 40, -1,
+	0,  3, 41,  7, 42, -1,
+	25, -1,
+	27, 17, 45, -1,
+	28, 26, 46, -1,
+	29, 51, 48, -1,
+	30, 53, 49, -1,
+	0, 27, 50, -1,
+	32, 17, 51, -1,
+	52,  2, 52, -1,
+	-3,  3, -3, -1,
+	31, -1,
+	24,  6, 43, -1,
+	47, -1,
+	0,  2, 64, -1,
+	54,  3, 54, -1,
+	27, -1,
+	26, 17, 45, -1
+};
+
+// area transition descriptors
+goto_t gotos[] = {
+// area, oldarea, vid, time, valleyVid
+	{  0,  1,   0,  2,  20 },
+	{  0,  1, 162,  3, 168 },
+	{  0,  2,   0,  2,  21 },
+	{  0,  6,   0,  3, 108 },
+	{  0,  9, 151,  3,   0 },
+	{  0,  7, 106,  2, 101 },
+	{  0, 10,  79,  3, 102 },
+	{  0, 12,   0,  3,   0 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  1,  3,  58,  2, 104 },
+	{  1,  4, 100,  4, 104 },
+	{  1,  5, 107,  6, 104 },
+	{  1,  6, 155,  8, 104 },
+	{  1,  7, 165,  6, 104 },
+	{  1,  8, 169,  6, 104 },
+	{  1, 10, 111,  2, 104 },
+	{  1, 11, 164,  4, 104 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  1,  3, 161,  3, 102 },
+	{  1,  4, 163,  6, 102 },
+	{  1,  5, 157,  9, 102 },
+	{  1,  9, 160,  9, 102 },
+	{  1, 10,  79,  3, 102 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  1,  3,   0,  3, 153 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  3,  1, 154,  2, 103 },
+	{  3,  4, 100,  2, 103 },
+	{  3,  5, 107,  4, 103 },
+	{  3,  6, 155,  6, 103 },
+	{  3,  7, 165,  8, 103 },
+	{  3,  8, 169,  6, 103 },
+	{  3, 10, 111,  4, 103 },
+	{  3, 11, 164,  6, 103 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  3,  1, 162,  3,  22 },
+	{  3,  4, 163,  6,  22 },
+	{  3,  5, 157,  9,  22 },
+	{  3,  9, 160,  9,  22 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  3,  1,   0,  3, 166 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  4,  1, 154,  4,  51 },
+	{  4,  3,  58,  2,  51 },
+	{  4,  5, 107,  2,  51 },
+	{  4,  6, 155,  4,  51 },
+	{  4,  7, 165,  6,  51 },
+	{  4,  8, 169,  8,  51 },
+	{  4, 10, 111,  6,  51 },
+	{  4, 11, 164,  8,  51 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  4,  1, 162,  3, 109 },
+	{  4,  3, 161,  6, 109 },
+	{  4,  5, 157,  9, 109 },
+	{  4,  9, 160,  9, 109 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  5,  1, 154,  6,  33 },
+	{  5,  3,  58,  4,  33 },
+	{  5,  4, 100,  2,  33 },
+	{  5,  6, 155,  2,  33 },
+	{  5,  7, 165,  4,  33 },
+	{  5,  8, 169,  8,  33 },
+	{  5, 10, 111,  8,  33 },
+	{  5, 11, 164,  8,  33 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  5,  1, 162,  3,  99 },
+	{  5,  3, 161,  6,  99 },
+	{  5,  4, 163,  9,  99 },
+	{  5,  9, 160,  9,  99 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  9,  1, 162,  3, 167 },
+	{  9,  3, 161,  6, 167 },
+	{  9,  4, 163,  9, 167 },
+	{  9,  5, 157,  9, 167 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  6,  1, 154,  8, 105 },
+	{  6,  3,  58,  6, 105 },
+	{  6,  4, 100,  4, 105 },
+	{  6,  5, 107,  2, 105 },
+	{  6,  7, 165,  2, 105 },
+	{  6,  8, 169, 10, 105 },
+	{  6, 10, 111,  6, 105 },
+	{  6, 11, 164,  8, 105 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  7,  1, 154,  4, 158 },
+	{  7,  3,  58,  6, 158 },
+	{  7,  4, 100,  6, 158 },
+	{  7,  5, 107,  4, 158 },
+	{  7,  6, 155,  2, 158 },
+	{  7,  8, 169,  8, 158 },
+	{  7, 10, 111,  4, 158 },
+	{  7, 11, 164,  6, 158 },
+	{ -1, -1,  -1, -1,  -1 },
+	{  8,  1, 154,  2, 159 },
+	{  8,  3,  58,  4, 159 },
+	{  8,  4, 100,  6, 159 },
+	{  8,  5, 107,  8, 159 },
+	{  8,  6, 155, 10, 159 },
+	{  8,  7, 165,  8, 159 },
+	{  8, 10, 111,  6, 159 },
+	{  8, 11, 164,  4, 159 },
+	{ -1, -1,  -1, -1,  -1 },
+	{ 10,  1, 154,  2,  77 },
+	{ 10,  3,  58,  4,  77 },
+	{ 10,  4, 100,  6,  77 },
+	{ 10,  5, 107,  8,  77 },
+	{ 10,  6, 155,  6,  77 },
+	{ 10,  7, 165,  4,  77 },
+	{ 10,  8, 169,  6,  77 },
+	{ 10, 11, 164,  4,  77 },
+	{ -1, -1,  -1, -1,  -1 },
+	{ 11,  1, 154,  2,  80 },
+	{ 11,  3,  58,  4,  80 },
+	{ 11,  4, 100,  6,  80 },
+	{ 11,  5, 107,  8,  80 },
+	{ 11,  6, 155,  8,  80 },
+	{ 11,  7, 165,  6,  80 },
+	{ 11,  8, 169,  2,  80 },
+	{ 11, 10, 111,  4,  80 },
+	{ -1, -1,  -1, -1,  -1 },
+	{ 12,  1, 154,  8,  56 },
+	{ 12,  3,  58,  4,  56 },
+	{ 12,  4, 100,  4,  56 },
+	{ 12,  5, 107,  6,  56 },
+	{ 12,  6, 155,  8,  56 },
+	{ 12,  7, 165, 10,  56 },
+	{ 12,  8, 169,  4,  56 },
+	{ 12, 10, 111, 10,  56 },
+	{ 12, 11, 164,  6,  56 },
+	{ -1, -1,  -1, -1,  -1 }
+};
+
+#define SUB_LINE(start, end) \
+	(start), (end) | 0x8000
+
+short tab_2D24C[] = {
+	SUB_LINE(68, 120),
+	123, 32964,
+	199, 33042,
+	276, 33138,
+	799, 33653,
+	888, 33708,
+	947, 33768,
+	1319, 34146,
+	1380, 34208,
+	1854, 34666,
+	1900, 34728,
+	2116, 34952,
+	2186, 35020,
+	2254, 35088,
+	3038, 35862,
+	3096, 35928,
+	-1
+};
+
+short tab_2D28E[] = {
+	99, 32923,
+	157, 33024,
+	-1
+};
+
+short tab_2D298[] = {
+	106, 32941,
+	175, 33012,
+	246, 33118,
+	352, 33235,
+	-1
+};
+
+short tab_2D2AA[] = {
+	126, 32944,
+	178, 33035,
+	269, 33110,
+	344, 33166,
+	400, 33226,
+	460, 33326,
+	-1
+};
+
+short tab_2D2C4[] = {
+	101, 32981,
+	215, 33121,
+	355, 33223,
+	457, 33286,
+	520, 33428,
+	662, 33536,
+	-1
+};
+#undef SUB_LINE
+
+object_t objects[] = {
+	//id,fl,loc,masklow,maskhi,ct
+	{  1, 0,  3,      1,     0, 0},     // Eve's Way Stone
+	{  2, 0,  3,      2,     0, 0},     // Thau's Seashell
+	{  3, 0,  3,      4,     0, 0},     // Talisman of bravery
+	{  4, 0,  3,      8,     0, 0},     // An old tooth. Very old! Whoever lost it most certainly has no further use for it!
+	{  5, 0,  0,   0x10,     0, 0},     // Prism
+	{  6, 0,  3,      0,     0, 0},     // Flute
+	{  7, 0,  3, 0x4000,     0, 0},     // Apple
+	{  8, 0,  4, 0x1000,     0, 0},     // Egg of Destiny
+	{  9, 0,  3,  0x800,     0, 0},     // Root
+	{ 10, 0,  3,      0,     0, 0},     // ???
+	{ 11, 0,  6,      0,     0, 0},     // Mushroom
+	{ 12, 0, 13,      0,     0, 0},     // Poisonous Mushroom
+	{ 13, 0,  2,  0x400,     0, 0},     // Graa's Knife
+	{ 14, 0, 22,      0,     0, 0},     // Empty Nest
+	{ 15, 0, 26,      0,     0, 0},     // Full Nest
+	{ 16, 0, 33,   0x20,     0, 0},     // Gold
+	{ 17, 0,  3,      0,     0, 0},     // Sign of Shadow Mistress  (moon stone)
+	{ 18, 0,  3,      0,     0, 0},     // Sign of Mother of all    (bag of soil)
+	{ 19, 0, 40,      0,     0, 0},     // Sign of the life-giving  (sun star)
+	{ 20, 0, 20,  0x200,     0, 0},     // King's Horn
+	{ 21, 0,  3,      0,     0, 0},     // Golden Sword of Mashaar
+	// Masks
+	{ 22, 0,  3,   0x40,     0, 0},     // Mask of Death
+	{ 23, 0,  3,   0x80,     0, 0},     // Mask of Bonding
+	{ 24, 0,  3,  0x100,     0, 0},     // Mask of Birth
+	// Objects of power
+	{ 25, 0,  3,      0,     1, 0},     // Eye in the Storm
+	{ 26, 0,  3,      0,     2, 0},     // Sky Hammer
+	{ 27, 0,  3,      0,     4, 0},     // Fire in the Clouds
+	{ 28, 0,  3,      0,     8, 0},     // Within and Without
+	{ 29, 0,  3,      0,  0x10, 0},     // Eye in the Cyclone
+	{ 30, 0,  3,      0,  0x20, 0},     // River that Winds
+	// Musical instruments
+	{ 31, 0,  3,      0,  0x40, 0},     // Trumpet
+	{ 32, 0,  3,      0,  0x80, 0},     // -- unused (but still has a dialog line)
+	{ 33, 0,  3,      0, 0x100, 0},     // Drum
+	{ 34, 0,  3,      0, 0x200, 0},     // -- unused (but still has a dialog line)
+	{ 35, 0,  3,      0, 0x400, 0},     // -- unused (but still has a dialog line)
+	{ 36, 0,  3,      0, 0x800, 0},     // Ring
+	// Tablets
+	{ 37, 0,  3,      0,     0, 0},     // Tablet #1 (Mo)
+	{ 38, 0, 42, 0x2000,     0, 0},     // Tablet #2 (Morkus' Lair)
+	{ 39, 0,  3,      0,     0, 0},     // Tablet #3 (White Arch?)
+	{ 40, 0,  3,      0,     0, 0},     // Tablet #4
+	{ 41, 0,  3,      0,     0, 0},     // Tablet #5
+	{ 42, 0,  3, 0x8000,     0, 0}      // Tablet #6 (Castra)
+};
+
+short kObjectLocations[100] = {
+	0x112, -1,
+	0x202, -1,
+	0x120, -1,
+	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
+	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
+	0, -1,
+	0x344, 0x53A, 0x831, -1,
+	0x331, 0x420, 0x54B, 0x637, 0x716, 0x840, -1,
+	0x834A, 0x8430, 0x8531, 0x644, 0x745, 0x838, -1,
+	0x510, -1,
+	0xC04, -1,
+	-1
+};
+
+perso_t kPersons[] = {
+	// room, aid, party mask,                            id,                                            flags,  X,bank,X, X,sprId,sprX,speed, X
+	{ 0x103, 230, PersonMask::pmGregor, PersonId::pidGregor            ,                                                0,  0,  1, 0, 0,  0,   0, 0, 0 },
+	{ 0x116, 231, PersonMask::pmDina  , PersonId::pidDina              ,                                                0,  4,  2, 0, 0,  3,   9, 0, 0 },
+	{ 0x202, 232, PersonMask::pmTau   , PersonId::pidTau               ,                                                0,  8,  3, 0, 0,  0,   0, 0, 0 },
+	{ 0x109, 233, PersonMask::pmMonk  , PersonId::pidMonk              ,                                                0, 12,  4, 0, 0,  6,  52, 0, 0 },
+	{ 0x108, 234, PersonMask::pmJabber, PersonId::pidJabber            ,                                                0, 18,  5, 0, 0,  2,   0, 0, 0 },
+	{ 0x103, 235, PersonMask::pmEloi  , PersonId::pidEloi              ,                                                0, 22,  6, 0, 0,  4,  20, 0, 0 },
+	{ 0x301, 236, PersonMask::pmMungo , PersonId::pidMungo             ,                                                0, 28,  8, 0, 0, 11,  45, 0, 0 },
+	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 30, 10, 0, 0,  7,  35, 0, 0 },
+	{ 0x81A, 238, PersonMask::pmShazia, PersonId::pidShazia            ,                                                0, 34, 11, 0, 0,  1,  11, 0, 0 },
+	{ 0x330, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
+	{ 0x41B, 239, PersonMask::pmLeader, PersonId::pidUlanOfUlele       ,                                                0, 46, 15, 0, 0, 13,   0, 0, 0 },
+	{ 0x53B, 239, PersonMask::pmLeader, PersonId::pidKommalaOfKoto     ,                                                0, 42, 14, 0, 0,  9,   0, 0, 0 },
+	{ 0x711, 239, PersonMask::pmLeader, PersonId::pidCabukaOfCantura   ,                                                0, 50, 16, 0, 0, 14,   0, 0, 0 },
+	{ 0xA02, 239, PersonMask::pmLeader, PersonId::pidMarindaOfEmbalmers,                                                0, 54, 17, 0, 0,  0,   0, 0, 0 },
+	{ 0x628, 239, PersonMask::pmLeader, PersonId::pidFuggOfTamara      ,                                                0, 62, 18, 0, 0, 12,   0, 0, 0 },
+	{ 0x801, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
+	{ 0x41B,  10, PersonMask::pmQuest , PersonId::pidUlanOfUlele       , PersonFlags::pfType2                            , 46, 15, 0, 0, 13,   0, 0, 0 },
+	{ 0x711,  11, PersonMask::pmQuest , PersonId::pidCabukaOfCantura   , PersonFlags::pfType2                            , 50, 16, 0, 0, 14,   0, 0, 0 },
+	{ 0x106, 240, PersonMask::pmThugg , PersonId::pidThugg             ,                                                0, 64,  7, 0, 0,  0,  61, 0, 0 },
+	{     0,  13,                    0, PersonId::pidNarrator          ,                                                0, 68, 12, 0, 0,  0,   0, 0, 0 },
+	{ 0x902, 241, PersonMask::pmQuest , PersonId::pidNarrim            ,                                                0, 70, 19, 0, 0,  0,   0, 0, 0 },
+	{ 0xC03, 244, PersonMask::pmMorkus, PersonId::pidMorkus            ,                                                0, 74, 20, 0, 0,  0,   0, 0, 0 },
+	// dinos in each valley
+	{ 0x332, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x329, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x33B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x317, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x320, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType12                           ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x349, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x429, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x43B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x422, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x432, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x522, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x534, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x515, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x533, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x622, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x630, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x643, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x63A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x737, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x739, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x74A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x726, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0x842, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pfType8        ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x822, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x828, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
+	{ 0x84B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
+
+	{ 0xB03, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            , 58, 252, 0, 0,  0,   0, 0, 0 },
+	// enemy dinos
+	{ 0x311, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x410, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x51B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x618, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x71B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{ 0x81B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
+	{    -1,  -1,                   -1,                              -1,                                               -1, -1, -1, -1, -1, -1,  -1, -1, -1 },
+	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 80,  9, 0, 0,  8,  35, 0, 0 },
+	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 78, 10, 0, 0,  7,  35, 0, 0 }
+};
+
+cita_t cita_list[] = {
+	{
+		1,
+		{
+			163, 182,   0, 0,
+			124, 147, 193, 0,
+			0,   0,   0, 0,
+			0,   0,   0, 0
+		}
+	},
+	{
+		48,
+		{
+			285, 286,   0, 0,
+			287, 288, 284, 0,
+			114, 115,   0, 0,
+			116, 117, 113, 0
+		}
+	},
+	{
+		63,
+		{
+			290, 291,   0, 0,
+			292, 293, 289, 0,
+			119, 120,   0, 0,
+			121, 122, 118, 0
+		}
+	},
+	{
+		95,
+		{
+			295, 296,   0, 0,
+			297, 298, 294, 0,
+			124, 125,   0, 0,
+			126, 127, 123, 0
+		}
+	},
+	{
+		127,
+		{
+			300, 301,   0, 0,
+			302, 303, 299, 0,
+			129, 130,   0, 0,
+			131, 132, 128, 0
+		}
+	},
+	{
+		159,
+		{
+			305, 306,   0, 0,
+			307, 308, 304, 0,
+			134, 135,   0, 0,
+			136, 137, 133, 0
+		}
+	},
+	{
+		255,
+		{
+			310, 311,   0, 0,
+			312, 313, 309, 0,
+			139, 140,   0, 0,
+			141, 142, 138, 0
+		}
+	}
+};
+
+
+short tab_2CB16[] = { 2075, 2080, 2119, -1};
+
+char tab_2CB1E[8][4] = {
+	{ 0x10, 0x81,    1, 0x90},
+	{ 0x90,    1, 0x81, 0x10},
+	{    1, 0x90, 0x10, 0x81},
+	{    1, 0x10, 0x90, 0x81},
+	{    1, 0x90, 0x10, 0x81},
+	{ 0x81, 0x10, 0x90,    1},
+	{ 0x81, 0x10, 0x90,    1},
+	{ 0x81, 0x90,    1, 0x10}
+};
+
+struct prect_t {
+	short   sx, sy, ex, ey;
+};
+typedef struct prect_t prect_t;
+
+prect_t perso_rects[] = {   //TODO: just an array of shorts?
+	{  93,  69, 223, 176},
+	{ 102,  86, 162, 126},
+	{  88, 103, 168, 163},
+	{ 116,  66, 192, 176},
+	{ 129,  92, 202, 153},
+	{  60,  95, 160, 176},
+	{ 155,  97, 230, 145},
+	{ 100,  77, 156, 145},
+	{ 110,  78, 170, 156},
+	{  84,  76, 166, 162},
+	{  57,  77, 125, 114},
+	{  93,  69, 223, 175},
+	{  93,  69, 223, 176},
+	{  93,  69, 223, 176},
+	{ 154,  54, 245, 138},
+	{ 200,  50, 261, 116},
+	{  70,  84, 162, 176},
+	{ 125, 101, 222, 172},
+	{ 188,  83, 251, 158}
+};
+
+unsigned char tab_persxx[][5] = {   //TODO: struc?
+	{  8, 15, 23, 25, -1},
+	{  0,  9, -1        },
+	{  0,  9, -1        },
+	{  0,  9, -1        },
+	{  0, 13, -1        },
+	{ 16, 21, -1        },
+	{ 11, 20, -1        },
+	{  0, 12, -1        },
+	{  0,  9, -1        },
+	{  0,  9, -1        },
+	{  5, 13, -1        },
+	{ -1                },
+	{  0,  8, -1        },
+	{ -1                },
+	{  0,  7, -1        },
+	{  0,  8, -1        },
+	{  8, 12, -1        },
+	{  0,  5, -1        },
+	{  0,  4, -1        },
+	{ -1                }
+};
+
+area_t kAreasTable[] = {
+	{ Areas::arMo           , AreaType::atCitadel,                           0,   0, 0,  1},
+	{ Areas::arTausCave     , AreaType::atCave   ,                           0, 112, 0,  2},
+	{ Areas::arChamaar      , AreaType::atValley ,                           0, 133, 0,  3},
+	{ Areas::arUluru        , AreaType::atValley ,                           0, 187, 0,  4},
+	{ Areas::arKoto         , AreaType::atValley , AreaFlags::HasVelociraptors, 236, 0,  5},
+	{ Areas::arTamara       , AreaType::atValley ,                           0, 288, 0,  6},
+	{ Areas::arCantura      , AreaType::atValley ,                           0, 334, 0,  7},
+	{ Areas::arShandovra    , AreaType::atValley ,                           0, 371, 0,  8},
+	{ Areas::arNarimsCave   , AreaType::atCave   ,                           0, 115, 0,  9},
+	{ Areas::arEmbalmersCave, AreaType::atCave   ,                           0, 118, 0, 10},
+	{ Areas::arWhiteArch    , AreaType::atCave   ,                           0, 122, 0, 11},
+	{ Areas::arMoorkusLair  , AreaType::atCave   ,                           0, 127, 0, 12}
+};
+
+short tab_2CEF0[64] = {
+	25, 257,  0,   0, 37, 258, 38, 259,  0,   0, 24, 260, 0, 0, 0, 0,
+	0,   0, 53, 265,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
+	39, 261,  0,   0, 40, 262, 62, 263,  0,   0, 63, 264, 0, 0, 0, 0,
+	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0
+};
+
+short tab_2CF70[64] = {
+	65, 266,  0,   0, 66, 267, 67, 268,  0,   0, 68, 269, 0, 0, 0, 0,
+	0,   0, 73, 274,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
+	69, 270,  0,   0, 70, 271, 71, 272,  0,   0, 72, 273, 0, 0, 0, 0,
+	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0,
+};
+
+short kActionCursors[299] = {
+	3, 1, 2, 4, 5, 5, 5, 0, 5, 5,
+	5, 5, 5, 3, 2, 5, 5, 5, 3, 2,
+	4, 5, 7, 7, 4, 5, 5, 0, 0, 0,
+	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+	5, 5, 0, 0, 0, 0, 5, 5, 5, 5,
+	5, 5, 5, 5, 5, 5, 5, 5, 0, 0,
+	0, 0, 5, 5, 5, 5, 5, 5, 5, 5,
+	5, 5, 5, 5, 0, 0, 0, 0, 5, 5,
+	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+	6, 6, 6, 6, 6, 6, 6, 0, 5, 6,
+	6, 1, 6, 6, 0, 0, 6, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+	8, 8, 8, 8, 8, 8, 0, 0, 6, 6,
+	53, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+struct cubeface_t {
+	int             tri;
+	char            ff_4;
+	char            ff_5;
+
+	unsigned char   *texptr;
+	unsigned short  *indices;
+	short           *uv;
+};
+typedef struct cubeface_t cubeface_t;
+
+struct cube_t {
+	int             num;
+	cubeface_t      **faces;
+	short           *projection;    // projected XYZ coords
+	short           *vertices;
+};
+typedef struct cube_t cube_t;
+
+float flt_2DF7C = -3400;
+float flt_2DF80 = -3400;
+float flt_2DF84 =   200;
+
+// Cube faces to texture coords mapping
+// each entry is num_polys(6) * num_faces_per_poly(2) * vertex_per_face(3) * uv(2)
+
+short cube_texcoords[3][6 * 2 * 3 * 2] = {
+	{
+		32, 32,  0, 32,  0,  0,
+		32, 32,  0,  0, 32,  0,
+
+		0, 32,  0,  0, 32,  0,
+		0, 32, 32,  0, 32, 32,
+
+		32, 32,  0, 32,  0,  0,
+		32, 32,  0,  0, 32,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		0,  0, 32,  0, 32, 32,
+		0,  0, 32, 32,  0, 32,
+
+		0, 32,  0,  0, 32,  0,
+		0, 32, 32,  0, 32, 32
+	}, {
+		32, 32,  0, 32,  0,  0,
+		32, 32,  0,  0, 32,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		0, 32,  0,  0, 32,  0,
+		0, 32, 32,  0, 32, 32,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0,
+
+		32,  0, 32, 32,  0, 32,
+		32,  0,  0, 32,  0,  0
+	}, {
+		30, 30,  2, 30,  2,  2,
+		30, 30,  2,  2, 30,  2,
+
+		2, 30,  2,  2, 30,  2,
+		2, 30, 30,  2, 30, 30,
+
+		30, 30,  2, 30,  2,  2,
+		30, 30,  2,  2, 30,  2,
+
+		30,  2, 30, 30,  2, 30,
+		30,  2,  2, 30,  2,  2,
+
+		2,  2, 30,  2, 30, 30,
+		2,  2, 30, 30,  2, 30,
+
+		2, 30,  2,  2, 30,  2,
+		2, 30, 30,  2, 30, 30
+	}
+};
+
+char tab_2E138[4 * 3] = {
+	0, 0, 1, 1,
+	0, 0, 0, 1,
+	0, 0, 2, 0
+};
diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp
index 98b45d7..48416f7 100644
--- a/engines/cryo/eden.cpp
+++ b/engines/cryo/eden.cpp
@@ -1,8456 +1,8456 @@
-//#include <stdint.h>
-
-#include "common/scummsys.h"
-
-#include "common/config-manager.h"
-#include "common/debug.h"
-#include "common/debug-channels.h"
-#include "common/error.h"
-#include "gui/EventRecorder.h"
-#include "common/file.h"
-#include "common/savefile.h"
-#include "common/fs.h"
-#include "common/system.h"
-#include "graphics/surface.h"
-#include "graphics/screen.h"
-#include "graphics/palette.h"
-#include "common/timer.h"
-
-//#include "audio/audiostream.h"
-#include "audio/mixer.h"
-
-#include "cryo/cryo.h"
-#include "cryo/eden.h"
-
-namespace Cryo {
-
-#include "cryo/platdefs.h"
-#include "cryo/defs.h"
-#include "cryo/CryoLib.h"
-#include "cryo/CryoLibStub.c"
-
-short       word_2C300 = 0;
-short       word_2C302 = 0;
-short       word_2C304 = 0;
-
-unsigned char   allow_doubled = 1;
-int     curs_center = 11;
-
-struct {
-	short   x, y;
-} saved_repadam = { -1, -1 };
-
-class EdenGameImpl : EdenGame {
-private:
-
-	short           old_scroll_pos, scroll_pos;
-	short           word_2F514;
-	unsigned char   fresqTalk;
-	unsigned char   keep01, keep02, keep10, keep11, keep12, keep13, keep21, keep22;
-	unsigned char   curs_keepbuf[2500];
-	short           curs_keepy, curs_keepx;
-	short           torchCursor;
-	short           cur_bank_num;
-	short           glow_h;
-	short           glow_w;
-	short           glow_y;
-	short           glow_x;
-	unsigned char   needPaletteUpdate;
-	unsigned char   curs_saved;
-	unsigned char   showBlackBars;
-	unsigned char   fond_saved;
-	unsigned char   *bank_data_ptr;
-	color3_t        pal_entry;
-	color_t         global_palette[256];    //TODO palette_t
-	perso_t         *tyranPtr;
-	int             last_anim_frame_num;
-	int             cur_anim_frame_num;
-	int             last_anim_ticks;
-	prect_t         *cur_perso_rect;
-	short           num_anim_frames;
-	short           max_perso_desc;
-	short           num_img_desc;
-	unsigned char   restartAnimation;
-	unsigned char   animationActive;
-	unsigned char   animationDelay;
-	unsigned char   animationIndex;
-	unsigned char   lastAnimationIndex;
-
-	unsigned char   *dword_30724;
-	unsigned char   *dword_30728;   //TODO: rename - something amim-related
-	unsigned char   *dword_3072C;   //TODO ditto
-	unsigned char   *animationTable;
-	unsigned char   imagedesc[512];
-	unsigned char   *perso_img_bank_data_ptr;
-	unsigned char   savedUnderSubtitles;
-	short           num_text_lines;
-	unsigned char   phraseBuffer[400];
-	unsigned char   *text_ptr;
-	unsigned char   phraseIconsBuffer[10];
-	unsigned char   phraseCoordsBuffer[22];
-	unsigned char   *textoutptr;
-	unsigned char   *textout;
-	object_t        *currentSpecialObject;
-	short           word_30AFC;
-	unsigned char   byte_30AFE;
-
-	unsigned char   byte_30B00;
-	int             dword_30B04;
-
-	char            lastPhrasesFile;
-	char            dialogSkipFlags;
-
-	color3_t        newColor;
-	color_t         oldPalette[256];    // TODO palette_t ?
-	color_t         newPalette[256];
-	rect_t          rect_dst, rect_src;
-	void            *voiceSamplesBuffer;    //TODO: sound sample buffer
-	file_t          h_bigfile;
-	unsigned char   info_list[16];
-	unsigned char   needToFade;
-	unsigned char   lastMusicNum;
-	unsigned char   *main_bank_buf;
-	unsigned char   *music_buf;
-	unsigned char   *gameLipsync;
-	unsigned char   *gamePhrases;
-	unsigned char   *gameDialogs;   //TODO: rename to dialogs?
-	unsigned char   *gameConditions;
-	void            *sal_buf;   //TODO: fixme
-	unsigned char   *bank_data_buf;
-	icon_t          *gameIcons;
-	room_t          *gameRooms;
-	pak_t           *bigfile_header;
-	unsigned char   *glow_buffer;
-	unsigned char   *p_mainview_buf;
-	unsigned char   *p_view2_buf;
-	unsigned char   *gameFont;  //TODO: rename to font?
-	unsigned char   *p_subtitlesview_buf;
-	unsigned char   *p_underSubtitlesView_buf;
-	global_t        *p_global;
-	unsigned short  mouse_y_center, mouse_x_center;
-	int             quit_flag3;     //TODO: some obsolete error flag?
-	unsigned short  machine_speed;
-	unsigned char   quit_flag;
-
-	unsigned char   gameStarted;
-
-	unsigned char   quit_flag2;
-	unsigned char   soundAllocated;
-	soundchannel_t  *music_channel;
-	soundchannel_t  *hnmsound_ch;
-	sound_t         *voiceSound;
-
-	view_t          *p_view2;
-	view_t          *p_underSubtitlesView;
-	view_t          *p_subtitlesview;
-	view_t          *p_underBarsView;
-	view_t          *p_mainview;
-	view_t          *p_hnmview;
-	hnm_t           *p_hnmcontext;
-	filespec_t      bigfilespec;
-	rect_t          underSubtitlesBackupRect, underSubtitlesScreenRect, underBottomBarBackupRect, underBottomBarScreenRect,
-	                underTopBarBackupRect, underTopBarScreenRect, rect_31C7A;
-	int             demoCurrentTicks;
-	int             demoStartTicks;
-	int             currentTime;
-	short           mouse_y;
-	short           mouse_x;
-	short           doubled;
-	short           curs_x_pan;
-	short           inventoryScrollDelay;
-	short           curs_y, curs_x;
-	short           current_cursor;
-	icon_t          *current_spot;
-	icon_t          *current_spot2;
-	unsigned char   pomme_q;
-	unsigned char   keybd_held;
-	unsigned char   mouse_held;
-	unsigned char   normalCursor;
-	unsigned char   *p_hnmview_buf;
-	unsigned char   showVideoSubtitle;
-	unsigned char   videoCanceled;  //TODO: hnm_canceled
-	unsigned char   specialTextMode;
-	int             hnm_position;
-	int             voiceSamplesSize;   //TODO: perso vox sample data len
-	short           mus_vol_right;
-	short           mus_vol_left;
-
-
-	unsigned char   animateTalking;
-	unsigned char   personTalking;
-	unsigned char   mus_fade_flags;
-
-	char            musicSequencePos;
-	unsigned char   musicPlaying;
-
-	unsigned char   *mus_samples_ptr;
-	unsigned char   *mus_patterns_ptr;  //TODO: sndblock_t ?
-	unsigned char   *mus_sequence_ptr;
-	soundgroup_t    *mus_queue_grp;
-	short           *pCurrentObjectLocation;
-	unsigned char   own_objects[128];
-	unsigned char   byte_31D64;
-
-	unsigned char   no_palette;
-	unsigned char   gameLoaded;
-#define MAX_TAPES 16
-	tape_t          tapes[MAX_TAPES];
-	unsigned char   confirmMode;
-	unsigned char   *cur_slider_value_ptr;
-	unsigned char   lastMenuItemIdLo;
-	short           lastTapeRoomNum;
-	short           cur_slider_x;
-	short           cur_slider_y;
-	short           destinationRoom;
-	short           word_31E7A;
-
-	short           word_378CC; //TODO: set by CLComputer_Init to 0
-	short           word_378CE;
-
-	void RemoveConsole() {
-	}
-	void scroll() {
-		restaurefrises();
-		p_mainview->norm.src_left = scroll_pos;
-		p_mainview->zoom.src_left = scroll_pos;
-
-	}
-	void resetscroll() {
-		old_scroll_pos = scroll_pos;
-		scroll_pos = 0;
-		restaurefrises();   //TODO: inlined scroll() ?
-		p_mainview->norm.src_left = 0;
-		p_mainview->zoom.src_left = 0;
-	}
-	void scrollfresques() {
-		if (curs_y > 16 && curs_y < 176) {
-			if (curs_x >= 0 && curs_x < 32 && scroll_pos > 3) {
-				scroll_pos -= 4;
-			} else if (curs_x > 288 && curs_x < 320 && scroll_pos < p_global->fresqWidth) {
-				scroll_pos += 4;
-			}
-		}
-		scroll();
-
-	}
-	void afffresques() {
-		use_bank(p_global->fresqImgBank);
-		noclipax(0, 0, 16);
-		use_bank(p_global->fresqImgBank + 1);
-		noclipax(0, 320, 16);
-		needPaletteUpdate = 1;
-	}
-	void gametofresques() {
-		fresqTalk = 0;
-		rundcurs();
-		sauvefrises();
-		afffresques();
-		p_global->displayFlags = DisplayFlags::dfFresques;
-	}
-	void dofresques() {
-		curs_saved = 0;
-		torchCursor = 1;
-		glow_x = -1;
-		glow_y = -1;
-		p_global->gameFlags |= GameFlags::gfFlag20;
-		p_global->ff_D4 = 0;
-		p_global->curObjectId = 0;
-		p_global->iconsIndex = 13;
-		p_global->autoDialog = 0;
-		gametofresques();
-		p_global->fresqNumber = 3;
-	}
-	void finfresques() {
-		torchCursor = 0;
-		curs_saved = 1;
-		p_global->displayFlags = DisplayFlags::dfFlag1;
-		resetscroll();
-		p_global->ff_100 = -1;
-		maj_salle(p_global->roomNum);
-		if (p_global->phaseNum == 114)
-			p_global->narratorSequence = 1;
-		p_global->eventType = EventType::etEvent8;
-		showevents();
-	}
-	void scrollmiroir() {
-		if (curs_y > 16 && curs_y < 165) {
-			if (curs_x >= 0 && curs_x < 16) {
-				if (scroll_pos > 3) {
-					if (doubled)
-						scroll_pos -= 2;
-					else
-						scroll_pos -= 1;
-					scroll();
-				}
-			} else if (curs_x > 290 && curs_x < 320) {
-				if (scroll_pos < 320) {
-					if (doubled)
-						scroll_pos += 2;
-					else
-						scroll_pos += 1;
-					scroll();
-				}
-			}
-		}
-	}
-	void scrollpano() {
-		if (curs_y > 16 && curs_y < 165) {
-			if (curs_x >= 0 && curs_x < 16) {
-				if (scroll_pos > 3) {
-					if (doubled)
-						scroll_pos -= 2;
-					else
-						scroll_pos -= 1;
-				}
-			} else if (curs_x > 290 && curs_x < 320) {
-				if (scroll_pos < 320) {
-					if (doubled)
-						scroll_pos += 2;
-					else
-						scroll_pos += 1;
-				}
-			}
-		}
-		scroll();
-	}
-	void affsuiveur(suiveur_t *suiveur, short x, short y) {
-		use_bank(suiveur->bank);
-		noclipax(suiveur->image, x, y + 16);
-	}
-	void persoinmiroir() {
-		icon_t  *icon1 = &gameIcons[3];
-		icon_t  *icon = &gameIcons[28];
-		suiveur_t *suiveur = suiveurs_list;
-		short num = 1;
-		int i;
-		for (i = 0; i < 16; i++) {
-			if (p_global->party & (1 << i))
-				num++;
-		}
-		icon += num;
-		icon->sx = -1;
-		icon--;
-		icon->sx = icon1->sx;
-		icon->sy = icon1->sy;
-		icon->ex = icon1->ex;
-		icon->ey = 170;
-		icon->cursor_id = icon1->cursor_id;
-		icon->action_id = icon1->action_id;
-		icon->object_id = icon1->object_id;
-		icon--;
-		affsuiveur(suiveur, suiveur->sx, suiveur->sy);
-		for (; suiveur->id != -1; suiveur++) {
-			perso_t *perso;
-			for (perso = kPersons; perso != &kPersons[PER_UNKN_156]; perso++) {
-				if (perso->id != suiveur->id)                       continue;
-				if (perso->flags & PersonFlags::pf80)               continue;
-				if ((perso->flags & PersonFlags::pfInParty) == 0)   continue;
-				if (perso->roomNum != p_global->roomNum)            continue;
-				icon->sx = suiveur->sx;
-				icon->sy = suiveur->sy;
-				icon->ex = suiveur->ex;
-				icon->ey = suiveur->ey;
-				icon->cursor_id = 8;
-				icon->action_id = perso->actionId;
-				icon--;
-				affsuiveur(suiveur, suiveur->sx, suiveur->sy);
-				break;
-			}
-		}
-	}
-	void gametomiroir(unsigned char arg1) {
-		short bank;
-		if (p_global->displayFlags != DisplayFlags::dfFlag2) {
-			rundcurs();
-			restaurefrises();
-			afftopscr();
-			showobjects();
-			sauvefrises();
-		}
-		bank = p_global->roomBgBankNum;
-		if (bank == 76 || bank == 128)
-			bank = 2161;
-		use_bank(bank + 326);
-		noclipax(0, 0, 16);
-		use_bank(bank + 327);
-		noclipax(0, 320, 16);
-		persoinmiroir();
-		needPaletteUpdate = 1;
-		p_global->iconsIndex = 16;
-		p_global->autoDialog = 0;
-		p_global->displayFlags = DisplayFlags::dfMirror;
-		p_global->ff_102 = arg1;
-	}
-	void flipmode() {
-		if (personTalking) {
-			endpersovox();
-			if (p_global->displayFlags == DisplayFlags::dfPerson) {
-				if (p_global->perso_ptr == &kPersons[PER_THOO] && p_global->phaseNum >= 80)
-					af_subtitle();
-				else {
-					getdatasync();
-					load_perso_cour();
-					addanim();
-					restartAnimation = 1;
-					anim_perso();
-				}
-			} else
-				af_subtitle();
-			persovox();
-		} else {
-			if (p_global->displayFlags != DisplayFlags::dfFresques && p_global->displayFlags != DisplayFlags::dfFlag2) {
-				closesalle();
-				if (p_global->displayFlags & DisplayFlags::dfFlag1)
-					gametomiroir(1);
-				else {
-					quitmiroir();
-					maj_salle(p_global->roomNum);
-					if (byte_31D64) {
-						dialautoon();
-						parle_moi();
-					}
-					byte_31D64 = 0;
-				}
-			}
-		}
-	}
-	void quitmiroir() {
-		rundcurs();
-		afficher();
-		resetscroll();
-		sauvefrises();
-		p_global->displayFlags = DisplayFlags::dfFlag1;
-		p_global->ff_100 = -1;
-		p_global->eventType = EventType::etEventC;
-		p_global->ff_102 = 1;
-	}
-	void clictimbre() {
-		flipmode();
-	}
-	void clicplanval() {
-		if ((p_global->partyOutside & PersonMask::pmDina) && p_global->phaseNum == 371) {
-			quitmiroir();
-			maj_salle(p_global->roomNum);
-			return;
-		}
-		if (p_global->roomNum == 8 || p_global->roomNum < 16)
-			return;
-		rundcurs();
-		afficher();
-		if (p_global->displayFlags == DisplayFlags::dfMirror)
-			quitmiroir();
-		deplaval((p_global->roomNum & 0xFF00) | 1); //TODO: check me
-	}
-	void gotolieu(goto_t *go) {
-		p_global->valleyVidNum = go->arriveVid;
-		p_global->travelTime = go->travelTime * 256;
-		p_global->stepsToFindAppleFast = 0;
-		p_global->eventType = EventType::etEvent2;
-		init_oui();
-		showevents();
-		if (!verif_oui())
-			return;
-		if (p_global->ff_113) {
-			waitendspeak();
-			if (!pomme_q)
-				close_perso();
-		}
-		if (go->departVid) {
-			bars_out();
-			playhnm(go->departVid);
-			needToFade = 1;
-		}
-		initlieu(p_global->newRoomNum);
-		specialoutside();
-		faire_suivre(p_global->newRoomNum);
-		closesalle();
-		saved_repadam.x = -1;
-		saved_repadam.y = -1;
-		temps_passe(p_global->travelTime);
-		p_global->ff_100 = p_global->room_ptr->ff_0;
-		p_global->roomNum = p_global->newRoomNum;
-		p_global->areaNum = p_global->roomNum >> 8;
-		p_global->eventType = EventType::etEvent5;
-		p_global->newMusicType = MusicType::mt2;
-		setpersohere();
-		musique();
-		majsalle1(p_global->roomNum);
-		afftopscr();
-		saved_repadam.x = -1;
-		saved_repadam.y = -1;
-	}
-	void deplaval(unsigned short roomNum) {
-		unsigned char c1, newAreaNum, curAreaNum;
-		short newRoomNum;
-		p_global->newLocation = roomNum & 0xFF;
-		p_global->valleyVidNum = 0;
-		p_global->phaseActionsCount++;
-		closesalle();
-		endpersovox();
-		c1 = roomNum & 0xFF;
-		if (c1 == 0)
-			return;
-		if (c1 < 0x80) {
-			p_global->displayFlags = DisplayFlags::dfFlag1;
-			init_oui();
-			p_global->eventType = EventType::etEvent1;
-			showevents();
-			if (!verif_oui())
-				return;
-			if (p_global->ff_113) {
-				waitendspeak();
-				if (!pomme_q)
-					close_perso();
-			}
-			specialout();
-			if (p_global->area_ptr->type == AreaType::atValley) {
-				temps_passe(32);
-				p_global->stepsToFindAppleFast++;
-				p_global->stepsToFindAppleNormal++;
-			}
-			faire_suivre((roomNum & 0xFF00) | p_global->newLocation);
-			p_global->ff_100 = p_global->room_ptr->ff_0;
-			p_global->roomNum = roomNum;
-			p_global->areaNum = roomNum >> 8;
-			p_global->eventType = EventType::etEvent5;
-			setpersohere();
-			p_global->newMusicType = MusicType::mtNormal;
-			musique();
-			majsalle1(roomNum);
-			p_global->chrono_on = 0;
-			p_global->chrono = 0;
-			p_global->ff_54 = 0;
-			if (p_global->roomPersoType == PersonFlags::pftTyrann)
-				chronoon(3000);
-			return;
-		}
-		if (c1 == 0xFF) {
-			p_global->eventType = EventType::etEventE;
-			showevents();
-			if (!kPersons[PER_MESSAGER].roomNum) {
-				if (eloirevientq())
-					chronoon(800);
-			}
-			return;
-		}
-		p_global->stepsToFindAppleFast = 0;
-		newAreaNum = c1 & 0x7F;
-		curAreaNum = p_global->roomNum >> 8;
-		newRoomNum = newAreaNum << 8;
-		if (curAreaNum == Areas::arTausCave && newAreaNum == Areas::arMo)
-			newRoomNum |= 0x16;
-		else if (curAreaNum == Areas::arMoorkusLair)
-			newRoomNum |= 4;
-		else
-			newRoomNum |= 1;
-		p_global->newRoomNum = newRoomNum;
-		if (newAreaNum == Areas::arTausCave)
-			gotolieu(&gotos[0]);
-		else {
-			goto_t *go;
-			for (go = gotos + 1; go->curAreaNum != 0xFF; go++)
-				if (go->curAreaNum == curAreaNum) {
-					gotolieu(go);
-					break;
-				}
-		}
-	}
-	void deplacement(short dir) {
-		room_t *room = p_global->room_ptr;
-		short roomNum = p_global->roomNum;
-		debug("deplacement: from room %4X", roomNum);
-		char newLoc;
-		rundcurs();
-		afficher();
-		p_global->prevLocation = roomNum & 0xFF;
-		switch (dir) {
-		case 0:
-			newLoc = room->exits[0];
-			break;
-		case 1:
-			newLoc = room->exits[1];
-			break;
-		case 2:
-			newLoc = room->exits[2];
-			break;
-		case 3:
-			newLoc = room->exits[3];
-			break;
-		}
-		deplaval((roomNum & 0xFF00) | newLoc);
-	}
-	void deplacement2(short dir) {
-		room_t *room = p_global->room_ptr;
-		short roomNum = p_global->roomNum;
-		char newLoc;
-		p_global->prevLocation = roomNum & 0xFF;
-		switch (dir) {
-		case 0:
-			newLoc = room->exits[0];
-			break;
-		case 1:
-			newLoc = room->exits[1];
-			break;
-		case 2:
-			newLoc = room->exits[2];
-			break;
-		case 3:
-			newLoc = room->exits[3];
-			break;
-		}
-		deplaval((roomNum & 0xFF00) | newLoc);
-
-	}
-	void dinosoufle() {
-		if (p_global->curObjectId == 0) {
-			bars_out();
-			playhnm(148);
-			maj2();
-		}
-	}
-	void plaquemonk() {
-		if (p_global->curObjectId != 0) {
-			if (p_global->curObjectId == Objects::obPrism) {
-				loseobject(Objects::obPrism);
-				bars_out();
-				specialTextMode = 1;
-				playhnm(89);
-				word_2F514 |= 0x8000;
-				maj2();
-				p_global->eventType = EventType::etEventB;
-				showevents();
-			}
-		} else {
-			bars_out();
-			playhnm(7);
-			maj2();
-			p_global->eventType = EventType::etEvent4;
-			showevents();
-		}
-	}
-	void fresquesgraa() {
-		if (p_global->curObjectId == 0) {
-			p_global->fresqWidth = 320;
-			p_global->fresqImgBank = 113;
-			dofresques();
-			dinaparle();
-		}
-	}
-	void fresqueslasc() {
-		if (p_global->curObjectId == 0) {
-			p_global->fresqWidth = 112;
-			p_global->fresqImgBank = 315;
-			dofresques();
-		}
-	}
-	void pushpierre() {
-		if (p_global->curObjectId == 0) {
-			gameRooms[22].exits[0] = 17;
-			gameRooms[26].exits[2] = 9;
-			deplacement(0);
-		}
-	}
-	void tetemomie() {
-		if (p_global->curObjectId == Objects::obTooth) {
-			p_global->gameFlags |= GameFlags::gfMummyOpened;
-			deplacement(0);
-		} else if (p_global->curObjectId == 0) {
-			if (p_global->gameFlags & GameFlags::gfMummyOpened)
-				deplacement(0);
-			else {
-				p_global->eventType = EventType::etEvent6;
-				persoparle(PersonId::pidMonk);
-				p_global->eventType = 0;
-			}
-		}
-	}
-	void tetesquel() {
-		if (p_global->curObjectId == Objects::obTooth) {
-			gameRooms[22].exits[0] = 16;
-			gameRooms[26].exits[2] = 13;
-			gameIcons[16].cursor_id |= 0x8000;
-			loseobject(Objects::obTooth);
-			deplacement(0);
-		}
-	}
-	void squelmoorkong() {
-		p_global->eventType = EventType::etEvent9;
-		showevents();
-	}
-	void choisir() {
-		unsigned char obj, objid = current_spot2->object_id;
-		switch (objid) {
-		case 0:
-			obj = p_global->giveobj1;
-			break;
-		case 1:
-			obj = p_global->giveobj2;
-			break;
-		case 2:
-			obj = p_global->giveobj3;
-			break;
-		}
-		objectmain(obj);
-		winobject(obj);
-		p_global->iconsIndex = 16;
-		p_global->autoDialog = 0;
-		p_global->ff_60 = 0;
-		parle_moi();
-	}
-	void dinaparle() {
-		short num;
-		char res;
-		perso_t *perso = &kPersons[PER_DINA];
-		if (perso->party & (p_global->party | p_global->partyOutside)) {
-			if (p_global->fresqNumber < 3)
-				p_global->fresqNumber = 3;
-			p_global->fresqNumber++;
-			if (p_global->fresqNumber < 15) {
-				endpersovox();
-				if (p_global->fresqNumber == 7 && p_global->phaseNum == 113)
-					incphase1();
-				p_global->perso_ptr = perso;
-				p_global->dialogType = DialogType::dtInspect;
-				num = (perso->id << 3) | DialogType::dtInspect; //TODO: combine
-				res = dialoscansvmas((dial_t *)GetElem(gameDialogs, num));
-				fresqTalk = 0;
-				if (res) {
-					restaurefondbulle();
-					fresqTalk = 1;
-					persovox();
-				}
-				p_global->ff_CA = 0;
-				p_global->dialogType = 0;
-			} else
-				finfresques();
-		}
-	}
-	void roiparle() {
-		if (p_global->phaseNum <= 400)
-			persoparle(0);
-	}
-	void roiparle1() {
-		if (p_global->curObjectId == Objects::obSword) {
-			p_global->gameFlags |= GameFlags::gfFlag80;
-			bars_out();
-			playhnm(76);
-			deplacement2(0);
-		} else {
-			p_global->fresqNumber = 1;
-			roiparle();
-		}
-	}
-	void roiparle2() {
-		p_global->fresqNumber = 2;
-		roiparle();
-	}
-	void roiparle3() {
-		p_global->fresqNumber = 3;
-		roiparle();
-	}
-	void getcouteau() {
-		if (p_global->phaseNum >= 80) {
-			gameRooms[113].video = 0;
-			getobject(Objects::obKnife);
-		}
-		p_global->eventType = EventType::etEvent7;
-		showevents();
-	}
-	void getprisme() {
-		getobject(Objects::obPrism);
-		p_global->eventType = EventType::etEvent7;
-		showevents();
-	}
-	void getchampb() {
-		getobject(Objects::obShroom);
-	}
-	void getchampm() {
-		getobject(Objects::obBadShroom);
-	}
-	void getor() {
-		getobject(Objects::obGold);
-	}
-	void getnido() {
-		if (p_global->curObjectId != 0)
-			return;
-		p_global->room_ptr->bank = 282; //TODO: fix me
-		p_global->room_ptr--;
-		p_global->room_ptr->bank = 281; //TODO: fix me
-		p_global->room_ptr->ff_0 = 3;
-		getobject(Objects::obFullNest);
-	}
-	void getnidv() {
-		if (p_global->curObjectId != 0)
-			return;
-		p_global->room_ptr->bank = 282; //TODO: fix me
-		p_global->room_ptr--;
-		p_global->room_ptr->bank = 281; //TODO: fix me
-		p_global->room_ptr->ff_0 = 3;
-		getobject(Objects::obNest);
-	}
-	void getcorne() {
-		if (p_global->curObjectId != 0)
-			return;
-		getobject(Objects::obHorn);
-		p_global->eventType = EventType::etEvent7;
-		showevents();
-		bigphase1();
-		setpersohere();
-		p_global->room_ptr = getsalle(p_global->roomNum);
-	}
-	void getsoleil() {
-		if (p_global->curObjectId != 0)
-			return;
-		gameRooms[238].video = 0;
-		gameRooms[238].flags = RoomFlags::rf80;
-		getobject(Objects::obSunStone);
-	}
-	void getoeuf() {
-		if (p_global->curObjectId != 0)
-			return;
-		p_global->room_ptr->flags = 0;
-		p_global->room_ptr->video = 0;
-		getobject(Objects::obEgg);
-	}
-	void getplaque() {
-		int i;
-		if (p_global->curObjectId != 0 && p_global->curObjectId < Objects::obTablet1)
-			return;
-		p_global->curObjectId = 0;
-		getobject(Objects::obTablet2);
-		putobject();
-		for (i = 0; i < 6; i++)
-			objects[Objects::obTablet1 - 1 + i].count = 0;
-		p_global->curObjectFlags = 0;
-		p_global->inventoryScrollPos = 0;
-		p_global->curObjectCursor = 9;
-		gameIcons[16].cursor_id |= 0x8000;
-		showobjects();
-		gameRooms[131].video = 0;
-		bars_out();
-		playhnm(149);
-		p_global->ff_F1 = RoomFlags::rf04;
-		p_global->drawFlags = DrawFlags::drDrawFlag20;
-		normalCursor = 1;
-		maj2();
-	}
-	void voirlac() {
-		perso_t *perso = &kPersons[PER_MORKUS];
-		room_t *room = p_global->room_ptr;
-		area_t *area = p_global->area_ptr;
-		short vid = p_global->curObjectId == Objects::obApple ? 81 : 54;
-		for (++perso; perso->roomNum != 0xFFFF; perso++) {
-			if (perso->roomNum != p_global->roomNum)
-				continue;
-			vid++;
-			if (p_global->curObjectId != Objects::obApple)
-				continue;                   //TODO: pc breaks here
-			if ((perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftMosasaurus)
-				continue;
-			if (!(perso->flags & PersonFlags::pf80))
-				return;
-			perso->flags &= ~PersonFlags::pf80; //TODO: useless? see above
-			area->flags |= AreaFlags::afFlag8;
-			p_global->curAreaFlags |= AreaFlags::afFlag8;
-			room->ff_0 = 3;
-		}
-		debug("sea monster: room = %X, d0 = %X\n", p_global->roomNum, p_global->roomImgBank);
-		bars_out();
-		playhnm(vid);
-		maj_salle(p_global->roomNum);           //TODO: getting memory trashed here?
-		if (p_global->curObjectId == Objects::obApple)
-			loseobject(Objects::obApple);
-		p_global->eventType = EventType::etEventF;
-		showevents();
-	}
-	void gotohall() {
-		p_global->prevLocation = p_global->roomNum & 0xFF;
-		deplaval((p_global->roomNum & 0xFF00) | 6);
-	}
-	void demitourlabi() {
-		unsigned short target;
-		p_global->prevLocation = p_global->roomNum & 0xFF;
-		p_global->ff_100 = -1;
-		target = (p_global->roomNum & 0xFF00) | p_global->room_ptr->exits[2];
-		faire_suivre(target);
-		p_global->roomNum = target;
-		p_global->eventType = EventType::etEvent5;
-		maj_salle(p_global->roomNum);
-	}
-	void gotonido() {
-		p_global->room_ptr++;
-		p_global->eventType = 0;
-		p_global->roomImgBank = p_global->room_ptr->bank;
-		p_global->roomVidNum = p_global->room_ptr->video;
-		p_global->curRoomFlags = p_global->room_ptr->flags;
-		p_global->ff_F1 = p_global->room_ptr->flags;
-		animpiece();
-		p_global->ff_100 = 0;
-		maj2();
-	}
-	void gotoval() {
-		unsigned short target = p_global->roomNum;
-		char obj;
-		rundcurs();
-		afficher();
-		scroll_pos = 0;
-		obj = current_spot2->object_id - 14;    //TODO
-		p_global->prevLocation = target & 0xFF;
-		deplaval((target & 0xFF00) | obj);  //TODO careful!
-	}
-	void visiter() {
-		bars_out();
-		playhnm(144);
-		p_global->ff_F1 = RoomFlags::rf04;
-		maj2();
-	}
-	void final() {
-		if (p_global->curObjectId != 0)
-			return;
-		bars_out();
-		*(short *)(gameRooms + 0x6DC) = 319; //TODO
-		p_global->roomImgBank = 319;
-		playhnm(97);
-		maj2();
-		p_global->eventType = EventType::etEvent12;
-		showevents();
-		p_global->narratorSequence = 54;
-	}
-	void goto_nord() {
-		if (p_global->curObjectId == 0)
-			deplacement(0);
-	}
-	void goto_est() {
-		if (p_global->curObjectId == 0)
-			deplacement(1);
-	}
-	void goto_sud() {
-		if (p_global->curObjectId == 0)
-			deplacement(2);
-	}
-	void goto_ouest() {
-		if (p_global->curObjectId == 0)
-			deplacement(3);
-	}
-	void afficher() {
-		if (!p_global->ff_102 && !p_global->ff_103) {
-			if (needPaletteUpdate) {
-				needPaletteUpdate = 0;
-				CLPalette_Send2Screen(global_palette, 0, 256);
-			}
-			CLBlitter_CopyView2Screen(p_mainview);
-		} else {
-			if (p_global->ff_102)
-				effet3();
-			else
-				effet2();
-			p_global->ff_103 = 0;
-			p_global->ff_102 = 0;
-		}
-	}
-	void afficher128() {
-		if (p_global->updatePaletteFlag == 16) {
-			CLPalette_Send2Screen(global_palette, 0, 129);
-			CLBlitter_CopyView2Screen(p_mainview);
-			p_global->updatePaletteFlag = 0;
-		} else {
-			ClearScreen();
-			fadetoblack128(1);
-			if (showBlackBars)
-				blackbars();
-			CLBlitter_CopyView2Screen(p_mainview);
-			fadefromblack128(1);
-		}
-	}
-	void sauvefrises() {
-		sauvefriseshaut(0);
-		sauvefrisesbas();
-	}
-	void sauvefriseshaut(short x) { // Save top bar
-		underTopBarScreenRect.sy = 0;       //TODO: wrong fields order?
-		underTopBarScreenRect.sx = x;
-		underTopBarScreenRect.ex = x + 320 - 1;
-		underTopBarScreenRect.ey = 15;
-		underTopBarBackupRect.sy = 0;
-		underTopBarBackupRect.sx = 0;
-		underTopBarBackupRect.ex = 320 - 1;
-		underTopBarBackupRect.ey = 15;
-		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
-	}
-	void sauvefrisesbas() {         // Save bottom bar
-		underBottomBarScreenRect.sx = 0;
-		underBottomBarScreenRect.ex = 320 - 1;
-		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
-	}
-	void restaurefrises() {
-		restaurefriseshaut();
-		restaurefrisesbas();
-	}
-	void restaurefriseshaut() {
-		underTopBarScreenRect.sx = scroll_pos;
-		underTopBarScreenRect.ex = scroll_pos + 320 - 1;
-		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarBackupRect, &underTopBarScreenRect);
-	}
-	void restaurefrisesbas() {
-		underBottomBarScreenRect.sx = scroll_pos;
-		underBottomBarScreenRect.ex = scroll_pos + 320 - 1;
-		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underBottomBarBackupRect, &underBottomBarScreenRect);
-	}
-	void use_main_bank() {
-		bank_data_ptr = main_bank_buf;
-	}
-	void use_bank(short bank) {
-		if (bank > 2500)
-			debug("attempt to load bad bank %d", bank);
-		bank_data_ptr = bank_data_buf;
-		if (cur_bank_num != bank) {
-			loadfile(bank, bank_data_buf);
-			verifh(bank_data_buf);
-			cur_bank_num = bank;
-		}
-	}
-	void sundcurs(short x, short y) {
-		unsigned char *scr, *keep = curs_keepbuf;
-		short w, h;
-		curs_keepx = x - 4;
-		curs_keepy = y - 4;
-		scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
-		for (h = 48; h--;) {
-			for (w = 48; w--;)
-				*keep++ = *scr++;
-			scr += 640 - 48;
-		}
-		curs_saved = 1;
-	}
-	void rundcurs() {
-		unsigned char *scr, *keep = curs_keepbuf;
-		short w, h;
-		scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
-		if (!curs_saved || (curs_keepx == -1 && curs_keepy == -1))  //TODO ...
-			return;
-		for (h = 48; h--;) {
-			for (w = 48; w--;)
-				*scr++ = *keep++;
-			scr += 640 - 48;
-		}
-
-	}
-	void noclipax(short index, short x, short y) {
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char h0, h1, mode;
-		short w, h;
-		if (cur_bank_num != 117 && !no_palette) {
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
-		}
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		debug("- draw sprite %d at %d:%d, %dx%d", index, x, y, w, h);
-		if (mode != 0xFF && mode != 0xFE)
-			return;
-		if (y + h > 200)
-			h -= (y + h - 200);
-		if (h1 & 0x80) {
-			// compressed
-			for (; h-- > 0;) {
-				short ww;
-				for (ww = w; ww > 0;) {
-					unsigned char c = *pix++;
-					if (c >= 0x80) {
-						if (c == 0x80) {
-							unsigned char fill = *pix++;
-							if (fill == 0) {
-								scr += 128 + 1;
-								ww -= 128 + 1;
-							} else {
-								unsigned char run;
-								*scr++ = fill;  //TODO: wha?
-								*scr++ = fill;
-								ww -= 128 + 1;
-								for (run = 127; run--;)
-									*scr++ = fill;
-							}
-						} else {
-							unsigned char fill = *pix++;
-							unsigned char run = 255 - c + 2;
-							ww -= run;
-							if (fill == 0)
-								scr += run;
-							else
-								for (; run--;)
-									*scr++ = fill;
-						}
-					} else {
-						unsigned char run = c + 1;
-						ww -= run;
-						for (; run--;) {
-							unsigned char p = *pix++;
-							if (p == 0)
-								scr++;
-							else
-								*scr++ = p;
-						}
-					}
-				}
-				scr += 640 - w;
-			}
-		} else {
-			// uncompressed
-			for (; h--;) {
-				short ww;
-				for (ww = w; ww--;) {
-					unsigned char p = *pix++;
-					if (p == 0)
-						scr++;
-					else
-						*scr++ = p;
-				}
-				scr += 640 - w;
-			}
-		}
-	}
-	void noclipax_avecnoir(short index, short x, short y) {
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char h0, h1, mode;
-		short w, h;
-		if (cur_bank_num != 117) {
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
-		}
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		if (mode != 0xFF && mode != 0xFE)
-			return;
-		if (y + h > 200)
-			h -= (y + h - 200);
-		if (h1 & 0x80) {
-			// compressed
-			for (; h-- > 0;) {
-				short ww;
-				for (ww = w; ww > 0;) {
-					unsigned char c = *pix++;
-					if (c >= 0x80) {
-						if (c == 0x80) {
-							unsigned char fill = *pix++;
-							unsigned char run;
-							*scr++ = fill;  //TODO: wha?
-							*scr++ = fill;
-							ww -= 128 + 1;
-							for (run = 127; run--;)
-								*scr++ = fill;
-						} else {
-							unsigned char fill = *pix++;
-							unsigned char run = 255 - c + 2;
-							ww -= run;
-							for (; run--;)
-								*scr++ = fill;
-						}
-					} else {
-						unsigned char run = c + 1;
-						ww -= run;
-						for (; run--;) {
-							unsigned char p = *pix++;
-							*scr++ = p;
-						}
-					}
-				}
-				scr += 640 - w;
-			}
-		} else {
-			// uncompressed
-			for (; h--;) {
-				short ww;
-				for (ww = w; ww--;) {
-					unsigned char p = *pix++;
-					*scr++ = p;
-				}
-				scr += 640 - w;
-			}
-		}
-	}
-	void getglow(short x, short y, short w, short h) {
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char *gl = glow_buffer;
-		glow_x = x;
-		glow_y = y;
-		glow_w = w;
-		glow_h = h;
-		for (; h--;) {
-			short ww;
-			for (ww = w; ww--;)
-				*gl++ = *scr++;
-			scr += 640 - w;
-		}
-	}
-	void unglow() {
-		unsigned char *gl = glow_buffer;
-		unsigned char *scr = p_mainview_buf + glow_x + glow_y * 640;
-		if (glow_x < 0 || glow_y < 0)   //TODO: move it up
-			return;
-		for (; glow_h--;) {
-			short ww;
-			for (ww = glow_w; ww--;)
-				*scr++ = *gl++;
-			scr += 640 - glow_w;
-		}
-	}
-	void glow(short index) {
-		unsigned char pixbase;
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr;
-		unsigned char h0, h1, mode;
-		short w, h, x, y, ex, dx, dy, pstride, sstride;
-		index += 9;
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		if (mode != 0xFF && mode != 0xFE)
-			return;
-
-		x = curs_x + scroll_pos - 38;
-		y = curs_y - 28;
-		ex = p_global->fresqWidth + 320;
-
-		if (x + w <= 0 || x >= ex || y + h <= 0 || y >= 176)
-			return;
-
-		if (x < 0) {
-			dx = -x;
-			x = 0;
-		} else if (x + w > ex)
-			dx = x + w - ex;
-		else
-			dx = 0;
-
-		if (y < 16) {
-			dy = 16 - y;
-			y = 16;
-		} else if (y + h > 175)
-			dy = y + h - 175;
-		else
-			dy = 0;
-		pstride = dx;
-		sstride = 640 - (w - dx);
-		if (y == 16)
-			pix += w * dy;
-		if (x == 0)
-			pix += dx;
-
-		scr = p_mainview_buf + x + y * 640;
-
-		w -= dx;
-		h -= dy;
-
-		getglow(x, y, w, h);
-
-		for (; h--;) {
-			short ww;
-			for (ww = w; ww--;) {
-				unsigned char p = *pix++;
-				if (p == 0)
-					scr++;
-				else
-					*scr++ += p << 4;
-			}
-			pix += pstride;
-			scr += sstride;
-		}
-	}
-	void readpalette(unsigned char *ptr) {
-		int doit = 1;
-		while (doit) {
-			unsigned short idx = *ptr++;
-			if (idx != 0xFF) {
-				unsigned short cnt = *ptr++;
-				while (cnt--) {
-					if (idx == 0) {
-						pal_entry.r = 0;
-						pal_entry.g = 0;
-						pal_entry.b = 0;
-						ptr += 3;
-					} else {
-						pal_entry.r = *ptr++ << 10;
-						pal_entry.g = *ptr++ << 10;
-						pal_entry.b = *ptr++ << 10;
-					}
-					CLPalette_SetRGBColor(global_palette, idx, &pal_entry);
-					idx++;
-				}
-			} else
-				doit = 0;
-		}
-	}
-	void spritesurbulle(short index, short x, short y) {
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_subtitlesview_buf + x + y * subtitles_x_width;
-		unsigned char h0, h1, mode;
-		short w, h;
-		if (cur_bank_num != 117) {
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
-		}
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		if (mode != 0xFF && mode != 0xFE)
-			return;
-		if (h1 & 0x80) {
-			// compressed
-			for (; h-- > 0;) {
-				short ww;
-				for (ww = w; ww > 0;) {
-					unsigned char c = *pix++;
-					if (c >= 0x80) {
-						if (c == 0x80) {
-							unsigned char fill = *pix++;
-							if (fill == 0) {
-								scr += 128 + 1;
-								ww -= 128 + 1;
-							} else {
-								unsigned char run;
-								*scr++ = fill;  //TODO: wha?
-								*scr++ = fill;
-								ww -= 128 + 1;
-								for (run = 127; run--;)
-									*scr++ = fill;
-							}
-						} else {
-							unsigned char fill = *pix++;
-							unsigned char run = 255 - c + 2;
-							ww -= run;
-							if (fill == 0)
-								scr += run;
-							else
-								for (; run--;)
-									*scr++ = fill;
-						}
-					} else {
-						unsigned char run = c + 1;
-						ww -= run;
-						for (; run--;) {
-							unsigned char p = *pix++;
-							if (p == 0)
-								scr++;
-							else
-								*scr++ = p;
-						}
-					}
-				}
-				scr += subtitles_x_width - w;
-			}
-		} else {
-			// uncompressed
-			for (; h--;) {
-				short ww;
-				for (ww = w; ww--;) {
-					unsigned char p = *pix++;
-					if (p == 0)
-						scr++;
-					else
-						*scr++ = p;
-				}
-				scr += subtitles_x_width - w;
-			}
-		}
-	}
-	void bars_out() {
-		short i, r19, r20, r25, r24;
-		unsigned int *scr40, *scr41, *scr42;
-		if (showBlackBars)
-			return;
-		afficher();
-		underTopBarScreenRect.sx = scroll_pos;
-		underTopBarScreenRect.ex = scroll_pos + 320 - 1;
-		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
-		underBottomBarScreenRect.sx = underTopBarScreenRect.sx;
-		underBottomBarScreenRect.ex = underTopBarScreenRect.ex;
-		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
-		r19 = 14;   // TODO - init in decl?
-		r20 = 176;
-		r25 = 14;
-		r24 = 21;
-		underTopBarScreenRect.sx = 0;
-		underTopBarScreenRect.ex = 320 - 1;
-		underTopBarBackupRect.sx = scroll_pos;
-		underTopBarBackupRect.ex = scroll_pos + 320 - 1;
-		while (r24 > 0) {
-			if (r25 > 0) {
-				underTopBarScreenRect.sy = 16 - r25;
-				underTopBarScreenRect.ey = 16 - 1;
-				underTopBarBackupRect.sy = 0;
-				underTopBarBackupRect.ey = r25 - 1;
-				CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-				scr40 = ((unsigned int *)p_mainview_buf) + r19 * 640 / 4;
-				scr41 = scr40 + 640 / 4;
-				for (i = 0; i < 320; i += 4) {
-					*scr40++ = 0;
-					*scr41++ = 0;
-				}
-			}
-			underTopBarScreenRect.sy = 16;
-			underTopBarScreenRect.ey = r24 + 16 - 1;
-			underTopBarBackupRect.sy = 200 - r24;
-			underTopBarBackupRect.ey = 200 - 1;
-			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-			scr40 = ((unsigned int *)p_mainview_buf) + r20 * 640 / 4;
-			scr41 = scr40 + 640 / 4;
-			scr42 = scr41 + 640 / 4;
-			for (i = 0; i < 320; i += 4) {
-				*scr40++ = 0;
-				*scr41++ = 0;
-				*scr42++ = 0;
-			}
-			r19 -= 2;
-			r20 += 3;
-			r25 -= 2;
-			r24 -= 3;
-			afficher();
-		}
-		scr40 = (unsigned int *)p_mainview_buf;
-		scr41 = scr40 + 640 / 4;
-		for (i = 0; i < 320; i += 4) {
-			*scr40++ = 0;
-			*scr41++ = 0;
-		}
-		scr40 = ((unsigned int *)p_mainview_buf) + r20 * 640 / 4;
-		scr41 = scr40 + 640 / 4;
-		scr42 = scr41 + 640 / 4;
-		for (i = 0; i < 320; i += 4) {
-			*scr40++ = 0;
-			*scr41++ = 0;
-			*scr42++ = 0;
-		}
-		afficher();
-		initrect();
-		showBlackBars = 1;
-	}
-	void bars_in() {
-		short r29, r28;
-		if (!showBlackBars)
-			return;
-		blackbars();
-		r29 = 2;
-		r28 = 2;
-		underTopBarScreenRect.sx = 0;
-		underTopBarScreenRect.ex = 320 - 1;
-		underTopBarBackupRect.sx = scroll_pos;
-		underTopBarBackupRect.ex = scroll_pos + 320 - 1;
-		while (r28 < 24) {
-			if (r29 <= 16) {
-				underTopBarScreenRect.sy = 16 - r29;
-				underTopBarScreenRect.ey = 16 - 1;
-				underTopBarBackupRect.sy = 0;
-				underTopBarBackupRect.ey = r29 - 1;
-				CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-			}
-			underTopBarScreenRect.sy = 16;
-			underTopBarScreenRect.ey = 16 + r28;
-			underTopBarBackupRect.sy = 200 - 1 - r28;
-			underTopBarBackupRect.ey = 200 - 1;
-			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
-			r29 += 2;
-			r28 += 3;
-			afficher();
-		}
-		initrect();
-		showBlackBars = 0;
-	}
-	void sauvefondbouche() {
-		rect_src.sx = cur_perso_rect->sx;
-		rect_src.sy = cur_perso_rect->sy;
-		rect_src.ex = cur_perso_rect->ex;
-		rect_src.ey = cur_perso_rect->ey;
-		rect_dst.sx = cur_perso_rect->sx + 320;
-		rect_dst.sy = cur_perso_rect->sy;
-		rect_dst.ex = cur_perso_rect->ex + 320;
-		rect_dst.ey = cur_perso_rect->ey;
-		CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_src, &rect_dst);
-		fond_saved = 1;
-	}
-	void restaurefondbouche() {
-		rect_src.sx = cur_perso_rect->sx;
-		rect_src.sy = cur_perso_rect->sy;
-		rect_src.ex = cur_perso_rect->ex;
-		rect_src.ey = cur_perso_rect->ey;
-		rect_dst.sx = cur_perso_rect->sx + 320;
-		rect_dst.sy = cur_perso_rect->sy;
-		rect_dst.ex = cur_perso_rect->ex + 320;
-		rect_dst.ey = cur_perso_rect->ey;
-		CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_dst, &rect_src);
-	}
-	void blackbars() {
-		unsigned char *scr = p_mainview_buf;
-		short x, y;
-		for (y = 0; y < 16; y++)
-			for (x = 0; x < 640; x++)
-				*scr++ = 0;
-		scr += 640 * (200 - 16 - 24);
-		for (y = 0; y < 24; y++)
-			for (x = 0; x < 640; x++)
-				*scr++ = 0;
-	}
-	void afftopscr() {  // Draw  top bar (location / party / map)
-		perso_t *perso;
-		p_global->drawFlags &= ~DrawFlags::drDrawTopScreen;
-		use_bank(314);
-		noclipax(36, 83, 0);
-		noclipax(p_global->area_ptr->num - 1, 0, 0);
-		noclipax(23, 145, 0);
-		for (perso = &kPersons[PER_DINA]; perso != &kPersons[PER_UNKN_156]; perso++) {
-			if ((perso->flags & PersonFlags::pfInParty) && !(perso->flags & PersonFlags::pf80))
-				noclipax(perso->targetLoc + 18, perso->lastLoc + 120, 0);
-		}
-		saved_repadam.x = -1;
-		saved_repadam.y = -1;
-		affplanval();
-		needPaletteUpdate = 1;
-	}
-	void affplanval() { // Draw mini-map
-		short loc;
-		perso_t *perso;
-		if (p_global->area_ptr->type == AreaType::atValley) {
-			noclipax(p_global->area_ptr->num + 9, 266, 1);
-			for (perso = &kPersons[PER_UNKN_18C]; perso->roomNum != 0xFFFF; perso++) {
-				if (((perso->roomNum >> 8) == p_global->areaNum)
-				        && !(perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pf20))
-					affrepere(33, perso->roomNum & 0xFF);
-			}
-			if (p_global->area_ptr->citadelLevel)
-				affrepere(34, p_global->area_ptr->citadelRoom->location);
-			sauvefriseshaut(0);
-			loc = p_global->roomNum & 0xFF;
-			if (loc >= 16)
-				affrepereadam(loc);
-			restaurefriseshaut();
-		} else {
-			sauvefriseshaut(0);
-			restaurefriseshaut();
-		}
-	}
-	void affrepere(short index, short location) {
-		noclipax(index, 269 + location % 16 * 4, 2 + (location - 16) / 16 * 3);
-	}
-	void affrepereadam(short location) {
-		short x = 269;
-		short y = 2;
-		short w;
-		unsigned char *pix;
-		rest_repadam();
-		if (location > 15 && location < 76) {
-			x += (location & 15) * 4;
-			y += ((location - 16) >> 4) * 3;
-			save_repadam(x, y);
-			pix = p_underBarsView->p_buffer;
-			w = p_underBarsView->width;
-			pix += x + w * y;
-			pix[1] = 0xC3;
-			pix[2] = 0xC3;
-			pix += w;
-			pix[0] = 0xC3;
-			pix[1] = 0xC3;
-			pix[2] = 0xC3;
-			pix[3] = 0xC3;
-			pix += w;
-			pix[1] = 0xC3;
-			pix[2] = 0xC3;
-		}
-	}
-	void rest_repadam() {
-		short x, y, w;
-		unsigned char *pix;
-		if (saved_repadam.x == -1 && saved_repadam.y == -1)
-			return;
-		x = saved_repadam.x;
-		y = saved_repadam.y;
-		pix = p_underBarsView->p_buffer;
-		w = p_underBarsView->width;
-		pix += x + w * y;
-		pix[1] = keep01;    //TODO keep is array?
-		pix[2] = keep02;
-		pix += w;
-		pix[0] = keep10;
-		pix[1] = keep11;
-		pix[2] = keep12;
-		pix[3] = keep13;
-		pix += w;
-		pix[1] = keep21;
-		pix[2] = keep22;
-	}
-	void save_repadam(short x, short y) {
-		short w;
-		unsigned char *pix;
-		saved_repadam.x = x;
-		saved_repadam.y = y;
-		pix = p_underBarsView->p_buffer;
-		w = p_underBarsView->width;
-		pix += x + w * y;
-		keep01 = pix[1];
-		keep02 = pix[2];
-		pix += w;
-		keep10 = pix[0];
-		keep11 = pix[1];
-		keep12 = pix[2];
-		keep13 = pix[3];
-		pix += w;
-		keep21 = pix[1];
-		keep22 = pix[2];
-	}
-	char istrice(short roomNum) {
-		char loc = roomNum & 0xFF;
-		short area = roomNum & 0xFF00;
-		perso_t *perso;
-		for (perso = &kPersons[PER_UNKN_18C]; perso != &kPersons[PER_UNKN_372]; perso++) {
-			if ((perso->flags & PersonFlags::pf80) || (perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftTriceraptor)
-				continue;
-			if (perso->roomNum == (area | (loc - 16)))
-				return 1;
-			if (perso->roomNum == (area | (loc + 16)))
-				return 1;
-			if (perso->roomNum == (area | (loc - 1)))
-				return 1;
-			if (perso->roomNum == (area | (loc + 1)))
-				return 1;
-		}
-		return 0;
-	}
-	char istyran(short roomNum) {
-		char loc = roomNum & 0xFF;
-		short area = roomNum & 0xFF00;
-		// TODO: orig bug: this ptr is not initialized when first called from getsalle
-		// PC version scans kPersons[] directly and is not affected
-		if (!tyranPtr)
-			return 0;
-
-		for (; tyranPtr->roomNum != 0xFFFF; tyranPtr++) {
-			if (tyranPtr->flags & PersonFlags::pf80)
-				continue;
-			if (tyranPtr->roomNum == (area | (loc - 16)))
-				return 1;
-			if (tyranPtr->roomNum == (area | (loc + 16)))
-				return 1;
-			if (tyranPtr->roomNum == (area | (loc - 1)))
-				return 1;
-			if (tyranPtr->roomNum == (area | (loc + 1)))
-				return 1;
-		}
-		return 0;
-	}
-	void istyranval(area_t *area) {
-		perso_t *perso;
-		unsigned char areaNum = area->num;
-		area->flags &= ~AreaFlags::HasTyrann;
-		for (perso = &kPersons[PER_UNKN_372]; perso->roomNum != 0xFFFF; perso++) {
-			if (perso->flags & PersonFlags::pf80)
-				continue;
-			if ((perso->roomNum >> 8) == areaNum) {
-				area->flags |= AreaFlags::HasTyrann;
-				break;
-			}
-		}
-	}
-	char getdirection(perso_t *perso) {
-		char dir = -1;
-		unsigned char trgLoc = perso->targetLoc;
-		unsigned char curLoc = perso->roomNum & 0xFF;   //TODO name
-		if (curLoc != trgLoc) {
-			curLoc &= 0xF;
-			trgLoc &= 0xF;
-			if (curLoc != trgLoc) {
-				dir = 2;
-				if (curLoc > trgLoc)
-					dir = 5;
-			}
-			trgLoc = perso->targetLoc;
-			curLoc = perso->roomNum & 0xFF;
-			curLoc &= 0xF0;
-			trgLoc &= 0xF0;
-			if (curLoc != trgLoc) {
-				if (curLoc > trgLoc)
-					dir++;
-				dir++;
-			}
-		}
-		return dir;
-	};
-	char caselibre(char loc, perso_t *perso) {
-		short roomNum;
-		room_t *room = p_global->cita_area_firstRoom;
-		if (loc <= 0x10 || loc > 76 || (loc & 0xF) >= 12 || loc == perso->lastLoc)
-			return 0;
-		roomNum = (perso->roomNum & ~0xFF) | loc;   //TODO: danger! signed
-		if (roomNum == p_global->roomNum)
-			return 0;
-		for (; room->ff_0 != 0xFF; room++) {
-			if (room->location != loc)
-				continue;
-			if (!(room->flags & RoomFlags::rf01))
-				return 0;
-			for (perso = &kPersons[PER_UNKN_18C]; perso->roomNum != 0xFFFF; perso++) {
-				if (perso->flags & PersonFlags::pf80)
-					continue;
-				if (perso->roomNum == roomNum)
-					break;
-			}
-			if (perso->roomNum != 0xFFFF)
-				return 0;
-			return 1;
-		}
-		return 0;
-	}
-	void melange1(char elem[4]) {
-		if (g_ed->_rnd->getRandomNumber(1) & 1) {
-			char e1 = elem[1];
-			char e2 = elem[2];
-			elem[1] = e2;
-			elem[2] = e1;
-		}
-	}
-	void melange2(char elem[4]) {
-		if (g_ed->_rnd->getRandomNumber(1) & 1) {
-			char e0 = elem[0];
-			char e1 = elem[1];
-			elem[0] = e1;
-			elem[1] = e0;
-		}
-		if (g_ed->_rnd->getRandomNumber(1) & 1) {
-			char e2 = elem[2];
-			char e3 = elem[3];
-			elem[2] = e3;
-			elem[3] = e2;
-		}
-	}
-	void melangedir() {
-		melange1(tab_2CB1E[0]);
-		melange1(tab_2CB1E[1]);
-		melange1(tab_2CB1E[2]);
-		melange2(tab_2CB1E[3]);
-		melange2(tab_2CB1E[4]);
-		melange1(tab_2CB1E[5]);
-		melange2(tab_2CB1E[6]);
-		melange2(tab_2CB1E[7]);
-	}
-	char naitredino(char persoType) {
-		perso_t *perso;
-		for (perso = &kPersons[PER_MORKUS]; (++perso)->roomNum != 0xFFFF;) {
-			char areaNum = perso->roomNum >> 8;
-			if (areaNum != p_global->cita_area_num)
-				continue;
-			if ((perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pfTypeMask) == persoType) {
-				perso->flags &= ~PersonFlags::pf80;
-				return 1;
-			}
-		}
-		return 0;
-	}
-	void newcita(char arg1, short arg2, room_t *room) {
-		unsigned short index;
-		short *ptr;
-		cita_t *cita = cita_list;
-		while (cita->ff_0 < arg2)
-			cita++;
-		index = ((room->flags & 0xC0) >> 6);    //TODO: this is very wrong
-		ptr = cita->ff_2 + index * 2;
-		if (arg1 == 4 || arg1 == 6)
-			ptr++;
-		room->bank = ptr[0];
-		room->video = ptr[8];
-		room->flags |= RoomFlags::rf02;
-	}
-	void citaevol(short level) {
-		room_t *room = p_global->cur_area_ptr->citadelRoom;
-		perso_t *perso = &kPersons[PER_UNKN_372];
-		unsigned char speed, loc = room->location;
-		if (level >= 80 && !istrice((p_global->cita_area_num << 8) | room->location)) { //TODO: loc ?
-			room->level = 79;
-			return;
-		}
-		if (level > 160)
-			level = 160;
-		if (room->level < 64 && level >= 64 && naitredino(PersonFlags::pftTriceraptor)) {
-			p_global->cur_area_ptr->flags |= AreaFlags::HasTriceraptors;
-			ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
-		}
-		if (room->level < 40 && level >= 40 && naitredino(PersonFlags::pftVelociraptor)) {
-			p_global->cur_area_ptr->flags |= AreaFlags::HasVelociraptors;
-			ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsIn);
-		}
-		room->level = level;
-		newcita(p_global->cita_area_num, level, room);
-		speed = kDinoSpeedForCitaLevel[room->level >> 4];
-		for (; perso->roomNum != 0xFFFF; perso++) {
-			if (perso->flags & PersonFlags::pf80)
-				continue;
-			if ((perso->roomNum >> 8) == p_global->cita_area_num && perso->targetLoc == loc)
-				perso->speed = speed;
-		}
-	}
-	void citacapoute(short roomNum) {
-		perso_t *perso = &kPersons[PER_UNKN_18C];
-		room_t *room = p_global->cur_area_ptr->citadelRoom;
-		room->flags |= RoomFlags::rf01;
-		room->flags &= ~RoomFlags::rfHasCitadel;
-		room->bank = 193;
-		room->video = 0;
-		room->level = 0;
-		p_global->cur_area_ptr->citadelLevel = 0;
-		p_global->cur_area_ptr->citadelRoom = 0;
-		roomNum = (roomNum & ~0xFF) | room->location;
-		for (; perso->roomNum != 0xFFFF; perso++) {
-			if (perso->roomNum == roomNum) {
-				perso->flags &= ~PersonFlags::pf80;
-				delinfo((roomNum >> 8) + ValleyNews::vnTyrannIn);
-				break;
-			}
-		}
-	}
-	void buildcita() {
-		area_t *area = p_global->area_ptr;
-		p_global->cur_area_ptr = p_global->area_ptr;
-		if (area->citadelRoom)
-			citacapoute(p_global->roomNum);
-		p_global->ff_6A = p_global->ff_69;
-		p_global->narratorSequence = p_global->ff_69 | 0x80;
-		area->citadelRoom = p_global->room_ptr;
-		p_global->room_ptr->flags &= ~RoomFlags::rf01;
-		p_global->room_ptr->flags |= RoomFlags::rfHasCitadel;
-		p_global->room_ptr->level = 32;
-		newcita(p_global->areaNum, 32, p_global->room_ptr);
-		area->flags &= ~AreaFlags::TyrannSighted;
-		if (!(area->flags & AreaFlags::afFlag8000)) {
-			if (p_global->phaseNum == 304 || p_global->phaseNum != 384) //TODO: wha
-				eloirevient();
-			area->flags |= AreaFlags::afFlag8000;
-		}
-		p_global->room_perso->flags |= PersonFlags::pf80;
-		p_global->cita_area_num = p_global->areaNum;
-		naitredino(1);
-		delinfo(p_global->areaNum + ValleyNews::vnCitadelLost);
-		delinfo(p_global->areaNum + ValleyNews::vnTyrannLost);
-		if (p_global->phaseNum == 193 && p_global->areaNum == Areas::arUluru)
-			bigphase1();
-	}
-	void citatombe(char level) {
-		if (level)
-			newcita(p_global->cita_area_num, level, p_global->cur_area_ptr->citadelRoom);
-		else {
-			citacapoute(p_global->cita_area_num << 8);
-			ajouinfo(p_global->cita_area_num + ValleyNews::vnCitadelLost);
-		}
-	}
-	void constcita() {
-		unsigned char level;
-		room_t *room;
-		unsigned char loc;
-//	room_t *room = p_global->cur_area_ptr->room_ptr; //TODO: wrong? chk below
-//	unsigned char id = room->ff_C;
-		if (!p_global->cur_area_ptr->citadelLevel || !p_global->cur_area_ptr->citadelRoom)
-			return;
-		room = p_global->cur_area_ptr->citadelRoom; //TODO: copied here by me
-		loc = room->location;
-		tyranPtr = &kPersons[PER_UNKN_372];
-		if (istyran((p_global->cita_area_num << 8) | loc)) {
-			if (!(p_global->cur_area_ptr->flags & AreaFlags::TyrannSighted)) {
-				ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
-				p_global->cur_area_ptr->flags |= AreaFlags::TyrannSighted;
-			}
-			level = room->level - 1;
-			if (level < 32)
-				level = 32;
-			room->level = level;
-			citatombe(level);
-		} else {
-			p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
-			citaevol(room->level + 1);
-		}
-	}
-	void depladino(perso_t *perso) {
-		char *dirs, dir, dir2;
-		unsigned char loc;
-		dir = getdirection(perso);
-		if (dir != -1) {
-			melangedir();
-			dirs = tab_2CB1E[dir];
-			loc = perso->roomNum & 0xFF;
-			dir2 = *dirs++;
-			if (dir2 & 0x80)
-				dir2 = -(dir2 & ~0x80);
-			dir2 += loc;
-			if (caselibre(dir2, perso))
-				goto ok;
-			dir2 = *dirs++;
-			if (dir2 & 0x80)
-				dir2 = -(dir2 & ~0x80);
-			dir2 += loc;
-			if (caselibre(dir2, perso))
-				goto ok;
-			dir2 = *dirs++;
-			if (dir2 & 0x80)
-				dir2 = -(dir2 & ~0x80);
-			dir2 += loc;
-			if (caselibre(dir2, perso))
-				goto ok;
-			dir2 = *dirs++;
-			if (dir2 & 0x80)
-				dir2 = -(dir2 & ~0x80);
-			dir2 += loc;
-			if (caselibre(dir2, perso))
-				goto ok;
-			dir2 = perso->lastLoc;
-			perso->lastLoc = 0;
-			if (!caselibre(dir2, perso))
-				return;
-ok:
-			;
-			perso->lastLoc = perso->roomNum & 0xFF;
-			perso->roomNum &= ~0xFF;
-			perso->roomNum |= dir2 & 0xFF;
-			if (perso->targetLoc - 16 == (perso->roomNum & 0xFF))
-				perso->targetLoc = 0;
-			if (perso->targetLoc + 16 == (perso->roomNum & 0xFF))
-				perso->targetLoc = 0;
-			if (perso->targetLoc - 1 == (perso->roomNum & 0xFF))
-				perso->targetLoc = 0;
-			if (perso->targetLoc + 1 == (perso->roomNum & 0xFF))
-				perso->targetLoc = 0;
-		} else
-			perso->targetLoc = 0;
-	}
-	void deplaalldino() {
-		perso_t *perso = &kPersons[PER_UNKN_18C - 1];   //TODO fix this
-		while ((++perso)->roomNum != 0xFFFF) {
-			if (((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
-				continue;
-			if (perso->flags & PersonFlags::pf80)
-				continue;
-			if (!perso->targetLoc)
-				continue;
-			if (--perso->steps)
-				continue;
-			perso->steps = 1;
-			if (perso->roomNum == p_global->roomNum)
-				continue;
-			perso->steps = perso->speed;
-			depladino(perso);
-		}
-	}
-	void newvallee() {
-		perso_t *perso = &kPersons[PER_UNKN_372];
-		short *ptr = tab_2CB16;
-		short roomNum;
-		while ((roomNum = *ptr++) != -1) {
-			perso->roomNum = roomNum;
-			perso->flags &= ~PersonFlags::pf80;
-			perso->flags &= ~PersonFlags::pf20; //TODO: combine?
-			perso++;
-		}
-		perso->roomNum = -1;
-		kAreasTable[7].flags |= AreaFlags::HasTyrann;
-		p_global->worldHasTyrann = 32;
-	}
-	char whereiscita() {
-		room_t *room = p_global->cita_area_firstRoom;
-		char res = -1;
-		for (; room->ff_0 != 0xFF; room++) {
-			if (!(room->flags & RoomFlags::rfHasCitadel))
-				continue;
-			res = room->location;
-			break;
-		}
-		return res;
-	}
-	char iscita(short loc) {
-		room_t *room = p_global->cita_area_firstRoom;
-		loc &= 0xFF;
-		for (; room->ff_0 != 0xFF; room++) {
-			if (!(room->flags & RoomFlags::rfHasCitadel))
-				continue;
-			if (room->location == loc + 16)
-				return 1;
-			if (room->location == loc - 16)
-				return 1;
-			if (room->location == loc - 1)
-				return 1;
-			if (room->location == loc + 1)
-				return 1;
-		}
-		return 0;
-	}
-	void lieuvava(area_t *area) {
-		unsigned char mask;
-		if (area->type == AreaType::atValley) {
-			istyranval(area);
-			area->citadelLevel = 0;
-			if (area->citadelRoom)
-				area->citadelLevel = p_global->cita_area_firstRoom->level;  //TODO: no search?
-			mask = ~(1 << (area->num - Areas::arChamaar));
-			p_global->worldTyrannSighted &= mask;
-			p_global->ff_4E &= mask;
-			p_global->worldGaveGold &= mask;
-			p_global->worldHasVelociraptors &= mask;
-			p_global->worldHasTriceraptors &= mask;
-			p_global->worldHasTyrann &= mask;
-			p_global->ff_53 &= mask;
-			mask = ~mask;
-			if (area->flags & AreaFlags::TyrannSighted)
-				p_global->worldTyrannSighted |= mask;
-			if (area->flags & AreaFlags::afFlag4)
-				p_global->ff_4E |= mask;
-			if (area->flags & AreaFlags::HasTriceraptors)
-				p_global->worldHasTriceraptors |= mask;
-			if (area->flags & AreaFlags::afGaveGold)
-				p_global->worldGaveGold |= mask;
-			if (area->flags & AreaFlags::HasVelociraptors)
-				p_global->worldHasVelociraptors |= mask;
-			if (area->flags & AreaFlags::HasTyrann)
-				p_global->worldHasTyrann |= mask;
-			if (area->flags & AreaFlags::afFlag20)
-				p_global->ff_53 |= mask;
-			if (area == p_global->area_ptr) {
-				p_global->curAreaFlags = area->flags;
-				p_global->curCitadelLevel = area->citadelLevel;
-			}
-		}
-		p_global->ff_4D &= p_global->worldTyrannSighted;
-	}
-	void vivredino() {
-		char cita;
-		perso_t *perso = &kPersons[PER_UNKN_18C];
-		for (; perso->roomNum != 0xFFFF; perso++) {
-			if (((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
-				continue;
-			if (perso->flags & PersonFlags::pf80)
-				continue;
-			switch (perso->flags & PersonFlags::pfTypeMask) {
-			case PersonFlags::pftTyrann:
-				if (iscita(perso->roomNum))
-					perso->targetLoc = 0;
-				else if (!perso->targetLoc) {
-					cita = whereiscita();
-					if (cita != -1) {
-						perso->targetLoc = cita;
-						perso->speed = 2;
-						perso->steps = 1;
-					}
-				}
-				break;
-			case PersonFlags::pftTriceraptor:
-				if (perso->flags & PersonFlags::pfInParty) {
-					if (iscita(perso->roomNum))
-						perso->targetLoc = 0;
-					else if (!perso->targetLoc) {
-						cita = whereiscita();
-						if (cita != -1) {
-							perso->targetLoc = cita;
-							perso->speed = 3;
-							perso->steps = 1;
-						}
-					}
-				}
-				break;
-			case PersonFlags::pftVelociraptor:
-				if (perso->flags & PersonFlags::pf10) {
-					if (perso->roomNum == p_global->roomNum) {
-						perso_t *perso2 = &kPersons[PER_UNKN_372];
-						char found = 0;
-						for (; perso2->roomNum != 0xFFFF; perso2++) {
-							if ((perso->roomNum & ~0xFF) == (perso2->roomNum & ~0xFF)) {
-								if (perso2->flags & PersonFlags::pf80)
-									continue;
-								perso->targetLoc = perso2->roomNum & 0xFF;
-								perso->steps = 1;
-								found = 1;
-								break;
-							}
-						}
-						if (found)
-							continue;
-					} else {
-						tyranPtr = &kPersons[PER_UNKN_372];
-						if (istyran(perso->roomNum)) {
-							if (p_global->phaseNum < 481 && (perso->powers & (1 << (p_global->cita_area_num - 3)))) {
-								tyranPtr->flags |= PersonFlags::pf80;
-								tyranPtr->roomNum = 0;
-								perso->flags &= ~PersonFlags::pf10;
-								perso->flags |= PersonFlags::pfInParty;
-								ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannLost);
-								delinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
-								if (naitredino(PersonFlags::pftTriceraptor))
-									ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
-								constcita();
-								p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
-							} else {
-								perso->flags &= ~PersonFlags::pf10;
-								perso->flags &= ~PersonFlags::pfInParty;
-								ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsLost);
-							}
-							continue;
-						}
-					}
-				}
-				if (!perso->targetLoc) {
-					short loc;
-					perso->lastLoc = 0;
-					do {
-						loc = (g_ed->_rnd->getRandomNumber(63) & 63) + 16;
-						if ((loc & 0xF) >= 12)
-							loc &= ~4;  //TODO: ??? same as -= 4
-					} while (!caselibre(loc, perso));
-					perso->targetLoc = loc;
-					perso->steps = 1;
-				}
-				break;
-			}
-		}
-	}
-	void vivreval(short areaNum) {
-		p_global->cita_area_num = areaNum;
-		p_global->cur_area_ptr = &kAreasTable[areaNum - 1];
-		p_global->cita_area_firstRoom = &gameRooms[p_global->cur_area_ptr->firstRoomIndex];
-		deplaalldino();
-		constcita();
-		vivredino();
-		newchampi();
-		newnido();
-		newnidv();
-		if (p_global->phaseNum >= 226)
-			newor();
-		lieuvava(p_global->cur_area_ptr);
-	}
-	void chaquejour() {
-		vivreval(3);
-		vivreval(4);
-		vivreval(5);
-		vivreval(6);
-		vivreval(7);
-		vivreval(8);
-		p_global->drawFlags |= DrawFlags::drDrawTopScreen;
-	}
-	void temps_passe(short t) {
-		short days = p_global->gameDays;
-		short lo = p_global->ff_56;
-		lo += t;
-		if (lo > 255) {
-			days++;
-			lo &= 0xFF;
-		}
-		p_global->ff_56 = lo;
-		t = ((t >> 8) & 0xFF) + days;
-		t -= p_global->gameDays;
-		if (t) {
-			p_global->gameDays += t;
-			while (t--)
-				chaquejour();
-		}
-	}
-	void heurepasse() {
-		temps_passe(5);
-	}
-	void anim_perso() {
-		if (cur_bank_num != p_global->perso_img_bank)
-			load_perso(p_global->perso_ptr);
-		restaurefondbulle();
-		if (restartAnimation) {
-			last_anim_ticks = TimerTicks;
-			restartAnimation = 0;
-		}
-		cur_anim_frame_num = (TimerTicks - last_anim_ticks) >> 2;   // TODO: check me!!!
-		if (cur_anim_frame_num > num_anim_frames)               // TODO: bug?
-			animateTalking = 0;
-		if (p_global->curPersoAnimPtr && !p_global->animationFlags && cur_anim_frame_num != last_anim_frame_num) {
-			last_anim_frame_num = cur_anim_frame_num;
-			if (*p_global->curPersoAnimPtr == 0xFF)
-				getanimrnd();
-			bank_data_ptr = perso_img_bank_data_ptr;
-			num_img_desc = 0;
-			perso_spr(p_global->curPersoAnimPtr);
-			p_global->curPersoAnimPtr += num_img_desc + 1;
-			dword_3072C = imagedesc + 200;
-			virespritebouche();
-			if (*dword_3072C)
-				af_image();
-			animationDelay--;
-			if (!animationDelay) { //TODO: combine
-				p_global->animationFlags = 1;
-				animationDelay = 8;
-			}
-		}
-
-		animationDelay--;
-		if (!animationDelay) { //TODO: combine
-			getanimrnd();
-			//TODO: no reload?
-		}
-		if (animateTalking) {
-			if (!animationTable) {
-				animationTable = gameLipsync + 7262;    //TODO: fix me
-				if (!fond_saved)
-					sauvefondbouche();
-			}
-			if (!personTalking)
-				cur_anim_frame_num = num_anim_frames - 1;
-			animationIndex = animationTable[cur_anim_frame_num];
-			if (animationIndex == 0xFF)
-				animateTalking = 0;
-			else if (animationIndex != lastAnimationIndex) {
-				bank_data_ptr = perso_img_bank_data_ptr;
-				restaurefondbouche();
-//			debug("perso spr %d", animationIndex);
-				perso_spr(p_global->persoSpritePtr2 + animationIndex * 2);  //TODO: shorts?
-				dword_3072C = imagedesc + 200;
-				if (*dword_3072C)
-					af_image();
-				lastAnimationIndex = animationIndex;
-			}
-		}
-		af_subtitle();
-	}
-	void getanimrnd() {
-		short rnd;
-		animationDelay = 8;
-		rnd = g_ed->_rnd->getRandomNumber(65535) & (unsigned char)~0x18;    //TODO
-		dword_30724 = p_global->persoSpritePtr + 16;    //TODO
-		p_global->curPersoAnimPtr = p_global->persoSpritePtr + ((dword_30724[1] << 8) + dword_30724[0]);
-		p_global->animationFlags = 1;
-		if (rnd >= 8)
-			return;
-		p_global->animationFlags = 0;
-		if (rnd <= 0)
-			return;
-		for (rnd *= 8; rnd > 0; rnd--) {
-			while (*p_global->curPersoAnimPtr)
-				p_global->curPersoAnimPtr++;
-			p_global->curPersoAnimPtr++;
-		}
-	}
-	void addanim() {
-		lastAnimationIndex = -1;
-		last_anim_ticks = 0;
-		p_global->animationFlags = 0xC0;
-		p_global->curPersoAnimPtr = p_global->persoSpritePtr;
-		getanimrnd();
-		animationActive = 1;
-		if (p_global->perso_ptr == &kPersons[PER_ROI])
-			return;
-		perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));  //TODO: GetElem(0)
-		dword_3072C = imagedesc + 200;
-		if (p_global->perso_ptr->id != PersonId::pidCabukaOfCantura && p_global->perso_ptr->targetLoc != 7) //TODO: targetLoc is minisprite idx
-			virespritebouche();
-		if (*dword_3072C)
-			af_image();
-	}
-	void virespritebouche() {
-		unsigned char *src = dword_3072C + 2;
-		unsigned char *dst = src;
-		char cnt = dword_3072C[0];
-		while (cnt--) {
-			unsigned char a = *src++;
-			unsigned char b = *src++;
-			unsigned char c = *src++;
-			dst[0] = a;
-			dst[1] = b;
-			dst[2] = c;
-			if (dword_30728[0] != 0xFF) {
-				if ((a < dword_30728[0] || a > dword_30728[1])
-				        && (a < dword_30728[2] || a > dword_30728[3]))
-					dst += 3;
-				else
-					dword_3072C[0]--;
-			} else
-				dst += 3;
-		}
-	}
-	void anim_perfin() {
-		p_global->animationFlags &= ~0x80;
-		animationDelay = 0;
-		animationActive = 0;
-	}
-	void perso_spr(unsigned char *spr) {
-		unsigned char *img = imagedesc + 200 + 2;
-		short count = 0;
-		unsigned char c, cc;
-		while ((c = *spr++)) {
-			unsigned char *src;
-			short index;
-			cc = 0;
-			if (c == 1) {
-				cc = index;
-				c = *spr++;
-			}
-			num_img_desc++;
-			index = (cc << 8) | c;
-			index -= 2;
-//	debug("anim sprite %d", index);
-
-			if (index > max_perso_desc)
-				index = max_perso_desc;
-			index *= 2;         //TODO: src = GetElem(ff_C2, index)
-			src = p_global->ff_C2;
-			src = src + PLE16(src + index);
-			while ((c = *src++)) {
-				*img++ = c;
-				*img++ = *src++;
-				*img++ = *src++;
-				count++;
-			}
-		}
-		imagedesc[200] = count & 0xFF;
-		imagedesc[201] = count >> 8;
-	}
-	void af_image() {
-		unsigned char *img = imagedesc + 200, *img_start, *curimg = imagedesc;
-		short count;
-
-		count = PLE16(img);
-		if (!count)
-			return;
-		img_start = img;
-		img += 2;
-		count *= 3;
-		while (count--)
-			*curimg++ = *img++;
-		img = img_start;
-		count = PLE16(img);
-		img += 2;
-/////// draw it
-		while (count--) {
-			unsigned short index = *img++;
-			unsigned short x = *img++ + gameIcons[0].sx;
-			unsigned short y = *img++ + gameIcons[0].sy;
-			unsigned char *pix = bank_data_ptr;
-			unsigned char *scr = p_mainview_buf + x + y * 640;
-			unsigned char h0, h1, mode;
-			short w, h;
-			index--;
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
-			pix += PLE16(pix);
-			pix += PLE16(pix + index * 2);
-			//  short   height:9
-			//  short   pad:6;
-			//  short   flag:1;
-			h0 = *pix++;
-			h1 = *pix++;
-			w = ((h1 & 1) << 8) | h0;
-			h = *pix++;
-			mode = *pix++;
-			if (mode != 0xFF && mode != 0xFE)
-				continue;   //TODO: enclosing block?
-			if (h1 & 0x80) {
-				// compressed
-				for (; h-- > 0;) {
-					short ww;
-					for (ww = w; ww > 0;) {
-						unsigned char c = *pix++;
-						if (c >= 0x80) {
-							if (c == 0x80) {
-								unsigned char fill = *pix++;
-								if (fill == 0) {
-									scr += 128 + 1;
-									ww -= 128 + 1;
-								} else {
-									unsigned char run;
-									*scr++ = fill;  //TODO: wha?
-									*scr++ = fill;
-									ww -= 128 + 1;
-									for (run = 127; run--;)
-										*scr++ = fill;
-								}
-							} else {
-								unsigned char fill = *pix++;
-								unsigned char run = 255 - c + 2;
-								ww -= run;
-								if (fill == 0)
-									scr += run;
-								else
-									for (; run--;)
-										*scr++ = fill;
-							}
-						} else {
-							unsigned char run = c + 1;
-							ww -= run;
-							for (; run--;) {
-								unsigned char p = *pix++;
-								if (p == 0)
-									scr++;
-								else
-									*scr++ = p;
-							}
-						}
-					}
-					scr += 640 - w;
-				}
-			} else {
-				// uncompressed
-				for (; h--;) {
-					short ww;
-					for (ww = w; ww--;) {
-						unsigned char p = *pix++;
-						if (p == 0)
-							scr++;
-						else
-							*scr++ = p;
-					}
-					scr += 640 - w;
-				}
-			}
-		}
-	}
-	void af_perso1() {
-		perso_spr(p_global->persoSpritePtr + PLE16(p_global->persoSpritePtr));
-		af_image();
-	}
-	void af_perso() {
-		load_perso_cour();
-		af_perso1();
-	}
-	void ef_perso() {
-		p_global->animationFlags &= 0x3F;
-	}
-	void load_perso(perso_t *perso) {
-		unsigned char *ptr, *baseptr;
-		perso_img_bank_data_ptr = 0;
-		if (!perso->bank)
-			return;
-		if (perso->bank != p_global->perso_img_bank) {
-			cur_perso_rect = &perso_rects[perso->id];   //TODO: array of short?
-			dword_30728 = tab_persxx[perso->id];
-			ef_perso();
-			p_global->perso_img_bank = perso->bank;
-			use_bank(p_global->perso_img_bank);
-			perso_img_bank_data_ptr = bank_data_ptr;
-			ptr = bank_data_ptr;
-			ptr += PLE16(ptr);
-			baseptr = ptr;
-			ptr += PLE16(ptr) - 2;
-			ptr = baseptr + PLE16(ptr) + 4;
-			gameIcons[0].sx = PLE16(ptr);
-			gameIcons[0].sy = PLE16(ptr + 2);
-			gameIcons[0].ex = PLE16(ptr + 4);
-			gameIcons[0].ey = PLE16(ptr + 6);
-			ptr += 8;
-			p_global->ff_C2 = ptr + 2;
-			max_perso_desc = PLE16(ptr) / 2;
-			ptr += PLE16(ptr);
-			baseptr = ptr;
-			ptr += PLE16(ptr) - 2;
-			p_global->persoSpritePtr = baseptr;
-			p_global->persoSpritePtr2 = baseptr + PLE16(ptr);
-			debug("load perso: b6 len is %d", p_global->persoSpritePtr2 - p_global->persoSpritePtr);
-		} else {
-			use_bank(p_global->perso_img_bank);
-			perso_img_bank_data_ptr = bank_data_ptr;
-		}
-	}
-	void load_perso_cour() {
-		load_perso(p_global->perso_ptr);
-	}
-	void fin_perso() {
-		p_global->animationFlags &= 0x3F;
-		p_global->curPersoAnimPtr = 0;
-		p_global->ff_CA = 0;
-		p_global->perso_img_bank = -1;
-		anim_perfin();
-	}
-	void no_perso() {
-		if (p_global->displayFlags == DisplayFlags::dfPerson) {
-			p_global->displayFlags = p_global->oldDisplayFlags;
-			fin_perso();
-		}
-		endpersovox();
-	}
-	void close_perso() {
-		char old;
-		endpersovox();
-		if (p_global->displayFlags == DisplayFlags::dfPerson && p_global->perso_ptr->id != PersonId::pidNarrator && p_global->eventType != EventType::etEventE) {
-			rundcurs();
-			savedUnderSubtitles = 1;
-			restaurefondbulle();
-			afficher();
-			p_global->ff_103 = 16;
-		}
-		if (p_global->perso_ptr->id == PersonId::pidNarrator)
-			p_global->ff_103 = 69;
-		p_global->eloiHaveNews &= 1;
-		p_global->ff_CA = 0;
-		p_global->ff_F6 = 0;
-		if (p_global->displayFlags == DisplayFlags::dfPerson) {
-			p_global->displayFlags = p_global->oldDisplayFlags;
-			p_global->animationFlags &= 0x3F;
-			p_global->curPersoAnimPtr = 0;
-			anim_perfin();
-			if (p_global->displayFlags & DisplayFlags::dfMirror) {
-				gametomiroir(1);
-				scroll_pos = old_scroll_pos;
-				scroll();
-				return;
-			}
-			if (p_global->numGiveObjs) {
-				if (!(p_global->displayFlags & DisplayFlags::dfFlag2))
-					showobjects();
-				p_global->numGiveObjs = 0;
-			}
-			if (p_global->ff_F2 & 1) {
-				p_global->ff_102 = 6;
-				p_global->ff_F2 &= ~1;
-			}
-			old = p_global->newLocation;
-			p_global->newLocation = 0;
-			if (!(p_global->narratorSequence & 0x80))
-				p_global->ff_100 = -1;
-			maj_salle(p_global->roomNum);
-			p_global->newLocation = old;
-		}
-		if (p_global->chrono)
-			p_global->chrono_on = 1;
-	}
-	void af_fondsuiveur() {
-		char id = p_global->perso_ptr->id;
-		suiveur_t *suiveur = suiveurs_list;
-		for (; suiveur->id != -1; suiveur++) {
-			if (suiveur->id == id) {
-				int bank = 326;
-				if (suiveur->sx >= 320)
-					bank = 327;
-				use_bank(bank + p_global->roomBgBankNum);
-				noclipax_avecnoir(0, 0, 16);
-				break;
-			}
-		}
-	}
-	void af_fondperso1() {
-		unsigned char bank;
-		char *ptab;
-		if (p_global->perso_ptr == &kPersons[PER_MESSAGER]) {
-			gameIcons[0].sx = 0;
-			perso_rects[PER_MESSAGER].sx = 2;
-			bank = p_global->persoBackgroundBankIdx;
-			if (p_global->eventType == EventType::etEventE) {
-				p_global->ff_103 = 1;
-				goto no_suiveur;
-			}
-			gameIcons[0].sx = 60;
-			perso_rects[PER_MESSAGER].sx = 62;
-		}
-		if (p_global->perso_ptr == &kPersons[PER_THOO]) {
-			bank = 37;
-			if (p_global->curObjectId == Objects::obShell)
-				goto no_suiveur;
-		}
-		ptab = kPersoRoomBankTable + p_global->perso_ptr->roomBankIdx;
-		bank = *ptab++;
-		if (!(p_global->perso_ptr->party & p_global->party)) {
-			while ((bank = *ptab++) != 0xFF) {
-				if (bank == (p_global->roomNum & 0xFF)) { //TODO: signed vs unsigned - chg r31 to uns?
-					bank = *ptab;
-					break;
-				}
-				ptab++;
-			}
-			if (bank != 0xFF)
-				goto no_suiveur;
-			ptab = kPersoRoomBankTable + p_global->perso_ptr->roomBankIdx;
-			bank = *ptab++;
-		}
-		af_fondsuiveur();
-no_suiveur:
-		;
-		if (!bank)
-			return;
-		use_bank(bank);
-		if (p_global->perso_ptr == &kPersons[PER_UNKN_156])
-			noclipax_avecnoir(0, 0, 16);
-		else
-			noclipax(0, 0, 16);
-	}
-	void af_fondperso() {
-		if (p_global->perso_ptr->bank) {
-			fond_saved = 0;
-			af_fondperso1();
-		}
-	}
-	void setpersoicon() {
-		icon_t *icon = gameIcons, *icon2 = &gameIcons[28];
-		if (p_global->iconsIndex == 4)
-			return;
-		if (p_global->perso_ptr == &kPersons[PER_MESSAGER] && p_global->eventType == EventType::etEventE) {
-			p_global->iconsIndex = 123;
-			return;
-		}
-		*icon2++ = *icon++; //TODO: is this ok?
-		*icon2++ = *icon++;
-		icon2->sx = -1;
-	}
-	void show_perso() {
-		perso_t *perso = p_global->perso_ptr;
-		if (perso->bank) {
-			closesalle();
-			if (p_global->displayFlags != DisplayFlags::dfPerson) {
-				if (p_global->displayFlags & DisplayFlags::dfMirror)
-					resetscroll();
-				p_global->oldDisplayFlags = p_global->displayFlags;
-				p_global->displayFlags = DisplayFlags::dfPerson;
-				load_perso(perso);
-				setpersoicon();
-				af_fondperso();
-				if (perso == &kPersons[PER_THOO] && p_global->curObjectId == Objects::obShell) {
-					af_subtitle();
-					update_cursor();
-					needPaletteUpdate = 1;
-					afficher();
-					rundcurs();
-					return;
-				}
-			}
-			load_perso_cour();
-			addanim();
-			if (!p_global->curPersoAnimPtr) {
-				af_perso();
-				af_subtitle();
-			}
-			restartAnimation = 1;
-			anim_perso();
-			if (perso != &kPersons[PER_UNKN_156])
-				update_cursor();
-			needPaletteUpdate = 1;
-			if (perso != &kPersons[PER_UNKN_156])
-				rundcurs();
-			afficher();
-		} else {
-			aflieu();
-			af_subtitle();
-		}
-	}
-	void showpersopanel() {
-		perso_t *perso = p_global->perso_ptr;
-		load_perso_cour();
-		addanim();
-		if (!p_global->curPersoAnimPtr) {
-			af_perso();
-			af_subtitle();
-		}
-		restartAnimation = 1;
-		needPaletteUpdate = 1;
-		if (p_global->drawFlags & DrawFlags::drDrawFlag8)
-			return;
-		anim_perso();
-		if (perso != &kPersons[PER_UNKN_156])
-			update_cursor();
-		afficher();
-		if (perso != &kPersons[PER_UNKN_156])
-			rundcurs();
-		p_global->drawFlags |= DrawFlags::drDrawFlag8;
-		p_global->iconsIndex = 112;
-	}
-	void getdatasync() {
-		short num = p_global->textNum;
-		if (p_global->textBankIndex != 1)
-			num += 565;
-		if (p_global->textBankIndex == 3)
-			num += 707;
-		if (num == 144)
-			num = 142;
-		animateTalking = ReadDataSync(num - 1);
-		if (animateTalking)
-			num_anim_frames = ReadNombreFrames();
-		else
-			num_anim_frames = 0;
-		if (p_global->textNum == 144)
-			num_anim_frames = 48;
-		animationTable = 0;
-	}
-	short ReadNombreFrames() {
-		short num = 0;
-		animationTable = gameLipsync + 7262;    //TODO: fix me
-		while (*animationTable++ != 0xFF)
-			num++;
-		return num;
-	}
-	void waitendspeak() {
-		for (;;) {
-			if (animationActive)
-				anim_perso();
-			musicspy();
-			afficher();
-			CLKeyboard_Read();
-			testPommeQ();
-			if (pomme_q) {
-				close_perso();
-				PommeQ();
-				break;
-			}
-			if (!mouse_held)
-				if (CLMouse_IsDown())
-					break;
-			if (mouse_held)
-				if (!CLMouse_IsDown())
-					mouse_held = 0;
-		}
-		mouse_held = 1;
-	}
-	void my_bulle() {
-		unsigned char c;
-		unsigned char i;
-		short words_on_line, word_width, line_width;
-		unsigned char *icons = phraseIconsBuffer;
-		unsigned char *lines = phraseCoordsBuffer;
-		unsigned char *phrasePtr = phraseBuffer;
-		if (!p_global->textNum)
-			return;
-		p_global->numGiveObjs = 0;
-		p_global->giveobj1 = 0;
-		p_global->giveobj2 = 0;
-		p_global->giveobj3 = 0;
-		p_global->textWidthLimit = subtitles_x_width;
-		text_ptr = gettxtad(p_global->textNum);
-		num_text_lines = 0;
-		words_on_line = 0;
-		word_width = 0;
-		line_width = 0;
-		while ((c = *text_ptr++) != 0xFF) {
-			if (c == 0x11 || c == 0x13) {
-				if (p_global->phaseNum <= 272 || p_global->phaseNum == 386) {
-					p_global->eloiHaveNews = c & 0xF;
-					p_global->ff_4D = p_global->worldTyrannSighted;
-				}
-			} else if (c >= 0x80 && c < 0x90)
-				SysBeep(1);
-			else if (c >= 0x90 && c < 0xA0) {
-				while (*text_ptr++ != 0xFF) ;
-				text_ptr--;
-			} else if (c >= 0xA0 && c < 0xC0)
-				p_global->textToken1 = c & 0xF;
-			else if (c >= 0xC0 && c < 0xD0)
-				p_global->textToken2 = c & 0xF;
-			else if (c >= 0xD0 && c < 0xE0) {
-				unsigned char c1 = *text_ptr++;
-				if (c == 0xD2)
-#ifdef FAKE_DOS_VERSION
-					p_global->textWidthLimit = c1 + 160;
-#else
-					p_global->textWidthLimit = c1 + subtitles_x_center; //TODO: signed? 160 in pc ver
-#endif
-				else {
-					unsigned char c2 = *text_ptr++;
-					switch (p_global->numGiveObjs) {
-					case 0:
-						p_global->giveobj1 = c2;
-						break;
-					case 1:
-						p_global->giveobj2 = c2;
-						break;
-					case 2:
-						p_global->giveobj3 = c2;
-						break;
-					}
-					p_global->numGiveObjs++;
-					*icons++ = *text_ptr++;
-					*icons++ = *text_ptr++;
-					*icons++ = c2;
-				}
-			} else if (c >= 0xE0 && c < 0xFF)
-				SysBeep(1);
-			else if (c != '\r') {
-				unsigned char width;
-				short overrun;
-				*phrasePtr++ = c;
-				width = gameFont[c];
-#ifdef FAKE_DOS_VERSION
-				if (c == ' ')
-					width = space_width;
-#endif
-				word_width += width;
-				line_width += width;
-				overrun = line_width - p_global->textWidthLimit;
-				if (overrun > 0) {
-					num_text_lines++;
-					if (c != ' ') {
-						*lines++ = words_on_line;
-						*lines++ = word_width + space_width - overrun;
-						line_width = word_width;
-					} else {
-						*lines++ = words_on_line + 1;
-						*lines++ = space_width - overrun;   //TODO: checkme
-						line_width = 0;
-					}
-					word_width = 0;
-					words_on_line = 0;
-				} else {
-					if (c == ' ') {
-						words_on_line++;
-						word_width = 0;
-					}
-				}
-			}
-		}
-		num_text_lines++;
-		*lines++ = words_on_line + 1;
-		*lines++ = word_width;
-		*phrasePtr = c;
-		if (p_global->textBankIndex == 2 && p_global->textNum == 101 && p_global->pref_language == 1)
-			patchphrase();
-		my_pr_bulle();
-		if (!p_global->numGiveObjs)
-			return;
-		use_main_bank();
-		if (num_text_lines < 3)
-			num_text_lines = 3;
-		icons = phraseIconsBuffer;
-		for (i = 0; i < p_global->numGiveObjs; i++) {
-			unsigned char x = *icons++;
-			unsigned char y = *icons++;
-			unsigned char s = *icons++;
-			spritesurbulle(52, x + subtitles_x_center, y - 1);
-			spritesurbulle(s + 9, x + subtitles_x_center + 1, y);
-		}
-	}
-	void my_pr_bulle() {
-		unsigned char *cur_out;
-		unsigned char *coo = phraseCoordsBuffer;
-		short extra_spacing, lines;
-		char done = 0;
-		CLBlitter_FillView(p_subtitlesview, 0);
-		if (p_global->pref_language == 0)
-			return;
-		textout = p_subtitlesview_buf;
-		text_ptr = phraseBuffer;
-		lines = 1;
-		while (!done) {
-			unsigned char c;
-			short num_words = *coo++;       // num words on line
-			short pad_size = *coo++;        // amount of extra spacing
-			cur_out = textout;
-			extra_spacing = num_words > 1 ? pad_size / (num_words - 1) + 1 : 0;
-			if (lines == num_text_lines)
-				extra_spacing = 0;
-			c = *text_ptr++;
-			while (!done & (num_words > 0)) { //TODO: bug - missed & ?
-				if (c < 0x80 && c != '\r') {
-					if (c == ' ') {
-						num_words--;
-						if (pad_size >= extra_spacing) {
-							textout += extra_spacing + space_width;
-							pad_size -= extra_spacing;
-						} else {
-							textout += pad_size + space_width;
-							pad_size = 0;
-						}
-					} else {
-						short char_width = gameFont[c];
-						if (!(p_global->drawFlags & DrawFlags::drDrawMenu)) {
-							textout += subtitles_x_width;
-							if (!specialTextMode)
-								charsurbulle(c, 195, char_width);
-							textout++;
-							if (!specialTextMode)
-								charsurbulle(c, 195, char_width);
-							textout -= subtitles_x_width + 1;
-						}
-						if (specialTextMode)
-							charsurbulle(c, 250, char_width);
-						else
-							charsurbulle(c, 230, char_width);
-						textout += char_width;
-					}
-				} else
-					monbreak();
-				c = *text_ptr++;
-				if (c == 0xFF)
-					done = 1;
-			}
-			textout = cur_out + subtitles_x_width * FONT_HEIGHT;
-			lines++;
-			text_ptr--;
-		}
-	}
-	void charsurbulle(unsigned char c, unsigned char color, short width) {
-		short w, h;
-		unsigned char *glyph = gameFont + 256 + c * FONT_HEIGHT;
-		textoutptr = textout;
-		for (h = 0; h < FONT_HEIGHT; h++) {
-			unsigned char bits = *glyph++;
-			short mask = 0x80;
-			for (w = 0; w < width; w++) {
-				if (bits & mask)
-					*textoutptr = color;
-				textoutptr++;
-				mask >>= 1;
-			}
-			textoutptr += subtitles_x_width - width;
-		}
-	}
-	void af_subtitle() {
-		short w, h, y;
-		unsigned char *src = p_subtitlesview_buf, *dst = p_mainview_buf;
-		if (p_global->displayFlags & DisplayFlags::dfFlag2) {
-			y = 174;
-			if ((p_global->drawFlags & DrawFlags::drDrawMenu) && num_text_lines == 1)
-				y = 167;
-			dst += 640 * (y - num_text_lines * FONT_HEIGHT) + subtitles_x_scr_margin;
-		} else {
-			y = 174;
-			dst += 640 * (y - num_text_lines * FONT_HEIGHT) + scroll_pos + subtitles_x_scr_margin;
-		}
-		if (animationActive && !personTalking)
-			return;
-		sauvefondbulle(y);
-		for (h = 0; h < num_text_lines * FONT_HEIGHT + 1; h++) {
-			for (w = 0; w < subtitles_x_width; w++) {
-				unsigned char c = *src++;
-				if (c)
-					*dst = c;
-				dst++;
-			}
-			dst += 640 - subtitles_x_width;
-		}
-	}
-	void sauvefondbulle(short y) {
-		underSubtitlesScreenRect.sy = y - num_text_lines * FONT_HEIGHT;
-		underSubtitlesScreenRect.sx = scroll_pos + subtitles_x_scr_margin;
-		underSubtitlesScreenRect.ex = scroll_pos + subtitles_x_scr_margin + subtitles_x_width - 1;
-		underSubtitlesScreenRect.ey = y;
-		underSubtitlesBackupRect.sy = 0;
-		underSubtitlesBackupRect.ey = num_text_lines * FONT_HEIGHT;
-		CLBlitter_CopyViewRect(p_mainview, p_underSubtitlesView, &underSubtitlesScreenRect, &underSubtitlesBackupRect);
-		savedUnderSubtitles = 1;
-	}
-	void restaurefondbulle() {
-		if (!savedUnderSubtitles)
-			return;
-		CLBlitter_CopyViewRect(p_underSubtitlesView, p_mainview, &underSubtitlesBackupRect, &underSubtitlesScreenRect);
-		savedUnderSubtitles = 0;
-	}
-	void af_subtitlehnm() {
-		short x, y;
-		unsigned char *src = p_subtitlesview_buf;
-		unsigned char *dst = p_hnmview_buf + subtitles_x_scr_margin + (158 - num_text_lines * FONT_HEIGHT) * 320;
-		for (y = 0; y < num_text_lines * FONT_HEIGHT; y++) {
-			for (x = 0; x < subtitles_x_width; x++) {
-				char c = *src++;
-				if (c)
-					*dst = c;
-				dst++;
-			}
-			dst += 320 - subtitles_x_width;
-		}
-	}
-	void patchphrase() {
-		phraseBuffer[36] = 'c';
-	}
-	void vavapers() {
-		perso_t *perso = p_global->perso_ptr;
-		p_global->curPersoFlags = perso->flags;
-		p_global->curPersoItems = perso->items;
-		p_global->curPersoPowers = perso->powers;
-	}
-	void citadelle() {
-		p_global->ff_69++;
-		p_global->ff_F6++;
-		byte_30AFE = 1;
-		byte_30B00 = 1;
-	}
-	void choixzone() {


Commit: 0dfe25149634bff3f7bcb5cc5e883bfe2fe03d1e
    https://github.com/scummvm/scummvm/commit/0dfe25149634bff3f7bcb5cc5e883bfe2fe03d1e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-25T22:41:54+01:00

Commit Message:
CRYO: Fix warnings

Changed paths:
    engines/cryo/CryoLib.h
    engines/cryo/defs.h


diff --git a/engines/cryo/CryoLib.h b/engines/cryo/CryoLib.h
index 628ba29..ec06320 100644
--- a/engines/cryo/CryoLib.h
+++ b/engines/cryo/CryoLib.h
@@ -34,15 +34,15 @@ extern short __debug, __libError, __osError;
 #define CLNoError       __libError = 0;
 
 #define CLCheckError() if(__debug && __libError){   \
-		char buffer[260];           \
-		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
-		DebugStr(c2pstr(buffer));   \
+		char buffer_[260];           \
+		sprintf(buffer_, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer_));   \
 	};
 
 #define CLAssert(x) if(!(x)) {  \
-		char buffer[260];           \
-		sprintf(buffer, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
-		DebugStr(c2pstr(buffer));   \
+		char buffer_[260];           \
+		sprintf(buffer_, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer_));   \
 	};
 
 struct rect_t {
diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h
index ed6fff2..3400c23 100644
--- a/engines/cryo/defs.h
+++ b/engines/cryo/defs.h
@@ -101,7 +101,7 @@ enum OBJECT {
 	OBJ_PLAQUE, // 38
 	OBJ_39,
 	OBJ_40,
-	OBJ_41,
+	OBJ_41
 };
 
 namespace Objects {


Commit: ea01120013f144ba9ad61a1973907b565acb7833
    https://github.com/scummvm/scummvm/commit/ea01120013f144ba9ad61a1973907b565acb7833
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-25T22:41:54+01:00

Commit Message:
CRYO: Refactor to avoid nested includes

Changed paths:
  A engines/cryo/clerror.cpp
  A engines/cryo/clhnm.cpp
  A engines/cryo/clsoundgroup.cpp
  A engines/cryo/clsoundraw.cpp
  A engines/cryo/cryolib.cpp
  A engines/cryo/cryolib.h
  A engines/cryo/staticdata.cpp
  R engines/cryo/CLError.c
  R engines/cryo/CLHNM.c
  R engines/cryo/CLSouNdRaw.c
  R engines/cryo/CryoLib.h
  R engines/cryo/CryoLibStub.c
  R engines/cryo/clsoundgroup.c
    engines/cryo/cryo.cpp
    engines/cryo/cryo.h
    engines/cryo/defs.h
    engines/cryo/eden.cpp
    engines/cryo/eden.h
    engines/cryo/module.mk
    engines/cryo/platdefs.h


diff --git a/engines/cryo/CLError.c b/engines/cryo/CLError.c
deleted file mode 100644
index d9f8bad..0000000
--- a/engines/cryo/CLError.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "cryolib.h"
-
-short __debug, __libError, __osError;
diff --git a/engines/cryo/CLHNM.c b/engines/cryo/CLHNM.c
deleted file mode 100644
index d459489..0000000
--- a/engines/cryo/CLHNM.c
+++ /dev/null
@@ -1,746 +0,0 @@
-#include "cryolib.h"
-
-static short safe_palette = 0;
-static short pred_r = 0, pred_l = 0;
-static short use_adpcm = 0;
-static float hnm_rate = 0.0;
-static float next_frame_time = 0.0;
-static float expected_frame_time = 0.0;
-static float time_drift = 0.0;
-static short use_mono = 0;
-static short use_sound = 0;
-static short use_sound_sync = 0;
-static short pending_sounds = 0;
-static short sound_started = 0;
-static short preserve_color0 = 0;
-static soundchannel_t *soundChannel_adpcm = 0;
-static soundgroup_t *soundGroup_adpcm = 0;
-static soundchannel_t *soundChannel = 0;
-static soundgroup_t *soundGroup = 0;
-static void (*custom_chunk_handler)(unsigned char *buffer, int size, short id, char h6, char h7) = 0;
-static short use_preload = 0;
-static short decomp_table[256];
-
-void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
-
-void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output) {
-	unsigned char *inp = buffer;
-	unsigned char *out = output;
-
-	unsigned int queue = 0;
-	int qpos = -1;
-
-	//TODO: fix for BE
-#define GetBit() ( 1 & ( (qpos >= 0) ? (queue >> qpos--) : (queue = *(unsigned int*)((inp += 4) - 4)) >> ((qpos = 30) + 1) ) )
-
-	for (;;) {
-		if (GetBit()) {
-			*out++ = *inp++;
-		} else {
-			int l, o;
-			if (GetBit()) {
-				l = *inp & 7;
-				o = *(unsigned short *)inp >> 3;
-				inp += 2;
-				o -= 8192;
-				if (!l)
-					l = *inp++;
-				if (!l)
-					break;
-			} else {
-				l = GetBit() * 2 + GetBit();
-				o = *(inp++) - 256;
-			}
-			l += 2;
-			while (l--) {
-				*out = *(out + o);
-				out++;
-			}
-		}
-	}
-
-#undef GetBit
-
-	return;
-}
-
-void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
-                     unsigned char *input, int width, char flags) {
-	unsigned int code;
-	char mode, count, color;
-	unsigned short offs;
-	unsigned char *ref;
-	unsigned char *out_start = output;
-	unsigned char swap;
-	int shft1, shft2;
-//	return;
-	if ((flags & 1) == 0) {
-		//HNM4 classic
-		int twolinesabove = -(width * 2);
-		for (;;) {
-			code = PLE32(input) & 0xFFFFFF; //input++;
-			count = code & 0x1F;
-			if (count) {
-				input += 3;
-				mode = (code >> 5) & 0xF;
-				offs = code >> 9;
-				//
-				swap = mode >> 3;
-				ref = ((mode & 1) ? prev_buffer : curr_buffer) + (output - out_start) + (offs * 2) - 32768;
-				if (mode & 2) {
-					//                  ref += twolinesabove;
-					shft1 = twolinesabove + 1;
-					shft2 = 0;
-					//swap ^= 1;
-				} else {
-					shft1 = 0;
-					shft2 = 1;
-				}
-				while (count--) {
-					unsigned char b0 = ref[shft1];
-					unsigned char b1 = ref[shft2];
-					output[swap] = b0;
-					output[swap ^ 1] = b1;
-					output += 2;
-					ref += (mode & 4) ? -2 : 2;
-				}
-			} else {
-				input++;
-				mode = code & 0xFF; // bits 0..4 are zero
-				switch (mode) {
-				case 0:
-					*(output++) = *(input++);
-					*(output++) = *(input++);
-					break;
-				case 0x20:
-					output += 2 * *(input++);
-					break;
-				case 0x40:
-					output += 2 * (code >> 8);
-					input += 2;
-					break;
-				case 0x60:
-					count = *(input++);
-					color = *(input++);
-					while (count--) {
-						*(output++) = color;
-						*(output++) = color;
-					}
-					break;
-				default:
-					return;
-				}
-			}
-		}
-	} else {
-		assert(0);
-		//HNM4 hires
-		for (;;) {
-			code = PLE32(input) & 0xFFFFFF;
-			input++;
-			count = code & 0x3F;
-			if (count) {
-				mode = (code >> 5) & 0xF;
-				offs = code >> 9;
-				//
-			} else {
-				mode = code & 0xFF; // bits 0..5 are zero
-				switch (mode) {
-				case 0x00:
-					output += *input++;
-					break;
-				case 0x40:
-					*output++ = *input++;
-					*(output++ + width) = *input++;
-					break;
-				case 0x80:
-					output += width;
-					break;
-				default:
-					return;
-				}
-			}
-		}
-	}
-}
-
-void CLHNM_Init() {
-	use_preload = 0;
-	custom_chunk_handler = 0;
-	preserve_color0 = 0;
-	CLNoError;
-}
-
-void CLHNM_Done() {
-	CLNoError;
-}
-
-void CLHNM_SetupTimer(float rate) {
-	hnm_rate = 100.0 / rate;
-	CLNoError;
-}
-
-void CLHNM_WaitLoop(hnm_t *hnm) {
-	expected_frame_time += hnm_rate;
-	next_frame_time = expected_frame_time - time_drift;
-	if (use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
-		use_sound = 0;
-	while (TimerTicks < next_frame_time) ;  // waste time
-	time_drift = TimerTicks - next_frame_time;
-}
-
-void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode) {
-	soundChannel = CLSoundChannel_New(mode);
-	soundGroup = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
-	if (sampleSize == 16)
-		CLSoundGroup_Reverse16All(soundGroup);
-}
-
-void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode) {
-	soundChannel_adpcm = CLSoundChannel_New(mode);
-	soundGroup_adpcm = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
-}
-
-void CLHNM_CloseSound() {
-	if (soundChannel) {
-		CLSoundChannel_Stop(soundChannel);
-		CLSoundChannel_Free(soundChannel);
-		soundChannel = 0;
-	}
-	if (soundGroup) {
-		CLSoundGroup_Free(soundGroup);
-		soundGroup = 0;
-	}
-	if (soundChannel_adpcm) {
-		CLSoundChannel_Stop(soundChannel_adpcm);
-		CLSoundChannel_Free(soundChannel_adpcm);
-		soundChannel = 0;
-	}
-	if (soundGroup_adpcm) {
-		CLSoundGroup_Free(soundGroup_adpcm);
-		soundGroup = 0;
-	}
-}
-
-void CLHNM_SetForceZero2Black(short forceblack) {
-	preserve_color0 = forceblack;
-}
-
-hnm_t *CLHNM_New(int preload_size) {
-	hnm_t *hnm;
-	short i;
-
-	preload_size = 0;   //TODO: let's ignore it for now
-
-	CLBeginCheck;
-	hnm = (hnm_t *)CLMemory_Alloc(sizeof(*hnm));
-	CLCheckError();
-	if (hnm) {
-		if (preload_size) {
-			use_preload = 1;
-
-		}
-		if (!__libError) {
-			hnm->frame = 0;
-			hnm->ff_4 = 0;
-			hnm->file = 0;
-			hnm->work_buffer[0] = 0;
-			hnm->work_buffer[1] = 0;
-			hnm->final_buffer = 0;
-			hnm->read_buffer = 0;
-			hnm->ff_896 = 0;
-			hnm->total_read = 0;
-			for (i = 0; i < 256; i++) {
-				hnm->palette[i].a = 0;
-				hnm->palette[i].r = 0;
-				hnm->palette[i].g = 0;
-				hnm->palette[i].b = 0;
-			}
-		} else
-			CLCheckError();
-	}
-	CLEndCheck;
-	return hnm;
-}
-
-void CLHNM_Dispose(hnm_t *hnm) {
-	CLBeginCheck;
-
-	if (use_preload) {
-
-	}
-
-	CLMemory_Free(hnm);
-	CLCheckError();
-
-	CLEndCheck;
-}
-
-
-void CLHNM_SetFile(hnm_t *hnm, file_t *file) {
-	hnm->file = file;
-	CLNoError;
-}
-
-void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer) {
-	hnm->final_buffer = buffer;
-	CLNoError;
-}
-
-void CLHNM_AllocMemory(hnm_t *hnm) {
-	CLBeginCheck;
-
-	hnm->work_buffer[0] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
-	CLCheckError();
-
-	if (!hnm->work_buffer[0])
-		goto fin;
-
-	hnm->work_buffer[1] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
-	CLCheckError();
-
-	if (!hnm->work_buffer[1]) {
-		CLMemory_Free(hnm->work_buffer[0]);
-		CLCheckError();
-		hnm->work_buffer[0] = 0;
-		goto fin;
-	}
-
-	if (!use_preload) {
-		hnm->read_buffer = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
-//		CLCheckError();
-		if (!hnm->read_buffer) {
-			CLMemory_Free(hnm->work_buffer[0]);
-			CLCheckError();
-			hnm->work_buffer[0] = 0;
-			CLMemory_Free(hnm->work_buffer[1]);
-			CLCheckError();
-			hnm->work_buffer[1] = 0;
-		}
-	}
-fin:
-	;
-	CLEndCheck;
-}
-
-void CLHNM_DeallocMemory(hnm_t *hnm) {
-	CLBeginCheck;
-	if (hnm->work_buffer[0]) {
-		CLMemory_Free(hnm->work_buffer[0]);
-		CLCheckError();
-		hnm->work_buffer[0] = 0;
-	}
-	if (hnm->work_buffer[1]) {
-		CLMemory_Free(hnm->work_buffer[1]);
-		CLCheckError();
-		hnm->work_buffer[1] = 0;
-	}
-
-	if (!use_preload) {
-		if (hnm->read_buffer) {
-			CLMemory_Free(hnm->read_buffer);
-			CLCheckError();
-			hnm->read_buffer = 0;
-		}
-	}
-
-	CLEndCheck;
-}
-
-void CLHNM_Read(hnm_t *hnm, int size) {
-	long _size = size;
-	if (!use_preload) {
-		CLFile_Read(*hnm->file, hnm->read_buffer, &_size);
-	} else {
-	}
-}
-
-void CLHNM_GiveTime(hnm_t *hnm) {
-	if (use_preload) {
-		//stuff preload_buffer from disk
-	}
-}
-
-void CLHNM_CanLoop(hnm_t *hnm, short can_loop) {
-	hnm->can_loop = can_loop;
-}
-
-void CLHNM_SelectBuffers(hnm_t *hnm) {
-	if (hnm->frame % 2) {
-		hnm->new_frame_buffer = hnm->work_buffer[1];
-		hnm->old_frame_buffer = hnm->work_buffer[0];
-	} else {
-		hnm->new_frame_buffer = hnm->work_buffer[0];
-		hnm->old_frame_buffer = hnm->work_buffer[1];
-	}
-}
-
-void CLHNM_ChangePalette(hnm_t *hnm) {
-	short mincolor, maxcolor;
-	unsigned short fst, cnt;
-	unsigned char *pal;
-	color_t *color;
-	CLPalette_GetLastPalette(hnm->palette);
-	pal = hnm->data_ptr;
-	if (*(unsigned short *)pal == 0xFFFF)
-		return;
-	mincolor = 255;
-	maxcolor = 0;
-	do {
-		fst = *pal++;
-		cnt = *pal++;
-		if (cnt == 0)
-			cnt = 256;
-		debug("hnm: setting palette, fst = %d, cnt = %d, last = %d", fst, cnt, fst + cnt - 1);
-		assert(fst + cnt <= 256);
-		if (mincolor > fst)
-			mincolor = fst;
-		if (maxcolor < fst + cnt)
-			maxcolor = fst + cnt;
-		color = hnm->palette + fst;
-		if (safe_palette) {
-			while (cnt--) {
-				unsigned char r = *pal++;
-				unsigned char g = *pal++;
-				unsigned char b = *pal++;
-				short rr = r << 10;
-				short gg = g << 10;
-				short bb = b << 10;
-				if (color->r != rr || color->g != gg || color->b != bb)
-					CLBlitter_OneBlackFlash();
-				color->r = rr;
-				color->g = gg;
-				color->b = bb;
-				color++;
-			}
-		} else {
-			while (cnt--) {
-				unsigned char r = *pal++;
-				unsigned char g = *pal++;
-				unsigned char b = *pal++;
-				color->r = r << 10;
-				color->g = g << 10;
-				color->b = b << 10;
-				color++;
-			}
-		}
-
-	} while (*(unsigned short *)pal != 0xFFFF);
-#if 0
-	if (preserve_color0) {
-		hnm->palette[0].r = 0;
-		hnm->palette[0].g = 0;
-		hnm->palette[0].b = 0;
-	}
-#endif
-//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);
-	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);
-}
-
-void CLHNM_Desentrelace(hnm_t *hnm) {
-	switch (hnm->header.width) {
-	case 320:
-		CLHNM_Desentrelace320(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-		CLNoError;
-		break;
-//	case 480:
-//		CLHNM_Desentrelace480(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-//		CLNoError;
-//		break;
-	default:
-		__libError = -5;
-		__osError = 0;
-		CLCheckError();
-	}
-}
-
-void CLHNM_FlushPreloadBuffer(hnm_t *hnm) {
-	if (use_preload) {
-	}
-}
-
-soundchannel_t *CLHNM_GetSoundChannel() {
-	return soundChannel;
-}
-
-
-void CLHNM_TryRead(hnm_t *hnm, int size) {
-	short err;
-	do {
-		CLHNM_Read(hnm, size);
-		err = __libError == -6;
-		if (err)
-			CLHNM_GiveTime(hnm);
-	} while (err);
-}
-
-void CLHNM_ResetInternalTimer() {
-	time_drift = 0.0;
-	next_frame_time = expected_frame_time = TimerTicks;
-}
-
-void CLHNM_Reset(hnm_t *hnm) {
-	hnm->frame = 0;
-	hnm->ff_4 = 0;
-	hnm->total_read = 0;
-	sound_started = 0;
-	pending_sounds = 0;
-	CLHNM_ResetInternalTimer();
-	CLNoError;
-}
-
-short CLHNM_LoadFrame(hnm_t *hnm) {
-	int chunk;
-	CLBeginCheck;
-	CLHNM_TryRead(hnm, 4);
-	CLEndCheck;
-	chunk = *(int *)hnm->read_buffer;
-	chunk = LE32(chunk);
-	chunk &= 0xFFFFFF;  // upper bit - keyframe mark?
-	if (!chunk)
-		return 0;
-
-	if (use_preload) {
-	} else {
-		if (chunk - 4 > hnm->header.buffersize) {
-			__libError = -3;
-			__osError = 0;
-			CLCheckError();
-		} else if (use_preload && chunk - 4 > 102400) {
-			__libError = -3;
-			__osError = 0;
-			CLCheckError();
-		}
-	}
-	CLBeginCheck;
-	CLHNM_TryRead(hnm, chunk - 4);
-	CLEndCheck;
-	hnm->data_ptr = hnm->read_buffer;
-	hnm->total_read += chunk;
-	return 1;
-}
-
-void CLHNM_WantsSound(short sound) {
-	use_sound = sound;
-}
-
-void CLHNM_LoadDecompTable(short *buffer) {
-	short i;
-	short e;
-	for (i = 0; i < 256; i++) {
-		e = *buffer++;
-		decomp_table[i] = LE16(e);
-	}
-}
-
-void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size) {
-	short l = pred_l, r = pred_r;
-	size &= ~1;
-	while (size--) {
-		*output++ = l += decomp_table[*buffer++];
-		*output++ = r += decomp_table[*buffer++];
-		if (l > 512 || r > 512)
-			DebugStr(" coucou");
-	}
-	pred_l = l;
-	pred_r = r;
-}
-
-void CLHNM_SoundInADPCM(short is_adpcm) {
-	use_adpcm = is_adpcm;
-}
-
-void CLHNM_SoundMono(short is_mono) {
-	use_mono = is_mono;
-}
-
-short CLHNM_NextElement(hnm_t *hnm) {
-	int sz;
-	short id;
-	char h6, h7;
-	short i;
-	if (hnm->frame == 0) {
-		CLHNM_ResetInternalTimer();
-		pred_l = pred_r = 0;
-	}
-	if (hnm->frame == hnm->header.nframe)
-		return 0;
-	if (!CLHNM_LoadFrame(hnm))
-		return 0;
-	for (;;) {
-		sz = PLE32(hnm->data_ptr) & 0xFFFFFF;
-		hnm->data_ptr += 4;
-		id = *(short *)hnm->data_ptr;
-		hnm->data_ptr += 2;
-		h6 = *hnm->data_ptr;
-		hnm->data_ptr += 1;
-		h7 = *hnm->data_ptr;
-		hnm->data_ptr += 1;
-		hnm->chunk_id = id;
-		switch (id) {
-		case BE16('PL'):
-			CLHNM_ChangePalette(hnm);
-			hnm->data_ptr += sz - 8;
-			break;
-		case BE16('IZ'):
-			hnm->frame++;
-			CLHNM_SelectBuffers(hnm);
-			CLHNM_DecompLempelZiv(hnm->data_ptr + 4, hnm->new_frame_buffer);
-			switch (hnm->header.width) {
-//			case 320: CLBlitter_RawCopy320ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
-//			case 480: CLBlitter_RawCopy480ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
-//			case 640: CLBlitter_RawCopy640ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
-//			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
-			default:
-				memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);  //TODO strange buffer size here
-			}
-			if (!(h6 & 1))
-				CLHNM_Desentrelace(hnm);
-			else {
-//				if(hnm->header.width == 640)
-//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-//				else
-				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);   //TODO: wrong size?
-			}
-			if (use_adpcm) {
-				if (!sound_started) {
-					for (i = 0; i < pending_sounds; i++)
-						CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
-					sound_started = 1;
-				}
-			} else {
-				if (!sound_started) {
-					for (i = 0; i < pending_sounds; i++)
-						CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
-					sound_started = 1;
-				}
-			}
-			goto end_frame;
-		case BE16('IU'):
-			hnm->frame++;
-			CLHNM_SelectBuffers(hnm);
-			CLHNM_DecompUBA(hnm->new_frame_buffer, hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->data_ptr, hnm->header.width, h6);
-			if (!(h6 & 1))
-				CLHNM_Desentrelace(hnm);
-			else {
-//				if(hnm->header.width == 640)
-//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
-//				else
-				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
-			}
-			goto end_frame;
-		case BE16('sd'):
-		case BE16('SD'):
-			if (use_sound) {
-				if (!h6) {
-					int sound_size = sz - 8;
-					if (!use_adpcm) {
-						CLSoundGroup_SetDatas(soundGroup, hnm->data_ptr, sound_size - 2, 0);
-						if (sound_started)
-							CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
-						else
-							pending_sounds++;
-					} else {
-						short *sound_buffer = (short *)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
-						if (!pending_sounds) {
-							const int kDecompTableSize = 256 * sizeof(short);
-							CLHNM_LoadDecompTable((short *)hnm->data_ptr);
-							CLHNM_DecompADPCM(hnm->data_ptr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize);
-							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, 0);
-						} else {
-							CLHNM_DecompADPCM(hnm->data_ptr, sound_buffer, sound_size);
-							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, sound_size * 2, 0);
-						}
-						pending_sounds++;
-						if (sound_started)
-							CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
-					}
-				} else {
-					__libError = -3;
-					__osError = 0;
-					CLCheckError();
-				}
-			}
-			hnm->data_ptr += sz - 8;
-			break;
-		default:
-			if (custom_chunk_handler)
-				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7);
-			hnm->data_ptr += sz - 8;
-		}
-	}
-end_frame:
-	;
-	if (use_preload) {
-	}
-	return 1;
-}
-
-void CLHNM_ReadHeader(hnm_t *hnm) {
-	CLBeginCheck;
-	if (!use_preload) {
-		long size = sizeof(hnm->header);
-		CLFile_Read(*hnm->file, &hnm->header, &size);
-	} else
-		;
-	CLCheckError();
-	CLEndCheck;
-	hnm->header.width = LE16(hnm->header.width);
-	hnm->header.height = LE16(hnm->header.height);
-	hnm->header.filesize = LE32(hnm->header.filesize);
-	hnm->header.nframe = LE32(hnm->header.nframe);
-	hnm->header.table_offset = LE32(hnm->header.table_offset);
-	hnm->header.speed = LE16(hnm->header.speed);
-	hnm->header.maxbuffer = LE16(hnm->header.maxbuffer);
-	hnm->header.buffersize = LE32(hnm->header.buffersize);
-	hnm->header.ff_20 = LE16(hnm->header.ff_20);
-	hnm->header.buffersize += 4096; //TODO: checkme
-}
-
-short CLHNM_GetVersion(hnm_t *hnm) {
-	CLNoError;
-	if (hnm->header.id == BE32('HNM4'))
-		return 4;
-	return -1;
-}
-
-int CLHNM_GetFrameNum(hnm_t *hnm) {
-	return hnm->frame;
-}
-
-void CLHNM_DeactivatePreloadBuffer() {
-	use_preload = 0;
-}
-
-void CLHNM_Prepare2Read(hnm_t *hnm, int mode) {
-	if (use_preload) {
-	}
-}
-
-void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos) {
-	CLFile_SetPosition(*hnm->file, 1, pos);
-}
-
-void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height) {
-	unsigned int *input = (unsigned int *)frame_buffer;
-	unsigned int *line0 = (unsigned int *)final_buffer;
-	unsigned int *line1 = (unsigned int *)(final_buffer + 320);
-	int count = (height) / 2;
-	while (count--) {
-		short i;
-		for (i = 0; i < 320 / 4; i++) {
-			unsigned int p0 = *input++;
-			unsigned int p4 = *input++;
-#if 0
-			*line0++ = ((p4 & 0xFF00) >> 8) | ((p4 & 0xFF000000) >> 16) | ((p0 & 0xFF00) << 8) | (p0 & 0xFF000000);
-//			*line0++ = (p0 & 0xFF000000) | ((p0 & 0xFF00) << 8) | ((p4 & 0xFF000000) >> 16) | ((p4 & 0xFF00) >> 8);
-			*line1++ = ((p0 & 0xFF0000) << 8) | ((p0 & 0xFF) << 16) | ((p4 & 0xFF0000) >> 8) | (p4 & 0xFF);
-#else
-			*line0++ = (p0 & 0xFF) | ((p0 & 0xFF0000) >> 8) | ((p4 & 0xFF) << 16) | ((p4 & 0xFF0000) << 8);
-			*line1++ = ((p0 & 0xFF00) >> 8) | ((p0 & 0xFF000000) >> 16) | ((p4 & 0xFF00) << 8) | (p4 & 0xFF000000);
-#endif
-		}
-		line0 += 320 / 4;
-		line1 += 320 / 4;
-	}
-}
diff --git a/engines/cryo/CLSouNdRaw.c b/engines/cryo/CLSouNdRaw.c
deleted file mode 100644
index 0294dfe..0000000
--- a/engines/cryo/CLSouNdRaw.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "cryolib.h"
-
-sound_t *CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode) {
-	sound_t *sound;
-	CLBeginCheck;
-
-	sound = (sound_t *)CLMemory_Alloc(sizeof(*sound));
-	if (sound) {
-		sound->ff_1A = arg1;
-		sound->rate = rate;
-		sound->sampleSize = sampleSize;
-		sound->buffer = 0;
-//		sound->sndHandle = CLMemory_AllocHandle(arg1 + 100);
-//		if(!sound->sndHandle)
-//		{
-//			__libError = -1;
-//			__osError = MemError();
-//			CLCheckError();
-//		}
-//		else
-		{
-			CLSound_PrepareSample(sound, mode);
-			CLNoError;
-		}
-	} else {
-		__libError = -1;
-		__osError = MemError();
-		CLCheckError();
-	}
-
-	CLEndCheck;
-	return sound;
-}
-
-void CLSoundRaw_Free(sound_t *sound) {
-	while (sound->locked) ;
-//	CLMemory_FreeHandle(sound->sndHandle);
-	CLMemory_Free(sound);
-}
-
-void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
-	char *buf;
-	CLSound_SetLength(sound, length);
-	sound->length = length;
-	buf = bufferOffs + (char *)buffer;
-//	if(CLSound_GetWantsDesigned())
-//		CLSound_Signed2NonSigned(buf, length);
-	sound->buffer = buf;
-//	if(sound->reversed && sound->sampleSize == 16)
-//		ReverseBlock16(buf, length);
-}
diff --git a/engines/cryo/CryoLib.h b/engines/cryo/CryoLib.h
deleted file mode 100644
index ec06320..0000000
--- a/engines/cryo/CryoLib.h
+++ /dev/null
@@ -1,181 +0,0 @@
-#pragma once
-#define SW16(n) ( (((n) & 0xFF) << 8) | (((n) >> 8) & 0xFF) )
-#define SW32(n) ( (((n) & 0xFF) << 24) | (((n) >> 24) & 0xFF) | (((n) & 0xFF00) << 8) | (((n) >> 8) & 0xFF00))
-#if 0
-//big-endian host
-#define LE16(n) SW16(n)
-#define LE32(n) SW32(n)
-#define BE16(n) (n)
-#define BE32(n) (n)
-#else
-//little-endian host
-#define LE16(n) (n)
-#define LE32(n) (n)
-#define BE16(n) SW16(n)
-#define BE32(n) SW32(n)
-#endif
-#define PLE16(p) ( (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
-#define PLE32(p) ( (((unsigned char*)(p))[3] << 24) | (((unsigned char*)(p))[2] << 16) | (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
-
-#include "audio/mixer.h"
-
-typedef void *SndChannel;
-typedef char *Handle;
-enum {
-	fsFromStart = 1
-};
-
-extern short __debug2;
-
-extern short __debug, __libError, __osError;
-
-#define CLBeginCheck    { short __oldDebug = __debug; __debug = -1;
-#define CLEndCheck      __debug = __oldDebug; }
-#define CLNoError       __libError = 0;
-
-#define CLCheckError() if(__debug && __libError){   \
-		char buffer_[260];           \
-		sprintf(buffer_, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
-		DebugStr(c2pstr(buffer_));   \
-	};
-
-#define CLAssert(x) if(!(x)) {  \
-		char buffer_[260];           \
-		sprintf(buffer_, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
-		DebugStr(c2pstr(buffer_));   \
-	};
-
-struct rect_t {
-	int sy, sx, ey, ex;
-};
-typedef struct rect_t rect_t;
-
-struct view_t {
-	unsigned char   *p_buffer;
-	int     width;
-	int     height;
-	short   pitch;
-	short   doubled;
-	short   allocated;
-	struct {
-		int     src_left;
-		int     src_top;
-		int     dst_left;
-		int     dst_top;
-		int     width;
-		int     height;
-	} norm, zoom;
-};
-typedef struct view_t view_t;
-
-struct color3_t {
-	short   r, g, b;
-};
-typedef struct color3_t color3_t;
-
-struct color_t {
-	short   a, r, g, b;
-};
-typedef struct color_t color_t;
-
-struct palette_t {
-	color_t colors[256];
-};
-typedef struct palette_t palette_t;
-
-#pragma pack(push, 1)
-struct hnmheader_t {
-	int             id;
-	char            flag1;
-	char            flag2;
-	char            reseverd;
-	char            bpp;
-	unsigned short  width;
-	unsigned short  height;
-	int             filesize;
-	int             nframe;
-	int             table_offset;
-	short           speed;
-	short           maxbuffer;
-	int             buffersize;
-	short           ff_20;
-	char            reserved2[14];
-	char            copyright[16];
-};
-typedef struct hnmheader_t hnmheader_t;
-#pragma pack(pop)
-
-struct hnm_t {
-	int             frame;
-	int             ff_4;
-	file_t         *file;
-	hnmheader_t     header;
-	unsigned char   *work_buffer[2];
-	unsigned char   *final_buffer;
-	unsigned char   *new_frame_buffer;
-	unsigned char   *old_frame_buffer;
-	unsigned char   *read_buffer;
-	unsigned char   *data_ptr;
-	color_t         palette[256];
-
-	short           can_loop;
-
-	short           ff_896;
-	short           chunk_id;
-	int             total_read;
-};
-typedef struct hnm_t hnm_t;
-
-//struct filespec_t {
-//char  puff;
-//};
-
-struct sound_t {
-	Handle  sndHandle;
-	short   headerLen;
-	long    headerOffset;
-	short   ff_A;
-
-	char    *buffer;
-	int     ff_16;
-	short   ff_1A;
-	float   rate;
-	short   sampleSize;
-	int     length;
-	short   mode;
-	volatile short  locked;
-	long    loopStart;
-	short   loopTimes;
-	short   reversed;
-	short   ff_32;
-	short   volume;
-};
-typedef struct sound_t sound_t;
-
-#define CL_MAX_SOUNDS 64
-
-struct soundgroup_t {
-	sound_t *sound[CL_MAX_SOUNDS];
-	short   numSounds;
-	short   soundIndex;
-	short   playIndex;
-	short   ff_106;
-};
-typedef struct soundgroup_t soundgroup_t;
-
-#define CL_MAX_CH_SOUNDS 10
-
-struct soundchannel_t {
-	Audio::SoundHandle ch;
-	int     xx;
-
-	short   volumeLeft;
-	short   volumeRight;
-	short   numSounds;
-
-	sound_t *sounds[CL_MAX_CH_SOUNDS];
-
-	short   ff_536;
-};
-typedef struct soundchannel_t soundchannel_t;
-
diff --git a/engines/cryo/CryoLibStub.c b/engines/cryo/CryoLibStub.c
deleted file mode 100644
index ae6e48b..0000000
--- a/engines/cryo/CryoLibStub.c
+++ /dev/null
@@ -1,504 +0,0 @@
-
-///// Mac APIs
-typedef short OSErr;
-
-short MemError() {
-	return 0;
-}
-
-void SysBeep(int x) {
-}
-
-OSErr SetFPos(short handle, short mode, long pos) {
-	return 0;
-}
-
-OSErr FSRead(short handle, long *size, void *buffer) {
-	return 0;
-}
-
-void FlushEvents(short arg1, short arg2) {
-}
-
-char *c2pstr(char *s) {
-	return s;
-}
-
-void DebugStr(char *s) {
-}
-
-// from mw lib???
-long TickCount() {
-	return g_system->getMillis();
-}
-
-///// CLMemory
-void *CLMemory_Alloc(int size) {
-	return malloc(size);
-}
-void CLMemory_Free(void *ptr) {
-	//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
-	if (!ptr)
-		return;
-
-	free(ptr);
-}
-
-
-///// CLTimer
-volatile long TimerTicks = 0;   // incremented in realtime
-
-///// CLView
-void CLView_SetSrcZoomValues(view_t *view, int x, int y) {
-	view->zoom.src_left = x;
-	view->zoom.src_top = y;
-}
-void CLView_SetDisplayZoomValues(view_t *view, int w, int h) {
-	view->zoom.width = w;
-	view->zoom.height = h;
-}
-void CLView_Free(view_t *view) {
-	if (view->p_buffer && view->allocated)
-		CLMemory_Free(view->p_buffer);
-	if (view)
-		CLMemory_Free(view);
-}
-void CLView_InitDatas(view_t *view, int w, int h, void *buffer) {
-	view->p_buffer = (unsigned char *)buffer;
-	view->width = w;
-	view->height = h;
-	view->pitch = w;
-	view->doubled = 0;
-	view->norm.src_left = 0;
-	view->norm.src_top = 0;
-	view->norm.dst_left = 0;
-	view->norm.dst_top = 0;
-	view->norm.width = w;
-	view->norm.height = h;
-	view->zoom.src_left = 0;
-	view->zoom.src_top = 0;
-	view->zoom.dst_left = 0;
-	view->zoom.dst_top = 0;
-	view->zoom.width = w;
-	view->zoom.height = h;
-}
-view_t *CLView_New(int w, int h) {
-	view_t *view = (view_t *)CLMemory_Alloc(sizeof(view_t));
-	if (view) {
-		void *buffer = (unsigned char *)CLMemory_Alloc(w * h);
-		if (buffer) {
-			view->allocated = 1;
-			CLView_InitDatas(view, w, h, buffer);
-		} else {
-			CLMemory_Free(view);
-			view = 0;
-		}
-	}
-	return view;
-}
-void CLView_CenterIn(view_t *parent, view_t *child) {
-	child->norm.dst_left = (parent->width - child->norm.width) / 2;
-	child->norm.dst_top = (parent->height - child->norm.height) / 2;
-	child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
-	child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
-}
-
-///// CLScreenView
-view_t ScreenView;
-
-void CLScreenView_Init() {
-	// ScreenView is the game's target screen (a pc display)
-	// we use a dedicated surface for it, which at some point will be
-	// presented to user by System::copyRectToScreen call
-	CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
-}
-
-void CLScreenView_CenterIn(view_t *view) {
-	CLView_CenterIn(&ScreenView, view);
-}
-
-///// CLPalette
-unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
-short gMacintize = 0;
-color_t black_palette[256];
-color_t last_palette[256];
-void CLPalette_Init() {
-	short i;
-	for (i = 0; i < 256; i++)
-		black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
-}
-void CLPalette_SetLastPalette(color_t *palette, short first, short count) {
-	short i;
-	for (i = first; i < first + count; i++)
-		last_palette[i] = palette[i];
-}
-void CLPalette_GetLastPalette(color_t *palette) {
-	short i;
-	for (i = 0; i < 256; i++)
-		palette[i] = last_palette[i];
-}
-void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb) {
-	palette[index].r = rgb->r;
-	palette[index].g = rgb->g;
-	palette[index].b = rgb->b;
-	palette[index].a = 0;
-}
-void CLPalette_Macintize(short macintize) {
-	gMacintize = macintize;
-}
-void CLPalette_SetInterval(unsigned short first, unsigned short last) {
-	gIntervalFirst = first;
-	gIntervalSet = 1;
-	gIntervalLast = last;
-}
-void CLPalette_DeactivateInterval() {
-	gIntervalSet = 0;
-}
-void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count) {
-	OSErr err;
-	short i;
-	if (gMacintize) {
-		palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
-		palette[255].r = palette[255].g = palette[255].b = 0;
-	}
-	if (gIntervalSet) {
-		if (first < gIntervalFirst)
-			first = gIntervalFirst;
-		if (first + count > gIntervalLast)
-			count = gIntervalLast - first;
-	}
-
-	byte buffer[256 * 3];
-	for (i = 0; i < 256; i++) {
-		buffer[i * 3] = palette[i].r >> 8;
-		buffer[i * 3 + 1] = palette[i].g >> 8;
-		buffer[i * 3 + 2] = palette[i].b >> 8;
-	}
-
-	g_system->getPaletteManager()->setPalette(buffer, first, count);
-	g_system->updateScreen();
-
-	CLPalette_SetLastPalette(palette, first, count);
-}
-void CLPalette_BeBlack() {
-	CLPalette_Send2Screen(black_palette, 0, 256);
-}
-void CLPalette_BeSystem() {
-}
-
-///// CLBlitter
-static unsigned short newPaletteCount, newPaletteFirst;
-static color_t *pNewPalette;
-static unsigned short useNewPalette;
-
-void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2) {
-	int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
-	//  debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
-	//      rect1->sx, rect1->sy, rect1->ex, rect1->ey,
-	//      rect2->sx, rect2->sy, rect2->ex, rect2->ey,
-	//      (rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
-	assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
-	for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++) {
-		unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
-		unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
-		for (x = 0; x < w; x++)
-			*d++ = *s++;
-	}
-}
-void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count) {
-	pNewPalette = palette;
-	useNewPalette = 1;
-	newPaletteFirst = first;
-	newPaletteCount = count;
-}
-void CLBlitter_OneBlackFlash() {
-}
-void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
-                                       unsigned char *dst, short dstw, short dstp, short dsth) {
-	short x, y;
-	for (y = 0; y < srch; y++) {
-		for (x = 0; x < srcw; x++)
-			*dst++ = *src++;
-		src += srcp - srcw;
-		dst += dstp - dstw;
-	}
-}
-void CLBlitter_CopyView2ScreenCUSTOM(view_t *view) {
-	view_t *dest = &ScreenView;
-	if (!view->doubled) {
-		short srcpitch = view->pitch;
-		short dstpitch = dest->pitch;
-
-		//      this is not quite correct?
-		//      CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
-		//          dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
-
-		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
-		                                  dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
-
-	} else {
-		assert(0);
-	}
-}
-void CLBlitter_CopyView2Screen(view_t *view) {
-
-	if (useNewPalette) {
-		color_t palette[256];
-		CLPalette_GetLastPalette(palette);
-		CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
-		useNewPalette = 0;
-	}
-
-	//TODO: quick hack to force screen update
-	if (view)
-		CLBlitter_CopyView2ScreenCUSTOM(view);
-
-	g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
-	g_system->updateScreen();
-}
-void CLBlitter_UpdateScreen() {
-	CLBlitter_CopyView2Screen(nullptr);
-}
-void CLBlitter_FillView(view_t *view, unsigned int fill) {
-	short x, y;
-	unsigned char *d = view->p_buffer;
-	assert((fill & 0xFF) * 0x01010101 == fill);
-	for (y = 0; y < view->height; y++) {
-		for (x = 0; x < view->width; x++)
-			*d++ = fill;
-		d += view->pitch - view->width;
-	}
-}
-void CLBlitter_FillScreenView(unsigned int fill) {
-	CLBlitter_FillView(&ScreenView, fill);
-}
-
-
-///// events wrapper
-int _mouseButton;
-byte _keyState[256];
-
-void pollEvents() {
-	g_system->delayMillis(10);
-
-	Common::Event event;
-	while (g_system->getEventManager()->pollEvent(event)) {
-		// Handle keypress
-		switch (event.type) {
-		case Common::EVENT_QUIT:
-		case Common::EVENT_RTL:
-			return;
-
-		case Common::EVENT_KEYDOWN:
-			//          _keyState[(byte)toupper(event.kbd.ascii)] = true;
-			return;
-		case Common::EVENT_KEYUP:
-			//          _keyState[(byte)toupper(event.kbd.ascii)] = false;
-			return;
-		case Common::EVENT_LBUTTONDOWN:
-			_mouseButton = 1;
-			return;
-		case Common::EVENT_RBUTTONDOWN:
-			_mouseButton = 2;
-			return;
-		case Common::EVENT_LBUTTONUP:
-		case Common::EVENT_RBUTTONUP:
-			_mouseButton = 0;
-			return;
-		default:
-			break;
-		}
-	}
-}
-
-
-///// CLKeyboard
-short CLKeyboard_HasCmdDown() {
-	return 0;
-}
-void CLKeyboard_Read() {
-	pollEvents();
-}
-unsigned char CLKeyboard_GetLastASCII() {
-	return 0;
-}
-short CLKeyboard_IsScanCodeDown(short scancode) {
-	return 0;
-}
-
-///// CLMouse
-void CLMouse_Hide() {
-}
-void CLMouse_Show() {
-}
-void CLMouse_GetPosition(short *x, short *y) {
-	*x = g_system->getEventManager()->getMousePos().x;
-	*y = g_system->getEventManager()->getMousePos().y;
-}
-void CLMouse_SetPosition(short x, short y) {
-	g_system->warpMouse(x, y);
-}
-unsigned short CLMouse_IsDown() {
-	pollEvents();
-	return _mouseButton != 0;
-}
-
-///// CLFile
-void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7) {
-}
-void CLFile_SetFinderInfos(void *fs, int a4, int a5) {
-}
-void CLFile_GetFullPath(void *a3, char *a4) {
-}
-void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs) {
-	strcpy(fs->name, name);
-	fs->create = 0;
-}
-void CLFile_Create(filespec_t *fs) {
-	fs->create = 1;
-}
-void CLFile_Open(filespec_t *fs, short mode, file_t &handle) {
-	handle.open(fs->name);
-}
-void CLFile_Close(file_t &handle) {
-	handle.close();
-}
-void CLFile_SetPosition(file_t &handle, short mode, long pos) {
-	assert(mode == 1);
-	handle.seek(pos, 0);
-}
-void CLFile_Read(file_t &handle, void *buffer, long *size) {
-	handle.read(buffer, *size);
-}
-void CLFile_Write(file_t &handle, void *buffer, long *size) {
-	assert(0);
-}
-
-///// CLSound
-// base sound
-void CLSound_PrepareSample(sound_t *sound, short mode) {
-	sound->mode = mode;
-	sound->locked = 0;
-	sound->loopTimes = 0;
-	sound->reversed = 0;
-	sound->ff_32 = 0;
-	sound->volume = 255;
-}
-void CLSound_SetWantsDesigned(short designed) {
-}
-void CLSound_SetLength(sound_t *sound, int length) {
-}
-
-///// CLSoundRaw
-// sound from memory buffer
-#include "CLSouNdRaw.c"
-
-///// CLSoundChannel
-/// sound output device that plays queue of sounds
-soundchannel_t *CLSoundChannel_New(int arg1) {
-	short i;
-	soundchannel_t *ch = (soundchannel_t *)CLMemory_Alloc(sizeof(*ch));
-	if (!ch)
-		return 0;
-
-	ch->volumeLeft = ch->volumeRight = 255;
-	ch->numSounds = 0;
-
-	for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
-		ch->sounds[i] = 0;
-
-	return ch;
-}
-void CLSoundChannel_Free(soundchannel_t *ch) {
-	CLMemory_Free(ch);
-}
-void CLSoundChannel_Stop(soundchannel_t *ch) {
-	//  g_ed->_mixer->stopHandle(ch->ch);
-}
-void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound) {
-}
-short CLSoundChannel_GetVolume(soundchannel_t *ch) {
-	return (ch->volumeLeft + ch->volumeRight) / 2;
-}
-void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume) {
-	if (volume < 0 || volume > 255)
-		return;
-	ch->volumeLeft = volume;
-	ch->volumeRight = volume;
-}
-void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume) {
-	if (volume < 0 || volume > 255)
-		return;
-	ch->volumeRight = volume;
-}
-void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume) {
-	if (volume < 0 || volume > 255)
-		return;
-	ch->volumeLeft = volume;
-}
-
-///// CLSoundGroup
-/// a queue of sounds of same format
-#include "CLSoundGroup.c"
-
-///// CLTimer
-void CLTimer_Action(void *arg) {
-	//  long& counter = *((long*)arg);
-	//  counter++;
-	TimerTicks++;
-}
-
-void CLTimer_Init() {
-	g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
-}
-
-void CLTimer_Done() {
-	g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
-}
-
-///// CRYOLib
-void CRYOLib_InstallExitPatch() {
-}
-void CRYOLib_RemoveExitPatch() {
-}
-void CRYOLib_Init() {
-}
-void CRYOLib_Done() {
-}
-void CRYOLib_MinimalInit() {
-}
-void CRYOLib_ManagersInit() {
-	CLTimer_Init();
-	CLScreenView_Init();
-}
-void CRYOLib_ManagersDone() {
-	CLTimer_Done();
-}
-void CRYOLib_SetDebugMode(short enable) {
-}
-void CRYOLib_InstallEmergencyExit(void(*proc)()) {
-}
-void CRYOLib_SetupEnvironment() {
-}
-void CRYOLib_RestoreEnvironment() {
-}
-void CRYOLib_TestConfig() {
-}
-
-///// CLComputer
-short CLComputer_Has68030() {
-	return 0;
-}
-short CLComputer_Has68040() {
-	return 0;
-}
-
-///// CLDesktop
-void CLDesktop_TestOpenFileAtStartup() {
-}
-
-///// CLHNM
-#include "CLHNM.c"
-
-///// CLError
-#include "CLError.c"
diff --git a/engines/cryo/clerror.cpp b/engines/cryo/clerror.cpp
new file mode 100644
index 0000000..0fa2116
--- /dev/null
+++ b/engines/cryo/clerror.cpp
@@ -0,0 +1,7 @@
+#include "cryo/cryolib.h"
+
+namespace Cryo {
+
+short __debug, __libError, __osError;
+
+} // End of namespace Cryo
diff --git a/engines/cryo/clhnm.cpp b/engines/cryo/clhnm.cpp
new file mode 100644
index 0000000..1a25b7c
--- /dev/null
+++ b/engines/cryo/clhnm.cpp
@@ -0,0 +1,752 @@
+#include "common/debug.h"
+
+#include "cryo/cryolib.h"
+
+namespace Cryo {
+
+static short safe_palette = 0;
+static short pred_r = 0, pred_l = 0;
+static short use_adpcm = 0;
+static float hnm_rate = 0.0;
+static float next_frame_time = 0.0;
+static float expected_frame_time = 0.0;
+static float time_drift = 0.0;
+static short use_mono = 0;
+static short use_sound = 0;
+static short use_sound_sync = 0;
+static short pending_sounds = 0;
+static short sound_started = 0;
+static short preserve_color0 = 0;
+static soundchannel_t *soundChannel_adpcm = 0;
+static soundgroup_t *soundGroup_adpcm = 0;
+static soundchannel_t *soundChannel = 0;
+static soundgroup_t *soundGroup = 0;
+static void (*custom_chunk_handler)(unsigned char *buffer, int size, short id, char h6, char h7) = 0;
+static short use_preload = 0;
+static short decomp_table[256];
+
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
+
+void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output) {
+	unsigned char *inp = buffer;
+	unsigned char *out = output;
+
+	unsigned int queue = 0;
+	int qpos = -1;
+
+	//TODO: fix for BE
+#define GetBit() ( 1 & ( (qpos >= 0) ? (queue >> qpos--) : (queue = *(unsigned int*)((inp += 4) - 4)) >> ((qpos = 30) + 1) ) )
+
+	for (;;) {
+		if (GetBit()) {
+			*out++ = *inp++;
+		} else {
+			int l, o;
+			if (GetBit()) {
+				l = *inp & 7;
+				o = *(unsigned short *)inp >> 3;
+				inp += 2;
+				o -= 8192;
+				if (!l)
+					l = *inp++;
+				if (!l)
+					break;
+			} else {
+				l = GetBit() * 2 + GetBit();
+				o = *(inp++) - 256;
+			}
+			l += 2;
+			while (l--) {
+				*out = *(out + o);
+				out++;
+			}
+		}
+	}
+
+#undef GetBit
+
+	return;
+}
+
+void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
+                     unsigned char *input, int width, char flags) {
+	unsigned int code;
+	char mode, count, color;
+	unsigned short offs;
+	unsigned char *ref;
+	unsigned char *out_start = output;
+	unsigned char swap;
+	int shft1, shft2;
+//	return;
+	if ((flags & 1) == 0) {
+		//HNM4 classic
+		int twolinesabove = -(width * 2);
+		for (;;) {
+			code = PLE32(input) & 0xFFFFFF; //input++;
+			count = code & 0x1F;
+			if (count) {
+				input += 3;
+				mode = (code >> 5) & 0xF;
+				offs = code >> 9;
+				//
+				swap = mode >> 3;
+				ref = ((mode & 1) ? prev_buffer : curr_buffer) + (output - out_start) + (offs * 2) - 32768;
+				if (mode & 2) {
+					//                  ref += twolinesabove;
+					shft1 = twolinesabove + 1;
+					shft2 = 0;
+					//swap ^= 1;
+				} else {
+					shft1 = 0;
+					shft2 = 1;
+				}
+				while (count--) {
+					unsigned char b0 = ref[shft1];
+					unsigned char b1 = ref[shft2];
+					output[swap] = b0;
+					output[swap ^ 1] = b1;
+					output += 2;
+					ref += (mode & 4) ? -2 : 2;
+				}
+			} else {
+				input++;
+				mode = code & 0xFF; // bits 0..4 are zero
+				switch (mode) {
+				case 0:
+					*(output++) = *(input++);
+					*(output++) = *(input++);
+					break;
+				case 0x20:
+					output += 2 * *(input++);
+					break;
+				case 0x40:
+					output += 2 * (code >> 8);
+					input += 2;
+					break;
+				case 0x60:
+					count = *(input++);
+					color = *(input++);
+					while (count--) {
+						*(output++) = color;
+						*(output++) = color;
+					}
+					break;
+				default:
+					return;
+				}
+			}
+		}
+	} else {
+		assert(0);
+		//HNM4 hires
+		for (;;) {
+			code = PLE32(input) & 0xFFFFFF;
+			input++;
+			count = code & 0x3F;
+			if (count) {
+				mode = (code >> 5) & 0xF;
+				offs = code >> 9;
+				//
+			} else {
+				mode = code & 0xFF; // bits 0..5 are zero
+				switch (mode) {
+				case 0x00:
+					output += *input++;
+					break;
+				case 0x40:
+					*output++ = *input++;
+					*(output++ + width) = *input++;
+					break;
+				case 0x80:
+					output += width;
+					break;
+				default:
+					return;
+				}
+			}
+		}
+	}
+}
+
+void CLHNM_Init() {
+	use_preload = 0;
+	custom_chunk_handler = 0;
+	preserve_color0 = 0;
+	CLNoError;
+}
+
+void CLHNM_Done() {
+	CLNoError;
+}
+
+void CLHNM_SetupTimer(float rate) {
+	hnm_rate = 100.0 / rate;
+	CLNoError;
+}
+
+void CLHNM_WaitLoop(hnm_t *hnm) {
+	expected_frame_time += hnm_rate;
+	next_frame_time = expected_frame_time - time_drift;
+	if (use_sound_sync && TimerTicks > 1000.0 + next_frame_time)
+		use_sound = 0;
+	while (TimerTicks < next_frame_time) ;  // waste time
+	time_drift = TimerTicks - next_frame_time;
+}
+
+void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode) {
+	soundChannel = CLSoundChannel_New(mode);
+	soundGroup = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
+	if (sampleSize == 16)
+		CLSoundGroup_Reverse16All(soundGroup);
+}
+
+void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode) {
+	soundChannel_adpcm = CLSoundChannel_New(mode);
+	soundGroup_adpcm = CLSoundGroup_New(numSounds, arg4, sampleSize, rate, mode);
+}
+
+void CLHNM_CloseSound() {
+	if (soundChannel) {
+		CLSoundChannel_Stop(soundChannel);
+		CLSoundChannel_Free(soundChannel);
+		soundChannel = 0;
+	}
+	if (soundGroup) {
+		CLSoundGroup_Free(soundGroup);
+		soundGroup = 0;
+	}
+	if (soundChannel_adpcm) {
+		CLSoundChannel_Stop(soundChannel_adpcm);
+		CLSoundChannel_Free(soundChannel_adpcm);
+		soundChannel = 0;
+	}
+	if (soundGroup_adpcm) {
+		CLSoundGroup_Free(soundGroup_adpcm);
+		soundGroup = 0;
+	}
+}
+
+void CLHNM_SetForceZero2Black(short forceblack) {
+	preserve_color0 = forceblack;
+}
+
+hnm_t *CLHNM_New(int preload_size) {
+	hnm_t *hnm;
+	short i;
+
+	preload_size = 0;   //TODO: let's ignore it for now
+
+	CLBeginCheck;
+	hnm = (hnm_t *)CLMemory_Alloc(sizeof(*hnm));
+	CLCheckError();
+	if (hnm) {
+		if (preload_size) {
+			use_preload = 1;
+
+		}
+		if (!__libError) {
+			hnm->frame = 0;
+			hnm->ff_4 = 0;
+			hnm->file = 0;
+			hnm->work_buffer[0] = 0;
+			hnm->work_buffer[1] = 0;
+			hnm->final_buffer = 0;
+			hnm->read_buffer = 0;
+			hnm->ff_896 = 0;
+			hnm->total_read = 0;
+			for (i = 0; i < 256; i++) {
+				hnm->palette[i].a = 0;
+				hnm->palette[i].r = 0;
+				hnm->palette[i].g = 0;
+				hnm->palette[i].b = 0;
+			}
+		} else
+			CLCheckError();
+	}
+	CLEndCheck;
+	return hnm;
+}
+
+void CLHNM_Dispose(hnm_t *hnm) {
+	CLBeginCheck;
+
+	if (use_preload) {
+
+	}
+
+	CLMemory_Free(hnm);
+	CLCheckError();
+
+	CLEndCheck;
+}
+
+
+void CLHNM_SetFile(hnm_t *hnm, file_t *file) {
+	hnm->file = file;
+	CLNoError;
+}
+
+void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer) {
+	hnm->final_buffer = buffer;
+	CLNoError;
+}
+
+void CLHNM_AllocMemory(hnm_t *hnm) {
+	CLBeginCheck;
+
+	hnm->work_buffer[0] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
+	CLCheckError();
+
+	if (!hnm->work_buffer[0])
+		goto fin;
+
+	hnm->work_buffer[1] = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
+	CLCheckError();
+
+	if (!hnm->work_buffer[1]) {
+		CLMemory_Free(hnm->work_buffer[0]);
+		CLCheckError();
+		hnm->work_buffer[0] = 0;
+		goto fin;
+	}
+
+	if (!use_preload) {
+		hnm->read_buffer = (unsigned char *)CLMemory_Alloc(hnm->header.buffersize + 2);
+//		CLCheckError();
+		if (!hnm->read_buffer) {
+			CLMemory_Free(hnm->work_buffer[0]);
+			CLCheckError();
+			hnm->work_buffer[0] = 0;
+			CLMemory_Free(hnm->work_buffer[1]);
+			CLCheckError();
+			hnm->work_buffer[1] = 0;
+		}
+	}
+fin:
+	;
+	CLEndCheck;
+}
+
+void CLHNM_DeallocMemory(hnm_t *hnm) {
+	CLBeginCheck;
+	if (hnm->work_buffer[0]) {
+		CLMemory_Free(hnm->work_buffer[0]);
+		CLCheckError();
+		hnm->work_buffer[0] = 0;
+	}
+	if (hnm->work_buffer[1]) {
+		CLMemory_Free(hnm->work_buffer[1]);
+		CLCheckError();
+		hnm->work_buffer[1] = 0;
+	}
+
+	if (!use_preload) {
+		if (hnm->read_buffer) {
+			CLMemory_Free(hnm->read_buffer);
+			CLCheckError();
+			hnm->read_buffer = 0;
+		}
+	}
+
+	CLEndCheck;
+}
+
+void CLHNM_Read(hnm_t *hnm, int size) {
+	long _size = size;
+	if (!use_preload) {
+		CLFile_Read(*hnm->file, hnm->read_buffer, &_size);
+	} else {
+	}
+}
+
+void CLHNM_GiveTime(hnm_t *hnm) {
+	if (use_preload) {
+		//stuff preload_buffer from disk
+	}
+}
+
+void CLHNM_CanLoop(hnm_t *hnm, short can_loop) {
+	hnm->can_loop = can_loop;
+}
+
+void CLHNM_SelectBuffers(hnm_t *hnm) {
+	if (hnm->frame % 2) {
+		hnm->new_frame_buffer = hnm->work_buffer[1];
+		hnm->old_frame_buffer = hnm->work_buffer[0];
+	} else {
+		hnm->new_frame_buffer = hnm->work_buffer[0];
+		hnm->old_frame_buffer = hnm->work_buffer[1];
+	}
+}
+
+void CLHNM_ChangePalette(hnm_t *hnm) {
+	short mincolor, maxcolor;
+	unsigned short fst, cnt;
+	unsigned char *pal;
+	color_t *color;
+	CLPalette_GetLastPalette(hnm->palette);
+	pal = hnm->data_ptr;
+	if (*(unsigned short *)pal == 0xFFFF)
+		return;
+	mincolor = 255;
+	maxcolor = 0;
+	do {
+		fst = *pal++;
+		cnt = *pal++;
+		if (cnt == 0)
+			cnt = 256;
+		debug("hnm: setting palette, fst = %d, cnt = %d, last = %d", fst, cnt, fst + cnt - 1);
+		assert(fst + cnt <= 256);
+		if (mincolor > fst)
+			mincolor = fst;
+		if (maxcolor < fst + cnt)
+			maxcolor = fst + cnt;
+		color = hnm->palette + fst;
+		if (safe_palette) {
+			while (cnt--) {
+				unsigned char r = *pal++;
+				unsigned char g = *pal++;
+				unsigned char b = *pal++;
+				short rr = r << 10;
+				short gg = g << 10;
+				short bb = b << 10;
+				if (color->r != rr || color->g != gg || color->b != bb)
+					CLBlitter_OneBlackFlash();
+				color->r = rr;
+				color->g = gg;
+				color->b = bb;
+				color++;
+			}
+		} else {
+			while (cnt--) {
+				unsigned char r = *pal++;
+				unsigned char g = *pal++;
+				unsigned char b = *pal++;
+				color->r = r << 10;
+				color->g = g << 10;
+				color->b = b << 10;
+				color++;
+			}
+		}
+
+	} while (*(unsigned short *)pal != 0xFFFF);
+#if 0
+	if (preserve_color0) {
+		hnm->palette[0].r = 0;
+		hnm->palette[0].g = 0;
+		hnm->palette[0].b = 0;
+	}
+#endif
+//	CLBlitter_Send2ScreenNextCopy(hnm->palette, mincolor, maxcolor - mincolor);
+	CLBlitter_Send2ScreenNextCopy(hnm->palette, 0, 256);
+}
+
+void CLHNM_Desentrelace(hnm_t *hnm) {
+	switch (hnm->header.width) {
+	case 320:
+		CLHNM_Desentrelace320(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+		CLNoError;
+		break;
+//	case 480:
+//		CLHNM_Desentrelace480(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//		CLNoError;
+//		break;
+	default:
+		__libError = -5;
+		__osError = 0;
+		CLCheckError();
+	}
+}
+
+void CLHNM_FlushPreloadBuffer(hnm_t *hnm) {
+	if (use_preload) {
+	}
+}
+
+soundchannel_t *CLHNM_GetSoundChannel() {
+	return soundChannel;
+}
+
+
+void CLHNM_TryRead(hnm_t *hnm, int size) {
+	short err;
+	do {
+		CLHNM_Read(hnm, size);
+		err = __libError == -6;
+		if (err)
+			CLHNM_GiveTime(hnm);
+	} while (err);
+}
+
+void CLHNM_ResetInternalTimer() {
+	time_drift = 0.0;
+	next_frame_time = expected_frame_time = TimerTicks;
+}
+
+void CLHNM_Reset(hnm_t *hnm) {
+	hnm->frame = 0;
+	hnm->ff_4 = 0;
+	hnm->total_read = 0;
+	sound_started = 0;
+	pending_sounds = 0;
+	CLHNM_ResetInternalTimer();
+	CLNoError;
+}
+
+short CLHNM_LoadFrame(hnm_t *hnm) {
+	int chunk;
+	CLBeginCheck;
+	CLHNM_TryRead(hnm, 4);
+	CLEndCheck;
+	chunk = *(int *)hnm->read_buffer;
+	chunk = LE32(chunk);
+	chunk &= 0xFFFFFF;  // upper bit - keyframe mark?
+	if (!chunk)
+		return 0;
+
+	if (use_preload) {
+	} else {
+		if (chunk - 4 > hnm->header.buffersize) {
+			__libError = -3;
+			__osError = 0;
+			CLCheckError();
+		} else if (use_preload && chunk - 4 > 102400) {
+			__libError = -3;
+			__osError = 0;
+			CLCheckError();
+		}
+	}
+	CLBeginCheck;
+	CLHNM_TryRead(hnm, chunk - 4);
+	CLEndCheck;
+	hnm->data_ptr = hnm->read_buffer;
+	hnm->total_read += chunk;
+	return 1;
+}
+
+void CLHNM_WantsSound(short sound) {
+	use_sound = sound;
+}
+
+void CLHNM_LoadDecompTable(short *buffer) {
+	short i;
+	short e;
+	for (i = 0; i < 256; i++) {
+		e = *buffer++;
+		decomp_table[i] = LE16(e);
+	}
+}
+
+void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size) {
+	short l = pred_l, r = pred_r;
+	size &= ~1;
+	while (size--) {
+		*output++ = l += decomp_table[*buffer++];
+		*output++ = r += decomp_table[*buffer++];
+		if (l > 512 || r > 512)
+			DebugStr(" coucou");
+	}
+	pred_l = l;
+	pred_r = r;
+}
+
+void CLHNM_SoundInADPCM(short is_adpcm) {
+	use_adpcm = is_adpcm;
+}
+
+void CLHNM_SoundMono(short is_mono) {
+	use_mono = is_mono;
+}
+
+short CLHNM_NextElement(hnm_t *hnm) {
+	int sz;
+	short id;
+	char h6, h7;
+	short i;
+	if (hnm->frame == 0) {
+		CLHNM_ResetInternalTimer();
+		pred_l = pred_r = 0;
+	}
+	if (hnm->frame == hnm->header.nframe)
+		return 0;
+	if (!CLHNM_LoadFrame(hnm))
+		return 0;
+	for (;;) {
+		sz = PLE32(hnm->data_ptr) & 0xFFFFFF;
+		hnm->data_ptr += 4;
+		id = *(short *)hnm->data_ptr;
+		hnm->data_ptr += 2;
+		h6 = *hnm->data_ptr;
+		hnm->data_ptr += 1;
+		h7 = *hnm->data_ptr;
+		hnm->data_ptr += 1;
+		hnm->chunk_id = id;
+		switch (id) {
+		case BE16('PL'):
+			CLHNM_ChangePalette(hnm);
+			hnm->data_ptr += sz - 8;
+			break;
+		case BE16('IZ'):
+			hnm->frame++;
+			CLHNM_SelectBuffers(hnm);
+			CLHNM_DecompLempelZiv(hnm->data_ptr + 4, hnm->new_frame_buffer);
+			switch (hnm->header.width) {
+//			case 320: CLBlitter_RawCopy320ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			case 480: CLBlitter_RawCopy480ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			case 640: CLBlitter_RawCopy640ASM(hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->header.height); break;
+//			default: memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+			default:
+				memcpy(hnm->old_frame_buffer, hnm->new_frame_buffer, hnm->header.buffersize);  //TODO strange buffer size here
+			}
+			if (!(h6 & 1))
+				CLHNM_Desentrelace(hnm);
+			else {
+//				if(hnm->header.width == 640)
+//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//				else
+				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.height);   //TODO: wrong size?
+			}
+			if (use_adpcm) {
+				if (!sound_started) {
+					for (i = 0; i < pending_sounds; i++)
+						CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
+					sound_started = 1;
+				}
+			} else {
+				if (!sound_started) {
+					for (i = 0; i < pending_sounds; i++)
+						CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
+					sound_started = 1;
+				}
+			}
+			goto end_frame;
+		case BE16('IU'):
+			hnm->frame++;
+			CLHNM_SelectBuffers(hnm);
+			CLHNM_DecompUBA(hnm->new_frame_buffer, hnm->new_frame_buffer, hnm->old_frame_buffer, hnm->data_ptr, hnm->header.width, h6);
+			if (!(h6 & 1))
+				CLHNM_Desentrelace(hnm);
+			else {
+//				if(hnm->header.width == 640)
+//					CLBlitter_RawCopy640(hnm->new_frame_buffer, hnm->final_buffer, hnm->header.height);
+//				else
+				memcpy(hnm->final_buffer, hnm->new_frame_buffer, hnm->header.width * hnm->header.height);
+			}
+			goto end_frame;
+		case BE16('sd'):
+		case BE16('SD'):
+			if (use_sound) {
+				if (!h6) {
+					int sound_size = sz - 8;
+					if (!use_adpcm) {
+						CLSoundGroup_SetDatas(soundGroup, hnm->data_ptr, sound_size - 2, 0);
+						if (sound_started)
+							CLSoundGroup_PlayNextSample(soundGroup, soundChannel);
+						else
+							pending_sounds++;
+					} else {
+						short *sound_buffer = (short *)CLSoundGroup_GetNextBuffer(soundGroup_adpcm);
+						if (!pending_sounds) {
+							const int kDecompTableSize = 256 * sizeof(short);
+							CLHNM_LoadDecompTable((short *)hnm->data_ptr);
+							CLHNM_DecompADPCM(hnm->data_ptr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize);
+							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, 0);
+						} else {
+							CLHNM_DecompADPCM(hnm->data_ptr, sound_buffer, sound_size);
+							CLSoundGroup_AssignDatas(soundGroup_adpcm, sound_buffer, sound_size * 2, 0);
+						}
+						pending_sounds++;
+						if (sound_started)
+							CLSoundGroup_PlayNextSample(soundGroup_adpcm, soundChannel);
+					}
+				} else {
+					__libError = -3;
+					__osError = 0;
+					CLCheckError();
+				}
+			}
+			hnm->data_ptr += sz - 8;
+			break;
+		default:
+			if (custom_chunk_handler)
+				custom_chunk_handler(hnm->data_ptr, sz - 8, id, h6, h7);
+			hnm->data_ptr += sz - 8;
+		}
+	}
+end_frame:
+	;
+	if (use_preload) {
+	}
+	return 1;
+}
+
+void CLHNM_ReadHeader(hnm_t *hnm) {
+	CLBeginCheck;
+	if (!use_preload) {
+		long size = sizeof(hnm->header);
+		CLFile_Read(*hnm->file, &hnm->header, &size);
+	} else
+		;
+	CLCheckError();
+	CLEndCheck;
+	hnm->header.width = LE16(hnm->header.width);
+	hnm->header.height = LE16(hnm->header.height);
+	hnm->header.filesize = LE32(hnm->header.filesize);
+	hnm->header.nframe = LE32(hnm->header.nframe);
+	hnm->header.table_offset = LE32(hnm->header.table_offset);
+	hnm->header.speed = LE16(hnm->header.speed);
+	hnm->header.maxbuffer = LE16(hnm->header.maxbuffer);
+	hnm->header.buffersize = LE32(hnm->header.buffersize);
+	hnm->header.ff_20 = LE16(hnm->header.ff_20);
+	hnm->header.buffersize += 4096; //TODO: checkme
+}
+
+short CLHNM_GetVersion(hnm_t *hnm) {
+	CLNoError;
+	if (hnm->header.id == BE32('HNM4'))
+		return 4;
+	return -1;
+}
+
+int CLHNM_GetFrameNum(hnm_t *hnm) {
+	return hnm->frame;
+}
+
+void CLHNM_DeactivatePreloadBuffer() {
+	use_preload = 0;
+}
+
+void CLHNM_Prepare2Read(hnm_t *hnm, int mode) {
+	if (use_preload) {
+	}
+}
+
+void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos) {
+	CLFile_SetPosition(*hnm->file, 1, pos);
+}
+
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height) {
+	unsigned int *input = (unsigned int *)frame_buffer;
+	unsigned int *line0 = (unsigned int *)final_buffer;
+	unsigned int *line1 = (unsigned int *)(final_buffer + 320);
+	int count = (height) / 2;
+	while (count--) {
+		short i;
+		for (i = 0; i < 320 / 4; i++) {
+			unsigned int p0 = *input++;
+			unsigned int p4 = *input++;
+#if 0
+			*line0++ = ((p4 & 0xFF00) >> 8) | ((p4 & 0xFF000000) >> 16) | ((p0 & 0xFF00) << 8) | (p0 & 0xFF000000);
+//			*line0++ = (p0 & 0xFF000000) | ((p0 & 0xFF00) << 8) | ((p4 & 0xFF000000) >> 16) | ((p4 & 0xFF00) >> 8);
+			*line1++ = ((p0 & 0xFF0000) << 8) | ((p0 & 0xFF) << 16) | ((p4 & 0xFF0000) >> 8) | (p4 & 0xFF);
+#else
+			*line0++ = (p0 & 0xFF) | ((p0 & 0xFF0000) >> 8) | ((p4 & 0xFF) << 16) | ((p4 & 0xFF0000) << 8);
+			*line1++ = ((p0 & 0xFF00) >> 8) | ((p0 & 0xFF000000) >> 16) | ((p4 & 0xFF00) << 8) | (p4 & 0xFF000000);
+#endif
+		}
+		line0 += 320 / 4;
+		line1 += 320 / 4;
+	}
+}
+
+} // End of namespace Cryo
diff --git a/engines/cryo/clsoundgroup.c b/engines/cryo/clsoundgroup.c
deleted file mode 100644
index a1abaf4..0000000
--- a/engines/cryo/clsoundgroup.c
+++ /dev/null
@@ -1,105 +0,0 @@
-#include "cryolib.h"
-
-soundgroup_t *CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode) {
-	soundgroup_t *sg;
-	short i;
-
-	sg = (soundgroup_t *)CLMemory_Alloc(sizeof(*sg));
-	if (numSounds < CL_MAX_SOUNDS)
-		sg->numSounds = numSounds;
-	else {
-		__libError = -3;
-		__osError = 0;
-		CLCheckError();
-		sg->numSounds = CL_MAX_SOUNDS;
-	}
-	for (i = 0; i < sg->numSounds; i++) {
-		sound_t *sound = CLSoundRaw_New(arg4, rate, sampleSize, mode);
-		sg->sound[i] = sound;
-		sound->ff_1A = arg4;
-	}
-	sg->soundIndex = 0;
-	sg->playIndex = 0;
-	sg->ff_106 = 1;
-
-	return sg;
-}
-
-void CLSoundGroup_Free(soundgroup_t *sg) {
-	short i;
-	for (i = 0; i < sg->numSounds; i++)
-		CLSoundRaw_Free(sg->sound[i]);
-	CLMemory_Free(sg);
-}
-
-void CLSoundGroup_Reverse16All(soundgroup_t *sg) {
-	short i;
-	for (i = 0; i < sg->numSounds; i++)
-		sg->sound[i]->reversed = 1;
-}
-
-void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg) {
-	sound_t *sound = sg->sound[sg->soundIndex];
-	if (sg->ff_106)
-		while (sound->locked) ;
-	return ((char *)(*sound->sndHandle)) + sound->headerLen;
-}
-
-short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned) {
-	sound_t *sound = sg->sound[sg->soundIndex];
-	if (sg->ff_106)
-		while (sound->locked) ;
-	else if (sound->locked)
-		return 0;
-	sound->buffer = (char *)buffer;
-	CLSound_SetLength(sound, length);
-	sound->length = length;
-//	if(sound->reversed && sound->sampleSize == 16)
-//		ReverseBlock16(buffer, length);
-//	if(isSigned)
-//		CLSound_Signed2NonSigned(buffer, length);
-	if (sg->soundIndex == sg->numSounds - 1)
-		sg->soundIndex = 0;
-	else
-		sg->soundIndex++;
-
-	return 1;
-}
-
-short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned) {
-	void *buffer;
-	sound_t *sound = sg->sound[sg->soundIndex];
-	if (length >= sound->ff_1A) {
-		__libError = -10;
-		__osError = 0;
-		CLCheckError();
-	}
-	if (sg->ff_106)
-		while (sound->locked) ;
-	else if (sound->locked)
-		return 0;
-	buffer = ((char *)(*sound->sndHandle)) + sound->headerLen;
-	sound->buffer = (char *)buffer;
-	memcpy(buffer, data, length);
-	CLSound_SetLength(sound, length);
-	sound->length = length;
-//	if(sound->reversed && sound->sampleSize == 16)
-//		ReverseBlock16(buffer, length);
-//	if(isSigned)
-//		CLSound_Signed2NonSigned(buffer, length);
-	if (sg->soundIndex == sg->numSounds - 1)
-		sg->soundIndex = 0;
-	else
-		sg->soundIndex++;
-
-	return 1;
-}
-
-void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch) {
-	CLSoundChannel_Play(ch, sg->sound[sg->playIndex]);
-	if (sg->playIndex == sg->numSounds - 1)
-		sg->playIndex = 0;
-	else
-		sg->playIndex++;
-
-}
diff --git a/engines/cryo/clsoundgroup.cpp b/engines/cryo/clsoundgroup.cpp
new file mode 100644
index 0000000..1011901
--- /dev/null
+++ b/engines/cryo/clsoundgroup.cpp
@@ -0,0 +1,109 @@
+#include "cryo/cryolib.h"
+
+namespace Cryo {
+
+soundgroup_t *CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode) {
+	soundgroup_t *sg;
+	short i;
+
+	sg = (soundgroup_t *)CLMemory_Alloc(sizeof(*sg));
+	if (numSounds < CL_MAX_SOUNDS)
+		sg->numSounds = numSounds;
+	else {
+		__libError = -3;
+		__osError = 0;
+		CLCheckError();
+		sg->numSounds = CL_MAX_SOUNDS;
+	}
+	for (i = 0; i < sg->numSounds; i++) {
+		sound_t *sound = CLSoundRaw_New(arg4, rate, sampleSize, mode);
+		sg->sound[i] = sound;
+		sound->ff_1A = arg4;
+	}
+	sg->soundIndex = 0;
+	sg->playIndex = 0;
+	sg->ff_106 = 1;
+
+	return sg;
+}
+
+void CLSoundGroup_Free(soundgroup_t *sg) {
+	short i;
+	for (i = 0; i < sg->numSounds; i++)
+		CLSoundRaw_Free(sg->sound[i]);
+	CLMemory_Free(sg);
+}
+
+void CLSoundGroup_Reverse16All(soundgroup_t *sg) {
+	short i;
+	for (i = 0; i < sg->numSounds; i++)
+		sg->sound[i]->reversed = 1;
+}
+
+void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg) {
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if (sg->ff_106)
+		while (sound->locked) ;
+	return ((char *)(*sound->sndHandle)) + sound->headerLen;
+}
+
+short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned) {
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if (sg->ff_106)
+		while (sound->locked) ;
+	else if (sound->locked)
+		return 0;
+	sound->buffer = (char *)buffer;
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buffer, length);
+//	if(isSigned)
+//		CLSound_Signed2NonSigned(buffer, length);
+	if (sg->soundIndex == sg->numSounds - 1)
+		sg->soundIndex = 0;
+	else
+		sg->soundIndex++;
+
+	return 1;
+}
+
+short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned) {
+	void *buffer;
+	sound_t *sound = sg->sound[sg->soundIndex];
+	if (length >= sound->ff_1A) {
+		__libError = -10;
+		__osError = 0;
+		CLCheckError();
+	}
+	if (sg->ff_106)
+		while (sound->locked) ;
+	else if (sound->locked)
+		return 0;
+	buffer = ((char *)(*sound->sndHandle)) + sound->headerLen;
+	sound->buffer = (char *)buffer;
+	memcpy(buffer, data, length);
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buffer, length);
+//	if(isSigned)
+//		CLSound_Signed2NonSigned(buffer, length);
+	if (sg->soundIndex == sg->numSounds - 1)
+		sg->soundIndex = 0;
+	else
+		sg->soundIndex++;
+
+	return 1;
+}
+
+void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch) {
+	CLSoundChannel_Play(ch, sg->sound[sg->playIndex]);
+	if (sg->playIndex == sg->numSounds - 1)
+		sg->playIndex = 0;
+	else
+		sg->playIndex++;
+
+}
+
+} // End of namespace Cryo
diff --git a/engines/cryo/clsoundraw.cpp b/engines/cryo/clsoundraw.cpp
new file mode 100644
index 0000000..7058780
--- /dev/null
+++ b/engines/cryo/clsoundraw.cpp
@@ -0,0 +1,55 @@
+#include "cryo/cryolib.h"
+
+namespace Cryo {
+
+sound_t *CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode) {
+	sound_t *sound;
+	CLBeginCheck;
+
+	sound = (sound_t *)CLMemory_Alloc(sizeof(*sound));
+	if (sound) {
+		sound->ff_1A = arg1;
+		sound->rate = rate;
+		sound->sampleSize = sampleSize;
+		sound->buffer = 0;
+//		sound->sndHandle = CLMemory_AllocHandle(arg1 + 100);
+//		if(!sound->sndHandle)
+//		{
+//			__libError = -1;
+//			__osError = MemError();
+//			CLCheckError();
+//		}
+//		else
+		{
+			CLSound_PrepareSample(sound, mode);
+			CLNoError;
+		}
+	} else {
+		__libError = -1;
+		__osError = MemError();
+		CLCheckError();
+	}
+
+	CLEndCheck;
+	return sound;
+}
+
+void CLSoundRaw_Free(sound_t *sound) {
+	while (sound->locked) ;
+//	CLMemory_FreeHandle(sound->sndHandle);
+	CLMemory_Free(sound);
+}
+
+void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
+	char *buf;
+	CLSound_SetLength(sound, length);
+	sound->length = length;
+	buf = bufferOffs + (char *)buffer;
+//	if(CLSound_GetWantsDesigned())
+//		CLSound_Signed2NonSigned(buf, length);
+	sound->buffer = buf;
+//	if(sound->reversed && sound->sampleSize == 16)
+//		ReverseBlock16(buf, length);
+}
+
+} // End of namespace Cryo
diff --git a/engines/cryo/cryo.cpp b/engines/cryo/cryo.cpp
index 7aed601..87b50e8 100644
--- a/engines/cryo/cryo.cpp
+++ b/engines/cryo/cryo.cpp
@@ -73,7 +73,7 @@ Common::Error CryoEngine::run() {
 	// This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline
 	debugC(3, kCryoDebugExample | kCryoDebugExample2, "Example debug call two");
 
-	game.main();
+	game.run();
 
 	return Common::kNoError;
 }
diff --git a/engines/cryo/cryo.h b/engines/cryo/cryo.h
index 9a0d48b..2e76708 100644
--- a/engines/cryo/cryo.h
+++ b/engines/cryo/cryo.h
@@ -1,5 +1,5 @@
-#ifndef CRYO_H
-#define CRYO_H
+#ifndef CRYO_CRYO_H
+#define CRYO_CRYO_H
 
 #include "common/scummsys.h"
 #include "common/config-manager.h"
diff --git a/engines/cryo/cryolib.cpp b/engines/cryo/cryolib.cpp
new file mode 100644
index 0000000..2ea53fd
--- /dev/null
+++ b/engines/cryo/cryolib.cpp
@@ -0,0 +1,502 @@
+#include "common/system.h"
+#include "common/events.h"
+#include "common/timer.h"
+
+#include "graphics/palette.h"
+
+#include "cryo/cryo.h"
+#include "cryo/cryolib.h"
+
+namespace Cryo {
+
+///// Mac APIs
+typedef short OSErr;
+
+short MemError() {
+	return 0;
+}
+
+void SysBeep(int x) {
+}
+
+OSErr SetFPos(short handle, short mode, long pos) {
+	return 0;
+}
+
+OSErr FSRead(short handle, long *size, void *buffer) {
+	return 0;
+}
+
+void FlushEvents(short arg1, short arg2) {
+}
+
+char *c2pstr(char *s) {
+	return s;
+}
+
+void DebugStr(char *s) {
+}
+
+// from mw lib???
+long TickCount() {
+	return g_system->getMillis();
+}
+
+///// CLMemory
+void *CLMemory_Alloc(int size) {
+	return malloc(size);
+}
+void CLMemory_Free(void *ptr) {
+	//TODO: due to a bug in ssndfl() sometimes a null ptr passed, skip it
+	if (!ptr)
+		return;
+
+	free(ptr);
+}
+
+
+///// CLTimer
+volatile long TimerTicks = 0;   // incremented in realtime
+
+///// CLView
+void CLView_SetSrcZoomValues(view_t *view, int x, int y) {
+	view->zoom.src_left = x;
+	view->zoom.src_top = y;
+}
+void CLView_SetDisplayZoomValues(view_t *view, int w, int h) {
+	view->zoom.width = w;
+	view->zoom.height = h;
+}
+void CLView_Free(view_t *view) {
+	if (view->p_buffer && view->allocated)
+		CLMemory_Free(view->p_buffer);
+	if (view)
+		CLMemory_Free(view);
+}
+void CLView_InitDatas(view_t *view, int w, int h, void *buffer) {
+	view->p_buffer = (unsigned char *)buffer;
+	view->width = w;
+	view->height = h;
+	view->pitch = w;
+	view->doubled = 0;
+	view->norm.src_left = 0;
+	view->norm.src_top = 0;
+	view->norm.dst_left = 0;
+	view->norm.dst_top = 0;
+	view->norm.width = w;
+	view->norm.height = h;
+	view->zoom.src_left = 0;
+	view->zoom.src_top = 0;
+	view->zoom.dst_left = 0;
+	view->zoom.dst_top = 0;
+	view->zoom.width = w;
+	view->zoom.height = h;
+}
+view_t *CLView_New(int w, int h) {
+	view_t *view = (view_t *)CLMemory_Alloc(sizeof(view_t));
+	if (view) {
+		void *buffer = (unsigned char *)CLMemory_Alloc(w * h);
+		if (buffer) {
+			view->allocated = 1;
+			CLView_InitDatas(view, w, h, buffer);
+		} else {
+			CLMemory_Free(view);
+			view = 0;
+		}
+	}
+	return view;
+}
+void CLView_CenterIn(view_t *parent, view_t *child) {
+	child->norm.dst_left = (parent->width - child->norm.width) / 2;
+	child->norm.dst_top = (parent->height - child->norm.height) / 2;
+	child->zoom.dst_left = (parent->width - child->zoom.width) / 2;
+	child->zoom.dst_top = (parent->height - child->zoom.height) / 2;
+}
+
+///// CLScreenView
+view_t ScreenView;
+
+void CLScreenView_Init() {
+	// ScreenView is the game's target screen (a pc display)
+	// we use a dedicated surface for it, which at some point will be
+	// presented to user by System::copyRectToScreen call
+	CLView_InitDatas(&ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
+}
+
+void CLScreenView_CenterIn(view_t *view) {
+	CLView_CenterIn(&ScreenView, view);
+}
+
+///// CLPalette
+unsigned short gIntervalLast, gIntervalFirst, gIntervalSet;
+short gMacintize = 0;
+color_t black_palette[256];
+color_t last_palette[256];
+void CLPalette_Init() {
+	short i;
+	for (i = 0; i < 256; i++)
+		black_palette[i].r = black_palette[i].g = black_palette[i].b = 0;
+}
+void CLPalette_SetLastPalette(color_t *palette, short first, short count) {
+	short i;
+	for (i = first; i < first + count; i++)
+		last_palette[i] = palette[i];
+}
+void CLPalette_GetLastPalette(color_t *palette) {
+	short i;
+	for (i = 0; i < 256; i++)
+		palette[i] = last_palette[i];
+}
+void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb) {
+	palette[index].r = rgb->r;
+	palette[index].g = rgb->g;
+	palette[index].b = rgb->b;
+	palette[index].a = 0;
+}
+void CLPalette_Macintize(short macintize) {
+	gMacintize = macintize;
+}
+void CLPalette_SetInterval(unsigned short first, unsigned short last) {
+	gIntervalFirst = first;
+	gIntervalSet = 1;
+	gIntervalLast = last;
+}
+void CLPalette_DeactivateInterval() {
+	gIntervalSet = 0;
+}
+void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count) {
+	OSErr err;
+	short i;
+	if (gMacintize) {
+		palette[0].r = palette[0].g = palette[0].b = 0xFFFF;
+		palette[255].r = palette[255].g = palette[255].b = 0;
+	}
+	if (gIntervalSet) {
+		if (first < gIntervalFirst)
+			first = gIntervalFirst;
+		if (first + count > gIntervalLast)
+			count = gIntervalLast - first;
+	}
+
+	byte buffer[256 * 3];
+	for (i = 0; i < 256; i++) {
+		buffer[i * 3] = palette[i].r >> 8;
+		buffer[i * 3 + 1] = palette[i].g >> 8;
+		buffer[i * 3 + 2] = palette[i].b >> 8;
+	}
+
+	g_system->getPaletteManager()->setPalette(buffer, first, count);
+	g_system->updateScreen();
+
+	CLPalette_SetLastPalette(palette, first, count);
+}
+void CLPalette_BeBlack() {
+	CLPalette_Send2Screen(black_palette, 0, 256);
+}
+void CLPalette_BeSystem() {
+}
+
+///// CLBlitter
+static unsigned short newPaletteCount, newPaletteFirst;
+static color_t *pNewPalette;
+static unsigned short useNewPalette;
+
+void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2) {
+	int sy, dy = rect2->sy, x, w = rect1->ex - rect1->sx + 1;
+	//  debug("- Copy rect %3d:%3d-%3d:%3d -> %3d:%3d-%3d:%3d - %s",
+	//      rect1->sx, rect1->sy, rect1->ex, rect1->ey,
+	//      rect2->sx, rect2->sy, rect2->ex, rect2->ey,
+	//      (rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy) ? "ok" : "BAD");
+	assert(rect1->ex - rect1->sx == rect2->ex - rect2->sx && rect1->ey - rect1->sy == rect2->ey - rect2->sy);
+	for (sy = rect1->sy; sy <= rect1->ey; sy++, dy++) {
+		unsigned char *s = view1->p_buffer + sy * view1->pitch + rect1->sx;
+		unsigned char *d = view2->p_buffer + dy * view2->pitch + rect2->sx;
+		for (x = 0; x < w; x++)
+			*d++ = *s++;
+	}
+}
+void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count) {
+	pNewPalette = palette;
+	useNewPalette = 1;
+	newPaletteFirst = first;
+	newPaletteCount = count;
+}
+void CLBlitter_OneBlackFlash() {
+}
+void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
+                                       unsigned char *dst, short dstw, short dstp, short dsth) {
+	short x, y;
+	for (y = 0; y < srch; y++) {
+		for (x = 0; x < srcw; x++)
+			*dst++ = *src++;
+		src += srcp - srcw;
+		dst += dstp - dstw;
+	}
+}
+void CLBlitter_CopyView2ScreenCUSTOM(view_t *view) {
+	view_t *dest = &ScreenView;
+	if (!view->doubled) {
+		short srcpitch = view->pitch;
+		short dstpitch = dest->pitch;
+
+		//      this is not quite correct?
+		//      CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+		//          dest->p_buffer + dest->norm.dst_top * dstpitch + dest->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+		CLBlitter_CopyView2ViewSimpleSize(view->p_buffer + view->norm.src_top * srcpitch + view->norm.src_left, view->norm.width, srcpitch, view->norm.height,
+		                                  dest->p_buffer + (dest->norm.dst_top + view->norm.dst_top) * dstpitch + dest->norm.dst_left + view->norm.dst_left, dest->norm.width, dstpitch, dest->norm.height);
+
+	} else {
+		assert(0);
+	}
+}
+void CLBlitter_CopyView2Screen(view_t *view) {
+
+	if (useNewPalette) {
+		color_t palette[256];
+		CLPalette_GetLastPalette(palette);
+		CLPalette_Send2Screen(pNewPalette, newPaletteFirst, newPaletteCount);
+		useNewPalette = 0;
+	}
+
+	//TODO: quick hack to force screen update
+	if (view)
+		CLBlitter_CopyView2ScreenCUSTOM(view);
+
+	g_system->copyRectToScreen(ScreenView.p_buffer, ScreenView.pitch, 0, 0, ScreenView.width, ScreenView.height);
+	g_system->updateScreen();
+}
+void CLBlitter_UpdateScreen() {
+	CLBlitter_CopyView2Screen(nullptr);
+}
+void CLBlitter_FillView(view_t *view, unsigned int fill) {
+	short x, y;
+	unsigned char *d = view->p_buffer;
+	assert((fill & 0xFF) * 0x01010101 == fill);
+	for (y = 0; y < view->height; y++) {
+		for (x = 0; x < view->width; x++)
+			*d++ = fill;
+		d += view->pitch - view->width;
+	}
+}
+void CLBlitter_FillScreenView(unsigned int fill) {
+	CLBlitter_FillView(&ScreenView, fill);
+}
+
+
+///// events wrapper
+int _mouseButton;
+byte _keyState[256];
+
+void pollEvents() {
+	g_system->delayMillis(10);
+
+	Common::Event event;
+	while (g_system->getEventManager()->pollEvent(event)) {
+		// Handle keypress
+		switch (event.type) {
+		case Common::EVENT_QUIT:
+		case Common::EVENT_RTL:
+			return;
+
+		case Common::EVENT_KEYDOWN:
+			//          _keyState[(byte)toupper(event.kbd.ascii)] = true;
+			return;
+		case Common::EVENT_KEYUP:
+			//          _keyState[(byte)toupper(event.kbd.ascii)] = false;
+			return;
+		case Common::EVENT_LBUTTONDOWN:
+			_mouseButton = 1;
+			return;
+		case Common::EVENT_RBUTTONDOWN:
+			_mouseButton = 2;
+			return;
+		case Common::EVENT_LBUTTONUP:
+		case Common::EVENT_RBUTTONUP:
+			_mouseButton = 0;
+			return;
+		default:
+			break;
+		}
+	}
+}
+
+
+///// CLKeyboard
+short CLKeyboard_HasCmdDown() {
+	return 0;
+}
+void CLKeyboard_Read() {
+	pollEvents();
+}
+unsigned char CLKeyboard_GetLastASCII() {
+	return 0;
+}
+short CLKeyboard_IsScanCodeDown(short scancode) {
+	return 0;
+}
+
+///// CLMouse
+void CLMouse_Hide() {
+}
+void CLMouse_Show() {
+}
+void CLMouse_GetPosition(short *x, short *y) {
+	*x = g_system->getEventManager()->getMousePos().x;
+	*y = g_system->getEventManager()->getMousePos().y;
+}
+void CLMouse_SetPosition(short x, short y) {
+	g_system->warpMouse(x, y);
+}
+unsigned short CLMouse_IsDown() {
+	pollEvents();
+	return _mouseButton != 0;
+}
+
+///// CLFile
+void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7) {
+}
+void CLFile_SetFinderInfos(void *fs, int a4, int a5) {
+}
+void CLFile_GetFullPath(void *a3, char *a4) {
+}
+void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs) {
+	strcpy(fs->name, name);
+	fs->create = 0;
+}
+void CLFile_Create(filespec_t *fs) {
+	fs->create = 1;
+}
+void CLFile_Open(filespec_t *fs, short mode, file_t &handle) {
+	handle.open(fs->name);
+}
+void CLFile_Close(file_t &handle) {
+	handle.close();
+}
+void CLFile_SetPosition(file_t &handle, short mode, long pos) {
+	assert(mode == 1);
+	handle.seek(pos, 0);
+}
+void CLFile_Read(file_t &handle, void *buffer, long *size) {
+	handle.read(buffer, *size);
+}
+void CLFile_Write(file_t &handle, void *buffer, long *size) {
+	assert(0);
+}
+
+///// CLSound
+// base sound
+void CLSound_PrepareSample(sound_t *sound, short mode) {
+	sound->mode = mode;
+	sound->locked = 0;
+	sound->loopTimes = 0;
+	sound->reversed = 0;
+	sound->ff_32 = 0;
+	sound->volume = 255;
+}
+void CLSound_SetWantsDesigned(short designed) {
+}
+void CLSound_SetLength(sound_t *sound, int length) {
+}
+
+///// CLSoundChannel
+/// sound output device that plays queue of sounds
+soundchannel_t *CLSoundChannel_New(int arg1) {
+	short i;
+	soundchannel_t *ch = (soundchannel_t *)CLMemory_Alloc(sizeof(*ch));
+	if (!ch)
+		return 0;
+
+	ch->volumeLeft = ch->volumeRight = 255;
+	ch->numSounds = 0;
+
+	for (i = 0; i < CL_MAX_CH_SOUNDS; i++)
+		ch->sounds[i] = 0;
+
+	return ch;
+}
+void CLSoundChannel_Free(soundchannel_t *ch) {
+	CLMemory_Free(ch);
+}
+void CLSoundChannel_Stop(soundchannel_t *ch) {
+	//  g_ed->_mixer->stopHandle(ch->ch);
+}
+void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound) {
+}
+short CLSoundChannel_GetVolume(soundchannel_t *ch) {
+	return (ch->volumeLeft + ch->volumeRight) / 2;
+}
+void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeLeft = volume;
+	ch->volumeRight = volume;
+}
+void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeRight = volume;
+}
+void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume) {
+	if (volume < 0 || volume > 255)
+		return;
+	ch->volumeLeft = volume;
+}
+
+///// CLTimer
+void CLTimer_Action(void *arg) {
+	//  long& counter = *((long*)arg);
+	//  counter++;
+	TimerTicks++;
+}
+
+void CLTimer_Init() {
+	g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
+}
+
+void CLTimer_Done() {
+	g_system->getTimerManager()->removeTimerProc(CLTimer_Action);
+}
+
+///// CRYOLib
+void CRYOLib_InstallExitPatch() {
+}
+void CRYOLib_RemoveExitPatch() {
+}
+void CRYOLib_Init() {
+}
+void CRYOLib_Done() {
+}
+void CRYOLib_MinimalInit() {
+}
+void CRYOLib_ManagersInit() {
+	CLTimer_Init();
+	CLScreenView_Init();
+}
+void CRYOLib_ManagersDone() {
+	CLTimer_Done();
+}
+void CRYOLib_SetDebugMode(short enable) {
+}
+void CRYOLib_InstallEmergencyExit(void(*proc)()) {
+}
+void CRYOLib_SetupEnvironment() {
+}
+void CRYOLib_RestoreEnvironment() {
+}
+void CRYOLib_TestConfig() {
+}
+
+///// CLComputer
+short CLComputer_Has68030() {
+	return 0;
+}
+short CLComputer_Has68040() {
+	return 0;
+}
+
+///// CLDesktop
+void CLDesktop_TestOpenFileAtStartup() {
+}
+
+} // End of namespace Cryo
diff --git a/engines/cryo/cryolib.h b/engines/cryo/cryolib.h
new file mode 100644
index 0000000..9add90a
--- /dev/null
+++ b/engines/cryo/cryolib.h
@@ -0,0 +1,344 @@
+#ifndef CRYO_CRYOLIB_H
+#define CRYO_CRYOLIB_H
+
+#include "audio/mixer.h"
+
+#include "cryo/platdefs.h"
+
+namespace Cryo {
+
+#define SW16(n) ( (((n) & 0xFF) << 8) | (((n) >> 8) & 0xFF) )
+#define SW32(n) ( (((n) & 0xFF) << 24) | (((n) >> 24) & 0xFF) | (((n) & 0xFF00) << 8) | (((n) >> 8) & 0xFF00))
+#if 0
+//big-endian host
+#define LE16(n) SW16(n)
+#define LE32(n) SW32(n)
+#define BE16(n) (n)
+#define BE32(n) (n)
+#else
+//little-endian host
+#define LE16(n) (n)
+#define LE32(n) (n)
+#define BE16(n) SW16(n)
+#define BE32(n) SW32(n)
+#endif
+#define PLE16(p) ( (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
+#define PLE32(p) ( (((unsigned char*)(p))[3] << 24) | (((unsigned char*)(p))[2] << 16) | (((unsigned char*)(p))[1] << 8) | ((unsigned char*)(p))[0] )
+
+typedef void *SndChannel;
+typedef char *Handle;
+enum {
+	fsFromStart = 1
+};
+
+extern short __debug2;
+
+extern short __debug, __libError, __osError;
+
+#define CLBeginCheck    { short __oldDebug = __debug; __debug = -1;
+#define CLEndCheck      __debug = __oldDebug; }
+#define CLNoError       __libError = 0;
+
+#define CLCheckError() if(__debug && __libError){   \
+		char buffer_[260];           \
+		sprintf(buffer_, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer_));   \
+	};
+
+#define CLAssert(x) if(!(x)) {  \
+		char buffer_[260];           \
+		sprintf(buffer_, "File %s at line %d, with __libError = %d and __osError = %d", __FILE__, __LINE__, __libError, __osError);  \
+		DebugStr(c2pstr(buffer_));   \
+	};
+
+struct rect_t {
+	int sy, sx, ey, ex;
+};
+typedef struct rect_t rect_t;
+
+struct view_t {
+	unsigned char   *p_buffer;
+	int     width;
+	int     height;
+	short   pitch;
+	short   doubled;
+	short   allocated;
+	struct {
+		int     src_left;
+		int     src_top;
+		int     dst_left;
+		int     dst_top;
+		int     width;
+		int     height;
+	} norm, zoom;
+};
+typedef struct view_t view_t;
+
+struct color3_t {
+	short   r, g, b;
+};
+typedef struct color3_t color3_t;
+
+struct color_t {
+	short   a, r, g, b;
+};
+typedef struct color_t color_t;
+
+struct palette_t {
+	color_t colors[256];
+};
+typedef struct palette_t palette_t;
+
+#pragma pack(push, 1)
+struct hnmheader_t {
+	int             id;
+	char            flag1;
+	char            flag2;
+	char            reseverd;
+	char            bpp;
+	unsigned short  width;
+	unsigned short  height;
+	int             filesize;
+	int             nframe;
+	int             table_offset;
+	short           speed;
+	short           maxbuffer;
+	int             buffersize;
+	short           ff_20;
+	char            reserved2[14];
+	char            copyright[16];
+};
+typedef struct hnmheader_t hnmheader_t;
+#pragma pack(pop)
+
+struct hnm_t {
+	int             frame;
+	int             ff_4;
+	file_t         *file;
+	hnmheader_t     header;
+	unsigned char   *work_buffer[2];
+	unsigned char   *final_buffer;
+	unsigned char   *new_frame_buffer;
+	unsigned char   *old_frame_buffer;
+	unsigned char   *read_buffer;
+	unsigned char   *data_ptr;
+	color_t         palette[256];
+
+	short           can_loop;
+
+	short           ff_896;
+	short           chunk_id;
+	int             total_read;
+};
+typedef struct hnm_t hnm_t;
+
+//struct filespec_t {
+//char  puff;
+//};
+
+struct sound_t {
+	Handle  sndHandle;
+	short   headerLen;
+	long    headerOffset;
+	short   ff_A;
+
+	char    *buffer;
+	int     ff_16;
+	short   ff_1A;
+	float   rate;
+	short   sampleSize;
+	int     length;
+	short   mode;
+	volatile short  locked;
+	long    loopStart;
+	short   loopTimes;
+	short   reversed;
+	short   ff_32;
+	short   volume;
+};
+typedef struct sound_t sound_t;
+
+#define CL_MAX_SOUNDS 64
+
+struct soundgroup_t {
+	sound_t *sound[CL_MAX_SOUNDS];
+	short   numSounds;
+	short   soundIndex;
+	short   playIndex;
+	short   ff_106;
+};
+typedef struct soundgroup_t soundgroup_t;
+
+#define CL_MAX_CH_SOUNDS 10
+
+struct soundchannel_t {
+	Audio::SoundHandle ch;
+	int     xx;
+
+	short   volumeLeft;
+	short   volumeRight;
+	short   numSounds;
+
+	sound_t *sounds[CL_MAX_CH_SOUNDS];
+
+	short   ff_536;
+};
+typedef struct soundchannel_t soundchannel_t;
+
+extern volatile long TimerTicks;
+extern view_t ScreenView;
+
+
+soundgroup_t *CLSoundGroup_New(short numSounds, short arg4, short sampleSize, float rate, short mode);
+void CLSoundGroup_Free(soundgroup_t *sg);
+void CLSoundGroup_Reverse16All(soundgroup_t *sg);
+void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg);
+short CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, short isSigned);
+short CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, short isSigned);
+void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch);
+
+sound_t *CLSoundRaw_New(short arg1, float rate, short sampleSize, short mode);
+void CLSoundRaw_Free(sound_t *sound);
+void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length);
+
+char *c2pstr(char *s);
+void DebugStr(char *s);
+void *CLMemory_Alloc(int size);
+void CLMemory_Free(void *ptr);
+short MemError();
+void SysBeep(int x);
+long TickCount();
+void FlushEvents(short arg1, short arg2);
+
+void CLBlitter_CopyViewRect(view_t *view1, view_t *view2, rect_t *rect1, rect_t *rect2);
+void CLBlitter_Send2ScreenNextCopy(color_t *palette, unsigned short first, unsigned short count);
+void CLBlitter_OneBlackFlash();
+void CLBlitter_CopyView2ViewSimpleSize(unsigned char *src, short srcw, short srcp, short srch,
+                                       unsigned char *dst, short dstw, short dstp, short dsth);
+void CLBlitter_CopyView2ScreenCUSTOM(view_t *view);
+void CLBlitter_CopyView2Screen(view_t *view);
+void CLBlitter_UpdateScreen();
+void CLBlitter_FillView(view_t *view, unsigned int fill);
+void CLBlitter_FillScreenView(unsigned int fill);
+
+void CLPalette_Init();
+void CLPalette_SetLastPalette(color_t *palette, short first, short count);
+void CLPalette_GetLastPalette(color_t *palette);
+void CLPalette_SetRGBColor(color_t *palette, unsigned short index, color3_t *rgb);
+void CLPalette_Macintize(short macintize);
+void CLPalette_SetInterval(unsigned short first, unsigned short last);
+void CLPalette_DeactivateInterval();
+void CLPalette_Send2Screen(struct color_t *palette, unsigned short first, unsigned short count);
+void CLPalette_BeBlack();
+void CLPalette_BeSystem();
+
+void CLFile_SetFilter(int a3, int a4, int a5, int a6, int a7);
+void CLFile_SetFinderInfos(void *fs, int a4, int a5);
+void CLFile_GetFullPath(void *a3, char *a4);
+void CLFile_MakeStruct(int a3, int a4, char *name, filespec_t *fs);
+void CLFile_Create(filespec_t *fs);
+void CLFile_Open(filespec_t *fs, short mode, file_t &handle);
+void CLFile_Close(file_t &handle);
+void CLFile_SetPosition(file_t &handle, short mode, long pos);
+void CLFile_Read(file_t &handle, void *buffer, long *size);
+void CLFile_Write(file_t &handle, void *buffer, long *size);
+
+void CLSound_PrepareSample(sound_t *sound, short mode);
+void CLSound_SetWantsDesigned(short designed);
+void CLSound_SetLength(sound_t *sound, int length);
+
+soundchannel_t *CLSoundChannel_New(int arg1);
+void CLSoundChannel_Free(soundchannel_t *ch);
+void CLSoundChannel_Stop(soundchannel_t *ch);
+void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound);
+short CLSoundChannel_GetVolume(soundchannel_t *ch);
+void CLSoundChannel_SetVolume(soundchannel_t *ch, short volume);
+void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, short volume);
+void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, short volume);
+
+short CLKeyboard_HasCmdDown();
+void CLKeyboard_Read();
+unsigned char CLKeyboard_GetLastASCII();
+short CLKeyboard_IsScanCodeDown(short scancode);
+
+void CLMouse_Hide();
+void CLMouse_Show();
+void CLMouse_GetPosition(short *x, short *y);
+void CLMouse_SetPosition(short x, short y);
+unsigned short CLMouse_IsDown();
+
+void CLView_SetSrcZoomValues(view_t *view, int x, int y);
+void CLView_SetDisplayZoomValues(view_t *view, int w, int h);
+void CLView_Free(view_t *view);
+void CLView_InitDatas(view_t *view, int w, int h, void *buffer);
+view_t *CLView_New(int w, int h);
+void CLView_CenterIn(view_t *parent, view_t *child);
+
+void CLScreenView_Init();
+void CLScreenView_CenterIn(view_t *view);
+
+void CRYOLib_InstallExitPatch();
+void CRYOLib_RemoveExitPatch();
+void CRYOLib_Init();
+void CRYOLib_Done();
+void CRYOLib_MinimalInit();
+void CRYOLib_ManagersInit();
+void CRYOLib_ManagersDone();
+void CRYOLib_SetDebugMode(short enable);
+void CRYOLib_InstallEmergencyExit(void(*proc)());
+void CRYOLib_SetupEnvironment();
+void CRYOLib_RestoreEnvironment();
+void CRYOLib_TestConfig();
+
+short CLComputer_Has68030();
+short CLComputer_Has68040();
+void CLDesktop_TestOpenFileAtStartup();
+
+
+void CLHNM_DecompLempelZiv(unsigned char *buffer, unsigned char *output);
+void CLHNM_DecompUBA(unsigned char *output, unsigned char *curr_buffer, unsigned char *prev_buffer,
+                     unsigned char *input, int width, char flags);
+void CLHNM_Init();
+void CLHNM_Done();
+void CLHNM_SetupTimer(float rate);
+void CLHNM_WaitLoop(hnm_t *hnm);
+void CLHNM_SetupSound(short numSounds, short arg4, short sampleSize, float rate, short mode);
+void CLHNM_SetupSoundADPCM(short numSounds, short arg4, short sampleSize, float rate, short mode);
+void CLHNM_CloseSound();
+void CLHNM_SetForceZero2Black(short forceblack);
+hnm_t *CLHNM_New(int preload_size);
+void CLHNM_Dispose(hnm_t *hnm);
+void CLHNM_SetFile(hnm_t *hnm, file_t *file);
+void CLHNM_SetFinalBuffer(hnm_t *hnm, unsigned char *buffer);
+void CLHNM_AllocMemory(hnm_t *hnm);
+void CLHNM_DeallocMemory(hnm_t *hnm);
+void CLHNM_Read(hnm_t *hnm, int size);
+void CLHNM_GiveTime(hnm_t *hnm);
+void CLHNM_CanLoop(hnm_t *hnm, short can_loop);
+void CLHNM_SelectBuffers(hnm_t *hnm);
+void CLHNM_ChangePalette(hnm_t *hnm);
+void CLHNM_Desentrelace(hnm_t *hnm);
+void CLHNM_FlushPreloadBuffer(hnm_t *hnm);
+soundchannel_t *CLHNM_GetSoundChannel();
+void CLHNM_TryRead(hnm_t *hnm, int size);
+void CLHNM_ResetInternalTimer();
+void CLHNM_Reset(hnm_t *hnm);
+short CLHNM_LoadFrame(hnm_t *hnm);
+void CLHNM_WantsSound(short sound);
+void CLHNM_LoadDecompTable(short *buffer);
+void CLHNM_DecompADPCM(unsigned char *buffer, short *output, int size);
+void CLHNM_SoundInADPCM(short is_adpcm);
+void CLHNM_SoundMono(short is_mono);
+short CLHNM_NextElement(hnm_t *hnm);
+void CLHNM_ReadHeader(hnm_t *hnm);
+short CLHNM_GetVersion(hnm_t *hnm);
+int CLHNM_GetFrameNum(hnm_t *hnm);
+void CLHNM_DeactivatePreloadBuffer();
+void CLHNM_Prepare2Read(hnm_t *hnm, int mode);
+void CLHNM_SetPosIntoFile(hnm_t *hnm, long pos);
+void CLHNM_Desentrelace320(unsigned char *frame_buffer, unsigned char *final_buffer, unsigned short height);
+
+
+} // End of namespace Cryo
+
+#endif
diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h
index 3400c23..ce5857a 100644
--- a/engines/cryo/defs.h
+++ b/engines/cryo/defs.h
@@ -1,6 +1,9 @@
-#include <stddef.h>
-#include <stdlib.h>
-#include "cryolib.h"
+#include "cryo/cryolib.h"
+
+#ifndef CRYO_DEFS_H
+#define CRYO_DEFS_H
+
+namespace Cryo {
 
 #define GetElem(array, idx) \
 	( (char*)(array) + PLE16((idx) * 2 + (char*)(array)) )
@@ -309,9 +312,11 @@ struct perso_t {
 };
 typedef struct perso_t perso_t;
 
+class EdenGame;
+
 struct phase_t {
 	short           id;
-	void (EdenGameImpl::*disp)();
+	void (EdenGame::*disp)();
 };
 typedef struct phase_t phase_t;
 
@@ -763,24 +768,7 @@ typedef struct cita_t cita_t;
 
 /////////////// vars
 
-suiveur_t suiveurs_list[] = {
-//            char,                 X,  sx, sy,  ex,  ey,bank,
-	{ PersonId::pidGregor,          5, 211,  9, 320, 176, 228,   0,  0 },
-	{ PersonId::pidEloi,            4, 162, 47, 223, 176, 228, 112, 78 },
-	{ PersonId::pidDina,            3,  55,  0, 172, 176, 228,  90, 16 },
-	{ PersonId::pidChongOfChamaar,  4,   0,  5, 114, 176, 229,   0, 16 },
-	{ PersonId::pidKommalaOfKoto,   3,   0, 15, 102, 176, 229,   0, 16 },
-	{ PersonId::pidUlanOfUlele,     1,   0,  0, 129, 176, 230,   0, 16 },
-	{ PersonId::pidCabukaOfCantura, 2,   0,  0, 142, 176, 230,   0, 16 },
-	{ PersonId::pidFuggOfTamara,    0,   0, 17, 102, 176, 230,   0, 16 },
-	{ PersonId::pidJabber,          2,   0,  6, 134, 176, 228,   0, 16 },
-	{ PersonId::pidShazia,          1,  90, 17, 170, 176, 228,  50, 22 },
-	{ PersonId::pidThugg,           0, 489,  8, 640, 176, 228, 160, 24 },
-	{ PersonId::pidMungo,           5, 361,  0, 517, 176, 229,   0, 16 },
-	{ PersonId::pidMonk,            0, 419, 22, 569, 176, 229, 100, 30 },
-	{ PersonId::pidEve,             1, 300, 28, 428, 176, 229,   0, 38 },
-	{ -1,                          -1,  -1, -1,  -1,  -1,  -1,  -1, -1 }
-};
+extern suiveur_t suiveurs_list[];
 
 
 /*
@@ -797,580 +785,40 @@ enum {
 	LAB_W
 };
 
-#define LAB(toCrypt, toThrone)  \
-	(((LAB_##toCrypt) << 4) | (LAB_##toThrone))
-
-unsigned char kLabyrinthPath[] = {
-// each nibble tells wich direction to choose to exit the labyrinth
-	0x11, 0x11, 0x11, 0x22, 0x33, 0x55, 0x25, 0x44, 0x25, 0x11, 0x11, 0x11,
-	0x11, 0x35, 0x55, 0x45, 0x45, 0x44, 0x44, 0x34, 0x44, 0x34, 0x32, 0x52,
-	0x33, 0x23, 0x24, 0x44, 0x24, 0x22, 0x54, 0x22, 0x54, 0x54, 0x44, 0x22,
-	0x22, 0x42, 0x45, 0x22, 0x42, 0x45, 0x35, 0x11, 0x44, 0x34, 0x52, 0x11,
-	0x44, 0x32, 0x55, 0x11, 0x11, 0x33, 0x11, 0x11, 0x53, 0x11, 0x11, 0x53,
-	0x54, 0x24, 0x11, 0x22, 0x25, 0x33, 0x53, 0x54, 0x23, 0x44
-};
-
-#undef LAB
+extern unsigned char kLabyrinthPath[];
 
-char kDinoSpeedForCitaLevel[16] = { 1, 2, 3, 4, 4, 5, 6, 7, 8, 9 };
+extern char kDinoSpeedForCitaLevel[16];
 
-char kTabletView[] = {          //TODO: make as struct?
-	// opposite tablet id, video id
-	Objects::obUnused10, 83,
-	Objects::obUnused10, 84,
-	Objects::obTablet4, 85,
-	Objects::obTablet3, 86,
-	Objects::obTablet6, 87,
-	Objects::obTablet5, 85
-};
+extern char kTabletView[];
 
 // special character backgrounds for specific rooms
-char kPersoRoomBankTable[] = {
-	// first entry is default bank, then pairs of [roomNum, bankNum], terminated by -1
-	0,  3, 33, -1,
-	21, 17, 35, -1,
-	0,  2, 36, -1,
-	22,  9, 38,  3, 39, -1,
-	23,  8, 40, -1,
-	0,  3, 41,  7, 42, -1,
-	25, -1,
-	27, 17, 45, -1,
-	28, 26, 46, -1,
-	29, 51, 48, -1,
-	30, 53, 49, -1,
-	0, 27, 50, -1,
-	32, 17, 51, -1,
-	52,  2, 52, -1,
-	-3,  3, -3, -1,
-	31, -1,
-	24,  6, 43, -1,
-	47, -1,
-	0,  2, 64, -1,
-	54,  3, 54, -1,
-	27, -1,
-	26, 17, 45, -1
-};
+extern char kPersoRoomBankTable[];
 
 // area transition descriptors
-goto_t gotos[] = {
-// area, oldarea, vid, time, valleyVid
-	{  0,  1,   0,  2,  20 },
-	{  0,  1, 162,  3, 168 },
-	{  0,  2,   0,  2,  21 },
-	{  0,  6,   0,  3, 108 },
-	{  0,  9, 151,  3,   0 },
-	{  0,  7, 106,  2, 101 },
-	{  0, 10,  79,  3, 102 },
-	{  0, 12,   0,  3,   0 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  1,  3,  58,  2, 104 },
-	{  1,  4, 100,  4, 104 },
-	{  1,  5, 107,  6, 104 },
-	{  1,  6, 155,  8, 104 },
-	{  1,  7, 165,  6, 104 },
-	{  1,  8, 169,  6, 104 },
-	{  1, 10, 111,  2, 104 },
-	{  1, 11, 164,  4, 104 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  1,  3, 161,  3, 102 },
-	{  1,  4, 163,  6, 102 },
-	{  1,  5, 157,  9, 102 },
-	{  1,  9, 160,  9, 102 },
-	{  1, 10,  79,  3, 102 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  1,  3,   0,  3, 153 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  3,  1, 154,  2, 103 },
-	{  3,  4, 100,  2, 103 },
-	{  3,  5, 107,  4, 103 },
-	{  3,  6, 155,  6, 103 },
-	{  3,  7, 165,  8, 103 },
-	{  3,  8, 169,  6, 103 },
-	{  3, 10, 111,  4, 103 },
-	{  3, 11, 164,  6, 103 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  3,  1, 162,  3,  22 },
-	{  3,  4, 163,  6,  22 },
-	{  3,  5, 157,  9,  22 },
-	{  3,  9, 160,  9,  22 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  3,  1,   0,  3, 166 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  4,  1, 154,  4,  51 },
-	{  4,  3,  58,  2,  51 },
-	{  4,  5, 107,  2,  51 },
-	{  4,  6, 155,  4,  51 },
-	{  4,  7, 165,  6,  51 },
-	{  4,  8, 169,  8,  51 },
-	{  4, 10, 111,  6,  51 },
-	{  4, 11, 164,  8,  51 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  4,  1, 162,  3, 109 },
-	{  4,  3, 161,  6, 109 },
-	{  4,  5, 157,  9, 109 },
-	{  4,  9, 160,  9, 109 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  5,  1, 154,  6,  33 },
-	{  5,  3,  58,  4,  33 },
-	{  5,  4, 100,  2,  33 },
-	{  5,  6, 155,  2,  33 },
-	{  5,  7, 165,  4,  33 },
-	{  5,  8, 169,  8,  33 },
-	{  5, 10, 111,  8,  33 },
-	{  5, 11, 164,  8,  33 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  5,  1, 162,  3,  99 },
-	{  5,  3, 161,  6,  99 },
-	{  5,  4, 163,  9,  99 },
-	{  5,  9, 160,  9,  99 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  9,  1, 162,  3, 167 },
-	{  9,  3, 161,  6, 167 },
-	{  9,  4, 163,  9, 167 },
-	{  9,  5, 157,  9, 167 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  6,  1, 154,  8, 105 },
-	{  6,  3,  58,  6, 105 },
-	{  6,  4, 100,  4, 105 },
-	{  6,  5, 107,  2, 105 },
-	{  6,  7, 165,  2, 105 },
-	{  6,  8, 169, 10, 105 },
-	{  6, 10, 111,  6, 105 },
-	{  6, 11, 164,  8, 105 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  7,  1, 154,  4, 158 },
-	{  7,  3,  58,  6, 158 },
-	{  7,  4, 100,  6, 158 },
-	{  7,  5, 107,  4, 158 },
-	{  7,  6, 155,  2, 158 },
-	{  7,  8, 169,  8, 158 },
-	{  7, 10, 111,  4, 158 },
-	{  7, 11, 164,  6, 158 },
-	{ -1, -1,  -1, -1,  -1 },
-	{  8,  1, 154,  2, 159 },
-	{  8,  3,  58,  4, 159 },
-	{  8,  4, 100,  6, 159 },
-	{  8,  5, 107,  8, 159 },
-	{  8,  6, 155, 10, 159 },
-	{  8,  7, 165,  8, 159 },
-	{  8, 10, 111,  6, 159 },
-	{  8, 11, 164,  4, 159 },
-	{ -1, -1,  -1, -1,  -1 },
-	{ 10,  1, 154,  2,  77 },
-	{ 10,  3,  58,  4,  77 },
-	{ 10,  4, 100,  6,  77 },
-	{ 10,  5, 107,  8,  77 },
-	{ 10,  6, 155,  6,  77 },
-	{ 10,  7, 165,  4,  77 },
-	{ 10,  8, 169,  6,  77 },
-	{ 10, 11, 164,  4,  77 },
-	{ -1, -1,  -1, -1,  -1 },
-	{ 11,  1, 154,  2,  80 },
-	{ 11,  3,  58,  4,  80 },
-	{ 11,  4, 100,  6,  80 },
-	{ 11,  5, 107,  8,  80 },
-	{ 11,  6, 155,  8,  80 },
-	{ 11,  7, 165,  6,  80 },
-	{ 11,  8, 169,  2,  80 },
-	{ 11, 10, 111,  4,  80 },
-	{ -1, -1,  -1, -1,  -1 },
-	{ 12,  1, 154,  8,  56 },
-	{ 12,  3,  58,  4,  56 },
-	{ 12,  4, 100,  4,  56 },
-	{ 12,  5, 107,  6,  56 },
-	{ 12,  6, 155,  8,  56 },
-	{ 12,  7, 165, 10,  56 },
-	{ 12,  8, 169,  4,  56 },
-	{ 12, 10, 111, 10,  56 },
-	{ 12, 11, 164,  6,  56 },
-	{ -1, -1,  -1, -1,  -1 }
-};
-
-#define SUB_LINE(start, end) \
-	(start), (end) | 0x8000
-
-short tab_2D24C[] = {
-	SUB_LINE(68, 120),
-	123, 32964,
-	199, 33042,
-	276, 33138,
-	799, 33653,
-	888, 33708,
-	947, 33768,
-	1319, 34146,
-	1380, 34208,
-	1854, 34666,
-	1900, 34728,
-	2116, 34952,
-	2186, 35020,
-	2254, 35088,
-	3038, 35862,
-	3096, 35928,
-	-1
-};
-
-short tab_2D28E[] = {
-	99, 32923,
-	157, 33024,
-	-1
-};
-
-short tab_2D298[] = {
-	106, 32941,
-	175, 33012,
-	246, 33118,
-	352, 33235,
-	-1
-};
-
-short tab_2D2AA[] = {
-	126, 32944,
-	178, 33035,
-	269, 33110,
-	344, 33166,
-	400, 33226,
-	460, 33326,
-	-1
-};
-
-short tab_2D2C4[] = {
-	101, 32981,
-	215, 33121,
-	355, 33223,
-	457, 33286,
-	520, 33428,
-	662, 33536,
-	-1
-};
-#undef SUB_LINE
-
-object_t objects[] = {
-	//id,fl,loc,masklow,maskhi,ct
-	{  1, 0,  3,      1,     0, 0},     // Eve's Way Stone
-	{  2, 0,  3,      2,     0, 0},     // Thau's Seashell
-	{  3, 0,  3,      4,     0, 0},     // Talisman of bravery
-	{  4, 0,  3,      8,     0, 0},     // An old tooth. Very old! Whoever lost it most certainly has no further use for it!
-	{  5, 0,  0,   0x10,     0, 0},     // Prism
-	{  6, 0,  3,      0,     0, 0},     // Flute
-	{  7, 0,  3, 0x4000,     0, 0},     // Apple
-	{  8, 0,  4, 0x1000,     0, 0},     // Egg of Destiny
-	{  9, 0,  3,  0x800,     0, 0},     // Root
-	{ 10, 0,  3,      0,     0, 0},     // ???
-	{ 11, 0,  6,      0,     0, 0},     // Mushroom
-	{ 12, 0, 13,      0,     0, 0},     // Poisonous Mushroom
-	{ 13, 0,  2,  0x400,     0, 0},     // Graa's Knife
-	{ 14, 0, 22,      0,     0, 0},     // Empty Nest
-	{ 15, 0, 26,      0,     0, 0},     // Full Nest
-	{ 16, 0, 33,   0x20,     0, 0},     // Gold
-	{ 17, 0,  3,      0,     0, 0},     // Sign of Shadow Mistress  (moon stone)
-	{ 18, 0,  3,      0,     0, 0},     // Sign of Mother of all    (bag of soil)
-	{ 19, 0, 40,      0,     0, 0},     // Sign of the life-giving  (sun star)
-	{ 20, 0, 20,  0x200,     0, 0},     // King's Horn
-	{ 21, 0,  3,      0,     0, 0},     // Golden Sword of Mashaar
-	// Masks
-	{ 22, 0,  3,   0x40,     0, 0},     // Mask of Death
-	{ 23, 0,  3,   0x80,     0, 0},     // Mask of Bonding
-	{ 24, 0,  3,  0x100,     0, 0},     // Mask of Birth
-	// Objects of power
-	{ 25, 0,  3,      0,     1, 0},     // Eye in the Storm
-	{ 26, 0,  3,      0,     2, 0},     // Sky Hammer
-	{ 27, 0,  3,      0,     4, 0},     // Fire in the Clouds
-	{ 28, 0,  3,      0,     8, 0},     // Within and Without
-	{ 29, 0,  3,      0,  0x10, 0},     // Eye in the Cyclone
-	{ 30, 0,  3,      0,  0x20, 0},     // River that Winds
-	// Musical instruments
-	{ 31, 0,  3,      0,  0x40, 0},     // Trumpet
-	{ 32, 0,  3,      0,  0x80, 0},     // -- unused (but still has a dialog line)
-	{ 33, 0,  3,      0, 0x100, 0},     // Drum
-	{ 34, 0,  3,      0, 0x200, 0},     // -- unused (but still has a dialog line)
-	{ 35, 0,  3,      0, 0x400, 0},     // -- unused (but still has a dialog line)
-	{ 36, 0,  3,      0, 0x800, 0},     // Ring
-	// Tablets
-	{ 37, 0,  3,      0,     0, 0},     // Tablet #1 (Mo)
-	{ 38, 0, 42, 0x2000,     0, 0},     // Tablet #2 (Morkus' Lair)
-	{ 39, 0,  3,      0,     0, 0},     // Tablet #3 (White Arch?)
-	{ 40, 0,  3,      0,     0, 0},     // Tablet #4
-	{ 41, 0,  3,      0,     0, 0},     // Tablet #5
-	{ 42, 0,  3, 0x8000,     0, 0}      // Tablet #6 (Castra)
-};
-
-short kObjectLocations[100] = {
-	0x112, -1,
-	0x202, -1,
-	0x120, -1,
-	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
-	0x340, 0x44B, 0x548, 0x640, 0x717, 0x830, -1,
-	0, -1,
-	0x344, 0x53A, 0x831, -1,
-	0x331, 0x420, 0x54B, 0x637, 0x716, 0x840, -1,
-	0x834A, 0x8430, 0x8531, 0x644, 0x745, 0x838, -1,
-	0x510, -1,
-	0xC04, -1,
-	-1
-};
-
-perso_t kPersons[] = {
-	// room, aid, party mask,                            id,                                            flags,  X,bank,X, X,sprId,sprX,speed, X
-	{ 0x103, 230, PersonMask::pmGregor, PersonId::pidGregor            ,                                                0,  0,  1, 0, 0,  0,   0, 0, 0 },
-	{ 0x116, 231, PersonMask::pmDina  , PersonId::pidDina              ,                                                0,  4,  2, 0, 0,  3,   9, 0, 0 },
-	{ 0x202, 232, PersonMask::pmTau   , PersonId::pidTau               ,                                                0,  8,  3, 0, 0,  0,   0, 0, 0 },
-	{ 0x109, 233, PersonMask::pmMonk  , PersonId::pidMonk              ,                                                0, 12,  4, 0, 0,  6,  52, 0, 0 },
-	{ 0x108, 234, PersonMask::pmJabber, PersonId::pidJabber            ,                                                0, 18,  5, 0, 0,  2,   0, 0, 0 },
-	{ 0x103, 235, PersonMask::pmEloi  , PersonId::pidEloi              ,                                                0, 22,  6, 0, 0,  4,  20, 0, 0 },
-	{ 0x301, 236, PersonMask::pmMungo , PersonId::pidMungo             ,                                                0, 28,  8, 0, 0, 11,  45, 0, 0 },
-	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 30, 10, 0, 0,  7,  35, 0, 0 },
-	{ 0x81A, 238, PersonMask::pmShazia, PersonId::pidShazia            ,                                                0, 34, 11, 0, 0,  1,  11, 0, 0 },
-	{ 0x330, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
-	{ 0x41B, 239, PersonMask::pmLeader, PersonId::pidUlanOfUlele       ,                                                0, 46, 15, 0, 0, 13,   0, 0, 0 },
-	{ 0x53B, 239, PersonMask::pmLeader, PersonId::pidKommalaOfKoto     ,                                                0, 42, 14, 0, 0,  9,   0, 0, 0 },
-	{ 0x711, 239, PersonMask::pmLeader, PersonId::pidCabukaOfCantura   ,                                                0, 50, 16, 0, 0, 14,   0, 0, 0 },
-	{ 0xA02, 239, PersonMask::pmLeader, PersonId::pidMarindaOfEmbalmers,                                                0, 54, 17, 0, 0,  0,   0, 0, 0 },
-	{ 0x628, 239, PersonMask::pmLeader, PersonId::pidFuggOfTamara      ,                                                0, 62, 18, 0, 0, 12,   0, 0, 0 },
-	{ 0x801, 239, PersonMask::pmLeader, PersonId::pidChongOfChamaar    ,                                                0, 38, 13, 0, 0, 10,   0, 0, 0 },
-	{ 0x41B,  10, PersonMask::pmQuest , PersonId::pidUlanOfUlele       , PersonFlags::pfType2                            , 46, 15, 0, 0, 13,   0, 0, 0 },
-	{ 0x711,  11, PersonMask::pmQuest , PersonId::pidCabukaOfCantura   , PersonFlags::pfType2                            , 50, 16, 0, 0, 14,   0, 0, 0 },
-	{ 0x106, 240, PersonMask::pmThugg , PersonId::pidThugg             ,                                                0, 64,  7, 0, 0,  0,  61, 0, 0 },
-	{     0,  13,                    0, PersonId::pidNarrator          ,                                                0, 68, 12, 0, 0,  0,   0, 0, 0 },
-	{ 0x902, 241, PersonMask::pmQuest , PersonId::pidNarrim            ,                                                0, 70, 19, 0, 0,  0,   0, 0, 0 },
-	{ 0xC03, 244, PersonMask::pmMorkus, PersonId::pidMorkus            ,                                                0, 74, 20, 0, 0,  0,   0, 0, 0 },
-	// dinos in each valley
-	{ 0x332, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x329, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x33B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x317, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x320, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType12                           ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x349, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x429, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x43B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x422, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x432, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x522, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x534, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x515, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x533, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x622, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x630, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x643, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x63A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x737, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x739, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x74A, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftVelociraptor,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x726, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0x842, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pfType8        ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x822, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftTriceraptor ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x828, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pftVelociraptor                    ,  0,  0, 0, 0,  0,   0, 1, 0 },
-	{ 0x84B, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pf80 | PersonFlags::pftMosasaurus  ,  0,  0, 0, 0,  0,   0, 0, 0 },
-
-	{ 0xB03, 242, PersonMask::pmDino  , PersonId::pidDinosaur          , PersonFlags::pfType8                            , 58, 252, 0, 0,  0,   0, 0, 0 },
-	// enemy dinos
-	{ 0x311, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x410, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x51B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x618, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x71B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{ 0x81B, 243, PersonMask::pmEnemy , PersonId::pidEnemy             , PersonFlags::pf80 | PersonFlags::pftTyrann      ,  0,  0, 0, 0,  0,   0, 0, 0 },
-	{    -1,  -1,                   -1,                              -1,                                               -1, -1, -1, -1, -1, -1,  -1, -1, -1 },
-	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 80,  9, 0, 0,  8,  35, 0, 0 },
-	{ 0x628, 237, PersonMask::pmEve   , PersonId::pidEve               ,                                                0, 78, 10, 0, 0,  7,  35, 0, 0 }
-};
-
-cita_t cita_list[] = {
-	{
-		1,
-		{
-			163, 182,   0, 0,
-			124, 147, 193, 0,
-			0,   0,   0, 0,
-			0,   0,   0, 0
-		}
-	},
-	{
-		48,
-		{
-			285, 286,   0, 0,
-			287, 288, 284, 0,
-			114, 115,   0, 0,
-			116, 117, 113, 0
-		}
-	},
-	{
-		63,
-		{
-			290, 291,   0, 0,
-			292, 293, 289, 0,
-			119, 120,   0, 0,
-			121, 122, 118, 0
-		}
-	},
-	{
-		95,
-		{
-			295, 296,   0, 0,
-			297, 298, 294, 0,
-			124, 125,   0, 0,
-			126, 127, 123, 0
-		}
-	},
-	{
-		127,
-		{
-			300, 301,   0, 0,
-			302, 303, 299, 0,
-			129, 130,   0, 0,
-			131, 132, 128, 0
-		}
-	},
-	{
-		159,
-		{
-			305, 306,   0, 0,
-			307, 308, 304, 0,
-			134, 135,   0, 0,
-			136, 137, 133, 0
-		}
-	},
-	{
-		255,
-		{
-			310, 311,   0, 0,
-			312, 313, 309, 0,
-			139, 140,   0, 0,
-			141, 142, 138, 0
-		}
-	}
-};
-
-
-short tab_2CB16[] = { 2075, 2080, 2119, -1};
-
-char tab_2CB1E[8][4] = {
-	{ 0x10, 0x81,    1, 0x90},
-	{ 0x90,    1, 0x81, 0x10},
-	{    1, 0x90, 0x10, 0x81},
-	{    1, 0x10, 0x90, 0x81},
-	{    1, 0x90, 0x10, 0x81},
-	{ 0x81, 0x10, 0x90,    1},
-	{ 0x81, 0x10, 0x90,    1},
-	{ 0x81, 0x90,    1, 0x10}
-};
+extern goto_t gotos[];
+extern short tab_2D24C[];
+extern short tab_2D28E[];
+extern short tab_2D298[];
+extern short tab_2D2AA[];
+extern short tab_2D2C4[];
+extern object_t objects[];
+extern short kObjectLocations[100];
+extern perso_t kPersons[];
+extern cita_t cita_list[];
+extern short tab_2CB16[];
+extern char tab_2CB1E[8][4];
 
 struct prect_t {
 	short   sx, sy, ex, ey;
 };
 typedef struct prect_t prect_t;
 
-prect_t perso_rects[] = {   //TODO: just an array of shorts?
-	{  93,  69, 223, 176},
-	{ 102,  86, 162, 126},
-	{  88, 103, 168, 163},
-	{ 116,  66, 192, 176},
-	{ 129,  92, 202, 153},
-	{  60,  95, 160, 176},
-	{ 155,  97, 230, 145},
-	{ 100,  77, 156, 145},
-	{ 110,  78, 170, 156},
-	{  84,  76, 166, 162},
-	{  57,  77, 125, 114},
-	{  93,  69, 223, 175},
-	{  93,  69, 223, 176},
-	{  93,  69, 223, 176},
-	{ 154,  54, 245, 138},
-	{ 200,  50, 261, 116},
-	{  70,  84, 162, 176},
-	{ 125, 101, 222, 172},
-	{ 188,  83, 251, 158}
-};
-
-unsigned char tab_persxx[][5] = {   //TODO: struc?
-	{  8, 15, 23, 25, -1},
-	{  0,  9, -1        },
-	{  0,  9, -1        },
-	{  0,  9, -1        },
-	{  0, 13, -1        },
-	{ 16, 21, -1        },
-	{ 11, 20, -1        },
-	{  0, 12, -1        },
-	{  0,  9, -1        },
-	{  0,  9, -1        },
-	{  5, 13, -1        },
-	{ -1                },
-	{  0,  8, -1        },
-	{ -1                },
-	{  0,  7, -1        },
-	{  0,  8, -1        },
-	{  8, 12, -1        },
-	{  0,  5, -1        },
-	{  0,  4, -1        },
-	{ -1                }
-};
-
-area_t kAreasTable[] = {
-	{ Areas::arMo           , AreaType::atCitadel,                           0,   0, 0,  1},
-	{ Areas::arTausCave     , AreaType::atCave   ,                           0, 112, 0,  2},
-	{ Areas::arChamaar      , AreaType::atValley ,                           0, 133, 0,  3},
-	{ Areas::arUluru        , AreaType::atValley ,                           0, 187, 0,  4},
-	{ Areas::arKoto         , AreaType::atValley , AreaFlags::HasVelociraptors, 236, 0,  5},
-	{ Areas::arTamara       , AreaType::atValley ,                           0, 288, 0,  6},
-	{ Areas::arCantura      , AreaType::atValley ,                           0, 334, 0,  7},
-	{ Areas::arShandovra    , AreaType::atValley ,                           0, 371, 0,  8},
-	{ Areas::arNarimsCave   , AreaType::atCave   ,                           0, 115, 0,  9},
-	{ Areas::arEmbalmersCave, AreaType::atCave   ,                           0, 118, 0, 10},
-	{ Areas::arWhiteArch    , AreaType::atCave   ,                           0, 122, 0, 11},
-	{ Areas::arMoorkusLair  , AreaType::atCave   ,                           0, 127, 0, 12}
-};
-
-short tab_2CEF0[64] = {
-	25, 257,  0,   0, 37, 258, 38, 259,  0,   0, 24, 260, 0, 0, 0, 0,
-	0,   0, 53, 265,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
-	39, 261,  0,   0, 40, 262, 62, 263,  0,   0, 63, 264, 0, 0, 0, 0,
-	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0
-};
-
-short tab_2CF70[64] = {
-	65, 266,  0,   0, 66, 267, 67, 268,  0,   0, 68, 269, 0, 0, 0, 0,
-	0,   0, 73, 274,  0,   0,  0,   0,  0,   0,  0,   0, 0, 0, 0, 0,
-	69, 270,  0,   0, 70, 271, 71, 272,  0,   0, 72, 273, 0, 0, 0, 0,
-	18, 275,  0,   0, 35, 254, 36, 255, 19, 318, 23, 256, 0, 0, 0, 0,
-};
-
-short kActionCursors[299] = {
-	3, 1, 2, 4, 5, 5, 5, 0, 5, 5,
-	5, 5, 5, 3, 2, 5, 5, 5, 3, 2,
-	4, 5, 7, 7, 4, 5, 5, 0, 0, 0,
-	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-	5, 5, 0, 0, 0, 0, 5, 5, 5, 5,
-	5, 5, 5, 5, 5, 5, 5, 5, 0, 0,
-	0, 0, 5, 5, 5, 5, 5, 5, 5, 5,
-	5, 5, 5, 5, 0, 0, 0, 0, 5, 5,
-	5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-	6, 6, 6, 6, 6, 6, 6, 0, 5, 6,
-	6, 1, 6, 6, 0, 0, 6, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-	8, 8, 8, 8, 8, 8, 0, 0, 6, 6,
-	53, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
+extern prect_t perso_rects[];
+extern unsigned char tab_persxx[][5];
+extern area_t kAreasTable[];
+extern short tab_2CEF0[64];
+extern short tab_2CF70[64];
+extern short kActionCursors[299];
 
 struct cubeface_t {
 	int             tri;
@@ -1391,73 +839,16 @@ struct cube_t {
 };
 typedef struct cube_t cube_t;
 
-float flt_2DF7C = -3400;
-float flt_2DF80 = -3400;
-float flt_2DF84 =   200;
+extern float flt_2DF7C;
+extern float flt_2DF80;
+extern float flt_2DF84;
 
 // Cube faces to texture coords mapping
 // each entry is num_polys(6) * num_faces_per_poly(2) * vertex_per_face(3) * uv(2)
 
-short cube_texcoords[3][6 * 2 * 3 * 2] = {
-	{
-		32, 32,  0, 32,  0,  0,
-		32, 32,  0,  0, 32,  0,
-
-		0, 32,  0,  0, 32,  0,
-		0, 32, 32,  0, 32, 32,
-
-		32, 32,  0, 32,  0,  0,
-		32, 32,  0,  0, 32,  0,
+extern short cube_texcoords[3][6 * 2 * 3 * 2];
+extern char tab_2E138[4 * 3];
 
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
+} // End of namespace Cryo
 
-		0,  0, 32,  0, 32, 32,
-		0,  0, 32, 32,  0, 32,
-
-		0, 32,  0,  0, 32,  0,
-		0, 32, 32,  0, 32, 32
-	}, {
-		32, 32,  0, 32,  0,  0,
-		32, 32,  0,  0, 32,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		0, 32,  0,  0, 32,  0,
-		0, 32, 32,  0, 32, 32,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0,
-
-		32,  0, 32, 32,  0, 32,
-		32,  0,  0, 32,  0,  0
-	}, {
-		30, 30,  2, 30,  2,  2,
-		30, 30,  2,  2, 30,  2,
-
-		2, 30,  2,  2, 30,  2,
-		2, 30, 30,  2, 30, 30,
-
-		30, 30,  2, 30,  2,  2,
-		30, 30,  2,  2, 30,  2,
-
-		30,  2, 30, 30,  2, 30,
-		30,  2,  2, 30,  2,  2,
-
-		2,  2, 30,  2, 30, 30,
-		2,  2, 30, 30,  2, 30,
-
-		2, 30,  2,  2, 30,  2,
-		2, 30, 30,  2, 30, 30
-	}
-};
-
-char tab_2E138[4 * 3] = {
-	0, 0, 1, 1,
-	0, 0, 0, 1,
-	0, 0, 2, 0
-};
+#endif
diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp
index 48416f7..10f368e 100644
--- a/engines/cryo/eden.cpp
+++ b/engines/cryo/eden.cpp
@@ -1,5 +1,3 @@
-//#include <stdint.h>
-
 #include "common/scummsys.h"
 
 #include "common/config-manager.h"
@@ -19,16 +17,14 @@
 //#include "audio/audiostream.h"
 #include "audio/mixer.h"
 
+#include "cryo/defs.h"
 #include "cryo/cryo.h"
+#include "cryo/platdefs.h"
+#include "cryo/cryolib.h"
 #include "cryo/eden.h"
 
 namespace Cryo {
 
-#include "cryo/platdefs.h"
-#include "cryo/defs.h"
-#include "cryo/CryoLib.h"
-#include "cryo/CryoLibStub.c"
-
 short       word_2C300 = 0;
 short       word_2C302 = 0;
 short       word_2C304 = 0;
@@ -40,413 +36,311 @@ struct {
 	short   x, y;
 } saved_repadam = { -1, -1 };
 
-class EdenGameImpl : EdenGame {
-private:
-
-	short           old_scroll_pos, scroll_pos;
-	short           word_2F514;
-	unsigned char   fresqTalk;
-	unsigned char   keep01, keep02, keep10, keep11, keep12, keep13, keep21, keep22;
-	unsigned char   curs_keepbuf[2500];
-	short           curs_keepy, curs_keepx;
-	short           torchCursor;
-	short           cur_bank_num;
-	short           glow_h;
-	short           glow_w;
-	short           glow_y;
-	short           glow_x;
-	unsigned char   needPaletteUpdate;
-	unsigned char   curs_saved;
-	unsigned char   showBlackBars;
-	unsigned char   fond_saved;
-	unsigned char   *bank_data_ptr;
-	color3_t        pal_entry;
-	color_t         global_palette[256];    //TODO palette_t
-	perso_t         *tyranPtr;
-	int             last_anim_frame_num;
-	int             cur_anim_frame_num;
-	int             last_anim_ticks;
-	prect_t         *cur_perso_rect;
-	short           num_anim_frames;
-	short           max_perso_desc;
-	short           num_img_desc;
-	unsigned char   restartAnimation;
-	unsigned char   animationActive;
-	unsigned char   animationDelay;
-	unsigned char   animationIndex;
-	unsigned char   lastAnimationIndex;
-
-	unsigned char   *dword_30724;
-	unsigned char   *dword_30728;   //TODO: rename - something amim-related
-	unsigned char   *dword_3072C;   //TODO ditto
-	unsigned char   *animationTable;
-	unsigned char   imagedesc[512];
-	unsigned char   *perso_img_bank_data_ptr;
-	unsigned char   savedUnderSubtitles;
-	short           num_text_lines;
-	unsigned char   phraseBuffer[400];
-	unsigned char   *text_ptr;
-	unsigned char   phraseIconsBuffer[10];
-	unsigned char   phraseCoordsBuffer[22];
-	unsigned char   *textoutptr;
-	unsigned char   *textout;
-	object_t        *currentSpecialObject;
-	short           word_30AFC;
-	unsigned char   byte_30AFE;
-
-	unsigned char   byte_30B00;
-	int             dword_30B04;
-
-	char            lastPhrasesFile;
-	char            dialogSkipFlags;
-
-	color3_t        newColor;
-	color_t         oldPalette[256];    // TODO palette_t ?
-	color_t         newPalette[256];
-	rect_t          rect_dst, rect_src;
-	void            *voiceSamplesBuffer;    //TODO: sound sample buffer
-	file_t          h_bigfile;
-	unsigned char   info_list[16];
-	unsigned char   needToFade;
-	unsigned char   lastMusicNum;
-	unsigned char   *main_bank_buf;
-	unsigned char   *music_buf;
-	unsigned char   *gameLipsync;
-	unsigned char   *gamePhrases;
-	unsigned char   *gameDialogs;   //TODO: rename to dialogs?
-	unsigned char   *gameConditions;
-	void            *sal_buf;   //TODO: fixme
-	unsigned char   *bank_data_buf;
-	icon_t          *gameIcons;
-	room_t          *gameRooms;
-	pak_t           *bigfile_header;
-	unsigned char   *glow_buffer;
-	unsigned char   *p_mainview_buf;
-	unsigned char   *p_view2_buf;
-	unsigned char   *gameFont;  //TODO: rename to font?
-	unsigned char   *p_subtitlesview_buf;
-	unsigned char   *p_underSubtitlesView_buf;
-	global_t        *p_global;
-	unsigned short  mouse_y_center, mouse_x_center;
-	int             quit_flag3;     //TODO: some obsolete error flag?
-	unsigned short  machine_speed;
-	unsigned char   quit_flag;
-
-	unsigned char   gameStarted;
-
-	unsigned char   quit_flag2;
-	unsigned char   soundAllocated;
-	soundchannel_t  *music_channel;
-	soundchannel_t  *hnmsound_ch;
-	sound_t         *voiceSound;
-
-	view_t          *p_view2;
-	view_t          *p_underSubtitlesView;
-	view_t          *p_subtitlesview;
-	view_t          *p_underBarsView;
-	view_t          *p_mainview;
-	view_t          *p_hnmview;
-	hnm_t           *p_hnmcontext;
-	filespec_t      bigfilespec;
-	rect_t          underSubtitlesBackupRect, underSubtitlesScreenRect, underBottomBarBackupRect, underBottomBarScreenRect,
-	                underTopBarBackupRect, underTopBarScreenRect, rect_31C7A;
-	int             demoCurrentTicks;
-	int             demoStartTicks;
-	int             currentTime;
-	short           mouse_y;
-	short           mouse_x;
-	short           doubled;
-	short           curs_x_pan;
-	short           inventoryScrollDelay;
-	short           curs_y, curs_x;
-	short           current_cursor;
-	icon_t          *current_spot;
-	icon_t          *current_spot2;
-	unsigned char   pomme_q;
-	unsigned char   keybd_held;
-	unsigned char   mouse_held;
-	unsigned char   normalCursor;
-	unsigned char   *p_hnmview_buf;
-	unsigned char   showVideoSubtitle;
-	unsigned char   videoCanceled;  //TODO: hnm_canceled
-	unsigned char   specialTextMode;
-	int             hnm_position;
-	int             voiceSamplesSize;   //TODO: perso vox sample data len
-	short           mus_vol_right;
-	short           mus_vol_left;
-
-
-	unsigned char   animateTalking;
-	unsigned char   personTalking;
-	unsigned char   mus_fade_flags;
-
-	char            musicSequencePos;
-	unsigned char   musicPlaying;
-
-	unsigned char   *mus_samples_ptr;
-	unsigned char   *mus_patterns_ptr;  //TODO: sndblock_t ?
-	unsigned char   *mus_sequence_ptr;
-	soundgroup_t    *mus_queue_grp;
-	short           *pCurrentObjectLocation;
-	unsigned char   own_objects[128];
-	unsigned char   byte_31D64;
-
-	unsigned char   no_palette;
-	unsigned char   gameLoaded;
-#define MAX_TAPES 16
-	tape_t          tapes[MAX_TAPES];
-	unsigned char   confirmMode;
-	unsigned char   *cur_slider_value_ptr;
-	unsigned char   lastMenuItemIdLo;
-	short           lastTapeRoomNum;
-	short           cur_slider_x;
-	short           cur_slider_y;
-	short           destinationRoom;
-	short           word_31E7A;
-
-	short           word_378CC; //TODO: set by CLComputer_Init to 0
-	short           word_378CE;
-
-	void RemoveConsole() {
-	}
-	void scroll() {
-		restaurefrises();
-		p_mainview->norm.src_left = scroll_pos;
-		p_mainview->zoom.src_left = scroll_pos;
-
-	}
-	void resetscroll() {
-		old_scroll_pos = scroll_pos;
-		scroll_pos = 0;
-		restaurefrises();   //TODO: inlined scroll() ?
-		p_mainview->norm.src_left = 0;
-		p_mainview->zoom.src_left = 0;
-	}
-	void scrollfresques() {
-		if (curs_y > 16 && curs_y < 176) {
-			if (curs_x >= 0 && curs_x < 32 && scroll_pos > 3) {
-				scroll_pos -= 4;
-			} else if (curs_x > 288 && curs_x < 320 && scroll_pos < p_global->fresqWidth) {
-				scroll_pos += 4;
-			}
-		}
-		scroll();
+void EdenGame::RemoveConsole() {
+}
 
+void EdenGame::scroll() {
+	restaurefrises();
+	p_mainview->norm.src_left = scroll_pos;
+	p_mainview->zoom.src_left = scroll_pos;
+
+}
+
+void EdenGame::resetscroll() {
+	old_scroll_pos = scroll_pos;
+	scroll_pos = 0;
+	restaurefrises();   //TODO: inlined scroll() ?
+	p_mainview->norm.src_left = 0;
+	p_mainview->zoom.src_left = 0;
+}
+
+void EdenGame::scrollfresques() {
+	if (curs_y > 16 && curs_y < 176) {
+		if (curs_x >= 0 && curs_x < 32 && scroll_pos > 3) {
+			scroll_pos -= 4;
+		} else if (curs_x > 288 && curs_x < 320 && scroll_pos < p_global->fresqWidth) {
+			scroll_pos += 4;
+		}
 	}
-	void afffresques() {
-		use_bank(p_global->fresqImgBank);
-		noclipax(0, 0, 16);
-		use_bank(p_global->fresqImgBank + 1);
-		noclipax(0, 320, 16);
-		needPaletteUpdate = 1;
-	}
-	void gametofresques() {
-		fresqTalk = 0;
-		rundcurs();
-		sauvefrises();
-		afffresques();
-		p_global->displayFlags = DisplayFlags::dfFresques;
-	}
-	void dofresques() {
-		curs_saved = 0;
-		torchCursor = 1;
-		glow_x = -1;
-		glow_y = -1;
-		p_global->gameFlags |= GameFlags::gfFlag20;
-		p_global->ff_D4 = 0;
-		p_global->curObjectId = 0;
-		p_global->iconsIndex = 13;
-		p_global->autoDialog = 0;
-		gametofresques();
-		p_global->fresqNumber = 3;
-	}
-	void finfresques() {
-		torchCursor = 0;
-		curs_saved = 1;
-		p_global->displayFlags = DisplayFlags::dfFlag1;
-		resetscroll();
-		p_global->ff_100 = -1;
-		maj_salle(p_global->roomNum);
-		if (p_global->phaseNum == 114)
-			p_global->narratorSequence = 1;
-		p_global->eventType = EventType::etEvent8;
-		showevents();
-	}
-	void scrollmiroir() {
-		if (curs_y > 16 && curs_y < 165) {
-			if (curs_x >= 0 && curs_x < 16) {
-				if (scroll_pos > 3) {
-					if (doubled)
-						scroll_pos -= 2;
-					else
-						scroll_pos -= 1;
-					scroll();
-				}
-			} else if (curs_x > 290 && curs_x < 320) {
-				if (scroll_pos < 320) {
-					if (doubled)
-						scroll_pos += 2;
-					else
-						scroll_pos += 1;
-					scroll();
-				}
+	scroll();
+
+}
+
+void EdenGame::afffresques() {
+	use_bank(p_global->fresqImgBank);
+	noclipax(0, 0, 16);
+	use_bank(p_global->fresqImgBank + 1);
+	noclipax(0, 320, 16);
+	needPaletteUpdate = 1;
+}
+
+void EdenGame::gametofresques() {
+	fresqTalk = 0;
+	rundcurs();
+	sauvefrises();
+	afffresques();
+	p_global->displayFlags = DisplayFlags::dfFresques;
+}
+
+void EdenGame::dofresques() {
+	curs_saved = 0;
+	torchCursor = 1;
+	glow_x = -1;
+	glow_y = -1;
+	p_global->gameFlags |= GameFlags::gfFlag20;
+	p_global->ff_D4 = 0;
+	p_global->curObjectId = 0;
+	p_global->iconsIndex = 13;
+	p_global->autoDialog = 0;
+	gametofresques();
+	p_global->fresqNumber = 3;
+}
+
+void EdenGame::finfresques() {
+	torchCursor = 0;
+	curs_saved = 1;
+	p_global->displayFlags = DisplayFlags::dfFlag1;
+	resetscroll();
+	p_global->ff_100 = -1;
+	maj_salle(p_global->roomNum);
+	if (p_global->phaseNum == 114)
+		p_global->narratorSequence = 1;
+	p_global->eventType = EventType::etEvent8;
+	showevents();
+}
+
+void EdenGame::scrollmiroir() {
+	if (curs_y > 16 && curs_y < 165) {
+		if (curs_x >= 0 && curs_x < 16) {
+			if (scroll_pos > 3) {
+				if (doubled)
+					scroll_pos -= 2;
+				else
+					scroll_pos -= 1;
+				scroll();
+			}
+		} else if (curs_x > 290 && curs_x < 320) {
+			if (scroll_pos < 320) {
+				if (doubled)
+					scroll_pos += 2;
+				else
+					scroll_pos += 1;
+				scroll();
 			}
 		}
 	}
-	void scrollpano() {
-		if (curs_y > 16 && curs_y < 165) {
-			if (curs_x >= 0 && curs_x < 16) {
-				if (scroll_pos > 3) {
-					if (doubled)
-						scroll_pos -= 2;
-					else
-						scroll_pos -= 1;
-				}
-			} else if (curs_x > 290 && curs_x < 320) {
-				if (scroll_pos < 320) {
-					if (doubled)
-						scroll_pos += 2;
-					else
-						scroll_pos += 1;
-				}
+}
+
+void EdenGame::scrollpano() {
+	if (curs_y > 16 && curs_y < 165) {
+		if (curs_x >= 0 && curs_x < 16) {
+			if (scroll_pos > 3) {
+				if (doubled)
+					scroll_pos -= 2;
+				else
+					scroll_pos -= 1;
+			}
+		} else if (curs_x > 290 && curs_x < 320) {
+			if (scroll_pos < 320) {
+				if (doubled)
+					scroll_pos += 2;
+				else
+					scroll_pos += 1;
 			}
 		}
-		scroll();
 	}
-	void affsuiveur(suiveur_t *suiveur, short x, short y) {
-		use_bank(suiveur->bank);
-		noclipax(suiveur->image, x, y + 16);
+	scroll();
+}
+
+void EdenGame::affsuiveur(suiveur_t *suiveur, short x, short y) {
+	use_bank(suiveur->bank);
+	noclipax(suiveur->image, x, y + 16);
+}
+
+void EdenGame::persoinmiroir() {
+	icon_t  *icon1 = &gameIcons[3];
+	icon_t  *icon = &gameIcons[28];
+	suiveur_t *suiveur = suiveurs_list;
+	short num = 1;
+	int i;
+	for (i = 0; i < 16; i++) {
+		if (p_global->party & (1 << i))
+			num++;
 	}
-	void persoinmiroir() {
-		icon_t  *icon1 = &gameIcons[3];
-		icon_t  *icon = &gameIcons[28];
-		suiveur_t *suiveur = suiveurs_list;
-		short num = 1;
-		int i;
-		for (i = 0; i < 16; i++) {
-			if (p_global->party & (1 << i))
-				num++;
-		}
-		icon += num;
-		icon->sx = -1;
-		icon--;
-		icon->sx = icon1->sx;
-		icon->sy = icon1->sy;
-		icon->ex = icon1->ex;
-		icon->ey = 170;
-		icon->cursor_id = icon1->cursor_id;
-		icon->action_id = icon1->action_id;
-		icon->object_id = icon1->object_id;
-		icon--;
-		affsuiveur(suiveur, suiveur->sx, suiveur->sy);
-		for (; suiveur->id != -1; suiveur++) {
-			perso_t *perso;
-			for (perso = kPersons; perso != &kPersons[PER_UNKN_156]; perso++) {
-				if (perso->id != suiveur->id)                       continue;
-				if (perso->flags & PersonFlags::pf80)               continue;
-				if ((perso->flags & PersonFlags::pfInParty) == 0)   continue;
-				if (perso->roomNum != p_global->roomNum)            continue;
-				icon->sx = suiveur->sx;
-				icon->sy = suiveur->sy;
-				icon->ex = suiveur->ex;
-				icon->ey = suiveur->ey;
-				icon->cursor_id = 8;
-				icon->action_id = perso->actionId;
-				icon--;
-				affsuiveur(suiveur, suiveur->sx, suiveur->sy);
-				break;
-			}
+	icon += num;
+	icon->sx = -1;
+	icon--;
+	icon->sx = icon1->sx;
+	icon->sy = icon1->sy;
+	icon->ex = icon1->ex;
+	icon->ey = 170;
+	icon->cursor_id = icon1->cursor_id;
+	icon->action_id = icon1->action_id;
+	icon->object_id = icon1->object_id;
+	icon--;
+	affsuiveur(suiveur, suiveur->sx, suiveur->sy);
+	for (; suiveur->id != -1; suiveur++) {
+		perso_t *perso;
+		for (perso = kPersons; perso != &kPersons[PER_UNKN_156]; perso++) {
+			if (perso->id != suiveur->id)                       continue;
+			if (perso->flags & PersonFlags::pf80)               continue;
+			if ((perso->flags & PersonFlags::pfInParty) == 0)   continue;
+			if (perso->roomNum != p_global->roomNum)            continue;
+			icon->sx = suiveur->sx;
+			icon->sy = suiveur->sy;
+			icon->ex = suiveur->ex;
+			icon->ey = suiveur->ey;
+			icon->cursor_id = 8;
+			icon->action_id = perso->actionId;
+			icon--;
+			affsuiveur(suiveur, suiveur->sx, suiveur->sy);
+			break;
 		}
 	}
-	void gametomiroir(unsigned char arg1) {
-		short bank;
-		if (p_global->displayFlags != DisplayFlags::dfFlag2) {
-			rundcurs();
-			restaurefrises();
-			afftopscr();
-			showobjects();
-			sauvefrises();
-		}
-		bank = p_global->roomBgBankNum;
-		if (bank == 76 || bank == 128)
-			bank = 2161;
-		use_bank(bank + 326);
-		noclipax(0, 0, 16);
-		use_bank(bank + 327);
-		noclipax(0, 320, 16);
-		persoinmiroir();
-		needPaletteUpdate = 1;
-		p_global->iconsIndex = 16;
-		p_global->autoDialog = 0;
-		p_global->displayFlags = DisplayFlags::dfMirror;
-		p_global->ff_102 = arg1;
+}
+
+void EdenGame::gametomiroir(unsigned char arg1) {
+	short bank;
+	if (p_global->displayFlags != DisplayFlags::dfFlag2) {
+		rundcurs();
+		restaurefrises();
+		afftopscr();
+		showobjects();
+		sauvefrises();
 	}
-	void flipmode() {
-		if (personTalking) {
-			endpersovox();
-			if (p_global->displayFlags == DisplayFlags::dfPerson) {
-				if (p_global->perso_ptr == &kPersons[PER_THOO] && p_global->phaseNum >= 80)
-					af_subtitle();
-				else {
-					getdatasync();
-					load_perso_cour();
-					addanim();
-					restartAnimation = 1;
-					anim_perso();
-				}
-			} else
+	bank = p_global->roomBgBankNum;
+	if (bank == 76 || bank == 128)
+		bank = 2161;
+	use_bank(bank + 326);
+	noclipax(0, 0, 16);
+	use_bank(bank + 327);
+	noclipax(0, 320, 16);
+	persoinmiroir();
+	needPaletteUpdate = 1;
+	p_global->iconsIndex = 16;
+	p_global->autoDialog = 0;
+	p_global->displayFlags = DisplayFlags::dfMirror;
+	p_global->ff_102 = arg1;
+}
+
+void EdenGame::flipmode() {
+	if (personTalking) {
+		endpersovox();
+		if (p_global->displayFlags == DisplayFlags::dfPerson) {
+			if (p_global->perso_ptr == &kPersons[PER_THOO] && p_global->phaseNum >= 80)
 				af_subtitle();
-			persovox();
-		} else {
-			if (p_global->displayFlags != DisplayFlags::dfFresques && p_global->displayFlags != DisplayFlags::dfFlag2) {
-				closesalle();
-				if (p_global->displayFlags & DisplayFlags::dfFlag1)
-					gametomiroir(1);
-				else {
-					quitmiroir();
-					maj_salle(p_global->roomNum);
-					if (byte_31D64) {
-						dialautoon();
-						parle_moi();
-					}
-					byte_31D64 = 0;
+			else {
+				getdatasync();
+				load_perso_cour();
+				addanim();
+				restartAnimation = 1;
+				anim_perso();
+			}
+		} else
+			af_subtitle();
+		persovox();
+	} else {
+		if (p_global->displayFlags != DisplayFlags::dfFresques && p_global->displayFlags != DisplayFlags::dfFlag2) {
+			closesalle();
+			if (p_global->displayFlags & DisplayFlags::dfFlag1)
+				gametomiroir(1);
+			else {
+				quitmiroir();
+				maj_salle(p_global->roomNum);
+				if (byte_31D64) {
+					dialautoon();
+					parle_moi();
 				}
+				byte_31D64 = 0;
 			}
 		}
 	}
-	void quitmiroir() {
-		rundcurs();
-		afficher();
-		resetscroll();
-		sauvefrises();
-		p_global->displayFlags = DisplayFlags::dfFlag1;
-		p_global->ff_100 = -1;
-		p_global->eventType = EventType::etEventC;
-		p_global->ff_102 = 1;
-	}
-	void clictimbre() {
-		flipmode();
+}
+
+void EdenGame::quitmiroir() {
+	rundcurs();
+	afficher();
+	resetscroll();
+	sauvefrises();
+	p_global->displayFlags = DisplayFlags::dfFlag1;
+	p_global->ff_100 = -1;
+	p_global->eventType = EventType::etEventC;
+	p_global->ff_102 = 1;
+}
+
+void EdenGame::clictimbre() {
+	flipmode();
+}
+
+void EdenGame::clicplanval() {
+	if ((p_global->partyOutside & PersonMask::pmDina) && p_global->phaseNum == 371) {
+		quitmiroir();
+		maj_salle(p_global->roomNum);
+		return;
 	}
-	void clicplanval() {
-		if ((p_global->partyOutside & PersonMask::pmDina) && p_global->phaseNum == 371) {
-			quitmiroir();
-			maj_salle(p_global->roomNum);
-			return;
-		}
-		if (p_global->roomNum == 8 || p_global->roomNum < 16)
-			return;
-		rundcurs();
-		afficher();
-		if (p_global->displayFlags == DisplayFlags::dfMirror)
-			quitmiroir();
-		deplaval((p_global->roomNum & 0xFF00) | 1); //TODO: check me
+	if (p_global->roomNum == 8 || p_global->roomNum < 16)
+		return;
+	rundcurs();
+	afficher();
+	if (p_global->displayFlags == DisplayFlags::dfMirror)
+		quitmiroir();
+	deplaval((p_global->roomNum & 0xFF00) | 1); //TODO: check me
+}
+
+void EdenGame::gotolieu(goto_t *go) {
+	p_global->valleyVidNum = go->arriveVid;
+	p_global->travelTime = go->travelTime * 256;
+	p_global->stepsToFindAppleFast = 0;
+	p_global->eventType = EventType::etEvent2;
+	init_oui();
+	showevents();
+	if (!verif_oui())
+		return;
+	if (p_global->ff_113) {
+		waitendspeak();
+		if (!pomme_q)
+			close_perso();
 	}
-	void gotolieu(goto_t *go) {
-		p_global->valleyVidNum = go->arriveVid;
-		p_global->travelTime = go->travelTime * 256;
-		p_global->stepsToFindAppleFast = 0;
-		p_global->eventType = EventType::etEvent2;
+	if (go->departVid) {
+		bars_out();
+		playhnm(go->departVid);
+		needToFade = 1;
+	}
+	initlieu(p_global->newRoomNum);
+	specialoutside();
+	faire_suivre(p_global->newRoomNum);
+	closesalle();
+	saved_repadam.x = -1;
+	saved_repadam.y = -1;
+	temps_passe(p_global->travelTime);
+	p_global->ff_100 = p_global->room_ptr->ff_0;
+	p_global->roomNum = p_global->newRoomNum;
+	p_global->areaNum = p_global->roomNum >> 8;
+	p_global->eventType = EventType::etEvent5;
+	p_global->newMusicType = MusicType::mt2;
+	setpersohere();
+	musique();
+	majsalle1(p_global->roomNum);
+	afftopscr();
+	saved_repadam.x = -1;
+	saved_repadam.y = -1;
+}
+
+void EdenGame::deplaval(unsigned short roomNum) {
+	unsigned char c1, newAreaNum, curAreaNum;
+	short newRoomNum;
+	p_global->newLocation = roomNum & 0xFF;
+	p_global->valleyVidNum = 0;
+	p_global->phaseActionsCount++;
+	closesalle();
+	endpersovox();
+	c1 = roomNum & 0xFF;
+	if (c1 == 0)
+		return;
+	if (c1 < 0x80) {
+		p_global->displayFlags = DisplayFlags::dfFlag1;
 		init_oui();
+		p_global->eventType = EventType::etEvent1;
 		showevents();
 		if (!verif_oui())
 			return;
@@ -455,865 +349,1960 @@ private:
 			if (!pomme_q)
 				close_perso();
 		}
-		if (go->departVid) {
-			bars_out();
-			playhnm(go->departVid);
-			needToFade = 1;
+		specialout();
+		if (p_global->area_ptr->type == AreaType::atValley) {
+			temps_passe(32);
+			p_global->stepsToFindAppleFast++;
+			p_global->stepsToFindAppleNormal++;
 		}
-		initlieu(p_global->newRoomNum);
-		specialoutside();
-		faire_suivre(p_global->newRoomNum);
-		closesalle();
-		saved_repadam.x = -1;
-		saved_repadam.y = -1;
-		temps_passe(p_global->travelTime);
+		faire_suivre((roomNum & 0xFF00) | p_global->newLocation);
 		p_global->ff_100 = p_global->room_ptr->ff_0;
-		p_global->roomNum = p_global->newRoomNum;
-		p_global->areaNum = p_global->roomNum >> 8;
+		p_global->roomNum = roomNum;
+		p_global->areaNum = roomNum >> 8;
 		p_global->eventType = EventType::etEvent5;
-		p_global->newMusicType = MusicType::mt2;
 		setpersohere();
+		p_global->newMusicType = MusicType::mtNormal;
 		musique();
-		majsalle1(p_global->roomNum);
-		afftopscr();
-		saved_repadam.x = -1;
-		saved_repadam.y = -1;
-	}
-	void deplaval(unsigned short roomNum) {
-		unsigned char c1, newAreaNum, curAreaNum;
-		short newRoomNum;
-		p_global->newLocation = roomNum & 0xFF;
-		p_global->valleyVidNum = 0;
-		p_global->phaseActionsCount++;
-		closesalle();
-		endpersovox();
-		c1 = roomNum & 0xFF;
-		if (c1 == 0)
-			return;
-		if (c1 < 0x80) {
-			p_global->displayFlags = DisplayFlags::dfFlag1;
-			init_oui();
-			p_global->eventType = EventType::etEvent1;
-			showevents();
-			if (!verif_oui())
-				return;
-			if (p_global->ff_113) {
-				waitendspeak();
-				if (!pomme_q)
-					close_perso();
-			}
-			specialout();
-			if (p_global->area_ptr->type == AreaType::atValley) {
-				temps_passe(32);
-				p_global->stepsToFindAppleFast++;
-				p_global->stepsToFindAppleNormal++;
-			}
-			faire_suivre((roomNum & 0xFF00) | p_global->newLocation);
-			p_global->ff_100 = p_global->room_ptr->ff_0;
-			p_global->roomNum = roomNum;
-			p_global->areaNum = roomNum >> 8;
-			p_global->eventType = EventType::etEvent5;
-			setpersohere();
-			p_global->newMusicType = MusicType::mtNormal;
-			musique();
-			majsalle1(roomNum);
-			p_global->chrono_on = 0;
-			p_global->chrono = 0;
-			p_global->ff_54 = 0;
-			if (p_global->roomPersoType == PersonFlags::pftTyrann)
-				chronoon(3000);
-			return;
+		majsalle1(roomNum);
+		p_global->chrono_on = 0;
+		p_global->chrono = 0;
+		p_global->ff_54 = 0;
+		if (p_global->roomPersoType == PersonFlags::pftTyrann)
+			chronoon(3000);
+		return;
+	}
+	if (c1 == 0xFF) {
+		p_global->eventType = EventType::etEventE;
+		showevents();
+		if (!kPersons[PER_MESSAGER].roomNum) {
+			if (eloirevientq())
+				chronoon(800);
 		}
-		if (c1 == 0xFF) {
-			p_global->eventType = EventType::etEventE;
-			showevents();
-			if (!kPersons[PER_MESSAGER].roomNum) {
-				if (eloirevientq())
-					chronoon(800);
+		return;
+	}
+	p_global->stepsToFindAppleFast = 0;
+	newAreaNum = c1 & 0x7F;
+	curAreaNum = p_global->roomNum >> 8;
+	newRoomNum = newAreaNum << 8;
+	if (curAreaNum == Areas::arTausCave && newAreaNum == Areas::arMo)
+		newRoomNum |= 0x16;
+	else if (curAreaNum == Areas::arMoorkusLair)
+		newRoomNum |= 4;
+	else
+		newRoomNum |= 1;
+	p_global->newRoomNum = newRoomNum;
+	if (newAreaNum == Areas::arTausCave)
+		gotolieu(&gotos[0]);
+	else {
+		goto_t *go;
+		for (go = gotos + 1; go->curAreaNum != 0xFF; go++)
+			if (go->curAreaNum == curAreaNum) {
+				gotolieu(go);
+				break;
 			}
-			return;
-		}
-		p_global->stepsToFindAppleFast = 0;
-		newAreaNum = c1 & 0x7F;
-		curAreaNum = p_global->roomNum >> 8;
-		newRoomNum = newAreaNum << 8;
-		if (curAreaNum == Areas::arTausCave && newAreaNum == Areas::arMo)
-			newRoomNum |= 0x16;
-		else if (curAreaNum == Areas::arMoorkusLair)
-			newRoomNum |= 4;
-		else
-			newRoomNum |= 1;
-		p_global->newRoomNum = newRoomNum;
-		if (newAreaNum == Areas::arTausCave)
-			gotolieu(&gotos[0]);
-		else {
-			goto_t *go;
-			for (go = gotos + 1; go->curAreaNum != 0xFF; go++)
-				if (go->curAreaNum == curAreaNum) {
-					gotolieu(go);
-					break;
-				}
-		}
 	}
-	void deplacement(short dir) {
-		room_t *room = p_global->room_ptr;
-		short roomNum = p_global->roomNum;
-		debug("deplacement: from room %4X", roomNum);
-		char newLoc;
-		rundcurs();
-		afficher();
-		p_global->prevLocation = roomNum & 0xFF;
-		switch (dir) {
-		case 0:
-			newLoc = room->exits[0];
-			break;
-		case 1:
-			newLoc = room->exits[1];
-			break;
-		case 2:
-			newLoc = room->exits[2];
-			break;
-		case 3:
-			newLoc = room->exits[3];
-			break;
-		}
-		deplaval((roomNum & 0xFF00) | newLoc);
-	}
-	void deplacement2(short dir) {
-		room_t *room = p_global->room_ptr;
-		short roomNum = p_global->roomNum;
-		char newLoc;
-		p_global->prevLocation = roomNum & 0xFF;
-		switch (dir) {
-		case 0:
-			newLoc = room->exits[0];
-			break;
-		case 1:
-			newLoc = room->exits[1];
-			break;
-		case 2:
-			newLoc = room->exits[2];
-			break;
-		case 3:
-			newLoc = room->exits[3];
-			break;
-		}
-		deplaval((roomNum & 0xFF00) | newLoc);
+}
 
+void EdenGame::deplacement(short dir) {
+	room_t *room = p_global->room_ptr;
+	short roomNum = p_global->roomNum;
+	debug("deplacement: from room %4X", roomNum);
+	char newLoc;
+	rundcurs();
+	afficher();
+	p_global->prevLocation = roomNum & 0xFF;
+	switch (dir) {
+	case 0:
+		newLoc = room->exits[0];
+		break;
+	case 1:
+		newLoc = room->exits[1];
+		break;
+	case 2:
+		newLoc = room->exits[2];
+		break;
+	case 3:
+		newLoc = room->exits[3];
+		break;
+	}
+	deplaval((roomNum & 0xFF00) | newLoc);
+}
+
+void EdenGame::deplacement2(short dir) {
+	room_t *room = p_global->room_ptr;
+	short roomNum = p_global->roomNum;
+	char newLoc;
+	p_global->prevLocation = roomNum & 0xFF;
+	switch (dir) {
+	case 0:
+		newLoc = room->exits[0];
+		break;
+	case 1:
+		newLoc = room->exits[1];
+		break;
+	case 2:
+		newLoc = room->exits[2];
+		break;
+	case 3:
+		newLoc = room->exits[3];
+		break;
+	}
+	deplaval((roomNum & 0xFF00) | newLoc);
+
+}
+
+void EdenGame::dinosoufle() {
+	if (p_global->curObjectId == 0) {
+		bars_out();
+		playhnm(148);
+		maj2();
 	}
-	void dinosoufle() {
-		if (p_global->curObjectId == 0) {
-			bars_out();
-			playhnm(148);
-			maj2();
-		}
-	}
-	void plaquemonk() {
-		if (p_global->curObjectId != 0) {
-			if (p_global->curObjectId == Objects::obPrism) {
-				loseobject(Objects::obPrism);
-				bars_out();
-				specialTextMode = 1;
-				playhnm(89);
-				word_2F514 |= 0x8000;
-				maj2();
-				p_global->eventType = EventType::etEventB;
-				showevents();
-			}
-		} else {
+}
+
+void EdenGame::plaquemonk() {
+	if (p_global->curObjectId != 0) {
+		if (p_global->curObjectId == Objects::obPrism) {
+			loseobject(Objects::obPrism);
 			bars_out();
-			playhnm(7);
+			specialTextMode = 1;
+			playhnm(89);
+			word_2F514 |= 0x8000;
 			maj2();
-			p_global->eventType = EventType::etEvent4;
+			p_global->eventType = EventType::etEventB;
 			showevents();
 		}
+	} else {
+		bars_out();
+		playhnm(7);
+		maj2();
+		p_global->eventType = EventType::etEvent4;
+		showevents();
 	}
-	void fresquesgraa() {
-		if (p_global->curObjectId == 0) {
-			p_global->fresqWidth = 320;
-			p_global->fresqImgBank = 113;
-			dofresques();
-			dinaparle();
-		}
-	}
-	void fresqueslasc() {
-		if (p_global->curObjectId == 0) {
-			p_global->fresqWidth = 112;
-			p_global->fresqImgBank = 315;
-			dofresques();
-		}
+}
+
+void EdenGame::fresquesgraa() {
+	if (p_global->curObjectId == 0) {
+		p_global->fresqWidth = 320;
+		p_global->fresqImgBank = 113;
+		dofresques();
+		dinaparle();
 	}
-	void pushpierre() {
-		if (p_global->curObjectId == 0) {
-			gameRooms[22].exits[0] = 17;
-			gameRooms[26].exits[2] = 9;
-			deplacement(0);
-		}
+}
+
+void EdenGame::fresqueslasc() {
+	if (p_global->curObjectId == 0) {
+		p_global->fresqWidth = 112;
+		p_global->fresqImgBank = 315;
+		dofresques();
 	}
-	void tetemomie() {
-		if (p_global->curObjectId == Objects::obTooth) {
-			p_global->gameFlags |= GameFlags::gfMummyOpened;
-			deplacement(0);
-		} else if (p_global->curObjectId == 0) {
-			if (p_global->gameFlags & GameFlags::gfMummyOpened)
-				deplacement(0);
-			else {
-				p_global->eventType = EventType::etEvent6;
-				persoparle(PersonId::pidMonk);
-				p_global->eventType = 0;
-			}
-		}
+}
+
+void EdenGame::pushpierre() {
+	if (p_global->curObjectId == 0) {
+		gameRooms[22].exits[0] = 17;
+		gameRooms[26].exits[2] = 9;
+		deplacement(0);
 	}
-	void tetesquel() {
-		if (p_global->curObjectId == Objects::obTooth) {
-			gameRooms[22].exits[0] = 16;
-			gameRooms[26].exits[2] = 13;
-			gameIcons[16].cursor_id |= 0x8000;
-			loseobject(Objects::obTooth);
+}
+
+void EdenGame::tetemomie() {
+	if (p_global->curObjectId == Objects::obTooth) {
+		p_global->gameFlags |= GameFlags::gfMummyOpened;
+		deplacement(0);
+	} else if (p_global->curObjectId == 0) {
+		if (p_global->gameFlags & GameFlags::gfMummyOpened)
 			deplacement(0);
+		else {
+			p_global->eventType = EventType::etEvent6;
+			persoparle(PersonId::pidMonk);
+			p_global->eventType = 0;
 		}
 	}
-	void squelmoorkong() {
-		p_global->eventType = EventType::etEvent9;
-		showevents();
+}
+
+void EdenGame::tetesquel() {
+	if (p_global->curObjectId == Objects::obTooth) {
+		gameRooms[22].exits[0] = 16;
+		gameRooms[26].exits[2] = 13;
+		gameIcons[16].cursor_id |= 0x8000;
+		loseobject(Objects::obTooth);
+		deplacement(0);
 	}
-	void choisir() {
-		unsigned char obj, objid = current_spot2->object_id;
-		switch (objid) {
-		case 0:
-			obj = p_global->giveobj1;
-			break;
-		case 1:
-			obj = p_global->giveobj2;
-			break;
-		case 2:
-			obj = p_global->giveobj3;
-			break;
-		}
-		objectmain(obj);
-		winobject(obj);
-		p_global->iconsIndex = 16;
-		p_global->autoDialog = 0;
-		p_global->ff_60 = 0;
-		parle_moi();
+}
+
+void EdenGame::squelmoorkong() {
+	p_global->eventType = EventType::etEvent9;
+	showevents();
+}
+
+void EdenGame::choisir() {
+	unsigned char obj, objid = current_spot2->object_id;
+	switch (objid) {
+	case 0:
+		obj = p_global->giveobj1;
+		break;
+	case 1:
+		obj = p_global->giveobj2;
+		break;
+	case 2:
+		obj = p_global->giveobj3;
+		break;
+	}
+	objectmain(obj);
+	winobject(obj);
+	p_global->iconsIndex = 16;
+	p_global->autoDialog = 0;
+	p_global->ff_60 = 0;
+	parle_moi();
+}
+
+void EdenGame::dinaparle() {
+	short num;
+	char res;
+	perso_t *perso = &kPersons[PER_DINA];
+	if (perso->party & (p_global->party | p_global->partyOutside)) {
+		if (p_global->fresqNumber < 3)
+			p_global->fresqNumber = 3;
+		p_global->fresqNumber++;
+		if (p_global->fresqNumber < 15) {
+			endpersovox();
+			if (p_global->fresqNumber == 7 && p_global->phaseNum == 113)
+				incphase1();
+			p_global->perso_ptr = perso;
+			p_global->dialogType = DialogType::dtInspect;
+			num = (perso->id << 3) | DialogType::dtInspect; //TODO: combine
+			res = dialoscansvmas((dial_t *)GetElem(gameDialogs, num));
+			fresqTalk = 0;
+			if (res) {
+				restaurefondbulle();
+				fresqTalk = 1;
+				persovox();
+			}
+			p_global->ff_CA = 0;
+			p_global->dialogType = 0;
+		} else
+			finfresques();
 	}
-	void dinaparle() {
-		short num;
-		char res;
-		perso_t *perso = &kPersons[PER_DINA];
-		if (perso->party & (p_global->party | p_global->partyOutside)) {
-			if (p_global->fresqNumber < 3)
-				p_global->fresqNumber = 3;
-			p_global->fresqNumber++;
-			if (p_global->fresqNumber < 15) {
-				endpersovox();
-				if (p_global->fresqNumber == 7 && p_global->phaseNum == 113)
-					incphase1();
-				p_global->perso_ptr = perso;
-				p_global->dialogType = DialogType::dtInspect;
-				num = (perso->id << 3) | DialogType::dtInspect; //TODO: combine
-				res = dialoscansvmas((dial_t *)GetElem(gameDialogs, num));
-				fresqTalk = 0;
-				if (res) {
-					restaurefondbulle();
-					fresqTalk = 1;
-					persovox();
-				}
-				p_global->ff_CA = 0;
-				p_global->dialogType = 0;
-			} else
-				finfresques();
-		}
-	}
-	void roiparle() {
-		if (p_global->phaseNum <= 400)
-			persoparle(0);
-	}
-	void roiparle1() {
-		if (p_global->curObjectId == Objects::obSword) {
-			p_global->gameFlags |= GameFlags::gfFlag80;
-			bars_out();
-			playhnm(76);
-			deplacement2(0);
-		} else {
-			p_global->fresqNumber = 1;
-			roiparle();
-		}
-	}
-	void roiparle2() {
-		p_global->fresqNumber = 2;
-		roiparle();
-	}
-	void roiparle3() {
-		p_global->fresqNumber = 3;
+}
+
+void EdenGame::roiparle() {
+	if (p_global->phaseNum <= 400)
+		persoparle(0);
+}
+
+void EdenGame::roiparle1() {
+	if (p_global->curObjectId == Objects::obSword) {
+		p_global->gameFlags |= GameFlags::gfFlag80;
+		bars_out();
+		playhnm(76);
+		deplacement2(0);
+	} else {
+		p_global->fresqNumber = 1;
 		roiparle();
 	}
-	void getcouteau() {
-		if (p_global->phaseNum >= 80) {
-			gameRooms[113].video = 0;
-			getobject(Objects::obKnife);
-		}
-		p_global->eventType = EventType::etEvent7;
-		showevents();
-	}
-	void getprisme() {
-		getobject(Objects::obPrism);
-		p_global->eventType = EventType::etEvent7;
-		showevents();
-	}
-	void getchampb() {
-		getobject(Objects::obShroom);
-	}
-	void getchampm() {
-		getobject(Objects::obBadShroom);
-	}
-	void getor() {
-		getobject(Objects::obGold);
-	}
-	void getnido() {
-		if (p_global->curObjectId != 0)
-			return;
-		p_global->room_ptr->bank = 282; //TODO: fix me
-		p_global->room_ptr--;
-		p_global->room_ptr->bank = 281; //TODO: fix me
-		p_global->room_ptr->ff_0 = 3;
-		getobject(Objects::obFullNest);
-	}
-	void getnidv() {
-		if (p_global->curObjectId != 0)
-			return;
-		p_global->room_ptr->bank = 282; //TODO: fix me
-		p_global->room_ptr--;
-		p_global->room_ptr->bank = 281; //TODO: fix me
-		p_global->room_ptr->ff_0 = 3;
-		getobject(Objects::obNest);
-	}
-	void getcorne() {
-		if (p_global->curObjectId != 0)
-			return;
-		getobject(Objects::obHorn);
-		p_global->eventType = EventType::etEvent7;
-		showevents();
-		bigphase1();
-		setpersohere();
-		p_global->room_ptr = getsalle(p_global->roomNum);
-	}
-	void getsoleil() {
-		if (p_global->curObjectId != 0)
-			return;
-		gameRooms[238].video = 0;
-		gameRooms[238].flags = RoomFlags::rf80;
-		getobject(Objects::obSunStone);
-	}
-	void getoeuf() {
-		if (p_global->curObjectId != 0)
-			return;
-		p_global->room_ptr->flags = 0;
-		p_global->room_ptr->video = 0;
-		getobject(Objects::obEgg);
+}
+
+void EdenGame::roiparle2() {
+	p_global->fresqNumber = 2;
+	roiparle();
+}
+
+void EdenGame::roiparle3() {
+	p_global->fresqNumber = 3;
+	roiparle();
+}
+
+void EdenGame::getcouteau() {
+	if (p_global->phaseNum >= 80) {
+		gameRooms[113].video = 0;
+		getobject(Objects::obKnife);
 	}
-	void getplaque() {
-		int i;
-		if (p_global->curObjectId != 0 && p_global->curObjectId < Objects::obTablet1)
+	p_global->eventType = EventType::etEvent7;
+	showevents();
+}
+
+void EdenGame::getprisme() {
+	getobject(Objects::obPrism);
+	p_global->eventType = EventType::etEvent7;
+	showevents();
+}
+
+void EdenGame::getchampb() {
+	getobject(Objects::obShroom);
+}
+
+void EdenGame::getchampm() {
+	getobject(Objects::obBadShroom);
+}
+
+void EdenGame::getor() {
+	getobject(Objects::obGold);
+}
+
+void EdenGame::getnido() {
+	if (p_global->curObjectId != 0)
+		return;
+	p_global->room_ptr->bank = 282; //TODO: fix me
+	p_global->room_ptr--;
+	p_global->room_ptr->bank = 281; //TODO: fix me
+	p_global->room_ptr->ff_0 = 3;
+	getobject(Objects::obFullNest);
+}
+
+void EdenGame::getnidv() {
+	if (p_global->curObjectId != 0)
+		return;
+	p_global->room_ptr->bank = 282; //TODO: fix me
+	p_global->room_ptr--;
+	p_global->room_ptr->bank = 281; //TODO: fix me
+	p_global->room_ptr->ff_0 = 3;
+	getobject(Objects::obNest);
+}
+
+void EdenGame::getcorne() {
+	if (p_global->curObjectId != 0)
+		return;
+	getobject(Objects::obHorn);
+	p_global->eventType = EventType::etEvent7;
+	showevents();
+	bigphase1();
+	setpersohere();
+	p_global->room_ptr = getsalle(p_global->roomNum);
+}
+
+void EdenGame::getsoleil() {
+	if (p_global->curObjectId != 0)
+		return;
+	gameRooms[238].video = 0;
+	gameRooms[238].flags = RoomFlags::rf80;
+	getobject(Objects::obSunStone);
+}
+
+void EdenGame::getoeuf() {
+	if (p_global->curObjectId != 0)
+		return;
+	p_global->room_ptr->flags = 0;
+	p_global->room_ptr->video = 0;
+	getobject(Objects::obEgg);
+}
+
+void EdenGame::getplaque() {
+	int i;
+	if (p_global->curObjectId != 0 && p_global->curObjectId < Objects::obTablet1)
+		return;
+	p_global->curObjectId = 0;
+	getobject(Objects::obTablet2);
+	putobject();
+	for (i = 0; i < 6; i++)
+		objects[Objects::obTablet1 - 1 + i].count = 0;
+	p_global->curObjectFlags = 0;
+	p_global->inventoryScrollPos = 0;
+	p_global->curObjectCursor = 9;
+	gameIcons[16].cursor_id |= 0x8000;
+	showobjects();
+	gameRooms[131].video = 0;
+	bars_out();
+	playhnm(149);
+	p_global->ff_F1 = RoomFlags::rf04;
+	p_global->drawFlags = DrawFlags::drDrawFlag20;
+	normalCursor = 1;
+	maj2();
+}
+
+void EdenGame::voirlac() {
+	perso_t *perso = &kPersons[PER_MORKUS];
+	room_t *room = p_global->room_ptr;
+	area_t *area = p_global->area_ptr;
+	short vid = p_global->curObjectId == Objects::obApple ? 81 : 54;
+	for (++perso; perso->roomNum != 0xFFFF; perso++) {
+		if (perso->roomNum != p_global->roomNum)
+			continue;
+		vid++;
+		if (p_global->curObjectId != Objects::obApple)
+			continue;                   //TODO: pc breaks here
+		if ((perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftMosasaurus)
+			continue;
+		if (!(perso->flags & PersonFlags::pf80))
 			return;
-		p_global->curObjectId = 0;
-		getobject(Objects::obTablet2);
-		putobject();
-		for (i = 0; i < 6; i++)
-			objects[Objects::obTablet1 - 1 + i].count = 0;
-		p_global->curObjectFlags = 0;
-		p_global->inventoryScrollPos = 0;
-		p_global->curObjectCursor = 9;
-		gameIcons[16].cursor_id |= 0x8000;
-		showobjects();
-		gameRooms[131].video = 0;
-		bars_out();
-		playhnm(149);
-		p_global->ff_F1 = RoomFlags::rf04;
-		p_global->drawFlags = DrawFlags::drDrawFlag20;
-		normalCursor = 1;
-		maj2();
-	}
-	void voirlac() {
-		perso_t *perso = &kPersons[PER_MORKUS];
-		room_t *room = p_global->room_ptr;
-		area_t *area = p_global->area_ptr;
-		short vid = p_global->curObjectId == Objects::obApple ? 81 : 54;
-		for (++perso; perso->roomNum != 0xFFFF; perso++) {
-			if (perso->roomNum != p_global->roomNum)
-				continue;
-			vid++;
-			if (p_global->curObjectId != Objects::obApple)
-				continue;                   //TODO: pc breaks here
-			if ((perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftMosasaurus)
-				continue;
-			if (!(perso->flags & PersonFlags::pf80))
-				return;
-			perso->flags &= ~PersonFlags::pf80; //TODO: useless? see above
-			area->flags |= AreaFlags::afFlag8;
-			p_global->curAreaFlags |= AreaFlags::afFlag8;
-			room->ff_0 = 3;
+		perso->flags &= ~PersonFlags::pf80; //TODO: useless? see above
+		area->flags |= AreaFlags::afFlag8;
+		p_global->curAreaFlags |= AreaFlags::afFlag8;
+		room->ff_0 = 3;
+	}
+	debug("sea monster: room = %X, d0 = %X\n", p_global->roomNum, p_global->roomImgBank);
+	bars_out();
+	playhnm(vid);
+	maj_salle(p_global->roomNum);           //TODO: getting memory trashed here?
+	if (p_global->curObjectId == Objects::obApple)
+		loseobject(Objects::obApple);
+	p_global->eventType = EventType::etEventF;
+	showevents();
+}
+
+void EdenGame::gotohall() {
+	p_global->prevLocation = p_global->roomNum & 0xFF;
+	deplaval((p_global->roomNum & 0xFF00) | 6);
+}
+
+void EdenGame::demitourlabi() {
+	unsigned short target;
+	p_global->prevLocation = p_global->roomNum & 0xFF;
+	p_global->ff_100 = -1;
+	target = (p_global->roomNum & 0xFF00) | p_global->room_ptr->exits[2];
+	faire_suivre(target);
+	p_global->roomNum = target;
+	p_global->eventType = EventType::etEvent5;
+	maj_salle(p_global->roomNum);
+}
+
+void EdenGame::gotonido() {
+	p_global->room_ptr++;
+	p_global->eventType = 0;
+	p_global->roomImgBank = p_global->room_ptr->bank;
+	p_global->roomVidNum = p_global->room_ptr->video;
+	p_global->curRoomFlags = p_global->room_ptr->flags;
+	p_global->ff_F1 = p_global->room_ptr->flags;
+	animpiece();
+	p_global->ff_100 = 0;
+	maj2();
+}
+
+void EdenGame::gotoval() {
+	unsigned short target = p_global->roomNum;
+	char obj;
+	rundcurs();
+	afficher();
+	scroll_pos = 0;
+	obj = current_spot2->object_id - 14;    //TODO
+	p_global->prevLocation = target & 0xFF;
+	deplaval((target & 0xFF00) | obj);  //TODO careful!
+}
+
+void EdenGame::visiter() {
+	bars_out();
+	playhnm(144);
+	p_global->ff_F1 = RoomFlags::rf04;
+	maj2();
+}
+
+void EdenGame::final() {
+	if (p_global->curObjectId != 0)
+		return;
+	bars_out();
+	*(short *)(gameRooms + 0x6DC) = 319; //TODO
+	p_global->roomImgBank = 319;
+	playhnm(97);
+	maj2();
+	p_global->eventType = EventType::etEvent12;
+	showevents();
+	p_global->narratorSequence = 54;
+}
+
+void EdenGame::goto_nord() {
+	if (p_global->curObjectId == 0)
+		deplacement(0);
+}
+
+void EdenGame::goto_est() {
+	if (p_global->curObjectId == 0)
+		deplacement(1);
+}
+
+void EdenGame::goto_sud() {
+	if (p_global->curObjectId == 0)
+		deplacement(2);
+}
+
+void EdenGame::goto_ouest() {
+	if (p_global->curObjectId == 0)
+		deplacement(3);
+}
+
+void EdenGame::afficher() {
+	if (!p_global->ff_102 && !p_global->ff_103) {
+		if (needPaletteUpdate) {
+			needPaletteUpdate = 0;
+			CLPalette_Send2Screen(global_palette, 0, 256);
 		}
-		debug("sea monster: room = %X, d0 = %X\n", p_global->roomNum, p_global->roomImgBank);
-		bars_out();
-		playhnm(vid);
-		maj_salle(p_global->roomNum);           //TODO: getting memory trashed here?
-		if (p_global->curObjectId == Objects::obApple)
-			loseobject(Objects::obApple);
-		p_global->eventType = EventType::etEventF;
-		showevents();
-	}
-	void gotohall() {
-		p_global->prevLocation = p_global->roomNum & 0xFF;
-		deplaval((p_global->roomNum & 0xFF00) | 6);
-	}
-	void demitourlabi() {
-		unsigned short target;
-		p_global->prevLocation = p_global->roomNum & 0xFF;
-		p_global->ff_100 = -1;
-		target = (p_global->roomNum & 0xFF00) | p_global->room_ptr->exits[2];
-		faire_suivre(target);
-		p_global->roomNum = target;
-		p_global->eventType = EventType::etEvent5;
-		maj_salle(p_global->roomNum);
-	}
-	void gotonido() {
-		p_global->room_ptr++;
-		p_global->eventType = 0;
-		p_global->roomImgBank = p_global->room_ptr->bank;
-		p_global->roomVidNum = p_global->room_ptr->video;
-		p_global->curRoomFlags = p_global->room_ptr->flags;
-		p_global->ff_F1 = p_global->room_ptr->flags;
-		animpiece();
-		p_global->ff_100 = 0;
-		maj2();
-	}
-	void gotoval() {
-		unsigned short target = p_global->roomNum;
-		char obj;
-		rundcurs();
-		afficher();
-		scroll_pos = 0;
-		obj = current_spot2->object_id - 14;    //TODO
-		p_global->prevLocation = target & 0xFF;
-		deplaval((target & 0xFF00) | obj);  //TODO careful!
-	}
-	void visiter() {
-		bars_out();
-		playhnm(144);
-		p_global->ff_F1 = RoomFlags::rf04;
-		maj2();
-	}
-	void final() {
-		if (p_global->curObjectId != 0)
-			return;
-		bars_out();
-		*(short *)(gameRooms + 0x6DC) = 319; //TODO
-		p_global->roomImgBank = 319;
-		playhnm(97);
-		maj2();
-		p_global->eventType = EventType::etEvent12;
-		showevents();
-		p_global->narratorSequence = 54;
-	}
-	void goto_nord() {
-		if (p_global->curObjectId == 0)
-			deplacement(0);
+		CLBlitter_CopyView2Screen(p_mainview);
+	} else {
+		if (p_global->ff_102)
+			effet3();
+		else
+			effet2();
+		p_global->ff_103 = 0;
+		p_global->ff_102 = 0;
 	}
-	void goto_est() {
-		if (p_global->curObjectId == 0)
-			deplacement(1);
+}
+
+void EdenGame::afficher128() {
+	if (p_global->updatePaletteFlag == 16) {
+		CLPalette_Send2Screen(global_palette, 0, 129);
+		CLBlitter_CopyView2Screen(p_mainview);
+		p_global->updatePaletteFlag = 0;
+	} else {
+		ClearScreen();
+		fadetoblack128(1);
+		if (showBlackBars)
+			blackbars();
+		CLBlitter_CopyView2Screen(p_mainview);
+		fadefromblack128(1);
 	}
-	void goto_sud() {
-		if (p_global->curObjectId == 0)
-			deplacement(2);
+}
+
+void EdenGame::sauvefrises() {
+	sauvefriseshaut(0);
+	sauvefrisesbas();
+}
+
+void EdenGame::sauvefriseshaut(short x) { // Save top bar
+	underTopBarScreenRect.sy = 0;       //TODO: wrong fields order?
+	underTopBarScreenRect.sx = x;
+	underTopBarScreenRect.ex = x + 320 - 1;
+	underTopBarScreenRect.ey = 15;
+	underTopBarBackupRect.sy = 0;
+	underTopBarBackupRect.sx = 0;
+	underTopBarBackupRect.ex = 320 - 1;
+	underTopBarBackupRect.ey = 15;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
+}
+
+void EdenGame::sauvefrisesbas() {         // Save bottom bar
+	underBottomBarScreenRect.sx = 0;
+	underBottomBarScreenRect.ex = 320 - 1;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
+}
+
+void EdenGame::restaurefrises() {
+	restaurefriseshaut();
+	restaurefrisesbas();
+}
+
+void EdenGame::restaurefriseshaut() {
+	underTopBarScreenRect.sx = scroll_pos;
+	underTopBarScreenRect.ex = scroll_pos + 320 - 1;
+	CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarBackupRect, &underTopBarScreenRect);
+}
+
+void EdenGame::restaurefrisesbas() {
+	underBottomBarScreenRect.sx = scroll_pos;
+	underBottomBarScreenRect.ex = scroll_pos + 320 - 1;
+	CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underBottomBarBackupRect, &underBottomBarScreenRect);
+}
+
+void EdenGame::use_main_bank() {
+	bank_data_ptr = main_bank_buf;
+}
+
+void EdenGame::use_bank(short bank) {
+	if (bank > 2500)
+		debug("attempt to load bad bank %d", bank);
+	bank_data_ptr = bank_data_buf;
+	if (cur_bank_num != bank) {
+		loadfile(bank, bank_data_buf);
+		verifh(bank_data_buf);
+		cur_bank_num = bank;
 	}
-	void goto_ouest() {
-		if (p_global->curObjectId == 0)
-			deplacement(3);
+}
+
+void EdenGame::sundcurs(short x, short y) {
+	unsigned char *scr, *keep = curs_keepbuf;
+	short w, h;
+	curs_keepx = x - 4;
+	curs_keepy = y - 4;
+	scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
+	for (h = 48; h--;) {
+		for (w = 48; w--;)
+			*keep++ = *scr++;
+		scr += 640 - 48;
+	}
+	curs_saved = 1;
+}
+
+void EdenGame::rundcurs() {
+	unsigned char *scr, *keep = curs_keepbuf;
+	short w, h;
+	scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
+	if (!curs_saved || (curs_keepx == -1 && curs_keepy == -1))  //TODO ...
+		return;
+	for (h = 48; h--;) {
+		for (w = 48; w--;)
+			*scr++ = *keep++;
+		scr += 640 - 48;
 	}
-	void afficher() {
-		if (!p_global->ff_102 && !p_global->ff_103) {
-			if (needPaletteUpdate) {
-				needPaletteUpdate = 0;
-				CLPalette_Send2Screen(global_palette, 0, 256);
+
+}
+
+void EdenGame::noclipax(short index, short x, short y) {
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr = p_mainview_buf + x + y * 640;
+	unsigned char h0, h1, mode;
+	short w, h;
+	if (cur_bank_num != 117 && !no_palette) {
+		if (PLE16(pix) > 2)
+			readpalette(pix + 2);
+	}
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//  short   height:9
+	//  short   pad:6;
+	//  short   flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	debug("- draw sprite %d at %d:%d, %dx%d", index, x, y, w, h);
+	if (mode != 0xFF && mode != 0xFE)
+		return;
+	if (y + h > 200)
+		h -= (y + h - 200);
+	if (h1 & 0x80) {
+		// compressed
+		for (; h-- > 0;) {
+			short ww;
+			for (ww = w; ww > 0;) {
+				unsigned char c = *pix++;
+				if (c >= 0x80) {
+					if (c == 0x80) {
+						unsigned char fill = *pix++;
+						if (fill == 0) {
+							scr += 128 + 1;
+							ww -= 128 + 1;
+						} else {
+							unsigned char run;
+							*scr++ = fill;  //TODO: wha?
+							*scr++ = fill;
+							ww -= 128 + 1;
+							for (run = 127; run--;)
+								*scr++ = fill;
+						}
+					} else {
+						unsigned char fill = *pix++;
+						unsigned char run = 255 - c + 2;
+						ww -= run;
+						if (fill == 0)
+							scr += run;
+						else
+							for (; run--;)
+								*scr++ = fill;
+					}
+				} else {
+					unsigned char run = c + 1;
+					ww -= run;
+					for (; run--;) {
+						unsigned char p = *pix++;
+						if (p == 0)
+							scr++;
+						else
+							*scr++ = p;
+					}
+				}
 			}
-			CLBlitter_CopyView2Screen(p_mainview);
-		} else {
-			if (p_global->ff_102)
-				effet3();
-			else
-				effet2();
-			p_global->ff_103 = 0;
-			p_global->ff_102 = 0;
+			scr += 640 - w;
 		}
-	}
-	void afficher128() {
-		if (p_global->updatePaletteFlag == 16) {
-			CLPalette_Send2Screen(global_palette, 0, 129);
-			CLBlitter_CopyView2Screen(p_mainview);
-			p_global->updatePaletteFlag = 0;
-		} else {
-			ClearScreen();
-			fadetoblack128(1);
-			if (showBlackBars)
-				blackbars();
-			CLBlitter_CopyView2Screen(p_mainview);
-			fadefromblack128(1);
+	} else {
+		// uncompressed
+		for (; h--;) {
+			short ww;
+			for (ww = w; ww--;) {
+				unsigned char p = *pix++;
+				if (p == 0)
+					scr++;
+				else
+					*scr++ = p;
+			}
+			scr += 640 - w;
 		}
 	}
-	void sauvefrises() {
-		sauvefriseshaut(0);
-		sauvefrisesbas();
-	}
-	void sauvefriseshaut(short x) { // Save top bar
-		underTopBarScreenRect.sy = 0;       //TODO: wrong fields order?
-		underTopBarScreenRect.sx = x;
-		underTopBarScreenRect.ex = x + 320 - 1;
-		underTopBarScreenRect.ey = 15;
-		underTopBarBackupRect.sy = 0;
-		underTopBarBackupRect.sx = 0;
-		underTopBarBackupRect.ex = 320 - 1;
-		underTopBarBackupRect.ey = 15;
-		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
-	}
-	void sauvefrisesbas() {         // Save bottom bar
-		underBottomBarScreenRect.sx = 0;
-		underBottomBarScreenRect.ex = 320 - 1;
-		CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
-	}
-	void restaurefrises() {
-		restaurefriseshaut();
-		restaurefrisesbas();
-	}
-	void restaurefriseshaut() {
-		underTopBarScreenRect.sx = scroll_pos;
-		underTopBarScreenRect.ex = scroll_pos + 320 - 1;
-		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarBackupRect, &underTopBarScreenRect);
-	}
-	void restaurefrisesbas() {
-		underBottomBarScreenRect.sx = scroll_pos;
-		underBottomBarScreenRect.ex = scroll_pos + 320 - 1;
-		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underBottomBarBackupRect, &underBottomBarScreenRect);
-	}
-	void use_main_bank() {
-		bank_data_ptr = main_bank_buf;
-	}
-	void use_bank(short bank) {
-		if (bank > 2500)
-			debug("attempt to load bad bank %d", bank);
-		bank_data_ptr = bank_data_buf;
-		if (cur_bank_num != bank) {
-			loadfile(bank, bank_data_buf);
-			verifh(bank_data_buf);
-			cur_bank_num = bank;
+}
+
+void EdenGame::noclipax_avecnoir(short index, short x, short y) {
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr = p_mainview_buf + x + y * 640;
+	unsigned char h0, h1, mode;
+	short w, h;
+	if (cur_bank_num != 117) {
+		if (PLE16(pix) > 2)
+			readpalette(pix + 2);
+	}
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//  short   height:9
+	//  short   pad:6;
+	//  short   flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	if (mode != 0xFF && mode != 0xFE)
+		return;
+	if (y + h > 200)
+		h -= (y + h - 200);
+	if (h1 & 0x80) {
+		// compressed
+		for (; h-- > 0;) {
+			short ww;
+			for (ww = w; ww > 0;) {
+				unsigned char c = *pix++;
+				if (c >= 0x80) {
+					if (c == 0x80) {
+						unsigned char fill = *pix++;
+						unsigned char run;
+						*scr++ = fill;  //TODO: wha?
+						*scr++ = fill;
+						ww -= 128 + 1;
+						for (run = 127; run--;)
+							*scr++ = fill;
+					} else {
+						unsigned char fill = *pix++;
+						unsigned char run = 255 - c + 2;
+						ww -= run;
+						for (; run--;)
+							*scr++ = fill;
+					}
+				} else {
+					unsigned char run = c + 1;
+					ww -= run;
+					for (; run--;) {
+						unsigned char p = *pix++;
+						*scr++ = p;
+					}
+				}
+			}
+			scr += 640 - w;
 		}
-	}
-	void sundcurs(short x, short y) {
-		unsigned char *scr, *keep = curs_keepbuf;
-		short w, h;
-		curs_keepx = x - 4;
-		curs_keepy = y - 4;
-		scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
-		for (h = 48; h--;) {
-			for (w = 48; w--;)
-				*keep++ = *scr++;
-			scr += 640 - 48;
+	} else {
+		// uncompressed
+		for (; h--;) {
+			short ww;
+			for (ww = w; ww--;) {
+				unsigned char p = *pix++;
+				*scr++ = p;
+			}
+			scr += 640 - w;
 		}
-		curs_saved = 1;
 	}
-	void rundcurs() {
-		unsigned char *scr, *keep = curs_keepbuf;
-		short w, h;
-		scr = p_mainview_buf + curs_keepx + curs_keepy * 640;
-		if (!curs_saved || (curs_keepx == -1 && curs_keepy == -1))  //TODO ...
-			return;
-		for (h = 48; h--;) {
-			for (w = 48; w--;)
-				*scr++ = *keep++;
-			scr += 640 - 48;
-		}
+}
 
+void EdenGame::getglow(short x, short y, short w, short h) {
+	unsigned char *scr = p_mainview_buf + x + y * 640;
+	unsigned char *gl = glow_buffer;
+	glow_x = x;
+	glow_y = y;
+	glow_w = w;
+	glow_h = h;
+	for (; h--;) {
+		short ww;
+		for (ww = w; ww--;)
+			*gl++ = *scr++;
+		scr += 640 - w;
 	}
-	void noclipax(short index, short x, short y) {
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char h0, h1, mode;
-		short w, h;
-		if (cur_bank_num != 117 && !no_palette) {
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
+}
+
+void EdenGame::unglow() {
+	unsigned char *gl = glow_buffer;
+	unsigned char *scr = p_mainview_buf + glow_x + glow_y * 640;
+	if (glow_x < 0 || glow_y < 0)   //TODO: move it up
+		return;
+	for (; glow_h--;) {
+		short ww;
+		for (ww = glow_w; ww--;)
+			*scr++ = *gl++;
+		scr += 640 - glow_w;
+	}
+}
+
+void EdenGame::glow(short index) {
+	unsigned char pixbase;
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr;
+	unsigned char h0, h1, mode;
+	short w, h, x, y, ex, dx, dy, pstride, sstride;
+	index += 9;
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//  short   height:9
+	//  short   pad:6;
+	//  short   flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	if (mode != 0xFF && mode != 0xFE)
+		return;
+
+	x = curs_x + scroll_pos - 38;
+	y = curs_y - 28;
+	ex = p_global->fresqWidth + 320;
+
+	if (x + w <= 0 || x >= ex || y + h <= 0 || y >= 176)
+		return;
+
+	if (x < 0) {
+		dx = -x;
+		x = 0;
+	} else if (x + w > ex)
+		dx = x + w - ex;
+	else
+		dx = 0;
+
+	if (y < 16) {
+		dy = 16 - y;
+		y = 16;
+	} else if (y + h > 175)
+		dy = y + h - 175;
+	else
+		dy = 0;
+	pstride = dx;
+	sstride = 640 - (w - dx);
+	if (y == 16)
+		pix += w * dy;
+	if (x == 0)
+		pix += dx;
+
+	scr = p_mainview_buf + x + y * 640;
+
+	w -= dx;
+	h -= dy;
+
+	getglow(x, y, w, h);
+
+	for (; h--;) {
+		short ww;
+		for (ww = w; ww--;) {
+			unsigned char p = *pix++;
+			if (p == 0)
+				scr++;
+			else
+				*scr++ += p << 4;
 		}
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		debug("- draw sprite %d at %d:%d, %dx%d", index, x, y, w, h);
-		if (mode != 0xFF && mode != 0xFE)
-			return;
-		if (y + h > 200)
-			h -= (y + h - 200);
-		if (h1 & 0x80) {
-			// compressed
-			for (; h-- > 0;) {
-				short ww;
-				for (ww = w; ww > 0;) {
-					unsigned char c = *pix++;
-					if (c >= 0x80) {
-						if (c == 0x80) {
-							unsigned char fill = *pix++;
-							if (fill == 0) {
-								scr += 128 + 1;
-								ww -= 128 + 1;
-							} else {
-								unsigned char run;
-								*scr++ = fill;  //TODO: wha?
-								*scr++ = fill;
-								ww -= 128 + 1;
-								for (run = 127; run--;)
-									*scr++ = fill;
-							}
-						} else {
-							unsigned char fill = *pix++;
-							unsigned char run = 255 - c + 2;
-							ww -= run;
-							if (fill == 0)
-								scr += run;
-							else
-								for (; run--;)
-									*scr++ = fill;
-						}
-					} else {
-						unsigned char run = c + 1;
-						ww -= run;
-						for (; run--;) {
-							unsigned char p = *pix++;
-							if (p == 0)
-								scr++;
-							else
-								*scr++ = p;
-						}
-					}
-				}
-				scr += 640 - w;
-			}
-		} else {
-			// uncompressed
-			for (; h--;) {
-				short ww;
-				for (ww = w; ww--;) {
-					unsigned char p = *pix++;
-					if (p == 0)
-						scr++;
-					else
-						*scr++ = p;
+		pix += pstride;
+		scr += sstride;
+	}
+}
+
+void EdenGame::readpalette(unsigned char *ptr) {
+	int doit = 1;
+	while (doit) {
+		unsigned short idx = *ptr++;
+		if (idx != 0xFF) {
+			unsigned short cnt = *ptr++;
+			while (cnt--) {
+				if (idx == 0) {
+					pal_entry.r = 0;
+					pal_entry.g = 0;
+					pal_entry.b = 0;
+					ptr += 3;
+				} else {
+					pal_entry.r = *ptr++ << 10;
+					pal_entry.g = *ptr++ << 10;
+					pal_entry.b = *ptr++ << 10;
 				}
-				scr += 640 - w;
+				CLPalette_SetRGBColor(global_palette, idx, &pal_entry);
+				idx++;
 			}
-		}
+		} else
+			doit = 0;
 	}
-	void noclipax_avecnoir(short index, short x, short y) {
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char h0, h1, mode;
-		short w, h;
-		if (cur_bank_num != 117) {
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
-		}
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		if (mode != 0xFF && mode != 0xFE)
-			return;
-		if (y + h > 200)
-			h -= (y + h - 200);
-		if (h1 & 0x80) {
-			// compressed
-			for (; h-- > 0;) {
-				short ww;
-				for (ww = w; ww > 0;) {
-					unsigned char c = *pix++;
-					if (c >= 0x80) {
-						if (c == 0x80) {
-							unsigned char fill = *pix++;
+}
+
+void EdenGame::spritesurbulle(short index, short x, short y) {
+	unsigned char *pix = bank_data_ptr;
+	unsigned char *scr = p_subtitlesview_buf + x + y * subtitles_x_width;
+	unsigned char h0, h1, mode;
+	short w, h;
+	if (cur_bank_num != 117) {
+		if (PLE16(pix) > 2)
+			readpalette(pix + 2);
+	}
+	pix += PLE16(pix);
+	pix += PLE16(pix + index * 2);
+	//  short   height:9
+	//  short   pad:6;
+	//  short   flag:1;
+	h0 = *pix++;
+	h1 = *pix++;
+	w = ((h1 & 1) << 8) | h0;
+	h = *pix++;
+	mode = *pix++;
+	if (mode != 0xFF && mode != 0xFE)
+		return;
+	if (h1 & 0x80) {
+		// compressed
+		for (; h-- > 0;) {
+			short ww;
+			for (ww = w; ww > 0;) {
+				unsigned char c = *pix++;
+				if (c >= 0x80) {
+					if (c == 0x80) {
+						unsigned char fill = *pix++;
+						if (fill == 0) {
+							scr += 128 + 1;
+							ww -= 128 + 1;
+						} else {
 							unsigned char run;
 							*scr++ = fill;  //TODO: wha?
 							*scr++ = fill;
 							ww -= 128 + 1;
 							for (run = 127; run--;)
 								*scr++ = fill;
-						} else {
-							unsigned char fill = *pix++;
-							unsigned char run = 255 - c + 2;
-							ww -= run;
-							for (; run--;)
-								*scr++ = fill;
 						}
 					} else {
-						unsigned char run = c + 1;
+						unsigned char fill = *pix++;
+						unsigned char run = 255 - c + 2;
 						ww -= run;
-						for (; run--;) {
-							unsigned char p = *pix++;
+						if (fill == 0)
+							scr += run;
+						else
+							for (; run--;)
+								*scr++ = fill;
+					}
+				} else {
+					unsigned char run = c + 1;
+					ww -= run;
+					for (; run--;) {
+						unsigned char p = *pix++;
+						if (p == 0)
+							scr++;
+						else
 							*scr++ = p;
-						}
 					}
 				}
-				scr += 640 - w;
 			}
-		} else {
-			// uncompressed
-			for (; h--;) {
-				short ww;
-				for (ww = w; ww--;) {
-					unsigned char p = *pix++;
+			scr += subtitles_x_width - w;
+		}
+	} else {
+		// uncompressed
+		for (; h--;) {
+			short ww;
+			for (ww = w; ww--;) {
+				unsigned char p = *pix++;
+				if (p == 0)
+					scr++;
+				else
 					*scr++ = p;
-				}
-				scr += 640 - w;
 			}
+			scr += subtitles_x_width - w;
 		}
 	}
-	void getglow(short x, short y, short w, short h) {
-		unsigned char *scr = p_mainview_buf + x + y * 640;
-		unsigned char *gl = glow_buffer;
-		glow_x = x;
-		glow_y = y;
-		glow_w = w;
-		glow_h = h;
-		for (; h--;) {
-			short ww;
-			for (ww = w; ww--;)
-				*gl++ = *scr++;
-			scr += 640 - w;
+}
+
+void EdenGame::bars_out() {
+	short i, r19, r20, r25, r24;
+	unsigned int *scr40, *scr41, *scr42;
+	if (showBlackBars)
+		return;
+	afficher();
+	underTopBarScreenRect.sx = scroll_pos;
+	underTopBarScreenRect.ex = scroll_pos + 320 - 1;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underTopBarScreenRect, &underTopBarBackupRect);
+	underBottomBarScreenRect.sx = underTopBarScreenRect.sx;
+	underBottomBarScreenRect.ex = underTopBarScreenRect.ex;
+	CLBlitter_CopyViewRect(p_mainview, p_underBarsView, &underBottomBarScreenRect, &underBottomBarBackupRect);
+	r19 = 14;   // TODO - init in decl?
+	r20 = 176;
+	r25 = 14;
+	r24 = 21;
+	underTopBarScreenRect.sx = 0;
+	underTopBarScreenRect.ex = 320 - 1;
+	underTopBarBackupRect.sx = scroll_pos;
+	underTopBarBackupRect.ex = scroll_pos + 320 - 1;
+	while (r24 > 0) {
+		if (r25 > 0) {
+			underTopBarScreenRect.sy = 16 - r25;
+			underTopBarScreenRect.ey = 16 - 1;
+			underTopBarBackupRect.sy = 0;
+			underTopBarBackupRect.ey = r25 - 1;
+			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+			scr40 = ((unsigned int *)p_mainview_buf) + r19 * 640 / 4;
+			scr41 = scr40 + 640 / 4;
+			for (i = 0; i < 320; i += 4) {
+				*scr40++ = 0;
+				*scr41++ = 0;
+			}
+		}
+		underTopBarScreenRect.sy = 16;
+		underTopBarScreenRect.ey = r24 + 16 - 1;
+		underTopBarBackupRect.sy = 200 - r24;
+		underTopBarBackupRect.ey = 200 - 1;
+		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+		scr40 = ((unsigned int *)p_mainview_buf) + r20 * 640 / 4;
+		scr41 = scr40 + 640 / 4;
+		scr42 = scr41 + 640 / 4;
+		for (i = 0; i < 320; i += 4) {
+			*scr40++ = 0;
+			*scr41++ = 0;
+			*scr42++ = 0;
 		}
+		r19 -= 2;
+		r20 += 3;
+		r25 -= 2;
+		r24 -= 3;
+		afficher();
 	}
-	void unglow() {
-		unsigned char *gl = glow_buffer;
-		unsigned char *scr = p_mainview_buf + glow_x + glow_y * 640;
-		if (glow_x < 0 || glow_y < 0)   //TODO: move it up
-			return;
-		for (; glow_h--;) {
-			short ww;
-			for (ww = glow_w; ww--;)
-				*scr++ = *gl++;
-			scr += 640 - glow_w;
+	scr40 = (unsigned int *)p_mainview_buf;
+	scr41 = scr40 + 640 / 4;
+	for (i = 0; i < 320; i += 4) {
+		*scr40++ = 0;
+		*scr41++ = 0;
+	}
+	scr40 = ((unsigned int *)p_mainview_buf) + r20 * 640 / 4;
+	scr41 = scr40 + 640 / 4;
+	scr42 = scr41 + 640 / 4;
+	for (i = 0; i < 320; i += 4) {
+		*scr40++ = 0;
+		*scr41++ = 0;
+		*scr42++ = 0;
+	}
+	afficher();
+	initrect();
+	showBlackBars = 1;
+}
+
+void EdenGame::bars_in() {
+	short r29, r28;
+	if (!showBlackBars)
+		return;
+	blackbars();
+	r29 = 2;
+	r28 = 2;
+	underTopBarScreenRect.sx = 0;
+	underTopBarScreenRect.ex = 320 - 1;
+	underTopBarBackupRect.sx = scroll_pos;
+	underTopBarBackupRect.ex = scroll_pos + 320 - 1;
+	while (r28 < 24) {
+		if (r29 <= 16) {
+			underTopBarScreenRect.sy = 16 - r29;
+			underTopBarScreenRect.ey = 16 - 1;
+			underTopBarBackupRect.sy = 0;
+			underTopBarBackupRect.ey = r29 - 1;
+			CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
 		}
+		underTopBarScreenRect.sy = 16;
+		underTopBarScreenRect.ey = 16 + r28;
+		underTopBarBackupRect.sy = 200 - 1 - r28;
+		underTopBarBackupRect.ey = 200 - 1;
+		CLBlitter_CopyViewRect(p_underBarsView, p_mainview, &underTopBarScreenRect, &underTopBarBackupRect);
+		r29 += 2;
+		r28 += 3;
+		afficher();
 	}
-	void glow(short index) {
-		unsigned char pixbase;
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr;
-		unsigned char h0, h1, mode;
-		short w, h, x, y, ex, dx, dy, pstride, sstride;
-		index += 9;
-		pix += PLE16(pix);
-		pix += PLE16(pix + index * 2);
-		//  short   height:9
-		//  short   pad:6;
-		//  short   flag:1;
-		h0 = *pix++;
-		h1 = *pix++;
-		w = ((h1 & 1) << 8) | h0;
-		h = *pix++;
-		mode = *pix++;
-		if (mode != 0xFF && mode != 0xFE)
-			return;
+	initrect();
+	showBlackBars = 0;
+}
 
-		x = curs_x + scroll_pos - 38;
-		y = curs_y - 28;
-		ex = p_global->fresqWidth + 320;
+void EdenGame::sauvefondbouche() {
+	rect_src.sx = cur_perso_rect->sx;
+	rect_src.sy = cur_perso_rect->sy;
+	rect_src.ex = cur_perso_rect->ex;
+	rect_src.ey = cur_perso_rect->ey;
+	rect_dst.sx = cur_perso_rect->sx + 320;
+	rect_dst.sy = cur_perso_rect->sy;
+	rect_dst.ex = cur_perso_rect->ex + 320;
+	rect_dst.ey = cur_perso_rect->ey;
+	CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_src, &rect_dst);
+	fond_saved = 1;
+}
 
-		if (x + w <= 0 || x >= ex || y + h <= 0 || y >= 176)
-			return;
+void EdenGame::restaurefondbouche() {
+	rect_src.sx = cur_perso_rect->sx;
+	rect_src.sy = cur_perso_rect->sy;
+	rect_src.ex = cur_perso_rect->ex;
+	rect_src.ey = cur_perso_rect->ey;
+	rect_dst.sx = cur_perso_rect->sx + 320;
+	rect_dst.sy = cur_perso_rect->sy;
+	rect_dst.ex = cur_perso_rect->ex + 320;
+	rect_dst.ey = cur_perso_rect->ey;
+	CLBlitter_CopyViewRect(p_mainview, p_mainview, &rect_dst, &rect_src);
+}
 
-		if (x < 0) {
-			dx = -x;
-			x = 0;
-		} else if (x + w > ex)
-			dx = x + w - ex;
-		else
-			dx = 0;
+void EdenGame::blackbars() {
+	unsigned char *scr = p_mainview_buf;
+	short x, y;
+	for (y = 0; y < 16; y++)
+		for (x = 0; x < 640; x++)
+			*scr++ = 0;
+	scr += 640 * (200 - 16 - 24);
+	for (y = 0; y < 24; y++)
+		for (x = 0; x < 640; x++)
+			*scr++ = 0;
+}
 
-		if (y < 16) {
-			dy = 16 - y;
-			y = 16;
-		} else if (y + h > 175)
-			dy = y + h - 175;
-		else
-			dy = 0;
-		pstride = dx;
-		sstride = 640 - (w - dx);
-		if (y == 16)
-			pix += w * dy;
-		if (x == 0)
-			pix += dx;
+void EdenGame::afftopscr() {  // Draw  top bar (location / party / map)
+	perso_t *perso;
+	p_global->drawFlags &= ~DrawFlags::drDrawTopScreen;
+	use_bank(314);
+	noclipax(36, 83, 0);
+	noclipax(p_global->area_ptr->num - 1, 0, 0);
+	noclipax(23, 145, 0);
+	for (perso = &kPersons[PER_DINA]; perso != &kPersons[PER_UNKN_156]; perso++) {
+		if ((perso->flags & PersonFlags::pfInParty) && !(perso->flags & PersonFlags::pf80))
+			noclipax(perso->targetLoc + 18, perso->lastLoc + 120, 0);
+	}
+	saved_repadam.x = -1;
+	saved_repadam.y = -1;
+	affplanval();
+	needPaletteUpdate = 1;
+}
 
-		scr = p_mainview_buf + x + y * 640;
+void EdenGame::affplanval() { // Draw mini-map
+	short loc;
+	perso_t *perso;
+	if (p_global->area_ptr->type == AreaType::atValley) {
+		noclipax(p_global->area_ptr->num + 9, 266, 1);
+		for (perso = &kPersons[PER_UNKN_18C]; perso->roomNum != 0xFFFF; perso++) {
+			if (((perso->roomNum >> 8) == p_global->areaNum)
+			        && !(perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pf20))
+				affrepere(33, perso->roomNum & 0xFF);
+		}
+		if (p_global->area_ptr->citadelLevel)
+			affrepere(34, p_global->area_ptr->citadelRoom->location);
+		sauvefriseshaut(0);
+		loc = p_global->roomNum & 0xFF;
+		if (loc >= 16)
+			affrepereadam(loc);
+		restaurefriseshaut();
+	} else {
+		sauvefriseshaut(0);
+		restaurefriseshaut();
+	}
+}
 
-		w -= dx;
-		h -= dy;
+void EdenGame::affrepere(short index, short location) {
+	noclipax(index, 269 + location % 16 * 4, 2 + (location - 16) / 16 * 3);
+}
 
-		getglow(x, y, w, h);
+void EdenGame::affrepereadam(short location) {
+	short x = 269;
+	short y = 2;
+	short w;
+	unsigned char *pix;
+	rest_repadam();
+	if (location > 15 && location < 76) {
+		x += (location & 15) * 4;
+		y += ((location - 16) >> 4) * 3;
+		save_repadam(x, y);
+		pix = p_underBarsView->p_buffer;
+		w = p_underBarsView->width;
+		pix += x + w * y;
+		pix[1] = 0xC3;
+		pix[2] = 0xC3;
+		pix += w;
+		pix[0] = 0xC3;
+		pix[1] = 0xC3;
+		pix[2] = 0xC3;
+		pix[3] = 0xC3;
+		pix += w;
+		pix[1] = 0xC3;
+		pix[2] = 0xC3;
+	}
+}
 
-		for (; h--;) {
-			short ww;
-			for (ww = w; ww--;) {
-				unsigned char p = *pix++;
-				if (p == 0)
-					scr++;
-				else
-					*scr++ += p << 4;
-			}
-			pix += pstride;
-			scr += sstride;
+void EdenGame::rest_repadam() {
+	short x, y, w;
+	unsigned char *pix;
+	if (saved_repadam.x == -1 && saved_repadam.y == -1)
+		return;
+	x = saved_repadam.x;
+	y = saved_repadam.y;
+	pix = p_underBarsView->p_buffer;
+	w = p_underBarsView->width;
+	pix += x + w * y;
+	pix[1] = keep01;    //TODO keep is array?
+	pix[2] = keep02;
+	pix += w;
+	pix[0] = keep10;
+	pix[1] = keep11;
+	pix[2] = keep12;
+	pix[3] = keep13;
+	pix += w;
+	pix[1] = keep21;
+	pix[2] = keep22;
+}
+
+void EdenGame::save_repadam(short x, short y) {
+	short w;
+	unsigned char *pix;
+	saved_repadam.x = x;
+	saved_repadam.y = y;
+	pix = p_underBarsView->p_buffer;
+	w = p_underBarsView->width;
+	pix += x + w * y;
+	keep01 = pix[1];
+	keep02 = pix[2];
+	pix += w;
+	keep10 = pix[0];
+	keep11 = pix[1];
+	keep12 = pix[2];
+	keep13 = pix[3];
+	pix += w;
+	keep21 = pix[1];
+	keep22 = pix[2];
+}
+
+char EdenGame::istrice(short roomNum) {
+	char loc = roomNum & 0xFF;
+	short area = roomNum & 0xFF00;
+	perso_t *perso;
+	for (perso = &kPersons[PER_UNKN_18C]; perso != &kPersons[PER_UNKN_372]; perso++) {
+		if ((perso->flags & PersonFlags::pf80) || (perso->flags & PersonFlags::pfTypeMask) != PersonFlags::pftTriceraptor)
+			continue;
+		if (perso->roomNum == (area | (loc - 16)))
+			return 1;
+		if (perso->roomNum == (area | (loc + 16)))
+			return 1;
+		if (perso->roomNum == (area | (loc - 1)))
+			return 1;
+		if (perso->roomNum == (area | (loc + 1)))
+			return 1;
+	}
+	return 0;
+}
+
+char EdenGame::istyran(short roomNum) {
+	char loc = roomNum & 0xFF;
+	short area = roomNum & 0xFF00;
+	// TODO: orig bug: this ptr is not initialized when first called from getsalle
+	// PC version scans kPersons[] directly and is not affected
+	if (!tyranPtr)
+		return 0;
+
+	for (; tyranPtr->roomNum != 0xFFFF; tyranPtr++) {
+		if (tyranPtr->flags & PersonFlags::pf80)
+			continue;
+		if (tyranPtr->roomNum == (area | (loc - 16)))
+			return 1;
+		if (tyranPtr->roomNum == (area | (loc + 16)))
+			return 1;
+		if (tyranPtr->roomNum == (area | (loc - 1)))
+			return 1;
+		if (tyranPtr->roomNum == (area | (loc + 1)))
+			return 1;
+	}
+	return 0;
+}
+
+void EdenGame::istyranval(area_t *area) {
+	perso_t *perso;
+	unsigned char areaNum = area->num;
+	area->flags &= ~AreaFlags::HasTyrann;
+	for (perso = &kPersons[PER_UNKN_372]; perso->roomNum != 0xFFFF; perso++) {
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if ((perso->roomNum >> 8) == areaNum) {
+			area->flags |= AreaFlags::HasTyrann;
+			break;
 		}
 	}
-	void readpalette(unsigned char *ptr) {
-		int doit = 1;
-		while (doit) {
-			unsigned short idx = *ptr++;
-			if (idx != 0xFF) {
-				unsigned short cnt = *ptr++;
-				while (cnt--) {
-					if (idx == 0) {
-						pal_entry.r = 0;
-						pal_entry.g = 0;
-						pal_entry.b = 0;
-						ptr += 3;
-					} else {
-						pal_entry.r = *ptr++ << 10;
-						pal_entry.g = *ptr++ << 10;
-						pal_entry.b = *ptr++ << 10;
-					}
-					CLPalette_SetRGBColor(global_palette, idx, &pal_entry);
-					idx++;
-				}
-			} else
-				doit = 0;
+}
+
+char EdenGame::getdirection(perso_t *perso) {
+	char dir = -1;
+	unsigned char trgLoc = perso->targetLoc;
+	unsigned char curLoc = perso->roomNum & 0xFF;   //TODO name
+	if (curLoc != trgLoc) {
+		curLoc &= 0xF;
+		trgLoc &= 0xF;
+		if (curLoc != trgLoc) {
+			dir = 2;
+			if (curLoc > trgLoc)
+				dir = 5;
+		}
+		trgLoc = perso->targetLoc;
+		curLoc = perso->roomNum & 0xFF;
+		curLoc &= 0xF0;
+		trgLoc &= 0xF0;
+		if (curLoc != trgLoc) {
+			if (curLoc > trgLoc)
+				dir++;
+			dir++;
 		}
 	}
-	void spritesurbulle(short index, short x, short y) {
-		unsigned char *pix = bank_data_ptr;
-		unsigned char *scr = p_subtitlesview_buf + x + y * subtitles_x_width;
-		unsigned char h0, h1, mode;
-		short w, h;
-		if (cur_bank_num != 117) {
-			if (PLE16(pix) > 2)
-				readpalette(pix + 2);
+	return dir;
+}
+
+char EdenGame::caselibre(char loc, perso_t *perso) {
+	short roomNum;
+	room_t *room = p_global->cita_area_firstRoom;
+	if (loc <= 0x10 || loc > 76 || (loc & 0xF) >= 12 || loc == perso->lastLoc)
+		return 0;
+	roomNum = (perso->roomNum & ~0xFF) | loc;   //TODO: danger! signed
+	if (roomNum == p_global->roomNum)
+		return 0;
+	for (; room->ff_0 != 0xFF; room++) {
+		if (room->location != loc)
+			continue;
+		if (!(room->flags & RoomFlags::rf01))
+			return 0;
+		for (perso = &kPersons[PER_UNKN_18C]; perso->roomNum != 0xFFFF; perso++) {
+			if (perso->flags & PersonFlags::pf80)
+				continue;
+			if (perso->roomNum == roomNum)
+				break;
 		}
+		if (perso->roomNum != 0xFFFF)
+			return 0;
+		return 1;
+	}
+	return 0;
+}
+
+void EdenGame::melange1(char elem[4]) {
+	if (g_ed->_rnd->getRandomNumber(1) & 1) {
+		char e1 = elem[1];
+		char e2 = elem[2];
+		elem[1] = e2;
+		elem[2] = e1;
+	}
+}
+
+void EdenGame::melange2(char elem[4]) {
+	if (g_ed->_rnd->getRandomNumber(1) & 1) {
+		char e0 = elem[0];
+		char e1 = elem[1];
+		elem[0] = e1;
+		elem[1] = e0;
+	}
+	if (g_ed->_rnd->getRandomNumber(1) & 1) {
+		char e2 = elem[2];
+		char e3 = elem[3];
+		elem[2] = e3;
+		elem[3] = e2;
+	}
+}
+
+void EdenGame::melangedir() {
+	melange1(tab_2CB1E[0]);
+	melange1(tab_2CB1E[1]);
+	melange1(tab_2CB1E[2]);
+	melange2(tab_2CB1E[3]);
+	melange2(tab_2CB1E[4]);
+	melange1(tab_2CB1E[5]);
+	melange2(tab_2CB1E[6]);
+	melange2(tab_2CB1E[7]);
+}
+
+char EdenGame::naitredino(char persoType) {
+	perso_t *perso;
+	for (perso = &kPersons[PER_MORKUS]; (++perso)->roomNum != 0xFFFF;) {
+		char areaNum = perso->roomNum >> 8;
+		if (areaNum != p_global->cita_area_num)
+			continue;
+		if ((perso->flags & PersonFlags::pf80) && (perso->flags & PersonFlags::pfTypeMask) == persoType) {
+			perso->flags &= ~PersonFlags::pf80;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+void EdenGame::newcita(char arg1, short arg2, room_t *room) {
+	unsigned short index;
+	short *ptr;
+	cita_t *cita = cita_list;
+	while (cita->ff_0 < arg2)
+		cita++;
+	index = ((room->flags & 0xC0) >> 6);    //TODO: this is very wrong
+	ptr = cita->ff_2 + index * 2;
+	if (arg1 == 4 || arg1 == 6)
+		ptr++;
+	room->bank = ptr[0];
+	room->video = ptr[8];
+	room->flags |= RoomFlags::rf02;
+}
+
+void EdenGame::citaevol(short level) {
+	room_t *room = p_global->cur_area_ptr->citadelRoom;
+	perso_t *perso = &kPersons[PER_UNKN_372];
+	unsigned char speed, loc = room->location;
+	if (level >= 80 && !istrice((p_global->cita_area_num << 8) | room->location)) { //TODO: loc ?
+		room->level = 79;
+		return;
+	}
+	if (level > 160)
+		level = 160;
+	if (room->level < 64 && level >= 64 && naitredino(PersonFlags::pftTriceraptor)) {
+		p_global->cur_area_ptr->flags |= AreaFlags::HasTriceraptors;
+		ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+	}
+	if (room->level < 40 && level >= 40 && naitredino(PersonFlags::pftVelociraptor)) {
+		p_global->cur_area_ptr->flags |= AreaFlags::HasVelociraptors;
+		ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsIn);
+	}
+	room->level = level;
+	newcita(p_global->cita_area_num, level, room);
+	speed = kDinoSpeedForCitaLevel[room->level >> 4];
+	for (; perso->roomNum != 0xFFFF; perso++) {
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if ((perso->roomNum >> 8) == p_global->cita_area_num && perso->targetLoc == loc)
+			perso->speed = speed;
+	}
+}
+
+void EdenGame::citacapoute(short roomNum) {
+	perso_t *perso = &kPersons[PER_UNKN_18C];
+	room_t *room = p_global->cur_area_ptr->citadelRoom;
+	room->flags |= RoomFlags::rf01;
+	room->flags &= ~RoomFlags::rfHasCitadel;
+	room->bank = 193;
+	room->video = 0;
+	room->level = 0;
+	p_global->cur_area_ptr->citadelLevel = 0;
+	p_global->cur_area_ptr->citadelRoom = 0;
+	roomNum = (roomNum & ~0xFF) | room->location;
+	for (; perso->roomNum != 0xFFFF; perso++) {
+		if (perso->roomNum == roomNum) {
+			perso->flags &= ~PersonFlags::pf80;
+			delinfo((roomNum >> 8) + ValleyNews::vnTyrannIn);
+			break;
+		}
+	}
+}
+
+void EdenGame::buildcita() {
+	area_t *area = p_global->area_ptr;
+	p_global->cur_area_ptr = p_global->area_ptr;
+	if (area->citadelRoom)
+		citacapoute(p_global->roomNum);
+	p_global->ff_6A = p_global->ff_69;
+	p_global->narratorSequence = p_global->ff_69 | 0x80;
+	area->citadelRoom = p_global->room_ptr;
+	p_global->room_ptr->flags &= ~RoomFlags::rf01;
+	p_global->room_ptr->flags |= RoomFlags::rfHasCitadel;
+	p_global->room_ptr->level = 32;
+	newcita(p_global->areaNum, 32, p_global->room_ptr);
+	area->flags &= ~AreaFlags::TyrannSighted;
+	if (!(area->flags & AreaFlags::afFlag8000)) {
+		if (p_global->phaseNum == 304 || p_global->phaseNum != 384) //TODO: wha
+			eloirevient();
+		area->flags |= AreaFlags::afFlag8000;
+	}
+	p_global->room_perso->flags |= PersonFlags::pf80;
+	p_global->cita_area_num = p_global->areaNum;
+	naitredino(1);
+	delinfo(p_global->areaNum + ValleyNews::vnCitadelLost);
+	delinfo(p_global->areaNum + ValleyNews::vnTyrannLost);
+	if (p_global->phaseNum == 193 && p_global->areaNum == Areas::arUluru)
+		bigphase1();
+}
+
+void EdenGame::citatombe(char level) {
+	if (level)
+		newcita(p_global->cita_area_num, level, p_global->cur_area_ptr->citadelRoom);
+	else {
+		citacapoute(p_global->cita_area_num << 8);
+		ajouinfo(p_global->cita_area_num + ValleyNews::vnCitadelLost);
+	}
+}
+
+void EdenGame::constcita() {
+	unsigned char level;
+	room_t *room;
+	unsigned char loc;
+	//	room_t *room = p_global->cur_area_ptr->room_ptr; //TODO: wrong? chk below
+	//	unsigned char id = room->ff_C;
+	if (!p_global->cur_area_ptr->citadelLevel || !p_global->cur_area_ptr->citadelRoom)
+		return;
+	room = p_global->cur_area_ptr->citadelRoom; //TODO: copied here by me
+	loc = room->location;
+	tyranPtr = &kPersons[PER_UNKN_372];
+	if (istyran((p_global->cita_area_num << 8) | loc)) {
+		if (!(p_global->cur_area_ptr->flags & AreaFlags::TyrannSighted)) {
+			ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
+			p_global->cur_area_ptr->flags |= AreaFlags::TyrannSighted;
+		}
+		level = room->level - 1;
+		if (level < 32)
+			level = 32;
+		room->level = level;
+		citatombe(level);
+	} else {
+		p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+		citaevol(room->level + 1);
+	}
+}
+
+void EdenGame::depladino(perso_t *perso) {
+	char *dirs, dir, dir2;
+	unsigned char loc;
+	dir = getdirection(perso);
+	if (dir != -1) {
+		melangedir();
+		dirs = tab_2CB1E[dir];
+		loc = perso->roomNum & 0xFF;
+		dir2 = *dirs++;
+		if (dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = *dirs++;
+		if (dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = *dirs++;
+		if (dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = *dirs++;
+		if (dir2 & 0x80)
+			dir2 = -(dir2 & ~0x80);
+		dir2 += loc;
+		if (caselibre(dir2, perso))
+			goto ok;
+		dir2 = perso->lastLoc;
+		perso->lastLoc = 0;
+		if (!caselibre(dir2, perso))
+			return;
+	ok:
+		;
+		perso->lastLoc = perso->roomNum & 0xFF;
+		perso->roomNum &= ~0xFF;
+		perso->roomNum |= dir2 & 0xFF;
+		if (perso->targetLoc - 16 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+		if (perso->targetLoc + 16 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+		if (perso->targetLoc - 1 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+		if (perso->targetLoc + 1 == (perso->roomNum & 0xFF))
+			perso->targetLoc = 0;
+	} else
+		perso->targetLoc = 0;
+}
+
+void EdenGame::deplaalldino() {
+	perso_t *perso = &kPersons[PER_UNKN_18C - 1];   //TODO fix this
+	while ((++perso)->roomNum != 0xFFFF) {
+		if (((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
+			continue;
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		if (!perso->targetLoc)
+			continue;
+		if (--perso->steps)
+			continue;
+		perso->steps = 1;
+		if (perso->roomNum == p_global->roomNum)
+			continue;
+		perso->steps = perso->speed;
+		depladino(perso);
+	}
+}
+
+void EdenGame::newvallee() {
+	perso_t *perso = &kPersons[PER_UNKN_372];
+	short *ptr = tab_2CB16;
+	short roomNum;
+	while ((roomNum = *ptr++) != -1) {
+		perso->roomNum = roomNum;
+		perso->flags &= ~PersonFlags::pf80;
+		perso->flags &= ~PersonFlags::pf20; //TODO: combine?
+		perso++;
+	}
+	perso->roomNum = -1;
+	kAreasTable[7].flags |= AreaFlags::HasTyrann;
+	p_global->worldHasTyrann = 32;
+}
+
+char EdenGame::whereiscita() {
+	room_t *room = p_global->cita_area_firstRoom;
+	char res = -1;
+	for (; room->ff_0 != 0xFF; room++) {
+		if (!(room->flags & RoomFlags::rfHasCitadel))
+			continue;
+		res = room->location;
+		break;
+	}
+	return res;
+}
+
+char EdenGame::iscita(short loc) {
+	room_t *room = p_global->cita_area_firstRoom;
+	loc &= 0xFF;
+	for (; room->ff_0 != 0xFF; room++) {
+		if (!(room->flags & RoomFlags::rfHasCitadel))
+			continue;
+		if (room->location == loc + 16)
+			return 1;
+		if (room->location == loc - 16)
+			return 1;
+		if (room->location == loc - 1)
+			return 1;
+		if (room->location == loc + 1)
+			return 1;
+	}
+	return 0;
+}
+
+void EdenGame::lieuvava(area_t *area) {
+	unsigned char mask;
+	if (area->type == AreaType::atValley) {
+		istyranval(area);
+		area->citadelLevel = 0;
+		if (area->citadelRoom)
+			area->citadelLevel = p_global->cita_area_firstRoom->level;  //TODO: no search?
+		mask = ~(1 << (area->num - Areas::arChamaar));
+		p_global->worldTyrannSighted &= mask;
+		p_global->ff_4E &= mask;
+		p_global->worldGaveGold &= mask;
+		p_global->worldHasVelociraptors &= mask;
+		p_global->worldHasTriceraptors &= mask;
+		p_global->worldHasTyrann &= mask;
+		p_global->ff_53 &= mask;
+		mask = ~mask;
+		if (area->flags & AreaFlags::TyrannSighted)
+			p_global->worldTyrannSighted |= mask;
+		if (area->flags & AreaFlags::afFlag4)
+			p_global->ff_4E |= mask;
+		if (area->flags & AreaFlags::HasTriceraptors)
+			p_global->worldHasTriceraptors |= mask;
+		if (area->flags & AreaFlags::afGaveGold)
+			p_global->worldGaveGold |= mask;
+		if (area->flags & AreaFlags::HasVelociraptors)
+			p_global->worldHasVelociraptors |= mask;
+		if (area->flags & AreaFlags::HasTyrann)
+			p_global->worldHasTyrann |= mask;
+		if (area->flags & AreaFlags::afFlag20)
+			p_global->ff_53 |= mask;
+		if (area == p_global->area_ptr) {
+			p_global->curAreaFlags = area->flags;
+			p_global->curCitadelLevel = area->citadelLevel;
+		}
+	}
+	p_global->ff_4D &= p_global->worldTyrannSighted;
+}
+
+void EdenGame::vivredino() {
+	char cita;
+	perso_t *perso = &kPersons[PER_UNKN_18C];
+	for (; perso->roomNum != 0xFFFF; perso++) {
+		if (((perso->roomNum >> 8) & 0xFF) != p_global->cita_area_num)
+			continue;
+		if (perso->flags & PersonFlags::pf80)
+			continue;
+		switch (perso->flags & PersonFlags::pfTypeMask) {
+		case PersonFlags::pftTyrann:
+			if (iscita(perso->roomNum))
+				perso->targetLoc = 0;
+			else if (!perso->targetLoc) {
+				cita = whereiscita();
+				if (cita != -1) {
+					perso->targetLoc = cita;
+					perso->speed = 2;
+					perso->steps = 1;
+				}
+			}
+			break;
+		case PersonFlags::pftTriceraptor:
+			if (perso->flags & PersonFlags::pfInParty) {
+				if (iscita(perso->roomNum))
+					perso->targetLoc = 0;
+				else if (!perso->targetLoc) {
+					cita = whereiscita();
+					if (cita != -1) {
+						perso->targetLoc = cita;
+						perso->speed = 3;
+						perso->steps = 1;
+					}
+				}
+			}
+			break;
+		case PersonFlags::pftVelociraptor:
+			if (perso->flags & PersonFlags::pf10) {
+				if (perso->roomNum == p_global->roomNum) {
+					perso_t *perso2 = &kPersons[PER_UNKN_372];
+					char found = 0;
+					for (; perso2->roomNum != 0xFFFF; perso2++) {
+						if ((perso->roomNum & ~0xFF) == (perso2->roomNum & ~0xFF)) {
+							if (perso2->flags & PersonFlags::pf80)
+								continue;
+							perso->targetLoc = perso2->roomNum & 0xFF;
+							perso->steps = 1;
+							found = 1;
+							break;
+						}
+					}
+					if (found)
+						continue;
+				} else {
+					tyranPtr = &kPersons[PER_UNKN_372];
+					if (istyran(perso->roomNum)) {
+						if (p_global->phaseNum < 481 && (perso->powers & (1 << (p_global->cita_area_num - 3)))) {
+							tyranPtr->flags |= PersonFlags::pf80;
+							tyranPtr->roomNum = 0;
+							perso->flags &= ~PersonFlags::pf10;
+							perso->flags |= PersonFlags::pfInParty;
+							ajouinfo(p_global->cita_area_num + ValleyNews::vnTyrannLost);
+							delinfo(p_global->cita_area_num + ValleyNews::vnTyrannIn);
+							if (naitredino(PersonFlags::pftTriceraptor))
+								ajouinfo(p_global->cita_area_num + ValleyNews::vnTriceraptorsIn);
+							constcita();
+							p_global->cur_area_ptr->flags &= ~AreaFlags::TyrannSighted;
+						} else {
+							perso->flags &= ~PersonFlags::pf10;
+							perso->flags &= ~PersonFlags::pfInParty;
+							ajouinfo(p_global->cita_area_num + ValleyNews::vnVelociraptorsLost);
+						}
+						continue;
+					}
+				}
+			}
+			if (!perso->targetLoc) {
+				short loc;
+				perso->lastLoc = 0;
+				do {
+					loc = (g_ed->_rnd->getRandomNumber(63) & 63) + 16;
+					if ((loc & 0xF) >= 12)
+						loc &= ~4;  //TODO: ??? same as -= 4
+				} while (!caselibre(loc, perso));
+				perso->targetLoc = loc;
+				perso->steps = 1;
+			}
+			break;
+		}
+	}
+}
+
+void EdenGame::vivreval(short areaNum) {
+	p_global->cita_area_num = areaNum;
+	p_global->cur_area_ptr = &kAreasTable[areaNum - 1];
+	p_global->cita_area_firstRoom = &gameRooms[p_global->cur_area_ptr->firstRoomIndex];
+	deplaalldino();
+	constcita();
+	vivredino();
+	newchampi();
+	newnido();
+	newnidv();
+	if (p_global->phaseNum >= 226)
+		newor();
+	lieuvava(p_global->cur_area_ptr);
+}
+
+void EdenGame::chaquejour() {
+	vivreval(3);
+	vivreval(4);
+	vivreval(5);
+	vivreval(6);
+	vivreval(7);
+	vivreval(8);
+	p_global->drawFlags |= DrawFlags::drDrawTopScreen;
+}
+
+void EdenGame::temps_passe(short t) {
+	short days = p_global->gameDays;
+	short lo = p_global->ff_56;
+	lo += t;
+	if (lo > 255) {
+		days++;
+		lo &= 0xFF;
+	}
+	p_global->ff_56 = lo;
+	t = ((t >> 8) & 0xFF) + days;
+	t -= p_global->gameDays;
+	if (t) {
+		p_global->gameDays += t;
+		while (t--)
+			chaquejour();
+	}
+}
+
+void EdenGame::heurepasse() {
+	temps_passe(5);
+}
+
+void EdenGame::anim_perso() {
+	if (cur_bank_num != p_global->perso_img_bank)
+		load_perso(p_global->perso_ptr);
+	restaurefondbulle();
+	if (restartAnimation) {
+		last_anim_ticks = TimerTicks;
+		restartAnimation = 0;
+	}
+	cur_anim_frame_num = (TimerTicks - last_anim_ticks) >> 2;   // TODO: check me!!!
+	if (cur_anim_frame_num > num_anim_frames)               // TODO: bug?
+		animateTalking = 0;
+	if (p_global->curPersoAnimPtr && !p_global->animationFlags && cur_anim_frame_num != last_anim_frame_num) {
+		last_anim_frame_num = cur_anim_frame_num;
+		if (*p_global->curPersoAnimPtr == 0xFF)
+			getanimrnd();
+		bank_data_ptr = perso_img_bank_data_ptr;
+		num_img_desc = 0;
+		perso_spr(p_global->curPersoAnimPtr);
+		p_global->curPersoAnimPtr += num_img_desc + 1;
+		dword_3072C = imagedesc + 200;
+		virespritebouche();
+		if (*dword_3072C)
+			af_image();
+		animationDelay--;
+		if (!animationDelay) { //TODO: combine
+			p_global->animationFlags = 1;
+			animationDelay = 8;
+		}
+	}
+
+	animationDelay--;
+	if (!animationDelay) { //TODO: combine
+		getanimrnd();
+		//TODO: no reload?
+	}
+	if (animateTalking) {
+		if (!animationTable) {
+			animationTable = gameLipsync + 7262;    //TODO: fix me
+			if (!fond_saved)
+				sauvefondbouche();
+		}
+		if (!personTalking)
+			cur_anim_frame_num = num_anim_frames - 1;
+		animationIndex = animationTable[cur_anim_frame_num];
+		if (animationIndex == 0xFF)
+			animateTalking = 0;
+		else if (animationIndex != lastAnimationIndex) {
+			bank_data_ptr = perso_img_bank_data_ptr;
+			restaurefondbouche();
+//			debug("perso spr %d", animationIndex);
+			perso_spr(p_global->persoSpritePtr2