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

OMGPizzaGuy 48367439+OMGPizzaGuy at users.noreply.github.com
Sun Feb 21 21:20:05 UTC 2021


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:
f2f1c9b4d4 ULTIMA8: Switch IDataSource to SeekableReadStream where possible


Commit: f2f1c9b4d462faf58af919f9e7db24bfde247405
    https://github.com/scummvm/scummvm/commit/f2f1c9b4d462faf58af919f9e7db24bfde247405
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2021-02-21T15:19:50-06:00

Commit Message:
ULTIMA8: Switch IDataSource to SeekableReadStream where possible

Changed paths:
    engines/ultima/ultima8/audio/music_flex.cpp
    engines/ultima/ultima8/filesys/idata_source.h
    engines/ultima/ultima8/filesys/raw_archive.cpp
    engines/ultima/ultima8/filesys/raw_archive.h
    engines/ultima/ultima8/filesys/savegame.cpp
    engines/ultima/ultima8/filesys/savegame.h
    engines/ultima/ultima8/games/game_info.cpp
    engines/ultima/ultima8/games/game_info.h
    engines/ultima/ultima8/graphics/skf_player.cpp
    engines/ultima/ultima8/ultima8.cpp
    engines/ultima/ultima8/usecode/uc_machine.cpp


diff --git a/engines/ultima/ultima8/audio/music_flex.cpp b/engines/ultima/ultima8/audio/music_flex.cpp
index ce4a479a9a..6dcf9ba0bf 100644
--- a/engines/ultima/ultima8/audio/music_flex.cpp
+++ b/engines/ultima/ultima8/audio/music_flex.cpp
@@ -109,12 +109,12 @@ void MusicFlex::loadSongInfo() {
 	if (!buf || !size) {
 		error("Unable to load song info from sound/music.flx");
 	}
-	IBufferDataSource ds(buf, size);
+	Common::MemoryReadStream ds(buf, size);
 	Std::string line;
 
 	// Read first section till we hit a #
 	for (;;) {
-		ds.readline(line);
+		line = ds.readLine();
 
 		// We have hit the end of the section
 		if (line.at(0) == '#') break;
@@ -158,7 +158,7 @@ void MusicFlex::loadSongInfo() {
 	// Read 'Section2', or more like skip it, since it's only trans.xmi
 	// Read first section till we hit a #
 	for (;;) {
-		ds.readline(line);
+		line = ds.readLine();
 
 		// We have hit the end of the section
 		if (line.at(0) == '#') break;
@@ -166,7 +166,7 @@ void MusicFlex::loadSongInfo() {
 
 	// Skip 'Section3'
 	for (;;) {
-		ds.readline(line);
+		line = ds.readLine();
 
 		// We have hit the end of the section
 		if (line.at(0) == '#') break;
@@ -174,7 +174,7 @@ void MusicFlex::loadSongInfo() {
 
 	// Read 'Section4' (trans _info)
 	for (;;) {
-		ds.readline(line);
+		line = ds.readLine();
 
 		// We have hit the end of the section
 		if (line.at(0) == '#') break;
diff --git a/engines/ultima/ultima8/filesys/idata_source.h b/engines/ultima/ultima8/filesys/idata_source.h
index 6a70ca46f0..7457498ea3 100644
--- a/engines/ultima/ultima8/filesys/idata_source.h
+++ b/engines/ultima/ultima8/filesys/idata_source.h
@@ -58,18 +58,6 @@ public:
 		else if (num_bytes == 3) return (((static_cast<int32>(readUint24LE())) << 8) >> 8);
 		else return static_cast<int32>(readUint32LE());
 	}
-
-	void readline(Std::string &str) {
-		str.clear();
-		while (!eos()) {
-			char character =  static_cast<char>(readByte());
-
-			if (character == '\r') continue;    // Skip cr
-			else if (character == '\n') break;  // break on line feed
-
-			str += character;
-		}
-	}
 };
 
 class IBufferDataSource : public IDataSource {
@@ -87,20 +75,6 @@ public:
 		_buf = _bufPtr = static_cast<const uint8 *>(data);
 	}
 
-	virtual void load(const void *data, unsigned int len, bool is_text = false,
-	                  bool delete_data = false) {
-		assert(!is_text);
-		if (_freeBuffer && _buf)
-			delete[] const_cast<uint8 *>(_buf);
-		_freeBuffer = false;
-		_buf = _bufPtr = nullptr;
-
-		assert(data != nullptr || len == 0);
-		_buf = _bufPtr = static_cast<const uint8 *>(data);
-		_size = len;
-		_freeBuffer = delete_data;
-	}
-
 	~IBufferDataSource() override {
 		if (_freeBuffer && _buf)
 			delete[] const_cast<uint8 *>(_buf);
diff --git a/engines/ultima/ultima8/filesys/raw_archive.cpp b/engines/ultima/ultima8/filesys/raw_archive.cpp
index 42c3ce1888..609f30cf45 100644
--- a/engines/ultima/ultima8/filesys/raw_archive.cpp
+++ b/engines/ultima/ultima8/filesys/raw_archive.cpp
@@ -20,10 +20,9 @@
  *
  */
 
+#include "common/memstream.h"
 #include "ultima/ultima8/misc/pent_include.h"
-
 #include "ultima/ultima8/filesys/raw_archive.h"
-#include "ultima/ultima8/filesys/idata_source.h"
 
 namespace Ultima {
 namespace Ultima8 {
@@ -88,7 +87,7 @@ uint32 RawArchive::get_size(uint32 index) {
 	return getRawSize(index);
 }
 
-IDataSource *RawArchive::get_datasource(uint32 index) {
+Common::SeekableReadStream *RawArchive::get_datasource(uint32 index) {
 	if (index >= _count)
 		return nullptr;
 	cache(index);
@@ -96,7 +95,7 @@ IDataSource *RawArchive::get_datasource(uint32 index) {
 	if (!_objects[index])
 		return nullptr;
 
-	return new IBufferDataSource(_objects[index], getRawSize(index));
+	return new Common::MemoryReadStream(_objects[index], getRawSize(index));
 }
 
 } // End of namespace Ultima8
diff --git a/engines/ultima/ultima8/filesys/raw_archive.h b/engines/ultima/ultima8/filesys/raw_archive.h
index 93b53b36bf..b5d35a29e4 100644
--- a/engines/ultima/ultima8/filesys/raw_archive.h
+++ b/engines/ultima/ultima8/filesys/raw_archive.h
@@ -52,9 +52,9 @@ public:
 	//! get size of object
 	virtual uint32 get_size(uint32 index);
 
-	//! return object as IDataSource. Delete the IDataSource afterwards,
+	//! return object as SeekableReadStream. Delete the SeekableReadStream afterwards,
 	//! but DON'T delete/modify the buffer it points to.
-	virtual IDataSource *get_datasource(uint32 index);
+	virtual Common::SeekableReadStream *get_datasource(uint32 index);
 
 protected:
 	Std::vector<uint8 *> _objects;
diff --git a/engines/ultima/ultima8/filesys/savegame.cpp b/engines/ultima/ultima8/filesys/savegame.cpp
index 0bd0f48e3a..17a9426334 100644
--- a/engines/ultima/ultima8/filesys/savegame.cpp
+++ b/engines/ultima/ultima8/filesys/savegame.cpp
@@ -73,7 +73,7 @@ SavegameReader::State SavegameReader::isValid() const {
 		return SAVE_VALID;
 }
 
-IDataSource *SavegameReader::getDataSource(const Std::string &name) {
+Common::SeekableReadStream *SavegameReader::getDataSource(const Std::string &name) {
 	assert(_index.contains(name));
 
 	const FileEntry &fe = _index[name];
@@ -81,7 +81,7 @@ IDataSource *SavegameReader::getDataSource(const Std::string &name) {
 	_file->seek(fe._offset);
 	_file->read(data, fe._size);
 
-	return new IBufferDataSource(data, fe._size, false, true);
+	return new Common::MemoryReadStream(data, fe._size, DisposeAfterUse::YES);
 }
 
 
diff --git a/engines/ultima/ultima8/filesys/savegame.h b/engines/ultima/ultima8/filesys/savegame.h
index 539b49150e..169c774bda 100644
--- a/engines/ultima/ultima8/filesys/savegame.h
+++ b/engines/ultima/ultima8/filesys/savegame.h
@@ -60,7 +60,7 @@ public:
 	/**
 	 * Get an entry/section within the save
 	 */
-	IDataSource *getDataSource(const Std::string &name);
+	Common::SeekableReadStream *getDataSource(const Std::string &name);
 };
 
 class SavegameWriter {
diff --git a/engines/ultima/ultima8/games/game_info.cpp b/engines/ultima/ultima8/games/game_info.cpp
index 1118b97439..eb88c53b46 100644
--- a/engines/ultima/ultima8/games/game_info.cpp
+++ b/engines/ultima/ultima8/games/game_info.cpp
@@ -185,11 +185,11 @@ void GameInfo::save(Common::WriteStream *ws) {
 	ws->write(d.c_str(), d.size());
 }
 
-bool GameInfo::load(IDataSource *ids, uint32 ver) {
+bool GameInfo::load(Common::SeekableReadStream *rs, uint32 ver) {
 	Std::string s;
 	Std::vector<Std::string> parts;
 
-	ids->readline(s);
+	s = rs->readLine();
 	SplitString(s, ',', parts);
 	if (parts.size() != 4) return false;
 
diff --git a/engines/ultima/ultima8/games/game_info.h b/engines/ultima/ultima8/games/game_info.h
index 7fa02bb1c7..9885a6be7e 100644
--- a/engines/ultima/ultima8/games/game_info.h
+++ b/engines/ultima/ultima8/games/game_info.h
@@ -72,7 +72,7 @@ struct GameInfo {
 	bool match(GameInfo &other, bool ignoreMD5 = false) const;
 
 	void save(Common::WriteStream *ws);
-	bool load(IDataSource *ids, uint32 /* version */);
+	bool load(Common::SeekableReadStream *rs, uint32 /* version */);
 };
 
 } // End of namespace Ultima8
diff --git a/engines/ultima/ultima8/graphics/skf_player.cpp b/engines/ultima/ultima8/graphics/skf_player.cpp
index 0cd3b0ade7..3fe95a08fd 100644
--- a/engines/ultima/ultima8/graphics/skf_player.cpp
+++ b/engines/ultima/ultima8/graphics/skf_player.cpp
@@ -270,7 +270,7 @@ void SKFPlayer::run() {
 	_curFrame++;
 
 	PaletteManager *palman = PaletteManager::get_instance();
-	IDataSource *object;
+	Common::SeekableReadStream *object;
 
 	uint16 objecttype = 0;
 	do {
diff --git a/engines/ultima/ultima8/ultima8.cpp b/engines/ultima/ultima8/ultima8.cpp
index ff9ab5b4ff..3cf54294aa 100644
--- a/engines/ultima/ultima8/ultima8.cpp
+++ b/engines/ultima/ultima8/ultima8.cpp
@@ -1192,7 +1192,7 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
 	_mouse->paint();
 	_screen->EndPainting();
 
-	IDataSource *ds;
+	Common::SeekableReadStream *ds;
 	GameInfo saveinfo;
 	ds = sg->getDataSource("GAME");
 	uint32 version = sg->getVersion();
diff --git a/engines/ultima/ultima8/usecode/uc_machine.cpp b/engines/ultima/ultima8/usecode/uc_machine.cpp
index fe493e17e1..66f84d3246 100644
--- a/engines/ultima/ultima8/usecode/uc_machine.cpp
+++ b/engines/ultima/ultima8/usecode/uc_machine.cpp
@@ -20,6 +20,8 @@
  *
  */
 
+#include "common/memstream.h"
+
 #include "ultima/ultima8/misc/pent_include.h"
 #include "ultima/ultima8/usecode/uc_machine.h"
 #include "ultima/ultima8/usecode/uc_process.h"
@@ -34,7 +36,6 @@
 #include "ultima/ultima8/usecode/uc_list.h"
 #include "ultima/ultima8/misc/id_man.h"
 #include "ultima/ultima8/world/get_object.h"
-#include "ultima/ultima8/filesys/idata_source.h"
 
 #include "ultima/ultima8/convert/u8/convert_usecode_u8.h"
 #include "ultima/ultima8/convert/crusader/convert_usecode_regret.h"
@@ -155,9 +156,9 @@ void UCMachine::execProcess(UCProcess *p) {
 	assert(p);
 
 	uint32 base = p->_usecode->get_class_base_offset(p->_classId);
-	IBufferDataSource cs(p->_usecode->get_class(p->_classId) + base,
-	                     p->_usecode->get_class_size(p->_classId) - base);
-	cs.seek(p->_ip);
+	Common::SeekableReadStream *cs = new Common::MemoryReadStream(p->_usecode->get_class(p->_classId) + base,
+																  p->_usecode->get_class_size(p->_classId) - base);
+	cs->seek(p->_ip);
 
 #ifdef DEBUG
 	if (trace_show(p->_pid, p->_itemNum, p->_classId)) {
@@ -175,7 +176,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		//! guard against reading past end of class
 		//! guard against other error conditions
 
-		uint8 opcode = cs.readByte();
+		uint8 opcode = cs->readByte();
 
 #ifdef DEBUG
 		uint16 trace_classid = p->_classId;
@@ -199,7 +200,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x00:
 			// 00 xx
 			// pop 16 bit int, and assign LS 8 bit int into bp+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.pop2();
 			p->_stack.assign1(p->_bp + si8a, static_cast<uint8>(ui16a));
 			LOGPF(("pop byte\t%s = %02Xh\n", print_bp(si8a), ui16a));
@@ -208,7 +209,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x01:
 			// 01 xx
 			// pop 16 bit int into bp+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.pop2();
 			p->_stack.assign2(p->_bp + si8a, ui16a);
 			LOGPF(("pop\t\t%s = %04Xh\n", print_bp(si8a), ui16a));
@@ -217,7 +218,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x02:
 			// 02 xx
 			// pop 32 bit int into bp+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui32a = p->_stack.pop4();
 			p->_stack.assign4(p->_bp + si8a, ui32a);
 			LOGPF(("pop dword\t%s = %08Xh\n", print_bp(si8a), ui32a));
@@ -226,8 +227,8 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x03: {
 			// 03 xx yy
 			// pop yy bytes into bp+xx
-			si8a = static_cast<int8>(cs.readByte());
-			uint8 size = cs.readByte();
+			si8a = static_cast<int8>(cs->readByte());
+			uint8 size = cs->readByte();
 			uint8 buf[256];
 			p->_stack.pop(buf, size);
 			p->_stack.assign(p->_bp + si8a, buf, size);
@@ -250,9 +251,9 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x09: {
 			// 09 xx yy zz
 			// pop yy bytes into an element of list bp+xx (or slist if zz set)
-			si8a = static_cast<int8>(cs.readByte());
-			ui32a = cs.readByte();
-			si8b = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
+			ui32a = cs->readByte();
+			si8b = static_cast<int8>(cs->readByte());
 			LOGPF(("assign element\t%s (%02X) (slist==%02X)\n",
 			       print_bp(si8a), ui32a, si8b));
 			ui16a = p->_stack.pop2() - 1; // index
@@ -286,7 +287,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x0A:
 			// 0A xx
 			// push sign-extended 8 bit xx onto the stack as 16 bit
-			ui16a = static_cast<int8>(cs.readByte());
+			ui16a = static_cast<int8>(cs->readByte());
 			p->_stack.push2(ui16a);
 			LOGPF(("push byte\t%04Xh\n", ui16a));
 			break;
@@ -294,7 +295,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x0B:
 			// 0B xx xx
 			// push 16 bit xxxx onto the stack
-			ui16a = cs.readUint16LE();
+			ui16a = cs->readUint16LE();
 			p->_stack.push2(ui16a);
 			LOGPF(("push\t\t%04Xh\n", ui16a));
 			break;
@@ -302,7 +303,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x0C:
 			// 0C xx xx xx xx
 			// push 32 bit xxxxxxxx onto the stack
-			ui32a = cs.readUint32LE();
+			ui32a = cs->readUint32LE();
 			p->_stack.push4(ui32a);
 			LOGPF(("push dword\t%08Xh\n", ui32a));
 			break;
@@ -310,9 +311,9 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x0D: {
 			// 0D xx xx yy ... yy 00
 			// push string (yy ... yy) of length xx xx onto the stack
-			ui16a = cs.readUint16LE();
+			ui16a = cs->readUint16LE();
 			char *str = new char[ui16a + 1];
-			cs.read(str, ui16a);
+			cs->read(str, ui16a);
 			str[ui16a] = 0;
 
 			// REALLY MAJOR HACK:
@@ -325,7 +326,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			}
 
 			LOGPF(("push string\t\"%s\"\n", str));
-			ui16b = cs.readByte();
+			ui16b = cs->readByte();
 			if (ui16b != 0) {
 				perr << "Zero terminator missing in push string"
 				     << Std::endl;
@@ -340,8 +341,8 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 0E xx yy
 			// pop yy values of size xx and push the resulting list
 			// (list is created in reverse order)
-			ui16a = cs.readByte();
-			ui16b = cs.readByte();
+			ui16a = cs->readByte();
+			ui16b = cs->readByte();
 			UCList *l = new UCList(ui16a, ui16b);
 			p->_stack.addSP(ui16a * (ui16b - 1));
 			for (unsigned int i = 0; i < ui16b; i++) {
@@ -361,8 +362,8 @@ void UCMachine::execProcess(UCProcess *p) {
 			// intrinsic call. xx is number of argument bytes
 			// (includes this pointer, if present)
 			// NB: do not actually pop these argument bytes
-			uint16 arg_bytes = cs.readByte();
-			uint16 func = cs.readUint16LE();
+			uint16 arg_bytes = cs->readByte();
+			uint16 func = cs->readUint16LE();
 			LOGPF(("calli\t\t%04Xh (%02Xh arg bytes) %s\n", func, arg_bytes, _convUse->intrinsics()[func]));
 
 			// !constants
@@ -426,22 +427,23 @@ void UCMachine::execProcess(UCProcess *p) {
 			// call the function at offset yy yy of class xx xx
 			// Crusader:
 			// call function number yy yy of class xx xx
-			uint16 new_classid = cs.readUint16LE();
-			uint16 new_offset = cs.readUint16LE();
+			uint16 new_classid = cs->readUint16LE();
+			uint16 new_offset = cs->readUint16LE();
 			LOGPF(("call\t\t%04X:%04X\n", new_classid, new_offset));
 			if (GAME_IS_CRUSADER) {
 				new_offset = p->_usecode->get_class_event(new_classid,
 				             new_offset);
 			}
 
-			p->_ip = static_cast<uint16>(cs.pos());   // Truncates!!
+			p->_ip = static_cast<uint16>(cs->pos());   // Truncates!!
 			p->call(new_classid, new_offset);
 
 			// Update the code segment
 			uint32 base_ = p->_usecode->get_class_base_offset(p->_classId);
-			cs.load(p->_usecode->get_class(p->_classId) + base_,
-			        p->_usecode->get_class_size(p->_classId) - base_);
-			cs.seek(p->_ip);
+			delete cs;
+			cs = new Common::MemoryReadStream(p->_usecode->get_class(p->_classId) + base_,
+											  p->_usecode->get_class_size(p->_classId) - base_);
+			cs->seek(p->_ip);
 
 			// Resume execution
 			break;
@@ -541,7 +543,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x19: {
 			// 19 02
 			// add two stringlists, removing duplicates
-			ui32a = cs.readByte();
+			ui32a = cs->readByte();
 			if (ui32a != 2) {
 				perr << "Unhandled operand " << ui32a << " to union slist"
 				     << Std::endl;
@@ -565,7 +567,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x1A: {
 			// 1A 02
 			// subtract string list
-			ui32a = cs.readByte(); // elementsize (always 02)
+			ui32a = cs->readByte(); // elementsize (always 02)
 			ui32a = 2;
 			ui16a = p->_stack.pop2();
 			ui16b = p->_stack.pop2();
@@ -587,7 +589,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// pop two lists from the stack of element size xx and
 			// remove the 2nd from the 1st
 			// (free the originals? order?)
-			ui32a = cs.readByte(); // elementsize
+			ui32a = cs->readByte(); // elementsize
 			ui16a = p->_stack.pop2();
 			ui16b = p->_stack.pop2();
 			UCList *srclist = getList(ui16a);
@@ -950,8 +952,8 @@ void UCMachine::execProcess(UCProcess *p) {
 			// is element (size xx) in list? (or slist if yy is true)
 			// free list/slist afterwards
 
-			ui16a = cs.readByte();
-			ui32a = cs.readByte();
+			ui16a = cs->readByte();
+			ui32a = cs->readByte();
 			ui16b = p->_stack.pop2();
 			UCList *l = getList(ui16b);
 			if (!l) {
@@ -1040,7 +1042,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x3E:
 			// 3E xx
 			// push the value of the unsigned 8 bit local var xx as 16 bit int
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access1(p->_bp + si8a);
 			p->_stack.push2(ui16a);
 			LOGPF(("push byte\t%s = %02Xh\n", print_bp(si8a), ui16a));
@@ -1049,7 +1051,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x3F:
 			// 3F xx
 			// push the value of the 16 bit local var xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_bp + si8a);
 			p->_stack.push2(ui16a);
 			LOGPF(("push\t\t%s = %04Xh\n", print_bp(si8a), ui16a));
@@ -1058,7 +1060,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x40:
 			// 40 xx
 			// push the value of the 32 bit local var xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui32a = p->_stack.access4(p->_bp + si8a);
 			p->_stack.push4(ui32a);
 			LOGPF(("push dword\t%s = %08Xh\n", print_bp(si8a), ui32a));
@@ -1068,7 +1070,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 41 xx
 			// push the string local var xx
 			// duplicating the string?
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_bp + si8a);
 			p->_stack.push2(duplicateString(ui16a));
 			LOGPF(("push string\t%s\n", print_bp(si8a)));
@@ -1078,8 +1080,8 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 42 xx yy
 			// push the list (with yy size elements) at BP+xx
 			// duplicating the list?
-			si8a = static_cast<int8>(cs.readByte());
-			ui16a = cs.readByte();
+			si8a = static_cast<int8>(cs->readByte());
+			ui16a = cs->readByte();
 			ui16b = p->_stack.access2(p->_bp + si8a);
 			UCList *l = new UCList(ui16a);
 			if (getList(ui16b)) {
@@ -1100,7 +1102,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 43 xx
 			// push the stringlist local var xx
 			// duplicating the list, duplicating the strings in the list
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = 2;
 			ui16b = p->_stack.access2(p->_bp + si8a);
 			UCList *l = new UCList(ui16a);
@@ -1126,8 +1128,8 @@ void UCMachine::execProcess(UCProcess *p) {
 			// duplicate string if YY? yy = 1 only occurs
 			// in two places in U8: once it pops into temp afterwards,
 			// once it is indeed freed. So, guessing we should duplicate.
-			ui32a = cs.readByte();
-			ui32b = cs.readByte();
+			ui32a = cs->readByte();
+			ui32b = cs->readByte();
 			ui16a = p->_stack.pop2() - 1; // index
 			ui16b = p->_stack.pop2(); // list
 			UCList *l = getList(ui16b);
@@ -1156,8 +1158,8 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x45:
 			// 45 xx yy
 			// push huge of size yy from BP+xx
-			si8a = static_cast<int8>(cs.readByte());
-			ui16b = cs.readByte();
+			si8a = static_cast<int8>(cs->readByte());
+			ui16b = cs->readByte();
 			p->_stack.push(p->_stack.access(p->_bp + si8a), ui16b);
 			LOGPF(("push huge\t%s %02X\n", print_bp(si8a), ui16b));
 			break;
@@ -1171,7 +1173,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x4B:
 			// 4B xx
 			// push 32 bit pointer address of BP+XX
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			p->_stack.push4(stackToPtr(p->_pid, p->_bp + si8a));
 			LOGPF(("push addr\t%s\n", print_bp(si8a)));
 			break;
@@ -1181,7 +1183,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// indirect push,
 			// pops a 32 bit pointer off the stack and pushes xx bytes
 			// from the location referenced by the pointer
-			ui16a = cs.readByte();
+			ui16a = cs->readByte();
 			ui32a = p->_stack.pop4();
 
 			p->_stack.addSP(-ui16a);
@@ -1204,7 +1206,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// indirect pop
 			// pops a 32 bit pointer off the stack and pushes xx bytes
 			// from the location referenced by the pointer
-			ui16a = cs.readByte();
+			ui16a = cs->readByte();
 			ui32a = p->_stack.pop4();
 
 			if (assignPointer(ui32a, p->_stack.access(), ui16a)) {
@@ -1220,8 +1222,8 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x4E:
 			// 4E xx xx yy
 			// push global xxxx size yy bits
-			ui16a = cs.readUint16LE();
-			ui16b = cs.readByte();
+			ui16a = cs->readUint16LE();
+			ui16b = cs->readByte();
 			ui32a = _globals->getEntries(ui16a, ui16b);
 			p->_stack.push2(static_cast<uint16>(ui32a));
 			LOGPF(("push\t\tglobal [%04X %02X] = %02X\n", ui16a, ui16b, ui32a));
@@ -1230,8 +1232,8 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x4F:
 			// 4F xx xx yy
 			// pop value into global xxxx size yy bits
-			ui16a = cs.readUint16LE();
-			ui16b = cs.readByte();
+			ui16a = cs->readUint16LE();
+			ui16b = cs->readByte();
 			ui32a = p->_stack.pop2();
 			_globals->setEntries(ui16a, ui16b, ui32a);
 
@@ -1267,9 +1269,11 @@ void UCMachine::execProcess(UCProcess *p) {
 
 				// Update the code segment
 				uint32 base_ = p->_usecode->get_class_base_offset(p->_classId);
-				cs.load(p->_usecode->get_class(p->_classId) + base_,
-				        p->_usecode->get_class_size(p->_classId) - base_);
-				cs.seek(p->_ip);
+
+				delete cs;
+				cs = new Common::MemoryReadStream(p->_usecode->get_class(p->_classId) + base_,
+												  p->_usecode->get_class_size(p->_classId) - base_);
+				cs->seek(p->_ip);
 			}
 
 			// Resume execution
@@ -1278,26 +1282,26 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x51:
 			// 51 xx xx
 			// relative jump to xxxx if false
-			si16a = static_cast<int16>(cs.readUint16LE());
+			si16a = static_cast<int16>(cs->readUint16LE());
 			ui16b = p->_stack.pop2();
 			if (!ui16b) {
-				ui16a = cs.pos() + si16a;
-				cs.seek(ui16a);
+				ui16a = cs->pos() + si16a;
+				cs->seek(ui16a);
 				LOGPF(("jne\t\t%04hXh\t(to %04X) (taken)\n", si16a,
-				       cs.pos()));
+				       cs->pos()));
 			} else {
 				LOGPF(("jne\t\t%04hXh\t(to %04X) (not taken)\n", si16a,
-				       cs.pos()));
+				       cs->pos()));
 			}
 			break;
 
 		case 0x52:
 			// 52 xx xx
 			// relative jump to xxxx
-			si16a = static_cast<int16>(cs.readUint16LE());
-			ui16a = cs.pos() + si16a;
-			cs.seek(ui16a);
-			LOGPF(("jmp\t\t%04hXh\t(to %04X)\n", si16a, cs.pos()));
+			si16a = static_cast<int16>(cs->readUint16LE());
+			ui16a = cs->pos() + si16a;
+			cs->seek(ui16a);
+			LOGPF(("jmp\t\t%04hXh\t(to %04X)\n", si16a, cs->pos()));
 			break;
 
 		case 0x53:
@@ -1328,7 +1332,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 0x6D (push process result) only seems to occur soon after
 			// an 'implies'
 
-			cs.readUint16LE(); // skip the 01 01
+			cs->readUint16LE(); // skip the 01 01
 			ui16a = p->_stack.pop2();
 			ui16b = p->_stack.pop2();
 			p->_stack.push2(ui16a); //!! which pid do we need to push!?
@@ -1370,10 +1374,10 @@ void UCMachine::execProcess(UCProcess *p) {
 			// tt = sizeof this pointer object
 			// only remove the this pointer from stack (4 bytes)
 			// put PID of spawned process in temp
-			int arg_bytes = cs.readByte();
-			int this_size = cs.readByte();
-			uint16 classid = cs.readUint16LE();
-			uint16 offset = cs.readUint16LE();
+			int arg_bytes = cs->readByte();
+			int this_size = cs->readByte();
+			uint16 classid = cs->readUint16LE();
+			uint16 offset = cs->readUint16LE();
 
 			uint32 thisptr = p->_stack.pop4();
 
@@ -1410,11 +1414,11 @@ void UCMachine::execProcess(UCProcess *p) {
 			// spawn inline process function yyyy in class xxxx at offset zzzz
 			// tt = size of this pointer
 			// uu = unknown (occurring values: 00, 02, 05) - seems unused in original
-			uint16 classid = cs.readUint16LE();
-			uint16 offset = cs.readUint16LE();
-			uint16 delta = cs.readUint16LE();
-			int this_size = cs.readByte();
-			int unknown = cs.readByte(); // ??
+			uint16 classid = cs->readUint16LE();
+			uint16 offset = cs->readUint16LE();
+			uint16 delta = cs->readUint16LE();
+			int this_size = cs->readByte();
+			int unknown = cs->readByte(); // ??
 
 			debug(MM_INFO, "spawn inline\t%04X:%04X+%04X=%04X %02X %02X\n",
 				classid, offset, delta, offset + delta, this_size, unknown);
@@ -1450,7 +1454,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 5A xx
 			// init function. xx = local var size
 			// sets xx bytes on stack to 0, moving sp
-			ui16a = cs.readByte();
+			ui16a = cs->readByte();
 			LOGPF(("init\t\t%02X\n", ui16a));
 
 			if (ui16a & 1) ui16a++; // 16-bit align
@@ -1462,7 +1466,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x5B:
 			// 5B xx xx
 			// debug line no xx xx
-			ui16a = cs.readUint16LE(); // source line number
+			ui16a = cs->readUint16LE(); // source line number
 			debug(10, "ignore debug opcode %02X: line offset %d", opcode, ui16a);
 			LOGPF(("line number %d\n", ui16a));
 			break;
@@ -1470,11 +1474,11 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x5C: {
 			// 5C xx xx char[9]
 			// debug line no xx xx in class str
-			ui16a = cs.readUint16LE(); // source line number
+			ui16a = cs->readUint16LE(); // source line number
 			char name[10] = {0};
 			for (int x = 0; x < 9; x++) {
 				// skip over class name and null terminator
-				name[x] = cs.readByte();
+				name[x] = cs->readByte();
 			}
 			LOGPF(("line number %s %d\n", name, ui16a));
 			debug(10, "ignore debug opcode %02X: %s line offset %d", opcode, name, ui16a);
@@ -1524,7 +1528,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x62:
 			// 62 xx
 			// free the string in var BP+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_bp + si8a);
 			freeString(ui16a);
 			LOGPF(("free string\t%s = %04X\n", print_bp(si8a), ui16a));
@@ -1533,7 +1537,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x63:
 			// 63 xx
 			// free the stringlist in var BP+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_bp + si8a);
 			freeStringList(ui16a);
 			LOGPF(("free slist\t%s = %04X\n", print_bp(si8a), ui16a));
@@ -1542,7 +1546,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x64:
 			// 64 xx
 			// free the list in var BP+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_bp + si8a);
 			freeList(ui16a);
 			LOGPF(("free list\t%s = %04X\n", print_bp(si8a), ui16a));
@@ -1553,7 +1557,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// free the string at SP+xx
 			// NB: sometimes there's a 32-bit string pointer at SP+xx
 			//     However, the low word of this is exactly the 16bit ref
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_stack.getSP() + si8a);
 			freeString(ui16a);
 			LOGPF(("free string\t%s = %04X\n", print_sp(si8a), ui16a));
@@ -1562,7 +1566,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x66:
 			// 66 xx
 			// free the list at SP+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_stack.getSP() + si8a);
 			freeList(ui16a);
 			LOGPF(("free list\t%s = %04X\n", print_sp(si8a), ui16a));
@@ -1571,7 +1575,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x67:
 			// 67 xx
 			// free the string list at SP+xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_stack.getSP() + si8a);
 			freeStringList(ui16a);
 			LOGPF(("free slist\t%s = %04x\n", print_sp(si8a), ui16a));
@@ -1582,7 +1586,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x69:
 			// 69 xx
 			// push the string in var BP+xx as 32 bit pointer
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			ui16a = p->_stack.access2(p->_bp + si8a);
 			p->_stack.push4(stringToPtr(ui16a));
 			LOGPF(("str to ptr\t%s\n", print_bp(si8a)));
@@ -1603,8 +1607,8 @@ void UCMachine::execProcess(UCProcess *p) {
 			// yy = type (01 = string, 02 = slist, 03 = list)
 			// copy the (string/slist/list) in BP+xx to the current process,
 			// and add it to the "Free Me" list of the process
-			si8a = cs.readByte(); // index
-			ui8a = cs.readByte(); // type
+			si8a = cs->readByte(); // index
+			ui8a = cs->readByte(); // type
 			LOGPF(("param _pid chg\t%s, type=%u\n", print_bp(si8a), ui8a));
 
 			ui16a = p->_stack.access2(p->_bp + si8a);
@@ -1662,7 +1666,7 @@ void UCMachine::execProcess(UCProcess *p) {
 			// 6E xx
 			// subtract xx from stack pointer
 			// (effect on SP is the same as popping xx bytes)
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			p->_stack.addSP(-si8a);
 			LOGPF(("move sp\t\t%s%02Xh\n", si8a < 0 ? "-" : "", si8a < 0 ? -si8a : si8a));
 			break;
@@ -1670,7 +1674,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x6F:
 			// 6F xx
 			// push 32 pointer address of SP-xx
-			si8a = static_cast<int8>(cs.readByte());
+			si8a = static_cast<int8>(cs->readByte());
 			p->_stack.push4(stackToPtr(p->_pid, static_cast<uint16>(p->_stack.getSP() - si8a)));
 			LOGPF(("push addr\t%s\n", print_sp(-si8a)));
 			break;
@@ -1691,9 +1695,9 @@ void UCMachine::execProcess(UCProcess *p) {
 			// loop something. Stores 'current object' in var xx
 			// yy == num bytes in string
 			// zz == type
-			si16a = cs.readSByte();
-			uint32 scriptsize = cs.readByte();
-			uint32 searchtype = cs.readByte();
+			si16a = cs->readSByte();
+			uint32 scriptsize = cs->readByte();
+			uint32 searchtype = cs->readByte();
 
 			ui16a = p->_stack.pop2();
 			ui16b = p->_stack.pop2();
@@ -1884,7 +1888,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x74:
 			// 74 xx
 			// add xx to the current 'loopscript'
-			ui8a = cs.readByte();
+			ui8a = cs->readByte();
 			p->_stack.push1(ui8a);
 			LOGPF(("loopscr\t\t%02X \"%c\"\n", ui8a, static_cast<char>(ui8a)));
 			break;
@@ -1930,9 +1934,9 @@ void UCMachine::execProcess(UCProcess *p) {
 			// Strings are _not_ duplicated when putting them in the loopvar
 			// Lists _are_ freed afterwards
 
-			si8a = cs.readByte();  // loop variable
-			ui32a = cs.readByte(); // list size
-			si16a = cs.readUint16LE(); // jump offset
+			si8a = cs->readByte();  // loop variable
+			ui32a = cs->readByte(); // list size
+			si16a = cs->readUint16LE(); // jump offset
 
 			ui16a = p->_stack.access2(p->_stack.getSP());     // Loop index
 			ui16b = p->_stack.access2(p->_stack.getSP() + 2); // Loop list
@@ -1966,8 +1970,8 @@ void UCMachine::execProcess(UCProcess *p) {
 				p->_stack.addSP(4);  // Pop list and counter
 
 				// jump out
-				ui16a = cs.pos() + si16a;
-				cs.seek(ui16a);
+				ui16a = cs->pos() + si16a;
+				cs->seek(ui16a);
 			} else {
 				// loop iteration
 				// (not duplicating any strings)
@@ -2013,7 +2017,7 @@ void UCMachine::execProcess(UCProcess *p) {
 		case 0x79:
 			// 79
 			// push address of global (Crusader only)
-			ui16a = cs.readUint16LE(); // global address
+			ui16a = cs->readUint16LE(); // global address
 			ui32a = globalToPtr(ui16a);
 			p->_stack.push4(ui32a);
 			LOGPF(("push global 0x%x (value: %x)\n", ui16a, ui32a));
@@ -2037,13 +2041,15 @@ void UCMachine::execProcess(UCProcess *p) {
 
 		// write back IP (but preserve IP if there was an error)
 		if (!error)
-			p->_ip = static_cast<uint16>(cs.pos());   // TRUNCATES!
+			p->_ip = static_cast<uint16>(cs->pos());   // TRUNCATES!
 
 		// check if we suspended ourselves
 		if ((p->_flags & Process::PROC_SUSPENDED) != 0)
 			cede = true;
 	} // while(!cede && !error && !p->terminated && !p->terminate_deferred)
 
+	delete cs;
+
 	if (error) {
 		perr.Print("Process %d caused an error at %04X:%04X (item %d). Killing process.\n",
 		            p->_pid, p->_classId, p->_ip, p->_itemNum);




More information about the Scummvm-git-logs mailing list