diff options
Diffstat (limited to 'engines/dm')
-rw-r--r-- | engines/dm/detection.cpp | 4 | ||||
-rw-r--r-- | engines/dm/dm.cpp | 49 | ||||
-rw-r--r-- | engines/dm/dm.h | 3 | ||||
-rw-r--r-- | engines/dm/gfx.cpp | 126 | ||||
-rw-r--r-- | engines/dm/gfx.h | 38 | ||||
-rw-r--r-- | engines/dm/module.mk | 3 |
6 files changed, 207 insertions, 16 deletions
diff --git a/engines/dm/detection.cpp b/engines/dm/detection.cpp index 443d2dba78..855d1284b9 100644 --- a/engines/dm/detection.cpp +++ b/engines/dm/detection.cpp @@ -15,8 +15,8 @@ static const ADGameDescription gameDescriptions[] = { { "dm", "Amiga 2.0v English", { - {"graphics.dat", 0, "6A2F135B53C2220F0251FA103E2A6E7E", 411960}, - {"Dungeon.dat", 0, "30028FB6A301ECB20127EF0B3AF32B05", 25006}, + {"graphics.dat", 0, "c2205f6225bde728417de29394f97d55", 411960}, + {"Dungeon.dat", 0, "43a213da8eda413541dd12f90ce202f6", 25006}, AD_LISTEND }, Common::EN_GRB, Common::kPlatformAmiga, ADGF_NO_FLAGS, GUIO1(GUIO_NONE) diff --git a/engines/dm/dm.cpp b/engines/dm/dm.cpp index ba6c326db8..d6fc1f3d7d 100644 --- a/engines/dm/dm.cpp +++ b/engines/dm/dm.cpp @@ -1,16 +1,17 @@ #include "common/scummsys.h" +#include "common/system.h" -#include "common/config-manager.h" #include "common/debug.h" #include "common/debug-channels.h" #include "common/error.h" -#include "gui/EventRecorder.h" -#include "common/file.h" -#include "common/fs.h" #include "engines/util.h" +#include "engines/engine.h" +#include "graphics/palette.h" +#include "common/file.h" #include "dm/dm.h" +#include "dm/gfx.h" namespace DM { @@ -36,26 +37,48 @@ DMEngine::~DMEngine() { // dispose of resources delete _rnd; + delete _console; + delete _displayMan; // clear debug channels DebugMan.clearAllDebugChannels(); } Common::Error DMEngine::run() { - // Init graphics initGraphics(320, 200, false); - - // Create debug console (it requirese GFX to be inited) _console = new Console(this); + _displayMan = new DisplayMan(this); + _displayMan->setUpScreens(320, 200); + _displayMan->loadGraphics(); + + + byte *palette = new byte[256 * 3]; + for (int i = 0; i < 16; ++i) + palette[i * 3] = palette[i * 3 + 1] = palette[i * 3 + 2] = i * 16; + + _displayMan->setPalette(palette, 16); + + byte *buffer = new byte[320 * 200]; + for (int i = 0; i < 320 * 100; ++i) + buffer[i] = 4; + for (int i = 320 * 100; i < 320 * 200; ++i) + buffer[i] = 6; + + _system->copyRectToScreen(buffer, 320, 0, 0, 320, 200); + _system->updateScreen(); + + + uint16 width = _displayMan->getImageWidth(75); + uint16 height = _displayMan->getImageHeight(75); + byte *cleanByteImg0Data = new byte[width * height]; + _displayMan->loadIntoBitmap(75, cleanByteImg0Data); + _displayMan->blitToScreen(cleanByteImg0Data, width, height, 30, 30); - // Additional setup - debug("DMEngine::init"); - // Run main loop - debug("DMEngine:: start main loop"); + while (true) { + _displayMan->updateScreen(); + } - while (true) - debug("Run!"); return Common::kNoError; } diff --git a/engines/dm/dm.h b/engines/dm/dm.h index 79deb299da..6820640d18 100644 --- a/engines/dm/dm.h +++ b/engines/dm/dm.h @@ -9,6 +9,7 @@ namespace DM { class Console; +class DisplayMan; enum { // engine debug channels @@ -21,10 +22,12 @@ public: ~DMEngine(); virtual Common::Error run(); + Common::Error go(); private: Console *_console; Common::RandomSource *_rnd; + DisplayMan *_displayMan; }; class Console : public GUI::Debugger { diff --git a/engines/dm/gfx.cpp b/engines/dm/gfx.cpp new file mode 100644 index 0000000000..53abbbfc76 --- /dev/null +++ b/engines/dm/gfx.cpp @@ -0,0 +1,126 @@ +#include "gfx.h" +#include "engines/util.h" +#include "common/system.h" +#include "common/file.h" +#include "graphics/palette.h" +#include "common/endian.h" + +using namespace DM; + +DisplayMan::DisplayMan(DMEngine *dmEngine) : + _vm(dmEngine), _currPalette(NULL), _screenWidth(0), _screenHeight(0), + _vgaBuffer(0), _itemCount(0), _indexBytePos(NULL), _compressedData(NULL) {} + +DisplayMan::~DisplayMan() { + delete[] _compressedData; + delete[] _indexBytePos; + delete[] _currPalette; +} + +void DisplayMan::setUpScreens(uint16 width, uint16 height) { + _currPalette = new byte[256 * 2]; + _screenWidth = width; + _screenHeight = height; + _vgaBuffer = new byte[_screenWidth * _screenHeight]; + memset(_vgaBuffer, 0, width * height); +} + +void DisplayMan::loadGraphics() { + Common::File f; + f.open("graphics.dat"); + + _itemCount = f.readUint16BE(); + _indexBytePos = new uint32[_itemCount + 1]; + _indexBytePos[0] = 0; + for (uint16 i = 1; i < _itemCount + 1; ++i) + _indexBytePos[i] = f.readUint16BE() + _indexBytePos[i - 1]; + + _compressedData = new uint8[_indexBytePos[_itemCount]]; + + f.seek(2 + _itemCount * 4); + for (uint32 i = 0; i < _indexBytePos[_itemCount]; ++i) + _compressedData[i] = f.readByte(); + + f.close(); +} + +void DisplayMan::setPalette(byte *buff, uint16 colorCount) { + memcpy(_currPalette, buff, sizeof(byte) * colorCount * 3); + _vm->_system->getPaletteManager()->setPalette(buff, 0, colorCount); +} + +#define TOBE2(byte1, byte2) ((((uint16)(byte1)) << 8) | (uint16)(byte2)) + +void DisplayMan::loadIntoBitmap(uint16 index, byte *destBitmap) { + uint8 *data = _compressedData + _indexBytePos[index]; + uint16 width = TOBE2(data[0], data[1]); + uint16 height = TOBE2(data[2], data[3]); + uint16 nextByteIndex = 4; + for (uint16 k = 0; k < width * height;) { + uint8 nextByte = data[nextByteIndex++]; + uint8 nibble1 = (nextByte & 0xF0) >> 4; + uint8 nibble2 = (nextByte & 0x0F); + if (nibble1 <= 7) { + for (int j = 0; j < nibble1 + 1; ++j) + destBitmap[k++] = nibble2; + } else if (nibble1 == 0x8) { + uint8 byte1 = data[nextByteIndex++]; + for (int j = 0; j < byte1 + 1; ++j) + destBitmap[k++] = nibble2; + } else if (nibble1 == 0xC) { + uint16 word1 = TOBE2(data[nextByteIndex], data[nextByteIndex + 1]); + nextByteIndex += 2; + for (int j = 0; j < word1 + 1; ++j) + destBitmap[k++] = nibble2; + } else if (nibble1 == 0xB) { + uint8 byte1 = data[nextByteIndex++]; + for (int j = 0; j < byte1 + 1; ++j, ++k) + destBitmap[k] = destBitmap[k - width]; + destBitmap[k++] = nibble2; + } else if (nibble1 == 0xF) { + uint16 word1 = TOBE2(data[nextByteIndex], data[nextByteIndex + 1]); + nextByteIndex += 2; + for (int j = 0; j < word1 + 1; ++j, ++k) + destBitmap[k] = destBitmap[k - width]; + destBitmap[k++] = nibble2; + } else if (nibble1 == 9) { + uint8 byte1 = data[nextByteIndex++]; + if (byte1 % 2) + byte1++; + else + destBitmap[k++] = nibble2; + + for (int j = 0; j < byte1 / 2; ++j) { + uint8 byte2 = data[nextByteIndex++]; + destBitmap[k++] = byte2 & 0x0F; + destBitmap[k++] = (byte2 & 0xF0) >> 4; + } + } + } +} + +void DisplayMan::blitToScreen(byte *srcBitmap, uint16 srcWidth, uint16 srcHeight, uint16 destX, uint16 destY) { + for (uint16 y = 0; y < srcHeight; ++y) + memcpy(getCurrentVgaBuffer() + ((y + destY) * _screenWidth + destX), srcBitmap + y * srcWidth, srcWidth * sizeof(byte)); + +} + +void DisplayMan::updateScreen() { + _vm->_system->copyRectToScreen(_vgaBuffer, _screenWidth, 0, 0, _screenWidth, _screenHeight); + _vm->_system->updateScreen(); +} + +byte *DisplayMan::getCurrentVgaBuffer() { + return _vgaBuffer; +} + +uint16 DisplayMan::getImageWidth(uint16 index) { + uint8 *data = _compressedData + _indexBytePos[index]; + return TOBE2(data[0], data[1]); +} + +uint16 DisplayMan::getImageHeight(uint16 index) { + uint8 *data = _compressedData + _indexBytePos[index]; + return TOBE2(data[2], data[3]); +} + diff --git a/engines/dm/gfx.h b/engines/dm/gfx.h new file mode 100644 index 0000000000..91cf7e1ca2 --- /dev/null +++ b/engines/dm/gfx.h @@ -0,0 +1,38 @@ +#ifndef GFX_H +#define GFX_H + +#include "common/scummsys.h" +#include "dm/dm.h" + +namespace DM { + +class DisplayMan { + DMEngine *_vm; + byte *_currPalette; + uint16 _screenWidth; + uint16 _screenHeight; + byte *_vgaBuffer; + uint16 _itemCount; + uint32 *_indexBytePos; + uint8 *_compressedData; + DisplayMan(const DMEngine &dmEngine); // no implementation on purpose + void operator=(const DisplayMan &rhs); // no implementation on purpose +public: + DisplayMan(DMEngine *dmEngine); + ~DisplayMan(); + void setUpScreens(uint16 width, uint16 height); + void loadGraphics(); + void setPalette(byte *buff, uint16 colorCount); + void loadIntoBitmap(uint16 index, byte *destBitmap); + uint16 getImageWidth(uint16 index); + uint16 getImageHeight(uint16 index); + void blitToScreen(byte *srcBitmap, uint16 srcWidth, uint16 srcHeight, uint16 destX, uint16 destY); + byte *getCurrentVgaBuffer(); + void updateScreen(); +}; + +} + + + +#endif diff --git a/engines/dm/module.mk b/engines/dm/module.mk index 808b4e5c52..3fad4ee9f4 100644 --- a/engines/dm/module.mk +++ b/engines/dm/module.mk @@ -2,7 +2,8 @@ MODULE := engines/dm MODULE_OBJS := \ detection.o \ - dm.o + dm.o \ + gfx.o MODULE_DIRS += \ engines/dm |