aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm
diff options
context:
space:
mode:
Diffstat (limited to 'engines/scumm')
-rw-r--r--engines/scumm/charset.cpp907
-rw-r--r--engines/scumm/charset.h88
-rw-r--r--engines/scumm/cursor.cpp71
-rw-r--r--engines/scumm/detection.cpp23
-rw-r--r--engines/scumm/detection_tables.h18
-rw-r--r--engines/scumm/dialogs.cpp71
-rw-r--r--engines/scumm/gfx.cpp1
-rw-r--r--engines/scumm/he/animation_he.cpp128
-rw-r--r--engines/scumm/he/animation_he.h35
-rw-r--r--engines/scumm/he/intern_he.h2
-rw-r--r--engines/scumm/he/logic/baseball2001.cpp63
-rw-r--r--engines/scumm/he/logic/basketball.cpp230
-rw-r--r--engines/scumm/he/logic/football.cpp288
-rw-r--r--engines/scumm/he/logic/funshop.cpp216
-rw-r--r--engines/scumm/he/logic/moonbase.cpp50
-rw-r--r--engines/scumm/he/logic/puttrace.cpp376
-rw-r--r--engines/scumm/he/logic/soccer.cpp1206
-rw-r--r--engines/scumm/he/logic_he.cpp1393
-rw-r--r--engines/scumm/he/logic_he.h155
-rw-r--r--engines/scumm/he/script_v100he.cpp24
-rw-r--r--engines/scumm/he/script_v60he.cpp12
-rw-r--r--engines/scumm/he/script_v72he.cpp11
-rw-r--r--engines/scumm/he/script_v80he.cpp5
-rw-r--r--engines/scumm/he/script_v90he.cpp2
-rw-r--r--engines/scumm/he/sprite_he.cpp10
-rw-r--r--engines/scumm/he/sprite_he.h1
-rw-r--r--engines/scumm/he/wiz_he.cpp2
-rw-r--r--engines/scumm/help.cpp2
-rw-r--r--engines/scumm/help.h1
-rw-r--r--engines/scumm/imuse/imuse.cpp153
-rw-r--r--engines/scumm/imuse/imuse.h7
-rw-r--r--engines/scumm/imuse/imuse_internal.h42
-rw-r--r--engines/scumm/imuse/imuse_part.cpp12
-rw-r--r--engines/scumm/imuse/imuse_player.cpp49
-rw-r--r--engines/scumm/imuse/instrument.cpp100
-rw-r--r--engines/scumm/imuse/instrument.h6
-rw-r--r--engines/scumm/imuse/pcspk.cpp834
-rw-r--r--engines/scumm/imuse/pcspk.h160
-rw-r--r--engines/scumm/imuse/sysex.h1
-rw-r--r--engines/scumm/imuse/sysex_samnmax.cpp3
-rw-r--r--engines/scumm/imuse/sysex_scumm.cpp81
-rw-r--r--engines/scumm/imuse_digi/dimuse.cpp2
-rw-r--r--engines/scumm/input.cpp12
-rw-r--r--engines/scumm/insane/insane_enemy.cpp1
-rw-r--r--engines/scumm/insane/insane_iact.cpp1
-rw-r--r--engines/scumm/insane/insane_scenes.cpp1
-rw-r--r--engines/scumm/module.mk10
-rw-r--r--engines/scumm/palette.cpp12
-rw-r--r--engines/scumm/player_v2.h5
-rw-r--r--engines/scumm/player_v2base.h6
-rw-r--r--engines/scumm/player_v2cms.cpp536
-rw-r--r--engines/scumm/player_v2cms.h74
-rw-r--r--engines/scumm/saveload.cpp7
-rw-r--r--engines/scumm/script_v4.cpp12
-rw-r--r--engines/scumm/script_v5.cpp14
-rw-r--r--engines/scumm/scumm-md5.h6
-rw-r--r--engines/scumm/scumm.cpp106
-rw-r--r--engines/scumm/scumm.h23
-rw-r--r--engines/scumm/smush/channel.cpp4
-rw-r--r--engines/scumm/smush/codec37.cpp1
-rw-r--r--engines/scumm/smush/smush_font.cpp1
-rw-r--r--engines/scumm/sound.cpp70
-rw-r--r--engines/scumm/sound.h3
-rw-r--r--engines/scumm/string.cpp10
-rw-r--r--engines/scumm/vars.cpp11
65 files changed, 5016 insertions, 2751 deletions
diff --git a/engines/scumm/charset.cpp b/engines/scumm/charset.cpp
index eaae64dc77..8558da397e 100644
--- a/engines/scumm/charset.cpp
+++ b/engines/scumm/charset.cpp
@@ -49,35 +49,28 @@ void ScummEngine::loadCJKFont() {
_newLineCharacter = 0;
if (_game.version <= 5 && _game.platform == Common::kPlatformFMTowns && _language == Common::JA_JPN) { // FM-TOWNS v3 / v5 Kanji
-#ifdef DISABLE_TOWNS_DUAL_LAYER_MODE
+#if defined(DISABLE_TOWNS_DUAL_LAYER_MODE) || !defined(USE_RGB_COLOR)
GUIErrorMessage("FM-Towns Kanji font drawing requires dual graphics layer support which is disabled in this build");
error("FM-Towns Kanji font drawing requires dual graphics layer support which is disabled in this build");
#else
// use FM-TOWNS font rom, since game files don't have kanji font resources
- _cjkFont = Graphics::FontSJIS::createFont(Common::kPlatformFMTowns);
+ _cjkFont = Graphics::FontSJIS::createFont(_game.platform);
if (!_cjkFont)
error("SCUMM::Font: Could not open file 'FMT_FNT.ROM'");
_textSurfaceMultiplier = 2;
_useCJKMode = true;
#endif
} else if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine && _language == Common::JA_JPN) {
- int numChar = 3418;
- _2byteWidth = 12;
- _2byteHeight = 12;
+#ifdef USE_RGB_COLOR
// use PC-Engine System Card, since game files don't have kanji font resources
- if (!fp.open("pce.cdbios")) {
- error("SCUMM::Font: Could not open System Card pce.cdbios");
- } else {
- _useCJKMode = true;
- debug(2, "Loading PC-Engine System Card");
-
- // A 0x200 byte header can be present at the beginning of the syscard. Seek past it too.
- fp.seek((fp.size() & 0x200) ? 0x30200 : 0x30000);
+ _cjkFont = Graphics::FontSJIS::createFont(_game.platform);
+ if (!_cjkFont)
+ error("SCUMM::Font: Could not open file 'pce.cdbios'");
- _2byteFontPtr = new byte[_2byteWidth * _2byteHeight * numChar / 8];
- fp.read(_2byteFontPtr, _2byteWidth * _2byteHeight * numChar / 8);
- fp.close();
- }
+ _cjkFont->setDrawingMode(Graphics::FontSJIS::kShadowMode);
+ _2byteWidth = _2byteHeight = 12;
+ _useCJKMode = true;
+#endif
} else if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::JA_JPN) {
int numChar = 1413;
_2byteWidth = 16;
@@ -161,71 +154,16 @@ void ScummEngine::loadCJKFont() {
}
}
-static int SJIStoPCEChunk(int f, int s) { //converts sjis code to pce font offset
- // rangeTbl maps SJIS char-codes to the PCE System Card font rom.
- // Each pair {<upperBound>,<lowerBound>} in the array represents a SJIS range.
- const int rangeCnt = 45;
- static const uint16 rangeTbl[rangeCnt][2] = {
- // Symbols
- {0x8140,0x817E},{0x8180,0x81AC},
- // 0-9
- {0x824F,0x8258},
- // Latin upper
- {0x8260,0x8279},
- // Latin lower
- {0x8281,0x829A},
- // Kana
- {0x829F,0x82F1},{0x8340,0x837E},{0x8380,0x8396},
- // Greek upper
- {0x839F,0x83B6},
- // Greek lower
- {0x83BF,0x83D6},
- // Cyrillic upper
- {0x8440,0x8460},
- // Cyrillic lower
- {0x8470,0x847E},{0x8480,0x8491},
- // Kanji
- {0x889F,0x88FC},
- {0x8940,0x897E},{0x8980,0x89FC},
- {0x8A40,0x8A7E},{0x8A80,0x8AFC},
- {0x8B40,0x8B7E},{0x8B80,0x8BFC},
- {0x8C40,0x8C7E},{0x8C80,0x8CFC},
- {0x8D40,0x8D7E},{0x8D80,0x8DFC},
- {0x8E40,0x8E7E},{0x8E80,0x8EFC},
- {0x8F40,0x8F7E},{0x8F80,0x8FFC},
- {0x9040,0x907E},{0x9080,0x90FC},
- {0x9140,0x917E},{0x9180,0x91FC},
- {0x9240,0x927E},{0x9280,0x92FC},
- {0x9340,0x937E},{0x9380,0x93FC},
- {0x9440,0x947E},{0x9480,0x94FC},
- {0x9540,0x957E},{0x9580,0x95FC},
- {0x9640,0x967E},{0x9680,0x96FC},
- {0x9740,0x977E},{0x9780,0x97FC},
- {0x9840,0x9872}
- };
-
- int ch = (f << 8) | (s & 0xFF);
- int offset = 0;
- for (int i = 0; i < rangeCnt; ++i) {
- if (ch >= rangeTbl[i][0] && ch <= rangeTbl[i][1])
- return offset + ch - rangeTbl[i][0];
- offset += rangeTbl[i][1] - rangeTbl[i][0] + 1;
- }
-
- debug(4, "Invalid Char: 0x%x", ch);
- return 0;
-}
-
byte *ScummEngine::get2byteCharPtr(int idx) {
+ if (_game.platform == Common::kPlatformFMTowns || _game.platform == Common::kPlatformPCEngine)
+ return 0;
+
switch (_language) {
case Common::KO_KOR:
idx = ((idx % 256) - 0xb0) * 94 + (idx / 256) - 0xa1;
break;
case Common::JA_JPN:
- if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine) {
- idx = SJIStoPCEChunk((idx % 256), (idx / 256));
- return _2byteFontPtr + (_2byteWidth * _2byteHeight / 8) * idx;
- } else if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::JA_JPN) {
+ if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::JA_JPN) {
// init pointer to charset resource
if (_2byteFontPtr[0] == 0xFF) {
int charsetId = 5;
@@ -314,7 +252,7 @@ CharsetRenderer::~CharsetRenderer() {
CharsetRendererCommon::CharsetRendererCommon(ScummEngine *vm)
: CharsetRenderer(vm), _bytesPerPixel(0), _fontHeight(0), _numChars(0) {
- _shadowMode = kNoShadowMode;
+ _shadowMode = false;
_shadowColor = 0;
}
@@ -362,17 +300,9 @@ void CharsetRendererV3::setCurID(int32 id) {
}
int CharsetRendererCommon::getFontHeight() {
- if (_vm->_useCJKMode) {
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- static const uint8 sjisFontHeightM1[] = { 0, 8, 9, 8, 9, 8, 9, 0, 0, 0 };
- static const uint8 sjisFontHeightM2[] = { 0, 8, 9, 9, 9, 8, 9, 9, 9, 8 };
- static const uint8 sjisFontHeightI4[] = { 0, 8, 9, 9, 9, 8, 8, 8, 8, 8 };
- const uint8 *htbl = (_vm->_game.id == GID_MONKEY) ? sjisFontHeightM1 : ((_vm->_game.id == GID_INDY4) ? sjisFontHeightI4 : sjisFontHeightM2);
- return (_vm->_game.version == 3) ? 8 : htbl[_curId];
- } else {
- return MAX(_vm->_2byteHeight + 1, _fontHeight);
- }
- } else
+ if (_vm->_useCJKMode)
+ return MAX(_vm->_2byteHeight + 1, _fontHeight);
+ else
return _fontHeight;
}
@@ -380,57 +310,16 @@ int CharsetRendererCommon::getFontHeight() {
int CharsetRendererClassic::getCharWidth(uint16 chr) {
int spacing = 0;
- if (_vm->_useCJKMode) {
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- if ((chr & 0xff00) == 0xfd00) {
- chr &= 0xff;
- } else if (chr >= 256) {
- spacing = 8;
- } else if (useTownsFontRomCharacter(chr)) {
- spacing = 4;
- }
+ if (_vm->_useCJKMode && chr >= 0x80)
+ return _vm->_2byteWidth / 2;
- if (spacing) {
- if (_vm->_game.id == GID_MONKEY) {
- spacing++;
- if (_curId == 2)
- spacing++;
- } else if (_vm->_game.id != GID_INDY4 && _curId == 1) {
- spacing++;
- }
- }
-
- } else if (chr >= 0x80) {
- return _vm->_2byteWidth / 2;
- }
- }
-
- if (!spacing) {
- int offs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
- if (offs) {
- spacing = _fontPtr[offs] + (signed char)_fontPtr[offs + 2];
- }
- }
+ int offs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
+ if (offs)
+ spacing = _fontPtr[offs] + (signed char)_fontPtr[offs + 2];
return spacing;
}
-bool CharsetRendererClassic::useTownsFontRomCharacter(uint16 chr) {
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (_vm->_game.platform != Common::kPlatformFMTowns || !_vm->_useCJKMode)
- return false;
-
- if (chr < 128) {
- if (((_vm->_game.id == GID_MONKEY2 && _curId != 0) || (_vm->_game.id == GID_INDY4 && _curId != 3)) && (chr > 31 && chr != 94 && chr != 95 && chr != 126 && chr != 127))
- return true;
- return false;
- }
- return true;
-#else
- return false;
-#endif
-}
-
int CharsetRenderer::getStringWidth(int arg, const byte *text) {
int pos = 0;
int width = 1;
@@ -608,22 +497,51 @@ void CharsetRenderer::addLinebreaks(int a, byte *str, int pos, int maxwidth) {
int CharsetRendererV3::getCharWidth(uint16 chr) {
int spacing = 0;
- if (_vm->_useCJKMode) {
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- if (chr >= 256)
- spacing = 8;
- else if (chr >= 128)
- spacing = 4;
- } else if (chr & 0x80) {
- spacing = _vm->_2byteWidth / 2;
+ if (_vm->_useCJKMode && (chr & 0x80))
+ spacing = _vm->_2byteWidth / 2;
+
+ if (!spacing)
+ spacing = *(_widthTable + chr);
+
+ return spacing;
+}
+
+void CharsetRendererV3::enableShadow(bool enable) {
+ _shadowColor = 0;
+ _shadowMode = enable;
+}
+
+void CharsetRendererV3::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
+ int y, x;
+ byte bits = 0;
+ uint8 col = _color;
+ int pitch = s.pitch - width * bitDepth;
+ byte *dst2 = dst + s.pitch;
+
+ for (y = 0; y < height && y + drawTop < s.h; y++) {
+ for (x = 0; x < width; x++) {
+ if ((x % 8) == 0)
+ bits = *src++;
+ if ((bits & revBitMask(x % 8)) && y + drawTop >= 0) {
+ if (_shadowMode)
+ dst[1] = dst2[0] = dst2[1] = _shadowColor;
+ dst[0] = col;
+ }
+ dst += bitDepth;
+ dst2 += bitDepth;
}
- }
- if (!spacing) {
- spacing = *(_widthTable + chr);
+ dst += pitch;
+ dst2 += pitch;
}
+}
- return spacing;
+int CharsetRendererV3::getDrawWidthIntern(uint16 chr) {
+ return getCharWidth(chr);
+}
+
+int CharsetRendererV3::getDrawHeightIntern(uint16) {
+ return 8;
}
void CharsetRendererV3::setColor(byte color) {
@@ -662,43 +580,6 @@ void CharsetRendererPCE::setColor(byte color) {
}
#endif
-void CharsetRendererCommon::enableShadow(bool enable) {
- if (enable) {
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- _shadowColor = 8;
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- _shadowColor = _vm->_game.version == 5 ? _vm->_townsCharsetColorMap[0] : 0x88;
- if (_vm->_cjkFont) {
- if (_vm->_game.version == 5) {
- if (((_vm->_game.id == GID_MONKEY) && (_curId == 2 || _curId == 4 || _curId == 6)) ||
- ((_vm->_game.id == GID_MONKEY2) && (_curId != 1 && _curId != 5 && _curId != 9)) ||
- ((_vm->_game.id == GID_INDY4) && (_curId == 2 || _curId == 3 || _curId == 4))) {
- _vm->_cjkFont->setDrawingMode(Graphics::FontSJIS::kOutlineMode);
- } else {
- _vm->_cjkFont->setDrawingMode(Graphics::FontSJIS::kDefaultMode);
- }
- _vm->_cjkFont->toggleFlippedMode((_vm->_game.id == GID_MONKEY || _vm->_game.id == GID_MONKEY2) && _curId == 3);
- } else {
- _vm->_cjkFont->setDrawingMode(Graphics::FontSJIS::kShadowMode);
- }
- }
-#endif
- _shadowMode = kFMTOWNSShadowMode;
- } else {
- _shadowColor = 0;
- _shadowMode = kNormalShadowMode;
- }
- } else {
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (_vm->_cjkFont) {
- _vm->_cjkFont->setDrawingMode(Graphics::FontSJIS::kDefaultMode);
- _vm->_cjkFont->toggleFlippedMode(false);
- }
-#endif
- _shadowMode = kNoShadowMode;
- }
-}
-
void CharsetRendererV3::printChar(int chr, bool ignoreCharsetMask) {
// WORKAROUND for bug #1509509: Indy3 Mac does not show black
// characters (such as in the grail diary) if ignoreCharsetMask
@@ -721,33 +602,19 @@ void CharsetRendererV3::printChar(int chr, bool ignoreCharsetMask) {
if (chr == '@')
return;
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (_vm->_useCJKMode && chr > 127) {
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- charPtr = 0;
- width = _vm->_cjkFont->getCharWidth(chr);
- height = _vm->_cjkFont->getFontHeight();
- } else {
- width = _vm->_2byteWidth;
- height = _vm->_2byteHeight;
- charPtr = _vm->get2byteCharPtr(chr);
- }
- } else
-#endif
- {
- charPtr = _fontPtr + chr * 8;
- width = getCharWidth(chr);
- height = 8;
- }
+ charPtr = (_vm->_useCJKMode && chr > 127) ? _vm->get2byteCharPtr(chr) : _fontPtr + chr * 8;
+ width = getDrawWidthIntern(chr);
+ height = getDrawHeightIntern(chr);
+ setDrawCharIntern(chr);
+
+ origWidth = width;
+ origHeight = height;
// Clip at the right side (to avoid drawing "outside" the screen bounds).
if (_left + origWidth > _right + 1)
return;
- origWidth = width;
- origHeight = height;
-
- if (_shadowMode != kNoShadowMode) {
+ if (_shadowMode) {
width++;
height++;
}
@@ -769,30 +636,17 @@ void CharsetRendererV3::printChar(int chr, bool ignoreCharsetMask) {
_textScreenID = vs->number;
}
- if (
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- (_vm->_game.platform != Common::kPlatformFMTowns) &&
-#endif
- (ignoreCharsetMask || !vs->hasTwoBuffers)) {
+ if ((ignoreCharsetMask || !vs->hasTwoBuffers)) {
dst = vs->getPixels(_left, drawTop);
- if (charPtr)
- drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight, vs->format.bytesPerPixel);
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- else if (_vm->_cjkFont)
- _vm->_cjkFont->drawChar(*vs, chr, _left, drawTop, _color, _shadowColor);
-#endif
+ drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight, vs->format.bytesPerPixel);
} else {
dst = (byte *)_vm->_textSurface.getBasePtr(_left * _vm->_textSurfaceMultiplier, _top * _vm->_textSurfaceMultiplier);
- if (charPtr)
- drawBits1(_vm->_textSurface, dst, charPtr, drawTop, origWidth, origHeight, _vm->_textSurface.format.bytesPerPixel, (_vm->_textSurfaceMultiplier == 2 && !is2byte));
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- else if (_vm->_cjkFont)
- _vm->_cjkFont->drawChar(_vm->_textSurface, chr, _left * _vm->_textSurfaceMultiplier, _top * _vm->_textSurfaceMultiplier, _color, _shadowColor);
-#endif
- if (is2byte) {
- origWidth /= _vm->_textSurfaceMultiplier;
- height /= _vm->_textSurfaceMultiplier;
- }
+ drawBits1(_vm->_textSurface, dst, charPtr, drawTop, origWidth, origHeight, _vm->_textSurface.format.bytesPerPixel);
+ }
+
+ if (is2byte) {
+ origWidth /= _vm->_textSurfaceMultiplier;
+ height /= _vm->_textSurfaceMultiplier;
}
if (_str.left > _left)
@@ -802,7 +656,7 @@ void CharsetRendererV3::printChar(int chr, bool ignoreCharsetMask) {
if (_str.right < _left) {
_str.right = _left;
- if (_shadowMode != kNoShadowMode)
+ if (_shadowMode)
_str.right++;
}
@@ -811,30 +665,12 @@ void CharsetRendererV3::printChar(int chr, bool ignoreCharsetMask) {
}
void CharsetRendererV3::drawChar(int chr, Graphics::Surface &s, int x, int y) {
- const byte *charPtr;
- byte *dst;
- int width, height;
- int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
- if (is2byte) {
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- _vm->_cjkFont->drawChar(s, chr, x * _vm->_textSurfaceMultiplier, y * _vm->_textSurfaceMultiplier, _color, _shadowColor);
- return;
- }
- else
-#endif
- {
- charPtr = _vm->get2byteCharPtr(chr);
- width = _vm->_2byteWidth;
- height = _vm->_2byteHeight;
- }
- } else {
- charPtr = _fontPtr + chr * 8;
-// width = height = 8;
- width = getCharWidth(chr);
- height = 8;
- }
- dst = (byte *)s.pixels + y * s.pitch + x;
+ const byte *charPtr = (_vm->_useCJKMode && chr > 127) ? _vm->get2byteCharPtr(chr) : _fontPtr + chr * 8;
+ int width = getDrawWidthIntern(chr);
+ int height = getDrawHeightIntern(chr);
+ setDrawCharIntern(chr);
+
+ byte *dst = (byte *)s.pixels + y * s.pitch + x;
drawBits1(s, dst, charPtr, y, width, height, s.format.bytesPerPixel);
}
@@ -853,29 +689,6 @@ void CharsetRenderer::translateColor() {
}
}
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
-void CharsetRenderer::processTownsCharsetColors(uint8 bytesPerPixel) {
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- for (int i = 0; i < (1 << bytesPerPixel); i++) {
- uint8 c = _vm->_charsetColorMap[i];
-
- if (c > 16) {
- uint8 t = (_vm->_currentPalette[c * 3] < 32) ? 4 : 12;
- t |= ((_vm->_currentPalette[c * 3 + 1] < 32) ? 2 : 10);
- t |= ((_vm->_currentPalette[c * 3 + 1] < 32) ? 1 : 9);
- c = t;
- }
-
- if (c == 0)
- c = _vm->_townsOverrideShadowColor;
-
- c = ((c & 0x0f) << 4) | (c & 0x0f);
- _vm->_townsCharsetColorMap[i] = c;
- }
- }
-}
-#endif
-
void CharsetRenderer::saveLoadWithSerializer(Serializer *ser) {
static const SaveLoadEntry charsetRendererEntries[] = {
MKLINE_OLD(CharsetRenderer, _curId, sleByte, VER(73), VER(73)),
@@ -893,10 +706,7 @@ void CharsetRenderer::saveLoadWithSerializer(Serializer *ser) {
}
void CharsetRendererClassic::printChar(int chr, bool ignoreCharsetMask) {
- int width, height, origWidth, origHeight;
- int offsX, offsY;
VirtScreen *vs;
- const byte *charPtr;
bool is2byte = (chr >= 256 && _vm->_useCJKMode);
assertRange(1, _curId, _vm->_numCharsets - 1, "charset");
@@ -911,64 +721,8 @@ void CharsetRendererClassic::printChar(int chr, bool ignoreCharsetMask) {
_vm->_charsetColorMap[1] = _color;
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- processTownsCharsetColors(_bytesPerPixel);
- bool noSjis = false;
-
- if (_vm->_game.platform == Common::kPlatformFMTowns && _vm->_useCJKMode) {
- if ((chr & 0x00ff) == 0x00fd) {
- chr >>= 8;
- noSjis = true;
- }
- }
-
- if (useTownsFontRomCharacter(chr) && !noSjis) {
- charPtr = 0;
- _vm->_cjkChar = chr;
- enableShadow(true);
-
- width = getCharWidth(chr);
- // For whatever reason MI1 uses a different font width
- // for alignment calculation and for drawing when
- // charset 2 is active. This fixes some subtle glitches.
- if (_vm->_game.id == GID_MONKEY && _curId == 2)
- width--;
- origWidth = width;
-
- origHeight = height = getFontHeight();
- offsX = offsY = 0;
- } else if (_vm->_useCJKMode && (chr >= 128) && !noSjis) {
- enableShadow(true);
- origWidth = width = _vm->_2byteWidth;
- origHeight = height = _vm->_2byteHeight;
- charPtr = _vm->get2byteCharPtr(chr);
- offsX = offsY = 0;
- if (_shadowMode != kNoShadowMode) {
- width++;
- height++;
- }
- } else
-#endif
- {
- uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
- assert(charOffs < 0x14000);
- if (!charOffs)
- return;
- charPtr = _fontPtr + charOffs;
-
- width = origWidth = charPtr[0];
- height = origHeight = charPtr[1];
-
- if (_disableOffsX) {
- offsX = 0;
- } else {
- offsX = (signed char)charPtr[2];
- }
-
- offsY = (signed char)charPtr[3];
-
- charPtr += 4; // Skip over char header
- }
+ if (!prepareDraw(chr))
+ return;
if (_firstChar) {
_str.left = 0;
@@ -977,12 +731,12 @@ void CharsetRendererClassic::printChar(int chr, bool ignoreCharsetMask) {
_str.bottom = 0;
}
- _top += offsY;
- _left += offsX;
+ _top += _offsY;
+ _left += _offsX;
- if (_left + origWidth > _right + 1 || _left < 0) {
- _left += origWidth;
- _top -= offsY;
+ if (_left + _origWidth > _right + 1 || _left < 0) {
+ _left += _origWidth;
+ _top -= _offsY;
return;
}
@@ -1004,33 +758,29 @@ void CharsetRendererClassic::printChar(int chr, bool ignoreCharsetMask) {
int drawTop = _top - vs->topline;
- _vm->markRectAsDirty(vs->number, _left, _left + width, drawTop, drawTop + height);
+ _vm->markRectAsDirty(vs->number, _left, _left + _width, drawTop, drawTop + _height);
// This check for kPlatformFMTowns and kMainVirtScreen is at least required for the chat with
// the navigator's head in front of the ghost ship in Monkey Island 1
- if (!ignoreCharsetMask
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- || (_vm->_game.platform == Common::kPlatformFMTowns && vs->number == kMainVirtScreen)
-#endif
- ) {
+ if (!ignoreCharsetMask || (_vm->_game.platform == Common::kPlatformFMTowns && vs->number == kMainVirtScreen)) {
_hasMask = true;
_textScreenID = vs->number;
}
- printCharIntern(is2byte, charPtr, origWidth, origHeight, width, height, vs, ignoreCharsetMask);
+ printCharIntern(is2byte, _charPtr, _origWidth, _origHeight, _width, _height, vs, ignoreCharsetMask);
- _left += origWidth;
+ _left += _origWidth;
if (_str.right < _left) {
_str.right = _left;
- if (_vm->_game.platform != Common::kPlatformFMTowns && _shadowMode != kNoShadowMode)
+ if (_vm->_game.platform != Common::kPlatformFMTowns && _shadowMode)
_str.right++;
}
- if (_str.bottom < _top + origHeight)
- _str.bottom = _top + origHeight;
+ if (_str.bottom < _top + _origHeight)
+ _str.bottom = _top + _origHeight;
- _top -= offsY;
+ _top -= _offsY;
}
void CharsetRendererClassic::printCharIntern(bool is2byte, const byte *charPtr, int origWidth, int origHeight, int width, int height, VirtScreen *vs, bool ignoreCharsetMask) {
@@ -1068,11 +818,7 @@ void CharsetRendererClassic::printCharIntern(bool is2byte, const byte *charPtr,
} else {
Graphics::Surface dstSurface;
Graphics::Surface backSurface;
- if ((ignoreCharsetMask || !vs->hasTwoBuffers)
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- && (_vm->_game.platform != Common::kPlatformFMTowns)
-#endif
- ) {
+ if ((ignoreCharsetMask || !vs->hasTwoBuffers)) {
dstSurface = *vs;
dstPtr = vs->getPixels(_left, drawTop);
} else {
@@ -1091,16 +837,7 @@ void CharsetRendererClassic::printCharIntern(bool is2byte, const byte *charPtr,
drawTop = _top - _vm->_screenTop;
}
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (!charPtr && _vm->_cjkFont) {
- _vm->_cjkFont->drawChar(dstSurface, _vm->_cjkChar, _left * _vm->_textSurfaceMultiplier, (_top - _vm->_screenTop) * _vm->_textSurfaceMultiplier, _vm->_townsCharsetColorMap[1], _shadowColor);
- } else
-#endif
- if (is2byte) {
- drawBits1(dstSurface, dstPtr, charPtr, drawTop, origWidth, origHeight, dstSurface.format.bytesPerPixel);
- } else {
- drawBitsN(dstSurface, dstPtr, charPtr, *_fontPtr, drawTop, origWidth, origHeight, _vm->_textSurfaceMultiplier == 2);
- }
+ drawBitsN(dstSurface, dstPtr, charPtr, *_fontPtr, drawTop, origWidth, origHeight);
if (_blitAlso && vs->hasTwoBuffers) {
// FIXME: Revisiting this code, I think the _blitAlso mode is likely broken
@@ -1139,54 +876,36 @@ void CharsetRendererClassic::printCharIntern(bool is2byte, const byte *charPtr,
}
}
-void CharsetRendererClassic::drawChar(int chr, Graphics::Surface &s, int x, int y) {
- const byte *charPtr;
- byte *dst;
- int width, height;
- int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
-
- if (is2byte) {
- enableShadow(true);
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (_vm->_game.platform == Common::kPlatformFMTowns) {
- _vm->_cjkFont->drawChar(s, chr, x * _vm->_textSurfaceMultiplier, y * _vm->_textSurfaceMultiplier, _color, _shadowColor);
- return;
- } else
-#endif
- {
- charPtr = _vm->get2byteCharPtr(chr);
- width = _vm->_2byteWidth;
- height = _vm->_2byteHeight;
- }
- } else {
- uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
- assert(charOffs < 0x10000);
- if (!charOffs)
- return;
- charPtr = _fontPtr + charOffs;
+bool CharsetRendererClassic::prepareDraw(uint16 chr) {
+ uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
+ assert(charOffs < 0x14000);
+ if (!charOffs)
+ return false;
+ _charPtr = _fontPtr + charOffs;
- width = charPtr[0];
- height = charPtr[1];
+ _width = _origWidth = _charPtr[0];
+ _height = _origHeight = _charPtr[1];
- charPtr += 4; // Skip over char header
+ if (_disableOffsX) {
+ _offsX = 0;
+ } else {
+ _offsX = (signed char)_charPtr[2];
}
- dst = (byte *)s.pixels + y * s.pitch + x;
+ _offsY = (signed char)_charPtr[3];
- if (is2byte) {
- drawBits1(s, dst, charPtr, y, width, height, s.format.bytesPerPixel);
- } else {
- drawBitsN(s, dst, charPtr, *_fontPtr, y, width, height);
- }
+ _charPtr += 4; // Skip over char header
+ return true;
}
-void CharsetRendererClassic::drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height,
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- bool scale2x) {
-#else
- bool) {
-#endif
+void CharsetRendererClassic::drawChar(int chr, Graphics::Surface &s, int x, int y) {
+ if (!prepareDraw(chr))
+ return;
+ byte *dst = (byte *)s.pixels + y * s.pitch + x;
+ drawBitsN(s, dst, _charPtr, *_fontPtr, y, _width, _height);
+}
+void CharsetRendererClassic::drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height) {
int y, x;
int color;
byte numbits, bits;
@@ -1198,38 +917,13 @@ void CharsetRendererClassic::drawBitsN(const Graphics::Surface &s, byte *dst, co
numbits = 8;
byte *cmap = _vm->_charsetColorMap;
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- byte *dst2 = dst;
-
- if (_vm->_game.platform == Common::kPlatformFMTowns)
- cmap = _vm->_townsCharsetColorMap;
- if (scale2x) {
- dst2 += s.pitch;
- pitch <<= 1;
- }
-#endif
-
for (y = 0; y < height && y + drawTop < s.h; y++) {
for (x = 0; x < width; x++) {
color = (bits >> (8 - bpp)) & 0xFF;
- if (color && y + drawTop >= 0) {
+ if (color && y + drawTop >= 0)
*dst = cmap[color];
-
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (scale2x)
- dst[1] = dst2[0] = dst2[1] = dst[0];
-#endif
- }
dst++;
-
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- if (scale2x) {
- dst++;
- dst2 += 2;
- }
-#endif
-
bits <<= bpp;
numbits -= bpp;
if (numbits == 0) {
@@ -1238,52 +932,93 @@ void CharsetRendererClassic::drawBitsN(const Graphics::Surface &s, byte *dst, co
}
}
dst += pitch;
+ }
+}
+
+CharsetRendererTownsV3::CharsetRendererTownsV3(ScummEngine *vm) : CharsetRendererV3(vm), _sjisCurChar(0) {
+}
+
+int CharsetRendererTownsV3::getCharWidth(uint16 chr) {
+ int spacing = 0;
+
+ if (_vm->_useCJKMode) {
+ if (chr >= 256)
+ spacing = 8;
+ else if (chr >= 128)
+ spacing = 4;
+ }
+
+ if (!spacing)
+ spacing = *(_widthTable + chr);
+
+ return spacing;
+}
+
+int CharsetRendererTownsV3::getFontHeight() {
+ return _vm->_useCJKMode ? 8 : _fontHeight;
+}
+
+void CharsetRendererTownsV3::enableShadow(bool enable) {
+ _shadowColor = 8;
+ _shadowMode = enable;
+
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- dst2 += pitch;
+ _shadowColor = 0x88;
+#ifdef USE_RGB_COLOR
+ if (_vm->_cjkFont)
+ _vm->_cjkFont->setDrawingMode(enable ? Graphics::FontSJIS::kFMTownsShadowMode : Graphics::FontSJIS::kDefaultMode);
+#endif
#endif
- }
}
-void CharsetRendererCommon::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth,
+void CharsetRendererTownsV3::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- bool scale2x) {
+#ifdef USE_RGB_COLOR
+ if (_sjisCurChar) {
+ assert(_vm->_cjkFont);
+ _vm->_cjkFont->drawChar(_vm->_textSurface, _sjisCurChar, _left * _vm->_textSurfaceMultiplier, _top * _vm->_textSurfaceMultiplier, _color, _shadowColor);
+ return;
+ }
+#endif
+
+ dst = (byte *)_vm->_textSurface.getBasePtr(_left * _vm->_textSurfaceMultiplier, _top * _vm->_textSurfaceMultiplier);
+ int sfPitch = _vm->_textSurface.pitch;
+ int sfHeight = _vm->_textSurface.h;
+ bool scale2x = (_vm->_textSurfaceMultiplier == 2 && !(_sjisCurChar >= 256 && _vm->_useCJKMode));
#else
- bool) {
+ int sfPitch = s.pitch;
+ int sfHeight = s.h;
#endif
int y, x;
byte bits = 0;
uint8 col = _color;
- int pitch = s.pitch - width * bitDepth;
- byte *dst2 = dst + s.pitch;
+ int pitch = sfPitch - width * bitDepth;
+ byte *dst2 = dst + sfPitch;
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
byte *dst3 = dst2;
byte *dst4 = dst2;
if (scale2x) {
- dst3 = dst2 + s.pitch;
- dst4 = dst3 + s.pitch;
+ dst3 = dst2 + sfPitch;
+ dst4 = dst3 + sfPitch;
pitch <<= 1;
}
- if (_vm->_game.platform == Common::kPlatformFMTowns && _vm->_game.version == 5)
- col = _vm->_townsCharsetColorMap[1];
#endif
- for (y = 0; y < height && y + drawTop < s.h; y++) {
+ for (y = 0; y < height && y + drawTop < sfHeight; y++) {
for (x = 0; x < width; x++) {
if ((x % 8) == 0)
bits = *src++;
if ((bits & revBitMask(x % 8)) && y + drawTop >= 0) {
if (bitDepth == 2) {
- if (_shadowMode != kNoShadowMode) {
+ if (_shadowMode) {
WRITE_UINT16(dst + 2, _vm->_16BitPalette[_shadowColor]);
- WRITE_UINT16(dst + s.pitch, _vm->_16BitPalette[_shadowColor]);
- if (_shadowMode != kFMTOWNSShadowMode)
- WRITE_UINT16(dst + s.pitch + 2, _vm->_16BitPalette[_shadowColor]);
+ WRITE_UINT16(dst + sfPitch, _vm->_16BitPalette[_shadowColor]);
}
WRITE_UINT16(dst, _vm->_16BitPalette[_color]);
} else {
- if (_shadowMode != kNoShadowMode) {
+ if (_shadowMode) {
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
if (scale2x) {
dst[2] = dst[3] = dst2[2] = dst2[3] = _shadowColor;
@@ -1292,8 +1027,6 @@ void CharsetRendererCommon::drawBits1(const Graphics::Surface &s, byte *dst, con
#endif
{
dst[1] = dst2[0] = _shadowColor;
- if (_shadowMode != kFMTOWNSShadowMode)
- dst2[1] = _shadowColor;
}
}
dst[0] = col;
@@ -1324,31 +1057,64 @@ void CharsetRendererCommon::drawBits1(const Graphics::Surface &s, byte *dst, con
#endif
}
}
+#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
+int CharsetRendererTownsV3::getDrawWidthIntern(uint16 chr) {
+#ifdef USE_RGB_COLOR
+ if (_vm->_useCJKMode && chr > 127) {
+ assert(_vm->_cjkFont);
+ return _vm->_cjkFont->getCharWidth(chr);
+ }
+#endif
+ return CharsetRendererV3::getDrawWidthIntern(chr);
+}
+
+int CharsetRendererTownsV3::getDrawHeightIntern(uint16 chr) {
+#ifdef USE_RGB_COLOR
+ if (_vm->_useCJKMode && chr > 127) {
+ assert(_vm->_cjkFont);
+ return _vm->_cjkFont->getFontHeight();
+ }
+#endif
+ return CharsetRendererV3::getDrawHeightIntern(chr);
+}
+
+void CharsetRendererTownsV3::setDrawCharIntern(uint16 chr) {
+ _sjisCurChar = (_vm->_useCJKMode && chr > 127) ? chr : 0;
+}
+#endif
#ifdef USE_RGB_COLOR
-void CharsetRendererPCE::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth, bool scalex) {
+void CharsetRendererPCE::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
+ if (_sjisCurChar) {
+ assert(_vm->_cjkFont);
+ uint16 col1 = _color;
+ uint16 col2 = _shadowColor;
+
+ if (s.format.bytesPerPixel == 2) {
+ col1 = _vm->_16BitPalette[col1];
+ col2 = _vm->_16BitPalette[col2];
+ }
+
+ _vm->_cjkFont->drawChar(dst, _sjisCurChar, s.pitch, s.format.bytesPerPixel, col1, col2, -1, -1);
+ return;
+ }
+
int y, x;
- int bitCount = 0;
byte bits = 0;
- const bool resetLineBitCount = (_vm->_language != Common::JA_JPN || width != 12);
-
for (y = 0; y < height && y + drawTop < s.h; y++) {
- if (resetLineBitCount)
- bitCount = 0;
+ int bitCount = 0;
for (x = 0; x < width; x++) {
if ((bitCount % 8) == 0)
bits = *src++;
if ((bits & revBitMask(bitCount % 8)) && y + drawTop >= 0) {
if (bitDepth == 2) {
- if (_shadowMode != kNoShadowMode) {
+ if (_shadowMode)
WRITE_UINT16(dst + s.pitch + 2, _vm->_16BitPalette[_shadowColor]);
- }
WRITE_UINT16(dst, _vm->_16BitPalette[_color]);
} else {
- if (_shadowMode != kNoShadowMode) {
+ if (_shadowMode)
*(dst + s.pitch + 1) = _shadowColor;
- }
*dst = _color;
}
}
@@ -1359,6 +1125,22 @@ void CharsetRendererPCE::drawBits1(const Graphics::Surface &s, byte *dst, const
dst += s.pitch - width * bitDepth;
}
}
+
+int CharsetRendererPCE::getDrawWidthIntern(uint16 chr) {
+ if (_vm->_useCJKMode && chr > 127)
+ return _vm->_2byteWidth;
+ return CharsetRendererV3::getDrawWidthIntern(chr);
+}
+
+int CharsetRendererPCE::getDrawHeightIntern(uint16 chr) {
+ if (_vm->_useCJKMode && chr > 127)
+ return _vm->_2byteHeight;
+ return CharsetRendererV3::getDrawHeightIntern(chr);
+}
+
+void CharsetRendererPCE::setDrawCharIntern(uint16 chr) {
+ _sjisCurChar = (_vm->_useCJKMode && chr > 127) ? chr : 0;
+}
#endif
#ifdef ENABLE_SCUMM_7_8
@@ -1533,7 +1315,7 @@ void CharsetRendererNES::printChar(int chr, bool ignoreCharsetMask) {
if (_str.right < _left) {
_str.right = _left;
- if (_shadowMode != kNoShadowMode)
+ if (_shadowMode)
_str.right++;
}
@@ -1556,7 +1338,204 @@ void CharsetRendererNES::drawChar(int chr, Graphics::Surface &s, int x, int y) {
drawBits1(s, dst, charPtr, y, width, height, s.format.bytesPerPixel);
}
-void CharsetRendererNES::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth, bool scalex) {
+#ifdef USE_RGB_COLOR
+#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
+CharsetRendererTownsClassic::CharsetRendererTownsClassic(ScummEngine *vm) : CharsetRendererClassic(vm), _sjisCurChar(0) {
+}
+
+int CharsetRendererTownsClassic::getCharWidth(uint16 chr) {
+ int spacing = 0;
+
+ if (_vm->_useCJKMode) {
+ if ((chr & 0xff00) == 0xfd00) {
+ chr &= 0xff;
+ } else if (chr >= 256) {
+ spacing = 8;
+ } else if (useFontRomCharacter(chr)) {
+ spacing = 4;
+ }
+
+ if (spacing) {
+ if (_vm->_game.id == GID_MONKEY) {
+ spacing++;
+ if (_curId == 2)
+ spacing++;
+ } else if (_vm->_game.id != GID_INDY4 && _curId == 1) {
+ spacing++;
+ }
+ }
+ }
+
+ if (!spacing) {
+ int offs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
+ if (offs)
+ spacing = _fontPtr[offs] + (signed char)_fontPtr[offs + 2];
+ }
+
+ return spacing;
+}
+
+int CharsetRendererTownsClassic::getFontHeight() {
+ static const uint8 sjisFontHeightM1[] = { 0, 8, 9, 8, 9, 8, 9, 0, 0, 0 };
+ static const uint8 sjisFontHeightM2[] = { 0, 8, 9, 9, 9, 8, 9, 9, 9, 8 };
+ static const uint8 sjisFontHeightI4[] = { 0, 8, 9, 9, 9, 8, 8, 8, 8, 8 };
+ const uint8 *htbl = (_vm->_game.id == GID_MONKEY) ? sjisFontHeightM1 : ((_vm->_game.id == GID_INDY4) ? sjisFontHeightI4 : sjisFontHeightM2);
+ return _vm->_useCJKMode ? htbl[_curId] : _fontHeight;
+}
+
+void CharsetRendererTownsClassic::drawBitsN(const Graphics::Surface&, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height) {
+ if (_sjisCurChar) {
+ assert(_vm->_cjkFont);
+ _vm->_cjkFont->drawChar(_vm->_textSurface, _sjisCurChar, _left * _vm->_textSurfaceMultiplier, (_top - _vm->_screenTop) * _vm->_textSurfaceMultiplier, _vm->_townsCharsetColorMap[1], _shadowColor);
+ return;
+ }
+
+ bool scale2x = (_vm->_textSurfaceMultiplier == 2);
+ dst = (byte *)_vm->_textSurface.pixels + (_top - _vm->_screenTop) * _vm->_textSurface.pitch * _vm->_textSurfaceMultiplier + _left * _vm->_textSurfaceMultiplier;
+
+ int y, x;
+ int color;
+ byte numbits, bits;
+
+ int pitch = _vm->_textSurface.pitch - width;
+
+ assert(bpp == 1 || bpp == 2 || bpp == 4 || bpp == 8);
+ bits = *src++;
+ numbits = 8;
+ byte *cmap = _vm->_charsetColorMap;
+ byte *dst2 = dst;
+
+ if (_vm->_game.platform == Common::kPlatformFMTowns)
+ cmap = _vm->_townsCharsetColorMap;
+ if (scale2x) {
+ dst2 += _vm->_textSurface.pitch;
+ pitch <<= 1;
+ }
+
+ for (y = 0; y < height && y + drawTop < _vm->_textSurface.h; y++) {
+ for (x = 0; x < width; x++) {
+ color = (bits >> (8 - bpp)) & 0xFF;
+
+ if (color && y + drawTop >= 0) {
+ *dst = cmap[color];
+ if (scale2x)
+ dst[1] = dst2[0] = dst2[1] = dst[0];
+ }
+ dst++;
+
+ if (scale2x) {
+ dst++;
+ dst2 += 2;
+ }
+
+ bits <<= bpp;
+ numbits -= bpp;
+ if (numbits == 0) {
+ bits = *src++;
+ numbits = 8;
+ }
+ }
+ dst += pitch;
+ dst2 += pitch;
+ }
+}
+
+bool CharsetRendererTownsClassic::prepareDraw(uint16 chr) {
+ processCharsetColors();
+ bool noSjis = false;
+
+ if (_vm->_game.platform == Common::kPlatformFMTowns && _vm->_useCJKMode) {
+ if ((chr & 0x00ff) == 0x00fd) {
+ chr >>= 8;
+ noSjis = true;
+ }
+ }
+
+ if (useFontRomCharacter(chr) && !noSjis) {
+ setupShadowMode();
+ _charPtr = 0;
+ _sjisCurChar = chr;
+
+ _width = getCharWidth(chr);
+ // For whatever reason MI1 uses a different font width
+ // for alignment calculation and for drawing when
+ // charset 2 is active. This fixes some subtle glitches.
+ if (_vm->_game.id == GID_MONKEY && _curId == 2)
+ _width--;
+ _origWidth = _width;
+
+ _origHeight = _height = getFontHeight();
+ _offsX = _offsY = 0;
+ } else if (_vm->_useCJKMode && (chr >= 128) && !noSjis) {
+ setupShadowMode();
+ _origWidth = _width = _vm->_2byteWidth;
+ _origHeight = _height = _vm->_2byteHeight;
+ _charPtr = _vm->get2byteCharPtr(chr);
+ _offsX = _offsY = 0;
+ if (_shadowMode) {
+ _width++;
+ _height++;
+ }
+ } else {
+ _sjisCurChar = 0;
+ return CharsetRendererClassic::prepareDraw(chr);
+ }
+ return true;
+}
+
+void CharsetRendererTownsClassic::setupShadowMode() {
+ _shadowMode = true;
+ _shadowColor = _vm->_townsCharsetColorMap[0];
+ assert(_vm->_cjkFont);
+
+ if (((_vm->_game.id == GID_MONKEY) && (_curId == 2 || _curId == 4 || _curId == 6)) ||
+ ((_vm->_game.id == GID_MONKEY2) && (_curId != 1 && _curId != 5 && _curId != 9)) ||
+ ((_vm->_game.id == GID_INDY4) && (_curId == 2 || _curId == 3 || _curId == 4))) {
+ _vm->_cjkFont->setDrawingMode(Graphics::FontSJIS::kOutlineMode);
+ } else {
+ _vm->_cjkFont->setDrawingMode(Graphics::FontSJIS::kDefaultMode);
+ }
+
+ _vm->_cjkFont->toggleFlippedMode((_vm->_game.id == GID_MONKEY || _vm->_game.id == GID_MONKEY2) && _curId == 3);
+}
+
+bool CharsetRendererTownsClassic::useFontRomCharacter(uint16 chr) {
+ if (!_vm->_useCJKMode)
+ return false;
+
+ // Some SCUMM 5 games contain hard coded logic to determine whether to use
+ // the SCUMM fonts or the FM-Towns font rom to draw a character. For the other
+ // games we will simply check for a character greater 127.
+ if (chr < 128) {
+ if (((_vm->_game.id == GID_MONKEY2 && _curId != 0) || (_vm->_game.id == GID_INDY4 && _curId != 3)) && (chr > 31 && chr != 94 && chr != 95 && chr != 126 && chr != 127))
+ return true;
+ return false;
+ }
+ return true;
+}
+
+void CharsetRendererTownsClassic::processCharsetColors() {
+ for (int i = 0; i < (1 << _bytesPerPixel); i++) {
+ uint8 c = _vm->_charsetColorMap[i];
+
+ if (c > 16) {
+ uint8 t = (_vm->_currentPalette[c * 3] < 32) ? 4 : 12;
+ t |= ((_vm->_currentPalette[c * 3 + 1] < 32) ? 2 : 10);
+ t |= ((_vm->_currentPalette[c * 3 + 1] < 32) ? 1 : 9);
+ c = t;
+ }
+
+ if (c == 0)
+ c = _vm->_townsOverrideShadowColor;
+
+ c = ((c & 0x0f) << 4) | (c & 0x0f);
+ _vm->_townsCharsetColorMap[i] = c;
+ }
+}
+#endif
+#endif
+
+void CharsetRendererNES::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
for (int i = 0; i < 8; i++) {
byte c0 = src[i];
byte c1 = src[i + 8];
diff --git a/engines/scumm/charset.h b/engines/scumm/charset.h
index 4c657b475e..b23ec996f5 100644
--- a/engines/scumm/charset.h
+++ b/engines/scumm/charset.h
@@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "common/rect.h"
#include "graphics/sjis.h"
+#include "scumm/scumm.h"
#include "scumm/gfx.h"
#include "scumm/saveload.h"
@@ -78,10 +79,6 @@ public:
void addLinebreaks(int a, byte *str, int pos, int maxwidth);
void translateColor();
-#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
- void processTownsCharsetColors(uint8 bytesPerPixel);
-#endif
-
virtual void setCurID(int32 id) = 0;
int getCurID() { return _curId; }
@@ -101,31 +98,26 @@ protected:
int _fontHeight;
int _numChars;
- enum ShadowMode {
- kNoShadowMode,
- kFMTOWNSShadowMode,
- kNormalShadowMode
- };
byte _shadowColor;
- ShadowMode _shadowMode;
-
- void enableShadow(bool enable);
- virtual void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth, bool scale2x = false);
-
+ bool _shadowMode;
public:
CharsetRendererCommon(ScummEngine *vm);
void setCurID(int32 id);
- int getFontHeight();
+ virtual int getFontHeight();
};
class CharsetRendererClassic : public CharsetRendererCommon {
protected:
- void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height, bool scale2x = false);
+ virtual void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height);
+ void printCharIntern(bool is2byte, const byte *charPtr, int origWidth, int origHeight, int width, int height, VirtScreen *vs, bool ignoreCharsetMask);
+ virtual bool prepareDraw(uint16 chr);
- void printCharIntern(bool is2byte, const byte *charPtr, int origWidth, int origHeight, int width, int height, VirtScreen *vs, bool ignoreCharsetMask);
+ int _width, _height, _origWidth, _origHeight;
+ int _offsX, _offsY;
+ const byte *_charPtr;
public:
CharsetRendererClassic(ScummEngine *vm) : CharsetRendererCommon(vm) {}
@@ -134,18 +126,34 @@ public:
void drawChar(int chr, Graphics::Surface &s, int x, int y);
int getCharWidth(uint16 chr);
+};
+
+#ifdef USE_RGB_COLOR
+#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
+class CharsetRendererTownsClassic : public CharsetRendererClassic {
+public:
+ CharsetRendererTownsClassic(ScummEngine *vm);
+
+ int getCharWidth(uint16 chr);
+ int getFontHeight();
- // Some SCUMM 5 games contain hard coded logic to determine whether to use
- // the SCUMM fonts or the FM-Towns font rom to draw a character. For the other
- // games we will simply check for a character greater 127.
- bool useTownsFontRomCharacter(uint16 chr);
+private:
+ void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height);
+ bool prepareDraw(uint16 chr);
+ void setupShadowMode();
+ bool useFontRomCharacter(uint16 chr);
+ void processCharsetColors();
+
+ uint16 _sjisCurChar;
};
+#endif
+#endif
class CharsetRendererNES : public CharsetRendererCommon {
protected:
byte *_trTable;
- void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth, bool scale2x = false);
+ void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth);
public:
CharsetRendererNES(ScummEngine *vm) : CharsetRendererCommon(vm) {}
@@ -160,6 +168,12 @@ public:
class CharsetRendererV3 : public CharsetRendererCommon {
protected:
+ virtual void enableShadow(bool enable);
+ virtual void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth);
+ virtual int getDrawWidthIntern(uint16 chr);
+ virtual int getDrawHeightIntern(uint16 chr);
+ virtual void setDrawCharIntern(uint16 chr) {}
+
const byte *_widthTable;
public:
@@ -169,16 +183,40 @@ public:
void drawChar(int chr, Graphics::Surface &s, int x, int y);
void setCurID(int32 id);
void setColor(byte color);
+ virtual int getCharWidth(uint16 chr);
+};
+
+class CharsetRendererTownsV3 : public CharsetRendererV3 {
+public:
+ CharsetRendererTownsV3(ScummEngine *vm);
+
int getCharWidth(uint16 chr);
+ int getFontHeight();
+
+private:
+ void enableShadow(bool enable);
+ void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth);
+#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
+ int getDrawWidthIntern(uint16 chr);
+ int getDrawHeightIntern(uint16 chr);
+ void setDrawCharIntern(uint16 chr);
+#endif
+ uint16 _sjisCurChar;
};
#ifdef USE_RGB_COLOR
class CharsetRendererPCE : public CharsetRendererV3 {
-protected:
- void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth, bool scale2x = false);
+private:
+ void drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth);
+
+ int getDrawWidthIntern(uint16 chr);
+ int getDrawHeightIntern(uint16 chr);
+ void setDrawCharIntern(uint16 chr);
+
+ uint16 _sjisCurChar;
public:
- CharsetRendererPCE(ScummEngine *vm) : CharsetRendererV3(vm) {}
+ CharsetRendererPCE(ScummEngine *vm) : CharsetRendererV3(vm), _sjisCurChar(0) {}
void setColor(byte color);
};
diff --git a/engines/scumm/cursor.cpp b/engines/scumm/cursor.cpp
index a8adb4d5c5..6739282c9d 100644
--- a/engines/scumm/cursor.cpp
+++ b/engines/scumm/cursor.cpp
@@ -22,6 +22,9 @@
#include "common/system.h"
#include "common/util.h"
#include "graphics/cursorman.h"
+#ifdef ENABLE_HE
+#include "graphics/wincursor.h"
+#endif
#include "scumm/bomp.h"
#include "scumm/charset.h"
#include "scumm/he/intern_he.h"
@@ -177,12 +180,8 @@ void ScummEngine_v70he::setDefaultCursor() {
0xff, 0xff, 0xff,
0, 0, 0, };
- if (_bytesPerPixel == 2) {
- for (i = 0; i < 1024; i++)
- WRITE_UINT16(_grabbedCursor + i * 2, 5);
- } else {
- memset(_grabbedCursor, 5, sizeof(_grabbedCursor));
- }
+
+ memset(_grabbedCursor, 5, sizeof(_grabbedCursor));
_cursor.hotspotX = _cursor.hotspotY = 2;
src = default_he_cursor;
@@ -195,16 +194,10 @@ void ScummEngine_v70he::setDefaultCursor() {
for (j = 0; j < 32; j++) {
switch ((p & (0x3 << 14)) >> 14) {
case 1:
- if (_bytesPerPixel == 2)
- WRITE_UINT16(_grabbedCursor + 64 * i + j * 2, get16BitColor(palette[4], palette[5], palette[6]));
- else
- _grabbedCursor[32 * i + j] = 0xfe;
+ _grabbedCursor[32 * i + j] = 0xfe;
break;
case 2:
- if (_bytesPerPixel == 2)
- WRITE_UINT16(_grabbedCursor + 64 * i + j * 2, get16BitColor(palette[0], palette[1], palette[2]));
- else
- _grabbedCursor[32 * i + j] = 0xfd;
+ _grabbedCursor[32 * i + j] = 0xfd;
break;
default:
break;
@@ -216,15 +209,63 @@ void ScummEngine_v70he::setDefaultCursor() {
}
}
+ // Since white color position is not guaranteed
+ // we setup our own palette if supported by backend
+ CursorMan.disableCursorPalette(false);
+ CursorMan.replaceCursorPalette(palette, 0xfd, 3);
+
+ updateCursor();
+}
+
+#ifdef ENABLE_HE
+void ScummEngine_v80he::setDefaultCursor() {
+ // v80+ games use the default Windows cursor instead of the usual
+ // default HE cursor.
+ Graphics::Cursor *cursor = Graphics::makeDefaultWinCursor();
+
+ // Clear the cursor
+ if (_bytesPerPixel == 2) {
+ for (int i = 0; i < 1024; i++)
+ WRITE_UINT16(_grabbedCursor + i * 2, 5);
+ } else {
+ memset(_grabbedCursor, 5, sizeof(_grabbedCursor));
+ }
+
+ _cursor.width = cursor->getWidth();
+ _cursor.height = cursor->getHeight();
+ _cursor.hotspotX = cursor->getHotspotX();
+ _cursor.hotspotY = cursor->getHotspotY();
+
+ const byte *surface = cursor->getSurface();
+ const byte *palette = cursor->getPalette();
+
+ for (uint16 y = 0; y < _cursor.height; y++) {
+ for (uint16 x = 0; x < _cursor.width; x++) {
+ byte pixel = *surface++;
+
+ if (pixel != cursor->getKeyColor()) {
+ pixel -= cursor->getPaletteStartIndex();
+
+ if (_bytesPerPixel == 2)
+ WRITE_UINT16(_grabbedCursor + (y * _cursor.width + x) * 2, get16BitColor(palette[pixel * 3], palette[pixel * 3 + 1], palette[pixel * 3 + 2]));
+ else
+ _grabbedCursor[y * _cursor.width + x] = (pixel == 0) ? 0xfd : 0xfe;
+ }
+ }
+ }
+
if (_bytesPerPixel == 1) {
// Since white color position is not guaranteed
// we setup our own palette if supported by backend
CursorMan.disableCursorPalette(false);
- CursorMan.replaceCursorPalette(palette, 0xfd, 3);
+ CursorMan.replaceCursorPalette(palette, 0xfd, cursor->getPaletteCount());
}
+ delete cursor;
+
updateCursor();
}
+#endif
void ScummEngine_v6::setCursorFromImg(uint img, uint room, uint imgindex) {
int w, h;
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index 18f2f4ddec..037c12bdbf 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -33,6 +33,8 @@
#include "common/savefile.h"
#include "common/system.h"
+#include "audio/mididrv.h"
+
#include "scumm/detection.h"
#include "scumm/detection_tables.h"
#include "scumm/he/intern_he.h"
@@ -142,6 +144,14 @@ Common::String ScummEngine_v70he::generateFilename(const int room) const {
Common::String result;
char id = 0;
+ Common::String bPattern = _filenamePattern.pattern;
+
+ // Special cases for Blue's games, which share common (b) files
+ if (_game.id == GID_BIRTHDAYYELLOW || _game.id == GID_BIRTHDAYRED)
+ bPattern = "Blue'sBirthday";
+ else if (_game.id == GID_TREASUREHUNT)
+ bPattern = "Blue'sTreasureHunt";
+
switch (_filenamePattern.genMethod) {
case kGenHEMac:
case kGenHEMacNoParens:
@@ -154,13 +164,7 @@ Common::String ScummEngine_v70he::generateFilename(const int room) const {
switch (disk) {
case 2:
id = 'b';
- // Special cases for Blue's games, which share common (b) files
- if (_game.id == GID_BIRTHDAY && !(_game.features & GF_DEMO))
- result = "Blue'sBirthday.(b)";
- else if (_game.id == GID_TREASUREHUNT)
- result = "Blue'sTreasureHunt.(b)";
- else
- result = Common::String::format("%s.(b)", _filenamePattern.pattern);
+ result = bPattern + ".(b)";
break;
case 1:
id = 'a';
@@ -185,10 +189,11 @@ Common::String ScummEngine_v70he::generateFilename(const int room) const {
// For mac they're stored in game binary
result = _filenamePattern.pattern;
} else {
+ Common::String pattern = id == 'b' ? bPattern : _filenamePattern.pattern;
if (_filenamePattern.genMethod == kGenHEMac)
- result = Common::String::format("%s (%c)", _filenamePattern.pattern, id);
+ result = Common::String::format("%s (%c)", pattern.c_str(), id);
else
- result = Common::String::format("%s %c", _filenamePattern.pattern, id);
+ result = Common::String::format("%s %c", pattern.c_str(), id);
}
}
diff --git a/engines/scumm/detection_tables.h b/engines/scumm/detection_tables.h
index e510c46cf2..78645ea8d5 100644
--- a/engines/scumm/detection_tables.h
+++ b/engines/scumm/detection_tables.h
@@ -222,7 +222,7 @@ static const GameSettings gameVariantsTable[] = {
{"indy3", "EGA", "ega", GID_INDY3, 3, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB, 0, UNK, GUIO_NOSPEECH | GUIO_NOMIDI},
{"indy3", "No AdLib", "ega", GID_INDY3, 3, 0, MDT_PCSPK | MDT_PCJR, 0, UNK, GUIO_NOSPEECH | GUIO_NOMIDI},
- {"indy3", "VGA", "vga", GID_INDY3, 3, 0, MDT_PCSPK | MDT_PCJR | MDT_ADLIB, GF_OLD256 | GF_FEW_LOCALS, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
+ {"indy3", "VGA", "vga", GID_INDY3, 3, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB, GF_OLD256 | GF_FEW_LOCALS, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
{"indy3", "FM-TOWNS", 0, GID_INDY3, 3, 0, MDT_TOWNS, GF_OLD256 | GF_FEW_LOCALS | GF_AUDIOTRACKS, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_NOMIDI | GUIO_MIDITOWNS},
{"loom", "EGA", "ega", GID_LOOM, 3, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
@@ -233,9 +233,9 @@ static const GameSettings gameVariantsTable[] = {
{"loom", "FM-TOWNS", 0, GID_LOOM, 3, 0, MDT_TOWNS, GF_AUDIOTRACKS | GF_OLD256, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_NOMIDI | GUIO_MIDITOWNS},
{"loom", "VGA", "vga", GID_LOOM, 4, 0, MDT_NONE, GF_AUDIOTRACKS, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
- {"pass", 0, 0, GID_PASS, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_ADLIB, GF_16COLOR, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
+ {"pass", 0, 0, GID_PASS, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB, GF_16COLOR, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
- {"monkey", "VGA", "vga", GID_MONKEY_VGA, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
+ {"monkey", "VGA", "vga", GID_MONKEY_VGA, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
{"monkey", "EGA", "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, GF_16COLOR, Common::kPlatformPC, GUIO_NOSPEECH},
{"monkey", "No AdLib", "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_PCJR, GF_16COLOR, Common::kPlatformAtariST, GUIO_NOSPEECH | GUIO_NOMIDI},
{"monkey", "Demo", "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_ADLIB, GF_16COLOR, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
@@ -243,11 +243,11 @@ static const GameSettings gameVariantsTable[] = {
{"monkey", "FM-TOWNS", 0, GID_MONKEY, 5, 0, MDT_TOWNS, GF_AUDIOTRACKS, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_NOMIDI | GUIO_MIDITOWNS},
{"monkey", "SEGA", 0, GID_MONKEY, 5, 0, MDT_NONE, GF_AUDIOTRACKS, Common::kPlatformSegaCD, GUIO_NOSPEECH | GUIO_NOMIDI},
- {"monkey2", "", 0, GID_MONKEY2, 5, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
- {"monkey2", "FM-TOWNS", 0, GID_MONKEY2, 5, 0, MDT_TOWNS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_MIDITOWNS | GUIO_MIDIADLIB | GUIO_MIDIMT32},
+ {"monkey2", "", 0, GID_MONKEY2, 5, 0, MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
+ {"monkey2", "FM-TOWNS", 0, GID_MONKEY2, 5, 0, MDT_PCSPK | MDT_TOWNS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_MIDITOWNS | GUIO_MIDIADLIB | GUIO_MIDIMT32},
- {"atlantis", "", 0, GID_INDY4, 5, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NONE},
- {"atlantis", "Floppy", 0, GID_INDY4, 5, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
+ {"atlantis", "", 0, GID_INDY4, 5, 0, MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NONE},
+ {"atlantis", "Floppy", 0, GID_INDY4, 5, 0, MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
{"atlantis", "FM-TOWNS", 0, GID_INDY4, 5, 0, MDT_TOWNS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MT32, 0, Common::kPlatformFMTowns, GUIO_MIDITOWNS | GUIO_MIDIADLIB | GUIO_MIDIMT32},
{"tentacle", "", 0, GID_TENTACLE, 6, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_GM, GF_USE_KEY, UNK, GUIO_NONE},
@@ -343,7 +343,9 @@ static const GameSettings gameVariantsTable[] = {
{"puttrace", "HE 99", 0, GID_PUTTRACE, 6, 99, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
{"bluesabctime", "", 0, GID_HEGAME, 6, 98, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
- {"BluesBirthday", 0, 0, GID_BIRTHDAY, 6, 98, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
+ {"BluesBirthday", "", 0, GID_HEGAME, 6, 98, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
+ {"BluesBirthday", "Red", 0, GID_BIRTHDAYRED, 6, 98, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
+ {"BluesBirthday", "Yellow", 0, GID_BIRTHDAYYELLOW, 6, 98, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
{"soccer", "", 0, GID_SOCCER, 6, 98, MDT_NONE, GF_USE_KEY, UNK, GUIO_NOLAUNCHLOAD | GUIO_NOMIDI},
// Global scripts increased to 2048
diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp
index f7f0c7d7ec..74a92f2204 100644
--- a/engines/scumm/dialogs.cpp
+++ b/engines/scumm/dialogs.cpp
@@ -23,6 +23,7 @@
#include "common/savefile.h"
#include "common/system.h"
#include "common/events.h"
+#include "common/localization.h"
#include "common/translation.h"
#include "graphics/scaler.h"
@@ -171,29 +172,33 @@ static const ResString string_map_table_v6[] = {
};
static const ResString string_map_table_v345[] = {
- {1, "Insert Disk %c and Press Button to Continue."},
- {2, "Unable to Find %s, (%c%d) Press Button."},
- {3, "Error reading disk %c, (%c%d) Press Button."},
- {4, "Game Paused. Press SPACE to Continue."},
- {5, "Are you sure you want to restart? (Y/N)"},
- {6, "Are you sure you want to quit? (Y/N)"},
+ {1, _s("Insert Disk %c and Press Button to Continue.")},
+ {2, _s("Unable to Find %s, (%c%d) Press Button.")},
+ {3, _s("Error reading disk %c, (%c%d) Press Button.")},
+ {4, _s("Game Paused. Press SPACE to Continue.")},
+ // I18N: You may specify 'Yes' symbol at the end of the line, like this:
+ // "Moechten Sie wirklich neu starten? (J/N)J"
+ // Will react to J as 'Yes'
+ {5, _s("Are you sure you want to restart? (Y/N)")},
+ // I18N: you may specify 'Yes' symbol at the end of the line. See previous comment
+ {6, _s("Are you sure you want to quit? (Y/N)")},
// Added in SCUMM4
- {7, "Save"},
- {8, "Load"},
- {9, "Play"},
- {10, "Cancel"},
- {11, "Quit"},
- {12, "OK"},
- {13, "Insert save/load game disk"},
- {14, "You must enter a name"},
- {15, "The game was NOT saved (disk full?)"},
- {16, "The game was NOT loaded"},
- {17, "Saving '%s'"},
- {18, "Loading '%s'"},
- {19, "Name your SAVE game"},
- {20, "Select a game to LOAD"},
- {28, "Game title"}
+ {7, _s("Save")},
+ {8, _s("Load")},
+ {9, _s("Play")},
+ {10, _s("Cancel")},
+ {11, _s("Quit")},
+ {12, _s("OK")},
+ {13, _s("Insert save/load game disk")},
+ {14, _s("You must enter a name")},
+ {15, _s("The game was NOT saved (disk full?)")},
+ {16, _s("The game was NOT loaded")},
+ {17, _s("Saving '%s'")},
+ {18, _s("Loading '%s'")},
+ {19, _s("Name your SAVE game")},
+ {20, _s("Select a game to LOAD")},
+ {28, _s("Game title)")}
};
#pragma mark -
@@ -278,7 +283,9 @@ HelpDialog::HelpDialog(const GameSettings &game)
_numPages = ScummHelp::numPages(_game.id);
+ // I18N: Previous page button
_prevButton = new GUI::ButtonWidget(this, "ScummHelp.Prev", _("~P~revious"), 0, kPrevCmd);
+ // I18N: Next page button
_nextButton = new GUI::ButtonWidget(this, "ScummHelp.Next", _("~N~ext"), 0, kNextCmd);
new GUI::ButtonWidget(this, "ScummHelp.Close", _("~C~lose"), 0, GUI::kCloseCmd);
_prevButton->clearFlags(WIDGET_ENABLED);
@@ -429,7 +436,7 @@ const Common::String InfoDialog::queryResString(int stringno) {
else if (_vm->_game.version >= 3)
result = _vm->getStringAddress(string_map_table_v345[stringno - 1].num);
else
- return string_map_table_v345[stringno - 1].string;
+ return _(string_map_table_v345[stringno - 1].string);
if (result && *result == '/') {
_vm->translateText(result, buf);
@@ -437,7 +444,7 @@ const Common::String InfoDialog::queryResString(int stringno) {
}
if (!result || *result == '\0') { // Gracelessly degrade to english :)
- return string_map_table_v345[stringno - 1].string;
+ return _(string_map_table_v345[stringno - 1].string);
}
// Convert to a proper string (take care of FF codes)
@@ -482,10 +489,14 @@ ConfirmDialog::ConfirmDialog(ScummEngine *scumm, int res)
}
void ConfirmDialog::handleKeyDown(Common::KeyState state) {
- if (state.keycode == Common::KEYCODE_n || state.ascii == _noKey) {
+ Common::KeyCode keyYes, keyNo;
+
+ Common::getLanguageYesNo(keyYes, keyNo);
+
+ if (state.keycode == Common::KEYCODE_n || state.ascii == _noKey || state.ascii == keyNo) {
setResult(0);
close();
- } else if (state.keycode == Common::KEYCODE_y || state.ascii == _yesKey) {
+ } else if (state.keycode == Common::KEYCODE_y || state.ascii == _yesKey || state.ascii == keyYes) {
setResult(1);
close();
} else
@@ -583,9 +594,9 @@ void SubtitleSettingsDialog::open() {
void SubtitleSettingsDialog::cycleValue() {
static const char* subtitleDesc[] = {
- "Speech Only",
- "Speech and Subtitles",
- "Subtitles Only"
+ _s("Speech Only"),
+ _s("Speech and Subtitles"),
+ _s("Subtitles Only")
};
_value += 1;
@@ -593,9 +604,9 @@ void SubtitleSettingsDialog::cycleValue() {
_value = 0;
if (_value == 1 && g_system->getOverlayWidth() <= 320)
- setInfoText("Speech & Subs");
+ setInfoText(_sc("Speech & Subs", "lowres"));
else
- setInfoText(subtitleDesc[_value]);
+ setInfoText(_(subtitleDesc[_value]));
_timer = g_system->getMillis() + 1500;
}
diff --git a/engines/scumm/gfx.cpp b/engines/scumm/gfx.cpp
index f22547f193..8a32b963cd 100644
--- a/engines/scumm/gfx.cpp
+++ b/engines/scumm/gfx.cpp
@@ -4111,4 +4111,3 @@ void ScummEngine::unkScreenEffect6() {
}
} // End of namespace Scumm
-
diff --git a/engines/scumm/he/animation_he.cpp b/engines/scumm/he/animation_he.cpp
index 74183c24d3..40e99c26a8 100644
--- a/engines/scumm/he/animation_he.cpp
+++ b/engines/scumm/he/animation_he.cpp
@@ -26,27 +26,42 @@
#include "scumm/he/intern_he.h"
#include "audio/audiostream.h"
+#include "video/smk_decoder.h"
+
+#ifdef USE_BINK
+#include "video/bink_decoder.h"
+#endif
namespace Scumm {
-MoviePlayer::MoviePlayer(ScummEngine_v90he *vm, Audio::Mixer *mixer)
- : SmackerDecoder(mixer), _vm(vm), _mixer(mixer) {
+MoviePlayer::MoviePlayer(ScummEngine_v90he *vm, Audio::Mixer *mixer) : _vm(vm) {
+#ifdef USE_BINK
+ if (_vm->_game.heversion >= 100 && (_vm->_game.features & GF_16BIT_COLOR))
+ _video = new Video::BinkDecoder();
+ else
+#endif
+ _video = new Video::SmackerDecoder(mixer);
_flags = 0;
_wizResNum = 0;
}
+MoviePlayer::~MoviePlayer() {
+ delete _video;
+}
+
int MoviePlayer::getImageNum() {
- if (!isVideoLoaded())
+ if (!_video->isVideoLoaded())
return 0;
+
return _wizResNum;
}
int MoviePlayer::load(const char *filename, int flags, int image) {
- if (isVideoLoaded())
- close();
+ if (_video->isVideoLoaded())
+ _video->close();
- if (!loadFile(filename)) {
+ if (!_video->loadFile(filename)) {
warning("Failed to load video file %s", filename);
return -1;
}
@@ -54,7 +69,7 @@ int MoviePlayer::load(const char *filename, int flags, int image) {
debug(1, "Playing video %s", filename);
if (flags & 2)
- _vm->_wiz->createWizEmptyImage(image, 0, 0, getWidth(), getHeight());
+ _vm->_wiz->createWizEmptyImage(image, 0, 0, _video->getWidth(), _video->getHeight());
_flags = flags;
_wizResNum = image;
@@ -62,34 +77,59 @@ int MoviePlayer::load(const char *filename, int flags, int image) {
}
void MoviePlayer::copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint pitch) {
- uint h = getHeight();
- uint w = getWidth();
+ uint h = _video->getHeight();
+ uint w = _video->getWidth();
+
+ const Graphics::Surface *surface = _video->decodeNextFrame();
+
+ if (!surface)
+ return;
- const Graphics::Surface *surface = decodeNextFrame();
byte *src = (byte *)surface->pixels;
- if (hasDirtyPalette())
- _vm->setPaletteFromPtr(getPalette(), 256);
+ if (_video->hasDirtyPalette())
+ _vm->setPaletteFromPtr(_video->getPalette(), 256);
if (_vm->_game.features & GF_16BIT_COLOR) {
- dst += y * pitch + x * 2;
- do {
- for (uint i = 0; i < w; i++) {
- uint16 color = READ_LE_UINT16(_vm->_hePalettes + _vm->_hePaletteSlot + 768 + src[i] * 2);
- switch (dstType) {
- case kDstScreen:
- WRITE_UINT16(dst + i * 2, color);
- break;
- case kDstResource:
- WRITE_LE_UINT16(dst + i * 2, color);
- break;
- default:
- error("copyFrameToBuffer: Unknown dstType %d", dstType);
+ if (surface->format.bytesPerPixel == 1) {
+ dst += y * pitch + x * 2;
+ do {
+ for (uint i = 0; i < w; i++) {
+ uint16 color = READ_LE_UINT16(_vm->_hePalettes + _vm->_hePaletteSlot + 768 + src[i] * 2);
+ switch (dstType) {
+ case kDstScreen:
+ WRITE_UINT16(dst + i * 2, color);
+ break;
+ case kDstResource:
+ WRITE_LE_UINT16(dst + i * 2, color);
+ break;
+ default:
+ error("copyFrameToBuffer: Unknown dstType %d", dstType);
+ }
}
- }
- dst += pitch;
- src += w;
- } while (--h);
+ dst += pitch;
+ src += w;
+ } while (--h);
+ } else {
+ dst += y * pitch + x * 2;
+ do {
+ for (uint i = 0; i < w; i++) {
+ uint16 color = *((uint16 *)src + i);
+ switch (dstType) {
+ case kDstScreen:
+ WRITE_UINT16(dst + i * 2, color);
+ break;
+ case kDstResource:
+ WRITE_LE_UINT16(dst + i * 2, color);
+ break;
+ default:
+ error("copyFrameToBuffer: Unknown dstType %d", dstType);
+ }
+ }
+ dst += pitch;
+ src += surface->pitch;
+ } while (--h);
+ }
} else {
dst += y * pitch + x;
do {
@@ -101,7 +141,7 @@ void MoviePlayer::copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint
}
void MoviePlayer::handleNextFrame() {
- if (!isVideoLoaded())
+ if (!_video->isVideoLoaded())
return;
VirtScreen *pvs = &_vm->_virtscr[kMainVirtScreen];
@@ -115,17 +155,37 @@ void MoviePlayer::handleNextFrame() {
} else if (_flags & 1) {
copyFrameToBuffer(pvs->getBackPixels(0, 0), kDstScreen, 0, 0, pvs->pitch);
- Common::Rect imageRect(getWidth(), getHeight());
+ Common::Rect imageRect(_video->getWidth(), _video->getHeight());
_vm->restoreBackgroundHE(imageRect);
} else {
copyFrameToBuffer(pvs->getPixels(0, 0), kDstScreen, 0, 0, pvs->pitch);
- Common::Rect imageRect(getWidth(), getHeight());
+ Common::Rect imageRect(_video->getWidth(), _video->getHeight());
_vm->markRectAsDirty(kMainVirtScreen, imageRect);
}
- if (endOfVideo())
- close();
+ if (_video->endOfVideo())
+ _video->close();
+}
+
+void MoviePlayer::close() {
+ _video->close();
+}
+
+int MoviePlayer::getWidth() const {
+ return _video->getWidth();
+}
+
+int MoviePlayer::getHeight() const {
+ return _video->getHeight();
+}
+
+int MoviePlayer::getFrameCount() const {
+ return _video->getFrameCount();
+}
+
+int MoviePlayer::getCurFrame() const {
+ return _video->endOfVideo() ? -1 : _video->getCurFrame() + 1;
}
} // End of namespace Scumm
diff --git a/engines/scumm/he/animation_he.h b/engines/scumm/he/animation_he.h
index b3405fead0..7fa31a195d 100644
--- a/engines/scumm/he/animation_he.h
+++ b/engines/scumm/he/animation_he.h
@@ -23,34 +23,41 @@
#if !defined(SCUMM_HE_ANIMATION_H) && defined(ENABLE_HE)
#define SCUMM_HE_ANIMATION_H
-#include "video/smk_decoder.h"
-
#include "audio/mixer.h"
+namespace Video {
+ class VideoDecoder;
+}
+
namespace Scumm {
class ScummEngine_v90he;
-class MoviePlayer : public Video::SmackerDecoder {
- ScummEngine_v90he *_vm;
-
- Audio::Mixer *_mixer;
-
- Audio::SoundHandle _bgSound;
- Audio::AudioStream *_bgSoundStream;
-
- char baseName[40];
- uint32 _flags;
- uint32 _wizResNum;
-
+class MoviePlayer {
public:
MoviePlayer(ScummEngine_v90he *vm, Audio::Mixer *mixer);
+ ~MoviePlayer();
int getImageNum();
int load(const char *filename, int flags, int image = 0);
void copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint pitch);
void handleNextFrame();
+
+ void close();
+ int getWidth() const;
+ int getHeight() const;
+ int getFrameCount() const;
+ int getCurFrame() const;
+
+private:
+ ScummEngine_v90he *_vm;
+
+ Video::VideoDecoder *_video;
+
+ char baseName[40];
+ uint32 _flags;
+ uint32 _wizResNum;
};
} // End of namespace Scumm
diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h
index c49217b650..f4df6571fa 100644
--- a/engines/scumm/he/intern_he.h
+++ b/engines/scumm/he/intern_he.h
@@ -383,6 +383,8 @@ protected:
void drawLine(int x1, int y1, int x, int unk1, int unk2, int type, int id);
void drawPixel(int x, int y, int flags);
+ virtual void setDefaultCursor();
+
/* HE version 80 script opcodes */
void o80_createSound();
void o80_getFileSize();
diff --git a/engines/scumm/he/logic/baseball2001.cpp b/engines/scumm/he/logic/baseball2001.cpp
new file mode 100644
index 0000000000..342423fd79
--- /dev/null
+++ b/engines/scumm/he/logic/baseball2001.cpp
@@ -0,0 +1,63 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Backyard Baseball 2001
+ */
+class LogicHEbaseball2001 : public LogicHE {
+public:
+ LogicHEbaseball2001(ScummEngine_v90he *vm) : LogicHE(vm) {}
+
+ int versionID();
+ int32 dispatch(int op, int numArgs, int32 *args);
+};
+
+int LogicHEbaseball2001::versionID() {
+ return 1;
+}
+
+int32 LogicHEbaseball2001::dispatch(int op, int numArgs, int32 *args) {
+ int res = 0;
+
+ switch (op) {
+ case 3001:
+ // Check network status
+ break;
+
+ default:
+ LogicHE::dispatch(op, numArgs, args);
+ }
+
+ return res;
+}
+
+LogicHE *makeLogicHEbaseball2001(ScummEngine_v90he *vm) {
+ return new LogicHEbaseball2001(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic/basketball.cpp b/engines/scumm/he/logic/basketball.cpp
new file mode 100644
index 0000000000..8352aa4357
--- /dev/null
+++ b/engines/scumm/he/logic/basketball.cpp
@@ -0,0 +1,230 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Backyard Basketball
+ */
+class LogicHEbasketball : public LogicHE {
+public:
+ LogicHEbasketball(ScummEngine_v90he *vm) : LogicHE(vm) {}
+
+ int versionID();
+ int32 dispatch(int op, int numArgs, int32 *args);
+
+private:
+ int op_1012();
+ int op_1050(int32 *args);
+ int op_1053();
+
+ // op_1050 loads court object data
+ enum CourtObjectType {
+ kObjectTypeBackboard = 1,
+ kObjectTypeRim = 2,
+ kObjectTypeOther = 3,
+ kObjectTypeFloor = 4
+ };
+
+ struct CourtObject {
+ Common::String name;
+ CourtObjectType type;
+ uint32 data[10];
+ };
+
+ Common::Array<CourtObject> _courtObjects;
+ uint32 _backboardObjectLeft, _backboardObjectRight;
+};
+
+int LogicHEbasketball::versionID() {
+ return 1;
+}
+
+int32 LogicHEbasketball::dispatch(int op, int numArgs, int32 *args) {
+ int res = 0;
+
+ switch (op) {
+ case 1001:
+ break;
+
+ case 1006:
+ break;
+
+ case 1011:
+ break;
+
+ case 1012:
+ res = op_1012();
+ break;
+
+ case 1035:
+ break;
+
+ case 1050:
+ res = op_1050(args);
+ break;
+
+ case 1051:
+ break;
+
+ case 1052:
+ break;
+
+ case 1053:
+ res = op_1053();
+ break;
+
+ case 1056:
+ break;
+
+ case 1057:
+ break;
+
+ case 1058:
+ break;
+
+ case 1060:
+ break;
+
+ case 1064:
+ break;
+
+ case 1067:
+ break;
+
+ case 1073:
+ break;
+
+ case 1075:
+ break;
+
+ case 1076:
+ break;
+
+ case 1080:
+ break;
+
+ case 1081:
+ break;
+
+ case 1090:
+ break;
+
+ case 1091:
+ break;
+
+ case 1513:
+ break;
+
+ default:
+ LogicHE::dispatch(op, numArgs, args);
+ }
+
+ return res;
+}
+
+int LogicHEbasketball::op_1012() {
+ writeScummVar(108, 12000);
+ writeScummVar(109, 8000);
+ writeScummVar(110, 760);
+ writeScummVar(111, 4000);
+ writeScummVar(112, 1600);
+ return 1;
+}
+
+int LogicHEbasketball::op_1050(int32 *args) {
+ // This function loads the court data
+ static const char *courtNames[] = {
+ "Dobbaguchi", "Jocindas", "SandyFlats", "Queens",
+ "Park", "Scheffler", "Polk", "McMillan",
+ "CrownHill", "Memorial", "TechState", "Garden",
+ "Moon", "Barn"
+ };
+
+ Common::String courtFileName = Common::String::format("data/courts/%s.cof", courtNames[args[0] - 1]);
+
+ Common::File file;
+ if (!file.open(courtFileName))
+ error("Could not open file '%s'", courtFileName.c_str());
+
+ debug(0, "Loading court data from '%s'", courtFileName.c_str());
+
+ // First, read in the header
+ file.readUint32LE(); // Header size (?)
+
+ char version[6];
+ file.read(version, 5);
+ version[5] = 0;
+
+ if (strcmp(version, "01.05"))
+ error("Invalid court version field: %s", version);
+
+ uint32 objectCount = file.readUint32LE();
+
+ for (uint32 i = 0; i < objectCount; i++) {
+ char nameBuf[100];
+ memset(nameBuf, 0, sizeof(nameBuf));
+
+ uint32 nameLength = file.readUint32LE();
+ assert(nameLength < sizeof(nameBuf) - 1);
+ file.read(nameBuf, nameLength);
+
+ CourtObject object;
+ object.name = nameBuf;
+ object.type = (CourtObjectType)file.readUint32LE();
+ for (uint32 j = 0; j < 10; j++)
+ object.data[j] = file.readUint32LE();
+
+ debug(1, "Found court object '%s' - Type %d", nameBuf, object.type);
+
+ // Store backboard object indices for later
+ if (object.type == kObjectTypeBackboard) {
+ if (object.data[7] + object.data[4] / 2 >= 6000)
+ _backboardObjectRight = i;
+ else
+ _backboardObjectLeft = i;
+ }
+
+ _courtObjects.push_back(object);
+ }
+
+ // TODO: Some other variables are initialized with constants here
+
+ return 1;
+}
+
+int LogicHEbasketball::op_1053() {
+ _courtObjects.clear();
+ // TODO: This also calls op_1065 with one argument (5)
+
+ return 1;
+}
+
+LogicHE *makeLogicHEbasketball(ScummEngine_v90he *vm) {
+ return new LogicHEbasketball(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic/football.cpp b/engines/scumm/he/logic/football.cpp
new file mode 100644
index 0000000000..f86f97eaf7
--- /dev/null
+++ b/engines/scumm/he/logic/football.cpp
@@ -0,0 +1,288 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Backyard Football
+ * Backyard Football 2002
+ */
+class LogicHEfootball : public LogicHE {
+public:
+ LogicHEfootball(ScummEngine_v90he *vm) : LogicHE(vm) {}
+
+ int versionID();
+ int32 dispatch(int op, int numArgs, int32 *args);
+
+private:
+ int op_1004(int32 *args);
+ int op_1006(int32 *args);
+ int op_1007(int32 *args);
+ int op_1010(int32 *args);
+ int op_1022(int32 *args);
+ int op_1023(int32 *args);
+ int op_1024(int32 *args);
+};
+
+int LogicHEfootball::versionID() {
+ return 1;
+}
+
+int32 LogicHEfootball::dispatch(int op, int numArgs, int32 *args) {
+ int res = 0;
+
+ switch (op) {
+ case 1004:
+ res = op_1004(args);
+ break;
+
+ case 1006:
+ res = op_1006(args);
+ break;
+
+ case 1007:
+ res = op_1007(args);
+ break;
+
+ case 1010:
+ res = op_1010(args);
+ break;
+
+ case 1022:
+ res = op_1022(args);
+ break;
+
+ case 1023:
+ res = op_1023(args);
+ break;
+
+ case 1024:
+ res = op_1024(args);
+ break;
+
+ case 8221968:
+ // Someone had a fun and used his birthday as opcode number
+ res = getFromArray(args[0], args[1], args[2]);
+ break;
+
+ case 1492: case 1493: case 1494: case 1495: case 1496:
+ case 1497: case 1498: case 1499: case 1500: case 1501:
+ case 1502: case 1503: case 1504: case 1505: case 1506:
+ case 1507: case 1508: case 1509: case 1510: case 1511:
+ case 1512: case 1513: case 1514: case 1555:
+ // DirectPlay-related
+ // 1513: initialize
+ // 1555: set fake lag
+ break;
+
+ case 2200: case 2201: case 2202: case 2203: case 2204:
+ case 2205: case 2206: case 2207: case 2208: case 2209:
+ case 2210: case 2211: case 2212: case 2213: case 2214:
+ case 2215: case 2216: case 2217: case 2218: case 2219:
+ case 2220: case 2221: case 2222: case 2223: case 2224:
+ case 2225: case 2226: case 2227: case 2228:
+ // Boneyards-related
+ break;
+
+ case 3000: case 3001: case 3002: case 3003: case 3004:
+ // Internet-related
+ // 3000: check for updates
+ // 3001: check network status
+ // 3002: autoupdate
+ // 3003: close connection
+ break;
+
+ default:
+ LogicHE::dispatch(op, numArgs, args);
+ warning("Tell sev how to reproduce it (%d)", op);
+ }
+
+ return res;
+}
+
+int LogicHEfootball::op_1004(int32 *args) {
+ // Identical to LogicHEsoccer::op_1004
+ double res, a2, a4, a5;
+
+ a5 = ((double)args[4] - (double)args[1]) / ((double)args[5] - (double)args[2]);
+ a4 = ((double)args[3] - (double)args[0]) / ((double)args[5] - (double)args[2]);
+ a2 = (double)args[2] - (double)args[0] * a4 - args[1] * a5;
+
+ res = (double)args[6] * a4 + (double)args[7] * a5 + a2;
+ writeScummVar(108, (int32)res);
+
+ writeScummVar(109, (int32)a2);
+ writeScummVar(110, (int32)a5);
+ writeScummVar(111, (int32)a4);
+
+ return 1;
+}
+
+int LogicHEfootball::op_1006(int32 *args) {
+ // This seems to be more or less the inverse of op_1010
+ const double a1 = args[1];
+ double res;
+
+ // 2.9411764e-4 = 1/3400
+ // 5.3050399e-2 = 1/18.85 = 20/377
+ // 1.1764706e-2 = 1/85 = 40/3400
+ // 1.2360656e-1 = 377/3050
+ res = (1.0 - a1 * 2.9411764e-4 * 5.3050399e-2) * 1.2360656e-1 * args[0] +
+ a1 * 1.1764706e-2 + 46;
+
+ // Shortened / optimized version of that formula:
+ // res = (377.0 - a1 / 170.0) / 3050.0 * args[0] + a1 / 85.0 + 46;
+
+ writeScummVar(108, (int32)res);
+
+ // 1.2360656e-1 = 377/3050
+ // 1.1588235e-1 = 197/1700 = 394/3400
+ res = 640.0 - args[2] * 1.2360656e-1 - a1 * 1.1588235e-1 - 26;
+
+ writeScummVar(109, (int32)res);
+
+ return 1;
+}
+
+int LogicHEfootball::op_1007(int32 *args) {
+ double res, temp;
+
+ temp = (double)args[1] * 0.32;
+
+ if (temp > 304.0)
+ res = -args[2] * 0.142;
+ else
+ res = args[2] * 0.142;
+
+ res += temp;
+
+ writeScummVar(108, (int32)res);
+
+ res = (1000.0 - args[2]) * 0.48;
+
+ writeScummVar(109, (int32)res);
+
+ return 1;
+}
+
+int LogicHEfootball::op_1010(int32 *args) {
+ // This seems to be more or less the inverse of op_1006
+ double a1 = (640.0 - (double)args[1] - 26.0) / 1.1588235e-1;
+
+ // 2.9411764e-4 = 1/3400
+ // 5.3050399e-2 = 1/18.85 = 20/377
+ // 1.1764706e-2 = 1/85 = 40/3400
+ // 1.2360656e-1 = 377/3050
+ double a0 = ((double)args[0] - 46 - a1 * 1.1764706e-2) /
+ ((1.0 - a1 * 2.9411764e-4 * 5.3050399e-2) * 1.2360656e-1);
+
+ writeScummVar(108, (int32)a0);
+ writeScummVar(109, (int32)a1);
+
+ return 1;
+}
+
+int LogicHEfootball::op_1022(int32 *args) {
+ double res;
+ double var10 = args[4] - args[1];
+ double var8 = args[5] - args[2];
+ double var6 = args[3] - args[0];
+
+ res = sqrt(var8 * var8 + var6 * var6 + var10 * var10);
+
+ if (res >= (double)args[6]) {
+ var8 = (double)args[6] * var8 / res;
+ var10 = (double)args[6] * var10 / res;
+ res = (double)args[6] * var6 / res;
+ }
+
+ writeScummVar(108, (int32)res);
+ writeScummVar(109, (int32)var10);
+ writeScummVar(110, (int32)var8);
+
+ return 1;
+}
+
+int LogicHEfootball::op_1023(int32 *args) {
+ double var10, var18, var20, var28, var30, var30_;
+ double argf[7];
+
+ for (int i = 0; i < 7; i++)
+ argf[i] = args[i];
+
+ var10 = (argf[3] - argf[1]) / (argf[2] - argf[0]);
+ var28 = var10 * var10 + 1;
+ var20 = argf[0] * var10;
+ var18 = (argf[5] + argf[1] + var20) * argf[4] * var10 * 2 +
+ argf[6] * argf[6] * var28 + argf[4] * argf[4] -
+ argf[0] * argf[0] * var10 * var10 -
+ argf[5] * argf[0] * var10 * 2 -
+ argf[5] * argf[1] * 2 -
+ argf[1] * argf[1] - argf[5] * argf[5];
+
+ if (var18 >= 0) {
+ var18 = sqrt(var18);
+
+ var30_ = argf[4] + argf[5] * var10 + argf[1] * var10 + argf[0] * var10 * var10;
+ var30 = (var30_ - var18) / var28;
+ var18 = (var30_ + var18) / var28;
+
+ if ((argf[0] - var30 < 0) && (argf[0] - var18 < 0)) {
+ var30_ = var30;
+ var30 = var18;
+ var18 = var30_;
+ }
+ var28 = var18 * var10 - var20 - argf[1];
+ var20 = var30 * var10 - var20 - argf[1];
+ } else {
+ var18 = 0;
+ var20 = 0;
+ var28 = 0;
+ var30 = 0;
+ }
+
+ writeScummVar(108, (int32)var18);
+ writeScummVar(109, (int32)var28);
+ writeScummVar(110, (int32)var30);
+ writeScummVar(111, (int32)var20);
+
+ return 1;
+}
+
+int LogicHEfootball::op_1024(int32 *args) {
+ writeScummVar(108, 0);
+ writeScummVar(109, 0);
+ writeScummVar(110, 0);
+ writeScummVar(111, 0);
+
+ return 1;
+}
+
+LogicHE *makeLogicHEfootball(ScummEngine_v90he *vm) {
+ return new LogicHEfootball(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic/funshop.cpp b/engines/scumm/he/logic/funshop.cpp
new file mode 100644
index 0000000000..8993fedad2
--- /dev/null
+++ b/engines/scumm/he/logic/funshop.cpp
@@ -0,0 +1,216 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Freddi Fish's One-Stop Fun Shop
+ * Pajama Sam's One-Stop Fun Shop
+ * Putt-Putt's One-Stop Fun Shop
+ */
+class LogicHEfunshop : public LogicHE {
+public:
+ LogicHEfunshop(ScummEngine_v90he *vm) : LogicHE(vm) {}
+
+ int versionID();
+ int32 dispatch(int op, int numArgs, int32 *args);
+
+private:
+ void op_1004(int32 *args);
+ void op_1005(int32 *args);
+ int checkShape(int32 data0, int32 data1, int32 data4, int32 data5, int32 data2, int32 data3, int32 data6, int32 data7, int32 *x, int32 *y);
+};
+
+int LogicHEfunshop::versionID() {
+ return 1;
+}
+
+int32 LogicHEfunshop::dispatch(int op, int numArgs, int32 *args) {
+ switch (op) {
+ case 1004:
+ op_1004(args);
+ break;
+
+ case 1005:
+ op_1005(args);
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+void LogicHEfunshop::op_1004(int32 *args) {
+ double data[8], at, sq;
+ int32 x, y;
+ int i=0;
+
+ for (i = 0; i <= 6; i += 2) {
+ data[i] = getFromArray(args[0], 0, 519 + i);
+ data[i + 1] = getFromArray(args[0], 0, 519 + i + 1);
+ }
+ int s = checkShape((int32)data[0], (int32)data[1], (int32)data[4], (int32)data[5],
+ (int32)data[2], (int32)data[3], (int32)data[6], (int32)data[7], &x, &y);
+
+ if (s != 1) {
+ error("LogicHEfunshop::op_1004: Your shape has defied the laws of physics");
+ return;
+ }
+
+ for (i = 0; i <= 6; i += 2) {
+ data[i] -= (double)x;
+ data[i + 1] -= (double)y;
+ }
+
+ double a1 = (double)args[1] * DEG2RAD;
+
+ for (i = 0; i <= 6; i += 2) {
+ at = atan2(data[i + 1], data[i]);
+ sq = sqrt(data[i + 1] * data[i + 1] + data[i] * data[i]);
+
+ if (at <= 0)
+ at += 2 * M_PI;
+
+ data[i] = cos(at + a1) * sq;
+ data[i + 1] = sin(at + a1) * sq;
+ }
+
+ double minx = data[0];
+ double miny = data[1];
+
+ for (i = 0; i <= 6; i += 2) {
+ if (data[i] < minx)
+ minx = data[i];
+ if (data[i + 1] < miny)
+ miny = data[i + 1];
+ }
+
+ for (i = 0; i <= 6; i += 2) {
+ data[i] -= minx;
+ data[i + 1] -= miny;
+
+ putInArray(args[0], 0, 519 + i, scummRound(data[i]));
+ putInArray(args[0], 0, 519 + i + 1, scummRound(data[i + 1]));
+ }
+}
+
+void LogicHEfunshop::op_1005(int32 *args) {
+ double data[8];
+ double args1, args2;
+ int i;
+ for (i = 520; i <= 526; i += 2) {
+ data[i - 520] = getFromArray(args[0], 0, i - 1);
+ data[i - 520 + 1] = getFromArray(args[0], 0, i);
+ }
+
+ args1 = (double)args[1] * 0.01 + 1;
+ args2 = (double)args[2] * 0.01 + 1;
+
+ for (i = 0; i < 4; i++) {
+ data[2 * i] *= args1;
+ data[2 * i + 1] *= args2;
+ }
+
+ for (i = 520; i <= 526; i += 2) {
+ putInArray(args[0], 0, i - 1, scummRound(data[i - 520]));
+ putInArray(args[0], 0, i, scummRound(data[i - 520 + 1]));
+ }
+}
+
+int LogicHEfunshop::checkShape(int32 data0, int32 data1, int32 data4, int32 data5, int32 data2, int32 data3, int32 data6, int32 data7, int32 *x, int32 *y) {
+ int32 diff5_1, diff0_4, diff7_3, diff2_6;
+ int32 diff1, diff2;
+ int32 delta, delta2;
+ int32 sum1, sum2;
+
+ diff0_4 = data0 - data4;
+ diff5_1 = data5 - data1;
+ diff1 = data1 * data4 - data0 * data5;
+ sum1 = diff0_4 * data3 + diff1 + diff5_1 * data2;
+ sum2 = diff0_4 * data7 + diff1 + diff5_1 * data6;
+
+ if (sum1 != 0 && sum2 != 0) {
+ sum2 ^= sum1;
+
+ if (sum2 >= 0)
+ return 0;
+ }
+
+ diff2_6 = data2 - data6;
+ diff7_3 = data7 - data3;
+ diff2 = data3 * data6 - data2 * data7;
+ sum1 = diff2_6 * data1 + diff2 + diff7_3 * data0;
+ sum2 = diff2_6 * data5 + diff2 + diff7_3 * data4;
+
+ if (sum1 != 0 && sum2 != 0) {
+ sum2 ^= sum1;
+
+ if (sum2 >= 0)
+ return 0;
+ }
+
+ delta = diff2_6 * diff5_1 - diff0_4 * diff7_3;
+
+ if (delta == 0) {
+ return 2;
+ }
+
+ if (delta < 0) {
+ data7 = -((delta + 1) >> 1);
+ } else {
+ data7 = delta >> 1;
+ }
+
+ delta2 = diff2 * diff0_4 - diff1 * diff2_6;
+
+ if (delta2 < 0) {
+ delta2 -= data7;
+ } else {
+ delta2 += data7;
+ }
+
+ *x = delta2 / delta;
+
+ delta2 = diff1 * diff7_3 - diff2 * diff5_1;
+
+ if (delta2 < 0) {
+ delta2 -= data7;
+ } else {
+ delta2 += data7;
+ }
+
+ *y = delta2 / delta;
+
+ return 1;
+}
+
+LogicHE *makeLogicHEfunshop(ScummEngine_v90he *vm) {
+ return new LogicHEfunshop(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic/moonbase.cpp b/engines/scumm/he/logic/moonbase.cpp
new file mode 100644
index 0000000000..fac2ea27ff
--- /dev/null
+++ b/engines/scumm/he/logic/moonbase.cpp
@@ -0,0 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Moonbase Commander
+ */
+class LogicHEmoonbase : public LogicHE {
+public:
+ LogicHEmoonbase(ScummEngine_v90he *vm) : LogicHE(vm) {}
+
+ int versionID();
+};
+
+int LogicHEmoonbase::versionID() {
+ if (_vm->_game.features & GF_DEMO)
+ return -100;
+ else
+ return 100;
+}
+
+LogicHE *makeLogicHEmoonbase(ScummEngine_v90he *vm) {
+ return new LogicHEmoonbase(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic/puttrace.cpp b/engines/scumm/he/logic/puttrace.cpp
new file mode 100644
index 0000000000..ea4397cd97
--- /dev/null
+++ b/engines/scumm/he/logic/puttrace.cpp
@@ -0,0 +1,376 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Putt-Putt Enters the Race
+ */
+class LogicHErace : public LogicHE {
+private:
+ float *_userData;
+ double *_userDataD;
+public:
+ LogicHErace(ScummEngine_v90he *vm);
+ ~LogicHErace();
+
+ int versionID();
+ int32 dispatch(int op, int numArgs, int32 *args);
+
+private:
+ int32 op_1003(int32 *args);
+ int32 op_1004(int32 *args);
+ int32 op_1100(int32 *args);
+ int32 op_1101(int32 *args);
+ int32 op_1102(int32 *args);
+ int32 op_1103(int32 *args);
+ int32 op_1110();
+ int32 op_1120(int32 *args);
+ int32 op_1130(int32 *args);
+ int32 op_1140(int32 *args);
+
+ void op_sub1(float arg);
+ void op_sub2(float arg);
+ void op_sub3(float arg);
+};
+
+LogicHErace::LogicHErace(ScummEngine_v90he *vm) : LogicHE(vm) {
+ // Originally it used 0x930 and stored both floats and doubles inside
+ _userData = (float *)calloc(550, sizeof(float));
+ _userDataD = (double *)calloc(30, sizeof(double));
+
+ // FIXME: of the 550 entries in _userData, only 516 till 532 are used
+ // FIXME: similarly, in _userDataD only 9 till 17 are used for computations
+ // (some of the other entries are also set, but never read, hence useless).
+}
+
+LogicHErace::~LogicHErace() {
+ free(_userData);
+ free(_userDataD);
+}
+
+int LogicHErace::versionID() {
+ return 1;
+}
+
+int32 LogicHErace::dispatch(int op, int numArgs, int32 *args) {
+ int32 res;
+
+ switch (op) {
+ case 1003:
+ res = op_1003(args);
+ break;
+
+ case 1004:
+ res = op_1004(args);
+ break;
+
+ case 1100:
+ res = op_1100(args);
+ break;
+
+ case 1101:
+ res = op_1101(args);
+ break;
+
+ case 1102:
+ res = op_1102(args);
+ break;
+
+ case 1103:
+ res = op_1103(args);
+ break;
+
+ case 1110:
+ res = op_1110();
+ break;
+
+ case 1120:
+ res = op_1120(args);
+ break;
+
+ case 1130:
+ res = op_1130(args);
+ break;
+
+ case 1140:
+ res = op_1140(args);
+ break;
+
+ default:
+ res = 0;
+ break;
+
+ }
+
+ return res;
+}
+
+#define RAD2DEG (180 / M_PI)
+#define DEG2RAD (M_PI / 180)
+
+int32 LogicHErace::op_1003(int32 *args) {
+ int value = args[2] ? args[2] : 1;
+
+ writeScummVar(108, (int32)(atan2((double)args[0], (double)args[1]) * RAD2DEG * value));
+
+ return 1;
+}
+
+int32 LogicHErace::op_1004(int32 *args) {
+ int value = args[1] ? args[1] : 1;
+
+ writeScummVar(108, (int32)(sqrt((float)args[0]) * value));
+
+ return 1;
+}
+
+int32 LogicHErace::op_1100(int32 *args) {
+ // _userData 516,517,518 describe a 3D translation?
+ _userData[516] = (float)args[0] / args[10];
+ _userData[517] = (float)args[1] / args[10];
+ _userData[518] = (float)args[2] / args[10];
+
+ // _userData 519,520,521 describe rotation angles around the x,y,z axes?
+ _userData[519] = (float)args[3] / args[10];
+ _userData[520] = (float)args[4] / args[10];
+ _userData[521] = (float)args[5] / args[10];
+
+ op_sub1(_userData[520]);
+ op_sub2(_userData[521]);
+
+ // _userData[532] seems to be some kind of global scale factor
+ _userData[532] = (float)args[10];
+
+ _userData[524] = (float)args[8]; // not used
+ _userData[525] = (float)args[9]; // not used
+ _userData[522] = (float)args[6] / args[10]; // not used
+ _userData[523] = (float)args[7] / args[10]; // only used to compute 528 and 529
+
+ // The following two are some kind of scale factors
+ _userData[526] = (float)args[6] / args[8] / args[10];
+ _userData[527] = (float)args[7] / args[9] / args[10];
+
+ // Set var 108 and 109 -- the value set here corresponds to the values
+ // set by op_1110!
+ writeScummVar(108, (int32)((float)args[6] / args[8] * args[10]));
+ writeScummVar(109, (int32)((float)args[7] / args[9] * args[10]));
+
+ _userData[528] = (float)(_userData[519] - _userData[523] * 0.5);
+ _userData[529] = (float)(_userData[519] + _userData[523] * 0.5);
+
+ writeScummVar(110, (int32)(_userData[528] * args[10]));
+ writeScummVar(111, (int32)(_userData[529] * args[10]));
+
+ // 530 and 531 are only used to set vars 112 and 113, so no need
+ // to store them permanently
+ _userData[530] = (float)(_userData[517] / tan(_userData[529] * DEG2RAD));
+ _userData[531] = (float)(_userData[517] / tan(_userData[528] * DEG2RAD));
+
+ writeScummVar(112, (int32)(_userData[530] * args[10]));
+ writeScummVar(113, (int32)(_userData[531] * args[10]));
+
+ return 1;
+}
+
+int32 LogicHErace::op_1101(int32 *args) {
+ // Update rotation params?
+ int32 retval;
+ float temp;
+
+ temp = args[0] / _userData[532];
+ if (_userData[519] != temp) {
+ _userData[519] = temp;
+ op_sub3(temp);
+ retval = 1;
+ } else {
+ retval = (int32)temp;
+ }
+
+ temp = args[1] / _userData[532];
+ if (_userData[520] != temp) {
+ _userData[520] = temp;
+ op_sub1(temp);
+ retval = 1;
+ }
+
+ temp = args[2] / _userData[532];
+ if (_userData[521] != temp) {
+ _userData[521] = temp;
+ op_sub2(temp);
+ retval = 1;
+ }
+
+ return retval;
+}
+
+int32 LogicHErace::op_1102(int32 *args) {
+ // Update translation params?
+ int32 retval;
+ float temp;
+
+ temp = args[0] / _userData[532];
+ if (_userData[516] != temp) {
+ _userData[516] = temp;
+ retval = 1;
+ } else {
+ retval = (int32)_userData[532];
+ }
+
+ temp = args[1] / _userData[532];
+ if (_userData[517] != temp) {
+ _userData[517] = temp;
+ retval = 1;
+ }
+
+ temp = args[2] / _userData[532];
+ if (_userData[518] != temp) {
+ _userData[518] = temp;
+ retval = 1;
+ }
+
+ return retval;
+}
+
+int32 LogicHErace::op_1103(int32 *args) {
+ double angle = args[0] / args[1] * DEG2RAD;
+
+ writeScummVar(108, (int32)(sin(angle) * args[2]));
+ writeScummVar(109, (int32)(cos(angle) * args[2]));
+
+ return 1;
+}
+
+int32 LogicHErace::op_1110() {
+ writeScummVar(108, (int32)(_userData[526] * _userData[532] * _userData[532]));
+ writeScummVar(109, (int32)(_userData[527] * _userData[532] * _userData[532]));
+ writeScummVar(110, (int32)(_userData[532]));
+
+ return 1;
+}
+
+int32 LogicHErace::op_1120(int32 *args) {
+ double a0, a1, a2;
+ double b0, b1, b2;
+ double res1, res2;
+
+ a0 = args[0] / _userData[532] - _userData[516];
+ a1 = args[1] / _userData[532] - _userData[517];
+ a2 = args[2] / _userData[532] - _userData[518];
+
+ // Perform matrix multiplication (multiplying by a rotation matrix)
+ b2 = a2 * _userDataD[17] + a1 * _userDataD[14] + a0 * _userDataD[11];
+ b1 = a2 * _userDataD[16] + a1 * _userDataD[13] + a0 * _userDataD[10];
+ b0 = a2 * _userDataD[15] + a1 * _userDataD[12] + a0 * _userDataD[9];
+
+ res1 = (atan2(b0, b2) * RAD2DEG) / _userData[526];
+ res2 = (atan2(b1, b2) * RAD2DEG - _userData[528]) / _userData[527];
+
+ writeScummVar(108, (int32)res1);
+ writeScummVar(109, (int32)res2);
+
+ return 1;
+}
+
+int32 LogicHErace::op_1130(int32 *args) {
+ double cs = cos(args[0] / _userData[532] * DEG2RAD);
+ double sn = sin(args[0] / _userData[532] * DEG2RAD);
+
+ writeScummVar(108, (int32)(cs * args[1] + sn * args[2]));
+ writeScummVar(109, (int32)(cs * args[2] - sn * args[1]));
+
+ return 1;
+}
+
+int32 LogicHErace::op_1140(int32 *args) {
+ // This functions seems to perform some kind of projection: We project
+ // the vector (arg2,arg3) onto the vector (arg0,arg1), but also apply
+ // some kind of distortion factor ?!?
+ double x = args[2], y = args[3];
+
+ // We start by normalizing the vector described by arg2 and arg3.
+ // So compute its length and divide the x and y coordinates
+ const double sq = sqrt(x*x + y*y);
+ x /= sq;
+ y /= sq;
+
+ // Compute the scalar product of the vectors (arg0,arg1) and (x,y)
+ const double scalarProduct = x * args[0] + y * args[1];
+
+ // Finally compute the projection of (arg2,arg3) onto (arg0,arg1)
+ double projX = args[0] - 2 * scalarProduct * x;
+ double projY = args[1] - 2 * scalarProduct * y;
+
+ projX = projX * 20.0 / 23.0; // FIXME: Why is this here?
+
+ writeScummVar(108, (int32)projX);
+
+ if (args[3] >= 0) // FIXME: Why is this here?
+ projY = projY * 5.0 / 6.0;
+
+ writeScummVar(109, (int32)projY);
+
+ return 1;
+}
+
+void LogicHErace::op_sub1(float arg) {
+ // Setup a rotation matrix
+ _userDataD[10] = _userDataD[12] = _userDataD[14] = _userDataD[16] = 0;
+ _userDataD[13] = 1;
+
+ _userDataD[9] = cos(arg * DEG2RAD);
+ _userDataD[15] = sin(arg * DEG2RAD);
+ _userDataD[11] = -_userDataD[15];
+ _userDataD[17] = _userDataD[9];
+}
+
+void LogicHErace::op_sub2(float arg) {
+ // Setup a rotation matrix -- but it is NEVER USED!
+ _userDataD[20] = _userDataD[21] = _userDataD[24] = _userDataD[25] = 0;
+ _userDataD[26] = 1;
+
+ _userDataD[19] = sin(arg * DEG2RAD);
+ _userDataD[18] = cos(arg * DEG2RAD);
+ _userDataD[21] = -_userDataD[19];
+ _userDataD[22] = _userDataD[18];
+}
+
+void LogicHErace::op_sub3(float arg) {
+ // Setup a rotation matrix -- but it is NEVER USED!
+ _userDataD[1] = _userDataD[2] = _userDataD[3] = _userDataD[6] = 0;
+ _userDataD[0] = 1;
+
+ _userDataD[4] = cos(arg * DEG2RAD);
+ _userDataD[5] = sin(arg * DEG2RAD);
+ _userDataD[7] = -_userDataD[5];
+ _userDataD[8] = _userDataD[4];
+}
+
+LogicHE *makeLogicHErace(ScummEngine_v90he *vm) {
+ return new LogicHErace(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic/soccer.cpp b/engines/scumm/he/logic/soccer.cpp
new file mode 100644
index 0000000000..05f377a736
--- /dev/null
+++ b/engines/scumm/he/logic/soccer.cpp
@@ -0,0 +1,1206 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "scumm/he/intern_he.h"
+#include "scumm/he/logic_he.h"
+
+namespace Scumm {
+
+/**
+ * Logic code for:
+ * Backyard Soccer
+ * Backyard Soccer MLS Edition
+ * Backyard Soccer 2004
+ */
+class LogicHEsoccer : public LogicHE {
+private:
+ double *_userDataD;
+
+public:
+ LogicHEsoccer(ScummEngine_v90he *vm);
+ ~LogicHEsoccer();
+
+ int versionID();
+ int32 dispatch(int op, int numArgs, int32 *args);
+
+ void beforeBootScript();
+ void initOnce();
+ int startOfFrame();
+
+private:
+ int op_1005(float x1, float y1, float z1, float x2, float y2, float z2, float *nextVelX, float *nextVelY, float *nextVelZ, float *a10);
+ int op_1006(int32 a1, int32 a2, int32 a3, int32 a4);
+ int op_1007(int32 *args);
+ int op_1008(int outArray, int srcX, int srcY, int srcZ, int vecX, int vecY, int vecZ, int airResX, int airResY, int airResZ, int vecNumerator, int vecDenom, int gravityMult, int requiredSegments, int a15, int a16, int a17, int a18, int fieldType);
+ int op_1011(int32 worldPosArray, int32 screenPosArray, int32 a3, int32 closestActorArray, int32 maxDistance, int32 fieldAreaArray);
+ int op_1012(int32 *args);
+ int op_1013(int32 a1, int32 a2, int32 a3);
+ int op_1014(int32 srcX, int32 srcY, int32 srcZ, int32 velX, int32 velY, int32 velZ, int32 outArray, int32 dataArrayId, int32 indexArrayId, int32 requestType, int32 vecNumerator, int32 vecDenom, int32 a13, int32 a14);
+ int op_1016(int32 *args);
+ int op_1017(int32 *args);
+ int op_1019(int32 *args);
+ int op_1021(int32 inX, int32 inY, int32 inZ, int32 velX, int32 velY, int32 velZ, int32 internalUse);
+
+ // op_1007 allocates some arrays
+ // they're then filled by op_1019
+ byte _collisionObjIds[4096], _collisionNodeEnabled[585];
+
+ // op_1011 has a subfunction
+ void calculateDistances(int32 worldPosArray, int32 a2, int32 closestActorArray, int32 maxDistance);
+
+ // array containing collision detection tree
+ bool _collisionTreeAllocated;
+ uint32 *_collisionTree;
+ int addCollisionTreeChild(int depth, int index, int parent);
+
+ // op_1014 has several subops
+ // ...and several sub-subops
+ int generateCollisionObjectList(float srcX, float srcY, float srcZ, float velX, float velY, float velZ);
+ int addFromCollisionTreeNode(int index, int parent, uint32 *indices, int objIndexBase);
+ void addCollisionObj(byte objId);
+ int findCollisionWith(int objId, float inX, float inY, float inZ, float inXVec, float inYVec, float inZVec, float &collideX, float &collideY, float &collideZ, int indexArrayId, int dataArrayId, float *nextVelX, float *nextVelY, float *nextVelZ, float *a15);
+ void getPointsForFace(int faceId, float &x1, float &y1, float &z1, float &x2, float &y2, float &z2, float &x3, float &y3, float &z3, float &x4, float &y4, float &z4, const int *objPoints);
+ void crossProduct(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, float &outX, float &outY, float &outZ);
+ double dotProduct(float a1, float a2, float a3, float a4, float a5, float a6);
+ void sortCollisionList(float *data, int numEntries, int entrySize, int compareOn);
+ int setCollisionOutputData(float *collisionData, int entrySize, int dataArrayId, int indexArrayId, int startX, int startY, int startZ, float a8, int a9, int a10, int a11, int *out);
+
+ // op_1014 sets an array optionally based upon
+ // setCollisionOutputData; it is then used by op_1008
+ int _internalCollisionOutData[10];
+ Common::List<byte> _collisionObjs;
+
+ // op_1021 can (optionally) set two variables for use in op_1008
+ uint32 _var1021[2];
+};
+
+int LogicHEsoccer::versionID() {
+ return 1;
+}
+
+LogicHEsoccer::LogicHEsoccer(ScummEngine_v90he *vm) : LogicHE(vm) {
+ _userDataD = (double *)calloc(1732, sizeof(double));
+ _collisionTree = 0;
+ _collisionTreeAllocated = false;
+}
+
+LogicHEsoccer::~LogicHEsoccer() {
+ free(_userDataD);
+ delete[] _collisionTree;
+}
+
+int32 LogicHEsoccer::dispatch(int op, int numArgs, int32 *args) {
+ int res = 0;
+
+ switch (op) {
+ case 1006:
+ res = op_1006(args[0], args[1], args[2], args[3]);
+ break;
+
+ case 1007:
+ res = op_1007(args);
+ break;
+
+ case 1008:
+ res = op_1008(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18]);
+ break;
+
+ case 1011:
+ res = op_1011(args[0], args[1], args[2], args[3], args[4], args[5]);
+ break;
+
+ case 1012:
+ res = op_1012(args);
+ break;
+
+ case 1013:
+ res = op_1013(args[0], args[1], args[2]);
+ break;
+
+ case 1014:
+ res = op_1014(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13]);
+ break;
+
+ case 1016:
+ res = op_1016(args);
+ break;
+
+ case 1017:
+ res = op_1017(args);
+ break;
+
+ case 1019:
+ res = op_1019(args);
+ break;
+
+ case 1021:
+ res = op_1021(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
+ break;
+
+ case 1001: case 1002: case 1003: case 1005:
+ case 1009: case 8221968:
+ // In the u32, but unused by any of the soccer scripts
+ // 1005 is called from another opcode, however
+ error("Unused soccer u32 opcode %d called", op);
+
+ case 1004: case 1010: case 1015: case 1018:
+ case 1020:
+ // Used only by the unaccessible in-game editor (so, fall through)
+
+ default:
+ LogicHE::dispatch(op, numArgs, args);
+ }
+
+ return res;
+}
+
+void LogicHEsoccer::beforeBootScript() {
+ _userDataD[530] = 0;
+}
+
+void LogicHEsoccer::initOnce() {
+ // The original sets some paths here that we don't need to worry about
+ _collisionTreeAllocated = false;
+ _userDataD[530] = 0;
+}
+
+int LogicHEsoccer::startOfFrame() {
+ // This variable is some sort of flag that activates this mode
+ int res = (int)_userDataD[530];
+
+ if (res)
+ res = op_1011((int)_userDataD[531], (int)_userDataD[532], (int)_userDataD[533], (int)_userDataD[534], (int)_userDataD[535], (int)_userDataD[536]);
+
+ return res;
+}
+
+int LogicHEsoccer::op_1005(float x1, float y1, float z1, float x2, float y2, float z2, float *nextVelX, float *nextVelY, float *nextVelZ, float *a10) {
+ // Called from op_1014
+
+ double dot = x1 * x2 + y1 * y2 + z1 * z2;
+ *nextVelX = x2 - 2 * dot * x1;
+ *nextVelY = y2 - 2 * dot * y1;
+ *nextVelZ = z2 - 2 * dot * z1;
+ *a10 = 1.0f; // It always does this. How curious!
+
+ return 1;
+}
+
+int LogicHEsoccer::op_1006(int32 a1, int32 a2, int32 a3, int32 a4) {
+ double v1 = a1 * 0.01;
+ double v2 = a2 * 0.01;
+ double v3 = a3 * 0.01;
+ double var108, var109;
+
+ _userDataD[529] = a4;
+
+ var108 = atan2(v1, v3) * _userDataD[523] - a4;
+ var109 = _userDataD[526] - _userDataD[528] - (_userDataD[521] - atan2(_userDataD[524] - v2, v3)) * _userDataD[522];
+
+ writeScummVar(108, (int32)var108);
+ writeScummVar(109, (int32)var109);
+
+ return 1;
+}
+
+int LogicHEsoccer::op_1007(int32 *args) {
+ // Used when the HE logo is shown
+ // This initializes the _userDataD fields that are used in op_1006/op_1011
+
+ float y1 = (double)args[0] / 100.0;
+ float x1 = (double)args[1] / 100.0;
+ float x2 = (double)args[2] / 100.0;
+ float y2 = (double)args[3] / 100.0;
+ float x3 = (double)args[4] / 100.0;
+
+ _userDataD[518] = x2;
+ _userDataD[519] = 2 * atan2(y2, x2 - x3);
+ _userDataD[520] = atan2(y1, x2);
+ _userDataD[521] = atan2(y1, x1);
+ _userDataD[524] = y1;
+ _userDataD[525] = 2 * (_userDataD[521] - _userDataD[520]);
+ _userDataD[526] = args[6];
+ _userDataD[527] = args[5];
+ _userDataD[528] = args[7];
+ _userDataD[522] = _userDataD[526] / _userDataD[525];
+ _userDataD[523] = _userDataD[527] / _userDataD[519];
+
+ // Clear both byte arrays
+ memset(_collisionObjIds, 0, 4096);
+ memset(_collisionNodeEnabled, 0, 585);
+
+ if (!_collisionTreeAllocated)
+ op_1013(4, args[8], args[9]);
+
+ return 1;
+}
+
+static inline double vectorLength(double x, double y, double z) {
+ return sqrt(x * x + y * y + z * z);
+}
+
+int LogicHEsoccer::op_1008(int outArray, int srcX, int srcY, int srcZ, int vecX, int vecY, int vecZ, int airResX, int airResY, int airResZ, int vecNumerator, int vecDenom, int gravityMult, int requiredSegments, int a15, int a16, int a17, int a18, int fieldType) {
+ // Calculate requiredSegments consecutive movement segments, and place
+ // the associated data (positions, vectors, etc) into outArray.
+
+ int loopsSoFar = 0;
+ int segmentsSoFar = 1;
+ int prevVecY = 500;
+ int inX = srcX;
+ int inZ = srcZ;
+ int checkForCollisions = 0;
+
+ while (segmentsSoFar <= requiredSegments) {
+ if (fieldType == 1 && srcZ > 8819)
+ checkForCollisions = 1;
+ else if (fieldType == 2 && (srcX < -2350 || srcX > 2350))
+ checkForCollisions = 1;
+ else if (fieldType == 3 && (srcX < -2350 || srcX > 2350 || srcZ < 6119 || srcZ > 8819))
+ checkForCollisions = 1;
+
+ if (srcY > 0)
+ vecY -= vecNumerator * gravityMult / vecDenom;
+
+ int prevX = srcX;
+ int prevY = srcY;
+ int prevZ = srcZ;
+ srcX += vecNumerator * vecX / vecDenom;
+ srcY += vecNumerator * vecY / vecDenom;
+ srcZ += vecNumerator * vecZ / vecDenom;
+
+ if (srcY > 0) {
+ if (checkForCollisions && op_1014(prevX, prevY, prevZ, vecX, vecY, vecZ, 0, a17, a18, 3, vecNumerator, vecDenom, a15, a16)) {
+ srcX = _internalCollisionOutData[6];
+ srcY = _internalCollisionOutData[7];
+ srcZ = _internalCollisionOutData[8];
+ vecX = _internalCollisionOutData[3];
+ vecY = _internalCollisionOutData[4];
+ vecZ = _internalCollisionOutData[5];
+ putInArray(outArray, segmentsSoFar, 0, loopsSoFar);
+ putInArray(outArray, segmentsSoFar, 1, (int)vectorLength((double)(_internalCollisionOutData[6] - inX), 0.0, (double)(_internalCollisionOutData[8] - inZ)));
+ putInArray(outArray, segmentsSoFar, 2, _internalCollisionOutData[6]);
+ putInArray(outArray, segmentsSoFar, 3, _internalCollisionOutData[7]);
+ putInArray(outArray, segmentsSoFar, 4, _internalCollisionOutData[8]);
+ putInArray(outArray, segmentsSoFar, 5, vecX);
+ putInArray(outArray, segmentsSoFar, 6, vecY);
+ putInArray(outArray, segmentsSoFar++, 7, vecZ);
+ }
+ } else {
+ srcY = 0;
+ int thisVecX = vecX;
+ int thisVecZ = vecZ;
+ vecX = vecX * airResX / 100;
+
+ if (vecY) {
+ int v18 = ABS(vecY);
+ if (v18 > ABS(prevVecY))
+ vecY = ABS(prevVecY);
+ vecY = ABS(airResY * vecY) / 100;
+ }
+
+ vecZ = airResZ * vecZ / 100;
+
+ if (prevVecY >= 0) {
+ if (op_1014(prevX, prevY, prevZ, thisVecX, prevVecY, thisVecZ, 0, a17, a18, 3, vecNumerator, vecDenom, a15, a16)) {
+ srcX = _internalCollisionOutData[6];
+ srcY = _internalCollisionOutData[7];
+ srcZ = _internalCollisionOutData[8];
+ vecX = _internalCollisionOutData[3];
+ vecY = _internalCollisionOutData[4];
+ vecZ = _internalCollisionOutData[5];
+ }
+ } else {
+ if (checkForCollisions) {
+ op_1021(srcX, 0, srcZ, thisVecX, prevVecY, thisVecZ, 1);
+
+ if (op_1014(prevX, prevY, prevZ, thisVecX, prevVecY, thisVecZ, 0, a17, a18, 3, vecNumerator, vecDenom, a15, a16)) {
+ srcX = _internalCollisionOutData[6];
+ srcY = _internalCollisionOutData[7];
+ srcZ = _internalCollisionOutData[8];
+ vecX = _internalCollisionOutData[3];
+ vecY = _internalCollisionOutData[4];
+ vecZ = _internalCollisionOutData[5];
+ } else {
+ // try it with the output of op_1021 instead
+ int tmpVecZ = vecZ + prevZ - _var1021[1];
+ int v20 = ABS(prevVecY);
+
+ if (op_1014(_var1021[0], 0, _var1021[1], vecX + prevX - _var1021[0], v20 - prevY, tmpVecZ, 0, a17, a18, 3, vecNumerator, vecDenom, a15, a16)) {
+ srcX = _internalCollisionOutData[6];
+ srcY = _internalCollisionOutData[7];
+ srcZ = _internalCollisionOutData[8];
+ vecX = _internalCollisionOutData[3];
+ vecY = _internalCollisionOutData[4];
+ vecZ = _internalCollisionOutData[5];
+ }
+ }
+ }
+ }
+
+ prevVecY = vecY;
+ putInArray(outArray, segmentsSoFar, 0, loopsSoFar);
+ putInArray(outArray, segmentsSoFar, 1, (int32)vectorLength(srcX - inX, 0.0, srcZ - inZ));
+ putInArray(outArray, segmentsSoFar, 2, srcX);
+ putInArray(outArray, segmentsSoFar, 3, srcY);
+ putInArray(outArray, segmentsSoFar, 4, srcZ);
+ putInArray(outArray, segmentsSoFar, 5, vecX);
+ putInArray(outArray, segmentsSoFar, 6, vecY);
+ putInArray(outArray, segmentsSoFar++, 7, vecZ);
+ }
+
+ loopsSoFar++;
+ }
+
+ return 1;
+}
+
+int LogicHEsoccer::op_1011(int32 worldPosArray, int32 screenPosArray, int32 a3, int32 closestActorArray, int32 maxDistance, int32 fieldAreaArray) {
+ // This is called on each frame by startOfFrame() if activated by op_1012.
+
+ float objY = 0.0;
+
+ // First, iterate over the field objects and project them onto the screen.
+ for (int i = 0; i < 18; i++) {
+ int rawX = getFromArray(worldPosArray, i, 0);
+ int rawY = getFromArray(worldPosArray, i, 1);
+ int rawZ = getFromArray(worldPosArray, i, 2);
+
+ float objX = (double)rawX / 100.0;
+ objY = (double)rawY / 100.0;
+ float objZ = (double)rawZ / 100.0;
+
+ if (i < 13) {
+ // For the players and the ball: work out the area of the field
+ // this object is in, storing it in an array if provided.
+ int areaX = (rawX + 2750) / 500;
+ areaX = CLIP(areaX, 0, 10);
+
+ int areaZ = (9219 - rawZ) / 500;
+ areaZ = CLIP(areaZ, 0, 6);
+
+ if (fieldAreaArray)
+ putInArray(fieldAreaArray, 0, i, areaX + 11 * areaZ);
+ }
+
+ float v7 = atan2(_userDataD[524] - objY, (double)objZ);
+ int screenY = (int)(_userDataD[526] - (_userDataD[521] - v7) * _userDataD[522] - 300.0);
+ double v9 = _userDataD[523];
+
+ // x/y position of objects
+ putInArray(screenPosArray, i, 0, (int32)(atan2(objX, objZ) * v9 + 640.0));
+ putInArray(screenPosArray, i, 1, screenY);
+
+ double v10 = atan2(_userDataD[524], (double)objZ);
+ int shadowScreenY = (int)(_userDataD[526] - (_userDataD[521] - (float)v10) * _userDataD[522] - 300.0);
+ double v13 = _userDataD[523];
+
+ // x/y position of shadows
+ putInArray(screenPosArray, i + ((_vm->_game.id == GID_SOCCER) ? 20 : 22), 0, (int32)(atan2(objX, objZ) * v13 + 640.0));
+ putInArray(screenPosArray, i + ((_vm->_game.id == GID_SOCCER) ? 20 : 22), 1, shadowScreenY);
+ }
+
+ // soccer only uses one array here
+ // soccermls/soccer2004 use four
+ int start = (_vm->_game.id == GID_SOCCER) ? 19 : 18;
+ int end = (_vm->_game.id == GID_SOCCER) ? 19 : 21;
+
+ // The following loop is doing cursor scaling
+ // The further up on the screen, the smaller the cursor is
+ for (int i = start; i <= end; i++) {
+ int x = getFromArray(screenPosArray, i, 0);
+ int y = getFromArray(screenPosArray, i, 1);
+
+ // This retains objY from (i == 17)?
+ float v16 = _userDataD[524] - objY;
+ float scaledZ = v16 / tan((_userDataD[528] + y - _userDataD[526]) / _userDataD[522] + _userDataD[521]);
+ double scaledX = tan((double)(x - ((_vm->_game.id == GID_SOCCER) ? 0 : 640)) / _userDataD[523]) * scaledZ;
+ putInArray(worldPosArray, i, 0, (int)(scaledX * 100.0));
+ putInArray(worldPosArray, i, 2, (int)(scaledZ * 100.0));
+ }
+
+ calculateDistances(worldPosArray, a3, closestActorArray, maxDistance);
+
+ return 1;
+}
+
+static inline int distance(int a1, int a2, int a3, int a4) {
+ return (int)sqrt((double)((a4 - a3) * (a4 - a3) + (a2 - a1) * (a2 - a1)));
+}
+
+void LogicHEsoccer::calculateDistances(int32 worldPosArray, int32 a2, int32 closestActorArray, int32 maxDistance) {
+ // As you can guess, this is called from op_1011
+ // This seems to be checking distances between the players and the ball
+ // and which distance is the shortest.
+
+ int closestActor[13];
+ int objectX[13];
+ int objectZ[13];
+ int closestDistance[195];
+
+ for (int i = 0; i < 13; i++) {
+ closestActor[i] = 0;
+ objectX[i] = getFromArray(worldPosArray, i, 0);
+ objectZ[i] = getFromArray(worldPosArray, i, 2);
+ }
+
+ // 12 here, 13 up there
+ // Probably 12 for players, 13 for players+ball
+ for (int i = 0; i < 12; i++) {
+ int bestDistance = maxDistance;
+ for (int j = i + 1; j < 13; j++) {
+ closestDistance[i * 15 + j] = distance(objectX[i], objectX[j], objectZ[i], objectZ[j]);
+ putInArray(a2, i, j, closestDistance[i * 15 + j]);
+ putInArray(a2, j, i, closestDistance[i * 15 + j]);
+ if (closestDistance[i * 15 + j] < bestDistance) {
+ bestDistance = closestDistance[i * 15 + j];
+ closestActor[i] = j + 1;
+ closestActor[j] = i + 1;
+ }
+ }
+ }
+
+ int v13 = getFromArray(worldPosArray, 18, 0);
+ int v14 = getFromArray(worldPosArray, 18, 2);
+ int v15 = getFromArray(worldPosArray, 19, 0);
+ int v16 = getFromArray(worldPosArray, 19, 2);
+ int v19[15];
+ int v20[15];
+
+ if (_vm->_game.id == GID_SOCCER) {
+ // soccer gets to be different
+ for (int i = 0; i < 13; i++)
+ v20[i] = distance(v15, objectX[i], v16, objectZ[i]);
+
+ for (int i = 0; i < 13; i++)
+ v19[i] = distance(v13, objectX[i], v14, objectZ[i]);
+ } else {
+ // soccermls and soccer2004 use two other arrays here
+ int v9 = getFromArray(worldPosArray, 20, 0);
+ int v10 = getFromArray(worldPosArray, 20, 2);
+ int v11 = getFromArray(worldPosArray, 21, 0);
+ int v12 = getFromArray(worldPosArray, 21, 2);
+
+ for (int i = 0; i < 6; i++) {
+ v20[i] = distance(v9, objectX[i], v10, objectZ[i]);
+ v19[i] = distance(v13, objectX[i], v14, objectZ[i]);
+ }
+
+ for (int i = 6; i < 13; i++) {
+ v20[i] = distance(v11, objectX[i], v12, objectZ[i]);
+ v19[i] = distance(v15, objectX[i], v16, objectZ[i]);
+ }
+ }
+
+ for (int i = 0; i < 13; i++) {
+ putInArray(a2, 14, i, v20[i]);
+ putInArray(a2, i, 14, v20[i]);
+ putInArray(a2, 13, i, v19[i]);
+ putInArray(a2, i, 13, v19[i]);
+ putInArray(closestActorArray, 0, i, closestActor[i]);
+ }
+}
+
+int LogicHEsoccer::op_1012(int32 *args) {
+ // Used after op_1019
+ // This function activates startOfFrame() to call op_1011
+ // (Possibly field parameters?)
+
+ _userDataD[530] = (args[0] != 0) ? 1 : 0;
+ _userDataD[531] = args[1];
+ _userDataD[532] = args[2];
+ _userDataD[533] = args[3];
+ _userDataD[534] = args[4];
+ _userDataD[535] = args[5];
+ _userDataD[536] = args[6];
+
+ return 1;
+}
+
+int LogicHEsoccer::addCollisionTreeChild(int depth, int index, int parent) {
+ uint32 *dataPtr = _collisionTree + 11 * index;
+
+ /*
+ * This sets up a node of the tree stored in _collisionTree. There are
+ * two sets of parents (at depth 1 and 2), then child nodes at depth
+ * 3 which represent a single collision object.
+ *
+ * 0 = this index, 1 = parent index,
+ * 2-9 = child indices (or all -1 if leaf),
+ * 10 = _collisionObjIds index (if leaf)
+ */
+ dataPtr[0] = index;
+ dataPtr[1] = parent;
+
+ if (depth > 2) {
+ // store the offset into _collisionObjIds (which holds collision object ids),
+ // but subtract 585 first because there are already (8 + 8*8 + 8*8*8 = 584)
+ // indexes at higher levels of the tree, and we want to start at 0
+ dataPtr[10] = 8 * index - 585;
+ for (int i = 0; i < 8; i++)
+ dataPtr[i + 2] = 0xffffffff;
+ } else {
+ for (int i = 0; i < 8; i++)
+ dataPtr[i + 2] = addCollisionTreeChild(depth + 1, i + 8 * index + 1, index);
+ }
+
+ return index;
+}
+
+int LogicHEsoccer::op_1013(int32 a1, int32 a2, int32 a3) {
+ // Initialises _collisionTree, a tree used for collision detection.
+ // It is used by op_1014 to work out which objects to check.
+
+ _collisionTree = new uint32[585 * 11];
+ _collisionTreeAllocated = true;
+ for (int i = 0; i < 585 * 11; i++)
+ _collisionTree[i] = 0;
+
+ for (int i = 0; i < 8; i++)
+ _collisionTree[i + 2] = addCollisionTreeChild(1, i + 1, 0);
+
+ return 1;
+}
+
+int LogicHEsoccer::op_1014(int32 srcX, int32 srcY, int32 srcZ, int32 velX, int32 velY, int32 velZ, int32 outArray, int32 dataArrayId, int32 indexArrayId, int32 requestType, int32 vecNumerator, int32 vecDenom, int32 a13, int32 a14) {
+ // Used many times during a match
+ // And called from op_1008!
+ // This seems to be doing collision handling
+
+ double startX = (double)srcX;
+ double startY = (double)srcY;
+ double startZ = (double)srcZ;
+ double adjustedVelZ = 0.0, adjustedVelY = 0.0, adjustedVelX = 0.0;
+
+ writeScummVar(108, 0);
+ writeScummVar(109, 0);
+
+ switch (requestType) {
+ case 1:
+ case 3:
+ adjustedVelX = (double)velX * (double)vecNumerator / (double)vecDenom / 100.0;
+ adjustedVelY = (double)velY * (double)vecNumerator / (double)vecDenom / 100.0;
+ adjustedVelZ = (double)velZ * (double)vecNumerator / (double)vecDenom / 100.0;
+ break;
+ case 2:
+ // length of movement vector
+ double v15 = vectorLength((double)velX * (double)vecNumerator / (double)vecDenom, (double)velY * (double)vecNumerator / (double)vecDenom, (double)velZ * (double)vecNumerator / (double)vecDenom);
+
+ if (v15 != 0.0) {
+ // add the (scaled) movement vector to the input
+ double v26 = (double)ABS(velX) * (double)vecNumerator / (double)vecDenom * 50.0 / v15;
+ srcX = (int)((double)srcX + v26);
+ double v25 = (double)ABS(velY) * (double)vecNumerator / (double)vecDenom * 50.0 / v15;
+ srcY = (int)((double)srcY + v25);
+ double v24 = (double)ABS(velZ) * (double)vecNumerator / (double)vecDenom * 50.0 / v15;
+ srcZ = (int)((double)srcZ + v24);
+ }
+
+ // srcX = (newX / newZ) * 3869
+ startX = (double)srcX / (double)srcZ * 3869.0;
+ // srcY = (newY - (+524 * 100)) / (newZ * 3869 + (+524 * 100)
+ startY = ((double)srcY - _userDataD[524] * 100.0) / (double)srcZ * 3869.0 + _userDataD[524] * 100.0;
+ // srcZ = 3869
+ startZ = 3869.0;
+ // vectorX = (newX - srcX) / 100
+ adjustedVelX = ((double)srcX - startX) / 100.0;
+ // vectorY = (newY - srcY) / 100
+ adjustedVelY = ((double)srcY - startY) / 100.0;
+ // vectorZ = (newZ - 3869 = srcZ) / 100
+ adjustedVelZ = ((double)srcZ - 3869.0) / 100.0;
+ break;
+ }
+
+ int foundCollision = 0;
+
+ // work out which collision objects we might collide with (if any)
+ if (generateCollisionObjectList(startX, startY, startZ, adjustedVelX, adjustedVelY, adjustedVelZ)) {
+ int collisionId = 0;
+ float v46; // always 1.0 after a collision due to op_1005
+
+ float collisionInfo[42 * 8];
+ memset(collisionInfo, 0, 42 * 8 * sizeof(float));
+
+ // check each potential collision object for an actual collision,
+ // add it to collisionInfo if there is one
+ for (Common::List<byte>::const_iterator it = _collisionObjs.begin(); it != _collisionObjs.end(); it++) {
+ float collideZ, collideY, collideX;
+ float nextVelX, nextVelY, nextVelZ;
+
+ if (findCollisionWith(*it, startX, startY, startZ, adjustedVelX * 100.0, adjustedVelY * 100.0, adjustedVelZ * 100.0, collideX, collideY, collideZ, indexArrayId, dataArrayId, &nextVelX, &nextVelY, &nextVelZ, &v46)) {
+ collisionInfo[collisionId * 8] = *it;
+ collisionInfo[collisionId * 8 + 1] = vectorLength(collideX - startX, collideY - startY, collideZ - startZ);
+ collisionInfo[collisionId * 8 + 2] = collideX;
+ collisionInfo[collisionId * 8 + 3] = collideY;
+ collisionInfo[collisionId * 8 + 4] = collideZ;
+ collisionInfo[collisionId * 8 + 5] = vecDenom * nextVelX / vecNumerator;
+ collisionInfo[collisionId * 8 + 6] = vecDenom * nextVelY / vecNumerator;
+ collisionInfo[collisionId * 8 + 7] = vecDenom * nextVelZ / vecNumerator;
+ foundCollision = 1;
+ collisionId++;
+ }
+ }
+
+ if (foundCollision) {
+ // if we have more than one collision, sort them by distance
+ // to find the closest one
+ if (collisionId != 1)
+ sortCollisionList(collisionInfo, 42, 8, 1);
+
+ int v22, v39, v42;
+ float tmpData[8];
+ int outData[10];
+
+ // output the collision we found
+ switch (requestType) {
+ case 1:
+ for (int i = 0; i < 8; i++)
+ tmpData[i] = collisionInfo[i];
+ v22 = getFromArray(indexArrayId, 0, (int)((tmpData[0] - 1.0) * 4.0));
+ v42 = getFromArray(indexArrayId, 0, (int)((tmpData[0] - 1.0) * 4.0 + 1.0));
+ v39 = getFromArray(indexArrayId, 0, (int)((tmpData[0] - 1.0) * 4.0 + 2.0));
+ setCollisionOutputData(tmpData, 8, dataArrayId, indexArrayId, (int)startX, (int)startY, (int)startZ, v46, v22, v42, v39, outData);
+ for (int i = 0; i < 10; i++)
+ putInArray(outArray, 0, i, outData[i]);
+ break;
+ case 2:
+ // write the object id if collision happened (note that other case can't happen)
+ if (collisionId)
+ writeScummVar(109, (int)collisionInfo[(collisionId - 1) * 8]);
+ else
+ writeScummVar(109, 0);
+ break;
+ case 3:
+ for (int i = 0; i < 8; i++)
+ tmpData[i] = collisionInfo[i];
+ v22 = getFromArray(indexArrayId, 0, (int)((tmpData[0] - 1.0) * 4.0));
+ v42 = getFromArray(indexArrayId, 0, (int)((tmpData[0] - 1.0) * 4.0 + 1.0));
+ v39 = getFromArray(indexArrayId, 0, (int)((tmpData[0] - 1.0) * 4.0 + 2.0));
+ setCollisionOutputData(tmpData, 8, dataArrayId, indexArrayId, (int)startX, (int)startY, (int)startZ, v46, v22, v42, v39, outData);
+ for (int i = 0; i < 10; i++)
+ _internalCollisionOutData[i] = outData[i];
+ break;
+ }
+ }
+ }
+
+ writeScummVar(108, foundCollision);
+
+ _collisionObjs.clear();
+
+ return foundCollision;
+}
+
+int LogicHEsoccer::generateCollisionObjectList(float srcX, float srcY, float srcZ, float velX, float velY, float velZ) {
+ float v36 = srcX / 100.0;
+ float v37 = v36 + 52.0;
+ float destX = v37 + velX;
+
+ int v33, v29;
+
+ if (((int)destX / 52) ^ ((int)v37 / 52)) {
+ v33 = 1;
+ v29 = 1;
+ } else if ((int)v37 / 52) {
+ v29 = 0;
+ v33 = 1;
+ } else {
+ v33 = 0;
+ v29 = 1;
+ }
+
+ uint32 areaEnabled[8];
+ for (int i = 0; i < 4; i++) {
+ areaEnabled[i] = v29;
+ areaEnabled[i + 4] = v33;
+ }
+
+ float v38 = srcY / 100.0;
+ float destY = v38 + velY;
+
+ if (((int)destY / 20) ^ ((int)v38 / 20)) {
+ v33 = 1;
+ v29 = 1;
+ } else if ((int)v38 / 20) {
+ v33 = 1;
+ v29 = 0;
+ } else {
+ v29 = 1;
+ v33 = 0;
+ }
+
+ for (int i = 0; i < 2; i++) {
+ if (areaEnabled[i * 4 + 0])
+ areaEnabled[i * 4 + 0] = v29;
+ if (areaEnabled[i * 4 + 1])
+ areaEnabled[i * 4 + 1] = v29;
+ if (areaEnabled[i * 4 + 2])
+ areaEnabled[i * 4 + 2] = v33;
+ if (areaEnabled[i * 4 + 3])
+ areaEnabled[i * 4 + 3] = v33;
+ }
+
+ float v39 = srcZ / 100.0;
+ float v40 = v39 - 38.69;
+ float destZ = v40 + velZ;
+
+ if (((int)destZ / 36) ^ ((int)v40 / 36)) {
+ v33 = 1;
+ v29 = 1;
+ } else if ((int)v40 / 36) {
+ v29 = 0;
+ v33 = 1;
+ } else {
+ v33 = 0;
+ v29 = 1;
+ }
+
+ for (int i = 0; i <= 6; i += 2) {
+ if (areaEnabled[i])
+ areaEnabled[i] = v29;
+ if (areaEnabled[i + 1])
+ areaEnabled[i + 1] = v33;
+ }
+
+ int objCount = 0;
+
+ for (int i = 0; i < 8; i++) {
+ if (areaEnabled[i]) {
+ uint32 *ptr = _collisionTree + _collisionTree[i + 2] * 11;
+ objCount += addFromCollisionTreeNode(ptr[0], ptr[1], &ptr[2], ptr[10]);
+ }
+ }
+
+ writeScummVar(109, objCount);
+ return objCount;
+}
+
+int LogicHEsoccer::addFromCollisionTreeNode(int index, int parent, uint32 *indices, int objIndexBase) {
+ int objCount = 0;
+
+ if (indices[0] == 0xffffffff) {
+ for (int i = 0; i < 8; i++) {
+ if (_collisionObjIds[i + objIndexBase]) {
+ addCollisionObj(_collisionObjIds[i + objIndexBase]);
+ objCount = 1;
+ }
+ }
+ } else {
+ if (_collisionNodeEnabled[index]) {
+ for (int i = 0; i < 8; i++) {
+ uint32 *ptr = _collisionTree + indices[i] * 11;
+ objCount += addFromCollisionTreeNode(ptr[0], ptr[1], &ptr[2], ptr[10]);
+ }
+ }
+ }
+
+ return objCount;
+}
+
+void LogicHEsoccer::addCollisionObj(byte objId) {
+ // Add objId to the list if not found
+ for (Common::List<byte>::const_iterator it = _collisionObjs.begin(); it != _collisionObjs.end(); it++)
+ if (*it == objId)
+ return;
+
+ _collisionObjs.push_back(objId);
+}
+
+int LogicHEsoccer::findCollisionWith(int objId, float inX, float inY, float inZ, float inXVec, float inYVec, float inZVec, float &collideX, float &collideY, float &collideZ, int indexArrayId, int dataArrayId, float *nextVelX, float *nextVelY, float *nextVelZ, float *a15) {
+ int foundCollision = 0;
+ float inY_plus1 = inY + 1.0;
+ float destX = inX + inXVec;
+ float destY = inY_plus1 + inYVec;
+ float destZ = inZ + inZVec;
+
+ // don't go below the ground!
+ if (inY_plus1 <= 1.0001 && destY < 0.0) {
+ destY = 0.0;
+ inYVec = ABS((int)inYVec);
+ }
+
+ // get the 8 points which define the 6 faces of this object
+ int objIndex = getFromArray(indexArrayId, 0, 4 * objId - 1);
+ int objPoints[24];
+ for (int i = 0; i < 24; i++)
+ objPoints[i] = getFromArray(dataArrayId, 0, objIndex + i);
+
+ for (int faceId = 0; faceId < 6; faceId++) {
+ // This assigns variables from objPoints based on faceId
+ float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;
+ float faceCrossX, faceCrossY, faceCrossZ;
+ getPointsForFace(faceId, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, objPoints);
+ crossProduct(x1, y1, z1, x2, y2, z2, x1, y1, z1, x3, y3, z3, faceCrossX, faceCrossY, faceCrossZ);
+
+ float faceArea = sqrt(faceCrossX * faceCrossX + faceCrossY * faceCrossY + faceCrossZ * faceCrossZ);
+
+ // The original did not initialize these variables and would
+ // use them uninitialized if faceArea == 0.0
+ float xMult = 0.0, yMult = 0.0, zMult = 0.0;
+
+ if (faceArea != 0.0) {
+ // UnitCross = Cross/||Cross||
+ xMult = faceCrossX / faceArea;
+ yMult = faceCrossY / faceArea;
+ zMult = faceCrossZ / faceArea;
+ }
+ double scalingMult = 5.0;
+
+ float ZToFacePoint1 = z1 - inZ;
+ float YToFacePoint1 = y1 - inY_plus1;
+ float XToFacePoint1 = x1 - inX;
+ // scalar component of UnitCross in direction of (start -> P1)
+ double ToFacePoint1 = dotProduct(xMult, yMult, zMult, XToFacePoint1, YToFacePoint1, ZToFacePoint1);
+
+ float ZToDest = destZ - inZ;
+ float YToDest = destY - inY_plus1;
+ float XToDest = destX - inX;
+ // scalar component of UnitCross in direction of (start -> dest)
+ double ToDest = dotProduct(xMult, yMult, zMult, XToDest, YToDest, ZToDest);
+
+ if (fabs(ToDest) > 0.00000001)
+ scalingMult = ToFacePoint1 / ToDest;
+
+ if (scalingMult >= 0.0 && fabs(scalingMult) <= 1.0 && ToDest != 0.0) {
+ // calculate where the collision would be, in the plane containing this face
+ double collisionX = inX + (destX - inX) * scalingMult;
+ double collisionY = inY_plus1 + (destY - inY_plus1) * scalingMult + 5.0;
+ double collisionZ = inZ + (destZ - inZ) * scalingMult;
+
+ // now we need to work out whether this point is actually inside the face
+ double dot1 = dotProduct(x2 - x1, y2 - y1, z2 - z1, x3 - x1, y3 - y1, z3 - z1);
+ double sqrt1 = vectorLength(x2 - x1, y2 - y1, z2 - z1);
+ double num1 = dot1 / (vectorLength(x3 - x1, y3 - y1, z3 - z1) * sqrt1);
+ num1 = CLIP<double>(num1, -1.0, 1.0);
+ double faceAngle = acos(num1);
+
+ double dot2 = dotProduct(x2 - x1, y2 - y1, z2 - z1, collisionX - x1, collisionY - y1, collisionZ - z1);
+ double sqrt2 = vectorLength(x2 - x1, y2 - y1, z2 - z1);
+ double num2 = dot2 / (vectorLength(collisionX - x1, collisionY - y1, collisionZ - z1) * sqrt2);
+ num2 = CLIP<double>(num2, -1.0, 1.0);
+ double angle1 = acos(num2);
+
+ double dot3 = dotProduct(x3 - x1, y3 - y1, z3 - z1, collisionX - x1, collisionY - y1, collisionZ - z1);
+ double sqrt3 = vectorLength(x3 - x1, y3 - y1, z3 - z1);
+ double num3 = dot3 / (vectorLength(collisionX - x1, collisionY - y1, collisionZ - z1) * sqrt3);
+ num3 = CLIP<double>(num3, -1.0, 1.0);
+ double angle2 = acos(num3);
+
+ if (angle1 + angle2 - 0.001 <= faceAngle) {
+ double dot4 = dotProduct(x2 - x4, y2 - y4, z2 - z4, x3 - x4, y3 - y4, z3 - z4);
+ double sqrt4 = vectorLength(x2 - x4, y2 - y4, z2 - z4);
+ double num4 = dot4 / (vectorLength(x3 - x4, y3 - y4, z3 - z4) * sqrt4);
+ num4 = CLIP<double>(num4, -1.0, 1.0);
+ faceAngle = acos(num4);
+
+ double dot5 = dotProduct(x2 - x4, y2 - y4, z2 - z4, collisionX - x4, collisionY - y4, collisionZ - z4);
+ double sqrt5 = vectorLength(x2 - x4, y2 - y4, z2 - z4);
+ double num5 = dot5 / (vectorLength(collisionX - x4, collisionY - y4, collisionZ - z4) * sqrt5);
+ num5 = CLIP<double>(num5, -1.0, 1.0);
+ double angle3 = acos(num5);
+
+ double dot6 = dotProduct(x3 - x4, y3 - y4, z3 - z4, collisionX - x4, collisionY - y4, collisionZ - z4);
+ double sqrt6 = vectorLength(x3 - x4, y3 - y4, z3 - z4);
+ double num6 = dot6 / (vectorLength(collisionX - x4, collisionY - y4, collisionZ - z4) * sqrt6);
+ num6 = CLIP<double>(num6, -1.0, 1.0);
+ double angle4 = acos(num6);
+
+ if (angle3 + angle4 - 0.001 <= faceAngle) {
+ // found a collision with this face
+ if (foundCollision) {
+ // if we already found one, is the new one closer?
+ // (except this don't adjust for the modification of collideX/Y/Z..)
+ double ToCollide = vectorLength(inX - collisionX, inY_plus1 - collisionY, inZ - collisionZ);
+ if (vectorLength(inX - collideX, inY_plus1 - collideY, inZ - collideZ) > ToCollide) {
+ collideX = collisionX - xMult * 3.0;
+ collideY = collisionY - yMult * 3.0;
+ collideZ = collisionZ - zMult * 3.0;
+ op_1005(xMult, yMult, zMult, inXVec, inYVec, inZVec, nextVelX, nextVelY, nextVelZ, a15);
+ }
+ } else {
+ collideX = collisionX - xMult * 3.0;
+ collideY = collisionY - yMult * 3.0;
+ collideZ = collisionZ - zMult * 3.0;
+ op_1005(xMult, yMult, zMult, inXVec, inYVec, inZVec, nextVelX, nextVelY, nextVelZ, a15);
+ }
+
+ foundCollision = 1;
+ }
+ }
+ }
+ }
+
+ return foundCollision;
+}
+
+void LogicHEsoccer::getPointsForFace(int faceId, float &x1, float &y1, float &z1, float &x2, float &y2, float &z2, float &x3, float &y3, float &z3, float &x4, float &y4, float &z4, const int *objPoints) {
+ // Note that this originally returned a value, but said value was never used
+ // TODO: This can probably be shortened using a few tables...
+
+ switch (faceId) {
+ case 0:
+ x1 = objPoints[0];
+ y1 = objPoints[1];
+ z1 = objPoints[2];
+ x2 = objPoints[3];
+ y2 = objPoints[4];
+ z2 = objPoints[5];
+ x3 = objPoints[6];
+ y3 = objPoints[7];
+ z3 = objPoints[8];
+ x4 = objPoints[9];
+ y4 = objPoints[10];
+ z4 = objPoints[11];
+ break;
+ case 1:
+ x1 = objPoints[0];
+ y1 = objPoints[1];
+ z1 = objPoints[2];
+ x2 = objPoints[6];
+ y2 = objPoints[7];
+ z2 = objPoints[8];
+ x3 = objPoints[12];
+ y3 = objPoints[13];
+ z3 = objPoints[14];
+ x4 = objPoints[18];
+ y4 = objPoints[19];
+ z4 = objPoints[20];
+ break;
+ case 2:
+ x1 = objPoints[3];
+ y1 = objPoints[4];
+ z1 = objPoints[5];
+ x2 = objPoints[15];
+ y2 = objPoints[16];
+ z2 = objPoints[17];
+ x3 = objPoints[9];
+ y3 = objPoints[10];
+ z3 = objPoints[11];
+ x4 = objPoints[21];
+ y4 = objPoints[22];
+ z4 = objPoints[23];
+ break;
+ case 3:
+ x1 = objPoints[0];
+ y1 = objPoints[1];
+ z1 = objPoints[2];
+ x2 = objPoints[12];
+ y2 = objPoints[13];
+ z2 = objPoints[14];
+ x3 = objPoints[3];
+ y3 = objPoints[4];
+ z3 = objPoints[5];
+ x4 = objPoints[15];
+ y4 = objPoints[16];
+ z4 = objPoints[17];
+ break;
+ case 4:
+ x1 = objPoints[6];
+ y1 = objPoints[7];
+ z1 = objPoints[8];
+ x2 = objPoints[9];
+ y2 = objPoints[10];
+ z2 = objPoints[11];
+ x3 = objPoints[18];
+ y3 = objPoints[19];
+ z3 = objPoints[20];
+ x4 = objPoints[21];
+ y4 = objPoints[22];
+ z4 = objPoints[23];
+ break;
+ case 5:
+ x1 = objPoints[15];
+ y1 = objPoints[16];
+ z1 = objPoints[17];
+ x2 = objPoints[12];
+ y2 = objPoints[13];
+ z2 = objPoints[14];
+ x3 = objPoints[21];
+ y3 = objPoints[22];
+ z3 = objPoints[23];
+ x4 = objPoints[18];
+ y4 = objPoints[19];
+ z4 = objPoints[20];
+ break;
+ }
+}
+
+void LogicHEsoccer::crossProduct(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, float &outX, float &outY, float &outZ) {
+ outX = (y2 - y1) * (z4 - z3) - (y4 - y3) * (z2 - z1);
+ outY = ((x2 - x1) * (z4 - z3) - (x4 - x3) * (z2 - z1)) * -1.0;
+ outZ = (x2 - x1) * (y4 - y3) - (x4 - x3) * (y2 - y1);
+}
+
+double LogicHEsoccer::dotProduct(float a1, float a2, float a3, float a4, float a5, float a6) {
+ return a1 * a4 + a2 * a5 + a3 * a6;
+}
+
+void LogicHEsoccer::sortCollisionList(float *data, int numEntries, int entrySize, int compareOn) {
+ // This takes an input array of collisions, and tries to sort it based on the distance
+ // (index of compareOn, always 1), copying in groups of entrySize, which is always 8
+
+ bool found = true;
+ int entry = 0;
+
+ while (found) {
+ found = false;
+
+ // while we still have entries, and there is an obj id set for the next entry
+ while (entry <= numEntries - 2 && data[(entry + 1) * 8] != 0.0) {
+ // if the current entry has distance 0, or the next entry is closer (distance is less)
+ if (data[compareOn + entry * 8] == 0 || data[compareOn + entry * 8] > data[compareOn + (entry + 1) * 8]) {
+ found = true;
+
+ // swap all data with the next entry
+ for (int i = 0; i < entrySize; i++) {
+ float tmp = data[i + entry * 8];
+ data[i + entry * 8] = data[i + (entry + 1) * 8];
+ data[i + (entry + 1) * 8] = tmp;
+ }
+ }
+
+ entry++;
+ }
+ }
+}
+
+int LogicHEsoccer::setCollisionOutputData(float *collisionData, int entrySize, int dataArrayId, int indexArrayId, int startX, int startY, int startZ, float a8, int a9, int a10, int a11, int *out) {
+ // area-provided data
+ out[0] = a9;
+ out[1] = a10;
+ out[2] = a11;
+ // new velocity, slowed by area-provided value
+ out[3] = (int)(collisionData[5] * (double)a10 / 100.0);
+ out[4] = (int)(collisionData[6] * (double)a10 / 100.0 * a8); // Note: a8 should always be 1
+ out[5] = (int)(collisionData[7] * (double)a10 / 100.0);
+ // new position
+ out[6] = (int)collisionData[2];
+ out[7] = (int)collisionData[3];
+ out[8] = (int)collisionData[4];
+ // collision object id
+ out[9] = (int)collisionData[0];
+ return out[9];
+}
+
+int LogicHEsoccer::op_1016(int32 *args) {
+ // Called when a goal is scored
+
+ int result = 0;
+
+ double v9 = (double)args[1] / 100.0;
+ double v13 = (double)args[2] / 100.0;
+ double v12 = (double)args[3] / 100.0;
+ double v18 = v13 * v13;
+ double v10 = (double)args[0] / 100.0 * (double)args[0] / 100.0;
+ double v11 = v9 * v9;
+ double v19 = (v9 * v9 * v12 * v12 + 2.0 * v9 * v12 * v18 + v18 * v18) * v10 * v10 - (v10 + v11) * v12 * v12 * v10 * v10;
+
+ if (v19 >= 0.0) {
+ double v6 = sqrt(v19);
+ double v17 = ((v9 * v12 + v18) * v10 + v6) / (v10 + v11 + v10 + v11);
+ double v16 = ((v9 * v12 + v18) * v10 - v6) / (v10 + v11 + v10 + v11);
+ double v7, v14;
+
+ if (v17 <= 0.0 || (v7 = sqrt(v17), v14 = acos(v7 / v13), v14 > 0.7853981633974475)) {
+ double v8, v15;
+ if (v16 <= 0.0 || (v8 = sqrt(v16), v15 = acos(v8 / v13), v15 > 0.7853981633974475)) {
+ writeScummVar(108, -1);
+ } else {
+ writeScummVar(108, (int)(v15 / 0.01745329251994328 * 100.0));
+ result = 1;
+ }
+ } else {
+ writeScummVar(108, (int)(v14 / 0.01745329251994328 * 100.0));
+ result = 1;
+ }
+ } else {
+ writeScummVar(108, -1);
+ }
+
+ return result;
+}
+
+int LogicHEsoccer::op_1017(int32 *args) {
+ // Used sporadically during a match (out of bounds?)
+ if (!args[1])
+ args[1] = 1;
+
+ double v3 = asin((double)args[0] / (double)args[1]);
+ writeScummVar(108, (int32)(v3 / 0.01745329251994328 * (double)args[1]));
+
+ return 1;
+}
+
+int LogicHEsoccer::op_1019(int32 *args) {
+ // Used at the beginning of a match
+ // Initializes some arrays with field collision data
+
+ // _collisionObjIds provides object ids for leaf nodes
+ // of the collision tree (_collisionTree).
+ for (int i = 0; i < 4096; i++)
+ _collisionObjIds[i] = getFromArray(args[1], 0, i);
+
+ // _collisionNodeEnabled enables or disables non-leaf nodes
+ // of the collision tree (_collisionTree).
+ for (int i = 0; i < 585; i++)
+ _collisionNodeEnabled[i] = getFromArray(args[0], 0, i);
+
+ // The remaining code of this function was used for the
+ // built-in editor. However, it is incomplete in the
+ // final product, so we do not need to have it.
+
+ return 1;
+}
+
+int LogicHEsoccer::op_1021(int32 inX, int32 inY, int32 inZ, int32 velX, int32 velY, int32 velZ, int32 internalUse) {
+ // Used during a match (ball movement?)
+ // Also called from op_1008
+
+ int outX;
+ if (velX && velY)
+ outX = (int)(((double)inY - (double)velY * (double)inX / (double)velX) * -1.0 * (double)velX / (double)velY);
+ else
+ outX = inX;
+
+ int outZ;
+ if (velZ && velY)
+ outZ = (int)(((double)inY - (double)velY * (double)inZ / (double)velZ) * -1.0 * (double)velZ / (double)velY);
+ else
+ outZ = inZ;
+
+ // The final argument chooses whether to store the results for op_1008 or
+ // store them in SCUMM variables.
+ if (internalUse) {
+ _var1021[0] = outX;
+ _var1021[1] = outZ;
+ } else {
+ writeScummVar(108, outX);
+ writeScummVar(109, outZ);
+ }
+
+ return 1;
+}
+
+LogicHE *makeLogicHEsoccer(ScummEngine_v90he *vm) {
+ return new LogicHEsoccer(vm);
+}
+
+} // End of namespace Scumm
diff --git a/engines/scumm/he/logic_he.cpp b/engines/scumm/he/logic_he.cpp
index af56bca2ee..a76c393e13 100644
--- a/engines/scumm/he/logic_he.cpp
+++ b/engines/scumm/he/logic_he.cpp
@@ -33,29 +33,10 @@ LogicHE::LogicHE(ScummEngine_v90he *vm) : _vm(vm) {
LogicHE::~LogicHE() {
}
-LogicHErace::LogicHErace(ScummEngine_v90he *vm) : LogicHE(vm) {
- // Originally it used 0x930 and stored both floats and doubles inside
- _userData = (float *)calloc(550, sizeof(float));
- _userDataD = (double *)calloc(30, sizeof(double));
-
- // FIXME: of the 550 entries in _userData, only 516 till 532 are used
- // FIXME: similarly, in _userDataD only 9 till 17 are used for computations
- // (some of the other entries are also set, but never read, hence useless).
-}
-
-LogicHErace::~LogicHErace() {
- free(_userData);
- free(_userDataD);
-}
-
void LogicHE::writeScummVar(int var, int32 value) {
_vm->writeVar(var, value);
}
-static int32 scumm_round(double arg) {
- return (int32)(arg + 0.5);
-}
-
int LogicHE::versionID() {
return 1;
}
@@ -95,1370 +76,34 @@ int32 LogicHE::dispatch(int op, int numArgs, int32 *args) {
return 1;
}
-/***********************
- * Putt-Putt Joins the Race
- *
- */
-
-int LogicHErace::versionID() {
- return 1;
-}
-
-int32 LogicHErace::dispatch(int op, int numArgs, int32 *args) {
- int32 res;
-
- switch (op) {
- case 1003:
- res = op_1003(args);
- break;
-
- case 1004:
- res = op_1004(args);
- break;
-
- case 1100:
- res = op_1100(args);
- break;
-
- case 1101:
- res = op_1101(args);
- break;
-
- case 1102:
- res = op_1102(args);
- break;
-
- case 1103:
- res = op_1103(args);
- break;
-
- case 1110:
- res = op_1110();
- break;
-
- case 1120:
- res = op_1120(args);
- break;
-
- case 1130:
- res = op_1130(args);
- break;
-
- case 1140:
- res = op_1140(args);
- break;
-
- default:
- res = 0;
- break;
-
- }
-
- return res;
-}
-
-#define RAD2DEG (180 / M_PI)
-#define DEG2RAD (M_PI / 180)
-
-int32 LogicHErace::op_1003(int32 *args) {
- int value = args[2] ? args[2] : 1;
-
- writeScummVar(108, (int32)(atan2((double)args[0], (double)args[1]) * RAD2DEG * value));
-
- return 1;
-}
-
-int32 LogicHErace::op_1004(int32 *args) {
- int value = args[1] ? args[1] : 1;
-
- writeScummVar(108, (int32)(sqrt((float)args[0]) * value));
-
- return 1;
-}
-
-int32 LogicHErace::op_1100(int32 *args) {
- // _userData 516,517,518 describe a 3D translation?
- _userData[516] = (float)args[0] / args[10];
- _userData[517] = (float)args[1] / args[10];
- _userData[518] = (float)args[2] / args[10];
-
- // _userData 519,520,521 describe rotation angles around the x,y,z axes?
- _userData[519] = (float)args[3] / args[10];
- _userData[520] = (float)args[4] / args[10];
- _userData[521] = (float)args[5] / args[10];
-
- op_sub1(_userData[520]);
- op_sub2(_userData[521]);
-
- // _userData[532] seems to be some kind of global scale factor
- _userData[532] = (float)args[10];
-
- _userData[524] = (float)args[8]; // not used
- _userData[525] = (float)args[9]; // not used
- _userData[522] = (float)args[6] / args[10]; // not used
- _userData[523] = (float)args[7] / args[10]; // only used to compute 528 and 529
-
- // The following two are some kind of scale factors
- _userData[526] = (float)args[6] / args[8] / args[10];
- _userData[527] = (float)args[7] / args[9] / args[10];
-
- // Set var 108 and 109 -- the value set here corresponds to the values
- // set by op_1110!
- writeScummVar(108, (int32)((float)args[6] / args[8] * args[10]));
- writeScummVar(109, (int32)((float)args[7] / args[9] * args[10]));
-
- _userData[528] = (float)(_userData[519] - _userData[523] * 0.5);
- _userData[529] = (float)(_userData[519] + _userData[523] * 0.5);
-
- writeScummVar(110, (int32)(_userData[528] * args[10]));
- writeScummVar(111, (int32)(_userData[529] * args[10]));
-
- // 530 and 531 are only used to set vars 112 and 113, so no need
- // to store them permanently
- _userData[530] = (float)(_userData[517] / tan(_userData[529] * DEG2RAD));
- _userData[531] = (float)(_userData[517] / tan(_userData[528] * DEG2RAD));
-
- writeScummVar(112, (int32)(_userData[530] * args[10]));
- writeScummVar(113, (int32)(_userData[531] * args[10]));
-
- return 1;
-}
-
-int32 LogicHErace::op_1101(int32 *args) {
- // Update rotation params?
- int32 retval;
- float temp;
-
- temp = args[0] / _userData[532];
- if (_userData[519] != temp) {
- _userData[519] = temp;
- op_sub3(temp);
- retval = 1;
- } else {
- retval = (int32)temp;
- }
-
- temp = args[1] / _userData[532];
- if (_userData[520] != temp) {
- _userData[520] = temp;
- op_sub1(temp);
- retval = 1;
- }
-
- temp = args[2] / _userData[532];
- if (_userData[521] != temp) {
- _userData[521] = temp;
- op_sub2(temp);
- retval = 1;
- }
-
- return retval;
-}
-
-int32 LogicHErace::op_1102(int32 *args) {
- // Update translation params?
- int32 retval;
- float temp;
-
- temp = args[0] / _userData[532];
- if (_userData[516] != temp) {
- _userData[516] = temp;
- retval = 1;
- } else {
- retval = (int32)_userData[532];
- }
-
- temp = args[1] / _userData[532];
- if (_userData[517] != temp) {
- _userData[517] = temp;
- retval = 1;
- }
-
- temp = args[2] / _userData[532];
- if (_userData[518] != temp) {
- _userData[518] = temp;
- retval = 1;
- }
-
- return retval;
-}
-
-int32 LogicHErace::op_1103(int32 *args) {
- double angle = args[0] / args[1] * DEG2RAD;
-
- writeScummVar(108, (int32)(sin(angle) * args[2]));
- writeScummVar(109, (int32)(cos(angle) * args[2]));
-
- return 1;
-}
-
-int32 LogicHErace::op_1110() {
- writeScummVar(108, (int32)(_userData[526] * _userData[532] * _userData[532]));
- writeScummVar(109, (int32)(_userData[527] * _userData[532] * _userData[532]));
- writeScummVar(110, (int32)(_userData[532]));
-
- return 1;
-}
-
-int32 LogicHErace::op_1120(int32 *args) {
- double a0, a1, a2;
- double b0, b1, b2;
- double res1, res2;
-
- a0 = args[0] / _userData[532] - _userData[516];
- a1 = args[1] / _userData[532] - _userData[517];
- a2 = args[2] / _userData[532] - _userData[518];
-
- // Perform matrix multiplication (multiplying by a rotation matrix)
- b2 = a2 * _userDataD[17] + a1 * _userDataD[14] + a0 * _userDataD[11];
- b1 = a2 * _userDataD[16] + a1 * _userDataD[13] + a0 * _userDataD[10];
- b0 = a2 * _userDataD[15] + a1 * _userDataD[12] + a0 * _userDataD[9];
-
- res1 = (atan2(b0, b2) * RAD2DEG) / _userData[526];
- res2 = (atan2(b1, b2) * RAD2DEG - _userData[528]) / _userData[527];
-
- writeScummVar(108, (int32)res1);
- writeScummVar(109, (int32)res2);
-
- return 1;
-}
-
-int32 LogicHErace::op_1130(int32 *args) {
- double cs = cos(args[0] / _userData[532] * DEG2RAD);
- double sn = sin(args[0] / _userData[532] * DEG2RAD);
-
- writeScummVar(108, (int32)(cs * args[1] + sn * args[2]));
- writeScummVar(109, (int32)(cs * args[2] - sn * args[1]));
-
- return 1;
-}
-
-int32 LogicHErace::op_1140(int32 *args) {
- // This functions seems to perform some kind of projection: We project
- // the vector (arg2,arg3) onto the vector (arg0,arg1), but also apply
- // some kind of distortion factor ?!?
- double x = args[2], y = args[3];
-
- // We start by normalizing the vector described by arg2 and arg3.
- // So compute its length and divide the x and y coordinates
- const double sq = sqrt(x*x + y*y);
- x /= sq;
- y /= sq;
-
- // Compute the scalar product of the vectors (arg0,arg1) and (x,y)
- const double scalarProduct = x * args[0] + y * args[1];
-
- // Finally compute the projection of (arg2,arg3) onto (arg0,arg1)
- double projX = args[0] - 2 * scalarProduct * x;
- double projY = args[1] - 2 * scalarProduct * y;
-
- projX = projX * 20.0 / 23.0; // FIXME: Why is this here?
-
- writeScummVar(108, (int32)projX);
-
- if (args[3] >= 0) // FIXME: Why is this here?
- projY = projY * 5.0 / 6.0;
-
- writeScummVar(109, (int32)projY);
-
- return 1;
-}
-
-void LogicHErace::op_sub1(float arg) {
- // Setup a rotation matrix
- _userDataD[10] = _userDataD[12] = _userDataD[14] = _userDataD[16] = 0;
- _userDataD[13] = 1;
-
- _userDataD[9] = cos(arg * DEG2RAD);
- _userDataD[15] = sin(arg * DEG2RAD);
- _userDataD[11] = -_userDataD[15];
- _userDataD[17] = _userDataD[9];
-}
-
-void LogicHErace::op_sub2(float arg) {
- // Setup a rotation matrix -- but it is NEVER USED!
- _userDataD[20] = _userDataD[21] = _userDataD[24] = _userDataD[25] = 0;
- _userDataD[26] = 1;
-
- _userDataD[19] = sin(arg * DEG2RAD);
- _userDataD[18] = cos(arg * DEG2RAD);
- _userDataD[21] = -_userDataD[19];
- _userDataD[22] = _userDataD[18];
-}
-
-void LogicHErace::op_sub3(float arg) {
- // Setup a rotation matrix -- but it is NEVER USED!
- _userDataD[1] = _userDataD[2] = _userDataD[3] = _userDataD[6] = 0;
- _userDataD[0] = 1;
-
- _userDataD[4] = cos(arg * DEG2RAD);
- _userDataD[5] = sin(arg * DEG2RAD);
- _userDataD[7] = -_userDataD[5];
- _userDataD[8] = _userDataD[4];
-}
-
-/***********************
- * Freddi Fish's One-Stop Fun Shop
- * Pajama Sam's One-Stop Fun Shop
- * Putt-Putt's One-Stop Fun Shop
- *
- */
-
-int LogicHEfunshop::versionID() {
- return 1;
-}
-
-int32 LogicHEfunshop::dispatch(int op, int numArgs, int32 *args) {
- switch (op) {
- case 1004:
- op_1004(args);
- break;
-
- case 1005:
- op_1005(args);
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-void LogicHEfunshop::op_1004(int32 *args) {
- double data[8], at, sq;
- int32 x, y;
- int i=0;
-
- for (i = 0; i <= 6; i += 2) {
- data[i] = getFromArray(args[0], 0, 519 + i);
- data[i + 1] = getFromArray(args[0], 0, 519 + i + 1);
- }
- int s = checkShape((int32)data[0], (int32)data[1], (int32)data[4], (int32)data[5],
- (int32)data[2], (int32)data[3], (int32)data[6], (int32)data[7], &x, &y);
-
- if (s != 1) {
- error("LogicHEfunshop::op_1004: Your shape has defied the laws of physics");
- return;
- }
-
- for (i = 0; i <= 6; i += 2) {
- data[i] -= (double)x;
- data[i + 1] -= (double)y;
- }
-
- double a1 = (double)args[1] * DEG2RAD;
-
- for (i = 0; i <= 6; i += 2) {
- at = atan2(data[i + 1], data[i]);
- sq = sqrt(data[i + 1] * data[i + 1] + data[i] * data[i]);
-
- if (at <= 0)
- at += 2 * M_PI;
-
- data[i] = cos(at + a1) * sq;
- data[i + 1] = sin(at + a1) * sq;
- }
-
- double minx = data[0];
- double miny = data[1];
-
- for (i = 0; i <= 6; i += 2) {
- if (data[i] < minx)
- minx = data[i];
- if (data[i + 1] < miny)
- miny = data[i + 1];
- }
-
- for (i = 0; i <= 6; i += 2) {
- data[i] -= minx;
- data[i + 1] -= miny;
-
- putInArray(args[0], 0, 519 + i, scumm_round(data[i]));
- putInArray(args[0], 0, 519 + i + 1, scumm_round(data[i + 1]));
- }
-}
-
-void LogicHEfunshop::op_1005(int32 *args) {
- double data[8];
- double args1, args2;
- int i;
- for (i = 520; i <= 526; i += 2) {
- data[i - 520] = getFromArray(args[0], 0, i - 1);
- data[i - 520 + 1] = getFromArray(args[0], 0, i);
- }
-
- args1 = (double)args[1] * 0.01 + 1;
- args2 = (double)args[2] * 0.01 + 1;
-
- for (i = 0; i < 4; i++) {
- data[2 * i] *= args1;
- data[2 * i + 1] *= args2;
- }
-
- for (i = 520; i <= 526; i += 2) {
- putInArray(args[0], 0, i - 1, scumm_round(data[i - 520]));
- putInArray(args[0], 0, i, scumm_round(data[i - 520 + 1]));
- }
-}
-
-int LogicHEfunshop::checkShape(int32 data0, int32 data1, int32 data4, int32 data5, int32 data2, int32 data3, int32 data6, int32 data7, int32 *x, int32 *y) {
- int32 diff5_1, diff0_4, diff7_3, diff2_6;
- int32 diff1, diff2;
- int32 delta, delta2;
- int32 sum1, sum2;
-
- diff0_4 = data0 - data4;
- diff5_1 = data5 - data1;
- diff1 = data1 * data4 - data0 * data5;
- sum1 = diff0_4 * data3 + diff1 + diff5_1 * data2;
- sum2 = diff0_4 * data7 + diff1 + diff5_1 * data6;
-
- if (sum1 != 0 && sum2 != 0) {
- sum2 ^= sum1;
-
- if (sum2 >= 0)
- return 0;
- }
-
- diff2_6 = data2 - data6;
- diff7_3 = data7 - data3;
- diff2 = data3 * data6 - data2 * data7;
- sum1 = diff2_6 * data1 + diff2 + diff7_3 * data0;
- sum2 = diff2_6 * data5 + diff2 + diff7_3 * data4;
-
- if (sum1 != 0 && sum2 != 0) {
- sum2 ^= sum1;
-
- if (sum2 >= 0)
- return 0;
- }
-
- delta = diff2_6 * diff5_1 - diff0_4 * diff7_3;
-
- if (delta == 0) {
- return 2;
- }
-
- if (delta < 0) {
- data7 = -((delta + 1) >> 1);
- } else {
- data7 = delta >> 1;
- }
-
- delta2 = diff2 * diff0_4 - diff1 * diff2_6;
-
- if (delta2 < 0) {
- delta2 -= data7;
- } else {
- delta2 += data7;
- }
-
- *x = delta2 / delta;
-
- delta2 = diff1 * diff7_3 - diff2 * diff5_1;
-
- if (delta2 < 0) {
- delta2 -= data7;
- } else {
- delta2 += data7;
- }
-
- *y = delta2 / delta;
-
- return 1;
-}
-
-/***********************
- * Backyard Football
- * Backyard Football 2002
- * Backyard Football Demo
- *
- */
-
-int LogicHEfootball::versionID() {
- return 1;
-}
-
-int32 LogicHEfootball::dispatch(int op, int numArgs, int32 *args) {
- int res = 0;
-
- switch (op) {
- case 1004:
- res = op_1004(args);
- break;
-
- case 1006:
- res = op_1006(args);
- break;
-
- case 1007:
- res = op_1007(args);
- break;
-
- case 1010:
- res = op_1010(args);
- break;
-
- case 1022:
- res = op_1022(args);
- break;
-
- case 1023:
- res = op_1023(args);
- break;
-
- case 1024:
- res = op_1024(args);
- break;
-
- case 8221968:
- // Someone had a fun and used his birthday as opcode number
- res = getFromArray(args[0], args[1], args[2]);
- break;
-
- case 1492: case 1493: case 1494: case 1495: case 1496:
- case 1497: case 1498: case 1499: case 1500: case 1501:
- case 1502: case 1503: case 1504: case 1505: case 1506:
- case 1507: case 1508: case 1509: case 1510: case 1511:
- case 1512: case 1513: case 1514: case 1555:
- // DirectPlay-related
- // 1513: initialize
- // 1555: set fake lag
- break;
-
- case 2200: case 2201: case 2202: case 2203: case 2204:
- case 2205: case 2206: case 2207: case 2208: case 2209:
- case 2210: case 2211: case 2212: case 2213: case 2214:
- case 2215: case 2216: case 2217: case 2218: case 2219:
- case 2220: case 2221: case 2222: case 2223: case 2224:
- case 2225: case 2226: case 2227: case 2228:
- // Boneyards-related
- break;
-
- case 3000: case 3001: case 3002: case 3003: case 3004:
- // Internet-related
- // 3000: check for updates
- // 3001: check network status
- // 3002: autoupdate
- // 3003: close connection
- break;
-
- default:
- LogicHE::dispatch(op, numArgs, args);
- warning("Tell sev how to reproduce it (%d)", op);
- }
-
- return res;
-}
-
-int LogicHEfootball::op_1004(int32 *args) {
- // Identical to LogicHEsoccer::op_1004
- double res, a2, a4, a5;
-
- a5 = ((double)args[4] - (double)args[1]) / ((double)args[5] - (double)args[2]);
- a4 = ((double)args[3] - (double)args[0]) / ((double)args[5] - (double)args[2]);
- a2 = (double)args[2] - (double)args[0] * a4 - args[1] * a5;
-
- res = (double)args[6] * a4 + (double)args[7] * a5 + a2;
- writeScummVar(108, (int32)res);
-
- writeScummVar(109, (int32)a2);
- writeScummVar(110, (int32)a5);
- writeScummVar(111, (int32)a4);
-
- return 1;
-}
-
-int LogicHEfootball::op_1006(int32 *args) {
- // This seems to be more or less the inverse of op_1010
- const double a1 = args[1];
- double res;
-
- // 2.9411764e-4 = 1/3400
- // 5.3050399e-2 = 1/18.85 = 20/377
- // 1.1764706e-2 = 1/85 = 40/3400
- // 1.2360656e-1 = 377/3050
- res = (1.0 - a1 * 2.9411764e-4 * 5.3050399e-2) * 1.2360656e-1 * args[0] +
- a1 * 1.1764706e-2 + 46;
-
- // Shortened / optimized version of that formula:
- // res = (377.0 - a1 / 170.0) / 3050.0 * args[0] + a1 / 85.0 + 46;
-
- writeScummVar(108, (int32)res);
-
- // 1.2360656e-1 = 377/3050
- // 1.1588235e-1 = 197/1700 = 394/3400
- res = 640.0 - args[2] * 1.2360656e-1 - a1 * 1.1588235e-1 - 26;
-
- writeScummVar(109, (int32)res);
-
- return 1;
-}
-
-int LogicHEfootball::op_1007(int32 *args) {
- double res, temp;
-
- temp = (double)args[1] * 0.32;
-
- if (temp > 304.0)
- res = -args[2] * 0.142;
- else
- res = args[2] * 0.142;
-
- res += temp;
-
- writeScummVar(108, (int32)res);
-
- res = (1000.0 - args[2]) * 0.48;
-
- writeScummVar(109, (int32)res);
-
- return 1;
-}
-
-int LogicHEfootball::op_1010(int32 *args) {
- // This seems to be more or less the inverse of op_1006
- double a1 = (640.0 - (double)args[1] - 26.0) / 1.1588235e-1;
-
- // 2.9411764e-4 = 1/3400
- // 5.3050399e-2 = 1/18.85 = 20/377
- // 1.1764706e-2 = 1/85 = 40/3400
- // 1.2360656e-1 = 377/3050
- double a0 = ((double)args[0] - 46 - a1 * 1.1764706e-2) /
- ((1.0 - a1 * 2.9411764e-4 * 5.3050399e-2) * 1.2360656e-1);
-
- writeScummVar(108, (int32)a0);
- writeScummVar(109, (int32)a1);
-
- return 1;
-}
-
-int LogicHEfootball::op_1022(int32 *args) {
- double res;
- double var10 = args[4] - args[1];
- double var8 = args[5] - args[2];
- double var6 = args[3] - args[0];
-
- res = sqrt(var8 * var8 + var6 * var6 + var10 * var10);
-
- if (res >= (double)args[6]) {
- var8 = (double)args[6] * var8 / res;
- var10 = (double)args[6] * var10 / res;
- res = (double)args[6] * var6 / res;
- }
-
- writeScummVar(108, (int32)res);
- writeScummVar(109, (int32)var10);
- writeScummVar(110, (int32)var8);
-
- return 1;
-}
-
-int LogicHEfootball::op_1023(int32 *args) {
- double var10, var18, var20, var28, var30, var30_;
- double argf[7];
-
- for (int i = 0; i < 7; i++)
- argf[i] = args[i];
-
- var10 = (argf[3] - argf[1]) / (argf[2] - argf[0]);
- var28 = var10 * var10 + 1;
- var20 = argf[0] * var10;
- var18 = (argf[5] + argf[1] + var20) * argf[4] * var10 * 2 +
- argf[6] * argf[6] * var28 + argf[4] * argf[4] -
- argf[0] * argf[0] * var10 * var10 -
- argf[5] * argf[0] * var10 * 2 -
- argf[5] * argf[1] * 2 -
- argf[1] * argf[1] - argf[5] * argf[5];
-
- if (var18 >= 0) {
- var18 = sqrt(var18);
-
- var30_ = argf[4] + argf[5] * var10 + argf[1] * var10 + argf[0] * var10 * var10;
- var30 = (var30_ - var18) / var28;
- var18 = (var30_ + var18) / var28;
-
- if ((argf[0] - var30 < 0) && (argf[0] - var18 < 0)) {
- var30_ = var30;
- var30 = var18;
- var18 = var30_;
- }
- var28 = var18 * var10 - var20 - argf[1];
- var20 = var30 * var10 - var20 - argf[1];
- } else {
- var18 = 0;
- var20 = 0;
- var28 = 0;
- var30 = 0;
- }
-
- writeScummVar(108, (int32)var18);
- writeScummVar(109, (int32)var28);
- writeScummVar(110, (int32)var30);
- writeScummVar(111, (int32)var20);
-
- return 1;
-}
-int LogicHEfootball::op_1024(int32 *args) {
- writeScummVar(108, 0);
- writeScummVar(109, 0);
- writeScummVar(110, 0);
- writeScummVar(111, 0);
-
- return 1;
-}
-
-
-/***********************
- * Backyard Soccer
- *
- */
-
-int LogicHEsoccer::versionID() {
- return 1;
-}
-
-LogicHEsoccer::LogicHEsoccer(ScummEngine_v90he *vm) : LogicHE(vm) {
- _userDataD = (double *)calloc(1732, sizeof(double));
- _intArray1 = 0;
- _intArray2 = 0;
- _intArraysAllocated = false;
- _array1013 = 0;
- _array1013Allocated = false;
-}
-
-LogicHEsoccer::~LogicHEsoccer() {
- free(_userDataD);
- op_1020(); // clear int arrays
- delete[] _array1013;
-}
-
-int32 LogicHEsoccer::dispatch(int op, int numArgs, int32 *args) {
- int res = 0;
-
- switch (op) {
- case 1001:
- res = op_1001(args);
- break;
-
- case 1002:
- res = op_1002(args);
- break;
-
- case 1004:
- res = op_1004(args);
- break;
-
- case 1006:
- res = op_1006(args[0], args[1], args[2], args[3]);
- break;
-
- case 1011:
- // args[4] is ignored!
- // soccer passes the argument, but then ends up not using it
- // Makes sense that they removed it for soccermls
- res = op_1011(args[0], args[1], args[2], args[3], args[5]);
- break;
-
- case 1012:
- res = op_1012(args);
- break;
-
- case 1013:
- res = op_1013(args[0], args[1], args[2]);
- break;
-
- case 1019:
- res = op_1019(args);
- break;
-
- case 1020:
- res = op_1020();
- break;
-
- case 1021:
- res = op_1021(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
- break;
-
- case 8221968:
- // Someone had a fun and used his birthday as opcode number
- res = getFromArray(args[0], args[1], args[2]);
- break;
-
- default:
- // original range is 1001 - 1021
- LogicHE::dispatch(op, numArgs, args);
- }
-
- return res;
-}
-
-void LogicHEsoccer::beforeBootScript() {
- if (_intArraysAllocated)
- op_1020();
-
- _userDataD[530] = 0;
-}
-
-void LogicHEsoccer::initOnce() {
- // The original sets some paths here that we don't need to worry about
- _array1013Allocated = false;
- _userDataD[530] = 0;
-}
-
-int LogicHEsoccer::startOfFrame() {
- // This variable is some sort of flag that activates this mode
- int res = (int)_userDataD[530];
-
- // _userDataD[535] is not used!
- // soccer passes the argument, but then ends up not using it
- // Makes sense that they removed it for soccermls
- if (res)
- res = op_1011((int)_userDataD[531], (int)_userDataD[532], (int)_userDataD[533], (int)_userDataD[534], (int)_userDataD[536]);
-
- return res;
-}
-
-int LogicHEsoccer::op_1001(int32 *args) {
- return (int)(args[0] * sin((float)args[1]));
-}
-
-int LogicHEsoccer::op_1002(int32 *args) {
- return _vm->VAR(2) * args[0];
-}
-
-int LogicHEsoccer::op_1003(int32 *args) {
- double data[6], out[3];
- int i;
-
- for (i = 0; i < 6; i++) {
- data[i] = getFromArray(args[0], 0, i);
- }
-
- out[0] = data[1] * data[5] - data[4] * data[2];
- out[1] = data[5] * data[0] - data[3] * data[2];
- out[2] = data[4] * data[0] - data[3] * data[1];
-
- for (i = 0; i < 3; i++) {
- putInArray(args[0], 0, i, scumm_round(out[i]));
- }
-
- return 1;
-}
-
-int LogicHEsoccer::op_1004(int32 *args) {
- // Identical to LogicHEfootball::op_1004
- double res, a2, a4, a5;
-
- a5 = ((double)args[4] - (double)args[1]) / ((double)args[5] - (double)args[2]);
- a4 = ((double)args[3] - (double)args[0]) / ((double)args[5] - (double)args[2]);
- a2 = (double)args[2] - (double)args[0] * a4 - args[1] * a5;
-
- res = (double)args[6] * a4 + (double)args[7] * a5 + a2;
- writeScummVar(108, (int32)res);
-
- writeScummVar(109, (int32)a2);
- writeScummVar(110, (int32)a5);
- writeScummVar(111, (int32)a4);
-
- return 1;
-}
-
-int LogicHEsoccer::op_1006(int32 a1, int32 a2, int32 a3, int32 a4) {
- double v1 = a1 * 0.01;
- double v2 = a2 * 0.01;
- double v3 = a3 * 0.01;
- double var108, var109;
-
- _userDataD[529] = a4;
-
- var108 = atan2(v1, v3) * _userDataD[523] - a4;
- var109 = _userDataD[526] - _userDataD[528] + (_userDataD[521] - atan2(_userDataD[524] - v2, v3)) * _userDataD[522];
-
- writeScummVar(108, (int32)var108);
- writeScummVar(109, (int32)var109);
-
- return 1;
-}
-
-int LogicHEsoccer::op_1007(int32 *args) {
- // Used when the HE logo is shown
- // This initializes the _userDataD fields that are used in op_1006/op_1011
-
- _intArraysAllocated = false;
- double v14 = (double)args[0] * 0.01;
- double v13 = (double)args[2] * 0.01;
- _userDataD[524] = v14;
- double v12 = atan2(v13, v14);
- _userDataD[520] = v12;
- double v15 = atan2(v13 - (double)args[4] * 0.01, (double)args[3] * 0.01);
- double v19 = v15 * 2.0;
- double v17 = atan2(v13 - (double)args[4] * 0.01, v14);
- _userDataD[519] = v19;
- _userDataD[521] = v17;
- _userDataD[525] = (v17 - v12) * 2.0;
- _userDataD[527] = (double)args[5];
- _userDataD[526] = (double)args[6];
- _userDataD[528] = (double)args[7];
- _userDataD[522] = _userDataD[526] / _userDataD[525];
- _userDataD[523] = _userDataD[527] / _userDataD[519];
- _userDataD[518] = v13;
-
- // Clear both byte arrays
- memset(_byteArray1, 0, 4096);
- memset(_byteArray2, 0, 585);
-
- if (_array1013Allocated == 0 )
- op_1013(4, args[8], args[9]);
-
- return 1;
-}
-
-// Returns the square root of the sum of the squares of the arguments
-static inline double sqrtSquare(double a1, double a2, double a3) {
- return sqrt(a1 * a1 + a2 * a2 + a3 * a3);
-}
-
-int LogicHEsoccer::op_1008(int32 *args) {
- // TODO: Used during a match (kicking?)
-
- return 1;
-}
-
-int LogicHEsoccer::op_1011(int32 a1, int32 a2, int32 a3, int32 a4, int32 a5) {
- // This is called on each frame by startOfFrame() if activated by op_1012.
- // This seems to do player placement!
-
- float v28 = 0.0;
-
- for (int i = 0; i < 18; i++) {
- // These seem to be some sort of percent? of angles?
- int v32 = getFromArray(a1, i, 0);
- int v6 = getFromArray(a1, i, 1);
- int v30 = getFromArray(a1, i, 2);
-
- float v29 = (double)v32 / 100.0;
- v28 = (double)v6 / 100.0;
- float v31 = (double)v30 / 100.0;
-
- if (i < 13) {
- int v25 = ((v32 + 2760) / 500 >= 0) ? ((v32 + 2750) / 500) : 0;
- int v24 = 10;
-
- if (v25 <= 10) {
- int v23 = 0;
- if ((v32 + 2750) / 500 >= 0)
- v23 = (v32 + 2750) / 500;
-
- v24 = v23;
- }
-
- int v22 = 0;
- if ((9219 - v30) / 500 >= 0)
- v22 = (9219 - v30) / 500;
-
- int v21 = 6;
- if (v22 <= 6) {
- int v20 = 0;
- if ((9219 - v30) / 500 >= 0)
- v20 = (9219 - v30) / 500;
- v21 = v20;
- }
-
- if (a5)
- putInArray(a5, 0, i, v24 + 11 * v21);
- }
-
- float v7 = atan2(_userDataD[524] - v28, (double)v31);
- int v8 = (int)(_userDataD[526] - (_userDataD[521] - v7) * _userDataD[522] + 300.0);
-
- double v9 = atan2(_userDataD[523], (double)v31);
- // x/y position?
- putInArray(a2, i, 0, (int32)(v29 * v9 + 640.0));
- putInArray(a2, i, 1, v8);
-
- double v10 = atan2(_userDataD[524], (double)v31);
- int v12 = (int)(_userDataD[526] - (_userDataD[521] - (float)v10) * _userDataD[522] + 300.0);
- double v13 = _userDataD[523];
-
- v29 = atan2(v29, v31);
- // x/y position?
- putInArray(a2, i + 22, 0, (int32)(v29 * v13 + 640.0));
- putInArray(a2, i + 22, 1, v12);
- }
-
- // soccer only uses one array here
- // soccermls/soccer2004 use four
- int start = (_vm->_game.id == GID_SOCCER) ? 19 : 18;
- int end = (_vm->_game.id == GID_SOCCER) ? 19 : 21;
-
- for (int i = start; i <= end; i++) {
- int v14 = getFromArray(a2, i, 0);
- int v15 = getFromArray(a2, i, 1);
-
- // This retains v28 from (i == 17)?
- float v16 = _userDataD[524] - v28;
- float v17 = v16 / tan((_userDataD[528] + v15 - _userDataD[526]) / (_userDataD[522] + _userDataD[521]));
- double v18 = tan((double)(v14 - 640) / _userDataD[523]) * v17;
- putInArray(a1, i, 0, (int)(v18 * 100.0));
- putInArray(a1, i, 2, (int)(v17 * 100.0));
- }
-
- op_1011_sub(a1, a3, a4, a4);
-
- return 1;
-}
-
-static inline int distance(int a1, int a2, int a3, int a4) {
- return (int)sqrt((double)((a4 - a3) * (a4 - a3) + (a2 - a1) * (a2 - a1)));
-}
-
-void LogicHEsoccer::op_1011_sub(int32 a1, int32 a2, int32 a3, int32 a4) {
- // As you can guess, this is called from op_1011
- // This seems to be checking distances between the players and the ball
- // and which distance is the shortest.
-
- int v6[13];
- int v7[13];
- int v8[13];
- int v18[195];
-
- for (int i = 0; i < 13; i++) {
- v6[i] = 0;
- v7[i] = getFromArray(a1, i, 0);
- v8[i] = getFromArray(a1, i, 2);
- }
-
- // 12 here, 13 up there
- // Probably 12 for players, 13 for players+ball
- for (int i = 0; i < 12; i++) {
- int v22 = a4;
- for (int j = i + 1; j < 13; j++) {
- v18[i * 15 + j] = distance(v7[i], v7[j], v8[i], v8[j]);
- putInArray(a2, i, j, v18[i * 15 + j]);
- putInArray(a2, j, i, v18[i * 15 + j]);
- if (v18[i * 15 + j] < v22) {
- v22 = v18[i * 15 + j];
- v6[i] = j + 1;
- v6[j] = i + 1;
- }
- }
- }
-
- int v13 = getFromArray(a1, 18, 0);
- int v14 = getFromArray(a1, 18, 2);
- int v15 = getFromArray(a1, 19, 0);
- int v16 = getFromArray(a1, 19, 2);
- int v19[15];
- int v20[15];
-
- if (_vm->_game.id == GID_SOCCER) {
- // soccer gets to be different
- for (int i = 0; i < 13; i++)
- v20[i] = distance(v13, v7[i], v14, v8[i]);
-
- for (int i = 0; i < 13; i++)
- v19[i] = distance(v15, v7[i], v16, v8[i]);
- } else {
- // soccermls and soccer2004 use two other arrays here
- int v9 = getFromArray(a1, 20, 0);
- int v10 = getFromArray(a1, 20, 2);
- int v11 = getFromArray(a1, 21, 0);
- int v12 = getFromArray(a1, 21, 2);
-
- for (int i = 0; i < 6; i++) {
- v20[i] = distance(v9, v7[i], v10, v8[i]);
- v19[i] = distance(v13, v7[i], v14, v8[i]);
- }
-
- for (int i = 6; i < 13; i++) {
- v20[i] = distance(v11, v7[i], v12, v8[i]);
- v19[i] = distance(v15, v7[i], v16, v8[i]);
- }
- }
-
- for (int i = 0; i < 13; i++) {
- putInArray(a2, 14, i, v20[i]);
- putInArray(a2, i, 14, v20[i]);
- putInArray(a2, 13, i, v19[i]);
- putInArray(a2, i, 13, v19[i]);
- putInArray(a3, 0, i, v6[i]);
- }
-}
-
-int LogicHEsoccer::op_1012(int32 *args) {
- // Used after op_1019
- // This function activates startOfFrame() to call op_1011
- // (Possibly field parameters?)
-
- _userDataD[530] = (args[0] != 0) ? 1 : 0;
- _userDataD[531] = args[1];
- _userDataD[532] = args[2];
- _userDataD[533] = args[3];
- _userDataD[534] = args[4];
- _userDataD[535] = args[5]; // unused!!!
- _userDataD[536] = args[6];
-
- return 1;
-}
-
-// Some strange power operation, ignores negative exponents
-static inline double u32Pow(float a1, int a2) {
- if (a2 < 0)
- return 0.0;
+LogicHE *LogicHE::makeLogicHE(ScummEngine_v90he *vm) {
+ switch (vm->_game.id) {
+ case GID_PUTTRACE:
+ return makeLogicHErace(vm);
- float v4 = 1.0;
+ case GID_FUNSHOP:
+ return makeLogicHEfunshop(vm);
- for (int i = 1; i <= a2; i++)
- v4 *= a1;
+ case GID_FOOTBALL:
+ return makeLogicHEfootball(vm);
- return v4;
-}
+ case GID_SOCCER:
+ case GID_SOCCERMLS:
+ case GID_SOCCER2004:
+ return makeLogicHEsoccer(vm);
-int LogicHEsoccer::op_sub5(int a1, int a2, int a3) {
- byte *v9 = _array1013 + 44 * a2;
+ case GID_BASEBALL2001:
+ return makeLogicHEbaseball2001(vm);
- *((uint32 *)v9 + 4) = a3;
- *((uint32 *)v9) = a2;
+ case GID_BASKETBALL:
+ return makeLogicHEbasketball(vm);
- if (a1 > 2) {
- // Casual observation: 585 is also the size of _byteArray2
- *((uint32 *)v9 + 40) = 8 * a2 - 585;
- for (int i = 0; i < 8; i++)
- *((uint32 *)v9 + 4 * i + 8) = 0xffffffff;
- } else {
- for (int i = 0; i < 8; i++)
- *((uint32 *)v9 + 4 * i + 8) = op_sub5(a1 + 1, i + 8 * a2 + 1, a2);
- }
-
- return a2;
-}
-
-int LogicHEsoccer::op_1013(int32 a1, int32 a2, int32 a3) {
- // Creates _array1013 for *some* purpose
- // _array1013Temp is used again op_1014 for some reason...
- // Seems to be used in op_1015
-
- int v4 = (int)((1.0 - u32Pow(8.0, 4)) / -7.0);
-
- _array1013 = new byte[v4 * 44];
- memset(_array1013, 0, v4 * 44);
- _array1013Allocated = true;
- memset(_array1013Temp, 0, 44);
-
- for (int i = 0; i < 8; i++)
- _array1013Temp[i + 2] = op_sub5(1, i + 1, 0);
-
- // Yes, this is not endian-safe, but should not matter since we're
- // not saving/loading the data anywhere
- memcpy(_array1013, _array1013Temp, 44);
-
- return 1;
-}
-
-int LogicHEsoccer::op_1014(int32 a1, int32 a2, int32 a3, int32 a4, int32 a5, int32 a6, int32 a7, int32 a8, int32 a9, int32 a10, int32 a11, int32 a12, int32 a13, int32 a14) {
- // TODO: Used many times during a match
- // And called from op_1008!
-
- return 1;
-}
-
-int LogicHEsoccer::op_1019(int32 *args) {
- // Used at the beginning of a match
- // Initializes some arrays. Player positions?
-
- // These two arrays are used in op_1014 and op_1015
- for (int i = 0; i < 4096; i++)
- _byteArray1[i] = getFromArray(args[1], 0, i);
-
- for (int i = 0; i < 585; i++)
- _byteArray2[i] = getFromArray(args[0], 0, i);
-
- // Deallocate the two integer arrays
- if (_intArraysAllocated)
- op_1020();
-
- // Reallocate them
- _intArray1 = new uint32[1008];
- _intArray2 = new uint32[168];
- _intArraysAllocated = true;
-
- memset(_intArray1, 0, 4 * 4);
- memset(_intArray2, 0, 24 * 4);
-
- // These two arrays are used in op_1015
- for (int i = 0; i < 42; i++) {
- for (int j = 0; j < 24; j++)
- _intArray1[j + 24 * i] = getFromArray(args[3], 0, j + 24 * i);
-
- for (int j = 0; j < 4; j++)
- _intArray2[j + 4 * i] = getFromArray(args[2], 0, j + 4 * i);
- }
-
- return 1;
-}
-
-int LogicHEsoccer::op_1020() {
- // Deallocate integer arrays
- // The arrays can be allocated in op_1015 or op_1019
-
- delete[] _intArray1; _intArray1 = 0;
- delete[] _intArray2; _intArray2 = 0;
- _intArraysAllocated = false;
-
- return 1;
-}
-
-int LogicHEsoccer::op_1021(int32 a1, int32 a2, int32 a3, int32 a4, int32 a5, int32 a6, int32 a7) {
- // Used during a match (ball movement?)
- // Also called from op_1008
-
- int v10;
- if (a4 && a5)
- v10 = (int)(((double)a2 - (double)a5 * (double)a1 / (double)a4) * -1.0 * (double)a4 / (double)a5);
- else
- v10 = a1;
-
- int v9;
- if (a6 && a5)
- v9 = (int)(((double)a2 - (double)a5 * (double)a3 / (double)a6) * -1.0 * (double)a6 / (double)a5);
- else
- v9 = a3;
-
- // The final argument chooses whether to store the results for op_1008 or
- // store them in SCUMM variables.
- if (a7) {
- _var1021[0] = v10;
- _var1021[1] = v9;
- } else {
- writeScummVar(108, v10);
- writeScummVar(109, v9);
- }
-
- return 1;
-}
-
-/***********************
- * Backyard Baseball 2001
- *
- */
-
-int LogicHEbaseball2001::versionID() {
- return 1;
-}
-
-int32 LogicHEbaseball2001::dispatch(int op, int numArgs, int32 *args) {
- int res = 0;
-
- switch (op) {
- case 3001:
- // Check network status
- break;
-
- default:
- LogicHE::dispatch(op, numArgs, args);
- }
-
- return res;
-}
-
-/***********************
- * Backyard Basketball
- *
- */
-
-int LogicHEbasketball::versionID() {
- return 1;
-}
-
-int32 LogicHEbasketball::dispatch(int op, int numArgs, int32 *args) {
- int res = 0;
-
- switch (op) {
- case 1001:
- break;
-
- case 1006:
- break;
-
- case 1011:
- break;
-
- case 1012:
- break;
-
- case 1035:
- break;
-
- case 1050:
- break;
-
- case 1051:
- break;
-
- case 1052:
- break;
-
- case 1056:
- break;
-
- case 1057:
- break;
-
- case 1058:
- break;
-
- case 1060:
- break;
-
- case 1064:
- break;
-
- case 1067:
- break;
-
- case 1073:
- break;
-
- case 1075:
- break;
-
- case 1076:
- break;
-
- case 1080:
- break;
-
- case 1081:
- break;
-
- case 1090:
- break;
-
- case 1091:
- break;
-
- case 1513:
- break;
+ case GID_MOONBASE:
+ return makeLogicHEmoonbase(vm);
default:
- LogicHE::dispatch(op, numArgs, args);
+ return new LogicHE(vm);
}
-
- return res;
-}
-
-/***********************
- * Moonbase Commander
- *
- */
-
-int LogicHEmoonbase::versionID() {
- if (_vm->_game.features & GF_DEMO)
- return -100;
- else
- return 100;
}
} // End of namespace Scumm
diff --git a/engines/scumm/he/logic_he.h b/engines/scumm/he/logic_he.h
index e05a05f310..893dc81b87 100644
--- a/engines/scumm/he/logic_he.h
+++ b/engines/scumm/he/logic_he.h
@@ -29,15 +29,10 @@ class ScummEngine_v90he;
class LogicHE {
public:
- ScummEngine_v90he *_vm;
+ static LogicHE *makeLogicHE(ScummEngine_v90he *vm);
- LogicHE(ScummEngine_v90he *vm);
virtual ~LogicHE();
- void writeScummVar(int var, int32 value);
- int getFromArray(int arg0, int idx2, int idx1);
- void putInArray(int arg0, int idx2, int idx1, int val);
-
virtual void beforeBootScript() {}
virtual void initOnce() {}
virtual int startOfFrame() { return 1; }
@@ -46,142 +41,30 @@ public:
virtual int versionID();
virtual int32 dispatch(int op, int numArgs, int32 *args);
-};
-class LogicHErace : public LogicHE {
-private:
- float *_userData;
- double *_userDataD;
-public:
- LogicHErace(ScummEngine_v90he *vm);
- ~LogicHErace();
-
- int versionID();
- int32 dispatch(int op, int numArgs, int32 *args);
-
-private:
- int32 op_1003(int32 *args);
- int32 op_1004(int32 *args);
- int32 op_1100(int32 *args);
- int32 op_1101(int32 *args);
- int32 op_1102(int32 *args);
- int32 op_1103(int32 *args);
- int32 op_1110();
- int32 op_1120(int32 *args);
- int32 op_1130(int32 *args);
- int32 op_1140(int32 *args);
-
- void op_sub1(float arg);
- void op_sub2(float arg);
- void op_sub3(float arg);
-};
-
-class LogicHEfunshop : public LogicHE {
-public:
- LogicHEfunshop(ScummEngine_v90he *vm) : LogicHE(vm) {}
-
- int versionID();
- int32 dispatch(int op, int numArgs, int32 *args);
-
-private:
- void op_1004(int32 *args);
- void op_1005(int32 *args);
- int checkShape(int32 data0, int32 data1, int32 data4, int32 data5, int32 data2, int32 data3, int32 data6, int32 data7, int32 *x, int32 *y);
-};
-
-class LogicHEfootball : public LogicHE {
-public:
- LogicHEfootball(ScummEngine_v90he *vm) : LogicHE(vm) {}
-
- int versionID();
- int32 dispatch(int op, int numArgs, int32 *args);
-
-private:
- int op_1004(int32 *args);
- int op_1006(int32 *args);
- int op_1007(int32 *args);
- int op_1010(int32 *args);
- int op_1022(int32 *args);
- int op_1023(int32 *args);
- int op_1024(int32 *args);
-};
-
-class LogicHEsoccer : public LogicHE {
-private:
- double *_userDataD;
-
-public:
- LogicHEsoccer(ScummEngine_v90he *vm);
- ~LogicHEsoccer();
-
- int versionID();
- int32 dispatch(int op, int numArgs, int32 *args);
-
- void beforeBootScript();
- void initOnce();
- int startOfFrame();
-
-private:
- int op_1001(int32 *args);
- int op_1002(int32 *args);
- int op_1003(int32 *args);
- int op_1004(int32 *args);
- int op_1006(int32 a1, int32 a2, int32 a3, int32 a4);
- int op_1007(int32 *args);
- int op_1008(int32 *args);
- int op_1011(int32 a1, int32 a2, int32 a3, int32 a4, int32 a5);
- int op_1012(int32 *args);
- int op_1013(int32 a1, int32 a2, int32 a3);
- int op_1014(int32 a1, int32 a2, int32 a3, int32 a4, int32 a5, int32 a6, int32 a7, int32 a8, int32 a9, int32 a10, int32 a11, int32 a12, int32 a13, int32 a14);
- int op_1019(int32 *args);
- int op_1020();
- int op_1021(int32 a1, int32 a2, int32 a3, int32 a4, int32 a5, int32 a6, int32 a7);
-
- // Two integer arrays are used between some functions
- // Originally, these pointers were in _userData, but we keep them separate
- // Also, doing it that would break things on non 32-bit systems...
- bool _intArraysAllocated;
- uint32 *_intArray1, *_intArray2;
-
- // op_1007 allocates some arrays
- // they're then filled by op_1019
- byte _byteArray1[4096], _byteArray2[585];
-
- // op_1011 has a subfunction
- void op_1011_sub(int32 a1, int32 a2, int32 a3, int32 a4);
-
- // op_1013 creates some array, purpose unknown
- bool _array1013Allocated;
- byte *_array1013;
- uint32 _array1013Temp[11];
- int op_sub5(int a1, int a2, int a3);
-
- // op_1021 can (optionally) set two variables for use in op_1008
- uint32 _var1021[2];
-};
-
-class LogicHEbaseball2001 : public LogicHE {
-public:
- LogicHEbaseball2001(ScummEngine_v90he *vm) : LogicHE(vm) {}
+protected:
+ // Only to be used from makeLogicHE()
+ LogicHE(ScummEngine_v90he *vm);
- int versionID();
- int32 dispatch(int op, int numArgs, int32 *args);
-};
+ ScummEngine_v90he *_vm;
-class LogicHEbasketball : public LogicHE {
-public:
- LogicHEbasketball(ScummEngine_v90he *vm) : LogicHE(vm) {}
+ void writeScummVar(int var, int32 value);
+ int getFromArray(int arg0, int idx2, int idx1);
+ void putInArray(int arg0, int idx2, int idx1, int val);
+ int32 scummRound(double arg) { return (int32)(arg + 0.5); }
- int versionID();
- int32 dispatch(int op, int numArgs, int32 *args);
+ #define RAD2DEG (180 / M_PI)
+ #define DEG2RAD (M_PI / 180)
};
-class LogicHEmoonbase : public LogicHE {
-public:
- LogicHEmoonbase(ScummEngine_v90he *vm) : LogicHE(vm) {}
-
- int versionID();
-};
+// Logic declarations
+LogicHE *makeLogicHErace(ScummEngine_v90he *vm);
+LogicHE *makeLogicHEfunshop(ScummEngine_v90he *vm);
+LogicHE *makeLogicHEfootball(ScummEngine_v90he *vm);
+LogicHE *makeLogicHEsoccer(ScummEngine_v90he *vm);
+LogicHE *makeLogicHEbaseball2001(ScummEngine_v90he *vm);
+LogicHE *makeLogicHEbasketball(ScummEngine_v90he *vm);
+LogicHE *makeLogicHEmoonbase(ScummEngine_v90he *vm);
} // End of namespace Scumm
diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp
index e057ab524a..56ea10f507 100644
--- a/engines/scumm/he/script_v100he.cpp
+++ b/engines/scumm/he/script_v100he.cpp
@@ -542,7 +542,7 @@ void ScummEngine_v100he::o100_arrayOps() {
int dim1end, dim1start, dim2end, dim2start;
int id, len, b, c, list[128];
int offs, tmp, tmp2;
- uint tmp3;
+ uint tmp3, type;
byte subOp = fetchScriptByte();
int array = fetchScriptWord();
@@ -625,11 +625,10 @@ void ScummEngine_v100he::o100_arrayOps() {
}
break;
case 132:
- debug(0, "o100_arrayOps: case 132");
- // TODO: Used by Moonbase Commander
+ // TODO: Used by room 2 script 2180 in Moonbase Commander
fetchScriptWord();
fetchScriptWord();
- pop();
+ type = pop();
pop();
pop();
pop();
@@ -646,6 +645,21 @@ void ScummEngine_v100he::o100_arrayOps() {
if (id == 0) {
defineArray(array, kDwordArray, dim2start, dim2end, dim1start, dim1end);
}
+ switch (type) {
+ case 1:
+ break;
+ case 2:
+ break;
+ case 3:
+ break;
+ case 4:
+ break;
+ case 5:
+ break;
+ default:
+ error("o100_arrayOps: case 132 unknown type %d)", type);
+ }
+ debug(0, "o100_arrayOps: case 132 type %d", type);
break;
case 133:
b = pop();
@@ -2933,7 +2947,7 @@ void ScummEngine_v100he::o100_getVideoData() {
break;
case 73:
pop();
- push(_moviePlay->endOfVideo() ? -1 : (_moviePlay->getCurFrame() + 1));
+ push(_moviePlay->getCurFrame());
break;
case 84:
pop();
diff --git a/engines/scumm/he/script_v60he.cpp b/engines/scumm/he/script_v60he.cpp
index cf7d9fbd2f..dbeee567bf 100644
--- a/engines/scumm/he/script_v60he.cpp
+++ b/engines/scumm/he/script_v60he.cpp
@@ -94,6 +94,12 @@ int ScummEngine_v60he::convertFilePath(byte *dst, int dstSize) {
debug(1, "convertFilePath: original filePath is %s", dst);
int len = resStrLen(dst);
+
+ // Switch all \ to / for portablity
+ for (int i = 0; i < len; i++)
+ if (dst[i] == '\\')
+ dst[i] = '/';
+
if (_game.platform == Common::kPlatformMacintosh) {
// Remove : prefix in HE71 games
if (dst[0] == ':') {
@@ -107,12 +113,6 @@ int ScummEngine_v60he::convertFilePath(byte *dst, int dstSize) {
if (dst[i] == ':')
dst[i] = '/';
}
- } else {
- // Switch all \ to / for portablity
- for (int i = 0; i < len; i++) {
- if (dst[i] == '\\')
- dst[i] = '/';
- }
}
// Strip path
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index 5af4035930..b9f454de0f 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -1827,10 +1827,19 @@ void ScummEngine_v72he::o72_readINI() {
switch (subOp) {
case 43: // HE 100
case 6: // number
- if (!strcmp((char *)option, "NoPrinting")) {
+ if (!strcmp((char *)option, "DisablePrinting") || !strcmp((char *)option, "NoPrinting")) {
push(1);
} else if (!strcmp((char *)option, "TextOn")) {
push(ConfMan.getBool("subtitles"));
+ } else if (!strcmp((char *)option, "Disk") && (_game.id == GID_BIRTHDAYRED || _game.id == GID_BIRTHDAYYELLOW)) {
+ // WORKAROUND: Override the disk detection
+ // This removes the reliance on having the binary file around (which is
+ // very bad for the Mac version) just for the scripts to figure out if
+ // we're running Yellow or Red
+ if (_game.id == GID_BIRTHDAYRED)
+ push(4);
+ else
+ push(2);
} else {
push(ConfMan.getInt((char *)option));
}
diff --git a/engines/scumm/he/script_v80he.cpp b/engines/scumm/he/script_v80he.cpp
index 7970d7806f..9711f6415b 100644
--- a/engines/scumm/he/script_v80he.cpp
+++ b/engines/scumm/he/script_v80he.cpp
@@ -171,7 +171,10 @@ void ScummEngine_v80he::o80_readConfigFile() {
case 6: // number
ConfFile.getKey((const char *)option, (const char *)section, entry);
- push(atoi(entry.c_str()));
+ if (!strcmp((char *)option, "Benchmark"))
+ push(2);
+ else
+ push(atoi(entry.c_str()));
break;
case 77: // HE 100
case 7: // string
diff --git a/engines/scumm/he/script_v90he.cpp b/engines/scumm/he/script_v90he.cpp
index 6b632d8ff2..66a0a34d16 100644
--- a/engines/scumm/he/script_v90he.cpp
+++ b/engines/scumm/he/script_v90he.cpp
@@ -1460,7 +1460,7 @@ void ScummEngine_v90he::o90_getVideoData() {
break;
case 52: // Get current frame
pop();
- push(_moviePlay->endOfVideo() ? -1 : (_moviePlay->getCurFrame() + 1));
+ push(_moviePlay->getCurFrame());
break;
case 63: // Get image number
pop();
diff --git a/engines/scumm/he/sprite_he.cpp b/engines/scumm/he/sprite_he.cpp
index 0b37673e4a..081110c7cd 100644
--- a/engines/scumm/he/sprite_he.cpp
+++ b/engines/scumm/he/sprite_he.cpp
@@ -804,12 +804,18 @@ void Sprite::setSpriteImage(int spriteId, int imageNum) {
if (_spriteTable[spriteId].image) {
_spriteTable[spriteId].imageStateCount = _vm->_wiz->getWizImageStates(_spriteTable[spriteId].image);
- _spriteTable[spriteId].flags |= kSFActive | kSFAutoAnim | kSFMarkDirty | kSFBlitDirectly;
+
+ if (_vm->VAR(139))
+ _spriteTable[spriteId].flags |= kSFActive;
+ else
+ _spriteTable[spriteId].flags |= kSFActive | kSFAutoAnim | kSFMarkDirty | kSFBlitDirectly;
if (_spriteTable[spriteId].image != origResId || _spriteTable[spriteId].imageStateCount != origResWizStates)
_spriteTable[spriteId].flags |= kSFChanged | kSFNeedRedraw;
} else {
- if (_spriteTable[spriteId].flags & kSFImageless)
+ if (_vm->VAR(139))
+ _spriteTable[spriteId].flags &= ~kSFActive;
+ else if (_spriteTable[spriteId].flags & kSFImageless)
_spriteTable[spriteId].flags = 0;
else
_spriteTable[spriteId].flags = kSFChanged | kSFBlitDirectly;
diff --git a/engines/scumm/he/sprite_he.h b/engines/scumm/he/sprite_he.h
index d28c9f1944..be6717faa5 100644
--- a/engines/scumm/he/sprite_he.h
+++ b/engines/scumm/he/sprite_he.h
@@ -218,4 +218,3 @@ private:
} // End of namespace Scumm
#endif
-
diff --git a/engines/scumm/he/wiz_he.cpp b/engines/scumm/he/wiz_he.cpp
index 4107034fe6..f67922c81c 100644
--- a/engines/scumm/he/wiz_he.cpp
+++ b/engines/scumm/he/wiz_he.cpp
@@ -1755,7 +1755,7 @@ void Wiz::captureWizPolygon(int resNum, int maskNum, int maskState, int id1, int
uint8 *tmpPtr = imageBuffer;
for (i = 0; i < dsth; i++) {
for (j = 0; j < dstw; j++)
- WRITE_UINT16(tmpPtr + j * 2, transColor);
+ WRITE_LE_UINT16(tmpPtr + j * 2, transColor);
tmpPtr += dstpitch;
}
} else {
diff --git a/engines/scumm/help.cpp b/engines/scumm/help.cpp
index ae7a1ad3bc..cfb23a392a 100644
--- a/engines/scumm/help.cpp
+++ b/engines/scumm/help.cpp
@@ -175,6 +175,7 @@ void ScummHelp::updateStrings(byte gameId, byte version, Common::Platform platfo
ADD_BIND("b", _("To Henry / To Indy"));
break;
case GID_LOOM:
+ // I18N: These are different musical notes
ADD_BIND("q, c", _("play C minor on distaff"));
ADD_BIND("w, d", _("play D on distaff"));
ADD_BIND("e, e", _("play E on distaff"));
@@ -238,6 +239,7 @@ void ScummHelp::updateStrings(byte gameId, byte version, Common::Platform platfo
ADD_BIND("e", _("Examine"));
ADD_BIND("t", _("Regular cursor"));
ADD_BIND("i", _("Inventory"));
+ // I18N: Comm is a communication device
ADD_BIND("c", _("Comm"));
break;
case GID_CMI:
diff --git a/engines/scumm/help.h b/engines/scumm/help.h
index 9763da8c00..5ba6bdc65c 100644
--- a/engines/scumm/help.h
+++ b/engines/scumm/help.h
@@ -42,4 +42,3 @@ public:
} // End of namespace Scumm
#endif
-
diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp
index 317ef36cb9..27a72c2afe 100644
--- a/engines/scumm/imuse/imuse.cpp
+++ b/engines/scumm/imuse/imuse.cpp
@@ -44,30 +44,31 @@ namespace Scumm {
////////////////////////////////////////
IMuseInternal::IMuseInternal() :
-_native_mt32(false),
-_enable_gs(false),
-_sc55(false),
-_midi_adlib(NULL),
-_midi_native(NULL),
-_sysex(NULL),
-_paused(false),
-_initialized(false),
-_tempoFactor(0),
-_player_limit(ARRAYSIZE(_players)),
-_recycle_players(false),
-_queue_end(0),
-_queue_pos(0),
-_queue_sound(0),
-_queue_adding(0),
-_queue_marker(0),
-_queue_cleared(0),
-_master_volume(0),
-_music_volume(0),
-_trigger_count(0),
-_snm_trigger_index(0) {
- memset(_channel_volume,0,sizeof(_channel_volume));
- memset(_channel_volume_eff,0,sizeof(_channel_volume_eff));
- memset(_volchan_table,0,sizeof(_volchan_table));
+ _native_mt32(false),
+ _enable_gs(false),
+ _sc55(false),
+ _midi_adlib(NULL),
+ _midi_native(NULL),
+ _sysex(NULL),
+ _paused(false),
+ _initialized(false),
+ _tempoFactor(0),
+ _player_limit(ARRAYSIZE(_players)),
+ _recycle_players(false),
+ _queue_end(0),
+ _queue_pos(0),
+ _queue_sound(0),
+ _queue_adding(0),
+ _queue_marker(0),
+ _queue_cleared(0),
+ _master_volume(0),
+ _music_volume(0),
+ _trigger_count(0),
+ _snm_trigger_index(0),
+ _pcSpeaker(false) {
+ memset(_channel_volume, 0, sizeof(_channel_volume));
+ memset(_channel_volume_eff, 0, sizeof(_channel_volume_eff));
+ memset(_volchan_table, 0, sizeof(_volchan_table));
}
IMuseInternal::~IMuseInternal() {
@@ -119,7 +120,7 @@ byte *IMuseInternal::findStartOfSound(int sound, int ct) {
// Check for old-style headers first, like 'RO'
int trFlag = (kMThd | kFORM);
- if (ptr[0] == 'R' && ptr[1] == 'O'&& ptr[2] != 'L')
+ if (ptr[0] == 'R' && ptr[1] == 'O' && ptr[2] != 'L')
return ct == trFlag ? ptr : 0;
if (ptr[4] == 'S' && ptr[5] == 'O')
return ct == trFlag ? ptr + 4 : 0;
@@ -153,22 +154,22 @@ bool IMuseInternal::isMT32(int sound) {
uint32 tag = READ_BE_UINT32(ptr);
switch (tag) {
- case MKTAG('A','D','L',' '):
- case MKTAG('A','S','F','X'): // Special AD class for old AdLib sound effects
- case MKTAG('S','P','K',' '):
+ case MKTAG('A', 'D', 'L', ' '):
+ case MKTAG('A', 'S', 'F', 'X'): // Special AD class for old AdLib sound effects
+ case MKTAG('S', 'P', 'K', ' '):
return false;
- case MKTAG('A','M','I',' '):
- case MKTAG('R','O','L',' '):
+ case MKTAG('A', 'M', 'I', ' '):
+ case MKTAG('R', 'O', 'L', ' '):
return true;
- case MKTAG('M','A','C',' '): // Occurs in the Mac version of FOA and MI2
+ case MKTAG('M', 'A', 'C', ' '): // Occurs in the Mac version of FOA and MI2
return true;
- case MKTAG('G','M','D',' '):
+ case MKTAG('G', 'M', 'D', ' '):
return false;
- case MKTAG('M','I','D','I'): // Occurs in Sam & Max
+ case MKTAG('M', 'I', 'D', 'I'): // Occurs in Sam & Max
// HE games use Roland music
if (ptr[8] == 'H' && ptr[9] == 'S')
return true;
@@ -195,20 +196,20 @@ bool IMuseInternal::isMIDI(int sound) {
uint32 tag = READ_BE_UINT32(ptr);
switch (tag) {
- case MKTAG('A','D','L',' '):
- case MKTAG('A','S','F','X'): // Special AD class for old AdLib sound effects
- case MKTAG('S','P','K',' '):
+ case MKTAG('A', 'D', 'L', ' '):
+ case MKTAG('A', 'S', 'F', 'X'): // Special AD class for old AdLib sound effects
+ case MKTAG('S', 'P', 'K', ' '):
return false;
- case MKTAG('A','M','I',' '):
- case MKTAG('R','O','L',' '):
+ case MKTAG('A', 'M', 'I', ' '):
+ case MKTAG('R', 'O', 'L', ' '):
return true;
- case MKTAG('M','A','C',' '): // Occurs in the Mac version of FOA and MI2
+ case MKTAG('M', 'A', 'C', ' '): // Occurs in the Mac version of FOA and MI2
return true;
- case MKTAG('G','M','D',' '):
- case MKTAG('M','I','D','I'): // Occurs in Sam & Max
+ case MKTAG('G', 'M', 'D', ' '):
+ case MKTAG('M', 'I', 'D', 'I'): // Occurs in Sam & Max
return true;
}
@@ -381,7 +382,8 @@ int IMuseInternal::save_or_load(Serializer *ser, ScummEngine *scumm) {
for (i = 0; i < ARRAYSIZE(_parts); ++i)
_parts[i].saveLoadWithSerializer(ser);
- { // Load/save the instrument definitions, which were revamped with V11.
+ {
+ // Load/save the instrument definitions, which were revamped with V11.
Part *part = &_parts[0];
if (ser->getVersion() >= VER(11)) {
for (i = ARRAYSIZE(_parts); i; --i, ++part) {
@@ -467,6 +469,10 @@ uint32 IMuseInternal::property(int prop, uint32 value) {
case IMuse::PROP_GAME_ID:
_game_id = value;
break;
+
+ case IMuse::PROP_PC_SPEAKER:
+ _pcSpeaker = (value != 0);
+ break;
}
return 0;
@@ -522,7 +528,7 @@ void IMuseInternal::stopAllSounds() {
int IMuseInternal::getSoundStatus(int sound) const {
Common::StackLock lock(_mutex, "IMuseInternal::getSoundStatus()");
- return getSoundStatus_internal (sound, true);
+ return getSoundStatus_internal(sound, true);
}
int IMuseInternal::getMusicTimer() {
@@ -565,7 +571,7 @@ bool IMuseInternal::startSound_internal(int sound, int offset) {
int i;
ImTrigger *trigger = _snm_triggers;
for (i = ARRAYSIZE(_snm_triggers); i; --i, ++trigger) {
- if (trigger->sound && trigger->id && trigger->command[0] == 8 && trigger->command[1] == sound && getSoundStatus_internal (trigger->sound,true))
+ if (trigger->sound && trigger->id && trigger->command[0] == 8 && trigger->command[1] == sound && getSoundStatus_internal(trigger->sound, true))
return false;
}
@@ -663,9 +669,7 @@ int IMuseInternal::getSoundStatus_internal(int sound, bool ignoreFadeouts) const
return (sound == -1) ? 0 : get_queue_sound_status(sound);
}
-int32 IMuseInternal::doCommand_internal
- (int a, int b, int c, int d, int e, int f, int g, int h)
-{
+int32 IMuseInternal::doCommand_internal(int a, int b, int c, int d, int e, int f, int g, int h) {
int args[8];
args[0] = a;
args[1] = b;
@@ -733,7 +737,7 @@ int32 IMuseInternal::doCommand_internal(int numargs, int a[]) {
}
return -1;
case 13:
- return getSoundStatus_internal (a[1], true);
+ return getSoundStatus_internal(a[1], true);
case 14:
// Sam and Max: Parameter fade
player = findActivePlayer(a[1]);
@@ -779,8 +783,7 @@ int32 IMuseInternal::doCommand_internal(int numargs, int a[]) {
a[0] = 0;
for (i = 0; i < ARRAYSIZE(_snm_triggers); ++i) {
if (_snm_triggers[i].sound == a[1] && _snm_triggers[i].id &&
- (a[3] == -1 || _snm_triggers[i].id == a[3]))
- {
+ (a[3] == -1 || _snm_triggers[i].id == a[3])) {
++a[0];
}
}
@@ -1002,9 +1005,9 @@ int IMuseInternal::get_queue_sound_status(int sound) const {
i = (i + 1) % ARRAYSIZE(_cmd_queue);
}
- for (i = 0; i < ARRAYSIZE (_deferredCommands); ++i) {
+ for (i = 0; i < ARRAYSIZE(_deferredCommands); ++i) {
if (_deferredCommands[i].time_left && _deferredCommands[i].a == 8 &&
- _deferredCommands[i].b == sound) {
+ _deferredCommands[i].b == sound) {
return 2;
}
}
@@ -1213,7 +1216,7 @@ int32 IMuseInternal::ImSetTrigger(int sound, int id, int a, int b, int c, int d,
// NOTE: We ONLY do this if the sound that will trigger the command is actually
// playing. Otherwise, there's a problem when exiting and re-entering the
// Bumpusville mansion. Ref Bug #780918.
- if (trig->command[0] == 8 && getSoundStatus_internal(trig->command[1],true) && getSoundStatus_internal(sound,true))
+ if (trig->command[0] == 8 && getSoundStatus_internal(trig->command[1], true) && getSoundStatus_internal(sound, true))
stopSound_internal(trig->command[1]);
return 0;
}
@@ -1246,8 +1249,7 @@ int32 IMuseInternal::ImFireAllTriggers(int sound) {
return (count > 0) ? 0 : -1;
}
-int IMuseInternal::set_channel_volume(uint chan, uint vol)
-{
+int IMuseInternal::set_channel_volume(uint chan, uint vol) {
if (chan >= 8 || vol > 127)
return -1;
@@ -1427,7 +1429,7 @@ void IMuseInternal::initMT32(MidiDriver *midi) {
// Display a welcome message on MT-32 displays.
memcpy(&buffer[0], "\x41\x10\x16\x12\x20\x00\x00", 7);
memcpy(&buffer[7], " ", 20);
- memcpy(buffer + 7 +(20 - len) / 2, info, len);
+ memcpy(buffer + 7 + (20 - len) / 2, info, len);
byte checksum = 0;
for (int i = 4; i < 27; ++i)
checksum -= buffer[i];
@@ -1473,9 +1475,9 @@ void IMuseInternal::initGM(MidiDriver *midi) {
// Set Channels 1-16 to SC-55 Map, then CM-64/32L Variation
for (i = 0; i < 16; ++i) {
- midi->send(( 127 << 16) | (0 << 8) | (0xB0 | i));
- midi->send(( 1 << 16) | (32 << 8) | (0xB0 | i));
- midi->send(( 0 << 16) | (0 << 8) | (0xC0 | i));
+ midi->send((127 << 16) | (0 << 8) | (0xB0 | i));
+ midi->send((1 << 16) | (32 << 8) | (0xB0 | i));
+ midi->send((0 << 16) | (0 << 8) | (0xC0 | i));
}
debug(2, "GS Program Change: CM-64/32L Map Selected");
@@ -1496,7 +1498,7 @@ void IMuseInternal::initGM(MidiDriver *midi) {
// Set Channels 1-16 Reverb to 64, which is the
// equivalent of MT-32 default Reverb Level 5
for (i = 0; i < 16; ++i)
- midi->send(( 64 << 16) | (91 << 8) | (0xB0 | i));
+ midi->send((64 << 16) | (91 << 8) | (0xB0 | i));
debug(2, "GM Controller 91 Change: Channels 1-16 Reverb Level is 64");
// Set Channels 1-16 Pitch Bend Sensitivity to
@@ -1637,8 +1639,8 @@ void IMuseInternal::reallocateMidiChannels(MidiDriver *midi) {
hipart = NULL;
for (i = 32, part = _parts; i; i--, part++) {
if (part->_player && part->_player->getMidiDriver() == midi &&
- !part->_percussion && part->_on &&
- !part->_mc && part->_pri_eff >= hipri) {
+ !part->_percussion && part->_on &&
+ !part->_mc && part->_pri_eff >= hipri) {
hipri = part->_pri_eff;
hipart = part;
}
@@ -1668,16 +1670,35 @@ void IMuseInternal::reallocateMidiChannels(MidiDriver *midi) {
}
}
-void IMuseInternal::setGlobalAdLibInstrument(byte slot, byte *data) {
+void IMuseInternal::setGlobalInstrument(byte slot, byte *data) {
if (slot < 32) {
- _global_adlib_instruments[slot].adlib(data);
+ if (_pcSpeaker)
+ _global_instruments[slot].pcspk(data);
+ else
+ _global_instruments[slot].adlib(data);
}
}
-void IMuseInternal::copyGlobalAdLibInstrument(byte slot, Instrument *dest) {
+void IMuseInternal::copyGlobalInstrument(byte slot, Instrument *dest) {
if (slot >= 32)
return;
- _global_adlib_instruments[slot].copy_to(dest);
+
+ // Both the AdLib code and the PC Speaker code use an all zero instrument
+ // as default in the original, thus we do the same.
+ // PC Speaker instrument size is 23, while AdLib instrument size is 30.
+ // Thus we just use a 30 byte instrument data array as default.
+ const byte defaultInstr[30] = { 0 };
+
+ if (_global_instruments[slot].isValid()) {
+ // In case we have an valid instrument set up, copy it to the part.
+ _global_instruments[slot].copy_to(dest);
+ } else if (_pcSpeaker) {
+ debug(0, "Trying to use non-existant global PC Speaker instrument %d", slot);
+ dest->pcspk(defaultInstr);
+ } else {
+ debug(0, "Trying to use non-existant global AdLib instrument %d", slot);
+ dest->adlib(defaultInstr);
+ }
}
diff --git a/engines/scumm/imuse/imuse.h b/engines/scumm/imuse/imuse.h
index 8014b13409..23449e470b 100644
--- a/engines/scumm/imuse/imuse.h
+++ b/engines/scumm/imuse/imuse.h
@@ -37,7 +37,7 @@ class Player;
class ScummEngine;
class Serializer;
-typedef void (*sysexfunc) (Player *, const byte *, uint16);
+typedef void (*sysexfunc)(Player *, const byte *, uint16);
/**
* iMuse implementation interface.
@@ -55,7 +55,8 @@ public:
PROP_GS,
PROP_LIMIT_PLAYERS,
PROP_RECYCLE_PLAYERS,
- PROP_GAME_ID
+ PROP_GAME_ID,
+ PROP_PC_SPEAKER
};
public:
@@ -66,7 +67,7 @@ public:
virtual int32 doCommand(int numargs, int args[]) = 0;
virtual int clear_queue() = 0;
virtual uint32 property(int prop, uint32 value) = 0;
- virtual void addSysexHandler (byte mfgID, sysexfunc handler) = 0;
+ virtual void addSysexHandler(byte mfgID, sysexfunc handler) = 0;
public:
virtual void startSoundWithNoteOffset(int sound, int offset) = 0;
diff --git a/engines/scumm/imuse/imuse_internal.h b/engines/scumm/imuse/imuse_internal.h
index 6a7b9fc7d9..3b0d36e119 100644
--- a/engines/scumm/imuse/imuse_internal.h
+++ b/engines/scumm/imuse/imuse_internal.h
@@ -135,7 +135,7 @@ struct ImTrigger {
int sound;
byte id;
uint16 expire;
- int command [8];
+ int command[8];
ImTrigger() { memset(this, 0, sizeof(ImTrigger)); }
};
@@ -153,12 +153,12 @@ struct CommandQueue {
//////////////////////////////////////////////////
class Player : public MidiDriver_BASE {
-/*
- * External SysEx handler functions shall each be defined in
- * a separate file. This header file shall be included at the
- * top of the file immediately following this special #define:
- * #define SYSEX_CALLBACK_FUNCTION nameOfHandlerFunction
- */
+ /*
+ * External SysEx handler functions shall each be defined in
+ * a separate file. This header file shall be included at the
+ * top of the file immediately following this special #define:
+ * #define SYSEX_CALLBACK_FUNCTION nameOfHandlerFunction
+ */
#ifdef SYSEX_CALLBACK_FUNCTION
friend void SYSEX_CALLBACK_FUNCTION(Player *, const byte *, uint16);
#endif
@@ -244,7 +244,7 @@ public:
void clear();
void clearLoop();
void fixAfterLoad();
- Part * getActivePart(uint8 part);
+ Part *getActivePart(uint8 part);
uint getBeatIndex();
int8 getDetune() const { return _detune; }
byte getEffectiveVolume() const { return _vol_eff; }
@@ -252,7 +252,7 @@ public:
MidiDriver *getMidiDriver() const { return _midi; }
int getParam(int param, byte chan);
int8 getPan() const { return _pan; }
- Part * getPart(uint8 part);
+ Part *getPart(uint8 part);
byte getPriority() const { return _priority; }
uint getTicksPerBeat() const { return TICKS_PER_BEAT; }
int8 getTranspose() const { return _transpose; }
@@ -342,6 +342,7 @@ struct Part : public Serializable {
void off();
void set_instrument(uint b);
void set_instrument(byte *data);
+ void set_instrument_pcspk(byte *data);
void load_global_instrument(byte b);
void set_transpose(int8 transpose);
@@ -375,12 +376,12 @@ class IMuseInternal : public IMuse {
friend class Player;
friend struct Part;
-/*
- * External SysEx handler functions shall each be defined in
- * a separate file. This header file shall be included at the
- * top of the file immediately following this special #define:
- * #define SYSEX_CALLBACK_FUNCTION nameOfHandlerFunction
- */
+ /*
+ * External SysEx handler functions shall each be defined in
+ * a separate file. This header file shall be included at the
+ * top of the file immediately following this special #define:
+ * #define SYSEX_CALLBACK_FUNCTION nameOfHandlerFunction
+ */
#ifdef SYSEX_CALLBACK_FUNCTION
friend void SYSEX_CALLBACK_FUNCTION(Player *, const byte *, uint16);
#endif
@@ -433,7 +434,8 @@ protected:
Player _players[8];
Part _parts[32];
- Instrument _global_adlib_instruments[32];
+ bool _pcSpeaker;
+ Instrument _global_instruments[32];
CommandQueue _cmd_queue[64];
DeferredCommand _deferredCommands[4];
@@ -449,8 +451,8 @@ protected:
enum ChunkType {
kMThd = 1,
kFORM = 2,
- kMDhd = 4, // Used in MI2 and INDY4. Contain certain start parameters (priority, volume, etc. ) for the player.
- kMDpg = 8 // These chunks exist in DOTT and SAMNMAX. They don't get processed, however.
+ kMDhd = 4, // Used in MI2 and INDY4. Contain certain start parameters (priority, volume, etc. ) for the player.
+ kMDpg = 8 // These chunks exist in DOTT and SAMNMAX. They don't get processed, however.
};
byte *findStartOfSound(int sound, int ct = (kMThd | kFORM));
@@ -498,8 +500,8 @@ protected:
int setImuseMasterVolume(uint vol);
void reallocateMidiChannels(MidiDriver *midi);
- void setGlobalAdLibInstrument(byte slot, byte *data);
- void copyGlobalAdLibInstrument(byte slot, Instrument *dest);
+ void setGlobalInstrument(byte slot, byte *data);
+ void copyGlobalInstrument(byte slot, Instrument *dest);
bool isNativeMT32() { return _native_mt32; }
protected:
diff --git a/engines/scumm/imuse/imuse_part.cpp b/engines/scumm/imuse/imuse_part.cpp
index 5df8407a96..73e7704469 100644
--- a/engines/scumm/imuse/imuse_part.cpp
+++ b/engines/scumm/imuse/imuse_part.cpp
@@ -193,14 +193,18 @@ void Part::set_onoff(bool on) {
}
}
-void Part::set_instrument(byte * data) {
- _instrument.adlib(data);
+void Part::set_instrument(byte *data) {
+ if (_se->_pcSpeaker)
+ _instrument.pcspk(data);
+ else
+ _instrument.adlib(data);
+
if (clearToTransmit())
_instrument.send(_mc);
}
void Part::load_global_instrument(byte slot) {
- _player->_se->copyGlobalAdLibInstrument(slot, &_instrument);
+ _player->_se->copyGlobalInstrument(slot, &_instrument);
if (clearToTransmit())
_instrument.send(_mc);
}
@@ -234,7 +238,7 @@ void Part::noteOn(byte note, byte velocity) {
// should be implemented as a class static var. As it is, using
// a function level static var in most cases is arcane and evil.
static byte prev_vol_eff = 128;
- if (_vol_eff != prev_vol_eff){
+ if (_vol_eff != prev_vol_eff) {
mc->volume(_vol_eff);
prev_vol_eff = _vol_eff;
}
diff --git a/engines/scumm/imuse/imuse_player.cpp b/engines/scumm/imuse/imuse_player.cpp
index 61b9cad2cb..73be2174cd 100644
--- a/engines/scumm/imuse/imuse_player.cpp
+++ b/engines/scumm/imuse/imuse_player.cpp
@@ -79,7 +79,7 @@ Player::Player() :
_isMT32(false),
_isMIDI(false),
_se(0),
- _vol_chan(0){
+ _vol_chan(0) {
}
Player::~Player() {
@@ -133,7 +133,7 @@ bool Player::isFadingOut() const {
int i;
for (i = 0; i < ARRAYSIZE(_parameterFaders); ++i) {
if (_parameterFaders[i].param == ParameterFader::pfVolume &&
- _parameterFaders[i].end == 0) {
+ _parameterFaders[i].end == 0) {
return true;
}
}
@@ -371,11 +371,13 @@ void Player::sysEx(const byte *p, uint16 len) {
if (a != IMUSE_SYSEX_ID) {
if (a == ROLAND_SYSEX_ID) {
// Roland custom instrument definition.
- part = getPart(p[0] & 0x0F);
- if (part) {
- part->_instrument.roland(p - 1);
- if (part->clearToTransmit())
- part->_instrument.send(part->_mc);
+ if (_isMIDI || _isMT32) {
+ part = getPart(p[0] & 0x0F);
+ if (part) {
+ part->_instrument.roland(p - 1);
+ if (part->clearToTransmit())
+ part->_instrument.send(part->_mc);
+ }
}
} else if (a == YM2612_SYSEX_ID) {
// FM-TOWNS custom instrument definition
@@ -399,13 +401,13 @@ void Player::sysEx(const byte *p, uint16 len) {
if (!_scanning) {
for (a = 0; a < len + 1 && a < 19; ++a) {
- sprintf((char *)&buf[a*3], " %02X", p[a]);
+ sprintf((char *)&buf[a * 3], " %02X", p[a]);
} // next for
if (a < len + 1) {
- buf[a*3] = buf[a*3+1] = buf[a*3+2] = '.';
+ buf[a * 3] = buf[a * 3 + 1] = buf[a * 3 + 2] = '.';
++a;
} // end if
- buf[a*3] = '\0';
+ buf[a * 3] = '\0';
debugC(DEBUG_IMUSE, "[%02d] SysEx:%s", _id, buf);
}
@@ -814,7 +816,7 @@ int Player::query_part_param(int param, byte chan) {
return part->_vol;
case 16:
// FIXME: Need to know where this occurs...
-error("Trying to cast instrument (%d, %d) -- please tell Fingolfin", param, chan);
+ error("Trying to cast instrument (%d, %d) -- please tell Fingolfin", param, chan);
// In old versions of the code, this used to return part->_program.
// This was changed in revision 2.29 of imuse.cpp (where this code used
// to reside).
@@ -845,9 +847,8 @@ void Player::onTimer() {
uint beat_index = target_tick / TICKS_PER_BEAT + 1;
uint tick_index = target_tick % TICKS_PER_BEAT;
- if (_loop_counter &&(beat_index > _loop_from_beat ||
- (beat_index == _loop_from_beat && tick_index >= _loop_from_tick)))
- {
+ if (_loop_counter && (beat_index > _loop_from_beat ||
+ (beat_index == _loop_from_beat && tick_index >= _loop_from_tick))) {
_loop_counter--;
jump(_track_index, _loop_to_beat, _loop_to_tick);
}
@@ -891,15 +892,15 @@ int Player::addParameterFader(int param, int target, int time) {
// target = target * 128 / 100;
break;
- case 127:
- { // FIXME? I *think* this clears all parameter faders.
- ParameterFader *ptr = &_parameterFaders[0];
- int i;
- for (i = ARRAYSIZE(_parameterFaders); i; --i, ++ptr)
- ptr->param = 0;
- return 0;
- }
- break;
+ case 127: {
+ // FIXME? I *think* this clears all parameter faders.
+ ParameterFader *ptr = &_parameterFaders[0];
+ int i;
+ for (i = ARRAYSIZE(_parameterFaders); i; --i, ++ptr)
+ ptr->param = 0;
+ return 0;
+ }
+ break;
default:
debug(0, "Player::addParameterFader(%d, %d, %d): Unknown parameter", param, target, time);
@@ -1085,7 +1086,7 @@ void Player::saveLoadWithSerializer(Serializer *ser) {
}
ser->saveLoadEntries(this, playerEntries);
ser->saveLoadArrayOf(_parameterFaders, ARRAYSIZE(_parameterFaders),
- sizeof(ParameterFader), parameterFaderEntries);
+ sizeof(ParameterFader), parameterFaderEntries);
return;
}
diff --git a/engines/scumm/imuse/instrument.cpp b/engines/scumm/imuse/instrument.cpp
index 955700fc2b..11bb4e7605 100644
--- a/engines/scumm/imuse/instrument.cpp
+++ b/engines/scumm/imuse/instrument.cpp
@@ -114,14 +114,15 @@ roland_to_gm_map[] = {
// { "trickle4 ", ??? }
};
+// This emulates the percussion bank setup LEC used with the MT-32,
+// where notes 24 - 34 were assigned instruments without reverb.
+// It also fixes problems on GS devices that map sounds to these
+// notes by default.
const byte Instrument::_gmRhythmMap[35] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 36, 37, 38, 39, 40, 41, 66, 47,
- 65, 48, 56};
- // This emulates the percussion bank setup LEC used with the MT-32,
- // where notes 24 - 34 were assigned instruments without reverb.
- // It also fixes problems on GS devices that map sounds to these
- // notes by default.
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 36, 37, 38, 39, 40, 41, 66, 47,
+ 65, 48, 56
+};
class Instrument_Program : public InstrumentInternal {
private:
@@ -136,15 +137,16 @@ public:
void copy_to(Instrument *dest) { dest->program(_program, _mt32); }
bool is_valid() {
return (_program < 128) &&
- ((_native_mt32 == _mt32) || _native_mt32
- ? (MidiDriver::_gmToMt32[_program] < 128)
- : (MidiDriver::_mt32ToGm[_program] < 128)); }
+ ((_native_mt32 == _mt32) || _native_mt32
+ ? (MidiDriver::_gmToMt32[_program] < 128)
+ : (MidiDriver::_mt32ToGm[_program] < 128));
+ }
};
class Instrument_AdLib : public InstrumentInternal {
private:
-#include "common/pack-start.h" // START STRUCT PACKING
+#include "common/pack-start.h" // START STRUCT PACKING
struct AdLibInstrument {
byte flags_1;
@@ -159,13 +161,17 @@ private:
byte waveform_2;
byte feedback;
byte flags_a;
- struct { byte a,b,c,d,e,f,g,h; } extra_a;
+ struct {
+ byte a, b, c, d, e, f, g, h;
+ } extra_a;
byte flags_b;
- struct { byte a,b,c,d,e,f,g,h; } extra_b;
+ struct {
+ byte a, b, c, d, e, f, g, h;
+ } extra_b;
byte duration;
} PACKED_STRUCT;
-#include "common/pack-end.h" // END STRUCT PACKING
+#include "common/pack-end.h" // END STRUCT PACKING
AdLibInstrument _instrument;
@@ -181,7 +187,7 @@ public:
class Instrument_Roland : public InstrumentInternal {
private:
-#include "common/pack-start.h" // START STRUCT PACKING
+#include "common/pack-start.h" // START STRUCT PACKING
struct RolandInstrument {
byte roland_id;
@@ -242,11 +248,11 @@ private:
byte checksum;
} PACKED_STRUCT;
-#include "common/pack-end.h" // END STRUCT PACKING
+#include "common/pack-end.h" // END STRUCT PACKING
RolandInstrument _instrument;
- char _instrument_name [11];
+ char _instrument_name[11];
uint8 getEquivalentGM();
@@ -259,6 +265,19 @@ public:
bool is_valid() { return (_native_mt32 ? true : (_instrument_name[0] != '\0')); }
};
+class Instrument_PcSpk : public InstrumentInternal {
+public:
+ Instrument_PcSpk(const byte *data);
+ Instrument_PcSpk(Serializer *s);
+ void saveOrLoad(Serializer *s);
+ void send(MidiChannel *mc);
+ void copy_to(Instrument *dest) { dest->pcspk((byte *)&_instrument); }
+ bool is_valid() { return true; }
+
+private:
+ byte _instrument[23];
+};
+
////////////////////////////////////////
//
// Instrument class members
@@ -299,7 +318,15 @@ void Instrument::roland(const byte *instrument) {
_instrument = new Instrument_Roland(instrument);
}
-void Instrument::saveOrLoad (Serializer *s) {
+void Instrument::pcspk(const byte *instrument) {
+ clear();
+ if (!instrument)
+ return;
+ _type = itPcSpk;
+ _instrument = new Instrument_PcSpk(instrument);
+}
+
+void Instrument::saveOrLoad(Serializer *s) {
if (s->isSaving()) {
s->saveByte(_type);
if (_instrument)
@@ -319,6 +346,9 @@ void Instrument::saveOrLoad (Serializer *s) {
case itRoland:
_instrument = new Instrument_Roland(s);
break;
+ case itPcSpk:
+ _instrument = new Instrument_PcSpk(s);
+ break;
default:
warning("No known instrument classification #%d", (int)_type);
_type = itNone;
@@ -333,8 +363,8 @@ void Instrument::saveOrLoad (Serializer *s) {
////////////////////////////////////////
Instrument_Program::Instrument_Program(byte program, bool mt32) :
-_program (program),
-_mt32 (mt32) {
+ _program(program),
+ _mt32(mt32) {
if (program > 127)
_program = 255;
}
@@ -413,7 +443,7 @@ Instrument_Roland::Instrument_Roland(const byte *data) {
Instrument_Roland::Instrument_Roland(Serializer *s) {
_instrument_name[0] = '\0';
if (!s->isSaving())
- saveOrLoad (s);
+ saveOrLoad(s);
else
memset(&_instrument, 0, sizeof(_instrument));
}
@@ -470,4 +500,32 @@ uint8 Instrument_Roland::getEquivalentGM() {
return 255;
}
+////////////////////////////////////////
+//
+// Instrument_PcSpk class members
+//
+////////////////////////////////////////
+
+Instrument_PcSpk::Instrument_PcSpk(const byte *data) {
+ memcpy(_instrument, data, sizeof(_instrument));
+}
+
+Instrument_PcSpk::Instrument_PcSpk(Serializer *s) {
+ if (!s->isSaving())
+ saveOrLoad(s);
+ else
+ memset(_instrument, 0, sizeof(_instrument));
+}
+
+void Instrument_PcSpk::saveOrLoad(Serializer *s) {
+ if (s->isSaving())
+ s->saveBytes(_instrument, sizeof(_instrument));
+ else
+ s->loadBytes(_instrument, sizeof(_instrument));
+}
+
+void Instrument_PcSpk::send(MidiChannel *mc) {
+ mc->sysEx_customInstrument('SPK ', (byte *)&_instrument);
+}
+
} // End of namespace Scumm
diff --git a/engines/scumm/imuse/instrument.h b/engines/scumm/imuse/instrument.h
index 79cbd49032..a855c64155 100644
--- a/engines/scumm/imuse/instrument.h
+++ b/engines/scumm/imuse/instrument.h
@@ -51,10 +51,11 @@ public:
itNone = 0,
itProgram = 1,
itAdLib = 2,
- itRoland = 3
+ itRoland = 3,
+ itPcSpk = 4
};
- Instrument() : _type (0), _instrument (0) { }
+ Instrument() : _type(0), _instrument(0) { }
~Instrument() { delete _instrument; }
static void nativeMT32(bool native);
static const byte _gmRhythmMap[35];
@@ -70,6 +71,7 @@ public:
void program(byte program, bool mt32);
void adlib(const byte *instrument);
void roland(const byte *instrument);
+ void pcspk(const byte *instrument);
byte getType() { return _type; }
bool isValid() { return (_instrument ? _instrument->is_valid() : false); }
diff --git a/engines/scumm/imuse/pcspk.cpp b/engines/scumm/imuse/pcspk.cpp
new file mode 100644
index 0000000000..cbf3446f10
--- /dev/null
+++ b/engines/scumm/imuse/pcspk.cpp
@@ -0,0 +1,834 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "scumm/imuse/pcspk.h"
+
+#include "common/util.h"
+
+namespace Scumm {
+
+PcSpkDriver::PcSpkDriver(Audio::Mixer *mixer)
+ : MidiDriver_Emulated(mixer), _pcSpk(mixer->getOutputRate()) {
+}
+
+PcSpkDriver::~PcSpkDriver() {
+ close();
+}
+
+int PcSpkDriver::open() {
+ if (_isOpen)
+ return MERR_ALREADY_OPEN;
+
+ MidiDriver_Emulated::open();
+
+ for (uint i = 0; i < 6; ++i)
+ _channels[i].init(this, i);
+ _activeChannel = 0;
+ _effectTimer = 0;
+ _randBase = 1;
+
+ // We need to take care we only send note frequencies, when the internal
+ // settings actually changed, thus we need some extra state to keep track
+ // of that.
+ _lastActiveChannel = 0;
+ _lastActiveOut = 0;
+
+ // We set the output sound type to music here to allow sound volume
+ // adjustment. The drawback here is that we can not control the music and
+ // sfx separately here. But the AdLib output has the same issue so it
+ // should not be that bad.
+ _mixer->playStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
+ return 0;
+}
+
+void PcSpkDriver::close() {
+ if (!_isOpen)
+ return;
+ _isOpen = false;
+
+ _mixer->stopHandle(_mixerSoundHandle);
+}
+
+void PcSpkDriver::send(uint32 d) {
+ assert((d & 0x0F) < 6);
+ _channels[(d & 0x0F)].send(d);
+}
+
+void PcSpkDriver::sysEx_customInstrument(byte channel, uint32 type, const byte *instr) {
+ assert(channel < 6);
+ if (type == 'SPK ')
+ _channels[channel].sysEx_customInstrument(type, instr);
+}
+
+MidiChannel *PcSpkDriver::allocateChannel() {
+ for (uint i = 0; i < 6; ++i) {
+ if (_channels[i].allocate())
+ return &_channels[i];
+ }
+
+ return 0;
+}
+
+void PcSpkDriver::generateSamples(int16 *buf, int len) {
+ _pcSpk.readBuffer(buf, len);
+}
+
+void PcSpkDriver::onTimer() {
+ if (!_activeChannel)
+ return;
+
+ for (uint i = 0; i < 6; ++i) {
+ OutputChannel &out = _channels[i]._out;
+
+ if (!out.active)
+ continue;
+
+ if (out.length == 0 || --out.length != 0) {
+ if (out.unkB && out.unkC) {
+ out.unkA += out.unkB;
+ if (out.instrument)
+ out.unkE = ((int8)out.instrument[out.unkA] * out.unkC) >> 4;
+ }
+
+ ++_effectTimer;
+ if (_effectTimer > 3) {
+ _effectTimer = 0;
+
+ if (out.effectEnvelopeA.state)
+ updateEffectGenerator(_channels[i], out.effectEnvelopeA, out.effectDefA);
+ if (out.effectEnvelopeB.state)
+ updateEffectGenerator(_channels[i], out.effectEnvelopeB, out.effectDefB);
+ }
+ } else {
+ out.active = 0;
+ updateNote();
+ return;
+ }
+ }
+
+ if (_activeChannel->_tl) {
+ output((_activeChannel->_out.note << 7) + _activeChannel->_pitchBend + _activeChannel->_out.unk60 + _activeChannel->_out.unkE);
+ } else {
+ _pcSpk.stop();
+ _lastActiveChannel = 0;
+ _lastActiveOut = 0;
+ }
+}
+
+void PcSpkDriver::updateNote() {
+ uint8 priority = 0;
+ _activeChannel = 0;
+ for (uint i = 0; i < 6; ++i) {
+ if (_channels[i]._allocated && _channels[i]._out.active && _channels[i]._priority >= priority) {
+ priority = _channels[i]._priority;
+ _activeChannel = &_channels[i];
+ }
+ }
+
+ if (_activeChannel == 0 || _activeChannel->_tl == 0) {
+ _pcSpk.stop();
+ _lastActiveChannel = 0;
+ _lastActiveOut = 0;
+ } else {
+ output(_activeChannel->_pitchBend + (_activeChannel->_out.note << 7));
+ }
+}
+
+void PcSpkDriver::output(uint16 out) {
+ byte v1 = (out >> 7) & 0xFF;
+ byte v2 = (out >> 2) & 0x1E;
+
+ byte shift = _outputTable1[v1];
+ uint16 indexBase = _outputTable2[v1] << 5;
+ uint16 frequency = _frequencyTable[(indexBase + v2) / 2] >> shift;
+
+ // Only output in case the active channel changed or the frequency changed.
+ // This is not faithful to the original. Since our timings differ we would
+ // get distorted sound otherwise though.
+ if (_lastActiveChannel != _activeChannel || _lastActiveOut != out) {
+ _pcSpk.play(Audio::PCSpeaker::kWaveFormSquare, 1193180 / frequency, -1);
+ _lastActiveChannel = _activeChannel;
+ _lastActiveOut = out;
+ }
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::init(PcSpkDriver *owner, byte channel) {
+ _owner = owner;
+ _channel = channel;
+ _allocated = false;
+ memset(&_out, 0, sizeof(_out));
+}
+
+bool PcSpkDriver::MidiChannel_PcSpk::allocate() {
+ if (_allocated)
+ return false;
+
+ memset(&_out, 0, sizeof(_out));
+ memset(_instrument, 0, sizeof(_instrument));
+ _out.effectDefA.envelope = &_out.effectEnvelopeA;
+ _out.effectDefB.envelope = &_out.effectEnvelopeB;
+
+ _allocated = true;
+ return true;
+}
+
+MidiDriver *PcSpkDriver::MidiChannel_PcSpk::device() {
+ return _owner;
+}
+
+byte PcSpkDriver::MidiChannel_PcSpk::getNumber() {
+ return _channel;
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::release() {
+ _out.active = 0;
+ _allocated = false;
+ _owner->updateNote();
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::send(uint32 b) {
+ uint8 type = b & 0xF0;
+ uint8 p1 = (b >> 8) & 0xFF;
+ uint8 p2 = (b >> 16) & 0xFF;
+
+ switch (type) {
+ case 0x80:
+ noteOff(p1);
+ break;
+
+ case 0x90:
+ if (p2)
+ noteOn(p1, p2);
+ else
+ noteOff(p1);
+ break;
+
+ case 0xB0:
+ controlChange(p1, p2);
+ break;
+
+ case 0xE0:
+ pitchBend((p1 | (p2 << 7)) - 0x2000);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::noteOff(byte note) {
+ if (!_allocated)
+ return;
+
+ if (_sustain) {
+ if (_out.note == note)
+ _out.sustainNoteOff = 1;
+ } else {
+ if (_out.note == note) {
+ _out.active = 0;
+ _owner->updateNote();
+ }
+ }
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::noteOn(byte note, byte velocity) {
+ if (!_allocated)
+ return;
+
+ _out.note = note;
+ _out.sustainNoteOff = 0;
+ _out.length = _instrument[0];
+
+ if (_instrument[4] * 256 < ARRAYSIZE(PcSpkDriver::_outInstrumentData))
+ _out.instrument = _owner->_outInstrumentData + _instrument[4] * 256;
+ else
+ _out.instrument = 0;
+
+ _out.unkA = 0;
+ _out.unkB = _instrument[1];
+ _out.unkC = _instrument[2];
+ _out.unkE = 0;
+ _out.unk60 = 0;
+ _out.active = 1;
+
+ // In case we get a note on event on the last active channel, we reset the
+ // last active channel, thus we assure the frequency is correctly set, even
+ // when the same note was sent.
+ if (_owner->_lastActiveChannel == this) {
+ _owner->_lastActiveChannel = 0;
+ _owner->_lastActiveOut = 0;
+ }
+ _owner->updateNote();
+
+ _out.unkC += PcSpkDriver::getEffectModifier(_instrument[3] + ((velocity & 0xFE) << 4));
+ if (_out.unkC > 63)
+ _out.unkC = 63;
+
+ if ((_instrument[5] & 0x80) != 0)
+ _owner->setupEffects(*this, _out.effectEnvelopeA, _out.effectDefA, _instrument[5], _instrument + 6);
+
+ if ((_instrument[14] & 0x80) != 0)
+ _owner->setupEffects(*this, _out.effectEnvelopeB, _out.effectDefB, _instrument[14], _instrument + 15);
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::programChange(byte program) {
+ // Nothing to implement here, the iMuse code takes care of passing us the
+ // instrument data.
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::pitchBend(int16 bend) {
+ _pitchBend = (bend * _pitchBendFactor) >> 6;
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::controlChange(byte control, byte value) {
+ switch (control) {
+ case 1:
+ if (_out.effectEnvelopeA.state && _out.effectDefA.useModWheel)
+ _out.effectEnvelopeA.modWheelState = (value >> 2);
+ if (_out.effectEnvelopeB.state && _out.effectDefB.useModWheel)
+ _out.effectEnvelopeB.modWheelState = (value >> 2);
+ break;
+
+ case 7:
+ _tl = value;
+ if (_owner->_activeChannel == this) {
+ if (_tl == 0) {
+ _owner->_lastActiveChannel = 0;
+ _owner->_lastActiveOut = 0;
+ _owner->_pcSpk.stop();
+ } else {
+ _owner->output((_out.note << 7) + _pitchBend + _out.unk60 + _out.unkE);
+ }
+ }
+ break;
+
+ case 64:
+ _sustain = value;
+ if (!value && _out.sustainNoteOff) {
+ _out.active = 0;
+ _owner->updateNote();
+ }
+ break;
+
+ case 123:
+ _out.active = 0;
+ _owner->updateNote();
+ break;
+
+ default:
+ break;
+ }
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::pitchBendFactor(byte value) {
+ _pitchBendFactor = value;
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::priority(byte value) {
+ _priority = value;
+}
+
+void PcSpkDriver::MidiChannel_PcSpk::sysEx_customInstrument(uint32 type, const byte *instr) {
+ memcpy(_instrument, instr, sizeof(_instrument));
+}
+
+uint8 PcSpkDriver::getEffectModifier(uint16 level) {
+ uint8 base = level / 32;
+ uint8 index = level % 32;
+
+ if (index == 0)
+ return 0;
+
+ return (base * (index + 1)) >> 5;
+}
+
+int16 PcSpkDriver::getEffectModLevel(int16 level, int8 mod) {
+ if (!mod) {
+ return 0;
+ } else if (mod == 31) {
+ return level;
+ } else if (level < -63 || level > 63) {
+ return (mod * (level + 1)) >> 6;
+ } else if (mod < 0) {
+ if (level < 0)
+ return getEffectModifier(((-level) << 5) - mod);
+ else
+ return -getEffectModifier((level << 5) - mod);
+ } else {
+ if (level < 0)
+ return -getEffectModifier(((-level) << 5) + mod);
+ else
+ return getEffectModifier(((-level) << 5) + mod);
+ }
+}
+
+int16 PcSpkDriver::getRandScale(int16 input) {
+ if (_randBase & 1)
+ _randBase = (_randBase >> 1) ^ 0xB8;
+ else
+ _randBase >>= 1;
+
+ return (_randBase * input) >> 8;
+}
+
+void PcSpkDriver::setupEffects(MidiChannel_PcSpk &chan, EffectEnvelope &env, EffectDefinition &def, byte flags, const byte *data) {
+ def.phase = 0;
+ def.useModWheel = flags & 0x40;
+ env.loop = flags & 0x20;
+ def.type = flags & 0x1F;
+
+ env.modWheelSensitivity = 31;
+ if (def.useModWheel)
+ env.modWheelState = chan._modWheel >> 2;
+ else
+ env.modWheelState = 31;
+
+ switch (def.type) {
+ case 0:
+ env.maxLevel = 767;
+ env.startLevel = 383;
+ break;
+
+ case 1:
+ env.maxLevel = 31;
+ env.startLevel = 15;
+ break;
+
+ case 2:
+ env.maxLevel = 63;
+ env.startLevel = chan._out.unkB;
+ break;
+
+ case 3:
+ env.maxLevel = 63;
+ env.startLevel = chan._out.unkC;
+ break;
+
+ case 4:
+ env.maxLevel = 3;
+ env.startLevel = chan._instrument[4];
+ break;
+
+ case 5:
+ env.maxLevel = 62;
+ env.startLevel = 31;
+ env.modWheelState = 0;
+ break;
+
+ case 6:
+ env.maxLevel = 31;
+ env.startLevel = 0;
+ env.modWheelSensitivity = 0;
+ break;
+
+ default:
+ break;
+ }
+
+ startEffect(env, data);
+}
+
+void PcSpkDriver::startEffect(EffectEnvelope &env, const byte *data) {
+ env.state = 1;
+ env.currentLevel = 0;
+ env.modWheelLast = 31;
+ env.duration = data[0] * 63;
+
+ env.stateTargetLevels[0] = data[1];
+ env.stateTargetLevels[1] = data[3];
+ env.stateTargetLevels[2] = data[5];
+ env.stateTargetLevels[3] = data[6];
+
+ env.stateModWheelLevels[0] = data[2];
+ env.stateModWheelLevels[1] = data[4];
+ env.stateModWheelLevels[2] = 0;
+ env.stateModWheelLevels[3] = data[7];
+
+ initNextEnvelopeState(env);
+}
+
+void PcSpkDriver::initNextEnvelopeState(EffectEnvelope &env) {
+ uint8 lastState = env.state - 1;
+
+ uint16 stepCount = _effectEnvStepTable[getEffectModifier(((env.stateTargetLevels[lastState] & 0x7F) << 5) + env.modWheelSensitivity)];
+ if (env.stateTargetLevels[lastState] & 0x80)
+ stepCount = getRandScale(stepCount);
+ if (!stepCount)
+ stepCount = 1;
+
+ env.stateNumSteps = env.stateStepCounter = stepCount;
+
+ int16 totalChange = 0;
+ if (lastState != 2) {
+ totalChange = getEffectModLevel(env.maxLevel, (env.stateModWheelLevels[lastState] & 0x7F) - 31);
+ if (env.stateModWheelLevels[lastState] & 0x80)
+ totalChange = getRandScale(totalChange);
+
+ if (totalChange + env.startLevel > env.maxLevel)
+ totalChange = env.maxLevel - env.startLevel;
+ else if (totalChange + env.startLevel < 0)
+ totalChange = -env.startLevel;
+
+ totalChange -= env.currentLevel;
+ }
+
+ env.changePerStep = totalChange / stepCount;
+ if (totalChange < 0) {
+ totalChange = -totalChange;
+ env.dir = -1;
+ } else {
+ env.dir = 1;
+ }
+ env.changePerStepRem = totalChange % stepCount;
+ env.changeCountRem = 0;
+}
+
+void PcSpkDriver::updateEffectGenerator(MidiChannel_PcSpk &chan, EffectEnvelope &env, EffectDefinition &def) {
+ if (advanceEffectEnvelope(env, def) & 1) {
+ switch (def.type) {
+ case 0: case 1:
+ chan._out.unk60 = def.phase << 4;
+ break;
+
+ case 2:
+ chan._out.unkB = (def.phase & 0xFF) + chan._instrument[1];
+ break;
+
+ case 3:
+ chan._out.unkC = (def.phase & 0xFF) + chan._instrument[2];
+ break;
+
+ case 4:
+ if ((chan._instrument[4] + (def.phase & 0xFF)) * 256 < ARRAYSIZE(_outInstrumentData))
+ chan._out.instrument = _outInstrumentData + (chan._instrument[4] + (def.phase & 0xFF)) * 256;
+ else
+ chan._out.instrument = 0;
+ break;
+
+ case 5:
+ env.modWheelState = (def.phase & 0xFF);
+ break;
+
+ case 6:
+ env.modWheelSensitivity = (def.phase & 0xFF);
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+uint8 PcSpkDriver::advanceEffectEnvelope(EffectEnvelope &env, EffectDefinition &def) {
+ if (env.duration != 0) {
+ env.duration -= 17;
+ if (env.duration <= 0) {
+ env.state = 0;
+ return 0;
+ }
+ }
+
+ uint8 changedFlags = 0;
+ int16 newLevel = env.currentLevel + env.changePerStep;
+ env.changeCountRem += env.changePerStepRem;
+ if (env.changeCountRem >= env.stateNumSteps) {
+ env.changeCountRem -= env.stateNumSteps;
+ newLevel += env.dir;
+ }
+
+ if (env.currentLevel != newLevel || env.modWheelLast != env.modWheelState) {
+ env.currentLevel = newLevel;
+ env.modWheelLast = env.modWheelState;
+
+ int16 newPhase = getEffectModLevel(newLevel, env.modWheelState);
+ if (def.phase != newPhase) {
+ changedFlags |= 1;
+ def.phase = newPhase;
+ }
+ }
+
+ --env.stateStepCounter;
+ if (!env.stateStepCounter) {
+ ++env.state;
+ if (env.state > 4) {
+ if (env.loop) {
+ env.state = 1;
+ changedFlags |= 2;
+ } else {
+ env.state = 0;
+ return changedFlags;
+ }
+ }
+
+ initNextEnvelopeState(env);
+ }
+
+ return changedFlags;
+}
+
+const byte PcSpkDriver::_outInstrumentData[1024] = {
+ 0x00, 0x03, 0x06, 0x09, 0x0C, 0x0F, 0x12, 0x15,
+ 0x18, 0x1B, 0x1E, 0x21, 0x24, 0x27, 0x2A, 0x2D,
+ 0x30, 0x33, 0x36, 0x39, 0x3B, 0x3E, 0x41, 0x43,
+ 0x46, 0x49, 0x4B, 0x4E, 0x50, 0x52, 0x55, 0x57,
+ 0x59, 0x5B, 0x5E, 0x60, 0x62, 0x64, 0x66, 0x67,
+ 0x69, 0x6B, 0x6C, 0x6E, 0x70, 0x71, 0x72, 0x74,
+ 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7B,
+ 0x7C, 0x7D, 0x7D, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E,
+ 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7D, 0x7D,
+ 0x7C, 0x7B, 0x7B, 0x7A, 0x79, 0x78, 0x77, 0x76,
+ 0x75, 0x74, 0x72, 0x71, 0x70, 0x6E, 0x6C, 0x6B,
+ 0x69, 0x67, 0x66, 0x64, 0x62, 0x60, 0x5E, 0x5B,
+ 0x59, 0x57, 0x55, 0x52, 0x50, 0x4E, 0x4B, 0x49,
+ 0x46, 0x43, 0x41, 0x3E, 0x3B, 0x39, 0x36, 0x33,
+ 0x30, 0x2D, 0x2A, 0x27, 0x24, 0x21, 0x1E, 0x1B,
+ 0x18, 0x15, 0x12, 0x0F, 0x0C, 0x09, 0x06, 0x03,
+ 0x00, 0xFD, 0xFA, 0xF7, 0xF4, 0xF1, 0xEE, 0xEB,
+ 0xE8, 0xE5, 0xE2, 0xDF, 0xDC, 0xD9, 0xD6, 0xD3,
+ 0xD0, 0xCD, 0xCA, 0xC7, 0xC5, 0xC2, 0xBF, 0xBD,
+ 0xBA, 0xB7, 0xB5, 0xB2, 0xB0, 0xAE, 0xAB, 0xA9,
+ 0xA7, 0xA5, 0xA2, 0xA0, 0x9E, 0x9C, 0x9A, 0x99,
+ 0x97, 0x95, 0x94, 0x92, 0x90, 0x8F, 0x8E, 0x8C,
+ 0x8B, 0x8A, 0x89, 0x88, 0x87, 0x86, 0x85, 0x85,
+ 0x84, 0x83, 0x83, 0x82, 0x82, 0x82, 0x82, 0x82,
+ 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x83, 0x83,
+ 0x84, 0x85, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A,
+ 0x8B, 0x8C, 0x8E, 0x8F, 0x90, 0x92, 0x94, 0x95,
+ 0x97, 0x99, 0x9A, 0x9C, 0x9E, 0xA0, 0xA2, 0xA5,
+ 0xA7, 0xA9, 0xAB, 0xAE, 0xB0, 0xB2, 0xB5, 0xB7,
+ 0xBA, 0xBD, 0xBF, 0xC2, 0xC5, 0xC7, 0xCA, 0xCD,
+ 0xD0, 0xD3, 0xD6, 0xD9, 0xDC, 0xDF, 0xE2, 0xE5,
+ 0xE8, 0xEB, 0xEE, 0xF1, 0xF4, 0xF7, 0xFA, 0xFD,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
+ 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
+ 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
+ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
+ 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
+ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
+ 0x29, 0x23, 0xBE, 0x84, 0xE1, 0x6C, 0xD6, 0xAE,
+ 0x52, 0x90, 0x49, 0xF1, 0xF1, 0xBB, 0xE9, 0xEB,
+ 0xB3, 0xA6, 0xDB, 0x3C, 0x87, 0x0C, 0x3E, 0x99,
+ 0x24, 0x5E, 0x0D, 0x1C, 0x06, 0xB7, 0x47, 0xDE,
+ 0xB3, 0x12, 0x4D, 0xC8, 0x43, 0xBB, 0x8B, 0xA6,
+ 0x1F, 0x03, 0x5A, 0x7D, 0x09, 0x38, 0x25, 0x1F,
+ 0x5D, 0xD4, 0xCB, 0xFC, 0x96, 0xF5, 0x45, 0x3B,
+ 0x13, 0x0D, 0x89, 0x0A, 0x1C, 0xDB, 0xAE, 0x32,
+ 0x20, 0x9A, 0x50, 0xEE, 0x40, 0x78, 0x36, 0xFD,
+ 0x12, 0x49, 0x32, 0xF6, 0x9E, 0x7D, 0x49, 0xDC,
+ 0xAD, 0x4F, 0x14, 0xF2, 0x44, 0x40, 0x66, 0xD0,
+ 0x6B, 0xC4, 0x30, 0xB7, 0x32, 0x3B, 0xA1, 0x22,
+ 0xF6, 0x22, 0x91, 0x9D, 0xE1, 0x8B, 0x1F, 0xDA,
+ 0xB0, 0xCA, 0x99, 0x02, 0xB9, 0x72, 0x9D, 0x49,
+ 0x2C, 0x80, 0x7E, 0xC5, 0x99, 0xD5, 0xE9, 0x80,
+ 0xB2, 0xEA, 0xC9, 0xCC, 0x53, 0xBF, 0x67, 0xD6,
+ 0xBF, 0x14, 0xD6, 0x7E, 0x2D, 0xDC, 0x8E, 0x66,
+ 0x83, 0xEF, 0x57, 0x49, 0x61, 0xFF, 0x69, 0x8F,
+ 0x61, 0xCD, 0xD1, 0x1E, 0x9D, 0x9C, 0x16, 0x72,
+ 0x72, 0xE6, 0x1D, 0xF0, 0x84, 0x4F, 0x4A, 0x77,
+ 0x02, 0xD7, 0xE8, 0x39, 0x2C, 0x53, 0xCB, 0xC9,
+ 0x12, 0x1E, 0x33, 0x74, 0x9E, 0x0C, 0xF4, 0xD5,
+ 0xD4, 0x9F, 0xD4, 0xA4, 0x59, 0x7E, 0x35, 0xCF,
+ 0x32, 0x22, 0xF4, 0xCC, 0xCF, 0xD3, 0x90, 0x2D,
+ 0x48, 0xD3, 0x8F, 0x75, 0xE6, 0xD9, 0x1D, 0x2A,
+ 0xE5, 0xC0, 0xF7, 0x2B, 0x78, 0x81, 0x87, 0x44,
+ 0x0E, 0x5F, 0x50, 0x00, 0xD4, 0x61, 0x8D, 0xBE,
+ 0x7B, 0x05, 0x15, 0x07, 0x3B, 0x33, 0x82, 0x1F,
+ 0x18, 0x70, 0x92, 0xDA, 0x64, 0x54, 0xCE, 0xB1,
+ 0x85, 0x3E, 0x69, 0x15, 0xF8, 0x46, 0x6A, 0x04,
+ 0x96, 0x73, 0x0E, 0xD9, 0x16, 0x2F, 0x67, 0x68,
+ 0xD4, 0xF7, 0x4A, 0x4A, 0xD0, 0x57, 0x68, 0x76
+};
+
+const byte PcSpkDriver::_outputTable1[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5,
+ 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7
+};
+
+const byte PcSpkDriver::_outputTable2[] = {
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11,
+ 0, 1, 2, 3,
+ 4, 5, 6, 7
+};
+
+const uint16 PcSpkDriver::_effectEnvStepTable[] = {
+ 1, 2, 4, 5,
+ 6, 7, 8, 9,
+ 10, 12, 14, 16,
+ 18, 21, 24, 30,
+ 36, 50, 64, 82,
+ 100, 136, 160, 192,
+ 240, 276, 340, 460,
+ 600, 860, 1200, 1600
+};
+
+const uint16 PcSpkDriver::_frequencyTable[] = {
+ 0x8E84, 0x8E00, 0x8D7D, 0x8CFA,
+ 0x8C78, 0x8BF7, 0x8B76, 0x8AF5,
+ 0x8A75, 0x89F5, 0x8976, 0x88F7,
+ 0x8879, 0x87FB, 0x877D, 0x8700,
+ 0x8684, 0x8608, 0x858C, 0x8511,
+ 0x8496, 0x841C, 0x83A2, 0x8328,
+ 0x82AF, 0x8237, 0x81BF, 0x8147,
+ 0x80D0, 0x8059, 0x7FE3, 0x7F6D,
+ 0x7EF7, 0x7E82, 0x7E0D, 0x7D99,
+ 0x7D25, 0x7CB2, 0x7C3F, 0x7BCC,
+ 0x7B5A, 0x7AE8, 0x7A77, 0x7A06,
+ 0x7995, 0x7925, 0x78B5, 0x7846,
+ 0x77D7, 0x7768, 0x76FA, 0x768C,
+ 0x761F, 0x75B2, 0x7545, 0x74D9,
+ 0x746D, 0x7402, 0x7397, 0x732C,
+ 0x72C2, 0x7258, 0x71EF, 0x7186,
+ 0x711D, 0x70B5, 0x704D, 0x6FE5,
+ 0x6F7E, 0x6F17, 0x6EB0, 0x6E4A,
+ 0x6DE5, 0x6D7F, 0x6D1A, 0x6CB5,
+ 0x6C51, 0x6BED, 0x6B8A, 0x6B26,
+ 0x6AC4, 0x6A61, 0x69FF, 0x699D,
+ 0x693C, 0x68DB, 0x687A, 0x681A,
+ 0x67BA, 0x675A, 0x66FA, 0x669B,
+ 0x663D, 0x65DF, 0x6581, 0x6523,
+ 0x64C6, 0x6469, 0x640C, 0x63B0,
+ 0x6354, 0x62F8, 0x629D, 0x6242,
+ 0x61E7, 0x618D, 0x6133, 0x60D9,
+ 0x6080, 0x6027, 0x5FCE, 0x5F76,
+ 0x5F1E, 0x5EC6, 0x5E6E, 0x5E17,
+ 0x5DC1, 0x5D6A, 0x5D14, 0x5CBE,
+ 0x5C68, 0x5C13, 0x5BBE, 0x5B6A,
+ 0x5B15, 0x5AC1, 0x5A6E, 0x5A1A,
+ 0x59C7, 0x5974, 0x5922, 0x58CF,
+ 0x587D, 0x582C, 0x57DA, 0x5789,
+ 0x5739, 0x56E8, 0x5698, 0x5648,
+ 0x55F9, 0x55A9, 0x555A, 0x550B,
+ 0x54BD, 0x546F, 0x5421, 0x53D3,
+ 0x5386, 0x5339, 0x52EC, 0x52A0,
+ 0x5253, 0x5207, 0x51BC, 0x5170,
+ 0x5125, 0x50DA, 0x5090, 0x5046,
+ 0x4FFB, 0x4FB2, 0x4F68, 0x4F1F,
+ 0x4ED6, 0x4E8D, 0x4E45, 0x4DFC,
+ 0x4DB5, 0x4D6D, 0x4D25, 0x4CDE,
+ 0x4C97, 0x4C51, 0x4C0A, 0x4BC4,
+ 0x4B7E, 0x4B39, 0x4AF3, 0x4AAE,
+ 0x4A69, 0x4A24, 0x49E0, 0x499C,
+ 0x4958, 0x4914, 0x48D1, 0x488E,
+ 0x484B, 0x4808, 0x47C6, 0x4783
+};
+
+} // End of namespace Scumm
diff --git a/engines/scumm/imuse/pcspk.h b/engines/scumm/imuse/pcspk.h
new file mode 100644
index 0000000000..195bd34b07
--- /dev/null
+++ b/engines/scumm/imuse/pcspk.h
@@ -0,0 +1,160 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCUMM_IMUSE_PCSPK_H
+#define SCUMM_IMUSE_PCSPK_H
+
+#include "audio/softsynth/emumidi.h"
+#include "audio/softsynth/pcspk.h"
+
+namespace Scumm {
+
+class PcSpkDriver : public MidiDriver_Emulated {
+public:
+ PcSpkDriver(Audio::Mixer *mixer);
+ ~PcSpkDriver();
+
+ virtual int open();
+ virtual void close();
+
+ virtual void send(uint32 d);
+ virtual void sysEx_customInstrument(byte channel, uint32 type, const byte *instr);
+
+ virtual MidiChannel *allocateChannel();
+ virtual MidiChannel *getPercussionChannel() { return 0; }
+
+ bool isStereo() const { return _pcSpk.isStereo(); }
+ int getRate() const { return _pcSpk.getRate(); }
+protected:
+ void generateSamples(int16 *buf, int len);
+ void onTimer();
+
+private:
+ Audio::PCSpeaker _pcSpk;
+ int _effectTimer;
+ uint8 _randBase;
+
+ void updateNote();
+ void output(uint16 out);
+
+ static uint8 getEffectModifier(uint16 level);
+ int16 getEffectModLevel(int16 level, int8 mod);
+ int16 getRandScale(int16 input);
+
+ struct EffectEnvelope {
+ uint8 state;
+ int16 currentLevel;
+ int16 duration;
+ int16 maxLevel;
+ int16 startLevel;
+ uint8 loop;
+ uint8 stateTargetLevels[4];
+ uint8 stateModWheelLevels[4];
+ uint8 modWheelSensitivity;
+ uint8 modWheelState;
+ uint8 modWheelLast;
+ int16 stateNumSteps;
+ int16 stateStepCounter;
+ int16 changePerStep;
+ int8 dir;
+ int16 changePerStepRem;
+ int16 changeCountRem;
+ };
+
+ struct EffectDefinition {
+ int16 phase;
+ uint8 type;
+ uint8 useModWheel;
+ EffectEnvelope *envelope;
+ };
+
+ struct OutputChannel {
+ uint8 active;
+ uint8 note;
+ uint8 sustainNoteOff;
+ uint8 length;
+ const uint8 *instrument;
+ uint8 unkA;
+ uint8 unkB;
+ uint8 unkC;
+ int16 unkE;
+ EffectEnvelope effectEnvelopeA;
+ EffectDefinition effectDefA;
+ EffectEnvelope effectEnvelopeB;
+ EffectDefinition effectDefB;
+ int16 unk60;
+ };
+
+ struct MidiChannel_PcSpk : public MidiChannel {
+ virtual MidiDriver *device();
+ virtual byte getNumber();
+ virtual void release();
+
+ virtual void send(uint32 b);
+ virtual void noteOff(byte note);
+ virtual void noteOn(byte note, byte velocity);
+ virtual void programChange(byte program);
+ virtual void pitchBend(int16 bend);
+ virtual void controlChange(byte control, byte value);
+ virtual void pitchBendFactor(byte value);
+ virtual void priority(byte value);
+ virtual void sysEx_customInstrument(uint32 type, const byte *instr);
+
+ void init(PcSpkDriver *owner, byte channel);
+ bool allocate();
+
+ PcSpkDriver *_owner;
+ bool _allocated;
+ byte _channel;
+
+ OutputChannel _out;
+ uint8 _instrument[23];
+ uint8 _programNr;
+ uint8 _priority;
+ uint8 _tl;
+ uint8 _modWheel;
+ uint8 _sustain;
+ uint8 _pitchBendFactor;
+ int16 _pitchBend;
+ };
+
+ void setupEffects(MidiChannel_PcSpk &chan, EffectEnvelope &env, EffectDefinition &def, byte flags, const byte *data);
+ void startEffect(EffectEnvelope &env, const byte *data);
+ void initNextEnvelopeState(EffectEnvelope &env);
+ void updateEffectGenerator(MidiChannel_PcSpk &chan, EffectEnvelope &env, EffectDefinition &def);
+ uint8 advanceEffectEnvelope(EffectEnvelope &env, EffectDefinition &def);
+
+ MidiChannel_PcSpk _channels[6];
+ MidiChannel_PcSpk *_activeChannel;
+
+ MidiChannel_PcSpk *_lastActiveChannel;
+ uint16 _lastActiveOut;
+
+ static const byte _outInstrumentData[1024];
+ static const byte _outputTable1[];
+ static const byte _outputTable2[];
+ static const uint16 _effectEnvStepTable[];
+ static const uint16 _frequencyTable[];
+};
+
+} // End of namespace Scumm
+
+#endif
diff --git a/engines/scumm/imuse/sysex.h b/engines/scumm/imuse/sysex.h
index 7dd38e785e..06ac483afd 100644
--- a/engines/scumm/imuse/sysex.h
+++ b/engines/scumm/imuse/sysex.h
@@ -35,4 +35,3 @@ extern void sysexHandler_SamNMax(Player *, const byte *, uint16);
} // End of namespace Scumm
#endif
-
diff --git a/engines/scumm/imuse/sysex_samnmax.cpp b/engines/scumm/imuse/sysex_samnmax.cpp
index 4c4219e7bb..a4f525da56 100644
--- a/engines/scumm/imuse/sysex_samnmax.cpp
+++ b/engines/scumm/imuse/sysex_samnmax.cpp
@@ -53,8 +53,7 @@ void sysexHandler_SamNMax(Player *player, const byte *msg, uint16 len) {
// something magical is supposed to happen....
for (a = 0; a < ARRAYSIZE(se->_snm_triggers); ++a) {
if (se->_snm_triggers[a].sound == player->_id &&
- se->_snm_triggers[a].id == *p)
- {
+ se->_snm_triggers[a].id == *p) {
se->_snm_triggers[a].sound = se->_snm_triggers[a].id = 0;
se->doCommand(8, se->_snm_triggers[a].command);
break;
diff --git a/engines/scumm/imuse/sysex_scumm.cpp b/engines/scumm/imuse/sysex_scumm.cpp
index c3bec93a60..85ffc86f47 100644
--- a/engines/scumm/imuse/sysex_scumm.cpp
+++ b/engines/scumm/imuse/sysex_scumm.cpp
@@ -49,50 +49,52 @@ void sysexHandler_Scumm(Player *player, const byte *msg, uint16 len) {
switch (code = *p++) {
case 0:
// Allocate new part.
- // There are 17 bytes of useful information here.
+ // There are 8 bytes (after decoding!) of useful information here.
// Here is what we know about them so far:
- // BYTE 00: Channel #
- // BYTE 02: BIT 01(0x01): Part on?(1 = yes)
+ // BYTE 0: Channel #
+ // BYTE 1: BIT 01(0x01): Part on?(1 = yes)
// BIT 02(0x02): Reverb? (1 = yes) [bug #1088045]
- // BYTE 04: Priority adjustment [guessing]
- // BYTE 05: Volume(upper 4 bits) [guessing]
- // BYTE 06: Volume(lower 4 bits) [guessing]
- // BYTE 07: Pan(upper 4 bits) [bug #1088045]
- // BYTE 08: Pan(lower 4 bits) [bug #1088045]
- // BYTE 09: BIT 04(0x08): Percussion?(1 = yes)
- // BYTE 13: Pitchbend range(upper 4 bits) [bug #1088045]
- // BYTE 14: Pitchbend range(lower 4 bits) [bug #1088045]
- // BYTE 15: Program(upper 4 bits)
- // BYTE 16: Program(lower 4 bits)
-
- // athrxx (05-21-2011):
- // BYTE 9, 10: Transpose (if set to 0x80, this means that part->_transpose_eff will be 0 (also ignoring player->_transpose)
- // BYTE 11, 12: Detune
+ // BYTE 2: Priority adjustment
+ // BYTE 3: Volume [guessing]
+ // BYTE 4: Pan [bug #1088045]
+ // BYTE 5: BIT 8(0x80): Percussion?(1 = yes) [guessed?]
+ // BYTE 5: Transpose, if set to 0x80(=-1) it means no transpose
+ // BYTE 6: Detune
+ // BYTE 7: Pitchbend factor [bug #1088045]
+ // BYTE 8: Program
part = player->getPart(p[0] & 0x0F);
+ player->decode_sysex_bytes(p + 1, buf + 1, len - 1);
if (part) {
- part->set_onoff(p[2] & 0x01);
- part->effectLevel((p[2] & 0x02) ? 127 : 0);
- part->set_pri(p[4]);
- part->volume((p[5] & 0x0F) << 4 |(p[6] & 0x0F));
- part->set_pan((p[7] & 0x0F) << 4 | (p[8] & 0x0F));
- part->_percussion = player->_isMIDI ? ((p[9] & 0x08) > 0) : false;
- part->set_transpose((p[9] & 0x0F) << 4 | (p[10] & 0x0F));
- part->set_detune((p[11] & 0x0F) << 4 | (p[12] & 0x0F));
- part->pitchBendFactor((p[13] & 0x0F) << 4 | (p[14] & 0x0F));
+ part->set_onoff(buf[1] & 0x01);
+ part->effectLevel((buf[1] & 0x02) ? 127 : 0);
+ part->set_pri(buf[2]);
+ part->volume(buf[3]);
+ part->set_pan(buf[4]);
+ part->_percussion = player->_isMIDI ? ((buf[5] & 0x80) > 0) : false;
+ part->set_transpose(buf[5]);
+ part->set_detune(buf[6]);
+ part->pitchBendFactor(buf[7]);
if (part->_percussion) {
if (part->_mc) {
part->off();
se->reallocateMidiChannels(player->_midi);
}
} else {
- // Even in cases where a program does not seem to be specified,
- // i.e. bytes 15 and 16 are 0, we send a program change because
- // 0 is a valid program number. MI2 tests show that in such
- // cases, a regular program change message always seems to follow
- // anyway.
- if (player->_isMIDI)
- part->_instrument.program((p[15] & 0x0F) << 4 |(p[16] & 0x0F), player->_isMT32);
+ if (player->_isMIDI) {
+ // Even in cases where a program does not seem to be specified,
+ // i.e. bytes 15 and 16 are 0, we send a program change because
+ // 0 is a valid program number. MI2 tests show that in such
+ // cases, a regular program change message always seems to follow
+ // anyway.
+ part->_instrument.program(buf[8], player->_isMT32);
+ } else {
+ // Like the original we set up the instrument data of the
+ // specified program here too. In case the global
+ // instrument data is not loaded already, this will take
+ // care of setting a default instrument too.
+ se->copyGlobalInstrument(buf[8], &part->_instrument);
+ }
part->sendAll();
}
}
@@ -113,11 +115,10 @@ void sysexHandler_Scumm(Player *player, const byte *msg, uint16 len) {
++p; // Skip hardware type
part = player->getPart(a);
if (part) {
- if (len == 62) {
+ if (len == 62 || len == 48) {
player->decode_sysex_bytes(p, buf, len - 2);
part->set_instrument((byte *)buf);
} else {
- // SPK tracks have len == 48 here, and are not supported
part->programChange(254); // Must be invalid, but not 255 (which is reserved)
}
}
@@ -127,7 +128,8 @@ void sysexHandler_Scumm(Player *player, const byte *msg, uint16 len) {
p += 2; // Skip hardware type and... whatever came right before it
a = *p++;
player->decode_sysex_bytes(p, buf, len - 3);
- se->setGlobalAdLibInstrument(a, buf);
+ if (len == 63 || len == 49)
+ se->setGlobalInstrument(a, buf);
break;
case 33: // Parameter adjust
@@ -185,10 +187,9 @@ void sysexHandler_Scumm(Player *player, const byte *msg, uint16 len) {
case 80: // Loop
player->decode_sysex_bytes(p + 1, buf, len - 1);
- player->setLoop
- (READ_BE_UINT16(buf), READ_BE_UINT16(buf + 2),
- READ_BE_UINT16(buf + 4), READ_BE_UINT16(buf + 6),
- READ_BE_UINT16(buf + 8));
+ player->setLoop(READ_BE_UINT16(buf), READ_BE_UINT16(buf + 2),
+ READ_BE_UINT16(buf + 4), READ_BE_UINT16(buf + 6),
+ READ_BE_UINT16(buf + 8));
break;
case 81: // End loop
diff --git a/engines/scumm/imuse_digi/dimuse.cpp b/engines/scumm/imuse_digi/dimuse.cpp
index 23f57a01b9..eb3717494f 100644
--- a/engines/scumm/imuse_digi/dimuse.cpp
+++ b/engines/scumm/imuse_digi/dimuse.cpp
@@ -58,7 +58,7 @@ IMuseDigital::IMuseDigital(ScummEngine_v7 *scumm, Audio::Mixer *mixer, int fps)
memset(_track[l], 0, sizeof(Track));
_track[l]->trackId = l;
}
- _vm->getTimerManager()->installTimerProc(timer_handler, 1000000 / _callbackFps, this);
+ _vm->getTimerManager()->installTimerProc(timer_handler, 1000000 / _callbackFps, this, "IMuseDigital");
_audioNames = NULL;
_numAudioNames = 0;
diff --git a/engines/scumm/input.cpp b/engines/scumm/input.cpp
index 5eea7acc6b..6d9e1f3f72 100644
--- a/engines/scumm/input.cpp
+++ b/engines/scumm/input.cpp
@@ -324,7 +324,17 @@ void ScummEngine::processInput() {
VAR(VAR_LEFTBTN_HOLD) = (_leftBtnPressed & msDown) != 0;
VAR(VAR_RIGHTBTN_HOLD) = (_rightBtnPressed & msDown) != 0;
- if (_game.version >= 7) {
+ if (_game.heversion >= 72) {
+ // HE72 introduced a flag for whether or not this is a click
+ // or the player is continuing to hold the button down.
+ // 0x80 signifies that the button is continuing to be held down
+ // Backyard Soccer needs this in order to function
+ if (VAR(VAR_LEFTBTN_HOLD) && !(_leftBtnPressed & msClicked))
+ VAR(VAR_LEFTBTN_HOLD) |= 0x80;
+
+ if (VAR(VAR_RIGHTBTN_HOLD) && !(_rightBtnPressed & msClicked))
+ VAR(VAR_RIGHTBTN_HOLD) |= 0x80;
+ } else if (_game.version >= 7) {
VAR(VAR_LEFTBTN_DOWN) = (_leftBtnPressed & msClicked) != 0;
VAR(VAR_RIGHTBTN_DOWN) = (_rightBtnPressed & msClicked) != 0;
}
diff --git a/engines/scumm/insane/insane_enemy.cpp b/engines/scumm/insane/insane_enemy.cpp
index 68766ab72c..913f761f31 100644
--- a/engines/scumm/insane/insane_enemy.cpp
+++ b/engines/scumm/insane/insane_enemy.cpp
@@ -2779,4 +2779,3 @@ int32 Insane::actionEnemy() {
}
}
-
diff --git a/engines/scumm/insane/insane_iact.cpp b/engines/scumm/insane/insane_iact.cpp
index 3592d67c18..48c96b537c 100644
--- a/engines/scumm/insane/insane_iact.cpp
+++ b/engines/scumm/insane/insane_iact.cpp
@@ -520,4 +520,3 @@ void Insane::iactScene21(byte *renderBitmap, int32 codecparam, int32 setupsan12,
}
}
-
diff --git a/engines/scumm/insane/insane_scenes.cpp b/engines/scumm/insane/insane_scenes.cpp
index 841fedafe2..6db1cb5059 100644
--- a/engines/scumm/insane/insane_scenes.cpp
+++ b/engines/scumm/insane/insane_scenes.cpp
@@ -1506,4 +1506,3 @@ void Insane::postCaseMore(byte *renderBitmap, int32 codecparam, int32 setupsan12
}
}
-
diff --git a/engines/scumm/module.mk b/engines/scumm/module.mk
index 1a60564a9e..781ca30459 100644
--- a/engines/scumm/module.mk
+++ b/engines/scumm/module.mk
@@ -27,6 +27,7 @@ MODULE_OBJS := \
imuse/imuse_part.o \
imuse/imuse_player.o \
imuse/instrument.o \
+ imuse/pcspk.o \
imuse/sysex_samnmax.o \
imuse/sysex_scumm.o \
input.o \
@@ -123,7 +124,14 @@ MODULE_OBJS += \
he/script_v90he.o \
he/script_v100he.o \
he/sprite_he.o \
- he/wiz_he.o
+ he/wiz_he.o \
+ he/logic/baseball2001.o \
+ he/logic/basketball.o \
+ he/logic/football.o \
+ he/logic/funshop.o \
+ he/logic/moonbase.o \
+ he/logic/puttrace.o \
+ he/logic/soccer.o
endif
# This module can be built as a plugin
diff --git a/engines/scumm/palette.cpp b/engines/scumm/palette.cpp
index 51ba2195d7..30096000ce 100644
--- a/engines/scumm/palette.cpp
+++ b/engines/scumm/palette.cpp
@@ -544,6 +544,12 @@ void ScummEngine::palManipulateInit(int resID, int start, int end, int time) {
return;
#endif
+ // This function is actually a nullsub in Indy4 Amiga.
+ // It might very well be a nullsub in other Amiga games, but for now I
+ // limit this to Indy4 Amiga, since that is the only game I can check.
+ if (_game.platform == Common::kPlatformAmiga && _game.id == GID_INDY4)
+ return;
+
byte *string1 = getStringAddress(resID);
byte *string2 = getStringAddress(resID + 1);
byte *string3 = getStringAddress(resID + 2);
@@ -670,6 +676,12 @@ static inline uint colorWeight(int red, int green, int blue) {
}
void ScummEngine::setShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor, int start, int end) {
+ // This function is actually a nullsub in Indy4 Amiga.
+ // It might very well be a nullsub in other Amiga games, but for now I
+ // limit this to Indy4 Amiga, since that is the only game I can check.
+ if (_game.platform == Common::kPlatformAmiga && _game.id == GID_INDY4)
+ return;
+
const byte *basepal = getPalettePtr(_curPalIndex, _roomResource);
const byte *compareptr;
const byte *pal = basepal + start * 3;
diff --git a/engines/scumm/player_v2.h b/engines/scumm/player_v2.h
index 14a0b9c1e0..d932585b8e 100644
--- a/engines/scumm/player_v2.h
+++ b/engines/scumm/player_v2.h
@@ -46,10 +46,7 @@ public:
virtual int getSoundStatus(int sound) const;
// AudioStream API
- int readBuffer(int16 *buffer, const int numSamples);
- bool isStereo() const { return true; }
- bool endOfData() const { return false; }
- int getRate() const { return _sampleRate; }
+ virtual int readBuffer(int16 *buffer, const int numSamples);
protected:
unsigned int _update_step;
diff --git a/engines/scumm/player_v2base.h b/engines/scumm/player_v2base.h
index 2f048070ad..eb9ed941ca 100644
--- a/engines/scumm/player_v2base.h
+++ b/engines/scumm/player_v2base.h
@@ -86,9 +86,9 @@ public:
return numSamples;
}
*/
- bool isStereo() const { return true; }
- bool endOfData() const { return false; }
- int getRate() const { return _sampleRate; }
+ virtual bool isStereo() const { return true; }
+ virtual bool endOfData() const { return false; }
+ virtual int getRate() const { return _sampleRate; }
protected:
enum {
diff --git a/engines/scumm/player_v2cms.cpp b/engines/scumm/player_v2cms.cpp
index 21e7f193b5..d4b21774ed 100644
--- a/engines/scumm/player_v2cms.cpp
+++ b/engines/scumm/player_v2cms.cpp
@@ -28,162 +28,49 @@
namespace Scumm {
-#define PROCESS_ATTACK 1
-#define PROCESS_RELEASE 2
-#define PROCESS_SUSTAIN 3
-#define PROCESS_DECAY 4
-#define PROCESS_VIBRATO 5
-
-#define CMS_RATE 22050
-
-static const byte freqTable[] = {
- 3, 10, 17, 24, 31, 38, 45, 51,
- 58, 65, 71, 77, 83, 90, 96, 102,
- 107, 113, 119, 125, 130, 136, 141, 146,
- 151, 157, 162, 167, 172, 177, 181, 186,
- 191, 195, 200, 204, 209, 213, 217, 221,
- 226, 230, 234, 238, 242, 246, 249, 253
-};
-
-/*static const byte amplTable[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 %
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 10 %
- 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, // 20 %
- 0x10, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x20, // 30%
- 0x20, 0x20, 0x30, 0x30, 0x30, 0x30, 0x40, 0x40,
- 0x00, 0x00, 0x00, 0x10, 0x10, 0x20, 0x20, 0x20, // 40 %
- 0x30, 0x30, 0x40, 0x40, 0x40, 0x50, 0x50, 0x60,
- 0x00, 0x00, 0x10, 0x10, 0x20, 0x20, 0x30, 0x30, // 50%
- 0x40, 0x40, 0x50, 0x50, 0x60, 0x60, 0x70, 0x70,
- 0x00, 0x00, 0x10, 0x10, 0x20, 0x30, 0x30, 0x40, // 60 %
- 0x40, 0x50, 0x60, 0x60, 0x70, 0x70, 0x80, 0x90,
- 0x00, 0x00, 0x10, 0x20, 0x20, 0x30, 0x40, 0x40, // 70 %
- 0x50, 0x60, 0x70, 0x70, 0x80, 0x90, 0x90, 0xA0,
- 0x00, 0x00, 0x10, 0x20, 0x30, 0x40, 0x40, 0x50, // 80 %
- 0x60, 0x70, 0x80, 0x80, 0x90, 0xA0, 0xB0, 0xC0,
- 0x00, 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, // 90 %
- 0x70, 0x80, 0x90, 0x90, 0xA0, 0xB0, 0xC0, 0xD0,
- 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, // 100 %
- 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0
-};*/
-
-static const byte octaveTable[] = {
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03,
- 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07,
- 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0B,
- 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03,
- 0x01, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x07,
- 0x01, 0x08, 0x01, 0x09, 0x01, 0x0A, 0x01, 0x0B,
- 0x02, 0x00, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03,
- 0x02, 0x04, 0x02, 0x05, 0x02, 0x06, 0x02, 0x07,
- 0x02, 0x08, 0x02, 0x09, 0x02, 0x0A, 0x02, 0x0B,
- 0x03, 0x00, 0x03, 0x01, 0x03, 0x02, 0x03, 0x03,
- 0x03, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x07,
- 0x03, 0x08, 0x03, 0x09, 0x03, 0x0A, 0x03, 0x0B,
- 0x04, 0x00, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03,
- 0x04, 0x04, 0x04, 0x05, 0x04, 0x06, 0x04, 0x07,
- 0x04, 0x08, 0x04, 0x09, 0x04, 0x0A, 0x04, 0x0B,
- 0x05, 0x00, 0x05, 0x01, 0x05, 0x02, 0x05, 0x03,
- 0x05, 0x04, 0x05, 0x05, 0x05, 0x06, 0x05, 0x07,
- 0x05, 0x08, 0x05, 0x09, 0x05, 0x0A, 0x05, 0x0B,
- 0x06, 0x00, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03,
- 0x06, 0x04, 0x06, 0x05, 0x06, 0x06, 0x06, 0x07,
- 0x06, 0x08, 0x06, 0x09, 0x06, 0x0A, 0x06, 0x0B,
- 0x07, 0x00, 0x07, 0x01, 0x07, 0x02, 0x07, 0x03,
- 0x07, 0x04, 0x07, 0x05, 0x07, 0x06, 0x07, 0x07,
- 0x07, 0x08, 0x07, 0x09, 0x07, 0x0A, 0x07, 0x0B,
- 0x08, 0x00, 0x08, 0x01, 0x08, 0x02, 0x08, 0x03,
- 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x08, 0x07,
- 0x08, 0x08, 0x08, 0x09, 0x08, 0x0A, 0x08, 0x0B,
- 0x09, 0x00, 0x09, 0x01, 0x09, 0x02, 0x09, 0x03,
- 0x09, 0x04, 0x09, 0x05, 0x09, 0x06, 0x09, 0x07,
- 0x09, 0x08, 0x09, 0x09, 0x09, 0x0A, 0x09, 0x0B,
- 0x0A, 0x00, 0x0A, 0x01, 0x0A, 0x02, 0x0A, 0x03,
- 0x0A, 0x04, 0x0A, 0x05, 0x0A, 0x06, 0x0A, 0x07,
- 0x0A, 0x08, 0x0A, 0x09, 0x0A, 0x0A, 0x0A, 0x0B
-};
-
-static const byte attackRate[] = {
- 0, 2, 4, 7, 14, 26, 48, 82,
- 128, 144, 160, 176, 192, 208, 224, 255
-};
-
-static const byte decayRate[] = {
- 0, 1, 2, 3, 4, 6, 12, 24,
- 48, 96, 192, 215, 255, 255, 255, 255
-};
-
-static const byte sustainRate[] = {
- 255, 180, 128, 96, 80, 64, 56, 48,
- 42, 36, 32, 28, 24, 20, 16, 0
-};
-
-static const byte releaseRate[] = {
- 0, 1, 2, 4, 6, 9, 14, 22,
- 36, 56, 80, 100, 120, 140, 160, 255
-};
-
-static const byte volumeTable[] = {
- 0x00, 0x10, 0x10, 0x11, 0x11, 0x21, 0x22, 0x22,
- 0x33, 0x44, 0x55, 0x66, 0x88, 0xAA, 0xCC, 0xFF
-};
-
Player_V2CMS::Player_V2CMS(ScummEngine *scumm, Audio::Mixer *mixer)
- : Player_V2Base(scumm, mixer, true) {
- int i;
-
+ : Player_V2Base(scumm, mixer, true), _cmsVoicesBase(), _cmsVoices(),
+ _cmsChips(), _midiDelay(0), _octaveMask(0), _looping(0), _tempo(0),
+ _tempoSum(0), _midiData(0), _midiSongBegin(0), _musicTimer(0),
+ _musicTimerTicks(0), _voiceTimer(0), _loadedMidiSong(0),
+ _outputTableReady(0), _midiChannel(), _midiChannelUse() {
setMusicVolume(255);
- memset(_cmsVoicesBase, 0, sizeof(Voice)*16);
- memset(_cmsVoices, 0, sizeof(Voice2)*8);
- memset(_cmsChips, 0, sizeof(MusicChip)*2);
- _midiDelay = _octaveMask = _looping = _tempo = 0;
- _midiData = _midiSongBegin = 0;
- _loadedMidiSong = 0;
- memset(_midiChannel, 0, sizeof(Voice2*)*16);
- memset(_midiChannelUse, 0, sizeof(byte)*16);
-
- _cmsVoices[0].amplitudeOutput = &(_cmsChips[0].ampl[0]);
- _cmsVoices[0].freqOutput = &(_cmsChips[0].freq[0]);
- _cmsVoices[0].octaveOutput = &(_cmsChips[0].octave[0]);
- _cmsVoices[1].amplitudeOutput = &(_cmsChips[0].ampl[1]);
- _cmsVoices[1].freqOutput = &(_cmsChips[0].freq[1]);
- _cmsVoices[1].octaveOutput = &(_cmsChips[0].octave[0]);
- _cmsVoices[2].amplitudeOutput = &(_cmsChips[0].ampl[2]);
- _cmsVoices[2].freqOutput = &(_cmsChips[0].freq[2]);
- _cmsVoices[2].octaveOutput = &(_cmsChips[0].octave[1]);
- _cmsVoices[3].amplitudeOutput = &(_cmsChips[0].ampl[3]);
- _cmsVoices[3].freqOutput = &(_cmsChips[0].freq[3]);
- _cmsVoices[3].octaveOutput = &(_cmsChips[0].octave[1]);
- _cmsVoices[4].amplitudeOutput = &(_cmsChips[1].ampl[0]);
- _cmsVoices[4].freqOutput = &(_cmsChips[1].freq[0]);
- _cmsVoices[4].octaveOutput = &(_cmsChips[1].octave[0]);
- _cmsVoices[5].amplitudeOutput = &(_cmsChips[1].ampl[1]);
- _cmsVoices[5].freqOutput = &(_cmsChips[1].freq[1]);
- _cmsVoices[5].octaveOutput = &(_cmsChips[1].octave[0]);
- _cmsVoices[6].amplitudeOutput = &(_cmsChips[1].ampl[2]);
- _cmsVoices[6].freqOutput = &(_cmsChips[1].freq[2]);
- _cmsVoices[6].octaveOutput = &(_cmsChips[1].octave[1]);
- _cmsVoices[7].amplitudeOutput = &(_cmsChips[1].ampl[3]);
- _cmsVoices[7].freqOutput = &(_cmsChips[1].freq[3]);
- _cmsVoices[7].octaveOutput = &(_cmsChips[1].octave[1]);
+ memset(_sfxFreq, 0xFF, sizeof(_sfxFreq));
+ memset(_sfxAmpl, 0x00, sizeof(_sfxAmpl));
+ memset(_sfxOctave, 0x66, sizeof(_sfxOctave));
+
+ _cmsVoices[0].amplitudeOutput = &_cmsChips[0].ampl[0];
+ _cmsVoices[0].freqOutput = &_cmsChips[0].freq[0];
+ _cmsVoices[0].octaveOutput = &_cmsChips[0].octave[0];
+ _cmsVoices[1].amplitudeOutput = &_cmsChips[0].ampl[1];
+ _cmsVoices[1].freqOutput = &_cmsChips[0].freq[1];
+ _cmsVoices[1].octaveOutput = &_cmsChips[0].octave[0];
+ _cmsVoices[2].amplitudeOutput = &_cmsChips[0].ampl[2];
+ _cmsVoices[2].freqOutput = &_cmsChips[0].freq[2];
+ _cmsVoices[2].octaveOutput = &_cmsChips[0].octave[1];
+ _cmsVoices[3].amplitudeOutput = &_cmsChips[0].ampl[3];
+ _cmsVoices[3].freqOutput = &_cmsChips[0].freq[3];
+ _cmsVoices[3].octaveOutput = &_cmsChips[0].octave[1];
+ _cmsVoices[4].amplitudeOutput = &_cmsChips[1].ampl[0];
+ _cmsVoices[4].freqOutput = &_cmsChips[1].freq[0];
+ _cmsVoices[4].octaveOutput = &_cmsChips[1].octave[0];
+ _cmsVoices[5].amplitudeOutput = &_cmsChips[1].ampl[1];
+ _cmsVoices[5].freqOutput = &_cmsChips[1].freq[1];
+ _cmsVoices[5].octaveOutput = &_cmsChips[1].octave[0];
+ _cmsVoices[6].amplitudeOutput = &_cmsChips[1].ampl[2];
+ _cmsVoices[6].freqOutput = &_cmsChips[1].freq[2];
+ _cmsVoices[6].octaveOutput = &_cmsChips[1].octave[1];
+ _cmsVoices[7].amplitudeOutput = &_cmsChips[1].ampl[3];
+ _cmsVoices[7].freqOutput = &_cmsChips[1].freq[3];
+ _cmsVoices[7].octaveOutput = &_cmsChips[1].octave[1];
// inits the CMS Emulator like in the original
_cmsEmu = new CMSEmulator(_sampleRate);
- static const byte cmsInitData[13*2] = {
- 0x1C, 0x02,
- 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
- 0x14, 0x3F, 0x15, 0x00, 0x16, 0x00, 0x18, 0x00, 0x19, 0x00, 0x1C, 0x01
- };
-
- i = 0;
- for (int cmsPort = 0x220; i < 2; cmsPort += 2, ++i) {
+ for (int i = 0, cmsPort = 0x220; i < 2; cmsPort += 2, ++i) {
for (int off = 0; off < 13; ++off) {
- _cmsEmu->portWrite(cmsPort+1, cmsInitData[off*2]);
- _cmsEmu->portWrite(cmsPort, cmsInitData[off*2+1]);
+ _cmsEmu->portWrite(cmsPort+1, _cmsInitData[off*2]);
+ _cmsEmu->portWrite(cmsPort, _cmsInitData[off*2+1]);
}
}
@@ -200,6 +87,10 @@ Player_V2CMS::~Player_V2CMS() {
void Player_V2CMS::setMusicVolume(int vol) {
}
+int Player_V2CMS::getMusicTimer() {
+ return _midiData ? _musicTimer : Player_V2Base::getMusicTimer();
+}
+
void Player_V2CMS::stopAllSounds() {
Common::StackLock lock(_mutex);
@@ -211,6 +102,7 @@ void Player_V2CMS::stopAllSounds() {
_midiData = 0;
_midiSongBegin = 0;
_midiDelay = 0;
+ _musicTimer = _musicTimerTicks = 0;
offAllChannels();
}
@@ -244,6 +136,7 @@ void Player_V2CMS::startSound(int nr) {
assert(data);
if (data[6] == 0x80) {
+ _musicTimer = _musicTimerTicks = 0;
loadMidiData(data, nr);
} else {
int cprio = _current_data ? *(_current_data + _header_len) : 0;
@@ -282,7 +175,8 @@ void Player_V2CMS::startSound(int nr) {
}
void Player_V2CMS::loadMidiData(byte *data, int sound) {
- memset(_midiChannelUse, 0, sizeof(byte)*16);
+ memset(_midiChannelUse, 0, sizeof(_midiChannelUse));
+ memset(_midiChannel, 0, sizeof(_midiChannel));
_tempo = data[7];
_looping = data[8];
@@ -299,11 +193,11 @@ void Player_V2CMS::loadMidiData(byte *data, int sound) {
Voice *voiceDef = &_cmsVoicesBase[channel];
byte attackDecay = voice2[10];
- voiceDef->attack = attackRate[attackDecay >> 4];
- voiceDef->decay = decayRate[attackDecay & 0x0F];
+ voiceDef->attack = _attackRate[attackDecay >> 4];
+ voiceDef->decay = _decayRate[attackDecay & 0x0F];
byte sustainRelease = voice2[11];
- voiceDef->sustain = sustainRate[sustainRelease >> 4];
- voiceDef->release = releaseRate[sustainRelease & 0x0F];
+ voiceDef->sustain = _sustainRate[sustainRelease >> 4];
+ voiceDef->release = _releaseRate[sustainRelease & 0x0F];
if (voice2[3] & 0x40) {
voiceDef->vibrato = 0x0301;
@@ -331,12 +225,10 @@ void Player_V2CMS::loadMidiData(byte *data, int sound) {
}
}
- for (int i = 0, channel = 0; i < 8; ++i, channel += 2) {
+ for (int i = 0; i < 8; ++i) {
_cmsVoices[i].chanNumber = 0xFF;
_cmsVoices[i].curVolume = 0;
_cmsVoices[i].nextVoice = 0;
-
- _midiChannel[channel] = 0;
}
_midiDelay = 0;
@@ -351,11 +243,17 @@ int Player_V2CMS::getSoundStatus(int nr) const {
return _current_nr == nr || _next_nr == nr || _loadedMidiSong == nr;
}
-void Player_V2CMS::processMidiData(uint ticks) {
+void Player_V2CMS::processMidiData() {
byte *currentData = _midiData;
byte command = 0x00;
int16 temp = 0;
+ ++_musicTimerTicks;
+ if (_musicTimerTicks > 60) {
+ _musicTimerTicks = 0;
+ ++_musicTimer;
+ }
+
if (!_midiDelay) {
while (true) {
if ((command = *currentData++) == 0xFF) {
@@ -365,6 +263,8 @@ void Player_V2CMS::processMidiData(uint ticks) {
continue;
}
_midiData = _midiSongBegin = 0;
+ _midiDelay = 0;
+ _loadedMidiSong = 0;
offAllChannels();
return;
} else {
@@ -400,7 +300,7 @@ void Player_V2CMS::processMidiData(uint ticks) {
_midiDelay = temp;
}
- _midiDelay -= ticks;
+ --_midiDelay;
if (_midiDelay < 0)
_midiDelay = 0;
@@ -415,27 +315,21 @@ int Player_V2CMS::readBuffer(int16 *buffer, const int numSamples) {
// maybe this needs a complete rewrite
do {
- if (_midiData) {
- --_clkFrequenz;
- if (!(_clkFrequenz & 0x01)) {
- playVoice();
- }
-
- _tempoSum += _tempo;
- // FIXME: _tempoSum is declared as char; on some systems char is unsigned.
- // E.g. on OS X. Hence the following check is always false.
- // Moral of the story: Use uint8, int8 or any of the other types provided by
- // ScummVM if you want to ensure signedness and number of available bits.
- if (_tempoSum < 0) {
- // this have to be called in the same rate as in the original (I think)
- processMidiData(1);
+ if (!(_next_tick >> FIXP_SHIFT)) {
+ if (_midiData) {
+ --_voiceTimer;
+ if (!(_voiceTimer & 0x01))
+ playVoice();
+
+ int newTempoSum = _tempo + _tempoSum;
+ _tempoSum = newTempoSum & 0xFF;
+ if (newTempoSum > 0xFF)
+ processMidiData();
+ } else {
+ nextTick();
+ play();
}
- }
-
- if (!(_next_tick >> FIXP_SHIFT) && !_midiData) {
_next_tick += _tick_len;
- nextTick();
- play();
}
step = len;
@@ -456,99 +350,95 @@ void Player_V2CMS::playVoice() {
}
_octaveMask = 0xF0;
- Voice2 *voice =0;
+ Voice2 *voice = 0;
for (int i = 0; i < 8; ++i) {
voice = &_cmsVoices[i];
_octaveMask = ~_octaveMask;
if (voice->chanNumber != 0xFF) {
processChannel(voice);
- continue;
- }
-
- if (!voice->curVolume) {
- *(voice->amplitudeOutput) = 0;
- }
+ } else {
+ if (!voice->curVolume) {
+ *(voice->amplitudeOutput) = 0;
+ }
- int volume = voice->curVolume - voice->releaseRate;
- voice->curVolume = volume;
+ int volume = voice->curVolume - voice->releaseRate;
+ if (volume < 0)
+ volume = 0;
- if (volume < 0) {
- volume = voice->curVolume = 0;
+ voice->curVolume = volume;
+ *(voice->amplitudeOutput) = ((volume >> 4) | (volume & 0xF0)) & voice->channel;
+ ++_outputTableReady;
}
-
- *(voice->amplitudeOutput) = ((volume >> 4) | (volume & 0xF0)) & voice->channel;
- ++_outputTableReady;
}
}
void Player_V2CMS::processChannel(Voice2 *channel) {
++_outputTableReady;
switch (channel->nextProcessState) {
- case PROCESS_RELEASE:
- processRelease(channel);
- break;
-
- case PROCESS_ATTACK:
+ case Voice2::kEnvelopeAttack:
processAttack(channel);
break;
- case PROCESS_DECAY:
+ case Voice2::kEnvelopeDecay:
processDecay(channel);
break;
- case PROCESS_SUSTAIN:
+ case Voice2::kEnvelopeSustain:
processSustain(channel);
break;
- case PROCESS_VIBRATO:
- processVibrato(channel);
- break;
-
- default:
+ case Voice2::kEnvelopeRelease:
+ processRelease(channel);
break;
}
}
void Player_V2CMS::processRelease(Voice2 *channel) {
- channel->curVolume -= channel->releaseRate;
- if (channel->curVolume < 0)
- channel->curVolume = 0;
+ int newVolume = channel->curVolume - channel->releaseRate;
+ if (newVolume < 0)
+ newVolume = 0;
+
+ channel->curVolume = newVolume;
processVibrato(channel);
}
void Player_V2CMS::processAttack(Voice2 *channel) {
- channel->curVolume += channel->attackRate;
- if (channel->curVolume >= 0) {
- if (channel->curVolume <= channel->maxAmpl)
- return processVibrato(channel);
+ int newVolume = channel->curVolume + channel->attackRate;
+ if (newVolume > channel->maxAmpl) {
+ channel->curVolume = channel->maxAmpl;
+ channel->nextProcessState = Voice2::kEnvelopeDecay;
+ } else {
+ channel->curVolume = newVolume;
}
- channel->curVolume = channel->maxAmpl;
- channel->nextProcessState = PROCESS_DECAY;
+
processVibrato(channel);
}
void Player_V2CMS::processDecay(Voice2 *channel) {
- channel->curVolume -= channel->decayRate;
- if (channel->curVolume >= 0) {
- if (channel->curVolume > channel->sustainRate)
- return processVibrato(channel);
+ int newVolume = channel->curVolume - channel->decayRate;
+ if (newVolume <= channel->sustainRate) {
+ channel->curVolume = channel->sustainRate;
+ channel->nextProcessState = Voice2::kEnvelopeSustain;
+ } else {
+ channel->curVolume = newVolume;
}
- channel->curVolume = channel->sustainRate;
- channel->nextProcessState = PROCESS_SUSTAIN;
+
processVibrato(channel);
}
void Player_V2CMS::processSustain(Voice2 *channel) {
if (channel->unkVibratoRate) {
- int volume = (int)channel->curVolume + (int)channel->unkRate;
+ int16 volume = channel->curVolume + channel->unkRate;
if (volume & 0xFF00) {
- volume = ((~volume) >> 8) & 0xFF;
+ volume = int8(volume >> 8);
+ volume = -volume;
}
+
channel->curVolume = volume;
- --(channel->unkCount);
+ --channel->unkCount;
if (!channel->unkCount) {
- channel->unkRate = ~(channel->unkRate);
+ channel->unkRate = -channel->unkRate;
channel->unkCount = (channel->unkVibratoDepth & 0x0F) << 1;
}
}
@@ -557,12 +447,13 @@ void Player_V2CMS::processSustain(Voice2 *channel) {
void Player_V2CMS::processVibrato(Voice2 *channel) {
if (channel->vibratoRate) {
- uint16 temp = channel->curFreq + channel->curVibratoRate;
+ int16 temp = channel->curFreq + channel->curVibratoRate;
channel->curOctave += (temp & 0xFF00) >> 8;
channel->curFreq = temp & 0xFF;
- --(channel->curVibratoUnk);
+
+ --channel->curVibratoUnk;
if (!channel->curVibratoUnk) {
- channel->curVibratoRate = ~(channel->curVibratoRate);
+ channel->curVibratoRate = -channel->curVibratoRate;
channel->curVibratoUnk = (channel->vibratoDepth & 0x0F) << 1;
}
}
@@ -572,25 +463,16 @@ void Player_V2CMS::processVibrato(Voice2 *channel) {
output = channel->freqOutput;
*output = channel->curFreq;
output = channel->octaveOutput;
- *output = ((((channel->curOctave >> 4) | (channel->curOctave & 0x0F)) & _octaveMask) | ((~_octaveMask) & *output));
+ *output = (((channel->curOctave << 4) | (channel->curOctave & 0x0F)) & _octaveMask) | ((~_octaveMask) & *output);
}
void Player_V2CMS::offAllChannels() {
- warning("offAllChannels STUB");
-/*
- // after using this sound can not be played anymore (since it would deinit the emulator)
- static const byte cmsOffData[10*2] = {
- 0x1C, 0x02,
- 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
- 0x14, 0x3F, 0x15, 0x00, 0x16, 0x00
- };
-
for (int cmsPort = 0x220, i = 0; i < 2; cmsPort += 2, ++i) {
- for (int off = 0; off < 10; ++off) {
- _cmsEmu->portWrite(cmsPort+1, cmsOffData[off*2]);
- _cmsEmu->portWrite(cmsPort, cmsOffData[off*2+1]);
+ for (int off = 1; off <= 10; ++off) {
+ _cmsEmu->portWrite(cmsPort+1, _cmsInitData[off*2]);
+ _cmsEmu->portWrite(cmsPort, _cmsInitData[off*2+1]);
}
- }*/
+ }
}
Player_V2CMS::Voice2 *Player_V2CMS::getFreeVoice() {
@@ -637,8 +519,10 @@ void Player_V2CMS::playNote(byte *&data) {
freeVoice->sustainRate = voice->sustain;
freeVoice->releaseRate = voice->release;
freeVoice->octaveAdd = voice->octadd;
- freeVoice->vibratoRate = freeVoice->curVibratoRate = voice->vibrato;
- freeVoice->unkVibratoRate = freeVoice->unkRate = voice->vibrato2;
+ freeVoice->vibratoRate = freeVoice->curVibratoRate = voice->vibrato & 0xFF;
+ freeVoice->vibratoDepth = freeVoice->curVibratoUnk = voice->vibrato >> 8;
+ freeVoice->unkVibratoRate = freeVoice->unkRate = voice->vibrato2 & 0xFF;
+ freeVoice->unkVibratoDepth = freeVoice->unkCount = voice->vibrato2 >> 8;
freeVoice->maxAmpl = 0xFF;
uint8 rate = freeVoice->attackRate;
@@ -650,7 +534,14 @@ void Player_V2CMS::playNote(byte *&data) {
rate -= freeVoice->attackRate;
freeVoice->curVolume = rate;
freeVoice->playingNote = *data;
- int octave = octaveTable[(*data + 3) << 1] + freeVoice->octaveAdd - 3;
+
+ int effectiveNote = freeVoice->playingNote + 3;
+ if (effectiveNote < 0 || effectiveNote >= ARRAYSIZE(_midiNotes)) {
+ warning("Player_V2CMS::playNote: Note %d out of bounds", effectiveNote);
+ effectiveNote = CLIP<int>(effectiveNote, 0, ARRAYSIZE(_midiNotes) - 1);
+ }
+
+ int octave = _midiNotes[effectiveNote].baseOctave + freeVoice->octaveAdd - 3;
if (octave < 0)
octave = 0;
if (octave > 7)
@@ -658,10 +549,10 @@ void Player_V2CMS::playNote(byte *&data) {
if (!octave)
++octave;
freeVoice->curOctave = octave;
- freeVoice->curFreq = freqTable[volume << 2];
+ freeVoice->curFreq = _midiNotes[effectiveNote].frequency;
freeVoice->curVolume = 0;
- freeVoice->nextProcessState = PROCESS_ATTACK;
- if (_lastMidiCommand & 1)
+ freeVoice->nextProcessState = Voice2::kEnvelopeAttack;
+ if (!(_lastMidiCommand & 1))
freeVoice->channel = 0xF0;
else
freeVoice->channel = 0x0F;
@@ -672,35 +563,27 @@ void Player_V2CMS::playNote(byte *&data) {
Player_V2CMS::Voice2 *Player_V2CMS::getPlayVoice(byte param) {
byte channelNum = _lastMidiCommand & 0x0F;
- Voice2 *channel = _midiChannel[channelNum];
+ Voice2 *curVoice = _midiChannel[channelNum];
- if (channel) {
- Voice2 *backUp = 0;
+ if (curVoice) {
+ Voice2 *prevVoice = 0;
while (true) {
- if (channel->playingNote == param)
+ if (curVoice->playingNote == param)
break;
- backUp = channel;
- channel = channel->nextVoice;
- if (!channel)
+ prevVoice = curVoice;
+ curVoice = curVoice->nextVoice;
+ if (!curVoice)
return 0;
}
- Voice2 *backUp2 = channel->nextVoice;
- {
- Voice2 *temp = backUp;
- backUp = channel;
- channel = temp;
- }
- if (channel) {
- channel->nextVoice = backUp2;
- } else {
- _midiChannel[channelNum] = backUp2;
- }
- channel = backUp;
+ if (prevVoice)
+ prevVoice->nextVoice = curVoice->nextVoice;
+ else
+ _midiChannel[channelNum] = curVoice->nextVoice;
}
- return channel;
+ return curVoice;
}
void Player_V2CMS::clearNote(byte *&data) {
@@ -708,22 +591,17 @@ void Player_V2CMS::clearNote(byte *&data) {
if (voice) {
voice->chanNumber = 0xFF;
voice->nextVoice = 0;
- voice->nextProcessState = PROCESS_RELEASE;
+ voice->nextProcessState = Voice2::kEnvelopeRelease;
}
data += 2;
}
void Player_V2CMS::play() {
_octaveMask = 0xF0;
- channel_data *chan = &(_channels[0].d);
+ channel_data *chan = &_channels[0].d;
- static byte volumeReg[4] = { 0x00, 0x00, 0x00, 0x00 };
- static byte octaveReg[4] = { 0x66, 0x66, 0x66, 0x66 };
- static byte freqReg[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
+ byte noiseGen = 3;
- static byte freqEnable = 0x3E;
- static byte noiseEnable = 0x01;
- static byte noiseGen = 0x02;
for (int i = 1; i <= 4; ++i) {
if (chan->time_left) {
uint16 freq = chan->freq;
@@ -733,8 +611,8 @@ void Player_V2CMS::play() {
noiseGen = freq & 0xFF;
} else {
noiseGen = 3;
- freqReg[0] = freqReg[3];
- octaveReg[0] = (octaveReg[0] & 0xF0) | ((octaveReg[1] & 0xF0) >> 4);
+ _sfxFreq[0] = _sfxFreq[3];
+ _sfxOctave[0] = (_sfxOctave[0] & 0xF0) | ((_sfxOctave[1] & 0xF0) >> 4);
}
} else {
if (freq == 0) {
@@ -760,17 +638,18 @@ void Player_V2CMS::play() {
oct |= cmsOct;
oct &= _octaveMask;
- oct |= ((~_octaveMask) & octaveReg[((i & 3) >> 1)]);
- octaveReg[((i & 3) >> 1)] = oct;
+ oct |= (~_octaveMask) & _sfxOctave[(i & 3) >> 1];
+ _sfxOctave[(i & 3) >> 1] = oct;
- freq >>= -(cmsOct-9);
- freqReg[(i&3)] = (-(freq-511)) & 0xFF;
+ freq >>= -(cmsOct - 9);
+ _sfxFreq[i & 3] = (-(freq - 511)) & 0xFF;
}
- volumeReg[i & 3] = volumeTable[chan->volume >> 12];
+ _sfxAmpl[i & 3] = _volumeTable[chan->volume >> 12];
} else {
- volumeReg[i & 3] = 0;
+ _sfxAmpl[i & 3] = 0;
}
- chan = &(_channels[i].d);
+
+ chan = &_channels[i].d;
_octaveMask ^= 0xFF;
}
@@ -778,29 +657,29 @@ void Player_V2CMS::play() {
// the right channels amplitude is set
// with the low value the left channels amplitude
_cmsEmu->portWrite(0x221, 0);
- _cmsEmu->portWrite(0x220, volumeReg[0]);
+ _cmsEmu->portWrite(0x220, _sfxAmpl[0]);
_cmsEmu->portWrite(0x221, 1);
- _cmsEmu->portWrite(0x220, volumeReg[1]);
+ _cmsEmu->portWrite(0x220, _sfxAmpl[1]);
_cmsEmu->portWrite(0x221, 2);
- _cmsEmu->portWrite(0x220, volumeReg[2]);
+ _cmsEmu->portWrite(0x220, _sfxAmpl[2]);
_cmsEmu->portWrite(0x221, 3);
- _cmsEmu->portWrite(0x220, volumeReg[3]);
+ _cmsEmu->portWrite(0x220, _sfxAmpl[3]);
_cmsEmu->portWrite(0x221, 8);
- _cmsEmu->portWrite(0x220, freqReg[0]);
+ _cmsEmu->portWrite(0x220, _sfxFreq[0]);
_cmsEmu->portWrite(0x221, 9);
- _cmsEmu->portWrite(0x220, freqReg[1]);
+ _cmsEmu->portWrite(0x220, _sfxFreq[1]);
_cmsEmu->portWrite(0x221, 10);
- _cmsEmu->portWrite(0x220, freqReg[2]);
+ _cmsEmu->portWrite(0x220, _sfxFreq[2]);
_cmsEmu->portWrite(0x221, 11);
- _cmsEmu->portWrite(0x220, freqReg[3]);
+ _cmsEmu->portWrite(0x220, _sfxFreq[3]);
_cmsEmu->portWrite(0x221, 0x10);
- _cmsEmu->portWrite(0x220, octaveReg[0]);
+ _cmsEmu->portWrite(0x220, _sfxOctave[0]);
_cmsEmu->portWrite(0x221, 0x11);
- _cmsEmu->portWrite(0x220, octaveReg[1]);
+ _cmsEmu->portWrite(0x220, _sfxOctave[1]);
_cmsEmu->portWrite(0x221, 0x14);
- _cmsEmu->portWrite(0x220, freqEnable);
+ _cmsEmu->portWrite(0x220, 0x3E);
_cmsEmu->portWrite(0x221, 0x15);
- _cmsEmu->portWrite(0x220, noiseEnable);
+ _cmsEmu->portWrite(0x220, 0x01);
_cmsEmu->portWrite(0x221, 0x16);
_cmsEmu->portWrite(0x220, noiseGen);
}
@@ -838,4 +717,71 @@ void Player_V2CMS::playMusicChips(const MusicChip *table) {
} while ((cmsPort & 2) == 0);
}
+const Player_V2CMS::MidiNote Player_V2CMS::_midiNotes[132] = {
+ { 3, 0 }, { 31, 0 }, { 58, 0 }, { 83, 0 },
+ { 107, 0 }, { 130, 0 }, { 151, 0 }, { 172, 0 },
+ { 191, 0 }, { 209, 0 }, { 226, 0 }, { 242, 0 },
+ { 3, 1 }, { 31, 1 }, { 58, 1 }, { 83, 1 },
+ { 107, 1 }, { 130, 1 }, { 151, 1 }, { 172, 1 },
+ { 191, 1 }, { 209, 1 }, { 226, 1 }, { 242, 1 },
+ { 3, 2 }, { 31, 2 }, { 58, 2 }, { 83, 2 },
+ { 107, 2 }, { 130, 2 }, { 151, 2 }, { 172, 2 },
+ { 191, 2 }, { 209, 2 }, { 226, 2 }, { 242, 2 },
+ { 3, 3 }, { 31, 3 }, { 58, 3 }, { 83, 3 },
+ { 107, 3 }, { 130, 3 }, { 151, 3 }, { 172, 3 },
+ { 191, 3 }, { 209, 3 }, { 226, 3 }, { 242, 3 },
+ { 3, 4 }, { 31, 4 }, { 58, 4 }, { 83, 4 },
+ { 107, 4 }, { 130, 4 }, { 151, 4 }, { 172, 4 },
+ { 191, 4 }, { 209, 4 }, { 226, 4 }, { 242, 4 },
+ { 3, 5 }, { 31, 5 }, { 58, 5 }, { 83, 5 },
+ { 107, 5 }, { 130, 5 }, { 151, 5 }, { 172, 5 },
+ { 191, 5 }, { 209, 5 }, { 226, 5 }, { 242, 5 },
+ { 3, 6 }, { 31, 6 }, { 58, 6 }, { 83, 6 },
+ { 107, 6 }, { 130, 6 }, { 151, 6 }, { 172, 6 },
+ { 191, 6 }, { 209, 6 }, { 226, 6 }, { 242, 6 },
+ { 3, 7 }, { 31, 7 }, { 58, 7 }, { 83, 7 },
+ { 107, 7 }, { 130, 7 }, { 151, 7 }, { 172, 7 },
+ { 191, 7 }, { 209, 7 }, { 226, 7 }, { 242, 7 },
+ { 3, 8 }, { 31, 8 }, { 58, 8 }, { 83, 8 },
+ { 107, 8 }, { 130, 8 }, { 151, 8 }, { 172, 8 },
+ { 191, 8 }, { 209, 8 }, { 226, 8 }, { 242, 8 },
+ { 3, 9 }, { 31, 9 }, { 58, 9 }, { 83, 9 },
+ { 107, 9 }, { 130, 9 }, { 151, 9 }, { 172, 9 },
+ { 191, 9 }, { 209, 9 }, { 226, 9 }, { 242, 9 },
+ { 3, 10 }, { 31, 10 }, { 58, 10 }, { 83, 10 },
+ { 107, 10 }, { 130, 10 }, { 151, 10 }, { 172, 10 },
+ { 191, 10 }, { 209, 10 }, { 226, 10 }, { 242, 10 }
+};
+
+const byte Player_V2CMS::_attackRate[16] = {
+ 0, 2, 4, 7, 14, 26, 48, 82,
+ 128, 144, 160, 176, 192, 208, 224, 255
+};
+
+const byte Player_V2CMS::_decayRate[16] = {
+ 0, 1, 2, 3, 4, 6, 12, 24,
+ 48, 96, 192, 215, 255, 255, 255, 255
+};
+
+const byte Player_V2CMS::_sustainRate[16] = {
+ 255, 180, 128, 96, 80, 64, 56, 48,
+ 42, 36, 32, 28, 24, 20, 16, 0
+};
+
+const byte Player_V2CMS::_releaseRate[16] = {
+ 0, 1, 2, 4, 6, 9, 14, 22,
+ 36, 56, 80, 100, 120, 140, 160, 255
+};
+
+const byte Player_V2CMS::_volumeTable[16] = {
+ 0x00, 0x10, 0x10, 0x11, 0x11, 0x21, 0x22, 0x22,
+ 0x33, 0x44, 0x55, 0x66, 0x88, 0xAA, 0xCC, 0xFF
+};
+
+const byte Player_V2CMS::_cmsInitData[26] = {
+ 0x1C, 0x02,
+ 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
+ 0x14, 0x3F, 0x15, 0x00, 0x16, 0x00, 0x18, 0x00, 0x19, 0x00, 0x1C, 0x01
+};
+
} // End of namespace Scumm
diff --git a/engines/scumm/player_v2cms.h b/engines/scumm/player_v2cms.h
index f7dc0c16b1..905c7c141e 100644
--- a/engines/scumm/player_v2cms.h
+++ b/engines/scumm/player_v2cms.h
@@ -42,18 +42,14 @@ public:
virtual void startSound(int sound);
virtual void stopSound(int sound);
virtual void stopAllSounds();
-// virtual int getMusicTimer();
+ virtual int getMusicTimer();
virtual int getSoundStatus(int sound) const;
// AudioStream API
- int readBuffer(int16 *buffer, const int numSamples);
- bool isStereo() const { return true; }
- bool endOfData() const { return false; }
- int getRate() const { return _sampleRate; }
+ virtual int readBuffer(int16 *buffer, const int numSamples);
+ virtual bool isStereo() const { return true; }
-protected:
-
-#include "common/pack-start.h" // START STRUCT PACKING
+private:
struct Voice {
byte attack;
byte decay;
@@ -63,7 +59,7 @@ protected:
int16 vibrato;
int16 vibrato2;
int16 noise;
- } PACKED_STRUCT;
+ };
struct Voice2 {
byte *amplitudeOutput;
@@ -72,12 +68,12 @@ protected:
uint8 channel;
int8 sustainLevel;
- int8 attackRate;
+ uint8 attackRate;
uint8 maxAmpl;
- int8 decayRate;
- int8 sustainRate;
- int8 releaseRate;
- int8 releaseTime;
+ uint8 decayRate;
+ uint8 sustainRate;
+ uint8 releaseRate;
+ uint8 releaseTime;
int8 vibratoRate;
int8 vibratoDepth;
@@ -90,10 +86,17 @@ protected:
int8 unkRate;
int8 unkCount;
- int nextProcessState;
- int8 curVolume;
- int8 curOctave;
- int8 curFreq;
+ enum EnvelopeState {
+ kEnvelopeAttack,
+ kEnvelopeDecay,
+ kEnvelopeSustain,
+ kEnvelopeRelease
+ };
+
+ EnvelopeState nextProcessState;
+ uint8 curVolume;
+ uint8 curOctave;
+ uint8 curFreq;
int8 octaveAdd;
@@ -101,21 +104,20 @@ protected:
Voice2 *nextVoice;
byte chanNumber;
- } PACKED_STRUCT;
+ };
struct MusicChip {
byte ampl[4];
byte freq[4];
byte octave[2];
- } PACKED_STRUCT;
-#include "common/pack-end.h" // END STRUCT PACKING
+ };
Voice _cmsVoicesBase[16];
Voice2 _cmsVoices[8];
MusicChip _cmsChips[2];
- int8 _tempo;
- int8 _tempoSum;
+ uint8 _tempo;
+ uint8 _tempoSum;
byte _looping;
byte _octaveMask;
int16 _midiDelay;
@@ -126,11 +128,13 @@ protected:
int _loadedMidiSong;
+ byte _sfxFreq[4], _sfxAmpl[4], _sfxOctave[2];
+
byte _lastMidiCommand;
uint _outputTableReady;
- byte _clkFrequenz;
- byte _restart;
- byte _curSno;
+ byte _voiceTimer;
+
+ int _musicTimer, _musicTimerTicks;
void loadMidiData(byte *data, int sound);
void play();
@@ -147,15 +151,25 @@ protected:
void clearNote(byte *&data);
void offAllChannels();
void playVoice();
- void processMidiData(uint ticks);
+ void processMidiData();
Voice2 *getFreeVoice();
Voice2 *getPlayVoice(byte param);
- // from Player_V2
-protected:
- CMSEmulator *_cmsEmu;
+ struct MidiNote {
+ byte frequency;
+ byte baseOctave;
+ };
+
+ static const MidiNote _midiNotes[132];
+ static const byte _attackRate[16];
+ static const byte _decayRate[16];
+ static const byte _sustainRate[16];
+ static const byte _releaseRate[16];
+ static const byte _volumeTable[16];
+ static const byte _cmsInitData[26];
+ CMSEmulator *_cmsEmu;
};
} // End of namespace Scumm
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 3cc710c207..870ec8cdf7 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -686,12 +686,7 @@ Graphics::Surface *ScummEngine::loadThumbnailFromSlot(const char *target, int sl
Graphics::Surface *thumb = 0;
if (Graphics::checkThumbnailHeader(*in)) {
- thumb = new Graphics::Surface();
- assert(thumb);
- if (!Graphics::loadThumbnail(*in, *thumb)) {
- delete thumb;
- thumb = 0;
- }
+ thumb = Graphics::loadThumbnail(*in);
}
delete in;
diff --git a/engines/scumm/script_v4.cpp b/engines/scumm/script_v4.cpp
index 1302c8c28d..8340f62dbc 100644
--- a/engines/scumm/script_v4.cpp
+++ b/engines/scumm/script_v4.cpp
@@ -68,6 +68,18 @@ void ScummEngine_v4::o4_ifState() {
int a = getVarOrDirectWord(PARAM_1);
int b = getVarOrDirectByte(PARAM_2);
+ // WORKAROUND bug #3306145 (also occurs in original): Some old versions of
+ // Indy3 sometimes fail to allocate IQ points correctly. To quote:
+ // "About the points error leaving Castle Brunwald: It seems to "reversed"!
+ // When you get caught, free yourself and escape, you get 25 IQ points even
+ // though you're not supposed to. However if you escape WITHOUT getting
+ // caught, you get 0 IQ points (supposed to get 25 IQ points)."
+ // This workaround is meant to address that.
+ if (_game.id == GID_INDY3 && a == 367 &&
+ vm.slot[_currentScript].number == 363 && _currentRoom == 25) {
+ b = 0;
+ }
+
jumpRelative(getState(a) == b);
}
diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp
index a6cf504586..02c8d977a5 100644
--- a/engines/scumm/script_v5.cpp
+++ b/engines/scumm/script_v5.cpp
@@ -2095,6 +2095,20 @@ void ScummEngine_v5::o5_startScript() {
if (_game.id == GID_ZAK && _game.platform == Common::kPlatformFMTowns && script == 171)
return;
+ // WORKAROUND bug #3306145 (also occurs in original): Some old versions of
+ // Indy3 sometimes fail to allocate IQ points correctly. To quote:
+ // "In the Amiga version you get the 15 points for puzzle 30 if you give the
+ // book or KO the guy. The PC version correctly gives 10 points for puzzle
+ // 29 for KO and 15 for puzzle 30 when giving the book."
+ // This workaround is meant to address that.
+ if (_game.id == GID_INDY3 && vm.slot[_currentScript].number == 106 && script == 125 && VAR(115) != 2) {
+ // If Var[115] != 2, then:
+ // Correct: startScript(125,[29,10]);
+ // Wrong : startScript(125,[30,15]);
+ data[0] = 29;
+ data[1] = 10;
+ }
+
// Method used by original games to skip copy protection scheme
if (!_copyProtection) {
// Copy protection was disabled in LucasArts Classic Adventures (PC Disk)
diff --git a/engines/scumm/scumm-md5.h b/engines/scumm/scumm-md5.h
index 8f555818f4..319eddf871 100644
--- a/engines/scumm/scumm-md5.h
+++ b/engines/scumm/scumm-md5.h
@@ -1,5 +1,5 @@
/*
- This file was generated by the md5table tool on Sun Apr 17 10:46:26 2011
+ This file was generated by the md5table tool on Wed Aug 3 03:14:00 2011
DO NOT EDIT MANUALLY!
*/
@@ -99,7 +99,7 @@ static const MD5Table md5table[] = {
{ "1ed22f601f8b3695804a6583cc3083f1", "puttrace", "HE 98.5", "", -1, Common::NL_NLD, Common::kPlatformUnknown },
{ "1f2e62b5a9c50589fc342285a6bb3a27", "freddi", "HE 73", "", -1, Common::HE_ISR, Common::kPlatformWindows },
{ "1fbebd7b2b692df5297870447a80cfed", "atlantis", "Floppy", "Floppy", 12030, Common::DE_DEU, Common::kPlatformPC },
- { "1ff5997c78fbd0a841a75ef15a05d9d5", "BluesBirthday", "", "Red", -1, Common::EN_ANY, Common::kPlatformWindows },
+ { "1ff5997c78fbd0a841a75ef15a05d9d5", "BluesBirthday", "Red", "Red", -1, Common::EN_ANY, Common::kPlatformUnknown },
{ "2012f854d83d9cc6f73b2b544cd8bbf8", "water", "HE 80", "", -1, Common::RU_RUS, Common::kPlatformWindows },
{ "20176076d708bf14407bcc9bdcd7a418", "pajama3", "", "", -1, Common::RU_RUS, Common::kPlatformWindows },
{ "204453e33456c4faa26e276229fe5b76", "spyfox2", "", "Demo", 14689, Common::DE_DEU, Common::kPlatformWindows },
@@ -403,7 +403,7 @@ static const MD5Table md5table[] = {
{ "9781422e4288dbc090720e4563168ba7", "puttzoo", "", "", -1, Common::FR_FRA, Common::kPlatformWindows },
{ "981e1e1891f2be7e25a01f50ae55a5af", "puttrace", "HE 98", "", -1, Common::EN_USA, Common::kPlatformUnknown },
{ "98744fe66ff730e8c2b3b1f58803ab0b", "atlantis", "Floppy", "Demo", -1, Common::EN_ANY, Common::kPlatformPC },
- { "99128b6a5bdd9831d9682fb8b5cbf8d4", "BluesBirthday", "", "Yellow", -1, Common::EN_ANY, Common::kPlatformUnknown },
+ { "99128b6a5bdd9831d9682fb8b5cbf8d4", "BluesBirthday", "Yellow", "Yellow", -1, Common::EN_ANY, Common::kPlatformUnknown },
{ "99a3699f80b8f776efae592b44b9b991", "maniac", "V2", "V2", -1, Common::FR_FRA, Common::kPlatformPC },
{ "99b6f822b0b2612415407865438697d6", "atlantis", "", "Demo", -1, Common::EN_ANY, Common::kPlatformPC },
{ "9b7452b5cd6d3ffb2b2f5118010af84f", "ft", "Demo", "Demo", 116463537, Common::EN_ANY, Common::kPlatformMacintosh },
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 7b136dc36d..3b83019275 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -71,6 +71,7 @@
#include "scumm/he/cup_player_he.h"
#include "scumm/util.h"
#include "scumm/verbs.h"
+#include "scumm/imuse/pcspk.h"
#include "backends/audiocd/audiocd.h"
@@ -283,8 +284,9 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
_16BitPalette = NULL;
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
_townsScreen = 0;
+#ifdef USE_RGB_COLOR
_cjkFont = 0;
- _cjkChar = 0;
+#endif
#endif
_shadowPalette = NULL;
_shadowPaletteSize = 0;
@@ -297,7 +299,6 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
_haveActorSpeechMsg = false;
_useTalkAnims = false;
_defaultTalkDelay = 0;
- _musicType = MDT_NONE;
_saveSound = 0;
memset(_extraBoxFlags, 0, sizeof(_extraBoxFlags));
memset(_scaleSlots, 0, sizeof(_scaleSlots));
@@ -633,8 +634,10 @@ ScummEngine::~ScummEngine() {
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
delete _townsScreen;
+#ifdef USE_RGB_COLOR
delete _cjkFont;
#endif
+#endif
delete _debugger;
@@ -1350,13 +1353,23 @@ void ScummEngine::setupCharsetRenderer() {
_charset = new CharsetRendererPCE(this);
else
#endif
+ if (_game.platform == Common::kPlatformFMTowns)
+ _charset = new CharsetRendererTownsV3(this);
+ else
_charset = new CharsetRendererV3(this);
#ifdef ENABLE_SCUMM_7_8
} else if (_game.version == 8) {
_charset = new CharsetRendererNut(this);
#endif
} else {
- _charset = new CharsetRendererClassic(this);
+#ifdef USE_RGB_COLOR
+#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
+ if (_game.platform == Common::kPlatformFMTowns)
+ _charset = new CharsetRendererTownsClassic(this);
+ else
+#endif
+#endif
+ _charset = new CharsetRendererClassic(this);
}
}
@@ -1655,43 +1668,8 @@ void ScummEngine_v90he::resetScumm() {
_sprite->resetTables(0);
memset(&_wizParams, 0, sizeof(_wizParams));
- if (_game.heversion >= 98) {
- switch (_game.id) {
- case GID_PUTTRACE:
- _logicHE = new LogicHErace(this);
- break;
-
- case GID_FUNSHOP:
- _logicHE = new LogicHEfunshop(this);
- break;
-
- case GID_FOOTBALL:
- _logicHE = new LogicHEfootball(this);
- break;
-
- case GID_SOCCER:
- case GID_SOCCERMLS:
- case GID_SOCCER2004:
- _logicHE = new LogicHEsoccer(this);
- break;
-
- case GID_BASEBALL2001:
- _logicHE = new LogicHEbaseball2001(this);
- break;
-
- case GID_BASKETBALL:
- _logicHE = new LogicHEbasketball(this);
- break;
-
- case GID_MOONBASE:
- _logicHE = new LogicHEmoonbase(this);
- break;
-
- default:
- _logicHE = new LogicHE(this);
- break;
- }
- }
+ if (_game.heversion >= 98)
+ _logicHE = LogicHE::makeLogicHE(this);
}
void ScummEngine_v99he::resetScumm() {
@@ -1732,40 +1710,36 @@ void ScummEngine::setupMusic(int midi) {
switch (MidiDriver::getMusicType(dev)) {
case MT_NULL:
- _musicType = MDT_NONE;
+ _sound->_musicType = MDT_NONE;
break;
case MT_PCSPK:
- _musicType = MDT_PCSPK;
+ _sound->_musicType = MDT_PCSPK;
break;
case MT_PCJR:
- _musicType = MDT_PCJR;
+ _sound->_musicType = MDT_PCJR;
break;
- //case MT_CMS:
-#if 1
- _musicType = MDT_ADLIB;
-#else
- _musicType = MDT_CMS; // Still has number of bugs, disable by default
-#endif
+ case MT_CMS:
+ _sound->_musicType = MDT_CMS;
break;
case MT_TOWNS:
- _musicType = MDT_TOWNS;
+ _sound->_musicType = MDT_TOWNS;
break;
case MT_ADLIB:
- _musicType = MDT_ADLIB;
+ _sound->_musicType = MDT_ADLIB;
break;
case MT_C64:
- _musicType = MDT_C64;
+ _sound->_musicType = MDT_C64;
break;
case MT_APPLEIIGS:
- _musicType = MDT_APPLEIIGS;
+ _sound->_musicType = MDT_APPLEIIGS;
break;
default:
- _musicType = MDT_MIDI;
+ _sound->_musicType = MDT_MIDI;
break;
}
if ((_game.id == GID_MONKEY_EGA || (_game.id == GID_LOOM && _game.version == 3))
- && (_game.platform == Common::kPlatformPC) && _musicType == MDT_MIDI) {
+ && (_game.platform == Common::kPlatformPC) && _sound->_musicType == MDT_MIDI) {
Common::String fileName;
bool missingFile = false;
if (_game.id == GID_LOOM) {
@@ -1795,7 +1769,7 @@ void ScummEngine::setupMusic(int midi) {
"but %s is missing. Using AdLib instead."), fileName.c_str()),
_("OK"));
dialog.runModal();
- _musicType = MDT_ADLIB;
+ _sound->_musicType = MDT_ADLIB;
}
}
@@ -1809,9 +1783,9 @@ void ScummEngine::setupMusic(int midi) {
* automatically when samples need to be generated */
if (!_mixer->isReady()) {
warning("Sound mixer initialization failed");
- if (_musicType == MDT_ADLIB || _musicType == MDT_PCSPK || _musicType == MDT_PCJR || _musicType == MDT_CMS) {
+ if (_sound->_musicType == MDT_ADLIB || _sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR || _sound->_musicType == MDT_CMS) {
dev = 0;
- _musicType = MDT_NONE;
+ _sound->_musicType = MDT_NONE;
warning("MIDI driver depends on sound mixer, switching to null MIDI driver");
}
}
@@ -1843,9 +1817,9 @@ void ScummEngine::setupMusic(int midi) {
_musicEngine = new Player_V1(this, _mixer, MidiDriver::getMusicType(dev) != MT_PCSPK);
} else if (_game.version <= 2) {
_musicEngine = new Player_V2(this, _mixer, MidiDriver::getMusicType(dev) != MT_PCSPK);
- } else if ((_musicType == MDT_PCSPK || _musicType == MDT_PCJR) && (_game.version > 2 && _game.version <= 4)) {
+ } else if ((_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR) && (_game.version > 2 && _game.version <= 4)) {
_musicEngine = new Player_V2(this, _mixer, MidiDriver::getMusicType(dev) != MT_PCSPK);
- } else if (_musicType == MDT_CMS) {
+ } else if (_sound->_musicType == MDT_CMS) {
_musicEngine = new Player_V2CMS(this, _mixer);
} else if (_game.platform == Common::kPlatform3DO && _game.heversion <= 62) {
// 3DO versions use digital music and sound samples.
@@ -1857,14 +1831,16 @@ void ScummEngine::setupMusic(int midi) {
MidiDriver *nativeMidiDriver = 0;
MidiDriver *adlibMidiDriver = 0;
- if (_musicType != MDT_ADLIB && _musicType != MDT_TOWNS)
+ if (_sound->_musicType != MDT_ADLIB && _sound->_musicType != MDT_TOWNS && _sound->_musicType != MDT_PCSPK)
nativeMidiDriver = MidiDriver::createMidi(dev);
if (nativeMidiDriver != NULL && _native_mt32)
nativeMidiDriver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
- bool multi_midi = ConfMan.getBool("multi_midi") && _musicType != MDT_NONE && (midi & MDT_ADLIB);
- if (_musicType == MDT_ADLIB || _musicType == MDT_TOWNS || multi_midi) {
- adlibMidiDriver = MidiDriver::createMidi(MidiDriver::detectDevice(_musicType == MDT_TOWNS ? MDT_TOWNS : MDT_ADLIB));
+ bool multi_midi = ConfMan.getBool("multi_midi") && _sound->_musicType != MDT_NONE && _sound->_musicType != MDT_PCSPK && (midi & MDT_ADLIB);
+ if (_sound->_musicType == MDT_ADLIB || _sound->_musicType == MDT_TOWNS || multi_midi) {
+ adlibMidiDriver = MidiDriver::createMidi(MidiDriver::detectDevice(_sound->_musicType == MDT_TOWNS ? MDT_TOWNS : MDT_ADLIB));
adlibMidiDriver->property(MidiDriver::PROP_OLD_ADLIB, (_game.features & GF_SMALL_HEADER) ? 1 : 0);
+ } else if (_sound->_musicType == MDT_PCSPK) {
+ adlibMidiDriver = new PcSpkDriver(_mixer);
}
_imuse = IMuse::create(_system, nativeMidiDriver, adlibMidiDriver);
@@ -1893,6 +1869,8 @@ void ScummEngine::setupMusic(int midi) {
_imuse->property(IMuse::PROP_LIMIT_PLAYERS, 1);
_imuse->property(IMuse::PROP_RECYCLE_PLAYERS, 1);
}
+ if (_sound->_musicType == MDT_PCSPK)
+ _imuse->property(IMuse::PROP_PC_SPEAKER, 1);
}
}
}
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index 01bde90e1c..04a175e732 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -40,15 +40,14 @@
#include "scumm/detection.h"
#include "scumm/script.h"
-#include "audio/mididrv.h"
-
#ifdef __DS__
/* This disables the dual layer mode which is used in FM-Towns versions
* of SCUMM games and which emulates the behavior of the original code.
* The only purpose is code size reduction for certain backends.
- * SCUMM 3 (FM-Towns) games will run in normal (DOS VGA) mode, which should
- * work just fine in most situations. Some glitches might occur. SCUMM 5 games
- * will not work without dual layer (and 16 bit color) support.
+ * SCUMM 3 (FM-Towns) games will run in English in normal (DOS VGA) mode,
+ * which should work just fine in most situations. Some glitches might
+ * occur. Japanese mode and SCUMM 5 FM-Towns games will not work without
+ * dual layer (and 16 bit color) support.
*/
#define DISABLE_TOWNS_DUAL_LAYER_MODE
#endif
@@ -234,7 +233,8 @@ enum ScummGameId {
GID_PUTTMOON,
GID_FUNPACK,
GID_FREDDI3,
- GID_BIRTHDAY,
+ GID_BIRTHDAYRED,
+ GID_BIRTHDAYYELLOW,
GID_TREASUREHUNT,
GID_PUTTRACE,
GID_FUNSHOP, // Used for all three funshops
@@ -345,6 +345,7 @@ class ResourceManager;
class ScummEngine : public Engine {
friend class ScummDebugger;
friend class CharsetRenderer;
+ friend class CharsetRendererTownsClassic;
friend class ResourceManager;
public:
@@ -1082,7 +1083,6 @@ protected:
int _saveSound;
bool _native_mt32;
bool _enable_gs;
- MidiDriverFlags _musicType;
bool _copyProtection;
public:
@@ -1326,14 +1326,17 @@ public:
// Exists both in V7 and in V72HE:
byte VAR_NUM_GLOBAL_OBJS;
+#ifdef USE_RGB_COLOR
+ // FM-Towns / PC-Engine specific
+ Graphics::FontSJIS *_cjkFont;
+#endif
+
// FM-Towns specific
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
public:
bool towns_isRectInStringBox(int x1, int y1, int x2, int y2);
byte _townsPaletteFlags;
- byte _townsCharsetColorMap[16];
- Graphics::FontSJIS *_cjkFont;
- uint16 _cjkChar;
+ byte _townsCharsetColorMap[16];
protected:
void towns_drawStripToScreen(VirtScreen *vs, int dstX, int dstY, int srcX, int srcY, int w, int h);
diff --git a/engines/scumm/smush/channel.cpp b/engines/scumm/smush/channel.cpp
index 7f71d0549b..fd822f56b6 100644
--- a/engines/scumm/smush/channel.cpp
+++ b/engines/scumm/smush/channel.cpp
@@ -60,6 +60,8 @@ void SmushChannel::processBuffer() {
if (offset < _tbufferSize) {
int new_size = _tbufferSize - offset;
_tbuffer = (byte *)malloc(new_size);
+ // FIXME: _tbuffer might be 0 if new_size is 0.
+ // NB: Also check other "if (_tbuffer)" locations in smush
if (!_tbuffer)
error("smush channel failed to allocate memory");
memcpy(_tbuffer, _sbuffer + offset, new_size);
@@ -97,6 +99,8 @@ void SmushChannel::processBuffer() {
byte *old = _tbuffer;
int32 new_size = _tbufferSize - offset;
_tbuffer = (byte *)malloc(new_size);
+ // FIXME: _tbuffer might be 0 if new_size is 0.
+ // NB: Also check other "if (_tbuffer)" locations in smush
if (!_tbuffer)
error("smush channel failed to allocate memory");
memcpy(_tbuffer, old + offset, new_size);
diff --git a/engines/scumm/smush/codec37.cpp b/engines/scumm/smush/codec37.cpp
index dcc8ee3c19..344057e3ac 100644
--- a/engines/scumm/smush/codec37.cpp
+++ b/engines/scumm/smush/codec37.cpp
@@ -571,4 +571,3 @@ void Codec37Decoder::decode(byte *dst, const byte *src) {
}
} // End of namespace Scumm
-
diff --git a/engines/scumm/smush/smush_font.cpp b/engines/scumm/smush/smush_font.cpp
index 7765bf1292..5cfa0ea519 100644
--- a/engines/scumm/smush/smush_font.cpp
+++ b/engines/scumm/smush/smush_font.cpp
@@ -258,4 +258,3 @@ void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int
}
} // End of namespace Scumm
-
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 27e43b3740..d8235206f8 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -84,6 +84,8 @@ Sound::Sound(ScummEngine *parent, Audio::Mixer *mixer)
memset(_soundQue, 0, sizeof(_soundQue));
memset(_soundQue2, 0, sizeof(_soundQue2));
memset(_mouthSyncTimes, 0, sizeof(_mouthSyncTimes));
+
+ _musicType = MDT_NONE;
}
Sound::~Sound() {
@@ -1016,7 +1018,7 @@ void Sound::startCDTimer() {
// appears.
_vm->getTimerManager()->removeTimerProc(&cd_timer_handler);
- _vm->getTimerManager()->installTimerProc(&cd_timer_handler, 100700, _vm);
+ _vm->getTimerManager()->installTimerProc(&cd_timer_handler, 100700, _vm, "scummCDtimer");
}
void Sound::stopCDTimer() {
@@ -1094,7 +1096,7 @@ int ScummEngine::readSoundResource(ResId idx) {
switch (basetag) {
case MKTAG('M','I','D','I'):
case MKTAG('i','M','U','S'):
- if (_musicType != MDT_PCSPK && _musicType != MDT_PCJR) {
+ if (_sound->_musicType != MDT_PCSPK && _sound->_musicType != MDT_PCJR) {
_fileHandle->seek(-8, SEEK_CUR);
_fileHandle->read(_res->createResource(rtSound, idx, total_size + 8), total_size + 8);
return 1;
@@ -1118,7 +1120,7 @@ int ScummEngine::readSoundResource(ResId idx) {
break;
case MKTAG('A','D','L',' '):
pri = 1;
- if (_musicType == MDT_ADLIB || _musicType == MDT_TOWNS)
+ if (_sound->_musicType == MDT_ADLIB || _sound->_musicType == MDT_TOWNS)
pri = 10;
break;
case MKTAG('A','M','I',' '):
@@ -1137,16 +1139,33 @@ int ScummEngine::readSoundResource(ResId idx) {
break;
case MKTAG('S','P','K',' '):
pri = -1;
-// if (_musicType == MDT_PCSPK || _musicType == MDT_PCJR)
-// pri = 11;
+ if (_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR)
+ pri = 11;
break;
}
- if ((_musicType == MDT_PCSPK || _musicType == MDT_PCJR || _musicType == MDT_CMS) && pri != 11)
+ // We only allow SPK resources for PC Speaker and PCJr here
+ // since other resource would sound horribly with their output
+ // drivers.
+ if ((_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR) && pri != 11)
pri = -1;
- debugC(DEBUG_RESOURCE, " tag: %s, total_size=%d, pri=%d", tag2str(tag), size, pri);
+ // We only allow ADL resources when AdLib or FM-Towns is used as
+ // primary audio output. This fixes some odd sounds when Indy and
+ // Sophia leave Atlantis with the submarine in Indy4. (Easy to
+ // check with bootparam 4061 in the CD version). It seems the game
+ // only contains a ROL resource for sound id 60. Formerly we tried
+ // to play that via the AdLib or FM-Towns audio driver resulting
+ // in strange noises. Now we behave like the original did.
+ // We make an exception for Macintosh, which uses priority 2 for
+ // its sound resources, and Amiga games, which feature only ROL
+ // resources, since we are a doing Midi -> AdLib conversion for
+ // these.
+ if ((_sound->_musicType == MDT_ADLIB || _sound->_musicType == MDT_TOWNS) && pri != 10
+ && pri != 2 && _game.platform != Common::kPlatformAmiga)
+ pri = -1;
+ debugC(DEBUG_RESOURCE, " tag: %s, total_size=%d, pri=%d", tag2str(tag), size, pri);
if (pri > best_pri) {
best_pri = pri;
@@ -1984,6 +2003,14 @@ static void convertADResource(ResourceManager *res, const GameSettings& game, Re
break;
case 0x80:
+ // FIXME: This is incorrect. The original uses 0x80 for
+ // looping a single channel. We currently interpret it as stop
+ // thus we won't get looping for sound effects. It should
+ // always jump to the start of the channel.
+ //
+ // Since we convert the data to MIDI and we cannot only loop a
+ // single channel via MIDI fixing this will require some more
+ // thought.
track_time[ch] = -1;
src_ptr ++;
break;
@@ -2074,7 +2101,7 @@ int ScummEngine::readSoundResourceSmallHeader(ResId idx) {
}
}
- if ((_musicType == MDT_PCSPK || _musicType == MDT_PCJR) && wa_offs != 0) {
+ if ((_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR) && wa_offs != 0) {
if (_game.features & GF_OLD_BUNDLE) {
_fileHandle->seek(wa_offs, SEEK_SET);
_fileHandle->read(_res->createResource(rtSound, idx, wa_size), wa_size);
@@ -2083,18 +2110,37 @@ int ScummEngine::readSoundResourceSmallHeader(ResId idx) {
_fileHandle->read(_res->createResource(rtSound, idx, wa_size + 6), wa_size + 6);
}
return 1;
- } else if (_musicType == MDT_CMS && ad_offs != 0) {
+ } else if (_sound->_musicType == MDT_CMS) {
if (_game.features & GF_OLD_BUNDLE) {
- _fileHandle->seek(wa_offs + wa_size + 6, SEEK_SET);
- byte musType = _fileHandle->readByte();
+ bool hasAdLibMusicTrack = false;
+
+ if (ad_offs) {
+ _fileHandle->seek(ad_offs + 4 + 2, SEEK_SET);
+ hasAdLibMusicTrack = (_fileHandle->readByte() == 0x80);
+ }
- if (musType == 0x80) {
+ if (hasAdLibMusicTrack) {
_fileHandle->seek(ad_offs, SEEK_SET);
_fileHandle->read(_res->createResource(rtSound, idx, ad_size), ad_size);
} else {
_fileHandle->seek(wa_offs, SEEK_SET);
_fileHandle->read(_res->createResource(rtSound, idx, wa_size), wa_size);
}
+ } else {
+ bool hasAdLibMusicTrack = false;
+
+ if (ad_offs) {
+ _fileHandle->seek(ad_offs + 2, SEEK_SET);
+ hasAdLibMusicTrack = (_fileHandle->readByte() == 0x80);
+ }
+
+ if (hasAdLibMusicTrack) {
+ _fileHandle->seek(ad_offs - 4, SEEK_SET);
+ _fileHandle->read(_res->createResource(rtSound, idx, ad_size + 4), ad_size + 4);
+ } else {
+ _fileHandle->seek(wa_offs - 6, SEEK_SET);
+ _fileHandle->read(_res->createResource(rtSound, idx, wa_size + 6), wa_size + 6);
+ }
}
} else if (ad_offs != 0) {
// AD resources have a header, instrument definitions and one MIDI track.
diff --git a/engines/scumm/sound.h b/engines/scumm/sound.h
index 03659ceff1..e9a37ac9fa 100644
--- a/engines/scumm/sound.h
+++ b/engines/scumm/sound.h
@@ -24,6 +24,7 @@
#include "common/scummsys.h"
#include "audio/audiostream.h"
+#include "audio/mididrv.h"
#include "audio/mixer.h"
#include "scumm/saveload.h"
@@ -90,6 +91,8 @@ public:
byte _sfxMode;
uint _lastSound;
+ MidiDriverFlags _musicType;
+
public:
Sound(ScummEngine *parent, Audio::Mixer *mixer);
virtual ~Sound();
diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp
index 2d2209c155..61bb89328d 100644
--- a/engines/scumm/string.cpp
+++ b/engines/scumm/string.cpp
@@ -1127,8 +1127,6 @@ int ScummEngine::convertMessageToString(const byte *msg, byte *dst, int dstSize)
}
num += (_game.version == 8) ? 4 : 2;
}
- } else if (_game.id == GID_DIG && (chr == 1 || chr == 2 || chr == 3 || chr == 8)) {
- // Skip these characters
} else {
if ((chr != '@') || (_game.id == GID_CMI && _language == Common::ZH_TWN) ||
(_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine && _language == Common::JA_JPN) ||
@@ -1142,6 +1140,14 @@ int ScummEngine::convertMessageToString(const byte *msg, byte *dst, int dstSize)
if (dst >= end)
error("convertMessageToString: buffer overflow");
}
+
+ // WORKAROUND: Russian The Dig pads messages with 03. No idea why
+ // it does not work as is with our rendering code, thus fixing it
+ // with a workaround.
+ if (_game.id == GID_DIG) {
+ while (*(dst - 1) == 0x03)
+ dst--;
+ }
*dst = 0;
return dstSize - (end - dst);
diff --git a/engines/scumm/vars.cpp b/engines/scumm/vars.cpp
index 56f8de2ad1..26a6a2f3b1 100644
--- a/engines/scumm/vars.cpp
+++ b/engines/scumm/vars.cpp
@@ -25,9 +25,12 @@
#include "scumm/scumm.h"
#include "scumm/scumm_v0.h"
#include "scumm/scumm_v8.h"
+#include "scumm/sound.h"
#include "scumm/he/intern_he.h"
#include "scumm/he/logic_he.h"
+#include "audio/mididrv.h"
+
namespace Scumm {
void ScummEngine::setupScummVars() {
@@ -704,8 +707,12 @@ void ScummEngine_v99he::resetScummVars() {
VAR(VAR_NUM_UNK) = _numUnk;
if (_game.heversion >= 100 && (_game.features & GF_16BIT_COLOR)) {
- // Disable Bink and Smacker video in 16bit color games
+ // Enable Bink video in 16bit color games
+#ifdef USE_BINK
+ VAR(140) = 1;
+#else
VAR(140) = 0;
+#endif
}
}
#endif
@@ -718,7 +725,7 @@ void ScummEngine::resetScummVars() {
// 2 CMS
// 3 AdLib
// 4 Roland
- switch (_musicType) {
+ switch (_sound->_musicType) {
case MDT_NONE:
case MDT_PCSPK:
VAR(VAR_SOUNDCARD) = 0;