[Scummvm-cvs-logs] SF.net SVN: scummvm:[54435] scummvm/trunk/engines/scumm

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Nov 23 23:25:36 CET 2010


Revision: 54435
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54435&view=rev
Author:   fingolfin
Date:     2010-11-23 22:25:36 +0000 (Tue, 23 Nov 2010)

Log Message:
-----------
SCUMM: Use explicit XOR decoding code in BaseScummFile subclasses

This made it possible to turn some MemoryReadStream pointers into plain
SeekableReadStream pointers.

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/file.cpp
    scummvm/trunk/engines/scumm/file.h
    scummvm/trunk/engines/scumm/file_nes.cpp
    scummvm/trunk/engines/scumm/file_nes.h
    scummvm/trunk/engines/scumm/he/resource_he.cpp
    scummvm/trunk/engines/scumm/he/sound_he.cpp

Modified: scummvm/trunk/engines/scumm/file.cpp
===================================================================
--- scummvm/trunk/engines/scumm/file.cpp	2010-11-23 22:25:10 UTC (rev 54434)
+++ scummvm/trunk/engines/scumm/file.cpp	2010-11-23 22:25:36 UTC (rev 54435)
@@ -27,6 +27,7 @@
 
 #include "scumm/scumm.h"
 
+#include "common/memstream.h"
 #include "common/substream.h"
 
 namespace Scumm {
@@ -35,13 +36,9 @@
 #pragma mark --- ScummFile ---
 #pragma mark -
 
-ScummFile::ScummFile() : _encbyte(0), _subFileStart(0), _subFileLen(0) {
+ScummFile::ScummFile() : _subFileStart(0), _subFileLen(0) {
 }
 
-void ScummFile::setEnc(byte value) {
-	_encbyte = value;
-}
-
 void ScummFile::setSubfileRange(int32 start, int32 len) {
 	// TODO: Add sanity checks
 	const int32 fileSize = File::size();
@@ -248,10 +245,6 @@
 	}
 }
 
-void ScummDiskImage::setEnc(byte enc) {
-	_stream->setEnc(enc);
-}
-
 byte ScummDiskImage::fileReadByte() {
 	byte b = 0;
 	File::read(&b, 1);
@@ -499,4 +492,17 @@
 	return true;
 }
 
+uint32 ScummDiskImage::read(void *dataPtr, uint32 dataSize) {
+	uint32 realLen = _stream->read(dataPtr, dataSize);
+
+	if (_encbyte) {
+		byte *p = (byte *)dataPtr;
+		byte *end = p + realLen;
+		while (p < end)
+			*p++ ^= _encbyte;
+	}
+
+	return realLen;
+}
+
 } // End of namespace Scumm

Modified: scummvm/trunk/engines/scumm/file.h
===================================================================
--- scummvm/trunk/engines/scumm/file.h	2010-11-23 22:25:10 UTC (rev 54434)
+++ scummvm/trunk/engines/scumm/file.h	2010-11-23 22:25:36 UTC (rev 54435)
@@ -27,15 +27,19 @@
 #define SCUMM_FILE_H
 
 #include "common/file.h"
