diff options
author | Paul Gilbert | 2012-10-31 09:34:38 +1100 |
---|---|---|
committer | Paul Gilbert | 2012-10-31 09:34:38 +1100 |
commit | 798ddfaab500bb212f620cf095328eee5eb140a4 (patch) | |
tree | 55b5d0b90affd88063c04b7ff62fea1616b83e80 /engines/cine | |
parent | ef663f95a516d8fe47a245653d418c047361281a (diff) | |
parent | fdc80fd952120ecb8a4941edd4c2e404cdc5fa33 (diff) | |
download | scummvm-rg350-798ddfaab500bb212f620cf095328eee5eb140a4.tar.gz scummvm-rg350-798ddfaab500bb212f620cf095328eee5eb140a4.tar.bz2 scummvm-rg350-798ddfaab500bb212f620cf095328eee5eb140a4.zip |
Merge branch 'master' into hopkins
Diffstat (limited to 'engines/cine')
-rw-r--r-- | engines/cine/anim.cpp | 62 | ||||
-rw-r--r-- | engines/cine/cine.cpp | 13 | ||||
-rw-r--r-- | engines/cine/cine.h | 2 | ||||
-rw-r--r-- | engines/cine/console.cpp | 2 | ||||
-rw-r--r-- | engines/cine/gfx.cpp | 87 | ||||
-rw-r--r-- | engines/cine/gfx.h | 3 | ||||
-rw-r--r-- | engines/cine/main_loop.cpp | 29 | ||||
-rw-r--r-- | engines/cine/object.cpp | 2 | ||||
-rw-r--r-- | engines/cine/pal.cpp | 3 | ||||
-rw-r--r-- | engines/cine/part.cpp | 2 | ||||
-rw-r--r-- | engines/cine/saveload.cpp | 2 | ||||
-rw-r--r-- | engines/cine/saveload.h | 2 | ||||
-rw-r--r-- | engines/cine/script.h | 1 | ||||
-rw-r--r-- | engines/cine/script_fw.cpp | 1640 | ||||
-rw-r--r-- | engines/cine/sound.cpp | 161 | ||||
-rw-r--r-- | engines/cine/sound.h | 36 | ||||
-rw-r--r-- | engines/cine/texte.cpp | 2 | ||||
-rw-r--r-- | engines/cine/texte.h | 2 | ||||
-rw-r--r-- | engines/cine/various.cpp | 218 |
19 files changed, 1231 insertions, 1038 deletions
diff --git a/engines/cine/anim.cpp b/engines/cine/anim.cpp index 60168831a1..075a59cfb6 100644 --- a/engines/cine/anim.cpp +++ b/engines/cine/anim.cpp @@ -202,13 +202,13 @@ AnimData::AnimData(const AnimData &src) : _width(src._width), if (src._data) { _data = new byte[_size]; assert(_data); - memcpy(_data, src._data, _size*sizeof(byte)); + memcpy(_data, src._data, _size * sizeof(byte)); } if (src._mask) { _mask = new byte[_size]; assert(_mask); - memcpy(_mask, src._mask, _size*sizeof(byte)); + memcpy(_mask, src._mask, _size * sizeof(byte)); } memset(_name, 0, sizeof(_name)); @@ -272,8 +272,7 @@ byte AnimData::getColor(int x, int y) { * @param transparent Transparent color (for ANIM_MASKSPRITE) */ void AnimData::load(byte *d, int type, uint16 w, uint16 h, int16 file, - int16 frame, const char *n, byte transparent) { - + int16 frame, const char *n, byte transparent) { assert(d); if (_data) { @@ -299,7 +298,7 @@ void AnimData::load(byte *d, int type, uint16 w, uint16 h, int16 file, _size = w * h; _data = new byte[_size]; assert(_data); - memcpy(_data, d, _size*sizeof(byte)); + memcpy(_data, d, _size * sizeof(byte)); break; case ANIM_MASK: @@ -536,7 +535,7 @@ int loadSpl(const char *resourceName, int16 idx) { entry = idx < 0 ? emptyAnimSpace() : idx; assert(entry >= 0); - g_cine->_animDataTable[entry].load(dataPtr, ANIM_RAW, g_cine->_partBuffer[foundFileIdx].unpackedSize, 1, foundFileIdx, 0, currentPartName); + g_cine->_animDataTable[entry].load(dataPtr + 0x16, ANIM_RAW, g_cine->_partBuffer[foundFileIdx].unpackedSize - 0x16, 1, foundFileIdx, 0, currentPartName); free(dataPtr); return entry + 1; @@ -546,9 +545,10 @@ int loadSpl(const char *resourceName, int16 idx) { * Load 1bpp mask * @param resourceName Mask filename * @param idx Target index in animDataTable (-1 if any empty space will do) + * @param frameIndex frame of animation to load (-1 for all frames) * @return The number of the animDataTable entry after the loaded mask (-1 if error) */ -int loadMsk(const char *resourceName, int16 idx) { +int loadMsk(const char *resourceName, int16 idx, int16 frameIndex) { int16 foundFileIdx = findFileInBundle(resourceName); if (foundFileIdx < 0) { return -1; @@ -563,9 +563,18 @@ int loadMsk(const char *resourceName, int16 idx) { loadAnimHeader(animHeader, readS); ptr = dataPtr + 0x16; + int16 startFrame = 0; + int16 endFrame = animHeader.numFrames; + + if (frameIndex >= 0) { + startFrame = frameIndex; + endFrame = frameIndex + 1; + ptr += frameIndex * animHeader.frameWidth * animHeader.frameHeight; + } + entry = idx < 0 ? emptyAnimSpace() : idx; assert(entry >= 0); - for (int16 i = 0; i < animHeader.numFrames; i++, entry++) { + for (int16 i = startFrame; i < endFrame; i++, entry++) { g_cine->_animDataTable[entry].load(ptr, ANIM_MASK, animHeader.frameWidth, animHeader.frameHeight, foundFileIdx, i, currentPartName); ptr += animHeader.frameWidth * animHeader.frameHeight; } @@ -578,9 +587,10 @@ int loadMsk(const char *resourceName, int16 idx) { * Load animation * @param resourceName Animation filename * @param idx Target index in animDataTable (-1 if any empty space will do) + * @param frameIndex frame of animation to load (-1 for all frames) * @return The number of the animDataTable entry after the loaded animation (-1 if error) */ -int loadAni(const char *resourceName, int16 idx) { +int loadAni(const char *resourceName, int16 idx, int16 frameIndex) { int16 foundFileIdx = findFileInBundle(resourceName); if (foundFileIdx < 0) { return -1; @@ -596,6 +606,15 @@ int loadAni(const char *resourceName, int16 idx) { loadAnimHeader(animHeader, readS); ptr = dataPtr + 0x16; + int16 startFrame = 0; + int16 endFrame = animHeader.numFrames; + + if (frameIndex >= 0) { + startFrame = frameIndex; + endFrame = frameIndex + 1; + ptr += frameIndex * animHeader.frameWidth * animHeader.frameHeight; + } + transparentColor = getAnimTransparentColor(resourceName); // TODO: Merge this special case hack into getAnimTransparentColor somehow. @@ -609,7 +628,7 @@ int loadAni(const char *resourceName, int16 idx) { entry = idx < 0 ? emptyAnimSpace() : idx; assert(entry >= 0); - for (int16 i = 0; i < animHeader.numFrames; i++, entry++) { + for (int16 i = startFrame; i < endFrame; i++, entry++) { // special case transparency handling if (!strcmp(resourceName, "L2202.ANI")) { transparentColor = i < 2 ? 0 : 7; @@ -669,13 +688,13 @@ void convert8BBP2(byte *dest, byte *source, int16 width, int16 height) { *(source + k) <<= 1; if (k > 0 + m) color <<= 1; - } // end k + } // end k *(dest++) = color; - } // end i - } // end m + } // end i + } // end m source += 0x10; - } // end j + } // end j } /** @@ -685,7 +704,7 @@ void convert8BBP2(byte *dest, byte *source, int16 width, int16 height) { * @param frameIndex frame of animation to load (-1 for all frames) * @return The number of the animDataTable entry after the loaded image set (-1 if error) */ -int loadSet(const char *resourceName, int16 idx, int16 frameIndex =-1 ) { +int loadSet(const char *resourceName, int16 idx, int16 frameIndex = -1) { AnimHeader2Struct header2; uint16 numSpriteInAnim; int16 foundFileIdx = findFileInBundle(resourceName); @@ -712,10 +731,9 @@ int loadSet(const char *resourceName, int16 idx, int16 frameIndex =-1 ) { int16 startFrame = 0; int16 endFrame = numSpriteInAnim; - if(frameIndex>=0) - { + if (frameIndex >= 0) { startFrame = frameIndex; - endFrame = frameIndex+1; + endFrame = frameIndex + 1; ptr += 0x10 * frameIndex; } @@ -766,7 +784,7 @@ int loadSeq(const char *resourceName, int16 idx) { byte *dataPtr = readBundleFile(foundFileIdx); int entry = idx < 0 ? emptyAnimSpace() : idx; - g_cine->_animDataTable[entry].load(dataPtr+0x16, ANIM_RAW, g_cine->_partBuffer[foundFileIdx].unpackedSize-0x16, 1, foundFileIdx, 0, currentPartName); + g_cine->_animDataTable[entry].load(dataPtr + 0x16, ANIM_RAW, g_cine->_partBuffer[foundFileIdx].unpackedSize - 0x16, 1, foundFileIdx, 0, currentPartName); free(dataPtr); return entry + 1; } @@ -783,11 +801,11 @@ int loadResource(const char *resourceName, int16 idx, int16 frameIndex) { if (strstr(resourceName, ".SPL")) { result = loadSpl(resourceName, idx); } else if (strstr(resourceName, ".MSK")) { - result = loadMsk(resourceName, idx); + result = loadMsk(resourceName, idx, frameIndex); } else if (strstr(resourceName, ".ANI")) { - result = loadAni(resourceName, idx); + result = loadAni(resourceName, idx, frameIndex); } else if (strstr(resourceName, ".ANM")) { - result = loadAni(resourceName, idx); + result = loadAni(resourceName, idx, frameIndex); } else if (strstr(resourceName, ".SET")) { result = loadSet(resourceName, idx, frameIndex); } else if (strstr(resourceName, ".SEQ")) { diff --git a/engines/cine/cine.cpp b/engines/cine/cine.cpp index bbe2cd4896..aa7221f733 100644 --- a/engines/cine/cine.cpp +++ b/engines/cine/cine.cpp @@ -189,7 +189,18 @@ void CineEngine::initialize() { g_cine->_messageTable.clear(); resetObjectTable(); - disableSystemMenu = 1; + if (getGameType() == Cine::GType_OS) { + disableSystemMenu = 1; + } else { + // WORKAROUND: We do not save this variable in FW's savegames. + // Initializing this to 1, like we do it in the OS case, will + // cause the menu disabled when loading from the launcher or + // command line. + // A proper fix here would be to save this variable in FW's saves. + // Since it seems these are unversioned so far, there would be need + // to properly add versioning to them first. + disableSystemMenu = 0; + } var8 = 0; diff --git a/engines/cine/cine.h b/engines/cine/cine.h index 55376dce29..47edf51c30 100644 --- a/engines/cine/cine.h +++ b/engines/cine/cine.h @@ -159,7 +159,7 @@ private: bool _preLoad; int _timerDelayMultiplier; - public: +public: // TODO: These are pseudo-global vars // They better belong to appropriate classes Common::Array<AnimData> _animDataTable; diff --git a/engines/cine/console.cpp b/engines/cine/console.cpp index 0a24b2408a..4af28592e7 100644 --- a/engines/cine/console.cpp +++ b/engines/cine/console.cpp @@ -28,7 +28,7 @@ namespace Cine { bool labyrinthCheat; CineConsole::CineConsole(CineEngine *vm) : GUI::Debugger(), _vm(vm) { - DCmd_Register("labyrinthCheat", WRAP_METHOD(CineConsole, Cmd_LabyrinthCheat)); + DCmd_Register("labyrinthCheat", WRAP_METHOD(CineConsole, Cmd_LabyrinthCheat)); labyrinthCheat = false; } diff --git a/engines/cine/gfx.cpp b/engines/cine/gfx.cpp index 7a988227f6..636c0cf8d9 100644 --- a/engines/cine/gfx.cpp +++ b/engines/cine/gfx.cpp @@ -113,7 +113,7 @@ FWRenderer::FWRenderer() : _background(NULL), _backupPal(), _cmd(""), assert(_backBuffer); memset(_backBuffer, 0, _screenSize); - memset(_bgName, 0, sizeof (_bgName)); + memset(_bgName, 0, sizeof(_bgName)); } @@ -249,7 +249,7 @@ void FWRenderer::drawCommand() { unsigned int i; int x = 10, y = _cmdY; - if(disableSystemMenu == 0) { + if (disableSystemMenu == 0) { drawPlainBox(x, y, 301, 11, 0); drawBorder(x - 1, y - 1, 302, 12, 2); @@ -307,7 +307,7 @@ void FWRenderer::drawMessage(const char *str, int x, int y, int width, int color i++; line = fitLine(str + i, tw, words, cw); - if ( str[i + line] != '\0' && str[i + line] != 0x7C && words) { + if (str[i + line] != '\0' && str[i + line] != 0x7C && words) { space = (tw - cw) / words; extraSpace = (tw - cw) % words; } else { @@ -471,6 +471,41 @@ int FWRenderer::drawChar(char character, int x, int y) { return x; } +/** + * Clears the character glyph to black + * This function is called "undrawChar", because the original only applies + * this drawing after the original glyph has been drawn. + * Possible TODO: Find a better name. + * @param character Character to undraw + * @param x Character coordinate + * @param y Character coordinate + */ +int FWRenderer::undrawChar(char character, int x, int y) { + int width, idx; + + if (character == ' ') { + x += 5; + } else if ((width = g_cine->_textHandler.fontParamTable[(unsigned char)character].characterWidth)) { + idx = g_cine->_textHandler.fontParamTable[(unsigned char)character].characterIdx; + const byte *sprite = g_cine->_textHandler.textTable[idx][FONT_DATA]; + for (uint i = 0; i < FONT_HEIGHT; ++i) { + byte *dst = _backBuffer + (y + i) * 320 + x; + for (uint j = 0; j < FONT_WIDTH; ++j, ++dst) { + // The original does this based on whether bit 1 of the pixel + // is set. Since that's the only bit ever set in (FW) this + // check should be fine. + // TODO: Check how Operation Stealth Amiga works + if (*sprite++) { + *dst = 0; + } + } + } + x += width + 1; + } + + return x; +} + int FWRenderer::getStringWidth(const char *str) { const char *p = str; int width = 0; @@ -969,20 +1004,29 @@ void SelectionMenu::drawMenu(FWRenderer &r, bool top) { charX = x + 4; if (i == _selection) { + int color; + if (isAmiga) { - // The original Amiga version is using a different highlight color here, - // but with our current code it is not possible to change the text color, - // thus we can not use the Amiga's color, since otherwise the text - // wouldn't be visible anymore. - r.drawPlainBox(charX, lineY, _width - 8, FONT_HEIGHT, top ? r._messageBg/*2*/ : 18); + if (top) { + color = 2; + } else { + color = 18; + } } else { - r.drawPlainBox(charX, lineY, _width - 8, 9, 0); + color = 0; } + + r.drawPlainBox(x + 2, lineY - 1, _width - 3, 9, color); } const int size = _elements[i].size(); - for (int j = 0; j < size; ++j) - charX = r.drawChar(_elements[i][j], charX, lineY); + for (int j = 0; j < size; ++j) { + if (isAmiga && i == _selection) { + charX = r.undrawChar(_elements[i][j], charX, lineY); + } else { + charX = r.drawChar(_elements[i][j], charX, lineY); + } + } } } @@ -1244,6 +1288,7 @@ void OSRenderer::renderOverlay(const Common::List<overlay>::iterator &it) { sprite = &g_cine->_animDataTable[g_cine->_objectTable[it->objIdx].frame]; drawSprite(&(*it), sprite->data(), sprite->_realWidth, sprite->_height, _backBuffer, g_cine->_objectTable[it->objIdx].x, g_cine->_objectTable[it->objIdx].y, g_cine->_objectTable[it->objIdx].part, sprite->_bpp); break; + // game message case 2: if (it->objIdx >= g_cine->_messageTable.size()) { @@ -1300,7 +1345,7 @@ void OSRenderer::renderOverlay(const Common::List<overlay>::iterator &it) { height = obj->costume; drawPlainBox(obj->x, obj->y, width, height, color); debug(5, "renderOverlay: type=%d, x=%d, y=%d, width=%d, height=%d, color=%d", - it->type, obj->x, obj->y, width, height, color); + it->type, obj->x, obj->y, width, height, color); break; // something else @@ -1424,7 +1469,7 @@ void OSRenderer::selectBg(unsigned int idx) { if (_bgTable[idx].bg) { assert(_bgTable[idx].pal.isValid() && !(_bgTable[idx].pal.empty())); - _currentBg = idx; + _currentBg = idx; } else warning("OSRenderer::selectBg(%d) - attempt to select null background", idx); reloadPalette(); @@ -1750,23 +1795,23 @@ void OSRenderer::drawSprite(overlay *overlayPtr, const byte *spritePtr, int16 wi // draw the mask based on next objects in the list Common::List<overlay>::iterator it; - for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ++it) { - if(&(*it) == overlayPtr) { + for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ++it) { + if (&(*it) == overlayPtr) { break; } } - while(it != g_cine->_overlayList.end()) { + while (it != g_cine->_overlayList.end()) { overlay *pCurrentOverlay = &(*it); if ((pCurrentOverlay->type == 5) || ((pCurrentOverlay->type == 21) && (pCurrentOverlay->x == overlayPtr->objIdx))) { AnimData *sprite = &g_cine->_animDataTable[g_cine->_objectTable[it->objIdx].frame]; if (pMask == NULL) { - pMask = new byte[width*height]; + pMask = new byte[width * height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - byte spriteColor= spritePtr[width * i + j]; + byte spriteColor = spritePtr[width * i + j]; pMask[width * i + j] = spriteColor; } } @@ -1777,7 +1822,7 @@ void OSRenderer::drawSprite(overlay *overlayPtr, const byte *spritePtr, int16 wi int inMaskX = (g_cine->_objectTable[it->objIdx].x + i) - x; int inMaskY = (g_cine->_objectTable[it->objIdx].y + j) - y; - if (inMaskX >=0 && inMaskX < width) { + if (inMaskX >= 0 && inMaskX < width) { if (inMaskY >= 0 && inMaskY < height) { if (sprite->_bpp == 1) { if (!sprite->getColor(i, j)) { @@ -1793,7 +1838,7 @@ void OSRenderer::drawSprite(overlay *overlayPtr, const byte *spritePtr, int16 wi } // now, draw with the mask we created - if(pMask) { + if (pMask) { spritePtr = pMask; } @@ -1808,7 +1853,7 @@ void OSRenderer::drawSprite(overlay *overlayPtr, const byte *spritePtr, int16 wi destPtr += i * 320; for (int j = 0; j < width; j++) { - byte color= *(spritePtr++); + byte color = *(spritePtr++); if ((transparentColor != color) && x + j >= 0 && x + j < 320 && i + y >= 0 && i + y < 200) { *(destPtr++) = color; } else { diff --git a/engines/cine/gfx.h b/engines/cine/gfx.h index 3434cf9fc2..8b8843fd72 100644 --- a/engines/cine/gfx.h +++ b/engines/cine/gfx.h @@ -152,6 +152,7 @@ protected: void drawBorder(int x, int y, int width, int height, byte color); void drawDoubleBorder(int x, int y, int width, int height, byte color); virtual int drawChar(char character, int x, int y); + virtual int undrawChar(char character, int x, int y); void drawLine(int x, int y, int width, int height, byte color); void remaskSprite(byte *mask, Common::List<overlay>::iterator it); virtual void drawBackground(); @@ -287,7 +288,7 @@ byte gfxGetColor(int16 x, int16 y, const byte *ptr, int16 width); void gfxResetRawPage(byte *pageRaw); void gfxConvertSpriteToRaw(byte *dst, const byte *src, uint16 w, uint16 h); -void gfxCopyRawPage(byte *source, byte * dest); +void gfxCopyRawPage(byte *source, byte *dest); void gfxFlipRawPage(byte *frontBuffer); void drawSpriteRaw(const byte *spritePtr, const byte *maskPtr, int16 width, int16 height, byte *page, int16 x, int16 y); void gfxDrawPlainBoxRaw(int16 x1, int16 y1, int16 x2, int16 y2, byte color, byte *page); diff --git a/engines/cine/main_loop.cpp b/engines/cine/main_loop.cpp index f13f38a45e..c822f1cabd 100644 --- a/engines/cine/main_loop.cpp +++ b/engines/cine/main_loop.cpp @@ -180,19 +180,19 @@ static void processEvent(Common::Event &event) { case Common::KEYCODE_F11: renderer->showCollisionPage(false); break; - case Common::KEYCODE_KP5: // Emulated left mouse button click - case Common::KEYCODE_LEFT: // Left - case Common::KEYCODE_KP4: // Left + case Common::KEYCODE_KP5: // Emulated left mouse button click + case Common::KEYCODE_LEFT: // Left + case Common::KEYCODE_KP4: // Left case Common::KEYCODE_RIGHT: // Right - case Common::KEYCODE_KP6: // Right - case Common::KEYCODE_UP: // Up - case Common::KEYCODE_KP8: // Up - case Common::KEYCODE_DOWN: // Down - case Common::KEYCODE_KP2: // Down - case Common::KEYCODE_KP9: // Up & Right - case Common::KEYCODE_KP7: // Up & Left - case Common::KEYCODE_KP1: // Down & Left - case Common::KEYCODE_KP3: // Down & Right + case Common::KEYCODE_KP6: // Right + case Common::KEYCODE_UP: // Up + case Common::KEYCODE_KP8: // Up + case Common::KEYCODE_DOWN: // Down + case Common::KEYCODE_KP2: // Down + case Common::KEYCODE_KP9: // Up & Right + case Common::KEYCODE_KP7: // Up & Left + case Common::KEYCODE_KP1: // Down & Left + case Common::KEYCODE_KP3: // Down & Right // Stop ego movement made with keyboard when releasing a known key moveUsingKeyboard(0, 0); break; @@ -217,7 +217,6 @@ void manageEvents() { g_system->delayMillis(20); } while (g_system->getMillis() < nextFrame); - g_sound->update(); mouseData.left = mouseLeft; mouseData.right = mouseRight; } @@ -434,9 +433,9 @@ void CineEngine::mainLoop(int bootScriptIdx) { hideMouse(); g_sound->stopMusic(); - // if (g_cine->getGameType() == Cine::GType_OS) { + //if (g_cine->getGameType() == Cine::GType_OS) { // freeUnkList(); - // } + //} closePart(); } diff --git a/engines/cine/object.cpp b/engines/cine/object.cpp index afd95c04b0..a75828abb1 100644 --- a/engines/cine/object.cpp +++ b/engines/cine/object.cpp @@ -59,7 +59,7 @@ void loadObject(char *pObjectName) { assert(numEntry <= NUM_MAX_OBJECT); for (i = 0; i < numEntry; i++) { - if (g_cine->_objectTable[i].costume != -2 && g_cine->_objectTable[i].costume != -3) { // flag is keep ? + if (g_cine->_objectTable[i].costume != -2 && g_cine->_objectTable[i].costume != -3) { // flag is keep? Common::MemoryReadStream readS(ptr, entrySize); g_cine->_objectTable[i].x = readS.readSint16BE(); diff --git a/engines/cine/pal.cpp b/engines/cine/pal.cpp index 779c279ea1..10077ecdc9 100644 --- a/engines/cine/pal.cpp +++ b/engines/cine/pal.cpp @@ -92,7 +92,8 @@ void loadRelatedPalette(const char *fileName) { paletteIndex = findPaletteFromName(localName); if (paletteIndex == -1) { - for (i = 0; i < 16; i++) { // generate default palette + // generate default palette + for (i = 0; i < 16; i++) { paletteBuffer1[i] = paletteBuffer2[i] = (i << 4) + i; } } else { diff --git a/engines/cine/part.cpp b/engines/cine/part.cpp index 03cb743b46..813cbe50af 100644 --- a/engines/cine/part.cpp +++ b/engines/cine/part.cpp @@ -263,7 +263,7 @@ byte *readBundleSoundFile(const char *entryName, uint32 *size) { /** Rotate byte value to the left by n bits */ byte rolByte(byte value, uint n) { n %= 8; - return (byte) ((value << n) | (value >> (8 - n))); + return (byte)((value << n) | (value >> (8 - n))); } byte *readFile(const char *filename, bool crypted) { diff --git a/engines/cine/saveload.cpp b/engines/cine/saveload.cpp index 20952eea52..51d2c1f6be 100644 --- a/engines/cine/saveload.cpp +++ b/engines/cine/saveload.cpp @@ -1002,7 +1002,7 @@ void loadResourcesFromSave(Common::SeekableReadStream &fHandle, enum CineSaveGam const int entrySize = ((saveGameFormat == ANIMSIZE_23) ? 23 : 30); const int fileStartPos = fHandle.pos(); - for(int resourceIndex=0; resourceIndex<NUM_MAX_ANIMDATA; resourceIndex++) { + for (int resourceIndex = 0; resourceIndex < NUM_MAX_ANIMDATA; resourceIndex++) { // Seek to the start of the current animation's entry fHandle.seek(fileStartPos + resourceIndex * entrySize); // Read in the current animation entry diff --git a/engines/cine/saveload.h b/engines/cine/saveload.h index 49c9c0cef7..fd661904af 100644 --- a/engines/cine/saveload.h +++ b/engines/cine/saveload.h @@ -68,7 +68,7 @@ enum CineSaveGameFormat { }; /** Identifier for the temporary Operation Stealth savegame format. */ -static const uint32 TEMP_OS_FORMAT_ID = MKTAG('T','E','M','P'); +static const uint32 TEMP_OS_FORMAT_ID = MKTAG('T', 'E', 'M', 'P'); /** The current version number of Operation Stealth's savegame format. */ static const uint32 CURRENT_OS_SAVE_VER = 1; diff --git a/engines/cine/script.h b/engines/cine/script.h index 3fc86c585b..a07c8d6cfc 100644 --- a/engines/cine/script.h +++ b/engines/cine/script.h @@ -227,6 +227,7 @@ protected: int o1_op72(); int o1_op73(); int o1_playSample(); + int o1_playSampleSwapped(); int o1_disableSystemMenu(); int o1_loadMask5(); int o1_unloadMask5(); diff --git a/engines/cine/script_fw.cpp b/engines/cine/script_fw.cpp index 9cbe3c3fab..b4fe68c343 100644 --- a/engines/cine/script_fw.cpp +++ b/engines/cine/script_fw.cpp @@ -196,7 +196,7 @@ void FWScript::setupTable() { { 0, 0 }, { &FWScript::o1_playSample, "bbwbww" }, /* 78 */ - { &FWScript::o1_playSample, "bbwbww" }, + { &FWScript::o1_playSampleSwapped, "bbwbww" }, { &FWScript::o1_disableSystemMenu, "b" }, { &FWScript::o1_loadMask5, "b" }, { &FWScript::o1_unloadMask5, "b" } @@ -352,7 +352,7 @@ void ScriptVars::load(Common::SeekableReadStream &fHandle, unsigned int len) { * Reset all values to 0 */ void ScriptVars::reset() { - memset( _vars, 0, _size * sizeof(int16)); + memset(_vars, 0, _size * sizeof(int16)); } /** @@ -380,10 +380,10 @@ RawScript::RawScript(const FWScriptInfo &info, const byte *data, uint16 s) : * Copy constructor */ RawScript::RawScript(const RawScript &src) : _size(src._size), - _data(new byte[_size+1]), _labels(src._labels) { + _data(new byte[_size + 1]), _labels(src._labels) { assert(_data); - memcpy(_data, src._data, _size+1); + memcpy(_data, src._data, _size + 1); } /** @@ -398,7 +398,7 @@ RawScript::~RawScript() { */ RawScript &RawScript::operator=(const RawScript &src) { assert(src._data); - byte *tmp = new byte[src._size+1]; + byte *tmp = new byte[src._size + 1]; assert(tmp); _labels = src._labels; @@ -443,14 +443,14 @@ int RawScript::getNextLabel(const FWScriptInfo &info, int offset) const { pos += 2; break; case 'c': { // byte != 0 ? byte : word - uint8 test = _data[pos]; + uint8 test = _data[pos]; + pos++; + if (test) { pos++; - if (test) { - pos++; - } else { - pos += 2; - } + } else { + pos += 2; } + } break; case 'l': // label return pos; @@ -459,7 +459,7 @@ int RawScript::getNextLabel(const FWScriptInfo &info, int offset) const { ; break; case 'x': // exit script - return -pos-1; + return -pos - 1; } } } @@ -498,9 +498,7 @@ void RawScript::computeLabels(const FWScriptInfo &info) { * * computeScriptStackFromScript replacement */ -uint16 RawScript::getLabel(const FWScriptInfo &info, byte index, uint16 offset) - const { - +uint16 RawScript::getLabel(const FWScriptInfo &info, byte index, uint16 offset) const { assert(_data); int pos = offset; @@ -519,7 +517,7 @@ uint16 RawScript::getLabel(const FWScriptInfo &info, byte index, uint16 offset) */ void RawScript::setData(const FWScriptInfo &info, const byte *data) { assert(!_data); // this function should be called only once per instance - _data = new byte[_size+1]; + _data = new byte[_size + 1]; assert(data && _data); memcpy(_data, data, _size * sizeof(byte)); @@ -553,7 +551,7 @@ byte RawScript::getByte(unsigned int pos) const { * @return Word of bytecode */ uint16 RawScript::getWord(unsigned int pos) const { - assert(_data && pos+1 < _size); + assert(_data && pos + 1 < _size); return READ_BE_UINT16(_data + pos); } @@ -566,7 +564,7 @@ uint16 RawScript::getWord(unsigned int pos) const { const char *RawScript::getString(unsigned int pos) const { assert(_data && pos < _size); - return (const char*)(_data+pos); + return (const char *)(_data + pos); } /** @@ -580,8 +578,8 @@ const char *RawScript::getString(unsigned int pos) const { * instance can be used. It leaves the instance in partially invalid state. */ RawObjectScript::RawObjectScript(uint16 s, uint16 p1, uint16 p2, uint16 p3) - : RawScript(s), _runCount(0), _param1(p1), _param2(p2), _param3(p3) -{ } + : RawScript(s), _runCount(0), _param1(p1), _param2(p2), _param3(p3) { +} /** * Complete constructor @@ -592,8 +590,9 @@ RawObjectScript::RawObjectScript(uint16 s, uint16 p1, uint16 p2, uint16 p3) * @param p3 Third object script parameter */ RawObjectScript::RawObjectScript(const FWScriptInfo &info, const byte *data, - uint16 s, uint16 p1, uint16 p2, uint16 p3) : RawScript(info, data, s), - _runCount(0), _param1(p1), _param2(p2), _param3(p3) { } + uint16 s, uint16 p1, uint16 p2, uint16 p3) + : RawScript(info, data, s), _runCount(0), _param1(p1), _param2(p2), _param3(p3) { +} /** * Contructor for global scripts @@ -603,7 +602,8 @@ RawObjectScript::RawObjectScript(const FWScriptInfo &info, const byte *data, FWScript::FWScript(const RawScript &script, int16 idx) : _script(script), _pos(0), _line(0), _compare(0), _index(idx), _labels(script.labels()), _localVars(LOCAL_VARS_SIZE), - _globalVars(g_cine->_globalVars), _info(new FWScriptInfo) { } + _globalVars(g_cine->_globalVars), _info(new FWScriptInfo) { +} /** * Copy constructor @@ -611,25 +611,27 @@ FWScript::FWScript(const RawScript &script, int16 idx) : _script(script), FWScript::FWScript(const FWScript &src) : _script(src._script), _pos(src._pos), _line(src._line), _compare(src._compare), _index(src._index), _labels(src._labels), _localVars(src._localVars), - _globalVars(src._globalVars), _info(new FWScriptInfo) { } + _globalVars(src._globalVars), _info(new FWScriptInfo) { +} /** * Contructor for global scripts in derived classes * @param script Script bytecode reference * @param idx Script bytecode index */ -FWScript::FWScript(const RawScript &script, int16 idx, FWScriptInfo *info) : - _script(script), _pos(0), _line(0), _compare(0), _index(idx), +FWScript::FWScript(const RawScript &script, int16 idx, FWScriptInfo *info) + : _script(script), _pos(0), _line(0), _compare(0), _index(idx), _labels(script.labels()), _localVars(LOCAL_VARS_SIZE), - _globalVars(g_cine->_globalVars), _info(info) { } + _globalVars(g_cine->_globalVars), _info(info) { +} /** * Constructor for object scripts in derived classes * @param script Script bytecode reference * @param idx Script bytecode index */ -FWScript::FWScript(RawObjectScript &script, int16 idx, FWScriptInfo *info) : - _script(script), _pos(0), _line(0), _compare(0), _index(idx), +FWScript::FWScript(RawObjectScript &script, int16 idx, FWScriptInfo *info) + : _script(script), _pos(0), _line(0), _compare(0), _index(idx), _labels(script.labels()), _localVars(LOCAL_VARS_SIZE), _globalVars(g_cine->_globalVars), _info(info) { @@ -639,8 +641,8 @@ FWScript::FWScript(RawObjectScript &script, int16 idx, FWScriptInfo *info) : /** * Copy constructor for derived classes */ -FWScript::FWScript(const FWScript &src, FWScriptInfo *info) : - _script(src._script), _pos(src._pos), _line(src._line), +FWScript::FWScript(const FWScript &src, FWScriptInfo *info) + : _script(src._script), _pos(src._pos), _line(src._line), _compare(src._compare), _index(src._index), _labels(src._labels), _localVars(src._localVars), _globalVars(src._globalVars), _info(info) { } @@ -704,7 +706,7 @@ void FWScript::load(const ScriptVars &labels, const ScriptVars &local, uint16 co int FWScript::execute() { int ret = 0; - if(_script._size) { + if (_script._size) { while (!ret) { _line = _pos; byte opcode = getNextByte(); @@ -1816,6 +1818,9 @@ int FWScript::o1_playSample() { if (g_cine->getPlatform() == Common::kPlatformAmiga || g_cine->getPlatform() == Common::kPlatformAtariST) { if (size == 0xFFFF) { size = g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height; + } else if (size > g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height) { + warning("o1_playSample: Got invalid sample size %d for sample %d", size, anim); + size = g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height; } if (channel < 10) { // || _currentOpcode == 0x78 int channel1, channel2; @@ -1823,8 +1828,8 @@ int FWScript::o1_playSample() { channel1 = 0; channel2 = 1; } else { - channel1 = 2; - channel2 = 3; + channel1 = 3; + channel2 = 2; } g_sound->playSound(channel1, freq, data, size, -1, volume, 63, repeat); g_sound->playSound(channel2, freq, data, size, 1, volume, 0, repeat); @@ -1858,6 +1863,53 @@ int FWScript::o1_playSample() { return 0; } +int FWScript::o1_playSampleSwapped() { + // TODO: The DOS version probably does not have any stereo support here + // since the only stereo output it supports should be the Roland MT-32. + // So it probably does the same as o1_playSample here. Checking this will + // be a good idea never the less. + if (g_cine->getPlatform() == Common::kPlatformPC) { + return o1_playSample(); + } + + debugC(5, kCineDebugScript, "Line: %d: playSampleInversed()", _line); + + byte anim = getNextByte(); + byte channel = getNextByte(); + + uint16 freq = getNextWord(); + byte repeat = getNextByte(); + + int16 volume = getNextWord(); + uint16 size = getNextWord(); + + const byte *data = g_cine->_animDataTable[anim].data(); + + if (!data) { + return 0; + } + + if (size == 0xFFFF) { + size = g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height; + } else if (size > g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height) { + warning("o1_playSampleSwapped: Got invalid sample size %d for sample %d", size, anim); + size = g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height; + } + + int channel1, channel2; + if (channel == 0) { + channel1 = 1; + channel2 = 0; + } else { + channel1 = 2; + channel2 = 3; + } + + g_sound->playSound(channel1, freq, data, size, -1, volume, 63, repeat); + g_sound->playSound(channel2, freq, data, size, 1, volume, 0, repeat); + return 0; +} + int FWScript::o1_disableSystemMenu() { byte param = getNextByte(); @@ -2074,1034 +2126,970 @@ void decompileScript(const byte *scriptPtr, uint16 scriptSize, uint16 scriptIdx) strcpy(lineBuffer, ""); switch (opcode - 1) { - case -1: - { - break; - } - case 0x0: - { - byte param1; - byte param2; - int16 param3; + case -1: { + break; + } + case 0x0: { + byte param1; + byte param2; + int16 param3; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(lineBuffer, "obj[%d]%s = %d\n", param1, getObjPramName(param2), param3); + sprintf(lineBuffer, "obj[%d]%s = %d\n", param1, getObjPramName(param2), param3); - break; - } - case 0x1: - { - byte param1; - byte param2; - byte param3; + break; + } + case 0x1: { + byte param1; + byte param2; + byte param3; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - param3 = *(localScriptPtr + position); - position++; + param3 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "var[%d]=obj[%d]%s\n", param3, param1, getObjPramName(param2)); - break; - } + sprintf(lineBuffer, "var[%d]=obj[%d]%s\n", param3, param1, getObjPramName(param2)); + break; + } case 0x2: case 0x3: case 0x4: case 0x5: - case 0x6: - { - byte param1; - byte param2; - int16 param3; - - param1 = *(localScriptPtr + position); - position++; - - param2 = *(localScriptPtr + position); - position++; - - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; - - if (opcode - 1 == 0x2) { - sprintf(lineBuffer, "obj[%d]%s+=%d\n", param1, getObjPramName(param2), param3); - } else if (opcode - 1 == 0x3) { - sprintf(lineBuffer, "obj[%d]%s-=%d\n", param1, getObjPramName(param2), param3); - } else if (opcode - 1 == 0x4) { - sprintf(lineBuffer, "obj[%d]%s+=obj[%d]%s\n", param1, getObjPramName(param2), param3, getObjPramName(param2)); - } else if (opcode - 1 == 0x5) { - sprintf(lineBuffer, "obj[%d]%s-=obj[%d]%s\n", param1, getObjPramName(param2), param3, getObjPramName(param2)); - } else if (opcode - 1 == 0x6) { - sprintf(compareString1, "obj[%d]%s", param1, getObjPramName(param2)); - sprintf(compareString2, "%d", param3); - } - break; + case 0x6: { + byte param1; + byte param2; + int16 param3; + + param1 = *(localScriptPtr + position); + position++; + + param2 = *(localScriptPtr + position); + position++; + + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; + + if (opcode - 1 == 0x2) { + sprintf(lineBuffer, "obj[%d]%s+=%d\n", param1, getObjPramName(param2), param3); + } else if (opcode - 1 == 0x3) { + sprintf(lineBuffer, "obj[%d]%s-=%d\n", param1, getObjPramName(param2), param3); + } else if (opcode - 1 == 0x4) { + sprintf(lineBuffer, "obj[%d]%s+=obj[%d]%s\n", param1, getObjPramName(param2), param3, getObjPramName(param2)); + } else if (opcode - 1 == 0x5) { + sprintf(lineBuffer, "obj[%d]%s-=obj[%d]%s\n", param1, getObjPramName(param2), param3, getObjPramName(param2)); + } else if (opcode - 1 == 0x6) { + sprintf(compareString1, "obj[%d]%s", param1, getObjPramName(param2)); + sprintf(compareString2, "%d", param3); } + break; + } case 0x7: - case 0x8: - { - byte param1; - int16 param2; - int16 param3; - int16 param4; - int16 param5; + case 0x8: { + byte param1; + int16 param2; + int16 param3; + int16 param4; + int16 param5; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param2 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param4 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param4 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param5 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param5 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - if (opcode - 1 == 0x7) { - sprintf(lineBuffer, "setupObject(Idx:%d,X:%d,Y:%d,mask:%d,frame:%d)\n", param1, param2, param3, param4, param5); - } else if (opcode - 1 == 0x8) { - sprintf(lineBuffer, "checkCollision(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); - } - break; + if (opcode - 1 == 0x7) { + sprintf(lineBuffer, "setupObject(Idx:%d,X:%d,Y:%d,mask:%d,frame:%d)\n", param1, param2, param3, param4, param5); + } else if (opcode - 1 == 0x8) { + sprintf(lineBuffer, "checkCollision(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); } - case 0x9: - { - byte param1; - int16 param2; + break; + } + case 0x9: { + byte param1; + int16 param2; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - if (param2) { - byte param3; - - param3 = *(localScriptPtr + position); - position++; - - if (param2 == 1) { - sprintf(lineBuffer, "var[%d]=var[%d]\n", param1, param3); - } else if (param2 == 2) { - sprintf(lineBuffer, "var[%d]=globalVar[%d]\n", param1, param3); - } else if (param2 == 3) { - sprintf(lineBuffer, "var[%d]=mouse.X\n", param1); - } else if (param2 == 4) { - sprintf(lineBuffer, "var[%d]=mouse.Y\n", param1); - } else if (param2 == 5) { - sprintf(lineBuffer, "var[%d]=rand() mod %d\n", param1, param3); - } else if (param2 == 8) { - sprintf(lineBuffer, "var[%d]=file[%d].packedSize\n", param1, param3); - } else if (param2 == 9) { - sprintf(lineBuffer, "var[%d]=file[%d].unpackedSize\n", param1, param3); - } else { - error("decompileScript: 0x09: param2 = %d", param2); - } - } else { - int16 param3; + if (param2) { + byte param3; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "var[%d]=%d\n", param1, param3); + if (param2 == 1) { + sprintf(lineBuffer, "var[%d]=var[%d]\n", param1, param3); + } else if (param2 == 2) { + sprintf(lineBuffer, "var[%d]=globalVar[%d]\n", param1, param3); + } else if (param2 == 3) { + sprintf(lineBuffer, "var[%d]=mouse.X\n", param1); + } else if (param2 == 4) { + sprintf(lineBuffer, "var[%d]=mouse.Y\n", param1); + } else if (param2 == 5) { + sprintf(lineBuffer, "var[%d]=rand() mod %d\n", param1, param3); + } else if (param2 == 8) { + sprintf(lineBuffer, "var[%d]=file[%d].packedSize\n", param1, param3); + } else if (param2 == 9) { + sprintf(lineBuffer, "var[%d]=file[%d].unpackedSize\n", param1, param3); + } else { + error("decompileScript: 0x09: param2 = %d", param2); } + } else { + int16 param3; - break; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; + + sprintf(lineBuffer, "var[%d]=%d\n", param1, param3); } + + break; + } case 0xA: case 0xB: case 0xC: - case 0xD: - { - byte param1; - byte param2; + case 0xD: { + byte param1; + byte param2; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); + param2 = *(localScriptPtr + position); + position++; + + if (param2) { + byte param3; + + param3 = *(localScriptPtr + position); position++; - if (param2) { - byte param3; + if (opcode - 1 == 0xA) { + sprintf(lineBuffer, "var[%d]+=var[%d]\n", param1, param3); + } else if (opcode - 1 == 0xB) { + sprintf(lineBuffer, "var[%d]-=var[%d]\n", param1, param3); + } else if (opcode - 1 == 0xC) { + sprintf(lineBuffer, "var[%d]*=var[%d]\n", param1, param3); + } else if (opcode - 1 == 0xD) { + sprintf(lineBuffer, "var[%d]/=var[%d]\n", param1, param3); + } + } else { + int16 param3; - param3 = *(localScriptPtr + position); - position++; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - if (opcode - 1 == 0xA) { - sprintf(lineBuffer, "var[%d]+=var[%d]\n", param1, param3); - } else if (opcode - 1 == 0xB) { - sprintf(lineBuffer, "var[%d]-=var[%d]\n", param1, param3); - } else if (opcode - 1 == 0xC) { - sprintf(lineBuffer, "var[%d]*=var[%d]\n", param1, param3); - } else if (opcode - 1 == 0xD) { - sprintf(lineBuffer, "var[%d]/=var[%d]\n", param1, param3); - } - } else { - int16 param3; - - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; - - if (opcode - 1 == 0xA) { - sprintf(lineBuffer, "var[%d]+=%d\n", param1, param3); - } else if (opcode - 1 == 0xB) { - sprintf(lineBuffer, "var[%d]-=%d\n", param1, param3); - } else if (opcode - 1 == 0xC) { - sprintf(lineBuffer, "var[%d]*=%d\n", param1, param3); - } else if (opcode - 1 == 0xD) { - sprintf(lineBuffer, "var[%d]/=%d\n", param1, param3); - } + if (opcode - 1 == 0xA) { + sprintf(lineBuffer, "var[%d]+=%d\n", param1, param3); + } else if (opcode - 1 == 0xB) { + sprintf(lineBuffer, "var[%d]-=%d\n", param1, param3); + } else if (opcode - 1 == 0xC) { + sprintf(lineBuffer, "var[%d]*=%d\n", param1, param3); + } else if (opcode - 1 == 0xD) { + sprintf(lineBuffer, "var[%d]/=%d\n", param1, param3); } - break; } - case 0xE: - { - byte param1; - byte param2; + break; + } + case 0xE: { + byte param1; + byte param2; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - if (param2) { - byte param3; + if (param2) { + byte param3; - param3 = *(localScriptPtr + position); - position++; + param3 = *(localScriptPtr + position); + position++; - if (param2 == 1) { - sprintf(compareString1, "var[%d]", param1); - sprintf(compareString2, "var[%d]", param3); + if (param2 == 1) { + sprintf(compareString1, "var[%d]", param1); + sprintf(compareString2, "var[%d]", param3); - } else if (param2 == 2) { - sprintf(compareString1, "var[%d]", param1); - sprintf(compareString2, "globalVar[%d]", param3); - } else { - error("decompileScript: 0x0E: param2 = %d", param2); - } + } else if (param2 == 2) { + sprintf(compareString1, "var[%d]", param1); + sprintf(compareString2, "globalVar[%d]", param3); } else { - int16 param3; + error("decompileScript: 0x0E: param2 = %d", param2); + } + } else { + int16 param3; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(compareString1, "var[%d]", param1); - sprintf(compareString2, "%d", param3); - } - break; + sprintf(compareString1, "var[%d]", param1); + sprintf(compareString2, "%d", param3); } - case 0xF: - { - byte param1; - byte param2; - byte param3; + break; + } + case 0xF: { + byte param1; + byte param2; + byte param3; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - param3 = *(localScriptPtr + position); - position++; + param3 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "obj[%d]%s=var[%d]\n", param1, getObjPramName(param2), param3); + sprintf(lineBuffer, "obj[%d]%s=var[%d]\n", param1, getObjPramName(param2), param3); - break; - } + break; + } case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: case 0x18: - case 0x19: - { - byte param; - - param = *(localScriptPtr + position); - position++; - - if (opcode - 1 == 0x13) { - sprintf(lineBuffer, "loadMask0(%d)\n", param); - } else if (opcode - 1 == 0x14) { - sprintf(lineBuffer, "unloadMask0(%d)\n", param); - } else if (opcode - 1 == 0x15) { - sprintf(lineBuffer, "OP_15(%d)\n", param); - } else if (opcode - 1 == 0x16) { - sprintf(lineBuffer, "loadMask1(%d)\n", param); - } else if (opcode - 1 == 0x17) { - sprintf(lineBuffer, "unloadMask0(%d)\n", param); - } else if (opcode - 1 == 0x18) { - sprintf(lineBuffer, "loadMask4(%d)\n", param); - } else if (opcode - 1 == 0x19) { - sprintf(lineBuffer, "unloadMask4(%d)\n", param); - } - break; + case 0x19: { + byte param; + + param = *(localScriptPtr + position); + position++; + + if (opcode - 1 == 0x13) { + sprintf(lineBuffer, "loadMask0(%d)\n", param); + } else if (opcode - 1 == 0x14) { + sprintf(lineBuffer, "unloadMask0(%d)\n", param); + } else if (opcode - 1 == 0x15) { + sprintf(lineBuffer, "OP_15(%d)\n", param); + } else if (opcode - 1 == 0x16) { + sprintf(lineBuffer, "loadMask1(%d)\n", param); + } else if (opcode - 1 == 0x17) { + sprintf(lineBuffer, "unloadMask0(%d)\n", param); + } else if (opcode - 1 == 0x18) { + sprintf(lineBuffer, "loadMask4(%d)\n", param); + } else if (opcode - 1 == 0x19) { + sprintf(lineBuffer, "unloadMask4(%d)\n", param); } - case 0x1A: - { - byte param; + break; + } + case 0x1A: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "OP_1A(%d)\n", param); + sprintf(lineBuffer, "OP_1A(%d)\n", param); - break; - } - case 0x1B: - { - sprintf(lineBuffer, "bgIncrustList.clear()\n"); - break; - } - case 0x1D: - { - byte param; + break; + } + case 0x1B: { + sprintf(lineBuffer, "bgIncrustList.clear()\n"); + break; + } + case 0x1D: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "label(%d)\n", param); + sprintf(lineBuffer, "label(%d)\n", param); - break; - } - case 0x1E: - { - byte param; + break; + } + case 0x1E: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "goto(%d)\n", param); + sprintf(lineBuffer, "goto(%d)\n", param); - break; - } + break; + } // If cases case 0x1F: case 0x20: case 0x21: case 0x22: case 0x23: - case 0x24: - { - byte param; - - param = *(localScriptPtr + position); - position++; - - if (opcode - 1 == 0x1F) { - sprintf(lineBuffer, "if(%s>%s) goto(%d)\n", compareString1, compareString2, param); - } else if (opcode - 1 == 0x20) { - sprintf(lineBuffer, "if(%s>=%s) goto(%d)\n", compareString1, compareString2, param); - } else if (opcode - 1 == 0x21) { - sprintf(lineBuffer, "if(%s<%s) goto(%d)\n", compareString1, compareString2, param); - } else if (opcode - 1 == 0x22) { - sprintf(lineBuffer, "if(%s<=%s) goto(%d)\n", compareString1, compareString2, param); - } else if (opcode - 1 == 0x23) { - sprintf(lineBuffer, "if(%s==%s) goto(%d)\n", compareString1, compareString2, param); - } else if (opcode - 1 == 0x24) { - sprintf(lineBuffer, "if(%s!=%s) goto(%d)\n", compareString1, compareString2, param); - } - break; + case 0x24: { + byte param; + + param = *(localScriptPtr + position); + position++; + + if (opcode - 1 == 0x1F) { + sprintf(lineBuffer, "if(%s>%s) goto(%d)\n", compareString1, compareString2, param); + } else if (opcode - 1 == 0x20) { + sprintf(lineBuffer, "if(%s>=%s) goto(%d)\n", compareString1, compareString2, param); + } else if (opcode - 1 == 0x21) { + sprintf(lineBuffer, "if(%s<%s) goto(%d)\n", compareString1, compareString2, param); + } else if (opcode - 1 == 0x22) { + sprintf(lineBuffer, "if(%s<=%s) goto(%d)\n", compareString1, compareString2, param); + } else if (opcode - 1 == 0x23) { + sprintf(lineBuffer, "if(%s==%s) goto(%d)\n", compareString1, compareString2, param); + } else if (opcode - 1 == 0x24) { + sprintf(lineBuffer, "if(%s!=%s) goto(%d)\n", compareString1, compareString2, param); } - case 0x25: - { - byte param; + break; + } + case 0x25: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "removeLabel(%d)\n", param); + sprintf(lineBuffer, "removeLabel(%d)\n", param); - break; - } - case 0x26: - { - byte param1; - byte param2; + break; + } + case 0x26: { + byte param1; + byte param2; - param1 = *(localScriptPtr + position); - position++; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; + param2 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "loop(--var[%d]) -> label(%d)\n", param1, param2); + sprintf(lineBuffer, "loop(--var[%d]) -> label(%d)\n", param1, param2); - break; - } + break; + } case 0x31: - case 0x32: - { - byte param; + case 0x32: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - if (opcode - 1 == 0x31) { - sprintf(lineBuffer, "startGlobalScript(%d)\n", param); - } else if (opcode - 1 == 0x32) { - sprintf(lineBuffer, "endGlobalScript(%d)\n", param); - } - break; + if (opcode - 1 == 0x31) { + sprintf(lineBuffer, "startGlobalScript(%d)\n", param); + } else if (opcode - 1 == 0x32) { + sprintf(lineBuffer, "endGlobalScript(%d)\n", param); } + break; + } case 0x3B: case 0x3C: case 0x3D: - case OP_loadPart: - { - if (opcode - 1 == 0x3B) { - sprintf(lineBuffer, "loadResource(%s)\n", localScriptPtr + position); - } else if (opcode - 1 == 0x3C) { - sprintf(lineBuffer, "loadBg(%s)\n", localScriptPtr + position); - } else if (opcode - 1 == 0x3D) { - sprintf(lineBuffer, "loadCt(%s)\n", localScriptPtr + position); - } else if (opcode - 1 == OP_loadPart) { - sprintf(lineBuffer, "loadPart(%s)\n", localScriptPtr + position); - } - - position += strlen((const char *)localScriptPtr + position) + 1; - break; - } - case 0x40: - { - sprintf(lineBuffer, "closePart()\n"); - break; - } - case OP_loadNewPrcName: - { - byte param; + case OP_loadPart: { + if (opcode - 1 == 0x3B) { + sprintf(lineBuffer, "loadResource(%s)\n", localScriptPtr + position); + } else if (opcode - 1 == 0x3C) { + sprintf(lineBuffer, "loadBg(%s)\n", localScriptPtr + position); + } else if (opcode - 1 == 0x3D) { + sprintf(lineBuffer, "loadCt(%s)\n", localScriptPtr + position); + } else if (opcode - 1 == OP_loadPart) { + sprintf(lineBuffer, "loadPart(%s)\n", localScriptPtr + position); + } + + position += strlen((const char *)localScriptPtr + position) + 1; + break; + } + case 0x40: { + sprintf(lineBuffer, "closePart()\n"); + break; + } + case OP_loadNewPrcName: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "loadPrc(%d,%s)\n", param, localScriptPtr + position); + sprintf(lineBuffer, "loadPrc(%d,%s)\n", param, localScriptPtr + position); - position += strlen((const char *)localScriptPtr + position) + 1; - break; - } - case OP_requestCheckPendingDataLoad: // nop - { - sprintf(lineBuffer, "requestCheckPendingDataLoad()\n"); - break; - } - case 0x45: - { - sprintf(lineBuffer, "blitAndFade()\n"); - break; - } - case 0x46: - { - sprintf(lineBuffer, "fadeToBlack()\n"); - break; - } - case 0x47: - { - byte param1; - byte param2; - int16 param3; - int16 param4; - int16 param5; + position += strlen((const char *)localScriptPtr + position) + 1; + break; + } + case OP_requestCheckPendingDataLoad: { // nop + sprintf(lineBuffer, "requestCheckPendingDataLoad()\n"); + break; + } + case 0x45: { + sprintf(lineBuffer, "blitAndFade()\n"); + break; + } + case 0x46: { + sprintf(lineBuffer, "fadeToBlack()\n"); + break; + } + case 0x47: { + byte param1; + byte param2; + int16 param3; + int16 param4; + int16 param5; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param4 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param4 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param5 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param5 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(lineBuffer, "transformPaletteRange(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); + sprintf(lineBuffer, "transformPaletteRange(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); - break; - } - case 0x49: - { - byte param; + break; + } + case 0x49: { + byte param; - param = *(localScriptPtr + position); - position++; + param = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "setDefaultMenuBgColor(%d)\n", param); + sprintf(lineBuffer, "setDefaultMenuBgColor(%d)\n", param); - break; - } - case 0x4F: - { - sprintf(lineBuffer, "break()\n"); - exitScript = 1; - break; - } - case 0x50: - { - sprintf(lineBuffer, "endScript()\n\n"); - break; - } - case 0x51: - { - byte param1; - int16 param2; - int16 param3; - int16 param4; - int16 param5; + break; + } + case 0x4F: { + sprintf(lineBuffer, "break()\n"); + exitScript = 1; + break; + } + case 0x50: { + sprintf(lineBuffer, "endScript()\n\n"); + break; + } + case 0x51: { + byte param1; + int16 param2; + int16 param3; + int16 param4; + int16 param5; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param2 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param4 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param4 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param5 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param5 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(lineBuffer, "message(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); + sprintf(lineBuffer, "message(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); - break; - } + break; + } case 0x52: - case 0x53: - { - byte param1; - byte param2; + case 0x53: { + byte param1; + byte param2; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - if (param2) { - byte param3; - - param3 = *(localScriptPtr + position); - position++; - - if (param2 == 1) { - if (opcode - 1 == 0x52) { - sprintf(lineBuffer, "globalVar[%d] = var[%d]\n", param1, param3); - } else if (opcode - 1 == 0x53) { - sprintf(compareString1, "globalVar[%d]", param1); - sprintf(compareString2, "var[%d]", param3); - } - } else if (param2 == 2) { - if (opcode - 1 == 0x52) { - sprintf(lineBuffer, "globalVar[%d] = globalVar[%d]\n", param1, param3); - } else if (opcode - 1 == 0x53) { - sprintf(compareString1, "globalVar[%d]", param1); - sprintf(compareString2, "globalVar[%d]", param3); - } - } else { - if (opcode - 1 == 0x52) { - error("decompileScript: 0x52: param2 = %d", param2); - } else if (opcode - 1 == 0x53) { - error("decompileScript: 0x53: param2 = %d", param2); - } - } - } else { - int16 param3; + if (param2) { + byte param3; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = *(localScriptPtr + position); + position++; + if (param2 == 1) { if (opcode - 1 == 0x52) { - sprintf(lineBuffer, "globalVar[%d] = %d\n", param1, param3); + sprintf(lineBuffer, "globalVar[%d] = var[%d]\n", param1, param3); } else if (opcode - 1 == 0x53) { sprintf(compareString1, "globalVar[%d]", param1); - sprintf(compareString2, "%d", param3); + sprintf(compareString2, "var[%d]", param3); + } + } else if (param2 == 2) { + if (opcode - 1 == 0x52) { + sprintf(lineBuffer, "globalVar[%d] = globalVar[%d]\n", param1, param3); + } else if (opcode - 1 == 0x53) { + sprintf(compareString1, "globalVar[%d]", param1); + sprintf(compareString2, "globalVar[%d]", param3); + } + } else { + if (opcode - 1 == 0x52) { + error("decompileScript: 0x52: param2 = %d", param2); + } else if (opcode - 1 == 0x53) { + error("decompileScript: 0x53: param2 = %d", param2); } } - break; - } - case 0x59: - { - sprintf(lineBuffer, "comment: %s\n", localScriptPtr + position); + } else { + int16 param3; - position += strlen((const char *)localScriptPtr + position); - break; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; + + if (opcode - 1 == 0x52) { + sprintf(lineBuffer, "globalVar[%d] = %d\n", param1, param3); + } else if (opcode - 1 == 0x53) { + sprintf(compareString1, "globalVar[%d]", param1); + sprintf(compareString2, "%d", param3); + } } - case 0x5A: - { - byte param1; - byte param2; + break; + } + case 0x59: { + sprintf(lineBuffer, "comment: %s\n", localScriptPtr + position); - param1 = *(localScriptPtr + position); - position++; + position += strlen((const char *)localScriptPtr + position); + break; + } + case 0x5A: { + byte param1; + byte param2; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "freePartRang(%d,%d)\n", param1, param2); + param2 = *(localScriptPtr + position); + position++; - break; - } - case 0x5B: - { - sprintf(lineBuffer, "unloadAllMasks()\n"); - break; - } - case 0x65: - { - sprintf(lineBuffer, "setupTableUnk1()\n"); - break; - } - case 0x66: - { - byte param1; - int16 param2; + sprintf(lineBuffer, "freePartRang(%d,%d)\n", param1, param2); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x5B: { + sprintf(lineBuffer, "unloadAllMasks()\n"); + break; + } + case 0x65: { + sprintf(lineBuffer, "setupTableUnk1()\n"); + break; + } + case 0x66: { + byte param1; + int16 param2; - param2 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param1 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "tableUnk1[%d] = %d\n", param1, param2); + param2 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - break; - } - case 0x68: - { - byte param; + sprintf(lineBuffer, "tableUnk1[%d] = %d\n", param1, param2); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x68: { + byte param; - sprintf(lineBuffer, "setPlayerCommandPosY(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x69: - { - sprintf(lineBuffer, "allowPlayerInput()\n"); - break; - } - case 0x6A: - { - sprintf(lineBuffer, "disallowPlayerInput()\n"); - break; - } - case 0x6B: - { - byte newDisk; + sprintf(lineBuffer, "setPlayerCommandPosY(%d)\n", param); - newDisk = *(localScriptPtr + position); - position++; + break; + } + case 0x69: { + sprintf(lineBuffer, "allowPlayerInput()\n"); + break; + } + case 0x6A: { + sprintf(lineBuffer, "disallowPlayerInput()\n"); + break; + } + case 0x6B: { + byte newDisk; - sprintf(lineBuffer, "changeDataDisk(%d)\n", newDisk); + newDisk = *(localScriptPtr + position); + position++; - break; - } - case 0x6D: - { - sprintf(lineBuffer, "loadDat(%s)\n", localScriptPtr + position); + sprintf(lineBuffer, "changeDataDisk(%d)\n", newDisk); - position += strlen((const char *)localScriptPtr + position) + 1; - break; - } - case 0x6E: // nop - { - sprintf(lineBuffer, "updateDat()\n"); - break; - } - case 0x6F: - { - sprintf(lineBuffer, "OP_6F() -> dat related\n"); - break; - } - case 0x70: - { - sprintf(lineBuffer, "stopSample()\n"); - break; - } - case 0x79: - { - byte param; + break; + } + case 0x6D: { + sprintf(lineBuffer, "loadDat(%s)\n", localScriptPtr + position); - param = *(localScriptPtr + position); - position++; + position += strlen((const char *)localScriptPtr + position) + 1; + break; + } + case 0x6E: { // nop + sprintf(lineBuffer, "updateDat()\n"); + break; + } + case 0x6F: { + sprintf(lineBuffer, "OP_6F() -> dat related\n"); + break; + } + case 0x70: { + sprintf(lineBuffer, "stopSample()\n"); + break; + } + case 0x79: { + byte param; - sprintf(lineBuffer, "disableSystemMenu(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } + sprintf(lineBuffer, "disableSystemMenu(%d)\n", param); + + break; + } case 0x77: - case 0x78: - { - byte param1; - byte param2; - int16 param3; - byte param4; - int16 param5; - int16 param6; + case 0x78: { + byte param1; + byte param2; + int16 param3; + byte param4; + int16 param5; + int16 param6; - param1 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param4 = *(localScriptPtr + position); - position++; + param4 = *(localScriptPtr + position); + position++; - param5 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param5 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param6 = READ_BE_UINT16(localScriptPtr + position); - position += 2; - - if (opcode - 1 == 0x77) { - sprintf(lineBuffer, "playSample(%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6); - } else if (opcode - 1 == 0x78) { - sprintf(lineBuffer, "OP_78(%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6); - } + param6 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - break; + if (opcode - 1 == 0x77) { + sprintf(lineBuffer, "playSample(%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6); + } else if (opcode - 1 == 0x78) { + sprintf(lineBuffer, "playSampleSwapped(%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6); } - case 0x7A: - { - byte param; - param = *(localScriptPtr + position); - position++; + break; + } + case 0x7A: { + byte param; - sprintf(lineBuffer, "OP_7A(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x7B: // OS only - { - byte param; + sprintf(lineBuffer, "OP_7A(%d)\n", param); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x7B: { // OS only + byte param; - sprintf(lineBuffer, "OP_7B(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x7F: // OS only - { - byte param1; - byte param2; - byte param3; - byte param4; - int16 param5; - int16 param6; - int16 param7; + sprintf(lineBuffer, "OP_7B(%d)\n", param); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x7F: { // OS only + byte param1; + byte param2; + byte param3; + byte param4; + int16 param5; + int16 param6; + int16 param7; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param3 = *(localScriptPtr + position); - position++; + param2 = *(localScriptPtr + position); + position++; - param4 = *(localScriptPtr + position); - position++; + param3 = *(localScriptPtr + position); + position++; - param5 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param4 = *(localScriptPtr + position); + position++; - param6 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param5 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param7 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param6 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(lineBuffer, "OP_7F(%d,%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6, param7); + param7 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - break; - } - case 0x80: // OS only - { - byte param1; - byte param2; + sprintf(lineBuffer, "OP_7F(%d,%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6, param7); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x80: { // OS only + byte param1; + byte param2; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "OP_80(%d,%d)\n", param1, param2); + param2 = *(localScriptPtr + position); + position++; - break; - } - case 0x82: // OS only - { - byte param1; - byte param2; - uint16 param3; - uint16 param4; - byte param5; + sprintf(lineBuffer, "OP_80(%d,%d)\n", param1, param2); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x82: { // OS only + byte param1; + byte param2; + uint16 param3; + uint16 param4; + byte param5; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param2 = *(localScriptPtr + position); + position++; - param4 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param5 = *(localScriptPtr + position); - position++; + param4 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(lineBuffer, "OP_82(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); + param5 = *(localScriptPtr + position); + position++; - break; - } - case 0x83: // OS only - { - byte param1; - byte param2; + sprintf(lineBuffer, "OP_82(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x83: { // OS only + byte param1; + byte param2; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "OP_83(%d,%d)\n", param1, param2); + param2 = *(localScriptPtr + position); + position++; - break; - } - case 0x89: // OS only - { - byte param; + sprintf(lineBuffer, "OP_83(%d,%d)\n", param1, param2); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x89: { // OS only + byte param; - sprintf(lineBuffer, "if(%s!=%s) goto next label(%d)\n", compareString1, compareString2, param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x8B: // OS only - { - byte param; + sprintf(lineBuffer, "if(%s!=%s) goto next label(%d)\n", compareString1, compareString2, param); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x8B: { // OS only + byte param; - sprintf(lineBuffer, "OP_8B(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x8C: // OS only - { - byte param; + sprintf(lineBuffer, "OP_8B(%d)\n", param); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x8C: { // OS only + byte param; - sprintf(lineBuffer, "OP_8C(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x8D: // OS only - { - int16 param1; - int16 param2; - int16 param3; - int16 param4; - int16 param5; - int16 param6; - int16 param7; - int16 param8; + sprintf(lineBuffer, "OP_8C(%d)\n", param); - param1 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + break; + } + case 0x8D: { // OS only + int16 param1; + int16 param2; + int16 param3; + int16 param4; + int16 param5; + int16 param6; + int16 param7; + int16 param8; - param2 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param1 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param3 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param2 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param4 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param3 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param5 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param4 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param6 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param5 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param7 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param6 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - param8 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + param7 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - sprintf(compareString1, "obj[%d]", param1); - sprintf(compareString2, "{%d,%d,%d,%d,%d,%d,%d}", param2, param3, param4, param5, param6, param7, param8); + param8 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - break; - } - case 0x8E: // OS only - { - byte param1; + sprintf(compareString1, "obj[%d]", param1); + sprintf(compareString2, "{%d,%d,%d,%d,%d,%d,%d}", param2, param3, param4, param5, param6, param7, param8); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x8E: { // OS only + byte param1; - sprintf(lineBuffer, "ADDBG(%d,%s)\n", param1, localScriptPtr + position); + param1 = *(localScriptPtr + position); + position++; - position += strlen((const char *)localScriptPtr + position); + sprintf(lineBuffer, "ADDBG(%d,%s)\n", param1, localScriptPtr + position); - break; - } - case 0x8F: // OS only - { - byte param; + position += strlen((const char *)localScriptPtr + position); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x8F: { // OS only + byte param; - sprintf(lineBuffer, "OP_8F(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x90: // OS only - { - byte param1; + sprintf(lineBuffer, "OP_8F(%d)\n", param); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0x90: { // OS only + byte param1; - sprintf(lineBuffer, "loadABS(%d,%s)\n", param1, localScriptPtr + position); + param1 = *(localScriptPtr + position); + position++; - position += strlen((const char *)localScriptPtr + position); + sprintf(lineBuffer, "loadABS(%d,%s)\n", param1, localScriptPtr + position); - break; - } - case 0x91: // OS only - { - byte param; + position += strlen((const char *)localScriptPtr + position); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x91: { // OS only + byte param; - sprintf(lineBuffer, "OP_91(%d)\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x9D: // OS only - { - byte param; + sprintf(lineBuffer, "OP_91(%d)\n", param); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x9D: { // OS only + byte param; - sprintf(lineBuffer, "OP_9D(%d) -> flip img idx\n", param); + param = *(localScriptPtr + position); + position++; - break; - } - case 0x9E: // OS only - { - byte param; + sprintf(lineBuffer, "OP_9D(%d) -> flip img idx\n", param); - param = *(localScriptPtr + position); - position++; + break; + } + case 0x9E: { // OS only + byte param; - if (param) { - byte param2; + param = *(localScriptPtr + position); + position++; - param2 = *(localScriptPtr + position); - position++; + if (param) { + byte param2; - sprintf(lineBuffer, "OP_9E(%d,%d)\n", param, param2); - } else { - int16 param2; + param2 = *(localScriptPtr + position); + position++; - param2 = READ_BE_UINT16(localScriptPtr + position); - position += 2; + sprintf(lineBuffer, "OP_9E(%d,%d)\n", param, param2); + } else { + int16 param2; - sprintf(lineBuffer, "OP_9E(%d,%d)\n", param, param2); - } + param2 = READ_BE_UINT16(localScriptPtr + position); + position += 2; - break; + sprintf(lineBuffer, "OP_9E(%d,%d)\n", param, param2); } - case 0xA0: // OS only - { - byte param1; - byte param2; - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0xA0: { // OS only + byte param1; + byte param2; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "OP_A0(%d,%d)\n", param1, param2); + param2 = *(localScriptPtr + position); + position++; - break; - } - case 0xA1: // OS only - { - byte param1; - byte param2; + sprintf(lineBuffer, "OP_A0(%d,%d)\n", param1, param2); - param1 = *(localScriptPtr + position); - position++; + break; + } + case 0xA1: { // OS only + byte param1; + byte param2; - param2 = *(localScriptPtr + position); - position++; + param1 = *(localScriptPtr + position); + position++; - sprintf(lineBuffer, "OP_A1(%d,%d)\n", param1, param2); + param2 = *(localScriptPtr + position); + position++; - break; - } - default: - { - sprintf(lineBuffer, "Unsupported opcode %X in decompileScript\n\n", opcode - 1); - position = scriptSize; - break; - } + sprintf(lineBuffer, "OP_A1(%d,%d)\n", param1, param2); + + break; + } + default: { + sprintf(lineBuffer, "Unsupported opcode %X in decompileScript\n\n", opcode - 1); + position = scriptSize; + break; + } } - // printf(lineBuffer); + //printf(lineBuffer); strcpy(decompileBuffer[decompileBufferPosition++], lineBuffer); exitScript = 0; diff --git a/engines/cine/sound.cpp b/engines/cine/sound.cpp index 52e1cdac7e..10404ae56b 100644 --- a/engines/cine/sound.cpp +++ b/engines/cine/sound.cpp @@ -153,7 +153,7 @@ const int AdLibSoundDriver::_freqTable[] = { const int AdLibSoundDriver::_freqTableCount = ARRAYSIZE(_freqTable); const int AdLibSoundDriver::_operatorsTable[] = { - 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21 + 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21 }; const int AdLibSoundDriver::_operatorsTableCount = ARRAYSIZE(_operatorsTable); @@ -614,7 +614,7 @@ void AdLibSoundDriverADL::playSample(const byte *data, int size, int channel, in } MidiSoundDriverH32::MidiSoundDriverH32(MidiDriver *output) - : _output(output), _callback(0), _mutex() { + : _output(output), _callback(0), _mutex() { } MidiSoundDriverH32::~MidiSoundDriverH32() { @@ -731,13 +731,13 @@ void MidiSoundDriverH32::selectInstrument(int channel, int timbreGroup, int timb 0x00, 0x00, 0x00, // offset 0x00, // Timbre group _ timbreGroup * 64 + timbreNumber should be the 0x00, // Timbre number / MT-32 instrument in case timbreGroup is 0 or 1. - 0x18, // Key shift (= 0) + 0x18, // Key shift (= 0) 0x32, // Fine tune (= 0) 0x0C, // Bender Range 0x03, // Assign Mode 0x01, // Reverb Switch (= enabled) 0x00, // dummy - 0x00, // Output level + 0x00, // Output level 0x07, // Panpot (= balanced) 0x00, // dummy 0x00, // dummy @@ -998,19 +998,55 @@ void PCSound::stopSound(int channel) { } PaulaSound::PaulaSound(Audio::Mixer *mixer, CineEngine *vm) - : Sound(mixer, vm) { + : Sound(mixer, vm), _sfxTimer(0), _musicTimer(0), _musicFadeTimer(0) { _moduleStream = 0; + // The original is using the following timer frequency: + // 0.709379Mhz / 8000 = 88.672375Hz + // 1000000 / 88.672375Hz = 11277.46944863us + g_system->getTimerManager()->installTimerProc(&PaulaSound::sfxTimerProc, 11277, this, "PaulaSound::sfxTimerProc"); + // The original is using the following timer frequency: + // 0.709379Mhz / 14565 = 48.704359Hz + // 1000000 / 48.704359Hz = 20532.04313806us + g_system->getTimerManager()->installTimerProc(&PaulaSound::musicTimerProc, 20532, this, "PaulaSound::musicTimerProc"); } PaulaSound::~PaulaSound() { + Common::StackLock sfxLock(_sfxMutex); + g_system->getTimerManager()->removeTimerProc(&PaulaSound::sfxTimerProc); for (int i = 0; i < NUM_CHANNELS; ++i) { stopSound(i); } + + Common::StackLock musicLock(_musicMutex); + g_system->getTimerManager()->removeTimerProc(&PaulaSound::musicTimerProc); stopMusic(); } void PaulaSound::loadMusic(const char *name) { debugC(5, kCineDebugSound, "PaulaSound::loadMusic('%s')", name); + for (int i = 0; i < NUM_CHANNELS; ++i) { + stopSound(i); + } + + // Fade music out when there is music playing. + _musicMutex.lock(); + if (_mixer->isSoundHandleActive(_moduleHandle)) { + // Only start fade out when it is not in progress. + if (!_musicFadeTimer) { + _musicFadeTimer = 1; + } + + _musicMutex.unlock(); + while (_musicFadeTimer != 64) { + g_system->delayMillis(50); + } + } else { + _musicMutex.unlock(); + } + + Common::StackLock lock(_musicMutex); + assert(!_mixer->isSoundHandleActive(_moduleHandle)); + if (_vm->getGameType() == GType_FW) { // look for separate files Common::File f; @@ -1031,54 +1067,135 @@ void PaulaSound::loadMusic(const char *name) { void PaulaSound::playMusic() { debugC(5, kCineDebugSound, "PaulaSound::playMusic()"); + Common::StackLock lock(_musicMutex); + _mixer->stopHandle(_moduleHandle); if (_moduleStream) { + _musicFadeTimer = 0; _mixer->playStream(Audio::Mixer::kMusicSoundType, &_moduleHandle, _moduleStream); } } void PaulaSound::stopMusic() { debugC(5, kCineDebugSound, "PaulaSound::stopMusic()"); + Common::StackLock lock(_musicMutex); + _mixer->stopHandle(_moduleHandle); } void PaulaSound::fadeOutMusic() { debugC(5, kCineDebugSound, "PaulaSound::fadeOutMusic()"); - // TODO - stopMusic(); + Common::StackLock lock(_musicMutex); + + _musicFadeTimer = 1; } void PaulaSound::playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat) { - // TODO: handle volume slides and repeat debugC(5, kCineDebugSound, "PaulaSound::playSound() channel %d size %d", channel, size); + Common::StackLock lock(_sfxMutex); + assert(frequency > 0); + stopSound(channel); - size = MIN<int>(size - SPL_HDR_SIZE, READ_BE_UINT16(data + 4)); - // TODO: consider skipping the header in loadSpl directly if (size > 0) { byte *sound = (byte *)malloc(size); if (sound) { - memcpy(sound, data + SPL_HDR_SIZE, size); - playSoundChannel(channel, frequency, sound, size, volume); + // Create the audio stream + memcpy(sound, data, size); + + // Clear the first and last 16 bits like in the original. + sound[0] = sound[1] = sound[size - 2] = sound[size - 1] = 0; + + Audio::SeekableAudioStream *stream = Audio::makeRawStream(sound, size, PAULA_FREQ / frequency, 0); + + // Initialize the volume control + _channelsTable[channel].initialize(volume, volumeStep, stepCount); + + // Start the sfx + _mixer->playStream(Audio::Mixer::kSFXSoundType, &_channelsTable[channel].handle, + Audio::makeLoopingAudioStream(stream, repeat ? 0 : 1), + -1, volume * Audio::Mixer::kMaxChannelVolume / 63, + _channelBalance[channel]); } } } void PaulaSound::stopSound(int channel) { debugC(5, kCineDebugSound, "PaulaSound::stopSound() channel %d", channel); - _mixer->stopHandle(_channelsTable[channel]); + Common::StackLock lock(_sfxMutex); + + _mixer->stopHandle(_channelsTable[channel].handle); } -void PaulaSound::update() { - // process volume slides and start sound playback - // TODO +void PaulaSound::sfxTimerProc(void *param) { + PaulaSound *sound = (PaulaSound *)param; + sound->sfxTimerCallback(); } -void PaulaSound::playSoundChannel(int channel, int frequency, uint8 *data, int size, int volume) { - assert(frequency > 0); - frequency = PAULA_FREQ / frequency; - Audio::AudioStream *stream = Audio::makeRawStream(data, size, frequency, 0); - _mixer->playStream(Audio::Mixer::kSFXSoundType, &_channelsTable[channel], stream); - _mixer->setChannelVolume(_channelsTable[channel], volume * Audio::Mixer::kMaxChannelVolume / 63); +void PaulaSound::sfxTimerCallback() { + Common::StackLock lock(_sfxMutex); + + if (_sfxTimer < 6) { + ++_sfxTimer; + + for (int i = 0; i < NUM_CHANNELS; ++i) { + // Only process active channels + if (!_mixer->isSoundHandleActive(_channelsTable[i].handle)) { + continue; + } + + if (_channelsTable[i].curStep) { + --_channelsTable[i].curStep; + } else { + _channelsTable[i].curStep = _channelsTable[i].stepCount; + const int volume = CLIP(_channelsTable[i].volume + _channelsTable[i].volumeStep, 0, 63); + _channelsTable[i].volume = volume; + // Unlike the original we stop silent sounds + if (volume) { + _mixer->setChannelVolume(_channelsTable[i].handle, volume * Audio::Mixer::kMaxChannelVolume / 63); + } else { + _mixer->stopHandle(_channelsTable[i].handle); + } + } + } + } else { + _sfxTimer = 0; + // Possible TODO: The original only ever started sounds here. This + // should not be noticable though. So we do not do it for now. + } } +void PaulaSound::musicTimerProc(void *param) { + PaulaSound *sound = (PaulaSound *)param; + sound->musicTimerCallback(); +} + +void PaulaSound::musicTimerCallback() { + Common::StackLock lock(_musicMutex); + + ++_musicTimer; + if (_musicTimer == 6) { + _musicTimer = 0; + if (_musicFadeTimer) { + ++_musicFadeTimer; + if (_musicFadeTimer == 64) { + stopMusic(); + } else { + if (_mixer->isSoundHandleActive(_moduleHandle)) { + _mixer->setChannelVolume(_moduleHandle, (64 - _musicFadeTimer) * Audio::Mixer::kMaxChannelVolume / 64); + } + } + } + } +} + +const int PaulaSound::_channelBalance[NUM_CHANNELS] = { + // L/R/R/L This is according to the Hardware Reference Manual. + // TODO: It seems the order is swapped for some Amiga models: + // http://www.amiga.org/forums/archive/index.php/t-7862.html + // Maybe we should consider using R/L/L/R to match Amiga 500? + // This also is a bit more drastic to what WineUAE defaults, + // which is only 70% of full panning. + -127, 127, 127, -127 +}; + } // End of namespace Cine diff --git a/engines/cine/sound.h b/engines/cine/sound.h index afc0994a26..fdb183ad34 100644 --- a/engines/cine/sound.h +++ b/engines/cine/sound.h @@ -24,6 +24,7 @@ #define CINE_SOUND_H_ #include "common/util.h" +#include "common/mutex.h" #include "audio/mixer.h" namespace Audio { @@ -47,7 +48,6 @@ public: virtual void playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat) = 0; virtual void stopSound(int channel) = 0; - virtual void update() {} protected: @@ -91,19 +91,39 @@ public: virtual void playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat); virtual void stopSound(int channel); - virtual void update(); enum { - PAULA_FREQ = 7093789, - NUM_CHANNELS = 4, - SPL_HDR_SIZE = 22 + PAULA_FREQ = 3579545, + NUM_CHANNELS = 4 }; protected: - void playSoundChannel(int channel, int frequency, uint8 *data, int size, int volume); - - Audio::SoundHandle _channelsTable[NUM_CHANNELS]; + struct SfxChannel { + Audio::SoundHandle handle; + int volume; + int volumeStep; + int curStep; + int stepCount; + + void initialize(int vol, int volStep, int stepCnt) { + volume = vol; + volumeStep = volStep; + curStep = stepCount = stepCnt; + } + }; + SfxChannel _channelsTable[NUM_CHANNELS]; + static const int _channelBalance[NUM_CHANNELS]; + Common::Mutex _sfxMutex; + int _sfxTimer; + static void sfxTimerProc(void *param); + void sfxTimerCallback(); + + Common::Mutex _musicMutex; + int _musicTimer; + int _musicFadeTimer; + static void musicTimerProc(void *param); + void musicTimerCallback(); Audio::SoundHandle _moduleHandle; Audio::AudioStream *_moduleStream; }; diff --git a/engines/cine/texte.cpp b/engines/cine/texte.cpp index 33ea569df7..998075c6ce 100644 --- a/engines/cine/texte.cpp +++ b/engines/cine/texte.cpp @@ -88,7 +88,7 @@ static const CharacterEntry fontParamTable_standard[NUM_FONT_CHARS] = { {64, 3}, {65, 3}, { 0, 0}, { 0, 0}, {62, 2}, {74, 6}, {66, 1}, {67, 6}, {52, 6}, {53, 6}, {54, 6}, {55, 6}, {56, 6}, {57, 6}, {58, 6}, {59, 6}, {60, 6}, {61, 6}, {76, 3}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {75, 6}, - { 0, 0}, { 0, 6}, //a + { 0, 0}, { 0, 6}, //a { 1, 6}, { 2, 6}, { 3, 6}, { 4, 6}, { 5, 6}, { 6, 6}, { 7, 6}, { 8, 3}, { 9, 6}, {10, 6}, {11, 6}, {12, 7}, {13, 6}, {14, 6}, {15, 6}, {16, 6}, {17, 6}, {18, 6}, {19, 6}, {20, 6}, {21, 6}, {22, 7}, diff --git a/engines/cine/texte.h b/engines/cine/texte.h index dd4b7e06ee..185dc53bfd 100644 --- a/engines/cine/texte.h +++ b/engines/cine/texte.h @@ -46,7 +46,7 @@ struct CharacterEntry { }; struct TextHandler { - byte textTable[NUM_FONT_CHARS][2][FONT_WIDTH * FONT_HEIGHT]; + byte textTable[NUM_FONT_CHARS][2][FONT_WIDTH *FONT_HEIGHT]; CharacterEntry fontParamTable[NUM_FONT_CHARS]; }; diff --git a/engines/cine/various.cpp b/engines/cine/various.cpp index eccd71cf05..23f439a7a7 100644 --- a/engines/cine/various.cpp +++ b/engines/cine/various.cpp @@ -99,8 +99,7 @@ byte isInPause = 0; * Bit on = mouse button down * Bit off = mouse button up */ -enum MouseButtonState -{ +enum MouseButtonState { kLeftMouseButton = (1 << 0), kRightMouseButton = (1 << 1) }; @@ -271,7 +270,7 @@ int16 getObjectUnderCursor(uint16 x, uint16 y) { } else if (it->type == 1 && gfxGetBit(xdif, ydif, g_cine->_animDataTable[frame].data(), g_cine->_animDataTable[frame]._width * 4)) { return it->objIdx; } - } else if (it->type == 0) { // use generated mask + } else if (it->type == 0) { // use generated mask if (gfxGetBit(xdif, ydif, g_cine->_animDataTable[frame].mask(), g_cine->_animDataTable[frame]._width)) { return it->objIdx; } @@ -358,128 +357,122 @@ void CineEngine::makeSystemMenu() { systemCommand = makeMenuChoice(systemMenu, numEntry, mouseX, mouseY, 140); switch (systemCommand) { - case 0: // Pause - { - renderer->drawString(otherMessages[2], 0); - waitPlayerInput(); - break; - } - case 1: // Restart Game - { - getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); - if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { - _restartRequested = true; - } - break; - } - case 2: // Quit - { - getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); - if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { - quitGame(); - } - break; + case 0: { // Pause + renderer->drawString(otherMessages[2], 0); + waitPlayerInput(); + break; + } + case 1: { // Restart Game + getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); + if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { + _restartRequested = true; } - case 3: // Select save drive... change ? - { - break; + break; + } + case 2: { // Quit + getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); + if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { + quitGame(); } - case 4: // load game - { - if (loadSaveDirectory()) { + break; + } + case 3: { // Select save drive... change ? + break; + } + case 4: { // load game + if (loadSaveDirectory()) { // int16 selectedSave; - getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); - selectedSave = makeMenuChoice(currentSaveName, 10, mouseX, mouseY + 8, 180); + getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); + selectedSave = makeMenuChoice(currentSaveName, 10, mouseX, mouseY + 8, 180); - if (selectedSave >= 0) { - char saveNameBuffer[256]; - sprintf(saveNameBuffer, "%s.%1d", _targetName.c_str(), selectedSave); + if (selectedSave >= 0) { + char saveNameBuffer[256]; + sprintf(saveNameBuffer, "%s.%1d", _targetName.c_str(), selectedSave); - getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); - if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { - char loadString[256]; + getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); + if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { + char loadString[256]; - sprintf(loadString, otherMessages[3], currentSaveName[selectedSave]); - renderer->drawString(loadString, 0); + sprintf(loadString, otherMessages[3], currentSaveName[selectedSave]); + renderer->drawString(loadString, 0); - makeLoad(saveNameBuffer); - } else { - renderer->drawString(otherMessages[4], 0); - waitPlayerInput(); - checkDataDisk(-1); - } + makeLoad(saveNameBuffer); } else { renderer->drawString(otherMessages[4], 0); waitPlayerInput(); checkDataDisk(-1); } } else { - renderer->drawString(otherMessages[5], 0); + renderer->drawString(otherMessages[4], 0); waitPlayerInput(); checkDataDisk(-1); } - break; + } else { + renderer->drawString(otherMessages[5], 0); + waitPlayerInput(); + checkDataDisk(-1); } - case 5: // Save game - { - loadSaveDirectory(); - selectedSave = makeMenuChoice(currentSaveName, 10, mouseX, mouseY + 8, 180); + break; + } + case 5: { // Save game + loadSaveDirectory(); + selectedSave = makeMenuChoice(currentSaveName, 10, mouseX, mouseY + 8, 180); - if (selectedSave >= 0) { - char saveFileName[256]; - char saveName[20]; - saveName[0] = 0; + if (selectedSave >= 0) { + char saveFileName[256]; + char saveName[20]; + saveName[0] = 0; - if (!makeTextEntryMenu(otherMessages[6], saveName, 20, 120)) - break; + if (!makeTextEntryMenu(otherMessages[6], saveName, 20, 120)) + break; - strncpy(currentSaveName[selectedSave], saveName, 20); + strncpy(currentSaveName[selectedSave], saveName, 20); - sprintf(saveFileName, "%s.%1d", _targetName.c_str(), selectedSave); + sprintf(saveFileName, "%s.%1d", _targetName.c_str(), selectedSave); - getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); - if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { - char saveString[256]; - Common::String tmp = Common::String::format("%s.dir", _targetName.c_str()); + getMouseData(mouseUpdateStatus, (uint16 *)&mouseButton, (uint16 *)&mouseX, (uint16 *)&mouseY); + if (!makeMenuChoice(confirmMenu, 2, mouseX, mouseY + 8, 100)) { + char saveString[256]; + Common::String tmp = Common::String::format("%s.dir", _targetName.c_str()); - Common::OutSaveFile *fHandle = _saveFileMan->openForSaving(tmp); - if (!fHandle) { - warning("Unable to open file %s for saving", tmp.c_str()); - break; - } + Common::OutSaveFile *fHandle = _saveFileMan->openForSaving(tmp); + if (!fHandle) { + warning("Unable to open file %s for saving", tmp.c_str()); + break; + } - fHandle->write(currentSaveName, 200); - delete fHandle; + fHandle->write(currentSaveName, 200); + delete fHandle; - sprintf(saveString, otherMessages[3], currentSaveName[selectedSave]); - renderer->drawString(saveString, 0); + sprintf(saveString, otherMessages[3], currentSaveName[selectedSave]); + renderer->drawString(saveString, 0); - makeSave(saveFileName); + makeSave(saveFileName); - checkDataDisk(-1); - } else { - renderer->drawString(otherMessages[4], 0); - waitPlayerInput(); - checkDataDisk(-1); - } + checkDataDisk(-1); + } else { + renderer->drawString(otherMessages[4], 0); + waitPlayerInput(); + checkDataDisk(-1); } - break; } + break; + } } inMenu = false; } } -void drawMessageBox(int16 x, int16 y, int16 width, int16 currentY, int16 offset, int16 color, byte* page) { - gfxDrawLine(x + offset, y + offset, x + width - offset, y + offset, color, page); // top - gfxDrawLine(x + offset, currentY + 4 - offset, x + width - offset, currentY + 4 - offset, color, page); // bottom - gfxDrawLine(x + offset, y + offset, x + offset, currentY + 4 - offset, color, page); // left - gfxDrawLine(x + width - offset, y + offset, x + width - offset, currentY + 4 - offset, color, page); // right +void drawMessageBox(int16 x, int16 y, int16 width, int16 currentY, int16 offset, int16 color, byte *page) { + gfxDrawLine(x + offset, y + offset, x + width - offset, y + offset, color, page); // top + gfxDrawLine(x + offset, currentY + 4 - offset, x + width - offset, currentY + 4 - offset, color, page); // bottom + gfxDrawLine(x + offset, y + offset, x + offset, currentY + 4 - offset, color, page); // left + gfxDrawLine(x + width - offset, y + offset, x + width - offset, currentY + 4 - offset, color, page); // right } -void drawDoubleMessageBox(int16 x, int16 y, int16 width, int16 currentY, int16 color, byte* page) { +void drawDoubleMessageBox(int16 x, int16 y, int16 width, int16 currentY, int16 color, byte *page) { drawMessageBox(x, y, width, currentY, 1, 0, page); drawMessageBox(x, y, width, currentY, 0, color, page); } @@ -581,7 +574,7 @@ void makeCommandLine() { g_cine->_commandBuffer = ""; } - if ((playerCommand != -1) && (choiceResultTable[playerCommand] == 2)) { // need object selection ? + if ((playerCommand != -1) && (choiceResultTable[playerCommand] == 2)) { // need object selection? int16 si; getMouseData(mouseUpdateStatus, &dummyU16, &x, &y); @@ -635,7 +628,7 @@ void makeCommandLine() { } if (g_cine->getGameType() == Cine::GType_OS && playerCommand != 2) { - if (playerCommand != -1 && canUseOnObject != 0) { // call use on sub object + if (playerCommand != -1 && canUseOnObject != 0) { // call use on sub object int16 si; getMouseData(mouseUpdateStatus, &dummyU16, &x, &y); @@ -742,11 +735,11 @@ int16 makeMenuChoice(const CommandeType commandList[], uint16 height, uint16 X, mainLoopSub6(); } - if (menuVar4 && currentSelection > 0) { // go up + if (menuVar4 && currentSelection > 0) { // go up currentSelection--; } - if (menuVar5) { // go down + if (menuVar5) { // go down if (height - 1 > currentSelection) { currentSelection++; } @@ -763,7 +756,7 @@ int16 makeMenuChoice(const CommandeType commandList[], uint16 height, uint16 X, } } - if (currentSelection != oldSelection) { // old != new + if (currentSelection != oldSelection) { // old != new if (needMouseSave) { hideMouse(); } @@ -789,7 +782,7 @@ int16 makeMenuChoice(const CommandeType commandList[], uint16 height, uint16 X, getMouseData(mouseUpdateStatus, &button, &dummyU16, &dummyU16); } while (button && !g_cine->shouldQuit()); - if (var_4 == 2) { // recheck + if (var_4 == 2) { // recheck if (!recheckValue) return -1; else @@ -809,7 +802,7 @@ void makeActionMenu() { getMouseData(mouseUpdateStatus, &mouseButton, &mouseX, &mouseY); if (g_cine->getGameType() == Cine::GType_OS) { - if(disableSystemMenu == 0) { + if (disableSystemMenu == 0) { playerCommand = makeMenuChoice(defaultActionCommand, 6, mouseX, mouseY, 70, true); } @@ -818,7 +811,7 @@ void makeActionMenu() { canUseOnObject = canUseOnItemTable[playerCommand]; } } else { - if(disableSystemMenu == 0) { + if (disableSystemMenu == 0) { playerCommand = makeMenuChoice(defaultActionCommand, 6, mouseX, mouseY, 70); } } @@ -1185,7 +1178,7 @@ void removeMessages() { Common::List<overlay>::iterator it; bool remove; - for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ) { + for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end();) { if (g_cine->getGameType() == Cine::GType_OS) { // NOTE: These are really removeOverlay calls that have been deferred. // In Operation Stealth's disassembly elements are removed from the @@ -1348,7 +1341,7 @@ void modifySeqListElement(uint16 objIdx, int16 var4Test, int16 param1, int16 par } void computeMove1(SeqListElement &element, int16 x, int16 y, int16 param1, - int16 param2, int16 x2, int16 y2) { + int16 param2, int16 x2, int16 y2) { element.var16 = 0; element.var14 = 0; @@ -1397,7 +1390,7 @@ uint16 addAni(uint16 param1, uint16 objIdx, const int8 *ptr, SeqListElement &ele int16 di; debug(5, "addAni: param1 = %d, objIdx = %d, ptr = %p, element.var8 = %d, element.var14 = %d param3 = %d", - param1, objIdx, ptr, element.var8, element.var14, param3); + param1, objIdx, ptr, element.var8, element.var14, param3); // In the original an error string is set and 0 is returned if the following doesn't hold assert(ptr); @@ -1413,16 +1406,16 @@ uint16 addAni(uint16 param1, uint16 objIdx, const int8 *ptr, SeqListElement &ele di = (g_cine->_objectTable[objIdx].costume + 1) % (*ptrData); ++ptrData; // Jump over the just read byte // Here ptr2 seems to be indexing a table of structs (8 bytes per struct): - // struct { - // int8 x; // 0 (Used with checkCollision) - // int8 y; // 1 (Used with checkCollision) - // int8 numZones; // 2 (Used with checkCollision) - // int8 var3; // 3 (Not used in this function) - // int8 xAdd; // 4 (Used with an object) - // int8 yAdd; // 5 (Used with an object) - // int8 maskAdd; // 6 (Used with an object) - // int8 frameAdd; // 7 (Used with an object) - // }; + // struct { + // int8 x; // 0 (Used with checkCollision) + // int8 y; // 1 (Used with checkCollision) + // int8 numZones; // 2 (Used with checkCollision) + // int8 var3; // 3 (Not used in this function) + // int8 xAdd; // 4 (Used with an object) + // int8 yAdd; // 5 (Used with an object) + // int8 maskAdd; // 6 (Used with an object) + // int8 frameAdd; // 7 (Used with an object) + // }; ptr2 = ptrData + di * 8; // We might probably safely discard the AND by 1 here because @@ -1572,8 +1565,7 @@ void processSeqListElement(SeqListElement &element) { var_4 = -1; if ((element.var16 == 1 - && !addAni(3, element.objIdx, ptr1, element, 0, &var_4)) || (element.var16 == 2 && !addAni(2, element.objIdx, ptr1, element, 0, - &var_4))) { + && !addAni(3, element.objIdx, ptr1, element, 0, &var_4)) || (element.var16 == 2 && !addAni(2, element.objIdx, ptr1, element, 0, &var_4))) { if (element.varC == 255) { g_cine->_globalVars[VAR_MOUSE_Y_POS] = 0; } @@ -1702,9 +1694,9 @@ bool makeTextEntryMenu(const char *messagePtr, char *inputString, int stringMaxL } break; default: - if (((keycode >= 'a') && (keycode <='z')) || - ((keycode >= '0') && (keycode <='9')) || - ((keycode >= 'A') && (keycode <='Z')) || + if (((keycode >= 'a') && (keycode <= 'z')) || + ((keycode >= '0') && (keycode <= '9')) || + ((keycode >= 'A') && (keycode <= 'Z')) || (keycode == ' ')) { if (inputLength < stringMaxLength - 1) { ch[0] = keycode; |