[Scummvm-cvs-logs] CVS: scummvm/sky autoroute.cpp,1.26,1.27 autoroute.h,1.11,1.12 compact.cpp,1.26,1.27 compact.h,1.12,1.13 control.cpp,1.81,1.82 control.h,1.34,1.35 debug.cpp,1.15,1.16 debug.h,1.7,1.8 disk.cpp,1.62,1.63 disk.h,1.16,1.17 grid.cpp,1.17,1.18 grid.h,1.10,1.11 logic.cpp,1.148,1.149 logic.h,1.39,1.40 mouse.cpp,1.37,1.38 mouse.h,1.26,1.27 screen.cpp,1.62,1.63 screen.h,1.19,1.20 sky.cpp,1.164,1.165 sky.h,1.62,1.63 skydefs.h,1.28,1.29 struc.h,1.15,1.16 text.cpp,1.62,1.63 text.h,1.32,1.33 talks.h,1.5,NONE

Robert Göffringmann lavosspawn at users.sourceforge.net
Tue Dec 14 22:50:04 CET 2004


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

Modified Files:
	autoroute.cpp autoroute.h compact.cpp compact.h control.cpp 
	control.h debug.cpp debug.h disk.cpp disk.h grid.cpp grid.h 
	logic.cpp logic.h mouse.cpp mouse.h screen.cpp screen.h 
	sky.cpp sky.h skydefs.h struc.h text.cpp text.h 
Removed Files:
	talks.h 
Log Message:
moved compacts and related static data out of the scummvm.exe into an external file
(available from www.lavosspawn.de/tmp/sky_cpt.zip)

Index: autoroute.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/autoroute.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- autoroute.cpp	22 Oct 2004 17:05:29 -0000	1.26
+++ autoroute.cpp	15 Dec 2004 06:48:03 -0000	1.27
@@ -37,9 +37,10 @@
 const int16 AutoRoute::_routeDirections[4] = {    -1,     1, -ROUTE_GRID_WIDTH, ROUTE_GRID_WIDTH };
 const uint16 AutoRoute::_logicCommands[4] = { RIGHTY, LEFTY,             DOWNY,              UPY };
 
