[Scummvm-git-logs] scummvm master -> f0bb3d51fad47c82a3fd24fe5f36b9778d8664c5

Strangerke noreply at scummvm.org
Thu Feb 20 09:34:44 UTC 2025


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

Summary:
f0bb3d51fa M4: Simplify memory allocation code, remove useless memory functions, remove unused file and access modes


Commit: f0bb3d51fad47c82a3fd24fe5f36b9778d8664c5
    https://github.com/scummvm/scummvm/commit/f0bb3d51fad47c82a3fd24fe5f36b9778d8664c5
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-02-20T10:34:26+01:00

Commit Message:
M4: Simplify memory allocation code, remove useless memory functions, remove unused file and access modes

Changed paths:
    engines/got/sound.cpp
    engines/got/sound.h
    engines/m4/adv_r/adv_chk.cpp
    engines/m4/adv_r/adv_file.cpp
    engines/m4/adv_r/conv_io.cpp
    engines/m4/burger/gui/game_menu.cpp
    engines/m4/fileio/fileio.h
    engines/m4/fileio/sys_file.cpp
    engines/m4/graphics/gr_buff.cpp
    engines/m4/graphics/gr_color.cpp
    engines/m4/graphics/gr_font.cpp
    engines/m4/gui/game_menu.cpp
    engines/m4/gui/gui_menu_items.cpp
    engines/m4/gui/gui_menu_items.h
    engines/m4/mem/reloc.cpp
    engines/m4/mem/reloc.h
    engines/m4/mem/res.cpp
    engines/m4/riddle/gui/game_menu.cpp
    engines/m4/riddle/rooms/section2/room204.cpp
    engines/m4/riddle/rooms/section9/room903.cpp
    engines/m4/riddle/rooms/section9/room917.cpp
    engines/m4/wscript/ws_load.cpp


