2002-04-12 21:26:59 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2001-2005 The ScummVM project
|
2002-04-12 21:26:59 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-04-12 21:26:59 +00:00
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
#include "backends/fs/fs.h"
|
|
|
|
|
2003-09-18 18:23:53 +00:00
|
|
|
#include "base/gameDetector.h"
|
|
|
|
#include "base/plugins.h"
|
|
|
|
|
2003-10-08 21:59:23 +00:00
|
|
|
#include "common/config-manager.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
#include "common/file.h"
|
2004-07-30 09:00:29 +00:00
|
|
|
#include "common/md5.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2003-12-11 04:41:42 +00:00
|
|
|
#include "gui/about.h"
|
2003-12-11 02:09:18 +00:00
|
|
|
#include "gui/message.h"
|
|
|
|
|
2002-08-21 16:07:07 +00:00
|
|
|
#include "simon/simon.h"
|
|
|
|
#include "simon/intern.h"
|
2002-10-22 12:05:04 +00:00
|
|
|
#include "simon/vga.h"
|
2004-01-27 16:28:39 +00:00
|
|
|
#include "simon/debugger.h"
|
2004-07-30 09:00:29 +00:00
|
|
|
#include "simon/simon-md5.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2002-10-09 20:54:15 +00:00
|
|
|
#include "sound/mididrv.h"
|
2005-07-05 20:22:56 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
extern bool isSmartphone(void);
|
|
|
|
#endif
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2003-12-02 11:17:21 +00:00
|
|
|
#ifdef __PALM_OS__
|
|
|
|
#include "globals.h"
|
|
|
|
#endif
|
2003-07-15 16:40:24 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
using Common::File;
|
|
|
|
|
2003-12-13 00:20:01 +00:00
|
|
|
struct SimonGameSettings {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
uint32 features;
|
|
|
|
const char *detectname;
|
|
|
|
GameSettings toGameSettings() const {
|
|
|
|
GameSettings dummy = { name, description, features };
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SimonGameSettings simon_settings[] = {
|
2003-05-19 00:38:35 +00:00
|
|
|
// Simon the Sorcerer 1 & 2 (not SCUMM games)
|
2004-07-30 11:47:27 +00:00
|
|
|
{"simon1acorn", "Simon the Sorcerer 1 (Acorn)", GAME_SIMON1ACORN, "DATA"},
|
2003-12-13 00:20:01 +00:00
|
|
|
{"simon1dos", "Simon the Sorcerer 1 (DOS)", GAME_SIMON1DOS, "GAMEPC"},
|
|
|
|
{"simon1amiga", "Simon the Sorcerer 1 (Amiga)", GAME_SIMON1AMIGA, "gameamiga"},
|
|
|
|
{"simon2dos", "Simon the Sorcerer 2 (DOS)", GAME_SIMON2DOS, "GAME32"},
|
2004-07-30 09:00:29 +00:00
|
|
|
{"simon1talkie", "Simon the Sorcerer 1 Talkie", GAME_SIMON1TALKIE, "GAMEPC"},
|
2005-05-08 05:23:31 +00:00
|
|
|
{"simon1win", "Simon the Sorcerer 1 Talkie (Windows)", GAME_SIMON1TALKIE, 0},
|
2004-07-30 09:00:29 +00:00
|
|
|
{"simon2talkie", "Simon the Sorcerer 2 Talkie", GAME_SIMON2TALKIE, "GSPTR30"},
|
2004-07-31 13:56:04 +00:00
|
|
|
{"simon2win", "Simon the Sorcerer 2 Talkie (Windows)", GAME_SIMON2WIN, 0},
|
|
|
|
{"simon2mac", "Simon the Sorcerer 2 Talkie (Amiga or Mac)", GAME_SIMON2WIN, 0},
|
2003-12-13 00:20:01 +00:00
|
|
|
{"simon1cd32", "Simon the Sorcerer 1 Talkie (Amiga CD32)", GAME_SIMON1CD32, "gameamiga"},
|
2005-07-30 21:11:48 +00:00
|
|
|
{"simon1demo", "Simon the Sorcerer 1 (DOS Demo)", GAME_SIMON1DEMO, "GDEMO"},
|
2005-10-19 10:54:22 +00:00
|
|
|
{"feeble", "The Feeble Files", GAME_FEEBLEFILES, "GAME22"},
|
2003-12-13 00:20:01 +00:00
|
|
|
|
|
|
|
{NULL, NULL, 0, NULL}
|
2003-03-01 22:04:48 +00:00
|
|
|
};
|
|
|
|
|
2004-07-30 09:00:29 +00:00
|
|
|
static int compareMD5Table(const void *a, const void *b) {
|
|
|
|
const char *key = (const char *)a;
|
|
|
|
const MD5Table *elem = (const MD5Table *)b;
|
|
|
|
return strcmp(key, elem->md5);
|
|
|
|
}
|
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
GameList Engine_SIMON_gameList() {
|
2003-12-13 00:20:01 +00:00
|
|
|
const SimonGameSettings *g = simon_settings;
|
2003-10-17 23:16:53 +00:00
|
|
|
GameList games;
|
2003-12-13 00:20:01 +00:00
|
|
|
while (g->name) {
|
|
|
|
games.push_back(g->toGameSettings());
|
|
|
|
g++;
|
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
DetectedGameList Engine_SIMON_detectGames(const FSList &fslist) {
|
|
|
|
DetectedGameList detectedGames;
|
2003-12-13 00:20:01 +00:00
|
|
|
const SimonGameSettings *g;
|
2003-10-17 23:16:53 +00:00
|
|
|
char detectName[128];
|
|
|
|
char detectName2[128];
|
|
|
|
|
2004-07-30 09:00:29 +00:00
|
|
|
typedef Common::Map<Common::String, bool> StringSet;
|
|
|
|
StringSet fileSet;
|
|
|
|
|
2003-12-13 00:20:01 +00:00
|
|
|
for (g = simon_settings; g->name; ++g) {
|
2004-07-31 13:56:04 +00:00
|
|
|
if (g->detectname == NULL)
|
|
|
|
continue;
|
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
strcpy(detectName, g->detectname);
|
|
|
|
strcpy(detectName2, g->detectname);
|
|
|
|
strcat(detectName2, ".");
|
|
|
|
|
|
|
|
// Iterate over all files in the given directory
|
2004-02-05 00:19:57 +00:00
|
|
|
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
2004-12-09 15:06:49 +00:00
|
|
|
if (!file->isDirectory()) {
|
|
|
|
const char *name = file->displayName().c_str();
|
|
|
|
|
|
|
|
if ((!scumm_stricmp(detectName, name)) || (!scumm_stricmp(detectName2, name))) {
|
|
|
|
// Match found, add to list of candidates, then abort inner loop.
|
|
|
|
detectedGames.push_back(g->toGameSettings());
|
|
|
|
fileSet.addKey(file->path());
|
|
|
|
break;
|
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-30 09:00:29 +00:00
|
|
|
|
|
|
|
// Now, we check the MD5 sums of the 'candidate' files. If we have an exact match,
|
|
|
|
// only return that.
|
|
|
|
bool exactMatch = false;
|
|
|
|
for (StringSet::const_iterator iter = fileSet.begin(); iter != fileSet.end(); ++iter) {
|
|
|
|
uint8 md5sum[16];
|
|
|
|
const char *name = iter->_key.c_str();
|
2005-05-10 22:56:25 +00:00
|
|
|
if (Common::md5_file(name, md5sum)) {
|
2004-07-30 09:00:29 +00:00
|
|
|
char md5str[32+1];
|
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const MD5Table *elem;
|
|
|
|
elem = (const MD5Table *)bsearch(md5str, md5table, ARRAYSIZE(md5table)-1, sizeof(MD5Table), compareMD5Table);
|
|
|
|
if (elem) {
|
|
|
|
if (!exactMatch)
|
|
|
|
detectedGames.clear(); // Clear all the non-exact candidates
|
|
|
|
// Find the GameSettings for that target
|
|
|
|
for (g = simon_settings; g->name; ++g) {
|
|
|
|
if (0 == scumm_stricmp(g->name, elem->target))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(g->name);
|
|
|
|
// Insert the 'enhanced' game data into the candidate list
|
|
|
|
detectedGames.push_back(DetectedGame(g->toGameSettings(), elem->language, elem->platform));
|
|
|
|
exactMatch = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
return detectedGames;
|
2003-03-01 22:04:48 +00:00
|
|
|
}
|
|
|
|
|
2003-09-18 18:23:53 +00:00
|
|
|
Engine *Engine_SIMON_create(GameDetector *detector, OSystem *syst) {
|
2003-10-03 19:42:27 +00:00
|
|
|
return new Simon::SimonEngine(detector, syst);
|
2003-09-18 18:23:53 +00:00
|
|
|
}
|
|
|
|
|
2005-03-25 17:55:57 +00:00
|
|
|
REGISTER_PLUGIN(SIMON, "Simon the Sorcerer")
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2003-10-03 19:42:27 +00:00
|
|
|
namespace Simon {
|
|
|
|
|
2003-11-12 16:00:11 +00:00
|
|
|
#ifdef __PALM_OS__
|
|
|
|
#define PTR(a) a
|
|
|
|
static const GameSpecificSettings *simon1_settings;
|
|
|
|
static const GameSpecificSettings *simon1acorn_settings;
|
|
|
|
static const GameSpecificSettings *simon1amiga_settings;
|
|
|
|
static const GameSpecificSettings *simon1demo_settings;
|
|
|
|
static const GameSpecificSettings *simon2win_settings;
|
|
|
|
static const GameSpecificSettings *simon2dos_settings;
|
|
|
|
#else
|
2003-11-13 00:00:49 +00:00
|
|
|
#define PTR(a) &a
|
2002-08-18 16:21:34 +00:00
|
|
|
static const GameSpecificSettings simon1_settings = {
|
2003-12-21 16:01:36 +00:00
|
|
|
"SIMON.GME", // gme_filename
|
|
|
|
"SIMON.WAV", // wav_filename
|
|
|
|
"SIMON.VOC", // voc_filename
|
|
|
|
"SIMON.MP3", // mp3_filename
|
|
|
|
"SIMON.OGG", // vorbis_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"SIMON.FLA", // flac_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"EFFECTS.VOC", // voc_effects_filename
|
|
|
|
"EFFECTS.MP3", // mp3_effects_filename
|
|
|
|
"EFFECTS.OGG", // vorbis_effects_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"EFFECTS.FLA", // flac_effects_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"GAMEPC", // gamepc_filename
|
2002-08-18 16:21:34 +00:00
|
|
|
};
|
|
|
|
|
2003-09-24 06:19:30 +00:00
|
|
|
static const GameSpecificSettings simon1acorn_settings = {
|
2003-12-21 16:01:36 +00:00
|
|
|
"DATA", // gme_filename
|
|
|
|
"", // wav_filename
|
|
|
|
"SIMON", // voc_filename
|
|
|
|
"SIMON.MP3", // mp3_filename
|
|
|
|
"SIMON.OGG", // vorbis_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"SIMON.FLA", // flac_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"EFFECTS", // voc_effects_filename
|
|
|
|
"EFFECTS.MP3", // mp3_effects_filename
|
|
|
|
"EFFECTS.OGG", // vorbis_effects_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"EFFECTS.FLA", // flac_effects_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"GAMEBASE", // gamepc_filename
|
2003-09-24 06:19:30 +00:00
|
|
|
};
|
|
|
|
|
2003-01-14 05:25:31 +00:00
|
|
|
static const GameSpecificSettings simon1amiga_settings = {
|
2003-12-21 16:01:36 +00:00
|
|
|
"", // gme_filename
|
|
|
|
"", // wav_filename
|
|
|
|
"", // voc_filename
|
|
|
|
"SIMON.MP3", // mp3_filename
|
|
|
|
"SIMON.OGG", // vorbis_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"SIMON.FLA", // flac_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"", // voc_effects_filename
|
|
|
|
"", // mp3_effects_filename
|
|
|
|
"", // vorbis_effects_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"", // flac_effects_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"gameamiga", // gamepc_filename
|
2003-01-14 04:25:38 +00:00
|
|
|
};
|
|
|
|
|
2002-10-24 09:40:20 +00:00
|
|
|
static const GameSpecificSettings simon1demo_settings = {
|
2003-12-21 16:01:36 +00:00
|
|
|
"", // gme_filename
|
|
|
|
"", // wav_filename
|
|
|
|
"", // voc_filename
|
|
|
|
"", // mp3_filename
|
|
|
|
"", // vorbis_filename
|
2004-07-30 11:02:47 +00:00
|
|
|
"", // flac_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"", // voc_effects_filename
|
|
|
|
"", // mp3_effects_filename
|
|
|
|
"", // vorbis_effects_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"", // flac_effects_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"GDEMO", // gamepc_filename
|
2002-10-24 09:40:20 +00:00
|
|
|
};
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
static const GameSpecificSettings simon2win_settings = {
|
2003-12-21 16:01:36 +00:00
|
|
|
"SIMON2.GME", // gme_filename
|
|
|
|
"SIMON2.WAV", // wav_filename
|
|
|
|
"SIMON2.VOC", // voc_filename
|
|
|
|
"SIMON2.MP3", // mp3_filename
|
|
|
|
"SIMON2.OGG", // vorbis_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"SIMON2.FLA", // flac_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"", // voc_effects_filename
|
|
|
|
"", // mp3_effects_filename
|
|
|
|
"", // vorbis_effects_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"", // flac_effects_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"GSPTR30", // gamepc_filename
|
2002-08-18 16:21:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GameSpecificSettings simon2dos_settings = {
|
2003-12-21 16:01:36 +00:00
|
|
|
"SIMON2.GME", // gme_filename
|
|
|
|
"", // wav_filename
|
|
|
|
"", // voc_filename
|
|
|
|
"", // mp3_filename
|
|
|
|
"", // vorbis_filename
|
2004-07-30 11:02:47 +00:00
|
|
|
"", // flac_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"", // voc_effects_filename
|
|
|
|
"", // mp3_effects_filename
|
|
|
|
"", // vorbis_effects_filename
|
2004-02-22 14:11:16 +00:00
|
|
|
"", // flac_effects_filename
|
2003-12-21 16:01:36 +00:00
|
|
|
"GAME32", // gamepc_filename
|
2002-08-18 16:21:34 +00:00
|
|
|
};
|
2005-10-06 14:34:24 +00:00
|
|
|
|
|
|
|
static const GameSpecificSettings feeblefiles_settings = {
|
2005-10-09 09:03:37 +00:00
|
|
|
"", // gme_filename
|
|
|
|
"VOICES.WAV", // wav_filename
|
|
|
|
"VOICES.VOC", // voc_filename
|
|
|
|
"VOICES.MP3", // mp3_filename
|
|
|
|
"VOICES.OGG", // vorbis_filename
|
|
|
|
"VOICES.FLA", // flac_filename
|
2005-10-06 14:34:24 +00:00
|
|
|
"", // voc_effects_filename
|
|
|
|
"", // mp3_effects_filename
|
|
|
|
"", // vorbis_effects_filename
|
|
|
|
"", // flac_effects_filename
|
|
|
|
"GAME22", // gamepc_filename
|
|
|
|
};
|
2003-11-12 16:00:11 +00:00
|
|
|
#endif
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2005-05-09 10:51:00 +00:00
|
|
|
static const char* bad_versions[3] = {
|
|
|
|
"465eed710cc242b2de7dc77edd467c4c", // simon1dos (English)
|
|
|
|
"bed9134804d96f72afa152b8ec5628c3", // simon1dos (French)
|
2005-05-09 10:54:24 +00:00
|
|
|
"27c8e7feada80c75b70b9c2f6088d519", // simon2dos (English)
|
2005-05-09 10:51:00 +00:00
|
|
|
};
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
SimonEngine::SimonEngine(GameDetector *detector, OSystem *syst)
|
2003-12-13 00:20:01 +00:00
|
|
|
: Engine(syst), midi(syst) {
|
2005-06-21 22:08:21 +00:00
|
|
|
int j =0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vcPtr = 0;
|
2004-12-18 01:33:21 +00:00
|
|
|
_vc_get_out_of_code = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameOffsetsPtr = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-09-22 22:55:01 +00:00
|
|
|
_debugger = 0;
|
|
|
|
|
2004-07-30 09:15:18 +00:00
|
|
|
const SimonGameSettings *g = simon_settings;
|
|
|
|
while (g->name) {
|
|
|
|
if (!scumm_stricmp(detector->_game.name, g->name))
|
|
|
|
break;
|
|
|
|
g++;
|
|
|
|
}
|
|
|
|
if (!g->name)
|
|
|
|
error("Invalid game '%s'\n", detector->_game.name);
|
|
|
|
|
|
|
|
SimonGameSettings game = *g;
|
|
|
|
|
|
|
|
switch (Common::parsePlatform(ConfMan.get("platform"))) {
|
|
|
|
case Common::kPlatformAmiga:
|
|
|
|
case Common::kPlatformMacintosh:
|
|
|
|
if (game.features & GF_SIMON2)
|
|
|
|
game.features |= GF_WIN;
|
|
|
|
break;
|
|
|
|
case Common::kPlatformWindows:
|
|
|
|
game.features |= GF_WIN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_game = game.features;
|
2003-06-21 15:32:35 +00:00
|
|
|
|
2004-07-31 13:56:04 +00:00
|
|
|
// Convert older targets
|
|
|
|
if (g->detectname == NULL) {
|
|
|
|
if (!strcmp("simon1win", g->name)) {
|
2005-07-30 21:11:48 +00:00
|
|
|
ConfMan.set("gameid", "simon1talkie");
|
|
|
|
ConfMan.set("platform", "Windows");
|
2004-07-31 13:56:04 +00:00
|
|
|
} else if (!strcmp("simon2win", g->name) || !strcmp("simon2mac", g->name)) {
|
2005-07-30 21:11:48 +00:00
|
|
|
ConfMan.set("gameid", "simon2talkie");
|
|
|
|
ConfMan.set("platform", "Windows");
|
2004-07-30 11:02:47 +00:00
|
|
|
}
|
2004-07-31 13:56:04 +00:00
|
|
|
ConfMan.flushToDisk();
|
|
|
|
} else {
|
|
|
|
char buf[100];
|
|
|
|
uint8 md5sum[16];
|
2004-08-21 00:47:29 +00:00
|
|
|
File f;
|
2004-07-30 11:02:47 +00:00
|
|
|
|
2004-07-31 13:56:04 +00:00
|
|
|
sprintf(buf, g->detectname);
|
2004-08-21 00:47:29 +00:00
|
|
|
f.open(buf);
|
|
|
|
if (f.isOpen() == false)
|
|
|
|
strcat(buf, ".");
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
if (Common::md5_file(buf, md5sum)) {
|
2004-07-31 13:56:04 +00:00
|
|
|
char md5str[32+1];
|
2005-06-21 22:08:21 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
2004-11-09 16:43:45 +00:00
|
|
|
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
2004-07-31 13:56:04 +00:00
|
|
|
}
|
|
|
|
|
2005-06-21 22:08:21 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2005-05-09 10:51:00 +00:00
|
|
|
if (!strcmp(md5str, bad_versions[j]))
|
2005-05-09 10:54:24 +00:00
|
|
|
error("Cracked versions aren't supported");
|
2005-05-09 10:51:00 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 13:56:04 +00:00
|
|
|
printf("%s %s\n", md5str, buf);
|
|
|
|
const MD5Table *elem;
|
|
|
|
elem = (const MD5Table *)bsearch(md5str, md5table, ARRAYSIZE(md5table)-1, sizeof(MD5Table), compareMD5Table);
|
|
|
|
if (elem)
|
|
|
|
printf("Match found in database: target %s, language %s, platform %s\n",
|
|
|
|
elem->target, Common::getLanguageDescription(elem->language), Common::getPlatformDescription(elem->platform));
|
|
|
|
else
|
|
|
|
printf("Unknown MD5! Please report the details (language, platform, etc.) of this game to the ScummVM team\n");
|
|
|
|
}
|
|
|
|
}
|
2004-07-30 11:02:47 +00:00
|
|
|
|
|
|
|
VGA_DELAY_BASE = 1;
|
2005-10-09 09:03:37 +00:00
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
|
|
|
NUM_VIDEO_OP_CODES = 85;
|
|
|
|
#ifndef __PALM_OS__
|
2005-10-09 12:12:24 +00:00
|
|
|
VGA_MEM_SIZE = 7500000;
|
2005-10-09 09:03:37 +00:00
|
|
|
#else
|
|
|
|
VGA_MEM_SIZE = gVars->memory[kMemSimon2Games];
|
|
|
|
#endif
|
2005-10-09 12:12:24 +00:00
|
|
|
TABLES_MEM_SIZE = 200000;
|
2005-10-09 09:03:37 +00:00
|
|
|
} else if (_game & GF_SIMON2) {
|
2003-12-01 00:45:16 +00:00
|
|
|
TABLE_INDEX_BASE = 1580 / 4;
|
|
|
|
TEXT_INDEX_BASE = 1500 / 4;
|
|
|
|
NUM_VIDEO_OP_CODES = 75;
|
2003-12-02 11:17:21 +00:00
|
|
|
#ifndef __PALM_OS__
|
2003-12-01 00:45:16 +00:00
|
|
|
VGA_MEM_SIZE = 2000000;
|
2003-12-02 11:17:21 +00:00
|
|
|
#else
|
|
|
|
VGA_MEM_SIZE = gVars->memory[kMemSimon2Games];
|
|
|
|
#endif
|
2003-12-01 00:45:16 +00:00
|
|
|
TABLES_MEM_SIZE = 100000;
|
2005-05-06 03:09:53 +00:00
|
|
|
// Check whether to use MT-32 MIDI tracks in Simon the Sorcerer 2
|
|
|
|
if ((_game & GF_SIMON2) && (ConfMan.getBool("native_mt32") || (_midiDriver == MD_MT32)))
|
2003-12-09 10:19:27 +00:00
|
|
|
MUSIC_INDEX_BASE = (1128 + 612) / 4;
|
|
|
|
else
|
|
|
|
MUSIC_INDEX_BASE = 1128 / 4;
|
2003-12-01 00:45:16 +00:00
|
|
|
SOUND_INDEX_BASE = 1660 / 4;
|
|
|
|
} else {
|
|
|
|
TABLE_INDEX_BASE = 1576 / 4;
|
|
|
|
TEXT_INDEX_BASE = 1460 / 4;
|
|
|
|
NUM_VIDEO_OP_CODES = 64;
|
2003-12-02 11:17:21 +00:00
|
|
|
#ifndef __PALM_OS__
|
2003-12-01 00:45:16 +00:00
|
|
|
VGA_MEM_SIZE = 1000000;
|
2003-12-02 11:17:21 +00:00
|
|
|
#else
|
|
|
|
VGA_MEM_SIZE = gVars->memory[kMemSimon1Games];
|
|
|
|
#endif
|
2003-12-01 00:45:16 +00:00
|
|
|
TABLES_MEM_SIZE = 50000;
|
|
|
|
MUSIC_INDEX_BASE = 1316 / 4;
|
|
|
|
SOUND_INDEX_BASE = 0;
|
|
|
|
}
|
|
|
|
|
2004-08-16 04:19:43 +00:00
|
|
|
_language = Common::parseLanguage(ConfMan.get("language"));
|
2005-10-06 14:34:24 +00:00
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
|
|
|
gss = PTR(feeblefiles_settings);
|
|
|
|
} else if (_game & GF_SIMON2) {
|
2005-05-08 02:50:43 +00:00
|
|
|
if (_game & GF_TALKIE) {
|
|
|
|
gss = PTR(simon2win_settings);
|
|
|
|
|
|
|
|
// Add default file directories
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "voices/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "VOICES/");
|
|
|
|
} else {
|
|
|
|
gss = PTR(simon2dos_settings);
|
|
|
|
}
|
|
|
|
} else if (_game & GF_SIMON1) {
|
|
|
|
if (_game & GF_ACORN) {
|
|
|
|
gss = PTR(simon1acorn_settings);
|
|
|
|
|
|
|
|
// Add default file directories
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "execute/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "EXECUTE/");
|
|
|
|
} else if (_game & GF_AMIGA) {
|
|
|
|
gss = PTR(simon1amiga_settings);
|
|
|
|
} else if (_game & GF_DEMO) {
|
|
|
|
gss = PTR(simon1demo_settings);
|
|
|
|
} else {
|
|
|
|
gss = PTR(simon1_settings);
|
|
|
|
}
|
|
|
|
}
|
2004-06-28 00:06:31 +00:00
|
|
|
|
2005-05-08 02:50:43 +00:00
|
|
|
if ((_game & GF_SIMON1) && (_game & GF_TALKIE)) {
|
2004-06-28 00:40:25 +00:00
|
|
|
// Add default file directories
|
2005-04-07 12:11:35 +00:00
|
|
|
switch (_language) {
|
2004-06-28 00:40:25 +00:00
|
|
|
case 20:
|
2004-10-08 16:09:52 +00:00
|
|
|
File::addDefaultDirectory(_gameDataPath + "hebrew/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "HEBREW/");
|
2004-06-28 00:40:25 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2004-10-08 16:09:52 +00:00
|
|
|
File::addDefaultDirectory(_gameDataPath + "spanish/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "SPANISH/");
|
2004-06-28 00:40:25 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2004-10-08 16:09:52 +00:00
|
|
|
File::addDefaultDirectory(_gameDataPath + "italian/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "ITALIAN/");
|
2004-06-28 00:40:25 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2004-10-08 16:09:52 +00:00
|
|
|
File::addDefaultDirectory(_gameDataPath + "french/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "FRENCH/");
|
2004-06-28 00:40:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_keyPressed = 0;
|
2003-06-21 15:32:35 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_strippedTxtMem = 0;
|
|
|
|
_textSize = 0;
|
|
|
|
_stringTabNum = 0;
|
|
|
|
_stringTabPos = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
_stringtab_numalloc = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_stringTabPtr = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemArrayPtr = 0;
|
|
|
|
_itemArraySize = 0;
|
|
|
|
_itemArrayInited = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemHeapPtr = 0;
|
|
|
|
_itemHeapCurPos = 0;
|
|
|
|
_itemHeapSize = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_iconFilePtr = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_tblList = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_codePtr = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_localStringtable = 0;
|
|
|
|
_stringIdLocalMin = 1;
|
|
|
|
_stringIdLocalMax = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesHeapPtr = 0;
|
|
|
|
_tablesHeapPtrOrg = 0;
|
|
|
|
_tablesheapPtrNew = 0;
|
|
|
|
_tablesHeapSize = 0;
|
|
|
|
_tablesHeapCurPos = 0;
|
|
|
|
_tablesHeapCurPosOrg = 0;
|
|
|
|
_tablesHeapCurPosNew = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_subroutineList = 0;
|
|
|
|
_subroutineListOrg = 0;
|
2003-12-23 08:59:30 +00:00
|
|
|
_subroutine = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_dxSurfacePitch = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_recursionDepth = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastVgaTick = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
_marks = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_scriptVar2 = 0;
|
|
|
|
_runScriptReturn1 = 0;
|
|
|
|
_skipVgaWait = 0;
|
|
|
|
_noParentNotify = 0;
|
|
|
|
_vgaRes328Loaded = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
_hitarea_unk_3 = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_mortalFlag = 0;
|
|
|
|
_videoVar8 = 0;
|
|
|
|
_usePaletteDelay = 0;
|
|
|
|
_syncFlag2 = 0;
|
|
|
|
_inCallBack = 0;
|
|
|
|
_cepeFlag = 0;
|
|
|
|
_copyPartialMode = 0;
|
2003-12-18 09:36:17 +00:00
|
|
|
_speed = 1;
|
2005-05-06 11:37:33 +00:00
|
|
|
_fastMode = 0;
|
|
|
|
_dxUse3Or4ForLock = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
|
|
|
_debugMode = 0;
|
2003-12-10 00:54:53 +00:00
|
|
|
_pause = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_startMainScript = 0;
|
|
|
|
_continousMainScript = 0;
|
|
|
|
_startVgaScript = 0;
|
|
|
|
_continousVgaScript = 0;
|
|
|
|
_drawImagesDebug = 0;
|
|
|
|
_dumpImages = 0;
|
2003-12-18 11:04:02 +00:00
|
|
|
_speech = true;
|
2004-01-01 06:29:27 +00:00
|
|
|
_subtitles = true;
|
2003-12-18 10:47:12 +00:00
|
|
|
_fade = true;
|
2005-05-06 11:37:33 +00:00
|
|
|
_mouseCursor = 0;
|
|
|
|
_vgaVar9 = 0;
|
|
|
|
_scriptUnk1 = 0;
|
|
|
|
_vgaVar6 = 0;
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollX = 0;
|
2005-10-09 09:03:37 +00:00
|
|
|
_scrollY = 0;
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollXMax = 0;
|
2005-10-09 09:03:37 +00:00
|
|
|
_scrollYMax = 0;
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollCount = 0;
|
|
|
|
_scrollFlag = 0;
|
|
|
|
_scrollHeight = 0;
|
2005-10-09 09:03:37 +00:00
|
|
|
_scrollWidth = 0;
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollImage = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaVar8 = 0;
|
|
|
|
|
|
|
|
_scriptCondA = 0;
|
|
|
|
_scriptCondB = 0;
|
|
|
|
_scriptCondC = 0;
|
|
|
|
|
|
|
|
_fcsUnk1 = 0;
|
|
|
|
_fcsPtr1 = 0;
|
|
|
|
|
|
|
|
_subjectItem = 0;
|
|
|
|
_objectItem = 0;
|
|
|
|
_item1 = 0;
|
|
|
|
|
|
|
|
_hitAreaObjectItem = 0;
|
|
|
|
_lastHitArea = 0;
|
|
|
|
_lastHitArea2Ptr = 0;
|
|
|
|
_lastHitArea3 = 0;
|
|
|
|
_leftButtonDown = 0;
|
|
|
|
_hitAreaSubjectItem = 0;
|
|
|
|
_hitAreaPtr5 = 0;
|
|
|
|
_hitAreaPtr7 = 0;
|
|
|
|
_needHitAreaRecalc = 0;
|
|
|
|
_verbHitArea = 0;
|
|
|
|
_hitAreaUnk4 = 0;
|
|
|
|
_lockCounter = 0;
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
_windowNum = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
|
|
|
|
_printCharUnk1 = 0;
|
|
|
|
_printCharUnk2 = 0;
|
|
|
|
_numLettersToPrint = 0;
|
|
|
|
|
|
|
|
_lastTime = 0;
|
|
|
|
|
|
|
|
_firstTimeStruct = 0;
|
|
|
|
_pendingDeleteTimeEvent = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-05-20 14:12:57 +00:00
|
|
|
_base_time = 0;
|
2002-08-18 17:48:18 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_mouseX = 0;
|
|
|
|
_mouseY = 0;
|
|
|
|
_mouseXOld = 0;
|
|
|
|
_mouseYOld = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_dummyItem1 = new Item();
|
|
|
|
_dummyItem2 = new Item();
|
|
|
|
_dummyItem3 = new Item();
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord = 0;
|
|
|
|
_scrollUpHitArea = 0;
|
|
|
|
_scrollDownHitArea = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar7 = 0xFFFF;
|
|
|
|
_paletteColorCount = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar4 = 0;
|
|
|
|
_videoVar5 = 0;
|
|
|
|
_videoVar3 = 0;
|
|
|
|
_unkPalFlag = 0;
|
|
|
|
_exitCutscene = 0;
|
|
|
|
_skipSpeech = 0;
|
|
|
|
_videoVar9 = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_soundFileId = 0;
|
|
|
|
_lastMusicPlayed = -1;
|
|
|
|
_nextMusicToPlay = -1;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_showPreposition = 0;
|
|
|
|
_showMessageFlag = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoNumPalColors = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaSpriteChanged = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaBufFreeStart = 0;
|
|
|
|
_vgaBufEnd = 0;
|
|
|
|
_vgaBufStart = 0;
|
|
|
|
_vgaFileBufOrg = 0;
|
|
|
|
_vgaFileBufOrg2 = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_curVgaFile1 = 0;
|
|
|
|
_curVgaFile2 = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_timer1 = 0;
|
|
|
|
_timer5 = 0;
|
|
|
|
_timer4 = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
_frameRate = 1;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaCurFile2 = 0;
|
|
|
|
_vgaWaitFor = 0;
|
|
|
|
_vgaCurFileId = 0;
|
|
|
|
_vgaCurSpriteId = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_nextVgaTimerToProcess = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_vcItemArray, 0, sizeof(_vcItemArray));
|
|
|
|
memset(_itemArray6, 0, sizeof(_itemArray6));
|
2003-05-20 14:34:07 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_stringIdArray2, 0, sizeof(_stringIdArray2));
|
|
|
|
memset(_stringIdArray3, 0, sizeof(_stringIdArray3));
|
|
|
|
memset(_speechIdArray4, 0, sizeof(_speechIdArray4));
|
2003-05-20 14:34:07 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_bitArray, 0, sizeof(_bitArray));
|
2003-05-20 14:34:07 +00:00
|
|
|
memset(_variableArray, 0, sizeof(_variableArray));
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_fcsPtrArray3, 0, sizeof(_fcsPtrArray3));
|
2003-05-20 14:34:07 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_fcsData1, 0, sizeof(_fcsData1));
|
|
|
|
memset(_fcsData2, 0, sizeof(_fcsData2));
|
2003-05-20 14:34:07 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_freeStringSlot = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-21 15:42:20 +00:00
|
|
|
memset(_stringReturnBuffer, 0, sizeof(_stringReturnBuffer));
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_pathFindArray, 0, sizeof(_pathFindArray));
|
2003-05-20 14:34:07 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_paletteBackup, 0, sizeof(_paletteBackup));
|
2003-05-20 14:34:07 +00:00
|
|
|
memset(_palette, 0, sizeof(_palette));
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_videoBuf1, 0, sizeof(_videoBuf1));
|
2003-05-20 14:34:07 +00:00
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
_fcs_list = new FillOrCopyStruct[16];
|
2002-08-18 17:48:18 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_lettersToPrintBuf, 0, sizeof(_lettersToPrintBuf));
|
2003-07-30 01:43:28 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_numScreenUpdates = 0;
|
|
|
|
_vgaTickCounter = 0;
|
2003-05-21 15:47:51 +00:00
|
|
|
|
|
|
|
_sound = 0;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_effectsPaused = false;
|
|
|
|
_ambientPaused = false;
|
|
|
|
_musicPaused = false;
|
2003-05-21 15:47:51 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_dumpFile = 0;
|
2003-05-20 14:12:57 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_saveLoadType = 0;
|
2003-12-11 02:09:18 +00:00
|
|
|
_saveLoadSlot = 0;
|
|
|
|
memset(_saveLoadName, 0, sizeof(_saveLoadName));
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_saveLoadRowCurPos = 0;
|
|
|
|
_numSaveGameRows = 0;
|
|
|
|
_saveDialogFlag = false;
|
|
|
|
_saveOrLoad = false;
|
|
|
|
_saveLoadFlag = false;
|
2003-05-21 15:47:51 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_sdlMouseX = 0;
|
|
|
|
_sdlMouseY = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-05-21 15:47:51 +00:00
|
|
|
_sdl_buf_3 = 0;
|
|
|
|
_sdl_buf = 0;
|
|
|
|
_sdl_buf_attached = 0;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vc10BasePtrOld = 0;
|
2003-08-02 07:00:58 +00:00
|
|
|
memcpy (_hebrew_char_widths,
|
|
|
|
"\x5\x5\x4\x6\x5\x3\x4\x5\x6\x3\x5\x5\x4\x6\x5\x3\x4\x6\x5\x6\x6\x6\x5\x5\x5\x6\x5\x6\x6\x6\x6\x6", 32);
|
2005-10-07 07:36:09 +00:00
|
|
|
|
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
|
|
|
_screenWidth = 640;
|
|
|
|
_screenHeight = 480;
|
|
|
|
} else {
|
|
|
|
_screenWidth = 320;
|
|
|
|
_screenHeight = 200;
|
|
|
|
}
|
2004-11-23 00:03:25 +00:00
|
|
|
}
|
2003-08-02 07:00:58 +00:00
|
|
|
|
2004-11-24 00:14:21 +00:00
|
|
|
int SimonEngine::init(GameDetector &detector) {
|
2003-08-06 00:19:20 +00:00
|
|
|
// Setup mixer
|
2003-12-24 17:42:22 +00:00
|
|
|
if (!_mixer->isReady())
|
2003-08-06 00:19:20 +00:00
|
|
|
warning("Sound initialization failed. "
|
|
|
|
"Features of the game that depend on sound synchronization will most likely break");
|
2005-01-22 02:01:22 +00:00
|
|
|
set_volume(ConfMan.getInt("sfx_volume"));
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
2003-08-06 00:19:20 +00:00
|
|
|
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->beginGFXTransaction();
|
|
|
|
initCommonGFX(detector);
|
2005-10-07 07:36:09 +00:00
|
|
|
_system->initSize(_screenWidth, _screenHeight);
|
|
|
|
if (_game == GAME_FEEBLEFILES)
|
|
|
|
_system->setGraphicsMode("1x");
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->endGFXTransaction();
|
2004-10-23 00:02:38 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// Setup midi driver
|
2003-12-12 15:28:44 +00:00
|
|
|
MidiDriver *driver = 0;
|
2004-10-23 00:02:38 +00:00
|
|
|
_midiDriver = MD_NULL;
|
2003-12-12 15:28:44 +00:00
|
|
|
if (_game == GAME_SIMON1AMIGA || _game == GAME_SIMON1CD32)
|
2004-12-02 00:33:42 +00:00
|
|
|
driver = MidiDriver::createMidi(MD_NULL); // Create fake MIDI driver for Simon1Amiga and Simon2CD32 for now
|
2004-10-23 00:02:38 +00:00
|
|
|
else {
|
2004-12-02 00:33:42 +00:00
|
|
|
_midiDriver = MidiDriver::detectMusicDriver(MDT_ADLIB | MDT_NATIVE);
|
|
|
|
driver = MidiDriver::createMidi(_midiDriver);
|
2004-10-23 00:02:38 +00:00
|
|
|
}
|
2002-10-10 18:51:36 +00:00
|
|
|
if (!driver)
|
2003-08-05 23:58:24 +00:00
|
|
|
driver = MidiDriver_ADLIB_create(_mixer);
|
2004-10-23 00:02:38 +00:00
|
|
|
else if (ConfMan.getBool("native_mt32") || (_midiDriver == MD_MT32))
|
2003-10-08 21:59:23 +00:00
|
|
|
driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
2003-07-14 08:48:38 +00:00
|
|
|
|
2004-10-23 00:02:38 +00:00
|
|
|
midi.mapMT32toGM (!(_game & GF_SIMON2) && !(ConfMan.getBool("native_mt32") || (_midiDriver == MD_MT32)));
|
|
|
|
|
2002-08-18 17:48:18 +00:00
|
|
|
midi.set_driver(driver);
|
2003-05-18 23:55:53 +00:00
|
|
|
int ret = midi.open();
|
|
|
|
if (ret)
|
|
|
|
warning ("MIDI Player init failed: \"%s\"", midi.getErrorName (ret));
|
2003-10-08 21:59:23 +00:00
|
|
|
midi.set_volume(ConfMan.getInt("music_volume"));
|
2002-12-06 15:24:14 +00:00
|
|
|
|
2005-04-24 12:21:53 +00:00
|
|
|
_debugMode = (gDebugLevel >= 0);
|
2003-07-18 15:37:06 +00:00
|
|
|
|
2003-12-21 16:55:50 +00:00
|
|
|
if (ConfMan.hasKey("music_mute") && ConfMan.getBool("music_mute") == 1)
|
2005-05-06 11:37:33 +00:00
|
|
|
midi.pause(_musicPaused ^= 1);
|
2003-12-21 16:55:50 +00:00
|
|
|
|
2003-12-21 14:42:19 +00:00
|
|
|
if ((_game & GF_SIMON2) && ConfMan.hasKey("speech_mute") && ConfMan.getBool("speech_mute") == 1)
|
2003-12-18 11:16:10 +00:00
|
|
|
_speech = 0;
|
|
|
|
|
2004-01-01 06:29:27 +00:00
|
|
|
if ((!(_game & GF_SIMON2) && _language > 1) || ((_game & GF_SIMON2) && _language == 20)) {
|
2003-12-18 10:48:48 +00:00
|
|
|
if (ConfMan.hasKey("subtitles") && ConfMan.getBool("subtitles") == 0)
|
2003-12-18 10:47:12 +00:00
|
|
|
_subtitles = 0;
|
2003-12-22 11:08:35 +00:00
|
|
|
} else
|
2003-12-18 10:47:12 +00:00
|
|
|
_subtitles = ConfMan.getBool("subtitles");
|
|
|
|
|
2003-12-22 11:08:35 +00:00
|
|
|
// Make sure either speech or subtitles is enabled
|
|
|
|
if ((_game & GF_TALKIE) && !_speech && !_subtitles)
|
|
|
|
_subtitles = 1;
|
|
|
|
|
2003-12-18 10:47:12 +00:00
|
|
|
if (ConfMan.hasKey("fade") && ConfMan.getBool("fade") == 0)
|
|
|
|
_fade = 0;
|
2003-12-22 11:08:35 +00:00
|
|
|
|
2003-12-18 09:36:17 +00:00
|
|
|
if (ConfMan.hasKey("slow_down") && ConfMan.getInt("slow_down") >= 1)
|
|
|
|
_speed = ConfMan.getInt("slow_down");
|
|
|
|
|
2003-07-20 15:31:47 +00:00
|
|
|
// FIXME Use auto dirty rects cleanup code to reduce CPU usage
|
2004-02-24 22:39:42 +00:00
|
|
|
g_system->setFeatureState(OSystem::kFeatureAutoComputeDirtyRects, true);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
2002-08-18 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
SimonEngine::~SimonEngine() {
|
2005-05-06 11:37:33 +00:00
|
|
|
delete _gameFile;
|
2004-12-18 02:08:32 +00:00
|
|
|
|
|
|
|
midi.close();
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
free(_stringTabPtr);
|
|
|
|
free(_itemArrayPtr);
|
|
|
|
free(_itemHeapPtr - _itemHeapCurPos);
|
|
|
|
free(_tablesHeapPtr - _tablesHeapCurPos);
|
|
|
|
free(_tblList);
|
|
|
|
free(_iconFilePtr);
|
|
|
|
free(_gameOffsetsPtr);
|
|
|
|
|
|
|
|
delete _dummyItem1;
|
|
|
|
delete _dummyItem2;
|
|
|
|
delete _dummyItem3;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
delete [] _fcs_list;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-21 15:53:27 +00:00
|
|
|
delete _sound;
|
2004-01-27 16:28:39 +00:00
|
|
|
delete _debugger;
|
2002-08-18 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::errorString(const char *buf1, char *buf2) {
|
2003-03-07 15:38:11 +00:00
|
|
|
strcpy(buf2, buf1);
|
2005-05-09 11:39:31 +00:00
|
|
|
|
2005-05-09 12:12:14 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
if (isSmartphone())
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Unless an error -originated- within the debugger, spawn the
|
|
|
|
// debugger. Otherwise exit out normally.
|
2005-05-09 11:39:31 +00:00
|
|
|
if (_debugger && !_debugger->isAttached()) {
|
2005-05-09 12:12:14 +00:00
|
|
|
// (Print it again in case debugger segfaults)
|
|
|
|
printf("%s\n", buf2);
|
2005-05-09 11:39:31 +00:00
|
|
|
_debugger->attach(buf2);
|
|
|
|
_debugger->onFrame();
|
|
|
|
}
|
2003-03-07 15:38:11 +00:00
|
|
|
}
|
|
|
|
|
2005-08-11 18:08:55 +00:00
|
|
|
void SimonEngine::palette_fadeout(uint32 *pal_values, uint num) {
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *p = (byte *)pal_values;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (p[0] >= 8)
|
|
|
|
p[0] -= 8;
|
|
|
|
else
|
|
|
|
p[0] = 0;
|
|
|
|
if (p[1] >= 8)
|
|
|
|
p[1] -= 8;
|
|
|
|
else
|
|
|
|
p[1] = 0;
|
|
|
|
if (p[2] >= 8)
|
|
|
|
p[2] -= 8;
|
|
|
|
else
|
|
|
|
p[2] = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
p += sizeof(uint32);
|
|
|
|
} while (--num);
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte *SimonEngine::allocateItem(uint size) {
|
2005-05-06 11:37:33 +00:00
|
|
|
byte *org = _itemHeapPtr;
|
2002-04-13 21:06:48 +00:00
|
|
|
size = (size + 3) & ~3;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemHeapPtr += size;
|
|
|
|
_itemHeapCurPos += size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_itemHeapCurPos > _itemHeapSize)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("Itemheap overflow");
|
|
|
|
|
|
|
|
return org;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::alignTableMem() {
|
2005-05-06 11:37:33 +00:00
|
|
|
if ((unsigned long)_tablesHeapPtr & 3) {
|
|
|
|
_tablesHeapPtr += 2;
|
|
|
|
_tablesHeapCurPos += 2;
|
2002-04-13 21:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte *SimonEngine::allocateTable(uint size) {
|
2005-05-06 11:37:33 +00:00
|
|
|
byte *org = _tablesHeapPtr;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
size = (size + 1) & ~1;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesHeapPtr += size;
|
|
|
|
_tablesHeapCurPos += size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_tablesHeapCurPos > _tablesHeapSize)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("Tablesheap overflow");
|
|
|
|
|
|
|
|
return org;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
int SimonEngine::allocGamePcVars(File *in) {
|
2002-04-12 21:26:59 +00:00
|
|
|
uint item_array_size, item_array_inited, stringtable_num;
|
|
|
|
uint32 version;
|
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-10-21 13:23:25 +00:00
|
|
|
item_array_size = in->readUint32BE();
|
|
|
|
version = in->readUint32BE();
|
|
|
|
item_array_inited = in->readUint32BE();
|
|
|
|
stringtable_num = in->readUint32BE();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
item_array_inited += 2; // first two items are predefined
|
2002-04-12 21:26:59 +00:00
|
|
|
item_array_size += 2;
|
|
|
|
|
|
|
|
if (version != 0x80)
|
|
|
|
error("Not a runtime database");
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemArrayPtr = (Item **)calloc(item_array_size, sizeof(Item *));
|
|
|
|
if (_itemArrayPtr == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("Out of memory for Item array");
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemArraySize = item_array_size;
|
|
|
|
_itemArrayInited = item_array_inited;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-15 13:07:06 +00:00
|
|
|
for (i = 1; i < item_array_inited; i++) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemArrayPtr[i] = (Item *)allocateItem(sizeof(Item));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// The rest is cleared automatically by calloc
|
2002-04-12 21:26:59 +00:00
|
|
|
allocateStringTable(stringtable_num + 10);
|
2005-05-06 11:37:33 +00:00
|
|
|
_stringTabNum = stringtable_num;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
return item_array_inited;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::loginPlayerHelper(Item *item, int a, int b) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Child9 *child;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
child = (Child9 *) findChildOfType(item, 9);
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child == NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
child = (Child9 *) allocateChildBlock(item, 9, sizeof(Child9));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a >= 0 && a <= 3)
|
2002-04-12 21:26:59 +00:00
|
|
|
child->array[a] = b;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::loginPlayer() {
|
2002-04-12 21:26:59 +00:00
|
|
|
Child *child;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_item1 = _itemArrayPtr[1];
|
2005-10-03 14:08:07 +00:00
|
|
|
_item1->adjective = -1;
|
|
|
|
_item1->noun = 10000;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
child = (Child *)allocateChildBlock(_item1, 3, sizeof(Child));
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child == NULL)
|
|
|
|
error("player create failure");
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
loginPlayerHelper(_item1, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::allocateStringTable(int num) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_stringTabPtr = (byte **)calloc(num, sizeof(byte *));
|
|
|
|
_stringTabPos = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
_stringtab_numalloc = num;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::setupStringTable(byte *mem, int num) {
|
2002-04-12 21:26:59 +00:00
|
|
|
int i = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_stringTabPtr[i++] = mem;
|
2002-04-12 21:26:59 +00:00
|
|
|
if (--num == 0)
|
|
|
|
break;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (; *mem; mem++);
|
2002-04-12 21:26:59 +00:00
|
|
|
mem++;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_stringTabPos = i;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::setupLocalStringTable(byte *mem, int num) {
|
2002-04-12 21:26:59 +00:00
|
|
|
int i = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_localStringtable[i++] = mem;
|
2002-04-12 21:26:59 +00:00
|
|
|
if (--num == 0)
|
|
|
|
break;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (; *mem; mem++);
|
2002-04-12 21:26:59 +00:00
|
|
|
mem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::readSubroutineLine(File *in, SubroutineLine *sl, Subroutine *sub) {
|
2002-04-12 21:26:59 +00:00
|
|
|
byte line_buffer[1024], *q = line_buffer;
|
|
|
|
int size;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (sub->id == 0) {
|
2002-10-21 13:23:25 +00:00
|
|
|
sl->cond_a = in->readUint16BE();
|
|
|
|
sl->cond_b = in->readUint16BE();
|
|
|
|
sl->cond_c = in->readUint16BE();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-09-16 08:22:30 +00:00
|
|
|
while ((*q = in->readByte()) != 0xFF) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (*q == 87) {
|
2002-10-21 13:23:25 +00:00
|
|
|
in->readUint16BE();
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
|
|
|
q = readSingleOpcode(in, q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = q - line_buffer + 1;
|
|
|
|
|
|
|
|
memcpy(allocateTable(size), line_buffer, size);
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
SubroutineLine *SimonEngine::createSubroutineLine(Subroutine *sub, int where) {
|
2002-04-12 21:26:59 +00:00
|
|
|
SubroutineLine *sl, *cur_sl = NULL, *last_sl = NULL;
|
|
|
|
|
|
|
|
if (sub->id == 0)
|
2002-07-07 19:06:48 +00:00
|
|
|
sl = (SubroutineLine *)allocateTable(SUBROUTINE_LINE_BIG_SIZE);
|
2002-04-12 21:26:59 +00:00
|
|
|
else
|
2002-07-07 19:06:48 +00:00
|
|
|
sl = (SubroutineLine *)allocateTable(SUBROUTINE_LINE_SMALL_SIZE);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// where is what offset to insert the line at, locate the proper beginning line
|
2002-04-12 21:26:59 +00:00
|
|
|
if (sub->first != 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
cur_sl = (SubroutineLine *)((byte *)sub + sub->first);
|
2002-04-12 21:26:59 +00:00
|
|
|
while (where) {
|
|
|
|
last_sl = cur_sl;
|
2002-07-07 19:06:48 +00:00
|
|
|
cur_sl = (SubroutineLine *)((byte *)sub + cur_sl->next);
|
|
|
|
if ((byte *)cur_sl == (byte *)sub)
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
where--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_sl != NULL) {
|
2003-05-19 00:38:35 +00:00
|
|
|
// Insert the subroutine line in the middle of the link
|
2002-07-07 19:06:48 +00:00
|
|
|
last_sl->next = (byte *)sl - (byte *)sub;
|
|
|
|
sl->next = (byte *)cur_sl - (byte *)sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2003-05-19 00:38:35 +00:00
|
|
|
// Insert the subroutine line at the head of the link
|
2002-04-12 21:26:59 +00:00
|
|
|
sl->next = sub->first;
|
2002-07-07 19:06:48 +00:00
|
|
|
sub->first = (byte *)sl - (byte *)sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sl;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::readSubroutine(File *in, Subroutine *sub) {
|
2002-10-21 13:23:25 +00:00
|
|
|
while (in->readUint16BE() == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
readSubroutineLine(in, createSubroutineLine(sub, 0xFFFF), sub);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Subroutine *SimonEngine::createSubroutine(uint id) {
|
2002-04-13 21:06:48 +00:00
|
|
|
Subroutine *sub;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-13 21:06:48 +00:00
|
|
|
alignTableMem();
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
sub = (Subroutine *)allocateTable(sizeof(Subroutine));
|
2002-04-12 21:26:59 +00:00
|
|
|
sub->id = id;
|
|
|
|
sub->first = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
sub->next = _subroutineList;
|
|
|
|
_subroutineList = sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::readSubroutineBlock(File *in) {
|
2002-10-21 13:23:25 +00:00
|
|
|
while (in->readUint16BE() == 0) {
|
|
|
|
readSubroutine(in, createSubroutine(in->readUint16BE()));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Child *SimonEngine::findChildOfType(Item *i, uint type) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Child *child = i->children;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (; child; child = child->next)
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child->type == type)
|
|
|
|
return child;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::hasChildOfType1(Item *item) {
|
2002-10-30 23:52:19 +00:00
|
|
|
return findChildOfType(item, 1) != NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::hasChildOfType2(Item *item) {
|
2002-10-30 23:52:19 +00:00
|
|
|
return findChildOfType(item, 2) != NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::getOffsetOfChild2Param(Child2 *child, uint prop) {
|
2002-04-12 21:26:59 +00:00
|
|
|
uint m = 1;
|
|
|
|
uint offset = 0;
|
|
|
|
while (m != prop) {
|
|
|
|
if (child->avail_props & m)
|
|
|
|
offset++;
|
2002-07-07 19:06:48 +00:00
|
|
|
m <<= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Child *SimonEngine::allocateChildBlock(Item *i, uint type, uint size) {
|
2002-07-07 19:06:48 +00:00
|
|
|
Child *child = (Child *)allocateItem(size);
|
2002-04-12 21:26:59 +00:00
|
|
|
child->next = i->children;
|
|
|
|
i->children = child;
|
|
|
|
child->type = type;
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::allocItemHeap() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_itemHeapSize = 10000;
|
|
|
|
_itemHeapCurPos = 0;
|
|
|
|
_itemHeapPtr = (byte *)calloc(10000, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::allocTablesHeap() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesHeapSize = TABLES_MEM_SIZE;
|
|
|
|
_tablesHeapCurPos = 0;
|
|
|
|
_tablesHeapPtr = (byte *)calloc(TABLES_MEM_SIZE, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 14:08:07 +00:00
|
|
|
void SimonEngine::setItemState(Item *item, int value) {
|
|
|
|
item->state = value;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
int SimonEngine::getNextWord() {
|
2005-05-06 11:37:33 +00:00
|
|
|
int16 a = (int16)READ_BE_UINT16(_codePtr);
|
|
|
|
_codePtr += 2;
|
2004-12-18 02:08:32 +00:00
|
|
|
return a;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::getNextStringID() {
|
2002-06-29 16:11:13 +00:00
|
|
|
return (uint16)getNextWord();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::getVarOrByte() {
|
2005-05-06 11:37:33 +00:00
|
|
|
uint a = *_codePtr++;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a != 255)
|
2002-06-29 16:11:13 +00:00
|
|
|
return a;
|
2005-05-06 11:37:33 +00:00
|
|
|
return readVariable(*_codePtr++);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::getVarOrWord() {
|
2005-05-06 11:37:33 +00:00
|
|
|
uint a = READ_BE_UINT16(_codePtr);
|
|
|
|
_codePtr += 2;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a >= 30000 && a < 30512)
|
2002-06-29 16:11:13 +00:00
|
|
|
return readVariable(a - 30000);
|
|
|
|
return a;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Item *SimonEngine::getNextItemPtr() {
|
2002-06-29 16:11:13 +00:00
|
|
|
int a = getNextWord();
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (a) {
|
|
|
|
case -1:
|
2005-05-06 11:37:33 +00:00
|
|
|
return _subjectItem;
|
2002-07-07 19:06:48 +00:00
|
|
|
case -3:
|
2005-05-06 11:37:33 +00:00
|
|
|
return _objectItem;
|
2002-07-07 19:06:48 +00:00
|
|
|
case -5:
|
|
|
|
return getItem1Ptr();
|
|
|
|
case -7:
|
|
|
|
return getItemPtrB();
|
|
|
|
case -9:
|
|
|
|
return derefItem(getItem1Ptr()->parent);
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
return derefItem(a);
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Item *SimonEngine::getNextItemPtrStrange() {
|
2002-06-29 16:11:13 +00:00
|
|
|
int a = getNextWord();
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (a) {
|
|
|
|
case -1:
|
2005-05-06 11:37:33 +00:00
|
|
|
return _subjectItem;
|
2002-07-07 19:06:48 +00:00
|
|
|
case -3:
|
2005-05-06 11:37:33 +00:00
|
|
|
return _objectItem;
|
2002-07-07 19:06:48 +00:00
|
|
|
case -5:
|
2005-05-06 11:37:33 +00:00
|
|
|
return _dummyItem2;
|
2002-07-07 19:06:48 +00:00
|
|
|
case -7:
|
|
|
|
return NULL;
|
|
|
|
case -9:
|
2005-05-06 11:37:33 +00:00
|
|
|
return _dummyItem3;
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
return derefItem(a);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::getNextItemID() {
|
2002-06-29 16:11:13 +00:00
|
|
|
int a = getNextWord();
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (a) {
|
|
|
|
case -1:
|
2005-05-06 11:37:33 +00:00
|
|
|
return itemPtrToID(_subjectItem);
|
2002-07-07 19:06:48 +00:00
|
|
|
case -3:
|
2005-05-06 11:37:33 +00:00
|
|
|
return itemPtrToID(_objectItem);
|
2002-07-07 19:06:48 +00:00
|
|
|
case -5:
|
|
|
|
return getItem1ID();
|
|
|
|
case -7:
|
|
|
|
return 0;
|
|
|
|
case -9:
|
|
|
|
return getItem1Ptr()->parent;
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
return a;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Item *SimonEngine::getItem1Ptr() {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_item1)
|
|
|
|
return _item1;
|
|
|
|
return _dummyItem1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Item *SimonEngine::getItemPtrB() {
|
2002-06-29 16:11:13 +00:00
|
|
|
error("getItemPtrB: is this code ever used?");
|
2005-05-06 11:37:33 +00:00
|
|
|
return _dummyItem1;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::getNextVarContents() {
|
2002-06-29 16:11:13 +00:00
|
|
|
return (uint16)readVariable(getVarOrByte());
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::readVariable(uint variable) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (variable >= 255)
|
|
|
|
error("Variable %d out of range in read", variable);
|
|
|
|
return _variableArray[variable];
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::writeNextVarContents(uint16 contents) {
|
2002-06-29 16:11:13 +00:00
|
|
|
writeVariable(getVarOrByte(), contents);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::writeVariable(uint variable, uint16 contents) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (variable >= 256)
|
|
|
|
error("Variable %d out of range in write", variable);
|
|
|
|
_variableArray[variable] = contents;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::setItemParent(Item *item, Item *parent) {
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *old_parent = derefItem(item->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (item == parent)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("Trying to set item as its own parent");
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// unlink it if it has a parent
|
2002-06-29 16:11:13 +00:00
|
|
|
if (old_parent)
|
|
|
|
unlinkItem(item);
|
|
|
|
itemChildrenChanged(old_parent);
|
|
|
|
linkItem(item, parent);
|
|
|
|
itemChildrenChanged(parent);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::itemChildrenChanged(Item *item) {
|
2002-06-29 16:11:13 +00:00
|
|
|
int i;
|
|
|
|
FillOrCopyStruct *fcs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_noParentNotify)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
lock();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 8; i++) {
|
2005-05-06 11:37:33 +00:00
|
|
|
fcs = _fcsPtrArray3[i];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (fcs && fcs->fcs_data && fcs->fcs_data->item_ptr == item) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_fcsData1[i]) {
|
|
|
|
_fcsData2[i] = true;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_fcsData2[i] = false;
|
2005-10-19 10:54:22 +00:00
|
|
|
drawIconArray(i, item, fcs->fcs_data->unk1, fcs->fcs_data->unk2);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock();
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::unlinkItem(Item *item) {
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *first, *parent, *next;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// can't unlink item without parent
|
2002-06-29 16:11:13 +00:00
|
|
|
if (item->parent == 0)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// get parent and first child of parent
|
2002-06-29 16:11:13 +00:00
|
|
|
parent = derefItem(item->parent);
|
|
|
|
first = derefItem(parent->child);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// the node to remove is first in the parent's children?
|
2002-06-29 16:11:13 +00:00
|
|
|
if (first == item) {
|
|
|
|
parent->child = item->sibling;
|
|
|
|
item->parent = 0;
|
|
|
|
item->sibling = 0;
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!first)
|
|
|
|
error("unlinkItem: parent empty");
|
|
|
|
if (first->sibling == 0)
|
|
|
|
error("unlinkItem: parent does not contain child");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
next = derefItem(first->sibling);
|
|
|
|
if (next == item) {
|
|
|
|
first->sibling = next->sibling;
|
|
|
|
item->parent = 0;
|
|
|
|
item->sibling = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::linkItem(Item *item, Item *parent) {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint id;
|
2003-05-19 00:38:35 +00:00
|
|
|
// Don't allow that an item that is already linked is relinked
|
2002-06-29 16:11:13 +00:00
|
|
|
if (item->parent)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
id = itemPtrToID(parent);
|
|
|
|
item->parent = id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (parent != 0) {
|
|
|
|
item->sibling = parent->child;
|
|
|
|
parent->child = itemPtrToID(item);
|
|
|
|
} else {
|
|
|
|
item->sibling = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
const byte *SimonEngine::getStringPtrByID(uint string_id) {
|
2002-06-29 16:11:13 +00:00
|
|
|
const byte *string_ptr;
|
|
|
|
byte *dst;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_freeStringSlot ^= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (string_id < 0x8000) {
|
2005-05-06 11:37:33 +00:00
|
|
|
string_ptr = _stringTabPtr[string_id];
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
|
|
|
string_ptr = getLocalStringByID(string_id);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
dst = _stringReturnBuffer[_freeStringSlot];
|
2002-07-07 19:06:48 +00:00
|
|
|
strcpy((char *)dst, (const char *)string_ptr);
|
2002-06-29 16:11:13 +00:00
|
|
|
return dst;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
const byte *SimonEngine::getLocalStringByID(uint string_id) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (string_id < _stringIdLocalMin || string_id >= _stringIdLocalMax) {
|
2002-06-29 16:11:13 +00:00
|
|
|
loadTextIntoMem(string_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
return _localStringtable[string_id - _stringIdLocalMin];
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::loadTextIntoMem(uint string_id) {
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *p;
|
|
|
|
char filename[30];
|
|
|
|
int i;
|
|
|
|
uint base_min = 0x8000, base_max, size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesHeapPtr = _tablesheapPtrNew;
|
|
|
|
_tablesHeapCurPos = _tablesHeapCurPosNew;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
p = _strippedTxtMem;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// get filename
|
2002-06-29 16:11:13 +00:00
|
|
|
while (*p) {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; *p; p++, i++)
|
2002-06-29 16:11:13 +00:00
|
|
|
filename[i] = *p;
|
2002-07-07 19:06:48 +00:00
|
|
|
filename[i] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
p++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
base_max = (p[0] << 8) | p[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
p += 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (string_id < base_max) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_stringIdLocalMin = base_min;
|
|
|
|
_stringIdLocalMax = base_max;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_localStringtable = (byte **)_tablesHeapPtr;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
size = (base_max - base_min + 1) * sizeof(byte *);
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesHeapPtr += size;
|
|
|
|
_tablesHeapCurPos += size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
size = loadTextFile(filename, _tablesHeapPtr);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
setupLocalStringTable(_tablesHeapPtr, base_max - base_min + 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesHeapPtr += size;
|
|
|
|
_tablesHeapCurPos += size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_tablesHeapCurPos > _tablesHeapSize) {
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTextIntoMem: Out of table memory");
|
|
|
|
}
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
base_min = base_max;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTextIntoMem: didn't find %d", string_id);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::loadTablesIntoMem(uint subr_id) {
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *p;
|
|
|
|
int i;
|
|
|
|
uint min_num, max_num;
|
|
|
|
char filename[30];
|
2002-09-16 08:22:30 +00:00
|
|
|
File *in;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
p = _tblList;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (p == NULL)
|
2002-07-07 19:06:48 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
while (*p) {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; *p; p++, i++)
|
2002-06-29 16:11:13 +00:00
|
|
|
filename[i] = *p;
|
|
|
|
filename[i] = 0;
|
|
|
|
p++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
|
|
|
min_num = (p[0] << 8) | p[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
p += 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (min_num == 0)
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
max_num = (p[0] << 8) | p[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
p += 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id >= min_num && subr_id <= max_num) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_subroutineList = _subroutineListOrg;
|
|
|
|
_tablesHeapPtr = _tablesHeapPtrOrg;
|
|
|
|
_tablesHeapCurPos = _tablesHeapCurPosOrg;
|
|
|
|
_stringIdLocalMin = 1;
|
|
|
|
_stringIdLocalMax = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
in = openTablesFile(filename);
|
|
|
|
readSubroutineBlock(in);
|
|
|
|
closeTablesFile(in);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-12 00:51:14 +00:00
|
|
|
if (_game == GAME_SIMON2DOS || _game == GAME_SIMON2TALKIE || _game == GAME_SIMON2WIN) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_sound->loadSfxTable(_gameFile, _gameOffsetsPtr[atoi(filename + 6) - 1 + SOUND_INDEX_BASE]);
|
2005-10-06 14:34:24 +00:00
|
|
|
} else if (_game == GAME_SIMON1TALKIE) {
|
2003-05-25 03:03:40 +00:00
|
|
|
memcpy(filename, "SFXXXX", 6);
|
2004-06-27 22:14:35 +00:00
|
|
|
_sound->readSfxFile(filename);
|
2002-11-24 12:53:01 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
alignTableMem();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_tablesheapPtrNew = _tablesHeapPtr;
|
|
|
|
_tablesHeapCurPosNew = _tablesHeapCurPos;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_tablesHeapCurPos > _tablesHeapSize)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTablesIntoMem: Out of table memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-12-18 02:08:32 +00:00
|
|
|
debug(1,"loadTablesIntoMem: didn't find %d", subr_id);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::playSting(uint a) {
|
2003-05-24 01:26:05 +00:00
|
|
|
if (!midi._enable_sfx)
|
2003-01-05 00:47:49 +00:00
|
|
|
return;
|
|
|
|
|
2004-01-01 08:42:49 +00:00
|
|
|
char filename[15];
|
2003-01-03 12:06:30 +00:00
|
|
|
|
2003-06-15 09:55:10 +00:00
|
|
|
File mus_file;
|
2003-06-21 15:53:27 +00:00
|
|
|
uint16 mus_offset;
|
2003-06-15 09:55:10 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
sprintf(filename, "STINGS%i.MUS", _soundFileId);
|
2004-06-27 22:14:35 +00:00
|
|
|
mus_file.open(filename);
|
2003-06-15 09:55:10 +00:00
|
|
|
if (!mus_file.isOpen()) {
|
2003-01-03 12:33:53 +00:00
|
|
|
warning("Can't load sound effect from '%s'", filename);
|
2003-01-05 00:47:49 +00:00
|
|
|
return;
|
2003-01-03 12:33:53 +00:00
|
|
|
}
|
2003-01-03 12:06:30 +00:00
|
|
|
|
2003-06-21 15:53:27 +00:00
|
|
|
mus_file.seek(a * 2, SEEK_SET);
|
|
|
|
mus_offset = mus_file.readUint16LE();
|
|
|
|
if (mus_file.ioFailed())
|
|
|
|
error("Can't read sting %d offset", a);
|
2003-01-03 12:33:53 +00:00
|
|
|
|
2003-06-21 15:53:27 +00:00
|
|
|
mus_file.seek(mus_offset, SEEK_SET);
|
|
|
|
midi.loadSMF(&mus_file, a, true);
|
|
|
|
midi.startTrack(0);
|
2003-01-03 12:06:30 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Subroutine *SimonEngine::getSubroutineByID(uint subroutine_id) {
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *cur;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-12-23 08:59:30 +00:00
|
|
|
_subroutine = subroutine_id;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (cur = _subroutineList; cur; cur = cur->next) {
|
2003-12-23 09:03:29 +00:00
|
|
|
if (cur->id == subroutine_id)
|
2002-06-29 16:11:13 +00:00
|
|
|
return cur;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
loadTablesIntoMem(subroutine_id);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (cur = _subroutineList; cur; cur = cur->next) {
|
2003-12-23 09:03:29 +00:00
|
|
|
if (cur->id == subroutine_id)
|
2002-06-29 16:11:13 +00:00
|
|
|
return cur;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-07-15 16:40:24 +00:00
|
|
|
debug(1,"getSubroutineByID: subroutine %d not found", subroutine_id);
|
2002-06-29 16:11:13 +00:00
|
|
|
return NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::loadTextFile_gme(const char *filename, byte *dst) {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint res;
|
|
|
|
uint32 offs;
|
|
|
|
uint32 size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-12-01 00:45:16 +00:00
|
|
|
res = atoi(filename + 4) + TEXT_INDEX_BASE - 1;
|
2005-05-06 11:37:33 +00:00
|
|
|
offs = _gameOffsetsPtr[res];
|
|
|
|
size = _gameOffsetsPtr[res + 1] - offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
resfile_read(dst, offs, size);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return size;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
File *SimonEngine::openTablesFile_gme(const char *filename) {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint res;
|
|
|
|
uint32 offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-12-01 00:45:16 +00:00
|
|
|
res = atoi(filename + 6) + TABLE_INDEX_BASE - 1;
|
2005-05-06 11:37:33 +00:00
|
|
|
offs = _gameOffsetsPtr[res];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(offs, SEEK_SET);
|
|
|
|
return _gameFile;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::loadTextFile_simon1(const char *filename, byte *dst) {
|
2002-09-16 08:22:30 +00:00
|
|
|
File fo;
|
2004-06-27 22:14:35 +00:00
|
|
|
fo.open(filename);
|
2002-06-29 16:11:13 +00:00
|
|
|
uint32 size;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-09-16 08:22:30 +00:00
|
|
|
if (fo.isOpen() == false)
|
2003-01-03 10:36:13 +00:00
|
|
|
error("loadTextFile: Can't open '%s'", filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-10-21 12:34:54 +00:00
|
|
|
size = fo.size();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-09-16 08:22:30 +00:00
|
|
|
if (fo.read(dst, size) != size)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTextFile: fread failed");
|
2002-09-16 08:22:30 +00:00
|
|
|
fo.close();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return size;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
File *SimonEngine::openTablesFile_simon1(const char *filename) {
|
2002-09-16 08:22:30 +00:00
|
|
|
File *fo = new File();
|
2004-06-27 22:14:35 +00:00
|
|
|
fo->open(filename);
|
2002-09-16 08:22:30 +00:00
|
|
|
if (fo->isOpen() == false)
|
2003-01-03 10:36:13 +00:00
|
|
|
error("openTablesFile: Can't open '%s'", filename);
|
2002-06-29 16:11:13 +00:00
|
|
|
return fo;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::loadTextFile(const char *filename, byte *dst) {
|
2003-12-02 06:23:05 +00:00
|
|
|
if (_game & GF_OLD_BUNDLE)
|
2002-06-29 16:11:13 +00:00
|
|
|
return loadTextFile_simon1(filename, dst);
|
|
|
|
else
|
|
|
|
return loadTextFile_gme(filename, dst);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
File *SimonEngine::openTablesFile(const char *filename) {
|
2003-12-02 06:23:05 +00:00
|
|
|
if (_game & GF_OLD_BUNDLE)
|
2002-06-29 16:11:13 +00:00
|
|
|
return openTablesFile_simon1(filename);
|
|
|
|
else
|
|
|
|
return openTablesFile_gme(filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::closeTablesFile(File *in) {
|
2003-12-02 06:23:05 +00:00
|
|
|
if (_game & GF_OLD_BUNDLE) {
|
2003-06-15 05:19:00 +00:00
|
|
|
in->close();
|
|
|
|
delete in;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::addTimeEvent(uint timeout, uint subroutine_id) {
|
2002-07-07 19:06:48 +00:00
|
|
|
TimeEvent *te = (TimeEvent *)malloc(sizeof(TimeEvent)), *first, *last = NULL;
|
2002-06-29 16:11:13 +00:00
|
|
|
time_t cur_time;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
time(&cur_time);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
te->time = cur_time + timeout - _base_time;
|
|
|
|
te->subroutine_id = subroutine_id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
first = _firstTimeStruct;
|
2002-06-29 16:11:13 +00:00
|
|
|
while (first) {
|
|
|
|
if (te->time <= first->time) {
|
|
|
|
if (last) {
|
|
|
|
last->next = te;
|
|
|
|
te->next = first;
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
te->next = _firstTimeStruct;
|
|
|
|
_firstTimeStruct = te;
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
|
|
|
|
last = first;
|
|
|
|
first = first->next;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (last) {
|
|
|
|
last->next = te;
|
|
|
|
te->next = NULL;
|
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_firstTimeStruct = te;
|
2002-06-29 16:11:13 +00:00
|
|
|
te->next = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::delTimeEvent(TimeEvent *te) {
|
2002-06-29 16:11:13 +00:00
|
|
|
TimeEvent *cur;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (te == _pendingDeleteTimeEvent)
|
|
|
|
_pendingDeleteTimeEvent = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (te == _firstTimeStruct) {
|
|
|
|
_firstTimeStruct = te->next;
|
2002-06-29 16:11:13 +00:00
|
|
|
free(te);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
cur = _firstTimeStruct;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (cur == NULL)
|
|
|
|
error("delTimeEvent: none available");
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (cur->next == NULL)
|
|
|
|
error("delTimeEvent: no such te");
|
|
|
|
if (te == cur->next) {
|
|
|
|
cur->next = te->next;
|
|
|
|
free(te);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::killAllTimers() {
|
2002-06-29 16:11:13 +00:00
|
|
|
TimeEvent *cur, *next;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (cur = _firstTimeStruct; cur; cur = next) {
|
2002-06-29 16:11:13 +00:00
|
|
|
next = cur->next;
|
|
|
|
delTimeEvent(cur);
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::kickoffTimeEvents() {
|
2002-06-29 16:11:13 +00:00
|
|
|
time_t cur_time;
|
|
|
|
TimeEvent *te;
|
|
|
|
bool result = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
time(&cur_time);
|
|
|
|
cur_time -= _base_time;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
while ((te = _firstTimeStruct) != NULL && te->time <= (uint32)cur_time) {
|
2002-06-29 16:11:13 +00:00
|
|
|
result = true;
|
2005-05-06 11:37:33 +00:00
|
|
|
_pendingDeleteTimeEvent = te;
|
2002-06-29 16:11:13 +00:00
|
|
|
invokeTimeEvent(te);
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_pendingDeleteTimeEvent) {
|
|
|
|
_pendingDeleteTimeEvent = NULL;
|
2002-06-29 16:11:13 +00:00
|
|
|
delTimeEvent(te);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::invokeTimeEvent(TimeEvent *te) {
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_scriptCondA = 0;
|
|
|
|
if (_runScriptReturn1)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
|
|
|
sub = getSubroutineByID(te->subroutine_id);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
2005-05-06 11:37:33 +00:00
|
|
|
_runScriptReturn1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_setup_cond_c() {
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
setup_cond_c_helper();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_objectItem = _hitAreaObjectItem;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_objectItem == _dummyItem2)
|
|
|
|
_objectItem = getItem1Ptr();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_objectItem == _dummyItem3)
|
|
|
|
_objectItem = derefItem(getItem1Ptr()->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_objectItem != NULL) {
|
2005-10-03 14:08:07 +00:00
|
|
|
_scriptCondC = _objectItem->noun;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_scriptCondC = -1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::setup_cond_c_helper() {
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *last;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_mouseCursor = 0;
|
|
|
|
if (_hitAreaUnk4 != 999) {
|
|
|
|
_mouseCursor = 9;
|
|
|
|
_needHitAreaRecalc++;
|
|
|
|
_hitAreaUnk4 = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastHitArea = 0;
|
|
|
|
_hitAreaObjectItem = NULL;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
last = _lastHitArea2Ptr;
|
2002-06-29 16:11:13 +00:00
|
|
|
defocusHitarea();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastHitArea2Ptr = last;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastHitArea = NULL;
|
|
|
|
_lastHitArea3 = 0;
|
|
|
|
_leftButtonDown = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
do {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_exitCutscene && (_bitArray[0] & 0x200)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
startSubroutine170();
|
|
|
|
goto out_of_here;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
delay(100);
|
2005-05-06 11:37:33 +00:00
|
|
|
} while (_lastHitArea3 == (HitArea *) 0xFFFFFFFF || _lastHitArea3 == 0);
|
|
|
|
|
|
|
|
if (_lastHitArea == NULL) {
|
|
|
|
} else if (_lastHitArea->id == 0x7FFB) {
|
|
|
|
handle_uparrow_hitarea(_lastHitArea->fcs);
|
|
|
|
} else if (_lastHitArea->id == 0x7FFC) {
|
|
|
|
handle_downarrow_hitarea(_lastHitArea->fcs);
|
|
|
|
} else if (_lastHitArea->item_ptr != NULL) {
|
|
|
|
_hitAreaObjectItem = _lastHitArea->item_ptr;
|
|
|
|
_variableArray[60] = (_lastHitArea->flags & 1) ? (_lastHitArea->flags >> 8) : 0xFFFF;
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
out_of_here:
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastHitArea3 = 0;
|
|
|
|
_lastHitArea = 0;
|
|
|
|
_lastHitArea2Ptr = NULL;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::startSubroutine170() {
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-12-07 17:36:38 +00:00
|
|
|
_sound->stopVoice();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
sub = getSubroutineByID(170);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_runScriptReturn1 = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::get_fcs_ptr_3_index(FillOrCopyStruct *fcs) {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (i = 0; i != ARRAYSIZE(_fcsPtrArray3); i++)
|
|
|
|
if (_fcsPtrArray3[i] == fcs)
|
2002-06-29 16:11:13 +00:00
|
|
|
return i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
error("get_fcs_ptr_3_index: not found");
|
2005-06-21 22:08:21 +00:00
|
|
|
return 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::lock() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockCounter++;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::unlock() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockCounter != 0)
|
|
|
|
_lockCounter--;
|
2002-12-07 18:00:25 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~1;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::handle_mouse_moved() {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint x;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockCounter) {
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->showMouse(false);
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2003-05-23 11:06:19 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->showMouse(true);
|
2002-06-29 16:11:13 +00:00
|
|
|
pollMouseXY();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_mouseX >= 32768)
|
|
|
|
_mouseX = 0;
|
|
|
|
if (_mouseX >= 638 / 2)
|
|
|
|
_mouseX = 638 / 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_mouseY >= 32768)
|
|
|
|
_mouseY = 0;
|
|
|
|
if (_mouseY >= 199)
|
|
|
|
_mouseY = 199;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_hitAreaUnk4) {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint id = 101;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_mouseY >= 136)
|
2002-06-29 16:11:13 +00:00
|
|
|
id = 102;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_hitAreaUnk4 != id)
|
2002-06-29 16:11:13 +00:00
|
|
|
hitarea_proc_1();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_bitArray[4] & 0x8000) {
|
|
|
|
if (!_vgaVar9) {
|
|
|
|
if (_mouseX >= 630 / 2 || _mouseX < 9)
|
2002-06-29 16:11:13 +00:00
|
|
|
goto get_out2;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaVar9 = 1;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollCount == 0) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_mouseX >= 631 / 2) {
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollX != _scrollXMax)
|
|
|
|
_scrollFlag = 1;
|
2005-05-06 11:37:33 +00:00
|
|
|
} else if (_mouseX < 8) {
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollX != 0)
|
|
|
|
_scrollFlag = -1;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
get_out2:;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaVar9 = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_mouseX != _mouseXOld || _mouseY != _mouseYOld)
|
|
|
|
_needHitAreaRecalc++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
x = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lastHitArea3 == 0 && _leftButtonDown != 0) {
|
|
|
|
_leftButtonDown = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
x = 1;
|
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_hitarea_unk_3 == 0 && _needHitAreaRecalc == 0)
|
2002-07-07 19:06:48 +00:00
|
|
|
goto get_out;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
setup_hitarea_from_pos(_mouseX, _mouseY, x);
|
|
|
|
_lastHitArea3 = _lastHitArea;
|
|
|
|
if (x == 1 && _lastHitArea == NULL)
|
|
|
|
_lastHitArea3 = (HitArea *) - 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
get_out:
|
|
|
|
draw_mouse_pointer();
|
2005-05-06 11:37:33 +00:00
|
|
|
_needHitAreaRecalc = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-10-19 10:54:22 +00:00
|
|
|
void SimonEngine::drawIconArray(uint fcs_index, Item *item_ptr, int unk1, int unk2) {
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *item_ptr_org = item_ptr;
|
|
|
|
FillOrCopyStruct *fcs_ptr;
|
|
|
|
uint width_div_3, height_div_3;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint j, k, i, num_sibs_with_flag;
|
2002-06-29 16:11:13 +00:00
|
|
|
bool item_again;
|
|
|
|
uint x_pos, y_pos;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
fcs_ptr = _fcsPtrArray3[fcs_index & 7];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
width_div_3 = fcs_ptr->width / 3;
|
|
|
|
height_div_3 = fcs_ptr->height / 3;
|
|
|
|
} else {
|
|
|
|
width_div_3 = 100;
|
|
|
|
height_div_3 = 40;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
i = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (fcs_ptr == NULL)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (fcs_ptr->fcs_data)
|
2005-10-19 10:54:22 +00:00
|
|
|
removeIconArray(fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
fcs_ptr->fcs_data = (FillOrCopyData *) malloc(sizeof(FillOrCopyData));
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_ptr->fcs_data->item_ptr = item_ptr;
|
2005-10-19 10:54:22 +00:00
|
|
|
fcs_ptr->fcs_data->upArrow = -1;
|
|
|
|
fcs_ptr->fcs_data->downArrow = -1;
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_ptr->fcs_data->unk1 = unk1;
|
|
|
|
fcs_ptr->fcs_data->unk2 = unk2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
item_ptr = derefItem(item_ptr->child);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
while (item_ptr && unk1-- != 0) {
|
|
|
|
num_sibs_with_flag = 0;
|
|
|
|
while (item_ptr && width_div_3 > num_sibs_with_flag) {
|
2005-10-03 14:08:07 +00:00
|
|
|
if ((unk2 == 0 || item_ptr->classFlags & unk2) && has_item_childflag_0x10(item_ptr))
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
num_sibs_with_flag++;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
num_sibs_with_flag += 20;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
item_ptr = derefItem(item_ptr->sibling);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (item_ptr == NULL) {
|
|
|
|
fcs_ptr->fcs_data->unk1 = 0;
|
|
|
|
item_ptr = derefItem(item_ptr_org->child);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
x_pos = 0;
|
|
|
|
y_pos = 0;
|
|
|
|
item_again = false;
|
|
|
|
k = 0;
|
|
|
|
j = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
while (item_ptr) {
|
2005-10-03 14:08:07 +00:00
|
|
|
if ((unk2 == 0 || item_ptr->classFlags & unk2) && has_item_childflag_0x10(item_ptr)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (item_again == false) {
|
|
|
|
fcs_ptr->fcs_data->e[k].item = item_ptr;
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-07-07 19:06:48 +00:00
|
|
|
draw_icon_c(fcs_ptr, item_get_icon_number(item_ptr), x_pos * 3, y_pos);
|
|
|
|
fcs_ptr->fcs_data->e[k].hit_area =
|
|
|
|
setup_icon_hit_area(fcs_ptr, x_pos * 3, y_pos,
|
|
|
|
item_get_icon_number(item_ptr), item_ptr);
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
draw_icon_c(fcs_ptr, item_get_icon_number(item_ptr), x_pos, y_pos);
|
2002-07-07 19:06:48 +00:00
|
|
|
fcs_ptr->fcs_data->e[k].hit_area =
|
|
|
|
setup_icon_hit_area(fcs_ptr, x_pos, y_pos, item_get_icon_number(item_ptr), item_ptr);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
k++;
|
|
|
|
} else {
|
|
|
|
fcs_ptr->fcs_data->e[k].item = NULL;
|
|
|
|
j = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2003-03-01 22:52:49 +00:00
|
|
|
x_pos += (_game & GF_SIMON2) ? 20 : 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (x_pos >= width_div_3) {
|
|
|
|
x_pos = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
y_pos += (_game & GF_SIMON2) ? 20 : 1;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (y_pos >= height_div_3)
|
|
|
|
item_again = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
item_ptr = derefItem(item_ptr->sibling);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_ptr->fcs_data->e[k].item = NULL;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (j != 0 || fcs_ptr->fcs_data->unk1 != 0) {
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_unk_proc_2(fcs_ptr, fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fcs_unk_proc_2(FillOrCopyStruct *fcs, uint fcs_index) {
|
2002-06-29 16:11:13 +00:00
|
|
|
setup_hit_areas(fcs, fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-19 10:54:22 +00:00
|
|
|
fcs->fcs_data->upArrow = _scrollUpHitArea;
|
|
|
|
fcs->fcs_data->downArrow = _scrollDownHitArea;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::setup_hit_areas(FillOrCopyStruct *fcs, uint fcs_index) {
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *ha;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ha = findEmptyHitArea();
|
2005-05-06 11:37:33 +00:00
|
|
|
_scrollUpHitArea = ha - _hitAreas;
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
ha->x = 308;
|
|
|
|
ha->y = 149;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 17;
|
|
|
|
ha->flags = 0x24;
|
|
|
|
ha->id = 0x7FFB;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
ha->x = 81;
|
|
|
|
ha->y = 158;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 26;
|
|
|
|
ha->flags = 36;
|
|
|
|
ha->id = 0x7FFB;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ha = findEmptyHitArea();
|
2005-05-06 11:37:33 +00:00
|
|
|
_scrollDownHitArea = ha - _hitAreas;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
ha->x = 308;
|
|
|
|
ha->y = 176;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 17;
|
|
|
|
ha->flags = 0x24;
|
|
|
|
ha->id = 0x7FFC;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// Simon1 specific
|
2003-05-24 12:26:28 +00:00
|
|
|
o_kill_sprite_simon1(0x80);
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(0, 1, 0x80, 0, 0, 0xE);
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
|
|
|
ha->x = 227;
|
|
|
|
ha->y = 162;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 26;
|
|
|
|
ha->flags = 36;
|
|
|
|
ha->id = 0x7FFC;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::has_item_childflag_0x10(Item *item) {
|
2002-10-30 23:52:19 +00:00
|
|
|
Child2 *child = (Child2 *)findChildOfType(item, 2);
|
2002-06-29 16:11:13 +00:00
|
|
|
return child && (child->avail_props & 0x10) != 0;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::item_get_icon_number(Item *item) {
|
2002-10-30 23:52:19 +00:00
|
|
|
Child2 *child = (Child2 *)findChildOfType(item, 2);
|
2002-06-29 16:11:13 +00:00
|
|
|
uint offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (child == NULL || !(child->avail_props & 0x10))
|
2002-06-29 16:11:13 +00:00
|
|
|
return 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
offs = getOffsetOfChild2Param(child, 0x10);
|
|
|
|
return child->array[offs];
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::f10_key() {
|
2003-08-10 15:58:38 +00:00
|
|
|
HitArea *ha, *dha;
|
2003-01-12 15:17:58 +00:00
|
|
|
uint count;
|
|
|
|
uint y_, x_;
|
|
|
|
byte *dst;
|
2003-08-05 17:39:06 +00:00
|
|
|
uint b, color;
|
2003-01-12 15:17:58 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x8000;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-08-05 17:39:06 +00:00
|
|
|
if (_game & GF_SIMON2)
|
|
|
|
color = 0xec;
|
|
|
|
else
|
|
|
|
color = 0xe1;
|
|
|
|
|
2003-12-23 10:00:51 +00:00
|
|
|
uint limit = (_game & GF_SIMON2) ? 200 : 134;
|
2003-08-05 17:39:06 +00:00
|
|
|
|
2003-01-12 15:17:58 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
2005-05-06 11:37:33 +00:00
|
|
|
ha = _hitAreas;
|
|
|
|
count = ARRAYSIZE(_hitAreas);
|
2003-01-12 15:17:58 +00:00
|
|
|
|
|
|
|
timer_vga_sprites();
|
|
|
|
|
|
|
|
do {
|
2003-08-06 05:47:49 +00:00
|
|
|
if (ha->id != 0 && ha->flags & 0x20 && !(ha->flags & 0x40)) {
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
dha = _hitAreas;
|
2003-08-10 15:58:38 +00:00
|
|
|
if (ha->flags & 1) {
|
|
|
|
while (dha != ha && dha->flags != ha->flags)
|
|
|
|
++dha;
|
|
|
|
if (dha != ha && dha->flags == ha->flags)
|
|
|
|
continue;
|
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
dha = _hitAreas;
|
2003-08-10 15:58:38 +00:00
|
|
|
while (dha != ha && dha->item_ptr != ha->item_ptr)
|
|
|
|
++dha;
|
|
|
|
if (dha != ha && dha->item_ptr == ha->item_ptr)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (ha->y >= limit || ((_game & GF_SIMON2) && ha->y >= _vgaVar8))
|
2003-08-10 15:49:06 +00:00
|
|
|
continue;
|
2003-01-12 15:17:58 +00:00
|
|
|
|
|
|
|
y_ = (ha->height >> 1) - 4 + ha->y;
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
x_ = (ha->width >> 1) - 4 + ha->x - (_scrollX << 3);
|
2003-01-12 15:17:58 +00:00
|
|
|
|
2003-05-21 17:49:33 +00:00
|
|
|
if (x_ >= 0x137)
|
2003-01-12 15:17:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
dst = dx_lock_attached();
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
dst += (((_dxSurfacePitch >> 2) * y_) << 2) + x_;
|
2003-01-12 15:17:58 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
b = _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[4] = color;
|
|
|
|
dst[b+1] = color;
|
|
|
|
dst[b+4] = color;
|
|
|
|
dst[b+7] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b+2] = color;
|
|
|
|
dst[b+4] = color;
|
|
|
|
dst[b+6] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b+3] = color;
|
|
|
|
dst[b+5] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b] = color;
|
|
|
|
dst[b+1] = color;
|
|
|
|
dst[b+2] = color;
|
|
|
|
dst[b+6] = color;
|
|
|
|
dst[b+7] = color;
|
|
|
|
dst[b+8] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b+3] = color;
|
|
|
|
dst[b+5] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b+2] = color;
|
|
|
|
dst[b+4] = color;
|
|
|
|
dst[b+6] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b+1] = color;
|
|
|
|
dst[b+4] = color;
|
|
|
|
dst[b+7] = color;
|
2005-05-06 11:37:33 +00:00
|
|
|
b += _dxSurfacePitch;
|
2003-08-05 17:39:06 +00:00
|
|
|
dst[b+4] = color;
|
2003-01-12 15:17:58 +00:00
|
|
|
|
|
|
|
dx_unlock_attached();
|
|
|
|
}
|
|
|
|
} while (ha++, --count);
|
|
|
|
|
|
|
|
dx_update_screen_and_palette();
|
|
|
|
delay(100);
|
|
|
|
timer_vga_sprites();
|
|
|
|
dx_update_screen_and_palette();
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2003-01-12 15:17:58 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::hitarea_stuff() {
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *ha;
|
|
|
|
uint id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_leftButtonDown = 0;
|
|
|
|
_lastHitArea = 0;
|
|
|
|
_verbHitArea = 0;
|
|
|
|
_hitAreaSubjectItem = NULL;
|
|
|
|
_hitAreaObjectItem = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
hitarea_proc_1();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
startOver:
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastHitArea = NULL;
|
|
|
|
_lastHitArea3 = NULL;
|
2003-11-28 10:11:56 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_keyPressed == 35)
|
2003-01-12 15:17:58 +00:00
|
|
|
f10_key();
|
2002-06-29 16:11:13 +00:00
|
|
|
processSpecialKeys();
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lastHitArea3 == (HitArea *) 0xFFFFFFFF)
|
2002-07-07 19:06:48 +00:00
|
|
|
goto startOver;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lastHitArea3 != 0)
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
|
|
|
hitarea_stuff_helper();
|
2005-07-30 21:11:48 +00:00
|
|
|
delay(100);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
ha = _lastHitArea;
|
2002-06-29 16:11:13 +00:00
|
|
|
|
|
|
|
if (ha == NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (ha->id == 0x7FFB) {
|
2003-05-10 05:20:56 +00:00
|
|
|
handle_uparrow_hitarea(ha->fcs);
|
2002-06-29 16:11:13 +00:00
|
|
|
} else if (ha->id == 0x7FFC) {
|
2003-05-10 05:20:56 +00:00
|
|
|
handle_downarrow_hitarea(ha->fcs);
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (ha->id >= 101 && ha->id < 113) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_verbHitArea = ha->unk3;
|
2002-06-29 16:11:13 +00:00
|
|
|
handle_verb_hitarea(ha);
|
2005-05-06 11:37:33 +00:00
|
|
|
_hitAreaUnk4 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if ((_verbHitArea != 0 || _hitAreaSubjectItem != ha->item_ptr && ha->flags & 0x80) &&
|
2002-07-07 19:06:48 +00:00
|
|
|
ha->item_ptr) {
|
|
|
|
if_1:;
|
2005-05-06 11:37:33 +00:00
|
|
|
_hitAreaSubjectItem = ha->item_ptr;
|
2002-06-29 16:11:13 +00:00
|
|
|
id = 0xFFFF;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (ha->flags & 1)
|
|
|
|
id = ha->flags >> 8;
|
2002-06-29 16:11:13 +00:00
|
|
|
_variableArray[60] = id;
|
|
|
|
new_current_hitarea(ha);
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_verbHitArea != 0)
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2003-05-19 00:38:35 +00:00
|
|
|
// else 1
|
2002-06-29 16:11:13 +00:00
|
|
|
if (ha->unk3 == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (ha->item_ptr)
|
|
|
|
goto if_1;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_verbHitArea = ha->unk3 & 0xBFFF;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (ha->unk3 & 0x4000) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_hitAreaSubjectItem = ha->item_ptr;
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_hitAreaSubjectItem != NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_needHitAreaRecalc++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::hitarea_stuff_helper() {
|
2002-06-29 16:11:13 +00:00
|
|
|
time_t cur_time;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2004-07-27 07:21:28 +00:00
|
|
|
uint subr_id = _variableArray[254];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id != 0) {
|
|
|
|
Subroutine *sub = getSubroutineByID(subr_id);
|
|
|
|
if (sub != NULL) {
|
|
|
|
startSubroutineEx(sub);
|
|
|
|
startUp_helper_2();
|
|
|
|
}
|
2004-07-27 07:21:28 +00:00
|
|
|
_variableArray[254] = 0;
|
2005-05-06 11:37:33 +00:00
|
|
|
_runScriptReturn1 = false;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2004-07-27 07:21:28 +00:00
|
|
|
if (_variableArray[254] || _variableArray[249]) {
|
2002-06-29 16:11:13 +00:00
|
|
|
hitarea_stuff_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
time(&cur_time);
|
2005-05-06 11:37:33 +00:00
|
|
|
if ((uint) cur_time != _lastTime) {
|
|
|
|
_lastTime = cur_time;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (kickoffTimeEvents())
|
|
|
|
startUp_helper_2();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// Simon 2 specific
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::hitarea_stuff_helper_2() {
|
2002-06-29 16:11:13 +00:00
|
|
|
uint subr_id;
|
|
|
|
Subroutine *sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-07-27 07:21:28 +00:00
|
|
|
subr_id = _variableArray[249];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id != 0) {
|
|
|
|
sub = getSubroutineByID(subr_id);
|
|
|
|
if (sub != NULL) {
|
2004-07-27 07:21:28 +00:00
|
|
|
_variableArray[249] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
startSubroutineEx(sub);
|
|
|
|
startUp_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2004-07-27 07:21:28 +00:00
|
|
|
_variableArray[249] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-07-27 07:21:28 +00:00
|
|
|
subr_id = _variableArray[254];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id != 0) {
|
|
|
|
sub = getSubroutineByID(subr_id);
|
|
|
|
if (sub != NULL) {
|
2004-07-27 07:21:28 +00:00
|
|
|
_variableArray[254] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
startSubroutineEx(sub);
|
|
|
|
startUp_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2004-07-27 07:21:28 +00:00
|
|
|
_variableArray[254] = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_runScriptReturn1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::startUp_helper_2() {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!_mortalFlag) {
|
|
|
|
_mortalFlag = true;
|
2004-08-02 11:37:07 +00:00
|
|
|
showmessage_print_char(0);
|
2005-05-06 11:37:33 +00:00
|
|
|
_fcsUnk1 = 0;
|
|
|
|
if (_fcsPtrArray3[0] != 0) {
|
|
|
|
_fcsPtr1 = _fcsPtrArray3[0];
|
|
|
|
showmessage_helper_3(_fcsPtr1->textLength, _fcsPtr1->textMaxLength);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
_mortalFlag = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::pollMouseXY() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_mouseX = _sdlMouseX;
|
|
|
|
_mouseY = _sdlMouseY;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::handle_verb_clicked(uint verb) {
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *sub;
|
|
|
|
int result;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_objectItem = _hitAreaObjectItem;
|
|
|
|
if (_objectItem == _dummyItem2) {
|
|
|
|
_objectItem = getItem1Ptr();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_objectItem == _dummyItem3) {
|
|
|
|
_objectItem = derefItem(getItem1Ptr()->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_subjectItem = _hitAreaSubjectItem;
|
|
|
|
if (_subjectItem == _dummyItem2) {
|
|
|
|
_subjectItem = getItem1Ptr();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_subjectItem == _dummyItem3) {
|
|
|
|
_subjectItem = derefItem(getItem1Ptr()->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_subjectItem) {
|
2005-10-03 14:08:07 +00:00
|
|
|
_scriptCondB = _subjectItem->noun;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_scriptCondB = -1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_objectItem) {
|
2005-10-03 14:08:07 +00:00
|
|
|
_scriptCondC = _objectItem->noun;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_scriptCondC = -1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_scriptCondA = _verbHitArea;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
sub = getSubroutineByID(0);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (sub == NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
result = startSubroutine(sub);
|
|
|
|
if (result == -1)
|
|
|
|
showMessageFormat("I don't understand");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_runScriptReturn1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
sub = getSubroutineByID(100);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (sub)
|
|
|
|
startSubroutine(sub);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2)
|
2005-05-06 11:37:33 +00:00
|
|
|
_runScriptReturn1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
startUp_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 17:50:40 +00:00
|
|
|
TextLocation *SimonEngine::getTextLocation(uint a) {
|
2002-12-04 22:40:16 +00:00
|
|
|
switch (a) {
|
|
|
|
case 1:
|
2005-05-06 11:37:33 +00:00
|
|
|
return &_textLocation1;
|
2002-12-04 22:40:16 +00:00
|
|
|
case 2:
|
2005-05-06 11:37:33 +00:00
|
|
|
return &_textLocation2;
|
2002-12-04 22:40:16 +00:00
|
|
|
case 101:
|
2005-05-06 11:37:33 +00:00
|
|
|
return &_textLocation3;
|
2002-12-04 22:40:16 +00:00
|
|
|
case 102:
|
2005-05-06 11:37:33 +00:00
|
|
|
return &_textLocation4;
|
2002-12-04 22:40:16 +00:00
|
|
|
default:
|
|
|
|
error("text, invalid value %d", a);
|
|
|
|
}
|
2005-06-21 22:08:21 +00:00
|
|
|
return NULL;
|
2002-12-04 22:40:16 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_print_str() {
|
2005-05-06 12:23:19 +00:00
|
|
|
uint vgaSpriteId = getVarOrByte();
|
2003-10-21 10:14:42 +00:00
|
|
|
uint color = getVarOrByte();
|
2002-06-29 16:11:13 +00:00
|
|
|
uint string_id = getNextStringID();
|
|
|
|
const byte *string_ptr = NULL;
|
|
|
|
uint speech_id = 0;
|
2004-03-14 17:50:40 +00:00
|
|
|
TextLocation *tl;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-10-26 05:31:36 +00:00
|
|
|
if (string_id != 0xFFFF)
|
|
|
|
string_ptr = getStringPtrByID(string_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-10-26 05:31:36 +00:00
|
|
|
if (_game & GF_TALKIE)
|
2002-06-29 16:11:13 +00:00
|
|
|
speech_id = (uint16)getNextWord();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 12:23:19 +00:00
|
|
|
tl = getTextLocation(vgaSpriteId);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-10-30 01:05:08 +00:00
|
|
|
if (_speech && speech_id != 0)
|
2005-05-06 12:23:19 +00:00
|
|
|
talk_with_speech(speech_id, vgaSpriteId);
|
2003-12-02 08:43:54 +00:00
|
|
|
if ((_game & GF_SIMON2) && (_game & GF_TALKIE) && speech_id == 0)
|
2005-05-06 12:23:19 +00:00
|
|
|
o_kill_sprite_simon2(2, vgaSpriteId + 2);
|
2003-12-02 08:43:54 +00:00
|
|
|
|
2003-10-26 05:31:36 +00:00
|
|
|
if (string_ptr != NULL && (speech_id == 0 || _subtitles))
|
2005-05-06 12:23:19 +00:00
|
|
|
talk_with_text(vgaSpriteId, color, (const char *)string_ptr, tl->x, tl->y, tl->width);
|
2003-09-25 04:23:07 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::ensureVgaResLoadedC(uint vga_res) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x80;
|
2002-06-29 16:11:13 +00:00
|
|
|
ensureVgaResLoaded(vga_res);
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x80;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::ensureVgaResLoaded(uint vga_res) {
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
CHECK_BOUNDS(vga_res, _vgaBufferPointers);
|
2002-06-29 16:11:13 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vpe = _vgaBufferPointers + vga_res;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (vpe->vgaFile1 != NULL)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
vpe->vgaFile2 = read_vga_from_datfile_2(vga_res * 2 + 1);
|
|
|
|
vpe->vgaFile1 = read_vga_from_datfile_2(vga_res * 2);
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte *SimonEngine::setup_vga_destination(uint32 size) {
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *dest, *end;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar4 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
dest = _vgaBufFreeStart;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
end = dest + size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (end >= _vgaBufEnd) {
|
|
|
|
_vgaBufFreeStart = _vgaBufStart;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar5 = false;
|
2002-06-29 16:11:13 +00:00
|
|
|
vga_buf_unk_proc3(end);
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar5)
|
2002-06-29 16:11:13 +00:00
|
|
|
continue;
|
|
|
|
vga_buf_unk_proc1(end);
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar5)
|
2002-06-29 16:11:13 +00:00
|
|
|
continue;
|
|
|
|
delete_memptr_range(end);
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaBufFreeStart = end;
|
2002-06-29 16:11:13 +00:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::setup_vga_file_buf_pointers() {
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *alloced;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-12-01 00:45:16 +00:00
|
|
|
alloced = (byte *)malloc(VGA_MEM_SIZE);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaBufFreeStart = alloced;
|
|
|
|
_vgaBufStart = alloced;
|
|
|
|
_vgaFileBufOrg = alloced;
|
|
|
|
_vgaFileBufOrg2 = alloced;
|
|
|
|
_vgaBufEnd = alloced + VGA_MEM_SIZE;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::vga_buf_unk_proc3(byte *end) {
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar7 == 0xFFFF)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar4 == 2)
|
|
|
|
error("vga_buf_unk_proc3: _videoVar4 == 2");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vpe = &_vgaBufferPointers[_videoVar7];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
|
|
|
|
_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
|
|
|
|
_videoVar5 = 1;
|
|
|
|
_videoVar4++;
|
|
|
|
_vgaBufFreeStart = vpe->vgaFile1 + 0x5000;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar5 = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::vga_buf_unk_proc1(byte *end) {
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaSprite *vsp;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockWord & 0x20)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (vsp = _vgaSprites; vsp->id; vsp++) {
|
2005-05-06 13:22:48 +00:00
|
|
|
vga_buf_unk_proc2(vsp->fileId, end);
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar5 == true)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::delete_memptr_range(byte *end) {
|
2005-05-06 11:37:33 +00:00
|
|
|
uint count = ARRAYSIZE(_vgaBufferPointers);
|
|
|
|
VgaPointersEntry *vpe = _vgaBufferPointers;
|
2002-06-29 16:11:13 +00:00
|
|
|
do {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
|
|
|
|
_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
|
2002-07-07 19:06:48 +00:00
|
|
|
vpe->dd = 0;
|
|
|
|
vpe->vgaFile1 = NULL;
|
|
|
|
vpe->vgaFile2 = NULL;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (++vpe, --count);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::vga_buf_unk_proc2(uint a, byte *end) {
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vpe = &_vgaBufferPointers[a];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
|
|
|
|
_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
|
|
|
|
_videoVar5 = true;
|
|
|
|
_videoVar4++;
|
|
|
|
_vgaBufFreeStart = vpe->vgaFile1 + 0x5000;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar5 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_clear_vgapointer_entry(uint a) {
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vpe = &_vgaBufferPointers[a];
|
2002-04-14 11:00:33 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
vpe->dd = 0;
|
|
|
|
vpe->vgaFile1 = NULL;
|
|
|
|
vpe->vgaFile2 = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_set_video_mode(uint mode, uint vga_res) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (mode == 4)
|
2005-05-06 13:22:48 +00:00
|
|
|
vc29_stopAllSounds();
|
2002-06-29 16:11:13 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockWord & 0x10)
|
|
|
|
error("o_set_video_mode_ex: _lockWord & 0x10");
|
2004-08-02 11:53:33 +00:00
|
|
|
|
|
|
|
set_video_mode_internal(mode, vga_res);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::set_video_mode_internal(uint mode, uint vga_res_id) {
|
2003-12-23 08:59:30 +00:00
|
|
|
uint num, num_lines;
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *bb, *b;
|
2005-10-09 12:12:24 +00:00
|
|
|
// uint16 count;
|
2004-12-18 01:33:21 +00:00
|
|
|
const byte *vc_ptr_org;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
_windowNum = mode;
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x20;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (vga_res_id == 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_unkPalFlag = true;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_dxUse3Or4ForLock = true;
|
|
|
|
_vgaVar6 = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaCurFile2 = num = vga_res_id / 100;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 11:37:33 +00:00
|
|
|
vpe = &_vgaBufferPointers[num];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_curVgaFile1 = vpe->vgaFile1;
|
|
|
|
_curVgaFile2 = vpe->vgaFile2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (vpe->vgaFile1 != NULL)
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ensureVgaResLoaded(num);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// ensure flipping complete
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
bb = _curVgaFile1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-07 06:59:49 +00:00
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
2005-10-09 12:12:24 +00:00
|
|
|
b = bb + READ_LE_UINT16(&((VgaFileHeader_Feeble *) bb)->hdr2_start);
|
|
|
|
//count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) b)->imageCount);
|
|
|
|
b = bb + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) b)->imageTable);
|
2005-10-07 06:59:49 +00:00
|
|
|
|
2005-10-09 12:12:24 +00:00
|
|
|
while (READ_LE_UINT16(&((ImageHeader_Feeble *) b)->id) != vga_res_id)
|
|
|
|
b += sizeof(ImageHeader_Feeble);
|
2005-10-07 06:59:49 +00:00
|
|
|
} else {
|
2005-10-09 12:12:24 +00:00
|
|
|
b = bb + READ_BE_UINT16(&((VgaFileHeader_Simon *) bb)->hdr2_start);
|
|
|
|
//count = READ_BE_UINT16(&((VgaFileHeader2_Simon *) b)->imageCount);
|
|
|
|
b = bb + READ_BE_UINT16(&((VgaFileHeader2_Simon *) b)->imageTable);
|
2005-10-07 06:59:49 +00:00
|
|
|
|
2005-10-09 12:12:24 +00:00
|
|
|
while (READ_BE_UINT16(&((ImageHeader_Simon *) b)->id) != vga_res_id)
|
|
|
|
b += sizeof(ImageHeader_Simon);
|
2005-10-07 06:59:49 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (num == 16300) {
|
|
|
|
dx_clear_attached_from_top(134);
|
2005-05-06 11:37:33 +00:00
|
|
|
_usePaletteDelay = true;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollX = 0;
|
|
|
|
_scrollXMax = 0;
|
|
|
|
_scrollCount = 0;
|
|
|
|
_scrollFlag = 0;
|
|
|
|
_scrollHeight = 134;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_variableArray[34] != -1)
|
2004-07-27 07:21:28 +00:00
|
|
|
_variableArray[251] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vc_ptr_org = _vcPtr;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-07 06:59:49 +00:00
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
2005-10-09 12:12:24 +00:00
|
|
|
_vcPtr = _curVgaFile1 + READ_LE_UINT16(&((ImageHeader_Feeble *) b)->scriptOffs);
|
2005-10-07 06:59:49 +00:00
|
|
|
} else {
|
2005-10-09 12:12:24 +00:00
|
|
|
_vcPtr = _curVgaFile1 + READ_BE_UINT16(&((ImageHeader_Simon *) b)->scriptOffs);
|
2005-10-07 06:59:49 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
//dump_vga_script(_vcPtr, num, vga_res_id);
|
2002-06-29 16:11:13 +00:00
|
|
|
run_vga_script();
|
2005-05-06 11:37:33 +00:00
|
|
|
_vcPtr = vc_ptr_org;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!_dxUse3Or4ForLock) {
|
2005-10-05 11:37:26 +00:00
|
|
|
num_lines = _windowNum == 4 ? 134 : 200;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaVar8 = num_lines;
|
2005-10-07 07:36:09 +00:00
|
|
|
dx_copy_from_attached_to_2(0, 0, _screenWidth, num_lines);
|
2002-06-29 16:11:13 +00:00
|
|
|
dx_copy_from_attached_to_3(num_lines);
|
2005-05-06 11:37:33 +00:00
|
|
|
_syncFlag2 = 1;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
_dxUse3Or4ForLock = false;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
2003-12-23 08:59:30 +00:00
|
|
|
// Allow one section of Simon the Sorcerer 1 introduction to be displayed
|
|
|
|
// in lower half of screen
|
2004-01-27 13:33:21 +00:00
|
|
|
if (_subroutine == 2923 || _subroutine == 2926)
|
2003-12-23 08:59:30 +00:00
|
|
|
num_lines = 200;
|
|
|
|
else
|
2005-10-05 11:37:26 +00:00
|
|
|
num_lines = _windowNum == 4 ? 134 : 200;
|
2005-10-07 07:36:09 +00:00
|
|
|
dx_copy_from_attached_to_2(0, 0, _screenWidth, num_lines);
|
2002-06-29 16:11:13 +00:00
|
|
|
dx_copy_from_attached_to_3(num_lines);
|
2005-05-06 11:37:33 +00:00
|
|
|
_syncFlag2 = 1;
|
|
|
|
_timer5 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x20;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_unkPalFlag) {
|
|
|
|
_unkPalFlag = false;
|
|
|
|
while (_paletteColorCount != 0) {
|
2002-06-29 16:11:13 +00:00
|
|
|
delay(10);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_fade_to_black() {
|
2002-04-12 21:26:59 +00:00
|
|
|
uint i;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memcpy(_videoBuf1, _paletteBackup, 256 * sizeof(uint32));
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
i = NUM_PALETTE_FADEOUT;
|
|
|
|
do {
|
2005-05-06 11:37:33 +00:00
|
|
|
palette_fadeout((uint32 *)_videoBuf1, 32);
|
|
|
|
palette_fadeout((uint32 *)_videoBuf1 + 32 + 16, 144);
|
|
|
|
palette_fadeout((uint32 *)_videoBuf1 + 32 + 16 + 144 + 16, 48);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_system->setPalette(_videoBuf1, 0, 256);
|
2003-12-18 10:47:12 +00:00
|
|
|
if (_fade)
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-04-12 21:26:59 +00:00
|
|
|
delay(5);
|
|
|
|
} while (--i);
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memcpy(_paletteBackup, _videoBuf1, 256 * sizeof(uint32));
|
|
|
|
memcpy(_palette, _videoBuf1, 256 * sizeof(uint32));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::delete_vga_timer(VgaTimerEntry * vte) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (vte + 1 <= _nextVgaTimerToProcess) {
|
|
|
|
_nextVgaTimerToProcess--;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(vte, vte + 1, sizeof(VgaTimerEntry));
|
2002-04-12 21:26:59 +00:00
|
|
|
vte++;
|
|
|
|
} while (vte->delay);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::expire_vga_timers() {
|
2005-05-06 11:37:33 +00:00
|
|
|
VgaTimerEntry *vte = _vgaTimerList;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaTickCounter++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-12-23 06:35:17 +00:00
|
|
|
while (vte->delay) {
|
|
|
|
if (!--vte->delay) {
|
|
|
|
uint16 cur_file = vte->cur_vga_file;
|
|
|
|
uint16 cur_unk = vte->sprite_id;
|
2004-12-18 01:33:21 +00:00
|
|
|
const byte *script_ptr = vte->script_pointer;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_nextVgaTimerToProcess = vte + 1;
|
2003-12-23 06:35:17 +00:00
|
|
|
delete_vga_timer(vte);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-12-23 06:35:17 +00:00
|
|
|
if ((_game & GF_SIMON2) && script_ptr == NULL) {
|
|
|
|
// special scroll timer
|
|
|
|
scroll_timeout();
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2003-05-24 12:26:28 +00:00
|
|
|
vc_resume_sprite(script_ptr, cur_file, cur_unk);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
vte = _nextVgaTimerToProcess;
|
2003-12-23 06:35:17 +00:00
|
|
|
} else {
|
|
|
|
vte++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// Simon2 specific
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::scroll_timeout() {
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollCount == 0)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollCount < 0) {
|
|
|
|
if (_scrollFlag != -1) {
|
|
|
|
_scrollFlag = -1;
|
|
|
|
if (++_scrollCount == 0)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollFlag != 1) {
|
|
|
|
_scrollFlag = 1;
|
|
|
|
if (--_scrollCount == 0)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-12-23 09:08:11 +00:00
|
|
|
add_vga_timer(6, NULL, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2004-12-18 01:33:21 +00:00
|
|
|
void SimonEngine::vc_resume_sprite(const byte *code_ptr, uint16 cur_file, uint16 cur_sprite) {
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaPointersEntry *vpe;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaCurSpriteId = cur_sprite;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaCurFileId = cur_file;
|
|
|
|
_vgaCurFile2 = cur_file;
|
|
|
|
vpe = &_vgaBufferPointers[cur_file];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_curVgaFile1 = vpe->vgaFile1;
|
|
|
|
_curVgaFile2 = vpe->vgaFile2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vcPtr = code_ptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
run_vga_script();
|
|
|
|
}
|
|
|
|
|
2004-12-18 01:33:21 +00:00
|
|
|
void SimonEngine::add_vga_timer(uint num, const byte *code_ptr, uint cur_sprite, uint cur_file) {
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaTimerEntry *vte;
|
|
|
|
|
2004-01-01 10:42:10 +00:00
|
|
|
// When Simon talks to the Golum about stew in French version of
|
|
|
|
// Simon the Sorcerer 1 the code_ptr is at wrong location for
|
2005-07-30 21:11:48 +00:00
|
|
|
// sprite 200. This was a bug in the original game, which
|
2004-01-01 10:42:10 +00:00
|
|
|
// caused several glitches in this scene.
|
|
|
|
// We work around the problem by correcting the code_ptr for sprite
|
|
|
|
// 200 in this scene, if it is wrong.
|
|
|
|
if (!(_game & GF_SIMON2) && (_language == 2) &&
|
2005-05-06 11:37:33 +00:00
|
|
|
(code_ptr - _vgaBufferPointers[cur_file].vgaFile1 == 4) && (cur_sprite == 200) && (cur_file == 2))
|
2004-01-01 10:42:10 +00:00
|
|
|
code_ptr += 0x66;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (vte = _vgaTimerList; vte->delay; vte++) {
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
vte->delay = num;
|
|
|
|
vte->script_pointer = code_ptr;
|
|
|
|
vte->sprite_id = cur_sprite;
|
|
|
|
vte->cur_vga_file = cur_file;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_force_unlock() {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_game & GF_SIMON2 && _bitArray[4] & 0x8000)
|
|
|
|
_mouseCursor = 0;
|
|
|
|
_lockCounter = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_force_lock() {
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x8000;
|
2005-10-05 12:16:49 +00:00
|
|
|
vc34_setMouseOff();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2002-12-22 03:54:51 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x4000;
|
2005-10-05 12:16:49 +00:00
|
|
|
vc34_setMouseOff();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x4000;
|
2002-12-22 03:54:51 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-16 12:07:19 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_wait_for_vga(uint a) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaWaitFor = a;
|
|
|
|
_timer1 = 0;
|
|
|
|
_exitCutscene = false;
|
|
|
|
_skipSpeech = false;
|
|
|
|
while (_vgaWaitFor != 0) {
|
|
|
|
if (_skipSpeech && _game & GF_SIMON2) {
|
|
|
|
if (_vgaWaitFor == 200 && !vc_get_bit(14)) {
|
2003-06-05 12:20:05 +00:00
|
|
|
skip_speech();
|
|
|
|
break;
|
2002-12-07 17:36:38 +00:00
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
} else if (_exitCutscene) {
|
2002-12-08 02:01:28 +00:00
|
|
|
if (vc_get_bit(9)) {
|
|
|
|
startSubroutine170();
|
|
|
|
break;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
|
|
|
processSpecialKeys();
|
|
|
|
}
|
|
|
|
|
2003-05-20 04:09:14 +00:00
|
|
|
delay(10);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_timer1 >= 1000) {
|
2002-11-29 16:50:15 +00:00
|
|
|
warning("wait timed out");
|
|
|
|
break;
|
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
} else if (_timer1 >= 500) {
|
2002-11-29 16:50:15 +00:00
|
|
|
warning("wait timed out");
|
|
|
|
break;
|
|
|
|
}
|
2002-11-29 11:42:00 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::skip_speech() {
|
2002-12-07 17:36:38 +00:00
|
|
|
_sound->stopVoice();
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!(_bitArray[1] & 0x1000)) {
|
|
|
|
_bitArray[0] |= 0x4000;
|
2002-12-08 13:37:38 +00:00
|
|
|
_variableArray[100] = 5;
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 1, 0x1e, 0, 0, 0);
|
2002-12-07 17:36:38 +00:00
|
|
|
o_wait_for_vga(0x82);
|
2003-05-24 12:26:28 +00:00
|
|
|
o_kill_sprite_simon2(2, 1);
|
2003-11-08 20:54:31 +00:00
|
|
|
}
|
2002-12-07 17:36:38 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::timer_vga_sprites() {
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
VgaPointersEntry *vpe;
|
2005-05-06 11:37:33 +00:00
|
|
|
const byte *vc_ptr_org = _vcPtr;
|
2005-05-06 13:22:48 +00:00
|
|
|
uint16 params[5]; // parameters to vc10
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar9 == 2)
|
|
|
|
_videoVar9 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_game & GF_SIMON2 && _scrollFlag) {
|
2002-04-12 21:26:59 +00:00
|
|
|
timer_vga_sprites_helper();
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vsp = _vgaSprites;
|
2004-03-14 17:50:40 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
while (vsp->id != 0) {
|
2005-10-05 11:37:26 +00:00
|
|
|
vsp->windowNum &= 0x7FFF;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 13:22:48 +00:00
|
|
|
vpe = &_vgaBufferPointers[vsp->fileId];
|
2005-05-06 11:37:33 +00:00
|
|
|
_curVgaFile1 = vpe->vgaFile1;
|
|
|
|
_curVgaFile2 = vpe->vgaFile2;
|
2005-10-05 11:37:26 +00:00
|
|
|
_windowNum = vsp->windowNum;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaCurSpriteId = vsp->id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-12 00:35:54 +00:00
|
|
|
params[0] = readUint16Wrapper(&vsp->image);
|
|
|
|
params[1] = readUint16Wrapper(&vsp->palette);
|
|
|
|
params[2] = readUint16Wrapper(&vsp->x);
|
|
|
|
params[3] = readUint16Wrapper(&vsp->y);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 12:23:19 +00:00
|
|
|
*(byte *)(¶ms[4]) = (byte)vsp->flags;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-05-06 12:23:19 +00:00
|
|
|
params[4] = READ_BE_UINT16(&vsp->flags);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_vcPtr = (const byte *)params;
|
2005-05-06 13:22:48 +00:00
|
|
|
vc10_draw();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_drawImagesDebug)
|
2005-10-07 07:36:09 +00:00
|
|
|
memset(_sdl_buf_attached, 0, _screenWidth * _screenHeight);
|
2003-03-07 13:39:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar8++;
|
|
|
|
_vcPtr = vc_ptr_org;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::timer_vga_sprites_helper() {
|
2004-12-18 01:33:21 +00:00
|
|
|
byte *dst = dx_lock_2();
|
|
|
|
const byte *src;
|
2002-04-12 21:26:59 +00:00
|
|
|
uint x;
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollFlag < 0) {
|
2005-10-07 07:36:09 +00:00
|
|
|
memmove(dst + 8, dst, _screenWidth * _scrollHeight - 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-10-07 07:36:09 +00:00
|
|
|
memmove(dst, dst + 8, _screenWidth * _scrollHeight - 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
x = _scrollX - 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
if (_scrollFlag > 0) {
|
2005-10-07 07:36:09 +00:00
|
|
|
dst += _screenWidth - 8;
|
2002-04-12 21:26:59 +00:00
|
|
|
x += 41;
|
|
|
|
}
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
src = _scrollImage + x * 4;
|
|
|
|
decodeStripA(dst, src + READ_BE_UINT32(src), _scrollHeight);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dx_unlock_2();
|
|
|
|
|
|
|
|
|
2005-10-07 07:36:09 +00:00
|
|
|
memcpy(_sdl_buf_attached, _sdl_buf, _screenWidth * _screenHeight);
|
2005-10-05 11:37:26 +00:00
|
|
|
dx_copy_from_attached_to_3(_scrollHeight);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollX += _scrollFlag;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
vc_write_var(0xfB, _scrollX);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
_scrollFlag = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::timer_vga_sprites_2() {
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
VgaPointersEntry *vpe;
|
2005-05-06 11:37:33 +00:00
|
|
|
const byte *vc_ptr_org = _vcPtr;
|
2005-05-06 13:22:48 +00:00
|
|
|
uint16 params[5]; // parameters to vc10_draw
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar9 == 2)
|
|
|
|
_videoVar9 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vsp = _vgaSprites;
|
2002-04-12 21:26:59 +00:00
|
|
|
while (vsp->id != 0) {
|
2005-10-05 11:37:26 +00:00
|
|
|
vsp->windowNum &= 0x7FFF;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 13:22:48 +00:00
|
|
|
vpe = &_vgaBufferPointers[vsp->fileId];
|
2005-05-06 11:37:33 +00:00
|
|
|
_curVgaFile1 = vpe->vgaFile1;
|
|
|
|
_curVgaFile2 = vpe->vgaFile2;
|
2005-10-05 11:37:26 +00:00
|
|
|
_windowNum = vsp->windowNum;
|
2005-05-06 11:37:33 +00:00
|
|
|
_vgaCurSpriteId = vsp->id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (vsp->image)
|
2005-05-06 11:37:33 +00:00
|
|
|
fprintf(_dumpFile, "id:%5d image:%3d base-color:%3d x:%3d y:%3d flags:%x\n",
|
2005-10-05 11:37:26 +00:00
|
|
|
vsp->id, vsp->image, vsp->palette, vsp->x, vsp->y, vsp->flags);
|
2005-10-12 00:35:54 +00:00
|
|
|
params[0] = readUint16Wrapper(&vsp->image);
|
|
|
|
params[1] = readUint16Wrapper(&vsp->palette);
|
|
|
|
params[2] = readUint16Wrapper(&vsp->x);
|
|
|
|
params[3] = readUint16Wrapper(&vsp->y);
|
|
|
|
params[4] = readUint16Wrapper(&vsp->flags);
|
2005-05-06 11:37:33 +00:00
|
|
|
_vcPtr = (const byte *)params;
|
2005-05-06 13:22:48 +00:00
|
|
|
vc10_draw();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar8++;
|
|
|
|
_vcPtr = vc_ptr_org;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::timer_proc1() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_timer4++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockWord & 0x80E9 || _lockWord & 2)
|
2003-07-31 01:59:31 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockWord & 0xC0E9 || _lockWord & 2)
|
2003-07-31 01:59:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_timer1++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!(_lockWord & 0x10)) {
|
2004-02-13 11:00:37 +00:00
|
|
|
expire_vga_timers();
|
|
|
|
expire_vga_timers();
|
2005-05-06 11:37:33 +00:00
|
|
|
_syncFlag2 ^= 1;
|
|
|
|
_cepeFlag ^= 1;
|
|
|
|
if (!_cepeFlag)
|
2002-04-12 21:26:59 +00:00
|
|
|
expire_vga_timers();
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_lockCounter != 0 && !_syncFlag2) {
|
|
|
|
_lockWord &= ~2;
|
2002-12-14 15:35:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
timer_vga_sprites();
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_drawImagesDebug)
|
2003-03-07 13:39:59 +00:00
|
|
|
timer_vga_sprites_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_copyPartialMode == 1) {
|
2002-08-20 09:58:35 +00:00
|
|
|
dx_copy_from_2_to_attached(80, 46, 208 - 80, 94 - 46);
|
|
|
|
}
|
2002-04-16 12:07:19 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_copyPartialMode == 2) {
|
2003-05-19 00:38:35 +00:00
|
|
|
// copy partial from attached to 2
|
2005-10-07 07:36:09 +00:00
|
|
|
dx_copy_from_attached_to_2(176, 61, _screenWidth - 176, 134 - 61);
|
2005-05-06 11:37:33 +00:00
|
|
|
_copyPartialMode = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_videoVar8) {
|
2002-04-12 21:26:59 +00:00
|
|
|
handle_mouse_moved();
|
|
|
|
dx_update_screen_and_palette();
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar8 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~2;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::timer_callback() {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_timer5 != 0) {
|
|
|
|
_syncFlag2 = true;
|
|
|
|
_timer5--;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
|
|
|
timer_proc1();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fcs_setTextColor(FillOrCopyStruct *fcs, uint value) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fcs->text_color = value;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_vga_reset() {
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x8000;
|
2005-05-06 13:22:48 +00:00
|
|
|
vc27_resetSprite();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2002-12-22 03:54:51 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x4000;
|
2005-05-06 13:22:48 +00:00
|
|
|
vc27_resetSprite();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x4000;
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::itemIsSiblingOf(uint16 a) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
CHECK_BOUNDS(a, _vcItemArray);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
item = _vcItemArray[a];
|
2002-04-12 21:26:59 +00:00
|
|
|
if (item == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return getItem1Ptr()->parent == item->parent;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::itemIsParentOf(uint16 a, uint16 b) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item_a, *item_b;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
CHECK_BOUNDS(a, _vcItemArray);
|
|
|
|
CHECK_BOUNDS(b, _vcItemArray);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
item_a = _vcItemArray[a];
|
|
|
|
item_b = _vcItemArray[b];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (item_a == NULL || item_b == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return derefItem(item_a->parent) == item_b;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
bool SimonEngine::vc_maybe_skip_proc_1(uint16 a, int16 b) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
CHECK_BOUNDS(a, _vcItemArray);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
item = _vcItemArray[a];
|
2002-04-12 21:26:59 +00:00
|
|
|
if (item == NULL)
|
|
|
|
return true;
|
2005-10-03 14:08:07 +00:00
|
|
|
return item->state == b;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// OK
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fcs_delete(uint a) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_fcsPtrArray3[a] == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
2005-10-19 10:54:22 +00:00
|
|
|
removeIconArray(a);
|
2005-05-06 11:37:33 +00:00
|
|
|
video_copy_if_flag_0x8_c(_fcsPtrArray3[a]);
|
|
|
|
_fcsPtrArray3[a] = NULL;
|
|
|
|
if (_fcsUnk1 == a) {
|
|
|
|
_fcsPtr1 = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
fcs_unk_2(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// OK
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fcs_unk_2(uint a) {
|
2002-04-12 21:26:59 +00:00
|
|
|
a &= 7;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_fcsPtrArray3[a] == NULL || _fcsUnk1 == a)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_fcsUnk1 = a;
|
2004-08-02 11:37:07 +00:00
|
|
|
showmessage_print_char(0);
|
2005-05-06 11:37:33 +00:00
|
|
|
_fcsPtr1 = _fcsPtrArray3[a];
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
showmessage_helper_3(_fcsPtr1->textLength, _fcsPtr1->textMaxLength);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// OK
|
2005-10-19 10:54:22 +00:00
|
|
|
FillOrCopyStruct *SimonEngine::fcs_alloc(uint x, uint y, uint w, uint h, uint flags, uint fill_color, uint text_color) {
|
2002-04-12 21:26:59 +00:00
|
|
|
FillOrCopyStruct *fcs;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
fcs = _fcs_list;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (fcs->mode != 0)
|
|
|
|
fcs++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
fcs->mode = 2;
|
|
|
|
fcs->x = x;
|
|
|
|
fcs->y = y;
|
|
|
|
fcs->width = w;
|
|
|
|
fcs->height = h;
|
|
|
|
fcs->flags = flags;
|
|
|
|
fcs->fill_color = fill_color;
|
2005-10-19 10:54:22 +00:00
|
|
|
fcs->text_color = text_color;
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumn = 0;
|
|
|
|
fcs->textRow = 0;
|
|
|
|
fcs->textColumnOffset = 0;
|
|
|
|
fcs->textMaxLength = fcs->width * 8 / 6; // characters are 6 pixels
|
2002-04-12 21:26:59 +00:00
|
|
|
return fcs;
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
Item *SimonEngine::derefItem(uint item) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (item >= _itemArraySize)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("derefItem: invalid item %d", item);
|
2005-05-06 11:37:33 +00:00
|
|
|
return _itemArrayPtr[item];
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
uint SimonEngine::itemPtrToID(Item *id) {
|
2002-04-12 21:26:59 +00:00
|
|
|
uint i;
|
2005-05-06 11:37:33 +00:00
|
|
|
for (i = 0; i != _itemArraySize; i++)
|
|
|
|
if (_itemArrayPtr[i] == id)
|
2002-04-12 21:26:59 +00:00
|
|
|
return i;
|
|
|
|
error("itemPtrToID: not found");
|
2005-06-21 22:08:21 +00:00
|
|
|
return 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::o_pathfind(int x, int y, uint var_1, uint var_2) {
|
2004-12-18 01:33:21 +00:00
|
|
|
const uint16 *p;
|
2002-04-12 21:26:59 +00:00
|
|
|
uint i, j;
|
|
|
|
uint prev_i;
|
|
|
|
uint x_diff, y_diff;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint best_i = 0, best_j = 0, best_dist = 0xFFFFFFFF;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
2005-10-05 11:37:26 +00:00
|
|
|
x += _scrollX * 8;
|
2002-10-31 12:11:34 +00:00
|
|
|
}
|
2002-04-16 12:07:19 +00:00
|
|
|
|
2005-10-12 00:35:54 +00:00
|
|
|
int end = (_game == GAME_FEEBLEFILES) ? 9999 : 999;
|
2002-04-12 21:26:59 +00:00
|
|
|
prev_i = 21 - _variableArray[12];
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 20; i != 0; --i) {
|
2005-05-06 11:37:33 +00:00
|
|
|
p = (const uint16 *)_pathFindArray[20 - i];
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!p)
|
|
|
|
continue;
|
2005-10-12 00:35:54 +00:00
|
|
|
for (j = 0; readUint16Wrapper(&p[0]) != end; j++, p += 2) { // 0xE703 = byteswapped 999
|
|
|
|
x_diff = abs((int)(readUint16Wrapper(&p[0]) - x));
|
|
|
|
y_diff = abs((int)(readUint16Wrapper(&p[1]) - 12 - y));
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (x_diff < y_diff) {
|
|
|
|
x_diff >>= 2;
|
|
|
|
y_diff <<= 2;
|
|
|
|
}
|
|
|
|
x_diff += y_diff >> 2;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (x_diff < best_dist || x_diff == best_dist && prev_i == i) {
|
2002-04-12 21:26:59 +00:00
|
|
|
best_dist = x_diff;
|
|
|
|
best_i = 21 - i;
|
|
|
|
best_j = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_variableArray[var_1] = best_i;
|
|
|
|
_variableArray[var_2] = best_j;
|
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// ok
|
2005-10-19 10:54:22 +00:00
|
|
|
void SimonEngine::removeIconArray(uint fcs_index) {
|
2002-04-12 21:26:59 +00:00
|
|
|
FillOrCopyStruct *fcs;
|
|
|
|
uint16 fcsunk1;
|
|
|
|
uint16 i;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
fcs = _fcsPtrArray3[fcs_index & 7];
|
|
|
|
fcsunk1 = _fcsUnk1;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (fcs == NULL || fcs->fcs_data == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fcs_unk_2(fcs_index);
|
|
|
|
fcs_putchar(12);
|
|
|
|
fcs_unk_2(fcsunk1);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (i = 0; fcs->fcs_data->e[i].item != NULL; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
delete_hitarea_by_index(fcs->fcs_data->e[i].hit_area);
|
|
|
|
}
|
|
|
|
|
2005-10-19 10:54:22 +00:00
|
|
|
if (fcs->fcs_data->upArrow != -1) {
|
|
|
|
delete_hitarea_by_index(fcs->fcs_data->upArrow);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-10-19 10:54:22 +00:00
|
|
|
if (fcs->fcs_data->downArrow != -1) {
|
|
|
|
delete_hitarea_by_index(fcs->fcs_data->downArrow);
|
2003-12-02 06:23:05 +00:00
|
|
|
if (!(_game & GF_SIMON2))
|
|
|
|
fcs_unk_5(fcs, fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(fcs->fcs_data);
|
|
|
|
fcs->fcs_data = NULL;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_fcsData1[fcs_index] = 0;
|
|
|
|
_fcsData2[fcs_index] = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// ok
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fcs_unk_5(FillOrCopyStruct *fcs, uint fcs_index) {
|
2004-01-30 03:26:47 +00:00
|
|
|
o_kill_sprite_simon1(0x80);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::delete_hitarea_by_index(uint index) {
|
2005-05-06 11:37:33 +00:00
|
|
|
CHECK_BOUNDS(index, _hitAreas);
|
|
|
|
_hitAreas[index].flags = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// ok
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fcs_putchar(uint a) {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_fcsPtr1 != _fcsPtrArray3[0])
|
|
|
|
video_putchar(_fcsPtr1, a);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// ok
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::video_fill_or_copy_from_3_to_2(FillOrCopyStruct *fcs) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (fcs->flags & 0x10)
|
|
|
|
copy_img_from_3_to_2(fcs);
|
|
|
|
else
|
|
|
|
video_erase(fcs);
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumn = 0;
|
|
|
|
fcs->textRow = 0;
|
|
|
|
fcs->textColumnOffset = 0;
|
|
|
|
fcs->textLength = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// ok
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::copy_img_from_3_to_2(FillOrCopyStruct *fcs) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
dx_copy_rgn_from_3_to_2(fcs->y + fcs->height * 8 + ((fcs == _fcsPtrArray3[2]) ? 1 : 0), (fcs->x + fcs->width) * 8, fcs->y, fcs->x * 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_vgaVar6 && _fcsPtrArray3[2] == fcs) {
|
|
|
|
fcs = _fcsPtrArray3[0x18 / 4];
|
|
|
|
_vgaVar6 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-12-12 11:07:01 +00:00
|
|
|
dx_copy_rgn_from_3_to_2(fcs->y + fcs->height * 8, (fcs->x + fcs->width) * 8, fcs->y, fcs->x * 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::video_erase(FillOrCopyStruct *fcs) {
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst;
|
|
|
|
uint h;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dst = dx_lock_2();
|
2005-05-06 11:37:33 +00:00
|
|
|
dst += _dxSurfacePitch * fcs->y + fcs->x * 8;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
h = fcs->height * 8;
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memset(dst, fcs->fill_color, fcs->width * 8);
|
2005-05-06 11:37:33 +00:00
|
|
|
dst += _dxSurfacePitch;
|
2002-04-12 21:26:59 +00:00
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
dx_unlock_2();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
VgaSprite *SimonEngine::find_cur_sprite() {
|
2005-05-06 11:37:33 +00:00
|
|
|
VgaSprite *vsp = _vgaSprites;
|
2003-05-30 09:39:21 +00:00
|
|
|
while (vsp->id) {
|
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 13:22:48 +00:00
|
|
|
if (vsp->id == _vgaCurSpriteId && vsp->fileId == _vgaCurFileId)
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
2003-05-30 09:39:21 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (vsp->id == _vgaCurSpriteId)
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-05-30 09:39:21 +00:00
|
|
|
vsp++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2003-05-30 09:39:21 +00:00
|
|
|
return vsp;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 13:22:48 +00:00
|
|
|
bool SimonEngine::isSpriteLoaded(uint16 id, uint16 fileId) {
|
2005-05-06 11:37:33 +00:00
|
|
|
VgaSprite *vsp = _vgaSprites;
|
2003-05-30 09:39:21 +00:00
|
|
|
while (vsp->id) {
|
|
|
|
if (_game & GF_SIMON2) {
|
2005-05-06 13:22:48 +00:00
|
|
|
if (vsp->id == id && vsp->fileId == fileId)
|
2002-04-12 21:26:59 +00:00
|
|
|
return true;
|
2003-05-30 09:39:21 +00:00
|
|
|
} else {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (vsp->id == id)
|
|
|
|
return true;
|
|
|
|
}
|
2003-05-30 09:39:21 +00:00
|
|
|
vsp++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2003-05-30 09:39:21 +00:00
|
|
|
return false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::processSpecialKeys() {
|
2005-05-06 11:37:33 +00:00
|
|
|
switch (_keyPressed) {
|
2003-09-24 06:33:59 +00:00
|
|
|
case 27: // escape
|
2005-05-06 11:37:33 +00:00
|
|
|
_exitCutscene = true;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 59: // F1
|
2003-12-01 09:53:03 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
|
|
|
vc_write_var(5, 50);
|
|
|
|
} else {
|
|
|
|
vc_write_var(5, 40);
|
|
|
|
}
|
|
|
|
vc_write_var(86, 0);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 60: // F2
|
2003-12-01 09:53:03 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
|
|
|
vc_write_var(5, 75);
|
|
|
|
} else {
|
|
|
|
vc_write_var(5, 60);
|
|
|
|
}
|
|
|
|
vc_write_var(86, 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 61: // F3
|
2003-12-01 09:53:03 +00:00
|
|
|
if (_game & GF_SIMON2) {
|
|
|
|
vc_write_var(5, 125);
|
|
|
|
} else {
|
|
|
|
vc_write_var(5, 100);
|
|
|
|
}
|
|
|
|
vc_write_var(86, 2);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 63: // F5
|
|
|
|
if (_game & GF_SIMON2)
|
2005-05-06 11:37:33 +00:00
|
|
|
_exitCutscene = true;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2003-12-10 00:54:53 +00:00
|
|
|
case 'p':
|
|
|
|
pause();
|
|
|
|
break;
|
2003-09-24 06:33:59 +00:00
|
|
|
case 't':
|
2003-10-30 01:09:41 +00:00
|
|
|
if ((_game & GF_SIMON2 && _game & GF_TALKIE) || ( _game & GF_TALKIE && _language > 1))
|
2003-10-30 01:05:08 +00:00
|
|
|
if (_speech)
|
|
|
|
_subtitles ^= 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2003-10-30 01:05:08 +00:00
|
|
|
case 'v':
|
2003-10-30 01:09:41 +00:00
|
|
|
if ((_game & GF_SIMON2) && (_game & GF_TALKIE))
|
2003-10-30 01:05:08 +00:00
|
|
|
if (_subtitles)
|
|
|
|
_speech ^= 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
case '+':
|
|
|
|
midi.set_volume(midi.get_volume() + 16);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
midi.set_volume(midi.get_volume() - 16);
|
|
|
|
break;
|
|
|
|
case 'm':
|
2005-05-06 11:37:33 +00:00
|
|
|
midi.pause(_musicPaused ^= 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (_game == GAME_SIMON1DOS)
|
|
|
|
midi._enable_sfx ^= 1;
|
|
|
|
else
|
2005-05-06 11:37:33 +00:00
|
|
|
_sound->effectsPause(_effectsPaused ^= 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
2005-05-06 11:37:33 +00:00
|
|
|
_sound->ambientPause(_ambientPaused ^= 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (_debugMode)
|
2005-05-06 11:37:33 +00:00
|
|
|
_startMainScript ^= 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (_debugMode)
|
2005-05-06 11:37:33 +00:00
|
|
|
_continousMainScript ^= 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2003-12-20 06:39:24 +00:00
|
|
|
case 'a':
|
|
|
|
if (_debugMode)
|
2005-05-06 11:37:33 +00:00
|
|
|
_startVgaScript ^= 1;
|
2003-12-20 06:39:24 +00:00
|
|
|
break;
|
2003-10-30 01:05:08 +00:00
|
|
|
case 'g':
|
2003-09-24 06:33:59 +00:00
|
|
|
if (_debugMode)
|
2005-05-06 11:37:33 +00:00
|
|
|
_continousVgaScript ^= 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
if (_debugMode)
|
2005-05-06 11:37:33 +00:00
|
|
|
_drawImagesDebug ^= 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2003-12-11 09:14:10 +00:00
|
|
|
case 'd':
|
|
|
|
if (_debugMode)
|
2005-05-06 11:37:33 +00:00
|
|
|
_dumpImages ^=1;
|
2003-12-11 09:14:10 +00:00
|
|
|
break;
|
2002-12-07 13:05:58 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_keyPressed = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-12-10 00:54:53 +00:00
|
|
|
void SimonEngine::pause() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_keyPressed = 1;
|
2003-12-10 00:54:53 +00:00
|
|
|
_pause = 1;
|
2005-05-06 11:37:33 +00:00
|
|
|
bool ambient_status = _ambientPaused;
|
|
|
|
bool music_status = _musicPaused;
|
2004-02-12 13:33:01 +00:00
|
|
|
|
|
|
|
midi.pause(true);
|
|
|
|
_sound->ambientPause(true);
|
2003-12-10 01:05:21 +00:00
|
|
|
while (_pause) {
|
2003-12-10 00:54:53 +00:00
|
|
|
delay(1);
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_keyPressed == 'p')
|
2003-12-10 01:05:21 +00:00
|
|
|
_pause = 0;
|
2003-12-10 00:54:53 +00:00
|
|
|
}
|
2004-02-12 13:33:01 +00:00
|
|
|
midi.pause(music_status);
|
|
|
|
_sound->ambientPause(ambient_status);
|
2003-12-10 01:05:21 +00:00
|
|
|
|
2003-12-10 00:54:53 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::video_toggle_colors(HitArea * ha, byte a, byte b, byte c, byte d) {
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *src, color;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint w, h, i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x8000;
|
|
|
|
src = dx_lock_2() + ha->y * _dxSurfacePitch + ha->x;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
w = ha->width;
|
|
|
|
h = ha->height;
|
|
|
|
|
2003-07-30 11:16:09 +00:00
|
|
|
// Works around bug in original Simon the Sorcerer 2
|
2003-07-30 11:17:51 +00:00
|
|
|
// Animations continue in background when load/save dialog is open
|
|
|
|
// often causing the savegame name highlighter to be cut short
|
2005-10-07 07:36:09 +00:00
|
|
|
if (!(h > 0 && w > 0 && ha->x + w <= _screenWidth && ha->y + h <= _screenHeight)) {
|
2003-07-15 16:40:24 +00:00
|
|
|
debug(1,"Invalid coordinates in video_toggle_colors (%d,%d,%d,%d)", ha->x, ha->y, ha->width, ha->height);
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != w; ++i) {
|
2002-04-12 21:26:59 +00:00
|
|
|
color = src[i];
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a >= color && b < color) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (c >= color)
|
|
|
|
color += d;
|
|
|
|
else
|
|
|
|
color -= d;
|
|
|
|
src[i] = color;
|
|
|
|
}
|
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
src += _dxSurfacePitch;
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (--h);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
dx_unlock_2();
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::video_copy_if_flag_0x8_c(FillOrCopyStruct *fcs) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (fcs->flags & 8)
|
2002-04-12 21:26:59 +00:00
|
|
|
copy_img_from_3_to_2(fcs);
|
|
|
|
fcs->mode = 0;
|
|
|
|
}
|
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
void SimonEngine::loadSprite(uint windowNum, uint fileId, uint vgaSpriteId, uint x, uint y, uint palette) {
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *p, *pp;
|
2002-04-12 21:26:59 +00:00
|
|
|
uint count;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord |= 0x40;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 13:22:48 +00:00
|
|
|
if (isSpriteLoaded(vgaSpriteId, fileId)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x40;
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
2002-08-11 09:05:30 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
vsp = _vgaSprites;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (vsp->id != 0)
|
|
|
|
vsp++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-05 11:37:26 +00:00
|
|
|
vsp->windowNum = windowNum;
|
2002-11-28 00:22:24 +00:00
|
|
|
vsp->priority = 0;
|
2005-05-06 12:23:19 +00:00
|
|
|
vsp->flags = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-10-21 11:41:33 +00:00
|
|
|
vsp->y = y;
|
|
|
|
vsp->x = x;
|
2002-04-12 21:26:59 +00:00
|
|
|
vsp->image = 0;
|
2005-10-05 11:37:26 +00:00
|
|
|
vsp->palette = palette;
|
2005-05-06 12:23:19 +00:00
|
|
|
vsp->id = vgaSpriteId;
|
|
|
|
if (_game & GF_SIMON1)
|
2005-05-06 13:22:48 +00:00
|
|
|
vsp->fileId = fileId = vgaSpriteId / 100;
|
2003-12-20 09:05:25 +00:00
|
|
|
else
|
2005-05-06 13:22:48 +00:00
|
|
|
vsp->fileId = fileId;
|
2003-12-20 09:05:25 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2005-05-06 13:22:48 +00:00
|
|
|
vpe = &_vgaBufferPointers[fileId];
|
|
|
|
_vgaCurFile2 = fileId;
|
2005-05-06 11:37:33 +00:00
|
|
|
_curVgaFile1 = vpe->vgaFile1;
|
2002-04-12 21:26:59 +00:00
|
|
|
if (vpe->vgaFile1 != NULL)
|
|
|
|
break;
|
2005-05-06 13:22:48 +00:00
|
|
|
ensureVgaResLoaded(fileId);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
pp = _curVgaFile1;
|
2005-10-09 12:12:24 +00:00
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
|
|
|
p = pp + READ_LE_UINT16(&((VgaFileHeader_Feeble *) pp)->hdr2_start);
|
|
|
|
count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationCount);
|
|
|
|
p = pp + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationTable);
|
|
|
|
} else {
|
|
|
|
p = pp + READ_BE_UINT16(&((VgaFileHeader_Simon *) pp)->hdr2_start);
|
|
|
|
count = READ_BE_UINT16(&((VgaFileHeader2_Simon *) p)->animationCount);
|
|
|
|
p = pp + READ_BE_UINT16(&((VgaFileHeader2_Simon *) p)->animationTable);
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2005-10-09 12:12:24 +00:00
|
|
|
if (_game == GAME_FEEBLEFILES) {
|
|
|
|
if (READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->id) == vgaSpriteId) {
|
|
|
|
if (_startVgaScript)
|
|
|
|
dump_vga_script(pp + READ_LE_UINT16(&((AnimationHeader_Feeble*)p)->scriptOffs), fileId, vgaSpriteId);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-10-09 12:12:24 +00:00
|
|
|
add_vga_timer(VGA_DELAY_BASE, pp + READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->scriptOffs), vgaSpriteId, fileId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p += sizeof(AnimationHeader_Feeble);
|
|
|
|
} else {
|
|
|
|
if (READ_BE_UINT16(&((AnimationHeader_Simon *) p)->id) == vgaSpriteId) {
|
|
|
|
if (_startVgaScript)
|
|
|
|
dump_vga_script(pp + READ_BE_UINT16(&((AnimationHeader_Simon*)p)->scriptOffs), fileId, vgaSpriteId);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-09 12:12:24 +00:00
|
|
|
add_vga_timer(VGA_DELAY_BASE, pp + READ_BE_UINT16(&((AnimationHeader_Simon *) p)->scriptOffs), vgaSpriteId, fileId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p += sizeof(AnimationHeader_Simon);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2005-10-09 12:12:24 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!--count) {
|
|
|
|
vsp->id = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lockWord &= ~0x40;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 12:23:19 +00:00
|
|
|
void SimonEngine::talk_with_speech(uint speech_id, uint vgaSpriteId) {
|
2003-03-01 22:52:49 +00:00
|
|
|
if (!(_game & GF_SIMON2)) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (speech_id == 9999) {
|
2003-06-05 12:20:05 +00:00
|
|
|
if (_subtitles)
|
|
|
|
return;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!(_bitArray[0] & 0x4000) && !(_bitArray[1] & 0x1000)) {
|
|
|
|
_bitArray[0] |= 0x4000;
|
2002-12-08 13:37:38 +00:00
|
|
|
_variableArray[100] = 0xF;
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 1, 0x82, 0, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
o_wait_for_vga(0x82);
|
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
_skipVgaWait = true;
|
2003-06-05 12:20:05 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_subtitles && _scriptVar2) {
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 2, 204, 0, 0, 0);
|
2003-06-05 12:20:05 +00:00
|
|
|
o_wait_for_vga(204);
|
|
|
|
o_kill_sprite_simon1(204);
|
|
|
|
}
|
2005-05-06 12:23:19 +00:00
|
|
|
o_kill_sprite_simon1(vgaSpriteId + 201);
|
2003-06-05 12:20:05 +00:00
|
|
|
_sound->playVoice(speech_id);
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 2, vgaSpriteId + 201, 0, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (speech_id == 0xFFFF) {
|
2003-03-07 12:29:33 +00:00
|
|
|
if (_subtitles)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!(_bitArray[0] & 0x4000) && !(_bitArray[1] & 0x1000)) {
|
|
|
|
_bitArray[0] |= 0x4000;
|
2002-12-08 13:37:38 +00:00
|
|
|
_variableArray[100] = 5;
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 1, 0x1e, 0, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
o_wait_for_vga(0x82);
|
|
|
|
}
|
2005-05-06 11:37:33 +00:00
|
|
|
_skipVgaWait = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2004-02-09 05:11:54 +00:00
|
|
|
if (_subtitles && _language != 20) {
|
|
|
|
_sound->playVoice(speech_id);
|
|
|
|
return;
|
2005-05-06 11:37:33 +00:00
|
|
|
} else if (_subtitles && _scriptVar2) {
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 2, 5, 0, 0, 0);
|
2003-12-22 11:08:35 +00:00
|
|
|
o_wait_for_vga(205);
|
|
|
|
o_kill_sprite_simon2(2,5);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2003-12-22 11:08:35 +00:00
|
|
|
|
2005-05-06 12:23:19 +00:00
|
|
|
o_kill_sprite_simon2(2, vgaSpriteId + 2);
|
2002-11-24 12:53:01 +00:00
|
|
|
_sound->playVoice(speech_id);
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(4, 2, vgaSpriteId + 2, 0, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 12:23:19 +00:00
|
|
|
void SimonEngine::talk_with_text(uint vgaSpriteId, uint color, const char *string, int16 x, int16 y, int16 width) {
|
2004-03-14 23:47:15 +00:00
|
|
|
char convertedString[320];
|
|
|
|
char *convertedString2 = convertedString;
|
|
|
|
int16 height, len_div_3;
|
|
|
|
int stringLength = strlen(string);
|
2004-07-31 08:55:08 +00:00
|
|
|
int padding, lettersPerRow, lettersPerRowJustified;
|
2004-03-14 23:47:15 +00:00
|
|
|
const int textHeight = 10;
|
|
|
|
|
|
|
|
height = textHeight;
|
|
|
|
lettersPerRow = width / 6;
|
2004-07-30 20:05:24 +00:00
|
|
|
lettersPerRowJustified = stringLength / (stringLength / lettersPerRow + 1) + 1;
|
2004-03-14 23:47:15 +00:00
|
|
|
|
|
|
|
len_div_3 = (stringLength + 3) / 3;
|
2003-12-01 00:54:50 +00:00
|
|
|
if (!(_game & GF_SIMON2) && (_game & GF_TALKIE)) {
|
2002-04-14 11:00:33 +00:00
|
|
|
if (_variableArray[141] == 0)
|
|
|
|
_variableArray[141] = 9;
|
|
|
|
_variableArray[85] = _variableArray[141] * len_div_3;
|
|
|
|
} else {
|
2003-11-29 10:12:47 +00:00
|
|
|
if (_variableArray[86] == 0)
|
2003-12-01 00:45:16 +00:00
|
|
|
len_div_3 >>= 1;
|
2003-11-29 10:12:47 +00:00
|
|
|
if (_variableArray[86] == 2)
|
2002-07-07 19:06:48 +00:00
|
|
|
len_div_3 <<= 1;
|
2003-08-05 17:42:23 +00:00
|
|
|
_variableArray[85] = len_div_3 * 5;
|
2002-04-14 11:00:33 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-03-14 23:47:15 +00:00
|
|
|
assert(stringLength > 0);
|
|
|
|
while (stringLength > 0) {
|
2004-07-31 08:55:08 +00:00
|
|
|
int pos = 0;
|
2004-03-14 23:47:15 +00:00
|
|
|
if (stringLength > lettersPerRow) {
|
2004-07-30 20:05:24 +00:00
|
|
|
int removeLastWord = 0;
|
|
|
|
if (lettersPerRow > lettersPerRowJustified) {
|
|
|
|
pos = lettersPerRowJustified;
|
|
|
|
while (string[pos] != ' ')
|
|
|
|
pos++;
|
|
|
|
if (pos > lettersPerRow)
|
|
|
|
removeLastWord = 1;
|
|
|
|
}
|
|
|
|
if (lettersPerRow <= lettersPerRowJustified || removeLastWord) {
|
|
|
|
pos = lettersPerRow;
|
|
|
|
while (string[pos] != ' ' && pos > 0)
|
|
|
|
pos--;
|
|
|
|
}
|
2004-03-14 23:47:15 +00:00
|
|
|
height += textHeight;
|
|
|
|
y -= textHeight;
|
|
|
|
} else
|
|
|
|
pos = stringLength;
|
2004-07-30 20:05:24 +00:00
|
|
|
padding = (lettersPerRow - pos) % 2 ?
|
|
|
|
(lettersPerRow - pos) / 2 + 1 : (lettersPerRow - pos) / 2;
|
2004-03-14 23:47:15 +00:00
|
|
|
while (padding--)
|
|
|
|
*convertedString2++ = ' ';
|
|
|
|
stringLength -= pos;
|
|
|
|
while (pos--)
|
|
|
|
*convertedString2++ = *string++;
|
|
|
|
*convertedString2++ = '\n';
|
|
|
|
string++; // skip space
|
|
|
|
stringLength--; // skip space
|
|
|
|
}
|
|
|
|
*(convertedString2 - 1) = '\0';
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-03-14 23:47:15 +00:00
|
|
|
if (_game & GF_SIMON2)
|
2005-05-06 12:23:19 +00:00
|
|
|
o_kill_sprite_simon2(2, vgaSpriteId);
|
2004-03-14 23:47:15 +00:00
|
|
|
else
|
2005-05-06 12:23:19 +00:00
|
|
|
o_kill_sprite_simon1(vgaSpriteId + 199);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-03-14 23:47:15 +00:00
|
|
|
color = color * 3 + 192;
|
2003-12-16 05:04:39 +00:00
|
|
|
if (_game & GF_AMIGA)
|
2005-05-06 12:23:19 +00:00
|
|
|
render_string_amiga(vgaSpriteId, color, width, height, convertedString);
|
2003-12-16 05:04:39 +00:00
|
|
|
else
|
2005-05-06 12:23:19 +00:00
|
|
|
render_string(vgaSpriteId, color, width, height, convertedString);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-03-14 23:47:15 +00:00
|
|
|
int b = 4;
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!(_bitArray[8] & 0x20))
|
2004-03-14 17:50:40 +00:00
|
|
|
b = 3;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-03-14 23:47:15 +00:00
|
|
|
x >>= 3;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-03-14 17:50:40 +00:00
|
|
|
if (y < 2)
|
|
|
|
y = 2;
|
2002-06-18 08:38:39 +00:00
|
|
|
|
2004-03-14 23:47:15 +00:00
|
|
|
if (_game & GF_SIMON2)
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(b, 2, vgaSpriteId, x, y, 12);
|
2004-03-14 23:47:15 +00:00
|
|
|
else
|
2005-05-06 13:22:48 +00:00
|
|
|
loadSprite(b, 2, vgaSpriteId + 199, x, y, 12);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-09-29 04:15:24 +00:00
|
|
|
// Thanks to Stuart Caie for providing the original
|
|
|
|
// C conversion upon which this decruncher is based.
|
|
|
|
|
2003-11-08 20:54:31 +00:00
|
|
|
#define SD_GETBIT(var) do { \
|
|
|
|
if (!bits--) { \
|
|
|
|
s -= 4; \
|
|
|
|
if (s < src) \
|
|
|
|
return false; \
|
|
|
|
bb = READ_BE_UINT32(s); \
|
|
|
|
bits = 31; \
|
|
|
|
} \
|
|
|
|
(var) = bb & 1; \
|
|
|
|
bb >>= 1; \
|
2005-05-08 21:49:52 +00:00
|
|
|
}while (0)
|
2003-09-29 04:15:24 +00:00
|
|
|
|
|
|
|
#define SD_GETBITS(var, nbits) do { \
|
2003-11-08 20:54:31 +00:00
|
|
|
bc = (nbits); \
|
|
|
|
(var) = 0; \
|
2005-05-08 21:49:52 +00:00
|
|
|
while (bc--) { \
|
2003-11-08 20:54:31 +00:00
|
|
|
(var) <<= 1; \
|
|
|
|
SD_GETBIT(bit); \
|
|
|
|
(var) |= bit; \
|
|
|
|
} \
|
2005-05-08 21:49:52 +00:00
|
|
|
}while (0)
|
2003-09-29 04:15:24 +00:00
|
|
|
|
|
|
|
#define SD_TYPE_LITERAL (0)
|
|
|
|
#define SD_TYPE_MATCH (1)
|
|
|
|
|
|
|
|
static bool decrunch_file_amiga (byte *src, byte *dst, uint32 size) {
|
|
|
|
byte *s = src + size - 4;
|
|
|
|
uint32 destlen = READ_BE_UINT32 (s);
|
|
|
|
uint32 bb, x, y;
|
|
|
|
byte *d = dst + destlen;
|
|
|
|
byte bc, bit, bits, type;
|
|
|
|
|
|
|
|
// Initialize bit buffer.
|
|
|
|
s -= 4;
|
|
|
|
bb = x = READ_BE_UINT32 (s);
|
|
|
|
bits = 0;
|
|
|
|
do {
|
|
|
|
x >>= 1;
|
|
|
|
bits++;
|
|
|
|
} while (x);
|
|
|
|
bits--;
|
|
|
|
|
|
|
|
while (d > dst) {
|
|
|
|
SD_GETBIT(x);
|
|
|
|
if (x) {
|
2003-11-08 20:54:31 +00:00
|
|
|
SD_GETBITS(x, 2);
|
2003-09-29 04:15:24 +00:00
|
|
|
switch (x) {
|
|
|
|
case 0:
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 9;
|
|
|
|
y = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 10;
|
|
|
|
y = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 12;
|
2003-11-08 20:54:31 +00:00
|
|
|
SD_GETBITS(y, 8);
|
2003-09-29 04:15:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
type = SD_TYPE_LITERAL;
|
|
|
|
x = 8;
|
|
|
|
y = 8;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SD_GETBIT(x);
|
|
|
|
if (x) {
|
|
|
|
type = SD_TYPE_MATCH;
|
|
|
|
x = 8;
|
|
|
|
y = 1;
|
|
|
|
} else {
|
|
|
|
type = SD_TYPE_LITERAL;
|
|
|
|
x = 3;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == SD_TYPE_LITERAL) {
|
2003-11-08 20:54:31 +00:00
|
|
|
SD_GETBITS(x, x);
|
2003-09-29 04:15:24 +00:00
|
|
|
y += x;
|
|
|
|
if ((int)(y + 1) > (d - dst))
|
|
|
|
return false; // Overflow?
|
|
|
|
do {
|
2003-11-08 20:54:31 +00:00
|
|
|
SD_GETBITS(x, 8);
|
2003-09-29 04:15:24 +00:00
|
|
|
*--d = x;
|
|
|
|
} while (y-- > 0);
|
|
|
|
} else {
|
|
|
|
if ((int)(y + 1) > (d - dst))
|
|
|
|
return false; // Overflow?
|
2003-11-08 20:54:31 +00:00
|
|
|
SD_GETBITS(x, x);
|
2003-09-29 04:15:24 +00:00
|
|
|
if ((d + x) > (dst + destlen))
|
|
|
|
return false; // Offset overflow?
|
|
|
|
do {
|
|
|
|
d--;
|
|
|
|
*d = d[x];
|
|
|
|
} while (y-- > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Successful decrunch.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef SD_GETBIT
|
|
|
|
#undef SD_GETBITS
|
|
|
|
#undef SD_TYPE_LITERAL
|
|
|
|
#undef SD_TYPE_MATCH
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::read_vga_from_datfile_1(uint vga_id) {
|
2003-12-02 06:23:05 +00:00
|
|
|
if (_game & GF_OLD_BUNDLE) {
|
2002-09-16 08:22:30 +00:00
|
|
|
File in;
|
2004-01-01 09:00:40 +00:00
|
|
|
char buf[15];
|
2002-04-12 21:26:59 +00:00
|
|
|
uint32 size;
|
2005-07-30 21:11:48 +00:00
|
|
|
if (vga_id == 23)
|
2003-01-14 05:25:31 +00:00
|
|
|
vga_id = 112;
|
|
|
|
if (vga_id == 328)
|
|
|
|
vga_id = 119;
|
|
|
|
|
|
|
|
if (_game == GAME_SIMON1CD32) {
|
2005-07-30 21:11:48 +00:00
|
|
|
sprintf(buf, "0%d.out", vga_id);
|
2003-01-14 05:25:31 +00:00
|
|
|
} else if (_game == GAME_SIMON1AMIGA) {
|
2003-09-29 04:15:24 +00:00
|
|
|
sprintf(buf, "0%d.pkd", vga_id);
|
2003-01-14 05:25:31 +00:00
|
|
|
} else {
|
2005-07-30 21:11:48 +00:00
|
|
|
sprintf(buf, "0%d.VGA", vga_id);
|
2003-01-14 04:25:38 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-06-27 22:14:35 +00:00
|
|
|
in.open(buf);
|
2003-01-03 04:24:16 +00:00
|
|
|
if (in.isOpen() == false)
|
2003-01-03 10:36:13 +00:00
|
|
|
error("read_vga_from_datfile_1: can't open %s", buf);
|
2002-10-21 12:34:54 +00:00
|
|
|
size = in.size();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-09-29 04:15:24 +00:00
|
|
|
if (_game == GAME_SIMON1AMIGA) {
|
|
|
|
byte *buffer = new byte[size];
|
|
|
|
if (in.read(buffer, size) != size)
|
|
|
|
error("read_vga_from_datfile_1: read failed");
|
2005-05-06 11:37:33 +00:00
|
|
|
decrunch_file_amiga (buffer, _vgaBufferPointers[11].vgaFile2, size);
|
2003-09-29 04:15:24 +00:00
|
|
|
delete [] buffer;
|
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (in.read(_vgaBufferPointers[11].vgaFile2, size) != size)
|
2003-09-29 04:15:24 +00:00
|
|
|
error("read_vga_from_datfile_1: read failed");
|
|
|
|
}
|
2002-09-16 08:22:30 +00:00
|
|
|
in.close();
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
uint32 offs_a = _gameOffsetsPtr[vga_id];
|
|
|
|
uint32 size = _gameOffsetsPtr[vga_id + 1] - offs_a;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
resfile_read(_vgaBufferPointers[11].vgaFile2, offs_a, size);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte *SimonEngine::read_vga_from_datfile_2(uint id) {
|
2004-04-12 12:25:51 +00:00
|
|
|
// !!! HACK !!!
|
|
|
|
// allocate more space for text to cope with foreign languages that use
|
|
|
|
// up more space than english. I hope 6400 bytes are enough. This number
|
|
|
|
// is base on: 2 (lines) * 320 (screen width) * 10 (textheight) -- olki
|
|
|
|
int extraBuffer = (id == 5 ? 6400 : 0);
|
|
|
|
|
2003-12-02 06:23:05 +00:00
|
|
|
if (_game & GF_OLD_BUNDLE) {
|
2002-09-16 08:22:30 +00:00
|
|
|
File in;
|
2004-01-01 09:00:40 +00:00
|
|
|
char buf[15];
|
2002-04-12 21:26:59 +00:00
|
|
|
uint32 size;
|
|
|
|
byte *dst;
|
|
|
|
|
2003-01-14 05:25:31 +00:00
|
|
|
if (_game == GAME_SIMON1CD32) {
|
2003-01-14 04:25:38 +00:00
|
|
|
sprintf(buf, "%.3d%d.out", id >> 1, (id & 1) + 1);
|
2003-01-14 05:25:31 +00:00
|
|
|
} else if (_game == GAME_SIMON1AMIGA) {
|
2003-09-29 04:15:24 +00:00
|
|
|
sprintf(buf, "%.3d%d.pkd", id >> 1, (id & 1) + 1);
|
2003-01-14 05:25:31 +00:00
|
|
|
} else {
|
2003-01-14 04:25:38 +00:00
|
|
|
sprintf(buf, "%.3d%d.VGA", id >> 1, (id & 1) + 1);
|
2003-01-14 05:25:31 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-06-27 22:14:35 +00:00
|
|
|
in.open(buf);
|
2002-09-16 08:22:30 +00:00
|
|
|
if (in.isOpen() == false)
|
2003-01-03 10:36:13 +00:00
|
|
|
error("read_vga_from_datfile_2: can't open %s", buf);
|
2002-10-21 12:34:54 +00:00
|
|
|
size = in.size();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-09-29 04:15:24 +00:00
|
|
|
if (_game == GAME_SIMON1AMIGA) {
|
|
|
|
byte *buffer = new byte[size];
|
|
|
|
if (in.read(buffer, size) != size)
|
|
|
|
error("read_vga_from_datfile_2: read failed");
|
2004-04-12 12:25:51 +00:00
|
|
|
dst = setup_vga_destination (READ_BE_UINT32(buffer + size - 4) + extraBuffer);
|
2003-09-29 04:15:24 +00:00
|
|
|
decrunch_file_amiga (buffer, dst, size);
|
2004-12-15 20:25:50 +00:00
|
|
|
delete[] buffer;
|
2003-09-29 04:15:24 +00:00
|
|
|
} else {
|
2004-04-12 12:25:51 +00:00
|
|
|
dst = setup_vga_destination(size + extraBuffer);
|
2003-09-29 04:15:24 +00:00
|
|
|
if (in.read(dst, size) != size)
|
|
|
|
error("read_vga_from_datfile_2: read failed");
|
|
|
|
}
|
2002-09-16 08:22:30 +00:00
|
|
|
in.close();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
uint32 offs_a = _gameOffsetsPtr[id];
|
|
|
|
uint32 size = _gameOffsetsPtr[id + 1] - offs_a;
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst;
|
|
|
|
|
2004-04-12 12:25:51 +00:00
|
|
|
dst = setup_vga_destination(size + extraBuffer);
|
2002-04-12 21:26:59 +00:00
|
|
|
resfile_read(dst, offs_a, size);
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::resfile_read(void *dst, uint32 offs, uint32 size) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(offs, SEEK_SET);
|
|
|
|
if (_gameFile->read(dst, size) != size)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("resfile_read(%d,%d) read failed", offs, size);
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::openGameFile() {
|
2003-12-02 06:23:05 +00:00
|
|
|
if (!(_game & GF_OLD_BUNDLE)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile = new File();
|
|
|
|
_gameFile->open(gss->gme_filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_gameFile->isOpen() == false)
|
2003-01-03 10:36:13 +00:00
|
|
|
error("Can't open game file '%s'", gss->gme_filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
uint32 size = _gameFile->readUint32LE();
|
2002-11-30 11:07:06 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameOffsetsPtr = (uint32 *)malloc(size);
|
|
|
|
if (_gameOffsetsPtr == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("out of memory, game offsets");
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
resfile_read(_gameOffsetsPtr, 0, size);
|
2002-04-21 12:51:13 +00:00
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
2002-11-30 11:07:06 +00:00
|
|
|
for (uint r = 0; r < size / sizeof(uint32); r++)
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameOffsetsPtr[r] = FROM_LE_32(_gameOffsetsPtr[r]);
|
2002-04-21 12:51:13 +00:00
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-10-06 14:34:24 +00:00
|
|
|
if (_game != GAME_FEEBLEFILES)
|
|
|
|
loadIconFile();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-10-05 12:16:49 +00:00
|
|
|
vc34_setMouseOff();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
runSubroutine101();
|
|
|
|
startUp_helper_2();
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::runSubroutine101() {
|
2002-04-12 21:26:59 +00:00
|
|
|
Subroutine *sub;
|
|
|
|
|
|
|
|
sub = getSubroutineByID(101);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
startUp_helper_2();
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_copy_rgn_from_3_to_2(uint b, uint r, uint y, uint x) {
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst, *src;
|
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
dst = dx_lock_2();
|
2002-08-18 16:21:34 +00:00
|
|
|
src = _sdl_buf_3;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
dst += y * _dxSurfacePitch;
|
|
|
|
src += y * _dxSurfacePitch;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
while (y < b) {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = x; i < r; i++)
|
2002-04-12 21:26:59 +00:00
|
|
|
dst[i] = src[i];
|
|
|
|
y++;
|
2005-05-06 11:37:33 +00:00
|
|
|
dst += _dxSurfacePitch;
|
|
|
|
src += _dxSurfacePitch;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
dx_unlock_2();
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_clear_surfaces(uint num_lines) {
|
2005-10-07 07:36:09 +00:00
|
|
|
memset(_sdl_buf_attached, 0, num_lines * _screenWidth);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2005-10-07 07:36:09 +00:00
|
|
|
_system->copyRectToScreen(_sdl_buf_attached, _screenWidth, 0, 0, _screenWidth, _screenHeight);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_dxUse3Or4ForLock) {
|
2005-10-07 07:36:09 +00:00
|
|
|
memset(_sdl_buf, 0, num_lines * _screenWidth);
|
|
|
|
memset(_sdl_buf_3, 0, num_lines * _screenWidth);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_clear_attached_from_top(uint lines) {
|
2005-10-07 07:36:09 +00:00
|
|
|
memset(_sdl_buf_attached, 0, lines * _screenWidth);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_copy_from_attached_to_2(uint x, uint y, uint w, uint h) {
|
2005-10-07 07:36:09 +00:00
|
|
|
uint offs = x + y * _screenWidth;
|
2002-08-18 16:21:34 +00:00
|
|
|
byte *s = _sdl_buf_attached + offs;
|
|
|
|
byte *d = _sdl_buf + offs;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(d, s, w);
|
2005-10-07 07:36:09 +00:00
|
|
|
d += _screenWidth;
|
|
|
|
s += _screenWidth;
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (--h);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_copy_from_2_to_attached(uint x, uint y, uint w, uint h) {
|
2005-10-07 07:36:09 +00:00
|
|
|
uint offs = x + y * _screenWidth;
|
2002-08-18 16:21:34 +00:00
|
|
|
byte *s = _sdl_buf + offs;
|
|
|
|
byte *d = _sdl_buf_attached + offs;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(d, s, w);
|
2005-10-07 07:36:09 +00:00
|
|
|
d += _screenWidth;
|
|
|
|
s += _screenWidth;
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (--h);
|
2002-04-16 12:07:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_copy_from_attached_to_3(uint lines) {
|
2005-10-07 07:36:09 +00:00
|
|
|
memcpy(_sdl_buf_3, _sdl_buf_attached, lines * _screenWidth);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_update_screen_and_palette() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_numScreenUpdates++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_paletteColorCount == 0 && _videoVar9 == 1) {
|
|
|
|
_videoVar9 = 0;
|
|
|
|
if (memcmp(_palette, _paletteBackup, 256 * 4) != 0) {
|
|
|
|
memcpy(_paletteBackup, _palette, 256 * 4);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->setPalette(_palette, 0, 256);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-07 07:36:09 +00:00
|
|
|
_system->copyRectToScreen(_sdl_buf_attached, _screenWidth, 0, 0, _screenWidth, _screenHeight);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-10-07 07:36:09 +00:00
|
|
|
memcpy(_sdl_buf_attached, _sdl_buf, _screenWidth * _screenHeight);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_paletteColorCount != 0) {
|
|
|
|
if (!(_game & GF_SIMON2) && _usePaletteDelay) {
|
2002-04-12 21:26:59 +00:00
|
|
|
delay(100);
|
2005-05-06 11:37:33 +00:00
|
|
|
_usePaletteDelay = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
realizePalette();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::realizePalette() {
|
2005-05-06 11:37:33 +00:00
|
|
|
_videoVar9 = false;
|
|
|
|
memcpy(_paletteBackup, _palette, 256 * 4);
|
2003-05-20 08:49:13 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_paletteColorCount & 0x8000) {
|
2003-05-20 08:49:13 +00:00
|
|
|
fadeUpPalette();
|
2002-11-28 05:52:55 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_system->setPalette(_palette, 0, _paletteColorCount);
|
2002-11-28 05:52:55 +00:00
|
|
|
}
|
2003-05-20 08:49:13 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_paletteColorCount = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::fadeUpPalette() {
|
2003-05-20 08:49:13 +00:00
|
|
|
bool done;
|
2003-01-19 15:39:54 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_paletteColorCount = (_paletteColorCount & 0x7fff) / 4;
|
2003-05-20 08:49:13 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
memset(_videoBuf1, 0, _paletteColorCount * sizeof(uint32));
|
2003-05-20 08:49:13 +00:00
|
|
|
|
|
|
|
// This function is used by Simon 2 when riding the lion to the goblin
|
2005-05-06 11:37:33 +00:00
|
|
|
// camp. Note that _paletteColorCount is not 1024 in this scene, so
|
2003-05-20 08:49:13 +00:00
|
|
|
// only part of the palette is faded up. But apparently that's enough,
|
|
|
|
// as long as we make sure that the remaining palette colours aren't
|
|
|
|
// completely ignored.
|
2003-01-19 15:39:54 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_paletteColorCount < _videoNumPalColors)
|
|
|
|
memcpy(_videoBuf1 + _paletteColorCount * sizeof(uint32),
|
|
|
|
_palette + _paletteColorCount * sizeof(uint32),
|
|
|
|
(_videoNumPalColors - _paletteColorCount) * sizeof(uint32));
|
2003-05-20 08:49:13 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
uint8 *src;
|
|
|
|
byte *dst;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
done = true;
|
2003-11-08 20:54:31 +00:00
|
|
|
src = _palette;
|
2005-05-06 11:37:33 +00:00
|
|
|
dst = _videoBuf1;
|
2003-01-19 15:39:54 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
for (i = 0; i < _paletteColorCount; i++) {
|
2003-05-20 08:49:13 +00:00
|
|
|
if (src[0] > dst[0]) {
|
|
|
|
if (dst[0] > src[0] - 4)
|
|
|
|
dst[0] = src[0];
|
|
|
|
else
|
|
|
|
dst[0] += 4;
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
if (src[1] > dst[1]) {
|
|
|
|
if (dst[1] > src[1] - 4)
|
|
|
|
dst[1] = src[1];
|
|
|
|
else
|
|
|
|
dst[1] += 4;
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
if (src[2] > dst[2]) {
|
|
|
|
if (dst[2] > src[2] - 4)
|
|
|
|
dst[2] = src[2];
|
|
|
|
else
|
|
|
|
dst[2] += 4;
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
dst += 4;
|
|
|
|
src += 4;
|
2003-01-19 15:39:54 +00:00
|
|
|
}
|
2003-05-20 08:49:13 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_system->setPalette(_videoBuf1, 0, _videoNumPalColors);
|
2003-01-19 15:39:54 +00:00
|
|
|
delay(5);
|
2003-05-20 08:49:13 +00:00
|
|
|
} while (!done);
|
2003-01-19 15:39:54 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
int SimonEngine::go() {
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!_dumpFile)
|
|
|
|
_dumpFile = stdout;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// allocate buffers
|
2005-10-07 07:36:09 +00:00
|
|
|
_sdl_buf_3 = (byte *)calloc(_screenWidth * _screenHeight, 1);
|
|
|
|
_sdl_buf = (byte *)calloc(_screenWidth * _screenHeight, 1);
|
|
|
|
_sdl_buf_attached = (byte *)calloc(_screenWidth * _screenHeight, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
allocItemHeap();
|
|
|
|
allocTablesHeap();
|
|
|
|
|
|
|
|
setup_vga_file_buf_pointers();
|
|
|
|
|
2004-06-27 22:14:35 +00:00
|
|
|
_sound = new Sound(_game, gss, _mixer);
|
2004-01-27 16:28:39 +00:00
|
|
|
_debugger = new Debugger(this);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-12-21 16:51:31 +00:00
|
|
|
if (ConfMan.hasKey("sfx_mute") && ConfMan.getBool("sfx_mute") == 1) {
|
|
|
|
if (_game == GAME_SIMON1DOS)
|
|
|
|
midi._enable_sfx ^= 1;
|
|
|
|
else
|
2005-05-06 11:37:33 +00:00
|
|
|
_sound->effectsPause(_effectsPaused ^= 1);
|
2003-12-21 16:51:31 +00:00
|
|
|
}
|
|
|
|
|
2003-01-03 10:36:13 +00:00
|
|
|
loadGamePcFile(gss->gamepc_filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
addTimeEvent(0, 1);
|
|
|
|
openGameFile();
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastMusicPlayed = -1;
|
2005-10-05 11:37:26 +00:00
|
|
|
_frameRate = 1;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_startMainScript = false;
|
|
|
|
_continousMainScript = false;
|
|
|
|
_startVgaScript = false;
|
|
|
|
_continousVgaScript = false;
|
|
|
|
_drawImagesDebug = false;
|
2002-11-24 13:05:44 +00:00
|
|
|
|
2005-04-23 13:52:27 +00:00
|
|
|
if (gDebugLevel == 2)
|
2005-05-06 11:37:33 +00:00
|
|
|
_continousMainScript = true;
|
2005-04-23 13:52:27 +00:00
|
|
|
if (gDebugLevel == 3)
|
2005-05-06 11:37:33 +00:00
|
|
|
_continousVgaScript = true;
|
2005-04-23 13:52:27 +00:00
|
|
|
if (gDebugLevel == 4)
|
2005-05-06 11:37:33 +00:00
|
|
|
_startMainScript = true;
|
2005-04-23 13:52:27 +00:00
|
|
|
if (gDebugLevel == 5)
|
2005-05-06 11:37:33 +00:00
|
|
|
_startVgaScript = true;
|
2002-12-06 15:24:14 +00:00
|
|
|
|
2003-06-05 13:47:07 +00:00
|
|
|
if (_game & GF_TALKIE) {
|
2003-10-26 05:31:36 +00:00
|
|
|
// English and German versions of Simon the Sorcerer 1 don't have full subtitles
|
2005-07-30 21:11:48 +00:00
|
|
|
if (!(_game & GF_SIMON2) && _language < 2)
|
2003-10-26 05:31:36 +00:00
|
|
|
_subtitles = false;
|
2003-12-02 08:09:14 +00:00
|
|
|
} else {
|
|
|
|
_subtitles = true;
|
2003-06-05 13:47:07 +00:00
|
|
|
}
|
2003-05-26 07:35:33 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
hitarea_stuff();
|
2005-05-06 11:37:33 +00:00
|
|
|
handle_verb_clicked(_verbHitArea);
|
2002-04-12 21:26:59 +00:00
|
|
|
delay(100);
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::shutdown() {
|
2005-05-06 11:37:33 +00:00
|
|
|
delete _gameFile;
|
2004-12-18 02:08:32 +00:00
|
|
|
|
|
|
|
midi.close();
|
2004-10-18 14:50:09 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
free(_stringTabPtr);
|
|
|
|
free(_itemArrayPtr);
|
|
|
|
free(_itemHeapPtr - _itemHeapCurPos);
|
|
|
|
free(_tablesHeapPtr - _tablesHeapCurPos);
|
|
|
|
free(_tblList);
|
|
|
|
free(_iconFilePtr);
|
|
|
|
free(_gameOffsetsPtr);
|
2004-12-18 02:08:32 +00:00
|
|
|
|
2003-05-29 06:05:34 +00:00
|
|
|
_system->quit();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::delay(uint amount) {
|
2002-07-07 19:06:48 +00:00
|
|
|
OSystem::Event event;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
uint32 start = _system->getMillis();
|
2002-04-12 21:26:59 +00:00
|
|
|
uint32 cur = start;
|
2003-12-10 00:54:53 +00:00
|
|
|
uint this_delay, vga_period;
|
2003-05-30 05:39:14 +00:00
|
|
|
|
2004-01-27 16:28:39 +00:00
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_fastMode)
|
2003-05-30 05:39:14 +00:00
|
|
|
vga_period = 10;
|
|
|
|
else if (_game & GF_SIMON2)
|
2003-12-18 09:36:17 +00:00
|
|
|
vga_period = 45 * _speed;
|
2003-07-25 06:55:05 +00:00
|
|
|
else
|
2003-12-18 09:36:17 +00:00
|
|
|
vga_period = 50 * _speed;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-12-01 15:36:36 +00:00
|
|
|
_rnd.getRandomNumber(2);
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
do {
|
2005-05-06 11:37:33 +00:00
|
|
|
while (!_inCallBack && cur >= _lastVgaTick + vga_period && !_pause) {
|
|
|
|
_lastVgaTick += vga_period;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2003-05-19 00:38:35 +00:00
|
|
|
// don't get too many frames behind
|
2005-05-06 11:37:33 +00:00
|
|
|
if (cur >= _lastVgaTick + vga_period * 2)
|
|
|
|
_lastVgaTick = cur;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_inCallBack = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
timer_callback();
|
2005-05-06 11:37:33 +00:00
|
|
|
_inCallBack = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
while (_system->pollEvent(event)) {
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2003-09-24 06:33:59 +00:00
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2003-12-13 01:26:40 +00:00
|
|
|
if (event.kbd.keycode >= '0' && event.kbd.keycode <='9'
|
2003-12-11 02:09:18 +00:00
|
|
|
&& (event.kbd.flags == OSystem::KBD_ALT ||
|
|
|
|
event.kbd.flags == OSystem::KBD_CTRL)) {
|
|
|
|
_saveLoadSlot = event.kbd.keycode - '0';
|
2003-12-13 01:26:40 +00:00
|
|
|
|
|
|
|
// There is no save slot 0
|
|
|
|
if (_saveLoadSlot == 0)
|
|
|
|
_saveLoadSlot = 10;
|
|
|
|
|
2003-12-11 02:09:18 +00:00
|
|
|
sprintf(_saveLoadName, "Quicksave %d", _saveLoadSlot);
|
2005-05-06 11:37:33 +00:00
|
|
|
_saveLoadType = (event.kbd.flags == OSystem::KBD_ALT) ? 1 : 2;
|
2003-12-11 02:09:18 +00:00
|
|
|
|
|
|
|
// We should only allow a load or save when it was possible in original
|
2003-12-12 01:31:02 +00:00
|
|
|
// This stops load/save during copy protection, conversations and cut scenes
|
2005-05-06 11:37:33 +00:00
|
|
|
if (!_lockCounter && !_showPreposition)
|
2003-12-11 03:50:25 +00:00
|
|
|
quick_load_or_save();
|
|
|
|
} else if (event.kbd.flags == OSystem::KBD_CTRL) {
|
2003-12-11 04:41:42 +00:00
|
|
|
if (event.kbd.keycode == 'a') {
|
|
|
|
GUI::Dialog *_aboutDialog;
|
|
|
|
_aboutDialog = new GUI::AboutDialog();
|
|
|
|
_aboutDialog->runModal();
|
2003-12-18 09:36:17 +00:00
|
|
|
} else if (event.kbd.keycode == 'f')
|
2005-05-06 11:37:33 +00:00
|
|
|
_fastMode ^= 1;
|
2004-01-27 16:28:39 +00:00
|
|
|
else if (event.kbd.keycode == 'd')
|
|
|
|
_debugger->attach();
|
2003-09-24 06:33:59 +00:00
|
|
|
}
|
|
|
|
// Make sure backspace works right (this fixes a small issue on OS X)
|
|
|
|
if (event.kbd.keycode == 8)
|
2005-05-06 11:37:33 +00:00
|
|
|
_keyPressed = 8;
|
2003-09-24 06:33:59 +00:00
|
|
|
else
|
2005-05-06 11:37:33 +00:00
|
|
|
_keyPressed = (byte)event.kbd.ascii;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
2005-05-06 11:37:33 +00:00
|
|
|
_sdlMouseX = event.mouse.x;
|
|
|
|
_sdlMouseY = event.mouse.y;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2005-05-06 11:37:33 +00:00
|
|
|
_leftButtonDown++;
|
2003-11-28 10:11:56 +00:00
|
|
|
#if defined (_WIN32_WCE) || defined(__PALM_OS__)
|
2005-05-06 11:37:33 +00:00
|
|
|
_sdlMouseX = event.mouse.x;
|
|
|
|
_sdlMouseY = event.mouse.y;
|
2002-07-18 22:51:29 +00:00
|
|
|
#endif
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
|
|
|
if (_game & GF_SIMON2)
|
2005-05-06 11:37:33 +00:00
|
|
|
_skipSpeech = true;
|
2003-09-24 06:33:59 +00:00
|
|
|
else
|
2005-05-06 11:37:33 +00:00
|
|
|
_exitCutscene = true;
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
shutdown();
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-23 00:11:27 +00:00
|
|
|
if (amount == 0)
|
2002-07-07 19:06:48 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 12:43:02 +00:00
|
|
|
{
|
2005-05-06 11:37:33 +00:00
|
|
|
this_delay = _fastMode ? 1 : 20 * _speed;
|
2002-10-23 00:11:27 +00:00
|
|
|
if (this_delay > amount)
|
|
|
|
this_delay = amount;
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(this_delay);
|
2002-04-13 12:43:02 +00:00
|
|
|
}
|
2004-09-28 20:19:37 +00:00
|
|
|
cur = _system->getMillis();
|
2002-10-23 00:11:27 +00:00
|
|
|
} while (cur < start + amount);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::loadMusic (uint music) {
|
2005-05-06 03:09:53 +00:00
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
if (_game & GF_AMIGA) {
|
|
|
|
if (_game != GAME_SIMON1CD32) {
|
|
|
|
// TODO Add support for decruncher
|
|
|
|
debug(5,"loadMusic - Decrunch %dtune attempt", music);
|
|
|
|
}
|
|
|
|
// TODO Add Protracker support for simon1amiga/cd32
|
|
|
|
debug(5,"playMusic - Load %dtune attempt", music);
|
|
|
|
} else if (_game & GF_SIMON2) { // Simon 2 music
|
2003-05-19 01:36:04 +00:00
|
|
|
midi.stop();
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(_gameOffsetsPtr[MUSIC_INDEX_BASE + music - 1], SEEK_SET);
|
|
|
|
_gameFile->read(buf, 4);
|
2005-05-06 03:09:53 +00:00
|
|
|
if (!memcmp(buf, "FORM", 4)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(_gameOffsetsPtr[MUSIC_INDEX_BASE + music - 1], SEEK_SET);
|
|
|
|
midi.loadXMIDI (_gameFile);
|
2005-05-06 03:09:53 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(_gameOffsetsPtr[MUSIC_INDEX_BASE + music - 1], SEEK_SET);
|
|
|
|
midi.loadMultipleSMF (_gameFile);
|
2003-05-20 07:26:19 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_lastMusicPlayed = music;
|
|
|
|
_nextMusicToPlay = -1;
|
2005-05-06 03:09:53 +00:00
|
|
|
} else if (_game & GF_SIMON1) { // Simon 1 music
|
|
|
|
midi.stop();
|
|
|
|
midi.setLoop (true); // Must do this BEFORE loading music. (GMF may have its own override.)
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
if (_game & GF_TALKIE) {
|
2005-05-06 03:09:53 +00:00
|
|
|
// FIXME: The very last music resource, a cymbal crash for when the
|
2005-07-30 21:11:48 +00:00
|
|
|
// two demons crash into each other, should NOT be looped like the
|
|
|
|
// other music tracks. In simon1dos/talkie the GMF resource includes
|
|
|
|
// a loop override that acomplishes this, but there seems to be nothing
|
2005-05-06 03:09:53 +00:00
|
|
|
// for this in the SMF resources.
|
|
|
|
if (music == 35)
|
|
|
|
midi.setLoop (false);
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(_gameOffsetsPtr[MUSIC_INDEX_BASE + music], SEEK_SET);
|
|
|
|
_gameFile->read(buf, 4);
|
2005-05-06 03:09:53 +00:00
|
|
|
if (!memcmp(buf, "GMF\x1", 4)) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(_gameOffsetsPtr[MUSIC_INDEX_BASE + music], SEEK_SET);
|
|
|
|
midi.loadSMF (_gameFile, music);
|
2003-05-01 07:55:55 +00:00
|
|
|
} else {
|
2005-05-06 11:37:33 +00:00
|
|
|
_gameFile->seek(_gameOffsetsPtr[MUSIC_INDEX_BASE + music], SEEK_SET);
|
|
|
|
midi.loadMultipleSMF (_gameFile);
|
2002-10-31 01:27:05 +00:00
|
|
|
}
|
2003-05-21 06:13:47 +00:00
|
|
|
|
2005-05-06 03:09:53 +00:00
|
|
|
} else {
|
|
|
|
char filename[15];
|
|
|
|
File f;
|
|
|
|
sprintf(filename, "MOD%d.MUS", music);
|
|
|
|
f.open(filename);
|
|
|
|
if (f.isOpen() == false) {
|
|
|
|
warning("Can't load music from '%s'", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_game & GF_DEMO)
|
|
|
|
midi.loadS1D (&f);
|
|
|
|
else
|
|
|
|
midi.loadSMF (&f, music);
|
2002-10-29 14:33:59 +00:00
|
|
|
}
|
2005-05-06 03:09:53 +00:00
|
|
|
|
|
|
|
midi.startTrack (0);
|
2002-10-24 07:14:28 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte *SimonEngine::dx_lock_2() {
|
2005-10-07 07:36:09 +00:00
|
|
|
_dxSurfacePitch = _screenWidth;
|
2002-08-18 16:21:34 +00:00
|
|
|
return _sdl_buf;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_unlock_2() {
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte *SimonEngine::dx_lock_attached() {
|
2005-10-07 07:36:09 +00:00
|
|
|
_dxSurfacePitch = _screenWidth;
|
2005-05-06 11:37:33 +00:00
|
|
|
return _dxUse3Or4ForLock ? _sdl_buf_3 : _sdl_buf_attached;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
void SimonEngine::dx_unlock_attached() {
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 02:01:22 +00:00
|
|
|
void SimonEngine::set_volume(int volume) {
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, volume);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 09:41:56 +00:00
|
|
|
byte SimonEngine::getByte() {
|
2005-05-06 11:37:33 +00:00
|
|
|
return *_codePtr++;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2003-10-03 19:42:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Simon
|
2003-11-12 16:00:11 +00:00
|
|
|
|
|
|
|
#ifdef __PALM_OS__
|
|
|
|
#include "scumm_globals.h"
|
|
|
|
|
|
|
|
_GINIT(Simon_Simon)
|
|
|
|
_GSETPTR(Simon::simon1_settings, GBVARS_SIMON1SETTINGS_INDEX, Simon::GameSpecificSettings, GBVARS_SIMON)
|
|
|
|
_GSETPTR(Simon::simon1acorn_settings, GBVARS_SIMON1ACORNSETTINGS_INDEX, Simon::GameSpecificSettings, GBVARS_SIMON)
|
|
|
|
_GSETPTR(Simon::simon1amiga_settings, GBVARS_SIMON1AMIGASETTINGS_INDEX, Simon::GameSpecificSettings, GBVARS_SIMON)
|
|
|
|
_GSETPTR(Simon::simon1demo_settings, GBVARS_SIMON1DEMOSETTINGS_INDEX, Simon::GameSpecificSettings, GBVARS_SIMON)
|
|
|
|
_GSETPTR(Simon::simon2win_settings, GBVARS_SIMON2WINSETTINGS_INDEX, Simon::GameSpecificSettings, GBVARS_SIMON)
|
|
|
|
_GSETPTR(Simon::simon2dos_settings, GBVARS_SIMON2DOSSETTINGS_INDEX, Simon::GameSpecificSettings, GBVARS_SIMON)
|
|
|
|
_GEND
|
|
|
|
|
|
|
|
_GRELEASE(Simon_Simon)
|
|
|
|
_GRELEASEPTR(GBVARS_SIMON1SETTINGS_INDEX, GBVARS_SIMON)
|
|
|
|
_GRELEASEPTR(GBVARS_SIMON1ACORNSETTINGS_INDEX, GBVARS_SIMON)
|
|
|
|
_GRELEASEPTR(GBVARS_SIMON1AMIGASETTINGS_INDEX, GBVARS_SIMON)
|
|
|
|
_GRELEASEPTR(GBVARS_SIMON1DEMOSETTINGS_INDEX, GBVARS_SIMON)
|
|
|
|
_GRELEASEPTR(GBVARS_SIMON2WINSETTINGS_INDEX, GBVARS_SIMON)
|
|
|
|
_GRELEASEPTR(GBVARS_SIMON2DOSSETTINGS_INDEX, GBVARS_SIMON)
|
|
|
|
_GEND
|
|
|
|
|
|
|
|
#endif
|