-AutoRoute::AutoRoute(Grid *pGrid) {
+AutoRoute::AutoRoute(Grid *pGrid, SkyCompact *compact) {
 
 	_grid = pGrid;
+	_skyCompact = compact;
 	_routeGrid = (uint16 *)malloc(ROUTE_GRID_SIZE);
 	_routeBuf = (uint16 *)malloc(ROUTE_SPACE);
 }
@@ -233,7 +234,7 @@
 uint16 AutoRoute::autoRoute(Compact *cpt) {
 
 	uint8 cptScreen = (uint8)cpt->screen;
-	uint8 cptWidth = (uint8)SkyCompact::getMegaSet(cpt, cpt->extCompact->megaSet)->gridWidth;
+	uint8 cptWidth = (uint8)SkyCompact::getMegaSet(cpt)->gridWidth;
 	initWalkGrid(cptScreen, cptWidth);
 
 	uint8 startX, startY, destX, destY;
@@ -241,15 +242,17 @@
 
 	clipCoordX(cpt->xcood, startX, initStaX);
 	clipCoordY(cpt->ycood, startY, initStaY);
-	clipCoordX(cpt->extCompact->arTargetX, destX, initDestX);
-	clipCoordY(cpt->extCompact->arTargetY, destY, initDestY);
+	clipCoordX(cpt->arTargetX, destX, initDestX);
+	clipCoordY(cpt->arTargetY, destY, initDestY);
 
-	memset(cpt->extCompact->animScratch, 0, 64);
+	uint16 *routeDest = (uint16*)_skyCompact->fetchCpt(cpt->animScratchId);
+	memset(routeDest, 0, 64);
 	if ((startX == destX) && (startY == destY))
 		return 2;
 
 	if (_routeGrid[(destY + 1) * ROUTE_GRID_WIDTH + destX + 1]) {
-		if ((cpt == &Sky::SkyCompact::foster) && (cptScreen == 12) && (destX == 2) && (destY == 14)) {
+		//if ((cpt == &Sky::SkyCompact::foster) && (cptScreen == 12) && (destX == 2) && (destY == 14)) {
+		if (_skyCompact->cptIsId(cpt, CPT_FOSTER) && (cptScreen == 12) && (destX == 2) && (destY == 14)) {
 			/* workaround for Scriptbug #1043047
 			   In screen 12 (the pipe factory) Joey can block Foster's target
 			   coordinates (2/14). This is normally not too tragic, but in the
@@ -271,8 +274,8 @@
 
 	uint8 cnt = 0;
 	do {
-		((uint16*)cpt->extCompact->animScratch)[cnt]     = routeData[cnt];
-		((uint16*)cpt->extCompact->animScratch)[cnt + 1] = routeData[cnt + 1];
+		routeDest[cnt]     = routeData[cnt];
+		routeDest[cnt + 1] = routeData[cnt + 1];
 		cnt += 2;
 	} while (routeData[cnt - 2]);
 	return 0;

Index: autoroute.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/autoroute.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- autoroute.h	6 Jan 2004 12:45:32 -0000	1.11
+++ autoroute.h	15 Dec 2004 06:48:04 -0000	1.12
@@ -29,10 +29,11 @@
 
 struct Compact;
 class Grid;
+class SkyCompact;
 
 class AutoRoute {
 public:
-	AutoRoute(Grid *pGrid);
+	AutoRoute(Grid *pGrid, SkyCompact *compact);
 	~AutoRoute(void);
 	uint16 autoRoute(Compact *cpt);
 private:
@@ -44,6 +45,7 @@
 	uint16 *makeRouteData(uint8 startX, uint8 startY, uint8 destX, uint8 destY);
 	uint16 *checkInitMove(uint16 *data, int16 initStaX);
 	Grid *_grid;
+	SkyCompact *_skyCompact;
 	uint16 *_routeGrid;
 	uint16 *_routeBuf;
 	static const int16 _routeDirections[4];

Index: compact.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/compact.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- compact.cpp	6 Jan 2004 12:45:32 -0000	1.26
+++ compact.cpp	15 Dec 2004 06:48:04 -0000	1.27
@@ -21,165 +21,25 @@
 
 #include "stdafx.h"
 #include "common/util.h"
+#include "common/file.h"
 #include "sky/compact.h"
-#include "sky/compacts/0compact.h"
-#include "sky/compacts/1compact.h"
-#include "sky/compacts/29comp.h"
-#include "sky/compacts/2compact.h"
-#include "sky/compacts/30comp.h"
-#include "sky/compacts/3compact.h"
-#include "sky/compacts/4compact.h"
-#include "sky/compacts/5compact.h"
-#include "sky/compacts/66comp.h"
-#include "sky/compacts/90comp.h"
-#include "sky/compacts/9compact.h"
-#include "sky/compacts/linc_gen.h"
-#include "sky/compacts/lincmenu.h"
-#include "sky/compacts/z_compac.h"
+#include "gui/message.h"
 
 namespace Sky {
 
-#define COMPACT_SIZE (sizeof(compactOffsets)/sizeof(uint32))
-#define EXTCOMPACT_SIZE (sizeof(extCompactOffsets)/sizeof(uint32))
-#define MEGASET_SIZE (sizeof(megaSetOffsets)/sizeof(uint32))
-#define TURNTABLE_SIZE (sizeof(turnTableOffsets)/sizeof(uint32))
-
 #define OFFS(type,item) (((long)(&((type*)0)->item)))
 #define MK32(type,item) OFFS(type, item),0,0,0
 #define MK16(type,item) OFFS(type, item),0
 #define MK32_A5(type, item) MK32(type, item[0]), MK32(type, item[1]), \
 	MK32(type, item[2]), MK32(type, item[3]), MK32(type, item[4])
 
-namespace TalkAnims {
-	extern bool animTalkTableIsPointer[];
-	extern uint16 animTalkTableVal[];
-	extern void *animTalkTablePtr[];
-}
-
-namespace SkyCompact {
-
-uint16 *getGrafixPtr(Compact *cpt) {
-	uint16 *buf;
-	switch (cpt->grafixProg.ptrType) {
-	case PTR_NULL:
-		return NULL;
-	case AUTOROUTE:
-		if (!cpt->extCompact)
-			error("::getGrafixPtr: request for AR pointer, extCompact is NULL, though.");
-		return (cpt->extCompact->animScratch + cpt->grafixProg.pos);
-	case COMPACT:
-		buf = (uint16*)SkyEngine::fetchCompact(cpt->grafixProg.ptrTarget);
-		if (buf == NULL)
-			error("::getGrafixPtr: request for cpt %d pointer. It's NULL.", cpt->grafixProg.ptrTarget);
-		return (buf + cpt->grafixProg.pos);
-	case COMPACTELEM:
-		buf = *(uint16 **)SkyCompact::getCompactElem(cpt, cpt->grafixProg.ptrTarget);
-		if (buf == NULL)
-			error("::getGrafixPtr: request for elem ptr %d. It's NULL.", cpt->grafixProg.ptrTarget);
-		return buf + cpt->grafixProg.pos;
-	case TALKTABLE:
-		buf = (uint16 *)TalkAnims::animTalkTablePtr[cpt->grafixProg.ptrTarget];
-		return buf + cpt->grafixProg.pos;
-	default:
-		error("::getGrafixPtr: unknown grafixProg type for Compact cpt");
-	}
-	return NULL; // never reached
-}
-
-/**
- * Returns the n'th mega set specified by \a megaSet from Compact \a cpt.
- */
-MegaSet *getMegaSet(Compact *cpt, uint16 megaSet) {
-	switch (megaSet) {
-	case 0:
-		return cpt->extCompact->megaSet0;
-	case NEXT_MEGA_SET:
-		return cpt->extCompact->megaSet1;
-	case NEXT_MEGA_SET*2:
-		return cpt->extCompact->megaSet2;
-	case NEXT_MEGA_SET*3:
-		return cpt->extCompact->megaSet3;
-	default:
-		error("Invalid MegaSet (%d)", megaSet);
-	}
-}
-
-/**
- \brief Returns the turn table for direction \a dir
- 	from Compact \a cpt in \a megaSet.
-  
- Functionally equivalent to:
- \verbatim
- clear eax
- mov al,20
- mul (cpt[esi]).c_dir
- add ax,(cpt[esi]).c_mega_set
- lea eax,(cpt[esi+eax]).c_turn_table_up
- \endverbatim
-*/
-uint16 **getTurnTable(Compact *cpt, uint16 megaSet, uint16 dir) {
-	MegaSet *m = getMegaSet(cpt, megaSet);
-	switch (dir) {
-	case 0:
-		return m->turnTable->turnTableUp;
-	case 1:
-		return m->turnTable->turnTableDown;
-	case 2:
-		return m->turnTable->turnTableLeft;
-	case 3:
-		return m->turnTable->turnTableRight;
-	case 4:
-		return m->turnTable->turnTableTalk;
-	default:
-		error("No TurnTable (%d) in MegaSet (%d)", dir, megaSet);
-	}
-}
-
-/**
- * \brief Returns the script for \a mode from Compact \a cpt.
- *        Add 2 to \a mode to get the offset.
- *
- \verbatim
- uint16 *scriptNo = SkyCompact::getSub(_compact, mode);
- uint16 *offset   = SkyCompact::getSub(_compact, mode + 2);
- uint32 script = (*offset << 16) | *scriptNo;
- \endverbatim
- * Is functionally equivalent to:
- \verbatim
- mov eax,c_base_sub[ebx+esi]
- \endverbatim
- where \a esi is the compact and ebx the mode.
- */ 
-uint16 *getSub(Compact *cpt, uint16 mode) {
-	switch (mode) {
-	case 0:
-		return &(cpt->baseSub);
-	case 2:
-		return &(cpt->baseSub_off);
-	case 4:
-		return &(cpt->extCompact->actionSub);
-	case 6:
-		return &(cpt->extCompact->actionSub_off);
-	case 8:
-		return &(cpt->extCompact->getToSub);
-	case 10:
-		return &(cpt->extCompact->getToSub_off);
-	case 12:
-		return &(cpt->extCompact->extraSub);
-	case 14:
-		return &(cpt->extCompact->extraSub_off);
-	default:
-		error("Invalid Mode (%d)", mode);
-	}
-}
-
 static const uint32 compactOffsets[] = {
 	MK16(Compact, logic),
 	MK16(Compact, status),
 	MK16(Compact, sync),
 	MK16(Compact, screen),
 	MK16(Compact, place),
-	MK32(Compact, getToTable),
+	MK32(Compact, getToTableId),
 	MK16(Compact, xcood),
 	MK16(Compact, ycood),
 	MK16(Compact, frame),
@@ -197,39 +57,36 @@
 	MK16(Compact, getToFlag),
 	MK16(Compact, flag),
 	MK16(Compact, mood),
-	MK32(Compact, grafixProg),
+	MK32(Compact, grafixProgId),
 	MK16(Compact, offset),
 	MK16(Compact, mode),
 	MK16(Compact, baseSub),
 	MK16(Compact, baseSub_off),
-};
-
-static const uint32 extCompactOffsets[] = {
-	MK16(ExtCompact, actionSub),
-	MK16(ExtCompact, actionSub_off),
-	MK16(ExtCompact, getToSub),
-	MK16(ExtCompact, getToSub_off),
-	MK16(ExtCompact, extraSub),
-	MK16(ExtCompact, extraSub_off),
-	MK16(ExtCompact, dir),
-	MK16(ExtCompact, stopScript),
-	MK16(ExtCompact, miniBump),
-	MK16(ExtCompact, leaving),
-	MK16(ExtCompact, atWatch),
-	MK16(ExtCompact, atWas),
-	MK16(ExtCompact, alt),
-	MK16(ExtCompact, request),
-	MK16(ExtCompact, spWidth_xx),
-	MK16(ExtCompact, spColour),
-	MK16(ExtCompact, spTextId),
-	MK16(ExtCompact, spTime),
-	MK16(ExtCompact, arAnimIndex),
-	MK32(ExtCompact, turnProg),
-	MK16(ExtCompact, waitingFor),
-	MK16(ExtCompact, arTargetX),
-	MK16(ExtCompact, arTargetY),
-	MK32(ExtCompact, animScratch),
-	MK16(ExtCompact, megaSet),
+	MK16(Compact, actionSub),
+	MK16(Compact, actionSub_off),
+	MK16(Compact, getToSub),
+	MK16(Compact, getToSub_off),
+	MK16(Compact, extraSub),
+	MK16(Compact, extraSub_off),
+	MK16(Compact, dir),
+	MK16(Compact, stopScript),
+	MK16(Compact, miniBump),
+	MK16(Compact, leaving),
+	MK16(Compact, atWatch),
+	MK16(Compact, atWas),
+	MK16(Compact, alt),
+	MK16(Compact, request),
+	MK16(Compact, spWidth_xx),
+	MK16(Compact, spColour),
+	MK16(Compact, spTextId),
+	MK16(Compact, spTime),
+	MK16(Compact, arAnimIndex),
+	MK32(Compact, turnProgId),
+	MK16(Compact, waitingFor),
+	MK16(Compact, arTargetX),
+	MK16(Compact, arTargetY),
+	MK32(Compact, animScratchId),
+	MK16(Compact, megaSet),
 };
 
 static const uint32 megaSetOffsets[] = {
@@ -237,15 +94,15 @@
 	MK16(MegaSet, colOffset),
 	MK16(MegaSet, colWidth),
 	MK16(MegaSet, lastChr),
-	MK32(MegaSet, animUp),
-	MK32(MegaSet, animDown),
-	MK32(MegaSet, animLeft),
-	MK32(MegaSet, animRight),
-	MK32(MegaSet, standUp),
-	MK32(MegaSet, standDown),
-	MK32(MegaSet, standLeft),
-	MK32(MegaSet, standRight),
-	MK32(MegaSet, standTalk),
+	MK32(MegaSet, animUpId),
+	MK32(MegaSet, animDownId),
+	MK32(MegaSet, animLeftId),
+	MK32(MegaSet, animRightId),
+	MK32(MegaSet, standUpId),
+	MK32(MegaSet, standDownId),
+	MK32(MegaSet, standLeftId),
+	MK32(MegaSet, standRightId),
+	MK32(MegaSet, standTalkId),
 };
 
 static const uint32 turnTableOffsets[] = {
@@ -256,354 +113,298 @@
 	MK32_A5(TurnTable, turnTableTalk),
 };
 
+#define COMPACT_SIZE (sizeof(compactOffsets)/sizeof(uint32))
+#define MEGASET_SIZE (sizeof(megaSetOffsets)/sizeof(uint32))
+#define TURNTABLE_SIZE (sizeof(turnTableOffsets)/sizeof(uint32))
+
+SkyCompact::SkyCompact(void) {
+	_cptFile = new File();
+	if (!_cptFile->open("sky.cpt")) {
+		GUI::MessageDialog dialog("Unable to find \"sky.cpt\" file!\n"
+								  "Please download it from www.scummvm.org", "OK", NULL);
+		dialog.runModal();
+		error("Unable to find \"sky.cpt\" file\nPlease download it from www.scummvm.org");
+	}
+		
+    uint16 fileVersion = _cptFile->readUint16LE();
+	if (fileVersion != 0)
+		error("unknown \"sky.cpt\" version");
+
+	// set the necessary data structs up...
+	_numDataLists = _cptFile->readUint16LE();
+	_cptNames	  = (char***)malloc(_numDataLists * sizeof(char**));
+	_dataListLen  = (uint16 *)malloc(_numDataLists * sizeof(uint16));
+	_cptSizes	  = (uint16 **)malloc(_numDataLists * sizeof(uint16*));
+	_cptTypes	  = (uint16 **)malloc(_numDataLists * sizeof(uint16*));
+	_compacts	  = (Compact***)malloc(_numDataLists * sizeof(Compact**));
+
+	for (int i = 0; i < _numDataLists; i++) {
+		_dataListLen[i] = _cptFile->readUint16LE();
+		_cptNames[i] = (char**)malloc(_dataListLen[i] * sizeof(char*));
+		_cptSizes[i] = (uint16 *)malloc(_dataListLen[i] * sizeof(uint16));
+		_cptTypes[i] = (uint16 *)malloc(_dataListLen[i] * sizeof(uint16));
+		_compacts[i] = (Compact**)malloc(_dataListLen[i] * sizeof(Compact*));
+	}
+	
+	uint32 rawSize = _cptFile->readUint32LE() * sizeof(uint16);
+	uint16 *rawPos = _rawBuf = (uint16*)malloc(rawSize);
+
+	uint32 srcSize = _cptFile->readUint32LE() * sizeof(uint16);
+	uint16 *srcBuf = (uint16*)malloc(srcSize);
+	uint16 *srcPos = srcBuf;
+	_cptFile->read(srcBuf, srcSize);
+
+	uint32 asciiSize = _cptFile->readUint32LE();
+	char *asciiPos = _asciiBuf = (char*)malloc(asciiSize);
+	_cptFile->read(_asciiBuf, asciiSize);
+
+	// and fill them with the compact data
+	uint32 debcnt = 0;
+	for (uint32 lcnt = 0; lcnt < _numDataLists; lcnt++) {
+		for (uint32 ecnt = 0; ecnt < _dataListLen[lcnt]; ecnt++) {
+			_cptSizes[lcnt][ecnt] = READ_LE_UINT16(srcPos++);
+			if (_cptSizes[lcnt][ecnt]) {
+				_cptTypes[lcnt][ecnt] = READ_LE_UINT16(srcPos++);				
+				_compacts[lcnt][ecnt] = (Compact*)rawPos;
+				_cptNames[lcnt][ecnt] = asciiPos;
+				asciiPos += strlen(asciiPos) + 1;
+
+				for (uint16 elemCnt = 0; elemCnt < _cptSizes[lcnt][ecnt]; elemCnt++)
+					*rawPos++ = READ_LE_UINT16(srcPos++);
+			} else {
+				_cptTypes[lcnt][ecnt] = 0;
+				_compacts[lcnt][ecnt] = NULL;
+				_cptNames[lcnt][ecnt] = NULL;
+			}
+		}
+	}
+	free(srcBuf);
+
+	uint16 numDlincs = _cptFile->readUint16LE();
+	uint16 *dlincBuf = (uint16*)malloc(numDlincs * 2 * sizeof(uint16));
+	uint16 *dlincPos = dlincBuf;
+	_cptFile->read(dlincBuf, numDlincs * 2 * sizeof(uint16));
+	// these compacts don't actually exist but only point to other ones...
+	for (uint16 cnt = 0; cnt < numDlincs; cnt++) {
+		uint16 dlincId = READ_LE_UINT16(dlincPos++);
+		uint16 destId = READ_LE_UINT16(dlincPos++);
+		assert(((dlincId >> 12) < _numDataLists) && ((dlincId & 0xFFF) < _dataListLen[dlincId >> 12]) && (_compacts[dlincId >> 12][dlincId & 0xFFF] == NULL));
+		_compacts[dlincId >> 12][dlincId & 0xFFF] = _compacts[destId >> 12][destId & 0xFFF];
+
+		assert(_cptNames[dlincId >> 12][dlincId & 0xFFF] == NULL);
+		_cptNames[dlincId >> 12][dlincId & 0xFFF] = asciiPos;
+		asciiPos += strlen(asciiPos) + 1;
+	}
+	free(dlincBuf);
+
+	// if this is v0.0288, parse this diff data
+	uint16 numDiffs = _cptFile->readUint16LE();
+	uint16 diffSize = _cptFile->readUint16LE();
+	uint16 *diffBuf = (uint16*)malloc(diffSize * sizeof(uint16));
+	_cptFile->read(diffBuf, diffSize * sizeof(uint16));
+	if (SkyEngine::_systemVars.gameVersion == 288) {
+		uint16 *diffPos = diffBuf;
+		for (uint16 cnt = 0; cnt < numDiffs; cnt++) {
+			uint16 cptId = READ_LE_UINT16(diffPos++);
+			uint16 *rawCpt = (uint16*)fetchCpt(cptId);
+			rawCpt += READ_LE_UINT16(diffPos++);
+			uint16 len = READ_LE_UINT16(diffPos++);
+			for (uint16 elemCnt = 0; elemCnt < len; elemCnt++)
+				rawCpt[elemCnt] = READ_LE_UINT16(diffPos++);
+		}
+		assert(diffPos == (diffBuf + diffSize));
+	}
+	free(diffBuf);
+
+	// these are the IDs that have to be saved into savegame files.
+	_numSaveIds = _cptFile->readUint16LE();
+	_saveIds = (uint16*)malloc(_numSaveIds * sizeof(uint16));
+	_cptFile->read(_saveIds, _numSaveIds * sizeof(uint16));
+	for (uint16 cnt = 0; cnt < _numSaveIds; cnt++)
+        _saveIds[cnt] = FROM_LE_16(_saveIds[cnt]);
+	_resetDataPos = _cptFile->pos();
+}
+
+SkyCompact::~SkyCompact(void) {
+	free(_rawBuf);
+	free(_asciiBuf);
+	for (int i = 0; i < _numDataLists; i++) {
+		free(_compacts[i]);
+		free(_cptNames[i]);
+		free(_cptSizes[i]);
+	}
+	free(_compacts);
+	free(_cptNames);
+	free(_cptSizes);
+	_cptFile->close();
+	delete _cptFile;
+}
+
+// needed for some workaround where the engine has to check if it's currently processing joey, for example
+bool SkyCompact::cptIsId(Compact *cpt, uint16 id) {
+	return (cpt == fetchCpt(id));
+}
+
+Compact *SkyCompact::fetchCpt(uint16 cptId) {
+	if (cptId == 0xFFFF) // is this really still necessary?
+		return NULL;
+	assert(((cptId >> 12) < _numDataLists) && ((cptId & 0xFFF) < _dataListLen[cptId >> 12]));
+	return _compacts[cptId >> 12][cptId & 0xFFF];
+}
+
+Compact *SkyCompact::fetchCptInfo(uint16 cptId, uint16 *elems, uint16 *type, char *name) {
+	assert(((cptId >> 12) < _numDataLists) && ((cptId & 0xFFF) < _dataListLen[cptId >> 12]));
+	if (elems)
+		*elems = _cptSizes[cptId >> 12][cptId & 0xFFF];
+	if (type)
+		*type  = _cptTypes[cptId >> 12][cptId & 0xFFF];
+	if (name)
+		strcpy(name, _cptNames[cptId >> 12][cptId & 0xFFF]);
+	return fetchCpt(cptId);
+}
+
+uint16 *SkyCompact::getSub(Compact *cpt, uint16 mode) {
+	switch (mode) {
+	case 0:
+		return &(cpt->baseSub);
+	case 2:
+		return &(cpt->baseSub_off);
+	case 4:
+		return &(cpt->actionSub);
+	case 6:
+		return &(cpt->actionSub_off);
+	case 8:
+		return &(cpt->getToSub);
+	case 10:
+		return &(cpt->getToSub_off);
+	case 12:
+		return &(cpt->extraSub);
+	case 14:
+		return &(cpt->extraSub_off);
+	default:
+		error("Invalid Mode (%d)", mode);
+	}
+}
+
+uint16 *SkyCompact::getGrafixPtr(Compact *cpt) {
+	uint16 *gfxBase = (uint16*)fetchCpt(cpt->grafixProgId);
+	if ((gfxBase == NULL) && cpt->grafixProgPos) {
+		warning("SkyCompact::getGrafixPtr: got offset for null ptr");
+		return NULL;
+	}
+	return gfxBase + cpt->grafixProgPos;
+}
+
 /**
- * Returns a void pointer to offset \a off in compact \a cpt
- * as it would be on a 386.
+ * Returns the n'th mega set specified by \a megaSet from Compact \a cpt.
  */
-void *getCompactElem(Compact *cpt, uint32 off) {
+MegaSet *SkyCompact::getMegaSet(Compact *cpt) {
+	switch (cpt->megaSet) {
+	case 0:
+		return &cpt->megaSet0;
+	case NEXT_MEGA_SET:
+		return &cpt->megaSet1;
+	case NEXT_MEGA_SET*2:
+		return &cpt->megaSet2;
+	case NEXT_MEGA_SET*3:
+		return &cpt->megaSet3;
+	default:
+		error("Invalid MegaSet (%d)", cpt->megaSet);
+	}
+}
+
+/**
+ \brief Returns the turn table for direction \a dir
+ 	from Compact \a cpt in \a megaSet.
+  
+ Functionally equivalent to:
+ \verbatim
+ clear eax
+ mov al,20
+ mul (cpt[esi]).c_dir
+ add ax,(cpt[esi]).c_mega_set
+ lea eax,(cpt[esi+eax]).c_turn_table_up
+ \endverbatim
+*/
+uint16 *SkyCompact::getTurnTable(Compact *cpt, uint16 dir) {
+	MegaSet *m = getMegaSet(cpt);
+	TurnTable *turnTable = (TurnTable*)fetchCpt(m->turnTableId);
+	switch (dir) {
+	case 0:
+		return turnTable->turnTableUp;
+	case 1:
+		return turnTable->turnTableDown;
+	case 2:
+		return turnTable->turnTableLeft;
+	case 3:
+		return turnTable->turnTableRight;
+	case 4:
+		return turnTable->turnTableTalk;
+	default:
+		error("No TurnTable (%d) in MegaSet (%d)", dir, cpt->megaSet);
+	}
+}
+
+void *SkyCompact::getCompactElem(Compact *cpt, uint16 off) {
 	if (off < COMPACT_SIZE)
 		return((uint8 *)cpt + compactOffsets[off]);
-
 	off -= COMPACT_SIZE;
-	if (off < EXTCOMPACT_SIZE)
-		return((uint8 *)(cpt->extCompact) + extCompactOffsets[off]);
 
-	off -= EXTCOMPACT_SIZE;
 	if (off < MEGASET_SIZE)
-		return((uint8 *)(cpt->extCompact->megaSet0) + megaSetOffsets[off]);
+		return((uint8 *)&(cpt->megaSet0) + megaSetOffsets[off]);
 
 	off -= MEGASET_SIZE;
 	if (off < TURNTABLE_SIZE)
-		return ((uint8 *)(cpt->extCompact->megaSet0->turnTable) + turnTableOffsets[off]);
+		return ((uint8 *)fetchCpt(cpt->megaSet0.turnTableId) + turnTableOffsets[off]);
 
 	off -= TURNTABLE_SIZE;
 	if (off < MEGASET_SIZE)
-		return((uint8 *)(cpt->extCompact->megaSet1) + megaSetOffsets[off]);
+		return((uint8 *)&(cpt->megaSet1) + megaSetOffsets[off]);
 
 	off -= MEGASET_SIZE;
 	if (off < TURNTABLE_SIZE)
-		return ((uint8 *)(cpt->extCompact->megaSet1->turnTable) + turnTableOffsets[off]);
+		return ((uint8 *)fetchCpt(cpt->megaSet1.turnTableId) + turnTableOffsets[off]);
 
 	off -= TURNTABLE_SIZE;
 	if (off < MEGASET_SIZE)
-		return((uint8 *)(cpt->extCompact->megaSet2) + megaSetOffsets[off]);
+		return((uint8 *)&(cpt->megaSet2) + megaSetOffsets[off]);
 
 	off -= MEGASET_SIZE;
 	if (off < TURNTABLE_SIZE)
-		return ((uint8 *)(cpt->extCompact->megaSet2->turnTable) + turnTableOffsets[off]);
+		return ((uint8 *)fetchCpt(cpt->megaSet2.turnTableId) + turnTableOffsets[off]);
 
 	off -= TURNTABLE_SIZE;
 	if (off < MEGASET_SIZE)
-		return((uint8 *)(cpt->extCompact->megaSet3) + megaSetOffsets[off]);
+		return((uint8 *)&(cpt->megaSet3) + megaSetOffsets[off]);
 
 	off -= MEGASET_SIZE;
 	if (off < TURNTABLE_SIZE)
-		return ((uint8 *)(cpt->extCompact->megaSet3->turnTable) + turnTableOffsets[off]);
+		return ((uint8 *)fetchCpt(cpt->megaSet3.turnTableId) + turnTableOffsets[off]);
 	off -= TURNTABLE_SIZE;
 
-	error("Offset %X out of bounds of compact", off + COMPACT_SIZE + EXTCOMPACT_SIZE + 4 * MEGASET_SIZE + 4 * TURNTABLE_SIZE);
-}
-
-// getToTables
-uint16 s11_fl_tab288[33] = {
-	0x3132, 0x001C, 0x3139, 0x3017, 0x3145, 0x301B, 0x3148, 0x301D, 
-	0x314C, 0x301F, 0x314D, 0x3021, 0x314E, 0x3022, 0x314F, 0x3023, 
-	0x3150, 0x3024, 0x3152, 0x301F, 0x3153, 0x3021, 0x3154, 0x3022, 
-	0x3155, 0x3023, 0x3156, 0x3024, 0x3157, 0x3026, 0x0000, 0x3028, 
-	0xFFFF
-};
-
-uint16 s19_fl_tab288[17] = {
-	0x3042, 0x001C, 0x0002, 0x002A, 0x0000, 0x302A, 0x0001, 0x3029, 
-	0x3046, 0x302B, 0x3049, 0x302D, 0x3189, 0x302F, 0x3001, 0x3033, 
-	0xFFFF
-};
-
-uint16 s20_fl_tab288[37] = {
-	0x30A4, 0x001C, 0x0002, 0x002A, 0x0000, 0x3035, 0x0001, 0x303F, 
-	0x0003, 0x3049, 0x30A8, 0x3037, 0x30AB, 0x303B, 0x30BA, 0x3047, 
-	0x30AE, 0x303D, 0x30BD, 0x3043, 0x30C8, 0x304A, 0x30C9, 0x304C, 
-	0x30CA, 0x304E, 0x3102, 0x3052, 0x310B, 0x3054, 0x310C, 0x3056, 
-	0x0017, 0x3059, 0x0018, 0x305B, 0xFFFF 
-};
-
-uint16 s21_fl_tab288[31] = {
-	0x30C2, 0x001C, 0x0002, 0x002A, 0x0000, 0x305C, 0x30C6, 0x305D, 
-	0x30DE, 0x305F, 0x30DF, 0x3061, 0x30E0, 0x3063, 0x30E2, 0x3066, 
-	0x30E4, 0x3069, 0x30E5, 0x306B, 0x30EC, 0x306D, 0x30EE, 0x3072, 
-	0x30EF, 0x3074, 0x30ED, 0x306F, 0x30F6, 0x3077, 0xFFFF
-};
-
-uint16 s22_fl_tab288[31] = {
-	0x30B3, 0x001C, 0x0002, 0x002A, 0x0000, 0x307A, 0x30B7, 0x307B, 
-	0x30CC, 0x307D, 0x30CD, 0x307F, 0x30CE, 0x3081, 0x30CF, 0x3081, 
-	0x30D0, 0x3085, 0x30D5, 0x3087, 0x30D9, 0x308A, 0x30DA, 0x308C, 
-	0x30DB, 0x308E, 0x30DC, 0x3090, 0x30DD, 0x3092, 0xFFFF
-} ;
-
-uint16 s23_fl_tab288[27] = {
-	0x3015, 0x001C, 0x0002, 0x002A, 0x0000, 0x3095, 0x0001, 0x3096, 
-	0x0003, 0x3097, 0x3019, 0x3098, 0x301B, 0x309A, 0x3027, 0x309D, 
-	0x305E, 0x309F, 0x305F, 0x30A1, 0x3060, 0x30A3, 0x3061, 0x30A5, 
-	0x3184, 0x30A7, 0xFFFF
-};
-
-uint16 s24_fl_tab288[23] = {
-	0x302C, 0x001C, 0x0002, 0x002A, 0x0000, 0x30A9, 0x3030, 0x30AA, 
-	0x3062, 0x30AC, 0x3063, 0x30AE, 0x3064, 0x30B0, 0x3075, 0x30B2, 
-	0x309A, 0x30B7, 0x3115, 0x30BA, 0x3118, 0x30BB, 0xFFFF
-};
-
-uint16 s25_fl_tab288[19] = {
-	0x3020, 0x001C, 0x0002, 0x002A, 0x0000, 0x30BE, 0x3024, 0x30BF, 
-	0x308E, 0x30C4, 0x0003, 0x30C7, 0x3093, 0x30C9, 0x3092, 0x30CE, 
-	0x3101, 0x30D0, 0xFFFF
-};
-
-uint16 s26_fl_tab288[29] = {
-	0x304E, 0x001C, 0x0002, 0x002A, 0x0000, 0x30D3, 0x0001, 0x30D2, 
-	0x3052, 0x30D4, 0x3066, 0x30E3, 0x3057, 0x30D7, 0x3058, 0x30D7, 
-	0x3059, 0x30D7, 0x305A, 0x30D7, 0x305B, 0x30DC, 0x305C, 0x30E9, 
-	0x305D, 0x30DF, 0x30FD, 0x30E7, 0xFFFF
-};
-
-uint16 body_tab288[7] = {
-	0x3081, 0x30F5, 0x3073, 0x30F3, 0x0018, 0x30FC, 0xFFFF
-};
-
-uint16 chair_tab288[23] = {
-	0x3081, 0x001C, 0x306B, 0x30F7, 0x306F, 0x30F7, 0x0017, 0x30F7, 
-	0x3071, 0x30F7, 0x3072, 0x30F7, 0x3073, 0x30F7, 0x3074, 0x30F7, 
-	0x3089, 0x30F7, 0x308D, 0x30F7, 0x3084, 0x30F7, 0xFFFF
-};
-
-uint16 s27_fl_tab288[29] = {
-	0x306B, 0x001C, 0x306F, 0x30ED, 0x0002, 0x002A, 0x0017, 0x30FA, 
-	0x0018, 0x30FC, 0x0000, 0x30EC, 0x3071, 0x30EF, 0x3072, 0x30F1, 
-	0x3073, 0x30F3, 0x3074, 0x30F8, 0x3089, 0x30FE, 0x3081, 0x30F5, 
-	0x3084, 0x3109, 0x308D, 0x3108, 0xFFFF
-};
-
-uint16 s28_fl_tab288[27] = {
-	0x3037, 0x001C, 0x0002, 0x002A, 0x0000, 0x310E, 0x0001, 0x3113, 
-	0x0003, 0x3119, 0x303B, 0x310F, 0x303D, 0x3111, 0x309F, 0x3117, 
-	0x3054, 0x3114, 0x0017, 0x311B, 0x0018, 0x311D, 0x3196, 0x3125, 
-	0x3199, 0x3128, 0xFFFF
-};
-
-uint16 s28_sml_tab288[13] = {
-	0x318E, 0x001C, 0x0002, 0x002A, 0x3187, 0x311E, 0x3188, 0x3120, 
-	0x0004, 0x3122, 0x0005, 0x3123, 0xFFFF
-};
-
-uint16 s29_fl_tab288[27] = {
-	0x3004, 0x001C, 0x0002, 0x002A, 0x3008, 0x312C, 0x300B, 0x312E, 
-	0x002A, 0x3137, 0x3010, 0x3130, 0x3032, 0x3133, 0x0001, 0x3132, 
-	0x0003, 0x3135, 0x002A, 0x3137, 0x0017, 0x313C, 0x0018, 0x313E, 
-	0x312C, 0x313F, 0xFFFF
-};
-
-uint16 s29_sml_tab288[13] = {
-	0x318A, 0x001C, 0x0002, 0x002A, 0x3185, 0x3141, 0x3186, 0x3143, 
-	0x0004, 0x3145, 0x0005, 0x3146, 0xFFFF
-};
-
-void patchFor288(void) {
-	memcpy(s11_floor_table, s11_fl_tab288, sizeof(s11_fl_tab288));
-	memcpy(s19_floor_table, s19_fl_tab288, sizeof(s19_fl_tab288));
-	memcpy(s20_floor_table, s20_fl_tab288, sizeof(s20_fl_tab288));
-	memcpy(s21_floor_table, s21_fl_tab288, sizeof(s21_fl_tab288));
-	memcpy(s22_floor_table, s22_fl_tab288, sizeof(s22_fl_tab288));
-	memcpy(s23_floor_table, s23_fl_tab288, sizeof(s23_fl_tab288));
-	memcpy(s24_floor_table, s24_fl_tab288, sizeof(s24_fl_tab288));
-	memcpy(s25_floor_table, s25_fl_tab288, sizeof(s25_fl_tab288));
-	memcpy(s26_floor_table, s26_fl_tab288, sizeof(s26_fl_tab288));
-	memcpy(s27_floor_table, s27_fl_tab288, sizeof(s27_fl_tab288));
-	memcpy(s28_floor_table, s28_fl_tab288, sizeof(s28_fl_tab288));
-	memcpy(s28_sml_table, s28_sml_tab288, sizeof(s28_sml_tab288));
-	memcpy(s29_floor_table, s29_fl_tab288, sizeof(s29_fl_tab288));
-	memcpy(s29_sml_table, s29_sml_tab288, sizeof(s29_sml_tab288));
-	memcpy(body_table, body_tab288, sizeof(body_tab288));
-	memcpy(chair_table, chair_tab288, sizeof(chair_tab288));
-
-	((Compact *)SkyCompact::data_0[121])->baseSub = 0x50; // full_screen
-	((Compact *)SkyCompact::data_0[122])->mouseClick = 0x51; // cancel_button
-	((Compact *)SkyCompact::data_0[122])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[123])->mouseClick = 0x52; // button_0
-	((Compact *)SkyCompact::data_0[123])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[124])->mouseClick = 0x52; // button_1
-	((Compact *)SkyCompact::data_0[124])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[125])->mouseClick = 0x52; // button_2
-	((Compact *)SkyCompact::data_0[125])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[126])->mouseClick = 0x52; // button_3
-	((Compact *)SkyCompact::data_0[126])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[127])->mouseClick = 0x52; // button_4
-	((Compact *)SkyCompact::data_0[127])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[128])->mouseClick = 0x52; // button_5
-	((Compact *)SkyCompact::data_0[128])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[129])->mouseClick = 0x52; // button_6
-	((Compact *)SkyCompact::data_0[129])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[130])->mouseClick = 0x52; // button_7
-	((Compact *)SkyCompact::data_0[130])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[131])->mouseClick = 0x52; // button_8
-	((Compact *)SkyCompact::data_0[131])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[132])->mouseClick = 0x52; // button_9
-	((Compact *)SkyCompact::data_0[132])->baseSub = 0x53;
-	((Compact *)SkyCompact::data_0[173])->baseSub = 0x54; // retina_scan
-	((Compact *)SkyCompact::data_3[1])->actionScript = 0x3032; // useless_char
-	((Compact *)SkyCompact::data_3[1])->baseSub = 0x3034;
-	((Compact *)SkyCompact::data_3[8])->actionScript = 0x312B; // lift_29
-	((Compact *)SkyCompact::data_3[8])->baseSub = 0x3129;
-	((Compact *)SkyCompact::data_3[11])->actionScript = 0x312D; // s29_card_slot
-	((uint16 *)SkyCompact::data_3[14])[11] = 0x312F; // rs_joey_7_29
-	((Compact *)SkyCompact::data_3[16])->actionScript = 0x3131; // right_exit_29
-	((Compact *)SkyCompact::data_3[25])->actionScript = 0x3099; // left_exit_23
-	((Compact *)SkyCompact::data_3[27])->actionScript = 0x309B; // anchor_exit_23
-	((Compact *)SkyCompact::data_3[36])->actionScript = 0x30C0; // anchor_exit_25
-	((Compact *)SkyCompact::data_3[39])->actionScript = 0x309E; // travel_exit_23
-	((Compact *)SkyCompact::data_3[48])->actionScript = 0x30AB; // left_exit_24
-	((Compact *)SkyCompact::data_3[50])->actionScript = 0x3134; // left_exit_29
-	((Compact *)SkyCompact::data_3[59])->actionScript = 0x3110; // right_exit_28
-	((Compact *)SkyCompact::data_3[61])->actionScript = 0x3112; // left_exit_28
-	((Compact *)SkyCompact::data_3[70])->actionScript = 0x302C; // right_exit_19
-	((Compact *)SkyCompact::data_3[73])->actionScript = 0x302E; // left_exit_19
-	((Compact *)SkyCompact::data_3[82])->actionScript = 0x30D5; // right_exit_26
-	((Compact *)SkyCompact::data_3[84])->actionScript = 0x3115; // dustbin_28
-	((Compact *)SkyCompact::data_3[87])->actionScript = 0x30D8; // poster1
-	((Compact *)SkyCompact::data_3[88])->actionScript = 0x30D9; // poster2
-	((Compact *)SkyCompact::data_3[89])->actionScript = 0x30DA; // poster3
-	((Compact *)SkyCompact::data_3[90])->actionScript = 0x30DB; // poster4
-	((Compact *)SkyCompact::data_3[91])->actionScript = 0x30DD; // plant_26
-	((Compact *)SkyCompact::data_3[92])->actionScript = 0x30EB; // leaflet
-	((Compact *)SkyCompact::data_3[92])->baseSub = 0x30EA;
-	((Compact *)SkyCompact::data_3[93])->actionScript = 0x30E0; // holo
-	((Compact *)SkyCompact::data_3[93])->baseSub = 0x30E1;
-	((Compact *)SkyCompact::data_3[94])->actionScript = 0x30A0; // bin_23
-	((Compact *)SkyCompact::data_3[95])->actionScript = 0x30A2; // sculpture
-	((Compact *)SkyCompact::data_3[96])->actionScript = 0x30A4; // link_23
-	((Compact *)SkyCompact::data_3[97])->actionScript = 0x30A6; // wreck_23
-	((Compact *)SkyCompact::data_3[98])->actionScript = 0x30AD; // london_poster
-	((Compact *)SkyCompact::data_3[99])->actionScript = 0x30AF; // new_york_poster
-	((Compact *)SkyCompact::data_3[100])->actionScript = 0x30B1; // mural
-	((Compact *)SkyCompact::data_3[102])->actionScript = 0x30E4; // left_exit_26
-	((Compact *)SkyCompact::data_3[111])->actionScript = 0x30EE; // right_exit_27
-	((Compact *)SkyCompact::data_3[113])->actionScript = 0x30F0; // chart1
-	((Compact *)SkyCompact::data_3[114])->actionScript = 0x30F2; // chart2
-	((Compact *)SkyCompact::data_3[115])->actionScript = 0x30F4; // gas
-	((Compact *)SkyCompact::data_3[116])->actionScript = 0x30F9; // scanner_27
-	((Compact *)SkyCompact::data_3[116])->baseSub = 0x3103;
-	((Compact *)SkyCompact::data_3[117])->actionScript = 0x30B3; // pidgeons
-	((Compact *)SkyCompact::data_3[119])->baseSub = 0x30FD; // burke
-	((Compact *)SkyCompact::data_3[129])->actionScript = 0x30F6; // chair_27
-	((Compact *)SkyCompact::data_3[132])->actionScript = 0x310A; // helmet_cole
-	((Compact *)SkyCompact::data_3[132])->baseSub = 0x3104;
-	((Compact *)SkyCompact::data_3[137])->actionScript = 0x30FF; // medi_comp
-	((Compact *)SkyCompact::data_3[137])->baseSub = 0x310D;
-	((Compact *)SkyCompact::data_3[141])->actionScript = 0x3106; // body
-	((Compact *)SkyCompact::data_3[141])->baseSub = 0x3105;
-	((Compact *)SkyCompact::data_3[142])->actionScript = 0x30C3; // anchor
-	((Compact *)SkyCompact::data_3[142])->baseSub = 0x30C1; // anchor
-	((Compact *)SkyCompact::data_3[146])->actionScript = 0x30CF; // hook
-	((Compact *)SkyCompact::data_3[146])->baseSub = 0x30C8; // hook
-	((Compact *)SkyCompact::data_3[147])->actionScript = 0x30CA; // statue_25
-	((Compact *)SkyCompact::data_3[149])->baseSub = 0x30CC; // lazer_25
-	((Compact *)SkyCompact::data_3[151])->baseSub = 0x30CD; // spark_25
-	((Compact *)SkyCompact::data_3[154])->actionScript = 0x30B6; // trevor
-	((Compact *)SkyCompact::data_3[154])->baseSub = 0x30B4; // trevor
-	((Compact *)SkyCompact::data_3[159])->actionScript = 0x3118; // up_exit_28
-	((Compact *)SkyCompact::data_3[168])->actionScript = 0x3038; // down_exit_20
-	((Compact *)SkyCompact::data_3[171])->mouseOn = 0x3039; // reich_door_20
-	((Compact *)SkyCompact::data_3[171])->actionScript = 0x303C;
-	((Compact *)SkyCompact::data_3[171])->baseSub = 0x3040;
-	((Compact *)SkyCompact::data_3[174])->actionScript = 0x303E; // reich_slot
-	((Compact *)SkyCompact::data_3[183])->actionScript = 0x307C; // right_exit_22
-
-	((Compact *)SkyCompact::data_3[186])->mouseOn = 0x3045; // lamb_door_20
-	((Compact *)SkyCompact::data_3[186])->actionScript = 0x3048; // lamb_door_20
-	((Compact *)SkyCompact::data_3[186])->baseSub = 0x3041; // lamb_door_20
-
-	((Compact *)SkyCompact::data_3[189])->actionScript = 0x3044; // lamb_slot
-	((Compact *)SkyCompact::data_3[198])->actionScript = 0x305E; // left_exit_21
-	((Compact *)SkyCompact::data_3[200])->actionScript = 0x304B; // shrub_1
-	((Compact *)SkyCompact::data_3[201])->actionScript = 0x304D; // shrub_2
-	((Compact *)SkyCompact::data_3[202])->actionScript = 0x304F; // shrub_3
-	((Compact *)SkyCompact::data_3[204])->actionScript = 0x307E; // lamb_bed
-	((Compact *)SkyCompact::data_3[205])->actionScript = 0x3080; // lamb_tv
-	((Compact *)SkyCompact::data_3[206])->actionScript = 0x3082; // fish_tank
-	((Compact *)SkyCompact::data_3[206])->baseSub = 0x3089;
-	((Compact *)SkyCompact::data_3[207])->actionScript = 0x3083; // fish_poster
-	((Compact *)SkyCompact::data_3[208])->actionScript = 0x3086; // pillow
-	((Compact *)SkyCompact::data_3[208])->baseSub = 0x3084;
-	((Compact *)SkyCompact::data_3[213])->actionScript = 0x3088; // magazine
-	((Compact *)SkyCompact::data_3[217])->actionScript = 0x308B; // reich_chair
-	((Compact *)SkyCompact::data_3[218])->actionScript = 0x308D; // cabinet
-	((Compact *)SkyCompact::data_3[219])->actionScript = 0x308F; // cert
-	((Compact *)SkyCompact::data_3[220])->actionScript = 0x3091; // reich_picture
-	((Compact *)SkyCompact::data_3[221])->actionScript = 0x3093; // fish_food
-	((Compact *)SkyCompact::data_3[222])->actionScript = 0x3060; // lambs_books
-	((Compact *)SkyCompact::data_3[223])->actionScript = 0x3062; // lambs_chair
-	((Compact *)SkyCompact::data_3[224])->actionScript = 0x3064; // dispensor
-	((Compact *)SkyCompact::data_3[226])->actionScript = 0x3067; // cat_food
-	((Compact *)SkyCompact::data_3[226])->baseSub = 0x3065; // cat_food
-	((Compact *)SkyCompact::data_3[228])->actionScript = 0x306A; // video
-	((Compact *)SkyCompact::data_3[228])->baseSub = 0x3068; // video
-	((Compact *)SkyCompact::data_3[229])->actionScript = 0x306C; // cassette
-	((Compact *)SkyCompact::data_3[236])->actionScript = 0x306E; // big_pict1
-	((Compact *)SkyCompact::data_3[237])->actionScript = 0x3070; // video_screen
-	((Compact *)SkyCompact::data_3[237])->baseSub = 0x3071;
-	((Compact *)SkyCompact::data_3[238])->actionScript = 0x3073; // big_pict2
-	((Compact *)SkyCompact::data_3[239])->actionScript = 0x3075; // big_pict3
-	((Compact *)SkyCompact::data_3[246])->actionScript = 0x3078; // cat
-	((Compact *)SkyCompact::data_3[246])->baseSub = 0x3076;
-	((Compact *)SkyCompact::data_3[253])->actionScript = 0x30E8; // bio_door
-	((Compact *)SkyCompact::data_3[253])->baseSub = 0x30E6;
-	((Compact *)SkyCompact::data_3[257])->actionScript = 0x30D1; // sales_chart
-	((Compact *)SkyCompact::data_3[258])->actionScript = 0x3053; // gallager_bel
-	((Compact *)SkyCompact::data_3[258])->baseSub = 0x3051; // gallager_bel
-	((Compact *)SkyCompact::data_3[267])->actionScript = 0x3055; // reich_window
-	((Compact *)SkyCompact::data_3[268])->actionScript = 0x3057; // lamb_window
-	((Compact *)SkyCompact::data_3[270])->baseSub = 0x3079; // inner_lamb_door
-	((Compact *)SkyCompact::data_3[277])->actionScript = 0x30B9; // ticket
-	((Compact *)SkyCompact::data_3[277])->baseSub = 0x30B8;
-	((Compact *)SkyCompact::data_3[280])->actionScript = 0x30BC; // globe
-	((Compact *)SkyCompact::data_3[280])->baseSub = 0x30BD; // globe
-	((Compact *)SkyCompact::data_3[283])->baseSub = 0x3094; // inner_reich_door
-	((Compact *)SkyCompact::data_3[286])->baseSub = 0x310B; // glass_slot
-	((uint16 *)SkyCompact::data_3[13])[13] = 0x3138; // rs_lamb_28
-	((Compact *)SkyCompact::data_3[300])->actionScript = 0x3140; // cable_29
-	((Compact *)SkyCompact::data_3[313])->actionScript = 0x3018; // cable_fall
-	((Compact *)SkyCompact::data_3[313])->baseSub = 0x3014;
-	((Compact *)SkyCompact::data_3[316])->actionScript = 0x3018; // cable_fall2
-	((Compact *)SkyCompact::data_3[316])->baseSub = 0x3013;
-	((Compact *)SkyCompact::data_3[317])->baseSub = 0x3015; // smashed_window
-	((Compact *)SkyCompact::data_3[319])->baseSub = 0x3016; // bits
-	((Compact *)SkyCompact::data_3[321])->baseSub = 0x3016; // bits2
-	((Compact *)SkyCompact::data_3[324])->baseSub = 0x3019; // spy_11
-	((Compact *)SkyCompact::data_3[325])->actionScript = 0x301C; // locker_11
-	((Compact *)SkyCompact::data_3[325])->baseSub = 0x301A; // locker_11
-	((Compact *)SkyCompact::data_3[328])->actionScript = 0x301E; // slot_11
-	((Compact *)SkyCompact::data_3[332])->actionScript = 0x3020; // soccer_1
-	((Compact *)SkyCompact::data_3[333])->actionScript = 0x3020; // soccer_2
-	((Compact *)SkyCompact::data_3[334])->actionScript = 0x3020; // soccer_3
-	((Compact *)SkyCompact::data_3[335])->actionScript = 0x3020; // soccer_4
-	((Compact *)SkyCompact::data_3[336])->actionScript = 0x3020; // soccer_5
-	((Compact *)SkyCompact::data_3[338])->actionScript = 0x3025; // slat_1
-	((Compact *)SkyCompact::data_3[339])->actionScript = 0x3025; // slat_2
-	((Compact *)SkyCompact::data_3[340])->actionScript = 0x3025; // slat_3
-	((Compact *)SkyCompact::data_3[341])->actionScript = 0x3025; // slat_4
-	((Compact *)SkyCompact::data_3[342])->actionScript = 0x3025; // slat_5
-	((Compact *)SkyCompact::data_3[343])->actionScript = 0x3027; // right_exit_11
-	((Compact *)SkyCompact::data_3[388])->actionScript = 0x30A8; // small_exit_23
-	((Compact *)SkyCompact::data_3[389])->actionScript = 0x3142; // small_r_29
-	((Compact *)SkyCompact::data_3[390])->actionScript = 0x3144; // small_l_29
-	((Compact *)SkyCompact::data_3[391])->actionScript = 0x311F; // small_r_28
-	((Compact *)SkyCompact::data_3[392])->actionScript = 0x3121; // small_l_28
-	((Compact *)SkyCompact::data_3[393])->actionScript = 0x3030; // top_right_19
-	((Compact *)SkyCompact::data_3[406])->actionScript = 0x3126; // lift_28
-	((Compact *)SkyCompact::data_3[406])->baseSub = 0x3124; // lift_28
-	((Compact *)SkyCompact::data_3[409])->actionScript = 0x3127; // slot_28
+	error("Offset %X out of bounds of compact", off + COMPACT_SIZE + 4 * MEGASET_SIZE + 4 * TURNTABLE_SIZE);
 }
 
