[Scummvm-cvs-logs] CVS: scummvm/sword2 anims.cpp,1.39,1.40 build_display.cpp,1.42,1.43 console.cpp,1.27,1.28 controls.cpp,1.45,1.46 debug.cpp,1.22,1.23 defs.h,1.6,1.7 function.cpp,1.35,1.36 icons.cpp,1.20,1.21 layers.cpp,1.18,1.19 logic.cpp,1.26,1.27 maketext.cpp,1.26,1.27 mem_view.cpp,1.19,1.20 memory.cpp,1.15,1.16 memory.h,1.9,1.10 mouse.cpp,1.35,1.36 protocol.cpp,1.18,1.19 protocol.h,1.6,1.7 resman.cpp,1.60,1.61 resman.h,1.12,1.13 router.cpp,1.26,1.27 save_rest.cpp,1.32,1.33 save_rest.h,1.6,1.7 scroll.cpp,1.10,1.11 scroll.h,1.3,1.4 sound.cpp,1.31,1.32 sound.h,1.6,1.7 speech.cpp,1.40,1.41 startup.cpp,1.26,1.27 sword2.cpp,1.74,1.75 sword2.h,1.32,1.33 tony_gsdk.cpp,1.14,1.15 walker.cpp,1.21,1.22

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Sun Nov 2 23:48:08 CET 2003


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1:/tmp/cvs-serv6809

Modified Files:
	anims.cpp build_display.cpp console.cpp controls.cpp debug.cpp 
	defs.h function.cpp icons.cpp layers.cpp logic.cpp 
	maketext.cpp mem_view.cpp memory.cpp memory.h mouse.cpp 
	protocol.cpp protocol.h resman.cpp resman.h router.cpp 
	save_rest.cpp save_rest.h scroll.cpp scroll.h sound.cpp 
	sound.h speech.cpp startup.cpp sword2.cpp sword2.h 
	tony_gsdk.cpp walker.cpp 
Log Message:
The resource and memory managers are now created dynamically.