-#include "common/memstream.h"
+#include "common/stream.h"
 
 #include "scumm/detection.h"
 
 namespace Scumm {
 
 class BaseScummFile : public Common::File {
+protected:
+	byte _encbyte;
+
 public:
-	virtual void setEnc(byte value) = 0;
+	BaseScummFile() : _encbyte(0) {}
+	void setEnc(byte value) { _encbyte = value; }
 
 	virtual bool open(const Common::String &filename) = 0;
 	virtual bool openSubFile(const Common::String &filename) = 0;
@@ -53,7 +57,6 @@
 
 class ScummFile : public BaseScummFile {
 private:
-	byte _encbyte;
 	int32	_subFileStart;
 	int32	_subFileLen;
 	bool	_myEos; // Have we read past the end of the subfile?
@@ -63,7 +66,6 @@
 
 public:
 	ScummFile();
-	void setEnc(byte value);
 
 	bool open(const Common::String &filename);
 	bool openSubFile(const Common::String &filename);
@@ -79,7 +81,7 @@
 
 class ScummDiskImage : public BaseScummFile {
 private:
-	Common::MemoryReadStream *_stream;
+	Common::SeekableReadStream *_stream;
 	byte _roomDisks[59], _roomTracks[59], _roomSectors[59];
 
 	byte *_buf;
@@ -109,7 +111,6 @@
 
 public:
 	ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
-	void setEnc(byte value);
 
 	bool open(const Common::String &filename);
 	bool openSubFile(const Common::String &filename);
@@ -119,7 +120,7 @@
 	int32 pos() const { return _stream->pos(); }
 	int32 size() const { return _stream->size(); }
 	bool seek(int32 offs, int whence = SEEK_SET) { return _stream->seek(offs, whence); }
-	uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
+	uint32 read(void *dataPtr, uint32 dataSize);
 };
 
 } // End of namespace Scumm

Modified: scummvm/trunk/engines/scumm/file_nes.cpp
===================================================================
--- scummvm/trunk/engines/scumm/file_nes.cpp	2010-11-23 22:25:10 UTC (rev 54434)
+++ scummvm/trunk/engines/scumm/file_nes.cpp	2010-11-23 22:25:36 UTC (rev 54435)
@@ -27,6 +27,7 @@
 #include "common/debug.h"
 #include "common/endian.h"
 #include "common/md5.h"
+#include "common/memstream.h"
 
 namespace Scumm {
 
@@ -47,10 +48,6 @@
 ScummNESFile::ScummNESFile() : _stream(0), _buf(0), _ROMset(kROMsetNum) {
 }
 
-void ScummNESFile::setEnc(byte enc) {
-	_stream->setEnc(enc);
-}
-
 static const ScummNESFile::Resource res_roomgfx_usa[40] = {
 	{ 0x04001, 0x03C9 }, { 0x043CA, 0x069E }, { 0x04A68, 0x0327 }, { 0x04D8F, 0x053B }, { 0x052CA, 0x06BE },
 	{ 0x05988, 0x0682 }, { 0x0600A, 0x0778 }, { 0x06782, 0x0517 }, { 0x06C99, 0x07FB }, { 0x07494, 0x07BE },
@@ -1450,5 +1447,17 @@
 	}
 }
 
+uint32 ScummNESFile::read(void *dataPtr, uint32 dataSize) {
+	uint32 realLen = _stream->read(dataPtr, dataSize);
 
+	if (_encbyte) {
+		byte *p = (byte *)dataPtr;
+		byte *end = p + realLen;
+		while (p < end)
+			*p++ ^= _encbyte;
+	}
+
+	return realLen;
+}
+
 } // End of namespace Scumm

Modified: scummvm/trunk/engines/scumm/file_nes.h
===================================================================
--- scummvm/trunk/engines/scumm/file_nes.h	2010-11-23 22:25:10 UTC (rev 54434)
+++ scummvm/trunk/engines/scumm/file_nes.h	2010-11-23 22:25:36 UTC (rev 54435)
@@ -26,9 +26,6 @@
 #ifndef SCUMM_FILE_NES_H
 #define SCUMM_FILE_NES_H
 
-#include "common/file.h"
-#include "common/memstream.h"
-
 #include "scumm/file.h"
 
 namespace Scumm {
@@ -71,7 +68,7 @@
 
 
 private:
-	Common::MemoryReadStream *_stream;
+	Common::SeekableReadStream *_stream;
 	ROMset _ROMset;
 	byte *_buf;
 
@@ -84,7 +81,6 @@
 
 public:
 	ScummNESFile();
-	void setEnc(byte value);
 
 	bool open(const Common::String &filename);
 	bool openSubFile(const Common::String &filename);
@@ -94,7 +90,7 @@
 	int32 pos() const { return _stream->pos(); }
 	int32 size() const { return _stream->size(); }
 	bool seek(int32 offs, int whence = SEEK_SET) { return _stream->seek(offs, whence); }
-	uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
+	uint32 read(void *dataPtr, uint32 dataSize);
 };
 
 } // End of namespace Scumm

Modified: scummvm/trunk/engines/scumm/he/resource_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/resource_he.cpp	2010-11-23 22:25:10 UTC (rev 54434)
+++ scummvm/trunk/engines/scumm/he/resource_he.cpp	2010-11-23 22:25:36 UTC (rev 54435)
@@ -34,7 +34,7 @@
 #include "graphics/cursorman.h"
 
 #include "common/archive.h"
-#include "common/stream.h"
+#include "common/memstream.h"
 #include "common/system.h"
 
 namespace Scumm {

Modified: scummvm/trunk/engines/scumm/he/sound_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/sound_he.cpp	2010-11-23 22:25:10 UTC (rev 54434)
+++ scummvm/trunk/engines/scumm/he/sound_he.cpp	2010-11-23 22:25:36 UTC (rev 54435)
@@ -32,6 +32,7 @@
 #include "scumm/util.h"
 
 #include "common/config-manager.h"
+#include "common/memstream.h"
 #include "common/timer.h"
 #include "common/util.h"
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list