+uint8 *SkyCompact::createResetData(uint16 gameVersion) {
+	_cptFile->seek(_resetDataPos);
+	uint32 dataSize = _cptFile->readUint16LE() * sizeof(uint16);
+	uint16 *resetBuf = (uint16*)malloc(dataSize);
+	_cptFile->read(resetBuf, dataSize);
+	uint16 numDiffs = _cptFile->readUint16LE();
+	for (uint16 cnt = 0; cnt < numDiffs; cnt++) {
+		uint16 version = _cptFile->readUint16LE();
+		uint16 diffFields = _cptFile->readUint16LE();
+		if (version == gameVersion) {
+			for (uint16 diffCnt = 0; diffCnt < diffFields; diffCnt++) {
+				uint16 pos = _cptFile->readUint16LE();
+				resetBuf[pos] = _cptFile->readUint16LE();
+			}
+			return (uint8*)resetBuf;
+		} else
+			_cptFile->seek(diffFields * 2 * sizeof(uint16), SEEK_CUR);
+	}
+	free(resetBuf);
+	error("Unable to find reset data for Beneath a Steel Sky Version 0.0%03d", gameVersion);
 }
 
 } // End of namespace Sky

Index: compact.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/compact.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- compact.h	6 Jan 2004 12:45:32 -0000	1.12
+++ compact.h	15 Dec 2004 06:48:04 -0000	1.13
@@ -26,3235 +26,57 @@
 #include "sky/struc.h"
 #include "sky/skydefs.h"
 
