[Scummvm-cvs-logs] CVS: scummvm/common stream.h,1.13,1.14

Eugene Sandulenko sev at users.sourceforge.net
Wed Mar 30 14:00:46 CEST 2005


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

Modified Files:
	stream.h 
Log Message:
Support for direct reading from NES ROM:
  o extend MemoryReadStream with XOR facility
  o implement MemoryWriteStream
  o _fileHandle now is a reference to BaseScummFile class and is created on the fly
  o implement ScummNESFile class which is basically extract_mm_nes utility
  o update NES MM md5's due to above changes

NOTE: to run MM NES now you need to remove *.LFL files and (probably) rename
ROM to standard conventional name 'Maniac Mansion (XXX).nes'


Index: stream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/stream.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- stream.h	9 Jan 2005 16:07:53 -0000	1.13
+++ stream.h	30 Mar 2005 21:57:44 -0000	1.14
@@ -223,16 +223,29 @@
 	const byte * const _ptrOrig;
 	const uint32 _bufSize;
 	uint32 _pos;
+	byte _encbyte;
+
 public:
 	MemoryReadStream(const byte *buf, uint32 len) : _ptr(buf), _ptrOrig(buf), _bufSize(len), _pos(0) {}
 
+	void setEnc(byte value) { _encbyte = value; }
+
 	uint32 read(void *ptr, uint32 len) {
 		// Read at most as many bytes as are still available...
 		if (len > _bufSize - _pos)
 			len = _bufSize - _pos;
 		memcpy(ptr, _ptr, len);
+
+		if (_encbyte) {
+			byte *p = (byte *)ptr;
+			byte *end = p + len;
+			while (p < end)
+				*p++ ^= _encbyte;
+		}
+
 		_ptr += len;
 		_pos += len;
+
 		return len;
 	}
 
@@ -243,6 +256,34 @@
 	void seek(int32 offs, int whence = SEEK_SET);
 };
 
+/**
+ * Simple memory based 'stream', which implements the WriteStream interface for
+ * a plain memory block.
+ */
+class MemoryWriteStream : public WriteStream {
+private:
+	byte *_ptr;
+	const byte * const _ptrOrig;
+	const uint32 _bufSize;
+	uint32 _pos;
+public:
+	MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _ptrOrig(buf), _bufSize(len), _pos(0) {}
+
+	uint32 write(const void *ptr, uint32 len) {
+		// Write at most as many bytes as are still available...
+		if (len > _bufSize - _pos)
+			len = _bufSize - _pos;
+		memcpy(_ptr, ptr, len);
+		_ptr += len;
+		_pos += len;
+		return len;
+	}
+
+	bool eof() const { return _pos == _bufSize; }
+	uint32 pos() const { return _pos; }
+	uint32 size() const { return _bufSize; }
+};
+
 }	// End of namespace Common
 
 #endif





More information about the Scummvm-git-logs mailing list