Renamed the resource manager's open/close methods openResource() and
closeResource() to avoid confusion. (It was I who originally shortened
their names to open() and close(), but I've changed my mind now.)

Moved more stuff into Sword2Engine.


Index: anims.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/anims.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- anims.cpp	1 Nov 2003 17:08:23 -0000	1.39
+++ anims.cpp	3 Nov 2003 07:47:41 -0000	1.40
@@ -117,11 +117,11 @@
 			// if the resource number is within range & it's not
 			// a null resource
 
-			if (res_man.Res_check_valid(res)) {
+			if (res_man->Res_check_valid(res)) {
 				// Open the resource. Can close it immediately.
 				// We've got a pointer to the header.
-				head = (_standardHeader *) res_man.open(res);
-				res_man.close(res);
+				head = (_standardHeader *) res_man->openResource(res);
+				res_man->closeResource(res);
 
 				// if it's not an animation file
 				if (head->fileType != ANIMATION_FILE) {
@@ -151,7 +151,7 @@
 #endif
 
 		// open anim file
-		anim_file = res_man.open(res);
+		anim_file = res_man->openResource(res);
 
 #ifdef _SWORD2_DEBUG
 		// check this this resource is actually an animation file!
@@ -161,7 +161,7 @@
 #endif
 
 		// point to anim header
-		anim_head = FetchAnimHeader(anim_file);
+		anim_head = g_sword2->fetchAnimHeader(anim_file);
 
 /* #ifdef _SWORD2_DEBUG
 		// check there's at least one frame
@@ -190,8 +190,8 @@
 		// frame of the anim.
 
 		// open anim file and point to anim header
-		anim_file = res_man.open(ob_graphic->anim_resource);
-		anim_head = FetchAnimHeader(anim_file);
+		anim_file = res_man->openResource(ob_graphic->anim_resource);
+		anim_head = g_sword2->fetchAnimHeader(anim_file);
 
 		if (reverse)
 			ob_graphic->anim_pc--;
@@ -210,7 +210,7 @@
 	}
 
 	// close the anim file
-	res_man.close(ob_graphic->anim_resource);
+	res_man->closeResource(ob_graphic->anim_resource);
 
 	// check if we want the script to loop back & call this function again
 	return ob_logic->looping ? IR_REPEAT : IR_STOP;
@@ -274,7 +274,7 @@
 
 	// open the resource (& check it's valid)
 
-	anim_file = res_man.open(res);
+	anim_file = res_man->openResource(res);
 
 #ifdef _SWORD2_DEBUG
 	// check this this resource is actually an animation file!
@@ -284,7 +284,7 @@
 #endif
 
 	// set up pointer to the animation header
-	anim_head = FetchAnimHeader(anim_file);
+	anim_head = g_sword2->fetchAnimHeader(anim_file);
 
 /* #ifdef _SWORD2_DEBUG
 	// check there's at least one frame
@@ -304,7 +304,7 @@
 
 	// Close the anim file and drop out of script
 
-	res_man.close(ob_graphic->anim_resource);
+	res_man->closeResource(ob_graphic->anim_resource);
 	return IR_CONT;
 }
 
@@ -497,11 +497,11 @@
 		local_text = _sequenceTextList[line].textNumber & 0xffff;
 
 		// open text resource & get the line
-		text = FetchTextLine(res_man.open(text_res), local_text);
+		text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
 		wavId = (int32) READ_LE_UINT16(text);
 
 		// now ok to close the text file
-		res_man.close(text_res);
+		res_man->closeResource(text_res);
 
 		// 1st word of text line is the official line number
 		debug(5,"(%d) SEQUENCE TEXT: %s", READ_LE_UINT16(text), text + 2);
@@ -523,7 +523,7 @@
 
 			File fp;
 
-			sprintf(speechFile, "speech%d.clu", res_man.whichCd());
+			sprintf(speechFile, "speech%d.clu", res_man->whichCd());
 			if (fp.open(speechFile))
 				fp.close();
 			else
@@ -540,7 +540,7 @@
 
 		if (gui->_subtitles || !speechRunning) {
 			// open text resource & get the line
-			text = FetchTextLine(res_man.open(text_res), local_text);
+			text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
 			// make the sprite
 			// 'text+2' to skip the first 2 bytes which form the
 			// line reference number
@@ -554,7 +554,7 @@
 			_sequenceTextList[line].text_mem = fontRenderer.makeTextSprite(text + 2, 600, 255, g_sword2->_speechFontId, 1);
 
 			// ok to close the text resource now
-			res_man.close(text_res);
+			res_man->closeResource(text_res);
 		} else {
 			_sequenceTextList[line].text_mem = NULL;
 			sequenceText[line]->textSprite = NULL;
@@ -572,7 +572,7 @@
 		// if we've made a text sprite for this line...
 
 		if (_sequenceTextList[line].text_mem) {
-			memory.lockMemory(_sequenceTextList[line].text_mem);
+			memory->lockMemory(_sequenceTextList[line].text_mem);
 
 			// now fill out the _spriteInfo structure in the
 			// _movieTextObjectStructure
@@ -611,7 +611,7 @@
 
 		// free up the mem block containing this text sprite
 		if (_sequenceTextList[line].text_mem)
-			memory.freeMemory(_sequenceTextList[line].text_mem);
+			memory->freeMemory(_sequenceTextList[line].text_mem);
 
 		// free up the mem block containing this speech sample
 		if (_sequenceTextList[line].speech_mem)
@@ -631,7 +631,7 @@
 
 	// params:	0 id of lead-in music
 
-	leadIn = res_man.open(params[0]);
+	leadIn = res_man->openResource(params[0]);
 
 #ifdef _SWORD2_DEBUG
 	header = (_standardHeader *) leadIn;
@@ -646,7 +646,7 @@
 	if (rv)
 		debug(5, "SFX ERROR: playFx() returned %.8x", rv);
 
-	res_man.close(params[0]);
+	res_man->closeResource(params[0]);
 
 	// fade out any music that is currently playing
 	fnStopMusic(NULL);
@@ -706,7 +706,7 @@
 	// open the lead-out music resource, if there is one
 
 	if (_smackerLeadOut) {
-		leadOut = res_man.open(_smackerLeadOut);
+		leadOut = res_man->openResource(_smackerLeadOut);
 
 #ifdef _SWORD2_DEBUG
 		header = (_standardHeader *) leadOut;
@@ -738,7 +738,7 @@
 	// close the lead-out music resource
 
 	if (_smackerLeadOut) {
-		res_man.close(_smackerLeadOut);
+		res_man->closeResource(_smackerLeadOut);
 		_smackerLeadOut = 0;
 	}
 

Index: build_display.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/build_display.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- build_display.cpp	2 Nov 2003 18:50:04 -0000	1.42
+++ build_display.cpp	3 Nov 2003 07:47:41 -0000	1.43
@@ -72,44 +72,44 @@
 			// first background parallax + related anims
 
 			// open the screen resource
-			file = res_man.open(_thisScreen.background_layer_id);
+			file = res_man->openResource(_thisScreen.background_layer_id);
 			screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
 
 			if (screenLayerTable->bg_parallax[0]) {
-				g_display->renderParallax(FetchBackgroundParallaxLayer(file, 0), 0);
+				g_display->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0);
 				// release the screen resource before cacheing
 				// the sprites
-	 			res_man.close(_thisScreen.background_layer_id);
+	 			res_man->closeResource(_thisScreen.background_layer_id);
 				sendBackPar0Frames();
 			} else {
 				// release the screen resource
- 	 			res_man.close(_thisScreen.background_layer_id);
+ 	 			res_man->closeResource(_thisScreen.background_layer_id);
 			}
 
 			// second background parallax + related anims
 
 			// open the screen resource
-			file = res_man.open(_thisScreen.background_layer_id);
+			file = res_man->openResource(_thisScreen.background_layer_id);
 			screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
 
 			if (screenLayerTable->bg_parallax[1]) {
-				g_display->renderParallax(FetchBackgroundParallaxLayer(file, 1), 1);
+				g_display->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1);
 				// release the screen resource before cacheing
 				// the sprites
-	 			res_man.close(_thisScreen.background_layer_id);
+	 			res_man->closeResource(_thisScreen.background_layer_id);
 				sendBackPar1Frames();
 			} else {
 				// release the screen resource
- 	 			res_man.close(_thisScreen.background_layer_id);
+ 	 			res_man->closeResource(_thisScreen.background_layer_id);
 			}
 
 			// normal backround layer (just the one!)
 
 			// open the screen resource
-			file = res_man.open(_thisScreen.background_layer_id);
-			g_display->renderParallax(FetchBackgroundLayer(file), 2);
+			file = res_man->openResource(_thisScreen.background_layer_id);
+			g_display->renderParallax(fetchBackgroundLayer(file), 2);
 			// release the screen resource
-			res_man.close(_thisScreen.background_layer_id);
+			res_man->closeResource(_thisScreen.background_layer_id);
 
 			// sprites & layers
 
@@ -121,35 +121,35 @@
 			// first foreground parallax + related anims
 
 			// open the screen resource
-			file = res_man.open(_thisScreen.background_layer_id);
+			file = res_man->openResource(_thisScreen.background_layer_id);
 			screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
 
 			if (screenLayerTable->fg_parallax[0]) {
-				g_display->renderParallax(FetchForegroundParallaxLayer(file, 0), 3);
+				g_display->renderParallax(fetchForegroundParallaxLayer(file, 0), 3);
 				// release the screen resource before cacheing
 				// the sprites
-	 			res_man.close(_thisScreen.background_layer_id);
+	 			res_man->closeResource(_thisScreen.background_layer_id);
 				sendForePar0Frames();
 			} else {
 				// release the screen resource
- 	 			res_man.close(_thisScreen.background_layer_id);
+ 	 			res_man->closeResource(_thisScreen.background_layer_id);
 			}
 
 			// second foreground parallax + related anims
 
 			// open the screen resource
-			file = res_man.open(_thisScreen.background_layer_id);
+			file = res_man->openResource(_thisScreen.background_layer_id);
 			screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
 
 			if (screenLayerTable->fg_parallax[1]) {
-				g_display->renderParallax(FetchForegroundParallaxLayer(file, 1), 4);
+				g_display->renderParallax(fetchForegroundParallaxLayer(file, 1), 4);
 				// release the screen resource before cacheing
 				// the sprites
-	 			res_man.close(_thisScreen.background_layer_id);
+	 			res_man->closeResource(_thisScreen.background_layer_id);
 				sendForePar1Frames();
 			} else {
 				// release the screen resource
- 	 			res_man.close(_thisScreen.background_layer_id);
+ 	 			res_man->closeResource(_thisScreen.background_layer_id);
 			}
 
 			// walkgrid, mouse & player markers & mouse area
@@ -251,7 +251,7 @@
 
 	g_display->fadeUp();
 
-	memory.freeMemory(text_spr);
+	memory->freeMemory(text_spr);
 
 	g_display->waitForFade();
 
@@ -356,10 +356,10 @@
 	uint32 current_layer_area = 0;
 
 	// file points to 1st byte in the layer file
-	file = res_man.open(_thisScreen.background_layer_id);
+	file = res_man->openResource(_thisScreen.background_layer_id);
 
 	// point to layer header
-	layer_head = FetchLayerHeader(file,layer_number);
+	layer_head = fetchLayerHeader(file,layer_number);
 
 	spriteInfo.x = layer_head->x;
 	spriteInfo.y = layer_head->y;
@@ -381,7 +381,7 @@
 		_largestLayerArea = current_layer_area;
 		sprintf(_largestLayerInfo,
 			"largest layer:  %s layer(%d) is %dx%d",
-			FetchObjectName(_thisScreen.background_layer_id),
+			fetchObjectName(_thisScreen.background_layer_id),
 			layer_number, layer_head->width, layer_head->height);
 	}
 
@@ -389,7 +389,7 @@
 	if (rv)
 		error("Driver Error %.8x in Process_layer(%d)", rv, layer_number);
 
-	res_man.close(_thisScreen.background_layer_id);
+	res_man->closeResource(_thisScreen.background_layer_id);
 }
 
 void Sword2Engine::processImage(buildit *build_unit) {
@@ -404,11 +404,11 @@
 	uint32 current_sprite_area = 0;
 
 	// open anim resource file & point to base
-	file = res_man.open(build_unit->anim_resource);
+	file = res_man->openResource(build_unit->anim_resource);
 
-	anim_head = FetchAnimHeader(file);
-	cdt_entry = FetchCdtEntry(file, build_unit->anim_pc);
-	frame_head = FetchFrameHeader(file, build_unit->anim_pc);
+	anim_head = fetchAnimHeader(file);
+	cdt_entry = fetchCdtEntry(file, build_unit->anim_pc);
+	frame_head = fetchFrameHeader(file, build_unit->anim_pc);
 
 	// so that 0-colour is transparent
 	spriteType = RDSPR_TRANS;
@@ -477,7 +477,7 @@
 		_largestSpriteArea = current_sprite_area;
 		sprintf(_largestSpriteInfo,
 			"largest sprite: %s frame(%d) is %dx%d",
-			FetchObjectName(build_unit->anim_resource),
+			fetchObjectName(build_unit->anim_resource),
 			build_unit->anim_pc,
 			frame_head->width,
 			frame_head->height);
@@ -507,18 +507,18 @@
 
 // #ifdef _SWORD2_DEBUG
 //	if (frame_head->width <= 1) {
-//		debug(5, "WARNING: 1-pixel-wide frame found in %s (%d)", FetchObjectName(build_unit->anim_resource), build_unit->anim_resource);
+//		debug(5, "WARNING: 1-pixel-wide frame found in %s (%d)", fetchObjectName(build_unit->anim_resource), build_unit->anim_resource);
 //	}
 // #endif
 
 	rv = g_display->drawSprite(&spriteInfo);
 	if (rv)
 		error("Driver Error %.8x with sprite %s (%d) in processImage",
-			rv, FetchObjectName(build_unit->anim_resource),
+			rv, fetchObjectName(build_unit->anim_resource),
 			build_unit->anim_resource);
 
 	// release the anim resource
-	res_man.close(build_unit->anim_resource);
+	res_man->closeResource(build_unit->anim_resource);
 }
 
 void Sword2Engine::resetRenderLists(void) {
@@ -580,11 +580,11 @@
 
 	assert(ob_graph->anim_resource);
 
-	file = res_man.open(ob_graph->anim_resource);
+	file = res_man->openResource(ob_graph->anim_resource);
 
-	anim_head = FetchAnimHeader(file);
-	cdt_entry = FetchCdtEntry(file, ob_graph->anim_pc);
-	frame_head = FetchFrameHeader(file, ob_graph->anim_pc);
+	anim_head = fetchAnimHeader(file);
+	cdt_entry = fetchCdtEntry(file, ob_graph->anim_pc);
+	frame_head = fetchFrameHeader(file, ob_graph->anim_pc);
 
 	// update player graphic details for on-screen debug info
 	if (ID == CUR_PLAYER_ID) {
@@ -690,7 +690,7 @@
 	}
 
 	// close animation file
-	res_man.close(ob_graph->anim_resource);
+	res_man->closeResource(ob_graph->anim_resource);
 }
 
 int32 Logic::fnRegisterFrame(int32 *params) {
@@ -764,17 +764,17 @@
 	g_display->waitForFade();
 
 	// open the screen file
-	screenFile = res_man.open(_thisScreen.background_layer_id);
+	screenFile = res_man->openResource(_thisScreen.background_layer_id);
 
-	g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(screenFile));
+	g_display->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile));
 
-	g_display->setPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE);
+	g_display->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE);
 
 	// indicating that it's a screen palette
 	_lastPaletteRes = 0;
 
 	// close screen file
-  	res_man.close(_thisScreen.background_layer_id);
+  	res_man->closeResource(_thisScreen.background_layer_id);
 
 	// start fade up
 	g_display->fadeUp();
@@ -872,7 +872,7 @@
 	// non-zero: set palette to this separate palette file
 	if (palRes) {
 		// open the palette file
-		head = (_standardHeader *) res_man.open(palRes);
+		head = (_standardHeader *) res_man->openResource(palRes);
 
 		assert(head->fileType == PALETTE_FILE);
 
@@ -898,21 +898,21 @@
 		}
 
 		// close palette file
-	  	res_man.close(palRes);
+	  	res_man->closeResource(palRes);
 	} else {
 		// 0: set palette to current screen palette
 		if (_thisScreen.background_layer_id) {
 			// open the screen file
-			file = res_man.open(_thisScreen.background_layer_id);
-			g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(file));
+			file = res_man->openResource(_thisScreen.background_layer_id);
+			g_display->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file));
 
-			g_display->setPalette(0, 256, FetchPalette(file), RDPAL_INSTANT);
+			g_display->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT);
 
 			// indicating that it's a screen palette
 			_lastPaletteRes = 0;
 
 			// close screen file
-	  		res_man.close(_thisScreen.background_layer_id);
+	  		res_man->closeResource(_thisScreen.background_layer_id);
 		} else
 			error("setFullPalette(0) called, but no current screen available!");
 	}

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- console.cpp	2 Nov 2003 18:50:05 -0000	1.27
+++ console.cpp	3 Nov 2003 07:47:41 -0000	1.28
@@ -182,7 +182,7 @@
 }
 
 bool Debugger::Cmd_Mem(int argc, const char **argv) {
-	memory.displayMemory();
+	memory->displayMemory();
 	return true;
 }
 
@@ -192,7 +192,7 @@
 }
 
 bool Debugger::Cmd_Res(int argc, const char **argv) {
-	res_man.printConsoleClusters();
+	res_man->printConsoleClusters();
 	return true;
 }
 
@@ -262,7 +262,7 @@
 	if (argc != 2)
 		DebugPrintf("Usage: %s number\n", argv[0]);
 	else
-		res_man.examine(atoi(argv[1]));
+		res_man->examine(atoi(argv[1]));
 	return true;
 }
 
@@ -280,13 +280,13 @@
 	if (argc != 2)
 		DebugPrintf("Usage: %s number\n", argv[0]);
 	else
-		res_man.kill(atoi(argv[1]));
+		res_man->kill(atoi(argv[1]));
 	return true;
 }
 
 bool Debugger::Cmd_Nuke(int argc, const char **argv) {
 	DebugPrintf("Killing all resources except variable file and player object\n");
-	res_man.killAll(true);
+	res_man->killAll(true);
 	return true;
 }
 
@@ -319,7 +319,7 @@
 }
 
 bool Debugger::Cmd_Clear(int argc, const char **argv) {
-	res_man.killAllObjects(true);
+	res_man->killAllObjects(true);
 	return true;
 }
 
@@ -361,7 +361,7 @@
 		uint8 description[SAVE_DESCRIPTION_LEN];
 
 		// if there is a save game print the name
-		if (GetSaveDescription(i, description) == SR_OK)
+		if (g_sword2->getSaveDescription(i, description) == SR_OK)
 			DebugPrintf("%d: \"%s\"\n", i, description);
 	}
 
@@ -405,7 +405,7 @@
 	}
 
 	slotNo = atoi(argv[1]);
-	rv = SaveGame(slotNo, (uint8 *) description);
+	rv = g_sword2->saveGame(slotNo, (uint8 *) description);
 
 	if (rv == SR_OK)
 		DebugPrintf("Saved game \"%s\" to file \"savegame.%.3d\"\n", description, slotNo);
@@ -434,10 +434,10 @@
 	}
 
 	slotNo = atoi(argv[1]);
-	rv = RestoreGame(slotNo);
+	rv = g_sword2->restoreGame(slotNo);
 
 	if (rv == SR_OK) {
-		GetSaveDescription(slotNo, description);
+		g_sword2->getSaveDescription(slotNo, description);
 		DebugPrintf("Restored game \"%s\" from file \"savegame.%.3d\"\n", description, slotNo);
 	} else if (rv == SR_ERR_FILEOPEN)
 		DebugPrintf("ERROR: Cannot open file \"savegame.%.3d\"\n", slotNo);
@@ -686,8 +686,8 @@
 			uint32 target = g_sword2->_eventList[i].id;
 			uint32 script = g_sword2->_eventList[i].interact_id;
 
-			DebugPrintf("slot %d: id = %s (%d)\n", i, FetchObjectName(target), target);
-			DebugPrintf("         script = %s (%d) pos %d\n", FetchObjectName(script / 65536), script / 65536, script % 65536);
+			DebugPrintf("slot %d: id = %s (%d)\n", i, g_sword2->fetchObjectName(target), target);
+			DebugPrintf("         script = %s (%d) pos %d\n", g_sword2->fetchObjectName(script / 65536), script / 65536, script % 65536);
 		}
 	}
 

Index: controls.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/controls.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- controls.cpp	2 Nov 2003 18:50:05 -0000	1.45
+++ controls.cpp	3 Nov 2003 07:47:41 -0000	1.46
@@ -64,14 +64,14 @@
 
 public:
 	FontRendererGui(int fontId) : _fontId(fontId) {
-		uint8 *font = res_man.open(fontId);
+		uint8 *font = res_man->openResource(fontId);
 		_frameHeader *head;
 		_spriteInfo sprite;
 
 		sprite.type = RDSPR_NOCOMPRESSION | RDSPR_TRANS;
 
 		for (int i = 0; i < SIZE_OF_CHAR_SET; i++) {
-			head = (_frameHeader *) FetchFrameHeader(font, i);
+			head = (_frameHeader *) g_sword2->fetchFrameHeader(font, i);
 			sprite.data = (uint8 *) (head + 1);
 			sprite.w = head->width;
 			sprite.h = head->height;
@@ -80,7 +80,7 @@
 			_glyph[i]._height = head->height;
 		}
 
-		res_man.close(fontId);
+		res_man->closeResource(fontId);
 	}
 
 	~FontRendererGui() {
@@ -89,7 +89,7 @@
 	}
 
 	void fetchText(int textId, char *buf) {
-		uint8 *data = FetchTextLine(res_man.open(textId / SIZE), textId & 0xffff);
+		uint8 *data = g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff);
 		int i;
 
 		for (i = 0; data[i + 2]; i++) {
@@ -98,7 +98,7 @@
 		}
 			
 		buf[i] = 0;
-		res_man.close(textId / SIZE);
+		res_man->closeResource(textId / SIZE);
 	}
 
 	int getTextWidth(char *text) {
@@ -251,11 +251,11 @@
 	uint32 spriteType = RDSPR_TRANS;
 
 	// open anim resource file, point to base
-	file = res_man.open(res);
+	file = res_man->openResource(res);
 
-	anim_head = FetchAnimHeader(file);
-	cdt_entry = FetchCdtEntry(file, pc);
-	frame_head = FetchFrameHeader(file, pc);
+	anim_head = g_sword2->fetchAnimHeader(file);
+	cdt_entry = g_sword2->fetchCdtEntry(file, pc);
+	frame_head = g_sword2->fetchFrameHeader(file, pc);
 
 	// If the frame is flipped. (Only really applicable to frames using
 	// offsets.)
@@ -296,7 +296,7 @@
 	_surfaces[state]._original = true;
 
 	// Release the anim resource
-	res_man.close(res);
+	res_man->closeResource(res);
 };
 
 void Widget::linkSurfaceImage(Widget *from, int state, int x, int y) {
@@ -1086,7 +1086,7 @@
 				fr = _fr1;
 			}
 
-			if (GetSaveDescription(gui->_baseSlot + i, description) == SR_OK) {
+			if (g_sword2->getSaveDescription(gui->_baseSlot + i, description) == SR_OK) {
 				slot->setText(fr, gui->_baseSlot + i, (char *) description);
 				slot->setClickable(true);
 			} else {
@@ -1247,7 +1247,7 @@
 
 			_editBuffer[_editPos] = 0;
 
-			uint32 rv = SaveGame(_selectedSlot, (uint8 *) &_editBuffer[_firstPos]);
+			uint32 rv = g_sword2->saveGame(_selectedSlot, (uint8 *) &_editBuffer[_firstPos]);
 
 			if (rv != SR_OK) {
 				uint32 textId;
@@ -1261,11 +1261,11 @@
 					break;
 				}
 
-				saveLoadError((char*) (FetchTextLine(res_man.open(textId / SIZE), textId & 0xffff) + 2));
+				saveLoadError((char*) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2));
 				result = 0;
 			}
 		} else {
-			uint32 rv = RestoreGame(_selectedSlot);
+			uint32 rv = g_sword2->restoreGame(_selectedSlot);
 
 			if (rv != SR_OK) {
 				uint32 textId;
@@ -1282,7 +1282,7 @@
 					break;
 				}
 
-				saveLoadError((char *) (FetchTextLine(res_man.open(textId / SIZE), textId & 0xffff) + 2));
+				saveLoadError((char *) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2));
 				result = 0;
 			} else {
 				// Prime system with a game cycle
@@ -1428,7 +1428,7 @@
 	}
 
 	// Stop music instantly!
-	Kill_music();
+	g_sword2->killMusic();
 
 	//in case we were dead - well we're not anymore!
 	DEAD = 0;
@@ -1442,12 +1442,12 @@
 
 	// remove all resources from memory, including player object and
 	// global variables
-	res_man.removeAll();
+	res_man->removeAll();
 
 	// reopen global variables resource & send address to interpreter -
 	// it won't be moving
-	g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
-	res_man.close(1);
+	g_logic.setGlobalInterpreterVariables((int32 *) (res_man->openResource(1) + sizeof(_standardHeader)));
+	res_man->closeResource(1);
 
 	DEMO = temp_demo_flag;
 

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/debug.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- debug.cpp	2 Nov 2003 18:50:05 -0000	1.22
+++ debug.cpp	3 Nov 2003 07:47:41 -0000	1.23
@@ -178,7 +178,7 @@
 		if (CLICKED_ID)
 			sprintf(buf, "last click at %d,%d (id %d: %s)",
 				MOUSE_X, MOUSE_Y, CLICKED_ID,
-				FetchObjectName(CLICKED_ID));
+				g_sword2->fetchObjectName(CLICKED_ID));
 		else
 			sprintf(buf, "last click at %d,%d (---)",
 				MOUSE_X, MOUSE_Y);
@@ -190,7 +190,7 @@
 				g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x,
 				g_display->_mouseY + g_sword2->_thisScreen.scroll_offset_y,
 				g_sword2->_mouseTouching,
-				FetchObjectName(g_sword2->_mouseTouching));
+				g_sword2->fetchObjectName(g_sword2->_mouseTouching));
 		else
 			sprintf(buf, "mouse %d,%d (not touching)",
 				g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x,
@@ -205,7 +205,7 @@
 			sprintf(buf, "player %d,%d %s (%d) #%d/%d",
 				g_sword2->_thisScreen.player_feet_x,
 				g_sword2->_thisScreen.player_feet_y,
-				FetchObjectName(_playerGraphic.anim_resource),
+				g_sword2->fetchObjectName(_playerGraphic.anim_resource),
 				_playerGraphic.anim_resource,
 				_playerGraphic.anim_pc,
 				_playerGraphicNoFrames);
@@ -271,7 +271,7 @@
 
 		if (speechScriptWaiting) {
 			sprintf(buf, "script waiting for %s (%d)",
-				FetchObjectName(speechScriptWaiting),
+				g_sword2->fetchObjectName(speechScriptWaiting),
 				speechScriptWaiting);
 			makeDebugTextBlock(buf, 0, 90);
 		}
@@ -281,7 +281,7 @@
 		showVarPos = 115;	// y-coord for first showVar
 
 		// res 1 is the global variables resource
-		varTable = (int32 *) (res_man.open(1) + sizeof(_standardHeader));
+		varTable = (int32 *) (res_man->openResource(1) + sizeof(_standardHeader));
 
 		for (showVarNo = 0; showVarNo < MAX_SHOWVARS; showVarNo++) {
 			varNo = _showVar[showVarNo];	// get variable number
@@ -296,12 +296,12 @@
 			}
 		}
 
-		res_man.close(1);	// close global variables resource
+		res_man->closeResource(1);	// close global variables resource
 
 		// memory indicator - this should come last, to show all the
 		// sprite blocks above!
 
-		memory.memoryString(buf);
+		memory->memoryString(buf);
 		makeDebugTextBlock(buf, 0, 0);
 	}
 }

Index: defs.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/defs.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- defs.h	28 Oct 2003 19:51:27 -0000	1.6
+++ defs.h	3 Nov 2003 07:47:41 -0000	1.7
@@ -29,7 +29,7 @@
 // global variable references
 // NB. 4 * <number from linc's Global Variables list>
 
-#define VAR(n)				(*(uint32 *) (res_man._resList[1]->ad + sizeof(_standardHeader) + 4 * (n)))
+#define VAR(n)				(*(uint32 *) (res_man->_resList[1]->ad + sizeof(_standardHeader) + 4 * (n)))
 
 #define ID				VAR(0)
 #define RESULT				VAR(1)

Index: function.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/function.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- function.cpp	2 Nov 2003 22:38:04 -0000	1.35
+++ function.cpp	3 Nov 2003 07:47:41 -0000	1.36
@@ -99,8 +99,8 @@
 
 	// params:	0 resource to preload
 
-	res_man.open(params[0]);
-	res_man.close(params[0]);
+	res_man->openResource(params[0]);
+	res_man->closeResource(params[0]);
 	return IR_CONT;
 }
 
@@ -337,8 +337,8 @@
 	// +2 to skip the encoded text number in the first 2 chars; 3 is
 	// duration in seconds
 
-	g_sword2->displayMsg(FetchTextLine(res_man.open(text_res), local_text) + 2, 3);
-	res_man.close(text_res);
+	g_sword2->displayMsg(g_sword2->fetchTextLine(res_man->openResource(text_res), local_text) + 2, 3);
+	res_man->closeResource(text_res);
 	g_sword2->removeMsg();
 
 	return IR_CONT;
@@ -353,20 +353,20 @@
 	int32 size;
 	uint32 *globals;
 
-	size = res_man.fetchLen(1);
+	size = res_man->fetchLen(1);
 	size -= sizeof(_standardHeader);
 
 	debug(5, "globals size: %d", size);
 
-	globals = (uint32 *) ((uint8 *) res_man.open(1) + sizeof(_standardHeader));
+	globals = (uint32 *) ((uint8 *) res_man->openResource(1) + sizeof(_standardHeader));
 
 	// blank each global variable
 	memset(globals, 0, size);
 
-	res_man.close(1);
+	res_man->closeResource(1);
 
 	// all objects but george
-	res_man.killAllObjects(false);
+	res_man->killAllObjects(false);
 
 	// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
 	// - this is taken from fnInitBackground

Index: icons.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/icons.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- icons.cpp	2 Nov 2003 18:50:05 -0000	1.20
+++ icons.cpp	3 Nov 2003 07:47:41 -0000	1.21
@@ -87,9 +87,9 @@
 	// Call menu builder script which will register all carried menu
 	// objects. Run the 'build_menu' script in the 'menu_master' object
 
-	head = res_man.open(MENU_MASTER_OBJECT);
+	head = res_man->openResource(MENU_MASTER_OBJECT);
 	g_logic.runScript((char*) head, (char*) head, &null_pc);
-	res_man.close(MENU_MASTER_OBJECT);
+	res_man->closeResource(MENU_MASTER_OBJECT);
 
 	// Compare new with old. Anything in master thats not in new gets
 	// removed from master - if found in new too, remove from temp
@@ -191,7 +191,7 @@
 					icon_coloured = true;
 			}
 
-			icon = res_man.open(_masterMenuList[j].icon_resource) + sizeof(_standardHeader);
+			icon = res_man->openResource(_masterMenuList[j].icon_resource) + sizeof(_standardHeader);
 
 			// The coloured icon is stored directly after the
 			// greyed out one.
@@ -200,7 +200,7 @@
 				icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
 
 			g_display->setMenuIcon(RDMENU_BOTTOM, j, icon);
-			res_man.close(res);
+			res_man->closeResource(res);
 		} else {
 			// no icon here
 			g_display->setMenuIcon(RDMENU_BOTTOM, j, NULL);
@@ -227,17 +227,17 @@
 	// build them all high in full colour - when one is clicked on all the
 	// rest will grey out
 
-	for (int j = 0; j < ARRAYSIZE(icon_list); j++) {
-		icon = res_man.open(icon_list[j]) + sizeof(_standardHeader);
+	for (int i = 0; i < ARRAYSIZE(icon_list); i++) {
+		icon = res_man->openResource(icon_list[i]) + sizeof(_standardHeader);
 		
 		// The only case when an icon is grayed is when the player
 		// is dead. Then SAVE is not available.
 
-		if (!DEAD || icon_list[j] != SAVE_ICON)
+		if (!DEAD || icon_list[i] != SAVE_ICON)
 			icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
 
-		g_display->setMenuIcon(RDMENU_TOP, j, icon);
-		res_man.close(icon_list[j]);
+		g_display->setMenuIcon(RDMENU_TOP, i, icon);
+		res_man->closeResource(icon_list[i]);
 	}
 
 	g_display->showMenu(RDMENU_TOP);

Index: layers.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/layers.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- layers.cpp	2 Nov 2003 17:17:09 -0000	1.18
+++ layers.cpp	3 Nov 2003 07:47:41 -0000	1.19
@@ -34,7 +34,7 @@
 #include "sword2/logic.h"
 #include "sword2/protocol.h"
 #include "sword2/resman.h"
-#include "sword2/sound.h"	// for Clear_fx_queue() called from fnInitBackground()
+#include "sword2/sound.h"	// for clearFxQueue() called from fnInitBackground()
 
 namespace Sword2 {
 
@@ -55,10 +55,10 @@
 	uint8 *file;
 	uint32 rv;
 
-	debug(5, "CHANGED TO LOCATION \"%s\"", FetchObjectName(res));
+	debug(5, "CHANGED TO LOCATION \"%s\"", fetchObjectName(res));
 
 	// stop all fx & clears the queue
-	Clear_fx_queue();
+	clearFxQueue();
 
 #ifdef _SWORD2_DEBUG
 	debug(5, "fnInitBackground(%d)", res);
@@ -92,9 +92,9 @@
 	// each cycle
 
 	// file points to 1st byte in the layer file
-	file = res_man.open(_thisScreen.background_layer_id);
+	file = res_man->openResource(_thisScreen.background_layer_id);
 	
-	screen_head = FetchScreenHeader(file);
+	screen_head = fetchScreenHeader(file);
 
 	//set number of special sort layers
 	_thisScreen.number_of_layers = screen_head->noLayers;
@@ -109,7 +109,7 @@
 	if (screen_head->noLayers) {
 		for (int i = 0; i < screen_head->noLayers; i++) {
 			// get layer header for layer i
-			layer = FetchLayerHeader(file, i);
+			layer = fetchLayerHeader(file, i);
 
 			// add into the sort list
 
@@ -174,7 +174,7 @@
 		spriteInfo.scaledHeight = 0;
 		spriteInfo.type = 0;
 		spriteInfo.blend = 0;
-		spriteInfo.data = FetchShadingMask(file);
+		spriteInfo.data = fetchShadingMask(file);
 		spriteInfo.colourTable = 0;
 
 		rv = g_display->openLightMask(&spriteInfo);
@@ -189,7 +189,7 @@
 	}
 
 	// close the screen file
-   	res_man.close(_thisScreen.background_layer_id);
+   	res_man->closeResource(_thisScreen.background_layer_id);
 
 	setUpBackgroundLayers();
 
@@ -211,9 +211,9 @@
 		// open resource & set pointers to headers
 		// file points to 1st byte in the layer file
 
-		file = res_man.open(_thisScreen.background_layer_id);
+		file = res_man->openResource(_thisScreen.background_layer_id);
 
-		screen_head = FetchScreenHeader(file);
+		screen_head = fetchScreenHeader(file);
 
 		screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
 
@@ -221,26 +221,26 @@
 
 		for (i = 0; i < 2; i++) {
 			if (screenLayerTable->bg_parallax[i])
-				g_display->initialiseBackgroundLayer(FetchBackgroundParallaxLayer(file, i));
+				g_display->initialiseBackgroundLayer(fetchBackgroundParallaxLayer(file, i));
 			else
 				g_display->initialiseBackgroundLayer(NULL);
 		}
 
 		// Normal backround layer
 
-		g_display->initialiseBackgroundLayer(FetchBackgroundLayer(file));
+		g_display->initialiseBackgroundLayer(fetchBackgroundLayer(file));
 
 		// Foreground parallax layers
 
 		for (i = 0; i < 2; i++) {
 			if (screenLayerTable->fg_parallax[i])
-				g_display->initialiseBackgroundLayer(FetchForegroundParallaxLayer(file, i));
+				g_display->initialiseBackgroundLayer(fetchForegroundParallaxLayer(file, i));
 			else
 				g_display->initialiseBackgroundLayer(NULL);
 		}
 
 		// close the screen file
-		res_man.close(_thisScreen.background_layer_id);
+		res_man->closeResource(_thisScreen.background_layer_id);
 	}
 }
 

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- logic.cpp	28 Oct 2003 19:51:28 -0000	1.26
+++ logic.cpp	3 Nov 2003 07:47:41 -0000	1.27
@@ -60,7 +60,7 @@
 	// processing on the current list
 
 	while (_pc != 0xffffffff) {
-		head = (_standardHeader*) res_man.open(run_list);
+		head = (_standardHeader*) res_man->openResource(run_list);
 
 		if (head->fileType != RUN_LIST)
 			error("Logic_engine %d not a run_list", run_list);
@@ -74,7 +74,7 @@
 		// release the list again so it can float in memory - at this
 		// point not one thing should be locked
 
-		res_man.close(run_list);
+		res_man->closeResource(run_list);
 
 		debug(5, "%d", ID);
 
@@ -84,7 +84,7 @@
 			return 0;
 		}
 
-		head = (_standardHeader*) res_man.open(ID);
+		head = (_standardHeader*) res_man->openResource(ID);
 
 		if (head->fileType != GAME_OBJECT)
 			error("Logic_engine %d not an object", ID);
@@ -130,7 +130,7 @@
 
 				raw_data_ad = (char*) head;
 
-				far_head = (_standardHeader*) res_man.open(script / SIZE);
+				far_head = (_standardHeader*) res_man->openResource(script / SIZE);
 
 				if (far_head->fileType != GAME_OBJECT && far_head->fileType != SCREEN_MANAGER)
 					error("Logic_engine %d not a far object (its a %d)", script / SIZE, far_head->fileType);
@@ -145,7 +145,7 @@
 				ret = runScript(raw_script_ad, raw_data_ad, &_curObjectHub->script_pc[LEVEL]);
 
 				// close foreign object again
-				res_man.close(script / SIZE);
+				res_man->closeResource(script / SIZE);
 
 				// reset to us for service script
 				raw_script_ad = raw_data_ad;
@@ -201,7 +201,7 @@
 
 		// and that's it so close the object resource
 
-		res_man.close(ID);
+		res_man->closeResource(ID);
 	}
 
 	// leaving a room so remove all ids that must reboot correctly
@@ -238,7 +238,7 @@
 	router.clearWalkGridList();
 
 	// stops all fx & clears the queue
-	Clear_fx_queue();
+	g_sword2->clearFxQueue();
 
 	// free all the route memory blocks from previous game
 	router.freeAllRouteMem();
@@ -339,17 +339,17 @@
 
 	if (_currentRunList) {
 		// open and lock in place
-		game_object_list = (uint32 *) (res_man.open(_currentRunList) + sizeof(_standardHeader));
+		game_object_list = (uint32 *) (res_man->openResource(_currentRunList) + sizeof(_standardHeader));
 
 		Debug_Printf("Runlist number %d\n", _currentRunList);
 
 		for (int i = 0; game_object_list[i]; i++) {
-			file_header = (_standardHeader *) res_man.open(game_object_list[i]);
+			file_header = (_standardHeader *) res_man->openResource(game_object_list[i]);
 			Debug_Printf("%d %s\n", game_object_list[i], file_header->name);
-			res_man.close(game_object_list[i]);
+			res_man->closeResource(game_object_list[i]);
 		}
 
-		res_man.close(_currentRunList);
+		res_man->closeResource(_currentRunList);
 	} else
 		Debug_Printf("No run list set\n");
 }
@@ -430,7 +430,7 @@
 
 void Logic::processKillList(void) {
 	for (uint32 i = 0; i < _kills; i++)
-		res_man.remove(_objectKillList[i]);
+		res_man->remove(_objectKillList[i]);
 
 	_kills = 0;
 }

Index: maketext.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/maketext.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- maketext.cpp	28 Oct 2003 19:51:28 -0000	1.26
+++ maketext.cpp	3 Nov 2003 07:47:41 -0000	1.27
@@ -54,7 +54,7 @@
 #include "sword2/header.h"
 #include "sword2/maketext.h"
 #include "sword2/memory.h"
-#include "sword2/protocol.h"	// for FetchFrameHeader()
+#include "sword2/protocol.h"	// for fetchFrameHeader()
 #include "sword2/resman.h"
 #include "sword2/sword2.h"
 
@@ -94,7 +94,7 @@
 
 	// allocate memory for array of lineInfo structures
 
-	line = memory.allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, UID_temp);
+	line = memory->allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, UID_temp);
 
 	// get details of sentence breakdown into array of LineInfo structures
 	// and get the no of lines involved
@@ -107,7 +107,7 @@
 	textSprite = buildTextSprite(sentence, fontRes, pen, (LineInfo *) line->ad, noOfLines);
 
 	// free up the lineInfo array now
-	memory.freeMemory(line);
+	memory->freeMemory(line);
 
 	return textSprite;
 }
@@ -220,7 +220,7 @@
 
 	// allocate memory for sprite, and lock it ready for use
 	// NB. 'textSprite' is the given pointer to the handle to be used
-	textSprite = memory.allocMemory(sizeof(_frameHeader) + sizeOfSprite, MEM_locked, UID_text_sprite);
+	textSprite = memory->allocMemory(sizeof(_frameHeader) + sizeOfSprite, MEM_locked, UID_text_sprite);
 
 	// the handle (*textSprite) now points to UNMOVABLE memory block
 	// set up the frame header
@@ -244,7 +244,7 @@
 	memset(linePtr, NO_COL, sizeOfSprite);
 
 	// open font file
-	charSet = res_man.open(fontRes);
+	charSet = res_man->openResource(fontRes);
 
 	// fill sprite with characters, one line at a time
 
@@ -278,10 +278,10 @@
 	}
 
 	// close font file
-	res_man.close(fontRes);
+	res_man->closeResource(fontRes);
 
 	// unlock the sprite memory block, so it's movable
-	memory.floatMemory(textSprite);
+	memory->floatMemory(textSprite);
 
 	return textSprite;
 }
@@ -295,14 +295,14 @@
 	uint16 width;
 
 	// open font file
-	charSet = res_man.open(fontRes);
+	charSet = res_man->openResource(fontRes);
 
 	// move to approp. sprite (header)
 	charFrame = findChar(ch, charSet);
 	width = charFrame->width;
 
 	// close font file
- 	res_man.close(fontRes);
+ 	res_man->closeResource(fontRes);
 
 	// return its width
 	return width;
@@ -317,14 +317,14 @@
 	uint16 height;
 
 	// open font file
-	charSet = res_man.open(fontRes);
+	charSet = res_man->openResource(fontRes);
 
 	// assume all chars the same height, i.e. FIRST_CHAR is as good as any
 	charFrame = findChar(FIRST_CHAR, charSet);
 	height = charFrame->height;
 
 	// close font file
-	res_man.close(fontRes);
+	res_man->closeResource(fontRes);
 
 	// return its height
 	return height;
@@ -338,7 +338,7 @@
 	if (ch < FIRST_CHAR)
 		ch = DUD;
 
-	return FetchFrameHeader(charSet, ch - FIRST_CHAR);
+	return g_sword2->fetchFrameHeader(charSet, ch - FIRST_CHAR);
 }
 
 // Copies a character sprite from 'charPtr' to the sprite buffer at 'spritePtr'
@@ -538,7 +538,7 @@
 
 	if (_blocList[bloc_number].text_mem) {
 		// release the floating memory and mark it as free
-		memory.freeMemory(_blocList[bloc_number].text_mem);
+		memory->freeMemory(_blocList[bloc_number].text_mem);
 		_blocList[bloc_number].text_mem = 0;
 	} else {
 		// illegal kill - stop the system
@@ -564,14 +564,14 @@
 	uint8 language;
 
 	// open the text resource
-	textFile = res_man.open(TEXT_RES);
+	textFile = res_man->openResource(TEXT_RES);
 
 	// If language is Polish or Finnish it requires alternate fonts.
 	// Otherwise, use regular fonts
 
 	// get the text line (& skip the 2 chars containing the wavId)
 
-	textLine = FetchTextLine(textFile, SAVE_LINE_NO) + 2;
+	textLine = fetchTextLine(textFile, SAVE_LINE_NO) + 2;
 
 	// "talenna"	Finnish for "save"
 	// "zapisz"	Polish for "save"
@@ -590,10 +590,10 @@
 
 	// Get the text line - skip the 2 chars containing the wavId
 
-	if (g_sword2->_features & GF_DEMO)
-		textLine = FetchTextLine(textFile, 451) + 2;
+	if (_features & GF_DEMO)
+		textLine = fetchTextLine(textFile, 451) + 2;
 	else
-		textLine = FetchTextLine(textFile, 54) + 2;
+		textLine = fetchTextLine(textFile, 54) + 2;
 
 	// According to the GetNameFunction(), which was never called and has
 	// therefore been removed, the name of the game is:
@@ -606,7 +606,7 @@
 	g_display->setWindowName((char *) textLine);
 
 	// now ok to close the text file
-	res_man.close(TEXT_RES);
+	res_man->closeResource(TEXT_RES);
 }
 
 // called from the above function, and also from console.cpp

Index: mem_view.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/mem_view.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mem_view.cpp	28 Oct 2003 19:51:29 -0000	1.19
+++ mem_view.cpp	3 Nov 2003 07:47:41 -0000	1.20
@@ -44,9 +44,9 @@
 	j = _baseMemBlock;
 	do {
 		if (_memList[j].uid < 65536) {
-			file_header = (_standardHeader*) res_man.open(_memList[j].uid);
+			file_header = (_standardHeader*) res_man->openResource(_memList[j].uid);
 			// close immediately so give a true count
-			res_man.close(_memList[j].uid);
+			res_man->closeResource(_memList[j].uid);
 
 			debug(5, "view %d", _memList[j].uid);
 
@@ -73,10 +73,10 @@
 					_memList[j].size / 1024,
 					(_memList[j].size * 100) / _totalFreeMemory,
 					_memList[j].uid,
-					res_man.fetchCluster(_memList[j].uid),
+					res_man->fetchCluster(_memList[j].uid),
 					file_header->name,
-					res_man.fetchAge(_memList[j].uid),
-					res_man.fetchCount(_memList[j].uid));
+					res_man->fetchAge(_memList[j].uid),
+					res_man->fetchCount(_memList[j].uid));
 			} else
 				Debug_Printf(" %d is an illegal resource\n", _memList[j].uid);
 		} else {
@@ -160,7 +160,7 @@
 	sprintf(string,
 		"locked(%u)+float(%u)+free(%u) = %u/%u blocks (%u%% used)(cur %uk)",
 		mem_locked, mem_floating, mem_free, blocksUsed, MAX_mem_blocks,
-		percent, (res_man.fetchUsage() / 1024));
+		percent, (res_man->fetchUsage() / 1024));
 }
 
 } // End of namespace Sword2

Index: memory.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/memory.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- memory.cpp	28 Oct 2003 19:51:29 -0000	1.15
+++ memory.cpp	3 Nov 2003 07:47:41 -0000	1.16
@@ -17,9 +17,6 @@
  * $Header$
  */
 
-// FIXME: We should investigate which problem all this memory managing stuff
-// is trying to solve. I'm not convinced that it's really needed.
-
 // memory manager
 //   - "remember, it's not good to leave memory locked for a moment longer
 //      than necessary" Tony
@@ -45,17 +42,13 @@
 
 namespace Sword2 {
 
-MemoryManager memory;
+MemoryManager *memory;
 
 #define MEMORY_POOL (1024 * 12000)
 
 // #define MEMDEBUG 1
 
-void MemoryManager::exit(void) {
-	free(_freeMemman);
-}
-
-void MemoryManager::init(void) {
+MemoryManager::MemoryManager(void) {
 	uint32 j;
 	uint8 *memory_base;
 
@@ -91,6 +84,10 @@
 	_baseMemBlock = 0;			// for now
 }
 
+MemoryManager::~MemoryManager(void) {
+	free(_freeMemman);
+}
+
 mem *MemoryManager::lowLevelAlloc(uint32 size, uint32 type, uint32 unique_id) {
 	// allocate a block of memory - locked or float
 
@@ -472,7 +469,7 @@
 
 	while (virtualDefrag(size)) {
 		// trash the oldest closed resource
-		if (!res_man.helpTheAgedOut()) {
+		if (!res_man->helpTheAgedOut()) {
 			error("alloc ran out of memory: size=%d type=%d unique_id=%d", size, type, unique_id);
 		}
 	}

Index: memory.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/memory.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- memory.h	26 Oct 2003 15:42:49 -0000	1.9
+++ memory.h	3 Nov 2003 07:47:41 -0000	1.10
@@ -34,10 +34,12 @@
 	uint8 *ad;
 } mem;
 
-#define	MEM_null			0	// null
-#define	MEM_free			1
-#define	MEM_locked			2
-#define	MEM_float			3
+enum {
+	MEM_null			= 0,	// null
+	MEM_free			= 1,
+	MEM_locked			= 2,
+	MEM_float			= 3
+};
 
 //---------------------------------------
 // MEMORY BLOCKS
@@ -48,17 +50,19 @@
 // highest recorded value from the on-screen info
 //---------------------------------------
 
-#define	UID_memman			0xffffffff
-#define	UID_NULL			0xfffffffe	// FREE
-#define	UID_font			0xfffffffd
-#define	UID_temp			0xfffffffc
-#define	UID_decompression_buffer	0xfffffffb
-#define	UID_shrink_buffer		0xfffffffa
-#define	UID_con_sprite			0xfffffff9
-#define	UID_text_sprite			0xfffffff8
-#define	UID_walk_anim			0xfffffff7
-#define	UID_savegame_buffer		0xfffffff6
-#define UID_restoregame_buffer		0xfffffff5
+enum {
+	UID_memman			= 0xffffffff,
+	UID_NULL			= 0xfffffffe,	// FREE
+	UID_font			= 0xfffffffd,
+	UID_temp			= 0xfffffffc,
+	UID_decompression_buffer	= 0xfffffffb,
+	UID_shrink_buffer		= 0xfffffffa,
+	UID_con_sprite			= 0xfffffff9,
+	UID_text_sprite			= 0xfffffff8,
+	UID_walk_anim			= 0xfffffff7,
+	UID_savegame_buffer		= 0xfffffff6,
+	UID_restoregame_buffer		= 0xfffffff5
+};
 
 class MemoryManager {
 private:
@@ -88,8 +92,9 @@
 	mem _memList[MAX_mem_blocks];
 	uint32 _baseMemBlock;
 
-	void init(void);
-	void exit(void);
+	MemoryManager(void);
+	~MemoryManager(void);
+
 	mem *allocMemory(uint32 size, uint32 type, uint32 unique_id);
 	void freeMemory(mem *block);
 	void floatMemory(mem *block);
@@ -100,7 +105,7 @@
 	void memoryString(char *string);
 };
 
-extern MemoryManager memory;
+extern MemoryManager *memory;
 
 } // End of namespace Sword2
 

Index: mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/mouse.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- mouse.cpp	2 Nov 2003 18:50:05 -0000	1.35
+++ mouse.cpp	3 Nov 2003 07:47:41 -0000	1.36
@@ -163,28 +163,28 @@
 				for (j = 0; j < ARRAYSIZE(icon_list); j++) {
 					// change all others to grey
 					if (j != hit) {
-						icon = res_man.open(icon_list[j]) + sizeof(_standardHeader);
+						icon = res_man->openResource(icon_list[j]) + sizeof(_standardHeader);
 						g_display->setMenuIcon(RDMENU_TOP, j, icon);
-						res_man.close( icon_list[j] );
+						res_man->closeResource(icon_list[j]);
 					}
 				}
 
 				g_sound->pauseFx();
 
 				// NB. Need to keep a safe copy of
-				// 'looping_music_id' for savegame & for
+				// '_loopingMusicId' for savegame & for
 				// playing when returning from control panels
 				// because control panel music will overwrite
 				// it!
 
-				safe_looping_music_id = looping_music_id;
+				safe_looping_music_id = _loopingMusicId;
 
 				pars[0] = 221;	// SystemM234 (M234.wav)
 				pars[1] = FX_LOOP;
 				g_logic.fnPlayMusic(pars);
 
 				// restore proper looping_music_id
-				looping_music_id = safe_looping_music_id;
+				_loopingMusicId = safe_looping_music_id;
 
 				// clear the screen & set up the new palette
 				// for the menus
@@ -251,8 +251,8 @@
 				// NB. This will also start music required
 				// when a game has been restored
 
-				if (looping_music_id) {
-					pars[0] = looping_music_id;
+				if (_loopingMusicId) {
+					pars[0] = _loopingMusicId;
 					pars[1] = FX_LOOP;
 					g_logic.fnPlayMusic(pars);
 
@@ -323,7 +323,7 @@
 
 			setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
 
-			debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID));
+			debug(5, "USED \"%s\" ICON ON %s", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID));
 
 			// Hide menu - back to normal menu mode
 
@@ -368,7 +368,7 @@
 
 						noHuman();
 
-						debug(5, "USED \"%s\" ICON ON \"%s\" ICON", FetchObjectName(OBJECT_HELD), FetchObjectName(COMBINE_BASE));
+						debug(5, "USED \"%s\" ICON ON \"%s\" ICON", fetchObjectName(OBJECT_HELD), fetchObjectName(COMBINE_BASE));
 					}
 
 					// refresh the menu
@@ -420,7 +420,7 @@
 
 					EXIT_CLICK_ID = 0;
 
-					debug(5, "RIGHT-CLICKED ON \"%s\" ICON", FetchObjectName(OBJECT_HELD));
+					debug(5, "RIGHT-CLICKED ON \"%s\" ICON", fetchObjectName(OBJECT_HELD));
 
 					setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT);
 
@@ -629,11 +629,11 @@
 				setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
 
 				if (OBJECT_HELD)
-					debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID));
+					debug(5, "USED \"%s\" ICON ON %s", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID));
 				else if (LEFT_BUTTON)