-namespace Sky {
+class File;
 
-namespace SkyCompact {
-	MegaSet *getMegaSet(Compact *cpt, uint16 megaSet);
-	uint16 **getTurnTable(Compact *cpt, uint16 megaSet, uint16 dir);
-	uint16 *getSub(Compact *cpt, uint16 mode);
-	uint16 *getGrafixPtr(Compact *cpt);
[...3252 lines suppressed...]
+	void *getCompactElem(Compact *cpt, uint16 off);
+	bool cptIsId(Compact *cpt, uint16 id);
+	uint8	*createResetData(uint16 gameVersion);
+	uint16	_numSaveIds;
+	uint16	*_saveIds;
+private:
+	uint16  _numDataLists;
+	uint16  *_dataListLen;
+	uint16  *_rawBuf;
+	char	*_asciiBuf;
+	Compact ***_compacts;
+	char    ***_cptNames;
+	uint16	**_cptSizes;
+	uint16  **_cptTypes;
+	File	*_cptFile;
+	uint32	_resetDataPos;
+};
 
 } // End of namespace Sky
 

Index: control.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/control.cpp,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- control.cpp	5 Dec 2004 17:42:19 -0000	1.81
+++ control.cpp	15 Dec 2004 06:48:04 -0000	1.82
@@ -36,6 +36,7 @@
 #include "sky/sound.h"
 #include "sky/struc.h"
 #include "sky/text.h"
+#include "sky/compact.h"
 
 namespace Sky {
 
@@ -191,7 +192,7 @@
 	_statusText->drawToScreen(WITH_MASK);
 }
 
