diff options
author | Eugene Sandulenko | 2005-07-30 21:11:48 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2005-07-30 21:11:48 +0000 |
commit | 6b4484472b79dc7ea7d1ce545a28fba7d3b7696f (patch) | |
tree | c44c4e61f18ddd537f7082cb48869cf33d422fbd /kyra | |
parent | 86ab70b149e5cd00cf54f2e41896e2c4e16795e4 (diff) | |
download | scummvm-rg350-6b4484472b79dc7ea7d1ce545a28fba7d3b7696f.tar.gz scummvm-rg350-6b4484472b79dc7ea7d1ce545a28fba7d3b7696f.tar.bz2 scummvm-rg350-6b4484472b79dc7ea7d1ce545a28fba7d3b7696f.zip |
Remove trailing whitespaces.
svn-id: r18604
Diffstat (limited to 'kyra')
-rw-r--r-- | kyra/codecs.cpp | 24 | ||||
-rw-r--r-- | kyra/codecs.h | 2 | ||||
-rw-r--r-- | kyra/cpsimage.cpp | 56 | ||||
-rw-r--r-- | kyra/font.cpp | 126 | ||||
-rw-r--r-- | kyra/kyra.cpp | 18 | ||||
-rw-r--r-- | kyra/kyra.h | 2 | ||||
-rw-r--r-- | kyra/palette.cpp | 20 | ||||
-rw-r--r-- | kyra/resource.cpp | 54 | ||||
-rw-r--r-- | kyra/resource.h | 4 | ||||
-rw-r--r-- | kyra/script.cpp | 66 | ||||
-rw-r--r-- | kyra/script.h | 46 | ||||
-rw-r--r-- | kyra/script_v1.cpp | 54 | ||||
-rw-r--r-- | kyra/sound.cpp | 30 | ||||
-rw-r--r-- | kyra/sound.h | 16 | ||||
-rw-r--r-- | kyra/wsamovie.cpp | 146 | ||||
-rw-r--r-- | kyra/wsamovie.h | 54 |
16 files changed, 359 insertions, 359 deletions
diff --git a/kyra/codecs.cpp b/kyra/codecs.cpp index a51e896802..1853fc85b4 100644 --- a/kyra/codecs.cpp +++ b/kyra/codecs.cpp @@ -23,7 +23,7 @@ #include "kyra/codecs.h" /***************************************************************************** - * decode.c - Decoding routines for format80, format40, format20 + * decode.c - Decoding routines for format80, format40, format20 * and format3 type graphics * Author: Olaf van der spek * Modified for FreeCNC by Kareem Dana @@ -83,7 +83,7 @@ int Compression::decode80(const uint8* image_in, uint8* image_out) { copyp = (const uint8*)&image_out[READ_LE_UINT16(readp)]; readp += 2; - // FIXME: Using memmove sometimes segfaults + // FIXME: Using memmove sometimes segfaults // (reproducably for Ender), which suggests something Bad here //memmove(writep, copyp, count); //writep += count; @@ -197,26 +197,26 @@ int Compression::decode40(const uint8* image_in, uint8* image_out) { */ int Compression::decode3(const uint8* image_in, uint8* image_out, int size) { /* Untested on BIG-Endian machines */ - + /* 0 copy - 1 fill - 2 fill + 1 fill + 2 fill */ const uint8* readp = image_in; uint8* writep = image_out; int16 code; int16 count; - + do { code = *const_cast<int8*>((const int8*)readp++); - if (code > 0) { // Copy + if (code > 0) { // Copy count = code ; while (count--) *writep++ = *readp++; } else if (code == 0) { // Fill(1) count = READ_BE_UINT16(readp); - + readp += 2; code = *readp++; while (count--) @@ -227,10 +227,10 @@ int Compression::decode3(const uint8* image_in, uint8* image_out, int size) { while (count--) *writep++ = (uint8)code; } - } while ((writep - image_out) < size); - - //and, to be uniform to other decomp. functions... - return (writep - image_out); + } while ((writep - image_out) < size); + + //and, to be uniform to other decomp. functions... + return (writep - image_out); } /** decompress format 20 compressed data. diff --git a/kyra/codecs.h b/kyra/codecs.h index 26868c319e..cb0cb13f74 100644 --- a/kyra/codecs.h +++ b/kyra/codecs.h @@ -29,7 +29,7 @@ #include "common/scummsys.h" namespace Kyra { -class Compression +class Compression { public: static int decode80(const uint8* image_in, uint8* image_out); diff --git a/kyra/cpsimage.cpp b/kyra/cpsimage.cpp index 18d8e04293..3e72d7d52e 100644 --- a/kyra/cpsimage.cpp +++ b/kyra/cpsimage.cpp @@ -35,7 +35,7 @@ struct CPSResource { static const CPSResource CPSResourceTable[] = { { 64000, 320 }, { 7740, 180 }, { 46080, 320 }, { 0, 0 } }; - + static int16 getWidthFromCPSRes(uint32 size) { int16 c = 0; @@ -53,32 +53,32 @@ CPSImage::CPSImage(uint8* buffer, uint32 size) { } _ownPalette = 0; Common::MemoryReadStream bufferstream(buffer, size); - + // reads in the Header _cpsHeader._filesize = bufferstream.readUint16LE() + 2; _cpsHeader._format = bufferstream.readUint16LE(); _cpsHeader._imagesize = bufferstream.readUint16LE(); _cpsHeader._pal = bufferstream.readUint32LE(); - + // lets check a bit if (_cpsHeader._pal == 0x3000000) { // if this was a compressed palette you should have strange graphics - + uint8* palbuffer = new uint8[768]; assert(palbuffer); - + bufferstream.read(palbuffer, 768 * sizeof(uint8)); - + _ownPalette = new Palette(palbuffer, 768); assert(palbuffer); } - + _image = new uint8[_cpsHeader._imagesize]; assert(_image); - + uint8* imagebuffer = &buffer[bufferstream.pos()]; assert(imagebuffer); - + if (_cpsHeader._format == 4) { Compression::decode80(imagebuffer, _image); } else if (_cpsHeader._format == 3) { @@ -86,36 +86,36 @@ CPSImage::CPSImage(uint8* buffer, uint32 size) { } else { error("unknown CPS format %d", _cpsHeader._format); } - + int16 width = getWidthFromCPSRes(_cpsHeader._imagesize); - + if (width == -1) { warning("unknown CPS width(imagesize: %d)", _cpsHeader._imagesize); delete [] buffer; return; } - + _width = (uint16)width; _height = _cpsHeader._imagesize / _width; - + _transparency = -1; - + delete [] buffer; } - + CPSImage::~CPSImage() { delete [] _image; delete _ownPalette; } - + void CPSImage::drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 x, uint16 y) { uint8* src = _image; uint8* dst = &plane[y * planepitch + x]; uint32 copysize = planepitch - x; - + if (copysize > _width) copysize = _width; - + if (_transparency == -1) { // 'fast' blitting for (uint16 y_ = 0; y_ < _height && y + y_ < planeheight; ++y_) { @@ -123,10 +123,10 @@ void CPSImage::drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, dst += planepitch; src += _width; } - + } else { // oh no! we have transparency so we have a very slow copy :/ - + for (uint16 yadd = 0; yadd < _height; ++yadd) { for (uint16 xadd = 0; xadd < copysize; ++xadd) { if (*src == _transparency) { @@ -136,25 +136,25 @@ void CPSImage::drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, *dst++ = *src++; } } - + src += _width - copysize; dst += planepitch - copysize; } } } - + void CPSImage::drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 x, uint16 y, uint16 srcx, uint16 srcy, uint16 srcwidth, uint16 srcheight) { uint8* src = &_image[srcy * _width + srcx]; uint8* dst = &plane[y * planepitch + x]; uint32 copysize = planepitch - x; - + if (srcwidth > _width) srcwidth = _width; - + if (copysize > srcwidth) copysize = srcwidth; - + if (_transparency == -1) { // 'fast' blitting for (uint16 y_ = 0; y_ < srcheight && y + y_ < planeheight; ++y_) { @@ -162,10 +162,10 @@ void CPSImage::drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, dst += planepitch; src += _width; } - + } else { // oh no! we have transparency so we have a very slow copy :/ - + for (uint16 yadd = 0; yadd < srcheight; ++yadd) { for (uint16 xadd = 0; xadd < copysize; ++xadd) { if (*src == _transparency) { @@ -175,7 +175,7 @@ void CPSImage::drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, *dst++ = *src++; } } - + dst += planepitch - copysize; src += _width - copysize; } diff --git a/kyra/font.cpp b/kyra/font.cpp index 669030b3b2..a4d4ded4dd 100644 --- a/kyra/font.cpp +++ b/kyra/font.cpp @@ -37,9 +37,9 @@ Font::Font(uint8* buffer, uint32 size) { if (!buffer) { error("resource created without data"); } - + _buffer = buffer; - + Common::MemoryReadStream bufferstream(buffer, size); _fontHeader._size = bufferstream.readUint16LE(); @@ -52,8 +52,8 @@ Font::Font(uint8* buffer, uint32 size) { _fontHeader._version = bufferstream.readUint16LE(); _fontHeader._countChars = bufferstream.readUint16LE(); _fontHeader._width = bufferstream.readByte(); - _fontHeader._height = bufferstream.readByte(); - + _fontHeader._height = bufferstream.readByte(); + // tests for the magic values if (_fontHeader._magic1 != FontHeader_Magic1 || _fontHeader._magic2 != FontHeader_Magic2 || _fontHeader._magic3 != FontHeader_Magic3) { @@ -61,13 +61,13 @@ Font::Font(uint8* buffer, uint32 size) { "_magic1 = 0x%x, _magic2 = 0x%x, _magic3 = 0x%x", _fontHeader._magic1, _fontHeader._magic2, _fontHeader._magic3); } - + // init all the pointers _offsetTable = (uint16*)&buffer[bufferstream.pos()]; _charWidth = &buffer[_fontHeader._charWidthOffset]; _charHeight = (uint16*)&buffer[_fontHeader._charHeightOffset]; _charBits = &buffer[_fontHeader._charBitsOffset]; - + // now prerender =) preRenderAllChars(bufferstream.pos()); @@ -77,7 +77,7 @@ Font::Font(uint8* buffer, uint32 size) { // Russian Floppy: 0x1010 // German Floppy and English/German CD: 0x1011 debug("Font::_version = 0x%x", _fontHeader._version); - + delete [] _buffer; _buffer = 0; _offsetTable = 0; @@ -85,54 +85,54 @@ Font::Font(uint8* buffer, uint32 size) { _charWidth = 0; _charBits = 0; } - + Font::~Font() { // FIXME: Release memory of the prerendered chars } - + uint32 Font::getStringWidth(const char* string, char terminator) { uint32 strsize; - + for (strsize = 0; string[strsize] != terminator && string[strsize] != '\0'; ++strsize) ; - + uint32 stringwidth = 0; - + for (uint32 pos = 0; pos < strsize; ++pos) { stringwidth += _preRenderedChars[string[pos]].width; } - + return stringwidth; } - + const uint8* Font::getChar(char c, uint8* width, uint8* height, uint8* heightadd) { PreRenderedChar& c_ = _preRenderedChars[c]; - + *width = c_.width; *height = c_.height; *heightadd = c_.heightadd; - + return c_.c; } - -// splits up the String in a word + +// splits up the String in a word const char* Font::getNextWord(const char* string, uint32* size) { uint32 startpos = 0; *size = 0; - + // gets start of the word for (; string[startpos] == ' '; ++startpos) ; - + // not counting size for (*size = 0; string[startpos + *size] != ' ' && string[startpos + *size] != '\0'; ++(*size)) ; - + ++(*size); - + return &string[startpos]; } - + // Move this to Font declaration? struct WordChunk { const char* _string; @@ -142,36 +142,36 @@ struct WordChunk { void Font::drawStringToPlane(const char* string, uint8* plane, uint16 planewidth, uint16 planeheight, uint16 x, uint16 y, uint8 color) { - + // lets do it word after word Common::Array<WordChunk> words; - + uint32 lastPos = 0; uint32 lastSize = 0; uint32 strlgt = strlen(string); - + while (true) { WordChunk newchunk; newchunk._string = getNextWord(&string[lastPos], &lastSize); newchunk._size = lastSize; - lastPos += lastSize; - + lastPos += lastSize; + words.push_back(newchunk); - + if (lastPos >= strlgt) break; } - + uint16 current_x = x, current_y = y; uint8 heighest = 0; - + const uint8* src = 0; uint8 width = 0, height = 0, heightadd = 0; - + // now the have alle of these words for (uint32 tmp = 0; tmp < words.size(); ++tmp) { lastSize = getStringWidth(words[tmp]._string, ' '); - + // adjust x position if (current_x + lastSize >= planewidth) { // hmm lets move it a bit to the left @@ -179,93 +179,93 @@ void Font::drawStringToPlane(const char* string, current_x = planewidth - lastSize; } else { current_x = x; - if (heighest) + if (heighest) current_y += heighest + 2; else // now we are using just the fist char :) current_y += _preRenderedChars[words[tmp]._string[0]].height; heighest = 0; } } - + // TODO: maybe test if current_y >= planeheight ? - + // output word :) for (lastPos = 0; lastPos < words[tmp]._size; ++lastPos) { if (words[tmp]._string[lastPos] == '\0') break; - + // gets our char :) src = getChar(words[tmp]._string[lastPos], &width, &height, &heightadd); - + // lets draw our char drawCharToPlane(src, color, width, height, plane, planewidth, planeheight, current_x, current_y + heightadd); - + current_x += width; heighest = MAX(heighest, height); } } } - + void Font::drawCharToPlane(const uint8* c, uint8 color, uint8 width, uint8 height, uint8* plane, uint16 planewidth, uint16 planeheight, uint16 x, uint16 y) { - const uint8* src = c; - + const uint8* src = c; + // blit them to the screen for (uint8 yadd = 0; yadd < height; ++yadd) { for (uint8 xadd = 0; xadd < width; ++xadd) { - switch(*src) { + switch(*src) { case 1: plane[(y + yadd) * planewidth + x + xadd] = color; break; - + case 2: plane[(y + yadd) * planewidth + x + xadd] = 14; break; - + case 3: plane[(y + yadd) * planewidth + x + xadd] = 0; break; - + default: // nothing to do now break; }; - + ++src; } } } - + void Font::preRenderAllChars(uint16 offsetTableOffset) { uint16 startOffset = _offsetTable[0]; uint16 currentOffset = offsetTableOffset; uint8 currentChar = 0; - + for (; currentOffset < startOffset; ++currentChar, currentOffset += sizeof(uint16)) { // lets prerender the char :) - + PreRenderedChar newChar; - + newChar.height = READ_LE_UINT16(&_charHeight[currentChar]) >> 8; newChar.width = _charWidth[currentChar]; newChar.heightadd = READ_LE_UINT16(&_charHeight[currentChar]) & 0xFF; newChar.c = new uint8[newChar.height * newChar.width]; assert(newChar.c); memset(newChar.c, 0, sizeof(uint8) * newChar.height * newChar.width); - + uint8* src = _buffer + READ_LE_UINT16(&_offsetTable[currentChar]); uint8* dst = &newChar.c[0]; uint8 index = 0; - + #ifdef DUMP_FILES static char filename[32] = { 0 }; sprintf(filename, "dumps/char%d.dmp", currentChar); FILE* dump = fopen(filename, "w+"); assert(dump); - + fprintf(dump, "This should be a '%c'\n", currentChar); #endif - + // prerender the char for (uint8 yadd = 0; yadd < newChar.height; ++yadd) { for (uint8 xadd = 0; xadd < newChar.width; ++xadd) { @@ -275,7 +275,7 @@ void Font::preRenderAllChars(uint16 offsetTableOffset) { } else { index = (*src) & 0x0F; } - + switch(index) { case 1: #ifdef DUMP_FILES @@ -283,21 +283,21 @@ void Font::preRenderAllChars(uint16 offsetTableOffset) { #endif dst[yadd * newChar.width + xadd] = 1; break; - + case 2: #ifdef DUMP_FILES fprintf(dump, "$"); #endif dst[yadd * newChar.width + xadd] = 2; break; - + case 3: #ifdef DUMP_FILES fprintf(dump, "§"); #endif dst[yadd * newChar.width + xadd] = 3; break; - + default: #ifdef DUMP_FILES fprintf(dump, "%d", index); @@ -305,7 +305,7 @@ void Font::preRenderAllChars(uint16 offsetTableOffset) { break; }; } - + if (newChar.width % 2) { ++src; } @@ -313,7 +313,7 @@ void Font::preRenderAllChars(uint16 offsetTableOffset) { fprintf(dump, "\n"); #endif } - + #ifdef DUMP_FILES fprintf(dump, "\nThis is the created map:\n"); // now print the whole thing again @@ -325,9 +325,9 @@ void Font::preRenderAllChars(uint16 offsetTableOffset) { } fclose(dump); #endif - + _preRenderedChars[currentChar] = newChar; - + if (currentChar == 255) { break; } diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp index e9d1bf8574..b73d102b93 100644 --- a/kyra/kyra.cpp +++ b/kyra/kyra.cpp @@ -165,7 +165,7 @@ int KyraEngine::init(GameDetector &detector) { // loads the Font _font = _resMgr->loadFont("8FAT.FNT"); - + _npcScript = _resMgr->loadScript("_NPC.EMC"); // loads the scripts (only Kyrandia 1) @@ -174,10 +174,10 @@ int KyraEngine::init(GameDetector &detector) { } else { error("game start files not known"); } - + assert(_npcScript); assert(_currentScript); - + return 0; } @@ -209,7 +209,7 @@ int KyraEngine::go() { warning("init script returned: %d", _currentScript->state()); } }*/ - + Movie* movie = _resMgr->loadMovie("MAL-KAL.WSA"); assert(movie); CPSImage* image = _resMgr->loadImage("GEMCUT.CPS"); @@ -234,12 +234,12 @@ int KyraEngine::go() { _midiDriver->playMusic("KYRA2A.XMI"); _midiDriver->playTrack(3); } - + while (true) { OSystem::Event event; //if (_debugger->isAttached()) // _debugger->onFrame(); - + memcpy(_screen, _buffer, 320 * 200); if (lastFrameChange + movie->frameChange() < _system->getMillis()) { lastFrameChange = _system->getMillis(); @@ -249,7 +249,7 @@ int KyraEngine::go() { currentFrame = 0; } } - + movie->renderFrame(_screen, 320, 200, currentFrame); _font->drawStringToPlane("This is only a test!", _screen, 320, 200, 75, 179, 136); _font->drawStringToPlane("Nothing scripted!", _screen, 320, 200, 85, 189, 136); @@ -265,11 +265,11 @@ int KyraEngine::go() { } _system->delayMillis(10); } - + delete movie; delete image; delete [] _buffer; - + return 0; } diff --git a/kyra/kyra.h b/kyra/kyra.h index dbead3a354..f3b67dd9d6 100644 --- a/kyra/kyra.h +++ b/kyra/kyra.h @@ -63,7 +63,7 @@ public: Resourcemanager* resManager(void) { return _resMgr; } MusicPlayer* midiDriver(void) { return _midiDriver; } - + uint8 game(void) { return _game; } protected: diff --git a/kyra/palette.cpp b/kyra/palette.cpp index 9136666634..b1099f72dc 100644 --- a/kyra/palette.cpp +++ b/kyra/palette.cpp @@ -31,39 +31,39 @@ Palette::Palette(uint8* data, uint32 size) { if (!data) { error("resource created without data"); } - + if (size != 768) { Common::MemoryReadStream datastream(data, size); - + datastream.readSint32LE(); int imageSize = datastream.readSint16LE(); - + if (imageSize != 768) { error("decompresed palette is not 768 byte long!"); } - + // lets uncompress this palette :) _palette = new uint8[imageSize]; assert(_palette); - + // made decompression if (Compression::decode80(data + 10, _palette) != 768) { error("decode80 decompressesize != 768 bytes"); } - + delete [] data; data = _palette; } - + // hmm.. common/system.h Docu is wrong or SDL Backend has a bug :) // a palette should have this order: // R1-G1-B1-A1-R2-G2-B2-A2-... // so we need 4 bytes per color _palette = new uint8[256 * 4]; - + uint8* currentpossrc = &data[0]; uint8* currentposdst = &_palette[0]; - + // creates the original pallette (only first 6 bits are used) for (uint32 i = 0; i < 256; i++) { currentposdst[0] = currentpossrc[0] << 2; @@ -72,7 +72,7 @@ Palette::Palette(uint8* data, uint32 size) { currentpossrc += 3; currentposdst += 4; } - + delete [] data; } diff --git a/kyra/resource.cpp b/kyra/resource.cpp index 1f37d3ec49..7da8772db3 100644 --- a/kyra/resource.cpp +++ b/kyra/resource.cpp @@ -29,9 +29,9 @@ namespace Kyra { Resourcemanager::Resourcemanager(KyraEngine* engine) { _engine = engine; - + // prefetches all PAK Files - + // ugly a hardcoded list // TODO: use the FS Backend to get all .PAK Files and load them // or any other thing to get all files @@ -40,7 +40,7 @@ Resourcemanager::Resourcemanager(KyraEngine* engine) { "S_Z.PAK", "WSA1.PAK", "WSA2.PAK", "WSA3.PAK", "WSA4.PAK", "WSA5.PAK", "WSA6.PAK", 0 }; - + static const char* kyra1CDFilelist[] = { "ADL.PAK", "BRINS.PAK", "CLIFF.PAK", "ENTER.PAK", "FORESTA.PAK", "GEM.PAK", "INTRO1.PAK", "LEPHOLE.PAK", "OAKS.PAK", "SPELL.PAK", "WILLOW.PAK", "ALCHEMY.PAK", "BROKEN.PAK", "COL.PAK", @@ -57,9 +57,9 @@ Resourcemanager::Resourcemanager(KyraEngine* engine) { "NWCLIFB.PAK", "SONG.PAK", "UPSTAIR.PAK", "BRIDGE.PAK", "CHASM.PAK", "EMCAV.PAK", "FNORTH.PAK", "GATECV.PAK", "HEALER.PAK", "LAVA.PAK", "NWCLIFF.PAK", "SORROW.PAK", "WELL.PAK", 0 }; - + const char** usedFilelist = 0; - + if (_engine->game() == KYRA1) usedFilelist = kyra1Filelist; else if (_engine->game() == KYRA1CD) @@ -70,39 +70,39 @@ Resourcemanager::Resourcemanager(KyraEngine* engine) { for (uint32 tmp = 0; usedFilelist[tmp]; ++tmp) { // prefetch file PAKFile* file = new PAKFile(usedFilelist[tmp]); - assert(file); - + assert(file); + if (file->isOpen() && file->isValid()) _pakfiles.push_back(file); else debug("couldn't load file '%s' correctly", usedFilelist[tmp]); } } - + Resourcemanager::~Resourcemanager() { Common::List<PAKFile*>::iterator start = _pakfiles.begin(); - + for (;start != _pakfiles.end(); ++start) { delete *start; *start = 0; } } - + uint8* Resourcemanager::fileData(const char* file, uint32* size) { uint8* buffer = 0; Common::File file_; - + // test to open it in the main dir if (file_.open(file)) { - + *size = file_.size(); buffer = new uint8[*size]; assert(buffer); - + file_.read(buffer, *size); - + file_.close(); - + } else { // opens the file in a PAK File Common::List<PAKFile*>::iterator start = _pakfiles.begin(); @@ -121,16 +121,16 @@ uint8* Resourcemanager::fileData(const char* file, uint32* size) { break; } - + } - + if (!buffer || !(*size)) { return 0; } - + return buffer; } - + Palette* Resourcemanager::loadPalette(const char* file) { uint32 size = 0; uint8* buffer = 0; @@ -141,7 +141,7 @@ Palette* Resourcemanager::loadPalette(const char* file) { } return new Palette(buffer, size); } - + CPSImage* Resourcemanager::loadImage(const char* file) { uint32 size = 0; uint8* buffer = 0; @@ -150,7 +150,7 @@ CPSImage* Resourcemanager::loadImage(const char* file) { return 0; return new CPSImage(buffer, size); } - + Font* Resourcemanager::loadFont(const char* file) { uint32 size = 0; uint8* buffer = 0; @@ -159,7 +159,7 @@ Font* Resourcemanager::loadFont(const char* file) { return 0; return new Font(buffer, size); } - + Movie* Resourcemanager::loadMovie(const char* file) { // TODO: we have to check the Extenion to create the right movie uint32 size = 0; @@ -178,7 +178,7 @@ VMContext* Resourcemanager::loadScript(const char* file) { context->loadScript(file); return context; } - + /////////////////////////////////////////// // Pak file manager #define PAKFile_Iterate Common::List<PakChunk*>::iterator start=_files.begin();start != _files.end(); ++start @@ -186,7 +186,7 @@ PAKFile::PAKFile(/*const Common::String &path, */const Common::String& file) { Common::File pakfile; _buffer = 0; _open = false; - + if (!pakfile.open(file.c_str())){ /*, Common::File::kFileReadMode, path.c_str())) {*/ printf("pakfile couldn't open %s\n", file.c_str()); return; @@ -217,7 +217,7 @@ PAKFile::PAKFile(/*const Common::String &path, */const Common::String& file) { endoffset = READ_LE_UINT32(_buffer + pos); pos += 4; - + if (endoffset == 0) { endoffset = filesize; } @@ -226,7 +226,7 @@ PAKFile::PAKFile(/*const Common::String &path, */const Common::String& file) { chunk->_size = endoffset - startoffset; _files.push_back(chunk); - + if (endoffset == filesize) break; @@ -260,7 +260,7 @@ uint32 PAKFile::getFileSize(const char* file) { if (!scumm_stricmp((*start)->_name, file)) return (*start)->_size; } - + return 0; } } // end of namespace Kyra diff --git a/kyra/resource.h b/kyra/resource.h index 6db1d6bc42..d8dd82d966 100644 --- a/kyra/resource.h +++ b/kyra/resource.h @@ -90,7 +90,7 @@ protected: class Palette { public: - + Palette(uint8* data, uint32 size); ~Palette() { delete [] _palette; } @@ -121,7 +121,7 @@ public: // only for testing :) uint8 getColor(uint16 x, uint16 y) { return _image[y * _width + x]; } - + uint8& operator[](uint16 index) { if (index > _width * _height) return _image[0]; return _image[index]; } protected: diff --git a/kyra/script.cpp b/kyra/script.cpp index 810a805c9c..5a52aca711 100644 --- a/kyra/script.cpp +++ b/kyra/script.cpp @@ -34,7 +34,7 @@ namespace Kyra { VMContext::VMContext(KyraEngine* engine) { _engine = engine; _error = false; - + // now we create a list of all Command/Opcode procs and so static CommandEntry commandProcs[] = { // 0x00 @@ -43,7 +43,7 @@ VMContext::VMContext(KyraEngine* engine) { COMMAND(c1_pushRetRec), COMMAND(c1_push), // 0x04 - COMMAND(c1_push), + COMMAND(c1_push), COMMAND(c1_pushVar), COMMAND(c1_pushFrameNeg), COMMAND(c1_pushFramePos), @@ -63,7 +63,7 @@ VMContext::VMContext(KyraEngine* engine) { }; _numCommands = ARRAYSIZE(commandProcs); _commands = commandProcs; - + static OpcodeEntry opcodeProcs[] = { // 0x00 OPCODE(o1_unknownOpcode), @@ -392,40 +392,40 @@ VMContext::VMContext(KyraEngine* engine) { _scriptFile = NULL; _scriptFileSize = 0; } - + void VMContext::loadScript(const char* file) { if (_scriptFile) { delete [] _scriptFile; _scriptFileSize = 0; } - + memset(_stack, 0, sizeof(int32) * ARRAYSIZE(_stack)); // loads the new file _scriptFile = _engine->resManager()->fileData(file, &_scriptFileSize); - + if (!_scriptFileSize || !_scriptFile) { error("couldn't load script file '%s'", file); } - + Common::MemoryReadStream script(_scriptFile, _scriptFileSize); memset(_chunks, 0, sizeof(ScriptChunk) * kCountChunkTypes); uint8 chunkName[sizeof("EMC2ORDR") + 1]; - + // so lets look for our chunks :) while (!script.eos()) { // lets read only the first 4 chars script.read(chunkName, sizeof(uint8) * 4); chunkName[4] = '\0'; - + // check name of chunk - if (!scumm_stricmp((const char *)chunkName, "FORM")) { + if (!scumm_stricmp((const char *)chunkName, "FORM")) { // FreeKyra swaps the size I only read it in BigEndian :) _chunks[kForm]._size = script.readUint32BE(); } else if (!scumm_stricmp((const char *)chunkName, "TEXT")) { uint32 text_size = script.readUint32BE(); text_size += text_size % 2 != 0 ? 1 : 0; - + _chunks[kText]._data = _scriptFile + script.pos(); _chunks[kText]._size = READ_BE_UINT16(_chunks[kText]._data) >> 1; _chunks[kText]._additional = _chunks[kText]._data + (_chunks[kText]._size << 1); @@ -439,7 +439,7 @@ void VMContext::loadScript(const char* file) { // read next 4 chars script.read(&chunkName[4], sizeof(uint8) * 4); chunkName[8] = '\0'; - + if (!scumm_stricmp((const char *)chunkName, "EMC2ORDR")) { _chunks[kEmc2Ordr]._size = script.readUint32BE() >> 1; _chunks[kEmc2Ordr]._data = _scriptFile + script.pos(); @@ -451,35 +451,35 @@ void VMContext::loadScript(const char* file) { } } } - + int32 VMContext::param(int32 index) { if (_stackPos - index - 1 >= ARRAYSIZE(_stack) || _stackPos - index - 1 < 0) return -0xFFFF; return _stack[_stackPos - index - 1]; } - + const char* VMContext::stringAtIndex(int32 index) { if (index < 0 || (uint32)index >= _chunks[kText]._size) return 0; - + return (const char *)(_chunks[kText]._additional + _chunks[kText]._data[index]); } - + bool VMContext::startScript(int32 func) { if ((uint32)func >= _chunks[kEmc2Ordr]._size || func < 0) { debug("script doesn't support function %d", func); return false; } - + _instructionPos = READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[func]) << 1; _stackPos = 0; _tempPos = 0; _delay = 0; _error = false; _scriptState = kScriptRunning; - + uint32 pos = 0xFFFFFFFE; - + // get start of next script for (uint32 tmp = 0; tmp < _chunks[kEmc2Ordr]._size; ++tmp) { if ((uint32)((READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[tmp]) << 1)) > (uint32)_instructionPos && @@ -487,22 +487,22 @@ bool VMContext::startScript(int32 func) { pos = ((READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[tmp]) << 1)); } } - + if (pos > _scriptFileSize) { pos = _scriptFileSize; } - + _nextScriptPos = pos; return true; } - + uint32 VMContext::contScript(void) { uint8* script_start = _chunks[kData]._data; assert(script_start); - + uint32 scriptStateAtStart = _scriptState; - + // runs the script while (true) { if ((uint32)_instructionPos > _chunks[kData]._size) { @@ -513,10 +513,10 @@ uint32 VMContext::contScript(void) { _scriptState = kScriptStopped; break; } - + _currentCommand = *(script_start + _instructionPos++); - - // gets out + + // gets out if (_currentCommand & 0x80) { _argument = ((_currentCommand & 0x0F) << 8) | *(script_start + _instructionPos++); _currentCommand &= 0xF0; @@ -524,10 +524,10 @@ uint32 VMContext::contScript(void) { _argument = *(script_start + _instructionPos++); } else if (_currentCommand & 0x20) { _instructionPos++; - + uint16 tmp = *(uint16*)(script_start + _instructionPos); tmp &= 0xFF7F; - + _argument = READ_BE_UINT16(&tmp); _instructionPos += 2; } else { @@ -535,21 +535,21 @@ uint32 VMContext::contScript(void) { // next thing continue; } - + _currentCommand &= 0x1f; - + if (_currentCommand < _numCommands) { CommandProc currentProc = _commands[_currentCommand].proc; (this->*currentProc)(); } else { c1_unknownCommand(); } - + if (_error) { _scriptState = kScriptError; break; } - + if (scriptStateAtStart != _scriptState) { break; } diff --git a/kyra/script.h b/kyra/script.h index 9cfdb48d21..5820a10a08 100644 --- a/kyra/script.h +++ b/kyra/script.h @@ -40,26 +40,26 @@ enum ScriptState { kScriptWaiting = 2, kScriptError = 3 }; - - + + class VMContext { public: VMContext(KyraEngine* engine); ~VMContext() { delete [] _scriptFile; } - + void loadScript(const char* file); - + const char* stringAtIndex(int32 index); - + // TODO: check for 'over'flow - void pushStack(int32 value) { _stack[_stackPos++] = value; } + void pushStack(int32 value) { _stack[_stackPos++] = value; } void registerValue(int32 reg, int32 value) { _registers[reg] = value; } int32 checkReg(int32 reg) { return _registers[reg]; } - + uint32 state(void) { return _scriptState; } - + bool startScript(int32 func); uint32 contScript(void); @@ -67,34 +67,34 @@ protected: KyraEngine* _engine; uint8* _scriptFile; uint32 _scriptFileSize; - + uint32 _scriptState; uint32 _delay; - + int32 _registers[32]; // registers of the interpreter int32 _stack[64]; // our stack - + // TODO: check for 'under'flow int32 popStack(void) { return _stack[--_stackPos]; } int32& topStack(void) { return _stack[_stackPos]; } - + uint32 _returnValue; - + int32 _nextScriptPos; int32 _instructionPos; int32 _stackPos; int32 _tempPos; - + // used by command & opcode procs uint16 _argument; uint8 _currentCommand; uint32 _currentOpcode; - + int32 param(int32 index); const char* paramString(int32 index) { return stringAtIndex(param(index)); } - + bool _error; // used by all command- and opcodefuncs - + enum ScriptChunkTypes { kForm = 0, kEmc2Ordr = 1, @@ -102,13 +102,13 @@ protected: kData = 3, kCountChunkTypes }; - + struct ScriptChunk { uint32 _size; uint8* _data; // by TEXT used for count of texts, by EMC2ODRD it is used for a count of somewhat uint8* _additional; // currently only used for TEXT }; - + ScriptChunk _chunks[kCountChunkTypes]; typedef void (VMContext::*CommandProc)(); @@ -116,18 +116,18 @@ protected: CommandProc proc; const char* desc; }; - + typedef void (VMContext::*OpcodeProc)(); struct OpcodeEntry { OpcodeProc proc; const char* desc; }; - + uint16 _numCommands; const CommandEntry* _commands; uint16 _numOpcodes; const OpcodeEntry* _opcodes; - + protected: // the command procs void c1_goToLine(void); // 0x00 @@ -148,7 +148,7 @@ protected: void c1_negate(void); // 0x10 void c1_evaluate(void); // 0x11 void c1_unknownCommand(void); - + // the opcode procs void o1_0x68(void); // 0x68 void o1_unknownOpcode(void); diff --git a/kyra/script_v1.cpp b/kyra/script_v1.cpp index 5d6124e65f..7cc3bdcf31 100644 --- a/kyra/script_v1.cpp +++ b/kyra/script_v1.cpp @@ -30,7 +30,7 @@ namespace Kyra { void VMContext::c1_unknownCommand(void) { debug("unknown command '0x%x'.", _currentCommand); debug("\targument: '0x%x'", _argument); - + _error = true; } @@ -76,7 +76,7 @@ void VMContext::c1_popRetRec(void) { _scriptState = kScriptStopped; } int32 rec = popStack(); - + _tempPos = (int16)((rec & 0xFFFF0000) >> 16); _instructionPos = (rec & 0x0000FFFF) * 2; } @@ -122,15 +122,15 @@ void VMContext::c1_negate(void) { case 0: topStack() = !topStack(); break; - + case 1: topStack() = -topStack(); break; - + case 2: topStack() = ~topStack(); break; - + default: debug("unkown negate instruction %d", _argument); _error = true; @@ -141,98 +141,98 @@ void VMContext::c1_negate(void) { void VMContext::c1_evaluate(void) { int32 x, y; int32 res = false; - + x = popStack(); y = popStack(); - + switch(_argument) { case 0: res = x && y; break; - + case 1: res = x || y; break; - + case 3: res = x != y; break; - + case 4: res = x < y; break; - + case 5: res = x <= y; break; - + case 6: res = x > y; break; - + case 7: res = x >= y; break; - + case 8: res = x + y; break; - + case 9: res = x - y; break; - + case 10: res = x * y; break; - + case 11: res = x / y; break; - + case 12: res = x >> y; break; - + case 13: res = x << y; break; - + case 14: res = x & y; break; - + case 15: res = x | y; break; - + case 16: res = x % y; break; - + case 17: res = x ^ y; break; - + default: debug("unknown evaluate command"); break; }; - + pushStack(res); } // opcode procs void VMContext::o1_unknownOpcode(void) { _error = true; - + debug("unknown opcode '0x%x'.", _argument); debug("parameters:\n" "Param0: %d\nParam1: %d\nParam2: %d\nParam3: %d\nParam4: %d\nParam5: %d\n" "Param0 as a string: %s\nParam1 as a string: %s\nParam2 as a string: %s\n" "Param3 as a string: %s\nParam4 as a string: %s\nParam5 as a string: %s\n", param(0), param(1), param(2), param(3), param(5), param(5), - paramString(0), paramString(1), paramString(2), paramString(3), + paramString(0), paramString(1), paramString(2), paramString(3), paramString(4), paramString(5)); } diff --git a/kyra/sound.cpp b/kyra/sound.cpp index f4454c0297..495b5f458e 100644 --- a/kyra/sound.cpp +++ b/kyra/sound.cpp @@ -28,22 +28,22 @@ namespace Kyra { _driver = driver; _passThrough = false; _isPlaying = _nativeMT32 = false; - + memset(_channel, 0, sizeof(MidiChannel*) * 16); memset(_channelVolume, 255, sizeof(uint8) * 16); _volume = 0; - + int ret = open(); if (ret != MERR_ALREADY_OPEN && ret != 0) { error("couldn't open midi driver"); } } - + MusicPlayer::~MusicPlayer() { _driver->setTimerCallback(NULL, NULL); close(); } - + void MusicPlayer::setVolume(int volume) { if (volume < 0) volume = 0; @@ -61,7 +61,7 @@ namespace Kyra { } } } - + int MusicPlayer::open() { // Don't ever call open without first setting the output driver! if (!_driver) @@ -80,7 +80,7 @@ namespace Kyra { _driver->close(); _driver = 0; } - + void MusicPlayer::send(uint32 b) { if (_passThrough) { _driver->send(b); @@ -120,28 +120,28 @@ namespace Kyra { break; } } - + void MusicPlayer::playMusic(const char* file) { uint32 size; uint8* data = 0; - + data = (_engine->resManager())->fileData(file, &size); - + if (!data) { warning("couldn't load '%s'", file); return; } - + playMusic(data, size); } - + void MusicPlayer::playMusic(uint8* data, uint32 size) { if (_isPlaying) stopMusic(); - + _parser = MidiParser::createParser_XMIDI(); assert(_parser); - + if (!_parser->loadMusic(data, size)) { warning("Error reading track!"); delete _parser; @@ -164,13 +164,13 @@ namespace Kyra { _parser = NULL; } } - + void MusicPlayer::onTimer(void *refCon) { MusicPlayer *music = (MusicPlayer *)refCon; if (music->_isPlaying) music->_parser->onTimer(); } - + void MusicPlayer::playTrack(uint8 track) { if (_parser) { _isPlaying = true; diff --git a/kyra/sound.h b/kyra/sound.h index edb1aaf68a..cf262515cd 100644 --- a/kyra/sound.h +++ b/kyra/sound.h @@ -30,21 +30,21 @@ namespace Kyra { class MusicPlayer : public MidiDriver { - + public: - + MusicPlayer(MidiDriver* driver, KyraEngine* engine); ~MusicPlayer(); - + void setVolume(int volume); int getVolume() { return _volume; } - + void hasNativeMT32(bool nativeMT32) { _nativeMT32 = nativeMT32; } void playMusic(const char* file); void playMusic(uint8* data, uint32 size); void stopMusic(); - + void playTrack(uint8 track); void setPassThrough(bool b) { _passThrough = b; } @@ -60,11 +60,11 @@ namespace Kyra { //Channel allocation functions MidiChannel *allocateChannel() { return 0; } MidiChannel *getPercussionChannel() { return 0; } - + protected: - + static void onTimer(void *data); - + MidiChannel* _channel[16]; uint8 _channelVolume[16]; MidiDriver* _driver; diff --git a/kyra/wsamovie.cpp b/kyra/wsamovie.cpp index b605513a92..7c8a57abb1 100644 --- a/kyra/wsamovie.cpp +++ b/kyra/wsamovie.cpp @@ -41,10 +41,10 @@ WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { _offsetTable = 0; _prefetchedFrame = 0xFFFE; _buffer = data; - + // I like these Streams .... =) Common::MemoryReadStream datastream(data, size); - + _wsaHeader._numFrames = datastream.readUint16LE(); _wsaHeader._width = datastream.readUint16LE(); _wsaHeader._height = datastream.readUint16LE(); @@ -52,11 +52,11 @@ WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { _wsaHeader._yPos = datastream.readByte(); _wsaHeader._delta = datastream.readUint16LE(); _wsaHeader._type = datastream.readUint16LE(); - + #ifdef DUMP_FILES // TODO: make Linux/BSD conform FILE* wsaheader = fopen("dumps/wsaheader.txt", "w+"); - + if (wsaheader) { for (uint32 pos = 0; pos < sizeof(_wsaHeader); ++pos) fprintf(wsaheader, "%d pos. byte: %d\n", pos + 1, ((uint8*)&_wsaHeader)[pos]); @@ -74,11 +74,11 @@ WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { uint16 tmp = _wsaHeader._delta; _wsaHeader._delta = _wsaHeader._type; _wsaHeader._type = tmp; - + // skip 2 bytes datastream.readUint16LE(); } - + debug("_wsaHeader._numFrames = %d", _wsaHeader._numFrames); debug("_wsaHeader._width = %d", _wsaHeader._width); debug("_wsaHeader._height = %d", _wsaHeader._height); @@ -86,40 +86,40 @@ WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { debug("_wsaHeader._yPos = %d", _wsaHeader._yPos); debug("_wsaHeader._delta = %d", _wsaHeader._delta); debug("_wsaHeader._type = %d", _wsaHeader._type); - + // check for version if (_wsaHeader._type) { error("loading a WSA version 2 with the WSA version 1 loader"); } - + uint16 offsetAdd = 0; - + // checks now for own palette if (_wsaHeader._type % 2) { // don't now if this will work right, because a few lines before we use // _wsaHeader._type for detect the version of the WSA movie, // but this code was from FreeKyra Tools so I think it will work - + // if this is a packed palette we have a problem :) offsetAdd = 768 /* 0x300 */; } - + // last frame seems every time to be a empty one _frameCount = _wsaHeader._numFrames - 1; _offsetTable = new uint32[_wsaHeader._numFrames + 2]; assert(_offsetTable); - + // loads the offset table for (uint32 tmp = 0; tmp < (uint32)_wsaHeader._numFrames + 2; ++tmp) { _offsetTable[tmp] = datastream.readUint32LE() + offsetAdd; } - + if (offsetAdd) { uint8* palbuffer = new uint8[offsetAdd]; assert(palbuffer); - + datastream.read(palbuffer, offsetAdd); - + _ownPalette = new Palette(palbuffer, offsetAdd); assert(_ownPalette); } @@ -128,18 +128,18 @@ WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { // LordHoto: What is the 'default' value? 0? _transparency = -1; } - + WSAMovieV1::~WSAMovieV1() { delete [] _buffer; delete [] _offsetTable; delete [] _currentFrame; delete _ownPalette; } - + const uint8* WSAMovieV1::loadFrame(uint16 frame, uint16* width, uint16* height) { if (width) *width = _wsaHeader._width; if (height) *height = _wsaHeader._height; - + if (frame == _prefetchedFrame) { return _currentFrame; } else { @@ -148,14 +148,14 @@ const uint8* WSAMovieV1::loadFrame(uint16 frame, uint16* width, uint16* height) assert(_currentFrame); memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); } - + if (frame >= _wsaHeader._numFrames) return 0; - + uint8* frameData = 0; static uint8 image40[64000]; // I think this will crash on Plam OS :) memset(image40, 0, ARRAYSIZE(image40)); - + if (frame == _prefetchedFrame + 1) { frameData = _buffer + _offsetTable[frame]; Compression::decode80(frameData, image40); @@ -166,7 +166,7 @@ const uint8* WSAMovieV1::loadFrame(uint16 frame, uint16* width, uint16* height) } else { memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); } - + for (uint32 i = 0; i <= frame; ++i) { frameData = _buffer + _offsetTable[i]; @@ -174,14 +174,14 @@ const uint8* WSAMovieV1::loadFrame(uint16 frame, uint16* width, uint16* height) Compression::decode40(image40, _currentFrame); } } - + _prefetchedFrame = frame; return _currentFrame; } - + return 0; } - + void WSAMovieV1::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame) { if (!loadFrame(frame, 0, 0)) return; @@ -189,10 +189,10 @@ void WSAMovieV1::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight uint8* src = _currentFrame; uint8* dst = &plane[_wsaHeader._yPos * planepitch + _wsaHeader._xPos]; uint32 copysize = planepitch - _wsaHeader._xPos; - + if (copysize > _wsaHeader._width) copysize = _wsaHeader._width; - + if (_transparency == -1) { for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < planeheight; ++y_) { memcpy(dst, src, copysize * sizeof(uint8)); @@ -209,16 +209,16 @@ void WSAMovieV1::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight *dst++ = *src++; } } - + src += _wsaHeader._width - copysize; dst += planepitch - copysize; } } } - + void WSAMovieV1::setImageBackground(uint8* plane, uint16 planepitch, uint16 height) { assert(plane); - + _background = plane; _backWidth = planepitch; _backHeight = height; @@ -226,38 +226,38 @@ void WSAMovieV1::setImageBackground(uint8* plane, uint16 planepitch, uint16 heig _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; assert(_currentFrame); } - + memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); - + uint8* src = &plane[_wsaHeader._yPos * planepitch + _wsaHeader._xPos]; uint8* dst = _currentFrame; uint32 copysize = planepitch - _wsaHeader._xPos; - + if (copysize > _wsaHeader._width) copysize = _wsaHeader._width; - + // now copy the rect of the plane for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < height; ++y_) { memcpy(dst, src, copysize * sizeof(uint8)); dst += _wsaHeader._width; src += planepitch; } - + for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < height; ++y_) { for (uint16 x = 0; x < _wsaHeader._width; ++x) { _currentFrame[y_ * _wsaHeader._width + x] ^= 0; } } - + _prefetchedFrame = 0xFFFE; } - + // Kyrandia 2+ Movies WSAMovieV2::WSAMovieV2(uint8* data, uint32 size) { if (!data) { error("resource created without data"); } - + _background = 0; _currentFrame = 0; _ownPalette = 0; @@ -265,55 +265,55 @@ WSAMovieV2::WSAMovieV2(uint8* data, uint32 size) { _prefetchedFrame = 0xFFFE; _looping = false; _buffer = data; - + // I like these Streams .... =) Common::MemoryReadStream datastream(data, size); - + datastream.read(&_wsaHeader, sizeof(_wsaHeader)); - + // check for version if (!_wsaHeader._type) { error("loading a WSA version 1 with the WSA version 2 loader"); } - + uint16 offsetAdd = 0; - + // checks now for own palette if (_wsaHeader._type % 2) { // don't now if this will work right, because a few lines before we use // _wsaHeader._type for detect the version of the WSA movie, // but this code was from FreeKyra Tools so I think it will work - + // if this is a packed palette we have a problem :) offsetAdd = 768 /* 0x300 */; } - + _offsetTable = new uint32[_wsaHeader._numFrames + 2]; assert(_offsetTable); - + // loads the offset table for (uint32 tmp = 0; tmp < (uint32)_wsaHeader._numFrames + 2; ++tmp) { _offsetTable[tmp] = datastream.readUint32LE() + offsetAdd; } - + if (offsetAdd) { uint8* palbuffer = new uint8[offsetAdd]; assert(palbuffer); - + datastream.read(palbuffer, offsetAdd); - + _ownPalette = new Palette(palbuffer, offsetAdd); assert(_ownPalette); } - + if (_offsetTable[_wsaHeader._numFrames + 1] - offsetAdd) { ++_wsaHeader._numFrames; _looping = true; } - + _frameCount = _wsaHeader._numFrames; } - + WSAMovieV2::~WSAMovieV2() { delete [] _buffer; delete [] _offsetTable; @@ -324,7 +324,7 @@ WSAMovieV2::~WSAMovieV2() { const uint8* WSAMovieV2::loadFrame(uint16 frame, uint16* width, uint16* height) { if (width) *width = _wsaHeader._width; if (height) *height = _wsaHeader._height; - + if (frame == _prefetchedFrame) { return _currentFrame; } else { @@ -333,14 +333,14 @@ const uint8* WSAMovieV2::loadFrame(uint16 frame, uint16* width, uint16* height) assert(_currentFrame); memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); } - + if (frame >= _wsaHeader._numFrames) return 0; - + uint8* frameData = 0; static uint8 image40[64000]; // I think this will crash on Plam OS :) memset(image40, 0, ARRAYSIZE(image40)); - + if (frame == _prefetchedFrame + 1) { frameData = _buffer + _offsetTable[frame]; Compression::decode80(frameData, image40); @@ -351,7 +351,7 @@ const uint8* WSAMovieV2::loadFrame(uint16 frame, uint16* width, uint16* height) } else { memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); } - + for (uint32 i = 0; i <= frame; ++i) { frameData = _buffer + _offsetTable[i]; @@ -359,25 +359,25 @@ const uint8* WSAMovieV2::loadFrame(uint16 frame, uint16* width, uint16* height) Compression::decode40(image40, _currentFrame); } } - + _prefetchedFrame = frame; return _currentFrame; } - + return 0; } - + void WSAMovieV2::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame) { if (!loadFrame(frame, 0, 0)) return; - + uint8* src = _currentFrame; uint8* dst = &plane[_wsaHeader._yPos * planepitch + _wsaHeader._xPos]; uint32 copysize = planepitch - _wsaHeader._xPos; - + if (copysize > _wsaHeader._width) copysize = _wsaHeader._width; - + if (_transparency == -1) { for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < planeheight; ++y_) { memcpy(dst, src, copysize * sizeof(uint8)); @@ -394,46 +394,46 @@ void WSAMovieV2::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight *dst++ = *src++; } } - + src += _wsaHeader._width - copysize; dst += planepitch - copysize; } } } - + void WSAMovieV2::setImageBackground(uint8* plane, uint16 planepitch, uint16 height) { assert(plane); - + _background = plane; _backWidth = planepitch; _backHeight = height; - + if (!_currentFrame) { _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; assert(_currentFrame); } - + memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); - + uint8* src = &plane[_wsaHeader._yPos * planepitch + _wsaHeader._xPos]; uint8* dst = _currentFrame; uint32 copysize = planepitch - _wsaHeader._xPos; - + if (copysize > _wsaHeader._width) copysize = _wsaHeader._width; - + // now copy the rect of the plane for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < height; ++y_) { memcpy(dst, src, copysize * sizeof(uint8)); dst += _wsaHeader._width; src += planepitch; } - + for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < height; ++y_) { for (uint16 x = 0; x < _wsaHeader._width; ++x) { _currentFrame[y_ * _wsaHeader._width + x] ^= 0; } } - + _prefetchedFrame = 0xFFFE; } } // end of namespace Kyra diff --git a/kyra/wsamovie.h b/kyra/wsamovie.h index 34737773a7..34de2e540d 100644 --- a/kyra/wsamovie.h +++ b/kyra/wsamovie.h @@ -28,26 +28,26 @@ namespace Kyra { // a generic movie class Movie { - + public: - + virtual ~Movie() { _transparency = -1; _ownPalette = 0; _frameCount = 0; } - + virtual void renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame) = 0; virtual const uint8* loadFrame(uint16 frame, uint16* width = 0, uint16* height = 0) = 0; virtual uint16 countFrames(void) { return _frameCount; } - + // could be deleted(not imdiantly maybe it's needed sometime) virtual void transparency(int16 color) { _transparency = color; } virtual void position(uint16 x, uint16 y) = 0; - + virtual bool hasPalette(void) { return (_ownPalette != 0); } virtual Palette* palette(void) { return _ownPalette; } - + virtual bool looping(void) { return false; } - virtual uint32 frameChange(void) { return 100; } + virtual uint32 frameChange(void) { return 100; } virtual void setImageBackground(uint8* plane, uint16 planepitch, uint16 height) {}; - + protected: int16 _transparency; uint16 _frameCount; @@ -56,22 +56,22 @@ protected: // movie format for Kyrandia 1 class WSAMovieV1 : public Movie { - + public: - + WSAMovieV1(uint8* data, uint32 size, uint8 gameid); ~WSAMovieV1(); - + void renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame); const uint8* loadFrame(uint16 frame, uint16* width, uint16* height); void setImageBackground(uint8* plane, uint16 planepitch, uint16 height); - + void position(uint16 x, uint16 y) { _wsaHeader._xPos = x; _wsaHeader._yPos = y; } protected: - + uint8* _buffer; - -#pragma START_PACK_STRUCTS + +#pragma START_PACK_STRUCTS struct WSAHeader { uint16 _numFrames; // All right uint16 _width; // All right @@ -84,31 +84,31 @@ protected: #pragma END_PACK_STRUCTS uint32* _offsetTable; - + uint8* _currentFrame; uint16 _prefetchedFrame; - + uint8* _background; // only a pointer to the screen uint16 _backWidth, _backHeight; }; - + // movie format for Kyrandia 2+ class WSAMovieV2 : public Movie { - + public: WSAMovieV2(uint8* data, uint32 size); ~WSAMovieV2(); - + void renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame); const uint8* loadFrame(uint16 frame, uint16* width, uint16* height); void setImageBackground(uint8* plane, uint16 planepitch, uint16 height); - + void position(uint16 x, uint16 y) { _wsaHeader._xPos = x; _wsaHeader._yPos = y; } bool looping(void) { return _looping; } protected: - + uint8* _buffer; - + struct WSAHeader { uint16 _numFrames; // All right uint16 _width; // should be right @@ -118,15 +118,15 @@ protected: uint16 _delta; // could be wrong uint16 _type; // should be right } GCC_PACK _wsaHeader; - + uint32* _offsetTable; - + uint8* _currentFrame; uint16 _prefetchedFrame; - + uint8* _background; // only a pointer to the screen uint16 _backWidth, _backHeight; - + bool _looping; }; } // end of namespace Kyra |