From 7e07dd5ec720905e09c5aac37a80941c6053e132 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 20 Apr 2008 15:36:40 +0000 Subject: Changed spaces to tabs. svn-id: r31610 --- engines/made/database.cpp | 122 ++++++++-------- engines/made/database.h | 34 ++--- engines/made/graphics.cpp | 226 +++++++++++++++--------------- engines/made/made.cpp | 32 ++--- engines/made/pmvplayer.cpp | 134 +++++++++--------- engines/made/pmvplayer.h | 30 ++-- engines/made/resource.cpp | 192 ++++++++++++------------- engines/made/resource.h | 168 +++++++++++----------- engines/made/screen.cpp | 326 +++++++++++++++++++++---------------------- engines/made/screen.h | 82 +++++------ engines/made/script.cpp | 160 ++++++++++----------- engines/made/script.h | 36 ++--- engines/made/scriptfuncs.cpp | 90 ++++++------ engines/made/scriptfuncs.h | 14 +- engines/made/sound.cpp | 62 ++++---- 15 files changed, 854 insertions(+), 854 deletions(-) diff --git a/engines/made/database.cpp b/engines/made/database.cpp index 1c2ddf0a8a..fc20087039 100644 --- a/engines/made/database.cpp +++ b/engines/made/database.cpp @@ -42,12 +42,12 @@ Object::Object() { Object::~Object() { if (_freeData && _objData) - delete[] _objData; + delete[] _objData; } void Object::load(Common::SeekableReadStream &source) { - _freeData = true; + _freeData = true; source.readUint16LE(); // skip flags uint16 type = source.readUint16LE(); @@ -72,9 +72,9 @@ void Object::load(Common::SeekableReadStream &source) { _objSize = (count1 + count2) * 2; } - source.seek(-6, SEEK_CUR); + source.seek(-6, SEEK_CUR); - _objSize += 6; + _objSize += 6; _objData = new byte[_objSize]; source.read(_objData, _objSize); @@ -88,7 +88,7 @@ void Object::load(Common::SeekableReadStream &source) { void Object::load(byte *source) { _objData = source; - _freeData = false; + _freeData = false; if (getClass() < 0x7FFE) { _objSize = (getCount1() + getCount2()) * 2; @@ -131,9 +131,9 @@ byte *Object::getData() { const char *Object::getString() { if (getClass() == 0x7FFF) - return (const char*)getData(); + return (const char*)getData(); else - return NULL; + return NULL; } bool Object::isObject() { @@ -146,16 +146,16 @@ bool Object::isVector() { int16 Object::getVectorSize() { if (getClass() == 0x7FFF || getClass() == 0x7FFE) { - return getSize(); + return getSize(); } else if (getClass() < 0x7FFE) { - return getCount1() + getCount2(); + return getCount1() + getCount2(); } else { return 0; // FIXME } } int16 Object::getVectorItem(int16 index) { - if (getClass() == 0x7FFF) { + if (getClass() == 0x7FFF) { byte *vector = (byte*)getData(); return vector[index]; } else if (getClass() == 0x7FFE) { @@ -170,7 +170,7 @@ int16 Object::getVectorItem(int16 index) { } void Object::setVectorItem(int16 index, int16 value) { - if (getClass() == 0x7FFF) { + if (getClass() == 0x7FFF) { byte *vector = (byte*)getData(); vector[index] = value; } else if (getClass() <= 0x7FFE) { @@ -192,7 +192,7 @@ GameDatabase::GameDatabase() { GameDatabase::~GameDatabase() { if (_gameState) - delete[] _gameState; + delete[] _gameState; } void GameDatabase::open(const char *filename) { @@ -213,30 +213,30 @@ void GameDatabase::open(const char *filename) { debug(2, "objectIndexOffs = %08X; objectCount = %d; gameStateOffs = %08X; gameStateSize = %d; objectsOffs = %08X; objectsSize = %d\n", objectIndexOffs, objectCount, gameStateOffs, _gameStateSize, objectsOffs, objectsSize); - _gameState = new byte[_gameStateSize]; + _gameState = new byte[_gameStateSize]; _fd.seek(gameStateOffs); _fd.read(_gameState, _gameStateSize); Common::Array objectOffsets; _fd.seek(objectIndexOffs); for (uint32 i = 0; i < objectCount; i++) - objectOffsets.push_back(_fd.readUint32LE()); + objectOffsets.push_back(_fd.readUint32LE()); for (uint32 i = 0; i < objectCount; i++) { - Object *obj = new Object(); - // The LSB indicates if it's a constant or variable object - - debug(2, "obj(%04X) ofs = %08X\n", i, objectOffsets[i]); - + Object *obj = new Object(); + // The LSB indicates if it's a constant or variable object + + debug(2, "obj(%04X) ofs = %08X\n", i, objectOffsets[i]); + if (objectOffsets[i] & 1) { - debug(2, "-> const %08X\n", objectsOffs + objectOffsets[i] - 1); - _fd.seek(objectsOffs + objectOffsets[i] - 1); - obj->load(_fd); - } else { - debug(2, "-> var\n"); - obj->load(_gameState + objectOffsets[i]); + debug(2, "-> const %08X\n", objectsOffs + objectOffsets[i] - 1); + _fd.seek(objectsOffs + objectOffsets[i] - 1); + obj->load(_fd); + } else { + debug(2, "-> var\n"); + obj->load(_gameState + objectOffsets[i]); } - _objects.push_back(obj); + _objects.push_back(obj); } } @@ -265,15 +265,15 @@ int16 *GameDatabase::getObjectPropertyPtr(int16 objectIndex, int16 propertyId, i // First see if the property exists in the given object while (count2-- > 0) { - if ((*prop & 0x3FFF) == propertyId) { - if (*prop & 0x4000) { + if ((*prop & 0x3FFF) == propertyId) { + if (*prop & 0x4000) { debug(2, "! L1.1\n"); - propertyFlag = 1; - return (int16*)_gameState + *propPtr1; + propertyFlag = 1; + return (int16*)_gameState + *propPtr1; } else { debug(2, "! L1.2\n"); - propertyFlag = obj->getFlags() & 1; - return propPtr1; + propertyFlag = obj->getFlags() & 1; + return propPtr1; } } prop++; @@ -283,18 +283,18 @@ int16 *GameDatabase::getObjectPropertyPtr(int16 objectIndex, int16 propertyId, i // Now check in the object hierarchy of the given object int16 parentObjectIndex = obj->getClass(); if (parentObjectIndex == 0) { - debug(2, "! NULL(np)\n"); - return NULL; + debug(2, "! NULL(np)\n"); + return NULL; } - + while (parentObjectIndex != 0) { - debug(2, "parentObjectIndex = %04X\n", parentObjectIndex); + debug(2, "parentObjectIndex = %04X\n", parentObjectIndex); //dumpObject(parentObjectIndex); - obj = getObject(parentObjectIndex); - + obj = getObject(parentObjectIndex); + prop = (int16*)obj->getData(); count1 = obj->getCount1(); count2 = obj->getCount2(); @@ -303,30 +303,30 @@ int16 *GameDatabase::getObjectPropertyPtr(int16 objectIndex, int16 propertyId, i int16 *propertyPtr = prop + count1; while (count2-- > 0) { - if (!(*prop & 0x8000)) { - if ((*prop & 0x3FFF) == propertyId) { - if (*prop & 0x4000) { + if (!(*prop & 0x8000)) { + if ((*prop & 0x3FFF) == propertyId) { + if (*prop & 0x4000) { debug(2, "! L2.1\n"); - propertyFlag = 1; - return (int16*)_gameState + *propPtr1; + propertyFlag = 1; + return (int16*)_gameState + *propPtr1; } else { debug(2, "! L2.2\n"); - propertyFlag = obj->getFlags() & 1; - return propPtr1; + propertyFlag = obj->getFlags() & 1; + return propPtr1; } } else { - propPtr1++; + propPtr1++; } } else { - if ((*prop & 0x3FFF) == propertyId) { - if (*prop & 0x4000) { - debug(2, "! L3.1\n"); - propertyFlag = 1; - return (int16*)_gameState + *propertyPtr; + if ((*prop & 0x3FFF) == propertyId) { + if (*prop & 0x4000) { + debug(2, "! L3.1\n"); + propertyFlag = 1; + return (int16*)_gameState + *propertyPtr; } else { - debug(2, "! L3.2\n"); - propertyFlag = obj->getFlags() & 1; - return propertyPtr; + debug(2, "! L3.2\n"); + propertyFlag = obj->getFlags() & 1; + return propertyPtr; } } } @@ -338,7 +338,7 @@ int16 *GameDatabase::getObjectPropertyPtr(int16 objectIndex, int16 propertyId, i } - debug(2, "! NULL(nf)\n"); + debug(2, "! NULL(nf)\n"); return NULL; fflush(stdout); @@ -348,7 +348,7 @@ int16 *GameDatabase::getObjectPropertyPtr(int16 objectIndex, int16 propertyId, i int16 GameDatabase::getObjectProperty(int16 objectIndex, int16 propertyId) { if (objectIndex == 0) - return 0; + return 0; int16 propertyFlag; int16 *property = getObjectPropertyPtr(objectIndex, propertyId, propertyFlag); @@ -356,7 +356,7 @@ int16 GameDatabase::getObjectProperty(int16 objectIndex, int16 propertyId) { if (property) { return *property; } else { - return 0; + return 0; } } @@ -364,21 +364,21 @@ int16 GameDatabase::getObjectProperty(int16 objectIndex, int16 propertyId) { int16 GameDatabase::setObjectProperty(int16 objectIndex, int16 propertyId, int16 value) { if (objectIndex == 0) - return 0; + return 0; int16 propertyFlag; int16 *property = getObjectPropertyPtr(objectIndex, propertyId, propertyFlag); if (property) { if (propertyFlag == 1) { - *property = value; + *property = value; } else { - debug(2, "GameDatabase::setObjectProperty(%04X, %04X, %04X) Trying to set constant property\n", + debug(2, "GameDatabase::setObjectProperty(%04X, %04X, %04X) Trying to set constant property\n", objectIndex, propertyId, value); } return value; } else { - return 0; + return 0; } } diff --git a/engines/made/database.h b/engines/made/database.h index d5468db607..e96be5e24c 100644 --- a/engines/made/database.h +++ b/engines/made/database.h @@ -35,28 +35,28 @@ namespace Made { class Object { public: - Object(); - ~Object(); - void load(Common::SeekableReadStream &source); - void load(byte *source); + Object(); + ~Object(); + void load(Common::SeekableReadStream &source); + void load(byte *source); - uint16 getFlags() const; - uint16 getClass() const; - uint16 getSize() const; + uint16 getFlags() const; + uint16 getClass() const; + uint16 getSize() const; byte getCount1() const; - byte getCount2() const; + byte getCount2() const; byte *getData(); - const char *getString(); + const char *getString(); - bool isObject(); - bool isVector(); - bool isConstant() const { return !(getFlags() & 1); } - - int16 getVectorSize(); - int16 getVectorItem(int16 index); - void setVectorItem(int16 index, int16 value); + bool isObject(); + bool isVector(); + bool isConstant() const { return !(getFlags() & 1); } + + int16 getVectorSize(); + int16 getVectorItem(int16 index); + void setVectorItem(int16 index, int16 value); void dump(const char *filename); @@ -70,7 +70,7 @@ class GameDatabase { public: GameDatabase(); - ~GameDatabase(); + ~GameDatabase(); void open(const char *filename); diff --git a/engines/made/graphics.cpp b/engines/made/graphics.cpp index 76c10d97cc..081621ef18 100644 --- a/engines/made/graphics.cpp +++ b/engines/made/graphics.cpp @@ -31,121 +31,121 @@ namespace Made { void decompressImage(byte *source, Graphics::Surface &surface, uint16 cmdOffs, uint16 pixelOffs, uint16 maskOffs, uint16 lineSize, bool deltaFrame) { - const int offsets[] = { - 0, 1, 2, 3, - 320, 321, 322, 323, - 640, 641, 642, 643, - 960, 961, 962, 963 - }; + const int offsets[] = { + 0, 1, 2, 3, + 320, 321, 322, 323, + 640, 641, 642, 643, + 960, 961, 962, 963 + }; uint16 width = surface.w; - uint16 height = surface.h; - - byte *cmdBuffer = source + cmdOffs; - byte *maskBuffer = source + maskOffs; - byte *pixelBuffer = source + pixelOffs; - - byte *destPtr = (byte*)surface.getBasePtr(0, 0); - - //byte lineBuf[320 * 4]; - byte lineBuf[640 * 4]; - byte bitBuf[40]; - - int bitBufLastOfs = (((lineSize + 1) >> 1) << 1) - 2; - int bitBufLastCount = ((width + 3) >> 2) & 7; - if (bitBufLastCount == 0) - bitBufLastCount = 8; - - while (height > 0) { - - int drawDestOfs = 0; - - memset(lineBuf, 0, sizeof(lineBuf)); - - memcpy(bitBuf, cmdBuffer, lineSize); - cmdBuffer += lineSize; - - for (uint16 bitBufOfs = 0; bitBufOfs < lineSize; bitBufOfs += 2) { - - uint16 bits = READ_LE_UINT16(&bitBuf[bitBufOfs]); - - int bitCount; - if (bitBufOfs == bitBufLastOfs) - bitCount = bitBufLastCount; - else - bitCount = 8; - - for (int curCmd = 0; curCmd < bitCount; curCmd++) { - int cmd = bits & 3; - bits >>= 2; - - byte pixels[4]; - uint32 mask; - - switch (cmd) { - - case 0: - pixels[0] = *pixelBuffer++; - for (int i = 0; i < 16; i++) - lineBuf[drawDestOfs + offsets[i]] = pixels[0]; - break; - - case 1: - pixels[0] = *pixelBuffer++; - pixels[1] = *pixelBuffer++; - mask = READ_LE_UINT16(maskBuffer); - maskBuffer += 2; - for (int i = 0; i < 16; i++) { - lineBuf[drawDestOfs + offsets[i]] = pixels[mask & 1]; - mask >>= 1; - } - break; - - case 2: - pixels[0] = *pixelBuffer++; - pixels[1] = *pixelBuffer++; - pixels[2] = *pixelBuffer++; - pixels[3] = *pixelBuffer++; - mask = READ_LE_UINT32(maskBuffer); - maskBuffer += 4; - for (int i = 0; i < 16; i++) { - lineBuf[drawDestOfs + offsets[i]] = pixels[mask & 3]; - mask >>= 2; - } - break; - - case 3: - if (!deltaFrame) { - // Yes, it reads from maskBuffer here - for (int i = 0; i < 16; i++) - lineBuf[drawDestOfs + offsets[i]] = *maskBuffer++; - } - break; - - } - - drawDestOfs += 4; - - } - - } - - if (deltaFrame) { - for (int y = 0; y < 4 && height > 0; y++, height--) { - for (int x = 0; x < width; x++) { - if (lineBuf[x + y * 320] != 0) - *destPtr = lineBuf[x + y * 320]; - destPtr++; - } - } - } else { - for (int y = 0; y < 4 && height > 0; y++, height--) { - memcpy(destPtr, &lineBuf[y * 320], width); - destPtr += width; - } - } - - } + uint16 height = surface.h; + + byte *cmdBuffer = source + cmdOffs; + byte *maskBuffer = source + maskOffs; + byte *pixelBuffer = source + pixelOffs; + + byte *destPtr = (byte*)surface.getBasePtr(0, 0); + + //byte lineBuf[320 * 4]; + byte lineBuf[640 * 4]; + byte bitBuf[40]; + + int bitBufLastOfs = (((lineSize + 1) >> 1) << 1) - 2; + int bitBufLastCount = ((width + 3) >> 2) & 7; + if (bitBufLastCount == 0) + bitBufLastCount = 8; + + while (height > 0) { + + int drawDestOfs = 0; + + memset(lineBuf, 0, sizeof(lineBuf)); + + memcpy(bitBuf, cmdBuffer, lineSize); + cmdBuffer += lineSize; + + for (uint16 bitBufOfs = 0; bitBufOfs < lineSize; bitBufOfs += 2) { + + uint16 bits = READ_LE_UINT16(&bitBuf[bitBufOfs]); + + int bitCount; + if (bitBufOfs == bitBufLastOfs) + bitCount = bitBufLastCount; + else + bitCount = 8; + + for (int curCmd = 0; curCmd < bitCount; curCmd++) { + int cmd = bits & 3; + bits >>= 2; + + byte pixels[4]; + uint32 mask; + + switch (cmd) { + + case 0: + pixels[0] = *pixelBuffer++; + for (int i = 0; i < 16; i++) + lineBuf[drawDestOfs + offsets[i]] = pixels[0]; + break; + + case 1: + pixels[0] = *pixelBuffer++; + pixels[1] = *pixelBuffer++; + mask = READ_LE_UINT16(maskBuffer); + maskBuffer += 2; + for (int i = 0; i < 16; i++) { + lineBuf[drawDestOfs + offsets[i]] = pixels[mask & 1]; + mask >>= 1; + } + break; + + case 2: + pixels[0] = *pixelBuffer++; + pixels[1] = *pixelBuffer++; + pixels[2] = *pixelBuffer++; + pixels[3] = *pixelBuffer++; + mask = READ_LE_UINT32(maskBuffer); + maskBuffer += 4; + for (int i = 0; i < 16; i++) { + lineBuf[drawDestOfs + offsets[i]] = pixels[mask & 3]; + mask >>= 2; + } + break; + + case 3: + if (!deltaFrame) { + // Yes, it reads from maskBuffer here + for (int i = 0; i < 16; i++) + lineBuf[drawDestOfs + offsets[i]] = *maskBuffer++; + } + break; + + } + + drawDestOfs += 4; + + } + + } + + if (deltaFrame) { + for (int y = 0; y < 4 && height > 0; y++, height--) { + for (int x = 0; x < width; x++) { + if (lineBuf[x + y * 320] != 0) + *destPtr = lineBuf[x + y * 320]; + destPtr++; + } + } + } else { + for (int y = 0; y < 4 && height > 0; y++, height--) { + memcpy(destPtr, &lineBuf[y * 320], width); + destPtr += width; + } + } + + } } diff --git a/engines/made/made.cpp b/engines/made/made.cpp index e8b0f1b1e1..f590f84d3d 100644 --- a/engines/made/made.cpp +++ b/engines/made/made.cpp @@ -80,11 +80,11 @@ MadeEngine::MadeEngine(OSystem *syst, const MadeGameDescription *gameDesc) : Eng if (cd_num >= 0) _system->openCD(cd_num); - _pmvPlayer = new PmvPlayer(_system, _mixer); - _res = new ProjectReader(); - _screen = new Screen(this); - _dat = new GameDatabase(); - _script = new ScriptInterpreter(this); + _pmvPlayer = new PmvPlayer(_system, _mixer); + _res = new ProjectReader(); + _screen = new Screen(this); + _dat = new GameDatabase(); + _script = new ScriptInterpreter(this); } @@ -112,42 +112,42 @@ int16 MadeEngine::getTimer(int16 timerNum) { } void MadeEngine::setTimer(int16 timerNum, int16 value) { - _timers[timerNum] = value * 60; + _timers[timerNum] = value * 60; } void MadeEngine::resetTimer(int16 timerNum) { - _timers[timerNum] = _system->getMillis(); + _timers[timerNum] = _system->getMillis(); } int16 MadeEngine::allocTimer() { for (int i = 0; i < ARRAYSIZE(_timers); i++) { - if (_timers[i] == -1) { - resetTimer(i); - return i + 1; + if (_timers[i] == -1) { + resetTimer(i); + return i + 1; } } return 0; } void MadeEngine::freeTimer(int16 timerNum) { - _timers[timerNum] = -1; + _timers[timerNum] = -1; } int MadeEngine::go() { for (int i = 0; i < ARRAYSIZE(_timers); i++) - _timers[i] = -1; + _timers[i] = -1; _dat->open("rtzcd.dat"); _res->open("rtzcd.prj"); - PictureResource *flex1 = _res->getPicture(78); - Graphics::Surface *surf = flex1->getPicture(); + PictureResource *flex1 = _res->getPicture(78); + Graphics::Surface *surf = flex1->getPicture(); CursorMan.replaceCursor((const byte *)surf->pixels, surf->w, surf->h, 0, 0, 0); CursorMan.showMouse(true); _res->freeResource(flex1); - _eventMouseX = _eventMouseY = 0; - _script->runScript(_dat->getMainCodeObjectIndex()); + _eventMouseX = _eventMouseY = 0; + _script->runScript(_dat->getMainCodeObjectIndex()); return 0; } diff --git a/engines/made/pmvplayer.cpp b/engines/made/pmvplayer.cpp index 704947132e..bd5252c601 100644 --- a/engines/made/pmvplayer.cpp +++ b/engines/made/pmvplayer.cpp @@ -10,19 +10,19 @@ PmvPlayer::~PmvPlayer() { void PmvPlayer::play(const char *filename) { - _abort = false; - _surface = NULL; + _abort = false; + _surface = NULL; - _fd = new Common::File(); - _fd->open(filename); + _fd = new Common::File(); + _fd->open(filename); - uint32 chunkType, chunkSize; + uint32 chunkType, chunkSize; readChunk(chunkType, chunkSize); // "MOVE" - readChunk(chunkType, chunkSize); // "MHED" + readChunk(chunkType, chunkSize); // "MHED" - // TODO: Evaluate header - //_fd->skip(0x3A); + // TODO: Evaluate header + //_fd->skip(0x3A); uint frameDelay = _fd->readUint16LE(); _fd->skip(10); @@ -39,26 +39,26 @@ void PmvPlayer::play(const char *filename) { } debug(2, "\n"); - _mixer->stopAll(); + _mixer->stopAll(); - _audioStream = Audio::makeAppendableAudioStream(soundFreq, Audio::Mixer::FLAG_UNSIGNED); + _audioStream = Audio::makeAppendableAudioStream(soundFreq, Audio::Mixer::FLAG_UNSIGNED); _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, _audioStream); - // Read palette - _fd->read(_palette, 768); - updatePalette(); + // Read palette + _fd->read(_palette, 768); + updatePalette(); //FILE *raw = fopen("track.raw", "wb"); - while (!_abort && !_fd->eof()) { + while (!_abort && !_fd->eof()) { - readChunk(chunkType, chunkSize); + readChunk(chunkType, chunkSize); if (_fd->eof()) break; - byte *frameData = new byte[chunkSize]; - _fd->read(frameData, chunkSize); + byte *frameData = new byte[chunkSize]; + _fd->read(frameData, chunkSize); byte *audioData = frameData + READ_LE_UINT32(frameData + 8) - 8; uint16 chunkSize = READ_LE_UINT16(audioData + 4); @@ -69,84 +69,84 @@ void PmvPlayer::play(const char *filename) { debug(2, "chunkCount = %d; chunkSize = %d\n", chunkCount, chunkSize); uint32 soundSize = chunkCount * chunkSize; - byte *soundData = new byte[soundSize]; - decompressSound(audioData + 8, soundData, chunkSize, chunkCount); - _audioStream->queueBuffer(soundData, soundSize); - - //fwrite(soundData, soundSize, 1, raw); - - byte *imageData = frameData + READ_LE_UINT32(frameData + 12) - 8; - - uint32 frameNum = READ_LE_UINT32(frameData); - uint16 width = READ_LE_UINT16(imageData + 8); - uint16 height = READ_LE_UINT16(imageData + 10); - uint16 cmdOffs = READ_LE_UINT16(imageData + 12); - uint16 pixelOffs = READ_LE_UINT16(imageData + 16); - uint16 maskOffs = READ_LE_UINT16(imageData + 20); - uint16 lineSize = READ_LE_UINT16(imageData + 24); - - debug(2, "width = %d; height = %d; cmdOffs = %04X; pixelOffs = %04X; maskOffs = %04X; lineSize = %d\n", - width, height, cmdOffs, pixelOffs, maskOffs, lineSize); - - if (!_surface) { - _surface = new Graphics::Surface(); - _surface->create(width, height, 1); - } + byte *soundData = new byte[soundSize]; + decompressSound(audioData + 8, soundData, chunkSize, chunkCount); + _audioStream->queueBuffer(soundData, soundSize); + + //fwrite(soundData, soundSize, 1, raw); + + byte *imageData = frameData + READ_LE_UINT32(frameData + 12) - 8; + + uint32 frameNum = READ_LE_UINT32(frameData); + uint16 width = READ_LE_UINT16(imageData + 8); + uint16 height = READ_LE_UINT16(imageData + 10); + uint16 cmdOffs = READ_LE_UINT16(imageData + 12); + uint16 pixelOffs = READ_LE_UINT16(imageData + 16); + uint16 maskOffs = READ_LE_UINT16(imageData + 20); + uint16 lineSize = READ_LE_UINT16(imageData + 24); + + debug(2, "width = %d; height = %d; cmdOffs = %04X; pixelOffs = %04X; maskOffs = %04X; lineSize = %d\n", + width, height, cmdOffs, pixelOffs, maskOffs, lineSize); + + if (!_surface) { + _surface = new Graphics::Surface(); + _surface->create(width, height, 1); + } - decompressImage(imageData, *_surface, cmdOffs, pixelOffs, maskOffs, lineSize, frameNum > 0); + decompressImage(imageData, *_surface, cmdOffs, pixelOffs, maskOffs, lineSize, frameNum > 0); handleEvents(); - updateScreen(); + updateScreen(); - delete[] frameData; + delete[] frameData; _system->delayMillis(frameDelay); - } + } - _audioStream->finish(); - _mixer->stopAll(); - - //delete _audioStream; - delete _fd; - delete _surface; + _audioStream->finish(); + _mixer->stopAll(); + + //delete _audioStream; + delete _fd; + delete _surface; //fclose(raw); } void PmvPlayer::readChunk(uint32 &chunkType, uint32 &chunkSize) { - chunkType = _fd->readUint32BE(); - chunkSize = _fd->readUint32LE(); + chunkType = _fd->readUint32BE(); + chunkSize = _fd->readUint32LE(); - debug(2, "chunkType = %c%c%c%c; chunkSize = %d\n", - (chunkType >> 24) & 0xFF, (chunkType >> 16) & 0xFF, (chunkType >> 8) & 0xFF, chunkType & 0xFF, - chunkSize); + debug(2, "chunkType = %c%c%c%c; chunkSize = %d\n", + (chunkType >> 24) & 0xFF, (chunkType >> 16) & 0xFF, (chunkType >> 8) & 0xFF, chunkType & 0xFF, + chunkSize); } void PmvPlayer::handleEvents() { Common::Event event; while (_system->getEventManager()->pollEvent(event)) { - if (event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) { - _abort = true; + if (event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) { + _abort = true; } } } void PmvPlayer::updatePalette() { - byte colors[1024]; - for (int i = 0; i < 256; i++) { - colors[i * 4 + 0] = _palette[i * 3 + 0]; - colors[i * 4 + 1] = _palette[i * 3 + 1]; - colors[i * 4 + 2] = _palette[i * 3 + 2]; - colors[i * 4 + 3] = 0; - } - _system->setPalette(colors, 0, 256); + byte colors[1024]; + for (int i = 0; i < 256; i++) { + colors[i * 4 + 0] = _palette[i * 3 + 0]; + colors[i * 4 + 1] = _palette[i * 3 + 1]; + colors[i * 4 + 2] = _palette[i * 3 + 2]; + colors[i * 4 + 3] = 0; + } + _system->setPalette(colors, 0, 256); } void PmvPlayer::updateScreen() { - _system->copyRectToScreen((const byte*)_surface->pixels, _surface->pitch, 0, 0, _surface->w, _surface->h); - _system->updateScreen(); + _system->copyRectToScreen((const byte*)_surface->pixels, _surface->pitch, 0, 0, _surface->w, _surface->h); + _system->updateScreen(); } } diff --git a/engines/made/pmvplayer.h b/engines/made/pmvplayer.h index 51f5a36734..11204df3a7 100644 --- a/engines/made/pmvplayer.h +++ b/engines/made/pmvplayer.h @@ -16,22 +16,22 @@ namespace Made { class PmvPlayer { public: - PmvPlayer(OSystem *system, Audio::Mixer *mixer); - ~PmvPlayer(); - void play(const char *filename); + PmvPlayer(OSystem *system, Audio::Mixer *mixer); + ~PmvPlayer(); + void play(const char *filename); protected: - OSystem *_system; - Audio::Mixer *_mixer; - Common::File *_fd; - Audio::AppendableAudioStream *_audioStream; - Audio::SoundHandle _audioStreamHandle; - byte _palette[768]; - Graphics::Surface *_surface; - bool _abort; - void readChunk(uint32 &chunkType, uint32 &chunkSize); - void handleEvents(); - void updatePalette(); - void updateScreen(); + OSystem *_system; + Audio::Mixer *_mixer; + Common::File *_fd; + Audio::AppendableAudioStream *_audioStream; + Audio::SoundHandle _audioStreamHandle; + byte _palette[768]; + Graphics::Surface *_surface; + bool _abort; + void readChunk(uint32 &chunkType, uint32 &chunkSize); + void handleEvents(); + void updatePalette(); + void updateScreen(); }; } diff --git a/engines/made/resource.cpp b/engines/made/resource.cpp index ea1e16b3a2..ebfc9a53da 100644 --- a/engines/made/resource.cpp +++ b/engines/made/resource.cpp @@ -43,9 +43,9 @@ PictureResource::PictureResource() : _picture(NULL), _palette(NULL) { PictureResource::~PictureResource() { if (_picture) - delete _picture; + delete _picture; if (_palette) - delete[] _palette; + delete[] _palette; } void PictureResource::load(byte *source, int size) { @@ -67,8 +67,8 @@ void PictureResource::load(byte *source, int size) { debug(2, "width = %d; height = %d\n", width, height); if (hasPalette) { - _palette = new byte[768]; - sourceS->read(_palette, 768); + _palette = new byte[768]; + sourceS->read(_palette, 768); } _picture = new Graphics::Surface(); @@ -107,11 +107,11 @@ void AnimationResource::load(byte *source, int size) { for (uint16 i = 0; i < frameCount; i++) { - sourceS->seek(26 + i * 4); + sourceS->seek(26 + i * 4); uint32 frameOffs = sourceS->readUint32LE(); - sourceS->seek(frameOffs); + sourceS->seek(frameOffs); sourceS->readUint32LE(); sourceS->readUint32LE(); @@ -128,9 +128,9 @@ void AnimationResource::load(byte *source, int size) { Graphics::Surface *frame = new Graphics::Surface(); frame->create(frameWidth, frameHeight, 1); - decompressImage(source + frameOffs, *frame, cmdOffs, pixelOffs, maskOffs, lineSize, _flags & 1); + decompressImage(source + frameOffs, *frame, cmdOffs, pixelOffs, maskOffs, lineSize, _flags & 1); - _frames.push_back(frame); + _frames.push_back(frame); } @@ -145,7 +145,7 @@ SoundResource::SoundResource() : _soundSize(0), _soundData(NULL) { SoundResource::~SoundResource() { if (_soundData) - delete[] _soundData; + delete[] _soundData; } void SoundResource::load(byte *source, int size) { @@ -154,7 +154,7 @@ void SoundResource::load(byte *source, int size) { uint16 chunkSize = READ_LE_UINT16(source + 12); _soundSize = chunkCount * chunkSize; - _soundData = new byte[_soundSize]; + _soundData = new byte[_soundSize]; decompressSound(source + 14, _soundData, chunkSize, chunkCount); @@ -173,18 +173,18 @@ MenuResource::~MenuResource() { } void MenuResource::load(byte *source, int size) { - _strings.clear(); - Common::MemoryReadStream *sourceS = new Common::MemoryReadStream(source, size); - sourceS->skip(4); // skip "MENU" - uint16 count = sourceS->readUint16LE(); - for (uint16 i = 0; i < count; i++) { - uint16 offs = sourceS->readUint16LE(); - const char *string = (const char*)(source + offs); - _strings.push_back(string); - debug(2, "%02d: %s\n", i, string); + _strings.clear(); + Common::MemoryReadStream *sourceS = new Common::MemoryReadStream(source, size); + sourceS->skip(4); // skip "MENU" + uint16 count = sourceS->readUint16LE(); + for (uint16 i = 0; i < count; i++) { + uint16 offs = sourceS->readUint16LE(); + const char *string = (const char*)(source + offs); + _strings.push_back(string); + debug(2, "%02d: %s\n", i, string); } fflush(stdout); - delete sourceS; + delete sourceS; } /* ProjectReader */ @@ -197,137 +197,137 @@ ProjectReader::~ProjectReader() { void ProjectReader::open(const char *filename) { - _fd = new Common::File(); - _fd->open(filename); + _fd = new Common::File(); + _fd->open(filename); - _fd->skip(0x18); // skip header for now + _fd->skip(0x18); // skip header for now - uint16 indexCount = _fd->readUint16LE(); + uint16 indexCount = _fd->readUint16LE(); - for (uint16 i = 0; i < indexCount; i++) { + for (uint16 i = 0; i < indexCount; i++) { - uint32 resType = _fd->readUint32BE(); - uint32 indexOffs = _fd->readUint32LE(); - _fd->readUint32LE(); - _fd->readUint32LE(); - _fd->readUint32LE(); - _fd->readUint16LE(); - _fd->readUint16LE(); + uint32 resType = _fd->readUint32BE(); + uint32 indexOffs = _fd->readUint32LE(); + _fd->readUint32LE(); + _fd->readUint32LE(); + _fd->readUint32LE(); + _fd->readUint16LE(); + _fd->readUint16LE(); - // We don't need ARCH, FREE and OMNI resources - if (resType == kResARCH || resType == kResFREE || resType == kResOMNI) - continue; + // We don't need ARCH, FREE and OMNI resources + if (resType == kResARCH || resType == kResFREE || resType == kResOMNI) + continue; - //debug(2, "resType = %08X; indexOffs = %d\n", resType, indexOffs); + //debug(2, "resType = %08X; indexOffs = %d\n", resType, indexOffs); - uint32 oldOffs = _fd->pos(); + uint32 oldOffs = _fd->pos(); - ResourceSlots *resSlots = new ResourceSlots(); - _fd->seek(indexOffs); - loadIndex(resSlots); - _resSlots[resType] = resSlots; + ResourceSlots *resSlots = new ResourceSlots(); + _fd->seek(indexOffs); + loadIndex(resSlots); + _resSlots[resType] = resSlots; - _fd->seek(oldOffs); + _fd->seek(oldOffs); - } + } - _cacheCount = 0; + _cacheCount = 0; } PictureResource *ProjectReader::getPicture(int index) { - return createResource(kResFLEX, index); + return createResource(kResFLEX, index); } AnimationResource *ProjectReader::getAnimation(int index) { - return createResource(kResANIM, index); + return createResource(kResANIM, index); } SoundResource *ProjectReader::getSound(int index) { - return createResource(kResSNDS, index); + return createResource(kResSNDS, index); } MenuResource *ProjectReader::getMenu(int index) { - return createResource(kResMENU, index); + return createResource(kResMENU, index); } void ProjectReader::loadIndex(ResourceSlots *slots) { - _fd->readUint32LE(); // skip INDX - _fd->readUint32LE(); // skip index size - _fd->readUint32LE(); // skip unknown - _fd->readUint32LE(); // skip res type - uint16 count = _fd->readUint16LE(); - _fd->readUint16LE(); // skip unknown count - _fd->readUint16LE(); // skip unknown count - for (uint16 i = 0; i < count; i++) { - uint32 offs = _fd->readUint32LE(); - uint32 size = _fd->readUint32LE(); - slots->push_back(ResourceSlot(offs, size)); - } + _fd->readUint32LE(); // skip INDX + _fd->readUint32LE(); // skip index size + _fd->readUint32LE(); // skip unknown + _fd->readUint32LE(); // skip res type + uint16 count = _fd->readUint16LE(); + _fd->readUint16LE(); // skip unknown count + _fd->readUint16LE(); // skip unknown count + for (uint16 i = 0; i < count; i++) { + uint32 offs = _fd->readUint32LE(); + uint32 size = _fd->readUint32LE(); + slots->push_back(ResourceSlot(offs, size)); + } } void ProjectReader::freeResource(Resource *resource) { - tossResourceFromCache(resource->slot); + tossResourceFromCache(resource->slot); } bool ProjectReader::loadResource(ResourceSlot *slot, byte *&buffer, uint32 &size) { if (slot && slot->size > 0) { - size = slot->size - 62; - buffer = new byte[size]; + size = slot->size - 62; + buffer = new byte[size]; debug(2, "ProjectReader::loadResource() %08X\n", slot->offs + 62); fflush(stdout); - _fd->seek(slot->offs + 62); - _fd->read(buffer, size); - return true; + _fd->seek(slot->offs + 62); + _fd->read(buffer, size); + return true; } else { - return false; + return false; } } ResourceSlot *ProjectReader::getResourceSlot(uint32 resType, uint index) { - ResourceSlots *slots = _resSlots[resType]; - if (index >= 1 && index < slots->size()) { - ResourceSlot *slot = &slots->operator[](index); - return slot; + ResourceSlots *slots = _resSlots[resType]; + if (index >= 1 && index < slots->size()) { + ResourceSlot *slot = &slots->operator[](index); + return slot; } else { - return NULL; + return NULL; } } Resource *ProjectReader::getResourceFromCache(ResourceSlot *slot) { - if (slot->res) - slot->refCount++; - return slot->res; + if (slot->res) + slot->refCount++; + return slot->res; } void ProjectReader::addResourceToCache(ResourceSlot *slot, Resource *res) { - if (_cacheCount >= kMaxResourceCacheCount) { - purgeCache(); - } - slot->res = res; - slot->refCount = 0; - _cacheCount++; + if (_cacheCount >= kMaxResourceCacheCount) { + purgeCache(); + } + slot->res = res; + slot->refCount = 0; + _cacheCount++; } void ProjectReader::tossResourceFromCache(ResourceSlot *slot) { - if (slot->res) { - slot->refCount--; - } + if (slot->res) { + slot->refCount--; + } } void ProjectReader::purgeCache() { printf("ProjectReader::purgeCache()\n"); - for (ResMap::const_iterator resTypeIter = _resSlots.begin(); resTypeIter != _resSlots.end(); ++resTypeIter) { - ResourceSlots *slots = (*resTypeIter)._value; - for (ResourceSlots::iterator slotIter = slots->begin(); slotIter != slots->end(); ++slotIter) { - ResourceSlot *slot = &(*slotIter); - if (slot->refCount <= 0 && slot->res) { - delete slot->res; - slot->res = NULL; - slot->refCount = 0; - _cacheCount--; - } - } - } + for (ResMap::const_iterator resTypeIter = _resSlots.begin(); resTypeIter != _resSlots.end(); ++resTypeIter) { + ResourceSlots *slots = (*resTypeIter)._value; + for (ResourceSlots::iterator slotIter = slots->begin(); slotIter != slots->end(); ++slotIter) { + ResourceSlot *slot = &(*slotIter); + if (slot->refCount <= 0 && slot->res) { + delete slot->res; + slot->res = NULL; + slot->refCount = 0; + _cacheCount--; + } + } + } } } // End of namespace Made diff --git a/engines/made/resource.h b/engines/made/resource.h index 9b672a1c5d..619bf80b0c 100644 --- a/engines/made/resource.h +++ b/engines/made/resource.h @@ -38,31 +38,31 @@ namespace Made { const int kMaxResourceCacheCount = 100; enum ResourceType { - kResARCH = MKID_BE('ARCH'), - kResFREE = MKID_BE('FREE'), - kResOMNI = MKID_BE('OMNI'), - kResFLEX = MKID_BE('FLEX'), - kResSNDS = MKID_BE('SNDS'), - kResANIM = MKID_BE('ANIM'), - kResMENU = MKID_BE('MENU') + kResARCH = MKID_BE('ARCH'), + kResFREE = MKID_BE('FREE'), + kResOMNI = MKID_BE('OMNI'), + kResFLEX = MKID_BE('FLEX'), + kResSNDS = MKID_BE('SNDS'), + kResANIM = MKID_BE('ANIM'), + kResMENU = MKID_BE('MENU') }; struct ResourceSlot; class Resource { public: - ResourceSlot *slot; - virtual ~Resource(); - virtual void load(byte *buffer, int size) = 0; + ResourceSlot *slot; + virtual ~Resource(); + virtual void load(byte *buffer, int size) = 0; }; class PictureResource : public Resource { public: - PictureResource(); - ~PictureResource(); - void load(byte *source, int size); - Graphics::Surface *getPicture() const { return _picture; } - byte *getPalette() const { return _palette; } + PictureResource(); + ~PictureResource(); + void load(byte *source, int size); + Graphics::Surface *getPicture() const { return _picture; } + byte *getPalette() const { return _palette; } protected: Graphics::Surface *_picture; byte *_palette; @@ -70,14 +70,14 @@ protected: class AnimationResource : public Resource { public: - AnimationResource(); - ~AnimationResource(); - void load(byte *source, int size); - int getCount() const { return _frames.size(); } - Graphics::Surface *getFrame(int index) const { return _frames[index]; } - uint16 getFlags() const { return _flags; } - int16 getWidth() const { return _width; } - int16 getHeight() const { return _height; } + AnimationResource(); + ~AnimationResource(); + void load(byte *source, int size); + int getCount() const { return _frames.size(); } + Graphics::Surface *getFrame(int index) const { return _frames[index]; } + uint16 getFlags() const { return _flags; } + int16 getWidth() const { return _width; } + int16 getHeight() const { return _height; } protected: Common::Array _frames; uint16 _flags; @@ -86,10 +86,10 @@ protected: class SoundResource : public Resource { public: - SoundResource(); - ~SoundResource(); - void load(byte *source, int size); - Audio::AudioStream *getAudioStream(); + SoundResource(); + ~SoundResource(); + void load(byte *source, int size); + Audio::AudioStream *getAudioStream(); protected: byte *_soundData; int _soundSize; @@ -97,79 +97,79 @@ protected: class MenuResource : public Resource { public: - MenuResource(); - ~MenuResource(); - void load(byte *source, int size); - int getCount() const { return _strings.size(); } - Common::String getString(int index) const { return _strings[index]; } + MenuResource(); + ~MenuResource(); + void load(byte *source, int size); + int getCount() const { return _strings.size(); } + Common::String getString(int index) const { return _strings[index]; } protected: Common::Array _strings; }; struct ResourceSlot { - uint32 offs; - uint32 size; - Resource *res; - int refCount; - ResourceSlot() : offs(0), size(0), res(NULL), refCount(0) { - } - ResourceSlot(uint32 roffs, uint32 rsize) : offs(roffs), size(rsize), res(NULL), refCount(0) { - } + uint32 offs; + uint32 size; + Resource *res; + int refCount; + ResourceSlot() : offs(0), size(0), res(NULL), refCount(0) { + } + ResourceSlot(uint32 roffs, uint32 rsize) : offs(roffs), size(rsize), res(NULL), refCount(0) { + } }; class ProjectReader { public: - ProjectReader(); - ~ProjectReader(); + ProjectReader(); + ~ProjectReader(); - void open(const char *filename); + void open(const char *filename); - PictureResource *getPicture(int index); - AnimationResource *getAnimation(int index); - SoundResource *getSound(int index); - MenuResource *getMenu(int index); + PictureResource *getPicture(int index); + AnimationResource *getAnimation(int index); + SoundResource *getSound(int index); + MenuResource *getMenu(int index); - void freeResource(Resource *resource); + void freeResource(Resource *resource); protected: - Common::File *_fd; - - typedef Common::Array ResourceSlots; - typedef Common::HashMap ResMap; - - ResMap _resSlots; - int _cacheCount; - - void loadIndex(ResourceSlots *slots); - - template - T *createResource(uint32 resType, int index) { - ResourceSlot *slot = getResourceSlot(resType, index); - if (!slot) - return NULL; - T *res = (T*)getResourceFromCache(slot); - if (!res) { - byte *buffer; - uint32 size; - if (loadResource(slot, buffer, size)) { - res = new T(); - res->slot = slot; - res->load(buffer, size); - addResourceToCache(slot, res); - delete[] buffer; - } - } - return res; - } - - bool loadResource(ResourceSlot *slot, byte *&buffer, uint32 &size); - ResourceSlot *getResourceSlot(uint32 resType, uint index); - Resource *getResourceFromCache(ResourceSlot *slot); - void addResourceToCache(ResourceSlot *slot, Resource *res); - void tossResourceFromCache(ResourceSlot *slot); - void purgeCache(); + Common::File *_fd; + + typedef Common::Array ResourceSlots; + typedef Common::HashMap ResMap; + + ResMap _resSlots; + int _cacheCount; + + void loadIndex(ResourceSlots *slots); + + template + T *createResource(uint32 resType, int index) { + ResourceSlot *slot = getResourceSlot(resType, index); + if (!slot) + return NULL; + T *res = (T*)getResourceFromCache(slot); + if (!res) { + byte *buffer; + uint32 size; + if (loadResource(slot, buffer, size)) { + res = new T(); + res->slot = slot; + res->load(buffer, size); + addResourceToCache(slot, res); + delete[] buffer; + } + } + return res; + } + + bool loadResource(ResourceSlot *slot, byte *&buffer, uint32 &size); + ResourceSlot *getResourceSlot(uint32 resType, uint index); + Resource *getResourceFromCache(ResourceSlot *slot); + void addResourceToCache(ResourceSlot *slot, Resource *res); + void tossResourceFromCache(ResourceSlot *slot); + void purgeCache(); }; diff --git a/engines/made/screen.cpp b/engines/made/screen.cpp index 90688929ae..c0cee5fa51 100644 --- a/engines/made/screen.cpp +++ b/engines/made/screen.cpp @@ -31,31 +31,31 @@ namespace Made { Screen::Screen(MadeEngine *vm) : _vm(vm) { - _screen1 = new Graphics::Surface(); - _screen1->create(320, 200, 1); - _clipInfo1.x = 0; - _clipInfo1.y = 0; - _clipInfo1.w = 320; - _clipInfo1.h = 200; - _clipInfo1.destSurface = _screen1; - - _screen2 = new Graphics::Surface(); - _screen2->create(320, 200, 1); - _clipInfo2.x = 0; - _clipInfo2.y = 0; - _clipInfo2.w = 320; - _clipInfo2.h = 200; - _clipInfo2.destSurface = _screen2; - - _clipArea.destSurface = _screen2; - - _excludeClipAreaEnabled[0] = false; - _excludeClipAreaEnabled[1] = false; - _excludeClipAreaEnabled[2] = false; - _excludeClipAreaEnabled[3] = false; - - clearChannels(); - + _screen1 = new Graphics::Surface(); + _screen1->create(320, 200, 1); + _clipInfo1.x = 0; + _clipInfo1.y = 0; + _clipInfo1.w = 320; + _clipInfo1.h = 200; + _clipInfo1.destSurface = _screen1; + + _screen2 = new Graphics::Surface(); + _screen2->create(320, 200, 1); + _clipInfo2.x = 0; + _clipInfo2.y = 0; + _clipInfo2.w = 320; + _clipInfo2.h = 200; + _clipInfo2.destSurface = _screen2; + + _clipArea.destSurface = _screen2; + + _excludeClipAreaEnabled[0] = false; + _excludeClipAreaEnabled[1] = false; + _excludeClipAreaEnabled[2] = false; + _excludeClipAreaEnabled[3] = false; + + clearChannels(); + } Screen::~Screen() { @@ -64,9 +64,9 @@ Screen::~Screen() { } void Screen::clearScreen() { - _screen1->fillRect(Common::Rect(0, 0, 320, 200), 0); - _screen2->fillRect(Common::Rect(0, 0, 320, 200), 0); - //_vm->_system->clearScreen(); + _screen1->fillRect(Common::Rect(0, 0, 320, 200), 0); + _screen2->fillRect(Common::Rect(0, 0, 320, 200), 0); + //_vm->_system->clearScreen(); } void Screen::drawSurface(Graphics::Surface *source, int x, int y) { @@ -82,7 +82,7 @@ uint16 Screen::updateChannel(uint16 channelIndex) { void Screen::deleteChannel(uint16 channelIndex) { if (channelIndex < 1 || channelIndex >= 100) - return; + return; _channels[channelIndex - 1].type = 0; _channels[channelIndex - 1].state = 0; _channels[channelIndex - 1].index = 0; @@ -90,54 +90,54 @@ void Screen::deleteChannel(uint16 channelIndex) { int16 Screen::getChannelType(uint16 channelIndex) { if (channelIndex < 1 || channelIndex >= 100) - return -1; + return -1; return _channels[channelIndex - 1].type; } int16 Screen::getChannelState(uint16 channelIndex) { if (channelIndex < 1 || channelIndex >= 100) - return -1; + return -1; return _channels[channelIndex - 1].state; } void Screen::setChannelState(uint16 channelIndex, int16 state) { if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0) - return; + return; _channels[channelIndex - 1].state = state; } uint16 Screen::setChannelLocation(uint16 channelIndex, int16 x, int16 y) { if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0) - return 0; - _channels[channelIndex - 1].x = x; - _channels[channelIndex - 1].y = y; + return 0; + _channels[channelIndex - 1].x = x; + _channels[channelIndex - 1].y = y; return updateChannel(channelIndex - 1) + 1; } uint16 Screen::setChannelContent(uint16 channelIndex, uint16 index) { if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0) - return 0; - //debug(2, "setChannelContent(%d, %04X)\n", channelIndex, index); fflush(stdout); g_system->delayMillis(5000); - _channels[channelIndex - 1].index = index; + return 0; + //debug(2, "setChannelContent(%d, %04X)\n", channelIndex, index); fflush(stdout); g_system->delayMillis(5000); + _channels[channelIndex - 1].index = index; return updateChannel(channelIndex - 1) + 1; } void Screen::drawSpriteChannels(const ClipInfo &clipInfo, int16 includeStateMask, int16 excludeStateMask) { - _excludeClipArea[0].destSurface = clipInfo.destSurface; - _excludeClipArea[1].destSurface = clipInfo.destSurface; - _excludeClipArea[2].destSurface = clipInfo.destSurface; - _excludeClipArea[3].destSurface = clipInfo.destSurface; - _clipArea.destSurface = clipInfo.destSurface; - - for (uint16 i = 0; i < _channelsUsedCount; i++) { - - debug(2, "drawSpriteChannels() i = %d\n", i); - - if (((_channels[i].state & includeStateMask) == includeStateMask) && (_channels[i].state & excludeStateMask) == 0) + _excludeClipArea[0].destSurface = clipInfo.destSurface; + _excludeClipArea[1].destSurface = clipInfo.destSurface; + _excludeClipArea[2].destSurface = clipInfo.destSurface; + _excludeClipArea[3].destSurface = clipInfo.destSurface; + _clipArea.destSurface = clipInfo.destSurface; + + for (uint16 i = 0; i < _channelsUsedCount; i++) { + + debug(2, "drawSpriteChannels() i = %d\n", i); + + if (((_channels[i].state & includeStateMask) == includeStateMask) && (_channels[i].state & excludeStateMask) == 0) { - uint16 flag1 = _channels[i].state & 0x10; + uint16 flag1 = _channels[i].state & 0x10; uint16 flag2 = _channels[i].state & 0x20; debug(2, "drawSpriteChannels() type = %d; index = %04X\n", _channels[i].type, _channels[i].index); @@ -145,48 +145,48 @@ void Screen::drawSpriteChannels(const ClipInfo &clipInfo, int16 includeStateMask switch (_channels[i].type) { case 1: // drawFlex - if (_channels[i].state & 4) { - drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, _clipArea); + if (_channels[i].state & 4) { + drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, _clipArea); } else if (_channels[i].state & 8) { - for (int excludeIndex = 0; excludeIndex < 4; excludeIndex++) { + for (int excludeIndex = 0; excludeIndex < 4; excludeIndex++) { if (_excludeClipAreaEnabled[excludeIndex]) { - drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, _excludeClipArea[excludeIndex]); + drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, _excludeClipArea[excludeIndex]); } } } else { - drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, clipInfo); + drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, clipInfo); } - break; + break; case 2: // drawObjectText - // TODO - break; + // TODO + break; case 3: // drawAnimFrame - if (_channels[i].state & 4) { - drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, _clipArea); + if (_channels[i].state & 4) { + drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, _clipArea); } else if (_channels[i].state & 8) { - for (int excludeIndex = 0; excludeIndex < 4; excludeIndex++) { + for (int excludeIndex = 0; excludeIndex < 4; excludeIndex++) { if (_excludeClipAreaEnabled[excludeIndex]) { - drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, _excludeClipArea[excludeIndex]); + drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, _excludeClipArea[excludeIndex]); } } } else { - drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, clipInfo); + drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, clipInfo); } - break; + break; case 4: // drawMenuText - // TODO - break; - + // TODO + break; + default: - break; + break; } } - + } } @@ -197,27 +197,27 @@ void Screen::updateSprites() { memcpy(_screen2->pixels, _screen1->pixels, 64000); - //drawSpriteChannels(_clipInfo1, 3, 0x40);//CHECKME + //drawSpriteChannels(_clipInfo1, 3, 0x40);//CHECKME - drawSpriteChannels(_clipInfo1, 3, 0);//CHECKME - drawSpriteChannels(_clipInfo2, 1, 2);//CHECKME + drawSpriteChannels(_clipInfo1, 3, 0);//CHECKME + drawSpriteChannels(_clipInfo2, 1, 2);//CHECKME - _vm->_system->copyRectToScreen((const byte*)_screen2->pixels, _screen2->pitch, 0, 0, _screen2->w, _screen2->h); + _vm->_system->copyRectToScreen((const byte*)_screen2->pixels, _screen2->pitch, 0, 0, _screen2->w, _screen2->h); } void Screen::clearChannels() { for (uint16 i = 0; i < ARRAYSIZE(_channels); i++) { - _channels[i].type = 0; - _channels[i].index = 0; + _channels[i].type = 0; + _channels[i].index = 0; } - _channelsUsedCount = 0; + _channelsUsedCount = 0; } uint16 Screen::drawFlex(uint16 flexIndex, int16 x, int16 y, uint16 flag1, uint16 flag2, const ClipInfo &clipInfo) { if (flexIndex == 0) - return 0; + return 0; PictureResource *flex = _vm->_res->getPicture(flexIndex); Graphics::Surface *sourceSurface = flex->getPicture(); @@ -226,16 +226,16 @@ uint16 Screen::drawFlex(uint16 flexIndex, int16 x, int16 y, uint16 flag1, uint16 if (x + sourceSurface->w > clipInfo.destSurface->w || y + sourceSurface->h > clipInfo.destSurface->h) { - debug(2, "CLIPPING PROBLEM: x = %d; y = %d; w = %d; h = %d; x+w = %d; y+h = %d\n", + debug(2, "CLIPPING PROBLEM: x = %d; y = %d; w = %d; h = %d; x+w = %d; y+h = %d\n", x, y, sourceSurface->w, sourceSurface->h, x + sourceSurface->w, y + sourceSurface->h); - //fflush(stdout); g_system->delayMillis(5000); - return 0; + //fflush(stdout); g_system->delayMillis(5000); + return 0; } for (int16 yc = 0; yc < sourceSurface->h; yc++) { - for (int16 xc = 0; xc < sourceSurface->w; xc++) { - if (source[xc]) - dest[xc] = source[xc]; + for (int16 xc = 0; xc < sourceSurface->w; xc++) { + if (source[xc]) + dest[xc] = source[xc]; } source += sourceSurface->pitch; dest += clipInfo.destSurface->pitch; @@ -243,16 +243,16 @@ uint16 Screen::drawFlex(uint16 flexIndex, int16 x, int16 y, uint16 flag1, uint16 // TODO: Palette stuff; palette should be set in showPage byte *pal = flex->getPalette(); - if (pal) { - for (int i = 0; i < 256; i++) { - _palette[i * 4 + 0] = pal[i * 3 + 0]; - _palette[i * 4 + 1] = pal[i * 3 + 1]; - _palette[i * 4 + 2] = pal[i * 3 + 2]; + if (pal) { + for (int i = 0; i < 256; i++) { + _palette[i * 4 + 0] = pal[i * 3 + 0]; + _palette[i * 4 + 1] = pal[i * 3 + 1]; + _palette[i * 4 + 2] = pal[i * 3 + 2]; } _vm->_system->setPalette(_palette, 0, 256); } - _vm->_res->freeResource(flex); + _vm->_res->freeResource(flex); return 0; } @@ -265,16 +265,16 @@ void Screen::drawAnimFrame(uint16 animIndex, int16 x, int16 y, int16 frameNum, u byte *dest = (byte*)clipInfo.destSurface->getBasePtr(x, y); for (int16 yc = 0; yc < sourceSurface->h; yc++) { - for (int16 xc = 0; xc < sourceSurface->w; xc++) { - if (source[xc]) - dest[xc] = source[xc]; + for (int16 xc = 0; xc < sourceSurface->w; xc++) { + if (source[xc]) + dest[xc] = source[xc]; } source += sourceSurface->pitch; dest += clipInfo.destSurface->pitch; } - _vm->_res->freeResource(anim); - + _vm->_res->freeResource(anim); + } uint16 Screen::drawPic(uint16 index, int16 x, int16 y, uint16 flag1, uint16 flag2) { @@ -282,12 +282,12 @@ uint16 Screen::drawPic(uint16 index, int16 x, int16 y, uint16 flag1, uint16 flag //DEBUG if (y > 200) y = 0; - drawFlex(index, x, y, flag1, flag2, _clipInfo1); + drawFlex(index, x, y, flag1, flag2, _clipInfo1); return 0; } uint16 Screen::drawAnimPic(uint16 animIndex, int16 x, int16 y, int16 frameNum, uint16 flag1, uint16 flag2) { - drawAnimFrame(animIndex, x, y, frameNum, flag1, flag2, _clipInfo1); + drawAnimFrame(animIndex, x, y, frameNum, flag1, flag2, _clipInfo1); return 0; } @@ -299,23 +299,23 @@ uint16 Screen::addSprite(uint16 spriteIndex) { } uint16 Screen::drawSprite(uint16 flexIndex, int16 x, int16 y) { - return placeSprite(_channelsUsedCount + 1, flexIndex, x, y); + return placeSprite(_channelsUsedCount + 1, flexIndex, x, y); } uint16 Screen::placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 y) { - debug(2, "placeSprite(%d, %04X, %d, %d)\n", channelIndex, flexIndex, x, y); fflush(stdout); + debug(2, "placeSprite(%d, %04X, %d, %d)\n", channelIndex, flexIndex, x, y); fflush(stdout); //g_system->delayMillis(5000); if (channelIndex < 1 || channelIndex >= 100) - return 0; - - channelIndex--; - + return 0; + + channelIndex--; + PictureResource *flex = _vm->_res->getPicture(flexIndex); if (flex) { - Graphics::Surface *surf = flex->getPicture(); + Graphics::Surface *surf = flex->getPicture(); int16 state = 1; int16 x1, y1, x2, y2; @@ -327,30 +327,30 @@ uint16 Screen::placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 //TODO: clipRect(x1, y1, x2, y2); if (_ground == 0) - state |= 2; + state |= 2; if (_clip != 0) - state |= 4; + state |= 4; if (_exclude != 0) - state |= 8; - - _channels[channelIndex].state = state; - _channels[channelIndex].type = 1; - _channels[channelIndex].index = flexIndex; - _channels[channelIndex].x = x; - _channels[channelIndex].y = y; - _channels[channelIndex].x1 = x1; - _channels[channelIndex].y1 = y1; - _channels[channelIndex].x2 = x2; - _channels[channelIndex].y2 = y2; - _channels[channelIndex].area = (x2 - x2) * (y2 - y1); - - if (_channelsUsedCount <= channelIndex) - _channelsUsedCount = channelIndex + 1; - - _vm->_res->freeResource(flex); + state |= 8; + + _channels[channelIndex].state = state; + _channels[channelIndex].type = 1; + _channels[channelIndex].index = flexIndex; + _channels[channelIndex].x = x; + _channels[channelIndex].y = y; + _channels[channelIndex].x1 = x1; + _channels[channelIndex].y1 = y1; + _channels[channelIndex].x2 = x2; + _channels[channelIndex].y2 = y2; + _channels[channelIndex].area = (x2 - x2) * (y2 - y1); + + if (_channelsUsedCount <= channelIndex) + _channelsUsedCount = channelIndex + 1; + + _vm->_res->freeResource(flex); } else { - _channels[channelIndex].type = 0; - _channels[channelIndex].state = 0; + _channels[channelIndex].type = 0; + _channels[channelIndex].state = 0; } return channelIndex + 1; @@ -360,9 +360,9 @@ uint16 Screen::placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 uint16 Screen::placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y, int16 frameNum) { if (channelIndex < 1 || channelIndex >= 100) - return 0; + return 0; - channelIndex--; + channelIndex--; AnimationResource *anim = _vm->_res->getAnimation(animIndex); @@ -378,32 +378,32 @@ uint16 Screen::placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y //TODO: clipRect(x1, y1, x2, y2); if (anim->getFlags() == 1 || _ground == 0) - state |= 2; + state |= 2; if (_clip != 0) - state |= 4; + state |= 4; if (_exclude != 0) - state |= 8; - - _channels[channelIndex].state = state; - _channels[channelIndex].type = 3; - _channels[channelIndex].index = animIndex; - _channels[channelIndex].frameNum = frameNum; - _channels[channelIndex].needRefresh = 1; - _channels[channelIndex].x = x; - _channels[channelIndex].y = y; - _channels[channelIndex].x1 = x1; - _channels[channelIndex].y1 = y1; - _channels[channelIndex].x2 = x2; - _channels[channelIndex].y2 = y2; - _channels[channelIndex].area = (x2 - x2) * (y2 - y1); - - if (_channelsUsedCount <= channelIndex) - _channelsUsedCount = channelIndex + 1; - - _vm->_res->freeResource(anim); + state |= 8; + + _channels[channelIndex].state = state; + _channels[channelIndex].type = 3; + _channels[channelIndex].index = animIndex; + _channels[channelIndex].frameNum = frameNum; + _channels[channelIndex].needRefresh = 1; + _channels[channelIndex].x = x; + _channels[channelIndex].y = y; + _channels[channelIndex].x1 = x1; + _channels[channelIndex].y1 = y1; + _channels[channelIndex].x2 = x2; + _channels[channelIndex].y2 = y2; + _channels[channelIndex].area = (x2 - x2) * (y2 - y1); + + if (_channelsUsedCount <= channelIndex) + _channelsUsedCount = channelIndex + 1; + + _vm->_res->freeResource(anim); } else { - _channels[channelIndex].type = 0; - _channels[channelIndex].state = 0; + _channels[channelIndex].type = 0; + _channels[channelIndex].state = 0; } return channelIndex + 1; @@ -412,27 +412,27 @@ uint16 Screen::placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y int16 Screen::setAnimFrame(uint16 channelIndex, int16 frameNum) { if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0) - return 0; - channelIndex--; - _channels[channelIndex].frameNum = frameNum; - _channels[channelIndex].needRefresh = 1; + return 0; + channelIndex--; + _channels[channelIndex].frameNum = frameNum; + _channels[channelIndex].needRefresh = 1; return updateChannel(channelIndex) + 1; } int16 Screen::getAnimFrame(uint16 channelIndex) { if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0) - return -1; - return _channels[channelIndex - 1].frameNum; + return -1; + return _channels[channelIndex - 1].frameNum; } int16 Screen::getAnimFrameCount(uint16 animIndex) { int16 frameCount = 0; AnimationResource *anim = _vm->_res->getAnimation(animIndex); if (anim) { - frameCount = anim->getCount(); + frameCount = anim->getCount(); _vm->_res->freeResource(anim); } - return frameCount; + return frameCount; } @@ -446,13 +446,13 @@ void Screen::show() { memcpy(_screen2->pixels, _screen1->pixels, 64000); - drawSpriteChannels(_clipInfo2, 0, 0); - - //drawSpriteChannels(_clipInfo2, 3, 0);//CHECKME - //drawSpriteChannels(_clipInfo2, 1, 2);//CHECKME + drawSpriteChannels(_clipInfo2, 0, 0); + + //drawSpriteChannels(_clipInfo2, 3, 0);//CHECKME + //drawSpriteChannels(_clipInfo2, 1, 2);//CHECKME - //_vm->_system->copyRectToScreen((const byte*)_screen1->pixels, _screen1->pitch, 0, 0, _screen1->w, _screen1->h); - _vm->_system->copyRectToScreen((const byte*)_screen2->pixels, _screen2->pitch, 0, 0, _screen2->w, _screen2->h); + //_vm->_system->copyRectToScreen((const byte*)_screen1->pixels, _screen1->pitch, 0, 0, _screen1->w, _screen1->h); + _vm->_system->copyRectToScreen((const byte*)_screen2->pixels, _screen2->pitch, 0, 0, _screen2->w, _screen2->h); } diff --git a/engines/made/screen.h b/engines/made/screen.h index 9197663383..dfaa34d7c6 100644 --- a/engines/made/screen.h +++ b/engines/made/screen.h @@ -55,66 +55,66 @@ class MadeEngine; class Screen { public: - Screen(MadeEngine *vm); - ~Screen(); + Screen(MadeEngine *vm); + ~Screen(); - void clearScreen(); - - void drawSurface(Graphics::Surface *source, int x, int y); - void setPalette(byte *palette, int start, int count); + void clearScreen(); + + void drawSurface(Graphics::Surface *source, int x, int y); + void setPalette(byte *palette, int start, int count); - uint16 updateChannel(uint16 channelIndex); - void deleteChannel(uint16 channelIndex); - int16 getChannelType(uint16 channelIndex); + uint16 updateChannel(uint16 channelIndex); + void deleteChannel(uint16 channelIndex); + int16 getChannelType(uint16 channelIndex); int16 getChannelState(uint16 channelIndex); void setChannelState(uint16 channelIndex, int16 state); - uint16 setChannelLocation(uint16 channelIndex, int16 x, int16 y); - uint16 setChannelContent(uint16 channelIndex, uint16 index); - void drawSpriteChannels(const ClipInfo &clipInfo, int16 includeStateMask, int16 excludeStateMask); - void updateSprites(); + uint16 setChannelLocation(uint16 channelIndex, int16 x, int16 y); + uint16 setChannelContent(uint16 channelIndex, uint16 index); + void drawSpriteChannels(const ClipInfo &clipInfo, int16 includeStateMask, int16 excludeStateMask); + void updateSprites(); void clearChannels(); - uint16 drawFlex(uint16 flexIndex, int16 x, int16 y, uint16 flag1, uint16 flag2, const ClipInfo &clipInfo); + uint16 drawFlex(uint16 flexIndex, int16 x, int16 y, uint16 flag1, uint16 flag2, const ClipInfo &clipInfo); void drawAnimFrame(uint16 animIndex, int16 x, int16 y, int16 frameNum, uint16 flag1, uint16 flag2, const ClipInfo &clipInfo); - uint16 drawPic(uint16 index, int16 x, int16 y, uint16 flag1, uint16 flag2); + uint16 drawPic(uint16 index, int16 x, int16 y, uint16 flag1, uint16 flag2); uint16 drawAnimPic(uint16 animIndex, int16 x, int16 y, int16 frameNum, uint16 flag1, uint16 flag2); uint16 addSprite(uint16 spriteIndex); - uint16 drawSprite(uint16 flexIndex, int16 x, int16 y); - uint16 placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 y); + uint16 drawSprite(uint16 flexIndex, int16 x, int16 y); + uint16 placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 y); - uint16 placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y, int16 frameNum); + uint16 placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y, int16 frameNum); int16 setAnimFrame(uint16 channelIndex, int16 frameNum); - int16 getAnimFrame(uint16 channelIndex); - // TODO: Move to script function + int16 getAnimFrame(uint16 channelIndex); + // TODO: Move to script function int16 getAnimFrameCount(uint16 animIndex); - uint16 placeText(uint16 channelIndex, uint16 textObjectIndex, int16 x, int16 y, uint16 fontNum, int16 textColor, int16 outlineColor); - - void show(); - - void setClip(uint16 clip); - void setExclude(uint16 exclude); - void setGround(uint16 ground); + uint16 placeText(uint16 channelIndex, uint16 textObjectIndex, int16 x, int16 y, uint16 fontNum, int16 textColor, int16 outlineColor); + + void show(); + + void setClip(uint16 clip); + void setExclude(uint16 exclude); + void setGround(uint16 ground); - byte _palette[256 * 4]; + byte _palette[256 * 4]; protected: - MadeEngine *_vm; - - bool _screenLock; - - uint16 _clip, _exclude, _ground; - - Graphics::Surface *_screen1, *_screen2; - ClipInfo _clipArea, _clipInfo1, _clipInfo2; - - ClipInfo _excludeClipArea[4]; - bool _excludeClipAreaEnabled[4]; - - uint16 _channelsUsedCount; + MadeEngine *_vm; + + bool _screenLock; + + uint16 _clip, _exclude, _ground; + + Graphics::Surface *_screen1, *_screen2; + ClipInfo _clipArea, _clipInfo1, _clipInfo2; + + ClipInfo _excludeClipArea[4]; + bool _excludeClipAreaEnabled[4]; + + uint16 _channelsUsedCount; SpriteChannel _channels[100]; }; diff --git a/engines/made/script.cpp b/engines/made/script.cpp index abbdf94eaa..2231f3ed2b 100644 --- a/engines/made/script.cpp +++ b/engines/made/script.cpp @@ -154,13 +154,13 @@ int16 ScriptStack::top() { int16 ScriptStack::pop() { if (_stackPos == kScriptStackSize) - error("ScriptStack::pop() Stack underflow"); + error("ScriptStack::pop() Stack underflow"); return _stack[_stackPos++]; } void ScriptStack::push(int16 value) { if (_stackPos == 0) - error("ScriptStack::push() Stack overflow"); + error("ScriptStack::push() Stack overflow"); _stack[--_stackPos] = value; } @@ -173,7 +173,7 @@ int16 ScriptStack::peek(int16 index) { } void ScriptStack::poke(int16 index, int16 value) { - _stack[index] = value; + _stack[index] = value; } void ScriptStack::alloc(int16 count) { @@ -197,77 +197,77 @@ int16 *ScriptStack::getStackPtr() { ScriptInterpreter::ScriptInterpreter(MadeEngine *vm) : _vm(vm) { #define COMMAND(x) { &ScriptInterpreter::x, #x } static CommandEntry commandProcs[] = { - /* 01 */ + /* 01 */ COMMAND(cmd_branchTrue), COMMAND(cmd_branchFalse), COMMAND(cmd_branch), COMMAND(cmd_true), - /* 05 */ + /* 05 */ COMMAND(cmd_false), COMMAND(cmd_push), COMMAND(cmd_not), COMMAND(cmd_add), - /* 09 */ + /* 09 */ COMMAND(cmd_sub), COMMAND(cmd_mul), COMMAND(cmd_div), COMMAND(cmd_mod), - /* 13 */ + /* 13 */ COMMAND(cmd_band), COMMAND(cmd_bor), COMMAND(cmd_bnot), COMMAND(cmd_lt), - /* 17 */ + /* 17 */ COMMAND(cmd_eq), COMMAND(cmd_gt), COMMAND(cmd_loadConstant), COMMAND(cmd_loadVariable), - /* 21 */ + /* 21 */ COMMAND(cmd_getObjectProperty), COMMAND(cmd_setObjectProperty), COMMAND(cmd_set), COMMAND(cmd_print), - /* 25 */ + /* 25 */ COMMAND(cmd_terpri), COMMAND(cmd_printNumber), COMMAND(cmd_vref), COMMAND(cmd_vset), - /* 29 */ + /* 29 */ COMMAND(cmd_vsize), COMMAND(cmd_exit), COMMAND(cmd_return), COMMAND(cmd_call), - /* 33 */ + /* 33 */ COMMAND(cmd_svar), COMMAND(cmd_sset), COMMAND(cmd_split), COMMAND(cmd_snlit), - /* 37 */ + /* 37 */ COMMAND(cmd_yorn), COMMAND(cmd_save), COMMAND(cmd_restore), COMMAND(cmd_arg), - /* 41 */ + /* 41 */ COMMAND(cmd_aset), COMMAND(cmd_tmp), COMMAND(cmd_tset), COMMAND(cmd_tspace), - /* 45 */ + /* 45 */ COMMAND(cmd_class), COMMAND(cmd_objectp), COMMAND(cmd_vectorp), COMMAND(cmd_restart), - /* 49 */ + /* 49 */ COMMAND(cmd_rand), COMMAND(cmd_randomize), COMMAND(cmd_send), COMMAND(cmd_extend), - /* 53 */ + /* 53 */ COMMAND(cmd_catch), COMMAND(cmd_cdone), COMMAND(cmd_throw), COMMAND(cmd_functionp), - /* 57 */ + /* 57 */ COMMAND(cmd_le), COMMAND(cmd_ge), COMMAND(cmd_varx), @@ -288,21 +288,21 @@ ScriptInterpreter::~ScriptInterpreter() { void ScriptInterpreter::runScript(int16 scriptObjectIndex) { - _terminated = false; - _runningScriptObjectIndex = scriptObjectIndex; + _terminated = false; + _runningScriptObjectIndex = scriptObjectIndex; - _localStackPos = _stack.getStackPos(); + _localStackPos = _stack.getStackPos(); - _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); + _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); _codeIp = _codeBase; while (!_terminated) { - byte opcode = readByte(); - if (opcode >= 1 && opcode <= _commandsMax) { - debug(4, "opcode = %s\n", _commands[opcode - 1].desc); - (this->*_commands[opcode - 1].proc)(); + byte opcode = readByte(); + if (opcode >= 1 && opcode <= _commandsMax) { + debug(4, "opcode = %s\n", _commands[opcode - 1].desc); + (this->*_commands[opcode - 1].proc)(); } else { - printf("ScriptInterpreter::runScript(%d) Unknown opcode %02X\n", _runningScriptObjectIndex, opcode); + printf("ScriptInterpreter::runScript(%d) Unknown opcode %02X\n", _runningScriptObjectIndex, opcode); } } @@ -350,9 +350,9 @@ void ScriptInterpreter::cmd_push() { void ScriptInterpreter::cmd_not() { if (_stack.top() == 0) - _stack.setTop(-1); + _stack.setTop(-1); else - _stack.setTop(0); + _stack.setTop(0); } void ScriptInterpreter::cmd_add() { @@ -373,7 +373,7 @@ void ScriptInterpreter::cmd_mul() { void ScriptInterpreter::cmd_div() { int16 value = _stack.pop(); if (value == 0) - _stack.setTop(0); + _stack.setTop(0); else _stack.setTop(_stack.top() / value); } @@ -381,7 +381,7 @@ void ScriptInterpreter::cmd_div() { void ScriptInterpreter::cmd_mod() { int16 value = _stack.pop(); if (value == 0) - _stack.setTop(0); + _stack.setTop(0); else _stack.setTop(_stack.top() % value); } @@ -405,7 +405,7 @@ void ScriptInterpreter::cmd_lt() { if (_stack.top() < value) _stack.setTop(-1); else - _stack.setTop(0); + _stack.setTop(0); } void ScriptInterpreter::cmd_eq() { @@ -413,7 +413,7 @@ void ScriptInterpreter::cmd_eq() { if (_stack.top() == value) _stack.setTop(-1); else - _stack.setTop(0); + _stack.setTop(0); } void ScriptInterpreter::cmd_gt() { @@ -421,7 +421,7 @@ void ScriptInterpreter::cmd_gt() { if (_stack.top() > value) _stack.setTop(-1); else - _stack.setTop(0); + _stack.setTop(0); } void ScriptInterpreter::cmd_loadConstant() { @@ -463,7 +463,7 @@ void ScriptInterpreter::cmd_set() { void ScriptInterpreter::cmd_print() { // TODO: This opcode was used for printing debug messages - Object *obj = _vm->_dat->getObject(_stack.top()); + Object *obj = _vm->_dat->getObject(_stack.top()); const char *text = obj->getString(); debug(4, "%s", text); fflush(stdout); _stack.setTop(0); @@ -486,8 +486,8 @@ void ScriptInterpreter::cmd_vref() { int16 value = 0; debug(4, "index = %d; objectIndex = %d\n", index, objectIndex); fflush(stdout); if (objectIndex > 0) { - Object *obj = _vm->_dat->getObject(objectIndex); - value = obj->getVectorItem(index); + Object *obj = _vm->_dat->getObject(objectIndex); + value = obj->getVectorItem(index); } _stack.setTop(value); debug(4, "--> value = %d\n", value); fflush(stdout); @@ -499,8 +499,8 @@ void ScriptInterpreter::cmd_vset() { int16 objectIndex = _stack.top(); debug(4, "index = %d; objectIndex = %d; value = %d\n", index, objectIndex, value); fflush(stdout); if (objectIndex > 0) { - Object *obj = _vm->_dat->getObject(objectIndex); - obj->setVectorItem(index, value); + Object *obj = _vm->_dat->getObject(objectIndex); + obj->setVectorItem(index, value); } _stack.setTop(value); } @@ -514,7 +514,7 @@ void ScriptInterpreter::cmd_vsize() { } void ScriptInterpreter::cmd_exit() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_return() { @@ -524,10 +524,10 @@ void ScriptInterpreter::cmd_return() { _localStackPos = kScriptStackLimit - _stack.pop(); //_localStackPos = _stack.pop(); _runningScriptObjectIndex = _stack.pop(); - _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); + _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); _codeIp = _codeBase + _stack.pop(); byte argc = _stack.pop(); - _stack.free(argc); + _stack.free(argc); _stack.setTop(funcResult); debug(4, "LEAVE: stackPtr = %d; _localStackPos = %d\n\n\n", _stack.getStackPos(), _localStackPos); } @@ -540,41 +540,41 @@ void ScriptInterpreter::cmd_call() { _stack.push(_runningScriptObjectIndex); _stack.push(kScriptStackLimit - _localStackPos); _localStackPos = _stack.getStackPos(); - _runningScriptObjectIndex = _stack.peek(_localStackPos + argc + 4); - debug(4, "argc = %d; _runningScriptObjectIndex = %04X\n", argc, _runningScriptObjectIndex); fflush(stdout); - _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); + _runningScriptObjectIndex = _stack.peek(_localStackPos + argc + 4); + debug(4, "argc = %d; _runningScriptObjectIndex = %04X\n", argc, _runningScriptObjectIndex); fflush(stdout); + _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); _codeIp = _codeBase; - //_vm->_dat->dumpObject(_runningScriptObjectIndex); + //_vm->_dat->dumpObject(_runningScriptObjectIndex); } void ScriptInterpreter::cmd_svar() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_sset() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_split() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_snlit() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_yorn() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_save() { - //fflush(stdout); g_system->delayMillis(5000); - // TODO - _stack.setTop(0); + //fflush(stdout); g_system->delayMillis(5000); + // TODO + _stack.setTop(0); } void ScriptInterpreter::cmd_restore() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_arg() { @@ -608,28 +608,28 @@ void ScriptInterpreter::cmd_tspace() { } void ScriptInterpreter::cmd_class() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_objectp() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_vectorp() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_restart() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_rand() { - //fflush(stdout); g_system->delayMillis(5000); + //fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_randomize() { - // TODO - _stack.setTop(0); + // TODO + _stack.setTop(0); } void ScriptInterpreter::cmd_send() { @@ -652,25 +652,25 @@ void ScriptInterpreter::cmd_send() { debug(4, "objectIndex = %d (%04X); propertyId = %d(%04X)\n", objectIndex, objectIndex, propertyId, propertyId); fflush(stdout); if (objectIndex != 0) { - objectIndex = _vm->_dat->getObject(objectIndex)->getClass(); + objectIndex = _vm->_dat->getObject(objectIndex)->getClass(); } else { objectIndex = _stack.peek(_localStackPos + argc + 3); } - debug(4, "--> objectIndex = %d(%04X)\n", objectIndex, objectIndex); fflush(stdout); + debug(4, "--> objectIndex = %d(%04X)\n", objectIndex, objectIndex); fflush(stdout); if (objectIndex != 0) { - _runningScriptObjectIndex = _vm->_dat->getObjectProperty(objectIndex, propertyId); - if (_runningScriptObjectIndex != 0) { - _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); + _runningScriptObjectIndex = _vm->_dat->getObjectProperty(objectIndex, propertyId); + if (_runningScriptObjectIndex != 0) { + _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); _codeIp = _codeBase; } else { - _stack.push(0); - cmd_return(); + _stack.push(0); + cmd_return(); } } else { - _stack.push(0); - cmd_return(); + _stack.push(0); + cmd_return(); } } @@ -684,7 +684,7 @@ void ScriptInterpreter::cmd_extend() { debug(4, "func = %d (%s); argc = %d\n", func, extendFuncNames[func], argc); fflush(stdout); for (int i = 0; i < argc; i++) - debug(4, "argv[%02d] = %04X (%d)\n", i, argv[i], argv[i]); + debug(4, "argv[%02d] = %04X (%d)\n", i, argv[i], argv[i]); int16 result = _functions->callFunction(func, argc, argv); debug(4, "result = %04X (%d)\n", result, result); @@ -696,19 +696,19 @@ void ScriptInterpreter::cmd_extend() { } void ScriptInterpreter::cmd_catch() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_cdone() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_throw() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_functionp() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_le() { @@ -716,7 +716,7 @@ void ScriptInterpreter::cmd_le() { if (_stack.top() <= value) _stack.setTop(-1); else - _stack.setTop(0); + _stack.setTop(0); } void ScriptInterpreter::cmd_ge() { @@ -724,15 +724,15 @@ void ScriptInterpreter::cmd_ge() { if (_stack.top() >= value) _stack.setTop(-1); else - _stack.setTop(0); + _stack.setTop(0); } void ScriptInterpreter::cmd_varx() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } void ScriptInterpreter::cmd_setx() { - fflush(stdout); g_system->delayMillis(5000); + fflush(stdout); g_system->delayMillis(5000); } } // End of namespace Made diff --git a/engines/made/script.h b/engines/made/script.h index 5831d3edd2..6c031f8708 100644 --- a/engines/made/script.h +++ b/engines/made/script.h @@ -40,19 +40,19 @@ const int kScriptStackLimit = kScriptStackSize + 1; class ScriptStack { public: - ScriptStack(); - ~ScriptStack(); - int16 top(); - int16 pop(); - void push(int16 value = 0); - void setTop(int16 value); - int16 peek(int16 index); - void poke(int16 index, int16 value); - void alloc(int16 count); - void free(int16 count); - int16 getStackPos() const { return _stackPos; } - void setStackPos(int16 stackPtr); - int16 *getStackPtr(); + ScriptStack(); + ~ScriptStack(); + int16 top(); + int16 pop(); + void push(int16 value = 0); + void setTop(int16 value); + int16 peek(int16 index); + void poke(int16 index, int16 value); + void alloc(int16 count); + void free(int16 count); + int16 getStackPos() const { return _stackPos; } + void setStackPos(int16 stackPtr); + int16 *getStackPtr(); protected: int16 _stack[kScriptStackSize]; int16 _stackPos; @@ -60,11 +60,11 @@ protected: class ScriptInterpreter { public: - ScriptInterpreter(MadeEngine *vm); - ~ScriptInterpreter(); - void runScript(int16 scriptObjectIndex); + ScriptInterpreter(MadeEngine *vm); + ~ScriptInterpreter(); + void runScript(int16 scriptObjectIndex); protected: - MadeEngine *_vm; + MadeEngine *_vm; ScriptStack _stack; int16 _localStackPos; @@ -72,7 +72,7 @@ protected: byte *_codeBase, *_codeIp; bool _terminated; - ScriptFunctions *_functions; + ScriptFunctions *_functions; byte readByte(); int16 readInt16(); diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp index 3f3ad98380..b1d528871d 100644 --- a/engines/made/scriptfuncs.cpp +++ b/engines/made/scriptfuncs.cpp @@ -41,14 +41,14 @@ namespace Made { int16 ScriptFunctions::callFunction(uint16 index, int16 argc, int16 *argv) { if (index >= _externalFuncs.size()) { - // TODO: ERROR! - return 0; + // TODO: ERROR! + return 0; } fflush(stdout); //g_system->delayMillis(2000); - return (*_externalFuncs[index])(argc, argv); + return (*_externalFuncs[index])(argc, argv); } typedef Functor2Mem ExternalFuncRtz; @@ -178,9 +178,9 @@ int16 ScriptFunctionsRtz::o1_RESTOREGRAF(int16 argc, int16 *argv) { int16 ScriptFunctionsRtz::o1_DRAWPIC(int16 argc, int16 *argv) { fflush(stdout); - //g_system->delayMillis(5000); + //g_system->delayMillis(5000); - int16 channel = _vm->_screen->drawPic(argv[4], argv[3], argv[2], argv[1], argv[0]); + int16 channel = _vm->_screen->drawPic(argv[4], argv[3], argv[2], argv[1], argv[0]); return channel; } @@ -191,7 +191,7 @@ int16 ScriptFunctionsRtz::o1_CLS(int16 argc, int16 *argv) { int16 ScriptFunctionsRtz::o1_SHOWPAGE(int16 argc, int16 *argv) { //_vm->_system->setPalette(_vm->_screen->_palette, 0, 256); - _vm->_screen->show(); + _vm->_screen->show(); return 0; } @@ -203,45 +203,45 @@ int16 ScriptFunctionsRtz::o1_EVENT(int16 argc, int16 *argv) { int16 eventNum = 0; if (eventMan->pollEvent(event)) { - switch (event.type) { + switch (event.type) { - case Common::EVENT_MOUSEMOVE: - _vm->_eventMouseX = event.mouse.x; - _vm->_eventMouseY = event.mouse.y; - break; - + case Common::EVENT_MOUSEMOVE: + _vm->_eventMouseX = event.mouse.x; + _vm->_eventMouseY = event.mouse.y; + break; + case Common::EVENT_LBUTTONDOWN: - eventNum = 1; - break; + eventNum = 1; + break; case Common::EVENT_RBUTTONDOWN: - eventNum = 3; - break; - - case Common::EVENT_KEYDOWN: - switch (event.kbd.ascii) { - case '1': - eventNum = 1; - break; - case '2': - eventNum = 2; - break; - case '3': - eventNum = 3; - break; - case '4': - eventNum = 4; - break; - case '5': - eventNum = 5; - break; - default: - break; + eventNum = 3; + break; + + case Common::EVENT_KEYDOWN: + switch (event.kbd.ascii) { + case '1': + eventNum = 1; + break; + case '2': + eventNum = 2; + break; + case '3': + eventNum = 3; + break; + case '4': + eventNum = 4; + break; + case '5': + eventNum = 5; + break; + default: + break; } - break; + break; default: - break; + break; } } @@ -347,7 +347,7 @@ int16 ScriptFunctionsRtz::o1_ERASESPRITES(int16 argc, int16 *argv) { } int16 ScriptFunctionsRtz::o1_UPDATESPRITES(int16 argc, int16 *argv) { - _vm->_screen->updateSprites(); + _vm->_screen->updateSprites(); return 0; } @@ -376,7 +376,7 @@ int16 ScriptFunctionsRtz::o1_FREETIMER(int16 argc, int16 *argv) { } int16 ScriptFunctionsRtz::o1_PALETTELOCK(int16 argc, int16 *argv) { - //g_system->delayMillis(1000); + //g_system->delayMillis(1000); return 0; } @@ -559,7 +559,7 @@ int16 ScriptFunctionsRtz::o1_SETSTATE(int16 argc, int16 *argv) { } int16 ScriptFunctionsRtz::o1_SETLOCATION(int16 argc, int16 *argv) { - g_system->delayMillis(5000); + g_system->delayMillis(5000); return 0; } @@ -613,7 +613,7 @@ int16 ScriptFunctionsRtz::o1_PICWIDTH(int16 argc, int16 *argv) { int16 width = 0; PictureResource *flex = _vm->_res->getPicture(argv[0]); if (flex) { - width = flex->getPicture()->w; + width = flex->getPicture()->w; _vm->_res->freeResource(flex); } return width; @@ -623,7 +623,7 @@ int16 ScriptFunctionsRtz::o1_PICHEIGHT(int16 argc, int16 *argv) { int16 height = 0; PictureResource *flex = _vm->_res->getPicture(argv[0]); if (flex) { - height = flex->getPicture()->h; + height = flex->getPicture()->h; _vm->_res->freeResource(flex); } return height; @@ -658,7 +658,7 @@ int16 ScriptFunctionsRtz::o1_READMENU(int16 argc, int16 *argv) { if (menu) { const char *text = menu->getString(textIndex).c_str(); debug(4, "text = %s\n", text); fflush(stdout); - _vm->_res->freeResource(menu); + _vm->_res->freeResource(menu); } g_system->delayMillis(5000); */ @@ -666,7 +666,7 @@ int16 ScriptFunctionsRtz::o1_READMENU(int16 argc, int16 *argv) { } int16 ScriptFunctionsRtz::o1_DRAWMENU(int16 argc, int16 *argv) { - g_system->delayMillis(5000); + g_system->delayMillis(5000); return 0; } diff --git a/engines/made/scriptfuncs.h b/engines/made/scriptfuncs.h index fc09886bf0..ec8982af06 100644 --- a/engines/made/scriptfuncs.h +++ b/engines/made/scriptfuncs.h @@ -62,12 +62,12 @@ typedef Functor2 ExternalFunc; class ScriptFunctions { public: - ScriptFunctions(MadeEngine *vm) : _vm(vm) {} - virtual ~ScriptFunctions() {} - int16 callFunction(uint16 index, int16 argc, int16 *argv); + ScriptFunctions(MadeEngine *vm) : _vm(vm) {} + virtual ~ScriptFunctions() {} + int16 callFunction(uint16 index, int16 argc, int16 *argv); virtual void setupExternalsTable() = 0; protected: - MadeEngine *_vm; + MadeEngine *_vm; Common::Array _externalFuncs; @@ -75,9 +75,9 @@ protected: class ScriptFunctionsRtz : public ScriptFunctions { public: - ScriptFunctionsRtz(MadeEngine *vm) : ScriptFunctions(vm) {} - ~ScriptFunctionsRtz() {} - void setupExternalsTable(); + ScriptFunctionsRtz(MadeEngine *vm) : ScriptFunctions(vm) {} + ~ScriptFunctionsRtz() {} + void setupExternalsTable(); protected: int16 o1_SYSTEM(int16 argc, int16 *argv); diff --git a/engines/made/sound.cpp b/engines/made/sound.cpp index 520239135d..55b6584003 100644 --- a/engines/made/sound.cpp +++ b/engines/made/sound.cpp @@ -39,13 +39,13 @@ void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCou while (chunkCount--) { - byte deltaType = (*source) >> 6; + byte deltaType = (*source) >> 6; uint16 workChunkSize = chunkSize; - if (deltaType == 1) - workChunkSize /= 2; + if (deltaType == 1) + workChunkSize /= 2; else if (deltaType == 2) - workChunkSize /= 4; + workChunkSize /= 4; byte type = (*source++) & 0x0F; @@ -54,22 +54,22 @@ void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCou switch (type) { case 0: - memset(soundBuffer, 0x80, workChunkSize); - workSample = 0; - break; + memset(soundBuffer, 0x80, workChunkSize); + workSample = 0; + break; case 1: - break; + break; case 2: case 3: case 4: { - const int modeValues[3][4] = { - { 2, 8, 0x01, 1}, - { 4, 4, 0x03, 2}, - {16, 2, 0x0F, 4} + const int modeValues[3][4] = { + { 2, 8, 0x01, 1}, + { 4, 4, 0x03, 2}, + {16, 2, 0x0F, 4} }; uint16 byteCount = modeValues[type - 2][0]; @@ -79,39 +79,39 @@ void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCou uint16 ofs = 0; - for (uint16 i = 0; i < byteCount; i++) - soundBuffer2[i] = (*source++) * 2 - 128; + for (uint16 i = 0; i < byteCount; i++) + soundBuffer2[i] = (*source++) * 2 - 128; while (ofs < workChunkSize) { - byte val = *source++; + byte val = *source++; for (uint i = 0; i < bitCount; i++) { - workSample = CLIP(workSample + soundBuffer2[val & bitMask], -127, 127); - val >>= bitShift; - soundBuffer[ofs++] = workSample + 128; + workSample = CLIP(workSample + soundBuffer2[val & bitMask], -127, 127); + val >>= bitShift; + soundBuffer[ofs++] = workSample + 128; } } - break; + break; } case 5: { - for (uint16 i = 0; i < workChunkSize; i++) - soundBuffer[i] = *source++; - workSample = soundBuffer[workChunkSize - 1] - 128; - break; + for (uint16 i = 0; i < workChunkSize; i++) + soundBuffer[i] = *source++; + workSample = soundBuffer[workChunkSize - 1] - 128; + break; } default: - return; + return; } if (deltaType == 1) { - for (uint16 i = 0; i < chunkSize - 1; i += 2) { - uint16 l = i / 2; - soundBuffer3[i] = soundBuffer[l]; - soundBuffer3[i + 1] = (soundBuffer[l + 1] + soundBuffer[l]) / 2; + for (uint16 i = 0; i < chunkSize - 1; i += 2) { + uint16 l = i / 2; + soundBuffer3[i] = soundBuffer[l]; + soundBuffer3[i + 1] = (soundBuffer[l + 1] + soundBuffer[l]) / 2; } for (uint16 i = 0; i < chunkSize; i++) { soundBuffer[i] = soundBuffer3[i]; @@ -120,9 +120,9 @@ void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCou debug(2, "****************************************"); } - prevSample = workSample; - memcpy(dest, soundBuffer, chunkSize); - dest += chunkSize; + prevSample = workSample; + memcpy(dest, soundBuffer, chunkSize); + dest += chunkSize; } -- cgit v1.2.3