[Scummvm-cvs-logs] CVS: scummvm/saga actor.cpp,1.158,1.159 actor.h,1.85,1.86 animation.cpp,1.48,1.49 animation.h,1.25,1.26 console.cpp,1.27,1.28 console.h,1.14,1.15 events.cpp,1.60,1.61 font.cpp,1.31,1.32 font.h,1.14,1.15 game.cpp,1.76,1.77 gfx.cpp,1.54,1.55 gfx.h,1.34,1.35 ihnm_introproc.cpp,1.44,1.45 image.cpp,1.23,1.24 input.cpp,1.48,1.49 interface.cpp,1.119,1.120 interface.h,1.64,1.65 isomap.cpp,1.56,1.57 ite_introproc.cpp,1.59,1.60 music.cpp,1.55,1.56 music.h,1.23,1.24 objectmap.cpp,1.42,1.43 objectmap.h,1.22,1.23 palanim.cpp,1.24,1.25 rscfile.cpp,1.23,1.24 rscfile.h,1.10,1.11 saga.cpp,1.120,1.121 saga.h,1.106,1.107 scene.cpp,1.121,1.122 scene.h,1.62,1.63 script.cpp,1.70,1.71 script.h,1.93,1.94 sfuncs.cpp,1.139,1.140 sndres.cpp,1.44,1.45 sndres.h,1.20,1.21 sound.cpp,1.29,1.30 sound.h,1.21,1.22 sprite.cpp,1.59,1.60 sprite.h,1.21,1.22 sthread.cpp,1.85,1.86

Andrew Kurushin h00ligan at users.sourceforge.net
Tue Jul 19 12:10:26 CEST 2005


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

Modified Files:
	actor.cpp actor.h animation.cpp animation.h console.cpp 
	console.h events.cpp font.cpp font.h game.cpp gfx.cpp gfx.h 
	ihnm_introproc.cpp image.cpp input.cpp interface.cpp 
	interface.h isomap.cpp ite_introproc.cpp music.cpp music.h 
	objectmap.cpp objectmap.h palanim.cpp rscfile.cpp rscfile.h 
	saga.cpp saga.h scene.cpp scene.h script.cpp script.h 
	sfuncs.cpp sndres.cpp sndres.h sound.cpp sound.h sprite.cpp 
	sprite.h sthread.cpp 
Log Message:
finally Resource manager rewritten:
-adds patch file support
-global _vm removed

cleanups

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.cpp,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- actor.cpp	18 Jul 2005 14:37:04 -0000	1.158
+++ actor.cpp	19 Jul 2005 19:05:38 -0000	1.159
@@ -25,7 +25,6 @@
 #include "saga/gfx.h"
 
 #include "saga/console.h"
-#include "saga/rscfile_mod.h"
 #include "saga/script.h"
 #include "saga/sndres.h"
 #include "saga/sprite.h"
@@ -40,6 +39,9 @@
 #include "saga/interface.h"
 #include "saga/events.h"
 #include "saga/objectmap.h"
+#include "saga/rscfile.h"
+#include "saga/resnames.h"
+
 #include "common/config-manager.h"
 
 namespace Saga {
@@ -164,7 +166,6 @@
 
 Actor::Actor(SagaEngine *vm) : _vm(vm) {
 	int i;
-	int result;
 	byte *stringsPointer;
 	size_t stringsLength;
 	ActorData *actor;
@@ -207,18 +208,15 @@
 
 	if (_vm->getGameType() == GType_ITE) {
 		// Get actor resource file context
-		_actorContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
+		_actorContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
 		if (_actorContext == NULL) {
-			error("Actor::Actor(): Couldn't load actor module resource context.");
+			error("Actor::Actor() resource context not found");
 		}
 	
-		result = RSC_LoadResource(_actorContext, _vm->getResourceDescription()->actorsStringsResourceId, &stringsPointer, &stringsLength);
-		if ((result != SUCCESS) || (stringsLength == 0)) {
-			error("Error loading strings list resource");
-		}
+		_vm->_resource->loadResource(_actorContext, _vm->getResourceDescription()->actorsStringsResourceId, stringsPointer, stringsLength);
 	
 		_vm->loadStrings(_actorsStrings, stringsPointer, stringsLength);
-		RSC_FreeResource(stringsPointer);
+		free(stringsPointer);
 	} else {
 		// TODO
 	}
@@ -325,10 +323,7 @@
 	}
 
 	debug(9, "Loading frame resource id %d", actor->frameListResourceId);
-	if (RSC_LoadResource(_actorContext, actor->frameListResourceId, &resourcePointer, &resourceLength) != SUCCESS) {
-		warning("Couldn't load sprite action index resource");
-		return false;
-	}
+	_vm->_resource->loadResource(_actorContext, actor->frameListResourceId, resourcePointer, resourceLength);
 
 	framesCount = resourceLength / 16;
 	debug(9, "Frame resource contains %d frames", framesCount);
@@ -338,7 +333,7 @@
 		memoryError("Actor::loadActorResources");
 	}
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _actorContext->isBigEndian);
 
 	lastFrame = 0;
 
@@ -355,27 +350,22 @@
 		}
 	}
 
-	RSC_FreeResource(resourcePointer);
+	free(resourcePointer);
 
 	actor->frames = framesPointer;
 	actor->framesCount = framesCount;
 
 	resourceId = actor->spriteListResourceId;
 	debug(9, "Loading sprite resource id %d", resourceId);
-	if (_vm->_sprite->loadList(resourceId, actor->spriteList) != SUCCESS) {
-		warning("loadActorResources: Unable to load sprite list");
-		return false;
-	}
+
+	_vm->_sprite->loadList(resourceId, actor->spriteList);
 
 	i = actor->spriteList.spriteCount;
 	if ((actor->flags & kExtended)) {
 		while ((lastFrame >= actor->spriteList.spriteCount)) {
 			resourceId++;
 			debug(9, "Appending to sprite list %d", resourceId);
-			if (_vm->_sprite->loadList(resourceId, actor->spriteList) != SUCCESS) {
-				warning("Unable append sprite list");
-				return false;
-			}
+			_vm->_sprite->loadList(resourceId, actor->spriteList);
 		}
 	}
 
@@ -2652,7 +2642,7 @@
 
 	for (i = 0; i < _actorsCount; i++) {
 		ActorData *a = _actors[i];
-		a->loadState(in);
+		a->loadState(_vm->getCurrentLoadVersion(), in);
 	}
 
 	for (i = 0; i < _objsCount; i++) {

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.h,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- actor.h	15 Jul 2005 15:23:19 -0000	1.85
+++ actor.h	19 Jul 2005 19:05:40 -0000	1.86
@@ -375,7 +375,7 @@
 		out->writeSint32LE(walkFrameSequence);
 	}
 
-	void loadState(Common::InSaveFile *in) {
+	void loadState(uint32 version, Common::InSaveFile *in) {
 		int i = 0;
 		CommonObjectData::loadState(in);
 		actorFlags = in->readUint16LE();
@@ -390,14 +390,14 @@
 		cycleDelay = in->readByte();
 		cycleTimeCount = in->readByte();
 		cycleFlags = in->readByte();
-		if (_vm->getCurrentLoadVersion() > 1) {
+		if (version > 1) {
 			fallVelocity = in->readSint16LE();			
 			fallAcceleration = in->readSint16LE();			
 			fallPosition = in->readSint16LE();			
 		} else {
 			fallVelocity = fallAcceleration = fallPosition = 0;
 		}
-		if (_vm->getCurrentLoadVersion() > 2) {
+		if (version > 2) {
 			dragonBaseFrame = in->readByte();			
 			dragonStepCycle = in->readByte();			
 			dragonMoveType = in->readByte();			
@@ -621,7 +621,7 @@
 	ObjectData **_objs;
 
 	SagaEngine *_vm;
-	RSCFILE_CONTEXT *_actorContext;
+	ResourceContext *_actorContext;
 
 	StringsTable _actorsStrings;
 	int _lastTickMsec;

Index: animation.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/animation.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- animation.cpp	9 Jul 2005 16:23:44 -0000	1.48
+++ animation.cpp	19 Jul 2005 19:05:41 -0000	1.49
@@ -46,6 +46,7 @@
 
 void Anim::load(uint16 animId, const byte *animResourceData, size_t animResourceLength) {
 	AnimationData *anim;
+	uint16 temp;
 
 	if (animId >= MAX_ANIMATIONS) {
 		error("Anim::load could not find unused animation slot");
@@ -53,7 +54,7 @@
 
 	anim = _animations[animId] = new AnimationData(animResourceData, animResourceLength);
 
-	MemoryReadStreamEndian headerReadS(anim->resourceData, anim->resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian headerReadS(anim->resourceData, anim->resourceLength, _vm->isBigEndian());
 	anim->magic = headerReadS.readUint16LE(); // cause ALWAYS LE
 	anim->screenWidth = headerReadS.readUint16();
 	anim->screenHeight = headerReadS.readUint16();
@@ -62,9 +63,12 @@
 	anim->unknown07 = headerReadS.readByte();
 	anim->maxFrame = headerReadS.readByte() - 1;
 	anim->loopFrame = headerReadS.readByte() - 1;
-	anim->start = headerReadS.readUint16BE();
-
-	anim->start += headerReadS.pos();
+	temp = headerReadS.readUint16BE();
+	anim->start = headerReadS.pos();
+	if (temp == (uint16)(-1)) {
+		temp = 0;
+	}
+	anim->start += temp;
 
 
 	if (_vm->getGameType() == GType_ITE) {
@@ -76,8 +80,15 @@
 
 		fillFrameOffsets(anim);
 	} else {
-		anim->cur_frame_p = anim->resourceData + SAGA_FRAME_HEADER_LEN; // ? len - may vary
-		anim->cur_frame_len = anim->resourceLength - SAGA_FRAME_HEADER_LEN;
+/*		anim->frameOffsets = (size_t *)malloc((anim->maxFrame + 1) * sizeof(*anim->frameOffsets));
+		if (anim->frameOffsets == NULL) {
+			memoryError("Anim::load");
+		}
+
+		fillFrameOffsets(anim);*/
+
+		anim->cur_frame_p = anim->resourceData + getFrameHeaderLength(); // ? len - may vary
+		anim->cur_frame_len = anim->resourceLength - getFrameHeaderLength();
 	}
 
 	// Set animation data
@@ -179,8 +190,8 @@
 			
 			if (_vm->getGameType() == GType_IHNM) {
 				// FIXME: HACK. probably needs more testing for IHNM
-				anim->cur_frame_p = anim->resourceData + SAGA_FRAME_HEADER_LEN;
-				anim->cur_frame_len = anim->resourceLength - SAGA_FRAME_HEADER_LEN;
+				anim->cur_frame_p = anim->resourceData + getFrameHeaderLength();
+				anim->cur_frame_len = anim->resourceLength - getFrameHeaderLength();
 			}
 			
 			if (anim->flags & ANIM_STOPPING || anim->currentFrame == -1) {
@@ -489,7 +500,7 @@
 
 	size_t in_ch_offset;
 
-	MemoryReadStreamEndian readS(thisf_p, thisf_len, !IS_BIG_ENDIAN); // RLE has inversion BE<>LE
+	MemoryReadStreamEndian readS(thisf_p, thisf_len, !_vm->isBigEndian()); // RLE has inversion BE<>LE
 
 	byte *outbuf_p = decode_buf;
 	byte *outbuf_endp = (decode_buf + decode_buf_len) - 1;
@@ -502,7 +513,7 @@
 		in_ch_offset = readS.pos();
 		in_ch = readS.readByte();
 		switch (in_ch) {
-		case 0x0F: // 15: Frame header
+		case SAGA_FRAME_START: // Frame header
 			{
 				int param1;
 				int param2;
@@ -702,12 +713,16 @@
 
 	int i;
 
-	MemoryReadStreamEndian readS(anim->resourceData, anim->resourceLength, IS_BIG_ENDIAN); 
+	MemoryReadStreamEndian readS(anim->resourceData, anim->resourceLength, _vm->isBigEndian()); 
 
-	readS.seek(12);
+	if (_vm->getGameType() == GType_ITE) {
+		readS.seek(12);
+	} else {
+		readS.seek(15);		// ihnm has longer anim header
+	}
 	
 
-	readS._bigEndian = !IS_BIG_ENDIAN; // RLE has inversion BE<>LE
+	readS._bigEndian = !_vm->isBigEndian(); // RLE has inversion BE<>LE
 
 	for (currentFrame = 0; currentFrame <= anim->maxFrame; currentFrame++) {
 		anim->frameOffsets[currentFrame] = readS.pos();
@@ -723,14 +738,14 @@
 		}
 
 		// skip header
-		readS.seek(SAGA_FRAME_HEADER_LEN, SEEK_CUR);
+		readS.seek(getFrameHeaderLength(), SEEK_CUR);
 
 		// For some strange reason, the animation header is in little
 		// endian format, but the actual RLE encoded frame data, 
 		// including the frame header, is in big endian format. */
 		do {
 			mark_byte = readS.readByte();
-//			debug(7, "_pos=%x mark_byte=%x", readS.pos(), mark_byte);
+//			debug(7, "_pos=%x currentFrame=%i mark_byte=%x", readS.pos(), currentFrame, mark_byte);
 
 			switch (mark_byte) {
 			case SAGA_FRAME_END: // End of frame marker

Index: animation.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/animation.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- animation.h	25 Jun 2005 15:55:43 -0000	1.25
+++ animation.h	19 Jul 2005 19:05:41 -0000	1.26
@@ -33,7 +33,6 @@
 #define MAX_ANIMATIONS 7
 #define DEFAULT_FRAME_TIME 140
 
-#define SAGA_FRAME_HEADER_LEN (_vm->getFeatures() & GF_MAC_RESOURCES ? 13 : 12)
 
 #define SAGA_FRAME_START 0xF
 #define SAGA_FRAME_END 0x3F
@@ -146,6 +145,10 @@
 		}
 	}
 
+	int getFrameHeaderLength() const {
+		return (_vm->getFeatures() & GF_MAC_RESOURCES ? 13 : 12);
+	}
+
 	AnimationData* getAnimation(uint16 animId) {
 		validateAnimationId(animId);
 		return _animations[animId];

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/console.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- console.cpp	8 Jan 2005 20:30:06 -0000	1.27
+++ console.cpp	19 Jul 2005 19:05:41 -0000	1.28
@@ -66,18 +66,8 @@
 
 	// Scene commands
 	DCmd_Register("scene_change", &Console::cmdSceneChange);
-	DCmd_Register("scene_info", &Console::cmdSceneInfo);
 	DCmd_Register("action_map_info", &Console::cmdActionMapInfo);
 	DCmd_Register("object_map_info", &Console::cmdObjectMapInfo);
-	// CVAR_Register_I(&_sceneNumber, "scene", NULL, CVAR_READONLY, 0, 0);
-
-	// Script commands
-	DCmd_Register("script_info", &Console::Cmd_ScriptInfo);
-	DCmd_Register("script_exec", &Console::Cmd_ScriptExec);
-	DCmd_Register("script_togglestep", &Console::Cmd_ScriptToggleStep);
-//	CVAR_RegisterFunc(CF_script_info, "script_info", NULL, CVAR_NONE, 0, 0, this);
-//	CVAR_RegisterFunc(CF_script_exec, "script_exec", "<Script number>", CVAR_NONE, 1, 1, this);
-//	CVAR_RegisterFunc(CF_script_togglestep, "script_togglestep", NULL, CVAR_NONE, 0, 0, this);
 }
 
 Console::~Console() {
@@ -154,11 +144,6 @@
 	return true;
 }
 
-bool Console::cmdSceneInfo(int argc, const char **argv) {
-	_vm->_scene->cmdSceneInfo();
-	return true;
-}
-
 bool Console::cmdActionMapInfo(int argc, const char **argv) {
 	_vm->_scene->cmdActionMapInfo();
 	return true;
@@ -169,22 +154,4 @@
 	return true;
 }
 
-bool Console::Cmd_ScriptInfo(int argc, const char **argv) {
-	_vm->_script->scriptInfo();
-	return true;
-}
-
-bool Console::Cmd_ScriptExec(int argc, const char **argv) {
-	if (argc != 2)
-		DebugPrintf("Usage: %s <Script number>\n", argv[0]);
-	else
-		_vm->_script->scriptExec(argc, argv);
-	return true;
-}
-
-bool Console::Cmd_ScriptToggleStep(int argc, const char **argv) {
-	_vm->_script->CF_script_togglestep();
-	return true;
-}
-
 } // End of namespace Saga

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/console.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- console.h	6 Jul 2005 20:46:10 -0000	1.14
+++ console.h	19 Jul 2005 19:05:42 -0000	1.15
@@ -48,13 +48,9 @@
 	bool Cmd_AnimInfo(int argc, const char **argv);
 
 	bool cmdSceneChange(int argc, const char **argv);
-	bool cmdSceneInfo(int argc, const char **argv);
 	bool cmdActionMapInfo(int argc, const char **argv);
 	bool cmdObjectMapInfo(int argc, const char **argv);
-
-	bool Cmd_ScriptInfo(int argc, const char **argv);
-	bool Cmd_ScriptExec(int argc, const char **argv);
-	bool Cmd_ScriptToggleStep(int argc, const char **argv);
+	
 
 private:
 	SagaEngine *_vm;

Index: events.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/events.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- events.cpp	14 Jul 2005 17:46:19 -0000	1.60
+++ events.cpp	19 Jul 2005 19:05:42 -0000	1.61
@@ -278,7 +278,7 @@
 	case TEXT_EVENT:
 		switch (event->op) {
 		case EVENT_DISPLAY:
-			((TextListEntry *)event->data)->display = 1;
+			((TextListEntry *)event->data)->display = true;
 			break;
 		case EVENT_REMOVE:
 			_vm->_scene->_textList.remove((TextListEntry *)event->data);
@@ -299,7 +299,7 @@
 	case MUSIC_EVENT:
 		_vm->_music->stop();
 		if (event->op == EVENT_PLAY)
-			_vm->_music->play(event->param, event->param2);
+			_vm->_music->play(event->param, (MusicFlags)event->param2);
 		break;
 	case BG_EVENT:
 		{
@@ -332,9 +332,9 @@
 				}
 
 				if (event->param == SET_PALETTE) {
-					PalEntry *pal_p;
-					_vm->_scene->getBGPal(&pal_p);
-					_vm->_gfx->setPalette(pal_p);
+					PalEntry *palPointer;
+					_vm->_scene->getBGPal(palPointer);
+					_vm->_gfx->setPalette(palPointer);
 				}
 			}
 		}

Index: font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/font.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- font.cpp	14 Jul 2005 17:46:19 -0000	1.31
+++ font.cpp	19 Jul 2005 19:05:42 -0000	1.32
@@ -24,8 +24,7 @@
 // Font management and font drawing module
 #include "saga/saga.h"
 #include "saga/gfx.h"
-
-#include "saga/rscfile_mod.h"
+#include "saga/rscfile.h"
 
 #include "saga/font.h"
 #include "saga/stream.h"
@@ -69,26 +68,24 @@
 	size_t fontResourceLength;
 	int numBits;
 	int c;
-	RSCFILE_CONTEXT *fontContext;
+	ResourceContext *fontContext;
 
 
 	debug(1, "Font::loadFont(): Reading fontResourceId %d...", fontResourceId);
 
-	fontContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
+	fontContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
 	if (fontContext == NULL) {
-		error("Font::Font(): Couldn't get resource context.");
+		error("Font::Font() resource context not found");
 	}
 
 	// Load font resource
-	if (RSC_LoadResource(fontContext, fontResourceId, &fontResourcePointer, &fontResourceLength) != SUCCESS) {
-		error("Font::loadFont(): Couldn't load font resource.");
-	}
+	_vm->_resource->loadResource(fontContext, fontResourceId, fontResourcePointer, fontResourceLength);
 
 	if (fontResourceLength < FONT_DESCSIZE) {
-		error("Font::loadFont(): Invalid font length (%d < %d)", fontResourceLength, FONT_DESCSIZE);
+		error("Font::loadFont() Invalid font length (%i < %i)", fontResourceLength, FONT_DESCSIZE);
 	}
 
-	MemoryReadStreamEndian readS(fontResourcePointer, fontResourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(fontResourcePointer, fontResourceLength, fontContext->isBigEndian);
 
 	// Create new font structure
 	font = (FontData *)malloc(sizeof(*font));
@@ -127,7 +124,7 @@
 	font->normal.font = (byte*)malloc(fontResourceLength - FONT_DESCSIZE);
 	memcpy(font->normal.font, fontResourcePointer + FONT_DESCSIZE, fontResourceLength - FONT_DESCSIZE);
 
-	RSC_FreeResource(fontResourcePointer);
+	free(fontResourcePointer);
 
 
 	// Create outline font style
@@ -437,12 +434,13 @@
 		fitWidth = ((ds->w - TEXT_MARGIN) - textPoint.x) * 2;
 	}
 
-	if (fitWidth >= textWidth) {
-		// Entire string fits, draw it
-		textPoint.x = textPoint.x - (textWidth / 2);
-		draw(fontId, ds, text, textLength, textPoint, color, effectColor, flags);
+	if (fitWidth < textWidth) {
+		warning("text too long to be displayed in one line");
 		return;
 	}
+	// Entire string fits, draw it
+	textPoint.x = textPoint.x - (textWidth / 2);
+	draw(fontId, ds, text, textLength, textPoint, color, effectColor, flags);
 }
 
 int Font::getHeight(FontId fontId, const char *text, int width, FontEffectFlags flags) {

Index: font.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/font.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- font.h	14 Jul 2005 17:46:19 -0000	1.14
+++ font.h	19 Jul 2005 19:05:42 -0000	1.15
@@ -54,9 +54,10 @@
 #define TEXT_LINESPACING 2
 
 struct TextListEntry {
-	int display;
-//	int id;
+	bool display;
+	bool useRect;
 	Common::Point point;
+	Common::Rect rect;
 	int color;
 	int effectColor;
 	FontEffectFlags flags;

Index: game.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/game.cpp,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- game.cpp	16 Jul 2005 21:46:32 -0000	1.76
+++ game.cpp	19 Jul 2005 19:05:43 -0000	1.77
@@ -32,9 +32,10 @@
 #include "base/gameDetector.h"
 #include "backends/fs/fs.h"
 
-#include "saga/rscfile_mod.h"
+#include "saga/rscfile.h"
 #include "saga/interface.h"
 #include "saga/scene.h"
+#include "saga/resnames.h"
 
 namespace Saga {
 
@@ -202,11 +203,6 @@
 	GAME_SOUND_VOC, 0, 0, 0
 };
 
-static GameFontDescription ITEMACDEMO_GameFonts[] = {
-	{2},
-	{0}
-}; 
-
 // Inherit the Earth - Wyrmkeep Win32 Demo version
 static GameFileDescription ITEWINDEMO_GameFiles[] = {
 	{"ited.rsc", GAME_RESOURCEFILE},
@@ -215,6 +211,11 @@
 	{"voicesd.rsc", GAME_VOICEFILE}
 };
 
+static GameFontDescription ITEWINDEMO_GameFonts[] = {
+	{2},
+	{0}
+}; 
+
 // Inherit the Earth - Wyrmkeep Linux Demo version
 static GameFileDescription ITELINDEMO_GameFiles[] = {
 	{"ited.rsc", GAME_RESOURCEFILE},
@@ -247,11 +248,6 @@
 	{"music.rsc", GAME_MUSICFILE}
 };
 
-static GameFontDescription ITEWINDEMO_GameFonts[] = {
-	{2},
-	{0}
-}; 
-
 // Inherit the Earth - Mac Wyrmkeep version
 static GameFileDescription ITEMACCD_GameFiles[] = {
 	{"ite.rsc", GAME_RESOURCEFILE},
@@ -274,7 +270,7 @@
 	{1}
 };
 
-static GameSoundInfo ITE_GameSound = {
+static GameSoundInfo ITEDISK_GameSound = {
 	GAME_SOUND_VOC, 0, 0, 0
 };
 
@@ -296,7 +292,79 @@
 	GAME_SOUND_PCM,
 	22050,
 	16,
-	0
+	false
+};
+
+static GamePatchDescription ITEWinPatch1_Files[] = {
+	{ "cave.mid", GAME_RESOURCEFILE, 9},
+	{ "intro.mid", GAME_RESOURCEFILE, 10},
+	{ "fvillage.mid", GAME_RESOURCEFILE, 11},
+	{ "elkhall.mid", GAME_RESOURCEFILE, 12},
+	{ "mouse.mid", GAME_RESOURCEFILE, 13},
+	{ "darkclaw.mid", GAME_RESOURCEFILE, 14},
+	{ "birdchrp.mid", GAME_RESOURCEFILE, 15},
+	{ "orbtempl.mid", GAME_RESOURCEFILE, 16},
+	{ "spooky.mid", GAME_RESOURCEFILE, 17},
+	{ "catfest.mid", GAME_RESOURCEFILE, 18},
+	{ "elkfanfare.mid", GAME_RESOURCEFILE, 19},
+	{ "bcexpl.mid", GAME_RESOURCEFILE, 20},
+	{ "boargtnt.mid", GAME_RESOURCEFILE, 21},
+	{ "boarking.mid", GAME_RESOURCEFILE, 22},
+	{ "explorea.mid", GAME_RESOURCEFILE, 23},
+	{ "exploreb.mid", GAME_RESOURCEFILE, 24},
+	{ "explorec.mid", GAME_RESOURCEFILE, 25},
+	{ "sunstatm.mid", GAME_RESOURCEFILE, 26},
+	{ "nitstrlm.mid", GAME_RESOURCEFILE, 27},
+	{ "humruinm.mid", GAME_RESOURCEFILE, 28},
+	{ "damexplm.mid", GAME_RESOURCEFILE, 29},
+	{ "tychom.mid", GAME_RESOURCEFILE, 30},
+	{ "kitten.mid", GAME_RESOURCEFILE, 31},
+	{ "sweet.mid", GAME_RESOURCEFILE, 32},
+	{ "brutalmt.mid", GAME_RESOURCEFILE, 33},
+	{ "shiala.mid", GAME_RESOURCEFILE, 34},
+
+	{ "wyrm.pak", GAME_RESOURCEFILE, 1529},
+	{ "wyrm1.dlt", GAME_RESOURCEFILE, 1530},
+	{ "wyrm2.dlt", GAME_RESOURCEFILE, 1531},
+	{ "wyrm3.dlt", GAME_RESOURCEFILE, 1532},
+	{ "wyrm4.dlt", GAME_RESOURCEFILE, 1533},
+	{ "credit3n.dlt", GAME_RESOURCEFILE, 1796},
+	{ "credit4n.dlt", GAME_RESOURCEFILE, 1797},
+	{ "p2_a.voc", GAME_VOICEFILE, 4},
+};
+
+static GamePatchDescription ITEWinPatch2_Files[] = {
+	{ "cave.mid", GAME_RESOURCEFILE, 9},
+	{ "intro.mid", GAME_RESOURCEFILE, 10},
+	{ "fvillage.mid", GAME_RESOURCEFILE, 11},
+	{ "elkfanfare.mid", GAME_RESOURCEFILE, 19},
+	{ "bcexpl.mid", GAME_RESOURCEFILE, 20},
+	{ "boargtnt.mid", GAME_RESOURCEFILE, 21},
+	{ "explorea.mid", GAME_RESOURCEFILE, 23},
+	{ "sweet.mid", GAME_RESOURCEFILE, 32},
+
+	{ "wyrm.pak", GAME_RESOURCEFILE, 1529},
+	{ "wyrm1.dlt", GAME_RESOURCEFILE, 1530},
+	{ "wyrm2.dlt", GAME_RESOURCEFILE, 1531},
+	{ "wyrm3.dlt", GAME_RESOURCEFILE, 1532},
+	{ "p2_a.iaf", GAME_VOICEFILE, 4}
+/*	boarhall.bbm
+	elkenter.bbm
+	ferrets.bbm
+	ratdoor.bbm
+	sanctuar.bbm
+	tycho.bbm*/
+};
+
+static GamePatchDescription ITEMacPatch_Files[] = {
+	{ "wyrm.pak", GAME_RESOURCEFILE, 1529},
+	{ "wyrm1.dlt", GAME_RESOURCEFILE, 1530},
+	{ "wyrm2.dlt", GAME_RESOURCEFILE, 1531},
+	{ "wyrm3.dlt", GAME_RESOURCEFILE, 1532},
+	{ "wyrm4.dlt", GAME_RESOURCEFILE, 1533},
+	{ "credit3m.dlt", GAME_RESOURCEFILE, 1796},
+	{ "credit4m.dlt", GAME_RESOURCEFILE, 1797},
+	{ "p2_a.iaf", GAME_VOICEFILE, 4}
 };
 
 // IHNM section
@@ -588,6 +656,8 @@
 		ARRAYSIZE(ITEDEMO_GameFonts),
 		ITEDEMO_GameFonts,
 		&ITEDEMO_GameSound,
+		0,
+		NULL,
 		0, // features
 	},
 
@@ -602,9 +672,11 @@
 		&ITE_Resources,
 		ARRAYSIZE(ITEWINDEMO_GameFiles),
 		ITEWINDEMO_GameFiles,
-		ARRAYSIZE(ITEMACDEMO_GameFonts),
-		ITEMACDEMO_GameFonts,
+		ARRAYSIZE(ITEWINDEMO_GameFonts),
+		ITEWINDEMO_GameFonts,
 		&ITECD_GameSound,
+		ARRAYSIZE(ITEMacPatch_Files),
+		ITEMacPatch_Files,
 		GF_VOX_VOICES | GF_BIG_ENDIAN_DATA | GF_MAC_RESOURCES | GF_WYRMKEEP | GF_CD_FX
 	},
 
@@ -619,9 +691,11 @@
 		&ITE_Resources,
 		ARRAYSIZE(ITEWINDEMO_GameFiles),
 		ITEWINDEMO_GameFiles,
-		ARRAYSIZE(ITEMACDEMO_GameFonts),
-		ITEMACDEMO_GameFonts,
+		ARRAYSIZE(ITEWINDEMO_GameFonts),
+		ITEWINDEMO_GameFonts,
 		&ITECD_GameSound,
+		ARRAYSIZE(ITEMacPatch_Files),
+		ITEMacPatch_Files,
 		GF_VOX_VOICES | GF_BIG_ENDIAN_DATA | GF_MAC_RESOURCES | GF_WYRMKEEP | GF_CD_FX
 	},
 
@@ -636,9 +710,11 @@
 		&ITE_Resources,
 		ARRAYSIZE(ITEMACCD_GameFiles),
 		ITEMACCD_GameFiles,
-		ARRAYSIZE(ITEMACDEMO_GameFonts),
-		ITEMACDEMO_GameFonts,
+		ARRAYSIZE(ITEWINDEMO_GameFonts),
+		ITEWINDEMO_GameFonts,
 		&ITECD_GameSound,
+		ARRAYSIZE(ITEMacPatch_Files),
+		ITEMacPatch_Files,
 		GF_BIG_ENDIAN_DATA | GF_MAC_RESOURCES | GF_WYRMKEEP | GF_CD_FX
 	},
 
@@ -657,6 +733,8 @@
 		ARRAYSIZE(ITECD_GameFonts),
 		ITECD_GameFonts,
 		&ITECD_GameSound,
+		0,
+		NULL,
 		GF_VOX_VOICES | GF_WYRMKEEP | GF_CD_FX
 	},
 	
@@ -674,6 +752,8 @@
 		ARRAYSIZE(ITEWINDEMO_GameFonts),
 		ITEWINDEMO_GameFonts,
 		&ITECD_GameSound,
+		ARRAYSIZE(ITEWinPatch2_Files),
+		ITEWinPatch2_Files,
 		GF_VOX_VOICES | GF_WYRMKEEP | GF_CD_FX
 	},
 	
@@ -691,6 +771,8 @@
 		ARRAYSIZE(ITEWINDEMO_GameFonts),
 		ITEWINDEMO_GameFonts,
 		&ITECD_GameSound,
+		ARRAYSIZE(ITEWinPatch1_Files),
+		ITEWinPatch1_Files,
 		GF_VOX_VOICES | GF_WYRMKEEP | GF_CD_FX
 	},
 
@@ -708,6 +790,8 @@
 		ARRAYSIZE(ITECD_GameFonts),
 		ITECD_GameFonts,
 		&ITECD_GameSound,
+		0,
+		NULL,
 		GF_WYRMKEEP | GF_BIG_ENDIAN_VOICES | GF_CD_FX
 	},
 	
@@ -726,6 +810,8 @@
 		ARRAYSIZE(ITECD_GameFonts),
 		ITECD_GameFonts,
 		&ITECD_GameSound,
+		0,
+		NULL,
 		GF_WYRMKEEP | GF_CD_FX
 	},
 
@@ -743,6 +829,8 @@
 		ARRAYSIZE(ITECD_GameFonts),
 		ITECD_GameFonts,
 		&ITECD_GameSound,
+		0,
+		NULL,
 		GF_CD_FX
 	},
 
@@ -760,6 +848,8 @@
 		ARRAYSIZE(ITECD_GameFonts),
 		ITECD_GameFonts,
 		&ITECD_GameSound,
+		0,
+		NULL,
 		GF_LANG_DE | GF_CD_FX
 	},
 