diff --git a/engines/got/sound.cpp b/engines/got/sound.cpp
index 7168218d790..66d2b10d9a4 100644
--- a/engines/got/sound.cpp
+++ b/engines/got/sound.cpp
@@ -129,13 +129,31 @@ void Sound::musicPlay(const char *name, bool override) {
 		File file(name);
 
 #ifdef TODO
-		// FIXME: Completely wrong. Don't know music format yet
-		// Open it up for access
-		Common::SeekableReadStream *f = file.readStream(file.size());
-		Audio::AudioStream *audioStream = Audio::makeRawStream(
-			f, 11025, 0, DisposeAfterUse::YES);
-		g_engine->_mixer->playStream(Audio::Mixer::kPlainSoundType,
-									 &_musicHandle, audioStream);
+		// Just a POC + Not working - No volume, maybe?
+
+		OPL::OPL *opl = OPL::Config::create();
+		opl->init();
+		opl->start()
+		const int startLoop = file.readUint16LE();
+
+		while (!file.eos()) {
+			int delayAfter = file.readByte();
+			if (delayAfter & 0x80)
+				delayAfter = ((delayAfter & 0x7f) << 8) | file.readByte();
+
+			const int reg = file.readByte();
+			const int value = file.readByte();
+			if (reg == 0 && value == 0) {
+				debug(1, "End of song");
+				break;
+			}
+
+			opl->writeReg(reg, value);
+			debug("DelayAfter %d, OPL reg 0x%X, value %d", delayAfter, reg, value);
+			g_engine->_system->delayMillis(delayAfter);
+		}
+		debug(1, "looping at pos %d", startLoop);
+		
 #else
 		warning("TODO: play_music %s", name);
 
@@ -149,51 +167,6 @@ void Sound::musicPlay(const char *name, bool override) {
 		outFile->finalize();
 		outFile->close();
 #endif
-		
-		// The following is a dump of the music data in the hopes
-		// it will help someone write a decoder for ScummVM based on it.
-		// After an unknown header that doesn't seem to be used, the
-		// music seems to be a set of pauses followed by what I think
-		// are single byte combinations of frequency and duration that
-		/*
-        Following is a dump of the "play note" method, in case it's useful:
-        MU_playNote     proc far
-
-        freq            = byte ptr  6
-        duration        = byte ptr  8
-
-                        push    bp
-                        mov     bp, sp
-                        pushf
-                        cli
-                        mov     al, [bp+freq]
-                        mov     ah, 0
-                        mov     dl, [bp+duration]
-                        mov     bx, ax
-                        mov     MU_lookupTable[bx], dl
-                        mov     dx, 388h
-                        mov     al, [bp+freq]
-                        out     dx, al
-                        in      al, dx
-                        in      al, dx
-                        in      al, dx
-                        in      al, dx
-                        in      al, dx
-                        in      al, dx
-                        inc     dx
-                        mov     al, [bp+duration]
-                        out     dx, al
-                        popf
-                        dec     dx
-                        mov     cx, 35
-
-        loc_246C8:
-                        in      al, dx
-                        loop    loc_246C8
-                        pop     bp
-                        retf
-        MU_playNote     endp
-        */
 
 		const int startLoop = file.readUint16LE();
 
diff --git a/engines/got/sound.h b/engines/got/sound.h
index 93230e2c97b..b65742a2119 100644
--- a/engines/got/sound.h
+++ b/engines/got/sound.h
@@ -22,6 +22,8 @@
 #ifndef GOT_SOUND_H
 #define GOT_SOUND_H
 
+#include "audio/fmopl.h"
+
 #include "audio/mixer.h"
 #include "got/data/defines.h"
 #include "got/gfx/gfx_chunks.h"
diff --git a/engines/m4/adv_r/adv_chk.cpp b/engines/m4/adv_r/adv_chk.cpp
index fd4045f775f..96214d2f4b8 100644
--- a/engines/m4/adv_r/adv_chk.cpp
+++ b/engines/m4/adv_r/adv_chk.cpp
@@ -135,7 +135,7 @@ int db_def_chk_read(int16 room_code, SceneDef *rdef) {
 	_G(myDef) = rdef;
 
 	_G(def_filename) = Common::String::format("%03d.chk", room_code);
-	SysFile fpdef(_G(def_filename), BINARY);
+	SysFile fpdef(_G(def_filename));
 
 	load_def(&fpdef);
 	fpdef.close();
diff --git a/engines/m4/adv_r/adv_file.cpp b/engines/m4/adv_r/adv_file.cpp
index ee273a6bcf2..523eb15a1cb 100644
--- a/engines/m4/adv_r/adv_file.cpp
+++ b/engines/m4/adv_r/adv_file.cpp
@@ -122,7 +122,7 @@ bool kernel_load_room(int minPalEntry, int maxPalEntry, SceneDef *rdef, GrBuff *
 		_G(currBackgroundFN) = f_extension_new(_G(currBackgroundFN), "TT");
 	}
 
-	SysFile *pic_file = new SysFile(_G(currBackgroundFN), BINARY);
+	SysFile *pic_file = new SysFile(_G(currBackgroundFN));
 
 	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 	// Select attributes code file
@@ -138,7 +138,7 @@ bool kernel_load_room(int minPalEntry, int maxPalEntry, SceneDef *rdef, GrBuff *
 		_G(currCodeFN) = f_extension_new(_G(currCodeFN), "COD");
 	}
 
-	SysFile *code_file = new SysFile(_G(currCodeFN), BINARY);
+	SysFile *code_file = new SysFile(_G(currCodeFN));
 	if (!code_file->exists()) {
 		delete code_file;
 		code_file = nullptr;
diff --git a/engines/m4/adv_r/conv_io.cpp b/engines/m4/adv_r/conv_io.cpp
index d8d7c105dc8..bf9c6886ae7 100644
--- a/engines/m4/adv_r/conv_io.cpp
+++ b/engines/m4/adv_r/conv_io.cpp
@@ -751,7 +751,7 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
 	else
 		Common::sprintf_s(fullpathname, "%s.chk", filename);
 
-	SysFile fp(fullpathname, BINARY);
+	SysFile fp(fullpathname);
 	if (!fp.exists()) {
 		// Force the file open
 		error_show(FL, 'CNVL', "couldn't conv_load %s", fullpathname);
diff --git a/engines/m4/burger/gui/game_menu.cpp b/engines/m4/burger/gui/game_menu.cpp
index 580e816058e..3c12dcb93bd 100644
--- a/engines/m4/burger/gui/game_menu.cpp
+++ b/engines/m4/burger/gui/game_menu.cpp
@@ -30,7 +30,6 @@
 #include "m4/gui/gui_menu_items.h"
 #include "m4/gui/hotkeys.h"
 #include "m4/graphics/gr_sprite.h"
-#include "m4/graphics/krn_pal.h"
 #include "m4/gui/gui_sys.h"
 #include "m4/gui/gui_vmng.h"
 #include "m4/mem/mem.h"
@@ -182,10 +181,6 @@ void GameMenu::show(RGB8 *myPalette) {
 		guiMenu::initialize(myPalette);
 	}
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("gamemenu", GM_TOTAL_SPRITES)) {
 		return;
@@ -318,10 +313,6 @@ void OptionsMenu::show(RGB8 *myPalette) {
 		guiMenu::initialize(myPalette);
 	}
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("opmenu", OM_TOTAL_SPRITES)) {
 		return;
@@ -408,10 +399,6 @@ void ErrorMenu::show(RGB8 *myPalette) {
 		guiMenu::initialize(myPalette);
 	}
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("errmenu", 5)) {
 		return;
@@ -519,10 +506,6 @@ void SaveLoadMenu::show(RGB8 *myPalette, bool saveMenu) {
 		guiMenu::initialize(myPalette);
 	}
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("slmenu", GUI::SaveLoadMenuBase::SL_TOTAL_SPRITES)) {
 		return;
diff --git a/engines/m4/fileio/fileio.h b/engines/m4/fileio/fileio.h
index 2602aaa5de8..30fa18a34d8 100644
--- a/engines/m4/fileio/fileio.h
+++ b/engines/m4/fileio/fileio.h
@@ -28,16 +28,12 @@ namespace M4 {
 
 enum AccessMode {
 	UNOPENED,
-	READ,
-	WRITE,
-	READ_OR_WRITE
+	READ
 };
 
 enum FileMode {
 	BINARY,
-	TEXT,
-	BINARYW,
-	TEXTW
+	TEXT
 };
 
 struct Hag_Name_Record {
diff --git a/engines/m4/fileio/sys_file.cpp b/engines/m4/fileio/sys_file.cpp
index bc4ae25bec6..c836d545ffd 100644
--- a/engines/m4/fileio/sys_file.cpp
+++ b/engines/m4/fileio/sys_file.cpp
@@ -39,21 +39,14 @@ SysFile::SysFile(const Common::String &fname, FileMode myfmode) :
 }
 
 bool SysFile::exists() {
-	if (fmode == BINARY || fmode == TEXT) {
-		show_error_flag = false;
-		open_read_low_level();
-		show_error_flag = true;
-
-	} else if (fmode == BINARYW || fmode == TEXTW) {
-		show_error_flag = false;
-		open_write();
-		show_error_flag = true;
-	}
+	show_error_flag = false;
+	open_read_low_level();
+	show_error_flag = true;
 
 	if (!_G(hag).hag_flag)
 		return _fp != nullptr;
-	else
-		return (hag_success);
+
+	return (hag_success);
 }
 
 uint32 SysFile::size() {
@@ -81,22 +74,18 @@ uint32 SysFile::get_pos() {
 
 		return rs()->pos();
 
-	} else {
-		if (hag_success)
-			return (uint32)(curr_hag_record->hag_pos - curr_hash_record.offset);
-		else
-			return  0;
 	}
+
+	if (hag_success)
+		return (uint32)(curr_hag_record->hag_pos - curr_hash_record.offset);
+
+	return  0;
 }
 
 void SysFile::open_read_low_level() {
 	Common::File temp_fp;
-	uint32 hash_table_size;
 	char hag_name[33];
-	byte hagfile;
-	Hag_Name_Record *temp_ptr;
 	char *temp_name;
-	Common::String last_string;
 	Common::String resource_hag;
 	Common::File hagfile_fp;
 
@@ -113,7 +102,7 @@ void SysFile::open_read_low_level() {
 			if (!temp_fp.open(_G(hag).hash_file))
 				error("Hash file not found: %s", _G(hag).hash_file.toString().c_str());
 
-			hash_table_size = temp_fp.readUint32LE();
+			const uint32 hash_table_size = temp_fp.readUint32LE();
 			if (!temp_fp.seek(hash_table_size * HASH_RECORD_LENGTH, SEEK_CUR))
 				error("fail to seek");
 
@@ -121,9 +110,9 @@ void SysFile::open_read_low_level() {
 			while (!temp_fp.eos()) {
 				if (temp_fp.read(hag_name, 33) != 33)
 					break;
-				hagfile = temp_fp.readByte();
+				const byte hagfile = temp_fp.readByte();
 
-				temp_ptr = (Hag_Name_Record *)mem_alloc(sizeof(Hag_Name_Record), "hag_name_list");
+				Hag_Name_Record *temp_ptr = (Hag_Name_Record *)mem_alloc(sizeof(Hag_Name_Record), "hag_name_list");
 				assert(temp_ptr);
 
 				// Check hag file exists or not
@@ -141,10 +130,10 @@ void SysFile::open_read_low_level() {
 
 			temp_fp.close();
 		} else {
-			_G(hag).hag_flag = 0;
+			_G(hag).hag_flag = false;
 		}
 
-		_G(hag).first_read_flag = 1;
+		_G(hag).first_read_flag = true;
 	}
 
 	switch (mode) {
@@ -182,7 +171,7 @@ void SysFile::open_read_low_level() {
 				open_by_first_char();
 
 			} else {
-				last_string = get_last_string(filename);
+				Common::String last_string = get_last_string(filename);
 
 				if (!open_hash_file()) {
 					if (show_error_flag)
@@ -197,9 +186,6 @@ void SysFile::open_read_low_level() {
 		break;
 
 	case READ:
-	case WRITE:
-		break;
-
 	default:
 		break;
 	}
@@ -217,7 +203,9 @@ void SysFile::open_read() {
 
 	if (!_G(hag).hag_flag && !_fp) {
 		error("Error opening - %s", filename.c_str());
-	} else if (_G(hag).hag_flag && !hag_success) {
+	}
+
+	if (_G(hag).hag_flag && !hag_success) {
 		error("Error opening - %s", filename.c_str());
 	}
 }
@@ -227,185 +215,172 @@ void SysFile::open_write() {
 }
 
 Common::String SysFile::get_last_string(const Common::String &src) {
-	int len, j, k;
-
-	len = src.size();
+	int len = src.size();
 	Common::String result;
 
+	int j;
 	for (j = len - 1; j >= 0; j--) {
 		if (src[j] == '\\' || src[j] == ':')
 			break;
 	}
 
 	if (j >= 0) {
-		for (k = j + 1; k < len; k++)
+		for (int k = j + 1; k < len; k++)
 			result += src[k];
 		return result;
 
-	} else {
-		return src;
 	}
+
+	return src;
 }
 
 bool SysFile::open_hash_file() {
-	Common::SeekableReadStream *hashfp;
-	Common::Stream *temp_fp;
-	uint32 hash_address;
-	Common::String hag_name, temp_name;
-	Common::String local_name;
-	Hag_Record *temp_ptr;
-	uint32  hash_table_size;
-	bool found;
-	Common::String ext_name;
-
-	hashfp = dynamic_cast<Common::SeekableReadStream *>(f_io_open(_G(hag).hash_file, "rb"));
+	Common::SeekableReadStream *hashfp = dynamic_cast<Common::SeekableReadStream *>(f_io_open(_G(hag).hash_file, "rb"));
 	if (!hashfp) {
 		warning("open_hash_file: %s", _G(hag).hash_file.toString().c_str());
 		hag_success = false;
 		return false;
 	}
 
-	hash_table_size = hashfp->readUint32LE();
-	hash_address = key_to_hash_address(filename, hash_table_size);
+	uint32 hash_table_size = hashfp->readUint32LE();
+	uint32 hash_address = key_to_hash_address(filename, hash_table_size);
 
 	if (!hash_search(filename, &curr_hash_record, curr_hag_record, hash_address, hashfp, hash_table_size, show_error_flag)) {
 		hag_success = 0;
 		return false;
+	}
 
-	} else {
-		// How to open hag file
-		// Calculate Hagfile name - depends on hagfile field in curr_hash_record
-		if (!get_local_name_from_hagfile(local_name, curr_hash_record.hagfile)) {
-			hag_success = 0;
-			return false;
-		}
+	// How to open hag file
+	// Calculate Hagfile name - depends on hagfile field in curr_hash_record
+	Common::String local_name;
+
+	if (!get_local_name_from_hagfile(local_name, curr_hash_record.hagfile)) {
+		hag_success = 0;
+		return false;
+	}
 
-		// Check if this Hag file already open or not
-		local_name = f_extension_new(local_name, "HAG");
-		temp_name = local_name;
-		hag_name = local_name;		// Original used in cd_resource + name
+	// Check if this Hag file already open or not
+	local_name = f_extension_new(local_name, "HAG");
+	Common::String temp_name = local_name;
+	Common::String hag_name = local_name; // Original used in cd_resource + name
 
-		found = false;
-		temp_ptr = _G(hag).hag_file_list;
+	bool found = false;
+	Hag_Record *temp_ptr = _G(hag).hag_file_list;
+
+	// Search local open files for hag file...
+	while (temp_ptr) {
+		if (hag_name.equalsIgnoreCase(temp_ptr->hag_name)) {
+			found = true;
+			break;
+		}
+		temp_ptr = temp_ptr->next;
+	}
 
-		// Search local open files for hag file...
+	// Search resource directory open files for hag file
+	if (!found) {
+		temp_ptr = _G(hag).hag_file_list;
+		found = false;
 		while (temp_ptr) {
-			if (hag_name.equalsIgnoreCase(temp_ptr->hag_name)) {
+			if (temp_name.equalsIgnoreCase(temp_ptr->hag_name)) {
 				found = true;
 				break;
 			}
 			temp_ptr = temp_ptr->next;
 		}
-
-		// Search resource directory open files for hag file
 		if (!found) {
-			temp_ptr = _G(hag).hag_file_list;
-			found = false;
-			while (temp_ptr) {
-				if (temp_name.equalsIgnoreCase(temp_ptr->hag_name)) {
-					found = true;
-					break;
-				}
-				temp_ptr = temp_ptr->next;
-			}
-			if (!found) {
-				// hag file is not open, try the current directory first, then RESOURCE_PATH
-				temp_fp = f_io_open(Common::Path(hag_name), "rb");
+			// hag file is not open, try the current directory first, then RESOURCE_PATH
+			Common::Stream *temp_fp = f_io_open(Common::Path(hag_name), "rb");
+			if (!temp_fp) {
+				// hag_file is not in current directory, search for RESOURCE_PATH
+				temp_fp = f_io_open(Common::Path(temp_name), "rb");
 				if (!temp_fp) {
-					// hag_file is not in current directory, search for RESOURCE_PATH
-					temp_fp = f_io_open(Common::Path(temp_name), "rb");
-					if (!temp_fp) {
-						error("hag file not found: %s", hag_name.c_str());
-						hag_success = 0;
-						return 0;
-					}
-
-					// Add this new open hag file in resource dir into open hag file list
-					temp_ptr = (Hag_Record *)mem_alloc(sizeof(Hag_Record), "Hag_File_List");
-					if (!temp_ptr) {
-						f_io_close(temp_fp);
-						error("creating Hag_record");
-						hag_success = 0;
-						return 0;
-					}
-
-					Common::strcpy_s(temp_ptr->hag_name, temp_name.c_str());
-					temp_ptr->hag_fp = temp_fp;
-
-					Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(temp_fp);
-					assert(rs);
-
-					if (!rs->seek(curr_hash_record.offset))
-						term_message("fail to fseek");
-					last_head_pos = rs->pos();
-
-					temp_ptr->hag_pos = curr_hash_record.offset;
-					temp_ptr->hagfile = curr_hash_record.hagfile;
-
-					// insert the element into list
-					temp_ptr->next = _G(hag).hag_file_list;
-					_G(hag).hag_file_list = temp_ptr;
+					error("hag file not found: %s", hag_name.c_str());
+					hag_success = 0;
+					return 0;
 				}
-				// we just opened a previously unopened hag file
-				else {
-					// add this new open hag file in exec dir into its list
-					temp_ptr = (Hag_Record *)mem_alloc(sizeof(Hag_Record), "Hag_File_List");
-					if (!temp_ptr) {
-						f_io_close(temp_fp);
-						error("creating hag_record");
-						hag_success = 0;
-						return 0;
-					}
-
-					Common::strcpy_s(temp_ptr->hag_name, hag_name.c_str());
-					temp_ptr->hag_fp = temp_fp;
-
-					Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(temp_fp);
-					assert(rs);
-
-					if (!rs->seek(curr_hash_record.offset))
-						term_message("fail to fseek");
-					last_head_pos = rs->pos();
-
-					temp_ptr->hag_pos = curr_hash_record.offset;
-					temp_ptr->hagfile = curr_hash_record.hagfile;
-
-					// Insert the element into list
-					temp_ptr->next = _G(hag).hag_file_list;
-					_G(hag).hag_file_list = temp_ptr;
+
+				// Add this new open hag file in resource dir into open hag file list
+				temp_ptr = (Hag_Record *)mem_alloc(sizeof(Hag_Record), "Hag_File_List");
+				if (!temp_ptr) {
+					f_io_close(temp_fp);
+					error("creating Hag_record");
+					hag_success = 0;
+					return 0;
 				}
+
+				Common::strcpy_s(temp_ptr->hag_name, temp_name.c_str());
+				temp_ptr->hag_fp = temp_fp;
+
+				Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(temp_fp);
+				assert(rs);
+
+				if (!rs->seek(curr_hash_record.offset))
+					term_message("fail to fseek");
+				last_head_pos = rs->pos();
+
+				temp_ptr->hag_pos = curr_hash_record.offset;
+				temp_ptr->hagfile = curr_hash_record.hagfile;
+
+				// insert the element into list
+				temp_ptr->next = _G(hag).hag_file_list;
+				_G(hag).hag_file_list = temp_ptr;
 			}
-		}
+			// we just opened a previously unopened hag file
+			else {
+				// add this new open hag file in exec dir into its list
+				temp_ptr = (Hag_Record *)mem_alloc(sizeof(Hag_Record), "Hag_File_List");
+				if (!temp_ptr) {
+					f_io_close(temp_fp);
+					error("creating hag_record");
+					hag_success = 0;
+					return 0;
+				}
 
-		Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(temp_ptr->hag_fp);
-		assert(rs);
+				Common::strcpy_s(temp_ptr->hag_name, hag_name.c_str());
+				temp_ptr->hag_fp = temp_fp;
 
-		// set hag file pointer to current file position //
-		if (!rs->seek(curr_hash_record.offset))
-			term_message("fail to fseek");
-		last_head_pos = rs->pos();
+				Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(temp_fp);
+				assert(rs);
 
-		temp_ptr->hag_pos = curr_hash_record.offset;
-		curr_hag_record = temp_ptr;
+				if (!rs->seek(curr_hash_record.offset))
+					term_message("fail to fseek");
+				last_head_pos = rs->pos();
 
-		hag_success = true;
-		return true;
+				temp_ptr->hag_pos = curr_hash_record.offset;
+				temp_ptr->hagfile = curr_hash_record.hagfile;
+
+				// Insert the element into list
+				temp_ptr->next = _G(hag).hag_file_list;
+				_G(hag).hag_file_list = temp_ptr;
+			}
+		}
 	}
+
+	Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(temp_ptr->hag_fp);
+	assert(rs);
+
+	// set hag file pointer to current file position //
+	if (!rs->seek(curr_hash_record.offset))
+		term_message("fail to fseek");
+	last_head_pos = rs->pos();
+
+	temp_ptr->hag_pos = curr_hash_record.offset;
+	curr_hag_record = temp_ptr;
+
+	hag_success = true;
+	return true;
 }
 
 uint32 SysFile::key_to_hash_address(const Common::String &src, uint32 hash_table_size) {
-	uint32 h;
-	int i, len;
-
 	Common::String key = src;
 	key.toUppercase();
 
 	if (key.empty())
 		return 0;
 
-	h = key[0];
-	len = key.size();
-	for (i = 1; i < len; i++)
+	uint32 h = key[0];
+	const int len = key.size();
+	for (int i = 1; i < len; i++)
 		h = ((h * 256) + key[i]) % hash_table_size;   // * 256 is because one char is 8 bits
 
 	return h;
@@ -413,22 +388,19 @@ uint32 SysFile::key_to_hash_address(const Common::String &src, uint32 hash_table
 
 int SysFile::hash_search(const Common::String &fname, Hash_Record *current_hash_record_ptr, Hag_Record *current_hag_record, uint32 hash_address,
 	Common::SeekableReadStream *hashfp, uint32 hash_table_size, bool show_errors) {
-	uint32 offset;
-	bool finded = false;
+	bool found = false;
 	char myfilename[33];
-	uint32 next_entry;
-	uint32 best_dist, find_offset, next_record;
-	Common::String local_name, local_hag_name;
+	Common::String local_name;
 
 
-	next_entry = hash_address;
+	uint32 next_entry = hash_address;
 	// 4 bytes is header of hash file, store hash_table_size
-	offset = HASH_RECORD_LENGTH * next_entry + 4;
-	best_dist = 0x7fffffff;
-	find_offset = offset;
+	uint32 offset = HASH_RECORD_LENGTH * next_entry + 4;
+	uint32 best_dist = 0x7fffffff;
+	uint32 find_offset = offset;
 	myfilename[0] = '\0';
 
-	while (!finded) {
+	while (!found) {
 		if (!hashfp->seek(offset))
 			term_message("fail to fseek");
 		hashfp->read(myfilename, 33);
@@ -442,23 +414,25 @@ int SysFile::hash_search(const Common::String &fname, Hash_Record *current_hash_
 			else
 				term_message("fclass: file not found '%s', in hag file", fname.c_str());
 			return 0;
-		} else if (fname.equalsIgnoreCase(myfilename)) {
+		}
+
+		if (fname.equalsIgnoreCase(myfilename)) {
 			// The new record already in hash table, do nothing
 			auto &r = *current_hash_record_ptr;
 			r.hagfile = hashfp->readByte();
 			r.disks = hashfp->readByte();
 			r.offset = hashfp->readUint32LE();
 			r.size = hashfp->readUint32LE();
-			next_record = hashfp->readUint32LE();
+			uint32 next_record = hashfp->readUint32LE();
 			r.filename = myfilename;
 
 			// As long as we find a hag file, use it immedeiately
 			get_local_name_from_hagfile(local_name, current_hash_record_ptr->hagfile);
-			local_hag_name = f_extension_new(local_name, "HAG");
+			Common::String local_hag_name = f_extension_new(local_name, "HAG");
 			local_name = local_hag_name;
 
 			if (!Common::File::exists(Common::Path(local_name))) {
-				finded = 1;
+				found = 1;
 				find_offset = offset;
 				break;
 			}
@@ -473,7 +447,7 @@ int SysFile::hash_search(const Common::String &fname, Hash_Record *current_hash_
 			}
 			if (next_record == offset) {
 				// only one record of fname in hash table
-				finded = 1;
+				found = 1;
 			} else {
 				offset = next_record;
 			}
@@ -499,7 +473,7 @@ int SysFile::hash_search(const Common::String &fname, Hash_Record *current_hash_
 	}
 
 	f_io_close(hashfp);
-	if (!finded) {
+	if (!found) {
 		error("not in hag file: %s", fname.c_str());
 	}
 
@@ -543,54 +517,51 @@ bool SysFile::get_local_name_from_hagfile(Common::String &local_name, byte hagfi
 bool SysFile::seek(uint32 pos) {
 	if (!_G(hag).hag_flag) {
 		return rs()->seek(pos);
+	}
 
-	} else {
-		if (hag_success) {
-			Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(curr_hag_record->hag_fp);
-			assert(rs);
-
-			if (!rs->seek(curr_hash_record.offset + pos - curr_hag_record->hag_pos, SEEK_CUR))
-				term_message("fail to fseek");
-			last_head_pos = rs->pos();
+	if (hag_success) {
+		Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(curr_hag_record->hag_fp);
+		assert(rs);
 
-			curr_hag_record->hag_pos = curr_hash_record.offset + pos;	// Change file position
-			return true;
+		if (!rs->seek(curr_hash_record.offset + pos - curr_hag_record->hag_pos, SEEK_CUR))
+			term_message("fail to fseek");
+		last_head_pos = rs->pos();
 
-		} else {
-			return false;
-		}
+		curr_hag_record->hag_pos = curr_hash_record.offset + pos;	// Change file position
+		return true;
 	}
+
+	return false;
 }
 
 bool SysFile::seek_ahead(int32 amount) {
 	if (!_G(hag).hag_flag) {
 		return rs()->seek(amount, SEEK_CUR);
 
-	} else {
-		if (hag_success) {
-			Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(curr_hag_record->hag_fp);
-			assert(rs);
+	}
 
-			if (!rs->seek(amount, SEEK_CUR))
-				term_message("fail to fseek");
+	if (hag_success) {
+		Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(curr_hag_record->hag_fp);
+		assert(rs);
 
-			last_head_pos = rs->pos();
-			curr_hag_record->hag_pos += amount;		// Change file position
-			return true;
+		if (!rs->seek(amount, SEEK_CUR))
+			term_message("fail to fseek");
 
-		} else {
-			return false;
-		}
+		last_head_pos = rs->pos();
+		curr_hag_record->hag_pos += amount;		// Change file position
+		return true;
 	}
+
+	return false;
 }
 
 
 uint32 SysFile::read(MemHandle bufferHandle) {
-	int32 bytesToRead  = size() - get_pos();
+	const int32 bytesToRead  = size() - get_pos();
 	if (bytesToRead < 0)
 		error("SysFile::read - %s", filename.c_str());
 
-	return read(bufferHandle, (int32)bytesToRead);
+	return read(bufferHandle, bytesToRead);
 }
 
 int32 SysFile::read(byte *bufferHandle, int32 n) {
@@ -599,8 +570,6 @@ int32 SysFile::read(byte *bufferHandle, int32 n) {
 }
 
 int32 SysFile::read(MemHandle bufferHandle, int32 n) {
-	uint32 temp_size;
-
 	if (!bufferHandle)
 		error("reading %s", filename.c_str());
 
@@ -613,25 +582,24 @@ int32 SysFile::read(MemHandle bufferHandle, int32 n) {
 
 	if (!_G(hag).hag_flag) {
 		return (uint32)rs()->read(*bufferHandle, n);
+	}
 
-	} else {
-		// Hag mode
-		if (hag_success) {
-			Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(curr_hag_record->hag_fp);
-			assert(rs);
-			rs->seek(last_head_pos);
-			uint32 temp_myfpos = rs->pos();
+	// Hag mode
+	if (hag_success) {
+		Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(curr_hag_record->hag_fp);
+		assert(rs);
+		rs->seek(last_head_pos);
+		uint32 temp_myfpos = rs->pos();
 
-			temp_size = (uint32)rs->read(*bufferHandle, n);
-			curr_hag_record->hag_pos = temp_myfpos + temp_size;   // Change file position
+		uint32 temp_size = (uint32)rs->read(*bufferHandle, n);
+		curr_hag_record->hag_pos = temp_myfpos + temp_size;   // Change file position
 
-			last_head_pos = rs->pos();
-			return temp_size;
+		last_head_pos = rs->pos();
+		return temp_size;
 
-		} else {
-			return 0;
-		}
 	}
+
+	return 0;
 }
 
 byte SysFile::readByte() {
@@ -688,9 +656,7 @@ void sysfile_init(bool in_hag_mode) {
 }
 
 void sysfile_shutdown() {
-	Hag_Record *temp_ptr;
-
-	temp_ptr = _G(hag).hag_file_list;
+	Hag_Record *temp_ptr = _G(hag).hag_file_list;
 	while (temp_ptr) {
 		_G(hag).hag_file_list = _G(hag).hag_file_list->next;
 		f_io_close(temp_ptr->hag_fp);
diff --git a/engines/m4/graphics/gr_buff.cpp b/engines/m4/graphics/gr_buff.cpp
index 8d5577a8332..a507aff4145 100644
--- a/engines/m4/graphics/gr_buff.cpp
+++ b/engines/m4/graphics/gr_buff.cpp
@@ -24,7 +24,6 @@
 #include "m4/gui/gui_vmng_core.h"
 #include "m4/core/errors.h"
 #include "m4/mem/memman.h"
-#include "m4/core/term.h"
 
 namespace M4 {
 
@@ -66,15 +65,6 @@ void GrBuff::release() {
 
 void GrBuff::alloc_pixmap() {
 	pixmap = NewHandle(pitch * height, "pixmap");
-	if (!pixmap) {
-		term_message("GrBuff::alloc_pixmap(): Trying to free up %d bytes", pitch * height);
-		if (MakeMem(pitch * height, "pixmap")) {
-			pixmap = NewHandle(pitch * height, "pixmap");
-			if (!pixmap)
-				error_show(FL, 15, "pixmap h:%d w:%d bytes:%d", height, pitch, pitch * height);
-		} else
-			error_show(FL, 1, "GrBuff::alloc_pixmap() x, y: %d %d", pitch, height);
-	}
 	HLock(pixmap);
 	memset(*pixmap, __BLACK, pitch * height);
 	HUnLock(pixmap);
diff --git a/engines/m4/graphics/gr_color.cpp b/engines/m4/graphics/gr_color.cpp
index 2600355f336..6329fe174bb 100644
--- a/engines/m4/graphics/gr_color.cpp
+++ b/engines/m4/graphics/gr_color.cpp
@@ -31,23 +31,13 @@ InvPal::InvPal(const char *filename) {
 	if (!filename)
 		return;
 
-	SysFile ipl5(filename, BINARY);
+	SysFile ipl5(filename);
 
 	if (!ipl5.exists())
 		return;
 
 	handle = NewHandle(32768, "5 bit ict");
 
-	if (!handle) {
-		MakeMem(32768, "5 bit ict");
-		handle = NewHandle(32768, "5 bit ict");
-		if (!handle) {
-			ipl5.close();
-			error_show(FL, 'OOM!', "5 bit ict");
-			return;
-		}
-	}
-
 	ipl5.read(handle, 32768);
 }
 
diff --git a/engines/m4/graphics/gr_font.cpp b/engines/m4/graphics/gr_font.cpp
index cfb53b535f4..b377e7371f7 100644
--- a/engines/m4/graphics/gr_font.cpp
+++ b/engines/m4/graphics/gr_font.cpp
@@ -360,7 +360,7 @@ Font *gr_font_load(const char *fontName) {
 	uint32 tag;
 	Font *newFont;
 
-	SysFile fontFile(fontName, BINARY);
+	SysFile fontFile(fontName);
 	if (!fontFile.exists())
 		return nullptr;
 
diff --git a/engines/m4/gui/game_menu.cpp b/engines/m4/gui/game_menu.cpp
index 6b5c783e3ea..3d845a390c8 100644
--- a/engines/m4/gui/game_menu.cpp
+++ b/engines/m4/gui/game_menu.cpp
@@ -319,9 +319,7 @@ Sprite *SaveLoadMenuBase::menu_CreateThumbnail(int32 *spriteSize) {
 	thumbNailSprite->h = destBuff->h;
 	thumbNailSprite->encoding = RLE8;
 	thumbNailSprite->data = nullptr;
-	if ((thumbNailSprite->sourceHandle = NewHandle(*spriteSize, "thumbNail source")) == nullptr) {
-		return nullptr;
-	}
+	thumbNailSprite->sourceHandle = NewHandle(*spriteSize, "thumbNail source");
 	thumbNailSprite->sourceOffset = 0;
 
 	// Now copy the RLE8Buff into the thumbNail source handle
diff --git a/engines/m4/gui/gui_menu_items.cpp b/engines/m4/gui/gui_menu_items.cpp
index a89682171db..88d483c6f14 100644
--- a/engines/m4/gui/gui_menu_items.cpp
+++ b/engines/m4/gui/gui_menu_items.cpp
@@ -115,30 +115,6 @@ bool guiMenu::initialize(RGB8 *myPalette) {
 	_GM(dumpedCodes) = false;
 	_GM(dumpedBackground) = false;
 
-	// Make sure we have enough memory
-	PurgeMem();
-	CompactMem();
-	int32 memAvail = mem_avail();
-
-	// Dump the screen codes if necessary
-	if (memAvail < MEMORY_NEEDED) {
-		adv_GetCodeMemory();
-		_GM(dumpedCodes) = true;
-		memAvail = mem_avail();
-	}
-
-	// Dump the background if necessary
-	if (memAvail < MEMORY_NEEDED) {
-		adv_GetBackgroundMemory();
-		_GM(dumpedBackground) = true;
-		memAvail = mem_avail();
-	}
-
-	// If we still don't have enough memory, we are hosed
-	if (memAvail < MEMORY_NEEDED) {
-		return false;
-	}
-
 	// Load in the font
 	_GM(menuFont) = gr_font_load("FONTMENU.FNT");
 
@@ -201,8 +177,6 @@ void guiMenu::shutdown(bool fadeToColor) {
 	mem_free((void *)_GM(thumbNails));
 
 	// Restore the background and codes if necessary
-	PurgeMem();
-	CompactMem();
 	if (_GM(dumpedBackground)) {
 		if (!adv_restoreBackground()) {
 			error_show(FL, 0, "unable to restore background");
diff --git a/engines/m4/gui/gui_menu_items.h b/engines/m4/gui/gui_menu_items.h
index 48366e8d91d..603a9efeef4 100644
--- a/engines/m4/gui/gui_menu_items.h
+++ b/engines/m4/gui/gui_menu_items.h
@@ -384,7 +384,6 @@ extern void gui_DrawSprite(Sprite *mySprite, Buffer *myBuff, int32 x, int32 y);
 //
 //		gamemenu module defines
 //
-#define MEMORY_NEEDED		0	// bytes needed for menus to work
 #define MENU_DEPTH 			9 	// video depth for menu popup boxes
 #define MAX_SLOTS			99	// number of save games you can have
 #define MAX_SLOTS_SHOWN 	8	// number of slots in the scrolling field
diff --git a/engines/m4/mem/reloc.cpp b/engines/m4/mem/reloc.cpp
index 05ade98b876..5b6d24f2ba0 100644
--- a/engines/m4/mem/reloc.cpp
+++ b/engines/m4/mem/reloc.cpp
@@ -20,6 +20,7 @@
  */
 
 #include "m4/mem/reloc.h"
+#include "common/textconsole.h"
 
 namespace M4 {
 
@@ -27,8 +28,12 @@ struct HR {
 	void *_data;
 };
 
-MemHandle NewHandle(size_t size, const Common::String &) {
+MemHandle NewHandle(size_t size, const Common::String &str) {
 	HR *result = (HR *)malloc(sizeof(HR));
+
+	if (!result)
+		error("Unable to allocate memory - %d bytes for %s", size, str.c_str());
+
 	result->_data = malloc(size);
 
 	return (MemHandle)result;
@@ -51,8 +56,4 @@ void DisposeHandle(MemHandle handle) {
 	free(handle);
 }
 
-uint32 MaxMem(Size *growBytes) {
-	return 7999999;
-}
-
 } // namespace M4
diff --git a/engines/m4/mem/reloc.h b/engines/m4/mem/reloc.h
index 0208db60908..69a8d0f63b2 100644
--- a/engines/m4/mem/reloc.h
+++ b/engines/m4/mem/reloc.h
@@ -41,15 +41,8 @@ inline bool MakeMem(size_t FreeBlockNeeded, const char *) {
 
 MemHandle MakeNewHandle(size_t size, const Common::String &);
 bool mem_ReallocateHandle(MemHandle h, size_t size, const Common::String &name);
-MemHandle NewHandle(size_t size, const Common::String &);
+MemHandle NewHandle(size_t size, const Common::String &str);
 void DisposeHandle(MemHandle handle);
-uint32 MaxMem(Size *growBytes);
-
-inline void PurgeMem() {}
-inline void CompactMem() {}
-inline size_t mem_avail() { return 0; }
-inline void adv_GetCodeMemory() {}
-inline void adv_GetBackgroundMemory() {}
 
 } // namespace M4
 
diff --git a/engines/m4/mem/res.cpp b/engines/m4/mem/res.cpp
index 64cb6089994..9295e1d1bae 100644
--- a/engines/m4/mem/res.cpp
+++ b/engines/m4/mem/res.cpp
@@ -102,14 +102,14 @@ MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSiz
 		*resourceSize = 0;
 
 	if (!(resEntry = findAndSetResEntry(resourceName))) {
-		term_message("rgetting:%s  -> failed!", resourceName.c_str());
+		term_message("rget:%s  -> failed!", resourceName.c_str());
 		return nullptr;
 	}
 
 	// Check if resource is fully buffered
 	// All resources are currently fully buffered!
 	if (!(resEntry->Flags & FULLY_BUFFERED)) {
-		term_message("rgetting:%s  -> failed!", resourceName.c_str());
+		term_message("rget:%s  -> failed!", resourceName.c_str());
 		return nullptr;
 	}
 
@@ -121,7 +121,7 @@ MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSiz
 
 		HNoPurge(resEntry->RHandle);
 		resEntry->Flags &= ~MARKED_PURGE;
-		term_message("rgetting:%s  -> from memory", resourceName.c_str());
+		term_message("rget:%s  -> from memory", resourceName.c_str());
 		return resEntry->RHandle; 
 	}
 
@@ -135,22 +135,11 @@ MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSiz
 
 	// Check if resource handle allocated
 	if (!resEntry->RHandle)
-		if (!(resEntry->RHandle = MakeNewHandle(resEntry->BufferSize, resEntry->name.c_str())))
-			error("rgetting: %s  -> failed", resEntry->name.c_str());
+		resEntry->RHandle = MakeNewHandle(resEntry->BufferSize, resEntry->name.c_str());
 
 	// Check if resource handle has valid memory block allocated to	it
 	if (!*resEntry->RHandle)
-		if (!mem_ReallocateHandle(resEntry->RHandle, resEntry->BufferSize, resEntry->name.c_str())) {
-			if (MakeMem(resEntry->BufferSize, resEntry->name.c_str())) {
-				if (!mem_ReallocateHandle(resEntry->RHandle, resEntry->BufferSize, resEntry->name.c_str())) {
-					term_message("rgetting:%s  -> failed!", resourceName.c_str());
-					return nullptr;
-				}
-			} else {
-				term_message("rgetting:%s  -> failed!", resourceName.c_str());
-				return nullptr;
-			}
-		}
+		mem_ReallocateHandle(resEntry->RHandle, resEntry->BufferSize, resEntry->name.c_str());
 
 	if (!do_file(resEntry->RHandle))
 		error("rget: do_file -> %s", resourceName.c_str());
@@ -158,7 +147,7 @@ MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSiz
 	if (resourceSize)		    // xi change
 		*resourceSize = resEntry->Size;
 
-	term_message("rgetting:%s  -> from disk", resourceName.c_str());
+	term_message("rget:%s  -> from disk", resourceName.c_str());
 	return resEntry->RHandle;
 }
 
diff --git a/engines/m4/riddle/gui/game_menu.cpp b/engines/m4/riddle/gui/game_menu.cpp
index fe582d579ae..125bbdf96c7 100644
--- a/engines/m4/riddle/gui/game_menu.cpp
+++ b/engines/m4/riddle/gui/game_menu.cpp
@@ -23,16 +23,11 @@
 #include "m4/riddle/vars.h"
 #include "graphics/thumbnail.h"
 #include "m4/adv_r/other.h"
-#include "m4/adv_r/adv_background.h"
-#include "m4/adv_r/adv_control.h"
 #include "m4/adv_r/adv_player.h"
-#include "m4/core/errors.h"
 #include "m4/core/imath.h"
 #include "m4/gui/gui_event.h"
 #include "m4/gui/hotkeys.h"
-#include "m4/graphics/gr_line.h"
 #include "m4/graphics/gr_sprite.h"
-#include "m4/graphics/krn_pal.h"
 #include "m4/gui/gui_sys.h"
 #include "m4/gui/gui_vmng.h"
 #include "m4/mem/mem.h"
@@ -91,10 +86,6 @@ void GameMenu::show(RGB8 *myPalette) {
 		guiMenu::initialize(myPalette);
 	}
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("gamemenu", GM_TOTAL_SPRITES))
 		error("Error loading gamemenu");
@@ -351,10 +342,6 @@ void SaveLoadMenu::show(RGB8 *myPalette, bool saveMenu) {
 	if (!_G(menuSystemInitialized))
 		guiMenu::initialize(myPalette);
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("slmenu", GUI::SaveLoadMenuBase::SL_TOTAL_SPRITES)) {
 		return;
@@ -829,10 +816,6 @@ void ErrorMenu::show(RGB8 *myPalette) {
 		guiMenu::initialize(myPalette);
 	}
 
-	// Keep the memory tidy
-	PurgeMem();
-	CompactMem();
-
 	// Load in the game menu sprites
 	if (!guiMenu::loadSprites("errmenu", EM_TOTAL_SPRITES)) {
 		return;
diff --git a/engines/m4/riddle/rooms/section2/room204.cpp b/engines/m4/riddle/rooms/section2/room204.cpp
index 7071ca5147b..7f4269a7a09 100644
--- a/engines/m4/riddle/rooms/section2/room204.cpp
+++ b/engines/m4/riddle/rooms/section2/room204.cpp
@@ -993,6 +993,7 @@ done:
 }
 
 void Room204::daemon() {
+	warning("Trigger %d", _G(kernel).trigger);
 	switch (_G(kernel).trigger) {
 	case 5:
 		digi_play("204r47", 1, 255, -1, -1);
@@ -2410,7 +2411,6 @@ void Room204::daemon() {
 	case 675:
 		player_set_commands_allowed(false);
 		digi_preload("950_s34", -1);
-		CompactMem();
 		midi_play("RIPTHEM1", 180, 0, -1, 949);
 		_204pu99Series = series_load("204PU99", -1, nullptr);
 		_ripSketchingInNotebookPos2Series = series_load("RIP SKETCHING IN NOTEBOOK POS 2", -1, nullptr);
diff --git a/engines/m4/riddle/rooms/section9/room903.cpp b/engines/m4/riddle/rooms/section9/room903.cpp
index 1ec06c4f455..4ee286af543 100644
--- a/engines/m4/riddle/rooms/section9/room903.cpp
+++ b/engines/m4/riddle/rooms/section9/room903.cpp
@@ -103,7 +103,6 @@ void Room903::daemon() {
 		digi_unload("gunshot1");
 		digi_unload("gunshot2");
 		digi_unload("ricochet");
-		MaxMem(nullptr);
 		series_plain_play("903 hold frame", -1, 0, 100, 256, 3000, -1, false);
 		kernel_timing_trigger(120, 201, nullptr);
 		break;
diff --git a/engines/m4/riddle/rooms/section9/room917.cpp b/engines/m4/riddle/rooms/section9/room917.cpp
index 9f51c58cf92..7ada34de303 100644
--- a/engines/m4/riddle/rooms/section9/room917.cpp
+++ b/engines/m4/riddle/rooms/section9/room917.cpp
@@ -152,7 +152,6 @@ void Room917::daemon() {
 		digi_unload("950_S48b");
 		digi_unload("950_S48c");
 		digi_unload("950_S50");
-		MaxMem(nullptr);
 		_G(game).new_room = 493;
 		_G(game).new_section = 4;
 		break;
diff --git a/engines/m4/wscript/ws_load.cpp b/engines/m4/wscript/ws_load.cpp
index bc9ff4a493c..0556077d6f3 100644
--- a/engines/m4/wscript/ws_load.cpp
+++ b/engines/m4/wscript/ws_load.cpp
@@ -620,8 +620,7 @@ int32 LoadSpriteSeriesDirect(const char *assetName, MemHandle *seriesHandle, int
 	assetSize = f.size();
 
 	// Create a handle big enough to hold the contents of the file
-	if ((workHandle = NewHandle(assetSize, "ss file")) == nullptr)
-		return -1;
+	workHandle = NewHandle(assetSize, "ss file");
 
 	// Lock the handle and read the contents of the file intoit
 	HLock(workHandle);
@@ -1092,11 +1091,9 @@ int32 LoadSpriteSeries(const char *assetName, Handle *seriesHandle, int32 *celsO
 }
 
 int32 LoadSpriteSeriesDirect(const char *assetName, Handle *seriesHandle, int32 *celsOffset, int32 *palOffset, RGB8 *myPalette) {
-	MemHandle workHandle;
 	Common::File f;
 	int32 celsSize, *celsPtr, *palPtr;
-	char *mainAssetPtr, *endOfAssetBlock, *parseAssetPtr;
-	uint32 assetSize;
+	char *parseAssetPtr;
 
 	// This loads a sprite series into the provided vars, rather than the WS tables.
 	// The WS loader is not involved with this procedure.
@@ -1106,17 +1103,14 @@ int32 LoadSpriteSeriesDirect(const char *assetName, Handle *seriesHandle, int32
 		return -1;
 
 	// Get the size
-	assetSize = f.size();
+	const uint32 assetSize = f.size();
 
 	// Create a handle big enough to hold the contents of the file
-	if ((workHandle = NewHandle(assetSize, "ss file")) == nullptr) {
-		f.close();
-		return -1;
-	}
+	MemHandle workHandle = NewHandle(assetSize, "ss file");
 
 	// Lock the handle and read the contents of the file intoit
 	HLock(workHandle);
-	mainAssetPtr = (char *)*workHandle;
+	char *mainAssetPtr = (char *)*workHandle;
 	if (f.read(mainAssetPtr, assetSize) < assetSize) {
 		f.close();
 		mem_free(workHandle);
@@ -1127,7 +1121,7 @@ int32 LoadSpriteSeriesDirect(const char *assetName, Handle *seriesHandle, int32
 	f.close();
 
 	// Set up some pointers
-	endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
+	char *endOfAssetBlock = (char *)((intptr)mainAssetPtr + assetSize);
 	parseAssetPtr = mainAssetPtr;
 
 	// Process the SS from the stream file
@@ -1146,7 +1140,6 @@ int32 LoadSpriteSeriesDirect(const char *assetName, Handle *seriesHandle, int32
 
 CCB *GetWSAssetCEL(uint32 hash, uint32 index, CCB *myCCB) {
 	bool streamSeries;
-	M4sprite *mySprite;
 
 	// Ensure the WS loader has been initialized.
 	if (!_GWS(wsloaderInitialized)) {
@@ -1180,7 +1173,7 @@ CCB *GetWSAssetCEL(uint32 hash, uint32 index, CCB *myCCB) {
 	}
 
 	//The source for a CCB is a sprite.  create the sprite from the WS tables hash, index
-	mySprite = myCCB->source;
+	M4sprite *mySprite = myCCB->source;
 	if ((mySprite = GetWSAssetSprite(nullptr, hash, index, mySprite, &streamSeries)) == nullptr) {
 		// Term messages for whatever went wrong are printed from within GetWSAssetSprite()
 		return nullptr;
@@ -1202,8 +1195,6 @@ CCB *GetWSAssetCEL(uint32 hash, uint32 index, CCB *myCCB) {
 }
 
 int32 GetWSAssetCELCount(uint32 hash) {
-	uint32 *celsPtr;
-
 	// Ensure the WS loader has been initialized.
 	if (!_GWS(wsloaderInitialized)) {
 		ws_LogErrorMsg(FL, "WS loader has not been initialized.");
@@ -1223,7 +1214,7 @@ int32 GetWSAssetCELCount(uint32 hash) {
 	}
 
 	// Find and return the number of sprites in the SS
-	celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
+	uint32 *celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
 	return FROM_LE_32(celsPtr[CELS_COUNT]);
 }
 




More information about the Scummvm-git-logs mailing list