aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWinterGrascph2016-05-03 17:55:04 +0200
committerBendegúz Nagy2016-08-26 23:02:22 +0200
commitcdf377f7a7a43521403c38014bb1406b1ce15721 (patch)
tree7c45683f4025da5b095e259c0398098a0853c356 /engines
parent055e789d0461f881b13cb4fe6e3331b1872eb633 (diff)
downloadscummvm-rg350-cdf377f7a7a43521403c38014bb1406b1ce15721.tar.gz
scummvm-rg350-cdf377f7a7a43521403c38014bb1406b1ce15721.tar.bz2
scummvm-rg350-cdf377f7a7a43521403c38014bb1406b1ce15721.zip
DM: Add support for Dungeon.dat uncompression
Add DungeonMan class with support for loading and uncompressing Dungeon.dat file into memory
Diffstat (limited to 'engines')
-rw-r--r--engines/dm/dm.cpp8
-rw-r--r--engines/dm/dm.h2
-rw-r--r--engines/dm/dungeonman.cpp62
-rw-r--r--engines/dm/dungeonman.h22
-rw-r--r--engines/dm/gfx.h2
5 files changed, 94 insertions, 2 deletions
diff --git a/engines/dm/dm.cpp b/engines/dm/dm.cpp
index d6fc1f3d7d..61e68dfaa7 100644
--- a/engines/dm/dm.cpp
+++ b/engines/dm/dm.cpp
@@ -12,6 +12,7 @@
#include "dm/dm.h"
#include "dm/gfx.h"
+#include "dm/dungeonman.h"
namespace DM {
@@ -39,17 +40,23 @@ DMEngine::~DMEngine() {
delete _rnd;
delete _console;
delete _displayMan;
+ delete _dungeonMan;
// clear debug channels
DebugMan.clearAllDebugChannels();
}
+
Common::Error DMEngine::run() {
initGraphics(320, 200, false);
_console = new Console(this);
_displayMan = new DisplayMan(this);
+ _dungeonMan = new DungeonMan(this);
_displayMan->setUpScreens(320, 200);
_displayMan->loadGraphics();
+ _dungeonMan->loadDungeonFile();
+
+
byte *palette = new byte[256 * 3];
@@ -79,7 +86,6 @@ Common::Error DMEngine::run() {
_displayMan->updateScreen();
}
-
return Common::kNoError;
}
diff --git a/engines/dm/dm.h b/engines/dm/dm.h
index 6820640d18..705939cc63 100644
--- a/engines/dm/dm.h
+++ b/engines/dm/dm.h
@@ -10,6 +10,7 @@ namespace DM {
class Console;
class DisplayMan;
+class DungeonMan;
enum {
// engine debug channels
@@ -28,6 +29,7 @@ private:
Console *_console;
Common::RandomSource *_rnd;
DisplayMan *_displayMan;
+ DungeonMan *_dungeonMan;
};
class Console : public GUI::Debugger {
diff --git a/engines/dm/dungeonman.cpp b/engines/dm/dungeonman.cpp
new file mode 100644
index 0000000000..6ddf966eb9
--- /dev/null
+++ b/engines/dm/dungeonman.cpp
@@ -0,0 +1,62 @@
+#include "dungeonman.h"
+#include "common/file.h"
+
+
+namespace DM {
+DungeonMan::DungeonMan(DMEngine *dmEngine) : _vm(dmEngine), _dungeonDataSize(0), _dungeonData(NULL) {}
+DungeonMan::~DungeonMan() { delete[] _dungeonData; }
+void DungeonMan::loadDungeonFile() {
+ Common::File f;
+ f.open("Dungeon.dat");
+ if (f.readUint16BE() == 0x8104) {
+ _dungeonDataSize = f.readUint32BE();
+ _dungeonData = new byte[_dungeonDataSize];
+ f.readUint16BE();
+ byte common[4];
+ for (uint16 i = 0; i < 4; ++i)
+ common[i] = f.readByte();
+ byte lessCommon[16];
+ for (uint16 i = 0; i < 16; ++i)
+ lessCommon[i] = f.readByte();
+
+ // start unpacking
+ uint32 uncompIndex = 0;
+ uint8 bitsUsedInWord = 0;
+ uint16 wordBuff = f.readUint16BE();
+ uint8 bitsLeftInByte = 8;
+ byte byteBuff = f.readByte();
+ while (uncompIndex < _dungeonDataSize) {
+ while (bitsUsedInWord != 0) {
+ uint8 shiftVal;
+ if (f.eos()) {
+ shiftVal = bitsUsedInWord;
+ wordBuff <<= shiftVal;
+ } else {
+ shiftVal = MIN(bitsLeftInByte, bitsUsedInWord);
+ wordBuff <<= shiftVal;
+ wordBuff |= (byteBuff >> (8 - shiftVal));
+ byteBuff <<= shiftVal;
+ bitsLeftInByte -= shiftVal;
+ if (!bitsLeftInByte) {
+ byteBuff = f.readByte();
+ bitsLeftInByte = 8;
+ }
+ }
+ bitsUsedInWord -= shiftVal;
+ }
+ if (((wordBuff >> 15) & 1) == 0) {
+ _dungeonData[uncompIndex++] = common[(wordBuff >> 13) & 3];
+ bitsUsedInWord += 3;
+ } else if (((wordBuff >> 14) & 3) == 2) {
+ _dungeonData[uncompIndex++] = lessCommon[(wordBuff >> 10) & 15];
+ bitsUsedInWord += 6;
+ } else if (((wordBuff >> 14) & 3) == 3) {
+ _dungeonData[uncompIndex++] = (wordBuff >> 6) & 255;
+ bitsUsedInWord += 10;
+ }
+ }
+ }
+ f.close();
+}
+
+} \ No newline at end of file
diff --git a/engines/dm/dungeonman.h b/engines/dm/dungeonman.h
new file mode 100644
index 0000000000..b820bb2b58
--- /dev/null
+++ b/engines/dm/dungeonman.h
@@ -0,0 +1,22 @@
+#ifndef DUNGEONMAN_H
+#define DUNGEONMAN_H
+
+#include "dm.h"
+
+namespace DM {
+
+class DungeonMan {
+ DMEngine *_vm;
+ uint32 _dungeonDataSize;
+ byte *_dungeonData;
+ DungeonMan(const DungeonMan &other); // no implementation on purpose
+ void operator=(const DungeonMan &rhs); // no implementation on purpose
+public:
+ DungeonMan(DMEngine *dmEngine);
+ ~DungeonMan();
+ void loadDungeonFile();
+};
+
+}
+
+#endif
diff --git a/engines/dm/gfx.h b/engines/dm/gfx.h
index 91cf7e1ca2..98d035be2c 100644
--- a/engines/dm/gfx.h
+++ b/engines/dm/gfx.h
@@ -15,7 +15,7 @@ class DisplayMan {
uint16 _itemCount;
uint32 *_indexBytePos;
uint8 *_compressedData;
- DisplayMan(const DMEngine &dmEngine); // no implementation on purpose
+ DisplayMan(const DisplayMan &other); // no implementation on purpose
void operator=(const DisplayMan &rhs); // no implementation on purpose
public:
DisplayMan(DMEngine *dmEngine);