@@ -777,6 +867,8 @@
 		ARRAYSIZE(ITECD_GameFonts),
 		ITECD_GameFonts,
 		&ITECD_GameSound,
+		0,
+		NULL,
 		GF_CD_FX
 	},
 
@@ -793,7 +885,9 @@
 		ITEDISK_GameFiles,
 		ARRAYSIZE(ITEDISK_GameFonts),
 		ITEDISK_GameFonts,
-		&ITE_GameSound,
+		&ITEDISK_GameSound,
+		0,
+		NULL,
 		GF_LANG_DE
 	},
 
@@ -810,7 +904,9 @@
 		ITEDISK_GameFiles,
 		ARRAYSIZE(ITEDISK_GameFonts),
 		ITEDISK_GameFonts,
-		&ITE_GameSound,
+		&ITEDISK_GameSound,
+		0,
+		NULL,
 		0
 	},
 
@@ -828,6 +924,8 @@
 		ARRAYSIZE(IHNMCD_GameFonts),
 		IHNMCD_GameFonts,
 		&IHNM_GameSound,
+		0,
+		NULL,
 		GF_DEFAULT_TO_1X_SCALER
 	},
 
@@ -845,6 +943,8 @@
 		ARRAYSIZE(IHNMCD_GameFonts),
 		IHNMCD_GameFonts,
 		&IHNM_GameSound,
+		0,
+		NULL,
 		GF_DEFAULT_TO_1X_SCALER
 	},
 
@@ -862,56 +962,39 @@
 		ARRAYSIZE(IHNMCD_GameFonts),
 		IHNMCD_GameFonts,
 		&IHNM_GameSound,
+		0,
+		NULL,
 		GF_DEFAULT_TO_1X_SCALER
 	}
 };
 