-Control::Control(SaveFileManager *saveFileMan, Screen *screen, Disk *disk, Mouse *mouse, Text *text, MusicBase *music, Logic *logic, Sound *sound, OSystem *system) {
+Control::Control(SaveFileManager *saveFileMan, Screen *screen, Disk *disk, Mouse *mouse, Text *text, MusicBase *music, Logic *logic, Sound *sound, SkyCompact *skyCompact, OSystem *system) {
 	_saveFileMan = saveFileMan;
 
 	_skyScreen = screen;
@@ -201,8 +202,8 @@
 	_skyMusic = music;
 	_skyLogic = logic;
 	_skySound = sound;
+	_skyCompact = skyCompact;
 	_system = system;
-	_memListRoot = NULL;
 }
 
 ConResource *Control::createResource(void *pSpData, uint32 pNSprites, uint32 pCurSprite, int16 pX, int16 pY, uint32 pText, uint8 pOnClick, uint8 panelType) {
@@ -434,7 +435,7 @@
 	_system->copyRectToScreen(_screenBuf, GAME_SCREEN_WIDTH, 0, 0, GAME_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
 	_system->updateScreen();
 	_skyScreen->forceRefresh();
-	_skyScreen->setPaletteEndian((uint8 *)SkyEngine::fetchCompact(SkyEngine::_systemVars.currentPalette));
+	_skyScreen->setPaletteEndian((uint8 *)_skyCompact->fetchCpt(SkyEngine::_systemVars.currentPalette));
 	removePanel();
 	_skyMouse->spriteMouse(_savedMouse, 0, 0);
 	_skyText->fnSetFont(_savedCharSet);
@@ -500,7 +501,7 @@
 	_system->copyRectToScreen(_screenBuf, GAME_SCREEN_WIDTH, 0, 0, GAME_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
 	_system->updateScreen();
 	_skyScreen->forceRefresh();
-	_skyScreen->setPaletteEndian((uint8 *)SkyEngine::fetchCompact(SkyEngine::_systemVars.currentPalette));
+	_skyScreen->setPaletteEndian((uint8 *)_skyCompact->fetchCpt(SkyEngine::_systemVars.currentPalette));
 	removePanel();
 	_skyMouse->spriteMouse(_savedMouse, 0, 0);
 	_skyText->fnSetFont(_savedCharSet);
@@ -1118,7 +1119,6 @@
 }
 
 uint16 Control::saveGameToFile(void) {
-
 	char fName[20];
 	sprintf(fName,"SKY-VM.%03d", _selectedGame);
 
@@ -1144,125 +1144,14 @@
 #define STOSD(ptr, val) { *(uint32 *)(ptr) = TO_LE_32(val); (ptr) += 4; }
 #define STOSW(ptr, val) { *(uint16 *)(ptr) = TO_LE_16(val); (ptr) += 2; }
 
-void Control::stosMegaSet(uint8 **destPos, MegaSet *mega) {
-	STOSW(*destPos, mega->gridWidth);
-	STOSW(*destPos, mega->colOffset);
-	STOSW(*destPos, mega->colWidth);
-	STOSW(*destPos, mega->lastChr);
-	// anims, stands, turnTable
-}
-
-void Control::stosStr(uint8 **destPos, Compact *cpt, uint16 type) {
-	uint16 strLen = 0;
-	if (type & SAVE_GRAFX) {
-		STOSW(*destPos, cpt->grafixProg.ptrType);
-		STOSW(*destPos, cpt->grafixProg.ptrTarget);
-		STOSW(*destPos, cpt->grafixProg.pos);
-	}
-
-	if (type & SAVE_TURNP) {
-		uint16 *src = cpt->extCompact->turnProg;
-		while (src[strLen])
-			strLen++;
-		strLen++;
-		STOSW(*destPos, strLen);
-		for (uint16 cnt = 0; cnt < strLen; cnt++) {
-			STOSW(*destPos, src[cnt]);
-		}
-	}
-}
-
-void Control::stosCompact(uint8 **destPos, Compact *cpt) {
-	uint16 saveType = 0;
-	if (cpt->extCompact) {
-		saveType |= SAVE_EXT;
-		if (cpt->extCompact->megaSet0) saveType |= SAVE_MEGA0;
-		if (cpt->extCompact->megaSet1) saveType |= SAVE_MEGA1;
-		if (cpt->extCompact->megaSet2) saveType |= SAVE_MEGA2;
-		if (cpt->extCompact->megaSet3) saveType |= SAVE_MEGA3;
-		if (cpt->extCompact->turnProg) saveType |= SAVE_TURNP;
-	}
-	if (cpt->grafixProg.ptrType != PTR_NULL)
-		saveType |= SAVE_GRAFX;
-
-	STOSW(*destPos, saveType);
-
-	stosStr(destPos, cpt, saveType);
-
-	STOSW(*destPos, cpt->logic);
-	STOSW(*destPos, cpt->status);
-	STOSW(*destPos, cpt->sync);
-	STOSW(*destPos, cpt->screen);
-	STOSW(*destPos, cpt->place);
-	// getToTable
-	STOSW(*destPos, cpt->xcood);
-	STOSW(*destPos, cpt->ycood);
-	STOSW(*destPos, cpt->frame);
-	STOSW(*destPos, cpt->cursorText);
-	STOSW(*destPos, cpt->mouseOn);
-	STOSW(*destPos, cpt->mouseOff);
-	STOSW(*destPos, cpt->mouseClick);
-	STOSW(*destPos, cpt->mouseRelX);
-	STOSW(*destPos, cpt->mouseRelY);
-	STOSW(*destPos, cpt->mouseSizeX);
-	STOSW(*destPos, cpt->mouseSizeY);
-	STOSW(*destPos, cpt->actionScript);
-	STOSW(*destPos, cpt->upFlag);
-	STOSW(*destPos, cpt->downFlag);
-	STOSW(*destPos, cpt->getToFlag);
-	STOSW(*destPos, cpt->flag);
-	STOSW(*destPos, cpt->mood);
-	// grafixProg
-	STOSW(*destPos, cpt->offset);
-	STOSW(*destPos, cpt->mode);
-	STOSW(*destPos, cpt->baseSub);
-	STOSW(*destPos, cpt->baseSub_off);
-	if (cpt->extCompact) {
-		STOSW(*destPos, cpt->extCompact->actionSub);
-		STOSW(*destPos, cpt->extCompact->actionSub_off);
-		STOSW(*destPos, cpt->extCompact->getToSub);
-		STOSW(*destPos, cpt->extCompact->getToSub_off);
-		STOSW(*destPos, cpt->extCompact->extraSub);
-		STOSW(*destPos, cpt->extCompact->extraSub_off);
-		STOSW(*destPos, cpt->extCompact->dir);
-		STOSW(*destPos, cpt->extCompact->stopScript);
-		STOSW(*destPos, cpt->extCompact->miniBump);
-		STOSW(*destPos, cpt->extCompact->leaving);
-		STOSW(*destPos, cpt->extCompact->atWatch);
-		STOSW(*destPos, cpt->extCompact->atWas);
-		STOSW(*destPos, cpt->extCompact->alt);
-		STOSW(*destPos, cpt->extCompact->request);
-		STOSW(*destPos, cpt->extCompact->spWidth_xx);
-		STOSW(*destPos, cpt->extCompact->spColour);
-		STOSW(*destPos, cpt->extCompact->spTextId);
-		STOSW(*destPos, cpt->extCompact->spTime);
-		STOSW(*destPos, cpt->extCompact->arAnimIndex);
-		// turnProg
-		STOSW(*destPos, cpt->extCompact->waitingFor);
-		STOSW(*destPos, cpt->extCompact->arTargetX);
-		STOSW(*destPos, cpt->extCompact->arTargetY);
-		// animScratch
-		STOSW(*destPos, cpt->extCompact->megaSet);
-
-		if (cpt->extCompact->megaSet0)
-			stosMegaSet(destPos, cpt->extCompact->megaSet0);
-		if (cpt->extCompact->megaSet1)
-			stosMegaSet(destPos, cpt->extCompact->megaSet1);
-		if (cpt->extCompact->megaSet2)
-			stosMegaSet(destPos, cpt->extCompact->megaSet2);
-		if (cpt->extCompact->megaSet3)
-			stosMegaSet(destPos, cpt->extCompact->megaSet3);
-	}
-}
-
 uint32 Control::prepareSaveData(uint8 *destBuf) {
 
 	uint32 cnt;
 	memset(destBuf, 0, 4); // space for data size
 	uint8 *destPos = destBuf + 4;
 	STOSD(destPos, SAVE_FILE_REVISION);
-
 	STOSD(destPos, SkyEngine::_systemVars.gameVersion);
+
 	STOSW(destPos, _skySound->_saveSounds[0]);
 	STOSW(destPos, _skySound->_saveSounds[1]);
 
@@ -1277,19 +1166,12 @@
 	for (cnt = 0; cnt < 60; cnt++)
 		STOSD(destPos, loadedFilesList[cnt]);
 
-	for (cnt = 0; cnt < ARRAYSIZE(_saveLoadCpts); cnt++)
-		stosCompact(&destPos, _saveLoadCpts[cnt]);
-
-	for (cnt = 0; cnt < ARRAYSIZE(_saveLoadARs); cnt++)
-		for (uint8 elemCnt = 0; elemCnt < 32; elemCnt++) {
-			STOSW(destPos, _saveLoadARs[cnt][elemCnt]);
-		}
-
-	for (cnt = 0; cnt < 3; cnt++)
-		STOSW(destPos, SkyCompact::park_table[cnt]);
-
-	for (cnt = 0; cnt < 13; cnt++)
-		STOSW(destPos, SkyCompact::high_floor_table[cnt]);
+	for (cnt = 0; cnt < _skyCompact->_numSaveIds; cnt++) {
+		uint16 numElems;
+		uint16 *rawCpt = (uint16*)_skyCompact->fetchCptInfo(_skyCompact->_saveIds[cnt], &numElems, NULL, NULL);
+		for (uint16 cnt = 0; cnt < numElems; cnt++)
+			STOSW(destPos, rawCpt[cnt]);
+	}
 
 	*(uint32 *)destBuf = TO_LE_32(destPos - destBuf); // save size
 	return destPos - destBuf;
@@ -1298,163 +1180,143 @@
 #undef STOSD
 #undef STOSW
 
-void Control::appendMemList(uint16 *pMem) {
-	AllocedMem *newMem = new AllocedMem;
-	newMem->mem = pMem;
-	newMem->next = _memListRoot;
-	_memListRoot = newMem;
-}
-
-void Control::freeMemList(void) {
-	AllocedMem *block = _memListRoot;
-	AllocedMem *temp;
-	while (block) {
-		temp = block;
-		free(block->mem);
-		block = block->next;
-		delete temp;
-	}
-	_memListRoot = NULL;
-}
-
-
 #define LODSD(strPtr, val) { val = READ_LE_UINT32(strPtr); (strPtr) += 4; }
 #define LODSW(strPtr, val) { val = READ_LE_UINT16(strPtr); (strPtr) += 2; }
 
-void Control::lodsMegaSet(uint8 **srcPos, MegaSet *mega) {
+void Control::importOldMegaSet(uint8 **srcPos, MegaSet *mega) {
 	LODSW(*srcPos, mega->gridWidth);
 	LODSW(*srcPos, mega->colOffset);
 	LODSW(*srcPos, mega->colWidth);
 	LODSW(*srcPos, mega->lastChr);
-	// anims, stands, turnTable
 }
 
-void Control::lodsCompact(uint8 **srcPos, Compact *cpt) {
-
-	uint16 saveType, cnt;
+void Control::importOldCompact(Compact* destCpt, uint8 **srcPos, uint16 numElems, uint16 type, char *name) {
+	uint16 saveType;
 	LODSW(*srcPos, saveType);
-	if ((saveType & (SAVE_EXT | SAVE_TURNP)) && (cpt->extCompact == NULL))
-		error("Can't restore! SaveData is SAVE_EXT for Compact");
-	if ((saveType & SAVE_MEGA0) && (cpt->extCompact->megaSet0 == NULL))
-		error("Can't restore! SaveData is SAVE_MEGA0 for Compact");
-	if ((saveType & SAVE_MEGA1) && (cpt->extCompact->megaSet1 == NULL))
-		error("Can't restore! SaveData is SAVE_MEGA1 for Compact");
-	if ((saveType & SAVE_MEGA2) && (cpt->extCompact->megaSet2 == NULL))
-		error("Can't restore! SaveData is SAVE_MEGA2 for Compact");
-	if ((saveType & SAVE_MEGA3) && (cpt->extCompact->megaSet3 == NULL))
-		error("Can't restore! SaveData is SAVE_MEGA3 for Compact");
-
+	if ((saveType & (SAVE_EXT | SAVE_TURNP)) && (numElems < 54))
+		error("Cpt %s: Savedata doesn't match cpt size (%d)!\n", name, numElems);
+	if ((saveType & SAVE_MEGA0) && (numElems < 54 + 13))
+		error("Cpt %s: Savedata doesn't match cpt size (%d)!\n", name, numElems);
+	if ((saveType & SAVE_MEGA1) && (numElems < 54 + 13 + 13))
+		error("Cpt %s: Savedata doesn't match cpt size (%d)!\n", name, numElems);
+	if ((saveType & SAVE_MEGA2) && (numElems < 54 + 13 + 13 + 13))
+		error("Cpt %s: Savedata doesn't match cpt size (%d)!\n", name, numElems);
+	if ((saveType & SAVE_MEGA3) && (numElems < 54 + 13 + 13 + 13))
+		error("Cpt %s: Savedata doesn't match cpt size (%d)!\n", name, numElems);
 	if (saveType & SAVE_GRAFX) {
-		uint16 tmp;
-		LODSW(*srcPos, tmp);
-		cpt->grafixProg.ptrType = (uint8)tmp;
-		LODSW(*srcPos, cpt->grafixProg.ptrTarget);
-		LODSW(*srcPos, cpt->grafixProg.pos);
-	} else {
-		cpt->grafixProg.ptrType = PTR_NULL;
-		cpt->grafixProg.ptrTarget = 0;
-		cpt->grafixProg.pos = 0;
+		uint16 type, target, pos;
+		LODSW(*srcPos, type);
+		LODSW(*srcPos, target);
+		LODSW(*srcPos, pos);
+		// convert to new compact system..
+		destCpt->grafixProgPos = pos;
+		if (type == OG_PTR_NULL)
+			destCpt->grafixProgId = 0;
+		else if (type == OG_AUTOROUTE)
+			destCpt->grafixProgId = destCpt->animScratchId;
+		else if (type == OG_COMPACT)
+			destCpt->grafixProgId = target;
+		else if (type == OG_TALKTABLE)
+			destCpt->grafixProgId = TALKTABLE_LIST_ID | target;
+		else if (type == OG_COMPACTELEM)
+			destCpt->grafixProgId = *(uint16*)_skyCompact->getCompactElem(destCpt, target);
+		else 
+			error("Illegal GrafixProg type encountered for compact %s", name);
 	}
-
 	if (saveType & SAVE_TURNP) {
-		uint16 turnLen;
-		LODSW(*srcPos, turnLen);
-		cpt->extCompact->turnProg = (uint16 *)malloc(turnLen << 1);
-		appendMemList(cpt->extCompact->turnProg);
-		for (cnt = 0; cnt < turnLen; cnt++)
-			LODSW(*srcPos, cpt->extCompact->turnProg[cnt]);
-	} else if (cpt->extCompact)
-		cpt->extCompact->turnProg = NULL;
-
-	LODSW(*srcPos, cpt->logic);
-	LODSW(*srcPos, cpt->status);
-	LODSW(*srcPos, cpt->sync);
-	LODSW(*srcPos, cpt->screen);
-	LODSW(*srcPos, cpt->place);
+		// basically impossible to import these. simply set it to end-of-turn and hope the script
+		// will take care of it.
+		destCpt->turnProgId = 0x13B;
+		destCpt->turnProgPos = 1;
+		uint16 turnSkipLen;
+		LODSW(*srcPos, turnSkipLen);
+		*srcPos += 2 * turnSkipLen;
+	} else if (numElems >= 49) {
+		destCpt->turnProgId = 0;
+		destCpt->turnProgPos = 0;
+	}
+	LODSW(*srcPos, destCpt->logic);
+	LODSW(*srcPos, destCpt->status);
+	LODSW(*srcPos, destCpt->sync);
+	LODSW(*srcPos, destCpt->screen);
+	LODSW(*srcPos, destCpt->place);
 	// getToTable
-	LODSW(*srcPos, cpt->xcood);
-	LODSW(*srcPos, cpt->ycood);
-	LODSW(*srcPos, cpt->frame);
-	LODSW(*srcPos, cpt->cursorText);
-	LODSW(*srcPos, cpt->mouseOn);
-	LODSW(*srcPos, cpt->mouseOff);
-	LODSW(*srcPos, cpt->mouseClick);
-	LODSW(*srcPos, cpt->mouseRelX);
-	LODSW(*srcPos, cpt->mouseRelY);
-	LODSW(*srcPos, cpt->mouseSizeX);
-	LODSW(*srcPos, cpt->mouseSizeY);
-	LODSW(*srcPos, cpt->actionScript);
-	LODSW(*srcPos, cpt->upFlag);
-	LODSW(*srcPos, cpt->downFlag);
-	LODSW(*srcPos, cpt->getToFlag);
-	LODSW(*srcPos, cpt->flag);
-	LODSW(*srcPos, cpt->mood);
+	LODSW(*srcPos, destCpt->xcood);
+	LODSW(*srcPos, destCpt->ycood);
+	LODSW(*srcPos, destCpt->frame);
+	LODSW(*srcPos, destCpt->cursorText);
+	LODSW(*srcPos, destCpt->mouseOn);
+	LODSW(*srcPos, destCpt->mouseOff);
+	LODSW(*srcPos, destCpt->mouseClick);
+	LODSW(*srcPos, destCpt->mouseRelX);
+	LODSW(*srcPos, destCpt->mouseRelY);
+	LODSW(*srcPos, destCpt->mouseSizeX);
+	LODSW(*srcPos, destCpt->mouseSizeY);
+	LODSW(*srcPos, destCpt->actionScript);
+	LODSW(*srcPos, destCpt->upFlag);
+	LODSW(*srcPos, destCpt->downFlag);
+	LODSW(*srcPos, destCpt->getToFlag);
+	LODSW(*srcPos, destCpt->flag);
+	LODSW(*srcPos, destCpt->mood);
 	// grafixProg
-	LODSW(*srcPos, cpt->offset);
-	LODSW(*srcPos, cpt->mode);
-	LODSW(*srcPos, cpt->baseSub);
-	LODSW(*srcPos, cpt->baseSub_off);
+	LODSW(*srcPos, destCpt->offset);
+	LODSW(*srcPos, destCpt->mode);
+	LODSW(*srcPos, destCpt->baseSub);
+	LODSW(*srcPos, destCpt->baseSub_off);
 	if (saveType & SAVE_EXT) {
-		LODSW(*srcPos, cpt->extCompact->actionSub);
-		LODSW(*srcPos, cpt->extCompact->actionSub_off);
-		LODSW(*srcPos, cpt->extCompact->getToSub);
-		LODSW(*srcPos, cpt->extCompact->getToSub_off);
-		LODSW(*srcPos, cpt->extCompact->extraSub);
-		LODSW(*srcPos, cpt->extCompact->extraSub_off);
-		LODSW(*srcPos, cpt->extCompact->dir);
-		LODSW(*srcPos, cpt->extCompact->stopScript);
-		LODSW(*srcPos, cpt->extCompact->miniBump);
-		LODSW(*srcPos, cpt->extCompact->leaving);
-		LODSW(*srcPos, cpt->extCompact->atWatch);
-		LODSW(*srcPos, cpt->extCompact->atWas);
-		LODSW(*srcPos, cpt->extCompact->alt);
-		LODSW(*srcPos, cpt->extCompact->request);
-		LODSW(*srcPos, cpt->extCompact->spWidth_xx);
-		LODSW(*srcPos, cpt->extCompact->spColour);
-		LODSW(*srcPos, cpt->extCompact->spTextId);
-		LODSW(*srcPos, cpt->extCompact->spTime);
-		LODSW(*srcPos, cpt->extCompact->arAnimIndex);
+		LODSW(*srcPos, destCpt->actionSub);
+		LODSW(*srcPos, destCpt->actionSub_off);
+		LODSW(*srcPos, destCpt->getToSub);
+		LODSW(*srcPos, destCpt->getToSub_off);
+		LODSW(*srcPos, destCpt->extraSub);
+		LODSW(*srcPos, destCpt->extraSub_off);
+		LODSW(*srcPos, destCpt->dir);
+		LODSW(*srcPos, destCpt->stopScript);
+		LODSW(*srcPos, destCpt->miniBump);
+		LODSW(*srcPos, destCpt->leaving);
+		LODSW(*srcPos, destCpt->atWatch);
+		LODSW(*srcPos, destCpt->atWas);
+		LODSW(*srcPos, destCpt->alt);
+		LODSW(*srcPos, destCpt->request);
+		LODSW(*srcPos, destCpt->spWidth_xx);
+		LODSW(*srcPos, destCpt->spColour);
+		LODSW(*srcPos, destCpt->spTextId);
+		LODSW(*srcPos, destCpt->spTime);
+		LODSW(*srcPos, destCpt->arAnimIndex);
 		// turnProg
-		LODSW(*srcPos, cpt->extCompact->waitingFor);
-		LODSW(*srcPos, cpt->extCompact->arTargetX);
-		LODSW(*srcPos, cpt->extCompact->arTargetY);
+		LODSW(*srcPos, destCpt->waitingFor);
+		LODSW(*srcPos, destCpt->arTargetX);
+		LODSW(*srcPos, destCpt->arTargetY);
 		// animScratch
-		LODSW(*srcPos, cpt->extCompact->megaSet);
-
+		LODSW(*srcPos, destCpt->megaSet);
 		if (saveType & SAVE_MEGA0)
-			lodsMegaSet(srcPos, cpt->extCompact->megaSet0);
+			importOldMegaSet(srcPos, &(destCpt->megaSet0));
 		if (saveType & SAVE_MEGA1)
-			lodsMegaSet(srcPos, cpt->extCompact->megaSet1);
+			importOldMegaSet(srcPos, &(destCpt->megaSet1));
 		if (saveType & SAVE_MEGA2)
-			lodsMegaSet(srcPos, cpt->extCompact->megaSet2);
+			importOldMegaSet(srcPos, &(destCpt->megaSet2));
 		if (saveType & SAVE_MEGA3)
-			lodsMegaSet(srcPos, cpt->extCompact->megaSet3);
+			importOldMegaSet(srcPos, &(destCpt->megaSet3));
 	}
 }
 
 uint16 Control::parseSaveData(uint8 *srcBuf) {
-
 	uint32 reloadList[60];
 	uint32 oldSection = Logic::_scriptVariables[CUR_SECTION];
-	
 	uint32 cnt;
 	uint8 *srcPos = srcBuf;
 	uint32 size;
 	uint32 saveRev;
-
+	uint32 gameVersion;
 	LODSD(srcPos, size);
 	LODSD(srcPos, saveRev);
 	if (saveRev > SAVE_FILE_REVISION) {
 		displayMessage(0, "Unknown save file revision (%d)", saveRev);
 		return RESTORE_FAILED;
-	}
-
-	if (saveRev <= OLD_SAVEGAME_TYPE) {
+	} else if (saveRev < OLD_SAVEGAME_TYPE) {
 		displayMessage(0, "This savegame version is unsupported.");
 		return RESTORE_FAILED;
 	}
-	uint32 music, mouseType, palette, gameVersion;
-	
 	LODSD(srcPos, gameVersion);
 	if (gameVersion != SkyEngine::_systemVars.gameVersion) {
 		if ((!SkyEngine::isCDVersion()) || (gameVersion < 365)) { // cd versions are compatible
@@ -1469,7 +1331,7 @@
 	LODSW(srcPos, _skySound->_saveSounds[1]);
 	_skySound->restoreSfx();
 
-	freeMemList(); // memory from last restore isn't needed anymore
+	uint32 music, mouseType, palette;
 	LODSD(srcPos, music);
 	LODSD(srcPos, _savedCharSet);
 	LODSD(srcPos, mouseType);
@@ -1481,19 +1343,34 @@
 	for (cnt = 0; cnt < 60; cnt++)
 		LODSD(srcPos, reloadList[cnt]);
 
-	for (cnt = 0; cnt < ARRAYSIZE(_saveLoadCpts); cnt++)
-		lodsCompact(&srcPos, _saveLoadCpts[cnt]);
-
-	for (cnt = 0; cnt < ARRAYSIZE(_saveLoadARs); cnt++)
-		for (uint8 elemCnt = 0; elemCnt < 32; elemCnt++) {
-			LODSW(srcPos, _saveLoadARs[cnt][elemCnt]);
+	if (saveRev == SAVE_FILE_REVISION) {
+		for (cnt = 0; cnt < _skyCompact->_numSaveIds; cnt++) {
+			uint16 numElems;
+			uint16 *rawCpt = (uint16*)_skyCompact->fetchCptInfo(_skyCompact->_saveIds[cnt], &numElems, NULL, NULL);
+			for (uint16 elemCnt = 0; elemCnt < numElems; elemCnt++)
+				LODSW(srcPos, rawCpt[elemCnt]);
 		}
-
-	for (cnt = 0; cnt < 3; cnt++)
-		LODSW(srcPos, SkyCompact::park_table[cnt]);
-
-	for (cnt = 0; cnt < 13; cnt++)
-		LODSW(srcPos, SkyCompact::high_floor_table[cnt]);
+	} else {	// import old savegame revision
+		for (cnt = 0; cnt < (uint32)(_skyCompact->_numSaveIds - 2); cnt++) {
+			uint16 numElems;
+			uint16 type;
+			char name[128];
+			uint16 *rawCpt = (uint16*)_skyCompact->fetchCptInfo(_skyCompact->_saveIds[cnt], &numElems, &type, name);
+			if (type == COMPACT) {
+				importOldCompact((Compact*)rawCpt, &srcPos, numElems, type, name);
+			} else if (type == ROUTEBUF) {
+				assert(numElems == 32);
+				for (uint32 elemCnt = 0; elemCnt < numElems; elemCnt++)
+					LODSW(srcPos, rawCpt[elemCnt]);
+			}
+		}
+		uint16 *rawCpt = (uint16*)_skyCompact->fetchCpt(0xBF);
+		for (cnt = 0; cnt < 3; cnt++)
+			LODSW(srcPos, rawCpt[cnt]);
+		rawCpt = (uint16*)_skyCompact->fetchCpt(0xC2);
+		for (cnt = 0; cnt < 13; cnt++)
+			LODSW(srcPos, rawCpt[cnt]);
+	}
 
 	if (srcPos - srcBuf != (int32)size)
 		error("Restore failed! Savegame data = %d bytes. Expected size: %d", srcPos-srcBuf, size);
@@ -1513,11 +1390,8 @@
 	return GAME_RESTORED;
 }
 
-#undef LODSD
-#undef LODSW
 
 uint16 Control::restoreGameFromFile(bool autoSave) {
-	
 	char fName[20];
 	if (autoSave) {
 		if (SkyEngine::isCDVersion())
@@ -1581,7 +1455,7 @@
 		memset(_skyScreen->giveCurrent(), 0, GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT);
 		_skyScreen->showScreen(_skyScreen->giveCurrent());
 		_skyScreen->forceRefresh();
-		_skyScreen->setPaletteEndian((uint8 *)SkyEngine::fetchCompact(SkyEngine::_systemVars.currentPalette));
+		_skyScreen->setPaletteEndian((uint8 *)_skyCompact->fetchCpt(SkyEngine::_systemVars.currentPalette));
 	} else {
 		memset(_screenBuf, 0, FULL_SCREEN_WIDTH * FULL_SCREEN_HEIGHT);
 		_system->copyRectToScreen(_screenBuf, GAME_SCREEN_WIDTH, 0, 0, GAME_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
@@ -1596,82 +1470,18 @@
     return result;
 }
 
-uint16 *Control::lz77decode(uint16 *data) {
-	uint32 size = READ_LE_UINT32(data);
-	data += 2;
-	uint16 *outBuf = (uint16*)malloc(size << 1);
-	uint32 outPos = 0;
-	uint16 lzPos;
-	uint16 lzBuf[0x1000];
-	memset(lzBuf + 0xF00, 0, 0x200);
-	for (lzPos = 0; lzPos < 0xF00; lzPos++)
-		lzBuf[lzPos] = TO_LE_16(0xF00 - lzPos);
-	lzPos = 0;
-	uint32 indic = 0;
-	while (outPos < size) {
-		if (!(indic >> 16)) {
-			indic = READ_LE_UINT16(data) | 0xFFFF0000;
-			data++;
-		}
-		if (indic & 1) {
-			lzBuf[lzPos] = outBuf[outPos] = *data;
-			outPos++;
-			lzPos = (lzPos + 1) & 0xFFF;
-		} else {
-			uint16 lzFrom = READ_LE_UINT16(data) >> 4;
-			uint16 lzLen = (READ_LE_UINT16(data) & 0xF) + 2;
-			for (uint16 cnt = 0; cnt < lzLen; cnt++)
-				outBuf[outPos + cnt] = lzBuf[(lzPos + cnt) & 0xFFF] = lzBuf[(lzFrom + cnt) & 0xFFF];
-			
-			outPos += lzLen;
-			lzPos = (lzPos + lzLen) & 0xFFF;
-		}
-		data++;
-		indic >>= 1;
-	}
-	return outBuf;
-}
-
-void Control::applyDiff(uint16 *data, uint16 *diffData, uint16 len) {
-	for (uint16 cnt = 0; cnt < len; cnt++) {
-		data += READ_LE_UINT16(diffData);
-		diffData++;
-		*data = *diffData;
-		diffData++;
-		data++;
-	}
-}
-
 void Control::restartGame(void) {
 	if (SkyEngine::_systemVars.gameVersion <= 267)
 		return; // no restart for floppy demo
 
-	uint16 *resetData = lz77decode((uint16 *)_resetData288);
-	switch (SkyEngine::_systemVars.gameVersion) {
-	case 303:
-		applyDiff(resetData, (uint16*)_resetDiff303, 206);
-		break;
-	case 331:
-		applyDiff(resetData, (uint16*)_resetDiff331, 206);
-		break;
-	case 348:
-		applyDiff(resetData, (uint16*)_resetDiff348, 206);
-		break;
-	case 365:
-	case 368:
-	case 372:
-		applyDiff(resetData, (uint16*)_resetDiffCd, 214);
-	default:
-		break;
-	}
-	// ok, we finally have our savedata
-
+	uint8 *resetData = _skyCompact->createResetData((uint16)SkyEngine::_systemVars.gameVersion);
 	parseSaveData((uint8*)resetData);
 	free(resetData);
 	_skyScreen->forceRefresh();
+
 	memset(_skyScreen->giveCurrent(), 0, GAME_SCREEN_WIDTH * FULL_SCREEN_HEIGHT);
 	_skyScreen->showScreen(_skyScreen->giveCurrent());
-	_skyScreen->setPaletteEndian((uint8 *)SkyEngine::fetchCompact(SkyEngine::_systemVars.currentPalette));
+	_skyScreen->setPaletteEndian((uint8 *)_skyCompact->fetchCpt(SkyEngine::_systemVars.currentPalette));
 	_skyMouse->spriteMouse(_savedMouse, 0, 0);
 	SkyEngine::_systemVars.pastIntro = true;
 }

Index: control.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/control.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- control.h	27 Nov 2004 00:26:00 -0000	1.34
+++ control.h	15 Dec 2004 06:48:04 -0000	1.35
@@ -37,6 +37,7 @@
 class Text;
 class MusicBase;
 class Sound;
+class SkyCompact;
 struct Compact;
 struct dataFileHeader;
 struct MegaSet;
@@ -118,9 +119,8 @@
 #define SAVE_GRAFX	32
 #define SAVE_TURNP	64
 
-#define SAVE_FILE_REVISION 5
-// skipping revision 4, that one will be used for messy downward compatibility in 0.5.0 branch
-#define OLD_SAVEGAME_TYPE 4
+#define SAVE_FILE_REVISION 6
+#define OLD_SAVEGAME_TYPE 5
 
 struct AllocedMem {
 	uint16 *mem;
@@ -175,7 +175,7 @@
 
 class Control {
 public:
-	Control(SaveFileManager *saveFileMan, Screen *screen, Disk *disk, Mouse *mouse, Text *text, MusicBase *music, Logic *logic, Sound *sound, OSystem *system);
+	Control(SaveFileManager *saveFileMan, Screen *screen, Disk *disk, Mouse *mouse, Text *text, MusicBase *music, Logic *logic, Sound *sound, SkyCompact *skyCompact, OSystem *system);
 	void doControlPanel(void);
 	void doLoadSavePanel(void);
 	void restartGame(void);
@@ -218,33 +218,16 @@
 
 	uint16 _selectedGame;
 	uint16 saveGameToFile(void);
-	void stosMegaSet(uint8 **destPos, MegaSet *mega);
-	void stosCompact(uint8 **destPos, Compact *cpt);
-	void stosStr(uint8 **destPos, Compact *cpt, uint16 type);
 	uint32 prepareSaveData(uint8 *destBuf);
 
 	bool autoSaveExists(void);
 	uint16 restoreGameFromFile(bool autoSave);
-	void lodsMegaSet(uint8 **srcPos, MegaSet *mega);
-	void lodsCompact(uint8 **srcPos, Compact *cpt);
-	void lodsStr(uint8 **srcPos, uint16 *src);
+	void importOldMegaSet(uint8 **srcPos, MegaSet *mega);
+	void importOldCompact(Compact* destCpt, uint8 **srcPos, uint16 numElems, uint16 type, char *name);
 	uint16 parseSaveData(uint8 *srcBuf);
 
-	uint16 *lz77decode(uint16 *data);
-	void applyDiff(uint16 *data, uint16 *diffData, uint16 len);
-	static Compact *_saveLoadCpts[833]; //-----------------
-	static uint16 *_saveLoadARs[19];
-	static uint8 _resetData288[0x39B8];
-	static uint8 _resetDiff303[824];    // moved to sky/compacts/savedata.cpp
-	static uint8 _resetDiff331[824];
-	static uint8 _resetDiff348[824];
-	static uint8 _resetDiffCd[856];  //-----------------
-
-	AllocedMem *_memListRoot;
-	void appendMemList(uint16 *pMem);
-	void freeMemList(void);
-
 	SaveFileManager *_saveFileMan;
+	SkyCompact *_skyCompact;
 	Screen *_skyScreen;
 	Disk *_skyDisk;
 	Mouse *_skyMouse;

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/debug.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- debug.cpp	22 Oct 2004 18:45:35 -0000	1.15
+++ debug.cpp	15 Dec 2004 06:48:04 -0000	1.16
@@ -28,6 +28,7 @@
 #include "sky/screen.h"
 #include "sky/sky.h"
 #include "sky/struc.h"
+#include "sky/compact.h"
 
 #include "common/debugger.cpp"
 
@@ -1276,7 +1277,8 @@
 
 
 
-Debugger::Debugger(Logic *logic, Mouse *mouse, Screen *screen) : _logic(logic), _mouse(mouse), _screen(screen), _showGrid(false) {
+Debugger::Debugger(Logic *logic, Mouse *mouse, Screen *screen, SkyCompact *skyCompact) 
+: _logic(logic), _mouse(mouse), _screen(screen), _skyCompact(skyCompact), _showGrid(false) {
 	DCmd_Register("exit", &Debugger::Cmd_Exit);
 	DCmd_Register("help", &Debugger::Cmd_Help);
 	DCmd_Register("info", &Debugger::Cmd_Info);
@@ -1356,7 +1358,7 @@
 
 	for (i = 0; i < numCompacts; ++i) {
 		if (0 == strcmp(section_0_compacts[i], argv[1])) {
-			cpt = SkyEngine::fetchCompact(i);
+			cpt = _skyCompact->fetchCpt(i);
 			break;
 		}
 	}
@@ -1372,10 +1374,10 @@
 		DebugPrintf("getToFlag  : %d\n", cpt->getToFlag);
 		DebugPrintf("mode       : %d\n", cpt->mode);
 		// Mega / extCompact info
-		if (cpt->extCompact) {
+		/*if (cpt->extCompact) {
 			DebugPrintf("waitingFor : %d\n", cpt->extCompact->waitingFor);
 			DebugPrintf("arTargetX/Y: %d/%d\n", cpt->extCompact->arTargetX, cpt->extCompact->arTargetY);
-		}
+		}*/
 	} else {
 		DebugPrintf("Unknown compact: '%s'\n", argv[1]);
 	}
@@ -1471,7 +1473,7 @@
 	if (section >= 0 && section <= 6) {
 		_logic->fnEnterSection(section == 6 ? 4 : section, 0, 0);
 		_logic->fnAssignBase(ID_FOSTER, baseId[section], 0);
-		SkyEngine::fetchCompact(ID_FOSTER)->extCompact->megaSet = 0;
+		_skyCompact->fetchCpt(ID_FOSTER)->megaSet = 0;
 	} else {
 		DebugPrintf("Unknown section '%s'\n", argv[1]);
 	}

Index: debug.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/debug.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- debug.h	22 Oct 2004 18:37:42 -0000	1.7
+++ debug.h	15 Dec 2004 06:48:04 -0000	1.8
@@ -31,10 +31,11 @@
 class Logic;
 class Mouse;
 class Screen;
+class SkyCompact;
 
 class Debugger : public Common::Debugger<Debugger> {
 public:
-	Debugger(Logic *logic, Mouse *mouse, Screen *screen);
+	Debugger(Logic *logic, Mouse *mouse, Screen *screen, SkyCompact *skyCompact);
 	bool showGrid()	{	return _showGrid; }
 	
 protected:
@@ -54,6 +55,7 @@
 	Logic *_logic;
 	Mouse *_mouse;
 	Screen *_screen;
+	SkyCompact *_skyCompact;
 
 	bool _showGrid;
 };

Index: disk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/disk.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- disk.cpp	13 Dec 2004 02:02:47 -0000	1.62
+++ disk.cpp	15 Dec 2004 06:48:04 -0000	1.63
@@ -255,12 +255,12 @@
 	return 0; //not found
 }
 
-void Disk::fnCacheChip(uint32 list) {
+void Disk::fnCacheChip(uint16 *fList) {
 
 	// fnCacheChip is called after fnCacheFast
 	uint16 cnt = 0;
-	while (_buildList[cnt]) cnt++;
-	uint16 *fList = (uint16 *)SkyEngine::fetchCompact(list);
+	while (_buildList[cnt])
+		cnt++;	
 	uint16 fCnt = 0;
 	do {
 		_buildList[cnt + fCnt] = fList[fCnt] & 0x7FFFU;
@@ -269,15 +269,14 @@
 	fnCacheFiles();
 }
 
-void Disk::fnCacheFast(uint32 list) {
-
-	if (list == 0) return;
-	uint8 cnt = 0;
-	uint16 *fList = (uint16 *)SkyEngine::fetchCompact(list);
-	do {
-		_buildList[cnt] = fList[cnt] & 0x7FFFU;
-		cnt++;
-	} while (fList[cnt-1]);
+void Disk::fnCacheFast(uint16 *fList) {
+	if (fList != NULL) {
+		uint8 cnt = 0;
+		do {
+			_buildList[cnt] = fList[cnt] & 0x7FFFU;
+			cnt++;
+		} while (fList[cnt-1]);
+	}
 }
 
 void Disk::fnCacheFiles(void) {

Index: disk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/disk.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- disk.h	11 Nov 2004 10:14:35 -0000	1.16
+++ disk.h	15 Dec 2004 06:48:04 -0000	1.17
@@ -55,8 +55,8 @@
 	uint32 _lastLoadedFileSize;
 
 	void fnMiniLoad(uint16 fileNum);
-	void fnCacheFast(uint32 list);
-	void fnCacheChip(uint32 list);
+	void fnCacheFast(uint16 *fList);
+	void fnCacheChip(uint16 *fList);
 	void fnCacheFiles(void);
 	void fnFlushBuffers(void);
 	uint32 *giveLoadedFilesList(void) { return _loadedFilesList; };

Index: grid.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/grid.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- grid.cpp	11 Nov 2004 10:14:35 -0000	1.17
+++ grid.cpp	15 Dec 2004 06:48:04 -0000	1.18
@@ -23,6 +23,7 @@
 #include "sky/disk.h"
 #include "sky/grid.h"
 #include "sky/logic.h"
+#include "sky/compact.h"
 
 namespace Sky {
 
@@ -129,10 +130,11 @@
 	69,	//96
 };
 
-Grid::Grid(Disk *pDisk) {
+Grid::Grid(Disk *pDisk, SkyCompact *skyCompact) {
 	for (int cnt = 0; cnt < TOT_NO_GRIDS; cnt++)
 		_gameGrids[cnt] = NULL;
 	_skyDisk = pDisk;
+	_skyCompact = skyCompact;
 }
 
 Grid::~Grid(void) {
@@ -152,12 +154,13 @@
 		// Reloading the grids can sometimes cause problems eg when reichs door is
 		// open the door grid bit gets replaced so you can't get back in (or out)
 		if (Logic::_scriptVariables[REICH_DOOR_FLAG])
-			removeGrid(256, 280, 1, &SkyCompact::reich_door_20);
+			removeGrid(256, 280, 1, _skyCompact->fetchCpt(CPT_REICH_DOOR_20));
+			//removeGrid(256, 280, 1, &SkyCompact::reich_door_20);
 	}
 }
 
 bool Grid::getGridValues(Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth) {
-	uint16 width = SkyCompact::getMegaSet(cpt, cpt->extCompact->megaSet)->gridWidth;
+	uint16 width = SkyCompact::getMegaSet(cpt)->gridWidth;
 	return getGridValues(cpt->xcood, cpt->ycood, width, cpt, resGrid, resBitNum, resWidth);
 }
 

Index: grid.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/grid.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- grid.h	11 Nov 2004 10:31:03 -0000	1.10
+++ grid.h	15 Dec 2004 06:48:04 -0000	1.11
@@ -30,10 +30,11 @@
 
 struct Compact;
 class Disk;
+class SkyCompact;
 
 class Grid {
 public:
-	Grid(Disk *pDisk);
+	Grid(Disk *pDisk, SkyCompact *skyCompact);
 	~Grid(void);
 
 	// grid.asm routines
@@ -58,6 +59,7 @@
 	static int8 _gridConvertTable[];
 	uint8 *_gameGrids[TOT_NO_GRIDS];
 	Disk *_skyDisk;
+	SkyCompact *_skyCompact;
 };
 
 } // End of namespace Sky

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/logic.cpp,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- logic.cpp	11 Nov 2004 15:40:48 -0000	1.148
+++ logic.cpp	15 Dec 2004 06:48:04 -0000	1.149
@@ -34,11 +34,6 @@
 #include "sky/sky.h"
 #include "sky/sound.h"
 #include "sky/struc.h"
-#include "sky/talks.h"
-/*
-#include "sky/skydefs.h"
-#include "base/gameDetector.h"
-*/
 
 namespace Sky {
 
[...1181 lines suppressed...]
@@ -2554,14 +2531,16 @@
 			
 	} else {
 		//talking off-screen
-		target->extCompact->spTextId = 0; 	//don't kill any text 'cos none was made
+		target->spTextId = 0; 	//don't kill any text 'cos none was made
 		textCompact->status = 0;	//don't display text
 	}
 	// In CD version, we're doing the timing by checking when the VOC has stopped playing.
 	// Setting spTime to 10 thus means that we're doing a pause of 10 gamecycles between
 	// each sentence.
-	if (speechUsed) target->extCompact->spTime = 10;
-	else target->extCompact->spTime = (uint16)_skyText->_dtLetters + 5;
+	if (speechUsed)
+		target->spTime = 10;
+	else
+		target->spTime = (uint16)_skyText->_dtLetters + 5;
 	target->logic = L_TALK; 
 }
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/logic.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- logic.h	14 Sep 2004 20:46:04 -0000	1.39
+++ logic.h	15 Dec 2004 06:48:04 -0000	1.40
@@ -121,10 +121,12 @@
 class Screen;
 class Sound;
 class Text;
+class SkyCompact;
 
 class Logic {
 public:
 	Logic(
+		SkyCompact *skyCompact,
 		Screen *skyScreen,
 		Disk *skyDisk,
 		Text *skyText,
@@ -299,14 +301,15 @@
 
 	Common::RandomSource _rnd;
 	
-	Screen *_skyScreen;
-	Disk *_skyDisk;
-	Text *_skyText;
-	MusicBase *_skyMusic;
-	Sound *_skySound;
-	AutoRoute *_skyAutoRoute;
-	Mouse *_skyMouse;
-	Control *_skyControl;
+	SkyCompact	*_skyCompact;
+	Screen		*_skyScreen;
+	Disk		*_skyDisk;
+	Text		*_skyText;
+	MusicBase	*_skyMusic;
+	Sound		*_skySound;
+	AutoRoute	*_skyAutoRoute;
+	Mouse		*_skyMouse;
+	Control		*_skyControl;
 };
 
 } // End of namespace Sky

Index: mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/mouse.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mouse.cpp	5 Dec 2004 17:42:19 -0000	1.37
+++ mouse.cpp	15 Dec 2004 06:48:04 -0000	1.38
@@ -27,6 +27,7 @@
 #include "sky/sky.h"
 #include "sky/skydefs.h"
 #include "sky/struc.h"
+#include "sky/compact.h"
 
 namespace Sky {
 
@@ -85,9 +86,10 @@
 	24829
 };
 
-Mouse::Mouse(OSystem *system, Disk *skyDisk) {
+Mouse::Mouse(OSystem *system, Disk *skyDisk, SkyCompact *skyCompact) {
 
 	_skyDisk = skyDisk;
+	_skyCompact = skyCompact;
 	_system = system;
 	_mouseB = 0;
 	_currentCursor = 6;
@@ -215,10 +217,12 @@
 	uint32 currentListNum = Logic::_scriptVariables[MOUSE_LIST_NO];
 	uint16 *currentList;
 	do {
-		currentList = (uint16 *)SkyEngine::fetchCompact(currentListNum);
+		currentList = (uint16 *)_skyCompact->fetchCpt(currentListNum);
 		while ((*currentList != 0) && (*currentList != 0xFFFF)) {
 			uint16 itemNum = *currentList;
-			Compact *itemData = SkyEngine::fetchCompact(itemNum);
+			Compact *itemData = _skyCompact->fetchCpt(itemNum);
+			if (itemNum == 0x2E)
+				printf("menu\n");
 			currentList++;
 			if ((itemData->screen == Logic::_scriptVariables[SCREEN]) &&	(itemData->status & 16)) {
 				if (itemData->xcood + ((int16)itemData->mouseRelX) > xPos) continue;
@@ -237,8 +241,8 @@
 				return;
 			}
 		}
-		if (*currentList == 0xFFFF) currentListNum = currentList[1];
-
+		if (*currentList == 0xFFFF)
+			currentListNum = currentList[1];
 	} while (*currentList != 0);
 	if (Logic::_scriptVariables[SPECIAL_ITEM] != 0) {
 		Logic::_scriptVariables[SPECIAL_ITEM] = 0;
@@ -261,7 +265,7 @@
 	if (_mouseB) {	//anything pressed?
 		Logic::_scriptVariables[BUTTON] = _mouseB;
 		if (Logic::_scriptVariables[SPECIAL_ITEM]) { //over anything?
-			Compact *item = SkyEngine::fetchCompact(Logic::_scriptVariables[SPECIAL_ITEM]);
+			Compact *item = _skyCompact->fetchCpt(Logic::_scriptVariables[SPECIAL_ITEM]);
 			if (item->mouseClick)
 				_skyLogic->mouseScript(item->mouseClick, item);
 		}

Index: mouse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/mouse.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mouse.h	13 Sep 2004 17:05:23 -0000	1.26
+++ mouse.h	15 Dec 2004 06:48:04 -0000	1.27
@@ -31,12 +31,13 @@
 
 class Disk;
 class Logic;
+class SkyCompact;
 
 class Mouse {
 
 public:
 
-	Mouse(OSystem *system, Disk *skyDisk);
+	Mouse(OSystem *system, Disk *skyDisk, SkyCompact *skyCompact);
 	~Mouse(void);
 
 	void mouseEngine(uint16 mouseX, uint16 mouseY);
@@ -82,6 +83,7 @@
 	OSystem *_system;
 	Disk *_skyDisk;
 	Logic *_skyLogic;
+	SkyCompact *_skyCompact;
 };
 
 } // End of namespace Sky

Index: screen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/screen.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- screen.cpp	11 Nov 2004 10:14:35 -0000	1.62
+++ screen.cpp	15 Dec 2004 06:48:04 -0000	1.63
@@ -24,6 +24,7 @@
 #include "sky/disk.h"
 #include "sky/logic.h"
 #include "sky/screen.h"
+#include "sky/compact.h"
 #include "sky/sky.h"
 #include "sky/skydefs.h"
 #include "sky/struc.h"
@@ -49,10 +50,11 @@
 	63, 63, 63
 };
 
-Screen::Screen(OSystem *pSystem, Disk *pDisk) {
+Screen::Screen(OSystem *pSystem, Disk *pDisk, SkyCompact *skyCompact) {
 
 	_system = pSystem;
 	_skyDisk = pDisk;
+	_skyCompact = skyCompact;
 
 	int i;
 	uint8 tmpPal[1024];
@@ -87,7 +89,8 @@
 Screen::~Screen(void) {
 
 	free(_gameGrid);
-	if (_currentScreen) free(_currentScreen);
+	if (_currentScreen)
+		free(_currentScreen);
 }
 
 void Screen::clearScreen(void) {
@@ -137,16 +140,20 @@
 	if (tmpPal) {
 		setPalette(tmpPal);
 		free(tmpPal);
-	} else warning("Screen::setPalette: can't load file nr. %d",fileNum);
+	} else
+		warning("Screen::setPalette: can't load file nr. %d",fileNum);
 }
 
 void Screen::showScreen(uint16 fileNum) {
 
-	if (_currentScreen) free(_currentScreen);
+	if (_currentScreen)
+		free(_currentScreen);
 	_currentScreen = _skyDisk->loadFile(fileNum);
 	
-	if (_currentScreen) showScreen(_currentScreen);
-	else warning("Screen::showScreen: can't load file nr. %d",fileNum);
+	if (_currentScreen)
+		showScreen(_currentScreen);
+	else
+		warning("Screen::showScreen: can't load file nr. %d",fileNum);
 }
 
 void Screen::showScreen(uint8 *pScreen) {
@@ -208,7 +215,8 @@
 		for (uint8 cntx = 0; cntx < GRID_X; cntx++) {
 			if (_gameGrid[cnty * GRID_X + cntx] & 1) {
 				_gameGrid[cnty * GRID_X + cntx] &= ~1;
-				if (!copyWidth) copyX = cntx * GRID_W;
+				if (!copyWidth)
+					copyX = cntx * GRID_W;
 				copyWidth += GRID_W;
 			} else if (copyWidth) {
 				_system->copyRectToScreen(_currentScreen + cnty * GRID_H * GAME_SCREEN_WIDTH + copyX, GAME_SCREEN_WIDTH, copyX, cnty * GRID_H, copyWidth, GRID_H);
@@ -285,7 +293,8 @@
 	if (pal) {
 		paletteFadeUp(pal);
 		free(pal);
-	} else warning("Screen::paletteFadeUp: Can't load palette #%d",fileNr);
+	} else
+		warning("Screen::paletteFadeUp: Can't load palette #%d",fileNr);
 }
 
 void Screen::paletteFadeUp(uint8 *pal) {
@@ -320,7 +329,7 @@
 	}
 
 	if ((scroll == 0) || (SkyEngine::_systemVars.systemFlags & SF_NO_SCROLL)) {
-		uint8 *palette = (uint8 *)SkyEngine::fetchCompact(palNum);
+		uint8 *palette = (uint8 *)_skyCompact->fetchCpt(palNum);
 		if (palette == NULL)
 			error("Screen::fnFadeUp: can't fetch compact %X", palNum);
 #ifdef SCUMM_BIG_ENDIAN
@@ -331,10 +340,11 @@
 #else
 		paletteFadeUp(palette);
 #endif
-	} else if (scroll == 123) {
-		// scroll left (going right)
-		if (!_currentScreen) error("Screen::fnFadeUp[Scroll L]: _currentScreen is NULL");
-		if (!_scrollScreen) error("Screen::fnFadeUp[Scroll L]: _scrollScreen is NULL");
+	} else if (scroll == 123) {	// scroll left (going right)
+		if (!_currentScreen)
+			error("Screen::fnFadeUp[Scroll L]: _currentScreen is NULL");
+		if (!_scrollScreen)
+			error("Screen::fnFadeUp[Scroll L]: _scrollScreen is NULL");
 		uint8 *scrNewPtr, *scrOldPtr;
 		for (uint8 scrollCnt = 0; scrollCnt < (GAME_SCREEN_WIDTH / SCROLL_JUMP) - 1; scrollCnt++) {
 			scrNewPtr = _currentScreen + scrollCnt * SCROLL_JUMP;
@@ -350,10 +360,11 @@
 		}
 		showScreen(_currentScreen);
 		free(_scrollScreen);
-	} else if (scroll == 321) {
-		// scroll right (going left)
-		if (!_currentScreen) error("Screen::fnFadeUp[Scroll R]: _currentScreen is NULL");
-		if (!_scrollScreen) error("Screen::fnFadeUp[Scroll R]: _scrollScreen is NULL");
+	} else if (scroll == 321) {	// scroll right (going left)
+		if (!_currentScreen)
+			error("Screen::fnFadeUp[Scroll R]: _currentScreen is NULL");
+		if (!_scrollScreen)
+			error("Screen::fnFadeUp[Scroll R]: _scrollScreen is NULL");
 		uint8 *scrNewPtr, *scrOldPtr;
 		for (uint8 scrollCnt = 0; scrollCnt < (GAME_SCREEN_WIDTH / SCROLL_JUMP) - 1; scrollCnt++) {
 			scrNewPtr = _currentScreen + GAME_SCREEN_WIDTH - (scrollCnt + 1) * SCROLL_JUMP;
@@ -451,6 +462,8 @@
 
 				uint8 gridSta = (uint8)((screenPos / (GAME_SCREEN_WIDTH * 16))*20 + ((screenPos % GAME_SCREEN_WIDTH) >> 4));
 				uint8 gridEnd = (uint8)(((screenPos+nrToDo) / (GAME_SCREEN_WIDTH * 16))*20 + (((screenPos+nrToDo) % GAME_SCREEN_WIDTH) >> 4));
+				gridSta = MIN(gridSta, (uint8)(12 * 20 - 1));
+				gridEnd = MIN(gridEnd, (uint8)(12 * 20 - 1));
 				if (gridEnd >= gridSta)
 					for (cnt = gridSta; cnt <= gridEnd; cnt++)
 						_seqGrid[cnt] = 1;
@@ -498,7 +511,7 @@
 	if (_seqInfo.framesLeft == 0) {
 		_seqInfo.running = false;
 		if (!_seqInfo.runningItem)
-		free(_seqInfo.seqData);
+			free(_seqInfo.seqData);
 		_seqInfo.seqData = _seqInfo.seqDataPos = NULL;
 	}
 }
@@ -526,7 +539,7 @@
 		currDrawList++;
 
 		do { // a_new_draw_list:
-			uint16 *drawListData = (uint16 *)SkyEngine::fetchCompact(loadDrawList);
+			uint16 *drawListData = (uint16 *)_skyCompact->fetchCpt(loadDrawList);
 			nextDrawList = false;
 			while ((!nextDrawList) && (drawListData[0])) {
 				if (drawListData[0] == 0xFFFF) {
@@ -534,7 +547,7 @@
 					nextDrawList = true;
 				} else {
 					// process_this_id:
-					Compact *spriteComp = SkyEngine::fetchCompact(drawListData[0]);
+					Compact *spriteComp = _skyCompact->fetchCpt(drawListData[0]);
 					if ((spriteComp->status & 4) && // is it sortable playfield?(!?!)
 						(spriteComp->screen == Logic::_scriptVariables[SCREEN])) { // on current screen
 							dataFileHeader *spriteData = 
@@ -572,9 +585,12 @@
 		}
 		for (uint32 cnt = 0; cnt < spriteCnt; cnt++) {
 			drawSprite((uint8 *)sortList[cnt].sprite, sortList[cnt].compact);
-			if (sortList[cnt].compact->status & 8) vectorToGame(0x81);
-			else vectorToGame(1);
-			if (!(sortList[cnt].compact->status & 0x200)) verticalMask();
+			if (sortList[cnt].compact->status & 8)
+				vectorToGame(0x81);
+			else
+				vectorToGame(1);
+			if (!(sortList[cnt].compact->status & 0x200))
+				verticalMask();
 		}
 	}
 }
@@ -588,13 +604,13 @@
 		idNum = Logic::_scriptVariables[drawListNum];
 		drawListNum++;
 
-		drawList = (uint16 *)SkyEngine::fetchCompact(idNum);
+		drawList = (uint16 *)_skyCompact->fetchCpt(idNum);
 		while(drawList[0]) {
 			// new_draw_list:
 			while ((drawList[0] != 0) && (drawList[0] != 0xFFFF)) {
 				// back_loop:
 				// not_new_list
-				Compact *spriteData = SkyEngine::fetchCompact(drawList[0]);
+				Compact *spriteData = _skyCompact->fetchCpt(drawList[0]);
 				drawList++;
 				if ((spriteData->status & (1 << layer)) && 
 						(spriteData->screen == Logic::_scriptVariables[SCREEN])) {
@@ -604,14 +620,17 @@
 						spriteData->status = 0;
 					} else {
 						drawSprite(toBeDrawn, spriteData);
-						if (layer == BACK) verticalMask();
-						if (spriteData->status & 8) vectorToGame(0x81);
-						else vectorToGame(1);
+						if (layer == BACK)
+							verticalMask();
+						if (spriteData->status & 8)
+							vectorToGame(0x81);
+						else
+							vectorToGame(1);
 					}
 				}
 			}
 			while (drawList[0] == 0xFFFF)
-				drawList = (uint16 *)SkyEngine::fetchCompact(drawList[1]);
+				drawList = (uint16 *)_skyCompact->fetchCpt(drawList[1]);
 		}
 	}
 }
@@ -687,7 +706,8 @@
 	
 	for (uint16 cnty = 0; cnty < _sprHeight; cnty++) {
 		for (uint16 cntx = 0; cntx < _sprWidth; cntx++)
-			if (spriteData[cntx + _maskX1]) screenPtr[cntx] = spriteData[cntx + _maskX1];
+			if (spriteData[cntx + _maskX1])
+				screenPtr[cntx] = spriteData[cntx + _maskX1];
 		spriteData += _sprWidth + _maskX2 + _maskX1;
 		screenPtr += GAME_SCREEN_WIDTH;
 	}
@@ -726,20 +746,23 @@
 				uint8 *dataTrg = screenPtr;
 				for (uint32 grdCntY = 0; grdCntY < GRID_H; grdCntY++) {
 					for (uint32 grdCntX = 0; grdCntX < GRID_W; grdCntX++)
-						if (dataSrc[grdCntX]) dataTrg[grdCntX] = dataSrc[grdCntX];
+						if (dataSrc[grdCntX])
+							dataTrg[grdCntX] = dataSrc[grdCntX];
 					dataSrc += GRID_W;
 					dataTrg += GAME_SCREEN_WIDTH;
 				}
 			} // dummy_end:
 			screenPtr -= GRID_H * GAME_SCREEN_WIDTH;
 			gridOfs -= GRID_X;
-		} else return;
+		} else
+			return;
 	} // next_x
 }
 
 void Screen::verticalMask(void) {
 
-	if (_sprWidth == 0) return ;
+	if (_sprWidth == 0)
+		return ;
 	uint32 startGridOfs = (_sprY + _sprHeight - 1) * GRID_X + _sprX;
 	uint8 *startScreenPtr = (_sprY + _sprHeight - 1) * GRID_H * GAME_SCREEN_WIDTH + _sprX * GRID_W + _currentScreen;
 
@@ -754,7 +777,8 @@
 				if (scrGrid[gridOfs]) {
 					vertMaskSub(scrGrid, gridOfs, screenPtr, layerCnt);
 					break;
-				} else nLayerCnt++;
+				} else
+					nLayerCnt++;
 			}
 			// next_x:
 			screenPtr += GRID_W;

Index: screen.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/screen.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- screen.h	6 Jan 2004 12:45:32 -0000	1.19
+++ screen.h	15 Dec 2004 06:48:04 -0000	1.20
@@ -32,6 +32,7 @@
 
 class Disk;
 class SkyEngine;
+class SkyCompact;
 struct Compact;
 struct dataFileHeader;
 
@@ -51,7 +52,7 @@
 
 class Screen {
 public:
-	Screen(OSystem *pSystem, Disk *pDisk);
+	Screen(OSystem *pSystem, Disk *pDisk, SkyCompact *skyCompact);
 	~Screen(void);
 	void setPalette(uint8 *pal);
 	void setPaletteEndian(uint8 *pal);
@@ -90,6 +91,7 @@
 private:
 	OSystem *_system;
 	Disk *_skyDisk;
+	SkyCompact *_skyCompact;
 	static uint8 _top16Colours[16*3];
 	uint8 _palette[1024];
 	uint32 _currentPalette;

Index: sky.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/sky.cpp,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- sky.cpp	9 Dec 2004 15:06:47 -0000	1.164
+++ sky.cpp	15 Dec 2004 06:48:04 -0000	1.165
@@ -30,7 +30,6 @@
 #include "common/file.h"
 #include "common/timer.h"
 
-#include "sky/compact.h"
 #include "sky/control.h"
 #include "sky/debug.h"
 #include "sky/disk.h"
@@ -47,6 +46,7 @@
 #include "sky/skydefs.h"
 #include "sky/sound.h"
 #include "sky/text.h"
+#include "sky/compact.h"
 
 #include "sound/mididrv.h"
 #include "sound/mixer.h"
@@ -112,7 +112,7 @@
 
 namespace Sky {
 
-void **SkyEngine::_itemList[300];
+void *SkyEngine::_itemList[300];
 
 SystemVars SkyEngine::_systemVars = {0, 0, 0, 0, 4316, 0, 0, false, false };
 
@@ -293,25 +293,23 @@
 	_systemVars.systemFlags |= SF_PLAY_VOCS;
 	_systemVars.gameSpeed = 50;
 
-	_skyText = new Text(_skyDisk);
-	_skyMouse = new Mouse(_system, _skyDisk);
-	_skyScreen = new Screen(_system, _skyDisk);
+	_skyCompact = new SkyCompact();
+	_skyText = new Text(_skyDisk, _skyCompact);
+	_skyMouse = new Mouse(_system, _skyDisk, _skyCompact);
+	_skyScreen = new Screen(_system, _skyDisk, _skyCompact);
 
 	initVirgin();
 	initItemList();
 	loadFixedItems();
-	_skyLogic = new Logic(_skyScreen, _skyDisk, _skyText, _skyMusic, _skyMouse, _skySound);
+	_skyLogic = new Logic(_skyCompact, _skyScreen, _skyDisk, _skyText, _skyMusic, _skyMouse, _skySound);
 	_skyMouse->useLogicInstance(_skyLogic);
 	
 	// initialize timer *after* _skyScreen has been initialized.
 	_timer->installTimerProc(&timerHandler, 1000000 / 50, this); //call 50 times per second
 
-	_skyControl = new Control(_saveFileMan, _skyScreen, _skyDisk, _skyMouse, _skyText, _skyMusic, _skyLogic, _skySound, _system);
+	_skyControl = new Control(_saveFileMan, _skyScreen, _skyDisk, _skyMouse, _skyText, _skyMusic, _skyLogic, _skySound, _skyCompact, _system);
 	_skyLogic->useControlInstance(_skyControl);
 
-	if (_systemVars.gameVersion == 288)
-		SkyCompact::patchFor288();
-
 	switch (Common::parseLanguage(ConfMan.get("language"))) {
 	case Common::DE_DEU:
 		_systemVars.language = SKY_GERMAN;
@@ -364,7 +362,7 @@
 
 	_skyMusic->setVolume(ConfMan.getInt("music_volume") >> 1);
 
-	_debugger = new Debugger(_skyLogic, _skyMouse, _skyScreen);
+	_debugger = new Debugger(_skyLogic, _skyMouse, _skyScreen, _skyCompact);
 	
 	return 0;
 }
@@ -374,10 +372,12 @@
 	//See List.asm for (cryptic) item # descriptions
 
 	for (int i = 0; i < 300; i++)
-		_itemList[i] = (void **)NULL;
+		_itemList[i] = NULL;
 
 	//init the non-null items
-	_itemList[119] = (void **)SkyCompact::data_0; // Compacts - Section 0
+	// I don't see where the script could possible access this.. so it should be safe to
+	// leave these as NULL.
+	/*_itemList[119] = (void **)SkyCompact::data_0; // Compacts - Section 0
 	_itemList[120] = (void **)SkyCompact::data_1; // Compacts - Section 1
 	
 	if (isDemo()) {
@@ -388,7 +388,7 @@
 		_itemList[123] = (void **)SkyCompact::data_4; // Compacts - Section 4
 		_itemList[124] = (void **)SkyCompact::data_5; // Compacts - Section 5
 		_itemList[125] = (void **)SkyCompact::data_6; // Compacts - Section 6
-	}
+	}*/
 }
 
 void SkyEngine::loadBase0(void) {
@@ -400,29 +400,25 @@
 
 void SkyEngine::loadFixedItems(void) {
 
-	if (!isDemo())
-		_itemList[36] = (void **)_skyDisk->loadFile(36);
-
-	_itemList[49] = (void **)_skyDisk->loadFile(49);
-	_itemList[50] = (void **)_skyDisk->loadFile(50);
-	_itemList[73] = (void **)_skyDisk->loadFile(73);
-	_itemList[262] = (void **)_skyDisk->loadFile(262);
+	_itemList[49] = _skyDisk->loadFile(49);
+	_itemList[50] = _skyDisk->loadFile(50);
+	_itemList[73] = _skyDisk->loadFile(73);
+	_itemList[262] = _skyDisk->loadFile(262);
 
-	if (isDemo()) 
-		return;
-	
-	_itemList[263] = (void **)_skyDisk->loadFile(263);
-	_itemList[264] = (void **)_skyDisk->loadFile(264);
-	_itemList[265] = (void **)_skyDisk->loadFile(265);
-	_itemList[266] = (void **)_skyDisk->loadFile(266);
-	_itemList[267] = (void **)_skyDisk->loadFile(267);
-	_itemList[269] = (void **)_skyDisk->loadFile(269);
-	_itemList[271] = (void **)_skyDisk->loadFile(271);
-	_itemList[272] = (void **)_skyDisk->loadFile(272);
-		
+	if (!isDemo()) {
+		_itemList[36] = _skyDisk->loadFile(36);
+		_itemList[263] = _skyDisk->loadFile(263);
+		_itemList[264] = _skyDisk->loadFile(264);
+		_itemList[265] = _skyDisk->loadFile(265);
+		_itemList[266] = _skyDisk->loadFile(266);
+		_itemList[267] = _skyDisk->loadFile(267);
+		_itemList[269] = _skyDisk->loadFile(269);
+		_itemList[271] = _skyDisk->loadFile(271);
+		_itemList[272] = _skyDisk->loadFile(272);
+	}		
 }
 
-void **SkyEngine::fetchItem(uint32 num) {
+void *SkyEngine::fetchItem(uint32 num) {
 
 	return _itemList[num];
 }
@@ -437,14 +433,6 @@
 	_skyScreen->handleTimer();
 }
 
-Compact *SkyEngine::fetchCompact(uint32 a) {
-	Debug::fetchCompact(a);
-	uint32 sectionNum = (a & 0xf000) >> 12;
-	uint32 compactNum = (a & 0x0fff);
-
-	return (Compact *)(_itemList[119 + sectionNum][compactNum]);
-}
-
 void SkyEngine::delay(uint amount) {
 
 	OSystem::Event event;

Index: sky.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/sky.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- sky.h	24 Nov 2004 00:14:19 -0000	1.62
+++ sky.h	15 Dec 2004 06:48:04 -0000	1.63
@@ -52,6 +52,7 @@
 class MusicBase;
 class Intro;
 class Debugger;
+class SkyCompact;
 
 class SkyEngine : public Engine {
 	void errorString(const char *buf_input, char *buf_output);
@@ -69,6 +70,7 @@
 	Mouse *_skyMouse;
 	Screen *_skyScreen;
 	Control *_skyControl;
+	SkyCompact *_skyCompact;
 	Debugger *_debugger;
 	
 	MusicBase *_skyMusic;
@@ -81,10 +83,8 @@
 	static bool isDemo(void);
 	static bool isCDVersion(void);
 
-	static Compact *fetchCompact(uint32 a);
-	static void **fetchItem(uint32 num);
-	
-	static void **_itemList[300];
+	static void *fetchItem(uint32 num);
+	static void *_itemList[300];
 
 	static SystemVars _systemVars;
 

Index: skydefs.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/skydefs.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- skydefs.h	6 Jan 2004 12:45:32 -0000	1.28
+++ skydefs.h	15 Dec 2004 06:48:04 -0000	1.29
@@ -29,11 +29,11 @@
 //This file is incomplete, several flags still missing.
 
 // grafixProg pointer types:
-#define PTR_NULL	0
-#define AUTOROUTE	1
-#define COMPACT		2
-#define COMPACTELEM	3 // needed by fnSetToStand
-#define TALKTABLE	4
+#define OG_PTR_NULL		0
+#define OG_AUTOROUTE	1
+#define OG_COMPACT		2
+#define OG_COMPACTELEM	3 // needed by fnSetToStand
+#define OG_TALKTABLE	4
 
 // language codes:
 #define SKY_ENGLISH		0

Index: struc.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/struc.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- struc.h	16 Sep 2004 07:35:01 -0000	1.15
+++ struc.h	15 Dec 2004 06:48:04 -0000	1.16
@@ -54,125 +54,119 @@
 	uint16 s_compressed_size;
 } GCC_PACK;
 
-#if !defined(__GNUC__)
-#pragma END_PACK_STRUCTS
-#endif
-
-struct GrafixPtr { // replacement for old grafixProg pointer. More savegame compatible.
-	uint8 ptrType; // ptr to autoroute / to compact / to turntable
-	uint16 ptrTarget; // compact / turntable number
-	uint16 pos; // position
-};
-
 struct TurnTable {
-	uint16 *turnTableUp[5];
-	uint16 *turnTableDown[5];
-	uint16 *turnTableLeft[5];
-	uint16 *turnTableRight[5];
-	uint16 *turnTableTalk[5];
-};
+	uint16 turnTableUp[5];
+	uint16 turnTableDown[5];
+	uint16 turnTableLeft[5];
+	uint16 turnTableRight[5];
+	uint16 turnTableTalk[5];
+} GCC_PACK;
 
 struct MegaSet {
-	uint16 gridWidth;
-	uint16 colOffset;
-	uint16 colWidth;
-	uint16 lastChr;
+	uint16 gridWidth;	 //  0
+	uint16 colOffset;	 //  1
+	uint16 colWidth;	 //  2
+	uint16 lastChr;		 //  3
 
-	uint16 *animUp;
-	uint16 *animDown;
-	uint16 *animLeft;
-	uint16 *animRight;
+	uint16 animUpId;	 //  4
+	uint16 animDownId;	 //  5
+	uint16 animLeftId;	 //  6
+	uint16 animRightId;	 //  7
 
-	uint16 *standUp;
-	uint16 *standDown;
-	uint16 *standLeft;
-	uint16 *standRight;
-	uint16 *standTalk;
-	TurnTable *turnTable;
-};
+	uint16 standUpId;	 //  8
+	uint16 standDownId;	 //  9
+	uint16 standLeftId;	 // 10
+	uint16 standRightId; // 11
+	uint16 standTalkId;	 // 12
+	uint16 turnTableId;	 // 13
+} GCC_PACK;
 
-struct ExtCompact {
-	uint16 actionSub;
-	uint16 actionSub_off;
-	uint16 getToSub;
-	uint16 getToSub_off;
-	uint16 extraSub;
-	uint16 extraSub_off;
+struct Compact {
+	uint16 logic;		 //  0: Entry in logic table to run (byte as <256entries in logic table
+	uint16 status;		 //  1
+	uint16 sync;		 //  2: flag sent to compacts by other things
 
-	uint16 dir;
+	uint16 screen;		 //  3: current screen
+	uint16 place;		 //  4: so's this one
+	uint16 getToTableId; //  5: Address of how to get to things table
 
-	uint16 stopScript;
-	uint16 miniBump;
-	uint16 leaving;
-	uint16 atWatch; // pointer to script variable
-	uint16 atWas; // pointer to script variable
-	uint16 alt; // alternate script
-	uint16 request;
+	uint16 xcood;		 //  6
+	uint16 ycood;		 //  7
 
-	uint16 spWidth_xx;
-	uint16 spColour;
-	uint16 spTextId;
-	uint16 spTime;
+	uint16 frame;		 //  8
 
-	uint16 arAnimIndex;
-	uint16 *turnProg;
+	uint16 cursorText;	 //  9
+	uint16 mouseOn;		 // 10
+	uint16 mouseOff;	 // 11
+	uint16 mouseClick;	 // 12
 
-	uint16 waitingFor;
+	int16 mouseRelX;	 // 13
+	int16 mouseRelY;	 // 14
+	uint16 mouseSizeX;	 // 15
+	uint16 mouseSizeY;	 // 16
 
-	uint16 arTargetX;
-	uint16 arTargetY;
+	uint16 actionScript; // 17
 
-	uint16 *animScratch; // data area for AR
+	uint16 upFlag;		 // 18: usually holds the Action Mode
+	uint16 downFlag;	 // 19: used for passing back
+	uint16 getToFlag;	 // 20: used by action script for get to attempts, also frame store (hence word)
+	uint16 flag;		 // 21: a use any time flag
 
-	uint16 megaSet;
-	MegaSet *megaSet0;
-	MegaSet *megaSet1;
-	MegaSet *megaSet2;
-	MegaSet *megaSet3;
-};
+	uint16 mood;		 // 22: high level - stood or not
+	
+	uint16 grafixProgId; // 23
+	uint16 grafixProgPos;// 24
 
-struct Compact {
-	uint16 logic; // Entry in logic table to run (byte as <256entries in logic table
-	uint16 status;
-	uint16 sync; // flag sent to compacts by other things
+	uint16 offset;		 // 25
 
-	uint16 screen; // current screen
-	uint16 place; // so's this one
-	uint16 *getToTable; // Address of how to get to things table
+	uint16 mode;		 // 26: which mcode block
 
-	uint16 xcood;
-	uint16 ycood;
+	uint16 baseSub;		 // 27: 1st mcode block relative to start of compact
+	uint16 baseSub_off;	 // 28
+	uint16 actionSub;	 // 29
+	uint16 actionSub_off;// 30
+	uint16 getToSub;	 // 31
+	uint16 getToSub_off; // 32
+	uint16 extraSub;	 // 33
+	uint16 extraSub_off; // 34
 
-	uint16 frame;
+	uint16 dir;			 // 35
 
-	uint16 cursorText;
-	uint16 mouseOn;
-	uint16 mouseOff;
-	uint16 mouseClick; // dword script
+	uint16 stopScript;	 // 36
+	uint16 miniBump;	 // 37
+	uint16 leaving;		 // 38
+	uint16 atWatch;		 // 39: pointer to script variable
+	uint16 atWas;		 // 40: pointer to script variable
+	uint16 alt;			 // 41: alternate script
+	uint16 request;		 // 42
 
-	int16 mouseRelX;
-	int16 mouseRelY;
-	uint16 mouseSizeX;
-	uint16 mouseSizeY;
+	uint16 spWidth_xx;	 // 43
+	uint16 spColour;	 // 44
+	uint16 spTextId;	 // 45
+	uint16 spTime;		 // 46
 
-	uint16 actionScript;
+	uint16 arAnimIndex;	 // 47
+	uint16 turnProgId;	 // 48
+	uint16 turnProgPos;	 // 49
 
-	uint16 upFlag; // usually holds the Action Mode
-	uint16 downFlag; // used for passing back
-	uint16 getToFlag; // used by action script for get to attempts, also frame store (hence word)
-	uint16 flag; // a use any time flag
+	uint16 waitingFor;	 // 50
 
-	uint16 mood; // high level - stood or not
-	GrafixPtr grafixProg;
-	uint16 offset;
+	uint16 arTargetX;	 // 51
+	uint16 arTargetY;	 // 52
 
-	uint16 mode; // which mcode block
+	uint16 animScratchId;// 53: data area for AR
 
-	uint16 baseSub; // 1st mcode block relative to start of compact
-	uint16 baseSub_off;
+	uint16 megaSet;		 // 54
 
-	ExtCompact *extCompact;
-};
+	MegaSet megaSet0;	 // 55
+	MegaSet megaSet1;	 // 
+	MegaSet megaSet2;	 // 
+	MegaSet megaSet3;	 // 
+} GCC_PACK;
+
+#if !defined(__GNUC__)
+#pragma END_PACK_STRUCTS
+#endif
 
 } // End of namespace Sky
 

Index: text.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/text.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- text.cpp	11 Nov 2004 10:14:35 -0000	1.62
+++ text.cpp	15 Dec 2004 06:48:04 -0000	1.63
@@ -25,6 +25,7 @@
 #include "sky/sky.h"
 #include "sky/skydefs.h"
 #include "sky/struc.h"
+#include "sky/compact.h"
 
 namespace Sky {
 
@@ -36,8 +37,9 @@
 #define CHAR_SET_HEADER	128
 #define	MAX_NO_LINES	10
 
-Text::Text(Disk *skyDisk) {
+Text::Text(Disk *skyDisk, SkyCompact *skyCompact) {
 	_skyDisk = skyDisk;
+	_skyCompact = skyCompact;
 
 	initHuffTree();
 
@@ -247,10 +249,10 @@
 void Text::fnTextModule(uint32 textInfoId, uint32 textNo) {
 
 	fnSetFont(1);
-	uint16* msgData = (uint16 *)SkyEngine::fetchCompact(textInfoId);
+	uint16* msgData = (uint16 *)_skyCompact->fetchCpt(textInfoId);
 	lowTextManager_t textId = lowTextManager(textNo, msgData[1], msgData[2], 209, false);
 	Logic::_scriptVariables[RESULT] = textId.compactNum;
-	Compact *textCompact = SkyEngine::fetchCompact(textId.compactNum);
+	Compact *textCompact = _skyCompact->fetchCpt(textId.compactNum);
 	textCompact->xcood = msgData[3];
 	textCompact->ycood = msgData[4];
 	fnSetFont(0);
@@ -331,7 +333,7 @@
 
 void Text::fnPointerText(uint32 pointedId, uint16 mouseX, uint16 mouseY) {
 
-	Compact *ptrComp = SkyEngine::fetchCompact(pointedId);
+	Compact *ptrComp = _skyCompact->fetchCpt(pointedId);
 	lowTextManager_t text = lowTextManager(ptrComp->cursorText, TEXT_MOUSE_WIDTH, L_CURSOR, 242, false);
 	Logic::_scriptVariables[CURSOR_ID] = text.compactNum;
 	if (Logic::_scriptVariables[MENU]) {
@@ -343,7 +345,7 @@
 		if (mouseX < 150) _mouseOfsX = TOP_LEFT_X + 13;
 		else _mouseOfsX = TOP_LEFT_X - 8 - _lowTextWidth;
 	}
-	Compact *textCompact = SkyEngine::fetchCompact(text.compactNum);
+	Compact *textCompact = _skyCompact->fetchCpt(text.compactNum);
 	logicCursor(textCompact, mouseX, mouseY);
 }
 
@@ -537,11 +539,11 @@
 
 	uint32 compactNum = FIRST_TEXT_COMPACT;
 
-	Compact *cpt = SkyEngine::fetchCompact(compactNum);
+	Compact *cpt = _skyCompact->fetchCpt(compactNum);
 
 	while (cpt->status != 0) { 
 		compactNum++;
-		cpt = SkyEngine::fetchCompact(compactNum);
+		cpt = _skyCompact->fetchCpt(compactNum);
 	}
 
 	cpt->flag = (uint16)(compactNum - FIRST_TEXT_COMPACT) + FIRST_TEXT_BUFFER;

Index: text.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/text.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- text.h	6 Jan 2004 12:45:32 -0000	1.32
+++ text.h	15 Dec 2004 06:48:04 -0000	1.33
@@ -29,6 +29,7 @@
 
 struct Compact;
 class Disk;
+class SkyCompact;
 
 struct HuffTree {
 	unsigned char lChild;
@@ -45,7 +46,7 @@
 
 class Text {
 public:
-	Text(Disk *skyDisk);
+	Text(Disk *skyDisk, SkyCompact *skyCompact);
 	~Text(void);
 	void getText(uint32 textNr);
 	struct displayText_t displayText(uint8 *dest, bool centre, uint16 pixelWidth, uint8 color);
@@ -68,6 +69,7 @@
 	bool patchMessage(uint32 textNum);
 
 	Disk *_skyDisk;
+	SkyCompact *_skyCompact;
 	uint8	_inputValue;
 	uint8	_shiftBits;
 	uint8	*_textItemPtr;

--- talks.h DELETED ---





More information about the Scummvm-git-logs mailing list