[Scummvm-cvs-logs] CVS: scummvm/gob anim.cpp,1.4,1.5 anim.h,1.5,1.6 cdrom.cpp,1.4,1.5 cdrom.h,1.2,1.3 dataio.cpp,1.11,1.12 dataio.h,1.7,1.8 draw.cpp,1.14,1.15 draw.h,1.6,1.7 driver_vga.cpp,1.12,1.13 driver_vga.h,1.6,1.7 game.cpp,1.28,1.29 game.h,1.6,1.7 global.cpp,1.9,1.10 global.h,1.8,1.9 gob.cpp,1.27,1.28 gob.h,1.11,1.12 goblin.cpp,1.24,1.25 goblin.h,1.6,1.7 init.cpp,1.12,1.13 init.h,1.4,1.5 inter.cpp,1.25,1.26 inter.h,1.4,1.5 map.cpp,1.17,1.18 map.h,1.11,1.12 mult.cpp,1.13,1.14 mult.h,1.6,1.7 pack.cpp,1.6,1.7 pack.h,1.4,1.5 palanim.cpp,1.11,1.12 palanim.h,1.4,1.5 parse.cpp,1.15,1.16 parse.h,1.4,1.5 scenery.cpp,1.20,1.21 scenery.h,1.7,1.8 sound.cpp,1.13,1.14 sound.h,1.9,1.10 timer.cpp,1.7,1.8 timer.h,1.4,1.5 util.cpp,1.18,1.19 util.h,1.6,1.7 video.cpp,1.16,1.17 video.h,1.10,1.11

Eugene Sandulenko sev at users.sourceforge.net
Tue Jan 3 15:16:01 CET 2006


Update of /cvsroot/scummvm/scummvm/gob
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26509

Modified Files:
	anim.cpp anim.h cdrom.cpp cdrom.h dataio.cpp dataio.h draw.cpp 
	draw.h driver_vga.cpp driver_vga.h game.cpp game.h global.cpp 
	global.h gob.cpp gob.h goblin.cpp goblin.h init.cpp init.h 
	inter.cpp inter.h map.cpp map.h mult.cpp mult.h pack.cpp 
	pack.h palanim.cpp palanim.h parse.cpp parse.h scenery.cpp 
	scenery.h sound.cpp sound.h timer.cpp timer.h util.cpp util.h 
	video.cpp video.h 
Log Message:
Patch #1395615 "GobEngine code wrapped in classes". With some cosmetic changes.


Index: anim.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/anim.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- anim.cpp	18 Oct 2005 01:30:17 -0000	1.4
+++ anim.cpp	3 Jan 2006 23:14:39 -0000	1.5
@@ -25,10 +25,12 @@
 
 namespace Gob {
 
-int16 anim_animAreaLeft;
-int16 anim_animAreaTop;
-int16 anim_animAreaWidth;
-int16 anim_animAreaHeight;
-SurfaceDesc *anim_underAnimSurf = 0;
+Anim::Anim() {
+	_areaLeft = 0;
+	_areaTop = 0;
+	_areaWidth = 0;
+	_areaHeight = 0;
+	_animSurf = 0;
+}
 
 }				// End of namespace Gob

Index: anim.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/anim.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- anim.h	18 Oct 2005 01:30:17 -0000	1.5
+++ anim.h	3 Jan 2006 23:14:39 -0000	1.6
@@ -24,11 +24,16 @@
 
 namespace Gob {
 
-extern int16 anim_animAreaLeft;
-extern int16 anim_animAreaTop;
-extern int16 anim_animAreaWidth;
-extern int16 anim_animAreaHeight;
-extern SurfaceDesc *anim_underAnimSurf;
+class Anim {
+public:
+	int16 _areaLeft;
+	int16 _areaTop;
+	int16 _areaWidth;
+	int16 _areaHeight;
+	Video::SurfaceDesc *_animSurf;
+
+	Anim();
+};
 
 }				// End of namespace Gob
 

