diff options
| author | Eugene Sandulenko | 2004-11-14 20:11:22 +0000 |
|---|---|---|
| committer | Eugene Sandulenko | 2004-11-14 20:11:22 +0000 |
| commit | ddda67753e012a2946403933f57115b37e796bf8 (patch) | |
| tree | bab4ebf24cb0e9cb03082658e5986e32a5fc0d79 /kyra | |
| parent | 0cfd573951c2cdd886cea650c43f0c4406e7fa94 (diff) | |
| download | scummvm-rg350-ddda67753e012a2946403933f57115b37e796bf8.tar.gz scummvm-rg350-ddda67753e012a2946403933f57115b37e796bf8.tar.bz2 scummvm-rg350-ddda67753e012a2946403933f57115b37e796bf8.zip | |
Patch #1066256. Mostly indentation fixes and some debug messages removed.
svn-id: r15811
Diffstat (limited to 'kyra')
| -rw-r--r-- | kyra/codecs.h | 16 | ||||
| -rw-r--r-- | kyra/cpsimage.cpp | 248 | ||||
| -rw-r--r-- | kyra/font.cpp | 492 | ||||
| -rw-r--r-- | kyra/kyra.cpp | 4 | ||||
| -rw-r--r-- | kyra/kyra.h | 12 | ||||
| -rw-r--r-- | kyra/palette.cpp | 80 | ||||
| -rw-r--r-- | kyra/resource.cpp | 379 | ||||
| -rw-r--r-- | kyra/resource.h | 232 | ||||
| -rw-r--r-- | kyra/script.cpp | 1003 | ||||
| -rw-r--r-- | kyra/script.h | 241 | ||||
| -rw-r--r-- | kyra/script_v1.cpp | 384 | ||||
| -rw-r--r-- | kyra/wsamovie.cpp | 664 | ||||
| -rw-r--r-- | kyra/wsamovie.h | 166 |
13 files changed, 1959 insertions, 1962 deletions
diff --git a/kyra/codecs.h b/kyra/codecs.h index a7b9f11338..93a28312d0 100644 --- a/kyra/codecs.h +++ b/kyra/codecs.h @@ -29,14 +29,14 @@ #include "common/scummsys.h" namespace Kyra { - class Compression - { - public: - static int decode80(const uint8* image_in, uint8* image_out); - static int decode40(const uint8* image_in, uint8* image_out); - static int decode3(const uint8* image_in, uint8* image_out, int s); - static int decode2(const uint8* s, uint8* d, int cb_s); - }; +class Compression +{ +public: + static int decode80(const uint8* image_in, uint8* image_out); + static int decode40(const uint8* image_in, uint8* image_out); + static int decode3(const uint8* image_in, uint8* image_out, int s); + static int decode2(const uint8* s, uint8* d, int cb_s); +}; } // end of namespace Kyra #endif diff --git a/kyra/cpsimage.cpp b/kyra/cpsimage.cpp index bb50c0a916..479961efb3 100644 --- a/kyra/cpsimage.cpp +++ b/kyra/cpsimage.cpp @@ -27,159 +27,159 @@ namespace Kyra { - struct CPSResource { - uint32 size; - uint16 width; - }; +struct CPSResource { + uint32 size; + uint16 width; +}; - static const CPSResource CPSResourceTable[] = { - { 64000, 320 }, { 7740, 180 }, { 46080, 320 }, { 0, 0 } - }; +static const CPSResource CPSResourceTable[] = { + { 64000, 320 }, { 7740, 180 }, { 46080, 320 }, { 0, 0 } +}; - static int16 getWidthFromCPSRes(uint32 size) { - int16 c = 0; - - for (; CPSResourceTable[c].size; ++c) { - if (CPSResourceTable[c].size == size) - return CPSResourceTable[c].width; - } - - return -1; +static int16 getWidthFromCPSRes(uint32 size) { + int16 c = 0; + + for (; CPSResourceTable[c].size; ++c) { + if (CPSResourceTable[c].size == size) + return CPSResourceTable[c].width; } - CPSImage::CPSImage(uint8* buffer, uint32 size) { - if (!buffer) { - error("resource created without data"); - } - _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(); + return -1; +} + +CPSImage::CPSImage(uint8* buffer, uint32 size) { + if (!buffer) { + error("resource created without data"); + } + _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); + // lets check a bit + if(_cpsHeader._pal == 0x3000000) { + // if this was a compressed palette you should have strange graphics - bufferstream.read(palbuffer, 768 * sizeof(uint8)); - - _ownPalette = new Palette(palbuffer, 768); - assert(palbuffer); - } + uint8* palbuffer = new uint8[768]; + assert(palbuffer); - _image = new uint8[_cpsHeader._imagesize]; - assert(_image); + 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); + uint8* imagebuffer = &buffer[bufferstream.pos()]; + assert(imagebuffer); - if(_cpsHeader._format == 4) { - Compression::decode80(imagebuffer, _image); - } else if(_cpsHeader._format == 3) { - Compression::decode3(imagebuffer, _image, _cpsHeader._imagesize); - } else { - error("unknown CPS format %d", _cpsHeader._format); - } + if(_cpsHeader._format == 4) { + Compression::decode80(imagebuffer, _image); + } else if(_cpsHeader._format == 3) { + Compression::decode3(imagebuffer, _image, _cpsHeader._imagesize); + } else { + error("unknown CPS format %d", _cpsHeader._format); + } - int16 width = getWidthFromCPSRes(_cpsHeader._imagesize); + int16 width = getWidthFromCPSRes(_cpsHeader._imagesize); - if(width == -1) { - warning("unknown CPS width(imagesize: %d)", _cpsHeader._imagesize); - delete [] buffer; - return; - } + if(width == -1) { + warning("unknown CPS width(imagesize: %d)", _cpsHeader._imagesize); + delete [] buffer; + return; + } - _width = (uint16)width; - _height = _cpsHeader._imagesize / _width; + _width = (uint16)width; + _height = _cpsHeader._imagesize / _width; - _transparency = -1; + _transparency = -1; - delete [] buffer; - } + delete [] buffer; +} - CPSImage::~CPSImage() { - delete [] _image; - delete _ownPalette; - } +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; - 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_) { + memcpy(dst, src, copysize * sizeof(uint8)); + dst += planepitch; + src += _width; + } - if (copysize > _width) - copysize = _width; + } else { + // oh no! we have transparency so we have a very slow copy :/ - if (_transparency == -1) { - // 'fast' blitting - for (uint16 y_ = 0; y_ < _height && y + y_ < planeheight; ++y_) { - memcpy(dst, src, copysize * sizeof(uint8)); - 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) { - ++dst; - ++src; - } else { - *dst++ = *src++; - } + for (uint16 yadd = 0; yadd < _height; ++yadd) { + for (uint16 xadd = 0; xadd < copysize; ++xadd) { + if (*src == _transparency) { + ++dst; + ++src; + } else { + *dst++ = *src++; } - - src += _width - copysize; - dst += planepitch - copysize; } + + 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; - 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 (srcwidth > _width) - srcwidth = _width; + if (_transparency == -1) { + // 'fast' blitting + for (uint16 y_ = 0; y_ < srcheight && y + y_ < planeheight; ++y_) { + memcpy(dst, src, copysize * sizeof(uint8)); + dst += planepitch; + src += _width; + } - if (copysize > srcwidth) - copysize = srcwidth; + } else { + // oh no! we have transparency so we have a very slow copy :/ - if (_transparency == -1) { - // 'fast' blitting - for (uint16 y_ = 0; y_ < srcheight && y + y_ < planeheight; ++y_) { - memcpy(dst, src, copysize * sizeof(uint8)); - 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) { - ++dst; - ++src; - } else { - *dst++ = *src++; - } + for (uint16 yadd = 0; yadd < srcheight; ++yadd) { + for (uint16 xadd = 0; xadd < copysize; ++xadd) { + if (*src == _transparency) { + ++dst; + ++src; + } else { + *dst++ = *src++; } - - dst += planepitch - copysize; - src += _width - copysize; } + + dst += planepitch - copysize; + src += _width - copysize; } } +} } // end of namespace Kyra diff --git a/kyra/font.cpp b/kyra/font.cpp index 01428f1442..6a5b44c629 100644 --- a/kyra/font.cpp +++ b/kyra/font.cpp @@ -29,301 +29,299 @@ #endif namespace Kyra { - const uint16 FontHeader_Magic1 = 0x0500; - const uint16 FontHeader_Magic2 = 0x000e; - const uint16 FontHeader_Magic3 = 0x0014; - - Font::Font(uint8* buffer, uint32 size) { - if (!buffer) { - error("resource created without data"); - } - - _buffer = buffer; - - Common::MemoryReadStream bufferstream(buffer, size); - - bufferstream.read(&_fontHeader, sizeof(_fontHeader)); - - // tests for the magic values - if(_fontHeader._magic1 != FontHeader_Magic1 || _fontHeader._magic2 != FontHeader_Magic2 || - _fontHeader._magic3 != FontHeader_Magic3) { - error("magic vars in the fontheader are corrupt\n" - "_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()); +const uint16 FontHeader_Magic1 = 0x0500; +const uint16 FontHeader_Magic2 = 0x000e; +const uint16 FontHeader_Magic3 = 0x0014; - // This value seems to be a version or language variable - // Known Values - // ------------ - // Russian Floppy: 0x1010 - // German Floppy and English CD: 0x1011 - // Kyrandia 2 should be 0x1012 - debug("_version = 0x%x", _fontHeader._version); - - delete [] _buffer; - _buffer = 0; - _offsetTable = 0; - _charHeight = 0; - _charWidth = 0; - _charBits = 0; +Font::Font(uint8* buffer, uint32 size) { + if (!buffer) { + error("resource created without data"); } - - Font::~Font() { + _buffer = buffer; + + Common::MemoryReadStream bufferstream(buffer, size); + + bufferstream.read(&_fontHeader, sizeof(_fontHeader)); + + // tests for the magic values + if(_fontHeader._magic1 != FontHeader_Magic1 || _fontHeader._magic2 != FontHeader_Magic2 || + _fontHeader._magic3 != FontHeader_Magic3) { + error("magic vars in the fontheader are corrupt\n" + "_magic1 = 0x%x, _magic2 = 0x%x, _magic3 = 0x%x", + _fontHeader._magic1, _fontHeader._magic2, _fontHeader._magic3); } - uint32 Font::getStringWidth(const char* string, char terminator) { - uint32 strsize; - - for (strsize = 0; string[strsize] != terminator && string[strsize] != '\0'; ++strsize) - ; + // 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()); + + // This value seems to be a version or language variable + // Known Values + // ------------ + // Russian Floppy: 0x1010 + // German Floppy and English/German CD: 0x1011 + debug("Font::_version = 0x%x", _fontHeader._version); + + delete [] _buffer; + _buffer = 0; + _offsetTable = 0; + _charHeight = 0; + _charWidth = 0; + _charBits = 0; +} + +Font::~Font() { + // FIXME: Release memory of the prerendered chars +} + +uint32 Font::getStringWidth(const char* string, char terminator) { + uint32 strsize; - uint32 stringwidth = 0; + for (strsize = 0; string[strsize] != terminator && string[strsize] != '\0'; ++strsize) + ; - for (uint32 pos = 0; pos < strsize; ++pos) { - stringwidth += _preRenderedChars[string[pos]].width; - } + uint32 stringwidth = 0; - return stringwidth; + for (uint32 pos = 0; pos < strsize; ++pos) { + stringwidth += _preRenderedChars[string[pos]].width; } - - 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; - } + return stringwidth; +} - // 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]; - } +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 +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)) + ; - // Move this to Font declaration? - struct WordChunk { - const char* _string; - uint32 _size; - }; + ++(*size); + + return &string[startpos]; +} - void Font::drawStringToPlane(const char* string, - uint8* plane, uint16 planewidth, uint16 planeheight, - uint16 x, uint16 y, uint8 color) { +// Move this to Font declaration? +struct WordChunk { + const char* _string; + uint32 _size; +}; + +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); + // 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; + + words.push_back(newchunk); + + if (lastPos >= strlgt) + break; + } - while (true) { - WordChunk newchunk; - newchunk._string = getNextWord(&string[lastPos], &lastSize); - newchunk._size = lastSize; - - lastPos += lastSize; - - words.push_back(newchunk); + 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, ' '); - if (lastPos >= strlgt) - break; + // adjust x position + if (current_x + lastSize >= planewidth) { + // hmm lets move it a bit to the left + if (current_x == x && (int16)planewidth - (int16)lastSize >= 0) { + current_x = planewidth - lastSize; + } else { + current_x = x; + 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; + } } - uint16 current_x = x, current_y = y; - uint8 heighest = 0; - - const uint8* src = 0; - uint8 width = 0, height = 0, heightadd = 0; + // TODO: maybe test if current_y >= planeheight ? - // 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 - if (current_x == x && (int16)planewidth - (int16)lastSize >= 0) { - current_x = planewidth - lastSize; - } else { - current_x = x; - 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; - } - } + // 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); - // TODO: maybe test if current_y >= planeheight ? + // lets draw our char + drawCharToPlane(src, color, width, height, plane, planewidth, planeheight, current_x, current_y + heightadd); - // 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); - } + 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; - - // blit them to the screen - for (uint8 yadd = 0; yadd < height; ++yadd) { - for (uint8 xadd = 0; xadd < width; ++xadd) { - 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; - }; +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; + + // blit them to the screen + for (uint8 yadd = 0; yadd < height; ++yadd) { + for (uint8 xadd = 0; xadd < width; ++xadd) { + switch(*src) { + case 1: + plane[(y + yadd) * planewidth + x + xadd] = color; + break; - ++src; - } + 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; +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.c = new uint8[(_charHeight[currentChar] >> 8) * _charWidth[currentChar]]; + assert(newChar.c); + memset(newChar.c, 0, sizeof(uint8) * (_charHeight[currentChar] >> 8) * _charWidth[currentChar]); + newChar.height = (_charHeight[currentChar] >> 8); + newChar.width = _charWidth[currentChar]; + newChar.heightadd = _charHeight[currentChar] & 0xFF; + + uint8* src = _buffer + _offsetTable[currentChar]; + uint8* dst = &newChar.c[0]; + uint8 index = 0; - for (; currentOffset < startOffset; ++currentChar, currentOffset += sizeof(uint16)) { - // lets prerender the char :) - - PreRenderedChar newChar; - - newChar.c = new uint8[(_charHeight[currentChar] >> 8) * _charWidth[currentChar]]; - assert(newChar.c); - memset(newChar.c, 0, sizeof(uint8) * (_charHeight[currentChar] >> 8) * _charWidth[currentChar]); - newChar.height = (_charHeight[currentChar] >> 8); - newChar.width = _charWidth[currentChar]; - newChar.heightadd = _charHeight[currentChar] & 0xFF; - - uint8* src = _buffer + _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); + 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) { - if (xadd % 2) { - index = ((*src) & 0xF0) >> 4; - ++src; - } else { - index = (*src) & 0x0F; - } - - switch(index) { - case 1: + // prerender the char + for (uint8 yadd = 0; yadd < newChar.height; ++yadd) { + for (uint8 xadd = 0; xadd < newChar.width; ++xadd) { + if (xadd % 2) { + index = ((*src) & 0xF0) >> 4; + ++src; + } else { + index = (*src) & 0x0F; + } + + switch(index) { + case 1: #ifdef DUMP_FILES - fprintf(dump, "#"); + fprintf(dump, "#"); #endif - dst[yadd * newChar.width + xadd] = 1; - break; - - case 2: + dst[yadd * newChar.width + xadd] = 1; + break; + + case 2: #ifdef DUMP_FILES - fprintf(dump, "$"); + fprintf(dump, "$"); #endif - dst[yadd * newChar.width + xadd] = 2; - break; - - case 3: + dst[yadd * newChar.width + xadd] = 2; + break; + + case 3: #ifdef DUMP_FILES - fprintf(dump, "§"); + fprintf(dump, "§"); #endif - dst[yadd * newChar.width + xadd] = 3; - break; - - default: + dst[yadd * newChar.width + xadd] = 3; + break; + + default: #ifdef DUMP_FILES - fprintf(dump, "%d", index); + fprintf(dump, "%d", index); #endif - break; - }; - } + break; + }; + } - if (newChar.width % 2) { - ++src; - } + if (newChar.width % 2) { + ++src; + } #ifdef DUMP_FILES - fprintf(dump, "\n"); + fprintf(dump, "\n"); #endif - } + } #ifdef DUMP_FILES - fprintf(dump, "\nThis is the created map:\n"); - // now print the whole thing again - for (uint8 yadd = 0; yadd < newChar.height; ++yadd) { - for (uint8 xadd = 0; xadd < newChar.width; ++xadd) { - fprintf(dump, "%d", dst[yadd * newChar.width + xadd]); - } - fprintf(dump, "\n"); + fprintf(dump, "\nThis is the created map:\n"); + // now print the whole thing again + for (uint8 yadd = 0; yadd < newChar.height; ++yadd) { + for (uint8 xadd = 0; xadd < newChar.width; ++xadd) { + fprintf(dump, "%d", dst[yadd * newChar.width + xadd]); } - fclose(dump); + fprintf(dump, "\n"); + } + fclose(dump); #endif - - _preRenderedChars[currentChar] = newChar; - - if (currentChar == 255) { - break; - } + + _preRenderedChars[currentChar] = newChar; + + if (currentChar == 255) { + break; } } +} } // end of namespace Kyra diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp index 94831b98d3..440c1bced1 100644 --- a/kyra/kyra.cpp +++ b/kyra/kyra.cpp @@ -52,7 +52,7 @@ static const KyraGameSettings kyra_settings[] = { {"kyra1cd", "Legend of Kyrandia (CD)", GF_TALKIE | GF_KYRA1, "CHAPTER1.VRM"}, {"kyra2", "Hand of Fate (Floppy)", GF_FLOPPY | GF_KYRA2, 0 }, {"kyra2cd", "Hand of Fate (CD)", GF_TALKIE | GF_KYRA2, "AUDIO.PAK"}, - {"kyra3", "Malcom's Revenge", GF_TALKIE | GF_KYRA3, "K3INTRO0.VQA"}, + {"kyra3", "Malcolm's Revenge", GF_TALKIE | GF_KYRA3, "K3INTRO0.VQA"}, {0, 0, 0, 0} }; @@ -188,7 +188,7 @@ void KyraEngine::errorString(const char *buf1, char *buf2) { void KyraEngine::go() { warning("Kyrandia Engine ::go()"); // starts the init script - /*if (!_currentScript->startScript(kSetupScene)) { +/* if (!_currentScript->startScript(kSetupScene)) { error("couldn't init '_STARTUP.EMC' script"); } diff --git a/kyra/kyra.h b/kyra/kyra.h index b0dfc34501..15564bffee 100644 --- a/kyra/kyra.h +++ b/kyra/kyra.h @@ -45,12 +45,12 @@ enum { }; namespace Kyra { - class Resourcemanager; - class CPSImage; - class Font; - class Palette; - class VMContext; - class MusicPlayer; +class Resourcemanager; +class CPSImage; +class Font; +class Palette; +class VMContext; +class MusicPlayer; class KyraEngine : public Engine { public: diff --git a/kyra/palette.cpp b/kyra/palette.cpp index 8087672e6e..3e66a10b99 100644 --- a/kyra/palette.cpp +++ b/kyra/palette.cpp @@ -27,54 +27,54 @@ namespace Kyra { - Palette::Palette(uint8* data, uint32 size) { - if (!data) { - error("resource created without data"); - } +Palette::Palette(uint8* data, uint32 size) { + if (!data) { + error("resource created without data"); + } + + if (size != 768) { + Common::MemoryReadStream datastream(data, size); - 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; - } + datastream.readSint32LE(); + int imageSize = datastream.readSint16LE(); - // 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]; + if (imageSize != 768) { + error("decompresed palette is not 768 byte long!"); + } - uint8* currentpossrc = &data[0]; - uint8* currentposdst = &_palette[0]; + // lets uncompress this palette :) + _palette = new uint8[imageSize]; + assert(_palette); - // creates the original pallette (only first 6 bits are used) - for (uint32 i = 0; i < 256; i++) { - currentposdst[0] = currentpossrc[0] << 2; - currentposdst[1] = currentpossrc[1] << 2; - currentposdst[2] = currentpossrc[2] << 2; - currentpossrc += 3; - currentposdst += 4; + // 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; + currentposdst[1] = currentpossrc[1] << 2; + currentposdst[2] = currentpossrc[2] << 2; + currentpossrc += 3; + currentposdst += 4; + } + + delete [] data; +} } // end of namespace Kyra diff --git a/kyra/resource.cpp b/kyra/resource.cpp index 37b563f457..84de1e5d1a 100644 --- a/kyra/resource.cpp +++ b/kyra/resource.cpp @@ -27,242 +27,241 @@ #include "script.h" namespace Kyra { - Resourcemanager::Resourcemanager(KyraEngine* engine) { - _engine = engine; +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 - static const char* kyra1Filelist[] = { - "A_E.PAK", "DAT.PAK", "F_L.PAK", "MAP_5.PAK", "MSC.PAK", "M_S.PAK", - "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", - "EXTHEAL.PAK", "FORESTB.PAK", "GEMCUT.PAK", "INTRO2.PAK", "LIBRARY.PAK", "PLATEAU.PAK", "SPRING.PAK", - "WISE.PAK", "ALGAE.PAK", "BURN.PAK", "DARMS.PAK", "EXTPOT.PAK", "FORESTC.PAK", "GENCAVB.PAK", - "INTRO3.PAK", "MISC.PAK", "PLTCAVE.PAK", "SQUARE.PAK", "XEDGE.PAK", "ALTAR.PAK", "CASTLE.PAK", - "DEAD.PAK", "EXTSPEL.PAK", "FOUNTN.PAK", "GENHALL.PAK", "INTRO4.PAK", "MIX.PAK", "POTION.PAK", - "STARTUP.PAK", "XEDGEB.PAK", "ARCH.PAK", "CATACOM.PAK", "DNSTAIR.PAK", "FALLS.PAK", "FOYER.PAK", - "GEN_CAV.PAK", "KITCHEN.PAK", "MOONCAV.PAK", "RUBY.PAK", "STUMP.PAK", "XEDGEC.PAK", "BALCONY.PAK", - "CAVE.PAK", "DRAGON.PAK", "FESTSTH.PAK", "FSOUTH.PAK", "GLADE.PAK", "KYRAGEM.PAK", "NCLIFF.PAK", - "SICKWIL.PAK", "TEMPLE.PAK", "XMI.PAK", "BELROOM.PAK", "CAVEB.PAK", "EDGE.PAK", "FGOWEST.PAK", - "FSOUTHB.PAK", "GRAVE.PAK", "LAGOON.PAK", "NCLIFFB.PAK", "SND.PAK", "TRUNK.PAK", "ZROCK.PAK", - "BONKBG.PAK", "CGATE.PAK", "EDGEB.PAK", "FINALE.PAK", "FWSTSTH.PAK", "GRTHALL.PAK", "LANDING.PAK", - "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 - }; + // 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 + static const char* kyra1Filelist[] = { + "A_E.PAK", "DAT.PAK", "F_L.PAK", "MAP_5.PAK", "MSC.PAK", "M_S.PAK", + "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", + "EXTHEAL.PAK", "FORESTB.PAK", "GEMCUT.PAK", "INTRO2.PAK", "LIBRARY.PAK", "PLATEAU.PAK", "SPRING.PAK", + "WISE.PAK", "ALGAE.PAK", "BURN.PAK", "DARMS.PAK", "EXTPOT.PAK", "FORESTC.PAK", "GENCAVB.PAK", + "INTRO3.PAK", "MISC.PAK", "PLTCAVE.PAK", "SQUARE.PAK", "XEDGE.PAK", "ALTAR.PAK", "CASTLE.PAK", + "DEAD.PAK", "EXTSPEL.PAK", "FOUNTN.PAK", "GENHALL.PAK", "INTRO4.PAK", "MIX.PAK", "POTION.PAK", + "STARTUP.PAK", "XEDGEB.PAK", "ARCH.PAK", "CATACOM.PAK", "DNSTAIR.PAK", "FALLS.PAK", "FOYER.PAK", + "GEN_CAV.PAK", "KITCHEN.PAK", "MOONCAV.PAK", "RUBY.PAK", "STUMP.PAK", "XEDGEC.PAK", "BALCONY.PAK", + "CAVE.PAK", "DRAGON.PAK", "FESTSTH.PAK", "FSOUTH.PAK", "GLADE.PAK", "KYRAGEM.PAK", "NCLIFF.PAK", + "SICKWIL.PAK", "TEMPLE.PAK", "XMI.PAK", "BELROOM.PAK", "CAVEB.PAK", "EDGE.PAK", "FGOWEST.PAK", + "FSOUTHB.PAK", "GRAVE.PAK", "LAGOON.PAK", "NCLIFFB.PAK", "SND.PAK", "TRUNK.PAK", "ZROCK.PAK", + "BONKBG.PAK", "CGATE.PAK", "EDGEB.PAK", "FINALE.PAK", "FWSTSTH.PAK", "GRTHALL.PAK", "LANDING.PAK", + "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; + const char** usedFilelist = 0; - if (_engine->game() == KYRA1) - usedFilelist = kyra1Filelist; - else if (_engine->game() == KYRA1CD) - usedFilelist = kyra1CDFilelist; + if (_engine->game() == KYRA1) + usedFilelist = kyra1Filelist; + else if (_engine->game() == KYRA1CD) + usedFilelist = kyra1CDFilelist; + else + error("no filelist found for this game"); + + for (uint32 tmp = 0; usedFilelist[tmp]; ++tmp) { + // prefetch file + PAKFile* file = new PAKFile(usedFilelist[tmp]); + assert(file); + + if (file->isOpen() && file->isValid()) + _pakfiles.push_back(file); else - error("no filelist found for this game"); - - for (uint32 tmp = 0; usedFilelist[tmp]; ++tmp) { - // prefetch file - PAKFile* file = new PAKFile(usedFilelist[tmp]); - assert(file); - - if (file->isOpen() && file->isValid()) - _pakfiles.push_back(file); - else - debug("couldn't load file '%s' correctly", usedFilelist[tmp]); - } + 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; - } +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; - File file_; - - // test to open it in the main dir - if (file_.open(file)) { +uint8* Resourcemanager::fileData(const char* file, uint32* size) { + uint8* buffer = 0; + File file_; - *size = file_.size(); - - buffer = new uint8[*size]; - assert(buffer); + // 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_.read(buffer, *size); - file_.close(); - - } else { - // opens the file in a PAK File - Common::List<PAKFile*>::iterator start = _pakfiles.begin(); + file_.close(); + + } else { + // opens the file in a PAK File + Common::List<PAKFile*>::iterator start = _pakfiles.begin(); - for (;start != _pakfiles.end(); ++start) { - *size = (*start)->getFileSize(file); + for (;start != _pakfiles.end(); ++start) { + *size = (*start)->getFileSize(file); - if (!(*size)) - continue; + if (!(*size)) + continue; - buffer = new uint8[*size]; - assert(buffer); + buffer = new uint8[*size]; + assert(buffer); - // creates a copy of the file - memcpy(buffer, (*start)->getFile(file), *size); + // creates a copy of the file + memcpy(buffer, (*start)->getFile(file), *size); - break; - } - + break; } - if (!buffer || !(*size)) { - return 0; - } + } - return buffer; + if (!buffer || !(*size)) { + return 0; } + + return buffer; +} - Palette* Resourcemanager::loadPalette(const char* file) { - uint32 size = 0; - uint8* buffer = 0; - buffer = fileData(file, &size); - if (!buffer) { - warning("ResMgr: Failed loading palette %s", file); - return 0; - } - return new Palette(buffer, size); +Palette* Resourcemanager::loadPalette(const char* file) { + uint32 size = 0; + uint8* buffer = 0; + buffer = fileData(file, &size); + if (!buffer) { + warning("ResMgr: Failed loading palette %s", file); + return 0; } + return new Palette(buffer, size); +} - CPSImage* Resourcemanager::loadImage(const char* file) { - uint32 size = 0; - uint8* buffer = 0; - buffer = fileData(file, &size); - if (!buffer) - return 0; - return new CPSImage(buffer, size); - } +CPSImage* Resourcemanager::loadImage(const char* file) { + uint32 size = 0; + uint8* buffer = 0; + buffer = fileData(file, &size); + if (!buffer) + return 0; + return new CPSImage(buffer, size); +} - Font* Resourcemanager::loadFont(const char* file) { - uint32 size = 0; - uint8* buffer = 0; - buffer = fileData(file, &size); - if (!buffer) - return 0; - return new Font(buffer, size); - } +Font* Resourcemanager::loadFont(const char* file) { + uint32 size = 0; + uint8* buffer = 0; + buffer = fileData(file, &size); + if (!buffer) + 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; - uint8* buffer = 0; - buffer = fileData(file, &size); - if (!buffer || !size) - return 0; - if (_engine->game() == KYRA1 || _engine->game() == KYRA1CD) - return new WSAMovieV1(buffer, size, _engine->game()); - else - return new WSAMovieV2(buffer, size); - } - - VMContext* Resourcemanager::loadScript(const char* file) { - VMContext* context = new VMContext(_engine); - context->loadScript(file); - return context; - } +Movie* Resourcemanager::loadMovie(const char* file) { + // TODO: we have to check the Extenion to create the right movie + uint32 size = 0; + uint8* buffer = 0; + buffer = fileData(file, &size); + if (!buffer || !size) + return 0; + if (_engine->game() == KYRA1 || _engine->game() == KYRA1CD) + return new WSAMovieV1(buffer, size, _engine->game()); + else + return new WSAMovieV2(buffer, size); +} + +VMContext* Resourcemanager::loadScript(const char* file) { + VMContext* context = new VMContext(_engine); + context->loadScript(file); + return context; +} /////////////////////////////////////////// // Pak file manager - #define PAKFile_Iterate Common::List<PakChunk*>::iterator start=_files.begin();start != _files.end(); ++start - PAKFile::PAKFile(/*const Common::String &path, */const Common::String& file) { - File pakfile; - _buffer = 0; - _open = false; - - if (!pakfile.open(file.c_str())){ /*, File::kFileReadMode, path.c_str())) {*/ - printf("pakfile couldn't open %s\n", file.c_str()); - return; - } +#define PAKFile_Iterate Common::List<PakChunk*>::iterator start=_files.begin();start != _files.end(); ++start +PAKFile::PAKFile(/*const Common::String &path, */const Common::String& file) { + File pakfile; + _buffer = 0; + _open = false; + + if (!pakfile.open(file.c_str())){ /*, File::kFileReadMode, path.c_str())) {*/ + printf("pakfile couldn't open %s\n", file.c_str()); + return; + } - uint32 filesize = pakfile.size(); - _buffer = new uint8[filesize]; - assert(_buffer); + uint32 filesize = pakfile.size(); + _buffer = new uint8[filesize]; + assert(_buffer); - pakfile.read(_buffer, filesize); - pakfile.close(); + pakfile.read(_buffer, filesize); + pakfile.close(); - // works with the file - uint32 pos = 0, startoffset = 0, endoffset = 0; + // works with the file + uint32 pos = 0, startoffset = 0, endoffset = 0; - startoffset = READ_LE_UINT32(_buffer + pos); - pos += 4; + startoffset = READ_LE_UINT32(_buffer + pos); + pos += 4; - while (pos < filesize) { - PakChunk* chunk = new PakChunk; - assert(chunk); + while (pos < filesize) { + PakChunk* chunk = new PakChunk; + assert(chunk); - // saves the name - chunk->_name = reinterpret_cast<const char*>(_buffer + pos); - pos += strlen(chunk->_name) + 1; - if(!(*chunk->_name)) - break; + // saves the name + chunk->_name = reinterpret_cast<const char*>(_buffer + pos); + pos += strlen(chunk->_name) + 1; + if(!(*chunk->_name)) + break; - endoffset = READ_LE_UINT32(_buffer + pos); - pos += 4; - - if (endoffset == 0) { - endoffset = filesize; - } + endoffset = READ_LE_UINT32(_buffer + pos); + pos += 4; + + if (endoffset == 0) { + endoffset = filesize; + } - chunk->_data = _buffer + startoffset; - chunk->_size = endoffset - startoffset; + chunk->_data = _buffer + startoffset; + chunk->_size = endoffset - startoffset; - _files.push_back(chunk); - - if (endoffset == filesize) - break; + _files.push_back(chunk); + + if (endoffset == filesize) + break; - startoffset = endoffset; - } - _open = true; + startoffset = endoffset; } + _open = true; +} - PAKFile::~PAKFile() { - delete [] _buffer; - _buffer = 0; - _open = false; +PAKFile::~PAKFile() { + delete [] _buffer; + _buffer = 0; + _open = false; - for (PAKFile_Iterate) { - delete *start; - *start = 0; - } + for (PAKFile_Iterate) { + delete *start; + *start = 0; } +} - const uint8* PAKFile::getFile(const char* file) { - for (PAKFile_Iterate) { - if (!scumm_stricmp((*start)->_name, file)) - return (*start)->_data; - } - - return 0; +const uint8* PAKFile::getFile(const char* file) { + for (PAKFile_Iterate) { + if (!scumm_stricmp((*start)->_name, file)) + return (*start)->_data; } - uint32 PAKFile::getFileSize(const char* file) { - for (PAKFile_Iterate) { - if (!scumm_stricmp((*start)->_name, file)) - return (*start)->_size; - } + return 0; +} - return 0; +uint32 PAKFile::getFileSize(const char* file) { + for (PAKFile_Iterate) { + 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 9b159c427d..3806575f4a 100644 --- a/kyra/resource.h +++ b/kyra/resource.h @@ -32,167 +32,165 @@ namespace Kyra { - // standard Package format for Kyrandia games - class PAKFile { - struct PakChunk { - const char* _name; - const uint8* _data; - uint32 _size; - }; - - public: +// standard Package format for Kyrandia games +class PAKFile { + struct PakChunk { + const char* _name; + const uint8* _data; + uint32 _size; + }; - PAKFile(const Common::String& file); - ~PAKFile(); +public: - const uint8* getFile(const char* file); - uint32 getFileSize(const char* file); + PAKFile(const Common::String& file); + ~PAKFile(); - bool isValid(void) {return (_buffer != 0);} - bool isOpen(void) {return _open;} - private: - bool _open; - uint8* _buffer; // the whole file - Common::List<PakChunk*> _files; // the entries + const uint8* getFile(const char* file); + uint32 getFileSize(const char* file); - }; + bool isValid(void) {return (_buffer != 0);} + bool isOpen(void) {return _open;} +private: + bool _open; + uint8* _buffer; // the whole file + Common::List<PakChunk*> _files; // the entries +}; - // some resource types - class Palette; - class CPSImage; - class Font; - class Movie; - class VMContext; +// some resource types +class Palette; +class CPSImage; +class Font; +class Movie; +class VMContext; - // out resource manager - class Resourcemanager { - typedef Common::String string; +// out resource manager +class Resourcemanager { + typedef Common::String string; - public: +public: - Resourcemanager(KyraEngine* engine); - virtual ~Resourcemanager(); + Resourcemanager(KyraEngine* engine); + virtual ~Resourcemanager(); - uint8* fileData(const char* file, uint32* size); + uint8* fileData(const char* file, uint32* size); - Palette* loadPalette(const char* file); - CPSImage* loadImage(const char* file); - Font* loadFont(const char* file); - Movie* loadMovie(const char* file); - VMContext* loadScript(const char* file); + Palette* loadPalette(const char* file); + CPSImage* loadImage(const char* file); + Font* loadFont(const char* file); + Movie* loadMovie(const char* file); + VMContext* loadScript(const char* file); - protected: - KyraEngine* _engine; +protected: + KyraEngine* _engine; - Common::List<PAKFile*> _pakfiles; + Common::List<PAKFile*> _pakfiles; - }; +}; - class Palette { +class Palette { - public: +public: + + Palette(uint8* data, uint32 size); + ~Palette() { delete [] _palette; } - Palette(uint8* data, uint32 size); - ~Palette() { delete [] _palette; } + uint8* getData(void) { return _palette; } - uint8* getData(void) { return _palette; } +protected: - protected: + uint8* _palette; - uint8* _palette; +}; - }; +class CPSImage { - class CPSImage { +public: - public: + CPSImage(uint8* buffer, uint32 size); + ~CPSImage(); - CPSImage(uint8* buffer, uint32 size); - ~CPSImage(); + Palette* palette(void) { return _ownPalette; } + bool hasPalette(void) { return (_ownPalette != 0); } - Palette* palette(void) { return _ownPalette; } - bool hasPalette(void) { return (_ownPalette != 0); } + // if col == -1 then no transparany + void transparency(int16 col) { _transparency = col; } - // if col == -1 then no transparany - void transparency(int16 col) { _transparency = col; } + void drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 x, uint16 y); + void drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 x, uint16 y, + uint16 srcx, uint16 srcy, uint16 srcwidth, uint16 srcheight); - void drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 x, uint16 y); - void drawToPlane(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 x, uint16 y, - uint16 srcx, uint16 srcy, uint16 srcwidth, uint16 srcheight); - - // only for testing :) - uint8 getColor(uint16 x, uint16 y) { return _image[y * _width + x]; } + // 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: + uint8& operator[](uint16 index) { if(index > _width * _height) return _image[0]; return _image[index]; } - struct CPSHeader { - uint16 _filesize; - uint16 _format; - uint16 _imagesize; - uint32 _pal; - } _cpsHeader; +protected: - Palette* _ownPalette; - uint8* _image; + struct CPSHeader { + uint16 _filesize; + uint16 _format; + uint16 _imagesize; + uint32 _pal; + } _cpsHeader; - uint16 _width, _height; - int16 _transparency; - }; + Palette* _ownPalette; + uint8* _image; - class Font { + uint16 _width, _height; + int16 _transparency; +}; - public: +class Font { - Font(uint8* buffer, uint32 size); - ~Font(); +public: - uint32 getStringWidth(const char* string, char terminator = '\0'); - void drawStringToPlane(const char* string, - uint8* plane, uint16 planewidth, uint16 planeheight, - uint16 x, uint16 y, uint8 color); + Font(uint8* buffer, uint32 size); + ~Font(); - protected: + uint32 getStringWidth(const char* string, char terminator = '\0'); + void drawStringToPlane(const char* string, + uint8* plane, uint16 planewidth, uint16 planeheight, + uint16 x, uint16 y, uint8 color); - void drawCharToPlane(const uint8* c, uint8 color, uint8 width, uint8 height, - uint8* plane, uint16 planewidth, uint16 planeheight, uint16 x, uint16 y); - const uint8* getChar(char c, uint8* width, uint8* height, uint8* heightadd); - const char* getNextWord(const char* string, uint32* size); +protected: - void preRenderAllChars(uint16 offsetTableOffset); + void drawCharToPlane(const uint8* c, uint8 color, uint8 width, uint8 height, + uint8* plane, uint16 planewidth, uint16 planeheight, uint16 x, uint16 y); + const uint8* getChar(char c, uint8* width, uint8* height, uint8* heightadd); + const char* getNextWord(const char* string, uint32* size); - uint8* _buffer; + void preRenderAllChars(uint16 offsetTableOffset); - uint16* _offsetTable; - uint8* _charWidth; - uint16* _charHeight; - uint8* _charBits; + uint8* _buffer; + uint16* _offsetTable; + uint8* _charWidth; + uint16* _charHeight; + uint8* _charBits; - // the chars I call 'prerendered' aren't really prerendered - // they are only 'decoded' - struct PreRenderedChar { - uint8* c; - uint8 width, height, heightadd; - }; + // the chars I call 'prerendered' aren't really prerendered + // they are only 'decoded' + struct PreRenderedChar { + uint8* c; + uint8 width, height, heightadd; + }; - Common::Map<uint8, PreRenderedChar> _preRenderedChars; // our prerendered chars :) + Common::Map<uint8, PreRenderedChar> _preRenderedChars; // our prerendered chars :) - // INFO: - // _magic1 = 0x0500 - // _magic2 = 0x000e - // _magic3 = 0x0014 + // INFO: + // _magic1 = 0x0500 + // _magic2 = 0x000e + // _magic3 = 0x0014 #pragma START_PACK_STRUCTS - struct FontHeader { - uint16 _size; - uint16 _magic1, _magic2, _magic3; - uint16 _charWidthOffset, _charBitsOffset, _charHeightOffset; - uint16 _version; - uint16 _countChars; - uint8 _width, _height; - } GCC_PACK _fontHeader; + struct FontHeader { + uint16 _size; + uint16 _magic1, _magic2, _magic3; + uint16 _charWidthOffset, _charBitsOffset, _charHeightOffset; + uint16 _version; + uint16 _countChars; + uint8 _width, _height; + } GCC_PACK _fontHeader; #pragma END_PACK_STRUCTS - }; +}; } // end of namespace Kyra #endif diff --git a/kyra/script.cpp b/kyra/script.cpp index bb58d2c887..99e9999d54 100644 --- a/kyra/script.cpp +++ b/kyra/script.cpp @@ -31,534 +31,533 @@ #define OPCODE(x) { &VMContext::x, #x } namespace Kyra { - VMContext::VMContext(KyraEngine* engine) { - _engine = engine; - _error = false; +VMContext::VMContext(KyraEngine* engine) { + _engine = engine; + _error = false; - // now we create a list of all Command/Opcode procs and so - static CommandEntry commandProcs[] = { - // 0x00 - COMMAND(c1_goToLine), - COMMAND(c1_setReturn), - COMMAND(c1_pushRetRec), - COMMAND(c1_push), - // 0x04 - COMMAND(c1_push), - COMMAND(c1_pushVar), - COMMAND(c1_pushFrameNeg), - COMMAND(c1_pushFramePos), - // 0x08 - COMMAND(c1_popRetRec), - COMMAND(c1_popVar), - COMMAND(c1_popFrameNeg), - COMMAND(c1_popFramePos), - // 0x0C - COMMAND(c1_addToSP), - COMMAND(c1_subFromSP), - COMMAND(c1_execOpcode), - COMMAND(c1_ifNotGoTo), - // 0x10 - COMMAND(c1_negate), - COMMAND(c1_evaluate) - }; - _numCommands = ARRAYSIZE(commandProcs); - _commands = commandProcs; + // now we create a list of all Command/Opcode procs and so + static CommandEntry commandProcs[] = { + // 0x00 + COMMAND(c1_goToLine), + COMMAND(c1_setReturn), + COMMAND(c1_pushRetRec), + COMMAND(c1_push), + // 0x04 + COMMAND(c1_push), + COMMAND(c1_pushVar), + COMMAND(c1_pushFrameNeg), + COMMAND(c1_pushFramePos), + // 0x08 + COMMAND(c1_popRetRec), + COMMAND(c1_popVar), + COMMAND(c1_popFrameNeg), + COMMAND(c1_popFramePos), + // 0x0C + COMMAND(c1_addToSP), + COMMAND(c1_subFromSP), + COMMAND(c1_execOpcode), + COMMAND(c1_ifNotGoTo), + // 0x10 + COMMAND(c1_negate), + COMMAND(c1_evaluate) + }; + _numCommands = ARRAYSIZE(commandProcs); + _commands = commandProcs; - static OpcodeEntry opcodeProcs[] = { - // 0x00 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x04 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x08 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x0C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x10 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x14 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x18 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x1C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x20 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x24 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x28 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x2C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x30 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x34 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x38 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x3C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x40 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x44 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x48 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x4C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x50 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x54 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x58 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x5C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x60 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x64 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x68 - COMMAND(o1_0x68), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x6C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x70 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x74 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x78 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x7C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x80 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x84 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x88 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x8C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x90 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x94 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x98 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0x9C - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xA0 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xA4 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xA8 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xAC - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xB0 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xB4 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xB8 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xBC - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xC0 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xC4 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xC8 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xCC - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xD0 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xD4 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xD8 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xDC - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xE0 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xE4 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xE8 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xEC - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xF0 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xF4 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xF8 - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - // 0xFC - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode), - COMMAND(o1_unknownOpcode) - }; - _numOpcodes = ARRAYSIZE(opcodeProcs); - _opcodes = opcodeProcs; + static OpcodeEntry opcodeProcs[] = { + // 0x00 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x04 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x08 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x0C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x10 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x14 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x18 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x1C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x20 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x24 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x28 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x2C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x30 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x34 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x38 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x3C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x40 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x44 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x48 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x4C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x50 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x54 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x58 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x5C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x60 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x64 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x68 + OPCODE(o1_0x68), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x6C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x70 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x74 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x78 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x7C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x80 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x84 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x88 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x8C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x90 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x94 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x98 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0x9C + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xA0 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xA4 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xA8 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xAC + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xB0 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xB4 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xB8 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xBC + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xC0 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xC4 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xC8 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xCC + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xD0 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xD4 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xD8 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xDC + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xE0 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xE4 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xE8 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xEC + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xF0 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xF4 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xF8 + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + // 0xFC + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode), + OPCODE(o1_unknownOpcode) + }; + _numOpcodes = ARRAYSIZE(opcodeProcs); + _opcodes = opcodeProcs; - _scriptFile = NULL; + _scriptFile = NULL; + _scriptFileSize = 0; +} + +void VMContext::loadScript(const char* file) { + if (_scriptFile) { + delete [] _scriptFile; _scriptFileSize = 0; } - - void VMContext::loadScript(const char* file) { - if (_scriptFile) { - delete [] _scriptFile; - _scriptFileSize = 0; - } - memset(_stack, 0, sizeof(int32) * ARRAYSIZE(_stack)); + 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); + // 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(true) { + if (script.eof()) { + break; } - - Common::MemoryReadStream script(_scriptFile, _scriptFileSize); - memset(_chunks, 0, sizeof(ScriptChunk) * kCountChunkTypes); - uint8 chunkName[sizeof("EMC2ORDR") + 1]; - - // so lets look for our chunks :) - while(true) { - if (script.eof()) { - break; - } - // 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")) { - // FreeKyra swaps the size I only read it in BigEndian :) - _chunks[kForm]._size = script.readUint32BE(); - debug("_chunks[kForm]._size = %d", _chunks[kForm]._size); - } 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); - script.seek(script.pos() + text_size); - } else if (!scumm_stricmp((const char *)chunkName, "DATA")) { - _chunks[kData]._size = script.readUint32BE(); - _chunks[kData]._data = _scriptFile + script.pos(); - // mostly it will be the end of the file because all files should end with a 'DATA' chunk - script.seek(script.pos() + _chunks[kData]._size); + // 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")) { + // 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); + script.seek(script.pos() + text_size); + } else if (!scumm_stricmp((const char *)chunkName, "DATA")) { + _chunks[kData]._size = script.readUint32BE(); + _chunks[kData]._data = _scriptFile + script.pos(); + // mostly it will be the end of the file because all files should end with a 'DATA' chunk + script.seek(script.pos() + _chunks[kData]._size); + } else { + // 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(); + script.seek(script.pos() + _chunks[kEmc2Ordr]._size * 2); } else { - // read next 4 chars - script.read(&chunkName[4], sizeof(uint8) * 4); - chunkName[8] = '\0'; - debug("chunk name(8 chars): '%s'", chunkName); - - if (!scumm_stricmp((const char *)chunkName, "EMC2ORDR")) { - _chunks[kEmc2Ordr]._size = script.readUint32BE() >> 1; - _chunks[kEmc2Ordr]._data = _scriptFile + script.pos(); - script.seek(script.pos() + _chunks[kEmc2Ordr]._size * 2); - } else { - // any unkown chunk or problems with seeking through the file - error("unknown chunk(%s)", chunkName); - } + // any unkown chunk or problems with seeking through the file + error("unknown chunk(%s)", chunkName); } } } +} - int32 VMContext::param(int32 index) { - if (_stackPos - index - 1 >= ARRAYSIZE(_stack) || _stackPos - index - 1 < 0) - return -0xFFFF; - return _stack[_stackPos - index - 1]; - } +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]); - } +const char* VMContext::stringAtIndex(int32 index) { + if (index < 0 || (uint32)index >= _chunks[kText]._size) + return 0; - bool VMContext::startScript(int32 func) { - if ((uint32)func >= _chunks[kEmc2Ordr]._size || func < 0) { - debug("script doesn't support function %d", func); - return false; - } + 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; - _scriptState = kScriptRunning; + _instructionPos = READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[func]) << 1; + _stackPos = 0; + _tempPos = 0; + _delay = 0; + _error = false; + _scriptState = kScriptRunning; + + uint32 pos = 0xFFFFFFFE; - 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 && - (uint32)((READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[tmp]) << 1)) < pos) { - pos = ((READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[tmp]) << 1)); - } - } - - if (pos > _scriptFileSize) { - pos = _scriptFileSize; + // 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 && + (uint32)((READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[tmp]) << 1)) < pos) { + pos = ((READ_BE_UINT16(&_chunks[kEmc2Ordr]._data[tmp]) << 1)); } + } - _nextScriptPos = pos; - - return true; + if (pos > _scriptFileSize) { + pos = _scriptFileSize; } - - uint32 VMContext::contScript(void) { - uint8* script_start = _chunks[kData]._data; - assert(script_start); - uint32 scriptStateAtStart = _scriptState; + _nextScriptPos = pos; - // runs the script - while(true) { - if ((uint32)_instructionPos > _chunks[kData]._size) { - debug("_instructionPos( = %d) > _chunks[kData]._size( = %d)", _instructionPos, _chunks[kData]._size); - _error = true; - break; - } else if(_instructionPos >= _nextScriptPos) { - _scriptState = kScriptStopped; - break; - } - - _currentCommand = *(script_start + _instructionPos++); + 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) { + debug("_instructionPos( = %d) > _chunks[kData]._size( = %d)", _instructionPos, _chunks[kData]._size); + _error = true; + break; + } else if(_instructionPos >= _nextScriptPos) { + _scriptState = kScriptStopped; + break; + } - // gets out - if (_currentCommand & 0x80) { - _argument = ((_currentCommand & 0x0F) << 8) | *(script_start + _instructionPos++); - _currentCommand &= 0xF0; - } else if (_currentCommand & 0x40) { - _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 { - debug("unknown way of getting the command"); - // next thing - continue; - } + _currentCommand = *(script_start + _instructionPos++); + + // gets out + if (_currentCommand & 0x80) { + _argument = ((_currentCommand & 0x0F) << 8) | *(script_start + _instructionPos++); + _currentCommand &= 0xF0; + } else if (_currentCommand & 0x40) { + _argument = *(script_start + _instructionPos++); + } else if (_currentCommand & 0x20) { + _instructionPos++; - _currentCommand &= 0x1f; - - if (_currentCommand < _numCommands) { - CommandProc currentProc = _commands[_currentCommand].proc; - (this->*currentProc)(); - } else { - c1_unknownCommand(); - } + uint16 tmp = *(uint16*)(script_start + _instructionPos); + tmp &= 0xFF7F; - if (_error) { - _scriptState = kScriptError; - break; - } + _argument = READ_BE_UINT16(&tmp); + _instructionPos += 2; + } else { + debug("unknown way of getting the command (0x%X)", _currentCommand); + // next thing + continue; + } + + _currentCommand &= 0x1f; - if (scriptStateAtStart != _scriptState) { - break; - } + if (_currentCommand < _numCommands) { + CommandProc currentProc = _commands[_currentCommand].proc; + (this->*currentProc)(); + } else { + c1_unknownCommand(); + } + + if (_error) { + _scriptState = kScriptError; + break; + } + + if (scriptStateAtStart != _scriptState) { + break; } - - return _scriptState; } + + return _scriptState; +} } // end of namespace Kyra diff --git a/kyra/script.h b/kyra/script.h index 664850b62c..7612e78f2d 100644 --- a/kyra/script.h +++ b/kyra/script.h @@ -23,135 +23,136 @@ #define VM_H namespace Kyra { - // TODO: - // find out more script functions - enum ScriptFunc { - kSetupScene = 0, - kClickEvent = 1, // _registers[1] and _registers[2] are mouse x, y _registers[4] is action - kActorEvent = 2, - kEnterEvent = 4, - kExitEvent = 5, - kLoadResources = 7 - }; +// TODO: +// find out more script functions +enum ScriptFunc { + kSetupScene = 0, + kClickEvent = 1, // _registers[1] and _registers[2] are mouse x, y _registers[4] is action + kActorEvent = 2, + kEnterEvent = 4, + kExitEvent = 5, + kLoadResources = 7 +}; + +enum ScriptState { + kScriptStopped = 0, + kScriptRunning = 1, + kScriptWaiting = 2, + kScriptError = 3 +}; - enum ScriptState { - kScriptStopped = 0, - kScriptRunning = 1, - kScriptWaiting = 2, - kScriptError = 3 - }; + +class VMContext { + +public: - class VMContext { + VMContext(KyraEngine* engine); + ~VMContext() { delete [] _scriptFile; } - public: + void loadScript(const char* file); - 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 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); + const char* stringAtIndex(int32 index); - 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, - kText = 2, - 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]; + // TODO: check for 'over'flow + 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); - typedef void (VMContext::*CommandProc)(); - struct CommandEntry { - CommandProc proc; - const char* desc; - }; +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; - typedef void (VMContext::*OpcodeProc)(); - struct OpcodeEntry { - OpcodeProc proc; - const char* desc; - }; + 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, + kText = 2, + 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)(); + struct CommandEntry { + CommandProc proc; + const char* desc; + }; - uint16 _numCommands; - const CommandEntry* _commands; - uint16 _numOpcodes; - const OpcodeEntry* _opcodes; - - protected: - // the command procs - void c1_goToLine(void); // 0x00 - void c1_setReturn(void); // 0x01 - void c1_pushRetRec(void); // 0x02 - void c1_push(void); // 0x03 & 0x04 - void c1_pushVar(void); // 0x05 - void c1_pushFrameNeg(void); // 0x06 - void c1_pushFramePos(void); // 0x07 - void c1_popRetRec(void); // 0x08 - void c1_popVar(void); // 0x09 - void c1_popFrameNeg(void); // 0x0A - void c1_popFramePos(void); // 0x0B - void c1_addToSP(void); // 0x0C - void c1_subFromSP(void); // 0x0D - void c1_execOpcode(void); // 0x0E - void c1_ifNotGoTo(void); // 0x0F - 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); + 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 + void c1_setReturn(void); // 0x01 + void c1_pushRetRec(void); // 0x02 + void c1_push(void); // 0x03 & 0x04 + void c1_pushVar(void); // 0x05 + void c1_pushFrameNeg(void); // 0x06 + void c1_pushFramePos(void); // 0x07 + void c1_popRetRec(void); // 0x08 + void c1_popVar(void); // 0x09 + void c1_popFrameNeg(void); // 0x0A + void c1_popFramePos(void); // 0x0B + void c1_addToSP(void); // 0x0C + void c1_subFromSP(void); // 0x0D + void c1_execOpcode(void); // 0x0E + void c1_ifNotGoTo(void); // 0x0F + 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); +}; } // end of namespace Kyra #endif diff --git a/kyra/script_v1.cpp b/kyra/script_v1.cpp index c69c58c514..bab2442ff5 100644 --- a/kyra/script_v1.cpp +++ b/kyra/script_v1.cpp @@ -25,219 +25,219 @@ #include "script.h" namespace Kyra { - // Command procs +// Command procs + +void VMContext::c1_unknownCommand(void) { + debug("unknown command '0x%x'.", _currentCommand); + debug("\targument: '0x%x'", _argument); - void VMContext::c1_unknownCommand(void) { - debug("unknown command '0x%x'.", _currentCommand); - debug("\targument: '0x%x'", _argument); + _error = true; +} + +void VMContext::c1_goToLine(void) { + _instructionPos = _argument << 1; +} + +void VMContext::c1_setReturn(void) { + _returnValue = _argument; +} + +void VMContext::c1_pushRetRec(void) { + if (!_argument) { + pushStack(_returnValue); + } else { + int32 rec = ((int16)_tempPos << 16) | ((_instructionPos >> 1) + 1); + pushStack(rec); + _tempPos = _instructionPos; + } +} + +void VMContext::c1_push(void) { + pushStack(_argument); +} + +void VMContext::c1_pushVar(void) { + pushStack(_registers[_argument]); +} + +void VMContext::c1_pushFrameNeg(void) { + pushStack(_stack[_tempPos + _argument]); +} + +void VMContext::c1_pushFramePos(void) { + pushStack(_stack[_tempPos - _argument]); +} + +void VMContext::c1_popRetRec(void) { + if (!_argument) { + _returnValue = popStack(); + } else { + if (_stackPos <= 0) { + _scriptState = kScriptStopped; + } + int32 rec = popStack(); - _error = true; + _tempPos = (int16)((rec & 0xFFFF0000) >> 16); + _instructionPos = (rec & 0x0000FFFF) * 2; } - - void VMContext::c1_goToLine(void) { +} + +void VMContext::c1_popVar(void) { + _registers[_argument] = popStack(); +} + +void VMContext::c1_popFrameNeg(void) { + _stack[_tempPos + _argument] = popStack(); +} + +void VMContext::c1_popFramePos(void) { + _stack[_tempPos - _argument] = popStack(); +} + +void VMContext::c1_addToSP(void) { + _stackPos -= _argument; +} + +void VMContext::c1_subFromSP(void) { + _stackPos += _argument; +} + +void VMContext::c1_execOpcode(void) { + if (_argument < _numOpcodes) { + OpcodeProc proc = _opcodes[_argument].proc; + (this->*proc)(); + } else { + error("Invalid opcode 0x%X", _argument); + } +} + +void VMContext::c1_ifNotGoTo(void) { + if (!popStack()) { _instructionPos = _argument << 1; } +} + +void VMContext::c1_negate(void) { + switch(_argument) { + case 0: + topStack() = !topStack(); + break; + + case 1: + topStack() = -topStack(); + break; + + case 2: + topStack() = ~topStack(); + break; + + default: + debug("unkown negate instruction %d", _argument); + _error = true; + break; + }; +} + +void VMContext::c1_evaluate(void) { + int32 x, y; + int32 res = false; - void VMContext::c1_setReturn(void) { - _returnValue = _argument; - } + x = popStack(); + y = popStack(); - void VMContext::c1_pushRetRec(void) { - if (!_argument) { - pushStack(_returnValue); - } else { - int32 rec = ((int16)_tempPos << 16) | ((_instructionPos >> 1) + 1); - pushStack(rec); - _tempPos = _instructionPos; - } - } + switch(_argument) { + case 0: + res = x && y; + break; - void VMContext::c1_push(void) { - pushStack(_argument); - } + case 1: + res = x || y; + break; - void VMContext::c1_pushVar(void) { - pushStack(_registers[_argument]); - } + case 3: + res = x != y; + break; - void VMContext::c1_pushFrameNeg(void) { - pushStack(_stack[_tempPos + _argument]); - } + case 4: + res = x < y; + break; - void VMContext::c1_pushFramePos(void) { - pushStack(_stack[_tempPos - _argument]); - } + case 5: + res = x <= y; + break; + + case 6: + res = x > y; + break; - void VMContext::c1_popRetRec(void) { - if (!_argument) { - _returnValue = popStack(); - } else { - if (_stackPos <= 0) { - _scriptState = kScriptStopped; - } - int32 rec = popStack(); - - _tempPos = (int16)((rec & 0xFFFF0000) >> 16); - _instructionPos = (rec & 0x0000FFFF) * 2; - } - } + case 7: + res = x >= y; + break; - void VMContext::c1_popVar(void) { - _registers[_argument] = popStack(); - } + case 8: + res = x + y; + break; + + case 9: + res = x - y; + break; - void VMContext::c1_popFrameNeg(void) { - _stack[_tempPos + _argument] = popStack(); - } + case 10: + res = x * y; + break; + + case 11: + res = x / y; + break; - void VMContext::c1_popFramePos(void) { - _stack[_tempPos - _argument] = popStack(); - } + case 12: + res = x >> y; + break; - void VMContext::c1_addToSP(void) { - _stackPos -= _argument; - } + case 13: + res = x << y; + break; - void VMContext::c1_subFromSP(void) { - _stackPos += _argument; - } + case 14: + res = x & y; + break; - void VMContext::c1_execOpcode(void) { - if (_argument < _numOpcodes) { - OpcodeProc proc = _opcodes[_argument].proc; - (this->*proc)(); - } else { - error("Invalid opcode 0x%X", _argument); - } - } + case 15: + res = x | y; + break; - void VMContext::c1_ifNotGoTo(void) { - if (!popStack()) { - _instructionPos = _argument << 1; - } - } + case 16: + res = x % y; + break; - void VMContext::c1_negate(void) { - switch(_argument) { - case 0: - topStack() = !topStack(); - break; - - case 1: - topStack() = -topStack(); - break; - - case 2: - topStack() = ~topStack(); - break; - - default: - debug("unkown negate instruction %d", _argument); - _error = true; - break; - }; - } + case 17: + res = x ^ y; + break; - 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; + default: + debug("unknown evaluate command"); + break; + }; + + pushStack(res); +} - 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(4), paramString(5)); - } +// 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(4), paramString(5)); +} - void VMContext::o1_0x68(void) { - debug("o1_0x68 was called with param0: '%d'", param(0)); - _error = true; - } +void VMContext::o1_0x68(void) { + debug("o1_0x68 was called with param0: '0x%x'", param(0)); + _error = true; +} } // end of namespace Kyra diff --git a/kyra/wsamovie.cpp b/kyra/wsamovie.cpp index 1408482cf5..56f7432f39 100644 --- a/kyra/wsamovie.cpp +++ b/kyra/wsamovie.cpp @@ -30,403 +30,405 @@ #endif namespace Kyra { - WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { - if (!data) { - error("resource created without data"); - } - - _background = 0; - _currentFrame = 0; - _ownPalette = 0; - _offsetTable = 0; - _prefetchedFrame = 0xFFFE; - _buffer = data; +WSAMovieV1::WSAMovieV1(uint8* data, uint32 size, uint8 gameid) { + if (!data) { + error("resource created without data"); + } - // I like these Streams .... =) - Common::MemoryReadStream datastream(data, size); + _background = 0; + _currentFrame = 0; + _ownPalette = 0; + _offsetTable = 0; + _prefetchedFrame = 0xFFFE; + _buffer = data; - datastream.read(&_wsaHeader, sizeof(_wsaHeader)); + // I like these Streams .... =) + Common::MemoryReadStream datastream(data, size); + + datastream.read(&_wsaHeader, sizeof(_wsaHeader)); #ifdef DUMP_FILES - 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]); - fprintf(wsaheader, "\n"); - for (uint32 pos = 0; pos < sizeof(_wsaHeader) / 2; ++pos) - fprintf(wsaheader, "%d pos. word: %d\n", pos + 1, ((uint16*)&_wsaHeader)[pos]); - fprintf(wsaheader, "\n"); - for (uint32 pos = 0; pos < sizeof(_wsaHeader) / 4; ++pos) - fprintf(wsaheader, "%d pos. dword: %d\n", pos + 1, ((uint32*)&_wsaHeader)[pos]); - } - fclose(wsaheader); + // 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]); + fprintf(wsaheader, "\n"); + for (uint32 pos = 0; pos < sizeof(_wsaHeader) / 2; ++pos) + fprintf(wsaheader, "%d pos. word: %d\n", pos + 1, ((uint16*)&_wsaHeader)[pos]); + fprintf(wsaheader, "\n"); + for (uint32 pos = 0; pos < sizeof(_wsaHeader) / 4; ++pos) + fprintf(wsaheader, "%d pos. dword: %d\n", pos + 1, ((uint32*)&_wsaHeader)[pos]); + } + fclose(wsaheader); #endif - if (gameid == KYRA1CD) { - 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); - debug("_wsaHeader._xPos = %d", _wsaHeader._xPos); - 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"); - } + if (gameid == KYRA1CD) { + uint16 tmp = _wsaHeader._delta; + _wsaHeader._delta = _wsaHeader._type; + _wsaHeader._type = tmp; - uint16 offsetAdd = 0; + // skip 2 bytes + datastream.readUint16LE(); + } - // 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 */; - } + debug("_wsaHeader._numFrames = %d", _wsaHeader._numFrames); + debug("_wsaHeader._width = %d", _wsaHeader._width); + debug("_wsaHeader._height = %d", _wsaHeader._height); + debug("_wsaHeader._xPos = %d", _wsaHeader._xPos); + 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"); + } - // last frame seems every time to be a empty one - _frameCount = _wsaHeader._numFrames - 1; - _offsetTable = new uint32[_wsaHeader._numFrames + 2]; - assert(_offsetTable); + uint16 offsetAdd = 0; - // loads the offset table - for (uint32 tmp = 0; tmp < (uint32)_wsaHeader._numFrames + 2; ++tmp) { - _offsetTable[tmp] = datastream.readUint32LE() + offsetAdd; - } + // 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 (offsetAdd) { - uint8* palbuffer = new uint8[offsetAdd]; - assert(palbuffer); - - datastream.read(palbuffer, offsetAdd); - - _ownPalette = new Palette(palbuffer, offsetAdd); - assert(_ownPalette); - } - - // FIXME: Confirm the default value here? - _transparency = -1; + // 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); - WSAMovieV1::~WSAMovieV1() { - delete [] _buffer; - delete [] _offsetTable; - delete [] _currentFrame; - delete _ownPalette; + // 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); } + + // FIXME: Confirm the default value here? + // 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; +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; + if (frame == _prefetchedFrame) { + return _currentFrame; + } else { + if (!_currentFrame) { + _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._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); + Compression::decode40(image40, _currentFrame); } else { - if (!_currentFrame) { - _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; - assert(_currentFrame); + if (_background) { + setImageBackground(_background, _backWidth, _backHeight); + } else { 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]; + for (uint32 i = 0; i <= frame; ++i) + { + frameData = _buffer + _offsetTable[i]; Compression::decode80(frameData, image40); Compression::decode40(image40, _currentFrame); - } else { - if (_background) { - setImageBackground(_background, _backWidth, _backHeight); - } else { - memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); - } - - for (uint32 i = 0; i <= frame; ++i) - { - frameData = _buffer + _offsetTable[i]; - Compression::decode80(frameData, image40); - 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; - - 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)); - dst += planepitch; - src += _wsaHeader._width; - } - } else { - for (uint16 yadd = 0; yadd < _wsaHeader._height; ++yadd) { - for (uint16 xadd = 0; xadd < copysize; ++xadd) { - if (*src == _transparency) { - ++dst; - ++src; - } else { - *dst++ = *src++; - } - } - - src += _wsaHeader._width - copysize; - dst += planepitch - copysize; - } - } + _prefetchedFrame = frame; + return _currentFrame; } - - void WSAMovieV1::setImageBackground(uint8* plane, uint16 planepitch, uint16 height) { - assert(plane); - _background = plane; - _backWidth = planepitch; _backHeight = height; + return 0; +} + +void WSAMovieV1::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame) { + if (!loadFrame(frame, 0, 0)) + return; - 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; + uint8* src = _currentFrame; + uint8* dst = &plane[_wsaHeader._yPos * planepitch + _wsaHeader._xPos]; + 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_) { + if (_transparency == -1) { + for (uint16 y_ = 0; y_ < _wsaHeader._height && _wsaHeader._yPos + y_ < planeheight; ++y_) { memcpy(dst, src, copysize * sizeof(uint8)); - dst += _wsaHeader._width; - src += planepitch; + dst += planepitch; + src += _wsaHeader._width; } - - 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; + } else { + for (uint16 yadd = 0; yadd < _wsaHeader._height; ++yadd) { + for (uint16 xadd = 0; xadd < copysize; ++xadd) { + if (*src == _transparency) { + ++dst; + ++src; + } else { + *dst++ = *src++; + } } + + src += _wsaHeader._width - copysize; + dst += planepitch - copysize; } - - _prefetchedFrame = 0xFFFE; } +} - // Kyrandia 2+ Movies - WSAMovieV2::WSAMovieV2(uint8* data, uint32 size) { - if (!data) { - error("resource created without data"); - } +void WSAMovieV1::setImageBackground(uint8* plane, uint16 planepitch, uint16 height) { + assert(plane); - _background = 0; - _currentFrame = 0; - _ownPalette = 0; - _offsetTable = 0; - _prefetchedFrame = 0xFFFE; - _looping = false; - _buffer = data; + _background = plane; + _backWidth = planepitch; _backHeight = height; - // 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 (!_currentFrame) { + _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; + assert(_currentFrame); + } - if (offsetAdd) { - uint8* palbuffer = new uint8[offsetAdd]; - assert(palbuffer); - - datastream.read(palbuffer, offsetAdd); - - _ownPalette = new Palette(palbuffer, offsetAdd); - assert(_ownPalette); + 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; + _offsetTable = 0; + _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); - if (_offsetTable[_wsaHeader._numFrames + 1] - offsetAdd) { - ++_wsaHeader._numFrames; - _looping = true; - } + datastream.read(palbuffer, offsetAdd); - _frameCount = _wsaHeader._numFrames; + _ownPalette = new Palette(palbuffer, offsetAdd); + assert(_ownPalette); } - WSAMovieV2::~WSAMovieV2() { - delete [] _buffer; - delete [] _offsetTable; - delete [] _currentFrame; - delete _ownPalette; + if (_offsetTable[_wsaHeader._numFrames + 1] - offsetAdd) { + ++_wsaHeader._numFrames; + _looping = true; } - const uint8* WSAMovieV2::loadFrame(uint16 frame, uint16* width, uint16* height) { - if (width) *width = _wsaHeader._width; - if (height) *height = _wsaHeader._height; + _frameCount = _wsaHeader._numFrames; +} + +WSAMovieV2::~WSAMovieV2() { + delete [] _buffer; + delete [] _offsetTable; + delete [] _currentFrame; + delete _ownPalette; +} + +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 { + if (!_currentFrame) { + _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; + assert(_currentFrame); + memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); + } + + if (frame >= _wsaHeader._numFrames) + return 0; - if (frame == _prefetchedFrame) { - return _currentFrame; + 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); + Compression::decode40(image40, _currentFrame); } else { - if (!_currentFrame) { - _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; - assert(_currentFrame); + if (_background) { + setImageBackground(_background, _backWidth, _backHeight); + } else { 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]; + for (uint32 i = 0; i <= frame; ++i) + { + frameData = _buffer + _offsetTable[i]; Compression::decode80(frameData, image40); Compression::decode40(image40, _currentFrame); - } else { - if (_background) { - setImageBackground(_background, _backWidth, _backHeight); - } else { - memset(_currentFrame, 0, sizeof(uint8) * _wsaHeader._width * _wsaHeader._height); - } - - for (uint32 i = 0; i <= frame; ++i) - { - frameData = _buffer + _offsetTable[i]; - Compression::decode80(frameData, image40); - Compression::decode40(image40, _currentFrame); - } } - - _prefetchedFrame = frame; - return _currentFrame; } - return 0; + _prefetchedFrame = frame; + return _currentFrame; } - 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; + return 0; +} + +void WSAMovieV2::renderFrame(uint8* plane, uint16 planepitch, uint16 planeheight, uint16 frame) { + if (!loadFrame(frame, 0, 0)) + return; - 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)); - dst += planepitch; - src += _wsaHeader._width; - } - } else { - for (uint16 yadd = 0; yadd < _wsaHeader._height; ++yadd) { - for (uint16 xadd = 0; xadd < copysize; ++xadd) { - if (*src == _transparency) { - ++dst; - ++src; - } else { - *dst++ = *src++; - } + 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)); + dst += planepitch; + src += _wsaHeader._width; + } + } else { + for (uint16 yadd = 0; yadd < _wsaHeader._height; ++yadd) { + for (uint16 xadd = 0; xadd < copysize; ++xadd) { + if (*src == _transparency) { + ++dst; + ++src; + } else { + *dst++ = *src++; } - - src += _wsaHeader._width - copysize; - dst += planepitch - copysize; } + + 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; +void WSAMovieV2::setImageBackground(uint8* plane, uint16 planepitch, uint16 height) { + assert(plane); + + _background = plane; + _backWidth = planepitch; _backHeight = height; - // 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; - } + if (!_currentFrame) { + _currentFrame = new uint8[_wsaHeader._width * _wsaHeader._height]; + assert(_currentFrame); + } - 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; - } + 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; } + + _prefetchedFrame = 0xFFFE; +} } // end of namespace Kyra diff --git a/kyra/wsamovie.h b/kyra/wsamovie.h index 62b7b8489d..7d9da17e76 100644 --- a/kyra/wsamovie.h +++ b/kyra/wsamovie.h @@ -26,109 +26,109 @@ namespace Kyra { - // a generic movie - class Movie { +// a generic movie +class Movie { - public: +public: - virtual ~Movie() { _transparency = -1; _ownPalette = 0; _frameCount = 0; } + 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; } + 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; + // 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 void setImageBackground(uint8* plane, uint16 planepitch, uint16 height) {}; + virtual bool hasPalette(void) { return (_ownPalette != 0); } + virtual Palette* palette(void) { return _ownPalette; } - protected: - int16 _transparency; - uint16 _frameCount; - Palette* _ownPalette; - }; + virtual bool looping(void) { return false; } + virtual uint32 frameChange(void) { return 100; } + virtual void setImageBackground(uint8* plane, uint16 planepitch, uint16 height) {}; - // movie format for Kyrandia 1 - class WSAMovieV1 : public Movie { +protected: + int16 _transparency; + uint16 _frameCount; + Palette* _ownPalette; +}; + +// movie format for Kyrandia 1 +class WSAMovieV1 : public Movie { - public: +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); + WSAMovieV1(uint8* data, uint32 size, uint8 gameid); + ~WSAMovieV1(); - void position(uint16 x, uint16 y) { _wsaHeader._xPos = x; _wsaHeader._yPos = y; } - protected: + 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); - uint8* _buffer; + void position(uint16 x, uint16 y) { _wsaHeader._xPos = x; _wsaHeader._yPos = y; } +protected: + + uint8* _buffer; #pragma START_PACK_STRUCTS - struct WSAHeader { - uint16 _numFrames; // All right - uint16 _width; // All right - uint16 _height; // All right - uint8 _xPos; // is wrong - uint8 _yPos; // is wrong - uint16 _delta; // should be right - uint16 _type; // should be right - } GCC_PACK _wsaHeader; + struct WSAHeader { + uint16 _numFrames; // All right + uint16 _width; // All right + uint16 _height; // All right + uint8 _xPos; // is wrong + uint8 _yPos; // is wrong + uint16 _delta; // is wrong + uint16 _type; // is wrong + } GCC_PACK _wsaHeader; #pragma END_PACK_STRUCTS - uint32* _offsetTable; - - uint8* _currentFrame; - uint16 _prefetchedFrame; - - uint8* _background; // only a pointer to the screen - uint16 _backWidth, _backHeight; - }; + uint32* _offsetTable; - // movie format for Kyrandia 2+ - class WSAMovieV2 : public Movie { + uint8* _currentFrame; + uint16 _prefetchedFrame; - public: - WSAMovieV2(uint8* data, uint32 size); - ~WSAMovieV2(); + uint8* _background; // only a pointer to the screen + uint16 _backWidth, _backHeight; +}; - 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: +// movie format for Kyrandia 2+ +class WSAMovieV2 : public Movie { - uint8* _buffer; - - struct WSAHeader { - uint16 _numFrames; // All right - uint16 _width; // should be right - uint16 _height; // should be right - uint16 _xPos; // could be wrong - uint16 _yPos; // could be wrong - 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; +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; - bool _looping; - }; + struct WSAHeader { + uint16 _numFrames; // All right + uint16 _width; // should be right + uint16 _height; // should be right + uint16 _xPos; // could be wrong + uint16 _yPos; // could be wrong + 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 #endif |
