[Scummvm-git-logs] scummvm master -> 94ddf526f43068925ca914f60934cf5ad53371cf

sev- sev at scummvm.org
Thu Jul 13 18:28:54 CEST 2017


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

Summary:
94439e2ce3 SLUDGE: Add first classes in scummvm to detect .slg game file
219044abf9 SLUDGE: Add sludge files and make it compile
c4a5af22ea SLUDGE: Add namespace
f2d81f6f5d SLUDGE: Add new debug channels
1aa64b5b0f SLUDGE: Add namespace for file version.h
f5b4cf6803 SLUDGE: Remove inner include of vorbis library
45dcfdfc0b SLUDGE: Replace standard file reading functions by Common functions
f8ca5d14c4 SLUDGE: Replace stream writing functions id backdrop and formatting
9f7d301ef4 SLUDGE: Refactor background loading code
6808650f3e SLUDGE: Refactor png specific functions in backdrop
2dddb900c9 SLUDGE: Use PNGDecoder to read backdrop
ca2ee02496 SLUDGE: code formatting
6e5dec3137 SLUDGE: Fix png displaying
c0822cbc8d SLUDGE: Fix configure.engine
3ae270f709 SLUDGE: Correct ifdef position in backdrop.h
b920f61a11 SLUDGE: Add the slusge specific image decoder
8c59f8deac SLUDGE: Replace sludge stream reading functions by scummvm ones
786e4c3dc3 SLUDGE: Refactor image loading function and apply in backdrop
cfe2e63793 SLUDGE: refactor HSIDecoder out of Imgloader
cd42e483de SLUDGE: complete sprite loading
733e758fcb SLUDGE: move backdrop display code to backdrop.cpp
00b64e01d4 SLUDGE: Add debug channel for fatal msg
54ad266157 SLUDGE: fix sprite loading error
30eef2568c SLUDGE: display sprites with TransparentSurface
a589fac895 SLUDGE: fix sprite flickering by using a full screen surface
414b3c4714 SLUDGE: text display
10ff6994ae SLUDGE: format code and remove oneliners
39c1223856 SLUDGE: add copyright information
dc380b4ba4 SLUDGE: align increment operator
c44b4f3128 SLUDGE: remove implementation of tga.h
a8ccd05315 SLUDGE: header formatting
7430ebe883 SLUDGE: use scummvm int type instead of uint16/32_t
bee42dc52f SLUDGE: remove platform dependent defines
4773aff468 SLUDGE: correct int type
90ea9d0177 SLUDGE: spelling correction in define
83ab05630c SLUDGE: replace int type by scummvm types in utf8
3975fd7215 SLUDGE: remove showSetupWindow
2ca6845962 SLUDGE: use AD_ENTRY1s instead of AD_ENTRY1
d5379c212c SLUDGE: add game file name getter in detection
77d5c7235d SLUDGE: replace sludge colours by pixelformat
839e7fb4d2 SLUDGE: fix unmatched delete[] leaks
78cba75570 SLUDGE: change pixel formats to pointers and fix seg fault
09b4a0675e SLUDGE: remove value setting loop by memset
da842ee14e SLUDGE: remove unused sound files and rename cpp
ef9438065f SLUDGE: play game wav sound in a rough way
51a20af064 SLUDGE: leave MOD sound loading aside
7b2a2123f4 SLUDGE: add new game for testing
747820bbed SLUDGE: get loop sound work for wav and ogg
36d078cfe4 SLUDGE: add sound loop test game
15c7958d57 SLUDGE: add sound loop for wav and ogg
5baae657fd SLUDGE: cache of ended sound in playlist won't be used before handled
bbde5f4bf4 SLUDGE: remove #ifndef of cursor display and formatting code
0eb18c2627 SLUDGE: set to right delay time
536ddf7e89 SLUDGE: change struct texture to Surface
e52dbca7fd SLUDGE: remove unused variable in parallaxLayer
9418891237 SLUDGE: get freeze and unfreeze scene work
43ffa3bcc8 SLUDGE: give a 0.5 opacity for mixOverlay image
ea1f2412ee SLUDGE: get input work by replacing sdl event by scummvm event
82f023d9bd SLUDGE: free surfaces in freeze struct
83926d07a3 SLUDGE: fix error that chracter has no click effect
4b941e16db SLUDGE: remove a low-level graphic loop
387a558ec4 SLUDGE: add dark screen effect
f138547808 SLUDGE: paste image to background
eb9968332e SLUDGE: change background and zByffer restore order in freeze
714196132c SLUDGE: load zBuffer sprites as backdrop copies
f89f1aad4c SLUDGE: formatting code in sprites.cpp
52b627bae6 SLUDGE: use Common::List to reproduce layer effects
03f43f789c SLUDGE: add fall back detection
279a53302a SLUDGE: add game detection for Robin's rescue
e7a22b59f8 SLUDGE: add several debug infos and exit when error
d63953d9ce SLUDGE: free resource when finish reading png sprite
5469aaf8ec SLUDGE: move initGraphics after sludge init
1a27d67123 IMAGE: add flag to skip signature check in png decoder
44d7663a49 SLUDGE: read headless png sprites
e7d1f272dc SLUDGE: set sludge game to 1xScale by default
639f20f168 SLUDGE: fix bug of setting zbuffer before backdrop
15e7f5c48e SLUDGE: fix unmatched delete []
ae54897ff5 SLUDGE: add channel to debug text
3b3c92558b SLUDGE: add game timing
9a57db6b9c SLUDGE: correct text color for png font
082bf55b56 SLUDGE: clean debug info
91d2b5d31e SLUDGE: kill a sprite bank
b5a77c9393 SLUDGE: check point to non transparent part of a character
0e8db2bf0d SLUDGE: add blankscreen effect
874d03f79b SLUDGE: stop a sound by file number
791aedf7a5 Image: extend writePng for 4-byte pixelFormat
8152793d09 SLUDGE: save&load system (without thumbnail and snapshot)
fe773c1beb SLUDGE: replace char* by Common::String for error messages
302c946279 SLUDGE: use U32String to replace sludge utf8 library
53572c8e58 SLUDGE: not to build sludge by default
9560969ea8 SLUDGE: remove shader-related files
1e261d6cd3 SLUDGE: remove unused libs
07e4982027 SLUDGE: remove #ifdef HAVE_GLES2 and clean code in graphics
ee45e15178 SLUDGE: use Common::Point instead of struct POINT
ed09887e84 SLUDGE: remove an unused .h
08304b848a SLUDGE: use Common/debug instead of sludge debug
b8cede684e SLUDGE: remove unused files
cc727710b4 SLUDGE: remove define duplication
f8e1fe0064 SLUDGE: replace int types to scummvm defined ones
2563180f11 SLUDGE: remove math functions defined in sludge
389bd92ab9 SLUDGE: correct #define in header to match file name
076f841526 SLUDGE: fix u32string saving error
d37888ad5f SLUDGE: use read/writeSint16LE instead of get/putSigned
8f2a177cef STREAM: add read/write functions for float LE/BE
38262ad630 SLUDGE: use write/readFloatLB instead of Sludge get/putFloat
9d349e794e SLUDGE: code formatting for **
ae8df00f56 SLUDGE: replace abs() by scummvm ABS()
59ea5e5834 SLUDGE: use Graphics::Surface::drawLine instead of sludge defined drawLine
19ff9f419b SLUDGE: correct loadfile existence check
800987ab95 SLUDGE: replace char *by Common::String
1cd6de22e4 SLUDGE: remove debug code
d6308b9176 SLUDGE: replace utf8 chars by code
91fcdda2d1 SLUDGE: change global Common::String to public var of SludgeEngine
8f618e55ae SLUDGE: move namespace to functionlist.h
3c84965724 SLUDGE: delete a game that doesn't exist any more
6b794d3da7 SLUDGE: remove game settings from Sludge code
ef5e8091f6 SLUDGE: use multiple entries for language selection
94ddf526f4 SLUDGE: remove CommonCode directory to have a flat structure


Commit: 94439e2ce311734bfe7bb5700a6584b7550ea8f9
    https://github.com/scummvm/scummvm/commit/94439e2ce311734bfe7bb5700a6584b7550ea8f9
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Add first classes in scummvm to detect .slg game file

Changed paths:
  A engines/sludge/configure.engine
  A engines/sludge/console.cpp
  A engines/sludge/console.h
  A engines/sludge/detection.cpp
  A engines/sludge/module.mk
  A engines/sludge/sludge.cpp
  A engines/sludge/sludge.h


diff --git a/engines/sludge/configure.engine b/engines/sludge/configure.engine
new file mode 100644
index 0000000..24ae50d
--- /dev/null
+++ b/engines/sludge/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 sludge "Sludge" yes
\ No newline at end of file
diff --git a/engines/sludge/console.cpp b/engines/sludge/console.cpp
new file mode 100644
index 0000000..95d70b9
--- /dev/null
+++ b/engines/sludge/console.cpp
@@ -0,0 +1,34 @@
+/* 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 "sludge/console.h"
+
+namespace Sludge {
+
+SludgeConsole::SludgeConsole(SludgeEngine *vm) : GUI::Debugger() {
+	_vm = vm;
+}
+
+SludgeConsole::~SludgeConsole() {
+}
+
+} // End of namespace Sludge
diff --git a/engines/sludge/console.h b/engines/sludge/console.h
new file mode 100644
index 0000000..5f96409
--- /dev/null
+++ b/engines/sludge/console.h
@@ -0,0 +1,44 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_CONSOLE_H
+#define SLUDGE_CONSOLE_H
+
+#include "gui/debugger.h"
+
+namespace Sludge {
+
+class SludgeEngine;
+
+// Example console class
+class SludgeConsole : public GUI::Debugger {
+public:
+	SludgeConsole(SludgeEngine *vm);
+	virtual ~SludgeConsole(void);
+	
+private:
+	SludgeEngine *_vm;
+};
+
+} // End of namespace Sludge
+
+#endif /* SLUDGE_CONSOLE_H */
diff --git a/engines/sludge/detection.cpp b/engines/sludge/detection.cpp
new file mode 100644
index 0000000..8297165
--- /dev/null
+++ b/engines/sludge/detection.cpp
@@ -0,0 +1,98 @@
+/* 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 "common/debug.h"
+
+#include "engines/advancedDetector.h"
+
+#include "sludge/sludge.h"
+
+namespace Sludge {
+
+struct SludgeGameDescription {
+	ADGameDescription desc;
+
+	int gameType;
+};
+
+int SludgeEngine::getGameType() const { return _gameDescription->gameType; }
+const char *SludgeEngine::getGameId() const { return _gameDescription->desc.gameId;}
+uint32 SludgeEngine::getFeatures() const { return _gameDescription->desc.flags; }
+Common::Language SludgeEngine::getLanguage() const { return _gameDescription->desc.language; }
+
+} // End of namespace Sludge
+
+static const PlainGameDescriptor sludgeGames[] = {
+	{ "sludge", "Sludge Game" },
+	{ "welcome", "Welcome Example" },
+	{ 0, 0 }
+};
+ 
+namespace Sludge {
+static const SludgeGameDescription gameDescriptions[] = {
+	{
+		{
+			"welcome",
+			"",
+			AD_ENTRY1("Welcome.slg", "50445503761cf6684fe3270d0860a4c3"),
+			Common::EN_ANY,
+			Common::kPlatformUnknown,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		0
+	},
+
+	{ AD_TABLE_END_MARKER, 0 }
+};
+
+} // End of namespace Sludge
+
+class SludgeMetaEngine : public AdvancedMetaEngine {
+public:
+	SludgeMetaEngine() : AdvancedMetaEngine(Sludge::gameDescriptions, sizeof(Sludge::SludgeGameDescription), sludgeGames) {
+		_singleId = "sludge";
+		_maxScanDepth = 1;
+	}
+
+	virtual const char *getName() const {
+		return "Sludge Engine";
+	}
+ 
+	virtual const char *getOriginalCopyright() const {
+		return "Copyright (C) 2000-2014 Hungry Software and contributors";
+	}
+ 
+ 
+	virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
+		const Sludge::SludgeGameDescription *gd = (const Sludge::SludgeGameDescription *)desc;
+			if (gd) {
+				*engine = new Sludge::SludgeEngine(syst, gd);
+			}
+			return gd != 0;
+	}
+};
+
+#if PLUGIN_ENABLED_DYNAMIC(SLUDGE)
+	REGISTER_PLUGIN_DYNAMIC(SLUDGE, PLUGIN_TYPE_ENGINE, SludgeMetaEngine);
+#else
+	REGISTER_PLUGIN_STATIC(SLUDGE, PLUGIN_TYPE_ENGINE, SludgeMetaEngine);
+#endif
diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk
new file mode 100644
index 0000000..45929cf
--- /dev/null
+++ b/engines/sludge/module.mk
@@ -0,0 +1,17 @@
+MODULE := engines/sludge
+ 
+MODULE_OBJS := \
+	detection.o \
+	sludge.o \
+	console.o
+ 
+MODULE_DIRS += \
+	engines/sludge
+ 
+# This module can be built as a plugin
+ifeq ($(ENABLE_SLUDGE), DYNAMIC_PLUGIN)
+PLUGIN := 1
+endif
+ 
+# Include common rules 
+include $(srcdir)/rules.mk
\ No newline at end of file
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
new file mode 100644
index 0000000..9a910b2
--- /dev/null
+++ b/engines/sludge/sludge.cpp
@@ -0,0 +1,74 @@
+/* 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 "common/scummsys.h"
+ 
+#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/error.h"
+
+#include "engines/util.h"
+
+#include "sludge/sludge.h"
+ 
+namespace Sludge {
+ 
+SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
+ : Engine(syst), _gameDescription(gameDesc), _console(nullptr) {
+ 
+	// register your random source
+	_rnd = new Common::RandomSource("sludge");
+
+	// Add debug channels
+	DebugMan.addDebugChannel(kSludgeDebugScript, "Script", "Script debug level");
+
+	// check init
+	debug("SludgeEngine::SludgeEngine");
+}
+ 
+SludgeEngine::~SludgeEngine() {
+
+	// Dispose resources
+	delete _rnd;
+ 
+	// Remove debug levels
+	DebugMan.clearAllDebugChannels();
+	
+	// Dispose console
+	delete _console;
+}
+ 
+Common::Error SludgeEngine::run() {
+	// init graphics
+	initGraphics(640, 480, false);
+
+	// create console
+	_console = new SludgeConsole(this);
+ 
+	// debug log
+	debug("SludgeEngine::init");
+ 
+	return Common::kNoError;
+}
+ 
+} // End of namespace Sludge
+
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
new file mode 100644
index 0000000..5fe7c9a
--- /dev/null
+++ b/engines/sludge/sludge.h
@@ -0,0 +1,66 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_H
+#define SLUDGE_H
+ 
+#include "common/random.h"
+#include "engines/engine.h"
+#include "gui/debugger.h"
+ 
+#include "sludge/console.h"
+
+namespace Sludge {
+ 
+class SludgeConsole;
+ 
+struct SludgeGameDescription;
+
+// debug channels
+enum {
+	kSludgeDebugScript = 1 << 0
+};
+ 
+class SludgeEngine : public Engine {
+protected:
+	// Engine APIs
+	virtual Common::Error run();
+
+public:
+	SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
+	virtual ~SludgeEngine();
+ 
+	int getGameType() const;
+	const char *getGameId() const;
+	uint32 getFeatures() const;
+	Common::Language getLanguage() const;
+
+	const SludgeGameDescription *_gameDescription;
+ 
+private:
+	SludgeConsole *_console;
+ 	Common::RandomSource *_rnd;
+};
+
+} // End of namespace Sludge
+ 
+#endif


Commit: 219044abf9841461043d6e2acf0d5a48a7c7648b
    https://github.com/scummvm/scummvm/commit/219044abf9841461043d6e2acf0d5a48a7c7648b
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Add sludge files and make it compile

Changed paths:
  A engines/sludge/CommonCode/functionlist.h
  A engines/sludge/CommonCode/specialsettings.h
  A engines/sludge/CommonCode/tga.cpp
  A engines/sludge/CommonCode/tga.h
  A engines/sludge/CommonCode/utf8.cpp
  A engines/sludge/CommonCode/utf8.h
  A engines/sludge/CommonCode/version.h
  A engines/sludge/allfiles.h
  A engines/sludge/backdrop.cpp
  A engines/sludge/backdrop.h
  A engines/sludge/bg_effects.cpp
  A engines/sludge/bg_effects.h
  A engines/sludge/builtin.cpp
  A engines/sludge/builtin.h
  A engines/sludge/color.frag
  A engines/sludge/color.vert
  A engines/sludge/colours.h
  A engines/sludge/csludge.h
  A engines/sludge/cursors.cpp
  A engines/sludge/cursors.h
  A engines/sludge/debug.cpp
  A engines/sludge/debug.h
  A engines/sludge/eglport/eglport.cpp
  A engines/sludge/eglport/eglport.h
  A engines/sludge/errors.h
  A engines/sludge/fileset.cpp
  A engines/sludge/fileset.h
  A engines/sludge/fixScaleSprite.frag
  A engines/sludge/fixScaleSprite.vert
  A engines/sludge/floor.cpp
  A engines/sludge/floor.h
  A engines/sludge/fonttext.cpp
  A engines/sludge/fonttext.h
  A engines/sludge/freeze.cpp
  A engines/sludge/freeze.h
  A engines/sludge/graphics.cpp
  A engines/sludge/graphics.h
  A engines/sludge/helpers.cpp
  A engines/sludge/helpers.h
  A engines/sludge/language.cpp
  A engines/sludge/language.h
  A engines/sludge/libvorbis/COPYING
  A engines/sludge/libvorbis/vorbis_misc.h
  A engines/sludge/libvorbis/vorbis_os.h
  A engines/sludge/libwebm/AUTHORS.TXT
  A engines/sludge/libwebm/LICENSE.TXT
  A engines/sludge/libwebm/PATENTS.TXT
  A engines/sludge/libwebm/mkvparser.cpp
  A engines/sludge/libwebm/mkvparser.hpp
  A engines/sludge/libwebm/mkvreader.cpp
  A engines/sludge/libwebm/mkvreader.hpp
  A engines/sludge/line.cpp
  A engines/sludge/line.h
  A engines/sludge/linuxstuff.cpp
  A engines/sludge/linuxstuff.h
  A engines/sludge/loadsave.cpp
  A engines/sludge/loadsave.h
  A engines/sludge/main_loop.cpp
  A engines/sludge/main_loop.h
  A engines/sludge/memwatch.cpp
  A engines/sludge/memwatch.h
  A engines/sludge/moreio.cpp
  A engines/sludge/moreio.h
  A engines/sludge/movie.cpp
  A engines/sludge/movie.h
  A engines/sludge/newfatal.cpp
  A engines/sludge/newfatal.h
  A engines/sludge/objtypes.cpp
  A engines/sludge/objtypes.h
  A engines/sludge/people.cpp
  A engines/sludge/people.h
  A engines/sludge/platform-dependent.h
  A engines/sludge/region.cpp
  A engines/sludge/region.h
  A engines/sludge/savedata.cpp
  A engines/sludge/savedata.h
  A engines/sludge/scale.frag
  A engines/sludge/scale.vert
  A engines/sludge/scale_noaa.frag
  A engines/sludge/shaders.cpp
  A engines/sludge/shaders.h
  A engines/sludge/sludger.cpp
  A engines/sludge/sludger.h
  A engines/sludge/sound.h
  A engines/sludge/sound_bass.cpp
  A engines/sludge/sound_nosound.cpp
  A engines/sludge/sound_openal.cpp
  A engines/sludge/sprbanks.cpp
  A engines/sludge/sprbanks.h
  A engines/sludge/sprites.cpp
  A engines/sludge/sprites.h
  A engines/sludge/statusba.cpp
  A engines/sludge/statusba.h
  A engines/sludge/stringy.cpp
  A engines/sludge/stringy.h
  A engines/sludge/talk.cpp
  A engines/sludge/talk.h
  A engines/sludge/texture.frag
  A engines/sludge/texture.vert
  A engines/sludge/thumbnail.cpp
  A engines/sludge/thumbnail.h
  A engines/sludge/timing.cpp
  A engines/sludge/timing.h
  A engines/sludge/transition.cpp
  A engines/sludge/transition.h
  A engines/sludge/variable.cpp
  A engines/sludge/variable.h
  A engines/sludge/vid.cpp
  A engines/sludge/vid.h
  A engines/sludge/winstuff.cpp
  A engines/sludge/winstuff.h
  A engines/sludge/yuv.frag
  A engines/sludge/yuv.vert
  A engines/sludge/zbuffer.cpp
  A engines/sludge/zbuffer.h
    engines/sludge/module.mk
    engines/sludge/sludge.cpp


diff --git a/engines/sludge/CommonCode/functionlist.h b/engines/sludge/CommonCode/functionlist.h
new file mode 100644
index 0000000..3d98553
--- /dev/null
+++ b/engines/sludge/CommonCode/functionlist.h
@@ -0,0 +1,175 @@
+/*
+This is the list of the built in functions
+
+true or false states if it's a used function
+in the current version of the engine,
+but that value currently isn't used anywhere
+*/
+
+FUNC(true, say)
+FUNC(true, skipSpeech)
+FUNC(true, statusText)
+FUNC(true, pause)
+FUNC(true, onLeftMouse)
+FUNC(true, onRightMouse)
+FUNC(true, setCursor)
+FUNC(true, addOverlay)
+FUNC(true, addCharacter)
+FUNC(true, playSound)
+FUNC(true, getMouseX)
+FUNC(true, getMouseY)
+FUNC(true, addScreenRegion)
+FUNC(true, onMoveMouse)
+FUNC(true, onFocusChange)
+FUNC(true, getOverObject)
+FUNC(true, blankScreen)
+FUNC(true, moveCharacter)
+FUNC(true, onKeyboard)
+FUNC(true, getObjectX)
+FUNC(true, getObjectY)
+FUNC(true, random)
+FUNC(true, spawnSub)
+FUNC(true, blankArea)
+FUNC(true, hideCharacter)
+FUNC(true, showCharacter)
+FUNC(true, callEvent)
+FUNC(true, removeScreenRegion)
+FUNC(true, animate)
+FUNC(true, turnCharacter)
+FUNC(true, removeAllCharacters)
+FUNC(true, removeAllScreenRegions)
+FUNC(true, setScale)
+FUNC(true, newStack)
+FUNC(true, pushToStack)
+FUNC(true, popFromStack)
+FUNC(true, clearStatus)
+FUNC(true, addStatus)
+FUNC(true, removeLastStatus)
+FUNC(true, lightStatus)
+FUNC(true, getStatusText)
+FUNC(true, setStatusColour)
+FUNC(true, deleteFromStack)
+FUNC(true, freeze)
+FUNC(true, unfreeze)
+FUNC(true, pasteImage)
+FUNC(true, copyStack)
+FUNC(true, completeTimers)
+FUNC(true, setCharacterDrawMode)
+FUNC(true, anim)
+FUNC(true, costume)
+FUNC(true, pickOne)
+FUNC(true, setCostume)
+FUNC(true, wait)
+FUNC(true, somethingSpeaking)
+FUNC(true, substring)
+FUNC(true, stringLength)
+FUNC(true, darkBackground)
+FUNC(true, saveGame)
+FUNC(true, loadGame)
+FUNC(true, quitGame)
+FUNC(true, rename)
+FUNC(true, stackSize)
+FUNC(true, pasteString)
+FUNC(true, startMusic)
+FUNC(true, setDefaultMusicVolume)
+FUNC(true, setMusicVolume)
+FUNC(true, stopMusic)
+FUNC(true, stopSound)
+FUNC(true, setFont)
+FUNC(true, alignStatus)
+FUNC(true, showFloor)
+FUNC(true, showBoxes)
+FUNC(true, positionStatus)
+FUNC(true, setFloor)
+FUNC(true, forceCharacter)
+FUNC(true, jumpCharacter)
+FUNC(true, peekStart)
+FUNC(true, peekEnd)
+FUNC(true, enqueue)
+FUNC(true, setZBuffer)
+FUNC(true, getMatchingFiles)
+FUNC(true, inFont)
+FUNC(true, onLeftMouseUp)
+FUNC(true, onRightMouseUp)
+FUNC(true, loopSound)
+FUNC(true, removeCharacter)
+FUNC(true, stopCharacter)
+FUNC(true, launch)
+FUNC(true, howFrozen)
+FUNC(true, setPasteColour)
+FUNC(true, setLitStatusColour)
+FUNC(true, fileExists)
+FUNC(true, floatCharacter)
+FUNC(true, cancelSub)
+FUNC(true, setCharacterWalkSpeed)
+FUNC(true, deleteAllFromStack)
+FUNC(true, setCharacterExtra)
+FUNC(true, mixOverlay)
+FUNC(true, pasteCharacter)
+FUNC(true, setSceneDimensions)
+FUNC(true, aimCamera)
+FUNC(true, getMouseScreenX)
+FUNC(true, getMouseScreenY)
+FUNC(true, setDefaultSoundVolume)
+FUNC(true, setSoundVolume)
+FUNC(true, setSoundLoopPoints)
+FUNC(true, setSpeechMode)
+FUNC(true, setLightMap)
+FUNC(true, think)
+FUNC(true, getCharacterDirection)
+FUNC(true, isCharacter)
+FUNC(true, isScreenRegion)
+FUNC(true, isMoving)
+FUNC(true, deleteFile)
+FUNC(true, renameFile)
+FUNC(true, hardScroll)
+FUNC(true, stringWidth)
+FUNC(true, setSpeechSpeed)
+FUNC(true, normalCharacter)
+FUNC(true, fetchEvent)
+FUNC(true, transitionLevel)
+FUNC(true, spinCharacter)
+FUNC(true, setFontSpacing)
+FUNC(true, burnString)
+FUNC(true, captureAllKeys)
+FUNC(true, cacheSound)
+FUNC(true, setCharacterSpinSpeed)
+FUNC(true, transitionMode)
+FUNC(false,  _rem_movieStart)
+FUNC(false,  _rem_movieAbort)
+FUNC(false,  _rem_moviePlaying)
+FUNC(false,  _rem_updateDisplay)
+FUNC(true, getSoundCache)
+FUNC(true, saveCustomData)
+FUNC(true, loadCustomData)
+FUNC(true, setCustomEncoding)
+FUNC(true, freeSound)
+FUNC(true, parallaxAdd)
+FUNC(true, parallaxClear)
+FUNC(true, setBlankColour)
+FUNC(true, setBurnColour)
+FUNC(true, getPixelColour)
+FUNC(true, makeFastArray)
+FUNC(true, getCharacterScale)
+FUNC(true, getLanguageID)
+FUNC(false, _rem_launchWith)
+FUNC(true, getFramesPerSecond)
+FUNC(true, showThumbnail)
+FUNC(true, setThumbnailSize)
+FUNC(true, hasFlag)
+FUNC(true, snapshotGrab)
+FUNC(true, snapshotClear)
+FUNC(true, bodgeFilenames)
+FUNC(false,  _rem_registryGetString)
+FUNC(true, quitWithFatalError)
+FUNC(true, _rem_setCharacterAA)
+FUNC(true, _rem_setMaximumAA)
+FUNC(true, setBackgroundEffect)
+FUNC(true, doBackgroundEffect)
+FUNC(true, setCharacterAngleOffset)
+FUNC(true, setCharacterTransparency)
+FUNC(true, setCharacterColourise)
+FUNC(true, zoomCamera)
+FUNC(true, playMovie)
+FUNC(true, stopMovie)
+FUNC(true, pauseMovie)
diff --git a/engines/sludge/CommonCode/specialsettings.h b/engines/sludge/CommonCode/specialsettings.h
new file mode 100644
index 0000000..1e41e4e
--- /dev/null
+++ b/engines/sludge/CommonCode/specialsettings.h
@@ -0,0 +1,8 @@
+#define SPECIAL_REGISTERED      1
+#define SPECIAL_FULLSCREEN      2
+#define SPECIAL_MOUSE_1         4
+#define SPECIAL_SILENT          8
+#define SPECIAL_MOUSE_2         16
+#define SPECIAL_INVISIBLE       32
+#define SPECIAL_HIDELOGO        64
+#define SPECIAL_HIDELOADING     128
diff --git a/engines/sludge/CommonCode/tga.cpp b/engines/sludge/CommonCode/tga.cpp
new file mode 100644
index 0000000..d25ccd9
--- /dev/null
+++ b/engines/sludge/CommonCode/tga.cpp
@@ -0,0 +1,278 @@
+#include <stdio.h>
+
+#include "tga.h"
+
+//FILE * debugFile = fopen ("TGAdebug.txt", "wt");
+
+unsigned short int makeColour (unsigned char r, unsigned char g, unsigned char b) {
+	unsigned short int reply = (unsigned short int) (r >> 3);
+	reply <<= 6;
+	reply += (unsigned short int) (g >> 2);
+	reply <<= 5;
+	reply += (unsigned short int) (b >> 3);
+	return reply & 65503;
+}
+
+int get2bytesReverse (FILE * fp) {
+	int a = fgetc (fp);
+	return a + fgetc (fp) * 256;
+}
+
+int countDown = 0;
+
+bool dither24bitImages = 0;
+
+char ditherArray[4][4] = {{4,12,6,14},{10,0,8,2},{7,15,5,13},{9,3,11,1}};
+
+void grabRGBA (FILE * fp, int bpc, unsigned char & r, unsigned char & g, unsigned char & b, unsigned char & a, palCol thePalette[])
+{
+	int grabbed1, grabbed2;
+	switch (bpc) {
+		case 8:
+			grabbed1 = fgetc (fp);
+			r = thePalette[grabbed1].r;
+			g = thePalette[grabbed1].g;
+			b = thePalette[grabbed1].b;
+			if (r == 255 && g == 0 && b == 255) {
+				r = g = b = a = 0;
+			} else a = 255;
+			break;
+			
+		case 16:
+			grabbed1 = fgetc (fp);
+			grabbed2 = fgetc (fp);
+			if (grabbed2*256+grabbed1 == 31775) {
+				r=g=b=a=0;
+				break;
+			}
+
+			r = ((grabbed2 & 127) << 1),
+			g = ((grabbed1 & 224) >> 2) + (grabbed2 << 6);
+			b = ((grabbed1 & 31) << 3);
+			if (r == 255 && g == 0 && b == 255) {
+				r = g = b = a = 0;
+			} else a = 255;
+			break;
+			
+		case 24:
+			b = fgetc (fp);
+			g = fgetc (fp);
+			r = fgetc (fp);
+			if (r == 255 && g == 0 && b == 255) {
+				r = g = b = a = 0;
+			} else a = 255;
+			break;
+			
+		case 32:
+			b = fgetc (fp);
+			g = fgetc (fp);
+			r = fgetc (fp);
+			a = fgetc (fp);
+			break;		
+	}
+}
+
+
+void grabRGB (FILE * fp, int bpc, unsigned char & r, unsigned char & g, unsigned char & b, palCol thePalette[])
+{
+	int a;
+	int grabbed1, grabbed2;
+	switch (bpc) {
+		case 8:
+		grabbed1 = fgetc (fp);
+		r = thePalette[grabbed1].r;
+		g = thePalette[grabbed1].g;
+		b = thePalette[grabbed1].b;
+		break;
+	
+		case 16:
+		grabbed1 = fgetc (fp);
+		grabbed2 = fgetc (fp);
+		r = ((grabbed2 & 127) << 1),
+		g = ((grabbed1 & 224) >> 2) + (grabbed2 << 6);
+		b = ((grabbed1 & 31) << 3);
+		break;
+				
+		case 24:
+		b = fgetc (fp);
+		g = fgetc (fp);
+		r = fgetc (fp);
+		break;
+		
+		case 32:
+		b = fgetc (fp);
+		g = fgetc (fp);
+		r = fgetc (fp);
+		a = fgetc (fp);
+			if (a < 100) {
+				r = 255;
+				g = 0;
+				b = 255;
+			}
+		break;		
+	}
+}
+
+void grabRGBACompressed (FILE * fp, int bpc, unsigned char & r2, unsigned char & g2, unsigned char & b2, unsigned char & a2, palCol thePalette[]) {
+	static unsigned char r, g, b, a;
+	static bool oneCol;
+	unsigned short col;
+	
+	// Do we have to start a new packet?
+	if (countDown == 0) {
+		
+		// Read the packet description thingy
+		col = fgetc (fp);
+		
+		// Is it raw data?
+		if (col >= 128) {
+			oneCol = true;
+			countDown = col - 127;
+			grabRGBA (fp, bpc, r, g, b, a, thePalette);
+			//			fprintf (debugFile, "  %d raw colours...\n", countDown);
+		} else {
+			oneCol = false;
+			countDown = col + 1;
+			//			fprintf (debugFile, "  %d pixels the same colour...\n", countDown);
+		}
+	}
+	
+	countDown --;
+	
+	if (! oneCol) {
+		grabRGBA (fp, bpc, r2, g2, b2, a2, thePalette);
+	} else {
+		r2 = r;
+		g2 = g;
+		b2 = b;
+		a2 = a;
+	}
+}
+
+
+void grabRGBCompressed (FILE * fp, int bpc, unsigned char & r2, unsigned char & g2, unsigned char & b2, palCol thePalette[]) {
+	static unsigned char r, g, b;
+	static bool oneCol;
+	unsigned short col;
+	
+	// Do we have to start a new packet?
+	if (countDown == 0) {
+		
+		// Read the packet description thingy
+		col = fgetc (fp);
+		
+		// Is it raw data?
+		if (col >= 128) {
+			oneCol = true;
+			countDown = col - 127;
+			grabRGB (fp, bpc, r, g, b, thePalette);
+			//			fprintf (debugFile, "  %d raw colours...\n", countDown);
+		} else {
+			oneCol = false;
+			countDown = col + 1;
+			//			fprintf (debugFile, "  %d pixels the same colour...\n", countDown);
+		}
+	}
+	
+	countDown --;
+	
+	if (! oneCol) {
+		grabRGB (fp, bpc, r2, g2, b2, thePalette);
+	} else {
+		r2 = r;
+		g2 = g;
+		b2 = b;
+	}
+}
+
+void addDither (unsigned char & col, const unsigned char add)
+{
+	int tot = col;
+	tot += add;
+	col = (tot > 255) ? 255 : tot;
+}
+
+unsigned short readAColour (FILE * fp, int bpc, palCol thePalette[], int x, int y) {
+	unsigned char r,g,b;
+	grabRGB (fp, bpc, r, g, b, thePalette);
+
+	if (dither24bitImages)
+	{
+		addDither (r, ditherArray[x&3][y&3]);
+		addDither (g, ditherArray[x&3][y&3] / 2);
+		addDither (b, ditherArray[x&3][y&3]);
+	}
+
+	return makeColour (r, g, b);
+}
+
+unsigned short readCompressedColour (FILE * fp, int bpc, palCol thePalette[], int x, int y) {
+	unsigned char r,g,b;
+	grabRGBCompressed (fp, bpc, r, g, b, thePalette);
+	
+	if (dither24bitImages)
+	{
+		addDither (r, ditherArray[x&3][y&3]);
+		addDither (g, ditherArray[x&3][y&3] / 2);
+		addDither (b, ditherArray[x&3][y&3]);
+	}
+	
+	return makeColour (r, g, b);
+}
+
+const char * readTGAHeader (TGAHeader & h, FILE * fp, palCol thePalette[]) {
+
+	h.IDBlockSize = fgetc (fp);
+	h.gotMap = fgetc (fp);
+	unsigned char imageType = fgetc (fp);
+	h.firstPalColour = get2bytesReverse (fp);
+	h.numPalColours = get2bytesReverse (fp);
+	h.bitsPerPalColour = fgetc (fp);
+	h.xOrigin = get2bytesReverse (fp);
+	h.yOrigin = get2bytesReverse (fp);
+	h.width = get2bytesReverse (fp);
+	h.height = get2bytesReverse (fp);
+	h.pixelDepth = fgetc (fp);
+	h.imageDescriptor = fgetc (fp);
+	countDown = 0;
+	// Who cares about the ID block?
+	fseek (fp, h.IDBlockSize, 1);
+
+	switch (imageType) {
+		case 1:
+		case 2:
+		h.compressed = false;
+		break;
+		
+		case 9:
+		case 10:
+		h.compressed = true;
+		break;
+		
+		default:
+		return "Unsupported internal image format... are you sure this is a valid TGA image file?";
+	}
+
+	if (h.pixelDepth != 8 && h.pixelDepth != 16 && h.pixelDepth != 24 && h.pixelDepth != 32) {
+		return "Colour depth is not 8, 16, 24 or 32 bits... are you sure this is a valid TGA image file?";
+	}
+
+	if (h.gotMap) {
+		int c;
+		for (c = 0; c < h.numPalColours; c ++) {
+			grabRGB (fp, h.bitsPerPalColour, thePalette[c].r, thePalette[c].g, thePalette[c].b, thePalette);
+		}
+	}
+
+	return NULL;
+}
+
+void setDither (int dither)
+{
+	dither24bitImages = dither;
+}
+
+bool getDither ()
+{
+	return dither24bitImages;
+}
diff --git a/engines/sludge/CommonCode/tga.h b/engines/sludge/CommonCode/tga.h
new file mode 100644
index 0000000..e7f6b55
--- /dev/null
+++ b/engines/sludge/CommonCode/tga.h
@@ -0,0 +1,45 @@
+#include <stdio.h>
+
+struct TGAHeader {
+	unsigned char IDBlockSize;
+	unsigned char gotMap;
+	bool compressed;
+	unsigned short int firstPalColour;
+	unsigned short int numPalColours;
+	unsigned char bitsPerPalColour;
+	unsigned short xOrigin;
+	unsigned short yOrigin;
+	unsigned short width;
+	unsigned short height;
+	unsigned char pixelDepth;
+	unsigned char imageDescriptor;
+};
+
+struct palCol {
+	unsigned char r, g, b;
+};
+
+void grabRGBCompressed(FILE *fp, int bpc, unsigned char &r2, unsigned char &g2, unsigned char &b2, palCol thePalette[]);
+void grabRGB(FILE *fp, int bpc, unsigned char &r, unsigned char &g, unsigned char &b, palCol thePalette[]);
+void grabRGBACompressed(FILE *fp, int bpc, unsigned char &r2, unsigned char &g2, unsigned char &b2, unsigned char &a2, palCol thePalette[]);
+void grabRGBA(FILE *fp, int bpc, unsigned char &r, unsigned char &g, unsigned char &b, unsigned char &a, palCol thePalette[]);
+
+unsigned short int makeColour(unsigned char r, unsigned char g, unsigned char b);
+unsigned short readAColour(FILE *fp, int bpc, palCol thePalette[], int x, int y);
+unsigned short readCompressedColour(FILE *fp, int bpc, palCol thePalette[], int x, int y);
+const char *readTGAHeader(TGAHeader &h, FILE *fp, palCol thePalette[]);
+void setDither(int dither);
+bool getDither();
+
+inline unsigned short redValue(unsigned short c) {
+	return (c >> 11) << 3;
+}
+inline unsigned short greenValue(unsigned short c) {
+	return ((c >> 5) & 63) << 2;
+}
+inline unsigned short blueValue(unsigned short c) {
+	return (c & 31) << 3;
+}
+inline int brightness(unsigned short c) {
+	return ((int) redValue(c)) + ((int) greenValue(c)) + ((int) blueValue(c) >> 1);
+}
diff --git a/engines/sludge/CommonCode/utf8.cpp b/engines/sludge/CommonCode/utf8.cpp
new file mode 100644
index 0000000..24d9010
--- /dev/null
+++ b/engines/sludge/CommonCode/utf8.cpp
@@ -0,0 +1,541 @@
+/*
+  Basic UTF-8 manipulation routines
+  by Jeff Bezanson
+  placed in the public domain Fall 2005
+
+  This code is designed to provide the utilities you need to manipulate
+  UTF-8 as an internal string encoding. These functions do not perform the
+  error checking normally needed when handling UTF-8 data, so if you happen
+  to be from the Unicode Consortium you will want to flay me alive.
+  I do this because error checking can be performed at the boundaries (I/O),
+  with these routines reserved for higher performance on data known to be
+  valid.
+*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#ifdef WIN32
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
+
+#include "utf8.h"
+
+static const uint32_t offsetsFromUTF8[6] = {
+    0x00000000UL, 0x00003080UL, 0x000E2080UL,
+    0x03C82080UL, 0xFA082080UL, 0x82082080UL
+};
+
+static const char trailingBytesForUTF8[256] = {
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,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,1,1,1,1,1,1,
+    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
+};
+
+/* returns length of next utf-8 sequence */
+int u8_seqlen(char *s)
+{
+    return trailingBytesForUTF8[(unsigned int)(unsigned char)s[0]] + 1;
+}
+
+/* conversions without error checking
+   only works for valid UTF-8, i.e. no 5- or 6-byte sequences
+   srcsz = source size in bytes, or -1 if 0-terminated
+   sz = dest size in # of wide characters
+
+   returns # characters converted
+   dest will always be L'\0'-terminated, even if there isn't enough room
+   for all the characters.
+   if sz = srcsz+1 (i.e. 4*srcsz+4 bytes), there will always be enough space.
+*/
+int u8_toucs(uint32_t *dest, int sz, char *src, int srcsz)
+{
+    uint32_t ch;
+    char *src_end = src + srcsz;
+    int nb;
+    int i=0;
+
+    while (i < sz-1) {
+        nb = trailingBytesForUTF8[(unsigned char)*src];
+        if (srcsz == -1) {
+            if (*src == 0)
+                goto done_toucs;
+        }
+        else {
+            if (src + nb >= src_end)
+                goto done_toucs;
+        }
+        ch = 0;
+        switch (nb) {
+            /* these fall through deliberately */
+        case 3: ch += (unsigned char)*src++; ch <<= 6;
+        case 2: ch += (unsigned char)*src++; ch <<= 6;
+        case 1: ch += (unsigned char)*src++; ch <<= 6;
+        case 0: ch += (unsigned char)*src++;
+        }
+        ch -= offsetsFromUTF8[nb];
+        dest[i++] = ch;
+    }
+ done_toucs:
+    dest[i] = 0;
+    return i;
+}
+
+/* srcsz = number of source characters, or -1 if 0-terminated
+   sz = size of dest buffer in bytes
+
+   returns # characters converted
+   dest will only be '\0'-terminated if there is enough space. this is
+   for consistency; imagine there are 2 bytes of space left, but the next
+   character requires 3 bytes. in this case we could NUL-terminate, but in
+   general we can't when there's insufficient space. therefore this function
+   only NUL-terminates if all the characters fit, and there's space for
+   the NUL as well.
+   the destination string will never be bigger than the source string.
+*/
+int u8_toutf8(char *dest, int sz, uint32_t *src, int srcsz)
+{
+    uint32_t ch;
+    int i = 0;
+    char *dest_end = dest + sz;
+
+    while (srcsz<0 ? src[i]!=0 : i < srcsz) {
+        ch = src[i];
+        if (ch < 0x80) {
+            if (dest >= dest_end)
+                return i;
+            *dest++ = (char)ch;
+        }
+        else if (ch < 0x800) {
+            if (dest >= dest_end-1)
+                return i;
+            *dest++ = (ch>>6) | 0xC0;
+            *dest++ = (ch & 0x3F) | 0x80;
+        }
+        else if (ch < 0x10000) {
+            if (dest >= dest_end-2)
+                return i;
+            *dest++ = (ch>>12) | 0xE0;
+            *dest++ = ((ch>>6) & 0x3F) | 0x80;
+            *dest++ = (ch & 0x3F) | 0x80;
+        }
+        else if (ch < 0x110000) {
+            if (dest >= dest_end-3)
+                return i;
+            *dest++ = (ch>>18) | 0xF0;
+            *dest++ = ((ch>>12) & 0x3F) | 0x80;
+            *dest++ = ((ch>>6) & 0x3F) | 0x80;
+            *dest++ = (ch & 0x3F) | 0x80;
+        }
+        i++;
+    }
+    if (dest < dest_end)
+        *dest = '\0';
+    return i;
+}
+
+int u8_wc_toutf8(char *dest, uint32_t ch)
+{
+    if (ch < 0x80) {
+        dest[0] = (char)ch;
+        return 1;
+    }
+    if (ch < 0x800) {
+        dest[0] = (ch>>6) | 0xC0;
+        dest[1] = (ch & 0x3F) | 0x80;
+        return 2;
+    }
+    if (ch < 0x10000) {
+        dest[0] = (ch>>12) | 0xE0;
+        dest[1] = ((ch>>6) & 0x3F) | 0x80;
+        dest[2] = (ch & 0x3F) | 0x80;
+        return 3;
+    }
+    if (ch < 0x110000) {
+        dest[0] = (ch>>18) | 0xF0;
+        dest[1] = ((ch>>12) & 0x3F) | 0x80;
+        dest[2] = ((ch>>6) & 0x3F) | 0x80;
+        dest[3] = (ch & 0x3F) | 0x80;
+        return 4;
+    }
+    return 0;
+}
+
+/* charnum => byte offset */
+int u8_offset(char *str, int charnum)
+{
+    int offs=0;
+
+    while (charnum > 0 && str[offs]) {
+        (void)(isutf(str[++offs]) || isutf(str[++offs]) ||
+               isutf(str[++offs]) || ++offs);
+        charnum--;
+    }
+    return offs;
+}
+
+/* byte offset => charnum */
+int u8_charnum(char *s, int offset)
+{
+    int charnum = 0, offs=0;
+
+    while (offs < offset && s[offs]) {
+        (void)(isutf(s[++offs]) || isutf(s[++offs]) ||
+               isutf(s[++offs]) || ++offs);
+        charnum++;
+    }
+    return charnum;
+}
+
+/* number of characters */
+int u8_strlen(char *s)
+{
+    int count = 0;
+    int i = 0;
+
+    while (u8_nextchar(s, &i) != 0)
+        count++;
+
+    return count;
+}
+
+/* reads the next utf-8 sequence out of a string, updating an index */
+uint32_t u8_nextchar(const char *s, int *i)
+{
+    uint32_t ch = 0;
+    int sz = 0;
+
+    do {
+        ch <<= 6;
+        ch += (unsigned char)s[(*i)++];
+        sz++;
+    } while (s[*i] && !isutf(s[*i]));
+    ch -= offsetsFromUTF8[sz-1];
+
+    return ch;
+}
+
+void u8_inc(char *s, int *i)
+{
+    (void)(isutf(s[++(*i)]) || isutf(s[++(*i)]) ||
+           isutf(s[++(*i)]) || ++(*i));
+}
+
+void u8_dec(char *s, int *i)
+{
+    (void)(isutf(s[--(*i)]) || isutf(s[--(*i)]) ||
+           isutf(s[--(*i)]) || --(*i));
+}
+
+int octal_digit(char c)
+{
+    return (c >= '0' && c <= '7');
+}
+
+int hex_digit(char c)
+{
+    return ((c >= '0' && c <= '9') ||
+            (c >= 'A' && c <= 'F') ||
+            (c >= 'a' && c <= 'f'));
+}
+
+/* assumes that src points to the character after a backslash
+   returns number of input characters processed */
+int u8_read_escape_sequence(char *str, uint32_t *dest)
+{
+    uint32_t ch;
+    char digs[9]="\0\0\0\0\0\0\0\0";
+    int dno=0, i=1;
+
+    ch = (uint32_t)str[0];    /* take literal character */
+    if (str[0] == 'n')
+        ch = L'\n';
+    else if (str[0] == 't')
+        ch = L'\t';
+    else if (str[0] == 'r')
+        ch = L'\r';
+    else if (str[0] == 'b')
+        ch = L'\b';
+    else if (str[0] == 'f')
+        ch = L'\f';
+    else if (str[0] == 'v')
+        ch = L'\v';
+    else if (str[0] == 'a')
+        ch = L'\a';
+    else if (octal_digit(str[0])) {
+        i = 0;
+        do {
+            digs[dno++] = str[i++];
+        } while (octal_digit(str[i]) && dno < 3);
+        ch = strtol(digs, NULL, 8);
+    }
+    else if (str[0] == 'x') {
+        while (hex_digit(str[i]) && dno < 2) {
+            digs[dno++] = str[i++];
+        }
+        if (dno > 0)
+            ch = strtol(digs, NULL, 16);
+    }
+    else if (str[0] == 'u') {
+        while (hex_digit(str[i]) && dno < 4) {
+            digs[dno++] = str[i++];
+        }
+        if (dno > 0)
+            ch = strtol(digs, NULL, 16);
+    }
+    else if (str[0] == 'U') {
+        while (hex_digit(str[i]) && dno < 8) {
+            digs[dno++] = str[i++];
+        }
+        if (dno > 0)
+            ch = strtol(digs, NULL, 16);
+    }
+    *dest = ch;
+
+    return i;
+}
+
+/* convert a string with literal \uxxxx or \Uxxxxxxxx characters to UTF-8
+   example: u8_unescape(mybuf, 256, "hello\\u220e")
+   note the double backslash is needed if called on a C string literal */
+int u8_unescape(char *buf, int sz, char *src)
+{
+    int c=0, amt;
+    uint32_t ch;
+    char temp[4];
+
+    while (*src && c < sz) {
+        if (*src == '\\') {
+            src++;
+            amt = u8_read_escape_sequence(src, &ch);
+        }
+        else {
+            ch = (uint32_t)*src;
+            amt = 1;
+        }
+        src += amt;
+        amt = u8_wc_toutf8(temp, ch);
+        if (amt > sz-c)
+            break;
+        memcpy(&buf[c], temp, amt);
+        c += amt;
+    }
+    if (c < sz)
+        buf[c] = '\0';
+    return c;
+}
+
+int u8_escape_wchar(char *buf, int sz, uint32_t ch)
+{
+    if (ch == L'\n')
+        return snprintf(buf, sz, "\\n");
+    else if (ch == L'\t')
+        return snprintf(buf, sz, "\\t");
+    else if (ch == L'\r')
+        return snprintf(buf, sz, "\\r");
+    else if (ch == L'\b')
+        return snprintf(buf, sz, "\\b");
+    else if (ch == L'\f')
+        return snprintf(buf, sz, "\\f");
+    else if (ch == L'\v')
+        return snprintf(buf, sz, "\\v");
+    else if (ch == L'\a')
+        return snprintf(buf, sz, "\\a");
+    else if (ch == L'\\')
+        return snprintf(buf, sz, "\\\\");
+    else if (ch < 32 || ch == 0x7f)
+        return snprintf(buf, sz, "\\x%hhX", (unsigned char)ch);
+    else if (ch > 0xFFFF)
+        return snprintf(buf, sz, "\\U%.8X", (uint32_t)ch);
+    else if (ch >= 0x80 && ch <= 0xFFFF)
+        return snprintf(buf, sz, "\\u%.4hX", (unsigned short)ch);
+
+    return snprintf(buf, sz, "%c", (char)ch);
+}
+
+int u8_escape(char *buf, int sz, char *src, int escape_quotes)
+{
+    int c=0, i=0, amt;
+
+    while (src[i] && c < sz) {
+        if (escape_quotes && src[i] == '"') {
+            amt = snprintf(buf, sz - c, "\\\"");
+            i++;
+        }
+        else {
+            amt = u8_escape_wchar(buf, sz - c, u8_nextchar(src, &i));
+        }
+        c += amt;
+        buf += amt;
+    }
+    if (c < sz)
+        *buf = '\0';
+    return c;
+}
+
+char *u8_strchr(char *s, uint32_t ch, int *charn)
+{
+    int i = 0, lasti=0;
+    uint32_t c;
+
+    *charn = 0;
+    while (s[i]) {
+        c = u8_nextchar(s, &i);
+        if (c == ch) {
+            return &s[lasti];
+        }
+        lasti = i;
+        (*charn)++;
+    }
+    return NULL;
+}
+
+char *u8_memchr(char *s, uint32_t ch, size_t sz, int *charn)
+{
+    int i = 0, lasti=0;
+    uint32_t c;
+    int csz;
+
+    *charn = 0;
+    while (i < sz) {
+        c = csz = 0;
+        do {
+            c <<= 6;
+            c += (unsigned char)s[i++];
+            csz++;
+        } while (i < sz && !isutf(s[i]));
+        c -= offsetsFromUTF8[csz-1];
+
+        if (c == ch) {
+            return &s[lasti];
+        }
+        lasti = i;
+        (*charn)++;
+    }
+    return NULL;
+}
+
+int u8_is_locale_utf8(char *locale)
+{
+    /* this code based on libutf8 */
+    const char* cp = locale;
+
+    for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++) {
+        if (*cp == '.') {
+            const char* encoding = ++cp;
+            for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++)
+                ;
+            if ((cp-encoding == 5 && !strncmp(encoding, "UTF-8", 5))
+                || (cp-encoding == 4 && !strncmp(encoding, "utf8", 4)))
+                return 1; /* it's UTF-8 */
+            break;
+        }
+    }
+    return 0;
+}
+
+int u8_vprintf(char *fmt, va_list ap)
+{
+    int cnt, sz=0;
+    char *buf;
+    uint32_t *wcs;
+
+    sz = 512;
+    buf = (char*)alloca(sz);
+ try_print:
+    cnt = vsnprintf(buf, sz, fmt, ap);
+    if (cnt >= sz) {
+        buf = (char*)alloca(cnt - sz + 1);
+        sz = cnt + 1;
+        goto try_print;
+    }
+    wcs = (uint32_t*)alloca((cnt+1) * sizeof(uint32_t));
+    cnt = u8_toucs(wcs, cnt+1, buf, cnt);
+    printf("%ls", (wchar_t*)wcs);
+    return cnt;
+}
+
+int u8_printf(char *fmt, ...)
+{
+    int cnt;
+    va_list args;
+
+    va_start(args, fmt);
+
+    cnt = u8_vprintf(fmt, args);
+
+    va_end(args);
+    return cnt;
+}
+
+
+// This function checks a string to see if it's valid UTF-8
+// It returns true if the string is valid.
+//
+// based on the valid_utf8 routine from the PCRE library by Philip Hazel
+
+int u8_isvalid(const char *str)
+{
+    const unsigned char *p;
+    unsigned char c;
+    int ab;
+	
+    for (p = (unsigned char*)str; *p; p++) {
+        c = *p;
+        if (c < 128)
+            continue;
+        if ((c & 0xc0) != 0xc0)
+            return 0;
+        ab = trailingBytesForUTF8[c];
+		
+        p++;
+        /* Check top bits in the second byte */
+        if ((*p & 0xc0) != 0x80)
+            return 0;
+		
+        /* Check for overlong sequences for each different length */
+        switch (ab) {
+				/* Check for xx00 000x */
+			case 1:
+				if ((c & 0x3e) == 0) return 0;
+				continue;   /* We know there aren't any more bytes to check */
+				
+				/* Check for 1110 0000, xx0x xxxx */
+			case 2:
+				if (c == 0xe0 && (*p & 0x20) == 0) return 0;
+				break;
+				
+				/* Check for 1111 0000, xx00 xxxx */
+			case 3:
+				if (c == 0xf0 && (*p & 0x30) == 0) return 0;
+				break;
+				
+				/* Check for 1111 1000, xx00 0xxx */
+			case 4:
+				if (c == 0xf8 && (*p & 0x38) == 0) return 0;
+				break;
+				
+				/* Check for leading 0xfe or 0xff,
+				 and then for 1111 1100, xx00 00xx */
+			case 5:
+				if (c == 0xfe || c == 0xff ||
+					(c == 0xfc && (*p & 0x3c) == 0)) return 0;
+				break;
+        }
+		
+        /* Check for valid bytes after the 2nd, if any; all must start 10 */
+        while (--ab > 0) {
+            if ((*(++p) & 0xc0) != 0x80) return 0;
+        }
+    }
+	
+    return 1;
+}
+
diff --git a/engines/sludge/CommonCode/utf8.h b/engines/sludge/CommonCode/utf8.h
new file mode 100644
index 0000000..85989ee
--- /dev/null
+++ b/engines/sludge/CommonCode/utf8.h
@@ -0,0 +1,75 @@
+#include <stdint.h>
+#include <stdarg.h>
+
+/* is c the start of a utf8 sequence? */
+#define isutf(c) (((c)&0xC0)!=0x80)
+
+/* convert UTF-8 data to wide character */
+int u8_toucs(uint32_t *dest, int sz, char *src, int srcsz);
+
+/* the opposite conversion */
+int u8_toutf8(char *dest, int sz, uint32_t *src, int srcsz);
+
+/* single character to UTF-8 */
+int u8_wc_toutf8(char *dest, uint32_t ch);
+
+/* character number to byte offset */
+int u8_offset(char *str, int charnum);
+
+/* byte offset to character number */
+int u8_charnum(char *s, int offset);
+
+/* return next character, updating an index variable */
+uint32_t u8_nextchar(const char *s, int *i);
+
+/* move to next character */
+void u8_inc(char *s, int *i);
+
+/* move to previous character */
+void u8_dec(char *s, int *i);
+
+/* returns length of next utf-8 sequence */
+int u8_seqlen(char *s);
+
+/* assuming src points to the character after a backslash, read an
+   escape sequence, storing the result in dest and returning the number of
+   input characters processed */
+int u8_read_escape_sequence(char *src, uint32_t *dest);
+
+/* given a wide character, convert it to an ASCII escape sequence stored in
+   buf, where buf is "sz" bytes. returns the number of characters output. */
+int u8_escape_wchar(char *buf, int sz, uint32_t ch);
+
+/* convert a string "src" containing escape sequences to UTF-8 */
+int u8_unescape(char *buf, int sz, char *src);
+
+/* convert UTF-8 "src" to ASCII with escape sequences.
+   if escape_quotes is nonzero, quote characters will be preceded by
+   backslashes as well. */
+int u8_escape(char *buf, int sz, char *src, int escape_quotes);
+
+/* utility predicates used by the above */
+int octal_digit(char c);
+int hex_digit(char c);
+
+/* return a pointer to the first occurrence of ch in s, or NULL if not
+   found. character index of found character returned in *charn. */
+char *u8_strchr(char *s, uint32_t ch, int *charn);
+
+/* same as the above, but searches a buffer of a given size instead of
+   a NUL-terminated string. */
+char *u8_memchr(char *s, uint32_t ch, size_t sz, int *charn);
+
+/* count the number of characters in a UTF-8 string */
+int u8_strlen(char *s);
+
+int u8_is_locale_utf8(char *locale);
+
+/* printf where the format string and arguments may be in UTF-8.
+   you can avoid this function and just use ordinary printf() if the current
+   locale is UTF-8. */
+int u8_vprintf(char *fmt, va_list ap);
+int u8_printf(char *fmt, ...);
+
+
+int u8_isvalid(const char *input);
diff --git a/engines/sludge/CommonCode/version.h b/engines/sludge/CommonCode/version.h
new file mode 100644
index 0000000..2b640a0
--- /dev/null
+++ b/engines/sludge/CommonCode/version.h
@@ -0,0 +1,13 @@
+#define MAJOR_VERSION 2
+#define MINOR_VERSION 2
+#define RELEASE_VERSION 1
+#define BUILD_VERSION 208
+#define TEXT_VERSION "2.2.1"
+#define WHOLE_VERSION (MAJOR_VERSION * 256 + MINOR_VERSION) // This version
+#define MINIM_VERSION (1             * 256 + 2)             // Earliest version of games the engine can run
+
+#define COPYRIGHT_TEXT "\251 Hungry Software and contributors 2000-2014"
+
+#define VERSION(a,b)    (a * 256 + b)
+
+extern int gameVersion;
diff --git a/engines/sludge/allfiles.h b/engines/sludge/allfiles.h
new file mode 100644
index 0000000..9478da5
--- /dev/null
+++ b/engines/sludge/allfiles.h
@@ -0,0 +1,32 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_ALLFILES_H
+#define SLUDGE_ALLFILES_H
+
+#include "common/system.h"
+
+//#define debuggy2 int
+#define IN_THE_CENTRE 65535
+typedef unsigned char byte;
+
+#endif
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
new file mode 100644
index 0000000..ed71770
--- /dev/null
+++ b/engines/sludge/backdrop.cpp
@@ -0,0 +1,1753 @@
+/* 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.
+ *
+ */
+
+#if 0
+#if defined __unix__ && !(defined __APPLE__)
+#include <png.h>
+#else
+#include <libpng/png.h>
+#endif
+
+#include <stdlib.h>
+#include <stdint.h>
+
+#if !defined(HAVE_GLES2)
+#include "GLee.h"
+#else
+#include <GLES2/gl2.h>
+#endif
+#endif
+
+#include "allfiles.h"
+#include "debug.h"
+#include "newfatal.h"
+#include "colours.h"
+#include "fileset.h"
+#include "cursors.h"
+#include "backdrop.h"
+#include "language.h"
+#include "moreio.h"
+#include "variable.h"
+#include "zbuffer.h"
+#include "graphics.h"
+#include "line.h"
+#include "people.h"
+#include "talk.h"
+#include "sludger.h"
+#include "statusba.h"
+
+#include "CommonCode/version.h"
+
+extern inputType input;
+
+
+bool freeze();
+void unfreeze(bool);    // Because FREEZE.H needs a load of other includes
+
+#if 0
+GLubyte *backdropTexture = NULL;
+GLuint backdropTextureName = 0;
+bool backdropExists = false;
+GLfloat backdropTexW = 1.0;
+GLfloat backdropTexH = 1.0;
+
+texture lightMap;
+
+GLuint snapshotTextureName = 0;
+#endif
+
+float snapTexW = 1.0;
+float snapTexH = 1.0;
+
+int lightMapMode = LIGHTMAPMODE_PIXEL;
+parallaxLayer *parallaxStuff = NULL;
+int cameraPX = 0, cameraPY = 0;
+
+unsigned int sceneWidth, sceneHeight;
+int lightMapNumber;
+unsigned int currentBlankColour = makeColour(0, 0, 0);
+
+extern int cameraX, cameraY;
+extern float cameraZoom;
+
+void nosnapshot() {
+#if 0
+	deleteTextures(1, &snapshotTextureName);
+	snapshotTextureName = 0;
+#endif
+}
+
+#if ALLOW_FILE
+void saveSnapshot(FILE *fp) {
+	if (snapshotTextureName) {
+		fputc(1, fp);               // 1 for snapshot follows
+		saveCoreHSI(fp, snapshotTextureName, winWidth, winHeight);
+	} else {
+		fputc(0, fp);
+	}
+}
+#endif
+
+bool snapshot() {
+
+	nosnapshot();
+	if (! freeze()) return false;
+#if 0
+	setPixelCoords(true);
+	glGenTextures(1, &snapshotTextureName);
+
+	int w = winWidth;
+	int h = winHeight;
+	if (! NPOT_textures) {
+		w = getNextPOT(winWidth);
+		h = getNextPOT(winHeight);
+		snapTexW = ((double)winWidth) / w;
+		snapTexH = ((double)winHeight) / h;
+	}
+
+	glBindTexture(GL_TEXTURE_2D, snapshotTextureName);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, snapshotTextureName);
+
+	// Render scene
+	glDepthMask(GL_TRUE);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen
+	glDepthMask(GL_FALSE);
+
+	drawBackDrop();                 // Draw the room
+	drawZBuffer(cameraX, cameraY, false);
+
+	glEnable(GL_DEPTH_TEST);
+
+	drawPeople();                   // Then add any moving characters...
+
+	glDisable(GL_DEPTH_TEST);
+
+	viewSpeech();                   // ...and anything being said
+	drawStatusBar();
+	// Copy Our ViewPort To The Texture
+	copyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewportOffsetX, viewportOffsetY, winWidth, winHeight, snapshotTextureName);
+
+	setPixelCoords(false);
+#endif
+	unfreeze(false);
+	return true;
+}
+
+#if ALLOW_FILE
+bool restoreSnapshot(FILE *fp) {
+	unsigned int picWidth = get2bytes(fp);
+	unsigned int picHeight = get2bytes(fp);
+
+	if ((picWidth != winWidth) || (picHeight != winHeight))
+		return false;
+
+	unsigned int t1, t2, n;
+	unsigned short c;
+
+	GLubyte *target;
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(picWidth);
+		picHeight = getNextPOT(picHeight);
+		snapTexW = ((double)winWidth) / picWidth;
+		snapTexH = ((double)winHeight) / picHeight;
+	}
+	GLubyte *snapshotTexture = new GLubyte [picHeight * picWidth * 4];
+	if (! snapshotTexture) return fatal("Out of memory while restoring snapshot.");
+
+	for (t2 = 0; t2 < winHeight; t2 ++) {
+		t1 = 0;
+		while (t1 < winWidth) {
+			c = (unsigned short) get2bytes(fp);
+			if (c & 32) {
+				n = fgetc(fp) + 1;
+				c -= 32;
+			} else {
+				n = 1;
+			}
+			while (n --) {
+				target = snapshotTexture + 4 * picWidth * t2 + t1 * 4;
+				target[0] = (GLubyte) redValue(c);
+				target[1] = (GLubyte) greenValue(c);
+				target[2] = (GLubyte) blueValue(c);
+				target[3] = (GLubyte) 255;
+				t1++;
+			}
+		}
+	}
+
+	if (! snapshotTextureName) glGenTextures(1, &snapshotTextureName);
+	glBindTexture(GL_TEXTURE_2D, snapshotTextureName);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, snapshotTexture, snapshotTextureName);
+
+	delete snapshotTexture;
+	snapshotTexture = NULL;
+
+	return true;
+}
+#endif
+
+void killBackDrop() {
+#if 0
+	deleteTextures(1, &backdropTextureName);
+	backdropTextureName = 0;
+	backdropExists = false;
+#endif
+}
+
+void killLightMap() {
+#if 0
+	deleteTextures(1, &lightMap.name);
+	lightMap.name = 0;
+	if (lightMap.data) {
+		delete lightMap.data;
+		lightMap.data = NULL;
+	}
+	lightMapNumber = 0;
+#endif
+}
+
+void killParallax() {
+#if 0
+	while (parallaxStuff) {
+
+		parallaxLayer *k = parallaxStuff;
+		parallaxStuff = k -> next;
+
+		// Now kill the image
+		deleteTextures(1, &k -> textureName);
+		delete k -> texture;
+		delete k;
+		k = NULL;
+	}
+#endif
+}
+
+bool reserveBackdrop() {
+	cameraX = 0;
+	cameraY = 0;
+	input.mouseX = (int)((float)input.mouseX * cameraZoom);
+	input.mouseY = (int)((float)input.mouseY * cameraZoom);
+	cameraZoom = 1.0;
+	input.mouseX = (int)((float)input.mouseX / cameraZoom);
+	input.mouseY = (int)((float)input.mouseY / cameraZoom);
+	setPixelCoords(false);
+	int picWidth = sceneWidth;
+	int picHeight = sceneHeight;
+#if 0
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+	if (backdropTexture) delete backdropTexture;
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(sceneWidth);
+		picHeight = getNextPOT(sceneHeight);
+		backdropTexW = ((double)sceneWidth) / picWidth;
+		backdropTexH = ((double)sceneHeight) / picHeight;
+	}
+	backdropTexture = new GLubyte [picWidth * picHeight * 4];
+	if (! checkNew(backdropTexture)) return false;
+
+	if (! backdropTextureName) glGenTextures(1, &backdropTextureName);
+	glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (gameSettings.antiAlias < 0) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	} else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	}
+
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, backdropTextureName);
+#endif
+	return true;
+}
+
+bool resizeBackdrop(int x, int y) {
+	killLightMap();
+	killBackDrop();
+	killParallax();
+	killZBuffer();
+	sceneWidth = x;
+	sceneHeight = y;
+	return reserveBackdrop();
+}
+
+void loadBackDrop(int fileNum, int x, int y) {
+	setResourceForFatal(fileNum);
+#if ALLOW_FILE
+	if (! openFileFromNum(fileNum)) {
+		fatal("Can't load overlay image");
+		return;
+	}
+
+	if (! loadHSI(bigDataFile, x, y, false)) {
+		char mess[200];
+		sprintf(mess, "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight);
+		fatal(mess);
+	}
+
+	finishAccess();
+#endif
+	setResourceForFatal(-1);
+}
+
+void mixBackDrop(int fileNum, int x, int y) {
+#if ALLOW_FILE
+	setResourceForFatal(fileNum);
+	if (! openFileFromNum(fileNum)) {
+		fatal("Can't load overlay image");
+		return;
+	}
+
+	if (! mixHSI(bigDataFile, x, y)) {
+		fatal("Can't paste overlay image outside screen dimensions");
+	}
+
+	finishAccess();
+#endif
+	setResourceForFatal(-1);
+}
+
+void blankScreen(int x1, int y1, int x2, int y2) {
+
+	if (y1 < 0) y1 = 0;
+	if (x1 < 0) x1 = 0;
+	if (x2 > (int) sceneWidth) x2 = (int)sceneWidth;
+	if (y2 > (int) sceneHeight) y2 = (int)sceneHeight;
+
+	int picWidth = x2 - x1;
+	int picHeight = y2 - y1;
+#if 0
+	setPixelCoords(true);
+
+	int xoffset = 0;
+	while (xoffset < picWidth) {
+		int w = (picWidth - xoffset < viewportWidth) ? picWidth - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < picHeight) {
+			int h = (picHeight - yoffset < viewportHeight) ? picHeight - yoffset : viewportHeight;
+
+			// Render the scene
+
+
+
+			const GLfloat vertices[] = {
+				-10.325f, -1.325f, 0.0f,
+				w + 1.325f, -1.325f, 0.0f,
+				-10.325f, h + 1.325f, 0.0f,
+				w + 1.325f, h + 1.325f, 0.0f
+			};
+
+			glUseProgram(shader.color);
+
+			setPMVMatrix(shader.color);
+			setPrimaryColor(redValue(currentBlankColour) / 255.0f, greenValue(currentBlankColour) / 255.0f, blueValue(currentBlankColour) / 255.0f, 1.0f);
+			drawQuad(shader.color, vertices, 0);
+
+			glUseProgram(0);
+
+			// Copy Our ViewPort To The Texture
+			copyTexSubImage2D(GL_TEXTURE_2D, 0, x1 + xoffset, y1 + yoffset, viewportOffsetX, viewportOffsetY, w, h, backdropTextureName);
+
+			yoffset += viewportHeight;
+		}
+		xoffset += viewportWidth;
+	}
+
+	setPixelCoords(false);
+#endif
+}
+
+void hardScroll(int distance) {
+	if (abs(distance) >= sceneHeight) {
+		blankScreen(0, 0, sceneWidth, sceneHeight);
+		return;
+	}
+
+	if (! distance) return;
+#if 0
+	const GLfloat backdropTexCoords[] = {
+		0.0f, 0.0f,
+		backdropTexW, 0.0f,
+		0.0f, backdropTexH,
+		backdropTexW, backdropTexH
+	};
+
+	setPixelCoords(true);
+
+	unsigned int xoffset = 0;
+	while (xoffset < sceneWidth) {
+		int w = (sceneWidth - xoffset < viewportWidth) ? sceneWidth - xoffset : viewportWidth;
+
+		unsigned int yoffset = 0;
+		while (yoffset < sceneHeight) {
+			int h = (sceneHeight - yoffset < viewportHeight) ? sceneHeight - yoffset : viewportHeight;
+
+
+			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
+
+			// Render the backdrop
+			glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - distance - yoffset, 0.,
+				(GLfloat)sceneWidth - xoffset, (GLfloat) - distance - yoffset, 0.,
+				(GLfloat) - xoffset, (GLfloat)sceneHeight - distance - yoffset, 0.,
+				(GLfloat)sceneWidth - xoffset, (GLfloat)sceneHeight - distance - yoffset, 0.
+			};
+
+
+			glUseProgram(shader.texture);
+
+			setPMVMatrix(shader.texture);
+
+			drawQuad(shader.texture, vertices, 1, backdropTexCoords);
+
+			glUseProgram(0);
+
+			// Copy Our ViewPort To The Texture
+			copyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, viewportOffsetX, viewportOffsetY, w, h, backdropTextureName);
+
+			yoffset += viewportHeight;
+		}
+		xoffset += viewportWidth;
+	}
+	setPixelCoords(false);
+#endif
+}
+
+void drawVerticalLine(unsigned int x, unsigned int y1, unsigned int y2) {
+	drawLine(x, y1, x, y2);
+}
+
+void drawHorizontalLine(unsigned int x1, unsigned int y, unsigned int x2) {
+	drawLine(x1, y, x2, y);
+}
+
+void darkScreen() {
+	setPixelCoords(true);
+
+	int xoffset = 0;
+	while (xoffset < sceneWidth) {
+		int w = (sceneWidth - xoffset < viewportWidth) ? sceneWidth - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < sceneHeight) {
+			int h = (sceneHeight - yoffset < viewportHeight) ? sceneHeight - yoffset : viewportHeight;
+
+			// Render the scene - first the old backdrop
+#if 0
+			//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+			glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat)sceneWidth - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat) - xoffset, (GLfloat)sceneHeight - yoffset, 0.,
+				(GLfloat)sceneWidth - xoffset, (GLfloat)sceneHeight - yoffset, 0.
+			};
+
+			const GLfloat texCoords[] = {
+				0.0f, 0.0f,
+				backdropTexW, 0.0f,
+				0.0f, backdropTexH,
+				backdropTexW, backdropTexH
+			};
+
+
+			glUseProgram(shader.texture);
+
+			setPMVMatrix(shader.texture);
+
+			drawQuad(shader.texture, vertices, 1, texCoords);
+
+			// Then the darkness
+			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
+
+			glEnable(GL_BLEND);
+
+			glUseProgram(shader.color);
+
+			setPMVMatrix(shader.color);
+			setPrimaryColor(0.0f, 0.0f, 0.0f, 0.5f);
+			drawQuad(shader.color, vertices, 0);
+
+			glUseProgram(0);
+
+			glDisable(GL_BLEND);
+			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+			// Copy Our ViewPort To The Texture
+			copyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, viewportOffsetX, viewportOffsetY, w, h, backdropTextureName);
+
+			yoffset += h;
+
+			glClear(GL_COLOR_BUFFER_BIT);
+#endif
+		}
+		xoffset += w;
+	}
+
+
+	setPixelCoords(false);
+}
+
+
+
+inline int sortOutPCamera(int cX, int fX, int sceneMax, int boxMax) {
+	return (fX == 65535) ?
+	       (sceneMax ? ((cX * boxMax) / sceneMax) : 0)
+	       :
+	       ((cX * fX) / 100);
+}
+
+
+void drawBackDrop() {
+#if 0
+	setPrimaryColor(1.0, 1.0, 1.0, 1.0);
+
+	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+	glEnable(GL_BLEND);
+
+	glUseProgram(shader.smartScaler);
+	GLuint uniform = glGetUniformLocation(shader.smartScaler, "useLightTexture");
+	if (uniform >= 0) glUniform1i(uniform, 0);
+
+	setPMVMatrix(shader.smartScaler);
+
+	if (gameSettings.antiAlias == 1) {
+		glUniform1i(glGetUniformLocation(shader.smartScaler, "antialias"), 1);
+	} else {
+		glUniform1i(glGetUniformLocation(shader.smartScaler, "antialias"), 0);
+	}
+
+	if (parallaxStuff) {
+		parallaxLayer *ps = parallaxStuff;
+
+		while (ps->next) ps = ps->next;
+
+		while (ps) {
+			ps -> cameraX = sortOutPCamera(cameraX, ps -> fractionX, (int)(sceneWidth - (float)winWidth / cameraZoom), (int)(ps -> width - (float)winWidth / cameraZoom));
+			ps -> cameraY = sortOutPCamera(cameraY, ps -> fractionY, (int)(sceneHeight - (float)winHeight / cameraZoom), (int)(ps -> height - (float)winHeight / cameraZoom));
+			glBindTexture(GL_TEXTURE_2D, ps->textureName);
+
+			float w = (ps->wrapS) ? sceneWidth : ps->width;
+			float h = (ps->wrapT) ? sceneHeight : ps->height;
+			float texw;
+			float texh;
+			if (! NPOT_textures) {
+				texw = (ps->wrapS) ? (float) sceneWidth / ps->width : (float) ps->width / getNextPOT(ps->width);
+				texh = (ps->wrapT) ? (float) sceneHeight / ps->height : (float) ps->height / getNextPOT(ps->height);
+			} else {
+				texw = (ps->wrapS) ? (float) sceneWidth / ps->width : 1.0;
+				texh = (ps->wrapT) ? (float) sceneHeight / ps->height : 1.0;
+			}
+
+			const GLfloat vertices[] = {
+				(GLfloat) - ps -> cameraX, (GLfloat) - ps -> cameraY, 0.1f,
+				w - ps -> cameraX, (GLfloat) - ps -> cameraY, 0.1f,
+				(GLfloat) - ps -> cameraX, h - ps -> cameraY, 0.1f,
+				w - ps -> cameraX, h - ps -> cameraY, 0.1f
+			};
+
+			const GLfloat texCoords[] = {
+				0.0f, 0.0f,
+				texw, 0.0f,
+				0.0f, texh,
+				texw, texh
+			};
+			drawQuad(shader.smartScaler, vertices, 1, texCoords);
+
+			ps = ps -> prev;
+		}
+	}
+
+	glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+
+	const GLfloat backdropTexCoords[] = {
+		0.0f, 0.0f,
+		backdropTexW, 0.0f,
+		0.0f, backdropTexH,
+		backdropTexW, backdropTexH
+	};
+
+	const GLfloat vertices[] = {
+		(GLfloat) - cameraX, (GLfloat) - cameraY, 0.,
+		(GLfloat)sceneWidth - (GLfloat)cameraX, (GLfloat) - cameraY, 0.,
+		(GLfloat) - cameraX, (GLfloat)sceneHeight - (GLfloat)cameraY, 0.,
+		(GLfloat)sceneWidth - (GLfloat)cameraX, (GLfloat)sceneHeight - (GLfloat)cameraY, 0.
+	};
+
+	drawQuad(shader.smartScaler, vertices, 1, backdropTexCoords);
+
+	glDisable(GL_BLEND);
+
+	glUseProgram(0);
+#endif
+}
+
+bool loadLightMap(int v) {
+	int newPicWidth, newPicHeight;
+#if ALLOW_FILE
+	setResourceForFatal(v);
+	if (! openFileFromNum(v)) return fatal("Can't open light map.");
+	long file_pointer = ftell(bigDataFile);
+
+	png_structp png_ptr;
+	png_infop info_ptr, end_info;
+
+
+	int fileIsPNG = true;
+
+	// Is this a PNG file?
+
+	char tmp[10];
+	size_t bytes_read = fread(tmp, 1, 8, bigDataFile);
+	if (bytes_read != 8 && ferror(bigDataFile)) {
+		debugOut("Reading error in loadLightMap.\n");
+	}
+
+	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
+		// No, it's old-school HSI
+		fileIsPNG = false;
+		fseek(bigDataFile, file_pointer, SEEK_SET);
+
+		newPicWidth = lightMap.w = get2bytes(bigDataFile);
+		newPicHeight = lightMap.h = get2bytes(bigDataFile);
+	} else {
+		// Read the PNG header
+
+		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+		if (!png_ptr) {
+			return false;
+		}
+
+		info_ptr = png_create_info_struct(png_ptr);
+		if (!info_ptr) {
+			png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+			return false;
+		}
+
+		end_info = png_create_info_struct(png_ptr);
+		if (!end_info) {
+			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+			return false;
+		}
+		png_init_io(png_ptr, bigDataFile);      // Tell libpng which file to read
+		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+
+		png_read_info(png_ptr, info_ptr);
+
+		png_uint_32 width, height;
+		int bit_depth, color_type, interlace_type, compression_type, filter_method;
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		newPicWidth = lightMap.w = width;
+		newPicHeight = lightMap.h = height;
+
+		if (bit_depth < 8) png_set_packing(png_ptr);
+		png_set_expand(png_ptr);
+		if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
+		if (bit_depth == 16) png_set_strip_16(png_ptr);
+
+		png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
+
+		png_read_update_info(png_ptr, info_ptr);
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+
+	}
+
+	if (lightMapMode == LIGHTMAPMODE_HOTSPOT) {
+		if (lightMap.w != sceneWidth || lightMap.h != sceneHeight) {
+			return fatal("Light map width and height don't match scene width and height. That is required for lightmaps in HOTSPOT mode.");
+		}
+	}
+
+	if (! NPOT_textures) {
+		newPicWidth = getNextPOT(lightMap.w);
+		newPicHeight = getNextPOT(lightMap.h);
+		lightMap.texW = (double) lightMap.w / newPicWidth;
+		lightMap.texH = (double) lightMap.h / newPicHeight;
+	} else {
+		lightMap.texW = 1.0;
+		lightMap.texH = 1.0;
+	}
+
+	killLightMap();
+	lightMapNumber = v;
+#if 0
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+#endif
+	if (lightMap.data) delete [] lightMap.data;
+
+	lightMap.data = new GLubyte [newPicWidth * newPicHeight * 4];
+	if (! lightMap.data) {
+		return fatal("Out of memory loading light map.");
+	}
+
+	int t1, t2, n;
+	unsigned short c;
+	GLubyte *target;
+
+	if (fileIsPNG) {
+		unsigned char *row_pointers[lightMap.h];
+		for (int i = 0; i < lightMap.h; i++)
+			row_pointers[i] = lightMap.data + 4 * i * newPicWidth;
+
+		png_read_image(png_ptr, (png_byte **) row_pointers);
+		png_read_end(png_ptr, NULL);
+		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+	} else {
+
+		for (t2 = 0; t2 < lightMap.h; t2 ++) {
+			t1 = 0;
+			while (t1 < lightMap.w) {
+				c = (unsigned short) get2bytes(bigDataFile);
+				if (c & 32) {
+					n = fgetc(bigDataFile) + 1;
+					c -= 32;
+				} else {
+					n = 1;
+				}
+				while (n --) {
+					target = lightMap.data + 4 * newPicWidth * t2 + t1 * 4;
+					target[0] = (GLubyte) redValue(c);
+					target[1] = (GLubyte) greenValue(c);
+					target[2] = (GLubyte) blueValue(c);
+					target[3] = (GLubyte) 255;
+					t1++;
+				}
+			}
+		}
+	}
+#if 0
+	if (! lightMap.name) glGenTextures(1, &lightMap.name);
+	glBindTexture(GL_TEXTURE_2D, lightMap.name);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+#endif
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, newPicWidth, newPicHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightMap.data, lightMap.name);
+
+	finishAccess();
+
+#endif
+	setResourceForFatal(-1);
+
+	return true;
+}
+
+void reloadParallaxTextures() {
+#if 0
+	parallaxLayer *nP = parallaxStuff;
+	if (! nP) return;
+
+	while (nP) {
+		//fprintf (stderr, "Reloading parallax. (%d, %d) ", nP->width, nP->height);
+		nP->textureName = 0;
+
+		glGenTextures(1, &nP->textureName);
+		glBindTexture(GL_TEXTURE_2D, nP->textureName);
+		if (nP -> wrapS)
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+		else
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+		if (nP -> wrapT)
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+		else
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+		if (gameSettings.antiAlias < 0) {
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		} else {
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		}
+
+		if (! NPOT_textures) {
+			texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getNextPOT(nP->width), getNextPOT(nP->height), 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName);
+		} else {
+			texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nP->width, nP->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName);
+		}
+
+		nP = nP->next;
+	}
+#endif
+}
+
+bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) {
+
+#if ALLOW_FILE
+	setResourceForFatal(v);
+	if (! openFileFromNum(v)) return fatal("Can't open parallax image");
+
+	parallaxLayer *nP = new parallaxLayer;
+	if (! checkNew(nP)) return false;
+
+	nP -> next = parallaxStuff;
+	parallaxStuff = nP;
+	if (nP -> next) {
+		nP -> next -> prev = nP;
+	}
+	nP -> prev = NULL;
+
+	int picWidth;
+	int picHeight;
+
+	long file_pointer = ftell(bigDataFile);
+
+	png_structp png_ptr;
+	png_infop info_ptr, end_info;
+
+
+	int fileIsPNG = true;
+
+	// Is this a PNG file?
+
+	char tmp[10];
+	size_t bytes_read = fread(tmp, 1, 8, bigDataFile);
+	if (bytes_read != 8 && ferror(bigDataFile)) {
+		debugOut("Reading error in loadParallax.\n");
+	}
+	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
+		// No, it's old-school HSI
+		fileIsPNG = false;
+		fseek(bigDataFile, file_pointer, SEEK_SET);
+
+		picWidth = nP -> width = get2bytes(bigDataFile);
+		picHeight = nP -> height = get2bytes(bigDataFile);
+	} else {
+		// Read the PNG header
+
+		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+		if (!png_ptr) {
+			return false;
+		}
+
+		info_ptr = png_create_info_struct(png_ptr);
+		if (!info_ptr) {
+			png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+			return false;
+		}
+
+		end_info = png_create_info_struct(png_ptr);
+		if (!end_info) {
+			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+			return false;
+		}
+		png_init_io(png_ptr, bigDataFile);      // Tell libpng which file to read
+		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+
+		png_read_info(png_ptr, info_ptr);
+
+		png_uint_32 width, height;
+		int bit_depth, color_type, interlace_type, compression_type, filter_method;
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		picWidth = nP -> width = width;
+		picHeight = nP -> height = height;
+
+		if (bit_depth < 8) png_set_packing(png_ptr);
+		png_set_expand(png_ptr);
+		if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
+		if (bit_depth == 16) png_set_strip_16(png_ptr);
+
+		png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
+
+		png_read_update_info(png_ptr, info_ptr);
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+
+	}
+
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(picWidth);
+		picHeight = getNextPOT(picHeight);
+	}
+
+	nP -> fileNum = v;
+	nP -> fractionX = fracX;
+	nP -> fractionY = fracY;
+
+	if (fracX == 65535) {
+		nP -> wrapS = false;
+		if (nP -> width < winWidth) {
+			fatal("For AUTOFIT parallax backgrounds, the image must be at least as wide as the game window/screen.");
+			return false;
+		}
+	} else {
+		nP -> wrapS = true;
+	}
+
+	if (fracY == 65535) {
+		nP -> wrapT = false;
+		if (nP -> height < winHeight) {
+			fatal("For AUTOFIT parallax backgrounds, the image must be at least as tall as the game window/screen.");
+			return false;
+		}
+	} else {
+		nP -> wrapT = true;
+	}
+
+	nP -> texture = new GLubyte [picHeight * picWidth * 4];
+	if (! checkNew(nP -> texture)) return false;
+
+	if (fileIsPNG) {
+		unsigned char *row_pointers[nP -> height];
+		for (int i = 0; i < nP -> height; i++)
+			row_pointers[i] = nP -> texture + 4 * i * picWidth;
+
+		png_read_image(png_ptr, (png_byte **) row_pointers);
+		png_read_end(png_ptr, NULL);
+		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+	} else {
+
+		int t1, t2, n;
+		unsigned short c;
+		GLubyte *target;
+
+		for (t2 = 0; t2 < nP -> height; t2 ++) {
+			t1 = 0;
+			while (t1 < nP -> width) {
+				c = (unsigned short) get2bytes(bigDataFile);
+				if (c & 32) {
+					n = fgetc(bigDataFile) + 1;
+					c -= 32;
+				} else {
+					n = 1;
+				}
+				while (n--) {
+					target = nP -> texture + 4 * picWidth * t2 + t1 * 4;
+					if (c == 63519 || c == 2015) {
+						target[0] = (GLubyte) 0;
+						target[1] = (GLubyte) 0;
+						target[2] = (GLubyte) 0;
+						target[3] = (GLubyte) 0;
+					} else {
+						target[0] = (GLubyte) redValue(c);
+						target[1] = (GLubyte) greenValue(c);
+						target[2] = (GLubyte) blueValue(c);
+						target[3] = (GLubyte) 255;
+					}
+					t1 ++;
+				}
+			}
+		}
+	}
+
+	glGenTextures(1, &nP->textureName);
+	glBindTexture(GL_TEXTURE_2D, nP->textureName);
+	if (nP -> wrapS)
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	else
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	if (nP -> wrapT)
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+	else
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+	if (gameSettings.antiAlias < 0) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	} else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	}
+
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName);
+
+	finishAccess();
+#endif
+	setResourceForFatal(-1);
+	return true;
+}
+
+extern int viewportOffsetX, viewportOffsetY;
+
+#if ALLOW_FILE
+bool loadHSI(FILE *fp, int x, int y, bool reserve) {
+
+	int t1, t2, n;
+	unsigned short c;
+	GLubyte *target;
+	int32_t transCol = reserve ? -1 : 63519;
+	int picWidth;
+	int picHeight;
+	int realPicWidth, realPicHeight;
+	long file_pointer = ftell(fp);
+
+	png_structp png_ptr;
+	png_infop info_ptr, end_info;
+
+
+	int fileIsPNG = true;
+
+	// Is this a PNG file?
+
+	char tmp[10];
+	size_t bytes_read = fread(tmp, 1, 8, fp);
+	if (bytes_read != 8 && ferror(fp)) {
+		debugOut("Reading error in loadHSI.\n");
+	}
+	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
+		// No, it's old-school HSI
+		fileIsPNG = false;
+		fseek(fp, file_pointer, SEEK_SET);
+
+		picWidth = realPicWidth = get2bytes(fp);
+		picHeight = realPicHeight = get2bytes(fp);
+	} else {
+		// Read the PNG header
+
+		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+		if (!png_ptr) {
+			return false;
+		}
+
+		info_ptr = png_create_info_struct(png_ptr);
+		if (!info_ptr) {
+			png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+			return false;
+		}
+
+		end_info = png_create_info_struct(png_ptr);
+		if (!end_info) {
+			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+			return false;
+		}
+		png_init_io(png_ptr, fp);       // Tell libpng which file to read
+		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+
+		png_read_info(png_ptr, info_ptr);
+
+		png_uint_32 width, height;
+		int bit_depth, color_type, interlace_type, compression_type, filter_method;
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		picWidth = realPicWidth = width;
+		picHeight = realPicHeight = height;
+
+		if (bit_depth < 8) png_set_packing(png_ptr);
+		png_set_expand(png_ptr);
+		if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
+		if (bit_depth == 16) png_set_strip_16(png_ptr);
+
+		png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
+
+		png_read_update_info(png_ptr, info_ptr);
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+
+	}
+
+
+	GLfloat texCoordW = 1.0;
+	GLfloat texCoordH = 1.0;
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(picWidth);
+		picHeight = getNextPOT(picHeight);
+		texCoordW = ((double)realPicWidth) / picWidth;
+		texCoordH = ((double)realPicHeight) / picHeight;
+	}
+
+	if (reserve) {
+		if (! resizeBackdrop(realPicWidth, realPicHeight)) return false;
+	}
+
+	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
+	if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1;
+	if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false;
+
+	if (fileIsPNG) {
+		unsigned char *row_pointers[realPicHeight];
+		for (int i = 0; i < realPicHeight; i++)
+			row_pointers[i] = backdropTexture + 4 * i * picWidth;
+
+		png_read_image(png_ptr, (png_byte **) row_pointers);
+		png_read_end(png_ptr, NULL);
+		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+	} else {
+		for (t2 = 0; t2 < realPicHeight; t2 ++) {
+			t1 = 0;
+			while (t1 < realPicWidth) {
+				c = (unsigned short) get2bytes(fp);
+				if (c & 32) {
+					n = fgetc(fp) + 1;
+					c -= 32;
+				} else {
+					n = 1;
+				}
+				while (n --) {
+					target = backdropTexture + 4 * picWidth * t2 + t1 * 4;
+					if (c == transCol || c == 2015) {
+						target[0] = (GLubyte) 0;
+						target[1] = (GLubyte) 0;
+						target[2] = (GLubyte) 0;
+						target[3] = (GLubyte) 0;
+					} else {
+						target[0] = (GLubyte) redValue(c);
+						target[1] = (GLubyte) greenValue(c);
+						target[2] = (GLubyte) blueValue(c);
+						target[3] = (GLubyte) 255;
+					}
+					t1++;
+				}
+			}
+		}
+	}
+
+	GLuint tmpTex;
+#if 0
+	glGenTextures(1, &tmpTex);
+	glBindTexture(GL_TEXTURE_2D, tmpTex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (gameSettings.antiAlias < 0) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	} else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	}
+#endif
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
+
+
+	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+
+	float btx1;
+	float btx2;
+	float bty1;
+	float bty2;
+	if (! NPOT_textures) {
+		btx1 = backdropTexW * x / sceneWidth;
+		btx2 = backdropTexW * (x + realPicWidth) / sceneWidth;
+		bty1 = backdropTexH * y / sceneHeight;
+		bty2 = backdropTexH * (y + realPicHeight) / sceneHeight;
+	} else {
+		btx1 = (float) x / sceneWidth;
+		btx2 = (float)(x + realPicWidth) / sceneWidth;
+		bty1 = (float) y / sceneHeight;
+		bty2 = (float)(y + realPicHeight) / sceneHeight;
+	}
+
+	const GLfloat btexCoords[] = {
+		btx1, bty1,
+		btx2, bty1,
+		btx1, bty2,
+		btx2, bty2
+	};
+
+	setPixelCoords(true);
+
+	int xoffset = 0;
+	while (xoffset < realPicWidth) {
+		int w = (realPicWidth - xoffset < viewportWidth) ? realPicWidth - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < realPicHeight) {
+			int h = (realPicHeight - yoffset < viewportHeight) ? realPicHeight - yoffset : viewportHeight;
+#if 0
+			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
+#endif
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat)realPicWidth - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat) - xoffset, (GLfloat) - yoffset + realPicHeight, 0.,
+				(GLfloat)realPicWidth - xoffset, (GLfloat) - yoffset + realPicHeight, 0.
+			};
+
+			const GLfloat texCoords[] = {
+				0.0f, 0.0f,
+				texCoordW, 0.0f,
+				0.0f, texCoordH,
+				texCoordW, texCoordH
+			};
+
+			if (backdropExists) {
+#if 0
+				// Render the sprite to the backdrop
+				// (using mulitexturing, so the old backdrop is seen where alpha < 1.0)
+				glActiveTexture(GL_TEXTURE2);
+				glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+				glActiveTexture(GL_TEXTURE0);
+
+				glUseProgram(shader.paste);
+				GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
+				if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
+#endif
+				setPMVMatrix(shader.paste);
+
+				setPrimaryColor(1.0, 1.0, 1.0, 1.0);
+#if 0
+				glBindTexture(GL_TEXTURE_2D, tmpTex);
+				//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+#endif
+				drawQuad(shader.paste, vertices, 3, texCoords, NULL, btexCoords);
+#if 0
+				glUseProgram(0);
+#endif
+			} else {
+				// It's all new - nothing special to be done.
+
+#if 0
+				glUseProgram(shader.texture);
+#endif
+				setPMVMatrix(shader.texture);
+#if 0
+				glBindTexture(GL_TEXTURE_2D, tmpTex);
+#endif
+				setPrimaryColor(1.0, 0.0, 0.0, 0.0);
+
+				drawQuad(shader.texture, vertices, 1, texCoords);
+
+#if 0
+				glUseProgram(0);
+#endif
+			}
+
+			// Copy Our ViewPort To The Texture
+			copyTexSubImage2D(GL_TEXTURE_2D, 0, x + xoffset, y + yoffset, viewportOffsetX, viewportOffsetY, w, h, backdropTextureName);
+
+			yoffset += viewportHeight;
+		}
+
+		xoffset += viewportWidth;
+	}
+	deleteTextures(1, &tmpTex);
+
+	setPixelCoords(false);
+
+	backdropExists = true;
+	return true;
+}
+
+bool mixHSI(FILE *fp, int x, int y) {
+	int realPicWidth, realPicHeight;
+	int picWidth;
+	int picHeight;
+
+	long file_pointer = ftell(fp);
+
+	png_structp png_ptr;
+	png_infop info_ptr, end_info;
+
+
+	int fileIsPNG = true;
+
+	// Is this a PNG file?
+	char tmp[10];
+	size_t bytes_read = fread(tmp, 1, 8, fp);
+	if (bytes_read != 8 && ferror(fp)) {
+		debugOut("Reading error in mixHSI.\n");
+	}
+	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
+		// No, it's old-school HSI
+		fileIsPNG = false;
+		fseek(fp, file_pointer, SEEK_SET);
+
+		picWidth = realPicWidth = get2bytes(fp);
+		picHeight = realPicHeight = get2bytes(fp);
+	} else {
+		// Read the PNG header
+
+		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+		if (!png_ptr) {
+			return false;
+		}
+
+		info_ptr = png_create_info_struct(png_ptr);
+		if (!info_ptr) {
+			png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+			return false;
+		}
+
+		end_info = png_create_info_struct(png_ptr);
+		if (!end_info) {
+			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+			return false;
+		}
+		png_init_io(png_ptr, fp);       // Tell libpng which file to read
+		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+
+		png_read_info(png_ptr, info_ptr);
+
+		png_uint_32 width, height;
+		int bit_depth, color_type, interlace_type, compression_type, filter_method;
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		picWidth = realPicWidth = width;
+		picHeight = realPicHeight = height;
+
+		if (bit_depth < 8) png_set_packing(png_ptr);
+		png_set_expand(png_ptr);
+		if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
+		if (bit_depth == 16) png_set_strip_16(png_ptr);
+
+		png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
+
+		png_read_update_info(png_ptr, info_ptr);
+		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+
+		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+
+	}
+
+	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
+	if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1;
+	if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false;
+
+	float btx1, tx1;
+	float btx2, tx2;
+	float bty1, ty1;
+	float bty2, ty2;
+
+	if (! NPOT_textures) {
+		tx1 = 0.0;
+		ty1 = 0.0;
+		tx2 = ((double)picWidth) / getNextPOT(picWidth);
+		ty2 = ((double)picHeight) / getNextPOT(picHeight);
+		picWidth = getNextPOT(picWidth);
+		picHeight = getNextPOT(picHeight);
+		btx1 = backdropTexW * x / sceneWidth;
+		btx2 = backdropTexW * (x + realPicWidth) / sceneWidth;
+		bty1 = backdropTexH * y / sceneHeight;
+		bty2 = backdropTexH * (y + realPicHeight) / sceneHeight;
+	} else {
+		tx1 = 0.0;
+		ty1 = 0.0;
+		tx2 = 1.0;
+		ty2 = 1.0;
+		btx1 = (float) x / sceneWidth;
+		btx2 = (float)(x + picWidth) / sceneWidth;
+		bty1 = (float) y / sceneHeight;
+		bty2 = (float)(y + picHeight) / sceneHeight;
+	}
+
+	const GLfloat texCoords[] = {
+		tx1, ty1,
+		tx2, ty1,
+		tx1, ty2,
+		tx2, ty2
+	};
+
+	const GLfloat btexCoords[] = {
+		btx1, bty1,
+		btx2, bty1,
+		btx1, bty2,
+		btx2, bty2
+	};
+
+	int t1, t2, n;
+	unsigned short c;
+	GLubyte *target;
+	int32_t transCol = 63519;
+
+
+	if (fileIsPNG) {
+		unsigned char *row_pointers[realPicHeight];
+		for (int i = 0; i < realPicHeight; i++)
+			row_pointers[i] = backdropTexture + 4 * i * picWidth;
+
+		png_read_image(png_ptr, (png_byte **) row_pointers);
+		png_read_end(png_ptr, NULL);
+		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+	} else {
+		for (t2 = 0; t2 < realPicHeight; t2 ++) {
+			t1 = 0;
+			while (t1 < realPicWidth) {
+				c = (unsigned short) get2bytes(fp);
+				if (c & 32) {
+					n = fgetc(fp) + 1;
+					c -= 32;
+				} else {
+					n = 1;
+				}
+				while (n --) {
+					target = backdropTexture + 4 * picWidth * t2 + t1 * 4;
+					if (c == transCol || c == 2015) {
+						target[0] = (GLubyte) 0;
+						target[1] = (GLubyte) 0;
+						target[2] = (GLubyte) 0;
+						target[3] = (GLubyte) 0;
+					} else {
+						target[0] = (GLubyte) redValue(c);
+						target[1] = (GLubyte) greenValue(c);
+						target[2] = (GLubyte) blueValue(c);
+						target[3] = (GLubyte) 255;
+					}
+					t1++;
+				}
+			}
+		}
+	}
+
+	GLuint tmpTex;
+#if 0
+	glGenTextures(1, &tmpTex);
+	glBindTexture(GL_TEXTURE_2D, tmpTex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (gameSettings.antiAlias < 0) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	} else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	}
+#endif
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
+
+
+	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+	setPixelCoords(true);
+
+
+	int xoffset = 0;
+	while (xoffset < realPicWidth) {
+		int w = (realPicWidth - xoffset < viewportWidth) ? realPicWidth - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < realPicHeight) {
+			int h = (realPicHeight - yoffset < viewportHeight) ? realPicHeight - yoffset : viewportHeight;
+#if 0
+			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
+
+			// Render the sprite to the backdrop
+			// (using mulitexturing, so the backdrop is seen where alpha < 1.0)
+			glActiveTexture(GL_TEXTURE2);
+			glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+			glActiveTexture(GL_TEXTURE0);
+
+			glUseProgram(shader.paste);
+			GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
+			if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
+#endif
+			setPMVMatrix(shader.paste);
+
+			setPrimaryColor(1.0, 1.0, 1.0, 0.5);
+#if 0
+			glBindTexture(GL_TEXTURE_2D, tmpTex);
+			//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+#endif
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat)realPicWidth - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat) - xoffset, (GLfloat) - yoffset + realPicHeight, 0.,
+				(GLfloat)realPicWidth - xoffset, (GLfloat) - yoffset + realPicHeight, 0.
+			};
+
+			drawQuad(shader.paste, vertices, 3, texCoords, NULL, btexCoords);
+#if 0
+			// Copy Our ViewPort To The Texture
+			glUseProgram(0);
+#endif
+			copyTexSubImage2D(GL_TEXTURE_2D, 0, (int)((x < 0) ? xoffset : x + xoffset), (int)((y < 0) ? yoffset : y + yoffset), (int)((x < 0) ? viewportOffsetX - x : viewportOffsetX), (int)((y < 0) ? viewportOffsetY - y : viewportOffsetY), w, h, backdropTextureName);
+
+			yoffset += viewportHeight;
+		}
+
+		xoffset += viewportWidth;
+	}
+	deleteTextures(1, &tmpTex);
+	setPixelCoords(false);
+	return true;
+}
+
+void saveCorePNG(FILE *writer, GLuint texture, int w, int h) {
+	GLint tw, th;
+#if 0
+	glBindTexture(GL_TEXTURE_2D, texture);
+#endif
+	getTextureDimensions(texture, &tw, &th);
+
+	GLubyte *image = new GLubyte [tw * th * 4];
+	if (! checkNew(image)) return;
+#if 0
+	glPixelStorei(GL_PACK_ALIGNMENT, 1);
+//	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
+#endif
+#ifdef HAVE_GLES2
+#if 0
+	GLuint old_fbo, new_fbo;
+	GLint old_vp[4];
+	glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *)&old_fbo);
+	glGetIntegerv(GL_VIEWPORT, old_vp);
+	glGenFramebuffers(1, &new_fbo);
+	glBindFramebuffer(GL_FRAMEBUFFER, new_fbo);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+	glViewport(0, 0, tw, th);
+	glReadPixels(0, 0, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, image);
+	glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
+	glViewport(old_vp[0], old_vp[1], old_vp[2], old_vp[3]);
+	glDeleteFramebuffers(1, &new_fbo);
+#endif
+#else
+	setPixelCoords(true);
+
+
+	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+	const GLfloat texCoords[] = {
+		0.0f, 0.0f,
+		1.0f, 0.0f,
+		0.0f, 1.0f,
+		1.0f, 1.0f
+	};
+
+	int xoffset = 0;
+	while (xoffset < tw) {
+		int w = (tw - xoffset < viewportWidth) ? tw - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < th) {
+			int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight;
+#if 0
+			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
+#endif
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat)tw - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat) - xoffset, (GLfloat) - yoffset + th, 0.,
+				(GLfloat)tw - xoffset, (GLfloat) - yoffset + th, 0.
+			};
+
+#if 0
+			glUseProgram(shader.texture);
+#endif
+			setPMVMatrix(shader.texture);
+
+			drawQuad(shader.texture, vertices, 1, texCoords);
+#if 0
+			glUseProgram(0);
+
+			for (int i = 0; i < h; i++)   {
+				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, image + xoffset * 4 + (yoffset + i) * 4 * tw);
+			}
+#endif
+			yoffset += viewportHeight;
+		}
+
+		xoffset += viewportWidth;
+	}
+	setPixelCoords(false);
+#endif
+
+
+
+	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+	if (!png_ptr) {
+		fatal("Error saving image!");
+		return;
+	}
+
+	png_infop info_ptr = png_create_info_struct(png_ptr);
+	if (!info_ptr) {
+		png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+		fatal("Error saving image!");
+		return;
+	}
+
+	png_init_io(png_ptr, writer);
+
+	png_set_IHDR(png_ptr, info_ptr, w, h,
+	             8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+
+	unsigned char *row_pointers[h];
+
+	for (int i = 0; i < h; i++) {
+		row_pointers[i] = image + 4 * i * tw;
+	}
+
+	png_set_rows(png_ptr, info_ptr, row_pointers);
+	png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
+
+	delete [] image;
+	image = NULL;
+}
+
+void saveCoreHSI(FILE *writer, GLuint texture, int w, int h) {
+
+	GLint tw, th;
+#if 0
+	glBindTexture(GL_TEXTURE_2D, texture);
+#endif
+	getTextureDimensions(texture, &tw, &th);
+
+	GLushort *image = new GLushort [tw * th];
+	if (! checkNew(image)) return;
+#if 0
+	glPixelStorei(GL_PACK_ALIGNMENT, 1);
+//	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image);
+#endif
+	setPixelCoords(true);
+
+	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+	const GLfloat texCoords[] = {
+		0.0f, 0.0f,
+		1.0f, 0.0f,
+		0.0f, 1.0f,
+		1.0f, 1.0f
+	};
+
+	int xoffset = 0;
+	while (xoffset < tw) {
+		int w = (tw - xoffset < viewportWidth) ? tw - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < th) {
+			int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight;
+#if 0
+			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
+#endif
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat)w - xoffset, (GLfloat) - yoffset, 0.,
+				(GLfloat) - xoffset, (GLfloat) - yoffset + h, 0.,
+				(GLfloat)w - xoffset, (GLfloat) - yoffset + h, 0.
+			};
+
+#if 0
+			glUseProgram(shader.texture);
+#endif
+			setPMVMatrix(shader.texture);
+			drawQuad(shader.texture, vertices, 1, texCoords);
+#if 0
+			glUseProgram(0);
+
+			for (int i = 0; i < h; i++)   {
+				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i)*tw);
+			}
+#endif
+			yoffset += viewportHeight;
+		}
+
+		xoffset += viewportWidth;
+	}
+	//glReadPixels(viewportOffsetX, viewportOffsetY, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+	setPixelCoords(false);
+
+
+
+	int x, y, lookAhead;
+	unsigned short int *fromHere, * lookPointer;
+
+	put2bytes(w, writer);
+	put2bytes(h, writer);
+
+	for (y = 0; y < h; y ++) {
+		fromHere = image + (y * tw);
+		x = 0;
+		while (x < w) {
+			lookPointer = fromHere + 1;
+			for (lookAhead = x + 1; lookAhead < w; lookAhead ++) {
+				if (lookAhead - x == 256) break;
+				if (* fromHere != * lookPointer) break;
+				lookPointer ++;
+			}
+			if (lookAhead == x + 1) {
+				put2bytes((* fromHere) & 65503, writer);
+			} else {
+				put2bytes(* fromHere | 32, writer);
+				fputc(lookAhead - x - 1, writer);
+			}
+			fromHere = lookPointer;
+			x = lookAhead;
+		}
+	}
+	delete [] image;
+	image = NULL;
+}
+
+void saveHSI(FILE *writer) {
+	saveCorePNG(writer, backdropTextureName, sceneWidth, sceneHeight);
+}
+
+
+void saveParallaxRecursive(parallaxLayer *me, FILE *fp) {
+	if (me) {
+		saveParallaxRecursive(me -> next, fp);
+		fputc(1, fp);
+		put2bytes(me->fileNum, fp);
+		put2bytes(me ->fractionX, fp);
+		put2bytes(me->fractionY, fp);
+	}
+}
+#endif
+
+bool getRGBIntoStack(unsigned int x, unsigned int y, stackHandler *sH) {
+#if 0
+	if (x >= sceneWidth || y >= sceneHeight) {
+		return fatal("Co-ordinates are outside current scene!");
+	}
+
+	variable newValue;
+
+	newValue.varType = SVT_NULL;
+
+	saveTexture(backdropTextureName, backdropTexture);
+
+	GLubyte *target;
+	if (! NPOT_textures) {
+		target = backdropTexture + 4 * getNextPOT(sceneWidth) * y + x * 4;
+	} else {
+		target = backdropTexture + 4 * sceneWidth * y + x * 4;
+	}
+
+	setVariable(newValue, SVT_INT, target[2]);
+	if (! addVarToStackQuick(newValue, sH -> first)) return false;
+	sH -> last = sH -> first;
+
+	setVariable(newValue, SVT_INT, target[1]);
+	if (! addVarToStackQuick(newValue, sH -> first)) return false;
+
+	setVariable(newValue, SVT_INT, target[0]);
+	if (! addVarToStackQuick(newValue, sH -> first)) return false;
+#endif
+	return true;
+}
diff --git a/engines/sludge/backdrop.h b/engines/sludge/backdrop.h
new file mode 100644
index 0000000..97d3377
--- /dev/null
+++ b/engines/sludge/backdrop.h
@@ -0,0 +1,103 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_BACKDROP_H
+#define SLUDGE_BACKDROP_H
+
+#if 0
+#if !defined(HAVE_GLES2)
+#include "GLee.h"
+#else
+#include <GLES2/gl2.h>
+#endif
+#endif
+
+#include "variable.h"
+#include "graphics.h"
+
+enum {
+	LIGHTMAPMODE_NONE       = -1,
+	LIGHTMAPMODE_HOTSPOT,
+	LIGHTMAPMODE_PIXEL,
+	LIGHTMAPMODE_NUM
+};
+
+extern unsigned int winWidth, winHeight, sceneWidth, sceneHeight;
+extern int lightMapMode;
+
+
+struct parallaxLayer {
+#if 0
+	GLubyte *texture;
+	GLuint textureName;
+#endif
+	int width, height, speedX, speedY;
+	bool wrapS, wrapT;
+	unsigned short fileNum, fractionX, fractionY;
+	int cameraX, cameraY;
+	parallaxLayer *next;
+	parallaxLayer *prev;
+};
+
+bool resizeBackdrop(int x, int y);
+void killBackDrop();
+void loadBackDrop(int fileNum, int x, int y);
+void mixBackDrop(int fileNum, int x, int y);
+void drawBackDrop();
+void blankScreen(int x1, int y1, int x2, int y2);
+void darkScreen();
+#if ALLOW_FILE
+void saveHSI(FILE *writer);
+void saveCoreHSI(FILE *writer, GLuint texture, int w, int h);
+bool loadHSI(FILE *fp, int, int, bool);
+bool mixHSI(FILE *fp, int x = 0, int y = 0);
+#endif
+void drawHorizontalLine(unsigned int, unsigned int, unsigned int);
+void drawVerticalLine(unsigned int, unsigned int, unsigned int);
+void hardScroll(int distance);
+bool getRGBIntoStack(unsigned int x, unsigned int y, stackHandler *sH);
+
+// Also the light map stuff
+
+void killLightMap();
+bool loadLightMap(int v);
+
+#if 0
+extern texture lightMap;
+#endif
+
+// And background parallax scrolling
+
+void killParallax();
+bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY);
+#if 0
+void saveParallaxRecursive(parallaxLayer *me, FILE *fp);
+#endif
+void reloadParallaxTextures();
+
+void nosnapshot();
+bool snapshot();
+#if ALLOW_FILE
+void saveSnapshot(FILE *fp);
+bool restoreSnapshot(FILE *fp);
+#endif
+#endif
diff --git a/engines/sludge/bg_effects.cpp b/engines/sludge/bg_effects.cpp
new file mode 100644
index 0000000..ad6438b
--- /dev/null
+++ b/engines/sludge/bg_effects.cpp
@@ -0,0 +1,375 @@
+/* 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 "allfiles.h"
+#include "backdrop.h"
+#include "colours.h"
+#include "debug.h"
+#include "graphics.h"
+#include "newfatal.h"
+#include "moreio.h"
+
+#if 0
+//extern unsigned short int * * backDropImage;
+extern GLuint backdropTextureName;
+#endif
+
+#if 0
+// Raised
+static int s_matrixEffectDivide = 2;
+static int s_matrixEffectWidth = 3;
+static int s_matrixEffectHeight = 3;
+static int s_matrixEffectData[9] = {0, 0, 0, 0, -1, 0, 0, 0, 2};
+static int s_matrixEffectBase = 0;
+#elif 0
+// Stay put
+static int s_matrixEffectDivide = 1;
+static int s_matrixEffectWidth = 3;
+static int s_matrixEffectHeight = 3;
+static int s_matrixEffectData[9] = {0, 0, 0, 0, 1, 0, 0, 0, 0};
+static int s_matrixEffectBase = 0;
+#elif 0
+// Brighten
+static int s_matrixEffectDivide = 9;
+static int s_matrixEffectWidth = 1;
+static int s_matrixEffectHeight = 1;
+static int s_matrixEffectData[9] = {10};
+static int s_matrixEffectBase = 15;
+#elif 0
+// Raised up/left
+static int s_matrixEffectDivide = 4;
+static int s_matrixEffectWidth = 3;
+static int s_matrixEffectHeight = 3;
+static int s_matrixEffectData[9] = { -2, -1, 0, -1, 1, 1, 0, 1, 2};
+static int s_matrixEffectBase = 16;
+#elif 0
+// Standard emboss
+static int s_matrixEffectDivide = 2;
+static int s_matrixEffectWidth = 3;
+static int s_matrixEffectHeight = 3;
+static int s_matrixEffectData[9] = { -1, 0, 0, 0, 0, 0, 0, 0, 1};
+static int s_matrixEffectBase = 128;
+#elif 0
+// Horizontal blur
+static int s_matrixEffectDivide = 11;
+static int s_matrixEffectWidth = 5;
+static int s_matrixEffectHeight = 1;
+static int s_matrixEffectData[9] = {1, 3, 3, 3, 1};
+static int s_matrixEffectBase = 0;
+#elif 0
+// Double vision
+static int s_matrixEffectDivide = 6;
+static int s_matrixEffectWidth = 13;
+static int s_matrixEffectHeight = 2;
+static int s_matrixEffectData[26] = {2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3};
+static int s_matrixEffectBase = 0;
+#elif 0
+// Negative
+static int s_matrixEffectDivide = 1;
+static int s_matrixEffectWidth = 1;
+static int s_matrixEffectHeight = 1;
+static int s_matrixEffectData[9] = { -1};
+static int s_matrixEffectBase = 255;
+#elif 0
+// Fog
+static int s_matrixEffectDivide = 4;
+static int s_matrixEffectWidth = 1;
+static int s_matrixEffectHeight = 1;
+static int s_matrixEffectData[9] = {3};
+static int s_matrixEffectBase = 45;
+#elif 0
+// Blur
+static int s_matrixEffectDivide = 14;
+static int s_matrixEffectWidth = 3;
+static int s_matrixEffectHeight = 3;
+static int s_matrixEffectData[9] = {1, 2, 1, 2, 2, 2, 1, 2, 1};
+static int s_matrixEffectBase = 0;
+#else
+static int s_matrixEffectDivide = 0;
+static int s_matrixEffectWidth = 0;
+static int s_matrixEffectHeight = 0;
+static int *s_matrixEffectData = NULL;
+static int s_matrixEffectBase = 0;
+#endif
+
+#if ALLOW_FILE
+void blur_saveSettings(FILE *fp) {
+	if (s_matrixEffectData) {
+		put4bytes(s_matrixEffectDivide, fp);
+		put4bytes(s_matrixEffectWidth, fp);
+		put4bytes(s_matrixEffectHeight, fp);
+		put4bytes(s_matrixEffectBase, fp);
+		fwrite(s_matrixEffectData, sizeof(int), s_matrixEffectWidth * s_matrixEffectHeight, fp);
+	} else {
+		put4bytes(0, fp);
+		put4bytes(0, fp);
+		put4bytes(0, fp);
+		put4bytes(0, fp);
+	}
+}
+#endif
+
+static int *blur_allocateMemoryForEffect() {
+	free(s_matrixEffectData);
+	s_matrixEffectData = NULL;
+
+	if (s_matrixEffectWidth && s_matrixEffectHeight) {
+		s_matrixEffectData = (int *) malloc(sizeof(int) * s_matrixEffectHeight * s_matrixEffectWidth);
+		checkNew(s_matrixEffectData);
+	}
+	return s_matrixEffectData;
+}
+
+#if ALLOW_FILE
+void blur_loadSettings(FILE *fp) {
+	s_matrixEffectDivide = get4bytes(fp);
+	s_matrixEffectWidth = get4bytes(fp);
+	s_matrixEffectHeight = get4bytes(fp);
+	s_matrixEffectBase = get4bytes(fp);
+
+	if (blur_allocateMemoryForEffect()) {
+		size_t bytes_read = fread(s_matrixEffectData, sizeof(int), s_matrixEffectWidth * s_matrixEffectHeight, fp);
+		if (bytes_read != sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight && ferror(fp)) {
+			debugOut("Reading error in blur_loadSettings.\n");
+		}
+	} else {
+		fseek(fp, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight, SEEK_CUR);
+	}
+}
+#endif
+
+bool blur_createSettings(int numParams, variableStack *&stack) {
+	bool createNullThing = true;
+	const char *error = NULL;
+
+	if (numParams >= 3) {
+		// PARAMETERS: base, divide, stack (, stack (, stack...))
+
+		int height = numParams - 2;
+		int width = 0;
+
+		variableStack *justToCheckSizes = stack;
+		for (int a = 0; a < height; a ++) {
+			if (justToCheckSizes->thisVar.varType != SVT_STACK) {
+				error = "Third and subsequent parameters in setBackgroundEffect should be arrays";
+				break;
+			} else {
+				int w = stackSize(justToCheckSizes->thisVar.varData.theStack);
+				if (a) {
+					if (w != width) {
+						error = "Arrays in setBackgroundEffect must be the same size";
+						break;
+					}
+					if (w < width) {
+						width = w;
+					}
+				} else {
+					width = w;
+				}
+			}
+		}
+
+		if (width == 0 && ! error) {
+			error = "Empty arrays found in setBackgroundEffect parameters";
+		}
+
+		if (! error) {
+			s_matrixEffectWidth = width;
+			s_matrixEffectHeight = height;
+
+			if (blur_allocateMemoryForEffect()) {
+				for (int y = height - 1; y >= 0; y --) {
+					variableStack *eachNumber = stack->thisVar.varData.theStack->first;
+					if (! error) {
+						for (int x = 0; x < width; x ++) {
+							int arraySlot = x + (y * width);
+//							s_matrixEffectData[arraySlot] = (rand() % 4);
+							if (!getValueType(s_matrixEffectData[arraySlot], SVT_INT, eachNumber->thisVar)) {
+								error = "";
+								break;
+							}
+							eachNumber = eachNumber->next;
+						}
+						trimStack(stack);
+					}
+				}
+				if (! error && !getValueType(s_matrixEffectDivide, SVT_INT, stack -> thisVar))
+					error = "";
+				trimStack(stack);
+				if (! error && !getValueType(s_matrixEffectBase, SVT_INT, stack -> thisVar))
+					error = "";
+				trimStack(stack);
+				if (! error) {
+					if (s_matrixEffectDivide) {
+						createNullThing = false;
+					} else {
+						error = "Second parameter of setBackgroundEffect (the 'divide' value) should not be 0!";
+					}
+				}
+			} else {
+				error = "Couldn't allocate memory for effect";
+			}
+		}
+	} else {
+		if (numParams) {
+			error = "setBackgroundEffect should either have 0 parameters or more than 2";
+		}
+	}
+
+	if (createNullThing) {
+		s_matrixEffectDivide = 0;
+		s_matrixEffectWidth = 0;
+		s_matrixEffectHeight = 0;
+		s_matrixEffectBase = 0;
+		delete s_matrixEffectData;
+		s_matrixEffectData = NULL;
+	}
+
+	if (error && error[0]) {
+		fatal(error);
+	}
+
+	return ! createNullThing;
+}
+
+static inline int clampi(int i, int min, int max) {
+	return (i >= max) ? max : ((i <= min) ? min : i);
+}
+
+static inline void blur_createSourceLine(unsigned char *createLine, unsigned char *fromLine, int overlapOnLeft, int width) {
+	int miniX;
+	memcpy(createLine + overlapOnLeft * 4, fromLine, width * 4);
+
+	for (miniX = 0; miniX < overlapOnLeft; miniX ++) {
+		createLine[miniX * 4] = fromLine[0];
+		createLine[miniX * 4 + 1] = fromLine[1];
+		createLine[miniX * 4 + 2] = fromLine[2];
+	}
+
+	for (miniX = width + overlapOnLeft; miniX < width + s_matrixEffectWidth - 1; miniX ++) {
+		createLine[miniX * 4] = fromLine[width * 4 - 4];
+		createLine[miniX * 4 + 1] = fromLine[width * 4 - 3];
+		createLine[miniX * 4 + 2] = fromLine[width * 4 - 2];
+	}
+}
+
+bool blurScreen() {
+#if 0
+	if (s_matrixEffectWidth && s_matrixEffectHeight && s_matrixEffectDivide && s_matrixEffectData) {
+		unsigned char *thisLine;
+		int y, x;
+		bool ok = true;
+		int overlapOnLeft = s_matrixEffectWidth / 2;
+		int overlapAbove  = s_matrixEffectHeight / 2;
+
+		unsigned char **sourceLine = new unsigned char *[s_matrixEffectHeight];
+		if (! checkNew(sourceLine)) return false;
+
+		int picWidth = sceneWidth;
+		int picHeight = sceneHeight;
+
+		if (! NPOT_textures) {
+			picWidth = getNextPOT(sceneWidth);
+			picHeight = getNextPOT(sceneHeight);
+		}
+
+		// Retrieve the texture
+		saveTexture(backdropTextureName, backdropTexture);
+
+		for (y = 0; y < s_matrixEffectHeight; y ++) {
+			sourceLine[y] = new unsigned char[(s_matrixEffectWidth - 1 + picWidth) * 4];
+			ok &= (sourceLine[y] != NULL);
+		}
+
+		if (ok) {
+			for (y = 0; y < s_matrixEffectHeight; y ++) {
+				int miniY = clampi(y - overlapAbove - 1, 0, sceneHeight - 1);
+
+				blur_createSourceLine(sourceLine[y], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth);
+			}
+
+			for (y = 0; y < sceneHeight; y ++) {
+				thisLine = backdropTexture + y * picWidth * 4;
+
+				//-------------------------
+				// Scroll source lines
+				//-------------------------
+				unsigned char *tempLine = sourceLine[0];
+				for (int miniY = 0; miniY < s_matrixEffectHeight - 1; miniY ++) {
+					sourceLine[miniY] = sourceLine[miniY + 1];
+				}
+				sourceLine[s_matrixEffectHeight - 1] = tempLine;
+				{
+					int h = s_matrixEffectHeight - 1;
+					int miniY = clampi(y + (s_matrixEffectHeight - overlapAbove - 1), 0, sceneHeight - 1);
+
+					blur_createSourceLine(sourceLine[h], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth);
+				}
+				for (x = 0; x < sceneWidth; x ++) {
+					int totalRed = 0;
+					int totalGreen = 0;
+					int totalBlue = 0;
+					int *matrixElement = s_matrixEffectData;
+					for (int miniY = 0; miniY < s_matrixEffectHeight; ++ miniY) {
+						unsigned char *pixel = & sourceLine[miniY][x * 4];
+						for (int miniX = 0; miniX < s_matrixEffectWidth; ++ miniX) {
+
+							totalRed    += pixel[0]     * * matrixElement;
+							totalGreen  += pixel[1]     * * matrixElement;
+							totalBlue   += pixel[2]     * * matrixElement;
+							++ matrixElement;
+							pixel += 4;
+						}
+					}
+					totalRed = (totalRed + s_matrixEffectDivide / 2) / s_matrixEffectDivide + s_matrixEffectBase;
+					totalRed = (totalRed < 0) ? 0 : ((totalRed > 255) ? 255 : totalRed);
+
+					totalGreen = (totalGreen + s_matrixEffectDivide / 2) / s_matrixEffectDivide + s_matrixEffectBase;
+					totalGreen = (totalGreen < 0) ? 0 : ((totalGreen > 255) ? 255 : totalGreen);
+
+					totalBlue = (totalBlue + s_matrixEffectDivide / 2) / s_matrixEffectDivide + s_matrixEffectBase;
+					totalBlue = (totalBlue < 0) ? 0 : ((totalBlue > 255) ? 255 : totalBlue);
+
+					* thisLine = totalRed;
+					++ thisLine;
+					* thisLine = totalGreen;
+					++ thisLine;
+					* thisLine = totalBlue;
+					++ thisLine;
+//					* thisLine = totalAlpha;
+					++ thisLine;
+				}
+			}
+		}
+
+		for (y = 0; y < s_matrixEffectHeight; y ++) {
+			delete sourceLine[y];
+		}
+		delete sourceLine;
+		sourceLine = NULL;
+
+		texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, backdropTextureName);
+		return true;
+	}
+#endif
+	return false;
+}
diff --git a/engines/sludge/bg_effects.h b/engines/sludge/bg_effects.h
new file mode 100644
index 0000000..067fa8d
--- /dev/null
+++ b/engines/sludge/bg_effects.h
@@ -0,0 +1,33 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_BG_EFFECTS_H
+#define SLUDGE_BG_EFFECTS_H
+
+bool blurScreen();
+#if ALLOW_FILE
+void blur_saveSettings(FILE *fp);
+void blur_loadSettings(FILE *fp);
+#endif
+bool blur_createSettings(int numParams, variableStack *&stack);
+
+#endif
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
new file mode 100644
index 0000000..9ba633d
--- /dev/null
+++ b/engines/sludge/builtin.cpp
@@ -0,0 +1,2545 @@
+/* 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.
+ *
+ */
+
+#if 0
+#include <SDL/SDL.h>
+#endif
+
+#include "debug.h"
+#include "allfiles.h"
+#include "sludger.h"
+#include "builtin.h"
+#include "stringy.h"
+#include "newfatal.h"
+#include "cursors.h"
+#include "statusba.h"
+#include "loadsave.h"
+#include "backdrop.h"
+#include "bg_effects.h"
+#include "sprites.h"
+#include "fonttext.h"
+#include "sprbanks.h"
+#include "people.h"
+#include "sound.h"
+#include "objtypes.h"
+#include "floor.h"
+#include "zbuffer.h"
+#include "talk.h"
+#include "region.h"
+#include "language.h"
+#include "moreio.h"
+#include "movie.h"
+#include "savedata.h"
+#include "freeze.h"
+#include "colours.h"
+#include "language.h"
+#include "thumbnail.h"
+#include "graphics.h"
+#include "CommonCode/utf8.h"
+
+extern char *gamePath;
+
+int speechMode = 0;
+int cameraX, cameraY;
+float cameraZoom = 1.0;
+spritePalette pastePalette;
+
+char *launchMe = NULL;
+variable *launchResult = NULL;
+
+extern int lastFramesPerSecond, thumbWidth, thumbHeight;
+extern bool allowAnyFilename;
+extern bool captureAllKeys;
+extern short fontSpace;
+extern eventHandlers *currentEvents;
+extern variableStack *noStack;
+extern statusStuff *nowStatus;
+extern screenRegion *overRegion;
+extern HWND hMainWindow;
+extern unsigned int sceneWidth, sceneHeight;
+extern int numBIFNames, numUserFunc;
+extern char builtInFunctionNames[][25];
+
+extern char * *allUserFunc;
+extern char * *allBIFNames;
+extern inputType input;
+extern char *loadNow;
+
+#if 0
+extern GLuint backdropTextureName;
+#endif
+
+extern float speechSpeed;
+extern unsigned char brightnessLevel;
+extern unsigned char fadeMode;
+extern unsigned short saveEncoding;
+extern frozenStuffStruct *frozenStuff;
+extern unsigned int currentBlankColour;
+extern unsigned int languageID;
+extern unsigned char currentBurnR, currentBurnG, currentBurnB;
+
+int paramNum[] = { -1, 0, 1, 1, -1, -1, 1, 3, 4, 1, 0, 0, 8, -1,    // SAY -> MOVEMOUSE
+                   -1, 0, 0, -1, -1, 1, 1, 1, 1, 4, 1, 1, 2, 1,// FOCUS -> REMOVEREGION
+                   2, 2, 0, 0, 2,                              // ANIMATE -> SETSCALE
+                   -1, 2, 1, 0, 0, 0, 1, 0, 3,                 // new/push/pop stack, status stuff
+                   2, 0, 0, 3, 1, 0, 2,                        // delFromStack -> completeTimers
+                   -1, -1, -1, 2, 2, 0, 3, 1,                  // anim, costume, pO, setC, wait, sS, substring, stringLength
+                   0, 1, 1, 0, 2,                              // dark, save, load, quit, rename
+                   1, 3, 3, 1, 2, 1, 1, 3, 1, 0, 0, 2, 1,      // stackSize, pasteString, startMusic, defvol, vol, stopmus, stopsound, setfont, alignStatus, show x 2, pos'Status, setFloor
+                   -1, -1, 1, 1, 2, 1, 1, 1, -1, -1, -1, 1, 1, // force, jump, peekstart, peekend, enqueue, getSavedGames, inFont, loopSound, removeChar, stopCharacter
+                   1, 0, 3, 3, 1, 2, 1, 2, 2,                  // launch, howFrozen, pastecol, litcol, checksaved, float, cancelfunc, walkspeed, delAll
+                   2, 3, 1, 2, 2, 0, 0, 1, 2, 3, 1, -1,        // extras, mixoverlay, pastebloke, getMScreenX/Y, setSound(Default/-)Volume, looppoints, speechMode, setLightMap
+                   -1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,           // think, getCharacterDirection, is(char/region/moving), deleteGame, renameGame, hardScroll, stringWidth, speechSpeed, normalCharacter
+                   2, 1, 2, 1, 3, 1, 1, 2, 1,                  // fetchEvent, setBrightness, spin, fontSpace, burnString, captureAll, cacheSound, setSpinSpeed, transitionMode
+                   1, 0, 0, 1, 0, 2, 1, 1, 1,                  // movie(Start/Abort/Playing), updateDisplay, getSoundCache, savedata, loaddata, savemode, freeSound
+                   3, 0, 3, 3, 2, 1, 1,                        // setParallax, clearParallax, setBlankColour, setBurnColour, getPixelColour, makeFastArray, getCharacterScale
+                   0, 2, 0,                                    // getLanguage, launchWith, getFramesPerSecond
+                   3, 2, 2, 0, 0, 1,                           // readThumbnail, setThumbnailSize, hasFlag, snapshot, clearSnapshot, anyFilename
+                   2, 1,                                       // regGet, fatal
+                   4, 3, -1, 0,                                // chr AA, max AA, setBackgroundEffect, doBackgroundEffect
+                   2,                                          // setCharacterAngleOffset
+                   2, 5,                                       // setCharacterTransparency, setCharacterColourise
+                   1,                                          // zoomCamera
+                   1, 0, 0                                     // playMovie, stopMovie, pauseMovie
+                 };
+
+bool failSecurityCheck(char *fn) {
+	if (fn == NULL) return true;
+
+	int a = 0;
+
+	while (fn[a]) {
+		switch (fn[a]) {
+		case ':':
+		case '\\':
+		case '/':
+		case '*':
+		case '?':
+		case '"':
+		case '<':
+		case '>':
+		case '|':
+			fatal("Filenames may not contain the following characters: \n\n\\  /  :  \"  <  >  |  ?  *\n\nConsequently, the following filename is not allowed:", fn);
+			return true;
+		}
+		a ++;
+	}
+	return false;
+}
+
+loadedFunction *saverFunc;
+
+typedef builtReturn(* builtInSludgeFunc)(int numParams, loadedFunction *fun);
+struct builtInFunctionData {
+	builtInSludgeFunc func;
+};
+
+#define builtIn(a)          static builtReturn builtIn_ ## a (int numParams, loadedFunction * fun)
+#define UNUSEDALL           (void) (0 && sizeof(numParams) && sizeof (fun));
+
+static builtReturn sayCore(int numParams, loadedFunction *fun, bool sayIt) {
+	int fileNum = -1;
+	char *newText;
+	int objT, p;
+	killSpeechTimers();
+
+	switch (numParams) {
+	case 3:
+		if (!getValueType(fileNum, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+	// No break; here
+
+	case 2:
+		newText = getTextFromAnyVar(fun -> stack -> thisVar);
+		if (!newText) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!getValueType(objT, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		p = wrapSpeech(newText, objT, fileNum, sayIt);
+		fun -> timeLeft = p;
+		//debugOut ("BUILTIN: sayCore: %s (%i)\n", newText, p);
+		fun -> isSpeech = true;
+		delete newText;
+		newText = NULL;
+		return BR_KEEP_AND_PAUSE;
+	}
+
+	fatal("Function should have either 2 or 3 parameters");
+	return BR_ERROR;
+}
+
+#pragma mark -
+#pragma mark Built in functions
+
+builtIn(say) {
+	UNUSEDALL
+	return sayCore(numParams, fun, true);
+}
+
+builtIn(think) {
+	UNUSEDALL
+	return sayCore(numParams, fun, false);
+}
+
+builtIn(freeze) {
+	UNUSEDALL
+	freeze();
+	freezeSubs();
+	fun -> freezerLevel = 0;
+	return BR_CONTINUE;
+}
+
+builtIn(unfreeze) {
+	UNUSEDALL
+	unfreeze();
+	unfreezeSubs();
+	return BR_CONTINUE;
+}
+
+builtIn(howFrozen) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, howFrozen());
+	return BR_CONTINUE;
+}
+
+builtIn(setCursor) {
+	UNUSEDALL
+	personaAnimation *aa = getAnimationFromVar(fun -> stack -> thisVar);
+	pickAnimCursor(aa);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(getMouseX) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, input.mouseX + cameraX);
+	return BR_CONTINUE;
+}
+
+builtIn(getMouseY) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, input.mouseY + cameraY);
+	return BR_CONTINUE;
+}
+
+builtIn(getMouseScreenX) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, input.mouseX * cameraZoom);
+	return BR_CONTINUE;
+}
+
+builtIn(getMouseScreenY) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, input.mouseY * cameraZoom);
+	return BR_CONTINUE;
+}
+
+builtIn(getStatusText) {
+	UNUSEDALL
+	makeTextVar(fun -> reg, statusBarText());
+	return BR_CONTINUE;
+}
+
+builtIn(getMatchingFiles) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!newText) return BR_ERROR;
+	trimStack(fun -> stack);
+	unlinkVar(fun -> reg);
+
+	// Return value
+	fun -> reg.varType = SVT_STACK;
+	fun -> reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
+	fun -> reg.varData.theStack -> first = NULL;
+	fun -> reg.varData.theStack -> last = NULL;
+	fun -> reg.varData.theStack -> timesUsed = 1;
+	if (!getSavedGamesStack(fun -> reg.varData.theStack, newText)) return BR_ERROR;
+	delete newText;
+	newText = NULL;
+	return BR_CONTINUE;
+}
+
+builtIn(saveGame) {
+	UNUSEDALL
+
+	if (frozenStuff) {
+		fatal("Can't save game state while the engine is frozen");
+	}
+
+	loadNow = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+
+	char *aaaaa = encodeFilename(loadNow);
+	delete[] loadNow;
+	if (failSecurityCheck(aaaaa)) return BR_ERROR;      // Won't fail if encoded, how cool is that? OK, not very.
+
+	loadNow = joinStrings(":", aaaaa);
+	delete[] aaaaa;
+
+	setVariable(fun -> reg, SVT_INT, 0);
+	saverFunc = fun;
+	return BR_KEEP_AND_PAUSE;
+}
+
+builtIn(fileExists) {
+	UNUSEDALL
+	loadNow = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	char *aaaaa = encodeFilename(loadNow);
+	delete loadNow;
+	if (failSecurityCheck(aaaaa)) return BR_ERROR;
+#if ALLOW_FILE
+	FILE *fp = fopen(aaaaa, "rb");
+	if (!fp) {
+		char currentDir[1000];
+		if (!getcwd(currentDir, 998)) {
+			debugOut("Can't get current directory.\n");
+		}
+
+		if (chdir(gamePath)) {
+			debugOut("Error: Failed changing to directory %s\n", gamePath);
+		}
+		fp = fopen(aaaaa, "rb");
+		if (chdir(currentDir)) {
+			debugOut("Error: Failed changing to directory %s\n", currentDir);
+		}
+	}
+	// Return value
+	setVariable(fun -> reg, SVT_INT, (fp != NULL));
+	if (fp) fclose(fp);
+	delete[] aaaaa;
+	loadNow = NULL;
+#endif
+	return BR_CONTINUE;
+}
+
+builtIn(loadGame) {
+	UNUSEDALL
+	char *aaaaa = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	loadNow = encodeFilename(aaaaa);
+	delete aaaaa;
+
+	if (frozenStuff) {
+		fatal("Can't load a saved game while the engine is frozen");
+	}
+#if ALLOW_FILE
+	if (failSecurityCheck(loadNow)) return BR_ERROR;
+	FILE *fp = fopen(loadNow, "rb");
+	if (fp) {
+		fclose(fp);
+		return BR_KEEP_AND_PAUSE;
+	}
+	delete loadNow;
+	loadNow = NULL;
+#endif
+	return BR_CONTINUE;
+}
+
+//--------------------------------------
+#pragma mark -
+#pragma mark Background image - Painting
+
+builtIn(blankScreen) {
+	UNUSEDALL
+	blankScreen(0, 0, sceneWidth, sceneHeight);
+	return BR_CONTINUE;
+}
+
+builtIn(blankArea) {
+	UNUSEDALL
+	int x1, y1, x2, y2;
+	if (!getValueType(y2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(y1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	blankScreen(x1, y1, x2, y2);
+	return BR_CONTINUE;
+}
+
+builtIn(darkBackground) {
+	UNUSEDALL
+	darkScreen();
+	return BR_CONTINUE;
+}
+
+builtIn(addOverlay) {
+	UNUSEDALL
+	int fileNumber, xPos, yPos;
+	if (!getValueType(yPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(xPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	loadBackDrop(fileNumber, xPos, yPos);
+	return BR_CONTINUE;
+}
+
+builtIn(mixOverlay) {
+	UNUSEDALL
+	int fileNumber, xPos, yPos;
+	if (!getValueType(yPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(xPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	mixBackDrop(fileNumber, xPos, yPos);
+	return BR_CONTINUE;
+}
+
+builtIn(pasteImage) {
+	UNUSEDALL
+	int x, y;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	personaAnimation *pp = getAnimationFromVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	if (pp == NULL) return BR_CONTINUE;
+
+	pasteCursor(x, y, pp);
+	return BR_CONTINUE;
+}
+
+#pragma mark -
+#pragma mark Background Image - Scrolling
+
+builtIn(setSceneDimensions) {
+	UNUSEDALL
+	int x, y;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (resizeBackdrop(x, y)) {
+		blankScreen(0, 0, x, y);
+		return BR_CONTINUE;
+	}
+	fatal("Out of memory creating new backdrop.");
+	return BR_ERROR;
+}
+
+builtIn(aimCamera) {
+	UNUSEDALL
+	if (!getValueType(cameraY, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(cameraX, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	cameraX -= (float)(winWidth >> 1) / cameraZoom;
+	cameraY -= (float)(winHeight >> 1) / cameraZoom;
+
+	if (cameraX < 0) cameraX = 0;
+	else if (cameraX > sceneWidth - (float)winWidth / cameraZoom) cameraX = sceneWidth - (float)winWidth / cameraZoom;
+	if (cameraY < 0) cameraY = 0;
+	else if (cameraY > sceneHeight - (float)winHeight / cameraZoom) cameraY = sceneHeight - (float)winHeight / cameraZoom;
+	return BR_CONTINUE;
+}
+
+
+builtIn(zoomCamera) {
+	UNUSEDALL
+	int z;
+	if (!getValueType(z, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	input.mouseX = input.mouseX * cameraZoom;
+	input.mouseY = input.mouseY * cameraZoom;
+
+
+	cameraZoom = (float) z * 0.01;
+	if ((float) winWidth / cameraZoom > sceneWidth) cameraZoom = (float)winWidth / sceneWidth;
+	if ((float) winHeight / cameraZoom > sceneHeight) cameraZoom = (float)winHeight / sceneHeight;
+	setPixelCoords(false);
+
+	input.mouseX = input.mouseX / cameraZoom;
+	input.mouseY = input.mouseY / cameraZoom;
+
+	return BR_CONTINUE;
+}
+
+#pragma mark -
+#pragma mark Variables
+
+
+builtIn(pickOne) {
+	UNUSEDALL
+	if (!numParams) {
+		fatal("Built-in function should have at least 1 parameter");
+		return BR_ERROR;
+	}
+
+	int i;
+#if 0
+	i = rand() % numParams;
+#endif
+
+	// Return value
+	while (numParams --) {
+		if (i == numParams) copyVariable(fun -> stack -> thisVar, fun -> reg);
+		trimStack(fun -> stack);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(substring) {
+	UNUSEDALL
+	char *wholeString;
+	char *newString;
+	int start, length;
+
+	//debugOut ("BUILTIN: substring\n");
+
+	if (!getValueType(length, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(start, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	wholeString = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+
+	if (u8_strlen(wholeString) < start + length) {
+		length = u8_strlen(wholeString) - start;
+		if (u8_strlen(wholeString) < start) {
+			start = 0;
+		}
+	}
+	if (length < 0) {
+		length = 0;
+	}
+
+	int startoffset = u8_offset(wholeString, start);
+	int endoffset = u8_offset(wholeString, start + length);
+
+	newString = new char[endoffset - startoffset + 1];
+	if (!checkNew(newString)) {
+		return BR_ERROR;
+	}
+
+	memcpy(newString, wholeString + startoffset, endoffset - startoffset);
+	newString[endoffset - startoffset] = 0;
+
+	makeTextVar(fun -> reg, newString);
+	delete newString;
+	return BR_CONTINUE;
+}
+
+builtIn(stringLength) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, stringLength(newText));
+	delete[] newText;
+	return BR_CONTINUE;
+}
+
+builtIn(newStack) {
+	UNUSEDALL
+	unlinkVar(fun -> reg);
+
+	// Return value
+	fun -> reg.varType = SVT_STACK;
+	fun -> reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
+	fun -> reg.varData.theStack -> first = NULL;
+	fun -> reg.varData.theStack -> last = NULL;
+	fun -> reg.varData.theStack -> timesUsed = 1;
+	while (numParams --) {
+		if (!addVarToStack(fun -> stack -> thisVar, fun -> reg.varData.theStack -> first)) return BR_ERROR;
+		if (fun -> reg.varData.theStack -> last == NULL) {
+			fun -> reg.varData.theStack -> last = fun -> reg.varData.theStack -> first;
+		}
+		trimStack(fun -> stack);
+	}
+	return BR_CONTINUE;
+}
+
+// wait is exactly the same function, but limited to 2 parameters
+#define builtIn_wait builtIn_newStack
+
+builtIn(stackSize) {
+	UNUSEDALL
+	switch (fun -> stack -> thisVar.varType) {
+	case SVT_STACK:
+		// Return value
+		setVariable(fun -> reg, SVT_INT, stackSize(fun -> stack -> thisVar.varData.theStack));
+		trimStack(fun -> stack);
+		return BR_CONTINUE;
+
+	case SVT_FASTARRAY:
+		// Return value
+		setVariable(fun -> reg, SVT_INT, fun -> stack -> thisVar.varData.fastArray -> size);
+		trimStack(fun -> stack);
+		return BR_CONTINUE;
+
+	default:
+		break;
+	}
+	fatal("Parameter isn't a stack or a fast array.");
+	return BR_ERROR;
+}
+
+builtIn(copyStack) {
+	UNUSEDALL
+	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack.");
+		return BR_ERROR;
+	}
+	// Return value
+	if (!copyStack(fun -> stack -> thisVar, fun -> reg)) return BR_ERROR;
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(pushToStack) {
+	UNUSEDALL
+	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack");
+		return BR_ERROR;
+	}
+
+	if (!addVarToStack(fun -> stack -> thisVar, fun -> stack -> next -> thisVar.varData.theStack -> first))
+		return BR_ERROR;
+
+	if (fun -> stack -> next -> thisVar.varData.theStack -> first -> next == NULL)
+		fun -> stack -> next -> thisVar.varData.theStack -> last = fun -> stack -> next -> thisVar.varData.theStack -> first;
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(enqueue) {
+	UNUSEDALL
+	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack");
+		return BR_ERROR;
+	}
+
+	if (fun -> stack -> next -> thisVar.varData.theStack -> first == NULL) {
+		if (!addVarToStack(fun -> stack -> thisVar, fun -> stack -> next -> thisVar.varData.theStack -> first))
+			return BR_ERROR;
+
+		fun -> stack -> next -> thisVar.varData.theStack -> last = fun -> stack -> next -> thisVar.varData.theStack -> first;
+	} else {
+		if (!addVarToStack(fun -> stack -> thisVar,
+		                    fun -> stack -> next -> thisVar.varData.theStack -> last -> next))
+			return BR_ERROR;
+		fun -> stack -> next -> thisVar.varData.theStack -> last = fun -> stack -> next -> thisVar.varData.theStack -> last -> next;
+	}
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(deleteFromStack) {
+	UNUSEDALL
+	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack.");
+		return BR_ERROR;
+	}
+
+	// Return value
+	setVariable(fun -> reg, SVT_INT,
+	            deleteVarFromStack(fun -> stack -> thisVar,
+	                               fun -> stack -> next -> thisVar.varData.theStack -> first, false));
+
+	// Horrible hacking because 'last' value might now be wrong!
+	fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first);
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(deleteAllFromStack) {
+	UNUSEDALL
+	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack.");
+		return BR_ERROR;
+	}
+
+	// Return value
+	setVariable(fun -> reg, SVT_INT,
+	            deleteVarFromStack(fun -> stack -> thisVar,
+	                               fun -> stack -> next -> thisVar.varData.theStack -> first, true));
+
+	// Horrible hacking because 'last' value might now be wrong!
+	fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first);
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(popFromStack) {
+	UNUSEDALL
+	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack.");
+		return BR_ERROR;
+	}
+	if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+		fatal("The stack's empty.");
+		return BR_ERROR;
+	}
+
+	// Return value
+	copyVariable(fun -> stack -> thisVar.varData.theStack -> first -> thisVar, fun -> reg);
+	trimStack(fun -> stack -> thisVar.varData.theStack -> first);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(peekStart) {
+	UNUSEDALL
+	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack.");
+		return BR_ERROR;
+	}
+	if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+		fatal("The stack's empty.");
+		return BR_ERROR;
+	}
+
+	// Return value
+	copyVariable(fun -> stack -> thisVar.varData.theStack -> first -> thisVar, fun -> reg);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(peekEnd) {
+	UNUSEDALL
+	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+		fatal("Parameter isn't a stack.");
+		return BR_ERROR;
+	}
+	if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+		fatal("The stack's empty.");
+		return BR_ERROR;
+	}
+
+	// Return value
+	copyVariable(fun -> stack -> thisVar.varData.theStack -> last -> thisVar, fun -> reg);
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(random) {
+	UNUSEDALL
+	int num;
+
+	if (!getValueType(num, SVT_INT, fun -> stack -> thisVar))
+		return BR_ERROR;
+
+	trimStack(fun -> stack);
+	if (num <= 0) num = 1;
+	setVariable(fun -> reg, SVT_INT, 0 /*rand() % num*/); //TODO:false value
+	return BR_CONTINUE;
+}
+
+static bool getRGBParams(int &red, int &green, int &blue, loadedFunction *fun) {
+	if (!getValueType(blue, SVT_INT, fun -> stack -> thisVar)) return false;
+	trimStack(fun -> stack);
+	if (!getValueType(green, SVT_INT, fun -> stack -> thisVar)) return false;
+	trimStack(fun -> stack);
+	if (!getValueType(red, SVT_INT, fun -> stack -> thisVar)) return false;
+	trimStack(fun -> stack);
+	return true;
+}
+
+builtIn(setStatusColour) {
+	UNUSEDALL
+	int red, green, blue;
+
+	if (!getRGBParams(red, green, blue, fun))
+		return BR_ERROR;
+
+	statusBarColour((byte) red, (byte) green, (byte) blue);
+	return BR_CONTINUE;
+}
+
+builtIn(setLitStatusColour) {
+	UNUSEDALL
+	int red, green, blue;
+
+	if (!getRGBParams(red, green, blue, fun))
+		return BR_ERROR;
+
+	statusBarLitColour((byte) red, (byte) green, (byte) blue);
+	return BR_CONTINUE;
+}
+
+builtIn(setPasteColour) {
+	UNUSEDALL
+	int red, green, blue;
+
+	if (!getRGBParams(red, green, blue, fun))
+		return BR_ERROR;
+
+	setFontColour(pastePalette, (byte) red, (byte) green, (byte) blue);
+	return BR_CONTINUE;
+}
+
+builtIn(setBlankColour) {
+	UNUSEDALL
+	int red, green, blue;
+
+	if (!getRGBParams(red, green, blue, fun))
+		return BR_ERROR;
+
+	currentBlankColour = makeColour(red & 255, green & 255, blue & 255);
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+builtIn(setBurnColour) {
+	UNUSEDALL
+	int red, green, blue;
+
+	if (!getRGBParams(red, green, blue, fun))
+		return BR_ERROR;
+
+	currentBurnR = red;
+	currentBurnG = green;
+	currentBurnB = blue;
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+
+builtIn(setFont) {
+	UNUSEDALL
+	int fileNumber, newHeight;
+	if (!getValueType(newHeight, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	//              newDebug ("  Height:", newHeight);
+	trimStack(fun -> stack);
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!newText) return BR_ERROR;
+	//              newDebug ("  Character supported:", newText);
+	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	//              newDebug ("  File:", fileNumber);
+	trimStack(fun -> stack);
+	if (!loadFont(fileNumber, newText, newHeight)) return BR_ERROR;
+	//              newDebug ("  Done!");
+	delete newText;
+
+	return BR_CONTINUE;
+}
+
+builtIn(inFont) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!newText) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	// Return value
+
+	setVariable(fun -> reg, SVT_INT, isInFont(newText));
+	return BR_CONTINUE;
+}
+
+builtIn(pasteString) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	int y, x;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (x == IN_THE_CENTRE) x = (winWidth - stringWidth(newText)) >> 1;
+	fixFont(pastePalette);
+	pasteStringToBackdrop(newText, x, y, pastePalette);
+	delete[] newText;
+	return BR_CONTINUE;
+}
+
+builtIn(anim) {
+	UNUSEDALL
+	if (numParams < 2) {
+		fatal("Built-in function anim() must have at least 2 parameters.");
+		return BR_ERROR;
+	}
+
+	// First store the frame numbers and take 'em off the stack
+	personaAnimation *ba = createPersonaAnim(numParams - 1, fun -> stack);
+
+	// Only remaining paramter is the file number
+	int fileNumber;
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	// Load the required sprite bank
+	loadedSpriteBank *sprBanky = loadBankForAnim(fileNumber);
+	if (!sprBanky) return BR_ERROR;    // File not found, fatal done already
+	setBankFile(ba, sprBanky);
+
+	// Return value
+	newAnimationVariable(fun -> reg, ba);
+
+	return BR_CONTINUE;
+}
+
+builtIn(costume) {
+	UNUSEDALL
+	persona *newPersona = new persona;
+	if (!checkNew(newPersona)) return BR_ERROR;
+	newPersona -> numDirections = numParams / 3;
+	if (numParams == 0 || newPersona -> numDirections * 3 != numParams) {
+		fatal("Illegal number of parameters (should be greater than 0 and divisible by 3)");
+		return BR_ERROR;
+	}
+	int iii;
+	newPersona -> animation = new personaAnimation * [numParams];
+	if (!checkNew(newPersona -> animation)) return BR_ERROR;
+	for (iii = numParams - 1; iii >= 0; iii --) {
+		newPersona -> animation[iii] = getAnimationFromVar(fun -> stack -> thisVar);
+		trimStack(fun -> stack);
+	}
+
+	// Return value
+	newCostumeVariable(fun -> reg, newPersona);
+	return BR_CONTINUE;
+}
+
+builtIn(launch) {
+	UNUSEDALL
+	char *newTextA = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!newTextA) return BR_ERROR;
+
+	char *newText = encodeFilename(newTextA);
+
+	trimStack(fun -> stack);
+	if (newTextA[0] == 'h' &&
+	        newTextA[1] == 't' &&
+	        newTextA[2] == 't' &&
+	        newTextA[3] == 'p' &&
+	        (newTextA[4] == ':' || (newTextA[4] == 's' && newTextA[5] == ':'))) {
+
+		// IT'S A WEBSITE!
+		launchMe = copyString(newTextA);
+	} else {
+		char *gameDir;
+#ifdef _WIN32
+		gameDir = joinStrings(gamePath, "\\");
+#else
+		gameDir = joinStrings(gamePath, "/");
+#endif
+		launchMe = joinStrings(gameDir, newText);
+		delete newText;
+		if (!launchMe) return BR_ERROR;
+	}
+	delete newTextA;
+	setGraphicsWindow(false);
+	setVariable(fun -> reg, SVT_INT, 1);
+	launchResult = &fun->reg;
+
+	return BR_KEEP_AND_PAUSE;
+}
+
+builtIn(pause) {
+	UNUSEDALL
+	int theTime;
+	if (!getValueType(theTime, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (theTime > 0) {
+		fun -> timeLeft = theTime - 1;
+		fun -> isSpeech = false;
+		return BR_KEEP_AND_PAUSE;
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(completeTimers) {
+	UNUSEDALL
+	completeTimers();
+	return BR_CONTINUE;
+}
+
+builtIn(callEvent) {
+	UNUSEDALL
+	int obj1, obj2;
+	if (!getValueType(obj2, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj1, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	int fNum = getCombinationFunction(obj1, obj2);
+
+	// Return value
+	if (fNum) {
+		setVariable(fun -> reg, SVT_FUNC, fNum);
+		return BR_CALLAFUNC;
+	}
+	setVariable(fun -> reg, SVT_INT, 0);
+	return BR_CONTINUE;
+}
+
+#if 0
+SDL_Event quit_event;
+#endif
+
+bool reallyWantToQuit = false;
+
+builtIn(quitGame) {
+	UNUSEDALL
+	reallyWantToQuit = true;
+#if 0
+	quit_event.type = SDL_QUIT;
+	SDL_PushEvent(&quit_event);
+#endif
+	return BR_CONTINUE;
+}
+
+
+#pragma mark -
+#pragma mark Movie functions
+
+// The old movie functions are deprecated and does nothing.
+builtIn(_rem_movieStart) {
+	UNUSEDALL
+	trimStack(fun -> stack);
+	return BR_CONTINUE;
+}
+
+builtIn(_rem_movieAbort) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, 0);
+	return BR_CONTINUE;
+}
+
+builtIn(_rem_moviePlaying) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, 0);
+	return BR_CONTINUE;
+}
+
+builtIn(playMovie) {
+	UNUSEDALL
+	int fileNumber, r;
+
+	if (movieIsPlaying) return BR_PAUSE;
+
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	r = playMovie(fileNumber);
+
+	setVariable(fun -> reg, SVT_INT, r);
+
+	if (r && (!fun->next)) {
+		restartFunction(fun);
+		return BR_ALREADY_GONE;
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(stopMovie) {
+	UNUSEDALL
+	int r;
+
+	r = stopMovie();
+
+	setVariable(fun -> reg, SVT_INT, 0);
+	return BR_CONTINUE;
+}
+
+builtIn(pauseMovie) {
+	UNUSEDALL
+	int r;
+
+	r = pauseMovie();
+
+	setVariable(fun -> reg, SVT_INT, 0);
+	return BR_CONTINUE;
+}
+
+
+#pragma mark -
+#pragma mark Audio functions
+
+builtIn(startMusic) {
+	UNUSEDALL
+	int fromTrack, musChan, fileNumber;
+	if (!getValueType(fromTrack, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(musChan, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!playMOD(fileNumber, musChan, fromTrack)) return BR_CONTINUE;  //BR_ERROR;
+	return BR_CONTINUE;
+}
+
+builtIn(stopMusic) {
+	UNUSEDALL
+	int v;
+	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	stopMOD(v);
+	return BR_CONTINUE;
+}
+
+builtIn(setMusicVolume) {
+	UNUSEDALL
+	int musChan, v;
+	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(musChan, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setMusicVolume(musChan, v);
+	return BR_CONTINUE;
+}
+
+builtIn(setDefaultMusicVolume) {
+	UNUSEDALL
+	int v;
+	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setDefaultMusicVolume(v);
+	return BR_CONTINUE;
+}
+
+builtIn(playSound) {
+	UNUSEDALL
+	int fileNumber;
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!startSound(fileNumber, false)) return BR_CONTINUE;    // Was BR_ERROR
+	return BR_CONTINUE;
+}
+builtIn(loopSound) {
+	UNUSEDALL
+	int fileNumber;
+
+	if (numParams < 1) {
+		fatal("Built-in function loopSound() must have at least 1 parameter.");
+		return BR_ERROR;
+	} else if (numParams < 2) {
+
+		if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!startSound(fileNumber, true)) return BR_CONTINUE;     // Was BR_ERROR
+		return BR_CONTINUE;
+	} else {
+		// We have more than one sound to play!
+
+		int doLoop = 2;
+		soundList *s = NULL;
+		soundList *old = NULL;
+
+		// Should we loop?
+		if (fun->stack->thisVar.varType != SVT_FILE) {
+			getValueType(doLoop, SVT_INT, fun -> stack -> thisVar);
+			trimStack(fun -> stack);
+			numParams--;
+		}
+		while (numParams) {
+			if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) {
+				fatal("Illegal parameter given built-in function loopSound().");
+				return BR_ERROR;
+			}
+			s = new soundList;
+			if (!checkNew(s)) return BR_ERROR;
+
+			s-> next = old;
+			s-> prev = NULL;
+			s-> sound = fileNumber;
+			old = s;
+
+			trimStack(fun->stack);
+			numParams--;
+		}
+		while (s->next) s = s-> next;
+		if (doLoop > 1) {
+			s->next = old;
+			old->prev = s;
+		} else if (doLoop) {
+			s->next = s;
+		}
+		old->vol = -1;
+		playSoundList(old);
+		return BR_CONTINUE;
+	}
+}
+
+builtIn(stopSound) {
+	UNUSEDALL
+	int v;
+	if (!getValueType(v, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	huntKillSound(v);
+	return BR_CONTINUE;
+}
+
+builtIn(setDefaultSoundVolume) {
+	UNUSEDALL
+	int v;
+	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setDefaultSoundVolume(v);
+	return BR_CONTINUE;
+}
+
+builtIn(setSoundVolume) {
+	UNUSEDALL
+	int musChan, v;
+	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(musChan, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setSoundVolume(musChan, v);
+	return BR_CONTINUE;
+}
+
+
+builtIn(setSoundLoopPoints) {
+	UNUSEDALL
+	int musChan, theEnd, theStart;
+	if (!getValueType(theEnd, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(theStart, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(musChan, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setSoundLoop(musChan, theStart, theEnd);
+	return BR_CONTINUE;
+}
+
+#pragma mark -
+#pragma mark Extra room bits
+
+builtIn(setFloor) {
+	UNUSEDALL
+	if (fun -> stack -> thisVar.varType == SVT_FILE) {
+		int v;
+		getValueType(v, SVT_FILE, fun -> stack -> thisVar);
+		trimStack(fun -> stack);
+		if (!setFloor(v)) return BR_ERROR;
+	} else {
+		trimStack(fun -> stack);
+		setFloorNull();
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(showFloor) {
+	UNUSEDALL
+	drawFloor();
+	return BR_CONTINUE;
+}
+
+builtIn(setZBuffer) {
+	UNUSEDALL
+	if (fun -> stack -> thisVar.varType == SVT_FILE) {
+		int v;
+		getValueType(v, SVT_FILE, fun -> stack -> thisVar);
+		trimStack(fun -> stack);
+		if (!setZBuffer(v)) return BR_ERROR;
+	} else {
+		trimStack(fun -> stack);
+		killZBuffer();
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(setLightMap) {
+	UNUSEDALL
+	switch (numParams) {
+	case 2:
+		if (!getValueType(lightMapMode, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		lightMapMode %= LIGHTMAPMODE_NUM;
+	// No break;
+
+	case 1:
+		if (fun -> stack -> thisVar.varType == SVT_FILE) {
+			int v;
+			getValueType(v, SVT_FILE, fun -> stack -> thisVar);
+			trimStack(fun -> stack);
+			if (!loadLightMap(v)) return BR_ERROR;
+			setVariable(fun -> reg, SVT_INT, 1);
+		} else {
+			trimStack(fun -> stack);
+			killLightMap();
+			setVariable(fun -> reg, SVT_INT, 0);
+		}
+		break;
+
+	default:
+		fatal("Function should have either 2 or 3 parameters");
+		return BR_ERROR;
+	}
+	return BR_CONTINUE;
+}
+
+
+#pragma mark -
+#pragma mark Objects
+
+builtIn(setSpeechMode) {
+	UNUSEDALL
+	if (!getValueType(speechMode, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (speechMode < 0 || speechMode > 2) {
+		fatal("Valid parameters are be SPEECHANDTEXT, SPEECHONLY or TEXTONLY");
+		return BR_ERROR;
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(somethingSpeaking) {
+	UNUSEDALL
+	int i = isThereAnySpeechGoingOn();
+	if (i == -1) {
+		setVariable(fun -> reg, SVT_INT, 0);
+	} else {
+		setVariable(fun -> reg, SVT_OBJTYPE, i);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(skipSpeech) {
+	UNUSEDALL
+	killSpeechTimers();
+	return BR_CONTINUE;
+}
+
+builtIn(getOverObject) {
+	UNUSEDALL
+	if (overRegion)
+		// Return value
+		setVariable(fun -> reg, SVT_OBJTYPE, overRegion -> thisType -> objectNum);
+	else
+		// Return value
+		setVariable(fun -> reg, SVT_INT, 0);
+	return BR_CONTINUE;
+}
+
+builtIn(rename) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	int objT;
+	if (!newText) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(objT, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	objectType *o = findObjectType(objT);
+	delete o -> screenName;
+	o -> screenName = newText;
+	return BR_CONTINUE;
+}
+
+builtIn(getObjectX) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *pers = findPerson(objectNumber);
+	if (pers) {
+		setVariable(fun -> reg, SVT_INT, pers -> x);
+	} else {
+		screenRegion *la = getRegionForObject(objectNumber);
+		if (la) {
+			setVariable(fun -> reg, SVT_INT, la -> sX);
+		} else {
+			setVariable(fun -> reg, SVT_INT, 0);
+		}
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(getObjectY) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *pers = findPerson(objectNumber);
+	if (pers) {
+		setVariable(fun -> reg, SVT_INT, pers -> y);
+	} else {
+		screenRegion *la = getRegionForObject(objectNumber);
+		if (la) {
+			setVariable(fun -> reg, SVT_INT, la -> sY);
+		} else {
+			setVariable(fun -> reg, SVT_INT, 0);
+		}
+	}
+	return BR_CONTINUE;
+}
+
+
+builtIn(addScreenRegion) {
+	UNUSEDALL
+	int sX, sY, x1, y1, x2, y2, di, objectNumber;
+	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(sY, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(sX, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(y2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(y1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (addScreenRegion(x1, y1, x2, y2, sX, sY, di, objectNumber)) return BR_CONTINUE;
+	return BR_ERROR;
+
+}
+
+builtIn(removeScreenRegion) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	removeScreenRegion(objectNumber);
+	return BR_CONTINUE;
+}
+
+builtIn(showBoxes) {
+	UNUSEDALL
+	showBoxes();
+	return BR_CONTINUE;
+}
+
+builtIn(removeAllScreenRegions) {
+	UNUSEDALL
+	killAllRegions();
+	return BR_CONTINUE;
+}
+
+builtIn(addCharacter) {
+	UNUSEDALL
+	persona *p;
+	int x, y, objectNumber;
+
+	p = getCostumeFromVar(fun -> stack -> thisVar);
+	if (p == NULL) return BR_ERROR;
+
+	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (addPerson(x, y, objectNumber, p)) return BR_CONTINUE;
+	return BR_ERROR;
+}
+
+builtIn(hideCharacter) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setShown(false, objectNumber);
+	return BR_CONTINUE;
+}
+
+builtIn(showCharacter) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setShown(true, objectNumber);
+	return BR_CONTINUE;
+}
+
+builtIn(removeAllCharacters) {
+	UNUSEDALL
+	killSpeechTimers();
+	killMostPeople();
+	return BR_CONTINUE;
+}
+
+builtIn(setCharacterDrawMode) {
+	UNUSEDALL
+	int obj, di;
+	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setDrawMode(di, obj);
+	return BR_CONTINUE;
+}
+builtIn(setCharacterTransparency) {
+	UNUSEDALL
+	int obj, x;
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setPersonTransparency(obj, x);
+	return BR_CONTINUE;
+}
+builtIn(setCharacterColourise) {
+	UNUSEDALL
+	int obj, r, g, b, mix;
+	if (!getValueType(mix, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(b, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(g, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(r, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setPersonColourise(obj, r, g, b, mix);
+	return BR_CONTINUE;
+}
+
+builtIn(setScale) {
+	UNUSEDALL
+	int val1, val2;
+	if (!getValueType(val2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(val1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setScale((short int) val1, (short int) val2);
+	return BR_CONTINUE;
+}
+
+builtIn(stopCharacter) {
+	UNUSEDALL
+	int obj;
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	// Return value
+	setVariable(fun -> reg, SVT_INT, stopPerson(obj));
+	return BR_CONTINUE;
+}
+
+builtIn(pasteCharacter) {
+	UNUSEDALL
+	int obj;
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *thisPerson = findPerson(obj);
+	if (thisPerson) {
+		personaAnimation *myAnim;
+		myAnim = thisPerson -> myAnim;
+		if (myAnim != thisPerson -> lastUsedAnim) {
+			thisPerson -> lastUsedAnim = myAnim;
+			thisPerson -> frameNum = 0;
+			thisPerson -> frameTick = myAnim -> frames[0].howMany;
+		}
+
+		int fNum = myAnim -> frames[thisPerson -> frameNum].frameNum;
+		fixScaleSprite(thisPerson -> x, thisPerson -> y, myAnim -> theSprites -> bank.sprites[abs(fNum)], myAnim -> theSprites -> bank.myPalette, thisPerson, 0, 0, fNum < 0);
+		setVariable(fun -> reg, SVT_INT, 1);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(animate) {
+	UNUSEDALL
+	int obj;
+	personaAnimation *pp = getAnimationFromVar(fun -> stack -> thisVar);
+	if (pp == NULL) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	animatePerson(obj, pp);
+	setVariable(fun -> reg, SVT_INT, timeForAnim(pp));
+	return BR_CONTINUE;
+}
+
+builtIn(setCostume) {
+	UNUSEDALL
+	int obj;
+	persona *pp = getCostumeFromVar(fun -> stack -> thisVar);
+	if (pp == NULL) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	animatePerson(obj, pp);
+	return BR_CONTINUE;
+}
+
+builtIn(floatCharacter) {
+	UNUSEDALL
+	int obj, di;
+	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, floatCharacter(di, obj));
+	return BR_CONTINUE;
+}
+
+builtIn(setCharacterWalkSpeed) {
+	UNUSEDALL
+	int obj, di;
+	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, setCharacterWalkSpeed(di, obj));
+	return BR_CONTINUE;
+}
+
+builtIn(turnCharacter) {
+	UNUSEDALL
+	int obj, di;
+	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, turnPersonToFace(obj, di));
+	return BR_CONTINUE;
+}
+
+builtIn(setCharacterExtra) {
+	UNUSEDALL
+	int obj, di;
+	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, setPersonExtra(obj, di));
+	return BR_CONTINUE;
+}
+
+builtIn(removeCharacter) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	removeOneCharacter(objectNumber);
+	return BR_CONTINUE;
+}
+
+static builtReturn moveChr(int numParams, loadedFunction *fun, bool force, bool immediate) {
+	switch (numParams) {
+	case 3: {
+		int x, y, objectNumber;
+
+		if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+
+		if (force) {
+			if (forceWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE;
+		} else if (immediate) {
+			jumpPerson(x, y, objectNumber);
+		} else {
+			if (makeWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE;
+		}
+		return BR_CONTINUE;
+	}
+
+	case 2: {
+		int toObj, objectNumber;
+		screenRegion *reggie;
+
+		if (!getValueType(toObj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		reggie = getRegionForObject(toObj);
+		if (reggie == NULL) return BR_CONTINUE;
+
+		if (force) {
+			if (forceWalkingPerson(reggie -> sX, reggie -> sY, objectNumber, fun, reggie -> di)) return BR_PAUSE;
+		} else if (immediate) {
+			jumpPerson(reggie -> sX, reggie -> sY, objectNumber);
+		} else {
+			if (makeWalkingPerson(reggie -> sX, reggie -> sY, objectNumber, fun, reggie -> di)) return BR_PAUSE;
+		}
+		return BR_CONTINUE;
+	}
+
+	default:
+		fatal("Built-in function must have either 2 or 3 parameters.");
+		return BR_ERROR;
+	}
+}
+
+builtIn(moveCharacter) {
+	UNUSEDALL
+	return moveChr(numParams, fun, false, false);
+}
+
+builtIn(forceCharacter) {
+	UNUSEDALL
+	return moveChr(numParams, fun, true, false);
+}
+
+builtIn(jumpCharacter) {
+	UNUSEDALL
+	return moveChr(numParams, fun, false, true);
+}
+
+builtIn(clearStatus) {
+	UNUSEDALL
+	clearStatusBar();
+	return BR_CONTINUE;
+}
+
+builtIn(removeLastStatus) {
+	UNUSEDALL
+	killLastStatus();
+	return BR_CONTINUE;
+}
+
+builtIn(addStatus) {
+	UNUSEDALL
+	addStatusBar();
+	return BR_CONTINUE;
+}
+
+builtIn(statusText) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!newText) return BR_ERROR;
+	trimStack(fun -> stack);
+	setStatusBar(newText);
+	delete newText;
+	return BR_CONTINUE;
+}
+
+builtIn(lightStatus) {
+	UNUSEDALL
+	int val;
+	if (!getValueType(val, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setLitStatus(val);
+	return BR_CONTINUE;
+}
+
+builtIn(positionStatus) {
+	UNUSEDALL
+	int x, y;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	positionStatus(x, y);
+	return BR_CONTINUE;
+}
+
+builtIn(alignStatus) {
+	UNUSEDALL
+	int val;
+	if (!getValueType(val, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	nowStatus -> alignStatus = (short) val;
+	return BR_CONTINUE;
+}
+
+static bool getFuncNumForCallback(int numParams, loadedFunction *fun, int &functionNum) {
+	switch (numParams) {
+	case 0:
+		functionNum = 0;
+		break;
+
+	case 1:
+		if (!getValueType(functionNum, SVT_FUNC, fun -> stack -> thisVar)) return false;
+		trimStack(fun -> stack);
+		break;
+
+	default:
+		fatal("Too many parameters.");
+		return false;
+	}
+	return true;
+}
+
+builtIn(onLeftMouse) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> leftMouseFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(onLeftMouseUp) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> leftMouseUpFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(onRightMouse) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> rightMouseFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(onRightMouseUp) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> rightMouseUpFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(onFocusChange) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> focusFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(onMoveMouse) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> moveMouseFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(onKeyboard) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		currentEvents -> spaceFunction = functionNum;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(spawnSub) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		if (!startNewFunctionNum(functionNum, 0, NULL, noStack)) return BR_ERROR;
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(cancelSub) {
+	UNUSEDALL
+	int functionNum;
+	if (getFuncNumForCallback(numParams, fun, functionNum)) {
+		bool killedMyself;
+		cancelAFunction(functionNum, fun, killedMyself);
+		if (killedMyself) {
+			abortFunction(fun);
+			return BR_ALREADY_GONE;
+		}
+		return BR_CONTINUE;
+	}
+	return BR_ERROR;
+}
+
+builtIn(stringWidth) {
+	UNUSEDALL
+	char *theText = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!theText) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	// Return value
+	setVariable(fun -> reg, SVT_INT, stringWidth(theText));
+	delete theText;
+	return BR_CONTINUE;
+}
+
+builtIn(hardScroll) {
+	UNUSEDALL
+	int v;
+	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	hardScroll(v);
+	return BR_CONTINUE;
+}
+
+
+builtIn(isScreenRegion) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, getRegionForObject(objectNumber) != NULL);
+	return BR_CONTINUE;
+}
+
+builtIn(setSpeechSpeed) {
+	UNUSEDALL
+	int number;
+	if (!getValueType(number, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	speechSpeed = number * 0.01;
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+builtIn(setFontSpacing) {
+	UNUSEDALL
+	int fontSpaceI;
+	if (!getValueType(fontSpaceI, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	fontSpace = fontSpaceI;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+builtIn(transitionLevel) {
+	UNUSEDALL
+	int number;
+	if (!getValueType(number, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	if (number < 0)
+		brightnessLevel = 0;
+	else if (number > 255)
+		brightnessLevel = 255;
+	else
+		brightnessLevel = number;
+
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+builtIn(captureAllKeys) {
+	UNUSEDALL
+	captureAllKeys = getBoolean(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, captureAllKeys);
+	return BR_CONTINUE;
+}
+
+
+builtIn(spinCharacter) {
+	UNUSEDALL
+	int number, objectNumber;
+	if (!getValueType(number, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *thisPerson = findPerson(objectNumber);
+	if (thisPerson) {
+		thisPerson -> wantAngle = number;
+		thisPerson -> spinning = true;
+		thisPerson -> continueAfterWalking = fun;
+		setVariable(fun -> reg, SVT_INT, 1);
+		return BR_PAUSE;
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+		return BR_CONTINUE;
+	}
+}
+
+builtIn(getCharacterDirection) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	onScreenPerson *thisPerson = findPerson(objectNumber);
+	if (thisPerson) {
+		setVariable(fun -> reg, SVT_INT, thisPerson -> direction);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(isCharacter) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	onScreenPerson *thisPerson = findPerson(objectNumber);
+	setVariable(fun -> reg, SVT_INT, thisPerson != NULL);
+	return BR_CONTINUE;
+}
+
+builtIn(normalCharacter) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	onScreenPerson *thisPerson = findPerson(objectNumber);
+	if (thisPerson) {
+		thisPerson -> myAnim = thisPerson -> myPersona -> animation[thisPerson -> direction];
+		setVariable(fun -> reg, SVT_INT, 1);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(isMoving) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	onScreenPerson *thisPerson = findPerson(objectNumber);
+	if (thisPerson) {
+		setVariable(fun -> reg, SVT_INT, thisPerson -> walking);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(fetchEvent) {
+	UNUSEDALL
+	int obj1, obj2;
+	if (!getValueType(obj2, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(obj1, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	int fNum = getCombinationFunction(obj1, obj2);
+
+	// Return value
+	if (fNum) {
+		setVariable(fun -> reg, SVT_FUNC, fNum);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(deleteFile) {
+	UNUSEDALL
+
+	char *namNormal = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	char *nam = encodeFilename(namNormal);
+	delete namNormal;
+	if (failSecurityCheck(nam)) return BR_ERROR;
+	setVariable(fun -> reg, SVT_INT, remove(nam));
+	delete nam;
+
+	return BR_CONTINUE;
+}
+
+builtIn(renameFile) {
+	UNUSEDALL
+	char *temp;
+
+	temp = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newnam = encodeFilename(temp);
+	trimStack(fun -> stack);
+	if (failSecurityCheck(newnam)) return BR_ERROR;
+	delete temp;
+
+	temp = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *nam = encodeFilename(temp);
+	trimStack(fun -> stack);
+	if (failSecurityCheck(nam)) return BR_ERROR;
+	delete temp;
+
+	setVariable(fun -> reg, SVT_INT, rename(nam, newnam));
+	delete nam;
+	delete newnam;
+
+
+	return BR_CONTINUE;
+}
+
+builtIn(cacheSound) {
+	UNUSEDALL
+	int fileNumber;
+	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (cacheSound(fileNumber) == -1) return BR_ERROR;
+	return BR_CONTINUE;
+}
+
+builtIn(burnString) {
+	UNUSEDALL
+	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	int y, x;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (x == IN_THE_CENTRE) x = (winWidth - stringWidth(newText)) >> 1;
+	fixFont(pastePalette);
+	burnStringToBackdrop(newText, x, y, pastePalette);
+	delete[] newText;
+	return BR_CONTINUE;
+}
+
+builtIn(setCharacterSpinSpeed) {
+	UNUSEDALL
+	int speed, who;
+	if (!getValueType(speed, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(who, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *thisPerson = findPerson(who);
+
+	if (thisPerson) {
+		thisPerson -> spinSpeed = speed;
+		setVariable(fun -> reg, SVT_INT, 1);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(setCharacterAngleOffset) {
+	UNUSEDALL
+	int angle, who;
+	if (!getValueType(angle, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(who, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *thisPerson = findPerson(who);
+
+	if (thisPerson) {
+		thisPerson -> angleOffset = angle;
+		setVariable(fun -> reg, SVT_INT, 1);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+
+builtIn(transitionMode) {
+	UNUSEDALL
+	int n;
+	if (!getValueType(n, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	fadeMode = n;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+
+// Removed function - does nothing
+builtIn(_rem_updateDisplay) {
+	UNUSEDALL
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, true);
+	return BR_CONTINUE;
+}
+
+builtIn(getSoundCache) {
+	UNUSEDALL
+	fun -> reg.varType = SVT_STACK;
+	fun -> reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
+	fun -> reg.varData.theStack -> first = NULL;
+	fun -> reg.varData.theStack -> last = NULL;
+	fun -> reg.varData.theStack -> timesUsed = 1;
+	if (!getSoundCacheStack(fun -> reg.varData.theStack)) return BR_ERROR;
+	return BR_CONTINUE;
+}
+
+builtIn(saveCustomData) {
+	UNUSEDALL
+	// saveCustomData (thisStack, fileName);
+	char *fileNameB = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!checkNew(fileNameB)) return BR_ERROR;
+
+	char *fileName = encodeFilename(fileNameB);
+	delete fileNameB;
+
+	if (failSecurityCheck(fileName)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+		fatal("First parameter isn't a stack");
+		return BR_ERROR;
+	}
+	if (!stackToFile(fileName, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	delete fileName;
+	return BR_CONTINUE;
+}
+
+builtIn(loadCustomData) {
+	UNUSEDALL
+
+	char *newTextA = getTextFromAnyVar(fun -> stack -> thisVar);
+	if (!checkNew(newTextA)) return BR_ERROR;
+
+	char *newText = encodeFilename(newTextA);
+	delete newTextA;
+
+	if (failSecurityCheck(newText)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	unlinkVar(fun -> reg);
+	fun -> reg.varType = SVT_STACK;
+	fun -> reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
+	fun -> reg.varData.theStack -> first = NULL;
+	fun -> reg.varData.theStack -> last = NULL;
+	fun -> reg.varData.theStack -> timesUsed = 1;
+	if (!fileToStack(newText, fun -> reg.varData.theStack)) return BR_ERROR;
+	delete newText;
+	return BR_CONTINUE;
+}
+
+builtIn(setCustomEncoding) {
+	UNUSEDALL
+	int n;
+	if (!getValueType(n, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	saveEncoding = n;
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+builtIn(freeSound) {
+	UNUSEDALL
+	int v;
+	if (!getValueType(v, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	huntKillFreeSound(v);
+	return BR_CONTINUE;
+}
+
+builtIn(parallaxAdd) {
+	UNUSEDALL
+	if (frozenStuff) {
+		fatal("Can't set background parallax image while frozen");
+		return BR_ERROR;
+	} else {
+		int wrapX, wrapY, v;
+		if (!getValueType(wrapY, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!getValueType(wrapX, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+		if (!getValueType(v, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+		trimStack(fun -> stack);
+
+		if (!loadParallax(v, wrapX, wrapY)) return BR_ERROR;
+		setVariable(fun -> reg, SVT_INT, 1);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(parallaxClear) {
+	UNUSEDALL
+	killParallax();
+	setVariable(fun -> reg, SVT_INT, 1);
+	return BR_CONTINUE;
+}
+
+builtIn(getPixelColour) {
+	UNUSEDALL
+	int x, y;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	unlinkVar(fun -> reg);
+	fun -> reg.varType = SVT_STACK;
+	fun -> reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
+	fun -> reg.varData.theStack -> first = NULL;
+	fun -> reg.varData.theStack -> last = NULL;
+	fun -> reg.varData.theStack -> timesUsed = 1;
+	if (!getRGBIntoStack(x, y, fun -> reg.varData.theStack)) return BR_ERROR;
+
+	return BR_CONTINUE;
+}
+
+builtIn(makeFastArray) {
+	UNUSEDALL
+	switch (fun -> stack -> thisVar.varType) {
+	case SVT_STACK: {
+		bool success = makeFastArrayFromStack(fun -> reg, fun -> stack -> thisVar.varData.theStack);
+		trimStack(fun -> stack);
+		return success ? BR_CONTINUE : BR_ERROR;
+	}
+	break;
+
+	case SVT_INT: {
+		int i = fun -> stack -> thisVar.varData.intValue;
+		trimStack(fun -> stack);
+		return makeFastArraySize(fun -> reg, i) ? BR_CONTINUE : BR_ERROR;
+	}
+	break;
+
+	default:
+		break;
+	}
+	fatal("Parameter must be a number or a stack.");
+	return BR_ERROR;
+}
+
+builtIn(getCharacterScale) {
+	UNUSEDALL
+	int objectNumber;
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	onScreenPerson *pers = findPerson(objectNumber);
+	if (pers) {
+		setVariable(fun -> reg, SVT_INT, pers -> scale * 100);
+	} else {
+		setVariable(fun -> reg, SVT_INT, 0);
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(getLanguageID) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, gameSettings.languageID);
+	return BR_CONTINUE;
+}
+
+// Removed function
+builtIn(_rem_launchWith) {
+	UNUSEDALL
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, false);
+
+	return BR_CONTINUE;
+
+}
+
+builtIn(getFramesPerSecond) {
+	UNUSEDALL
+	setVariable(fun -> reg, SVT_INT, lastFramesPerSecond);
+	return BR_CONTINUE;
+}
+
+builtIn(showThumbnail) {
+	UNUSEDALL
+	int x, y;
+	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+
+	// Encode the name!Encode the name!
+	char *aaaaa = getTextFromAnyVar(fun -> stack -> thisVar);
+	//              deb ("Got name:", aaaaa;)
+	trimStack(fun -> stack);
+	//              deb ("About to encode", aaaaa);
+	char *file = encodeFilename(aaaaa);
+	//              deb ("Made new name", file);
+	//              deb ("aaaaa is still ", aaaaa);
+	delete[] aaaaa;
+	//              deb ("Deleted", "aaaaa");
+	showThumbnail(file, x, y);
+	delete[] file;
+	return BR_CONTINUE;
+}
+
+builtIn(setThumbnailSize) {
+	UNUSEDALL
+	if (!getValueType(thumbHeight, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(thumbWidth, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (thumbWidth < 0 || thumbHeight < 0 || thumbWidth > winWidth || thumbHeight > winHeight) {
+		char buff[50];
+		sprintf(buff, "%d x %d", thumbWidth, thumbHeight);
+		fatal("Invalid thumbnail size", buff);
+		return BR_ERROR;
+	}
+	return BR_CONTINUE;
+}
+
+builtIn(hasFlag) {
+	UNUSEDALL
+	int objNum, flagIndex;
+	if (!getValueType(flagIndex, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	if (!getValueType(objNum, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun -> stack);
+	objectType *objT = findObjectType(objNum);
+	if (!objT) return BR_ERROR;
+	setVariable(fun -> reg, SVT_INT, objT->flags & (1 << flagIndex));
+	return BR_CONTINUE;
+}
+
+builtIn(snapshotGrab) {
+	UNUSEDALL
+	return snapshot() ? BR_CONTINUE : BR_ERROR;
+}
+
+builtIn(snapshotClear) {
+	UNUSEDALL
+	nosnapshot();
+	return BR_CONTINUE;
+}
+
+builtIn(bodgeFilenames) {
+	UNUSEDALL
+	bool lastValue = allowAnyFilename;
+	allowAnyFilename = getBoolean(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, lastValue);
+	return BR_CONTINUE;
+}
+
+// Deprecated - does nothing.
+builtIn(_rem_registryGetString) {
+	UNUSEDALL
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	setVariable(fun -> reg, SVT_INT, 0);
+
+	return BR_CONTINUE;
+}
+
+builtIn(quitWithFatalError) {
+	UNUSEDALL
+	char *mess = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun -> stack);
+	fatal(mess);
+	return BR_ERROR;
+}
+
+builtIn(_rem_setCharacterAA) {
+	UNUSEDALL
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+
+	return BR_CONTINUE;
+}
+
+builtIn(_rem_setMaximumAA) {
+	UNUSEDALL
+
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+	trimStack(fun -> stack);
+
+	return BR_CONTINUE;
+
+}
+
+builtIn(setBackgroundEffect) {
+	UNUSEDALL
+	bool done = blur_createSettings(numParams, fun->stack);
+	setVariable(fun -> reg, SVT_INT, done ? 1 : 0);
+	return BR_CONTINUE;
+}
+
+builtIn(doBackgroundEffect) {
+	UNUSEDALL
+	bool done = blurScreen();
+	setVariable(fun -> reg, SVT_INT, done ? 1 : 0);
+	return BR_CONTINUE;
+}
+
+#pragma mark -
+#pragma mark Other functions
+
+//-------------------------------------
+
+#define FUNC(special,name)      {builtIn_ ## name},
+static builtInFunctionData builtInFunctionArray[] = {
+#include "CommonCode/functionlist.h"
+};
+#undef FUNC
+
+#define FUNC(special,name)      {#name},
+char builtInFunctionNames[][25] = {
+#include "CommonCode/functionlist.h"
+};
+#undef FUNC
+
+#define NUM_FUNCS           (sizeof (builtInFunctionArray) / sizeof (builtInFunctionArray[0]))
+
+
+
+builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun) {
+	// fprintf (stderr, "Calling function %d: %s\n", whichFunc, builtInFunctionNames[whichFunc]);    fflush (stderr);
+	if (numBIFNames) {
+
+		//      deb ("IN:", (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function");
+		//      deb ("GO:", (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function");
+
+		setFatalInfo(
+		    (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function",
+		    (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function");
+	}
+
+	if (whichFunc < NUM_FUNCS) {
+		if (paramNum[whichFunc] != -1) {
+			if (paramNum[whichFunc] != numParams) {
+				char buff[100];
+				sprintf(buff, "Built in function must have %i parameter%s",
+				        paramNum[whichFunc],
+				        (paramNum[whichFunc] == 1) ? "" : "s");
+
+				fatal(copyString(buff));
+				return BR_ERROR;
+			}
+		}
+
+		if (builtInFunctionArray[whichFunc].func) {
+			//fprintf (stderr, "Calling %i: %s\n", whichFunc, builtInFunctionNames[whichFunc]);
+			return builtInFunctionArray[whichFunc].func(numParams, fun);
+		}
+	}
+
+	fatal("Unknown / unimplemented built-in function.");
+	return BR_ERROR;
+}
+
diff --git a/engines/sludge/builtin.h b/engines/sludge/builtin.h
new file mode 100644
index 0000000..8f5ac59
--- /dev/null
+++ b/engines/sludge/builtin.h
@@ -0,0 +1,31 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_BUILTIN_H
+#define SLUDGE_BUILTIN_H
+
+enum builtReturn {BR_KEEP_AND_PAUSE, BR_ERROR, BR_CONTINUE, BR_PAUSE, BR_CALLAFUNC, BR_ALREADY_GONE};
+
+bool failSecurityCheck(char *fn);
+builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun);
+
+#endif
diff --git a/engines/sludge/color.frag b/engines/sludge/color.frag
new file mode 100644
index 0000000..1f3e45a
--- /dev/null
+++ b/engines/sludge/color.frag
@@ -0,0 +1,7 @@
+varying vec4 color;
+
+void main(void)
+{
+	gl_FragColor = color;
+}
+
diff --git a/engines/sludge/color.vert b/engines/sludge/color.vert
new file mode 100644
index 0000000..819d377
--- /dev/null
+++ b/engines/sludge/color.vert
@@ -0,0 +1,13 @@
+attribute vec4 myVertex;
+
+uniform mat4 myPMVMatrix;
+uniform vec4 myColor;
+
+varying vec4 color;
+
+void main(void)
+{
+	gl_Position = myPMVMatrix * myVertex;
+	color = myColor;
+}
+
diff --git a/engines/sludge/colours.h b/engines/sludge/colours.h
new file mode 100644
index 0000000..503823f
--- /dev/null
+++ b/engines/sludge/colours.h
@@ -0,0 +1,47 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_COLOURS_H
+#define SLUDGE_COLOURS_H
+
+// Simple colour conversion routines to deal with 16-bit graphics
+//unsigned short int makeColour (byte r, byte g, byte b);
+
+inline unsigned short redValue(unsigned short c) {
+	return (c >> 11) << 3;
+}
+inline unsigned short greenValue(unsigned short c) {
+	return ((c >> 5) & 63) << 2;
+}
+inline unsigned short blueValue(unsigned short c) {
+	return (c & 31) << 3;
+}
+
+inline unsigned short makeGrey(unsigned short int r) {
+	return ((r >> 3) << 11) | ((r >> 2) << 5) | (r >> 3);
+}
+
+inline unsigned short makeColour(unsigned short int r, unsigned short int g, unsigned short int b) {
+	return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
+}
+
+#endif
diff --git a/engines/sludge/csludge.h b/engines/sludge/csludge.h
new file mode 100644
index 0000000..3c73a9d1
--- /dev/null
+++ b/engines/sludge/csludge.h
@@ -0,0 +1,43 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_CSLUDGE_H
+#define SLUDGE_CSLUDGE_H
+
+enum sludgeCommand {SLU_UNKNOWN,
+                    SLU_RETURN, SLU_BRANCH, SLU_BR_ZERO, SLU_SET_GLOBAL,
+                    SLU_SET_LOCAL, SLU_LOAD_GLOBAL, SLU_LOAD_LOCAL,
+                    SLU_PLUS, SLU_MINUS, SLU_MULT, SLU_DIVIDE,
+                    SLU_AND, SLU_OR, SLU_EQUALS, SLU_NOT_EQ, SLU_MODULUS,
+                    SLU_LOAD_VALUE, SLU_LOAD_BUILT, SLU_LOAD_FUNC, SLU_CALLIT,
+                    SLU_LOAD_STRING, SLU_LOAD_FILE, /*SLU_LOAD_SCENE,*/ SLU_LOAD_OBJTYPE,
+                    SLU_NOT, SLU_LOAD_NULL, SLU_STACK_PUSH, SLU_LESSTHAN, SLU_MORETHAN, SLU_NEGATIVE,
+                    SLU_UNREG, SLU_LESS_EQUAL, SLU_MORE_EQUAL,
+                    SLU_INCREMENT_LOCAL,
+                    SLU_DECREMENT_LOCAL,
+                    SLU_INCREMENT_GLOBAL,
+                    SLU_DECREMENT_GLOBAL, SLU_INDEXSET, SLU_INDEXGET,
+                    SLU_INCREMENT_INDEX, SLU_DECREMENT_INDEX, SLU_QUICK_PUSH,
+                    numSludgeCommands
+                   };
+
+#endif
diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
new file mode 100644
index 0000000..6ad3a35
--- /dev/null
+++ b/engines/sludge/cursors.cpp
@@ -0,0 +1,86 @@
+/* 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.
+ *
+ */
+
+#if 0
+#if !defined(HAVE_GLES2)
+#include "GLee.h"
+#else
+#include <GLES2/gl2.h>
+#endif
+#endif
+
+#include "allfiles.h"
+#include "cursors.h"
+#include "colours.h"
+#include "sprites.h"
+#include "sprbanks.h"
+#include "people.h"
+#include "sludger.h"
+
+personaAnimation *mouseCursorAnim;
+int mouseCursorFrameNum = 0;
+int mouseCursorCountUp = 0;
+
+extern inputType input;
+
+void pickAnimCursor(personaAnimation *pp) {
+	deleteAnim(mouseCursorAnim);
+	mouseCursorAnim = pp;
+	mouseCursorFrameNum = 0;
+	mouseCursorCountUp = 0;
+}
+
+void displayCursor() {
+#if 0
+	if (mouseCursorAnim && mouseCursorAnim -> numFrames) {
+
+		int spriteNum = mouseCursorAnim -> frames[mouseCursorFrameNum].frameNum;
+		int flipMe = 0;
+
+		if (spriteNum < 0) {
+			spriteNum = -spriteNum;
+			flipMe = 1;
+			if (spriteNum >= mouseCursorAnim -> theSprites -> bank.total) spriteNum = 0;
+		} else {
+			if (spriteNum >= mouseCursorAnim -> theSprites -> bank.total) flipMe = 2;
+		}
+
+		if (flipMe != 2) {
+			(flipMe ? flipFontSprite : fontSprite)(input.mouseX, input.mouseY,
+			                                       mouseCursorAnim -> theSprites -> bank.sprites[spriteNum],
+			                                       mouseCursorAnim -> theSprites -> bank.myPalette /* ( spritePalette&) NULL*/);
+		}
+
+		if (++ mouseCursorCountUp >= mouseCursorAnim -> frames[mouseCursorFrameNum].howMany) {
+			mouseCursorCountUp = 0;
+			mouseCursorFrameNum ++;
+			mouseCursorFrameNum %= mouseCursorAnim -> numFrames;
+		}
+	}
+#endif
+}
+
+void pasteCursor(int x, int y, personaAnimation *c) {
+	if (c -> numFrames) pasteSpriteToBackDrop(x, y,
+		        c -> theSprites -> bank.sprites[c -> frames[0].frameNum],
+		        c -> theSprites -> bank.myPalette);
+}
diff --git a/engines/sludge/cursors.h b/engines/sludge/cursors.h
new file mode 100644
index 0000000..9c803fc
--- /dev/null
+++ b/engines/sludge/cursors.h
@@ -0,0 +1,30 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_CURSORS_H
+#define SLUDGE_CURSORS_H
+
+void pickAnimCursor(struct personaAnimation *pp);
+void displayCursor();
+void pasteCursor(int x, int y, struct personaAnimation *c);
+
+#endif
diff --git a/engines/sludge/debug.cpp b/engines/sludge/debug.cpp
new file mode 100644
index 0000000..222f411
--- /dev/null
+++ b/engines/sludge/debug.cpp
@@ -0,0 +1,52 @@
+/* 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.
+ *
+ */
+
+#if 0
+#include <stdarg.h>
+#endif
+
+#include "allfiles.h"
+#include "debug.h"
+#include "language.h"
+
+void debugOut(const char *a, ...) {
+	if (! gameSettings.debugMode) return;
+
+	va_list argptr;
+	va_start(argptr, a);
+
+#if ALLOW_FILE
+#if defined __unix__ && !(defined __APPLE__)
+	vfprintf(stderr, a, argptr);
+#else
+	FILE *fp = fopen("debuggy.txt", "at");
+	if (fp) {
+		vfprintf(fp, a, argptr);
+		fclose(fp);
+	}
+#endif
+#endif
+}
+
+void debugHeader() {
+	debugOut("*** Engine compiled " __DATE__ " at " __TIME__ ".\n");
+}
diff --git a/engines/sludge/debug.h b/engines/sludge/debug.h
new file mode 100644
index 0000000..94b6c34
--- /dev/null
+++ b/engines/sludge/debug.h
@@ -0,0 +1,29 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_DEDBUG_H
+#define SLUDGE_DEGBUG_H
+
+void debugOut(const char *a, ...);
+void debugHeader();
+
+#endif
diff --git a/engines/sludge/eglport/eglport.cpp b/engines/sludge/eglport/eglport.cpp
new file mode 100755
index 0000000..8414383
--- /dev/null
+++ b/engines/sludge/eglport/eglport.cpp
@@ -0,0 +1,712 @@
+/**
+ *
+ *  EGLPORT.C
+ *  Copyright (C) 2011-2013 Scott R. Smith
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to deal
+ *  in the Software without restriction, including without limitation the rights
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *  copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *  THE SOFTWARE.
+ *
+ */
+
+#include "eglport.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+//#define USE_EGL_SDL 1
+//#define USE_GLES1	1
+
+#if defined(USE_EGL_SDL)
+#include "SDL.h"
+#include "SDL_syswm.h"
+SDL_SysWMinfo sysWmInfo;      /** Holds our X Display/Window information */
+#endif /* USE_EGL_SDL */
+
+#if defined(PANDORA) /* Pandora VSync Support */
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/fb.h>
+
+#ifndef FBIO_WAITFORVSYNC
+#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
+#endif
+int fbdev = -1;
+
+#elif defined(RPI)
+#include "bcm_host.h"
+#endif /* PANDORA */
+
+enum EGL_RENDER_T {
+    RENDER_RAW=0,           /** Sets render mode to raw or framebuffer mode. */
+    RENDER_SDL,             /** Sets render mode to X11/SDL mode. */
+    RENDER_TOTAL
+};
+
+enum EGL_SETTINGS_T {
+    CFG_MODE=0,             /** Render mode for EGL 0=RAW 1=SDL. */
+    CFG_VSYNC,              /** Controls system vsync if available. */
+    CFG_FSAA,               /** Number of samples for full screen AA. 0 is off, 2/4 samples. */
+    CFG_FPS,                /** Calculate and report frame per second. */
+    CFG_RED_SIZE,           /** Number of bits of Red in the color buffer. */
+    CFG_GREEN_SIZE,         /** Number of bits of Green in the color buffer. */
+    CFG_BLUE_SIZE,          /** Number of bits of Blue in the color buffer. */
+    CFG_ALPHA_SIZE,         /** Number of bits of Alpha in the color buffer. */
+    CFG_DEPTH_SIZE,         /** Number of bits of Z in the depth buffer. */
+    CFG_BUFFER_SIZE,        /** The total color component bits in the color buffer. */
+    CFG_STENCIL_SIZE,       /** Number of bits of Stencil in the stencil buffer. */
+    CFG_TOTAL               /** Total number of settings. */
+};
+
+NativeDisplayType   nativeDisplay = 0;      /** Reference to the systems native display */
+NativeWindowType    nativeWindow  = 0;      /** Reference to the systems native window */
+EGLint              eglSettings[CFG_TOTAL]; /** Stores setting values. */
+EGLDisplay          eglDisplay    = NULL;   /** Reference to the EGL display */
+EGLConfig           eglConfig     = NULL;   /** Reference to the EGL config */
+EGLContext          eglContext    = NULL;   /** Reference to the EGL context */
+EGLSurface          eglSurface    = NULL;   /** Reference to the EGL surface */
+
+#define     totalConfigsIn 5                /** Total number of configurations to request */
+EGLint      totalConfigsFound = 0;          /** Total number of configurations matching attributes */
+EGLConfig   eglConfigs[totalConfigsIn];     /** Structure containing references to matching configurations */
+
+uint32_t    fpsCount    = 0;                /** Total number of frames counted */
+uint32_t    fpsTime     = 0;                /** Start time of frame count measurment */
+
+int8_t	eglColorbits 	= 0;
+int8_t	eglDepthbits	= 0;
+int8_t	eglStencilbits	= 0;
+
+
+/** Private API */
+void        OpenCfg                 ( const char* file );
+int8_t      ConfigureEGL            ( EGLConfig config );
+int8_t      FindEGLConfigs          ( void );
+int8_t      CheckEGLErrors          ( const char* file, uint16_t line );
+
+int8_t      GetNativeDisplay        ( void );
+int8_t      GetNativeWindow         ( uint16_t width, uint16_t height );
+void        FreeNativeDisplay       ( void );
+void        FreeNativeWindow        ( void );
+
+void        Platform_Open           ( void );
+void        Platform_Close          ( void );
+void        Platform_VSync          ( void );
+uint32_t    Platform_GetTicks       ( void );
+
+void EGL_Init( void )
+{
+  //nothing...
+  return;
+}
+/** @brief Release all EGL and system resources
+ */
+void EGL_Close( void )
+{
+    /* Release EGL resources */
+    if (eglDisplay != NULL)
+    {
+        peglMakeCurrent( eglDisplay, NULL, NULL, EGL_NO_CONTEXT );
+        if (eglContext != NULL) {
+            peglDestroyContext( eglDisplay, eglContext );
+        }
+        if (eglSurface != NULL) {
+            peglDestroySurface( eglDisplay, eglSurface );
+        }
+        peglTerminate( eglDisplay );
+    }
+
+    eglSurface = NULL;
+    eglContext = NULL;
+    eglDisplay = NULL;
+	
+	eglColorbits = 0;
+	eglDepthbits = 0;
+	eglStencilbits = 0;
+
+    /* Release platform resources */
+    FreeNativeWindow();
+    FreeNativeDisplay();
+    Platform_Close();
+
+    CheckEGLErrors( __FILE__, __LINE__ );
+
+    printf( "EGLport: Closed\n" );
+}
+
+/** @brief Swap the surface buffer onto the display
+ */
+void EGL_SwapBuffers( void )
+{
+    if (eglSettings[CFG_VSYNC] != 0) {
+        Platform_VSync();
+    }
+
+    peglSwapBuffers( eglDisplay, eglSurface );
+
+    if (eglSettings[CFG_FPS] != 0) {
+        fpsCount++;
+
+        if (fpsTime - Platform_GetTicks() >= 1000)
+        {
+            printf( "EGLport: %d fps\n", fpsCount );
+            fpsTime = Platform_GetTicks();
+            fpsCount = 0;
+        }
+    }
+}
+
+/** @brief Obtain the system display and initialize EGL
+ * @param width : desired pixel width of the window (not used by all platforms)
+ * @param height : desired pixel height of the window (not used by all platforms)
+ * @return : 0 if the function passed, else 1
+ */
+int8_t EGL_Open( /*uint16_t width, uint16_t height*/ )
+{
+    EGLint eglMajorVer, eglMinorVer;
+    EGLBoolean result;
+    uint32_t configIndex = 0;
+    const char* output;
+
+    static const EGLint contextAttribs[] =
+    {
+#if defined(USE_GLES2)
+          EGL_CONTEXT_CLIENT_VERSION,     2,
+#endif
+          EGL_NONE
+    };
+
+#if defined(DEBUG)
+    printf( "EGLport Warning: DEBUG is enabled which may effect performance\n" );
+#endif
+
+    /* Check that system is not open */
+    if (eglDisplay != NULL || eglContext != NULL || eglSurface != NULL)
+    {
+        printf( "EGLport ERROR: EGL system is already open!\n" );
+        return 1;
+    }
+
+    /* Check for the cfg file to alternative settings */
+    OpenCfg( "eglport.cfg" );
+
+    /* Setup any platform specific bits */
+    Platform_Open();
+
+    printf( "EGLport: Opening EGL display\n" );
+    if (GetNativeDisplay() != 0)
+    {
+        printf( "EGLport ERROR: Unable to obtain native display!\n" );
+        return 1;
+    }
+
+    eglDisplay = peglGetDisplay( nativeDisplay );
+    if (eglDisplay == EGL_NO_DISPLAY)
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Unable to create EGL display.\n" );
+        return 1;
+    }
+
+    printf( "EGLport: Initializing\n" );
+    result = peglInitialize( eglDisplay, &eglMajorVer, &eglMinorVer );
+    if (result != EGL_TRUE )
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Unable to initialize EGL display.\n" );
+        return 1;
+    }
+
+    /* Get EGL Library Information */
+    printf( "EGL Implementation Version: Major %d Minor %d\n", eglMajorVer, eglMinorVer );
+    output = peglQueryString( eglDisplay, EGL_VENDOR );
+    printf( "EGL_VENDOR: %s\n", output );
+    output = peglQueryString( eglDisplay, EGL_VERSION );
+    printf( "EGL_VERSION: %s\n", output );
+    output = peglQueryString( eglDisplay, EGL_EXTENSIONS );
+    printf( "EGL_EXTENSIONS: %s\n", output );
+
+    if (FindEGLConfigs() != 0)
+    {
+        printf( "EGLport ERROR: Unable to configure EGL. See previous error.\n" );
+        return 1;
+    }
+
+    printf( "EGLport: Using Config %d\n", configIndex );
+#if defined(EGL_VERSION_1_2)
+    /* Bind GLES and create the context */
+    printf( "EGLport: Binding API\n" );
+    result = peglBindAPI( EGL_OPENGL_ES_API );
+    if ( result == EGL_FALSE )
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Could not bind EGL API.\n" );
+        return 1;
+    }
+#endif /* EGL_VERSION_1_2 */
+
+    printf( "EGLport: Creating Context\n" );
+    eglContext = peglCreateContext( eglDisplay, eglConfigs[configIndex], NULL, contextAttribs );
+    if (eglContext == EGL_NO_CONTEXT)
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Unable to create GLES context!\n");
+        return 1;
+    }
+
+    printf( "EGLport: Creating window surface\n" );
+    if (GetNativeWindow( 800, 480/*width, height*/ ) != 0)
+    {
+        printf( "EGLport ERROR: Unable to obtain native window!\n" );
+        return 1;
+    }
+
+    eglSurface = peglCreateWindowSurface( eglDisplay, eglConfigs[configIndex], nativeWindow, 0 );
+    if (eglSurface == EGL_NO_SURFACE)
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Unable to create EGL surface!\n" );
+        return 1;
+    }
+
+    printf( "EGLport: Making Current\n" );
+    result = peglMakeCurrent( eglDisplay,  eglSurface,  eglSurface, eglContext );
+    if (result != EGL_TRUE)
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Unable to make GLES context current\n" );
+        return 1;
+    }
+
+	{
+	  EGLint color, depth, stencil;
+	  eglGetConfigAttrib(eglDisplay, eglConfigs[configIndex], EGL_BUFFER_SIZE, &color);
+	  eglGetConfigAttrib(eglDisplay, eglConfigs[configIndex], EGL_DEPTH_SIZE, &depth);
+	  eglGetConfigAttrib(eglDisplay, eglConfigs[configIndex], EGL_STENCIL_SIZE, &stencil);
+	  eglColorbits = (color==16)?5:8; //quick hack
+	  eglDepthbits = depth;
+	  eglStencilbits = stencil;
+	}
+
+    printf( "EGLport: Setting swap interval\n" );
+    peglSwapInterval( eglDisplay, (eglSettings[CFG_VSYNC] > 0) ? 1 : 0 );
+
+    printf( "EGLport: Complete\n" );
+
+    CheckEGLErrors( __FILE__, __LINE__ );
+	
+    return 0;
+}
+
+/** @brief Read settings that configure how to use EGL
+ * @param file : name of the config file
+ */
+void OpenCfg ( const char* file )
+{
+    #define MAX_STRING 20
+    #define MAX_SIZE 100
+    uint8_t i;
+    FILE* fp = NULL;
+    char* location = NULL;
+    char eglStrings[CFG_TOTAL][MAX_STRING];
+    char buffer[MAX_SIZE];
+
+    strncpy( eglStrings[CFG_MODE], "egl_mode=", MAX_STRING );
+    strncpy( eglStrings[CFG_VSYNC], "use_vsync=", MAX_STRING );
+    strncpy( eglStrings[CFG_FSAA], "use_fsaa=", MAX_STRING );
+    strncpy( eglStrings[CFG_RED_SIZE], "size_red=", MAX_STRING );
+    strncpy( eglStrings[CFG_GREEN_SIZE], "size_green=", MAX_STRING );
+    strncpy( eglStrings[CFG_BLUE_SIZE], "size_blue=", MAX_STRING );
+    strncpy( eglStrings[CFG_ALPHA_SIZE], "size_alpha=", MAX_STRING );
+    strncpy( eglStrings[CFG_DEPTH_SIZE], "size_depth=", MAX_STRING );
+    strncpy( eglStrings[CFG_BUFFER_SIZE], "size_buffer=", MAX_STRING );
+    strncpy( eglStrings[CFG_STENCIL_SIZE], "size_stencil=", MAX_STRING );
+
+    /* Set defaults */
+#if defined(USE_EGL_SDL) && !defined(PANDORA)
+    eglSettings[CFG_MODE]           = RENDER_SDL;
+#else
+    eglSettings[CFG_MODE]           = RENDER_RAW;
+#endif
+    eglSettings[CFG_VSYNC]          = 0;
+    eglSettings[CFG_FSAA]           = 0;
+    eglSettings[CFG_FPS]            = 0;
+    eglSettings[CFG_RED_SIZE]       = 5;
+    eglSettings[CFG_GREEN_SIZE]     = 6;
+    eglSettings[CFG_BLUE_SIZE]      = 5;
+    eglSettings[CFG_ALPHA_SIZE]     = 0;
+    eglSettings[CFG_DEPTH_SIZE]     = 16;
+    eglSettings[CFG_BUFFER_SIZE]    = 16;
+    eglSettings[CFG_STENCIL_SIZE]   = 0;
+
+    /* Parse INI file */
+    fp = fopen( file, "r");
+    if (fp != NULL)
+    {
+        while (fgets( buffer, MAX_SIZE, fp ) != NULL)
+        {
+            for (i=0; i<CFG_TOTAL; i++)
+            {
+                location = strstr( buffer, eglStrings[i] );
+                if (location != NULL)
+                {
+                    eglSettings[i] = atol( location+strlen( eglStrings[i] ) );
+                    printf( "EGLport: %s set to %d.\n", eglStrings[i], eglSettings[i] );
+                    break;
+                }
+            }
+        }
+
+        fclose( fp );
+    }
+    else
+    {
+        printf( "EGL NOTICE: Unable to read ini settings from file '%s'. Using defaults\n", file );
+    }
+}
+
+/** @brief Find a EGL configuration tht matches the defined attributes
+ * @return : 0 if the function passed, else 1
+ */
+int8_t FindEGLConfigs( void )
+{
+    EGLBoolean result;
+    int attrib = 0;
+    EGLint ConfigAttribs[23];
+
+    ConfigAttribs[attrib++] = EGL_RED_SIZE;                         /* 1 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_RED_SIZE];            /* 2 */
+    ConfigAttribs[attrib++] = EGL_GREEN_SIZE;                       /* 3 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_GREEN_SIZE];          /* 4 */
+    ConfigAttribs[attrib++] = EGL_BLUE_SIZE;                        /* 5 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_BLUE_SIZE];           /* 6 */
+    ConfigAttribs[attrib++] = EGL_ALPHA_SIZE;                       /* 7 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_ALPHA_SIZE];          /* 8 */
+    ConfigAttribs[attrib++] = EGL_DEPTH_SIZE;                       /* 9 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_DEPTH_SIZE];          /* 10 */
+    ConfigAttribs[attrib++] = EGL_BUFFER_SIZE;                      /* 11 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_BUFFER_SIZE];         /* 12 */
+    ConfigAttribs[attrib++] = EGL_STENCIL_SIZE;                     /* 13 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_STENCIL_SIZE];        /* 14 */
+    ConfigAttribs[attrib++] = EGL_SURFACE_TYPE;                     /* 15 */
+    ConfigAttribs[attrib++] = EGL_WINDOW_BIT;                       /* 16 */
+#if defined(EGL_VERSION_1_2)
+    ConfigAttribs[attrib++] = EGL_RENDERABLE_TYPE;                  /* 17 */
+#if defined(USE_GLES1)
+    ConfigAttribs[attrib++] = EGL_OPENGL_ES_BIT;
+#elif defined(USE_GLES2)
+    ConfigAttribs[attrib++] = EGL_OPENGL_ES2_BIT;                   /* 18 */
+#endif /* USE_GLES1 */
+#endif /* EGL_VERSION_1_2 */
+    ConfigAttribs[attrib++] = EGL_SAMPLE_BUFFERS;                   /* 19 */
+    ConfigAttribs[attrib++] = (eglSettings[CFG_FSAA] > 0) ? 1 : 0;  /* 20 */
+    ConfigAttribs[attrib++] = EGL_SAMPLES;                          /* 21 */
+    ConfigAttribs[attrib++] = eglSettings[CFG_FSAA];                /* 22 */
+    ConfigAttribs[attrib++] = EGL_NONE;                             /* 23 */
+
+    result = peglChooseConfig( eglDisplay, ConfigAttribs, eglConfigs, totalConfigsIn, &totalConfigsFound );
+    if (result != EGL_TRUE || totalConfigsFound == 0)
+    {
+        CheckEGLErrors( __FILE__, __LINE__ );
+        printf( "EGLport ERROR: Unable to query for available configs, found %d.\n", totalConfigsFound );
+        return 1;
+    }
+    printf( "EGLport: Found %d available configs\n", totalConfigsFound );
+
+    return 0;
+}
+
+/** @brief Error checking function
+ * @param file : string reference that contains the source file that the check is occuring in
+ * @param line : numeric reference that contains the line number that the check is occuring in
+ * @return : 0 if the function passed, else 1
+ */
+int8_t CheckEGLErrors( const char* file, uint16_t line )
+{
+    EGLenum error;
+    const char* errortext;
+    const char* description;
+
+    error = eglGetError();
+
+    if (error != EGL_SUCCESS && error != 0)
+    {
+        switch (error)
+        {
+            case EGL_NOT_INITIALIZED:
+                errortext   = "EGL_NOT_INITIALIZED.";
+                description = "EGL is not or could not be initialized, for the specified display.";
+                break;
+            case EGL_BAD_ACCESS:
+                errortext   = "EGL_BAD_ACCESS EGL";
+                description = "cannot access a requested resource (for example, a context is bound in another thread).";
+                break;
+            case EGL_BAD_ALLOC:
+                errortext   = "EGL_BAD_ALLOC EGL";
+                description = "failed to allocate resources for the requested operation.";
+                break;
+            case EGL_BAD_ATTRIBUTE:
+                errortext   = "EGL_BAD_ATTRIBUTE";
+                description = "An unrecognized attribute or attribute value was passed in anattribute list.";
+                break;
+            case EGL_BAD_CONFIG:
+                errortext   = "EGL_BAD_CONFIG";
+                description = "An EGLConfig argument does not name a valid EGLConfig.";
+                break;
+            case EGL_BAD_CONTEXT:
+                errortext   = "EGL_BAD_CONTEXT";
+                description = "An EGLContext argument does not name a valid EGLContext.";
+                break;
+            case EGL_BAD_CURRENT_SURFACE:
+                errortext   = "EGL_BAD_CURRENT_SURFACE";
+                description = "The current surface of the calling thread is a window, pbuffer,or pixmap that is no longer valid.";
+                break;
+            case EGL_BAD_DISPLAY:
+                errortext   = "EGL_BAD_DISPLAY";
+                description = "An EGLDisplay argument does not name a valid EGLDisplay.";
+                break;
+            case EGL_BAD_MATCH:
+                errortext   = "EGL_BAD_MATCH";
+                description = "Arguments are inconsistent; for example, an otherwise valid context requires buffers (e.g. depth or stencil) not allocated by an otherwise valid surface.";
+                break;
+            case EGL_BAD_NATIVE_PIXMAP:
+                errortext   = "EGL_BAD_NATIVE_PIXMAP";
+                description = "An EGLNativePixmapType argument does not refer to a validnative pixmap.";
+                break;
+            case EGL_BAD_NATIVE_WINDOW:
+                errortext   = "EGL_BAD_NATIVE_WINDOW";
+                description = "An EGLNativeWindowType argument does not refer to a validnative window.";
+                break;
+            case EGL_BAD_PARAMETER:
+                errortext   = "EGL_BAD_PARAMETER";
+                description = "One or more argument values are invalid.";
+                break;
+            case EGL_BAD_SURFACE:
+                errortext   = "EGL_BAD_SURFACE";
+                description = "An EGLSurface argument does not name a valid surface (window,pbuffer, or pixmap) configured for rendering";
+                break;
+            case EGL_CONTEXT_LOST:
+                errortext   = "EGL_CONTEXT_LOST";
+                description = "A power management event has occurred. The application mustdestroy all contexts and reinitialise client API state and objects to continue rendering.";
+                break;
+            default:
+                errortext   = "Unknown EGL Error";
+                description = "";
+                break;
+        }
+
+        printf( "EGLport ERROR: EGL Error detected in file %s at line %d: %s (0x%X)\n  Description: %s\n", file, line, errortext, error, description );
+        return 1;
+    }
+
+    return 0;
+}
+
+/** @brief Obtain a reference to the system's native display
+ * @param window : pointer to save the display reference
+ * @return : 0 if the function passed, else 1
+ */
+int8_t GetNativeDisplay( void )
+{
+    if (eglSettings[CFG_MODE] == RENDER_RAW)        /* RAW FB mode */
+    {
+        printf( "EGLport: Using EGL_DEFAULT_DISPLAY\n" );
+        nativeDisplay = EGL_DEFAULT_DISPLAY;
+    }
+    else if (eglSettings[CFG_MODE] == RENDER_SDL)   /* SDL/X11 mode */
+    {
+#if defined(USE_EGL_SDL)
+        printf( "EGLport: Opening SDL/X11 display\n" );
+        SDL_VERSION(&sysWmInfo.version);
+        SDL_GetWMInfo(&sysWmInfo);
+        nativeDisplay = (EGLNativeDisplayType)sysWmInfo.info.x11.display;
+
+        if (nativeDisplay == 0)
+        {
+            printf( "EGLport ERROR: unable to get display!\n" );
+            return 1;
+        }
+#else
+        printf( "EGLport ERROR: SDL mode was not enabled in this compile!\n" );
+#endif
+    }
+
+    return 0;
+}
+
+/** @brief Obtain a reference to the system's native window
+ * @param width : desired pixel width of the window (not used by all platforms)
+ * @param height : desired pixel height of the window (not used by all platforms)
+ * @return : 0 if the function passed, else 1
+ */
+int8_t GetNativeWindow( uint16_t width, uint16_t height )
+{
+    nativeWindow = 0;
+
+#if defined(WIZ) || defined(CAANOO)
+
+    nativeWindow = (NativeWindowType)malloc(16*1024);
+
+    if(nativeWindow == NULL) {
+        printf( "EGLport ERROR: Memory for window Failed\n" );
+        return 1;
+    }
+
+#elif defined(RPI)
+
+    EGLBoolean result;
+    uint32_t screen_width, screen_height;
+    static EGL_DISPMANX_WINDOW_T nativewindow;
+    DISPMANX_ELEMENT_HANDLE_T dispman_element;
+    DISPMANX_DISPLAY_HANDLE_T dispman_display;
+    DISPMANX_UPDATE_HANDLE_T dispman_update;
+    VC_RECT_T dst_rect;
+    VC_RECT_T src_rect;
+
+    /* create an EGL window surface */
+    result = graphics_get_display_size(0 /* LCD */, &screen_width, &screen_height);
+    if(result < 0) {
+        printf( "EGLport ERROR: RPi graphicget_display_size failed\n" );
+        return 1;
+    }
+
+    dst_rect.x = 0;
+    dst_rect.y = 0;
+    dst_rect.width = screen_width;
+    dst_rect.height = screen_height;
+
+    src_rect.x = 0;
+    src_rect.y = 0;
+    src_rect.width = width << 16;
+    src_rect.height = height << 16;
+
+    dispman_display = vc_dispmanx_display_open( 0 /* LCD */);
+    dispman_update  = vc_dispmanx_update_start( 0 );
+    dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display,
+      0 /*layer*/, &dst_rect, 0 /*src*/,
+      &src_rect, DISPMANX_PROTECTION_NONE,  (VC_DISPMANX_ALPHA_T*)0 /*alpha*/,  (DISPMANX_CLAMP_T*)0 /*clamp*/,  (DISPMANX_TRANSFORM_T)0 /*transform*/);
+
+    nativewindow.element = dispman_element;
+    nativewindow.width = screen_width;
+    nativewindow.height = screen_height;
+    vc_dispmanx_update_submit_sync( dispman_update );
+
+    nativeWindow = (NativeWindowType)&nativewindow;
+
+#else /* default */
+
+    if (eglSettings[CFG_MODE] == RENDER_RAW)        /* RAW FB mode */
+    {
+        nativeWindow = 0;
+    }
+    else if(eglSettings[CFG_MODE] == RENDER_SDL)    /* SDL/X11 mode */
+    {
+#if defined(USE_EGL_SDL)
+        /* SDL_GetWMInfo is populated when display was opened */
+        nativeWindow = (NativeWindowType)sysWmInfo.info.x11.window;
+
+        if (nativeWindow == 0)
+        {
+            printf( "EGLport ERROR: unable to get window!\n" );
+            return 1;
+        }
+#else
+        printf( "EGLport ERROR: SDL mode was not enabled in this compile!\n" );
+#endif
+    }
+    else
+    {
+        printf( "EGLport ERROR: Unknown EGL render mode %d!\n", eglSettings[CFG_MODE] );
+        return 1;
+    }
+
+#endif /* WIZ / CAANOO */
+
+    return 0;
+}
+
+/** @brief Release the system's native display
+ */
+void FreeNativeDisplay( void )
+{
+}
+
+/** @brief Release the system's native window
+ */
+void FreeNativeWindow( void )
+{
+#if defined(WIZ) || defined(CAANOO)
+    if (nativeWindow != NULL) {
+        free( nativeWindow );
+    }
+    nativeWindow = NULL;
+#endif /* WIZ / CAANOO */
+}
+
+/** @brief Open any system specific resources
+ */
+void Platform_Open( void )
+{
+#if defined(PANDORA)
+    /* Pandora VSync */
+    fbdev = open( "/dev/fb0", O_RDONLY /* O_RDWR */ );
+    if ( fbdev < 0 ) {
+        printf( "EGLport ERROR: Couldn't open /dev/fb0 for Pandora Vsync\n" );
+    }
+#elif defined(RPI)
+    bcm_host_init();
+#endif /* PANDORA */
+}
+
+/** @brief Release any system specific resources
+ */
+void Platform_Close( void )
+{
+#if defined(PANDORA)
+    /* Pandora VSync */
+    close( fbdev );
+    fbdev = -1;
+#endif /* PANDORA */
+}
+
+/** @brief Check the systems vsync state
+ */
+void Platform_VSync( void )
+{
+#if defined(PANDORA)
+    /* Pandora VSync */
+    if (fbdev >= 0) {
+        int arg = 0;
+        ioctl( fbdev, FBIO_WAITFORVSYNC, &arg );
+    }
+#endif /* PANDORA */
+}
+
+/** @brief Get the system tick time (ms)
+ */
+uint32_t Platform_GetTicks( void )
+{
+    uint32_t ticks = 0;
+#if defined(USE_EGL_SDL)
+    ticks = SDL_GetTicks();
+#else
+    printf( "EGLport ERROR: SDL mode was not enabled in this compile!\n" );
+#endif
+    return ticks;
+}
+
diff --git a/engines/sludge/eglport/eglport.h b/engines/sludge/eglport/eglport.h
new file mode 100644
index 0000000..20fb979
--- /dev/null
+++ b/engines/sludge/eglport/eglport.h
@@ -0,0 +1,109 @@
+/**
+ *
+ *  EGLPORT.H
+ *  Copyright (C) 2011-2013 Scott R. Smith
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to deal
+ *  in the Software without restriction, including without limitation the rights
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *  copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *  THE SOFTWARE.
+ *
+ */
+
+#ifndef EGLPORT_H
+#define EGLPORT_H
+
+#include <stdint.h>
+#include "EGL/egl.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Defines (in every case choose only one) */
+/**     Common: */
+/**         DEBUG : enable additional error monitoring per EGL function call */
+/**     Native display and window system for use with EGL */
+/**         USE_EGL_SDL : used for access to a SDL X11 window */
+/**     Platform: settings that are specific to that device */
+/**         PANDORA (USE_GLES1 or USE_GLES2) */
+/**         WIZ     (USE_GLES1) */
+/**         CAANOO  (USE_GLES1) */
+/**         RPI     (USE_GLES1 or USE_GLES2) */
+/**     GLES Version */
+/**         USE_GLES1 : EGL for use with OpenGL-ES 1.X contexts */
+/**         USE_GLES2 : EGL for use with OpenGL-ES 2.0 contexts */
+
+/** Public API */
+void    EGL_Init                    ( void );
+void    EGL_Close                   ( void );
+int8_t  EGL_Open                    ( /*uint16_t width, uint16_t height*/ );
+void    EGL_SwapBuffers             ( void );
+
+extern int8_t	eglColorbits;
+extern int8_t	eglDepthbits;
+extern int8_t	eglStencilbits;
+
+/** Simple Examples  */
+/**     Raw mode:
+            EGL_Open( window_width, window_height );
+            do while(!quit) {
+                ... run app
+                EGL_SwapBuffers();
+            }
+            EGL_Close();
+*/
+/**     X11/SDL mode:
+            SDL_Init( SDL_INIT_VIDEO );
+            SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_FULLSCREEN);
+            EGL_Open( window_width, window_height );
+            do while(!quit) {
+                ... run app
+                EGL_SwapBuffers();
+            }
+            EGL_Close();
+            SDL_Quit();
+*/
+
+#if defined(DEBUG)
+#define GET_EGLERROR(FUNCTION)               \
+    FUNCTION;                                \
+    {                                        \
+        CheckEGLErrors(__FILE__, __LINE__);  \
+    }
+#else
+#define GET_EGLERROR(FUNCTION) FUNCTION;
+#endif
+
+#define peglQueryString(A,B)                    GET_EGLERROR(eglQueryString(A,B))
+#define peglDestroyContext(A,B)                 GET_EGLERROR(eglDestroyContext(A,B))
+#define peglDestroySurface(A,B)                 GET_EGLERROR(eglDestroySurface(A,B))
+#define peglTerminate(A)                        GET_EGLERROR(eglTerminate(A))
+#define peglSwapBuffers(A,B)                    GET_EGLERROR(eglSwapBuffers(A,B))
+#define peglGetDisplay(A)                       GET_EGLERROR(eglGetDisplay(A))
+#define peglBindAPI(A)                          GET_EGLERROR(eglBindAPI(A))
+#define peglCreateContext(A,B,C,D)              GET_EGLERROR(eglCreateContext(A,B,C,D))
+#define peglCreateWindowSurface(A,B,C,D)        GET_EGLERROR(eglCreateWindowSurface(A,B,C,D))
+#define peglInitialize(A,B,C)                   GET_EGLERROR(eglInitialize(A,B,C))
+#define peglMakeCurrent(A,B,C,D)                GET_EGLERROR(eglMakeCurrent(A,B,C,D))
+#define peglChooseConfig(A,B,C,D,E)             GET_EGLERROR(eglChooseConfig(A,B,C,D,E))
+#define peglSwapInterval(A,B)                   GET_EGLERROR(eglSwapInterval(A,B))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* EGLPORT_H */
diff --git a/engines/sludge/errors.h b/engines/sludge/errors.h
new file mode 100644
index 0000000..0c4716c
--- /dev/null
+++ b/engines/sludge/errors.h
@@ -0,0 +1,72 @@
+/* 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.
+ *
+ */
+
+#ifndef SLUDGE_ERRRORS_H
+#define SLUDGE_ERRRORS_H
+
+#define _NO_MEMORY_GENERAL_         "\n\nTry closing down any programs you don't really need running (or freeing up a bit of disk space, which will give you more virtual memory - that should help too)."
+
+//---------------------------------------
+// Fatal errors
+//---------------------------------------
+
+#define ERROR_VERSION_TOO_LOW_1     "This SLUDGE file requires a more recent version of the SLUDGE engine"
+#define ERROR_VERSION_TOO_LOW_2     "(it was created for v%i.%i).\n\nVisit http://opensludge.github.io/ to download the most recent version."
+#define ERROR_VERSION_TOO_HIGH_1    "This SLUDGE file was created for an older version of the SLUDGE engine"
+#define ERROR_VERSION_TOO_HIGH_2    "(v%i.%i).\n\nPlease contact the author of this game to obtain a version compatible with your SLUDGE engine (v" TEXT_VERSION ")."
+#define ERROR_BAD_HEADER            "Bad header information... this isn't a valid SLUDGE game"
+#define ERROR_HACKER                "What have you been up to? Think we're a hacker, do we? Nice try."
+
+#define ERROR_GAME_LOAD_NO          "This isn't a SLUDGE saved game!\n"
+#define ERROR_GAME_LOAD_WRONG       "Can't load this saved game! It was either created by...\n\n  (a)  a different SLUDGE game to the one which you're playing, or...\n  (b)  a different (newer or older) version of the same game.\n\nFilename"
+#define ERROR_GAME_SAVE_FROZEN      "Can't save games while I'm frozen"
+#define ERROR_GAME_LOAD_CORRUPT     "This saved game appears to be corrupted"
+
+#define ERROR_NON_EMPTY_STACK       "Returning from function with non-empty stack"
+#define ERROR_UNKNOWN_MCODE         "Unknown SLUDGE machine code"
+#define ERROR_CALL_NONFUNCTION      "Call of non-function"
+#define ERROR_INCDEC_UNKNOWN        "Tried to increment/decrement index of an undefined variable"
+#define ERROR_INDEX_EMPTY           "Tried to index an empty stack"
+#define ERROR_INDEX_NONSTACK        "Tried to index a non-stack variable"
+#define ERROR_NOSTACK               "Corrupt file - no stack"
+#define ERROR_UNKNOWN_CODE          "Unimplemented internal SLUDGE command code."
+#define ERROR_OUT_OF_MEMORY         "Out of memory!" _NO_MEMORY_GENERAL_
+
+#define ERROR_MUSIC_MEMORY_LOW      "Your computer doesn't have enough memory available to load a music resource that needs playing." _NO_MEMORY_GENERAL_
+#define ERROR_SOUND_MEMORY_LOW      "Your computer doesn't have enough memory available to load a sound resource that needs playing." _NO_MEMORY_GENERAL_
+#define ERROR_MUSIC_UNKNOWN         "I can't understand a piece of music which I've been told to play!\n\n" \
+	"Maybe it's stored in a format that SLUDGE doesn't know about... " \
+	"make sure you've got a recent version of the SLUDGE engine from http://opensludge.github.io/. " \
+	"Failing that, maybe the resource in question isn't a valid music format at all... in which case, contact the game's author and tell them what's happened."
+#define ERROR_SOUND_UNKNOWN         "I can't understand a sample which I've been told to play!\nMake sure you've got the latest SLUDGE engine from http://opensludge.github.io/. Failing that, maybe the resource in question isn't a valid sound at all... in which case, contact the game's author and tell them what's happened."
+#define ERROR_MUSIC_ODDNESS         "I can't load a music resource I've been told to play. Sorry."
+#define ERROR_SOUND_ODDNESS         "I can't load a sound resource I've been told to play. Sorry."
+#define ERROR_MOVIE_ODDNESS         "I can't load a music resource I've been told to play. Sorry."
+
+//---------------------------------------
+// Startup warnings
+//---------------------------------------
+
+#define WARNING_BASS_WRONG_VERSION  "Incompatible version of BASS.DLL found!"
+#define WARNING_BASS_FAIL           "Can't initialise sound engine."
+
+#endif
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
new file mode 100644
index 0000000..8d5eb52
--- /dev/null
+++ b/engines/sludge/fileset.cpp
@@ -0,0 +1,237 @@
+/* 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.
+ *
+ */
+#if 0
+#include <errno.h>
+#include <stdint.h>
+#include <string.h>
+// For unicode conversion
+#include <iconv.h>
+#endif
+
+#include "debug.h"
+#include "stringy.h"
+
+#include "allfiles.h"
+#include "moreio.h"
+#include "newfatal.h"
+#include "CommonCode/version.h"
+
+
+bool sliceBusy = true;
+#if ALLOW_FILE
+FILE *bigDataFile = NULL;
+#endif
+uint32_t startOfDataIndex, startOfTextIndex,
+         startOfSubIndex, startOfObjectIndex;
+
+bool openSubSlice(int num) {
+//	FILE * dbug = fopen ("debuggy.txt", "at");
+
+//	fprintf (dbug, "\nTrying to open sub %i\n", num);
+
+	if (sliceBusy) {
+		fatal("Can't read from data file", "I'm already reading something");
+		return false;
+	}
+//	fprintf (dbug, "Going to position %li\n", startOfSubIndex + (num << 2));
+	fseek(bigDataFile, startOfSubIndex + (num << 2), 0);
+	fseek(bigDataFile, get4bytes(bigDataFile), 0);
+//	fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile));
+//	fclose (dbug);
+
+	return sliceBusy = true;
+}
+
+bool openObjectSlice(int num) {
+//	FILE * dbug = fopen ("debuggy.txt", "at");
+
+//	fprintf (dbug, "\nTrying to open object %i\n", num);
+
+	if (sliceBusy) {
+		fatal("Can't read from data file", "I'm already reading something");
+		return false;
+	}
+
+//	fprintf (dbug, "Going to position %li\n", startOfObjectIndex + (num << 2));
+	fseek(bigDataFile, startOfObjectIndex + (num << 2), 0);
+	fseek(bigDataFile, get4bytes(bigDataFile), 0);
+//	fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile));
+//	fclose (dbug);
+	return sliceBusy = true;
+}
+
+unsigned int openFileFromNum(int num) {
+//	FILE * dbug = fopen ("debuggy.txt", "at");
+
+	if (sliceBusy) {
+		fatal("Can't read from data file", "I'm already reading something");
+		return 0;
+	}
+
+//	fprintf (dbug, "\nTrying to open file %i\n", num);
+//	fprintf (dbug, "Jumping to %li (for index) \n", startOfDataIndex + (num << 2));
+	fseek(bigDataFile, startOfDataIndex + (num << 2), 0);
+	fseek(bigDataFile, get4bytes(bigDataFile), 1);
+//	fprintf (dbug, "Jumping to %li (for data) \n", ftell (bigDataFile));
+	sliceBusy = true;
+//	fclose (dbug);
+
+	return get4bytes(bigDataFile);
+}
+
+
+// Converts a string from Windows CP-1252 to UTF-8.
+// This is needed for old games.
+char *convertString(char *s) {
+	static char *buf = NULL;
+
+	if (! buf) {
+		buf = new char [65536];
+		if (! checkNew(buf)) return NULL;
+	}
+
+	char **tmp1 = (char **) &s;
+	char **tmp2 = (char **) &buf;
+	char *sOrig = s;
+	char *bufOrig = buf;
+#if defined __unix__ && !(defined __APPLE__)
+	iconv_t convert = iconv_open("UTF-8", "ISO8859-2");
+#else
+	iconv_t convert = iconv_open("UTF-8", "CP1250");
+#endif
+
+	if (convert == (iconv_t) - 1) {
+		switch (errno) {
+		case EINVAL:
+			fprintf(stderr, "Error: Encoding not supported by iconv.\n");
+			break;
+		default:
+			fprintf(stderr, "Error: Could not open iconv conversion descriptor.\n");
+		}
+	}
+
+	size_t len1 = strlen(s) + 1;
+	size_t len2 = 65535;
+	size_t iconv_value =
+#ifdef _WIN32
+	    iconv(convert, (const char **) tmp1, &len1, tmp2, &len2);
+#else
+	    iconv(convert, (char **) tmp1, &len1, tmp2, &len2);
+#endif
+
+	if (iconv_value == (size_t) - 1) {
+		switch (errno) {
+		/* See "man 3 iconv" for an explanation. */
+		case EILSEQ:
+			fprintf(stderr, "Invalid multibyte sequence.\n");
+			break;
+		case EINVAL:
+			fprintf(stderr, "Incomplete multibyte sequence.\n");
+			break;
+		case E2BIG:
+			fprintf(stderr, "No more room.\n");
+			break;
+		default:
+			fprintf(stderr, "Error: %s.\n", strerror(errno));
+		}
+		fatal("Conversion to Unicode failed. This can be fixed by recompiling the game in a current version of the SLUDGE Development Kit, but this error should never happen. Congratulations, you've found a bug in the SLUDGE engine! Please let us know about it.");
+	}
+	iconv_close(convert);
+
+
+	delete [] sOrig;
+	return copyString(buf = bufOrig);
+}
+
+char *getNumberedString(int value) {
+
+	if (sliceBusy) {
+		fatal("Can't read from data file", "I'm already reading something");
+		return NULL;
+	}
+
+	fseek(bigDataFile, (value << 2) + startOfTextIndex, 0);
+	value = get4bytes(bigDataFile);
+	fseek(bigDataFile, value, 0);
+
+	char *s = readString(bigDataFile);
+
+	if (gameVersion < VERSION(2, 2)) {
+		// This is an older game - We need to convert the string to UTF-8
+		s = convertString(s);
+	}
+
+	return s;
+}
+
+bool startAccess() {
+	int wasBusy = sliceBusy;
+	sliceBusy = true;
+	return wasBusy;
+}
+void finishAccess() {
+	sliceBusy = false;
+}
+
+int32_t startIndex;
+
+void setFileIndices(FILE *fp, int numLanguages, unsigned int skipBefore) {
+	if (fp) {
+		// Keep hold of the file handle, and let things get at it
+		bigDataFile = fp;
+		startIndex = ftell(fp);
+	} else {
+		// No file pointer - this means that we reuse the bigDataFile
+		fp = bigDataFile;
+		fseek(fp, startIndex, 0);
+	}
+	sliceBusy = false;
+
+	if (skipBefore > numLanguages) {
+		warning("Not a valid language ID! Using default instead.");
+		skipBefore = 0;
+	}
+
+	// STRINGS
+	int skipAfter = numLanguages - skipBefore;
+	while (skipBefore) {
+		fseek(fp, get4bytes(fp), 0);
+		skipBefore --;
+	}
+	startOfTextIndex = ftell(fp) + 4;
+
+	fseek(fp, get4bytes(fp), 0);
+
+	while (skipAfter) {
+		fseek(fp, get4bytes(fp), 0);
+		skipAfter --;
+	}
+
+	startOfSubIndex = ftell(fp) + 4;
+	fseek(fp, get4bytes(fp), 1);
+
+	startOfObjectIndex = ftell(fp) + 4;
+	fseek(fp, get4bytes(fp), 1);
+
+	// Remember that the data section starts here
+	startOfDataIndex = ftell(fp);
+}
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
new file mode 100644
index 0000000..39a6691
--- /dev/null
+++ b/engines/sludge/fileset.h
@@ -0,0 +1,39 @@
+/* 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.
+ *
+ */
+#ifndef SLUDGE_FILESET_H
+#define SLUDGE_FILESET_H
+
+#if ALLOW_FILE
+extern FILE *bigDataFile;
+
+void setFileIndices(FILE *fp, int, unsigned int);
+#endif
+
+unsigned int openFileFromNum(int num);
+bool openSubSlice(int num);
+bool openObjectSlice(int num);
+char *getNumberedString(int value);
+
+bool startAccess();
+void finishAccess();
+
+#endif
diff --git a/engines/sludge/fixScaleSprite.frag b/engines/sludge/fixScaleSprite.frag
new file mode 100644
index 0000000..ed9f6cf
--- /dev/null
+++ b/engines/sludge/fixScaleSprite.frag
@@ -0,0 +1,29 @@
+uniform sampler2D tex0;
+uniform sampler2D tex1;
+uniform sampler2D tex2;
+uniform bool useLightTexture;
+
+varying vec2 varCoord0;
+varying vec2 varCoord1;
+varying vec2 varCoord2;
+
+varying vec4 color;
+varying vec4 secondaryColor;
+
+void main()
+{
+	vec4 texture = texture2D (tex0, varCoord0);
+	vec4 texture2 = texture2D (tex2, varCoord2);
+	vec3 col;
+	if (useLightTexture) {
+		vec4 texture1 = texture2D (tex1, varCoord1);
+		col = texture1.rgb * texture.rgb;
+	} else {
+		col = color.rgb * texture.rgb;
+	}
+	col += vec3(secondaryColor);
+	vec4 color = vec4 (col, color.a * texture.a);
+	col = mix (texture2.rgb, color.rgb, color.a);
+	gl_FragColor = vec4 (col, max(texture.a, texture2.a));
+}
+
diff --git a/engines/sludge/fixScaleSprite.vert b/engines/sludge/fixScaleSprite.vert
new file mode 100644
index 0000000..d9f4e51
--- /dev/null
+++ b/engines/sludge/fixScaleSprite.vert
@@ -0,0 +1,25 @@
+attribute vec4 myVertex;
+attribute vec2 myUV0;
+attribute vec2 myUV1;
+attribute vec2 myUV2;
+
+uniform mat4 myPMVMatrix;
+uniform vec4 myColor;
+uniform vec4 mySecondaryColor;
+
+varying vec2 varCoord0;
+varying vec2 varCoord1;
+varying vec2 varCoord2;
+
+varying vec4 color;
+varying vec4 secondaryColor;
+
+void main() {
+	varCoord0 = myUV0.st;
+	varCoord1 = myUV1.st;
+	varCoord2 = myUV2.st;
+	gl_Position = myPMVMatrix * myVertex;
+
+	color = myColor;
+	secondaryColor = mySecondaryColor;
+}
diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp
new file mode 100644
index 0000000..826632a
--- /dev/null
+++ b/engines/sludge/floor.cpp
@@ -0,0 +1,290 @@
+/* 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 "allfiles.h"
+#include "newfatal.h"
+#include "fileset.h"
+#include "moreio.h"
+#include "floor.h"
+#include "line.h"
+
+flor *currentFloor = NULL;
+
+bool pointInFloorPolygon(floorPolygon &floorPoly, int x, int y) {
+	int i = 0, j, c = 0;
+	float xp_i, yp_i;
+	float xp_j, yp_j;
+
+	for (j = floorPoly.numVertices - 1; i < floorPoly.numVertices;
+	        j = i ++) {
+
+		xp_i = currentFloor -> vertex[floorPoly.vertexID[i]].x;
+		yp_i = currentFloor -> vertex[floorPoly.vertexID[i]].y;
+		xp_j = currentFloor -> vertex[floorPoly.vertexID[j]].x;
+		yp_j = currentFloor -> vertex[floorPoly.vertexID[j]].y;
+
+		if ((((yp_i <= y) && (y < yp_j)) ||
+		        ((yp_j <= y) && (y < yp_i))) &&
+		        (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) {
+
+			c = !c;
+		}
+	}
+	return c;
+}
+
+bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA, int &cornerB) {
+	int sharedVertices = 0;
+	int i, j;
+
+	for (i = 0; i < a.numVertices; i ++) {
+		for (j = 0; j < b.numVertices; j ++) {
+			if (a.vertexID[i] == b.vertexID[j]) {
+				if (sharedVertices ++) {
+					cornerB = a.vertexID[i];
+					return true;
+				} else {
+					cornerA = a.vertexID[i];
+				}
+			}
+		}
+	}
+
+	return false;
+}
+
+bool polysShareSide(floorPolygon &a, floorPolygon &b) {
+	int sharedVertices = 0;
+	int i, j;
+
+	for (i = 0; i < a.numVertices; i ++) {
+		for (j = 0; j < b.numVertices; j ++) {
+			if (a.vertexID[i] == b.vertexID[j]) {
+				if (sharedVertices ++) return true;
+			}
+		}
+	}
+
+	return false;
+}
+
+void noFloor() {
+	currentFloor -> numPolygons = 0;
+	currentFloor -> polygon = NULL;
+	currentFloor -> vertex = NULL;
+	currentFloor -> matrix = NULL;
+}
+
+bool initFloor() {
+	currentFloor = new flor;
+	if (! checkNew(currentFloor)) return false;
+	noFloor();
+	return true;
+}
+
+void killFloor() {
+	for (int i = 0; i < currentFloor -> numPolygons; i ++) {
+		delete currentFloor -> polygon[i].vertexID;
+		delete currentFloor -> matrix[i];
+	}
+	delete currentFloor -> polygon;
+	currentFloor -> polygon = NULL;
+	delete currentFloor -> vertex;
+	currentFloor -> vertex = NULL;
+	delete currentFloor -> matrix;
+	currentFloor -> matrix = NULL;
+}
+
+void setFloorNull() {
+	killFloor();
+	noFloor();
+}
+
+bool setFloor(int fileNum) {
+
+	int i, j;
+
+	killFloor();
+
+	setResourceForFatal(fileNum);
+#if ALLOW_FILE
+	if (! openFileFromNum(fileNum)) return false;
+
+	// Find out how many polygons there are and reserve memory
+
+	currentFloor -> originalNum = fileNum;
+	currentFloor -> numPolygons = fgetc(bigDataFile);
+	currentFloor -> polygon = new floorPolygon[currentFloor -> numPolygons];
+	if (! checkNew(currentFloor -> polygon)) return false;
+
+	// Read in each polygon
+
+	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+
+		// Find out how many vertex IDs there are and reserve memory
+
+		currentFloor -> polygon[i].numVertices = fgetc(bigDataFile);
+		currentFloor -> polygon[i].vertexID = new int[currentFloor -> polygon[i].numVertices];
+		if (! checkNew(currentFloor -> polygon[i].vertexID)) return false;
+
+		// Read in each vertex ID
+
+		for (j = 0; j < currentFloor -> polygon[i].numVertices; j ++) {
+			currentFloor -> polygon[i].vertexID[j] = get2bytes(bigDataFile);
+		}
+	}
+
+	// Find out how many vertices there are and reserve memory
+
+	i = get2bytes(bigDataFile);
+	currentFloor -> vertex = new POINT[i];
+	if (! checkNew(currentFloor -> vertex)) return false;
+
+	for (j = 0; j < i; j ++) {
+
+		currentFloor -> vertex[j].x = get2bytes(bigDataFile);
+		currentFloor -> vertex[j].y = get2bytes(bigDataFile);
+	}
+
+	finishAccess();
+#endif
+	// Now build the movement martix
+
+	currentFloor -> matrix = new int *[currentFloor -> numPolygons];
+	int * * distanceMatrix = new int *[currentFloor -> numPolygons];
+
+	if (! checkNew(currentFloor -> matrix)) return false;
+
+	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+		currentFloor -> matrix[i] = new int [currentFloor -> numPolygons];
+		distanceMatrix        [i] = new int [currentFloor -> numPolygons];
+		if (! checkNew(currentFloor -> matrix[i])) return false;
+		for (j = 0; j < currentFloor -> numPolygons; j ++) {
+			currentFloor -> matrix[i][j] = -1;
+			distanceMatrix        [i][j] = 10000;
+		}
+	}
+
+	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+		for (j = 0; j < currentFloor -> numPolygons; j ++) {
+			if (i != j) {
+				if (polysShareSide(currentFloor -> polygon[i], currentFloor -> polygon[j])) {
+					currentFloor -> matrix[i][j] = j;
+					distanceMatrix        [i][j] = 1;
+				}
+			} else {
+				currentFloor -> matrix[i][j] = -2;
+				distanceMatrix        [i][j] = 0;
+			}
+		}
+	}
+
+	bool madeChange;
+	int lookForDistance = 0;
+
+	do {
+		lookForDistance ++;
+//		debugMatrix ();
+		madeChange = false;
+		for (i = 0; i < currentFloor -> numPolygons; i ++) {
+			for (j = 0; j < currentFloor -> numPolygons; j ++) {
+				if (currentFloor -> matrix[i][j] == -1) {
+
+					// OK, so we don't know how to get from i to j...
+					for (int d = 0; d < currentFloor -> numPolygons; d ++) {
+						if (d != i && d != j) {
+							if (currentFloor -> matrix[i][d] == d &&
+							        currentFloor -> matrix[d][j] >= 0 &&
+							        distanceMatrix        [d][j] <= lookForDistance) {
+
+								currentFloor -> matrix[i][j] = d;
+								distanceMatrix       [i][j] = lookForDistance + 1;
+								madeChange = true;
+							}
+						}
+					}
+				}
+			}
+		}
+	} while (madeChange);
+
+	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+		delete distanceMatrix [i];
+	}
+
+	delete distanceMatrix;
+	distanceMatrix = NULL;
+
+	setResourceForFatal(-1);
+
+	return true;
+}
+
+void drawFloor() {
+	int i, j, nV;
+	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+//		drawLine (i, 0, i + 5, 100);
+		nV = currentFloor -> polygon[i].numVertices;
+		if (nV > 1) {
+			for (j = 1; j < nV; j ++) {
+				drawLine(currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j - 1]].x,
+				         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j - 1]].y,
+				         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j]].x,
+				         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j]].y);
+			}
+			drawLine(currentFloor -> vertex[currentFloor -> polygon[i].vertexID[0]].x,
+			         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[0]].y,
+			         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[nV - 1]].x,
+			         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[nV - 1]].y);
+		}
+	}
+}
+
+int inFloor(int x, int y) {
+	int i, r = -1;
+
+	for (i = 0; i < currentFloor -> numPolygons; i ++)
+		if (pointInFloorPolygon(currentFloor -> polygon[i], x, y))
+			r = i;
+
+	return r;
+}
+
+bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP) {
+	int xDiff = x2 - x1;
+	int yDiff = y2 - y1;
+
+	double m = xDiff * (xP - x1) + yDiff * (yP - y1);
+	m /= (xDiff * xDiff) + (yDiff * yDiff);
+
+	if (m < 0) {
+		closestX = x1;
+		closestY = y1;
+	} else if (m > 1) {
+		closestX = x2;
+		closestY = y2;
+	} else {
+		closestX = x1 + m * xDiff;
+		closestY = y1 + m * yDiff;
+		return true;
+	}
+	return false;
+}
diff --git a/engines/sludge/floor.h b/engines/sludge/floor.h
new file mode 100644
index 0000000..5c0d050
--- /dev/null
+++ b/engines/sludge/floor.h
@@ -0,0 +1,57 @@
+/* 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.
+ *
+ */
+#ifndef SLUDGE_FLOOR_H
+#define SLUDGE_FLOOR_H
+
+#ifdef _WIN32
+#include "windef.h"
+#endif
+
+struct floorPolygon {
+	int numVertices;
+	int *vertexID;
+};
+
+#ifndef _WIN32
+struct POINT {
+	int x;
+	int y;
+};
+#endif
+
+struct flor {
+	int originalNum;
+	POINT *vertex;
+	int numPolygons;
+	floorPolygon *polygon;
+	int * *matrix;
+};
+
+bool initFloor();
+void setFloorNull();
+bool setFloor(int fileNum);
+void drawFloor();
+int inFloor(int x, int y);
+bool getMatchingCorners(floorPolygon &, floorPolygon &, int &, int &);
+bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP);
+
+#endif
diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
new file mode 100644
index 0000000..835c2a6
--- /dev/null
+++ b/engines/sludge/fonttext.cpp
@@ -0,0 +1,206 @@
+/* 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 "platform-dependent.h"
+
+#include <stdint.h>
+#include <string.h>
+
+#include "CommonCode/utf8.h"
+
+#include "debug.h"
+#include "allfiles.h"
+#include "stringy.h"
+
+#include "sprites.h"
+#include "colours.h"
+#include "fonttext.h"
+#include "newfatal.h"
+#include "moreio.h"
+
+spriteBank theFont;
+int fontHeight = 0, numFontColours, loadedFontNum;
+char *fontOrderString = NULL;
+short fontSpace = -1;
+
+uint32_t *fontTable = NULL;
+unsigned int fontTableSize = 0;
+
+#define fontInTable(x) ((x<fontTableSize) ? fontTable[(uint32_t) x] : 0)
+
+extern float cameraZoom;
+
+bool isInFont(char *theText) {
+	if (! fontTableSize) return 0;
+	if (! theText[0]) return 0;
+
+	// We don't want to compare strings. Only single characters allowed!
+	if (u8_strlen(theText) > 1) return false;
+
+	int i = 0;
+	uint32_t c = u8_nextchar(theText, &i);
+
+	return u8_strchr(fontOrderString, c, &i);
+}
+
+int stringLength(char *theText) {
+	return u8_strlen(theText);
+}
+
+int stringWidth(char *theText) {
+	int a = 0;
+	uint32_t c;
+	int xOff = 0;
+
+	if (! fontTableSize) return 0;
+
+	while (theText[a]) {
+		c = u8_nextchar(theText, &a);
+		xOff += theFont.sprites[fontInTable(c)].width + fontSpace;
+	}
+
+	return xOff;
+}
+
+void pasteString(char *theText, int xOff, int y, spritePalette &thePal) {
+	sprite *mySprite;
+	int a = 0;
+	uint32_t c;
+
+	if (! fontTableSize) return;
+
+	xOff += (int)((float)(fontSpace >> 1) / cameraZoom);
+	while (theText[a]) {
+		c = u8_nextchar(theText, &a);
+		mySprite = & theFont.sprites[fontInTable(c)];
+		fontSprite(xOff, y, * mySprite, thePal);
+		xOff += (int)((double)(mySprite -> width + fontSpace) / cameraZoom);
+	}
+}
+
+void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
+	sprite *mySprite;
+	int a = 0;
+	uint32_t c;
+
+	if (! fontTableSize) return;
+
+	xOff += fontSpace >> 1;
+	while (theText[a]) {
+		c = u8_nextchar(theText, &a);
+		mySprite = & theFont.sprites[fontInTable(c)];
+		pasteSpriteToBackDrop(xOff, y, * mySprite, thePal);
+		xOff += mySprite -> width + fontSpace;
+	}
+}
+
+void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
+	sprite *mySprite;
+	int a = 0;
+	uint32_t c;
+
+	if (! fontTableSize) return;
+
+	xOff += fontSpace >> 1;
+	while (theText[a]) {
+		c = u8_nextchar(theText, &a);
+		mySprite = & theFont.sprites[fontInTable(c)];
+		burnSpriteToBackDrop(xOff, y, * mySprite, thePal);
+		xOff += mySprite -> width + fontSpace;
+	}
+}
+
+void fixFont(spritePalette &spal) {
+#if 0
+	delete [] spal.tex_names;
+	delete [] spal.burnTex_names;
+	delete [] spal.tex_h;
+	delete [] spal.tex_w;
+
+	spal.numTextures = theFont.myPalette.numTextures;
+
+	spal.tex_names = new GLuint [spal.numTextures];
+	if (! checkNew(spal.tex_names)) return;
+	spal.burnTex_names = new GLuint [spal.numTextures];
+	if (! checkNew(spal.burnTex_names)) return;
+	spal.tex_w = new int [spal.numTextures];
+	if (! checkNew(spal.tex_w)) return;
+	spal.tex_h = new int [spal.numTextures];
+	if (! checkNew(spal.tex_h)) return;
+
+	for (int i = 0; i < theFont.myPalette.numTextures; i++) {
+		spal.tex_names[i] = theFont.myPalette.tex_names[i];
+		spal.burnTex_names[i] = theFont.myPalette.burnTex_names[i];
+		spal.tex_w[i] = theFont.myPalette.tex_w[i];
+		spal.tex_h[i] = theFont.myPalette.tex_h[i];
+	}
+#endif
+}
+
+void setFontColour(spritePalette &sP, byte r, byte g, byte b) {
+	sP.originalRed = r;
+	sP.originalGreen = g;
+	sP.originalBlue = b;
+}
+
+bool loadFont(int filenum, const char *charOrder, int h) {
+	int a = 0;
+	uint32_t c;
+
+	delete [] fontOrderString;
+	fontOrderString = copyString(charOrder);
+
+	forgetSpriteBank(theFont);
+
+	loadedFontNum = filenum;
+
+
+	fontTableSize = 0;
+	while (charOrder[a]) {
+		c = u8_nextchar(charOrder, &a);
+		if (c > fontTableSize) fontTableSize = c;
+	}
+	fontTableSize++;
+
+	delete [] fontTable;
+	fontTable = new uint32_t [fontTableSize];
+	if (! checkNew(fontTable)) return false;
+
+	for (a = 0; a < fontTableSize; a ++) {
+		fontTable[a] = 0;
+	}
+	a = 0;
+	int i = 0;
+	while (charOrder[a]) {
+		c = u8_nextchar(charOrder, &a);
+		fontTable[c] = i;
+		i++;
+	}
+
+	if (! loadSpriteBank(filenum, theFont, true)) {
+		fatal("Can't load font");
+		return false;
+	}
+
+	numFontColours = theFont.myPalette.total;
+	fontHeight = h;
+	return true;
+}
diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h
new file mode 100644
index 0000000..f33876f
--- /dev/null
+++ b/engines/sludge/fonttext.h
@@ -0,0 +1,35 @@
+/* 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.
+ *
+ */
+#ifndef SLUDGE_FONTTEXT_H
+#define SLUDGE_FONTTEXT_H
+
+bool loadFont(int filenum, const char *charOrder, int);
+void pasteString(char *theText, int, int, spritePalette &);
+void fixFont(spritePalette &spal);
+void setFontColour(spritePalette &sP, byte r, byte g, byte b);
+int stringWidth(char *theText);
+int stringLength(char *theText);
+void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal);
+void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal);
+bool isInFont(char *theText);
+
+#endif
diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp
new file mode 100644
index 0000000..f245ad0
--- /dev/null
+++ b/engines/sludge/freeze.cpp
@@ -0,0 +1,364 @@
+/* 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 "allfiles.h"
+#include "debug.h"
+#include "graphics.h"
+#include "newfatal.h"
+#include "sprites.h"
+#include "sprbanks.h"
+#include "people.h"
+#include "sludger.h"
+#include "objtypes.h"
+#include "region.h"
+#include "backdrop.h"
+#include "talk.h"
+#include "fonttext.h"
+#include "statusba.h"
+#include "freeze.h"
+#include "zbuffer.h"
+
+extern onScreenPerson *allPeople;
+extern screenRegion *allScreenRegions;
+extern screenRegion *overRegion;
+extern speechStruct *speech;
+extern inputType input;
+#if 0
+extern GLuint backdropTextureName;
+#endif
+extern parallaxLayer *parallaxStuff;
+extern int lightMapNumber, zBufferNumber;
+extern eventHandlers *currentEvents;
+extern personaAnimation *mouseCursorAnim;
+extern int mouseCursorFrameNum;
+extern int cameraX, cameraY;
+extern unsigned int sceneWidth, sceneHeight;
+extern float cameraZoom;
+extern zBufferData zBuffer;
+extern bool backdropExists;
+frozenStuffStruct *frozenStuff = NULL;
+extern unsigned int sceneWidth, sceneHeight;
+
+void shufflePeople();
+#if 0
+GLuint freezeTextureName = 0;
+#endif
+
+void freezeGraphics() {
+#if 0
+	glViewport(0, 0, realWinWidth, realWinHeight);
+
+	glGenTextures(1, &freezeTextureName);
+#endif
+	int w = winWidth;
+	int h = winHeight;
+	if (! NPOT_textures) {
+		w = getNextPOT(winWidth);
+		h = getNextPOT(winHeight);
+	}
+#if 0
+	glBindTexture(GL_TEXTURE_2D, freezeTextureName);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, freezeTextureName);
+#endif
+	// Temporarily disable AA
+	int antiAlias = gameSettings.antiAlias;
+	gameSettings.antiAlias = 0;
+
+
+	int x = 0;
+	while (x < winWidth) {
+		int y = 0;
+
+		if (winWidth - x < realWinWidth) {
+			w = winWidth - x;
+		} else {
+			w = realWinWidth;
+		}
+
+		while (y < winHeight) {
+
+			if (winHeight - y < realWinHeight) {
+				h = winHeight - y;
+			} else {
+				h = realWinHeight;
+			}
+#if 0
+			const GLfloat bPMVMatrix[] = {
+				2.0f / realWinWidth * cameraZoom,                            .0,   .0,  .0,
+				.0, 2.0f / realWinHeight * cameraZoom,   .0,  .0,
+				.0,                            .0, 1.0f,  .0,
+				-2.0f * (x / realWinWidth) - 1.0f,  -2.0f * (y / realWinHeight) - 1.0f,   .0, 1.0f
+
+			};
+			for (int i = 0; i < 16; i++) {
+				aPMVMatrix[i] = bPMVMatrix[i];
+			}
+			// Render scene
+			glDepthMask(GL_TRUE);
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen
+			glDepthMask(GL_FALSE);
+
+			drawBackDrop();                 // Draw the room
+			drawZBuffer(cameraX, cameraY, false);
+
+			glEnable(GL_DEPTH_TEST);
+
+			drawPeople();                   // Then add any moving characters...
+
+			glDisable(GL_DEPTH_TEST);
+
+
+			// Copy Our ViewPort To The Texture
+			copyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, w, h, freezeTextureName);
+#endif
+			y += h;
+		}
+		x += w;
+	}
+
+	gameSettings.antiAlias = antiAlias;
+
+#if 0
+	glViewport(viewportOffsetX, viewportOffsetY, viewportWidth, viewportHeight);
+	setPixelCoords(false);
+#endif
+}
+
+bool freeze() {
+	debugOut("calling freeze()\n");
+	frozenStuffStruct *newFreezer = new frozenStuffStruct;
+	if (! checkNew(newFreezer)) return false;
+
+	// Grab a copy of the current scene
+	freezeGraphics();
+#if 0
+	newFreezer -> backdropTextureName = backdropTextureName;
+#endif
+	int picWidth = sceneWidth;
+	int picHeight = sceneHeight;
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(picWidth);
+		picHeight = getNextPOT(picHeight);
+	}
+#if 0
+	newFreezer -> backdropTexture = new GLubyte [picHeight * picWidth * 4];
+	if (! checkNew(newFreezer -> backdropTexture)) return false;
+
+	saveTexture(backdropTextureName, newFreezer->backdropTexture);
+
+	backdropTextureName = 0;
+#endif
+	newFreezer -> sceneWidth = sceneWidth;
+	newFreezer -> sceneHeight = sceneHeight;
+	newFreezer -> cameraX = cameraX;
+	newFreezer -> cameraY = cameraY;
+	newFreezer -> cameraZoom = cameraZoom;
+#if 0
+	newFreezer -> lightMapTexture = lightMap.data;
+	newFreezer -> lightMapTextureName = lightMap.name;
+	newFreezer -> lightMapNumber = lightMapNumber;
+	lightMap.data = NULL;
+	lightMap.name = 0;
+	newFreezer -> parallaxStuff = parallaxStuff;
+	parallaxStuff = NULL;
+	newFreezer -> zBufferImage = zBuffer.tex;
+	newFreezer -> zBufferNumber = zBuffer.originalNum;
+	newFreezer -> zPanels = zBuffer.numPanels;
+	zBuffer.tex = NULL;
+#endif
+	// resizeBackdrop kills parallax stuff, light map, z-buffer...
+	if (! resizeBackdrop(winWidth, winHeight)) return fatal("Can't create new temporary backdrop buffer");
+
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(sceneWidth);
+		picHeight = getNextPOT(sceneHeight);
+#if 0
+		backdropTexW = (double) sceneWidth / picWidth;
+		backdropTexH = (double) sceneHeight / picHeight;
+#endif
+	}
+
+#if 0
+	// Copy the old scene to the new backdrop
+	deleteTextures(1, &backdropTextureName);
+	backdropTextureName = freezeTextureName;
+	backdropExists = true;
+
+	// Free texture memory used by old stuff
+	parallaxStuff = newFreezer -> parallaxStuff;
+	while (parallaxStuff) {
+		deleteTextures(1, &parallaxStuff -> textureName);
+		parallaxStuff = parallaxStuff -> next;
+	}
+	if (newFreezer -> zBufferImage) {
+		deleteTextures(1, &zBuffer.texName);
+	}
+	if (newFreezer -> lightMapTextureName) {
+		deleteTextures(1, &newFreezer -> lightMapTextureName);
+	}
+	if (newFreezer -> backdropTextureName) {
+		deleteTextures(1, &newFreezer -> backdropTextureName);
+	}
+#endif
+	newFreezer -> allPeople = allPeople;
+	allPeople = NULL;
+
+	statusStuff *newStatusStuff = new statusStuff;
+	if (! checkNew(newStatusStuff)) return false;
+	newFreezer -> frozenStatus = copyStatusBarStuff(newStatusStuff);
+
+	newFreezer -> allScreenRegions = allScreenRegions;
+	allScreenRegions = NULL;
+	overRegion = NULL;
+
+	newFreezer -> mouseCursorAnim = mouseCursorAnim;
+	newFreezer -> mouseCursorFrameNum = mouseCursorFrameNum;
+	mouseCursorAnim = makeNullAnim();
+	mouseCursorFrameNum = 0;
+
+	newFreezer -> speech = speech;
+	initSpeech();
+
+	newFreezer -> currentEvents = currentEvents;
+	currentEvents = new eventHandlers;
+	if (! checkNew(currentEvents)) return false;
+	memset(currentEvents, 0, sizeof(eventHandlers));
+
+	newFreezer -> next = frozenStuff;
+	frozenStuff = newFreezer;
+
+	return true;
+}
+
+int howFrozen() {
+	int a = 0;
+	frozenStuffStruct *f = frozenStuff;
+	while (f) {
+		a ++;
+		f = f -> next;
+	}
+	return a;
+}
+
+#if 0
+extern GLubyte *backdropTexture;
+#endif
+
+void unfreeze(bool killImage) {
+	frozenStuffStruct *killMe = frozenStuff;
+
+	if (! frozenStuff) return;
+
+	sceneWidth = frozenStuff -> sceneWidth;
+	sceneHeight = frozenStuff -> sceneHeight;
+
+	cameraX = frozenStuff -> cameraX;
+	cameraY = frozenStuff -> cameraY;
+	input.mouseX = (int)(input.mouseX * cameraZoom);
+	input.mouseY = (int)(input.mouseY * cameraZoom);
+	cameraZoom = frozenStuff -> cameraZoom;
+	input.mouseX = (int)(input.mouseX / cameraZoom);
+	input.mouseY = (int)(input.mouseY / cameraZoom);
+	setPixelCoords(false);
+
+	killAllPeople();
+	allPeople = frozenStuff -> allPeople;
+
+	killAllRegions();
+	allScreenRegions = frozenStuff -> allScreenRegions;
+
+	killLightMap();
+#if 0
+	lightMap.data = frozenStuff -> lightMapTexture;
+	lightMap.name = frozenStuff -> lightMapTextureName;
+	lightMapNumber = frozenStuff -> lightMapNumber;
+	if (lightMapNumber) {
+		lightMap.name = 0;
+		loadLightMap(lightMapNumber);
+	}
+
+	killZBuffer();
+	zBuffer.tex = frozenStuff -> zBufferImage;
+	zBuffer.originalNum = frozenStuff -> zBufferNumber;
+	zBuffer.numPanels = frozenStuff -> zPanels;
+	if (zBuffer.numPanels) {
+		zBuffer.texName = 0;
+		setZBuffer(zBuffer.originalNum);
+	}
+
+	killParallax();
+	parallaxStuff = frozenStuff -> parallaxStuff;
+	reloadParallaxTextures();
+
+	if (killImage) killBackDrop();
+	backdropTextureName = frozenStuff -> backdropTextureName;
+	if (backdropTexture) delete[] backdropTexture;
+	backdropTexture = frozenStuff -> backdropTexture;
+	backdropExists = true;
+	if (backdropTextureName) {
+		backdropTextureName = 0;
+		glGenTextures(1, &backdropTextureName);
+		glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+		if (gameSettings.antiAlias < 0) {
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		} else {
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		}
+
+		int picWidth = sceneWidth;
+		int picHeight = sceneHeight;
+		if (! NPOT_textures) {
+			picWidth = getNextPOT(picWidth);
+			picHeight = getNextPOT(picHeight);
+		}
+		// Restore the backdrop
+		texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frozenStuff -> backdropTexture, backdropTextureName);
+	}
+#endif
+	deleteAnim(mouseCursorAnim);
+	mouseCursorAnim = frozenStuff -> mouseCursorAnim;
+	mouseCursorFrameNum = frozenStuff -> mouseCursorFrameNum;
+
+	restoreBarStuff(frozenStuff -> frozenStatus);
+
+	delete currentEvents;
+	currentEvents = frozenStuff -> currentEvents;
+	killAllSpeech();
+	delete speech;
+
+	speech = frozenStuff -> speech;
+	frozenStuff = frozenStuff -> next;
+
+	overRegion = NULL;
+	delete killMe;
+	killMe = NULL;
+
+}
diff --git a/engines/sludge/freeze.h b/engines/sludge/freeze.h
new file mode 100644
index 0000000..1682d3b
--- /dev/null
+++ b/engines/sludge/freeze.h
@@ -0,0 +1,55 @@
+/* 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.
+ *
+ */
+#ifndef SLUDGE_FREEZE_H
+#define SLUDGE_FREEZE_H
+
+
+struct frozenStuffStruct {
+	onScreenPerson *allPeople;
+	screenRegion *allScreenRegions;
+#if 0
+	GLubyte *backdropTexture;
+	GLuint backdropTextureName;
+	GLuint lightMapTextureName;
+	GLubyte *lightMapTexture;
+	GLubyte *zBufferImage;
+#endif
+	int zPanels;
+	parallaxLayer *parallaxStuff;
+	int lightMapNumber, zBufferNumber;
+	speechStruct *speech;
+	statusStuff *frozenStatus;
+	eventHandlers *currentEvents;
+	personaAnimation *mouseCursorAnim;
+	int mouseCursorFrameNum;
+	int cameraX, cameraY, sceneWidth, sceneHeight;
+	float cameraZoom;
+
+	frozenStuffStruct *next;
+};
+
+
+bool freeze();
+void unfreeze(bool killImage = true);
+int howFrozen();
+
+#endif
diff --git a/engines/sludge/graphics.cpp b/engines/sludge/graphics.cpp
new file mode 100644
index 0000000..8bdc917
--- /dev/null
+++ b/engines/sludge/graphics.cpp
@@ -0,0 +1,956 @@
+/* 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.
+ *
+ */
+#if 0
+#include <stdarg.h>
+
+#include <SDL/SDL.h>
+#endif
+
+#include "allfiles.h"
+#include "debug.h"
+#include "platform-dependent.h"
+#include "CommonCode/specialsettings.h"
+#include "graphics.h"
+#include "language.h"
+#include "newfatal.h"
+#include "sprbanks.h"
+#include "zbuffer.h"
+#include "backdrop.h"
+#include "shaders.h"
+#include "movie.h"
+#include "stringy.h"
+
+#include "language.h" // for settings
+
+#if 0
+#if !defined(HAVE_GLES2)
+#ifdef _WIN32
+#include <GL\glu.h> // handy for gluErrorString
+#elif defined __APPLE__
+#include <OpenGL/glu.h>
+#else
+#include <GL/glu.h>
+#endif
+#endif
+#endif
+
+unsigned int winWidth, winHeight;
+int viewportHeight, viewportWidth;
+int viewportOffsetX = 0, viewportOffsetY = 0;
+
+extern float cameraZoom;
+
+bool NPOT_textures = true;
+
+extern int specialSettings;
+
+void setMovieViewport();
+
+#if 0
+extern GLuint backdropTextureName;
+extern GLuint snapshotTextureName;
+#endif
+
+extern unsigned int sceneWidth, sceneHeight;
+extern zBufferData zBuffer;
+extern int lightMapNumber;
+#if 0
+extern GLuint yTextureName;
+extern GLuint uTextureName;
+extern GLuint vTextureName;
+//extern GLubyte * ytex, * utex, * vtex;
+
+shaders shader;
+GLfloat aPMVMatrix[16];
+
+void sludgeDisplay();
+
+GLfloat primaryColor[4];
+GLfloat secondaryColor[4];
+#endif
+
+struct textureList *firstTexture = NULL;
+
+textureList *addTexture() {
+	textureList *newTexture = new textureList;
+	newTexture -> next = firstTexture;
+	firstTexture = newTexture;
+	return newTexture;
+}
+
+#if 0
+void deleteTextures(GLsizei n,  const GLuint *textures) {
+	if (firstTexture == NULL) {
+		//debugOut("Deleting texture while list is already empty.\n");
+	} else {
+		for (int i = 0; i < n; i++) {
+			bool found = false;
+			textureList *list = firstTexture;
+			if (list->name == textures[i]) {
+				found = true;
+				firstTexture = list->next;
+				delete list;
+				continue;
+			}
+
+			while (list->next) {
+				if (list->next->name == textures[i]) {
+					found = true;
+					textureList *deleteMe = list->next;
+					list->next = list->next->next;
+					delete deleteMe;
+					break;
+				}
+				list = list->next;
+			}
+			//if (!found)
+			//  debugOut("Deleting texture that was not in list.\n");
+		}
+	}
+
+	glDeleteTextures(n, textures);
+
+}
+
+void getTextureDimensions(GLuint name, GLint *width,  GLint *height) {
+	textureList *list = firstTexture;
+	while (list) {
+		if (list->name == name)  {
+			*width = list->width;
+			*height = list->height;
+#if !defined(HAVE_GLES2)
+			//For the following test it is assumed that glBindTexture is always
+			//called for the right texture before getTextureDimensions.
+			GLint tw, th;
+			glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tw);
+			glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &th);
+			if (tw != *width || th != *height) {
+				debugOut("Warning: Texture dimensions don't match: They are %ix%i, but SLUDGEs bookkeeping says %ix%i.\n", tw, th, *width, *height);
+			}
+#endif
+			return;
+		}
+		list = list->next;
+	}
+	fatal("Texture not found in list.\n");
+}
+
+void storeTextureDimensions(GLuint name, GLsizei width,  GLsizei height, const char *file, int line) {
+	if (! NPOT_textures && !(((height & (height - 1)) == 0) || ((width & (width - 1)) == 0))) {
+		debugOut("I was told to create a texture with dimensions %ix%i in %s @ line %d although NPOT textures are disabled.\n", width, height, file, line);
+		//height = getNextPOT(height);
+		//width = getNextPOT(width);
+	}
+
+	textureList *list = firstTexture;
+	while (list) {
+		if (list->name == name)  {
+			//debugOut("Texture dimensions are overwritten.\n");
+			break;
+		}
+		list = list->next;
+	}
+	if (list == NULL) {
+		list = addTexture();
+	}
+	list->name = name;
+	list->width = width;
+	list->height = height;
+
+}
+#endif
+
+#ifdef HAVE_GLES2
+void glesCopyTexSubImage2D(GLenum target,  GLint level, GLint xoffset, GLint yoffset, GLint x,  GLint y,  GLsizei width,  GLsizei height) {
+	// Work around for broken glCopy(Sub)TexImage2D...
+	void *tmp = malloc(width * height * 4);
+	glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
+	glTexSubImage2D(target, level, xoffset, yoffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
+	free(tmp);
+}
+void glesCopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint x,  GLint y,  GLsizei width,  GLsizei height,  GLint border) {
+	// Work around for broken glCopy(Sub)TexImage2D...
+	void *tmp = malloc(width * height * 4);
+	glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
+	glTexImage2D(target, level, GL_RGBA, width, height, border, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
+	free(tmp);
+}
+#endif
+
+#if 0
+void dcopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint x,  GLint y,  GLsizei width,  GLsizei height,  GLint border, GLuint name, const char *file, int line) {
+
+	glBindTexture(GL_TEXTURE_2D, name);
+#ifdef HAVE_GLES2_
+	glesCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
+#else
+	glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
+#endif
+}
+
+void dcopyTexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLint x,  GLint y,  GLsizei width,  GLsizei height, GLuint name, const char *file, int line) {
+	glBindTexture(GL_TEXTURE_2D, name);
+#ifdef HAVE_GLES2_
+	glesCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+#else
+	glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+#endif
+}
+
+void dtexImage2D(GLenum target,  GLint level,  GLint internalformat,  GLsizei width,  GLsizei height,
+                 GLint border,  GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line) {
+	storeTextureDimensions(name, width,  height, file, line);
+	glBindTexture(GL_TEXTURE_2D, name);
+	glTexImage2D(target, level, internalformat, width, height, border, format, type,  data);
+}
+
+void dtexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLsizei width,  GLsizei height,
+                    GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line) {
+	storeTextureDimensions(name, width,  height, file, line);
+	glBindTexture(GL_TEXTURE_2D, name);
+	glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
+}
+
+void setPrimaryColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
+	primaryColor[0] = r;
+	primaryColor[1] = g;
+	primaryColor[2] = b;
+	primaryColor[3] = a;
+}
+
+void setSecondaryColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
+	secondaryColor[0] = r;
+	secondaryColor[1] = g;
+	secondaryColor[2] = b;
+	secondaryColor[3] = a;
+}
+
+void drawQuad(GLint program, const GLfloat *vertices, int numTexCoords, ...) {
+	int i, vertexLoc, texCoordLocs[numTexCoords];
+	const GLfloat *texCoords[numTexCoords];
+
+	va_list vl;
+	va_start(vl, numTexCoords);
+	for (i = 0; i < numTexCoords; i++) {
+		texCoords[i] = va_arg(vl, const GLfloat *);
+	}
+	va_end(vl);
+
+	glUniform4f(glGetUniformLocation(program, "myColor"), primaryColor[0], primaryColor[1], primaryColor[2], primaryColor[3]);
+	if (program == shader.smartScaler || program == shader.paste) {
+		glUniform4f(glGetUniformLocation(program, "mySecondaryColor"), secondaryColor[0], secondaryColor[1], secondaryColor[2], secondaryColor[3]);
+	}
+
+	vertexLoc = glGetAttribLocation(program, "myVertex");
+	texCoordLocs[0] = glGetAttribLocation(program, "myUV0");
+	if (numTexCoords > 1) texCoordLocs[1] = glGetAttribLocation(program, "myUV1");
+	if (numTexCoords > 2) texCoordLocs[2] = glGetAttribLocation(program, "myUV2");
+	if (numTexCoords > 3) texCoordLocs[3] = glGetAttribLocation(program, "myUV3");
+
+	glEnableVertexAttribArray(vertexLoc);
+	glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, GL_FALSE, 0, vertices);
+
+	for (i = 0; i < numTexCoords; i++) {
+		if (texCoords[i]) {
+			glEnableVertexAttribArray(texCoordLocs[i]);
+			glVertexAttribPointer(texCoordLocs[i], 2, GL_FLOAT, GL_FALSE, 0, texCoords[i]);
+		}
+	}
+
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	for (i = 0; i < numTexCoords; i++) {
+		if (texCoords[i]) {
+			glDisableVertexAttribArray(texCoordLocs[i]);
+		}
+	}
+	glDisableVertexAttribArray(vertexLoc);
+
+}
+
+
+void setPMVMatrix(GLint program) {
+	glUniformMatrix4fv(glGetUniformLocation(program, "myPMVMatrix"), 1, GL_FALSE, aPMVMatrix);
+}
+#endif
+// This is for swapping settings between rendering to texture or to the screen
+void setPixelCoords(bool pixels) {
+	static int current = -1;
+//	if (current == pixels) return;
+	current = pixels;
+#if 0
+	glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+
+	if (pixels) {
+
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+		glClear(GL_COLOR_BUFFER_BIT);
+
+		const GLfloat bPMVMatrix[] = {
+			2.0f / viewportWidth,                  .0,   .0,  .0,
+			.0, 2.0f / viewportHeight,   .0,  .0,
+			.0,                  .0, 1.0f,  .0,
+			-1.0,               -1.0f,   .0, 1.0f
+
+		};
+		for (int i = 0; i < 16; i++) {
+			aPMVMatrix[i] = bPMVMatrix[i];
+		}
+	} else {
+		if (gameSettings.antiAlias < 0) {
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		} else {
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		}
+
+		GLfloat w = (GLfloat) winWidth / cameraZoom;
+		GLfloat h = (GLfloat) winHeight / cameraZoom;
+
+		const GLfloat bPMVMatrix[] = {
+			2.0f / w,      .0,   .0,  .0,
+			.0, -2.0f / h,   .0,  .0,
+			.0,      .0, 1.0f,  .0,
+			-1.0,    1.0f,   .0, 1.0f
+
+		};
+		for (int i = 0; i < 16; i++) {
+			aPMVMatrix[i] = bPMVMatrix[i];
+		}
+	}
+#endif
+}
+
+int desktopW = 0, desktopH = 0;
+bool runningFullscreen = false;
+
+
+#if defined(HAVE_GLES2)
+void saveTexture(GLuint tex, GLubyte *data) {
+	// use an FBO to easily grab the texture...
+	static GLuint fbo = 0;
+	GLuint old_fbo;
+	GLint tw, th;
+	GLint old_vp[4];
+	if (fbo == 0) {
+		glGenFramebuffers(1, &fbo);
+	}
+	glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *)&old_fbo);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
+	getTextureDimensions(tex, &tw, &th);
+	glGetIntegerv(GL_VIEWPORT, old_vp);
+	glViewport(0, 0, tw, th);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+	glReadPixels(0, 0, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, data);
+	glViewport(old_vp[0], old_vp[1], old_vp[2], old_vp[3]);
+	glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
+}
+#elif defined _WIN32
+// Replacement for glGetTexImage, because some ATI drivers are buggy.
+void saveTexture(GLuint tex, GLubyte *data) {
+	setPixelCoords(true);
+
+	glBindTexture(GL_TEXTURE_2D, tex);
+
+	GLint tw, th;
+	getTextureDimensions(tex, &tw, &th);
+
+	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+	int xoffset = 0;
+	while (xoffset < tw) {
+		int w = (tw - xoffset < viewportWidth) ? tw - xoffset : viewportWidth;
+
+		int yoffset = 0;
+		while (yoffset < th) {
+			int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight;
+
+			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
+
+			const GLfloat vertices[] = {
+				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.f,
+				(GLfloat)tw - xoffset, (GLfloat) - yoffset, 0.f,
+				(GLfloat) - xoffset, (GLfloat) - yoffset + th, 0.f,
+				(GLfloat)tw - xoffset, (GLfloat) - yoffset + th, 0.f
+			};
+
+			const GLfloat texCoords[] = {
+				0.0f, 0.0f,
+				1.0f, 0.0f,
+				0.0f, 1.0f,
+				1.0f, 1.0f
+			};
+
+			glUseProgram(shader.texture);
+			setPMVMatrix(shader.texture);
+
+			drawQuad(shader.texture, vertices, 1, texCoords);
+			glUseProgram(0);
+
+			for (int i = 0; i < h; i++)   {
+				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, data + xoffset * 4 + (yoffset + i) * 4 * tw);
+			}
+
+			yoffset += viewportHeight;
+		}
+
+		xoffset += viewportWidth;
+	}
+	//glReadPixels(viewportOffsetX, viewportOffsetY, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+	setPixelCoords(false);
+
+}
+#else
+#if 0
+void saveTexture(GLuint tex, GLubyte *data) {
+
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+}
+#endif
+#endif
+
+// This is for setting windowed or fullscreen graphics.
+// Used for switching, and for initial window creation.
+void setGraphicsWindow(bool fullscreen, bool restoreGraphics, bool resize) {
+#if defined(PANDORA)
+	fullscreen = true;
+#endif
+#if 0
+	GLubyte *snapTexture = NULL;
+
+	Uint32 videoflags = 0;
+
+	if (! desktopW) {
+
+		// Get video hardware information
+		const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
+		desktopW = videoInfo->current_w;
+		desktopH = videoInfo->current_h;
+
+	} else if (restoreGraphics && fullscreen == runningFullscreen & ! resize) return;
+
+	runningFullscreen = fullscreen;
+
+	if (restoreGraphics) {
+		/*
+		 * Save the textures
+		 */
+		if (backdropTextureName) {
+			if (backdropTexture) delete backdropTexture;
+			int picWidth = sceneWidth;
+			int picHeight = sceneHeight;
+			if (! NPOT_textures) {
+				picWidth = getNextPOT(picWidth);
+				picHeight = getNextPOT(picHeight);
+			}
+			backdropTexture = new GLubyte [picHeight * picWidth * 4];
+			if (! checkNew(backdropTexture)) return;
+
+			saveTexture(backdropTextureName, backdropTexture);
+		}
+		if (snapshotTextureName) {
+			int picWidth = winWidth;
+			int picHeight = winHeight;
+			if (! NPOT_textures) {
+				picWidth = getNextPOT(picWidth);
+				picHeight = getNextPOT(picHeight);
+			}
+			snapTexture = new GLubyte [picHeight * picWidth * 4];
+			if (! checkNew(snapTexture)) return;
+
+			saveTexture(snapshotTextureName, snapTexture);
+		}
+	}
+
+	/*
+	 * Set the graphics mode
+	 */
+	float winAspect = (float) winWidth / winHeight;
+
+	if (fullscreen) {
+		specialSettings &= ~SPECIAL_INVISIBLE;
+#if !defined(HAVE_GLES2)
+		videoflags = SDL_OPENGL | SDL_FULLSCREEN;
+#else
+		videoflags = SDL_SWSURFACE | SDL_FULLSCREEN;
+#endif
+
+		if (gameSettings.fixedPixels) {
+			viewportWidth = realWinWidth = winWidth;
+			viewportHeight = realWinHeight = winHeight;
+			viewportOffsetY = 0;
+			viewportOffsetX = 0;
+		} else {
+			realWinWidth = desktopW;
+			realWinHeight = desktopH;
+
+			float realAspect = (float) realWinWidth / realWinHeight;
+
+			if (realAspect > winAspect) {
+				viewportHeight = realWinHeight;
+				viewportWidth = (int)(realWinHeight * winAspect);
+				viewportOffsetY = 0;
+				viewportOffsetX = (realWinWidth - viewportWidth) / 2;
+			} else {
+				viewportWidth = realWinWidth;
+				viewportHeight = (int)((float) realWinWidth / winAspect);
+				viewportOffsetY = (realWinHeight - viewportHeight) / 2;
+				viewportOffsetX = 0;
+			}
+		}
+
+	} else {
+#if !defined(HAVE_GLES2)
+		videoflags = SDL_OPENGL/* | SDL_RESIZABLE*/;
+#else
+		videoflags = SDL_SWSURFACE;
+#endif
+
+		if (resize) {
+			float realAspect = (float) desktopW / desktopH;
+
+			if (realAspect > winAspect) {
+				realWinWidth = (int)(realWinHeight * winAspect);
+			} else {
+				realWinHeight = (int)(realWinWidth / winAspect);
+			}
+
+			realAspect = (float) realWinWidth / realWinHeight;
+
+			if (realAspect > winAspect) {
+				viewportHeight = realWinHeight;
+				viewportWidth = (int)(realWinHeight * winAspect);
+				viewportOffsetY = 0;
+				viewportOffsetX = (realWinWidth - viewportWidth) / 2;
+			} else {
+				viewportWidth = realWinWidth;
+				viewportHeight = (int)((float) realWinWidth / winAspect);
+				viewportOffsetY = (realWinHeight - viewportHeight) / 2;
+				viewportOffsetX = 0;
+			}
+		} else {
+
+			if (gameSettings.fixedPixels) {
+				viewportWidth = realWinWidth = winWidth;
+				viewportHeight = realWinHeight = winHeight;
+				viewportOffsetY = 0;
+				viewportOffsetX = 0;
+			} else {
+				realWinHeight = desktopH * 3 / 4;
+				realWinWidth = (int)(realWinHeight * winAspect);
+
+				if (realWinWidth > desktopW) {
+					realWinWidth = desktopW;
+					realWinHeight = (int)((float) realWinWidth / winAspect);
+				}
+
+				viewportHeight = realWinHeight;
+				viewportWidth = realWinWidth;
+				viewportOffsetY = 0;
+				viewportOffsetX = 0;
+			}
+		}
+	}
+
+	debugHeader();
+
+	if (SDL_SetVideoMode(realWinWidth, realWinHeight, 32, videoflags) == 0) {
+		msgBox("Startup Error: Couldn't set video mode.", SDL_GetError());
+		SDL_Quit();
+		exit(2);
+	}
+	debugOut("Video mode %d %d set successfully.\n", realWinWidth, realWinHeight);
+
+#if defined(HAVE_GLES2)
+	if (EGL_Open()) {
+		msgBox("Startup Error", "Couldn't initialize EGL.");
+		SDL_Quit();
+		exit(1);
+	}
+	EGL_Init();
+#endif
+
+	GLint uniform;
+	const char *Vertex;
+	const char *Fragment;
+
+	Vertex = shaderFileRead("scale.vert");
+
+#if !defined(HAVE_GLES2)
+	Fragment = shaderFileRead("scale.frag");
+#else
+	/*  const GLubyte *str;
+	    int glDerivativesAvailable;
+	    str = glGetString (GL_EXTENSIONS);
+	    glDerivativesAvailable = (strstr((const char *)str, "GL_OES_standard_derivatives") != NULL);
+	    if (!glDerivativesAvailable) {
+	        debugOut("Extension \"GL_OES_standard_derivatives\" not available. Advanced anti-aliasing is not possible. Using linear anti-aliasing instead.");
+	        gameSettings.antiAlias = -1;
+	*/
+	Fragment = shaderFileRead("scale_noaa.frag");
+//	}
+
+	Fragment = joinStrings("precision mediump float;\n", Fragment);
+#endif
+
+	if (! Vertex || ! Fragment) {
+		fatal("Error loading \"scale\" shader program!", "Try re-installing the game. (scale.frag, scale_noaa.frag or scale.vert was not found.)");
+		gameSettings.antiAlias = -1;
+		shader.smartScaler = 0;
+	} else {
+
+		shader.smartScaler = buildShaders(Vertex, Fragment);
+
+		if (! shader.smartScaler) {
+			fatal("Error building \"scale\" shader program!");
+			gameSettings.antiAlias = -1;
+			shader.smartScaler = 0;
+		} else {
+			debugOut("Built shader program: %d (smartScaler)\n", shader.smartScaler);
+
+			glUseProgram(shader.smartScaler);
+			uniform = glGetUniformLocation(shader.smartScaler, "Texture");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.smartScaler, "lightTexture");
+			if (uniform >= 0) glUniform1i(uniform, 1);
+			uniform = glGetUniformLocation(shader.smartScaler, "useLightTexture");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.smartScaler, "antialias");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.smartScaler, "scale");
+
+			float scale = (float)realWinWidth / (float)winWidth * 0.25;
+			if (scale > 1.0) scale = 1.0;
+			if (uniform >= 0) glUniform1f(uniform, scale);
+
+		}
+	}
+
+	Vertex = shaderFileRead("fixScaleSprite.vert");
+	Fragment = shaderFileRead("fixScaleSprite.frag");
+
+#if defined(HAVE_GLES2)
+	Fragment = joinStrings("precision mediump float;\n", Fragment);
+#endif
+
+	if (! Vertex || ! Fragment) {
+		fatal("Error loading \"fixScaleSprite\" shader program!", "Try re-installing the game. (fixScaleSprite.frag or fixScaleSprite.vert was not found.)");
+		shader.paste = 0;
+	} else {
+
+		shader.paste = buildShaders(Vertex, Fragment);
+		if (! shader.paste) {
+			fatal("Error building \"fixScaleSprite\" shader program!");
+		} else {
+			debugOut("Built shader program: %d (fixScaleSprite)\n", shader.paste);
+
+			glUseProgram(shader.paste);
+			uniform = glGetUniformLocation(shader.paste, "tex0");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.paste, "tex1");
+			if (uniform >= 0) glUniform1i(uniform, 1);
+			uniform = glGetUniformLocation(shader.paste, "tex2");
+			if (uniform >= 0) glUniform1i(uniform, 2);
+			uniform = glGetUniformLocation(shader.paste, "useLightTexture");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+
+		}
+	}
+
+	Vertex = shaderFileRead("yuv.vert");
+	Fragment = shaderFileRead("yuv.frag");
+
+#if defined(HAVE_GLES2)
+	Fragment = joinStrings("precision mediump float;\n", Fragment);
+#endif
+
+	if (! Vertex || ! Fragment) {
+		fatal("Error loading \"yuv\" shader program!", "Try re-installing the game. (yuv.frag or yuv.vert was not found.)");
+		shader.yuv = 0;
+	} else {
+
+		shader.yuv = buildShaders(Vertex, Fragment);
+		if (! shader.yuv) {
+			fatal("Error building \"yuv\" shader program!");
+		} else {
+			debugOut("Built shader program: %d (yuv)\n", shader.yuv);
+
+			glUseProgram(shader.yuv);
+			uniform = glGetUniformLocation(shader.yuv, "Ytex");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.yuv, "Utex");
+			if (uniform >= 0) glUniform1i(uniform, 1);
+			uniform = glGetUniformLocation(shader.yuv, "Vtex");
+			if (uniform >= 0) glUniform1i(uniform, 2);
+
+		}
+	}
+
+	Vertex = shaderFileRead("texture.vert");
+	Fragment = shaderFileRead("texture.frag");
+
+#if defined(HAVE_GLES2)
+	Fragment = joinStrings("precision mediump float;\n", Fragment);
+#endif
+
+	if (! Vertex || ! Fragment) {
+		fatal("Error loading \"texture\" shader program!", "Try re-installing the game. (texture.frag or texture.vert was not found.)");
+		shader.texture = 0;
+	} else {
+
+		shader.texture = buildShaders(Vertex, Fragment);
+		if (! shader.texture) {
+			fatal("Error building \"texture\" shader program!");
+		} else {
+			debugOut("Built shader program: %d (texture)\n", shader.texture);
+
+			glUseProgram(shader.texture);
+			uniform = glGetUniformLocation(shader.texture, "sampler2d");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.texture, "zBuffer");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+			uniform = glGetUniformLocation(shader.texture, "zBufferLayer");
+			if (uniform >= 0) glUniform1f(uniform, 0.);
+			uniform = glGetUniformLocation(shader.texture, "modulateColor");
+			if (uniform >= 0) glUniform1i(uniform, 0);
+		}
+	}
+
+	Vertex = shaderFileRead("color.vert");
+	Fragment = shaderFileRead("color.frag");
+
+#if defined(HAVE_GLES2)
+	Fragment = joinStrings("precision mediump float;\n", Fragment);
+#endif
+
+	if (! Vertex || ! Fragment) {
+		fatal("Error loading \"color\" shader program!", "Try re-installing the game. (color.frag or color.vert was not found.)");
+		shader.color = 0;
+	} else {
+
+		shader.color = buildShaders(Vertex, Fragment);
+		if (! shader.color) {
+			fatal("Error building \"color\" shader program!");
+		} else {
+			debugOut("Built shader program: %d (color)\n", shader.color);
+			glUseProgram(shader.color);
+		}
+	}
+	glUseProgram(0);
+
+	glViewport(viewportOffsetX, viewportOffsetY, viewportWidth, viewportHeight);
+
+	/*
+	 * Set up OpenGL for 2D rendering.
+	 */
+	glDisable(GL_DEPTH_TEST);
+	glDisable(GL_CULL_FACE);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	setPixelCoords(false);
+
+	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+	if (restoreGraphics) {
+		/*
+		 * Restore the textures
+		 */
+		if (backdropTextureName) {
+			if (!glIsTexture(backdropTextureName)) {
+				glGenTextures(1, &backdropTextureName);
+			}
+			glBindTexture(GL_TEXTURE_2D, backdropTextureName);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+			if (gameSettings.antiAlias < 0) {
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+			} else {
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+			}
+			// Restore the backdrop
+			texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sceneWidth, sceneHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, backdropTextureName);
+
+		}
+		if (snapshotTextureName) {
+			if (!glIsTexture(snapshotTextureName)) {
+				glGenTextures(1, &snapshotTextureName);
+			}
+			glBindTexture(GL_TEXTURE_2D, snapshotTextureName);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+			// Restore the backdrop
+			texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, winWidth, winHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, snapTexture, snapshotTextureName);
+			delete snapTexture;
+		}
+
+		if (yTextureName) {
+			if (!glIsTexture(yTextureName)) {
+				glGenTextures(1, &yTextureName);
+				glGenTextures(1, &uTextureName);
+				glGenTextures(1, &vTextureName);
+			}
+		}
+
+
+		reloadSpriteTextures();
+		reloadParallaxTextures();
+		zBuffer.texName = 0;
+		if (zBuffer.numPanels) {
+			setZBuffer(zBuffer.originalNum);
+		}
+		lightMap.name = 0;
+		if (lightMapNumber) {
+			loadLightMap(lightMapNumber);
+		}
+
+		sludgeDisplay();
+	}
+
+	if (movieIsPlaying)
+		setMovieViewport();
+#endif
+}
+
+void setupOpenGLStuff() {
+
+	/*
+	 * Time to setup our requested window attributes for our OpenGL window.
+	 * We want *at least* 8 bits of red, green and blue. We also want at least a 16-bit
+	 * depth buffer.
+	 *
+	 * The last thing we do is request a double buffered window. '1' turns on double
+	 * buffering, '0' turns it off.
+	 */
+#if 0
+	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+#endif
+	setGraphicsWindow(gameSettings.userFullScreen, false);
+
+#if !defined(HAVE_GLES2)
+#if 0
+	/* Check for graphics capabilities... */
+	if (GLEE_VERSION_2_0) {
+		// Yes! Textures can be any size!
+		NPOT_textures = true;
+		debugOut("OpenGL 2.0! All is good.\n");
+	} else {
+		if (GLEE_VERSION_1_5) {
+			debugOut("OpenGL 1.5!\n");
+		} else if (GLEE_VERSION_1_4) {
+			debugOut("OpenGL 1.4!\n");
+		} else if (GLEE_VERSION_1_3) {
+			debugOut("OpenGL 1.3!\n");
+		} else if (GLEE_VERSION_1_2) {
+			debugOut("OpenGL 1.2!\n");
+		}
+
+		if (GLEE_ARB_texture_non_power_of_two) {
+			// Yes! Textures can be any size!
+			NPOT_textures = true;
+		} else {
+			// Workaround needed for lesser graphics cards. Let's hope this works...
+			NPOT_textures = false;
+			debugOut("Warning: Old graphics card! GLEE_ARB_texture_non_power_of_two not supported.\n");
+		}
+
+		if (GLEE_ARB_shading_language_100) {
+			debugOut("ARB_shading_language_100 supported.\n");
+		} else {
+			debugOut("Warning: Old graphics card! ARB_shading_language_100 not supported. Try updating your drivers.\n");
+		}
+		if (GLEE_ARB_shader_objects) {
+			debugOut("ARB_shader_objects supported.\n");
+		} else {
+			fatal("Error: Old graphics card! ARB_shader_objects not supported.\n");
+		}
+		if (GLEE_ARB_vertex_shader) {
+			debugOut("ARB_vertex_shader supported.\n");
+		} else {
+			fatal("Error: Old graphics card! ARB_vertex_shader not supported.\n");
+		}
+		if (GLEE_ARB_fragment_shader) {
+			debugOut("ARB_fragment_shader supported.\n");
+		} else {
+			fatal("Error: Old graphics card! ARB_fragment_shader not supported.\n");
+		}
+	}
+#else
+	NPOT_textures = false;
+#endif
+#endif
+	int n;
+#if 0
+	glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (GLint *) &n);
+#endif
+	debugOut("Max texture image units: %d\n", n);
+
+}
+
+
+// I found this function on a coding forum on the 'net.
+// Looks a bit weird, but it should work.
+int getNextPOT(int n) {
+	--n;
+	n |= n >> 16;
+	n |= n >> 8;
+	n |= n >> 4;
+	n |= n >> 2;
+	n |= n >> 1;
+	++n;
+	return n;
+}
+
+int printOglError(const char *file, int line) {
+	/* Returns 1 if an OpenGL error occurred, 0 otherwise. */
+	int retCode = 0;
+#if 0
+	GLenum glErr;
+
+	glErr = glGetError();
+	while (glErr != GL_NO_ERROR) {
+#if !defined(HAVE_GLES2)
+		debugOut("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
+#else
+		debugOut("glError in file %s @ line %d: error code %i\n", file, line, glErr);
+#endif
+		retCode = 1;
+		glErr = glGetError();
+	}
+#endif
+	return retCode;
+}
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
new file mode 100644
index 0000000..ca95307
--- /dev/null
+++ b/engines/sludge/graphics.h
@@ -0,0 +1,118 @@
+/* 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.
+ *
+ */
+#ifndef SLUDGE_GRAPHICS_H
+#define SLUDGE_GRAPHICS_H
+
+#if 0
+#if !defined(HAVE_GLES2)
+#include "GLee.h"
+#else
+#include <GLES2/gl2.h>
+#include "eglport/eglport.h"
+#endif
+#endif
+
+
+struct texture {
+#if 0
+	GLubyte *data;
+	GLuint name;
+#endif
+	int w, h;
+	double texW, texH;
+};
+
+#if 0
+struct shaders {
+	GLuint paste;
+	GLuint smartScaler;
+	GLuint yuv;
+	GLuint texture;
+	GLuint color;
+};
+#endif
+
+struct textureList {
+#if 0
+	GLuint name;
+	GLsizei width;
+	GLsizei height;
+#endif
+	struct textureList *next;
+};
+
+#if 0
+// From Backdrop.cpp, but they're here anyway
+extern GLubyte *backdropTexture;
+extern GLfloat backdropTexW, backdropTexH;
+#endif
+
+extern unsigned int winWidth, winHeight;
+extern int viewportHeight, viewportWidth;
+extern int viewportOffsetX, viewportOffsetY;
+extern int realWinWidth, realWinHeight;
+
+extern bool NPOT_textures;
+
+#if 0
+extern shaders shader;
+extern GLfloat aPMVMatrix[];
+
+void setPrimaryColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
+void setSecondaryColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
+
+void drawQuad(GLint program, const GLfloat *vertices, int numTexCoords, ...);
+
+void setPMVMatrix(GLint program);
+#endif
+
+void setPixelCoords(bool pixels);
+void setGraphicsWindow(bool fullscreen, bool restoreGraphics = true, bool resize = false);
+
+void setupOpenGLStuff();
+
+int getNextPOT(int n);
+
+#if 0
+void saveTexture(GLuint tex, GLubyte *data);
+
+void dcopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint x,  GLint y,  GLsizei width,  GLsizei height,  GLint border, GLuint name, const char *file, int line);
+void dcopyTexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLint x,  GLint y,  GLsizei width,  GLsizei height, GLuint name, const char *file, int line);
+void dtexImage2D(GLenum target,  GLint level,  GLint internalformat,  GLsizei width,  GLsizei height,  GLint border,  GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line);
+void dtexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLsizei width,  GLsizei height,  GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line);
+
+#define copyTexImage2D(target, level, internalformat, x, y,  width, height, border, name) dcopyTexImage2D(target,  level,  internalformat,  x,  y,  width,height, border, name, __FILE__, __LINE__)
+
+#define copyTexSubImage2D(target,  level,  xoffset,yoffset, x,  y,   width,   height, name) dcopyTexSubImage2D(target,  level,  xoffset,  yoffset,  x,  y,   width,  height, name, __FILE__, __LINE__)
+
+#define texImage2D(target,  level,  internalformat,  width,  height,  border,  format, type,  data,name) dtexImage2D( target,   level,  internalformat, width, height, border,  format,  type,  data, name, __FILE__, __LINE__)
+
+#define texSubImage2D( target,  level,   xoffset,   yoffset,   width,  height, format,  type,   data,name) dtexSubImage2D( target, level,   xoffset,  yoffset,  width,  height, format,  type,  data,  name, __FILE__, __LINE__)
+
+void deleteTextures(GLsizei n,  const GLuint *textures);
+
+void getTextureDimensions(GLuint name, GLint *width,  GLint *height);
+
+int printOglError(const char *file, int         line);
+#define printOpenGLError() printOglError(__FILE__, __LINE__)
+#endif
+#endif
diff --git a/engines/sludge/helpers.cpp b/engines/sludge/helpers.cpp
new file mode 100644
index 0000000..f25f878
--- /dev/null
+++ b/engines/sludge/helpers.cpp
@@ -0,0 +1,36 @@
+/* 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 "allfiles.h"
+#include "helpers.h"
+
+bool fileExists(const char *file) {
+	bool retval = false;
+#if ALLOW_FILE
+	FILE *tester;
+	tester = fopen(file, "rb");
+	if (tester) {
+		retval = true;
+		fclose(tester);
+	}
+#endif
+	return retval;
+}
diff --git a/engines/sludge/helpers.h b/engines/sludge/helpers.h
new file mode 100644
index 0000000..82d8e40
--- /dev/null
+++ b/engines/sludge/helpers.h
@@ -0,0 +1,27 @@
+/* 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.
+ *
+ */
+#ifndef SLUDGE_HELPERS_H
+#define SLUDGE_HELPERS_H
+
+bool fileExists(const char *file);
+
+#endif
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
new file mode 100644
index 0000000..3a95661
--- /dev/null
+++ b/engines/sludge/language.cpp
@@ -0,0 +1,210 @@
+/* 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 <stdio.h>
+#include <string.h>
+#include "stringy.h"
+#include "newfatal.h"
+#include "moreio.h"
+#include "language.h"
+#include "CommonCode/version.h"
+#include "platform-dependent.h"
+
+int *languageTable;
+char **languageName;
+settingsStruct gameSettings;
+
+unsigned int stringToInt(char *s) {
+	int i = 0;
+	bool negative = false;
+	for (;;) {
+		if (*s >= '0' && *s <= '9') {
+			i *= 10;
+			i += *s - '0';
+			s ++;
+		} else if (*s == '-') {
+			negative = ! negative;
+			s++;
+		} else {
+			if (negative)
+				return -i;
+			return i;
+		}
+	}
+}
+
+
+char *getPrefsFilename(char *filename) {
+	// Yes, this trashes the original string, but
+	// we also free it at the end (warning!)...
+
+	int n, i;
+
+	n = strlen(filename);
+
+	if (n > 4 && filename[n - 4] == '.') {
+		filename[n - 4] = 0;
+	}
+
+	char *f = filename;
+	for (i = 0; i < n; i++) {
+#ifdef _WIN32
+		if (filename[i] == '\\')
+#else
+		if (filename[i] == '/')
+#endif
+			f = filename + i + 1;
+	}
+
+	char *joined = joinStrings(f, ".ini");
+
+	delete filename;


Commit: c4a5af22eac930b5ed8e04fede2b9e61a76ca5d6
    https://github.com/scummvm/scummvm/commit/c4a5af22eac930b5ed8e04fede2b9e61a76ca5d6
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Add namespace

Changed paths:
    engines/sludge/allfiles.h
    engines/sludge/backdrop.cpp
    engines/sludge/backdrop.h
    engines/sludge/bg_effects.cpp
    engines/sludge/bg_effects.h
    engines/sludge/builtin.cpp
    engines/sludge/builtin.h
    engines/sludge/colours.h
    engines/sludge/csludge.h
    engines/sludge/cursors.cpp
    engines/sludge/cursors.h
    engines/sludge/debug.cpp
    engines/sludge/debug.h
    engines/sludge/errors.h
    engines/sludge/fileset.cpp
    engines/sludge/fileset.h
    engines/sludge/floor.cpp
    engines/sludge/floor.h
    engines/sludge/fonttext.cpp
    engines/sludge/fonttext.h
    engines/sludge/freeze.cpp
    engines/sludge/freeze.h
    engines/sludge/graphics.cpp
    engines/sludge/graphics.h
    engines/sludge/helpers.cpp
    engines/sludge/helpers.h
    engines/sludge/language.cpp
    engines/sludge/language.h
    engines/sludge/line.cpp
    engines/sludge/line.h
    engines/sludge/linuxstuff.cpp
    engines/sludge/linuxstuff.h
    engines/sludge/loadsave.cpp
    engines/sludge/loadsave.h
    engines/sludge/main_loop.cpp
    engines/sludge/main_loop.h
    engines/sludge/memwatch.cpp
    engines/sludge/memwatch.h
    engines/sludge/moreio.cpp
    engines/sludge/moreio.h
    engines/sludge/movie.cpp
    engines/sludge/movie.h
    engines/sludge/newfatal.cpp
    engines/sludge/newfatal.h
    engines/sludge/objtypes.cpp
    engines/sludge/objtypes.h
    engines/sludge/people.cpp
    engines/sludge/people.h
    engines/sludge/platform-dependent.h
    engines/sludge/region.cpp
    engines/sludge/region.h
    engines/sludge/savedata.cpp
    engines/sludge/savedata.h
    engines/sludge/shaders.cpp
    engines/sludge/shaders.h
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h
    engines/sludge/sludger.cpp
    engines/sludge/sludger.h
    engines/sludge/sound.h
    engines/sludge/sound_bass.cpp
    engines/sludge/sound_nosound.cpp
    engines/sludge/sound_openal.cpp
    engines/sludge/sprbanks.cpp
    engines/sludge/sprbanks.h
    engines/sludge/sprites.cpp
    engines/sludge/sprites.h
    engines/sludge/statusba.cpp
    engines/sludge/statusba.h
    engines/sludge/stringy.cpp
    engines/sludge/stringy.h
    engines/sludge/talk.cpp
    engines/sludge/talk.h
    engines/sludge/thumbnail.cpp
    engines/sludge/thumbnail.h
    engines/sludge/timing.cpp
    engines/sludge/timing.h
    engines/sludge/transition.cpp
    engines/sludge/transition.h
    engines/sludge/variable.cpp
    engines/sludge/variable.h
    engines/sludge/vid.cpp
    engines/sludge/vid.h
    engines/sludge/winstuff.cpp
    engines/sludge/winstuff.h
    engines/sludge/zbuffer.cpp
    engines/sludge/zbuffer.h


diff --git a/engines/sludge/allfiles.h b/engines/sludge/allfiles.h
index 9478da5..a08df72 100644
--- a/engines/sludge/allfiles.h
+++ b/engines/sludge/allfiles.h
@@ -27,6 +27,11 @@
 
 //#define debuggy2 int
 #define IN_THE_CENTRE 65535
+
+namespace Sludge {
+
 typedef unsigned char byte;
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index ed71770..bb840b3 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -19,7 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-
 #if 0
 #if defined __unix__ && !(defined __APPLE__)
 #include <png.h>
@@ -54,11 +53,12 @@
 #include "talk.h"
 #include "sludger.h"
 #include "statusba.h"
-
+#include "variable.h"
 #include "CommonCode/version.h"
 
-extern inputType input;
+namespace Sludge {
 
+extern inputType input;
 
 bool freeze();
 void unfreeze(bool);    // Because FREEZE.H needs a load of other includes
@@ -96,7 +96,7 @@ void nosnapshot() {
 #endif
 }
 
-#if ALLOW_FILE
+#if 0
 void saveSnapshot(FILE *fp) {
 	if (snapshotTextureName) {
 		fputc(1, fp);               // 1 for snapshot follows
@@ -157,7 +157,7 @@ bool snapshot() {
 	return true;
 }
 
-#if ALLOW_FILE
+#if 0
 bool restoreSnapshot(FILE *fp) {
 	unsigned int picWidth = get2bytes(fp);
 	unsigned int picHeight = get2bytes(fp);
@@ -304,7 +304,7 @@ bool resizeBackdrop(int x, int y) {
 
 void loadBackDrop(int fileNum, int x, int y) {
 	setResourceForFatal(fileNum);
-#if ALLOW_FILE
+#if 0
 	if (! openFileFromNum(fileNum)) {
 		fatal("Can't load overlay image");
 		return;
@@ -322,7 +322,7 @@ void loadBackDrop(int fileNum, int x, int y) {
 }
 
 void mixBackDrop(int fileNum, int x, int y) {
-#if ALLOW_FILE
+#if 0
 	setResourceForFatal(fileNum);
 	if (! openFileFromNum(fileNum)) {
 		fatal("Can't load overlay image");
@@ -623,7 +623,7 @@ void drawBackDrop() {
 
 bool loadLightMap(int v) {
 	int newPicWidth, newPicHeight;
-#if ALLOW_FILE
+#if 0
 	setResourceForFatal(v);
 	if (! openFileFromNum(v)) return fatal("Can't open light map.");
 	long file_pointer = ftell(bigDataFile);
@@ -764,9 +764,9 @@ bool loadLightMap(int v) {
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-#endif
-	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, newPicWidth, newPicHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightMap.data, lightMap.name);
 
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, newPicWidth, newPicHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightMap.data, lightMap.name);
+#endif
 	finishAccess();
 
 #endif
@@ -816,7 +816,7 @@ void reloadParallaxTextures() {
 
 bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) {
 
-#if ALLOW_FILE
+#if 0
 	setResourceForFatal(v);
 	if (! openFileFromNum(v)) return fatal("Can't open parallax image");
 
@@ -1004,7 +1004,7 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 extern int viewportOffsetX, viewportOffsetY;
 
-#if ALLOW_FILE
+#if 0
 bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 
 	int t1, t2, n;
@@ -1751,3 +1751,5 @@ bool getRGBIntoStack(unsigned int x, unsigned int y, stackHandler *sH) {
 #endif
 	return true;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/backdrop.h b/engines/sludge/backdrop.h
index 97d3377..5dd2014 100644
--- a/engines/sludge/backdrop.h
+++ b/engines/sludge/backdrop.h
@@ -34,6 +34,8 @@
 #include "variable.h"
 #include "graphics.h"
 
+namespace Sludge {
+
 enum {
 	LIGHTMAPMODE_NONE       = -1,
 	LIGHTMAPMODE_HOTSPOT,
@@ -65,7 +67,7 @@ void mixBackDrop(int fileNum, int x, int y);
 void drawBackDrop();
 void blankScreen(int x1, int y1, int x2, int y2);
 void darkScreen();
-#if ALLOW_FILE
+#if 0
 void saveHSI(FILE *writer);
 void saveCoreHSI(FILE *writer, GLuint texture, int w, int h);
 bool loadHSI(FILE *fp, int, int, bool);
@@ -101,3 +103,5 @@ void saveSnapshot(FILE *fp);
 bool restoreSnapshot(FILE *fp);
 #endif
 #endif
+
+} // End of namespace Sludge
diff --git a/engines/sludge/bg_effects.cpp b/engines/sludge/bg_effects.cpp
index ad6438b..0a8550e 100644
--- a/engines/sludge/bg_effects.cpp
+++ b/engines/sludge/bg_effects.cpp
@@ -28,6 +28,8 @@
 #include "newfatal.h"
 #include "moreio.h"
 
+namespace Sludge {
+
 #if 0
 //extern unsigned short int * * backDropImage;
 extern GLuint backdropTextureName;
@@ -373,3 +375,5 @@ bool blurScreen() {
 #endif
 	return false;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/bg_effects.h b/engines/sludge/bg_effects.h
index 067fa8d..d18fae6 100644
--- a/engines/sludge/bg_effects.h
+++ b/engines/sludge/bg_effects.h
@@ -23,6 +23,8 @@
 #ifndef SLUDGE_BG_EFFECTS_H
 #define SLUDGE_BG_EFFECTS_H
 
+namespace Sludge {
+
 bool blurScreen();
 #if ALLOW_FILE
 void blur_saveSettings(FILE *fp);
@@ -30,4 +32,6 @@ void blur_loadSettings(FILE *fp);
 #endif
 bool blur_createSettings(int numParams, variableStack *&stack);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 9ba633d..6f2660d 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -56,6 +56,8 @@
 #include "graphics.h"
 #include "CommonCode/utf8.h"
 
+namespace Sludge {
+
 extern char *gamePath;
 
 int speechMode = 0;
@@ -308,7 +310,7 @@ builtIn(fileExists) {
 	char *aaaaa = encodeFilename(loadNow);
 	delete loadNow;
 	if (failSecurityCheck(aaaaa)) return BR_ERROR;
-#if ALLOW_FILE
+#if 0
 	FILE *fp = fopen(aaaaa, "rb");
 	if (!fp) {
 		char currentDir[1000];
@@ -324,8 +326,10 @@ builtIn(fileExists) {
 			debugOut("Error: Failed changing to directory %s\n", currentDir);
 		}
 	}
+#endif
 	// Return value
-	setVariable(fun -> reg, SVT_INT, (fp != NULL));
+	setVariable(fun -> reg, SVT_INT, 0/*(fp != NULL)*/);//TODO:false value
+#if 0
 	if (fp) fclose(fp);
 	delete[] aaaaa;
 	loadNow = NULL;
@@ -2543,3 +2547,4 @@ builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun) {
 	return BR_ERROR;
 }
 
+} // End of namespace Sludge
diff --git a/engines/sludge/builtin.h b/engines/sludge/builtin.h
index 8f5ac59..00d780e 100644
--- a/engines/sludge/builtin.h
+++ b/engines/sludge/builtin.h
@@ -23,9 +23,13 @@
 #ifndef SLUDGE_BUILTIN_H
 #define SLUDGE_BUILTIN_H
 
+namespace Sludge {
+
 enum builtReturn {BR_KEEP_AND_PAUSE, BR_ERROR, BR_CONTINUE, BR_PAUSE, BR_CALLAFUNC, BR_ALREADY_GONE};
 
 bool failSecurityCheck(char *fn);
 builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/colours.h b/engines/sludge/colours.h
index 503823f..2caf963 100644
--- a/engines/sludge/colours.h
+++ b/engines/sludge/colours.h
@@ -23,6 +23,8 @@
 #ifndef SLUDGE_COLOURS_H
 #define SLUDGE_COLOURS_H
 
+namespace Sludge {
+
 // Simple colour conversion routines to deal with 16-bit graphics
 //unsigned short int makeColour (byte r, byte g, byte b);
 
@@ -44,4 +46,6 @@ inline unsigned short makeColour(unsigned short int r, unsigned short int g, uns
 	return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
 }
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/csludge.h b/engines/sludge/csludge.h
index 3c73a9d1..22b6125 100644
--- a/engines/sludge/csludge.h
+++ b/engines/sludge/csludge.h
@@ -23,6 +23,8 @@
 #ifndef SLUDGE_CSLUDGE_H
 #define SLUDGE_CSLUDGE_H
 
+namespace Sludge {
+
 enum sludgeCommand {SLU_UNKNOWN,
                     SLU_RETURN, SLU_BRANCH, SLU_BR_ZERO, SLU_SET_GLOBAL,
                     SLU_SET_LOCAL, SLU_LOAD_GLOBAL, SLU_LOAD_LOCAL,
@@ -40,4 +42,6 @@ enum sludgeCommand {SLU_UNKNOWN,
                     numSludgeCommands
                    };
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
index 6ad3a35..91d0112 100644
--- a/engines/sludge/cursors.cpp
+++ b/engines/sludge/cursors.cpp
@@ -36,6 +36,8 @@
 #include "people.h"
 #include "sludger.h"
 
+namespace Sludge {
+
 personaAnimation *mouseCursorAnim;
 int mouseCursorFrameNum = 0;
 int mouseCursorCountUp = 0;
@@ -84,3 +86,5 @@ void pasteCursor(int x, int y, personaAnimation *c) {
 		        c -> theSprites -> bank.sprites[c -> frames[0].frameNum],
 		        c -> theSprites -> bank.myPalette);
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/cursors.h b/engines/sludge/cursors.h
index 9c803fc..6a32665 100644
--- a/engines/sludge/cursors.h
+++ b/engines/sludge/cursors.h
@@ -23,8 +23,12 @@
 #ifndef SLUDGE_CURSORS_H
 #define SLUDGE_CURSORS_H
 
+namespace Sludge {
+
 void pickAnimCursor(struct personaAnimation *pp);
 void displayCursor();
 void pasteCursor(int x, int y, struct personaAnimation *c);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/debug.cpp b/engines/sludge/debug.cpp
index 222f411..3e256bd 100644
--- a/engines/sludge/debug.cpp
+++ b/engines/sludge/debug.cpp
@@ -28,13 +28,15 @@
 #include "debug.h"
 #include "language.h"
 
+namespace Sludge {
+
 void debugOut(const char *a, ...) {
 	if (! gameSettings.debugMode) return;
 
 	va_list argptr;
 	va_start(argptr, a);
 
-#if ALLOW_FILE
+#if 0
 #if defined __unix__ && !(defined __APPLE__)
 	vfprintf(stderr, a, argptr);
 #else
@@ -50,3 +52,5 @@ void debugOut(const char *a, ...) {
 void debugHeader() {
 	debugOut("*** Engine compiled " __DATE__ " at " __TIME__ ".\n");
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/debug.h b/engines/sludge/debug.h
index 94b6c34..aecff42 100644
--- a/engines/sludge/debug.h
+++ b/engines/sludge/debug.h
@@ -23,7 +23,11 @@
 #ifndef SLUDGE_DEDBUG_H
 #define SLUDGE_DEGBUG_H
 
+namespace Sludge {
+
 void debugOut(const char *a, ...);
 void debugHeader();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/errors.h b/engines/sludge/errors.h
index 0c4716c..f706bad 100644
--- a/engines/sludge/errors.h
+++ b/engines/sludge/errors.h
@@ -23,6 +23,8 @@
 #ifndef SLUDGE_ERRRORS_H
 #define SLUDGE_ERRRORS_H
 
+namespace Sludge {
+
 #define _NO_MEMORY_GENERAL_         "\n\nTry closing down any programs you don't really need running (or freeing up a bit of disk space, which will give you more virtual memory - that should help too)."
 
 //---------------------------------------
@@ -69,4 +71,6 @@
 #define WARNING_BASS_WRONG_VERSION  "Incompatible version of BASS.DLL found!"
 #define WARNING_BASS_FAIL           "Can't initialise sound engine."
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index 8d5eb52..852fd70 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -35,6 +35,7 @@
 #include "newfatal.h"
 #include "CommonCode/version.h"
 
+namespace Sludge {
 
 bool sliceBusy = true;
 #if ALLOW_FILE
@@ -235,3 +236,5 @@ void setFileIndices(FILE *fp, int numLanguages, unsigned int skipBefore) {
 	// Remember that the data section starts here
 	startOfDataIndex = ftell(fp);
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
index 39a6691..b83e47d 100644
--- a/engines/sludge/fileset.h
+++ b/engines/sludge/fileset.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_FILESET_H
 #define SLUDGE_FILESET_H
 
+namespace Sludge {
+
 #if ALLOW_FILE
 extern FILE *bigDataFile;
 
@@ -36,4 +38,6 @@ char *getNumberedString(int value);
 bool startAccess();
 void finishAccess();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp
index 826632a..291961d 100644
--- a/engines/sludge/floor.cpp
+++ b/engines/sludge/floor.cpp
@@ -26,6 +26,8 @@
 #include "floor.h"
 #include "line.h"
 
+namespace Sludge {
+
 flor *currentFloor = NULL;
 
 bool pointInFloorPolygon(floorPolygon &floorPoly, int x, int y) {
@@ -288,3 +290,5 @@ bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, in
 	}
 	return false;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/floor.h b/engines/sludge/floor.h
index 5c0d050..193b6d1 100644
--- a/engines/sludge/floor.h
+++ b/engines/sludge/floor.h
@@ -26,6 +26,8 @@
 #include "windef.h"
 #endif
 
+namespace Sludge {
+
 struct floorPolygon {
 	int numVertices;
 	int *vertexID;
@@ -54,4 +56,6 @@ int inFloor(int x, int y);
 bool getMatchingCorners(floorPolygon &, floorPolygon &, int &, int &);
 bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
index 835c2a6..6ac9209 100644
--- a/engines/sludge/fonttext.cpp
+++ b/engines/sludge/fonttext.cpp
@@ -36,6 +36,8 @@
 #include "newfatal.h"
 #include "moreio.h"
 
+namespace Sludge {
+
 spriteBank theFont;
 int fontHeight = 0, numFontColours, loadedFontNum;
 char *fontOrderString = NULL;
@@ -204,3 +206,5 @@ bool loadFont(int filenum, const char *charOrder, int h) {
 	fontHeight = h;
 	return true;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h
index f33876f..92520a0 100644
--- a/engines/sludge/fonttext.h
+++ b/engines/sludge/fonttext.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_FONTTEXT_H
 #define SLUDGE_FONTTEXT_H
 
+namespace Sludge {
+
 bool loadFont(int filenum, const char *charOrder, int);
 void pasteString(char *theText, int, int, spritePalette &);
 void fixFont(spritePalette &spal);
@@ -32,4 +34,6 @@ void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal
 void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal);
 bool isInFont(char *theText);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp
index f245ad0..8435a9c 100644
--- a/engines/sludge/freeze.cpp
+++ b/engines/sludge/freeze.cpp
@@ -36,6 +36,8 @@
 #include "freeze.h"
 #include "zbuffer.h"
 
+namespace Sludge {
+
 extern onScreenPerson *allPeople;
 extern screenRegion *allScreenRegions;
 extern screenRegion *overRegion;
@@ -362,3 +364,5 @@ void unfreeze(bool killImage) {
 	killMe = NULL;
 
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/freeze.h b/engines/sludge/freeze.h
index 1682d3b..a9f5129 100644
--- a/engines/sludge/freeze.h
+++ b/engines/sludge/freeze.h
@@ -22,6 +22,7 @@
 #ifndef SLUDGE_FREEZE_H
 #define SLUDGE_FREEZE_H
 
+namespace Sludge {
 
 struct frozenStuffStruct {
 	onScreenPerson *allPeople;
@@ -52,4 +53,6 @@ bool freeze();
 void unfreeze(bool killImage = true);
 int howFrozen();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/graphics.cpp b/engines/sludge/graphics.cpp
index 8bdc917..702865e 100644
--- a/engines/sludge/graphics.cpp
+++ b/engines/sludge/graphics.cpp
@@ -53,6 +53,8 @@
 #endif
 #endif
 
+namespace Sludge {
+
 unsigned int winWidth, winHeight;
 int viewportHeight, viewportWidth;
 int viewportOffsetX = 0, viewportOffsetY = 0;
@@ -954,3 +956,5 @@ int printOglError(const char *file, int line) {
 #endif
 	return retCode;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
index ca95307..24b7671 100644
--- a/engines/sludge/graphics.h
+++ b/engines/sludge/graphics.h
@@ -31,6 +31,7 @@
 #endif
 #endif
 
+namespace Sludge {
 
 struct texture {
 #if 0
@@ -115,4 +116,7 @@ void getTextureDimensions(GLuint name, GLint *width,  GLint *height);
 int printOglError(const char *file, int         line);
 #define printOpenGLError() printOglError(__FILE__, __LINE__)
 #endif
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/helpers.cpp b/engines/sludge/helpers.cpp
index f25f878..30d5094 100644
--- a/engines/sludge/helpers.cpp
+++ b/engines/sludge/helpers.cpp
@@ -22,6 +22,8 @@
 #include "allfiles.h"
 #include "helpers.h"
 
+namespace Sludge {
+
 bool fileExists(const char *file) {
 	bool retval = false;
 #if ALLOW_FILE
@@ -34,3 +36,5 @@ bool fileExists(const char *file) {
 #endif
 	return retval;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/helpers.h b/engines/sludge/helpers.h
index 82d8e40..27625d2 100644
--- a/engines/sludge/helpers.h
+++ b/engines/sludge/helpers.h
@@ -22,6 +22,10 @@
 #ifndef SLUDGE_HELPERS_H
 #define SLUDGE_HELPERS_H
 
+namespace Sludge {
+
 bool fileExists(const char *file);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
index 3a95661..a55adae 100644
--- a/engines/sludge/language.cpp
+++ b/engines/sludge/language.cpp
@@ -28,6 +28,8 @@
 #include "CommonCode/version.h"
 #include "platform-dependent.h"
 
+namespace Sludge {
+
 int *languageTable;
 char **languageName;
 settingsStruct gameSettings;
@@ -208,3 +210,5 @@ int getLanguageForFileB() {
 
 	return indexNum;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/language.h b/engines/sludge/language.h
index fff3ef9..27faffb 100644
--- a/engines/sludge/language.h
+++ b/engines/sludge/language.h
@@ -22,6 +22,8 @@
 #ifndef LANGUAGE_H
 #define LANGUAGE_H
 
+namespace Sludge {
+
 struct settingsStruct {
 	unsigned int languageID;
 	unsigned int numLanguages;
@@ -43,4 +45,6 @@ int getLanguageForFileB();
 void makeLanguageTable(FILE *table);
 #endif
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/line.cpp b/engines/sludge/line.cpp
index f57bb64..bcb1343 100644
--- a/engines/sludge/line.cpp
+++ b/engines/sludge/line.cpp
@@ -26,6 +26,8 @@
 #include "graphics.h"
 #include "allfiles.h"
 
+namespace Sludge {
+
 extern int sceneWidth, sceneHeight;
 #if 0
 extern GLuint backdropTextureName;
@@ -141,3 +143,5 @@ void drawLine(int x1, int y1, int x2, int y2) {
 	setPixelCoords(false);
 #endif
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/line.h b/engines/sludge/line.h
index e7d00f0..49e895f 100644
--- a/engines/sludge/line.h
+++ b/engines/sludge/line.h
@@ -22,6 +22,10 @@
 #ifndef SLUDGE_LINE_H
 #define SLUDGE_LINE_H
 
+namespace Sludge {
+
 void drawLine(int x1, int y1, int x2, int y2);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/linuxstuff.cpp b/engines/sludge/linuxstuff.cpp
index d5b76a5..454cf93 100644
--- a/engines/sludge/linuxstuff.cpp
+++ b/engines/sludge/linuxstuff.cpp
@@ -35,6 +35,8 @@
 #include "debug.h"
 #include "helpers.h"
 
+namespace Sludge {
+
 extern settingsStruct gameSettings;
 cmdlineSettingsStruct cmdlineSettings;
 
@@ -222,4 +224,7 @@ uint32_t launch(char *filename) {
 bool defaultUserFullScreen() {
 	return false;
 }
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/linuxstuff.h b/engines/sludge/linuxstuff.h
index ba7344c..b97c7bf 100644
--- a/engines/sludge/linuxstuff.h
+++ b/engines/sludge/linuxstuff.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_LINUXSTUFF_H
 #define SLUDGE_LINUXSTUFF_H
 
+namespace Sludge {
+
 struct cmdlineSettingsStruct {
 	bool languageSet;
 	unsigned int languageID;
@@ -37,4 +39,6 @@ struct cmdlineSettingsStruct {
 void printCmdlineUsage();
 bool parseCmdlineParameters(int argc, char *argv[]);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 8641a67..2014095 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -41,6 +41,8 @@
 #include "fileset.h"
 #include "debug.h"
 
+namespace Sludge {
+
 //----------------------------------------------------------------------
 // From elsewhere
 //----------------------------------------------------------------------
@@ -91,7 +93,7 @@ stackLibrary *stackLib = NULL;
 //----------------------------------------------------------------------
 // For saving and loading stacks...
 //----------------------------------------------------------------------
-#if ALLOW_FILE
+#if 0
 bool saveVariable(variable *from, FILE *fp);
 bool loadVariable(variable *to, FILE *fp);
 
@@ -179,7 +181,7 @@ stackHandler *getStackFromLibrary(int n) {
 	}
 	return stackLib -> stack;
 }
-#if ALLOW_FILE
+#if 0
 stackHandler *loadStackRef(FILE *fp) {
 	stackHandler *nsh;
 
@@ -381,7 +383,7 @@ loadedFunction *loadFunction(FILE *fp) {
 //----------------------------------------------------------------------
 
 bool saveGame(char *fname) {
-#if ALLOW_FILE
+#if 0
 	int a;
 
 	FILE *fp = fopen(fname, "wb");
@@ -500,7 +502,7 @@ bool saveGame(char *fname) {
 int ssgVersion;
 
 bool loadGame(char *fname) {
-#if ALLOW_FILE
+#if 0
 	FILE *fp;
 	FILETIME savedGameTime;
 	int a;
@@ -676,3 +678,5 @@ bool loadGame(char *fname) {
 	clearStackLib();
 	return true;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/loadsave.h b/engines/sludge/loadsave.h
index d2ce316..b91e872 100644
--- a/engines/sludge/loadsave.h
+++ b/engines/sludge/loadsave.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_LOADSAVE_H
 #define SLUDGE_LOADSAVE_H
 
+namespace Sludge {
+
 bool saveGame(char *fname);
 bool loadGame(char *fname);
 
@@ -30,4 +32,6 @@ loadedFunction *loadFunction(FILE *fp);
 void saveFunction(loadedFunction *fun, FILE *fp);
 #endif
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 0d807af..47bfe67 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -75,6 +75,7 @@
 #include "graphics.h"
 #include "helpers.h"
 
+namespace Sludge {
 
 #ifdef _WIN32
 #define PATHSLASH '\\'
@@ -506,3 +507,5 @@ catch (std::exception &ex) { //NOTE by reference, not value
 	return -2;
 }
 #endif
+
+} // End of namespace Sludge
diff --git a/engines/sludge/main_loop.h b/engines/sludge/main_loop.h
index 8fea28e..7ea5881 100644
--- a/engines/sludge/main_loop.h
+++ b/engines/sludge/main_loop.h
@@ -22,6 +22,10 @@
 #ifndef SLUDGE_MAIN_LOOP_H
 #define SLUDGE_MAIN_LOOP_H
 
+namespace Sludge {
+
 int main_loop(char *filename);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/memwatch.cpp b/engines/sludge/memwatch.cpp
index dab57b8..d316687 100644
--- a/engines/sludge/memwatch.cpp
+++ b/engines/sludge/memwatch.cpp
@@ -19,9 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <stdlib.h>
 #include "allfiles.h"
 
+namespace Sludge {
+
 void *allKnownMem[3000];
 int allKnownNum = 0;
 
@@ -59,3 +60,5 @@ void deleting(void *mem) {
 	//db ("Error! Deleted a block which hasn't been allocated!");
 	exit(1);
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/memwatch.h b/engines/sludge/memwatch.h
index 2325b2e..0fb6f26 100644
--- a/engines/sludge/memwatch.h
+++ b/engines/sludge/memwatch.h
@@ -22,7 +22,11 @@
 #ifndef SLUDGE_MEMWATCH_H
 #define SLUDGE_MEMWATCH_H
 
+namespace Sludge {
+
 void adding(void *);
 void deleting(void *);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp
index 6df41fa..b8dc3f9 100644
--- a/engines/sludge/moreio.cpp
+++ b/engines/sludge/moreio.cpp
@@ -19,9 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <string.h>
-#include <stdint.h>
-
 #include "allfiles.h"
 #include "moreio.h"
 #include "newfatal.h"
@@ -36,6 +33,8 @@
 #endif
 #endif
 
+namespace Sludge {
+
 bool allowAnyFilename = true;
 
 #if ALLOW_FILE
@@ -322,3 +321,5 @@ char *decodeFilename(char *nameIn) {
 		return copyString(nameIn);
 	}
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/moreio.h b/engines/sludge/moreio.h
index 9635ffa..5d107a8 100644
--- a/engines/sludge/moreio.h
+++ b/engines/sludge/moreio.h
@@ -24,6 +24,8 @@
 
 #include <stdint.h>
 
+namespace Sludge {
+
 #if ALLOW_FILE
 int get2bytes(FILE *fp);
 void put2bytes(int numtoput, FILE *fp);
@@ -39,4 +41,6 @@ void put4bytes(uint32_t f, FILE *fp);
 char *encodeFilename(char *nameIn);
 char *decodeFilename(char *nameIn);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/movie.cpp b/engines/sludge/movie.cpp
index debec5e..09693f1 100644
--- a/engines/sludge/movie.cpp
+++ b/engines/sludge/movie.cpp
@@ -55,6 +55,8 @@
 #include "AL/alure.h"
 #endif
 
+namespace Sludge {
+
 extern int specialSettings;
 
 // in main.c
@@ -1041,3 +1043,5 @@ int pauseMovie() {
 #endif
 	return movieIsPlaying;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/movie.h b/engines/sludge/movie.h
index 460edb6..100439a 100644
--- a/engines/sludge/movie.h
+++ b/engines/sludge/movie.h
@@ -21,6 +21,9 @@
  */
 #ifndef SLUDGE_MOVIE_H
 #define SLUDGE_MOVIE_H
+
+namespace Sludge {
+
 /*
  movieIsPlaying tracks the state of movie playing
  */
@@ -35,4 +38,6 @@ int playMovie(int fileNumber);
 int stopMovie();
 int pauseMovie();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp
index b3fa74a..f05de5c 100644
--- a/engines/sludge/newfatal.cpp
+++ b/engines/sludge/newfatal.cpp
@@ -26,18 +26,18 @@
 #include <stdlib.h>
 #endif
 
-#include "common/debug.h"
+#include "allfiles.h"
 
+#include "common/debug.h"
 #include "platform-dependent.h"
-#include "allfiles.h"
 #include "CommonCode/version.h"
-
 #include "sound.h"
-
 #include "stringy.h"
 #include "errors.h"
 #include "graphics.h"
 
+namespace Sludge {
+
 const char emergencyMemoryMessage[] = "Out of memory displaying error message!";
 
 static char *fatalMessage = NULL;
@@ -85,7 +85,7 @@ extern SDL_Event quit_event;
 #endif
 
 int inFatal(const char *str) {
-#if ALLOW_FILE
+#if 0
 	FILE *fatFile = fopen("fatal.txt", "wt");
 	if (fatFile) {
 		fprintf(fatFile, "FATAL:\n%s\n", str);
@@ -156,3 +156,5 @@ int fatal(const char *str1, const char *str2) {
 	} else fatal(emergencyMemoryMessage);
 	return 0;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/newfatal.h b/engines/sludge/newfatal.h
index 6fd5b2f..a97dca8 100644
--- a/engines/sludge/newfatal.h
+++ b/engines/sludge/newfatal.h
@@ -24,6 +24,8 @@
 
 #include "errors.h"
 
+namespace Sludge {
+
 bool hasFatal();
 
 int fatal(const char *str);
@@ -36,4 +38,6 @@ void warning(const char *l);
 void setResourceForFatal(int n);
 char *resourceNameFromNum(int i);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp
index 7f19ee7..58572b0 100644
--- a/engines/sludge/objtypes.cpp
+++ b/engines/sludge/objtypes.cpp
@@ -27,6 +27,8 @@
 #include "fileset.h"
 #include "CommonCode/version.h"
 
+namespace Sludge {
+
 objectType *allObjectTypes = NULL;
 extern char *outputDir;
 
@@ -175,3 +177,5 @@ void removeObjectType(objectType *oT) {
 	}
 	fatal("Can't delete object type: bad pointer");
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/objtypes.h b/engines/sludge/objtypes.h
index b56b112..f61c845 100644
--- a/engines/sludge/objtypes.h
+++ b/engines/sludge/objtypes.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_OBJTYPES_H
 #define SLUDGE_OBJTYPES_H
 
+namespace Sludge {
+
 struct combination {
 	int withObj, funcNum;
 };
@@ -46,4 +48,7 @@ void removeObjectType(objectType *oT);
 void saveObjectRef(objectType *r, FILE *fp);
 objectType *loadObjectRef(FILE *fp);
 #endif
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index 3853bbe..f54b1ff 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -45,6 +45,8 @@
 #define ANI_WALK 1
 #define ANI_TALK 2
 
+namespace Sludge {
+
 extern speechStruct *speech;
 
 extern variableStack *noStack;
@@ -1175,3 +1177,5 @@ bool loadPeople(FILE *fp) {
 	return true;
 }
 #endif
+
+} // End of namespace Sludge
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index fbc8fd7..11cf10b 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_PEOPLE_H
 #define SLUDGE_PEOPLE_H
 
+namespace Sludge {
+
 struct animFrame {
 	int frameNum, howMany;
 	int noise;
@@ -131,4 +133,7 @@ bool loadPeople(FILE *fp);
 bool saveCostume(persona *cossy, FILE *fp);
 bool loadCostume(persona *cossy, FILE *fp);
 #endif
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/platform-dependent.h b/engines/sludge/platform-dependent.h
index 973e20f..5754ef5 100644
--- a/engines/sludge/platform-dependent.h
+++ b/engines/sludge/platform-dependent.h
@@ -26,6 +26,8 @@
  */
 #include <stdint.h>
 
+namespace Sludge {
+
 char *grabFileName();
 int showSetupWindow();
 
@@ -37,4 +39,6 @@ uint32_t launch(char *filename);
 
 bool defaultUserFullScreen();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp
index 3cd7164..8c55ece 100644
--- a/engines/sludge/region.cpp
+++ b/engines/sludge/region.cpp
@@ -27,6 +27,8 @@
 #include "moreio.h"
 #include "backdrop.h"
 
+namespace Sludge {
+
 screenRegion *allScreenRegions = NULL;
 screenRegion *overRegion = NULL;
 extern inputType input;
@@ -162,3 +164,5 @@ screenRegion *getRegionForObject(int obj) {
 
 	return NULL;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/region.h b/engines/sludge/region.h
index 4c4843f..52c1c58 100644
--- a/engines/sludge/region.h
+++ b/engines/sludge/region.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_REGION_H
 #define SLUDGE_REGION_H
 
+namespace Sludge {
+
 struct screenRegion {
 	int x1, y1, x2, y2, sX, sY, di;
 	objectType *thisType;
@@ -39,4 +41,6 @@ void saveRegions(FILE *);
 #endif
 void showBoxes();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/savedata.cpp b/engines/sludge/savedata.cpp
index e8075cc..79e672b 100644
--- a/engines/sludge/savedata.cpp
+++ b/engines/sludge/savedata.cpp
@@ -31,6 +31,8 @@
 
 #define LOAD_ERROR "Can't load custom data...\n\n"
 
+namespace Sludge {
+
 unsigned short saveEncoding = false;
 char encode1 = 0;
 char encode2 = 0;
@@ -266,3 +268,5 @@ bool stackToFile(char *filename, const variable &from) {
 #endif
 	return true;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/savedata.h b/engines/sludge/savedata.h
index 19821cc..e6422b8 100644
--- a/engines/sludge/savedata.h
+++ b/engines/sludge/savedata.h
@@ -22,7 +22,11 @@
 #ifndef SLUDGE_SAVEDATA_H
 #define SLUDGE_SAVEDATA_H
 
+namespace Sludge {
+
 bool fileToStack(char *filename, stackHandler *sH);
 bool stackToFile(char *filename, const variable &from);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/shaders.cpp b/engines/sludge/shaders.cpp
index fd4ca30..e11a834 100644
--- a/engines/sludge/shaders.cpp
+++ b/engines/sludge/shaders.cpp
@@ -19,14 +19,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <stdio.h>
-#include <stdlib.h>
-
+#include "allfiles.h"
 #include "debug.h"
 #include "stringy.h"
 #include "shaders.h"
 #include "graphics.h"
 
+namespace Sludge {
+
 extern char *bundleFolder;
 
 //Function from: http://www.evl.uic.edu/aej/594/code/ogl.cpp
@@ -175,4 +175,4 @@ int buildShaders(const char *vertexShader, const char *fragmentShader) {
 	return prog;
 }
 
-
+} // End of namespace Sludge
diff --git a/engines/sludge/shaders.h b/engines/sludge/shaders.h
index f62808b..13b6e37 100644
--- a/engines/sludge/shaders.h
+++ b/engines/sludge/shaders.h
@@ -30,8 +30,12 @@
 #endif
 #endif
 
+namespace Sludge {
+
 char *shaderFileRead(const char *fn);
 int buildShaders(const char *vertexShader, const char *fragmentShader);
 
+} // End of namespace Sludge
+
 #endif
 
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index 12d0bbf..0301d73 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -41,6 +41,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 
 	// Add debug channels
 	DebugMan.addDebugChannel(kSludgeDebugScript, "Script", "Script debug level");
+	DebugMan.addDebugChannel(kSludgeDebugDataLoad, "DataLoad", "Data loading debug level");
 
 	// check init
 	debug("SludgeEngine::SludgeEngine");
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 5fe7c9a..7878518 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -37,7 +37,8 @@ struct SludgeGameDescription;
 
 // debug channels
 enum {
-	kSludgeDebugScript = 1 << 0
+	kSludgeDebugScript = 1 << 0,
+	kSludgeDebugDataLoad = 1 << 1,
 };
  
 class SludgeEngine : public Engine {
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index d73c128..02a27f1 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -62,9 +62,11 @@
 #include "language.h"
 #include "CommonCode/specialsettings.h"
 #include "graphics.h"
+#include "variable.h"
+#include "common/debug.h"
+#include "sludge.h"
 
-#include "debug.h"
-
+namespace Sludge {
 
 extern personaAnimation *mouseCursorAnim;
 extern spritePalette pastePalette;
@@ -165,7 +167,7 @@ FILE *openAndVerify(char *filename, char extra1, char extra2, const char *er, in
 	}
 	char c;
 	c = fgetc(fp);
-	putchar(c);
+	debug(c);
 	while (c = fgetc(fp)) {
 		putchar(c);
 	}
@@ -264,19 +266,21 @@ bool initSludge(char *filename) {
 	}
 
 	char *checker = readString(fp);
-	printf("checker : %s\n", checker);
+	debug(kSludgeDebugDataLoad, "checker : %s\n", checker);
 
 	if (strcmp(checker, "okSoFar")) return fatal(ERROR_BAD_HEADER, filename);
 	delete checker;
 	checker = NULL;
 
 	unsigned char customIconLogo = fgetc(fp);
-	putchar(customIconLogo);
+	kSludgeDebugDataLoad(kSludgeDebugDataLoad, "Game icon: %i", customIconLogo);
 
 	if (customIconLogo & 1) {
 		// There is an icon - read it!
-		int n;
+		debug(kSludgeDebugDataLoad, "There is an icon - read it!");
 
+#if 0
+		int n;
 		long file_pointer = ftell(fp);
 
 		png_structp png_ptr;
@@ -378,10 +382,12 @@ bool initSludge(char *filename) {
 				}
 			}
 		}
+#endif
 	}
 
 	if (customIconLogo & 2) {
 		// There is an logo - read it!
+		debug(kSludgeDebugDataLoad, "There is an logo - read it!");
 		int n;
 
 		long file_pointer = ftell(fp);
@@ -519,7 +525,7 @@ bool initSludge(char *filename) {
 	delete gameNameOrig;
 
 	changeToUserDir();
-
+#if 0
 #ifdef _WIN32
 	mkdir(gameName);
 #else
@@ -527,7 +533,7 @@ bool initSludge(char *filename) {
 #endif
 
 	if (chdir(gameName)) return fatal("This game's preference folder is inaccessible!\nI can't access the following directory (maybe there's a file with the same name, or maybe it's read-protected):", gameName);
-
+#endif
 	delete [] gameName;
 
 	// Get user settings
@@ -552,6 +558,7 @@ bool initSludge(char *filename) {
 
 	if (dataFol[0]) {
 		char *dataFolder = encodeFilename(dataFol);
+#if 0
 #ifdef _WIN32
 		mkdir(dataFolder);
 #else
@@ -559,7 +566,7 @@ bool initSludge(char *filename) {
 #endif
 
 		if (chdir(dataFolder)) return fatal("This game's data folder is inaccessible!\nI can't access the following directory (maybe there's a file with the same name, or maybe it's read-protected):", dataFolder);
-
+#endif
 		delete dataFolder;
 	}
 
@@ -1561,3 +1568,5 @@ bool handleInput() {
 	lastRegion = overRegion;
 	return runSludge();
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/sludger.h b/engines/sludge/sludger.h
index fb9734a..ff24b24 100644
--- a/engines/sludge/sludger.h
+++ b/engines/sludge/sludger.h
@@ -24,10 +24,13 @@
 
 #include <stdint.h>
 
+#include "allfiles.h"
 #include "variable.h"
 #include "csludge.h"
 #include "language.h"
 
+namespace Sludge {
+
 #ifndef _WIN32
 typedef struct _FILETIME {
 	uint32_t dwLowDateTime;
@@ -35,6 +38,8 @@ typedef struct _FILETIME {
 } FILETIME;
 #endif
 
+struct variable;
+struct variableStack;
 
 struct eventHandlers {
 	int leftMouseFunction;
@@ -47,8 +52,8 @@ struct eventHandlers {
 };
 
 struct lineOfCode {
-	sludgeCommand               theCommand;
-	int32_t                     param;
+	sludgeCommand theCommand;
+	int32_t param;
 };
 
 struct loadedFunction {
@@ -95,4 +100,6 @@ void completeTimers();
 void killSpeechTimers();
 int cancelAFunction(int funcNum, loadedFunction *myself, bool &killedMyself);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/sound.h b/engines/sludge/sound.h
index 61f834b..5bb3f9d 100644
--- a/engines/sludge/sound.h
+++ b/engines/sludge/sound.h
@@ -19,13 +19,19 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "variable.h"
+
+#ifndef SLUDGE_SOUND_H
+#define SLUDGE_SOUND_H
+
 #ifdef _WIN32
 #include <windows.h>
 #else
 #define HWND void *
 #endif
 
+#include "variable.h"
+
+namespace Sludge {
 
 // Sound list stuff
 struct soundList {
@@ -38,8 +44,6 @@ struct soundList {
 soundList *deleteSoundFromList(soundList *s);
 void playSoundList(soundList *s);
 
-
-
 // GENERAL...
 bool initSoundStuff(HWND);
 void killSoundStuff();
@@ -69,3 +73,7 @@ void saveSounds(FILE *fp);
 #endif
 
 unsigned int getSoundSource(int index);
+
+} // End of namespace Sludge
+
+#endif
diff --git a/engines/sludge/sound_bass.cpp b/engines/sludge/sound_bass.cpp
index 65d8c93..017796c 100644
--- a/engines/sludge/sound_bass.cpp
+++ b/engines/sludge/sound_bass.cpp
@@ -19,8 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <stdint.h>
-
 #include "allfiles.h"
 #include "newfatal.h"
 #include "bass.h"
@@ -33,6 +31,8 @@
 #define EFFECT_CHANNELS 8
 #define TOTAL_CHANNELS 32
 
+namespace Sludge {
+
 bool soundOK = false;
 
 struct soundThing {
@@ -389,3 +389,4 @@ bool getSoundCacheStack(stackHandler *sH) {
 	return true;
 }
 
+} // End of namespace Sludge
diff --git a/engines/sludge/sound_nosound.cpp b/engines/sludge/sound_nosound.cpp
index 0731d23..8f8bb28 100644
--- a/engines/sludge/sound_nosound.cpp
+++ b/engines/sludge/sound_nosound.cpp
@@ -19,14 +19,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <stdint.h>
-
 #include "allfiles.h"
 #include "newfatal.h"
 #include "sound.h"
 #include "moreio.h"
 #include "fileset.h"
 
+namespace Sludge {
+
 bool soundOK = false;
 
 int defVol = 128;
@@ -133,3 +133,5 @@ bool getSoundCacheStack(stackHandler *sH) {
 //#pragma unused (sH)
 	return true;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/sound_openal.cpp b/engines/sludge/sound_openal.cpp
index fdb1e0b..aa8f8e1 100644
--- a/engines/sludge/sound_openal.cpp
+++ b/engines/sludge/sound_openal.cpp
@@ -37,6 +37,8 @@
 #define MAX_MODS 3
 #define NUM_BUFS 3
 
+namespace Sludge {
+
 bool soundOK = false;
 bool cacheLoopySound = false;
 bool SilenceIKillYou = false;
@@ -815,3 +817,5 @@ int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
 unsigned int getSoundSource(int index) {
 	return 0; /*soundCache[index].playingOnSource;*/ //TODO:false value
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/sprbanks.cpp b/engines/sludge/sprbanks.cpp
index bb3303b..c95e405 100644
--- a/engines/sludge/sprbanks.cpp
+++ b/engines/sludge/sprbanks.cpp
@@ -25,6 +25,8 @@
 #include "newfatal.h"
 #include "debug.h"
 
+namespace Sludge {
+
 loadedSpriteBank *allLoadedBanks = NULL;
 extern spriteBank theFont;
 extern int loadedFontNum, fontTableSize;
@@ -72,3 +74,5 @@ void reloadSpriteTextures() {
 		loadSpriteBank(loadedFontNum, theFont, true);
 	}
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/sprbanks.h b/engines/sludge/sprbanks.h
index 3c0efd3..81d1bc7 100644
--- a/engines/sludge/sprbanks.h
+++ b/engines/sludge/sprbanks.h
@@ -24,6 +24,8 @@
 
 #include "sprites.h"
 
+namespace Sludge {
+
 struct loadedSpriteBank {
 	int ID, timesUsed;
 	spriteBank bank;
@@ -33,4 +35,6 @@ struct loadedSpriteBank {
 loadedSpriteBank *loadBankForAnim(int ID);
 void reloadSpriteTextures();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index 43ddcbe..792fe66 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -27,8 +27,6 @@
 #endif
 #endif
 
-#include <string.h>
-
 #include "allfiles.h"
 
 #include "fileset.h"
@@ -45,6 +43,8 @@
 
 #include "shaders.h"
 
+namespace Sludge {
+
 extern zBufferData zBuffer;
 
 #if 0
@@ -1109,3 +1109,4 @@ void fixScaleSprite(int x, int y, sprite &single, const spritePalette &fontPal,
 #endif
 }
 
+} // End of namespace Sludge
diff --git a/engines/sludge/sprites.h b/engines/sludge/sprites.h
index e9f053f..2a617bb 100644
--- a/engines/sludge/sprites.h
+++ b/engines/sludge/sprites.h
@@ -30,6 +30,8 @@
 #endif
 #endif
 
+namespace Sludge {
+
 struct onScreenPerson;
 
 struct sprite {
@@ -90,4 +92,6 @@ bool reserveSpritePal(spritePalette &sP, int n);
 void fixScaleSprite(int x1, int y1, sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, const int camX, const int camY, bool);
 void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/statusba.cpp b/engines/sludge/statusba.cpp
index 43674a9..e7dc4cb 100644
--- a/engines/sludge/statusba.cpp
+++ b/engines/sludge/statusba.cpp
@@ -30,6 +30,8 @@
 #include "newfatal.h"
 #include "statusba.h"
 
+namespace Sludge {
+
 spritePalette verbLinePalette;
 spritePalette litVerbLinePalette;
 
@@ -227,3 +229,5 @@ bool loadStatusBars(FILE *fp) {
 	return true;
 }
 #endif
+
+} // End of namespace Sludge
diff --git a/engines/sludge/statusba.h b/engines/sludge/statusba.h
index faa164c..2f0d30a 100644
--- a/engines/sludge/statusba.h
+++ b/engines/sludge/statusba.h
@@ -22,6 +22,8 @@
 #ifndef SLUDGE_STATUSBA_H
 #define SLUDGE_STATUSBA_H
 
+namespace Sludge {
+
 struct statusBar {
 	char *text;
 	statusBar *next;
@@ -59,4 +61,6 @@ void saveStatusBars(FILE *fp);
 void restoreBarStuff(statusStuff *here);
 statusStuff *copyStatusBarStuff(statusStuff *here);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/stringy.cpp b/engines/sludge/stringy.cpp
index fdf4536..a5440b6 100644
--- a/engines/sludge/stringy.cpp
+++ b/engines/sludge/stringy.cpp
@@ -20,10 +20,13 @@
  *
  */
 #include "allfiles.h"
-#include <string.h>
-
 #include "newfatal.h"
 
+#ifndef SLUDGE_STRINGY_H
+#define SLUDGE_STRINGY_H
+
+namespace Sludge {
+
 char *copyString(const char *copyMe) {
 	char *newString = new char [strlen(copyMe) + 1];
 	if (! checkNew(newString)) return NULL;
@@ -37,3 +40,7 @@ char *joinStrings(const char *s1, const char *s2) {
 	sprintf(newString, "%s%s", s1, s2);
 	return newString;
 }
+
+} // End of namespace Sludge
+
+#endif
diff --git a/engines/sludge/stringy.h b/engines/sludge/stringy.h
index 2306567..7c6f9ed 100644
--- a/engines/sludge/stringy.h
+++ b/engines/sludge/stringy.h
@@ -22,7 +22,11 @@
 #ifndef SLUDGE_STRINGY_H
 #define SLUDGE_STRINGY_H
 
+namespace Sludge {
+
 char *copyString(const char *copyMe);
 char *joinStrings(const char *s1, const char *s2);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp
index 2803e2b..b6bc864 100644
--- a/engines/sludge/talk.cpp
+++ b/engines/sludge/talk.cpp
@@ -20,9 +20,6 @@
  *
  */
 #include "allfiles.h"
-
-#include <string.h>
-
 #include "backdrop.h"
 #include "sprites.h"
 #include "sludger.h"
@@ -37,6 +34,8 @@
 #include "stringy.h"
 #include "moreio.h"
 
+namespace Sludge {
+
 extern int fontHeight, cameraX, cameraY, speechMode;
 extern float cameraZoom;
 speechStruct *speech;
@@ -272,3 +271,5 @@ bool loadSpeech(speechStruct *sS, FILE *fp) {
 	return true;
 }
 #endif
+
+} // End of namespace Sludge
diff --git a/engines/sludge/talk.h b/engines/sludge/talk.h
index ba9bd7f..a0fb1a9 100644
--- a/engines/sludge/talk.h
+++ b/engines/sludge/talk.h
@@ -24,6 +24,8 @@
 
 #include "sprites.h"
 
+namespace Sludge {
+
 struct speechLine {
 	char *textLine;
 	speechLine *next;
@@ -49,4 +51,7 @@ void initSpeech();
 void saveSpeech(speechStruct *sS, FILE *fp);
 bool loadSpeech(speechStruct *sS, FILE *fp);
 #endif
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/thumbnail.cpp b/engines/sludge/thumbnail.cpp
index 53ab7ec..9cb471f 100644
--- a/engines/sludge/thumbnail.cpp
+++ b/engines/sludge/thumbnail.cpp
@@ -19,8 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <stdint.h>
-
 #include "allfiles.h"
 #include "errors.h"
 #include "moreio.h"
@@ -31,6 +29,8 @@
 #include "graphics.h"
 #include "newfatal.h"
 
+namespace Sludge {
+
 bool freeze();
 void unfreeze(bool);    // Because FREEZE.H needs a load of other includes
 
@@ -264,3 +264,5 @@ bool skipThumbnail(FILE *fp) {
 	return (fgetc(fp) == '!');
 }
 #endif
+
+} // End of namespace Sludge
diff --git a/engines/sludge/thumbnail.h b/engines/sludge/thumbnail.h
index 4e505be..3836478 100644
--- a/engines/sludge/thumbnail.h
+++ b/engines/sludge/thumbnail.h
@@ -22,10 +22,15 @@
 #ifndef SLUDGE_THUMBNAIL_H
 #define SLUDGE_THUMBNAIL_H
 
+namespace Sludge {
+
 #if ALLOW_FILE
 bool saveThumbnail(FILE *fp);
 bool skipThumbnail(FILE *fp);
 #endif
 
 void showThumbnail(char *filename, int x, int y);
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/timing.cpp b/engines/sludge/timing.cpp
index a1dcba0..ae4c0cd 100644
--- a/engines/sludge/timing.cpp
+++ b/engines/sludge/timing.cpp
@@ -23,6 +23,8 @@
 #include <SDL/SDL.h>
 #endif
 
+namespace Sludge {
+
 int desiredfps = 300;               //holds desired frames per second
 Uint32 starttime, endtime;
 Uint32 desired_frame_time;
@@ -54,3 +56,4 @@ void Wait_Frame(void) {
 	starttime = endtime;
 }
 
+} // End of namespace Sludge
diff --git a/engines/sludge/timing.h b/engines/sludge/timing.h
index 504bf62..0fd59f5 100644
--- a/engines/sludge/timing.h
+++ b/engines/sludge/timing.h
@@ -22,10 +22,14 @@
 #ifndef SLUDGE_TIMING_H
 #define SLUDGE_TIMING_H
 
+namespace Sludge {
+
 void Init_Timer(void);
 void Init_Special_Timer(int t);
 void Get_Start_Time(void);
 void Get_End_Time(void);
 void Wait_Frame(void);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/transition.cpp b/engines/sludge/transition.cpp
index 041e2c9..0fcd4fe 100644
--- a/engines/sludge/transition.cpp
+++ b/engines/sludge/transition.cpp
@@ -20,8 +20,6 @@
  *
  */
 #include <stdint.h>
-#include <string.h>
-
 #include "allfiles.h"
 #include "colours.h"
 #include "backdrop.h"
@@ -32,13 +30,14 @@
 extern GLuint snapshotTextureName;
 #endif
 
+namespace Sludge {
+
 extern unsigned char brightnessLevel;
 
 extern float snapTexW, snapTexH;
 
 unsigned char fadeMode = 2;
 
-
 //----------------------------------------------------
 // PROPER BRIGHTNESS FADING
 //----------------------------------------------------
@@ -406,3 +405,5 @@ void fixBrightness() {
 
 	}
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/transition.h b/engines/sludge/transition.h
index f05c438..7dc29f7 100644
--- a/engines/sludge/transition.h
+++ b/engines/sludge/transition.h
@@ -22,7 +22,11 @@
 #ifndef SLUDGE_TRANSITION_H
 #define SLUDGE_TRANSITION_H
 
+namespace Sludge {
+
 void fixBrightness();
 void resetRandW();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index 2c64a7f..334beb1 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -19,15 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <string.h>
-
 #include "debug.h"
 
 #include "allfiles.h"
-
 #include "variable.h"
 #include "newfatal.h"
-
 #include "stringy.h"
 #include "objtypes.h"
 #include "people.h"
@@ -40,6 +36,8 @@
 
 #endif
 
+namespace Sludge {
+
 const char *typeName[] = {"undefined", "number", "user function", "string",
                           "built-in function", "file", "stack",
                           "object type", "animation", "costume"
@@ -667,3 +665,5 @@ void debugVar (FILE * fp, const variable & thisVar) {
     }
 }
 */
+
+} // End of namespace Sludge
diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h
index 8d633c8..8f9f743 100644
--- a/engines/sludge/variable.h
+++ b/engines/sludge/variable.h
@@ -22,6 +22,11 @@
 #ifndef SLUDGE_VARIABLE_H
 #define SLUDGE_VARIABLE_H
 
+namespace Sludge {
+
+struct variable;
+struct variableStack;
+
 enum variableType {SVT_NULL, SVT_INT, SVT_FUNC, SVT_STRING,
                    SVT_BUILT, SVT_FILE, SVT_STACK,
                    SVT_OBJTYPE, SVT_ANIM, SVT_COSTUME,
@@ -114,6 +119,7 @@ variable *fastArrayGetByIndex(fastArrayHandler *vS, unsigned int theIndex);
 #define stackDebug(a)  {}
 #endif
 
+} // End of namespace Sludge
 
 #endif
 
diff --git a/engines/sludge/vid.cpp b/engines/sludge/vid.cpp
index a95a452..266c5bd 100644
--- a/engines/sludge/vid.cpp
+++ b/engines/sludge/vid.cpp
@@ -37,6 +37,8 @@
 #include "colours.h"
 #include "fileset.h"
 
+namespace Sludge {
+
 struct timStream {
 	PAVISTREAM      got;
 	AVISTREAMINFO   info;
@@ -257,3 +259,5 @@ bool nextVideoFrame() {
 
 	return true;
 }
+
+} // End of namespace Sludge
diff --git a/engines/sludge/vid.h b/engines/sludge/vid.h
index 5b28e37..1d81daf 100644
--- a/engines/sludge/vid.h
+++ b/engines/sludge/vid.h
@@ -22,9 +22,13 @@
 #ifndef SLUDGE_VID_H
 #define SLUDGE_VID_H
 
+namespace Sludge {
+
 bool startVideo(int fileNum);
 bool nextVideoFrame();
 void finishVideo();
 void initialiseMovieStuff();
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/winstuff.cpp b/engines/sludge/winstuff.cpp
index 2e51b4b..266df69 100644
--- a/engines/sludge/winstuff.cpp
+++ b/engines/sludge/winstuff.cpp
@@ -51,6 +51,8 @@
 
 #include "..\..\images\resource.h"
 
+namespace Sludge {
+
 HINSTANCE hInst;                // Handle of the main instance
 extern HWND hMainWindow;
 
@@ -224,4 +226,7 @@ uint32_t launch(char *f) {
 bool defaultUserFullScreen() {
 	return true;
 }
+
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/winstuff.h b/engines/sludge/winstuff.h
index a934f44..4a0cbbe 100644
--- a/engines/sludge/winstuff.h
+++ b/engines/sludge/winstuff.h
@@ -26,6 +26,8 @@
 #include <windows.h>
 #endif
 
+namespace Sludge {
+
 #ifndef _WIN32
 #ifndef HINSTANCE
 #define HINSTANCE int
@@ -36,4 +38,6 @@ void setWindowName(const char *tx);
 bool InitApplication(HINSTANCE hInstance);
 bool InitInstance(HINSTANCE hInstance, const char *);
 
+} // End of namespace Sludge
+
 #endif
diff --git a/engines/sludge/zbuffer.cpp b/engines/sludge/zbuffer.cpp
index 6597f37..ddcebb1 100644
--- a/engines/sludge/zbuffer.cpp
+++ b/engines/sludge/zbuffer.cpp
@@ -28,6 +28,8 @@
 #include "newfatal.h"
 #include "graphics.h"
 
+namespace Sludge {
+
 zBufferData zBuffer;
 extern int sceneWidth, sceneHeight;
 
@@ -203,3 +205,4 @@ void drawZBuffer(int x, int y, bool upsidedown) {
 #endif
 }
 
+} // End of namespace Sludge
diff --git a/engines/sludge/zbuffer.h b/engines/sludge/zbuffer.h
index 9040f57..6fdbd02 100644
--- a/engines/sludge/zbuffer.h
+++ b/engines/sludge/zbuffer.h
@@ -30,6 +30,7 @@
 #endif
 #endif
 
+namespace Sludge {
 
 struct zBufferData {
 	int width, height;
@@ -48,4 +49,6 @@ bool setZBuffer(int y);
 void killZBuffer();
 void drawZBuffer(int x, int y, bool upsidedown);
 
+} // End of namespace Sludges
+
 #endif


Commit: f2d81f6f5dd52f838518ee24080f1ebc9451c7f8
    https://github.com/scummvm/scummvm/commit/f2d81f6f5dd52f838518ee24080f1ebc9451c7f8
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Add new debug channels

Changed paths:
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h


diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index 0301d73..d0d6b37 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -41,7 +41,9 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 
 	// Add debug channels
 	DebugMan.addDebugChannel(kSludgeDebugScript, "Script", "Script debug level");
-	DebugMan.addDebugChannel(kSludgeDebugDataLoad, "DataLoad", "Data loading debug level");
+	DebugMan.addDebugChannel(kSludgeDebugDataLoad, "Data Load", "Data loading debug level");
+	DebugMan.addDebugChannel(kSludgeDebugStackMachine, "Stack Machine", "Stack Machine debug level");
+	DebugMan.addDebugChannel(kSludgeDebugBuiltin, "Built-in", "Built-in debug level");
 
 	// check init
 	debug("SludgeEngine::SludgeEngine");
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 7878518..4570b04 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -22,23 +22,25 @@
 
 #ifndef SLUDGE_H
 #define SLUDGE_H
- 
+
 #include "common/random.h"
 #include "engines/engine.h"
 #include "gui/debugger.h"
- 
+
 #include "sludge/console.h"
 
 namespace Sludge {
  
 class SludgeConsole;
- 
+
 struct SludgeGameDescription;
 
 // debug channels
 enum {
 	kSludgeDebugScript = 1 << 0,
 	kSludgeDebugDataLoad = 1 << 1,
+	kSludgeDebugStackMachine = 1 << 2,
+	kSludgeDebugBuiltin = 1 << 3,
 };
  
 class SludgeEngine : public Engine {


Commit: 1aa64b5b0f1b6908e76e796cb7e683a5587d5c4d
    https://github.com/scummvm/scummvm/commit/1aa64b5b0f1b6908e76e796cb7e683a5587d5c4d
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Add namespace for file version.h

Changed paths:
    engines/sludge/CommonCode/version.h


diff --git a/engines/sludge/CommonCode/version.h b/engines/sludge/CommonCode/version.h
index 2b640a0..9307bff 100644
--- a/engines/sludge/CommonCode/version.h
+++ b/engines/sludge/CommonCode/version.h
@@ -10,4 +10,8 @@
 
 #define VERSION(a,b)    (a * 256 + b)
 
+namespace Sludge {
+
 extern int gameVersion;
+
+} // End of namespace Sludge


Commit: f5b4cf680371b5b2098c766361b5efc6e0a68e91
    https://github.com/scummvm/scummvm/commit/f5b4cf680371b5b2098c766361b5efc6e0a68e91
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Remove inner include of vorbis library

Changed paths:
    engines/sludge/movie.cpp


diff --git a/engines/sludge/movie.cpp b/engines/sludge/movie.cpp
index 09693f1..3f02f73 100644
--- a/engines/sludge/movie.cpp
+++ b/engines/sludge/movie.cpp
@@ -44,11 +44,12 @@
 #include "shaders.h"
 
 #include "sound.h"
+
+#if 0
 #include "vorbis/codec.h"
 #define OV_EXCLUDE_STATIC_CALLBACKS
 #include "vorbis/vorbisfile.h"
 
-#if 0
 #include "ogg/ogg.h"
 #include "libvorbis/vorbis_os.h"
 


Commit: 45dcfdfc0bad326800618d4d3edfd772d53c9fc6
    https://github.com/scummvm/scummvm/commit/45dcfdfc0bad326800618d4d3edfd772d53c9fc6
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Replace standard file reading functions by Common functions

Changed paths:
    engines/sludge/backdrop.cpp
    engines/sludge/backdrop.h
    engines/sludge/bg_effects.cpp
    engines/sludge/bg_effects.h
    engines/sludge/builtin.cpp
    engines/sludge/detection.cpp
    engines/sludge/fileset.cpp
    engines/sludge/fileset.h
    engines/sludge/floor.cpp
    engines/sludge/helpers.cpp
    engines/sludge/language.cpp
    engines/sludge/language.h
    engines/sludge/loadsave.cpp
    engines/sludge/loadsave.h
    engines/sludge/main_loop.cpp
    engines/sludge/memwatch.cpp
    engines/sludge/module.mk
    engines/sludge/moreio.cpp
    engines/sludge/moreio.h
    engines/sludge/newfatal.cpp
    engines/sludge/objtypes.cpp
    engines/sludge/objtypes.h
    engines/sludge/people.cpp
    engines/sludge/people.h
    engines/sludge/region.cpp
    engines/sludge/region.h
    engines/sludge/savedata.cpp
    engines/sludge/shaders.cpp
    engines/sludge/sludger.cpp
    engines/sludge/sludger.h
    engines/sludge/sound.h
    engines/sludge/sound_bass.cpp
    engines/sludge/sound_nosound.cpp
    engines/sludge/sound_openal.cpp
    engines/sludge/sprites.cpp
    engines/sludge/statusba.cpp
    engines/sludge/statusba.h
    engines/sludge/talk.cpp
    engines/sludge/talk.h
    engines/sludge/thumbnail.cpp
    engines/sludge/thumbnail.h
    engines/sludge/timing.cpp
    engines/sludge/variable.cpp
    engines/sludge/vid.cpp
    engines/sludge/zbuffer.cpp


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index bb840b3..929e67d 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -96,16 +96,16 @@ void nosnapshot() {
 #endif
 }
 
+void saveSnapshot(Common::WriteStream *stream) {
 #if 0
-void saveSnapshot(FILE *fp) {
 	if (snapshotTextureName) {
-		fputc(1, fp);               // 1 for snapshot follows
-		saveCoreHSI(fp, snapshotTextureName, winWidth, winHeight);
+		putch(1, stream);               // 1 for snapshot follows
+		saveCoreHSI(stream, snapshotTextureName, winWidth, winHeight);
 	} else {
-		fputc(0, fp);
+		putch(0, stream);
 	}
-}
 #endif
+}
 
 bool snapshot() {
 
@@ -157,17 +157,16 @@ bool snapshot() {
 	return true;
 }
 
-#if 0
-bool restoreSnapshot(FILE *fp) {
-	unsigned int picWidth = get2bytes(fp);
-	unsigned int picHeight = get2bytes(fp);
+bool restoreSnapshot(Common::SeekableReadStream *stream) {
+	unsigned int picWidth = get2bytes(stream);
+	unsigned int picHeight = get2bytes(stream);
 
 	if ((picWidth != winWidth) || (picHeight != winHeight))
 		return false;
 
 	unsigned int t1, t2, n;
 	unsigned short c;
-
+#if 0
 	GLubyte *target;
 	if (! NPOT_textures) {
 		picWidth = getNextPOT(picWidth);
@@ -177,17 +176,19 @@ bool restoreSnapshot(FILE *fp) {
 	}
 	GLubyte *snapshotTexture = new GLubyte [picHeight * picWidth * 4];
 	if (! snapshotTexture) return fatal("Out of memory while restoring snapshot.");
+#endif
 
 	for (t2 = 0; t2 < winHeight; t2 ++) {
 		t1 = 0;
 		while (t1 < winWidth) {
-			c = (unsigned short) get2bytes(fp);
+			c = (unsigned short) get2bytes(stream);
 			if (c & 32) {
-				n = fgetc(fp) + 1;
+				n = getch(stream) + 1;
 				c -= 32;
 			} else {
 				n = 1;
 			}
+#if 0
 			while (n --) {
 				target = snapshotTexture + 4 * picWidth * t2 + t1 * 4;
 				target[0] = (GLubyte) redValue(c);
@@ -196,9 +197,10 @@ bool restoreSnapshot(FILE *fp) {
 				target[3] = (GLubyte) 255;
 				t1++;
 			}
+#endif
 		}
 	}
-
+#if 0
 	if (! snapshotTextureName) glGenTextures(1, &snapshotTextureName);
 	glBindTexture(GL_TEXTURE_2D, snapshotTextureName);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -210,10 +212,9 @@ bool restoreSnapshot(FILE *fp) {
 
 	delete snapshotTexture;
 	snapshotTexture = NULL;
-
+#endif
 	return true;
 }
-#endif
 
 void killBackDrop() {
 #if 0
@@ -1005,7 +1006,7 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 extern int viewportOffsetX, viewportOffsetY;
 
 #if 0
-bool loadHSI(FILE *fp, int x, int y, bool reserve) {
+bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 
 	int t1, t2, n;
 	unsigned short c;
@@ -1014,7 +1015,7 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 	int picWidth;
 	int picHeight;
 	int realPicWidth, realPicHeight;
-	long file_pointer = ftell(fp);
+	long file_pointer = stream->pos();
 
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
@@ -1025,20 +1026,20 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 	// Is this a PNG file?
 
 	char tmp[10];
-	size_t bytes_read = fread(tmp, 1, 8, fp);
-	if (bytes_read != 8 && ferror(fp)) {
+	size_t bytes_read = stream->read(tmp, 8);
+	if (bytes_read != 8 && stream->err()) {
 		debugOut("Reading error in loadHSI.\n");
 	}
 	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
 		// No, it's old-school HSI
 		fileIsPNG = false;
-		fseek(fp, file_pointer, SEEK_SET);
+		stream->seek(file_pointer, SEEK_SET);
 
-		picWidth = realPicWidth = get2bytes(fp);
-		picHeight = realPicHeight = get2bytes(fp);
+		picWidth = realPicWidth = get2bytes(stream);
+		picHeight = realPicHeight = get2bytes(stream);
 	} else {
 		// Read the PNG header
-
+#if 0
 		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 		if (!png_ptr) {
 			return false;
@@ -1078,10 +1079,10 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
 
 		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-
+#endif
 	}
 
-
+#if 0
 	GLfloat texCoordW = 1.0;
 	GLfloat texCoordH = 1.0;
 	if (! NPOT_textures) {
@@ -1138,7 +1139,7 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 	}
 
 	GLuint tmpTex;
-#if 0
+
 	glGenTextures(1, &tmpTex);
 	glBindTexture(GL_TEXTURE_2D, tmpTex);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -1150,7 +1151,7 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	}
-#endif
+
 	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
 
 
@@ -1189,9 +1190,9 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 		int yoffset = 0;
 		while (yoffset < realPicHeight) {
 			int h = (realPicHeight - yoffset < viewportHeight) ? realPicHeight - yoffset : viewportHeight;
-#if 0
+
 			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
-#endif
+
 			const GLfloat vertices[] = {
 				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
 				(GLfloat)realPicWidth - xoffset, (GLfloat) - yoffset, 0.,
@@ -1207,7 +1208,7 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 			};
 
 			if (backdropExists) {
-#if 0
+
 				// Render the sprite to the backdrop
 				// (using mulitexturing, so the old backdrop is seen where alpha < 1.0)
 				glActiveTexture(GL_TEXTURE2);
@@ -1217,35 +1218,34 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 				glUseProgram(shader.paste);
 				GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
 				if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
-#endif
 				setPMVMatrix(shader.paste);
 
 				setPrimaryColor(1.0, 1.0, 1.0, 1.0);
-#if 0
+
 				glBindTexture(GL_TEXTURE_2D, tmpTex);
 				//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-#endif
+
 				drawQuad(shader.paste, vertices, 3, texCoords, NULL, btexCoords);
-#if 0
+
 				glUseProgram(0);
-#endif
+
 			} else {
 				// It's all new - nothing special to be done.
 
-#if 0
+
 				glUseProgram(shader.texture);
-#endif
+
 				setPMVMatrix(shader.texture);
-#if 0
+
 				glBindTexture(GL_TEXTURE_2D, tmpTex);
-#endif
+
 				setPrimaryColor(1.0, 0.0, 0.0, 0.0);
 
 				drawQuad(shader.texture, vertices, 1, texCoords);
 
-#if 0
+
 				glUseProgram(0);
-#endif
+
 			}
 
 			// Copy Our ViewPort To The Texture
@@ -1259,17 +1259,17 @@ bool loadHSI(FILE *fp, int x, int y, bool reserve) {
 	deleteTextures(1, &tmpTex);
 
 	setPixelCoords(false);
-
+#endif
 	backdropExists = true;
 	return true;
 }
 
-bool mixHSI(FILE *fp, int x, int y) {
+bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 	int realPicWidth, realPicHeight;
 	int picWidth;
 	int picHeight;
 
-	long file_pointer = ftell(fp);
+	long file_pointer = stream->pos();
 
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
@@ -1279,17 +1279,18 @@ bool mixHSI(FILE *fp, int x, int y) {
 
 	// Is this a PNG file?
 	char tmp[10];
-	size_t bytes_read = fread(tmp, 1, 8, fp);
-	if (bytes_read != 8 && ferror(fp)) {
+	size_t bytes_read = stream->read(tmp, 8);
+	if (bytes_read != 8 && stream->err()) {
 		debugOut("Reading error in mixHSI.\n");
 	}
+#if 0
 	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
 		// No, it's old-school HSI
 		fileIsPNG = false;
-		fseek(fp, file_pointer, SEEK_SET);
+		stream->seek(file_pointer, SEEK_SET);
 
-		picWidth = realPicWidth = get2bytes(fp);
-		picHeight = realPicHeight = get2bytes(fp);
+		picWidth = realPicWidth = get2bytes(stream);
+		picHeight = realPicHeight = get2bytes(stream);
 	} else {
 		// Read the PNG header
 
@@ -1309,7 +1310,7 @@ bool mixHSI(FILE *fp, int x, int y) {
 			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
 			return false;
 		}
-		png_init_io(png_ptr, fp);       // Tell libpng which file to read
+		png_init_io(png_ptr, stream);       // Tell libpng which file to read
 		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
 
 		png_read_info(png_ptr, info_ptr);
@@ -1398,9 +1399,9 @@ bool mixHSI(FILE *fp, int x, int y) {
 		for (t2 = 0; t2 < realPicHeight; t2 ++) {
 			t1 = 0;
 			while (t1 < realPicWidth) {
-				c = (unsigned short) get2bytes(fp);
+				c = (unsigned short) get2bytes(stream);
 				if (c & 32) {
-					n = fgetc(fp) + 1;
+					n = getch(stream) + 1;
 					c -= 32;
 				} else {
 					n = 1;
@@ -1425,7 +1426,7 @@ bool mixHSI(FILE *fp, int x, int y) {
 	}
 
 	GLuint tmpTex;
-#if 0
+
 	glGenTextures(1, &tmpTex);
 	glBindTexture(GL_TEXTURE_2D, tmpTex);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -1437,7 +1438,7 @@ bool mixHSI(FILE *fp, int x, int y) {
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	}
-#endif
+
 	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
 
 
@@ -1453,7 +1454,7 @@ bool mixHSI(FILE *fp, int x, int y) {
 		int yoffset = 0;
 		while (yoffset < realPicHeight) {
 			int h = (realPicHeight - yoffset < viewportHeight) ? realPicHeight - yoffset : viewportHeight;
-#if 0
+
 			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
 
 			// Render the sprite to the backdrop
@@ -1465,14 +1466,14 @@ bool mixHSI(FILE *fp, int x, int y) {
 			glUseProgram(shader.paste);
 			GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
 			if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
-#endif
+
 			setPMVMatrix(shader.paste);
 
 			setPrimaryColor(1.0, 1.0, 1.0, 0.5);
-#if 0
+
 			glBindTexture(GL_TEXTURE_2D, tmpTex);
 			//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-#endif
+
 			const GLfloat vertices[] = {
 				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
 				(GLfloat)realPicWidth - xoffset, (GLfloat) - yoffset, 0.,
@@ -1481,10 +1482,10 @@ bool mixHSI(FILE *fp, int x, int y) {
 			};
 
 			drawQuad(shader.paste, vertices, 3, texCoords, NULL, btexCoords);
-#if 0
+
 			// Copy Our ViewPort To The Texture
 			glUseProgram(0);
-#endif
+
 			copyTexSubImage2D(GL_TEXTURE_2D, 0, (int)((x < 0) ? xoffset : x + xoffset), (int)((y < 0) ? yoffset : y + yoffset), (int)((x < 0) ? viewportOffsetX - x : viewportOffsetX), (int)((y < 0) ? viewportOffsetY - y : viewportOffsetY), w, h, backdropTextureName);
 
 			yoffset += viewportHeight;
@@ -1494,19 +1495,21 @@ bool mixHSI(FILE *fp, int x, int y) {
 	}
 	deleteTextures(1, &tmpTex);
 	setPixelCoords(false);
+#endif
 	return true;
 }
 
-void saveCorePNG(FILE *writer, GLuint texture, int w, int h) {
-	GLint tw, th;
+void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 #if 0
+	GLint tw, th;
+
 	glBindTexture(GL_TEXTURE_2D, texture);
-#endif
+
 	getTextureDimensions(texture, &tw, &th);
 
 	GLubyte *image = new GLubyte [tw * th * 4];
 	if (! checkNew(image)) return;
-#if 0
+
 	glPixelStorei(GL_PACK_ALIGNMENT, 1);
 //	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
 #endif
@@ -1557,11 +1560,11 @@ void saveCorePNG(FILE *writer, GLuint texture, int w, int h) {
 
 #if 0
 			glUseProgram(shader.texture);
-#endif
+
 			setPMVMatrix(shader.texture);
 
 			drawQuad(shader.texture, vertices, 1, texCoords);
-#if 0
+
 			glUseProgram(0);
 
 			for (int i = 0; i < h; i++)   {
diff --git a/engines/sludge/backdrop.h b/engines/sludge/backdrop.h
index 5dd2014..8974f92 100644
--- a/engines/sludge/backdrop.h
+++ b/engines/sludge/backdrop.h
@@ -67,12 +67,12 @@ void mixBackDrop(int fileNum, int x, int y);
 void drawBackDrop();
 void blankScreen(int x1, int y1, int x2, int y2);
 void darkScreen();
+void saveHSI(Common::WriteStream *stream);
 #if 0
-void saveHSI(FILE *writer);
-void saveCoreHSI(FILE *writer, GLuint texture, int w, int h);
-bool loadHSI(FILE *fp, int, int, bool);
-bool mixHSI(FILE *fp, int x = 0, int y = 0);
+void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h);
 #endif
+bool loadHSI(Common::SeekableReadStream *stream, int, int, bool);
+bool mixHSI(Common::SeekableReadStream *stream, int x = 0, int y = 0);
 void drawHorizontalLine(unsigned int, unsigned int, unsigned int);
 void drawVerticalLine(unsigned int, unsigned int, unsigned int);
 void hardScroll(int distance);
@@ -91,17 +91,13 @@ extern texture lightMap;
 
 void killParallax();
 bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY);
-#if 0
-void saveParallaxRecursive(parallaxLayer *me, FILE *fp);
-#endif
+void saveParallaxRecursive(parallaxLayer *me, Common::WriteStream *fp);
 void reloadParallaxTextures();
 
 void nosnapshot();
 bool snapshot();
-#if ALLOW_FILE
-void saveSnapshot(FILE *fp);
-bool restoreSnapshot(FILE *fp);
-#endif
+void saveSnapshot(Common::WriteStream *stream);
+bool restoreSnapshot(Common::SeekableReadStream *stream);
 #endif
 
 } // End of namespace Sludge
diff --git a/engines/sludge/bg_effects.cpp b/engines/sludge/bg_effects.cpp
index 0a8550e..8a61551 100644
--- a/engines/sludge/bg_effects.cpp
+++ b/engines/sludge/bg_effects.cpp
@@ -28,6 +28,9 @@
 #include "newfatal.h"
 #include "moreio.h"
 
+#include "common/debug.h"
+#include "common/file.h"
+
 namespace Sludge {
 
 #if 0
@@ -113,22 +116,20 @@ static int *s_matrixEffectData = NULL;
 static int s_matrixEffectBase = 0;
 #endif
 
-#if ALLOW_FILE
-void blur_saveSettings(FILE *fp) {
+void blur_saveSettings(Common::WriteStream *stream) {
 	if (s_matrixEffectData) {
-		put4bytes(s_matrixEffectDivide, fp);
-		put4bytes(s_matrixEffectWidth, fp);
-		put4bytes(s_matrixEffectHeight, fp);
-		put4bytes(s_matrixEffectBase, fp);
-		fwrite(s_matrixEffectData, sizeof(int), s_matrixEffectWidth * s_matrixEffectHeight, fp);
+		put4bytes(s_matrixEffectDivide, stream);
+		put4bytes(s_matrixEffectWidth, stream);
+		put4bytes(s_matrixEffectHeight, stream);
+		put4bytes(s_matrixEffectBase, stream);
+		stream->write(s_matrixEffectData, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight);
 	} else {
-		put4bytes(0, fp);
-		put4bytes(0, fp);
-		put4bytes(0, fp);
-		put4bytes(0, fp);
+		put4bytes(0, stream);
+		put4bytes(0, stream);
+		put4bytes(0, stream);
+		put4bytes(0, stream);
 	}
 }
-#endif
 
 static int *blur_allocateMemoryForEffect() {
 	free(s_matrixEffectData);
@@ -141,23 +142,21 @@ static int *blur_allocateMemoryForEffect() {
 	return s_matrixEffectData;
 }
 
-#if ALLOW_FILE
-void blur_loadSettings(FILE *fp) {
-	s_matrixEffectDivide = get4bytes(fp);
-	s_matrixEffectWidth = get4bytes(fp);
-	s_matrixEffectHeight = get4bytes(fp);
-	s_matrixEffectBase = get4bytes(fp);
+void blur_loadSettings(Common::SeekableReadStream *stream) {
+	s_matrixEffectDivide = get4bytes(stream);
+	s_matrixEffectWidth = get4bytes(stream);
+	s_matrixEffectHeight = get4bytes(stream);
+	s_matrixEffectBase = get4bytes(stream);
 
 	if (blur_allocateMemoryForEffect()) {
-		size_t bytes_read = fread(s_matrixEffectData, sizeof(int), s_matrixEffectWidth * s_matrixEffectHeight, fp);
-		if (bytes_read != sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight && ferror(fp)) {
-			debugOut("Reading error in blur_loadSettings.\n");
+		size_t bytes_read = stream->read(s_matrixEffectData, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight);
+		if (bytes_read != sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight && stream->err()) {
+			debug("Reading error in blur_loadSettings.");
 		}
 	} else {
-		fseek(fp, sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight, SEEK_CUR);
+		stream->seek(sizeof(int) * s_matrixEffectWidth * s_matrixEffectHeight, SEEK_CUR);
 	}
 }
-#endif
 
 bool blur_createSettings(int numParams, variableStack *&stack) {
 	bool createNullThing = true;
diff --git a/engines/sludge/bg_effects.h b/engines/sludge/bg_effects.h
index d18fae6..b726ec7 100644
--- a/engines/sludge/bg_effects.h
+++ b/engines/sludge/bg_effects.h
@@ -23,13 +23,13 @@
 #ifndef SLUDGE_BG_EFFECTS_H
 #define SLUDGE_BG_EFFECTS_H
 
+#include "common/file.h"
+
 namespace Sludge {
 
 bool blurScreen();
-#if ALLOW_FILE
-void blur_saveSettings(FILE *fp);
-void blur_loadSettings(FILE *fp);
-#endif
+void blur_saveSettings(Common::WriteStream *stream);
+void blur_loadSettings(Common::SeekableReadStream *stream);
 bool blur_createSettings(int numParams, variableStack *&stack);
 
 } // End of namespace Sludge
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 6f2660d..5d5c0fa 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -99,11 +99,11 @@ extern unsigned int currentBlankColour;
 extern unsigned int languageID;
 extern unsigned char currentBurnR, currentBurnG, currentBurnB;
 
-int paramNum[] = { -1, 0, 1, 1, -1, -1, 1, 3, 4, 1, 0, 0, 8, -1,    // SAY -> MOVEMOUSE
-                   -1, 0, 0, -1, -1, 1, 1, 1, 1, 4, 1, 1, 2, 1,// FOCUS -> REMOVEREGION
-                   2, 2, 0, 0, 2,                              // ANIMATE -> SETSCALE
+int paramNum[] = { -1, 0, 1, 1, -1, -1, 1, 3, 4, 1, 0, 0, 8, -1,    // SAY->MOVEMOUSE
+                   -1, 0, 0, -1, -1, 1, 1, 1, 1, 4, 1, 1, 2, 1,// FOCUS->REMOVEREGION
+                   2, 2, 0, 0, 2,                              // ANIMATE->SETSCALE
                    -1, 2, 1, 0, 0, 0, 1, 0, 3,                 // new/push/pop stack, status stuff
-                   2, 0, 0, 3, 1, 0, 2,                        // delFromStack -> completeTimers
+                   2, 0, 0, 3, 1, 0, 2,                        // delFromStack->completeTimers
                    -1, -1, -1, 2, 2, 0, 3, 1,                  // anim, costume, pO, setC, wait, sS, substring, stringLength
                    0, 1, 1, 0, 2,                              // dark, save, load, quit, rename
                    1, 3, 3, 1, 2, 1, 1, 3, 1, 0, 0, 2, 1,      // stackSize, pasteString, startMusic, defvol, vol, stopmus, stopsound, setfont, alignStatus, show x 2, pos'Status, setFloor
@@ -166,20 +166,20 @@ static builtReturn sayCore(int numParams, loadedFunction *fun, bool sayIt) {
 
 	switch (numParams) {
 	case 3:
-		if (!getValueType(fileNum, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		if (!getValueType(fileNum, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 	// No break; here
 
 	case 2:
-		newText = getTextFromAnyVar(fun -> stack -> thisVar);
+		newText = getTextFromAnyVar(fun->stack->thisVar);
 		if (!newText) return BR_ERROR;
-		trimStack(fun -> stack);
-		if (!getValueType(objT, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		trimStack(fun->stack);
+		if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 		p = wrapSpeech(newText, objT, fileNum, sayIt);
-		fun -> timeLeft = p;
+		fun->timeLeft = p;
 		//debugOut ("BUILTIN: sayCore: %s (%i)\n", newText, p);
-		fun -> isSpeech = true;
+		fun->isSpeech = true;
 		delete newText;
 		newText = NULL;
 		return BR_KEEP_AND_PAUSE;
@@ -206,7 +206,7 @@ builtIn(freeze) {
 	UNUSEDALL
 	freeze();
 	freezeSubs();
-	fun -> freezerLevel = 0;
+	fun->freezerLevel = 0;
 	return BR_CONTINUE;
 }
 
@@ -219,63 +219,63 @@ builtIn(unfreeze) {
 
 builtIn(howFrozen) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, howFrozen());
+	setVariable(fun->reg, SVT_INT, howFrozen());
 	return BR_CONTINUE;
 }
 
 builtIn(setCursor) {
 	UNUSEDALL
-	personaAnimation *aa = getAnimationFromVar(fun -> stack -> thisVar);
+	personaAnimation *aa = getAnimationFromVar(fun->stack->thisVar);
 	pickAnimCursor(aa);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(getMouseX) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, input.mouseX + cameraX);
+	setVariable(fun->reg, SVT_INT, input.mouseX + cameraX);
 	return BR_CONTINUE;
 }
 
 builtIn(getMouseY) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, input.mouseY + cameraY);
+	setVariable(fun->reg, SVT_INT, input.mouseY + cameraY);
 	return BR_CONTINUE;
 }
 
 builtIn(getMouseScreenX) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, input.mouseX * cameraZoom);
+	setVariable(fun->reg, SVT_INT, input.mouseX * cameraZoom);
 	return BR_CONTINUE;
 }
 
 builtIn(getMouseScreenY) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, input.mouseY * cameraZoom);
+	setVariable(fun->reg, SVT_INT, input.mouseY * cameraZoom);
 	return BR_CONTINUE;
 }
 
 builtIn(getStatusText) {
 	UNUSEDALL
-	makeTextVar(fun -> reg, statusBarText());
+	makeTextVar(fun->reg, statusBarText());
 	return BR_CONTINUE;
 }
 
 builtIn(getMatchingFiles) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
 	if (!newText) return BR_ERROR;
-	trimStack(fun -> stack);
-	unlinkVar(fun -> reg);
+	trimStack(fun->stack);
+	unlinkVar(fun->reg);
 
 	// Return value
-	fun -> reg.varType = SVT_STACK;
-	fun -> reg.varData.theStack = new stackHandler;
-	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
-	fun -> reg.varData.theStack -> first = NULL;
-	fun -> reg.varData.theStack -> last = NULL;
-	fun -> reg.varData.theStack -> timesUsed = 1;
-	if (!getSavedGamesStack(fun -> reg.varData.theStack, newText)) return BR_ERROR;
+	fun->reg.varType = SVT_STACK;
+	fun->reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR;
+	fun->reg.varData.theStack->first = NULL;
+	fun->reg.varData.theStack->last = NULL;
+	fun->reg.varData.theStack->timesUsed = 1;
+	if (!getSavedGamesStack(fun->reg.varData.theStack, newText)) return BR_ERROR;
 	delete newText;
 	newText = NULL;
 	return BR_CONTINUE;
@@ -288,8 +288,8 @@ builtIn(saveGame) {
 		fatal("Can't save game state while the engine is frozen");
 	}
 
-	loadNow = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	loadNow = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 
 	char *aaaaa = encodeFilename(loadNow);
 	delete[] loadNow;
@@ -298,15 +298,15 @@ builtIn(saveGame) {
 	loadNow = joinStrings(":", aaaaa);
 	delete[] aaaaa;
 
-	setVariable(fun -> reg, SVT_INT, 0);
+	setVariable(fun->reg, SVT_INT, 0);
 	saverFunc = fun;
 	return BR_KEEP_AND_PAUSE;
 }
 
 builtIn(fileExists) {
 	UNUSEDALL
-	loadNow = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	loadNow = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	char *aaaaa = encodeFilename(loadNow);
 	delete loadNow;
 	if (failSecurityCheck(aaaaa)) return BR_ERROR;
@@ -328,7 +328,7 @@ builtIn(fileExists) {
 	}
 #endif
 	// Return value
-	setVariable(fun -> reg, SVT_INT, 0/*(fp != NULL)*/);//TODO:false value
+	setVariable(fun->reg, SVT_INT, 0/*(fp != NULL)*/);//TODO:false value
 #if 0
 	if (fp) fclose(fp);
 	delete[] aaaaa;
@@ -339,24 +339,23 @@ builtIn(fileExists) {
 
 builtIn(loadGame) {
 	UNUSEDALL
-	char *aaaaa = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	char *aaaaa = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	loadNow = encodeFilename(aaaaa);
 	delete aaaaa;
 
 	if (frozenStuff) {
 		fatal("Can't load a saved game while the engine is frozen");
 	}
-#if ALLOW_FILE
 	if (failSecurityCheck(loadNow)) return BR_ERROR;
-	FILE *fp = fopen(loadNow, "rb");
-	if (fp) {
-		fclose(fp);
+	Common::File fd;
+	if (fd.open(loadNow)) {
+		fd.close();
 		return BR_KEEP_AND_PAUSE;
 	}
 	delete loadNow;
 	loadNow = NULL;
-#endif
+
 	return BR_CONTINUE;
 }
 
@@ -373,14 +372,14 @@ builtIn(blankScreen) {
 builtIn(blankArea) {
 	UNUSEDALL
 	int x1, y1, x2, y2;
-	if (!getValueType(y2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(y1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y2, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x2, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(y1, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x1, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	blankScreen(x1, y1, x2, y2);
 	return BR_CONTINUE;
 }
@@ -394,12 +393,12 @@ builtIn(darkBackground) {
 builtIn(addOverlay) {
 	UNUSEDALL
 	int fileNumber, xPos, yPos;
-	if (!getValueType(yPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(xPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(yPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(xPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	loadBackDrop(fileNumber, xPos, yPos);
 	return BR_CONTINUE;
 }
@@ -407,12 +406,12 @@ builtIn(addOverlay) {
 builtIn(mixOverlay) {
 	UNUSEDALL
 	int fileNumber, xPos, yPos;
-	if (!getValueType(yPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(xPos, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(yPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(xPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	mixBackDrop(fileNumber, xPos, yPos);
 	return BR_CONTINUE;
 }
@@ -420,12 +419,12 @@ builtIn(mixOverlay) {
 builtIn(pasteImage) {
 	UNUSEDALL
 	int x, y;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	personaAnimation *pp = getAnimationFromVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	personaAnimation *pp = getAnimationFromVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	if (pp == NULL) return BR_CONTINUE;
 
 	pasteCursor(x, y, pp);
@@ -438,10 +437,10 @@ builtIn(pasteImage) {
 builtIn(setSceneDimensions) {
 	UNUSEDALL
 	int x, y;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (resizeBackdrop(x, y)) {
 		blankScreen(0, 0, x, y);
 		return BR_CONTINUE;
@@ -452,10 +451,10 @@ builtIn(setSceneDimensions) {
 
 builtIn(aimCamera) {
 	UNUSEDALL
-	if (!getValueType(cameraY, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(cameraX, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(cameraY, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(cameraX, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	cameraX -= (float)(winWidth >> 1) / cameraZoom;
 	cameraY -= (float)(winHeight >> 1) / cameraZoom;
@@ -471,8 +470,8 @@ builtIn(aimCamera) {
 builtIn(zoomCamera) {
 	UNUSEDALL
 	int z;
-	if (!getValueType(z, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(z, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	input.mouseX = input.mouseX * cameraZoom;
 	input.mouseY = input.mouseY * cameraZoom;
@@ -507,8 +506,8 @@ builtIn(pickOne) {
 
 	// Return value
 	while (numParams --) {
-		if (i == numParams) copyVariable(fun -> stack -> thisVar, fun -> reg);
-		trimStack(fun -> stack);
+		if (i == numParams) copyVariable(fun->stack->thisVar, fun->reg);
+		trimStack(fun->stack);
 	}
 	return BR_CONTINUE;
 }
@@ -521,12 +520,12 @@ builtIn(substring) {
 
 	//debugOut ("BUILTIN: substring\n");
 
-	if (!getValueType(length, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(start, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	wholeString = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	if (!getValueType(length, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(start, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	wholeString = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 
 	if (u8_strlen(wholeString) < start + length) {
 		length = u8_strlen(wholeString) - start;
@@ -549,37 +548,37 @@ builtIn(substring) {
 	memcpy(newString, wholeString + startoffset, endoffset - startoffset);
 	newString[endoffset - startoffset] = 0;
 
-	makeTextVar(fun -> reg, newString);
+	makeTextVar(fun->reg, newString);
 	delete newString;
 	return BR_CONTINUE;
 }
 
 builtIn(stringLength) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, stringLength(newText));
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, stringLength(newText));
 	delete[] newText;
 	return BR_CONTINUE;
 }
 
 builtIn(newStack) {
 	UNUSEDALL
-	unlinkVar(fun -> reg);
+	unlinkVar(fun->reg);
 
 	// Return value
-	fun -> reg.varType = SVT_STACK;
-	fun -> reg.varData.theStack = new stackHandler;
-	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
-	fun -> reg.varData.theStack -> first = NULL;
-	fun -> reg.varData.theStack -> last = NULL;
-	fun -> reg.varData.theStack -> timesUsed = 1;
+	fun->reg.varType = SVT_STACK;
+	fun->reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR;
+	fun->reg.varData.theStack->first = NULL;
+	fun->reg.varData.theStack->last = NULL;
+	fun->reg.varData.theStack->timesUsed = 1;
 	while (numParams --) {
-		if (!addVarToStack(fun -> stack -> thisVar, fun -> reg.varData.theStack -> first)) return BR_ERROR;
-		if (fun -> reg.varData.theStack -> last == NULL) {
-			fun -> reg.varData.theStack -> last = fun -> reg.varData.theStack -> first;
+		if (!addVarToStack(fun->stack->thisVar, fun->reg.varData.theStack->first)) return BR_ERROR;
+		if (fun->reg.varData.theStack->last == NULL) {
+			fun->reg.varData.theStack->last = fun->reg.varData.theStack->first;
 		}
-		trimStack(fun -> stack);
+		trimStack(fun->stack);
 	}
 	return BR_CONTINUE;
 }
@@ -589,17 +588,17 @@ builtIn(newStack) {
 
 builtIn(stackSize) {
 	UNUSEDALL
-	switch (fun -> stack -> thisVar.varType) {
+	switch (fun->stack->thisVar.varType) {
 	case SVT_STACK:
 		// Return value
-		setVariable(fun -> reg, SVT_INT, stackSize(fun -> stack -> thisVar.varData.theStack));
-		trimStack(fun -> stack);
+		setVariable(fun->reg, SVT_INT, stackSize(fun->stack->thisVar.varData.theStack));
+		trimStack(fun->stack);
 		return BR_CONTINUE;
 
 	case SVT_FASTARRAY:
 		// Return value
-		setVariable(fun -> reg, SVT_INT, fun -> stack -> thisVar.varData.fastArray -> size);
-		trimStack(fun -> stack);
+		setVariable(fun->reg, SVT_INT, fun->stack->thisVar.varData.fastArray->size);
+		trimStack(fun->stack);
 		return BR_CONTINUE;
 
 	default:
@@ -611,147 +610,147 @@ builtIn(stackSize) {
 
 builtIn(copyStack) {
 	UNUSEDALL
-	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack.");
 		return BR_ERROR;
 	}
 	// Return value
-	if (!copyStack(fun -> stack -> thisVar, fun -> reg)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!copyStack(fun->stack->thisVar, fun->reg)) return BR_ERROR;
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(pushToStack) {
 	UNUSEDALL
-	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->next->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack");
 		return BR_ERROR;
 	}
 
-	if (!addVarToStack(fun -> stack -> thisVar, fun -> stack -> next -> thisVar.varData.theStack -> first))
+	if (!addVarToStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->first))
 		return BR_ERROR;
 
-	if (fun -> stack -> next -> thisVar.varData.theStack -> first -> next == NULL)
-		fun -> stack -> next -> thisVar.varData.theStack -> last = fun -> stack -> next -> thisVar.varData.theStack -> first;
+	if (fun->stack->next->thisVar.varData.theStack->first->next == NULL)
+		fun->stack->next->thisVar.varData.theStack->last = fun->stack->next->thisVar.varData.theStack->first;
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(enqueue) {
 	UNUSEDALL
-	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->next->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack");
 		return BR_ERROR;
 	}
 
-	if (fun -> stack -> next -> thisVar.varData.theStack -> first == NULL) {
-		if (!addVarToStack(fun -> stack -> thisVar, fun -> stack -> next -> thisVar.varData.theStack -> first))
+	if (fun->stack->next->thisVar.varData.theStack->first == NULL) {
+		if (!addVarToStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->first))
 			return BR_ERROR;
 
-		fun -> stack -> next -> thisVar.varData.theStack -> last = fun -> stack -> next -> thisVar.varData.theStack -> first;
+		fun->stack->next->thisVar.varData.theStack->last = fun->stack->next->thisVar.varData.theStack->first;
 	} else {
-		if (!addVarToStack(fun -> stack -> thisVar,
-		                    fun -> stack -> next -> thisVar.varData.theStack -> last -> next))
+		if (!addVarToStack(fun->stack->thisVar,
+		                    fun->stack->next->thisVar.varData.theStack->last->next))
 			return BR_ERROR;
-		fun -> stack -> next -> thisVar.varData.theStack -> last = fun -> stack -> next -> thisVar.varData.theStack -> last -> next;
+		fun->stack->next->thisVar.varData.theStack->last = fun->stack->next->thisVar.varData.theStack->last->next;
 	}
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(deleteFromStack) {
 	UNUSEDALL
-	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->next->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack.");
 		return BR_ERROR;
 	}
 
 	// Return value
-	setVariable(fun -> reg, SVT_INT,
-	            deleteVarFromStack(fun -> stack -> thisVar,
-	                               fun -> stack -> next -> thisVar.varData.theStack -> first, false));
+	setVariable(fun->reg, SVT_INT,
+	            deleteVarFromStack(fun->stack->thisVar,
+	                               fun->stack->next->thisVar.varData.theStack->first, false));
 
 	// Horrible hacking because 'last' value might now be wrong!
 	fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first);
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(deleteAllFromStack) {
 	UNUSEDALL
-	if (fun -> stack -> next -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->next->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack.");
 		return BR_ERROR;
 	}
 
 	// Return value
-	setVariable(fun -> reg, SVT_INT,
-	            deleteVarFromStack(fun -> stack -> thisVar,
-	                               fun -> stack -> next -> thisVar.varData.theStack -> first, true));
+	setVariable(fun->reg, SVT_INT,
+	            deleteVarFromStack(fun->stack->thisVar,
+	                               fun->stack->next->thisVar.varData.theStack->first, true));
 
 	// Horrible hacking because 'last' value might now be wrong!
 	fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first);
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(popFromStack) {
 	UNUSEDALL
-	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack.");
 		return BR_ERROR;
 	}
-	if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+	if (fun->stack->thisVar.varData.theStack->first == NULL) {
 		fatal("The stack's empty.");
 		return BR_ERROR;
 	}
 
 	// Return value
-	copyVariable(fun -> stack -> thisVar.varData.theStack -> first -> thisVar, fun -> reg);
-	trimStack(fun -> stack -> thisVar.varData.theStack -> first);
-	trimStack(fun -> stack);
+	copyVariable(fun->stack->thisVar.varData.theStack->first->thisVar, fun->reg);
+	trimStack(fun->stack->thisVar.varData.theStack->first);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(peekStart) {
 	UNUSEDALL
-	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack.");
 		return BR_ERROR;
 	}
-	if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+	if (fun->stack->thisVar.varData.theStack->first == NULL) {
 		fatal("The stack's empty.");
 		return BR_ERROR;
 	}
 
 	// Return value
-	copyVariable(fun -> stack -> thisVar.varData.theStack -> first -> thisVar, fun -> reg);
-	trimStack(fun -> stack);
+	copyVariable(fun->stack->thisVar.varData.theStack->first->thisVar, fun->reg);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(peekEnd) {
 	UNUSEDALL
-	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->thisVar.varType != SVT_STACK) {
 		fatal("Parameter isn't a stack.");
 		return BR_ERROR;
 	}
-	if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+	if (fun->stack->thisVar.varData.theStack->first == NULL) {
 		fatal("The stack's empty.");
 		return BR_ERROR;
 	}
 
 	// Return value
-	copyVariable(fun -> stack -> thisVar.varData.theStack -> last -> thisVar, fun -> reg);
-	trimStack(fun -> stack);
+	copyVariable(fun->stack->thisVar.varData.theStack->last->thisVar, fun->reg);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
@@ -759,22 +758,22 @@ builtIn(random) {
 	UNUSEDALL
 	int num;
 
-	if (!getValueType(num, SVT_INT, fun -> stack -> thisVar))
+	if (!getValueType(num, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	if (num <= 0) num = 1;
-	setVariable(fun -> reg, SVT_INT, 0 /*rand() % num*/); //TODO:false value
+	setVariable(fun->reg, SVT_INT, 0 /*rand() % num*/); //TODO:false value
 	return BR_CONTINUE;
 }
 
 static bool getRGBParams(int &red, int &green, int &blue, loadedFunction *fun) {
-	if (!getValueType(blue, SVT_INT, fun -> stack -> thisVar)) return false;
-	trimStack(fun -> stack);
-	if (!getValueType(green, SVT_INT, fun -> stack -> thisVar)) return false;
-	trimStack(fun -> stack);
-	if (!getValueType(red, SVT_INT, fun -> stack -> thisVar)) return false;
-	trimStack(fun -> stack);
+	if (!getValueType(blue, SVT_INT, fun->stack->thisVar)) return false;
+	trimStack(fun->stack);
+	if (!getValueType(green, SVT_INT, fun->stack->thisVar)) return false;
+	trimStack(fun->stack);
+	if (!getValueType(red, SVT_INT, fun->stack->thisVar)) return false;
+	trimStack(fun->stack);
 	return true;
 }
 
@@ -819,7 +818,7 @@ builtIn(setBlankColour) {
 		return BR_ERROR;
 
 	currentBlankColour = makeColour(red & 255, green & 255, blue & 255);
-	setVariable(fun -> reg, SVT_INT, 1);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
@@ -833,7 +832,7 @@ builtIn(setBurnColour) {
 	currentBurnR = red;
 	currentBurnG = green;
 	currentBurnB = blue;
-	setVariable(fun -> reg, SVT_INT, 1);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
@@ -841,16 +840,16 @@ builtIn(setBurnColour) {
 builtIn(setFont) {
 	UNUSEDALL
 	int fileNumber, newHeight;
-	if (!getValueType(newHeight, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	if (!getValueType(newHeight, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
 	//              newDebug ("  Height:", newHeight);
-	trimStack(fun -> stack);
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	trimStack(fun->stack);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
 	if (!newText) return BR_ERROR;
 	//              newDebug ("  Character supported:", newText);
-	trimStack(fun -> stack);
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
 	//              newDebug ("  File:", fileNumber);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	if (!loadFont(fileNumber, newText, newHeight)) return BR_ERROR;
 	//              newDebug ("  Done!");
 	delete newText;
@@ -860,25 +859,25 @@ builtIn(setFont) {
 
 builtIn(inFont) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
 	if (!newText) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 
 	// Return value
 
-	setVariable(fun -> reg, SVT_INT, isInFont(newText));
+	setVariable(fun->reg, SVT_INT, isInFont(newText));
 	return BR_CONTINUE;
 }
 
 builtIn(pasteString) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	int y, x;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (x == IN_THE_CENTRE) x = (winWidth - stringWidth(newText)) >> 1;
 	fixFont(pastePalette);
 	pasteStringToBackdrop(newText, x, y, pastePalette);
@@ -894,12 +893,12 @@ builtIn(anim) {
 	}
 
 	// First store the frame numbers and take 'em off the stack
-	personaAnimation *ba = createPersonaAnim(numParams - 1, fun -> stack);
+	personaAnimation *ba = createPersonaAnim(numParams - 1, fun->stack);
 
 	// Only remaining paramter is the file number
 	int fileNumber;
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	// Load the required sprite bank
 	loadedSpriteBank *sprBanky = loadBankForAnim(fileNumber);
@@ -907,7 +906,7 @@ builtIn(anim) {
 	setBankFile(ba, sprBanky);
 
 	// Return value
-	newAnimationVariable(fun -> reg, ba);
+	newAnimationVariable(fun->reg, ba);
 
 	return BR_CONTINUE;
 }
@@ -916,32 +915,32 @@ builtIn(costume) {
 	UNUSEDALL
 	persona *newPersona = new persona;
 	if (!checkNew(newPersona)) return BR_ERROR;
-	newPersona -> numDirections = numParams / 3;
-	if (numParams == 0 || newPersona -> numDirections * 3 != numParams) {
+	newPersona->numDirections = numParams / 3;
+	if (numParams == 0 || newPersona->numDirections * 3 != numParams) {
 		fatal("Illegal number of parameters (should be greater than 0 and divisible by 3)");
 		return BR_ERROR;
 	}
 	int iii;
-	newPersona -> animation = new personaAnimation * [numParams];
-	if (!checkNew(newPersona -> animation)) return BR_ERROR;
+	newPersona->animation = new personaAnimation * [numParams];
+	if (!checkNew(newPersona->animation)) return BR_ERROR;
 	for (iii = numParams - 1; iii >= 0; iii --) {
-		newPersona -> animation[iii] = getAnimationFromVar(fun -> stack -> thisVar);
-		trimStack(fun -> stack);
+		newPersona->animation[iii] = getAnimationFromVar(fun->stack->thisVar);
+		trimStack(fun->stack);
 	}
 
 	// Return value
-	newCostumeVariable(fun -> reg, newPersona);
+	newCostumeVariable(fun->reg, newPersona);
 	return BR_CONTINUE;
 }
 
 builtIn(launch) {
 	UNUSEDALL
-	char *newTextA = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newTextA = getTextFromAnyVar(fun->stack->thisVar);
 	if (!newTextA) return BR_ERROR;
 
 	char *newText = encodeFilename(newTextA);
 
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	if (newTextA[0] == 'h' &&
 	        newTextA[1] == 't' &&
 	        newTextA[2] == 't' &&
@@ -963,7 +962,7 @@ builtIn(launch) {
 	}
 	delete newTextA;
 	setGraphicsWindow(false);
-	setVariable(fun -> reg, SVT_INT, 1);
+	setVariable(fun->reg, SVT_INT, 1);
 	launchResult = &fun->reg;
 
 	return BR_KEEP_AND_PAUSE;
@@ -972,11 +971,11 @@ builtIn(launch) {
 builtIn(pause) {
 	UNUSEDALL
 	int theTime;
-	if (!getValueType(theTime, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(theTime, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (theTime > 0) {
-		fun -> timeLeft = theTime - 1;
-		fun -> isSpeech = false;
+		fun->timeLeft = theTime - 1;
+		fun->isSpeech = false;
 		return BR_KEEP_AND_PAUSE;
 	}
 	return BR_CONTINUE;
@@ -991,19 +990,19 @@ builtIn(completeTimers) {
 builtIn(callEvent) {
 	UNUSEDALL
 	int obj1, obj2;
-	if (!getValueType(obj2, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj1, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(obj2, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj1, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	int fNum = getCombinationFunction(obj1, obj2);
 
 	// Return value
 	if (fNum) {
-		setVariable(fun -> reg, SVT_FUNC, fNum);
+		setVariable(fun->reg, SVT_FUNC, fNum);
 		return BR_CALLAFUNC;
 	}
-	setVariable(fun -> reg, SVT_INT, 0);
+	setVariable(fun->reg, SVT_INT, 0);
 	return BR_CONTINUE;
 }
 
@@ -1030,19 +1029,19 @@ builtIn(quitGame) {
 // The old movie functions are deprecated and does nothing.
 builtIn(_rem_movieStart) {
 	UNUSEDALL
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	return BR_CONTINUE;
 }
 
 builtIn(_rem_movieAbort) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, 0);
+	setVariable(fun->reg, SVT_INT, 0);
 	return BR_CONTINUE;
 }
 
 builtIn(_rem_moviePlaying) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, 0);
+	setVariable(fun->reg, SVT_INT, 0);
 	return BR_CONTINUE;
 }
 
@@ -1052,12 +1051,12 @@ builtIn(playMovie) {
 
 	if (movieIsPlaying) return BR_PAUSE;
 
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	r = playMovie(fileNumber);
 
-	setVariable(fun -> reg, SVT_INT, r);
+	setVariable(fun->reg, SVT_INT, r);
 
 	if (r && (!fun->next)) {
 		restartFunction(fun);
@@ -1072,7 +1071,7 @@ builtIn(stopMovie) {
 
 	r = stopMovie();
 
-	setVariable(fun -> reg, SVT_INT, 0);
+	setVariable(fun->reg, SVT_INT, 0);
 	return BR_CONTINUE;
 }
 
@@ -1082,7 +1081,7 @@ builtIn(pauseMovie) {
 
 	r = pauseMovie();
 
-	setVariable(fun -> reg, SVT_INT, 0);
+	setVariable(fun->reg, SVT_INT, 0);
 	return BR_CONTINUE;
 }
 
@@ -1093,12 +1092,12 @@ builtIn(pauseMovie) {
 builtIn(startMusic) {
 	UNUSEDALL
 	int fromTrack, musChan, fileNumber;
-	if (!getValueType(fromTrack, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(musChan, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(fromTrack, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(musChan, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (!playMOD(fileNumber, musChan, fromTrack)) return BR_CONTINUE;  //BR_ERROR;
 	return BR_CONTINUE;
 }
@@ -1106,8 +1105,8 @@ builtIn(startMusic) {
 builtIn(stopMusic) {
 	UNUSEDALL
 	int v;
-	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	stopMOD(v);
 	return BR_CONTINUE;
 }
@@ -1115,10 +1114,10 @@ builtIn(stopMusic) {
 builtIn(setMusicVolume) {
 	UNUSEDALL
 	int musChan, v;
-	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(musChan, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(musChan, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setMusicVolume(musChan, v);
 	return BR_CONTINUE;
 }
@@ -1126,8 +1125,8 @@ builtIn(setMusicVolume) {
 builtIn(setDefaultMusicVolume) {
 	UNUSEDALL
 	int v;
-	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setDefaultMusicVolume(v);
 	return BR_CONTINUE;
 }
@@ -1135,8 +1134,8 @@ builtIn(setDefaultMusicVolume) {
 builtIn(playSound) {
 	UNUSEDALL
 	int fileNumber;
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (!startSound(fileNumber, false)) return BR_CONTINUE;    // Was BR_ERROR
 	return BR_CONTINUE;
 }
@@ -1149,8 +1148,8 @@ builtIn(loopSound) {
 		return BR_ERROR;
 	} else if (numParams < 2) {
 
-		if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 		if (!startSound(fileNumber, true)) return BR_CONTINUE;     // Was BR_ERROR
 		return BR_CONTINUE;
 	} else {
@@ -1162,12 +1161,12 @@ builtIn(loopSound) {
 
 		// Should we loop?
 		if (fun->stack->thisVar.varType != SVT_FILE) {
-			getValueType(doLoop, SVT_INT, fun -> stack -> thisVar);
-			trimStack(fun -> stack);
+			getValueType(doLoop, SVT_INT, fun->stack->thisVar);
+			trimStack(fun->stack);
 			numParams--;
 		}
 		while (numParams) {
-			if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) {
+			if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) {
 				fatal("Illegal parameter given built-in function loopSound().");
 				return BR_ERROR;
 			}
@@ -1198,8 +1197,8 @@ builtIn(loopSound) {
 builtIn(stopSound) {
 	UNUSEDALL
 	int v;
-	if (!getValueType(v, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	huntKillSound(v);
 	return BR_CONTINUE;
 }
@@ -1207,8 +1206,8 @@ builtIn(stopSound) {
 builtIn(setDefaultSoundVolume) {
 	UNUSEDALL
 	int v;
-	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setDefaultSoundVolume(v);
 	return BR_CONTINUE;
 }
@@ -1216,10 +1215,10 @@ builtIn(setDefaultSoundVolume) {
 builtIn(setSoundVolume) {
 	UNUSEDALL
 	int musChan, v;
-	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(musChan, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setSoundVolume(musChan, v);
 	return BR_CONTINUE;
 }
@@ -1228,12 +1227,12 @@ builtIn(setSoundVolume) {
 builtIn(setSoundLoopPoints) {
 	UNUSEDALL
 	int musChan, theEnd, theStart;
-	if (!getValueType(theEnd, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(theStart, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(musChan, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(theEnd, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(theStart, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setSoundLoop(musChan, theStart, theEnd);
 	return BR_CONTINUE;
 }
@@ -1243,13 +1242,13 @@ builtIn(setSoundLoopPoints) {
 
 builtIn(setFloor) {
 	UNUSEDALL
-	if (fun -> stack -> thisVar.varType == SVT_FILE) {
+	if (fun->stack->thisVar.varType == SVT_FILE) {
 		int v;
-		getValueType(v, SVT_FILE, fun -> stack -> thisVar);
-		trimStack(fun -> stack);
+		getValueType(v, SVT_FILE, fun->stack->thisVar);
+		trimStack(fun->stack);
 		if (!setFloor(v)) return BR_ERROR;
 	} else {
-		trimStack(fun -> stack);
+		trimStack(fun->stack);
 		setFloorNull();
 	}
 	return BR_CONTINUE;
@@ -1263,13 +1262,13 @@ builtIn(showFloor) {
 
 builtIn(setZBuffer) {
 	UNUSEDALL
-	if (fun -> stack -> thisVar.varType == SVT_FILE) {
+	if (fun->stack->thisVar.varType == SVT_FILE) {
 		int v;
-		getValueType(v, SVT_FILE, fun -> stack -> thisVar);
-		trimStack(fun -> stack);
+		getValueType(v, SVT_FILE, fun->stack->thisVar);
+		trimStack(fun->stack);
 		if (!setZBuffer(v)) return BR_ERROR;
 	} else {
-		trimStack(fun -> stack);
+		trimStack(fun->stack);
 		killZBuffer();
 	}
 	return BR_CONTINUE;
@@ -1279,22 +1278,22 @@ builtIn(setLightMap) {
 	UNUSEDALL
 	switch (numParams) {
 	case 2:
-		if (!getValueType(lightMapMode, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		if (!getValueType(lightMapMode, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 		lightMapMode %= LIGHTMAPMODE_NUM;
 	// No break;
 
 	case 1:
-		if (fun -> stack -> thisVar.varType == SVT_FILE) {
+		if (fun->stack->thisVar.varType == SVT_FILE) {
 			int v;
-			getValueType(v, SVT_FILE, fun -> stack -> thisVar);
-			trimStack(fun -> stack);
+			getValueType(v, SVT_FILE, fun->stack->thisVar);
+			trimStack(fun->stack);
 			if (!loadLightMap(v)) return BR_ERROR;
-			setVariable(fun -> reg, SVT_INT, 1);
+			setVariable(fun->reg, SVT_INT, 1);
 		} else {
-			trimStack(fun -> stack);
+			trimStack(fun->stack);
 			killLightMap();
-			setVariable(fun -> reg, SVT_INT, 0);
+			setVariable(fun->reg, SVT_INT, 0);
 		}
 		break;
 
@@ -1311,8 +1310,8 @@ builtIn(setLightMap) {
 
 builtIn(setSpeechMode) {
 	UNUSEDALL
-	if (!getValueType(speechMode, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(speechMode, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (speechMode < 0 || speechMode > 2) {
 		fatal("Valid parameters are be SPEECHANDTEXT, SPEECHONLY or TEXTONLY");
 		return BR_ERROR;
@@ -1324,9 +1323,9 @@ builtIn(somethingSpeaking) {
 	UNUSEDALL
 	int i = isThereAnySpeechGoingOn();
 	if (i == -1) {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	} else {
-		setVariable(fun -> reg, SVT_OBJTYPE, i);
+		setVariable(fun->reg, SVT_OBJTYPE, i);
 	}
 	return BR_CONTINUE;
 }
@@ -1341,42 +1340,42 @@ builtIn(getOverObject) {
 	UNUSEDALL
 	if (overRegion)
 		// Return value
-		setVariable(fun -> reg, SVT_OBJTYPE, overRegion -> thisType -> objectNum);
+		setVariable(fun->reg, SVT_OBJTYPE, overRegion->thisType->objectNum);
 	else
 		// Return value
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	return BR_CONTINUE;
 }
 
 builtIn(rename) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
 	int objT;
 	if (!newText) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(objT, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	objectType *o = findObjectType(objT);
-	delete o -> screenName;
-	o -> screenName = newText;
+	delete o->screenName;
+	o->screenName = newText;
 	return BR_CONTINUE;
 }
 
 builtIn(getObjectX) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *pers = findPerson(objectNumber);
 	if (pers) {
-		setVariable(fun -> reg, SVT_INT, pers -> x);
+		setVariable(fun->reg, SVT_INT, pers->x);
 	} else {
 		screenRegion *la = getRegionForObject(objectNumber);
 		if (la) {
-			setVariable(fun -> reg, SVT_INT, la -> sX);
+			setVariable(fun->reg, SVT_INT, la->sX);
 		} else {
-			setVariable(fun -> reg, SVT_INT, 0);
+			setVariable(fun->reg, SVT_INT, 0);
 		}
 	}
 	return BR_CONTINUE;
@@ -1385,18 +1384,18 @@ builtIn(getObjectX) {
 builtIn(getObjectY) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *pers = findPerson(objectNumber);
 	if (pers) {
-		setVariable(fun -> reg, SVT_INT, pers -> y);
+		setVariable(fun->reg, SVT_INT, pers->y);
 	} else {
 		screenRegion *la = getRegionForObject(objectNumber);
 		if (la) {
-			setVariable(fun -> reg, SVT_INT, la -> sY);
+			setVariable(fun->reg, SVT_INT, la->sY);
 		} else {
-			setVariable(fun -> reg, SVT_INT, 0);
+			setVariable(fun->reg, SVT_INT, 0);
 		}
 	}
 	return BR_CONTINUE;
@@ -1406,22 +1405,22 @@ builtIn(getObjectY) {
 builtIn(addScreenRegion) {
 	UNUSEDALL
 	int sX, sY, x1, y1, x2, y2, di, objectNumber;
-	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(sY, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(sX, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(y2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(y1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(sY, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(sX, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(y2, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x2, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(y1, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x1, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (addScreenRegion(x1, y1, x2, y2, sX, sY, di, objectNumber)) return BR_CONTINUE;
 	return BR_ERROR;
 
@@ -1430,8 +1429,8 @@ builtIn(addScreenRegion) {
 builtIn(removeScreenRegion) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	removeScreenRegion(objectNumber);
 	return BR_CONTINUE;
 }
@@ -1453,16 +1452,16 @@ builtIn(addCharacter) {
 	persona *p;
 	int x, y, objectNumber;
 
-	p = getCostumeFromVar(fun -> stack -> thisVar);
+	p = getCostumeFromVar(fun->stack->thisVar);
 	if (p == NULL) return BR_ERROR;
 
-	trimStack(fun -> stack);
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (addPerson(x, y, objectNumber, p)) return BR_CONTINUE;
 	return BR_ERROR;
 }
@@ -1470,8 +1469,8 @@ builtIn(addCharacter) {
 builtIn(hideCharacter) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setShown(false, objectNumber);
 	return BR_CONTINUE;
 }
@@ -1479,8 +1478,8 @@ builtIn(hideCharacter) {
 builtIn(showCharacter) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setShown(true, objectNumber);
 	return BR_CONTINUE;
 }
@@ -1495,36 +1494,36 @@ builtIn(removeAllCharacters) {
 builtIn(setCharacterDrawMode) {
 	UNUSEDALL
 	int obj, di;
-	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setDrawMode(di, obj);
 	return BR_CONTINUE;
 }
 builtIn(setCharacterTransparency) {
 	UNUSEDALL
 	int obj, x;
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setPersonTransparency(obj, x);
 	return BR_CONTINUE;
 }
 builtIn(setCharacterColourise) {
 	UNUSEDALL
 	int obj, r, g, b, mix;
-	if (!getValueType(mix, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(b, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(g, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(r, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(mix, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(b, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(g, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(r, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setPersonColourise(obj, r, g, b, mix);
 	return BR_CONTINUE;
 }
@@ -1532,10 +1531,10 @@ builtIn(setCharacterColourise) {
 builtIn(setScale) {
 	UNUSEDALL
 	int val1, val2;
-	if (!getValueType(val2, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(val1, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(val2, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(val1, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setScale((short int) val1, (short int) val2);
 	return BR_CONTINUE;
 }
@@ -1543,35 +1542,35 @@ builtIn(setScale) {
 builtIn(stopCharacter) {
 	UNUSEDALL
 	int obj;
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	// Return value
-	setVariable(fun -> reg, SVT_INT, stopPerson(obj));
+	setVariable(fun->reg, SVT_INT, stopPerson(obj));
 	return BR_CONTINUE;
 }
 
 builtIn(pasteCharacter) {
 	UNUSEDALL
 	int obj;
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *thisPerson = findPerson(obj);
 	if (thisPerson) {
 		personaAnimation *myAnim;
-		myAnim = thisPerson -> myAnim;
-		if (myAnim != thisPerson -> lastUsedAnim) {
-			thisPerson -> lastUsedAnim = myAnim;
-			thisPerson -> frameNum = 0;
-			thisPerson -> frameTick = myAnim -> frames[0].howMany;
+		myAnim = thisPerson->myAnim;
+		if (myAnim != thisPerson->lastUsedAnim) {
+			thisPerson->lastUsedAnim = myAnim;
+			thisPerson->frameNum = 0;
+			thisPerson->frameTick = myAnim->frames[0].howMany;
 		}
 
-		int fNum = myAnim -> frames[thisPerson -> frameNum].frameNum;
-		fixScaleSprite(thisPerson -> x, thisPerson -> y, myAnim -> theSprites -> bank.sprites[abs(fNum)], myAnim -> theSprites -> bank.myPalette, thisPerson, 0, 0, fNum < 0);
-		setVariable(fun -> reg, SVT_INT, 1);
+		int fNum = myAnim->frames[thisPerson->frameNum].frameNum;
+		fixScaleSprite(thisPerson->x, thisPerson->y, myAnim->theSprites->bank.sprites[abs(fNum)], myAnim->theSprites->bank.myPalette, thisPerson, 0, 0, fNum < 0);
+		setVariable(fun->reg, SVT_INT, 1);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -1579,24 +1578,24 @@ builtIn(pasteCharacter) {
 builtIn(animate) {
 	UNUSEDALL
 	int obj;
-	personaAnimation *pp = getAnimationFromVar(fun -> stack -> thisVar);
+	personaAnimation *pp = getAnimationFromVar(fun->stack->thisVar);
 	if (pp == NULL) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	animatePerson(obj, pp);
-	setVariable(fun -> reg, SVT_INT, timeForAnim(pp));
+	setVariable(fun->reg, SVT_INT, timeForAnim(pp));
 	return BR_CONTINUE;
 }
 
 builtIn(setCostume) {
 	UNUSEDALL
 	int obj;
-	persona *pp = getCostumeFromVar(fun -> stack -> thisVar);
+	persona *pp = getCostumeFromVar(fun->stack->thisVar);
 	if (pp == NULL) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	animatePerson(obj, pp);
 	return BR_CONTINUE;
 }
@@ -1604,52 +1603,52 @@ builtIn(setCostume) {
 builtIn(floatCharacter) {
 	UNUSEDALL
 	int obj, di;
-	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, floatCharacter(di, obj));
+	if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, floatCharacter(di, obj));
 	return BR_CONTINUE;
 }
 
 builtIn(setCharacterWalkSpeed) {
 	UNUSEDALL
 	int obj, di;
-	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, setCharacterWalkSpeed(di, obj));
+	if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, setCharacterWalkSpeed(di, obj));
 	return BR_CONTINUE;
 }
 
 builtIn(turnCharacter) {
 	UNUSEDALL
 	int obj, di;
-	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, turnPersonToFace(obj, di));
+	if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, turnPersonToFace(obj, di));
 	return BR_CONTINUE;
 }
 
 builtIn(setCharacterExtra) {
 	UNUSEDALL
 	int obj, di;
-	if (!getValueType(di, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, setPersonExtra(obj, di));
+	if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, setPersonExtra(obj, di));
 	return BR_CONTINUE;
 }
 
 builtIn(removeCharacter) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	removeOneCharacter(objectNumber);
 	return BR_CONTINUE;
 }
@@ -1659,12 +1658,12 @@ static builtReturn moveChr(int numParams, loadedFunction *fun, bool force, bool
 	case 3: {
 		int x, y, objectNumber;
 
-		if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
-		if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
-		if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
+		if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
+		if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 
 		if (force) {
 			if (forceWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE;
@@ -1680,19 +1679,19 @@ static builtReturn moveChr(int numParams, loadedFunction *fun, bool force, bool
 		int toObj, objectNumber;
 		screenRegion *reggie;
 
-		if (!getValueType(toObj, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
-		if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		if (!getValueType(toObj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
+		if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 		reggie = getRegionForObject(toObj);
 		if (reggie == NULL) return BR_CONTINUE;
 
 		if (force) {
-			if (forceWalkingPerson(reggie -> sX, reggie -> sY, objectNumber, fun, reggie -> di)) return BR_PAUSE;
+			if (forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) return BR_PAUSE;
 		} else if (immediate) {
-			jumpPerson(reggie -> sX, reggie -> sY, objectNumber);
+			jumpPerson(reggie->sX, reggie->sY, objectNumber);
 		} else {
-			if (makeWalkingPerson(reggie -> sX, reggie -> sY, objectNumber, fun, reggie -> di)) return BR_PAUSE;
+			if (makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) return BR_PAUSE;
 		}
 		return BR_CONTINUE;
 	}
@@ -1738,9 +1737,9 @@ builtIn(addStatus) {
 
 builtIn(statusText) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
 	if (!newText) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	setStatusBar(newText);
 	delete newText;
 	return BR_CONTINUE;
@@ -1749,8 +1748,8 @@ builtIn(statusText) {
 builtIn(lightStatus) {
 	UNUSEDALL
 	int val;
-	if (!getValueType(val, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(val, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	setLitStatus(val);
 	return BR_CONTINUE;
 }
@@ -1758,10 +1757,10 @@ builtIn(lightStatus) {
 builtIn(positionStatus) {
 	UNUSEDALL
 	int x, y;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	positionStatus(x, y);
 	return BR_CONTINUE;
 }
@@ -1769,9 +1768,9 @@ builtIn(positionStatus) {
 builtIn(alignStatus) {
 	UNUSEDALL
 	int val;
-	if (!getValueType(val, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	nowStatus -> alignStatus = (short) val;
+	if (!getValueType(val, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	nowStatus->alignStatus = (short) val;
 	return BR_CONTINUE;
 }
 
@@ -1782,8 +1781,8 @@ static bool getFuncNumForCallback(int numParams, loadedFunction *fun, int &funct
 		break;
 
 	case 1:
-		if (!getValueType(functionNum, SVT_FUNC, fun -> stack -> thisVar)) return false;
-		trimStack(fun -> stack);
+		if (!getValueType(functionNum, SVT_FUNC, fun->stack->thisVar)) return false;
+		trimStack(fun->stack);
 		break;
 
 	default:
@@ -1797,7 +1796,7 @@ builtIn(onLeftMouse) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> leftMouseFunction = functionNum;
+		currentEvents->leftMouseFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1807,7 +1806,7 @@ builtIn(onLeftMouseUp) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> leftMouseUpFunction = functionNum;
+		currentEvents->leftMouseUpFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1817,7 +1816,7 @@ builtIn(onRightMouse) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> rightMouseFunction = functionNum;
+		currentEvents->rightMouseFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1827,7 +1826,7 @@ builtIn(onRightMouseUp) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> rightMouseUpFunction = functionNum;
+		currentEvents->rightMouseUpFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1837,7 +1836,7 @@ builtIn(onFocusChange) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> focusFunction = functionNum;
+		currentEvents->focusFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1847,7 +1846,7 @@ builtIn(onMoveMouse) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> moveMouseFunction = functionNum;
+		currentEvents->moveMouseFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1857,7 +1856,7 @@ builtIn(onKeyboard) {
 	UNUSEDALL
 	int functionNum;
 	if (getFuncNumForCallback(numParams, fun, functionNum)) {
-		currentEvents -> spaceFunction = functionNum;
+		currentEvents->spaceFunction = functionNum;
 		return BR_CONTINUE;
 	}
 	return BR_ERROR;
@@ -1890,12 +1889,12 @@ builtIn(cancelSub) {
 
 builtIn(stringWidth) {
 	UNUSEDALL
-	char *theText = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *theText = getTextFromAnyVar(fun->stack->thisVar);
 	if (!theText) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 
 	// Return value
-	setVariable(fun -> reg, SVT_INT, stringWidth(theText));
+	setVariable(fun->reg, SVT_INT, stringWidth(theText));
 	delete theText;
 	return BR_CONTINUE;
 }
@@ -1903,8 +1902,8 @@ builtIn(stringWidth) {
 builtIn(hardScroll) {
 	UNUSEDALL
 	int v;
-	if (!getValueType(v, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	hardScroll(v);
 	return BR_CONTINUE;
 }
@@ -1913,37 +1912,37 @@ builtIn(hardScroll) {
 builtIn(isScreenRegion) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, getRegionForObject(objectNumber) != NULL);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, getRegionForObject(objectNumber) != NULL);
 	return BR_CONTINUE;
 }
 
 builtIn(setSpeechSpeed) {
 	UNUSEDALL
 	int number;
-	if (!getValueType(number, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	speechSpeed = number * 0.01;
-	setVariable(fun -> reg, SVT_INT, 1);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
 builtIn(setFontSpacing) {
 	UNUSEDALL
 	int fontSpaceI;
-	if (!getValueType(fontSpaceI, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	if (!getValueType(fontSpaceI, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
 	fontSpace = fontSpaceI;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, 1);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
 builtIn(transitionLevel) {
 	UNUSEDALL
 	int number;
-	if (!getValueType(number, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	if (number < 0)
 		brightnessLevel = 0;
@@ -1952,15 +1951,15 @@ builtIn(transitionLevel) {
 	else
 		brightnessLevel = number;
 
-	setVariable(fun -> reg, SVT_INT, 1);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
 builtIn(captureAllKeys) {
 	UNUSEDALL
-	captureAllKeys = getBoolean(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, captureAllKeys);
+	captureAllKeys = getBoolean(fun->stack->thisVar);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, captureAllKeys);
 	return BR_CONTINUE;
 }
 
@@ -1968,20 +1967,20 @@ builtIn(captureAllKeys) {
 builtIn(spinCharacter) {
 	UNUSEDALL
 	int number, objectNumber;
-	if (!getValueType(number, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *thisPerson = findPerson(objectNumber);
 	if (thisPerson) {
-		thisPerson -> wantAngle = number;
-		thisPerson -> spinning = true;
-		thisPerson -> continueAfterWalking = fun;
-		setVariable(fun -> reg, SVT_INT, 1);
+		thisPerson->wantAngle = number;
+		thisPerson->spinning = true;
+		thisPerson->continueAfterWalking = fun;
+		setVariable(fun->reg, SVT_INT, 1);
 		return BR_PAUSE;
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 		return BR_CONTINUE;
 	}
 }
@@ -1989,13 +1988,13 @@ builtIn(spinCharacter) {
 builtIn(getCharacterDirection) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	onScreenPerson *thisPerson = findPerson(objectNumber);
 	if (thisPerson) {
-		setVariable(fun -> reg, SVT_INT, thisPerson -> direction);
+		setVariable(fun->reg, SVT_INT, thisPerson->direction);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -2003,24 +2002,24 @@ builtIn(getCharacterDirection) {
 builtIn(isCharacter) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	onScreenPerson *thisPerson = findPerson(objectNumber);
-	setVariable(fun -> reg, SVT_INT, thisPerson != NULL);
+	setVariable(fun->reg, SVT_INT, thisPerson != NULL);
 	return BR_CONTINUE;
 }
 
 builtIn(normalCharacter) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	onScreenPerson *thisPerson = findPerson(objectNumber);
 	if (thisPerson) {
-		thisPerson -> myAnim = thisPerson -> myPersona -> animation[thisPerson -> direction];
-		setVariable(fun -> reg, SVT_INT, 1);
+		thisPerson->myAnim = thisPerson->myPersona->animation[thisPerson->direction];
+		setVariable(fun->reg, SVT_INT, 1);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -2028,13 +2027,13 @@ builtIn(normalCharacter) {
 builtIn(isMoving) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	onScreenPerson *thisPerson = findPerson(objectNumber);
 	if (thisPerson) {
-		setVariable(fun -> reg, SVT_INT, thisPerson -> walking);
+		setVariable(fun->reg, SVT_INT, thisPerson->walking);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -2042,18 +2041,18 @@ builtIn(isMoving) {
 builtIn(fetchEvent) {
 	UNUSEDALL
 	int obj1, obj2;
-	if (!getValueType(obj2, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(obj1, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(obj2, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(obj1, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	int fNum = getCombinationFunction(obj1, obj2);
 
 	// Return value
 	if (fNum) {
-		setVariable(fun -> reg, SVT_FUNC, fNum);
+		setVariable(fun->reg, SVT_FUNC, fNum);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -2061,12 +2060,12 @@ builtIn(fetchEvent) {
 builtIn(deleteFile) {
 	UNUSEDALL
 
-	char *namNormal = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	char *namNormal = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	char *nam = encodeFilename(namNormal);
 	delete namNormal;
 	if (failSecurityCheck(nam)) return BR_ERROR;
-	setVariable(fun -> reg, SVT_INT, remove(nam));
+	setVariable(fun->reg, SVT_INT, remove(nam));
 	delete nam;
 
 	return BR_CONTINUE;
@@ -2076,19 +2075,19 @@ builtIn(renameFile) {
 	UNUSEDALL
 	char *temp;
 
-	temp = getTextFromAnyVar(fun -> stack -> thisVar);
+	temp = getTextFromAnyVar(fun->stack->thisVar);
 	char *newnam = encodeFilename(temp);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	if (failSecurityCheck(newnam)) return BR_ERROR;
 	delete temp;
 
-	temp = getTextFromAnyVar(fun -> stack -> thisVar);
+	temp = getTextFromAnyVar(fun->stack->thisVar);
 	char *nam = encodeFilename(temp);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	if (failSecurityCheck(nam)) return BR_ERROR;
 	delete temp;
 
-	setVariable(fun -> reg, SVT_INT, rename(nam, newnam));
+	setVariable(fun->reg, SVT_INT, rename(nam, newnam));
 	delete nam;
 	delete newnam;
 
@@ -2099,21 +2098,21 @@ builtIn(renameFile) {
 builtIn(cacheSound) {
 	UNUSEDALL
 	int fileNumber;
-	if (!getValueType(fileNumber, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (cacheSound(fileNumber) == -1) return BR_ERROR;
 	return BR_CONTINUE;
 }
 
 builtIn(burnString) {
 	UNUSEDALL
-	char *newText = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	char *newText = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	int y, x;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (x == IN_THE_CENTRE) x = (winWidth - stringWidth(newText)) >> 1;
 	fixFont(pastePalette);
 	burnStringToBackdrop(newText, x, y, pastePalette);
@@ -2124,18 +2123,18 @@ builtIn(burnString) {
 builtIn(setCharacterSpinSpeed) {
 	UNUSEDALL
 	int speed, who;
-	if (!getValueType(speed, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(who, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(speed, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(who, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *thisPerson = findPerson(who);
 
 	if (thisPerson) {
-		thisPerson -> spinSpeed = speed;
-		setVariable(fun -> reg, SVT_INT, 1);
+		thisPerson->spinSpeed = speed;
+		setVariable(fun->reg, SVT_INT, 1);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -2143,18 +2142,18 @@ builtIn(setCharacterSpinSpeed) {
 builtIn(setCharacterAngleOffset) {
 	UNUSEDALL
 	int angle, who;
-	if (!getValueType(angle, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(who, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(angle, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(who, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *thisPerson = findPerson(who);
 
 	if (thisPerson) {
-		thisPerson -> angleOffset = angle;
-		setVariable(fun -> reg, SVT_INT, 1);
+		thisPerson->angleOffset = angle;
+		setVariable(fun->reg, SVT_INT, 1);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
@@ -2163,10 +2162,10 @@ builtIn(setCharacterAngleOffset) {
 builtIn(transitionMode) {
 	UNUSEDALL
 	int n;
-	if (!getValueType(n, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	if (!getValueType(n, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
 	fadeMode = n;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, 1);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
@@ -2174,41 +2173,41 @@ builtIn(transitionMode) {
 // Removed function - does nothing
 builtIn(_rem_updateDisplay) {
 	UNUSEDALL
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, true);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, true);
 	return BR_CONTINUE;
 }
 
 builtIn(getSoundCache) {
 	UNUSEDALL
-	fun -> reg.varType = SVT_STACK;
-	fun -> reg.varData.theStack = new stackHandler;
-	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
-	fun -> reg.varData.theStack -> first = NULL;
-	fun -> reg.varData.theStack -> last = NULL;
-	fun -> reg.varData.theStack -> timesUsed = 1;
-	if (!getSoundCacheStack(fun -> reg.varData.theStack)) return BR_ERROR;
+	fun->reg.varType = SVT_STACK;
+	fun->reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR;
+	fun->reg.varData.theStack->first = NULL;
+	fun->reg.varData.theStack->last = NULL;
+	fun->reg.varData.theStack->timesUsed = 1;
+	if (!getSoundCacheStack(fun->reg.varData.theStack)) return BR_ERROR;
 	return BR_CONTINUE;
 }
 
 builtIn(saveCustomData) {
 	UNUSEDALL
 	// saveCustomData (thisStack, fileName);
-	char *fileNameB = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *fileNameB = getTextFromAnyVar(fun->stack->thisVar);
 	if (!checkNew(fileNameB)) return BR_ERROR;
 
 	char *fileName = encodeFilename(fileNameB);
 	delete fileNameB;
 
 	if (failSecurityCheck(fileName)) return BR_ERROR;
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 
-	if (fun -> stack -> thisVar.varType != SVT_STACK) {
+	if (fun->stack->thisVar.varType != SVT_STACK) {
 		fatal("First parameter isn't a stack");
 		return BR_ERROR;
 	}
-	if (!stackToFile(fileName, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!stackToFile(fileName, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	delete fileName;
 	return BR_CONTINUE;
 }
@@ -2216,23 +2215,23 @@ builtIn(saveCustomData) {
 builtIn(loadCustomData) {
 	UNUSEDALL
 
-	char *newTextA = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *newTextA = getTextFromAnyVar(fun->stack->thisVar);
 	if (!checkNew(newTextA)) return BR_ERROR;
 
 	char *newText = encodeFilename(newTextA);
 	delete newTextA;
 
 	if (failSecurityCheck(newText)) return BR_ERROR;
-	trimStack(fun -> stack);
-
-	unlinkVar(fun -> reg);
-	fun -> reg.varType = SVT_STACK;
-	fun -> reg.varData.theStack = new stackHandler;
-	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
-	fun -> reg.varData.theStack -> first = NULL;
-	fun -> reg.varData.theStack -> last = NULL;
-	fun -> reg.varData.theStack -> timesUsed = 1;
-	if (!fileToStack(newText, fun -> reg.varData.theStack)) return BR_ERROR;
+	trimStack(fun->stack);
+
+	unlinkVar(fun->reg);
+	fun->reg.varType = SVT_STACK;
+	fun->reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR;
+	fun->reg.varData.theStack->first = NULL;
+	fun->reg.varData.theStack->last = NULL;
+	fun->reg.varData.theStack->timesUsed = 1;
+	if (!fileToStack(newText, fun->reg.varData.theStack)) return BR_ERROR;
 	delete newText;
 	return BR_CONTINUE;
 }
@@ -2240,18 +2239,18 @@ builtIn(loadCustomData) {
 builtIn(setCustomEncoding) {
 	UNUSEDALL
 	int n;
-	if (!getValueType(n, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
+	if (!getValueType(n, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
 	saveEncoding = n;
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, 1);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
 builtIn(freeSound) {
 	UNUSEDALL
 	int v;
-	if (!getValueType(v, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	huntKillFreeSound(v);
 	return BR_CONTINUE;
 }
@@ -2263,15 +2262,15 @@ builtIn(parallaxAdd) {
 		return BR_ERROR;
 	} else {
 		int wrapX, wrapY, v;
-		if (!getValueType(wrapY, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
-		if (!getValueType(wrapX, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
-		if (!getValueType(v, SVT_FILE, fun -> stack -> thisVar)) return BR_ERROR;
-		trimStack(fun -> stack);
+		if (!getValueType(wrapY, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
+		if (!getValueType(wrapX, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
+		if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) return BR_ERROR;
+		trimStack(fun->stack);
 
 		if (!loadParallax(v, wrapX, wrapY)) return BR_ERROR;
-		setVariable(fun -> reg, SVT_INT, 1);
+		setVariable(fun->reg, SVT_INT, 1);
 	}
 	return BR_CONTINUE;
 }
@@ -2279,44 +2278,44 @@ builtIn(parallaxAdd) {
 builtIn(parallaxClear) {
 	UNUSEDALL
 	killParallax();
-	setVariable(fun -> reg, SVT_INT, 1);
+	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
 }
 
 builtIn(getPixelColour) {
 	UNUSEDALL
 	int x, y;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
-	unlinkVar(fun -> reg);
-	fun -> reg.varType = SVT_STACK;
-	fun -> reg.varData.theStack = new stackHandler;
-	if (!checkNew(fun -> reg.varData.theStack)) return BR_ERROR;
-	fun -> reg.varData.theStack -> first = NULL;
-	fun -> reg.varData.theStack -> last = NULL;
-	fun -> reg.varData.theStack -> timesUsed = 1;
-	if (!getRGBIntoStack(x, y, fun -> reg.varData.theStack)) return BR_ERROR;
+	unlinkVar(fun->reg);
+	fun->reg.varType = SVT_STACK;
+	fun->reg.varData.theStack = new stackHandler;
+	if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR;
+	fun->reg.varData.theStack->first = NULL;
+	fun->reg.varData.theStack->last = NULL;
+	fun->reg.varData.theStack->timesUsed = 1;
+	if (!getRGBIntoStack(x, y, fun->reg.varData.theStack)) return BR_ERROR;
 
 	return BR_CONTINUE;
 }
 
 builtIn(makeFastArray) {
 	UNUSEDALL
-	switch (fun -> stack -> thisVar.varType) {
+	switch (fun->stack->thisVar.varType) {
 	case SVT_STACK: {
-		bool success = makeFastArrayFromStack(fun -> reg, fun -> stack -> thisVar.varData.theStack);
-		trimStack(fun -> stack);
+		bool success = makeFastArrayFromStack(fun->reg, fun->stack->thisVar.varData.theStack);
+		trimStack(fun->stack);
 		return success ? BR_CONTINUE : BR_ERROR;
 	}
 	break;
 
 	case SVT_INT: {
-		int i = fun -> stack -> thisVar.varData.intValue;
-		trimStack(fun -> stack);
-		return makeFastArraySize(fun -> reg, i) ? BR_CONTINUE : BR_ERROR;
+		int i = fun->stack->thisVar.varData.intValue;
+		trimStack(fun->stack);
+		return makeFastArraySize(fun->reg, i) ? BR_CONTINUE : BR_ERROR;
 	}
 	break;
 
@@ -2330,21 +2329,21 @@ builtIn(makeFastArray) {
 builtIn(getCharacterScale) {
 	UNUSEDALL
 	int objectNumber;
-	if (!getValueType(objectNumber, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	onScreenPerson *pers = findPerson(objectNumber);
 	if (pers) {
-		setVariable(fun -> reg, SVT_INT, pers -> scale * 100);
+		setVariable(fun->reg, SVT_INT, pers->scale * 100);
 	} else {
-		setVariable(fun -> reg, SVT_INT, 0);
+		setVariable(fun->reg, SVT_INT, 0);
 	}
 	return BR_CONTINUE;
 }
 
 builtIn(getLanguageID) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, gameSettings.languageID);
+	setVariable(fun->reg, SVT_INT, gameSettings.languageID);
 	return BR_CONTINUE;
 }
 
@@ -2352,9 +2351,9 @@ builtIn(getLanguageID) {
 builtIn(_rem_launchWith) {
 	UNUSEDALL
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, false);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, false);
 
 	return BR_CONTINUE;
 
@@ -2362,22 +2361,22 @@ builtIn(_rem_launchWith) {
 
 builtIn(getFramesPerSecond) {
 	UNUSEDALL
-	setVariable(fun -> reg, SVT_INT, lastFramesPerSecond);
+	setVariable(fun->reg, SVT_INT, lastFramesPerSecond);
 	return BR_CONTINUE;
 }
 
 builtIn(showThumbnail) {
 	UNUSEDALL
 	int x, y;
-	if (!getValueType(y, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(x, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 
 	// Encode the name!Encode the name!
-	char *aaaaa = getTextFromAnyVar(fun -> stack -> thisVar);
+	char *aaaaa = getTextFromAnyVar(fun->stack->thisVar);
 	//              deb ("Got name:", aaaaa;)
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
 	//              deb ("About to encode", aaaaa);
 	char *file = encodeFilename(aaaaa);
 	//              deb ("Made new name", file);
@@ -2391,10 +2390,10 @@ builtIn(showThumbnail) {
 
 builtIn(setThumbnailSize) {
 	UNUSEDALL
-	if (!getValueType(thumbHeight, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(thumbWidth, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(thumbHeight, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(thumbWidth, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	if (thumbWidth < 0 || thumbHeight < 0 || thumbWidth > winWidth || thumbHeight > winHeight) {
 		char buff[50];
 		sprintf(buff, "%d x %d", thumbWidth, thumbHeight);
@@ -2407,13 +2406,13 @@ builtIn(setThumbnailSize) {
 builtIn(hasFlag) {
 	UNUSEDALL
 	int objNum, flagIndex;
-	if (!getValueType(flagIndex, SVT_INT, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
-	if (!getValueType(objNum, SVT_OBJTYPE, fun -> stack -> thisVar)) return BR_ERROR;
-	trimStack(fun -> stack);
+	if (!getValueType(flagIndex, SVT_INT, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
+	if (!getValueType(objNum, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR;
+	trimStack(fun->stack);
 	objectType *objT = findObjectType(objNum);
 	if (!objT) return BR_ERROR;
-	setVariable(fun -> reg, SVT_INT, objT->flags & (1 << flagIndex));
+	setVariable(fun->reg, SVT_INT, objT->flags & (1 << flagIndex));
 	return BR_CONTINUE;
 }
 
@@ -2431,26 +2430,26 @@ builtIn(snapshotClear) {
 builtIn(bodgeFilenames) {
 	UNUSEDALL
 	bool lastValue = allowAnyFilename;
-	allowAnyFilename = getBoolean(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, lastValue);
+	allowAnyFilename = getBoolean(fun->stack->thisVar);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, lastValue);
 	return BR_CONTINUE;
 }
 
 // Deprecated - does nothing.
 builtIn(_rem_registryGetString) {
 	UNUSEDALL
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
-	setVariable(fun -> reg, SVT_INT, 0);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
+	setVariable(fun->reg, SVT_INT, 0);
 
 	return BR_CONTINUE;
 }
 
 builtIn(quitWithFatalError) {
 	UNUSEDALL
-	char *mess = getTextFromAnyVar(fun -> stack -> thisVar);
-	trimStack(fun -> stack);
+	char *mess = getTextFromAnyVar(fun->stack->thisVar);
+	trimStack(fun->stack);
 	fatal(mess);
 	return BR_ERROR;
 }
@@ -2458,10 +2457,10 @@ builtIn(quitWithFatalError) {
 builtIn(_rem_setCharacterAA) {
 	UNUSEDALL
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
 
 	return BR_CONTINUE;
 }
@@ -2469,9 +2468,9 @@ builtIn(_rem_setCharacterAA) {
 builtIn(_rem_setMaximumAA) {
 	UNUSEDALL
 
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
-	trimStack(fun -> stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
+	trimStack(fun->stack);
 
 	return BR_CONTINUE;
 
@@ -2480,14 +2479,14 @@ builtIn(_rem_setMaximumAA) {
 builtIn(setBackgroundEffect) {
 	UNUSEDALL
 	bool done = blur_createSettings(numParams, fun->stack);
-	setVariable(fun -> reg, SVT_INT, done ? 1 : 0);
+	setVariable(fun->reg, SVT_INT, done ? 1 : 0);
 	return BR_CONTINUE;
 }
 
 builtIn(doBackgroundEffect) {
 	UNUSEDALL
 	bool done = blurScreen();
-	setVariable(fun -> reg, SVT_INT, done ? 1 : 0);
+	setVariable(fun->reg, SVT_INT, done ? 1 : 0);
 	return BR_CONTINUE;
 }
 
@@ -2516,11 +2515,11 @@ builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun) {
 	// fprintf (stderr, "Calling function %d: %s\n", whichFunc, builtInFunctionNames[whichFunc]);    fflush (stderr);
 	if (numBIFNames) {
 
-		//      deb ("IN:", (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function");
+		//      deb ("IN:", (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function");
 		//      deb ("GO:", (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function");
 
 		setFatalInfo(
-		    (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function",
+		    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
 		    (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function");
 	}
 
diff --git a/engines/sludge/detection.cpp b/engines/sludge/detection.cpp
index 8297165..7e5c124 100644
--- a/engines/sludge/detection.cpp
+++ b/engines/sludge/detection.cpp
@@ -43,6 +43,8 @@ Common::Language SludgeEngine::getLanguage() const { return _gameDescription->de
 static const PlainGameDescriptor sludgeGames[] = {
 	{ "sludge", "Sludge Game" },
 	{ "welcome", "Welcome Example" },
+	{ "welcome2", "Welcome Example 2" },
+	{ "verbcoin", "Verb Coin" },
 	{ 0, 0 }
 };
  
@@ -61,6 +63,32 @@ static const SludgeGameDescription gameDescriptions[] = {
 		0
 	},
 
+	{
+		{
+			"welcome2",
+			"",
+			AD_ENTRY1("Welcome.slg", "cb1f307c05b8ae4107bcc7f86a3d2f99"),
+			Common::EN_ANY,
+			Common::kPlatformUnknown,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		0
+	},
+
+	{
+		{
+			"verbcoin",
+			"",
+			AD_ENTRY1("Welcome.slg", "e39ec315dcbf3a1137481f0a5fe1617d"),
+			Common::EN_ANY,
+			Common::kPlatformUnknown,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		0
+	},
+
 	{ AD_TABLE_END_MARKER, 0 }
 };
 
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index 852fd70..3c653f4 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -29,18 +29,19 @@
 
 #include "debug.h"
 #include "stringy.h"
-
 #include "allfiles.h"
 #include "moreio.h"
 #include "newfatal.h"
 #include "CommonCode/version.h"
 
+#include "common/file.h"
+
 namespace Sludge {
 
 bool sliceBusy = true;
-#if ALLOW_FILE
-FILE *bigDataFile = NULL;
-#endif
+
+Common::File *bigDataFile = NULL;
+
 uint32_t startOfDataIndex, startOfTextIndex,
          startOfSubIndex, startOfObjectIndex;
 
@@ -54,8 +55,8 @@ bool openSubSlice(int num) {
 		return false;
 	}
 //	fprintf (dbug, "Going to position %li\n", startOfSubIndex + (num << 2));
-	fseek(bigDataFile, startOfSubIndex + (num << 2), 0);
-	fseek(bigDataFile, get4bytes(bigDataFile), 0);
+	bigDataFile->seek(startOfSubIndex + (num << 2), 0);
+	bigDataFile->seek(get4bytes(bigDataFile), 0);
 //	fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile));
 //	fclose (dbug);
 
@@ -73,8 +74,8 @@ bool openObjectSlice(int num) {
 	}
 
 //	fprintf (dbug, "Going to position %li\n", startOfObjectIndex + (num << 2));
-	fseek(bigDataFile, startOfObjectIndex + (num << 2), 0);
-	fseek(bigDataFile, get4bytes(bigDataFile), 0);
+	bigDataFile->seek(startOfObjectIndex + (num << 2), 0);
+	bigDataFile->seek(get4bytes(bigDataFile), 0);
 //	fprintf (dbug, "Told to skip forward to %li\n", ftell (bigDataFile));
 //	fclose (dbug);
 	return sliceBusy = true;
@@ -90,8 +91,8 @@ unsigned int openFileFromNum(int num) {
 
 //	fprintf (dbug, "\nTrying to open file %i\n", num);
 //	fprintf (dbug, "Jumping to %li (for index) \n", startOfDataIndex + (num << 2));
-	fseek(bigDataFile, startOfDataIndex + (num << 2), 0);
-	fseek(bigDataFile, get4bytes(bigDataFile), 1);
+	bigDataFile->seek(startOfDataIndex + (num << 2), 0);
+	bigDataFile->seek(get4bytes(bigDataFile), 1);
 //	fprintf (dbug, "Jumping to %li (for data) \n", ftell (bigDataFile));
 	sliceBusy = true;
 //	fclose (dbug);
@@ -103,6 +104,7 @@ unsigned int openFileFromNum(int num) {
 // Converts a string from Windows CP-1252 to UTF-8.
 // This is needed for old games.
 char *convertString(char *s) {
+#if 0
 	static char *buf = NULL;
 
 	if (! buf) {
@@ -161,6 +163,8 @@ char *convertString(char *s) {
 
 	delete [] sOrig;
 	return copyString(buf = bufOrig);
+#endif
+	return s;//TODO: false value
 }
 
 char *getNumberedString(int value) {
@@ -170,9 +174,9 @@ char *getNumberedString(int value) {
 		return NULL;
 	}
 
-	fseek(bigDataFile, (value << 2) + startOfTextIndex, 0);
+	bigDataFile->seek((value << 2) + startOfTextIndex, 0);
 	value = get4bytes(bigDataFile);
-	fseek(bigDataFile, value, 0);
+	bigDataFile->seek(value, 0);
 
 	char *s = readString(bigDataFile);
 
@@ -195,15 +199,15 @@ void finishAccess() {
 
 int32_t startIndex;
 
-void setFileIndices(FILE *fp, int numLanguages, unsigned int skipBefore) {
+void setFileIndices(Common::File *fp, int numLanguages, unsigned int skipBefore) {
 	if (fp) {
 		// Keep hold of the file handle, and let things get at it
 		bigDataFile = fp;
-		startIndex = ftell(fp);
+		startIndex = fp->pos();
 	} else {
 		// No file pointer - this means that we reuse the bigDataFile
 		fp = bigDataFile;
-		fseek(fp, startIndex, 0);
+		fp->seek(startIndex, SEEK_SET);
 	}
 	sliceBusy = false;
 
@@ -215,26 +219,26 @@ void setFileIndices(FILE *fp, int numLanguages, unsigned int skipBefore) {
 	// STRINGS
 	int skipAfter = numLanguages - skipBefore;
 	while (skipBefore) {
-		fseek(fp, get4bytes(fp), 0);
+		fp->seek(get4bytes(fp), SEEK_SET);
 		skipBefore --;
 	}
-	startOfTextIndex = ftell(fp) + 4;
+	startOfTextIndex = fp->pos() + 4;
 
-	fseek(fp, get4bytes(fp), 0);
+	fp->seek(get4bytes(fp), SEEK_SET);
 
 	while (skipAfter) {
-		fseek(fp, get4bytes(fp), 0);
+		fp->seek(get4bytes(fp), SEEK_SET);
 		skipAfter --;
 	}
 
-	startOfSubIndex = ftell(fp) + 4;
-	fseek(fp, get4bytes(fp), 1);
+	startOfSubIndex = fp->pos() + 4;
+	fp->seek(get4bytes(fp), SEEK_CUR);
 
-	startOfObjectIndex = ftell(fp) + 4;
-	fseek(fp, get4bytes(fp), 1);
+	startOfObjectIndex = fp->pos() + 4;
+	fp->seek(get4bytes(fp), SEEK_CUR);
 
 	// Remember that the data section starts here
-	startOfDataIndex = ftell(fp);
+	startOfDataIndex = fp->pos();
 }
 
 } // End of namespace Sludge
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
index b83e47d..2dec0d3 100644
--- a/engines/sludge/fileset.h
+++ b/engines/sludge/fileset.h
@@ -22,13 +22,13 @@
 #ifndef SLUDGE_FILESET_H
 #define SLUDGE_FILESET_H
 
+#include "common/file.h"
+
 namespace Sludge {
 
-#if ALLOW_FILE
-extern FILE *bigDataFile;
+extern Common::File *bigDataFile;
 
-void setFileIndices(FILE *fp, int, unsigned int);
-#endif
+void setFileIndices(Common::File *fp, int, unsigned int);
 
 unsigned int openFileFromNum(int num);
 bool openSubSlice(int num);
diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp
index 291961d..7ca30b6 100644
--- a/engines/sludge/floor.cpp
+++ b/engines/sludge/floor.cpp
@@ -127,13 +127,13 @@ bool setFloor(int fileNum) {
 	killFloor();
 
 	setResourceForFatal(fileNum);
-#if ALLOW_FILE
+
 	if (! openFileFromNum(fileNum)) return false;
 
 	// Find out how many polygons there are and reserve memory
 
 	currentFloor -> originalNum = fileNum;
-	currentFloor -> numPolygons = fgetc(bigDataFile);
+	currentFloor -> numPolygons = getch(bigDataFile);
 	currentFloor -> polygon = new floorPolygon[currentFloor -> numPolygons];
 	if (! checkNew(currentFloor -> polygon)) return false;
 
@@ -143,7 +143,7 @@ bool setFloor(int fileNum) {
 
 		// Find out how many vertex IDs there are and reserve memory
 
-		currentFloor -> polygon[i].numVertices = fgetc(bigDataFile);
+		currentFloor -> polygon[i].numVertices = getch(bigDataFile);
 		currentFloor -> polygon[i].vertexID = new int[currentFloor -> polygon[i].numVertices];
 		if (! checkNew(currentFloor -> polygon[i].vertexID)) return false;
 
@@ -167,7 +167,7 @@ bool setFloor(int fileNum) {
 	}
 
 	finishAccess();
-#endif
+
 	// Now build the movement martix
 
 	currentFloor -> matrix = new int *[currentFloor -> numPolygons];
diff --git a/engines/sludge/helpers.cpp b/engines/sludge/helpers.cpp
index 30d5094..60a29af 100644
--- a/engines/sludge/helpers.cpp
+++ b/engines/sludge/helpers.cpp
@@ -22,18 +22,19 @@
 #include "allfiles.h"
 #include "helpers.h"
 
+#include "common/file.h"
+
 namespace Sludge {
 
 bool fileExists(const char *file) {
 	bool retval = false;
-#if ALLOW_FILE
-	FILE *tester;
-	tester = fopen(file, "rb");
-	if (tester) {
+
+	Common::File tester;
+	if (tester.open(file)) {
 		retval = true;
-		fclose(tester);
+		tester.close();
 	}
-#endif
+
 	return retval;
 }
 
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
index a55adae..4fe2780 100644
--- a/engines/sludge/language.cpp
+++ b/engines/sludge/language.cpp
@@ -19,8 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <stdio.h>
-#include <string.h>
+#include "allfiles.h"
 #include "stringy.h"
 #include "newfatal.h"
 #include "moreio.h"
@@ -28,6 +27,10 @@
 #include "CommonCode/version.h"
 #include "platform-dependent.h"
 
+#include "sludge.h"
+
+#include "common/debug.h"
+
 namespace Sludge {
 
 int *languageTable;
@@ -84,13 +87,17 @@ char *getPrefsFilename(char *filename) {
 }
 
 void readIniFile(char *filename) {
-#if ALLOW_FILE
+
 	char *langName = getPrefsFilename(copyString(filename));
 
-	FILE *fp = fopen(langName, "rb");
+	Common::File fd;
+	if (!fd.open(langName)) {
+		debug(kSludgeDebugDataLoad, "Fail to open language file : %s", langName);
+		return;
+	}
 
 	gameSettings.languageID = 0;
-	gameSettings.userFullScreen = defaultUserFullScreen();
+	gameSettings.userFullScreen = false; //defaultUserFullScreen(); TODO: false value
 	gameSettings.refreshRate = 0;
 	gameSettings.antiAlias = 1;
 	gameSettings.fixedPixels = false;
@@ -100,70 +107,67 @@ void readIniFile(char *filename) {
 	delete langName;
 	langName = NULL;
 
-	if (fp) {
-		char lineSoFar[257] = "";
-		char secondSoFar[257] = "";
-		unsigned char here = 0;
-		char readChar = ' ';
-		bool keepGoing = true;
-		bool doingSecond = false;
-
-		do {
-			readChar = fgetc(fp);
-			if (feof(fp)) {
-				readChar = '\n';
-				keepGoing = false;
-			}
-			switch (readChar) {
-			case '\n':
-			case '\r':
-				if (doingSecond) {
-					if (strcmp(lineSoFar, "LANGUAGE") == 0) {
-						gameSettings.languageID = stringToInt(secondSoFar);
-					} else if (strcmp(lineSoFar, "WINDOW") == 0) {
-						gameSettings.userFullScreen = ! stringToInt(secondSoFar);
-					} else if (strcmp(lineSoFar, "REFRESH") == 0) {
-						gameSettings.refreshRate = stringToInt(secondSoFar);
-					} else if (strcmp(lineSoFar, "ANTIALIAS") == 0) {
-						gameSettings.antiAlias = stringToInt(secondSoFar);
-					} else if (strcmp(lineSoFar, "FIXEDPIXELS") == 0) {
-						gameSettings.fixedPixels = stringToInt(secondSoFar);
-					} else if (strcmp(lineSoFar, "NOSTARTWINDOW") == 0) {
-						gameSettings.noStartWindow = stringToInt(secondSoFar);
-					} else if (strcmp(lineSoFar, "DEBUGMODE") == 0) {
-						gameSettings.debugMode = stringToInt(secondSoFar);
-					}
-				}
-				here = 0;
-				doingSecond = false;
-				lineSoFar[0] = 0;
-				secondSoFar[0] = 0;
-				break;
-
-			case '=':
-				doingSecond = true;
-				here = 0;
-				break;
-
-			default:
-				if (doingSecond) {
-					secondSoFar[here ++] = readChar;
-					secondSoFar[here] = 0;
-				} else {
-					lineSoFar[here ++] = readChar;
-					lineSoFar[here] = 0;
+	char lineSoFar[257] = "";
+	char secondSoFar[257] = "";
+	unsigned char here = 0;
+	char readChar = ' ';
+	bool keepGoing = true;
+	bool doingSecond = false;
+
+	do {
+		readChar = getch(&fd);
+		if (fd.eos()) {
+			readChar = '\n';
+			keepGoing = false;
+		}
+		switch (readChar) {
+		case '\n':
+		case '\r':
+			if (doingSecond) {
+				if (strcmp(lineSoFar, "LANGUAGE") == 0) {
+					gameSettings.languageID = stringToInt(secondSoFar);
+				} else if (strcmp(lineSoFar, "WINDOW") == 0) {
+					gameSettings.userFullScreen = ! stringToInt(secondSoFar);
+				} else if (strcmp(lineSoFar, "REFRESH") == 0) {
+					gameSettings.refreshRate = stringToInt(secondSoFar);
+				} else if (strcmp(lineSoFar, "ANTIALIAS") == 0) {
+					gameSettings.antiAlias = stringToInt(secondSoFar);
+				} else if (strcmp(lineSoFar, "FIXEDPIXELS") == 0) {
+					gameSettings.fixedPixels = stringToInt(secondSoFar);
+				} else if (strcmp(lineSoFar, "NOSTARTWINDOW") == 0) {
+					gameSettings.noStartWindow = stringToInt(secondSoFar);
+				} else if (strcmp(lineSoFar, "DEBUGMODE") == 0) {
+					gameSettings.debugMode = stringToInt(secondSoFar);
 				}
-				break;
 			}
-		} while (keepGoing);
+			here = 0;
+			doingSecond = false;
+			lineSoFar[0] = 0;
+			secondSoFar[0] = 0;
+			break;
+
+		case '=':
+			doingSecond = true;
+			here = 0;
+			break;
+
+		default:
+			if (doingSecond) {
+				secondSoFar[here ++] = readChar;
+				secondSoFar[here] = 0;
+			} else {
+				lineSoFar[here ++] = readChar;
+				lineSoFar[here] = 0;
+			}
+			break;
+		}
+	} while (keepGoing);
 
-		fclose(fp);
-	}
-#endif
+	fd.close();
 }
 
 void saveIniFile(char *filename) {
-#if ALLOW_FILE
+#if 0
 	char *langName = getPrefsFilename(copyString(filename));
 	FILE *fp = fopen(langName, "wt");
 	delete langName;
@@ -179,8 +183,7 @@ void saveIniFile(char *filename) {
 #endif
 }
 
-#if ALLOW_FILE
-void makeLanguageTable(FILE *table) {
+void makeLanguageTable(Common::File *table) {
 	languageTable = new int[gameSettings.numLanguages + 1];
 	if (! checkNew(languageTable)) return;
 
@@ -189,17 +192,16 @@ void makeLanguageTable(FILE *table) {
 
 	for (unsigned int i = 0; i <= gameSettings.numLanguages; i ++) {
 		languageTable[i] = i ? get2bytes(table) : 0;
-		printf("languageTable %i: %i\n", i, languageTable[i]);
+		debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, languageTable[i]);
 		languageName[i] = 0;
 		if (gameVersion >= VERSION(2, 0)) {
 			if (gameSettings.numLanguages) {
 				languageName[i] = readString(table);
-				printf("languageName %i: %s\n", i, languageName[i]);
+				debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, languageName[i]);
 			}
 		}
 	}
 }
-#endif
 
 int getLanguageForFileB() {
 	int indexNum = -1;
diff --git a/engines/sludge/language.h b/engines/sludge/language.h
index 27faffb..93805c2 100644
--- a/engines/sludge/language.h
+++ b/engines/sludge/language.h
@@ -22,6 +22,10 @@
 #ifndef LANGUAGE_H
 #define LANGUAGE_H
 
+#include "allfiles.h"
+
+#include "common/file.h"
+
 namespace Sludge {
 
 struct settingsStruct {
@@ -41,9 +45,7 @@ void readIniFile(char *filename);
 void saveIniFile(char *filename);
 int getLanguageForFileB();
 
-#if ALLOW_FILE
-void makeLanguageTable(FILE *table);
-#endif
+void makeLanguageTable(Common::File *table);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 2014095..959885f 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -40,6 +40,7 @@
 #include "sound.h"
 #include "fileset.h"
 #include "debug.h"
+#include "loadsave.h"
 
 namespace Sludge {
 
@@ -93,81 +94,76 @@ stackLibrary *stackLib = NULL;
 //----------------------------------------------------------------------
 // For saving and loading stacks...
 //----------------------------------------------------------------------
-#if 0
-bool saveVariable(variable *from, FILE *fp);
-bool loadVariable(variable *to, FILE *fp);
-
-void saveStack(variableStack *vs, FILE *fp) {
+void saveStack(variableStack *vs, Common::WriteStream *stream) {
 	int elements = 0;
 	int a;
 
 	variableStack *search = vs;
 	while (search) {
 		elements ++;
-		search = search -> next;
+		search = search->next;
 	}
 
 	stackDebug((stackfp, "  stack contains %d elements\n", elements));
 
-	put2bytes(elements, fp);
+	put2bytes(elements, stream);
 	search = vs;
-	for (a = 0; a < elements; a ++) {
-		saveVariable(& search -> thisVar, fp);
-		search = search -> next;
+	for (a = 0; a < elements; ++a) {
+		saveVariable(&search->thisVar, stream);
+		search = search->next;
 	}
 }
 
-variableStack *loadStack(FILE *fp, variableStack **last) {
-	int elements = get2bytes(fp);
+variableStack *loadStack(Common::SeekableReadStream *stream, variableStack **last) {
+	int elements = get2bytes(stream);
 	int a;
 	variableStack *first = NULL;
-	variableStack * * changeMe = & first;
+	variableStack * * changeMe = &first;
 
-	for (a = 0; a < elements; a ++) {
+	for (a = 0; a < elements; ++a) {
 		variableStack *nS = new variableStack;
 		if (!checkNew(nS)) return NULL;
-		loadVariable(& (nS -> thisVar), fp);
+		loadVariable(&(nS->thisVar), stream);
 		if (last && a == elements - 1) {
 			stackDebug((stackfp, "Setting last to %p\n", nS));
 			*last = nS;
 		}
-		nS -> next = NULL;
+		nS->next = NULL;
 		(* changeMe) = nS;
-		changeMe = & (nS -> next);
+		changeMe = &(nS->next);
 	}
 
 	return first;
 }
 
-bool saveStackRef(stackHandler *vs, FILE *fp) {
+bool saveStackRef(stackHandler *vs, Common::WriteStream *stream) {
 	stackLibrary *s = stackLib;
 	int a = 0;
 	while (s) {
-		if (s -> stack == vs) {
-			fputc(1, fp);
-			put2bytes(stackLibTotal - a, fp);
+		if (s->stack == vs) {
+			putch(1, stream);
+			put2bytes(stackLibTotal - a, stream);
 			return true;
 		}
-		s = s -> next;
-		a ++;
+		s = s->next;
+		++a;
 	}
-	fputc(0, fp);
-	saveStack(vs -> first, fp);
+	putch(0, stream);
+	saveStack(vs->first, stream);
 	s = new stackLibrary;
 	stackLibTotal ++;
 	if (! checkNew(s)) return false;
-	s -> next = stackLib;
-	s -> stack = vs;
+	s->next = stackLib;
+	s->stack = vs;
 	stackLib = s;
 	return true;
 }
-#endif
 
 void clearStackLib() {
 	stackLibrary *k;
 	while (stackLib) {
 		k = stackLib;
-		stackLib = stackLib -> next;
+		stackLib = stackLib->next;
 		delete k;
 	}
 	stackLibTotal = 0;
@@ -176,20 +172,20 @@ void clearStackLib() {
 stackHandler *getStackFromLibrary(int n) {
 	n = stackLibTotal - n;
 	while (n) {
-		stackLib = stackLib -> next;
+		stackLib = stackLib->next;
 		n --;
 	}
-	return stackLib -> stack;
+	return stackLib->stack;
 }
-#if 0
-stackHandler *loadStackRef(FILE *fp) {
+
+stackHandler *loadStackRef(Common::SeekableReadStream *stream) {
 	stackHandler *nsh;
 
-	if (fgetc(fp)) {    // It's one we've loaded already...
+	if (getch(stream)) {    // It's one we've loaded already...
 		stackDebug((stackfp, "loadStackRef (duplicate, get from library)\n"));
 
-		nsh = getStackFromLibrary(get2bytes(fp));
-		nsh -> timesUsed ++;
+		nsh = getStackFromLibrary(get2bytes(stream));
+		nsh->timesUsed ++;
 	} else {
 		stackDebug((stackfp, "loadStackRef (new one)\n"));
 
@@ -197,9 +193,9 @@ stackHandler *loadStackRef(FILE *fp) {
 
 		nsh = new stackHandler;
 		if (! checkNew(nsh)) return NULL;
-		nsh -> last = NULL;
-		nsh -> first = loadStack(fp, & nsh->last);
-		nsh -> timesUsed = 1;
+		nsh->last = NULL;
+		nsh->first = loadStack(stream, &nsh->last);
+		nsh->timesUsed = 1;
 		stackDebug((stackfp, "  first = %p\n", nsh->first));
 		if (nsh->first)
 			stackDebug((stackfp, "  first->next = %p\n", nsh->first->next));
@@ -211,8 +207,8 @@ stackHandler *loadStackRef(FILE *fp) {
 
 		stackLibrary *s = new stackLibrary;
 		if (! checkNew(s)) return NULL;
-		s -> stack = nsh;
-		s -> next = stackLib;
+		s->stack = nsh;
+		s->next = stackLib;
 		stackLib = s;
 		stackLibTotal ++;
 	}
@@ -222,8 +218,7 @@ stackHandler *loadStackRef(FILE *fp) {
 //----------------------------------------------------------------------
 // For saving and loading variables...
 //----------------------------------------------------------------------
-
-bool saveVariable(variable *from, FILE *fp) {
+bool saveVariable(variable *from, Common::WriteStream *stream) {
 #if DEBUG_STACKINESS
 	{
 		char *str = getTextFromAnyVar(*from);
@@ -232,29 +227,29 @@ bool saveVariable(variable *from, FILE *fp) {
 	}
 #endif
 
-	fputc(from -> varType, fp);
-	switch (from -> varType) {
+	putch(from->varType, stream);
+	switch (from->varType) {
 	case SVT_INT:
 	case SVT_FUNC:
 	case SVT_BUILT:
 	case SVT_FILE:
 	case SVT_OBJTYPE:
-		put4bytes(from -> varData.intValue, fp);
+		put4bytes(from->varData.intValue, stream);
 		return true;
 
 	case SVT_STRING:
-		writeString(from -> varData.theString, fp);
+		writeString(from->varData.theString, stream);
 		return true;
 
 	case SVT_STACK:
-		return saveStackRef(from -> varData.theStack, fp);
+		return saveStackRef(from->varData.theStack, stream);
 
 	case SVT_COSTUME:
-		saveCostume(from -> varData.costumeHandler, fp);
+		saveCostume(from->varData.costumeHandler, stream);
 		return false;
 
 	case SVT_ANIM:
-		saveAnim(from -> varData.animHandler, fp);
+		saveAnim(from->varData.animHandler, stream);
 		return false;
 
 	case SVT_NULL:
@@ -269,23 +264,23 @@ bool saveVariable(variable *from, FILE *fp) {
 	return true;
 }
 
-bool loadVariable(variable *to, FILE *fp) {
-	to -> varType = (variableType) fgetc(fp);
-	switch (to -> varType) {
+bool loadVariable(variable *to, Common::SeekableReadStream *stream) {
+	to->varType = (variableType)getch(stream);
+	switch (to->varType) {
 	case SVT_INT:
 	case SVT_FUNC:
 	case SVT_BUILT:
 	case SVT_FILE:
 	case SVT_OBJTYPE:
-		to -> varData.intValue = get4bytes(fp);
+		to->varData.intValue = get4bytes(stream);
 		return true;
 
 	case SVT_STRING:
-		to -> varData.theString = readString(fp);
+		to->varData.theString = readString(stream);
 		return true;
 
 	case SVT_STACK:
-		to -> varData.theStack = loadStackRef(fp);
+		to->varData.theStack = loadStackRef(stream);
 #if DEBUG_STACKINESS
 		{
 			char *str = getTextFromAnyVar(*to);
@@ -296,15 +291,15 @@ bool loadVariable(variable *to, FILE *fp) {
 		return true;
 
 	case SVT_COSTUME:
-		to -> varData.costumeHandler = new persona;
-		if (! checkNew(to -> varData.costumeHandler)) return false;
-		loadCostume(to -> varData.costumeHandler, fp);
+		to->varData.costumeHandler = new persona;
+		if (! checkNew(to->varData.costumeHandler)) return false;
+		loadCostume(to->varData.costumeHandler, stream);
 		return true;
 
 	case SVT_ANIM:
-		to -> varData.animHandler = new personaAnimation;
-		if (! checkNew(to -> varData.animHandler)) return false;
-		loadAnim(to -> varData.animHandler, fp);
+		to->varData.animHandler = new personaAnimation;
+		if (! checkNew(to->varData.animHandler)) return false;
+		loadAnim(to->varData.animHandler, stream);
 		return true;
 
 	default:
@@ -316,34 +311,32 @@ bool loadVariable(variable *to, FILE *fp) {
 //----------------------------------------------------------------------
 // For saving and loading functions
 //----------------------------------------------------------------------
-
-void saveFunction(loadedFunction *fun, FILE *fp) {
+void saveFunction(loadedFunction *fun, Common::WriteStream *stream) {
 	int a;
-	put2bytes(fun -> originalNumber, fp);
-	if (fun -> calledBy) {
-		fputc(1, fp);
-		saveFunction(fun -> calledBy, fp);
+	put2bytes(fun->originalNumber, stream);
+	if (fun->calledBy) {
+		putch(1, stream);
+		saveFunction(fun->calledBy, stream);
 	} else {
-		fputc(0, fp);
+		putch(0, stream);
 	}
-	put4bytes(fun -> timeLeft, fp);
-	put2bytes(fun -> runThisLine, fp);
-	fputc(fun -> cancelMe, fp);
-	fputc(fun -> returnSomething, fp);
-	fputc(fun -> isSpeech, fp);
-	saveVariable(& (fun -> reg), fp);
+	put4bytes(fun->timeLeft, stream);
+	put2bytes(fun->runThisLine, stream);
+	putch(fun->cancelMe, stream);
+	putch(fun->returnSomething, stream);
+	putch(fun->isSpeech, stream);
+	saveVariable(&(fun->reg), stream);
 
-	if (fun -> freezerLevel) {
+	if (fun->freezerLevel) {
 		fatal(ERROR_GAME_SAVE_FROZEN);
 	}
-	saveStack(fun -> stack, fp);
-	for (a = 0; a < fun -> numLocals; a ++) {
-		saveVariable(& (fun -> localVars[a]), fp);
+	saveStack(fun->stack, stream);
+	for (a = 0; a < fun->numLocals; ++a) {
+		saveVariable(&(fun->localVars[a]), stream);
 	}
 }
 
-
-loadedFunction *loadFunction(FILE *fp) {
+loadedFunction *loadFunction(Common::SeekableReadStream *stream) {
 	int a;
 
 	// Reserve memory...
@@ -353,31 +346,31 @@ loadedFunction *loadFunction(FILE *fp) {
 
 	// See what it was called by and load if we need to...
 
-	buildFunc -> originalNumber = get2bytes(fp);
-	buildFunc -> calledBy = NULL;
-	if (fgetc(fp)) {
-		buildFunc -> calledBy = loadFunction(fp);
-		if (! buildFunc -> calledBy) return NULL;
+	buildFunc->originalNumber = get2bytes(stream);
+	buildFunc->calledBy = NULL;
+	if (getch(stream)) {
+		buildFunc->calledBy = loadFunction(stream);
+		if (! buildFunc->calledBy) return NULL;
 	}
 
-	buildFunc -> timeLeft = get4bytes(fp);
-	buildFunc -> runThisLine = get2bytes(fp);
-	buildFunc -> freezerLevel = 0;
-	buildFunc -> cancelMe = fgetc(fp);
-	buildFunc -> returnSomething = fgetc(fp);
-	buildFunc -> isSpeech = fgetc(fp);
-	loadVariable(& (buildFunc -> reg), fp);
+	buildFunc->timeLeft = get4bytes(stream);
+	buildFunc->runThisLine = get2bytes(stream);
+	buildFunc->freezerLevel = 0;
+	buildFunc->cancelMe = getch(stream);
+	buildFunc->returnSomething = getch(stream);
+	buildFunc->isSpeech = getch(stream);
+	loadVariable(&(buildFunc->reg), stream);
 	loadFunctionCode(buildFunc);
 
-	buildFunc -> stack = loadStack(fp, NULL);
+	buildFunc->stack = loadStack(stream, NULL);
 
-	for (a = 0; a < buildFunc -> numLocals; a ++) {
-		loadVariable(& (buildFunc -> localVars[a]), fp);
+	for (a = 0; a < buildFunc->numLocals; ++a) {
+		loadVariable(&(buildFunc->localVars[a]), stream);
 	}
 
 	return buildFunc;
 }
-#endif
+
 //----------------------------------------------------------------------
 // Save everything
 //----------------------------------------------------------------------
@@ -397,7 +390,7 @@ bool saveGame(char *fname) {
 
 	if (! saveThumbnail(fp)) return false;
 
-	fwrite(& fileTime, sizeof(FILETIME), 1, fp);
+	fwrite(&fileTime, sizeof(FILETIME), 1, fp);
 
 	// DON'T ADD ANYTHING NEW BEFORE THIS POINT!
 
@@ -435,25 +428,25 @@ bool saveGame(char *fname) {
 	int countFunctions = 0;
 	while (thisFunction) {
 		countFunctions ++;
-		thisFunction = thisFunction -> next;
+		thisFunction = thisFunction->next;
 	}
 	put2bytes(countFunctions, fp);
 
 	thisFunction = allRunningFunctions;
 	while (thisFunction) {
 		saveFunction(thisFunction, fp);
-		thisFunction = thisFunction -> next;
+		thisFunction = thisFunction->next;
 	}
 
-	for (a = 0; a < numGlobals; a ++) {
-		saveVariable(& globalVars[a], fp);
+	for (a = 0; a < numGlobals; ++a) {
+		saveVariable(&globalVars[a], fp);
 	}
 
 	savePeople(fp);
 
-	if (currentFloor -> numPolygons) {
+	if (currentFloor->numPolygons) {
 		fputc(1, fp);
-		put2bytes(currentFloor -> originalNum, fp);
+		put2bytes(currentFloor->originalNum, fp);
 	} else fputc(0, fp);
 
 	if (zBuffer.tex) {
@@ -516,7 +509,7 @@ bool loadGame(char *fname) {
 		if (! skipThumbnail(fp)) return fatal(ERROR_GAME_LOAD_CORRUPT, fname);
 	}
 
-	size_t bytes_read = fread(& savedGameTime, sizeof(FILETIME), 1, fp);
+	size_t bytes_read = fread(&savedGameTime, sizeof(FILETIME), 1, fp);
 	if (bytes_read != sizeof(FILETIME) && ferror(fp)) {
 		debugOut("Reading error in loadGame.\n");
 	}
@@ -546,7 +539,7 @@ bool loadGame(char *fname) {
 			charOrder = new char[257];
 			if (! checkNew(charOrder)) return false;
 
-			for (int a = 0; a < 256; a ++) {
+			for (int a = 0; a < 256; ++a) {
 				x = fgetc(fp);
 				charOrder[x] = a;
 			}
@@ -584,20 +577,20 @@ bool loadGame(char *fname) {
 	mouseCursorFrameNum = get2bytes(fp);
 
 	loadedFunction *rFunc;
-	loadedFunction * * buildList = & allRunningFunctions;
+	loadedFunction * * buildList = &allRunningFunctions;
 
 
 	int countFunctions = get2bytes(fp);
 	while (countFunctions --) {
 		rFunc = loadFunction(fp);
-		rFunc -> next = NULL;
+		rFunc->next = NULL;
 		(* buildList) = rFunc;
-		buildList = & (rFunc -> next);
+		buildList = &(rFunc->next);
 	}
 
-	for (a = 0; a < numGlobals; a ++) {
+	for (a = 0; a < numGlobals; ++a) {
 		unlinkVar(globalVars[a]);
-		loadVariable(& globalVars[a], fp);
+		loadVariable(&globalVars[a], fp);
 	}
 
 	loadPeople(fp);
diff --git a/engines/sludge/loadsave.h b/engines/sludge/loadsave.h
index b91e872..87024f2 100644
--- a/engines/sludge/loadsave.h
+++ b/engines/sludge/loadsave.h
@@ -27,10 +27,15 @@ namespace Sludge {
 bool saveGame(char *fname);
 bool loadGame(char *fname);
 
-#if ALLOW_FILE
-loadedFunction *loadFunction(FILE *fp);
-void saveFunction(loadedFunction *fun, FILE *fp);
-#endif
+bool saveVariable(variable *from, Common::WriteStream *stream);
+bool loadVariable(variable *to, Common::SeekableReadStream *stream);
+
+variableStack *loadStack(Common::SeekableReadStream *stream, variableStack **last);
+bool saveStackRef(stackHandler *vs, Common::WriteStream *stream);
+stackHandler *loadStackRef(Common::SeekableReadStream *stream);
+
+loadedFunction *loadFunction(Common::SeekableReadStream *stream);
+void saveFunction(loadedFunction *fun, Common::WriteStream *stream);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 47bfe67..b278a35 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -138,9 +138,7 @@ void setGameFilePath(char *f) {
 #endif
 }
 
-#if ALLOW_FILE
-void saveHSI(FILE *writer);
-#endif
+void saveHSI(Common::WriteStream *writer);
 
 extern bool reallyWantToQuit;
 
@@ -440,9 +438,8 @@ try
 	initStatusBar();
 	resetRandW();
 
-#if ALLOW_FILE
 	gameName = getNumberedString(1);
-#endif
+
 #if 0
 	SDL_WM_SetCaption(gameName, gameName);
 
diff --git a/engines/sludge/memwatch.cpp b/engines/sludge/memwatch.cpp
index d316687..34e8605 100644
--- a/engines/sludge/memwatch.cpp
+++ b/engines/sludge/memwatch.cpp
@@ -21,12 +21,15 @@
  */
 #include "allfiles.h"
 
+#include "common/debug.h"
+
 namespace Sludge {
 
 void *allKnownMem[3000];
 int allKnownNum = 0;
 
 void outputKnownMem() {
+#if 0
 	FILE *debu = fopen("debuTURN.txt", "at");
 
 	fprintf(debu, "%i lumps:", allKnownNum);
@@ -35,6 +38,7 @@ void outputKnownMem() {
 	}
 	fprintf(debu, "\n");
 	fclose(debu);
+#endif
 }
 
 void adding(void *mem) {
@@ -43,8 +47,10 @@ void adding(void *mem) {
 
 	outputKnownMem();
 	if (allKnownNum == 3000) {
-		//db ("Error! Array too full!");
+		debug("Error! Array too full!");
+#if 0
 		exit(1);
+#endif
 	}
 }
 
@@ -57,8 +63,10 @@ void deleting(void *mem) {
 			return;
 		}
 	}
+#if 0
 	//db ("Error! Deleted a block which hasn't been allocated!");
 	exit(1);
+#endif
 }
 
 } // End of namespace Sludge
diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk
index 78f41dd..bad7f35 100644
--- a/engines/sludge/module.mk
+++ b/engines/sludge/module.mk
@@ -8,6 +8,7 @@ MODULE_OBJS := \
 	cursors.o \
 	debug.o \
 	detection.o \
+	fileset.o \
 	floor.o \
 	freeze.o \
 	fonttext.o \
@@ -17,6 +18,7 @@ MODULE_OBJS := \
 	line.o \
 	loadsave.o \
 	main_loop.o \
+	memwatch.o \
 	moreio.o \
 	movie.o \
 	newfatal.o \
@@ -33,15 +35,13 @@ MODULE_OBJS := \
 	stringy.o \
 	talk.o \
 	thumbnail.o \
+	timing.o \
 	transition.o \
 	variable.o \
 	zbuffer.o \
 	CommonCode/utf8.o \
-#	fileset.o \
-	linuxstuff.o \
-	memwatch.o \
+#	linuxstuff.o \
 	shaders.o \
-	timing.o \
 	libwebm/mkvparser.o \
 	libwebm/mkvreader.o \
  
diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp
index b8dc3f9..8bb0d77 100644
--- a/engines/sludge/moreio.cpp
+++ b/engines/sludge/moreio.cpp
@@ -24,7 +24,10 @@
 #include "newfatal.h"
 #include "stringy.h"
 
-#include "debug.h"
+#include "sludge.h"
+
+#include "common/debug.h"
+#include "common/file.h"
 
 #if defined __unix__ && !(defined __APPLE__)
 #include <endian.h>
@@ -37,43 +40,48 @@ namespace Sludge {
 
 bool allowAnyFilename = true;
 
-#if ALLOW_FILE
-int get2bytes(FILE *fp) {
+int getch(Common::SeekableReadStream *stream) {
+	return stream->readByte();
+}
+
+void putch(int c, Common::WriteStream *stream) {
+	stream->writeByte(c);
+}
+
+int get2bytes(Common::SeekableReadStream *stream) {
 	int f1, f2;
 
-	f1 = fgetc(fp);
-	f2 = fgetc(fp);
+	f1 = getch(stream);
+	f2 = getch(stream);
 
 	return (f1 * 256 + f2);
 }
 
-void put2bytes(int numtoput, FILE *fp) {
-	fputc((char)(numtoput / 256), fp);
-	fputc((char)(numtoput % 256), fp);
+void put2bytes(int numtoput, Common::WriteStream *stream) {
+	putch((char)(numtoput / 256), stream);
+	putch((char)(numtoput % 256), stream);
 }
 
-void writeString(char *s, FILE *fp) {
+void writeString(char *s, Common::WriteStream *stream) {
 	int a, len = strlen(s);
-	put2bytes(len, fp);
-	for (a = 0; a < len; a ++) {
-		fputc(s[a] + 1, fp);
+	put2bytes(len, stream);
+	for (a = 0; a < len; ++a) {
+		putch(s[a] + 1, stream);
 	}
 }
 
 
-char *readString(FILE *fp) {
-
-	int a, len = get2bytes(fp);
-	//debugOut ("MOREIO: readString - len %i\n", len);
+char *readString(Common::SeekableReadStream *stream) {
+	int a, len = get2bytes(stream);
 	char *s = new char[len + 1];
-	if (! checkNew(s)) {
+	if (!checkNew(s)) {
 		return NULL;
 	}
-	for (a = 0; a < len; a ++) {
-		s[a] = (char)(fgetc(fp) - 1);
+	for (a = 0; a < len; ++a) {
+		s[a] = (char)(getch(stream) - 1);
 	}
 	s[len] = 0;
-	//debugOut ("MOREIO: readString: %s\n", s);
+	debug(kSludgeDebugDataLoad, "Read string of length %i: %s", len, s);
 	return s;
 }
 
@@ -92,11 +100,12 @@ float floatSwap(float f) {
 }
 
 
-float getFloat(FILE *fp) {
+float getFloat(Common::SeekableReadStream *stream) {
 	float f;
-	size_t bytes_read = fread(& f, sizeof(float), 1, fp);
-	if (bytes_read != sizeof(float) && ferror(fp)) {
-		debugOut("Reading error in getFloat.\n");
+	size_t bytes_read = stream->read(&f, sizeof(float));
+			//fread(& f, sizeof(float), 1, fp);
+	if (bytes_read != sizeof(float) && stream->err()) {
+		debug("Reading error in getFloat.\n");
 	}
 
 #ifdef  __BIG_ENDIAN__
@@ -106,11 +115,12 @@ float getFloat(FILE *fp) {
 #endif
 }
 
-void putFloat(float f, FILE *fp) {
+void putFloat(float f, Common::WriteStream *stream) {
 #ifdef  __BIG_ENDIAN__
 	f = floatSwap(f);
 #endif
-	fwrite(& f, sizeof(float), 1, fp);
+	stream->write(&f,sizeof(float));
+	//fwrite(& f, sizeof(float), 1, fp);
 }
 
 short shortSwap(short s) {
@@ -123,11 +133,11 @@ short shortSwap(short s) {
 }
 
 
-short getSigned(FILE *fp) {
+short getSigned(Common::SeekableReadStream *stream) {
 	short f;
-	size_t bytes_read = fread(& f, sizeof(short), 1, fp);
-	if (bytes_read != sizeof(short) && ferror(fp)) {
-		debugOut("Reading error in getSigned.\n");
+	size_t bytes_read = stream->read(&f, sizeof(short));
+	if (bytes_read != sizeof(short) && stream->err()) {
+		debug("Reading error in getSigned.\n");
 	}
 #ifdef  __BIG_ENDIAN__
 	f = shortSwap(f);
@@ -135,39 +145,32 @@ short getSigned(FILE *fp) {
 	return f;
 }
 
-void putSigned(short f, FILE *fp) {
+void putSigned(short f, Common::WriteStream *stream) {
 #ifdef  __BIG_ENDIAN__
 	f = shortSwap(f);
 #endif
-	fwrite(& f, sizeof(short), 1, fp);
+	stream->write(&f, sizeof(short));
 }
 
 
 // The following two functions treat signed integers as unsigned.
 // That's done on purpose.
 
-int32_t get4bytes(FILE *fp) {
+int32_t get4bytes(Common::SeekableReadStream *stream) {
 	int f1, f2, f3, f4;
 
-	f1 = fgetc(fp);
-	f2 = fgetc(fp);
-	f3 = fgetc(fp);
-	f4 = fgetc(fp);
+	f1 = getch(stream);
+	f2 = getch(stream);
+	f3 = getch(stream);
+	f4 = getch(stream);
 
 	unsigned int x = f1 + f2 * 256 + f3 * 256 * 256 + f4 * 256 * 256 * 256;
 
 	return x;
-
-	/*
-
-	    int32_t f;
-	    fread (& f, sizeof (int32_t), 1, fp);
-	    return f;*/
 }
 
 
-void put4bytes(unsigned int i, FILE *fp) {
-	//  fwrite (&i, sizeof (long int), 1, fp);
+void put4bytes(unsigned int i, Common::WriteStream *stream) {
 	unsigned char f1, f2, f3, f4;
 
 	f4 = i / (256 * 256 * 256);
@@ -177,17 +180,17 @@ void put4bytes(unsigned int i, FILE *fp) {
 	f2 = i / 256;
 	f1 = i % 256;
 
-	fputc(f1, fp);
-	fputc(f2, fp);
-	fputc(f3, fp);
-	fputc(f4, fp);
+	putch(f1, stream);
+	putch(f2, stream);
+	putch(f3, stream);
+	putch(f4, stream);
 }
-#endif
+
 char *encodeFilename(char *nameIn) {
-	if (! nameIn) return NULL;
+	if (!nameIn) return NULL;
 	if (allowAnyFilename) {
 		char *newName = new char[strlen(nameIn) * 2 + 1];
-		if (! checkNew(newName)) return NULL;
+		if (!checkNew(newName)) return NULL;
 
 		int i = 0;
 		while (*nameIn) {
@@ -243,7 +246,7 @@ char *encodeFilename(char *nameIn) {
 		return newName;
 	} else {
 		int a;
-		for (a = 0; nameIn[a]; a ++) {
+		for (a = 0; nameIn[a]; ++a) {
 #ifdef _WIN32
 			if (nameIn[a] == '/') nameIn[a] = '\\';
 #else
@@ -258,7 +261,7 @@ char *encodeFilename(char *nameIn) {
 char *decodeFilename(char *nameIn) {
 	if (allowAnyFilename) {
 		char *newName = new char[strlen(nameIn) + 1];
-		if (! checkNew(newName)) return NULL;
+		if (!checkNew(newName)) return NULL;
 
 		int i = 0;
 		while (* nameIn) {
diff --git a/engines/sludge/moreio.h b/engines/sludge/moreio.h
index 5d107a8..9c2287b 100644
--- a/engines/sludge/moreio.h
+++ b/engines/sludge/moreio.h
@@ -26,18 +26,22 @@
 
 namespace Sludge {
 
-#if ALLOW_FILE
-int get2bytes(FILE *fp);
-void put2bytes(int numtoput, FILE *fp);
-char *readString(FILE *fp);
-void writeString(char *s, FILE *fp);
-void putFloat(float f, FILE *fp);
-float getFloat(FILE *fp);
-void putSigned(short f, FILE *fp);
-short getSigned(FILE *fp);
-int32_t get4bytes(FILE *fp);
-void put4bytes(uint32_t f, FILE *fp);
-#endif
+// Read
+int getch(Common::SeekableReadStream *stream);
+int get2bytes(Common::SeekableReadStream *stream);
+char *readString(Common::SeekableReadStream *stream);
+float getFloat(Common::SeekableReadStream *stream);
+short getSigned(Common::SeekableReadStream *stream);
+int32_t get4bytes(Common::SeekableReadStream *stream);
+
+// Write
+void putch(int c, Common::WriteStream *stream);
+void put2bytes(int numtoput, Common::WriteStream *stream);
+void writeString(char *s, Common::WriteStream *stream);
+void putFloat(float f, Common::WriteStream *stream);
+void putSigned(short f, Common::WriteStream *stream);
+void put4bytes(uint32_t f, Common::WriteStream *stream);
+
 char *encodeFilename(char *nameIn);
 char *decodeFilename(char *nameIn);
 
diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp
index f05de5c..5c8a36d 100644
--- a/engines/sludge/newfatal.cpp
+++ b/engines/sludge/newfatal.cpp
@@ -95,9 +95,8 @@ int inFatal(const char *str) {
 	fatalMessage = copyString(str);
 	if (fatalMessage == NULL) fatalMessage = copyString("Out of memory");
 
-#if 0
+
 	killSoundStuff();
-#endif
 
 #if defined(HAVE_GLES2)
 	EGL_Close();
@@ -123,7 +122,7 @@ void setFatalInfo(const char *userFunc, const char *BIF) {
 	delete fatalInfo;
 	fatalInfo = new char [strlen(userFunc) + strlen(BIF) + 38];
 	if (fatalInfo) sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, BIF);
-	debug("%s\n", fatalInfo);
+	debug("%s", fatalInfo);
 }
 
 void setResourceForFatal(int n) {
diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp
index 58572b0..ba70977 100644
--- a/engines/sludge/objtypes.cpp
+++ b/engines/sludge/objtypes.cpp
@@ -50,24 +50,23 @@ objectType *findObjectType(int i) {
 }
 
 objectType *loadObjectType(int i) {
-#if ALLOW_FILE
 	int a, nameNum;
 	objectType *newType = new objectType;
 
 	if (checkNew(newType)) {
 		if (openObjectSlice(i)) {
 			nameNum = get2bytes(bigDataFile);
-			newType -> r = (byte) fgetc(bigDataFile);
-			newType -> g = (byte) fgetc(bigDataFile);
-			newType -> b = (byte) fgetc(bigDataFile);
-			newType -> speechGap = fgetc(bigDataFile);
-			newType -> walkSpeed = fgetc(bigDataFile);
+			newType -> r = (byte) getch(bigDataFile);
+			newType -> g = (byte) getch(bigDataFile);
+			newType -> b = (byte) getch(bigDataFile);
+			newType -> speechGap = getch(bigDataFile);
+			newType -> walkSpeed = getch(bigDataFile);
 			newType -> wrapSpeech = get4bytes(bigDataFile);
 			newType -> spinSpeed = get2bytes(bigDataFile);
 
 			if (gameVersion >= VERSION(1, 6)) {
 				// aaLoad
-				fgetc(bigDataFile);
+				getch(bigDataFile);
 				getFloat(bigDataFile);
 				getFloat(bigDataFile);
 			}
@@ -111,23 +110,21 @@ objectType *loadObjectType(int i) {
 			return newType;
 		}
 	}
-#endif
+
 	return NULL;
 }
 
-#if ALLOW_FILE
-objectType *loadObjectRef(FILE *fp) {
-	objectType *r = loadObjectType(get2bytes(fp));
+objectType *loadObjectRef(Common::SeekableReadStream *stream) {
+	objectType *r = loadObjectType(get2bytes(stream));
 	delete r -> screenName;
-	r -> screenName = readString(fp);
+	r -> screenName = readString(stream);
 	return r;
 }
 
-void saveObjectRef(objectType *r, FILE *fp) {
-	put2bytes(r -> objectNum, fp);
-	writeString(r -> screenName, fp);
+void saveObjectRef(objectType *r, Common::WriteStream *stream) {
+	put2bytes(r -> objectNum, stream);
+	writeString(r -> screenName, stream);
 }
-#endif
 
 int getCombinationFunction(int withThis, int thisObject) {
 	int i, num = 0;
diff --git a/engines/sludge/objtypes.h b/engines/sludge/objtypes.h
index f61c845..0bd785a 100644
--- a/engines/sludge/objtypes.h
+++ b/engines/sludge/objtypes.h
@@ -44,10 +44,8 @@ objectType *findObjectType(int i);
 objectType *loadObjectType(int i);
 int getCombinationFunction(int a, int b);
 void removeObjectType(objectType *oT);
-#if ALLOW_FILE
-void saveObjectRef(objectType *r, FILE *fp);
-objectType *loadObjectRef(FILE *fp);
-#endif
+void saveObjectRef(objectType *r, Common::WriteStream *stream);
+objectType *loadObjectRef(Common::SeekableReadStream *stream);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index f54b1ff..6430d35 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -71,36 +71,36 @@ inline int TF_abs(int a) {
 }
 
 void setFrames(onScreenPerson &m, int a) {
-	m.myAnim = m.myPersona -> animation[(a * m.myPersona -> numDirections) + m.direction];
+	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
 }
 
 personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
 	personaAnimation *newP = new personaAnimation;
 	checkNew(newP);
 
-	newP -> numFrames = num;
-	newP -> frames = new animFrame[num];
-	checkNew(newP -> frames);
+	newP->numFrames = num;
+	newP->frames = new animFrame[num];
+	checkNew(newP->frames);
 
 	int a = num, frameNum, howMany;
 
 	while (a) {
 		a --;
-		newP -> frames[a].noise = 0;
-		if (stacky -> thisVar.varType == SVT_FILE) {
-			newP -> frames[a].noise = stacky -> thisVar.varData.intValue;
-		} else if (stacky -> thisVar.varType == SVT_FUNC) {
-			newP -> frames[a].noise = - stacky -> thisVar.varData.intValue;
-		} else if (stacky -> thisVar.varType == SVT_STACK) {
-			getValueType(frameNum, SVT_INT, stacky -> thisVar.varData.theStack -> first -> thisVar);
-			getValueType(howMany, SVT_INT, stacky -> thisVar.varData.theStack -> first -> next -> thisVar);
+		newP->frames[a].noise = 0;
+		if (stacky->thisVar.varType == SVT_FILE) {
+			newP->frames[a].noise = stacky->thisVar.varData.intValue;
+		} else if (stacky->thisVar.varType == SVT_FUNC) {
+			newP->frames[a].noise = - stacky->thisVar.varData.intValue;
+		} else if (stacky->thisVar.varType == SVT_STACK) {
+			getValueType(frameNum, SVT_INT, stacky->thisVar.varData.theStack->first->thisVar);
+			getValueType(howMany, SVT_INT, stacky->thisVar.varData.theStack->first->next->thisVar);
 		} else {
-			getValueType(frameNum, SVT_INT, stacky -> thisVar);
+			getValueType(frameNum, SVT_INT, stacky->thisVar);
 			howMany = 1;
 		}
 		trimStack(stacky);
-		newP -> frames[a].frameNum = frameNum;
-		newP -> frames[a].howMany = howMany;
+		newP->frames[a].frameNum = frameNum;
+		newP->frames[a].howMany = howMany;
 	}
 
 	return newP;
@@ -108,39 +108,39 @@ personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
 
 personaAnimation *makeNullAnim() {
 	personaAnimation *newAnim  = new personaAnimation;
-	if (! checkNew(newAnim)) return NULL;
+	if (!checkNew(newAnim)) return NULL;
 
 
-	newAnim -> theSprites       = NULL;
-	newAnim -> numFrames        = 0;
-	newAnim -> frames           = NULL;
+	newAnim->theSprites       = NULL;
+	newAnim->numFrames        = 0;
+	newAnim->frames           = NULL;
 	return newAnim;
 }
 
 personaAnimation *copyAnim(personaAnimation *orig) {
-	int num = orig -> numFrames;
+	int num = orig->numFrames;
 
 	personaAnimation *newAnim  = new personaAnimation;
-	if (! checkNew(newAnim)) return NULL;
+	if (!checkNew(newAnim)) return NULL;
 
 	// Copy the easy bits...
-	newAnim -> theSprites       = orig -> theSprites;
-	newAnim -> numFrames        = num;
+	newAnim->theSprites       = orig->theSprites;
+	newAnim->numFrames        = num;
 
 	if (num) {
 
-		// Argh! Frames! We need a whole NEW array of animFrame structures...
+		// Argh!Frames!We need a whole NEW array of animFrame structures...
 
 		newAnim->frames = new animFrame[num];
-		if (! checkNew(newAnim->frames)) return NULL;
+		if (!checkNew(newAnim->frames)) return NULL;
 
-		for (int a = 0; a < num; a ++) {
-			newAnim -> frames[a].frameNum = orig -> frames[a].frameNum;
-			newAnim -> frames[a].howMany = orig -> frames[a].howMany;
-			newAnim -> frames[a].noise = orig -> frames[a].noise;
+		for (int a = 0; a < num; ++a) {
+			newAnim->frames[a].frameNum = orig->frames[a].frameNum;
+			newAnim->frames[a].howMany = orig->frames[a].howMany;
+			newAnim->frames[a].noise = orig->frames[a].noise;
 		}
 	} else {
-		newAnim -> frames = NULL;
+		newAnim->frames = NULL;
 	}
 
 	return newAnim;
@@ -149,8 +149,8 @@ personaAnimation *copyAnim(personaAnimation *orig) {
 void deleteAnim(personaAnimation *orig) {
 
 	if (orig) {
-		if (orig -> numFrames) {
-			delete[] orig -> frames;
+		if (orig->numFrames) {
+			delete[] orig->frames;
 		}
 		delete orig;
 		orig = NULL;
@@ -158,11 +158,11 @@ void deleteAnim(personaAnimation *orig) {
 }
 
 void turnMeAngle(onScreenPerson *thisPerson, int direc) {
-	int d = thisPerson -> myPersona -> numDirections;
-	thisPerson -> angle = direc;
-	direc += (180 / d) + 180 + thisPerson -> angleOffset;
+	int d = thisPerson->myPersona->numDirections;
+	thisPerson->angle = direc;
+	direc += (180 / d) + 180 + thisPerson->angleOffset;
 	while (direc >= 360) direc -= 360;
-	thisPerson -> direction = (direc * d) / 360;
+	thisPerson->direction = (direc * d) / 360;
 }
 
 bool initPeople() {
@@ -175,36 +175,36 @@ bool initPeople() {
 }
 
 void spinStep(onScreenPerson *thisPerson) {
-	int diff = (thisPerson -> angle + 360) - thisPerson -> wantAngle;
-	int eachSlice = thisPerson -> spinSpeed ? thisPerson -> spinSpeed : (360 / thisPerson -> myPersona -> numDirections);
+	int diff = (thisPerson->angle + 360) - thisPerson->wantAngle;
+	int eachSlice = thisPerson->spinSpeed ? thisPerson->spinSpeed : (360 / thisPerson->myPersona->numDirections);
 	while (diff > 180) {
 		diff -= 360;
 	}
 
 	if (diff >= eachSlice) {
-		turnMeAngle(thisPerson, thisPerson -> angle - eachSlice);
+		turnMeAngle(thisPerson, thisPerson->angle - eachSlice);
 	} else if (diff <= - eachSlice) {
-		turnMeAngle(thisPerson, thisPerson -> angle + eachSlice);
+		turnMeAngle(thisPerson, thisPerson->angle + eachSlice);
 	} else {
-		turnMeAngle(thisPerson, thisPerson -> wantAngle);
-		thisPerson -> spinning = false;
+		turnMeAngle(thisPerson, thisPerson->wantAngle);
+		thisPerson->spinning = false;
 	}
 }
 
 void rethinkAngle(onScreenPerson *thisPerson) {
-	int d = thisPerson -> myPersona -> numDirections;
-	int direc = thisPerson -> angle + (180 / d) + 180 + thisPerson -> angleOffset;
+	int d = thisPerson->myPersona->numDirections;
+	int direc = thisPerson->angle + (180 / d) + 180 + thisPerson->angleOffset;
 	while (direc >= 360) direc -= 360;
-	thisPerson -> direction = (direc * d) / 360;
+	thisPerson->direction = (direc * d) / 360;
 }
 
 bool turnPersonToFace(int thisNum, int direc) {
 	onScreenPerson *thisPerson = findPerson(thisNum);
 	if (thisPerson) {
-		if (thisPerson -> continueAfterWalking) abortFunction(thisPerson -> continueAfterWalking);
-		thisPerson -> continueAfterWalking = NULL;
-		thisPerson -> walking = false;
-		thisPerson -> spinning = false;
+		if (thisPerson->continueAfterWalking) abortFunction(thisPerson->continueAfterWalking);
+		thisPerson->continueAfterWalking = NULL;
+		thisPerson->walking = false;
+		thisPerson->spinning = false;
 		turnMeAngle(thisPerson, direc);
 		setFrames(* thisPerson, (thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND);
 		return true;
@@ -215,8 +215,8 @@ bool turnPersonToFace(int thisNum, int direc) {
 bool setPersonExtra(int thisNum, int extra) {
 	onScreenPerson *thisPerson = findPerson(thisNum);
 	if (thisPerson) {
-		thisPerson -> extra = extra;
-		if (extra & EXTRA_NOSCALE) thisPerson -> scale = 1;
+		thisPerson->extra = extra;
+		if (extra & EXTRA_NOSCALE) thisPerson->scale = 1;
 		return true;
 	}
 	return false;
@@ -236,8 +236,8 @@ void moveAndScale(onScreenPerson &me, float x, float y) {
 onScreenPerson *findPerson(int v) {
 	onScreenPerson *thisPerson = allPeople;
 	while (thisPerson) {
-		if (v == thisPerson -> thisType -> objectNum) break;
-		thisPerson = thisPerson -> next;
+		if (v == thisPerson->thisType->objectNum) break;
+		thisPerson = thisPerson->next;
 	}
 	return thisPerson;
 }
@@ -249,7 +249,7 @@ void movePerson(int x, int y, int objNum) {
 
 void setShown(bool h, int ob) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (moveMe) moveMe -> show = h;
+	if (moveMe) moveMe->show = h;
 }
 
 enum drawModes {
@@ -384,14 +384,14 @@ void setMyDrawMode(onScreenPerson *moveMe, int h) {
 
 void setDrawMode(int h, int ob) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (! moveMe) return;
+	if (!moveMe) return;
 
 	setMyDrawMode(moveMe, h);
 }
 
 void setPersonTransparency(int ob, unsigned char x) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (! moveMe) return;
+	if (!moveMe) return;
 
 	if (x > 254) x = 254;
 	moveMe->transparency = x;
@@ -399,7 +399,7 @@ void setPersonTransparency(int ob, unsigned char x) {
 
 void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (! moveMe) return;
+	if (!moveMe) return;
 
 	moveMe->r = r;
 	moveMe->g = g;
@@ -415,23 +415,23 @@ void shufflePeople() {
 	onScreenPerson * * thisReference = & allPeople;
 	onScreenPerson *A, * B;
 
-	if (! allPeople) return;
+	if (!allPeople) return;
 
-	while ((* thisReference) -> next) {
-		float y1 = (* thisReference) -> y;
-		if ((* thisReference) -> extra & EXTRA_FRONT) y1 += 1000;
+	while ((* thisReference)->next) {
+		float y1 = (* thisReference)->y;
+		if ((* thisReference)->extra & EXTRA_FRONT) y1 += 1000;
 
-		float y2 = (* thisReference) -> next -> y;
-		if ((* thisReference) -> next -> extra & EXTRA_FRONT) y2 += 1000;
+		float y2 = (* thisReference)->next->y;
+		if ((* thisReference)->next->extra & EXTRA_FRONT) y2 += 1000;
 
 		if (y1 > y2) {
 			A = (* thisReference);
-			B = (* thisReference) -> next;
-			A -> next = B -> next;
-			B -> next = A;
+			B = (* thisReference)->next;
+			A->next = B->next;
+			B->next = A;
 			(* thisReference) = B;
 		} else {
-			thisReference = & ((* thisReference) -> next);
+			thisReference = & ((* thisReference)->next);
 		}
 	}
 }
@@ -446,62 +446,62 @@ void drawPeople() {
 	overRegion = NULL;
 
 	while (thisPerson) {
-		if (thisPerson -> show) {
-			myAnim = thisPerson -> myAnim;
-			if (myAnim != thisPerson -> lastUsedAnim) {
-				thisPerson -> lastUsedAnim = myAnim;
-				thisPerson -> frameNum = 0;
-				thisPerson -> frameTick = myAnim -> frames[0].howMany;
-				if (myAnim -> frames[thisPerson -> frameNum].noise > 0) {
-					startSound(myAnim -> frames[thisPerson -> frameNum].noise, false);
-					thisPerson -> frameNum ++;
-					thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames;
-					thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany;
-				} else if (myAnim -> frames[thisPerson -> frameNum].noise) {
-					startNewFunctionNum(- myAnim -> frames[thisPerson -> frameNum].noise, 0, NULL, noStack);
-					thisPerson -> frameNum ++;
-					thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames;
-					thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany;
+		if (thisPerson->show) {
+			myAnim = thisPerson->myAnim;
+			if (myAnim != thisPerson->lastUsedAnim) {
+				thisPerson->lastUsedAnim = myAnim;
+				thisPerson->frameNum = 0;
+				thisPerson->frameTick = myAnim->frames[0].howMany;
+				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
+					startSound(myAnim->frames[thisPerson->frameNum].noise, false);
+					thisPerson->frameNum ++;
+					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
+					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+				} else if (myAnim->frames[thisPerson->frameNum].noise) {
+					startNewFunctionNum(- myAnim->frames[thisPerson->frameNum].noise, 0, NULL, noStack);
+					thisPerson->frameNum ++;
+					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
+					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 				}
 			}
-			int fNumSign = myAnim -> frames[thisPerson -> frameNum].frameNum;
+			int fNumSign = myAnim->frames[thisPerson->frameNum].frameNum;
 			int m = fNumSign < 0;
 			int fNum = abs(fNumSign);
-			if (fNum >= myAnim -> theSprites -> bank.total) {
+			if (fNum >= myAnim->theSprites->bank.total) {
 				fNum = 0;
 				m = 2 - m;
 			}
 			if (m != 2) {
 				bool r = false;
-				r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim -> theSprites -> bank.myPalette, thisPerson, m);
+				r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m);
 				if (r) {
-					if (thisPerson -> thisType -> screenName[0]) {
-						if (personRegion.thisType != thisPerson -> thisType) lastRegion = NULL;
-						personRegion.thisType = thisPerson -> thisType;
+					if (thisPerson->thisType->screenName[0]) {
+						if (personRegion.thisType != thisPerson->thisType) lastRegion = NULL;
+						personRegion.thisType = thisPerson->thisType;
 						overRegion = & personRegion;
 					}
 				}
 			}
 		}
-		if (! -- thisPerson -> frameTick) {
-			thisPerson -> frameNum ++;
-			thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames;
-			thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany;
-			if (thisPerson -> show && myAnim && myAnim -> frames) {
-				if (myAnim -> frames[thisPerson -> frameNum].noise > 0) {
-					startSound(myAnim -> frames[thisPerson -> frameNum].noise, false);
-					thisPerson -> frameNum ++;
-					thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames;
-					thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany;
-				} else if (myAnim -> frames[thisPerson -> frameNum].noise) {
-					startNewFunctionNum(- myAnim -> frames[thisPerson -> frameNum].noise, 0, NULL, noStack);
-					thisPerson -> frameNum ++;
-					thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames;
-					thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany;
+		if (!-- thisPerson->frameTick) {
+			thisPerson->frameNum ++;
+			thisPerson->frameNum %= thisPerson->myAnim->numFrames;
+			thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+			if (thisPerson->show && myAnim && myAnim->frames) {
+				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
+					startSound(myAnim->frames[thisPerson->frameNum].noise, false);
+					thisPerson->frameNum ++;
+					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
+					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+				} else if (myAnim->frames[thisPerson->frameNum].noise) {
+					startNewFunctionNum(- myAnim->frames[thisPerson->frameNum].noise, 0, NULL, noStack);
+					thisPerson->frameNum ++;
+					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
+					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 				}
 			}
 		}
-		thisPerson = thisPerson -> next;
+		thisPerson = thisPerson->next;
 	}
 }
 
@@ -521,14 +521,14 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
 //	FILE * dbug = fopen ("debug_closest.txt", "at");
 //	fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY);
 
-	for (i = 0; i < currentFloor -> numPolygons; i ++) {
-		oldJ = currentFloor -> polygon[i].numVertices - 1;
-		for (j = 0; j < currentFloor -> polygon[i].numVertices; j ++) {
+	for (i = 0; i < currentFloor->numPolygons; i ++) {
+		oldJ = currentFloor->polygon[i].numVertices - 1;
+		for (j = 0; j < currentFloor->polygon[i].numVertices; j ++) {
 //			fprintf (dbug, "Polygon %i, line %i... ", i, j);
-			xTest1 = currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j]].x;
-			yTest1 = currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j]].y;
-			xTest2 = currentFloor -> vertex[currentFloor -> polygon[i].vertexID[oldJ]].x;
-			yTest2 = currentFloor -> vertex[currentFloor -> polygon[i].vertexID[oldJ]].y;
+			xTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x;
+			yTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y;
+			xTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x;
+			yTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y;
 			closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, yTest2, setX, setY);
 //			fprintf (dbug, "closest point is %i, %i... ", closestX, closestY);
 			xTest1 = setX - closestX;
@@ -537,7 +537,7 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
 //			fprintf (dbug, "Distance squared %i\n", thisDistance);
 
 			if (thisDistance < currentDistance) {
-//				fprintf (dbug, "** We have a new winner! **\n");
+//				fprintf (dbug, "** We have a new winner!**\n");
 
 				currentDistance = thisDistance;
 				gotX = closestX;
@@ -558,28 +558,28 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
 }
 
 bool doBorderStuff(onScreenPerson *moveMe) {
-	if (moveMe -> inPoly == moveMe -> walkToPoly) {
-		moveMe -> inPoly = -1;
-		moveMe -> thisStepX = moveMe -> walkToX;
-		moveMe -> thisStepY = moveMe -> walkToY;
+	if (moveMe->inPoly == moveMe->walkToPoly) {
+		moveMe->inPoly = -1;
+		moveMe->thisStepX = moveMe->walkToX;
+		moveMe->thisStepY = moveMe->walkToY;
 	} else {
 		// The section in which we need to be next...
-		int newPoly = currentFloor -> matrix[moveMe -> inPoly][moveMe -> walkToPoly];
+		int newPoly = currentFloor->matrix[moveMe->inPoly][moveMe->walkToPoly];
 		if (newPoly == -1) return false;
 
 		// Grab the index of the second matching corner...
 		int ID, ID2;
-		if (! getMatchingCorners(currentFloor -> polygon[moveMe -> inPoly], currentFloor -> polygon[newPoly], ID, ID2))
+		if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly], currentFloor->polygon[newPoly], ID, ID2))
 			return fatal("Not a valid floor plan!");
 
 		// Remember that we're walking to the new polygon...
-		moveMe -> inPoly = newPoly;
+		moveMe->inPoly = newPoly;
 
 		// Calculate the destination position on the coincidantal line...
-		int x1 = moveMe -> x, y1 = moveMe -> y;
-		int x2 = moveMe -> walkToX, y2 = moveMe -> walkToY;
-		int x3 = currentFloor -> vertex[ID].x, y3 = currentFloor -> vertex[ID].y;
-		int x4 = currentFloor -> vertex[ID2].x, y4 = currentFloor -> vertex[ID2].y;
+		int x1 = moveMe->x, y1 = moveMe->y;
+		int x2 = moveMe->walkToX, y2 = moveMe->walkToY;
+		int x3 = currentFloor->vertex[ID].x, y3 = currentFloor->vertex[ID].y;
+		int x4 = currentFloor->vertex[ID2].x, y4 = currentFloor->vertex[ID2].y;
 
 		int xAB = x1 - x2;
 		int yAB = y1 - y2;
@@ -590,8 +590,8 @@ bool doBorderStuff(onScreenPerson *moveMe) {
 		m /= ((xAB * yCD) - (yAB * xCD));
 
 		if (m > 0 && m < 1) {
-			moveMe -> thisStepX = x3 + m * xCD;
-			moveMe -> thisStepY = y3 + m * yCD;
+			moveMe->thisStepX = x3 + m * xCD;
+			moveMe->thisStepY = y3 + m * yCD;
 		} else {
 			int dx13 = x1 - x3, dx14 = x1 - x4, dx23 = x2 - x3, dx24 = x2 - x4;
 			int dy13 = y1 - y3, dy14 = y1 - y4, dy23 = y2 - y3, dy24 = y2 - y4;
@@ -607,20 +607,20 @@ bool doBorderStuff(onScreenPerson *moveMe) {
 
 			if (sqrt((double) dx13 + dy13) + sqrt((double) dx23 + dy23) <
 			        sqrt((double) dx14 + dy14) + sqrt((double) dx24 + dy24)) {
-				moveMe -> thisStepX = x3;
-				moveMe -> thisStepY = y3;
+				moveMe->thisStepX = x3;
+				moveMe->thisStepY = y3;
 			} else {
-				moveMe -> thisStepX = x4;
-				moveMe -> thisStepY = y4;
+				moveMe->thisStepX = x4;
+				moveMe->thisStepY = y4;
 			}
 		}
 	}
 
-	float yDiff = moveMe -> thisStepY - moveMe -> y;
-	float xDiff = moveMe -> x - moveMe -> thisStepX;
+	float yDiff = moveMe->thisStepY - moveMe->y;
+	float xDiff = moveMe->x - moveMe->thisStepX;
 	if (xDiff || yDiff) {
-		moveMe -> wantAngle = 180 + ANGLEFIX * atan2(xDiff, yDiff * 2);
-		moveMe -> spinning = true;
+		moveMe->wantAngle = 180 + ANGLEFIX * atan2(xDiff, yDiff * 2);
+		moveMe->spinning = true;
 	}
 
 	setFrames(* moveMe, ANI_WALK);
@@ -631,72 +631,72 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) {
 	float xDiff, yDiff, maxDiff, s;
 
 	for (;;) {
-		xDiff = thisPerson -> thisStepX - thisPerson -> x;
-		yDiff = (thisPerson -> thisStepY - thisPerson -> y) * 2;
-		s = thisPerson -> scale * thisPerson -> walkSpeed;
+		xDiff = thisPerson->thisStepX - thisPerson->x;
+		yDiff = (thisPerson->thisStepY - thisPerson->y) * 2;
+		s = thisPerson->scale * thisPerson->walkSpeed;
 		if (s < 0.2) s = 0.2;
 
 		maxDiff = (TF_abs(xDiff) >= TF_abs(yDiff)) ? TF_abs(xDiff) : TF_abs(yDiff);
 
 		if (TF_abs(maxDiff) > s) {
-			if (thisPerson -> spinning) {
+			if (thisPerson->spinning) {
 				spinStep(thisPerson);
 				setFrames(* thisPerson, ANI_WALK);
 			}
 			s = maxDiff / s;
 			if (move)
 				moveAndScale(* thisPerson,
-				             thisPerson -> x + xDiff / s,
-				             thisPerson -> y + yDiff / (s * 2));
+				             thisPerson->x + xDiff / s,
+				             thisPerson->y + yDiff / (s * 2));
 			return true;
 		}
 
-		if (thisPerson -> inPoly == -1) {
-			if (thisPerson -> directionWhenDoneWalking != -1) {
-				thisPerson -> wantAngle = thisPerson -> directionWhenDoneWalking;
-				thisPerson -> spinning = true;
+		if (thisPerson->inPoly == -1) {
+			if (thisPerson->directionWhenDoneWalking != -1) {
+				thisPerson->wantAngle = thisPerson->directionWhenDoneWalking;
+				thisPerson->spinning = true;
 				spinStep(thisPerson);
 			}
 			break;
 		}
-		if (! doBorderStuff(thisPerson)) break;
+		if (!doBorderStuff(thisPerson)) break;
 	}
 
-	thisPerson -> walking = false;
+	thisPerson->walking = false;
 	setFrames(* thisPerson, ANI_STAND);
 	moveAndScale(* thisPerson,
-	             thisPerson -> walkToX,
-	             thisPerson -> walkToY);
+	             thisPerson->walkToX,
+	             thisPerson->walkToY);
 	return false;
 }
 
 bool makeWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
 	if (x == 0 && y == 0) return false;
-	if (currentFloor -> numPolygons == 0) return false;
+	if (currentFloor->numPolygons == 0) return false;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (! moveMe) return false;
-
-	if (moveMe -> continueAfterWalking) abortFunction(moveMe -> continueAfterWalking);
-	moveMe -> continueAfterWalking = NULL;
-	moveMe -> walking = true;
-	moveMe -> directionWhenDoneWalking = di;
-
-	moveMe -> walkToX = x;
-	moveMe -> walkToY = y;
-	moveMe -> walkToPoly = inFloor(x, y);
-	if (moveMe -> walkToPoly == -1) {
-		if (! handleClosestPoint(moveMe -> walkToX, moveMe -> walkToY, moveMe -> walkToPoly)) return false;
+	if (!moveMe) return false;
+
+	if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+	moveMe->continueAfterWalking = NULL;
+	moveMe->walking = true;
+	moveMe->directionWhenDoneWalking = di;
+
+	moveMe->walkToX = x;
+	moveMe->walkToY = y;
+	moveMe->walkToPoly = inFloor(x, y);
+	if (moveMe->walkToPoly == -1) {
+		if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY, moveMe->walkToPoly)) return false;
 	}
 
-	moveMe -> inPoly = inFloor(moveMe -> x, moveMe -> y);
-	if (moveMe -> inPoly == -1) {
-		int xxx = moveMe -> x, yyy = moveMe -> y;
-		if (! handleClosestPoint(xxx, yyy, moveMe -> inPoly)) return false;
+	moveMe->inPoly = inFloor(moveMe->x, moveMe->y);
+	if (moveMe->inPoly == -1) {
+		int xxx = moveMe->x, yyy = moveMe->y;
+		if (!handleClosestPoint(xxx, yyy, moveMe->inPoly)) return false;
 	}
 
 	doBorderStuff(moveMe);
-	if (walkMe(moveMe, false) || moveMe -> spinning) {
-		moveMe -> continueAfterWalking = func;
+	if (walkMe(moveMe, false) || moveMe->spinning) {
+		moveMe->continueAfterWalking = func;
 		return true;
 	} else {
 		return false;
@@ -706,11 +706,11 @@ bool makeWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
 bool stopPerson(int o) {
 	onScreenPerson *moveMe = findPerson(o);
 	if (moveMe)
-		if (moveMe -> continueAfterWalking) {
-			abortFunction(moveMe -> continueAfterWalking);
-			moveMe -> continueAfterWalking = NULL;
-			moveMe -> walking = false;
-			moveMe -> spinning = false;
+		if (moveMe->continueAfterWalking) {
+			abortFunction(moveMe->continueAfterWalking);
+			moveMe->continueAfterWalking = NULL;
+			moveMe->walking = false;
+			moveMe->spinning = false;
 			setFrames(* moveMe, ANI_STAND);
 			return true;
 		}
@@ -720,24 +720,24 @@ bool stopPerson(int o) {
 bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
 	if (x == 0 && y == 0) return false;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (! moveMe) return false;
+	if (!moveMe) return false;
 
-	if (moveMe -> continueAfterWalking) abortFunction(moveMe -> continueAfterWalking);
-	moveMe -> walking = true;
-	moveMe -> continueAfterWalking = NULL;
-	moveMe -> directionWhenDoneWalking = di;
+	if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+	moveMe->walking = true;
+	moveMe->continueAfterWalking = NULL;
+	moveMe->directionWhenDoneWalking = di;
 
-	moveMe -> walkToX = x;
-	moveMe -> walkToY = y;
+	moveMe->walkToX = x;
+	moveMe->walkToY = y;
 
 	// Let's pretend the start and end points are both in the same
 	// polygon (which one isn't important)
-	moveMe -> inPoly = 0;
-	moveMe -> walkToPoly = 0;
+	moveMe->inPoly = 0;
+	moveMe->walkToPoly = 0;
 
 	doBorderStuff(moveMe);
-	if (walkMe(moveMe) || moveMe -> spinning) {
-		moveMe -> continueAfterWalking = func;
+	if (walkMe(moveMe) || moveMe->spinning) {
+		moveMe->continueAfterWalking = func;
 		return true;
 	} else {
 		return false;
@@ -747,26 +747,26 @@ bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di)
 void jumpPerson(int x, int y, int objNum) {
 	if (x == 0 && y == 0) return;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (! moveMe) return;
-	if (moveMe -> continueAfterWalking) abortFunction(moveMe -> continueAfterWalking);
-	moveMe -> continueAfterWalking = NULL;
-	moveMe -> walking = false;
-	moveMe -> spinning = false;
+	if (!moveMe) return;
+	if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+	moveMe->continueAfterWalking = NULL;
+	moveMe->walking = false;
+	moveMe->spinning = false;
 	moveAndScale(* moveMe, x, y);
 }
 
 bool floatCharacter(int f, int objNum) {
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (! moveMe) return false;
-	moveMe -> floaty = f;
+	if (!moveMe) return false;
+	moveMe->floaty = f;
 	return true;
 }
 
 bool setCharacterWalkSpeed(int f, int objNum) {
 	if (f <= 0) return false;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (! moveMe) return false;
-	moveMe -> walkSpeed = f;
+	if (!moveMe) return false;
+	moveMe->walkSpeed = f;
 	return true;
 }
 
@@ -774,82 +774,82 @@ void walkAllPeople() {
 	onScreenPerson *thisPerson = allPeople;
 
 	while (thisPerson) {
-		if (thisPerson -> walking) {
+		if (thisPerson->walking) {
 			walkMe(thisPerson);
-		} else if (thisPerson -> spinning) {
+		} else if (thisPerson->spinning) {
 			spinStep(thisPerson);
 			setFrames(* thisPerson, ANI_STAND);
 		}
-		if ((! thisPerson -> walking) && (! thisPerson -> spinning) && thisPerson -> continueAfterWalking) {
-			restartFunction(thisPerson -> continueAfterWalking);
-			thisPerson -> continueAfterWalking = NULL;
+		if ((!thisPerson->walking) && (!thisPerson->spinning) && thisPerson->continueAfterWalking) {
+			restartFunction(thisPerson->continueAfterWalking);
+			thisPerson->continueAfterWalking = NULL;
 		}
-		thisPerson = thisPerson -> next;
+		thisPerson = thisPerson->next;
 	}
 }
 
 bool addPerson(int x, int y, int objNum, persona *p) {
 	onScreenPerson *newPerson = new onScreenPerson;
-	if (! checkNew(newPerson)) return false;
+	if (!checkNew(newPerson)) return false;
 
 	// EASY STUFF
-	newPerson -> thisType = loadObjectType(objNum);
-	newPerson -> scale = 1;
-	newPerson -> extra = 0;
-	newPerson -> continueAfterWalking = NULL;
+	newPerson->thisType = loadObjectType(objNum);
+	newPerson->scale = 1;
+	newPerson->extra = 0;
+	newPerson->continueAfterWalking = NULL;
 	moveAndScale(* newPerson, x, y);
-	newPerson -> frameNum = 0;
-	newPerson -> walkToX = x;
-	newPerson -> walkToY = y;
-	newPerson -> walking = false;
-	newPerson -> spinning = false;
-	newPerson -> show = true;
-	newPerson -> direction = 0;
-	newPerson -> angle = 180;
-	newPerson -> wantAngle = 180;
-	newPerson -> angleOffset = 0;
-	newPerson -> floaty = 0;
-	newPerson -> walkSpeed = newPerson -> thisType -> walkSpeed;
-	newPerson -> myAnim = NULL;
-	newPerson -> spinSpeed = newPerson -> thisType -> spinSpeed;
-	newPerson -> r = 0;
-	newPerson -> g = 0;
-	newPerson -> b = 0;
-	newPerson -> colourmix = 0;
-	newPerson -> transparency = 0;
-	newPerson -> myPersona = p;
+	newPerson->frameNum = 0;
+	newPerson->walkToX = x;
+	newPerson->walkToY = y;
+	newPerson->walking = false;
+	newPerson->spinning = false;
+	newPerson->show = true;
+	newPerson->direction = 0;
+	newPerson->angle = 180;
+	newPerson->wantAngle = 180;
+	newPerson->angleOffset = 0;
+	newPerson->floaty = 0;
+	newPerson->walkSpeed = newPerson->thisType->walkSpeed;
+	newPerson->myAnim = NULL;
+	newPerson->spinSpeed = newPerson->thisType->spinSpeed;
+	newPerson->r = 0;
+	newPerson->g = 0;
+	newPerson->b = 0;
+	newPerson->colourmix = 0;
+	newPerson->transparency = 0;
+	newPerson->myPersona = p;
 
 	setFrames(* newPerson, ANI_STAND);
 
 	// HEIGHT (BASED ON 1st FRAME OF 1st ANIMATION... INC. SPECIAL CASES)
-	int fNumSigned = p -> animation[0] -> frames[0].frameNum;
+	int fNumSigned = p->animation[0]->frames[0].frameNum;
 	int fNum = abs(fNumSigned);
-	if (fNum >= p -> animation[0] -> theSprites -> bank.total) {
+	if (fNum >= p->animation[0]->theSprites->bank.total) {
 		if (fNumSigned < 0) {
-			newPerson -> height = 5;
+			newPerson->height = 5;
 		} else {
-			newPerson -> height = p -> animation[0] -> theSprites -> bank.sprites[0].yhot + 5;
+			newPerson->height = p->animation[0]->theSprites->bank.sprites[0].yhot + 5;
 		}
 	} else {
-		newPerson -> height = p -> animation[0] -> theSprites -> bank.sprites[fNum].yhot + 5;
+		newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot + 5;
 	}
 
 	// NOW ADD IT IN THE RIGHT PLACE
 	onScreenPerson * * changethat = & allPeople;
 
-	while (((* changethat) != NULL) && ((* changethat) -> y < y))
-		changethat = & ((* changethat) -> next);
+	while (((* changethat) != NULL) && ((* changethat)->y < y))
+		changethat = & ((* changethat)->next);
 
-	newPerson -> next = (* changethat);
+	newPerson->next = (* changethat);
 	(* changethat) = newPerson;
 
-	return (bool)(newPerson -> thisType != NULL);
+	return (bool)(newPerson->thisType != NULL);
 }
 
 int timeForAnim(personaAnimation *fram) {
 	int total = 0;
-	for (int a = 0; a < fram -> numFrames; a ++) {
-		total += fram -> frames[a].howMany;
+	for (int a = 0; a < fram->numFrames; ++a) {
+		total += fram->frames[a].howMany;
 	}
 	return total;
 }
@@ -857,22 +857,22 @@ int timeForAnim(personaAnimation *fram) {
 void animatePerson(int obj, personaAnimation *fram) {   // Set a new SINGLE animation
 	onScreenPerson *moveMe = findPerson(obj);
 	if (moveMe) {
-		if (moveMe -> continueAfterWalking) abortFunction(moveMe -> continueAfterWalking);
-		moveMe -> continueAfterWalking = NULL;
-		moveMe -> walking = false;
-		moveMe -> spinning = false;
-		moveMe -> myAnim = fram;
+		if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+		moveMe->continueAfterWalking = NULL;
+		moveMe->walking = false;
+		moveMe->spinning = false;
+		moveMe->myAnim = fram;
 	}
 }
 
 void animatePerson(int obj, persona *per) {             // Set a new costume
 	onScreenPerson *moveMe = findPerson(obj);
 	if (moveMe) {
-		//  if (moveMe -> continueAfterWalking) abortFunction (moveMe -> continueAfterWalking);
-		//  moveMe -> continueAfterWalking = NULL;
-		//  moveMe -> walking = false;
-		moveMe -> spinning = false;
-		moveMe -> myPersona = per;
+		//  if (moveMe->continueAfterWalking) abortFunction (moveMe->continueAfterWalking);
+		//  moveMe->continueAfterWalking = NULL;
+		//  moveMe->walking = false;
+		moveMe->spinning = false;
+		moveMe->myPersona = per;
 		rethinkAngle(moveMe);
 		if (moveMe-> walking) {
 			setFrames(* moveMe, ANI_WALK);
@@ -885,11 +885,11 @@ void animatePerson(int obj, persona *per) {             // Set a new costume
 void killAllPeople() {
 	onScreenPerson *killPeople;
 	while (allPeople) {
-		if (allPeople -> continueAfterWalking) abortFunction(allPeople -> continueAfterWalking);
-		allPeople -> continueAfterWalking = NULL;
+		if (allPeople->continueAfterWalking) abortFunction(allPeople->continueAfterWalking);
+		allPeople->continueAfterWalking = NULL;
 		killPeople = allPeople;
-		allPeople = allPeople -> next;
-		removeObjectType(killPeople -> thisType);
+		allPeople = allPeople->next;
+		removeObjectType(killPeople->thisType);
 		delete killPeople;
 	}
 }
@@ -899,18 +899,18 @@ void killMostPeople() {
 	onScreenPerson * * lookyHere = & allPeople;
 
 	while (* lookyHere) {
-		if ((* lookyHere) -> extra & EXTRA_NOREMOVE) {
-			lookyHere = & (* lookyHere) -> next;
+		if ((* lookyHere)->extra & EXTRA_NOREMOVE) {
+			lookyHere = & (* lookyHere)->next;
 		} else {
 			killPeople = (* lookyHere);
 
 			// Change last pointer to NEXT in the list instead
-			(* lookyHere) = killPeople -> next;
+			(* lookyHere) = killPeople->next;
 
 			// Gone from the list... now free some memory
-			if (killPeople -> continueAfterWalking) abortFunction(killPeople -> continueAfterWalking);
-			killPeople -> continueAfterWalking = NULL;
-			removeObjectType(killPeople -> thisType);
+			if (killPeople->continueAfterWalking) abortFunction(killPeople->continueAfterWalking);
+			killPeople->continueAfterWalking = NULL;
+			removeObjectType(killPeople->thisType);
 			delete killPeople;
 		}
 	}
@@ -924,69 +924,68 @@ void removeOneCharacter(int i) {
 			overRegion = NULL;
 		}
 
-		if (p -> continueAfterWalking) abortFunction(p -> continueAfterWalking);
-		p -> continueAfterWalking = NULL;
+		if (p->continueAfterWalking) abortFunction(p->continueAfterWalking);
+		p->continueAfterWalking = NULL;
 		onScreenPerson * * killPeople;
 
 		for (killPeople = & allPeople;
 		        * killPeople != p;
-		        killPeople = & ((* killPeople) -> next)) {
+		        killPeople = & ((* killPeople)->next)) {
 			;
 		}
 
-		* killPeople = p -> next;
-		removeObjectType(p -> thisType);
+		* killPeople = p->next;
+		removeObjectType(p->thisType);
 		delete p;
 	}
 }
 
-#if ALLOW_FILE
-bool saveAnim(personaAnimation *p, FILE *fp) {
-	put2bytes(p -> numFrames, fp);
-	if (p -> numFrames) {
-		put4bytes(p -> theSprites -> ID, fp);
+bool saveAnim(personaAnimation *p, Common::WriteStream *stream) {
+	put2bytes(p->numFrames, stream);
+	if (p->numFrames) {
+		put4bytes(p->theSprites->ID, stream);
 
-		for (int a = 0; a < p -> numFrames; a ++) {
-			put4bytes(p -> frames[a].frameNum, fp);
-			put4bytes(p -> frames[a].howMany, fp);
-			put4bytes(p -> frames[a].noise, fp);
+		for (int a = 0; a < p->numFrames; ++a) {
+			put4bytes(p->frames[a].frameNum, stream);
+			put4bytes(p->frames[a].howMany, stream);
+			put4bytes(p->frames[a].noise, stream);
 		}
 	}
 	return true;
 }
 
-bool loadAnim(personaAnimation *p, FILE *fp) {
-	p -> numFrames = get2bytes(fp);
+bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream) {
+	p->numFrames = get2bytes(stream);
 
-	if (p -> numFrames) {
-		int a = get4bytes(fp);
-		p -> frames = new animFrame[p -> numFrames];
-		if (! checkNew(p -> frames)) return false;
-		p -> theSprites = loadBankForAnim(a);
+	if (p->numFrames) {
+		int a = get4bytes(stream);
+		p->frames = new animFrame[p->numFrames];
+		if (!checkNew(p->frames)) return false;
+		p->theSprites = loadBankForAnim(a);
 
-		for (a = 0; a < p -> numFrames; a ++) {
-			p -> frames[a].frameNum = get4bytes(fp);
-			p -> frames[a].howMany = get4bytes(fp);
+		for (a = 0; a < p->numFrames; ++a) {
+			p->frames[a].frameNum = get4bytes(stream);
+			p->frames[a].howMany = get4bytes(stream);
 			if (ssgVersion >= VERSION(2, 0)) {
-				p -> frames[a].noise = get4bytes(fp);
+				p->frames[a].noise = get4bytes(stream);
 			} else {
-				p -> frames[a].noise = 0;
+				p->frames[a].noise = 0;
 			}
 		}
 	} else {
-		p -> theSprites = NULL;
-		p -> frames = NULL;
+		p->theSprites = NULL;
+		p->frames = NULL;
 	}
 	return true;
 }
 /*
 void debugCostume (char * message, persona * cossy) {
     FILE * db = fopen ("debuTURN.txt", "at");
-    fprintf (db, "  %s costume with %i directions...\n", message, cossy -> numDirections);
-    for (int a = 0; a < cossy -> numDirections * 3; a ++) {
-        fprintf (db, "      %i frames:", cossy -> animation[a] -> numFrames);
-        for (int b = 0; b < cossy -> animation[a] -> numFrames; b ++) {
-            fprintf (db, " %i", cossy -> animation[a] -> frames[b]);
+    fprintf (db, "  %s costume with %i directions...\n", message, cossy->numDirections);
+    for (int a = 0; a < cossy->numDirections * 3; ++a) {
+        fprintf (db, "      %i frames:", cossy->animation[a]->numFrames);
+        for (int b = 0; b < cossy->animation[a]->numFrames; b ++) {
+            fprintf (db, " %i", cossy->animation[a]->frames[b]);
         }
         fprintf (db, "\n");
 
@@ -994,188 +993,187 @@ void debugCostume (char * message, persona * cossy) {
     fclose (db);
 }
 */
-bool saveCostume(persona *cossy, FILE *fp) {
+bool saveCostume(persona *cossy, Common::WriteStream *stream) {
 	int a;
-	put2bytes(cossy -> numDirections, fp);
-	for (a = 0; a < cossy -> numDirections * 3; a ++) {
-		if (! saveAnim(cossy -> animation[a], fp)) return false;
+	put2bytes(cossy->numDirections, stream);
+	for (a = 0; a < cossy->numDirections * 3; ++a) {
+		if (!saveAnim(cossy->animation[a], stream)) return false;
 	}
 //	debugCostume ("Saved", cossy);
 	return true;
 }
 
-bool loadCostume(persona *cossy, FILE *fp) {
+bool loadCostume(persona *cossy, Common::SeekableReadStream *stream) {
 	int a;
-	cossy -> numDirections = get2bytes(fp);
-	cossy -> animation = new personaAnimation * [cossy -> numDirections * 3];
-	if (! checkNew(cossy -> animation)) return false;
-	for (a = 0; a < cossy -> numDirections * 3; a ++) {
-		cossy -> animation[a] = new personaAnimation;
-		if (! checkNew(cossy -> animation[a])) return false;
-
-		if (! loadAnim(cossy -> animation[a], fp)) return false;
+	cossy->numDirections = get2bytes(stream);
+	cossy->animation = new personaAnimation * [cossy->numDirections * 3];
+	if (!checkNew(cossy->animation)) return false;
+	for (a = 0; a < cossy->numDirections * 3; ++a) {
+		cossy->animation[a] = new personaAnimation;
+		if (!checkNew(cossy->animation[a])) return false;
+
+		if (!loadAnim(cossy->animation[a], stream)) return false;
 	}
 //	debugCostume ("Loaded", cossy);
 	return true;
 }
 
-bool savePeople(FILE *fp) {
+bool savePeople(Common::WriteStream *stream) {
 	onScreenPerson *me = allPeople;
 	int countPeople = 0, a;
 
-	putSigned(scaleHorizon, fp);
-	putSigned(scaleDivide, fp);
+	putSigned(scaleHorizon, stream);
+	putSigned(scaleDivide, stream);
 
 	while (me) {
 		countPeople ++;
-		me = me -> next;
+		me = me->next;
 	}
 
-	put2bytes(countPeople, fp);
+	put2bytes(countPeople, stream);
 
 	me = allPeople;
-	for (a = 0; a < countPeople; a ++) {
-
-		putFloat(me -> x, fp);
-		putFloat(me -> y, fp);
-
-		saveCostume(me -> myPersona, fp);
-		saveAnim(me -> myAnim, fp);
-		fputc(me -> myAnim == me -> lastUsedAnim, fp);
-
-		putFloat(me -> scale, fp);
-
-		put2bytes(me -> extra, fp);
-		put2bytes(me -> height, fp);
-		put2bytes(me -> walkToX, fp);
-		put2bytes(me -> walkToY, fp);
-		put2bytes(me -> thisStepX, fp);
-		put2bytes(me -> thisStepY, fp);
-		put2bytes(me -> frameNum, fp);
-		put2bytes(me -> frameTick, fp);
-		put2bytes(me -> walkSpeed, fp);
-		put2bytes(me -> spinSpeed, fp);
-		putSigned(me -> floaty, fp);
-		fputc(me -> show, fp);
-		fputc(me -> walking, fp);
-		fputc(me -> spinning, fp);
-		if (me -> continueAfterWalking) {
-			fputc(1, fp);
-			saveFunction(me -> continueAfterWalking, fp);
+	for (a = 0; a < countPeople; ++a) {
+
+		putFloat(me->x, stream);
+		putFloat(me->y, stream);
+
+		saveCostume(me->myPersona, stream);
+		saveAnim(me->myAnim, stream);
+		putch(me->myAnim == me->lastUsedAnim, stream);
+
+		putFloat(me->scale, stream);
+
+		put2bytes(me->extra, stream);
+		put2bytes(me->height, stream);
+		put2bytes(me->walkToX, stream);
+		put2bytes(me->walkToY, stream);
+		put2bytes(me->thisStepX, stream);
+		put2bytes(me->thisStepY, stream);
+		put2bytes(me->frameNum, stream);
+		put2bytes(me->frameTick, stream);
+		put2bytes(me->walkSpeed, stream);
+		put2bytes(me->spinSpeed, stream);
+		putSigned(me->floaty, stream);
+		putch(me->show, stream);
+		putch(me->walking, stream);
+		putch(me->spinning, stream);
+		if (me->continueAfterWalking) {
+			putch(1, stream);
+			saveFunction(me->continueAfterWalking, stream);
 		} else {
-			fputc(0, fp);
+			putch(0, stream);
 		}
-		put2bytes(me -> direction, fp);
-		put2bytes(me -> angle, fp);
-		put2bytes(me -> angleOffset, fp);
-		put2bytes(me -> wantAngle, fp);
-		putSigned(me -> directionWhenDoneWalking, fp);
-		putSigned(me -> inPoly, fp);
-		putSigned(me -> walkToPoly, fp);
-
-		fputc(me -> r, fp);
-		fputc(me -> g, fp);
-		fputc(me -> b, fp);
-		fputc(me -> colourmix, fp);
-		fputc(me -> transparency, fp);
-
-		saveObjectRef(me -> thisType, fp);
-
-		me = me -> next;
+		put2bytes(me->direction, stream);
+		put2bytes(me->angle, stream);
+		put2bytes(me->angleOffset, stream);
+		put2bytes(me->wantAngle, stream);
+		putSigned(me->directionWhenDoneWalking, stream);
+		putSigned(me->inPoly, stream);
+		putSigned(me->walkToPoly, stream);
+
+		putch(me->r, stream);
+		putch(me->g, stream);
+		putch(me->b, stream);
+		putch(me->colourmix, stream);
+		putch(me->transparency, stream);
+
+		saveObjectRef(me->thisType, stream);
+
+		me = me->next;
 	}
 	return true;
 }
 
-bool loadPeople(FILE *fp) {
+bool loadPeople(Common::SeekableReadStream *stream) {
 	onScreenPerson * * pointy = & allPeople;
 	onScreenPerson *me;
 
-	scaleHorizon = getSigned(fp);
-	scaleDivide = getSigned(fp);
+	scaleHorizon = getSigned(stream);
+	scaleDivide = getSigned(stream);
 
-	int countPeople = get2bytes(fp);
+	int countPeople = get2bytes(stream);
 	int a;
 
 	allPeople = NULL;
-	for (a = 0; a < countPeople; a ++) {
+	for (a = 0; a < countPeople; ++a) {
 		me = new onScreenPerson;
-		if (! checkNew(me)) return false;
-
-		me -> myPersona = new persona;
-		if (! checkNew(me -> myPersona)) return false;
-
-		me -> myAnim = new personaAnimation;
-		if (! checkNew(me -> myAnim)) return false;
-
-		me -> x = getFloat(fp);
-		me -> y = getFloat(fp);
-
-		loadCostume(me -> myPersona, fp);
-		loadAnim(me -> myAnim, fp);
-
-		me -> lastUsedAnim = fgetc(fp) ? me -> myAnim : NULL;
-
-		me -> scale = getFloat(fp);
-
-		me -> extra = get2bytes(fp);
-		me -> height = get2bytes(fp);
-		me -> walkToX = get2bytes(fp);
-		me -> walkToY = get2bytes(fp);
-		me -> thisStepX = get2bytes(fp);
-		me -> thisStepY = get2bytes(fp);
-		me -> frameNum = get2bytes(fp);
-		me -> frameTick = get2bytes(fp);
-		me -> walkSpeed = get2bytes(fp);
-		me -> spinSpeed = get2bytes(fp);
-		me -> floaty = getSigned(fp);
-		me -> show = fgetc(fp);
-		me -> walking = fgetc(fp);
-		me -> spinning = fgetc(fp);
-		if (fgetc(fp)) {
-			me -> continueAfterWalking = loadFunction(fp);
-			if (! me -> continueAfterWalking) return false;
+		if (!checkNew(me)) return false;
+
+		me->myPersona = new persona;
+		if (!checkNew(me->myPersona)) return false;
+
+		me->myAnim = new personaAnimation;
+		if (!checkNew(me->myAnim)) return false;
+
+		me->x = getFloat(stream);
+		me->y = getFloat(stream);
+
+		loadCostume(me->myPersona, stream);
+		loadAnim(me->myAnim, stream);
+
+		me->lastUsedAnim = getch(stream) ? me->myAnim : NULL;
+
+		me->scale = getFloat(stream);
+
+		me->extra = get2bytes(stream);
+		me->height = get2bytes(stream);
+		me->walkToX = get2bytes(stream);
+		me->walkToY = get2bytes(stream);
+		me->thisStepX = get2bytes(stream);
+		me->thisStepY = get2bytes(stream);
+		me->frameNum = get2bytes(stream);
+		me->frameTick = get2bytes(stream);
+		me->walkSpeed = get2bytes(stream);
+		me->spinSpeed = get2bytes(stream);
+		me->floaty = getSigned(stream);
+		me->show = getch(stream);
+		me->walking = getch(stream);
+		me->spinning = getch(stream);
+		if (getch(stream)) {
+			me->continueAfterWalking = loadFunction(stream);
+			if (!me->continueAfterWalking) return false;
 		} else {
-			me -> continueAfterWalking = NULL;
+			me->continueAfterWalking = NULL;
 		}
-		me -> direction = get2bytes(fp);
-		me -> angle = get2bytes(fp);
+		me->direction = get2bytes(stream);
+		me->angle = get2bytes(stream);
 		if (ssgVersion >= VERSION(2, 0)) {
-			me -> angleOffset = get2bytes(fp);
+			me->angleOffset = get2bytes(stream);
 		} else {
-			me -> angleOffset = 0;
+			me->angleOffset = 0;
 		}
-		me -> wantAngle = get2bytes(fp);
-		me -> directionWhenDoneWalking = getSigned(fp);
-		me -> inPoly = getSigned(fp);
-		me -> walkToPoly = getSigned(fp);
+		me->wantAngle = get2bytes(stream);
+		me->directionWhenDoneWalking = getSigned(stream);
+		me->inPoly = getSigned(stream);
+		me->walkToPoly = getSigned(stream);
 		if (ssgVersion >= VERSION(2, 0)) {
-			me -> r = fgetc(fp);
-			me -> g = fgetc(fp);
-			me -> b = fgetc(fp);
-			me -> colourmix = fgetc(fp);
-			me -> transparency = fgetc(fp);
+			me->r = getch(stream);
+			me->g = getch(stream);
+			me->b = getch(stream);
+			me->colourmix = getch(stream);
+			me->transparency = getch(stream);
 		} else {
-			setMyDrawMode(me, get2bytes(fp));
+			setMyDrawMode(me, get2bytes(stream));
 		}
-		me -> thisType = loadObjectRef(fp);
+		me->thisType = loadObjectRef(stream);
 
 		// Anti-aliasing settings
 		if (ssgVersion >= VERSION(1, 6)) {
 			if (ssgVersion < VERSION(2, 0)) {
 				// aaLoad
-				fgetc(fp);
-				getFloat(fp);
-				getFloat(fp);
+				getch(stream);
+				getFloat(stream);
+				getFloat(stream);
 			}
 		}
 
-		me -> next = NULL;
+		me->next = NULL;
 		* pointy = me;
-		pointy = & (me -> next);
+		pointy = & (me->next);
 	}
 //	db ("End of loadPeople");
 	return true;
 }
-#endif
 
 } // End of namespace Sludge
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index 11cf10b..ba726b0 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -125,14 +125,12 @@ personaAnimation *makeNullAnim();
 void deleteAnim(personaAnimation *orig);
 
 // Loading and saving
-#if ALLOW_FILE
-bool saveAnim(personaAnimation *p, FILE *fp);
-bool loadAnim(personaAnimation *p, FILE *fp);
-bool savePeople(FILE *fp);
-bool loadPeople(FILE *fp);
-bool saveCostume(persona *cossy, FILE *fp);
-bool loadCostume(persona *cossy, FILE *fp);
-#endif
+bool saveAnim(personaAnimation *p, Common::WriteStream *stream);
+bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream);
+bool savePeople(Common::WriteStream *stream);
+bool loadPeople(Common::SeekableReadStream *stream);
+bool saveCostume(persona *cossy, Common::WriteStream *stream);
+bool loadCostume(persona *cossy, Common::SeekableReadStream *stream);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp
index 8c55ece..eebcb57 100644
--- a/engines/sludge/region.cpp
+++ b/engines/sludge/region.cpp
@@ -38,11 +38,11 @@ void showBoxes() {
 	screenRegion *huntRegion = allScreenRegions;
 
 	while (huntRegion) {
-		drawVerticalLine(huntRegion -> x1, huntRegion -> y1, huntRegion -> y2);
-		drawVerticalLine(huntRegion -> x2, huntRegion -> y1, huntRegion -> y2);
-		drawHorizontalLine(huntRegion -> x1, huntRegion -> y1, huntRegion -> x2);
-		drawHorizontalLine(huntRegion -> x1, huntRegion -> y2, huntRegion -> x2);
-		huntRegion = huntRegion -> next;
+		drawVerticalLine(huntRegion->x1, huntRegion->y1, huntRegion->y2);
+		drawVerticalLine(huntRegion->x2, huntRegion->y1, huntRegion->y2);
+		drawHorizontalLine(huntRegion->x1, huntRegion->y1, huntRegion->x2);
+		drawHorizontalLine(huntRegion->x1, huntRegion->y2, huntRegion->x2);
+		huntRegion = huntRegion->next;
 	}
 }
 
@@ -51,45 +51,44 @@ void removeScreenRegion(int objectNum) {
 	screenRegion *killMe;
 
 	while (* huntRegion) {
-		if ((* huntRegion) -> thisType -> objectNum == objectNum) {
+		if ((* huntRegion)->thisType->objectNum == objectNum) {
 			killMe = * huntRegion;
-			* huntRegion = killMe -> next;
-			removeObjectType(killMe -> thisType);
+			* huntRegion = killMe->next;
+			removeObjectType(killMe->thisType);
 			if (killMe == overRegion) overRegion = NULL;
 			delete killMe;
 			killMe = NULL;
 		} else {
-			huntRegion = & ((* huntRegion) -> next);
+			huntRegion = & ((* huntRegion)->next);
 		}
 	}
 }
 
-#if ALLOW_FILE
-void saveRegions(FILE *fp) {
+void saveRegions(Common::WriteStream *stream) {
 	int numRegions = 0;
 	screenRegion *thisRegion = allScreenRegions;
 	while (thisRegion) {
-		thisRegion = thisRegion -> next;
+		thisRegion = thisRegion->next;
 		numRegions ++;
 	}
-	put2bytes(numRegions, fp);
+	put2bytes(numRegions, stream);
 	thisRegion = allScreenRegions;
 	while (thisRegion) {
-		put2bytes(thisRegion -> x1, fp);
-		put2bytes(thisRegion -> y1, fp);
-		put2bytes(thisRegion -> x2, fp);
-		put2bytes(thisRegion -> y2, fp);
-		put2bytes(thisRegion -> sX, fp);
-		put2bytes(thisRegion -> sY, fp);
-		put2bytes(thisRegion -> di, fp);
-		saveObjectRef(thisRegion -> thisType, fp);
-
-		thisRegion = thisRegion -> next;
+		put2bytes(thisRegion->x1, stream);
+		put2bytes(thisRegion->y1, stream);
+		put2bytes(thisRegion->x2, stream);
+		put2bytes(thisRegion->y2, stream);
+		put2bytes(thisRegion->sX, stream);
+		put2bytes(thisRegion->sY, stream);
+		put2bytes(thisRegion->di, stream);
+		saveObjectRef(thisRegion->thisType, stream);
+
+		thisRegion = thisRegion->next;
 	}
 }
 
-void loadRegions(FILE *fp) {
-	int numRegions = get2bytes(fp);
+void loadRegions(Common::SeekableReadStream *stream) {
+	int numRegions = get2bytes(stream);
 
 	screenRegion *newRegion;
 	screenRegion * * pointy = & allScreenRegions;
@@ -97,26 +96,26 @@ void loadRegions(FILE *fp) {
 	while (numRegions --) {
 		newRegion = new screenRegion;
 		* pointy = newRegion;
-		pointy = & (newRegion -> next);
-
-		newRegion -> x1 = get2bytes(fp);
-		newRegion -> y1 = get2bytes(fp);
-		newRegion -> x2 = get2bytes(fp);
-		newRegion -> y2 = get2bytes(fp);
-		newRegion -> sX = get2bytes(fp);
-		newRegion -> sY = get2bytes(fp);
-		newRegion -> di = get2bytes(fp);
-		newRegion -> thisType = loadObjectRef(fp);
+		pointy = & (newRegion->next);
+
+		newRegion->x1 = get2bytes(stream);
+		newRegion->y1 = get2bytes(stream);
+		newRegion->x2 = get2bytes(stream);
+		newRegion->y2 = get2bytes(stream);
+		newRegion->sX = get2bytes(stream);
+		newRegion->sY = get2bytes(stream);
+		newRegion->di = get2bytes(stream);
+		newRegion->thisType = loadObjectRef(stream);
 	}
 	* pointy = NULL;
 }
-#endif
+
 void killAllRegions() {
 	screenRegion *killRegion;
 	while (allScreenRegions) {
 		killRegion = allScreenRegions;
-		allScreenRegions = allScreenRegions -> next;
-		removeObjectType(killRegion -> thisType);
+		allScreenRegions = allScreenRegions->next;
+		removeObjectType(killRegion->thisType);
 		delete killRegion;
 	}
 	overRegion = NULL;
@@ -124,29 +123,29 @@ void killAllRegions() {
 
 bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di, int objectNum) {
 	screenRegion *newRegion = new screenRegion;
-	if (! checkNew(newRegion)) return false;
-	newRegion -> di = di;
-	newRegion -> x1 = x1;
-	newRegion -> y1 = y1;
-	newRegion -> x2 = x2;
-	newRegion -> y2 = y2;
-	newRegion -> sX = sX;
-	newRegion -> sY = sY;
-	newRegion -> thisType = loadObjectType(objectNum);
-	newRegion -> next = allScreenRegions;
+	if (!checkNew(newRegion)) return false;
+	newRegion->di = di;
+	newRegion->x1 = x1;
+	newRegion->y1 = y1;
+	newRegion->x2 = x2;
+	newRegion->y2 = y2;
+	newRegion->sX = sX;
+	newRegion->sY = sY;
+	newRegion->thisType = loadObjectType(objectNum);
+	newRegion->next = allScreenRegions;
 	allScreenRegions = newRegion;
-	return (bool)(newRegion -> thisType != NULL);
+	return (bool)(newRegion->thisType != NULL);
 }
 
 void getOverRegion() {
 	screenRegion *thisRegion = allScreenRegions;
 	while (thisRegion) {
-		if ((input.mouseX >= thisRegion -> x1 - cameraX) && (input.mouseY >= thisRegion -> y1 - cameraY) &&
-		        (input.mouseX <= thisRegion -> x2 - cameraX) && (input.mouseY <= thisRegion -> y2 - cameraY)) {
+		if ((input.mouseX >= thisRegion->x1 - cameraX) && (input.mouseY >= thisRegion->y1 - cameraY) &&
+		        (input.mouseX <= thisRegion->x2 - cameraX) && (input.mouseY <= thisRegion->y2 - cameraY)) {
 			overRegion = thisRegion;
 			return;
 		}
-		thisRegion = thisRegion -> next;
+		thisRegion = thisRegion->next;
 	}
 	overRegion = NULL;
 	return;
@@ -156,10 +155,10 @@ screenRegion *getRegionForObject(int obj) {
 	screenRegion *thisRegion = allScreenRegions;
 
 	while (thisRegion) {
-		if (obj == thisRegion -> thisType -> objectNum) {
+		if (obj == thisRegion->thisType->objectNum) {
 			return thisRegion;
 		}
-		thisRegion = thisRegion -> next;
+		thisRegion = thisRegion->next;
 	}
 
 	return NULL;
diff --git a/engines/sludge/region.h b/engines/sludge/region.h
index 52c1c58..2bc4ab6 100644
--- a/engines/sludge/region.h
+++ b/engines/sludge/region.h
@@ -34,11 +34,10 @@ bool addScreenRegion(int x1, int y1, int x2, int y2, int, int, int, int objectNu
 void getOverRegion();
 screenRegion *getRegionForObject(int obj);
 void removeScreenRegion(int objectNum);
+void loadRegions(Common::SeekableReadStream *stream);
+void saveRegions(Common::WriteStream *stream);
 void killAllRegions();
-#if ALLOW_FILE
-void loadRegions(FILE *);
-void saveRegions(FILE *);
-#endif
+
 void showBoxes();
 
 } // End of namespace Sludge
diff --git a/engines/sludge/savedata.cpp b/engines/sludge/savedata.cpp
index 79e672b..dc061c6 100644
--- a/engines/sludge/savedata.cpp
+++ b/engines/sludge/savedata.cpp
@@ -29,6 +29,8 @@
 #include "newfatal.h"
 #include "moreio.h"
 
+#include "common/file.h"
+
 #define LOAD_ERROR "Can't load custom data...\n\n"
 
 namespace Sludge {
@@ -59,107 +61,109 @@ void loadSaveDebug (int com) {
 }
 */
 
-#if ALLOW_FILE
-void writeStringEncoded(const char *s, FILE *fp) {
+void writeStringEncoded(const char *s, Common::WriteStream *stream) {
 	int a, len = strlen(s);
 
-	put2bytes(len, fp);
+	put2bytes(len, stream);
 	for (a = 0; a < len; a ++) {
-		fputc(s[a] ^ encode1, fp);
+		putch(s[a] ^ encode1, stream);
 		encode1 += encode2;
 	}
 }
 
-char *readStringEncoded(FILE *fp) {
+char *readStringEncoded(Common::File *fp) {
 	int a, len = get2bytes(fp);
 	char *s = new char[len + 1];
-	if (! checkNew(s)) return NULL;
+	if (!checkNew(s)) return NULL;
 	for (a = 0; a < len; a ++) {
-		s[a] = (char)(fgetc(fp) ^ encode1);
+		s[a] = (char)(getch(fp) ^ encode1);
 		encode1 += encode2;
 	}
 	s[len] = 0;
 	return s;
 }
 
-char *readTextPlain(FILE *fp) {
+char *readTextPlain(Common::File *fp) {
 	int32_t startPos;
 
-	int stringSize = 0;
+	uint32 stringSize = 0;
 	bool keepGoing = true;
 	char gotChar;
 	char *reply;
 
-	startPos = ftell(fp);
+	startPos = fp->pos();
 
 	while (keepGoing) {
-		gotChar = (char) fgetc(fp);
-		if ((gotChar == '\n') || (feof(fp))) {
+		gotChar = (char) getch(fp);
+		if ((gotChar == '\n') || (fp->eos())) {
 			keepGoing = false;
 		} else {
 			stringSize ++;
 		}
 	}
 
-	if ((stringSize == 0) && (feof(fp))) {
+	if ((stringSize == 0) && (fp->eos())) {
 		return NULL;
 	} else {
-		fseek(fp, startPos, SEEK_SET);
+		fp->seek(startPos, SEEK_SET);
 		reply = new char[stringSize + 1];
 		if (reply == NULL) return NULL;
-		size_t bytes_read = fread(reply, stringSize, 1, fp);
-		if (bytes_read != stringSize && ferror(fp)) {
+		size_t bytes_read = fp->read(reply, stringSize);
+		if (bytes_read != stringSize && fp->err()) {
 			debugOut("Reading error in readTextPlain.\n");
 		}
-		fgetc(fp);  // Skip the newline character
+		getch(fp);  // Skip the newline character
 		reply[stringSize] = 0;
 	}
 
 	return reply;
 }
-#endif
 
 bool fileToStack(char *filename, stackHandler *sH) {
-#if ALLOW_FILE
+
 	variable stringVar;
 	stringVar.varType = SVT_NULL;
 	const char *checker = saveEncoding ? "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";
 
-	FILE *fp = fopen(filename, "rb");
-	if (! fp) {
+	Common::File fd;
+
+	if (!fd.open(filename)) {
+#if 0
 		char currentDir[1000];
-		if (! getcwd(currentDir, 998)) {
+		if (!getcwd(currentDir, 998)) {
 			debugOut("Can't get current directory.\n");
 		}
 
 		if (chdir(gamePath)) {
 			debugOut("Error: Failed changing to directory %s\n", gamePath);
 		}
-		fp = fopen(filename, "rb");
+
 		if (chdir(currentDir)) {
 			debugOut("Error: Failed changing to directory %s\n", currentDir);
 		}
 
-		if (! fp) {
+		if (!fd.open(filename)) {
 			return fatal("No such file", filename);
 		}
+#endif
+		return fatal("No such file", filename); //TODO: false value
 	}
 
 	encode1 = (unsigned char) saveEncoding & 255;
 	encode2 = (unsigned char)(saveEncoding >> 8);
 
 	while (* checker) {
-		if (fgetc(fp) != * checker) {
-			fclose(fp);
+		if (getch(&fd) != * checker) {
+			fd.close();
 			return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", filename);
 		}
 		checker ++;
 	}
 
 	if (saveEncoding) {
-		char *checker = readStringEncoded(fp);
+		char *checker = readStringEncoded(&fd);
 		if (strcmp(checker, "UN�LO�CKED")) {
-			fclose(fp);
+			fd.close();
 			return fatal(LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", filename);
 		}
 		delete checker;
@@ -169,55 +173,55 @@ bool fileToStack(char *filename, stackHandler *sH) {
 
 	for (;;) {
 		if (saveEncoding) {
-			char i = fgetc(fp) ^ encode1;
+			char i = getch(&fd) ^ encode1;
 
-			if (feof(fp)) break;
+			if (fd.eos()) break;
 			switch (i) {
 			case 0: {
-				char *g = readStringEncoded(fp);
+				char *g = readStringEncoded(&fd);
 				makeTextVar(stringVar, g);
 				delete g;
 			}
 			break;
 
 			case 1:
-				setVariable(stringVar, SVT_INT, get4bytes(fp));
+				setVariable(stringVar, SVT_INT, get4bytes(&fd));
 				break;
 
 			case 2:
-				setVariable(stringVar, SVT_INT, fgetc(fp));
+				setVariable(stringVar, SVT_INT, getch(&fd));
 				break;
 
 			default:
 				fatal(LOAD_ERROR "Corrupt custom data file:", filename);
-				fclose(fp);
+				fd.close();
 				return false;
 			}
 		} else {
-			char *line = readTextPlain(fp);
-			if (! line) break;
+			char *line = readTextPlain(&fd);
+			if (!line) break;
 			makeTextVar(stringVar, line);
 		}
 
 		if (sH -> first == NULL) {
 			// Adds to the TOP of the array... oops!
-			if (! addVarToStackQuick(stringVar, sH -> first)) return false;
+			if (!addVarToStackQuick(stringVar, sH -> first)) return false;
 			sH -> last = sH -> first;
 		} else {
 			// Adds to the END of the array... much better
-			if (! addVarToStackQuick(stringVar, sH -> last -> next)) return false;
+			if (!addVarToStackQuick(stringVar, sH -> last -> next)) return false;
 			sH -> last = sH -> last -> next;
 		}
 	}
-	fclose(fp);
-#endif
+	fd.close();
+
 	return true;
 }
 
 bool stackToFile(char *filename, const variable &from) {
-#if ALLOW_FILE
+#if 0
 	FILE *fp = fopen(filename, saveEncoding ? "wb" : "wt");
-	if (! fp) return fatal("Can't create file", filename);
+	if (!fp) return fatal("Can't create file", filename);
 
 	variableStack *hereWeAre = from.varData.theStack -> first;
 
diff --git a/engines/sludge/shaders.cpp b/engines/sludge/shaders.cpp
index e11a834..cd95079 100644
--- a/engines/sludge/shaders.cpp
+++ b/engines/sludge/shaders.cpp
@@ -33,37 +33,32 @@ extern char *bundleFolder;
 //Read in a textfile (GLSL program)
 // we need to pass it as a string to the GLSL driver
 char *shaderFileRead(const char *name) {
-	FILE *fp;
+	Common::File fd;
 	char *content = NULL;
 	char *fn = joinStrings(bundleFolder, name);
 
 	int count = 0;
 
 	if (fn != NULL) {
+		if (fd.open(fn)) {
 
-		fp = fopen(fn, "rt");
-
-		if (fp != NULL) {
-
-			fseek(fp, 0, SEEK_END);
-			count = ftell(fp);
-			rewind(fp);
+			fd.seek(0, SEEK_END);
+			count = fd.pos();
+			fd.seek(0);
 
 			if (count > 0) {
 				content = (char *)malloc(sizeof(char) * (count + 1));
-				count = fread(content, sizeof(char), count, fp);
+				count = fd.read(content, sizeof(char) * count);
 				content[count] = '\0';
 			}
-			fclose(fp);
-
+			fd.close();
 		}
 	}
-
 	delete fn;
-
 	return content;
 }
 
+#if 0
 static void
 printShaderInfoLog(GLuint shader) {
 	GLint     infologLength = 0;
@@ -116,12 +111,14 @@ printProgramInfoLog(GLuint program) {
 	}
 	printOpenGLError();   // Check for OpenGL errors
 }
+#endif
 
 int buildShaders(const char *vertexShader, const char *fragmentShader) {
+#if 0
 	GLuint VS, FS, prog;
 	GLint vertCompiled, fragCompiled;
 	GLint linked;
-#if 0
+
 	// Create Shader Objects
 	VS = glCreateShader(GL_VERTEX_SHADER);
 	FS = glCreateShader(GL_FRAGMENT_SHADER);
@@ -145,10 +142,10 @@ int buildShaders(const char *vertexShader, const char *fragmentShader) {
 	printOpenGLError();
 	glGetShaderiv(FS, GL_COMPILE_STATUS, &fragCompiled);
 	printShaderInfoLog(FS);
-#endif
+
 	if (!vertCompiled || !fragCompiled)
 		return 0;
-
+#endif
 	debugOut("\nShaders compiled. \n");
 
 #if 0
@@ -166,13 +163,15 @@ int buildShaders(const char *vertexShader, const char *fragmentShader) {
 	printOpenGLError();
 	glGetProgramiv(prog, GL_LINK_STATUS, &linked);
 	printProgramInfoLog(prog);
-#endif
+
 	if (!linked)
 		return 0;
 
 	debugOut("Shader program linked. \n");
 
 	return prog;
+#endif
+	return 0; //TODO: false value
 }
 
 } // End of namespace Sludge
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 02a27f1..5202168 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -127,55 +127,55 @@ const char *sludgeText[] = { "?????", "RETURN", "BRANCH", "BR_ZERO", "SET_GLOBAL
                              "INC_LOCAL", "DEC_LOCAL", "INC_GLOBAL", "DEC_GLOBAL", "INDEXSET", "INDEXGET",
                              "INC_INDEX", "DEC_INDEX", "QUICK_PUSH"
                            };
-#if ALLOW_FILE
-void loadHandlers(FILE *fp) {
-	currentEvents -> leftMouseFunction      = get2bytes(fp);
-	currentEvents -> leftMouseUpFunction    = get2bytes(fp);
-	currentEvents -> rightMouseFunction     = get2bytes(fp);
-	currentEvents -> rightMouseUpFunction   = get2bytes(fp);
-	currentEvents -> moveMouseFunction      = get2bytes(fp);
-	currentEvents -> focusFunction          = get2bytes(fp);
-	currentEvents -> spaceFunction          = get2bytes(fp);
+
+void loadHandlers(Common::SeekableReadStream *stream) {
+	currentEvents->leftMouseFunction      = get2bytes(stream);
+	currentEvents->leftMouseUpFunction    = get2bytes(stream);
+	currentEvents->rightMouseFunction     = get2bytes(stream);
+	currentEvents->rightMouseUpFunction   = get2bytes(stream);
+	currentEvents->moveMouseFunction      = get2bytes(stream);
+	currentEvents->focusFunction          = get2bytes(stream);
+	currentEvents->spaceFunction          = get2bytes(stream);
 }
 
-void saveHandlers(FILE *fp) {
-	put2bytes(currentEvents -> leftMouseFunction,      fp);
-	put2bytes(currentEvents -> leftMouseUpFunction,    fp);
-	put2bytes(currentEvents -> rightMouseFunction,     fp);
-	put2bytes(currentEvents -> rightMouseUpFunction,   fp);
-	put2bytes(currentEvents -> moveMouseFunction,      fp);
-	put2bytes(currentEvents -> focusFunction,          fp);
-	put2bytes(currentEvents -> spaceFunction,          fp);
+void saveHandlers(Common::WriteStream *stream) {
+	put2bytes(currentEvents->leftMouseFunction,      stream);
+	put2bytes(currentEvents->leftMouseUpFunction,    stream);
+	put2bytes(currentEvents->rightMouseFunction,     stream);
+	put2bytes(currentEvents->rightMouseUpFunction,   stream);
+	put2bytes(currentEvents->moveMouseFunction,      stream);
+	put2bytes(currentEvents->focusFunction,          stream);
+	put2bytes(currentEvents->spaceFunction,          stream);
 }
 
-FILE *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion) {
-	FILE *fp = fopen(filename, "rb");
-	if (! fp) {
+Common::File *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion) {
+	Common::File *fp = new Common::File();
+	if (!fp->open(filename)) {
 		fatal("Can't open file", filename);
 		return NULL;
 	}
 	bool headerBad = false;
-	if (fgetc(fp) != 'S') headerBad = true;
-	if (fgetc(fp) != 'L') headerBad = true;
-	if (fgetc(fp) != 'U') headerBad = true;
-	if (fgetc(fp) != 'D') headerBad = true;
-	if (fgetc(fp) != extra1) headerBad = true;
-	if (fgetc(fp) != extra2) headerBad = true;
+	if (getch(fp) != 'S') headerBad = true;
+	if (getch(fp) != 'L') headerBad = true;
+	if (getch(fp) != 'U') headerBad = true;
+	if (getch(fp) != 'D') headerBad = true;
+	if (getch(fp) != extra1) headerBad = true;
+	if (getch(fp) != extra2) headerBad = true;
 	if (headerBad) {
 		fatal(er, filename);
 		return NULL;
 	}
 	char c;
-	c = fgetc(fp);
-	debug(c);
-	while (c = fgetc(fp)) {
-		putchar(c);
+	c = getch(fp);
+	debug("%c", c);
+	while ((c = getch(fp))) {
+		debug("%c", c);
 	}
 
-	int majVersion = fgetc(fp);
-	printf("$majVersion %i\n", majVersion);
-	int minVersion = fgetc(fp);
-	printf("$minVersion %i\n", minVersion);
+	int majVersion = getch(fp);
+	debug(kSludgeDebugDataLoad, "majVersion %i", majVersion);
+	int minVersion = getch(fp);
+	debug(kSludgeDebugDataLoad, "minVersion %i", minVersion);
 	fileVersion = majVersion * 256 + minVersion;
 
 	char txtVer[120];
@@ -191,89 +191,83 @@ FILE *openAndVerify(char *filename, char extra1, char extra2, const char *er, in
 	}
 	return fp;
 }
-#endif
 
 bool initSludge(char *filename) {
 	int a = 0;
 	mouseCursorAnim = makeNullAnim();
 
-#if ALLOW_FILE
-	FILE *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion);
-	if (! fp) return false;
+	Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion);
+	if (!fp) return false;
 
-	char c = fgetc(fp);
-	putchar(c);
+	char c = getch(fp);
 	if (c) {
 		numBIFNames = get2bytes(fp);
-		printf("numBIFNames %i\n", numBIFNames);
+		debug(kSludgeDebugDataLoad, "numBIFNames %i", numBIFNames);
 		allBIFNames = new char *[numBIFNames];
-		if (! checkNew(allBIFNames)) return false;
+		if (!checkNew(allBIFNames)) return false;
 
 		for (int fn = 0; fn < numBIFNames; fn ++) {
 			allBIFNames[fn] = readString(fp);
-			printf("%s\n", allBIFNames[fn]);
 		}
 		numUserFunc = get2bytes(fp);
-		printf("numUserFunc %i\n", numUserFunc);
+		debug(kSludgeDebugDataLoad, "numUserFunc %i", numUserFunc);
 		allUserFunc = new char *[numUserFunc];
-		if (! checkNew(allUserFunc)) return false;
+		if (!checkNew(allUserFunc)) return false;
 
 		for (int fn = 0; fn < numUserFunc; fn ++) {
 			allUserFunc[fn] = readString(fp);
-			printf("%s\n", allUserFunc[fn]);
 		}
 		if (gameVersion >= VERSION(1, 3)) {
 			numResourceNames = get2bytes(fp);
-			printf("numResourceNames %i\n", numResourceNames);
+			debug(kSludgeDebugDataLoad, "numResourceNames %i", numResourceNames);
 			allResourceNames = new char *[numResourceNames];
-			if (! checkNew(allResourceNames)) return false;
+			if (!checkNew(allResourceNames)) return false;
 
 			for (int fn = 0; fn < numResourceNames; fn ++) {
 				allResourceNames[fn] = readString(fp);
-				printf("%s\n", allResourceNames[fn]);
 			}
 		}
 	}
 
 	winWidth = get2bytes(fp);
-	printf("winWidth : %i\n", winWidth);
+	debug(kSludgeDebugDataLoad, "winWidth : %i", winWidth);
 	winHeight = get2bytes(fp);
-	printf("winHeight : %i\n", winHeight);
-	specialSettings = fgetc(fp);
-	printf("specialSettings : %i\n", specialSettings);
-	desiredfps = 1000 / fgetc(fp);
+	debug(kSludgeDebugDataLoad, "winHeight : %i", winHeight);
+	specialSettings = getch(fp);
+	debug(kSludgeDebugDataLoad, "specialSettings : %i", specialSettings);
+	desiredfps = 1000 / getch(fp);
 
 	delete[] readString(fp);  // Unused - was used for registration purposes.
 
-	size_t bytes_read = fread(& fileTime, sizeof(FILETIME), 1, fp);
-	if (bytes_read != sizeof(FILETIME) && ferror(fp)) {
-		debugOut("Reading error in initSludge.\n");
+	size_t bytes_read = fp->read(&fileTime, sizeof(FILETIME));
+	if (bytes_read != sizeof(FILETIME) && fp->err()) {
+		debug("Reading error in initSludge.");
 	}
 
 	char *dataFol = (gameVersion >= VERSION(1, 3)) ? readString(fp) : joinStrings("", "");
-	printf("dataFol : %s\n", dataFol);
+	debug(kSludgeDebugDataLoad, "dataFol : %s", dataFol);
 
-	gameSettings.numLanguages = (gameVersion >= VERSION(1, 3)) ? (fgetc(fp)) : 0;
-	printf("numLanguages : %c\n", gameSettings.numLanguages);
+	gameSettings.numLanguages = (gameVersion >= VERSION(1, 3)) ? (getch(fp)) : 0;
+	debug(kSludgeDebugDataLoad, "numLanguages : %c", gameSettings.numLanguages);
 	makeLanguageTable(fp);
 
 	if (gameVersion >= VERSION(1, 6)) {
-		fgetc(fp);
+		getch(fp);
 		// aaLoad
-		fgetc(fp);
+		getch(fp);
 		getFloat(fp);
 		getFloat(fp);
 	}
 
 	char *checker = readString(fp);
-	debug(kSludgeDebugDataLoad, "checker : %s\n", checker);
+	debug(kSludgeDebugDataLoad, "checker : %s", checker);
 
 	if (strcmp(checker, "okSoFar")) return fatal(ERROR_BAD_HEADER, filename);
 	delete checker;
 	checker = NULL;
 
-	unsigned char customIconLogo = fgetc(fp);
-	kSludgeDebugDataLoad(kSludgeDebugDataLoad, "Game icon: %i", customIconLogo);
+	unsigned char customIconLogo = getch(fp);
+	debug(kSludgeDebugDataLoad, "Game icon type: %i", customIconLogo);
 
 	if (customIconLogo & 1) {
 		// There is an icon - read it!
@@ -346,7 +340,7 @@ bool initSludge(char *filename) {
 		}
 
 		gameIcon = new unsigned char [iconW * iconH * 4];
-		if (! gameIcon) return fatal("Can't reserve memory for game icon.");
+		if (!gameIcon) return fatal("Can't reserve memory for game icon.");
 
 		int32_t transCol = 63519;
 		Uint8 *p = (Uint8 *) gameIcon;
@@ -388,8 +382,8 @@ bool initSludge(char *filename) {
 	if (customIconLogo & 2) {
 		// There is an logo - read it!
 		debug(kSludgeDebugDataLoad, "There is an logo - read it!");
+#if 0
 		int n;
-
 		long file_pointer = ftell(fp);
 
 		png_structp png_ptr;
@@ -402,7 +396,7 @@ bool initSludge(char *filename) {
 		char tmp[10];
 		bytes_read = fread(tmp, 1, 8, fp);
 		if (bytes_read != 8 && ferror(fp)) {
-			debugOut("Reading error in initSludge.\n");
+			debugOut("Reading error in initSludge.");
 		}
 		if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
 			// No, it's old-school HSI
@@ -463,7 +457,7 @@ bool initSludge(char *filename) {
 		if ((logoW != 310) || (logoH != 88)) return fatal("Game logo have wrong dimensions. (Should be 310x88)");
 
 		gameLogo = new unsigned char [logoW * logoH * 4];
-		if (! gameLogo) return fatal("Can't reserve memory for game logo.");
+		if (!gameLogo) return fatal("Can't reserve memory for game logo.");
 
 		// int32_t transCol = 63519;
 		Uint8 *p = (Uint8 *) gameLogo;
@@ -506,13 +500,14 @@ bool initSludge(char *filename) {
 				}
 			}
 		}
+#endif
 	}
 
 	numGlobals = get2bytes(fp);
-	printf("numGlobals : %i\n", numGlobals);
+	debug("numGlobals : %i", numGlobals);
 
 	globalVars = new variable[numGlobals];
-	if (! checkNew(globalVars)) return false;
+	if (!checkNew(globalVars)) return false;
 	for (a = 0; a < numGlobals; a ++) initVarNew(globalVars[a]);
 
 	// Get the original (untranslated) name of the game and convert it to Unicode.
@@ -524,8 +519,9 @@ bool initSludge(char *filename) {
 
 	delete gameNameOrig;
 
-	changeToUserDir();
 #if 0
+	changeToUserDir();
+
 #ifdef _WIN32
 	mkdir(gameName);
 #else
@@ -542,11 +538,13 @@ bool initSludge(char *filename) {
 	// There's no startup window on Linux and respecting this
 	// option from the ini file would disable commandline options.
 #if defined __unix__ && !(defined __APPLE__)
-	if (! showSetupWindow()) return 0;
+#if 0
+	if (!showSetupWindow()) return 0;
+#endif
 	saveIniFile(filename);
 #else
-	if (! gameSettings.noStartWindow) {
-		if (! showSetupWindow()) return 0;
+	if (!gameSettings.noStartWindow) {
+		if (!showSetupWindow()) return 0;
 		saveIniFile(filename);
 	}
 #endif
@@ -571,7 +569,7 @@ bool initSludge(char *filename) {
 	}
 
 	positionStatus(10, winHeight - 15);
-#endif
+
 	return true;
 }
 
@@ -740,16 +738,16 @@ void pauseFunction(loadedFunction *fun) {
 	loadedFunction * * huntAndDestroy = & allRunningFunctions;
 	while (* huntAndDestroy) {
 		if (fun == * huntAndDestroy) {
-			(* huntAndDestroy) = (* huntAndDestroy) -> next;
+			(* huntAndDestroy) = (* huntAndDestroy)->next;
 			fun->next = NULL;
 		} else {
-			huntAndDestroy = & (* huntAndDestroy) -> next;
+			huntAndDestroy = & (* huntAndDestroy)->next;
 		}
 	}
 }
 
 void restartFunction(loadedFunction *fun) {
-	fun -> next = allRunningFunctions;
+	fun->next = allRunningFunctions;
 	allRunningFunctions = fun;
 }
 
@@ -757,11 +755,11 @@ void killSpeechTimers() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction -> freezerLevel == 0 && thisFunction -> isSpeech && thisFunction -> timeLeft) {
-			thisFunction -> timeLeft = 0;
-			thisFunction -> isSpeech = false;
+		if (thisFunction->freezerLevel == 0 && thisFunction->isSpeech && thisFunction->timeLeft) {
+			thisFunction->timeLeft = 0;
+			thisFunction->isSpeech = false;
 		}
-		thisFunction = thisFunction -> next;
+		thisFunction = thisFunction->next;
 	}
 
 	killAllSpeech();
@@ -771,8 +769,8 @@ void completeTimers() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction -> freezerLevel == 0) thisFunction -> timeLeft = 0;
-		thisFunction = thisFunction -> next;
+		if (thisFunction->freezerLevel == 0) thisFunction->timeLeft = 0;
+		thisFunction = thisFunction->next;
 	}
 }
 
@@ -780,11 +778,11 @@ void finishFunction(loadedFunction *fun) {
 	int a;
 
 	pauseFunction(fun);
-	if (fun -> stack) fatal(ERROR_NON_EMPTY_STACK);
-	delete fun -> compiledLines;
-	for (a = 0; a < fun -> numLocals; a ++) unlinkVar(fun -> localVars[a]);
-	delete fun -> localVars;
-	unlinkVar(fun -> reg);
+	if (fun->stack) fatal(ERROR_NON_EMPTY_STACK);
+	delete fun->compiledLines;
+	for (a = 0; a < fun->numLocals; a ++) unlinkVar(fun->localVars[a]);
+	delete fun->localVars;
+	unlinkVar(fun->reg);
 	delete fun;
 	fun = NULL;
 }
@@ -793,12 +791,12 @@ void abortFunction(loadedFunction *fun) {
 	int a;
 
 	pauseFunction(fun);
-	while (fun -> stack) trimStack(fun -> stack);
-	delete fun -> compiledLines;
-	for (a = 0; a < fun -> numLocals; a ++) unlinkVar(fun -> localVars[a]);
-	delete fun -> localVars;
-	unlinkVar(fun -> reg);
-	if (fun -> calledBy) abortFunction(fun -> calledBy);
+	while (fun->stack) trimStack(fun->stack);
+	delete fun->compiledLines;
+	for (a = 0; a < fun->numLocals; a ++) unlinkVar(fun->localVars[a]);
+	delete fun->localVars;
+	unlinkVar(fun->reg);
+	if (fun->calledBy) abortFunction(fun->calledBy);
 	delete fun;
 	fun = NULL;
 }
@@ -809,12 +807,12 @@ int cancelAFunction(int funcNum, loadedFunction *myself, bool &killedMyself) {
 
 	loadedFunction *fun = allRunningFunctions;
 	while (fun) {
-		if (fun -> originalNumber == funcNum) {
-			fun -> cancelMe = true;
+		if (fun->originalNumber == funcNum) {
+			fun->cancelMe = true;
 			n ++;
 			if (fun == myself) killedMyself = true;
 		}
-		fun = fun -> next;
+		fun = fun->next;
 	}
 	return n;
 }
@@ -823,12 +821,12 @@ void freezeSubs() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction -> unfreezable) {
+		if (thisFunction->unfreezable) {
 			//msgBox ("SLUDGE debugging bollocks!", "Trying to freeze an unfreezable function!");
 		} else {
-			thisFunction -> freezerLevel ++;
+			thisFunction->freezerLevel ++;
 		}
-		thisFunction = thisFunction -> next;
+		thisFunction = thisFunction->next;
 	}
 }
 
@@ -836,8 +834,8 @@ void unfreezeSubs() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction -> freezerLevel) thisFunction -> freezerLevel --;
-		thisFunction = thisFunction -> next;
+		if (thisFunction->freezerLevel) thisFunction->freezerLevel --;
+		thisFunction = thisFunction->next;
 	}
 }
 
@@ -848,25 +846,25 @@ bool continueFunction(loadedFunction *fun) {
 	unsigned int param;
 	sludgeCommand com;
 
-	if (fun -> cancelMe) {
+	if (fun->cancelMe) {
 		abortFunction(fun);
 		return true;
 	}
 
-//	if (numBIFNames) newDebug ("*** Function:", allUserFunc[fun -> originalNumber]);
+//	if (numBIFNames) newDebug ("*** Function:", allUserFunc[fun->originalNumber]);
 
 	//debugOut ("SLUDGER: continueFunction\n");
 
 	while (keepLooping) {
 		advanceNow = true;
-		param = fun -> compiledLines[fun -> runThisLine].param;
-		com = fun -> compiledLines[fun -> runThisLine].theCommand;
+		param = fun->compiledLines[fun->runThisLine].param;
+		com = fun->compiledLines[fun->runThisLine].theCommand;
 //		fprintf (stderr, "com: %d param: %d (%s)\n", com, param,
 //				(com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE); fflush(stderr);
 
 		if (numBIFNames) {
 			setFatalInfo(
-			    (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function",
+			    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
 			    (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE);
 //			newDebug (
 //				(com < numSludgeCommands) ? sludgeText[com] : "Unknown SLUDGE machine code",
@@ -877,9 +875,9 @@ bool continueFunction(loadedFunction *fun) {
 
 		switch (com) {
 		case SLU_RETURN:
-			if (fun -> calledBy) {
-				loadedFunction *returnTo = fun -> calledBy;
-				if (fun -> returnSomething) copyVariable(fun -> reg, returnTo -> reg);
+			if (fun->calledBy) {
+				loadedFunction *returnTo = fun->calledBy;
+				if (fun->returnSomething) copyVariable(fun->reg, returnTo->reg);
 				finishFunction(fun);
 				fun = returnTo;
 				restartFunction(fun);
@@ -891,20 +889,21 @@ bool continueFunction(loadedFunction *fun) {
 			break;
 
 		case SLU_CALLIT:
-			switch (fun -> reg.varType) {
+			switch (fun->reg.varType) {
 			case SVT_FUNC:
 				pauseFunction(fun);
 				if (numBIFNames) setFatalInfo(
-					    (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function",
-					    (fun -> reg.varData.intValue < numUserFunc) ? allUserFunc[fun -> reg.varData.intValue] : "Unknown user function");
+					    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
+					    (fun->reg.varData.intValue < numUserFunc) ? allUserFunc[fun->reg.varData.intValue] : "Unknown user function");
 
-				if (! startNewFunctionNum(fun -> reg.varData.intValue, param, fun, fun -> stack)) return false;
+				if (!startNewFunctionNum(fun->reg.varData.intValue, param, fun, fun->stack)) return false;
 				fun = allRunningFunctions;
 				advanceNow = false;     // So we don't do anything else with "fun"
 				break;
 
 			case SVT_BUILT: {
-				builtReturn br = callBuiltIn(fun -> reg.varData.intValue, param, fun);
+				debug(kSludgeDebugStackMachine, "Built-in init value: %i", fun->reg.varData.intValue);
+				builtReturn br = callBuiltIn(fun->reg.varData.intValue, param, fun);
 
 				switch (br) {
 				case BR_ERROR:
@@ -924,13 +923,13 @@ bool continueFunction(loadedFunction *fun) {
 					break;
 
 				case BR_CALLAFUNC: {
-					int i = fun -> reg.varData.intValue;
-					setVariable(fun -> reg, SVT_INT, 1);
+					int i = fun->reg.varData.intValue;
+					setVariable(fun->reg, SVT_INT, 1);
 					pauseFunction(fun);
 					if (numBIFNames) setFatalInfo(
-						    (fun -> originalNumber < numUserFunc) ? allUserFunc[fun -> originalNumber] : "Unknown user function",
+						    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
 						    (i < numUserFunc) ? allUserFunc[i] : "Unknown user function");
-					if (! startNewFunctionNum(i, 0, fun, noStack, false)) return false;
+					if (!startNewFunctionNum(i, 0, fun, noStack, false)) return false;
 					fun = allRunningFunctions;
 					advanceNow = false;     // So we don't do anything else with "fun"
 				}
@@ -950,41 +949,41 @@ bool continueFunction(loadedFunction *fun) {
 		// These all grab things and shove 'em into the register
 
 		case SLU_LOAD_NULL:
-			setVariable(fun -> reg, SVT_NULL, 0);
+			setVariable(fun->reg, SVT_NULL, 0);
 			break;
 
 		case SLU_LOAD_FILE:
-			setVariable(fun -> reg, SVT_FILE, param);
+			setVariable(fun->reg, SVT_FILE, param);
 			break;
 
 		case SLU_LOAD_VALUE:
-			setVariable(fun -> reg, SVT_INT, param);
+			setVariable(fun->reg, SVT_INT, param);
 			break;
 
 		case SLU_LOAD_LOCAL:
-			if (! copyVariable(fun -> localVars[param], fun -> reg)) return false;
+			if (!copyVariable(fun->localVars[param], fun->reg)) return false;
 			break;
 
 		case SLU_AND:
-			setVariable(fun -> reg, SVT_INT, getBoolean(fun -> reg) && getBoolean(fun -> stack -> thisVar));
-			trimStack(fun -> stack);
+			setVariable(fun->reg, SVT_INT, getBoolean(fun->reg) && getBoolean(fun->stack->thisVar));
+			trimStack(fun->stack);
 			break;
 
 		case SLU_OR:
-			setVariable(fun -> reg, SVT_INT, getBoolean(fun -> reg) || getBoolean(fun -> stack -> thisVar));
-			trimStack(fun -> stack);
+			setVariable(fun->reg, SVT_INT, getBoolean(fun->reg) || getBoolean(fun->stack->thisVar));
+			trimStack(fun->stack);
 			break;
 
 		case SLU_LOAD_FUNC:
-			setVariable(fun -> reg, SVT_FUNC, param);
+			setVariable(fun->reg, SVT_FUNC, param);
 			break;
 
 		case SLU_LOAD_BUILT:
-			setVariable(fun -> reg, SVT_BUILT, param);
+			setVariable(fun->reg, SVT_BUILT, param);
 			break;
 
 		case SLU_LOAD_OBJTYPE:
-			setVariable(fun -> reg, SVT_OBJTYPE, param);
+			setVariable(fun->reg, SVT_OBJTYPE, param);
 			break;
 
 		case SLU_UNREG:
@@ -992,7 +991,7 @@ bool continueFunction(loadedFunction *fun) {
 			break;
 
 		case SLU_LOAD_STRING:
-			if (! loadStringToVar(fun -> reg, param)) {
+			if (!loadStringToVar(fun->reg, param)) {
 				return false;
 			}
 			break;
@@ -1000,11 +999,11 @@ bool continueFunction(loadedFunction *fun) {
 		case SLU_INDEXGET:
 		case SLU_INCREMENT_INDEX:
 		case SLU_DECREMENT_INDEX:
-			switch (fun -> stack -> thisVar.varType) {
+			switch (fun->stack->thisVar.varType) {
 			case SVT_NULL:
 				if (com == SLU_INDEXGET) {
-					setVariable(fun -> reg, SVT_NULL, 0);
-					trimStack(fun -> stack);
+					setVariable(fun->reg, SVT_NULL, 0);
+					trimStack(fun->stack);
 				} else {
 					return fatal(ERROR_INCDEC_UNKNOWN);
 				}
@@ -1012,37 +1011,37 @@ bool continueFunction(loadedFunction *fun) {
 
 			case SVT_FASTARRAY:
 			case SVT_STACK:
-				if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+				if (fun->stack->thisVar.varData.theStack->first == NULL) {
 					return fatal(ERROR_INDEX_EMPTY);
 				} else {
 					int ii;
-					if (! getValueType(ii, SVT_INT, fun -> reg)) return false;
-					variable *grab = (fun -> stack -> thisVar.varType == SVT_FASTARRAY) ?
-					                 fastArrayGetByIndex(fun -> stack -> thisVar.varData.fastArray, ii)
+					if (!getValueType(ii, SVT_INT, fun->reg)) return false;
+					variable *grab = (fun->stack->thisVar.varType == SVT_FASTARRAY) ?
+					                 fastArrayGetByIndex(fun->stack->thisVar.varData.fastArray, ii)
 					                 :
-					                 stackGetByIndex(fun -> stack -> thisVar.varData.theStack -> first, ii);
+					                 stackGetByIndex(fun->stack->thisVar.varData.theStack->first, ii);
 
-					trimStack(fun -> stack);
+					trimStack(fun->stack);
 
-					if (! grab) {
-						setVariable(fun -> reg, SVT_NULL, 0);
+					if (!grab) {
+						setVariable(fun->reg, SVT_NULL, 0);
 					} else {
 						int ii;
 						switch (com) {
 						case SLU_INCREMENT_INDEX:
-							if (! getValueType(ii, SVT_INT, * grab)) return false;
-							setVariable(fun -> reg, SVT_INT, ii);
-							grab -> varData.intValue = ii + 1;
+							if (!getValueType(ii, SVT_INT, * grab)) return false;
+							setVariable(fun->reg, SVT_INT, ii);
+							grab->varData.intValue = ii + 1;
 							break;
 
 						case SLU_DECREMENT_INDEX:
-							if (! getValueType(ii, SVT_INT, * grab)) return false;
-							setVariable(fun -> reg, SVT_INT, ii);
-							grab -> varData.intValue = ii - 1;
+							if (!getValueType(ii, SVT_INT, * grab)) return false;
+							setVariable(fun->reg, SVT_INT, ii);
+							grab->varData.intValue = ii - 1;
 							break;
 
 						default:
-							if (! copyVariable(* grab, fun -> reg)) return false;
+							if (!copyVariable(* grab, fun->reg)) return false;
 						}
 					}
 				}
@@ -1054,29 +1053,29 @@ bool continueFunction(loadedFunction *fun) {
 			break;
 
 		case SLU_INDEXSET:
-			switch (fun -> stack -> thisVar.varType) {
+			switch (fun->stack->thisVar.varType) {
 			case SVT_STACK:
-				if (fun -> stack -> thisVar.varData.theStack -> first == NULL) {
+				if (fun->stack->thisVar.varData.theStack->first == NULL) {
 					return fatal(ERROR_INDEX_EMPTY);
 				} else {
 					int ii;
-					if (! getValueType(ii, SVT_INT, fun -> reg)) return false;
-					if (! stackSetByIndex(fun -> stack -> thisVar.varData.theStack -> first, ii, fun -> stack -> next -> thisVar)) {
+					if (!getValueType(ii, SVT_INT, fun->reg)) return false;
+					if (!stackSetByIndex(fun->stack->thisVar.varData.theStack->first, ii, fun->stack->next->thisVar)) {
 						return false;
 					}
-					trimStack(fun -> stack);
-					trimStack(fun -> stack);
+					trimStack(fun->stack);
+					trimStack(fun->stack);
 				}
 				break;
 
 			case SVT_FASTARRAY: {
 				int ii;
-				if (! getValueType(ii, SVT_INT, fun -> reg)) return false;
-				variable *v = fastArrayGetByIndex(fun -> stack -> thisVar.varData.fastArray, ii);
+				if (!getValueType(ii, SVT_INT, fun->reg)) return false;
+				variable *v = fastArrayGetByIndex(fun->stack->thisVar.varData.fastArray, ii);
 				if (v == NULL) return fatal("Not within bounds of fast array.");
-				if (! copyVariable(fun -> stack -> next -> thisVar, * v)) return false;
-				trimStack(fun -> stack);
-				trimStack(fun -> stack);
+				if (!copyVariable(fun->stack->next->thisVar, * v)) return false;
+				trimStack(fun->stack);
+				trimStack(fun->stack);
 			}
 			break;
 
@@ -1090,81 +1089,81 @@ bool continueFunction(loadedFunction *fun) {
 
 		case SLU_INCREMENT_LOCAL: {
 			int ii;
-			if (! getValueType(ii, SVT_INT, fun -> localVars[param])) return false;
-			setVariable(fun -> reg, SVT_INT, ii);
-			setVariable(fun -> localVars[param], SVT_INT, ii + 1);
+			if (!getValueType(ii, SVT_INT, fun->localVars[param])) return false;
+			setVariable(fun->reg, SVT_INT, ii);
+			setVariable(fun->localVars[param], SVT_INT, ii + 1);
 		}
 		break;
 
 		case SLU_INCREMENT_GLOBAL: {
 			int ii;
-			if (! getValueType(ii, SVT_INT, globalVars[param])) return false;
-			setVariable(fun -> reg, SVT_INT, ii);
+			if (!getValueType(ii, SVT_INT, globalVars[param])) return false;
+			setVariable(fun->reg, SVT_INT, ii);
 			setVariable(globalVars[param], SVT_INT, ii + 1);
 		}
 		break;
 
 		case SLU_DECREMENT_LOCAL: {
 			int ii;
-			if (! getValueType(ii, SVT_INT, fun -> localVars[param])) return false;
-			setVariable(fun -> reg, SVT_INT, ii);
-			setVariable(fun -> localVars[param], SVT_INT, ii - 1);
+			if (!getValueType(ii, SVT_INT, fun->localVars[param])) return false;
+			setVariable(fun->reg, SVT_INT, ii);
+			setVariable(fun->localVars[param], SVT_INT, ii - 1);
 		}
 		break;
 
 		case SLU_DECREMENT_GLOBAL: {
 			int ii;
-			if (! getValueType(ii, SVT_INT, globalVars[param])) return false;
-			setVariable(fun -> reg, SVT_INT, ii);
+			if (!getValueType(ii, SVT_INT, globalVars[param])) return false;
+			setVariable(fun->reg, SVT_INT, ii);
 			setVariable(globalVars[param], SVT_INT, ii - 1);
 		}
 		break;
 
 		case SLU_SET_LOCAL:
-			if (! copyVariable(fun -> reg, fun -> localVars[param])) return false;
+			if (!copyVariable(fun->reg, fun->localVars[param])) return false;
 			break;
 
 		case SLU_SET_GLOBAL:
 //			newDebug ("  Copying TO global variable", param);
 //			newDebug ("  Global type at the moment", globalVars[param].varType);
-			if (! copyVariable(fun -> reg, globalVars[param])) return false;
+			if (!copyVariable(fun->reg, globalVars[param])) return false;
 //			newDebug ("  New type", globalVars[param].varType);
 			break;
 
 		case SLU_LOAD_GLOBAL:
 //			newDebug ("  Copying FROM global variable", param);
 //			newDebug ("  Global type at the moment", globalVars[param].varType);
-			if (! copyVariable(globalVars[param], fun -> reg)) return false;
+			if (!copyVariable(globalVars[param], fun->reg)) return false;
 			break;
 
 		case SLU_STACK_PUSH:
-			if (! addVarToStack(fun -> reg, fun -> stack)) return false;
+			if (!addVarToStack(fun->reg, fun->stack)) return false;
 			break;
 
 		case SLU_QUICK_PUSH:
-			if (! addVarToStackQuick(fun -> reg, fun -> stack)) return false;
+			if (!addVarToStackQuick(fun->reg, fun->stack)) return false;
 			break;
 
 		case SLU_NOT:
-			setVariable(fun -> reg, SVT_INT, ! getBoolean(fun -> reg));
+			setVariable(fun->reg, SVT_INT, !getBoolean(fun->reg));
 			break;
 
 		case SLU_BR_ZERO:
-			if (! getBoolean(fun -> reg)) {
+			if (!getBoolean(fun->reg)) {
 				advanceNow = false;
-				fun -> runThisLine = param;
+				fun->runThisLine = param;
 			}
 			break;
 
 		case SLU_BRANCH:
 			advanceNow = false;
-			fun -> runThisLine = param;
+			fun->runThisLine = param;
 			break;
 
 		case SLU_NEGATIVE: {
 			int i;
-			if (! getValueType(i, SVT_INT, fun -> reg)) return false;
-			setVariable(fun -> reg, SVT_INT, -i);
+			if (!getValueType(i, SVT_INT, fun->reg)) return false;
+			setVariable(fun->reg, SVT_INT, -i);
 		}
 		break;
 
@@ -1181,62 +1180,62 @@ bool continueFunction(loadedFunction *fun) {
 		case SLU_MORETHAN:
 		case SLU_LESS_EQUAL:
 		case SLU_MORE_EQUAL:
-			if (fun -> stack) {
+			if (fun->stack) {
 				int firstValue, secondValue;
 
 				switch (com) {
 				case SLU_PLUS:
-					addVariablesInSecond(fun -> stack -> thisVar, fun -> reg);
-					trimStack(fun -> stack);
+					addVariablesInSecond(fun->stack->thisVar, fun->reg);
+					trimStack(fun->stack);
 					break;
 
 				case SLU_EQUALS:
-					compareVariablesInSecond(fun -> stack -> thisVar, fun -> reg);
-					trimStack(fun -> stack);
+					compareVariablesInSecond(fun->stack->thisVar, fun->reg);
+					trimStack(fun->stack);
 					break;
 
 				case SLU_NOT_EQ:
-					compareVariablesInSecond(fun -> stack -> thisVar, fun -> reg);
-					trimStack(fun -> stack);
-					fun -> reg.varData.intValue = ! fun -> reg.varData.intValue;
+					compareVariablesInSecond(fun->stack->thisVar, fun->reg);
+					trimStack(fun->stack);
+					fun->reg.varData.intValue = !fun->reg.varData.intValue;
 					break;
 
 				default:
-					if (! getValueType(firstValue, SVT_INT, fun -> stack -> thisVar)) return false;
-					if (! getValueType(secondValue, SVT_INT, fun -> reg)) return false;
-					trimStack(fun -> stack);
+					if (!getValueType(firstValue, SVT_INT, fun->stack->thisVar)) return false;
+					if (!getValueType(secondValue, SVT_INT, fun->reg)) return false;
+					trimStack(fun->stack);
 
 					switch (com) {
 					case SLU_MULT:
-						setVariable(fun -> reg, SVT_INT, firstValue * secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue * secondValue);
 						break;
 
 					case SLU_MINUS:
-						setVariable(fun -> reg, SVT_INT, firstValue - secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue - secondValue);
 						break;
 
 					case SLU_MODULUS:
-						setVariable(fun -> reg, SVT_INT, firstValue % secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue % secondValue);
 						break;
 
 					case SLU_DIVIDE:
-						setVariable(fun -> reg, SVT_INT, firstValue / secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue / secondValue);
 						break;
 
 					case SLU_LESSTHAN:
-						setVariable(fun -> reg, SVT_INT, firstValue < secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue < secondValue);
 						break;
 
 					case SLU_MORETHAN:
-						setVariable(fun -> reg, SVT_INT, firstValue > secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue > secondValue);
 						break;
 
 					case SLU_LESS_EQUAL:
-						setVariable(fun -> reg, SVT_INT, firstValue <= secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue <= secondValue);
 						break;
 
 					case SLU_MORE_EQUAL:
-						setVariable(fun -> reg, SVT_INT, firstValue >= secondValue);
+						setVariable(fun->reg, SVT_INT, firstValue >= secondValue);
 						break;
 
 					default:
@@ -1252,7 +1251,7 @@ bool continueFunction(loadedFunction *fun) {
 			return fatal(ERROR_UNKNOWN_CODE);
 		}
 
-		if (advanceNow) fun -> runThisLine ++;
+		if (advanceNow) fun->runThisLine ++;
 
 	}
 	return true;
@@ -1265,22 +1264,22 @@ bool runSludge() {
 	loadedFunction *nextFunction;
 
 	while (thisFunction) {
-		nextFunction = thisFunction -> next;
+		nextFunction = thisFunction->next;
 
-		if (! thisFunction -> freezerLevel) {
-			if (thisFunction -> timeLeft) {
-				if (thisFunction -> timeLeft < 0) {
-					if (! stillPlayingSound(findInSoundCache(speech -> lastFile))) {
-						thisFunction -> timeLeft = 0;
+		if (!thisFunction->freezerLevel) {
+			if (thisFunction->timeLeft) {
+				if (thisFunction->timeLeft < 0) {
+					if (!stillPlayingSound(findInSoundCache(speech->lastFile))) {
+						thisFunction->timeLeft = 0;
 					}
-				} else if (! -- (thisFunction -> timeLeft)) {
+				} else if (!-- (thisFunction->timeLeft)) {
 				}
 			} else {
-				if (thisFunction -> isSpeech) {
-					thisFunction -> isSpeech = false;
+				if (thisFunction->isSpeech) {
+					thisFunction->isSpeech = false;
 					killAllSpeech();
 				}
-				if (! continueFunction(thisFunction))
+				if (!continueFunction(thisFunction))
 					return false;
 			}
 		}
@@ -1291,9 +1290,9 @@ bool runSludge() {
 	if (loadNow) {
 		if (loadNow[0] == ':') {
 			saveGame(loadNow + 1);
-			setVariable(saverFunc -> reg, SVT_INT, 1);
+			setVariable(saverFunc->reg, SVT_INT, 1);
 		} else {
-			if (! loadGame(loadNow)) return false;
+			if (!loadGame(loadNow)) return false;
 		}
 		delete loadNow;
 		loadNow = NULL;
@@ -1303,38 +1302,37 @@ bool runSludge() {
 }
 
 bool loadFunctionCode(loadedFunction *newFunc) {
-#if ALLOW_FILE
-	printf("\nCurrent address: %li\n", ftell(bigDataFile));
+
+	debug(kSludgeDebugDataLoad, "Current address: %i", bigDataFile->pos());
 	unsigned int numLines, numLinesRead;
 
-	if (! openSubSlice(newFunc -> originalNumber)) return false;
+	if (!openSubSlice(newFunc->originalNumber)) return false;
 
-	printf("Load function code\n");
+	debug(kSludgeDebugDataLoad, "Load function code");
 
-	newFunc -> unfreezable  = fgetc(bigDataFile);
+	newFunc->unfreezable  = getch(bigDataFile);
 	numLines                = get2bytes(bigDataFile);
-	printf("numLines: %i\n", numLines);
-	newFunc -> numArgs      = get2bytes(bigDataFile);
-	printf("numArgs: %i\n", newFunc -> numArgs);
-	newFunc -> numLocals    = get2bytes(bigDataFile);
-	printf("numLocals: %i\n", newFunc -> numLocals);
-	newFunc -> compiledLines = new lineOfCode[numLines];
-	if (! checkNew(newFunc -> compiledLines)) return false;
+	debug(kSludgeDebugDataLoad, "numLines: %i", numLines);
+	newFunc->numArgs      = get2bytes(bigDataFile);
+	debug(kSludgeDebugDataLoad, "numArgs: %i", newFunc->numArgs);
+	newFunc->numLocals    = get2bytes(bigDataFile);
+	debug(kSludgeDebugDataLoad, "numLocals: %i", newFunc->numLocals);
+	newFunc->compiledLines = new lineOfCode[numLines];
+	if (!checkNew(newFunc->compiledLines)) return false;
 
 	for (numLinesRead = 0; numLinesRead < numLines; numLinesRead ++) {
-		newFunc -> compiledLines[numLinesRead].theCommand = (sludgeCommand) fgetc(bigDataFile);
-		newFunc -> compiledLines[numLinesRead].param = get2bytes(bigDataFile);
-		printf("command line %i: %i\n", numLinesRead, newFunc->compiledLines[numLinesRead].theCommand);
+		newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) getch(bigDataFile);
+		newFunc->compiledLines[numLinesRead].param = get2bytes(bigDataFile);
+		debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead, newFunc->compiledLines[numLinesRead].theCommand);
 	}
 	finishAccess();
 
 	// Now we need to reserve memory for the local variables
-	newFunc -> localVars = new variable[newFunc -> numLocals];
-	if (! checkNew(newFunc -> localVars)) return false;
-	for (int a = 0; a < newFunc -> numLocals; a ++) {
-		initVarNew(newFunc -> localVars[a]);
+	newFunc->localVars = new variable[newFunc->numLocals];
+	if (!checkNew(newFunc->localVars)) return false;
+	for (int a = 0; a < newFunc->numLocals; a ++) {
+		initVarNew(newFunc->localVars[a]);
 	}
-#endif
 
 	return true;
 }
@@ -1342,31 +1340,31 @@ bool loadFunctionCode(loadedFunction *newFunc) {
 int startNewFunctionNum(unsigned int funcNum, unsigned int numParamsExpected, loadedFunction *calledBy, variableStack *&vStack, bool returnSommet) {
 	loadedFunction *newFunc = new loadedFunction;
 	checkNew(newFunc);
-	newFunc -> originalNumber = funcNum;
+	newFunc->originalNumber = funcNum;
 
 	loadFunctionCode(newFunc);
 
-	if (newFunc -> numArgs != (int)numParamsExpected) return fatal("Wrong number of parameters!");
-	if (newFunc -> numArgs > newFunc -> numLocals) return fatal("More arguments than local variable space!");
+	if (newFunc->numArgs != (int)numParamsExpected) return fatal("Wrong number of parameters!");
+	if (newFunc->numArgs > newFunc->numLocals) return fatal("More arguments than local variable space!");
 
 	// Now, lets copy the parameters from the calling function's stack...
 
 	while (numParamsExpected) {
 		numParamsExpected --;
-		if (vStack == NULL) return fatal("Corrupted file! The stack's empty and there were still parameters expected");
-		copyVariable(vStack -> thisVar, newFunc -> localVars[numParamsExpected]);
+		if (vStack == NULL) return fatal("Corrupted file!The stack's empty and there were still parameters expected");
+		copyVariable(vStack->thisVar, newFunc->localVars[numParamsExpected]);
 		trimStack(vStack);
 	}
 
-	newFunc -> cancelMe = false;
-	newFunc -> timeLeft = 0;
-	newFunc -> returnSomething = returnSommet;
-	newFunc -> calledBy = calledBy;
-	newFunc -> stack = NULL;
-	newFunc -> freezerLevel = 0;
-	newFunc -> runThisLine = 0;
-	newFunc -> isSpeech = 0;
-	initVarNew(newFunc -> reg);
+	newFunc->cancelMe = false;
+	newFunc->timeLeft = 0;
+	newFunc->returnSomething = returnSommet;
+	newFunc->calledBy = calledBy;
+	newFunc->stack = NULL;
+	newFunc->freezerLevel = 0;
+	newFunc->runThisLine = 0;
+	newFunc->isSpeech = 0;
+	initVarNew(newFunc->reg);
 
 	restartFunction(newFunc);
 	return 1;
@@ -1408,40 +1406,40 @@ bool handleInput() {
 		l = 0;
 	}
 
-	if (! overRegion) getOverRegion();
+	if (!overRegion) getOverRegion();
 
 	if (input.justMoved) {
-		if (currentEvents -> moveMouseFunction) {
-			if (! startNewFunctionNum(currentEvents -> moveMouseFunction, 0, NULL, noStack)) return false;
+		if (currentEvents->moveMouseFunction) {
+			if (!startNewFunctionNum(currentEvents->moveMouseFunction, 0, NULL, noStack)) return false;
 		}
 	}
 	input.justMoved = false;
 
-	if (lastRegion != overRegion && currentEvents -> focusFunction) {
+	if (lastRegion != overRegion && currentEvents->focusFunction) {
 		variableStack *tempStack = new variableStack;
-		if (! checkNew(tempStack)) return false;
+		if (!checkNew(tempStack)) return false;
 
-		initVarNew(tempStack -> thisVar);
+		initVarNew(tempStack->thisVar);
 		if (overRegion) {
-			setVariable(tempStack -> thisVar, SVT_OBJTYPE, overRegion -> thisType -> objectNum);
+			setVariable(tempStack->thisVar, SVT_OBJTYPE, overRegion->thisType->objectNum);
 		} else {
-			setVariable(tempStack -> thisVar, SVT_INT, 0);
+			setVariable(tempStack->thisVar, SVT_INT, 0);
 		}
-		tempStack -> next = NULL;
-		if (! startNewFunctionNum(currentEvents -> focusFunction, 1, NULL, tempStack)) return false;
+		tempStack->next = NULL;
+		if (!startNewFunctionNum(currentEvents->focusFunction, 1, NULL, tempStack)) return false;
 	}
-	if (input.leftRelease && currentEvents -> leftMouseUpFunction)  {
-		if (! startNewFunctionNum(currentEvents -> leftMouseUpFunction, 0, NULL, noStack)) return false;
+	if (input.leftRelease && currentEvents->leftMouseUpFunction)  {
+		if (!startNewFunctionNum(currentEvents->leftMouseUpFunction, 0, NULL, noStack)) return false;
 	}
-	if (input.rightRelease && currentEvents -> rightMouseUpFunction) {
-		if (! startNewFunctionNum(currentEvents -> rightMouseUpFunction, 0, NULL, noStack)) return false;
+	if (input.rightRelease && currentEvents->rightMouseUpFunction) {
+		if (!startNewFunctionNum(currentEvents->rightMouseUpFunction, 0, NULL, noStack)) return false;
 	}
-	if (input.leftClick && currentEvents -> leftMouseFunction)
-		if (! startNewFunctionNum(currentEvents -> leftMouseFunction, 0, NULL, noStack)) return false;
-	if (input.rightClick && currentEvents -> rightMouseFunction) {
-		if (! startNewFunctionNum(currentEvents -> rightMouseFunction, 0, NULL, noStack)) return false;
+	if (input.leftClick && currentEvents->leftMouseFunction)
+		if (!startNewFunctionNum(currentEvents->leftMouseFunction, 0, NULL, noStack)) return false;
+	if (input.rightClick && currentEvents->rightMouseFunction) {
+		if (!startNewFunctionNum(currentEvents->rightMouseFunction, 0, NULL, noStack)) return false;
 	}
-	if (input.keyPressed && currentEvents -> spaceFunction) {
+	if (input.keyPressed && currentEvents->spaceFunction) {
 		char *tempString = NULL;
 		switch (input.keyPressed) {
 		case 127:
@@ -1551,13 +1549,13 @@ bool handleInput() {
 
 		if (tempString) {
 			variableStack *tempStack = new variableStack;
-			if (! checkNew(tempStack)) return false;
-			initVarNew(tempStack -> thisVar);
-			makeTextVar(tempStack -> thisVar, tempString);
+			if (!checkNew(tempStack)) return false;
+			initVarNew(tempStack->thisVar);
+			makeTextVar(tempStack->thisVar, tempString);
 			delete tempString;
 			tempString = NULL;
-			tempStack -> next = NULL;
-			if (! startNewFunctionNum(currentEvents -> spaceFunction, 1, NULL, tempStack)) return false;
+			tempStack->next = NULL;
+			if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL, tempStack)) return false;
 		}
 	}
 	input.rightClick = false;
diff --git a/engines/sludge/sludger.h b/engines/sludge/sludger.h
index ff24b24..d67192d 100644
--- a/engines/sludge/sludger.h
+++ b/engines/sludge/sludger.h
@@ -29,6 +29,8 @@
 #include "csludge.h"
 #include "language.h"
 
+#include "common/file.h"
+
 namespace Sludge {
 
 #ifndef _WIN32
@@ -85,15 +87,13 @@ int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *, variableSt
 bool handleInput();
 void restartFunction(loadedFunction *fun);
 bool loadFunctionCode(loadedFunction *newFunc);
-#if ALLOW_FILE
-void loadHandlers(FILE *fp);
-void saveHandlers(FILE *fp);
-#endif
+void loadHandlers(Common::SeekableReadStream *stream);
+void saveHandlers(Common::WriteStream *stream);
+
 void finishFunction(loadedFunction *fun);
 void abortFunction(loadedFunction *fun);
-#if ALLOW_FILE
-FILE *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion);
-#endif
+Common::File *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion);
+
 void freezeSubs();
 void unfreezeSubs();
 void completeTimers();
diff --git a/engines/sludge/sound.h b/engines/sludge/sound.h
index 5bb3f9d..1c5af96 100644
--- a/engines/sludge/sound.h
+++ b/engines/sludge/sound.h
@@ -31,6 +31,8 @@
 
 #include "variable.h"
 
+#include "common/file.h"
+
 namespace Sludge {
 
 // Sound list stuff
@@ -66,11 +68,9 @@ bool stillPlayingSound(int ch);
 bool getSoundCacheStack(stackHandler *sH);
 int findInSoundCache(int a);
 
-#if ALLOW_FILE
 void debugSounds();
-void loadSounds(FILE *fp);
-void saveSounds(FILE *fp);
-#endif
+void loadSounds(Common::SeekableReadStream *stream);
+void saveSounds(Common::WriteStream *stream);
 
 unsigned int getSoundSource(int index);
 
diff --git a/engines/sludge/sound_bass.cpp b/engines/sludge/sound_bass.cpp
index 017796c..6f16d66 100644
--- a/engines/sludge/sound_bass.cpp
+++ b/engines/sludge/sound_bass.cpp
@@ -49,10 +49,10 @@ soundThing soundCache[MAX_SAMPLES];
 int defVol = 128;
 int defSoundVol = 255;
 
-char *loadEntireFileToMemory(FILE *inputFile, uint32_t size) {
+char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t size) {
 	char *allData = new char[size];
-	if (! allData) return NULL;
-	fread(allData, size, 1, inputFile);
+	if (!allData) return NULL;
+	inputFile->read(allData, size);
 	finishAccess();
 
 	return allData;
@@ -136,17 +136,17 @@ bool playMOD(int f, int a, int fromTrack) {
 
 		char *memImage;
 		memImage = loadEntireFileToMemory(bigDataFile, length);
-		if (! memImage) return fatal(ERROR_MUSIC_MEMORY_LOW);
+		if (!memImage) return fatal(ERROR_MUSIC_MEMORY_LOW);
 
 		mod[a] = BASS_MusicLoad(true, memImage, 0, length, BASS_MUSIC_LOOP | BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0);
 		delete memImage;
 
-		if (! mod[a]) {
+		if (!mod[a]) {
 
 		} else {
 			setMusicVolume(a, defVol);
 
-			if (! BASS_ChannelPlay(mod[a], true))
+			if (!BASS_ChannelPlay(mod[a], true))
 				debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode());
 
 			BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER);
@@ -161,7 +161,7 @@ void setMusicVolume(int a, int v) {
 	int ret;
 	if (soundOK && mod[a]) {
 		ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL, (float) v / 256);
-		if (! ret) {
+		if (!ret) {
 			debugOut("setMusicVolume: Error %d\n", BASS_ErrorGetCode());
 		}
 	}
@@ -215,19 +215,19 @@ int findEmptySoundSlot() {
 	for (t = 0; t < MAX_SAMPLES; t ++) {
 		emptySoundSlot ++;
 		emptySoundSlot %= MAX_SAMPLES;
-		if (! soundCache[emptySoundSlot].sample)
+		if (!soundCache[emptySoundSlot].sample)
 			return emptySoundSlot;
 	}
 
-	// Argh! They're all playing! Let's trash the oldest that's not looping...
+	// Argh!They're all playing!Let's trash the oldest that's not looping...
 
 	for (t = 0; t < MAX_SAMPLES; t ++) {
 		emptySoundSlot ++;
 		emptySoundSlot %= MAX_SAMPLES;
-		if (! soundCache[emptySoundSlot].looping) return emptySoundSlot;
+		if (!soundCache[emptySoundSlot].looping) return emptySoundSlot;
 	}
 
-	// Holy crap, they're all looping! What's this twat playing at?
+	// Holy crap, they're all looping!What's this twat playing at?
 
 	emptySoundSlot ++;
 	emptySoundSlot %= MAX_SAMPLES;
@@ -246,7 +246,7 @@ void soundWarning (char * t, int i) {
 
 bool forceRemoveSound() {
 	for (int a = 0; a < 8; a ++) {
-		if (soundCache[a].fileLoaded != -1 && ! stillPlayingSound(a)) {
+		if (soundCache[a].fileLoaded != -1 && !stillPlayingSound(a)) {
 //			soundWarning ("Deleting silent sound", a);
 			freeSound(a);
 			return 1;
@@ -267,7 +267,7 @@ bool forceRemoveSound() {
 int cacheSound(int f) {
 	setResourceForFatal(f);
 
-	if (! soundOK) return 0;
+	if (!soundOK) return 0;
 
 	int a = findInSoundCache(f);
 	if (a != -1) return a;
@@ -276,7 +276,7 @@ int cacheSound(int f) {
 	freeSound(a);
 
 	uint32_t length = openFileFromNum(f);
-	if (! length) return -1;
+	if (!length) return -1;
 
 	char *memImage;
 
@@ -286,7 +286,7 @@ int cacheSound(int f) {
 		memImage = loadEntireFileToMemory(bigDataFile, length);
 		tryAgain = memImage == NULL;
 		if (tryAgain) {
-			if (! forceRemoveSound()) {
+			if (!forceRemoveSound()) {
 				fatal(ERROR_SOUND_MEMORY_LOW);
 				return -1;
 			}
@@ -347,32 +347,32 @@ void debugSounds () {
 }
 // */
 
-void saveSounds(FILE *fp) {
+void saveSounds(Common::WriteStream *stream) {
 	if (soundOK) {
 		for (int i = 0; i < MAX_SAMPLES; i ++) {
 			if (soundCache[i].looping) {
-				fputc(1, fp);
-				put2bytes(soundCache[i].fileLoaded, fp);
-				put2bytes(soundCache[i].vol, fp);
+				putch(1, stream);
+				put2bytes(soundCache[i].fileLoaded, stream);
+				put2bytes(soundCache[i].vol, stream);
 			}
 		}
 	}
-	fputc(0, fp);
-	put2bytes(defSoundVol, fp);
-	put2bytes(defVol, fp);
+	putch(0, stream);
+	put2bytes(defSoundVol, stream);
+	put2bytes(defVol, stream);
 }
 
-void loadSounds(FILE *fp) {
+void loadSounds(Common::SeekableReadStream *stream) {
 	for (int i = 0; i < MAX_SAMPLES; i ++) freeSound(i);
 
-	while (fgetc(fp)) {
-		int fileLoaded = get2bytes(fp);
-		defSoundVol = get2bytes(fp);
+	while (getch(stream)) {
+		int fileLoaded = get2bytes(stream);
+		defSoundVol = get2bytes(stream);
 		startSound(fileLoaded, 1);
 	}
 
-	defSoundVol = get2bytes(fp);
-	defVol = get2bytes(fp);
+	defSoundVol = get2bytes(stream);
+	defVol = get2bytes(stream);
 }
 
 bool getSoundCacheStack(stackHandler *sH) {
@@ -382,7 +382,7 @@ bool getSoundCacheStack(stackHandler *sH) {
 	for (int a = 0; a < MAX_SAMPLES; a ++) {
 		if (soundCache[a].fileLoaded != -1) {
 			setVariable(newFileHandle, SVT_FILE, soundCache[a].fileLoaded);
-			if (! addVarToStackQuick(newFileHandle, sH -> first)) return false;
+			if (!addVarToStackQuick(newFileHandle, sH -> first)) return false;
 			if (sH -> last == NULL) sH -> last = sH -> first;
 		}
 	}
diff --git a/engines/sludge/sound_nosound.cpp b/engines/sludge/sound_nosound.cpp
index 8f8bb28..292148b 100644
--- a/engines/sludge/sound_nosound.cpp
+++ b/engines/sludge/sound_nosound.cpp
@@ -112,23 +112,22 @@ bool startSound(int f, bool loopy) {
 	return true;
 }
 
-#if ALLOW_FILE
-void saveSounds(FILE *fp) {
-	fputc(0, fp);
-	put2bytes(defSoundVol, fp);
-	put2bytes(defVol, fp);
+void saveSounds(Common::WriteStream *stream) {
+	putch(0, stream);
+	put2bytes(defSoundVol, stream);
+	put2bytes(defVol, stream);
 }
 
-void loadSounds(FILE *fp) {
-	while (fgetc(fp)) {
-		get2bytes(fp);
-		get2bytes(fp);
+void loadSounds(Common::SeekableReadStream *stream) {
+	while (getch(stream)) {
+		get2bytes(stream);
+		get2bytes(stream);
 	}
 
-	defSoundVol = get2bytes(fp);
-	defVol = get2bytes(fp);
+	defSoundVol = get2bytes(stream);
+	defVol = get2bytes(stream);
 }
-#endif
+
 bool getSoundCacheStack(stackHandler *sH) {
 //#pragma unused (sH)
 	return true;
diff --git a/engines/sludge/sound_openal.cpp b/engines/sludge/sound_openal.cpp
index aa8f8e1..5faefdb 100644
--- a/engines/sludge/sound_openal.cpp
+++ b/engines/sludge/sound_openal.cpp
@@ -33,6 +33,8 @@
 #include "moreio.h"
 #include "fileset.h"
 
+#include "common/file.h"
+
 #define MAX_SAMPLES 8
 #define MAX_MODS 3
 #define NUM_BUFS 3
@@ -359,13 +361,12 @@ void playStream(int a, bool isMOD, bool loopy) {
 #endif
 }
 
-#if ALLOW_FILE
-char *loadEntireFileToMemory(FILE *inputFile, uint32_t size) {
+char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t size) {
 	char *allData = new char[size];
 	if (! allData) return NULL;
 
-	size_t bytes_read = fread(allData, size, 1, inputFile);
-	if (bytes_read != size && ferror(inputFile)) {
+	size_t bytes_read = inputFile->read(allData, size);
+	if (bytes_read != size && inputFile->err()) {
 		debugOut("Reading error in loadEntireFileToMemory.\n");
 	}
 
@@ -373,10 +374,8 @@ char *loadEntireFileToMemory(FILE *inputFile, uint32_t size) {
 
 	return allData;
 }
-#endif
 
 bool playMOD(int f, int a, int fromTrack) {
-#if ALLOW_FILE
 	if (! soundOK) return true;
 	stopMOD(a);
 
@@ -387,7 +386,6 @@ bool playMOD(int f, int a, int fromTrack) {
 		setResourceForFatal(-1);
 		return false;
 	}
-#endif
 #if 0
 	unsigned char *memImage;
 	memImage = (unsigned char *) loadEntireFileToMemory(bigDataFile, length);
@@ -592,35 +590,33 @@ bool startSound(int f, bool loopy) {
 	return true;
 }
 
-#if ALLOW_FILE
-void saveSounds(FILE *fp) {
+void saveSounds(Common::WriteStream *stream) {
 	if (soundOK) {
 		for (int i = 0; i < MAX_SAMPLES; i ++) {
 			if (soundCache[i].looping) {
-				fputc(1, fp);
-				put2bytes(soundCache[i].fileLoaded, fp);
-				put2bytes(soundCache[i].vol, fp);
+				putch(1, stream);
+				put2bytes(soundCache[i].fileLoaded, stream);
+				put2bytes(soundCache[i].vol, stream);
 			}
 		}
 	}
-	fputc(0, fp);
-	put2bytes(defSoundVol, fp);
-	put2bytes(defVol, fp);
+	putch(0, stream);
+	put2bytes(defSoundVol, stream);
+	put2bytes(defVol, stream);
 }
 
-void loadSounds(FILE *fp) {
+void loadSounds(Common::SeekableReadStream *stream) {
 	for (int i = 0; i < MAX_SAMPLES; i ++) freeSound(i);
 
-	while (fgetc(fp)) {
-		int fileLoaded = get2bytes(fp);
-		defSoundVol = get2bytes(fp);
+	while (getch(stream)) {
+		int fileLoaded = get2bytes(stream);
+		defSoundVol = get2bytes(stream);
 		startSound(fileLoaded, 1);
 	}
 
-	defSoundVol = get2bytes(fp);
-	defVol = get2bytes(fp);
+	defSoundVol = get2bytes(stream);
+	defVol = get2bytes(stream);
 }
-#endif
 
 bool getSoundCacheStack(stackHandler *sH) {
 	variable newFileHandle;
@@ -742,12 +738,12 @@ void playSoundList(soundList *s) {
 #endif
 }
 
-#if ALLOW_FILE
 void playMovieStream(int a) {
+#if 0
 	if (! soundOK) return;
 	ALboolean ok;
 	ALuint src;
-#if 0
+
 	alGenSources(1, &src);
 	if (alGetError() != AL_NO_ERROR) {
 		debugOut("Failed to create OpenAL source!\n");
@@ -758,22 +754,20 @@ void playMovieStream(int a) {
 
 	ok = alurePlaySourceStream(src, soundCache[a].stream,
 	                           10, 0, sound_eos_callback, &intpointers[a]);
-#endif
 	if (!ok) {
-#if 0
 		debugOut("Failed to play stream: %s\n", alureGetErrorString());
 		alDeleteSources(1, &src);
 		if (alGetError() != AL_NO_ERROR) {
 			debugOut("Failed to delete OpenAL source!\n");
 		}
-#endif
+
 		soundCache[a].playingOnSource = 0;
 	} else {
 		soundCache[a].playingOnSource = src;
 		soundCache[a].playing = true;
 	}
-}
 #endif
+}
 
 #if 0
 int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index 792fe66..ec4144f 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -116,7 +116,7 @@ bool reserveSpritePal(spritePalette &sP, int n) {
 }
 
 bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
-#if ALLOW_FILE
+#if 0
 	int i, tex_num, total, picwidth, picheight, spriteBankVersion = 0, howmany = 0, startIndex = 0;
 	int *totalwidth, * maxheight;
 	int numTextures = 0;
diff --git a/engines/sludge/statusba.cpp b/engines/sludge/statusba.cpp
index e7dc4cb..d90d3a2 100644
--- a/engines/sludge/statusba.cpp
+++ b/engines/sludge/statusba.cpp
@@ -41,105 +41,105 @@ extern int fontHeight;
 extern float cameraZoom;
 
 void setLitStatus(int i) {
-	nowStatus -> litStatus = i;
+	nowStatus->litStatus = i;
 }
 
 void killLastStatus() {
-	if (nowStatus -> firstStatusBar) {
-		statusBar *kill = nowStatus -> firstStatusBar;
-		nowStatus -> firstStatusBar = kill -> next;
-		delete kill -> text;
+	if (nowStatus->firstStatusBar) {
+		statusBar *kill = nowStatus->firstStatusBar;
+		nowStatus->firstStatusBar = kill->next;
+		delete kill->text;
 		delete kill;
 	}
 }
 
 void clearStatusBar() {
-	statusBar *stat = nowStatus -> firstStatusBar;
+	statusBar *stat = nowStatus->firstStatusBar;
 	statusBar *kill;
-	nowStatus -> litStatus = -1;
+	nowStatus->litStatus = -1;
 	while (stat) {
 		kill = stat;
-		stat = stat -> next;
-		delete kill -> text;
+		stat = stat->next;
+		delete kill->text;
 		delete kill;
 	}
-	nowStatus -> firstStatusBar = NULL;
+	nowStatus->firstStatusBar = NULL;
 }
 
 void addStatusBar() {
 	statusBar *newStat = new statusBar;
 	if (checkNew(newStat)) {
-		newStat -> next = nowStatus -> firstStatusBar;
-		newStat -> text = copyString("");
-		nowStatus -> firstStatusBar = newStat;
+		newStat->next = nowStatus->firstStatusBar;
+		newStat->text = copyString("");
+		nowStatus->firstStatusBar = newStat;
 	}
 }
 
 void setStatusBar(char *txt) {
-	if (nowStatus -> firstStatusBar) {
-		delete nowStatus -> firstStatusBar -> text;
-		nowStatus -> firstStatusBar -> text = copyString(txt);
+	if (nowStatus->firstStatusBar) {
+		delete nowStatus->firstStatusBar->text;
+		nowStatus->firstStatusBar->text = copyString(txt);
 	}
 }
 
 void positionStatus(int x, int y) {
-	nowStatus -> statusX = x;
-	nowStatus -> statusY = y;
+	nowStatus->statusX = x;
+	nowStatus->statusY = y;
 }
 
 void drawStatusBar() {
-	int y = nowStatus -> statusY, n = 0;
-	statusBar *stat = nowStatus -> firstStatusBar;
+	int y = nowStatus->statusY, n = 0;
+	statusBar *stat = nowStatus->firstStatusBar;
 	fixFont(litVerbLinePalette);
 	fixFont(verbLinePalette);
 	while (stat) {
-		switch (nowStatus -> alignStatus) {
+		switch (nowStatus->alignStatus) {
 		case IN_THE_CENTRE:
-			pasteString(stat -> text, ((winWidth - stringWidth(stat -> text)) >> 1) / cameraZoom, y / cameraZoom, (n ++ == nowStatus -> litStatus) ? litVerbLinePalette : verbLinePalette);
+			pasteString(stat->text, ((winWidth - stringWidth(stat->text)) >> 1) / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
 			break;
 
 		case 1001:
-			pasteString(stat -> text, (winWidth - stringWidth(stat -> text)) - nowStatus -> statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus -> litStatus) ? litVerbLinePalette : verbLinePalette);
+			pasteString(stat->text, (winWidth - stringWidth(stat->text)) - nowStatus->statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
 			break;
 
 		default:
-			pasteString(stat -> text, nowStatus -> statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus -> litStatus) ? litVerbLinePalette : verbLinePalette);
+			pasteString(stat->text, nowStatus->statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
 		}
-		stat = stat -> next;
+		stat = stat->next;
 		y -= fontHeight;
 	}
 }
 
 void statusBarColour(byte r, byte g, byte b) {
 	setFontColour(verbLinePalette, r, g, b);
-	nowStatus -> statusR = r;
-	nowStatus -> statusG = g;
-	nowStatus -> statusB = b;
+	nowStatus->statusR = r;
+	nowStatus->statusG = g;
+	nowStatus->statusB = b;
 }
 
 void statusBarLitColour(byte r, byte g, byte b) {
 	setFontColour(litVerbLinePalette, r, g, b);
-	nowStatus -> statusLR = r;
-	nowStatus -> statusLG = g;
-	nowStatus -> statusLB = b;
+	nowStatus->statusLR = r;
+	nowStatus->statusLG = g;
+	nowStatus->statusLB = b;
 }
 
 statusStuff *copyStatusBarStuff(statusStuff *here) {
 
 	// Things we want to keep
-	here -> statusLR = nowStatus -> statusLR;
-	here -> statusLG = nowStatus -> statusLG;
-	here -> statusLB = nowStatus -> statusLB;
-	here -> statusR = nowStatus -> statusR;
-	here -> statusG = nowStatus -> statusG;
-	here -> statusB = nowStatus -> statusB;
-	here -> alignStatus = nowStatus -> alignStatus;
-	here -> statusX = nowStatus -> statusX;
-	here -> statusY = nowStatus -> statusY;
+	here->statusLR = nowStatus->statusLR;
+	here->statusLG = nowStatus->statusLG;
+	here->statusLB = nowStatus->statusLB;
+	here->statusR = nowStatus->statusR;
+	here->statusG = nowStatus->statusG;
+	here->statusB = nowStatus->statusB;
+	here->alignStatus = nowStatus->alignStatus;
+	here->statusX = nowStatus->statusX;
+	here->statusY = nowStatus->statusY;
 
 	// Things we want to clear
-	here -> litStatus = -1;
-	here -> firstStatusBar = NULL;
+	here->litStatus = -1;
+	here->firstStatusBar = NULL;
 
 	statusStuff *old = nowStatus;
 	nowStatus = here;
@@ -149,8 +149,8 @@ statusStuff *copyStatusBarStuff(statusStuff *here) {
 
 void restoreBarStuff(statusStuff *here) {
 	delete nowStatus;
-	setFontColour(verbLinePalette, here -> statusR, here -> statusG, here -> statusB);
-	setFontColour(litVerbLinePalette, here -> statusLR, here -> statusLG, here -> statusLB);
+	setFontColour(verbLinePalette, here->statusR, here->statusG, here->statusB);
+	setFontColour(litVerbLinePalette, here->statusLR, here->statusLG, here->statusLB);
 	nowStatus = here;
 }
 
@@ -166,68 +166,66 @@ void initStatusBar() {
 }
 
 const char *statusBarText() {
-	if (nowStatus -> firstStatusBar) {
-		return nowStatus -> firstStatusBar -> text;
+	if (nowStatus->firstStatusBar) {
+		return nowStatus->firstStatusBar->text;
 	} else {
 		return "";
 	}
 }
 
-#if ALLOW_FILE
-void saveStatusBars(FILE *fp) {
-	statusBar *viewLine = nowStatus -> firstStatusBar;
+void saveStatusBars(Common::WriteStream *stream) {
+	statusBar *viewLine = nowStatus->firstStatusBar;
 
-	put2bytes(nowStatus -> alignStatus, fp);
-	putSigned(nowStatus -> litStatus, fp);
-	put2bytes(nowStatus -> statusX, fp);
-	put2bytes(nowStatus -> statusY, fp);
+	put2bytes(nowStatus->alignStatus, stream);
+	putSigned(nowStatus->litStatus, stream);
+	put2bytes(nowStatus->statusX, stream);
+	put2bytes(nowStatus->statusY, stream);
 
-	fputc(nowStatus -> statusR, fp);
-	fputc(nowStatus -> statusG, fp);
-	fputc(nowStatus -> statusB, fp);
-	fputc(nowStatus -> statusLR, fp);
-	fputc(nowStatus -> statusLG, fp);
-	fputc(nowStatus -> statusLB, fp);
+	putch(nowStatus->statusR, stream);
+	putch(nowStatus->statusG, stream);
+	putch(nowStatus->statusB, stream);
+	putch(nowStatus->statusLR, stream);
+	putch(nowStatus->statusLG, stream);
+	putch(nowStatus->statusLB, stream);
 
 	// Write what's being said
 	while (viewLine) {
-		fputc(1, fp);
-		writeString(viewLine -> text, fp);
-		viewLine = viewLine -> next;
+		putch(1, stream);
+		writeString(viewLine->text, stream);
+		viewLine = viewLine->next;
 	}
-	fputc(0, fp);
+	putch(0, stream);
 }
 
-bool loadStatusBars(FILE *fp) {
+bool loadStatusBars(Common::SeekableReadStream *stream) {
 	clearStatusBar();
 
-	nowStatus -> alignStatus = get2bytes(fp);
-	nowStatus -> litStatus = getSigned(fp);
-	nowStatus -> statusX = get2bytes(fp);
-	nowStatus -> statusY = get2bytes(fp);
+	nowStatus->alignStatus = get2bytes(stream);
+	nowStatus->litStatus = getSigned(stream);
+	nowStatus->statusX = get2bytes(stream);
+	nowStatus->statusY = get2bytes(stream);
 
-	nowStatus -> statusR = fgetc(fp);
-	nowStatus -> statusG = fgetc(fp);
-	nowStatus -> statusB = fgetc(fp);
-	nowStatus -> statusLR = fgetc(fp);
-	nowStatus -> statusLG = fgetc(fp);
-	nowStatus -> statusLB = fgetc(fp);
+	nowStatus->statusR = getch(stream);
+	nowStatus->statusG = getch(stream);
+	nowStatus->statusB = getch(stream);
+	nowStatus->statusLR = getch(stream);
+	nowStatus->statusLG = getch(stream);
+	nowStatus->statusLB = getch(stream);
 
-	setFontColour(verbLinePalette, nowStatus -> statusR, nowStatus -> statusG, nowStatus -> statusB);
-	setFontColour(litVerbLinePalette, nowStatus -> statusLR, nowStatus -> statusLG, nowStatus -> statusLB);
+	setFontColour(verbLinePalette, nowStatus->statusR, nowStatus->statusG, nowStatus->statusB);
+	setFontColour(litVerbLinePalette, nowStatus->statusLR, nowStatus->statusLG, nowStatus->statusLB);
 	// Read what's being said
-	statusBar * * viewLine = & (nowStatus -> firstStatusBar);
+	statusBar * * viewLine = & (nowStatus->firstStatusBar);
 	statusBar *newOne;
-	while (fgetc(fp)) {
+	while (getch(stream)) {
 		newOne = new statusBar;
 		if (! checkNew(newOne)) return false;
-		newOne -> text = readString(fp);
-		newOne -> next = NULL;
+		newOne->text = readString(stream);
+		newOne->next = NULL;
 		(* viewLine) = newOne;
-		viewLine = & (newOne -> next);
+		viewLine = & (newOne->next);
 	}
 	return true;
 }
-#endif
 
 } // End of namespace Sludge
diff --git a/engines/sludge/statusba.h b/engines/sludge/statusba.h
index 2f0d30a..03c61cf 100644
--- a/engines/sludge/statusba.h
+++ b/engines/sludge/statusba.h
@@ -51,11 +51,9 @@ const char *statusBarText();
 void positionStatus(int, int);
 void drawStatusBar();
 
-#if ALLOW_FILE
 // Load and save
-bool loadStatusBars(FILE *fp);
-void saveStatusBars(FILE *fp);
-#endif
+bool loadStatusBars(Common::SeekableReadStream *stream);
+void saveStatusBars(Common::WriteStream *stream);
 
 // For freezing
 void restoreBarStuff(statusStuff *here);
diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp
index b6bc864..abee33c 100644
--- a/engines/sludge/talk.cpp
+++ b/engines/sludge/talk.cpp
@@ -44,32 +44,32 @@ float speechSpeed = 1;
 void initSpeech() {
 	speech = new speechStruct;
 	if (checkNew(speech)) {
-		speech -> currentTalker = NULL;
-		speech -> allSpeech = NULL;
-		speech -> speechY = 0;
-		speech -> lastFile = -1;
+		speech->currentTalker = NULL;
+		speech->allSpeech = NULL;
+		speech->speechY = 0;
+		speech->lastFile = -1;
 	}
 }
 
 void killAllSpeech() {
-	if (speech -> lastFile != -1) {
+	if (speech->lastFile != -1) {
 #if 0
-		huntKillSound(speech -> lastFile);
+		huntKillSound(speech->lastFile);
 #endif
-		speech -> lastFile = -1;
+		speech->lastFile = -1;
 	}
 
-	if (speech -> currentTalker) {
-		makeSilent(* (speech -> currentTalker));
-		speech -> currentTalker = NULL;
+	if (speech->currentTalker) {
+		makeSilent(* (speech->currentTalker));
+		speech->currentTalker = NULL;
 	}
 
 	speechLine *killMe;
 
-	while (speech -> allSpeech) {
-		killMe = speech -> allSpeech;
-		speech -> allSpeech = speech -> allSpeech -> next;
-		delete killMe -> textLine;
+	while (speech->allSpeech) {
+		killMe = speech->allSpeech;
+		speech->allSpeech = speech->allSpeech->next;
+		delete killMe->textLine;
 		delete killMe;
 	}
 }
@@ -79,7 +79,7 @@ void killAllSpeech() {
 
 inline void setObjFontColour(objectType *t) {
 #if 0
-	setFontColour(speech -> talkCol, t -> r, t -> g, t -> b);
+	setFontColour(speech->talkCol, t->r, t->g, t->b);
 #endif
 }
 
@@ -90,10 +90,10 @@ void addSpeechLine(char *theLine, int x, int &offset) {
 	speechLine *newLine = new speechLine;
 	checkNew(newLine);
 
-	newLine -> next = speech -> allSpeech;
-	newLine -> textLine = copyString(theLine);
-	newLine -> x = xx1;
-	speech -> allSpeech = newLine;
+	newLine->next = speech->allSpeech;
+	newLine->textLine = copyString(theLine);
+	newLine->x = xx1;
+	speech->allSpeech = newLine;
 	if ((xx1 < 5) && (offset < (5 - xx1))) {
 		offset = 5 - xx1;
 	} else if ((xx2 >= ((float)winWidth / cameraZoom) - 5) && (offset > (((float)winWidth / cameraZoom) - 5 - xx2))) {
@@ -102,7 +102,7 @@ void addSpeechLine(char *theLine, int x, int &offset) {
 }
 
 int isThereAnySpeechGoingOn() {
-	return speech -> allSpeech ? speech -> lookWhosTalking : -1;
+	return speech->allSpeech ? speech->lookWhosTalking : -1;
 }
 
 int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
@@ -117,13 +117,13 @@ int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
 #if 0
 			if (startSound(sampleFile, false)) {
 				speechTime = -10;
-				speech -> lastFile = sampleFile;
+				speech->lastFile = sampleFile;
 				if (speechMode == 2) return -10;
 			}
 #endif
 		}
 	}
-	speech -> speechY = y;
+	speech->speechY = y;
 
 	while (strlen(theText) > wrap) {
 		a = wrap;
@@ -143,24 +143,24 @@ int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
 	addSpeechLine(theText, x, offset);
 	y -= fontHeight / cameraZoom;
 
-	if (y < 0) speech -> speechY -= y;
-	else if (speech -> speechY > cameraY + (float)(winHeight - fontHeight / 3) / cameraZoom) speech -> speechY = cameraY + (float)(winHeight - fontHeight / 3) / cameraZoom;
+	if (y < 0) speech->speechY -= y;
+	else if (speech->speechY > cameraY + (float)(winHeight - fontHeight / 3) / cameraZoom) speech->speechY = cameraY + (float)(winHeight - fontHeight / 3) / cameraZoom;
 
 	if (offset) {
-		speechLine *viewLine = speech -> allSpeech;
+		speechLine *viewLine = speech->allSpeech;
 		while (viewLine) {
-			viewLine -> x += offset;
-			viewLine = viewLine -> next;
+			viewLine->x += offset;
+			viewLine = viewLine->next;
 		}
 	}
 	return speechTime;
 }
 
 int wrapSpeechPerson(char *theText, onScreenPerson &thePerson, int sampleFile, bool animPerson) {
-	int i = wrapSpeechXY(theText, thePerson.x - cameraX, thePerson.y - cameraY - (thePerson.scale * (thePerson.height - thePerson.floaty)) - thePerson.thisType -> speechGap, thePerson.thisType -> wrapSpeech, sampleFile);
+	int i = wrapSpeechXY(theText, thePerson.x - cameraX, thePerson.y - cameraY - (thePerson.scale * (thePerson.height - thePerson.floaty)) - thePerson.thisType->speechGap, thePerson.thisType->wrapSpeech, sampleFile);
 	if (animPerson) {
 		makeTalker(thePerson);
-		speech -> currentTalker = & thePerson;
+		speech->currentTalker = &thePerson;
 	}
 	return i;
 }
@@ -168,20 +168,20 @@ int wrapSpeechPerson(char *theText, onScreenPerson &thePerson, int sampleFile, b
 int wrapSpeech(char *theText, int objT, int sampleFile, bool animPerson) {
 	int i;
 
-	speech -> lookWhosTalking = objT;
+	speech->lookWhosTalking = objT;
 	onScreenPerson *thisPerson = findPerson(objT);
 	if (thisPerson) {
-		setObjFontColour(thisPerson -> thisType);
+		setObjFontColour(thisPerson->thisType);
 		i = wrapSpeechPerson(theText, * thisPerson, sampleFile, animPerson);
 	} else {
 		screenRegion *thisRegion = getRegionForObject(objT);
 		if (thisRegion) {
-			setObjFontColour(thisRegion -> thisType);
-			i = wrapSpeechXY(theText, ((thisRegion -> x1 + thisRegion -> x2) >> 1) - cameraX, thisRegion -> y1 - thisRegion -> thisType -> speechGap - cameraY, thisRegion -> thisType -> wrapSpeech, sampleFile);
+			setObjFontColour(thisRegion->thisType);
+			i = wrapSpeechXY(theText, ((thisRegion->x1 + thisRegion->x2) >> 1) - cameraX, thisRegion->y1 - thisRegion->thisType->speechGap - cameraY, thisRegion->thisType->wrapSpeech, sampleFile);
 		} else {
 			objectType *temp = findObjectType(objT);
 			setObjFontColour(temp);
-			i = wrapSpeechXY(theText, winWidth >> 1, 10, temp -> wrapSpeech, sampleFile);
+			i = wrapSpeechXY(theText, winWidth >> 1, 10, temp->wrapSpeech, sampleFile);
 		}
 	}
 	return i;
@@ -189,87 +189,89 @@ int wrapSpeech(char *theText, int objT, int sampleFile, bool animPerson) {
 
 void viewSpeech() {
 #if 0
-	int viewY = speech -> speechY;
-	speechLine *viewLine = speech -> allSpeech;
-	fixFont(speech -> talkCol);
+	int viewY = speech->speechY;
+	speechLine *viewLine = speech->allSpeech;
+	fixFont(speech->talkCol);
 	while (viewLine) {
-		pasteString(viewLine -> textLine, viewLine -> x, viewY, speech -> talkCol);
+		pasteString(viewLine->textLine, viewLine->x, viewY, speech->talkCol);
 		viewY -= fontHeight / cameraZoom;
-		viewLine = viewLine -> next;
+		viewLine = viewLine->next;
 	}
 #endif
 }
 
-#if ALLOW_FILE
-void saveSpeech(speechStruct *sS, FILE *fp) {
-	speechLine *viewLine = sS -> allSpeech;
+void saveSpeech(speechStruct *sS, Common::WriteStream *stream) {
+#if 0
+	speechLine *viewLine = sS->allSpeech;
 
-	fputc(sS -> talkCol.originalRed, fp);
-	fputc(sS -> talkCol.originalGreen, fp);
-	fputc(sS -> talkCol.originalBlue, fp);
+	putch(sS->talkCol.originalRed, stream);
+	putch(sS->talkCol.originalGreen, stream);
+	putch(sS->talkCol.originalBlue, stream);
 
-	putFloat(speechSpeed, fp);
+	putFloat(speechSpeed, stream);
 
 	// Write y co-ordinate
-	put2bytes(sS -> speechY, fp);
+	put2bytes(sS->speechY, stream);
 
 	// Write which character's talking
-	put2bytes(sS -> lookWhosTalking, fp);
-	if (sS -> currentTalker) {
-		fputc(1, fp);
-		put2bytes(sS -> currentTalker -> thisType -> objectNum, fp);
+	put2bytes(sS->lookWhosTalking, stream);
+	if (sS->currentTalker) {
+		putch(1, stream);
+		put2bytes(sS->currentTalker->thisType->objectNum, stream);
 	} else {
-		fputc(0, fp);
+		putch(0, stream);
 	}
 
 	// Write what's being said
 	while (viewLine) {
-		fputc(1, fp);
-		writeString(viewLine -> textLine, fp);
-		put2bytes(viewLine -> x, fp);
-		viewLine = viewLine -> next;
+		putch(1, stream);
+		writeString(viewLine->textLine, stream);
+		put2bytes(viewLine->x, stream);
+		viewLine = viewLine->next;
 	}
-	fputc(0, fp);
+	putch(0, stream);
+#endif
 }
 
-bool loadSpeech(speechStruct *sS, FILE *fp) {
-	speech -> currentTalker = NULL;
+bool loadSpeech(speechStruct *sS, Common::SeekableReadStream *stream) {
+#if 0
+	speech->currentTalker = NULL;
 	killAllSpeech();
-	byte r = fgetc(fp);
-	byte g = fgetc(fp);
-	byte b = fgetc(fp);
-	setFontColour(sS -> talkCol, r, g, b);
+	byte r = getch(stream);
+	byte g = getch(stream);
+	byte b = getch(stream);
+	setFontColour(sS->talkCol, r, g, b);
 
-	speechSpeed = getFloat(fp);
+	speechSpeed = getFloat(stream);
 
 	// Read y co-ordinate
-	sS -> speechY = get2bytes(fp);
+	sS->speechY = get2bytes(stream);
 
 	// Read which character's talking
-	sS -> lookWhosTalking = get2bytes(fp);
+	sS->lookWhosTalking = get2bytes(stream);
 
-	if (fgetc(fp)) {
-		sS -> currentTalker = findPerson(get2bytes(fp));
+	if (getch(stream)) {
+		sS->currentTalker = findPerson(get2bytes(stream));
 	} else {
-		sS -> currentTalker = NULL;
+		sS->currentTalker = NULL;
 	}
 
 	// Read what's being said
-	speechLine * * viewLine = & sS -> allSpeech;
+	speechLine * * viewLine = &sS->allSpeech;
 	speechLine *newOne;
-	speech -> lastFile = -1;
-	while (fgetc(fp)) {
+	speech->lastFile = -1;
+	while (getch(stream)) {
 		newOne = new speechLine;
 		if (! checkNew(newOne)) return false;
-		newOne -> textLine = readString(fp);
-		newOne -> x = get2bytes(fp);
-		newOne -> next = NULL;
+		newOne->textLine = readString(stream);
+		newOne->x = get2bytes(stream);
+		newOne->next = NULL;
 		(* viewLine) = newOne;
-		viewLine = & (newOne -> next);
+		viewLine = &(newOne->next);
 	}
 
 	return true;
-}
 #endif
+}
 
 } // End of namespace Sludge
diff --git a/engines/sludge/talk.h b/engines/sludge/talk.h
index a0fb1a9..2ce4c4a 100644
--- a/engines/sludge/talk.h
+++ b/engines/sludge/talk.h
@@ -47,10 +47,8 @@ void viewSpeech();
 void killAllSpeech();
 int isThereAnySpeechGoingOn();
 void initSpeech();
-#if ALLOW_FILE
-void saveSpeech(speechStruct *sS, FILE *fp);
-bool loadSpeech(speechStruct *sS, FILE *fp);
-#endif
+void saveSpeech(speechStruct *sS, Common::WriteStream *stream);
+bool loadSpeech(speechStruct *sS, Common::SeekableReadStream *stream);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/thumbnail.cpp b/engines/sludge/thumbnail.cpp
index 9cb471f..c24946a 100644
--- a/engines/sludge/thumbnail.cpp
+++ b/engines/sludge/thumbnail.cpp
@@ -40,8 +40,9 @@ int thumbWidth = 0, thumbHeight = 0;
 extern GLuint backdropTextureName;
 #endif
 
-#if ALLOW_FILE
-bool saveThumbnail(FILE *fp) {
+
+bool saveThumbnail(Common::WriteStream *stream) {
+#if 0
 	GLuint thumbnailTextureName = 0;
 
 	put4bytes(thumbWidth, fp);
@@ -136,8 +137,8 @@ bool saveThumbnail(FILE *fp) {
 	}
 	fputc('!', fp);
 	return true;
-}
 #endif
+}
 
 void showThumbnail(char *filename, int atX, int atY) {
 #if 0
@@ -254,15 +255,13 @@ void showThumbnail(char *filename, int atX, int atY) {
 #endif
 }
 
-#if ALLOW_FILE
-bool skipThumbnail(FILE *fp) {
-	thumbWidth = get4bytes(fp);
-	thumbHeight = get4bytes(fp);
+bool skipThumbnail(Common::SeekableReadStream *stream) {
+	thumbWidth = get4bytes(stream);
+	thumbHeight = get4bytes(stream);
 	uint32_t skippy = thumbWidth;
 	skippy *= thumbHeight << 1;
-	fseek(fp, skippy, 1);
-	return (fgetc(fp) == '!');
+	stream->seek(skippy, 1);
+	return (getch(stream) == '!');
 }
-#endif
 
 } // End of namespace Sludge
diff --git a/engines/sludge/thumbnail.h b/engines/sludge/thumbnail.h
index 3836478..4452dca 100644
--- a/engines/sludge/thumbnail.h
+++ b/engines/sludge/thumbnail.h
@@ -24,10 +24,8 @@
 
 namespace Sludge {
 
-#if ALLOW_FILE
-bool saveThumbnail(FILE *fp);
-bool skipThumbnail(FILE *fp);
-#endif
+bool saveThumbnail(Common::WriteStream *stream);
+bool skipThumbnail(Common::SeekableReadStream *stream);
 
 void showThumbnail(char *filename, int x, int y);
 
diff --git a/engines/sludge/timing.cpp b/engines/sludge/timing.cpp
index ae4c0cd..887c4ed 100644
--- a/engines/sludge/timing.cpp
+++ b/engines/sludge/timing.cpp
@@ -26,6 +26,8 @@
 namespace Sludge {
 
 int desiredfps = 300;               //holds desired frames per second
+
+#if 0
 Uint32 starttime, endtime;
 Uint32 desired_frame_time;
 
@@ -55,5 +57,6 @@ void Wait_Frame(void) {
 
 	starttime = endtime;
 }
+#endif
 
 } // End of namespace Sludge
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index 334beb1..928b65b 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -29,6 +29,9 @@
 #include "people.h"
 #include "fileset.h"
 
+#include "sludge.h"
+#include "common/debug.h"
+
 #include <dirent.h>
 #include "moreio.h"
 #ifdef _WIN32
@@ -325,9 +328,8 @@ void makeTextVar(variable &thisVar, const char *txt) {
 }
 
 bool loadStringToVar(variable &thisVar, int value) {
-#if ALLOW_FILE
+
 	makeTextVar(thisVar, getNumberedString(value));
-#endif
 	return (bool)(thisVar.varData.theString != NULL);
 }
 
@@ -536,7 +538,7 @@ bool addVarToStack(const variable &va, variableStack *&thisStack) {
 	if (! copyMain(va, newStack -> thisVar)) return false;
 	newStack -> next = thisStack;
 	thisStack = newStack;
-	//printf("Variable %s was added to stack\n", getTextFromAnyVar(va));
+	debug(kSludgeDebugStackMachine, "Variable %s was added to stack", getTextFromAnyVar(va));
 	return true;
 }
 
@@ -551,7 +553,7 @@ bool addVarToStackQuick(variable &va, variableStack *&thisStack) {
 
 	newStack -> next = thisStack;
 	thisStack = newStack;
-	//printf("Variable %s was added to stack quick\n", getTextFromAnyVar(va));
+	debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick", getTextFromAnyVar(va));
 	return true;
 }
 
@@ -622,7 +624,7 @@ void trimStack(variableStack *&stack) {
 	variableStack *killMe = stack;
 	stack = stack -> next;
 
-	//printf("Variable %s was removed from stack\n", getTextFromAnyVar(killMe -> thisVar));
+	debug(kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe -> thisVar));
 
 	// When calling this, we've ALWAYS checked that stack != NULL
 	unlinkVar(killMe -> thisVar);
diff --git a/engines/sludge/vid.cpp b/engines/sludge/vid.cpp
index 266c5bd..13eea52 100644
--- a/engines/sludge/vid.cpp
+++ b/engines/sludge/vid.cpp
@@ -155,7 +155,7 @@ bool extractSlice(int fileNum, char *toName) {
 
 	unsigned long fileLength = openFileFromNum(fileNum);
 	if (! fileLength) return false; // Error already displayed
-
+#if 0
 	FILE *copyVid = fopen(toName, "wb");
 	if (! copyVid) return fatal("Can't extract resource");
 
@@ -170,6 +170,7 @@ bool extractSlice(int fileNum, char *toName) {
 	}
 
 	fclose(copyVid);
+#endif
 	finishAccess();
 
 	return true;
diff --git a/engines/sludge/zbuffer.cpp b/engines/sludge/zbuffer.cpp
index ddcebb1..f73f4f6 100644
--- a/engines/sludge/zbuffer.cpp
+++ b/engines/sludge/zbuffer.cpp
@@ -19,8 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "common/system.h"
-
 #include "allfiles.h"
 #include "zbuffer.h"
 #include "fileset.h"
@@ -66,7 +64,7 @@ void sortZPal(int *oldpal, int *newpal, int size) {
 }
 
 bool setZBuffer(int y) {
-#if ALLOW_FILE
+#if 0
 	int x, n;
 	uint32_t stillToGo = 0;
 	int yPalette[16], sorted[16], sortback[16];


Commit: f8ca5d14c4e6468f2963561e15cc86978cb08fe4
    https://github.com/scummvm/scummvm/commit/f8ca5d14c4e6468f2963561e15cc86978cb08fe4
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Replace stream writing functions id backdrop and formatting

Changed paths:
    engines/sludge/backdrop.cpp


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index 929e67d..6b99f0c 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -110,14 +110,14 @@ void saveSnapshot(Common::WriteStream *stream) {
 bool snapshot() {
 
 	nosnapshot();
-	if (! freeze()) return false;
+	if (!freeze()) return false;
 #if 0
 	setPixelCoords(true);
 	glGenTextures(1, &snapshotTextureName);
 
 	int w = winWidth;
 	int h = winHeight;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		w = getNextPOT(winWidth);
 		h = getNextPOT(winHeight);
 		snapTexW = ((double)winWidth) / w;
@@ -168,14 +168,14 @@ bool restoreSnapshot(Common::SeekableReadStream *stream) {
 	unsigned short c;
 #if 0
 	GLubyte *target;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(picWidth);
 		picHeight = getNextPOT(picHeight);
 		snapTexW = ((double)winWidth) / picWidth;
 		snapTexH = ((double)winHeight) / picHeight;
 	}
 	GLubyte *snapshotTexture = new GLubyte [picHeight * picWidth * 4];
-	if (! snapshotTexture) return fatal("Out of memory while restoring snapshot.");
+	if (!snapshotTexture) return fatal("Out of memory while restoring snapshot.");
 #endif
 
 	for (t2 = 0; t2 < winHeight; t2 ++) {
@@ -201,7 +201,7 @@ bool restoreSnapshot(Common::SeekableReadStream *stream) {
 		}
 	}
 #if 0
-	if (! snapshotTextureName) glGenTextures(1, &snapshotTextureName);
+	if (!snapshotTextureName) glGenTextures(1, &snapshotTextureName);
 	glBindTexture(GL_TEXTURE_2D, snapshotTextureName);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -241,11 +241,11 @@ void killParallax() {
 	while (parallaxStuff) {
 
 		parallaxLayer *k = parallaxStuff;
-		parallaxStuff = k -> next;
+		parallaxStuff = k->next;
 
 		// Now kill the image
-		deleteTextures(1, &k -> textureName);
-		delete k -> texture;
+		deleteTextures(1, &k->textureName);
+		delete k->texture;
 		delete k;
 		k = NULL;
 	}
@@ -267,16 +267,16 @@ bool reserveBackdrop() {
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
 	if (backdropTexture) delete backdropTexture;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(sceneWidth);
 		picHeight = getNextPOT(sceneHeight);
 		backdropTexW = ((double)sceneWidth) / picWidth;
 		backdropTexH = ((double)sceneHeight) / picHeight;
 	}
 	backdropTexture = new GLubyte [picWidth * picHeight * 4];
-	if (! checkNew(backdropTexture)) return false;
+	if (!checkNew(backdropTexture)) return false;
 
-	if (! backdropTextureName) glGenTextures(1, &backdropTextureName);
+	if (!backdropTextureName) glGenTextures(1, &backdropTextureName);
 	glBindTexture(GL_TEXTURE_2D, backdropTextureName);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -306,12 +306,12 @@ bool resizeBackdrop(int x, int y) {
 void loadBackDrop(int fileNum, int x, int y) {
 	setResourceForFatal(fileNum);
 #if 0
-	if (! openFileFromNum(fileNum)) {
+	if (!openFileFromNum(fileNum)) {
 		fatal("Can't load overlay image");
 		return;
 	}
 
-	if (! loadHSI(bigDataFile, x, y, false)) {
+	if (!loadHSI(bigDataFile, x, y, false)) {
 		char mess[200];
 		sprintf(mess, "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight);
 		fatal(mess);
@@ -325,12 +325,12 @@ void loadBackDrop(int fileNum, int x, int y) {
 void mixBackDrop(int fileNum, int x, int y) {
 #if 0
 	setResourceForFatal(fileNum);
-	if (! openFileFromNum(fileNum)) {
+	if (!openFileFromNum(fileNum)) {
 		fatal("Can't load overlay image");
 		return;
 	}
 
-	if (! mixHSI(bigDataFile, x, y)) {
+	if (!mixHSI(bigDataFile, x, y)) {
 		fatal("Can't paste overlay image outside screen dimensions");
 	}
 
@@ -396,7 +396,7 @@ void hardScroll(int distance) {
 		return;
 	}
 
-	if (! distance) return;
+	if (!distance) return;
 #if 0
 	const GLfloat backdropTexCoords[] = {
 		0.0f, 0.0f,
@@ -563,15 +563,15 @@ void drawBackDrop() {
 		while (ps->next) ps = ps->next;
 
 		while (ps) {
-			ps -> cameraX = sortOutPCamera(cameraX, ps -> fractionX, (int)(sceneWidth - (float)winWidth / cameraZoom), (int)(ps -> width - (float)winWidth / cameraZoom));
-			ps -> cameraY = sortOutPCamera(cameraY, ps -> fractionY, (int)(sceneHeight - (float)winHeight / cameraZoom), (int)(ps -> height - (float)winHeight / cameraZoom));
+			ps->cameraX = sortOutPCamera(cameraX, ps->fractionX, (int)(sceneWidth - (float)winWidth / cameraZoom), (int)(ps->width - (float)winWidth / cameraZoom));
+			ps->cameraY = sortOutPCamera(cameraY, ps->fractionY, (int)(sceneHeight - (float)winHeight / cameraZoom), (int)(ps->height - (float)winHeight / cameraZoom));
 			glBindTexture(GL_TEXTURE_2D, ps->textureName);
 
 			float w = (ps->wrapS) ? sceneWidth : ps->width;
 			float h = (ps->wrapT) ? sceneHeight : ps->height;
 			float texw;
 			float texh;
-			if (! NPOT_textures) {
+			if (!NPOT_textures) {
 				texw = (ps->wrapS) ? (float) sceneWidth / ps->width : (float) ps->width / getNextPOT(ps->width);
 				texh = (ps->wrapT) ? (float) sceneHeight / ps->height : (float) ps->height / getNextPOT(ps->height);
 			} else {
@@ -580,10 +580,10 @@ void drawBackDrop() {
 			}
 
 			const GLfloat vertices[] = {
-				(GLfloat) - ps -> cameraX, (GLfloat) - ps -> cameraY, 0.1f,
-				w - ps -> cameraX, (GLfloat) - ps -> cameraY, 0.1f,
-				(GLfloat) - ps -> cameraX, h - ps -> cameraY, 0.1f,
-				w - ps -> cameraX, h - ps -> cameraY, 0.1f
+				(GLfloat) - ps->cameraX, (GLfloat) - ps->cameraY, 0.1f,
+				w - ps->cameraX, (GLfloat) - ps->cameraY, 0.1f,
+				(GLfloat) - ps->cameraX, h - ps->cameraY, 0.1f,
+				w - ps->cameraX, h - ps->cameraY, 0.1f
 			};
 
 			const GLfloat texCoords[] = {
@@ -594,7 +594,7 @@ void drawBackDrop() {
 			};
 			drawQuad(shader.smartScaler, vertices, 1, texCoords);
 
-			ps = ps -> prev;
+			ps = ps->prev;
 		}
 	}
 
@@ -626,7 +626,7 @@ bool loadLightMap(int v) {
 	int newPicWidth, newPicHeight;
 #if 0
 	setResourceForFatal(v);
-	if (! openFileFromNum(v)) return fatal("Can't open light map.");
+	if (!openFileFromNum(v)) return fatal("Can't open light map.");
 	long file_pointer = ftell(bigDataFile);
 
 	png_structp png_ptr;
@@ -701,7 +701,7 @@ bool loadLightMap(int v) {
 		}
 	}
 
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		newPicWidth = getNextPOT(lightMap.w);
 		newPicHeight = getNextPOT(lightMap.h);
 		lightMap.texW = (double) lightMap.w / newPicWidth;
@@ -719,7 +719,7 @@ bool loadLightMap(int v) {
 	if (lightMap.data) delete [] lightMap.data;
 
 	lightMap.data = new GLubyte [newPicWidth * newPicHeight * 4];
-	if (! lightMap.data) {
+	if (!lightMap.data) {
 		return fatal("Out of memory loading light map.");
 	}
 
@@ -759,7 +759,7 @@ bool loadLightMap(int v) {
 		}
 	}
 #if 0
-	if (! lightMap.name) glGenTextures(1, &lightMap.name);
+	if (!lightMap.name) glGenTextures(1, &lightMap.name);
 	glBindTexture(GL_TEXTURE_2D, lightMap.name);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -779,7 +779,7 @@ bool loadLightMap(int v) {
 void reloadParallaxTextures() {
 #if 0
 	parallaxLayer *nP = parallaxStuff;
-	if (! nP) return;
+	if (!nP) return;
 
 	while (nP) {
 		//fprintf (stderr, "Reloading parallax. (%d, %d) ", nP->width, nP->height);
@@ -787,11 +787,11 @@ void reloadParallaxTextures() {
 
 		glGenTextures(1, &nP->textureName);
 		glBindTexture(GL_TEXTURE_2D, nP->textureName);
-		if (nP -> wrapS)
+		if (nP->wrapS)
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 		else
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-		if (nP -> wrapT)
+		if (nP->wrapT)
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 		else
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -804,7 +804,7 @@ void reloadParallaxTextures() {
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 		}
 
-		if (! NPOT_textures) {
+		if (!NPOT_textures) {
 			texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getNextPOT(nP->width), getNextPOT(nP->height), 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName);
 		} else {
 			texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nP->width, nP->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName);
@@ -819,17 +819,17 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 #if 0
 	setResourceForFatal(v);
-	if (! openFileFromNum(v)) return fatal("Can't open parallax image");
+	if (!openFileFromNum(v)) return fatal("Can't open parallax image");
 
 	parallaxLayer *nP = new parallaxLayer;
-	if (! checkNew(nP)) return false;
+	if (!checkNew(nP)) return false;
 
-	nP -> next = parallaxStuff;
+	nP->next = parallaxStuff;
 	parallaxStuff = nP;
-	if (nP -> next) {
-		nP -> next -> prev = nP;
+	if (nP->next) {
+		nP->next->prev = nP;
 	}
-	nP -> prev = NULL;
+	nP->prev = NULL;
 
 	int picWidth;
 	int picHeight;
@@ -854,8 +854,8 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 		fileIsPNG = false;
 		fseek(bigDataFile, file_pointer, SEEK_SET);
 
-		picWidth = nP -> width = get2bytes(bigDataFile);
-		picHeight = nP -> height = get2bytes(bigDataFile);
+		picWidth = nP->width = get2bytes(bigDataFile);
+		picHeight = nP->height = get2bytes(bigDataFile);
 	} else {
 		// Read the PNG header
 
@@ -884,8 +884,8 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 		int bit_depth, color_type, interlace_type, compression_type, filter_method;
 		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
 
-		picWidth = nP -> width = width;
-		picHeight = nP -> height = height;
+		picWidth = nP->width = width;
+		picHeight = nP->height = height;
 
 		if (bit_depth < 8) png_set_packing(png_ptr);
 		png_set_expand(png_ptr);
@@ -901,42 +901,42 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 	}
 
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(picWidth);
 		picHeight = getNextPOT(picHeight);
 	}
 
-	nP -> fileNum = v;
-	nP -> fractionX = fracX;
-	nP -> fractionY = fracY;
+	nP->fileNum = v;
+	nP->fractionX = fracX;
+	nP->fractionY = fracY;
 
 	if (fracX == 65535) {
-		nP -> wrapS = false;
-		if (nP -> width < winWidth) {
+		nP->wrapS = false;
+		if (nP->width < winWidth) {
 			fatal("For AUTOFIT parallax backgrounds, the image must be at least as wide as the game window/screen.");
 			return false;
 		}
 	} else {
-		nP -> wrapS = true;
+		nP->wrapS = true;
 	}
 
 	if (fracY == 65535) {
-		nP -> wrapT = false;
-		if (nP -> height < winHeight) {
+		nP->wrapT = false;
+		if (nP->height < winHeight) {
 			fatal("For AUTOFIT parallax backgrounds, the image must be at least as tall as the game window/screen.");
 			return false;
 		}
 	} else {
-		nP -> wrapT = true;
+		nP->wrapT = true;
 	}
 
-	nP -> texture = new GLubyte [picHeight * picWidth * 4];
-	if (! checkNew(nP -> texture)) return false;
+	nP->texture = new GLubyte [picHeight * picWidth * 4];
+	if (!checkNew(nP->texture)) return false;
 
 	if (fileIsPNG) {
-		unsigned char *row_pointers[nP -> height];
-		for (int i = 0; i < nP -> height; i++)
-			row_pointers[i] = nP -> texture + 4 * i * picWidth;
+		unsigned char *row_pointers[nP->height];
+		for (int i = 0; i < nP->height; i++)
+			row_pointers[i] = nP->texture + 4 * i * picWidth;
 
 		png_read_image(png_ptr, (png_byte **) row_pointers);
 		png_read_end(png_ptr, NULL);
@@ -947,9 +947,9 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 		unsigned short c;
 		GLubyte *target;
 
-		for (t2 = 0; t2 < nP -> height; t2 ++) {
+		for (t2 = 0; t2 < nP->height; t2 ++) {
 			t1 = 0;
-			while (t1 < nP -> width) {
+			while (t1 < nP->width) {
 				c = (unsigned short) get2bytes(bigDataFile);
 				if (c & 32) {
 					n = fgetc(bigDataFile) + 1;
@@ -958,7 +958,7 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 					n = 1;
 				}
 				while (n--) {
-					target = nP -> texture + 4 * picWidth * t2 + t1 * 4;
+					target = nP->texture + 4 * picWidth * t2 + t1 * 4;
 					if (c == 63519 || c == 2015) {
 						target[0] = (GLubyte) 0;
 						target[1] = (GLubyte) 0;
@@ -978,11 +978,11 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 	glGenTextures(1, &nP->textureName);
 	glBindTexture(GL_TEXTURE_2D, nP->textureName);
-	if (nP -> wrapS)
+	if (nP->wrapS)
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	else
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	if (nP -> wrapT)
+	if (nP->wrapT)
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 	else
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -1005,9 +1005,9 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 extern int viewportOffsetX, viewportOffsetY;
 
-#if 0
-bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 
+bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
+#if 0
 	int t1, t2, n;
 	unsigned short c;
 	GLubyte *target;
@@ -1039,7 +1039,6 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 		picHeight = realPicHeight = get2bytes(stream);
 	} else {
 		// Read the PNG header
-#if 0
 		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 		if (!png_ptr) {
 			return false;
@@ -1079,13 +1078,11 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
 
 		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-#endif
 	}
 
-#if 0
 	GLfloat texCoordW = 1.0;
 	GLfloat texCoordH = 1.0;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(picWidth);
 		picHeight = getNextPOT(picHeight);
 		texCoordW = ((double)realPicWidth) / picWidth;
@@ -1093,7 +1090,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 	}
 
 	if (reserve) {
-		if (! resizeBackdrop(realPicWidth, realPicHeight)) return false;
+		if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
 	}
 
 	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
@@ -1162,7 +1159,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 	float btx2;
 	float bty1;
 	float bty2;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		btx1 = backdropTexW * x / sceneWidth;
 		btx2 = backdropTexW * (x + realPicWidth) / sceneWidth;
 		bty1 = backdropTexH * y / sceneHeight;
@@ -1259,12 +1256,13 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 	deleteTextures(1, &tmpTex);
 
 	setPixelCoords(false);
-#endif
 	backdropExists = true;
+#endif
 	return true;
 }
 
 bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
+#if 0
 	int realPicWidth, realPicHeight;
 	int picWidth;
 	int picHeight;
@@ -1283,7 +1281,6 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 	if (bytes_read != 8 && stream->err()) {
 		debugOut("Reading error in mixHSI.\n");
 	}
-#if 0
 	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
 		// No, it's old-school HSI
 		fileIsPNG = false;
@@ -1345,7 +1342,7 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 	float bty1, ty1;
 	float bty2, ty2;
 
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		tx1 = 0.0;
 		ty1 = 0.0;
 		tx2 = ((double)picWidth) / getNextPOT(picWidth);
@@ -1498,9 +1495,8 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 #endif
 	return true;
 }
-
-void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 #if 0
+void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 	GLint tw, th;
 
 	glBindTexture(GL_TEXTURE_2D, texture);
@@ -1508,13 +1504,12 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 	getTextureDimensions(texture, &tw, &th);
 
 	GLubyte *image = new GLubyte [tw * th * 4];
-	if (! checkNew(image)) return;
+	if (!checkNew(image)) return;
 
 	glPixelStorei(GL_PACK_ALIGNMENT, 1);
 //	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
-#endif
+
 #ifdef HAVE_GLES2
-#if 0
 	GLuint old_fbo, new_fbo;
 	GLint old_vp[4];
 	glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *)&old_fbo);
@@ -1527,13 +1522,8 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 	glBindFramebuffer(GL_FRAMEBUFFER, old_fbo);
 	glViewport(old_vp[0], old_vp[1], old_vp[2], old_vp[3]);
 	glDeleteFramebuffers(1, &new_fbo);
-#endif
 #else
 	setPixelCoords(true);
-
-
-	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-
 	const GLfloat texCoords[] = {
 		0.0f, 0.0f,
 		1.0f, 0.0f,
@@ -1548,9 +1538,8 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 		int yoffset = 0;
 		while (yoffset < th) {
 			int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight;
-#if 0
+
 			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
-#endif
 			const GLfloat vertices[] = {
 				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
 				(GLfloat)tw - xoffset, (GLfloat) - yoffset, 0.,
@@ -1558,7 +1547,6 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 				(GLfloat)tw - xoffset, (GLfloat) - yoffset + th, 0.
 			};
 
-#if 0
 			glUseProgram(shader.texture);
 
 			setPMVMatrix(shader.texture);
@@ -1570,16 +1558,12 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 			for (int i = 0; i < h; i++)   {
 				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, image + xoffset * 4 + (yoffset + i) * 4 * tw);
 			}
-#endif
 			yoffset += viewportHeight;
 		}
 
 		xoffset += viewportWidth;
 	}
 	setPixelCoords(false);
-#endif
-
-
 
 	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 	if (!png_ptr) {
@@ -1610,22 +1594,20 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 
 	delete [] image;
 	image = NULL;
+#endif
 }
+#endif
 
-void saveCoreHSI(FILE *writer, GLuint texture, int w, int h) {
-
-	GLint tw, th;
 #if 0
+void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
+	GLint tw, th;
 	glBindTexture(GL_TEXTURE_2D, texture);
-#endif
 	getTextureDimensions(texture, &tw, &th);
 
 	GLushort *image = new GLushort [tw * th];
-	if (! checkNew(image)) return;
-#if 0
+	if (!checkNew(image)) return;
 	glPixelStorei(GL_PACK_ALIGNMENT, 1);
 //	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image);
-#endif
 	setPixelCoords(true);
 
 	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
@@ -1644,9 +1626,7 @@ void saveCoreHSI(FILE *writer, GLuint texture, int w, int h) {
 		int yoffset = 0;
 		while (yoffset < th) {
 			int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight;
-#if 0
 			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
-#endif
 			const GLfloat vertices[] = {
 				(GLfloat) - xoffset, (GLfloat) - yoffset, 0.,
 				(GLfloat)w - xoffset, (GLfloat) - yoffset, 0.,
@@ -1654,34 +1634,27 @@ void saveCoreHSI(FILE *writer, GLuint texture, int w, int h) {
 				(GLfloat)w - xoffset, (GLfloat) - yoffset + h, 0.
 			};
 
-#if 0
 			glUseProgram(shader.texture);
-#endif
 			setPMVMatrix(shader.texture);
 			drawQuad(shader.texture, vertices, 1, texCoords);
-#if 0
 			glUseProgram(0);
 
 			for (int i = 0; i < h; i++)   {
 				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i)*tw);
 			}
-#endif
 			yoffset += viewportHeight;
 		}
 
 		xoffset += viewportWidth;
 	}
 	//glReadPixels(viewportOffsetX, viewportOffsetY, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, data);
-
 	setPixelCoords(false);
 
-
-
 	int x, y, lookAhead;
 	unsigned short int *fromHere, * lookPointer;
 
-	put2bytes(w, writer);
-	put2bytes(h, writer);
+	put2bytes(w, stream);
+	put2bytes(h, stream);
 
 	for (y = 0; y < h; y ++) {
 		fromHere = image + (y * tw);
@@ -1694,10 +1667,10 @@ void saveCoreHSI(FILE *writer, GLuint texture, int w, int h) {
 				lookPointer ++;
 			}
 			if (lookAhead == x + 1) {
-				put2bytes((* fromHere) & 65503, writer);
+				put2bytes((* fromHere) & 65503, stream);
 			} else {
-				put2bytes(* fromHere | 32, writer);
-				fputc(lookAhead - x - 1, writer);
+				put2bytes(* fromHere | 32, stream);
+				putch(lookAhead - x - 1, stream);
 			}
 			fromHere = lookPointer;
 			x = lookAhead;
@@ -1706,22 +1679,23 @@ void saveCoreHSI(FILE *writer, GLuint texture, int w, int h) {
 	delete [] image;
 	image = NULL;
 }
+#endif
 
-void saveHSI(FILE *writer) {
-	saveCorePNG(writer, backdropTextureName, sceneWidth, sceneHeight);
+#if 0
+void saveHSI(Common::WriteStream *stream) {
+	saveCorePNG(stream, backdropTextureName, sceneWidth, sceneHeight);
 }
+#endif
 
-
-void saveParallaxRecursive(parallaxLayer *me, FILE *fp) {
+void saveParallaxRecursive(parallaxLayer *me, Common::WriteStream *stream) {
 	if (me) {
-		saveParallaxRecursive(me -> next, fp);
-		fputc(1, fp);
-		put2bytes(me->fileNum, fp);
-		put2bytes(me ->fractionX, fp);
-		put2bytes(me->fractionY, fp);
+		saveParallaxRecursive(me->next, stream);
+		putch(1, stream);
+		put2bytes(me->fileNum, stream);
+		put2bytes(me ->fractionX, stream);
+		put2bytes(me->fractionY, stream);
 	}
 }
-#endif
 
 bool getRGBIntoStack(unsigned int x, unsigned int y, stackHandler *sH) {
 #if 0
@@ -1736,21 +1710,21 @@ bool getRGBIntoStack(unsigned int x, unsigned int y, stackHandler *sH) {
 	saveTexture(backdropTextureName, backdropTexture);
 
 	GLubyte *target;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		target = backdropTexture + 4 * getNextPOT(sceneWidth) * y + x * 4;
 	} else {
 		target = backdropTexture + 4 * sceneWidth * y + x * 4;
 	}
 
 	setVariable(newValue, SVT_INT, target[2]);
-	if (! addVarToStackQuick(newValue, sH -> first)) return false;
-	sH -> last = sH -> first;
+	if (!addVarToStackQuick(newValue, sH->first)) return false;
+	sH->last = sH->first;
 
 	setVariable(newValue, SVT_INT, target[1]);
-	if (! addVarToStackQuick(newValue, sH -> first)) return false;
+	if (!addVarToStackQuick(newValue, sH->first)) return false;
 
 	setVariable(newValue, SVT_INT, target[0]);
-	if (! addVarToStackQuick(newValue, sH -> first)) return false;
+	if (!addVarToStackQuick(newValue, sH->first)) return false;
 #endif
 	return true;
 }


Commit: 9f7d301ef4b48469ad1679e479f8597d1b3e97e1
    https://github.com/scummvm/scummvm/commit/9f7d301ef4b48469ad1679e479f8597d1b3e97e1
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Refactor background loading code

Changed paths:
    engines/sludge/backdrop.cpp


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index 6b99f0c..b5c3885 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -1005,24 +1005,19 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 extern int viewportOffsetX, viewportOffsetY;
 
-
-bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 #if 0
+bool loadImage(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) {
+
 	int t1, t2, n;
 	unsigned short c;
 	GLubyte *target;
 	int32_t transCol = reserve ? -1 : 63519;
-	int picWidth;
-	int picHeight;
-	int realPicWidth, realPicHeight;
 	long file_pointer = stream->pos();
-
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
 
 
 	int fileIsPNG = true;
-
 	// Is this a PNG file?
 
 	char tmp[10];
@@ -1076,21 +1071,10 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 
 		png_read_update_info(png_ptr, info_ptr);
 		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-
-		//int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-	}
-
-	GLfloat texCoordW = 1.0;
-	GLfloat texCoordH = 1.0;
-	if (!NPOT_textures) {
-		picWidth = getNextPOT(picWidth);
-		picHeight = getNextPOT(picHeight);
-		texCoordW = ((double)realPicWidth) / picWidth;
-		texCoordH = ((double)realPicHeight) / picHeight;
 	}
 
 	if (reserve) {
-		if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
+		if (! resizeBackdrop(realPicWidth, realPicHeight)) return false;
 	}
 
 	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
@@ -1102,7 +1086,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 		for (int i = 0; i < realPicHeight; i++)
 			row_pointers[i] = backdropTexture + 4 * i * picWidth;
 
-		png_read_image(png_ptr, (png_byte **) row_pointers);
+		png_read_image(png_ptr, (png_byte **)row_pointers);
 		png_read_end(png_ptr, NULL);
 		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
 	} else {
@@ -1116,7 +1100,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 				} else {
 					n = 1;
 				}
-				while (n --) {
+				while (--n) {
 					target = backdropTexture + 4 * picWidth * t2 + t1 * 4;
 					if (c == transCol || c == 2015) {
 						target[0] = (GLubyte) 0;
@@ -1134,9 +1118,10 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 			}
 		}
 	}
+	return true;
+}
 
-	GLuint tmpTex;
-
+void makeGlArray(GLuint &tmpTex, const GLubyte *texture, int picWidth, int picHeight) {
 	glGenTextures(1, &tmpTex);
 	glBindTexture(GL_TEXTURE_2D, tmpTex);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -1148,18 +1133,25 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	}
+	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture, tmpTex);
 
-	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
-
-
-	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+}
 
+void renderToTexture(GLuint tmpTex, int x, int y, int picWidth, int picHeight, int realPicWidth, int realPicHeight) {
+	GLfloat texCoordW = 1.0;
+	GLfloat texCoordH = 1.0;
+	if (! NPOT_textures) {
+		picWidth = getNextPOT(picWidth);
+		picHeight = getNextPOT(picHeight);
+		texCoordW = ((double)realPicWidth) / picWidth;
+		texCoordH = ((double)realPicHeight) / picHeight;
+	}
 
 	float btx1;
 	float btx2;
 	float bty1;
 	float bty2;
-	if (!NPOT_textures) {
+	if (! NPOT_textures) {
 		btx1 = backdropTexW * x / sceneWidth;
 		btx2 = backdropTexW * (x + realPicWidth) / sceneWidth;
 		bty1 = backdropTexH * y / sceneHeight;
@@ -1205,7 +1197,6 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 			};
 
 			if (backdropExists) {
-
 				// Render the sprite to the backdrop
 				// (using mulitexturing, so the old backdrop is seen where alpha < 1.0)
 				glActiveTexture(GL_TEXTURE2);
@@ -1215,10 +1206,10 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 				glUseProgram(shader.paste);
 				GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
 				if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
+
 				setPMVMatrix(shader.paste);
 
 				setPrimaryColor(1.0, 1.0, 1.0, 1.0);
-
 				glBindTexture(GL_TEXTURE_2D, tmpTex);
 				//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
@@ -1228,10 +1219,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 
 			} else {
 				// It's all new - nothing special to be done.
-
-
 				glUseProgram(shader.texture);
-
 				setPMVMatrix(shader.texture);
 
 				glBindTexture(GL_TEXTURE_2D, tmpTex);
@@ -1240,9 +1228,7 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 
 				drawQuad(shader.texture, vertices, 1, texCoords);
 
-
 				glUseProgram(0);
-
 			}
 
 			// Copy Our ViewPort To The Texture
@@ -1250,12 +1236,27 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 
 			yoffset += viewportHeight;
 		}
-
 		xoffset += viewportWidth;
 	}
+	setPixelCoords(false);
+}
+#endif
+
+bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
+#if 0
+	int picWidth, picHeight;
+	int realPicWidth, realPicHeight;
+
+	if (!loadImage(backdropTexture, picWidth, picHeight, realPicWidth, realPicHeight, stream, x, y, reserve))
+		return false;
+
+	GLuint tmpTex;
+	makeGlArray(tmpTex, backdropTexture, picWidth, picHeight);
+
+	renderToTexture(tmpTex, x, y, picWidth, picHeight, realPicWidth, realPicHeight);
+
 	deleteTextures(1, &tmpTex);
 
-	setPixelCoords(false);
 	backdropExists = true;
 #endif
 	return true;


Commit: 6808650f3e17f57c2dc2424c813f1f62a04ed03c
    https://github.com/scummvm/scummvm/commit/6808650f3e17f57c2dc2424c813f1f62a04ed03c
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Refactor png specific functions in backdrop

Changed paths:
    engines/sludge/backdrop.cpp


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index b5c3885..3e05997 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -1006,118 +1006,128 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 extern int viewportOffsetX, viewportOffsetY;
 
 #if 0
-bool loadImage(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) {
-
-	int t1, t2, n;
-	unsigned short c;
-	GLubyte *target;
-	int32_t transCol = reserve ? -1 : 63519;
+bool loadPng(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
 	long file_pointer = stream->pos();
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
 
-
-	int fileIsPNG = true;
-	// Is this a PNG file?
-
 	char tmp[10];
 	size_t bytes_read = stream->read(tmp, 8);
+
 	if (bytes_read != 8 && stream->err()) {
-		debugOut("Reading error in loadHSI.\n");
+		stream->seek(file_pointer, SEEK_SET);
+		return false;
 	}
+
 	if (png_sig_cmp((png_byte *) tmp, 0, 8)) {
-		// No, it's old-school HSI
-		fileIsPNG = false;
 		stream->seek(file_pointer, SEEK_SET);
+		return false;
+	}
 
-		picWidth = realPicWidth = get2bytes(stream);
-		picHeight = realPicHeight = get2bytes(stream);
-	} else {
-		// Read the PNG header
-		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-		if (!png_ptr) {
-			return false;
-		}
+	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+	if (!png_ptr) {
+		return false;
+	}
 
-		info_ptr = png_create_info_struct(png_ptr);
-		if (!info_ptr) {
-			png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
-			return false;
-		}
+	info_ptr = png_create_info_struct(png_ptr);
+	if (!info_ptr) {
+		png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+		return false;
+	}
 
-		end_info = png_create_info_struct(png_ptr);
-		if (!end_info) {
-			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-			return false;
-		}
-		png_init_io(png_ptr, fp);       // Tell libpng which file to read
-		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+	end_info = png_create_info_struct(png_ptr);
+	if (!end_info) {
+		png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+		return false;
+	}
+	png_init_io(png_ptr, stream);		// Tell libpng which file to read
+	png_set_sig_bytes(png_ptr, 8);	// 8 bytes already read
 
-		png_read_info(png_ptr, info_ptr);
+	png_read_info(png_ptr, info_ptr);
 
-		png_uint_32 width, height;
-		int bit_depth, color_type, interlace_type, compression_type, filter_method;
-		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+	png_uint_32 width, height;
+	int bit_depth, color_type, interlace_type, compression_type, filter_method;
+	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
 
-		picWidth = realPicWidth = width;
-		picHeight = realPicHeight = height;
+	picWidth = realPicWidth = width;
+	picHeight = realPicHeight = height;
 
-		if (bit_depth < 8) png_set_packing(png_ptr);
-		png_set_expand(png_ptr);
-		if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
-		if (bit_depth == 16) png_set_strip_16(png_ptr);
+	if (bit_depth < 8) png_set_packing(png_ptr);
+	png_set_expand(png_ptr);
+	if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
+	if (bit_depth == 16) png_set_strip_16(png_ptr);
 
-		png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
+	png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
 
-		png_read_update_info(png_ptr, info_ptr);
-		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
-	}
+	png_read_update_info(png_ptr, info_ptr);
+	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
 
 	if (reserve) {
-		if (! resizeBackdrop(realPicWidth, realPicHeight)) return false;
+		if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
 	}
 
-	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
-	if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1;
-	if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false;
+	unsigned char *row_pointers[realPicHeight];
 
-	if (fileIsPNG) {
-		unsigned char *row_pointers[realPicHeight];
-		for (int i = 0; i < realPicHeight; i++)
-			row_pointers[i] = backdropTexture + 4 * i * picWidth;
+	for (int i = 0; i < realPicHeight; i++)
+		row_pointers[i] = loadhere + 4 * i * picWidth;
 
-		png_read_image(png_ptr, (png_byte **)row_pointers);
-		png_read_end(png_ptr, NULL);
-		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
-	} else {
-		for (t2 = 0; t2 < realPicHeight; t2 ++) {
-			t1 = 0;
-			while (t1 < realPicWidth) {
-				c = (unsigned short) get2bytes(fp);
-				if (c & 32) {
-					n = fgetc(fp) + 1;
-					c -= 32;
+	png_read_image(png_ptr, (png_byte **) row_pointers);
+	png_read_end(png_ptr, NULL);
+	png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+}
+
+bool loadByteArray(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
+	int32_t transCol = reserve ? -1 : 63519;
+	int t1, t2, n;
+	unsigned short c;
+	picWidth = realPicWidth = get2bytes(stream);
+	picHeight = realPicHeight = get2bytes(stream);
+
+	if (reserve) {
+		if (!resizeBackdrop(realPicWidth, realPicHeight)) return false;
+	}
+
+	for (t2 = 0; t2 < realPicHeight; t2 ++) {
+		t1 = 0;
+		while (t1 < realPicWidth) {
+			c = (unsigned short) get2bytes(stream);
+			if (c & 32) {
+				n = getch(stream) + 1;
+				c -= 32;
+			} else {
+				n = 1;
+			}
+			while (n --) {
+				GLubyte *target = loadhere + 4 * picWidth * t2 + t1 * 4;
+				if (c == transCol || c == 2015) {
+					target[0] = (GLubyte)0;
+					target[1] = (GLubyte)0;
+					target[2] = (GLubyte)0;
+					target[3] = (GLubyte)0;
 				} else {
-					n = 1;
-				}
-				while (--n) {
-					target = backdropTexture + 4 * picWidth * t2 + t1 * 4;
-					if (c == transCol || c == 2015) {
-						target[0] = (GLubyte) 0;
-						target[1] = (GLubyte) 0;
-						target[2] = (GLubyte) 0;
-						target[3] = (GLubyte) 0;
-					} else {
-						target[0] = (GLubyte) redValue(c);
-						target[1] = (GLubyte) greenValue(c);
-						target[2] = (GLubyte) blueValue(c);
-						target[3] = (GLubyte) 255;
-					}
-					t1++;
+					target[0] = (GLubyte)redValue(c);
+					target[1] = (GLubyte)greenValue(c);
+					target[2] = (GLubyte)blueValue(c);
+					target[3] = (GLubyte)255;
 				}
+				t1++;
 			}
 		}
 	}
+}
+
+bool loadImage(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) {
+
+	if (!loadPng(loadhere, picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
+		if (!loadByteArray(loadhere, picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
+			return false;
+		}
+	}
+
+	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
+	if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1;
+	if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false;
+
 	return true;
 }
 
@@ -1140,7 +1150,7 @@ void makeGlArray(GLuint &tmpTex, const GLubyte *texture, int picWidth, int picHe
 void renderToTexture(GLuint tmpTex, int x, int y, int picWidth, int picHeight, int realPicWidth, int realPicHeight) {
 	GLfloat texCoordW = 1.0;
 	GLfloat texCoordH = 1.0;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(picWidth);
 		picHeight = getNextPOT(picHeight);
 		texCoordW = ((double)realPicWidth) / picWidth;
@@ -1151,7 +1161,7 @@ void renderToTexture(GLuint tmpTex, int x, int y, int picWidth, int picHeight, i
 	float btx2;
 	float bty1;
 	float bty2;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		btx1 = backdropTexW * x / sceneWidth;
 		btx2 = backdropTexW * (x + realPicWidth) / sceneWidth;
 		bty1 = backdropTexH * y / sceneHeight;


Commit: 2dddb900c9b6d4356a19886cd31587a049be23d8
    https://github.com/scummvm/scummvm/commit/2dddb900c9b6d4356a19886cd31587a049be23d8
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Use PNGDecoder to read backdrop

Changed paths:
    engines/sludge/backdrop.cpp
    engines/sludge/detection.cpp
    engines/sludge/main_loop.cpp
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index 3e05997..c28a7d0 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -55,6 +55,10 @@
 #include "statusba.h"
 #include "variable.h"
 #include "CommonCode/version.h"
+#include "common/debug.h"
+#include "image/png.h"
+#include "graphics/surface.h"
+#include "sludge.h"
 
 namespace Sludge {
 
@@ -75,6 +79,8 @@ texture lightMap;
 GLuint snapshotTextureName = 0;
 #endif
 
+Graphics::Surface backdropSurface;
+
 float snapTexW = 1.0;
 float snapTexH = 1.0;
 
@@ -110,7 +116,8 @@ void saveSnapshot(Common::WriteStream *stream) {
 bool snapshot() {
 
 	nosnapshot();
-	if (!freeze()) return false;
+	if (!freeze())
+		return false;
 #if 0
 	setPixelCoords(true);
 	glGenTextures(1, &snapshotTextureName);
@@ -134,19 +141,19 @@ bool snapshot() {
 
 	// Render scene
 	glDepthMask(GL_TRUE);
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen
 	glDepthMask(GL_FALSE);
 
-	drawBackDrop();                 // Draw the room
+	drawBackDrop();// Draw the room
 	drawZBuffer(cameraX, cameraY, false);
 
 	glEnable(GL_DEPTH_TEST);
 
-	drawPeople();                   // Then add any moving characters...
+	drawPeople();// Then add any moving characters...
 
 	glDisable(GL_DEPTH_TEST);
 
-	viewSpeech();                   // ...and anything being said
+	viewSpeech();// ...and anything being said
 	drawStatusBar();
 	// Copy Our ViewPort To The Texture
 	copyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewportOffsetX, viewportOffsetY, winWidth, winHeight, snapshotTextureName);
@@ -178,7 +185,7 @@ bool restoreSnapshot(Common::SeekableReadStream *stream) {
 	if (!snapshotTexture) return fatal("Out of memory while restoring snapshot.");
 #endif
 
-	for (t2 = 0; t2 < winHeight; t2 ++) {
+	for (t2 = 0; t2 < winHeight; t2++) {
 		t1 = 0;
 		while (t1 < winWidth) {
 			c = (unsigned short) get2bytes(stream);
@@ -255,11 +262,11 @@ void killParallax() {
 bool reserveBackdrop() {
 	cameraX = 0;
 	cameraY = 0;
-	input.mouseX = (int)((float)input.mouseX * cameraZoom);
-	input.mouseY = (int)((float)input.mouseY * cameraZoom);
+	input.mouseX = (int) ((float) input.mouseX * cameraZoom);
+	input.mouseY = (int) ((float) input.mouseY * cameraZoom);
 	cameraZoom = 1.0;
-	input.mouseX = (int)((float)input.mouseX / cameraZoom);
-	input.mouseY = (int)((float)input.mouseY / cameraZoom);
+	input.mouseX = (int) ((float) input.mouseX / cameraZoom);
+	input.mouseY = (int) ((float) input.mouseY / cameraZoom);
 	setPixelCoords(false);
 	int picWidth = sceneWidth;
 	int picHeight = sceneHeight;
@@ -304,8 +311,8 @@ bool resizeBackdrop(int x, int y) {
 }
 
 void loadBackDrop(int fileNum, int x, int y) {
+	debug(kSludgeDebugGraphics, "Load back drop");
 	setResourceForFatal(fileNum);
-#if 0
 	if (!openFileFromNum(fileNum)) {
 		fatal("Can't load overlay image");
 		return;
@@ -318,7 +325,6 @@ void loadBackDrop(int fileNum, int x, int y) {
 	}
 
 	finishAccess();
-#endif
 	setResourceForFatal(-1);
 }
 
@@ -341,10 +347,14 @@ void mixBackDrop(int fileNum, int x, int y) {
 
 void blankScreen(int x1, int y1, int x2, int y2) {
 
-	if (y1 < 0) y1 = 0;
-	if (x1 < 0) x1 = 0;
-	if (x2 > (int) sceneWidth) x2 = (int)sceneWidth;
-	if (y2 > (int) sceneHeight) y2 = (int)sceneHeight;
+	if (y1 < 0)
+		y1 = 0;
+	if (x1 < 0)
+		x1 = 0;
+	if (x2 > (int) sceneWidth)
+		x2 = (int) sceneWidth;
+	if (y2 > (int) sceneHeight)
+		y2 = (int) sceneHeight;
 
 	int picWidth = x2 - x1;
 	int picHeight = y2 - y1;
@@ -361,8 +371,6 @@ void blankScreen(int x1, int y1, int x2, int y2) {
 
 			// Render the scene
 
-
-
 			const GLfloat vertices[] = {
 				-10.325f, -1.325f, 0.0f,
 				w + 1.325f, -1.325f, 0.0f,
@@ -396,7 +404,8 @@ void hardScroll(int distance) {
 		return;
 	}
 
-	if (!distance) return;
+	if (!distance)
+		return;
 #if 0
 	const GLfloat backdropTexCoords[] = {
 		0.0f, 0.0f,
@@ -415,7 +424,6 @@ void hardScroll(int distance) {
 		while (yoffset < sceneHeight) {
 			int h = (sceneHeight - yoffset < viewportHeight) ? sceneHeight - yoffset : viewportHeight;
 
-
 			glClear(GL_COLOR_BUFFER_BIT);   // Clear The Screen
 
 			// Render the backdrop
@@ -430,7 +438,6 @@ void hardScroll(int distance) {
 				(GLfloat)sceneWidth - xoffset, (GLfloat)sceneHeight - distance - yoffset, 0.
 			};
 
-
 			glUseProgram(shader.texture);
 
 			setPMVMatrix(shader.texture);
@@ -463,11 +470,13 @@ void darkScreen() {
 
 	int xoffset = 0;
 	while (xoffset < sceneWidth) {
-		int w = (sceneWidth - xoffset < viewportWidth) ? sceneWidth - xoffset : viewportWidth;
+		int w = (sceneWidth - xoffset < viewportWidth) ?
+				sceneWidth - xoffset : viewportWidth;
 
 		int yoffset = 0;
 		while (yoffset < sceneHeight) {
-			int h = (sceneHeight - yoffset < viewportHeight) ? sceneHeight - yoffset : viewportHeight;
+			int h = (sceneHeight - yoffset < viewportHeight) ?
+					sceneHeight - yoffset : viewportHeight;
 
 			// Render the scene - first the old backdrop
 #if 0
@@ -490,7 +499,6 @@ void darkScreen() {
 				backdropTexW, backdropTexH
 			};
 
-
 			glUseProgram(shader.texture);
 
 			setPMVMatrix(shader.texture);
@@ -524,20 +532,14 @@ void darkScreen() {
 		xoffset += w;
 	}
 
-
 	setPixelCoords(false);
 }
 
-
-
 inline int sortOutPCamera(int cX, int fX, int sceneMax, int boxMax) {
 	return (fX == 65535) ?
-	       (sceneMax ? ((cX * boxMax) / sceneMax) : 0)
-	       :
-	       ((cX * fX) / 100);
+			(sceneMax ? ((cX * boxMax) / sceneMax) : 0) : ((cX * fX) / 100);
 }
 
-
 void drawBackDrop() {
 #if 0
 	setPrimaryColor(1.0, 1.0, 1.0, 1.0);
@@ -632,7 +634,6 @@ bool loadLightMap(int v) {
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
 
-
 	int fileIsPNG = true;
 
 	// Is this a PNG file?
@@ -669,8 +670,8 @@ bool loadLightMap(int v) {
 			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
 			return false;
 		}
-		png_init_io(png_ptr, bigDataFile);      // Tell libpng which file to read
-		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+		png_init_io(png_ptr, bigDataFile);     // Tell libpng which file to read
+		png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 		png_read_info(png_ptr, info_ptr);
 
@@ -730,7 +731,7 @@ bool loadLightMap(int v) {
 	if (fileIsPNG) {
 		unsigned char *row_pointers[lightMap.h];
 		for (int i = 0; i < lightMap.h; i++)
-			row_pointers[i] = lightMap.data + 4 * i * newPicWidth;
+		row_pointers[i] = lightMap.data + 4 * i * newPicWidth;
 
 		png_read_image(png_ptr, (png_byte **) row_pointers);
 		png_read_end(png_ptr, NULL);
@@ -788,13 +789,13 @@ void reloadParallaxTextures() {
 		glGenTextures(1, &nP->textureName);
 		glBindTexture(GL_TEXTURE_2D, nP->textureName);
 		if (nP->wrapS)
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 		else
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 		if (nP->wrapT)
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 		else
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 		if (gameSettings.antiAlias < 0) {
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -815,7 +816,8 @@ void reloadParallaxTextures() {
 #endif
 }
 
-bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) {
+bool loadParallax(unsigned short v, unsigned short fracX,
+		unsigned short fracY) {
 
 #if 0
 	setResourceForFatal(v);
@@ -839,7 +841,6 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
 
-
 	int fileIsPNG = true;
 
 	// Is this a PNG file?
@@ -875,8 +876,8 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
 			return false;
 		}
-		png_init_io(png_ptr, bigDataFile);      // Tell libpng which file to read
-		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+		png_init_io(png_ptr, bigDataFile);     // Tell libpng which file to read
+		png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 		png_read_info(png_ptr, info_ptr);
 
@@ -936,7 +937,7 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 	if (fileIsPNG) {
 		unsigned char *row_pointers[nP->height];
 		for (int i = 0; i < nP->height; i++)
-			row_pointers[i] = nP->texture + 4 * i * picWidth;
+		row_pointers[i] = nP->texture + 4 * i * picWidth;
 
 		png_read_image(png_ptr, (png_byte **) row_pointers);
 		png_read_end(png_ptr, NULL);
@@ -979,13 +980,13 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 	glGenTextures(1, &nP->textureName);
 	glBindTexture(GL_TEXTURE_2D, nP->textureName);
 	if (nP->wrapS)
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	else
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	if (nP->wrapT)
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 	else
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 	if (gameSettings.antiAlias < 0) {
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -1005,8 +1006,16 @@ bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY)
 
 extern int viewportOffsetX, viewportOffsetY;
 
+bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
+	debug("Loading back drop png.");
+	::Image::PNGDecoder png;
+	if (!png.loadStream(*stream))
+		return false;
+	backdropSurface.copyFrom(*(png.getSurface()));
+	picWidth = realPicWidth = backdropSurface.w;
+	picHeight = realPicHeight = backdropSurface.h;
+	return true;
 #if 0
-bool loadPng(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
 	long file_pointer = stream->pos();
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
@@ -1041,7 +1050,7 @@ bool loadPng(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth
 		return false;
 	}
 	png_init_io(png_ptr, stream);		// Tell libpng which file to read
-	png_set_sig_bytes(png_ptr, 8);	// 8 bytes already read
+	png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 	png_read_info(png_ptr, info_ptr);
 
@@ -1069,14 +1078,16 @@ bool loadPng(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth
 	unsigned char *row_pointers[realPicHeight];
 
 	for (int i = 0; i < realPicHeight; i++)
-		row_pointers[i] = loadhere + 4 * i * picWidth;
+	row_pointers[i] = loadhere + 4 * i * picWidth;
 
 	png_read_image(png_ptr, (png_byte **) row_pointers);
 	png_read_end(png_ptr, NULL);
 	png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+#endif
 }
 
-bool loadByteArray(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
+bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
+#if 0
 	int32_t transCol = reserve ? -1 : 63519;
 	int t1, t2, n;
 	unsigned short c;
@@ -1114,12 +1125,13 @@ bool loadByteArray(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPi
 			}
 		}
 	}
+#endif
 }
 
-bool loadImage(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) {
-
-	if (!loadPng(loadhere, picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
-		if (!loadByteArray(loadhere, picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
+bool loadImage(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) {
+	debug(kSludgeDebugGraphics, "Loading back drop image.");
+	if (!loadPng(picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
+		if (!loadByteArray(picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
 			return false;
 		}
 	}
@@ -1131,6 +1143,7 @@ bool loadImage(GLubyte *loadhere, int &picWidth, int &picHeight, int &realPicWid
 	return true;
 }
 
+#if 0
 void makeGlArray(GLuint &tmpTex, const GLubyte *texture, int picWidth, int picHeight) {
 	glGenTextures(1, &tmpTex);
 	glBindTexture(GL_TEXTURE_2D, tmpTex);
@@ -1215,7 +1228,7 @@ void renderToTexture(GLuint tmpTex, int x, int y, int picWidth, int picHeight, i
 
 				glUseProgram(shader.paste);
 				GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
-				if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
+				if (uniform >= 0) glUniform1i(uniform, 0);// No lighting
 
 				setPMVMatrix(shader.paste);
 
@@ -1251,15 +1264,14 @@ void renderToTexture(GLuint tmpTex, int x, int y, int picWidth, int picHeight, i
 	setPixelCoords(false);
 }
 #endif
-
 bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
-#if 0
+	debug(kSludgeDebugGraphics, "Load HSI");
 	int picWidth, picHeight;
 	int realPicWidth, realPicHeight;
 
-	if (!loadImage(backdropTexture, picWidth, picHeight, realPicWidth, realPicHeight, stream, x, y, reserve))
+	if (!loadImage(picWidth, picHeight, realPicWidth, realPicHeight, stream, x, y, reserve))
 		return false;
-
+#if 0
 	GLuint tmpTex;
 	makeGlArray(tmpTex, backdropTexture, picWidth, picHeight);
 
@@ -1283,7 +1295,6 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 	png_structp png_ptr;
 	png_infop info_ptr, end_info;
 
-
 	int fileIsPNG = true;
 
 	// Is this a PNG file?
@@ -1319,7 +1330,7 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 			return false;
 		}
 		png_init_io(png_ptr, stream);       // Tell libpng which file to read
-		png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+		png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 		png_read_info(png_ptr, info_ptr);
 
@@ -1394,11 +1405,10 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 	GLubyte *target;
 	int32_t transCol = 63519;
 
-
 	if (fileIsPNG) {
 		unsigned char *row_pointers[realPicHeight];
 		for (int i = 0; i < realPicHeight; i++)
-			row_pointers[i] = backdropTexture + 4 * i * picWidth;
+		row_pointers[i] = backdropTexture + 4 * i * picWidth;
 
 		png_read_image(png_ptr, (png_byte **) row_pointers);
 		png_read_end(png_ptr, NULL);
@@ -1449,12 +1459,10 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 
 	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, backdropTexture, tmpTex);
 
-
 	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
 	setPixelCoords(true);
 
-
 	int xoffset = 0;
 	while (xoffset < realPicWidth) {
 		int w = (realPicWidth - xoffset < viewportWidth) ? realPicWidth - xoffset : viewportWidth;
@@ -1473,7 +1481,7 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) {
 
 			glUseProgram(shader.paste);
 			GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
-			if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
+			if (uniform >= 0) glUniform1i(uniform, 0);// No lighting
 
 			setPMVMatrix(shader.paste);
 
@@ -1566,7 +1574,7 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 
 			glUseProgram(0);
 
-			for (int i = 0; i < h; i++)   {
+			for (int i = 0; i < h; i++) {
 				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, image + xoffset * 4 + (yoffset + i) * 4 * tw);
 			}
 			yoffset += viewportHeight;
@@ -1592,7 +1600,7 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) {
 	png_init_io(png_ptr, writer);
 
 	png_set_IHDR(png_ptr, info_ptr, w, h,
-	             8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+			8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 
 	unsigned char *row_pointers[h];
 
@@ -1650,7 +1658,7 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) {
 			drawQuad(shader.texture, vertices, 1, texCoords);
 			glUseProgram(0);
 
-			for (int i = 0; i < h; i++)   {
+			for (int i = 0; i < h; i++) {
 				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i)*tw);
 			}
 			yoffset += viewportHeight;
@@ -1703,7 +1711,7 @@ void saveParallaxRecursive(parallaxLayer *me, Common::WriteStream *stream) {
 		saveParallaxRecursive(me->next, stream);
 		putch(1, stream);
 		put2bytes(me->fileNum, stream);
-		put2bytes(me ->fractionX, stream);
+		put2bytes(me->fractionX, stream);
 		put2bytes(me->fractionY, stream);
 	}
 }
diff --git a/engines/sludge/detection.cpp b/engines/sludge/detection.cpp
index 7e5c124..e45ada2 100644
--- a/engines/sludge/detection.cpp
+++ b/engines/sludge/detection.cpp
@@ -44,6 +44,7 @@ static const PlainGameDescriptor sludgeGames[] = {
 	{ "sludge", "Sludge Game" },
 	{ "welcome", "Welcome Example" },
 	{ "welcome2", "Welcome Example 2" },
+	{ "welcomePng", "Welcome For PNG Test" },
 	{ "verbcoin", "Verb Coin" },
 	{ 0, 0 }
 };
@@ -78,6 +79,19 @@ static const SludgeGameDescription gameDescriptions[] = {
 
 	{
 		{
+			"welcomePng",
+			"",
+			AD_ENTRY1("Welcome.slg", "ff0d7ef0ce73b5503ef6b965928af6d6"),
+			Common::EN_ANY,
+			Common::kPlatformUnknown,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		0
+	},
+
+	{
+		{
 			"verbcoin",
 			"",
 			AD_ENTRY1("Welcome.slg", "e39ec315dcbf3a1137481f0a5fe1617d"),
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index b278a35..283a228 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -74,6 +74,7 @@
 #include "sludger.h"
 #include "graphics.h"
 #include "helpers.h"
+#include "graphics/surface.h"
 
 namespace Sludge {
 
@@ -97,6 +98,7 @@ extern float cameraZoom;
 extern int specialSettings;
 extern inputType input;
 extern variableStack *noStack;
+extern Graphics::Surface backdropSurface;
 
 int dialogValue = 0;
 
@@ -471,6 +473,8 @@ try
 		walkAllPeople();
 		handleInput();
 		sludgeDisplay();
+		g_system->copyRectToScreen(backdropSurface.getPixels(), backdropSurface.pitch, 0, 0, backdropSurface.w, backdropSurface.h);
+		g_system->updateScreen();
 #if 0
 		Wait_Frame();
 #endif
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index d0d6b37..ea9dc57 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -44,6 +44,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 	DebugMan.addDebugChannel(kSludgeDebugDataLoad, "Data Load", "Data loading debug level");
 	DebugMan.addDebugChannel(kSludgeDebugStackMachine, "Stack Machine", "Stack Machine debug level");
 	DebugMan.addDebugChannel(kSludgeDebugBuiltin, "Built-in", "Built-in debug level");
+	DebugMan.addDebugChannel(kSludgeDebugGraphics, "Graphics", "Graphics debug level");
 
 	// check init
 	debug("SludgeEngine::SludgeEngine");
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 4570b04..734a856 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -41,6 +41,7 @@ enum {
 	kSludgeDebugDataLoad = 1 << 1,
 	kSludgeDebugStackMachine = 1 << 2,
 	kSludgeDebugBuiltin = 1 << 3,
+	kSludgeDebugGraphics = 1 << 4
 };
  
 class SludgeEngine : public Engine {


Commit: ca2ee02496f232a53ed6c96bd296e0941da636f6
    https://github.com/scummvm/scummvm/commit/ca2ee02496f232a53ed6c96bd296e0941da636f6
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: code formatting

Changed paths:
    engines/sludge/CommonCode/functionlist.h
    engines/sludge/backdrop.cpp
    engines/sludge/backdrop.h
    engines/sludge/builtin.cpp
    engines/sludge/builtin.h
    engines/sludge/colours.h
    engines/sludge/console.cpp
    engines/sludge/console.h
    engines/sludge/csludge.h
    engines/sludge/cursors.cpp
    engines/sludge/fileset.cpp
    engines/sludge/floor.cpp
    engines/sludge/floor.h
    engines/sludge/fonttext.cpp
    engines/sludge/freeze.cpp
    engines/sludge/freeze.h
    engines/sludge/graphics.cpp
    engines/sludge/graphics.h
    engines/sludge/language.cpp
    engines/sludge/line.cpp
    engines/sludge/loadsave.cpp
    engines/sludge/main_loop.cpp
    engines/sludge/memwatch.cpp
    engines/sludge/moreio.cpp
    engines/sludge/movie.cpp
    engines/sludge/movie.h
    engines/sludge/newfatal.cpp
    engines/sludge/objtypes.cpp
    engines/sludge/people.cpp
    engines/sludge/people.h
    engines/sludge/region.cpp
    engines/sludge/savedata.cpp
    engines/sludge/sludge.h
    engines/sludge/sludger.cpp
    engines/sludge/sludger.h
    engines/sludge/sound_bass.cpp
    engines/sludge/sound_openal.cpp
    engines/sludge/sprbanks.cpp
    engines/sludge/sprites.cpp
    engines/sludge/sprites.h
    engines/sludge/stringy.cpp
    engines/sludge/talk.cpp
    engines/sludge/talk.h
    engines/sludge/thumbnail.cpp
    engines/sludge/timing.cpp
    engines/sludge/transition.cpp
    engines/sludge/variable.cpp
    engines/sludge/variable.h
    engines/sludge/vid.cpp
    engines/sludge/winstuff.cpp
    engines/sludge/zbuffer.cpp
    engines/sludge/zbuffer.h


diff --git a/engines/sludge/CommonCode/functionlist.h b/engines/sludge/CommonCode/functionlist.h
index 3d98553..637ed5c 100644
--- a/engines/sludge/CommonCode/functionlist.h
+++ b/engines/sludge/CommonCode/functionlist.h
@@ -1,10 +1,10 @@
 /*
-This is the list of the built in functions
+ This is the list of the built in functions
 
-true or false states if it's a used function
-in the current version of the engine,
-but that value currently isn't used anywhere
-*/
+ true or false states if it's a used function
+ in the current version of the engine,
+ but that value currently isn't used anywhere
+ */
 
 FUNC(true, say)
 FUNC(true, skipSpeech)
@@ -135,10 +135,10 @@ FUNC(true, captureAllKeys)
 FUNC(true, cacheSound)
 FUNC(true, setCharacterSpinSpeed)
 FUNC(true, transitionMode)
-FUNC(false,  _rem_movieStart)
-FUNC(false,  _rem_movieAbort)
-FUNC(false,  _rem_moviePlaying)
-FUNC(false,  _rem_updateDisplay)
+FUNC(false, _rem_movieStart)
+FUNC(false, _rem_movieAbort)
+FUNC(false, _rem_moviePlaying)
+FUNC(false, _rem_updateDisplay)
 FUNC(true, getSoundCache)
 FUNC(true, saveCustomData)
 FUNC(true, loadCustomData)
@@ -160,7 +160,7 @@ FUNC(true, hasFlag)
 FUNC(true, snapshotGrab)
 FUNC(true, snapshotClear)
 FUNC(true, bodgeFilenames)
-FUNC(false,  _rem_registryGetString)
+FUNC(false, _rem_registryGetString)
 FUNC(true, quitWithFatalError)
 FUNC(true, _rem_setCharacterAA)
 FUNC(true, _rem_setMaximumAA)
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index c28a7d0..7fecf57 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -155,7 +155,7 @@ bool snapshot() {
 
 	viewSpeech();// ...and anything being said
 	drawStatusBar();
-	// Copy Our ViewPort To The Texture
+				 // Copy Our ViewPort To The Texture
 	copyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewportOffsetX, viewportOffsetY, winWidth, winHeight, snapshotTextureName);
 
 	setPixelCoords(false);
@@ -320,7 +320,9 @@ void loadBackDrop(int fileNum, int x, int y) {
 
 	if (!loadHSI(bigDataFile, x, y, false)) {
 		char mess[200];
-		sprintf(mess, "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight);
+		sprintf(mess,
+				"Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i",
+				x, y, sceneWidth, sceneHeight);
 		fatal(mess);
 	}
 
@@ -1006,11 +1008,14 @@ bool loadParallax(unsigned short v, unsigned short fracX,
 
 extern int viewportOffsetX, viewportOffsetY;
 
-bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
-	debug("Loading back drop png.");
+bool loadPng(int &picWidth, int &picHeight, int &realPicWidth,
+		int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
+	debug(kSludgeDebugGraphics, "Loading back drop png.");
 	::Image::PNGDecoder png;
-	if (!png.loadStream(*stream))
+	if (!png.loadStream(*stream)) {
+		debug(kSludgeDebugGraphics, "Back drop is not a png");
 		return false;
+	}
 	backdropSurface.copyFrom(*(png.getSurface()));
 	picWidth = realPicWidth = backdropSurface.w;
 	picHeight = realPicHeight = backdropSurface.h;
@@ -1049,7 +1054,7 @@ bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeigh
 		png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
 		return false;
 	}
-	png_init_io(png_ptr, stream);		// Tell libpng which file to read
+	png_init_io(png_ptr, stream);       // Tell libpng which file to read
 	png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 	png_read_info(png_ptr, info_ptr);
@@ -1086,7 +1091,8 @@ bool loadPng(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeigh
 #endif
 }
 
-bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
+bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth,
+		int &realPicHeight, Common::SeekableReadStream *stream, bool reserve) {
 #if 0
 	int32_t transCol = reserve ? -1 : 63519;
 	int t1, t2, n;
@@ -1128,17 +1134,25 @@ bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth, int &realPi
 #endif
 }
 
-bool loadImage(int &picWidth, int &picHeight, int &realPicWidth, int &realPicHeight, Common::SeekableReadStream *stream, int x, int y, bool reserve) {
+bool loadImage(int &picWidth, int &picHeight, int &realPicWidth,
+		int &realPicHeight, Common::SeekableReadStream *stream, int x, int y,
+		bool reserve) {
 	debug(kSludgeDebugGraphics, "Loading back drop image.");
-	if (!loadPng(picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
-		if (!loadByteArray(picWidth, picHeight, realPicWidth, realPicHeight, stream, reserve)) {
+	if (!loadPng(picWidth, picHeight, realPicWidth, realPicHeight, stream,
+			reserve)) {
+		if (!loadByteArray(picWidth, picHeight, realPicWidth, realPicHeight,
+				stream, reserve)) {
 			return false;
 		}
 	}
 
-	if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1;
-	if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1;
-	if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false;
+	if (x == IN_THE_CENTRE)
+		x = (sceneWidth - realPicWidth) >> 1;
+	if (y == IN_THE_CENTRE)
+		y = (sceneHeight - realPicHeight) >> 1;
+	if (x < 0 || x + realPicWidth > sceneWidth || y < 0
+			|| y + realPicHeight > sceneHeight)
+		return false;
 
 	return true;
 }
@@ -1269,7 +1283,8 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) {
 	int picWidth, picHeight;
 	int realPicWidth, realPicHeight;
 
-	if (!loadImage(picWidth, picHeight, realPicWidth, realPicHeight, stream, x, y, reserve))
+	if (!loadImage(picWidth, picHeight, realPicWidth, realPicHeight, stream, x,
+			y, reserve))
 		return false;
 #if 0
 	GLuint tmpTex;
diff --git a/engines/sludge/backdrop.h b/engines/sludge/backdrop.h
index 8974f92..8346a46 100644
--- a/engines/sludge/backdrop.h
+++ b/engines/sludge/backdrop.h
@@ -37,7 +37,7 @@
 namespace Sludge {
 
 enum {
-	LIGHTMAPMODE_NONE       = -1,
+	LIGHTMAPMODE_NONE = -1,
 	LIGHTMAPMODE_HOTSPOT,
 	LIGHTMAPMODE_PIXEL,
 	LIGHTMAPMODE_NUM
@@ -46,7 +46,6 @@ enum {
 extern unsigned int winWidth, winHeight, sceneWidth, sceneHeight;
 extern int lightMapMode;
 
-
 struct parallaxLayer {
 #if 0
 	GLubyte *texture;
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 5d5c0fa..f35a2bd 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -2529,7 +2529,7 @@ builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun) {
 				char buff[100];
 				sprintf(buff, "Built in function must have %i parameter%s",
 				        paramNum[whichFunc],
-				        (paramNum[whichFunc] == 1) ? "" : "s");
+						(paramNum[whichFunc] == 1) ? "" : "s");
 
 				fatal(copyString(buff));
 				return BR_ERROR;
diff --git a/engines/sludge/builtin.h b/engines/sludge/builtin.h
index 00d780e..0fb15d1 100644
--- a/engines/sludge/builtin.h
+++ b/engines/sludge/builtin.h
@@ -25,7 +25,14 @@
 
 namespace Sludge {
 
-enum builtReturn {BR_KEEP_AND_PAUSE, BR_ERROR, BR_CONTINUE, BR_PAUSE, BR_CALLAFUNC, BR_ALREADY_GONE};
+enum builtReturn {
+	BR_KEEP_AND_PAUSE,
+	BR_ERROR,
+	BR_CONTINUE,
+	BR_PAUSE,
+	BR_CALLAFUNC,
+	BR_ALREADY_GONE
+};
 
 bool failSecurityCheck(char *fn);
 builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun);
diff --git a/engines/sludge/colours.h b/engines/sludge/colours.h
index 2caf963..a613f67 100644
--- a/engines/sludge/colours.h
+++ b/engines/sludge/colours.h
@@ -42,7 +42,8 @@ inline unsigned short makeGrey(unsigned short int r) {
 	return ((r >> 3) << 11) | ((r >> 2) << 5) | (r >> 3);
 }
 
-inline unsigned short makeColour(unsigned short int r, unsigned short int g, unsigned short int b) {
+inline unsigned short makeColour(unsigned short int r, unsigned short int g,
+		unsigned short int b) {
 	return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
 }
 
diff --git a/engines/sludge/console.cpp b/engines/sludge/console.cpp
index 95d70b9..d47f04c 100644
--- a/engines/sludge/console.cpp
+++ b/engines/sludge/console.cpp
@@ -24,7 +24,8 @@
 
 namespace Sludge {
 
-SludgeConsole::SludgeConsole(SludgeEngine *vm) : GUI::Debugger() {
+SludgeConsole::SludgeConsole(SludgeEngine *vm) :
+		GUI::Debugger() {
 	_vm = vm;
 }
 
diff --git a/engines/sludge/console.h b/engines/sludge/console.h
index 5f96409..a720073 100644
--- a/engines/sludge/console.h
+++ b/engines/sludge/console.h
@@ -30,11 +30,11 @@ namespace Sludge {
 class SludgeEngine;
 
 // Example console class
-class SludgeConsole : public GUI::Debugger {
+class SludgeConsole: public GUI::Debugger {
 public:
 	SludgeConsole(SludgeEngine *vm);
 	virtual ~SludgeConsole(void);
-	
+
 private:
 	SludgeEngine *_vm;
 };
diff --git a/engines/sludge/csludge.h b/engines/sludge/csludge.h
index 22b6125..0564853 100644
--- a/engines/sludge/csludge.h
+++ b/engines/sludge/csludge.h
@@ -25,22 +25,51 @@
 
 namespace Sludge {
 
-enum sludgeCommand {SLU_UNKNOWN,
-                    SLU_RETURN, SLU_BRANCH, SLU_BR_ZERO, SLU_SET_GLOBAL,
-                    SLU_SET_LOCAL, SLU_LOAD_GLOBAL, SLU_LOAD_LOCAL,
-                    SLU_PLUS, SLU_MINUS, SLU_MULT, SLU_DIVIDE,
-                    SLU_AND, SLU_OR, SLU_EQUALS, SLU_NOT_EQ, SLU_MODULUS,
-                    SLU_LOAD_VALUE, SLU_LOAD_BUILT, SLU_LOAD_FUNC, SLU_CALLIT,
-                    SLU_LOAD_STRING, SLU_LOAD_FILE, /*SLU_LOAD_SCENE,*/ SLU_LOAD_OBJTYPE,
-                    SLU_NOT, SLU_LOAD_NULL, SLU_STACK_PUSH, SLU_LESSTHAN, SLU_MORETHAN, SLU_NEGATIVE,
-                    SLU_UNREG, SLU_LESS_EQUAL, SLU_MORE_EQUAL,
-                    SLU_INCREMENT_LOCAL,
-                    SLU_DECREMENT_LOCAL,
-                    SLU_INCREMENT_GLOBAL,
-                    SLU_DECREMENT_GLOBAL, SLU_INDEXSET, SLU_INDEXGET,
-                    SLU_INCREMENT_INDEX, SLU_DECREMENT_INDEX, SLU_QUICK_PUSH,
-                    numSludgeCommands
-                   };
+enum sludgeCommand {
+	SLU_UNKNOWN,
+	SLU_RETURN,
+	SLU_BRANCH,
+	SLU_BR_ZERO,
+	SLU_SET_GLOBAL,
+	SLU_SET_LOCAL,
+	SLU_LOAD_GLOBAL,
+	SLU_LOAD_LOCAL,
+	SLU_PLUS,
+	SLU_MINUS,
+	SLU_MULT,
+	SLU_DIVIDE,
+	SLU_AND,
+	SLU_OR,
+	SLU_EQUALS,
+	SLU_NOT_EQ,
+	SLU_MODULUS,
+	SLU_LOAD_VALUE,
+	SLU_LOAD_BUILT,
+	SLU_LOAD_FUNC,
+	SLU_CALLIT,
+	SLU_LOAD_STRING,
+	SLU_LOAD_FILE, /*SLU_LOAD_SCENE,*/
+	SLU_LOAD_OBJTYPE,
+	SLU_NOT,
+	SLU_LOAD_NULL,
+	SLU_STACK_PUSH,
+	SLU_LESSTHAN,
+	SLU_MORETHAN,
+	SLU_NEGATIVE,
+	SLU_UNREG,
+	SLU_LESS_EQUAL,
+	SLU_MORE_EQUAL,
+	SLU_INCREMENT_LOCAL,
+	SLU_DECREMENT_LOCAL,
+	SLU_INCREMENT_GLOBAL,
+	SLU_DECREMENT_GLOBAL,
+	SLU_INDEXSET,
+	SLU_INDEXGET,
+	SLU_INCREMENT_INDEX,
+	SLU_DECREMENT_INDEX,
+	SLU_QUICK_PUSH,
+	numSludgeCommands
+};
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
index 91d0112..562f386 100644
--- a/engines/sludge/cursors.cpp
+++ b/engines/sludge/cursors.cpp
@@ -68,8 +68,8 @@ void displayCursor() {
 
 		if (flipMe != 2) {
 			(flipMe ? flipFontSprite : fontSprite)(input.mouseX, input.mouseY,
-			                                       mouseCursorAnim -> theSprites -> bank.sprites[spriteNum],
-			                                       mouseCursorAnim -> theSprites -> bank.myPalette /* ( spritePalette&) NULL*/);
+					mouseCursorAnim -> theSprites -> bank.sprites[spriteNum],
+					mouseCursorAnim -> theSprites -> bank.myPalette /* ( spritePalette&) NULL*/);
 		}
 
 		if (++ mouseCursorCountUp >= mouseCursorAnim -> frames[mouseCursorFrameNum].howMany) {
@@ -82,9 +82,10 @@ void displayCursor() {
 }
 
 void pasteCursor(int x, int y, personaAnimation *c) {
-	if (c -> numFrames) pasteSpriteToBackDrop(x, y,
-		        c -> theSprites -> bank.sprites[c -> frames[0].frameNum],
-		        c -> theSprites -> bank.myPalette);
+	if (c->numFrames)
+		pasteSpriteToBackDrop(x, y,
+				c->theSprites->bank.sprites[c->frames[0].frameNum],
+				c->theSprites->bank.myPalette);
 }
 
 } // End of namespace Sludge
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index 3c653f4..eb39166 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -42,8 +42,8 @@ bool sliceBusy = true;
 
 Common::File *bigDataFile = NULL;
 
-uint32_t startOfDataIndex, startOfTextIndex,
-         startOfSubIndex, startOfObjectIndex;
+uint32_t startOfDataIndex, startOfTextIndex, startOfSubIndex,
+		startOfObjectIndex;
 
 bool openSubSlice(int num) {
 //	FILE * dbug = fopen ("debuggy.txt", "at");
@@ -100,7 +100,6 @@ unsigned int openFileFromNum(int num) {
 	return get4bytes(bigDataFile);
 }
 
-
 // Converts a string from Windows CP-1252 to UTF-8.
 // This is needed for old games.
 char *convertString(char *s) {
@@ -124,10 +123,10 @@ char *convertString(char *s) {
 
 	if (convert == (iconv_t) - 1) {
 		switch (errno) {
-		case EINVAL:
+			case EINVAL:
 			fprintf(stderr, "Error: Encoding not supported by iconv.\n");
 			break;
-		default:
+			default:
 			fprintf(stderr, "Error: Could not open iconv conversion descriptor.\n");
 		}
 	}
@@ -136,35 +135,34 @@ char *convertString(char *s) {
 	size_t len2 = 65535;
 	size_t iconv_value =
 #ifdef _WIN32
-	    iconv(convert, (const char **) tmp1, &len1, tmp2, &len2);
+	iconv(convert, (const char **) tmp1, &len1, tmp2, &len2);
 #else
-	    iconv(convert, (char **) tmp1, &len1, tmp2, &len2);
+	iconv(convert, (char **) tmp1, &len1, tmp2, &len2);
 #endif
 
 	if (iconv_value == (size_t) - 1) {
 		switch (errno) {
-		/* See "man 3 iconv" for an explanation. */
-		case EILSEQ:
+			/* See "man 3 iconv" for an explanation. */
+			case EILSEQ:
 			fprintf(stderr, "Invalid multibyte sequence.\n");
 			break;
-		case EINVAL:
+			case EINVAL:
 			fprintf(stderr, "Incomplete multibyte sequence.\n");
 			break;
-		case E2BIG:
+			case E2BIG:
 			fprintf(stderr, "No more room.\n");
 			break;
-		default:
+			default:
 			fprintf(stderr, "Error: %s.\n", strerror(errno));
 		}
 		fatal("Conversion to Unicode failed. This can be fixed by recompiling the game in a current version of the SLUDGE Development Kit, but this error should never happen. Congratulations, you've found a bug in the SLUDGE engine! Please let us know about it.");
 	}
 	iconv_close(convert);
 
-
 	delete [] sOrig;
 	return copyString(buf = bufOrig);
 #endif
-	return s;//TODO: false value
+	return s; //TODO: false value
 }
 
 char *getNumberedString(int value) {
@@ -199,7 +197,8 @@ void finishAccess() {
 
 int32_t startIndex;
 
-void setFileIndices(Common::File *fp, int numLanguages, unsigned int skipBefore) {
+void setFileIndices(Common::File *fp, int numLanguages,
+		unsigned int skipBefore) {
 	if (fp) {
 		// Keep hold of the file handle, and let things get at it
 		bigDataFile = fp;
@@ -220,7 +219,7 @@ void setFileIndices(Common::File *fp, int numLanguages, unsigned int skipBefore)
 	int skipAfter = numLanguages - skipBefore;
 	while (skipBefore) {
 		fp->seek(get4bytes(fp), SEEK_SET);
-		skipBefore --;
+		skipBefore--;
 	}
 	startOfTextIndex = fp->pos() + 4;
 
@@ -228,7 +227,7 @@ void setFileIndices(Common::File *fp, int numLanguages, unsigned int skipBefore)
 
 	while (skipAfter) {
 		fp->seek(get4bytes(fp), SEEK_SET);
-		skipAfter --;
+		skipAfter--;
 	}
 
 	startOfSubIndex = fp->pos() + 4;
diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp
index 7ca30b6..ec57387 100644
--- a/engines/sludge/floor.cpp
+++ b/engines/sludge/floor.cpp
@@ -35,17 +35,15 @@ bool pointInFloorPolygon(floorPolygon &floorPoly, int x, int y) {
 	float xp_i, yp_i;
 	float xp_j, yp_j;
 
-	for (j = floorPoly.numVertices - 1; i < floorPoly.numVertices;
-	        j = i ++) {
+	for (j = floorPoly.numVertices - 1; i < floorPoly.numVertices; j = i++) {
 
-		xp_i = currentFloor -> vertex[floorPoly.vertexID[i]].x;
-		yp_i = currentFloor -> vertex[floorPoly.vertexID[i]].y;
-		xp_j = currentFloor -> vertex[floorPoly.vertexID[j]].x;
-		yp_j = currentFloor -> vertex[floorPoly.vertexID[j]].y;
+		xp_i = currentFloor->vertex[floorPoly.vertexID[i]].x;
+		yp_i = currentFloor->vertex[floorPoly.vertexID[i]].y;
+		xp_j = currentFloor->vertex[floorPoly.vertexID[j]].x;
+		yp_j = currentFloor->vertex[floorPoly.vertexID[j]].y;
 
-		if ((((yp_i <= y) && (y < yp_j)) ||
-		        ((yp_j <= y) && (y < yp_i))) &&
-		        (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) {
+		if ((((yp_i <= y) && (y < yp_j)) || ((yp_j <= y) && (y < yp_i)))
+				&& (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) {
 
 			c = !c;
 		}
@@ -53,14 +51,15 @@ bool pointInFloorPolygon(floorPolygon &floorPoly, int x, int y) {
 	return c;
 }
 
-bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA, int &cornerB) {
+bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA,
+		int &cornerB) {
 	int sharedVertices = 0;
 	int i, j;
 
-	for (i = 0; i < a.numVertices; i ++) {
-		for (j = 0; j < b.numVertices; j ++) {
+	for (i = 0; i < a.numVertices; i++) {
+		for (j = 0; j < b.numVertices; j++) {
 			if (a.vertexID[i] == b.vertexID[j]) {
-				if (sharedVertices ++) {
+				if (sharedVertices++) {
 					cornerB = a.vertexID[i];
 					return true;
 				} else {
@@ -77,10 +76,11 @@ bool polysShareSide(floorPolygon &a, floorPolygon &b) {
 	int sharedVertices = 0;
 	int i, j;
 
-	for (i = 0; i < a.numVertices; i ++) {
-		for (j = 0; j < b.numVertices; j ++) {
+	for (i = 0; i < a.numVertices; i++) {
+		for (j = 0; j < b.numVertices; j++) {
 			if (a.vertexID[i] == b.vertexID[j]) {
-				if (sharedVertices ++) return true;
+				if (sharedVertices++)
+					return true;
 			}
 		}
 	}
@@ -89,30 +89,31 @@ bool polysShareSide(floorPolygon &a, floorPolygon &b) {
 }
 
 void noFloor() {
-	currentFloor -> numPolygons = 0;
-	currentFloor -> polygon = NULL;
-	currentFloor -> vertex = NULL;
-	currentFloor -> matrix = NULL;
+	currentFloor->numPolygons = 0;
+	currentFloor->polygon = NULL;
+	currentFloor->vertex = NULL;
+	currentFloor->matrix = NULL;
 }
 
 bool initFloor() {
 	currentFloor = new flor;
-	if (! checkNew(currentFloor)) return false;
+	if (!checkNew(currentFloor))
+		return false;
 	noFloor();
 	return true;
 }
 
 void killFloor() {
-	for (int i = 0; i < currentFloor -> numPolygons; i ++) {
-		delete currentFloor -> polygon[i].vertexID;
-		delete currentFloor -> matrix[i];
+	for (int i = 0; i < currentFloor->numPolygons; i++) {
+		delete currentFloor->polygon[i].vertexID;
+		delete currentFloor->matrix[i];
 	}
-	delete currentFloor -> polygon;
-	currentFloor -> polygon = NULL;
-	delete currentFloor -> vertex;
-	currentFloor -> vertex = NULL;
-	delete currentFloor -> matrix;
-	currentFloor -> matrix = NULL;
+	delete currentFloor->polygon;
+	currentFloor->polygon = NULL;
+	delete currentFloor->vertex;
+	currentFloor->vertex = NULL;
+	delete currentFloor->matrix;
+	currentFloor->matrix = NULL;
 }
 
 void setFloorNull() {
@@ -128,73 +129,81 @@ bool setFloor(int fileNum) {
 
 	setResourceForFatal(fileNum);
 
-	if (! openFileFromNum(fileNum)) return false;
+	if (!openFileFromNum(fileNum))
+		return false;
 
 	// Find out how many polygons there are and reserve memory
 
-	currentFloor -> originalNum = fileNum;
-	currentFloor -> numPolygons = getch(bigDataFile);
-	currentFloor -> polygon = new floorPolygon[currentFloor -> numPolygons];
-	if (! checkNew(currentFloor -> polygon)) return false;
+	currentFloor->originalNum = fileNum;
+	currentFloor->numPolygons = getch(bigDataFile);
+	currentFloor->polygon = new floorPolygon[currentFloor->numPolygons];
+	if (!checkNew(currentFloor->polygon))
+		return false;
 
 	// Read in each polygon
 
-	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+	for (i = 0; i < currentFloor->numPolygons; i++) {
 
 		// Find out how many vertex IDs there are and reserve memory
 
-		currentFloor -> polygon[i].numVertices = getch(bigDataFile);
-		currentFloor -> polygon[i].vertexID = new int[currentFloor -> polygon[i].numVertices];
-		if (! checkNew(currentFloor -> polygon[i].vertexID)) return false;
+		currentFloor->polygon[i].numVertices = getch(bigDataFile);
+		currentFloor->polygon[i].vertexID =
+				new int[currentFloor->polygon[i].numVertices];
+		if (!checkNew(currentFloor->polygon[i].vertexID))
+			return false;
 
 		// Read in each vertex ID
 
-		for (j = 0; j < currentFloor -> polygon[i].numVertices; j ++) {
-			currentFloor -> polygon[i].vertexID[j] = get2bytes(bigDataFile);
+		for (j = 0; j < currentFloor->polygon[i].numVertices; j++) {
+			currentFloor->polygon[i].vertexID[j] = get2bytes(bigDataFile);
 		}
 	}
 
 	// Find out how many vertices there are and reserve memory
 
 	i = get2bytes(bigDataFile);
-	currentFloor -> vertex = new POINT[i];
-	if (! checkNew(currentFloor -> vertex)) return false;
+	currentFloor->vertex = new POINT[i];
+	if (!checkNew(currentFloor->vertex))
+		return false;
 
-	for (j = 0; j < i; j ++) {
+	for (j = 0; j < i; j++) {
 
-		currentFloor -> vertex[j].x = get2bytes(bigDataFile);
-		currentFloor -> vertex[j].y = get2bytes(bigDataFile);
+		currentFloor->vertex[j].x = get2bytes(bigDataFile);
+		currentFloor->vertex[j].y = get2bytes(bigDataFile);
 	}
 
 	finishAccess();
 
 	// Now build the movement martix
 
-	currentFloor -> matrix = new int *[currentFloor -> numPolygons];
-	int * * distanceMatrix = new int *[currentFloor -> numPolygons];
+	currentFloor->matrix = new int *[currentFloor->numPolygons];
+	int * * distanceMatrix = new int *[currentFloor->numPolygons];
 
-	if (! checkNew(currentFloor -> matrix)) return false;
+	if (!checkNew(currentFloor->matrix))
+		return false;
 
-	for (i = 0; i < currentFloor -> numPolygons; i ++) {
-		currentFloor -> matrix[i] = new int [currentFloor -> numPolygons];
-		distanceMatrix        [i] = new int [currentFloor -> numPolygons];
-		if (! checkNew(currentFloor -> matrix[i])) return false;
-		for (j = 0; j < currentFloor -> numPolygons; j ++) {
-			currentFloor -> matrix[i][j] = -1;
-			distanceMatrix        [i][j] = 10000;
+	for (i = 0; i < currentFloor->numPolygons; i++) {
+		currentFloor->matrix[i] = new int[currentFloor->numPolygons];
+		distanceMatrix[i] = new int[currentFloor->numPolygons];
+		if (!checkNew(currentFloor->matrix[i]))
+			return false;
+		for (j = 0; j < currentFloor->numPolygons; j++) {
+			currentFloor->matrix[i][j] = -1;
+			distanceMatrix[i][j] = 10000;
 		}
 	}
 
-	for (i = 0; i < currentFloor -> numPolygons; i ++) {
-		for (j = 0; j < currentFloor -> numPolygons; j ++) {
+	for (i = 0; i < currentFloor->numPolygons; i++) {
+		for (j = 0; j < currentFloor->numPolygons; j++) {
 			if (i != j) {
-				if (polysShareSide(currentFloor -> polygon[i], currentFloor -> polygon[j])) {
-					currentFloor -> matrix[i][j] = j;
-					distanceMatrix        [i][j] = 1;
+				if (polysShareSide(currentFloor->polygon[i],
+						currentFloor->polygon[j])) {
+					currentFloor->matrix[i][j] = j;
+					distanceMatrix[i][j] = 1;
 				}
 			} else {
-				currentFloor -> matrix[i][j] = -2;
-				distanceMatrix        [i][j] = 0;
+				currentFloor->matrix[i][j] = -2;
+				distanceMatrix[i][j] = 0;
 			}
 		}
 	}
@@ -203,22 +212,23 @@ bool setFloor(int fileNum) {
 	int lookForDistance = 0;
 
 	do {
-		lookForDistance ++;
+		lookForDistance++;
 //		debugMatrix ();
 		madeChange = false;
-		for (i = 0; i < currentFloor -> numPolygons; i ++) {
-			for (j = 0; j < currentFloor -> numPolygons; j ++) {
-				if (currentFloor -> matrix[i][j] == -1) {
+		for (i = 0; i < currentFloor->numPolygons; i++) {
+			for (j = 0; j < currentFloor->numPolygons; j++) {
+				if (currentFloor->matrix[i][j] == -1) {
 
 					// OK, so we don't know how to get from i to j...
-					for (int d = 0; d < currentFloor -> numPolygons; d ++) {
+					for (int d = 0; d < currentFloor->numPolygons; d++) {
 						if (d != i && d != j) {
-							if (currentFloor -> matrix[i][d] == d &&
-							        currentFloor -> matrix[d][j] >= 0 &&
-							        distanceMatrix        [d][j] <= lookForDistance) {
+							if (currentFloor->matrix[i][d] == d
+									&& currentFloor->matrix[d][j] >= 0
+									&& distanceMatrix[d][j]
+											<= lookForDistance) {
 
-								currentFloor -> matrix[i][j] = d;
-								distanceMatrix       [i][j] = lookForDistance + 1;
+								currentFloor->matrix[i][j] = d;
+								distanceMatrix[i][j] = lookForDistance + 1;
 								madeChange = true;
 							}
 						}
@@ -228,8 +238,8 @@ bool setFloor(int fileNum) {
 		}
 	} while (madeChange);
 
-	for (i = 0; i < currentFloor -> numPolygons; i ++) {
-		delete distanceMatrix [i];
+	for (i = 0; i < currentFloor->numPolygons; i++) {
+		delete distanceMatrix[i];
 	}
 
 	delete distanceMatrix;
@@ -242,20 +252,26 @@ bool setFloor(int fileNum) {
 
 void drawFloor() {
 	int i, j, nV;
-	for (i = 0; i < currentFloor -> numPolygons; i ++) {
+	for (i = 0; i < currentFloor->numPolygons; i++) {
 //		drawLine (i, 0, i + 5, 100);
-		nV = currentFloor -> polygon[i].numVertices;
+		nV = currentFloor->polygon[i].numVertices;
 		if (nV > 1) {
-			for (j = 1; j < nV; j ++) {
-				drawLine(currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j - 1]].x,
-				         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j - 1]].y,
-				         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j]].x,
-				         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[j]].y);
+			for (j = 1; j < nV; j++) {
+				drawLine(
+						currentFloor->vertex[currentFloor->polygon[i].vertexID[j
+								- 1]].x,
+						currentFloor->vertex[currentFloor->polygon[i].vertexID[j
+								- 1]].y,
+						currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x,
+						currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y);
 			}
-			drawLine(currentFloor -> vertex[currentFloor -> polygon[i].vertexID[0]].x,
-			         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[0]].y,
-			         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[nV - 1]].x,
-			         currentFloor -> vertex[currentFloor -> polygon[i].vertexID[nV - 1]].y);
+			drawLine(
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].x,
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].y,
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[nV
+							- 1]].x,
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[nV
+							- 1]].y);
 		}
 	}
 }
@@ -263,14 +279,15 @@ void drawFloor() {
 int inFloor(int x, int y) {
 	int i, r = -1;
 
-	for (i = 0; i < currentFloor -> numPolygons; i ++)
-		if (pointInFloorPolygon(currentFloor -> polygon[i], x, y))
+	for (i = 0; i < currentFloor->numPolygons; i++)
+		if (pointInFloorPolygon(currentFloor->polygon[i], x, y))
 			r = i;
 
 	return r;
 }
 
-bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP) {
+bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2,
+		int y2, int xP, int yP) {
 	int xDiff = x2 - x1;
 	int yDiff = y2 - y1;
 
diff --git a/engines/sludge/floor.h b/engines/sludge/floor.h
index 193b6d1..50fe56e 100644
--- a/engines/sludge/floor.h
+++ b/engines/sludge/floor.h
@@ -54,7 +54,8 @@ bool setFloor(int fileNum);
 void drawFloor();
 int inFloor(int x, int y);
 bool getMatchingCorners(floorPolygon &, floorPolygon &, int &, int &);
-bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP);
+bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2,
+		int y2, int xP, int yP);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
index 6ac9209..7339d8f 100644
--- a/engines/sludge/fonttext.cpp
+++ b/engines/sludge/fonttext.cpp
@@ -51,11 +51,14 @@ unsigned int fontTableSize = 0;
 extern float cameraZoom;
 
 bool isInFont(char *theText) {
-	if (! fontTableSize) return 0;
-	if (! theText[0]) return 0;
+	if (!fontTableSize)
+		return 0;
+	if (!theText[0])
+		return 0;
 
 	// We don't want to compare strings. Only single characters allowed!
-	if (u8_strlen(theText) > 1) return false;
+	if (u8_strlen(theText) > 1)
+		return false;
 
 	int i = 0;
 	uint32_t c = u8_nextchar(theText, &i);
@@ -72,7 +75,8 @@ int stringWidth(char *theText) {
 	uint32_t c;
 	int xOff = 0;
 
-	if (! fontTableSize) return 0;
+	if (!fontTableSize)
+		return 0;
 
 	while (theText[a]) {
 		c = u8_nextchar(theText, &a);
@@ -87,46 +91,51 @@ void pasteString(char *theText, int xOff, int y, spritePalette &thePal) {
 	int a = 0;
 	uint32_t c;
 
-	if (! fontTableSize) return;
+	if (!fontTableSize)
+		return;
 
-	xOff += (int)((float)(fontSpace >> 1) / cameraZoom);
+	xOff += (int) ((float) (fontSpace >> 1) / cameraZoom);
 	while (theText[a]) {
 		c = u8_nextchar(theText, &a);
-		mySprite = & theFont.sprites[fontInTable(c)];
-		fontSprite(xOff, y, * mySprite, thePal);
-		xOff += (int)((double)(mySprite -> width + fontSpace) / cameraZoom);
+		mySprite = &theFont.sprites[fontInTable(c)];
+		fontSprite(xOff, y, *mySprite, thePal);
+		xOff += (int) ((double) (mySprite->width + fontSpace) / cameraZoom);
 	}
 }
 
-void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
+void pasteStringToBackdrop(char *theText, int xOff, int y,
+		spritePalette &thePal) {
 	sprite *mySprite;
 	int a = 0;
 	uint32_t c;
 
-	if (! fontTableSize) return;
+	if (!fontTableSize)
+		return;
 
 	xOff += fontSpace >> 1;
 	while (theText[a]) {
 		c = u8_nextchar(theText, &a);
-		mySprite = & theFont.sprites[fontInTable(c)];
-		pasteSpriteToBackDrop(xOff, y, * mySprite, thePal);
-		xOff += mySprite -> width + fontSpace;
+		mySprite = &theFont.sprites[fontInTable(c)];
+		pasteSpriteToBackDrop(xOff, y, *mySprite, thePal);
+		xOff += mySprite->width + fontSpace;
 	}
 }
 
-void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
+void burnStringToBackdrop(char *theText, int xOff, int y,
+		spritePalette &thePal) {
 	sprite *mySprite;
 	int a = 0;
 	uint32_t c;
 
-	if (! fontTableSize) return;
+	if (!fontTableSize)
+		return;
 
 	xOff += fontSpace >> 1;
 	while (theText[a]) {
 		c = u8_nextchar(theText, &a);
-		mySprite = & theFont.sprites[fontInTable(c)];
-		burnSpriteToBackDrop(xOff, y, * mySprite, thePal);
-		xOff += mySprite -> width + fontSpace;
+		mySprite = &theFont.sprites[fontInTable(c)];
+		burnSpriteToBackDrop(xOff, y, *mySprite, thePal);
+		xOff += mySprite->width + fontSpace;
 	}
 }
 
@@ -167,26 +176,27 @@ bool loadFont(int filenum, const char *charOrder, int h) {
 	int a = 0;
 	uint32_t c;
 
-	delete [] fontOrderString;
+	delete[] fontOrderString;
 	fontOrderString = copyString(charOrder);
 
 	forgetSpriteBank(theFont);
 
 	loadedFontNum = filenum;
 
-
 	fontTableSize = 0;
 	while (charOrder[a]) {
 		c = u8_nextchar(charOrder, &a);
-		if (c > fontTableSize) fontTableSize = c;
+		if (c > fontTableSize)
+			fontTableSize = c;
 	}
 	fontTableSize++;
 
-	delete [] fontTable;
-	fontTable = new uint32_t [fontTableSize];
-	if (! checkNew(fontTable)) return false;
+	delete[] fontTable;
+	fontTable = new uint32_t[fontTableSize];
+	if (!checkNew(fontTable))
+		return false;
 
-	for (a = 0; a < fontTableSize; a ++) {
+	for (a = 0; a < fontTableSize; a++) {
 		fontTable[a] = 0;
 	}
 	a = 0;
@@ -197,7 +207,7 @@ bool loadFont(int filenum, const char *charOrder, int h) {
 		i++;
 	}
 
-	if (! loadSpriteBank(filenum, theFont, true)) {
+	if (!loadSpriteBank(filenum, theFont, true)) {
 		fatal("Can't load font");
 		return false;
 	}
diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp
index 8435a9c..7057f6e 100644
--- a/engines/sludge/freeze.cpp
+++ b/engines/sludge/freeze.cpp
@@ -72,7 +72,7 @@ void freezeGraphics() {
 #endif
 	int w = winWidth;
 	int h = winHeight;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		w = getNextPOT(winWidth);
 		h = getNextPOT(winHeight);
 	}
@@ -89,7 +89,6 @@ void freezeGraphics() {
 	int antiAlias = gameSettings.antiAlias;
 	gameSettings.antiAlias = 0;
 
-
 	int x = 0;
 	while (x < winWidth) {
 		int y = 0;
@@ -109,10 +108,10 @@ void freezeGraphics() {
 			}
 #if 0
 			const GLfloat bPMVMatrix[] = {
-				2.0f / realWinWidth * cameraZoom,                            .0,   .0,  .0,
-				.0, 2.0f / realWinHeight * cameraZoom,   .0,  .0,
-				.0,                            .0, 1.0f,  .0,
-				-2.0f * (x / realWinWidth) - 1.0f,  -2.0f * (y / realWinHeight) - 1.0f,   .0, 1.0f
+				2.0f / realWinWidth * cameraZoom, .0, .0, .0,
+				.0, 2.0f / realWinHeight * cameraZoom, .0, .0,
+				.0, .0, 1.0f, .0,
+				-2.0f * (x / realWinWidth) - 1.0f, -2.0f * (y / realWinHeight) - 1.0f, .0, 1.0f
 
 			};
 			for (int i = 0; i < 16; i++) {
@@ -120,19 +119,18 @@ void freezeGraphics() {
 			}
 			// Render scene
 			glDepthMask(GL_TRUE);
-			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen
 			glDepthMask(GL_FALSE);
 
-			drawBackDrop();                 // Draw the room
+			drawBackDrop();// Draw the room
 			drawZBuffer(cameraX, cameraY, false);
 
 			glEnable(GL_DEPTH_TEST);
 
-			drawPeople();                   // Then add any moving characters...
+			drawPeople();// Then add any moving characters...
 
 			glDisable(GL_DEPTH_TEST);
 
-
 			// Copy Our ViewPort To The Texture
 			copyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, w, h, freezeTextureName);
 #endif
@@ -152,7 +150,8 @@ void freezeGraphics() {
 bool freeze() {
 	debugOut("calling freeze()\n");
 	frozenStuffStruct *newFreezer = new frozenStuffStruct;
-	if (! checkNew(newFreezer)) return false;
+	if (!checkNew(newFreezer))
+		return false;
 
 	// Grab a copy of the current scene
 	freezeGraphics();
@@ -161,7 +160,7 @@ bool freeze() {
 #endif
 	int picWidth = sceneWidth;
 	int picHeight = sceneHeight;
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(picWidth);
 		picHeight = getNextPOT(picHeight);
 	}
@@ -173,11 +172,11 @@ bool freeze() {
 
 	backdropTextureName = 0;
 #endif
-	newFreezer -> sceneWidth = sceneWidth;
-	newFreezer -> sceneHeight = sceneHeight;
-	newFreezer -> cameraX = cameraX;
-	newFreezer -> cameraY = cameraY;
-	newFreezer -> cameraZoom = cameraZoom;
+	newFreezer->sceneWidth = sceneWidth;
+	newFreezer->sceneHeight = sceneHeight;
+	newFreezer->cameraX = cameraX;
+	newFreezer->cameraY = cameraY;
+	newFreezer->cameraZoom = cameraZoom;
 #if 0
 	newFreezer -> lightMapTexture = lightMap.data;
 	newFreezer -> lightMapTextureName = lightMap.name;
@@ -192,9 +191,10 @@ bool freeze() {
 	zBuffer.tex = NULL;
 #endif
 	// resizeBackdrop kills parallax stuff, light map, z-buffer...
-	if (! resizeBackdrop(winWidth, winHeight)) return fatal("Can't create new temporary backdrop buffer");
+	if (!resizeBackdrop(winWidth, winHeight))
+		return fatal("Can't create new temporary backdrop buffer");
 
-	if (! NPOT_textures) {
+	if (!NPOT_textures) {
 		picWidth = getNextPOT(sceneWidth);
 		picHeight = getNextPOT(sceneHeight);
 #if 0
@@ -225,31 +225,33 @@ bool freeze() {
 		deleteTextures(1, &newFreezer -> backdropTextureName);
 	}
 #endif
-	newFreezer -> allPeople = allPeople;
+	newFreezer->allPeople = allPeople;
 	allPeople = NULL;
 
 	statusStuff *newStatusStuff = new statusStuff;
-	if (! checkNew(newStatusStuff)) return false;
-	newFreezer -> frozenStatus = copyStatusBarStuff(newStatusStuff);
+	if (!checkNew(newStatusStuff))
+		return false;
+	newFreezer->frozenStatus = copyStatusBarStuff(newStatusStuff);
 
-	newFreezer -> allScreenRegions = allScreenRegions;
+	newFreezer->allScreenRegions = allScreenRegions;
 	allScreenRegions = NULL;
 	overRegion = NULL;
 
-	newFreezer -> mouseCursorAnim = mouseCursorAnim;
-	newFreezer -> mouseCursorFrameNum = mouseCursorFrameNum;
+	newFreezer->mouseCursorAnim = mouseCursorAnim;
+	newFreezer->mouseCursorFrameNum = mouseCursorFrameNum;
 	mouseCursorAnim = makeNullAnim();
 	mouseCursorFrameNum = 0;
 
-	newFreezer -> speech = speech;
+	newFreezer->speech = speech;
 	initSpeech();
 
-	newFreezer -> currentEvents = currentEvents;
+	newFreezer->currentEvents = currentEvents;
 	currentEvents = new eventHandlers;
-	if (! checkNew(currentEvents)) return false;
+	if (!checkNew(currentEvents))
+		return false;
 	memset(currentEvents, 0, sizeof(eventHandlers));
 
-	newFreezer -> next = frozenStuff;
+	newFreezer->next = frozenStuff;
 	frozenStuff = newFreezer;
 
 	return true;
@@ -259,8 +261,8 @@ int howFrozen() {
 	int a = 0;
 	frozenStuffStruct *f = frozenStuff;
 	while (f) {
-		a ++;
-		f = f -> next;
+		a++;
+		f = f->next;
 	}
 	return a;
 }
@@ -272,25 +274,26 @@ extern GLubyte *backdropTexture;
 void unfreeze(bool killImage) {
 	frozenStuffStruct *killMe = frozenStuff;
 
-	if (! frozenStuff) return;
+	if (!frozenStuff)
+		return;
 
-	sceneWidth = frozenStuff -> sceneWidth;
-	sceneHeight = frozenStuff -> sceneHeight;
+	sceneWidth = frozenStuff->sceneWidth;
+	sceneHeight = frozenStuff->sceneHeight;
 
-	cameraX = frozenStuff -> cameraX;
-	cameraY = frozenStuff -> cameraY;
-	input.mouseX = (int)(input.mouseX * cameraZoom);
-	input.mouseY = (int)(input.mouseY * cameraZoom);
-	cameraZoom = frozenStuff -> cameraZoom;
-	input.mouseX = (int)(input.mouseX / cameraZoom);
-	input.mouseY = (int)(input.mouseY / cameraZoom);
+	cameraX = frozenStuff->cameraX;
+	cameraY = frozenStuff->cameraY;
+	input.mouseX = (int) (input.mouseX * cameraZoom);
+	input.mouseY = (int) (input.mouseY * cameraZoom);
+	cameraZoom = frozenStuff->cameraZoom;
+	input.mouseX = (int) (input.mouseX / cameraZoom);
+	input.mouseY = (int) (input.mouseY / cameraZoom);
 	setPixelCoords(false);
 
 	killAllPeople();
-	allPeople = frozenStuff -> allPeople;
+	allPeople = frozenStuff->allPeople;
 
 	killAllRegions();
-	allScreenRegions = frozenStuff -> allScreenRegions;
+	allScreenRegions = frozenStuff->allScreenRegions;
 
 	killLightMap();
 #if 0
@@ -346,18 +349,18 @@ void unfreeze(bool killImage) {
 	}
 #endif
 	deleteAnim(mouseCursorAnim);
-	mouseCursorAnim = frozenStuff -> mouseCursorAnim;
-	mouseCursorFrameNum = frozenStuff -> mouseCursorFrameNum;
+	mouseCursorAnim = frozenStuff->mouseCursorAnim;
+	mouseCursorFrameNum = frozenStuff->mouseCursorFrameNum;
 
-	restoreBarStuff(frozenStuff -> frozenStatus);
+	restoreBarStuff(frozenStuff->frozenStatus);
 
 	delete currentEvents;
-	currentEvents = frozenStuff -> currentEvents;
+	currentEvents = frozenStuff->currentEvents;
 	killAllSpeech();
 	delete speech;
 
-	speech = frozenStuff -> speech;
-	frozenStuff = frozenStuff -> next;
+	speech = frozenStuff->speech;
+	frozenStuff = frozenStuff->next;
 
 	overRegion = NULL;
 	delete killMe;
diff --git a/engines/sludge/freeze.h b/engines/sludge/freeze.h
index a9f5129..4472852 100644
--- a/engines/sludge/freeze.h
+++ b/engines/sludge/freeze.h
@@ -48,7 +48,6 @@ struct frozenStuffStruct {
 	frozenStuffStruct *next;
 };
 
-
 bool freeze();
 void unfreeze(bool killImage = true);
 int howFrozen();
diff --git a/engines/sludge/graphics.cpp b/engines/sludge/graphics.cpp
index 702865e..7c7c7be 100644
--- a/engines/sludge/graphics.cpp
+++ b/engines/sludge/graphics.cpp
@@ -94,13 +94,13 @@ struct textureList *firstTexture = NULL;
 
 textureList *addTexture() {
 	textureList *newTexture = new textureList;
-	newTexture -> next = firstTexture;
+	newTexture->next = firstTexture;
 	firstTexture = newTexture;
 	return newTexture;
 }
 
 #if 0
-void deleteTextures(GLsizei n,  const GLuint *textures) {
+void deleteTextures(GLsizei n, const GLuint *textures) {
 	if (firstTexture == NULL) {
 		//debugOut("Deleting texture while list is already empty.\n");
 	} else {
@@ -133,10 +133,10 @@ void deleteTextures(GLsizei n,  const GLuint *textures) {
 
 }
 
-void getTextureDimensions(GLuint name, GLint *width,  GLint *height) {
+void getTextureDimensions(GLuint name, GLint *width, GLint *height) {
 	textureList *list = firstTexture;
 	while (list) {
-		if (list->name == name)  {
+		if (list->name == name) {
 			*width = list->width;
 			*height = list->height;
 #if !defined(HAVE_GLES2)
@@ -156,7 +156,7 @@ void getTextureDimensions(GLuint name, GLint *width,  GLint *height) {
 	fatal("Texture not found in list.\n");
 }
 
-void storeTextureDimensions(GLuint name, GLsizei width,  GLsizei height, const char *file, int line) {
+void storeTextureDimensions(GLuint name, GLsizei width, GLsizei height, const char *file, int line) {
 	if (! NPOT_textures && !(((height & (height - 1)) == 0) || ((width & (width - 1)) == 0))) {
 		debugOut("I was told to create a texture with dimensions %ix%i in %s @ line %d although NPOT textures are disabled.\n", width, height, file, line);
 		//height = getNextPOT(height);
@@ -165,7 +165,7 @@ void storeTextureDimensions(GLuint name, GLsizei width,  GLsizei height, const c
 
 	textureList *list = firstTexture;
 	while (list) {
-		if (list->name == name)  {
+		if (list->name == name) {
 			//debugOut("Texture dimensions are overwritten.\n");
 			break;
 		}
@@ -182,14 +182,14 @@ void storeTextureDimensions(GLuint name, GLsizei width,  GLsizei height, const c
 #endif
 
 #ifdef HAVE_GLES2
-void glesCopyTexSubImage2D(GLenum target,  GLint level, GLint xoffset, GLint yoffset, GLint x,  GLint y,  GLsizei width,  GLsizei height) {
+void glesCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
 	// Work around for broken glCopy(Sub)TexImage2D...
 	void *tmp = malloc(width * height * 4);
 	glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
 	glTexSubImage2D(target, level, xoffset, yoffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
 	free(tmp);
 }
-void glesCopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint x,  GLint y,  GLsizei width,  GLsizei height,  GLint border) {
+void glesCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {
 	// Work around for broken glCopy(Sub)TexImage2D...
 	void *tmp = malloc(width * height * 4);
 	glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
@@ -199,7 +199,7 @@ void glesCopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GL
 #endif
 
 #if 0
-void dcopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint x,  GLint y,  GLsizei width,  GLsizei height,  GLint border, GLuint name, const char *file, int line) {
+void dcopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border, GLuint name, const char *file, int line) {
 
 	glBindTexture(GL_TEXTURE_2D, name);
 #ifdef HAVE_GLES2_
@@ -209,7 +209,7 @@ void dcopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint
 #endif
 }
 
-void dcopyTexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLint x,  GLint y,  GLsizei width,  GLsizei height, GLuint name, const char *file, int line) {
+void dcopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, GLuint name, const char *file, int line) {
 	glBindTexture(GL_TEXTURE_2D, name);
 #ifdef HAVE_GLES2_
 	glesCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
@@ -218,16 +218,16 @@ void dcopyTexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoff
 #endif
 }
 
-void dtexImage2D(GLenum target,  GLint level,  GLint internalformat,  GLsizei width,  GLsizei height,
-                 GLint border,  GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line) {
-	storeTextureDimensions(name, width,  height, file, line);
+void dtexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
+		GLint border, GLenum format, GLenum type, const GLvoid *data, GLuint name, const char *file, int line) {
+	storeTextureDimensions(name, width, height, file, line);
 	glBindTexture(GL_TEXTURE_2D, name);
-	glTexImage2D(target, level, internalformat, width, height, border, format, type,  data);
+	glTexImage2D(target, level, internalformat, width, height, border, format, type, data);
 }
 
-void dtexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLsizei width,  GLsizei height,
-                    GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line) {
-	storeTextureDimensions(name, width,  height, file, line);
+void dtexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
+		GLenum format, GLenum type, const GLvoid *data, GLuint name, const char *file, int line) {
+	storeTextureDimensions(name, width, height, file, line);
 	glBindTexture(GL_TEXTURE_2D, name);
 	glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
 }
@@ -289,7 +289,6 @@ void drawQuad(GLint program, const GLfloat *vertices, int numTexCoords, ...) {
 
 }
 
-
 void setPMVMatrix(GLint program) {
 	glUniformMatrix4fv(glGetUniformLocation(program, "myPMVMatrix"), 1, GL_FALSE, aPMVMatrix);
 }
@@ -310,10 +309,10 @@ void setPixelCoords(bool pixels) {
 		glClear(GL_COLOR_BUFFER_BIT);
 
 		const GLfloat bPMVMatrix[] = {
-			2.0f / viewportWidth,                  .0,   .0,  .0,
-			.0, 2.0f / viewportHeight,   .0,  .0,
-			.0,                  .0, 1.0f,  .0,
-			-1.0,               -1.0f,   .0, 1.0f
+			2.0f / viewportWidth, .0, .0, .0,
+			.0, 2.0f / viewportHeight, .0, .0,
+			.0, .0, 1.0f, .0,
+			-1.0, -1.0f, .0, 1.0f
 
 		};
 		for (int i = 0; i < 16; i++) {
@@ -332,10 +331,10 @@ void setPixelCoords(bool pixels) {
 		GLfloat h = (GLfloat) winHeight / cameraZoom;
 
 		const GLfloat bPMVMatrix[] = {
-			2.0f / w,      .0,   .0,  .0,
-			.0, -2.0f / h,   .0,  .0,
-			.0,      .0, 1.0f,  .0,
-			-1.0,    1.0f,   .0, 1.0f
+			2.0f / w, .0, .0, .0,
+			.0, -2.0f / h, .0, .0,
+			.0, .0, 1.0f, .0,
+			-1.0, 1.0f, .0, 1.0f
 
 		};
 		for (int i = 0; i < 16; i++) {
@@ -348,7 +347,6 @@ void setPixelCoords(bool pixels) {
 int desktopW = 0, desktopH = 0;
 bool runningFullscreen = false;
 
-
 #if defined(HAVE_GLES2)
 void saveTexture(GLuint tex, GLubyte *data) {
 	// use an FBO to easily grab the texture...
@@ -412,7 +410,7 @@ void saveTexture(GLuint tex, GLubyte *data) {
 			drawQuad(shader.texture, vertices, 1, texCoords);
 			glUseProgram(0);
 
-			for (int i = 0; i < h; i++)   {
+			for (int i = 0; i < h; i++) {
 				glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, data + xoffset * 4 + (yoffset + i) * 4 * tw);
 			}
 
@@ -607,13 +605,13 @@ void setGraphicsWindow(bool fullscreen, bool restoreGraphics, bool resize) {
 	Fragment = shaderFileRead("scale.frag");
 #else
 	/*  const GLubyte *str;
-	    int glDerivativesAvailable;
-	    str = glGetString (GL_EXTENSIONS);
-	    glDerivativesAvailable = (strstr((const char *)str, "GL_OES_standard_derivatives") != NULL);
-	    if (!glDerivativesAvailable) {
-	        debugOut("Extension \"GL_OES_standard_derivatives\" not available. Advanced anti-aliasing is not possible. Using linear anti-aliasing instead.");
-	        gameSettings.antiAlias = -1;
-	*/
+	 int glDerivativesAvailable;
+	 str = glGetString (GL_EXTENSIONS);
+	 glDerivativesAvailable = (strstr((const char *)str, "GL_OES_standard_derivatives") != NULL);
+	 if (!glDerivativesAvailable) {
+	 debugOut("Extension \"GL_OES_standard_derivatives\" not available. Advanced anti-aliasing is not possible. Using linear anti-aliasing instead.");
+	 gameSettings.antiAlias = -1;
+	 */
 	Fragment = shaderFileRead("scale_noaa.frag");
 //	}
 
@@ -823,7 +821,6 @@ void setGraphicsWindow(bool fullscreen, bool restoreGraphics, bool resize) {
 			}
 		}
 
-
 		reloadSpriteTextures();
 		reloadParallaxTextures();
 		zBuffer.texName = 0;
@@ -839,7 +836,7 @@ void setGraphicsWindow(bool fullscreen, bool restoreGraphics, bool resize) {
 	}
 
 	if (movieIsPlaying)
-		setMovieViewport();
+	setMovieViewport();
 #endif
 }
 
@@ -923,7 +920,6 @@ void setupOpenGLStuff() {
 
 }
 
-
 // I found this function on a coding forum on the 'net.
 // Looks a bit weird, but it should work.
 int getNextPOT(int n) {
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
index 24b7671..493e6f1 100644
--- a/engines/sludge/graphics.h
+++ b/engines/sludge/graphics.h
@@ -87,7 +87,8 @@ void setPMVMatrix(GLint program);
 #endif
 
 void setPixelCoords(bool pixels);
-void setGraphicsWindow(bool fullscreen, bool restoreGraphics = true, bool resize = false);
+void setGraphicsWindow(bool fullscreen, bool restoreGraphics = true,
+		bool resize = false);
 
 void setupOpenGLStuff();
 
@@ -96,10 +97,10 @@ int getNextPOT(int n);
 #if 0
 void saveTexture(GLuint tex, GLubyte *data);
 
-void dcopyTexImage2D(GLenum target,  GLint level,  GLenum internalformat,  GLint x,  GLint y,  GLsizei width,  GLsizei height,  GLint border, GLuint name, const char *file, int line);
-void dcopyTexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLint x,  GLint y,  GLsizei width,  GLsizei height, GLuint name, const char *file, int line);
-void dtexImage2D(GLenum target,  GLint level,  GLint internalformat,  GLsizei width,  GLsizei height,  GLint border,  GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line);
-void dtexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,  GLsizei width,  GLsizei height,  GLenum format,  GLenum type,  const GLvoid *data, GLuint name, const char *file, int line);
+void dcopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border, GLuint name, const char *file, int line);
+void dcopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, GLuint name, const char *file, int line);
+void dtexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data, GLuint name, const char *file, int line);
+void dtexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data, GLuint name, const char *file, int line);
 
 #define copyTexImage2D(target, level, internalformat, x, y,  width, height, border, name) dcopyTexImage2D(target,  level,  internalformat,  x,  y,  width,height, border, name, __FILE__, __LINE__)
 
@@ -109,14 +110,15 @@ void dtexSubImage2D(GLenum target,  GLint level,  GLint xoffset,  GLint yoffset,
 
 #define texSubImage2D( target,  level,   xoffset,   yoffset,   width,  height, format,  type,   data,name) dtexSubImage2D( target, level,   xoffset,  yoffset,  width,  height, format,  type,  data,  name, __FILE__, __LINE__)
 
-void deleteTextures(GLsizei n,  const GLuint *textures);
+void deleteTextures(GLsizei n, const GLuint *textures);
 
-void getTextureDimensions(GLuint name, GLint *width,  GLint *height);
+void getTextureDimensions(GLuint name, GLint *width, GLint *height);
 
-int printOglError(const char *file, int         line);
+int printOglError(const char *file, int line);
 #define printOpenGLError() printOglError(__FILE__, __LINE__)
 #endif
 
-} // End of namespace Sludge
+}
+ // End of namespace Sludge
 
 #endif
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
index 4fe2780..6bbb6d3 100644
--- a/engines/sludge/language.cpp
+++ b/engines/sludge/language.cpp
@@ -44,9 +44,9 @@ unsigned int stringToInt(char *s) {
 		if (*s >= '0' && *s <= '9') {
 			i *= 10;
 			i += *s - '0';
-			s ++;
+			s++;
 		} else if (*s == '-') {
-			negative = ! negative;
+			negative = !negative;
 			s++;
 		} else {
 			if (negative)
@@ -56,7 +56,6 @@ unsigned int stringToInt(char *s) {
 	}
 }
 
-
 char *getPrefsFilename(char *filename) {
 	// Yes, this trashes the original string, but
 	// we also free it at the end (warning!)...
@@ -92,7 +91,8 @@ void readIniFile(char *filename) {
 
 	Common::File fd;
 	if (!fd.open(langName)) {
-		debug(kSludgeDebugDataLoad, "Fail to open language file : %s", langName);
+		debug(kSludgeDebugDataLoad, "Fail to open language file : %s",
+				langName);
 		return;
 	}
 
@@ -127,7 +127,7 @@ void readIniFile(char *filename) {
 				if (strcmp(lineSoFar, "LANGUAGE") == 0) {
 					gameSettings.languageID = stringToInt(secondSoFar);
 				} else if (strcmp(lineSoFar, "WINDOW") == 0) {
-					gameSettings.userFullScreen = ! stringToInt(secondSoFar);
+					gameSettings.userFullScreen = !stringToInt(secondSoFar);
 				} else if (strcmp(lineSoFar, "REFRESH") == 0) {
 					gameSettings.refreshRate = stringToInt(secondSoFar);
 				} else if (strcmp(lineSoFar, "ANTIALIAS") == 0) {
@@ -153,10 +153,10 @@ void readIniFile(char *filename) {
 
 		default:
 			if (doingSecond) {
-				secondSoFar[here ++] = readChar;
+				secondSoFar[here++] = readChar;
 				secondSoFar[here] = 0;
 			} else {
-				lineSoFar[here ++] = readChar;
+				lineSoFar[here++] = readChar;
 				lineSoFar[here] = 0;
 			}
 			break;
@@ -185,19 +185,23 @@ void saveIniFile(char *filename) {
 
 void makeLanguageTable(Common::File *table) {
 	languageTable = new int[gameSettings.numLanguages + 1];
-	if (! checkNew(languageTable)) return;
+	if (!checkNew(languageTable))
+		return;
 
 	languageName = new char *[gameSettings.numLanguages + 1];
-	if (! checkNew(languageName)) return;
+	if (!checkNew(languageName))
+		return;
 
-	for (unsigned int i = 0; i <= gameSettings.numLanguages; i ++) {
+	for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
 		languageTable[i] = i ? get2bytes(table) : 0;
-		debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, languageTable[i]);
+		debug(kSludgeDebugDataLoad, "languageTable %i: %i", i,
+				languageTable[i]);
 		languageName[i] = 0;
 		if (gameVersion >= VERSION(2, 0)) {
 			if (gameSettings.numLanguages) {
 				languageName[i] = readString(table);
-				debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, languageName[i]);
+				debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i,
+						languageName[i]);
 			}
 		}
 	}
@@ -206,8 +210,9 @@ void makeLanguageTable(Common::File *table) {
 int getLanguageForFileB() {
 	int indexNum = -1;
 
-	for (unsigned int i = 0; i <= gameSettings.numLanguages; i ++) {
-		if (languageTable[i] == gameSettings.languageID) indexNum = i;
+	for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
+		if (languageTable[i] == gameSettings.languageID)
+			indexNum = i;
 	}
 
 	return indexNum;
diff --git a/engines/sludge/line.cpp b/engines/sludge/line.cpp
index bcb1343..1feba03 100644
--- a/engines/sludge/line.cpp
+++ b/engines/sludge/line.cpp
@@ -37,10 +37,10 @@ void drawLine(int x1, int y1, int x2, int y2) {
 	int x, y;
 	bool backwards = false;
 #if 0
-	if (x1 < 0)  x1 = 0;
-	if (y1 < 0)  y1 = 0;
-	if (x2 < 0)  x2 = 0;
-	if (y2 < 0)  y2 = 0;
+	if (x1 < 0) x1 = 0;
+	if (y1 < 0) y1 = 0;
+	if (x2 < 0) x2 = 0;
+	if (y2 < 0) y2 = 0;
 	if (x1 > sceneWidth) x1 = sceneWidth - 1;
 	if (x2 > sceneWidth) x2 = sceneWidth - 1;
 	if (y1 > sceneHeight) y1 = sceneHeight - 1;
@@ -69,10 +69,8 @@ void drawLine(int x1, int y1, int x2, int y2) {
 	}
 	setPixelCoords(true);
 
-
 	glLineWidth(2.0);
 
-
 	int xoffset = 0;
 	while (xoffset < diffX) {
 		int w = (diffX - xoffset < viewportWidth) ? diffX - xoffset : viewportWidth;
@@ -98,7 +96,6 @@ void drawLine(int x1, int y1, int x2, int y2) {
 				backdropTexW, backdropTexH
 			};
 
-
 			glUseProgram(shader.texture);
 
 			setPMVMatrix(shader.texture);
@@ -118,7 +115,6 @@ void drawLine(int x1, int y1, int x2, int y2) {
 				xo2, -yoffset + diffY, 0,
 			};
 
-
 			glUseProgram(shader.color);
 
 			setPMVMatrix(shader.color);
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 959885f..125e318 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -78,7 +78,6 @@ extern parallaxLayer *parallaxStuff;                //      "
 extern int lightMapMode;                    //      "
 extern int languageNum;
 
-
 //----------------------------------------------------------------------
 // Globals (so we know what's saved already and what's a reference
 //----------------------------------------------------------------------
@@ -100,7 +99,7 @@ void saveStack(variableStack *vs, Common::WriteStream *stream) {
 
 	variableStack *search = vs;
 	while (search) {
-		elements ++;
+		elements++;
 		search = search->next;
 	}
 
@@ -114,7 +113,8 @@ void saveStack(variableStack *vs, Common::WriteStream *stream) {
 	}
 }
 
-variableStack *loadStack(Common::SeekableReadStream *stream, variableStack **last) {
+variableStack *loadStack(Common::SeekableReadStream *stream,
+		variableStack **last) {
 	int elements = get2bytes(stream);
 	int a;
 	variableStack *first = NULL;
@@ -122,14 +122,15 @@ variableStack *loadStack(Common::SeekableReadStream *stream, variableStack **las
 
 	for (a = 0; a < elements; ++a) {
 		variableStack *nS = new variableStack;
-		if (!checkNew(nS)) return NULL;
+		if (!checkNew(nS))
+			return NULL;
 		loadVariable(&(nS->thisVar), stream);
 		if (last && a == elements - 1) {
 			stackDebug((stackfp, "Setting last to %p\n", nS));
 			*last = nS;
 		}
 		nS->next = NULL;
-		(* changeMe) = nS;
+		(*changeMe) = nS;
 		changeMe = &(nS->next);
 	}
 
@@ -151,8 +152,9 @@ bool saveStackRef(stackHandler *vs, Common::WriteStream *stream) {
 	putch(0, stream);
 	saveStack(vs->first, stream);
 	s = new stackLibrary;
-	stackLibTotal ++;
-	if (! checkNew(s)) return false;
+	stackLibTotal++;
+	if (!checkNew(s))
+		return false;
 	s->next = stackLib;
 	s->stack = vs;
 	stackLib = s;
@@ -173,7 +175,7 @@ stackHandler *getStackFromLibrary(int n) {
 	n = stackLibTotal - n;
 	while (n) {
 		stackLib = stackLib->next;
-		n --;
+		n--;
 	}
 	return stackLib->stack;
 }
@@ -185,14 +187,15 @@ stackHandler *loadStackRef(Common::SeekableReadStream *stream) {
 		stackDebug((stackfp, "loadStackRef (duplicate, get from library)\n"));
 
 		nsh = getStackFromLibrary(get2bytes(stream));
-		nsh->timesUsed ++;
+		nsh->timesUsed++;
 	} else {
 		stackDebug((stackfp, "loadStackRef (new one)\n"));
 
 		// Load the new stack
 
 		nsh = new stackHandler;
-		if (! checkNew(nsh)) return NULL;
+		if (!checkNew(nsh))
+			return NULL;
 		nsh->last = NULL;
 		nsh->first = loadStack(stream, &nsh->last);
 		nsh->timesUsed = 1;
@@ -206,11 +209,12 @@ stackHandler *loadStackRef(Common::SeekableReadStream *stream) {
 		// Add it to the library of loaded stacks
 
 		stackLibrary *s = new stackLibrary;
-		if (! checkNew(s)) return NULL;
+		if (!checkNew(s))
+			return NULL;
 		s->stack = nsh;
 		s->next = stackLib;
 		stackLib = s;
-		stackLibTotal ++;
+		stackLibTotal++;
 	}
 	return nsh;
 }
@@ -257,15 +261,14 @@ bool saveVariable(variable *from, Common::WriteStream *stream) {
 
 	default:
 		fatal("Can't save variables of this type:",
-		      (from->varType < SVT_NUM_TYPES) ?
-		      typeName[from->varType] :
-		      "bad ID");
+				(from->varType < SVT_NUM_TYPES) ?
+						typeName[from->varType] : "bad ID");
 	}
 	return true;
 }
 
 bool loadVariable(variable *to, Common::SeekableReadStream *stream) {
-	to->varType = (variableType)getch(stream);
+	to->varType = (variableType) getch(stream);
 	switch (to->varType) {
 	case SVT_INT:
 	case SVT_FUNC:
@@ -292,13 +295,15 @@ bool loadVariable(variable *to, Common::SeekableReadStream *stream) {
 
 	case SVT_COSTUME:
 		to->varData.costumeHandler = new persona;
-		if (! checkNew(to->varData.costumeHandler)) return false;
+		if (!checkNew(to->varData.costumeHandler))
+			return false;
 		loadCostume(to->varData.costumeHandler, stream);
 		return true;
 
 	case SVT_ANIM:
 		to->varData.animHandler = new personaAnimation;
-		if (! checkNew(to->varData.animHandler)) return false;
+		if (!checkNew(to->varData.animHandler))
+			return false;
 		loadAnim(to->varData.animHandler, stream);
 		return true;
 
@@ -342,7 +347,8 @@ loadedFunction *loadFunction(Common::SeekableReadStream *stream) {
 	// Reserve memory...
 
 	loadedFunction *buildFunc = new loadedFunction;
-	if (! checkNew(buildFunc)) return NULL;
+	if (!checkNew(buildFunc))
+		return NULL;
 
 	// See what it was called by and load if we need to...
 
@@ -350,7 +356,8 @@ loadedFunction *loadFunction(Common::SeekableReadStream *stream) {
 	buildFunc->calledBy = NULL;
 	if (getch(stream)) {
 		buildFunc->calledBy = loadFunction(stream);
-		if (! buildFunc->calledBy) return NULL;
+		if (!buildFunc->calledBy)
+			return NULL;
 	}
 
 	buildFunc->timeLeft = get4bytes(stream);
@@ -396,7 +403,7 @@ bool saveGame(char *fname) {
 
 	fputc(allowAnyFilename, fp);
 	fputc(captureAllKeys, fp);
-	fputc(true, fp);  // updateDisplay
+	fputc(true, fp);// updateDisplay
 	fputc(fontTableSize > 0, fp);
 
 	if (fontTableSize > 0) {
@@ -515,7 +522,7 @@ bool loadGame(char *fname) {
 	}
 
 	if (savedGameTime.dwLowDateTime != fileTime.dwLowDateTime ||
-	        savedGameTime.dwHighDateTime != fileTime.dwHighDateTime) {
+			savedGameTime.dwHighDateTime != fileTime.dwHighDateTime) {
 		return fatal(ERROR_GAME_LOAD_WRONG, fname);
 	}
 
@@ -579,7 +586,6 @@ bool loadGame(char *fname) {
 	loadedFunction *rFunc;
 	loadedFunction * * buildList = &allRunningFunctions;
 
-
 	int countFunctions = get2bytes(fp);
 	while (countFunctions --) {
 		rFunc = loadFunction(fp);
@@ -595,7 +601,6 @@ bool loadGame(char *fname) {
 
 	loadPeople(fp);
 
-
 	if (fgetc(fp)) {
 		if (! setFloor(get2bytes(fp))) return false;
 	} else setFloorNull();
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 283a228..8496a9b 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -36,7 +36,6 @@
 
 #include <iostream>
 
-
 #include <stdexcept>
 
 #include <time.h>
@@ -159,19 +158,19 @@ void checkInput() {
 	while (SDL_PollEvent(&event)) {
 		switch (event.type) {
 
-		case SDL_VIDEORESIZE:
+			case SDL_VIDEORESIZE:
 			realWinWidth = event.resize.w;
 			realWinHeight = event.resize.h;
 			setGraphicsWindow(false, true, true);
 			break;
 
-		case SDL_MOUSEMOTION:
+			case SDL_MOUSEMOTION:
 			input.justMoved = true;
 			input.mouseX = event.motion.x * ((float)winWidth / cameraZoom) / realWinWidth;
 			input.mouseY = event.motion.y * ((float)winHeight / cameraZoom) / realWinHeight;
 			break;
 
-		case SDL_MOUSEBUTTONDOWN:
+			case SDL_MOUSEBUTTONDOWN:
 			if (event.button.button == SDL_BUTTON_LEFT) {
 				if (SDL_GetModState() & KMOD_CTRL) {
 					input.rightClick = true;
@@ -186,7 +185,7 @@ void checkInput() {
 			input.mouseY = event.motion.y * ((float)winHeight / cameraZoom) / realWinHeight;
 			break;
 
-		case SDL_MOUSEBUTTONUP:
+			case SDL_MOUSEBUTTONUP:
 			if (event.button.button == SDL_BUTTON_LEFT) {
 				if (fakeRightclick) {
 					fakeRightclick = false;
@@ -200,7 +199,7 @@ void checkInput() {
 			input.mouseY = event.motion.y * ((float)winHeight / cameraZoom) / realWinHeight;
 			break;
 
-		case SDL_KEYDOWN:
+			case SDL_KEYDOWN:
 			// A Windows key is pressed - let's leave fullscreen.
 			if (runningFullscreen) {
 				if (event.key.keysym.sym == SDLK_LSUPER || event.key.keysym.sym == SDLK_LSUPER) {
@@ -224,7 +223,7 @@ void checkInput() {
 					break;
 				}
 				// Allow Alt+F4 to quit
-				if (SDLK_F4 ==  event.key.keysym.sym) {
+				if (SDLK_F4 == event.key.keysym.sym) {
 					SDL_Event event;
 					event.type = SDL_QUIT;
 					SDL_PushEvent(&event);
@@ -233,86 +232,86 @@ void checkInput() {
 				break;
 			}
 			switch (event.key.keysym.sym) {
-			case SDLK_BACKSPACE:
-			case SDLK_DELETE:   // Ok, mapping these to the same key is weird, I admit. But good?
+				case SDLK_BACKSPACE:
+				case SDLK_DELETE: // Ok, mapping these to the same key is weird, I admit. But good?
 				input.keyPressed = 127;
 				break;
-			case SDLK_TAB:
+				case SDLK_TAB:
 				input.keyPressed = 9;
 				break;
-			case SDLK_RETURN:
+				case SDLK_RETURN:
 				input.keyPressed = 13;
 				break;
-			case SDLK_ESCAPE:
+				case SDLK_ESCAPE:
 				input.keyPressed = 27;
 				break;
-			case SDLK_PAGEUP:
+				case SDLK_PAGEUP:
 				input.keyPressed = 63276;
 				break;
-			case SDLK_PAGEDOWN:
+				case SDLK_PAGEDOWN:
 				input.keyPressed = 63277;
 				break;
-			case SDLK_END:
+				case SDLK_END:
 				input.keyPressed = 63275;
 				break;
-			case SDLK_HOME:
+				case SDLK_HOME:
 				input.keyPressed = 63273;
 				break;
-			case SDLK_LEFT:
+				case SDLK_LEFT:
 				input.keyPressed = 63234;
 				break;
-			case SDLK_UP:
+				case SDLK_UP:
 				input.keyPressed = 63232;
 				break;
-			case SDLK_RIGHT:
+				case SDLK_RIGHT:
 				input.keyPressed = 63235;
 				break;
-			case SDLK_DOWN:
+				case SDLK_DOWN:
 				input.keyPressed = 63233;
 				break;
-			case SDLK_F1:
+				case SDLK_F1:
 				input.keyPressed = 63236;
 				break;
-			case SDLK_F2:
+				case SDLK_F2:
 				input.keyPressed = 63237;
 				break;
-			case SDLK_F3:
+				case SDLK_F3:
 				input.keyPressed = 63238;
 				break;
-			case SDLK_F4:
+				case SDLK_F4:
 				input.keyPressed = 63239;
 				break;
-			case SDLK_F5:
+				case SDLK_F5:
 				input.keyPressed = 63240;
 				break;
-			case SDLK_F6:
+				case SDLK_F6:
 				input.keyPressed = 63241;
 				break;
-			case SDLK_F7:
+				case SDLK_F7:
 				input.keyPressed = 63242;
 				break;
-			case SDLK_F8:
+				case SDLK_F8:
 				input.keyPressed = 63243;
 				break;
-			case SDLK_F9:
+				case SDLK_F9:
 				input.keyPressed = 63244;
 				break;
-			case SDLK_F10:
+				case SDLK_F10:
 				input.keyPressed = 63245;
 				break;
-			case SDLK_F11:
+				case SDLK_F11:
 				input.keyPressed = 63246;
 				break;
-			case SDLK_F12:
+				case SDLK_F12:
 				input.keyPressed = 63247;
 				break;
-			default:
+				default:
 				input.keyPressed = event.key.keysym.unicode;
 				break;
 			}
 			break;
 
-		case SDL_QUIT:
+			case SDL_QUIT:
 			if (reallyWantToQuit) {
 				// The game file has requested that we quit
 				weAreDoneSoQuit = 1;
@@ -326,7 +325,7 @@ void checkInput() {
 			}
 			break;
 
-		default:
+			default:
 			break;
 		}
 	}
@@ -335,9 +334,9 @@ void checkInput() {
 
 int main_loop(char *filename)
 #if 0
-try
+		try
 #endif
-{
+		{
 	/* Dimensions of our window. */
 	winWidth = 640;
 	winHeight = 480;
@@ -348,7 +347,6 @@ try
 	time_t t;
 	srand((unsigned) time(&t));
 
-
 	// bundleFolder is used to look for the game file
 	// and later to find the shader programs
 #ifdef __APPLE__
@@ -392,11 +390,13 @@ try
 
 	// The player pressed cancel in the file selection dialogue,
 	// so we should quit now.
-	if (!sludgeFile) return 0;
+	if (!sludgeFile)
+		return 0;
 
 	// OK, so we DO want to start up, then...
 	setGameFilePath(sludgeFile);
-	if (!initSludge(sludgeFile)) return 0;
+	if (!initSludge(sludgeFile))
+		return 0;
 
 #if 0
 	/* Initialize the SDL library */
@@ -430,12 +430,16 @@ try
 
 	registerWindowForFatal();
 
-	if (!resizeBackdrop(winWidth, winHeight)) return fatal("Couldn't allocate memory for backdrop");
+	if (!resizeBackdrop(winWidth, winHeight))
+		return fatal("Couldn't allocate memory for backdrop");
 
 	blankScreen(0, 0, winWidth, winHeight);
-	if (!initPeople()) return fatal("Couldn't initialise people stuff");
-	if (!initFloor()) return fatal("Couldn't initialise floor stuff");
-	if (!initObjectTypes()) return fatal("Couldn't initialise object type stuff");
+	if (!initPeople())
+		return fatal("Couldn't initialise people stuff");
+	if (!initFloor())
+		return fatal("Couldn't initialise floor stuff");
+	if (!initObjectTypes())
+		return fatal("Couldn't initialise object type stuff");
 	initSpeech();
 	initStatusBar();
 	resetRandW();
@@ -473,7 +477,9 @@ try
 		walkAllPeople();
 		handleInput();
 		sludgeDisplay();
-		g_system->copyRectToScreen(backdropSurface.getPixels(), backdropSurface.pitch, 0, 0, backdropSurface.w, backdropSurface.h);
+		g_system->copyRectToScreen(backdropSurface.getPixels(),
+				backdropSurface.pitch, 0, 0, backdropSurface.w,
+				backdropSurface.h);
 		g_system->updateScreen();
 #if 0
 		Wait_Frame();
@@ -509,4 +515,5 @@ catch (std::exception &ex) { //NOTE by reference, not value
 }
 #endif
 
-} // End of namespace Sludge
+}
+ // End of namespace Sludge
diff --git a/engines/sludge/memwatch.cpp b/engines/sludge/memwatch.cpp
index 34e8605..f9148c5 100644
--- a/engines/sludge/memwatch.cpp
+++ b/engines/sludge/memwatch.cpp
@@ -43,7 +43,7 @@ void outputKnownMem() {
 
 void adding(void *mem) {
 	allKnownMem[allKnownNum] = mem;
-	allKnownNum ++;
+	allKnownNum++;
 
 	outputKnownMem();
 	if (allKnownNum == 3000) {
@@ -55,8 +55,8 @@ void adding(void *mem) {
 }
 
 void deleting(void *mem) {
-	allKnownNum --;
-	for (int i = 0; i <= allKnownNum; i ++) {
+	allKnownNum--;
+	for (int i = 0; i <= allKnownNum; i++) {
 		if (allKnownMem[i] == mem) {
 			allKnownMem[i] = allKnownMem[allKnownNum];
 			outputKnownMem();
diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp
index 8bb0d77..754f22c 100644
--- a/engines/sludge/moreio.cpp
+++ b/engines/sludge/moreio.cpp
@@ -58,8 +58,8 @@ int get2bytes(Common::SeekableReadStream *stream) {
 }
 
 void put2bytes(int numtoput, Common::WriteStream *stream) {
-	putch((char)(numtoput / 256), stream);
-	putch((char)(numtoput % 256), stream);
+	putch((char) (numtoput / 256), stream);
+	putch((char) (numtoput % 256), stream);
 }
 
 void writeString(char *s, Common::WriteStream *stream) {
@@ -70,7 +70,6 @@ void writeString(char *s, Common::WriteStream *stream) {
 	}
 }
 
-
 char *readString(Common::SeekableReadStream *stream) {
 	int a, len = get2bytes(stream);
 	char *s = new char[len + 1];
@@ -78,7 +77,7 @@ char *readString(Common::SeekableReadStream *stream) {
 		return NULL;
 	}
 	for (a = 0; a < len; ++a) {
-		s[a] = (char)(getch(stream) - 1);
+		s[a] = (char) (getch(stream) - 1);
 	}
 	s[len] = 0;
 	debug(kSludgeDebugDataLoad, "Read string of length %i: %s", len, s);
@@ -99,11 +98,10 @@ float floatSwap(float f) {
 	return dat2.f;
 }
 
-
 float getFloat(Common::SeekableReadStream *stream) {
 	float f;
 	size_t bytes_read = stream->read(&f, sizeof(float));
-			//fread(& f, sizeof(float), 1, fp);
+	//fread(& f, sizeof(float), 1, fp);
 	if (bytes_read != sizeof(float) && stream->err()) {
 		debug("Reading error in getFloat.\n");
 	}
@@ -119,7 +117,7 @@ void putFloat(float f, Common::WriteStream *stream) {
 #ifdef  __BIG_ENDIAN__
 	f = floatSwap(f);
 #endif
-	stream->write(&f,sizeof(float));
+	stream->write(&f, sizeof(float));
 	//fwrite(& f, sizeof(float), 1, fp);
 }
 
@@ -132,7 +130,6 @@ short shortSwap(short s) {
 	return (b1 << 8) + b2;
 }
 
-
 short getSigned(Common::SeekableReadStream *stream) {
 	short f;
 	size_t bytes_read = stream->read(&f, sizeof(short));
@@ -152,7 +149,6 @@ void putSigned(short f, Common::WriteStream *stream) {
 	stream->write(&f, sizeof(short));
 }
 
-
 // The following two functions treat signed integers as unsigned.
 // That's done on purpose.
 
@@ -169,7 +165,6 @@ int32_t get4bytes(Common::SeekableReadStream *stream) {
 	return x;
 }
 
-
 void put4bytes(unsigned int i, Common::WriteStream *stream) {
 	unsigned char f1, f2, f3, f4;
 
@@ -187,10 +182,12 @@ void put4bytes(unsigned int i, Common::WriteStream *stream) {
 }
 
 char *encodeFilename(char *nameIn) {
-	if (!nameIn) return NULL;
+	if (!nameIn)
+		return NULL;
 	if (allowAnyFilename) {
 		char *newName = new char[strlen(nameIn) * 2 + 1];
-		if (!checkNew(newName)) return NULL;
+		if (!checkNew(newName))
+			return NULL;
 
 		int i = 0;
 		while (*nameIn) {
@@ -241,7 +238,7 @@ char *encodeFilename(char *nameIn) {
 				break;
 			}
 			newName[i] = 0;
-			nameIn ++;
+			nameIn++;
 		}
 		return newName;
 	} else {
@@ -250,7 +247,8 @@ char *encodeFilename(char *nameIn) {
 #ifdef _WIN32
 			if (nameIn[a] == '/') nameIn[a] = '\\';
 #else
-			if (nameIn[a] == '\\') nameIn[a] = '/';
+			if (nameIn[a] == '\\')
+				nameIn[a] = '/';
 #endif
 		}
 
@@ -261,61 +259,62 @@ char *encodeFilename(char *nameIn) {
 char *decodeFilename(char *nameIn) {
 	if (allowAnyFilename) {
 		char *newName = new char[strlen(nameIn) + 1];
-		if (!checkNew(newName)) return NULL;
+		if (!checkNew(newName))
+			return NULL;
 
 		int i = 0;
-		while (* nameIn) {
-			if (* nameIn == '_') {
-				nameIn ++;
-				switch (* nameIn) {
+		while (*nameIn) {
+			if (*nameIn == '_') {
+				nameIn++;
+				switch (*nameIn) {
 				case 'L':
 					newName[i] = '<';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'G':
 					newName[i] = '>';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'P':
 					newName[i] = '|';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'U':
 					newName[i] = '_';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'S':
 					newName[i] = '\"';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'B':
 					newName[i] = '\\';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'F':
 					newName[i] = '/';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'C':
 					newName[i] = ':';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'A':
 					newName[i] = '*';
-					nameIn ++;
+					nameIn++;
 					break;
 				case 'Q':
 					newName[i] = '?';
-					nameIn ++;
+					nameIn++;
 					break;
 				default:
 					newName[i] = '_';
 				}
 			} else {
 				newName[i] = *nameIn;
-				nameIn ++;
+				nameIn++;
 			}
-			i ++;
+			i++;
 
 		}
 		newName[i] = 0;
diff --git a/engines/sludge/movie.cpp b/engines/sludge/movie.cpp
index 3f02f73..cd4ef1b 100644
--- a/engines/sludge/movie.cpp
+++ b/engines/sludge/movie.cpp
@@ -71,7 +71,7 @@ bool handleInput();
 void playMovieStream(int a);
 #if 0
 int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
-                   ALuint(*callback)(void *userdata, ALubyte *data, ALuint bytes));
+		ALuint(*callback)(void *userdata, ALubyte *data, ALuint bytes));
 #endif
 
 movieStates movieIsPlaying = nothing;
@@ -85,14 +85,14 @@ typedef struct audioBuffers {
 	unsigned int size;
 	audioBuffers *next;
 	Uint32 time_ms;
-} audioBuffers;
+}audioBuffers;
 
 typedef struct audioQueue {
 	audioBuffers *first, *last;
 	int size;
 	SDL_mutex *mutex;
 	SDL_cond *cond;
-} audioQueue;
+}audioQueue;
 
 audioQueue audioQ;
 
@@ -115,18 +115,17 @@ typedef struct videoBuffers {
 	videoBuffers *next;
 	GLsizei w, h;
 	Uint32 time_ms;
-} videoBuffers;
+}videoBuffers;
 
 typedef struct videoQueue {
 	videoBuffers *first, *last;
 	int size;
 	SDL_mutex *mutex;
 	SDL_cond *cond;
-} videoQueue;
+}videoQueue;
 
 videoQueue videoQ;
 
-
 void audio_queue_init(audioQueue *q) {
 	memset(q, 0, sizeof(audioQueue));
 
@@ -138,7 +137,7 @@ int audio_queue_put(audioQueue *q, char *buffer, unsigned int size, long long ti
 
 	audioBuffers *audioBuf = new audioBuffers;
 	if (!audioBuf)
-		return -1;
+	return -1;
 	audioBuf->buffer = buffer;
 	audioBuf->next = NULL;
 	audioBuf->size = size;
@@ -147,9 +146,9 @@ int audio_queue_put(audioQueue *q, char *buffer, unsigned int size, long long ti
 	SDL_LockMutex(q->mutex);
 
 	if (!q->last)
-		q->first = audioBuf;
+	q->first = audioBuf;
 	else
-		q->last->next = audioBuf;
+	q->last->next = audioBuf;
 	q->last = audioBuf;
 	q->size ++;
 	SDL_CondSignal(q->cond);
@@ -161,7 +160,6 @@ int audio_queue_put(audioQueue *q, char *buffer, unsigned int size, long long ti
 inline static int audio_queue_get(audioQueue *q, char **buffer) {
 	int ret = 0;
 
-
 	audioBuffers *audioBuf;
 
 	SDL_LockMutex(q->mutex);
@@ -176,7 +174,7 @@ inline static int audio_queue_get(audioQueue *q, char **buffer) {
 
 		q->first = audioBuf->next;
 		if (!q->first)
-			q->last = NULL;
+		q->last = NULL;
 		q->size--;
 		*buffer = audioBuf->buffer;
 		ret = audioBuf->size;
@@ -194,14 +192,14 @@ void video_queue_init(videoQueue *q) {
 	q->cond = SDL_CreateCond();
 }
 int video_queue_put(videoQueue *q, GLubyte *ytex,
-                    GLubyte *utex,
-                    GLubyte *vtex,
-                    GLsizei w, GLsizei h,
-                    long long time_ms) {
+		GLubyte *utex,
+		GLubyte *vtex,
+		GLsizei w, GLsizei h,
+		long long time_ms) {
 
 	videoBuffers *videoBuf = new videoBuffers;
 	if (!videoBuf)
-		return -1;
+	return -1;
 	videoBuf->ytex = ytex;
 	videoBuf->utex = utex;
 	videoBuf->vtex = vtex;
@@ -213,9 +211,9 @@ int video_queue_put(videoQueue *q, GLubyte *ytex,
 	SDL_LockMutex(q->mutex);
 
 	if (!q->last)
-		q->first = videoBuf;
+	q->first = videoBuf;
 	else
-		q->last->next = videoBuf;
+	q->last->next = videoBuf;
 	q->last = videoBuf;
 	q->size ++;
 	SDL_CondSignal(q->cond);
@@ -224,10 +222,10 @@ int video_queue_put(videoQueue *q, GLubyte *ytex,
 	return 0;
 }
 inline static int video_queue_get(videoQueue *q,
-                                  GLubyte **ytex,
-                                  GLubyte **utex,
-                                  GLubyte **vtex,
-                                  GLsizei *w, GLsizei *h) {
+		GLubyte **ytex,
+		GLubyte **utex,
+		GLubyte **vtex,
+		GLsizei *w, GLsizei *h) {
 	videoBuffers *videoBuf;
 	int ret = 0;
 
@@ -237,7 +235,7 @@ inline static int video_queue_get(videoQueue *q,
 	if (videoBuf) {
 		q->first = videoBuf->next;
 		if (!q->first)
-			q->last = NULL;
+		q->last = NULL;
 		q->size--;
 		*ytex = videoBuf->ytex;
 		*utex = videoBuf->utex;
@@ -279,10 +277,10 @@ void setMovieViewport() {
 	glViewport(vpOffsetX, vpOffsetY, vpWidth, vpHeight);
 #endif
 	const GLfloat bPMVMatrix[] = {
-		2.0f / 640.f,          .0,   .0,  .0,
-		.0, -2.0f / 400.f,   .0,  .0,
-		.0,          .0, 1.0f,  .0,
-		-1.0,        1.0f,   .0, 1.0f
+		2.0f / 640.f, .0, .0, .0,
+		.0, -2.0f / 400.f, .0, .0,
+		.0, .0, 1.0f, .0,
+		-1.0, 1.0f, .0, 1.0f
 
 	};
 	for (int i = 0; i < 16; i++) {
@@ -341,9 +339,9 @@ ALuint feedAudio(void *userdata, ALubyte *data, ALuint length) {
 	fakeAudio = false;
 
 	if (length > bufSize - bufOffset)
-		bufLen = bufSize - bufOffset;
+	bufLen = bufSize - bufOffset;
 	else
-		bufLen = length;
+	bufLen = length;
 
 	memcpy(data, buffer + bufOffset, bufLen);
 
@@ -364,13 +362,13 @@ ALuint feedAudio(void *userdata, ALubyte *data, ALuint length) {
 int playMovie(int fileNumber) {
 #if 0
 	if (specialSettings & SPECIAL_SILENT)
-		return 0;
+	return 0;
 
 	if (movieIsPlaying) return 0;
 
 	movieSoundPlaying = false;
 
-	vpx_codec_ctx_t  codec;
+	vpx_codec_ctx_t codec;
 
 	float pausefade = 1.0;
 
@@ -396,7 +394,7 @@ int playMovie(int fileNumber) {
 		fatal("Movie error: Segment::CreateInstance() failed.\n");
 	}
 
-	ret  = pSegment->Load();
+	ret = pSegment->Load();
 	if (ret < 0) {
 		fatal("Movie error: Segment::Load() failed.\n");
 	}
@@ -413,7 +411,7 @@ int playMovie(int fileNumber) {
 	unsigned long i = 0;
 	const unsigned long j = pTracks->GetTracksCount();
 
-	enum { VIDEO_TRACK = 1, AUDIO_TRACK = 2 };
+	enum {VIDEO_TRACK = 1, AUDIO_TRACK = 2};
 	int videoTrack = -1;
 	int audioTrack = -1;
 	long long audioBitDepth;
@@ -427,7 +425,7 @@ int playMovie(int fileNumber) {
 		const Track *const pTrack = pTracks->GetTrackByIndex(i++);
 
 		if (pTrack == NULL)
-			continue;
+		continue;
 
 		const long long trackType = pTrack->GetType();
 		//const unsigned long long trackUid = pTrack->GetUid();
@@ -436,15 +434,15 @@ int playMovie(int fileNumber) {
 		if (trackType == VIDEO_TRACK && videoTrack < 0) {
 			videoTrack = pTrack->GetNumber();
 			const VideoTrack *const pVideoTrack =
-			    static_cast<const VideoTrack *>(pTrack);
+			static_cast<const VideoTrack *>(pTrack);
 
-			const long long width =  pVideoTrack->GetWidth();
+			const long long width = pVideoTrack->GetWidth();
 			const long long height = pVideoTrack->GetHeight();
 
 			const double rate = pVideoTrack->GetFrameRate();
 
 			if (rate > 0)
-				Init_Special_Timer(rate);
+			Init_Special_Timer(rate);
 
 			movieAspect = (float)width / height;
 		}
@@ -452,9 +450,9 @@ int playMovie(int fileNumber) {
 		if (trackType == AUDIO_TRACK && audioTrack < 0) {
 			audioTrack = pTrack->GetNumber();
 			const AudioTrack *const pAudioTrack =
-			    static_cast<const AudioTrack *>(pTrack);
+			static_cast<const AudioTrack *>(pTrack);
 
-			audioChannels =  pAudioTrack->GetChannels();
+			audioChannels = pAudioTrack->GetChannels();
 			audioBitDepth = pAudioTrack->GetBitDepth();
 			audioSampleRate = pAudioTrack->GetSamplingRate();
 
@@ -503,17 +501,17 @@ int playMovie(int fileNumber) {
 				oggPacket.b_o_s = oggPacket.packetno == 0;
 				r = vorbis_synthesis_headerin(&vorbisInfo, &vorbisComment, &oggPacket);
 				if (r)
-					fprintf(stderr, "vorbis_synthesis_headerin failed, error: %d", r);
+				fprintf(stderr, "vorbis_synthesis_headerin failed, error: %d", r);
 				oggPacket.packetno++;
 				p += sizes[i];
 			}
 
 			r = vorbis_synthesis_init(&vorbisDspState, &vorbisInfo);
 			if (r)
-				fprintf(stderr, "vorbis_synthesis_init failed, error: %d", r);
+			fprintf(stderr, "vorbis_synthesis_init failed, error: %d", r);
 			r = vorbis_block_init(&vorbisDspState, &vorbisBlock);
 			if (r)
-				fprintf(stderr, "vorbis_block_init failed, error: %d", r);
+			fprintf(stderr, "vorbis_block_init failed, error: %d", r);
 
 			ALenum audioFormat = alureGetSampleFormat(audioChannels, 16, 0);
 			movieAudioIndex = initMovieSound(fileNumber, audioFormat, audioChannels, (ALuint) audioSampleRate, feedAudio);
@@ -527,10 +525,10 @@ int playMovie(int fileNumber) {
 	}
 
 	if (videoTrack < 0)
-		fatal("Movie error: No video in movie file.");
+	fatal("Movie error: No video in movie file.");
 
 	if (audioTrack < 0)
-		fatal("Movie error: No sound found.");
+	fatal("Movie error: No sound found.");
 
 	video_queue_init(&videoQ);
 
@@ -540,11 +538,9 @@ int playMovie(int fileNumber) {
 		fatal("Movie error: Segment has no clusters.\n");
 	}
 
-
 	/* Initialize video codec */
 	if (vpx_codec_dec_init(&codec, interface, NULL, 0))
-		die_codec(&codec, "Failed to initialize decoder for movie.");
-
+	die_codec(&codec, "Failed to initialize decoder for movie.");
 
 	unsigned char *frame = new unsigned char[256 * 1024];
 	if (! checkNew(frame)) return false;
@@ -571,7 +567,7 @@ int playMovie(int fileNumber) {
 		}
 		pBlockEntry = pCluster->GetFirst();
 	}
-	const Block *pBlock  = pBlockEntry->GetBlock();
+	const Block *pBlock = pBlockEntry->GetBlock();
 	long long trackNum = pBlock->GetTrackNumber();
 	unsigned long tn = static_cast<unsigned long>(trackNum);
 	const Track *pTrack = pTracks->GetTrackByNumber(tn);
@@ -634,7 +630,7 @@ int playMovie(int fileNumber) {
 
 		checkInput();
 		if (weAreDoneSoQuit)
-			break;
+		break;
 		handleInput();
 
 		if (movieIsPlaying && (! movieIsEnding) && (videoQ.size < 100 || audioQ.size < 100)) {
@@ -652,7 +648,7 @@ int playMovie(int fileNumber) {
 						}
 						pBlockEntry = pCluster->GetFirst();
 					}
-					pBlock  = pBlockEntry->GetBlock();
+					pBlock = pBlockEntry->GetBlock();
 					trackNum = pBlock->GetTrackNumber();
 					tn = static_cast<unsigned long>(trackNum);
 					pTrack = pTracks->GetTrackByNumber(tn);
@@ -673,28 +669,27 @@ int playMovie(int fileNumber) {
 					if (! checkNew(frame)) return 0;
 				}
 				/*
-				                fprintf (stderr, "Block :%s,%s,%15lld\n",
-				                 (trackType == VIDEO_TRACK) ? "V" : "A",
-				                 pBlock->IsKey() ? "I" : "P",
-				                 time_ns);
+				 fprintf (stderr, "Block :%s,%s,%15lld\n",
+				 (trackType == VIDEO_TRACK) ? "V" : "A",
+				 pBlock->IsKey() ? "I" : "P",
+				 time_ns);
 				 */
 
 				if (trackNum == videoTrack) {
 
 					theFrame.Read(&reader, frame);
 
-
 					/* Decode the frame */
 					if (vpx_codec_decode(&codec, frame, size, NULL, 0))
-						die_codec(&codec, "Failed to decode frame");
+					die_codec(&codec, "Failed to decode frame");
 
 					// Let's decode an image frame!
-					vpx_codec_iter_t  iter = NULL;
-					vpx_image_t      *img;
+					vpx_codec_iter_t iter = NULL;
+					vpx_image_t *img;
 					/* Get frame data */
 					while ((img = vpx_codec_get_frame(&codec, &iter))) {
 						if (img->fmt != VPX_IMG_FMT_I420)
-							fatal("Movie error. The movie is not in I420 colour format, which is the only one I can hanlde at the moment.");
+						fatal("Movie error. The movie is not in I420 colour format, which is the only one I can hanlde at the moment.");
 
 						unsigned int y;
 
@@ -707,7 +702,7 @@ int playMovie(int fileNumber) {
 							utex = new GLubyte [(img->d_w >> 1) * (img->d_h >> 1)];
 							vtex = new GLubyte [(img->d_w >> 1) * (img->d_h >> 1)];
 							if (!ytex || !utex || !vtex)
-								fatal(ERROR_OUT_OF_MEMORY);
+							fatal(ERROR_OUT_OF_MEMORY);
 
 						}
 
@@ -728,8 +723,7 @@ int playMovie(int fileNumber) {
 						}
 
 						video_queue_put(&videoQ, ytex, utex, vtex,
-						                img->d_w, img->d_h, time_ns / 1000000);
-
+								img->d_w, img->d_h, time_ns / 1000000);
 
 					}
 
@@ -744,7 +738,7 @@ int playMovie(int fileNumber) {
 						oggPacket.granulepos = -1;
 						if (! vorbis_synthesis(&vorbisBlock, &oggPacket)) {
 							if (vorbis_synthesis_blockin(&vorbisDspState, &vorbisBlock))
-								fprintf(stderr, "Vorbis Synthesis block in error.\n");
+							fprintf(stderr, "Vorbis Synthesis block in error.\n");
 
 						} else {
 							fprintf(stderr, "Vorbis Synthesis error.\n");
@@ -771,12 +765,12 @@ int playMovie(int fileNumber) {
 									int off = (sgned ? 0 : 128);
 									vorbis_fpu_setround(&fpu);
 									for (j = 0; j < numSamples; j++)
-										for (i = 0; i < audioChannels; i++) {
-											val = vorbis_ftoi(pcm[i][j] * 128.f);
-											if (val > 127)val = 127;
-											else if (val < -128)val = -128;
-											*buffer++ = val + off;
-										}
+									for (i = 0; i < audioChannels; i++) {
+										val = vorbis_ftoi(pcm[i][j] * 128.f);
+										if (val > 127)val = 127;
+										else if (val < -128)val = -128;
+										*buffer++ = val + off;
+									}
 									vorbis_fpu_restore(fpu);
 								} else {
 									int off = (sgned ? 0 : 32768);
@@ -835,7 +829,7 @@ int playMovie(int fileNumber) {
 				++frameCounter;
 
 			} else {
-movieHasEnded:
+				movieHasEnded:
 				movieIsEnding = 1;
 			}
 		}
@@ -865,30 +859,29 @@ movieHasEnded:
 						if (! vTextureName) glGenTextures(1, &vTextureName);
 						glBindTexture(GL_TEXTURE_2D, yTextureName);
 						glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0,
-						             GL_ALPHA, GL_UNSIGNED_BYTE, ytex);
+								GL_ALPHA, GL_UNSIGNED_BYTE, ytex);
 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 						glBindTexture(GL_TEXTURE_2D, uTextureName);
 						glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w >> 1, h >> 1, 0,
-						             GL_ALPHA, GL_UNSIGNED_BYTE, utex);
+								GL_ALPHA, GL_UNSIGNED_BYTE, utex);
 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 						glBindTexture(GL_TEXTURE_2D, vTextureName);
 						glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w >> 1, h >> 1, 0,
-						             GL_ALPHA, GL_UNSIGNED_BYTE, vtex);
+								GL_ALPHA, GL_UNSIGNED_BYTE, vtex);
 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
-
 						glBindTexture(GL_TEXTURE_2D, yTextureName);
 						glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h,
-						                GL_ALPHA, GL_UNSIGNED_BYTE, ytex);
+								GL_ALPHA, GL_UNSIGNED_BYTE, ytex);
 						glBindTexture(GL_TEXTURE_2D, uTextureName);
 						glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w >> 1, h >> 1,
-						                GL_ALPHA, GL_UNSIGNED_BYTE, utex);
+								GL_ALPHA, GL_UNSIGNED_BYTE, utex);
 						glBindTexture(GL_TEXTURE_2D, vTextureName);
 						glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w >> 1, h >> 1,
-						                GL_ALPHA, GL_UNSIGNED_BYTE, vtex);
+								GL_ALPHA, GL_UNSIGNED_BYTE, vtex);
 
 						delete [] ytex;
 						delete [] utex;
@@ -946,7 +939,6 @@ movieHasEnded:
 
 				glUseProgram(0);
 
-
 				glDisable(GL_BLEND);
 
 				Wait_Frame();
@@ -971,10 +963,8 @@ movieHasEnded:
 	for (int i = 0; i < 10; i++) Wait_Frame();
 	huntKillFreeSound(fileNumber);
 
-
 	if (vpx_codec_destroy(&codec))
-		die_codec(&codec, "Failed to destroy codec");
-
+	die_codec(&codec, "Failed to destroy codec");
 
 	vorbis_dsp_clear(&vorbisDspState);
 	vorbis_block_clear(&vorbisBlock);
diff --git a/engines/sludge/movie.h b/engines/sludge/movie.h
index 100439a..c34322f 100644
--- a/engines/sludge/movie.h
+++ b/engines/sludge/movie.h
@@ -28,9 +28,7 @@ namespace Sludge {
  movieIsPlaying tracks the state of movie playing
  */
 enum movieStates {
-	nothing = 0,
-	playing,
-	paused
+	nothing = 0, playing, paused
 };
 extern movieStates movieIsPlaying;
 
diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp
index 5c8a36d..477a7f9 100644
--- a/engines/sludge/newfatal.cpp
+++ b/engines/sludge/newfatal.cpp
@@ -41,7 +41,9 @@ namespace Sludge {
 const char emergencyMemoryMessage[] = "Out of memory displaying error message!";
 
 static char *fatalMessage = NULL;
-static char *fatalInfo = joinStrings("Initialisation error! Something went wrong before we even got started!", "");
+static char *fatalInfo =
+		joinStrings("Initialisation error! Something went wrong before we even got started!",
+					"");
 
 extern int numResourceNames /* = 0*/;
 extern char * *allResourceNames /*= NULL*/;
@@ -49,14 +51,18 @@ extern char * *allResourceNames /*= NULL*/;
 int resourceForFatal = -1;
 
 const char *resourceNameFromNum(int i) {
-	if (i == -1) return NULL;
-	if (numResourceNames == 0) return "RESOURCE";
-	if (i < numResourceNames) return allResourceNames[i];
+	if (i == -1)
+		return NULL;
+	if (numResourceNames == 0)
+		return "RESOURCE";
+	if (i < numResourceNames)
+		return allResourceNames[i];
 	return "Unknown resource";
 }
 
 bool hasFatal() {
-	if (fatalMessage) return true;
+	if (fatalMessage)
+		return true;
 	return false;
 }
 
@@ -77,7 +83,10 @@ void warning(const char *l) {
 
 void registerWindowForFatal() {
 	delete fatalInfo;
-	fatalInfo = joinStrings("There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.", "");
+	fatalInfo =
+			joinStrings(
+					"There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.",
+					"");
 }
 
 #if 0
@@ -93,8 +102,8 @@ int inFatal(const char *str) {
 	}
 #endif
 	fatalMessage = copyString(str);
-	if (fatalMessage == NULL) fatalMessage = copyString("Out of memory");
-
+	if (fatalMessage == NULL)
+		fatalMessage = copyString("Out of memory");
 
 	killSoundStuff();
 
@@ -120,8 +129,10 @@ int checkNew(const void *mem) {
 
 void setFatalInfo(const char *userFunc, const char *BIF) {
 	delete fatalInfo;
-	fatalInfo = new char [strlen(userFunc) + strlen(BIF) + 38];
-	if (fatalInfo) sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, BIF);
+	fatalInfo = new char[strlen(userFunc) + strlen(BIF) + 38];
+	if (fatalInfo)
+		sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc,
+				BIF);
 	debug("%s", fatalInfo);
 }
 
@@ -132,17 +143,20 @@ void setResourceForFatal(int n) {
 int fatal(const char *str1) {
 	if (numResourceNames && resourceForFatal != -1) {
 		const char *r = resourceNameFromNum(resourceForFatal);
-		char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) + 14];
+		char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo)
+				+ 14];
 		if (checkNew(newStr)) {
 			sprintf(newStr, "%s\nResource: %s\n\n%s", fatalInfo, r, str1);
 			inFatal(newStr);
-		} else fatal(emergencyMemoryMessage);
+		} else
+			fatal(emergencyMemoryMessage);
 	} else {
 		char *newStr = new char[strlen(str1) + strlen(fatalInfo) + 3];
 		if (checkNew(newStr)) {
 			sprintf(newStr, "%s\n\n%s", fatalInfo, str1);
 			inFatal(newStr);
-		} else fatal(emergencyMemoryMessage);
+		} else
+			fatal(emergencyMemoryMessage);
 	}
 	return 0;
 }
@@ -152,7 +166,8 @@ int fatal(const char *str1, const char *str2) {
 	if (checkNew(newStr)) {
 		sprintf(newStr, "%s %s", str1, str2);
 		fatal(newStr);
-	} else fatal(emergencyMemoryMessage);
+	} else
+		fatal(emergencyMemoryMessage);
 	return 0;
 }
 
diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp
index ba70977..5f82fb0 100644
--- a/engines/sludge/objtypes.cpp
+++ b/engines/sludge/objtypes.cpp
@@ -42,8 +42,9 @@ objectType *findObjectType(int i) {
 	objectType *huntType = allObjectTypes;
 
 	while (huntType) {
-		if (huntType -> objectNum == i) return huntType;
-		huntType = huntType -> next;
+		if (huntType->objectNum == i)
+			return huntType;
+		huntType = huntType->next;
 	}
 
 	return loadObjectType(i);
@@ -56,13 +57,13 @@ objectType *loadObjectType(int i) {
 	if (checkNew(newType)) {
 		if (openObjectSlice(i)) {
 			nameNum = get2bytes(bigDataFile);
-			newType -> r = (byte) getch(bigDataFile);
-			newType -> g = (byte) getch(bigDataFile);
-			newType -> b = (byte) getch(bigDataFile);
-			newType -> speechGap = getch(bigDataFile);
-			newType -> walkSpeed = getch(bigDataFile);
-			newType -> wrapSpeech = get4bytes(bigDataFile);
-			newType -> spinSpeed = get2bytes(bigDataFile);
+			newType->r = (byte) getch(bigDataFile);
+			newType->g = (byte) getch(bigDataFile);
+			newType->b = (byte) getch(bigDataFile);
+			newType->speechGap = getch(bigDataFile);
+			newType->walkSpeed = getch(bigDataFile);
+			newType->wrapSpeech = get4bytes(bigDataFile);
+			newType->spinSpeed = get2bytes(bigDataFile);
 
 			if (gameVersion >= VERSION(1, 6)) {
 				// aaLoad
@@ -72,13 +73,14 @@ objectType *loadObjectType(int i) {
 			}
 
 			if (gameVersion >= VERSION(1, 4)) {
-				newType -> flags = get2bytes(bigDataFile);
+				newType->flags = get2bytes(bigDataFile);
 			} else {
-				newType -> flags = 0;
+				newType->flags = 0;
 			}
 
-			newType -> numCom = get2bytes(bigDataFile);
-			newType -> allCombis = (newType -> numCom) ? new combination[newType -> numCom] : NULL;
+			newType->numCom = get2bytes(bigDataFile);
+			newType->allCombis =
+					(newType->numCom) ? new combination[newType->numCom] : NULL;
 
 #if DEBUG_COMBINATIONS
 			FILE *callEventLog = fopen("callEventLog.txt", "at");
@@ -87,9 +89,9 @@ objectType *loadObjectType(int i) {
 			}
 #endif
 
-			for (a = 0; a < newType -> numCom; a ++) {
-				newType -> allCombis[a].withObj = get2bytes(bigDataFile);
-				newType -> allCombis[a].funcNum = get2bytes(bigDataFile);
+			for (a = 0; a < newType->numCom; a++) {
+				newType->allCombis[a].withObj = get2bytes(bigDataFile);
+				newType->allCombis[a].funcNum = get2bytes(bigDataFile);
 #if DEBUG_COMBINATIONS
 				if (callEventLog) {
 					fprintf(callEventLog, "%d(%d) ", newType -> allCombis[a].withObj, newType -> allCombis[a].funcNum);
@@ -103,9 +105,9 @@ objectType *loadObjectType(int i) {
 			}
 #endif
 			finishAccess();
-			newType -> screenName = getNumberedString(nameNum);
-			newType -> objectNum = i;
-			newType -> next = allObjectTypes;
+			newType->screenName = getNumberedString(nameNum);
+			newType->objectNum = i;
+			newType->next = allObjectTypes;
 			allObjectTypes = newType;
 			return newType;
 		}
@@ -116,14 +118,14 @@ objectType *loadObjectType(int i) {
 
 objectType *loadObjectRef(Common::SeekableReadStream *stream) {
 	objectType *r = loadObjectType(get2bytes(stream));
-	delete r -> screenName;
-	r -> screenName = readString(stream);
+	delete r->screenName;
+	r->screenName = readString(stream);
 	return r;
 }
 
 void saveObjectRef(objectType *r, Common::WriteStream *stream) {
-	put2bytes(r -> objectNum, stream);
-	writeString(r -> screenName, stream);
+	put2bytes(r->objectNum, stream);
+	writeString(r->screenName, stream);
 }
 
 int getCombinationFunction(int withThis, int thisObject) {
@@ -137,9 +139,9 @@ int getCombinationFunction(int withThis, int thisObject) {
 	}
 #endif
 
-	for (i = 0; i < obj -> numCom; i ++) {
-		if (obj -> allCombis[i].withObj == withThis) {
-			num = obj -> allCombis[i].funcNum;
+	for (i = 0; i < obj->numCom; i++) {
+		if (obj->allCombis[i].withObj == withThis) {
+			num = obj->allCombis[i].funcNum;
 			break;
 		}
 	}
@@ -155,21 +157,21 @@ int getCombinationFunction(int withThis, int thisObject) {
 }
 
 void removeObjectType(objectType *oT) {
-	objectType * * huntRegion = & allObjectTypes;
+	objectType * * huntRegion = &allObjectTypes;
 
-	while (* huntRegion) {
-		if ((* huntRegion) == oT) {
+	while (*huntRegion) {
+		if ((*huntRegion) == oT) {
 //			FILE * debuggy2 = fopen ("debug.txt", "at");
 //			fprintf (debuggy2, "DELETING OBJECT TYPE: %p %s\n", oT, oT -> screenName);
 //			fclose (debuggy2);
 
-			* huntRegion = oT -> next;
-			delete oT -> allCombis;
-			delete oT -> screenName;
+			*huntRegion = oT->next;
+			delete oT->allCombis;
+			delete oT->screenName;
 			delete oT;
 			return;
 		} else {
-			huntRegion = & ((* huntRegion) -> next);
+			huntRegion = &((*huntRegion)->next);
 		}
 	}
 	fatal("Can't delete object type: bad pointer");
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index 6430d35..93f1d6c 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -71,7 +71,8 @@ inline int TF_abs(int a) {
 }
 
 void setFrames(onScreenPerson &m, int a) {
-	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
+	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections)
+			+ m.direction];
 }
 
 personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
@@ -85,15 +86,17 @@ personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
 	int a = num, frameNum, howMany;
 
 	while (a) {
-		a --;
+		a--;
 		newP->frames[a].noise = 0;
 		if (stacky->thisVar.varType == SVT_FILE) {
 			newP->frames[a].noise = stacky->thisVar.varData.intValue;
 		} else if (stacky->thisVar.varType == SVT_FUNC) {
-			newP->frames[a].noise = - stacky->thisVar.varData.intValue;
+			newP->frames[a].noise = -stacky->thisVar.varData.intValue;
 		} else if (stacky->thisVar.varType == SVT_STACK) {
-			getValueType(frameNum, SVT_INT, stacky->thisVar.varData.theStack->first->thisVar);
-			getValueType(howMany, SVT_INT, stacky->thisVar.varData.theStack->first->next->thisVar);
+			getValueType(frameNum, SVT_INT,
+					stacky->thisVar.varData.theStack->first->thisVar);
+			getValueType(howMany, SVT_INT,
+					stacky->thisVar.varData.theStack->first->next->thisVar);
 		} else {
 			getValueType(frameNum, SVT_INT, stacky->thisVar);
 			howMany = 1;
@@ -107,32 +110,34 @@ personaAnimation *createPersonaAnim(int num, variableStack *&stacky) {
 }
 
 personaAnimation *makeNullAnim() {
-	personaAnimation *newAnim  = new personaAnimation;
-	if (!checkNew(newAnim)) return NULL;
+	personaAnimation *newAnim = new personaAnimation;
+	if (!checkNew(newAnim))
+		return NULL;
 
-
-	newAnim->theSprites       = NULL;
-	newAnim->numFrames        = 0;
-	newAnim->frames           = NULL;
+	newAnim->theSprites = NULL;
+	newAnim->numFrames = 0;
+	newAnim->frames = NULL;
 	return newAnim;
 }
 
 personaAnimation *copyAnim(personaAnimation *orig) {
 	int num = orig->numFrames;
 
-	personaAnimation *newAnim  = new personaAnimation;
-	if (!checkNew(newAnim)) return NULL;
+	personaAnimation *newAnim = new personaAnimation;
+	if (!checkNew(newAnim))
+		return NULL;
 
 	// Copy the easy bits...
-	newAnim->theSprites       = orig->theSprites;
-	newAnim->numFrames        = num;
+	newAnim->theSprites = orig->theSprites;
+	newAnim->numFrames = num;
 
 	if (num) {
 
 		// Argh!Frames!We need a whole NEW array of animFrame structures...
 
 		newAnim->frames = new animFrame[num];
-		if (!checkNew(newAnim->frames)) return NULL;
+		if (!checkNew(newAnim->frames))
+			return NULL;
 
 		for (int a = 0; a < num; ++a) {
 			newAnim->frames[a].frameNum = orig->frames[a].frameNum;
@@ -161,7 +166,8 @@ void turnMeAngle(onScreenPerson *thisPerson, int direc) {
 	int d = thisPerson->myPersona->numDirections;
 	thisPerson->angle = direc;
 	direc += (180 / d) + 180 + thisPerson->angleOffset;
-	while (direc >= 360) direc -= 360;
+	while (direc >= 360)
+		direc -= 360;
 	thisPerson->direction = (direc * d) / 360;
 }
 
@@ -176,14 +182,17 @@ bool initPeople() {
 
 void spinStep(onScreenPerson *thisPerson) {
 	int diff = (thisPerson->angle + 360) - thisPerson->wantAngle;
-	int eachSlice = thisPerson->spinSpeed ? thisPerson->spinSpeed : (360 / thisPerson->myPersona->numDirections);
+	int eachSlice =
+			thisPerson->spinSpeed ?
+					thisPerson->spinSpeed :
+					(360 / thisPerson->myPersona->numDirections);
 	while (diff > 180) {
 		diff -= 360;
 	}
 
 	if (diff >= eachSlice) {
 		turnMeAngle(thisPerson, thisPerson->angle - eachSlice);
-	} else if (diff <= - eachSlice) {
+	} else if (diff <= -eachSlice) {
 		turnMeAngle(thisPerson, thisPerson->angle + eachSlice);
 	} else {
 		turnMeAngle(thisPerson, thisPerson->wantAngle);
@@ -194,19 +203,22 @@ void spinStep(onScreenPerson *thisPerson) {
 void rethinkAngle(onScreenPerson *thisPerson) {
 	int d = thisPerson->myPersona->numDirections;
 	int direc = thisPerson->angle + (180 / d) + 180 + thisPerson->angleOffset;
-	while (direc >= 360) direc -= 360;
+	while (direc >= 360)
+		direc -= 360;
 	thisPerson->direction = (direc * d) / 360;
 }
 
 bool turnPersonToFace(int thisNum, int direc) {
 	onScreenPerson *thisPerson = findPerson(thisNum);
 	if (thisPerson) {
-		if (thisPerson->continueAfterWalking) abortFunction(thisPerson->continueAfterWalking);
+		if (thisPerson->continueAfterWalking)
+			abortFunction(thisPerson->continueAfterWalking);
 		thisPerson->continueAfterWalking = NULL;
 		thisPerson->walking = false;
 		thisPerson->spinning = false;
 		turnMeAngle(thisPerson, direc);
-		setFrames(* thisPerson, (thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND);
+		setFrames(*thisPerson,
+				(thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND);
 		return true;
 	}
 	return false;
@@ -216,7 +228,8 @@ bool setPersonExtra(int thisNum, int extra) {
 	onScreenPerson *thisPerson = findPerson(thisNum);
 	if (thisPerson) {
 		thisPerson->extra = extra;
-		if (extra & EXTRA_NOSCALE) thisPerson->scale = 1;
+		if (extra & EXTRA_NOSCALE)
+			thisPerson->scale = 1;
 		return true;
 	}
 	return false;
@@ -230,13 +243,15 @@ void setScale(short int h, short int d) {
 void moveAndScale(onScreenPerson &me, float x, float y) {
 	me.x = x;
 	me.y = y;
-	if (!(me.extra & EXTRA_NOSCALE) && scaleDivide) me.scale = (me.y - scaleHorizon) / scaleDivide;
+	if (!(me.extra & EXTRA_NOSCALE) && scaleDivide)
+		me.scale = (me.y - scaleHorizon) / scaleDivide;
 }
 
 onScreenPerson *findPerson(int v) {
 	onScreenPerson *thisPerson = allPeople;
 	while (thisPerson) {
-		if (v == thisPerson->thisType->objectNum) break;
+		if (v == thisPerson->thisType->objectNum)
+			break;
 		thisPerson = thisPerson->next;
 	}
 	return thisPerson;
@@ -244,12 +259,14 @@ onScreenPerson *findPerson(int v) {
 
 void movePerson(int x, int y, int objNum) {
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (moveMe) moveAndScale(* moveMe, x, y);
+	if (moveMe)
+		moveAndScale(*moveMe, x, y);
 }
 
 void setShown(bool h, int ob) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (moveMe) moveMe->show = h;
+	if (moveMe)
+		moveMe->show = h;
 }
 
 enum drawModes {
@@ -318,57 +335,57 @@ void setMyDrawMode(onScreenPerson *moveMe, int h) {
 		moveMe->colourmix = 255;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeShadow1:
+	case drawModeShadow1:
 		moveMe->r = moveMe->g = moveMe->b = 0;
 		moveMe->colourmix = 255;
 		moveMe->transparency = 64;
 		break;
-	case    drawModeShadow2:
+	case drawModeShadow2:
 		moveMe->r = moveMe->g = moveMe->b = 0;
 		moveMe->colourmix = 255;
 		moveMe->transparency = 128;
 		break;
-	case    drawModeShadow3:
+	case drawModeShadow3:
 		moveMe->r = moveMe->g = moveMe->b = 0;
 		moveMe->colourmix = 255;
 		moveMe->transparency = 192;
 		break;
-	case    drawModeFoggy3:
+	case drawModeFoggy3:
 		moveMe->r = moveMe->g = moveMe->b = 128;
 		moveMe->colourmix = 192;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeFoggy2:
+	case drawModeFoggy2:
 		moveMe->r = moveMe->g = moveMe->b = 128;
 		moveMe->colourmix = 128;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeFoggy1:
+	case drawModeFoggy1:
 		moveMe->r = moveMe->g = moveMe->b = 128;
 		moveMe->colourmix = 64;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeFoggy4:
+	case drawModeFoggy4:
 		moveMe->r = moveMe->g = moveMe->b = 128;
 		moveMe->colourmix = 255;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeGlow3:
+	case drawModeGlow3:
 		moveMe->r = moveMe->g = moveMe->b = 255;
 		moveMe->colourmix = 192;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeGlow2:
+	case drawModeGlow2:
 		moveMe->r = moveMe->g = moveMe->b = 255;
 		moveMe->colourmix = 128;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeGlow1:
+	case drawModeGlow1:
 		moveMe->r = moveMe->g = moveMe->b = 255;
 		moveMe->colourmix = 64;
 		moveMe->transparency = 0;
 		break;
-	case    drawModeGlow4:
+	case drawModeGlow4:
 		moveMe->r = moveMe->g = moveMe->b = 255;
 		moveMe->colourmix = 255;
 		moveMe->transparency = 0;
@@ -384,22 +401,27 @@ void setMyDrawMode(onScreenPerson *moveMe, int h) {
 
 void setDrawMode(int h, int ob) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (!moveMe) return;
+	if (!moveMe)
+		return;
 
 	setMyDrawMode(moveMe, h);
 }
 
 void setPersonTransparency(int ob, unsigned char x) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (!moveMe) return;
+	if (!moveMe)
+		return;
 
-	if (x > 254) x = 254;
+	if (x > 254)
+		x = 254;
 	moveMe->transparency = x;
 }
 
-void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix) {
+void setPersonColourise(int ob, unsigned char r, unsigned char g,
+		unsigned char b, unsigned char colourmix) {
 	onScreenPerson *moveMe = findPerson(ob);
-	if (!moveMe) return;
+	if (!moveMe)
+		return;
 
 	moveMe->r = r;
 	moveMe->g = g;
@@ -407,37 +429,36 @@ void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char
 	moveMe->colourmix = colourmix;
 }
 
-
-
 extern screenRegion *overRegion;
 
 void shufflePeople() {
-	onScreenPerson * * thisReference = & allPeople;
-	onScreenPerson *A, * B;
+	onScreenPerson * * thisReference = &allPeople;
+	onScreenPerson *A, *B;
 
-	if (!allPeople) return;
+	if (!allPeople)
+		return;
 
-	while ((* thisReference)->next) {
-		float y1 = (* thisReference)->y;
-		if ((* thisReference)->extra & EXTRA_FRONT) y1 += 1000;
+	while ((*thisReference)->next) {
+		float y1 = (*thisReference)->y;
+		if ((*thisReference)->extra & EXTRA_FRONT)
+			y1 += 1000;
 
-		float y2 = (* thisReference)->next->y;
-		if ((* thisReference)->next->extra & EXTRA_FRONT) y2 += 1000;
+		float y2 = (*thisReference)->next->y;
+		if ((*thisReference)->next->extra & EXTRA_FRONT)
+			y2 += 1000;
 
 		if (y1 > y2) {
-			A = (* thisReference);
-			B = (* thisReference)->next;
+			A = (*thisReference);
+			B = (*thisReference)->next;
 			A->next = B->next;
 			B->next = A;
-			(* thisReference) = B;
+			(*thisReference) = B;
 		} else {
-			thisReference = & ((* thisReference)->next);
+			thisReference = &((*thisReference)->next);
 		}
 	}
 }
 
-
-
 void drawPeople() {
 	shufflePeople();
 
@@ -453,15 +474,20 @@ void drawPeople() {
 				thisPerson->frameNum = 0;
 				thisPerson->frameTick = myAnim->frames[0].howMany;
 				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
-					startSound(myAnim->frames[thisPerson->frameNum].noise, false);
-					thisPerson->frameNum ++;
+					startSound(myAnim->frames[thisPerson->frameNum].noise,
+							false);
+					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
-					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+					thisPerson->frameTick =
+							thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 				} else if (myAnim->frames[thisPerson->frameNum].noise) {
-					startNewFunctionNum(- myAnim->frames[thisPerson->frameNum].noise, 0, NULL, noStack);
-					thisPerson->frameNum ++;
+					startNewFunctionNum(
+							-myAnim->frames[thisPerson->frameNum].noise, 0,
+							NULL, noStack);
+					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
-					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+					thisPerson->frameTick =
+							thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 				}
 			}
 			int fNumSign = myAnim->frames[thisPerson->frameNum].frameNum;
@@ -473,31 +499,39 @@ void drawPeople() {
 			}
 			if (m != 2) {
 				bool r = false;
-				r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m);
+				r = scaleSprite(myAnim->theSprites->bank.sprites[fNum],
+						myAnim->theSprites->bank.myPalette, thisPerson, m);
 				if (r) {
 					if (thisPerson->thisType->screenName[0]) {
-						if (personRegion.thisType != thisPerson->thisType) lastRegion = NULL;
+						if (personRegion.thisType != thisPerson->thisType)
+							lastRegion = NULL;
 						personRegion.thisType = thisPerson->thisType;
-						overRegion = & personRegion;
+						overRegion = &personRegion;
 					}
 				}
 			}
 		}
-		if (!-- thisPerson->frameTick) {
-			thisPerson->frameNum ++;
+		if (!--thisPerson->frameTick) {
+			thisPerson->frameNum++;
 			thisPerson->frameNum %= thisPerson->myAnim->numFrames;
-			thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+			thisPerson->frameTick =
+					thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 			if (thisPerson->show && myAnim && myAnim->frames) {
 				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
-					startSound(myAnim->frames[thisPerson->frameNum].noise, false);
-					thisPerson->frameNum ++;
+					startSound(myAnim->frames[thisPerson->frameNum].noise,
+							false);
+					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
-					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+					thisPerson->frameTick =
+							thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 				} else if (myAnim->frames[thisPerson->frameNum].noise) {
-					startNewFunctionNum(- myAnim->frames[thisPerson->frameNum].noise, 0, NULL, noStack);
-					thisPerson->frameNum ++;
+					startNewFunctionNum(
+							-myAnim->frames[thisPerson->frameNum].noise, 0,
+							NULL, noStack);
+					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
-					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
+					thisPerson->frameTick =
+							thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 				}
 			}
 		}
@@ -514,22 +548,27 @@ void makeSilent(onScreenPerson &me) {
 }
 
 bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
-	int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1,
-	    xTest2, yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF,
-	                                              thisDistance;
+	int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2,
+			yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF,
+			thisDistance;
 
 //	FILE * dbug = fopen ("debug_closest.txt", "at");
 //	fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY);
 
-	for (i = 0; i < currentFloor->numPolygons; i ++) {
+	for (i = 0; i < currentFloor->numPolygons; i++) {
 		oldJ = currentFloor->polygon[i].numVertices - 1;
-		for (j = 0; j < currentFloor->polygon[i].numVertices; j ++) {
+		for (j = 0; j < currentFloor->polygon[i].numVertices; j++) {
 //			fprintf (dbug, "Polygon %i, line %i... ", i, j);
-			xTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x;
-			yTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y;
-			xTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x;
-			yTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y;
-			closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, yTest2, setX, setY);
+			xTest1 =
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x;
+			yTest1 =
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y;
+			xTest2 =
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x;
+			yTest2 =
+					currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y;
+			closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2,
+					yTest2, setX, setY);
 //			fprintf (dbug, "closest point is %i, %i... ", closestX, closestY);
 			xTest1 = setX - closestX;
 			yTest1 = setY - closestY;
@@ -549,7 +588,8 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
 	}
 //	fclose (dbug);
 
-	if (gotPoly == -1) return false;
+	if (gotPoly == -1)
+		return false;
 	setX = gotX;
 	setY = gotY;
 	setPoly = gotPoly;
@@ -565,11 +605,13 @@ bool doBorderStuff(onScreenPerson *moveMe) {
 	} else {
 		// The section in which we need to be next...
 		int newPoly = currentFloor->matrix[moveMe->inPoly][moveMe->walkToPoly];
-		if (newPoly == -1) return false;
+		if (newPoly == -1)
+			return false;
 
 		// Grab the index of the second matching corner...
 		int ID, ID2;
-		if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly], currentFloor->polygon[newPoly], ID, ID2))
+		if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly],
+				currentFloor->polygon[newPoly], ID, ID2))
 			return fatal("Not a valid floor plan!");
 
 		// Remember that we're walking to the new polygon...
@@ -605,8 +647,8 @@ bool doBorderStuff(onScreenPerson *moveMe) {
 			dy23 *= dy23;
 			dy24 *= dy24;
 
-			if (sqrt((double) dx13 + dy13) + sqrt((double) dx23 + dy23) <
-			        sqrt((double) dx14 + dy14) + sqrt((double) dx24 + dy24)) {
+			if (sqrt((double) dx13 + dy13) + sqrt((double) dx23 + dy23)
+					< sqrt((double) dx14 + dy14) + sqrt((double) dx24 + dy24)) {
 				moveMe->thisStepX = x3;
 				moveMe->thisStepY = y3;
 			} else {
@@ -623,7 +665,7 @@ bool doBorderStuff(onScreenPerson *moveMe) {
 		moveMe->spinning = true;
 	}
 
-	setFrames(* moveMe, ANI_WALK);
+	setFrames(*moveMe, ANI_WALK);
 	return true;
 }
 
@@ -634,20 +676,22 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) {
 		xDiff = thisPerson->thisStepX - thisPerson->x;
 		yDiff = (thisPerson->thisStepY - thisPerson->y) * 2;
 		s = thisPerson->scale * thisPerson->walkSpeed;
-		if (s < 0.2) s = 0.2;
+		if (s < 0.2)
+			s = 0.2;
 
-		maxDiff = (TF_abs(xDiff) >= TF_abs(yDiff)) ? TF_abs(xDiff) : TF_abs(yDiff);
+		maxDiff =
+				(TF_abs(xDiff) >= TF_abs(yDiff)) ?
+						TF_abs(xDiff) : TF_abs(yDiff);
 
 		if (TF_abs(maxDiff) > s) {
 			if (thisPerson->spinning) {
 				spinStep(thisPerson);
-				setFrames(* thisPerson, ANI_WALK);
+				setFrames(*thisPerson, ANI_WALK);
 			}
 			s = maxDiff / s;
 			if (move)
-				moveAndScale(* thisPerson,
-				             thisPerson->x + xDiff / s,
-				             thisPerson->y + yDiff / (s * 2));
+				moveAndScale(*thisPerson, thisPerson->x + xDiff / s,
+						thisPerson->y + yDiff / (s * 2));
 			return true;
 		}
 
@@ -659,24 +703,27 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) {
 			}
 			break;
 		}
-		if (!doBorderStuff(thisPerson)) break;
+		if (!doBorderStuff(thisPerson))
+			break;
 	}
 
 	thisPerson->walking = false;
-	setFrames(* thisPerson, ANI_STAND);
-	moveAndScale(* thisPerson,
-	             thisPerson->walkToX,
-	             thisPerson->walkToY);
+	setFrames(*thisPerson, ANI_STAND);
+	moveAndScale(*thisPerson, thisPerson->walkToX, thisPerson->walkToY);
 	return false;
 }
 
 bool makeWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
-	if (x == 0 && y == 0) return false;
-	if (currentFloor->numPolygons == 0) return false;
+	if (x == 0 && y == 0)
+		return false;
+	if (currentFloor->numPolygons == 0)
+		return false;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (!moveMe) return false;
+	if (!moveMe)
+		return false;
 
-	if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+	if (moveMe->continueAfterWalking)
+		abortFunction(moveMe->continueAfterWalking);
 	moveMe->continueAfterWalking = NULL;
 	moveMe->walking = true;
 	moveMe->directionWhenDoneWalking = di;
@@ -685,13 +732,16 @@ bool makeWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
 	moveMe->walkToY = y;
 	moveMe->walkToPoly = inFloor(x, y);
 	if (moveMe->walkToPoly == -1) {
-		if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY, moveMe->walkToPoly)) return false;
+		if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY,
+				moveMe->walkToPoly))
+			return false;
 	}
 
 	moveMe->inPoly = inFloor(moveMe->x, moveMe->y);
 	if (moveMe->inPoly == -1) {
 		int xxx = moveMe->x, yyy = moveMe->y;
-		if (!handleClosestPoint(xxx, yyy, moveMe->inPoly)) return false;
+		if (!handleClosestPoint(xxx, yyy, moveMe->inPoly))
+			return false;
 	}
 
 	doBorderStuff(moveMe);
@@ -711,18 +761,22 @@ bool stopPerson(int o) {
 			moveMe->continueAfterWalking = NULL;
 			moveMe->walking = false;
 			moveMe->spinning = false;
-			setFrames(* moveMe, ANI_STAND);
+			setFrames(*moveMe, ANI_STAND);
 			return true;
 		}
 	return false;
 }
 
-bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) {
-	if (x == 0 && y == 0) return false;
+bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func,
+		int di) {
+	if (x == 0 && y == 0)
+		return false;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (!moveMe) return false;
+	if (!moveMe)
+		return false;
 
-	if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+	if (moveMe->continueAfterWalking)
+		abortFunction(moveMe->continueAfterWalking);
 	moveMe->walking = true;
 	moveMe->continueAfterWalking = NULL;
 	moveMe->directionWhenDoneWalking = di;
@@ -745,27 +799,33 @@ bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di)
 }
 
 void jumpPerson(int x, int y, int objNum) {
-	if (x == 0 && y == 0) return;
+	if (x == 0 && y == 0)
+		return;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (!moveMe) return;
-	if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+	if (!moveMe)
+		return;
+	if (moveMe->continueAfterWalking)
+		abortFunction(moveMe->continueAfterWalking);
 	moveMe->continueAfterWalking = NULL;
 	moveMe->walking = false;
 	moveMe->spinning = false;
-	moveAndScale(* moveMe, x, y);
+	moveAndScale(*moveMe, x, y);
 }
 
 bool floatCharacter(int f, int objNum) {
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (!moveMe) return false;
+	if (!moveMe)
+		return false;
 	moveMe->floaty = f;
 	return true;
 }
 
 bool setCharacterWalkSpeed(int f, int objNum) {
-	if (f <= 0) return false;
+	if (f <= 0)
+		return false;
 	onScreenPerson *moveMe = findPerson(objNum);
-	if (!moveMe) return false;
+	if (!moveMe)
+		return false;
 	moveMe->walkSpeed = f;
 	return true;
 }
@@ -778,9 +838,10 @@ void walkAllPeople() {
 			walkMe(thisPerson);
 		} else if (thisPerson->spinning) {
 			spinStep(thisPerson);
-			setFrames(* thisPerson, ANI_STAND);
+			setFrames(*thisPerson, ANI_STAND);
 		}
-		if ((!thisPerson->walking) && (!thisPerson->spinning) && thisPerson->continueAfterWalking) {
+		if ((!thisPerson->walking) && (!thisPerson->spinning)
+				&& thisPerson->continueAfterWalking) {
 			restartFunction(thisPerson->continueAfterWalking);
 			thisPerson->continueAfterWalking = NULL;
 		}
@@ -790,14 +851,15 @@ void walkAllPeople() {
 
 bool addPerson(int x, int y, int objNum, persona *p) {
 	onScreenPerson *newPerson = new onScreenPerson;
-	if (!checkNew(newPerson)) return false;
+	if (!checkNew(newPerson))
+		return false;
 
 	// EASY STUFF
 	newPerson->thisType = loadObjectType(objNum);
 	newPerson->scale = 1;
 	newPerson->extra = 0;
 	newPerson->continueAfterWalking = NULL;
-	moveAndScale(* newPerson, x, y);
+	moveAndScale(*newPerson, x, y);
 	newPerson->frameNum = 0;
 	newPerson->walkToX = x;
 	newPerson->walkToY = y;
@@ -819,7 +881,7 @@ bool addPerson(int x, int y, int objNum, persona *p) {
 	newPerson->transparency = 0;
 	newPerson->myPersona = p;
 
-	setFrames(* newPerson, ANI_STAND);
+	setFrames(*newPerson, ANI_STAND);
 
 	// HEIGHT (BASED ON 1st FRAME OF 1st ANIMATION... INC. SPECIAL CASES)
 	int fNumSigned = p->animation[0]->frames[0].frameNum;
@@ -828,22 +890,24 @@ bool addPerson(int x, int y, int objNum, persona *p) {
 		if (fNumSigned < 0) {
 			newPerson->height = 5;
 		} else {
-			newPerson->height = p->animation[0]->theSprites->bank.sprites[0].yhot + 5;
+			newPerson->height =
+					p->animation[0]->theSprites->bank.sprites[0].yhot + 5;
 		}
 	} else {
-		newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot + 5;
+		newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot
+				+ 5;
 	}
 
 	// NOW ADD IT IN THE RIGHT PLACE
-	onScreenPerson * * changethat = & allPeople;
+	onScreenPerson * * changethat = &allPeople;
 
-	while (((* changethat) != NULL) && ((* changethat)->y < y))
-		changethat = & ((* changethat)->next);
+	while (((*changethat) != NULL) && ((*changethat)->y < y))
+		changethat = &((*changethat)->next);
 
-	newPerson->next = (* changethat);
-	(* changethat) = newPerson;
+	newPerson->next = (*changethat);
+	(*changethat) = newPerson;
 
-	return (bool)(newPerson->thisType != NULL);
+	return (bool) (newPerson->thisType != NULL);
 }
 
 int timeForAnim(personaAnimation *fram) {
@@ -854,10 +918,11 @@ int timeForAnim(personaAnimation *fram) {
 	return total;
 }
 
-void animatePerson(int obj, personaAnimation *fram) {   // Set a new SINGLE animation
+void animatePerson(int obj, personaAnimation *fram) { // Set a new SINGLE animation
 	onScreenPerson *moveMe = findPerson(obj);
 	if (moveMe) {
-		if (moveMe->continueAfterWalking) abortFunction(moveMe->continueAfterWalking);
+		if (moveMe->continueAfterWalking)
+			abortFunction(moveMe->continueAfterWalking);
 		moveMe->continueAfterWalking = NULL;
 		moveMe->walking = false;
 		moveMe->spinning = false;
@@ -874,10 +939,10 @@ void animatePerson(int obj, persona *per) {             // Set a new costume
 		moveMe->spinning = false;
 		moveMe->myPersona = per;
 		rethinkAngle(moveMe);
-		if (moveMe-> walking) {
-			setFrames(* moveMe, ANI_WALK);
+		if (moveMe->walking) {
+			setFrames(*moveMe, ANI_WALK);
 		} else {
-			setFrames(* moveMe, ANI_STAND);
+			setFrames(*moveMe, ANI_STAND);
 		}
 	}
 }
@@ -885,7 +950,8 @@ void animatePerson(int obj, persona *per) {             // Set a new costume
 void killAllPeople() {
 	onScreenPerson *killPeople;
 	while (allPeople) {
-		if (allPeople->continueAfterWalking) abortFunction(allPeople->continueAfterWalking);
+		if (allPeople->continueAfterWalking)
+			abortFunction(allPeople->continueAfterWalking);
 		allPeople->continueAfterWalking = NULL;
 		killPeople = allPeople;
 		allPeople = allPeople->next;
@@ -896,19 +962,20 @@ void killAllPeople() {
 
 void killMostPeople() {
 	onScreenPerson *killPeople;
-	onScreenPerson * * lookyHere = & allPeople;
+	onScreenPerson * * lookyHere = &allPeople;
 
-	while (* lookyHere) {
-		if ((* lookyHere)->extra & EXTRA_NOREMOVE) {
-			lookyHere = & (* lookyHere)->next;
+	while (*lookyHere) {
+		if ((*lookyHere)->extra & EXTRA_NOREMOVE) {
+			lookyHere = &(*lookyHere)->next;
 		} else {
-			killPeople = (* lookyHere);
+			killPeople = (*lookyHere);
 
 			// Change last pointer to NEXT in the list instead
-			(* lookyHere) = killPeople->next;
+			(*lookyHere) = killPeople->next;
 
 			// Gone from the list... now free some memory
-			if (killPeople->continueAfterWalking) abortFunction(killPeople->continueAfterWalking);
+			if (killPeople->continueAfterWalking)
+				abortFunction(killPeople->continueAfterWalking);
 			killPeople->continueAfterWalking = NULL;
 			removeObjectType(killPeople->thisType);
 			delete killPeople;
@@ -920,21 +987,22 @@ void removeOneCharacter(int i) {
 	onScreenPerson *p = findPerson(i);
 
 	if (p) {
-		if (overRegion == &personRegion && overRegion->thisType == p->thisType) {
+		if (overRegion == &personRegion
+				&& overRegion->thisType == p->thisType) {
 			overRegion = NULL;
 		}
 
-		if (p->continueAfterWalking) abortFunction(p->continueAfterWalking);
+		if (p->continueAfterWalking)
+			abortFunction(p->continueAfterWalking);
 		p->continueAfterWalking = NULL;
 		onScreenPerson * * killPeople;
 
-		for (killPeople = & allPeople;
-		        * killPeople != p;
-		        killPeople = & ((* killPeople)->next)) {
+		for (killPeople = &allPeople; *killPeople != p; killPeople =
+				&((*killPeople)->next)) {
 			;
 		}
 
-		* killPeople = p->next;
+		*killPeople = p->next;
 		removeObjectType(p->thisType);
 		delete p;
 	}
@@ -960,7 +1028,8 @@ bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream) {
 	if (p->numFrames) {
 		int a = get4bytes(stream);
 		p->frames = new animFrame[p->numFrames];
-		if (!checkNew(p->frames)) return false;
+		if (!checkNew(p->frames))
+			return false;
 		p->theSprites = loadBankForAnim(a);
 
 		for (a = 0; a < p->numFrames; ++a) {
@@ -979,25 +1048,26 @@ bool loadAnim(personaAnimation *p, Common::SeekableReadStream *stream) {
 	return true;
 }
 /*
-void debugCostume (char * message, persona * cossy) {
-    FILE * db = fopen ("debuTURN.txt", "at");
-    fprintf (db, "  %s costume with %i directions...\n", message, cossy->numDirections);
-    for (int a = 0; a < cossy->numDirections * 3; ++a) {
-        fprintf (db, "      %i frames:", cossy->animation[a]->numFrames);
-        for (int b = 0; b < cossy->animation[a]->numFrames; b ++) {
-            fprintf (db, " %i", cossy->animation[a]->frames[b]);
-        }
-        fprintf (db, "\n");
-
-    }
-    fclose (db);
-}
-*/
+ void debugCostume (char * message, persona * cossy) {
+ FILE * db = fopen ("debuTURN.txt", "at");
+ fprintf (db, "  %s costume with %i directions...\n", message, cossy->numDirections);
+ for (int a = 0; a < cossy->numDirections * 3; ++a) {
+ fprintf (db, "      %i frames:", cossy->animation[a]->numFrames);
+ for (int b = 0; b < cossy->animation[a]->numFrames; b ++) {
+ fprintf (db, " %i", cossy->animation[a]->frames[b]);
+ }
+ fprintf (db, "\n");
+
+ }
+ fclose (db);
+ }
+ */
 bool saveCostume(persona *cossy, Common::WriteStream *stream) {
 	int a;
 	put2bytes(cossy->numDirections, stream);
 	for (a = 0; a < cossy->numDirections * 3; ++a) {
-		if (!saveAnim(cossy->animation[a], stream)) return false;
+		if (!saveAnim(cossy->animation[a], stream))
+			return false;
 	}
 //	debugCostume ("Saved", cossy);
 	return true;
@@ -1006,13 +1076,16 @@ bool saveCostume(persona *cossy, Common::WriteStream *stream) {
 bool loadCostume(persona *cossy, Common::SeekableReadStream *stream) {
 	int a;
 	cossy->numDirections = get2bytes(stream);
-	cossy->animation = new personaAnimation * [cossy->numDirections * 3];
-	if (!checkNew(cossy->animation)) return false;
+	cossy->animation = new personaAnimation *[cossy->numDirections * 3];
+	if (!checkNew(cossy->animation))
+		return false;
 	for (a = 0; a < cossy->numDirections * 3; ++a) {
 		cossy->animation[a] = new personaAnimation;
-		if (!checkNew(cossy->animation[a])) return false;
+		if (!checkNew(cossy->animation[a]))
+			return false;
 
-		if (!loadAnim(cossy->animation[a], stream)) return false;
+		if (!loadAnim(cossy->animation[a], stream))
+			return false;
 	}
 //	debugCostume ("Loaded", cossy);
 	return true;
@@ -1026,7 +1099,7 @@ bool savePeople(Common::WriteStream *stream) {
 	putSigned(scaleDivide, stream);
 
 	while (me) {
-		countPeople ++;
+		countPeople++;
 		me = me->next;
 	}
 
@@ -1086,7 +1159,7 @@ bool savePeople(Common::WriteStream *stream) {
 }
 
 bool loadPeople(Common::SeekableReadStream *stream) {
-	onScreenPerson * * pointy = & allPeople;
+	onScreenPerson * * pointy = &allPeople;
 	onScreenPerson *me;
 
 	scaleHorizon = getSigned(stream);
@@ -1098,13 +1171,16 @@ bool loadPeople(Common::SeekableReadStream *stream) {
 	allPeople = NULL;
 	for (a = 0; a < countPeople; ++a) {
 		me = new onScreenPerson;
-		if (!checkNew(me)) return false;
+		if (!checkNew(me))
+			return false;
 
 		me->myPersona = new persona;
-		if (!checkNew(me->myPersona)) return false;
+		if (!checkNew(me->myPersona))
+			return false;
 
 		me->myAnim = new personaAnimation;
-		if (!checkNew(me->myAnim)) return false;
+		if (!checkNew(me->myAnim))
+			return false;
 
 		me->x = getFloat(stream);
 		me->y = getFloat(stream);
@@ -1132,7 +1208,8 @@ bool loadPeople(Common::SeekableReadStream *stream) {
 		me->spinning = getch(stream);
 		if (getch(stream)) {
 			me->continueAfterWalking = loadFunction(stream);
-			if (!me->continueAfterWalking) return false;
+			if (!me->continueAfterWalking)
+				return false;
 		} else {
 			me->continueAfterWalking = NULL;
 		}
@@ -1169,8 +1246,8 @@ bool loadPeople(Common::SeekableReadStream *stream) {
 		}
 
 		me->next = NULL;
-		* pointy = me;
-		pointy = & (me->next);
+		*pointy = me;
+		pointy = &(me->next);
 	}
 //	db ("End of loadPeople");
 	return true;
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index ba726b0..f6d8784 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -96,13 +96,16 @@ void makeSilent(onScreenPerson &me);
 void setShown(bool h, int ob);
 void setDrawMode(int h, int ob);
 void setPersonTransparency(int ob, unsigned char x);
-void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix);
+void setPersonColourise(int ob, unsigned char r, unsigned char g,
+		unsigned char b, unsigned char colourmix);
 
 // Moving 'em
 
 void movePerson(int x, int y, int objNum);
-bool makeWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, int di);
-bool forceWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, int di);
+bool makeWalkingPerson(int x, int y, int objNum, struct loadedFunction *func,
+		int di);
+bool forceWalkingPerson(int x, int y, int objNum, struct loadedFunction *func,
+		int di);
 void jumpPerson(int x, int y, int objNum);
 void walkAllPeople();
 bool turnPersonToFace(int thisNum, int direc);
@@ -116,7 +119,7 @@ void animatePerson(int obj, personaAnimation *);
 void animatePerson(int obj, persona *per);
 personaAnimation *createPersonaAnim(int num, struct variableStack *&stacky);
 inline void setBankFile(personaAnimation *newP, loadedSpriteBank *sB) {
-	newP -> theSprites = sB;
+	newP->theSprites = sB;
 }
 bool setPersonExtra(int f, int newSetting);
 int timeForAnim(personaAnimation *fram);
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp
index eebcb57..f837d32 100644
--- a/engines/sludge/region.cpp
+++ b/engines/sludge/region.cpp
@@ -47,19 +47,20 @@ void showBoxes() {
 }
 
 void removeScreenRegion(int objectNum) {
-	screenRegion * * huntRegion = & allScreenRegions;
+	screenRegion * * huntRegion = &allScreenRegions;
 	screenRegion *killMe;
 
-	while (* huntRegion) {
-		if ((* huntRegion)->thisType->objectNum == objectNum) {
-			killMe = * huntRegion;
-			* huntRegion = killMe->next;
+	while (*huntRegion) {
+		if ((*huntRegion)->thisType->objectNum == objectNum) {
+			killMe = *huntRegion;
+			*huntRegion = killMe->next;
 			removeObjectType(killMe->thisType);
-			if (killMe == overRegion) overRegion = NULL;
+			if (killMe == overRegion)
+				overRegion = NULL;
 			delete killMe;
 			killMe = NULL;
 		} else {
-			huntRegion = & ((* huntRegion)->next);
+			huntRegion = &((*huntRegion)->next);
 		}
 	}
 }
@@ -69,7 +70,7 @@ void saveRegions(Common::WriteStream *stream) {
 	screenRegion *thisRegion = allScreenRegions;
 	while (thisRegion) {
 		thisRegion = thisRegion->next;
-		numRegions ++;
+		numRegions++;
 	}
 	put2bytes(numRegions, stream);
 	thisRegion = allScreenRegions;
@@ -91,12 +92,12 @@ void loadRegions(Common::SeekableReadStream *stream) {
 	int numRegions = get2bytes(stream);
 
 	screenRegion *newRegion;
-	screenRegion * * pointy = & allScreenRegions;
+	screenRegion * * pointy = &allScreenRegions;
 
-	while (numRegions --) {
+	while (numRegions--) {
 		newRegion = new screenRegion;
-		* pointy = newRegion;
-		pointy = & (newRegion->next);
+		*pointy = newRegion;
+		pointy = &(newRegion->next);
 
 		newRegion->x1 = get2bytes(stream);
 		newRegion->y1 = get2bytes(stream);
@@ -107,7 +108,7 @@ void loadRegions(Common::SeekableReadStream *stream) {
 		newRegion->di = get2bytes(stream);
 		newRegion->thisType = loadObjectRef(stream);
 	}
-	* pointy = NULL;
+	*pointy = NULL;
 }
 
 void killAllRegions() {
@@ -121,9 +122,11 @@ void killAllRegions() {
 	overRegion = NULL;
 }
 
-bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di, int objectNum) {
+bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di,
+		int objectNum) {
 	screenRegion *newRegion = new screenRegion;
-	if (!checkNew(newRegion)) return false;
+	if (!checkNew(newRegion))
+		return false;
 	newRegion->di = di;
 	newRegion->x1 = x1;
 	newRegion->y1 = y1;
@@ -134,14 +137,16 @@ bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di, int
 	newRegion->thisType = loadObjectType(objectNum);
 	newRegion->next = allScreenRegions;
 	allScreenRegions = newRegion;
-	return (bool)(newRegion->thisType != NULL);
+	return (bool) (newRegion->thisType != NULL);
 }
 
 void getOverRegion() {
 	screenRegion *thisRegion = allScreenRegions;
 	while (thisRegion) {
-		if ((input.mouseX >= thisRegion->x1 - cameraX) && (input.mouseY >= thisRegion->y1 - cameraY) &&
-		        (input.mouseX <= thisRegion->x2 - cameraX) && (input.mouseY <= thisRegion->y2 - cameraY)) {
+		if ((input.mouseX >= thisRegion->x1 - cameraX)
+				&& (input.mouseY >= thisRegion->y1 - cameraY)
+				&& (input.mouseX <= thisRegion->x2 - cameraX)
+				&& (input.mouseY <= thisRegion->y2 - cameraY)) {
 			overRegion = thisRegion;
 			return;
 		}
diff --git a/engines/sludge/savedata.cpp b/engines/sludge/savedata.cpp
index dc061c6..805f006 100644
--- a/engines/sludge/savedata.cpp
+++ b/engines/sludge/savedata.cpp
@@ -42,30 +42,30 @@ char encode2 = 0;
 extern char *gamePath;
 
 /*
-void loadSaveDebug (char * com) {
-    FILE * ffpp = fopen ("debuggy.txt", "at");
-    fprintf (ffpp, "%s\n", com);
-    fclose (ffpp);
-}
-
-void loadSaveDebug (char com) {
-    FILE * ffpp = fopen ("debuggy.txt", "at");
-    fprintf (ffpp, "%c\n", com);
-    fclose (ffpp);
-}
-
-void loadSaveDebug (int com) {
-    FILE * ffpp = fopen ("debuggy.txt", "at");
-    fprintf (ffpp, "%d\n", com);
-    fclose (ffpp);
-}
-*/
+ void loadSaveDebug (char * com) {
+ FILE * ffpp = fopen ("debuggy.txt", "at");
+ fprintf (ffpp, "%s\n", com);
+ fclose (ffpp);
+ }
+
+ void loadSaveDebug (char com) {
+ FILE * ffpp = fopen ("debuggy.txt", "at");
+ fprintf (ffpp, "%c\n", com);
+ fclose (ffpp);
+ }
+
+ void loadSaveDebug (int com) {
+ FILE * ffpp = fopen ("debuggy.txt", "at");
+ fprintf (ffpp, "%d\n", com);
+ fclose (ffpp);
+ }
+ */
 
 void writeStringEncoded(const char *s, Common::WriteStream *stream) {
 	int a, len = strlen(s);
 
 	put2bytes(len, stream);
-	for (a = 0; a < len; a ++) {
+	for (a = 0; a < len; a++) {
 		putch(s[a] ^ encode1, stream);
 		encode1 += encode2;
 	}
@@ -74,9 +74,10 @@ void writeStringEncoded(const char *s, Common::WriteStream *stream) {
 char *readStringEncoded(Common::File *fp) {
 	int a, len = get2bytes(fp);
 	char *s = new char[len + 1];
-	if (!checkNew(s)) return NULL;
-	for (a = 0; a < len; a ++) {
-		s[a] = (char)(getch(fp) ^ encode1);
+	if (!checkNew(s))
+		return NULL;
+	for (a = 0; a < len; a++) {
+		s[a] = (char) (getch(fp) ^ encode1);
 		encode1 += encode2;
 	}
 	s[len] = 0;
@@ -98,7 +99,7 @@ char *readTextPlain(Common::File *fp) {
 		if ((gotChar == '\n') || (fp->eos())) {
 			keepGoing = false;
 		} else {
-			stringSize ++;
+			stringSize++;
 		}
 	}
 
@@ -107,7 +108,8 @@ char *readTextPlain(Common::File *fp) {
 	} else {
 		fp->seek(startPos, SEEK_SET);
 		reply = new char[stringSize + 1];
-		if (reply == NULL) return NULL;
+		if (reply == NULL)
+			return NULL;
 		size_t bytes_read = fp->read(reply, stringSize);
 		if (bytes_read != stringSize && fp->err()) {
 			debugOut("Reading error in readTextPlain.\n");
@@ -123,7 +125,9 @@ bool fileToStack(char *filename, stackHandler *sH) {
 
 	variable stringVar;
 	stringVar.varType = SVT_NULL;
-	const char *checker = saveEncoding ? "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";
+	const char *checker =
+			saveEncoding ?
+					"[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";
 
 	Common::File fd;
 
@@ -150,39 +154,42 @@ bool fileToStack(char *filename, stackHandler *sH) {
 	}
 
 	encode1 = (unsigned char) saveEncoding & 255;
-	encode2 = (unsigned char)(saveEncoding >> 8);
+	encode2 = (unsigned char) (saveEncoding >> 8);
 
-	while (* checker) {
-		if (getch(&fd) != * checker) {
+	while (*checker) {
+		if (getch(&fd) != *checker) {
 			fd.close();
-			return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", filename);
+			return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:",
+					filename);
 		}
-		checker ++;
+		checker++;
 	}
 
 	if (saveEncoding) {
 		char *checker = readStringEncoded(&fd);
 		if (strcmp(checker, "UN�LO�CKED")) {
 			fd.close();
-			return fatal(LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", filename);
+			return fatal(
+					LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:",
+					filename);
 		}
 		delete checker;
 		checker = NULL;
 	}
 
-
 	for (;;) {
 		if (saveEncoding) {
 			char i = getch(&fd) ^ encode1;
 
-			if (fd.eos()) break;
+			if (fd.eos())
+				break;
 			switch (i) {
 			case 0: {
 				char *g = readStringEncoded(&fd);
 				makeTextVar(stringVar, g);
 				delete g;
 			}
-			break;
+				break;
 
 			case 1:
 				setVariable(stringVar, SVT_INT, get4bytes(&fd));
@@ -199,18 +206,21 @@ bool fileToStack(char *filename, stackHandler *sH) {
 			}
 		} else {
 			char *line = readTextPlain(&fd);
-			if (!line) break;
+			if (!line)
+				break;
 			makeTextVar(stringVar, line);
 		}
 
-		if (sH -> first == NULL) {
+		if (sH->first == NULL) {
 			// Adds to the TOP of the array... oops!
-			if (!addVarToStackQuick(stringVar, sH -> first)) return false;
-			sH -> last = sH -> first;
+			if (!addVarToStackQuick(stringVar, sH->first))
+				return false;
+			sH->last = sH->first;
 		} else {
 			// Adds to the END of the array... much better
-			if (!addVarToStackQuick(stringVar, sH -> last -> next)) return false;
-			sH -> last = sH -> last -> next;
+			if (!addVarToStackQuick(stringVar, sH->last->next))
+				return false;
+			sH->last = sH->last->next;
 		}
 	}
 	fd.close();
@@ -238,12 +248,12 @@ bool stackToFile(char *filename, const variable &from) {
 	while (hereWeAre) {
 		if (saveEncoding) {
 			switch (hereWeAre -> thisVar.varType) {
-			case SVT_STRING:
+				case SVT_STRING:
 				fputc(encode1, fp);
 				writeStringEncoded(hereWeAre -> thisVar.varData.theString, fp);
 				break;
 
-			case SVT_INT:
+				case SVT_INT:
 				// Small enough to be stored as a char
 				if (hereWeAre -> thisVar.varData.intValue >= 0 && hereWeAre -> thisVar.varData.intValue < 256) {
 					fputc(2 ^ encode1, fp);
@@ -254,7 +264,7 @@ bool stackToFile(char *filename, const variable &from) {
 				}
 				break;
 
-			default:
+				default:
 				fatal("Can't create an encoded custom data file containing anything other than numbers and strings", filename);
 				fclose(fp);
 				return false;
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 734a856..73105c4 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -30,7 +30,7 @@
 #include "sludge/console.h"
 
 namespace Sludge {
- 
+
 class SludgeConsole;
 
 struct SludgeGameDescription;
@@ -43,8 +43,8 @@ enum {
 	kSludgeDebugBuiltin = 1 << 3,
 	kSludgeDebugGraphics = 1 << 4
 };
- 
-class SludgeEngine : public Engine {
+
+class SludgeEngine: public Engine {
 protected:
 	// Engine APIs
 	virtual Common::Error run();
@@ -52,19 +52,19 @@ protected:
 public:
 	SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
 	virtual ~SludgeEngine();
- 
+
 	int getGameType() const;
 	const char *getGameId() const;
 	uint32 getFeatures() const;
 	Common::Language getLanguage() const;
 
 	const SludgeGameDescription *_gameDescription;
- 
+
 private:
 	SludgeConsole *_console;
- 	Common::RandomSource *_rnd;
+	Common::RandomSource *_rnd;
 };
 
 } // End of namespace Sludge
- 
+
 #endif
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 5202168..c7ffd9d 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -101,7 +101,7 @@ bool captureAllKeys = false;
 unsigned char brightnessLevel = 255;
 
 eventHandlers mainHandlers;
-eventHandlers *currentEvents = & mainHandlers;
+eventHandlers *currentEvents = &mainHandlers;
 
 extern HWND hMainWindow;
 extern screenRegion *overRegion;
@@ -117,50 +117,55 @@ inputType input;
 variable *globalVars;
 int numGlobals;
 
-const char *sludgeText[] = { "?????", "RETURN", "BRANCH", "BR_ZERO", "SET_GLOBAL",
-                             "SET_LOCAL", "LOAD_GLOBAL", "LOAD_LOCAL",
-                             "PLUS", "MINUS", "MULT", "DIVIDE",
-                             "AND", "OR", "EQUALS", "NOT_EQ", "MODULUS", "LOAD_VALUE",
-                             "LOAD_BUILT", "LOAD_FUNC", "CALLIT", "LOAD_STRING", "LOAD_FILE",
-                             "LOAD_OBJTYPE", "NOT", "LOAD_NULL", "STACK_PUSH",
-                             "LESSTHAN", "MORETHAN", "NEGATIVE", "U", "LESS_EQUAL", "MORE_EQUAL",
-                             "INC_LOCAL", "DEC_LOCAL", "INC_GLOBAL", "DEC_GLOBAL", "INDEXSET", "INDEXGET",
-                             "INC_INDEX", "DEC_INDEX", "QUICK_PUSH"
-                           };
+const char *sludgeText[] = { "?????", "RETURN", "BRANCH", "BR_ZERO",
+		"SET_GLOBAL", "SET_LOCAL", "LOAD_GLOBAL", "LOAD_LOCAL", "PLUS", "MINUS",
+		"MULT", "DIVIDE", "AND", "OR", "EQUALS", "NOT_EQ", "MODULUS",
+		"LOAD_VALUE", "LOAD_BUILT", "LOAD_FUNC", "CALLIT", "LOAD_STRING",
+		"LOAD_FILE", "LOAD_OBJTYPE", "NOT", "LOAD_NULL", "STACK_PUSH",
+		"LESSTHAN", "MORETHAN", "NEGATIVE", "U", "LESS_EQUAL", "MORE_EQUAL",
+		"INC_LOCAL", "DEC_LOCAL", "INC_GLOBAL", "DEC_GLOBAL", "INDEXSET",
+		"INDEXGET", "INC_INDEX", "DEC_INDEX", "QUICK_PUSH" };
 
 void loadHandlers(Common::SeekableReadStream *stream) {
-	currentEvents->leftMouseFunction      = get2bytes(stream);
-	currentEvents->leftMouseUpFunction    = get2bytes(stream);
-	currentEvents->rightMouseFunction     = get2bytes(stream);
-	currentEvents->rightMouseUpFunction   = get2bytes(stream);
-	currentEvents->moveMouseFunction      = get2bytes(stream);
-	currentEvents->focusFunction          = get2bytes(stream);
-	currentEvents->spaceFunction          = get2bytes(stream);
+	currentEvents->leftMouseFunction = get2bytes(stream);
+	currentEvents->leftMouseUpFunction = get2bytes(stream);
+	currentEvents->rightMouseFunction = get2bytes(stream);
+	currentEvents->rightMouseUpFunction = get2bytes(stream);
+	currentEvents->moveMouseFunction = get2bytes(stream);
+	currentEvents->focusFunction = get2bytes(stream);
+	currentEvents->spaceFunction = get2bytes(stream);
 }
 
 void saveHandlers(Common::WriteStream *stream) {
-	put2bytes(currentEvents->leftMouseFunction,      stream);
-	put2bytes(currentEvents->leftMouseUpFunction,    stream);
-	put2bytes(currentEvents->rightMouseFunction,     stream);
-	put2bytes(currentEvents->rightMouseUpFunction,   stream);
-	put2bytes(currentEvents->moveMouseFunction,      stream);
-	put2bytes(currentEvents->focusFunction,          stream);
-	put2bytes(currentEvents->spaceFunction,          stream);
+	put2bytes(currentEvents->leftMouseFunction, stream);
+	put2bytes(currentEvents->leftMouseUpFunction, stream);
+	put2bytes(currentEvents->rightMouseFunction, stream);
+	put2bytes(currentEvents->rightMouseUpFunction, stream);
+	put2bytes(currentEvents->moveMouseFunction, stream);
+	put2bytes(currentEvents->focusFunction, stream);
+	put2bytes(currentEvents->spaceFunction, stream);
 }
 
-Common::File *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion) {
+Common::File *openAndVerify(char *filename, char extra1, char extra2,
+		const char *er, int &fileVersion) {
 	Common::File *fp = new Common::File();
 	if (!fp->open(filename)) {
 		fatal("Can't open file", filename);
 		return NULL;
 	}
 	bool headerBad = false;
-	if (getch(fp) != 'S') headerBad = true;
-	if (getch(fp) != 'L') headerBad = true;
-	if (getch(fp) != 'U') headerBad = true;
-	if (getch(fp) != 'D') headerBad = true;
-	if (getch(fp) != extra1) headerBad = true;
-	if (getch(fp) != extra2) headerBad = true;
+	if (getch(fp) != 'S')
+		headerBad = true;
+	if (getch(fp) != 'L')
+		headerBad = true;
+	if (getch(fp) != 'U')
+		headerBad = true;
+	if (getch(fp) != 'D')
+		headerBad = true;
+	if (getch(fp) != extra1)
+		headerBad = true;
+	if (getch(fp) != extra2)
+		headerBad = true;
 	if (headerBad) {
 		fatal(er, filename);
 		return NULL;
@@ -196,34 +201,40 @@ bool initSludge(char *filename) {
 	int a = 0;
 	mouseCursorAnim = makeNullAnim();
 
-	Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion);
-	if (!fp) return false;
+	Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER,
+			gameVersion);
+	if (!fp)
+		return false;
 
 	char c = getch(fp);
 	if (c) {
 		numBIFNames = get2bytes(fp);
 		debug(kSludgeDebugDataLoad, "numBIFNames %i", numBIFNames);
 		allBIFNames = new char *[numBIFNames];
-		if (!checkNew(allBIFNames)) return false;
+		if (!checkNew(allBIFNames))
+			return false;
 
-		for (int fn = 0; fn < numBIFNames; fn ++) {
+		for (int fn = 0; fn < numBIFNames; fn++) {
 			allBIFNames[fn] = readString(fp);
 		}
 		numUserFunc = get2bytes(fp);
 		debug(kSludgeDebugDataLoad, "numUserFunc %i", numUserFunc);
 		allUserFunc = new char *[numUserFunc];
-		if (!checkNew(allUserFunc)) return false;
+		if (!checkNew(allUserFunc))
+			return false;
 
-		for (int fn = 0; fn < numUserFunc; fn ++) {
+		for (int fn = 0; fn < numUserFunc; fn++) {
 			allUserFunc[fn] = readString(fp);
 		}
 		if (gameVersion >= VERSION(1, 3)) {
 			numResourceNames = get2bytes(fp);
-			debug(kSludgeDebugDataLoad, "numResourceNames %i", numResourceNames);
+			debug(kSludgeDebugDataLoad, "numResourceNames %i",
+					numResourceNames);
 			allResourceNames = new char *[numResourceNames];
-			if (!checkNew(allResourceNames)) return false;
+			if (!checkNew(allResourceNames))
+				return false;
 
-			for (int fn = 0; fn < numResourceNames; fn ++) {
+			for (int fn = 0; fn < numResourceNames; fn++) {
 				allResourceNames[fn] = readString(fp);
 			}
 		}
@@ -244,10 +255,13 @@ bool initSludge(char *filename) {
 		debug("Reading error in initSludge.");
 	}
 
-	char *dataFol = (gameVersion >= VERSION(1, 3)) ? readString(fp) : joinStrings("", "");
+	char *dataFol =
+			(gameVersion >= VERSION(1, 3)) ?
+					readString(fp) : joinStrings("", "");
 	debug(kSludgeDebugDataLoad, "dataFol : %s", dataFol);
 
-	gameSettings.numLanguages = (gameVersion >= VERSION(1, 3)) ? (getch(fp)) : 0;
+	gameSettings.numLanguages =
+			(gameVersion >= VERSION(1, 3)) ? (getch(fp)) : 0;
 	debug(kSludgeDebugDataLoad, "numLanguages : %c", gameSettings.numLanguages);
 	makeLanguageTable(fp);
 
@@ -262,7 +276,8 @@ bool initSludge(char *filename) {
 	char *checker = readString(fp);
 	debug(kSludgeDebugDataLoad, "checker : %s", checker);
 
-	if (strcmp(checker, "okSoFar")) return fatal(ERROR_BAD_HEADER, filename);
+	if (strcmp(checker, "okSoFar"))
+		return fatal(ERROR_BAD_HEADER, filename);
 	delete checker;
 	checker = NULL;
 
@@ -316,7 +331,7 @@ bool initSludge(char *filename) {
 				return false;
 			}
 			png_init_io(png_ptr, fp);       // Tell libpng which file to read
-			png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+			png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 			png_read_info(png_ptr, info_ptr);
 
@@ -348,7 +363,7 @@ bool initSludge(char *filename) {
 		if (fileIsPNG) {
 			unsigned char *row_pointers[iconH];
 			for (int i = 0; i < iconH; i++)
-				row_pointers[i] = p + 4 * i * iconW;
+			row_pointers[i] = p + 4 * i * iconW;
 
 			png_read_image(png_ptr, (png_byte **) row_pointers);
 			png_read_end(png_ptr, NULL);
@@ -425,7 +440,7 @@ bool initSludge(char *filename) {
 				return false;
 			}
 			png_init_io(png_ptr, fp);       // Tell libpng which file to read
-			png_set_sig_bytes(png_ptr, 8);  // 8 bytes already read
+			png_set_sig_bytes(png_ptr, 8);// 8 bytes already read
 
 			png_read_info(png_ptr, info_ptr);
 
@@ -443,8 +458,8 @@ bool initSludge(char *filename) {
 #ifdef WIN32
 			// Windows wants a BGR bitmap
 			if (color_type == PNG_COLOR_TYPE_RGB ||
-			        color_type == PNG_COLOR_TYPE_RGB_ALPHA)
-				png_set_bgr(png_ptr);
+					color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+			png_set_bgr(png_ptr);
 #endif
 
 			png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
@@ -465,7 +480,7 @@ bool initSludge(char *filename) {
 		if (fileIsPNG) {
 			unsigned char *row_pointers[logoH];
 			for (int i = 0; i < logoH; i++)
-				row_pointers[i] = p + 4 * i * logoW;
+			row_pointers[i] = p + 4 * i * logoW;
 
 			png_read_image(png_ptr, (png_byte **) row_pointers);
 			png_read_end(png_ptr, NULL);
@@ -493,7 +508,7 @@ bool initSludge(char *filename) {
 						*p++ = (Uint8) greenValue(c);
 						*p++ = (Uint8) blueValue(c);
 #endif
-						*p++ = (Uint8) /*(c == transCol) ? 0 :*/ 255;
+						*p++ = (Uint8) /*(c == transCol) ? 0 :*/255;
 
 						t1++;
 					}
@@ -507,8 +522,10 @@ bool initSludge(char *filename) {
 	debug("numGlobals : %i", numGlobals);
 
 	globalVars = new variable[numGlobals];
-	if (!checkNew(globalVars)) return false;
-	for (a = 0; a < numGlobals; a ++) initVarNew(globalVars[a]);
+	if (!checkNew(globalVars))
+		return false;
+	for (a = 0; a < numGlobals; a++)
+		initVarNew(globalVars[a]);
 
 	// Get the original (untranslated) name of the game and convert it to Unicode.
 	// We use this to find saved preferences and saved games.
@@ -530,7 +547,7 @@ bool initSludge(char *filename) {
 
 	if (chdir(gameName)) return fatal("This game's preference folder is inaccessible!\nI can't access the following directory (maybe there's a file with the same name, or maybe it's read-protected):", gameName);
 #endif
-	delete [] gameName;
+	delete[] gameName;
 
 	// Get user settings
 	readIniFile(filename);
@@ -551,7 +568,8 @@ bool initSludge(char *filename) {
 
 	// Now set file indices properly to the chosen language.
 	languageNum = getLanguageForFileB();
-	if (languageNum < 0) return fatal("Can't find the translation data specified!");
+	if (languageNum < 0)
+		return fatal("Can't find the translation data specified!");
 	setFileIndices(NULL, gameSettings.numLanguages, languageNum);
 
 	if (dataFol[0]) {
@@ -581,8 +599,8 @@ bool checkColourChange(bool reset) {
 	static GLuint oldPixel;
 	static GLuint pixel;
 	glReadPixels((GLint)(viewportOffsetX + input.mouseX * viewportWidth / ((float)winWidth / cameraZoom)),
-	             (GLint)(viewportOffsetY + (((float)winHeight / cameraZoom) - input.mouseY)*viewportHeight / ((float)winHeight / cameraZoom)),
-	             1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
+			(GLint)(viewportOffsetY + (((float)winHeight / cameraZoom) - input.mouseY)*viewportHeight / ((float)winHeight / cameraZoom)),
+			1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
 
 	if (reset || oldPixel != pixel) {
 		oldPixel = pixel;
@@ -631,21 +649,21 @@ void sludgeDisplay() {
 		fbo_tex_w = (float)realWinWidth / width;
 		fbo_tex_h = (float)realWinHeight / height;
 		// create shader for blitting the fbo...
-		const char _blit_vsh[] = "                              \n\t" \
-		                         "attribute highp vec2 aPosition;                        \n\t" \
-		                         "attribute highp vec2 aTexCoord;                        \n\t" \
-		                         "varying mediump vec2 vTexCoord;                        \n\t" \
-		                         "void main(){                                           \n\t" \
-		                         "gl_Position = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n\t" \
-		                         "vTexCoord = aTexCoord;                                 \n\t" \
-		                         "}                                                      \n\t";
-
-		const char _blit_fsh[] = "                              \n\t" \
-		                         "uniform sampler2D uTex;                                \n\t" \
-		                         "varying mediump vec2 vTexCoord;                        \n\t" \
-		                         "void main(){                                           \n\t" \
-		                         "gl_FragColor = texture2D(uTex, vTexCoord);             \n\t" \
-		                         "}                                                      \n\t";
+		const char _blit_vsh[] = "                              \n\t"
+		"attribute highp vec2 aPosition;                        \n\t"
+		"attribute highp vec2 aTexCoord;                        \n\t"
+		"varying mediump vec2 vTexCoord;                        \n\t"
+		"void main(){                                           \n\t"
+		"gl_Position = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n\t"
+		"vTexCoord = aTexCoord;                                 \n\t"
+		"}                                                      \n\t";
+
+		const char _blit_fsh[] = "                              \n\t"
+		"uniform sampler2D uTex;                                \n\t"
+		"varying mediump vec2 vTexCoord;                        \n\t"
+		"void main(){                                           \n\t"
+		"gl_FragColor = texture2D(uTex, vTexCoord);             \n\t"
+		"}                                                      \n\t";
 
 		GLint success;
 		fbo_frag = glCreateShader(GL_FRAGMENT_SHADER);
@@ -682,20 +700,20 @@ void sludgeDisplay() {
 
 	glDepthMask(GL_TRUE);
 //	glClearColor(0.5, 0.5, 1.0, 0.0);
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen
 	glDepthMask(GL_FALSE);
 
-	drawBackDrop();                 // Draw the room
+	drawBackDrop();// Draw the room
 	drawZBuffer(cameraX, cameraY, false);
 
 	glEnable(GL_DEPTH_TEST);
-	drawPeople();                   // Then add any moving characters...
+	drawPeople();// Then add any moving characters...
 	glDisable(GL_DEPTH_TEST);
-	viewSpeech();                   // ...and anything being said
+	viewSpeech();// ...and anything being said
 	drawStatusBar();
 	displayCursor();
 
-	if (brightnessLevel < 255) fixBrightness();     // This is for transitionLevel special effects
+	if (brightnessLevel < 255) fixBrightness();// This is for transitionLevel special effects
 
 	glFlush();
 #if !defined(HAVE_GLES2)
@@ -735,13 +753,13 @@ void sludgeDisplay() {
 }
 
 void pauseFunction(loadedFunction *fun) {
-	loadedFunction * * huntAndDestroy = & allRunningFunctions;
-	while (* huntAndDestroy) {
-		if (fun == * huntAndDestroy) {
-			(* huntAndDestroy) = (* huntAndDestroy)->next;
+	loadedFunction * * huntAndDestroy = &allRunningFunctions;
+	while (*huntAndDestroy) {
+		if (fun == *huntAndDestroy) {
+			(*huntAndDestroy) = (*huntAndDestroy)->next;
 			fun->next = NULL;
 		} else {
-			huntAndDestroy = & (* huntAndDestroy)->next;
+			huntAndDestroy = &(*huntAndDestroy)->next;
 		}
 	}
 }
@@ -755,7 +773,8 @@ void killSpeechTimers() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction->freezerLevel == 0 && thisFunction->isSpeech && thisFunction->timeLeft) {
+		if (thisFunction->freezerLevel == 0 && thisFunction->isSpeech
+				&& thisFunction->timeLeft) {
 			thisFunction->timeLeft = 0;
 			thisFunction->isSpeech = false;
 		}
@@ -769,7 +788,8 @@ void completeTimers() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction->freezerLevel == 0) thisFunction->timeLeft = 0;
+		if (thisFunction->freezerLevel == 0)
+			thisFunction->timeLeft = 0;
 		thisFunction = thisFunction->next;
 	}
 }
@@ -778,9 +798,11 @@ void finishFunction(loadedFunction *fun) {
 	int a;
 
 	pauseFunction(fun);
-	if (fun->stack) fatal(ERROR_NON_EMPTY_STACK);
+	if (fun->stack)
+		fatal(ERROR_NON_EMPTY_STACK);
 	delete fun->compiledLines;
-	for (a = 0; a < fun->numLocals; a ++) unlinkVar(fun->localVars[a]);
+	for (a = 0; a < fun->numLocals; a++)
+		unlinkVar(fun->localVars[a]);
 	delete fun->localVars;
 	unlinkVar(fun->reg);
 	delete fun;
@@ -791,12 +813,15 @@ void abortFunction(loadedFunction *fun) {
 	int a;
 
 	pauseFunction(fun);
-	while (fun->stack) trimStack(fun->stack);
+	while (fun->stack)
+		trimStack(fun->stack);
 	delete fun->compiledLines;
-	for (a = 0; a < fun->numLocals; a ++) unlinkVar(fun->localVars[a]);
+	for (a = 0; a < fun->numLocals; a++)
+		unlinkVar(fun->localVars[a]);
 	delete fun->localVars;
 	unlinkVar(fun->reg);
-	if (fun->calledBy) abortFunction(fun->calledBy);
+	if (fun->calledBy)
+		abortFunction(fun->calledBy);
 	delete fun;
 	fun = NULL;
 }
@@ -809,8 +834,9 @@ int cancelAFunction(int funcNum, loadedFunction *myself, bool &killedMyself) {
 	while (fun) {
 		if (fun->originalNumber == funcNum) {
 			fun->cancelMe = true;
-			n ++;
-			if (fun == myself) killedMyself = true;
+			n++;
+			if (fun == myself)
+				killedMyself = true;
 		}
 		fun = fun->next;
 	}
@@ -824,7 +850,7 @@ void freezeSubs() {
 		if (thisFunction->unfreezable) {
 			//msgBox ("SLUDGE debugging bollocks!", "Trying to freeze an unfreezable function!");
 		} else {
-			thisFunction->freezerLevel ++;
+			thisFunction->freezerLevel++;
 		}
 		thisFunction = thisFunction->next;
 	}
@@ -834,12 +860,12 @@ void unfreezeSubs() {
 	loadedFunction *thisFunction = allRunningFunctions;
 
 	while (thisFunction) {
-		if (thisFunction->freezerLevel) thisFunction->freezerLevel --;
+		if (thisFunction->freezerLevel)
+			thisFunction->freezerLevel--;
 		thisFunction = thisFunction->next;
 	}
 }
 
-
 bool continueFunction(loadedFunction *fun) {
 	bool keepLooping = true;
 	bool advanceNow;
@@ -864,8 +890,11 @@ bool continueFunction(loadedFunction *fun) {
 
 		if (numBIFNames) {
 			setFatalInfo(
-			    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
-			    (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE);
+					(fun->originalNumber < numUserFunc) ?
+							allUserFunc[fun->originalNumber] :
+							"Unknown user function",
+					(com < numSludgeCommands) ?
+							sludgeText[com] : ERROR_UNKNOWN_MCODE);
 //			newDebug (
 //				(com < numSludgeCommands) ? sludgeText[com] : "Unknown SLUDGE machine code",
 //				param);
@@ -877,13 +906,14 @@ bool continueFunction(loadedFunction *fun) {
 		case SLU_RETURN:
 			if (fun->calledBy) {
 				loadedFunction *returnTo = fun->calledBy;
-				if (fun->returnSomething) copyVariable(fun->reg, returnTo->reg);
+				if (fun->returnSomething)
+					copyVariable(fun->reg, returnTo->reg);
 				finishFunction(fun);
 				fun = returnTo;
 				restartFunction(fun);
 			} else {
 				finishFunction(fun);
-				advanceNow = false;     // So we don't do anything else with "fun"
+				advanceNow = false;   // So we don't do anything else with "fun"
 				keepLooping = false;    // So we drop out of the loop
 			}
 			break;
@@ -892,26 +922,36 @@ bool continueFunction(loadedFunction *fun) {
 			switch (fun->reg.varType) {
 			case SVT_FUNC:
 				pauseFunction(fun);
-				if (numBIFNames) setFatalInfo(
-					    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
-					    (fun->reg.varData.intValue < numUserFunc) ? allUserFunc[fun->reg.varData.intValue] : "Unknown user function");
-
-				if (!startNewFunctionNum(fun->reg.varData.intValue, param, fun, fun->stack)) return false;
+				if (numBIFNames)
+					setFatalInfo(
+							(fun->originalNumber < numUserFunc) ?
+									allUserFunc[fun->originalNumber] :
+									"Unknown user function",
+							(fun->reg.varData.intValue < numUserFunc) ?
+									allUserFunc[fun->reg.varData.intValue] :
+									"Unknown user function");
+
+				if (!startNewFunctionNum(fun->reg.varData.intValue, param, fun,
+						fun->stack))
+					return false;
 				fun = allRunningFunctions;
-				advanceNow = false;     // So we don't do anything else with "fun"
+				advanceNow = false;   // So we don't do anything else with "fun"
 				break;
 
 			case SVT_BUILT: {
-				debug(kSludgeDebugStackMachine, "Built-in init value: %i", fun->reg.varData.intValue);
-				builtReturn br = callBuiltIn(fun->reg.varData.intValue, param, fun);
+				debug(kSludgeDebugStackMachine, "Built-in init value: %i",
+						fun->reg.varData.intValue);
+				builtReturn br = callBuiltIn(fun->reg.varData.intValue, param,
+						fun);
 
 				switch (br) {
 				case BR_ERROR:
-					return fatal("Unknown error. This shouldn't happen. Please notify the SLUDGE developers.");
+					return fatal(
+							"Unknown error. This shouldn't happen. Please notify the SLUDGE developers.");
 
 				case BR_PAUSE:
 					pauseFunction(fun);
-				// No break!
+					// No break!
 
 				case BR_KEEP_AND_PAUSE:
 					keepLooping = false;
@@ -926,27 +966,33 @@ bool continueFunction(loadedFunction *fun) {
 					int i = fun->reg.varData.intValue;
 					setVariable(fun->reg, SVT_INT, 1);
 					pauseFunction(fun);
-					if (numBIFNames) setFatalInfo(
-						    (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function",
-						    (i < numUserFunc) ? allUserFunc[i] : "Unknown user function");
-					if (!startNewFunctionNum(i, 0, fun, noStack, false)) return false;
+					if (numBIFNames)
+						setFatalInfo(
+								(fun->originalNumber < numUserFunc) ?
+										allUserFunc[fun->originalNumber] :
+										"Unknown user function",
+								(i < numUserFunc) ?
+										allUserFunc[i] :
+										"Unknown user function");
+					if (!startNewFunctionNum(i, 0, fun, noStack, false))
+						return false;
 					fun = allRunningFunctions;
-					advanceNow = false;     // So we don't do anything else with "fun"
+					advanceNow = false; // So we don't do anything else with "fun"
 				}
-				break;
+					break;
 
 				default:
 					break;
 				}
 			}
-			break;
+				break;
 
 			default:
 				return fatal(ERROR_CALL_NONFUNCTION);
 			}
 			break;
 
-		// These all grab things and shove 'em into the register
+			// These all grab things and shove 'em into the register
 
 		case SLU_LOAD_NULL:
 			setVariable(fun->reg, SVT_NULL, 0);
@@ -961,16 +1007,19 @@ bool continueFunction(loadedFunction *fun) {
 			break;
 
 		case SLU_LOAD_LOCAL:
-			if (!copyVariable(fun->localVars[param], fun->reg)) return false;
+			if (!copyVariable(fun->localVars[param], fun->reg))
+				return false;
 			break;
 
 		case SLU_AND:
-			setVariable(fun->reg, SVT_INT, getBoolean(fun->reg) && getBoolean(fun->stack->thisVar));
+			setVariable(fun->reg, SVT_INT,
+					getBoolean(fun->reg) && getBoolean(fun->stack->thisVar));
 			trimStack(fun->stack);
 			break;
 
 		case SLU_OR:
-			setVariable(fun->reg, SVT_INT, getBoolean(fun->reg) || getBoolean(fun->stack->thisVar));
+			setVariable(fun->reg, SVT_INT,
+					getBoolean(fun->reg) || getBoolean(fun->stack->thisVar));
 			trimStack(fun->stack);
 			break;
 
@@ -987,7 +1036,8 @@ bool continueFunction(loadedFunction *fun) {
 			break;
 
 		case SLU_UNREG:
-			if (dialogValue != 1) fatal(ERROR_HACKER);
+			if (dialogValue != 1)
+				fatal(ERROR_HACKER);
 			break;
 
 		case SLU_LOAD_STRING:
@@ -1015,11 +1065,16 @@ bool continueFunction(loadedFunction *fun) {
 					return fatal(ERROR_INDEX_EMPTY);
 				} else {
 					int ii;
-					if (!getValueType(ii, SVT_INT, fun->reg)) return false;
-					variable *grab = (fun->stack->thisVar.varType == SVT_FASTARRAY) ?
-					                 fastArrayGetByIndex(fun->stack->thisVar.varData.fastArray, ii)
-					                 :
-					                 stackGetByIndex(fun->stack->thisVar.varData.theStack->first, ii);
+					if (!getValueType(ii, SVT_INT, fun->reg))
+						return false;
+					variable *grab =
+							(fun->stack->thisVar.varType == SVT_FASTARRAY) ?
+									fastArrayGetByIndex(
+											fun->stack->thisVar.varData.fastArray,
+											ii) :
+									stackGetByIndex(
+											fun->stack->thisVar.varData.theStack->first,
+											ii);
 
 					trimStack(fun->stack);
 
@@ -1029,19 +1084,22 @@ bool continueFunction(loadedFunction *fun) {
 						int ii;
 						switch (com) {
 						case SLU_INCREMENT_INDEX:
-							if (!getValueType(ii, SVT_INT, * grab)) return false;
+							if (!getValueType(ii, SVT_INT, *grab))
+								return false;
 							setVariable(fun->reg, SVT_INT, ii);
 							grab->varData.intValue = ii + 1;
 							break;
 
 						case SLU_DECREMENT_INDEX:
-							if (!getValueType(ii, SVT_INT, * grab)) return false;
+							if (!getValueType(ii, SVT_INT, *grab))
+								return false;
 							setVariable(fun->reg, SVT_INT, ii);
 							grab->varData.intValue = ii - 1;
 							break;
 
 						default:
-							if (!copyVariable(* grab, fun->reg)) return false;
+							if (!copyVariable(*grab, fun->reg))
+								return false;
 						}
 					}
 				}
@@ -1059,8 +1117,11 @@ bool continueFunction(loadedFunction *fun) {
 					return fatal(ERROR_INDEX_EMPTY);
 				} else {
 					int ii;
-					if (!getValueType(ii, SVT_INT, fun->reg)) return false;
-					if (!stackSetByIndex(fun->stack->thisVar.varData.theStack->first, ii, fun->stack->next->thisVar)) {
+					if (!getValueType(ii, SVT_INT, fun->reg))
+						return false;
+					if (!stackSetByIndex(
+							fun->stack->thisVar.varData.theStack->first, ii,
+							fun->stack->next->thisVar)) {
 						return false;
 					}
 					trimStack(fun->stack);
@@ -1070,78 +1131,91 @@ bool continueFunction(loadedFunction *fun) {
 
 			case SVT_FASTARRAY: {
 				int ii;
-				if (!getValueType(ii, SVT_INT, fun->reg)) return false;
-				variable *v = fastArrayGetByIndex(fun->stack->thisVar.varData.fastArray, ii);
-				if (v == NULL) return fatal("Not within bounds of fast array.");
-				if (!copyVariable(fun->stack->next->thisVar, * v)) return false;
+				if (!getValueType(ii, SVT_INT, fun->reg))
+					return false;
+				variable *v = fastArrayGetByIndex(
+						fun->stack->thisVar.varData.fastArray, ii);
+				if (v == NULL)
+					return fatal("Not within bounds of fast array.");
+				if (!copyVariable(fun->stack->next->thisVar, *v))
+					return false;
 				trimStack(fun->stack);
 				trimStack(fun->stack);
 			}
-			break;
+				break;
 
 			default:
 				return fatal(ERROR_INDEX_NONSTACK);
 			}
 			break;
 
-		// What can we do with the register? Well, we can copy it into a local
-		// variable, a global or onto the stack...
+			// What can we do with the register? Well, we can copy it into a local
+			// variable, a global or onto the stack...
 
 		case SLU_INCREMENT_LOCAL: {
 			int ii;
-			if (!getValueType(ii, SVT_INT, fun->localVars[param])) return false;
+			if (!getValueType(ii, SVT_INT, fun->localVars[param]))
+				return false;
 			setVariable(fun->reg, SVT_INT, ii);
 			setVariable(fun->localVars[param], SVT_INT, ii + 1);
 		}
-		break;
+			break;
 
 		case SLU_INCREMENT_GLOBAL: {
 			int ii;
-			if (!getValueType(ii, SVT_INT, globalVars[param])) return false;
+			if (!getValueType(ii, SVT_INT, globalVars[param]))
+				return false;
 			setVariable(fun->reg, SVT_INT, ii);
 			setVariable(globalVars[param], SVT_INT, ii + 1);
 		}
-		break;
+			break;
 
 		case SLU_DECREMENT_LOCAL: {
 			int ii;
-			if (!getValueType(ii, SVT_INT, fun->localVars[param])) return false;
+			if (!getValueType(ii, SVT_INT, fun->localVars[param]))
+				return false;
 			setVariable(fun->reg, SVT_INT, ii);
 			setVariable(fun->localVars[param], SVT_INT, ii - 1);
 		}
-		break;
+			break;
 
 		case SLU_DECREMENT_GLOBAL: {
 			int ii;
-			if (!getValueType(ii, SVT_INT, globalVars[param])) return false;
+			if (!getValueType(ii, SVT_INT, globalVars[param]))
+				return false;
 			setVariable(fun->reg, SVT_INT, ii);
 			setVariable(globalVars[param], SVT_INT, ii - 1);
 		}
-		break;
+			break;
 
 		case SLU_SET_LOCAL:
-			if (!copyVariable(fun->reg, fun->localVars[param])) return false;
+			if (!copyVariable(fun->reg, fun->localVars[param]))
+				return false;
 			break;
 
 		case SLU_SET_GLOBAL:
 //			newDebug ("  Copying TO global variable", param);
 //			newDebug ("  Global type at the moment", globalVars[param].varType);
-			if (!copyVariable(fun->reg, globalVars[param])) return false;
+			if (!copyVariable(fun->reg, globalVars[param]))
+				return false;
 //			newDebug ("  New type", globalVars[param].varType);
 			break;
 
 		case SLU_LOAD_GLOBAL:
 //			newDebug ("  Copying FROM global variable", param);
 //			newDebug ("  Global type at the moment", globalVars[param].varType);
-			if (!copyVariable(globalVars[param], fun->reg)) return false;
+			if (!copyVariable(globalVars[param], fun->reg))
+				return false;
 			break;
 
 		case SLU_STACK_PUSH:
-			if (!addVarToStack(fun->reg, fun->stack)) return false;
+			if (!addVarToStack(fun->reg, fun->stack))
+				return false;
 			break;
 
 		case SLU_QUICK_PUSH:
-			if (!addVarToStackQuick(fun->reg, fun->stack)) return false;
+			if (!addVarToStackQuick(fun->reg, fun->stack))
+				return false;
 			break;
 
 		case SLU_NOT:
@@ -1162,12 +1236,13 @@ bool continueFunction(loadedFunction *fun) {
 
 		case SLU_NEGATIVE: {
 			int i;
-			if (!getValueType(i, SVT_INT, fun->reg)) return false;
+			if (!getValueType(i, SVT_INT, fun->reg))
+				return false;
 			setVariable(fun->reg, SVT_INT, -i);
 		}
-		break;
+			break;
 
-		// All these things rely on there being somet' on the stack
+			// All these things rely on there being somet' on the stack
 
 		case SLU_MULT:
 		case SLU_PLUS:
@@ -1201,41 +1276,51 @@ bool continueFunction(loadedFunction *fun) {
 					break;
 
 				default:
-					if (!getValueType(firstValue, SVT_INT, fun->stack->thisVar)) return false;
-					if (!getValueType(secondValue, SVT_INT, fun->reg)) return false;
+					if (!getValueType(firstValue, SVT_INT, fun->stack->thisVar))
+						return false;
+					if (!getValueType(secondValue, SVT_INT, fun->reg))
+						return false;
 					trimStack(fun->stack);
 
 					switch (com) {
 					case SLU_MULT:
-						setVariable(fun->reg, SVT_INT, firstValue * secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue * secondValue);
 						break;
 
 					case SLU_MINUS:
-						setVariable(fun->reg, SVT_INT, firstValue - secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue - secondValue);
 						break;
 
 					case SLU_MODULUS:
-						setVariable(fun->reg, SVT_INT, firstValue % secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue % secondValue);
 						break;
 
 					case SLU_DIVIDE:
-						setVariable(fun->reg, SVT_INT, firstValue / secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue / secondValue);
 						break;
 
 					case SLU_LESSTHAN:
-						setVariable(fun->reg, SVT_INT, firstValue < secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue < secondValue);
 						break;
 
 					case SLU_MORETHAN:
-						setVariable(fun->reg, SVT_INT, firstValue > secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue > secondValue);
 						break;
 
 					case SLU_LESS_EQUAL:
-						setVariable(fun->reg, SVT_INT, firstValue <= secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue <= secondValue);
 						break;
 
 					case SLU_MORE_EQUAL:
-						setVariable(fun->reg, SVT_INT, firstValue >= secondValue);
+						setVariable(fun->reg, SVT_INT,
+								firstValue >= secondValue);
 						break;
 
 					default:
@@ -1251,13 +1336,13 @@ bool continueFunction(loadedFunction *fun) {
 			return fatal(ERROR_UNKNOWN_CODE);
 		}
 
-		if (advanceNow) fun->runThisLine ++;
+		if (advanceNow)
+			fun->runThisLine++;
 
 	}
 	return true;
 }
 
-
 bool runSludge() {
 
 	loadedFunction *thisFunction = allRunningFunctions;
@@ -1269,10 +1354,11 @@ bool runSludge() {
 		if (!thisFunction->freezerLevel) {
 			if (thisFunction->timeLeft) {
 				if (thisFunction->timeLeft < 0) {
-					if (!stillPlayingSound(findInSoundCache(speech->lastFile))) {
+					if (!stillPlayingSound(
+							findInSoundCache(speech->lastFile))) {
 						thisFunction->timeLeft = 0;
 					}
-				} else if (!-- (thisFunction->timeLeft)) {
+				} else if (!--(thisFunction->timeLeft)) {
 				}
 			} else {
 				if (thisFunction->isSpeech) {
@@ -1292,7 +1378,8 @@ bool runSludge() {
 			saveGame(loadNow + 1);
 			setVariable(saverFunc->reg, SVT_INT, 1);
 		} else {
-			if (!loadGame(loadNow)) return false;
+			if (!loadGame(loadNow))
+				return false;
 		}
 		delete loadNow;
 		loadNow = NULL;
@@ -1306,52 +1393,62 @@ bool loadFunctionCode(loadedFunction *newFunc) {
 	debug(kSludgeDebugDataLoad, "Current address: %i", bigDataFile->pos());
 	unsigned int numLines, numLinesRead;
 
-	if (!openSubSlice(newFunc->originalNumber)) return false;
+	if (!openSubSlice(newFunc->originalNumber))
+		return false;
 
 	debug(kSludgeDebugDataLoad, "Load function code");
 
-	newFunc->unfreezable  = getch(bigDataFile);
-	numLines                = get2bytes(bigDataFile);
+	newFunc->unfreezable = getch(bigDataFile);
+	numLines = get2bytes(bigDataFile);
 	debug(kSludgeDebugDataLoad, "numLines: %i", numLines);
-	newFunc->numArgs      = get2bytes(bigDataFile);
+	newFunc->numArgs = get2bytes(bigDataFile);
 	debug(kSludgeDebugDataLoad, "numArgs: %i", newFunc->numArgs);
-	newFunc->numLocals    = get2bytes(bigDataFile);
+	newFunc->numLocals = get2bytes(bigDataFile);
 	debug(kSludgeDebugDataLoad, "numLocals: %i", newFunc->numLocals);
 	newFunc->compiledLines = new lineOfCode[numLines];
-	if (!checkNew(newFunc->compiledLines)) return false;
+	if (!checkNew(newFunc->compiledLines))
+		return false;
 
-	for (numLinesRead = 0; numLinesRead < numLines; numLinesRead ++) {
-		newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) getch(bigDataFile);
+	for (numLinesRead = 0; numLinesRead < numLines; numLinesRead++) {
+		newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) getch(
+				bigDataFile);
 		newFunc->compiledLines[numLinesRead].param = get2bytes(bigDataFile);
-		debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead, newFunc->compiledLines[numLinesRead].theCommand);
+		debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead,
+				newFunc->compiledLines[numLinesRead].theCommand);
 	}
 	finishAccess();
 
 	// Now we need to reserve memory for the local variables
 	newFunc->localVars = new variable[newFunc->numLocals];
-	if (!checkNew(newFunc->localVars)) return false;
-	for (int a = 0; a < newFunc->numLocals; a ++) {
+	if (!checkNew(newFunc->localVars))
+		return false;
+	for (int a = 0; a < newFunc->numLocals; a++) {
 		initVarNew(newFunc->localVars[a]);
 	}
 
 	return true;
 }
 
-int startNewFunctionNum(unsigned int funcNum, unsigned int numParamsExpected, loadedFunction *calledBy, variableStack *&vStack, bool returnSommet) {
+int startNewFunctionNum(unsigned int funcNum, unsigned int numParamsExpected,
+		loadedFunction *calledBy, variableStack *&vStack, bool returnSommet) {
 	loadedFunction *newFunc = new loadedFunction;
 	checkNew(newFunc);
 	newFunc->originalNumber = funcNum;
 
 	loadFunctionCode(newFunc);
 
-	if (newFunc->numArgs != (int)numParamsExpected) return fatal("Wrong number of parameters!");
-	if (newFunc->numArgs > newFunc->numLocals) return fatal("More arguments than local variable space!");
+	if (newFunc->numArgs != (int) numParamsExpected)
+		return fatal("Wrong number of parameters!");
+	if (newFunc->numArgs > newFunc->numLocals)
+		return fatal("More arguments than local variable space!");
 
 	// Now, lets copy the parameters from the calling function's stack...
 
 	while (numParamsExpected) {
-		numParamsExpected --;
-		if (vStack == NULL) return fatal("Corrupted file!The stack's empty and there were still parameters expected");
+		numParamsExpected--;
+		if (vStack == NULL)
+			return fatal(
+					"Corrupted file!The stack's empty and there were still parameters expected");
 		copyVariable(vStack->thisVar, newFunc->localVars[numParamsExpected]);
 		trimStack(vStack);
 	}
@@ -1397,7 +1494,7 @@ bool handleInput() {
 		} else {
 			l = 1;
 
-			setVariable(* launchResult, SVT_INT, 0/*launch(launchMe) > 31*/); //TODO:false value
+			setVariable(*launchResult, SVT_INT, 0/*launch(launchMe) > 31*/); //TODO:false value
 			launchMe = NULL;
 			launchResult = NULL;
 		}
@@ -1406,38 +1503,53 @@ bool handleInput() {
 		l = 0;
 	}
 
-	if (!overRegion) getOverRegion();
+	if (!overRegion)
+		getOverRegion();
 
 	if (input.justMoved) {
 		if (currentEvents->moveMouseFunction) {
-			if (!startNewFunctionNum(currentEvents->moveMouseFunction, 0, NULL, noStack)) return false;
+			if (!startNewFunctionNum(currentEvents->moveMouseFunction, 0, NULL,
+					noStack))
+				return false;
 		}
 	}
 	input.justMoved = false;
 
 	if (lastRegion != overRegion && currentEvents->focusFunction) {
 		variableStack *tempStack = new variableStack;
-		if (!checkNew(tempStack)) return false;
+		if (!checkNew(tempStack))
+			return false;
 
 		initVarNew(tempStack->thisVar);
 		if (overRegion) {
-			setVariable(tempStack->thisVar, SVT_OBJTYPE, overRegion->thisType->objectNum);
+			setVariable(tempStack->thisVar, SVT_OBJTYPE,
+					overRegion->thisType->objectNum);
 		} else {
 			setVariable(tempStack->thisVar, SVT_INT, 0);
 		}
 		tempStack->next = NULL;
-		if (!startNewFunctionNum(currentEvents->focusFunction, 1, NULL, tempStack)) return false;
+		if (!startNewFunctionNum(currentEvents->focusFunction, 1, NULL,
+				tempStack))
+			return false;
 	}
-	if (input.leftRelease && currentEvents->leftMouseUpFunction)  {
-		if (!startNewFunctionNum(currentEvents->leftMouseUpFunction, 0, NULL, noStack)) return false;
+	if (input.leftRelease && currentEvents->leftMouseUpFunction) {
+		if (!startNewFunctionNum(currentEvents->leftMouseUpFunction, 0, NULL,
+				noStack))
+			return false;
 	}
 	if (input.rightRelease && currentEvents->rightMouseUpFunction) {
-		if (!startNewFunctionNum(currentEvents->rightMouseUpFunction, 0, NULL, noStack)) return false;
+		if (!startNewFunctionNum(currentEvents->rightMouseUpFunction, 0, NULL,
+				noStack))
+			return false;
 	}
 	if (input.leftClick && currentEvents->leftMouseFunction)
-		if (!startNewFunctionNum(currentEvents->leftMouseFunction, 0, NULL, noStack)) return false;
+		if (!startNewFunctionNum(currentEvents->leftMouseFunction, 0, NULL,
+				noStack))
+			return false;
 	if (input.rightClick && currentEvents->rightMouseFunction) {
-		if (!startNewFunctionNum(currentEvents->rightMouseFunction, 0, NULL, noStack)) return false;
+		if (!startNewFunctionNum(currentEvents->rightMouseFunction, 0, NULL,
+				noStack))
+			return false;
 	}
 	if (input.keyPressed && currentEvents->spaceFunction) {
 		char *tempString = NULL;
@@ -1454,22 +1566,22 @@ bool handleInput() {
 		case 27:
 			tempString = copyString("ESCAPE");
 			break;
-		/*
-		case 1112:  tempString = copyString ("ALT+F1");     break;
-		case 1113:  tempString = copyString ("ALT+F2");     break;
-		case 1114:  tempString = copyString ("ALT+F3");     break;
-		case 1115:  tempString = copyString ("ALT+F4");     break;
-		case 1116:  tempString = copyString ("ALT+F5");     break;
-		case 1117:  tempString = copyString ("ALT+F6");     break;
-		case 1118:  tempString = copyString ("ALT+F7");     break;
-		case 1119:  tempString = copyString ("ALT+F8");     break;
-		case 1120:  tempString = copyString ("ALT+F9");     break;
-		case 1121:  tempString = copyString ("ALT+F10");    break;
-		case 1122:  tempString = copyString ("ALT+F11");    break;
-		case 1123:  tempString = copyString ("ALT+F12");    break;
-
-		case 2019:  tempString = copyString ("PAUSE");      break;
-		*/
+			/*
+			 case 1112:  tempString = copyString ("ALT+F1");     break;
+			 case 1113:  tempString = copyString ("ALT+F2");     break;
+			 case 1114:  tempString = copyString ("ALT+F3");     break;
+			 case 1115:  tempString = copyString ("ALT+F4");     break;
+			 case 1116:  tempString = copyString ("ALT+F5");     break;
+			 case 1117:  tempString = copyString ("ALT+F6");     break;
+			 case 1118:  tempString = copyString ("ALT+F7");     break;
+			 case 1119:  tempString = copyString ("ALT+F8");     break;
+			 case 1120:  tempString = copyString ("ALT+F9");     break;
+			 case 1121:  tempString = copyString ("ALT+F10");    break;
+			 case 1122:  tempString = copyString ("ALT+F11");    break;
+			 case 1123:  tempString = copyString ("ALT+F12");    break;
+
+			 case 2019:  tempString = copyString ("PAUSE");      break;
+			 */
 		case 63276:
 			tempString = copyString("PAGE UP");
 			break;
@@ -1494,10 +1606,10 @@ bool handleInput() {
 		case 63233:
 			tempString = copyString("DOWN");
 			break;
-		/*
-		case 2045:   tempString = copyString ("INSERT");     break;
-		case 2046:   tempString = copyString ("DELETE");     break;
-		*/
+			/*
+			 case 2045:   tempString = copyString ("INSERT");     break;
+			 case 2046:   tempString = copyString ("DELETE");     break;
+			 */
 		case 63236:
 			tempString = copyString("F1");
 			break;
@@ -1549,13 +1661,16 @@ bool handleInput() {
 
 		if (tempString) {
 			variableStack *tempStack = new variableStack;
-			if (!checkNew(tempStack)) return false;
+			if (!checkNew(tempStack))
+				return false;
 			initVarNew(tempStack->thisVar);
 			makeTextVar(tempStack->thisVar, tempString);
 			delete tempString;
 			tempString = NULL;
 			tempStack->next = NULL;
-			if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL, tempStack)) return false;
+			if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL,
+					tempStack))
+				return false;
 		}
 	}
 	input.rightClick = false;
diff --git a/engines/sludge/sludger.h b/engines/sludge/sludger.h
index d67192d..ef319db 100644
--- a/engines/sludge/sludger.h
+++ b/engines/sludge/sludger.h
@@ -59,17 +59,17 @@ struct lineOfCode {
 };
 
 struct loadedFunction {
-	int                         originalNumber;
-	lineOfCode                 *compiledLines;
-	int                         numLocals, timeLeft, numArgs;
-	variable                   *localVars;
-	variableStack              *stack;
-	variable                    reg;
-	unsigned int                runThisLine;
-	loadedFunction             *calledBy;
-	loadedFunction             *next;
-	bool                        returnSomething, isSpeech, unfreezable, cancelMe;
-	unsigned char               freezerLevel;
+	int originalNumber;
+	lineOfCode *compiledLines;
+	int numLocals, timeLeft, numArgs;
+	variable *localVars;
+	variableStack *stack;
+	variable reg;
+	unsigned int runThisLine;
+	loadedFunction *calledBy;
+	loadedFunction *next;
+	bool returnSomething, isSpeech, unfreezable, cancelMe;
+	unsigned char freezerLevel;
 };
 
 struct inputType {
@@ -80,10 +80,10 @@ struct inputType {
 extern unsigned char *gameIcon;
 extern int iconW, iconH;
 
-
 bool initSludge(char *);
 void sludgeDisplay();
-int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *, variableStack*&, bool = true);
+int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *,
+		variableStack*&, bool = true);
 bool handleInput();
 void restartFunction(loadedFunction *fun);
 bool loadFunctionCode(loadedFunction *newFunc);
@@ -92,7 +92,8 @@ void saveHandlers(Common::WriteStream *stream);
 
 void finishFunction(loadedFunction *fun);
 void abortFunction(loadedFunction *fun);
-Common::File *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion);
+Common::File *openAndVerify(char *filename, char extra1, char extra2,
+		const char *er, int &fileVersion);
 
 void freezeSubs();
 void unfreezeSubs();
diff --git a/engines/sludge/sound_bass.cpp b/engines/sludge/sound_bass.cpp
index 6f16d66..5bb4e79 100644
--- a/engines/sludge/sound_bass.cpp
+++ b/engines/sludge/sound_bass.cpp
@@ -49,9 +49,11 @@ soundThing soundCache[MAX_SAMPLES];
 int defVol = 128;
 int defSoundVol = 255;
 
-char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t size) {
+char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile,
+		uint32_t size) {
 	char *allData = new char[size];
-	if (!allData) return NULL;
+	if (!allData)
+		return NULL;
 	inputFile->read(allData, size);
 	finishAccess();
 
@@ -68,15 +70,17 @@ void stopMOD(int i) {
 
 int findInSoundCache(int a) {
 	int i;
-	for (i = 0; i < MAX_SAMPLES; i ++) {
-		if (soundCache[i].fileLoaded == a) return i;
+	for (i = 0; i < MAX_SAMPLES; i++) {
+		if (soundCache[i].fileLoaded == a)
+			return i;
 	}
 	return -1;
 }
 
 void huntKillSound(int filenum) {
 	int gotSlot = findInSoundCache(filenum);
-	if (gotSlot == -1) return;
+	if (gotSlot == -1)
+		return;
 	soundCache[gotSlot].looping = false;
 	BASS_SampleStop(soundCache[gotSlot].sample);
 }
@@ -90,7 +94,8 @@ void freeSound(int a) {
 
 void huntKillFreeSound(int filenum) {
 	int gotSlot = findInSoundCache(filenum);
-	if (gotSlot != -1) freeSound(gotSlot);
+	if (gotSlot != -1)
+		freeSound(gotSlot);
 }
 
 bool initSoundStuff(HWND hwnd) {
@@ -119,8 +124,10 @@ bool initSoundStuff(HWND hwnd) {
 void killSoundStuff() {
 	if (soundOK) {
 		int a;
-		for (a = 0; a < MAX_MODS;       a ++) stopMOD(a);
-		for (a = 0; a < MAX_SAMPLES;    a ++) freeSound(a);
+		for (a = 0; a < MAX_MODS; a++)
+			stopMOD(a);
+		for (a = 0; a < MAX_SAMPLES; a++)
+			freeSound(a);
 		BASS_Free();
 	}
 }
@@ -132,13 +139,19 @@ bool playMOD(int f, int a, int fromTrack) {
 
 		setResourceForFatal(f);
 		uint32_t length = openFileFromNum(f);
-		if (length == 0) return NULL;
+		if (length == 0)
+			return NULL;
 
 		char *memImage;
 		memImage = loadEntireFileToMemory(bigDataFile, length);
-		if (!memImage) return fatal(ERROR_MUSIC_MEMORY_LOW);
-
-		mod[a] = BASS_MusicLoad(true, memImage, 0, length, BASS_MUSIC_LOOP | BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0);
+		if (!memImage)
+			return fatal(ERROR_MUSIC_MEMORY_LOW);
+
+		mod[a] =
+				BASS_MusicLoad(true, memImage, 0, length,
+						BASS_MUSIC_LOOP
+								| BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/,
+						0);
 		delete memImage;
 
 		if (!mod[a]) {
@@ -149,8 +162,10 @@ bool playMOD(int f, int a, int fromTrack) {
 			if (!BASS_ChannelPlay(mod[a], true))
 				debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode());
 
-			BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER);
-			BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP);
+			BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0),
+					BASS_POS_MUSIC_ORDER);
+			BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP,
+					BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP);
 		}
 		setResourceForFatal(-1);
 	}
@@ -160,7 +175,8 @@ bool playMOD(int f, int a, int fromTrack) {
 void setMusicVolume(int a, int v) {
 	int ret;
 	if (soundOK && mod[a]) {
-		ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL, (float) v / 256);
+		ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL,
+				(float) v / 256);
 		if (!ret) {
 			debugOut("setMusicVolume: Error %d\n", BASS_ErrorGetCode());
 		}
@@ -176,7 +192,8 @@ void setSoundVolume(int a, int v) {
 		int ch = findInSoundCache(a);
 		if (ch != -1) {
 			if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel)) {
-				BASS_ChannelSetAttribute(soundCache[ch].mostRecentChannel, BASS_ATTRIB_VOL, (float) v / 256);
+				BASS_ChannelSetAttribute(soundCache[ch].mostRecentChannel,
+						BASS_ATTRIB_VOL, (float) v / 256);
 			}
 		}
 	}
@@ -186,7 +203,8 @@ bool stillPlayingSound(int ch) {
 	if (soundOK)
 		if (ch != -1)
 			if (soundCache[ch].fileLoaded != -1)
-				if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel) != BASS_ACTIVE_STOPPED)
+				if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel)
+						!= BASS_ACTIVE_STOPPED)
 					return true;
 	return false;
 }
@@ -212,8 +230,8 @@ int emptySoundSlot = 0;
 
 int findEmptySoundSlot() {
 	int t;
-	for (t = 0; t < MAX_SAMPLES; t ++) {
-		emptySoundSlot ++;
+	for (t = 0; t < MAX_SAMPLES; t++) {
+		emptySoundSlot++;
 		emptySoundSlot %= MAX_SAMPLES;
 		if (!soundCache[emptySoundSlot].sample)
 			return emptySoundSlot;
@@ -221,15 +239,16 @@ int findEmptySoundSlot() {
 
 	// Argh!They're all playing!Let's trash the oldest that's not looping...
 
-	for (t = 0; t < MAX_SAMPLES; t ++) {
-		emptySoundSlot ++;
+	for (t = 0; t < MAX_SAMPLES; t++) {
+		emptySoundSlot++;
 		emptySoundSlot %= MAX_SAMPLES;
-		if (!soundCache[emptySoundSlot].looping) return emptySoundSlot;
+		if (!soundCache[emptySoundSlot].looping)
+			return emptySoundSlot;
 	}
 
 	// Holy crap, they're all looping!What's this twat playing at?
 
-	emptySoundSlot ++;
+	emptySoundSlot++;
 	emptySoundSlot %= MAX_SAMPLES;
 	return emptySoundSlot;
 }
@@ -237,15 +256,15 @@ int findEmptySoundSlot() {
 int guessSoundFree = 0;
 
 /*
-void soundWarning (char * t, int i) {
-    FILE * u = fopen ("soundlog.txt", "at");
-    fprintf (u, "%s: %i\n", t, i);
-    fclose (u);
-}
-*/
+ void soundWarning (char * t, int i) {
+ FILE * u = fopen ("soundlog.txt", "at");
+ fprintf (u, "%s: %i\n", t, i);
+ fclose (u);
+ }
+ */
 
 bool forceRemoveSound() {
-	for (int a = 0; a < 8; a ++) {
+	for (int a = 0; a < 8; a++) {
 		if (soundCache[a].fileLoaded != -1 && !stillPlayingSound(a)) {
 //			soundWarning ("Deleting silent sound", a);
 			freeSound(a);
@@ -253,7 +272,7 @@ bool forceRemoveSound() {
 		}
 	}
 
-	for (int a = 0; a < 8; a ++) {
+	for (int a = 0; a < 8; a++) {
 		if (soundCache[a].fileLoaded != -1) {
 //			soundWarning ("Deleting playing sound", a);
 			freeSound(a);
@@ -267,16 +286,20 @@ bool forceRemoveSound() {
 int cacheSound(int f) {
 	setResourceForFatal(f);
 
-	if (!soundOK) return 0;
+	if (!soundOK)
+		return 0;
 
 	int a = findInSoundCache(f);
-	if (a != -1) return a;
-	if (f == -2) return -1;
+	if (a != -1)
+		return a;
+	if (f == -2)
+		return -1;
 	a = findEmptySoundSlot();
 	freeSound(a);
 
 	uint32_t length = openFileFromNum(f);
-	if (!length) return -1;
+	if (!length)
+		return -1;
 
 	char *memImage;
 
@@ -295,7 +318,8 @@ int cacheSound(int f) {
 
 	for (;;) {
 //		soundWarning ("  Trying to load sound into slot", a);
-		soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, 0);
+		soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535,
+				0);
 
 		if (soundCache[a].sample) {
 			soundCache[a].fileLoaded = f;
@@ -315,17 +339,21 @@ int cacheSound(int f) {
 bool startSound(int f, bool loopy) {
 	if (soundOK) {
 		int a = cacheSound(f);
-		if (a == -1) return false;
+		if (a == -1)
+			return false;
 
 		soundCache[a].looping = loopy;
 		soundCache[a].vol = defSoundVol;
 
-		soundCache[a].mostRecentChannel = BASS_SampleGetChannel(soundCache[a].sample, false);
+		soundCache[a].mostRecentChannel = BASS_SampleGetChannel(
+				soundCache[a].sample, false);
 		if (soundCache[a].mostRecentChannel) {
 			BASS_ChannelPlay(soundCache[a].mostRecentChannel, true);
-			BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel, BASS_ATTRIB_VOL, defSoundVol);
+			BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel,
+					BASS_ATTRIB_VOL, defSoundVol);
 			if (loopy) {
-				BASS_ChannelFlags(soundCache[a].mostRecentChannel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag
+				BASS_ChannelFlags(soundCache[a].mostRecentChannel,
+						BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag
 			}
 		}
 
@@ -334,22 +362,22 @@ bool startSound(int f, bool loopy) {
 }
 
 /*
-void debugSounds () {
-    FILE * fp = fopen ("newdebug.txt", "at");
-    if (fp) {
-        for (int aa = 0; aa < 32; aa ++) {
-            if (aa == EFFECT_CHANNELS) fprintf (fp, "|");
-            fprintf (fp, FSOUND_IsPlaying (aa) ? "#" : ".");
-        }
-        fprintf (fp, "\n");
-        fclose (fp);
-    }
-}
-// */
+ void debugSounds () {
+ FILE * fp = fopen ("newdebug.txt", "at");
+ if (fp) {
+ for (int aa = 0; aa < 32; aa ++) {
+ if (aa == EFFECT_CHANNELS) fprintf (fp, "|");
+ fprintf (fp, FSOUND_IsPlaying (aa) ? "#" : ".");
+ }
+ fprintf (fp, "\n");
+ fclose (fp);
+ }
+ }
+ // */
 
 void saveSounds(Common::WriteStream *stream) {
 	if (soundOK) {
-		for (int i = 0; i < MAX_SAMPLES; i ++) {
+		for (int i = 0; i < MAX_SAMPLES; i++) {
 			if (soundCache[i].looping) {
 				putch(1, stream);
 				put2bytes(soundCache[i].fileLoaded, stream);
@@ -363,7 +391,8 @@ void saveSounds(Common::WriteStream *stream) {
 }
 
 void loadSounds(Common::SeekableReadStream *stream) {
-	for (int i = 0; i < MAX_SAMPLES; i ++) freeSound(i);
+	for (int i = 0; i < MAX_SAMPLES; i++)
+		freeSound(i);
 
 	while (getch(stream)) {
 		int fileLoaded = get2bytes(stream);
@@ -379,11 +408,13 @@ bool getSoundCacheStack(stackHandler *sH) {
 	variable newFileHandle;
 	newFileHandle.varType = SVT_NULL;
 
-	for (int a = 0; a < MAX_SAMPLES; a ++) {
+	for (int a = 0; a < MAX_SAMPLES; a++) {
 		if (soundCache[a].fileLoaded != -1) {
 			setVariable(newFileHandle, SVT_FILE, soundCache[a].fileLoaded);
-			if (!addVarToStackQuick(newFileHandle, sH -> first)) return false;
-			if (sH -> last == NULL) sH -> last = sH -> first;
+			if (!addVarToStackQuick(newFileHandle, sH->first))
+				return false;
+			if (sH->last == NULL)
+				sH->last = sH->first;
 		}
 	}
 	return true;
diff --git a/engines/sludge/sound_openal.cpp b/engines/sludge/sound_openal.cpp
index 5faefdb..72824d3 100644
--- a/engines/sludge/sound_openal.cpp
+++ b/engines/sludge/sound_openal.cpp
@@ -97,7 +97,8 @@ bool initSoundStuff(HWND hwnd) {
 }
 
 void killSoundStuff() {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 #if 0
 	SilenceIKillYou = true;
 	for (int i = 0; i < MAX_SAMPLES; i ++) {
@@ -105,7 +106,7 @@ void killSoundStuff() {
 
 			if (! alureStopSource(soundCache[i].playingOnSource, AL_TRUE)) {
 				debugOut("Failed to stop source: %s\n",
-				         alureGetErrorString());
+						alureGetErrorString());
 			}
 
 		}
@@ -114,7 +115,7 @@ void killSoundStuff() {
 
 			if (! alureDestroyStream(soundCache[i].stream, 0, NULL)) {
 				debugOut("Failed to destroy stream: %s\n",
-				         alureGetErrorString());
+						alureGetErrorString());
 			}
 
 		}
@@ -125,7 +126,7 @@ void killSoundStuff() {
 
 			if (! alureStopSource(modCache[i].playingOnSource, AL_TRUE)) {
 				debugOut("Failed to stop source: %s\n",
-				         alureGetErrorString());
+						alureGetErrorString());
 			}
 
 		}
@@ -134,7 +135,7 @@ void killSoundStuff() {
 
 			if (! alureDestroyStream(modCache[i].stream, 0, NULL)) {
 				debugOut("Failed to destroy stream: %s\n",
-				         alureGetErrorString());
+						alureGetErrorString());
 			}
 
 		}
@@ -151,7 +152,8 @@ void killSoundStuff() {
  */
 
 void setMusicVolume(int a, int v) {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 
 	if (modCache[a].playing) {
 #if 0
@@ -165,7 +167,8 @@ void setDefaultMusicVolume(int v) {
 }
 
 void setSoundVolume(int a, int v) {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 	int ch = findInSoundCache(a);
 	if (ch != -1) {
 		if (soundCache[ch].playing) {
@@ -218,7 +221,7 @@ static void mod_eos_callback(void *cacheIndex, ALuint source) {
 
 	if (! alureDestroyStream(modCache[*a].stream, 0, NULL)) {
 		debugOut("Failed to destroy stream: %s\n",
-		         alureGetErrorString());
+				alureGetErrorString());
 	}
 
 	modCache[*a].stream = NULL;
@@ -232,7 +235,7 @@ static void mod_eos_callback(void *cacheIndex, ALuint source) {
 
 int findInSoundCache(int a) {
 	int i;
-	for (i = 0; i < MAX_SAMPLES; i ++) {
+	for (i = 0; i < MAX_SAMPLES; i++) {
 		if (soundCache[i].fileLoaded == a) {
 			return i;
 		}
@@ -241,7 +244,8 @@ int findInSoundCache(int a) {
 }
 
 void stopMOD(int i) {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 #if 0
 	alGetError();
 	if (modCache[i].playing) {
@@ -253,7 +257,8 @@ void stopMOD(int i) {
 }
 
 void huntKillSound(int filenum) {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 #if 0
 	// Clear OpenAL errors to make sure they don't block anything:
 	alGetError();
@@ -273,7 +278,8 @@ void huntKillSound(int filenum) {
 }
 
 void freeSound(int a) {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 #if 0
 	// Clear OpenAL errors to make sure they don't block anything:
 	alGetError();
@@ -283,12 +289,12 @@ void freeSound(int a) {
 	if (soundCache[a].playing) {
 		if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) {
 			debugOut("Failed to stop source: %s\n",
-			         alureGetErrorString());
+					alureGetErrorString());
 		}
 	}
 	if (! alureDestroyStream(soundCache[a].stream, 0, NULL)) {
 		debugOut("Failed to destroy stream: %s\n",
-		         alureGetErrorString());
+				alureGetErrorString());
 	}
 
 	soundCache[a].stream = NULL;
@@ -297,11 +303,12 @@ void freeSound(int a) {
 	SilenceIKillYou = false;
 }
 
-
 void huntKillFreeSound(int filenum) {
-	if (! soundOK) return;
+	if (!soundOK)
+		return;
 	int gotSlot = findInSoundCache(filenum);
-	if (gotSlot == -1) return;
+	if (gotSlot == -1)
+		return;
 	freeSound(gotSlot);
 }
 
@@ -339,10 +346,10 @@ void playStream(int a, bool isMOD, bool loopy) {
 
 	if (loopy) {
 		ok = alurePlaySourceStream(src, (*st).stream,
-		                           NUM_BUFS, -1, eos_callback, &intpointers[a]);
+				NUM_BUFS, -1, eos_callback, &intpointers[a]);
 	} else {
 		ok = alurePlaySourceStream(src, (*st).stream,
-		                           NUM_BUFS, 0, eos_callback, &intpointers[a]);
+				NUM_BUFS, 0, eos_callback, &intpointers[a]);
 	}
 
 	if (!ok) {
@@ -361,9 +368,11 @@ void playStream(int a, bool isMOD, bool loopy) {
 #endif
 }
 
-char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t size) {
+char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile,
+		uint32_t size) {
 	char *allData = new char[size];
-	if (! allData) return NULL;
+	if (!allData)
+		return NULL;
 
 	size_t bytes_read = inputFile->read(allData, size);
 	if (bytes_read != size && inputFile->err()) {
@@ -376,7 +385,8 @@ char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t siz
 }
 
 bool playMOD(int f, int a, int fromTrack) {
-	if (! soundOK) return true;
+	if (!soundOK)
+		return true;
 	stopMOD(a);
 
 	setResourceForFatal(f);
@@ -400,7 +410,7 @@ bool playMOD(int f, int a, int fromTrack) {
 
 		if (! alureSetStreamOrder(modCache[a].stream, fromTrack)) {
 			debugOut("Failed to set stream order: %s\n",
-			         alureGetErrorString());
+					alureGetErrorString());
 		}
 
 		playStream(a, true, true);
@@ -408,7 +418,7 @@ bool playMOD(int f, int a, int fromTrack) {
 	} else {
 
 		debugOut("Failed to create stream from MOD: %s\n",
-		         alureGetErrorString());
+				alureGetErrorString());
 
 		warning(ERROR_MUSIC_ODDNESS);
 		soundCache[a].stream = NULL;
@@ -431,15 +441,15 @@ bool stillPlayingSound(int ch) {
 }
 
 bool forceRemoveSound() {
-	for (int a = 0; a < MAX_SAMPLES; a ++) {
-		if (soundCache[a].fileLoaded != -1 && ! stillPlayingSound(a)) {
+	for (int a = 0; a < MAX_SAMPLES; a++) {
+		if (soundCache[a].fileLoaded != -1 && !stillPlayingSound(a)) {
 //			soundWarning ("Deleting silent sound", a);
 			freeSound(a);
 			return 1;
 		}
 	}
 
-	for (int a = 0; a < MAX_SAMPLES; a ++) {
+	for (int a = 0; a < MAX_SAMPLES; a++) {
 		if (soundCache[a].fileLoaded != -1) {
 //			soundWarning ("Deleting playing sound", a);
 			freeSound(a);
@@ -454,17 +464,17 @@ int emptySoundSlot = 0;
 
 int findEmptySoundSlot() {
 	int t;
-	for (t = 0; t < MAX_SAMPLES; t ++) {
-		emptySoundSlot ++;
+	for (t = 0; t < MAX_SAMPLES; t++) {
+		emptySoundSlot++;
 		emptySoundSlot %= MAX_SAMPLES;
 #if 0
 		if (soundCache[emptySoundSlot].stream == NULL)
-			return emptySoundSlot;
+		return emptySoundSlot;
 #endif
 	}
 
-	for (t = 0; t < MAX_SAMPLES; t ++) {
-		emptySoundSlot ++;
+	for (t = 0; t < MAX_SAMPLES; t++) {
+		emptySoundSlot++;
 		emptySoundSlot %= MAX_SAMPLES;
 		if (!soundCache[emptySoundSlot].playing)
 			return emptySoundSlot;
@@ -472,22 +482,24 @@ int findEmptySoundSlot() {
 
 	// Argh! They're all playing! Let's trash the oldest that's not looping...
 
-	for (t = 0; t < MAX_SAMPLES; t ++) {
-		emptySoundSlot ++;
+	for (t = 0; t < MAX_SAMPLES; t++) {
+		emptySoundSlot++;
 		emptySoundSlot %= MAX_SAMPLES;
-		if (! soundCache[emptySoundSlot].looping) return emptySoundSlot;
+		if (!soundCache[emptySoundSlot].looping)
+			return emptySoundSlot;
 	}
 
 	// Holy crap, they're all looping! What's this twat playing at?
 
-	emptySoundSlot ++;
+	emptySoundSlot++;
 	emptySoundSlot %= MAX_SAMPLES;
 	return emptySoundSlot;
 }
 
 int cacheSound(int f) {
 
-	if (! soundOK) return -1;
+	if (!soundOK)
+		return -1;
 
 	unsigned int chunkLength;
 	int retval;
@@ -506,12 +518,12 @@ int cacheSound(int f) {
 		if (soundCache[a].playing) {
 			if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) {
 				debugOut("Failed to stop source: %s\n",
-				         alureGetErrorString());
+						alureGetErrorString());
 			}
 		}
 		if (! alureRewindStream(soundCache[a].stream)) {
 			debugOut("Failed to rewind stream: %s\n",
-			         alureGetErrorString());
+					alureGetErrorString());
 		}
 
 		return a;
@@ -560,7 +572,7 @@ int cacheSound(int f) {
 	} else {
 
 		debugOut("Failed to create stream from sound: %s\n",
-		         alureGetErrorString());
+				alureGetErrorString());
 
 		warning(ERROR_SOUND_ODDNESS);
 		soundCache[a].stream = NULL;
@@ -592,7 +604,7 @@ bool startSound(int f, bool loopy) {
 
 void saveSounds(Common::WriteStream *stream) {
 	if (soundOK) {
-		for (int i = 0; i < MAX_SAMPLES; i ++) {
+		for (int i = 0; i < MAX_SAMPLES; i++) {
 			if (soundCache[i].looping) {
 				putch(1, stream);
 				put2bytes(soundCache[i].fileLoaded, stream);
@@ -606,7 +618,8 @@ void saveSounds(Common::WriteStream *stream) {
 }
 
 void loadSounds(Common::SeekableReadStream *stream) {
-	for (int i = 0; i < MAX_SAMPLES; i ++) freeSound(i);
+	for (int i = 0; i < MAX_SAMPLES; i++)
+		freeSound(i);
 
 	while (getch(stream)) {
 		int fileLoaded = get2bytes(stream);
@@ -622,11 +635,13 @@ bool getSoundCacheStack(stackHandler *sH) {
 	variable newFileHandle;
 	newFileHandle.varType = SVT_NULL;
 
-	for (int a = 0; a < MAX_SAMPLES; a ++) {
+	for (int a = 0; a < MAX_SAMPLES; a++) {
 		if (soundCache[a].fileLoaded != -1) {
 			setVariable(newFileHandle, SVT_FILE, soundCache[a].fileLoaded);
-			if (! addVarToStackQuick(newFileHandle, sH -> first)) return false;
-			if (sH -> last == NULL) sH -> last = sH -> first;
+			if (!addVarToStackQuick(newFileHandle, sH->first))
+				return false;
+			if (sH->last == NULL)
+				sH->last = sH->first;
 		}
 	}
 	return true;
@@ -634,19 +649,22 @@ bool getSoundCacheStack(stackHandler *sH) {
 
 soundList *deleteSoundFromList(soundList *s) {
 	// Don't delete a playing sound.
-	if (s->cacheIndex) return NULL;
+	if (s->cacheIndex)
+		return NULL;
 
 	soundList *o = NULL;
-	if (! s->next) {
+	if (!s->next) {
 		o = s->prev;
-		if (o) o-> next = NULL;
+		if (o)
+			o->next = NULL;
 		delete s;
 		return o;
 	}
 	if (s != s->next) {
 		o = s->next;
 		o->prev = s->prev;
-		if (o->prev) o->prev->next = o;
+		if (o->prev)
+			o->prev->next = o;
 	}
 	delete s;
 	return o;
@@ -699,9 +717,9 @@ void playSoundList(soundList *s) {
 		}
 		soundCache[a].looping = false;
 		if (s->vol < 0)
-			soundCache[a].vol = defSoundVol;
+		soundCache[a].vol = defSoundVol;
 		else
-			soundCache[a].vol = s->vol;
+		soundCache[a].vol = s->vol;
 		s-> cacheIndex = a;
 
 		ALboolean ok;
@@ -719,7 +737,7 @@ void playSoundList(soundList *s) {
 		alSourcef(src, AL_GAIN, (float) soundCache[a].vol / 256);
 
 		ok = alurePlaySourceStream(src, (*st).stream,
-		                           NUM_BUFS, 0, list_eos_callback, s);
+				NUM_BUFS, 0, list_eos_callback, s);
 
 		if (!ok) {
 
@@ -753,7 +771,7 @@ void playMovieStream(int a) {
 	alSourcef(src, AL_GAIN, (float) soundCache[a].vol / 256);
 
 	ok = alurePlaySourceStream(src, soundCache[a].stream,
-	                           10, 0, sound_eos_callback, &intpointers[a]);
+			10, 0, sound_eos_callback, &intpointers[a]);
 	if (!ok) {
 		debugOut("Failed to play stream: %s\n", alureGetErrorString());
 		alDeleteSources(1, &src);
@@ -771,7 +789,7 @@ void playMovieStream(int a) {
 
 #if 0
 int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
-                   ALuint(*callback)(void *userdata, ALubyte *data, ALuint bytes)) {
+		ALuint(*callback)(void *userdata, ALubyte *data, ALuint bytes)) {
 	if (! soundOK) return 0;
 
 	int retval;
@@ -782,9 +800,9 @@ int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
 #if 0
 	// audioChannel * sampleRate gives us a buffer of half a second. Not much, but it should be enough.
 	soundCache[a].stream = alureCreateStreamFromCallback(
-	                           callback,
-	                           &intpointers[a], format, samplerate,
-	                           audioChannels * samplerate, 0, NULL);
+			callback,
+			&intpointers[a], format, samplerate,
+			audioChannels * samplerate, 0, NULL);
 #endif
 	if (soundCache[a].stream != NULL) {
 		soundCache[a].fileLoaded = f;
@@ -793,7 +811,7 @@ int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
 	} else {
 #if 0
 		debugOut("Failed to create stream from sound: %s\n",
-		         alureGetErrorString());
+				alureGetErrorString());
 #endif
 		warning(ERROR_SOUND_ODDNESS);
 		soundCache[a].stream = NULL;
diff --git a/engines/sludge/sprbanks.cpp b/engines/sludge/sprbanks.cpp
index c95e405..8598cb5 100644
--- a/engines/sludge/sprbanks.cpp
+++ b/engines/sludge/sprbanks.cpp
@@ -31,42 +31,43 @@ loadedSpriteBank *allLoadedBanks = NULL;
 extern spriteBank theFont;
 extern int loadedFontNum, fontTableSize;
 
-
 loadedSpriteBank *loadBankForAnim(int ID) {
 	//debugOut ("loadBankForAnim: Looking for sprite bank with ID %d\n", ID);
 	loadedSpriteBank *returnMe = allLoadedBanks;
 	while (returnMe) {
-		if (returnMe -> ID == ID) {
+		if (returnMe->ID == ID) {
 			//debugOut ("loadBankForAnim: Found existing sprite bank with ID %d\n", returnMe -> ID);
 			return returnMe;
 		}
-		returnMe = returnMe -> next;
+		returnMe = returnMe->next;
 	}
 	returnMe = new loadedSpriteBank;
 	//debugOut ("loadBankForAnim: No existing sprite bank with ID %d\n", ID);
 	if (checkNew(returnMe)) {
-		returnMe -> ID = ID;
-		if (loadSpriteBank(ID, returnMe -> bank, false)) {
-			returnMe -> timesUsed = 0;
-			returnMe -> next = allLoadedBanks;
+		returnMe->ID = ID;
+		if (loadSpriteBank(ID, returnMe->bank, false)) {
+			returnMe->timesUsed = 0;
+			returnMe->next = allLoadedBanks;
 			allLoadedBanks = returnMe;
 			debugOut("loadBankForAnim: New sprite bank created OK\n");
 			return returnMe;
 		} else {
-			debugOut("loadBankForAnim: I guess I couldn't load the sprites...\n");
+			debugOut(
+					"loadBankForAnim: I guess I couldn't load the sprites...\n");
 			return NULL;
 		}
-	} else return NULL;
+	} else
+		return NULL;
 }
 
 void reloadSpriteTextures() {
 	loadedSpriteBank *spriteBank = allLoadedBanks;
 	while (spriteBank) {
 		//fprintf (stderr, "Reloading bank %d: %s.\n", spriteBank->ID, resourceNameFromNum (spriteBank->ID));
-		delete spriteBank-> bank.sprites;
-		spriteBank-> bank.sprites = NULL;
+		delete spriteBank->bank.sprites;
+		spriteBank->bank.sprites = NULL;
 		loadSpriteBank(spriteBank->ID, spriteBank->bank, false);
-		spriteBank = spriteBank -> next;
+		spriteBank = spriteBank->next;
 	}
 	if (fontTableSize) {
 		delete theFont.sprites;
diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index ec4144f..5b372e6 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -57,7 +57,6 @@ extern float cameraZoom;
 
 unsigned char currentBurnR = 0, currentBurnG = 0, currentBurnB = 0;
 
-
 void forgetSpriteBank(spriteBank &forgetme) {
 #if 0
 	deleteTextures(forgetme.myPalette.numTextures, forgetme.myPalette.tex_names);
@@ -70,49 +69,53 @@ void forgetSpriteBank(spriteBank &forgetme) {
 	delete [] forgetme.myPalette.tex_names;
 	forgetme.myPalette.tex_names = NULL;
 #endif
-	delete [] forgetme.myPalette.tex_w;
+	delete[] forgetme.myPalette.tex_w;
 	forgetme.myPalette.tex_w = NULL;
-	delete [] forgetme.myPalette.tex_h;
+	delete[] forgetme.myPalette.tex_h;
 	forgetme.myPalette.tex_h = NULL;
 
 	if (forgetme.myPalette.pal) {
-		delete  [] forgetme.myPalette.pal;
+		delete[] forgetme.myPalette.pal;
 		forgetme.myPalette.pal = NULL;
-		delete  [] forgetme.myPalette.r;
+		delete[] forgetme.myPalette.r;
 		forgetme.myPalette.r = NULL;
-		delete  [] forgetme.myPalette.g;
+		delete[] forgetme.myPalette.g;
 		forgetme.myPalette.g = NULL;
-		delete  [] forgetme.myPalette.b;
+		delete[] forgetme.myPalette.b;
 		forgetme.myPalette.b = NULL;
 	}
 
 	delete forgetme.sprites;
 	forgetme.sprites = NULL;
 
-
 	// TODO: also remove sprite bank from allLoadedBanks
 	// And add a function call for this function to the scripting language
 }
 
 bool reserveSpritePal(spritePalette &sP, int n) {
 	if (sP.pal) {
-		delete  [] sP.pal;
-		delete  [] sP.r;
-		delete  [] sP.g;
-		delete  [] sP.b;
+		delete[] sP.pal;
+		delete[] sP.r;
+		delete[] sP.g;
+		delete[] sP.b;
 	}
 
-	sP.pal = new unsigned short int [n];
-	if (! checkNew(sP.pal)) return false;
-
-	sP.r = new unsigned char [n];
-	if (! checkNew(sP.r)) return false;
-	sP.g = new unsigned char [n];
-	if (! checkNew(sP.g)) return false;
-	sP.b = new unsigned char [n];
-	if (! checkNew(sP.b)) return false;
+	sP.pal = new unsigned short int[n];
+	if (!checkNew(sP.pal))
+		return false;
+
+	sP.r = new unsigned char[n];
+	if (!checkNew(sP.r))
+		return false;
+	sP.g = new unsigned char[n];
+	if (!checkNew(sP.g))
+		return false;
+	sP.b = new unsigned char[n];
+	if (!checkNew(sP.b))
+		return false;
 	sP.total = n;
-	return (bool)(sP.pal != NULL) && (sP.r != NULL) && (sP.g != NULL) && (sP.b != NULL);
+	return (bool) (sP.pal != NULL) && (sP.r != NULL) && (sP.g != NULL)
+			&& (sP.b != NULL);
 }
 
 bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
@@ -173,60 +176,60 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
 
 	for (i = 0; i < total; i ++) {
 		switch (spriteBankVersion) {
-		case 3: {
-			loadhere.sprites[i].xhot = getSigned(bigDataFile);
-			loadhere.sprites[i].yhot = getSigned(bigDataFile);
+			case 3: {
+				loadhere.sprites[i].xhot = getSigned(bigDataFile);
+				loadhere.sprites[i].yhot = getSigned(bigDataFile);
 
-			png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-			if (!png_ptr) {
-				return fatal("Can't open sprite bank / font.");
-			}
+				png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+				if (!png_ptr) {
+					return fatal("Can't open sprite bank / font.");
+				}
 
-			png_infop info_ptr = png_create_info_struct(png_ptr);
-			if (!info_ptr) {
-				png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
-				return fatal("Can't open sprite bank / font.");
-			}
+				png_infop info_ptr = png_create_info_struct(png_ptr);
+				if (!info_ptr) {
+					png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+					return fatal("Can't open sprite bank / font.");
+				}
 
-			png_infop end_info = png_create_info_struct(png_ptr);
-			if (!end_info) {
-				png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-				return fatal("Can't open sprite bank / font.");
-			}
-			png_init_io(png_ptr, bigDataFile);      // Tell libpng which file to read
-			png_set_sig_bytes(png_ptr, 8);          // No sig
+				png_infop end_info = png_create_info_struct(png_ptr);
+				if (!end_info) {
+					png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+					return fatal("Can't open sprite bank / font.");
+				}
+				png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read
+				png_set_sig_bytes(png_ptr, 8);// No sig
 
-			png_read_info(png_ptr, info_ptr);
+				png_read_info(png_ptr, info_ptr);
 
-			png_uint_32 width, height;
-			int bit_depth, color_type, interlace_type, compression_type, filter_method;
-			png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
+				png_uint_32 width, height;
+				int bit_depth, color_type, interlace_type, compression_type, filter_method;
+				png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
 
-			int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+				int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
 
-			unsigned char *row_pointers[height];
-			spriteData[i] = new unsigned char [rowbytes * height];
-			if (! checkNew(spriteData[i])) return false;
+				unsigned char *row_pointers[height];
+				spriteData[i] = new unsigned char [rowbytes * height];
+				if (! checkNew(spriteData[i])) return false;
 
-			for (unsigned int row = 0; row < height; row++)
+				for (unsigned int row = 0; row < height; row++)
 				row_pointers[row] = spriteData[i] + row * rowbytes;
 
-			png_read_image(png_ptr, (png_byte **) row_pointers);
-			png_read_end(png_ptr, NULL);
-			png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+				png_read_image(png_ptr, (png_byte **) row_pointers);
+				png_read_end(png_ptr, NULL);
+				png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
 
-			picwidth = loadhere.sprites[i].width = width;
-			picheight = loadhere.sprites[i].height = height;
-			break;
-		}
-		case 2:
+				picwidth = loadhere.sprites[i].width = width;
+				picheight = loadhere.sprites[i].height = height;
+				break;
+			}
+			case 2:
 			picwidth = get2bytes(bigDataFile);
 			picheight = get2bytes(bigDataFile);
 			loadhere.sprites[i].xhot = getSigned(bigDataFile);
 			loadhere.sprites[i].yhot = getSigned(bigDataFile);
 			break;
 
-		default:
+			default:
 			picwidth = (byte) fgetc(bigDataFile);
 			picheight = (byte) fgetc(bigDataFile);
 			loadhere.sprites[i].xhot = fgetc(bigDataFile);
@@ -256,27 +259,27 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
 			}
 			spriteData[i] = data;
 			switch (spriteBankVersion) {
-			case 2: {       // RUN LENGTH COMPRESSED DATA
-				unsigned size = picwidth * picheight;
-				unsigned pip = 0;
-
-				while (pip < size) {
-					byte col = fgetc(bigDataFile);
-					int looper;
-
-					if (col > howmany) {
-						col -= howmany + 1;
-						looper = fgetc(bigDataFile) + 1;
-					} else looper = 1;
-
-					while (looper --) {
-						data[pip ++] = col;
+				case 2: {       // RUN LENGTH COMPRESSED DATA
+					unsigned size = picwidth * picheight;
+					unsigned pip = 0;
+
+					while (pip < size) {
+						byte col = fgetc(bigDataFile);
+						int looper;
+
+						if (col > howmany) {
+							col -= howmany + 1;
+							looper = fgetc(bigDataFile) + 1;
+						} else looper = 1;
+
+						while (looper --) {
+							data[pip ++] = col;
+						}
 					}
 				}
-			}
-			break;
+				break;
 
-			default:        // RAW DATA
+				default:        // RAW DATA
 				size_t bytes_read = fread(data, picwidth, picheight, bigDataFile);
 				if (bytes_read != picwidth * picheight && ferror(bigDataFile)) {
 					debugOut("Reading error in loadSpriteBank.\n");
@@ -287,7 +290,6 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
 	}
 	numTextures++;
 
-
 	if (! spriteBankVersion) {
 		howmany = fgetc(bigDataFile);
 		startIndex = fgetc(bigDataFile);
@@ -368,9 +370,9 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
 						target[1] = (GLubyte) 255;
 						target[2] = (GLubyte) 255;
 						if (s)
-							target[3] = (GLubyte) loadhere.myPalette.r[s];
+						target[3] = (GLubyte) loadhere.myPalette.r[s];
 						/*else
-						    target[3] = (GLubyte) 0;*/
+						 target[3] = (GLubyte) 0;*/
 					}
 				} else {
 					target[0] = (GLubyte) spriteData[i][fromhere++];
@@ -390,7 +392,7 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
 
 	glGenTextures(numTextures, loadhere.myPalette.tex_names);
 	if (isFont)
-		glGenTextures(numTextures, loadhere.myPalette.burnTex_names);
+	glGenTextures(numTextures, loadhere.myPalette.burnTex_names);
 
 #endif
 
@@ -436,7 +438,8 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
 	return true;
 }
 
-void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal) {
+void pasteSpriteToBackDrop(int x1, int y1, sprite &single,
+		const spritePalette &fontPal) {
 #if 0
 	float tx1 = (float)(single.tex_x) / fontPal.tex_w[single.texNum];
 	float ty1 = 0.0;
@@ -490,7 +493,6 @@ void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &
 		while (yoffset < diffY) {
 			int h = (diffY - yoffset < viewportHeight) ? diffY - yoffset : viewportHeight;
 
-
 			// Render the sprite to the backdrop
 			// (using mulitexturing, so the backdrop is seen where alpha < 1.0)
 			glActiveTexture(GL_TEXTURE2);
@@ -499,7 +501,7 @@ void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &
 
 			glUseProgram(shader.paste);
 			GLint uniform = glGetUniformLocation(shader.paste, "useLightTexture");
-			if (uniform >= 0) glUniform1i(uniform, 0); // No lighting
+			if (uniform >= 0) glUniform1i(uniform, 0);// No lighting
 
 			setPMVMatrix(shader.paste);
 
@@ -536,7 +538,8 @@ void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &
 	setPixelCoords(false);
 }
 
-void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal) {
+void burnSpriteToBackDrop(int x1, int y1, sprite &single,
+		const spritePalette &fontPal) {
 #if 0
 	float tx1 = (float)(single.tex_x - 0.5) / fontPal.tex_w[single.texNum];
 	float ty1 = 0.0;
@@ -626,7 +629,7 @@ void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &f
 			glBindTexture(GL_TEXTURE_2D, fontPal.burnTex_names[single.texNum]);
 
 //FIXME: Test this some more. Also pasting the backdrop again is not strictly necessary but allows using the paste shader.
-			drawQuad(shader.paste, spriteVertices, 3, spriteTexCoords, NULL,  backdropTexCoords);
+			drawQuad(shader.paste, spriteVertices, 3, spriteTexCoords, NULL, backdropTexCoords);
 			glUseProgram(0);
 
 			// Copy Our ViewPort To The Texture
@@ -644,17 +647,19 @@ void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &f
 extern GLuint backdropTextureName;
 #endif
 
-void fontSprite(bool flip, int x, int y, sprite &single, const spritePalette &fontPal) {
+void fontSprite(bool flip, int x, int y, sprite &single,
+		const spritePalette &fontPal) {
 
-	float tx1 = (float)(single.tex_x - 0.5) / fontPal.tex_w[single.texNum];
+	float tx1 = (float) (single.tex_x - 0.5) / fontPal.tex_w[single.texNum];
 	float ty1 = 0.0;
-	float tx2 = (float)(single.tex_x + single.width + (flip ? 1.0 : 0.5)) / fontPal.tex_w[single.texNum];
-	float ty2 = (float)(single.height + 2) / fontPal.tex_h[single.texNum];
+	float tx2 = (float) (single.tex_x + single.width + (flip ? 1.0 : 0.5))
+			/ fontPal.tex_w[single.texNum];
+	float ty2 = (float) (single.height + 2) / fontPal.tex_h[single.texNum];
 
-	float x1 = (float)x - (float)single.xhot / cameraZoom;
-	float y1 = (float)y - (float)single.yhot / cameraZoom;
-	float x2 = x1 + (float)single.width / cameraZoom;
-	float y2 = y1 + (float)single.height / cameraZoom;
+	float x1 = (float) x - (float) single.xhot / cameraZoom;
+	float y1 = (float) y - (float) single.yhot / cameraZoom;
+	float x2 = x1 + (float) single.width / cameraZoom;
+	float y2 = y1 + (float) single.height / cameraZoom;
 
 #if 0
 	GLfloat vertices[] = {
@@ -707,13 +712,11 @@ void fontSprite(int x, int y, sprite &single, const spritePalette &fontPal) {
 	fontSprite(false, x, y, single, fontPal);
 }
 
-void flipFontSprite(int x, int y, sprite &single, const spritePalette &fontPal) {
+void flipFontSprite(int x, int y, sprite &single,
+		const spritePalette &fontPal) {
 	fontSprite(true, x, y, single, fontPal);
 }
 
-
-
-
 unsigned char curLight[3];
 
 void setDrawMode(onScreenPerson *thisPerson) {
@@ -734,7 +737,8 @@ extern GLuint backdropTextureName;
 
 bool checkColourChange(bool reset);
 
-bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, bool mirror) {
+bool scaleSprite(sprite &single, const spritePalette &fontPal,
+		onScreenPerson *thisPerson, bool mirror) {
 #if 0
 	float x = thisPerson->x;
 	float y = thisPerson->y;
@@ -758,9 +762,9 @@ bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *t
 		x = x / cameraZoom;
 		y = y / cameraZoom;
 		if (single.xhot < 0)
-			x1 = x - (int)((mirror ? (float)(single.width - single.xhot) : (float)(single.xhot + 1)) * scale / cameraZoom);
+		x1 = x - (int)((mirror ? (float)(single.width - single.xhot) : (float)(single.xhot + 1)) * scale / cameraZoom);
 		else
-			x1 = x - (int)((mirror ? (float)(single.width - (single.xhot + 1)) : (float)single.xhot) * scale / cameraZoom);
+		x1 = x - (int)((mirror ? (float)(single.width - (single.xhot + 1)) : (float)single.xhot) * scale / cameraZoom);
 		y1 = y - (int)((single.yhot - thisPerson->floaty) * scale / cameraZoom);
 		x2 = x1 + (int)(diffX / cameraZoom);
 		y2 = y1 + (int)(diffY / cameraZoom);
@@ -768,9 +772,9 @@ bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *t
 		x -= cameraX;
 		y -= cameraY;
 		if (single.xhot < 0)
-			x1 = x - (int)((mirror ? (float)(single.width - single.xhot) : (float)(single.xhot + 1)) * scale);
+		x1 = x - (int)((mirror ? (float)(single.width - single.xhot) : (float)(single.xhot + 1)) * scale);
 		else
-			x1 = x - (int)((mirror ? (float)(single.width - (single.xhot + 1)) : (float)single.xhot) * scale);
+		x1 = x - (int)((mirror ? (float)(single.width - (single.xhot + 1)) : (float)single.xhot) * scale);
 		y1 = y - (int)((single.yhot - thisPerson->floaty) * scale);
 		x2 = x1 + diffX;
 		y2 = y1 + diffY;
@@ -843,7 +847,7 @@ bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *t
 	}
 #ifndef HAVE_GLES2
 	if (!(thisPerson->extra & EXTRA_RECTANGULAR))
-		checkColourChange(true);
+	checkColourChange(true);
 #endif
 	setDrawMode(thisPerson);
 
@@ -909,7 +913,8 @@ bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *t
 }
 
 // Paste a scaled sprite onto the backdrop
-void fixScaleSprite(int x, int y, sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, int camX, int camY, bool mirror) {
+void fixScaleSprite(int x, int y, sprite &single, const spritePalette &fontPal,
+		onScreenPerson *thisPerson, int camX, int camY, bool mirror) {
 #if 0
 	float scale = thisPerson-> scale;
 	bool useZB = !(thisPerson->extra & EXTRA_NOZB);
@@ -926,9 +931,9 @@ void fixScaleSprite(int x, int y, sprite &single, const spritePalette &fontPal,
 	int diffY = (int)(((float)single.height) * scale);
 	int x1;
 	if (single.xhot < 0)
-		x1 = x - (int)((mirror ? (float)(single.width - single.xhot) : (float)(single.xhot + 1)) * scale);
+	x1 = x - (int)((mirror ? (float)(single.width - single.xhot) : (float)(single.xhot + 1)) * scale);
 	else
-		x1 = x - (int)((mirror ? (float)(single.width - (single.xhot + 1)) : (float)single.xhot) * scale);
+	x1 = x - (int)((mirror ? (float)(single.width - (single.xhot + 1)) : (float)single.xhot) * scale);
 	int y1 = y - (int)((single.yhot - thisPerson->floaty) * scale);
 
 	float spriteWidth = diffX;
@@ -942,7 +947,6 @@ void fixScaleSprite(int x, int y, sprite &single, const spritePalette &fontPal,
 
 	GLfloat z;
 
-
 	if (useZB && zBuffer.numPanels) {
 		int i;
 		for (i = 1; i < zBuffer.numPanels; i++) {
diff --git a/engines/sludge/sprites.h b/engines/sludge/sprites.h
index 2a617bb..067c84a 100644
--- a/engines/sludge/sprites.h
+++ b/engines/sludge/sprites.h
@@ -51,23 +51,24 @@ public:
 	GLuint *tex_names;
 	GLuint *burnTex_names;
 #endif
-	int *tex_w, * tex_h;
+	int *tex_w, *tex_h;
 	int numTextures;
 	unsigned char originalRed, originalGreen, originalBlue, total;
 
-	spritePalette(): pal(0), r(0), g(0), b(0)/*, tex_names(0), burnTex_names(0)*/
-		, tex_w(0), tex_h(0), numTextures(0)
-		, total(0) {}
+	spritePalette() :
+			pal(0), r(0), g(0), b(0)/*, tex_names(0), burnTex_names(0)*/
+			, tex_w(0), tex_h(0), numTextures(0), total(0) {
+	}
 
 	~spritePalette() {
-		delete [] pal;
-		delete [] r;
-		delete [] g;
-		delete [] b;
+		delete[] pal;
+		delete[] r;
+		delete[] g;
+		delete[] b;
 //		delete [] tex_names;
 //		delete [] burnTex_names;
-		delete [] tex_w;
-		delete [] tex_h;
+		delete[] tex_w;
+		delete[] tex_h;
 	}
 };
 
@@ -84,13 +85,19 @@ bool loadSpriteBank(char *filename, spriteBank &loadhere);
 bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont);
 
 void fontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal);
-void flipFontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal);
+void flipFontSprite(int x1, int y1, sprite &single,
+		const spritePalette &fontPal);
 
-bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, bool mirror);
-void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal);
+bool scaleSprite(sprite &single, const spritePalette &fontPal,
+		onScreenPerson *thisPerson, bool mirror);
+void pasteSpriteToBackDrop(int x1, int y1, sprite &single,
+		const spritePalette &fontPal);
 bool reserveSpritePal(spritePalette &sP, int n);
-void fixScaleSprite(int x1, int y1, sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, const int camX, const int camY, bool);
-void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal);
+void fixScaleSprite(int x1, int y1, sprite &single,
+		const spritePalette &fontPal, onScreenPerson *thisPerson,
+		const int camX, const int camY, bool);
+void burnSpriteToBackDrop(int x1, int y1, sprite &single,
+		const spritePalette &fontPal);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/stringy.cpp b/engines/sludge/stringy.cpp
index a5440b6..5446f57 100644
--- a/engines/sludge/stringy.cpp
+++ b/engines/sludge/stringy.cpp
@@ -28,15 +28,17 @@
 namespace Sludge {
 
 char *copyString(const char *copyMe) {
-	char *newString = new char [strlen(copyMe) + 1];
-	if (! checkNew(newString)) return NULL;
+	char *newString = new char[strlen(copyMe) + 1];
+	if (!checkNew(newString))
+		return NULL;
 	strcpy(newString, copyMe);
 	return newString;
 }
 
 char *joinStrings(const char *s1, const char *s2) {
-	char *newString = new char [strlen(s1) + strlen(s2) + 1];
-	if (! checkNew(newString)) return NULL;
+	char *newString = new char[strlen(s1) + strlen(s2) + 1];
+	if (!checkNew(newString))
+		return NULL;
 	sprintf(newString, "%s%s", s1, s2);
 	return newString;
 }
diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp
index abee33c..5e6c10d 100644
--- a/engines/sludge/talk.cpp
+++ b/engines/sludge/talk.cpp
@@ -60,7 +60,7 @@ void killAllSpeech() {
 	}
 
 	if (speech->currentTalker) {
-		makeSilent(* (speech->currentTalker));
+		makeSilent(*(speech->currentTalker));
 		speech->currentTalker = NULL;
 	}
 
@@ -96,8 +96,9 @@ void addSpeechLine(char *theLine, int x, int &offset) {
 	speech->allSpeech = newLine;
 	if ((xx1 < 5) && (offset < (5 - xx1))) {
 		offset = 5 - xx1;
-	} else if ((xx2 >= ((float)winWidth / cameraZoom) - 5) && (offset > (((float)winWidth / cameraZoom) - 5 - xx2))) {
-		offset = ((float)winWidth / cameraZoom) - 5 - xx2;
+	} else if ((xx2 >= ((float) winWidth / cameraZoom) - 5)
+			&& (offset > (((float) winWidth / cameraZoom) - 5 - xx2))) {
+		offset = ((float) winWidth / cameraZoom) - 5 - xx2;
 	}
 }
 
@@ -111,7 +112,8 @@ int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
 	killAllSpeech();
 
 	int speechTime = (strlen(theText) + 20) * speechSpeed;
-	if (speechTime < 1) speechTime = 1;
+	if (speechTime < 1)
+		speechTime = 1;
 	if (sampleFile != -1) {
 		if (speechMode >= 1) {
 #if 0
@@ -128,7 +130,7 @@ int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
 	while (strlen(theText) > wrap) {
 		a = wrap;
 		while (theText[a] != ' ') {
-			a --;
+			a--;
 			if (a == 0) {
 				a = wrap;
 				break;
@@ -143,8 +145,12 @@ int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
 	addSpeechLine(theText, x, offset);
 	y -= fontHeight / cameraZoom;
 
-	if (y < 0) speech->speechY -= y;
-	else if (speech->speechY > cameraY + (float)(winHeight - fontHeight / 3) / cameraZoom) speech->speechY = cameraY + (float)(winHeight - fontHeight / 3) / cameraZoom;
+	if (y < 0)
+		speech->speechY -= y;
+	else if (speech->speechY
+			> cameraY + (float) (winHeight - fontHeight / 3) / cameraZoom)
+		speech->speechY = cameraY
+				+ (float) (winHeight - fontHeight / 3) / cameraZoom;
 
 	if (offset) {
 		speechLine *viewLine = speech->allSpeech;
@@ -156,8 +162,13 @@ int wrapSpeechXY(char *theText, int x, int y, int wrap, int sampleFile) {
 	return speechTime;
 }
 
-int wrapSpeechPerson(char *theText, onScreenPerson &thePerson, int sampleFile, bool animPerson) {
-	int i = wrapSpeechXY(theText, thePerson.x - cameraX, thePerson.y - cameraY - (thePerson.scale * (thePerson.height - thePerson.floaty)) - thePerson.thisType->speechGap, thePerson.thisType->wrapSpeech, sampleFile);
+int wrapSpeechPerson(char *theText, onScreenPerson &thePerson, int sampleFile,
+		bool animPerson) {
+	int i = wrapSpeechXY(theText, thePerson.x - cameraX,
+			thePerson.y - cameraY
+					- (thePerson.scale * (thePerson.height - thePerson.floaty))
+					- thePerson.thisType->speechGap,
+			thePerson.thisType->wrapSpeech, sampleFile);
 	if (animPerson) {
 		makeTalker(thePerson);
 		speech->currentTalker = &thePerson;
@@ -172,16 +183,20 @@ int wrapSpeech(char *theText, int objT, int sampleFile, bool animPerson) {
 	onScreenPerson *thisPerson = findPerson(objT);
 	if (thisPerson) {
 		setObjFontColour(thisPerson->thisType);
-		i = wrapSpeechPerson(theText, * thisPerson, sampleFile, animPerson);
+		i = wrapSpeechPerson(theText, *thisPerson, sampleFile, animPerson);
 	} else {
 		screenRegion *thisRegion = getRegionForObject(objT);
 		if (thisRegion) {
 			setObjFontColour(thisRegion->thisType);
-			i = wrapSpeechXY(theText, ((thisRegion->x1 + thisRegion->x2) >> 1) - cameraX, thisRegion->y1 - thisRegion->thisType->speechGap - cameraY, thisRegion->thisType->wrapSpeech, sampleFile);
+			i = wrapSpeechXY(theText,
+					((thisRegion->x1 + thisRegion->x2) >> 1) - cameraX,
+					thisRegion->y1 - thisRegion->thisType->speechGap - cameraY,
+					thisRegion->thisType->wrapSpeech, sampleFile);
 		} else {
 			objectType *temp = findObjectType(objT);
 			setObjFontColour(temp);
-			i = wrapSpeechXY(theText, winWidth >> 1, 10, temp->wrapSpeech, sampleFile);
+			i = wrapSpeechXY(theText, winWidth >> 1, 10, temp->wrapSpeech,
+					sampleFile);
 		}
 	}
 	return i;
diff --git a/engines/sludge/talk.h b/engines/sludge/talk.h
index 2ce4c4a..5e32def 100644
--- a/engines/sludge/talk.h
+++ b/engines/sludge/talk.h
@@ -32,7 +32,6 @@ struct speechLine {
 	int x;
 };
 
-
 struct speechStruct {
 	onScreenPerson *currentTalker;
 	speechLine *allSpeech;
diff --git a/engines/sludge/thumbnail.cpp b/engines/sludge/thumbnail.cpp
index c24946a..7c588a2 100644
--- a/engines/sludge/thumbnail.cpp
+++ b/engines/sludge/thumbnail.cpp
@@ -40,7 +40,6 @@ int thumbWidth = 0, thumbHeight = 0;
 extern GLuint backdropTextureName;
 #endif
 
-
 bool saveThumbnail(Common::WriteStream *stream) {
 #if 0
 	GLuint thumbnailTextureName = 0;
@@ -72,7 +71,6 @@ bool saveThumbnail(Common::WriteStream *stream) {
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
-
 		const GLfloat vertices[] = {
 			0., 0., 0.,
 			thumbWidth - 1.f, 0., 0.,
@@ -120,8 +118,6 @@ bool saveThumbnail(Common::WriteStream *stream) {
 		glReadPixels(viewportOffsetX, viewportOffsetY, thumbWidth, thumbHeight, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image);
 #endif
 
-
-
 		glUseProgram(0);
 #endif
 		setPixelCoords(false);
diff --git a/engines/sludge/timing.cpp b/engines/sludge/timing.cpp
index 887c4ed..6bf6863 100644
--- a/engines/sludge/timing.cpp
+++ b/engines/sludge/timing.cpp
@@ -59,4 +59,5 @@ void Wait_Frame(void) {
 }
 #endif
 
-} // End of namespace Sludge
+}
+               // End of namespace Sludge
diff --git a/engines/sludge/transition.cpp b/engines/sludge/transition.cpp
index 0fcd4fe..73ac737 100644
--- a/engines/sludge/transition.cpp
+++ b/engines/sludge/transition.cpp
@@ -113,7 +113,7 @@ void transitionSnapshotBox() {
 	//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 	glBindTexture(GL_TEXTURE_2D, snapshotTextureName);
 
-	float xScale = (float) brightnessLevel * winWidth / 510.f;  // 510 = 255*2
+	float xScale = (float) brightnessLevel * winWidth / 510.f;// 510 = 255*2
 	float yScale = (float) brightnessLevel * winHeight / 510.f;
 
 	const GLfloat vertices[] = {
@@ -187,7 +187,6 @@ bool reserveTransitionTexture() {
 	return true;
 }
 
-
 void transitionDisolve() {
 
 #if 0
@@ -224,7 +223,7 @@ void transitionDisolve() {
 			toScreen[0] = toScreen[1] = toScreen[2] = toScreen[3] = 0;
 		}
 		toScreen += 4;
-	} while (toScreen < end);
+	}while (toScreen < end);
 
 	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, transitionTexture, transitionTextureName);
 
@@ -292,7 +291,7 @@ void transitionTV() {
 			toScreen[0] = toScreen[1] = toScreen[2] = toScreen[3] = 0;
 		}
 		toScreen += 4;
-	} while (toScreen < end);
+	}while (toScreen < end);
 
 	texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, transitionTexture, transitionTextureName);
 
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index 928b65b..8d6beb2 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -41,10 +41,9 @@
 
 namespace Sludge {
 
-const char *typeName[] = {"undefined", "number", "user function", "string",
-                          "built-in function", "file", "stack",
-                          "object type", "animation", "costume"
-                         };
+const char *typeName[] = { "undefined", "number", "user function", "string",
+		"built-in function", "file", "stack", "object type", "animation",
+		"costume" };
 
 extern char *outputDir;
 
@@ -56,18 +55,19 @@ void unlinkVar(variable &thisVar) {
 		break;
 
 	case SVT_STACK:
-		thisVar.varData.theStack -> timesUsed --;
-		if (thisVar.varData.theStack -> timesUsed <= 0) {
-			while (thisVar.varData.theStack -> first) trimStack(thisVar.varData.theStack -> first);
+		thisVar.varData.theStack->timesUsed--;
+		if (thisVar.varData.theStack->timesUsed <= 0) {
+			while (thisVar.varData.theStack->first)
+				trimStack(thisVar.varData.theStack->first);
 			delete thisVar.varData.theStack;
 			thisVar.varData.theStack = NULL;
 		}
 		break;
 
 	case SVT_FASTARRAY:
-		thisVar.varData.fastArray -> timesUsed --;
-		if (thisVar.varData.theStack -> timesUsed <= 0) {
-			delete thisVar.varData.fastArray -> fastVariables;
+		thisVar.varData.fastArray->timesUsed--;
+		if (thisVar.varData.theStack->timesUsed <= 0) {
+			delete thisVar.varData.fastArray->fastVariables;
 			delete[] thisVar.varData.fastArray;
 			thisVar.varData.fastArray = NULL;
 		}
@@ -101,7 +101,8 @@ personaAnimation *getAnimationFromVar(variable &thisVar) {
 	if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0)
 		return makeNullAnim();
 
-	fatal("Expecting an animation variable; found variable of type", typeName[thisVar.varType]);
+	fatal("Expecting an animation variable; found variable of type",
+			typeName[thisVar.varType]);
 	return NULL;
 }
 
@@ -117,13 +118,15 @@ persona *getCostumeFromVar(variable &thisVar) {
 	switch (thisVar.varType) {
 	case SVT_ANIM:
 		p = new persona;
-		if (! checkNew(p)) return NULL;
-		p -> numDirections = 1;
-		p -> animation = new personaAnimation * [3];
-		if (! checkNew(p -> animation)) return NULL;
+		if (!checkNew(p))
+			return NULL;
+		p->numDirections = 1;
+		p->animation = new personaAnimation *[3];
+		if (!checkNew(p->animation))
+			return NULL;
 
-		for (int iii = 0; iii < 3; iii ++)
-			p -> animation[iii] = copyAnim(thisVar.varData.animHandler);
+		for (int iii = 0; iii < 3; iii++)
+			p->animation[iii] = copyAnim(thisVar.varData.animHandler);
 
 		break;
 
@@ -132,7 +135,8 @@ persona *getCostumeFromVar(variable &thisVar) {
 		break;
 
 	default:
-		fatal("Expecting an animation variable; found variable of type", typeName[thisVar.varType]);
+		fatal("Expecting an animation variable; found variable of type",
+				typeName[thisVar.varType]);
 	}
 
 	return p;
@@ -140,10 +144,10 @@ persona *getCostumeFromVar(variable &thisVar) {
 
 int stackSize(const stackHandler *me) {
 	int r = 0;
-	variableStack *a = me -> first;
+	variableStack *a = me->first;
 	while (a) {
-		r ++;
-		a = a -> next;
+		r++;
+		a = a->next;
 	}
 	return r;
 }
@@ -156,7 +160,8 @@ char *ConvertFromUTF16(const WCHAR *input);
 
 bool getSavedGamesStack(stackHandler *sH, char *ext) {
 	char *pattern = joinStrings("*", ext);
-	if (! pattern) return false;
+	if (!pattern)
+		return false;
 
 	variable newName;
 	newName.varType = SVT_NULL;
@@ -182,30 +187,32 @@ bool getSavedGamesStack(stackHandler *sH, char *ext) {
 			if (! addVarToStack(newName, sH -> first)) return false;
 			if (sH -> last == NULL) sH -> last = sH -> first;
 			keepGoing = FindNextFile(handle, & theData);
-		} while (keepGoing);
+		}while (keepGoing);
 		FindClose(handle);
 	}
 
 #else
 
 	DIR *dir = opendir(".");
-	if (! dir) return false;
+	if (!dir)
+		return false;
 
 	struct dirent *d = readdir(dir);
 	while (d != NULL) {
-		if (! strcmp(d->d_name + strlen(d->d_name) - strlen(ext), ext)) {
+		if (!strcmp(d->d_name + strlen(d->d_name) - strlen(ext), ext)) {
 			d->d_name[strlen(d->d_name) - strlen(ext)] = 0;
 			char *decoded = decodeFilename(d->d_name);
 			makeTextVar(newName, decoded);
 			delete[] decoded;
-			if (! addVarToStack(newName, sH -> first)) return false;
-			if (sH -> last == NULL) sH -> last = sH -> first;
+			if (!addVarToStack(newName, sH->first))
+				return false;
+			if (sH->last == NULL)
+				sH->last = sH->first;
 		}
 
 		d = readdir(dir);
 	}
 
-
 	closedir(dir);
 
 #endif
@@ -218,11 +225,12 @@ bool getSavedGamesStack(stackHandler *sH, char *ext) {
 bool copyStack(const variable &from, variable &to) {
 	to.varType = SVT_STACK;
 	to.varData.theStack = new stackHandler;
-	if (! checkNew(to.varData.theStack)) return false;
-	to.varData.theStack -> first = NULL;
-	to.varData.theStack -> last = NULL;
-	to.varData.theStack -> timesUsed = 1;
-	variableStack *a = from.varData.theStack -> first;
+	if (!checkNew(to.varData.theStack))
+		return false;
+	to.varData.theStack->first = NULL;
+	to.varData.theStack->last = NULL;
+	to.varData.theStack->timesUsed = 1;
+	variableStack *a = from.varData.theStack->first;
 
 #if DEBUG_STACKINESS
 	{
@@ -233,12 +241,12 @@ bool copyStack(const variable &from, variable &to) {
 #endif
 
 	while (a) {
-		addVarToStack(a -> thisVar, to.varData.theStack -> first);
-		if (to.varData.theStack -> last == NULL) {
+		addVarToStack(a->thisVar, to.varData.theStack->first);
+		if (to.varData.theStack->last == NULL) {
 #if DEBUG_STACKINESS
 			stackDebug((stackfp, "LAST"));
 #endif
-			to.varData.theStack -> last = to.varData.theStack -> first;
+			to.varData.theStack->last = to.varData.theStack->first;
 		}
 
 #if DEBUG_STACKINESS
@@ -249,7 +257,7 @@ bool copyStack(const variable &from, variable &to) {
 		}
 #endif
 
-		a = a -> next;
+		a = a->next;
 	}
 
 #if DEBUG_STACKINESS
@@ -265,10 +273,10 @@ bool copyStack(const variable &from, variable &to) {
 }
 
 /*void newStackVar (variable & thisVar) {
-    unlinkVar (thisVar);
-    thisVar.varType = VT_STACK;
-    thisVar.varData.theStack = NULL;
-} */
+ unlinkVar (thisVar);
+ thisVar.varType = VT_STACK;
+ thisVar.varData.theStack = NULL;
+ } */
 
 void addVariablesInSecond(variable &var1, variable &var2) {
 	if (var1.varType == SVT_INT && var2.varType == SVT_INT) {
@@ -330,7 +338,7 @@ void makeTextVar(variable &thisVar, const char *txt) {
 bool loadStringToVar(variable &thisVar, int value) {
 
 	makeTextVar(thisVar, getNumberedString(value));
-	return (bool)(thisVar.varData.theString != NULL);
+	return (bool) (thisVar.varData.theString != NULL);
 }
 
 char *getTextFromAnyVar(const variable &from) {
@@ -343,13 +351,16 @@ char *getTextFromAnyVar(const variable &from) {
 		char *builder2;
 		char *grabText;
 
-		for (int i = 0; i < from.varData.fastArray -> size; i ++) {
+		for (int i = 0; i < from.varData.fastArray->size; i++) {
 			builder2 = joinStrings(builder, " ");
-			if (! builder2) return NULL;
+			if (!builder2)
+				return NULL;
 			delete builder;
-			grabText = getTextFromAnyVar(from.varData.fastArray -> fastVariables[i]);
+			grabText = getTextFromAnyVar(
+					from.varData.fastArray->fastVariables[i]);
 			builder = joinStrings(builder2, grabText);
-			if (! builder) return NULL;
+			if (!builder)
+				return NULL;
 			delete grabText;
 			grabText = NULL;
 			delete builder2;
@@ -363,27 +374,30 @@ char *getTextFromAnyVar(const variable &from) {
 		char *builder2;
 		char *grabText;
 
-		variableStack *stacky = from.varData.theStack -> first;
+		variableStack *stacky = from.varData.theStack->first;
 
 		while (stacky) {
 			builder2 = joinStrings(builder, " ");
-			if (! builder2) return NULL;
+			if (!builder2)
+				return NULL;
 			delete builder;
-			grabText = getTextFromAnyVar(stacky -> thisVar);
+			grabText = getTextFromAnyVar(stacky->thisVar);
 			builder = joinStrings(builder2, grabText);
-			if (! builder) return NULL;
+			if (!builder)
+				return NULL;
 			delete grabText;
 			grabText = NULL;
 			delete builder2;
 			builder2 = NULL;
-			stacky = stacky -> next;
+			stacky = stacky->next;
 		}
 		return builder;
 	}
 
 	case SVT_INT: {
 		char *buff = new char[10];
-		if (! checkNew(buff)) return NULL;
+		if (!checkNew(buff))
+			return NULL;
 		sprintf(buff, "%i", from.varData.intValue);
 		return buff;
 	}
@@ -395,17 +409,18 @@ char *getTextFromAnyVar(const variable &from) {
 		return joinStrings("", resourceNameFromNum(from.varData.intValue));
 	}
 
-	/*      case SVT_ANIM:
-	        {
-	            char * buff = new char[20];
-	            if (! checkNew (buff)) return NULL;
-	            sprintf (buff, "%p", from.varData.animHandler);
-	            return buff;
-	        }*/
+		/*      case SVT_ANIM:
+		 {
+		 char * buff = new char[20];
+		 if (! checkNew (buff)) return NULL;
+		 sprintf (buff, "%p", from.varData.animHandler);
+		 return buff;
+		 }*/
 
 	case SVT_OBJTYPE: {
 		objectType *thisType = findObjectType(from.varData.intValue);
-		if (thisType) return copyString(thisType -> screenName);
+		if (thisType)
+			return copyString(thisType->screenName);
 	}
 
 	default:
@@ -421,16 +436,16 @@ bool getBoolean(const variable &from) {
 		return false;
 
 	case SVT_INT:
-		return (bool)(from.varData.intValue != 0);
+		return (bool) (from.varData.intValue != 0);
 
 	case SVT_STACK:
-		return (bool)(from.varData.theStack -> first != NULL);
+		return (bool) (from.varData.theStack->first != NULL);
 
 	case SVT_STRING:
-		return (bool)(from.varData.theString[0] != 0);
+		return (bool) (from.varData.theString[0] != 0);
 
 	case SVT_FASTARRAY:
-		return (bool)(from.varData.fastArray -> size != 0);
+		return (bool) (from.varData.fastArray->size != 0);
 
 	default:
 		break;
@@ -451,7 +466,7 @@ bool copyMain(const variable &from, variable &to) {
 
 	case SVT_FASTARRAY:
 		to.varData.fastArray = from.varData.fastArray;
-		to.varData.fastArray -> timesUsed ++;
+		to.varData.fastArray->timesUsed++;
 		return true;
 
 	case SVT_STRING:
@@ -460,7 +475,7 @@ bool copyMain(const variable &from, variable &to) {
 
 	case SVT_STACK:
 		to.varData.theStack = from.varData.theStack;
-		to.varData.theStack -> timesUsed ++;
+		to.varData.theStack->timesUsed++;
 		return true;
 
 	case SVT_COSTUME:
@@ -487,109 +502,124 @@ bool copyVariable(const variable &from, variable &to) {
 }
 
 variable *fastArrayGetByIndex(fastArrayHandler *vS, unsigned int theIndex) {
-	if (theIndex < 0 || theIndex >= vS -> size) return NULL;
-	return & vS -> fastVariables[theIndex];
+	if (theIndex < 0 || theIndex >= vS->size)
+		return NULL;
+	return &vS->fastVariables[theIndex];
 }
 
 bool makeFastArraySize(variable &to, int size) {
-	if (size < 0) return fatal("Can't create a fast array with a negative number of elements!");
+	if (size < 0)
+		return fatal(
+				"Can't create a fast array with a negative number of elements!");
 	unlinkVar(to);
 	to.varType = SVT_FASTARRAY;
 	to.varData.fastArray = new fastArrayHandler;
-	if (! checkNew(to.varData.fastArray)) return false;
-	to.varData.fastArray -> fastVariables = new variable[size];
-	if (! checkNew(to.varData.fastArray -> fastVariables)) return false;
-	for (int i = 0; i < size; i ++) {
-		initVarNew(to.varData.fastArray -> fastVariables[i]);
+	if (!checkNew(to.varData.fastArray))
+		return false;
+	to.varData.fastArray->fastVariables = new variable[size];
+	if (!checkNew(to.varData.fastArray->fastVariables))
+		return false;
+	for (int i = 0; i < size; i++) {
+		initVarNew(to.varData.fastArray->fastVariables[i]);
 	}
-	to.varData.fastArray -> size = size;
-	to.varData.fastArray -> timesUsed = 1;
+	to.varData.fastArray->size = size;
+	to.varData.fastArray->timesUsed = 1;
 	return true;
 }
 
 bool makeFastArrayFromStack(variable &to, const stackHandler *stacky) {
 	int size = stackSize(stacky);
-	if (! makeFastArraySize(to, size)) return false;
+	if (!makeFastArraySize(to, size))
+		return false;
 
 	// Now let's fill up the new array
 
-	variableStack *allV = stacky -> first;
+	variableStack *allV = stacky->first;
 	size = 0;
 	while (allV) {
-		copyMain(allV -> thisVar, to.varData.fastArray -> fastVariables[size]);
-		size ++;
-		allV = allV -> next;
+		copyMain(allV->thisVar, to.varData.fastArray->fastVariables[size]);
+		size++;
+		allV = allV->next;
 	}
 	return true;
 }
 
 /*
-bool moveVariable (variable & from, variable & to) {
-    unlinkVar (to);
-    memcpy (& to, & from, sizeof (variable));
-    from.varType = SVT_NULL;
-}
-*/
+ bool moveVariable (variable & from, variable & to) {
+ unlinkVar (to);
+ memcpy (& to, & from, sizeof (variable));
+ from.varType = SVT_NULL;
+ }
+ */
 
 bool addVarToStack(const variable &va, variableStack *&thisStack) {
 	variableStack *newStack = new variableStack;
-	if (! checkNew(newStack)) return false;
+	if (!checkNew(newStack))
+		return false;
 
-	if (! copyMain(va, newStack -> thisVar)) return false;
-	newStack -> next = thisStack;
+	if (!copyMain(va, newStack->thisVar))
+		return false;
+	newStack->next = thisStack;
 	thisStack = newStack;
-	debug(kSludgeDebugStackMachine, "Variable %s was added to stack", getTextFromAnyVar(va));
+	debug(kSludgeDebugStackMachine, "Variable %s was added to stack",
+			getTextFromAnyVar(va));
 	return true;
 }
 
 bool addVarToStackQuick(variable &va, variableStack *&thisStack) {
 	variableStack *newStack = new variableStack;
-	if (! checkNew(newStack)) return false;
+	if (!checkNew(newStack))
+		return false;
 
 //	if (! copyMain (va, newStack -> thisVar)) return false;
 
-	memcpy(& (newStack -> thisVar), & va, sizeof(variable));
+	memcpy(&(newStack->thisVar), &va, sizeof(variable));
 	va.varType = SVT_NULL;
 
-	newStack -> next = thisStack;
+	newStack->next = thisStack;
 	thisStack = newStack;
-	debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick", getTextFromAnyVar(va));
+	debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick",
+			getTextFromAnyVar(va));
 	return true;
 }
 
-bool stackSetByIndex(variableStack *vS, unsigned int theIndex, const variable &va) {
-	while (theIndex --) {
-		vS = vS -> next;
-		if (! vS) return fatal("Index past end of stack.");
+bool stackSetByIndex(variableStack *vS, unsigned int theIndex,
+		const variable &va) {
+	while (theIndex--) {
+		vS = vS->next;
+		if (!vS)
+			return fatal("Index past end of stack.");
 	}
-	return copyVariable(va, vS -> thisVar);
+	return copyVariable(va, vS->thisVar);
 }
 
 variable *stackGetByIndex(variableStack *vS, unsigned int theIndex) {
-	while (theIndex --) {
-		vS = vS -> next;
-		if (! vS) {
+	while (theIndex--) {
+		vS = vS->next;
+		if (!vS) {
 			return NULL;
 		}
 	}
-	return & (vS -> thisVar);
+	return &(vS->thisVar);
 }
 
-int deleteVarFromStack(const variable &va, variableStack *&thisStack, bool allOfEm) {
-	variableStack * * huntVar = & thisStack;
+int deleteVarFromStack(const variable &va, variableStack *&thisStack,
+		bool allOfEm) {
+	variableStack * * huntVar = &thisStack;
 	variableStack *killMe;
 	int reply = 0;
 
-	while (* huntVar) {
-		if (compareVars((* huntVar) -> thisVar, va)) {
-			killMe = * huntVar;
-			* huntVar = killMe -> next;
-			unlinkVar(killMe -> thisVar);
+	while (*huntVar) {
+		if (compareVars((*huntVar)->thisVar, va)) {
+			killMe = *huntVar;
+			*huntVar = killMe->next;
+			unlinkVar(killMe->thisVar);
 			delete killMe;
-			if (! allOfEm) return 1;
-			reply ++;
+			if (!allOfEm)
+				return 1;
+			reply++;
 		} else {
-			huntVar = & ((* huntVar) -> next);
+			huntVar = &((*huntVar)->next);
 		}
 	}
 
@@ -610,8 +640,12 @@ variableStack *stackFindLast(variableStack *hunt) {
 bool getValueType(int &toHere, variableType vT, const variable &v) {
 	//if (! v) return false;
 	if (v.varType != vT) {
-		char *e1 = joinStrings("Can only perform specified operation on a value which is of type ", typeName[vT]);
-		char *e2 = joinStrings("... value supplied was of type ", typeName[v.varType]);
+		char *e1 =
+				joinStrings(
+						"Can only perform specified operation on a value which is of type ",
+						typeName[vT]);
+		char *e2 = joinStrings("... value supplied was of type ",
+				typeName[v.varType]);
 		fatal(e1, e2);
 
 		return false;
@@ -622,50 +656,51 @@ bool getValueType(int &toHere, variableType vT, const variable &v) {
 
 void trimStack(variableStack *&stack) {
 	variableStack *killMe = stack;
-	stack = stack -> next;
+	stack = stack->next;
 
-	debug(kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe -> thisVar));
+	debug(kSludgeDebugStackMachine, "Variable %s was removed from stack",
+			getTextFromAnyVar(killMe->thisVar));
 
 	// When calling this, we've ALWAYS checked that stack != NULL
-	unlinkVar(killMe -> thisVar);
+	unlinkVar(killMe->thisVar);
 	delete killMe;
 }
 /*
-void debugVar (FILE * fp, const variable & thisVar) {
-    switch (thisVar.varType) {
-        case SVT_INT:
-        fprintf (fp, "integer value %i", thisVar.varData.intValue);
-        break;
-
-        case SVT_FUNC:
-        fprintf (fp, "pointer to function %i", thisVar.varData.intValue);
-        break;
-
-        case SVT_BUILT:
-        fprintf (fp, "pointer to bif %i", thisVar.varData.intValue);
-        break;
-
-        case SVT_OBJTYPE:
-        fprintf (fp, "object type %i", thisVar.varData.intValue);
-        break;
-
-        case SVT_STRING:
-        fprintf (fp, "\"%s\"", thisVar.varData.theString);
-        break;
-
-        case SVT_FILE:
-        fprintf (fp, "file handle %i", thisVar.varData.intValue);
-        break;
-
-        case SVT_NULL:
-        fprintf (fp, "null");
-        break;
-
-        default:
-        fprintf (fp, "unknown variable type");
-        break;
-    }
-}
-*/
+ void debugVar (FILE * fp, const variable & thisVar) {
+ switch (thisVar.varType) {
+ case SVT_INT:
+ fprintf (fp, "integer value %i", thisVar.varData.intValue);
+ break;
+
+ case SVT_FUNC:
+ fprintf (fp, "pointer to function %i", thisVar.varData.intValue);
+ break;
+
+ case SVT_BUILT:
+ fprintf (fp, "pointer to bif %i", thisVar.varData.intValue);
+ break;
+
+ case SVT_OBJTYPE:
+ fprintf (fp, "object type %i", thisVar.varData.intValue);
+ break;
+
+ case SVT_STRING:
+ fprintf (fp, "\"%s\"", thisVar.varData.theString);
+ break;
+
+ case SVT_FILE:
+ fprintf (fp, "file handle %i", thisVar.varData.intValue);
+ break;
+
+ case SVT_NULL:
+ fprintf (fp, "null");
+ break;
+
+ default:
+ fprintf (fp, "unknown variable type");
+ break;
+ }
+ }
+ */
 
 } // End of namespace Sludge
diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h
index 8f9f743..295473e 100644
--- a/engines/sludge/variable.h
+++ b/engines/sludge/variable.h
@@ -27,41 +27,50 @@ namespace Sludge {
 struct variable;
 struct variableStack;
 
-enum variableType {SVT_NULL, SVT_INT, SVT_FUNC, SVT_STRING,
-                   SVT_BUILT, SVT_FILE, SVT_STACK,
-                   SVT_OBJTYPE, SVT_ANIM, SVT_COSTUME,
-                   SVT_FASTARRAY, SVT_NUM_TYPES
-                  };
+enum variableType {
+	SVT_NULL,
+	SVT_INT,
+	SVT_FUNC,
+	SVT_STRING,
+	SVT_BUILT,
+	SVT_FILE,
+	SVT_STACK,
+	SVT_OBJTYPE,
+	SVT_ANIM,
+	SVT_COSTUME,
+	SVT_FASTARRAY,
+	SVT_NUM_TYPES
+};
 
 struct fastArrayHandler {
-	struct variable            *fastVariables;
-	int                         size;
-	int                         timesUsed;
+	struct variable *fastVariables;
+	int size;
+	int timesUsed;
 };
 
 struct stackHandler {
-	struct variableStack       *first;
-	struct variableStack       *last;
-	int                         timesUsed;
+	struct variableStack *first;
+	struct variableStack *last;
+	int timesUsed;
 };
 
 union variableData {
-	signed int                  intValue;
-	char                       *theString;
-	stackHandler               *theStack;
-	struct personaAnimation    *animHandler;
-	struct persona             *costumeHandler;
-	fastArrayHandler           *fastArray;
+	signed int intValue;
+	char *theString;
+	stackHandler *theStack;
+	struct personaAnimation *animHandler;
+	struct persona *costumeHandler;
+	fastArrayHandler *fastArray;
 };
 
 struct variable {
-	variableType                varType;
-	variableData                varData;
+	variableType varType;
+	variableData varData;
 };
 
 struct variableStack {
-	variable                    thisVar;
-	variableStack              *next;
+	variable thisVar;
+	variableStack *next;
 };
 
 // Initialisation
@@ -94,7 +103,8 @@ bool getValueType(int &toHere, variableType vT, const variable &v);
 bool addVarToStack(const variable &va, variableStack *&thisStack);
 bool addVarToStackQuick(variable &va, variableStack *&thisStack);
 void trimStack(variableStack *&stack);
-int deleteVarFromStack(const variable &va, variableStack *&thisStack, bool allOfEm = false);
+int deleteVarFromStack(const variable &va, variableStack *&thisStack,
+		bool allOfEm = false);
 variableStack *stackFindLast(variableStack *hunt);
 bool copyStack(const variable &from, variable &to);
 int stackSize(const stackHandler *me);
@@ -106,7 +116,6 @@ bool makeFastArrayFromStack(variable &to, const stackHandler *stacky);
 bool makeFastArraySize(variable &to, int size);
 variable *fastArrayGetByIndex(fastArrayHandler *vS, unsigned int theIndex);
 
-
 #define DEBUG_STACKINESS    0
 
 #if DEBUG_STACKINESS
diff --git a/engines/sludge/vid.cpp b/engines/sludge/vid.cpp
index 13eea52..00e2063 100644
--- a/engines/sludge/vid.cpp
+++ b/engines/sludge/vid.cpp
@@ -40,10 +40,10 @@
 namespace Sludge {
 
 struct timStream {
-	PAVISTREAM      got;
-	AVISTREAMINFO   info;
-	LONG            chunkSize;
-	LPBYTE          chunk;
+	PAVISTREAM got;
+	AVISTREAMINFO info;
+	LONG chunkSize;
+	LPBYTE chunk;
 };
 
 static PAVIFILE pAviFile = NULL;
@@ -64,27 +64,32 @@ extern HWND hMainWindow;
 
 void initialiseMovieStuff() {
 	char buffer[500];
-	if (ExpandEnvironmentStrings("%temp%", buffer, 499) == 0) buffer[0] = NULL;
+	if (ExpandEnvironmentStrings("%temp%", buffer, 499) == 0)
+		buffer[0] = NULL;
 	videoFile = joinStrings(buffer, "\\test.avi");
 //	warning (videoFile);
 }
 
 bool getStream(DWORD type, timStream &intoHere) {
-	if (AVIFileGetStream(pAviFile, & intoHere.got, type, 0)) {
+	if (AVIFileGetStream(pAviFile, &intoHere.got, type, 0)) {
 		intoHere.got = NULL;
 		return true;
-	} else if (AVIStreamInfo(intoHere.got, & intoHere.info, sizeof(AVISTREAMINFO))) {
+	} else if (AVIStreamInfo(intoHere.got, &intoHere.info,
+			sizeof(AVISTREAMINFO))) {
 		return fatal("Can't get stream info");
-	} else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got), NULL, & intoHere.chunkSize)) {
+	} else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got),
+	NULL, &intoHere.chunkSize)) {
 		return fatal("Can't get stream chunk size");
 	} else {
 		// So far so good! Let's read a chunk of data (huh?)
 
 		intoHere.chunk = new BYTE[intoHere.chunkSize];
 
-		if (! intoHere.chunk) {
+		if (!intoHere.chunk) {
 			return fatal("Out of memory");
-		} else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got), intoHere.chunk, & intoHere.chunkSize)) {
+		} else if (AVIStreamReadFormat(intoHere.got,
+				AVIStreamStart(intoHere.got), intoHere.chunk,
+				&intoHere.chunkSize)) {
 			return fatal("Couldn't read stream format");
 		}
 	}
@@ -97,46 +102,48 @@ void killStream(timStream &intoHere) {
 }
 
 /*
-#define WAVHEADERSIZE 20
-char wavHeader[WAVHEADERSIZE] = {'R', 'I', 'F', 'F', 0, 0, 0, 0,
-                                 'W', 'A', 'V', 'E', 'f', 'm', 't',
-                                 0x20, 0x10, 0, 0, 0};
-
-void handleAudio () {
-    LONG aSize;
-
-    if(AVIStreamRead(audio.got, 0, AVISTREAMREAD_CONVENIENT, NULL, 0, & aSize, NULL)) return;
-
-    int totalSize = aSize + audio.chunkSize + WAVHEADERSIZE + 4;
-
-    LPBYTE pBuffer = new BYTE[totalSize];
-    if (!pBuffer) return;
-
-    memcpy (pBuffer, wavHeader, WAVHEADERSIZE);
-    pBuffer[4] = (char) (aSize);
-    pBuffer[5] = (char) (aSize >> 8);
-    memcpy (pBuffer + WAVHEADERSIZE, audio.chunk, audio.chunkSize);
-    memcpy (pBuffer + WAVHEADERSIZE + audio.chunkSize, "data", 4);
-
-    if(! AVIStreamRead (audio.got, 0, AVISTREAMREAD_CONVENIENT, pBuffer + audio.chunkSize + WAVHEADERSIZE + 4, aSize, NULL, NULL)) {
-        FILE * fp = fopen ("test.wav", "wb");
-        if (fp) {
-            fwrite (pBuffer, 1, totalSize, fp);
-            fclose (fp);
-        }
-        int i = fakeCacheSoundForVideo ((char *) pBuffer, totalSize);
-        if (i != -1) startSound (i, false);
-    }
-
-    delete pBuffer;
-}
-*/
+ #define WAVHEADERSIZE 20
+ char wavHeader[WAVHEADERSIZE] = {'R', 'I', 'F', 'F', 0, 0, 0, 0,
+ 'W', 'A', 'V', 'E', 'f', 'm', 't',
+ 0x20, 0x10, 0, 0, 0};
+
+ void handleAudio () {
+ LONG aSize;
+
+ if(AVIStreamRead(audio.got, 0, AVISTREAMREAD_CONVENIENT, NULL, 0, & aSize, NULL)) return;
+
+ int totalSize = aSize + audio.chunkSize + WAVHEADERSIZE + 4;
+
+ LPBYTE pBuffer = new BYTE[totalSize];
+ if (!pBuffer) return;
+
+ memcpy (pBuffer, wavHeader, WAVHEADERSIZE);
+ pBuffer[4] = (char) (aSize);
+ pBuffer[5] = (char) (aSize >> 8);
+ memcpy (pBuffer + WAVHEADERSIZE, audio.chunk, audio.chunkSize);
+ memcpy (pBuffer + WAVHEADERSIZE + audio.chunkSize, "data", 4);
+
+ if(! AVIStreamRead (audio.got, 0, AVISTREAMREAD_CONVENIENT, pBuffer + audio.chunkSize + WAVHEADERSIZE + 4, aSize, NULL, NULL)) {
+ FILE * fp = fopen ("test.wav", "wb");
+ if (fp) {
+ fwrite (pBuffer, 1, totalSize, fp);
+ fclose (fp);
+ }
+ int i = fakeCacheSoundForVideo ((char *) pBuffer, totalSize);
+ if (i != -1) startSound (i, false);
+ }
+
+ delete pBuffer;
+ }
+ */
 
 void finishVideo() {
 	videoPlaying = false;
 	AVIStreamGetFrameClose(pgf);
-	if (audio.got) AVIStreamRelease(audio.got);
-	if (video.got) AVIStreamRelease(video.got);
+	if (audio.got)
+		AVIStreamRelease(audio.got);
+	if (video.got)
+		AVIStreamRelease(video.got);
 	killStream(audio);
 	killStream(video);
 	AVIFileRelease(pAviFile);
@@ -144,17 +151,19 @@ void finishVideo() {
 #ifdef _MSC_VER
 	_unlink(videoFile);
 #else
-	unlink(videoFile);
+	unlink(videoFile)
+;
 #endif
 }
 
 #define COPYSIZE 256
 
 bool extractSlice(int fileNum, char *toName) {
-	unsigned char buff[COPYSIZE];
+unsigned char buff[COPYSIZE];
 
-	unsigned long fileLength = openFileFromNum(fileNum);
-	if (! fileLength) return false; // Error already displayed
+unsigned long fileLength = openFileFromNum(fileNum);
+if (!fileLength)
+	return false; // Error already displayed
 #if 0
 	FILE *copyVid = fopen(toName, "wb");
 	if (! copyVid) return fatal("Can't extract resource");
@@ -171,94 +180,100 @@ bool extractSlice(int fileNum, char *toName) {
 
 	fclose(copyVid);
 #endif
-	finishAccess();
+finishAccess();
 
-	return true;
+return true;
 }
 
 bool startVideo(int fileNum) {
 
-	setResourceForFatal(fileNum);
+setResourceForFatal(fileNum);
 
-	AVIFILEINFO info;
+AVIFILEINFO info;
 
-	if (videoPlaying) finishVideo();
-	AVIFileInit();
+if (videoPlaying)
+	finishVideo();
+AVIFileInit();
 
-	if (! extractSlice(fileNum, videoFile)) return false;
-	if (AVIFileOpen(& pAviFile, videoFile, OF_READ, NULL))
-		return fatal(ERROR_AVI_FILE_ERROR);
+if (!extractSlice(fileNum, videoFile))
+	return false;
+if (AVIFileOpen(&pAviFile, videoFile, OF_READ, NULL))
+	return fatal(ERROR_AVI_FILE_ERROR);
 
-	AVIFileInfo(pAviFile, &info, sizeof(info));
+AVIFileInfo(pAviFile, &info, sizeof(info));
 
-	if (! getStream(streamtypeAUDIO, audio)) return false;
-	if (! getStream(streamtypeVIDEO, video)) return false;
+if (!getStream(streamtypeAUDIO, audio))
+	return false;
+if (!getStream(streamtypeVIDEO, video))
+	return false;
 
-	if (! video.got) return fatal(ERROR_AVI_NO_STREAM);
+if (!video.got)
+	return fatal(ERROR_AVI_NO_STREAM);
 
 //	if (audio.got) handleAudio ();
 
-	pgf = AVIStreamGetFrameOpen(video.got, NULL);
-	if (!pgf) return fatal(ERROR_AVI_ARGH);
+pgf = AVIStreamGetFrameOpen(video.got, NULL);
+if (!pgf)
+	return fatal(ERROR_AVI_ARGH);
 
-	LPBITMAPINFO pInfo = (LPBITMAPINFO)(video.chunk);
-	vidBytesPerPixel = pInfo -> bmiHeader.biBitCount / 8;
-	biSize = pInfo -> bmiHeader.biSize;
-	vidWidth = pInfo -> bmiHeader.biWidth;
-	vidHeight = pInfo -> bmiHeader.biHeight;
+LPBITMAPINFO pInfo = (LPBITMAPINFO)(video.chunk);
+vidBytesPerPixel = pInfo->bmiHeader.biBitCount / 8;
+biSize = pInfo->bmiHeader.biSize;
+vidWidth = pInfo->bmiHeader.biWidth;
+vidHeight = pInfo->bmiHeader.biHeight;
 
-	videoFrameNum = 0;
-	videoPlaying = true;
+videoFrameNum = 0;
+videoPlaying = true;
 
-	setResourceForFatal(-1);
+setResourceForFatal(-1);
 
-	return true;
+return true;
 }
 
 bool nextVideoFrame() {
-	LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER) AVIStreamGetFrame(pgf, videoFrameNum);
-	if (! lpbi) {
-		finishVideo();
-		return false;
-	}
+LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER) AVIStreamGetFrame(pgf,
+		videoFrameNum);
+if (!lpbi) {
+	finishVideo();
+	return false;
+}
+
+BYTE *pData = (((BYTE *) lpbi) + lpbi->biSize);
+
+int xOff = (winWidth - vidWidth) >> 1;
+int yOff = (winHeight + vidHeight) >> 1;
+unsigned short int *startingPoint = screen + xOff + (yOff * winWidth);
 
-	BYTE *pData = (((BYTE *) lpbi) + lpbi->biSize);
-
-	int xOff = (winWidth - vidWidth) >> 1;
-	int yOff = (winHeight + vidHeight) >> 1;
-	unsigned short int *startingPoint = screen + xOff + (yOff * winWidth);
-
-	for (int y = 0; y < vidHeight; y ++) {
-		startingPoint -= winWidth;
-		unsigned short int *toHere = startingPoint;
-		for (int x = 0; x < vidWidth; x ++) {
-			switch (vidBytesPerPixel) {
-			case 1:
-				(* toHere) = makeGrey(*pData);
-				break;
-
-			case 3:
-			case 4:
-				(* toHere) = makeColour(*(pData + 2), *(pData + 1), *pData);
-				break;
-
-			default: {
-				WORD Pixel16 = * ((WORD *) pData);
-				(* toHere) = makeColour(
-				                 (((UINT)(Pixel16) >> 10) & 0x1F) << 3,
-				                 (((UINT)(Pixel16) >> 5) & 0x1F) << 3,
-				                 (((UINT)(Pixel16) >> 0) & 0x1F) << 3);
-			}
+for (int y = 0; y < vidHeight; y++) {
+	startingPoint -= winWidth;
+	unsigned short int *toHere = startingPoint;
+	for (int x = 0; x < vidWidth; x++) {
+		switch (vidBytesPerPixel) {
+		case 1:
+			(*toHere) = makeGrey(*pData);
 			break;
-			}
-			pData += vidBytesPerPixel;
-			toHere ++;
+
+		case 3:
+		case 4:
+			(*toHere) = makeColour(*(pData + 2), *(pData + 1), *pData);
+			break;
+
+		default: {
+			WORD Pixel16 = *((WORD *) pData);
+			(*toHere) = makeColour((((UINT)(Pixel16) >> 10) & 0x1F) << 3,
+					(((UINT)(Pixel16) >> 5) & 0x1F) << 3,
+					(((UINT)(Pixel16) >> 0) & 0x1F) << 3);
 		}
+			break;
+		}
+		pData += vidBytesPerPixel;
+		toHere++;
 	}
+}
 
-	videoFrameNum ++;
+videoFrameNum++;
 
-	return true;
+return true;
 }
 
 } // End of namespace Sludge
diff --git a/engines/sludge/winstuff.cpp b/engines/sludge/winstuff.cpp
index 266df69..a229225 100644
--- a/engines/sludge/winstuff.cpp
+++ b/engines/sludge/winstuff.cpp
@@ -53,179 +53,178 @@
 
 namespace Sludge {
 
-HINSTANCE hInst;                // Handle of the main instance
-extern HWND hMainWindow;
+	HINSTANCE hInst;                // Handle of the main instance
+	extern HWND hMainWindow;
 
-extern variableStack *noStack;
+	extern variableStack *noStack;
 
 // The platform-specific functions - Windows edition.
 
-WCHAR *ConvertToUTF16(const char *input) {
-	int s = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input, -1, NULL, 0);
-	WCHAR *ret = new WCHAR [s];
-	checkNew(ret);
-	/*int a = */MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input, -1, ret, s);
-	return ret;
-}
-
-char *ConvertFromUTF16(const WCHAR *input) {
-	int s = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
-	char *ret = new char [s];
-	checkNew(ret);
-	/*int a = */WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, s, NULL, NULL);
-	return ret;
-}
-
-
-char *grabFileName() {
-	OPENFILENAME ofn;
-	WCHAR path[MAX_PATH];
-	WCHAR file[MAX_PATH] = TEXT("");
-
-	hInst = GetModuleHandle(NULL);
-
-	memset(& ofn, 0, sizeof(ofn));
-	ofn.lStructSize = sizeof(ofn);
-	ofn.hwndOwner = NULL;
-	ofn.hInstance = hInst;
-	ofn.nMaxFile = MAX_PATH;
-	ofn.lpstrInitialDir = path;
-	ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER;
-	ofn.lpstrFilter = TEXT("SLUDGE games (*.SLG)\0*.slg\0\0");
-	ofn.lpstrFile = file;
-
-	if (GetOpenFileName(& ofn)) {
-		return ConvertFromUTF16(file);
-	} else {
-		return NULL;
+	WCHAR *ConvertToUTF16(const char *input) {
+		int s = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input, -1, NULL, 0);
+		WCHAR *ret = new WCHAR [s];
+		checkNew(ret);
+		/*int a = */MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input, -1, ret, s);
+		return ret;
 	}
-}
 
-extern char **languageName;
-extern int *languageTable;
-
-HBITMAP hLogo = NULL;
-extern unsigned char *gameLogo;
+	char *ConvertFromUTF16(const WCHAR *input) {
+		int s = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
+		char *ret = new char [s];
+		checkNew(ret);
+		/*int a = */WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, s, NULL, NULL);
+		return ret;
+	}
 
-BOOL CALLBACK setupDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
-	switch (message) {
-	case WM_INITDIALOG:
-		if (gameLogo) {
-			hLogo = CreateBitmap(310, 88, 1, 32, gameLogo);
-			SendDlgItemMessage(hDlg, 1003, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hLogo);
+	char *grabFileName() {
+		OPENFILENAME ofn;
+		WCHAR path[MAX_PATH];
+		WCHAR file[MAX_PATH] = TEXT("");
+
+		hInst = GetModuleHandle(NULL);
+
+		memset(& ofn, 0, sizeof(ofn));
+		ofn.lStructSize = sizeof(ofn);
+		ofn.hwndOwner = NULL;
+		ofn.hInstance = hInst;
+		ofn.nMaxFile = MAX_PATH;
+		ofn.lpstrInitialDir = path;
+		ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER;
+		ofn.lpstrFilter = TEXT("SLUDGE games (*.SLG)\0*.slg\0\0");
+		ofn.lpstrFile = file;
+
+		if (GetOpenFileName(& ofn)) {
+			return ConvertFromUTF16(file);
+		} else {
+			return NULL;
 		}
+	}
+
+	extern char **languageName;
+	extern int *languageTable;
+
+	HBITMAP hLogo = NULL;
+	extern unsigned char *gameLogo;
+
+	BOOL CALLBACK setupDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
+		switch (message) {
+			case WM_INITDIALOG:
+			if (gameLogo) {
+				hLogo = CreateBitmap(310, 88, 1, 32, gameLogo);
+				SendDlgItemMessage(hDlg, 1003, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hLogo);
+			}
 
-		if (gameSettings.userFullScreen)
+			if (gameSettings.userFullScreen)
 			CheckDlgButton(hDlg, 1000, BST_CHECKED);
-		else
+			else
 			CheckDlgButton(hDlg, 1000, BST_UNCHECKED);
 
-		SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Default (best looking)")));
-		SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Linear (faster but blurry)")));
-		SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Off (blocky graphics)")));
+			SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Default (best looking)")));
+			SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Linear (faster but blurry)")));
+			SendDlgItemMessage(hDlg, 1002, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)TEXT("Off (blocky graphics)")));
 
-		if (gameSettings.antiAlias < 0)
+			if (gameSettings.antiAlias < 0)
 			SendDlgItemMessage(hDlg, 1002, CB_SETCURSEL, 1, 0);
-		else if (gameSettings.antiAlias)
+			else if (gameSettings.antiAlias)
 			SendDlgItemMessage(hDlg, 1002, CB_SETCURSEL, 0, 0);
-		else
+			else
 			SendDlgItemMessage(hDlg, 1002, CB_SETCURSEL, 2, 0);
 
-		if (gameSettings.numLanguages) {
-			WCHAR text[20];
-			for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
-				if (languageName[i]) {
-					WCHAR *w_lang = ConvertToUTF16(languageName[i]);
-					SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)w_lang));
-					delete w_lang;
-				} else {
-					swprintf(text, TEXT("Language %d"), i);
-					SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)text));
+			if (gameSettings.numLanguages) {
+				WCHAR text[20];
+				for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) {
+					if (languageName[i]) {
+						WCHAR *w_lang = ConvertToUTF16(languageName[i]);
+						SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)w_lang));
+						delete w_lang;
+					} else {
+						swprintf(text, TEXT("Language %d"), i);
+						SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)text));
+					}
 				}
+				SendDlgItemMessage(hDlg, 1001, CB_SETCURSEL, getLanguageForFileB(), 0);
+			} else {
+				const WCHAR *text = TEXT("No translations available");
+				SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)text));
+				SendDlgItemMessage(hDlg, 1001, CB_SETCURSEL, 0, 0);
+				EnableWindow(GetDlgItem(hDlg, 1001), false);
 			}
-			SendDlgItemMessage(hDlg, 1001, CB_SETCURSEL, getLanguageForFileB(), 0);
-		} else {
-			const WCHAR *text = TEXT("No translations available");
-			SendDlgItemMessage(hDlg, 1001, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)text));
-			SendDlgItemMessage(hDlg, 1001, CB_SETCURSEL, 0, 0);
-			EnableWindow(GetDlgItem(hDlg, 1001), false);
-		}
-		return true;
-
-	case WM_COMMAND:
-		if (hLogo) DeleteObject(hLogo);
-		switch (LOWORD(wParam)) {
-		case IDOK:
-
-			gameSettings.userFullScreen = (IsDlgButtonChecked(hDlg, 1000) == BST_CHECKED);
-			gameSettings.antiAlias = SendDlgItemMessage(hDlg, 1002, CB_GETCURSEL, 0, 0);
-			if (gameSettings.antiAlias == 0) gameSettings.antiAlias = 1;
-			else if (gameSettings.antiAlias == 1) gameSettings.antiAlias = -1;
-			else if (gameSettings.antiAlias == 2) gameSettings.antiAlias = 0;
+			return true;
+
+			case WM_COMMAND:
+			if (hLogo) DeleteObject(hLogo);
+			switch (LOWORD(wParam)) {
+				case IDOK:
+
+				gameSettings.userFullScreen = (IsDlgButtonChecked(hDlg, 1000) == BST_CHECKED);
+				gameSettings.antiAlias = SendDlgItemMessage(hDlg, 1002, CB_GETCURSEL, 0, 0);
+				if (gameSettings.antiAlias == 0) gameSettings.antiAlias = 1;
+				else if (gameSettings.antiAlias == 1) gameSettings.antiAlias = -1;
+				else if (gameSettings.antiAlias == 2) gameSettings.antiAlias = 0;
+
+				if (gameSettings.numLanguages) {
+					gameSettings.languageID = SendDlgItemMessage(hDlg, 1001, CB_GETCURSEL, 0, 0);
+					if (gameSettings.languageID < 0) gameSettings.languageID = 0;
+					gameSettings.languageID = languageTable[gameSettings.languageID];
+				}
+				EndDialog(hDlg, true);
+				return TRUE;
 
-			if (gameSettings.numLanguages) {
-				gameSettings.languageID = SendDlgItemMessage(hDlg, 1001, CB_GETCURSEL, 0, 0);
-				if (gameSettings.languageID < 0) gameSettings.languageID = 0;
-				gameSettings.languageID = languageTable[gameSettings.languageID];
+				case IDCANCEL:
+				EndDialog(hDlg, false);
+				return TRUE;
 			}
-			EndDialog(hDlg, true);
-			return TRUE;
-
-		case IDCANCEL:
-			EndDialog(hDlg, false);
-			return TRUE;
+			break;
 		}
-		break;
+		return false;
 	}
-	return false;
-}
 
-int showSetupWindow() {
+	int showSetupWindow() {
 
-	hInst = GetModuleHandle(NULL);
+		hInst = GetModuleHandle(NULL);
 
-	if (! hInst) debugOut("ERROR: No hInst!\n");
+		if (! hInst) debugOut("ERROR: No hInst!\n");
 
-	if (DialogBox(hInst, TEXT("SETUPWINDOW"), NULL, setupDlgProc)) return true;
-	return false;
+		if (DialogBox(hInst, TEXT("SETUPWINDOW"), NULL, setupDlgProc)) return true;
+		return false;
 
-}
+	}
 
-void msgBox(const char *head, const char *msg) {
-	WCHAR *w_head = ConvertToUTF16(head);
-	WCHAR *w_msg = ConvertToUTF16(msg);
-	MessageBox(NULL, w_msg, w_head, MB_OK | MB_ICONSTOP | MB_SYSTEMMODAL | MB_SETFOREGROUND);
-	delete w_head;
-	delete w_msg;
-}
+	void msgBox(const char *head, const char *msg) {
+		WCHAR *w_head = ConvertToUTF16(head);
+		WCHAR *w_msg = ConvertToUTF16(msg);
+		MessageBox(NULL, w_msg, w_head, MB_OK | MB_ICONSTOP | MB_SYSTEMMODAL | MB_SETFOREGROUND);
+		delete w_head;
+		delete w_msg;
+	}
 
-int msgBoxQuestion(const char *head, const char *msg) {
-	WCHAR *w_head = ConvertToUTF16(head);
-	WCHAR *w_msg = ConvertToUTF16(msg);
-	int val = MessageBox(NULL, w_msg, w_head, MB_YESNO | MB_SETFOREGROUND | MB_APPLMODAL | MB_ICONQUESTION) == IDNO;
-	delete w_head;
-	delete w_msg;
-	if (val)
+	int msgBoxQuestion(const char *head, const char *msg) {
+		WCHAR *w_head = ConvertToUTF16(head);
+		WCHAR *w_msg = ConvertToUTF16(msg);
+		int val = MessageBox(NULL, w_msg, w_head, MB_YESNO | MB_SETFOREGROUND | MB_APPLMODAL | MB_ICONQUESTION) == IDNO;
+		delete w_head;
+		delete w_msg;
+		if (val)
 		return false;
-	return true;
-}
-
-void changeToUserDir() {
-	TCHAR szAppData[MAX_PATH];
-	/*hr = */SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szAppData);
-	_wchdir(szAppData);
-}
-
-uint32_t launch(char *f) {
-	WCHAR *w_f = ConvertToUTF16(f);
-	uint32_t r = (uint32_t) ShellExecute(hMainWindow, TEXT("open"), w_f, NULL, TEXT("C:\\"), SW_SHOWNORMAL);
-	delete w_f;
-	return r;
-}
-
-bool defaultUserFullScreen() {
-	return true;
-}
+		return true;
+	}
+
+	void changeToUserDir() {
+		TCHAR szAppData[MAX_PATH];
+		/*hr = */SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szAppData);
+		_wchdir(szAppData);
+	}
+
+	uint32_t launch(char *f) {
+		WCHAR *w_f = ConvertToUTF16(f);
+		uint32_t r = (uint32_t) ShellExecute(hMainWindow, TEXT("open"), w_f, NULL, TEXT("C:\\"), SW_SHOWNORMAL);
+		delete w_f;
+		return r;
+	}
+
+	bool defaultUserFullScreen() {
+		return true;
+	}
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/zbuffer.cpp b/engines/sludge/zbuffer.cpp
index f73f4f6..fe13a98 100644
--- a/engines/sludge/zbuffer.cpp
+++ b/engines/sludge/zbuffer.cpp
@@ -47,13 +47,14 @@ void killZBuffer() {
 void sortZPal(int *oldpal, int *newpal, int size) {
 	int i, tmp;
 
-	for (i = 0; i < size; i ++) {
+	for (i = 0; i < size; i++) {
 		newpal[i] = i;
 	}
 
-	if (size < 2) return;
+	if (size < 2)
+		return;
 
-	for (i = 1; i < size; i ++) {
+	for (i = 1; i < size; i++) {
 		if (oldpal[newpal[i]] < oldpal[newpal[i - 1]]) {
 			tmp = newpal[i];
 			newpal[i] = newpal[i - 1];
@@ -80,17 +81,17 @@ bool setZBuffer(int y) {
 	if (fgetc(bigDataFile) != 'b') return fatal("Not a Z-buffer file");
 
 	switch (fgetc(bigDataFile)) {
-	case 0:
+		case 0:
 		zBuffer.width = 640;
 		zBuffer.height = 480;
 		break;
 
-	case 1:
+		case 1:
 		zBuffer.width = get2bytes(bigDataFile);
 		zBuffer.height = get2bytes(bigDataFile);
 		break;
 
-	default:
+		default:
 		return fatal("Extended Z-buffer format not supported in this version of the SLUDGE engine");
 	}
 	if (zBuffer.width != sceneWidth || zBuffer.height != sceneHeight) {
diff --git a/engines/sludge/zbuffer.h b/engines/sludge/zbuffer.h
index 6fdbd02..46510ec 100644
--- a/engines/sludge/zbuffer.h
+++ b/engines/sludge/zbuffer.h
@@ -44,7 +44,6 @@ struct zBufferData {
 #endif
 };
 
-
 bool setZBuffer(int y);
 void killZBuffer();
 void drawZBuffer(int x, int y, bool upsidedown);


Commit: 6e5dec313788be6ac3083e9d3ca30a9b66243894
    https://github.com/scummvm/scummvm/commit/6e5dec313788be6ac3083e9d3ca30a9b66243894
Author: yinsimei (roseline.yin at gmail.com)
Date: 2017-07-13T18:27:45+02:00

Commit Message:
SLUDGE: Fix png displaying

Changed paths:
    engines/sludge/backdrop.cpp
    engines/sludge/main_loop.cpp


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index 7fecf57..ff24e1b 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -58,6 +58,7 @@
 #include "common/debug.h"
 #include "image/png.h"
 #include "graphics/surface.h"
+#include "graphics/palette.h"
 #include "sludge.h"
 
 namespace Sludge {
@@ -81,6 +82,7 @@ GLuint snapshotTextureName = 0;
 
 Graphics::Surface backdropSurface;
 
+
 float snapTexW = 1.0;
 float snapTexH = 1.0;
 
@@ -1017,6 +1019,8 @@ bool loadPng(int &picWidth, int &picHeight, int &realPicWidth,
 		return false;
 	}
 	backdropSurface.copyFrom(*(png.getSurface()));
+	const byte *palette = png.getPalette();
+	g_system->getPaletteManager()->setPalette(palette, 0, 256);
 	picWidth = realPicWidth = backdropSurface.w;
 	picHeight = realPicHeight = backdropSurface.h;
 	return true;
@@ -1137,11 +1141,12 @@ bool loadByteArray(int &picWidth, int &picHeight, int &realPicWidth,
 bool loadImage(int &picWidth, int &picHeight, int &realPicWidth,
 		int &realPicHeight, Common::SeekableReadStream *stream, int x, int y,
 		bool reserve) {
-	debug(kSludgeDebugGraphics, "Loading back drop image.");
+	debug(kSludgeDebugGraphics, "Loading back drop image at file position: %i", stream->pos());
 	if (!loadPng(picWidth, picHeight, realPicWidth, realPicHeight, stream,
 			reserve)) {
 		if (!loadByteArray(picWidth, picHeight, realPicWidth, realPicHeight,
 				stream, reserve)) {
+			debug(kSludgeDebugGr