Index: cdrom.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/cdrom.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cdrom.cpp	18 Oct 2005 01:30:17 -0000	1.4
+++ cdrom.cpp	3 Jan 2006 23:14:39 -0000	1.5
@@ -28,73 +28,76 @@
 
 namespace Gob {
 
-byte *cd_LICbuffer;
-char cd_curTrack[16];
-uint16 cd_numTracks;
-bool cd_globFlag;
-uint32 cd_trackStop;
-uint32 cd_startTime;
+CDROM::CDROM(GobEngine *vm) : _vm(vm) {
+	_cdPlaying = false;
+	_LICbuffer = 0;
+	for (int i = 0; i < 16; i++)
+		_curTrack[i] = 0;
+	_numTracks = 0;
+	_trackStop = 0;
+	_startTime = 0;
+}
 
-void cd_readLIC(const char *fname) {
+void CDROM::readLIC(const char *fname) {
 	char tmp[80];
 	int handle;
 	uint16 version, startChunk, pos;
 
-	cd_freeLICbuffer();
+	freeLICbuffer();
 
-	*cd_curTrack = 0;
+	*_curTrack = 0;
 
 	strcpy(tmp, fname);
 
-	handle = data_openData(tmp);
+	handle = _vm->_dataio->openData(tmp);
 
 	if (handle == -1)
 		return;
 
-	data_closeData(handle);
+	_vm->_dataio->closeData(handle);
 
-	data_getUnpackedData(tmp);
+	_vm->_dataio->getUnpackedData(tmp);
 
-	handle = data_openData(tmp);
+	handle = _vm->_dataio->openData(tmp);
 
-	data_readData(handle, (char *)&version, 2);
+	_vm->_dataio->readData(handle, (char *)&version, 2);
 	version = READ_LE_UINT16(&version);
 
-	data_readData(handle, (char *)&startChunk, 2);
+	_vm->_dataio->readData(handle, (char *)&startChunk, 2);
 	startChunk = READ_LE_UINT16(&startChunk);
 
-	data_readData(handle, (char *)&cd_numTracks, 2);
-	cd_numTracks = READ_LE_UINT16(&cd_numTracks);
+	_vm->_dataio->readData(handle, (char *)&_numTracks, 2);
+	_numTracks = READ_LE_UINT16(&_numTracks);
 
 	if (version != 3) {
 		error("Wrong file %s (%d)", fname, version);
 		return;
 	}
 
-	data_seekData(handle, 50, SEEK_SET);
+	_vm->_dataio->seekData(handle, 50, SEEK_SET);
 
 	for (int i = 0; i < startChunk; i++) {
-		data_readData(handle, (char *)&pos, 2);
+		_vm->_dataio->readData(handle, (char *)&pos, 2);
 		pos = READ_LE_UINT16(&pos);
 
 		if (!pos)
 			break;
 
-		data_seekData(handle, pos, SEEK_CUR);
+		_vm->_dataio->seekData(handle, pos, SEEK_CUR);
 	}
 
-	cd_LICbuffer = (byte *)malloc(cd_numTracks * 22);
-	data_readData(handle, (char *)cd_LICbuffer, cd_numTracks * 22);
+	_LICbuffer = (byte *)malloc(_numTracks * 22);
+	_vm->_dataio->readData(handle, (char *)_LICbuffer, _numTracks * 22);
 
-	data_closeData(handle);
+	_vm->_dataio->closeData(handle);
 }
 
-void cd_freeLICbuffer(void) {
-	free(cd_LICbuffer);
-	cd_LICbuffer = 0;
+void CDROM::freeLICbuffer(void) {
+	free(_LICbuffer);
+	_LICbuffer = 0;
 }
 
-void cd_playBgMusic() {
+void CDROM::playBgMusic() {
 	static const char *tracks[][2] = {
 		{"avt00.tot",  "mine"},
 		{"avt001.tot", "nuit"},
@@ -121,13 +124,13 @@
 	};
 
 	for (int i = 0; i < ARRAYSIZE(tracks); i++)
-		if (!scumm_stricmp(game_curTotFile, tracks[i][0])) {
-			cd_startTrack(tracks[i][1]);
+		if (!scumm_stricmp(_vm->_game->curTotFile, tracks[i][0])) {
+			startTrack(tracks[i][1]);
 			break;
 		}
 }
 
-void cd_playMultMusic() {
+void CDROM::playMultMusic() {
 	static const char *tracks[][6] = {
 		{"avt005.tot", "fra1", "all1", "ang1", "esp1", "ita1"},
 		{"avt006.tot", "fra2", "all2", "ang2", "esp2", "ita2"},
@@ -138,25 +141,25 @@
 	};
 
 	for (int i = 0; i < ARRAYSIZE(tracks); i++)
-		if (!scumm_stricmp(game_curTotFile, tracks[i][0])) {
-			cd_globFlag = true;
-			cd_startTrack(tracks[i][language + 1]);
+		if (!scumm_stricmp(_vm->_game->curTotFile, tracks[i][0])) {
+			_cdPlaying = true;
+			startTrack(tracks[i][_vm->_global->language + 1]);
 			break;
 		}
 }
 
-void cd_startTrack(const char *trackname) {
+void CDROM::startTrack(const char *trackname) {
 	byte *curPtr, *matchPtr;
 
-	if (!cd_LICbuffer)
+	if (!_LICbuffer)
 		return;
 
-	debug(3, "cd_startTrack(%s)", trackname);
+	debug(3, "startTrack(%s)", trackname);
 
 	matchPtr = 0;
-	curPtr = cd_LICbuffer;
+	curPtr = _LICbuffer;
 
-	for (int i = 0; i < cd_numTracks; i++) {
+	for (int i = 0; i < _numTracks; i++) {
 		if (!scumm_stricmp((char *)curPtr, trackname)) {
 			matchPtr = curPtr;
 			break;
@@ -169,64 +172,64 @@
 		return;
 	}
 
-	strcpy(cd_curTrack, trackname);
+	strcpy(_curTrack, trackname);
 
-	cd_stopPlaying();
+	stopPlaying();
 
-	while (cd_getTrackPos() != -1);
+	while (getTrackPos() != -1);
 
 	uint32 start, end;
 
 	start = READ_LE_UINT32(matchPtr + 12);
 	end   = READ_LE_UINT32(matchPtr + 16);
 
-	cd_play(start, end);
+	play(start, end);
 
-	cd_startTime = util_getTimeKey();
-	cd_trackStop = cd_startTime + (end - start + 1 + 150) * 40 / 3;
+	_startTime = _vm->_util->getTimeKey();
+	_trackStop = _startTime + (end - start + 1 + 150) * 40 / 3;
 }
 
-void cd_play(uint32 from, uint32 to) {
+void CDROM::play(uint32 from, uint32 to) {
 	// play from sector [from] to sector [to]
 	//
 	// format is HSG:
 	// HSG encodes frame information into a double word:
 	// minute multiplied by 4500, plus second multiplied by 75,
 	// plus frame, minus 150
-	debug(3, "cd_play(%d, %d)", from, to);
+	debug(3, "play(%d, %d)", from, to);
 
 	AudioCD.play(1, 0, from, to - from + 1);
 }
 
-int32 cd_getTrackPos(void) {
-	uint32 curPos = util_getTimeKey() - cd_startTime;
+int32 CDROM::getTrackPos(void) {
+	uint32 curPos = _vm->_util->getTimeKey() - _startTime;
 
-	if (AudioCD.isPlaying() && (util_getTimeKey() < cd_trackStop))
+	if (AudioCD.isPlaying() && (_vm->_util->getTimeKey() < _trackStop))
 		return curPos * 3 / 40;
 	else
 		return -1;
 }
 
-void cd_stopPlaying(void) {
-	cd_stop();
+void CDROM::stopPlaying(void) {
+	stop();
 
-	while (cd_getTrackPos() != -1);
+	while (getTrackPos() != -1);
 }
 
-void cd_stop(void) {
-	debug(3, "cd_stop()");
+void CDROM::stop(void) {
+	debug(3, "stop()");
 
 	AudioCD.stop();
 }
 
-void cd_testCD(int trySubst, const char *label) {
+void CDROM::testCD(int trySubst, const char *label) {
 	if (!trySubst) {
 		error("CDROM track substitution is not supported");
 		return;
 	}
 
-	cd_LICbuffer = 0;
-	cd_globFlag = false;
+	_LICbuffer = 0;
+	_cdPlaying = false;
 
 	// Original checked CD label here
 	// but will skip it as it will require OSystem extensions of direct

Index: cdrom.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/cdrom.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cdrom.h	18 Oct 2005 01:30:17 -0000	1.2
+++ cdrom.h	3 Jan 2006 23:14:39 -0000	1.3
@@ -22,18 +22,31 @@
 
 namespace Gob {
 
-extern bool cd_globFlag;
+class CDROM {
+public:
+	bool _cdPlaying;
 
-void cd_readLIC(const char *fname);
-void cd_freeLICbuffer(void);
+	void readLIC(const char *fname);
+	void freeLICbuffer(void);
 
-void cd_startTrack(const char *s);
-void cd_playBgMusic();
-void cd_playMultMusic();
-void cd_play(uint32 from, uint32 to);
-int32 cd_getTrackPos(void);
-void cd_stopPlaying(void);
-void cd_stop(void);
-void cd_testCD(int trySubst, const char *label);
+	void startTrack(const char *s);
+	void playBgMusic();
+	void playMultMusic();
+	void play(uint32 from, uint32 to);
+	int32 getTrackPos(void);
+	void stopPlaying(void);
+	void stop(void);
+	void testCD(int trySubst, const char *label);
+
+	CDROM(GobEngine *vm);
+
+protected:
+	byte *_LICbuffer;
+	char _curTrack[16];
+	uint16 _numTracks;
+	uint32 _trackStop;
+	uint32 _startTime;
+	GobEngine *_vm;
+};
 
 } // End of namespace Gob

Index: dataio.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/dataio.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- dataio.cpp	22 Nov 2005 13:17:08 -0000	1.11
+++ dataio.cpp	3 Jan 2006 23:14:39 -0000	1.12
@@ -26,11 +26,14 @@
 
 namespace Gob {
 
-Common::File *file_getHandle(int16 handle) {
-	return &filesHandles[handle];
+DataIO::DataIO(GobEngine *vm) : _vm(vm) {
 }
 
-int16 file_open(const char *path, Common::File::AccessMode mode) {
+Common::File *DataIO::file_getHandle(int16 handle) {
+	return &_vm->_global->filesHandles[handle];
+}
+
+int16 DataIO::file_open(const char *path, Common::File::AccessMode mode) {
 	int16 i;
 
 	for (i = 0; i < MAX_FILES; i++) {
@@ -48,51 +51,51 @@
 	return -1;
 }
 
-int16 data_getChunk(const char *chunkName) {
+int16 DataIO::getChunk(const char *chunkName) {
 	int16 file;
 	int16 slot;
 	int16 chunk;
 	struct ChunkDesc *dataDesc;
 
 	for (file = 0; file < MAX_DATA_FILES; file++) {
-		if (dataFiles[file] == 0)
+		if (_vm->_global->dataFiles[file] == 0)
 			return -1;
 
 		for (slot = 0; slot < MAX_SLOT_COUNT; slot++)
-			if (chunkPos[file * MAX_SLOT_COUNT + slot] == -1)
+			if (_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] == -1)
 				break;
 
 		if (slot == MAX_SLOT_COUNT)
 			return -1;
 
-		dataDesc = dataFiles[file];
-		for (chunk = 0; chunk < numDataChunks[file];
+		dataDesc = _vm->_global->dataFiles[file];
+		for (chunk = 0; chunk < _vm->_global->numDataChunks[file];
 		    chunk++, dataDesc++) {
 			if (scumm_stricmp(chunkName, dataDesc->chunkName) != 0)
 				continue;
 
-			isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0;
-			chunkSize[file * MAX_SLOT_COUNT + slot] =
+			_vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0;
+			_vm->_global->chunkSize[file * MAX_SLOT_COUNT + slot] =
 			    dataDesc->size;
-			chunkOffset[file * MAX_SLOT_COUNT + slot] =
+			_vm->_global->chunkOffset[file * MAX_SLOT_COUNT + slot] =
 			    dataDesc->offset;
-			chunkPos[file * MAX_SLOT_COUNT + slot] = 0;
+			_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] = 0;
 			return file * 10 + slot + 50;
 		}
 	}
 	return -1;
 }
 
-char data_freeChunk(int16 handle) {
+char DataIO::freeChunk(int16 handle) {
 	if (handle >= 50 && handle < 100) {
 		handle -= 50;
-		chunkPos[(handle / 10) * MAX_SLOT_COUNT + (handle % 10)] = -1;
+		_vm->_global->chunkPos[(handle / 10) * MAX_SLOT_COUNT + (handle % 10)] = -1;
 		return 0;
 	}
 	return 1;
 }
 
-int32 data_readChunk(int16 handle, char *buf, int16 size) {
+int32 DataIO::readChunk(int16 handle, char *buf, int16 size) {
 	int16 file;
 	int16 slot;
 	int16 i;
@@ -103,30 +106,30 @@
 
 	file = (handle - 50) / 10;
 	slot = (handle - 50) % 10;
-	if (isCurrentSlot[file * MAX_SLOT_COUNT + slot] == 0) {
+	if (_vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] == 0) {
 		for (i = 0; i < MAX_SLOT_COUNT; i++)
-			isCurrentSlot[file * MAX_SLOT_COUNT + i] = 0;
+			_vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + i] = 0;
 
 		offset =
-		    chunkOffset[file * MAX_SLOT_COUNT + slot] +
-		    chunkPos[file * MAX_SLOT_COUNT + slot];
-		debug(7, "seek: %ld, %ld", chunkOffset[file * MAX_SLOT_COUNT + slot], chunkPos[file * MAX_SLOT_COUNT + slot]);
-		file_getHandle(dataFileHandles[file])->seek(offset, SEEK_SET);
+		    _vm->_global->chunkOffset[file * MAX_SLOT_COUNT + slot] +
+		    _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot];
+		debug(7, "seek: %ld, %ld", _vm->_global->chunkOffset[file * MAX_SLOT_COUNT + slot], _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot]);
+		file_getHandle(_vm->_global->dataFileHandles[file])->seek(offset, SEEK_SET);
 	}
 
-	isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 1;
-	if (chunkPos[file * MAX_SLOT_COUNT + slot] + size >
-	    chunkSize[file * MAX_SLOT_COUNT + slot])
+	_vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 1;
+	if (_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] + size >
+	    _vm->_global->chunkSize[file * MAX_SLOT_COUNT + slot])
 		size =
-		    chunkSize[file * MAX_SLOT_COUNT + slot] -
-		    chunkPos[file * MAX_SLOT_COUNT + slot];
+		    _vm->_global->chunkSize[file * MAX_SLOT_COUNT + slot] -
+		    _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot];
 
-	file_getHandle(dataFileHandles[file])->read(buf, size);
-	chunkPos[file * MAX_SLOT_COUNT + slot] += size;
+	file_getHandle(_vm->_global->dataFileHandles[file])->read(buf, size);
+	_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] += size;
 	return size;
 }
 
-int16 data_seekChunk(int16 handle, int32 pos, int16 from) {
+int16 DataIO::seekChunk(int16 handle, int32 pos, int16 from) {
 	int16 file;
 	int16 slot;
 
@@ -135,16 +138,16 @@
 
 	file = (handle - 50) / 10;
 	slot = (handle - 50) % 10;
-	isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0;
+	_vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0;
 	if (from == SEEK_SET)
-		chunkPos[file * MAX_SLOT_COUNT + slot] = pos;
+		_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] = pos;
 	else
-		chunkPos[file * MAX_SLOT_COUNT + slot] += pos;
+		_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] += pos;
 
-	return chunkPos[file * MAX_SLOT_COUNT + slot];
+	return _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot];
 }
 
-int32 data_getChunkSize(const char *chunkName) {
+int32 DataIO::getChunkSize(const char *chunkName) {
 	int16 file;
 	int16 chunk;
 	struct ChunkDesc *dataDesc;
@@ -152,33 +155,33 @@
 	int32 realSize;
 
 	for (file = 0; file < MAX_DATA_FILES; file++) {
-		if (dataFiles[file] == 0)
+		if (_vm->_global->dataFiles[file] == 0)
 			return -1;
 
-		dataDesc = dataFiles[file];
-		for (chunk = 0; chunk < numDataChunks[file];
+		dataDesc = _vm->_global->dataFiles[file];
+		for (chunk = 0; chunk < _vm->_global->numDataChunks[file];
 		    chunk++, dataDesc++) {
 			if (scumm_stricmp(chunkName, dataDesc->chunkName) != 0)
 				continue;
 
 			if (dataDesc->packed == 0) {
-				packedSize = -1;
+				_vm->_global->packedSize = -1;
 				return dataDesc->size;
 			}
 
 			for (slot = 0; slot < MAX_SLOT_COUNT; slot++)
-				isCurrentSlot[slot] = 0;
+				_vm->_global->isCurrentSlot[slot] = 0;
 
-			file_getHandle(dataFileHandles[file])->seek(dataDesc->offset, SEEK_SET);
-			realSize = file_getHandle(dataFileHandles[file])->readUint32LE();
-			packedSize = dataDesc->size;
+			file_getHandle(_vm->_global->dataFileHandles[file])->seek(dataDesc->offset, SEEK_SET);
+			realSize = file_getHandle(_vm->_global->dataFileHandles[file])->readUint32LE();
+			_vm->_global->packedSize = dataDesc->size;
 			return realSize;
 		}
 	}
 	return -1;
 }
 
-void data_openDataFile(const char *src) {
+void DataIO::openDataFile(const char *src) {
 	char path[128];
 	int16 i;
 	int16 file;
@@ -190,52 +193,52 @@
 		strcat(path, ".stk");
 
 	for (file = 0; file < MAX_DATA_FILES; file++)
-		if (dataFiles[file] == 0)
+		if (_vm->_global->dataFiles[file] == 0)
 			break;
 
 	if (file == MAX_DATA_FILES)
-		error("data_dataFileOpen: Data file slots are full\n");
-	dataFileHandles[file] = file_open(path);
+		error("dataFileOpen: Data file slots are full\n");
+	_vm->_global->dataFileHandles[file] = file_open(path);
 
-	if (dataFileHandles[file] == -1)
-		error("data_dataFileOpen: Can't open %s data file\n", path);
+	if (_vm->_global->dataFileHandles[file] == -1)
+		error("dataFileOpen: Can't open %s data file\n", path);
 
-	numDataChunks[file] = file_getHandle(dataFileHandles[file])->readUint16LE();
+	_vm->_global->numDataChunks[file] = file_getHandle(_vm->_global->dataFileHandles[file])->readUint16LE();
 
-	debug(7, "DataChunks: %d [for %s]", numDataChunks[file], path);
+	debug(7, "DataChunks: %d [for %s]", _vm->_global->numDataChunks[file], path);
 
-	dataFiles[file] = dataDesc =
+	_vm->_global->dataFiles[file] = dataDesc =
 	    (struct ChunkDesc *)malloc(sizeof(struct ChunkDesc) *
-	    numDataChunks[file]);
+	    _vm->_global->numDataChunks[file]);
 
-	for (i = 0; i < numDataChunks[file]; i++) {
-		file_getHandle(dataFileHandles[file])->read(dataDesc[i].chunkName, 13);
-		dataDesc[i].size = file_getHandle(dataFileHandles[file])->readUint32LE();
-		dataDesc[i].offset = file_getHandle(dataFileHandles[file])->readUint32LE();
-		dataDesc[i].packed = file_getHandle(dataFileHandles[file])->readByte();
+	for (i = 0; i < _vm->_global->numDataChunks[file]; i++) {
+		file_getHandle(_vm->_global->dataFileHandles[file])->read(dataDesc[i].chunkName, 13);
+		dataDesc[i].size = file_getHandle(_vm->_global->dataFileHandles[file])->readUint32LE();
+		dataDesc[i].offset = file_getHandle(_vm->_global->dataFileHandles[file])->readUint32LE();
+		dataDesc[i].packed = file_getHandle(_vm->_global->dataFileHandles[file])->readByte();
 	}
 
-	for (i = 0; i < numDataChunks[file]; i++)
+	for (i = 0; i < _vm->_global->numDataChunks[file]; i++)
 		debug(7, "%d: %s %d", i, dataDesc[i].chunkName, dataDesc[i].size);
 
 	for (i = 0; i < MAX_SLOT_COUNT; i++)
-		chunkPos[file * MAX_SLOT_COUNT + i] = -1;
+		_vm->_global->chunkPos[file * MAX_SLOT_COUNT + i] = -1;
 
 }
 
-void data_closeDataFile() {
+void DataIO::closeDataFile() {
 	int16 file;
 	for (file = MAX_DATA_FILES - 1; file >= 0; file--) {
-		if (dataFiles[file] != 0) {
-			free(dataFiles[file]);
-			dataFiles[file] = 0;
-			file_getHandle(dataFileHandles[file])->close();
+		if (_vm->_global->dataFiles[file] != 0) {
+			free(_vm->_global->dataFiles[file]);
+			_vm->_global->dataFiles[file] = 0;
+			file_getHandle(_vm->_global->dataFileHandles[file])->close();
 			return;
 		}
 	}
 }
 
-char *data_getUnpackedData(const char *name) {
+char *DataIO::getUnpackedData(const char *name) {
 	int32 realSize;
 	int16 chunk;
 	char *unpackBuf;
@@ -243,11 +246,11 @@
 	char *ptr;
 	int32 sizeLeft;
 
-	realSize = data_getChunkSize(name);
-	if (packedSize == -1 || realSize == -1)
+	realSize = getChunkSize(name);
+	if (_vm->_global->packedSize == -1 || realSize == -1)
 		return 0;
 
-	chunk = data_getChunk(name);
+	chunk = getChunk(name);
 	if (chunk == -1)
 		return 0;
 
@@ -255,76 +258,76 @@
 	if (unpackBuf == 0)
 		return 0;
 
-	packBuf = (char *)malloc(packedSize);
+	packBuf = (char *)malloc(_vm->_global->packedSize);
 	if (packBuf == 0) {
 		free(unpackBuf);
 		return 0;
 	}
 
-	sizeLeft = packedSize;
+	sizeLeft = _vm->_global->packedSize;
 	ptr = packBuf;
 	while (sizeLeft > 0x4000) {
-		data_readChunk(chunk, ptr, 0x4000);
+		readChunk(chunk, ptr, 0x4000);
 		sizeLeft -= 0x4000;
 		ptr += 0x4000;
 	}
-	data_readChunk(chunk, ptr, sizeLeft);
-	data_freeChunk(chunk);
-	unpackData(packBuf, unpackBuf);
+	readChunk(chunk, ptr, sizeLeft);
+	freeChunk(chunk);
+	_vm->_pack->unpackData(packBuf, unpackBuf);
 	free(packBuf);
 	return unpackBuf;
 }
 
-void data_closeData(int16 handle) {
-	if (data_freeChunk(handle) != 0)
+void DataIO::closeData(int16 handle) {
+	if (freeChunk(handle) != 0)
 		file_getHandle(handle)->close();
 }
 
-int16 data_openData(const char *path, Common::File::AccessMode mode) {
+int16 DataIO::openData(const char *path, Common::File::AccessMode mode) {
 	int16 handle;
 
 	if (mode != Common::File::kFileReadMode)
 		return file_open(path, mode);
 
-	handle = data_getChunk(path);
+	handle = getChunk(path);
 	if (handle >= 0)
 		return handle;
 
 	return file_open(path, mode);
 }
 
-int32 data_readData(int16 handle, char *buf, int16 size) {
+int32 DataIO::readData(int16 handle, char *buf, int16 size) {
 	int32 res;
 
-	res = data_readChunk(handle, buf, size);
+	res = readChunk(handle, buf, size);
 	if (res >= 0)
 		return res;
 
 	return file_getHandle(handle)->read(buf, size);
 }
 
-void data_seekData(int16 handle, int32 pos, int16 from) {
+void DataIO::seekData(int16 handle, int32 pos, int16 from) {
 	int32 resPos;
 
-	resPos = data_seekChunk(handle, pos, from);
+	resPos = seekChunk(handle, pos, from);
 	if (resPos != -1)
 		return;
 
 	file_getHandle(handle)->seek(pos, from);
 }
 
-int32 data_getDataSize(const char *name) {
+int32 DataIO::getDataSize(const char *name) {
 	char buf[128];
 	int32 chunkSz;
 	Common::File file;
 
 	strcpy(buf, name);
-	chunkSz = data_getChunkSize(buf);
+	chunkSz = getChunkSize(buf);
 	if (chunkSz >= 0)
 		return chunkSz;
 
 	if (!file.open(buf))
-		error("data_getDataSize: Can't find data(%s)", name);
+		error("getDataSize: Can't find data(%s)", name);
 
 	chunkSz = file.size();
 	file.close();
@@ -332,31 +335,31 @@
 	return chunkSz;
 }
 
-char *data_getData(const char *path) {
+char *DataIO::getData(const char *path) {
 	char *data;
 	char *ptr;
 	int32 size;
 	int16 handle;
 
-	data = data_getUnpackedData(path);
+	data = getUnpackedData(path);
 	if (data != 0)
 		return data;
 
-	size = data_getDataSize(path);
+	size = getDataSize(path);
 	data = (char *)malloc(size);
 	if (data == 0)
 		return 0;
 
-	handle = data_openData(path);
+	handle = openData(path);
 
 	ptr = data;
 	while (size > 0x4000) {
-		data_readData(handle, ptr, 0x4000);
+		readData(handle, ptr, 0x4000);
 		size -= 0x4000;
 		ptr += 0x4000;
 	}
-	data_readData(handle, ptr, size);
-	data_closeData(handle);
+	readData(handle, ptr, size);
+	closeData(handle);
 	return data;
 }
 

Index: dataio.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/dataio.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dataio.h	18 Oct 2005 01:30:17 -0000	1.7
+++ dataio.h	3 Jan 2006 23:14:39 -0000	1.8
@@ -23,36 +23,46 @@
 #define GOB_DATAIO_H
 
 #include "common/file.h"
+#include "gob/gob.h"
 
 namespace Gob {
 
 #define MAX_DATA_FILES	3
 #define MAX_SLOT_COUNT	4
 
-struct ChunkDesc {
-	char chunkName[13];
-	uint32 size;
-	uint32 offset;
-	byte packed;
-};
+class DataIO {
+public:
+	struct ChunkDesc {
+		char chunkName[13];
+		uint32 size;
+		uint32 offset;
+		byte packed;
+		ChunkDesc() : size(0), offset(0), packed(0) { chunkName[0] = 0; }
+	};
 
-int16 file_open(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode);
-Common::File *file_getHandle(int16 handle);
-int16 data_getChunk(const char *chunkName);
-char data_freeChunk(int16 handle);
-int32 data_readChunk(int16 handle, char *buf, int16 size);
-int16 data_seekChunk(int16 handle, int32 pos, int16 from);
-int32 data_getChunkSize(const char *chunkName);
-void data_openDataFile(const char *src);
-void data_closeDataFile(void);
-char *data_getUnpackedData(const char *name);
-void data_closeData(int16 handle);
-int16 data_openData(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode);
-int32 data_readData(int16 handle, char *buf, int16 size);
-void data_seekData(int16 handle, int32 pos, int16 from);
-int32 data_getDataSize(const char *name);
-char *data_getData(const char *path);
-char *data_getSmallData(const char *path);
+	int16 file_open(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode);
+	Common::File *file_getHandle(int16 handle);
+	int16 getChunk(const char *chunkName);
+	char freeChunk(int16 handle);
+	int32 readChunk(int16 handle, char *buf, int16 size);
+	int16 seekChunk(int16 handle, int32 pos, int16 from);
+	int32 getChunkSize(const char *chunkName);
+	void openDataFile(const char *src);
+	void closeDataFile(void);
+	char *getUnpackedData(const char *name);
+	void closeData(int16 handle);
+	int16 openData(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode);
+	int32 readData(int16 handle, char *buf, int16 size);
+	void seekData(int16 handle, int32 pos, int16 from);
+	int32 getDataSize(const char *name);
+	char *getData(const char *path);
+	char *getSmallData(const char *path);
+
+	DataIO(class GobEngine *vm);
+
+protected:
+	class GobEngine *_vm;
+};
 
 }				// End of namespace Gob
 

Index: draw.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/draw.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- draw.cpp	18 Oct 2005 01:30:17 -0000	1.14
+++ draw.cpp	3 Jan 2006 23:14:39 -0000	1.15
@@ -33,72 +33,101 @@
 
 namespace Gob {
 
-int16 draw_fontIndex = 0;
-int16 draw_spriteLeft = 0;
-int16 draw_spriteTop = 0;
-int16 draw_spriteRight = 0;
-int16 draw_spriteBottom = 0;
-int16 draw_destSpriteX = 0;
-int16 draw_destSpriteY = 0;
-int16 draw_backColor = 0;
[...1297 lines suppressed...]
-		warning("draw_printText: Input not supported!");
+	renderFlags = savedFlags;
+	if (renderFlags & 4) {
+		warning("printText: Input not supported!");
 //              xor     ax, ax
 //              loc_436_1391:
 //              xor     dx, dx
@@ -913,9 +942,9 @@
 //              add     sp, 0Ch
 	}
 
-	if ((draw_renderFlags & RENDERFLAG_CAPTUREPOP) && *scen_pCaptureCounter != 0) {
-		(*scen_pCaptureCounter)--;
-		game_capturePop(1);
+	if ((renderFlags & RENDERFLAG_CAPTUREPOP) && *_vm->_scenery->pCaptureCounter != 0) {
+		(*_vm->_scenery->pCaptureCounter)--;
+		_vm->_game->capturePop(1);
 	}
 }
 

Index: draw.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/draw.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- draw.h	18 Oct 2005 01:30:17 -0000	1.6
+++ draw.h	3 Jan 2006 23:14:39 -0000	1.7
@@ -31,81 +31,95 @@
 #define RENDERFLAG_CAPTUREPOP	8
 #define RENDERFLAG_USEDELTAS 	0x10
 
-typedef struct Draw_FontToSprite {
-	int8 sprite;
-	int8 base;
-	int8 width;
-	int8 height;
-} Draw_FontToSprite;
+class Draw {
+	public:
+		typedef struct FontToSprite {
+			int8 sprite;
+			int8 base;
+			int8 width;
+			int8 height;
+			FontToSprite() : sprite(0), base(0), width(0), height() {}
+		} FontToSprite;
 
-extern int16 draw_fontIndex;
-extern int16 draw_spriteLeft;
-extern int16 draw_spriteTop;
-extern int16 draw_spriteRight;
-extern int16 draw_spriteBottom;
-extern int16 draw_destSpriteX;
-extern int16 draw_destSpriteY;
-extern int16 draw_backColor;
-extern int16 draw_frontColor;
-extern char draw_letterToPrint;
-extern Draw_FontToSprite draw_fontToSprite[4];
-extern int16 draw_destSurface;
-extern int16 draw_sourceSurface;
-extern int16 draw_renderFlags;
-extern int16 draw_backDeltaX;
-extern int16 draw_backDeltaY;
-extern FontDesc *draw_fonts[4];
-extern char *draw_textToPrint;
-extern int16 draw_transparency;
-extern SurfaceDesc *draw_spritesArray[50];
+		int16 fontIndex;
+		int16 spriteLeft;
+		int16 spriteTop;
+		int16 spriteRight;
+		int16 spriteBottom;
+		int16 destSpriteX;
+		int16 destSpriteY;
+		int16 backColor;
+		int16 frontColor;
+		char letterToPrint;
+		FontToSprite fontToSprite[4];
+		int16 destSurface;
+		int16 sourceSurface;
+		int16 renderFlags;
+		int16 backDeltaX;
+		int16 backDeltaY;
+		Video::FontDesc *fonts[4];
+		char *textToPrint;
+		int16 transparency;
+		Video::SurfaceDesc *spritesArray[50];
 
-extern int16 draw_invalidatedCount;
-extern int16 draw_invalidatedTops[30];
-extern int16 draw_invalidatedLefts[30];
-extern int16 draw_invalidatedRights[30];
-extern int16 draw_invalidatedBottoms[30];
+		int16 invalidatedCount;
+		int16 invalidatedTops[30];
+		int16 invalidatedLefts[30];
+		int16 invalidatedRights[30];
+		int16 invalidatedBottoms[30];
 
-extern int8 draw_noInvalidated;
-extern int8 draw_doFullFlip;
-extern int8 draw_paletteCleared;
+		int8 noInvalidated;
+//		int8 doFullFlip; // Never used?!?
+		int8 paletteCleared;
 
-extern int16 draw_cursorIndex;
-extern int16 draw_transparentCursor;
+		int16 gcursorIndex;
+		int16 transparentCursor;
+		uint32 cursorTimeKey;
 
-extern SurfaceDesc *draw_backSurface;
-extern SurfaceDesc *draw_frontSurface;
+		Video::SurfaceDesc *backSurface;
+		Video::SurfaceDesc *frontSurface;
 
-extern int16 draw_unusedPalette1[18];
-extern int16 draw_unusedPalette2[16];
-extern Color draw_vgaPalette[256];
-extern Color draw_vgaSmallPalette[16];
+		int16 unusedPalette1[18];
+		int16 unusedPalette2[16];
+		Video::Color vgaPalette[256];
+		Video::Color vgaSmallPalette[16];
 
-extern int16 draw_cursorX;
-extern int16 draw_cursorY;
-extern int16 draw_cursorWidth;
-extern int16 draw_cursorHeight;
+		int16 cursorX;
+		int16 cursorY;
+		int16 cursorWidth;
+		int16 cursorHeight;
 
-extern int16 draw_cursorXDeltaVar;
-extern int16 draw_cursorYDeltaVar;
+		int16 cursorXDeltaVar;
+		int16 cursorYDeltaVar;
 
-extern SurfaceDesc *draw_cursorSprites;
-extern SurfaceDesc *draw_cursorBack;
-extern int16 draw_cursorAnim;
-extern int8 draw_cursorAnimLow[40];
-extern int8 draw_cursorAnimHigh[40];
-extern int8 draw_cursorAnimDelays[40];
-extern int8 draw_applyPal;
+		Video::SurfaceDesc *cursorSprites;
+		Video::SurfaceDesc *cursorBack;
+		int16 cursorAnim;
+		int8 cursorAnimLow[40];
+		int8 cursorAnimHigh[40];
+		int8 cursorAnimDelays[40];
+		int8 applyPal;
 
-void draw_invalidateRect(int16 left, int16 top, int16 right, int16 bottom);
-void draw_blitInvalidated(void);
-void draw_setPalette(void);
-void draw_clearPalette(void);
-void draw_blitCursor(void);
+		int16 palLoadData1[4];
+		int16 palLoadData2[4];
+		
+		void invalidateRect(int16 left, int16 top, int16 right, int16 bottom);
+		void blitInvalidated(void);
+		void setPalette(void);
+		void clearPalette(void);
+		void blitCursor(void);
+
+		void spriteOperation(int16 operation);
+		void animateCursor(int16 cursor);
+		void interPalLoad(void);
+		void printText(void);
+
+		Draw(GobEngine *vm);
+
+	protected:
+		GobEngine *_vm;
+};
 
-void draw_spriteOperation(int16 operation);
-void draw_animateCursor(int16 cursor);
-void draw_interPalLoad(void);
-void draw_printText(void);
 // Draw operations
 
 #define DRAW_BLITSURF	0

Index: driver_vga.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/driver_vga.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- driver_vga.cpp	18 Oct 2005 01:30:17 -0000	1.12
+++ driver_vga.cpp	3 Jan 2006 23:14:39 -0000	1.13
@@ -30,7 +30,7 @@
 
 namespace Gob {
 
-void VGAVideoDriver::drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) {
+void VGAVideoDriver::drawSprite(Video::SurfaceDesc *source, Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) {
 	if (x >= 0 && x < dest->width && y >= 0 && y < dest->height) {
 		int16 width = (right - left) + 1;
 		int16 height = (bottom - top) + 1;
@@ -54,7 +54,7 @@
 	}
 }
 
-void VGAVideoDriver::fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) {
+void VGAVideoDriver::fillRect(Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) {
 	if (left < dest->width && right < dest->width && top < dest->height && bottom < dest->height) {
 		byte *pos = dest->vidPtr + (top * dest->width) + left;
 		int16 width = (right - left) + 1;
@@ -69,12 +69,12 @@
 	}
 }
 
-void VGAVideoDriver::putPixel(int16 x, int16 y, byte color, SurfaceDesc *dest) {
+void VGAVideoDriver::putPixel(int16 x, int16 y, byte color, Video::SurfaceDesc *dest) {
 	if (x >= 0 && x < dest->width && y >= 0 && y < dest->height)
 		dest->vidPtr[(y * dest->width) + x] = color;
 }
 
-void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc *dest) {
+void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, Video::SurfaceDesc *dest) {
 	byte *src, *dst;
 	uint16 data;
 	int i, j;
@@ -103,16 +103,16 @@
 }
 
 static void plotPixel(int x, int y, int color, void *data) {
-	SurfaceDesc *dest = (SurfaceDesc *)data;
+	Video::SurfaceDesc *dest = (Video::SurfaceDesc *)data;
 	if (x >= 0 && x < dest->width && y >= 0 && y < dest->height)
 		dest->vidPtr[(y * dest->width) + x] = color;
 }
 
-void VGAVideoDriver::drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) {
+void VGAVideoDriver::drawLine(Video::SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) {
 	Graphics::drawLine(x0, y0, x1, y1, color, &plotPixel, dest);
 }
 
-void VGAVideoDriver::drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc *dest) {
+void VGAVideoDriver::drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, Video::SurfaceDesc *dest) {
 	int destRight = x + width;
 	int destBottom = y + height;
 

Index: driver_vga.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/driver_vga.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- driver_vga.h	18 Oct 2005 01:30:17 -0000	1.6
+++ driver_vga.h	3 Jan 2006 23:14:39 -0000	1.7
@@ -29,13 +29,13 @@
 class VGAVideoDriver : public VideoDriver {
 public:
 	VGAVideoDriver() {}
-        virtual ~VGAVideoDriver() {}
-        void drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp);
-        void fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color);
-        void putPixel(int16 x, int16 y, byte color, SurfaceDesc *dest);
-        void drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc *dest);
-	void drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color);
-	void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc *dest);
+	virtual ~VGAVideoDriver() {}
+	void drawSprite(Video::SurfaceDesc *source, Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp);
+	void fillRect(Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color);
+	void putPixel(int16 x, int16 y, byte color, Video::SurfaceDesc *dest);
+	void drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, Video::SurfaceDesc *dest);
+	void drawLine(Video::SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color);
+	void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, Video::SurfaceDesc *dest);
 };
 
 }

Index: game.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/game.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- game.cpp	18 Oct 2005 01:30:17 -0000	1.28
+++ game.cpp	3 Jan 2006 23:14:39 -0000	1.29
@@ -36,57 +36,60 @@
 
 namespace Gob {
 
-Game_ExtTable *game_extTable = 0;
-
-char *game_totFileData = 0;
-Game_TotTextTable *game_totTextData;
-Game_TotResTable *game_totResourceTable = 0;
-char *game_imFileData = 0;
-int16 game_extHandle = 0;
-char game_curExtFile[14];
[...2410 lines suppressed...]
-	game_collisionAreas = (Game_Collision *)malloc(250 * sizeof(Game_Collision));
-	game_prepareStart();
-	game_playTot(0);
+void Game::start(void) {
+	collisionAreas = (Collision *)malloc(250 * sizeof(Collision));
+	prepareStart();
+	playTot(0);
 
-	free(game_collisionAreas);
+	free(collisionAreas);
 
-	vid_freeSurfDesc(draw_cursorSprites);
-	vid_freeSurfDesc(draw_cursorBack);
-	vid_freeSurfDesc(draw_backSurface);
+	_vm->_video->freeSurfDesc(_vm->_draw->cursorSprites);
+	_vm->_video->freeSurfDesc(_vm->_draw->cursorBack);
+	_vm->_video->freeSurfDesc(_vm->_draw->backSurface);
 }
 
 } // End of namespace Gob

Index: game.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/game.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- game.h	18 Oct 2005 01:30:17 -0000	1.6
+++ game.h	3 Jan 2006 23:14:39 -0000	1.7
@@ -26,139 +26,162 @@
 
 namespace Gob {
 
-#pragma START_PACK_STRUCTS
-#define szGame_ExtItem (4 + 2 + 2 + 2)
-typedef struct Game_ExtItem {
-	int32 offset;		// offset from the table end
-	uint16 size;
-	int16 width;		// width&0x7fff - width, width&0x8000 - pack flag
-	int16 height;		// not zero
-} GCC_PACK Game_ExtItem;
-
-#define szGame_ExtTable (2 + 1)
-typedef struct Game_ExtTable {
-	int16 itemsCount;
-	byte unknown;
-	Game_ExtItem items[1];
-} GCC_PACK Game_ExtTable;
+class Game {
+public:
 
+#pragma START_PACK_STRUCTS
 #define szGame_TotResItem (4 + 2 + 2 + 2)
-typedef struct Game_TotResItem {
-	int32 offset;	// if > 0, then offset from end of resource table.
-					// If < 0, then -offset-1 is index in .IM file table
-	int16 size;
-	int16 width;
-	int16 height;
-} GCC_PACK Game_TotResItem;
+	typedef struct Collision {
+		int16 id;
+		int16 left;
+		int16 top;
+		int16 right;
+		int16 bottom;
+		int16 flags;
+		int16 key;
+		int16 funcEnter;
+		int16 funcLeave;
+	} GCC_PACK Collision;
+
+	typedef struct TotResItem {
+		int32 offset;	// if > 0, then offset from end of resource table.
+						// If < 0, then -offset-1 is index in .IM file table
+		int16 size;
+		int16 width;
+		int16 height;
+	} GCC_PACK TotResItem;
 
 #define szGame_TotResTable (2 + 1)
-typedef struct Game_TotResTable {
-	int16 itemsCount;
-	byte unknown;
-	Game_TotResItem items[1];
-} GCC_PACK Game_TotResTable;
+	typedef struct TotResTable {
+		int16 itemsCount;
+		byte unknown;
+		TotResItem items[1];
+	} GCC_PACK TotResTable;
+
+#define szGame_ExtItem (4 + 2 + 2 + 2)
+	typedef struct ExtItem {
+		int32 offset;		// offset from the table end
+		uint16 size;
+		int16 width;		// width&0x7fff - width, width&0x8000 - pack flag
+		int16 height;		// not zero
+	} GCC_PACK ExtItem;
+
+#define szGame_ExtTable (2 + 1)
+	typedef struct ExtTable {
+		int16 itemsCount;
+		byte unknown;
+		ExtItem items[1];
+	} GCC_PACK ExtTable;
 
 #define szGame_TotTextItem (2 + 2)
-typedef struct Game_TotTextItem {
-	int16 offset;
-	int16 size;
-} GCC_PACK Game_TotTextItem;
+	typedef struct TotTextItem {
+		int16 offset;
+		int16 size;
+	} GCC_PACK TotTextItem;
 
 #define szGame_TotTextTable (2)
-typedef struct Game_TotTextTable {
-	int16 itemsCount;
-	Game_TotTextItem items[1];
-} GCC_PACK Game_TotTextTable;
-
-typedef struct Game_Collision {
-	int16 id;
-	int16 left;
-	int16 top;
-	int16 right;
-	int16 bottom;
-	int16 flags;
-	int16 key;
-	int16 funcEnter;
-	int16 funcLeave;
-} GCC_PACK Game_Collision;
+	typedef struct TotTextTable {
+		int16 itemsCount;
+		TotTextItem items[1];
+	} GCC_PACK TotTextTable;
 
-typedef struct Game_InputDesc {
-	int16 fontIndex;
-	int16 backColor;
-	int16 frontColor;
-	char *ptr;
-} GCC_PACK Game_InputDesc;
+	typedef struct InputDesc {
+		int16 fontIndex;
+		int16 backColor;
+		int16 frontColor;
+		char *ptr;
+	} GCC_PACK InputDesc;
 #pragma END_PACK_STRUCTS
 
-extern Game_Collision *game_collisionAreas;
+	TotResTable *totResourceTable;
+	Collision *collisionAreas;
+	Collision *collStack[3];
 
-extern int16 game_lastCollKey;
-extern int16 game_lastCollAreaIndex;
-extern int16 game_lastCollId;
+	TotTextTable *totTextData;
 
-extern int16 game_activeCollResId;
-extern int16 game_activeCollIndex;
-extern char game_handleMouse;
-extern char game_forceHandleMouse;
+	char curTotFile[14];
+	char curExtFile[14];
 
-extern char game_tempStr[256];
+	char *imFileData;
+	char *totFileData;
 
-extern Game_ExtTable *game_extTable;
-extern char *game_totFileData;
-extern Game_TotTextTable *game_totTextData;
-extern Game_TotResTable *game_totResourceTable;
-extern char *game_imFileData;
-extern int16 game_extHandle;
-extern char game_curExtFile[14];
-extern char game_curTotFile[14];
-extern char game_curImaFile[18];
+	int16 extHandle;
 
-extern int16 game_collStackSize;
-extern Game_Collision *game_collStack[3];
-extern int16 game_collStackElemSizes[3];
+	Snd::SoundDesc *soundSamples[20];
 
-extern int16 game_mouseButtons;
+	char totToLoad[20];
 
-extern Snd_SoundDesc *game_soundSamples[20];
+	int32 startTimeKey;
+	int16 mouseButtons;
 
-extern char game_soundFromExt[20];
-extern char game_totToLoad[20];
+	Game(GobEngine *vm);
 
-extern int32 game_startTimeKey;
-extern char game_shouldPushColls;
+	char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight);
+	char *loadTotResource(int16 id);
 
-// Functions
+	void capturePush(int16 left, int16 top, int16 width, int16 height);
 
-char *game_loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight);
-void game_clearCollisions(void);
-void game_addNewCollision(int16 val_0, int16 left, int16 top, int16 right, int16 bottom,
-    int16 flags, int16 key, int16 val_E, int16 val_10);
-void game_freeCollision(int16 id);
-char *game_loadTotResource(int16 id);
-void game_capturePush(int16 left, int16 top, int16 width, int16 height);
+	void capturePop(char doDraw);
+	void interLoadSound(int16 slot);
+	void freeSoundSlot(int16 slot);
+	int16 checkKeys(int16 *pMousex, int16 *pMouseY, int16 *pButtons,
+					char handleMouse);
+	int16 checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId,
+						  int16 *pResIndex);
+	void clearCollisions(void);
+	void addNewCollision(int16 val_0, int16 left, int16 top, int16 right, int16 bottom,
+						 int16 flags, int16 key, int16 val_E, int16 val_10);
+	void freeCollision(int16 id);
 
-void game_capturePush(int16 left, int16 top, int16 width, int16 height);
-void game_capturePop(char doDraw);
+	void loadSound(int16 slot, char *dataPtr);
+	int16 inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 backColor,
+			int16 frontColor, char *str, int16 fontIndex, char inpType, int16 *pTotTime);
+	int16 multiEdit(int16 time, int16 index, int16 *pCurPos,
+					InputDesc * inpDesc);
+	int16 adjustKey(int16 key);
+	void collisionsBlock(void);
+	void prepareStart(void);
+	void loadTotFile(char *path);
+	void loadExtTable(void);
+	void loadImFile(void);
+	void playTot(int16 skipPlay);
+	void start(void);
 
-void game_loadSound(int16 slot, char *dataPtr);
-void game_interLoadSound(int16 slot);
-void game_freeSoundSlot(int16 slot);
-int16 game_checkKeys(int16 *pMousex, int16 *pMouseY, int16 *pButtons,
-    char handleMouse);
-int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId,
-    int16 *pResIndex);
-int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 backColor,
-    int16 frontColor, char *str, int16 fontIndex, char inpType, int16 *pTotTime);
-int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos,
-    Game_InputDesc * inpDesc);
-int16 game_adjustKey(int16 key);
-void game_collisionsBlock(void);
-void game_prepareStart(void);
-void game_loadTotFile(char *path);
-void game_loadExtTable(void);
-void game_loadImFile(void);
-void game_playTot(int16 skipPlay);
-void game_start(void);
+protected:
+
+	int16 lastCollKey;
+	int16 lastCollAreaIndex;
+	int16 lastCollId;
+
+	int16 activeCollResId;
+	int16 activeCollIndex;
+	char ghandleMouse;
+	char forceHandleMouse;
+
+	char tempStr[256];
+
+	ExtTable *extTable;
+	char curImaFile[18];
+
+	int16 collStackSize;
+	int16 collStackElemSizes[3];
+
+	char soundFromExt[20];
+
+	char shouldPushColls;
+
+	// Capture
+	static Common::Rect captureStack[20];
+	static int16 captureCount;
+
+	char collStr[256];
+
+	GobEngine *_vm;
+		
+	void pushCollisions(char all);
+	void popCollisions(void);
+	int16 checkMousePoint(int16 all, int16 *resId, int16 *resIndex);
+};
 
 }				// End of namespace Gob
 

Index: global.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/global.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- global.cpp	18 Oct 2005 01:30:17 -0000	1.9
+++ global.cpp	3 Jan 2006 23:14:39 -0000	1.10
@@ -24,135 +24,130 @@
 
 namespace Gob {
 
-char pressedKeys[128];
-
-char useMouse = UNDEF;
-int16 mousePresent = UNDEF;
-
-int16 presentCGA = UNDEF;
-int16 presentEGA = UNDEF;
-int16 presentVGA = UNDEF;
-int16 presentHER = UNDEF;
-
-int16 videoMode = 0;
-
-int16 disableVideoCfg;
-
-/* Sound */
-uint16 presentSound = 0x8000;	/* undefined values */
-uint16 soundFlags = 0x8000;
-int16 blasterPort = 0;
-int16 disableSoundCfg = 0;
-
-//char playingSound = 0;
+Global::Global(GobEngine *vm) : _vm(vm) {
+	useMouse = UNDEF;
+	mousePresent = UNDEF;
 
-/* Mouse */
-int16 disableMouseCfg = 0;
+	presentCGA = UNDEF;
+	presentEGA = UNDEF;
+	presentVGA = UNDEF;
+	presentHER = UNDEF;
 
-int16 mouseXShift = 3;
-int16 mouseYShift = 3;
+	videoMode = 0;
 
-int16 mouseMaxCol = 320;
-int16 mouseMaxRow = 200;
+	/* Sound */
+	presentSound = 0x8000;	/* undefined values */
+	soundFlags = 0x8000;
+	blasterPort = 0;
+	disableSoundCfg = 0;
 
-/* Language */
-uint16 disableLangCfg = 0x8000;
-uint16 language = 0x8000;
+	//char playingSound = 0;
 
-/* Timer variables */
-int32 startTime = 0;
-int16 timer_delta = 1000;
+	/* Mouse */
+	disableMouseCfg = 0;
 
-int16 frameWaitTime = 0;
-int32 startFrameTime = 0;
+	mouseXShift = 3;
+	mouseYShift = 3;
 
-/* Timer and delays */
-int16 delayTime = 0;
+	mouseMaxCol = 320;
+	mouseMaxRow = 200;
 
-/* Joystick */
-char useJoystick = 1;
+	/* Language */
+	disableLangCfg = 0x8000;
+	language = 0x8000;
 
-/* Files */
-Common::File filesHandles[MAX_FILES];
+	/* Timer variables */
+	startTime = 0;
+	timer_delta = 1000;
 
-/* Data files */
-struct ChunkDesc *dataFiles[MAX_DATA_FILES];
-int16 numDataChunks[MAX_DATA_FILES];
-int16 dataFileHandles[MAX_DATA_FILES];
-int32 chunkPos[MAX_SLOT_COUNT * MAX_DATA_FILES];
-int32 chunkOffset[MAX_SLOT_COUNT * MAX_DATA_FILES];
-int32 chunkSize[MAX_SLOT_COUNT * MAX_DATA_FILES];
-char isCurrentSlot[MAX_SLOT_COUNT * MAX_DATA_FILES];
-int32 packedSize = 0;
+	frameWaitTime = 0;
+	startFrameTime = 0;
 
-int16 sprAllocated = 0;
+	/* Timer and delays */
+	delayTime = 0;
 
-SurfaceDesc primarySurfDesc;
-SurfaceDesc *pPrimarySurfDesc;
+	/* Joystick */
+	useJoystick = 1;
 
-int16 primaryWidth;
-int16 primaryHeight;
+	/* Data files */
+	packedSize = 0;
+	for (int i = 0; i < MAX_DATA_FILES; i++) {
+		dataFiles[i] = 0;
+		numDataChunks[i] = 0;
+		dataFileHandles[i] = -1;
+	}
 
-int16 doRangeClamp = 0;
+	primaryWidth = 0;
+	primaryHeight = 0;
 
-char redPalette[256];
-char greenPalette[256];
-char bluePalette[256];
+	sprAllocated = 0;
 
-int16 setAllPalette = 0;
+	doRangeClamp = 0;
 
-int16 oldMode = 3;
-char dontSetPalette = 0;
-SurfaceDesc *curPrimaryDesc = 0;
-SurfaceDesc *allocatedPrimary = 0;
+	setAllPalette = 0;
 
-PalDesc *pPaletteDesc = 0;
+	oldMode = 3;
+	dontSetPalette = 0;
+	curPrimaryDesc = 0;
+	allocatedPrimary = 0;
+	pPrimarySurfDesc = 0;
 
-int16 unusedPalette1[18] = {
-	0, 0x0b, 0, (int16)0x5555, (int16)0xAAAA, (int16)0xFFFF, 0, (int16)0x5555,
-	(int16)0xAAAA, (int16)0xFFFF, 0, (int16)0x5555,
-	(int16)0xAAAA, (int16)0xFFFF, 0, (int16)0x5555, (int16)0xAAAA, (int16)0xFFFF
-};
+	pPaletteDesc = 0;
 
-int16 unusedPalette2[] = {
-	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
-};
+	unusedPalette1[0] = (int16)0;
+	unusedPalette1[1] = (int16)0x0b;
+	unusedPalette1[2] = (int16)0;
+	unusedPalette1[3] = (int16)0x5555;
+	unusedPalette1[4] = (int16)0xAAAA;
+	unusedPalette1[5] = (int16)0xFFFF;
+	unusedPalette1[6] = (int16)0;
+	unusedPalette1[7] = (int16)0x5555;
+	unusedPalette1[8] = (int16)0xAAAA;
+	unusedPalette1[9] = (int16)0xFFFF;
+	unusedPalette1[10] = (int16)0;
+	unusedPalette1[11] = (int16)0x5555;
+	unusedPalette1[12] = (int16)0xAAAA;
+	unusedPalette1[13] = (int16)0xFFFF;
+	unusedPalette1[14] = (int16)0;
+	unusedPalette1[15] = (int16)0x5555;
+	unusedPalette1[16] = (int16)0xAAAA;
+	unusedPalette1[17] = (int16)0xFFFF;
 
-Color vgaPalette[16] = {
-	{0x00, 0x00, 0x00},
-	{0x00, 0x00, 0x2a},
-	{0x00, 0x2a, 0x00},
-	{0x00, 0x2a, 0x2a},
-	{0x2a, 0x00, 0x00},
-	{0x2a, 0x00, 0x2a},
-	{0x2a, 0x15, 0x00},
-	{0x2a, 0x2a, 0x2a},
-	{0x15, 0x15, 0x15},
-	{0x15, 0x15, 0x3f},
-	{0x15, 0x3f, 0x15},
-	{0x15, 0x3f, 0x3f},
-	{0x3f, 0x15, 0x15},
-	{0x3f, 0x15, 0x3f},
-	{0x3f, 0x3f, 0x15},
-	{0x3f, 0x3f, 0x3f}
-};
+	for (int i = 0; i < 16 ;i++)
+		unusedPalette2[i] = i;
 
-PalDesc paletteStruct;
+	vgaPalette[0].red = 0x00; vgaPalette[0].green = 0x00; vgaPalette[0].blue = 0x00;
+	vgaPalette[1].red = 0x00; vgaPalette[1].green = 0x00; vgaPalette[1].blue = 0x2a;
+	vgaPalette[2].red = 0x00; vgaPalette[2].green = 0x2a; vgaPalette[2].blue = 0x00;
+	vgaPalette[3].red = 0x00; vgaPalette[3].green = 0x2a; vgaPalette[3].blue = 0x2a;
+	vgaPalette[4].red = 0x2a; vgaPalette[4].green = 0x00; vgaPalette[4].blue = 0x00;
+	vgaPalette[5].red = 0x2a; vgaPalette[5].green = 0x00; vgaPalette[5].blue = 0x2a;
+	vgaPalette[6].red = 0x2a; vgaPalette[6].green = 0x15; vgaPalette[6].blue = 0x00;
+	vgaPalette[7].red = 0x2a; vgaPalette[7].green = 0x2a; vgaPalette[7].blue = 0x2a;
+	vgaPalette[8].red = 0x15; vgaPalette[8].green = 0x15; vgaPalette[8].blue = 0x15;
+	vgaPalette[9].red = 0x15; vgaPalette[9].green = 0x15; vgaPalette[9].blue = 0x3f;
+	vgaPalette[10].red = 0x15; vgaPalette[10].green = 0x3f; vgaPalette[10].blue = 0x15;
+	vgaPalette[11].red = 0x15; vgaPalette[11].green = 0x3f; vgaPalette[11].blue = 0x3f;
+	vgaPalette[12].red = 0x3f; vgaPalette[12].green = 0x15; vgaPalette[12].blue = 0x15;
+	vgaPalette[13].red = 0x3f; vgaPalette[13].green = 0x15; vgaPalette[13].blue = 0x3f;
+	vgaPalette[14].red = 0x3f; vgaPalette[14].green = 0x3f; vgaPalette[14].blue = 0x15;
+	vgaPalette[15].red = 0x3f; vgaPalette[15].green = 0x3f; vgaPalette[15].blue = 0x3f;
 
-int16 debugFlag = 0;
-int16 inVM = 0;
-int16 colorCount = 16;
+	debugFlag = 0;
+	inVM = 0;
+	colorCount = 16;
 
-char inter_resStr[200];
-int32 inter_resVal = 0;
+	inter_resStr[0] = 0;
+	inter_resVal = 0;
 
-char *inter_variables = 0;
-char *inter_execPtr = 0;
-int16 inter_animDataSize = 10;
+	inter_variables = 0;
+	inter_execPtr = 0;
+	inter_animDataSize = 10;
 
-int16 inter_mouseX = 0;
-int16 inter_mouseY = 0;
+	inter_mouseX = 0;
+	inter_mouseY = 0;
 
-char *tmpPalBuffer = 0;
+	tmpPalBuffer = 0;
+}
 
 } // End of namespace Gob

Index: global.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/global.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- global.h	18 Oct 2005 01:30:17 -0000	1.8
+++ global.h	3 Jan 2006 23:14:39 -0000	1.9
@@ -29,29 +29,11 @@
 
 namespace Gob {
 
-extern char pressedKeys[128];
-
-extern char useMouse;
-extern int16 mousePresent;
-
-extern int16 presentCGA;
-extern int16 presentEGA;
-extern int16 presentVGA;
-extern int16 presentHER;
-
-extern int16 videoMode;
-
-extern int16 disableVideoCfg;
-
 #define VIDMODE_CGA	0x05
 #define VIDMODE_EGA	0x0d
 #define VIDMODE_VGA	0x13
 #define VIDMODE_HER	7
 
-extern uint16 presentSound;
-extern uint16 soundFlags;
-extern int16 disableSoundCfg;
-
 #define PROAUDIO_FLAG	0x10
 #define ADLIB_FLAG		0x08
 #define BLASTER_FLAG	0x04
@@ -59,9 +41,6 @@
 #define SPEAKER_FLAG	0x01
 #define MIDI_FLAG		0x4000
 
-extern uint16 disableLangCfg;
-extern uint16 language;
-
 #define NO	0
 #define YES	1
 #define UNDEF	2
@@ -75,92 +54,122 @@
 #define ESCAPE	0x001b
 #define ENTER	0x000d
 
-/* Timer variables */
-extern int32 startTime;
-extern int16 timer_delta;
+#define MAX_FILES	30
 
-extern int16 frameWaitTime;
-extern int32 startFrameTime;
+/* Video drivers */
+#define UNK_DRIVER	0
+#define VGA_DRIVER	1
+#define EGA_DRIVER	2
+#define CGA_DRIVER	3
+#define HER_DRIVER	4
 
-/* Mouse */
-extern int16 disableMouseCfg;
+class Global {
+public:
+	char pressedKeys[128];
 
-extern int16 mouseXShift;
-extern int16 mouseYShift;
-extern int16 mouseMaxCol;
-extern int16 mouseMaxRow;
+	char useMouse;
+	int16 mousePresent;
 
-/* Timer and delays */
-extern int16 delayTime;
+	int16 presentCGA;
+	int16 presentEGA;
+	int16 presentVGA;
+	int16 presentHER;
 
-/* Joystick */
-extern char useJoystick;
+	int16 videoMode;
 
-/* Files */
-#define MAX_FILES	30
+	int16 disableVideoCfg;
 
-extern Common::File filesHandles[MAX_FILES];
+	uint16 presentSound;
+	uint16 soundFlags;
+	int16 disableSoundCfg;
+	int16 blasterPort;
 
-/* Data files */
-extern struct ChunkDesc *dataFiles[MAX_DATA_FILES];
-extern int16 numDataChunks[MAX_DATA_FILES];
-extern int16 dataFileHandles[MAX_DATA_FILES];
-extern int32 chunkPos[MAX_SLOT_COUNT * MAX_DATA_FILES];
-extern int32 chunkOffset[MAX_SLOT_COUNT * MAX_DATA_FILES];
-extern int32 chunkSize[MAX_SLOT_COUNT * MAX_DATA_FILES];
-extern char isCurrentSlot[MAX_SLOT_COUNT * MAX_DATA_FILES];
-extern int32 packedSize;
+	uint16 disableLangCfg;
+	uint16 language;
 
-/* Video drivers */
-#define UNK_DRIVER	0
-#define VGA_DRIVER	1
-#define EGA_DRIVER	2
-#define CGA_DRIVER	3
-#define HER_DRIVER	4
+	// Timer variables
+	int32 startTime;
+	int16 timer_delta;
 
-extern SurfaceDesc primarySurfDesc;
-extern SurfaceDesc *pPrimarySurfDesc;
-extern int16 sprAllocated;
+	int16 frameWaitTime;
+	int32 startFrameTime;
 
-extern int16 primaryWidth;
-extern int16 primaryHeight;
+	// Mouse
+	int16 disableMouseCfg;
 
-extern int16 doRangeClamp;
+	int16 mouseXShift;
+	int16 mouseYShift;
+	int16 mouseMaxCol;
+	int16 mouseMaxRow;
 
-extern char redPalette[256];
-extern char greenPalette[256];
-extern char bluePalette[256];
+	// Timer and delays
+	int16 delayTime;
 
-extern int16 setAllPalette;
+	// Joystick
+	char useJoystick;
 
-extern SurfaceDesc *curPrimaryDesc;
-extern SurfaceDesc *allocatedPrimary;
+	// Files
+	Common::File filesHandles[MAX_FILES];
 
-extern int16 oldMode;
-extern char dontSetPalette;
+	// Data files
+	struct DataIO::ChunkDesc *dataFiles[MAX_DATA_FILES];
+	int16 numDataChunks[MAX_DATA_FILES];
+	int16 dataFileHandles[MAX_DATA_FILES];
+	int32 chunkPos[MAX_SLOT_COUNT * MAX_DATA_FILES];
+	int32 chunkOffset[MAX_SLOT_COUNT * MAX_DATA_FILES];
+	int32 chunkSize[MAX_SLOT_COUNT * MAX_DATA_FILES];
+	char isCurrentSlot[MAX_SLOT_COUNT * MAX_DATA_FILES];
+	int32 packedSize;
 
-extern PalDesc *pPaletteDesc;
+	int16 sprAllocated;
 
-extern int16 unusedPalette1[18];
-extern int16 unusedPalette2[16];
-extern Color vgaPalette[16];
-extern PalDesc paletteStruct;
+	int16 primaryWidth;
+	int16 primaryHeight;
 
-extern int16 debugFlag;
-extern int16 inVM;
-extern int16 colorCount;
+	int16 doRangeClamp;
 
-extern char inter_resStr[200];
-extern int32 inter_resVal;
+	char redPalette[256];
+	char greenPalette[256];
+	char bluePalette[256];
 
-extern char *inter_variables;
-extern char *inter_execPtr;
-extern int16 inter_animDataSize;
+	int16 setAllPalette;
 
-extern int16 inter_mouseX;
-extern int16 inter_mouseY;
+	Video::SurfaceDesc *curPrimaryDesc;
+	Video::SurfaceDesc *allocatedPrimary;
+	Video::SurfaceDesc_t primarySurfDesc;
+	Video::SurfaceDesc *pPrimarySurfDesc;
 
-extern char *tmpPalBuffer;
+	int16 oldMode;
+	char dontSetPalette;
+
+	Video::PalDesc *pPaletteDesc;
+
+	int16 unusedPalette1[18];
+	int16 unusedPalette2[16];
+	Video::Color vgaPalette[16];
+	Video::PalDesc paletteStruct;
+
+	int16 debugFlag;
+	int16 inVM;
+	int16 colorCount;
+
+	char inter_resStr[200];
+	int32 inter_resVal;
+
+	char *inter_variables;
+	char *inter_execPtr;
+	int16 inter_animDataSize;
+
+	int16 inter_mouseX;
+	int16 inter_mouseY;
+
+	char *tmpPalBuffer;
+
+	Global(GobEngine *vm);
+
+protected:
+	GobEngine *_vm;
+};
 
 } // End of namespace Gob
 

Index: gob.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/gob.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- gob.cpp	1 Nov 2005 11:18:50 -0000	1.27
+++ gob.cpp	3 Jan 2006 23:14:39 -0000	1.28
@@ -31,6 +31,19 @@
 #include "gob/game.h"
 #include "gob/sound.h"
 #include "gob/init.h"
+#include "gob/inter.h"
+#include "gob/draw.h"
+#include "gob/anim.h"
+#include "gob/cdrom.h"
+#include "gob/goblin.h"
+#include "gob/map.h"
+#include "gob/mult.h"
+#include "gob/pack.h"
+#include "gob/palanim.h"
+#include "gob/parse.h"
+#include "gob/scenery.h"
+#include "gob/timer.h"
+#include "gob/util.h"
 
 enum {
 	// We only compute MD5 of the first megabyte of our data files.
@@ -50,53 +63,53 @@
 
 static const GobGameSettings gob_games[] = {
 	// Supplied by Florian Zeitz on scummvm-devel
-	{"gob1", "Gobliiins (DOS EGA)", GF_GOB1, "82aea70ef26f41fa963dfae270993e49"},
-	{"gob1", "Gobliiins (DOS EGA)", GF_GOB1, "1f499458837008058b8ba6ae07057214"},
-	{"gob1", "Gobliiins (Windows)", GF_GOB1, "8a5e850c49d7cacdba5f5eb1fcc77b89"},
+	{"gob1", "Gobliiins (DOS EGA)", Gob::GF_GOB1, "82aea70ef26f41fa963dfae270993e49"},
+	{"gob1", "Gobliiins (DOS EGA)", Gob::GF_GOB1, "1f499458837008058b8ba6ae07057214"},
+	{"gob1", "Gobliiins (Windows)", Gob::GF_GOB1, "8a5e850c49d7cacdba5f5eb1fcc77b89"},
 
 	// Supplied by Theruler76 in bug report #1201233
-	{"gob1", "Gobliiins (DOS VGA)", GF_GOB1, "a5e232fcd02733c7dffff107d22d36eb"},
+	{"gob1", "Gobliiins (DOS VGA)", Gob::GF_GOB1, "a5e232fcd02733c7dffff107d22d36eb"},
 
 	// CD 1.000 version. Multilingual
-	{"gob1", "Gobliiins (CD)", GF_GOB1 | GF_CD, "037db48ebce94bdfe42e2c9510da9211"},
+	{"gob1", "Gobliiins (CD)", Gob::GF_GOB1 | Gob::GF_CD, "037db48ebce94bdfe42e2c9510da9211"},
 	// CD 1.02 version. Multilingual
-	{"gob1", "Gobliiins (CD)", GF_GOB1 | GF_CD, "45f9c1162dd7040fd05fd013ccc176e2"},
+	{"gob1", "Gobliiins (CD)", Gob::GF_GOB1 | Gob::GF_CD, "45f9c1162dd7040fd05fd013ccc176e2"},
 
-	{"gob1", "Gobliiins (Amiga)", GF_GOB1, "d9f8736b7dc0ea891cd06592a72e8a72"},
-	{"gob1", "Gobliiins (Amiga)", GF_GOB1, "69f9ae85252271e7dfa62883e581e5e9"},
-	{"gob1", "Gobliiins (Amiga)", GF_GOB1, "26de406cb09228d902274446a6a2eceb"},
-	{"gob1", "Gobliiins (Amiga)", GF_GOB1, "baf88a95928edb3f51067983f2dffa93"},
+	{"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "d9f8736b7dc0ea891cd06592a72e8a72"},
+	{"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "69f9ae85252271e7dfa62883e581e5e9"},
+	{"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "26de406cb09228d902274446a6a2eceb"},
+	{"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "baf88a95928edb3f51067983f2dffa93"},
 
-	{"gob1", "Gobliiins (Interactive Demo)", GF_GOB1, "4f5bf4b9e4c39ebb93579747fc678e97"},
+	{"gob1", "Gobliiins (Interactive Demo)", Gob::GF_GOB1, "4f5bf4b9e4c39ebb93579747fc678e97"},
 
 #if 0
-	{"gob2", "Gobliins 2 (DOS)", GF_GOB2, "abb5f762f9979d4253002de20f6e7b56"},
-	{"gob2", "Gobliins 2 (DOS)", GF_GOB2, "9b6de65d811c08eebf50391b84fcba92"},
-	{"gob2", "Gobliins 2 (DOS)", GF_GOB2, "54d59c200e3823ad0af11a605a6fd06a"},
-	{"gob2", "Gobliins 2 (DOS Ru)", GF_GOB2, "b6d47494bf88398ae59c1b5656cafce4"},
+	{"gob2", "Gobliins 2 (DOS)", Gob::GF_GOB2, "abb5f762f9979d4253002de20f6e7b56"},
+	{"gob2", "Gobliins 2 (DOS)", Gob::GF_GOB2, "9b6de65d811c08eebf50391b84fcba92"},
+	{"gob2", "Gobliins 2 (DOS)", Gob::GF_GOB2, "54d59c200e3823ad0af11a605a6fd06a"},
+	{"gob2", "Gobliins 2 (DOS Ru)", Gob::GF_GOB2, "b6d47494bf88398ae59c1b5656cafce4"},
 	// CD 1.000.
-	{"gob2", "Gobliins 2 (CD)", GF_GOB2, "02bf538fd8003b8da23a3546299c3df4"},
+	{"gob2", "Gobliins 2 (CD)", Gob::GF_GOB2, "02bf538fd8003b8da23a3546299c3df4"},
 	// CD 1.01
-	{"gob2", "Gobliins 2 (CD)", GF_GOB2, "410e632682ab11969bc3b3b588066d95"},
-	{"gob2", "Gobliins 2 (Demo)", GF_GOB2, "be8b111191f965ac9b28fe530580d14e"},
+	{"gob2", "Gobliins 2 (CD)", Gob::GF_GOB2, "410e632682ab11969bc3b3b588066d95"},
+	{"gob2", "Gobliins 2 (Demo)", Gob::GF_GOB2, "be8b111191f965ac9b28fe530580d14e"},
 
-	{"gob3", "Goblins Quest 3", GF_GOB3, "36d9b4032b39a794c8640e500e98893a"},
-	{"gob3", "Goblins Quest 3", GF_GOB3, "d129f639f6ca8d6b5f0f4e15edb91058"},
-	{"gob3", "Goblins Quest 3", GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"},
+	{"gob3", "Goblins Quest 3", Gob::GF_GOB3, "36d9b4032b39a794c8640e500e98893a"},
+	{"gob3", "Goblins Quest 3", Gob::GF_GOB3, "d129f639f6ca8d6b5f0f4e15edb91058"},
+	{"gob3", "Goblins Quest 3", Gob::GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"},
 	// CD 1.000
-	{"gob3", "Goblins Quest 3 (CD)", GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"},
+	{"gob3", "Goblins Quest 3 (CD)", Gob::GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"},
 	// CD 1.02. Spanish "Computer Gaming World"* distribution in Spain
-	{"gob3", "Goblins Quest 3 (CD)", GF_GOB3, "7d7ab9a987be7208b9b685846fbd3e82"},
+	{"gob3", "Goblins Quest 3 (CD)", Gob::GF_GOB3, "7d7ab9a987be7208b9b685846fbd3e82"},
 
-	{"gob3", "Goblins Quest 3 (Interactive Demo)", GF_GOB3, "4986b44cec309589508d7904f924c217"},
-	{"gob3", "Goblins Quest 3 (Demo)", GF_GOB3, "5024e7de8d6377fbbeabbaa92e0452bc"},
-	{"gob3", "Goblins Quest 3 (Interactive Demo)", GF_GOB3, "59ab69dab5fddbbf698c77a84297a5a2"},
+	{"gob3", "Goblins Quest 3 (Interactive Demo)", Gob::GF_GOB3, "4986b44cec309589508d7904f924c217"},
+	{"gob3", "Goblins Quest 3 (Demo)", Gob::GF_GOB3, "5024e7de8d6377fbbeabbaa92e0452bc"},
+	{"gob3", "Goblins Quest 3 (Interactive Demo)", Gob::GF_GOB3, "59ab69dab5fddbbf698c77a84297a5a2"},
 
 	// CD 1.0
-	{"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", GF_WOODRUFF, "c27402cee260d2ff1c4cecb2006a630a"},
+	{"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", Gob::GF_WOODRUFF, "c27402cee260d2ff1c4cecb2006a630a"},
 
 	// CD 1.00, German release (INTRO.STRK seems to be multilingual, though?)
-	{"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", GF_WOODRUFF, "751ba028d215e0db1e0254853de6a7e4"},
+	{"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", Gob::GF_WOODRUFF, "751ba028d215e0db1e0254853de6a7e4"},
 #endif
 	{0, 0, 0, 0}
 };
@@ -111,8 +124,8 @@
 		return dummy;
 	}
 } gob_list[] = {
-	{"gob1", "Gobliiins", GF_GOB1},
-	{"gob2", "Gobliins 2", GF_GOB2},
+	{"gob1", "Gobliiins", Gob::GF_GOB1},
+	{"gob2", "Gobliins 2", Gob::GF_GOB2},
 	{0, 0, 0}
 };
 
@@ -183,7 +196,6 @@
 GobEngine *_vm = NULL;
 
 GobEngine::GobEngine(GameDetector *detector, OSystem * syst) : Engine(syst) {
-
 	// Setup mixer
 	if (!_mixer->isReady()) {
 		warning("Sound initialization failed.");
@@ -232,6 +244,25 @@
 }
 
 GobEngine::~GobEngine() {
+	delete _game;
+	delete _snd;
+	delete _video;
+	delete _global;
+	delete _draw;
+	delete _anim;
+	delete _cdrom;
+	delete _dataio;
+	delete _goblin;
+	delete _init;
+	delete _inter;
+	delete _map;
+	delete _mult;
+	delete _pack;
+	delete _palanim;
+	delete _parse;
+	delete _scenery;
+	delete _gtimer;
+	delete _util;
 }
 
 void GobEngine::errorString(const char *buf1, char *buf2) {
@@ -239,6 +270,26 @@
 }
 
 int GobEngine::init(GameDetector &detector) {
+	_game = new Game(this);
+	_snd = new Snd(this);
+	_video = new Video(this);
+	_global = new Global(this);
+	_draw = new Draw(this);
+	_anim = new Anim();
+	_cdrom = new CDROM(this);
+	_dataio = new DataIO(this);
+	_goblin = new Goblin(this);
+	_init = new Init(this);
+	_inter = new Inter(this);
+	_map = new Map(this);
+	_mult = new Mult(this);
+	_pack = new Pack();
+	_palanim = new PalAnim(this);
+	_parse = new Parse(this);
+	_scenery = new Scenery(this);
+	_gtimer = new GTimer();
+	_util = new Util(this);
+
 	_system->beginGFXTransaction();
 		initCommonGFX(detector);
 		_system->initSize(320, 200);
@@ -252,30 +303,30 @@
 	if (cd_num >= 0)
 		_system->openCD(cd_num);
 
-	debugFlag = 1;
-	doRangeClamp = 1;
+	_global->debugFlag = 1;
+	_global->doRangeClamp = 1;
 
-	videoMode = 0x13;
-	snd_soundPort = 1;
-	useMouse = 1;
-	soundFlags = 0;
+	_global->videoMode = 0x13;
+	_snd->soundPort = 1;
+	_global->useMouse = 1;
+	_global->soundFlags = 0;
 
 	switch (Common::parseLanguage(ConfMan.get("language"))) {
 	case Common::FR_FRA:
-		language = 0;
+		_global->language = 0;
 		break;
 	case Common::DE_DEU:
-		language = 1;
+		_global->language = 1;
 		break;
 	case Common::ES_ESP:
-		language = 3;
+		_global->language = 3;
 		break;
 	case Common::IT_ITA:
-		language = 4;
+		_global->language = 4;
 		break;
 	default:
 		// Default to English
-		language = 2;
+		_global->language = 2;
 		break;
 	}
 
@@ -289,7 +340,7 @@
 }
 
 int GobEngine::go() {
-	init_initGame(0);
+	_init->initGame(0);
 
 	return 0;
 }

Index: gob.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/gob.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- gob.h	1 Nov 2005 11:18:50 -0000	1.11
+++ gob.h	3 Jan 2006 23:14:39 -0000	1.12
@@ -29,15 +29,39 @@
 
 #include "base/engine.h"
 
-#define	VAR_OFFSET(offs)		(*(uint32 *)(inter_variables + (offs)))
+#include "gob/dataio.h"
+#include "gob/video.h"
+#include "common/file.h"
+
+namespace Gob {
+
+class Game;
+class Snd;
+class Video;
+class Global;
+class Draw;
+class Anim;
+class CDROM;
+class DataIO;
+class Goblin;
+class Init;
+class Inter;
+class Map;
+class Mult;
+class Pack;
+class PalAnim;
+class Parse;
+class Scenery;
+class GTimer;
+class Util;
+
+#define	VAR_OFFSET(offs)		(*(uint32 *)(_vm->_global->inter_variables + (offs)))
 #define	VAR(var)			VAR_OFFSET((var) << 2)
 #define VAR_ADDRESS(var)		(&VAR(var))
 
 #define	WRITE_VAR_OFFSET(offs, val)	(VAR_OFFSET(offs) = (val))
 #define WRITE_VAR(var, val)		WRITE_VAR_OFFSET((var) << 2, (val))
 
-// TODO: Should be in the Gob namespace, I guess
-
 enum {
 	GF_GOB1 = 1 << 0,
 	GF_GOB2 = 1 << 1,
@@ -46,8 +70,6 @@
 	GF_CD = 1 << 4
 };
 
-namespace Gob {
-
 class GobEngine : public Engine {
 	void errorString(const char *buf_input, char *buf_output);
 
@@ -64,6 +86,25 @@
 	Common::RandomSource _rnd;
 
 	int32 _features;
+	Game *_game;
+	Snd *_snd;
+	Video *_video;
+	Global *_global;
+	Draw *_draw;
+	Anim *_anim;
+	CDROM *_cdrom;
+	DataIO *_dataio;
+	Goblin *_goblin;
+	Init *_init;
+	Inter *_inter;
+	Map *_map;
+	Mult *_mult;
+	Pack *_pack;
+	PalAnim *_palanim;
+	Parse *_parse;
+	Scenery *_scenery;
+	GTimer *_gtimer;
+	Util *_util;
 };
 
 extern GobEngine *_vm;

Index: goblin.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/goblin.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- goblin.cpp	30 Dec 2005 18:39:01 -0000	1.24
+++ goblin.cpp	3 Jan 2006 23:14:39 -0000	1.25
@@ -35,125 +35,137 @@
 
 namespace Gob {
 
-Util_List *gob_objList;
-Gob_Object *gob_goblins[4];
-int16 gob_currentGoblin;
-Snd_SoundDesc *gob_soundData[16];
-int16 gob_gobStateLayer;
-char gob_goesAtTarget = 0;
-char gob_readyToAct = 0;
-int16 gob_gobAction = 0;
[...4215 lines suppressed...]
-		gob_itemIndInPocket = -1;
-		gob_itemIdInPocket = -1;
-		util_beep(50);
+		itemIndInPocket = -1;
+		itemIdInPocket = -1;
+		_vm->_util->beep(50);
 		break;
 
 	default:
-		warning("gob_interFunc: Unknown command %d!", cmd);
-		inter_execPtr -= 2;
-		cmd = inter_load16();
-		inter_execPtr += cmd * 2;
+		warning("interFunc: Unknown command %d!", cmd);
+		_vm->_global->inter_execPtr -= 2;
+		cmd = _vm->_inter->load16();
+		_vm->_global->inter_execPtr += cmd * 2;
 		break;
 	}
 	return;

Index: goblin.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/goblin.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- goblin.h	18 Oct 2005 01:30:17 -0000	1.6
+++ goblin.h	3 Jan 2006 23:14:39 -0000	1.7
@@ -31,175 +31,201 @@
 #define TYPE_AMORPHOUS	1
 #define TYPE_MOBILE		3
 
+class Goblin {
+public:
 #pragma START_PACK_STRUCTS
-typedef struct Gob_State {
-	int16 animation;// +0h
-	int16 layer;	// +2h
-	int16 unk0;		// +4h
-	int16 unk1;		// +6h
-	int16 sndItem;	// +8h, high/low byte - sound sample index
-	int16 freq;		// +Ah, high/low byte * 100 - frequency
-	int16 repCount;	// +Ch high/low byte - repeat count
-	int16 sndFrame;		// +Eh
-} GCC_PACK Gob_State;
+	typedef struct Gob_State {
+		int16 animation;// +0h
+		int16 layer;	// +2h
+		int16 unk0;		// +4h
+		int16 unk1;		// +6h
+		int16 sndItem;	// +8h, high/low byte - sound sample index
+		int16 freq;		// +Ah, high/low byte * 100 - frequency
+		int16 repCount;	// +Ch high/low byte - repeat count
+		int16 sndFrame;		// +Eh
+	} GCC_PACK Gob_State;
 
-typedef struct Gob_State *Gob_PState;
+	typedef Gob_State *Gob_PState;
 
 #define szGob_StateLine 24
-typedef Gob_PState Gob_StateLine[6];
+	typedef Gob_PState Gob_StateLine[6];
 
-typedef struct Gob_Object {
-	int16 animation;	// +0h
-	int16 state;		// +2h
-	int16 stateColumn;	// +4h
-	int16 curFrame;		// +6h
-	int16 xPos;			// +8h
-	int16 yPos;			// +Ah
-	int16 dirtyLeft;	// +Ch
-	int16 dirtyTop;		// +Eh
-	int16 dirtyRight;	// +10h
-	int16 dirtyBottom;	// +12h
-	int16 left;			// +14h
-	int16 top;			// +16h
-	int16 right;		// +18h
-	int16 bottom;		// +1ah
-	int16 nextState;	// +1ch
-	int16 multState;	// +1eh
-	int16 actionStartState;	// +20h
-	int16 curLookDir;	// +22h
-	int16 pickable;		// +24h
-	int16 relaxTime;	// +26h
-	Gob_StateLine *stateMach;	// +28h
-	Gob_StateLine *realStateMach;	// +2ch
-	char doAnim;		// +30h
-	char order;			// +31h
-	char noTick;		// +32h
-	char toRedraw;		// +33h
-	char type;			// +34h
-	char maxTick;		// +35h
-	char tick;			// +36h
-	char multObjIndex;	// +37h, from which play mult animations
-	char unk14;			// +38h
-	char visible;		// +39h
-} GCC_PACK Gob_Object;
+	typedef struct Gob_Object {
+		int16 animation;	// +0h
+		int16 state;		// +2h
+		int16 stateColumn;	// +4h
+		int16 curFrame;		// +6h
+		int16 xPos;			// +8h
+		int16 yPos;			// +Ah
+		int16 dirtyLeft;	// +Ch
+		int16 dirtyTop;		// +Eh
+		int16 dirtyRight;	// +10h
+		int16 dirtyBottom;	// +12h
+		int16 left;			// +14h
+		int16 top;			// +16h
+		int16 right;		// +18h
+		int16 bottom;		// +1ah
+		int16 nextState;	// +1ch
+		int16 multState;	// +1eh
+		int16 actionStartState;	// +20h
+		int16 curLookDir;	// +22h
+		int16 pickable;		// +24h
+		int16 relaxTime;	// +26h
+		Gob_StateLine *stateMach;	// +28h
+		Gob_StateLine *realStateMach;	// +2ch
+		char doAnim;		// +30h
+		char order;			// +31h
+		char noTick;		// +32h
+		char toRedraw;		// +33h
+		char type;			// +34h
+		char maxTick;		// +35h
+		char tick;			// +36h
+		char multObjIndex;	// +37h, from which play mult animations
+		char unk14;			// +38h
+		char visible;		// +39h
+	} GCC_PACK Gob_Object;
 
-typedef struct Gob_Pos {
-	char x;
-	char y;
-} GCC_PACK Gob_Pos;
+	typedef struct Gob_Pos {
+		char x;
+		char y;
+	} GCC_PACK Gob_Pos;
 #pragma END_PACK_STRUCTS
 
-extern Util_List *gob_objList;
-extern Gob_Object *gob_goblins[4];
-extern int16 gob_currentGoblin;
-extern Snd_SoundDesc *gob_soundData[16];
-extern int16 gob_gobStateLayer;
-extern char gob_goesAtTarget;
-extern char gob_readyToAct;
-extern int16 gob_gobAction;	// 0 - move, 3 - do action, 4 - pick
-						  // goblins  0 - picker, 1 - fighter, 2 - mage
-extern Gob_Pos gob_gobPositions[3];
-extern int16 gob_gobDestX;
-extern int16 gob_gobDestY;
-extern int16 gob_pressedMapX;
-extern int16 gob_pressedMapY;
-extern char gob_pathExistence;
+	Util::List *objList;
+	Gob_Object *goblins[4];
+	int16 currentGoblin;
+	Snd::SoundDesc *soundData[16];
+	int16 gobStateLayer;
+	char goesAtTarget;
+	char readyToAct;
+	int16 gobAction;	// 0 - move, 3 - do action, 4 - pick
+						// goblins  0 - picker, 1 - fighter, 2 - mage
+	Gob_Pos gobPositions[3];
+	int16 gobDestX;
+	int16 gobDestY;
+	int16 pressedMapX;
+	int16 pressedMapY;
+	char pathExistence;
 
-// Pointers to interpreter variables
-extern int32 *gob_some0ValPtr;
+	// Pointers to interpreter variables
+	int32 *some0ValPtr;
 
-extern int32 *gob_gobRetVarPtr;
-extern int32 *gob_curGobVarPtr;
-extern int32 *gob_curGobXPosVarPtr;
-extern int32 *gob_curGobYPosVarPtr;
-extern int32 *gob_itemInPocketVarPtr;
+	int32 *gobRetVarPtr;
+	int32 *curGobVarPtr;
+	int32 *curGobXPosVarPtr;
+	int32 *curGobYPosVarPtr;
+	int32 *itemInPocketVarPtr;
 
-extern int32 *gob_curGobStateVarPtr;
-extern int32 *gob_curGobFrameVarPtr;
-extern int32 *gob_curGobMultStateVarPtr;
-extern int32 *gob_curGobNextStateVarPtr;
-extern int32 *gob_curGobScrXVarPtr;
-extern int32 *gob_curGobScrYVarPtr;
-extern int32 *gob_curGobLeftVarPtr;
-extern int32 *gob_curGobTopVarPtr;
-extern int32 *gob_curGobRightVarPtr;
-extern int32 *gob_curGobBottomVarPtr;
-extern int32 *gob_curGobDoAnimVarPtr;
-extern int32 *gob_curGobOrderVarPtr;
-extern int32 *gob_curGobNoTickVarPtr;
-extern int32 *gob_curGobTypeVarPtr;
-extern int32 *gob_curGobMaxTickVarPtr;
-extern int32 *gob_curGobTickVarPtr;
-extern int32 *gob_curGobActStartStateVarPtr;
-extern int32 *gob_curGobLookDirVarPtr;
-extern int32 *gob_curGobPickableVarPtr;
-extern int32 *gob_curGobRelaxVarPtr;
-extern int32 *gob_curGobMaxFrameVarPtr;
+	int32 *curGobStateVarPtr;
+	int32 *curGobFrameVarPtr;
+	int32 *curGobMultStateVarPtr;
+	int32 *curGobNextStateVarPtr;
+	int32 *curGobScrXVarPtr;
+	int32 *curGobScrYVarPtr;
+	int32 *curGobLeftVarPtr;
+	int32 *curGobTopVarPtr;
+	int32 *curGobRightVarPtr;
+	int32 *curGobBottomVarPtr;
+	int32 *curGobDoAnimVarPtr;
+	int32 *curGobOrderVarPtr;
+	int32 *curGobNoTickVarPtr;
+	int32 *curGobTypeVarPtr;
+	int32 *curGobMaxTickVarPtr;
+	int32 *curGobTickVarPtr;
+	int32 *curGobActStartStateVarPtr;
+	int32 *curGobLookDirVarPtr;
+	int32 *curGobPickableVarPtr;
+	int32 *curGobRelaxVarPtr;
+	int32 *curGobMaxFrameVarPtr;
 
-extern int32 *gob_destItemStateVarPtr;
-extern int32 *gob_destItemFrameVarPtr;
-extern int32 *gob_destItemMultStateVarPtr;
-extern int32 *gob_destItemNextStateVarPtr;
-extern int32 *gob_destItemScrXVarPtr;
-extern int32 *gob_destItemScrYVarPtr;
-extern int32 *gob_destItemLeftVarPtr;
-extern int32 *gob_destItemTopVarPtr;
-extern int32 *gob_destItemRightVarPtr;
-extern int32 *gob_destItemBottomVarPtr;
-extern int32 *gob_destItemDoAnimVarPtr;
-extern int32 *gob_destItemOrderVarPtr;
-extern int32 *gob_destItemNoTickVarPtr;
-extern int32 *gob_destItemTypeVarPtr;
-extern int32 *gob_destItemMaxTickVarPtr;
-extern int32 *gob_destItemTickVarPtr;
-extern int32 *gob_destItemActStartStVarPtr;
-extern int32 *gob_destItemLookDirVarPtr;
-extern int32 *gob_destItemPickableVarPtr;
-extern int32 *gob_destItemRelaxVarPtr;
-extern int32 *gob_destItemMaxFrameVarPtr;
+	int32 *destItemStateVarPtr;
+	int32 *destItemFrameVarPtr;
+	int32 *destItemMultStateVarPtr;
+	int32 *destItemNextStateVarPtr;
+	int32 *destItemScrXVarPtr;
+	int32 *destItemScrYVarPtr;
+	int32 *destItemLeftVarPtr;
+	int32 *destItemTopVarPtr;
+	int32 *destItemRightVarPtr;
+	int32 *destItemBottomVarPtr;
+	int32 *destItemDoAnimVarPtr;
+	int32 *destItemOrderVarPtr;
+	int32 *destItemNoTickVarPtr;
+	int32 *destItemTypeVarPtr;
+	int32 *destItemMaxTickVarPtr;
+	int32 *destItemTickVarPtr;
+	int32 *destItemActStartStVarPtr;
+	int32 *destItemLookDirVarPtr;
+	int32 *destItemPickableVarPtr;
+	int32 *destItemRelaxVarPtr;
+	int32 *destItemMaxFrameVarPtr;
 
-extern int16 gob_destItemType;
-extern int16 gob_destItemState;
-extern int16 gob_itemToObject[20];
-extern Gob_Object *gob_objects[20];
-extern int16 gob_objCount;
-extern int16 gob_gobsCount;
-extern int16 gob_itemIndInPocket;
-extern int16 gob_itemIdInPocket;
-extern char gob_itemByteFlag;
-extern int16 gob_destItemId;
-extern int16 gob_destActionItem;
-extern Gob_Object *gob_actDestItemDesc;
-extern int16 gob_forceNextState[10];
-extern char gob_boreCounter;
-extern int16 gob_positionedGob;
-extern char gob_noPick;
+	int16 destItemType;
+	int16 destItemState;
+	int16 itemToObject[20];
+	Gob_Object *objects[20];
+	int16 objCount;
+	int16 gobsCount;
+	int16 itemIndInPocket;
+	int16 itemIdInPocket;
+	char itemByteFlag;
+	int16 destItemId;
+	int16 destActionItem;
+	Gob_Object *actDestItemDesc;
+	int16 forceNextState[10];
+	char boreCounter;
+	int16 positionedGob;
+	char noPick;
 
-// Functions
-char gob_rotateState(int16 from, int16 to);
-void gob_playSound(Snd_SoundDesc * snd, int16 repCount, int16 freq);
-void gob_drawObjects(void);
-void gob_animateObjects(void);
-void gob_placeObject(Gob_Object * objDesc, char animated);
-int16 gob_getObjMaxFrame(Gob_Object * obj);
-int16 gob_objIntersected(Gob_Object * obj1, Gob_Object * obj2);
-void gob_setMultStates(Gob_Object * gobDesc);
-int16 gob_nextLayer(Gob_Object * gobDesc);
-void gob_showBoredom(int16 gobIndex);
-void gob_switchGoblin(int16 index);
-void gob_freeObjects(void);
-void gob_zeroObjects(void);
-void gob_freeAllObjects(void);
-void gob_loadObjects(char *source);
-void gob_initVarPointers(void);
-void gob_saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal);
-void gob_loadGobDataFromVars(void);
-void gob_pickItem(int16 indexToPocket, int16 idToPocket);
-void gob_placeItem(int16 indexInPocket, int16 idInPocket);
-void gob_swapItems(int16 indexToPick, int16 idToPick);
-void gob_treatItemPick(int16 itemId);
-int16 gob_treatItem(int16 action);
-void gob_interFunc(void);
+	// Functions
+	char rotateState(int16 from, int16 to);
+	void playSound(Snd::SoundDesc * snd, int16 repCount, int16 freq);
+	void drawObjects(void);
+	void animateObjects(void);
+	void placeObject(Gob_Object * objDesc, char animated);
+	int16 getObjMaxFrame(Gob_Object * obj);
+	int16 objIntersected(Gob_Object * obj1, Gob_Object * obj2);
+	void setMultStates(Gob_Object * gobDesc);
+	int16 nextLayer(Gob_Object * gobDesc);
+	void showBoredom(int16 gobIndex);
+	void switchGoblin(int16 index);
+	void freeObjects(void);
+	void zeroObjects(void);
+	void freeAllObjects(void);
+	void loadObjects(char *source);
+	void initVarPointers(void);
+	void saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal);
+	void loadGobDataFromVars(void);
+	void pickItem(int16 indexToPocket, int16 idToPocket);
+	void placeItem(int16 indexInPocket, int16 idInPocket);
+	void swapItems(int16 indexToPick, int16 idToPick);
+	void treatItemPick(int16 itemId);
+	int16 treatItem(int16 action);
+	void interFunc(void);
+
+	Goblin(GobEngine *vm);
+
+protected:
+	int16 rotStates[4][4];
+	GobEngine *_vm;
+
+	int16 peekGoblin(Gob_Object *curGob);
+	void initList(void);
+	void sortByOrder(Util::List *list);
+	void adjustDest(int16 posX, int16 posY);
+	void adjustTarget(void);
+	void targetDummyItem(Gob_Object *gobDesc);
+	void targetItem(void);
+	void initiateMove(void);
+	void moveFindItem(int16 posX, int16 posY);
+	void moveCheckSelect(int16 framesCount, Gob_Object * gobDesc, int16 *pGobIndex, int16 *nextAct);
+	void moveInitStep(int16 framesCount, int16 action, int16 cont,
+					  Gob_Object *gobDesc, int16 *pGobIndex, int16 *pNextAct);
+	void moveTreatRopeStairs(Gob_Object *gobDesc);
+	void movePathFind(Gob_Object *gobDesc, int16 nextAct);
+	void moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount);
+	int16 doMove(Gob_Object *gobDesc, int16 cont, int16 action);
+};
 
 }				// End of namespace Gob
 

Index: init.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/init.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- init.cpp	18 Oct 2005 01:30:17 -0000	1.12
+++ init.cpp	3 Jan 2006 23:14:39 -0000	1.13
@@ -36,102 +36,99 @@
 
 void game_start(void);
 
-extern int16 debugFlag;
-extern int16 inVM;
-extern int16 colorCount;
-
-PalDesc *init_palDesc;
+const char *Init::fontNames[] = { "jeulet1.let", "jeulet2.let", "jeucar1.let", "jeumath.let" };
 
-static const char *init_fontNames[] =
-    { "jeulet1.let", "jeulet2.let", "jeucar1.let", "jeumath.let" };
+Init::Init(GobEngine *vm) : _vm(vm) {
+	palDesc = 0;
+}
 
-void init_findBestCfg(void) {
-	videoMode = VIDMODE_VGA;
-	useMouse = mousePresent;
-	if (presentSound & BLASTER_FLAG)
-		soundFlags = BLASTER_FLAG | SPEAKER_FLAG | MIDI_FLAG;
-	else if (presentSound & PROAUDIO_FLAG)
-		soundFlags = PROAUDIO_FLAG | SPEAKER_FLAG | MIDI_FLAG;
-	else if (presentSound & ADLIB_FLAG)
-		soundFlags = ADLIB_FLAG | SPEAKER_FLAG | MIDI_FLAG;
-	else if (presentSound & INTERSOUND_FLAG)
-		soundFlags = INTERSOUND_FLAG | SPEAKER_FLAG;
-	else if (presentSound & SPEAKER_FLAG)
-		soundFlags = SPEAKER_FLAG;
+void Init::findBestCfg(void) {
+	_vm->_global->videoMode = VIDMODE_VGA;
+	_vm->_global->useMouse = _vm->_global->mousePresent;
+	if (_vm->_global->presentSound & BLASTER_FLAG)
+		_vm->_global->soundFlags = BLASTER_FLAG | SPEAKER_FLAG | MIDI_FLAG;
+	else if (_vm->_global->presentSound & PROAUDIO_FLAG)
+		_vm->_global->soundFlags = PROAUDIO_FLAG | SPEAKER_FLAG | MIDI_FLAG;
+	else if (_vm->_global->presentSound & ADLIB_FLAG)
+		_vm->_global->soundFlags = ADLIB_FLAG | SPEAKER_FLAG | MIDI_FLAG;
+	else if (_vm->_global->presentSound & INTERSOUND_FLAG)
+		_vm->_global->soundFlags = INTERSOUND_FLAG | SPEAKER_FLAG;
+	else if (_vm->_global->presentSound & SPEAKER_FLAG)
+		_vm->_global->soundFlags = SPEAKER_FLAG;
 	else
-		soundFlags = 0;
+		_vm->_global->soundFlags = 0;
 }
 
-void init_soundVideo(int32 smallHeap, int16 flag) {
-	if (videoMode != 0x13 && videoMode != 0)
-		error("init_soundVideo: Video mode 0x%x is not supported!",
-		    videoMode);
+void Init::soundVideo(int32 smallHeap, int16 flag) {
+	if (_vm->_global->videoMode != 0x13 && _vm->_global->videoMode != 0)
+		error("soundVideo: Video mode 0x%x is not supported!",
+		    _vm->_global->videoMode);
 
 	//if ((flag & 4) == 0)
-	//	vid_findVideo();
+	//	_vm->_video->findVideo();
 
-	mousePresent = 1;
+	_vm->_global->mousePresent = 1;
 
-	inVM = 0;
+	_vm->_global->inVM = 0;
 
-	presentSound = 0; // FIXME: sound is not supported yet
+	_vm->_global->presentSound = 0; // FIXME: sound is not supported yet
 
-	sprAllocated = 0;
-	timer_enableTimer();
+	_vm->_global->sprAllocated = 0;
+	_vm->_gtimer->enableTimer();
 
-	// snd_setResetTimerFlag(debugFlag); // TODO
+	// _vm->_snd->setResetTimerFlag(debugFlag); // TODO
 
-	if (videoMode == 0x13)
-		colorCount = 256;
+	if (_vm->_global->videoMode == 0x13)
+		_vm->_global->colorCount = 256;
 
-	pPaletteDesc = &paletteStruct;
-	pPaletteDesc->vgaPal = vgaPalette;
-	pPaletteDesc->unused1 = unusedPalette1;
-	pPaletteDesc->unused2 = unusedPalette2;
-	pPrimarySurfDesc = &primarySurfDesc;
+	_vm->_global->pPaletteDesc = &_vm->_global->paletteStruct;
+	_vm->_global->pPaletteDesc->vgaPal = _vm->_global->vgaPalette;
+	_vm->_global->pPaletteDesc->unused1 = _vm->_global->unusedPalette1;
+	_vm->_global->pPaletteDesc->unused2 = _vm->_global->unusedPalette2;
+	_vm->_global->pPrimarySurfDesc = &_vm->_global->primarySurfDesc;
 
-	if (videoMode != 0)
-		vid_initSurfDesc(videoMode, 320, 200, PRIMARY_SURFACE);
+	if (_vm->_global->videoMode != 0)
+		_vm->_video->initSurfDesc(_vm->_global->videoMode, 320, 200, PRIMARY_SURFACE);
 
-	if (soundFlags & MIDI_FLAG) {
-		soundFlags &= presentSound;
-		if (presentSound & ADLIB_FLAG)
-			soundFlags |= MIDI_FLAG;
+	if (_vm->_global->soundFlags & MIDI_FLAG) {
+		_vm->_global->soundFlags &= _vm->_global->presentSound;
+		if (_vm->_global->presentSound & ADLIB_FLAG)
+			_vm->_global->soundFlags |= MIDI_FLAG;
 	} else {
-		soundFlags &= presentSound;
+		_vm->_global->soundFlags &= _vm->_global->presentSound;
 	}
 }
 
-void init_cleanup(void) {
-	if (debugFlag == 0)
-		timer_disableTimer();
+void Init::cleanup(void) {
+	if (_vm->_global->debugFlag == 0)
+		_vm->_gtimer->disableTimer();
 
-	vid_freeDriver();
-	if (curPrimaryDesc != 0) {
-		vid_freeSurfDesc(curPrimaryDesc);
-		vid_freeSurfDesc(allocatedPrimary);
-		allocatedPrimary = 0;
-		curPrimaryDesc = 0;
+	_vm->_video->freeDriver();
+	if (_vm->_global->curPrimaryDesc != 0) {
+		_vm->_video->freeSurfDesc(_vm->_global->curPrimaryDesc);
+		_vm->_video->freeSurfDesc(_vm->_global->allocatedPrimary);
+		_vm->_global->allocatedPrimary = 0;
+		_vm->_global->curPrimaryDesc = 0;
 	}
-	pPrimarySurfDesc = 0;
-	if (snd_cleanupFunc != 0 && snd_playingSound != 0) {
-		(*snd_cleanupFunc) (0);
-		snd_cleanupFunc = 0;
+	_vm->_global->pPrimarySurfDesc = 0;
+	if (_vm->_snd->cleanupFunc != 0 && _vm->_snd->playingSound != 0) {
+		(*_vm->_snd->cleanupFunc) (0);
+		_vm->_snd->cleanupFunc = 0;
 	}
-	snd_speakerOff();
+	_vm->_snd->speakerOff();
 
-	data_closeDataFile();
+	_vm->_dataio->closeDataFile();
 
-	if (sprAllocated != 0)
-		error("init_cleanup: Error! Allocated sprites left: %d",
-		    sprAllocated);
+	if (_vm->_global->sprAllocated != 0)
+		error("cleanup: Error! Allocated sprites left: %d",
+		    _vm->_global->sprAllocated);
 
-	snd_stopSound(0);
-	keyboard_release();
+	_vm->_snd->stopSound(0);
+	_vm->_util->keyboard_release();
 	g_system->quit();
 }
 
-void init_initGame(char *totName) {
+void Init::initGame(char *totName) {
 	int16 handle2;
 	int16 i;
 	int16 handle;
@@ -154,58 +151,58 @@
 memAvail	= dword	ptr -6
 memBlocks	= word ptr -2*/
 
-	disableVideoCfg = 0x11;
-	disableMouseCfg = 0x15;
-	init_soundVideo(1000, 1);
+	_vm->_global->disableVideoCfg = 0x11;
+	_vm->_global->disableMouseCfg = 0x15;
+	soundVideo(1000, 1);
 
-	handle2 = data_openData("intro.stk");
+	handle2 = _vm->_dataio->openData("intro.stk");
 	if (handle2 >= 0) {
-		data_closeData(handle2);
-		data_openDataFile("intro.stk");
+		_vm->_dataio->closeData(handle2);
+		_vm->_dataio->openDataFile("intro.stk");
 	}
 
-	util_initInput();
+	_vm->_util->initInput();
 
-	vid_setHandlers();
-	vid_initPrimary(videoMode);
-	mouseXShift = 1;
-	mouseYShift = 1;
+	_vm->_video->setHandlers();
+	_vm->_video->initPrimary(_vm->_global->videoMode);
+	_vm->_global->mouseXShift = 1;
+	_vm->_global->mouseYShift = 1;
 
-	game_totTextData = 0;
-	game_totFileData = 0;
-	game_totResourceTable = 0;
-	inter_variables = 0;
-	init_palDesc = (PalDesc *)malloc(12);
+	_vm->_game->totTextData = 0;
+	_vm->_game->totFileData = 0;
+	_vm->_game->totResourceTable = 0;
+	_vm->_global->inter_variables = 0;
+	palDesc = (Video::PalDesc *)malloc(12);
 
-	if (videoMode != 0x13)
-		error("init_initGame: Only 0x13 video mode is supported!");
+	if (_vm->_global->videoMode != 0x13)
+		error("initGame: Only 0x13 video mode is supported!");
 
-	init_palDesc->vgaPal = draw_vgaPalette;
-	init_palDesc->unused1 = draw_unusedPalette1;
-	init_palDesc->unused2 = draw_unusedPalette2;
-	vid_setFullPalette(init_palDesc);
+	palDesc->vgaPal = _vm->_draw->vgaPalette;
+	palDesc->unused1 = _vm->_draw->unusedPalette1;
+	palDesc->unused2 = _vm->_draw->unusedPalette2;
+	_vm->_video->setFullPalette(palDesc);
 
 	for (i = 0; i < 4; i++)
-		draw_fonts[i] = 0;
+		_vm->_draw->fonts[i] = 0;
 
-	handle = data_openData("intro.inf");
+	handle = _vm->_dataio->openData("intro.inf");
 
 	if (handle < 0) {
 		for (i = 0; i < 4; i++) {
-			handle2 = data_openData(init_fontNames[i]);
+			handle2 = _vm->_dataio->openData(fontNames[i]);
 			if (handle2 >= 0) {
-				data_closeData(handle2);
-				draw_fonts[i] =
-				    util_loadFont(init_fontNames[i]);
+				_vm->_dataio->closeData(handle2);
+				_vm->_draw->fonts[i] =
+				    _vm->_util->loadFont(fontNames[i]);
 			}
 		}
 	} else {
-		data_closeData(handle);
+		_vm->_dataio->closeData(handle);
 
-		infPtr = data_getData("intro.inf");
+		infPtr = _vm->_dataio->getData("intro.inf");
 		infBuf = infPtr;
 
-		infEnd = infBuf + data_getDataSize("intro.inf");
+		infEnd = infBuf + _vm->_dataio->getDataSize("intro.inf");
 
 		for (i = 0; i < 4; i++, infPtr++) {
 			for (j = 0; *infPtr >= ' ' && infPtr != infEnd;
@@ -214,10 +211,10 @@
 
 			buffer[j] = 0;
 			strcat(buffer, ".let");
-			handle2 = data_openData(buffer);
+			handle2 = _vm->_dataio->openData(buffer);
 			if (handle2 >= 0) {
-				data_closeData(handle2);
-				draw_fonts[i] = util_loadFont(buffer);
+				_vm->_dataio->closeData(handle2);
+				_vm->_draw->fonts[i] = _vm->_util->loadFont(buffer);
 			}
 
 			if (infPtr == infEnd)
@@ -238,42 +235,42 @@
 		strcpy(buffer, "intro.tot");
 	}
 
-	handle = data_openData(buffer);
+	handle = _vm->_dataio->openData(buffer);
 
 	if (handle >= 0) {
 		// Get variables count
-		data_seekData(handle, 0x2c, SEEK_SET);
-		data_readData(handle, (char *)&varsCount, 4);
+		_vm->_dataio->seekData(handle, 0x2c, SEEK_SET);
+		_vm->_dataio->readData(handle, (char *)&varsCount, 4);
 		varsCount = FROM_LE_32(varsCount);
-		data_closeData(handle);
+		_vm->_dataio->closeData(handle);
 
-		inter_variables = (char *)malloc(varsCount * 4);
-		memset(inter_variables, 0, varsCount * 4);
+		_vm->_global->inter_variables = (char *)malloc(varsCount * 4);
+		memset(_vm->_global->inter_variables, 0, varsCount * 4);
 
-		strcpy(game_curTotFile, buffer);
+		strcpy(_vm->_game->curTotFile, buffer);
 
-		cd_testCD(1, "GOB");
-		cd_readLIC("gob.lic");
-		game_start();
+		_vm->_cdrom->testCD(1, "GOB");
+		_vm->_cdrom->readLIC("gob.lic");
+		_vm->_game->start();
 
-		cd_stopPlaying();
-		cd_freeLICbuffer();
+		_vm->_cdrom->stopPlaying();
+		_vm->_cdrom->freeLICbuffer();
 
-		free(inter_variables);
-		free(game_totFileData);
-		free(game_totTextData);
-		free(game_totResourceTable);
+		free(_vm->_global->inter_variables);
+		free(_vm->_game->totFileData);
+		free(_vm->_game->totTextData);
+		free(_vm->_game->totResourceTable);
 	}
 
 	for (i = 0; i < 4; i++) {
-		if (draw_fonts[i] != 0)
-			util_freeFont(draw_fonts[i]);
+		if (_vm->_draw->fonts[i] != 0)
+			_vm->_util->freeFont(_vm->_draw->fonts[i]);
 	}
 
-	free(init_palDesc);
-	data_closeDataFile();
-	vid_initPrimary(-1);
-	init_cleanup();
+	free(palDesc);
+	_vm->_dataio->closeDataFile();
+	_vm->_video->initPrimary(-1);
+	cleanup();
 }
 
 }				// End of namespace Gob

Index: init.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/init.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- init.h	18 Oct 2005 01:30:17 -0000	1.4
+++ init.h	3 Jan 2006 23:14:39 -0000	1.5
@@ -24,10 +24,22 @@
 
 namespace Gob {
 
-void init_findBestCfg(void);
-void init_soundVideo(int32 smallHeapSize, int16 flag);
+class Init {
+public:
+	void findBestCfg(void);
+	void soundVideo(int32 smallHeapSize, int16 flag);
 
-void init_initGame(char *totFile);
+	void initGame(char *totFile);
+
+	Init(GobEngine *vm);
+
+protected:
+	Video::PalDesc *palDesc;
+	static const char *fontNames[4];
+	GobEngine *_vm;
+
+	void cleanup(void);
+};
 
 }				// End of namespace Gob
 

Index: inter.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/inter.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- inter.cpp	18 Oct 2005 01:30:17 -0000	1.25
+++ inter.cpp	3 Jan 2006 23:14:39 -0000	1.26
@@ -33,42 +33,44 @@
 
 namespace Gob {
 
-int16 inter_animPalLowIndex;
-int16 inter_animPalHighIndex;
-int16 inter_animPalDir;
-uint32 inter_soundEndTimeKey;
-int16 inter_soundStopVal;
-char inter_terminate = 0;
-char inter_breakFlag = 0;
-int16 *inter_breakFromLevel;
[...2032 lines suppressed...]
-	while (inter_execPtr != 0 && (char *)inter_execPtr != game_totFileData) {
-		block = *inter_execPtr;
+	while (_vm->_global->inter_execPtr != 0 && (char *)_vm->_global->inter_execPtr != _vm->_game->totFileData) {
+		block = *_vm->_global->inter_execPtr;
 		if (block == 1) {
-			inter_funcBlock(retFlag);
+			funcBlock(retFlag);
 		} else if (block == 2) {
-			game_collisionsBlock();
+			_vm->_game->collisionsBlock();
 		}
 	}
 
-	if ((char *)inter_execPtr == game_totFileData)
-		inter_terminate = 1;
+	if ((char *)_vm->_global->inter_execPtr == _vm->_game->totFileData)
+		terminate = 1;
 }
 
 } // End of namespace Gob

Index: inter.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/inter.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- inter.h	18 Oct 2005 01:30:17 -0000	1.4
+++ inter.h	3 Jan 2006 23:14:39 -0000	1.5
@@ -24,75 +24,83 @@
 
 namespace Gob {
 
-extern int16 inter_animPalLowIndex;
-extern int16 inter_animPalHighIndex;
-extern int16 inter_animPalDir;
-extern uint32 inter_soundEndTimeKey;
-extern int16 inter_soundStopVal;
-extern char inter_terminate;
-extern char inter_breakFlag;
-extern int16 *inter_breakFromLevel;
-extern int16 *inter_nestLevel;
+class Inter {
+public:
+	int16 animPalLowIndex;
+	int16 animPalHighIndex;
+	int16 animPalDir;
+	uint32 soundEndTimeKey;
+	int16 soundStopVal;
+	char terminate;
+	char breakFlag;
+	int16 *breakFromLevel;
+	int16 *nestLevel;
 
-int16 inter_load16(void);
-int16 inter_peek16(char *ptr);
-int32 inter_peek32(char *ptr);
+	int16 load16(void);
+	int16 peek16(char *ptr);
+	int32 peek32(char *ptr);
 
-void inter_setMousePos(void);
-char inter_evalExpr(int16 *pRes);
-char inter_evalBoolResult(void);
-void inter_storeResult(void);
-void inter_printText(void);
-void inter_animPalette(void);
-void inter_animPalInit(void);
-void inter_loadMult(void);
-void inter_playMult(void);
-void inter_freeMult(void);
-void inter_initCursor(void);
-void inter_initCursorAnim(void);
-void inter_clearCursorAnim(void);
-void inter_drawOperations(void);
-void inter_getFreeMem(void);
-void inter_manageDataFile(void);
-void inter_getFreeMem(void);
-void inter_manageDataFile(void);
-void inter_writeData(void);
-void inter_checkData(void);
-void inter_readData(void);
-void inter_loadFont(void);
-void inter_freeFont(void);
-void inter_prepareStr(void);
-void inter_insertStr(void);
-void inter_cutStr(void);
-void inter_strstr(void);
-void inter_setFrameRate(void);
-void inter_strlen(void);
-void inter_strToLong(void);
-void inter_invalidate(void);
-void inter_loadSpriteContent(void);
-void inter_copySprite(void);
-void inter_putPixel(void);
-void inter_fillRect(void);
-void inter_drawLine(void);
-void inter_createSprite(void);
-void inter_freeSprite(void);
-void inter_renewTimeInVars(void);
-void inter_playComposition(void);
-void inter_stopSound(void);
-void inter_playSound(void);
-void inter_loadCursor(void);
-void inter_loadSpriteToPos(void);
-void inter_funcBlock(int16 retFlag);
-void inter_loadTot(void);
-void inter_storeKey(int16 key);
-void inter_keyFunc(void);
-void inter_checkSwitchTable(char **ppExec);
-void inter_repeatUntil(void);
-void inter_whileDo(void);
-void inter_funcBlock(int16 retFlag);
-void inter_callSub(int16 retFlag);
-void inter_initControlVars(void);
-void inter_callSub(int16 retFlag);
+	void setMousePos(void);
+	char evalExpr(int16 *pRes);
+	char evalBoolResult(void);
+	void storeResult(void);
+	void printText(void);
+	void animPalette(void);
+	void animPalInit(void);
+	void loadMult(void);
+	void playMult(void);
+	void freeMult(void);
+	void initCursor(void);
+	void initCursorAnim(void);
+	void clearCursorAnim(void);
+	void drawOperations(void);
+	void getFreeMem(void);
+	void manageDataFile(void);
+	void writeData(void);
+	void checkData(void);
+	void readData(void);
+	void loadFont(void);
+	void freeFont(void);
+	void prepareStr(void);
+	void insertStr(void);
+	void cutStr(void);
+	void strstr(void);
+	void setFrameRate(void);
+	void istrlen(void);
+	void strToLong(void);
+	void invalidate(void);
+	void loadSpriteContent(void);
+	void copySprite(void);
+	void putPixel(void);
+	void fillRect(void);
+	void drawLine(void);
+	void createSprite(void);
+	void freeSprite(void);
+	void renewTimeInVars(void);
+	void playComposition(void);
+	void stopSound(void);
+	void playSound(void);
+	void loadCursor(void);
+	void loadSpriteToPos(void);
+	void funcBlock(int16 retFlag);
+	void loadTot(void);
+	void storeKey(int16 key);
+	void keyFunc(void);
+	void checkSwitchTable(char **ppExec);
+	void repeatUntil(void);
+	void whileDo(void);
+	void callSub(int16 retFlag);
+	void initControlVars(void);
+
+	Inter(GobEngine *vm);
+
+protected:
+	GobEngine *_vm;
+
+	void evaluateStore(void);
+	void capturePush(void);
+	void capturePop(void);
+};
 
 }				// End of namespace Gob
 

Index: map.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/map.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- map.cpp	30 Dec 2005 18:39:01 -0000	1.17
+++ map.cpp	3 Jan 2006 23:14:39 -0000	1.18
@@ -31,28 +31,38 @@
 
 namespace Gob {
 
-int8 map_passMap[kMapHeight][kMapWidth];	// [y][x]
-int16 map_itemsMap[kMapHeight][kMapWidth];	// [y][x]
-
-Map_Point map_wayPoints[40];
-int16 map_nearestWayPoint = 0;
-int16 map_nearestDest = 0;
-
-int16 map_curGoblinX;
-int16 map_curGoblinY;
-int16 map_destX;
-int16 map_destY;
+Map::Map(GobEngine *vm) : _vm(vm) {
+	for (int i = 0; i < kMapHeight; i++)
+		for (int j = 0; j < kMapWidth; j++) {
+			passMap[i][j] = 0;
+			itemsMap[i][j] = 0;
+		}
+	for (int i = 0; i < 40; i++) {
+		wayPoints[i].x = 0;
+		wayPoints[i].y = 0;
+	}
+	for (int i = 0; i < 40; i++) {
+		itemPoses[i].x = 0;
+		itemPoses[i].y = 0;
+		itemPoses[i].orient = 0;
+	}
 
-Map_ItemPos map_itemPoses[40];
-int8 map_loadFromAvo;
-char map_sourceFile[15];
-static char *map_avoDataPtr;
+	nearestWayPoint = 0;
+	nearestDest = 0;
+	curGoblinX = 0;
+	curGoblinY = 0;
+	destX = 0;
+	destY = 0;
+	loadFromAvo = 0;
+	sourceFile[0] = 0;
+	avoDataPtr = 0;
+}
 
-void map_placeItem(int16 x, int16 y, int16 id) {
-	if ((map_itemsMap[y][x] & 0xff00) != 0)
-		map_itemsMap[y][x] = (map_itemsMap[y][x] & 0xff00) | id;
+void Map::placeItem(int16 x, int16 y, int16 id) {
+	if ((itemsMap[y][x] & 0xff00) != 0)
+		itemsMap[y][x] = (itemsMap[y][x] & 0xff00) | id;
 	else
-		map_itemsMap[y][x] = (map_itemsMap[y][x] & 0x00ff) | (id << 8);
+		itemsMap[y][x] = (itemsMap[y][x] & 0x00ff) | (id << 8);
 }
 
 enum {
@@ -62,7 +72,7 @@
 	kDown  = (1 << 3)
 };
 
-int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
+int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
 	int16 dir = 0;
 
 	if (x0 == x1 && y0 == y1)
@@ -81,63 +91,63 @@
 	else if (x1 < x0)
 		dir |= kLeft;
 
-	if (map_passMap[y0][x0] == 3 && (dir & kUp)) {
-		if (map_passMap[y0 - 1][x0] != 0)
+	if (passMap[y0][x0] == 3 && (dir & kUp)) {
+		if (passMap[y0 - 1][x0] != 0)
 			return kDirN;
 	}
 
-	if (map_passMap[y0][x0] == 3 && (dir & kDown)) {
-		if (map_passMap[y0 + 1][x0] != 0)
+	if (passMap[y0][x0] == 3 && (dir & kDown)) {
+		if (passMap[y0 + 1][x0] != 0)
 			return kDirS;
 	}
 
-	if (map_passMap[y0][x0] == 6 && (dir & kUp)) {
-		if (map_passMap[y0 - 1][x0] != 0)
+	if (passMap[y0][x0] == 6 && (dir & kUp)) {
+		if (passMap[y0 - 1][x0] != 0)
 			return kDirN;
 	}
 
-	if (map_passMap[y0][x0] == 6 && (dir & kDown)) {
-		if (map_passMap[y0 + 1][x0] != 0)
+	if (passMap[y0][x0] == 6 && (dir & kDown)) {
+		if (passMap[y0 + 1][x0] != 0)
 			return kDirS;
 	}
 
 	if (dir == kLeft) {
-		if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0)
+		if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0)
 			return kDirW;
 		return 0;
 	}
 
 	if (dir == kRight) {
-		if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0)
+		if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0)
 			return kDirE;
 		return 0;
 	}
 
 	if (dir == kUp) {
-		if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0)
+		if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0)
 			return kDirN;
 
 		if (y0 - 1 >= 0 && x0 - 1 >= 0
-		    && map_passMap[y0 - 1][x0 - 1] != 0)
+		    && passMap[y0 - 1][x0 - 1] != 0)
 			return kDirNW;
 
 		if (y0 - 1 >= 0 && x0 + 1 < kMapWidth
-		    && map_passMap[y0 - 1][x0 + 1] != 0)
+		    && passMap[y0 - 1][x0 + 1] != 0)
 			return kDirNE;
 
 		return 0;
 	}
 
 	if (dir == kDown) {
-		if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0)
+		if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0)
 			return kDirS;
 
 		if (y0 + 1 < kMapHeight && x0 - 1 >= 0
-		    && map_passMap[y0 + 1][x0 - 1] != 0)
+		    && passMap[y0 + 1][x0 - 1] != 0)
 			return kDirSW;
 
 		if (y0 + 1 < kMapHeight && x0 + 1 < kMapWidth
-		    && map_passMap[y0 + 1][x0 + 1] != 0)
+		    && passMap[y0 + 1][x0 + 1] != 0)
 			return kDirSE;
 
 		return 0;
@@ -145,13 +155,13 @@
 
 	if (dir == (kRight | kUp)) {
 		if (y0 - 1 >= 0 && x0 + 1 < kMapWidth
-		    && map_passMap[y0 - 1][x0 + 1] != 0)
+		    && passMap[y0 - 1][x0 + 1] != 0)
 			return kDirNE;
 
-		if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0)
+		if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0)
 			return kDirN;
 
-		if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0)
+		if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0)
 			return kDirE;
 
 		return 0;
@@ -159,13 +169,13 @@
 
 	if (dir == (kRight | kDown)) {
 		if (x0 + 1 < kMapWidth && y0 + 1 < kMapHeight
-		    && map_passMap[y0 + 1][x0 + 1] != 0)
+		    && passMap[y0 + 1][x0 + 1] != 0)
 			return kDirSE;
 
-		if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0)
+		if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0)
 			return kDirS;
 
-		if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0)
+		if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0)
 			return kDirE;
 
 		return 0;
@@ -173,13 +183,13 @@
 
 	if (dir == (kLeft | kUp)) {
 		if (x0 - 1 >= 0 && y0 - 1 >= 0
-		    && map_passMap[y0 - 1][x0 - 1] != 0)
+		    && passMap[y0 - 1][x0 - 1] != 0)
 			return kDirNW;
 
-		if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0)
+		if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0)
 			return kDirN;
 
-		if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0)
+		if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0)
 			return kDirW;
 
 		return 0;
@@ -187,13 +197,13 @@
 
 	if (dir == (kLeft | kDown)) {
 		if (x0 - 1 >= 0 && y0 + 1 < kMapHeight
-		    && map_passMap[y0 + 1][x0 - 1] != 0)
+		    && passMap[y0 + 1][x0 - 1] != 0)
 			return kDirSW;
 
-		if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0)
+		if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0)
 			return kDirS;
 
-		if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0)
+		if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0)
 			return kDirW;
 
 		return 0;
@@ -201,8 +211,8 @@
 	return -1;
 }
 
-int16 map_findNearestWayPoint(int16 x, int16 y) {
-	int16 nearestWayPoint = -1;
+int16 Map::findNearestWayPoint(int16 x, int16 y) {
+	int16 lnearestWayPoint = -1;
 	int16 length;
 	int16 i;
 	int16 tmp;
@@ -210,41 +220,41 @@
 	length = 30000;
 
 	for (i = 0; i < 40; i++) {
-		if (map_wayPoints[i].x < 0 ||
-		    map_wayPoints[i].x >= kMapWidth ||
-		    map_wayPoints[i].y < 0 || map_wayPoints[i].y >= kMapHeight)
+		if (wayPoints[i].x < 0 ||
+				wayPoints[i].x >= kMapWidth ||
+				wayPoints[i].y < 0 || wayPoints[i].y >= kMapHeight)
 			return -1;
 
-		tmp = ABS(x - map_wayPoints[i].x) + ABS(y - map_wayPoints[i].y);
+		tmp = ABS(x - wayPoints[i].x) + ABS(y - wayPoints[i].y);
 
 		if (tmp <= length) {
-			nearestWayPoint = i;
+			lnearestWayPoint = i;
 			length = tmp;
 		}
 	}
 
-	return nearestWayPoint;
+	return lnearestWayPoint;
 }
 
-void map_findNearestToGob(void) {
-	int16 wayPoint = map_findNearestWayPoint(map_curGoblinX, map_curGoblinY);
+void Map::findNearestToGob(void) {
+	int16 wayPoint = findNearestWayPoint(curGoblinX, curGoblinY);
 
 	if (wayPoint != -1)
-		map_nearestWayPoint = wayPoint;
+		nearestWayPoint = wayPoint;
 }
 
-void map_findNearestToDest(void) {
-	int16 wayPoint = map_findNearestWayPoint(map_destX, map_destY);
+void Map::findNearestToDest(void) {
+	int16 wayPoint = findNearestWayPoint(destX, destY);
 
 	if (wayPoint != -1)
-		map_nearestDest = wayPoint;
+		nearestDest = wayPoint;
 }
 
-int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) {
+int16 Map::checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) {
 	uint16 dir;
 
 	while (1) {
-		dir = map_getDirection(x0, y0, x1, y1);
+		dir = getDirection(x0, y0, x1, y1);
 
 		if (x0 == x1 && y0 == y1)
 			return 1;
@@ -292,7 +302,7 @@
 	}
 }
 
-int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) {
+int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) {
 	uint16 dir;
 	int16 curX;
 	int16 curY;
@@ -309,30 +319,30 @@
 			nextLink = 1;
 
 		if (nextLink != 0) {
-			if (map_checkDirectPath(x0, y0, x1, y1) == 1)
+			if (checkDirectPath(x0, y0, x1, y1) == 1)
 				return 1;
 
 			nextLink = 0;
 			if (i0 > i1) {
-				curX = map_wayPoints[i0].x;
-				curY = map_wayPoints[i0].y;
+				curX = wayPoints[i0].x;
+				curY = wayPoints[i0].y;
 				i0--;
 			} else if (i0 < i1) {
-				curX = map_wayPoints[i0].x;
-				curY = map_wayPoints[i0].y;
+				curX = wayPoints[i0].x;
+				curY = wayPoints[i0].y;
 				i0++;
 			} else if (i0 == i1) {
-				curX = map_wayPoints[i0].x;
-				curY = map_wayPoints[i0].y;
+				curX = wayPoints[i0].x;
+				curY = wayPoints[i0].y;
 			}
 		}
-		if (i0 == i1 && map_wayPoints[i0].x == x0
-		    && map_wayPoints[i0].y == y0) {
-			if (map_checkDirectPath(x0, y0, x1, y1) == 1)
+		if (i0 == i1 && wayPoints[i0].x == x0
+		    && wayPoints[i0].y == y0) {
+			if (checkDirectPath(x0, y0, x1, y1) == 1)
 				return 1;
 			return 0;
 		}
-		dir = map_getDirection(x0, y0, curX, curY);
+		dir = getDirection(x0, y0, curX, curY);
 		switch (dir) {
 		case 0:
 			return 0;
@@ -376,54 +386,54 @@
 	}
 }
 
-void map_optimizePoints(void) {
+void Map::optimizePoints(void) {
 	int16 i;
 
-	if (map_nearestWayPoint < map_nearestDest) {
-		for (i = map_nearestWayPoint; i <= map_nearestDest; i++) {
-			if (map_checkDirectPath(map_curGoblinX, map_curGoblinY,
-				map_wayPoints[i].x, map_wayPoints[i].y) == 1)
-				map_nearestWayPoint = i;
+	if (nearestWayPoint < nearestDest) {
+		for (i = nearestWayPoint; i <= nearestDest; i++) {
+			if (checkDirectPath(curGoblinX, curGoblinY,
+				wayPoints[i].x, wayPoints[i].y) == 1)
+				nearestWayPoint = i;
 		}
-	} else if (map_nearestWayPoint > map_nearestDest) {
-		for (i = map_nearestWayPoint; i >= map_nearestDest; i--) {
-			if (map_checkDirectPath(map_curGoblinX, map_curGoblinY,
-				map_wayPoints[i].x, map_wayPoints[i].y) == 1)
-				map_nearestWayPoint = i;
+	} else if (nearestWayPoint > nearestDest) {
+		for (i = nearestWayPoint; i >= nearestDest; i--) {
+			if (checkDirectPath(curGoblinX, curGoblinY,
+				wayPoints[i].x, wayPoints[i].y) == 1)
+				nearestWayPoint = i;
 		}
 	}
 }
 
-void map_loadDataFromAvo(char *dest, int16 size) {
-	memcpy(dest, map_avoDataPtr, size);
-	map_avoDataPtr += size;
+void Map::loadDataFromAvo(char *dest, int16 size) {
+	memcpy(dest, avoDataPtr, size);
+	avoDataPtr += size;
 }
 
-uint16 map_loadFromAvo_LE_UINT16() {
-	uint16 tmp = READ_LE_UINT16(map_avoDataPtr);
-	map_avoDataPtr += 2;
+uint16 Map::loadFromAvo_LE_UINT16() {
+	uint16 tmp = READ_LE_UINT16(avoDataPtr);
+	avoDataPtr += 2;
 	return tmp;
 }
 
-void map_loadItemToObject(void) {
+void Map::loadItemToObject(void) {
 	int16 flag;
 	int16 count;
 	int16 i;
 
-	flag = map_loadFromAvo_LE_UINT16();
+	flag = loadFromAvo_LE_UINT16();
 	if (flag == 0)
 		return;
 
-	map_avoDataPtr += 1456;
-	count = map_loadFromAvo_LE_UINT16();
+	avoDataPtr += 1456;
+	count = loadFromAvo_LE_UINT16();
 	for (i = 0; i < count; i++) {
-		map_avoDataPtr += 20;
-		gob_itemToObject[i] = map_loadFromAvo_LE_UINT16();
-		map_avoDataPtr += 5;
+		avoDataPtr += 20;
+		_vm->_goblin->itemToObject[i] = loadFromAvo_LE_UINT16();
+		avoDataPtr += 5;
 	}
 }
 
-void map_loadMapObjects(char *avjFile) {
+void Map::loadMapObjects(char *avjFile) {
 	int16 i;
 	char avoName[128];
 	int16 handle;
@@ -436,7 +446,7 @@
 	int16 state;
 	int16 col;
 	int32 flag;
-	Gob_State *pState;
+	Goblin::Gob_State *pState;
 	char buf[128];
 	char sndNames[20][14];
 	char *dataBuf;
@@ -445,154 +455,154 @@
 	int16 count2;
 	int16 count3;
 
-	strcpy(avoName, map_sourceFile);
+	strcpy(avoName, sourceFile);
 	strcat(avoName, ".avo");
 
-	handle = data_openData(avoName);
+	handle = _vm->_dataio->openData(avoName);
 	if (handle >= 0) {
-		map_loadFromAvo = 1;
-		data_closeData(handle);
-		map_avoDataPtr = data_getData(avoName);
-		dataBuf = map_avoDataPtr;
-		map_loadDataFromAvo((char *)map_passMap, kMapHeight * kMapWidth);
+		loadFromAvo = 1;
+		_vm->_dataio->closeData(handle);
+		avoDataPtr = _vm->_dataio->getData(avoName);
+		dataBuf = avoDataPtr;
+		loadDataFromAvo((char *)passMap, kMapHeight * kMapWidth);
 
 		for (y = 0; y < kMapHeight; y++) {
 			for (x = 0; x < kMapWidth; x++) {
-				map_loadDataFromAvo(&item, 1);
-				map_itemsMap[y][x] = item;
+				loadDataFromAvo(&item, 1);
+				itemsMap[y][x] = item;
 			}
 		}
 
 		for (i = 0; i < 40; i++) {
-			map_wayPoints[i].x = map_loadFromAvo_LE_UINT16();
-			map_wayPoints[i].y = map_loadFromAvo_LE_UINT16();
+			wayPoints[i].x = loadFromAvo_LE_UINT16();
+			wayPoints[i].y = loadFromAvo_LE_UINT16();
 		}
-		map_loadDataFromAvo((char *)map_itemPoses, szMap_ItemPos * 20);
+		loadDataFromAvo((char *)itemPoses, szMap_ItemPos * 20);
 	} else {
-		map_loadFromAvo = 0;
-		map_avoDataPtr = data_getData(avjFile);
-		dataBuf = map_avoDataPtr;
+		loadFromAvo = 0;
+		avoDataPtr = _vm->_dataio->getData(avjFile);
+		dataBuf = avoDataPtr;
 	}
 
-	map_avoDataPtr += 32;
-	map_avoDataPtr += 76;
-	map_avoDataPtr += 4;
-	map_avoDataPtr += 20;
+	avoDataPtr += 32;
+	avoDataPtr += 76;
+	avoDataPtr += 4;
+	avoDataPtr += 20;
 
 	for (i = 0; i < 3; i++) {
-		tmp = map_loadFromAvo_LE_UINT16();
-		map_avoDataPtr += tmp * 14;
+		tmp = loadFromAvo_LE_UINT16();
+		avoDataPtr += tmp * 14;
 	}
 
-	soundCount = map_loadFromAvo_LE_UINT16();
-	savedPtr = map_avoDataPtr;
+	soundCount = loadFromAvo_LE_UINT16();
+	savedPtr = avoDataPtr;
 
-	map_avoDataPtr += 14 * soundCount;
-	map_avoDataPtr += 4;
-	map_avoDataPtr += 24;
+	avoDataPtr += 14 * soundCount;
+	avoDataPtr += 4;
+	avoDataPtr += 24;
 
-	count2 = map_loadFromAvo_LE_UINT16();
-	count3 = map_loadFromAvo_LE_UINT16();
+	count2 = loadFromAvo_LE_UINT16();
+	count3 = loadFromAvo_LE_UINT16();
 
-	savedPtr2 = map_avoDataPtr;
-	map_avoDataPtr += count2 * 8;
+	savedPtr2 = avoDataPtr;
+	avoDataPtr += count2 * 8;
 
-	savedPtr3 = map_avoDataPtr;
-	map_avoDataPtr += count3 * 8;
+	savedPtr3 = avoDataPtr;
+	avoDataPtr += count3 * 8;
 
-	gob_gobsCount = map_loadFromAvo_LE_UINT16();
-	for (i = 0; i < gob_gobsCount; i++) {
-		gob_goblins[i] = (Gob_Object *)malloc(sizeof(Gob_Object));
+	_vm->_goblin->gobsCount = loadFromAvo_LE_UINT16();
+	for (i = 0; i < _vm->_goblin->gobsCount; i++) {
+		_vm->_goblin->goblins[i] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object));
 
-		gob_goblins[i]->xPos = READ_LE_UINT16(savedPtr2);
+		_vm->_goblin->goblins[i]->xPos = READ_LE_UINT16(savedPtr2);
 		savedPtr2 += 2;
 
-		gob_goblins[i]->yPos = READ_LE_UINT16(savedPtr2);
+		_vm->_goblin->goblins[i]->yPos = READ_LE_UINT16(savedPtr2);
 		savedPtr2 += 2;
 
-		gob_goblins[i]->order = READ_LE_UINT16(savedPtr2);
+		_vm->_goblin->goblins[i]->order = READ_LE_UINT16(savedPtr2);
 		savedPtr2 += 2;
 
-		gob_goblins[i]->state = READ_LE_UINT16(savedPtr2);
+		_vm->_goblin->goblins[i]->state = READ_LE_UINT16(savedPtr2);
 		savedPtr2 += 2;
 
 		if (i == 3)
-			gob_goblins[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 70);
+			_vm->_goblin->goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 70);
 		else
-			gob_goblins[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40);
+			_vm->_goblin->goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40);
 
-		// FIXME: All is wrong further. We should unwind calls to map_loadDataFromAvo()
-		map_loadDataFromAvo((char *)gob_goblins[i]->stateMach, 40 * szGob_StateLine);
-		map_avoDataPtr += 160;
-		gob_goblins[i]->multObjIndex = *map_avoDataPtr;
-		map_avoDataPtr += 2;
+		// FIXME: All is wrong further. We should unwind calls to loadDataFromAvo()
+		loadDataFromAvo((char *)_vm->_goblin->goblins[i]->stateMach, 40 * szGob_StateLine);
+		avoDataPtr += 160;
+		_vm->_goblin->goblins[i]->multObjIndex = *avoDataPtr;
+		avoDataPtr += 2;
 
-		gob_goblins[i]->realStateMach = gob_goblins[i]->stateMach;
+		_vm->_goblin->goblins[i]->realStateMach = _vm->_goblin->goblins[i]->stateMach;
 		for (state = 0; state < 40; state++) {
 			for (col = 0; col < 6; col++) {
-				if (gob_goblins[i]->stateMach[state][col] == 0)
+				if (_vm->_goblin->goblins[i]->stateMach[state][col] == 0)
 					continue;
 
-				Gob_State *tmpState = (Gob_State *)malloc(sizeof(Gob_State));
-				gob_goblins[i]->stateMach[state][col] = tmpState;
+				Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
+				_vm->_goblin->goblins[i]->stateMach[state][col] = tmpState;
 
-				tmpState->animation = map_loadFromAvo_LE_UINT16();
-				tmpState->layer = map_loadFromAvo_LE_UINT16();
-				map_avoDataPtr += 8;
-				tmpState->unk0 = map_loadFromAvo_LE_UINT16();
-				tmpState->unk1 = map_loadFromAvo_LE_UINT16();
+				tmpState->animation = loadFromAvo_LE_UINT16();
+				tmpState->layer = loadFromAvo_LE_UINT16();
+				avoDataPtr += 8;
+				tmpState->unk0 = loadFromAvo_LE_UINT16();
+				tmpState->unk1 = loadFromAvo_LE_UINT16();
 
-				map_avoDataPtr += 2;
-				if (READ_LE_UINT32(map_avoDataPtr) != 0) {
-					map_avoDataPtr += 4;
-					tmpState->sndItem = map_loadFromAvo_LE_UINT16();
+				avoDataPtr += 2;
+				if (READ_LE_UINT32(avoDataPtr) != 0) {
+					avoDataPtr += 4;
+					tmpState->sndItem = loadFromAvo_LE_UINT16();
 				} else {
-					map_avoDataPtr += 6;
+					avoDataPtr += 6;
 					tmpState->sndItem = -1;
 				}
-				tmpState->freq = map_loadFromAvo_LE_UINT16();
-				tmpState->repCount = map_loadFromAvo_LE_UINT16();
-				tmpState->sndFrame = map_loadFromAvo_LE_UINT16();
+				tmpState->freq = loadFromAvo_LE_UINT16();
+				tmpState->repCount = loadFromAvo_LE_UINT16();
+				tmpState->sndFrame = loadFromAvo_LE_UINT16();
 			}
 		}
 	}
 
-	pState = (Gob_State *)malloc(sizeof(Gob_State));
-	gob_goblins[0]->stateMach[39][0] = pState;
+	pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
+	_vm->_goblin->goblins[0]->stateMach[39][0] = pState;
 	pState->animation = 0;
 	pState->layer = 98;
 	pState->unk0 = 0;
 	pState->unk1 = 0;
 	pState->sndItem = -1;
 
-	pState = (Gob_State *) malloc(sizeof(Gob_State));
-	gob_goblins[1]->stateMach[39][0] = pState;
+	pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State));
+	_vm->_goblin->goblins[1]->stateMach[39][0] = pState;
 	pState->animation = 0;
 	pState->layer = 99;
 	pState->unk0 = 0;
 	pState->unk1 = 0;
 	pState->sndItem = -1;
 
-	pState = (Gob_State *) malloc(sizeof(Gob_State));
-	gob_goblins[2]->stateMach[39][0] = pState;
+	pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State));
+	_vm->_goblin->goblins[2]->stateMach[39][0] = pState;
 	pState->animation = 0;
 	pState->layer = 100;
 	pState->unk0 = 0;
 	pState->unk1 = 0;
 	pState->sndItem = -1;
 
-	gob_goblins[2]->stateMach[10][0]->sndFrame = 13;
-	gob_goblins[2]->stateMach[11][0]->sndFrame = 13;
-	gob_goblins[2]->stateMach[28][0]->sndFrame = 13;
-	gob_goblins[2]->stateMach[29][0]->sndFrame = 13;
+	_vm->_goblin->goblins[2]->stateMach[10][0]->sndFrame = 13;
+	_vm->_goblin->goblins[2]->stateMach[11][0]->sndFrame = 13;
+	_vm->_goblin->goblins[2]->stateMach[28][0]->sndFrame = 13;
+	_vm->_goblin->goblins[2]->stateMach[29][0]->sndFrame = 13;
 
-	gob_goblins[1]->stateMach[10][0]->sndFrame = 13;
-	gob_goblins[1]->stateMach[11][0]->sndFrame = 13;
+	_vm->_goblin->goblins[1]->stateMach[10][0]->sndFrame = 13;
+	_vm->_goblin->goblins[1]->stateMach[11][0]->sndFrame = 13;
 
 	for (state = 40; state < 70; state++) {
-		pState = (Gob_State *)malloc(sizeof(Gob_State));
-		gob_goblins[3]->stateMach[state][0] = pState;
-		gob_goblins[3]->stateMach[state][1] = 0;
+		pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
+		_vm->_goblin->goblins[3]->stateMach[state][0] = pState;
+		_vm->_goblin->goblins[3]->stateMach[state][1] = 0;
 
 		pState->animation = 9;
 		pState->layer = state - 40;
@@ -600,70 +610,70 @@
 		pState->sndFrame = 0;
 	}
 
-	gob_objCount = map_loadFromAvo_LE_UINT16();
-	for (i = 0; i < gob_objCount; i++) {
-		gob_objects[i] =
-		    (Gob_Object *) malloc(sizeof(Gob_Object));
+	_vm->_goblin->objCount = loadFromAvo_LE_UINT16();
+	for (i = 0; i < _vm->_goblin->objCount; i++) {
+		_vm->_goblin->objects[i] =
+		    (Goblin::Gob_Object *) malloc(sizeof(Goblin::Gob_Object));
 
-		gob_objects[i]->xPos = READ_LE_UINT16(savedPtr3);
+		_vm->_goblin->objects[i]->xPos = READ_LE_UINT16(savedPtr3);
 		savedPtr3 += 2;
 
-		gob_objects[i]->yPos = READ_LE_UINT16(savedPtr3);
+		_vm->_goblin->objects[i]->yPos = READ_LE_UINT16(savedPtr3);
 		savedPtr3 += 2;
 
-		gob_objects[i]->order = READ_LE_UINT16(savedPtr3);
+		_vm->_goblin->objects[i]->order = READ_LE_UINT16(savedPtr3);
 		savedPtr3 += 2;
 
-		gob_objects[i]->state = READ_LE_UINT16(savedPtr3);
+		_vm->_goblin->objects[i]->state = READ_LE_UINT16(savedPtr3);
 		savedPtr3 += 2;
 
-		gob_objects[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40);
+		_vm->_goblin->objects[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40);
 
-		map_loadDataFromAvo((char *)gob_objects[i]->stateMach, 40 * szGob_StateLine);
-		map_avoDataPtr += 160;
-		gob_objects[i]->multObjIndex = *map_avoDataPtr;
-		map_avoDataPtr += 2;
+		loadDataFromAvo((char *)_vm->_goblin->objects[i]->stateMach, 40 * szGob_StateLine);
+		avoDataPtr += 160;
+		_vm->_goblin->objects[i]->multObjIndex = *avoDataPtr;
+		avoDataPtr += 2;
 
-		gob_objects[i]->realStateMach = gob_objects[i]->stateMach;
+		_vm->_goblin->objects[i]->realStateMach = _vm->_goblin->objects[i]->stateMach;
 		for (state = 0; state < 40; state++) {
 			for (col = 0; col < 6; col++) {
-				if (gob_objects[i]->stateMach[state][col] == 0)
+				if (_vm->_goblin->objects[i]->stateMach[state][col] == 0)
 					continue;
 
-				Gob_State *tmpState = (Gob_State *)malloc(sizeof(Gob_State));
-				gob_objects[i]->stateMach[state][col] = tmpState;
+				Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
+				_vm->_goblin->objects[i]->stateMach[state][col] = tmpState;
 
-				tmpState->animation = map_loadFromAvo_LE_UINT16();
-				tmpState->layer = map_loadFromAvo_LE_UINT16();
-				map_avoDataPtr += 8;
-				tmpState->unk0 = map_loadFromAvo_LE_UINT16();
-				tmpState->unk1 = map_loadFromAvo_LE_UINT16();
+				tmpState->animation = loadFromAvo_LE_UINT16();
+				tmpState->layer = loadFromAvo_LE_UINT16();
+				avoDataPtr += 8;
+				tmpState->unk0 = loadFromAvo_LE_UINT16();
+				tmpState->unk1 = loadFromAvo_LE_UINT16();
 
-				map_avoDataPtr += 2;
-				if (READ_LE_UINT32(map_avoDataPtr) != 0) {
-					map_avoDataPtr += 4;
-					tmpState->sndItem = map_loadFromAvo_LE_UINT16();
+				avoDataPtr += 2;
+				if (READ_LE_UINT32(avoDataPtr) != 0) {
+					avoDataPtr += 4;
+					tmpState->sndItem = loadFromAvo_LE_UINT16();
 				} else {
-					map_avoDataPtr += 6;
+					avoDataPtr += 6;
 					tmpState->sndItem = -1;
 				}
-				tmpState->freq = map_loadFromAvo_LE_UINT16();
-				tmpState->repCount = map_loadFromAvo_LE_UINT16();
-				tmpState->sndFrame = map_loadFromAvo_LE_UINT16();
+				tmpState->freq = loadFromAvo_LE_UINT16();
+				tmpState->repCount = loadFromAvo_LE_UINT16();
+				tmpState->sndFrame = loadFromAvo_LE_UINT16();
 			}
 		}
 	}
 
-	gob_objects[10] = (Gob_Object *)malloc(sizeof(Gob_Object));
-	memset(gob_objects[10], 0, sizeof(Gob_Object));
+	_vm->_goblin->objects[10] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object));
+	memset(_vm->_goblin->objects[10], 0, sizeof(Goblin::Gob_Object));
 
-	gob_objects[10]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40);
-	memset(gob_objects[10]->stateMach, 0, szGob_StateLine * 40);
+	_vm->_goblin->objects[10]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40);
+	memset(_vm->_goblin->objects[10]->stateMach, 0, szGob_StateLine * 40);
 
-	pState = (Gob_State *)malloc(sizeof(Gob_State));
-	gob_objects[10]->stateMach[0][0] = pState;
+	pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
+	_vm->_goblin->objects[10]->stateMach[0][0] = pState;
 
-	memset(pState, 0, sizeof(Gob_State));
+	memset(pState, 0, sizeof(Goblin::Gob_State));
 	pState->animation = 9;
 	pState->layer = 27;
 	pState->unk0 = 0;
@@ -671,84 +681,84 @@
 	pState->sndItem = -1;
 	pState->sndFrame = 0;
 
-	gob_placeObject(gob_objects[10], 1);
+	_vm->_goblin->placeObject(_vm->_goblin->objects[10], 1);
 
-	gob_objects[10]->realStateMach = gob_objects[10]->stateMach;
-	gob_objects[10]->type = 1;
-	gob_objects[10]->unk14 = 1;
+	_vm->_goblin->objects[10]->realStateMach = _vm->_goblin->objects[10]->stateMach;
+	_vm->_goblin->objects[10]->type = 1;
+	_vm->_goblin->objects[10]->unk14 = 1;
 
-	state = map_loadFromAvo_LE_UINT16();
+	state = loadFromAvo_LE_UINT16();
 	for (i = 0; i < state; i++) {
-		map_avoDataPtr += 30;
+		avoDataPtr += 30;
 
-		map_loadDataFromAvo((char *)&flag, 4);
-		map_avoDataPtr += 56;
+		loadDataFromAvo((char *)&flag, 4);
+		avoDataPtr += 56;
 
 		if (flag != 0)
-			map_avoDataPtr += 30;
+			avoDataPtr += 30;
 	}
 
-	map_loadDataFromAvo((char *)&tmp, 2);
-	map_avoDataPtr += 48;
-	map_loadItemToObject();
-	map_avoDataPtr = savedPtr;
+	loadDataFromAvo((char *)&tmp, 2);
+	avoDataPtr += 48;
+	loadItemToObject();
+	avoDataPtr = savedPtr;
 
 	for (i = 0; i < soundCount; i++) {
-		map_loadDataFromAvo(buf, 14);
+		loadDataFromAvo(buf, 14);
 		strcat(buf, ".SND");
 		strcpy(sndNames[i], buf);
 	}
 
 	free(dataBuf);
 
-	gob_soundData[14] = snd_loadSoundData("diamant1.snd");
+	_vm->_goblin->soundData[14] = _vm->_snd->loadSoundData("diamant1.snd");
 
 	for (i = 0; i < soundCount; i++) {
-		handle = data_openData(sndNames[i]);
+		handle = _vm->_dataio->openData(sndNames[i]);
 		if (handle < 0)
 			continue;
 
-		data_closeData(handle);
-		gob_soundData[i] = snd_loadSoundData(sndNames[i]);
+		_vm->_dataio->closeData(handle);
+		_vm->_goblin->soundData[i] = _vm->_snd->loadSoundData(sndNames[i]);
 	}
 }
 
-void map_loadMapsInitGobs(void) {
+void Map::loadMapsInitGobs(void) {
 	int16 layer;
 	int16 i;
 
-	if (map_loadFromAvo == 0)
-		error("map_load: Loading .pas/.pos files is not supported!");
+	if (loadFromAvo == 0)
+		error("load: Loading .pas/.pos files is not supported!");
 
 	for (i = 0; i < 3; i++) {
-		gob_nextLayer(gob_goblins[i]);
+		_vm->_goblin->nextLayer(_vm->_goblin->goblins[i]);
 	}
 
 	for (i = 0; i < 3; i++) {
 
 		layer =
-		    gob_goblins[i]->stateMach[gob_goblins[i]->state][0]->layer;
+		    _vm->_goblin->goblins[i]->stateMach[_vm->_goblin->goblins[i]->state][0]->layer;
 
-		scen_updateAnim(layer, 0, gob_goblins[i]->animation, 0,
-		    gob_goblins[i]->xPos, gob_goblins[i]->yPos, 0);
+		_vm->_scenery->updateAnim(layer, 0, _vm->_goblin->goblins[i]->animation, 0,
+		    _vm->_goblin->goblins[i]->xPos, _vm->_goblin->goblins[i]->yPos, 0);
 
-		gob_goblins[i]->yPos = (gob_gobPositions[i].y + 1) * 6 -
-		    (scen_toRedrawBottom - scen_animTop);
+		_vm->_goblin->goblins[i]->yPos = (_vm->_goblin->gobPositions[i].y + 1) * 6 -
+		    (_vm->_scenery->toRedrawBottom - _vm->_scenery->animTop);
 
-		gob_goblins[i]->xPos = gob_gobPositions[i].x * 12 -
-		    (scen_toRedrawLeft - scen_animLeft);
+		_vm->_goblin->goblins[i]->xPos = _vm->_goblin->gobPositions[i].x * 12 -
+		    (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft);
 
-		gob_goblins[i]->order = scen_toRedrawBottom / 24 + 3;
+		_vm->_goblin->goblins[i]->order = _vm->_scenery->toRedrawBottom / 24 + 3;
 	}
 
-	gob_currentGoblin = 0;
-	gob_pressedMapX = gob_gobPositions[0].x;
-	gob_pressedMapY = gob_gobPositions[0].y;
-	gob_pathExistence = 0;
+	_vm->_goblin->currentGoblin = 0;
+	_vm->_goblin->pressedMapX = _vm->_goblin->gobPositions[0].x;
+	_vm->_goblin->pressedMapY = _vm->_goblin->gobPositions[0].y;
+	_vm->_goblin->pathExistence = 0;
 
-	gob_goblins[0]->doAnim = 0;
-	gob_goblins[1]->doAnim = 1;
-	gob_goblins[2]->doAnim = 1;
+	_vm->_goblin->goblins[0]->doAnim = 0;
+	_vm->_goblin->goblins[1]->doAnim = 1;
+	_vm->_goblin->goblins[2]->doAnim = 1;
 }
 
 }				// End of namespace Gob

Index: map.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/map.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- map.h	30 Dec 2005 18:41:19 -0000	1.11
+++ map.h	3 Jan 2006 23:14:39 -0000	1.12
@@ -26,66 +26,77 @@
 
 // The same numeric values are also used for the arrow keys.
 
-enum {
-	kDirNW = 0x4700,
-	kDirN  = 0x4800,
-	kDirNE = 0x4900,
-	kDirW  = 0x4b00,
-	kDirE  = 0x4d00,
-	kDirSW = 0x4f00,
-	kDirS  = 0x5000,
-	kDirSE = 0x5100
-};
+class Map {
+public:
+	enum {
+		kDirNW = 0x4700,
+		kDirN  = 0x4800,
+		kDirNE = 0x4900,
+		kDirW  = 0x4b00,
+		kDirE  = 0x4d00,
+		kDirSW = 0x4f00,
+		kDirS  = 0x5000,
+		kDirSE = 0x5100
+	};
+	enum {
+		kMapWidth  = 26,
+		kMapHeight = 28
+	};
 
 #pragma START_PACK_STRUCTS
 
-typedef struct Map_Point {
-	int16 x;
-	int16 y;
-} GCC_PACK Map_Point;
+	typedef struct Point {
+		int16 x;
+		int16 y;
+	} GCC_PACK Point;
 
 #define szMap_ItemPos 3
 
- typedef struct Map_ItemPos {
-	int8 x;
-	int8 y;
-	int8 orient;		// ??
-} GCC_PACK Map_ItemPos;
+	typedef struct ItemPos {
+		int8 x;
+		int8 y;
+		int8 orient;		// ??
+	} GCC_PACK ItemPos;
 
 #pragma END_PACK_STRUCTS
 
-enum {
-	kMapWidth  = 26,
-	kMapHeight = 28
-};
+	int8 passMap[kMapHeight][kMapWidth];	// [y][x]
+	int16 itemsMap[kMapHeight][kMapWidth];	// [y][x]
+	Point wayPoints[40];
+	int16 nearestWayPoint;
+	int16 nearestDest;
 
-extern int8 map_passMap[kMapHeight][kMapWidth];	// [y][x]
-extern int16 map_itemsMap[kMapHeight][kMapWidth];	// [y][x]
-extern Map_Point map_wayPoints[40];
-extern int16 map_nearestWayPoint;
-extern int16 map_nearestDest;
+   	int16 curGoblinX;
+	int16 curGoblinY;
+	int16 destX;
+	int16 destY;
+	int8 loadFromAvo;
 
-extern int16 map_curGoblinX;
-extern int16 map_curGoblinY;
-extern int16 map_destX;
-extern int16 map_destY;
-extern int8 map_loadFromAvo;
+	ItemPos itemPoses[40];
+	char sourceFile[15];
 
-extern Map_ItemPos map_itemPoses[40];
-extern char map_sourceFile[15];
+	void placeItem(int16 x, int16 y, int16 id);
 
-void map_placeItem(int16 x, int16 y, int16 id);
+	int16 getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
+	void findNearestToGob(void);
+	void findNearestToDest(void);
+	int16 checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1);
+	int16 checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1);
+	void optimizePoints(void);
+	void loadItemToObject(void);
+	void loadMapObjects(char *avjFile);
+	void loadDataFromAvo(char *dest, int16 size);
+	void loadMapsInitGobs(void);
 
-int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
-void map_findNearestToGob(void);
-void map_findNearestToDest(void);
-int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1);
-int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1);
-void map_optimizePoints(void);
-void map_loadItemToObject(void);
-void map_loadMapObjects(char *avjFile);
-void map_loadDataFromAvo(int8 *dest, int16 size);
-void map_loadMapsInitGobs(void);
+	Map(GobEngine *vm);
+
+protected:
+	char *avoDataPtr;
+	GobEngine *_vm;
+
+	int16 findNearestWayPoint(int16 x, int16 y);
+	uint16 loadFromAvo_LE_UINT16();
+};
 
 }				// End of namespace Gob
 

Index: mult.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/mult.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mult.cpp	18 Oct 2005 01:30:17 -0000	1.13
+++ mult.cpp	3 Jan 2006 23:14:39 -0000	1.14
@@ -35,73 +35,85 @@
 
 namespace Gob {
 
-Mult_Object *mult_objects;
-int16 *mult_renderData;
-int16 mult_objCount;
-int16 mult_frame;
-
-char *mult_multData;
-char mult_doPalSubst;
-int16 mult_counter;
[...1644 lines suppressed...]
-			vid_freeSurfDesc(anim_underAnimSurf);
-		anim_underAnimSurf = 0;
+		if (_vm->_anim->_animSurf)
+			_vm->_video->freeSurfDesc(_vm->_anim->_animSurf);
+		_vm->_anim->_animSurf = 0;
 
-		mult_animDataAllocated = 0;
+		animDataAllocated = 0;
 	}
 }
 
-void mult_checkFreeMult(void) {
-	if (mult_multData != 0)
-		mult_freeMultKeys();
+void Mult::checkFreeMult(void) {
+	if (multData != 0)
+		freeMultKeys();
 }
 
 }				// End of namespace Gob

Index: mult.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/mult.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mult.h	18 Oct 2005 01:30:17 -0000	1.6
+++ mult.h	3 Jan 2006 23:14:39 -0000	1.7
@@ -26,171 +26,182 @@
 
 namespace Gob {
 
+class Mult {
+public:
 #pragma START_PACK_STRUCTS
-typedef struct Mult_AnimData {
-	int8 animation;
-	int8 layer;
-	int8 frame;
-	int8 animType;
-	int8 order;
-	int8 isPaused;
-	int8 isStatic;
-	int8 maxTick;
-	int8 unknown;
-	int8 newLayer;
-	int8 newAnimation;
-	byte intersected;
-	int8 newCycle;
-} GCC_PACK Mult_AnimData;
+	typedef struct Mult_AnimData {
+		int8 animation;
+		int8 layer;
+		int8 frame;
+		int8 animType;
+		int8 order;
+		int8 isPaused;
+		int8 isStatic;
+		int8 maxTick;
+		int8 unknown;
+		int8 newLayer;
+		int8 newAnimation;
+		byte intersected;
+		int8 newCycle;
+	} GCC_PACK Mult_AnimData;
 
-typedef struct Mult_Object {
-	int32 *pPosX;
-	int32 *pPosY;
-	Mult_AnimData *pAnimData;
-	int16 tick;
-	int16 lastLeft;
-	int16 lastRight;
-	int16 lastTop;
-	int16 lastBottom;
-} Mult_Object;
+	typedef struct Mult_Object {
+		int32 *pPosX;
+		int32 *pPosY;
+		Mult_AnimData *pAnimData;
+		int16 tick;
+		int16 lastLeft;
+		int16 lastRight;
+		int16 lastTop;
+		int16 lastBottom;
+	} Mult_Object;
 
-// Mult
-typedef struct Mult_StaticKey {
-	int16 frame;
-	int16 layer;
-} GCC_PACK Mult_StaticKey;
+	// Mult
+	typedef struct Mult_StaticKey {
+		int16 frame;
+		int16 layer;
+	} GCC_PACK Mult_StaticKey;
 
-typedef struct Mult_AnimKey {
-	int16 frame;
-	int16 layer;
-	int16 posX;
-	int16 posY;
-	int16 order;
-} GCC_PACK Mult_AnimKey;
+	typedef struct Mult_AnimKey {
+		int16 frame;
+		int16 layer;
+		int16 posX;
+		int16 posY;
+		int16 order;
+	} GCC_PACK Mult_AnimKey;
 
-typedef struct Mult_TextKey {
-	int16 frame;
-	int16 cmd;
-	int16 unknown0[9];
-	int16 index;
-	int16 unknown1[2];
-} GCC_PACK Mult_TextKey;
+	typedef struct Mult_TextKey {
+		int16 frame;
+		int16 cmd;
+		int16 unknown0[9];
+		int16 index;
+		int16 unknown1[2];
+	} GCC_PACK Mult_TextKey;
 
-typedef struct Mult_PalKey {
-	int16 frame;
-	int16 cmd;
-	int16 rates[4];
-	int16 unknown0;
-	int16 unknown1;
-	int8 subst[16][4];
-} GCC_PACK Mult_PalKey;
+	typedef struct Mult_PalKey {
+		int16 frame;
+		int16 cmd;
+		int16 rates[4];
+		int16 unknown0;
+		int16 unknown1;
+		int8 subst[16][4];
+	} GCC_PACK Mult_PalKey;
 
-typedef struct Mult_PalFadeKey {
-	int16 frame;
-	int16 fade;
-	int16 palIndex;
-	int8 flag;
-} GCC_PACK Mult_PalFadeKey;
+	typedef struct Mult_PalFadeKey {
+		int16 frame;
+		int16 fade;
+		int16 palIndex;
+		int8 flag;
+	} GCC_PACK Mult_PalFadeKey;
 
-typedef struct Mult_SndKey {
-	int16 frame;
-	int16 cmd;
-	int16 freq;
-	int16 channel;
-	int16 repCount;
-	int16 resId;
-	int16 soundIndex;
-} GCC_PACK Mult_SndKey;
+	typedef struct Mult_SndKey {
+		int16 frame;
+		int16 cmd;
+		int16 freq;
+		int16 channel;
+		int16 repCount;
+		int16 resId;
+		int16 soundIndex;
+	} GCC_PACK Mult_SndKey;
 #pragma END_PACK_STRUCTS
 
-// Globals
+	// Globals
 
-extern Mult_Object *mult_objects;
-extern int16 *mult_renderData;
-extern int16 mult_objCount;
-extern SurfaceDesc *mult_underAnimSurf;
+	Mult_Object *objects;
+	int16 *renderData;
+	int16 objCount;
+	Video::SurfaceDesc *underAnimSurf;
 
-extern char *mult_multData;
-extern int16 mult_frame;
-extern char mult_doPalSubst;
-extern int16 mult_counter;
-extern int16 mult_frameRate;
+	char *multData;
+	int16 frame;
+	char doPalSubst;
+	int16 counter;
+	int16 frameRate;
 
-extern int32 *mult_animArrayX;
-extern int32 *mult_animArrayY;
+	int32 *animArrayX;
+	int32 *animArrayY;
 
-extern Mult_AnimData *mult_animArrayData;
+	Mult_AnimData *animArrayData;
 
-extern int16 mult_index;
+	int16 index;
 
-// Static keys
-extern int16 mult_staticKeysCount;
-extern Mult_StaticKey *mult_staticKeys;
-extern int16 mult_staticIndices[10];
+	// Static keys
+	int16 staticKeysCount;
+	Mult_StaticKey *staticKeys;
+	int16 staticIndices[10];
 
-// Anim keys
-extern Mult_AnimKey *mult_animKeys[4];
-extern int16 mult_animKeysCount[4];
-extern int16 mult_animLayer;
-extern int16 mult_animIndices[10];
+	// Anim keys
+	Mult_AnimKey *animKeys[4];
+	int16 animKeysCount[4];
+	int16 animLayer;
+	int16 animIndices[10];
 
-// Text keys
-extern int16 mult_textKeysCount;
-extern Mult_TextKey *mult_textKeys;
+	// Text keys
+	int16 textKeysCount;
+	Mult_TextKey *textKeys;
 
-extern int16 mult_frameStart;
+	int16 frameStart;
 
-// Palette keys
-extern int16 mult_palKeyIndex;
-extern int16 mult_palKeysCount;
-extern Mult_PalKey *mult_palKeys;
-extern Color *mult_oldPalette;
-extern Color mult_palAnimPalette[256];
-extern int16 mult_palAnimKey;
-extern int16 mult_palAnimIndices[4];
-extern int16 mult_palAnimRed[4];
-extern int16 mult_palAnimGreen[4];
-extern int16 mult_palAnimBlue[4];
+	// Palette keys
+	int16 palKeyIndex;
+	int16 palKeysCount;
+	Mult_PalKey *palKeys;
+	Video::Color *oldPalette;
+	Video::Color palAnimPalette[256];
+	int16 palAnimKey;
+	int16 palAnimIndices[4];
+	int16 palAnimRed[4];
+	int16 palAnimGreen[4];
+	int16 palAnimBlue[4];
 
-// Palette fading
-extern Mult_PalFadeKey *mult_palFadeKeys;
-extern int16 mult_palFadeKeysCount;
-extern char mult_palFadingRed;
-extern char mult_palFadingGreen;
-extern char mult_palFadingBlue;
+	// Palette fading
+	Mult_PalFadeKey *palFadeKeys;
+	int16 palFadeKeysCount;
+	char palFadingRed;
+	char palFadingGreen;
+	char palFadingBlue;
 
-extern char mult_animDataAllocated;
+	char animDataAllocated;
 
-extern char *mult_dataPtr;
-extern int16 mult_staticLoaded[10];
-extern int16 mult_animLoaded[10];
-extern int16 mult_sndSlotsCount;
+	char *dataPtr;
+	int16 staticLoaded[10];
+	int16 animLoaded[10];
+	int16 sndSlotsCount;
 
-// Sound keys
-extern int16 mult_sndKeysCount;
-extern Mult_SndKey *mult_sndKeys;
+	// Sound keys
+	int16 sndKeysCount;
+	Mult_SndKey *sndKeys;
 
-void mult_zeroMultData(void);
-void mult_loadMult(int16 resId);
-void mult_freeMultKeys(void);
-void mult_checkFreeMult(void);
-void mult_playMult(int16 startFrame, int16 endFrame, char checkEscape,
-    char handleMouse);
-void mult_animate(void);
-void mult_interGetObjAnimSize(void);
-void mult_interInitMult(void);
-void mult_freeMult(void);
-void mult_interLoadMult(void);
-void mult_freeAll(void);
-void mult_initAll(void);
-void mult_playSound(Snd_SoundDesc * soundDesc, int16 repCount, int16 freq,
-    int16 channel);
-void mult_playMult(int16 startFrame, int16 endFrame, char checkEscape,
-    char handleMouse);
-void mult_zeroMultData(void);
-void mult_loadMult(int16 resId);
-void mult_freeMultKeys(void);
-void mult_checkFreeMult(void);
+	void zeroMultData(void);
+	void loadMult(int16 resId);
+	void freeMultKeys(void);
+	void checkFreeMult(void);
+	void playMult(int16 startFrame, int16 endFrame, char checkEscape,
+				  char handleMouse);
+	void animate(void);
+	void interGetObjAnimSize(void);
+	void interInitMult(void);
+	void freeMult(void);
+	void interLoadMult(void);
+	void freeAll(void);
+	void initAll(void);
+	void playSound(Snd::SoundDesc * soundDesc, int16 repCount, int16 freq,
+				   int16 channel);
+
+	Mult(GobEngine *vm);
+
+protected:
+	Video::Color fadePal[5][16];
+	GobEngine *_vm;
+
+	char drawStatics(char stop);
+	void drawAnims(void);
+	void drawText(char *pStop, char *pStopNoClear);
+	char prepPalAnim(char stop);
+	void doPalAnim(void);
+	char doFadeAnim(char stop);
+	char doSoundAnim(char stop);
+};
 
 }				// End of namespace Gob
 

Index: pack.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/pack.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- pack.cpp	18 Oct 2005 01:30:17 -0000	1.6
+++ pack.cpp	3 Jan 2006 23:14:39 -0000	1.7
@@ -24,7 +24,7 @@
 
 namespace Gob {
 
-int32 unpackData(char *sourceBuf, char *destBuf) {
+int32 Pack::unpackData(char *sourceBuf, char *destBuf) {
 	uint32 realSize;
 	uint32 counter;
 	uint16 cmd;

Index: pack.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/pack.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pack.h	18 Oct 2005 01:30:17 -0000	1.4
+++ pack.h	3 Jan 2006 23:14:39 -0000	1.5
@@ -24,8 +24,11 @@
 
 namespace Gob {
 
-int32 asm_unpackData(char *source, char *dest, char *temp);
-int32 unpackData(char *source, char *dest);
+class Pack {
+public:
+	int32 asm_unpackData(char *source, char *dest, char *temp);
+	int32 unpackData(char *source, char *dest);
+};
 
 }				// End of namespace Gob
 

Index: palanim.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/palanim.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- palanim.cpp	18 Oct 2005 01:30:17 -0000	1.11
+++ palanim.cpp	3 Jan 2006 23:14:39 -0000	1.12
@@ -27,74 +27,77 @@
 
 namespace Gob {
 
-int16 pal_fadeValue = 1;
-
-byte pal_toFadeRed[256];
-byte pal_toFadeGreen[256];
-byte pal_toFadeBlue[256];
+PalAnim::PalAnim(GobEngine *vm) : _vm(vm) {
+	fadeValue = 1;
+	for (int i = 0; i < 256; i++) {
+		toFadeRed[i] = 0;
+		toFadeGreen[i] = 0;
+		toFadeBlue[i] = 0;
+	}
+}
 
-char pal_fadeColor(char from, char to) {
-	if ((int16)from - pal_fadeValue > (int16)to)
-		return from - pal_fadeValue;
-	else if ((int16)from + pal_fadeValue < (int16)to)
-		return from + pal_fadeValue;
+char PalAnim::fadeColor(char from, char to) {
+	if ((int16)from - fadeValue > (int16)to)
+		return from - fadeValue;
+	else if ((int16)from + fadeValue < (int16)to)
+		return from + fadeValue;
 	else
 		return to;
 }
 
-char pal_fadeStep(int16 oper) {
+char PalAnim::fadeStep(int16 oper) {
 	byte newRed;
 	byte newGreen;
 	byte newBlue;
 	char stop;
 	int16 i;
 
-	if (colorCount != 256)
-		error("pal_fadeStep: Only 256 color mode is supported!");
+	if (_vm->_global->colorCount != 256)
+		error("fadeStep: Only 256 color mode is supported!");
 
 	if (oper == 0) {
 		stop = 1;
-		if (setAllPalette) {
-			if (inVM != 0)
-				error("pal_fade: inVM != 0 not supported.");
+		if (_vm->_global->setAllPalette) {
+			if (_vm->_global->inVM != 0)
+				error("fade: _vm->_global->inVM != 0 not supported.");
 
 			for (i = 0; i < 256; i++) {
 				newRed =
-				    pal_fadeColor(redPalette[i],
-				    pal_toFadeRed[i]);
+				    fadeColor(_vm->_global->redPalette[i],
+				    toFadeRed[i]);
 				newGreen =
-				    pal_fadeColor(greenPalette[i],
-				    pal_toFadeGreen[i]);
+				    fadeColor(_vm->_global->greenPalette[i],
+				    toFadeGreen[i]);
 				newBlue =
-				    pal_fadeColor(bluePalette[i],
-				    pal_toFadeBlue[i]);
+				    fadeColor(_vm->_global->bluePalette[i],
+				    toFadeBlue[i]);
 
-				if (redPalette[i] != newRed
-				    || greenPalette[i] != newGreen
-				    || bluePalette[i] != newBlue) {
+				if (_vm->_global->redPalette[i] != newRed
+				    || _vm->_global->greenPalette[i] != newGreen
+				    || _vm->_global->bluePalette[i] != newBlue) {
 
-					vid_setPalElem(i, newRed, newGreen, newBlue, 0, 0x13);
+					_vm->_video->setPalElem(i, newRed, newGreen, newBlue, 0, 0x13);
 
-					redPalette[i] = newRed;
-					greenPalette[i] = newGreen;
-					bluePalette[i] = newBlue;
+					_vm->_global->redPalette[i] = newRed;
+					_vm->_global->greenPalette[i] = newGreen;
+					_vm->_global->bluePalette[i] = newBlue;
 					stop = 0;
 				}
 			}
 		} else {
 			for (i = 0; i < 16; i++) {
 
-				vid_setPalElem(i,
-				    pal_fadeColor(redPalette[i],
-					pal_toFadeRed[i]),
-				    pal_fadeColor(greenPalette[i],
-					pal_toFadeGreen[i]),
-				    pal_fadeColor(bluePalette[i],
-					pal_toFadeBlue[i]), -1, videoMode);
+				_vm->_video->setPalElem(i,
+				    fadeColor(_vm->_global->redPalette[i],
+					toFadeRed[i]),
+				    fadeColor(_vm->_global->greenPalette[i],
+					toFadeGreen[i]),
+				    fadeColor(_vm->_global->bluePalette[i],
+					toFadeBlue[i]), -1, _vm->_global->videoMode);
 
-				if (redPalette[i] != pal_toFadeRed[i] ||
-				    greenPalette[i] != pal_toFadeGreen[i] ||
-				    bluePalette[i] != pal_toFadeBlue[i])
+				if (_vm->_global->redPalette[i] != toFadeRed[i] ||
+				    _vm->_global->greenPalette[i] != toFadeGreen[i] ||
+				    _vm->_global->bluePalette[i] != toFadeBlue[i])
 					stop = 0;
 			}
 		}
@@ -102,36 +105,36 @@
 	} else if (oper == 1) {
 		stop = 1;
 		for (i = 0; i < 16; i++) {
-			vid_setPalElem(i,
-			    pal_fadeColor(redPalette[i], pal_toFadeRed[i]),
-			    greenPalette[i], bluePalette[i], -1, videoMode);
+			_vm->_video->setPalElem(i,
+			    fadeColor(_vm->_global->redPalette[i], toFadeRed[i]),
+			    _vm->_global->greenPalette[i], _vm->_global->bluePalette[i], -1, _vm->_global->videoMode);
 
-			if (redPalette[i] != pal_toFadeRed[i])
+			if (_vm->_global->redPalette[i] != toFadeRed[i])
 				stop = 0;
 		}
 		return stop;
 	} else if (oper == 2) {
 		stop = 1;
 		for (i = 0; i < 16; i++) {
-			vid_setPalElem(i,
-			    redPalette[i],
-			    pal_fadeColor(greenPalette[i], pal_toFadeGreen[i]),
-			    bluePalette[i], -1, videoMode);
+			_vm->_video->setPalElem(i,
+			    _vm->_global->redPalette[i],
+			    fadeColor(_vm->_global->greenPalette[i], toFadeGreen[i]),
+			    _vm->_global->bluePalette[i], -1, _vm->_global->videoMode);
 
-			if (greenPalette[i] != pal_toFadeGreen[i])
+			if (_vm->_global->greenPalette[i] != toFadeGreen[i])
 				stop = 0;
 		}
 		return stop;
 	} else if (oper == 3) {
 		stop = 1;
 		for (i = 0; i < 16; i++) {
-			vid_setPalElem(i,
-			    redPalette[i],
-			    greenPalette[i],
-			    pal_fadeColor(bluePalette[i], pal_toFadeBlue[i]),
-			    -1, videoMode);
+			_vm->_video->setPalElem(i,
+			    _vm->_global->redPalette[i],
+			    _vm->_global->greenPalette[i],
+			    fadeColor(_vm->_global->bluePalette[i], toFadeBlue[i]),
+			    -1, _vm->_global->videoMode);
 
-			if (bluePalette[i] != pal_toFadeBlue[i])
+			if (_vm->_global->bluePalette[i] != toFadeBlue[i])
 				stop = 0;
 		}
 		return stop;
@@ -139,95 +142,95 @@
 	return 1;
 }
 
-void pal_fade(PalDesc *palDesc, int16 fade, int16 allColors) {
+void PalAnim::fade(Video::PalDesc *palDesc, int16 fadeV, int16 allColors) {
 	char stop;
 	int16 i;
 
-	if (fade < 0)
-		pal_fadeValue = -fade;
+	if (fadeV < 0)
+		fadeValue = -fadeV;
 	else
-		pal_fadeValue = 2;
+		fadeValue = 2;
 
-	if (colorCount < 256) {
+	if (_vm->_global->colorCount < 256) {
 		if (palDesc != 0)
-			vid_setFullPalette(palDesc);
+			_vm->_video->setFullPalette(palDesc);
 		return;
 	}
 
-	if (setAllPalette == 0) {
+	if (_vm->_global->setAllPalette == 0) {
 		if (palDesc == 0) {
 			for (i = 0; i < 16; i++) {
-				pal_toFadeRed[i] = 0;
-				pal_toFadeGreen[i] = 0;
-				pal_toFadeBlue[i] = 0;
+				toFadeRed[i] = 0;
+				toFadeGreen[i] = 0;
+				toFadeBlue[i] = 0;
 			}
 		} else {
 			for (i = 0; i < 16; i++) {
-				pal_toFadeRed[i] = palDesc->vgaPal[i].red;
-				pal_toFadeGreen[i] = palDesc->vgaPal[i].green;
-				pal_toFadeBlue[i] = palDesc->vgaPal[i].blue;
+				toFadeRed[i] = palDesc->vgaPal[i].red;
+				toFadeGreen[i] = palDesc->vgaPal[i].green;
+				toFadeBlue[i] = palDesc->vgaPal[i].blue;
 			}
 		}
 	} else {
-		if (inVM != 0)
-			error("pal_fade: inVM != 0 is not supported");
+		if (_vm->_global->inVM != 0)
+			error("fade: _vm->_global->inVM != 0 is not supported");
 
 		if (palDesc == 0) {
 			for (i = 0; i < 256; i++) {
-				pal_toFadeRed[i] = 0;
-				pal_toFadeGreen[i] = 0;
-				pal_toFadeBlue[i] = 0;
+				toFadeRed[i] = 0;
+				toFadeGreen[i] = 0;
+				toFadeBlue[i] = 0;
 			}
 		} else {
 			for (i = 0; i < 256; i++) {
-				pal_toFadeRed[i] = palDesc->vgaPal[i].red;
-				pal_toFadeGreen[i] = palDesc->vgaPal[i].green;
-				pal_toFadeBlue[i] = palDesc->vgaPal[i].blue;
+				toFadeRed[i] = palDesc->vgaPal[i].red;
+				toFadeGreen[i] = palDesc->vgaPal[i].green;
+				toFadeBlue[i] = palDesc->vgaPal[i].blue;
 			}
 		}
 	}
 
 	if (allColors == 0) {
 		do {
-			if (tmpPalBuffer == 0)
-				vid_waitRetrace(videoMode);
+			if (_vm->_global->tmpPalBuffer == 0)
+				_vm->_video->waitRetrace(_vm->_global->videoMode);
 
-			stop = pal_fadeStep(0);
+			stop = fadeStep(0);
 
-			if (fade > 0)
-				util_delay(fade);
+			if (fadeV > 0)
+				_vm->_util->delay(fadeV);
 		} while (stop == 0);
 
 		if (palDesc != 0)
-			vid_setFullPalette(palDesc);
+			_vm->_video->setFullPalette(palDesc);
 		else
-			util_clearPalette();
+			_vm->_util->clearPalette();
 	}
 
 	if (allColors == 1) {
 		do {
-			vid_waitRetrace(videoMode);
-			stop = pal_fadeStep(1);
+			_vm->_video->waitRetrace(_vm->_global->videoMode);
+			stop = fadeStep(1);
 		} while (stop == 0);
 
 		do {
-			vid_waitRetrace(videoMode);
-			stop = pal_fadeStep(2);
+			_vm->_video->waitRetrace(_vm->_global->videoMode);
+			stop = fadeStep(2);
 		} while (stop == 0);
 
 		do {
-			vid_waitRetrace(videoMode);
-			stop = pal_fadeStep(3);
+			_vm->_video->waitRetrace(_vm->_global->videoMode);
+			stop = fadeStep(3);
 		} while (stop == 0);
 
 		if (palDesc != 0)
-			vid_setFullPalette(palDesc);
+			_vm->_video->setFullPalette(palDesc);
 		else
-			util_clearPalette();
+			_vm->_util->clearPalette();
 	}
 
-	free(tmpPalBuffer);
-	tmpPalBuffer = 0;
+	free(_vm->_global->tmpPalBuffer);
+	_vm->_global->tmpPalBuffer = 0;
 }
 
 }				// End of namespace Gob

Index: palanim.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/palanim.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- palanim.h	18 Oct 2005 01:30:17 -0000	1.4
+++ palanim.h	3 Jan 2006 23:14:39 -0000	1.5
@@ -24,11 +24,22 @@
 
 namespace Gob {
 
-extern int16 pal_fadeValue;
+class PalAnim {
+public:
+	int16 fadeValue;
 
-char pal_fadeColor(char from, char to);
-char pal_fadeStep(int16 oper);	// oper == 0 - fade all colors, 1, 2, 3 - red,green, blue
-void pal_fade(PalDesc * palDesc, int16 fade, int16 all);
+	char fadeColor(char from, char to);
+	char fadeStep(int16 oper);	// oper == 0 - fade all colors, 1, 2, 3 - red,green, blue
+	void fade(Video::PalDesc * palDesc, int16 fade, int16 all);
+
+	PalAnim(GobEngine *vm);
+
+protected:
+	byte toFadeRed[256];
+	byte toFadeGreen[256];
+	byte toFadeBlue[256];
+	GobEngine *_vm;
+};
 
 }				// End of namespace Gob
 

Index: parse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/parse.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- parse.cpp	18 Oct 2005 01:30:17 -0000	1.15
+++ parse.cpp	3 Jan 2006 23:14:39 -0000	1.16
@@ -28,24 +28,21 @@
 
 namespace Gob {
 
-enum PointerType {
-	kExecPtr = 0,
-	kInterVar = 1,
-	kResStr = 2
-};
+Parse::Parse(GobEngine *vm) : _vm(vm) {
+}
 
-int32 encodePtr(char *ptr, int type) {
+int32 Parse::encodePtr(char *ptr, int type) {
 	int32 offset;
 
 	switch (type) {
 	case kExecPtr:
-		offset = ptr - game_totFileData;
+		offset = ptr - _vm->_game->totFileData;
 		break;
 	case kInterVar:
-		offset = ptr - inter_variables;
+		offset = ptr - _vm->_global->inter_variables;
 		break;
 	case kResStr:
-		offset = ptr - inter_resStr;
+		offset = ptr - _vm->_global->inter_resStr;
 		break;
 	default:
 		error("encodePtr: Unknown pointer type");
@@ -54,18 +51,18 @@
 	return (type << 28) | offset;
 }
 
-char *decodePtr(int32 n) {
+char *Parse::decodePtr(int32 n) {
 	char *ptr;
 
 	switch (n >> 28) {
 	case kExecPtr:
-		ptr = game_totFileData;
+		ptr = _vm->_game->totFileData;
 		break;
 	case kInterVar:
-		ptr = inter_variables;
+		ptr = _vm->_global->inter_variables;
 		break;
 	case kResStr:
-		ptr = inter_resStr;
+		ptr = _vm->_global->inter_resStr;
 		break;
 	default:
 		error("decodePtr: Unknown pointer type");
@@ -73,7 +70,7 @@
 	return ptr + (n & 0x0FFFFFFF);
 }
 
-int16 parse_parseExpr(char arg_0, byte *arg_2) {
+int16 Parse::parseExpr(char arg_0, byte *arg_2) {
 	int32 values[20];
 	byte operStack[20];
 	int32 prevPrevVal;
@@ -101,54 +98,54 @@
 		stkPos++;
 		operPtr++;
 		valPtr++;
-		operation = *inter_execPtr++;
+		operation = *_vm->_global->inter_execPtr++;
 		if (operation >= 19 && operation <= 29) {
 			switch (operation) {
 			case 19:
 				*operPtr = 20;
-				*valPtr = READ_LE_UINT32(inter_execPtr);
-				inter_execPtr += 4;
+				*valPtr = READ_LE_UINT32(_vm->_global->inter_execPtr);
+				_vm->_global->inter_execPtr += 4;
 				break;
 
 			case 20:
 				*operPtr = 20;
-				*valPtr = inter_load16();
+				*valPtr = _vm->_inter->load16();
 				break;
 
 			case 22:
 				*operPtr = 22;
-				*valPtr = encodePtr(inter_execPtr, kExecPtr);
-				inter_execPtr += strlen(inter_execPtr) + 1;
+				*valPtr = encodePtr(_vm->_global->inter_execPtr, kExecPtr);
+				_vm->_global->inter_execPtr += strlen(_vm->_global->inter_execPtr) + 1;
 				break;
 
 			case 23:
 				*operPtr = 20;
-				*valPtr = VAR(inter_load16());
+				*valPtr = VAR(_vm->_inter->load16());
 				break;
 
 			case 25:
 				*operPtr = 22;
-				temp = inter_load16() * 4;
-				*valPtr = encodePtr(inter_variables + temp, kInterVar);
-				if (*inter_execPtr == 13) {
-					inter_execPtr++;
-					temp += parse_parseValExpr();
+				temp = _vm->_inter->load16() * 4;
+				*valPtr = encodePtr(_vm->_global->inter_variables + temp, kInterVar);
+				if (*_vm->_global->inter_execPtr == 13) {
+					_vm->_global->inter_execPtr++;
+					temp += parseValExpr();
 					*operPtr = 20;
-					*valPtr = (uint8)*(inter_variables + temp);
+					*valPtr = (uint8)*(_vm->_global->inter_variables + temp);
 				}
 				break;
 
 			case 26:
 			case 28:
 				*operPtr = operation - 6;
-				temp = inter_load16();
-				dimCount = *inter_execPtr++;
-				arrDescPtr = (byte *)inter_execPtr;
-				inter_execPtr += dimCount;
+				temp = _vm->_inter->load16();
+				dimCount = *_vm->_global->inter_execPtr++;
+				arrDescPtr = (byte *)_vm->_global->inter_execPtr;
+				_vm->_global->inter_execPtr += dimCount;
 				offset = 0;
 				dim = 0;
 				for (dim = 0; dim < dimCount; dim++) {
-					temp2 = parse_parseValExpr();
+					temp2 = parseValExpr();
 					offset = offset * arrDescPtr[dim] + temp2;
 				}
 
@@ -156,22 +153,22 @@
 					*valPtr = VAR(temp + offset);
 					break;
 				}
-				*valPtr = encodePtr(inter_variables + temp * 4 + offset * inter_animDataSize * 4, kInterVar);
-				if (*inter_execPtr == 13) {
-					inter_execPtr++;
-					temp2 = parse_parseValExpr();
+				*valPtr = encodePtr(_vm->_global->inter_variables + temp * 4 + offset * _vm->_global->inter_animDataSize * 4, kInterVar);
+				if (*_vm->_global->inter_execPtr == 13) {
+					_vm->_global->inter_execPtr++;
+					temp2 = parseValExpr();
 					*operPtr = 20;
-					*valPtr = (uint8)*(inter_variables + temp * 4 + offset * 4 * inter_animDataSize + temp2);
+					*valPtr = (uint8)*(_vm->_global->inter_variables + temp * 4 + offset * 4 * _vm->_global->inter_animDataSize + temp2);
 				}
 				break;
 
 			case 29:
-				operation = *inter_execPtr++;
-				parse_parseExpr(10, 0);
+				operation = *_vm->_global->inter_execPtr++;
+				parseExpr(10, 0);
 
 				switch (operation) {
 				case 5:
-					inter_resVal = inter_resVal * inter_resVal;
+					_vm->_global->inter_resVal = _vm->_global->inter_resVal * _vm->_global->inter_resVal;
 					break;
 
 				case 0:
@@ -183,22 +180,22 @@
 					do {
 						prevPrevVal = prevVal;
 						prevVal = curVal;
-						curVal = (curVal + inter_resVal / curVal) / 2;
+						curVal = (curVal + _vm->_global->inter_resVal / curVal) / 2;
 					} while (curVal != prevVal && curVal != prevPrevVal);
-					inter_resVal = curVal;
+					_vm->_global->inter_resVal = curVal;
 					break;
 
 				case 10:
-					inter_resVal = util_getRandom(inter_resVal);
+					_vm->_global->inter_resVal = _vm->_util->getRandom(_vm->_global->inter_resVal);
 					break;
 
 				case 7:
-					if (inter_resVal < 0)
-						inter_resVal = -inter_resVal;
+					if (_vm->_global->inter_resVal < 0)
+						_vm->_global->inter_resVal = -_vm->_global->inter_resVal;
 					break;
 				}
 				*operPtr = 20;
-				*valPtr = inter_resVal;
+				*valPtr = _vm->_global->inter_resVal;
 			}
 
 			if (stkPos > 0 && (operPtr[-1] == 1 || operPtr[-1] == 11)) {
@@ -223,11 +220,11 @@
 			switch (operPtr[-1]) {
 			case 2:
 				if (operPtr[-2] == 22) {
-					if (decodePtr(valPtr[-2]) != inter_resStr) {
-						strcpy(inter_resStr, decodePtr(valPtr[-2]));
-						valPtr[-2] = encodePtr(inter_resStr, kResStr);
+					if (decodePtr(valPtr[-2]) != _vm->_global->inter_resStr) {
+						strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-2]));
+						valPtr[-2] = encodePtr(_vm->_global->inter_resStr, kResStr);
 					}
-					strcat(inter_resStr, decodePtr(valPtr[0]));
+					strcat(_vm->_global->inter_resStr, decodePtr(valPtr[0]));
 					stkPos -= 2;
 					operPtr -= 2;
 					valPtr -= 2;
@@ -343,11 +340,11 @@
 					if (operStack[brackStart] == 20) {
 						values[brackStart] += valPtr[-1];
 					} else if (operStack[brackStart] == 22) {
-						if (decodePtr(values[brackStart]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(values[brackStart]));
-							values[brackStart] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(values[brackStart]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(values[brackStart]));
+							values[brackStart] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						strcat(inter_resStr, decodePtr(valPtr[-1]));
+						strcat(_vm->_global->inter_resStr, decodePtr(valPtr[-1]));
 					}
 					stkPos -= 2;
 					operPtr -= 2;
@@ -419,11 +416,11 @@
 						if (valPtr[-3] < valPtr[-1])
 							operPtr[-3] = 24;
 					} else if (var_C == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						if (strcmp(inter_resStr, decodePtr(valPtr[-1])) < 0)
+						if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) < 0)
 							operPtr[-3] = 24;
 					}
 					stkPos -= 2;
@@ -438,11 +435,11 @@
 						if (valPtr[-3] <= valPtr[-1])
 							operPtr[-3] = 24;
 					} else if (var_C == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						if (strcmp(inter_resStr, decodePtr(valPtr[-1])) <= 0)
+						if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) <= 0)
 							operPtr[-3] = 24;
 					}
 					stkPos -= 2;
@@ -457,11 +454,11 @@
 						if (valPtr[-3] > valPtr[-1])
 							operPtr[-3] = 24;
 					} else if (var_C == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						if (strcmp(inter_resStr, decodePtr(valPtr[-1])) > 0)
+						if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) > 0)
 							operPtr[-3] = 24;
 					}
 					stkPos -= 2;
@@ -476,11 +473,11 @@
 						if (valPtr[-3] >= valPtr[-1])
 							operPtr[-3] = 24;
 					} else if (var_C == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						if (strcmp(inter_resStr, decodePtr(valPtr[-1])) >= 0)
+						if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) >= 0)
 							operPtr[-3] = 24;
 					}
 					stkPos -= 2;
@@ -495,11 +492,11 @@
 						if (valPtr[-3] == valPtr[-1])
 							operPtr[-3] = 24;
 					} else if (var_C == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						if (strcmp(inter_resStr, decodePtr(valPtr[-1])) == 0)
+						if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) == 0)
 							operPtr[-3] = 24;
 					}
 					stkPos -= 2;
@@ -514,11 +511,11 @@
 						if (valPtr[-3] != valPtr[-1])
 							operPtr[-3] = 24;
 					} else if (var_C == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						if (strcmp(inter_resStr, decodePtr(valPtr[-1])) != 0)
+						if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) != 0)
 							operPtr[-3] = 24;
 					}
 					stkPos -= 2;
@@ -546,15 +543,15 @@
 				if ((operation == 30 && operPtr[-1] == 24) ||
 				    (operation == 31 && operPtr[-1] == 23)) {
 					if (stkPos > 1 && operPtr[-2] == 9) {
-						parse_skipExpr(10);
+						skipExpr(10);
 						operPtr[-2] = operPtr[-1];
 						stkPos -= 2;
 						operPtr -= 2;
 						valPtr -= 2;
 					} else {
-						parse_skipExpr(arg_0);
+						skipExpr(arg_0);
 					}
-					operation = inter_execPtr[-1];
+					operation = _vm->_global->inter_execPtr[-1];
 					if (stkPos > 0 && operPtr[-1] == 11) {
 						if (operPtr[0] == 23)
 							operPtr[-1] = 24;
@@ -581,12 +578,12 @@
 
 			switch (operStack[0]) {
 			case 20:
-				inter_resVal = values[0];
+				_vm->_global->inter_resVal = values[0];
 				break;
 
 			case 22:
-				if (decodePtr(values[0]) != inter_resStr)
-					strcpy(inter_resStr, decodePtr(values[0]));
+				if (decodePtr(values[0]) != _vm->_global->inter_resStr)
+					strcpy(_vm->_global->inter_resStr, decodePtr(values[0]));
 				break;
 
 			case 11:
@@ -599,7 +596,7 @@
 				break;
 
 			default:
-				inter_resVal = 0;
+				_vm->_global->inter_resVal = 0;
 				if (arg_2 != 0)
 					*arg_2 = 20;
 				break;
@@ -616,11 +613,11 @@
 					if (operPtr[-3] == 20) {
 						valPtr[-3] += valPtr[-1];
 					} else if (operPtr[-3] == 22) {
-						if (decodePtr(valPtr[-3]) != inter_resStr) {
-							strcpy(inter_resStr, decodePtr(valPtr[-3]));
-							valPtr[-3] = encodePtr(inter_resStr, kResStr);
+						if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) {
+							strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3]));
+							valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr);
 						}
-						strcat(inter_resStr, decodePtr(valPtr[-1]));
+						strcat(_vm->_global->inter_resStr, decodePtr(valPtr[-1]));
 					}
 					stkPos -= 2;
 					operPtr -= 2;
@@ -643,7 +640,7 @@
 	}
 }
 
-void parse_skipExpr(char arg_0) {
+void Parse::skipExpr(char arg_0) {
 	int16 dimCount;
 	char operation;
 	int16 num;
@@ -651,47 +648,47 @@
 
 	num = 0;
 	while (1) {
-		operation = *inter_execPtr++;
+		operation = *_vm->_global->inter_execPtr++;
 
 		if (operation >= 19 && operation <= 29) {
 			switch (operation) {
 			case 20:
 			case 23:
-				inter_execPtr += 2;
+				_vm->_global->inter_execPtr += 2;
 				break;
 
 			case 19:
-				inter_execPtr += 4;
+				_vm->_global->inter_execPtr += 4;
 				break;
 
 			case 22:
-				inter_execPtr += strlen(inter_execPtr) + 1;
+				_vm->_global->inter_execPtr += strlen(_vm->_global->inter_execPtr) + 1;
 				break;
 
 			case 25:
-				inter_execPtr += 2;
-				if (*inter_execPtr == 13) {
-					inter_execPtr++;
-					parse_skipExpr(12);
+				_vm->_global->inter_execPtr += 2;
+				if (*_vm->_global->inter_execPtr == 13) {
+					_vm->_global->inter_execPtr++;
+					skipExpr(12);
 				}
 				break;
 
 			case 26:
 			case 28:
-				dimCount = inter_execPtr[2];
-				inter_execPtr += 3 + dimCount;	// ???
+				dimCount = _vm->_global->inter_execPtr[2];
+				_vm->_global->inter_execPtr += 3 + dimCount;	// ???
 				for (dim = 0; dim < dimCount; dim++)
-					parse_skipExpr(12);
+					skipExpr(12);
 
-				if (operation == 28 && *inter_execPtr == 13) {
-					inter_execPtr++;
-					parse_skipExpr(12);
+				if (operation == 28 && *_vm->_global->inter_execPtr == 13) {
+					_vm->_global->inter_execPtr++;
+					skipExpr(12);
 				}
 				break;
 
 			case 29:
-				inter_execPtr++;
-				parse_skipExpr(10);
+				_vm->_global->inter_execPtr++;
+				skipExpr(10);
 			}
 			continue;
 		}		// if (operation >= 19 && operation <= 29)
@@ -718,7 +715,7 @@
 	}
 }
 
-int16 parse_parseValExpr() {
+int16 Parse::parseValExpr() {
 	int16 values[20];
 	byte operStack[20];
 	int16 *valPtr;
@@ -738,7 +735,7 @@
 	oldflag = flag;
 	if (flag == 0) {
 		flag = 1;
-		parse_printExpr(99);
+		printExpr(99);
 	}
 
 	stkPos = -1;
@@ -750,63 +747,63 @@
 		operPtr++;
 		valPtr++;
 
-		operation = *inter_execPtr++;
+		operation = *_vm->_global->inter_execPtr++;
 		if (operation >= 19 && operation <= 29) {
 			*operPtr = 20;
 			switch (operation) {
 			case 19:
-				*valPtr = READ_LE_UINT32(inter_execPtr);
-				inter_execPtr += 4;
+				*valPtr = READ_LE_UINT32(_vm->_global->inter_execPtr);
+				_vm->_global->inter_execPtr += 4;
 				break;
 
 			case 20:
-				*valPtr = inter_load16();
+				*valPtr = _vm->_inter->load16();
 				break;
 
 			case 23:
-				*valPtr = (uint16)VAR(inter_load16());
+				*valPtr = (uint16)VAR(_vm->_inter->load16());
 				break;
 
 			case 25:
-				temp = inter_load16() * 4;
-				inter_execPtr++;
-				temp += parse_parseValExpr();
-				*valPtr = (uint8)*(inter_variables + temp);
+				temp = _vm->_inter->load16() * 4;
+				_vm->_global->inter_execPtr++;
+				temp += parseValExpr();
+				*valPtr = (uint8)*(_vm->_global->inter_variables + temp);
 				break;
 
 			case 26:
 			case 28:
-				temp = inter_load16();
-				dimCount = *inter_execPtr++;
-				arrDesc = (byte*)inter_execPtr;
-				inter_execPtr += dimCount;
+				temp = _vm->_inter->load16();
+				dimCount = *_vm->_global->inter_execPtr++;
+				arrDesc = (byte*)_vm->_global->inter_execPtr;
+				_vm->_global->inter_execPtr += dimCount;
 				offset = 0;
 				for (dim = 0; dim < dimCount; dim++) {
-					temp2 = parse_parseValExpr();
+					temp2 = parseValExpr();
 					offset = arrDesc[dim] * offset + temp2;
 				}
 				if (operation == 26) {
 					*valPtr = (uint16)VAR(temp + offset);
 				} else {
-					inter_execPtr++;
-					temp2 = parse_parseValExpr();
-					*valPtr = (uint8)*(inter_variables + temp * 4 + offset * 4 * inter_animDataSize + temp2);
+					_vm->_global->inter_execPtr++;
+					temp2 = parseValExpr();
+					*valPtr = (uint8)*(_vm->_global->inter_variables + temp * 4 + offset * 4 * _vm->_global->inter_animDataSize + temp2);
 				}
 				break;
 
 			case 29:
-				operation = *inter_execPtr++;
-				parse_parseExpr(10, 0);
+				operation = *_vm->_global->inter_execPtr++;
+				parseExpr(10, 0);
 
 				if (operation == 5) {
-					inter_resVal = inter_resVal * inter_resVal;
+					_vm->_global->inter_resVal = _vm->_global->inter_resVal * _vm->_global->inter_resVal;
 				} else if (operation == 7) {
-					if (inter_resVal < 0)
-						inter_resVal = -inter_resVal;
+					if (_vm->_global->inter_resVal < 0)
+						_vm->_global->inter_resVal = -_vm->_global->inter_resVal;
 				} else if (operation == 10) {
-					inter_resVal = util_getRandom(inter_resVal);
+					_vm->_global->inter_resVal = _vm->_util->getRandom(_vm->_global->inter_resVal);
 				}
-				*valPtr = inter_resVal;
+				*valPtr = _vm->_global->inter_resVal;
 				break;
 
 			}	// switch
@@ -943,7 +940,7 @@
 	}
 }
 
-int16 parse_parseVarIndex() {
+int16 Parse::parseVarIndex() {
 	int16 temp2;
 	char *arrDesc;
 	int16 dim;
@@ -953,16 +950,16 @@
 	int16 offset;
 	int16 val;
 
-	operation = *inter_execPtr++;
+	operation = *_vm->_global->inter_execPtr++;
 	debug(5, "var parse = %d", operation);
 	switch (operation) {
 	case 23:
 	case 25:
-		temp = inter_load16() * 4;
-		debug(5, "oper = %d", (int16)*inter_execPtr);
-		if (operation == 25 && *inter_execPtr == 13) {
-			inter_execPtr++;
-			val = parse_parseValExpr();
+		temp = _vm->_inter->load16() * 4;
+		debug(5, "oper = %d", (int16)*_vm->_global->inter_execPtr);
+		if (operation == 25 && *_vm->_global->inter_execPtr == 13) {
+			_vm->_global->inter_execPtr++;
+			val = parseValExpr();
 			temp += val;
 			debug(5, "parse subscript = %d", val);
 		}
@@ -970,31 +967,31 @@
 
 	case 26:
 	case 28:
-		temp = inter_load16() * 4;
-		dimCount = *inter_execPtr++;
-		arrDesc = inter_execPtr;
-		inter_execPtr += dimCount;
+		temp = _vm->_inter->load16() * 4;
+		dimCount = *_vm->_global->inter_execPtr++;
+		arrDesc = _vm->_global->inter_execPtr;
+		_vm->_global->inter_execPtr += dimCount;
 		offset = 0;
 		for (dim = 0; dim < dimCount; dim++) {
-			temp2 = parse_parseValExpr();
+			temp2 = parseValExpr();
 			offset = arrDesc[dim] * offset + temp2;
 		}
 		offset *= 4;
 		if (operation != 28)
 			return temp + offset;
 
-		if (*inter_execPtr == 13) {
-			inter_execPtr++;
-			temp += parse_parseValExpr();
+		if (*_vm->_global->inter_execPtr == 13) {
+			_vm->_global->inter_execPtr++;
+			temp += parseValExpr();
 		}
-		return offset * inter_animDataSize + temp;
+		return offset * _vm->_global->inter_animDataSize + temp;
 
 	default:
 		return 0;
 	}
 }
 
-void parse_printExpr(char arg_0) {
+void Parse::printExpr(char arg_0) {
 	int16 dimCount;
 	char operation;
 	int16 num;
@@ -1009,40 +1006,40 @@
 	return;
 
 	if (savedPos == 0) {
-		savedPos = inter_execPtr;
+		savedPos = _vm->_global->inter_execPtr;
 		saved = 1;
 	}
 
 	num = 0;
 	while (1) {
-		operation = *inter_execPtr++;
+		operation = *_vm->_global->inter_execPtr++;
 
 		if (operation >= 19 && operation <= 29) {
 			switch (operation) {
 			case 19:
-				debug(5, "%l", READ_LE_UINT32(inter_execPtr));
-				inter_execPtr += 4;
+				debug(5, "%l", READ_LE_UINT32(_vm->_global->inter_execPtr));
+				_vm->_global->inter_execPtr += 4;
 				break;
 
 			case 20:
-				debug(5, "%d", inter_load16());
+				debug(5, "%d", _vm->_inter->load16());
 				break;
 
 			case 22:
-				debug(5, "\42%s\42", inter_execPtr);
-				inter_execPtr += strlen(inter_execPtr) + 1;
+				debug(5, "\42%s\42", _vm->_global->inter_execPtr);
+				_vm->_global->inter_execPtr += strlen(_vm->_global->inter_execPtr) + 1;
 				break;
 
 			case 23:
-				debug(5, "var_%d", inter_load16());
+				debug(5, "var_%d", _vm->_inter->load16());
 				break;
 
 			case 25:
-				debug(5, "(&var_%d)", inter_load16());
-				if (*inter_execPtr == 13) {
-					inter_execPtr++;
+				debug(5, "(&var_%d)", _vm->_inter->load16());
+				if (*_vm->_global->inter_execPtr == 13) {
+					_vm->_global->inter_execPtr++;
 					debug(5, "{");
-					parse_printExpr(12);
+					printExpr(12);
 //                  debug(5, "}");
 				}
 				break;
@@ -1052,12 +1049,12 @@
 				if (operation == 28)
 					debug(5, "(&");
 
-				debug(5, "var_%d[", inter_load16());
-				dimCount = *inter_execPtr++;
-				arrDesc = inter_execPtr;
-				inter_execPtr += dimCount;
+				debug(5, "var_%d[", _vm->_inter->load16());
+				dimCount = *_vm->_global->inter_execPtr++;
+				arrDesc = _vm->_global->inter_execPtr;
+				_vm->_global->inter_execPtr += dimCount;
 				for (dim = 0; dim < dimCount; dim++) {
-					parse_printExpr(12);
+					printExpr(12);
 					debug(5, " of %d", (int16)arrDesc[dim]);
 					if (dim != dimCount - 1)
 						debug(5, ",");
@@ -1066,16 +1063,16 @@
 				if (operation == 28)
 					debug(5, ")");
 
-				if (operation == 28 && *inter_execPtr == 13) {
-					inter_execPtr++;
+				if (operation == 28 && *_vm->_global->inter_execPtr == 13) {
+					_vm->_global->inter_execPtr++;
 					debug(5, "{");
-					parse_printExpr(12);
+					printExpr(12);
 //                  debug(5, "}");
 				}
 				break;
 
 			case 29:
-				func = *inter_execPtr++;
+				func = *_vm->_global->inter_execPtr++;
 				if (func == 5)
 					debug(5, "sqr(");
 				else if (func == 10)
@@ -1086,7 +1083,7 @@
 					debug(5, "sqrt(");
 				else
 					debug(5, "id(");
-				parse_printExpr(10);
+				printExpr(10);
 				break;
 
 			case 12:
@@ -1207,7 +1204,7 @@
 			if (arg_0 != 10 || num < 0) {
 
 				if (saved != 0) {
-					inter_execPtr = savedPos;
+					_vm->_global->inter_execPtr = savedPos;
 					savedPos = 0;
 				}
 				return;
@@ -1216,46 +1213,46 @@
 	}
 }
 
-void parse_printVarIndex() {
+void Parse::printVarIndex() {
 	char *arrDesc;
 	int16 dim;
 	int16 dimCount;
 	int16 operation;
 	int16 temp;
 
-	char *pos = inter_execPtr;
+	char *pos = _vm->_global->inter_execPtr;
 
-	operation = *inter_execPtr++;
+	operation = *_vm->_global->inter_execPtr++;
 	switch (operation) {
 	case 23:
 	case 25:
-		temp = inter_load16() * 4;
+		temp = _vm->_inter->load16() * 4;
 		debug(5, "&var_%d", temp);
-		if (operation == 25 && *inter_execPtr == 13) {
-			inter_execPtr++;
+		if (operation == 25 && *_vm->_global->inter_execPtr == 13) {
+			_vm->_global->inter_execPtr++;
 			debug(5, "+");
-			parse_printExpr(99);
+			printExpr(99);
 		}
 		break;
 
 	case 26:
 	case 28:
-		debug(5, "&var_%d[", inter_load16());
-		dimCount = *inter_execPtr++;
-		arrDesc = inter_execPtr;
-		inter_execPtr += dimCount;
+		debug(5, "&var_%d[", _vm->_inter->load16());
+		dimCount = *_vm->_global->inter_execPtr++;
+		arrDesc = _vm->_global->inter_execPtr;
+		_vm->_global->inter_execPtr += dimCount;
 		for (dim = 0; dim < dimCount; dim++) {
-			parse_printExpr(12);
+			printExpr(12);
 			debug(5, " of %d", (int16)arrDesc[dim]);
 			if (dim != dimCount - 1)
 				debug(5, ",");
 		}
 		debug(5, "]");
 
-		if (operation == 28 && *inter_execPtr == 13) {
-			inter_execPtr++;
+		if (operation == 28 && *_vm->_global->inter_execPtr == 13) {
+			_vm->_global->inter_execPtr++;
 			debug(5, "+");
-			parse_printExpr(99);
+			printExpr(99);
 		}
 		break;
 
@@ -1264,7 +1261,7 @@
 		break;
 	}
 	debug(5, "\n");
-	inter_execPtr = pos;
+	_vm->_global->inter_execPtr = pos;
 	return;
 }
 

Index: parse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/parse.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- parse.h	18 Oct 2005 01:30:17 -0000	1.4
+++ parse.h	3 Jan 2006 23:14:39 -0000	1.5
@@ -24,12 +24,29 @@
 
 namespace Gob {
 
-int16 parse_parseExpr(char stopToken, byte *resultPtr);
-void parse_skipExpr(char stopToken);
-int16 parse_parseValExpr(void);
-int16 parse_parseVarIndex(void);
-void parse_printExpr(char stopToken);
-void parse_printVarIndex(void);
+class Parse {
+public:
+	int16 parseExpr(char stopToken, byte *resultPtr);
+	void skipExpr(char stopToken);
+	int16 parseValExpr(void);
+	int16 parseVarIndex(void);
+	void printExpr(char stopToken);
+	void printVarIndex(void);
+	
+	Parse(GobEngine *vm);
+
+protected:
+	enum PointerType {
+		kExecPtr = 0,
+		kInterVar = 1,
+		kResStr = 2
+	};
+
+	GobEngine *_vm;
+
+	int32 encodePtr(char *ptr, int type);
+	char *decodePtr(int32 n);
+};
 
 }				// End of namespace Gob
 

Index: scenery.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/scenery.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- scenery.cpp	18 Oct 2005 01:30:17 -0000	1.20
+++ scenery.cpp	3 Jan 2006 23:14:39 -0000	1.21
@@ -33,35 +33,39 @@
 
 namespace Gob {
 
-int16 scen_spriteResId[20];
-char scen_spriteRefs[20];
-
-Scen_Static scen_statics[10];
-int16 scen_staticPictCount[10];
-char scen_staticFromExt[10];
-int16 scen_staticResId[10];
-char scen_staticPictToSprite[70];
-
-Scen_Animation scen_animations[10];
-int16 scen_animPictCount[10];
-char scen_animFromExt[10];
-int16 scen_animResId[10];
-char scen_animPictToSprite[70];
+Scenery::Scenery(GobEngine *vm) : _vm(vm) {
+	for (int i = 0; i < 20; i++) {
+		spriteRefs[i] = 0;
+		spriteResId[i] = 0;
+	}
+	for (int i = 0; i < 70; i++ ) {
+		staticPictToSprite[i] = 0;
+		animPictToSprite[i] = 0;
+	}
+	for (int i = 0; i < 10; i++) {
+		staticPictCount[i] = 0;
+		staticFromExt[i] = 0;
+		staticResId[i] = 0;
+		animPictCount[i] = 0;
+		animFromExt[i] = 0;
+		animResId[i] = 0;
+	}
 
-int16 scen_curStatic;
-int16 scen_curStaticLayer;
+	curStatic = 0;
+	curStaticLayer = 0;
 
-int16 scen_toRedrawLeft;
-int16 scen_toRedrawRight;
-int16 scen_toRedrawTop;
-int16 scen_toRedrawBottom;
+	toRedrawLeft = 0;
+	toRedrawRight = 0;
+	toRedrawTop = 0;
+	toRedrawBottom = 0;
 
-int16 scen_animTop;
-int16 scen_animLeft;
+	animTop = 0;
+	animLeft = 0;
 
-int16 *scen_pCaptureCounter;
+	pCaptureCounter = 0;
+}
 
-int16 scen_loadStatic(char search) {
+int16 Scenery::loadStatic(char search) {
 	int16 tmp;
 	int16 *backsPtr;
 	int16 picsCount;
@@ -69,7 +73,7 @@
 	int16 i;
 	int16 sceneryIndex;
 	char *dataPtr;
-	Scen_Static *ptr;
+	Static *ptr;
 	int16 offset;
 	int16 pictDescId;
 	int16 width;
@@ -77,48 +81,48 @@
 	int16 sprResId;
 	int16 sprIndex;
 
-	inter_evalExpr(&sceneryIndex);
-	tmp = inter_load16();
-	backsPtr = (int16 *)inter_execPtr;
-	inter_execPtr += tmp * 2;
-	picsCount = inter_load16();
-	resId = inter_load16();
+	_vm->_inter->evalExpr(&sceneryIndex);
+	tmp = _vm->_inter->load16();
+	backsPtr = (int16 *)_vm->_global->inter_execPtr;
+	_vm->_global->inter_execPtr += tmp * 2;
+	picsCount = _vm->_inter->load16();
+	resId = _vm->_inter->load16();
 	if (search) {
 		for (i = 0; i < 10; i++) {
-			if (scen_staticPictCount[i] != -1 && scen_staticResId[i] == resId) {
-				inter_execPtr += 8 * scen_staticPictCount[i];
+			if (staticPictCount[i] != -1 && staticResId[i] == resId) {
+				_vm->_global->inter_execPtr += 8 * staticPictCount[i];
 				return i;
 			}
 
-			if (scen_staticPictCount[i] == -1 && i < sceneryIndex)
+			if (staticPictCount[i] == -1 && i < sceneryIndex)
 				sceneryIndex = i;
 		}
 	}
 
-	scen_staticPictCount[sceneryIndex] = picsCount;
-	scen_staticResId[sceneryIndex] = resId;
+	staticPictCount[sceneryIndex] = picsCount;
+	staticResId[sceneryIndex] = resId;
 
 	if (resId >= 30000) {
-		scen_staticFromExt[sceneryIndex] = 1;
-		dataPtr = game_loadExtData(resId, 0, 0);
+		staticFromExt[sceneryIndex] = 1;
+		dataPtr = _vm->_game->loadExtData(resId, 0, 0);
 	} else {
-		scen_staticFromExt[sceneryIndex] = 0;
-		dataPtr = game_loadTotResource(resId);
+		staticFromExt[sceneryIndex] = 0;
+		dataPtr = _vm->_game->loadTotResource(resId);
 	}
 
-	ptr = &scen_statics[sceneryIndex];
+	ptr = &statics[sceneryIndex];
 	ptr->dataPtr = dataPtr;
 
 	ptr->layersCount = (int16)READ_LE_UINT16(dataPtr);
 	dataPtr += 2;
 
-	ptr->layers = (Scen_StaticLayer **)malloc(sizeof(Scen_StaticLayer *) * ptr->layersCount);
-	ptr->pieces = (Scen_PieceDesc **)malloc(sizeof(Scen_PieceDesc *) * picsCount);
+	ptr->layers = (StaticLayer **)malloc(sizeof(StaticLayer *) * ptr->layersCount);
+	ptr->pieces = (PieceDesc **)malloc(sizeof(PieceDesc *) * picsCount);
 	ptr->piecesFromExt = (int8 *)malloc(picsCount);
 
 	for (i = 0; i < ptr->layersCount; i++) {
 		offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]);
-		ptr->layers[i] = (Scen_StaticLayer *)(dataPtr + offset - 2);
+		ptr->layers[i] = (StaticLayer *)(dataPtr + offset - 2);
 
 		ptr->layers[i]->planeCount = (int16)READ_LE_UINT16(&ptr->layers[i]->planeCount);
 
@@ -132,91 +136,91 @@
 	}
 
 	for (i = 0; i < picsCount; i++) {
-		pictDescId = inter_load16();
+		pictDescId = _vm->_inter->load16();
 		if (pictDescId >= 30000) {
 			ptr->pieces[i] =
-			    (Scen_PieceDesc *) game_loadExtData(pictDescId, 0,
+			    (PieceDesc *) _vm->_game->loadExtData(pictDescId, 0,
 			    0);
 			ptr->piecesFromExt[i] = 1;
 		} else {
 			ptr->pieces[i] =
-			    (Scen_PieceDesc *)
-			    game_loadTotResource(pictDescId);
+			    (PieceDesc *)
+			    _vm->_game->loadTotResource(pictDescId);
 			ptr->piecesFromExt[i] = 0;
 		}
 
-		width = inter_load16();
-		height = inter_load16();
-		sprResId = inter_load16();
+		width = _vm->_inter->load16();
+		height = _vm->_inter->load16();
+		sprResId = _vm->_inter->load16();
 		for (sprIndex = 0; sprIndex < 20; sprIndex++) {
-			if (scen_spriteResId[sprIndex] == sprResId)
+			if (spriteResId[sprIndex] == sprResId)
 				break;
 		}
 
 		if (sprIndex < 20) {
-			scen_staticPictToSprite[7 * sceneryIndex + i] =
+			staticPictToSprite[7 * sceneryIndex + i] =
 			    sprIndex;
-			scen_spriteRefs[sprIndex]++;
+			spriteRefs[sprIndex]++;
 		} else {
-			for (sprIndex = 19; draw_spritesArray[sprIndex] != 0;
+			for (sprIndex = 19; _vm->_draw->spritesArray[sprIndex] != 0;
 			    sprIndex--);
 
-			scen_staticPictToSprite[7 * sceneryIndex + i] =
+			staticPictToSprite[7 * sceneryIndex + i] =
 			    sprIndex;
-			scen_spriteRefs[sprIndex] = 1;
-			scen_spriteResId[sprIndex] = sprResId;
-			draw_spritesArray[sprIndex] =
-			    vid_initSurfDesc(videoMode, width, height, 2);
+			spriteRefs[sprIndex] = 1;
+			spriteResId[sprIndex] = sprResId;
+			_vm->_draw->spritesArray[sprIndex] =
+			    _vm->_video->initSurfDesc(_vm->_global->videoMode, width, height, 2);
 
-			vid_clearSurf(draw_spritesArray[sprIndex]);
-			draw_destSurface = sprIndex;
-			draw_spriteLeft = sprResId;
-			draw_transparency = 0;
-			draw_destSpriteX = 0;
-			draw_destSpriteY = 0;
-			draw_spriteOperation(DRAW_LOADSPRITE);
+			_vm->_video->clearSurf(_vm->_draw->spritesArray[sprIndex]);
+			_vm->_draw->destSurface = sprIndex;
+			_vm->_draw->spriteLeft = sprResId;
+			_vm->_draw->transparency = 0;
+			_vm->_draw->destSpriteX = 0;
+			_vm->_draw->destSpriteY = 0;
+			_vm->_draw->spriteOperation(DRAW_LOADSPRITE);
 		}
 	}
 	return sceneryIndex + 100;
 }
 
-void scen_freeStatic(int16 index) {
+void Scenery::freeStatic(int16 index) {
 	int16 i;
 	int16 spr;
 
 	if (index == -1)
-		inter_evalExpr(&index);
+		_vm->_inter->evalExpr(&index);
 
-	if (scen_staticPictCount[index] == -1)
+	if (staticPictCount[index] == -1)
 		return;
 
-	for (i = 0; i < scen_staticPictCount[index]; i++) {
-		if (scen_statics[index].piecesFromExt[i] == 1)
-			free(scen_statics[index].pieces[i]);
+	for (i = 0; i < staticPictCount[index]; i++) {
+		if (statics[index].piecesFromExt[i] == 1)
+			free(statics[index].pieces[i]);
 
-		spr = scen_staticPictToSprite[index * 7 + i];
-		scen_spriteRefs[spr]--;
-		if (scen_spriteRefs[spr] == 0) {
-			vid_freeSurfDesc(draw_spritesArray[spr]);
-			draw_spritesArray[spr] = 0;
-			scen_spriteResId[spr] = -1;
+		spr = staticPictToSprite[index * 7 + i];
+		spriteRefs[spr]--;
+		if (spriteRefs[spr] == 0) {
+			_vm->_video->freeSurfDesc(_vm->_draw->spritesArray[spr]);
+			_vm->_draw->spritesArray[spr] = 0;
+			spriteResId[spr] = -1;
 		}
 	}
 
-	free(scen_statics[index].layers);
-	free(scen_statics[index].pieces);
-	free(scen_statics[index].piecesFromExt);
-	if (scen_staticFromExt[index] == 1)
-		free(scen_statics[index].dataPtr);
+	free(statics[index].layers);
+	free(statics[index].pieces);
+	free(statics[index].piecesFromExt);
+	if (staticFromExt[index] == 1)
+		free(statics[index].dataPtr);
 
-	scen_staticFromExt[index] = 0;
-	scen_staticPictCount[index] = -1;
+	staticFromExt[index] = 0;
+	staticPictCount[index] = -1;
 }
 
-void scen_renderStatic(int16 scenery, int16 layer) {
-	Scen_Static *ptr;
-	Scen_StaticLayer *layerPtr;
-	Scen_StaticPlane *planePtr;
+void Scenery::renderStatic(int16 scenery, int16 layer) {
+	Static *ptr;
+	StaticLayer *layerPtr;
+	StaticPlane *planePtr;
 	int16 planeCount;
 	int16 order;
 	int16 plane;
@@ -229,19 +233,19 @@
 	int16 top;
 	int16 bottom;
 
-	ptr = &scen_statics[scenery];
+	ptr = &statics[scenery];
 	if (layer >= ptr->layersCount)
 		return;
 
 	layerPtr = ptr->layers[layer];
 
-	draw_spriteLeft = layerPtr->backResId;
-	if (draw_spriteLeft != -1) {
-		draw_destSpriteX = 0;
-		draw_destSpriteY = 0;
-		draw_destSurface = 21;
-		draw_transparency = 0;
-		draw_spriteOperation(DRAW_LOADSPRITE);
+	_vm->_draw->spriteLeft = layerPtr->backResId;
+	if (_vm->_draw->spriteLeft != -1) {
+		_vm->_draw->destSpriteX = 0;
+		_vm->_draw->destSpriteY = 0;
+		_vm->_draw->destSurface = 21;
+		_vm->_draw->transparency = 0;
+		_vm->_draw->spriteOperation(DRAW_LOADSPRITE);
 	}
 
 	planeCount = layerPtr->planeCount;
@@ -254,44 +258,44 @@
 			pieceIndex = planePtr->pieceIndex;
 			pictIndex = planePtr->pictIndex - 1;
 
-			draw_destSpriteX = planePtr->destX;
-			draw_destSpriteY = planePtr->destY;
+			_vm->_draw->destSpriteX = planePtr->destX;
+			_vm->_draw->destSpriteY = planePtr->destY;
 			left = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].left);
 			right = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].right);
 			top = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].top);
 			bottom = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].bottom);
 
-			draw_sourceSurface =
-			    scen_staticPictToSprite[scenery * 7 + pictIndex];
-			draw_destSurface = 21;
-			draw_spriteLeft = left;
-			draw_spriteTop = top;
-			draw_spriteRight = right - left + 1;
-			draw_spriteBottom = bottom - top + 1;
-			draw_transparency = planePtr->transp ? 3 : 0;
-			draw_spriteOperation(DRAW_BLITSURF);
+			_vm->_draw->sourceSurface =
+			    staticPictToSprite[scenery * 7 + pictIndex];
+			_vm->_draw->destSurface = 21;
+			_vm->_draw->spriteLeft = left;
+			_vm->_draw->spriteTop = top;
+			_vm->_draw->spriteRight = right - left + 1;
+			_vm->_draw->spriteBottom = bottom - top + 1;
+			_vm->_draw->transparency = planePtr->transp ? 3 : 0;
+			_vm->_draw->spriteOperation(DRAW_BLITSURF);
 		}
 	}
 }
 
-void scen_interRenderStatic(void) {
+void Scenery::interRenderStatic(void) {
 	int16 layer;
 	int16 index;
 
-	inter_evalExpr(&index);
-	inter_evalExpr(&layer);
-	scen_renderStatic(index, layer);
+	_vm->_inter->evalExpr(&index);
+	_vm->_inter->evalExpr(&layer);
+	renderStatic(index, layer);
 }
 
-void scen_interLoadCurLayer(void) {
-	inter_evalExpr(&scen_curStatic);
-	inter_evalExpr(&scen_curStaticLayer);
+void Scenery::interLoadCurLayer(void) {
+	_vm->_inter->evalExpr(&curStatic);
+	_vm->_inter->evalExpr(&curStaticLayer);
 }
 
-void scen_updateStatic(int16 orderFrom) {
-	Scen_StaticLayer *layerPtr;
-	Scen_PieceDesc **pictPtr;
-	Scen_StaticPlane *planePtr;
+void Scenery::updateStatic(int16 orderFrom) {
+	StaticLayer *layerPtr;
+	PieceDesc **pictPtr;
+	StaticPlane *planePtr;
 	int16 planeCount;
 	int16 order;
 	int16 plane;
@@ -303,14 +307,14 @@
 	int16 top;
 	int16 bottom;
 
-	if (scen_curStatic == -1)
+	if (curStatic == -1)
 		return;
 
-	if (scen_curStaticLayer >= scen_statics[scen_curStatic].layersCount)
+	if (curStaticLayer >= statics[curStatic].layersCount)
 		return;
 
-	layerPtr = scen_statics[scen_curStatic].layers[scen_curStaticLayer];
-	pictPtr = scen_statics[scen_curStatic].pieces;
+	layerPtr = statics[curStatic].layers[curStaticLayer];
+	pictPtr = statics[curStatic].pieces;
 
 	planeCount = layerPtr->planeCount;
 
@@ -322,65 +326,65 @@
 
 			pieceIndex = planePtr->pieceIndex;
 			pictIndex = planePtr->pictIndex - 1;
-			draw_destSpriteX = planePtr->destX;
-			draw_destSpriteY = planePtr->destY;
+			_vm->_draw->destSpriteX = planePtr->destX;
+			_vm->_draw->destSpriteY = planePtr->destY;
 
 			left = FROM_LE_16(pictPtr[pictIndex][pieceIndex].left);
 			right = FROM_LE_16(pictPtr[pictIndex][pieceIndex].right);
 			top = FROM_LE_16(pictPtr[pictIndex][pieceIndex].top);
 			bottom = FROM_LE_16(pictPtr[pictIndex][pieceIndex].bottom);
 
-			if (draw_destSpriteX > scen_toRedrawRight)
+			if (_vm->_draw->destSpriteX > toRedrawRight)
 				continue;
 
-			if (draw_destSpriteY > scen_toRedrawBottom)
+			if (_vm->_draw->destSpriteY > toRedrawBottom)
 				continue;
 
-			if (draw_destSpriteX < scen_toRedrawLeft) {
-				left += scen_toRedrawLeft - draw_destSpriteX;
-				draw_destSpriteX = scen_toRedrawLeft;
+			if (_vm->_draw->destSpriteX < toRedrawLeft) {
+				left += toRedrawLeft - _vm->_draw->destSpriteX;
+				_vm->_draw->destSpriteX = toRedrawLeft;
 			}
 
-			if (draw_destSpriteY < scen_toRedrawTop) {
-				top += scen_toRedrawTop - draw_destSpriteY;
-				draw_destSpriteY = scen_toRedrawTop;
+			if (_vm->_draw->destSpriteY < toRedrawTop) {
+				top += toRedrawTop - _vm->_draw->destSpriteY;
+				_vm->_draw->destSpriteY = toRedrawTop;
 			}
 
-			draw_spriteLeft = left;
-			draw_spriteTop = top;
-			draw_spriteRight = right - left + 1;
-			draw_spriteBottom = bottom - top + 1;
+			_vm->_draw->spriteLeft = left;
+			_vm->_draw->spriteTop = top;
+			_vm->_draw->spriteRight = right - left + 1;
+			_vm->_draw->spriteBottom = bottom - top + 1;
 
-			if (draw_spriteRight <= 0 || draw_spriteBottom <= 0)
+			if (_vm->_draw->spriteRight <= 0 || _vm->_draw->spriteBottom <= 0)
 				continue;
 
-			if (draw_destSpriteX + draw_spriteRight - 1 >
-			    scen_toRedrawRight)
-				draw_spriteRight =
-				    scen_toRedrawRight - draw_destSpriteX + 1;
+			if (_vm->_draw->destSpriteX + _vm->_draw->spriteRight - 1 >
+			    toRedrawRight)
+				_vm->_draw->spriteRight =
+				    toRedrawRight - _vm->_draw->destSpriteX + 1;
 
-			if (draw_destSpriteY + draw_spriteBottom - 1 >
-			    scen_toRedrawBottom)
-				draw_spriteBottom =
-				    scen_toRedrawBottom - draw_destSpriteY + 1;
+			if (_vm->_draw->destSpriteY + _vm->_draw->spriteBottom - 1 >
+			    toRedrawBottom)
+				_vm->_draw->spriteBottom =
+				    toRedrawBottom - _vm->_draw->destSpriteY + 1;
 
-			draw_sourceSurface =
-			    scen_staticPictToSprite[scen_curStatic * 7 +
+			_vm->_draw->sourceSurface =
+			    staticPictToSprite[curStatic * 7 +
 			    pictIndex];
-			draw_destSurface = 21;
-			draw_transparency = planePtr->transp ? 3 : 0;
-			draw_spriteOperation(DRAW_BLITSURF);
+			_vm->_draw->destSurface = 21;
+			_vm->_draw->transparency = planePtr->transp ? 3 : 0;
+			_vm->_draw->spriteOperation(DRAW_BLITSURF);
 		}
 	}
 }
 
-int16 scen_loadAnim(char search) {
+int16 Scenery::loadAnim(char search) {
 	int16 picsCount;
 	int16 resId;
 	int16 i;
 	int16 sceneryIndex;
 	char *dataPtr;
-	Scen_Animation *ptr;
+	Animation *ptr;
 	int16 offset;
 	int16 pictDescId;
 	int16 width;
@@ -388,58 +392,58 @@
 	int16 sprResId;
 	int16 sprIndex;
 
-	if (cd_globFlag) {
-		while (cd_getTrackPos() != -1)
-		    util_longDelay(50);
+	if (_vm->_cdrom->_cdPlaying) {
+		while (_vm->_cdrom->getTrackPos() != -1)
+		    _vm->_util->longDelay(50);
 
-		cd_globFlag = false;
+		_vm->_cdrom->_cdPlaying = false;
 	}
 
-	inter_evalExpr(&sceneryIndex);
-	picsCount = inter_load16();
-	resId = inter_load16();
+	_vm->_inter->evalExpr(&sceneryIndex);
+	picsCount = _vm->_inter->load16();
+	resId = _vm->_inter->load16();
 
 	if (search) {
 		for (i = 0; i < 10; i++) {
-			if (scen_animPictCount[i] != 0
-			    && scen_animResId[i] == resId) {
-				inter_execPtr += 8 * scen_animPictCount[i];
+			if (animPictCount[i] != 0
+			    && animResId[i] == resId) {
+				_vm->_global->inter_execPtr += 8 * animPictCount[i];
 				return i;
 			}
 
-			if (scen_animPictCount[i] == 0 && i < sceneryIndex)
+			if (animPictCount[i] == 0 && i < sceneryIndex)
 				sceneryIndex = i;
 		}
 	}
 
-	scen_animPictCount[sceneryIndex] = picsCount;
-	scen_animResId[sceneryIndex] = resId;
+	animPictCount[sceneryIndex] = picsCount;
+	animResId[sceneryIndex] = resId;
 
 	if (resId >= 30000) {
-		scen_animFromExt[sceneryIndex] = 1;
-		dataPtr = game_loadExtData(resId, 0, 0);
+		animFromExt[sceneryIndex] = 1;
+		dataPtr = _vm->_game->loadExtData(resId, 0, 0);
 	} else {
-		scen_animFromExt[sceneryIndex] = 0;
-		dataPtr = game_loadTotResource(resId);
+		animFromExt[sceneryIndex] = 0;
+		dataPtr = _vm->_game->loadTotResource(resId);
 	}
 
-	ptr = &scen_animations[sceneryIndex];
+	ptr = &animations[sceneryIndex];
 	ptr->dataPtr = dataPtr;
 
 	ptr->layersCount = READ_LE_UINT16(dataPtr);
 	dataPtr += 2;
 
 	ptr->layers =
-	    (Scen_AnimLayer **) malloc(sizeof(Scen_AnimLayer *) *
+	    (AnimLayer **) malloc(sizeof(AnimLayer *) *
 	    ptr->layersCount);
 	ptr->pieces =
-	    (Scen_PieceDesc **) malloc(sizeof(Scen_PieceDesc *) *
+	    (PieceDesc **) malloc(sizeof(PieceDesc *) *
 	    picsCount);
 	ptr->piecesFromExt = (int8 *) malloc(picsCount);
 
 	for (i = 0; i < ptr->layersCount; i++) {
 		offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]);
-		ptr->layers[i] = (Scen_AnimLayer *) (dataPtr + offset - 2);
+		ptr->layers[i] = (AnimLayer *) (dataPtr + offset - 2);
 
 		ptr->layers[i]->unknown0 = (int16)READ_LE_UINT16(&ptr->layers[i]->unknown0);
 		ptr->layers[i]->posX = (int16)READ_LE_UINT16(&ptr->layers[i]->posX);
@@ -450,47 +454,47 @@
 	}
 
 	for (i = 0; i < picsCount; i++) {
-		pictDescId = inter_load16();
+		pictDescId = _vm->_inter->load16();
 		if (pictDescId >= 30000) {
 			ptr->pieces[i] =
-			    (Scen_PieceDesc *) game_loadExtData(pictDescId, 0,
+			    (PieceDesc *) _vm->_game->loadExtData(pictDescId, 0,
 			    0);
 			ptr->piecesFromExt[i] = 1;
 		} else {
 			ptr->pieces[i] =
-			    (Scen_PieceDesc *)
-			    game_loadTotResource(pictDescId);
+			    (PieceDesc *)
+			    _vm->_game->loadTotResource(pictDescId);
 			ptr->piecesFromExt[i] = 0;
 		}
 
-		width = inter_load16();
-		height = inter_load16();
-		sprResId = inter_load16();
+		width = _vm->_inter->load16();
+		height = _vm->_inter->load16();
+		sprResId = _vm->_inter->load16();
 		for (sprIndex = 0; sprIndex < 20; sprIndex++) {
-			if (scen_spriteResId[sprIndex] == sprResId)
+			if (spriteResId[sprIndex] == sprResId)
 				break;
 		}
 
 		if (sprIndex < 20) {
-			scen_animPictToSprite[7 * sceneryIndex + i] = sprIndex;
-			scen_spriteRefs[sprIndex]++;
+			animPictToSprite[7 * sceneryIndex + i] = sprIndex;
+			spriteRefs[sprIndex]++;
 		} else {
-			for (sprIndex = 19; draw_spritesArray[sprIndex] != 0;
+			for (sprIndex = 19; _vm->_draw->spritesArray[sprIndex] != 0;
 			    sprIndex--);
 
-			scen_animPictToSprite[7 * sceneryIndex + i] = sprIndex;
-			scen_spriteRefs[sprIndex] = 1;
-			scen_spriteResId[sprIndex] = sprResId;
-			draw_spritesArray[sprIndex] =
-			    vid_initSurfDesc(videoMode, width, height, 2);
+			animPictToSprite[7 * sceneryIndex + i] = sprIndex;
+			spriteRefs[sprIndex] = 1;
+			spriteResId[sprIndex] = sprResId;
+			_vm->_draw->spritesArray[sprIndex] =
+			    _vm->_video->initSurfDesc(_vm->_global->videoMode, width, height, 2);
 
-			vid_clearSurf(draw_spritesArray[sprIndex]);
-			draw_destSurface = sprIndex;
-			draw_spriteLeft = sprResId;
-			draw_transparency = 0;
-			draw_destSpriteX = 0;
-			draw_destSpriteY = 0;
-			draw_spriteOperation(DRAW_LOADSPRITE);
+			_vm->_video->clearSurf(_vm->_draw->spritesArray[sprIndex]);
+			_vm->_draw->destSurface = sprIndex;
+			_vm->_draw->spriteLeft = sprResId;
+			_vm->_draw->transparency = 0;
+			_vm->_draw->destSpriteX = 0;
+			_vm->_draw->destSpriteY = 0;
+			_vm->_draw->spriteOperation(DRAW_LOADSPRITE);
 		}
 	}
 	return sceneryIndex + 100;
@@ -500,11 +504,11 @@
 // flags & 4 == 0 - calculate animation final size
 // flags & 2 != 0 - don't check with "toRedraw"'s
 // flags & 4 != 0 - checkk view toRedraw
-void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags,
+void Scenery::updateAnim(int16 layer, int16 frame, int16 animation, int16 flags,
 	    int16 drawDeltaX, int16 drawDeltaY, char doDraw) {
-	Scen_AnimLayer *layerPtr;
-	Scen_PieceDesc **pictPtr;
-	Scen_AnimFramePiece *framePtr;
+	AnimLayer *layerPtr;
+	PieceDesc **pictPtr;
+	AnimFramePiece *framePtr;
 
 	uint16 pieceIndex;
 	uint16 pictIndex;
@@ -523,29 +527,29 @@
 	int16 destX;
 	int16 destY;
 
-	if (layer >= scen_animations[animation].layersCount)
+	if (layer >= animations[animation].layersCount)
 		return;
 
-	layerPtr = scen_animations[animation].layers[layer];
+	layerPtr = animations[animation].layers[layer];
 
 	if (frame >= layerPtr->framesCount)
 		return;
 
 	if (flags & 1)		// Do capture
 	{
-		scen_updateAnim(layer, frame, animation, 0, drawDeltaX,
+		updateAnim(layer, frame, animation, 0, drawDeltaX,
 		    drawDeltaY, 0);
 
-		if (scen_toRedrawLeft == -12345)	// Some magic number?
+		if (toRedrawLeft == -12345)	// Some magic number?
 			return;
 
-		game_capturePush(scen_toRedrawLeft, scen_toRedrawTop,
-		    scen_toRedrawRight - scen_toRedrawLeft + 1,
-		    scen_toRedrawBottom - scen_toRedrawTop + 1);
+		_vm->_game->capturePush(toRedrawLeft, toRedrawTop,
+		    toRedrawRight - toRedrawLeft + 1,
+		    toRedrawBottom - toRedrawTop + 1);
 
-		*scen_pCaptureCounter = *scen_pCaptureCounter + 1;
+		*pCaptureCounter = *pCaptureCounter + 1;
 	}
-	pictPtr = scen_animations[animation].pieces;
+	pictPtr = animations[animation].pieces;
 	framePtr = layerPtr->frames;
 
 	for (i = 0; i < frame; i++, framePtr++) {
@@ -554,18 +558,18 @@
 	}
 
 	if ((flags & 4) == 0) {
-		scen_toRedrawLeft = -12345;
+		toRedrawLeft = -12345;
 	} else {
-		scen_toRedrawLeft =
-		    MAX(scen_toRedrawLeft, anim_animAreaLeft);
-		scen_toRedrawTop =
-		    MAX(scen_toRedrawTop, anim_animAreaTop);
-		scen_toRedrawRight =
-		    MIN(scen_toRedrawRight,
-		    (int16)(anim_animAreaLeft + anim_animAreaWidth - 1));
-		scen_toRedrawBottom =
-		    MIN(scen_toRedrawBottom,
-		    (int16)(anim_animAreaTop + anim_animAreaHeight - 1));
+		toRedrawLeft =
+		    MAX(toRedrawLeft, _vm->_anim->_areaLeft);
+		toRedrawTop =
+		    MAX(toRedrawTop, _vm->_anim->_areaTop);
+		toRedrawRight =
+		    MIN(toRedrawRight,
+		    (int16)(_vm->_anim->_areaLeft + _vm->_anim->_areaWidth - 1));
+		toRedrawBottom =
+		    MIN(toRedrawBottom,
+		    (int16)(_vm->_anim->_areaTop + _vm->_anim->_areaHeight - 1));
 	}
 
 	transp = layerPtr->transp ? 3 : 0;
@@ -612,131 +616,131 @@
 		bottom = FROM_LE_16(pictPtr[pictIndex][pieceIndex].bottom);
 
 		if (flags & 2) {
-			if (destX < anim_animAreaLeft) {
-				left += anim_animAreaLeft - destX;
-				destX = anim_animAreaLeft;
+			if (destX < _vm->_anim->_areaLeft) {
+				left += _vm->_anim->_areaLeft - destX;
+				destX = _vm->_anim->_areaLeft;
 			}
 
 			if (left <= right
 			    && destX + right - left >=
-			    anim_animAreaLeft + anim_animAreaWidth)
+			    _vm->_anim->_areaLeft + _vm->_anim->_areaWidth)
 				right -=
 				    (destX + right - left) -
-				    (anim_animAreaLeft + anim_animAreaWidth) +
+				    (_vm->_anim->_areaLeft + _vm->_anim->_areaWidth) +
 				    1;
 
-			if (destY < anim_animAreaTop) {
-				top += anim_animAreaTop - destY;
-				destY = anim_animAreaTop;
+			if (destY < _vm->_anim->_areaTop) {
+				top += _vm->_anim->_areaTop - destY;
+				destY = _vm->_anim->_areaTop;
 			}
 
 			if (top <= bottom
 			    && destY + bottom - top >=
-			    anim_animAreaTop + anim_animAreaHeight)
+			    _vm->_anim->_areaTop + _vm->_anim->_areaHeight)
 				bottom -=
 				    (destY + bottom - top) -
-				    (anim_animAreaTop + anim_animAreaHeight) +
+				    (_vm->_anim->_areaTop + _vm->_anim->_areaHeight) +
 				    1;
 
 		} else if (flags & 4) {
-			if (destX < scen_toRedrawLeft) {
-				left += scen_toRedrawLeft - destX;
-				destX = scen_toRedrawLeft;
+			if (destX < toRedrawLeft) {
+				left += toRedrawLeft - destX;
+				destX = toRedrawLeft;
 			}
 
 			if (left <= right
-			    && destX + right - left > scen_toRedrawRight)
+			    && destX + right - left > toRedrawRight)
 				right -=
-				    destX + right - left - scen_toRedrawRight;
+				    destX + right - left - toRedrawRight;
 
-			if (destY < scen_toRedrawTop) {
-				top += scen_toRedrawTop - destY;
-				destY = scen_toRedrawTop;
+			if (destY < toRedrawTop) {
+				top += toRedrawTop - destY;
+				destY = toRedrawTop;
 			}
 
 			if (top <= bottom
-			    && destY + bottom - top > scen_toRedrawBottom)
+			    && destY + bottom - top > toRedrawBottom)
 				bottom -=
-				    destY + bottom - top - scen_toRedrawBottom;
+				    destY + bottom - top - toRedrawBottom;
 		}
 
 		if (left > right || top > bottom)
 			continue;
 
 		if (doDraw) {
-			draw_sourceSurface =
-			    scen_animPictToSprite[animation * 7 + pictIndex];
-			draw_destSurface = 21;
+			_vm->_draw->sourceSurface =
+			    animPictToSprite[animation * 7 + pictIndex];
+			_vm->_draw->destSurface = 21;
 
-			draw_spriteLeft = left;
-			draw_spriteTop = top;
-			draw_spriteRight = right - left + 1;
-			draw_spriteBottom = bottom - top + 1;
-			draw_destSpriteX = destX;
-			draw_destSpriteY = destY;
-			draw_transparency = transp;
-			draw_spriteOperation(DRAW_BLITSURF);
+			_vm->_draw->spriteLeft = left;
+			_vm->_draw->spriteTop = top;
+			_vm->_draw->spriteRight = right - left + 1;
+			_vm->_draw->spriteBottom = bottom - top + 1;
+			_vm->_draw->destSpriteX = destX;
+			_vm->_draw->destSpriteY = destY;
+			_vm->_draw->transparency = transp;
+			_vm->_draw->spriteOperation(DRAW_BLITSURF);
 		}
 
 		if ((flags & 4) == 0) {
-			if (scen_toRedrawLeft == -12345) {
-				scen_toRedrawLeft = destX;
-				scen_animLeft = destX;
-				scen_toRedrawTop = destY;
-				scen_animTop = destY;
-				scen_toRedrawRight = destX + right - left;
-				scen_toRedrawBottom = destY + bottom - top;
+			if (toRedrawLeft == -12345) {
+				toRedrawLeft = destX;
+				animLeft = destX;
+				toRedrawTop = destY;
+				animTop = destY;
+				toRedrawRight = destX + right - left;
+				toRedrawBottom = destY + bottom - top;
 			} else {
-				scen_toRedrawLeft =
-				    MIN(scen_toRedrawLeft, destX);
-				scen_toRedrawTop =
-				    MIN(scen_toRedrawTop, destY);
-				scen_toRedrawRight =
-				    MAX(scen_toRedrawRight,
+				toRedrawLeft =
+				    MIN(toRedrawLeft, destX);
+				toRedrawTop =
+				    MIN(toRedrawTop, destY);
+				toRedrawRight =
+				    MAX(toRedrawRight,
 				    (int16)(destX + right - left));
-				scen_toRedrawBottom =
-				    MAX(scen_toRedrawBottom,
+				toRedrawBottom =
+				    MAX(toRedrawBottom,
 				    (int16)(destY + bottom - top));
 			}
 		}
 	} while (framePtr->notFinal == 1);
 }
 
-void scen_freeAnim(int16 animation) {
+void Scenery::freeAnim(int16 animation) {
 	int16 i;
 	int16 spr;
 
 	if (animation == -1)
-		inter_evalExpr(&animation);
+		_vm->_inter->evalExpr(&animation);
 
-	if (scen_animPictCount[animation] == 0)
+	if (animPictCount[animation] == 0)
 		return;
 
-	for (i = 0; i < scen_animPictCount[animation]; i++) {
-		if (scen_animations[animation].piecesFromExt[i] == 1)
-			free(scen_animations[animation].pieces[i]);
+	for (i = 0; i < animPictCount[animation]; i++) {
+		if (animations[animation].piecesFromExt[i] == 1)
+			free(animations[animation].pieces[i]);
 
-		spr = scen_animPictToSprite[animation * 7 + i];
-		scen_spriteRefs[spr]--;
-		if (scen_spriteRefs[spr] == 0) {
-			vid_freeSurfDesc(draw_spritesArray[spr]);
+		spr = animPictToSprite[animation * 7 + i];
+		spriteRefs[spr]--;
+		if (spriteRefs[spr] == 0) {
+			_vm->_video->freeSurfDesc(_vm->_draw->spritesArray[spr]);
 
-			draw_spritesArray[spr] = 0;
-			scen_spriteResId[spr] = -1;
+			_vm->_draw->spritesArray[spr] = 0;
+			spriteResId[spr] = -1;
 		}
 	}
 
-	free(scen_animations[animation].layers);
-	free(scen_animations[animation].pieces);
-	free(scen_animations[animation].piecesFromExt);
-	if (scen_animFromExt[animation] == 1)
-		free(scen_animations[animation].dataPtr);
+	free(animations[animation].layers);
+	free(animations[animation].pieces);
+	free(animations[animation].piecesFromExt);
+	if (animFromExt[animation] == 1)
+		free(animations[animation].dataPtr);
 
-	scen_animFromExt[animation] = 0;
-	scen_animPictCount[animation] = 0;
+	animFromExt[animation] = 0;
+	animPictCount[animation] = 0;
 }
 
-void scen_interUpdateAnim(void) {
+void Scenery::interUpdateAnim(void) {
 	int16 deltaX;
 	int16 deltaY;
 	int16 flags;
@@ -744,37 +748,37 @@
 	int16 layer;
 	int16 animation;
 
-	inter_evalExpr(&deltaX);
-	inter_evalExpr(&deltaY);
-	inter_evalExpr(&animation);
-	inter_evalExpr(&layer);
-	inter_evalExpr(&frame);
-	flags = inter_load16();
-	scen_updateAnim(layer, frame, animation, flags, deltaX, deltaY, 1);
+	_vm->_inter->evalExpr(&deltaX);
+	_vm->_inter->evalExpr(&deltaY);
+	_vm->_inter->evalExpr(&animation);
+	_vm->_inter->evalExpr(&layer);
+	_vm->_inter->evalExpr(&frame);
+	flags = _vm->_inter->load16();
+	updateAnim(layer, frame, animation, flags, deltaX, deltaY, 1);
 }
 
-void scen_interStoreParams(void) {
-	Scen_AnimLayer *layerPtr;
+void Scenery::interStoreParams(void) {
+	AnimLayer *layerPtr;
 	int16 animation;
 	int16 layer;
 	int16 var;
 
-	warning("scen_interStoreParams: Storing...");
+	warning("interStoreParams: Storing...");
 
-	inter_evalExpr(&animation);
-	inter_evalExpr(&layer);
-	layerPtr = scen_animations[animation].layers[layer];
+	_vm->_inter->evalExpr(&animation);
+	_vm->_inter->evalExpr(&layer);
+	layerPtr = animations[animation].layers[layer];
 
-	var = parse_parseVarIndex();
+	var = _vm->_parse->parseVarIndex();
 	WRITE_VAR_OFFSET(var, layerPtr->animDeltaX);
 
-	var = parse_parseVarIndex();
+	var = _vm->_parse->parseVarIndex();
 	WRITE_VAR_OFFSET(var, layerPtr->animDeltaY);
 
-	var = parse_parseVarIndex();
+	var = _vm->_parse->parseVarIndex();
 	WRITE_VAR_OFFSET(var, layerPtr->unknown0);
 
-	var = parse_parseVarIndex();
+	var = _vm->_parse->parseVarIndex();
 	WRITE_VAR_OFFSET(var, layerPtr->framesCount);
 }
 

Index: scenery.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/scenery.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- scenery.h	18 Oct 2005 01:30:17 -0000	1.7
+++ scenery.h	3 Jan 2006 23:14:39 -0000	1.8
@@ -24,111 +24,123 @@
 
 namespace Gob {
 
+class Scenery {
+public:
 #pragma START_PACK_STRUCTS
-typedef struct Scen_PieceDesc {
-	int16 left;		//NOTE:
-	int16 right;		//These are stored in Little Endian format
-	int16 top;		//And should be converted by client code when accessed
-	int16 bottom;		//i.e. use FROM_LE_16()
-} GCC_PACK Scen_PieceDesc;
+	typedef struct PieceDesc {
+		int16 left;		//NOTE:
+		int16 right;		//These are stored in Little Endian format
+		int16 top;		//And should be converted by client code when accessed
+		int16 bottom;		//i.e. use FROM_LE_16()
+	} GCC_PACK PieceDesc;
 
-typedef struct Scen_StaticPlane {
-	int8 pictIndex;
-	int8 pieceIndex;
-	int8 drawOrder;
-	int16 destX;
-	int16 destY;
-	int8 transp;
-} GCC_PACK Scen_StaticPlane;
+	typedef struct StaticPlane {
+		int8 pictIndex;
+		int8 pieceIndex;
+		int8 drawOrder;
+		int16 destX;
+		int16 destY;
+		int8 transp;
+	} GCC_PACK StaticPlane;
 
-typedef struct Scen_StaticLayer {
-	int16 backResId;
-	int16 planeCount;
-	Scen_StaticPlane planes[1];
-} GCC_PACK Scen_StaticLayer;
+	typedef struct StaticLayer {
+		int16 backResId;
+		int16 planeCount;
+		StaticPlane planes[1];
+	} GCC_PACK StaticLayer;
 
-// Animations
+	// Animations
 
-typedef struct Scen_AnimFramePiece {
-	byte pictIndex;
-	byte pieceIndex;
-	int8 destX;
-	int8 destY;
-	int8 notFinal;
-} GCC_PACK Scen_AnimFramePiece;
+	typedef struct AnimFramePiece {
+		byte pictIndex;
+		byte pieceIndex;
+		int8 destX;
+		int8 destY;
+		int8 notFinal;
+	} GCC_PACK AnimFramePiece;
 
-typedef struct Scen_AnimLayer {
-	int16 unknown0;
-	int16 posX;
-	int16 posY;
-	int16 animDeltaX;
-	int16 animDeltaY;
-	int8 transp;
-	int16 framesCount;
-	Scen_AnimFramePiece frames[1];
-} GCC_PACK Scen_AnimLayer;
+	typedef struct AnimLayer {
+		int16 unknown0;
+		int16 posX;
+		int16 posY;
+		int16 animDeltaX;
+		int16 animDeltaY;
+		int8 transp;
+		int16 framesCount;
+		AnimFramePiece frames[1];
+	} GCC_PACK AnimLayer;
 #pragma END_PACK_STRUCTS
 
-typedef struct Scen_Static {
-	int16 layersCount;
-	Scen_StaticLayer **layers;
-	Scen_PieceDesc **pieces;
-	int8 *piecesFromExt;
-	char *dataPtr;
-} Scen_Static;
+	typedef struct Static {
+		int16 layersCount;
+		StaticLayer **layers;
+		PieceDesc **pieces;
+		int8 *piecesFromExt;
+		char *dataPtr;
+		Static() : layersCount(0), layers(0), pieces(0),
+				   piecesFromExt(0), dataPtr(0) {}
+	} Static;
 
-struct Scen_Animation {
-	int16 layersCount;
-	Scen_AnimLayer **layers;
-	Scen_PieceDesc **pieces;
-	int8 *piecesFromExt;
-	char *dataPtr;
-};
+	struct Animation {
+		int16 layersCount;
+		AnimLayer **layers;
+		PieceDesc **pieces;
+		int8 *piecesFromExt;
+		char *dataPtr;
+		Animation() : layersCount(0), layers(0), pieces(0),
+			              piecesFromExt(0), dataPtr(0) {}
+	};
 
-// Global variables
+	// Global variables
 
-extern char scen_spriteRefs[20];
-extern int16 scen_spriteResId[20];
+	char spriteRefs[20];
+	int16 spriteResId[20];
 
-extern char scen_staticPictToSprite[70];
-extern int16 scen_staticPictCount[10];
-extern Scen_Static scen_statics[10];
-extern char scen_staticFromExt[10];
-extern int16 scen_staticResId[10];
+	char staticPictToSprite[70];
+	int16 staticPictCount[10];
+	Static statics[10];
+	char staticFromExt[10];
+	int16 staticResId[10];
 
-extern char scen_animPictToSprite[70];
-extern int16 scen_animPictCount[10];
-extern char scen_animFromExt[10];
-extern Scen_Animation scen_animations[10];
-extern int16 scen_animResId[10];
+	char animPictToSprite[70];
+	int16 animPictCount[10];
+	char animFromExt[10];
+	Animation animations[10];
+	int16 animResId[10];
 
-extern int16 scen_curStatic;
-extern int16 scen_curStaticLayer;
+	int16 curStatic;
+	int16 curStaticLayer;
 
-extern int16 scen_toRedrawLeft;
-extern int16 scen_toRedrawRight;
-extern int16 scen_toRedrawTop;
-extern int16 scen_toRedrawBottom;
+	int16 toRedrawLeft;
+	int16 toRedrawRight;
+	int16 toRedrawTop;
+	int16 toRedrawBottom;
 
-extern int16 scen_animTop;
-extern int16 scen_animLeft;
+	int16 animTop;
+	int16 animLeft;
 
-extern int16 *scen_pCaptureCounter;
+	int16 *pCaptureCounter;
 
-// Functions
+	// Functions
 
-int16 scen_loadStatic(char search);
-void scen_freeStatic(int16 index);
-void scen_renderStatic(int16 scenery, int16 layer);
-void scen_interRenderStatic(void);
-void scen_interLoadCurLayer(void);
-void scen_updateStatic(int16 orderFrom);
-int16 scen_loadAnim(char search);
-void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags,
-    int16 drawDeltaX, int16 drawDeltaY, char doDraw);
-void scen_freeAnim(int16 animation);
-void scen_interUpdateAnim(void);
-void scen_interStoreParams(void);
+	int16 loadStatic(char search);
+	void freeStatic(int16 index);
+	void renderStatic(int16 scenery, int16 layer);
+	void interRenderStatic(void);
+	void interLoadCurLayer(void);
+	void updateStatic(int16 orderFrom);
+	int16 loadAnim(char search);
+	void updateAnim(int16 layer, int16 frame, int16 animation, int16 flags,
+					int16 drawDeltaX, int16 drawDeltaY, char doDraw);
+	void freeAnim(int16 animation);
+	void interUpdateAnim(void);
+	void interStoreParams(void);
+
+	Scenery(GobEngine *vm);
+
+protected:
+	GobEngine *_vm;
+};
 
 }				// End of namespace Gob
 

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/sound.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- sound.cpp	18 Oct 2005 01:30:18 -0000	1.13
+++ sound.cpp	3 Jan 2006 23:14:39 -0000	1.14
@@ -20,41 +20,14 @@
  *
  */
 
-#include "sound/audiostream.h"
-
 #include "gob/gob.h"
 #include "gob/global.h"
 #include "gob/sound.h"
 
 namespace Gob {
 
-// TODO: This is a very primitive square wave generator. The only thing is
-//       has in common with the PC speaker is that it sounds terrible.
-
-class SquareWaveStream : public AudioStream {
-private:
-	uint _rate;
-	bool _beepForever;
-	uint32 _periodLength;
-	uint32 _periodSamples;
-	uint32 _remainingSamples;
-	int16 _sampleValue;
-
-public:
-	SquareWaveStream() {}
-	~SquareWaveStream() {}
-
-	void playNote(int freq, int32 ms);
-
-	int readBuffer(int16 *buffer, const int numSamples);
-
-	bool endOfData() const	{ return _remainingSamples == 0; }
-	bool isStereo() const	{ return false; }
-	int getRate() const	{ return _rate; }
-};
-
-void SquareWaveStream::playNote(int freq, int32 ms) {
-	_rate = _vm->_mixer->getOutputRate();
+void Snd::SquareWaveStream::playNote(int freq, int32 ms, uint rate) {
+	_rate = rate;
 	_periodLength = _rate / (2 * freq);
 	_periodSamples = 0;
 	_sampleValue = 6000;
@@ -67,7 +40,7 @@
 	}
 }
 
-int SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) {
+int Snd::SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) {
 	int samples = 0;
 
 	while (samples < numSamples && _remainingSamples > 0) {
@@ -84,48 +57,42 @@
 	return samples;
 }
 
-SquareWaveStream speakerStream;
-Audio::SoundHandle speakerHandle;
-Snd_SoundDesc *snd_loopingSounds[5]; // Should be enough
-
-void snd_initSound(void) {
-	for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++)
-		snd_loopingSounds[i] = NULL;
+Snd::Snd(GobEngine *vm) : _vm(vm) {
+	//CleanupFuncPtr cleanupFunc;// = &snd_cleanupFuncCallback();
+	cleanupFunc = 0;
+	for (int i = 0; i < ARRAYSIZE(loopingSounds); i++)
+		loopingSounds[i] = NULL;
+	soundPort = 0;
+	playingSound = 0;
 }
 
-void snd_loopSounds(void) {
-	for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) {
-		Snd_SoundDesc *snd = snd_loopingSounds[i];
+void Snd::loopSounds(void) {
+	for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) {
+		SoundDesc *snd = loopingSounds[i];
 		if (snd && !_vm->_mixer->isSoundHandleActive(snd->handle)) {
 			if (snd->repCount-- > 0) {
 				_vm->_mixer->playRaw(&snd->handle, snd->data, snd->size, snd->frequency, 0);
 			} else {
-				snd_loopingSounds[i] = NULL;
+				loopingSounds[i] = NULL;
 			}
 		}
 	}
 }
 
-int16 snd_checkProAudio(void) {return 0;}
-int16 snd_checkAdlib(void) {return 0;}
-int16 snd_checkBlaster(void) {return 0;}
-void snd_setBlasterPort(int16 port) {return;}
+void Snd::setBlasterPort(int16 port) {return;}
 
-void snd_speakerOn(int16 frequency, int32 length) {
-	speakerStream.playNote(frequency, length);
+void Snd::speakerOn(int16 frequency, int32 length) {
+	speakerStream.playNote(frequency, length, _vm->_mixer->getOutputRate());
 	if (!_vm->_mixer->isSoundHandleActive(speakerHandle)) {
 		_vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &speakerHandle, &speakerStream, -1, 255, 0, false);
 	}
 }
 
-void snd_speakerOff(void) {
+void Snd::speakerOff(void) {
 	_vm->_mixer->stopHandle(speakerHandle);
 }
 
-void snd_stopSound(int16 arg){return;}
-void snd_setResetTimerFlag(char flag){return;}
-
-void snd_playSample(Snd_SoundDesc *sndDesc, int16 repCount, int16 frequency) {
+void Snd::playSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency) {
 	assert(frequency > 0);
 
 	if (!_vm->_mixer->isSoundHandleActive(sndDesc->handle)) {
@@ -136,9 +103,9 @@
 	sndDesc->frequency = frequency;
 
 	if (repCount > 1) {
-		for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) {
-			if (!snd_loopingSounds[i]) {
-				snd_loopingSounds[i] = sndDesc;
+		for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) {
+			if (!loopingSounds[i]) {
+				loopingSounds[i] = sndDesc;
 				return;
 			}
 		}
@@ -146,44 +113,34 @@
 	}
 }
 
-void snd_cleanupFuncCallback() {;}
-CleanupFuncPtr (snd_cleanupFunc);
-//CleanupFuncPtr snd_cleanupFunc;// = &snd_cleanupFuncCallback();
-
-int16 snd_soundPort;
-char snd_playingSound;
-
-void snd_writeAdlib(int16 port, int16 data) {
+void Snd::writeAdlib(int16 port, int16 data) {
 	return;
 }
 
-Snd_SoundDesc *snd_loadSoundData(const char *path) {
-	Snd_SoundDesc *sndDesc;
+Snd::SoundDesc *Snd::loadSoundData(const char *path) {
+	Snd::SoundDesc *sndDesc;
 	int32 size;
 
-	size = data_getDataSize(path);
-	sndDesc = (Snd_SoundDesc *)malloc(size);
+	size = _vm->_dataio->getDataSize(path);
+	sndDesc = (Snd::SoundDesc *)malloc(size);
 	sndDesc->size = size;
-	sndDesc->data = data_getData(path);
+	sndDesc->data = _vm->_dataio->getData(path);
 
 	return sndDesc;
 }
 
-void snd_freeSoundData(Snd_SoundDesc *sndDesc) {
+void Snd::freeSoundData(Snd::SoundDesc *sndDesc) {
 	_vm->_mixer->stopHandle(sndDesc->handle);
 
-	for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) {
-		if (snd_loopingSounds[i] == sndDesc)
-			snd_loopingSounds[i] = NULL;
+	for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) {
+		if (loopingSounds[i] == sndDesc)
+			loopingSounds[i] = NULL;
 	}
 
 	free(sndDesc->data);
 	free(sndDesc);
 }
 
-void snd_playComposition(Snd_SoundDesc ** samples, int16 *composit, int16 freqVal) {;}
-void snd_waitEndPlay(void) {;}
-
 }                               // End of namespace Gob
 
 

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/sound.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- sound.h	18 Oct 2005 01:30:18 -0000	1.9
+++ sound.h	3 Jan 2006 23:14:39 -0000	1.10
@@ -22,43 +22,82 @@
 #ifndef GOB_SOUND_H
 #define GOB_SOUND_H
 
+#include "sound/audiostream.h"
+
 namespace Gob {
 
-void snd_initSound(void);
-void snd_loopSounds(void);
-int16 snd_checkProAudio(void);
-int16 snd_checkAdlib(void);
-int16 snd_checkBlaster(void);
-void snd_setBlasterPort(int16 port);
-void snd_speakerOn(int16 frequency, int32 length);
-void snd_speakerOff(void);
-void snd_stopSound(int16 arg);
-void snd_setResetTimerFlag(char flag);
+class Snd {
+public:
+	typedef struct SoundDesc {
+		Audio::SoundHandle handle;
+		char *data;
+		int32 size;
+		int16 repCount;
+		int16 timerTicks;
+		int16 inClocks;
+		int16 frequency;
+		int16 flag;
+		SoundDesc() : data(0), size(0), repCount(0), timerTicks(0),
+					  inClocks(0), frequency(0), flag(0) {}
+	} SoundDesc;
 
-extern int16 snd_soundPort;
-extern char snd_playingSound;
+	typedef void (*CleanupFuncPtr) (int16);
 
-typedef void (*CleanupFuncPtr) (int16);
-extern CleanupFuncPtr snd_cleanupFunc;
+	SoundDesc *loopingSounds[5]; // Should be enough
+	int16 soundPort;
+	char playingSound;
+	CleanupFuncPtr cleanupFunc;
 
-void snd_writeAdlib(int16 port, int16 data);
+	Snd(GobEngine *vm);
+	void speakerOn(int16 frequency, int32 length);
+	void speakerOff(void);
+	SoundDesc *loadSoundData(const char *path);
+	void stopSound(int16 arg){return;}
+	void loopSounds(void);
+	void playSample(SoundDesc *sndDesc, int16 repCount, int16 frequency);
+	void playComposition(Snd::SoundDesc ** samples, int16 *composit, int16 freqVal) {;}
+	void waitEndPlay(void) {;}
+	void freeSoundData(SoundDesc *sndDesc);
 
-typedef struct Snd_SoundDesc {
-	Audio::SoundHandle handle;
-	char *data;
-	int32 size;
-	int16 repCount;
-	int16 timerTicks;
-	int16 inClocks;
-	int16 frequency;
-	int16 flag;
-} Snd_SoundDesc;
+protected:
+	// TODO: This is a very primitive square wave generator. The only thing is
+	//       has in common with the PC speaker is that it sounds terrible.
+	class SquareWaveStream : public AudioStream {
+	private:
+		uint _rate;
+		bool _beepForever;
+		uint32 _periodLength;
+		uint32 _periodSamples;
+		uint32 _remainingSamples;
+		int16 _sampleValue;
 
-void snd_playSample(Snd_SoundDesc *sndDesc, int16 repCount, int16 frequency);
-Snd_SoundDesc *snd_loadSoundData(const char *path);
-void snd_freeSoundData(Snd_SoundDesc *sndDesc);
-void snd_playComposition(Snd_SoundDesc **samples, int16 *composit, int16 freqVal);
-void snd_waitEndPlay(void);
+	public:
+		SquareWaveStream() {}
+		~SquareWaveStream() {}
+
+		void playNote(int freq, int32 ms, uint rate);
+
+		int readBuffer(int16 *buffer, const int numSamples);
+
+		bool endOfData() const	{ return _remainingSamples == 0; }
+		bool isStereo() const	{ return false; }
+		int getRate() const	{ return _rate; }
+	};
+
+	SquareWaveStream speakerStream;
+	Audio::SoundHandle speakerHandle;
+
+	GobEngine *_vm;
+
+	void cleanupFuncCallback() {;}
+	int16 checkProAudio(void) {return 0;}
+	int16 checkAdlib(void) {return 0;}
+	int16 checkBlaster(void) {return 0;}
+
+	void writeAdlib(int16 port, int16 data);
+	void setBlasterPort(int16 port);
+	void setResetTimerFlag(char flag){return;}
+};
 
 }				// End of namespace Gob
 

Index: timer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/timer.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- timer.cpp	18 Oct 2005 01:30:18 -0000	1.7
+++ timer.cpp	3 Jan 2006 23:14:39 -0000	1.8
@@ -22,13 +22,15 @@
 #include "gob/gob.h"
 #include "gob/global.h"
 #include "gob/sound.h"
+#include "gob/timer.h"
+
 namespace Gob {
 
-void timer_enableTimer() {
-	debug(4, "STUB: timer_enableTimer()");
+void GTimer::enableTimer() {
+	debug(4, "STUB: GTimer::enableTimer()");
 }
 
-void timer_disableTimer() {
-	debug(4, "STUB: timer_disableTimer()");
+void GTimer::disableTimer() {
+	debug(4, "STUB: GTimer::disableTimer()");
 }
 }

Index: timer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/timer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- timer.h	18 Oct 2005 01:30:18 -0000	1.4
+++ timer.h	3 Jan 2006 23:14:39 -0000	1.5
@@ -24,15 +24,18 @@
 
 namespace Gob {
 
-typedef void (* TickHandler) (void);
+class GTimer {
+public:
+	typedef void (* TickHandler) (void);
 
-void timer_enableTimer(void);
-void timer_disableTimer(void);
-void timer_setHandler(void);
-void timer_restoreHandler(void);
-void timer_addTicks(int16 ticks);
-void timer_setTickHandler(TickHandler handler);
-int32 timer_getTicks(void);
+	void enableTimer(void);
+	void disableTimer(void);
+	void setHandler(void);
+	void restoreHandler(void);
+	void addTicks(int16 ticks);
+	void setTickHandler(TickHandler handler);
+	int32 getTicks(void);
+};
 
 }				// End of namespace Gob
 

Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/util.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- util.cpp	18 Oct 2005 01:30:18 -0000	1.18
+++ util.cpp	3 Jan 2006 23:14:39 -0000	1.19
@@ -28,47 +28,52 @@
 
 namespace Gob {
 
-static const int kKeyBufSize = 16;
-
-static int16 _mouseX, _mouseY, _mouseButtons;
-static int16 _keyBuffer[kKeyBufSize], _keyBufferHead, _keyBufferTail;
+Util::Util(GobEngine *vm) : _vm(vm) {
+	_mouseX = 0;
+	_mouseY = 0;
+	_mouseButtons = 0;
+	for (int i = 0; i < KEYBUFSIZE; i++)
+		_keyBuffer[i] = 0;
+	_keyBufferHead = 0;
+	_keyBufferTail = 0;
+}
 
-static void addKeyToBuffer(int16 key) {
-	if ((_keyBufferHead + 1) % kKeyBufSize == _keyBufferTail) {
+void Util::addKeyToBuffer(int16 key) {
+	if ((_keyBufferHead + 1) % KEYBUFSIZE == _keyBufferTail) {
 		warning("key buffer overflow!");
 		return;
 	}
 
 	_keyBuffer[_keyBufferHead] = key;
-	_keyBufferHead = (_keyBufferHead + 1) % kKeyBufSize;
+	_keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE;
 }
 
-static bool keyBufferEmpty() {
+bool Util::keyBufferEmpty() {
 	return (_keyBufferHead == _keyBufferTail);
 }
 
-static bool getKeyFromBuffer(int16& key) {
+bool Util::getKeyFromBuffer(int16& key) {
 	if (_keyBufferHead == _keyBufferTail) return false;
 
 	key = _keyBuffer[_keyBufferTail];
-	_keyBufferTail = (_keyBufferTail + 1) % kKeyBufSize;
+	_keyBufferTail = (_keyBufferTail + 1) % KEYBUFSIZE;
 
 	return true;
 }
 
 
-void util_initInput(void) {
+void Util::initInput(void) {
 	_mouseX = _mouseY = _mouseButtons = 0;
 	_keyBufferHead = _keyBufferTail = 0;
 }
 
-void util_waitKey(void) {
+void Util::waitKey(void) {
 	// FIXME: wrong function name? This functions clears the keyboard buffer.
-	util_processInput();
+	processInput();
 	_keyBufferHead = _keyBufferTail = 0;
 }
 
-int16 util_translateKey(int16 key) {
+int16 Util::translateKey(int16 key) {
 	struct keyS {
 		int16 from;
 		int16 to;
@@ -104,32 +109,32 @@
 	return key;
 }
 
-int16 util_getKey(void) {
+int16 Util::getKey(void) {
 	int16 key;
 
 	while (!getKeyFromBuffer(key)) {
-		util_processInput();
+		processInput();
 
 		if (keyBufferEmpty())
 			g_system->delayMillis(10);
 	}
-	return util_translateKey(key);
+	return translateKey(key);
 }
 
-int16 util_checkKey(void) {
+int16 Util::checkKey(void) {
 	int16 key;
 
 	if (!getKeyFromBuffer(key))
 		key = 0;
 
-	return util_translateKey(key);
+	return translateKey(key);
 }
 
-int16 util_getRandom(int16 max) {
+int16 Util::getRandom(int16 max) {
 	return _vm->_rnd.getRandomNumber(max - 1);
 }
 
-void util_processInput() {
+void Util::processInput() {
 	OSystem::Event event;
 	while (g_system->pollEvent(event)) {
 		switch (event.type) {
@@ -163,7 +168,7 @@
 	}
 }
 
-void util_getMouseState(int16 *pX, int16 *pY, int16 *pButtons) {
+void Util::getMouseState(int16 *pX, int16 *pY, int16 *pButtons) {
 	*pX = _mouseX;
 	*pY = _mouseY;
 
@@ -171,91 +176,90 @@
 		*pButtons = _mouseButtons;
 }
 
-void util_setMousePos(int16 x, int16 y) {
+void Util::setMousePos(int16 x, int16 y) {
 	g_system->warpMouse(x, y);
 }
 
-void util_longDelay(uint16 msecs)
-{
+void Util::longDelay(uint16 msecs) {
 	uint32 time = g_system->getMillis() + msecs;
 	do {
-		vid_waitRetrace(videoMode);
-		util_processInput();
-		util_delay(25);
+		_vm->_video->waitRetrace(_vm->_global->videoMode);
+		processInput();
+		delay(25);
 	} while (g_system->getMillis() < time);
 }
 
-void util_delay(uint16 msecs) {
+void Util::delay(uint16 msecs) {
 	g_system->delayMillis(msecs);
 }
 
-void util_beep(int16 freq) {
-	if (soundFlags == 0)
+void Util::beep(int16 freq) {
+	if (_vm->_global->soundFlags == 0)
 		return;
 
-	snd_speakerOn(freq, 50);
+	_vm->_snd->speakerOn(freq, 50);
 }
 
-uint32 util_getTimeKey(void) {
+uint32 Util::getTimeKey(void) {
 	return g_system->getMillis();
 }
 
-void util_waitMouseUp(void) {
+void Util::waitMouseUp(void) {
 	int16 x;
 	int16 y;
 	int16 buttons;
 
 	do {
-		util_processInput();
-		util_getMouseState(&x, &y, &buttons);
-		if (buttons != 0) util_delay(10);
+		processInput();
+		getMouseState(&x, &y, &buttons);
+		if (buttons != 0) delay(10);
 	} while (buttons != 0);
 }
 
-void util_waitMouseDown(void) {
+void Util::waitMouseDown(void) {
 	int16 x;
 	int16 y;
 	int16 buttons;
 
 	do {
-		util_processInput();
-		util_getMouseState(&x, &y, &buttons);
-		if (buttons == 0) util_delay(10);
+		processInput();
+		getMouseState(&x, &y, &buttons);
+		if (buttons == 0) delay(10);
 	} while (buttons == 0);
 }
 
 /* NOT IMPLEMENTED */
-int16 util_calcDelayTime() {
+int16 Util::calcDelayTime() {
 	return 0;
 }
 
 /* NOT IMPLEMENTED */
-void util_checkJoystick() {
-	useJoystick = 0;
+void Util::checkJoystick() {
+	_vm->_global->useJoystick = 0;
 }
 
-void util_setFrameRate(int16 rate) {
+void Util::setFrameRate(int16 rate) {
 	if (rate == 0)
 		rate = 1;
 
-	frameWaitTime = 1000 / rate;
-	startFrameTime = util_getTimeKey();
+	_vm->_global->frameWaitTime = 1000 / rate;
+	_vm->_global->startFrameTime = getTimeKey();
 }
 
-void util_waitEndFrame() {
+void Util::waitEndFrame() {
 	int32 time;
 
-	vid_waitRetrace(videoMode);
+	_vm->_video->waitRetrace(_vm->_global->videoMode);
 
-	time = util_getTimeKey() - startFrameTime;
+	time = getTimeKey() - _vm->_global->startFrameTime;
 	if (time > 1000 || time < 0) {
-		startFrameTime = util_getTimeKey();
+		_vm->_global->startFrameTime = getTimeKey();
 		return;
 	}
-	if (frameWaitTime - time > 0) {
-		util_delay(frameWaitTime - time);
+	if (_vm->_global->frameWaitTime - time > 0) {
+		delay(_vm->_global->frameWaitTime - time);
 	}
-	startFrameTime = util_getTimeKey();
+	_vm->_global->startFrameTime = getTimeKey();
 }
 
 int16 joy_getState() {
@@ -266,14 +270,14 @@
 	return 0;
 }
 
-FontDesc *util_loadFont(const char *path) {
-	FontDesc *fontDesc = (FontDesc *) malloc(sizeof(FontDesc));
+Video::FontDesc *Util::loadFont(const char *path) {
+	Video::FontDesc *fontDesc = (Video::FontDesc *) malloc(sizeof(Video::FontDesc));
 	char *data;
 
 	if (fontDesc == 0)
 		return 0;
 
-	data = data_getData(path);
+	data = _vm->_dataio->getData(path);
 	if (data == 0) {
 		free(fontDesc);
 		return 0;
@@ -298,20 +302,20 @@
 	return fontDesc;
 }
 
-void util_freeFont(FontDesc * fontDesc) {
+void Util::freeFont(Video::FontDesc * fontDesc) {
 	free(fontDesc->dataPtr - 4);
 	free(fontDesc);
 }
 
-void util_clearPalette(void) {
+void Util::clearPalette(void) {
 	int16 i;
 	byte colors[768];
 
-	if (videoMode != 0x13)
-		error("util_clearPalette: Video mode 0x%x is not supported!",
-		    videoMode);
+	if (_vm->_global->videoMode != 0x13)
+		error("clearPalette: Video mode 0x%x is not supported!",
+		    _vm->_global->videoMode);
 
-	if (setAllPalette) {
+	if (_vm->_global->setAllPalette) {
 		for (i = 0; i < 768; i++)
 			colors[i] = 0;
 		g_system->setPalette(colors, 0, 256);
@@ -320,10 +324,10 @@
 	}
 
 	for (i = 0; i < 16; i++)
-		vid_setPalElem(i, 0, 0, 0, 0, videoMode);
+		_vm->_video->setPalElem(i, 0, 0, 0, 0, _vm->_global->videoMode);
 }
 
-void util_insertStr(const char *str1, char *str2, int16 pos) {
+void Util::insertStr(const char *str1, char *str2, int16 pos) {
 	int16 len1;
 	int16 i;
 	int16 from;
@@ -342,11 +346,11 @@
 		str2[i + from] = str1[i];
 }
 
-void util_cutFromStr(char *str, int16 from, int16 cutlen) {
+void Util::cutFromStr(char *str, int16 from, int16 cutlen) {
 	int16 len;
 	int16 i;
 
-	//log_write("util_cutFromStr: str = %s, ", str);
+	//log_write("cutFromStr: str = %s, ", str);
 	len = strlen(str);
 	if (from >= len)
 		return;
@@ -364,12 +368,12 @@
 	//log_write("res = %s\n", str);
 }
 
-int16 util_strstr(const char *str1, char *str2) {
+int16 Util::strstr(const char *str1, char *str2) {
 	char c;
 	uint16 len1;
 	uint16 i;
 
-	//log_write("util_strstr: str1 = %s, str2 = %s\n", str1, str2);
+	//log_write("strstr: str1 = %s, str2 = %s\n", str1, str2);
 
 	for (i = 0, len1 = strlen(str1); strlen(str2 + i) >= len1; i++) {
 		c = str2[i + len1];
@@ -383,10 +387,10 @@
 	return 0;
 }
 
-void util_listInsertFront(Util_List * list, void *data) {
-	Util_ListNode *node;
+void Util::listInsertFront(List * list, void *data) {
+	ListNode *node;
 
-	node = (Util_ListNode *) malloc(sizeof(Util_ListNode));
+	node = (ListNode *) malloc(sizeof(ListNode));
 	if (list->pHead != 0) {
 		node->pData = data;
 		node->pNext = list->pHead;
@@ -402,28 +406,28 @@
 	}
 }
 
-void util_listInsertBack(Util_List * list, void *data) {
-	Util_ListNode *node;
+void Util::listInsertBack(List * list, void *data) {
+	ListNode *node;
 
 	if (list->pHead != 0) {
 		if (list->pTail == 0) {
 			list->pTail = list->pHead;
-			warning("util_listInsertBack: Broken list!");
+			warning("listInsertBack: Broken list!");
 		}
 
 		node =
-		    (Util_ListNode *) malloc(sizeof(Util_ListNode));
+		    (ListNode *) malloc(sizeof(ListNode));
 		node->pData = data;
 		node->pPrev = list->pTail;
 		node->pNext = 0;
 		list->pTail->pNext = node;
 		list->pTail = node;
 	} else {
-		util_listInsertFront(list, data);
+		listInsertFront(list, data);
 	}
 }
 
-void util_listDropFront(Util_List * list) {
+void Util::listDropFront(List * list) {
 	if (list->pHead->pNext == 0) {
 		free((list->pHead));
 		list->pHead = 0;
@@ -435,50 +439,50 @@
 	}
 }
 
-void util_deleteList(Util_List * list) {
+void Util::deleteList(List * list) {
 	while (list->pHead != 0) {
-		util_listDropFront(list);
+		listDropFront(list);
 	}
 
 	free(list);
 }
 
-char util_str1[] =
+const char Util::trStr1[] =
     "       '   + - :0123456789: <=>  abcdefghijklmnopqrstuvwxyz      abcdefghijklmnopqrstuvwxyz     ";
-char util_str2[] =
+const char Util::trStr2[] =
     " ueaaaaceeeiii     ooouu        aioun                                                           ";
-char util_str3[] = "                                ";
+const char Util::trStr3[] = "                                ";
 
-void util_prepareStr(char *str) {
+void Util::prepareStr(char *str) {
 	uint16 i;
 	int16 j;
 	char buf[300];
 
-	strcpy(buf, util_str1);
-	strcat(buf, util_str2);
-	strcat(buf, util_str3);
+	strcpy(buf, trStr1);
+	strcat(buf, trStr2);
+	strcat(buf, trStr3);
 
 	for (i = 0; i < strlen(str); i++)
 		str[i] = buf[str[i] - 32];
 
 	while (str[0] == ' ')
-		util_cutFromStr(str, 0, 1);
+		cutFromStr(str, 0, 1);
 
 	while (strlen(str) > 0 && str[strlen(str) - 1] == ' ')
-		util_cutFromStr(str, strlen(str) - 1, 1);
+		cutFromStr(str, strlen(str) - 1, 1);
 
-	i = util_strstr(" ", str);
+	i = strstr(" ", str);
 
 	while (1) {
 		if (i == 0)
 			return;
 
 		if (str[i] == ' ') {
-			util_cutFromStr(str, i - 1, 1);
+			cutFromStr(str, i - 1, 1);
 			continue;
 		}
 
-		j = util_strstr(" ", str + i);
+		j = strstr(" ", str + i);
 		if (j != 0)
 			i += j;
 		else
@@ -486,18 +490,18 @@
 	}
 }
 
-void util_waitMouseRelease(char drawMouse) {
+void Util::waitMouseRelease(char drawMouse) {
 	int16 buttons;
 	int16 mouseX;
 	int16 mouseY;
 
 	do {
-		game_checkKeys(&mouseX, &mouseY, &buttons, drawMouse);
+		_vm->_game->checkKeys(&mouseX, &mouseY, &buttons, drawMouse);
 		if (drawMouse != 0)
-			draw_animateCursor(2);
-		util_delay(10);
+			_vm->_draw->animateCursor(2);
+		delay(10);
 	} while (buttons != 0);
 }
 
-void keyboard_release(void) {;}
+void Util::keyboard_release(void) {;}
 } // End of namespace Gob

Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/util.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- util.h	18 Oct 2005 01:30:18 -0000	1.6
+++ util.h	3 Jan 2006 23:14:39 -0000	1.7
@@ -26,57 +26,80 @@
 
 namespace Gob {
 
-struct Util_ListNode;
-typedef struct Util_ListNode {
-	void *pData;
-	struct Util_ListNode *pNext;
-	struct Util_ListNode *pPrev;
-} Util_ListNode;
+#define KEYBUFSIZE 16
 
-typedef struct Util_List {
-	Util_ListNode *pHead;
-	Util_ListNode *pTail;
-} Util_List;
+class Util {
+public:
+	struct ListNode;
+	typedef struct ListNode {
+		void *pData;
+		struct ListNode *pNext;
+		struct ListNode *pPrev;
+		ListNode() : pData(0), pNext(0), pPrev(0) {}
+	} ListNode;
 
-void util_initInput(void);
-void util_processInput(void);
-void util_waitKey(void);
-int16 util_getKey(void);
-int16 util_checkKey(void);
-int16 util_getRandom(int16 max);
-void util_getMouseState(int16 *pX, int16 *pY, int16 *pButtons);
-void util_setMousePos(int16 x, int16 y);
-void util_longDelay(uint16 msecs);
-void util_delay(uint16 msecs);
-void util_beep(int16 freq);
-uint32 util_getTimeKey(void);
-void util_waitMouseUp(void);
-void util_waitMouseDown(void);
+	typedef struct List {
+		ListNode *pHead;
+		ListNode *pTail;
+		List() : pHead(0), pTail(0) {}
+	} List;
 
-void keyboard_init(void);
-void keyboard_release(void);
+	void initInput(void);
+	void processInput(void);
+	void waitKey(void);
+	int16 getKey(void);
+	int16 checkKey(void);
+	int16 getRandom(int16 max);
+	void getMouseState(int16 *pX, int16 *pY, int16 *pButtons);
+	void setMousePos(int16 x, int16 y);
+	void longDelay(uint16 msecs);
+	void delay(uint16 msecs);
+	void beep(int16 freq);
+	uint32 getTimeKey(void);
+	void waitMouseUp(void);
+	void waitMouseDown(void);
 
-void util_clearPalette(void);
+	void keyboard_init(void);
+	void keyboard_release(void);
 
-void asm_setPaletteBlock(char *tmpPalBuffer, int16 start, int16 end);
+	void clearPalette(void);
 
-void vid_waitRetrace(int16 mode);
+	void asm_setPaletteBlock(char *tmpPalBuffer, int16 start, int16 end);
 
-FontDesc *util_loadFont(const char *path);
-void util_freeFont(FontDesc * fontDesc);
-void util_clearPalette(void);
-void util_insertStr(const char *str1, char *str2, int16 pos);
-void util_cutFromStr(char *str, int16 from, int16 cutlen);
-int16 util_strstr(const char *str1, char *str2);
-void util_waitEndFrame();
-void util_setFrameRate(int16 rate);
+	void vid_waitRetrace(int16 mode);
 
-void util_listInsertBack(Util_List * list, void *data);
-void util_listInsertFront(Util_List * list, void *data);
-void util_listDropFront(Util_List * list);
-void util_deleteList(Util_List * list);
-void util_prepareStr(char *str);
-void util_waitMouseRelease(char drawMouse);
+	Video::FontDesc *loadFont(const char *path);
+	void freeFont(Video::FontDesc * fontDesc);
+	void insertStr(const char *str1, char *str2, int16 pos);
+	void cutFromStr(char *str, int16 from, int16 cutlen);
+	int16 strstr(const char *str1, char *str2);
+	void waitEndFrame();
+	void setFrameRate(int16 rate);
+
+	void listInsertBack(List * list, void *data);
+	void listInsertFront(List * list, void *data);
+	void listDropFront(List * list);
+	void deleteList(List * list);
+	void prepareStr(char *str);
+	void waitMouseRelease(char drawMouse);
+
+	static const char trStr1[];
+	static const char trStr2[];
+	static const char trStr3[];
+	Util(GobEngine *vm);
+
+protected:
+	int16 _mouseX, _mouseY, _mouseButtons;
+	int16 _keyBuffer[KEYBUFSIZE], _keyBufferHead, _keyBufferTail;
+	GobEngine *_vm;
+
+	void addKeyToBuffer(int16 key);
+	bool keyBufferEmpty();
+	bool getKeyFromBuffer(int16& key);
+	int16 translateKey(int16 key);
+	int16 calcDelayTime();
+	void checkJoystick();
+};
 
 }				// End of namespace Gob
 

Index: video.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/video.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- video.cpp	18 Oct 2005 01:30:18 -0000	1.16
+++ video.cpp	3 Jan 2006 23:14:39 -0000	1.17
@@ -28,22 +28,22 @@
 
 namespace Gob {
 
-VideoDriver *_videoDriver;
-
-
 /* NOT IMPLEMENTED */
 
+Video::Video(GobEngine *vm) : _vm(vm) {
+}
+
 //XXX: Use this function to update the screen for now.
 //     This should be moved to a better location later on.
-void vid_waitRetrace(int16) {
-	if (pPrimarySurfDesc) {
-		g_system->copyRectToScreen(pPrimarySurfDesc->vidPtr, 320, 0, 0, 320, 200);
+void Video::waitRetrace(int16) {
+	if (_vm->_global->pPrimarySurfDesc) {
+		g_system->copyRectToScreen(_vm->_global->pPrimarySurfDesc->vidPtr, 320, 0, 0, 320, 200);
 		g_system->updateScreen();
 	}
 }
 
-char vid_initDriver(int16 vidMode) {
-	warning("STUB: vid_initDriver");
+char Video::initDriver(int16 vidMode) {
+	warning("STUB: Video::initDriver");
 
 	// FIXME: Finish all this stuff :)
 	_videoDriver = new VGAVideoDriver();
@@ -51,17 +51,17 @@
 	return 1;
 }
 
-void vid_freeDriver() {
+void Video::freeDriver() {
 	delete _videoDriver;
-	warning("STUB: vid_freeDriver");
+	warning("STUB: Video::freeDriver");
 }
 
-int32 vid_getRectSize(int16 width, int16 height, int16 flag, int16 mode) {
+int32 Video::getRectSize(int16 width, int16 height, int16 flag, int16 mode) {
 	int32 size;
 
 	if ((mode & 0x7f) != 0x13)
 		warning
-		    ("vid_getRectSize: Video mode %d is not fully supported!",
+		    ("Video::getRectSize: Video mode %d is not fully supported!",
 		    mode & 0x7f);
 	switch (mode & 0x7f) {
 	case 5:
@@ -83,7 +83,7 @@
 	return size;
 }
 
-SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags) {
+Video::SurfaceDesc *Video::initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags) {
 	int8 flagsAnd2;
 	byte *vidMem;
 	int32 sprSize;
@@ -91,13 +91,13 @@
 	SurfaceDesc *descPtr;
 
 	if (flags != PRIMARY_SURFACE)
-		sprAllocated++;
+		_vm->_global->sprAllocated++;
 
 	if (flags & RETURN_PRIMARY)
-		return pPrimarySurfDesc;
+		return _vm->_global->pPrimarySurfDesc;
 
 	if (vidMode != 0x13)
-		error("vid_initSurfDesc: Only VGA 0x13 mode is supported!");
+		error("Video::initSurfDesc: Only VGA 0x13 mode is supported!");
 
 	if ((flags & PRIMARY_SURFACE) == 0)
 		vidMode += 0x80;
@@ -109,20 +109,20 @@
 
 	if (flags & PRIMARY_SURFACE) {
 		vidMem = 0;
-		primaryWidth = width;
-		mouseMaxCol = width;
-		primaryHeight = height;
-		mouseMaxRow = height;
+		_vm->_global->primaryWidth = width;
+		_vm->_global->mouseMaxCol = width;
+		_vm->_global->primaryHeight = height;
+		_vm->_global->mouseMaxRow = height;
 		sprSize = 0;
 
 	} else {
 		vidMem = 0;
-		sprSize = vid_getRectSize(width, height, flagsAnd2, vidMode);
+		sprSize = Video::getRectSize(width, height, flagsAnd2, vidMode);
 		if (flagsAnd2)
 			someFlags += 0x80;
 	}
 	if (flags & PRIMARY_SURFACE) {
-		descPtr = pPrimarySurfDesc;
+		descPtr = _vm->_global->pPrimarySurfDesc;
 		vidMem = (byte *)malloc(320 * 200);
 	} else {
 		if (flags & DISABLE_SPR_ALLOC)
@@ -146,15 +146,15 @@
 	return descPtr;
 }
 
-void vid_freeSurfDesc(SurfaceDesc * surfDesc) {
-	sprAllocated--;
-	if (surfDesc != pPrimarySurfDesc)
+void Video::freeSurfDesc(SurfaceDesc * surfDesc) {
+	_vm->_global->sprAllocated--;
+	if (surfDesc != _vm->_global->pPrimarySurfDesc)
 		free(surfDesc);
 	else
 		free(surfDesc->vidPtr);
 }
 
-int16 vid_clampValue(int16 val, int16 max) {
+int16 Video::clampValue(int16 val, int16 max) {
 	if (val >= max)
 		val = max - 1;
 
@@ -164,13 +164,13 @@
 	return val;
 }
 
-void vid_drawSprite(SurfaceDesc *source, SurfaceDesc *dest,
+void Video::drawSprite(SurfaceDesc *source, SurfaceDesc *dest,
 	    int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) {
 	int16 temp;
 	int16 destRight;
 	int16 destBottom;
 
-	if (doRangeClamp) {
+	if (_vm->_global->doRangeClamp) {
 		if (left > right) {
 			temp = left;
 			left = right;
@@ -198,8 +198,8 @@
 			y -= top;
 			top = 0;
 		}
-		right = vid_clampValue(right, source->width);
-		bottom = vid_clampValue(bottom, source->height);
+		right = Video::clampValue(right, source->width);
+		bottom = Video::clampValue(bottom, source->height);
 		if (right - left >= source->width)
 			right = left + source->width - 1;
 		if (bottom - top >= source->height)
@@ -236,11 +236,11 @@
 	_videoDriver->drawSprite(source, dest, left, top, right, bottom, x, y, transp);
 }
 
-void vid_fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom,
+void Video::fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom,
 	    int16 color) {
 	int16 temp;
 
-	if (doRangeClamp) {
+	if (_vm->_global->doRangeClamp) {
 		if (left > right) {
 			temp = left;
 			left = right;
@@ -260,64 +260,64 @@
 		if (top >= dest->height)
 			return;
 
-		left = vid_clampValue(left, dest->width);
-		top = vid_clampValue(top, dest->height);
-		right = vid_clampValue(right, dest->width);
-		bottom = vid_clampValue(bottom, dest->height);
+		left = Video::clampValue(left, dest->width);
+		top = Video::clampValue(top, dest->height);
+		right = Video::clampValue(right, dest->width);
+		bottom = Video::clampValue(bottom, dest->height);
 	}
 
 	_videoDriver->fillRect(dest, left, top, right, bottom, color);
 }
 
-void vid_drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, int16 color) {
+void Video::drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, int16 color) {
 	if (x0 == x1 || y0 == y1) {
-		vid_fillRect(dest, x0, y0, x1, y1, color);
+		Video::fillRect(dest, x0, y0, x1, y1, color);
 		return;
 	}
 
 	_videoDriver->drawLine(dest, x0, y0, x1, y1, color);
 }
 
-void vid_putPixel(int16 x, int16 y, int16 color, SurfaceDesc *dest) {
+void Video::putPixel(int16 x, int16 y, int16 color, SurfaceDesc *dest) {
 	if (x < 0 || y < 0 || x >= dest->width || y >= dest->height)
 		return;
 
 	_videoDriver->putPixel(x, y, color, dest);
 }
 
-void vid_drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, int16 color1,
+void Video::drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, int16 color1,
 	    int16 color2, int16 transp, SurfaceDesc *dest) {
 
 	_videoDriver->drawLetter(item, x, y, fontDesc, color1, color2, transp, dest);
 }
 
-void vid_clearSurf(SurfaceDesc *dest) {
-	vid_fillRect(dest, 0, 0, dest->width - 1, dest->height - 1, 0);
+void Video::clearSurf(SurfaceDesc *dest) {
+	Video::fillRect(dest, 0, 0, dest->width - 1, dest->height - 1, 0);
 }
 
-void vid_drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y,
+void Video::drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y,
 	    int16 transp, SurfaceDesc *dest) {
 
-	if (vid_spriteUncompressor(sprBuf, width, height, x, y, transp, dest))
+	if (Video::spriteUncompressor(sprBuf, width, height, x, y, transp, dest))
 		return;
 
 	if ((dest->vidMode & 0x7f) != 0x13)
-		error("vid_drawPackedSprite: Vide mode 0x%x is not fully supported!",
+		error("Video::drawPackedSprite: Vide mode 0x%x is not fully supported!",
 		    dest->vidMode & 0x7f);
 
 	_videoDriver->drawPackedSprite(sprBuf, width, height, x, y, transp, dest);
 }
 
-void vid_setPalElem(int16 index, char red, char green, char blue, int16 unused,
+void Video::setPalElem(int16 index, char red, char green, char blue, int16 unused,
 	    int16 vidMode) {
 	byte pal[4];
 
-	redPalette[index] = red;
-	greenPalette[index] = green;
-	bluePalette[index] = blue;
+	_vm->_global->redPalette[index] = red;
+	_vm->_global->greenPalette[index] = green;
+	_vm->_global->bluePalette[index] = blue;
 
 	if (vidMode != 0x13)
-		error("vid_setPalElem: Video mode 0x%x is not supported!",
+		error("Video::setPalElem: Video mode 0x%x is not supported!",
 		    vidMode);
 
 	pal[0] = (red << 2) | (red >> 4);
@@ -327,16 +327,16 @@
 	g_system->setPalette(pal, index, 1);
 }
 
-void vid_setPalette(PalDesc *palDesc) {
+void Video::setPalette(PalDesc *palDesc) {
 	int16 i;
 	byte pal[1024];
 	int16 numcolors;
 
-	if (videoMode != 0x13)
-		error("vid_setPalette: Video mode 0x%x is not supported!",
-		    videoMode);
+	if (_vm->_global->videoMode != 0x13)
+		error("Video::setPalette: Video mode 0x%x is not supported!",
+		    _vm->_global->videoMode);
 
-	if (setAllPalette)
+	if (_vm->_global->setAllPalette)
 		numcolors = 256;
 	else
 		numcolors = 16;
@@ -351,17 +351,17 @@
 	g_system->setPalette(pal, 0, numcolors);
 }
 
-void vid_setFullPalette(PalDesc *palDesc) {
+void Video::setFullPalette(PalDesc *palDesc) {
 	Color *colors;
 	int16 i;
 	byte pal[1024];
 
-	if (setAllPalette) {
+	if (_vm->_global->setAllPalette) {
 		colors = palDesc->vgaPal;
 		for (i = 0; i < 256; i++) {
-			redPalette[i] = colors[i].red;
-			greenPalette[i] = colors[i].green;
-			bluePalette[i] = colors[i].blue;
+			_vm->_global->redPalette[i] = colors[i].red;
+			_vm->_global->greenPalette[i] = colors[i].green;
+			_vm->_global->bluePalette[i] = colors[i].blue;
 		}
 
 		for (i = 0; i < 256; i++) {
@@ -372,46 +372,46 @@
 		}
 		g_system->setPalette(pal, 0, 256);
 	} else {
-		vid_setPalette(palDesc);
+		Video::setPalette(palDesc);
 	}
 }
 
-void vid_initPrimary(int16 mode) {
+void Video::initPrimary(int16 mode) {
 	int16 old;
-	if (curPrimaryDesc) {
-		vid_freeSurfDesc(curPrimaryDesc);
-		vid_freeSurfDesc(allocatedPrimary);
+	if (_vm->_global->curPrimaryDesc) {
+		Video::freeSurfDesc(_vm->_global->curPrimaryDesc);
+		Video::freeSurfDesc(_vm->_global->allocatedPrimary);
 
-		curPrimaryDesc = 0;
-		allocatedPrimary = 0;
+		_vm->_global->curPrimaryDesc = 0;
+		_vm->_global->allocatedPrimary = 0;
 	}
 	if (mode != 0x13 && mode != 3 && mode != -1)
-		error("vid_initPrimary: Video mode 0x%x is not supported!",
+		error("Video::initPrimary: Video mode 0x%x is not supported!",
 		    mode);
 
-	if (videoMode != 0x13)
-		error("vid_initPrimary: Video mode 0x%x is not supported!",
+	if (_vm->_global->videoMode != 0x13)
+		error("Video::initPrimary: Video mode 0x%x is not supported!",
 		    mode);
 
-	old = oldMode;
+	old = _vm->_global->oldMode;
 	if (mode == -1)
 		mode = 3;
 
-	oldMode = mode;
+	_vm->_global->oldMode = mode;
 	if (mode != 3)
-		vid_initDriver(mode);
+		Video::initDriver(mode);
 
 	if (mode != 3) {
-		vid_initSurfDesc(mode, 320, 200, PRIMARY_SURFACE);
+		Video::initSurfDesc(mode, 320, 200, PRIMARY_SURFACE);
 
-		if (dontSetPalette)
+		if (_vm->_global->dontSetPalette)
 			return;
 
-		vid_setFullPalette(pPaletteDesc);
+		Video::setFullPalette(_vm->_global->pPaletteDesc);
 	}
 }
 
-char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight,
+char Video::spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight,
 	    int16 x, int16 y, int16 transp, SurfaceDesc *destDesc) {
 	SurfaceDesc sourceDesc;
 	byte *memBuffer;
@@ -432,7 +432,7 @@
 		return 1;
 
 	if ((destDesc->vidMode & 0x7f) != 0x13)
-		error("vid_spriteUncompressor: Video mode 0x%x is not supported!",
+		error("Video::spriteUncompressor: Video mode 0x%x is not supported!",
 		    destDesc->vidMode & 0x7f);
 
 	if (sprBuf[0] != 1)
@@ -446,7 +446,7 @@
 		sourceDesc.height = srcHeight;
 		sourceDesc.vidMode = 0x93;
 		sourceDesc.vidPtr = sprBuf + 3;
-		vid_drawSprite(&sourceDesc, destDesc, 0, 0, srcWidth - 1,
+		Video::drawSprite(&sourceDesc, destDesc, 0, 0, srcWidth - 1,
 		    srcHeight - 1, x, y, transp);
 		return 1;
 	} else {
@@ -540,8 +540,6 @@
 	return 1;
 }
 
-void vid_setHandlers() {
-	setAllPalette = 1;
-}
+void Video::setHandlers() { _vm->_global->setAllPalette = 1; }
 
 }				// End of namespace Gob

Index: video.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/video.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- video.h	18 Oct 2005 01:30:18 -0000	1.10
+++ video.h	3 Jan 2006 23:14:39 -0000	1.11
@@ -24,6 +24,7 @@
 
 #include "common/stdafx.h"
 #include "common/util.h"
+#include "gob/gob.h"
 
 namespace Gob {
 
@@ -35,40 +36,34 @@
 #define TEXT_COL_COUNT	80
 #define TEXT_ROW_COUNT	25
 
+extern int16 setAllPalette;
 
-typedef struct SurfaceDesc_t {
-	int16 width;
-	int16 height;
-	int8 reserved1;
-	int8 flag;
-	int16 vidMode;
-	byte *vidPtr;
-	int16 reserved2;
-} SurfaceDesc;
-
-typedef struct FontDesc_t {
-	char *dataPtr;
-	int8 itemWidth;
-	int8 itemHeight;
-	int8 startItem;
-	int8 endItem;
-	int8 itemSize;
-	int8 bitWidth;
-	void *extraData;
-} FontDesc;
-
-
-class VideoDriver {
+class Video {
 public:
-	VideoDriver() {}
-	virtual ~VideoDriver() {}
-	virtual void drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) = 0;
-	virtual void fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) = 0;
-	virtual void putPixel(int16 x, int16 y, byte color, SurfaceDesc *dest) = 0;
-	virtual void drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc *dest) = 0;
-	virtual void drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) = 0;
-	virtual void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc *dest) = 0;
-};
+	typedef struct SurfaceDesc_t {
+		int16 width;
+		int16 height;
+		int8 reserved1;
+		int8 flag;
+		int16 vidMode;
+		byte *vidPtr;
+		int16 reserved2;
+		SurfaceDesc_t() : width(0), height(0), reserved1(0), flag(0),
+						  vidMode(0), vidPtr(0), reserved2(0) {}
+	} SurfaceDesc;
+
+	typedef struct FontDesc_t {
+		char *dataPtr;
+		int8 itemWidth;
+		int8 itemHeight;
+		int8 startItem;
+		int8 endItem;
+		int8 itemSize;
+		int8 bitWidth;
+		void *extraData;
+		FontDesc_t() : dataPtr(0), itemWidth(0), itemHeight(0), startItem(0),
+			               endItem(0), itemSize(0), bitWidth(0) {}
+	} FontDesc;
 
 #define GDR_VERSION	4
 
@@ -76,52 +71,69 @@
 #define RETURN_PRIMARY		0x01
 #define DISABLE_SPR_ALLOC	0x20
 
-#if !defined(__GNUC__)
-	#pragma START_PACK_STRUCTS
-#endif
+#pragma START_PACK_STRUCTS
 
-typedef struct Color {
-	byte red;
-	byte green;
-	byte blue;
-} GCC_PACK Color;
+	typedef struct Color {
+		byte red;
+		byte green;
+		byte blue;
+	} GCC_PACK Color;
 
-#if !defined(__GNUC__)
-	#pragma END_PACK_STRUCTS
-#endif
+#pragma END_PACK_STRUCTS
 
-typedef struct PalDesc {
-	Color *vgaPal;
-	int16 *unused1;
-	int16 *unused2;
-} PalDesc;
+	typedef struct PalDesc {
+		Color *vgaPal;
+		int16 *unused1;
+		int16 *unused2;
+		PalDesc() : vgaPal(0), unused1(0), unused2(0) {}
+	} PalDesc;
 
-char vid_initDriver(int16 vidMode);
-void vid_freeDriver(void);
-int32 vid_getRectSize(int16 width, int16 height, int16 flag, int16 mode);
-SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags);
-void vid_freeSurfDesc(SurfaceDesc * surfDesc);
-int16 vid_clampValue(int16 val, int16 max);
-void vid_drawSprite(SurfaceDesc * source, SurfaceDesc * dest, int16 left,
-    int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp);
-void vid_fillRect(SurfaceDesc * dest, int16 left, int16 top, int16 right, int16 bottom,
-    int16 color);
-void vid_drawLine(SurfaceDesc * dest, int16 x0, int16 y0, int16 x1, int16 y1,
-    int16 color);
-void vid_putPixel(int16 x, int16 y, int16 color, SurfaceDesc * dest);
-void vid_drawLetter(unsigned char item, int16 x, int16 y, FontDesc * fontDesc, int16 color1,
-    int16 color2, int16 transp, SurfaceDesc * dest);
-void vid_clearSurf(SurfaceDesc * dest);
-void vid_drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y,
-    int16 transp, SurfaceDesc * dest);
-void vid_setPalElem(int16 index, char red, char green, char blue, int16 unused,
-    int16 vidMode);
-void vid_setPalette(PalDesc * palDesc);
-void vid_setFullPalette(PalDesc * palDesc);
-void vid_initPrimary(int16 mode);
-char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, int16 x,
-    int16 y, int16 transp, SurfaceDesc * destDesc);
-void vid_setHandlers(void);
+	Video(class GobEngine *vm);
+	int32 getRectSize(int16 width, int16 height, int16 flag, int16 mode);
+	SurfaceDesc *initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags);
+	void freeSurfDesc(SurfaceDesc * surfDesc);
+	int16 clampValue(int16 val, int16 max);
+	void drawSprite(SurfaceDesc * source, SurfaceDesc * dest, int16 left,
+					int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp);
+	void fillRect(SurfaceDesc * dest, int16 left, int16 top, int16 right, int16 bottom,
+				  int16 color);
+	void drawLine(SurfaceDesc * dest, int16 x0, int16 y0, int16 x1, int16 y1,
+				  int16 color);
+	void putPixel(int16 x, int16 y, int16 color, SurfaceDesc * dest);
+	void drawLetter(unsigned char item, int16 x, int16 y, FontDesc * fontDesc, int16 color1,
+					int16 color2, int16 transp, SurfaceDesc * dest);
+	void clearSurf(SurfaceDesc * dest);
+	void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y,
+						  int16 transp, SurfaceDesc * dest);
+	void setPalElem(int16 index, char red, char green, char blue, int16 unused,
+					int16 vidMode);
+	void setPalette(PalDesc * palDesc);
+	void setFullPalette(PalDesc * palDesc);
+	void initPrimary(int16 mode);
+	char spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, int16 x,
+							int16 y, int16 transp, SurfaceDesc * destDesc);
+	void waitRetrace(int16);
+	void freeDriver(void);
+	void setHandlers();
+
+protected:
+	class VideoDriver *_videoDriver;
+	GobEngine *_vm;
+
+	char initDriver(int16 vidMode);
+};
+
+class VideoDriver {
+public:
+	VideoDriver() {}
+	virtual ~VideoDriver() {}
+	virtual void drawSprite(Video::SurfaceDesc *source, Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) = 0;
+	virtual void fillRect(Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) = 0;
+	virtual void putPixel(int16 x, int16 y, byte color, Video::SurfaceDesc *dest) = 0;
+	virtual void drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, Video::SurfaceDesc *dest) = 0;
+	virtual void drawLine(Video::SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) = 0;
+	virtual void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, Video::SurfaceDesc *dest) = 0;
+};
 
 }				// End of namespace Gob
 





More information about the Scummvm-git-logs mailing list