-					debug(5, "LEFT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+					debug(5, "LEFT-CLICKED ON %s", fetchObjectName(CLICKED_ID));
 				else	// RIGHT BUTTON
-					debug(5, "RIGHT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+					debug(5, "RIGHT-CLICKED ON %s", fetchObjectName(CLICKED_ID));
 			}
 		}
 	}
@@ -694,7 +694,7 @@
 				setLuggage(_currentLuggageResource);
 			}
 		} else
-			error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", _mouseTouching, FetchObjectName(_mouseTouching));
+			error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", _mouseTouching, fetchObjectName(_mouseTouching));
 	} else if (_oldMouseTouching && !_mouseTouching) {
 		// the cursor has moved off something - reset cursor to
 		// normal pointer
@@ -741,8 +741,8 @@
 	_mousePointerRes = res;
 
 	if (res) {
-		icon = res_man.open(res) + sizeof(_standardHeader);
-		len = res_man._resList[res]->size - sizeof(_standardHeader);
+		icon = res_man->openResource(res) + sizeof(_standardHeader);
+		len = res_man->_resList[res]->size - sizeof(_standardHeader);
 
 		// don't pulse the normal pointer - just do the regular anim
 		// loop
@@ -752,7 +752,7 @@
 		else
  			g_display->setMouseAnim(icon, len, RDMOUSE_FLASH);
 
-		res_man.close(res);
+		res_man->closeResource(res);
 	} else {
 		// blank cursor
 		g_display->setMouseAnim(NULL, 0, 0);
@@ -766,12 +766,12 @@
 	_realLuggageItem = res;
 
 	if (res) {
-		icon = res_man.open(res) + sizeof(_standardHeader);
-		len = res_man._resList[res]->size - sizeof(_standardHeader);
+		icon = res_man->openResource(res) + sizeof(_standardHeader);
+		len = res_man->_resList[res]->size - sizeof(_standardHeader);
 
 		g_display->setLuggageAnim(icon, len);
 
-		res_man.close(res);
+		res_man->closeResource(res);
 	} else
 		g_display->setLuggageAnim(NULL, 0);
 }
@@ -960,7 +960,7 @@
 			local_text = text_id & 0xffff;
 
 			// open text file & get the line
-			text = FetchTextLine(res_man.open(text_res), local_text);
+			text = fetchTextLine(res_man->openResource(text_res), local_text);
 
 			// 'text+2' to skip the first 2 bytes which form the
 			// line reference number
@@ -973,7 +973,7 @@
 				_speechFontId, justification);
 
 			// now ok to close the text file
