aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm/smush
diff options
context:
space:
mode:
authorMax Horn2008-09-13 20:04:19 +0000
committerMax Horn2008-09-13 20:04:19 +0000
commit71a204d63cbbea985099d1909423e9e4b0a12e43 (patch)
treecea3d003c07c92f13a53feb6c77f9323f208f7dc /engines/scumm/smush
parenteefefa0afa77bb5547744a00bf95c04ac7df0b41 (diff)
downloadscummvm-rg350-71a204d63cbbea985099d1909423e9e4b0a12e43.tar.gz
scummvm-rg350-71a204d63cbbea985099d1909423e9e4b0a12e43.tar.bz2
scummvm-rg350-71a204d63cbbea985099d1909423e9e4b0a12e43.zip
SCUMM: Merged class BaseChunk & Chunk; got rid of MemoryChunk
svn-id: r34516
Diffstat (limited to 'engines/scumm/smush')
-rw-r--r--engines/scumm/smush/channel.h2
-rw-r--r--engines/scumm/smush/chunk.cpp53
-rw-r--r--engines/scumm/smush/chunk.h35
-rw-r--r--engines/scumm/smush/imuse_channel.cpp41
-rw-r--r--engines/scumm/smush/saud_channel.cpp16
5 files changed, 47 insertions, 100 deletions
diff --git a/engines/scumm/smush/channel.h b/engines/scumm/smush/channel.h
index 52fec22e0e..9abe9abf57 100644
--- a/engines/scumm/smush/channel.h
+++ b/engines/scumm/smush/channel.h
@@ -105,7 +105,7 @@ private:
protected:
void decode();
- bool handleMap(Chunk &c);
+ bool handleMap(byte *data);
bool handleSubTags(int32 &offset);
public:
diff --git a/engines/scumm/smush/chunk.cpp b/engines/scumm/smush/chunk.cpp
index 855f0a3985..2a797d459b 100644
--- a/engines/scumm/smush/chunk.cpp
+++ b/engines/scumm/smush/chunk.cpp
@@ -34,30 +34,7 @@
namespace Scumm {
-BaseChunk::BaseChunk() :
- _type(0),
- _size(0),
- _curPos(0),
- _name("") {
-}
-
-bool BaseChunk::eos() const {
- return _curPos >= _size;
-}
-
-int32 BaseChunk::pos() const {
- return _curPos;
-}
-
-Chunk::type BaseChunk::getType() const {
- return _type;
-}
-
-int32 BaseChunk::size() const {
- return _size;
-}
-
-bool BaseChunk::seek(int32 delta, int dir) {
+bool Chunk::seek(int32 delta, int dir) {
switch (dir) {
case SEEK_CUR:
_curPos += delta;
@@ -139,32 +116,4 @@ uint32 FileChunk::read(void *buffer, uint32 dataSize) {
return dataSize;
}
-MemoryChunk::MemoryChunk(byte *data) {
- if (data == 0)
- error("Chunk() called with NULL pointer");
-
- _type = (Chunk::type)READ_BE_UINT32(data);
- _size = READ_BE_UINT32(data + 4);
- _data = data + sizeof(Chunk::type) + sizeof(uint32);
- _curPos = 0;
-}
-
-Chunk *MemoryChunk::subBlock() {
- MemoryChunk *ptr = new MemoryChunk(_data + _curPos);
- skip(sizeof(Chunk::type) + sizeof(uint32) + ptr->size());
- return ptr;
-}
-
-void MemoryChunk::reseek() {
-}
-
-uint32 MemoryChunk::read(void *buffer, uint32 dataSize) {
- if (dataSize <= 0 || (_curPos + dataSize) > _size)
- error("invalid buffer read request");
-
- memcpy(buffer, _data + _curPos, dataSize);
- _curPos += dataSize;
- return dataSize;
-}
-
} // End of namespace Scumm
diff --git a/engines/scumm/smush/chunk.h b/engines/scumm/smush/chunk.h
index 08d7037d1c..76ea56c12c 100644
--- a/engines/scumm/smush/chunk.h
+++ b/engines/scumm/smush/chunk.h
@@ -34,34 +34,32 @@ namespace Scumm {
class BaseScummFile;
+// Common functionality for concrete chunks (FileChunk, MemoryChunk)
class Chunk : public Common::SeekableReadStream {
public:
typedef uint32 type;
- virtual type getType() const = 0;
- virtual Chunk *subBlock() = 0;
- virtual void reseek() = 0;
-};
-
-// Common functionality for concrete chunks (FileChunk, MemoryChunk)
-class BaseChunk : public Chunk {
protected:
Chunk::type _type;
uint32 _size;
uint32 _curPos;
Common::String _name;
- BaseChunk();
+ Chunk() : _type(0), _size(0), _curPos(0) {}
+
public:
- Chunk::type getType() const;
- int32 size() const;
- bool eos() const;
- int32 pos() const;
+ Chunk::type getType() const { return _type; }
+ int32 size() const { return _size; }
+ bool eos() const { return _curPos >= _size; }
+ int32 pos() const { return _curPos; }
bool seek(int32 delta, int dir);
+
+ virtual Chunk *subBlock() = 0;
+ virtual void reseek() = 0;
};
-class FileChunk : public BaseChunk {
+class FileChunk : public Chunk {
private:
BaseScummFile *_data;
bool _deleteData;
@@ -76,17 +74,6 @@ public:
uint32 read(void *buffer, uint32 size);
};
-class MemoryChunk : public BaseChunk {
-private:
- byte *_data;
-
-public:
- MemoryChunk(byte *data);
- Chunk *subBlock();
- void reseek();
- uint32 read(void *buffer, uint32 size);
-};
-
} // End of namespace Scumm
#endif
diff --git a/engines/scumm/smush/imuse_channel.cpp b/engines/scumm/smush/imuse_channel.cpp
index 822f32a896..a02e0654c2 100644
--- a/engines/scumm/smush/imuse_channel.cpp
+++ b/engines/scumm/smush/imuse_channel.cpp
@@ -104,35 +104,45 @@ bool ImuseChannel::appendData(Chunk &b, int32 size) {
return true;
}
-bool ImuseChannel::handleMap(Chunk &map) {
- while (!map.eos()) {
- Chunk *sub = map.subBlock();
- switch (sub->getType()) {
+bool ImuseChannel::handleMap(byte *data) {
+ // Read the chunk size & skip over the chunk header
+ int32 size = READ_BE_UINT32(data + 4);
+ data += 8;
+
+ while (size > 0) {
+ uint32 subType = READ_BE_UINT32(data);
+ int32 subSize = READ_BE_UINT32(data + 4);
+ data += 8;
+ size -= 8;
+
+ switch (subType) {
case MKID_BE('FRMT'):
- if (sub->size() != 20)
+ if (subSize != 20)
error("invalid size for FRMT Chunk");
- /*uint32 imuse_start =*/ sub->readUint32BE();
- sub->skip(4);
- _bitsize = sub->readUint32BE();
- _rate = sub->readUint32BE();
- _channels = sub->readUint32BE();
+ //uint32 imuse_start = READ_BE_UINT32(data);
+ //uint32 unk = READ_BE_UINT32(data+4);
+ _bitsize = READ_BE_UINT32(data+8);
+ _rate = READ_BE_UINT32(data+12);
+ _channels = READ_BE_UINT32(data+16);
assert(_channels == 1 || _channels == 2);
break;
case MKID_BE('TEXT'):
// Ignore this
break;
case MKID_BE('REGN'):
- if (sub->size() != 8)
+ if (subSize != 8)
error("invalid size for REGN Chunk");
break;
case MKID_BE('STOP'):
- if (sub->size() != 4)
+ if (subSize != 4)
error("invalid size for STOP Chunk");
break;
default:
- error("Unknown iMUS subChunk found : %s, %d", tag2str(sub->getType()), sub->size());
+ error("Unknown iMUS subChunk found : %s, %d", tag2str(subType), subSize);
}
- delete sub;
+
+ data += subSize;
+ size -= subSize;
}
return true;
}
@@ -194,8 +204,7 @@ bool ImuseChannel::handleSubTags(int32 &offset) {
case MKID_BE('MAP '):
_inData = false;
if (available_size >= (size + 8)) {
- MemoryChunk c((byte *)_tbuffer + offset);
- handleMap(c);
+ handleMap((byte *)_tbuffer + offset);
}
break;
case MKID_BE('DATA'):
diff --git a/engines/scumm/smush/saud_channel.cpp b/engines/scumm/smush/saud_channel.cpp
index 2fe34efe29..c01804c1b5 100644
--- a/engines/scumm/smush/saud_channel.cpp
+++ b/engines/scumm/smush/saud_channel.cpp
@@ -53,9 +53,9 @@ bool SaudChannel::handleSubTags(int32 &offset) {
case MKID_BE('STRK'):
_inData = false;
if (available_size >= (size + 8)) {
- MemoryChunk c((byte *)_tbuffer + offset);
- if (c.size() != 14 && c.size() != 10) {
- error("STRK has an invalid size : %d", c.size());
+ int32 subSize = READ_BE_UINT32((byte *)_tbuffer + offset + 4);
+ if (subSize != 14 && subSize != 10) {
+ error("STRK has an invalid size : %d", subSize);
}
} else
return false;
@@ -63,7 +63,9 @@ bool SaudChannel::handleSubTags(int32 &offset) {
case MKID_BE('SMRK'):
_inData = false;
if (available_size >= (size + 8)) {
- MemoryChunk c((byte *)_tbuffer + offset);
+ int32 subSize = READ_BE_UINT32((byte *)_tbuffer + offset + 4);
+ if (subSize != 0)
+ error("SMRK has an invalid size : %d", subSize);
_markReached = true;
} else
return false;
@@ -71,9 +73,9 @@ bool SaudChannel::handleSubTags(int32 &offset) {
case MKID_BE('SHDR'):
_inData = false;
if (available_size >= (size + 8)) {
- MemoryChunk c((byte *)_tbuffer + offset);
- if (c.size() != 4)
- error("SHDR has an invalid size : %d", c.size());
+ int32 subSize = READ_BE_UINT32((byte *)_tbuffer + offset + 4);
+ if (subSize != 4)
+ error("SHDR has an invalid size : %d", subSize);
} else
return false;
break;