-int SagaEngine::initGame(void) {
+bool SagaEngine::initGame(void) {
+	uint16 gameCount = ARRAYSIZE(gameDescriptions);
 	int gameNumber;
 	FSList dummy;
 
 	if ((gameNumber = detectGame(dummy)) == -1) {
 		warning("No valid games were found in the specified directory.");
-		return FAILURE;
-	}
-
-	if (loadGame(gameNumber) != SUCCESS) {
-		warning("Error loading game resource files.");
-		return FAILURE;
+		return false;
 	}
 
-	return SUCCESS;
-}
 
-RSCFILE_CONTEXT *SagaEngine::getFileContext(uint16 type, int param) {
-	uint16 i;
 
-	for (i = 0; i < _gameDescription->filesCount; i++) {
-		if (_gameDescription->filesDescriptions[i].fileType & type) {
-			return _gameFileContexts[i];
-		}
+	if (gameNumber >= gameCount) {
+		error("SagaEngine::loadGame wrong gameNumber");
 	}
 
-	return NULL;
-}
-
-bool SagaEngine::isBigEndianFile(const char *filename) {
-	bool isBigEndian = IS_BIG_ENDIAN;
-
-	if (isBigEndian)
-		return true;
+	_gameNumber = gameNumber;
+	_gameDescription = &gameDescriptions[gameNumber];
+	_gameDisplayInfo = *_gameDescription->gameDisplayInfo;
+	_displayClip.right = _gameDisplayInfo.logicalWidth; 
+	_displayClip.bottom = _gameDisplayInfo.logicalHeight; 
 
-	if (!(_vm->getFeatures() & GF_BIG_ENDIAN_VOICES))
-		return isBigEndian;
 
-	for (int i = 0; i < _gameDescription->filesCount; i++) {
-		GameFileDescription *desc = &_gameDescription->filesDescriptions[i];
-		if (desc->fileType & GAME_VOICEFILE && scumm_stricmp(filename, desc->fileName) == 0) {
-			return true;
-		}
+	if (!_resource->createContexts()) {
+		return false;
 	}
-
-	return isBigEndian;
+	return true;
 }
 
 DetectedGameList GAME_ProbeGame(const FSList &fslist) {
@@ -1044,45 +1127,4 @@
 	return -1;
 }
 
-int SagaEngine::loadGame(int gameNumber) {
-	RSCFILE_CONTEXT *loadContext;
-	uint16 gameCount = ARRAYSIZE(gameDescriptions);
-	const char *gameFileName;
-	uint16 gameFileCount;
-	uint16 i;
-
-	if (gameNumber >= gameCount) {
-		error("SagaEngine::loadGame wrong gameNumber");
-	}
-
-	_gameNumber = gameNumber;
-	_gameDescription = &gameDescriptions[gameNumber];
-	_gameDisplayInfo = *_gameDescription->gameDisplayInfo;
-	_displayClip.right = _gameDisplayInfo.logicalWidth; 
-	_displayClip.bottom = _gameDisplayInfo.logicalHeight; 
-
-	gameFileCount = _gameDescription->filesCount;
-	
-	_gameFileContexts = (RSCFILE_CONTEXT **)realloc(_gameFileContexts, gameFileCount * sizeof(*_gameFileContexts));
-	//TODO: on exit - FREE!
-	if (_gameFileContexts == NULL) {
-		memoryError("SagaEngine::loadGame");
-	}
-
-
-	// Load game resource files
-	for (i = 0; i < gameFileCount; i++) {
-		loadContext = RSC_CreateContext();
-		gameFileName = _gameDescription->filesDescriptions[i].fileName;
-		if (RSC_OpenContext(loadContext, gameFileName) != SUCCESS) {
-			return FAILURE;
-		}
-
-		debug(3, "Opened resource file: %s", gameFileName);
-		_gameFileContexts[i] = loadContext;
-	}
-	
-	return SUCCESS;
-}
-
 } // End of namespace Saga

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/gfx.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- gfx.cpp	9 Jul 2005 17:11:41 -0000	1.54
+++ gfx.cpp	19 Jul 2005 19:05:43 -0000	1.55
@@ -31,7 +31,7 @@
 
 namespace Saga {
 
-Gfx::Gfx(OSystem *system, int width, int height, GameDetector &detector) : _system(system) {
+Gfx::Gfx(SagaEngine *vm, OSystem *system, int width, int height, GameDetector &detector) : _vm(vm), _system(system) {
 	_system->beginGFXTransaction();
 		_vm->initCommonGFX(detector);
 		_system->initSize(width, height);

Index: gfx.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/gfx.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- gfx.h	10 Jul 2005 15:23:36 -0000	1.34
+++ gfx.h	19 Jul 2005 19:05:43 -0000	1.35
@@ -123,11 +123,12 @@
 #define CURSOR_ORIGIN_Y 4
 
 bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point);
+class SagaEngine;
 
 class Gfx {
 public:
 
-	Gfx(OSystem *system, int width, int height, GameDetector &detector);
+	Gfx(SagaEngine *vm, OSystem *system, int width, int height, GameDetector &detector);
 	~Gfx();
 	Surface *getBackBuffer() {
 		return &_backBuffer;
@@ -146,6 +147,7 @@
 	Surface _backBuffer;
 	byte _currentPal[PAL_ENTRIES * 4];
 	OSystem *_system;
+	SagaEngine *_vm;
 };
 
 } // End of namespace Saga

Index: ihnm_introproc.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/ihnm_introproc.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- ihnm_introproc.cpp	9 Jul 2005 16:23:44 -0000	1.44
+++ ihnm_introproc.cpp	19 Jul 2005 19:05:44 -0000	1.45
@@ -28,7 +28,6 @@
 
 #include "saga/animation.h"
 #include "saga/events.h"
-#include "saga/rscfile_mod.h"
 #include "saga/sndres.h"
 #include "saga/music.h"
 
@@ -36,9 +35,9 @@
 
 namespace Saga {
 
-SCENE_RESLIST IHNM_IntroMovie1RL[] = {
-	{30, SAGA_BG_IMAGE, 0, 0} ,
-	{31, SAGA_ANIM_1, 0, 0}
+SceneResourceData IHNM_IntroMovie1RL[] = {
+	{30, SAGA_BG_IMAGE, 0, 0, false} ,
+	{31, SAGA_ANIM_1, 0, 0, false}
 };
 
 SceneDescription IHNM_IntroMovie1Desc = {
@@ -47,9 +46,9 @@
 	ARRAYSIZE(IHNM_IntroMovie1RL)
 };
 
-SCENE_RESLIST IHNM_IntroMovie2RL[] = {
-	{32, SAGA_BG_IMAGE, 0, 0} ,
-	{33, SAGA_ANIM_1, 0, 0}
+SceneResourceData IHNM_IntroMovie2RL[] = {
+	{32, SAGA_BG_IMAGE, 0, 0, false} ,
+	{33, SAGA_ANIM_1, 0, 0, false}
 };
 
 SceneDescription IHNM_IntroMovie2Desc = {
@@ -58,9 +57,9 @@
 	ARRAYSIZE(IHNM_IntroMovie2RL)
 };
 
-SCENE_RESLIST IHNM_IntroMovie3RL[] = {
-	{34, SAGA_BG_IMAGE, 0, 0},
-	{35, SAGA_ANIM_1, 0, 0}
+SceneResourceData IHNM_IntroMovie3RL[] = {
+	{34, SAGA_BG_IMAGE, 0, 0, false},
+	{35, SAGA_ANIM_1, 0, 0, false}
 };
 
 SceneDescription IHNM_IntroMovie3Desc = {
@@ -69,9 +68,9 @@
 	ARRAYSIZE(IHNM_IntroMovie3RL)
 };
 
-SCENE_RESLIST IHNM_IntroMovie4RL[] = {
-	{1227, SAGA_BG_IMAGE, 0, 0},
-	{1226, SAGA_ANIM_1, 0, 0}
+SceneResourceData IHNM_IntroMovie4RL[] = {
+	{1227, SAGA_BG_IMAGE, 0, 0, false},
+	{1226, SAGA_ANIM_1, 0, 0, false}
 };
 
 SceneDescription IHNM_IntroMovie4Desc = {
@@ -207,7 +206,7 @@
 		q_event = _vm->_events->chain(q_event, &event);
 
 		// Fade in from black to the scene background palette
-		_vm->_scene->getBGPal(&pal);
+		_vm->_scene->getBGPal(pal);
 
 		event.type = CONTINUOUS_EVENT;
 		event.code = PAL_EVENT;
@@ -275,7 +274,7 @@
 		event.type = ONESHOT_EVENT;
 		event.code = MUSIC_EVENT;
 		event.param = 1;
-		event.param2 = 0;
+		event.param2 = MUSIC_NORMAL;
 		event.op = EVENT_PLAY;
 		event.time = 0;
 
@@ -292,7 +291,7 @@
 		q_event = _vm->_events->chain(q_event, &event);
 
 		// Fade in from black to the scene background palette
-		_vm->_scene->getBGPal(&pal);
+		_vm->_scene->getBGPal(pal);
 
 		event.type = CONTINUOUS_EVENT;
 		event.code = PAL_EVENT;

Index: image.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/image.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- image.cpp	14 Jul 2005 17:46:19 -0000	1.23
+++ image.cpp	19 Jul 2005 19:05:44 -0000	1.24
@@ -58,11 +58,10 @@
 	size_t out_buf_len;
 
 	if (image_size <= SAGA_IMAGE_DATA_OFFSET) {
-		/* Image size is way too small */
-		return FAILURE;
+		error("decodeBGImage() Image size is way too small");
 	}
 
-	MemoryReadStreamEndian readS(image_data, image_size, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(image_data, image_size, isBigEndian());
 
 	hdr.width = readS.readUint16();
 	hdr.height = readS.readUint16();
@@ -91,7 +90,7 @@
 	unbankBGImage(out_buf, decode_buf, hdr.width, hdr.height);
 
 	// For some reason bg images in IHNM are upside down
-	if (_vm->getGameType() == GType_IHNM) {
+	if (getGameType() == GType_IHNM) {
 		flipImage(out_buf, hdr.width, hdr.height);
 	}
 

Index: input.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/input.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- input.cpp	19 Jun 2005 23:41:39 -0000	1.48
+++ input.cpp	19 Jul 2005 19:05:44 -0000	1.49
@@ -76,7 +76,7 @@
 				break;*/
 			case 282: // F1
 				_render->toggleFlag(RF_SHOW_FPS);
-				_vm->_actor->_handleActionDiv = (_vm->_actor->_handleActionDiv == 15) ? 50 : 15;
+				_actor->_handleActionDiv = (_actor->_handleActionDiv == 15) ? 50 : 15;
 				break;
 			case 283: // F2
 				_render->toggleFlag(RF_PALETTE_TEST);
@@ -94,9 +94,6 @@
 				break;
 			case 289: // F8
 				break;
-			case 9: // Tab
-				_script->SThreadDebugStep();
-				break;
 
 			// Actual game keys
 			case 32: // space
@@ -140,7 +137,7 @@
 			_mousePos = event.mouse;
 			break;
 		case OSystem::EVENT_QUIT:
-			_vm->shutDown();
+			shutDown();
 			break;
 		default:
 			break;

Index: interface.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.cpp,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -d -r1.119 -r1.120
--- interface.cpp	18 Jul 2005 14:37:55 -0000	1.119
+++ interface.cpp	19 Jul 2005 19:05:44 -0000	1.120
@@ -33,10 +33,11 @@
 #include "saga/itedata.h"
 #include "saga/puzzle.h"
 #include "saga/render.h"
-#include "saga/rscfile_mod.h"
 #include "saga/scene.h"
 #include "saga/script.h"
 #include "saga/sprite.h"
+#include "saga/rscfile.h"
+#include "saga/resnames.h"
 
 #include "saga/interface.h"
 
@@ -63,21 +64,16 @@
 	-1
 };
 
-Interface::Interface(SagaEngine *vm) : _vm(vm), _initialized(false) {
+Interface::Interface(SagaEngine *vm) : _vm(vm) {
 	byte *resource;
 	size_t resourceLength;
-	int result;
 	int i;
-
-	if (_initialized) {
-		return;
-	}
 	
 
 	// Load interface module resource file context
-	_interfaceContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
+	_interfaceContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
 	if (_interfaceContext == NULL) {
-		error("Interface::Interface(): unable to load resource");
+		error("Interface::Interface() resource context not found");
 	}
 	
 	_mainPanel.buttons = _vm->getDisplayInfo().mainPanelButtons;
@@ -93,46 +89,33 @@
 		}
 	}
 
-	result = RSC_LoadResource(_interfaceContext, _vm->getResourceDescription()->mainPanelResourceId, &resource, &resourceLength);
-	if ((result != SUCCESS) || (resourceLength == 0)) {
-		error("Interface::Interface(): unable to load mainPanel resource");
-	}
+	_vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->mainPanelResourceId, resource, resourceLength);
 	_vm->decodeBGImage(resource, resourceLength, &_mainPanel.image,
 		&_mainPanel.imageLength, &_mainPanel.imageWidth, &_mainPanel.imageHeight);
 	
-	RSC_FreeResource(resource);
+	free(resource);
 
 	_conversePanel.buttons = _vm->getDisplayInfo().conversePanelButtons;
 	_conversePanel.buttonsCount = _vm->getDisplayInfo().conversePanelButtonsCount;
 
-	result = RSC_LoadResource(_interfaceContext, _vm->getResourceDescription()->conversePanelResourceId, &resource, &resourceLength);
-	if ((result != SUCCESS) || (resourceLength == 0)) {
-		error("Interface::Interface unable to load conversePanel resource");
-	}
+	_vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->conversePanelResourceId, resource, resourceLength);
 	_vm->decodeBGImage(resource, resourceLength, &_conversePanel.image,
 		&_conversePanel.imageLength, &_conversePanel.imageWidth, &_conversePanel.imageHeight);
-	RSC_FreeResource(resource);
+	free(resource);
 
 	_optionPanel.buttons = _vm->getDisplayInfo().optionPanelButtons;
 	_optionPanel.buttonsCount = _vm->getDisplayInfo().optionPanelButtonsCount;
 
-	result = RSC_LoadResource(_interfaceContext, _vm->getResourceDescription()->optionPanelResourceId, &resource, &resourceLength);
-	if ((result != SUCCESS) || (resourceLength == 0)) {
-		error("Interface::Interface unable to load optionPanel resource");
-	}
+	_vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->optionPanelResourceId, resource, resourceLength);
 	_vm->decodeBGImage(resource, resourceLength, &_optionPanel.image,
 		&_optionPanel.imageLength, &_optionPanel.imageWidth, &_optionPanel.imageHeight);
-	RSC_FreeResource(resource);
+	free(resource);
 
 
-	if (_vm->_sprite->loadList(_vm->getResourceDescription()->mainPanelSpritesResourceId, _mainPanel.sprites) != SUCCESS) {
-		error("Interface::Interface(): Unable to load sprite list");
-	}
+	_vm->_sprite->loadList(_vm->getResourceDescription()->mainPanelSpritesResourceId, _mainPanel.sprites);
 
 	if (_vm->getGameType() == GType_ITE) {
-		if (_vm->_sprite->loadList(_vm->getResourceDescription()->defaultPortraitsResourceId, _defPortraits) != SUCCESS) {
-			error("Interface::Interface(): Unable to load sprite list");
-		}
+		_vm->_sprite->loadList(_vm->getResourceDescription()->defaultPortraitsResourceId, _defPortraits);
 	} else {
 		// TODO
 	}
@@ -212,8 +195,6 @@
 	_textInput = false;
 	_statusTextInput = false;
 	_statusTextInputState = kStatusTextInputFirstRun;
-
-	_initialized = true;
 }
 
 Interface::~Interface(void) {
@@ -222,7 +203,6 @@
 	_mainPanel.sprites.freeMem();
 	_defPortraits.freeMem();
 	_scenePortraits.freeMem();
-	_initialized = false;
 }
 
 int Interface::activate() {
@@ -505,10 +485,10 @@
 	drawStatusBar();	
 }
 
-int Interface::loadScenePortraits(int resourceId) {
+void Interface::loadScenePortraits(int resourceId) {
 	_scenePortraits.freeMem();
 
-	return _vm->_sprite->loadList(resourceId, _scenePortraits);
+	_vm->_sprite->loadList(resourceId, _scenePortraits);
 }
 
 void Interface::drawVerbPanel(Surface *backBuffer, PanelButton* panelButton) {
@@ -2037,7 +2017,6 @@
 	Rect rect;
 	byte *image;
 	int imageWidth, imageHeight;
-	int result;
 	const byte *pal;
 	PalEntry cPal[PAL_ENTRIES];
 
@@ -2047,9 +2026,9 @@
 
 	rect.left = rect.top = 0;
 
-	result = RSC_LoadResource(_interfaceContext, RID_ITE_TYCHO_MAP, &resource, &resourceLength);
-	if ((result != SUCCESS) || (resourceLength == 0)) {
-		error("Interface::mapPanelShow(): unable to load Tycho map resource");
+	_vm->_resource->loadResource(_interfaceContext, RID_ITE_TYCHO_MAP, resource, resourceLength);
+	if (resourceLength == 0) {
+		error("Interface::mapPanelShow() unable to load Tycho map resource");
 	}
 
 	_vm->_gfx->getCurrentPal(_mapSavedPal);
@@ -2083,7 +2062,7 @@
 		_vm->_system->delayMillis(5);
 	}
 
-	RSC_FreeResource(resource);
+	free(resource);
 	free(image);
 
 	setSaveReminderState(false);

Index: interface.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- interface.h	12 Jul 2005 18:31:48 -0000	1.64
+++ interface.h	19 Jul 2005 19:05:45 -0000	1.65
@@ -209,7 +209,7 @@
 	void restoreMode();
 	bool isInMainMode() { return _inMainMode; }
 	void setStatusText(const char *text, int statusColor = -1);
-	int loadScenePortraits(int resourceId);
+	void loadScenePortraits(int resourceId);
 	void setLeftPortrait(int portrait) {
 		_leftPortrait = portrait;
 		draw();
@@ -376,8 +376,7 @@
 private:
 	SagaEngine *_vm;
 
-	bool _initialized;
-	RSCFILE_CONTEXT *_interfaceContext;
+	ResourceContext *_interfaceContext;
 	InterfacePanel _mainPanel;
 	PanelButton *_inventoryUpButton;
 	PanelButton *_inventoryDownButton;

Index: isomap.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/isomap.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- isomap.cpp	9 Jul 2005 21:29:54 -0000	1.56
+++ isomap.cpp	19 Jul 2005 19:05:45 -0000	1.57
@@ -114,7 +114,7 @@
 	_tileDataLength = resourceLength;
 	memcpy(_tileData, resourcePointer, resourceLength);
 	
-	MemoryReadStreamEndian readS(_tileData, _tileDataLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(_tileData, _tileDataLength, _vm->isBigEndian());
 	readS.readUint16(); // skip
 	_tilesCount = readS.readUint16();
 	_tilesCount = _tilesCount / SAGA_ISOTILEDATA_LEN;
@@ -146,7 +146,7 @@
 		error("IsoMap::loadPlatforms wrong resourceLength");
 	}
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
 
 	_tilePlatformsCount = resourceLength / SAGA_TILEPLATFORMDATA_LEN;
 	_tilePlatformList = (TilePlatformData *)malloc(_tilePlatformsCount * sizeof(*_tilePlatformList));
@@ -177,7 +177,7 @@
 		error("IsoMap::loadMap wrong resourceLength");
 	}
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
 	_tileMap.edgeType = readS.readByte();
 	readS.readByte(); //skip
 
@@ -197,7 +197,7 @@
 		error("IsoMap::loadMetaTiles wrong resourceLength");
 	}
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
 	_metaTilesCount = resourceLength / SAGA_METATILEDATA_LEN;
 
 	_metaTileList = (MetaTileData *)malloc(_metaTilesCount * sizeof(*_metaTileList));
@@ -224,7 +224,7 @@
 		error("IsoMap::loadMetaTiles wrong resourceLength");
 	}
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
 	_multiCount = readS.readUint16();
 	_multiTable = (MultiTileEntryData *)malloc(_multiCount * sizeof(*_multiTable));
 	if (_multiTable == NULL) {

Index: ite_introproc.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/ite_introproc.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- ite_introproc.cpp	14 Jul 2005 17:46:20 -0000	1.59
+++ ite_introproc.cpp	19 Jul 2005 19:05:45 -0000	1.60
@@ -30,12 +30,13 @@
 #include "saga/animation.h"
 #include "saga/events.h"
 #include "saga/font.h"
-#include "saga/rscfile_mod.h"
 #include "saga/sndres.h"
 #include "saga/palanim.h"
 #include "saga/music.h"
 
 #include "saga/scene.h"
+#include "saga/resnames.h"
+#include "saga/rscfile.h"
 
 namespace Saga {
 
@@ -56,17 +57,17 @@
 };
 
 int Scene::ITEStartProc() {
-	size_t n_introscenes;
+	size_t scenesCount;
 	size_t i;
 
 	LoadSceneParams firstScene;
 	LoadSceneParams tempScene;
 
-	n_introscenes = ARRAYSIZE(ITE_IntroList);
+	scenesCount = ARRAYSIZE(ITE_IntroList);
 
-	for (i = 0; i < n_introscenes; i++) {
+	for (i = 0; i < scenesCount; i++) {
 		tempScene = ITE_IntroList[i];
-		tempScene.sceneDescriptor = RSC_ConvertID(tempScene.sceneDescriptor);
+		tempScene.sceneDescriptor = _vm->_resource->convertResourceId(tempScene.sceneDescriptor);
 		_vm->_scene->queueScene(&tempScene);
 	}
 
@@ -94,8 +95,11 @@
 	// Queue narrator dialogue list
 	textEntry.color = 255;
 	textEntry.effectColor = 0;
-	textEntry.point.x = 320 / 2;
-	textEntry.point.y = (_vm->getFeatures() & GF_LANG_DE) ? INTRO_DE_CAPTION_Y : INTRO_CAPTION_Y;
+	textEntry.useRect = true;
+	textEntry.rect.left = 0;
+	textEntry.rect.right = _vm->getDisplayWidth();
+	textEntry.rect.top = (_vm->getFeatures() & GF_LANG_DE) ? INTRO_DE_CAPTION_Y : INTRO_CAPTION_Y;
+	textEntry.rect.bottom = _vm->getDisplayHeight();
 	textEntry.fontId = kMediumFont;
 	textEntry.flags = (FontEffectFlags)(kFontOutline | kFontCentered);
 
@@ -754,7 +758,7 @@
 		event.type = ONESHOT_EVENT;
 		event.code = MUSIC_EVENT;
 		event.param = MUSIC_2;
-		event.param2 = 0;
+		event.param2 = MUSIC_NORMAL;
 		event.op = EVENT_PLAY;
 		event.time = 0;
 		

Index: music.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/music.cpp,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- music.cpp	19 Jun 2005 21:18:00 -0000	1.55
+++ music.cpp	19 Jul 2005 19:05:45 -0000	1.56
@@ -22,8 +22,8 @@
  */
 #include "saga/saga.h"
 
+#include "saga/rscfile.h"
 #include "saga/music.h"
-#include "saga/rscfile_mod.h"
 #include "saga/stream.h"
 #include "sound/audiostream.h"
 #include "sound/mididrv.h"
@@ -42,10 +42,11 @@
 
 class RAWInputStream : public AudioStream {
 private:
+	ResourceContext *_context;
 	Common::File *_file;
-	uint32 _file_pos;
-	uint32 _start_pos;
-	uint32 _end_pos;
+	uint32 _filePos;
+	uint32 _startPos;
+	uint32 _endPos;
 	bool _finished;
 	bool _looping;
 	int16 _buf[BUFFER_SIZE];
@@ -53,11 +54,12 @@
 	const int16 *_pos;
 
 	void refill();
-	inline bool eosIntern() const;
+	bool eosIntern() const {
+		return _pos >= _bufferEnd;
+	}
 
 public:
-	RAWInputStream(Common::File *file, int size, bool looping);
-	~RAWInputStream();
+	RAWInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping);
 
 	int readBuffer(int16 *buffer, const int numSamples);
 
@@ -66,28 +68,23 @@
 	int getRate() const	{ return 11025; }
 };
 
-RAWInputStream::RAWInputStream(Common::File *file, int size, bool looping)
-	: _file(file), _finished(false), _looping(looping),
-	  _bufferEnd(_buf + BUFFER_SIZE) {
+RAWInputStream::RAWInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping)
+	: _context(context), _finished(false), _looping(looping), _bufferEnd(_buf + BUFFER_SIZE) {
+	
+	ResourceData * resourceData;
 
-	_file->incRef();
+	resourceData = vm->_resource->getResourceData(context, resourceId);	
+	_file = context->getFile(resourceData);
 
 	// Determine the end position
-	_file_pos = _file->pos();
-	_start_pos = _file_pos;
-	_end_pos = _file_pos + size;
+	_startPos = resourceData->offset;
+	_endPos = _startPos + resourceData->size;
+	_filePos = _startPos;
 
 	// Read in initial data
 	refill();
 }
 
-RAWInputStream::~RAWInputStream() {
-	_file->decRef();
-}
-
-inline bool RAWInputStream::eosIntern() const {
-	return _pos >= _bufferEnd;
-}
 
 int RAWInputStream::readBuffer(int16 *buffer, const int numSamples) {
 	int samples = 0;
@@ -108,61 +105,47 @@
 	if (_finished)
 		return;
 
-	uint32 len_left;
+	uint32 lengthLeft;
 	byte *ptr = (byte *) _buf;
 	
 
-	_file->seek(_file_pos, SEEK_SET);
+	_file->seek(_filePos, SEEK_SET);
 
 	if (_looping)
-		len_left = 2 * BUFFER_SIZE;
+		lengthLeft = 2 * BUFFER_SIZE;
 	else
-		len_left = MIN((uint32) (2 * BUFFER_SIZE), _end_pos - _file_pos);
+		lengthLeft = MIN((uint32) (2 * BUFFER_SIZE), _endPos - _filePos);
 
-	while (len_left > 0) {
-		uint32 len = _file->read(ptr, MIN(len_left, _end_pos - _file->pos()));
+	while (lengthLeft > 0) {
+		uint32 len = _file->read(ptr, MIN(lengthLeft, _endPos - _file->pos()));
 
 		if (len & 1)
 			len--;
 
-		if (_vm->getFeatures() & GF_BIG_ENDIAN_DATA) {			
+		if (_context->isBigEndian) {			
 			uint16 *ptr16 = (uint16 *)ptr;
 			for (uint32 i = 0; i < (len / 2); i++)
 				ptr16[i] = TO_BE_16(ptr16[i]);
 		}
 			
-		len_left -= len;
+		lengthLeft -= len;
 		ptr += len;
 
-		if (len_left > 0)
-			_file->seek(_start_pos);
+		if (lengthLeft > 0)
+			_file->seek(_startPos);
 	}
 
-	_file_pos = _file->pos();
+	_filePos = _file->pos();
 	_pos = _buf;
 	_bufferEnd = (int16 *)ptr;
 
-	if (!_looping && _file_pos >= _end_pos)
+	if (!_looping && _filePos >= _endPos) {
 		_finished = true;
-}
-
-AudioStream *makeRAWStream(const char *filename, uint32 pos, int size, bool looping) {
-	Common::File *file = new Common::File();
-
-	if (!file->open(filename)) {
-		delete file;
-		return NULL;
 	}
-
-	file->seek(pos);
-
-	AudioStream *audioStream = new RAWInputStream(file, size, looping);
-
-	file->decRef();
-	return audioStream;
 }
 
-	MusicPlayer::MusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
+
+MusicPlayer::MusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
 	memset(_channel, 0, sizeof(_channel));
 	_masterVolume = 0;
 	this->open();
@@ -274,19 +257,20 @@
 	_isPlaying = false;
 	if (_parser) {
 		_parser->unloadMusic();
-		delete _parser;
 		_parser = NULL;
 	}
 }
 
-Music::Music(Audio::Mixer *mixer, MidiDriver *driver, int enabled) : _mixer(mixer), _enabled(enabled), _adlib(false) {
+Music::Music(SagaEngine *vm, Audio::Mixer *mixer, MidiDriver *driver, int enabled) : _vm(vm), _mixer(mixer), _enabled(enabled), _adlib(false) {
 	_player = new MusicPlayer(driver);
-	_musicInitialized = 1;
 	_currentVolume = 0;
 
+	xmidiParser = MidiParser::createParser_XMIDI();
+	smfParser = MidiParser::createParser_SMF();
+
 	if (_vm->getGameType() == GType_ITE) {
 		Common::File file;
-		byte footerBuf[ARRAYSIZE(_digiTableITECD) * 8];
+//		byte footerBuf[ARRAYSIZE(_digiTableITECD) * 8];
 
 		// The lookup table is stored at the end of music.rsc. I don't
 		// know why it has 27 elements, but the last one represents a
@@ -300,40 +284,19 @@
 		// Proper approach would be to extend resource manager so it could
 		// return File object.
 
-		_musicContext = _vm->getFileContext(GAME_MUSICFILE, 0);
+		_musicContext = _vm->_resource->getContext(GAME_MUSICFILE);
 		if (_musicContext != NULL) {
-			_hasDigiMusic = true;
-
-			_musicFname = RSC_FileName(_musicContext);
-
-			file.open(_musicFname);
-			assert(file.size() > sizeof(footerBuf));
-
-			file.seek(-ARRAYSIZE(_digiTableITECD) * 8, SEEK_END);
-			file.read(footerBuf, sizeof(footerBuf));
-
-			MemoryReadStreamEndian readS(footerBuf, sizeof(footerBuf), IS_BIG_ENDIAN);
-
-
-			for (int i = 0; i < ARRAYSIZE(_digiTableITECD); i++) {
-				_digiTableITECD[i].start = readS.readUint32();
-				_digiTableITECD[i].length = readS.readUint32();
-			}
-
-			file.close();
-
 			// The "birdchrp" is just a short, high-pitched
 			// whining. Use the MIDI/XMIDI version instead.
-			_digiTableITECD[6].length = 0;
-		} else {
-			_hasDigiMusic = false;
-			memset(_digiTableITECD, 0, sizeof(_digiTableITECD));
+			///_digiTableITECD[6].length = 0;
 		}
 	}
 }
 
 Music::~Music() {
 	delete _player;
+	delete xmidiParser;
+	delete smfParser;
 }
 
 void Music::musicVolumeGaugeCallback(void *refCon) {
@@ -389,169 +352,114 @@
 //
 // reset.mid seems to be unused.
 
-const MUSIC_MIDITABLE Music::_midiTableITECD[26] = {
-	{ "cave.mid",       MUSIC_LOOP },	// 9
-	{ "intro.mid",      MUSIC_LOOP },	// 10
-	{ "fvillage.mid",   MUSIC_LOOP },	// 11
-	{ "elkhall.mid",    MUSIC_LOOP },	// 12
-	{ "mouse.mid",      0          },	// 13
-	{ "darkclaw.mid",   MUSIC_LOOP },	// 14
-	{ "birdchrp.mid",   MUSIC_LOOP },	// 15
-	{ "orbtempl.mid",   MUSIC_LOOP },	// 16
-	{ "spooky.mid",     MUSIC_LOOP },	// 17
-	{ "catfest.mid",    MUSIC_LOOP },	// 18
-	{ "elkfanfare.mid", 0          },	// 19
-	{ "bcexpl.mid",     MUSIC_LOOP },	// 20
-	{ "boargtnt.mid",   MUSIC_LOOP },	// 21
-	{ "boarking.mid",   MUSIC_LOOP },	// 22
-	{ "explorea.mid",   MUSIC_LOOP },	// 23
-	{ "exploreb.mid",   MUSIC_LOOP },	// 24
-	{ "explorec.mid",   MUSIC_LOOP },	// 25
-	{ "sunstatm.mid",   MUSIC_LOOP },	// 26
-	{ "nitstrlm.mid",   MUSIC_LOOP },	// 27
-	{ "humruinm.mid",   MUSIC_LOOP },	// 28
-	{ "damexplm.mid",   MUSIC_LOOP },	// 29
-	{ "tychom.mid",     MUSIC_LOOP },	// 30
-	{ "kitten.mid",     MUSIC_LOOP },	// 31
-	{ "sweet.mid",      MUSIC_LOOP },	// 32
-	{ "brutalmt.mid",   MUSIC_LOOP },	// 33
-	{ "shiala.mid",     MUSIC_LOOP }	// 34
-};
 
-int Music::play(uint32 music_rn, uint16 flags) {
-	RSCFILE_CONTEXT *rsc_ctxt = NULL;
-
-	byte *resource_data;
-	size_t resource_size;
-
-	if (!_musicInitialized) {
-		return FAILURE;
-	}
+void Music::play(uint32 resourceId, MusicFlags flags) {
+	AudioStream *audioStream = NULL;
+	MidiParser *parser;
+	ResourceContext *context;
+	byte *resourceData;
+	size_t resourceSize;
+	debug(2, "Music::play %d, %d", resourceId, flags);
 
 	if (!_enabled) {
-		return SUCCESS;
+		return;
 	}
 
-	if (isPlaying() && _trackNumber == music_rn) {
-		return SUCCESS;
+	if (isPlaying() && _trackNumber == resourceId) {
+		return;
 	}
 
-	_trackNumber = music_rn;
+	_trackNumber = resourceId;
 
 	_player->stopMusic();
 
 	_mixer->stopHandle(_musicHandle);
 
-	AudioStream *audioStream = NULL;
-	MidiParser *parser;
-	Common::File midiFile;
 
 	if (_vm->getGameType() == GType_ITE) {
-		if (music_rn >= 9 && music_rn <= 34) {
-			if (flags == MUSIC_DEFAULT) {
-				flags = _midiTableITECD[music_rn - 9].flags;
-			}
 
-			if (_hasDigiMusic) {
-				uint32 start = _digiTableITECD[music_rn - 9].start;
-				uint32 length = _digiTableITECD[music_rn - 9].length;
-
-				if (length > 0) {
-					audioStream = makeRAWStream(_musicFname, start, length, flags == MUSIC_LOOP);
+		if (resourceId >= 9 && resourceId <= 34) {
+			if (flags == MUSIC_DEFAULT) {
+				if ((resourceId == 13) || (resourceId == 19)) {
+					flags = MUSIC_NORMAL;
+				} else {
+					flags = MUSIC_LOOP;
 				}
 			}
 
-			// No digitized music - try standalone MIDI.
-			if (!audioStream) {
-				midiFile.open(_midiTableITECD[music_rn - 9].filename);
 
-				if (!midiFile.isOpen()) {
-					debug(2, "Cannot open music file %s", _midiTableITECD[music_rn - 9].filename);
-				}
+			if (_musicContext != NULL) {
+				//TODO: check resource size
+				audioStream = new RAWInputStream(_vm, _musicContext, resourceId, flags == MUSIC_LOOP);
 			}
 		}
 	}
 
-	if (flags == MUSIC_DEFAULT) {
-		flags = 0;
-	}
 
 	if (audioStream) {
 		debug(2, "Playing digitized music");
 		_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, audioStream);
-		return SUCCESS;
+		return;
 	}
 
-	// FIXME: Is resource_data ever freed?
+	if (flags == MUSIC_DEFAULT) {
+		flags = MUSIC_NORMAL;
+	}
 
-	if (midiFile.isOpen()) {
-		debug(2, "Using external MIDI file: %s", midiFile.name());
-		resource_size = midiFile.size();
-		resource_data = (byte *) malloc(resource_size);
-		midiFile.read(resource_data, resource_size);
-		midiFile.close();
+	// FIXME: Is resource_data ever freed?
+	// Load MIDI/XMI resource data
 
-		_player->setGM(true);
-		parser = MidiParser::createParser_SMF();
+	if (_vm->getGameType() == GType_ITE) {
+		context = _vm->_resource->getContext(GAME_RESOURCEFILE);
 	} else {
-		// Load MIDI/XMI resource data
-
-		if (_vm->getGameType() == GType_ITE) {
-			rsc_ctxt = _vm->getFileContext(GAME_RESOURCEFILE, 0);
-		} else {
-			// I've listened to music from both the FM and the GM
-			// file, and I've tentatively reached the conclusion
-			// that they are both General MIDI. My guess is that
-			// the FM file has been reorchestrated to sound better 
-			// on Adlib and other FM synths.
-			//
-			// Sev says the Adlib music does not sound like in the
-			// original, but I still think assuming General MIDI is
-			// the right thing to do. Some music, like the End
-			// Title (song 0) sound absolutely atrocious when piped
-			// through our MT-32 to GM mapping.
-			//
-			// It is, however, quite possible that the original
-			// used a different GM to FM mapping. If the original
-			// sounded markedly better, perhaps we should add some
-			// way of replacing our stock mapping in adlib.cpp?
-			//
-			// For the composer's own recording of the End Title,
-			// see http://www.johnottman.com/
-
-			// Oddly enough, the intro music (song 1) is very
-			// different in the two files. I have no idea why.
-
-			if (hasAdlib()) {
-				rsc_ctxt = _vm->getFileContext(GAME_MUSICFILE_FM, 0);
-			} else {
-				rsc_ctxt = _vm->getFileContext(GAME_MUSICFILE_GM, 0);
-			}
+		// I've listened to music from both the FM and the GM
+		// file, and I've tentatively reached the conclusion
+		// that they are both General MIDI. My guess is that
+		// the FM file has been reorchestrated to sound better 
+		// on Adlib and other FM synths.
+		//
+		// Sev says the Adlib music does not sound like in the
+		// original, but I still think assuming General MIDI is
+		// the right thing to do. Some music, like the End
+		// Title (song 0) sound absolutely atrocious when piped
+		// through our MT-32 to GM mapping.
+		//
+		// It is, however, quite possible that the original
+		// used a different GM to FM mapping. If the original
+		// sounded markedly better, perhaps we should add some
+		// way of replacing our stock mapping in adlib.cpp?
+		//
+		// For the composer's own recording of the End Title,
+		// see http://www.johnottman.com/
 
-			_player->setGM(true);
-		}
+		// Oddly enough, the intro music (song 1) is very
+		// different in the two files. I have no idea why.
 
-		if (RSC_LoadResource(rsc_ctxt, music_rn, &resource_data, 
-				&resource_size) != SUCCESS) {
-			warning("Music::play(): Resource load failed: %u", music_rn);
-			return FAILURE;
+		if (hasAdlib()) {
+			context = _vm->_resource->getContext(GAME_MUSICFILE_FM);
+		} else {
+			context = _vm->_resource->getContext(GAME_MUSICFILE_GM);
 		}
 
-		parser = MidiParser::createParser_XMIDI();
 	}
 
-	if (resource_size <= 0) {
-		warning("Music::play(): Resource load failed: %u", music_rn);
-		return FAILURE;
-	}
+	_player->setGM(true);
 
-	if (!parser->loadMusic(resource_data, resource_size)) {
-		warning("Error reading track!");
-		delete parser;
-		parser = 0;
+	_vm->_resource->loadResource(context, resourceId, resourceData, resourceSize); 
+	
+	if (resourceSize < 4) {
+		error("Music::play() wrong music resource size");
 	}
 
-	debug(2, "Music::play(%d, %d)", music_rn, flags);
+	if (xmidiParser->loadMusic(resourceData, resourceSize)) {
+		parser = xmidiParser;
+	} else {
+		if (smfParser->loadMusic(resourceData, resourceSize)) {
+			parser = smfParser;			
+		} else {
+			error("Music::play() wrong music resource");
+		}
+	}
 
 	parser->setTrack(0);
 	parser->setMidiDriver(_player);
@@ -559,37 +467,25 @@
 
 	_player->_parser = parser;
 	_player->setVolume(ConfMan.getInt("music_volume"));
+
 	if (flags & MUSIC_LOOP)
 		_player->setLoop(true);
 	else
 		_player->setLoop(false);
 
 	_player->playMusic();
-	return SUCCESS;
 }
 
-int Music::pause(void) {
-	if (!_musicInitialized) {
-		return FAILURE;
-	}
-
-	return SUCCESS;
+void Music::pause(void) {
+	//TODO: do it
 }
 
-int Music::resume(void) {
-	if (!_musicInitialized) {
-		return FAILURE;
-	}
-
-	return SUCCESS;
+void Music::resume(void) {
+	//TODO: do it}
 }
 
-int Music::stop(void) {
-	if (!_musicInitialized) {
-		return FAILURE;
-	}
-
-	return SUCCESS;
+void Music::stop(void) {
+	//TODO: do it
 }
 
 } // End of namespace Saga

Index: music.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/music.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- music.h	19 Jun 2005 21:18:00 -0000	1.23
+++ music.h	19 Jul 2005 19:05:46 -0000	1.24
@@ -26,27 +26,18 @@
 #ifndef SAGA_MUSIC_H_
 #define SAGA_MUSIC_H_
 
-#include "saga/rscfile_mod.h"
 #include "sound/mixer.h"
 #include "sound/mididrv.h"
 #include "sound/midiparser.h"
 
 namespace Saga {
-enum MUSIC_FLAGS {
+
+enum MusicFlags {
+	MUSIC_NORMAL = 0,
 	MUSIC_LOOP = 0x0001,
 	MUSIC_DEFAULT = 0xffff
 };
 
-struct MUSIC_MIDITABLE {
-	const char *filename;
-	int flags;
-};
-
-struct MUSIC_DIGITABLE {
-	uint32 start;
-	uint32 length;
-};
-
 class MusicPlayer : public MidiDriver {
 public:
 	MusicPlayer(MidiDriver *driver);
@@ -106,7 +97,7 @@
 class Music {
 public:
 
-	Music(Audio::Mixer *mixer, MidiDriver *driver, int enabled);
+	Music(SagaEngine *vm, Audio::Mixer *mixer, MidiDriver *driver, int enabled);
 	~Music(void);
 	void setNativeMT32(bool b)	{ _player->setNativeMT32(b); }
 	bool hasNativeMT32()		{ return _player->hasNativeMT32(); }
@@ -115,35 +106,31 @@
 	void setPassThrough(bool b)	{ _player->setPassThrough(b); }
 	bool isPlaying(void);
 
-	int play(uint32 music_rn, uint16 flags = MUSIC_DEFAULT);
-	int pause(void);
-	int resume(void);
-	int stop(void);
+	void play(uint32 resourceId, MusicFlags flags = MUSIC_DEFAULT);
+	void pause(void);
+	void resume(void);
+	void stop(void);
 
 	void setVolume(int volume, int time);
 
 private:
-
+	SagaEngine *_vm;
 	Audio::Mixer *_mixer;
 
 	MusicPlayer *_player;
 	Audio::SoundHandle _musicHandle;
 	uint32 _trackNumber;
 
-	static const MUSIC_MIDITABLE _midiTableITECD[26];
-	MUSIC_DIGITABLE _digiTableITECD[27];
-
-	int _musicInitialized;
 	int _enabled;
-	bool _hasDigiMusic;
 	bool _adlib;
 
 	int _targetVolume;
 	int _currentVolume;
 	int _currentVolumePercent;
 
-	RSCFILE_CONTEXT *_musicContext;
-	const char *_musicFname;
+	ResourceContext *_musicContext;
+	MidiParser *xmidiParser;
+	MidiParser *smfParser;
 
 	static void musicVolumeGaugeCallback(void *refCon);
 	void musicVolumeGauge(void);

Index: objectmap.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/objectmap.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- objectmap.cpp	14 Jul 2005 17:46:20 -0000	1.42
+++ objectmap.cpp	19 Jul 2005 19:05:46 -0000	1.43
@@ -132,7 +132,7 @@
 	return false;
 }
 
-void HitZone::draw(Surface *ds, int color) {
+void HitZone::draw(SagaEngine *vm, Surface *ds, int color) {
 	int i, pointsCount, j;
 	Location location;
 	HitZone::ClickArea *clickArea;
@@ -140,15 +140,14 @@
 	for (i = 0; i < _clickAreasCount; i++) {
 		clickArea = &_clickAreas[i];
 		pointsCount = clickArea->pointsCount;
-		if (_vm->_scene->getFlags() & kSceneFlagISO) {
+		if (vm->_scene->getFlags() & kSceneFlagISO) {
 			points = (Point*)malloc(sizeof(Point) * pointsCount);
 			for (j = 0; j < pointsCount; j++) {
 				location.u() = clickArea->points[j].x;
 				location.v() = clickArea->points[j].y;
 				location.z = 0;
-				_vm->_isoMap->tileCoordsToScreenPoint(location, points[j]);
-			}
-			//
+				vm->_isoMap->tileCoordsToScreenPoint(location, points[j]);
+			}			
 		} else {
 			points = clickArea->points;
 		}
@@ -162,7 +161,7 @@
 				ds->drawPolyLine(points, pointsCount, color);
 			}
 		}
-		if (_vm->_scene->getFlags() & kSceneFlagISO) {
+		if (vm->_scene->getFlags() & kSceneFlagISO) {
 			free(points);
 		}
 
@@ -174,11 +173,15 @@
 void ObjectMap::load(const byte *resourcePointer, size_t resourceLength) {
 	int i;
 
+	if (resourceLength == 0) {
+		return;
+	}
+
 	if (resourceLength < 4) {
 		error("ObjectMap::load wrong resourceLength");
 	}
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
 
 	_hitZoneListCount = readS.readSint16();
 	if (_hitZoneListCount < 0) {
@@ -232,7 +235,7 @@
 	hitZoneIndex = hitTest(pickPoint);
 
 	for (i = 0; i < _hitZoneListCount; i++) {		
-		_hitZoneList[i]->draw(ds, (hitZoneIndex == i) ? color2 : color);
+		_hitZoneList[i]->draw(_vm, ds, (hitZoneIndex == i) ? color2 : color);
 	}
 
 	if (hitZoneIndex != -1) {		

Index: objectmap.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/objectmap.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- objectmap.h	9 Jul 2005 16:23:44 -0000	1.22
+++ objectmap.h	19 Jul 2005 19:05:46 -0000	1.23
@@ -76,7 +76,7 @@
 		return objectIndexToId(kGameObjectStepZone, _index);
 	}
 	bool getSpecialPoint(Point &specialPoint) const;
-	void draw(Surface *ds, int color);	
+	void draw(SagaEngine *vm, Surface *ds, int color);	
 	bool hitTest(const Point &testPoint);
 
 private:

Index: palanim.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/palanim.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- palanim.cpp	9 Jul 2005 16:23:44 -0000	1.24
+++ palanim.cpp	19 Jul 2005 19:05:46 -0000	1.25
@@ -54,7 +54,7 @@
 		return FAILURE;
 	}
 
-	MemoryReadStreamEndian readS(resdata, resdata_len, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resdata, resdata_len, _vm->isBigEndian());
 
 	if (_vm->getGameType() == GType_IHNM) {
 		return SUCCESS;

Index: rscfile.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/rscfile.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- rscfile.cpp	21 Jun 2005 13:55:18 -0000	1.23
+++ rscfile.cpp	19 Jul 2005 19:05:46 -0000	1.24
@@ -24,300 +24,200 @@
 // RSC Resource file management module
 #include "saga/saga.h"
 
-#include "saga/rscfile_mod.h"
 #include "saga/rscfile.h"
 #include "saga/stream.h"
 
 namespace Saga {
 
-static struct Substitutes {
-	uint32 id;
-	const char *resfile;
-	const char *fname;
-} substitutes[] = {
-	{ 1529, "ite.rsc", "wyrm.pak" },
-	{ 1530, "ite.rsc", "wyrm1.dlt" },
-	{ 1531, "ite.rsc", "wyrm2.dlt" },
-	{ 1532, "ite.rsc", "wyrm3.dlt" },
-	{ 1533, "ite.rsc", "wyrm4.dlt" },
-	{ 1796, "ite.rsc", "credit3n.dlt" },
-	{ 1797, "ite.rsc", "credit4n.dlt" }
-};
-	
-
-RSCFILE_CONTEXT *RSC_CreateContext() {
-	RSCFILE_CONTEXT empty_context;
-	empty_context.rc_file_fspec = NULL;
-	empty_context.rc_file_loaded = 0;
-	empty_context.rc_res_table = NULL;
-	empty_context.rc_res_ct = 0;
-	empty_context.rc_file = new Common::File();
-	RSCFILE_CONTEXT *new_context;
-
-	new_context = (RSCFILE_CONTEXT *)malloc(sizeof(*new_context));
-	if (new_context == NULL) {
-		return NULL;
-	}
-
-	*new_context = empty_context;
-
-	return new_context;
-}
-
-int RSC_OpenContext(RSCFILE_CONTEXT *rsc_context, const char *fspec) {
-	if (rsc_context->rc_file->isOpen()) {
-		return FAILURE;
-	}
-
-	if (!rsc_context->rc_file->open(fspec)) {
-		return FAILURE;
-	}
-
-	rsc_context->rc_file_fspec = fspec;
-
-	if (RSC_LoadRSC(rsc_context) != SUCCESS) {
-		return FAILURE;
-	}
-
-	rsc_context->rc_file_loaded = 1;
-
-	return SUCCESS;
+Resource::Resource(SagaEngine *vm): _vm(vm) {
+	_contexts = NULL;
+	_contextsCount = 0;
 }
 
-int RSC_CloseContext(RSCFILE_CONTEXT *rsc_context) {
-	if (rsc_context->rc_file->isOpen()) {
-		rsc_context->rc_file->close();
-	}
-
-	RSC_FreeRSC(rsc_context);
-
-	rsc_context->rc_file_loaded = 0;
-
-	return SUCCESS;
+Resource::~Resource() {
+	clearContexts();
 }
 
-int RSC_DestroyContext(RSCFILE_CONTEXT *rsc_context) {
-	RSC_CloseContext(rsc_context);
+bool Resource::loadContext(ResourceContext *context) {
+	size_t i;
+	int j;
+	bool result;
+	byte tableInfo[RSC_TABLEINFO_SIZE];	
+	uint32 resourceTableOffset;
+	GamePatchDescription *patchDescription;
+	ResourceData *resourceData;
+	byte *tableBuffer;
+	size_t tableSize;
 
-	if (rsc_context->rc_file_loaded) {
-		free(rsc_context->rc_res_table);
+	if (!context->file->open(context->fileName)) {
+		return false;
+	}
+	
+	context->isBigEndian = _vm->isBigEndian();
+	
+	if (!context->isBigEndian) {
+		context->isBigEndian = ((_vm->getFeatures() & GF_BIG_ENDIAN_VOICES) != 0) && ((context->fileType & GAME_VOICEFILE) != 0);
 	}
 
-	free(rsc_context);
-
-	return SUCCESS;
-}
-
-int RSC_LoadRSC(RSCFILE_CONTEXT *rsc) {
-	uint32 res_tbl_ct;
-	uint32 res_tbl_offset;
-
-	byte tblinfo_buf[RSC_TABLEINFO_SIZE];
-	byte *tbl_buf;
-	size_t tbl_len;
-	uint32 i;
-
-	bool isBigEndian = _vm->isBigEndianFile(rsc->rc_file_fspec);
 
-	RSCFILE_RESOURCE *rsc_restbl;
 
-	if (rsc->rc_file->size() < RSC_MIN_FILESIZE) {
-		return FAILURE;
+	if (context->file->size() < RSC_MIN_FILESIZE) {
+		return false;
 	}
 
 	// Read resource table info from the rear end of file
-	rsc->rc_file->seek((long)(rsc->rc_file->size() - 8), SEEK_SET);
+	context->file->seek((long)(-RSC_TABLEINFO_SIZE), SEEK_END);
 
-	if (rsc->rc_file->read(tblinfo_buf, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
-		return FAILURE;
+	if (context->file->read(tableInfo, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
+		return false;
 	}
-	
-	MemoryReadStreamEndian readS(tblinfo_buf, RSC_TABLEINFO_SIZE, isBigEndian);
 
-	res_tbl_offset = readS.readUint32();
-	res_tbl_ct = readS.readUint32();
+	MemoryReadStreamEndian readS(tableInfo, RSC_TABLEINFO_SIZE, context->isBigEndian);
 
-	// Check for sane table offset
-	if (res_tbl_offset != rsc->rc_file->size() - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * res_tbl_ct) {
+	resourceTableOffset = readS.readUint32();
+	context->count = readS.readUint32();
 
-		return FAILURE;
+	// Check for sane table offset
+	if (resourceTableOffset != context->file->size() - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * context->count) {
+		return false;
 	}
 
 	// Load resource table
-	tbl_len = RSC_TABLEENTRY_SIZE * res_tbl_ct;
-
-	tbl_buf = (byte *)malloc(tbl_len);
-	if (tbl_buf == NULL) {
-		return FAILURE;
-	}
+	tableSize = RSC_TABLEENTRY_SIZE * context->count;
 
-	rsc->rc_file->seek((long)res_tbl_offset, SEEK_SET);
+	tableBuffer = (byte *)malloc(tableSize);
 
-	if (rsc->rc_file->read(tbl_buf, tbl_len) != tbl_len) {
-		free(tbl_buf);
-		return FAILURE;
-	}
+	context->file->seek((long)resourceTableOffset, SEEK_SET);
 
-	rsc_restbl = (RSCFILE_RESOURCE *)malloc(res_tbl_ct * sizeof(*rsc_restbl));
-	if (rsc_restbl == NULL) {
-		free(tbl_buf);
-		return FAILURE;
-	}
+	
+	result = (context->file->read(tableBuffer, tableSize) == tableSize);
+	if (result) {
+		context->table = (ResourceData *)calloc(context->count, sizeof(*context->table));
 
-	MemoryReadStreamEndian readS1(tbl_buf, tbl_len, isBigEndian);
+		MemoryReadStreamEndian readS1(tableBuffer, tableSize, context->isBigEndian);
 
-	debug(9, "RSC %s", rsc->rc_file_fspec);
-	for (i = 0; i < res_tbl_ct; i++) {
-		rsc_restbl[i].res_offset = readS1.readUint32();
-		rsc_restbl[i].res_size = readS1.readUint32();
-		//debug(9, "#%x Offset:%x Size:%x", i, rsc_restbl[i].res_offset, rsc_restbl[i].res_size);
-		if ((rsc_restbl[i].res_offset > rsc->rc_file->size()) || (rsc_restbl[i].res_size > rsc->rc_file->size())) {
-			free(tbl_buf);
-			free(rsc_restbl);
-			return FAILURE;
+		for (i = 0; i < context->count; i++) {
+			resourceData = &context->table[i];
+			resourceData->offset = readS1.readUint32();
+			resourceData->size = readS1.readUint32();
+			//sanity check
+			if ((resourceData->offset > context->file->size()) || (resourceData->size > context->file->size())) {
+				result = false;
+				break;
+			}
 		}
 	}
 
-	rsc->rc_res_table = rsc_restbl;
-	rsc->rc_res_ct = res_tbl_ct;
-
-	free(tbl_buf);
-
-	return SUCCESS;
-}
-
-int RSC_FreeRSC(RSCFILE_CONTEXT *rsc) {
-	if (!rsc->rc_file_loaded) {
-		return FAILURE;
+	free(tableBuffer);
+	
+	//process patch files
+	if (result) {
+		for (j = 0; j < _vm->getGameDescription()->patchsCount; j++) {
+			patchDescription = &_vm->getGameDescription()->patchDescriptions[j];
+			if ((patchDescription->fileType & context->fileType) != 0) {
+				if (patchDescription->resourceId < context->count) {
+					//TODO|fix: should we convert this ID? or make separate patch list for MAC version?
+					resourceData = &context->table[patchDescription->resourceId];
+					resourceData->patchFile = new Common::File();
+					if (resourceData->patchFile->open(patchDescription->fileName)) {
+						resourceData->offset = 0;
+						resourceData->size = resourceData->patchFile->size();
+					} else {
+						warning("loadContext: patch file not found %s", patchDescription->fileName);
+						delete resourceData->patchFile;
+						resourceData->patchFile = NULL;
+					}
+				}
+			}
+		}
 	}
 
-	delete rsc->rc_file;
-	rsc->rc_file = NULL;
-
-	free(rsc->rc_res_table);
-
-	return SUCCESS;
-}
-
-uint32 RSC_GetResourceCount(RSCFILE_CONTEXT *rsc) {
-	return (rsc == NULL) ? 0 : rsc->rc_res_ct;
+	return result;
 }
 
-int RSC_GetResourceSize(RSCFILE_CONTEXT *rsc, uint32 res_num, uint32 *res_size) {
-	if ((rsc == NULL) || (res_size == NULL)) {
-		return FAILURE;
-	}
-
-	if (res_num > (rsc->rc_res_ct - 1)) {
-		return FAILURE;
-	}
-
-	*res_size = rsc->rc_res_table[res_num].res_size;
-
-	return SUCCESS;
-}
+bool Resource::createContexts() {
+	int i, j;
+	ResourceContext *context;
+	_contextsCount = _vm->getGameDescription()->filesCount;
+	_contexts = (ResourceContext*)calloc(_contextsCount, sizeof(*_contexts));
 
-int RSC_GetResourceOffset(RSCFILE_CONTEXT *rsc, uint32 res_num, uint32 *res_offset) {
-	if ((rsc == NULL) || (res_offset == NULL)) {
-		return FAILURE;
-	}
+	for (i = 0; i < _contextsCount; i++) {
+		context = &_contexts[i];
+		context->file = new Common::File();
+		context->fileName = _vm->getGameDescription()->filesDescriptions[i].fileName;
+		context->fileType = _vm->getGameDescription()->filesDescriptions[i].fileType;
 
-	if (res_num > (rsc->rc_res_ct - 1)) {
-		return FAILURE;
+		//self check
+		for (j = 0; j < i; j++) {
+			if ((_contexts[j].fileType & context->fileType) != 0) {
+				error("Resource::createContexts() duplicate fileType");
+			}
+		}
+		
+		if (!loadContext(context)) {
+			return false;
+		}
 	}
-
-	*res_offset = rsc->rc_res_table[res_num].res_offset;
-
-	return SUCCESS;
-}
-
-const char *RSC_FileName(RSCFILE_CONTEXT *rsc) {
-	return rsc->rc_file_fspec;
+	return true;
 }
 
-int RSC_LoadResource(RSCFILE_CONTEXT *rsc, uint32 res_num, byte **res_p, size_t *res_size_p) {
-	uint32 res_offset;
-	size_t res_size = 0;
-	byte *res_buf = NULL;
-	int substnum = -1;
-
-	if ((rsc == NULL) || (res_p == NULL)) {
-		return FAILURE;
-	}
-
-	if (res_num > (rsc->rc_res_ct - 1)) {
-		return FAILURE;
+void Resource::clearContexts() {
+	int i;
+	size_t j;
+	ResourceContext *context;
+	if (_contexts == NULL) {
+		return;
 	}
-
-	debug(8, "LoadResource %d", res_num);
-	for (int i = 0; i < ARRAYSIZE(substitutes); i++) {
-		if (substitutes[i].id == res_num && strcmp(substitutes[i].resfile, rsc->rc_file_fspec) == 0) {
-			substnum = i;
-			break;
+	for(i = 0; i < _contextsCount; i++) {
+		context = &_contexts[i];
+		delete context->file;
+		if (context->table != NULL) {
+			for(j = 0; j < context->count; j++) {
+				delete context->table[j].patchFile;
+			}
 		}
+		free(context->table);
 	}
+	free(_contexts);
+	_contexts = NULL;
+}
 
-	if (!(_vm->getFeatures() & GF_WYRMKEEP))
-		substnum = -1;
-
-	if (substnum != -1) {
-		Common::File in;
-
-		if (in.open(substitutes[substnum].fname)) {
-			res_size = in.size();
-			if ((res_buf = (byte *)malloc(res_size)) == NULL)
-				return MEM;
-
-			in.read(res_buf, res_size);
-			in.close();
-			debug(8, "LoadResource: substituted resource by %s", substitutes[substnum].fname);
+uint32 Resource::convertResourceId(uint32 resourceId) {
+	
+	if ((_vm->getGameType() ==  GType_ITE) && (_vm->getFeatures() & GF_MAC_RESOURCES)) {
+		if (resourceId > 1537) {
+			return resourceId - 2;
 		} else {
-			substnum = -1;
-		}
-	}
-
-	if (substnum == -1) {
-		res_offset = rsc->rc_res_table[res_num].res_offset;
-		res_size = rsc->rc_res_table[res_num].res_size;
-
-		if ((res_buf = (byte *)malloc(res_size)) == NULL)
-			return MEM;
-
-		rsc->rc_file->seek((long)res_offset, SEEK_SET);
-
-		if (rsc->rc_file->read(res_buf, res_size) != res_size) {
-			free(res_buf);
-			return FAILURE;
+			if (resourceId == 1535 || resourceId == 1536) {
+				error ("Wrong resource number %d for Mac ITE", resourceId);
+			}
 		}
 	}
 
-	*res_p = res_buf;
+	return resourceId;
+}
 
-	if (res_size_p != NULL) {
-		*res_size_p = res_size;
-	}
+void Resource::loadResource(ResourceContext *context, uint32 resourceId, byte*&resourceBuffer, size_t &resourceSize) {
+	Common::File *file;
+	uint32 resourceOffset;
+	ResourceData *resourceData;
 
-	return SUCCESS;
-}
+	debug(8, "loadResource %d", resourceId);
+	
+	resourceData = getResourceData(context, resourceId);
+	
+	file = context->getFile(resourceData);
 
-int RSC_FreeResource(byte *resource_ptr) {
-	free(resource_ptr);
+	resourceOffset = resourceData->offset;
+	resourceSize = resourceData->size;
 
-	return SUCCESS;
-}
+	resourceBuffer = (byte*)malloc(resourceSize);
 
-int RSC_ConvertID(int id) {
-	int res = id;
+	file->seek((long)resourceOffset, SEEK_SET);
 
-	if (_vm->getFeatures() & GF_MAC_RESOURCES) {
-		if (res > 1537)
-			res -= 2;
-		else if (res == 1535 || res == 1536) {
-			error ("Wrong resource number %d for Mac ITE");
-		}
+	if (file->read(resourceBuffer, resourceSize) != resourceSize) {
+		error("Resource::loadResource() failed to read");
 	}
-
-	return res;
 }
 
 } // End of namespace Saga

Index: rscfile.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/rscfile.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- rscfile.h	10 May 2005 22:55:54 -0000	1.10
+++ rscfile.h	19 Jul 2005 19:05:47 -0000	1.11
@@ -36,22 +36,79 @@
 
 #define RSC_MIN_FILESIZE (RSC_TABLEINFO_SIZE + RSC_TABLEENTRY_SIZE + 1)
 
-struct RSCFILE_RESOURCE {
-	int res_type;
-	size_t res_offset;
-	size_t res_size;
+//TODO: good PATCH.RE_ support
+
+struct ResourceData {
+	size_t offset;
+	size_t size;
+	Common::File *patchFile;
 };
 
-struct RSCFILE_CONTEXT {
-	const char *rc_file_fspec;
-	Common::File *rc_file;
-	int rc_file_loaded;
-	RSCFILE_RESOURCE *rc_res_table;
-	size_t rc_res_ct;
+struct ResourceContext {
+	const char *fileName;
+	uint16 fileType;
+	Common::File *file;
+
+	bool isBigEndian;
+	ResourceData *table;
+	size_t count;
+
+	Common::File *getFile(ResourceData *resourceData) const {
+		if (resourceData->patchFile != NULL) {
+			return resourceData->patchFile;
+		} else {
+			return file;
+		}
+	}
 };
 
-int RSC_LoadRSC(RSCFILE_CONTEXT *rsc_context);
-int RSC_FreeRSC(RSCFILE_CONTEXT *rsc);
+class Resource {
+public:
+	Resource(SagaEngine *vm);
+	~Resource();
+	bool createContexts();
+	void clearContexts();
+	void loadResource(ResourceContext *context, uint32 resourceId, byte*&resourceBuffer, size_t &resourceSize);
+	size_t getResourceSize(ResourceContext *context, uint32 resourceId);
+	uint32 convertResourceId(uint32 resourceId);
+
+	ResourceContext *getContext(uint16 fileType) {
+		int i;
+		for (i = 0; i < _contextsCount; i++) {
+			if (_contexts[i].fileType & fileType) {
+				return &_contexts[i];
+			}
+		}
+		return NULL;
+	}
+
+	bool validResourceId(ResourceContext *context, uint32 resourceId) const {
+		return (resourceId < context->count);
+	}
+
+	size_t getResourceSize(ResourceContext *context, uint32 resourceId) const {
+		return getResourceData(context, resourceId)->size;
+	}
+
+	size_t getResourceOffset(ResourceContext *context, uint32 resourceId) const {
+		return getResourceData(context, resourceId)->offset;
+	}
+
+	ResourceData *getResourceData(ResourceContext *context, uint32 resourceId) const {
+		if (!validResourceId(context, resourceId)) {
+			error("Resource::getResourceData() wrong resourceId %d", resourceId);
+		}
+		return &context->table[resourceId];
+	}
+
+private:
+	SagaEngine *_vm;
+	ResourceContext *_contexts;
+	int _contextsCount;
+	
+	bool loadContext(ResourceContext *context);
+
+};
 
 } // End of namespace Saga
 

Index: saga.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saga.cpp,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- saga.cpp	13 Jul 2005 12:48:35 -0000	1.120
+++ saga.cpp	19 Jul 2005 19:05:47 -0000	1.121
@@ -34,8 +34,8 @@
 
 #include "saga/saga.h"
 
+#include "saga/rscfile.h"
 #include "saga/gfx.h"
-#include "saga/rscfile_mod.h"
 #include "saga/render.h"
 #include "saga/actor.h"
 #include "saga/animation.h"
@@ -53,6 +53,7 @@
 #include "saga/music.h"
 #include "saga/palanim.h"
 #include "saga/objectmap.h"
+#include "saga/resnames.h"
 
 static const GameSettings saga_games[] = {
 	{"ite", "Inherit the Earth", 0},
@@ -114,8 +115,6 @@
 
 #define MAX_TIME_DELTA 100
 
-SagaEngine *_vm = NULL;
-
 SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
 	: Engine(syst),
 	_targetName(detector->_targetName) {
@@ -123,9 +122,9 @@
 	_leftMouseButtonPressed = _rightMouseButtonPressed = false;
 
 	_console = NULL;
-	_gameFileContexts = NULL;
 	_quit = false;
 
+	_resource = NULL;
 	_sndRes = NULL;
 	_events = NULL;
 	_font = NULL;
@@ -166,13 +165,13 @@
 	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
 
 	_displayClip.left = _displayClip.top = 0;
-	_vm = this;
 }
 
 SagaEngine::~SagaEngine() {
-	int i;
-	if (_scene->isSceneLoaded()) {
-		_scene->endScene();
+	if (_scene != NULL) {
+		if (_scene->isSceneLoaded()) {
+			_scene->endScene();
+		}
 	}
 
 	delete _puzzle;
@@ -193,12 +192,7 @@
 	delete _gfx;
 	delete _console;
 
-	if (_gameFileContexts != NULL) {
-		for (i = 0; i < _gameDescription->filesCount; i++) {
-			RSC_DestroyContext(_gameFileContexts[i]);
-		}
-	}
-	free(_gameFileContexts);
+	delete _resource;
 }
 
 void SagaEngine::errorString(const char *buf1, char *buf2) {
@@ -209,6 +203,8 @@
 	_soundEnabled = 1;
 	_musicEnabled = 1;
 
+	_resource = new Resource(this);
+
 	// Add some default directories
 	// Win32 demo & full game
 	Common::File::addDefaultDirectory("graphics");
@@ -224,7 +220,7 @@
 	// Process command line
 
 	// Detect game and open resource files
-	if (initGame() != SUCCESS) {
+	if (!initGame()) {
 		return FAILURE;
 	}
 
@@ -242,17 +238,12 @@
 	_isoMap = new IsoMap(this);
 	_puzzle = new Puzzle(this);
 
-	if (!_scene->initialized()) {
-		warning("Couldn't initialize scene module");
-		return FAILURE;
-	}
-
 	// System initialization
 
 	_previousTicks = _system->getMillis();
 
 	// Initialize graphics
-	_gfx = new Gfx(_system, getDisplayWidth(), getDisplayHeight(), detector);
+	_gfx = new Gfx(this, _system, getDisplayWidth(), getDisplayHeight(), detector);
 
 	// Graphics driver should be initialized before console
 	_console = new Console(this);
@@ -270,7 +261,7 @@
 	} else if (native_mt32)
 		driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
 
-	_music = new Music(_mixer, driver, _musicEnabled);
+	_music = new Music(this, _mixer, driver, _musicEnabled);
 	_music->setNativeMT32(native_mt32);
 	_music->setAdlib(adlib);
 
@@ -368,11 +359,15 @@
 	size_t offset;
 	int i;
 	
+	if (stringsLength == 0) {
+		error("SagaEngine::loadStrings() Error loading strings list resource");
+	}
+
 	stringsTable.stringsPointer = (byte*)malloc(stringsLength);
 	memcpy(stringsTable.stringsPointer, stringsPointer, stringsLength);
 
 	
-	MemoryReadStreamEndian scriptS(stringsTable.stringsPointer, stringsLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian scriptS(stringsTable.stringsPointer, stringsLength, isBigEndian()); //TODO: get endianess from context
 
 	offset = scriptS.readUint16();
 	stringsCount = offset / 2;

Index: saga.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saga.h,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- saga.h	14 Jul 2005 17:46:21 -0000	1.106
+++ saga.h	19 Jul 2005 19:05:48 -0000	1.107
@@ -55,9 +55,13 @@
 class Events;
 class PalAnim;
 class Puzzle;
+class Resource;
 
-#define MIN_IMG_RLECODE    3
-#define MODEX_SCANLINE_LIMIT 200
+struct ResourceContext;
+struct StringList;
+
+//#define MIN_IMG_RLECODE    3
+//#define MODEX_SCANLINE_LIMIT 200 //TODO: remove
 
 #define SAGA_IMAGE_DATA_OFFSET 776
 #define SAGA_IMAGE_HEADER_LEN  8
@@ -68,9 +72,6 @@
 #define MAX_SAVES 96
 #define MAX_FILE_NAME 256
 
-
-#define IS_BIG_ENDIAN ((_vm->getFeatures() & GF_BIG_ENDIAN_DATA) != 0)
-
 #define ID_NOTHING 0
 #define ID_PROTAG 1
 #define OBJECT_TYPE_SHIFT 13
@@ -80,9 +81,6 @@
 
 #define memoryError(Place) error("%s Memory allocation error.", Place)
 
-struct RSCFILE_CONTEXT;
-struct StringList;
-
 enum ERRORCODE {
 	MEM = -2,//todo: remove
 	FAILURE = -1,
@@ -326,10 +324,10 @@
 };
 
 struct GameSoundInfo {
-	int res_type;
-	long freq;
-	int sample_size;
-	int stereo;
+	GameSoundTypes resourceType;
+	long frequency;
+	int sampleBits;
+	bool stereo;
 };
 
 struct GameFontDescription {
@@ -354,6 +352,12 @@
 	uint16 fileType;
 };
 
+struct GamePatchDescription {
+	const char *fileName;
+	uint16 fileType;
+	uint32 resourceId;
+};
+
 struct PanelButton {
 	PanelButtonType type;
 	int xOffset;
@@ -463,6 +467,8 @@
 	int fontsCount;
 	GameFontDescription *fontDescriptions;
 	GameSoundInfo *soundInfo;
+	int patchsCount;
+	GamePatchDescription *patchDescriptions;
 	uint32 features;
 
 	GameSettings toGameSettings() const {
@@ -569,6 +575,7 @@
 	Events *_events;
 	PalAnim *_palanim;
 	Puzzle *_puzzle;
+	Resource *_resource;
 
 
 	/** Random number generator */
@@ -619,7 +626,6 @@
 	bool _rightMouseButtonPressed;
 
 	bool _quit;
-	RSCFILE_CONTEXT **_gameFileContexts;
 
 //current game description
 	int _gameNumber;
@@ -628,10 +634,13 @@
 	Common::Rect _displayClip;
 
 public:
-	int initGame(void);
-	RSCFILE_CONTEXT *getFileContext(uint16 type, int param);
-	bool isBigEndianFile(const char *filename);
+	bool initGame(void);
+//	RSCFILE_CONTEXT *getFileContext(uint16 type, int param);
+//	bool isBigEndianFile(const char *filename);
 public:
+	const GameDescription *getGameDescription() const { return _gameDescription; }
+	const bool isBigEndian() const { return (_gameDescription->features & GF_BIG_ENDIAN_DATA) != 0; }
+	const bool isMacResources() const { return (_gameDescription->features & GF_MAC_RESOURCES) != 0; }
 	const GameResourceDescription *getResourceDescription() { return _gameDescription->resourceDescription; }
 	const GameSoundInfo *getSoundInfo() { return _gameDescription->soundInfo; }
 
@@ -656,12 +665,8 @@
 	
 	const char *getTextString(int textStringId);
 	void getExcuseInfo(int verb, const char *&textString, int &soundResourceId);
-private:
-	int loadGame(int gameNumber);
 };
 
-// FIXME: Global var. We use it until everything will be turned into objects
-extern SagaEngine *_vm;
 
 } // End of namespace Saga
 

Index: scene.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/scene.cpp,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- scene.cpp	14 Jul 2005 17:46:21 -0000	1.121
+++ scene.cpp	19 Jul 2005 19:05:48 -0000	1.122
@@ -34,7 +34,6 @@
 #include "saga/palanim.h"
 #include "saga/puzzle.h"
 #include "saga/render.h"
-#include "saga/rscfile_mod.h"
 #include "saga/script.h"
 #include "saga/sound.h"
 #include "saga/music.h"
@@ -42,6 +41,8 @@
 #include "saga/scene.h"
 #include "saga/stream.h"
 #include "saga/actor.h"
+#include "saga/rscfile.h"
+#include "saga/resnames.h"
 
 namespace Saga {
 
@@ -49,46 +50,41 @@
 0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 
 };
 
-Scene::Scene(SagaEngine *vm) : _vm(vm), _initialized(false) {
-	byte *scene_lut_p;
-	size_t scene_lut_len;
-	int result;
+Scene::Scene(SagaEngine *vm) : _vm(vm) {
+	byte *sceneLUTPointer;
+	size_t sceneLUTLength;
+	uint32 resourceId;
 	int i;
 
 
 	// Load scene module resource context
-	_sceneContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
+	_sceneContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
 	if (_sceneContext == NULL) {
-		warning("Scene::Scene(): Couldn't load scene resource context");
-		return;
+		error("Scene::Scene() scene context not found");
 	}
 
 
 	// Load scene lookup table
-	debug(3, "Loading scene LUT from resource %u.", RSC_ConvertID(_vm->getResourceDescription()->sceneLUTResourceId));
-	result = RSC_LoadResource(_sceneContext, RSC_ConvertID(_vm->getResourceDescription()->sceneLUTResourceId), &scene_lut_p, &scene_lut_len);
-	if (result != SUCCESS) {
-		warning("Scene::Scene(): Error: couldn't load scene LUT");
-		return;
-	}
-	if (scene_lut_len==0) {
-		warning("Scene::Scene(): scene_lut_len==0");
-		return;
+	resourceId = _vm->_resource->convertResourceId(_vm->getResourceDescription()->sceneLUTResourceId);
+	debug(3, "Loading scene LUT from resource %i", resourceId);
+	_vm->_resource->loadResource(_sceneContext, resourceId, sceneLUTPointer, sceneLUTLength);
+	if (sceneLUTLength == 0) {
+		error("Scene::Scene() sceneLUTLength == 0");
 	}
-	_sceneCount = scene_lut_len / 2;
+	_sceneCount = sceneLUTLength / 2;
 	_sceneLUT = (int *)malloc(_sceneCount * sizeof(*_sceneLUT));
 	if (_sceneLUT == NULL) {
 		memoryError("Scene::Scene()");
 	}
 
-	MemoryReadStreamEndian readS(scene_lut_p, scene_lut_len, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(sceneLUTPointer, sceneLUTLength, _sceneContext->isBigEndian);
 
 	for (i = 0; i < _sceneCount; i++) {
 		_sceneLUT[i] = readS.readUint16();
 		debug(8, "sceneNumber %i has resourceId %i", i, _sceneLUT[i]);
 	}
 
-	free(scene_lut_p);
+	free(sceneLUTPointer);
 
 	_firstScene = _vm->getStartSceneNumber();
 
@@ -102,22 +98,19 @@
 	_inGame = false;
 	_loadDescription = false;
 	memset(&_sceneDescription, 0, sizeof(_sceneDescription));
-	_resListEntries = 0;
-	_resList = NULL;
+	_resourceListCount = 0;
+	_resourceList = NULL;
 	_sceneProc = NULL;
 	_objectMap = new ObjectMap(_vm);
 	_actionMap = new ObjectMap(_vm);
 	memset(&_bg, 0, sizeof(_bg));
 	memset(&_bgMask, 0, sizeof(_bgMask));
-
-	_initialized = true;
 }
 
 Scene::~Scene() {
-	if (_initialized) {
-		delete _actionMap;
-		free(_sceneLUT);
-	}
+	delete _actionMap;
+	delete _objectMap;
+	free(_sceneLUT);
 }
 
 void Scene::drawTextList(Surface *ds) {
@@ -125,8 +118,13 @@
 
 	for (TextList::iterator textIterator = _textList.begin(); textIterator != _textList.end(); ++textIterator) {
 		entry = (TextListEntry *)textIterator.operator->();
-		if (entry->display != 0) {
-			_vm->_font->textDraw(entry->fontId, ds, entry->text, entry->point, entry->color, entry->effectColor, entry->flags);
+		if (entry->display) {
+
+			if (entry->useRect) {
+				_vm->_font->textDrawRect(entry->fontId, ds, entry->text, entry->rect, entry->color, entry->effectColor, entry->flags);
+			} else {
+				_vm->_font->textDraw(entry->fontId, ds, entry->text, entry->point, entry->color, entry->effectColor, entry->flags);
+			}			
 		}
 	}
 }
@@ -212,8 +210,6 @@
 	LoadSceneParams *sceneQueue = NULL;
 	LoadSceneParams *skipQueue = NULL;
 
-	assert(_initialized);
-
 	if (!_sceneLoaded) {
 		error("Scene::skip(): Error: Can't skip scene...no scene loaded");
 	}
@@ -287,13 +283,6 @@
 	bgInfo.bounds.setHeight(_bg.h);
 }
 
-int Scene::getBGPal(PalEntry **pal) {
-	assert(_initialized);
-	*pal = _bg.pal;
-
-	return SUCCESS;
-}
-
 int Scene::getBGMaskType(const Point &testPoint) {
 	uint offset;
 	if (!_bgMask.loaded) {
@@ -382,8 +371,7 @@
 }
 
 void Scene::loadScene(LoadSceneParams *loadSceneParams) {
-	int result;
-	int i;
+	size_t i;
 	EVENT event;
 	EVENT *q_event;
 	static PalEntry current_pal[PAL_ENTRIES];
@@ -407,11 +395,11 @@
 		_sceneNumber = -1;
 		_sceneResourceId = -1;
 		assert(loadSceneParams->sceneDescription != NULL);
-		assert(loadSceneParams->sceneDescription->resList != NULL);
+		assert(loadSceneParams->sceneDescription->resourceList != NULL);
 		_loadDescription = false;
 		_sceneDescription = *loadSceneParams->sceneDescription;
-		_resList = loadSceneParams->sceneDescription->resList;
-		_resListEntries = loadSceneParams->sceneDescription->resListCnt;
+		_resourceList = loadSceneParams->sceneDescription->resourceList;
+		_resourceListCount = loadSceneParams->sceneDescription->resourceListCount;
 		break;
 	}
 	
@@ -419,32 +407,25 @@
 
 	// Load scene descriptor and resource list resources
 	if (_loadDescription) {
-		debug(3, "Loading scene resource %u:", _sceneResourceId);
+		debug(3, "Loading scene resource %i", _sceneResourceId);
 
-		if (loadSceneDescriptor(_sceneResourceId) != SUCCESS) {
-			error("Scene::loadScene(): Error reading scene descriptor");
-		}
+		loadSceneDescriptor(_sceneResourceId);
 
-		if (loadSceneResourceList(_sceneDescription.resListRN) != SUCCESS) {
-			error("Scene::loadScene(): Error reading scene resource list");
-		}
+		loadSceneResourceList(_sceneDescription.resourceListResourceId);
 	} else {
-		debug(3, "Loading memory scene resource.");
+		debug(3, "Loading memory scene resource");
 	}
 
 	// Load resources from scene resource list
-	for (i = 0; i < _resListEntries; i++) {
-		result = RSC_LoadResource(_sceneContext, _resList[i].res_number,
-								&_resList[i].res_data, &_resList[i].res_data_len);
-		if (result != SUCCESS) {
-			error("Scene::loadScene(): Error: Allocation failure loading scene resource list");
+	for (i = 0; i < _resourceListCount; i++) {
+		if (!_resourceList[i].invalid) {
+			_vm->_resource->loadResource(_sceneContext, _resourceList[i].resourceId,
+				_resourceList[i].buffer, _resourceList[i].size);
 		}
 	}
 
 	// Process resources from scene resource list
-	if (processSceneResources() != SUCCESS) {
-		error("Scene::loadScene(): Error loading scene resources");
-	}
+	processSceneResources();
 
 	if (_sceneDescription.flags & kSceneFlagISO) {
 		_outsetSceneNumber = _sceneNumber;
@@ -565,10 +546,10 @@
 		_vm->_sound->stopVoice();
 		_vm->_sound->stopSound();
 
-		if (_sceneDescription.musicRN >= 0) {
+		if (_sceneDescription.musicResourceId >= 0) {
 			event.type = ONESHOT_EVENT;
 			event.code = MUSIC_EVENT;
-			event.param = _sceneDescription.musicRN;
+			event.param = _sceneDescription.musicResourceId;
 			event.param2 = MUSIC_DEFAULT;
 			event.op = EVENT_PLAY;
 			event.time = 0;
@@ -653,85 +634,76 @@
 
 }
 
-int Scene::loadSceneDescriptor(uint32 res_number) {
-	byte *scene_desc_data;
-	size_t scene_desc_len;
-	int result;
+void Scene::loadSceneDescriptor(uint32 resourceId) {
+	byte *sceneDescriptorData;
+	size_t sceneDescriptorDataLength;
 
-	result = RSC_LoadResource(_sceneContext, res_number, &scene_desc_data, &scene_desc_len);
-	if (result != SUCCESS) {
-		warning("Scene::loadSceneDescriptor(): Error: couldn't load scene descriptor");
-		return FAILURE;
-	}
+	_vm->_resource->loadResource(_sceneContext, resourceId, sceneDescriptorData, sceneDescriptorDataLength);
 
-	MemoryReadStreamEndian readS(scene_desc_data, scene_desc_len, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(sceneDescriptorData, sceneDescriptorDataLength, _sceneContext->isBigEndian);
 
 	_sceneDescription.flags = readS.readSint16();
-	_sceneDescription.resListRN = readS.readSint16();
+	_sceneDescription.resourceListResourceId = readS.readSint16();
 	_sceneDescription.endSlope = readS.readSint16();
 	_sceneDescription.beginSlope = readS.readSint16();
 	_sceneDescription.scriptModuleNumber = readS.readUint16();
 	_sceneDescription.sceneScriptEntrypointNumber = readS.readUint16();
 	_sceneDescription.startScriptEntrypointNumber = readS.readUint16();
-	_sceneDescription.musicRN = readS.readSint16();
-
-	RSC_FreeResource(scene_desc_data);
+	_sceneDescription.musicResourceId = readS.readSint16();
 
-	return SUCCESS;
+	free(sceneDescriptorData);
 }
 
-int Scene::loadSceneResourceList(uint32 reslist_rn) {
-	byte *resource_list;
-	size_t resource_list_len;
-	int result;
-	int i;
+void Scene::loadSceneResourceList(uint32 resourceId) {
+	byte *resourceListData;
+	size_t resourceListDataLength;
+	size_t i;
 
 	// Load the scene resource table
-	result = RSC_LoadResource(_sceneContext, reslist_rn, &resource_list, &resource_list_len);
-	if (result != SUCCESS) {
-		warning("Scene::loadSceneResourceList(): Error: couldn't load scene resource list");
-		return FAILURE;
-	}
+	_vm->_resource->loadResource(_sceneContext, resourceId, resourceListData, resourceListDataLength);
 
-	MemoryReadStreamEndian readS(resource_list, resource_list_len, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourceListData, resourceListDataLength, _sceneContext->isBigEndian);
 
 	// Allocate memory for scene resource list 
-	_resListEntries = resource_list_len / SAGA_RESLIST_ENTRY_LEN;
-	debug(3, "Scene resource list contains %d entries.", _resListEntries);
-	_resList = (SCENE_RESLIST *)calloc(_resListEntries, sizeof(*_resList));
-
-	if (_resList == NULL) {
-		memoryError("Scene::loadSceneResourceList()");
-	}
+	_resourceListCount = resourceListDataLength / SAGA_RESLIST_ENTRY_LEN;
+	debug(3, "Scene resource list contains %i entries", _resourceListCount);
+	_resourceList = (SceneResourceData *)calloc(_resourceListCount, sizeof(*_resourceList));
 
 	// Load scene resource list from raw scene 
 	// resource table
-	debug(3, "Loading scene resource list...");
+	debug(3, "Loading scene resource list");
 
-	for (i = 0; i < _resListEntries; i++) {
-		_resList[i].res_number = readS.readUint16();
-		_resList[i].res_type = readS.readUint16();
+	for (i = 0; i < _resourceListCount; i++) {
+		_resourceList[i].resourceId = readS.readUint16();
+		_resourceList[i].reourceType = readS.readUint16();
+		// demo version may contain invalid resourceId
+		_resourceList[i].invalid = !_vm->_resource->validResourceId(_sceneContext, _resourceList[i].resourceId);
 	}
 
-	RSC_FreeResource(resource_list);
-
-	return SUCCESS;
+	free(resourceListData);
 }
 
-int Scene::processSceneResources() {
+void Scene::processSceneResources() {
 	byte *resourceData;
 	uint16 resourceDataLength;
-	const byte *pal_p;
-	int i;
+	const byte *palPointer;
+	size_t i;
 
 	// Process the scene resource list
-	for (i = 0; i < _resListEntries; i++) {
-		resourceData = _resList[i].res_data;
-		resourceDataLength = _resList[i].res_data_len;
-		switch (_resList[i].res_type) {
+	for (i = 0; i < _resourceListCount; i++) {
+		if (_resourceList[i].invalid) {
+			continue;
+		}
+		resourceData = _resourceList[i].buffer;
+		resourceDataLength = _resourceList[i].size;
+		switch (_resourceList[i].reourceType) {
+		case SAGA_ACTOR:
+			break;
+		case SAGA_OBJECT:
+			break;
 		case SAGA_BG_IMAGE: // Scene background resource
 			if (_bg.loaded) {
-				error("Scene::processSceneResources(): Multiple background resources encountered");
+				error("Scene::processSceneResources() Multiple background resources encountered");
 			}
 
 			debug(3, "Loading background resource.");
@@ -745,12 +717,11 @@
 				&_bg.buf_len,
 				&_bg.w,
 				&_bg.h) != SUCCESS) {
-				warning("Scene::ProcessSceneResources(): Error loading background resource: %u", _resList[i].res_number);
-				return FAILURE;
+				error("Scene::processSceneResources() Error loading background resource %i", _resourceList[i].resourceId);
 			}
 
-			pal_p = _vm->getImagePal(_bg.res_buf, _bg.res_len);
-			memcpy(_bg.pal, pal_p, sizeof(_bg.pal));
+			palPointer = _vm->getImagePal(_bg.res_buf, _bg.res_len);
+			memcpy(_bg.pal, palPointer, sizeof(_bg.pal));
 			break;
 		case SAGA_BG_MASK: // Scene background mask resource
 			if (_bgMask.loaded) {
@@ -826,7 +797,7 @@
 		case SAGA_ANIM_6:
 		case SAGA_ANIM_7:
 			{
-				uint16 animId = _resList[i].res_type - SAGA_ANIM_1;
+				uint16 animId = _resourceList[i].reourceType - SAGA_ANIM_1;
 
 				debug(3, "Loading animation resource animId=%i", animId);
 
@@ -851,7 +822,7 @@
 			loadSceneEntryList(resourceData, resourceDataLength);
 			break;
 		case SAGA_FACES:
-			_vm->_interface->loadScenePortraits(_resList[i].res_number);
+			_vm->_interface->loadScenePortraits(_resourceList[i].resourceId);
 			break;
 		case SAGA_PALETTE:
 			{
@@ -859,7 +830,7 @@
 				byte *palPtr = resourceData;
 
 				if (resourceDataLength < 3 * PAL_ENTRIES)
-					error("Too small scene palette: %d", resourceDataLength);
+					error("Too small scene palette %i", resourceDataLength);
 
 				for (uint16 c = 0; c < PAL_ENTRIES; c++) {
 					pal[c].red = *palPtr++;
@@ -870,11 +841,10 @@
 			}
 			break;
 		default:
-			warning("Scene::ProcessSceneResources(): Encountered unknown resource type: %d", _resList[i].res_type);
+			error("Scene::ProcessSceneResources() Encountered unknown resource type %i", _resourceList[i].reourceType);
 			break;
 		}
 	}
-	return SUCCESS;
 }
 
 void Scene::draw() {
@@ -902,7 +872,7 @@
 	Surface *backBuffer;
 	Surface *backGroundSurface;
 	Rect rect;
-	int i;
+	size_t i;
 
 	if (!_sceneLoaded)
 		return;
@@ -936,12 +906,12 @@
 	}
 
 	// Free scene resource list
-	for (i = 0; i < _resListEntries; i++) {
-		RSC_FreeResource(_resList[i].res_data);
+	for (i = 0; i < _resourceListCount; i++) {
+		free(_resourceList[i].buffer);
 	}
 
 	if (_loadDescription) {
-		free(_resList);
+		free(_resourceList);
 	}
 
 	// Free animation info list
@@ -977,23 +947,6 @@
 	changeScene(scene_num, 0, kTransitionNoFade);
 }
 
-void Scene::cmdSceneInfo() {
-	const char *fmt = "%-20s %d\n";
-
-	_vm->_console->DebugPrintf(fmt, "Scene number:", _sceneNumber);
-	_vm->_console->DebugPrintf(fmt, "Descriptor ResourceId:", _sceneResourceId);
-	_vm->_console->DebugPrintf("-------------------------\n");
-	_vm->_console->DebugPrintf(fmt, "Flags:", _sceneDescription.flags);
-	_vm->_console->DebugPrintf(fmt, "Resource list R#:", _sceneDescription.resListRN);
-	_vm->_console->DebugPrintf(fmt, "End slope:", _sceneDescription.endSlope);
-	_vm->_console->DebugPrintf(fmt, "Begin slope:", _sceneDescription.beginSlope);
-	_vm->_console->DebugPrintf(fmt, "scriptModuleNumber:", _sceneDescription.scriptModuleNumber);
-	_vm->_console->DebugPrintf(fmt, "sceneScriptEntrypointNumber:", _sceneDescription.sceneScriptEntrypointNumber);
-	_vm->_console->DebugPrintf(fmt, "startScriptEntrypointNumber:", _sceneDescription.startScriptEntrypointNumber);
-	_vm->_console->DebugPrintf(fmt, "Music R#", _sceneDescription.musicRN);
-}
-
-
 void Scene::cmdActionMapInfo() {
 	_actionMap->cmdInfo();
 }
@@ -1008,7 +961,7 @@
 	
 	_entryList.entryListCount = resourceLength / 8;
 
-	MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(resourcePointer, resourceLength, _sceneContext->isBigEndian);
 
 
 	if (_entryList.entryList)

Index: scene.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/scene.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- scene.h	14 Jul 2005 17:46:21 -0000	1.62
+++ scene.h	19 Jul 2005 19:05:48 -0000	1.63
@@ -59,6 +59,8 @@
 
 // Resource type numbers
 enum SAGAResourceTypes {
+	SAGA_ACTOR = 0,
+	SAGA_OBJECT = 1,
 	SAGA_BG_IMAGE = 2,
 	SAGA_BG_MASK = 3,
 	SAGA_STRINGS = 5,
@@ -84,26 +86,27 @@
 
 #define SAGA_RESLIST_ENTRY_LEN 4
 
-struct SCENE_RESLIST {
-	uint32 res_number;
-	int res_type;
-	byte *res_data;
-	size_t res_data_len;
+struct SceneResourceData {
+	uint32 resourceId;
+	int reourceType;
+	byte *buffer;
+	size_t size;
+	bool invalid;
 };
 
 #define SAGA_SCENE_DESC_LEN 16
 
 struct SceneDescription {
 	int16 flags;
-	int16 resListRN;
+	int16 resourceListResourceId;
 	int16 endSlope;
 	int16 beginSlope;
 	uint16 scriptModuleNumber;
 	uint16 sceneScriptEntrypointNumber;
 	uint16 startScriptEntrypointNumber;
-	int16 musicRN;
-	SCENE_RESLIST *resList;
-	size_t resListCnt;
+	int16 musicResourceId;
+	SceneResourceData *resourceList;
+	size_t resourceListCount;
 };
 
 struct SceneEntry {
@@ -209,7 +212,6 @@
 	~Scene();
 
 // Console functions
-	void cmdSceneInfo();
 	void cmdActionMapInfo();
 	void cmdObjectMapInfo();
 
@@ -241,7 +243,10 @@
 	void initDoorsState();
 
 	void getBGInfo(BGInfo &bgInfo);
-	int getBGPal(PalEntry **pal);
+	void getBGPal(PalEntry *&pal) const {
+		pal = (PalEntry *)_bg.pal;
+	}
+
 	void getSlopes(int &beginSlope, int &endSlope);
 
 	void clearSceneQueue(void) {
@@ -249,7 +254,6 @@
 	}
 	void changeScene(uint16 sceneNumber, int actorsEntrance, SceneTransitionType transitionType);
 
-	bool initialized() const { return _initialized; }
 	bool isSceneLoaded() const { return _sceneLoaded; }
 
 
@@ -266,16 +270,15 @@
 	void drawTextList(Surface *ds);
  private:
 	void loadScene(LoadSceneParams *loadSceneParams);
-	int loadSceneDescriptor(uint32 res_number);
-	int loadSceneResourceList(uint32 res_number);
+	void loadSceneDescriptor(uint32 resourceId);
+	void loadSceneResourceList(uint32 resourceId);
 	void loadSceneEntryList(const byte* resourcePointer, size_t resourceLength);
-	int processSceneResources();
+	void processSceneResources();
 
  
 	SagaEngine *_vm;
-	bool _initialized;
 
-	RSCFILE_CONTEXT *_sceneContext;
+	ResourceContext *_sceneContext;
 	int *_sceneLUT;
 	int _sceneCount;
 	SceneQueueList _sceneQueue;
@@ -287,8 +290,8 @@
 	bool _inGame;
 	bool _loadDescription;
 	SceneDescription _sceneDescription;
-	int _resListEntries;
-	SCENE_RESLIST *_resList;
+	size_t _resourceListCount;
+	SceneResourceData *_resourceList;
 	SceneProc *_sceneProc;
 	SceneImage _bg;
 	SceneImage _bgMask;

Index: script.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- script.cpp	5 Jul 2005 16:58:36 -0000	1.70
+++ script.cpp	19 Jul 2005 19:05:49 -0000	1.71
@@ -25,7 +25,6 @@
 #include "saga/saga.h"
 
 #include "saga/gfx.h"
-#include "saga/rscfile_mod.h"
 #include "saga/console.h"
 
 #include "saga/script.h"
@@ -37,25 +36,22 @@
 #include "saga/actor.h"
 #include "saga/objectmap.h"
 #include "saga/isomap.h"
+#include "saga/rscfile.h"
 
 namespace Saga {
 
 // Initializes the scripting module.
 // Loads script resource look-up table, initializes script data system
-Script::Script(SagaEngine *vm) : _vm(vm){
-	RSCFILE_CONTEXT *resourceContext;
+Script::Script(SagaEngine *vm) : _vm(vm) {
+	ResourceContext *resourceContext;
 	byte *resourcePointer;
 	size_t resourceLength;
 	int prevTell;
-	int result;
 	int i, j;
 	byte *stringsPointer;
 	size_t stringsLength;
 
 	//initialize member variables
-	_dbg_thread = 0;
-	_dbg_singlestep = 0;
-	_scriptContext = 0;
 	_voiceLUTPresent = false;
 
 	_abortEnabled = true;
@@ -78,21 +74,19 @@
 	
 	debug(8, "Initializing scripting subsystem");
 	// Load script resource file context
-	_scriptContext = _vm->getFileContext(GAME_SCRIPTFILE, 0);
+	_scriptContext = _vm->_resource->getContext(GAME_SCRIPTFILE);
 	if (_scriptContext == NULL) {
-		error("Script::Script() Couldn't get script file context");
+		error("Script::Script() script context not found");
 	}
 
-	resourceContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
+	resourceContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
 	if (resourceContext == NULL) {
-		error("Script::Script() Couldn't get resource file context");
+		error("Script::Script() resource context not found");
 	}
 
-	debug(3, "Loading module LUT from resource %u.", _vm->getResourceDescription()->moduleLUTResourceId);
-	result = RSC_LoadResource(resourceContext, _vm->getResourceDescription()->moduleLUTResourceId, &resourcePointer, &resourceLength);
-	if (result != SUCCESS) {
-		error("Script::Script() Couldn't load module LUT resource");
-	}
+	debug(3, "Loading module LUT from resource %i", _vm->getResourceDescription()->moduleLUTResourceId);
+	_vm->_resource->loadResource(resourceContext, _vm->getResourceDescription()->moduleLUTResourceId, resourcePointer, resourceLength);
+	
 
 	// Create logical script LUT from resource
 	if (resourceLength % S_LUT_ENTRYLEN_ITECD == 0) {
@@ -100,13 +94,13 @@
 	} else if (resourceLength % S_LUT_ENTRYLEN_ITEDISK == 0) {
 		_modulesLUTEntryLen = S_LUT_ENTRYLEN_ITEDISK;
 	} else {
-		error("Script::Script() Invalid script lookup table length (%d)", resourceLength);
+		error("Script::Script() Invalid script lookup table length (%i)", resourceLength);
 	}
 
 	// Calculate number of entries
 	_modulesCount = resourceLength / _modulesLUTEntryLen;
 
-	debug(3, "LUT has %d entries.", _modulesCount);
+	debug(3, "LUT has %i entries", _modulesCount);
 	
 	// Allocate space for logical LUT
 	_modules = (ModuleData *)malloc(_modulesCount * sizeof(*_modules));
@@ -115,7 +109,7 @@
 	}
 
 	// Convert LUT resource to logical LUT
-	MemoryReadStreamEndian scriptS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian scriptS(resourcePointer, resourceLength, resourceContext->isBigEndian);
 	for (i = 0; i < _modulesCount; i++) {
 		memset(&_modules[i], 0, sizeof(ModuleData));
 
@@ -136,7 +130,7 @@
 		}
 	}
 
-	RSC_FreeResource(resourcePointer);
+	free(resourcePointer);
 
 	// TODO
 	//
@@ -150,27 +144,17 @@
 	// Or maybe I'm looking at the wrong resource. I found the IHNM one by
 	// trial and error...
 
-	result = RSC_LoadResource(resourceContext, _vm->getResourceDescription()->mainStringsResourceId, &stringsPointer, &stringsLength);
-
-	if ((result != SUCCESS) || (stringsLength == 0)) {
-		error("Error loading strings list resource");
-	}
+	_vm->_resource->loadResource(resourceContext, _vm->getResourceDescription()->mainStringsResourceId, stringsPointer, stringsLength);
 
 	_vm->loadStrings(_mainStrings, stringsPointer, stringsLength);
-	RSC_FreeResource(stringsPointer);
+	free(stringsPointer);
 
 	setupScriptFuncList();
-
-	_initialized = true;
 }
 
 // Shut down script module gracefully; free all allocated module resources
 Script::~Script() {
 
-	if (!_initialized) {
-		error("Script not initialized");
-	}
-
 	debug(8, "Shutting down scripting subsystem.");
 	
 	_mainStrings.freeMem();
@@ -179,14 +163,11 @@
 	free(_modules);
 	
 	free(_commonBuffer);
-
-	_initialized = false;
 }
 
 void Script::loadModule(int scriptModuleNumber) {
 	byte *resourcePointer;
 	size_t resourceLength;
-	int result;
 
 	// Validate script number
 	if ((scriptModuleNumber < 0) || (scriptModuleNumber >= _modulesCount)) {
@@ -200,30 +181,21 @@
 	// Initialize script data structure
 	debug(3, "Loading script module #%d", scriptModuleNumber);
 
-	result = RSC_LoadResource(_scriptContext, _modules[scriptModuleNumber].scriptResourceId, &resourcePointer, &resourceLength);
-	if (result != SUCCESS) {
-		error("Script::loadModule() unable to load module base resource");
-	}
+	_vm->_resource->loadResource(_scriptContext, _modules[scriptModuleNumber].scriptResourceId, resourcePointer, resourceLength);
 
 	loadModuleBase(_modules[scriptModuleNumber], resourcePointer, resourceLength);
-	RSC_FreeResource(resourcePointer);
+	free(resourcePointer);
 
-	result = RSC_LoadResource(_scriptContext, _modules[scriptModuleNumber].stringsResourceId, &resourcePointer, &resourceLength);
-	if ((result != SUCCESS) || (resourceLength == 0)) {
-		error("Script::loadModule() Error loading strings list resource");
-	}
+	_vm->_resource->loadResource(_scriptContext, _modules[scriptModuleNumber].stringsResourceId, resourcePointer, resourceLength);
 
 	_vm->loadStrings(_modules[scriptModuleNumber].strings, resourcePointer, resourceLength);
-	RSC_FreeResource(resourcePointer);
+	free(resourcePointer);
 
 	if (_modules[scriptModuleNumber].voicesResourceId > 0) {
-		result = RSC_LoadResource(_scriptContext, _modules[scriptModuleNumber].voicesResourceId, &resourcePointer, &resourceLength);
-		if (result != SUCCESS) {
-			error("Script::loadModule() Error loading voice LUT resource");
-		}
+		_vm->_resource->loadResource(_scriptContext, _modules[scriptModuleNumber].voicesResourceId, resourcePointer, resourceLength);
 
 		loadModuleVoiceLUT(_modules[scriptModuleNumber], resourcePointer, resourceLength);
-		RSC_FreeResource(resourcePointer);
+		free(resourcePointer);
 	}
 
 	_modules[scriptModuleNumber].staticOffset = _staticSize;
@@ -254,7 +226,7 @@
 
 	memcpy(module.moduleBase, resourcePointer, resourceLength);
 
-	MemoryReadStreamEndian scriptS(module.moduleBase, module.moduleBaseSize, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian scriptS(module.moduleBase, module.moduleBaseSize, _scriptContext->isBigEndian);
 
 	module.entryPointsCount = scriptS.readUint16();
 	scriptS.readUint16(); //skip
@@ -307,60 +279,13 @@
 		error("Script::loadModuleVoiceLUT() not enough memory");
 	}
 
-	MemoryReadStreamEndian scriptS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian scriptS(resourcePointer, resourceLength, _scriptContext->isBigEndian);
 
 	for (i = 0; i < module.voiceLUT.voicesCount; i++) {
 		module.voiceLUT.voices[i] = scriptS.readUint16();
 	}
 }
 
-
-void Script::scriptInfo() {
-/*	uint32 n_entrypoints;
-	uint32 i;
-	char *name_ptr;
-
-	if (currentScript() == NULL) {
-		return;
-	}
-
-	if (!currentScript()->loaded) {
-		return;
-	}
-
-	n_entrypoints = currentScript()->bytecode->n_entrypoints;
-
-	_vm->_console->DebugPrintf("Current script contains %d entrypoints:\n", n_entrypoints);
-
-	for (i = 0; i < n_entrypoints; i++) {
-		name_ptr = (char *)currentScript()->bytecode->bytecode_p +
-							currentScript()->bytecode->entrypoints[i].name_offset;
-		_vm->_console->DebugPrintf("%lu: %s\n", i, name_ptr);
-	}*/
-}
-
-void Script::scriptExec(int argc, const char **argv) {
-/*	uint16 ep_num;
-
-	ep_num = atoi(argv[1]);
-
-	if (_dbg_thread == NULL) {
-		_vm->_console->DebugPrintf("Creating debug thread...\n");
-		_dbg_thread = createThread();
-		if (_dbg_thread == NULL) {
-			_vm->_console->DebugPrintf("Thread creation failed.\n");
-			return;
-		}
-	}
-
-	if (ep_num >= currentScript()->bytecode->n_entrypoints) {
-		_vm->_console->DebugPrintf("Invalid entrypoint.\n");
-		return;
-	}
-
-	executeThread(_dbg_thread, ep_num);*/
-}
-
 // verb
 void Script::showVerb(int statusColor) {
 	const char *verbName;
@@ -818,9 +743,4 @@
 	}
 }
 
-// console wrappers
-void Script::CF_script_togglestep() {
-	_dbg_singlestep = !_dbg_singlestep;
-}
-
 } // End of namespace Saga

Index: script.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.h,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -d -r1.93 -r1.94
--- script.h	14 Jul 2005 17:46:21 -0000	1.93
+++ script.h	19 Jul 2005 19:05:49 -0000	1.94
@@ -346,12 +346,9 @@
 	Script(SagaEngine *vm);
 	~Script();
 	
-	void CF_script_togglestep();
-
 	void loadModule(int scriptModuleNumber);
 	void freeModules();
 
-	bool isInitialized() const { return _initialized;  }
 	bool isVoiceLUTPresent() const { return _voiceLUTPresent; }
 
 	void doVerb();
@@ -377,15 +374,11 @@
 		_currentObject[0] = _currentObject[0] = ID_NOTHING;
 		setPointerVerb();
 	}
-
-	void scriptInfo();
-	void scriptExec(int argc, const char **argv);
 	
 private:
 	SagaEngine *_vm;
-	bool _initialized;
 	bool _voiceLUTPresent;
-	RSCFILE_CONTEXT *_scriptContext;
+	ResourceContext *_scriptContext;
 	
 	uint16 _modulesLUTEntryLen;
 	ModuleData *_modules;
@@ -422,15 +415,10 @@
 	bool _skipSpeeches;
 	bool _abortEnabled;
 
-	int _dbg_singlestep;
-	int _dbg_dostep;
-	ScriptThread *_dbg_thread;
-
 public:
 	ScriptThread *createThread(uint16 scriptModuleNumber, uint16 scriptEntryPointNumber);
 	int executeThread(ScriptThread *thread, int entrypointNumber);
 	void executeThreads(uint msec);
-	int SThreadDebugStep();
 	void completeThread(void);
 	void abortAllThreads(void);
 
@@ -460,7 +448,6 @@
 	const ScriptFunctionDescription *_scriptFunctionsList;
 
 	void setupScriptFuncList(void);
-	int SDebugPrintInstr(ScriptThread *thread);
 
 	void sfPutString(SCRIPTFUNC_PARAMS);
 	void sfWait(SCRIPTFUNC_PARAMS);

Index: sfuncs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sfuncs.cpp,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- sfuncs.cpp	15 Jul 2005 15:23:19 -0000	1.139
+++ sfuncs.cpp	19 Jul 2005 19:05:50 -0000	1.140
@@ -44,6 +44,7 @@
 
 #include "saga/scene.h"
 #include "saga/isomap.h"
+#include "saga/resnames.h"
 
 #include "common/config-manager.h"
 
@@ -1271,7 +1272,7 @@
 
 	q_event = _vm->_events->chain(q_event, &event);
 
-	_vm->_scene->getBGPal(&pal);
+	_vm->_scene->getBGPal(pal);
 
 	event.type = IMMEDIATE_EVENT;
 	event.code = PAL_EVENT;
@@ -1327,7 +1328,7 @@
 
 	q_event = _vm->_events->chain(q_event, &event);
 
-	_vm->_scene->getBGPal(&pal);
+	_vm->_scene->getBGPal(pal);
 
 	event.type = IMMEDIATE_EVENT;
 	event.code = PAL_EVENT;

Index: sndres.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sndres.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- sndres.cpp	5 Jul 2005 16:58:36 -0000	1.44
+++ sndres.cpp	19 Jul 2005 19:05:51 -0000	1.45
@@ -25,8 +25,7 @@
 
 #include "saga/saga.h"
 
-#include "saga/rscfile_mod.h"
-
+#include "saga/rscfile.h"
 #include "saga/sndres.h"
 #include "saga/sound.h"
 #include "saga/stream.h"
@@ -35,276 +34,191 @@
 
 #include "sound/voc.h"
 #include "sound/wave.h"
+#include "sound/adpcm.h"
+#include "sound/audiostream.h"
 
 namespace Saga {
 
 SndRes::SndRes(SagaEngine *vm) : _vm(vm) {
 	/* Load sound module resource file contexts */
-	_sfx_ctxt = _vm->getFileContext(GAME_SOUNDFILE, 0);
-	if (_sfx_ctxt == NULL) {
-		return;
+	_sfxContext = _vm->_resource->getContext(GAME_SOUNDFILE);
+	if (_sfxContext == NULL) {
+		error("SndRes::SndRes resource context not found");
 	}
 
-	_voice_ctxt = _vm->getFileContext(GAME_VOICEFILE, 0);
-	if (_voice_ctxt == NULL) {
-		return;
+	_voiceContext = _vm->_resource->getContext(GAME_VOICEFILE);
+	if (_voiceContext == NULL) {
+		error("SndRes::SndRes resource context not found");
 	}
 
 	// Grab sound resource information for the current game
-	_snd_info = *_vm->getSoundInfo();
-
-	_init = 1;
+	_soundInfo = *_vm->getSoundInfo();
 }
 
-int SndRes::playSound(uint32 sound_rn, int volume, bool loop) {
-	SOUNDBUFFER snd_buffer;
+void SndRes::playSound(uint32 resourceId, int volume, bool loop) {
+	SoundBuffer buffer;
 
-	debug(4, "SndRes::playSound(%ld)", sound_rn);
+	debug(4, "SndRes::playSound %i", resourceId);
 
-	if (load(_sfx_ctxt, sound_rn, &snd_buffer) != SUCCESS) {
+	if (!load(_sfxContext, resourceId, buffer, false)) {
 		warning("Failed to load sound");
-		return FAILURE;
+		return;
 	}
 
-	_vm->_sound->playSound(&snd_buffer, volume, loop);
-
-	return SUCCESS;
+	_vm->_sound->playSound(buffer, volume, loop);
 }
 
-int SndRes::playVoice(uint32 voice_rn) {
-	SOUNDBUFFER snd_buffer;
-	int result = FAILURE;
-	bool voiceFile = false;
-
-	debug(4, "SndRes::playVoice(%ld)", voice_rn);
-
-	if (_vm->getGameType() == GType_ITE && voice_rn == 4) {
-		// The Wyrmkeep release of Inherit the Earth provides a
-		// separate file (p2_a.voc or P2_A.iaf), to correct voice 4 in
-		// the intro. Use that, if available.
-
-		Common::File f;
-		uint32 size;
-		bool voc = false;
-
-		if (f.open("p2_a.voc"))
-			voc = true;
-		else
-			f.open("P2_A.iaf");
-
-		if (f.isOpen()) {
-			size = f.size();
-			byte *snd_res = (byte *)malloc(size);
-			f.read(snd_res, size);
-			f.close();
-
-			if (!voc) {
-				snd_buffer.s_stereo = 0;
-				snd_buffer.s_samplebits = 16;
-				snd_buffer.s_freq = 22050;
-				snd_buffer.s_buf = snd_res;
-				snd_buffer.s_buf_len = size;
-				snd_buffer.s_signed = 1;
-				result = SUCCESS;
-			} else {
-				result = loadVocSound(snd_res, size, &snd_buffer);
-				RSC_FreeResource(snd_res);
-			}
-			voiceFile = true;
-		}
-	}
+void SndRes::playVoice(uint32 resourceId) {
+	SoundBuffer buffer;
 
-	// File is not present. It is DOS CD or Floppy
-	if (result != SUCCESS)
-		result = load(_voice_ctxt, voice_rn, &snd_buffer);
+	debug(4, "SndRes::playVoice %i", resourceId);
 
-	if (result != SUCCESS) {
-		return FAILURE;
+	if (!load(_voiceContext, resourceId, buffer, false)) {
+		warning("Failed to load voice");
+		return;
 	}
 
-	if (_vm->getFeatures() & GF_VOX_VOICES && !voiceFile)
-		_vm->_sound->playVoxVoice(&snd_buffer);
-	else
-		_vm->_sound->playVoice(&snd_buffer);
-
-	return SUCCESS;
+	_vm->_sound->playVoice(buffer);
 }
 
-int SndRes::load(RSCFILE_CONTEXT *snd_ctxt, uint32 snd_rn, SOUNDBUFFER *snd_buf_i) {
-	byte *snd_res;
-	size_t snd_res_len;
+bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buffer, bool onlyHeader) {
+	byte *soundResource;
+	AudioStream *voxStream;
+	size_t soundResourceLength;
+	bool result = false;
+	GameSoundTypes resourceType;
+	byte *data;
+	int rate;
+	int size;
+	byte flags;
+	bool voxPcm;	
+	size_t voxSize;
 
-	int result;
+	if (resourceId == (int32)-1) {
+		return false;
+	}
 
-	assert((snd_ctxt != NULL) && (snd_buf_i != NULL));
+	_vm->_resource->loadResource(context, resourceId, soundResource, soundResourceLength);
 
-	result = RSC_LoadResource(snd_ctxt, snd_rn, &snd_res, &snd_res_len);
-	if (result != SUCCESS) {
-		return FAILURE;
-	}
+	MemoryReadStream readS(soundResource, soundResourceLength);
+
+	//TODO: check soundResource header - game may have GAME_SOUND_PCM, but patch file can be GAME_SOUND_VOC
+	resourceType = _soundInfo.resourceType;
 	
-	switch (_snd_info.res_type) {
+	if (soundResourceLength >= 8) {
+		if (!memcmp(&soundResource, "Creative", 8)) {
+			resourceType = GAME_SOUND_VOC;
+		} else 	if (!memcmp(soundResource, "RIFF", 4) != 0) {
+			resourceType = GAME_SOUND_WAV;
+		}
+	}
+
+	switch (resourceType) {
 	case GAME_SOUND_PCM:
-		snd_buf_i->s_freq = _snd_info.freq;
-		snd_buf_i->s_samplebits = _snd_info.sample_size;
-		snd_buf_i->s_stereo = _snd_info.stereo;
-		snd_buf_i->s_buf = snd_res;
-		snd_buf_i->s_buf_len = snd_res_len;
-		snd_buf_i->s_signed = 1;
+		buffer.frequency = _soundInfo.frequency;
+		buffer.isSigned = true;
+		voxPcm = (_vm->getFeatures() & GF_VOX_VOICES);
+		if (voxPcm) {
+			if (_vm->getGameType() == GType_ITE) {
+				//.iaf is not vox
+				if (_vm->_resource->getResourceData(context, resourceId)->patchFile != NULL) {
+					voxPcm = false;
+				}
+			}
+		}
+		if (voxPcm) {
+			buffer.sampleBits = 16;
+			buffer.stereo = false;
+			buffer.size = soundResourceLength * 4;
+			if (onlyHeader) {
+				buffer.buffer = NULL;
+				free(soundResource);
+			} else {
+				voxStream = makeADPCMStream(readS, soundResourceLength, kADPCMOki);
+				buffer.buffer = (byte *)malloc(buffer.size);
+				voxSize = voxStream->readBuffer((int16*)buffer.buffer, soundResourceLength * 2);
+				if (voxSize != soundResourceLength * 2) {
+					error("SndRes::load() wrong VOX output size");
+				}
+				delete voxStream;
+			}
+		} else {
+			buffer.sampleBits = _soundInfo.sampleBits;
+			buffer.size = soundResourceLength;
+			buffer.stereo = _soundInfo.stereo;
+			if (onlyHeader) {
+				buffer.buffer = NULL;
+				free(soundResource);
+			} else {
+				buffer.buffer = soundResource;
+			}
+		}
+		result = true;
 		break;
 	case GAME_SOUND_VOC:
-		result = loadVocSound(snd_res, snd_res_len, snd_buf_i);
-		RSC_FreeResource(snd_res);
-		if (result != SUCCESS) {
-			return FAILURE;
+		data = loadVOCFromStream(readS, size, rate);
+		if (data) {
+			buffer.frequency = rate;
+			buffer.sampleBits = 8;
+			buffer.stereo = false;
+			buffer.isSigned = false;
+			buffer.size = size;
+			if (onlyHeader) {
+				buffer.buffer = NULL;
+				free(data);
+			} else {
+				buffer.buffer = data;
+			}
+			result = true;
 		}
+		free(soundResource);
 		break;
 	case GAME_SOUND_WAV:
-		result = loadWavSound(snd_res, snd_res_len, snd_buf_i);
-		RSC_FreeResource(snd_res);
-		if (result != SUCCESS) {
-			return FAILURE;
+		if (loadWAVFromStream(readS, size, rate, flags)) {
+			buffer.frequency = rate;
+			buffer.sampleBits = 16;
+			buffer.stereo = ((flags & Audio::Mixer::FLAG_STEREO) != 0);
+			buffer.isSigned = true;
+			buffer.size = size;
+			if (onlyHeader) {
+				buffer.buffer = NULL;
+			} else {
+				buffer.buffer = (byte *)malloc(size);
+				readS.read(buffer.buffer, size);
+			}
+			result = true;
 		}
+		free(soundResource);
 		break;
 	default:
-		/* Unknown sound type */
-		RSC_FreeResource(snd_res);
-		return FAILURE;
-	}
-
-	return SUCCESS;
-}
-
-int SndRes::loadVocSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i) {
-	MemoryReadStreamEndian readS(snd_res, snd_res_len, IS_BIG_ENDIAN);
-	byte *data;
-	int rate;
-	int len;
-
-	data = loadVOCFromStream(readS, len, rate);
-
-	if (!data) {
-		return FAILURE;
-	}
-
-	snd_buf_i->s_freq = rate;
-	snd_buf_i->s_samplebits = 8;
-	snd_buf_i->s_stereo = 0;
-	snd_buf_i->s_signed = 0;
-	snd_buf_i->s_buf = data;
-	snd_buf_i->s_buf_len = len;
-
-	return SUCCESS;
-
-}
-
-int SndRes::loadWavSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i) {
-	Common::MemoryReadStream readS(snd_res, snd_res_len);
-	int rate, size;
-	byte flags;
-
-	if (!loadWAVFromStream(readS, size, rate, flags)) {
-		return FAILURE;
-	}
-
-	snd_buf_i->s_stereo = ((flags & Audio::Mixer::FLAG_STEREO) != 0);
-	snd_buf_i->s_freq = rate;
-	snd_buf_i->s_samplebits = 16;
-	snd_buf_i->s_signed = 1;
-	snd_buf_i->s_buf_len = size;
-
-	byte *data = (byte *)malloc(snd_buf_i->s_buf_len);
-	if (!data) {
-		return FAILURE;
+		error("SndRes::load Unknown sound type");
 	}
 
-	readS.read(data, snd_buf_i->s_buf_len);
-	snd_buf_i->s_buf = data;
-	return SUCCESS;
+	return result;
 }
 
-int SndRes::getVoiceLength(uint32 voice_rn) {
-	int res_type = _snd_info.res_type;
-	uint32 length = 0;
+int SndRes::getVoiceLength(uint32 resourceId) {
 	bool voiceFile = false;
+	double msDouble;
+	SoundBuffer buffer;
 
-	double ms_f;
-	int ms_i = -1;
-
-	int result = FAILURE;
-
-	assert(_init);
-
-	Common::File f;
-
-	// The Wyrmkeep release of Inherit the Earth provides a separate file
-	// (p2_a.voc or P2_A.iaf), to correct voice 4 in the intro. Use that,
-	// if available.
-
-	if (_vm->getGameType() == GType_ITE && voice_rn == 4) {
-		if (f.open("p2_a.voc")) {
-			result = SUCCESS;
-			length = f.size();
-			res_type = GAME_SOUND_VOC;
-			f.close();
-			voiceFile = true;
-		} else if (f.open("P2_A.iaf")) {
-			result = SUCCESS;
-			length = f.size();
-			res_type = GAME_SOUND_PCM;
-			f.close();
-			voiceFile = true;
-		}
+	
+	if (!load(_voiceContext, resourceId, buffer, true)) {
+		return -1;
 	}
 
-	if (result == FAILURE) {
-		result = RSC_GetResourceSize(_voice_ctxt, voice_rn, &length);
 
-		if (result != SUCCESS) {
-			return -1;
-		}
+	msDouble = (double)buffer.size;
+	if (buffer.sampleBits == 16) {
+		msDouble /= 2.0;
 	}
-
-	if (_vm->getFeatures() & GF_VOX_VOICES && !voiceFile) {
-		// Rough hack, fix this to be accurate
-		ms_f = (double)length / 22050 * 2000.0;
-		ms_i = (int)ms_f;
-	} else if (res_type == GAME_SOUND_PCM) {
-		ms_f = (double)length / (_snd_info.sample_size / 8) / (_snd_info.freq) * 1000.0;
-		ms_i = (int)ms_f;
-	} else if (res_type == GAME_SOUND_VOC) {		
-		// Rough hack, fix this to be accurate
-		ms_f = (double)length / 14705 * 1000.0;
-		ms_i = (int)ms_f;
-	} else if (res_type == GAME_SOUND_WAV) {
-		// IHNM does not use the same format for all its WAV sounds, so
-		// we just have to load the stupid thing and see what that will
-		// tell us about it.
-
-		SOUNDBUFFER snd_buffer;
-
-		result = load(_voice_ctxt, voice_rn, &snd_buffer);
-		if (result != SUCCESS) {
-			return -1;
-		}
-
-		free(snd_buffer.s_buf);
-
-		ms_f = (double)snd_buffer.s_buf_len;
-		if (snd_buffer.s_samplebits == 16) {
-			ms_f /= 2.0;
-		}
-		if (snd_buffer.s_stereo) {
-			ms_f /= 2.0;
-		}
-
-		ms_f = ms_f / snd_buffer.s_freq * 1000.0;
-		ms_i = (int)ms_f;
-	} else {
-		return -1;
+	if (buffer.stereo) {
+		msDouble /= 2.0;
 	}
 
-	return ms_i;
+	msDouble = msDouble / buffer.frequency * 1000.0;
+	return (int)msDouble;
+
 }
 
 } // End of namespace Saga

Index: sndres.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sndres.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- sndres.h	9 Jan 2005 23:41:22 -0000	1.20
+++ sndres.h	19 Jul 2005 19:05:51 -0000	1.21
@@ -26,7 +26,6 @@
 #ifndef SAGA_SNDRES_H_
 #define SAGA_SNDRES_H_
 
-#include "saga/rscfile_mod.h"
 #include "saga/sound.h"
 
 namespace Saga {
@@ -36,22 +35,20 @@
 
 	SndRes(SagaEngine *vm);
 
-	int loadSound(uint32 sound_rn);
-	int playSound(uint32 sound_rn, int volume, bool loop);
-	int playVoice(uint32 voice_rn);
-	int getVoiceLength(uint32 voice_rn);
+	int loadSound(uint32 resourceId);
+	void playSound(uint32 resourceId, int volume, bool loop);
+	void playVoice(uint32 resourceId);
+	int getVoiceLength(uint32 resourceId);
 
  private:
-	int load(RSCFILE_CONTEXT *snd_ctxt, uint32 snd_rn, SOUNDBUFFER *snd_buf_i);
-	int loadVocSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i);
-	int loadWavSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i);
-
-	int _init;
+	bool load(ResourceContext *context, uint32 resourceId, SoundBuffer &buffer, bool onlyHeader);
+	bool loadVocSound(byte *soundResource, size_t soundResourceLength, SoundBuffer &buffer);
+	bool loadWavSound(byte *soundResource, size_t soundResourceLength, SoundBuffer &buffer);
 
-	RSCFILE_CONTEXT *_sfx_ctxt;
-	RSCFILE_CONTEXT *_voice_ctxt;
+	ResourceContext *_sfxContext;
+	ResourceContext *_voiceContext;
 
-	GameSoundInfo _snd_info;
+	GameSoundInfo _soundInfo;
 
 	SagaEngine *_vm;
 };

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sound.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- sound.cpp	4 Jun 2005 12:25:25 -0000	1.29
+++ sound.cpp	19 Jul 2005 19:05:51 -0000	1.30
@@ -32,127 +32,64 @@
 
 Sound::Sound(SagaEngine *vm, Audio::Mixer *mixer, int enabled) : 
 	_vm(vm), _mixer(mixer), _enabled(enabled), _voxStream(0) {
-
-	_soundInitialized = 1;
-	return;
 }
 
 Sound::~Sound() {
-	if (!_soundInitialized) {
-		return;
-	}
-
 	delete _voxStream;
-	_soundInitialized = 0;
 }
 
-int Sound::playSoundBuffer(Audio::SoundHandle *handle, SOUNDBUFFER *buf, int volume, bool loop, bool forceBigEndian) {
+void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume, bool loop, bool forceBigEndian) {
 	byte flags;
 
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
-
 	flags = Audio::Mixer::FLAG_AUTOFREE;
 
 	if (loop)
 		flags |= Audio::Mixer::FLAG_LOOP;
 
-	if (buf->s_samplebits == 16) {
+	if (buffer.sampleBits == 16) {
 		flags |= Audio::Mixer::FLAG_16BITS;
-		if (!(_vm->getFeatures() & GF_BIG_ENDIAN_DATA) && !forceBigEndian)
+		if (!(_vm->isBigEndian()) && !forceBigEndian)
 			flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
 	}
-	if (buf->s_stereo)
+	if (buffer.stereo)
 		flags |= Audio::Mixer::FLAG_STEREO;
-	if (!buf->s_signed)
+	if (!buffer.isSigned)
 		flags |= Audio::Mixer::FLAG_UNSIGNED;
 
-	_mixer->playRaw(handle, buf->s_buf, buf->s_buf_len, buf->s_freq, flags, -1, volume);
-
-	return SUCCESS;
+	_mixer->playRaw(handle, buffer.buffer, buffer.size, buffer.frequency, flags, -1, volume);	
 }
 
-int Sound::playSound(SOUNDBUFFER *buf, int volume, bool loop) {
-	return playSoundBuffer(&_effectHandle, buf, 2 * volume, loop, false);
+void Sound::playSound(SoundBuffer &buffer, int volume, bool loop) {
+	playSoundBuffer(&_effectHandle, buffer, 2 * volume, loop, false);
 }
 
-int Sound::pauseSound() {
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
-
+void Sound::pauseSound() {
 	_mixer->pauseHandle(_effectHandle, true);
-
-	return SUCCESS;
 }
 
-int Sound::resumeSound() {
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
-
+void Sound::resumeSound() {
 	_mixer->pauseHandle(_effectHandle, false);
-
-	return SUCCESS;
 }
 
-int Sound::stopSound() {
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
-
+void Sound::stopSound() {
 	_mixer->stopHandle(_effectHandle);
-
-	return SUCCESS;
 }
 
-int Sound::playVoice(SOUNDBUFFER *buf) {
-	return playSoundBuffer(&_voiceHandle, buf, 255, false, (_vm->getFeatures() & GF_BIG_ENDIAN_VOICES) != 0);
+void Sound::playVoice(SoundBuffer &buffer) {
+	playSoundBuffer(&_voiceHandle, buffer, 255, false, (_vm->getFeatures() & GF_BIG_ENDIAN_VOICES) != 0);
 }
 
-int Sound::playVoxVoice(SOUNDBUFFER *buf) {
-	AudioStream *audioStream;
-
-	if (_voxStream)
-		delete _voxStream;
-
-	_voxStream = new Common::MemoryReadStream(buf->s_buf, buf->s_buf_len);
-
-	audioStream = makeADPCMStream(*_voxStream, buf->s_buf_len, kADPCMOki);
-	_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_voiceHandle, audioStream);
-
-	return SUCCESS;
-}
-
-int Sound::pauseVoice() {
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
 
+void Sound::pauseVoice() {
 	_mixer->pauseHandle(_voiceHandle, true);
-
-	return SUCCESS;
 }
 
-int Sound::resumeVoice() {
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
-
+void Sound::resumeVoice() {
 	_mixer->pauseHandle(_voiceHandle, false);
-
-	return SUCCESS;
 }
 
-int Sound::stopVoice() {
-	if (!_soundInitialized) {
-		return FAILURE;
-	}
-
+void Sound::stopVoice() {
 	_mixer->stopHandle(_voiceHandle);
-
-	return SUCCESS;
 }
 
 } // End of namespace Saga

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sound.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- sound.h	4 Jun 2005 12:25:25 -0000	1.21
+++ sound.h	19 Jul 2005 19:05:51 -0000	1.22
@@ -26,7 +26,6 @@
 #ifndef SAGA_SOUND_H_
 #define SAGA_SOUND_H_
 
-#include "saga/rscfile_mod.h"
 #include "sound/mixer.h"
 
 namespace Saga {
@@ -35,14 +34,15 @@
 	SOUND_LOOP = 1
 };
 
-struct SOUNDBUFFER {
-	uint16 s_freq;
-	int s_samplebits;
-	int s_stereo;
-	int s_signed;
+struct SoundBuffer {
+	uint16 frequency;
+	int sampleBits;
+	bool stereo;
+	bool isSigned;
 
-	byte *s_buf;
-	size_t s_buf_len;
+	byte *buffer;
+	size_t size;
+	//big endianess flag!!!
 };
 
 class Sound {
@@ -51,22 +51,19 @@
 	Sound(SagaEngine *vm, Audio::Mixer *mixer, int enabled);
 	~Sound();
 
-	int playSound(SOUNDBUFFER *buf, int volume, bool loop);
-	int pauseSound();
-	int resumeSound();
-	int stopSound();
+	void playSound(SoundBuffer &buffer, int volume, bool loop);
+	void pauseSound();
+	void resumeSound();
+	void stopSound();
 
-	int playVoice(SOUNDBUFFER *buf);
-	int playVoxVoice(SOUNDBUFFER *buf);
-	int pauseVoice();
-	int resumeVoice();
-	int stopVoice();
+	void playVoice(SoundBuffer &buffer);
+	void pauseVoice();
+	void resumeVoice();
+	void stopVoice();
 
  private:
 
-	int playSoundBuffer(Audio::SoundHandle *handle, SOUNDBUFFER *buf, int volume, bool loop, bool forceBigEndian);
-
-	int _soundInitialized;
+	void playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume, bool loop, bool forceBigEndian);
 	int _enabled;
 
 	SagaEngine *_vm;

Index: sprite.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sprite.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- sprite.cpp	14 Jul 2005 17:46:21 -0000	1.59
+++ sprite.cpp	19 Jul 2005 19:05:51 -0000	1.60
@@ -26,7 +26,7 @@
 
 #include "saga/gfx.h"
 #include "saga/scene.h"
-#include "saga/rscfile_mod.h"
+#include "saga/rscfile.h"
 
 #include "saga/font.h"
 
@@ -35,38 +35,32 @@
 
 namespace Saga {
 
-Sprite::Sprite(SagaEngine *vm) : _vm(vm), _initialized(false) {
+Sprite::Sprite(SagaEngine *vm) : _vm(vm) {
 	debug(8, "Initializing sprite subsystem...");
 
 	// Load sprite module resource context
-	_spriteContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
+	_spriteContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
 	if (_spriteContext == NULL) {
-		return;
+		error("Sprite::Sprite resource context not found");
 	}
 
 	_decodeBufLen = DECODE_BUF_LEN;
 
 	_decodeBuf = (byte *)malloc(_decodeBufLen);
 	if (_decodeBuf == NULL) {
-		return;
+		memoryError("Sprite::Sprite");
 	}
 
 	loadList(_vm->getResourceDescription()->mainSpritesResourceId, _mainSprites);
-
-	_initialized = true;
 }
 
 Sprite::~Sprite(void) {
-	if (!_initialized) {
-		return;
-	}
-
 	debug(8, "Shutting down sprite subsystem...");
 	_mainSprites.freeMem();
 	free(_decodeBuf);
 }
 
-int Sprite::loadList(int resourceId, SpriteList &spriteList) {
+void Sprite::loadList(int resourceId, SpriteList &spriteList) {
 	SpriteInfo *spriteInfo;
 	byte *spriteListData;
 	size_t spriteListLength;
@@ -79,17 +73,13 @@
 	const byte *spritePointer;
 	const byte *spriteDataPointer;
 
-	if (RSC_LoadResource(_spriteContext, resourceId, &spriteListData, &spriteListLength) != SUCCESS) {
-		warning("Sprite::loadList RSC_LoadResource FAILURE");
-		return FAILURE;
-	}
+	_vm->_resource->loadResource(_spriteContext, resourceId, spriteListData, spriteListLength);
 
 	if (spriteListLength == 0) {
-		warning("Sprite::loadList spriteListLength == 0");
-		return FAILURE;
+		return;
 	}
 
-	MemoryReadStreamEndian readS(spriteListData, spriteListLength, IS_BIG_ENDIAN);
+	MemoryReadStreamEndian readS(spriteListData, spriteListLength, _spriteContext->isBigEndian);
 
 	spriteCount = readS.readUint16();
 
@@ -105,7 +95,7 @@
 
 	for (i = oldSpriteCount; i < spriteList.spriteCount; i++) {
 		spriteInfo = &spriteList.infoList[i];
-		if (_vm->getFeatures() & GF_MAC_RESOURCES)
+		if (_vm->isMacResources())
 			offset = readS.readUint32();
 		else
 			offset = readS.readUint16();
@@ -142,9 +132,7 @@
 		memcpy(spriteInfo->decodedBuffer, _decodeBuf, outputLength);
 	}
 
-	RSC_FreeResource(spriteListData);
-
-	return SUCCESS;
+	free(spriteListData);
 }
 
 void Sprite::getScaledSpriteBuffer(SpriteList &spriteList, int spriteNumber, int scale, int &width, int &height, int &xAlign, int &yAlign, const byte *&buffer) {
@@ -307,8 +295,6 @@
 	int maskZ;
 
 
-	assert(_initialized);
-
 	if (!_vm->_scene->isBGMaskPresent()) {
 		draw(ds, clipRect, spriteList, spriteNumber, screenCoord, scale);
 		return;

Index: sprite.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sprite.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- sprite.h	9 Jul 2005 16:23:45 -0000	1.21
+++ sprite.h	19 Jul 2005 19:05:52 -0000	1.22
@@ -81,7 +81,7 @@
 
 	void draw(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Rect &screenRect, int scale);
 
-	int loadList(int resourceId, SpriteList &spriteList); // load or append spriteList
+	void loadList(int resourceId, SpriteList &spriteList); // load or append spriteList
 	bool hitTest(SpriteList &spriteList, int spriteNumber, const Point &screenCoord, int scale, const Point &testPoint);
 	void getScaledSpriteBuffer(SpriteList &spriteList, int spriteNumber, int scale, int &width, int &height, int &xAlign, int &yAlign, const byte *&buffer);
 
@@ -90,8 +90,7 @@
 	void scaleBuffer(const byte *src, int width, int height, int scale);
 	
 	SagaEngine *_vm;
-	bool _initialized;
-	RSCFILE_CONTEXT *_spriteContext;
+	ResourceContext *_spriteContext;
 	byte *_decodeBuf;
 	size_t _decodeBufLen;
 };

Index: sthread.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sthread.cpp,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- sthread.cpp	19 Jun 2005 14:06:20 -0000	1.85
+++ sthread.cpp	19 Jul 2005 19:05:52 -0000	1.86
@@ -173,14 +173,6 @@
 		executeThreads(0);
 }
 
-int Script::SThreadDebugStep() {
-	if (_dbg_singlestep) {
-		_dbg_dostep = 1;
-	}
-
-	return SUCCESS;
-}
-
 bool Script::runThread(ScriptThread *thread, uint instructionLimit) {
 	const char*operandName;
 	uint instructionCount;
@@ -201,19 +193,7 @@
 	int debug_print = 0;
 	int operandChar;
 	int i;
-
-	// Handle debug single-stepping
-	if ((thread == _dbg_thread) && _dbg_singlestep) {
-		if (_dbg_dostep) {
-			debug_print = 1;
-			thread->_sleepTime = 0;
-			instructionLimit = 1;
-			_dbg_dostep = 0;
-		} else {
-			return false;
-		}
-	}
-
+	
 	MemoryReadStream scriptS(thread->_moduleBase, thread->_moduleBaseSize);
 
 	scriptS.seek(thread->_instructionOffset);





More information about the Scummvm-git-logs mailing list