-			res_man.close(text_res);
+			res_man->closeResource(text_res);
 		}
 	}
 }
@@ -1135,12 +1135,12 @@
 		// stops all fx & clears the queue - eg. when leaving a
 		// location
 
-		Clear_fx_queue();
+		g_sword2->clearFxQueue();
 
 		// Trash all object resources so they load in fresh & restart
 		// their logic scripts
 
-		res_man.killAllObjects(false);
+		res_man->killAllObjects(false);
 
 		g_display->setPalette(0, 1, black, RDPAL_INSTANT);
 	}

Index: protocol.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/protocol.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- protocol.cpp	28 Oct 2003 19:51:29 -0000	1.18
+++ protocol.cpp	3 Nov 2003 07:47:41 -0000	1.19
@@ -28,10 +28,12 @@
 
 namespace Sword2 {
 
-// Returns a pointer to the first palette entry, given the pointer to the
-// start of the screen file.
+/**
+ * Returns a pointer to the first palette entry, given the pointer to the start
+ * of the screen file.
+ */
 
-uint8 *FetchPalette(uint8 *screenFile) {
+uint8 *Sword2Engine::fetchPalette(uint8 *screenFile) {
 	uint8 *palette;
 
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
@@ -50,35 +52,41 @@
 	return palette;
 }
 
-// Returns a pointer to the start of the palette match table, given the
-// pointer to the start of the screen file.
+/**
+ * Returns a pointer to the start of the palette match table, given the pointer
+ * to the start of the screen file.
+ */
 
-uint8 *FetchPaletteMatchTable(uint8 *screenFile) {
+uint8 *Sword2Engine::fetchPaletteMatchTable(uint8 *screenFile) {
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
 
 	return (uint8 *) mscreenHeader + mscreenHeader->paletteTable;
 }
 
-// Returns a pointer to the screen header, given the pointer to the start of
-// the screen file.
+/**
+ * Returns a pointer to the screen header, given the pointer to the start of
+ * the screen file.
+ */
 
-_screenHeader *FetchScreenHeader(uint8 *screenFile) {
+_screenHeader *Sword2Engine::fetchScreenHeader(uint8 *screenFile) {
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
 	_screenHeader *screenHeader = (_screenHeader*) ((uint8 *) mscreenHeader + mscreenHeader->screen);
 
 	return screenHeader;
 }
 
-// Returns a pointer to the requested layer header, given the pointer to the
-// start of the screen file. Drops out if the requested layer number exceeds
-// the number of layers on this screen.
+/**
+ * Returns a pointer to the requested layer header, given the pointer to the
+ * start of the screen file. Drops out if the requested layer number exceeds
+ * the number of layers on this screen.
+ */
 
-_layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo) {	// Chris 04Oct96
+_layerHeader *Sword2Engine::fetchLayerHeader(uint8 *screenFile, uint16 layerNo) {
 #ifdef _SWORD2_DEBUG
-	_screenHeader *screenHead = FetchScreenHeader(screenFile);
+	_screenHeader *screenHead = fetchScreenHeader(screenFile);
 
 	if (layerNo > screenHead->noLayers - 1)
-		error("FetchLayerHeader(%d) invalid layer number!", layerNo);
+		error("fetchLayerHeader(%d) invalid layer number!", layerNo);
 #endif
 
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
@@ -88,76 +96,86 @@
 	return layerHeader;
 }
 
-// Returns a pointer to the start of the shading mask, given the pointer to
-// the start of the screen file.
+/**
+ * Returns a pointer to the start of the shading mask, given the pointer to the
+ * start of the screen file.
+ */
 
-uint8 *FetchShadingMask(uint8 *screenFile) {
+uint8 *Sword2Engine::fetchShadingMask(uint8 *screenFile) {
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
 
 	return (uint8 *) mscreenHeader + mscreenHeader->maskOffset;
 }
 
-// Returns a pointer to the anim header, given the pointer to the start of
-// the anim file.
+/**
+ * Returns a pointer to the anim header, given the pointer to the start of the
+ * anim file.
+ */
 
-_animHeader *FetchAnimHeader(uint8 *animFile) {
+_animHeader *Sword2Engine::fetchAnimHeader(uint8 *animFile) {
 	return (_animHeader *) (animFile + sizeof(_standardHeader));
 }
 
-// Returns a pointer to the requested frame number's cdtEntry, given the
-// pointer to the start of the anim file. Drops out if the requested frame
-// number exceeds the number of frames in this anim.
+/**
+ * Returns a pointer to the requested frame number's cdtEntry, given the
+ * pointer to the start of the anim file. Drops out if the requested frame
+ * number exceeds the number of frames in this anim.
+ */
 
-_cdtEntry *FetchCdtEntry(uint8 *animFile, uint16 frameNo) {
-	_animHeader *animHead = FetchAnimHeader(animFile);
+_cdtEntry *Sword2Engine::fetchCdtEntry(uint8 *animFile, uint16 frameNo) {
+	_animHeader *animHead = fetchAnimHeader(animFile);
 
 #ifdef _SWORD2_DEBUG
 	if (frameNo > animHead->noAnimFrames - 1)
-		error("FetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
+		error("fetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
 #endif
 
 	return (_cdtEntry *) ((uint8 *) animHead + sizeof(_animHeader) + frameNo * sizeof(_cdtEntry));
 }
 
-// Returns a pointer to the requested frame number's header, given the
-// pointer to the start of the anim file. Drops out if the requested frame
-// number exceeds the number of frames in this anim
+/**
+ * Returns a pointer to the requested frame number's header, given the pointer
+ * to the start of the anim file. Drops out if the requested frame number
+ * exceeds the number of frames in this anim
+ */
 
-_frameHeader *FetchFrameHeader(uint8 *animFile, uint16 frameNo)	{
+_frameHeader *Sword2Engine::fetchFrameHeader(uint8 *animFile, uint16 frameNo)	{
 	// required address = (address of the start of the anim header) + frameOffset
-	return (_frameHeader *) (animFile + sizeof(_standardHeader) + FetchCdtEntry(animFile, frameNo)->frameOffset);
+	return (_frameHeader *) (animFile + sizeof(_standardHeader) + fetchCdtEntry(animFile, frameNo)->frameOffset);
 }
 
-// Returns a pointer to the requested parallax layer data.
+/**
+ * Returns a pointer to the requested parallax layer data.
+ */
 
-_parallax *FetchBackgroundParallaxLayer(uint8 *screenFile, int layer) {
+_parallax *Sword2Engine::fetchBackgroundParallaxLayer(uint8 *screenFile, int layer) {
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
 
 #ifdef _SWORD2_DEBUG
 	if (mscreenHeader->bg_parallax[layer] == 0)
-		error("FetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
+		error("fetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
 #endif
 
 	return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->bg_parallax[layer]);
 }
 
-_parallax *FetchBackgroundLayer(uint8 *screenFile) {
+_parallax *Sword2Engine::fetchBackgroundLayer(uint8 *screenFile) {
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
 
 #ifdef _SWORD2_DEBUG
 	if (mscreenHeader->screen == 0)
-		error("FetchBackgroundLayer (%d) - No background layer exists");
+		error("fetchBackgroundLayer (%d) - No background layer exists");
 #endif
 
 	return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->screen + sizeof(_screenHeader));
 }
 
-_parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer) {
+_parallax *Sword2Engine::fetchForegroundParallaxLayer(uint8 *screenFile, int layer) {
 	_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
 
 #ifdef _SWORD2_DEBUG
 	if (mscreenHeader->fg_parallax[layer] == 0)
-		error("FetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
+		error("fetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
 #endif
 
 	return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->fg_parallax[layer]);
@@ -165,7 +183,7 @@
 
 uint8 errorLine[128];
 
-uint8 *FetchTextLine(uint8 *file, uint32 text_line) {
+uint8 *Sword2Engine::fetchTextLine(uint8 *file, uint32 text_line) {
 	_standardHeader *fileHeader;
 	uint32 *point;
 
@@ -182,7 +200,7 @@
 		return errorLine;
 	}
 
-	//point to the lookup table
+	// point to the lookup table
 	point = (uint32 *) text_header + 1;
 
 	return (uint8 *) (file + READ_LE_UINT32(point + text_line));
@@ -191,7 +209,7 @@
 
 // Used for testing text & speech (see fnISpeak in speech.cpp)
 
-uint8 CheckTextLine(uint8 *file, uint32	text_line) {
+uint8 Sword2Engine::checkTextLine(uint8 *file, uint32 text_line) {
 	_textHeader *text_header = (_textHeader *) (file + sizeof(_standardHeader));
 
 	// out of range => invalid
@@ -202,11 +220,11 @@
 	return 1;
 }
 
-uint8 *FetchObjectName(int32 resourceId) {
+uint8 *Sword2Engine::fetchObjectName(int32 resourceId) {
 	_standardHeader *header;
 	
-	header = (_standardHeader *) res_man.open(resourceId);
-	res_man.close(resourceId);
+	header = (_standardHeader *) res_man->openResource(resourceId);
+	res_man->closeResource(resourceId);
 
 	// note this pointer is no longer valid, but it should be ok until
 	// another resource is opened!

Index: protocol.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/protocol.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- protocol.h	28 Oct 2003 19:51:29 -0000	1.6
+++ protocol.h	3 Nov 2003 07:47:41 -0000	1.7
@@ -22,27 +22,7 @@
 #ifndef	_PROTOCOL
 #define	_PROTOCOL
 
-#include "sword2/driver/driver96.h"
-#include "sword2/header.h"
-
 namespace Sword2 {
-
-uint8 *FetchPalette(uint8 *screenFile);
-_screenHeader *FetchScreenHeader(uint8 *screenFile);
-_layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo);
-uint8 *FetchShadingMask(uint8 *screenFile);
-
-_animHeader *FetchAnimHeader(uint8 *animFile);
-_cdtEntry *FetchCdtEntry(uint8 *animFile, uint16 frameNo);
-_frameHeader *FetchFrameHeader(uint8 *animFile, uint16 frameNo);
-_parallax *FetchBackgroundParallaxLayer(uint8 *screenFile, int layer);
-_parallax *FetchBackgroundLayer(uint8 *screenFile);
-_parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer);
-uint8 *FetchTextLine(uint8 *file, uint32 text_line);
-uint8 CheckTextLine(uint8 *file, uint32	text_line);
-uint8 *FetchPaletteMatchTable(uint8 *screenFile);
-uint8 *FetchObjectName(int32 resourceId);
-
 } // End of namespace Sword2
 
 #endif

Index: resman.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- resman.cpp	2 Nov 2003 18:50:06 -0000	1.60
+++ resman.cpp	3 Nov 2003 07:47:41 -0000	1.61
@@ -33,7 +33,7 @@
 #include "sword2/mouse.h"	// for system setMouse & setLuggage routines
 #include "sword2/protocol.h"
 #include "sword2/resman.h"
-#include "sword2/sound.h"	// for Clear_fx_queue() called from cacheNewCluster()
+#include "sword2/sound.h"	// for clearFxQueue() called from cacheNewCluster()
 #include "sword2/router.h"
 
 namespace Sword2 {
@@ -54,7 +54,7 @@
 
 #define BUFFERSIZE	4096
 
-ResourceManager	res_man;	//declare the object global
+ResourceManager	*res_man;	// declare the object global
 
 // ---------------------------------------------------------------------------
 //
@@ -64,11 +64,13 @@
 //
 // ---------------------------------------------------------------------------
 
-#define BOTH		0x0		// Cluster is on both CDs
-#define CD1		0x1		// Cluster is on CD1 only
-#define CD2		0x2		// Cluster is on CD2 only
-#define LOCAL_CACHE	0x4		// Cluster is cached on HDD
-#define LOCAL_PERM	0x8		// Cluster is on HDD.
+enum {
+	BOTH		= 0x0,		// Cluster is on both CDs
+	CD1		= 0x1,		// Cluster is on CD1 only
+	CD2		= 0x2,		// Cluster is on CD2 only
+	LOCAL_CACHE	= 0x4,		// Cluster is cached on HDD
+	LOCAL_PERM	= 0x8		// Cluster is on HDD.
+};
 
 #if !defined(__GNUC__)
 	#pragma START_PACK_STRUCTS
@@ -83,9 +85,7 @@
 	#pragma END_PACK_STRUCTS
 #endif
 
-// FIXME: Should init() / exit() be moved to constructor / destructor instead?
-
-void ResourceManager::init(void) {
+ResourceManager::ResourceManager(void) {
 	// We read in the resource info which tells us the names of the
 	// resource cluster files ultimately, although there might be groups
 	// within the clusters at this point it makes no difference. We only
@@ -106,7 +106,7 @@
 	end = file.size();
 
 	//get some space for the incoming resource file - soon to be trashed
-	temp = memory.allocMemory(end, MEM_locked, UID_temp);
+	temp = memory->allocMemory(end, MEM_locked, UID_temp);
 
 	if (file.read(temp->ad, end) != end) {
 		file.close();
@@ -208,7 +208,7 @@
 	}
 
 	_resTime = 1;	//cannot start at 0
-	memory.freeMemory(temp);	//get that memory back
+	memory->freeMemory(temp);	//get that memory back
 
 	// FIXME: Is this really needed?
 
@@ -235,7 +235,7 @@
 		file.close();
 }
 
-void ResourceManager::exit(void) {
+ResourceManager::~ResourceManager(void) {
 	// free up our mallocs
 	free(_resList);
 	free(_age);
@@ -428,11 +428,11 @@
 	}
 }
 
-uint8 *ResourceManager::open(uint32 res) {
+uint8 *ResourceManager::openResource(uint32 res) {
 	// returns ad of resource. Loads if not in memory
 	// retains a count
 	// resource can be aged out of memory if count = 0
-	// the resource is locked while count != 0 i.e. until a res_close is
+	// the resource is locked while count != 0 i.e. until a closeResource is
 	// called
 
 	File	file;
@@ -528,13 +528,13 @@
 
 		// ok, we know the length so try and allocate the memory
 		// if it can't then old files will be ditched until it works
-		_resList[res] = memory.allocMemory(len, MEM_locked, res);
+		_resList[res] = memory->allocMemory(len, MEM_locked, res);
 
 		// now load the file
 		// hurray, load it in.
 		file.read(_resList[res]->ad, len);
 
-		//close the cluster
+		// close the cluster
 		file.close();
 
 #ifdef SCUMM_BIG_ENDIAN
@@ -553,7 +553,7 @@
 
 	// pass the address of the mem & lock the memory too
 	// might be locked already (if count > 1)
-	memory.lockMemory(_resList[res]);
+	memory->lockMemory(_resList[res]);
 
 	return (uint8 *) _resList[res]->ad;
 }
@@ -614,7 +614,7 @@
 	return _currentMemoryUsage;
 }
 
-void ResourceManager::close(uint32 res) {
+void ResourceManager::closeResource(uint32 res) {
 	// decrements the count
 	// resource floats when count = 0
 
@@ -624,7 +624,7 @@
 
 	//closing but isnt open?
 	if (!(_count[res]))
-		error("close: closing %d but it isn't open", res);
+		error("closeResource: closing %d but it isn't open", res);
 //#endif
 
 	//one less has it open
@@ -633,7 +633,7 @@
 	//if noone has the file open then unlock and allow to float
 	if (!_count[res]) {
 		// pass the address of the mem
-		memory.floatMemory(_resList[res]);
+		memory->floatMemory(_resList[res]);
 	}
 }
 
@@ -723,7 +723,7 @@
 	// trash this old resource
 
 	_age[oldest_res] = 0;		// effectively gone from _resList
-	memory.freeMemory(_resList[oldest_res]);	// release the memory too
+	memory->freeMemory(_resList[oldest_res]);	// release the memory too
 
 	return _resList[oldest_res]->size;	// return bytes freed
 }
@@ -745,8 +745,8 @@
 	else if (_resConvTable[res * 2] == 0xffff)
 		Debug_Printf("%d is a null & void resource number\n", res);
 	else {
-		//open up the resource and take a look inside!
-		file_header = (_standardHeader*) res_man.open(res);
+		// open up the resource and take a look inside!
+		file_header = (_standardHeader*) openResource(res);
 
 		// Debug_Printf("%d\n", file_header->fileType);
 		// Debug_Printf("%s\n", file_header->name);
@@ -826,7 +826,7 @@
 			Debug_Printf("unrecognised fileType %d\n", file_header->fileType);
 			break;
 		}
-		res_man.close(res);
+		closeResource(res);
 	}
 }
 
@@ -840,7 +840,7 @@
 	if (!_count[res]) {
 		if (_age[res]) {
 			_age[res] = 0;		// effectively gone from _resList
-			memory.freeMemory(_resList[res]);	// release the memory too
+			memory->freeMemory(_resList[res]);	// release the memory too
 			Debug_Printf("Trashed %d\n", res);
 		} else
 			Debug_Printf("%d not in memory\n", res);
@@ -851,7 +851,7 @@
 void ResourceManager::remove(uint32 res) {
 	if (_age[res]) {
 		_age[res] = 0;			// effectively gone from _resList
-		memory.freeMemory(_resList[res]);	// release the memory too
+		memory->freeMemory(_resList[res]);	// release the memory too
 		debug(5, " - Trashing %d", res);
 	} else
 		debug(5, "remove(%d) not even in memory!", res);
@@ -864,16 +864,16 @@
 	int j;
 	uint32 res;
 
-	j = memory._baseMemBlock;
+	j = memory->_baseMemBlock;
 
 	do {
-		if (memory._memList[j].uid < 65536) {	// a resource
-			res = memory._memList[j].uid;
+		if (memory->_memList[j].uid < 65536) {	// a resource
+			res = memory->_memList[j].uid;
 			_age[res] = 0;		// effectively gone from _resList
-			memory.freeMemory(_resList[res]);	// release the memory too
+			memory->freeMemory(_resList[res]);	// release the memory too
 		}
 
-		j = memory._memList[j].child;
+		j = memory->_memList[j].child;
 	} while	(j != -1);
 }
 
@@ -887,20 +887,20 @@
 	uint32 nuked = 0;
   	_standardHeader *header;
 
-	j = memory._baseMemBlock;
+	j = memory->_baseMemBlock;
 
 	do {
-		if (memory._memList[j].uid < 65536) {	// a resource
-			res = memory._memList[j].uid;
+		if (memory->_memList[j].uid < 65536) {	// a resource
+			res = memory->_memList[j].uid;
 
 			// not the global vars which are assumed to be open in
 			// memory & not the player object!
 			if (res != 1 && res != CUR_PLAYER_ID) {
-				header = (_standardHeader *) res_man.open(res);
-				res_man.close(res);
+				header = (_standardHeader *) openResource(res);
+				closeResource(res);
 
 				_age[res] = 0;		// effectively gone from _resList
-				memory.freeMemory(_resList[res]);	// release the memory too
+				memory->freeMemory(_resList[res]);	// release the memory too
 				nuked++;
 
 				// if this was called from the console,
@@ -910,7 +910,7 @@
 				}	
 			}
 		}
-		j = memory._memList[j].child;
+		j = memory->_memList[j].child;
 	} while (j != -1);
 
 	// if this was called from the console
@@ -937,20 +937,20 @@
 	uint32 nuked = 0;
  	_standardHeader *header;
 
-	j = memory._baseMemBlock;
+	j = memory->_baseMemBlock;
 
 	do {
-		if (memory._memList[j].uid < 65536) {	// a resource
-			res = memory._memList[j].uid;
+		if (memory->_memList[j].uid < 65536) {	// a resource
+			res = memory->_memList[j].uid;
 			//not the global vars which are assumed to be open in
 			// memory & not the player object!
 			if (res != 1 && res != CUR_PLAYER_ID) {
-				header = (_standardHeader*) res_man.open(res);
-				res_man.close(res);
+				header = (_standardHeader*) openResource(res);
+				closeResource(res);
 
 				if (header->fileType == GAME_OBJECT) {
 					_age[res] = 0;		// effectively gone from _resList
-					memory.freeMemory(_resList[res]);	// release the memory too
+					memory->freeMemory(_resList[res]);	// release the memory too
    					nuked++;
 
 					// if this was called from the console
@@ -961,7 +961,7 @@
 				}
 			}
 		}
-		j = memory._memList[j].child;
+		j = memory->_memList[j].child;
 	} while (j != -1);
 
 	// if this was called from the console
@@ -981,7 +981,7 @@
 
 	g_logic.fnStopMusic(NULL);
 
-	Clear_fx_queue();	// stops all fx & clears the queue (James22july97)
+	g_sword2->clearFxQueue();	// stops all fx & clears the queue (James22july97)
 	getCd(_cdTab[newCluster] & 3);
 
 	// Kick out old cached cluster and load the new one.
@@ -1031,16 +1031,16 @@
 	g_sword2->setLuggage(0);
 
 	uint8 *bgfile;
-	bgfile = res_man.open(2950);	// open the screen resource
+	bgfile = openResource(2950);	// open the screen resource
 	g_display->initialiseBackgroundLayer(NULL);
 	g_display->initialiseBackgroundLayer(NULL);
-	g_display->initialiseBackgroundLayer(FetchBackgroundLayer(bgfile));
+	g_display->initialiseBackgroundLayer(g_sword2->fetchBackgroundLayer(bgfile));
 	g_display->initialiseBackgroundLayer(NULL);
 	g_display->initialiseBackgroundLayer(NULL);
-	g_display->setPalette(0, 256, FetchPalette(bgfile), RDPAL_FADE);
+	g_display->setPalette(0, 256, g_sword2->fetchPalette(bgfile), RDPAL_FADE);
 
-	g_display->renderParallax(FetchBackgroundLayer(bgfile), 2);
-	res_man.close(2950);		// release the screen resource
+	g_display->renderParallax(g_sword2->fetchBackgroundLayer(bgfile), 2);
+	closeResource(2950);		// release the screen resource
 
 	// Git rid of read-only status, if it is set.
 	SVM_SetFileAttributes(_resourceFiles[newCluster], FILE_ATTRIBUTE_NORMAL);
@@ -1061,7 +1061,7 @@
 	uint8 *loadingBar;
 	_cdtEntry *cdt;
 
-	text_spr = fontRenderer.makeTextSprite(FetchTextLine(res_man.open(2283), 8) + 2, 640, 187, g_sword2->_speechFontId);
+	text_spr = fontRenderer.makeTextSprite(g_sword2->fetchTextLine(openResource(2283), 8) + 2, 640, 187, g_sword2->_speechFontId);
 
 	frame = (_frameHeader*) text_spr->ad;
 
@@ -1076,12 +1076,12 @@
 	textSprite.blend = 0;
 	textSprite.colourTable	= 0;
 
-	res_man.close(2283);
+	closeResource(2283);
 
-	loadingBar = res_man.open(2951);
+	loadingBar = openResource(2951);
 
-	frame = FetchFrameHeader(loadingBar, 0);
-	cdt   = FetchCdtEntry(loadingBar, 0);
+	frame = g_sword2->fetchFrameHeader(loadingBar, 0);
+	cdt   = g_sword2->fetchCdtEntry(loadingBar, 0);
 
 	barSprite.x = cdt->x;
 	barSprite.y = cdt->y;
@@ -1094,12 +1094,12 @@
 	barSprite.blend = 0;
 	barSprite.colourTable = 0;
 
-	res_man.close(2951);
+	closeResource(2951);
 
-	loadingBar = res_man.open(2951);
-	frame = FetchFrameHeader(loadingBar, 0);
+	loadingBar = openResource(2951);
+	frame = g_sword2->fetchFrameHeader(loadingBar, 0);
 	barSprite.data = (uint8 *) (frame + 1);
-	res_man.close(2951);
+	closeResource(2951);
 
 	int16 barX = barSprite.x;
 	int16 barY = barSprite.y;
@@ -1137,14 +1137,14 @@
 		if (step == stepSize) {
 			step = 0;
 			// open the screen resource
-			bgfile = res_man.open(2950);
-			g_display->renderParallax(FetchBackgroundLayer(bgfile), 2);
+			bgfile = openResource(2950);
+			g_display->renderParallax(g_sword2->fetchBackgroundLayer(bgfile), 2);
 			// release the screen resource
-			res_man.close(2950);
-			loadingBar = res_man.open(2951);
-			frame = FetchFrameHeader(loadingBar, fr);
+			closeResource(2950);
+			loadingBar = openResource(2951);
+			frame = g_sword2->fetchFrameHeader(loadingBar, fr);
 			barSprite.data = (uint8 *) (frame + 1);
-			res_man.close(2951);
+			closeResource(2951);
 			g_display->drawSprite(&barSprite);
 			barSprite.x = barX;
 			barSprite.y = barY;
@@ -1167,7 +1167,7 @@
 
 	inFile.close();
 	outFile.close();
-	memory.freeMemory(text_spr);
+	memory->freeMemory(text_spr);
 
 	g_display->clearScene();
 
@@ -1284,9 +1284,9 @@
 
 	g_logic.fnStopMusic(NULL);
 
-	textRes = res_man.open(2283);
-	g_sword2->displayMsg(FetchTextLine(textRes, 5 + cd) + 2, 0);
-	text_spr = fontRenderer.makeTextSprite(FetchTextLine(textRes, 5 + cd) + 2, 640, 187, g_sword2->_speechFontId);
+	textRes = openResource(2283);
+	g_sword2->displayMsg(g_sword2->fetchTextLine(textRes, 5 + cd) + 2, 0);
+	text_spr = fontRenderer.makeTextSprite(g_sword2->fetchTextLine(textRes, 5 + cd) + 2, 640, 187, g_sword2->_speechFontId);
 
 	frame = (_frameHeader*) text_spr->ad;
 
@@ -1304,7 +1304,7 @@
 	oldY = spriteInfo.y;
 	oldX = spriteInfo.x;
 
-	res_man.close(2283);
+	closeResource(2283);
 
 	do {
 		if (offNetwork == 1)
@@ -1337,7 +1337,7 @@
 		spriteInfo.x = oldX;
 	} while (!done);
 
-	memory.freeMemory(text_spr);
+	memory->freeMemory(text_spr);
 	g_sword2->removeMsg();
 }
 

Index: resman.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- resman.h	28 Oct 2003 19:51:29 -0000	1.12
+++ resman.h	3 Nov 2003 07:47:41 -0000	1.13
@@ -28,16 +28,16 @@
 
 class ResourceManager {
 public:
-	void init(void);		// read in the config file
-	void exit(void);
+	ResourceManager(void);		// read in the config file
+	~ResourceManager(void);
 
 	// Returns ad of resource. Loads if not in memory. Retains a count.
 	// Resource can be aged out of memory if count = 0
 	// The resource is locked while count != 0
 	// Resource floats when count = 0
 
-	uint8 *open(uint32 res);
-	void close(uint32 res);		// decrements the count
+	uint8 *openResource(uint32 res);
+	void closeResource(uint32 res);		// decrements the count
 
 	// returns '0' if resource out of range or null, otherwise '1' for ok
 
@@ -105,7 +105,7 @@
 	char _cdDrives[24];
 };							
 
-extern ResourceManager res_man;	//declare the object global
+extern ResourceManager *res_man;	// declare the object global
 
 } // End of namespace Sword2
 

Index: router.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/router.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- router.cpp	28 Oct 2003 19:51:29 -0000	1.26
+++ router.cpp	3 Nov 2003 07:47:41 -0000	1.27
@@ -117,7 +117,7 @@
 	if (_routeSlots[slotNo])
 		freeRouteMem();
 
-	_routeSlots[slotNo] = memory.allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim);
+	_routeSlots[slotNo] = memory->allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim);
 
 	// 12000 bytes were used for this in Sword1 mega compacts, based on
 	// 20 bytes per '_walkData' frame
@@ -135,14 +135,14 @@
 _walkData* Router::lockRouteMem(void) {
 	uint8 slotNo = returnSlotNo(ID); 
 	
-	memory.lockMemory(_routeSlots[slotNo]);
+	memory->lockMemory(_routeSlots[slotNo]);
 	return (_walkData *) _routeSlots[slotNo]->ad;
 }
 
 void Router::floatRouteMem(void) {
 	uint8 slotNo = returnSlotNo(ID); 
 
-	memory.floatMemory(_routeSlots[slotNo]);
+	memory->floatMemory(_routeSlots[slotNo]);
 }
 
 void Router::freeRouteMem(void) {
@@ -150,7 +150,7 @@
 
 	// free the mem block pointed to from this entry of _routeSlots[]
 
-	memory.freeMemory(_routeSlots[slotNo]);
+	memory->freeMemory(_routeSlots[slotNo]);
 	_routeSlots[slotNo] = NULL;
 }
 
@@ -159,7 +159,7 @@
 		if (_routeSlots[i]) {
 			// free the mem block pointed to from this entry of
 			// _routeSlots[]
-			memory.freeMemory(_routeSlots[i]);
+			memory->freeMemory(_routeSlots[i]);
 			_routeSlots[i] = NULL;
 		}
 	}
@@ -2561,7 +2561,7 @@
 	for (int i = 0; i < MAX_WALKGRIDS; i++) {
 		if (_walkGridList[i]) {
 			// open walk grid file
-			fPolygrid = res_man.open(_walkGridList[i]);
+			fPolygrid = res_man->openResource(_walkGridList[i]);
  			fPolygrid += sizeof(_standardHeader);
  			memmove((uint8 *) &floorHeader, fPolygrid, sizeof(_walkGridHeader));
  			fPolygrid += sizeof(_walkGridHeader);
@@ -2603,7 +2603,7 @@
 			}
 
 			// close walk grid file
-			res_man.close(_walkGridList[i]);
+			res_man->closeResource(_walkGridList[i]);
 
 			// increment counts of total bars & nodes in whole
 			// walkgrid

Index: save_rest.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/save_rest.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- save_rest.cpp	2 Nov 2003 17:17:09 -0000	1.32
+++ save_rest.cpp	3 Nov 2003 07:47:41 -0000	1.33
@@ -50,43 +50,8 @@
 // max length of a savegame filename, including full path
 #define	MAX_FILENAME_LEN 128
 
-static void GetPlayerStructures(void);
-static void PutPlayerStructures(void);
-
-static uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
-static uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
-
-static uint32 CalcChecksum(uint8 *buffer, uint32 size);
-
-// savegame file header
-
-typedef	struct {
-	// sum of all bytes in file, excluding this uint32
-	uint32 checksum;
-
-	// player's description of savegame
-	char description[SAVE_DESCRIPTION_LEN];
-
-	uint32 varLength;	// length of global variables resource
-	uint32 screenId;	// resource id of screen file
-	uint32 runListId;	// resource id of run list
-	uint32 feet_x;		// copy of _thisScreen.feet_x
-	uint32 feet_y;		// copy of _thisScreen.feet_y
-	uint32 music_id;	// copy of 'looping_music_id'
-	_object_hub player_hub;	// copy of player object's object_hub structure
-	Object_logic logic;	// copy of player character logic structure
-
-	// copy of player character graphic structure
-	Object_graphic	graphic;
-
-	Object_mega mega;	// copy of player character mega structure
-} _savegameHeader;
-
 // savegame consists of header & global variables resource
 
-// global because easier to copy to/from player object structures
-static _savegameHeader g_header;
-
 #ifdef SCUMM_BIG_ENDIAN
 // Quick macro to make swapping in-place easier to write
 #define SWAP32(x)	x = SWAP_BYTES_32(x)
@@ -135,70 +100,70 @@
 
 // SAVE GAME
 
-uint32 SaveGame(uint16 slotNo, uint8 *desc) {
+uint32 Sword2Engine::saveGame(uint16 slotNo, uint8 *desc) {
 	mem *saveBufferMem;
 	uint32 bufferSize;
 	uint32 errorCode;
 
 	// allocate the savegame buffer
 
-	bufferSize = FindBufferSize();
-	saveBufferMem = memory.allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
+	bufferSize = findBufferSize();
+	saveBufferMem = memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
 
-	FillSaveBuffer(saveBufferMem, bufferSize, desc);
+	fillSaveBuffer(saveBufferMem, bufferSize, desc);
 
 	// save it (hopefully no longer platform-specific)
 
 	// save the buffer
-	errorCode = SaveData(slotNo, saveBufferMem->ad, bufferSize);
+	errorCode = saveData(slotNo, saveBufferMem->ad, bufferSize);
 
 	// free the buffer
 
-	memory.freeMemory(saveBufferMem);
+	memory->freeMemory(saveBufferMem);
 
 	return errorCode;
 }
 
 // calculate size of required savegame buffer
 
-uint32 FindBufferSize(void) {
+uint32 Sword2Engine::findBufferSize(void) {
 	// size of savegame header + size of global variables
-	return sizeof(g_header) + res_man.fetchLen(1);
+	return sizeof(g_header) + res_man->fetchLen(1);
 }
 
-void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
-	uint8	*varsRes;
+void Sword2Engine::fillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
+	uint8 *varsRes;
 
 	// set up the g_header
 
 	// 'checksum' gets filled in last of all
 
 	// player's description of savegame
-	sprintf(g_header.description, "%s", (char*) desc);
+	strcpy(g_header.description, (char *) desc);
 
 	// length of global variables resource
-	g_header.varLength = res_man.fetchLen(1);
+	g_header.varLength = res_man->fetchLen(1);
 
 	// resource id of current screen file
-	g_header.screenId = g_sword2->_thisScreen.background_layer_id;
+	g_header.screenId = _thisScreen.background_layer_id;
 
 	// resource id of current run-list
 	g_header.runListId = g_logic.getRunList();
 
 	// those scroll position control things
-	g_header.feet_x = g_sword2->_thisScreen.feet_x;
-	g_header.feet_y	= g_sword2->_thisScreen.feet_y;
+	g_header.feet_x = _thisScreen.feet_x;
+	g_header.feet_y	= _thisScreen.feet_y;
 
 	// id of currently looping music (or zero)
-	g_header.music_id = looping_music_id;
+	g_header.music_id = _loopingMusicId;
 
 	// object hub
-	memcpy(&g_header.player_hub, res_man.open(CUR_PLAYER_ID) + sizeof(_standardHeader), sizeof(_object_hub));
-	res_man.close(CUR_PLAYER_ID);
+	memcpy(&g_header.player_hub, res_man->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), sizeof(_object_hub));
+	res_man->closeResource(CUR_PLAYER_ID);
 
 	// logic, graphic & mega structures
 	// copy the 4 essential player object structures into the header
-	GetPlayerStructures();
+	getPlayerStructures();
 
 	// copy the header to the buffer
 
@@ -212,7 +177,7 @@
 	// copy the global variables to the buffer
 
 	// open variables resource
-	varsRes = res_man.open(1);
+	varsRes = res_man->openResource(1);
 
 	// copy that to the buffer, following the header
 	memcpy(buffer->ad + sizeof(g_header), varsRes, FROM_LE_32(g_header.varLength));
@@ -226,24 +191,24 @@
 #endif
 
 	// close variables resource
- 	res_man.close(1);
+ 	res_man->closeResource(1);
 
-	// set the checksum & copy that to the buffer (James05aug97)
+	// set the checksum & copy that to the buffer
 
-	g_header.checksum = TO_LE_32(CalcChecksum((buffer->ad) + sizeof(g_header.checksum), size - sizeof(g_header.checksum)));
+	g_header.checksum = TO_LE_32(calcChecksum((buffer->ad) + sizeof(g_header.checksum), size - sizeof(g_header.checksum)));
  	memcpy(buffer->ad, &g_header.checksum, sizeof(g_header.checksum));
 }
 
-uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
+uint32 Sword2Engine::saveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
 	char saveFileName[MAX_FILENAME_LEN];
 	uint32 itemsWritten;
 	SaveFile *out;
 	SaveFileManager *mgr = g_system->get_savefile_manager();
 
 	// construct filename
-	sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
 	
-	if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true))) {
+	if (!(out = mgr->open_savefile(saveFileName, getSavePath(), true))) {
 		// error: couldn't open file
 		delete mgr;
 		return SR_ERR_FILEOPEN;
@@ -265,48 +230,48 @@
 
 // RESTORE GAME
 
-uint32 RestoreGame(uint16 slotNo) {
+uint32 Sword2Engine::restoreGame(uint16 slotNo) {
 	mem *saveBufferMem;
 	uint32 bufferSize;
 	uint32 errorCode;
 
 	// allocate the savegame buffer
 
-	bufferSize = FindBufferSize();
-	saveBufferMem = memory.allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
+	bufferSize = findBufferSize();
+	saveBufferMem = memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
 
 	// read the savegame file into our buffer
 
 	// load savegame into buffer
-	errorCode = RestoreData(slotNo, saveBufferMem->ad, bufferSize);
+	errorCode = restoreData(slotNo, saveBufferMem->ad, bufferSize);
 
 	// if it was read in successfully, then restore the game from the
 	// buffer & free the buffer
 
 	if (errorCode == SR_OK)	{
-		errorCode = RestoreFromBuffer(saveBufferMem, bufferSize);
+		errorCode = restoreFromBuffer(saveBufferMem, bufferSize);
 
 		// Note that the buffer has been freed inside
-		// RestoreFromBuffer, in order to clear it from memory before
+		// restoreFromBuffer, in order to clear it from memory before
 		// loading in the new screen & runlist
 	} else {
-		// because RestoreFromBuffer would have freed it
-		memory.freeMemory(saveBufferMem);
+		// because restoreFromBuffer would have freed it
+		memory->freeMemory(saveBufferMem);
 	}
 
 	return errorCode;
 }
 
-uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
+uint32 Sword2Engine::restoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
 	char saveFileName[MAX_FILENAME_LEN];
 	SaveFile *in;
 	SaveFileManager *mgr = g_system->get_savefile_manager();
  	uint32 itemsRead;
 
 	// construct filename
-	sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
 
-	if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
+	if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
 		// error: couldn't open file
 		delete mgr;
 		return SR_ERR_FILEOPEN;
@@ -339,7 +304,7 @@
 	}
 }
 
-uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
+uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) {
 	uint8 *varsRes;
 	int32 pars[2];
 
@@ -351,10 +316,9 @@
 #endif
 
 	// Calc checksum & check that aginst the value stored in the header
-	// (James05aug97)
 
-	if (g_header.checksum != CalcChecksum(buffer->ad + sizeof(g_header.checksum), size - sizeof(g_header.checksum))) {
-		memory.freeMemory(buffer);
+	if (g_header.checksum != calcChecksum(buffer->ad + sizeof(g_header.checksum), size - sizeof(g_header.checksum))) {
+		memory->freeMemory(buffer);
 
 		// error: incompatible save-data - can't use!
 		return SR_ERR_INCOMPATIBLE;
@@ -368,8 +332,8 @@
 	// shorter than the current expected length
 
 	// if header contradicts actual current size of global variables
-	if (g_header.varLength != res_man.fetchLen(1)) {
-		memory.freeMemory(buffer);
+	if (g_header.varLength != res_man->fetchLen(1)) {
+		memory->freeMemory(buffer);
 
 		// error: incompatible save-data - can't use!
 		return SR_ERR_INCOMPATIBLE;
@@ -379,7 +343,7 @@
 
 	// trash all resources from memory except player object & global
 	// variables
-	res_man.killAll(false);
+	res_man->killAll(false);
 
 	// clean out the system kill list (no more objects to kill)
 	g_logic.resetKillList();
@@ -387,17 +351,17 @@
 	// get player character data from savegame buffer
 
 	// object hub is just after the standard header 
-	memcpy(res_man.open(CUR_PLAYER_ID) + sizeof(_standardHeader), &g_header.player_hub, sizeof(_object_hub));
+	memcpy(res_man->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), &g_header.player_hub, sizeof(_object_hub));
 
-	res_man.close(CUR_PLAYER_ID);
+	res_man->closeResource(CUR_PLAYER_ID);
 
 	// fill in the 4 essential player object structures from the header
-	PutPlayerStructures();
+	putPlayerStructures();
 
 	// get variables resource from the savegame buffer	
 
 	// open variables resource
-	varsRes = res_man.open(1);
+	varsRes = res_man->openResource(1);
 
 	// copy that to the buffer, following the header
 	memcpy(varsRes, buffer->ad + sizeof(g_header), g_header.varLength );
@@ -411,11 +375,11 @@
 #endif
 
 	// close variables resource
- 	res_man.close(1);
+ 	res_man->closeResource(1);
 
 	// free it now, rather than in RestoreGame, to unblock memory before
 	// new screen & runlist loaded
-	memory.freeMemory(buffer);
+	memory->freeMemory(buffer);
 
 	pars[0] = g_header.screenId;
 	pars[1] = 1;
@@ -423,13 +387,13 @@
 
 	// So palette not restored immediately after control panel - we want to
 	// fade up instead!
-	g_sword2->_thisScreen.new_palette = 99;
+	_thisScreen.new_palette = 99;
 
 	// these need setting after the defaults get set in fnInitBackground
 	// remember that these can change through the game, so need saving &
 	// restoring too
-	g_sword2->_thisScreen.feet_x = g_header.feet_x;
-	g_sword2->_thisScreen.feet_y = g_header.feet_y;
+	_thisScreen.feet_x = g_header.feet_x;
+	_thisScreen.feet_y = g_header.feet_y;
 
 	// start the new run list
 	g_logic.expressChangeSession(g_header.runListId);
@@ -438,19 +402,19 @@
 	// not occur when screen first draws after returning from restore panel
 
 	// set '_thisScreen's record of player position
-	// - ready for Set_scrolling()
+	// - ready for setScrolling()
 
-	g_sword2->_thisScreen.player_feet_x = g_header.mega.feet_x;
-	g_sword2->_thisScreen.player_feet_y = g_header.mega.feet_y;
+	_thisScreen.player_feet_x = g_header.mega.feet_x;
+	_thisScreen.player_feet_y = g_header.mega.feet_y;
 
 	// if this screen is wide, recompute the scroll offsets now
-	if (g_sword2->_thisScreen.scroll_flag)
-		Set_scrolling();
+	if (_thisScreen.scroll_flag)
+		setScrolling();
 
 	// Any music required will be started after we've returned from
 	// Restore_control() - see System_menu() in mouse.cpp!
 
-	looping_music_id = g_header.music_id;
+	_loopingMusicId = g_header.music_id;
 
 	// Write to walkthrough file (zebug0.txt)
 
@@ -462,16 +426,16 @@
 
 // GetSaveDescription - PC version...
 
-uint32 GetSaveDescription(uint16 slotNo, uint8 *description) {
+uint32 Sword2Engine::getSaveDescription(uint16 slotNo, uint8 *description) {
 	char saveFileName[MAX_FILENAME_LEN];
 	_savegameHeader dummy;
 	SaveFile *in;
 	SaveFileManager *mgr = g_system->get_savefile_manager();
 
 	// construct filename
-	sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
 
-	if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
+	if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
 		// error: couldn't open file
 		delete mgr;
 		return SR_ERR_FILEOPEN;
@@ -482,19 +446,19 @@
 	delete in;
 	delete mgr;
 
-	sprintf((char*) description, dummy.description);
+	strcpy((char *) description, dummy.description);
 	return SR_OK;
 }
 
-bool SaveExists(uint16 slotNo) {
+bool Sword2Engine::saveExists(uint16 slotNo) {
 	char saveFileName[MAX_FILENAME_LEN];
 	SaveFileManager *mgr = g_system->get_savefile_manager();
 	SaveFile *in;
 
 	// construct filename
-	sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
 
-	if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
+	if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
 		delete mgr;
 		return false;
 	}
@@ -505,7 +469,7 @@
 	return true;
 }
 
-void GetPlayerStructures(void) {
+void Sword2Engine::getPlayerStructures(void) {
 	 // request the player object structures which need saving
 
 	// script no. 7 - 'george_savedata_request' calls fnPassPlayerSaveData
@@ -514,17 +478,17 @@
  	char *raw_script_ad;
 	_standardHeader *head;
 
-	head = (_standardHeader*) res_man.open(CUR_PLAYER_ID);
+	head = (_standardHeader*) res_man->openResource(CUR_PLAYER_ID);
 
 	if (head->fileType != GAME_OBJECT)
 		error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
 
 	raw_script_ad = (char *) head;
 	g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
-	res_man.close(CUR_PLAYER_ID);
+	res_man->closeResource(CUR_PLAYER_ID);
 }
 
-void PutPlayerStructures(void) {
+void Sword2Engine::putPlayerStructures(void) {
 	// fill out the player object structures from the savegame structures
 	// also run the appropriate scripts to set up george's anim tables &
 	// walkdata, and nico's anim tables
@@ -533,7 +497,7 @@
  	char *raw_script_ad;
 	_standardHeader *head;
 
-	head = (_standardHeader*) res_man.open(CUR_PLAYER_ID);
+	head = (_standardHeader*) res_man->openResource(CUR_PLAYER_ID);
 
 	if (head->fileType != GAME_OBJECT)
 		error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
@@ -571,7 +535,16 @@
 	}
 
 	g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
-	res_man.close(CUR_PLAYER_ID);
+	res_man->closeResource(CUR_PLAYER_ID);
+}
+
+uint32 Sword2Engine::calcChecksum(uint8 *buffer, uint32 size) {
+	uint32 total = 0;
+
+	for (uint32 pos = 0; pos < size; pos++)
+		total += buffer[pos];
+
+	return total;
 }
 
 int32 Logic::fnPassPlayerSaveData(int32 *params) {
@@ -587,9 +560,9 @@
 
 	// copy from player object to savegame header
 
-	memcpy(&g_header.logic, (uint8 *) params[0], sizeof(Object_logic));
-	memcpy(&g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic));
-	memcpy(&g_header.mega, (uint8 *) params[2], sizeof(Object_mega));
+	memcpy(&g_sword2->g_header.logic, (uint8 *) params[0], sizeof(Object_logic));
+	memcpy(&g_sword2->g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic));
+	memcpy(&g_sword2->g_header.mega, (uint8 *) params[2], sizeof(Object_mega));
 
 	// makes no odds
 	return IR_CONT;
@@ -611,9 +584,9 @@
 
 	// copy from savegame header to player object
 
-	memcpy((uint8 *) ob_logic, &g_header.logic, sizeof(Object_logic));
-	memcpy((uint8 *) ob_graphic, &g_header.graphic, sizeof(Object_graphic));
-	memcpy((uint8 *) ob_mega, &g_header.mega, sizeof(Object_mega));
+	memcpy((uint8 *) ob_logic, &g_sword2->g_header.logic, sizeof(Object_logic));
+	memcpy((uint8 *) ob_graphic, &g_sword2->g_header.graphic, sizeof(Object_graphic));
+	memcpy((uint8 *) ob_mega, &g_sword2->g_header.mega, sizeof(Object_mega));
 
  	// any walk-data must be cleared - the player will be set to stand if
 	// he was walking when saved
@@ -641,15 +614,6 @@
 
 	// makes no odds
 	return IR_CONT;
-}
-
-uint32 CalcChecksum(uint8 *buffer, uint32 size) {
-	uint32 total = 0;
-
-	for (uint32 pos = 0; pos < size; pos++)
-		total += buffer[pos];
-
-	return total;
 }
 
 } // End of namespace Sword2

Index: save_rest.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/save_rest.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- save_rest.h	28 Oct 2003 19:51:29 -0000	1.6
+++ save_rest.h	3 Nov 2003 07:47:41 -0000	1.7
@@ -26,14 +26,6 @@
 
 #define	SAVE_DESCRIPTION_LEN	64
 
-uint32 SaveGame(uint16 slotNo, uint8 *description);
-uint32 RestoreGame(uint16 slotNo);
-uint32 GetSaveDescription(uint16 slotNo, uint8 *description);
-bool SaveExists(uint16 slotNo);
-void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc);
-uint32 RestoreFromBuffer(mem *buffer, uint32 size);
-uint32 FindBufferSize(void);
-
 // Save & Restore error codes
 
 #define SR_OK			0x00000000	// No worries

Index: scroll.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/scroll.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- scroll.cpp	2 Nov 2003 17:17:10 -0000	1.10
+++ scroll.cpp	3 Nov 2003 07:47:41 -0000	1.11
@@ -33,10 +33,7 @@
 // max no of pixel allowed to scroll per cycle
 #define MAX_SCROLL_DISTANCE 8
 
-// used to be a define, but now it's flexible (see new functions below)
-uint8 scroll_fraction = 16;
-
-void Set_scrolling(void) {
+void Sword2Engine::setScrolling(void) {
 	// normally we aim to get George's feet at (320,250) from top left
 	// of screen window
 	// feet_x = 128 + 320
@@ -53,51 +50,51 @@
 	// if the scroll offsets are being forced in script
 	if (SCROLL_X || SCROLL_Y) {
 		// ensure not too far right
-		if (g_sword2->_thisScreen.max_scroll_offset_x > SCROLL_X)
-			g_sword2->_thisScreen.scroll_offset_x = SCROLL_X;
+		if (_thisScreen.max_scroll_offset_x > SCROLL_X)
+			_thisScreen.scroll_offset_x = SCROLL_X;
 		else
- 			g_sword2->_thisScreen.scroll_offset_x = g_sword2->_thisScreen.max_scroll_offset_x;
+ 			_thisScreen.scroll_offset_x = _thisScreen.max_scroll_offset_x;
 
 		// ensure not too far down
-		if (g_sword2->_thisScreen.max_scroll_offset_y > SCROLL_Y)
-			g_sword2->_thisScreen.scroll_offset_y = SCROLL_Y;
+		if (_thisScreen.max_scroll_offset_y > SCROLL_Y)
+			_thisScreen.scroll_offset_y = SCROLL_Y;
 		else
- 			g_sword2->_thisScreen.scroll_offset_y = g_sword2->_thisScreen.max_scroll_offset_y;
+ 			_thisScreen.scroll_offset_y = _thisScreen.max_scroll_offset_y;
 	} else {
 		// George's offset from the centre - the desired position
 		// for him
 
-		offset_x = g_sword2->_thisScreen.player_feet_x - g_sword2->_thisScreen.feet_x;
-		offset_y = g_sword2->_thisScreen.player_feet_y - g_sword2->_thisScreen.feet_y;
+		offset_x = _thisScreen.player_feet_x - _thisScreen.feet_x;
+		offset_y = _thisScreen.player_feet_y - _thisScreen.feet_y;
 
 		// prevent scrolling too far left/right/up/down
 
 		if (offset_x < 0)
 			offset_x = 0;
-		else if ((uint32) offset_x > g_sword2->_thisScreen.max_scroll_offset_x)
-			offset_x = g_sword2->_thisScreen.max_scroll_offset_x;
+		else if ((uint32) offset_x > _thisScreen.max_scroll_offset_x)
+			offset_x = _thisScreen.max_scroll_offset_x;
 
 		if (offset_y < 0)
 			offset_y = 0;
-		else if ((uint32) offset_y > g_sword2->_thisScreen.max_scroll_offset_y)
-			offset_y = g_sword2->_thisScreen.max_scroll_offset_y;
+		else if ((uint32) offset_y > _thisScreen.max_scroll_offset_y)
+			offset_y = _thisScreen.max_scroll_offset_y;
 
 		// first time on this screen - need absolute scroll
 		// immediately!
 
-		if (g_sword2->_thisScreen.scroll_flag == 2) {
+		if (_thisScreen.scroll_flag == 2) {
 			debug(5, "init scroll");
-			g_sword2->_thisScreen.scroll_offset_x = offset_x;
-			g_sword2->_thisScreen.scroll_offset_y = offset_y;
-			g_sword2->_thisScreen.scroll_flag = 1;
+			_thisScreen.scroll_offset_x = offset_x;
+			_thisScreen.scroll_offset_y = offset_y;
+			_thisScreen.scroll_flag = 1;
 		} else {
 			// catch up with required scroll offsets - speed
 			// depending on distance to catch up (dx and dy) &
 			// 'SCROLL_FRACTION' used, but limit to certain
 			// number of pixels per cycle (MAX_SCROLL_DISTANCE)
 
-			dx = g_sword2->_thisScreen.scroll_offset_x - offset_x;
-			dy = g_sword2->_thisScreen.scroll_offset_y - offset_y;
+			dx = _thisScreen.scroll_offset_x - offset_x;
+			dy = _thisScreen.scroll_offset_y - offset_y;
 
 			// current scroll_offset_x is less than the required
 			// value
@@ -111,39 +108,39 @@
 				// NB. dx is -ve, so we subtract
 				// dx / SCROLL_FRACTION
 
-				scroll_distance_x = 1 - dx / scroll_fraction;
+				scroll_distance_x = 1 - dx / _scrollFraction;
 
 				if (scroll_distance_x > MAX_SCROLL_DISTANCE)
 					scroll_distance_x = MAX_SCROLL_DISTANCE;
 
-				g_sword2->_thisScreen.scroll_offset_x += scroll_distance_x;
+				_thisScreen.scroll_offset_x += scroll_distance_x;
 			} else if (dx > 0) {
 				// current scroll_offset_x is greater than
 				// the required value
 				// => dec by (fraction of the differnce)
 
-				scroll_distance_x = 1 + dx / scroll_fraction;
+				scroll_distance_x = 1 + dx / _scrollFraction;
 
 				if (scroll_distance_x > MAX_SCROLL_DISTANCE)
 					scroll_distance_x = MAX_SCROLL_DISTANCE;
 
-				g_sword2->_thisScreen.scroll_offset_x -= scroll_distance_x;
+				_thisScreen.scroll_offset_x -= scroll_distance_x;
 			}
 
 			if (dy < 0) {
-				scroll_distance_y = 1 - dy / scroll_fraction;
+				scroll_distance_y = 1 - dy / _scrollFraction;
 
 				if (scroll_distance_y > MAX_SCROLL_DISTANCE)
 					scroll_distance_y = MAX_SCROLL_DISTANCE;
 
-				g_sword2->_thisScreen.scroll_offset_y += scroll_distance_y;
+				_thisScreen.scroll_offset_y += scroll_distance_y;
 			} else if (dy > 0) {
-				scroll_distance_y = 1 + dy / scroll_fraction;
+				scroll_distance_y = 1 + dy / _scrollFraction;
 
 				if (scroll_distance_y > MAX_SCROLL_DISTANCE)
 					scroll_distance_y = MAX_SCROLL_DISTANCE;
 
-				g_sword2->_thisScreen.scroll_offset_y -= scroll_distance_y;
+				_thisScreen.scroll_offset_y -= scroll_distance_y;
 			}
 		}
 	}
@@ -173,14 +170,14 @@
 int32 Logic::fnSetScrollSpeedNormal(int32 *params) {
 	// params:	none
 
-	scroll_fraction = 16;
+	g_sword2->_scrollFraction = 16;
 	return IR_CONT;
 }
 
 int32 Logic::fnSetScrollSpeedSlow(int32 *params) {
 	// params:	none
 
-	scroll_fraction = 32;
+	g_sword2->_scrollFraction = 32;
 	return IR_CONT;
 }
 

Index: scroll.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/scroll.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- scroll.h	4 Oct 2003 00:52:26 -0000	1.3
+++ scroll.h	3 Nov 2003 07:47:41 -0000	1.4
@@ -23,9 +23,6 @@
 #define	_SCROLL
 
 namespace Sword2 {
-
-void Set_scrolling(void);
-
 } // End of namespace Sword2
 
 #endif

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sound.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- sound.cpp	2 Nov 2003 15:58:45 -0000	1.31
+++ sound.cpp	3 Nov 2003 07:47:41 -0000	1.32
@@ -33,99 +33,80 @@
 #include "sword2/defs.h"		// for RESULT
 #include "sword2/interpreter.h"
 #include "sword2/logic.h"
-#include "sword2/protocol.h"	// for FetchObjectName() for debugging fnPlayFx
+#include "sword2/protocol.h"	// for fetchObjectName() for debugging fnPlayFx
 #include "sword2/resman.h"
 #include "sword2/sound.h"
 #include "sword2/sword2.h"
 
 namespace Sword2 {
 
-typedef struct {
-	uint32 resource;	// resource id of sample
-	uint32 fetchId;		// Id of resource in PSX CD queue. :)
-	uint16 delay;		// cycles to wait before playing (or 'random chance' if FX_RANDOM)
-	uint8 volume;		// 0..16
-	int8 pan;		// -16..16
-	uint8 type;		// FX_SPOT, FX_RANDOM or FX_LOOP
-} _fxq_entry;
-
-// max number of fx in queue at once [DO NOT EXCEED 255]
-#define FXQ_LENGTH 32
-
-static _fxq_entry fxq[FXQ_LENGTH];
-
-// used to store id of tunes that loop, for save & restore
-uint32 looping_music_id = 0;
-
-void Trigger_fx(uint8 j);
-
 // initialise the fxq by clearing all the entries
 
-void Init_fx_queue(void) {
-	for (int j = 0; j < FXQ_LENGTH; j++) {
-		fxq[j].resource = 0;	// 0 resource means 'empty' slot
-		fxq[j].fetchId = 0;	// Not being fetched.
+void Sword2Engine::initFxQueue(void) {
+	for (int i = 0; i < FXQ_LENGTH; i++) {
+		_fxQueue[i].resource = 0;	// 0 resource means 'empty' slot
+		_fxQueue[i].fetchId = 0;	// Not being fetched.
 	}
 }
 
-// process the fxq once every game cycle
+// process the fx queue once every game cycle
 
-void Process_fx_queue(void) {
-	for (int j = 0; j < FXQ_LENGTH; j++) {
-		if (!fxq[j].resource)
+void Sword2Engine::processFxQueue(void) {
+	for (int i = 0; i < FXQ_LENGTH; i++) {
+		if (!_fxQueue[i].resource)
 			continue;
 
-		switch (fxq[j].type) {
+		switch (_fxQueue[i].type) {
 		case FX_RANDOM:
 			// 1 in 'delay' chance of this fx occurring
-			if (g_sword2->_rnd.getRandomNumber(fxq[j].delay) == 0)
-				Trigger_fx(j);
+			if (_rnd.getRandomNumber(_fxQueue[i].delay) == 0)
+				triggerFx(i);
 			break;
 		case FX_SPOT:
-			if (fxq[j].delay)
-				fxq[j].delay--;
+			if (_fxQueue[i].delay)
+				_fxQueue[i].delay--;
 			else {
-				Trigger_fx(j);
-				fxq[j].type = FX_SPOT2;
+				triggerFx(i);
+				_fxQueue[i].type = FX_SPOT2;
 			}
 			break;
 		case FX_SPOT2:
 			// Once the Fx has finished remove it from the queue.
-			if (g_sound->isFxOpen(j + 1))
-				fxq[j].resource = 0;
+			if (g_sound->isFxOpen(i + 1))
+				_fxQueue[i].resource = 0;
 			break;
 		}
 	}
 }
 
-// called from Process_fx_queue only
+// called from processFxQueue only
 
-void Trigger_fx(uint8 j) {
+void Sword2Engine::triggerFx(uint8 j) {
 	uint8 *data;
 	int32 id;
 	uint32 rv;
 
 	id = (uint32) j + 1;	// because 0 is not a valid id
 
-	if (fxq[j].type == FX_SPOT) {
+	if (_fxQueue[j].type == FX_SPOT) {
 		// load in the sample
-		data = res_man.open(fxq[j].resource);
+		data = res_man->openResource(_fxQueue[j].resource);
 		data += sizeof(_standardHeader);
 		// wav data gets copied to sound memory
-		rv = g_sound->playFx(id, data, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT);
+		rv = g_sound->playFx(id, data, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT);
 		// release the sample
-		res_man.close(fxq[j].resource);
+		res_man->closeResource(_fxQueue[j].resource);
 	} else {
 		// random & looped fx are already loaded into sound memory
 		// by fnPlayFx()
 		// - to be referenced by 'j', so pass NULL data
 
-		if (fxq[j].type == FX_RANDOM) {
+		if (_fxQueue[j].type == FX_RANDOM) {
 			// Not looped
-			rv = g_sound->playFx(id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT);
+			rv = g_sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT);
 		} else {
 			// Looped
-			rv = g_sound->playFx(id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXLOOP);
+			rv = g_sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXLOOP);
 		}
 	}
 
@@ -133,6 +114,33 @@
 		debug(5, "SFX ERROR: playFx() returned %.8x", rv);
 }
 
+// Stops all looped & random fx and clears the entire queue
+
+void Sword2Engine::clearFxQueue(void) {
+	// stop all fx & remove the samples from sound memory
+	g_sound->clearAllFx();
+
+	// clean out the queue
+	initFxQueue();
+}
+
+void Sword2Engine::killMusic(void) {
+	_loopingMusicId = 0;		// clear the 'looping' flag
+	g_sound->stopMusic();
+}
+
+void Sword2Engine::pauseAllSound(void) {
+	g_sound->pauseMusic();
+	g_sound->pauseSpeech();
+	g_sound->pauseFx();
+}
+
+void Sword2Engine::unpauseAllSound(void) {
+	g_sound->unpauseMusic();
+	g_sound->unpauseSpeech();
+	g_sound->unpauseFx();
+}
+
 // called from script only
 
 int32 Logic::fnPlayFx(int32 *params) {
@@ -177,34 +185,34 @@
 			strcpy(type, "INVALID");
 		}
 
-		debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", FetchObjectName(params[0]), params[3], params[4], params[2], type);
+		debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", g_sword2->fetchObjectName(params[0]), params[3], params[4], params[2], type);
 	}
 
-	while (j < FXQ_LENGTH && fxq[j].resource != 0)
+	while (j < FXQ_LENGTH && g_sword2->_fxQueue[j].resource != 0)
 		j++;
 
 	if (j == FXQ_LENGTH)
 		return IR_CONT;
 
-	fxq[j].resource	= params[0];	// wav resource id
-	fxq[j].type = params[1];	// FX_SPOT, FX_LOOP or FX_RANDOM
+	g_sword2->_fxQueue[j].resource	= params[0];	// wav resource id
+	g_sword2->_fxQueue[j].type = params[1];	// FX_SPOT, FX_LOOP or FX_RANDOM
 
-	if (fxq[j].type == FX_RANDOM) {
+	if (g_sword2->_fxQueue[j].type == FX_RANDOM) {
 		// 'delay' param is the intended average no. seconds between
 		// playing this effect
-		fxq[j].delay = params[2] * 12;
+		g_sword2->_fxQueue[j].delay = params[2] * 12;
 	} else {
 		// FX_SPOT or FX_LOOP:
 		//  'delay' is no. frames to wait before playing
-		fxq[j].delay = params[2];
+		g_sword2->_fxQueue[j].delay = params[2];
 	}
 
-	fxq[j].volume = params[3];	// 0..16
-	fxq[j].pan = params[4];		// -16..16
+	g_sword2->_fxQueue[j].volume = params[3];	// 0..16
+	g_sword2->_fxQueue[j].pan = params[4];		// -16..16
 
-	if (fxq[j].type == FX_SPOT) {
+	if (g_sword2->_fxQueue[j].type == FX_SPOT) {
 		// "pre-load" the sample; this gets it into memory
-		data = res_man.open(fxq[j].resource);
+		data = res_man->openResource(g_sword2->_fxQueue[j].resource);
 
 #ifdef _SWORD2_DEBUG
 		header = (_standardHeader*) data;
@@ -213,14 +221,14 @@
 #endif
 
 		// but then releases it to "age" out if the space is needed
-		res_man.close(fxq[j].resource);
+		res_man->closeResource(g_sword2->_fxQueue[j].resource);
 	} else {
 		// random & looped fx
 
 		id = (uint32) j + 1;	// because 0 is not a valid id
 
 		// load in the sample
-		data = res_man.open(fxq[j].resource);
+		data = res_man->openResource(g_sword2->_fxQueue[j].resource);
 
 #ifdef _SWORD2_DEBUG
 		header = (_standardHeader*)data;
@@ -237,13 +245,13 @@
 			debug(5, "SFX ERROR: openFx() returned %.8x", rv);
 
 		// release the sample
-		res_man.close(fxq[j].resource);
+		res_man->closeResource(g_sword2->_fxQueue[j].resource);
 	}
 
-	if (fxq[j].type == FX_LOOP) {
+	if (g_sword2->_fxQueue[j].type == FX_LOOP) {
 		// play now, rather than in Process_fx_queue where it was
 		// getting played again & again!
-		Trigger_fx(j);
+		g_sword2->triggerFx(j);
 	}
 
 	// in case we want to call fnStopFx() later, to kill this fx
@@ -299,7 +307,7 @@
 	uint32 id;
 	uint32 rv;
 
-	if (fxq[j].type == FX_RANDOM || fxq[j].type == FX_LOOP) {
+	if (g_sword2->_fxQueue[j].type == FX_RANDOM || g_sword2->_fxQueue[j].type == FX_LOOP) {
 		id = (uint32) j + 1;		// because 0 is not a valid id
 
 		// stop fx & remove sample from sound memory
@@ -310,7 +318,7 @@
 	}
 
 	// remove from queue
-	fxq[j].resource = 0;
+	g_sword2->_fxQueue[j].resource = 0;
 
 	return IR_CONT;
 }
@@ -322,20 +330,10 @@
 
 	// params:	none
 
-	Clear_fx_queue();
+	g_sword2->clearFxQueue();
 	return IR_CONT;
 }
 
-// Stops all looped & random fx and clears the entire queue
-
-void Clear_fx_queue(void) {
-	// stop all fx & remove the samples from sound memory
-	g_sound->clearAllFx();
-
-	// clean out the queue
-	Init_fx_queue();
-}
-
 int32 Logic::fnPrepareMusic(int32 *params) {
 	// params:	1 id of music to prepare [guess]
 	return IR_CONT;
@@ -357,13 +355,13 @@
 
 		// keep a note of the id, for restarting after an
 		// interruption to gameplay
-		looping_music_id = params[0];
+		g_sword2->_loopingMusicId = params[0];
 	} else {
  		loopFlag = false;
 
 		// don't need to restart this tune after control panel or
 		// restore
-		looping_music_id = 0;
+		g_sword2->_loopingMusicId = 0;
 	}
 
 	// add the appropriate file extension & play it
@@ -376,7 +374,7 @@
 	} else {
 		File f;
 
-		sprintf(filename, "music%d.clu", res_man.whichCd());
+		sprintf(filename, "music%d.clu", res_man->whichCd());
 		if (f.open(filename))
 			f.close();
 		else
@@ -396,16 +394,11 @@
 int32 Logic::fnStopMusic(int32 *params) {
 	// params:	none
 
-	looping_music_id = 0;		// clear the 'looping' flag
+	g_sword2->_loopingMusicId = 0;		// clear the 'looping' flag
 	g_sound->stopMusic();
 	return IR_CONT;
 }
 
-void Kill_music(void) {
-	looping_music_id = 0;		// clear the 'looping' flag
-	g_sound->stopMusic();
-}
-
 int32 Logic::fnCheckMusicPlaying(int32 *params) {
 	// params:	none
 
@@ -416,18 +409,6 @@
 	RESULT = g_sound->musicTimeRemaining();
 
 	return IR_CONT;
-}
-
-void PauseAllSound(void) {
-	g_sound->pauseMusic();
-	g_sound->pauseSpeech();
-	g_sound->pauseFx();
-}
-
-void UnpauseAllSound(void) {
-	g_sound->unpauseMusic();
-	g_sound->unpauseSpeech();
-	g_sound->unpauseFx();
 }
 
 } // End of namespace Sword2

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sound.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- sound.h	18 Oct 2003 08:11:50 -0000	1.6
+++ sound.h	3 Nov 2003 07:47:41 -0000	1.7
@@ -30,31 +30,19 @@
 #ifndef SOUND_H
 #define SOUND_H
 
+// max number of fx in queue at once [DO NOT EXCEED 255]
+#define FXQ_LENGTH 32
+
 namespace Sword2 {
 
 // fx types
 
-#define FX_SPOT		0
-#define FX_LOOP		1
-#define FX_RANDOM	2
-#define FX_SPOT2	3
-
-// to be called during system initialisation
-void Init_fx_queue(void);
-
-// to be called from the main loop, once per cycle
-void Process_fx_queue(void);
-
-// stops all fx & clears the queue - eg. when leaving a location
-void Clear_fx_queue(void);
-
-void PauseAllSound(void);
-void UnpauseAllSound(void);
-
-void Kill_music(void);
-
-// used to store id of tunes that loop, for save & restore
-extern uint32 looping_music_id;
+enum {
+	FX_SPOT		= 0,
+	FX_LOOP		= 1,
+	FX_RANDOM	= 2,
+	FX_SPOT2	= 3
+};
 
 } // End of namespace Sword2
 

Index: speech.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/speech.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- speech.cpp	2 Nov 2003 18:50:07 -0000	1.40
+++ speech.cpp	3 Nov 2003 07:47:41 -0000	1.41
@@ -217,9 +217,9 @@
 		for (j = 0; j < 15; j++) {
 			if (j < IN_SUBJECT) {
 				debug(5, " ICON res %d for %d", subject_list[j].res, j);
-				icon = res_man.open(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP;
+				icon = res_man->openResource(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP;
 				g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon);
-				res_man.close(subject_list[j].res);
+				res_man->closeResource(subject_list[j].res);
 			} else {
 				//no icon here
 				debug(5, " NULL for %d", j);
@@ -261,18 +261,18 @@
 
 					// change icons
 					for (j = 0; j < IN_SUBJECT; j++) {
-						debug(5, "%s", FetchObjectName(subject_list[j].res));
+						debug(5, "%s", g_sword2->fetchObjectName(subject_list[j].res));
 
 						// change all others to grey
 						if (j != hit) {
-							icon = res_man.open( subject_list[j].res ) + sizeof(_standardHeader);
+							icon = res_man->openResource( subject_list[j].res ) + sizeof(_standardHeader);
 							g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon);
-							res_man.close(subject_list[j].res);
+							res_man->closeResource(subject_list[j].res);
 						}
 					}
 
 
-					debug(5, "Selected: %s", FetchObjectName(subject_list[hit].res));
+					debug(5, "Selected: %s", g_sword2->fetchObjectName(subject_list[hit].res));
 
 					// this is our looping flag
 					choosing = 0;
@@ -360,7 +360,7 @@
 	int32 target = params[0];
 
 	// request status of target
-	head = (_standardHeader*) res_man.open(target);
+	head = (_standardHeader*) res_man->openResource(target);
 	if (head->fileType != GAME_OBJECT)
 		error("fnTheyDo %d not an object", target);
 
@@ -369,7 +369,7 @@
 	// call the base script - this is the graphic/mouse service call
 	runScript(raw_script_ad, raw_script_ad, &null_pc);
 
-	res_man.close(target);
+	res_man->closeResource(target);
 
 	// result is 1 for waiting, 0 for busy
 
@@ -422,7 +422,7 @@
 	// ok, see if the target is busy - we must request this info from the
 	// target object
 
-	head = (_standardHeader*) res_man.open(target);
+	head = (_standardHeader*) res_man->openResource(target);
 	if (head->fileType != GAME_OBJECT)
 		error("fnTheyDoWeWait %d not an object", target);
 
@@ -431,7 +431,7 @@
 	// call the base script - this is the graphic/mouse service call
 	runScript(raw_script_ad, raw_script_ad, &null_pc);
 
-	res_man.close(target);
+	res_man->closeResource(target);
 
 	ob_logic = (Object_logic *) params[0];
 
@@ -502,7 +502,7 @@
 	int32 target = params[0];
 
 	// request status of target
-	head = (_standardHeader*) res_man.open(target);
+	head = (_standardHeader*) res_man->openResource(target);
 	if (head->fileType != GAME_OBJECT)
 		error("fnWeWait: %d not an object", target);
 
@@ -511,7 +511,7 @@
 	// call the base script - this is the graphic/mouse service call
 	runScript(raw_script_ad, raw_script_ad, &null_pc);
 
-	res_man.close(target);
+	res_man->closeResource(target);
 
 	// result is 1 for waiting, 0 for busy
 
@@ -550,7 +550,7 @@
 		ob_logic->looping = params[2];	//first time in
 
 	// request status of target
-	head = (_standardHeader*) res_man.open(target);
+	head = (_standardHeader*) res_man->openResource(target);
 	if (head->fileType != GAME_OBJECT)
 		error("fnTimedWait %d not an object", target);
 
@@ -559,7 +559,7 @@
 	// call the base script - this is the graphic/mouse service call
 	runScript(raw_script_ad, raw_script_ad, &null_pc);
 
-	res_man.close(target);
+	res_man->closeResource(target);
 
 	// result is 1 for waiting, 0 for busy
 
@@ -993,14 +993,14 @@
 			// if the resource number is within range & it's not
 			// a null resource
 
-			if (res_man.checkValid(text_res)) {
+			if (res_man->checkValid(text_res)) {
 				// open the resource
-				head = (_standardHeader*) res_man.open(text_res);
+				head = (_standardHeader*) res_man->openResource(text_res);
 
 				if (head->fileType == TEXT_FILE) {
 					// if it's not an animation file
 					// if line number is out of range
-					if (CheckTextLine((uint8*) head, local_text) == 0) {
+					if (g_sword2->checkTextLine((uint8*) head, local_text) == 0) {
 						// line number out of range
 						RESULT = 2;
 					}
@@ -1010,7 +1010,7 @@
 				}
 
 				// close the resource
-				res_man.close(text_res);
+				res_man->closeResource(text_res);
 
 				if (RESULT)
 					return IR_CONT;
@@ -1030,11 +1030,11 @@
 		local_text = params[S_TEXT] & 0xffff;
 
 		// open text file & get the line
-		text = FetchTextLine(res_man.open(text_res), local_text);
+		text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
 		officialTextNumber = READ_LE_UINT16(text);
 
 		// now ok to close the text file
-		res_man.close(text_res);
+		res_man->closeResource(text_res);
 
 		// prevent dud lines from appearing while testing text & speech
 		// since these will not occur in the game anyway
@@ -1065,7 +1065,7 @@
 		if (PLAYER_ID != CUR_PLAYER_ID)
 			debug(5, "(%d) Nico: %s", officialTextNumber, text + 2);
 		else
-			debug(5, "(%d) %s: %s", officialTextNumber, FetchObjectName(ID), text + 2);
+			debug(5, "(%d) %s: %s", officialTextNumber, g_sword2->fetchObjectName(ID), text + 2);
 
 		// Set up the speech animation
 
@@ -1169,7 +1169,7 @@
 
 			File fp;
 
-			sprintf(speechFile, "speech%d.clu", res_man.whichCd());
+			sprintf(speechFile, "speech%d.clu", res_man->whichCd());
 
 			if (fp.open(speechFile))
 				fp.close();
@@ -1212,8 +1212,8 @@
 		ob_graphic->anim_pc++;
 
 		// open the anim file
-		anim_file = res_man.open(ob_graphic->anim_resource);
-		anim_head = FetchAnimHeader(anim_file);
+		anim_file = res_man->openResource(ob_graphic->anim_resource);
+		anim_head = g_sword2->fetchAnimHeader(anim_file);
 
 		if (!speech_anim_type) {
 			// ANIM IS TO BE LIP-SYNC'ED & REPEATING
@@ -1242,7 +1242,7 @@
 		}
 
 		// close the anim file
-		res_man.close(ob_graphic->anim_resource);
+		res_man->closeResource(ob_graphic->anim_resource);
 	} else if (speech_anim_type) {
 		// Placed here so we actually display the last frame of the
 		// anim.
@@ -1404,15 +1404,15 @@
 		// build_display.cpp
 
 		// open animation file & set up the necessary pointers
-		file = res_man.open(anim_id);
+		file = res_man->openResource(anim_id);
 
-		anim_head = FetchAnimHeader(file);
+		anim_head = g_sword2->fetchAnimHeader(file);
 
 		// '0' means 1st frame
-		cdt_entry = FetchCdtEntry(file, 0);
+		cdt_entry = g_sword2->fetchCdtEntry(file, 0);
 
 		// '0' means 1st frame
-		frame_head = FetchFrameHeader(file, 0);
+		frame_head = g_sword2->fetchFrameHeader(file, 0);
 
 		// check if this frame has offsets ie. this is a scalable
 		// mega frame
@@ -1456,7 +1456,7 @@
 		text_y -= g_sword2->_thisScreen.scroll_offset_y;
 
 		// release the anim resource
-		res_man.close(anim_id);
+		res_man->closeResource(anim_id);
 	}
 }
 
@@ -1510,7 +1510,7 @@
 		local_text = params[S_TEXT] & 0xffff;
 
 		// open text file & get the line
-		text = FetchTextLine(res_man.open(text_res), local_text);
+		text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
 
 		// 'text + 2' to skip the first 2 bytes which form the line
 		// reference number
@@ -1522,7 +1522,7 @@
 			g_sword2->_speechFontId, POSITION_AT_CENTRE_OF_BASE);
 
 		// now ok to close the text file
-		res_man.close(text_res);
+		res_man->closeResource(text_res);
 
 		// set speech duration, in case not using wav
 		// no. of cycles = (no. of chars) + 30
@@ -1552,7 +1552,7 @@
 	// if we specifically need CD1 or CD2 (ie. it's not on both)
 	// then check it's there (& ask for it if it's not there)
 	if (cd == 1 || cd == 2)
-		res_man.getCd(cd);
+		res_man->getCd(cd);
 }
 #endif
 

Index: startup.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/startup.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- startup.cpp	28 Oct 2003 19:51:30 -0000	1.26
+++ startup.cpp	3 Nov 2003 07:47:42 -0000	1.27
@@ -125,17 +125,17 @@
 		// - need to check in case un-built sections included in
 		// start list
 
-		if (res_man.checkValid(res)) {
+		if (res_man->checkValid(res)) {
 			debug(5, "- resource %d ok", res);
-			raw_script = (char*) res_man.open(res);
+			raw_script = (char*) res_man->openResource(res);
 			null_pc = 0;
 			g_logic.runScript(raw_script, raw_script, &null_pc);
-			res_man.close(res);
+			res_man->closeResource(res);
 		} else
 			debug(5, "- resource %d invalid", res);
 	}
 
-	memory.freeMemory(temp);
+	memory->freeMemory(temp);
 
 	return 1;
 }
@@ -197,7 +197,7 @@
 
 		// restarting - stop sfx, music & speech!
 
-		Clear_fx_queue();
+		g_sword2->clearFxQueue();
 
 		// fade out any music that is currently playing
 		g_logic.fnStopMusic(NULL);
@@ -212,12 +212,12 @@
 		// remove all resources from memory, including player
 		// object & global variables
 
-		res_man.removeAll();
+		res_man->removeAll();
 
 		// reopen global variables resource & send address to
 		// interpreter - it won't be moving
-		g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
-		res_man.close(1);
+		g_logic.setGlobalInterpreterVariables((int32 *) (res_man->openResource(1) + sizeof(_standardHeader)));
+		res_man->closeResource(1);
 
 		// free all the route memory blocks from previous game
 		router.freeAllRouteMem();
@@ -231,8 +231,8 @@
 		// set the key
 
 		// Open George
-		raw_data_ad = (char *) res_man.open(8);
-		raw_script = (char *) res_man.open(start_list[start].start_res_id);
+		raw_data_ad = (char *) res_man->openResource(8);
+		raw_script = (char *) res_man->openResource(start_list[start].start_res_id);
 
 		// denotes script to run
 		null_pc = start_list[start].key & 0xffff;
@@ -240,10 +240,10 @@
 		Debug_Printf("Running start %d\n", start);
 		g_logic.runScript(raw_script, raw_data_ad, &null_pc);
 
-		res_man.close(start_list[start].start_res_id);
+		res_man->closeResource(start_list[start].start_res_id);
 
 		// Close George
-		res_man.close(8);
+		res_man->closeResource(8);
 
 		// make sure thre's a mouse, in case restarting while
 		// mouse not available

Index: sword2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- sword2.cpp	2 Nov 2003 18:50:08 -0000	1.74
+++ sword2.cpp	3 Nov 2003 07:47:42 -0000	1.75
@@ -133,6 +133,11 @@
 	_mixer->setVolume(256);
 	_mixer->setMusicVolume(256);
 
+	// get some falling RAM and put it in your pocket, never let it slip
+	// away
+
+	memory = new MemoryManager();
+	res_man = new ResourceManager();
 	g_sound = _sound = new Sound(_mixer);
 	g_display = _display = new Display(640, 480);
 	gui = new Gui();
@@ -180,6 +185,9 @@
 	_pointerTextBlocNo = 0;
 	_playerActivityDelay = 0;
 	_realLuggageItem = 0;
+
+	// used to be a define, but now it's flexible
+	_scrollFraction = 16;
 }
 
 Sword2Engine::~Sword2Engine() {
@@ -188,6 +196,8 @@
 	delete _display;
 	delete _debugger;
 	delete gui;
+	delete res_man;
+	delete memory;
 }
 
 void Sword2Engine::errorString(const char *buf1, char *buf2) {
@@ -212,19 +222,9 @@
 
 	uint8 *file;
 
-	// get some falling RAM and put it in your pocket, never let it slip
-	// away
-
-	debug(5, "CALLING: memory.init");
-	memory.init();
-
-	// initialise the resource manager
-	debug(5, "CALLING: res_man.init");
-	res_man.init();
-
 	// initialise global script variables
 	// res 1 is the globals list
-	file = res_man.open(1);
+	file = res_man->openResource(1);
 	debug(5, "CALLING: SetGlobalInterpreterVariables");
 	g_logic.setGlobalInterpreterVariables((int32 * ) (file + sizeof(_standardHeader)));
 
@@ -234,7 +234,7 @@
 	// DON'T CLOSE PLAYER OBJECT RESOURCE - KEEP IT OPEN IN MEMORY SO IT
 	// CAN'T MOVE!
 
-	file = res_man.open(8);
+	file = res_man->openResource(8);
 
 	// Set up font resource variables for this language version
 
@@ -255,7 +255,7 @@
 	// initialise the sound fx queue
 
 	debug(5, "CALLING: Init_fx_queue");
-	Init_fx_queue();
+	initFxQueue();
 
 	// all demos (not just web)
 	if (_features & GF_DEMO) {
@@ -270,11 +270,7 @@
 	debug(5, "Close_game() STARTING:");
 
 	// Stop music instantly!
-	Kill_music();
-
-	// free the memory again
-	memory.exit();
-	res_man.exit();
+	g_sword2->killMusic();
 
 	g_system->quit();
 }
@@ -304,13 +300,13 @@
 
 	// if this screen is wide, recompute the scroll offsets every cycle
 	if (g_sword2->_thisScreen.scroll_flag)
-		Set_scrolling();
+		g_sword2->setScrolling();
 
 	g_sword2->mouseEngine();
-	Process_fx_queue();
+	g_sword2->processFxQueue();
 
 	// update age and calculate previous cycle memory usage
-	res_man.nextCycle();
+	res_man->nextCycle();
 
 	if (quitGame)
 		return 1;
@@ -339,8 +335,8 @@
 	}
 
 	if (_saveSlot != -1) {
-		if (SaveExists(_saveSlot))
-			RestoreGame(_saveSlot);
+		if (saveExists(_saveSlot))
+			restoreGame(_saveSlot);
 		else { // show restore menu
 			setMouse(NORMAL_MOUSE_ID);
 			if (!gui->restoreControl())
@@ -488,19 +484,19 @@
 	uint32 null_pc = 1;
 
 	// open george object, ready for start script to reference
-	raw_data_ad = (char *) res_man.open(8);
+	raw_data_ad = (char *) res_man->openResource(8);
 
 	// open the ScreenManager object
-	raw_script = (char *) res_man.open(screen_manager_id);
+	raw_script = (char *) res_man->openResource(screen_manager_id);
 
 	// run the start script now (because no console)
 	g_logic.runScript(raw_script, raw_data_ad, &null_pc);
 
 	// close the ScreenManager object
-	res_man.close(screen_manager_id);
+	res_man->closeResource(screen_manager_id);
 
 	// close george
-	res_man.close(8);
+	res_man->closeResource(8);
 
 	debug(5, "Start_game() DONE.");
 }
@@ -523,16 +519,16 @@
 	// uint8 *text;
 
 	// open text file & get the line "PAUSED"
-	// text = FetchTextLine(res_man.open(3258), 449);
+	// text = FetchTextLine(res_man->openResource(3258), 449);
 	// pause_text_bloc_no = Build_new_block(text + 2, 320, 210, 640, 184, RDSPR_TRANS | RDSPR_DISPLAYALIGN, SPEECH_FONT_ID, POSITION_AT_CENTRE_OF_BASE);
 	// now ok to close the text file
-	// res_man.close(3258);
+	// res_man->closeResource(3258);
 
 	// don't allow Pause while screen fading or while black
 	if (g_display->getFadeStatus() != RDFADE_NONE)
 		return;
 	
-  	PauseAllSound();
+	g_sword2->pauseAllSound();
 
 	// make a normal mouse
 	g_sword2->clearPointerText();
@@ -557,7 +553,7 @@
 	}
 
 	// don't dim it if we're single-stepping through frames
-	// dim the palette during the pause (James26jun97)
+	// dim the palette during the pause
 
 	if (stepOneCycle == 0)
 		g_display->dimPalette();
@@ -572,7 +568,7 @@
 	if (OBJECT_HELD && g_sword2->_realLuggageItem)
 		g_sword2->setLuggage(g_sword2->_realLuggageItem);
 
-	UnpauseAllSound();
+	g_sword2->unpauseAllSound();
 
 	// put back game screen palette; see Build_display.cpp
 	g_sword2->setFullPalette(0xffffffff);

Index: sword2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- sword2.h	2 Nov 2003 18:50:09 -0000	1.32
+++ sword2.h	3 Nov 2003 07:47:42 -0000	1.33
@@ -28,10 +28,13 @@
 #include "sword2/build_display.h"
 #include "sword2/console.h"
 #include "sword2/events.h"
+#include "sword2/header.h"
 #include "sword2/icons.h"
 #include "sword2/layers.h"
 #include "sword2/mouse.h"
 #include "sword2/object.h"
+#include "sword2/save_rest.h"
+#include "sword2/sound.h"
 #include "sword2/driver/d_sound.h"
 #include "sword2/driver/d_draw.h"
 
@@ -129,6 +132,14 @@
 	void startNewPalette(void);
 	void processLayer(uint32 layer_number);
 
+	void getPlayerStructures(void);
+	void putPlayerStructures(void);
+
+	uint32 saveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
+	uint32 restoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
+
+	uint32 calcChecksum(uint8 *buffer, uint32 size);
+
 public:
 	Sword2Engine(GameDetector *detector, OSystem *syst);
 	~Sword2Engine();
@@ -275,6 +286,91 @@
 	void noHuman(void);
 
 	void registerMouse(Object_mouse *ob_mouse);
+
+	uint8 *fetchPalette(uint8 *screenFile);
+	_screenHeader *fetchScreenHeader(uint8 *screenFile);
+	_layerHeader *fetchLayerHeader(uint8 *screenFile, uint16 layerNo);
+	uint8 *fetchShadingMask(uint8 *screenFile);
+
+	_animHeader *fetchAnimHeader(uint8 *animFile);
+	_cdtEntry *fetchCdtEntry(uint8 *animFile, uint16 frameNo);
+	_frameHeader *fetchFrameHeader(uint8 *animFile, uint16 frameNo);
+	_parallax *fetchBackgroundParallaxLayer(uint8 *screenFile, int layer);
+	_parallax *fetchBackgroundLayer(uint8 *screenFile);
+	_parallax *fetchForegroundParallaxLayer(uint8 *screenFile, int layer);
+	uint8 *fetchTextLine(uint8 *file, uint32 text_line);
+	uint8 checkTextLine(uint8 *file, uint32	text_line);
+	uint8 *fetchPaletteMatchTable(uint8 *screenFile);
+	uint8 *fetchObjectName(int32 resourceId);
+
+	// savegame file header
+
+	struct _savegameHeader {
+		// sum of all bytes in file, excluding this uint32
+		uint32 checksum;
+
+		// player's description of savegame
+		char description[SAVE_DESCRIPTION_LEN];
+
+		uint32 varLength;	// length of global variables resource
+		uint32 screenId;	// resource id of screen file
+		uint32 runListId;	// resource id of run list
+		uint32 feet_x;		// copy of _thisScreen.feet_x
+		uint32 feet_y;		// copy of _thisScreen.feet_y
+		uint32 music_id;	// copy of 'looping_music_id'
+		_object_hub player_hub;	// copy of player object's object_hub structure
+		Object_logic logic;	// copy of player character logic structure
+
+		// copy of player character graphic structure
+		Object_graphic	graphic;
+
+		// copy of player character mega structure
+		Object_mega mega;
+	};
+
+	_savegameHeader g_header;
+
+	uint32 saveGame(uint16 slotNo, uint8 *description);
+	uint32 restoreGame(uint16 slotNo);
+	uint32 getSaveDescription(uint16 slotNo, uint8 *description);
+	bool saveExists(uint16 slotNo);
+	void fillSaveBuffer(mem *buffer, uint32 size, uint8 *desc);
+	uint32 restoreFromBuffer(mem *buffer, uint32 size);
+	uint32 findBufferSize(void);
+
+	uint8 _scrollFraction;
+
+	void setScrolling(void);
+
+	struct _fxq_entry {
+		uint32 resource;	// resource id of sample
+		uint32 fetchId;		// Id of resource in PSX CD queue. :)
+		uint16 delay;		// cycles to wait before playing (or 'random chance' if FX_RANDOM)
+		uint8 volume;		// 0..16
+		int8 pan;		// -16..16
+		uint8 type;		// FX_SPOT, FX_RANDOM or FX_LOOP
+	};
+
+	_fxq_entry _fxQueue[FXQ_LENGTH];
+
+	// used to store id of tunes that loop, for save & restore
+	uint32 _loopingMusicId;
+
+	// to be called during system initialisation
+	void initFxQueue(void);
+
+	// to be called from the main loop, once per cycle
+	void processFxQueue(void);
+
+	// stops all fx & clears the queue - eg. when leaving a location
+	void clearFxQueue(void);
+
+	void pauseAllSound(void);
+	void unpauseAllSound(void);
+
+	void killMusic(void);
+
+	void triggerFx(uint8 j);
 
 	void errorString(const char *buf_input, char *buf_output);
 	void initialiseFontResourceFlags(void);

Index: tony_gsdk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/tony_gsdk.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- tony_gsdk.cpp	28 Oct 2003 19:51:30 -0000	1.14
+++ tony_gsdk.cpp	3 Nov 2003 07:47:42 -0000	1.15
@@ -31,9 +31,6 @@
 uint32 Read_file(const char *name, mem **membloc, uint32 uid) {
 	// read the file in and place into an allocated MEM_float block
 
-	// FIXME: As far as I can see, this function is only used in debug
-	// builds, so maybe it should be removed completely?
-
 	File fh;
 	uint32 size;
 
@@ -45,7 +42,7 @@
 	size = fh.size();
 
 	// reserve enough floating memory for the file
-	*membloc = memory.allocMemory(size, MEM_float, uid);
+	*membloc = memory->allocMemory(size, MEM_float, uid);
 	
 	if (fh.read((*membloc)->ad, size) != size) {
 		debug(5, "Read_file read fail %d", name);
@@ -54,7 +51,7 @@
 
 	fh.close();
 
-	//ok, done it - return bytes read
+	// ok, done it - return bytes read
 	return size;
 }
 

Index: walker.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/walker.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- walker.cpp	2 Nov 2003 15:58:45 -0000	1.21
+++ walker.cpp	3 Nov 2003 07:47:42 -0000	1.22
@@ -266,17 +266,17 @@
 
 	if (ob_logic->looping == 0) {
 		// open anim file
-		anim_file = res_man.open(params[4]);
+		anim_file = res_man->openResource(params[4]);
 
 		// point to animation header
-		anim_head = FetchAnimHeader( anim_file );
+		anim_head = g_sword2->fetchAnimHeader( anim_file );
 
 		pars[4] = anim_head->feetStartX;	// target_x
 		pars[5] = anim_head->feetStartY;	// target_y
 		pars[6] = anim_head->feetStartDir;	// target_dir
 
 		// close anim file
-		res_man.close(params[4]);
+		res_man->closeResource(params[4]);
 
 		// if start coords not yet set in anim header, use the standby
 		// coords (which should be set beforehand in the script)
@@ -286,7 +286,7 @@
 			pars[5] = standby_y;
 			pars[6] = standby_dir;
 
-			debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", FetchObjectName(params[4]));
+			debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", g_sword2->fetchObjectName(params[4]));
 		}
 
 		if (pars[6] < 0 || pars[6] > 7)
@@ -430,8 +430,8 @@
 	// open the anim file & set up a pointer to the animation header
 
 	// open anim file
-	anim_file = res_man.open(params[2]);
-	anim_head = FetchAnimHeader(anim_file);
+	anim_file = res_man->openResource(params[2]);
+	anim_head = g_sword2->fetchAnimHeader(anim_file);
 
 	// set up the parameter list for fnWalkTo()
 
@@ -450,14 +450,14 @@
 		pars[3] = standby_y;
 		pars[4] = standby_dir;
 
-		debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", FetchObjectName(params[2]));
+		debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", g_sword2->fetchObjectName(params[2]));
 	}
 
 	if (pars[4] < 0 || pars[4] > 7)
 		error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
 
 	// close the anim file
-	res_man.close(params[2]);
+	res_man->closeResource(params[2]);
 
 	// call fnStandAt() with target coords set to anim end position
 	return fnStandAt(pars);
@@ -477,8 +477,8 @@
 	// open the anim file & set up a pointer to the animation header
 
 	// open anim file
-	anim_file = res_man.open(params[2]);
-	anim_head = FetchAnimHeader(anim_file);
+	anim_file = res_man->openResource(params[2]);
+	anim_head = g_sword2->fetchAnimHeader(anim_file);
 
 	// set up the parameter list for fnWalkTo()
 
@@ -497,14 +497,14 @@
 		pars[3] = standby_y;
 		pars[4] = standby_dir;
 
-		debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", FetchObjectName(params[2]));
+		debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", g_sword2->fetchObjectName(params[2]));
 	}
 
 	if (pars[4] < 0 || pars[4] > 7)
 		error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
 
 	// close the anim file
-	res_man.close(params[2]);
+	res_man->closeResource(params[2]);
 
 	// call fnStandAt() with target coords set to anim end position
 	return fnStandAt(pars);
@@ -603,7 +603,7 @@
 
 	if (ob_logic->looping == 0) {
 		// get targets info
-		head = (_standardHeader*) res_man.open(params[4]);
+		head = (_standardHeader*) res_man->openResource(params[4]);
 
 		if (head->fileType != GAME_OBJECT)
 			error("fnFaceMega %d not an object", params[4]);
@@ -613,7 +613,7 @@
 		//call the base script - this is the graphic/mouse service call
 		runScript(raw_script_ad, raw_script_ad, &null_pc);
 
-		res_man.close(params[4]);
+		res_man->closeResource(params[4]);
 
 		// engineMega is now the Object_mega of mega we want to turn
 		// to face
@@ -665,7 +665,7 @@
 	// not been here before so decide where to walk-to
 	if (!ob_logic->looping)	{
 		// first request the targets info
-		head = (_standardHeader*) res_man.open(params[4]);
+		head = (_standardHeader*) res_man->openResource(params[4]);
 
 		if (head->fileType != GAME_OBJECT)
 			error("fnWalkToTalkToMega %d not an object", params[4]);
@@ -676,7 +676,7 @@
 		// call
 		runScript(raw_script_ad, raw_script_ad, &null_pc);
 
-		res_man.close(params[4]);
+		res_man->closeResource(params[4]);
 
 		// engineMega is now the Object_mega of mega we want to
 		// route to
@@ -744,8 +744,8 @@
 	router.addWalkGrid(params[0]);
 
 	// Touch the grid, getting it into memory.
-	res_man.open(params[0]);
-	res_man.close(params[0]);
+	res_man->openResource(params[0]);
+	res_man->closeResource(params[0]);
 
 	return IR_CONT;
 }





More information about the Scummvm-git-logs mailing list