aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/console.cpp105
-rw-r--r--engines/sci/console.h4
-rw-r--r--engines/sci/debug.h6
-rw-r--r--engines/sci/detection.cpp28
-rw-r--r--engines/sci/detection_tables.h346
-rw-r--r--engines/sci/engine/features.cpp17
-rw-r--r--engines/sci/engine/gc.cpp13
-rw-r--r--engines/sci/engine/kernel.cpp8
-rw-r--r--engines/sci/engine/kernel.h12
-rw-r--r--engines/sci/engine/kernel_tables.h142
-rw-r--r--engines/sci/engine/kevent.cpp33
-rw-r--r--engines/sci/engine/kfile.cpp411
-rw-r--r--engines/sci/engine/kgraphics.cpp374
-rw-r--r--engines/sci/engine/klists.cpp3
-rw-r--r--engines/sci/engine/kmath.cpp66
-rw-r--r--engines/sci/engine/kmenu.cpp12
-rw-r--r--engines/sci/engine/kmisc.cpp16
-rw-r--r--engines/sci/engine/kmovement.cpp495
-rw-r--r--engines/sci/engine/kparse.cpp24
-rw-r--r--engines/sci/engine/kpathing.cpp64
-rw-r--r--engines/sci/engine/kscripts.cpp74
-rw-r--r--engines/sci/engine/kstring.cpp32
-rw-r--r--engines/sci/engine/kvideo.cpp2
-rw-r--r--engines/sci/engine/savegame.cpp58
-rw-r--r--engines/sci/engine/savegame.h2
-rw-r--r--engines/sci/engine/script.cpp29
-rw-r--r--engines/sci/engine/script.h23
-rw-r--r--engines/sci/engine/script_patches.cpp606
-rw-r--r--engines/sci/engine/seg_manager.cpp22
-rw-r--r--engines/sci/engine/segment.h9
-rw-r--r--engines/sci/engine/selector.cpp6
-rw-r--r--engines/sci/engine/selector.h7
-rw-r--r--engines/sci/engine/state.cpp12
-rw-r--r--engines/sci/engine/state.h28
-rw-r--r--engines/sci/engine/static_selectors.cpp128
-rw-r--r--engines/sci/engine/vm.cpp148
-rw-r--r--engines/sci/engine/workarounds.cpp72
-rw-r--r--engines/sci/engine/workarounds.h3
-rw-r--r--engines/sci/event.cpp19
-rw-r--r--engines/sci/graphics/animate.cpp123
-rw-r--r--engines/sci/graphics/animate.h6
-rw-r--r--engines/sci/graphics/compare.cpp26
-rw-r--r--engines/sci/graphics/controls.cpp46
-rw-r--r--engines/sci/graphics/cursor.cpp133
-rw-r--r--engines/sci/graphics/cursor.h23
-rw-r--r--engines/sci/graphics/frameout.cpp131
-rw-r--r--engines/sci/graphics/frameout.h9
-rw-r--r--engines/sci/graphics/menu.cpp2
-rw-r--r--engines/sci/graphics/paint16.cpp8
-rw-r--r--engines/sci/graphics/palette.cpp25
-rw-r--r--engines/sci/graphics/picture.cpp17
-rw-r--r--engines/sci/graphics/portrait.cpp2
-rw-r--r--engines/sci/graphics/ports.cpp29
-rw-r--r--engines/sci/graphics/robot.cpp169
-rw-r--r--engines/sci/graphics/robot.h1
-rw-r--r--engines/sci/graphics/screen.cpp6
-rw-r--r--engines/sci/graphics/text16.cpp79
-rw-r--r--engines/sci/graphics/text16.h10
-rw-r--r--engines/sci/graphics/transitions.cpp144
-rw-r--r--engines/sci/graphics/transitions.h5
-rw-r--r--engines/sci/graphics/view.cpp7
-rw-r--r--engines/sci/module.mk1
-rw-r--r--engines/sci/parser/grammar.cpp88
-rw-r--r--engines/sci/parser/said.cpp40
-rw-r--r--engines/sci/parser/vocabulary.cpp236
-rw-r--r--engines/sci/parser/vocabulary.h53
-rw-r--r--engines/sci/resource.cpp119
-rw-r--r--engines/sci/resource.h5
-rw-r--r--engines/sci/resource_audio.cpp46
-rw-r--r--engines/sci/sci.cpp247
-rw-r--r--engines/sci/sci.h22
-rw-r--r--engines/sci/sound/drivers/adlib.cpp10
-rw-r--r--engines/sci/sound/drivers/amigamac.cpp4
-rw-r--r--engines/sci/sound/drivers/cms.cpp817
-rw-r--r--engines/sci/sound/drivers/fb01.cpp4
-rw-r--r--engines/sci/sound/drivers/map-mt32-to-gm.h170
-rw-r--r--engines/sci/sound/drivers/midi.cpp58
-rw-r--r--engines/sci/sound/drivers/mididriver.h25
-rw-r--r--engines/sci/sound/drivers/pcjr.cpp8
-rw-r--r--engines/sci/sound/midiparser_sci.cpp43
-rw-r--r--engines/sci/sound/midiparser_sci.h4
-rw-r--r--engines/sci/sound/music.cpp100
-rw-r--r--engines/sci/sound/music.h7
-rw-r--r--engines/sci/sound/soundcmd.cpp21
-rw-r--r--engines/sci/sound/soundcmd.h7
85 files changed, 4912 insertions, 1683 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 7acbe56a12..79f63fded4 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -98,7 +98,7 @@ Console::Console(SciEngine *engine) : GUI::Debugger(),
DCmd_Register("diskdump", WRAP_METHOD(Console, cmdDiskDump));
DCmd_Register("hexdump", WRAP_METHOD(Console, cmdHexDump));
DCmd_Register("resource_id", WRAP_METHOD(Console, cmdResourceId));
- DCmd_Register("resource_size", WRAP_METHOD(Console, cmdResourceSize));
+ DCmd_Register("resource_info", WRAP_METHOD(Console, cmdResourceInfo));
DCmd_Register("resource_types", WRAP_METHOD(Console, cmdResourceTypes));
DCmd_Register("list", WRAP_METHOD(Console, cmdList));
DCmd_Register("hexgrep", WRAP_METHOD(Console, cmdHexgrep));
@@ -178,6 +178,10 @@ Console::Console(SciEngine *engine) : GUI::Debugger(),
DCmd_Register("bc", WRAP_METHOD(Console, cmdBreakpointDelete)); // alias
DCmd_Register("bp_method", WRAP_METHOD(Console, cmdBreakpointMethod));
DCmd_Register("bpx", WRAP_METHOD(Console, cmdBreakpointMethod)); // alias
+ DCmd_Register("bp_read", WRAP_METHOD(Console, cmdBreakpointRead));
+ DCmd_Register("bpr", WRAP_METHOD(Console, cmdBreakpointRead)); // alias
+ DCmd_Register("bp_write", WRAP_METHOD(Console, cmdBreakpointWrite));
+ DCmd_Register("bpw", WRAP_METHOD(Console, cmdBreakpointWrite)); // alias
DCmd_Register("bp_kernel", WRAP_METHOD(Console, cmdBreakpointKernel));
DCmd_Register("bpk", WRAP_METHOD(Console, cmdBreakpointKernel)); // alias
DCmd_Register("bp_function", WRAP_METHOD(Console, cmdBreakpointFunction));
@@ -323,7 +327,7 @@ bool Console::cmdHelp(int argc, const char **argv) {
DebugPrintf(" diskdump - Dumps the specified resource to disk as a patch file\n");
DebugPrintf(" hexdump - Dumps the specified resource to standard output\n");
DebugPrintf(" resource_id - Identifies a resource number by splitting it up in resource type and resource number\n");
- DebugPrintf(" resource_size - Shows the size of a resource\n");
+ DebugPrintf(" resource_info - Shows info about a resource\n");
DebugPrintf(" resource_types - Shows the valid resource types\n");
DebugPrintf(" list - Lists all the resources of a given type\n");
DebugPrintf(" hexgrep - Searches some resources for a particular sequence of bytes, represented as hexadecimal numbers\n");
@@ -389,7 +393,9 @@ bool Console::cmdHelp(int argc, const char **argv) {
DebugPrintf("Breakpoints:\n");
DebugPrintf(" bp_list / bplist / bl - Lists the current breakpoints\n");
DebugPrintf(" bp_del / bpdel / bc - Deletes a breakpoint with the specified index\n");
- DebugPrintf(" bp_method / bpx - Sets a breakpoint on the execution or access of a specified method/selector\n");
+ DebugPrintf(" bp_method / bpx - Sets a breakpoint on the execution of a specified method/selector\n");
+ DebugPrintf(" bp_read / bpr - Sets a breakpoint on reading of a specified selector\n");
+ DebugPrintf(" bp_write / bpw - Sets a breakpoint on writing to a specified selector\n");
DebugPrintf(" bp_kernel / bpk - Sets a breakpoint on execution of a kernel function\n");
DebugPrintf(" bp_function / bpe - Sets a breakpoint on the execution of the specified exported function\n");
DebugPrintf("\n");
@@ -641,7 +647,7 @@ bool Console::cmdDiskDump(int argc, const char **argv) {
outFile->finalize();
outFile->close();
delete outFile;
- DebugPrintf("Resource %s.%03d has been dumped to disk\n", argv[1], resNum);
+ DebugPrintf("Resource %s.%03d (located in %s) has been dumped to disk\n", argv[1], resNum, resource->getResourceLocation().c_str());
} else {
DebugPrintf("Resource %s.%03d not found\n", argv[1], resNum);
}
@@ -718,9 +724,9 @@ bool Console::cmdRoomNumber(int argc, const char **argv) {
return true;
}
-bool Console::cmdResourceSize(int argc, const char **argv) {
+bool Console::cmdResourceInfo(int argc, const char **argv) {
if (argc != 3) {
- DebugPrintf("Shows the size of a resource\n");
+ DebugPrintf("Shows information about a resource\n");
DebugPrintf("Usage: %s <resource type> <resource number>\n", argv[0]);
return true;
}
@@ -734,6 +740,7 @@ bool Console::cmdResourceSize(int argc, const char **argv) {
Resource *resource = _engine->getResMan()->findResource(ResourceId(res, resNum), 0);
if (resource) {
DebugPrintf("Resource size: %d\n", resource->size);
+ DebugPrintf("Resource location: %s\n", resource->getResourceLocation().c_str());
} else {
DebugPrintf("Resource %s.%03d not found\n", argv[1], resNum);
}
@@ -1095,7 +1102,7 @@ bool Console::cmdSaveGame(int argc, const char **argv) {
} else {
out->finalize();
if (out->err()) {
- warning("Writing the savegame failed.");
+ warning("Writing the savegame failed");
}
delete out;
}
@@ -1127,7 +1134,7 @@ bool Console::cmdRestoreGame(int argc, const char **argv) {
}
bool Console::cmdRestartGame(int argc, const char **argv) {
- _engine->_gamestate->abortScriptProcessing = kAbortRestartGame;;
+ _engine->_gamestate->abortScriptProcessing = kAbortRestartGame;
return Cmd_Exit(0, 0);
}
@@ -1135,10 +1142,12 @@ bool Console::cmdRestartGame(int argc, const char **argv) {
bool Console::cmdClassTable(int argc, const char **argv) {
DebugPrintf("Available classes:\n");
for (uint i = 0; i < _engine->_gamestate->_segMan->classTableSize(); i++) {
- if (_engine->_gamestate->_segMan->_classTable[i].reg.segment) {
- DebugPrintf(" Class 0x%x at %04x:%04x (script 0x%x)\n", i,
- PRINT_REG(_engine->_gamestate->_segMan->_classTable[i].reg),
- _engine->_gamestate->_segMan->_classTable[i].script);
+ Class temp = _engine->_gamestate->_segMan->_classTable[i];
+ if (temp.reg.segment) {
+ DebugPrintf(" Class 0x%x (%s) at %04x:%04x (script 0x%x)\n", i,
+ _engine->_gamestate->_segMan->getObjectName(temp.reg),
+ PRINT_REG(temp.reg),
+ temp.script);
}
}
@@ -1195,7 +1204,6 @@ bool Console::cmdParse(int argc, const char **argv) {
return true;
}
- ResultWordList words;
char *error;
char string[1000];
@@ -1207,6 +1215,8 @@ bool Console::cmdParse(int argc, const char **argv) {
}
DebugPrintf("Parsing '%s'\n", string);
+
+ ResultWordListList words;
bool res = _engine->getVocabulary()->tokenizeString(words, string, &error);
if (res && !words.empty()) {
int syntax_fail = 0;
@@ -1215,8 +1225,13 @@ bool Console::cmdParse(int argc, const char **argv) {
DebugPrintf("Parsed to the following blocks:\n");
- for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
- DebugPrintf(" Type[%04x] Group[%04x]\n", i->_class, i->_group);
+ for (ResultWordListList::const_iterator i = words.begin(); i != words.end(); ++i) {
+ DebugPrintf(" ");
+ for (ResultWordList::const_iterator j = i->begin(); j != i->end(); ++j) {
+ DebugPrintf("%sType[%04x] Group[%04x]", j == i->begin() ? "" : " / ", j->_class, j->_group);
+ }
+ DebugPrintf("\n");
+ }
if (_engine->getVocabulary()->parseGNF(words, true))
syntax_fail = 1; // Building a tree failed
@@ -1243,7 +1258,6 @@ bool Console::cmdSaid(int argc, const char **argv) {
return true;
}
- ResultWordList words;
char *error;
char string[1000];
byte spec[1000];
@@ -1317,6 +1331,7 @@ bool Console::cmdSaid(int argc, const char **argv) {
_engine->getVocabulary()->debugDecipherSaidBlock(spec);
printf("\n");
+ ResultWordListList words;
bool res = _engine->getVocabulary()->tokenizeString(words, string, &error);
if (res && !words.empty()) {
int syntax_fail = 0;
@@ -1325,8 +1340,15 @@ bool Console::cmdSaid(int argc, const char **argv) {
DebugPrintf("Parsed to the following blocks:\n");
- for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
- DebugPrintf(" Type[%04x] Group[%04x]\n", i->_class, i->_group);
+ for (ResultWordListList::const_iterator i = words.begin(); i != words.end(); ++i) {
+ DebugPrintf(" ");
+ for (ResultWordList::const_iterator j = i->begin(); j != i->end(); ++j) {
+ DebugPrintf("%sType[%04x] Group[%04x]", j == i->begin() ? "" : " / ", j->_class, j->_group);
+ }
+ DebugPrintf("\n");
+ }
+
+
if (_engine->getVocabulary()->parseGNF(words, true))
syntax_fail = 1; // Building a tree failed
@@ -2741,9 +2763,15 @@ bool Console::cmdBreakpointList(int argc, const char **argv) {
for (; bp != end; ++bp) {
DebugPrintf(" #%i: ", i);
switch (bp->type) {
- case BREAK_SELECTOR:
+ case BREAK_SELECTOREXEC:
DebugPrintf("Execute %s\n", bp->name.c_str());
break;
+ case BREAK_SELECTORREAD:
+ DebugPrintf("Read %s\n", bp->name.c_str());
+ break;
+ case BREAK_SELECTORWRITE:
+ DebugPrintf("Write %s\n", bp->name.c_str());
+ break;
case BREAK_EXPORT:
bpdata = bp->address;
DebugPrintf("Execute script %d, export %d\n", bpdata >> 16, bpdata & 0xFFFF);
@@ -2803,7 +2831,7 @@ bool Console::cmdBreakpointDelete(int argc, const char **argv) {
bool Console::cmdBreakpointMethod(int argc, const char **argv) {
if (argc != 2) {
- DebugPrintf("Sets a breakpoint on execution/access of a specified method/selector.\n");
+ DebugPrintf("Sets a breakpoint on execution of a specified method/selector.\n");
DebugPrintf("Usage: %s <name>\n", argv[0]);
DebugPrintf("Example: %s ego::doit\n", argv[0]);
DebugPrintf("May also be used to set a breakpoint that applies whenever an object\n");
@@ -2815,12 +2843,45 @@ bool Console::cmdBreakpointMethod(int argc, const char **argv) {
Thus, we can't check whether the command argument is a valid method name.
A breakpoint set on an invalid method name will just never trigger. */
Breakpoint bp;
- bp.type = BREAK_SELECTOR;
+ bp.type = BREAK_SELECTOREXEC;
+ bp.name = argv[1];
+
+ _debugState._breakpoints.push_back(bp);
+ _debugState._activeBreakpointTypes |= BREAK_SELECTOREXEC;
+ return true;
+}
+
+bool Console::cmdBreakpointRead(int argc, const char **argv) {
+ if (argc != 2) {
+ DebugPrintf("Sets a breakpoint on reading of a specified selector.\n");
+ DebugPrintf("Usage: %s <name>\n", argv[0]);
+ DebugPrintf("Example: %s ego::view\n", argv[0]);
+ return true;
+ }
+
+ Breakpoint bp;
+ bp.type = BREAK_SELECTORREAD;
bp.name = argv[1];
_debugState._breakpoints.push_back(bp);
- _debugState._activeBreakpointTypes |= BREAK_SELECTOR;
+ _debugState._activeBreakpointTypes |= BREAK_SELECTORREAD;
+ return true;
+}
+bool Console::cmdBreakpointWrite(int argc, const char **argv) {
+ if (argc != 2) {
+ DebugPrintf("Sets a breakpoint on writing of a specified selector.\n");
+ DebugPrintf("Usage: %s <name>\n", argv[0]);
+ DebugPrintf("Example: %s ego::view\n", argv[0]);
+ return true;
+ }
+
+ Breakpoint bp;
+ bp.type = BREAK_SELECTORWRITE;
+ bp.name = argv[1];
+
+ _debugState._breakpoints.push_back(bp);
+ _debugState._activeBreakpointTypes |= BREAK_SELECTORWRITE;
return true;
}
diff --git a/engines/sci/console.h b/engines/sci/console.h
index 60599ea783..8bc2da439c 100644
--- a/engines/sci/console.h
+++ b/engines/sci/console.h
@@ -70,7 +70,7 @@ private:
bool cmdDiskDump(int argc, const char **argv);
bool cmdHexDump(int argc, const char **argv);
bool cmdResourceId(int argc, const char **argv);
- bool cmdResourceSize(int argc, const char **argv);
+ bool cmdResourceInfo(int argc, const char **argv);
bool cmdResourceTypes(int argc, const char **argv);
bool cmdList(int argc, const char **argv);
bool cmdHexgrep(int argc, const char **argv);
@@ -135,6 +135,8 @@ private:
bool cmdBreakpointList(int argc, const char **argv);
bool cmdBreakpointDelete(int argc, const char **argv);
bool cmdBreakpointMethod(int argc, const char **argv);
+ bool cmdBreakpointRead(int argc, const char **argv);
+ bool cmdBreakpointWrite(int argc, const char **argv);
bool cmdBreakpointKernel(int argc, const char **argv);
bool cmdBreakpointFunction(int argc, const char **argv);
// VM
diff --git a/engines/sci/debug.h b/engines/sci/debug.h
index 5cf0e38fbc..d9959f0b7f 100644
--- a/engines/sci/debug.h
+++ b/engines/sci/debug.h
@@ -37,13 +37,15 @@ enum BreakpointType {
* Break when selector is executed. data contains (char *) selector name
* (in the format Object::Method)
*/
- BREAK_SELECTOR = 1,
+ BREAK_SELECTOREXEC = 1 << 0, // break when selector gets executed
+ BREAK_SELECTORREAD = 1 << 1, // break when selector gets executed
+ BREAK_SELECTORWRITE = 1 << 2, // break when selector gets executed
/**
* Break when an exported function is called. data contains
* script_no << 16 | export_no.
*/
- BREAK_EXPORT = 2
+ BREAK_EXPORT = 1 << 3
};
struct Breakpoint {
diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp
index e330bd5f30..a4d1edf2ed 100644
--- a/engines/sci/detection.cpp
+++ b/engines/sci/detection.cpp
@@ -55,6 +55,7 @@ static const PlainGameDescriptor s_sciGameTitles[] = {
{"laurabow", "Laura Bow: The Colonel's Bequest"},
{"lsl2", "Leisure Suit Larry 2: Goes Looking for Love (in Several Wrong Places)"},
{"lsl3", "Leisure Suit Larry 3: Passionate Patti in Pursuit of the Pulsating Pectorals"},
+ {"mothergoose", "Mixed-Up Mother Goose"},
{"pq2", "Police Quest II: The Vengeance"},
{"qfg1", "Quest for Glory I: So You Want to Be a Hero"},
{"sq3", "Space Quest III: The Pirates of Pestulon"},
@@ -77,6 +78,7 @@ static const PlainGameDescriptor s_sciGameTitles[] = {
{"longbow", "Conquests of the Longbow: The Adventures of Robin Hood"},
{"lsl1sci", "Leisure Suit Larry in the Land of the Lounge Lizards"},
{"lsl5", "Leisure Suit Larry 5: Passionate Patti Does a Little Undercover Work"},
+ {"mothergoose256", "Mixed-Up Mother Goose"},
{"msastrochicken", "Ms. Astro Chicken"},
{"pq1sci", "Police Quest: In Pursuit of the Death Angel"},
{"pq3", "Police Quest III: The Kindred"},
@@ -94,7 +96,6 @@ static const PlainGameDescriptor s_sciGameTitles[] = {
{"sq5", "Space Quest V: The Next Mutation"},
{"islandbrain", "The Island of Dr. Brain"},
{"lsl6", "Leisure Suit Larry 6: Shape Up or Slip Out!"},
- {"mothergoose", "Mixed-Up Mother Goose"},
{"pepper", "Pepper's Adventure in Time"},
{"slater", "Slater & Charlie Go Camping"},
// === SCI2 games =========================================================
@@ -170,6 +171,7 @@ static const GameIdStrToEnum s_gameIdStrToEnum[] = {
{ "lsl6hires", GID_LSL6HIRES },
{ "lsl7", GID_LSL7 },
{ "mothergoose", GID_MOTHERGOOSE },
+ { "mothergoose256", GID_MOTHERGOOSE256 },
{ "mothergoosehires",GID_MOTHERGOOSEHIRES },
{ "msastrochicken", GID_MSASTROCHICKEN },
{ "pepper", GID_PEPPER },
@@ -514,6 +516,15 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl
resMan->init();
// TODO: Add error handling.
+#ifndef ENABLE_SCI32
+ // Is SCI32 compiled in? If not, and this is a SCI32 game,
+ // stop here
+ if (getSciVersion() >= SCI_VERSION_2) {
+ delete resMan;
+ return (const ADGameDescription *)&s_fallbackDesc;
+ }
+#endif
+
ViewType gameViews = resMan->getViewType();
// Have we identified the game views? If not, stop here
@@ -524,15 +535,6 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl
return 0;
}
-#ifndef ENABLE_SCI32
- // Is SCI32 compiled in? If not, and this is a SCI32 game,
- // stop here
- if (getSciVersion() >= SCI_VERSION_2) {
- delete resMan;
- return (const ADGameDescription *)&s_fallbackDesc;
- }
-#endif
-
// EGA views
if (gameViews == kViewEga && s_fallbackDesc.platform != Common::kPlatformAmiga)
s_fallbackDesc.extra = "EGA";
@@ -654,7 +656,7 @@ SaveStateList SciMetaEngine::listSaves(const char *target) const {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
slotNum = atoi(file->c_str() + file->size() - 3);
- if (slotNum >= 0 && slotNum < 999) {
+ if (slotNum >= 0 && slotNum <= 99) {
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
if (in) {
SavegameMetadata meta;
@@ -721,7 +723,7 @@ SaveStateDescriptor SciMetaEngine::querySaveMetaInfos(const char *target, int sl
return SaveStateDescriptor();
}
-int SciMetaEngine::getMaximumSaveSlot() const { return 999; }
+int SciMetaEngine::getMaximumSaveSlot() const { return 99; }
void SciMetaEngine::removeSaveState(const char *target, int slot) const {
Common::String fileName = Common::String::printf("%s.%03d", target, slot);
@@ -763,7 +765,7 @@ Common::Error SciEngine::saveGameState(int slot, const char *desc) {
} else {
out->finalize();
if (out->err()) {
- warning("Writing the savegame failed.");
+ warning("Writing the savegame failed");
return Common::kWritingFailed;
}
delete out;
diff --git a/engines/sci/detection_tables.h b/engines/sci/detection_tables.h
index a74c34f517..e1d03d9914 100644
--- a/engines/sci/detection_tables.h
+++ b/engines/sci/detection_tables.h
@@ -219,6 +219,21 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Codename: Iceman - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.022 9x5.25" (label: Int#0.000.668)
+ {"iceman", "", {
+ {"resource.map", 0, "2948e06dab4930e4c8098c24ac874db8", 6252},
+ {"resource.000", 0, "b1bccd827453d4cb834bfd5b45bef63c", 26974},
+ {"resource.001", 0, "005bd332d4b0f9d8e99d3b905223a332", 126839},
+ {"resource.002", 0, "250b859381ebf2bf8922bd99683b0cc1", 307001},
+ {"resource.003", 0, "7d7a840701d2f6eff57679bf7dced747", 318060},
+ {"resource.004", 0, "e0e72970bad9a956db13dcb63d898437", 322457},
+ {"resource.005", 0, "1f2f79e399098859c73e49ac6a3545d8", 330657},
+ {"resource.006", 0, "08050329aa113a9f14ed99cbfe3536ec", 232942},
+ {"resource.007", 0, "64f342463f6f35ba71b3509ef696ae3f", 267811},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Codename: Iceman - English DOS 1.023 (from abevi, bug report #2612718)
{"iceman", "", {
{"resource.map", 0, "da131654de1d6f640222c092313c6ca5", 6252},
@@ -351,6 +366,16 @@ static const struct ADGameDescription SciGameDescriptions[] = {
{"resource.006", 0, "8c767b3939add63d11274065e46aad04", 713158},
AD_LISTEND}, Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Conquests of the Longbow DOS 1.0 EGA (4 x 5.25" disks)
+ // Provided by ssburnout in bug report #3046802
+ {"longbow", "EGA", {
+ {"resource.map", 0, "0517ca368ec844df0cb21a05020fae01", 6021},
+ {"resource.000", 0, "36e8fda5d0b8c49e587c8a9617959f72", 934643},
+ {"resource.001", 0, "76c729e563809170e6cc8b2f3f6cf0a4", 1196133},
+ {"resource.002", 0, "8c767b3939add63d11274065e46aad04", 1152478},
+ {"resource.003", 0, "7025b87e735b1df3f0e9488a621f4333", 1171439},
+ AD_LISTEND}, Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Conquests of the Longbow - English DOS Non-Interactive Demo
// SCI interpreter version 1.000.510
{"longbow", "Demo", {
@@ -699,6 +724,16 @@ static const struct ADGameDescription SciGameDescriptions[] = {
#endif // ENABLE_SCI32
+ // Hoyle 1 - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.000.104 3x5.25" (label:INT.0.000.519)
+ {"hoyle1", "", {
+ {"resource.map", 0, "d6c37503a8f282636e1b08f7a6cf4afd", 7818},
+ {"resource.001", 0, "e0dd44069a62a463fd124974b915f10d", 162805},
+ {"resource.002", 0, "e0dd44069a62a463fd124974b915f10d", 342149},
+ {"resource.003", 0, "e0dd44069a62a463fd124974b915f10d", 328925},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Hoyle 1 - English DOS (supplied by wibble92 in bug report #2644547)
// SCI interpreter version 0.000.530
{"hoyle1", "", {
@@ -717,6 +752,13 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Hoyle 1 - English DOS (supplied by eddydrama in bug report #3052366)
+ {"hoyle1", "", {
+ {"resource.map", 0, "0af9a3dcd72a091960de070432e1f524", 4386},
+ {"resource.001", 0, "e0dd44069a62463fd124974b915f10d", 518127},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
#if 0 // TODO: unknown if these files are corrupt
// Hoyle 1 - English Amiga (from www.back2roots.org)
// SCI interpreter version 0.000.519 - FIXME: some have 0.000.530, others x.yyy.zzz
@@ -737,6 +779,14 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Hoyle 2 - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.000.011 1x3.5" (label:Int#6.21.90)
+ {"hoyle2", "", {
+ {"resource.map", 0, "db0ba08b953e9904a4960ad99cd29c20", 1356},
+ {"resource.001", 0, "8f2dd70abe01112eca464cda818b5eb6", 216315},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Hoyle 2 - English Amiga (from www.back2roots.org)
// Executable scanning reports "1.002.032"
// SCI interpreter version 0.000.685
@@ -785,8 +835,19 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
- // Hoyle 3 - English DOS Floppy 1.0 (supplied by abevi in bug report #2612718)
+ // Hoyle 3 - English DOS Floppy (supplied by eddydrama in bug report #3038837)
{"hoyle3", "", {
+ {"resource.map", 0, "31c9fc0977ac6e5b566c37096803d0cb", 2469},
+ {"resource.000", 0, "6ef28cac094dcd97fdb461662ead6f92", 12070},
+ {"resource.001", 0, "ca6a9750a2c138d8bcbba369126040e9", 348646},
+ {"resource.002", 0, "0a98a268ee99b92c233a0d7187c1f0fa", 345811},
+ {"resource.003", 0, "97cfd72633f8f9b2a0b1d4116cf3ee81", 346116},
+ {"resource.004", 0, "2884fb91b225fabd9ca87ea231293b48", 351218},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
+ // Hoyle 3 EGA - English DOS Floppy 1.0 (supplied by abevi in bug report #2612718)
+ {"hoyle3", "EGA", {
{"resource.map", 0, "1728af1f6a85938c3522e64449e76ca1", 2205},
{"resource.000", 0, "6ef28cac094dcd97fdb461662ead6f92", 319905},
{"resource.001", 0, "0a98a268ee99b92c233a0d7187c1f0fa", 526438},
@@ -812,7 +873,7 @@ static const struct ADGameDescription SciGameDescriptions[] = {
// Hoyle 4 (Hoyle Classic Card Games) - English DOS/Win
// SCI1.1
// Supplied by abevi in bug report #3039291
- {"hoyle4", "Demo", {
+ {"hoyle4", "", {
{"resource.map", 0, "2b577c975cc8d8d43f61b6a756129fe3", 4352},
{"resource.000", 0, "43e2c15ce436aab611a462ad0603e12d", 2000132},
AD_LISTEND},
@@ -889,6 +950,20 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // King's Quest 1 SCI Remake - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.000.051 9x5.25" (label: INT#9.19.90)
+ {"kq1sci", "SCI Remake", {
+ {"resource.map", 0, "4dac689e98b2fa6806232fdd61e24712", 9936},
+ {"resource.001", 0, "fed9e0072ffd511d248674e60dee2099", 196027},
+ {"resource.002", 0, "fed9e0072ffd511d248674e60dee2099", 330278},
+ {"resource.003", 0, "fed9e0072ffd511d248674e60dee2099", 355008},
+ {"resource.004", 0, "fed9e0072ffd511d248674e60dee2099", 265478},
+ {"resource.005", 0, "fed9e0072ffd511d248674e60dee2099", 316854},
+ {"resource.006", 0, "fed9e0072ffd511d248674e60dee2099", 351062},
+ {"resource.007", 0, "fed9e0072ffd511d248674e60dee2099", 330472},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// King's Quest 4 - English Amiga (from www.back2roots.org)
// Executable scanning reports "1.002.032"
// SCI interpreter version 0.000.685
@@ -910,6 +985,17 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, ADGF_DEMO, GUIO_NOSPEECH },
+ // King's Quest 4 - English DOS (original boxed release, 3 1/2" disks)
+ // SCI interpreter version 0.000.247
+ {"kq4sci", "", {
+ {"resource.map", 0, "042d54434174d8f9faf926ade2ffd805", 7416},
+ {"resource.001", 0, "851a62d00972dc4002f472cc0d84e71d", 491919},
+ {"resource.002", 0, "851a62d00972dc4002f472cc0d84e71d", 678804},
+ {"resource.003", 0, "851a62d00972dc4002f472cc0d84e71d", 683145},
+ {"resource.004", 0, "851a62d00972dc4002f472cc0d84e71d", 649441},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// King's Quest 4 - English DOS (from the King's Quest Collection)
// Executable scanning reports "0.000.502"
// SCI interpreter version 0.000.502
@@ -922,6 +1008,20 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // King's Quest 4 - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.006.003 8x5.25" (label: Int.#0.000.502)
+ {"kq4sci", "", {
+ {"resource.map", 0, "a22b66e6fa0d82460b985e9f7e562950", 9384},
+ {"resource.001", 0, "6db7de6f93c6ea62dca78abee677f8c0", 174852},
+ {"resource.002", 0, "6db7de6f93c6ea62dca78abee677f8c0", 356024},
+ {"resource.003", 0, "6db7de6f93c6ea62dca78abee677f8c0", 335716},
+ {"resource.004", 0, "6db7de6f93c6ea62dca78abee677f8c0", 312231},
+ {"resource.005", 0, "6db7de6f93c6ea62dca78abee677f8c0", 283466},
+ {"resource.006", 0, "6db7de6f93c6ea62dca78abee677f8c0", 324789},
+ {"resource.007", 0, "6db7de6f93c6ea62dca78abee677f8c0", 334441},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// King's Quest 4 - English DOS
// SCI interpreter version 0.000.274
{"kq4sci", "", {
@@ -1054,6 +1154,18 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // King's Quest 5 EGA 1.2M disk version (from LordHoto)
+ // VERSION file reports "0.000.055"
+ {"kq5", "EGA", {
+ {"resource.002", 0, "4d74e8094ff57cea6ee92faf63dbd0af", 1195538},
+ {"resource.003", 0, "3cca5b2dae8afe94532edfdc98d7edbe", 1092132},
+ {"resource.000", 0, "a591bd4b879fc832b8095c0b3befe9e2", 413818},
+ {"resource.001", 0, "c1eef048fa9fe76298c2d4705ef9549f", 1162752},
+ {"resource.map", 0, "53206afb4fd73871a484e83acab80f31", 7608},
+ {"resource.004", 0, "83568edf7fde18b3eed988bc5d22ceb1", 1188053},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// King's Quest 5 EGA (supplied by omer_mor in bug report #3035421)
// VERSION file reports "0.000.062"
{"kq5", "EGA", {
@@ -1069,6 +1181,18 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // King's Quest V DOS 0.000.062 EGA (5 x 5.25" disks)
+ // Supplied by ssburnout in bug report #3046780
+ {"kq5", "EGA", {
+ {"resource.map", 0, "ef4fdc72ca7aef62054e8b075d7960d8", 7596},
+ {"resource.000", 0, "a591bd4b879fc832b8095c0b3befe9e2", 413648},
+ {"resource.001", 0, "c1eef048fa9fe76298c2d4705ef9549f", 1162806},
+ {"resource.002", 0, "4d74e8094ff57cea6ee92faf63dbd0af", 1194799},
+ {"resource.003", 0, "3cca5b2dae8afe94532edfdc98d7edbe", 1092325},
+ {"resource.004", 0, "8e5c1bc4d738cf7316ff506f59d265e2", 1187803},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// King's Quest 5 - German DOS Floppy (supplied by markcoolio in bug report #2727101, also includes english language)
// SCI interpreter version 1.000.060
{"kq5", "", {
@@ -1153,6 +1277,18 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformFMTowns, 0, GUIO_NONE },
+ // King's Quest 5 - Japanese PC-98 Floppy 0.000.015 (supplied by omer_mor in bug report #3073583)
+ {"kq5", "", {
+ {"resource.map", 0, "3bca188108ec5b6ad91612483a6cbc27", 7875},
+ {"resource.000", 0, "70d6a2ec17fd49a63217992fc4347cd9", 493681},
+ {"resource.001", 0, "a504e91327a4d51ee4818eb72026dbe9", 950364},
+ {"resource.002", 0, "0750a84ece1d89d3a952e2a2b90b525c", 911833},
+ {"resource.003", 0, "6f8d552b60ec82a165619a99e19c509d", 1078032},
+ {"resource.004", 0, "e114ce8f884601c43308fb5cbbea4874", 1174129},
+ {"resource.005", 0, "349ad9438172265d00680075c5a988d0", 1019669},
+ AD_LISTEND},
+ Common::JA_JPN, Common::kPlatformPC98, ADGF_ADDENGLISH, GUIO_NOSPEECH },
+
// King's Quest 6 - English DOS Non-Interactive Demo
// Executable scanning reports "1.001.055", VERSION file reports "1.000.000"
// SCI interpreter version 1.001.055
@@ -1536,6 +1672,26 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Larry 2 - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.000.011 3x3.5" (label: Int. #0.000.343)
+ {"lsl2", "", {
+ {"resource.map", 0, "e5caa855a5be78c53a6a92157d0b9f5c", 4740},
+ {"resource.001", 0, "96033f57accfca903750413fd09193c8", 474642},
+ {"resource.002", 0, "96033f57accfca903750413fd09193c8", 407014},
+ {"resource.003", 0, "96033f57accfca903750413fd09193c8", 592834},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
+ // Larry 2 - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.002.000 3x3.5" (label: INT#0.000.409)
+ {"lsl2", "", {
+ {"resource.map", 0, "2c9c3b0923e3764f5ab999bcb71c2d47", 4758},
+ {"resource.001", 0, "4a24443a25e2b1492462a52809605dc2", 477625},
+ {"resource.002", 0, "4a24443a25e2b1492462a52809605dc2", 406935},
+ {"resource.003", 0, "4a24443a25e2b1492462a52809605dc2", 592533},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Larry 3 - English Amiga (from www.back2roots.org)
// Executable scanning reports "1.002.032"
// SCI interpreter version 0.000.685
@@ -1561,6 +1717,20 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Larry 3 - English DOS (supplied by ssburnout in bug report #3049193)
+ // 1.021 8x5.25" (label: Int#5.15.90)
+ {"lsl3", "", {
+ {"resource.map", 0, "a39a20580362af3437352dbc717734f8", 7452},
+ {"resource.001", 0, "f18441027154292836b973c655fa3175", 141515},
+ {"resource.002", 0, "f18441027154292836b973c655fa3175", 345494},
+ {"resource.003", 0, "f18441027154292836b973c655fa3175", 329220},
+ {"resource.004", 0, "f18441027154292836b973c655fa3175", 290303},
+ {"resource.005", 0, "f18441027154292836b973c655fa3175", 303905},
+ {"resource.006", 0, "f18441027154292836b973c655fa3175", 282649},
+ {"resource.007", 0, "f18441027154292836b973c655fa3175", 257178},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Larry 3 - English DOS
// SCI interpreter version 0.000.572
{"lsl3", "", {
@@ -1608,6 +1778,20 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::FR_FRA, Common::kPlatformPC, ADGF_ADDENGLISH, GUIO_NOSPEECH },
+ // Larry 3 1.050 Fr/En (9 x 5.25" disks)
+ // Provided by ssburnout in bug report #3046779
+ {"lsl3", "", {
+ {"resource.map", 0, "527277cee7b31dd603229443b48e70c4", 8910},
+ {"resource.001", 0, "65f1bdaa20f6d0470e9d969f22473873", 162132},
+ {"resource.002", 0, "65f1bdaa20f6d0470e9d969f22473873", 309705},
+ {"resource.003", 0, "65f1bdaa20f6d0470e9d969f22473873", 346507},
+ {"resource.004", 0, "65f1bdaa20f6d0470e9d969f22473873", 331947},
+ {"resource.005", 0, "65f1bdaa20f6d0470e9d969f22473873", 347136},
+ {"resource.006", 0, "65f1bdaa20f6d0470e9d969f22473873", 325292},
+ {"resource.007", 0, "65f1bdaa20f6d0470e9d969f22473873", 308982},
+ AD_LISTEND},
+ Common::FR_FRA, Common::kPlatformPC, ADGF_ADDENGLISH, GUIO_NOSPEECH },
+
// Larry 5 - English Amiga
// Executable scanning reports "1.004.023"
// SCI interpreter version 1.000.784
@@ -1717,6 +1901,32 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::IT_ITA, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Larry 5 1.0 EGA DOS (8 x 3.5" disks)
+ // Provided by ssburnout in bug report #3046806
+ {"lsl5", "EGA", {
+ {"resource.map", 0, "1370ae356fdda2e7f9ea56dda3ff9a57", 6597},
+ {"resource.000", 0, "f2537473213d70e7f4fc82e988ab90ca", 248416},
+ {"resource.001", 0, "bb642b0b0f879aca98addd62d901387e", 445841},
+ {"resource.002", 0, "c2cb2dec12e26f6243bc1b78e4e84940", 617030},
+ {"resource.003", 0, "f8e876302a3aba5bcaab5c51db6b6532", 682911},
+ {"resource.004", 0, "16f4d8fb1b526125edaca4fc6cbb7530", 530230},
+ {"resource.005", 0, "6043b2cc23d663e6a01b25bd0e4de55e", 576442},
+ {"resource.006", 0, "f6046a8445422f17d40b1b10ab21ebf3", 568551},
+ {"resource.007", 0, "640ee65595d40372ef95462f2c1ae28a", 593429},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
+ // Larry 5 EGA
+ // Supplied by omer_mor in bug report #3049771
+ {"lsl5", "EGA", {
+ {"resource.map", 0, "89dbf8006985ec0c547ffe125c25ebf9", 6255},
+ {"resource.000", 0, "f2537473213d70e7f4fc82e988ab90ca", 765747},
+ {"resource.001", 0, "bb642b0b0f879aca98addd62d901387e", 1196260},
+ {"resource.002", 0, "5a55af4e40728b1a8103dc47ad2afa8d", 1100539},
+ {"resource.003", 0, "16f4d8fb1b526125edaca4fc6cbb7530", 1064563},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Larry 6 - English DOS (from spookypeanut)
// SCI interpreter version 1.001.113
{"lsl6", "", {
@@ -1968,9 +2178,22 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Mixed-Up Mother Goose - English DOS Floppy EGA (supplied by ssburnout in bug report #3049193)
+ // 1.011 5x5.25" (label: Int#8.2.90)
+ {"mothergoose", "EGA", {
+ {"resource.map", 0, "7d308bfc6006d0e20985a7295c238efc", 2010},
+ {"resource.000", 0, "bb662eebeb5ffea2d705064801f6f70f", 140375},
+ {"resource.001", 0, "13ddcdf971339150c2963548c9761b31", 52648},
+ {"resource.002", 0, "13ddcdf971339150c2963548c9761b31", 204401},
+ {"resource.003", 0, "e2c858b89e89bffe37b33e01d2827930", 166990},
+ {"resource.004", 0, "dbbc22f124533ce308bc386b08956326", 146251},
+ {"resource.005", 0, "2ba5348e7fad641b9c4c7ff7c7cf4e68", 110979},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Mixed-Up Mother Goose v2.000 - English DOS Floppy (supplied by markcoolio in bug report #2723795)
// Executable scanning reports "1.001.031"
- {"mothergoose", "", {
+ {"mothergoose256", "", {
{"resource.map", 0, "52aae15e493cafd1da7e1c9b657a5bb9", 7026},
{"resource.000", 0, "b7ecd8ae9e254e80310b5a668b276e6e", 2948975},
AD_LISTEND},
@@ -1979,7 +2202,7 @@ static const struct ADGameDescription SciGameDescriptions[] = {
// Mixed-Up Mother Goose - English DOS CD (from jvprat)
// Executable scanning reports "x.yyy.zzz"
// SCI interpreter version 0.000.999 (just a guess)
- {"mothergoose", "CD", {
+ {"mothergoose256", "CD", {
{"resource.map", 0, "1c7f311b0a2c927b2fbe81ae341fb2f6", 5790},
{"resource.001", 0, "5a0ed1d745855148364de1b3be099bac", 4369438},
AD_LISTEND},
@@ -1987,7 +2210,7 @@ static const struct ADGameDescription SciGameDescriptions[] = {
// Mixed-Up Mother Goose - English Windows Interactive Demo
// Executable scanning reports "x.yyy.zzz"
- {"mothergoose", "Demo", {
+ {"mothergoose256", "Demo", {
{"resource.map", 0, "87f9dc1cafc4d4fa835fb2f00cf3a6ef", 4560},
{"resource.001", 0, "5a0ed1d745855148364de1b3be099bac", 2070072},
AD_LISTEND},
@@ -2249,6 +2472,19 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::DE_DEU, Common::kPlatformPC, ADGF_ADDENGLISH, GUIO_NOSPEECH },
+ // Police Quest 3 EGA
+ // Reported by musiclyinspired in bug report #3046573
+ {"pq3", "", {
+ {"resource.map", 0, "1341f7c9643947414a8e238b88f68d82", 5901},
+ {"resource.000", 0, "7659713720d61d9465a59091b7ee63ea", 402208},
+ {"resource.001", 0, "0284ca44341fbc3cb7a047e49d230234", 703373},
+ {"resource.002", 0, "fc9452f962bd7a9bbf6e78e9e52a8e18", 692676},
+ {"resource.003", 0, "31c226bf01b69c8182b8ca0e8760b0a7", 527848},
+ {"resource.004", 0, "b96a86ab681769e4cbb439670d967ca6", 449682},
+ {"resource.005", 0, "9e6c53a0e7eef53694d260fade8b1fc7", 724000},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Police Quest 4 - English DOS Non-Interactive Demo (from FRG)
// SCI interpreter version 1.001.096
{"pq4", "Demo", {
@@ -2341,6 +2577,36 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Quest for Glory 1 / Hero's Quest - English DOS 5.25" Floppy (supplied by ssburnout in bug report #3049193)
+ // 1.001 10x5.25" (label: INT.#0.000.566)
+ {"qfg1", "", {
+ {"resource.map", 0, "c5a0346ff16c43b1eea9583d15e7743c", 6948},
+ {"resource.000", 0, "481b034132106390cb5160fe61dd5f58", 80334},
+ {"resource.001", 0, "4d67acf52833ff45c7f753d6663532e8", 95500},
+ {"resource.002", 0, "3e2a89d60d385caca5b3394049da4bc4", 271587},
+ {"resource.003", 0, "e56e9fd2f7d2c98774699f7a5087e524", 256373},
+ {"resource.004", 0, "d74cd4290bf60e1409117202e4ce8592", 266415},
+ {"resource.005", 0, "7288ed6d5da89b7a80b4af3897a7963a", 271185},
+ {"resource.006", 0, "69366c2a2f99917199fe1b60a4fee19d", 267852},
+ {"resource.007", 0, "7ab2bf8e224b57f75e0cd6e4ba790761", 272747},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
+ // Quest for Glory 1 / Hero's Quest - English DOS 5.25" Floppy (supplied by ssburnout in bug report #3049193)
+ // 1.200 10x5.25" (label: INT#9.10.90)
+ {"qfg1", "", {
+ {"resource.map", 0, "96939838dd9aa17b110c25256f04dd0b", 6906},
+ {"resource.000", 0, "40332d3ebfc70a4b6a6a0443c2763287", 79181},
+ {"resource.001", 0, "917fcef303e9489597154727baaa9e07", 74752},
+ {"resource.002", 0, "c000304092dc439d5103563853b4fc6d", 273186},
+ {"resource.003", 0, "1903eb08c02e2218b4a38ab9d5553e01", 258115},
+ {"resource.004", 0, "4b8e46d72ce887d13c552be56db3b3c8", 267882},
+ {"resource.005", 0, "f40198349d542e105d040743435e0cd6", 268907},
+ {"resource.006", 0, "f46690dca714abc8c89357d30e363dd3", 278387},
+ {"resource.007", 0, "951299a82a8134ed12c5c18118d45c2f", 269173},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Quest for Glory 1 / Hero's Quest - English DOS Demo
// Executable scanning reports "0.000.685"
{"qfg1", "Demo", {
@@ -2446,6 +2712,33 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformAmiga, 0, GUIO_NOSPEECH },
+ // Quest for Glory 2 - English (supplied by ssburnout in bug report #3049193)
+ // 1.000 5x5.25" (label: INT#10.31.90)
+ {"qfg2", "", {
+ {"resource.map", 0, "5b07fa7ea23afb7dd6804e64e7f7470f", 6906},
+ {"resource.000", 0, "a17e374c4d33b81208c862bc0ffc1a38", 212151},
+ {"resource.001", 0, "e4cc56e7a471325bc8ba1dc78334f52f", 866944},
+ {"resource.002", 0, "5f08242f962293be8fb852f183342350", 790850},
+ {"resource.003", 0, "0790f67d87642132be515cab05026baa", 972144},
+ {"resource.004", 0, "2ac1e6fea9aa1f5b91a06693a67b9766", 982830},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
+ // Quest for Glory 2 - English (supplied by ssburnout in bug report #3049193)
+ // 1.000 9x3.5" (label: INT#10.31.90)
+ {"qfg2", "", {
+ {"resource.map", 0, "1e30119a632a53eb8343fff7c9989025", 8148},
+ {"resource.000", 0, "a17e374c4d33b81208c862bc0ffc1a38", 212151},
+ {"resource.001", 0, "e4cc56e7a471325bc8ba1dc78334f52f", 331803},
+ {"resource.002", 0, "5f08242f962293be8fb852f183342350", 468129},
+ {"resource.003", 0, "5f08242f962293be8fb852f183342350", 501963},
+ {"resource.004", 0, "5f08242f962293be8fb852f183342350", 482486},
+ {"resource.005", 0, "5f08242f962293be8fb852f183342350", 478071},
+ {"resource.006", 0, "5e9deacbdb17198ad844988e04833520", 498593},
+ {"resource.007", 0, "2ac1e6fea9aa1f5b91a06693a67b9766", 490151},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Quest for Glory 2 - English (from FRG)
// Executable scanning reports "1.000.072"
{"qfg2", "", {
@@ -2522,6 +2815,15 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::ES_ESP, Common::kPlatformPC, 0, GUIO_NONE },
+ // Quest for Glory 3 - Italian DOS
+ // Supplied by ghoost in bug report #3053457
+ {"qfg3", "", {
+ {"resource.map", 0, "19e2bf9b693932b5e2bb59b9f9ab86c9", 5958},
+ {"resource.000", 0, "6178ad2e83e58e4671ca03315f7a6498", 5868000},
+ {"resource.msg", 0, "5a0a896ff3e4a628db38a75eb6c84114", 259018},
+ AD_LISTEND},
+ Common::IT_ITA, Common::kPlatformPC, 0, GUIO_NONE },
+
// Quest for Glory 4 - English DOS Non-Interactive Demo (from FRG)
// SCI interpreter version 1.001.069 (just a guess)
{"qfg4", "Demo", {
@@ -2725,6 +3027,19 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::ES_ESP, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Space Quest I 2.0 EGA DOS (6 x 3.5" disks)
+ // Provided by ssburnout in bug report #3046805
+ {"sq1sci", "EGA Remake", {
+ {"resource.map", 0, "dc1bb935bf32da652b2e687617f50cd4", 6003},
+ {"resource.000", 0, "e9d866534f8c84de82e25f2631ff258c", 409145},
+ {"resource.001", 0, "a89b7b52064c75b1985b289edc2f5c69", 647747},
+ {"resource.002", 0, "f43d4f08547336c9fd28c23a7da79c41", 697438},
+ {"resource.003", 0, "4164edf21495b9114f9a514e401b4d95", 669070},
+ {"resource.004", 0, "975c6e81194ae6b65e960a248129ecaa", 684119},
+ {"resource.005", 0, "13d96f7905637552c0647175ff816145", 695589},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Space Quest 3 - English Amiga (from www.back2roots.org)
// SCI interpreter version 0.000.453 (just a guess)
{"sq3", "", {
@@ -2851,7 +3166,6 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::DE_DEU, Common::kPlatformAmiga, ADGF_ADDENGLISH, GUIO_NOSPEECH },
-#if 0
// Space Quest 4 - English DOS - THIS VERSION IS PIRATED/CRACKED AND REPACKAGED =DO NOT RE-ADD=
// Executable scanning reports "1.000.753"
// SCI interpreter version 1.000.200 (just a guess)
@@ -2859,8 +3173,7 @@ static const struct ADGameDescription SciGameDescriptions[] = {
{"resource.map", 0, "a18088c8aceb06025dbc945f29e02935", 5124},
{"resource.000", 0, "e1f46832cd2458796028e054a0466031", 5502009},
AD_LISTEND},
- Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
-#endif
+ Common::EN_ANY, Common::kPlatformPC, ADGF_PIRATED, GUIO_NOSPEECH },
// Space Quest 4 - English DOS
// Executable scanning reports "1.000.753"
@@ -2897,6 +3210,19 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+ // Space Quest IV DOS 1.060 EGA (6 x 3.5" disks)
+ // Supplied by ssburnout in bug report #3046781
+ {"sq4", "EGA", {
+ {"resource.map", 0, "4f59814d23a3721f251140fdcfebe35d", 5556},
+ {"resource.000", 0, "e1f46832cd2458796028e054a0466031", 385479},
+ {"resource.001", 0, "590b996f85333dba50cfdd1489de2be2", 617504},
+ {"resource.002", 0, "ea8c49b84c6e641e7600cbca90a81741", 632814},
+ {"resource.003", 0, "33c396eb78bafaec38480bcdd9024843", 627369},
+ {"resource.004", 0, "9a673e33c3f6dd560b993ffed77eeb49", 534994},
+ {"resource.005", 0, "3c4841d0a3ebba4404af588c93620c22", 595465},
+ AD_LISTEND},
+ Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
+
// Space Quest 4 - German DOS (from Tobis87, also includes english language)
// SCI interpreter version 1.000.200 (just a guess)
{"sq4", "", {
@@ -3016,7 +3342,6 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
-#if 0
// Space Quest 5 - English DOS - THIS IS THE UNOFFICIAL BETA VERSION, WHICH IS OBVIOUSLY PIRATED AND CONTAINS MANY BUGS
// ffs. http://www.akril15.com/sr/sq5alt/sq5alt.html =DO NOT RE-ADD=
// SCI interpreter version 1.001.067
@@ -3024,8 +3349,7 @@ static const struct ADGameDescription SciGameDescriptions[] = {
{"resource.map", 0, "8bde0a9adb9a3e9aaa861826874c9834", 6473},
{"resource.000", 0, "f4a48705764544d7cc64a7bb22a610df", 6025184},
AD_LISTEND},
- Common::EN_ANY, Common::kPlatformPC, 0, GUIO_NOSPEECH },
-#endif
+ Common::EN_ANY, Common::kPlatformPC, ADGF_PIRATED, GUIO_NOSPEECH },
// Space Quest 5 v1.04 - German DOS (from Tobis87, updated information by markcool from bug reports #2723935 and #2724762)
// SCI interpreter version 1.001.068
diff --git a/engines/sci/engine/features.cpp b/engines/sci/engine/features.cpp
index f99d412c64..97eec38caf 100644
--- a/engines/sci/engine/features.cpp
+++ b/engines/sci/engine/features.cpp
@@ -138,9 +138,9 @@ bool GameFeatures::autoDetectSoundType() {
SciVersion GameFeatures::detectDoSoundType() {
if (_doSoundType == SCI_VERSION_NONE) {
if (getSciVersion() == SCI_VERSION_0_EARLY) {
- // This game is using early SCI0 sound code (different headers than
- // SCI0 late)
- _doSoundType = SCI_VERSION_0_EARLY;
+ // Almost all of the SCI0EARLY games use different sound resources than
+ // SCI0LATE. Although the last SCI0EARLY game (lsl2) uses SCI0LATE resources
+ _doSoundType = g_sci->getResMan()->detectEarlySound() ? SCI_VERSION_0_EARLY : SCI_VERSION_0_LATE;
#ifdef ENABLE_SCI32
} else if (getSciVersion() >= SCI_VERSION_2_1) {
_doSoundType = SCI_VERSION_2_1;
@@ -275,15 +275,8 @@ SciVersion GameFeatures::detectLofsType() {
return _lofsType;
}
- // Find the "Game" object, super class of the actual game-object
- const reg_t game = g_sci->getGameObject();
- const Object *gameObject = _segMan->getObject(game);
- reg_t gameSuperClass = NULL_REG;
- if (gameObject) {
- gameSuperClass = gameObject->getSuperClassSelector();
- }
-
- // Find a function of the game object which invokes lofsa/lofss
+ // Find a function of the "Game" object (which is the game super class) which invokes lofsa/lofss
+ reg_t gameSuperClass = g_sci->getGameSuperClassAddress();
bool found = false;
if (!gameSuperClass.isNull()) {
Common::String gameSuperClassName = _segMan->getObjectName(gameSuperClass);
diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp
index 936b83d760..c1939c6566 100644
--- a/engines/sci/engine/gc.cpp
+++ b/engines/sci/engine/gc.cpp
@@ -28,6 +28,8 @@
namespace Sci {
+//#define GC_DEBUG_CODE
+
struct WorklistManager {
Common::Array<reg_t> _worklist;
AddrSet _map;
@@ -153,10 +155,12 @@ void run_gc(EngineState *s) {
// Some debug stuff
debugC(2, kDebugLevelGC, "[GC] Running...");
+#ifdef GC_DEBUG_CODE
const char *segnames[SEG_TYPE_MAX + 1];
int segcount[SEG_TYPE_MAX + 1];
memset(segnames, 0, sizeof(segnames));
memset(segcount, 0, sizeof(segcount));
+#endif
// Compute the set of all segments references currently in use.
AddrSet *activeRefs = findAllActiveReferences(s);
@@ -166,10 +170,13 @@ void run_gc(EngineState *s) {
const Common::Array<SegmentObj *> &heap = segMan->getSegments();
for (uint seg = 1; seg < heap.size(); seg++) {
SegmentObj *mobj = heap[seg];
+
if (mobj != NULL) {
+#ifdef GC_DEBUG_CODE
const SegmentType type = mobj->getType();
segnames[type] = SegmentObj::getSegmentTypeName(type);
-
+#endif
+
// Get a list of all deallocatable objects in this segment,
// then free any which are not referenced from somewhere.
const Common::Array<reg_t> tmp = mobj->listAllDeallocatable(seg);
@@ -179,7 +186,9 @@ void run_gc(EngineState *s) {
// Not found -> we can free it
mobj->freeAtAddress(segMan, addr);
debugC(2, kDebugLevelGC, "[GC] Deallocating %04x:%04x", PRINT_REG(addr));
+#ifdef GC_DEBUG_CODE
segcount[type]++;
+#endif
}
}
@@ -188,11 +197,13 @@ void run_gc(EngineState *s) {
delete activeRefs;
+#ifdef GC_DEBUG_CODE
// Output debug summary of garbage collection
debugC(2, kDebugLevelGC, "[GC] Summary:");
for (int i = 0; i <= SEG_TYPE_MAX; i++)
if (segcount[i])
debugC(2, kDebugLevelGC, "\t%d\t* %s", segcount[i], segnames[i]);
+#endif
}
} // End of namespace Sci
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index 157884fac3..ff327a0049 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -744,11 +744,9 @@ void Kernel::setDefaultKernelNames(GameFeatures *features) {
_kernelNames = Common::StringArray(s_defaultKernelNames, ARRAYSIZE(s_defaultKernelNames));
// Some (later) SCI versions replaced CanBeHere by CantBeHere
- if (_selectorCache.cantBeHere != -1) {
- // hoyle 3 has cantBeHere selector but is assuming to call kCanBeHere
- if (g_sci->getGameId() != GID_HOYLE3)
- _kernelNames[0x4d] = "CantBeHere";
- }
+ // If vocab.999 exists, the kernel function is still named CanBeHere
+ if (_selectorCache.cantBeHere != -1)
+ _kernelNames[0x4d] = "CantBeHere";
switch (getSciVersion()) {
case SCI_VERSION_0_EARLY:
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index b6247b46f1..e50c6aaae2 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -278,7 +278,6 @@ private:
/******************** Kernel functions ********************/
-// New kernel functions
reg_t kStrLen(EngineState *s, int argc, reg_t *argv);
reg_t kGetFarText(EngineState *s, int argc, reg_t *argv);
reg_t kReadNumber(EngineState *s, int argc, reg_t *argv);
@@ -419,6 +418,8 @@ reg_t kStrSplit(EngineState *s, int argc, reg_t *argv);
reg_t kPlatform(EngineState *s, int argc, reg_t *argv);
reg_t kTextColors(EngineState *s, int argc, reg_t *argv);
reg_t kTextFonts(EngineState *s, int argc, reg_t *argv);
+reg_t kShow(EngineState *s, int argc, reg_t *argv);
+reg_t kRemapColors(EngineState *s, int argc, reg_t *argv);
reg_t kDummy(EngineState *s, int argc, reg_t *argv);
reg_t kEmpty(EngineState *s, int argc, reg_t *argv);
reg_t kStub(EngineState *s, int argc, reg_t *argv);
@@ -443,13 +444,14 @@ reg_t kAddPlane(EngineState *s, int argc, reg_t *argv);
reg_t kDeletePlane(EngineState *s, int argc, reg_t *argv);
reg_t kUpdatePlane(EngineState *s, int argc, reg_t *argv);
reg_t kRepaintPlane(EngineState *s, int argc, reg_t *argv);
+reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv);
reg_t kGetHighPlanePri(EngineState *s, int argc, reg_t *argv);
reg_t kFrameOut(EngineState *s, int argc, reg_t *argv);
+reg_t kIsOnMe(EngineState *s, int argc, reg_t *argv); // kOnMe for SCI2, kIsOnMe for SCI2.1
reg_t kListIndexOf(EngineState *s, int argc, reg_t *argv);
reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv);
reg_t kListFirstTrue(EngineState *s, int argc, reg_t *argv);
reg_t kListAllTrue(EngineState *s, int argc, reg_t *argv);
-reg_t kOnMe(EngineState *s, int argc, reg_t *argv);
reg_t kInPolygon(EngineState *s, int argc, reg_t *argv);
// SCI2.1 Kernel Functions
@@ -458,13 +460,15 @@ reg_t kSave(EngineState *s, int argc, reg_t *argv);
reg_t kList(EngineState *s, int argc, reg_t *argv);
reg_t kRobot(EngineState *s, int argc, reg_t *argv);
reg_t kPlayVMD(EngineState *s, int argc, reg_t *argv);
-reg_t kIsOnMe(EngineState *s, int argc, reg_t *argv);
reg_t kCD(EngineState *s, int argc, reg_t *argv);
reg_t kAddPicAt(EngineState *s, int argc, reg_t *argv);
-
reg_t kAddBefore(EngineState *s, int argc, reg_t *argv);
reg_t kMoveToFront(EngineState *s, int argc, reg_t *argv);
reg_t kMoveToEnd(EngineState *s, int argc, reg_t *argv);
+reg_t kGetWindowsOption(EngineState *s, int argc, reg_t *argv);
+reg_t kWinHelp(EngineState *s, int argc, reg_t *argv);
+reg_t kWinDLL(EngineState *s, int argc, reg_t *argv);
+reg_t kPrintDebug(EngineState *s, int argc, reg_t *argv);
#endif
reg_t kDoSoundInit(EngineState *s, int argc, reg_t *argv);
diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h
index e71e97e95d..d2c95053d5 100644
--- a/engines/sci/engine/kernel_tables.h
+++ b/engines/sci/engine/kernel_tables.h
@@ -81,6 +81,8 @@ struct SciKernelMapSubEntry {
#define SIG_EVERYWHERE SIG_SCIALL, SIGFOR_ALL
#define MAP_CALL(_name_) #_name_, k##_name_
+#define MAP_EMPTY(_name_) #_name_, kEmpty
+#define MAP_DUMMY(_name_) #_name_, kDummy
// version, subId, function-mapping, signature, workarounds
static const SciKernelMapSubEntry kDoSound_subops[] = {
@@ -248,7 +250,7 @@ static const SciKernelMapSubEntry kFileIO_subops[] = {
static const SciKernelMapSubEntry kList_subops[] = {
{ SIG_SCI21, 0, MAP_CALL(NewList), "", NULL },
{ SIG_SCI21, 1, MAP_CALL(DisposeList), "l", NULL },
- { SIG_SCI21, 2, MAP_CALL(NewNode), ".", NULL },
+ { SIG_SCI21, 2, MAP_CALL(NewNode), ".(.)", NULL },
{ SIG_SCI21, 3, MAP_CALL(FirstNode), "[l0]", NULL },
{ SIG_SCI21, 4, MAP_CALL(LastNode), "l", NULL },
{ SIG_SCI21, 5, MAP_CALL(EmptyList), "l", NULL },
@@ -257,20 +259,14 @@ static const SciKernelMapSubEntry kList_subops[] = {
{ SIG_SCI21, 8, MAP_CALL(NodeValue), "[n0]", NULL },
{ SIG_SCI21, 9, MAP_CALL(AddAfter), "lnn.", NULL },
{ SIG_SCI21, 10, MAP_CALL(AddToFront), "ln.", NULL },
- { SIG_SCI21, 11, MAP_CALL(AddToEnd), "ln.", NULL },
+ { SIG_SCI21, 11, MAP_CALL(AddToEnd), "ln(.)", NULL },
{ SIG_SCI21, 12, MAP_CALL(AddBefore), "ln.", NULL },
{ SIG_SCI21, 13, MAP_CALL(MoveToFront), "ln", NULL },
{ SIG_SCI21, 14, MAP_CALL(MoveToEnd), "ln", NULL },
{ SIG_SCI21, 15, MAP_CALL(FindKey), "l.", NULL },
{ SIG_SCI21, 16, MAP_CALL(DeleteKey), "l.", NULL },
{ SIG_SCI21, 17, MAP_CALL(ListAt), "li", NULL },
- // FIXME: This doesn't seem to be ListIndexOf. In Torin demo, an index is
- // passed as a second parameter instead of an object. Thus, it seems to
- // be something like ListAt instead... If we swap the two subops though,
- // Torin demo crashes complaining that it tried to send to a non-object,
- // therefore the semantics might be different here (signature was l[o0])
- // In SQ6 object is passed right when skipping the intro
- { SIG_SCI21, 18, MAP_CALL(StubNull), "l[io]", NULL },
+ { SIG_SCI21, 18, MAP_CALL(ListIndexOf) , "l[io]", NULL },
{ SIG_SCI21, 19, MAP_CALL(ListEachElementDo), "li(.*)", NULL },
{ SIG_SCI21, 20, MAP_CALL(ListFirstTrue), "li(.*)", NULL },
{ SIG_SCI21, 21, MAP_CALL(ListAllTrue), "li(.*)", NULL },
@@ -323,13 +319,13 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(Display), SIG_EVERYWHERE, "[ir]([ir!]*)", NULL, kDisplay_workarounds },
// ^ we allow invalid references here, because kDisplay gets called with those in e.g. pq3 during intro
// restoreBits() checks and skips invalid handles, so that's fine. Sierra SCI behaved the same
- { MAP_CALL(DirLoop), SIG_EVERYWHERE, "oi", NULL, NULL },
+ { MAP_CALL(DirLoop), SIG_EVERYWHERE, "oi", NULL, kDirLoop_workarounds },
{ MAP_CALL(DisposeClone), SIG_EVERYWHERE, "o", NULL, NULL },
{ MAP_CALL(DisposeList), SIG_EVERYWHERE, "l", NULL, NULL },
{ MAP_CALL(DisposeScript), SIG_EVERYWHERE, "i(i*)", NULL, kDisposeScript_workarounds },
{ MAP_CALL(DisposeWindow), SIG_EVERYWHERE, "i(i)", NULL, NULL },
{ MAP_CALL(DoAudio), SIG_EVERYWHERE, "i(.*)", NULL, NULL }, // subop
- { MAP_CALL(DoAvoider), SIG_EVERYWHERE, "o", NULL, NULL },
+ { MAP_CALL(DoAvoider), SIG_EVERYWHERE, "o(i)", NULL, NULL },
{ MAP_CALL(DoBresen), SIG_EVERYWHERE, "o", NULL, NULL },
{ MAP_CALL(DoSound), SIG_EVERYWHERE, "i(.*)", kDoSound_subops, NULL },
{ MAP_CALL(DoSync), SIG_EVERYWHERE, "i(.*)", NULL, NULL }, // subop
@@ -409,12 +405,13 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(PriCoord), SIG_EVERYWHERE, "i", NULL, NULL },
{ MAP_CALL(Random), SIG_EVERYWHERE, "i(i)(i)", NULL, NULL },
{ MAP_CALL(ReadNumber), SIG_EVERYWHERE, "r", NULL, NULL },
+ { MAP_CALL(RemapColors), SIG_EVERYWHERE, "i(i)(i)(i)(i)(i)", NULL, NULL },
{ MAP_CALL(ResCheck), SIG_EVERYWHERE, "ii(iiii)", NULL, NULL },
{ MAP_CALL(RespondsTo), SIG_EVERYWHERE, ".i", NULL, NULL },
{ MAP_CALL(RestartGame), SIG_EVERYWHERE, "", NULL, NULL },
- { MAP_CALL(RestoreGame), SIG_EVERYWHERE, "rir", NULL, NULL },
+ { MAP_CALL(RestoreGame), SIG_EVERYWHERE, "[r0]i[r0]", NULL, NULL },
{ MAP_CALL(Said), SIG_EVERYWHERE, "[r0]", NULL, NULL },
- { MAP_CALL(SaveGame), SIG_EVERYWHERE, "rir(r)", NULL, NULL },
+ { MAP_CALL(SaveGame), SIG_EVERYWHERE, "[r0]i[r0](r)", NULL, NULL },
{ MAP_CALL(ScriptID), SIG_EVERYWHERE, "[io](i)", NULL, NULL },
{ MAP_CALL(SetCursor), SIG_SCI21, SIGFOR_ALL, "i(i)([io])(i*)", NULL, NULL },
// TODO: SCI2.1 may supply an object optionally (mother goose sci21 right on startup) - find out why
@@ -430,11 +427,12 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(SetVideoMode), SIG_EVERYWHERE, "i", NULL, NULL },
{ MAP_CALL(ShakeScreen), SIG_EVERYWHERE, "(i)(i)", NULL, NULL },
{ MAP_CALL(ShowMovie), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_CALL(Show), SIG_EVERYWHERE, "i", NULL, NULL },
{ MAP_CALL(SinDiv), SIG_EVERYWHERE, "ii", NULL, NULL },
{ MAP_CALL(Sort), SIG_EVERYWHERE, "ooo", NULL, NULL },
{ MAP_CALL(Sqrt), SIG_EVERYWHERE, "i", NULL, NULL },
{ MAP_CALL(StrAt), SIG_EVERYWHERE, "ri(i)", NULL, kStrAt_workarounds },
- { MAP_CALL(StrCat), SIG_EVERYWHERE, "rr", NULL, NULL },
+ { MAP_CALL(StrCat), SIG_EVERYWHERE, "rr", NULL, kStrCat_workarounds },
{ MAP_CALL(StrCmp), SIG_EVERYWHERE, "rr(i)", NULL, NULL },
{ MAP_CALL(StrCpy), SIG_EVERYWHERE, "r[r0](i)", NULL, NULL },
{ MAP_CALL(StrEnd), SIG_EVERYWHERE, "r", NULL, NULL },
@@ -454,8 +452,25 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(ValidPath), SIG_EVERYWHERE, "r", NULL, NULL },
{ MAP_CALL(Wait), SIG_EVERYWHERE, "i", NULL, NULL },
+ // Unimplemented SCI0-SCI1.1 unused functions, always mapped to kDummy
+ { MAP_DUMMY(InspectObj), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(ShowSends), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(ShowObjs), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(ShowFree), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(StackUsage), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(Profiler), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(ShiftScreen), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(ListOps), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(ATan), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(Record), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(PlayBack), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(DbugStr), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+
+ // =======================================================================================================
+
#ifdef ENABLE_SCI32
// SCI2 Kernel Functions
+ // TODO: whoever knows his way through those calls, fix the signatures.
{ MAP_CALL(AddPlane), SIG_EVERYWHERE, "o", NULL, NULL },
{ MAP_CALL(AddScreenItem), SIG_EVERYWHERE, "o", NULL, NULL },
{ MAP_CALL(Array), SIG_EVERYWHERE, "(.*)", NULL, NULL },
@@ -471,15 +486,22 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(ListEachElementDo), SIG_EVERYWHERE, "li(.*)", NULL, NULL },
{ MAP_CALL(ListFirstTrue), SIG_EVERYWHERE, "li(.*)", NULL, NULL },
{ MAP_CALL(ListIndexOf), SIG_EVERYWHERE, "l[o0]", NULL, NULL },
- { MAP_CALL(OnMe), SIG_EVERYWHERE, "iio(.*)", NULL, NULL },
+ { "OnMe", kIsOnMe, SIG_EVERYWHERE, "iioi", NULL, NULL },
{ MAP_CALL(RepaintPlane), SIG_EVERYWHERE, "o", NULL, NULL },
+ { MAP_CALL(SetShowStyle), SIG_EVERYWHERE, "ioiiiii(i)", NULL, NULL },
{ MAP_CALL(String), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(UpdatePlane), SIG_EVERYWHERE, "o", NULL, NULL },
{ MAP_CALL(UpdateScreenItem), SIG_EVERYWHERE, "o", NULL, NULL },
+ // SCI2 empty functions
+
+ // Purge is used by the memory manager in SSCI to ensure that X number of bytes (the so called "unmovable
+ // memory") are available. We have our own memory manager and garbage collector, thus we ignore this call.
+ { MAP_EMPTY(Purge), SIG_EVERYWHERE, "i", NULL, NULL },
+
// SCI2.1 Kernel Functions
- { MAP_CALL(CD), SIG_EVERYWHERE, "(.*)", NULL, NULL },
- { MAP_CALL(IsOnMe), SIG_EVERYWHERE, "iio(.*)", NULL, NULL },
+ { MAP_CALL(CD), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_CALL(IsOnMe), SIG_EVERYWHERE, "iioi", NULL, NULL },
{ MAP_CALL(List), SIG_SCI21, SIGFOR_ALL, "(.*)", kList_subops, NULL },
{ MAP_CALL(MulDiv), SIG_EVERYWHERE, "iii", NULL, NULL },
{ MAP_CALL(PlayVMD), SIG_EVERYWHERE, "(.*)", NULL, NULL },
@@ -487,8 +509,32 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(Save), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(Text), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(AddPicAt), SIG_EVERYWHERE, "oiii", NULL, NULL },
- { NULL, NULL, SIG_EVERYWHERE, NULL, NULL, NULL }
+ { MAP_CALL(GetWindowsOption), SIG_EVERYWHERE, "i", NULL, NULL },
+ { MAP_CALL(WinHelp), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_CALL(WinDLL), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_CALL(PrintDebug), SIG_EVERYWHERE, "ri", NULL, NULL },
+
+ // SCI2.1 empty functions
+
+ // SetWindowsOption is used to set Windows specific options, like for example the title bar visibility of
+ // the game window in Phantasmagoria 2. We ignore these settings completely.
+ { MAP_EMPTY(SetWindowsOption), SIG_EVERYWHERE, "ii", NULL, NULL },
+
+ // Unimplemented SCI2.1 unused functions, always mapped to kDummy
+ { MAP_DUMMY(InspectObject), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ // Profiler (same as SCI0-SCI1.1)
+ // Record (same as SCI0-SCI1.1)
+ // PlayBack (same as SCI0-SCI1.1)
+ { MAP_DUMMY(MonoOut), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(SetFatalStr), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(IntegrityChecking),SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(CheckIntegrity), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(MarkMemory), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(GetSierraProfileInt), SIG_EVERYWHERE, "(.*)", NULL, NULL },
+ { MAP_DUMMY(GetSierraProfileString), SIG_EVERYWHERE, "(.*)", NULL, NULL },
#endif
+
+ { NULL, NULL, SIG_EVERYWHERE, NULL, NULL, NULL }
};
/** Default kernel name table. */
@@ -502,7 +548,7 @@ static const char *s_defaultKernelNames[] = {
/*0x06*/ "IsObject",
/*0x07*/ "RespondsTo",
/*0x08*/ "DrawPic",
- /*0x09*/ "Dummy", // Show
+ /*0x09*/ "Show",
/*0x0a*/ "PicNotValid",
/*0x0b*/ "Animate",
/*0x0c*/ "SetNowSeen",
@@ -574,20 +620,20 @@ static const char *s_defaultKernelNames[] = {
/*0x4a*/ "ReadNumber",
/*0x4b*/ "BaseSetter",
/*0x4c*/ "DirLoop",
- /*0x4d*/ "CanBeHere", // CantBeHere in newer SCI versions
+ /*0x4d*/ "CanBeHere", // CantBeHere in newer SCI versions
/*0x4e*/ "OnControl",
/*0x4f*/ "InitBresen",
/*0x50*/ "DoBresen",
- /*0x51*/ "Platform", // DoAvoider (SCI0)
+ /*0x51*/ "Platform", // DoAvoider (SCI0)
/*0x52*/ "SetJump",
- /*0x53*/ "SetDebug",
- /*0x54*/ "Dummy", // InspectObj
- /*0x55*/ "Dummy", // ShowSends
- /*0x56*/ "Dummy", // ShowObjs
- /*0x57*/ "Dummy", // ShowFree
+ /*0x53*/ "SetDebug", // for debugging
+ /*0x54*/ "InspectObj", // for debugging
+ /*0x55*/ "ShowSends", // for debugging
+ /*0x56*/ "ShowObjs", // for debugging
+ /*0x57*/ "ShowFree", // for debugging
/*0x58*/ "MemoryInfo",
- /*0x59*/ "Dummy", // StackUsage
- /*0x5a*/ "Dummy", // Profiler
+ /*0x59*/ "StackUsage", // for debugging
+ /*0x5a*/ "Profiler", // for debugging
/*0x5b*/ "GetMenu",
/*0x5c*/ "SetMenu",
/*0x5d*/ "GetSaveFiles",
@@ -608,33 +654,33 @@ static const char *s_defaultKernelNames[] = {
/*0x6c*/ "Graph",
/*0x6d*/ "Joystick",
// End of kernel function table for SCI0
- /*0x6e*/ "Dummy", // ShiftScreen
+ /*0x6e*/ "ShiftScreen", // never called?
/*0x6f*/ "Palette",
/*0x70*/ "MemorySegment",
/*0x71*/ "Intersections", // MoveCursor (SCI1 late), PalVary (SCI1.1)
/*0x72*/ "Memory",
- /*0x73*/ "Dummy", // ListOps
+ /*0x73*/ "ListOps", // never called?
/*0x74*/ "FileIO",
/*0x75*/ "DoAudio",
/*0x76*/ "DoSync",
/*0x77*/ "AvoidPath",
- /*0x78*/ "Sort", // StrSplit (SCI01)
- /*0x79*/ "Dummy", // ATan
+ /*0x78*/ "Sort", // StrSplit (SCI01)
+ /*0x79*/ "ATan", // never called?
/*0x7a*/ "Lock",
/*0x7b*/ "StrSplit",
- /*0x7c*/ "GetMessage", // Message (SCI1.1)
+ /*0x7c*/ "GetMessage", // Message (SCI1.1)
/*0x7d*/ "IsItSkip",
/*0x7e*/ "MergePoly",
/*0x7f*/ "ResCheck",
/*0x80*/ "AssertPalette",
/*0x81*/ "TextColors",
/*0x82*/ "TextFonts",
- /*0x83*/ "Dummy", // Record
- /*0x84*/ "Dummy", // PlayBack
+ /*0x83*/ "Record", // for debugging
+ /*0x84*/ "PlayBack", // for debugging
/*0x85*/ "ShowMovie",
/*0x86*/ "SetVideoMode",
/*0x87*/ "SetQuitStr",
- /*0x88*/ "Dummy" // DbugStr
+ /*0x88*/ "DbugStr" // for debugging
};
#ifdef ENABLE_SCI32
@@ -757,13 +803,13 @@ static const char *sci2_default_knames[] = {
/*0x70*/ "InPolygon",
/*0x71*/ "MergePoly",
/*0x72*/ "SetDebug",
- /*0x73*/ "InspectObject",
+ /*0x73*/ "InspectObject", // for debugging
/*0x74*/ "MemoryInfo",
- /*0x75*/ "Profiler",
- /*0x76*/ "Record",
- /*0x77*/ "PlayBack",
- /*0x78*/ "MonoOut",
- /*0x79*/ "SetFatalStr",
+ /*0x75*/ "Profiler", // for debugging
+ /*0x76*/ "Record", // for debugging
+ /*0x77*/ "PlayBack", // for debugging
+ /*0x78*/ "MonoOut", // for debugging
+ /*0x79*/ "SetFatalStr", // for debugging
/*0x7a*/ "GetCWD",
/*0x7b*/ "ValidPath",
/*0x7c*/ "FileIO",
@@ -775,10 +821,10 @@ static const char *sci2_default_knames[] = {
/*0x82*/ "Array",
/*0x83*/ "String",
/*0x84*/ "RemapColors",
- /*0x85*/ "IntegrityChecking",
- /*0x86*/ "CheckIntegrity",
+ /*0x85*/ "IntegrityChecking", // for debugging
+ /*0x86*/ "CheckIntegrity", // for debugging
/*0x87*/ "ObjectIntersect",
- /*0x88*/ "MarkMemory",
+ /*0x88*/ "MarkMemory", // for debugging
/*0x89*/ "TextWidth",
/*0x8a*/ "PointSize",
@@ -934,7 +980,7 @@ static const char *sci21_default_knames[] = {
/*0x7c*/ "SetQuitStr",
/*0x7d*/ "GetConfig",
/*0x7e*/ "Table",
- /*0x7f*/ "WinHelp", // Windows only
+ /*0x7f*/ "WinHelp", // Windows only
/*0x80*/ "Dummy",
/*0x81*/ "Dummy",
/*0x82*/ "Dummy",
@@ -956,8 +1002,8 @@ static const char *sci21_default_knames[] = {
/*0x92*/ "PlayVMD",
/*0x93*/ "SetHotRectangles",
/*0x94*/ "MulDiv",
- /*0x95*/ "GetSierraProfileInt", // Windows only
- /*0x96*/ "GetSierraProfileString", // Windows only
+ /*0x95*/ "GetSierraProfileInt", // , Windows only
+ /*0x96*/ "GetSierraProfileString", // , Windows only
/*0x97*/ "SetWindowsOption", // Windows only
/*0x98*/ "GetWindowsOption", // Windows only
/*0x99*/ "WinDLL", // Windows only
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index 3395811700..9d48174078 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -23,6 +23,8 @@
*
*/
+#include "common/system.h"
+
#include "sci/sci.h"
#include "sci/engine/features.h"
#include "sci/engine/state.h"
@@ -42,7 +44,6 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
int mask = argv[0].toUint16();
reg_t obj = argv[1];
SciEvent curEvent;
- int oldx, oldy;
int modifier_mask = getSciVersion() <= SCI_VERSION_01 ? SCI_KEYMOD_ALL : SCI_KEYMOD_NO_FOOLOCK;
SegManager *segMan = s->_segMan;
Common::Point mousePos;
@@ -67,13 +68,24 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
return make_reg(0, 1);
}
- oldx = mousePos.x;
- oldy = mousePos.y;
curEvent = g_sci->getEventManager()->getSciEvent(mask);
if (g_sci->getVocabulary())
g_sci->getVocabulary()->parser_event = NULL_REG; // Invalidate parser event
+ if (s->_cursorWorkaroundActive) {
+ // ffs: GfxCursor::setPosition()
+ // we check, if actual cursor position is inside given rect
+ // if that's the case, we switch ourself off. Otherwise
+ // we simulate the original set position to the scripts
+ if (s->_cursorWorkaroundRect.contains(mousePos.x, mousePos.y)) {
+ s->_cursorWorkaroundActive = false;
+ } else {
+ mousePos.x = s->_cursorWorkaroundPoint.x;
+ mousePos.y = s->_cursorWorkaroundPoint.y;
+ }
+ }
+
writeSelectorValue(segMan, obj, SELECTOR(x), mousePos.x);
writeSelectorValue(segMan, obj, SELECTOR(y), mousePos.y);
@@ -162,6 +174,21 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
g_sci->_soundCmd->updateSci0Cues();
}
+ // Wait a bit here, so that the CPU isn't maxed out when the game
+ // is waiting for user input (e.g. when showing text boxes) - bug
+ // #3037874. This works when games do benchmarking at the beginning,
+ // because most of them call kAnimate for benchmarking without
+ // calling kGetEvent in between (rightly so).
+ if (g_sci->getGameId() == GID_JONES && g_sci->getEngineState()->currentRoomNumber() == 764) {
+ // Jones CD is an exception, as it incorrectly calls GetEvent
+ // while benchmarking. Thus, don't delay here for room 764 in
+ // Jones (the speed test room), otherwise speed testing will
+ // fail and the game won't show any views, as it will think that
+ // the user has a slow machine - bug #3058865
+ } else {
+ g_system->delayMillis(10);
+ }
+
return s->r_acc;
}
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 39c32ccc68..b6d67513d2 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -24,9 +24,13 @@
*/
#include "common/archive.h"
+#include "common/config-manager.h"
#include "common/file.h"
#include "common/str.h"
#include "common/savefile.h"
+#include "common/translation.h"
+
+#include "gui/saveload.h"
#include "sci/sci.h"
#include "sci/engine/state.h"
@@ -37,7 +41,7 @@
namespace Sci {
struct SavegameDesc {
- uint id;
+ int16 id;
int virtualId; // straight numbered, according to id but w/o gaps
int date;
int time;
@@ -98,13 +102,9 @@ enum {
-reg_t file_open(EngineState *s, const char *filename, int mode) {
- // QfG3 character import prepends /\ to the filenames.
- if (filename[0] == '/' && filename[1] == '\\')
- filename += 2;
-
+reg_t file_open(EngineState *s, const char *filename, int mode, bool unwrapFilename) {
Common::String englishName = g_sci->getSciLanguageString(filename, K_LANG_ENGLISH);
- const Common::String wrappedName = g_sci->wrapFilename(englishName);
+ Common::String wrappedName = unwrapFilename ? g_sci->wrapFilename(englishName) : englishName;
Common::SeekableReadStream *inFile = 0;
Common::WriteStream *outFile = 0;
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
@@ -180,7 +180,7 @@ reg_t kFOpen(EngineState *s, int argc, reg_t *argv) {
int mode = argv[1].toUint16();
debugC(2, kDebugLevelFile, "kFOpen(%s,0x%x)", name.c_str(), mode);
- return file_open(s, name.c_str(), mode);
+ return file_open(s, name.c_str(), mode, true);
}
static FileHandle *getFileFromHandle(EngineState *s, uint handle) {
@@ -218,29 +218,31 @@ reg_t kFPuts(EngineState *s, int argc, reg_t *argv) {
return s->r_acc;
}
-static void fgets_wrapper(EngineState *s, char *dest, int maxsize, int handle) {
+static int fgets_wrapper(EngineState *s, char *dest, int maxsize, int handle) {
FileHandle *f = getFileFromHandle(s, handle);
if (!f)
- return;
+ return 0;
if (!f->_in) {
error("fgets_wrapper: Trying to read from file '%s' opened for writing", f->_name.c_str());
- return;
+ return 0;
}
+ int readBytes = 0;
if (maxsize > 1) {
memset(dest, 0, maxsize);
f->_in->readLine(dest, maxsize);
+ readBytes = strlen(dest); // FIXME: sierra sci returned byte count and didn't react on NUL characters
// The returned string must not have an ending LF
- int strSize = strlen(dest);
- if (strSize > 0) {
- if (dest[strSize - 1] == 0x0A)
- dest[strSize - 1] = 0;
+ if (readBytes > 0) {
+ if (dest[readBytes - 1] == 0x0A)
+ dest[readBytes - 1] = 0;
}
} else {
- *dest = f->_in->readByte();
+ *dest = 0;
}
debugC(2, kDebugLevelFile, " -> FGets'ed \"%s\"", dest);
+ return readBytes;
}
reg_t kFGets(EngineState *s, int argc, reg_t *argv) {
@@ -249,9 +251,9 @@ reg_t kFGets(EngineState *s, int argc, reg_t *argv) {
int handle = argv[2].toUint16();
debugC(2, kDebugLevelFile, "kFGets(%d, %d)", handle, maxsize);
- fgets_wrapper(s, buf, maxsize, handle);
+ int readBytes = fgets_wrapper(s, buf, maxsize, handle);
s->_segMan->memcpy(argv[0], (const byte*)buf, maxsize);
- return argv[0];
+ return readBytes ? argv[0] : NULL_REG;
}
/**
@@ -269,7 +271,7 @@ reg_t kGetCWD(EngineState *s, int argc, reg_t *argv) {
}
static void listSavegames(Common::Array<SavegameDesc> &saves);
-static int findSavegame(Common::Array<SavegameDesc> &saves, uint saveId);
+static int findSavegame(Common::Array<SavegameDesc> &saves, int16 saveId);
enum {
K_DEVICE_INFO_GET_DEVICE = 0,
@@ -452,7 +454,7 @@ static void listSavegames(Common::Array<SavegameDesc> &saves) {
}
// Find a savedgame according to virtualId and return the position within our array
-static int findSavegame(Common::Array<SavegameDesc> &saves, uint savegameId) {
+static int findSavegame(Common::Array<SavegameDesc> &saves, int16 savegameId) {
for (uint saveNr = 0; saveNr < saves.size(); saveNr++) {
if (saves[saveNr].id == savegameId)
return saveNr;
@@ -460,7 +462,7 @@ static int findSavegame(Common::Array<SavegameDesc> &saves, uint savegameId) {
return -1;
}
-// The scripts get IDs ranging from 1000->1999, because the scripts require us to assign unique ids THAT EVEN STAY BETWEEN
+// The scripts get IDs ranging from 100->199, because the scripts require us to assign unique ids THAT EVEN STAY BETWEEN
// SAVES and the scripts also use "saves-count + 1" to create a new savedgame slot.
// SCI1.1 actually recycles ids, in that case we will currently get "0".
// This behaviour is required especially for LSL6. In this game, it's possible to quick save. The scripts will use
@@ -494,7 +496,7 @@ reg_t kCheckSaveGame(EngineState *s, int argc, reg_t *argv) {
// Find saved-game
if ((virtualId < SAVEGAMEID_OFFICIALRANGE_START) || (virtualId > SAVEGAMEID_OFFICIALRANGE_END))
- error("kCheckSaveGame: called with invalid savegameId!");
+ error("kCheckSaveGame: called with invalid savegameId");
uint savegameId = virtualId - SAVEGAMEID_OFFICIALRANGE_START;
int savegameNr = findSavegame(saves, savegameId);
if (savegameNr == -1)
@@ -548,78 +550,110 @@ reg_t kGetSaveFiles(EngineState *s, int argc, reg_t *argv) {
}
reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
- Common::String game_id = s->_segMan->getString(argv[0]);
- uint virtualId = argv[1].toUint16();
- Common::String game_description = s->_segMan->getString(argv[2]);
+ Common::String game_id;
+ int16 virtualId = argv[1].toSint16();
+ int16 savegameId = -1;
+ Common::String game_description;
Common::String version;
+
if (argc > 3)
version = s->_segMan->getString(argv[3]);
- debug(3, "kSaveGame(%s,%d,%s,%s)", game_id.c_str(), virtualId, game_description.c_str(), version.c_str());
-
// We check here, we don't want to delete a users save in case we are within a kernel function
if (s->executionStackBase) {
warning("kSaveGame - won't save from within kernel function");
return NULL_REG;
}
- Common::Array<SavegameDesc> saves;
- listSavegames(saves);
-
- uint savegameId;
- if ((virtualId >= SAVEGAMEID_OFFICIALRANGE_START) && (virtualId <= SAVEGAMEID_OFFICIALRANGE_END)) {
- // savegameId is an actual Id, so search for it just to make sure
- savegameId = virtualId - SAVEGAMEID_OFFICIALRANGE_START;
- if (findSavegame(saves, savegameId) == -1)
+ if (argv[0].isNull()) {
+ // Direct call, from a patched Game::save
+ if ((argv[1] != SIGNAL_REG) || (!argv[2].isNull()))
+ error("kSaveGame: assumed patched call isn't accurate");
+
+ // we are supposed to show a dialog for the user and let him choose where to save
+ g_sci->_soundCmd->pauseAll(true); // pause music
+ const EnginePlugin *plugin = NULL;
+ EngineMan.findGame(g_sci->getGameIdStr(), &plugin);
+ GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"));
+ dialog->setSaveMode(true);
+ savegameId = dialog->runModal(plugin, ConfMan.getActiveDomainName());
+ game_description = dialog->getResultString();
+ if (game_description.empty()) {
+ // create our own description for the saved game, the user didnt enter it
+ TimeDate curTime;
+ g_system->getTimeAndDate(curTime);
+ curTime.tm_year += 1900; // fixup year
+ curTime.tm_mon++; // fixup month
+ game_description = Common::String::printf("%02d.%02d.%04d / %02d:%02d:%02d", curTime.tm_mday, curTime.tm_mon, curTime.tm_year, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
+ }
+ delete dialog;
+ g_sci->_soundCmd->pauseAll(false); // unpause music ( we can't have it paused during save)
+ if (savegameId < 0)
return NULL_REG;
- } else if (virtualId < SAVEGAMEID_OFFICIALRANGE_START) {
- // virtualId is low, we assume that scripts expect us to create new slot
- if (virtualId == s->_lastSaveVirtualId) {
- // if last virtual id is the same as this one, we assume that caller wants to overwrite last save
- savegameId = s->_lastSaveNewId;
- } else {
- uint savegameNr;
- // savegameId is in lower range, scripts expect us to create a new slot
- for (savegameId = 0; savegameId < SAVEGAMEID_OFFICIALRANGE_START; savegameId++) {
- for (savegameNr = 0; savegameNr < saves.size(); savegameNr++) {
- if (savegameId == saves[savegameNr].id)
+
+ } else {
+ // Real call from script
+ game_id = s->_segMan->getString(argv[0]);
+ if (argv[2].isNull())
+ error("kSaveGame: called with description being NULL");
+ game_description = s->_segMan->getString(argv[2]);
+
+ debug(3, "kSaveGame(%s,%d,%s,%s)", game_id.c_str(), virtualId, game_description.c_str(), version.c_str());
+
+ Common::Array<SavegameDesc> saves;
+ listSavegames(saves);
+
+ if ((virtualId >= SAVEGAMEID_OFFICIALRANGE_START) && (virtualId <= SAVEGAMEID_OFFICIALRANGE_END)) {
+ // savegameId is an actual Id, so search for it just to make sure
+ savegameId = virtualId - SAVEGAMEID_OFFICIALRANGE_START;
+ if (findSavegame(saves, savegameId) == -1)
+ return NULL_REG;
+ } else if (virtualId < SAVEGAMEID_OFFICIALRANGE_START) {
+ // virtualId is low, we assume that scripts expect us to create new slot
+ if (virtualId == s->_lastSaveVirtualId) {
+ // if last virtual id is the same as this one, we assume that caller wants to overwrite last save
+ savegameId = s->_lastSaveNewId;
+ } else {
+ uint savegameNr;
+ // savegameId is in lower range, scripts expect us to create a new slot
+ for (savegameId = 0; savegameId < SAVEGAMEID_OFFICIALRANGE_START; savegameId++) {
+ for (savegameNr = 0; savegameNr < saves.size(); savegameNr++) {
+ if (savegameId == saves[savegameNr].id)
+ break;
+ }
+ if (savegameNr == saves.size())
break;
}
- if (savegameNr == saves.size())
- break;
+ if (savegameId == SAVEGAMEID_OFFICIALRANGE_START)
+ error("kSavegame: no more savegame slots available");
}
- if (savegameId == SAVEGAMEID_OFFICIALRANGE_START)
- error("kSavegame: no more savegame slots available");
+ } else {
+ error("kSaveGame: invalid savegameId used");
}
- } else {
- error("kSaveGame: invalid savegameId used");
+
+ // Save in case caller wants to overwrite last newly created save
+ s->_lastSaveVirtualId = virtualId;
+ s->_lastSaveNewId = savegameId;
}
- // Save in case caller wants to overwrite last newly created save
- s->_lastSaveVirtualId = virtualId;
- s->_lastSaveNewId = savegameId;
+ s->r_acc = NULL_REG;
Common::String filename = g_sci->getSavegameName(savegameId);
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
Common::OutSaveFile *out;
if (!(out = saveFileMan->openForSaving(filename))) {
warning("Error opening savegame \"%s\" for writing", filename.c_str());
- s->r_acc = NULL_REG;
- return NULL_REG;
- }
-
- if (!gamestate_save(s, out, game_description.c_str(), version.c_str())) {
- warning("Saving the game failed.");
- s->r_acc = NULL_REG;
} else {
- out->finalize();
- if (out->err()) {
- delete out;
- warning("Writing the savegame failed.");
- s->r_acc = NULL_REG;
+ if (!gamestate_save(s, out, game_description.c_str(), version.c_str())) {
+ warning("Saving the game failed");
} else {
+ out->finalize();
+ if (out->err()) {
+ warning("Writing the savegame failed");
+ } else {
+ s->r_acc = TRUE_REG; // success
+ }
delete out;
- s->r_acc = make_reg(0, 1);
}
}
@@ -628,41 +662,75 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
reg_t kRestoreGame(EngineState *s, int argc, reg_t *argv) {
Common::String game_id = !argv[0].isNull() ? s->_segMan->getString(argv[0]) : "";
- uint savegameId = argv[1].toUint16();
+ int16 savegameId = argv[1].toSint16();
+ bool pausedMusic = false;
debug(3, "kRestoreGame(%s,%d)", game_id.c_str(), savegameId);
if (argv[0].isNull()) {
- // Loading from the launcher, don't adjust the ID of the saved game
+ // Direct call, either from launcher or from a patched Game::restore
+ if (savegameId == -1) {
+ // we are supposed to show a dialog for the user and let him choose a saved game
+ g_sci->_soundCmd->pauseAll(true); // pause music
+ const EnginePlugin *plugin = NULL;
+ EngineMan.findGame(g_sci->getGameIdStr(), &plugin);
+ GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"));
+ dialog->setSaveMode(false);
+ savegameId = dialog->runModal(plugin, ConfMan.getActiveDomainName());
+ delete dialog;
+ if (savegameId < 0) {
+ g_sci->_soundCmd->pauseAll(false); // unpause music
+ return s->r_acc;
+ }
+ pausedMusic = true;
+ }
+ // don't adjust ID of the saved game, it's already correct
} else {
- if ((savegameId < 1000) || (savegameId > 1999)) {
+ if (argv[2].isNull())
+ error("kRestoreGame: called with parameter 2 being NULL");
+ // Real call from script, we need to adjust ID
+ if ((savegameId < SAVEGAMEID_OFFICIALRANGE_START) || (savegameId > SAVEGAMEID_OFFICIALRANGE_END)) {
warning("Savegame ID %d is not allowed", savegameId);
return TRUE_REG;
}
- savegameId -= 1000;
+ savegameId -= SAVEGAMEID_OFFICIALRANGE_START;
}
+ s->r_acc = NULL_REG; // signals success
+
Common::Array<SavegameDesc> saves;
listSavegames(saves);
if (findSavegame(saves, savegameId) == -1) {
+ s->r_acc = TRUE_REG;
warning("Savegame ID %d not found", savegameId);
- return TRUE_REG;
- }
-
- Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
- Common::String filename = g_sci->getSavegameName(savegameId);
- Common::SeekableReadStream *in;
- if ((in = saveFileMan->openForLoading(filename))) {
- // found a savegame file
+ } else {
+ Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
+ Common::String filename = g_sci->getSavegameName(savegameId);
+ Common::SeekableReadStream *in;
+ if ((in = saveFileMan->openForLoading(filename))) {
+ // found a savegame file
- gamestate_restore(s, in);
- delete in;
+ gamestate_restore(s, in);
+ delete in;
- return s->r_acc;
+ if (g_sci->getGameId() == GID_MOTHERGOOSE256) {
+ // WORKAROUND: Mother Goose SCI1/SCI1.1 does some weird things for
+ // saving a previously restored game.
+ // We set the current savedgame-id directly and remove the script
+ // code concerning this via script patch.
+ s->variables[VAR_GLOBAL][0xB3].offset = SAVEGAMEID_OFFICIALRANGE_START + savegameId;
+ }
+ } else {
+ s->r_acc = TRUE_REG;
+ warning("Savegame #%d not found", savegameId);
+ }
}
- s->r_acc = TRUE_REG;
- warning("Savegame #%d not found", savegameId);
+ if (!s->r_acc.isNull()) {
+ // no success?
+ if (pausedMusic)
+ g_sci->_soundCmd->pauseAll(false); // unpause music
+ }
return s->r_acc;
}
@@ -676,45 +744,6 @@ reg_t kValidPath(EngineState *s, int argc, reg_t *argv) {
return make_reg(0, 1);
}
-reg_t DirSeeker::firstFile(const Common::String &mask, reg_t buffer, SegManager *segMan) {
- // Verify that we are given a valid buffer
- if (!buffer.segment) {
- error("DirSeeker::firstFile('%s') invoked with invalid buffer", mask.c_str());
- return NULL_REG;
- }
- _outbuffer = buffer;
-
- // Prefix the mask
- const Common::String wrappedMask = g_sci->wrapFilename(mask);
-
- // Obtain a list of all savefiles matching the given mask
- Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
- _savefiles = saveFileMan->listSavefiles(wrappedMask);
-
- // Reset the list iterator and write the first match to the output buffer,
- // if any.
- _iter = _savefiles.begin();
- return nextFile(segMan);
-}
-
-reg_t DirSeeker::nextFile(SegManager *segMan) {
- if (_iter == _savefiles.end()) {
- return NULL_REG;
- }
-
- const Common::String wrappedString = *_iter;
-
- // Strip the prefix
- Common::String string = g_sci->unwrapFilename(wrappedString);
- if (string.size() > 12)
- string = Common::String(string.c_str(), 12);
- segMan->strcpy(_outbuffer, string.c_str());
-
- // Return the result and advance the list iterator :)
- ++_iter;
- return _outbuffer;
-}
-
reg_t kFileIO(EngineState *s, int argc, reg_t *argv) {
if (!s)
return make_reg(0, getSciVersion());
@@ -727,6 +756,7 @@ reg_t kFileIOOpen(EngineState *s, int argc, reg_t *argv) {
// SCI32 can call K_FILEIO_OPEN with only one argument. It seems to
// just be checking if it exists.
int mode = (argc < 2) ? (int)_K_FILE_MODE_OPEN_OR_FAIL : argv[1].toUint16();
+ bool unwrapFilename = true;
// SQ4 floppy prepends /\ to the filenames
if (name.hasPrefix("/\\")) {
@@ -744,11 +774,21 @@ reg_t kFileIOOpen(EngineState *s, int argc, reg_t *argv) {
}
if (name.empty()) {
- warning("Attempted to open a file with an empty filename");
+ // Happens many times during KQ1 (e.g. when typing something)
+ debugC(2, kDebugLevelFile, "Attempted to open a file with an empty filename");
return SIGNAL_REG;
}
debugC(2, kDebugLevelFile, "kFileIO(open): %s, 0x%x", name.c_str(), mode);
- return file_open(s, name.c_str(), mode);
+
+ // QFG import rooms get a virtual filelisting instead of an actual one
+ if (g_sci->inQfGImportRoom()) {
+ // we need to find out what the user actually selected, "savedHeroes" is already destroyed
+ // when we get here. That's why we need to remember selection via kDrawControl
+ name = s->_dirseeker.getVirtualFilename(s->_chosenQfGImportItem);
+ unwrapFilename = false;
+ }
+
+ return file_open(s, name.c_str(), mode, unwrapFilename);
}
reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
@@ -840,10 +880,10 @@ reg_t kFileIOReadString(EngineState *s, int argc, reg_t *argv) {
int handle = argv[2].toUint16();
debugC(2, kDebugLevelFile, "kFileIO(readString): %d, %d", handle, size);
- fgets_wrapper(s, buf, size, handle);
+ int readBytes = fgets_wrapper(s, buf, size, handle);
s->_segMan->memcpy(argv[0], (const byte*)buf, size);
delete[] buf;
- return argv[0];
+ return readBytes ? argv[0] : NULL_REG;
}
reg_t kFileIOWriteString(EngineState *s, int argc, reg_t *argv) {
@@ -852,9 +892,12 @@ reg_t kFileIOWriteString(EngineState *s, int argc, reg_t *argv) {
debugC(2, kDebugLevelFile, "kFileIO(writeString): %d", handle);
FileHandle *f = getFileFromHandle(s, handle);
- if (f)
+
+ if (f) {
f->_out->write(str.c_str(), str.size());
return NULL_REG;
+ }
+
return make_reg(0, 6); // DOS - invalid handle
}
@@ -865,23 +908,117 @@ reg_t kFileIOSeek(EngineState *s, int argc, reg_t *argv) {
debugC(2, kDebugLevelFile, "kFileIO(seek): %d, %d, %d", handle, offset, whence);
FileHandle *f = getFileFromHandle(s, handle);
+
if (f)
s->r_acc = make_reg(0, f->_in->seek(offset, whence));
+
return SIGNAL_REG;
}
+void DirSeeker::addAsVirtualFiles(Common::String title, Common::String fileMask) {
+ Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
+ Common::StringArray foundFiles = saveFileMan->listSavefiles(fileMask);
+ if (!foundFiles.empty()) {
+ _files.push_back(title);
+ _virtualFiles.push_back("");
+ Common::StringArray::iterator it;
+ Common::StringArray::iterator it_end = foundFiles.end();
+
+ for (it = foundFiles.begin(); it != it_end; it++) {
+ Common::String regularFilename = *it;
+ Common::String wrappedFilename = Common::String(regularFilename.c_str() + fileMask.size() - 1);
+
+ Common::SeekableReadStream *testfile = saveFileMan->openForLoading(regularFilename);
+ int32 testfileSize = testfile->size();
+ delete testfile;
+ if (testfileSize > 1024) // check, if larger than 1k. in that case its a saved game.
+ continue; // and we dont want to have those in the list
+ // We need to remove the prefix for display purposes
+ _files.push_back(wrappedFilename);
+ // but remember the actual name as well
+ _virtualFiles.push_back(regularFilename);
+ }
+ }
+}
+
+Common::String DirSeeker::getVirtualFilename(uint fileNumber) {
+ if (fileNumber >= _virtualFiles.size())
+ error("invalid virtual filename access");
+ return _virtualFiles[fileNumber];
+}
+
+reg_t DirSeeker::firstFile(const Common::String &mask, reg_t buffer, SegManager *segMan) {
+ // Verify that we are given a valid buffer
+ if (!buffer.segment) {
+ error("DirSeeker::firstFile('%s') invoked with invalid buffer", mask.c_str());
+ return NULL_REG;
+ }
+ _outbuffer = buffer;
+ _files.clear();
+ _virtualFiles.clear();
+
+ int QfGImport = g_sci->inQfGImportRoom();
+ if (QfGImport) {
+ _files.clear();
+ addAsVirtualFiles("-QfG1-", "qfg1-*");
+ addAsVirtualFiles("-QfG1VGA-", "qfg1vga-*");
+ if (QfGImport > 2)
+ addAsVirtualFiles("-QfG2-", "qfg2-*");
+ if (QfGImport > 3)
+ addAsVirtualFiles("-QfG3-", "qfg3-*");
+
+ if (QfGImport == 3) {
+ // QfG3 sorts the filelisting itself, we can't let that happen otherwise our
+ // virtual list would go out-of-sync
+ reg_t savedHeros = segMan->findObjectByName("savedHeros");
+ if (!savedHeros.isNull())
+ writeSelectorValue(segMan, savedHeros, SELECTOR(sort), 0);
+ }
+
+ } else {
+ // Prefix the mask
+ const Common::String wrappedMask = g_sci->wrapFilename(mask);
+
+ // Obtain a list of all files matching the given mask
+ Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
+ _files = saveFileMan->listSavefiles(wrappedMask);
+ }
+
+ // Reset the list iterator and write the first match to the output buffer,
+ // if any.
+ _iter = _files.begin();
+ return nextFile(segMan);
+}
+
+reg_t DirSeeker::nextFile(SegManager *segMan) {
+ if (_iter == _files.end()) {
+ return NULL_REG;
+ }
+
+ Common::String string;
+
+ if (_virtualFiles.empty()) {
+ // Strip the prefix, if we don't got a virtual filelisting
+ const Common::String wrappedString = *_iter;
+ string = g_sci->unwrapFilename(wrappedString);
+ } else {
+ string = *_iter;
+ }
+ if (string.size() > 12)
+ string = Common::String(string.c_str(), 12);
+ segMan->strcpy(_outbuffer, string.c_str());
+
+ // Return the result and advance the list iterator :)
+ ++_iter;
+ return _outbuffer;
+}
+
reg_t kFileIOFindFirst(EngineState *s, int argc, reg_t *argv) {
Common::String mask = s->_segMan->getString(argv[0]);
reg_t buf = argv[1];
int attr = argv[2].toUint16(); // We won't use this, Win32 might, though...
debugC(2, kDebugLevelFile, "kFileIO(findFirst): %s, 0x%x", mask.c_str(), attr);
- // QfG3 uses "/\*.*" for the character import, QfG4 uses "/\*"
- if (mask.hasPrefix("/\\")) {
- mask.deleteChar(0);
- mask.deleteChar(0);
- }
-
// We remove ".*". mask will get prefixed, so we will return all additional files for that gameid
if (mask == "*.*")
mask = "*";
@@ -960,7 +1097,7 @@ reg_t kFileIOWriteByte(EngineState *s, int argc, reg_t *argv) {
FileHandle *f = getFileFromHandle(s, argv[0].toUint16());
if (f)
f->_out->writeByte(argv[1].toUint16() & 0xff);
- return s->r_acc; // FIXME: does this really doesn't return anything?
+ return s->r_acc; // FIXME: does this really not return anything?
}
reg_t kFileIOReadWord(EngineState *s, int argc, reg_t *argv) {
@@ -974,7 +1111,7 @@ reg_t kFileIOWriteWord(EngineState *s, int argc, reg_t *argv) {
FileHandle *f = getFileFromHandle(s, argv[0].toUint16());
if (f)
f->_out->writeUint16LE(argv[1].toUint16());
- return s->r_acc; // FIXME: does this really doesn't return anything?
+ return s->r_acc; // FIXME: does this really not return anything?
}
reg_t kCD(EngineState *s, int argc, reg_t *argv) {
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index a3f7a90da3..07385fd3f9 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -57,48 +57,46 @@
namespace Sci {
-void _k_dirloop(reg_t object, uint16 angle, EngineState *s, int argc, reg_t *argv) {
+void showScummVMDialog(const Common::String &message) {
+ GUI::MessageDialog dialog(message, "OK");
+ dialog.runModal();
+}
+
+void kDirLoopWorker(reg_t object, uint16 angle, EngineState *s, int argc, reg_t *argv) {
GuiResourceId viewId = readSelectorValue(s->_segMan, object, SELECTOR(view));
uint16 signal = readSelectorValue(s->_segMan, object, SELECTOR(signal));
- int16 loopNo;
- int16 maxLoops;
- bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
if (signal & kSignalDoesntTurn)
return;
- angle %= 360;
-
- if (!oldScriptHeader) {
- if (angle < 45)
- loopNo = 3;
- else if (angle < 136)
- loopNo = 0;
- else if (angle < 225)
- loopNo = 2;
- else if (angle < 316)
- loopNo = 1;
- else
- loopNo = 3;
+ int16 useLoop = -1;
+ if (getSciVersion() > SCI_VERSION_0_EARLY) {
+ if ((angle > 315) || (angle < 45)) {
+ useLoop = 3;
+ } else if ((angle > 135) && (angle < 225)) {
+ useLoop = 2;
+ }
} else {
- if (angle >= 330 || angle <= 30)
- loopNo = 3;
- else if (angle <= 150)
- loopNo = 0;
- else if (angle <= 210)
- loopNo = 2;
- else if (angle < 330)
- loopNo = 1;
- else loopNo = -1;
+ // SCI0EARLY
+ if ((angle > 330) || (angle < 30)) {
+ useLoop = 3;
+ } else if ((angle > 150) && (angle < 210)) {
+ useLoop = 2;
+ }
+ }
+ if (useLoop == -1) {
+ if (angle >= 180) {
+ useLoop = 1;
+ } else {
+ useLoop = 0;
+ }
+ } else {
+ int16 loopCount = g_sci->_gfxCache->kernelViewGetLoopCount(viewId);
+ if (loopCount < 4)
+ return;
}
- maxLoops = g_sci->_gfxCache->kernelViewGetLoopCount(viewId);
-
-
- if ((loopNo > 1) && (maxLoops < 4))
- return;
-
- writeSelectorValue(s->_segMan, object, SELECTOR(loop), loopNo);
+ writeSelectorValue(s->_segMan, object, SELECTOR(loop), useLoop);
}
static reg_t kSetCursorSci0(EngineState *s, int argc, reg_t *argv) {
@@ -131,8 +129,7 @@ static reg_t kSetCursorSci11(EngineState *s, int argc, reg_t *argv) {
g_sci->_gfxCursor->kernelHide();
break;
case -1:
- // TODO: Special case at least in kq6, check disassembly
- // Does something with magCursor, which is set on argc = 10, which we don't support
+ g_sci->_gfxCursor->kernelClearZoomZone();
break;
case -2:
g_sci->_gfxCursor->kernelResetMoveZone();
@@ -186,15 +183,10 @@ static reg_t kSetCursorSci11(EngineState *s, int argc, reg_t *argv) {
break;
case 10:
// Freddy pharkas, when using the whiskey glass to read the prescription (bug #3034973)
- // magnifier support, disabled using argc == 1, argv == -1
- warning("kSetCursor: unsupported magnifier");
- // we just set the view cursor currently
- g_sci->_gfxCursor->kernelSetView(argv[5].toUint16(), argv[6].toUint16(), argv[7].toUint16(), hotspot);
- // argv[0] -> 1, 2, 4 -> maybe magnification multiplier
- // argv[1-4] -> rect for magnification
- // argv[5, 6, 7] -> view resource for cursor
- // argv[8] -> picture resource for mag
- // argv[9] -> color for magnifier replacement
+ g_sci->_gfxCursor->kernelSetZoomZone(argv[0].toUint16(),
+ Common::Rect(argv[1].toUint16(), argv[2].toUint16(), argv[3].toUint16(), argv[4].toUint16()),
+ argv[5].toUint16(), argv[6].toUint16(), argv[7].toUint16(),
+ argv[8].toUint16(), argv[9].toUint16());
break;
default :
error("kSetCursor: Unhandled case: %d arguments given", argc);
@@ -264,7 +256,9 @@ reg_t kGraphDrawLine(EngineState *s, int argc, reg_t *argv) {
int16 priority = (argc > 5) ? argv[5].toSint16() : -1;
int16 control = (argc > 6) ? argv[6].toSint16() : -1;
- // TODO: Find out why we get >15 for color in EGA
+ // TODO: Find out why we get > 15 for color in EGA
+ // FIXME: EGA? Which EGA? SCI0 or SCI1? Check the
+ // workarounds inside kGraphFillBoxAny and kNewWindow
if (!g_sci->getResMan()->isVGA() && !g_sci->getResMan()->isAmiga32color())
color &= 0x0F;
@@ -303,6 +297,13 @@ reg_t kGraphFillBoxAny(EngineState *s, int argc, reg_t *argv) {
int16 priority = argv[6].toSint16(); // yes, we may read from stack sometimes here
int16 control = argv[7].toSint16(); // sierra did the same
+ // WORKAROUND: PQ3 EGA is setting invalid colors (above 0 - 15).
+ // Colors above 15 are all white in SCI1 EGA games, which is why this was never
+ // observed. We clip them all to (0, 15) instead, as colors above 15 are used
+ // for the undithering algorithm in EGA games - bug #3048908.
+ if (g_sci->getResMan()->getViewType() == kViewEga && getSciVersion() >= SCI_VERSION_1_EARLY)
+ color &= 0x0F;
+
g_sci->_gfxPaint16->kernelGraphFillBox(rect, colorMask, color, priority, control);
return s->r_acc;
}
@@ -397,7 +398,7 @@ reg_t kPriCoord(EngineState *s, int argc, reg_t *argv) {
}
reg_t kDirLoop(EngineState *s, int argc, reg_t *argv) {
- _k_dirloop(argv[0], argv[1].toUint16(), s, argc, argv);
+ kDirLoopWorker(argv[0], argv[1].toUint16(), s, argc, argv);
return s->r_acc;
}
@@ -801,6 +802,7 @@ void _k_GenericDrawControl(EngineState *s, reg_t controlObject, bool hilite) {
alignment = readSelectorValue(s->_segMan, controlObject, SELECTOR(mode));
debugC(2, kDebugLevelGraphics, "drawing text %04x:%04x ('%s') to %d,%d, mode=%d", PRINT_REG(controlObject), text.c_str(), x, y, alignment);
g_sci->_gfxControls->kernelDrawText(rect, controlObject, g_sci->strSplit(text.c_str()).c_str(), fontId, alignment, style, hilite);
+ s->r_acc = g_sci->_gfxText16->allocAndFillReferenceRectArray();
return;
case SCI_CONTROLS_TYPE_TEXTEDIT:
@@ -896,6 +898,10 @@ reg_t kDrawControl(EngineState *s, int argc, reg_t *argv) {
reg_t controlObject = argv[0];
Common::String objName = s->_segMan->getObjectName(controlObject);
+ // Most of the time, we won't return anything to the caller
+ // but |r| textcodes will trigger creation of rects in memory and will then set s->r_acc
+ s->r_acc = NULL_REG;
+
// Disable the "Change Directory" button, as we don't allow the game engine to
// change the directory where saved games are placed
// "changeDirItem" is used in the import windows of QFG2&3
@@ -922,20 +928,19 @@ reg_t kDrawControl(EngineState *s, int argc, reg_t *argv) {
if (!changeDirButton.isNull()) {
// check if checkDirButton is still enabled, in that case we are called the first time during that room
if (!(readSelectorValue(s->_segMan, changeDirButton, SELECTOR(state)) & SCI_CONTROLS_STYLE_DISABLED)) {
- GUI::MessageDialog dialog("Characters saved inside ScummVM are shown "
+ showScummVMDialog("Characters saved inside ScummVM are shown "
"automatically. Character files saved in the original "
"interpreter need to be put inside ScummVM's saved games "
"directory and a prefix needs to be added depending on which "
"game it was saved in: 'qfg1-' for Quest for Glory 1, 'qfg2-' "
- "for Quest for Glory 2. Example: 'qfg2-thief.sav'.",
- "OK");
- dialog.runModal();
+ "for Quest for Glory 2. Example: 'qfg2-thief.sav'.");
}
}
+ s->_chosenQfGImportItem = readSelectorValue(s->_segMan, controlObject, SELECTOR(mark));
}
_k_GenericDrawControl(s, controlObject, false);
- return NULL_REG;
+ return s->r_acc;
}
reg_t kHiliteControl(EngineState *s, int argc, reg_t *argv) {
@@ -1078,6 +1083,15 @@ reg_t kNewWindow(EngineState *s, int argc, reg_t *argv) {
int colorPen = (argc > 7 + argextra) ? argv[7 + argextra].toSint16() : 0;
int colorBack = (argc > 8 + argextra) ? argv[8 + argextra].toSint16() : 255;
+ // WORKAROUND: PQ3 EGA is setting invalid colors (above 0 - 15).
+ // Colors above 15 are all white in SCI1 EGA games, which is why this was never
+ // observed. We clip them all to (0, 15) instead, as colors above 15 are used
+ // for the undithering algorithm in EGA games - bug #3048908.
+ if (g_sci->getResMan()->getViewType() == kViewEga && getSciVersion() >= SCI_VERSION_1_EARLY) {
+ colorPen &= 0x0F;
+ colorBack &= 0x0F;
+ }
+
// const char *title = argv[4 + argextra].segment ? kernel_dereference_char_pointer(s, argv[4 + argextra], 0) : NULL;
if (argc>=13) {
rect2 = Common::Rect (argv[5].toSint16(), argv[4].toSint16(), argv[7].toSint16(), argv[6].toSint16());
@@ -1152,6 +1166,81 @@ reg_t kTextColors(EngineState *s, int argc, reg_t *argv) {
return s->r_acc;
}
+/**
+ * Debug command, used by the SCI builtin debugger
+ */
+reg_t kShow(EngineState *s, int argc, reg_t *argv) {
+ uint16 map = argv[0].toUint16();
+
+ switch (map) {
+ case 1: // Visual, substituted by display for us
+ g_sci->_gfxScreen->debugShowMap(3);
+ break;
+ case 2: // Priority
+ g_sci->_gfxScreen->debugShowMap(1);
+ break;
+ case 3: // Control
+ case 4: // Control
+ g_sci->_gfxScreen->debugShowMap(2);
+ break;
+ default:
+ warning("Map %d is not available", map);
+ }
+
+ return s->r_acc;
+}
+
+reg_t kRemapColors(EngineState *s, int argc, reg_t *argv) {
+ // TODO: This is all a stub/skeleton, thus we're invoking kStub() for now
+ kStub(s, argc, argv);
+
+ uint16 operation = argv[0].toUint16();
+
+ switch (operation) {
+ case 0: { // Initialize remapping to base. 0 turns remapping off.
+ //int16 unk1 = (argc >= 2) ? argv[1].toSint16() : 0;
+ }
+ break;
+ case 1: { // unknown
+ // The demo of QFG4 calls this with 1+3 parameters, thus there are differences here
+ //int16 unk1 = argv[1].toSint16();
+ //int16 unk2 = argv[2].toSint16();
+ //int16 unk3 = argv[3].toSint16();
+ //uint16 unk4 = argv[4].toUint16();
+ //uint16 unk5 = (argc >= 6) ? argv[5].toUint16() : 0;
+ }
+ break;
+ case 2: { // remap by percent
+ //int16 unk1 = argv[1].toSint16();
+ //uint16 percent = argv[2].toUint16();
+ //uint16 unk3 = (argc >= 4) ? argv[3].toUint16() : 0;
+ }
+ break;
+ case 3: { // remap to gray
+ //int16 unk1 = argv[1].toSint16();
+ //int16 percent = argv[2].toSint16(); // 0 - 100
+ //uint16 unk3 = (argc >= 4) ? argv[3].toUint16() : 0;
+ }
+ break;
+ case 4: { // unknown
+ //int16 unk1 = argv[1].toSint16();
+ //uint16 unk2 = argv[2].toUint16();
+ //uint16 unk3 = argv[3].toUint16();
+ //uint16 unk4 = (argc >= 5) ? argv[4].toUint16() : 0;
+ }
+ break;
+ case 5: { // increment color
+ //int16 unk1 = argv[1].toSint16();
+ //uint16 unk2 = argv[2].toUint16();
+ }
+ break;
+ default:
+ break;
+ }
+
+ return s->r_acc;
+}
+
#ifdef ENABLE_SCI32
reg_t kIsHiRes(EngineState *s, int argc, reg_t *argv) {
@@ -1172,69 +1261,38 @@ reg_t kCantBeHere32(EngineState *s, int argc, reg_t *argv) {
}
reg_t kAddScreenItem(EngineState *s, int argc, reg_t *argv) {
- reg_t viewObj = argv[0];
-
- g_sci->_gfxFrameout->kernelAddScreenItem(viewObj);
- return NULL_REG;
+ g_sci->_gfxFrameout->kernelAddScreenItem(argv[0]);
+ return s->r_acc;
}
reg_t kUpdateScreenItem(EngineState *s, int argc, reg_t *argv) {
- //reg_t viewObj = argv[0];
-
- //warning("kUpdateScreenItem, object %04x:%04x, view %d, loop %d, cel %d, pri %d", PRINT_REG(viewObj), viewId, loopNo, celNo, priority);
- return NULL_REG;
+ g_sci->_gfxFrameout->kernelUpdateScreenItem(argv[0]);
+ return s->r_acc;
}
reg_t kDeleteScreenItem(EngineState *s, int argc, reg_t *argv) {
- reg_t viewObj = argv[0];
-
- g_sci->_gfxFrameout->kernelDeleteScreenItem(viewObj);
-
- /*
- reg_t viewObj = argv[0];
- uint16 viewId = readSelectorValue(s->_segMan, viewObj, SELECTOR(view));
- int16 loopNo = readSelectorValue(s->_segMan, viewObj, SELECTOR(loop));
- int16 celNo = readSelectorValue(s->_segMan, viewObj, SELECTOR(cel));
- //int16 leftPos = 0;
- //int16 topPos = 0;
- int16 priority = readSelectorValue(s->_segMan, viewObj, SELECTOR(priority));
- //int16 control = 0;
- */
-
- // TODO
-
- //warning("kDeleteScreenItem, view %d, loop %d, cel %d, pri %d", viewId, loopNo, celNo, priority);
- return NULL_REG;
+ g_sci->_gfxFrameout->kernelDeleteScreenItem(argv[0]);
+ return s->r_acc;
}
reg_t kAddPlane(EngineState *s, int argc, reg_t *argv) {
- reg_t planeObj = argv[0];
-
- g_sci->_gfxFrameout->kernelAddPlane(planeObj);
- return NULL_REG;
+ g_sci->_gfxFrameout->kernelAddPlane(argv[0]);
+ return s->r_acc;
}
reg_t kDeletePlane(EngineState *s, int argc, reg_t *argv) {
- reg_t planeObj = argv[0];
-
- g_sci->_gfxFrameout->kernelDeletePlane(planeObj);
- return NULL_REG;
+ g_sci->_gfxFrameout->kernelDeletePlane(argv[0]);
+ return s->r_acc;
}
reg_t kUpdatePlane(EngineState *s, int argc, reg_t *argv) {
- reg_t planeObj = argv[0];
-
- g_sci->_gfxFrameout->kernelUpdatePlane(planeObj);
+ g_sci->_gfxFrameout->kernelUpdatePlane(argv[0]);
return s->r_acc;
}
reg_t kRepaintPlane(EngineState *s, int argc, reg_t *argv) {
- reg_t picObj = argv[0];
-
- // TODO
-
- warning("kRepaintPlane object %04x:%04x", PRINT_REG(picObj));
- return NULL_REG;
+ g_sci->_gfxFrameout->kernelRepaintPlane(argv[0]);
+ return s->r_acc;
}
reg_t kAddPicAt(EngineState *s, int argc, reg_t *argv) {
@@ -1261,9 +1319,8 @@ reg_t kFrameOut(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
}
-reg_t kOnMe(EngineState *s, int argc, reg_t *argv) {
- // Tests if the cursor is on the passed object
-
+// Tests if the coordinate is on the passed object
+reg_t kIsOnMe(EngineState *s, int argc, reg_t *argv) {
uint16 x = argv[0].toUint16();
uint16 y = argv[1].toUint16();
reg_t targetObject = argv[2];
@@ -1296,75 +1353,9 @@ reg_t kOnMe(EngineState *s, int argc, reg_t *argv) {
if (g_sci->_gfxCompare->kernelIsItSkip(viewId, loopNo, celNo, Common::Point(x - nsRect.left, y - nsRect.top)))
contained = false;
}
-// these hacks shouldn't be needed anymore
-// uint16 itemX = readSelectorValue(s->_segMan, targetObject, SELECTOR(x));
-// uint16 itemY = readSelectorValue(s->_segMan, targetObject, SELECTOR(y));
-
- // If top and left are negative, we need to adjust coordinates by
- // the item's x and y (e.g. happens in GK1, day 1, with detective
- // Mosely's hotspot in his office)
-
-// if (nsRect.left < 0)
-// nsRect.translate(itemX, 0);
-//
-// if (nsRect.top < 0)
-// nsRect.translate(0, itemY);
-
-// // HACK: nsLeft and nsTop can be invalid, so try and fix them here
-// // using x and y (e.g. with the inventory screen in GK1)
-// if (nsRect.left == itemY && nsRect.top == itemX) {
-// // Swap the values, as they're inversed (eh???)
-// nsRect.left = itemX;
-// nsRect.top = itemY;
-// }
-
return make_reg(0, contained);
}
-reg_t kIsOnMe(EngineState *s, int argc, reg_t *argv) {
- // Tests if the cursor is on the passed object, after adjusting the
- // coordinates of the object according to the object's plane
-
- uint16 x = argv[0].toUint16();
- uint16 y = argv[1].toUint16();
- reg_t targetObject = argv[2];
- // TODO: argv[3] - it's usually 0
- Common::Rect nsRect;
-
- // Get the bounding rectangle of the object
- nsRect.left = readSelectorValue(s->_segMan, targetObject, SELECTOR(nsLeft));
- nsRect.top = readSelectorValue(s->_segMan, targetObject, SELECTOR(nsTop));
- nsRect.right = readSelectorValue(s->_segMan, targetObject, SELECTOR(nsRight));
- nsRect.bottom = readSelectorValue(s->_segMan, targetObject, SELECTOR(nsBottom));
-
- // Get the object's plane
-#if 0
- reg_t planeObject = readSelector(s->_segMan, targetObject, SELECTOR(plane));
- if (!planeObject.isNull()) {
- //uint16 itemX = readSelectorValue(s->_segMan, targetObject, SELECTOR(x));
- //uint16 itemY = readSelectorValue(s->_segMan, targetObject, SELECTOR(y));
- uint16 planeResY = readSelectorValue(s->_segMan, planeObject, SELECTOR(resY));
- uint16 planeResX = readSelectorValue(s->_segMan, planeObject, SELECTOR(resX));
- uint16 planeTop = readSelectorValue(s->_segMan, planeObject, SELECTOR(top));
- uint16 planeLeft = readSelectorValue(s->_segMan, planeObject, SELECTOR(left));
- planeTop = (planeTop * g_sci->_gfxScreen->getHeight()) / planeResY;
- planeLeft = (planeLeft * g_sci->_gfxScreen->getWidth()) / planeResX;
-
- // Adjust the bounding rectangle of the object by the object's
- // actual X, Y coordinates
- nsRect.top = ((nsRect.top * g_sci->_gfxScreen->getHeight()) / planeResY);
- nsRect.left = ((nsRect.left * g_sci->_gfxScreen->getWidth()) / planeResX);
- nsRect.bottom = ((nsRect.bottom * g_sci->_gfxScreen->getHeight()) / planeResY);
- nsRect.right = ((nsRect.right * g_sci->_gfxScreen->getWidth()) / planeResX);
-
- nsRect.translate(planeLeft, planeTop);
- }
-#endif
- //warning("kIsOnMe: (%d, %d) on object %04x:%04x, parameter %d", argv[0].toUint16(), argv[1].toUint16(), PRINT_REG(argv[2]), argv[3].toUint16());
-
- return make_reg(0, nsRect.contains(x, y));
-}
-
reg_t kCreateTextBitmap(EngineState *s, int argc, reg_t *argv) {
// TODO: argument 0 is usually 0, and arguments 1 and 2 are usually 1
switch (argv[0].toUint16()) {
@@ -1421,6 +1412,61 @@ reg_t kRobot(EngineState *s, int argc, reg_t *argv) {
return s->r_acc;
}
+reg_t kGetWindowsOption(EngineState *s, int argc, reg_t *argv) {
+ uint16 windowsOption = argv[0].toUint16();
+ switch (windowsOption) {
+ case 0:
+ // Title bar on/off in Phantasmagoria, we return 0 (off)
+ return NULL_REG;
+ default:
+ warning("GetWindowsOption: Unknown option %d", windowsOption);
+ return NULL_REG;
+ }
+}
+
+reg_t kWinHelp(EngineState *s, int argc, reg_t *argv) {
+ switch (argv[0].toUint16()) {
+ case 1:
+ // Load a help file
+ // Maybe in the future we can implement this, but for now this message should suffice
+ showScummVMDialog("Please use an external viewer to open the game's help file: " + s->_segMan->getString(argv[1]));
+ break;
+ case 2:
+ // Looks like some init function
+ break;
+ default:
+ warning("Unknown kWinHelp subop %d", argv[0].toUint16());
+ }
+
+ return s->r_acc;
+}
+
+/**
+ * Used to programmatically mass set properties of the target plane
+ */
+reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv) {
+ // TODO: This is all a stub/skeleton, thus we're invoking kStub() for now
+ kStub(s, argc, argv);
+
+ // showStyle matches the style selector of the associated plane object
+ uint16 showStyle = argv[0].toUint16(); // 0 - 15
+ reg_t planeObj = argv[1];
+ //argv[2]
+ //int16 priority = argv[3].toSint16();
+ //argv[4]
+ //argv[5]
+ //argv[6]
+ //argv[7]
+ //int16 unk8 = (argc >= 9) ? argv[8].toSint16() : 0;
+
+ if (showStyle > 15) {
+ warning("kSetShowStyle: Illegal style %d for plane %04x:%04x", showStyle, PRINT_REG(planeObj));
+ return s->r_acc;
+ }
+
+ return s->r_acc;
+}
+
#endif
} // End of namespace Sci
diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp
index 93e95099f5..2188087b8c 100644
--- a/engines/sci/engine/klists.cpp
+++ b/engines/sci/engine/klists.cpp
@@ -40,6 +40,9 @@ static bool isSaneNodePointer(SegManager *segMan, reg_t addr) {
if ((g_sci->getGameId() == GID_ICEMAN) && (g_sci->getEngineState()->currentRoomNumber() == 40)) {
// ICEMAN: when plotting course, unDrawLast is called by startPlot::changeState
// there is no previous entry so we get 0 in here
+ } else if ((g_sci->getGameId() == GID_HOYLE1) && (g_sci->getEngineState()->currentRoomNumber() == 3)) {
+ // HOYLE1: after sorting cards in hearts, in the next round
+ // we get an invalid node - bug #3038433
} else {
error("isSaneNodePointer: Node at %04x:%04x wasn't found", PRINT_REG(addr));
}
diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp
index 332fbb62f8..792181b832 100644
--- a/engines/sci/engine/kmath.cpp
+++ b/engines/sci/engine/kmath.cpp
@@ -35,19 +35,21 @@ reg_t kRandom(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
case 2: { // get random number
- int fromNumber = argv[0].toUint16();
- int toNumber = argv[1].toUint16();
-
- // TODO/CHECKME: It is propbably not required to check whether
- // toNumber is greater than fromNumber, at least not when one
- // goes by their names, but let us be on the safe side and
- // allow toNumber to be smaller than fromNumber too.
- if (fromNumber > toNumber)
- SWAP(fromNumber, toNumber);
-
- const uint diff = (uint)(toNumber - fromNumber);
-
- const int randomNumber = fromNumber + (int)g_sci->getRNG().getRandomNumber(diff);
+ // numbers are definitely unsigned, for example lsl5 door code in k rap radio is random
+ // and 5-digit - we get called kRandom(10000, 65000)
+ // some codes in sq4 are also random and 5 digit (if i remember correctly)
+ const uint16 fromNumber = argv[0].toUint16();
+ const uint16 toNumber = argv[1].toUint16();
+ uint16 range = toNumber - fromNumber + 1;
+ // calculating range is exactly how sierra sci did it and is required for hoyle 4
+ // where we get called with kRandom(0, -1) and we are supposed to give back values from 0 to 0
+ // the returned value will be used as displace-offset for a background cel
+ // note: i assume that the hoyle4 code is actually buggy and it was never fixed because of
+ // the way sierra sci handled it - "it just worked". It should have called kRandom(0, 0)
+ if (range)
+ range--; // the range value was never returned, our random generator gets 0->range, so fix it
+
+ const int randomNumber = fromNumber + (int)g_sci->getRNG().getRandomNumber(range);
return make_reg(0, randomNumber);
}
@@ -70,30 +72,24 @@ reg_t kSqrt(EngineState *s, int argc, reg_t *argv) {
return make_reg(0, (int16) sqrt((float) ABS(argv[0].toSint16())));
}
-reg_t kGetAngle(EngineState *s, int argc, reg_t *argv) {
- // Based on behavior observed with a test program created with
- // SCI Studio.
- int x1 = argv[0].toSint16();
- int y1 = argv[1].toSint16();
- int x2 = argv[2].toSint16();
- int y2 = argv[3].toSint16();
- int xrel = x2 - x1;
- int yrel = y1 - y2; // y-axis is mirrored.
- int angle;
+uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) {
+ int16 xRel = x2 - x1;
+ int16 yRel = y1 - y2; // y-axis is mirrored.
+ int16 angle;
// Move (xrel, yrel) to first quadrant.
if (y1 < y2)
- yrel = -yrel;
+ yRel = -yRel;
if (x2 < x1)
- xrel = -xrel;
+ xRel = -xRel;
// Compute angle in grads.
- if (yrel == 0 && xrel == 0)
- angle = 0;
+ if (yRel == 0 && xRel == 0)
+ return 0;
else
- angle = 100 * xrel / (xrel + yrel);
+ angle = 100 * xRel / (xRel + yRel);
- // Fix up angle for actual quadrant of (xrel, yrel).
+ // Fix up angle for actual quadrant of (xRel, yRel).
if (y1 < y2)
angle = 200 - angle;
if (x2 < x1)
@@ -103,8 +99,18 @@ reg_t kGetAngle(EngineState *s, int argc, reg_t *argv) {
// grad 10 with grad 11, grad 20 with grad 21, etc. This leads to
// "degrees" that equal either one or two grads.
angle -= (angle + 9) / 10;
+ return angle;
+}
+
+reg_t kGetAngle(EngineState *s, int argc, reg_t *argv) {
+ // Based on behavior observed with a test program created with
+ // SCI Studio.
+ int x1 = argv[0].toSint16();
+ int y1 = argv[1].toSint16();
+ int x2 = argv[2].toSint16();
+ int y2 = argv[3].toSint16();
- return make_reg(0, angle);
+ return make_reg(0, kGetAngleWorker(x1, y1, x2, y2));
}
reg_t kGetDistance(EngineState *s, int argc, reg_t *argv) {
diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp
index c8a6e03556..428c27ca73 100644
--- a/engines/sci/engine/kmenu.cpp
+++ b/engines/sci/engine/kmenu.cpp
@@ -46,12 +46,13 @@ reg_t kSetMenu(EngineState *s, int argc, reg_t *argv) {
uint16 itemId = argv[0].toUint16() & 0xFF;
uint16 attributeId;
int argPos = 1;
+ reg_t value;
while (argPos < argc) {
attributeId = argv[argPos].toUint16();
- if ((argPos + 1) >= argc)
- error("Too few parameters for kSetMenu");
- g_sci->_gfxMenu->kernelSetAttribute(menuId, itemId, attributeId, argv[argPos + 1]);
+ // Happens in the fanmade game Cascade Quest when loading - bug #3038767
+ value = (argPos + 1 < argc) ? argv[argPos + 1] : NULL_REG;
+ g_sci->_gfxMenu->kernelSetAttribute(menuId, itemId, attributeId, value);
argPos += 2;
}
return s->r_acc;
@@ -76,6 +77,11 @@ reg_t kDrawStatus(EngineState *s, int argc, reg_t *argv) {
// Sometimes this is called without giving text, if thats the case dont process it.
text = s->_segMan->getString(textReference);
+ if (text == "Replaying sound") {
+ // Happens in the fanmade game Cascade Quest when loading - ignore it
+ return s->r_acc;
+ }
+
g_sci->_gfxMenu->kernelDrawStatus(g_sci->strSplit(text.c_str(), NULL).c_str(), colorPen, colorBack);
}
return s->r_acc;
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index fbe20410de..d8ae1a3418 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -188,7 +188,9 @@ reg_t kGetTime(EngineState *s, int argc, reg_t *argv) {
int mode = (argc > 0) ? argv[0].toUint16() : 0;
- if (getSciVersion() <= SCI_VERSION_0_LATE && mode > 1)
+ // Modes 2 and 3 are supported since 0.629.
+ // This condition doesn't check that exactly, but close enough.
+ if (getSciVersion() == SCI_VERSION_0_EARLY && mode > 1)
error("kGetTime called in SCI0 with mode %d (expected 0 or 1)", mode);
switch (mode) {
@@ -387,6 +389,18 @@ reg_t kPlatform(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
}
+#ifdef ENABLE_SCI32
+reg_t kWinDLL(EngineState *s, int argc, reg_t *argv) {
+ kStub(s, argc, argv);
+
+ // TODO: This seems to be loading and calling Windows DLLs. We'll probably
+ // need to either ignore calls made here, or wire each call for each game
+ // that requests it by hand
+
+ error("kWinDLL called");
+}
+#endif
+
reg_t kEmpty(EngineState *s, int argc, reg_t *argv) {
// Placeholder for empty kernel functions which are still called from the
// engine scripts (like the empty kSetSynonyms function in SCI1.1). This
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index 8c43a35fea..db54705694 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -129,7 +129,7 @@ reg_t kSetJump(EngineState *s, int argc, reg_t *argv) {
// Compute x step
if (tmp != 0)
- vx = (int)(dx * sqrt(gy / (2.0 * tmp)));
+ vx = (int16)((float)(dx * sqrt(gy / (2.0 * tmp))));
else
vx = 0;
@@ -145,7 +145,7 @@ reg_t kSetJump(EngineState *s, int argc, reg_t *argv) {
// FIXME: This choice of vy makes t roughly (2+sqrt(2))/gy * sqrt(dy);
// so if gy==3, then t is roughly sqrt(dy)...
- vy = (int)sqrt((double)gy * ABS(2 * dy)) + 1;
+ vy = (int)sqrt((float)gy * ABS(2 * dy)) + 1;
} else {
// As stated above, the vertical direction is correlated to the horizontal by the
// (non-zero) factor c.
@@ -166,230 +166,345 @@ reg_t kSetJump(EngineState *s, int argc, reg_t *argv) {
return s->r_acc;
}
-#define _K_BRESEN_AXIS_X 0
-#define _K_BRESEN_AXIS_Y 1
-
-static void initialize_bresen(SegManager *segMan, int argc, reg_t *argv, reg_t mover, int step_factor, int deltax, int deltay) {
- reg_t client = readSelector(segMan, mover, SELECTOR(client));
- int stepx = (int16)readSelectorValue(segMan, client, SELECTOR(xStep)) * step_factor;
- int stepy = (int16)readSelectorValue(segMan, client, SELECTOR(yStep)) * step_factor;
- int numsteps_x = stepx ? (ABS(deltax) + stepx - 1) / stepx : 0;
- int numsteps_y = stepy ? (ABS(deltay) + stepy - 1) / stepy : 0;
- int bdi, i1;
- int numsteps;
- int deltax_step;
- int deltay_step;
-
- if (numsteps_x > numsteps_y) {
- numsteps = numsteps_x;
- deltax_step = (deltax < 0) ? -stepx : stepx;
- deltay_step = numsteps ? deltay / numsteps : deltay;
- } else { // numsteps_x <= numsteps_y
- numsteps = numsteps_y;
- deltay_step = (deltay < 0) ? -stepy : stepy;
- deltax_step = numsteps ? deltax / numsteps : deltax;
- }
-
-/* if (ABS(deltax) > ABS(deltay)) {*/ // Bresenham on y
- if (numsteps_y < numsteps_x) {
-
- writeSelectorValue(segMan, mover, SELECTOR(b_xAxis), _K_BRESEN_AXIS_Y);
- writeSelectorValue(segMan, mover, SELECTOR(b_incr), (deltay < 0) ? -1 : 1);
- //i1 = 2 * (ABS(deltay) - ABS(deltay_step * numsteps)) * ABS(deltax_step);
- //bdi = -ABS(deltax);
- i1 = 2 * (ABS(deltay) - ABS(deltay_step * (numsteps - 1))) * ABS(deltax_step);
- bdi = -ABS(deltax);
- } else { // Bresenham on x
- writeSelectorValue(segMan, mover, SELECTOR(b_xAxis), _K_BRESEN_AXIS_X);
- writeSelectorValue(segMan, mover, SELECTOR(b_incr), (deltax < 0) ? -1 : 1);
- //i1= 2 * (ABS(deltax) - ABS(deltax_step * numsteps)) * ABS(deltay_step);
- //bdi = -ABS(deltay);
- i1 = 2 * (ABS(deltax) - ABS(deltax_step * (numsteps - 1))) * ABS(deltay_step);
- bdi = -ABS(deltay);
-
- }
-
- writeSelectorValue(segMan, mover, SELECTOR(dx), deltax_step);
- writeSelectorValue(segMan, mover, SELECTOR(dy), deltay_step);
-
- debugC(2, kDebugLevelBresen, "Init bresen for mover %04x:%04x: d=(%d,%d)", PRINT_REG(mover), deltax, deltay);
- debugC(2, kDebugLevelBresen, " steps=%d, mv=(%d, %d), i1= %d, i2=%d",
- numsteps, deltax_step, deltay_step, i1, bdi*2);
-
- //writeSelectorValue(segMan, mover, SELECTOR(b_movCnt), numsteps); // Needed for HQ1/Ogre?
- writeSelectorValue(segMan, mover, SELECTOR(b_di), bdi);
- writeSelectorValue(segMan, mover, SELECTOR(b_i1), i1);
- writeSelectorValue(segMan, mover, SELECTOR(b_i2), bdi * 2);
-}
-
reg_t kInitBresen(EngineState *s, int argc, reg_t *argv) {
SegManager *segMan = s->_segMan;
reg_t mover = argv[0];
reg_t client = readSelector(segMan, mover, SELECTOR(client));
+ int16 stepFactor = (argc >= 2) ? argv[1].toUint16() : 1;
+ int16 mover_x = readSelectorValue(segMan, mover, SELECTOR(x));
+ int16 mover_y = readSelectorValue(segMan, mover, SELECTOR(y));
+ int16 client_xStep = readSelectorValue(segMan, client, SELECTOR(xStep)) * stepFactor;
+ int16 client_yStep = readSelectorValue(segMan, client, SELECTOR(yStep)) * stepFactor;
+
+ int16 client_step;
+ if (client_xStep < client_yStep)
+ client_step = client_yStep * 2;
+ else
+ client_step = client_xStep * 2;
+
+ int16 deltaX = mover_x - readSelectorValue(segMan, client, SELECTOR(x));
+ int16 deltaY = mover_y - readSelectorValue(segMan, client, SELECTOR(y));
+ int16 mover_dx = 0;
+ int16 mover_dy = 0;
+ int16 mover_i1 = 0;
+ int16 mover_i2 = 0;
+ int16 mover_di = 0;
+ int16 mover_incr = 0;
+ int16 mover_xAxis = 0;
+
+ while (1) {
+ mover_dx = client_xStep;
+ mover_dy = client_yStep;
+ mover_incr = 1;
+
+ if (ABS(deltaX) >= ABS(deltaY)) {
+ mover_xAxis = 1;
+ if (deltaX < 0)
+ mover_dx = -mover_dx;
+ mover_dy = deltaX ? mover_dx * deltaY / deltaX : 0;
+ mover_i1 = ((mover_dx * deltaY) - (mover_dy * deltaX)) * 2;
+ if (deltaY < 0) {
+ mover_incr = -1;
+ mover_i1 = -mover_i1;
+ }
+ mover_i2 = mover_i1 - (deltaX * 2);
+ mover_di = mover_i1 - deltaX;
+ if (deltaX < 0) {
+ mover_i1 = -mover_i1;
+ mover_i2 = -mover_i2;
+ mover_di = -mover_di;
+ }
+ } else {
+ mover_xAxis = 0;
+ if (deltaY < 0)
+ mover_dy = -mover_dy;
+ mover_dx = deltaY ? mover_dy * deltaX / deltaY : 0;
+ mover_i1 = ((mover_dy * deltaX) - (mover_dx * deltaY)) * 2;
+ if (deltaX < 0) {
+ mover_incr = -1;
+ mover_i1 = -mover_i1;
+ }
+ mover_i2 = mover_i1 - (deltaY * 2);
+ mover_di = mover_i1 - deltaY;
+ if (deltaY < 0) {
+ mover_i1 = -mover_i1;
+ mover_i2 = -mover_i2;
+ mover_di = -mover_di;
+ }
+ break;
+ }
+ if (client_xStep <= client_yStep)
+ break;
+ if (!client_xStep)
+ break;
+ if (client_yStep >= ABS(mover_dy + mover_incr))
+ break;
+
+ client_step--;
+ if (!client_step)
+ error("kInitBresen failed");
+ client_xStep--;
+ }
- int deltax = (int16)readSelectorValue(segMan, mover, SELECTOR(x)) - (int16)readSelectorValue(segMan, client, SELECTOR(x));
- int deltay = (int16)readSelectorValue(segMan, mover, SELECTOR(y)) - (int16)readSelectorValue(segMan, client, SELECTOR(y));
- int step_factor = (argc < 1) ? argv[1].toUint16() : 1;
-
- initialize_bresen(s->_segMan, argc, argv, mover, step_factor, deltax, deltay);
-
+ // set mover
+ writeSelectorValue(segMan, mover, SELECTOR(dx), mover_dx);
+ writeSelectorValue(segMan, mover, SELECTOR(dy), mover_dy);
+ writeSelectorValue(segMan, mover, SELECTOR(b_i1), mover_i1);
+ writeSelectorValue(segMan, mover, SELECTOR(b_i2), mover_i2);
+ writeSelectorValue(segMan, mover, SELECTOR(b_di), mover_di);
+ writeSelectorValue(segMan, mover, SELECTOR(b_incr), mover_incr);
+ writeSelectorValue(segMan, mover, SELECTOR(b_xAxis), mover_xAxis);
return s->r_acc;
}
-#define MOVING_ON_X (((axis == _K_BRESEN_AXIS_X)&&bi1) || dx)
-#define MOVING_ON_Y (((axis == _K_BRESEN_AXIS_Y)&&bi1) || dy)
-
reg_t kDoBresen(EngineState *s, int argc, reg_t *argv) {
SegManager *segMan = s->_segMan;
reg_t mover = argv[0];
reg_t client = readSelector(segMan, mover, SELECTOR(client));
+ bool completed = false;
+ bool handleMoveCount = g_sci->_features->handleMoveCount();
- int x = (int16)readSelectorValue(segMan, client, SELECTOR(x));
- int y = (int16)readSelectorValue(segMan, client, SELECTOR(y));
- int oldx, oldy, destx, desty, dx, dy, bdi, bi1, bi2, movcnt, bdelta, axis;
- uint16 signal = readSelectorValue(segMan, client, SELECTOR(signal));
- int completed = 0;
- int max_movcnt = readSelectorValue(segMan, client, SELECTOR(moveSpeed));
-
- if (getSciVersion() > SCI_VERSION_01)
- signal &= ~kSignalHitObstacle;
-
- writeSelector(segMan, client, SELECTOR(signal), make_reg(0, signal)); // This is a NOP for SCI0
- oldx = x;
- oldy = y;
- destx = (int16)readSelectorValue(segMan, mover, SELECTOR(x));
- desty = (int16)readSelectorValue(segMan, mover, SELECTOR(y));
- dx = (int16)readSelectorValue(segMan, mover, SELECTOR(dx));
- dy = (int16)readSelectorValue(segMan, mover, SELECTOR(dy));
- bdi = (int16)readSelectorValue(segMan, mover, SELECTOR(b_di));
- bi1 = (int16)readSelectorValue(segMan, mover, SELECTOR(b_i1));
- bi2 = (int16)readSelectorValue(segMan, mover, SELECTOR(b_i2));
- movcnt = readSelectorValue(segMan, mover, SELECTOR(b_movCnt));
- bdelta = (int16)readSelectorValue(segMan, mover, SELECTOR(b_incr));
- axis = (int16)readSelectorValue(segMan, mover, SELECTOR(b_xAxis));
-
- if ((getSciVersion() >= SCI_VERSION_1_LATE)) {
- // Mixed-Up Fairy Tales has no xLast/yLast selectors
- if (SELECTOR(xLast) != -1) {
- // save last position into mover
- writeSelectorValue(segMan, mover, SELECTOR(xLast), x);
- writeSelectorValue(segMan, mover, SELECTOR(yLast), y);
- }
+ if (getSciVersion() >= SCI_VERSION_1_EGA) {
+ uint client_signal = readSelectorValue(segMan, client, SELECTOR(signal));
+ writeSelectorValue(segMan, client, SELECTOR(signal), client_signal & ~kSignalHitObstacle);
+ }
+
+ int16 mover_moveCnt = 1;
+ int16 client_moveSpeed = 0;
+ if (handleMoveCount) {
+ mover_moveCnt = readSelectorValue(segMan, mover, SELECTOR(b_movCnt));
+ client_moveSpeed = readSelectorValue(segMan, client, SELECTOR(moveSpeed));
+ mover_moveCnt++;
}
- //printf("movecnt %d, move speed %d\n", movcnt, max_movcnt);
+ if (client_moveSpeed < mover_moveCnt) {
+ mover_moveCnt = 0;
+ int16 client_x = readSelectorValue(segMan, client, SELECTOR(x));
+ int16 client_y = readSelectorValue(segMan, client, SELECTOR(y));
+ int16 client_org_x = client_x;
+ int16 client_org_y = client_y;
+ int16 mover_x = readSelectorValue(segMan, mover, SELECTOR(x));
+ int16 mover_y = readSelectorValue(segMan, mover, SELECTOR(y));
+ int16 mover_xAxis = readSelectorValue(segMan, mover, SELECTOR(b_xAxis));
+ int16 mover_dx = readSelectorValue(segMan, mover, SELECTOR(dx));
+ int16 mover_dy = readSelectorValue(segMan, mover, SELECTOR(dy));
+ int16 mover_incr = readSelectorValue(segMan, mover, SELECTOR(b_incr));
+ int16 mover_i1 = readSelectorValue(segMan, mover, SELECTOR(b_i1));
+ int16 mover_i2 = readSelectorValue(segMan, mover, SELECTOR(b_i2));
+ int16 mover_di = readSelectorValue(segMan, mover, SELECTOR(b_di));
+ int16 mover_org_i1 = mover_i1;
+ int16 mover_org_i2 = mover_i2;
+ int16 mover_org_di = mover_di;
+
+ if ((getSciVersion() >= SCI_VERSION_1_EGA)) {
+ // save current position into mover
+ writeSelectorValue(segMan, mover, SELECTOR(xLast), client_x);
+ writeSelectorValue(segMan, mover, SELECTOR(yLast), client_y);
+ }
+ // sierra sci saves full client selector variables here
- if (g_sci->_features->handleMoveCount()) {
- if (max_movcnt > movcnt) {
- ++movcnt;
- writeSelectorValue(segMan, mover, SELECTOR(b_movCnt), movcnt); // Needed for HQ1/Ogre?
- return NULL_REG;
+ if (mover_xAxis) {
+ if (ABS(mover_x - client_x) < ABS(mover_dx))
+ completed = true;
} else {
- movcnt = 0;
- writeSelectorValue(segMan, mover, SELECTOR(b_movCnt), movcnt); // Needed for HQ1/Ogre?
+ if (ABS(mover_y - client_y) < ABS(mover_dy))
+ completed = true;
+ }
+ if (completed) {
+ client_x = mover_x;
+ client_y = mover_y;
+ } else {
+ client_x += mover_dx;
+ client_y += mover_dy;
+ if (mover_di < 0) {
+ mover_di += mover_i1;
+ } else {
+ mover_di += mover_i2;
+ if (mover_xAxis == 0) {
+ client_x += mover_incr;
+ } else {
+ client_y += mover_incr;
+ }
+ }
+ }
+ writeSelectorValue(segMan, client, SELECTOR(x), client_x);
+ writeSelectorValue(segMan, client, SELECTOR(y), client_y);
+
+ // Now call client::canBeHere/client::cantBehere to check for collisions
+ bool collision = false;
+ reg_t cantBeHere = NULL_REG;
+
+ if (SELECTOR(cantBeHere) != -1) {
+ // adding this here for hoyle 3 to get happy. CantBeHere is a dummy in hoyle 3 and acc is != 0 so we would
+ // get a collision otherwise
+ s->r_acc = NULL_REG;
+ invokeSelector(s, client, SELECTOR(cantBeHere), argc, argv);
+ if (!s->r_acc.isNull())
+ collision = true;
+ cantBeHere = s->r_acc;
+ } else {
+ invokeSelector(s, client, SELECTOR(canBeHere), argc, argv);
+ if (s->r_acc.isNull())
+ collision = true;
}
- }
- if ((bdi += bi1) > 0) {
- bdi += bi2;
+ if (collision) {
+ // sierra restores full client variables here, seems that restoring x/y is enough
+ writeSelectorValue(segMan, client, SELECTOR(x), client_org_x);
+ writeSelectorValue(segMan, client, SELECTOR(y), client_org_y);
+ mover_i1 = mover_org_i1;
+ mover_i2 = mover_org_i2;
+ mover_di = mover_org_di;
- if (axis == _K_BRESEN_AXIS_X)
- dx += bdelta;
+ uint16 client_signal = readSelectorValue(segMan, client, SELECTOR(signal));
+ writeSelectorValue(segMan, client, SELECTOR(signal), client_signal | kSignalHitObstacle);
+ }
+ writeSelectorValue(segMan, mover, SELECTOR(b_i1), mover_i1);
+ writeSelectorValue(segMan, mover, SELECTOR(b_i2), mover_i2);
+ writeSelectorValue(segMan, mover, SELECTOR(b_di), mover_di);
+
+ if ((getSciVersion() >= SCI_VERSION_1_EGA)) {
+ // this calling code here was right before the last return in
+ // sci1ega and got changed to this position since sci1early
+ // this was an uninitialized issue in sierra sci
+ if ((handleMoveCount) && (getSciVersion() >= SCI_VERSION_1_EARLY))
+ writeSelectorValue(segMan, mover, SELECTOR(b_movCnt), mover_moveCnt);
+ // We need to compare directly in here, complete may have happened during
+ // the current move
+ if ((client_x == mover_x) && (client_y == mover_y))
+ invokeSelector(s, mover, SELECTOR(moveDone), argc, argv);
+ if (getSciVersion() >= SCI_VERSION_1_EARLY)
+ return s->r_acc;
+ }
+ }
+ if (handleMoveCount) {
+ if (getSciVersion() <= SCI_VERSION_1_EGA)
+ writeSelectorValue(segMan, mover, SELECTOR(b_movCnt), mover_moveCnt);
else
- dy += bdelta;
+ writeSelectorValue(segMan, mover, SELECTOR(b_movCnt), client_moveSpeed);
}
+ return s->r_acc;
+}
- writeSelectorValue(segMan, mover, SELECTOR(b_di), bdi);
+extern void kDirLoopWorker(reg_t obj, uint16 angle, EngineState *s, int argc, reg_t *argv);
+extern uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2);
- x += dx;
- y += dy;
+reg_t kDoAvoider(EngineState *s, int argc, reg_t *argv) {
+ SegManager *segMan = s->_segMan;
+ reg_t avoider = argv[0];
+ int16 timesStep = argc > 1 ? argv[1].toUint16() : 1;
- if ((MOVING_ON_X && (((x < destx) && (oldx >= destx)) // Moving left, exceeded?
- || ((x > destx) && (oldx <= destx)) // Moving right, exceeded?
- || ((x == destx) && (ABS(dx) > ABS(dy))) // Moving fast, reached?
- // Treat this last case specially- when doing sub-pixel movements
- // on the other axis, we could still be far away from the destination
- )) || (MOVING_ON_Y && (((y < desty) && (oldy >= desty)) /* Moving upwards, exceeded? */
- || ((y > desty) && (oldy <= desty)) /* Moving downwards, exceeded? */
- || ((y == desty) && (ABS(dy) >= ABS(dx))) /* Moving fast, reached? */
- ))) {
- // Whew... in short: If we have reached or passed our target position
+ if (!s->_segMan->isHeapObject(avoider)) {
+ error("DoAvoider() where avoider %04x:%04x is not an object", PRINT_REG(avoider));
+ return SIGNAL_REG;
+ }
- x = destx;
- y = desty;
- completed = 1;
+ reg_t client = readSelector(segMan, avoider, SELECTOR(client));
+ reg_t mover = readSelector(segMan, client, SELECTOR(mover));
+ if (mover.isNull())
+ return SIGNAL_REG;
- debugC(2, kDebugLevelBresen, "Finished mover %04x:%04x", PRINT_REG(mover));
- }
+ // call mover::doit
+ invokeSelector(s, mover, SELECTOR(doit), argc, argv);
- writeSelectorValue(segMan, client, SELECTOR(x), x);
- writeSelectorValue(segMan, client, SELECTOR(y), y);
+ // Read mover again
+ mover = readSelector(segMan, client, SELECTOR(mover));
+ if (mover.isNull())
+ return SIGNAL_REG;
- debugC(2, kDebugLevelBresen, "New data: (x,y)=(%d,%d), di=%d", x, y, bdi);
+ int16 clientX = readSelectorValue(segMan, client, SELECTOR(x));
+ int16 clientY = readSelectorValue(segMan, client, SELECTOR(y));
+ int16 moverX = readSelectorValue(segMan, mover, SELECTOR(x));
+ int16 moverY = readSelectorValue(segMan, mover, SELECTOR(y));
+ int16 avoiderHeading = readSelectorValue(segMan, avoider, SELECTOR(heading));
- bool collision = false;
- reg_t cantBeHere = NULL_REG;
+ // call client::isBlocked
+ invokeSelector(s, client, SELECTOR(isBlocked), argc, argv);
- if (SELECTOR(cantBeHere) != -1) {
- // adding this here for hoyle 3 to get happy. CantBeHere is a dummy in hoyle 3 and acc is != 0 so we would
- // get a collision otherwise
- s->r_acc = NULL_REG;
- invokeSelector(s, client, SELECTOR(cantBeHere), argc, argv);
- if (!s->r_acc.isNull())
- collision = true;
- cantBeHere = s->r_acc;
- } else {
- invokeSelector(s, client, SELECTOR(canBeHere), argc, argv);
- if (s->r_acc.isNull())
- collision = true;
- }
+ if (s->r_acc.isNull()) {
+ // not blocked
+ if (avoiderHeading == -1)
+ return SIGNAL_REG;
+ avoiderHeading = -1;
- if (collision) {
- signal = readSelectorValue(segMan, client, SELECTOR(signal));
+ uint16 angle = kGetAngleWorker(clientX, clientY, moverX, moverY);
- writeSelectorValue(segMan, client, SELECTOR(x), oldx);
- writeSelectorValue(segMan, client, SELECTOR(y), oldy);
- writeSelectorValue(segMan, client, SELECTOR(signal), (signal | kSignalHitObstacle));
+ reg_t clientLooper = readSelector(segMan, client, SELECTOR(looper));
+ if (clientLooper.isNull()) {
+ kDirLoopWorker(client, angle, s, argc, argv);
+ } else {
+ // call looper::doit
+ reg_t params[2] = { make_reg(0, angle), client };
+ invokeSelector(s, clientLooper, SELECTOR(doit), argc, argv, 2, params);
+ }
+ s->r_acc = SIGNAL_REG;
+
+ } else {
+ // is blocked
+ if (avoiderHeading == -1)
+ avoiderHeading = g_sci->getRNG().getRandomBit() ? 45 : -45;
+ int16 clientHeading = readSelectorValue(segMan, client, SELECTOR(heading));
+ clientHeading = (clientHeading / 45) * 45;
+
+ int16 clientXstep = readSelectorValue(segMan, client, SELECTOR(xStep)) * timesStep;
+ int16 clientYstep = readSelectorValue(segMan, client, SELECTOR(yStep)) * timesStep;
+ int16 newHeading = clientHeading;
+
+ while (1) {
+ int16 newX = clientX;
+ int16 newY = clientY;
+ switch (newHeading) {
+ case 45:
+ case 90:
+ case 135:
+ newX += clientXstep;
+ break;
+ case 225:
+ case 270:
+ case 315:
+ newX -= clientXstep;
+ }
- debugC(2, kDebugLevelBresen, "Finished mover %04x:%04x by collision", PRINT_REG(mover));
- // We shall not set completed in this case, sierra sci also doesn't do it
- // if we set call .moveDone in those cases qfg1 vga gate at the castle and lsl1 casino door will not work
- }
+ switch (newHeading) {
+ case 0:
+ case 45:
+ case 315:
+ newY -= clientYstep;
+ break;
+ case 135:
+ case 180:
+ case 225:
+ newY += clientYstep;
+ }
+ writeSelectorValue(segMan, client, SELECTOR(x), newX);
+ writeSelectorValue(segMan, client, SELECTOR(y), newY);
- if ((getSciVersion() >= SCI_VERSION_1_EGA))
- if (completed)
- invokeSelector(s, mover, SELECTOR(moveDone), argc, argv);
+ // call client::canBeHere
+ invokeSelector(s, client, SELECTOR(canBeHere), argc, argv);
- if (SELECTOR(cantBeHere) != -1)
- return cantBeHere;
- return make_reg(0, completed);
-}
+ if (!s->r_acc.isNull()) {
+ s->r_acc = make_reg(0, newHeading);
+ break; // break out
+ }
-extern void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int argc, reg_t *argv);
-
-int getAngle(int xrel, int yrel) {
- if ((xrel == 0) && (yrel == 0))
- return 0;
- else {
- int val = (int)(180.0 / PI * atan2((double)xrel, (double) - yrel));
- if (val < 0)
- val += 360;
-
- // Take care of OB1 differences between SSCI and
- // FSCI. SCI games sometimes check for equality with
- // "round" angles
- if (val % 45 == 44)
- val++;
- else if (val % 45 == 1)
- val--;
-
- return val;
+ newHeading += avoiderHeading;
+ if (newHeading >= 360)
+ newHeading -= 360;
+ if (newHeading < 0)
+ newHeading += 360;
+ if (newHeading == clientHeading) {
+ // tried everything
+ writeSelectorValue(segMan, client, SELECTOR(x), clientX);
+ writeSelectorValue(segMan, client, SELECTOR(y), clientY);
+ s->r_acc = SIGNAL_REG;
+ break; // break out
+ }
+ }
}
-}
+ writeSelectorValue(segMan, avoider, SELECTOR(heading), avoiderHeading);
+ return s->r_acc;
-reg_t kDoAvoider(EngineState *s, int argc, reg_t *argv) {
- SegManager *segMan = s->_segMan;
- reg_t avoider = argv[0];
+#if 0
reg_t client, looper, mover;
int angle;
int dx, dy;
@@ -486,18 +601,18 @@ reg_t kDoAvoider(EngineState *s, int argc, reg_t *argv) {
s->r_acc = make_reg(0, angle);
- reg_t params[2] = { make_reg(0, angle), client };
-
if (looper.segment) {
+ reg_t params[2] = { make_reg(0, angle), client };
invokeSelector(s, looper, SELECTOR(doit), argc, argv, 2, params);
return s->r_acc;
} else {
// No looper? Fall back to DirLoop
- _k_dirloop(client, (uint16)angle, s, argc, argv);
+ kDirLoopWorker(client, (uint16)angle, s, argc, argv);
}
}
return s->r_acc;
+#endif
}
} // End of namespace Sci
diff --git a/engines/sci/engine/kparse.cpp b/engines/sci/engine/kparse.cpp
index 552e425906..6a052a582d 100644
--- a/engines/sci/engine/kparse.cpp
+++ b/engines/sci/engine/kparse.cpp
@@ -93,13 +93,13 @@ reg_t kParse(EngineState *s, int argc, reg_t *argv) {
reg_t stringpos = argv[0];
Common::String string = s->_segMan->getString(stringpos);
char *error;
- ResultWordList words;
reg_t event = argv[1];
g_sci->checkVocabularySwitch();
Vocabulary *voc = g_sci->getVocabulary();
voc->parser_event = event;
reg_t params[2] = { voc->parser_base, stringpos };
+ ResultWordListList words;
bool res = voc->tokenizeString(words, string.c_str(), &error);
voc->parserIsValid = false; /* not valid */
@@ -109,10 +109,15 @@ reg_t kParse(EngineState *s, int argc, reg_t *argv) {
s->r_acc = make_reg(0, 1);
#ifdef DEBUG_PARSER
- debugC(2, kDebugLevelParser, "Parsed to the following blocks:");
-
- for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
- debugC(2, kDebugLevelParser, " Type[%04x] Group[%04x]", i->_class, i->_group);
+ debugC(2, kDebugLevelParser, "Parsed to the following blocks:");
+
+ for (ResultWordListList::const_iterator i = words.begin(); i != words.end(); ++i) {
+ debugCN(2, kDebugLevelParser, " ");
+ for (ResultWordList::const_iterator j = i->begin(); j != i->end(); ++j) {
+ debugCN(2, kDebugLevelParser, "%sType[%04x] Group[%04x]", j == i->begin() ? "" : " / ", j->_class, j->_group);
+ }
+ debugCN(2, kDebugLevelParser, "\n");
+ }
#endif
int syntax_fail = voc->parseGNF(words);
@@ -138,6 +143,15 @@ reg_t kParse(EngineState *s, int argc, reg_t *argv) {
} else {
s->r_acc = make_reg(0, 0);
+ // FIXME: When typing something wrong in the fanmade game Demo Quest,
+ // after the error dialog, the game checks for claimed to be 0 before
+ // showing a subsequent dialog. The following selector change causes
+ // it to be 1, thus causing the game to hang in an endless loop (bug
+ // #3038870. Thus, this seems to be wrong (since fanmade games use
+ // the original SCI interpreter), but we need to check against
+ // dissassembly. Since kParse is in the process of being dissassembled
+ // again, I'm leaving this FIXME in for now, so that it won't be
+ // forgotten :)
writeSelectorValue(segMan, event, SELECTOR(claimed), 1);
if (error) {
s->_segMan->strcpy(voc->parser_base, error);
diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp
index 07d0a31f0b..faf966af92 100644
--- a/engines/sci/engine/kpathing.cpp
+++ b/engines/sci/engine/kpathing.cpp
@@ -261,13 +261,7 @@ struct PathfindingState {
int findNearPoint(const Common::Point &p, Polygon *polygon, Common::Point *ret);
};
-
-static Common::Point read_point(SegManager *segMan, reg_t list, int offset) {
- SegmentRef list_r = segMan->dereference(list);
- if (!list_r.isValid() || list_r.skipByte) {
- // If this happens, then the code below will probably go OOB and crash
- error("read_point(): Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(list));
- }
+static Common::Point readPoint(SegmentRef list_r, int offset) {
Common::Point point;
if (list_r.isRaw) {
@@ -350,10 +344,16 @@ static void draw_polygon(EngineState *s, reg_t polygon, int width, int height) {
Common::Point first, prev;
int i;
- prev = first = read_point(segMan, points, 0);
+ SegmentRef pointList = segMan->dereference(points);
+ if (!pointList.isValid() || pointList.skipByte) {
+ warning("draw_polygon: Polygon data pointer is invalid, skipping polygon");
+ return;
+ }
+
+ prev = first = readPoint(pointList, 0);
for (i = 1; i < size; i++) {
- Common::Point point = read_point(segMan, points, i);
+ Common::Point point = readPoint(pointList, i);
draw_line(s, prev, point, type, width, height);
prev = point;
}
@@ -401,12 +401,18 @@ static void print_polygon(SegManager *segMan, reg_t polygon) {
debugN(-1, "%i:", type);
+ SegmentRef pointList = segMan->dereference(points);
+ if (!pointList.isValid() || pointList.skipByte) {
+ warning("print_polygon: Polygon data pointer is invalid, skipping polygon");
+ return;
+ }
+
for (i = 0; i < size; i++) {
- point = read_point(segMan, points, i);
+ point = readPoint(pointList, i);
debugN(-1, " (%i, %i)", point.x, point.y);
}
- point = read_point(segMan, points, 0);
+ point = readPoint(pointList, 0);
debug(" (%i, %i);", point.x, point.y);
}
@@ -1092,7 +1098,22 @@ static Polygon *convert_polygon(EngineState *s, reg_t polygon) {
return NULL;
}
- Polygon *poly = new Polygon(readSelectorValue(segMan, polygon, SELECTOR(type)));
+ SegmentRef pointList = segMan->dereference(points);
+ // Check if the target polygon is still valid. It may have been released
+ // in the meantime (e.g. in LSL6, room 700, when using the elevator).
+ // Refer to bug #3034501.
+ if (!pointList.isValid() || pointList.skipByte) {
+ warning("convert_polygon: Polygon data pointer is invalid, skipping polygon");
+ return NULL;
+ }
+
+ // Make sure that we have enough points
+ if (pointList.maxSize < size * POLY_POINT_SIZE) {
+ warning("convert_polygon: Not enough memory allocated for polygon points. "
+ "Expected %d, got %d. Skipping polygon",
+ size * POLY_POINT_SIZE, pointList.maxSize);
+ return NULL;
+ }
int skip = 0;
@@ -1100,14 +1121,16 @@ static Polygon *convert_polygon(EngineState *s, reg_t polygon) {
// Polygon has 17 points but size is set to 19
if ((size == 19) && g_sci->getGameId() == GID_LSL1) {
if ((s->currentRoomNumber() == 350)
- && (read_point(segMan, points, 18) == Common::Point(108, 137))) {
+ && (readPoint(pointList, 18) == Common::Point(108, 137))) {
debug(1, "Applying fix for broken polygon in lsl1sci, room 350");
size = 17;
}
}
+ Polygon *poly = new Polygon(readSelectorValue(segMan, polygon, SELECTOR(type)));
+
for (i = skip; i < size; i++) {
- Vertex *vertex = new Vertex(read_point(segMan, points, i));
+ Vertex *vertex = new Vertex(readPoint(pointList, i));
poly->vertices.insertHead(vertex);
}
@@ -1163,7 +1186,9 @@ static PathfindingState *convert_polygon_set(EngineState *s, reg_t poly_list, Co
Node *node = s->_segMan->lookupNode(list->first);
while (node) {
- polygon = convert_polygon(s, node->value);
+ // The node value might be null, in which case there's no polygon to parse.
+ // Happens in LB2 floppy - refer to bug #3041232
+ polygon = !node->value.isNull() ? convert_polygon(s, node->value) : NULL;
if (polygon) {
pf_s->polygons.push_back(polygon);
@@ -1402,8 +1427,15 @@ static reg_t output_path(PathfindingState *p, EngineState *s) {
if (DebugMan.isDebugChannelEnabled(kDebugLevelAvoidPath)) {
debug("\nReturning path:");
+
+ SegmentRef outputList = s->_segMan->dereference(output);
+ if (!outputList.isValid() || outputList.skipByte) {
+ warning("output_path: Polygon data pointer is invalid, skipping polygon");
+ return output;
+ }
+
for (int i = 0; i < offset; i++) {
- Common::Point pt = read_point(s->_segMan, output, i);
+ Common::Point pt = readPoint(outputList, i);
debugN(-1, " (%i, %i)", pt.x, pt.y);
}
debug(";\n");
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index a5501c160f..e7f466f9a2 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -143,56 +143,72 @@ reg_t kResCheck(EngineState *s, int argc, reg_t *argv) {
}
reg_t kClone(EngineState *s, int argc, reg_t *argv) {
- reg_t parent_addr = argv[0];
- const Object *parent_obj = s->_segMan->getObject(parent_addr);
- reg_t clone_addr;
- Clone *clone_obj; // same as Object*
+ reg_t parentAddr = argv[0];
+ const Object *parentObj = s->_segMan->getObject(parentAddr);
+ reg_t cloneAddr;
+ Clone *cloneObj; // same as Object*
- if (!parent_obj) {
- error("Attempt to clone non-object/class at %04x:%04x failed", PRINT_REG(parent_addr));
+ if (!parentObj) {
+ error("Attempt to clone non-object/class at %04x:%04x failed", PRINT_REG(parentAddr));
return NULL_REG;
}
- debugC(2, kDebugLevelMemory, "Attempting to clone from %04x:%04x", PRINT_REG(parent_addr));
+ debugC(2, kDebugLevelMemory, "Attempting to clone from %04x:%04x", PRINT_REG(parentAddr));
- clone_obj = s->_segMan->allocateClone(&clone_addr);
+ uint16 infoSelector = readSelectorValue(s->_segMan, parentAddr, SELECTOR(_info_));
+ cloneObj = s->_segMan->allocateClone(&cloneAddr);
- if (!clone_obj) {
- error("Cloning %04x:%04x failed-- internal error", PRINT_REG(parent_addr));
+ if (!cloneObj) {
+ error("Cloning %04x:%04x failed-- internal error", PRINT_REG(parentAddr));
return NULL_REG;
}
- *clone_obj = *parent_obj;
+ // In case the parent object is a clone itself we need to refresh our
+ // pointer to it here. This is because calling allocateClone might
+ // invalidate all pointers, references and iterators to data in the clones
+ // segment.
+ //
+ // The reason why it might invalidate those is, that the segment code
+ // (Table) uses Common::Array for internal storage. Common::Array now
+ // might invalidate references to its contained data, when it has to
+ // extend the internal storage size.
+ if (infoSelector & kInfoFlagClone)
+ parentObj = s->_segMan->getObject(parentAddr);
+
+ *cloneObj = *parentObj;
// Mark as clone
- clone_obj->markAsClone();
- clone_obj->setSpeciesSelector(clone_obj->getPos());
- if (parent_obj->isClass())
- clone_obj->setSuperClassSelector(parent_obj->getPos());
- s->_segMan->getScript(parent_obj->getPos().segment)->incrementLockers();
- s->_segMan->getScript(clone_obj->getPos().segment)->incrementLockers();
-
- return clone_addr;
+ infoSelector &= ~kInfoFlagClass; // remove class bit
+ writeSelectorValue(s->_segMan, cloneAddr, SELECTOR(_info_), infoSelector | kInfoFlagClone);
+
+ cloneObj->setSpeciesSelector(cloneObj->getPos());
+ if (parentObj->isClass())
+ cloneObj->setSuperClassSelector(parentObj->getPos());
+ s->_segMan->getScript(parentObj->getPos().segment)->incrementLockers();
+ s->_segMan->getScript(cloneObj->getPos().segment)->incrementLockers();
+
+ return cloneAddr;
}
extern void _k_view_list_mark_free(EngineState *s, reg_t off);
reg_t kDisposeClone(EngineState *s, int argc, reg_t *argv) {
- reg_t victim_addr = argv[0];
- Clone *victim_obj = s->_segMan->getObject(victim_addr);
+ reg_t obj = argv[0];
+ Clone *object = s->_segMan->getObject(obj);
- if (!victim_obj) {
+ if (!object) {
error("Attempt to dispose non-class/object at %04x:%04x",
- PRINT_REG(victim_addr));
- return s->r_acc;
- }
-
- if (!victim_obj->isClone()) {
- // SCI silently ignores this behaviour; some games actually depend on it
+ PRINT_REG(obj));
return s->r_acc;
}
- victim_obj->markAsFreed();
+ // SCI uses this technique to find out, if it's a clone and if it's supposed to get freed
+ // At least kq4early relies on this behaviour. The scripts clone "Sound", then set bit 1 manually
+ // and call kDisposeClone later. In that case we may not free it, otherwise we will run into issues
+ // later, because kIsObject would then return false and Sound object wouldn't get checked.
+ uint16 infoSelector = readSelectorValue(s->_segMan, obj, SELECTOR(_info_));
+ if ((infoSelector & 3) == kInfoFlagClone)
+ object->markAsFreed();
return s->r_acc;
}
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 9254bce9c1..5ea3178ae5 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -275,7 +275,7 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) {
reg = readSelector(s->_segMan, reg, SELECTOR(data));
#endif
- Common::String tempsource = (reg == NULL_REG) ? "" : g_sci->getKernel()->lookupText(reg,
+ Common::String tempsource = g_sci->getKernel()->lookupText(reg,
arguments[paramindex + 1]);
int slen = strlen(tempsource.c_str());
int extralen = str_leng - slen;
@@ -486,10 +486,12 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) {
}
#endif
- if ((func != K_MESSAGE_NEXT) && (argc < 2)) {
- warning("Message: not enough arguments passed to subfunction %d", func);
- return NULL_REG;
- }
+// TODO: Perhaps fix this check, currently doesn't work with PUSH and POP subfunctions
+// Pepper uses them to to handle the glossary
+// if ((func != K_MESSAGE_NEXT) && (argc < 2)) {
+// warning("Message: not enough arguments passed to subfunction %d", func);
+// return NULL_REG;
+// }
MessageTuple tuple;
@@ -558,6 +560,12 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
}
+ case K_MESSAGE_PUSH:
+ s->_msgState->pushCursorStack();
+ break;
+ case K_MESSAGE_POP:
+ s->_msgState->popCursorStack();
+ break;
default:
warning("Message: subfunction %i invoked (not implemented)", func);
}
@@ -779,6 +787,20 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
}
+/**
+ * Debug function, used in the demo of Shivers. It's marked as a stub
+ * in the original interpreter, but it gets called by the game scripts.
+ */
+reg_t kPrintDebug(EngineState *s, int argc, reg_t *argv) {
+ Common::String debugTemplate = s->_segMan->getString(argv[0]);
+ char debugString[500];
+
+ sprintf(debugString, debugTemplate.c_str(), argv[1].toUint16());
+ debugC(2, "kPrintDebug: \"%s\"\n", debugString);
+
+ return s->r_acc;
+}
+
#endif
} // End of namespace Sci
diff --git a/engines/sci/engine/kvideo.cpp b/engines/sci/engine/kvideo.cpp
index ac6cfb6835..e97ae38702 100644
--- a/engines/sci/engine/kvideo.cpp
+++ b/engines/sci/engine/kvideo.cpp
@@ -117,7 +117,7 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
initGraphics(screenWidth, screenHeight, screenWidth > 320, NULL);
if (g_system->getScreenFormat().bytesPerPixel == 1) {
- error("This video requires >8bpp color to be displayed, but could not switch to RGB color mode.");
+ error("This video requires >8bpp color to be displayed, but could not switch to RGB color mode");
return NULL_REG;
}
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index dfc41cc56a..87e328592f 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -45,8 +45,6 @@
#include "sci/sound/audio.h"
#include "sci/sound/music.h"
-#include "gui/message.h"
-
namespace Sci {
@@ -568,26 +566,32 @@ void GfxPalette::palVarySaveLoadPalette(Common::Serializer &s, Palette *palette)
}
void GfxPalette::saveLoadWithSerializer(Common::Serializer &s) {
- if (s.getVersion() < 24)
- return;
-
- if (s.isLoading() && _palVaryResourceId != -1)
- palVaryRemoveTimer();
-
- s.syncAsSint32LE(_palVaryResourceId);
- if (_palVaryResourceId != -1) {
- palVarySaveLoadPalette(s, &_palVaryOriginPalette);
- palVarySaveLoadPalette(s, &_palVaryTargetPalette);
- s.syncAsSint16LE(_palVaryStep);
- s.syncAsSint16LE(_palVaryStepStop);
- s.syncAsSint16LE(_palVaryDirection);
- s.syncAsUint16LE(_palVaryTicks);
- s.syncAsSint32LE(_palVaryPaused);
+ if (s.getVersion() >= 25) {
+ // We need to save intensity of the _sysPalette at least for kq6 when entering the dark cave (room 390)
+ // from room 340. scripts will set intensity to 60 for this room and restore them when leaving.
+ // Sierra SCI is also doing this (although obviously not for SCI0->SCI01 games, still it doesn't hurt
+ // to save it everywhere). ffs. bug #3072868
+ s.syncBytes(_sysPalette.intensity, 256);
}
+ if (s.getVersion() >= 24) {
+ if (s.isLoading() && _palVaryResourceId != -1)
+ palVaryRemoveTimer();
+
+ s.syncAsSint32LE(_palVaryResourceId);
+ if (_palVaryResourceId != -1) {
+ palVarySaveLoadPalette(s, &_palVaryOriginPalette);
+ palVarySaveLoadPalette(s, &_palVaryTargetPalette);
+ s.syncAsSint16LE(_palVaryStep);
+ s.syncAsSint16LE(_palVaryStepStop);
+ s.syncAsSint16LE(_palVaryDirection);
+ s.syncAsUint16LE(_palVaryTicks);
+ s.syncAsSint32LE(_palVaryPaused);
+ }
- if (s.isLoading() && _palVaryResourceId != -1) {
- _palVarySignal = 0;
- palVaryInstallTimer();
+ if (s.isLoading() && _palVaryResourceId != -1) {
+ _palVarySignal = 0;
+ palVaryInstallTimer();
+ }
}
}
@@ -701,6 +705,8 @@ bool gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savenam
return true;
}
+extern void showScummVMDialog(const Common::String &message);
+
void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
SavegameMetadata meta;
@@ -708,7 +714,7 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
sync_SavegameMetadata(ser, meta);
if (fh->eos()) {
- s->r_acc = make_reg(0, 1); // signal failure
+ s->r_acc = TRUE_REG; // signal failure
return;
}
@@ -721,10 +727,9 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
warning("Savegame version is %d, maximum supported is %0d", meta.savegame_version, CURRENT_SAVEGAME_VERSION);
*/
- GUI::MessageDialog dialog("The format of this saved game is obsolete, unable to load it", "OK");
- dialog.runModal();
+ showScummVMDialog("The format of this saved game is obsolete, unable to load it");
- s->r_acc = make_reg(0, 1); // signal failure
+ s->r_acc = TRUE_REG; // signal failure
return;
}
@@ -733,10 +738,9 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
if (script0->size != meta.script0_size || g_sci->getGameObject().offset != meta.game_object_offset) {
//warning("This saved game was created with a different version of the game, unable to load it");
- GUI::MessageDialog dialog("This saved game was created with a different version of the game, unable to load it", "OK");
- dialog.runModal();
+ showScummVMDialog("This saved game was created with a different version of the game, unable to load it");
- s->r_acc = make_reg(0, 1); // signal failure
+ s->r_acc = TRUE_REG; // signal failure
return;
}
}
diff --git a/engines/sci/engine/savegame.h b/engines/sci/engine/savegame.h
index fc254ba33d..14eec4aafc 100644
--- a/engines/sci/engine/savegame.h
+++ b/engines/sci/engine/savegame.h
@@ -36,7 +36,7 @@ namespace Sci {
struct EngineState;
enum {
- CURRENT_SAVEGAME_VERSION = 24,
+ CURRENT_SAVEGAME_VERSION = 25,
MINIMUM_SAVEGAME_VERSION = 14
};
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index f4129bb1ea..da9ab5106d 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -69,6 +69,9 @@ void Script::freeScript() {
void Script::init(int script_nr, ResourceManager *resMan) {
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
+ if (!script)
+ error("Script %d not found\n", script_nr);
+
_localsOffset = 0;
_localsBlock = NULL;
_localsCount = 0;
@@ -288,7 +291,8 @@ void Script::relocate(reg_t block) {
// code blocks. In SCI1.1 and newer versions, only locals and objects
// are relocated.
if (!relocateLocal(block.segment, pos)) {
- // Not a local? It's probably an object or code block. If it's an object, relocate it.
+ // Not a local? It's probably an object or code block. If it's an
+ // object, relocate it.
const ObjMap::iterator end = _objects.end();
for (ObjMap::iterator it = _objects.begin(); it != end; ++it)
if (it->_value.relocate(block.segment, pos, _scriptSize))
@@ -329,13 +333,13 @@ uint16 Script::validateExportFunc(int pubfunct) {
uint16 offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct);
VERIFY(offset < _bufSize, "invalid export function pointer");
- if (offset == 0) {
- // Check if the game has a second export table (e.g. script 912 in Camelot)
- // Fixes bug #3039785
- if (g_sci->getGameId() != GID_CAMELOT) // cheap fix
- return offset;
- // we are getting assert()s in eco quest 1 (right on startup) and kq6 and maybe more
- // [md5] plz look into this TODO FIXME
+ // Check if the offset found points to a second export table (e.g. script 912
+ // in Camelot and script 306 in KQ4). Such offsets are usually small (i.e. < 10),
+ // thus easily distinguished from actual code offsets.
+ // This only makes sense for SCI0-SCI1, as the export table in SCI1.1+ games
+ // is located at a specific address, thus findBlock() won't work.
+ // Fixes bugs #3039785 and #3037595.
+ if (offset < 10 && getSciVersion() <= SCI_VERSION_1_LATE) {
const uint16 *secondExportTable = (const uint16 *)findBlock(SCI_OBJ_EXPORTS, 0);
if (secondExportTable) {
@@ -532,7 +536,7 @@ void Script::initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId) {
// If object is instance, get -propDict- from class and set it for this
// object. This is needed for ::isMemberOf() to work.
- // Example testcase - room 381 of sq4cd - if isMemberOf() doesn't work,
+ // Example test case - room 381 of sq4cd - if isMemberOf() doesn't work,
// talk-clicks on the robot will act like clicking on ego
if (!obj->isClass()) {
reg_t classObject = obj->getSuperClassSelector();
@@ -554,6 +558,13 @@ void Script::initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId) {
relocate(make_reg(segmentId, READ_SCI11ENDIAN_UINT16(_heapStart)));
}
+void Script::initialiseObjects(SegManager *segMan, SegmentId segmentId) {
+ if (getSciVersion() >= SCI_VERSION_1_1)
+ initialiseObjectsSci11(segMan, segmentId);
+ else
+ initialiseObjectsSci0(segMan, segmentId);
+}
+
reg_t Script::findCanonicAddress(SegManager *segMan, reg_t addr) const {
addr.offset = 0;
return addr;
diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h
index c60cc4b19f..e316fc0c8d 100644
--- a/engines/sci/engine/script.h
+++ b/engines/sci/engine/script.h
@@ -159,14 +159,7 @@ public:
* @param segMan A reference to the segment manager
* @param segmentId The script's segment id
*/
- void initialiseObjectsSci0(SegManager *segMan, SegmentId segmentId);
-
- /**
- * Initializes the script's objects (SCI1.1+)
- * @param segMan A reference to the segment manager
- * @param segmentId The script's segment id
- */
- void initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId);
+ void initialiseObjects(SegManager *segMan, SegmentId segmentId);
// script lock operations
@@ -260,6 +253,20 @@ private:
void relocate(reg_t block);
bool relocateLocal(SegmentId segment, int location);
+
+ /**
+ * Initializes the script's objects (SCI0)
+ * @param segMan A reference to the segment manager
+ * @param segmentId The script's segment id
+ */
+ void initialiseObjectsSci0(SegManager *segMan, SegmentId segmentId);
+
+ /**
+ * Initializes the script's objects (SCI1.1+)
+ * @param segMan A reference to the segment manager
+ * @param segmentId The script's segment id
+ */
+ void initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId);
};
} // End of namespace Sci
diff --git a/engines/sci/engine/script_patches.cpp b/engines/sci/engine/script_patches.cpp
index 77818dd138..42d7c4d9cd 100644
--- a/engines/sci/engine/script_patches.cpp
+++ b/engines/sci/engine/script_patches.cpp
@@ -25,25 +25,34 @@
#include "sci/sci.h"
#include "sci/engine/script.h"
+#include "sci/engine/state.h"
#include "common/util.h"
namespace Sci {
#define PATCH_END 0xFFFF
-#define PATCH_ADDTOOFFSET 0x8000
-#define PATCH_GETORIGINALBYTE 0x4000
+#define PATCH_COMMANDMASK 0xF000
+#define PATCH_VALUEMASK 0x0FFF
+#define PATCH_ADDTOOFFSET 0xE000
+#define PATCH_GETORIGINALBYTE 0xD000
+#define PATCH_ADJUSTWORD 0xC000
+#define PATCH_ADJUSTWORD_NEG 0xB000
#define PATCH_MAGICDWORD(a, b, c, d) CONSTANT_LE_32(a | (b << 8) | (c << 16) | (d << 24))
+#define PATCH_VALUELIMIT 4096
struct SciScriptSignature {
uint16 scriptNr;
const char *description;
+ int16 applyCount;
uint32 magicDWord;
int magicOffset;
const byte *data;
const uint16 *patch;
};
+#define SCI_SIGNATUREENTRY_TERMINATOR { 0, NULL, 0, 0, 0, NULL, NULL }
+
// signatures are built like this:
// - first a counter of the bytes that follow
// - then the actual bytes that need to get matched
@@ -52,6 +61,51 @@ struct SciScriptSignature {
// - rinse and repeat
// ===========================================================================
+// Castle of Dr. Brain
+// cipher::init (script 391) is called on room 380 init. This resets the word
+// cipher puzzle. The puzzle sadly operates on some hep strings, which aren't
+// saved in our sci. So saving/restoring in this room will break the puzzle
+// Because of this issue, we just init the puzzle each time it's accessed.
+// this is not 100% sierra behaviour, in fact we will actually reset the puzzle
+// during each access which makes it impossible to cheat.
+const byte castlebrainSignatureCipherPuzzle[] = {
+ 22,
+ 0x35, 0x00, // ldi 00
+ 0xa3, 0x26, // sal local[26]
+ 0xa3, 0x25, // sal local[25]
+ 0x35, 0x00, // ldi 00
+ 0xa3, 0x2a, // sal local[2a] (local is not used)
+ 0xa3, 0x29, // sal local[29] (local is not used)
+ 0x35, 0xff, // ldi ff
+ 0xa3, 0x2c, // sal local[2c]
+ 0xa3, 0x2b, // sal local[2b]
+ 0x35, 0x00, // ldi 00
+ 0x65, 0x16, // aTop highlightedIcon
+ 0
+};
+
+const uint16 castlebrainPatchCipherPuzzle[] = {
+ 0x39, 0x6b, // pushi 6b (selector init)
+ 0x76, // push0
+ 0x55, 0x04, // self 04
+ 0x35, 0x00, // ldi 00
+ 0xa3, 0x25, // sal local[25]
+ 0xa3, 0x26, // sal local[26]
+ 0xa3, 0x29, // sal local[29]
+ 0x65, 0x16, // aTop highlightedIcon
+ 0x34, 0xff, 0xff, // ldi ffff
+ 0xa3, 0x2b, // sal local[2b]
+ 0xa3, 0x2c, // sal local[2c]
+ PATCH_END
+};
+
+// script, description, magic DWORD, adjust
+const SciScriptSignature castlebrainSignatures[] = {
+ { 391, "cipher puzzle save/restore break", 1, PATCH_MAGICDWORD(0xa3, 0x26, 0xa3, 0x25), -2, castlebrainSignatureCipherPuzzle, castlebrainPatchCipherPuzzle },
+ SCI_SIGNATUREENTRY_TERMINATOR
+};
+
+// ===========================================================================
// stayAndHelp::changeState (0) is called when ego swims to the left or right
// boundaries of room 660. Normally a textbox is supposed to get on screen
// but the call is wrong, so not only do we get an error message the script
@@ -73,7 +127,7 @@ const byte ecoquest1SignatureStayAndHelp[] = {
0x78, // push1
0x76, // push0
0x81, 0x00, // lag global[0]
- 0x4a, 0x06, // send 06 - ego::setMotion(0)
+ 0x4a, 0x06, // send 06 - call ego::setMotion(0)
0x39, 0x6e, // pushi 6e (selector init)
0x39, 0x04, // pushi 04
0x76, // push0
@@ -81,7 +135,7 @@ const byte ecoquest1SignatureStayAndHelp[] = {
0x39, 0x17, // pushi 17
0x7c, // pushSelf
0x51, 0x82, // class EcoNarrator
- 0x4a, 0x0c, // send 0c - EcoNarrator::init(0, 0, 23, self) (BADLY BROKEN!)
+ 0x4a, 0x0c, // send 0c - call EcoNarrator::init(0, 0, 23, self) (BADLY BROKEN!)
0x33, // jmp [end]
0
};
@@ -97,7 +151,7 @@ const uint16 ecoquest1PatchStayAndHelp[] = {
0x78, // push1
0x76, // push0
0x81, 0x00, // lag global[0]
- 0x4a, 0x06, // send 06 - ego::setMotion(0)
+ 0x4a, 0x06, // send 06 - call ego::setMotion(0)
0x39, 0x6e, // pushi 6e (selector init)
0x39, 0x06, // pushi 06
0x39, 0x02, // pushi 02 (additional 2 bytes)
@@ -107,16 +161,174 @@ const uint16 ecoquest1PatchStayAndHelp[] = {
0x7c, // pushSelf
0x38, 0x80, 0x02, // pushi 280 (additional 3 bytes)
0x51, 0x82, // class EcoNarrator
- 0x4a, 0x10, // send 10 - EcoNarrator::init(2, 0, 0, 23, self, 640)
+ 0x4a, 0x10, // send 10 - call EcoNarrator::init(2, 0, 0, 23, self, 640)
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature ecoquest1Signatures[] = {
- { 660, "CD: bad messagebox and freeze", PATCH_MAGICDWORD(0x38, 0x22, 0x01, 0x78), -17, ecoquest1SignatureStayAndHelp, ecoquest1PatchStayAndHelp },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 660, "CD: bad messagebox and freeze", 1, PATCH_MAGICDWORD(0x38, 0x22, 0x01, 0x78), -17, ecoquest1SignatureStayAndHelp, ecoquest1PatchStayAndHelp },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
+// ===========================================================================
+// doMyThing::changeState (2) is supposed to remove the initial text on the
+// ecorder. This is done by reusing temp-space, that was filled on state 1.
+// this worked in sierra sci just by accident. In our sci, the temp space
+// is resetted every time, which means the previous text isn't available
+// anymore. We have to patch the code because of that ffs. bug #3035386
+const byte ecoquest2SignatureEcorder[] = {
+ 35,
+ 0x31, 0x22, // bnt [next state]
+ 0x39, 0x0a, // pushi 0a
+ 0x5b, 0x04, 0x1e, // lea temp[1e]
+ 0x36, // push
+ 0x39, 0x64, // pushi 64
+ 0x39, 0x7d, // pushi 7d
+ 0x39, 0x32, // pushi 32
+ 0x39, 0x66, // pushi 66
+ 0x39, 0x17, // pushi 17
+ 0x39, 0x69, // pushi 69
+ 0x38, 0x31, 0x26, // pushi 2631
+ 0x39, 0x6a, // pushi 6a
+ 0x39, 0x64, // pushi 64
+ 0x43, 0x1b, 0x14, // call kDisplay
+ 0x35, 0x0a, // ldi 0a
+ 0x65, 0x20, // aTop ticks
+ 0x33, // jmp [end]
+ +1, 5, // [skip 1 byte]
+ 0x3c, // dup
+ 0x35, 0x03, // ldi 03
+ 0x1a, // eq?
+ 0x31, // bnt [end]
+ 0
+};
+
+const uint16 ecoquest2PatchEcorder[] = {
+ 0x2f, 0x02, // bt [to pushi 07]
+ 0x3a, // toss
+ 0x48, // ret
+ 0x38, 0x07, 0x00, // pushi 07 (parameter count) (waste 1 byte)
+ 0x39, 0x0b, // push (FillBoxAny)
+ 0x39, 0x1d, // pushi 29d
+ 0x39, 0x73, // pushi 115d
+ 0x39, 0x5e, // pushi 94d
+ 0x38, 0xd7, 0x00, // pushi 215d
+ 0x78, // push1 (visual screen)
+ 0x38, 0x17, 0x00, // pushi 17 (color) (waste 1 byte)
+ 0x43, 0x6c, 0x0e, // call kGraph
+ 0x38, 0x05, 0x00, // pushi 05 (parameter count) (waste 1 byte)
+ 0x39, 0x0c, // pushi 12d (UpdateBox)
+ 0x39, 0x1d, // pushi 29d
+ 0x39, 0x73, // pushi 115d
+ 0x39, 0x5e, // pushi 94d
+ 0x38, 0xd7, 0x00, // pushi 215d
+ 0x43, 0x6c, 0x0a, // call kGraph
+ PATCH_END
+};
+
+// script, description, magic DWORD, adjust
+const SciScriptSignature ecoquest2Signatures[] = {
+ { 50, "initial text not removed on ecorder", 1, PATCH_MAGICDWORD(0x39, 0x64, 0x39, 0x7d), -8, ecoquest2SignatureEcorder, ecoquest2PatchEcorder },
+ SCI_SIGNATUREENTRY_TERMINATOR
+};
+
+// ===========================================================================
+// script 0 of freddy pharkas/CD PointsSound::check waits for a signal and if
+// no signal received will call kDoSound(0xD) which is a dummy in sierra sci
+// and ScummVM and will use acc (which is not set by the dummy) to trigger
+// sound disposal. This somewhat worked in sierra sci, because the sample
+// was already playing in the sound driver. In our case we would also stop
+// the sample from playing, so we patch it out
+// The "score" code is already buggy and sets volume to 0 when playing
+const byte freddypharkasSignatureScoreDisposal[] = {
+ 10,
+ 0x67, 0x32, // pTos 32 (selector theAudCount)
+ 0x78, // push1
+ 0x39, 0x0d, // pushi 0d
+ 0x43, 0x75, 0x02, // call kDoAudio
+ 0x1c, // ne?
+ 0x31, // bnt (-> to skip disposal)
+ 0
+};
+
+const uint16 freddypharkasPatchScoreDisposal[] = {
+ 0x34, 0x00, 0x00, // ldi 0000
+ 0x34, 0x00, 0x00, // ldi 0000
+ 0x34, 0x00, 0x00, // ldi 0000
+ PATCH_END
+};
+
+// script 235 of freddy pharkas rm235::init and sEnterFrom500::changeState
+// disable icon 7+8 of iconbar (CD only). When picking up the cannister after
+// placing it down, the scripts will disable all the other icons. This results
+// in IconBar::disable doing endless loops even in sierra sci, because there
+// is no enabled icon left. We remove disabling of icon 8 (which is help),
+// this fixes the issue.
+const byte freddypharkasSignatureCannisterHang[] = {
+ 12,
+ 0x38, 0xf1, 0x00, // pushi f1 (selector disable)
+ 0x7a, // push2
+ 0x39, 0x07, // pushi 07
+ 0x39, 0x08, // pushi 08
+ 0x81, 0x45, // lag 45
+ 0x4a, 0x08, // send 08 - call IconBar::disable(7, 8)
+ 0
+};
+
+const uint16 freddypharkasPatchCannisterHang[] = {
+ PATCH_ADDTOOFFSET | +3,
+ 0x78, // push1
+ PATCH_ADDTOOFFSET | +2,
+ 0x33, 0x00, // ldi 00 (waste 2 bytes)
+ PATCH_ADDTOOFFSET | +3,
+ 0x06, // send 06 - call IconBar::disable(7)
+ PATCH_END
+};
+
+// script 215 of freddy pharkas lowerLadder::doit and highLadder::doit actually
+// process keyboard-presses when the ladder is on the screen in that room.
+// They strangely also call kGetEvent. Because the main User::doit also calls
+// kGetEvent, it's pure luck, where the event will hit. It's the same issue
+// as in QfG1VGA and if you turn dos-box to max cycles, and click around for
+// ego, sometimes clicks also won't get registered. Strangely it's not nearly
+// as bad as in our sci, but these differences may be caused by timing.
+// We just reuse the active event, thus removing the duplicate kGetEvent call.
+const byte freddypharkasSignatureLadderEvent[] = {
+ 21,
+ 0x39, 0x6d, // pushi 6d (selector new)
+ 0x76, // push0
+ 0x38, 0xf5, 0x00, // pushi f5 (selector curEvent)
+ 0x76, // push0
+ 0x81, 0x50, // lag global[50]
+ 0x4a, 0x04, // send 04 - read User::curEvent
+ 0x4a, 0x04, // send 04 - call curEvent::new
+ 0xa5, 0x00, // sat temp[0]
+ 0x38, 0x94, 0x00, // pushi 94 (selector localize)
+ 0x76, // push0
+ 0x4a, 0x04, // send 04 - call curEvent::localize
+ 0
+};
+
+const uint16 freddypharkasPatchLadderEvent[] = {
+ 0x34, 0x00, 0x00, // ldi 0000 (waste 3 bytes, overwrites first 2 pushes)
+ PATCH_ADDTOOFFSET | +8,
+ 0xa5, 0x00, // sat temp[0] (waste 2 bytes, overwrites 2nd send)
+ PATCH_ADDTOOFFSET | +2,
+ 0x34, 0x00, 0x00, // ldi 0000
+ 0x34, 0x00, 0x00, // ldi 0000 (waste 6 bytes, overwrites last 3 opcodes)
+ PATCH_END
+};
+
+// script, description, magic DWORD, adjust
+const SciScriptSignature freddypharkasSignatures[] = {
+ { 0, "CD: score early disposal", 1, PATCH_MAGICDWORD(0x39, 0x0d, 0x43, 0x75), -3, freddypharkasSignatureScoreDisposal, freddypharkasPatchScoreDisposal },
+ { 235, "CD: cannister pickup hang", 3, PATCH_MAGICDWORD(0x39, 0x07, 0x39, 0x08), -4, freddypharkasSignatureCannisterHang, freddypharkasPatchCannisterHang },
+ { 320, "ladder event issue", 2, PATCH_MAGICDWORD(0x6d, 0x76, 0x38, 0xf5), -1, freddypharkasSignatureLadderEvent, freddypharkasPatchLadderEvent },
+ SCI_SIGNATUREENTRY_TERMINATOR
+};
+
+// ===========================================================================
// daySixBeignet::changeState (4) is called when the cop goes out and sets cycles to 220.
// this is not enough time to get to the door, so we patch that to 23 seconds
const byte gk1SignatureDay6PoliceBeignet[] = {
@@ -182,12 +394,12 @@ const uint16 gk1PatchDay5PhoneFreeze[] = {
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature gk1Signatures[] = {
- { 212, "day 5 phone freeze", PATCH_MAGICDWORD(0x35, 0x03, 0x65, 0x1a), 0, gk1SignatureDay5PhoneFreeze, gk1PatchDay5PhoneFreeze },
- { 230, "day 6 police beignet timer issue", PATCH_MAGICDWORD(0x34, 0xdc, 0x00, 0x65), -16, gk1SignatureDay6PoliceBeignet, gk1PatchDay6PoliceBeignet },
- { 230, "day 6 police sleep timer issue", PATCH_MAGICDWORD(0x34, 0xdc, 0x00, 0x65), -5, gk1SignatureDay6PoliceSleep, gk1PatchDay6PoliceSleep },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 212, "day 5 phone freeze", 1, PATCH_MAGICDWORD(0x35, 0x03, 0x65, 0x1a), 0, gk1SignatureDay5PhoneFreeze, gk1PatchDay5PhoneFreeze },
+ { 230, "day 6 police beignet timer issue", 1, PATCH_MAGICDWORD(0x34, 0xdc, 0x00, 0x65), -16, gk1SignatureDay6PoliceBeignet, gk1PatchDay6PoliceBeignet },
+ { 230, "day 6 police sleep timer issue", 1, PATCH_MAGICDWORD(0x34, 0xdc, 0x00, 0x65), -5, gk1SignatureDay6PoliceSleep, gk1PatchDay6PoliceSleep },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
// ===========================================================================
@@ -196,63 +408,63 @@ const SciScriptSignature gk1Signatures[] = {
// we would get an invalid port handle to a kSetPort call. We just patch in
// resetting of the port selector. We destroy the stop/fade code in there,
// it seems it isn't used at all in the game.
-const byte hoyle4SignaturePortFix[] = {
- 28,
- 0x39, 0x09, // pushi 09
- 0x89, 0x0b, // lsg 0b
- 0x39, 0x64, // pushi 64
- 0x38, 0xc8, 0x00, // pushi 00c8
- 0x38, 0x2c, 0x01, // pushi 012c
- 0x38, 0x90, 0x01, // pushi 0190
- 0x38, 0xf4, 0x01, // pushi 01f4
- 0x38, 0x58, 0x02, // pushi 0258
- 0x38, 0xbc, 0x02, // pushi 02bc
- 0x38, 0x20, 0x03, // pushi 0320
- 0x46, // calle [xxxx] [xxxx] [xx]
- +5, 43, // [skip 5 bytes]
- 0x30, 0x27, 0x00, // bnt 0027 -> end of routine
- 0x87, 0x00, // lap 00
- 0x30, 0x19, 0x00, // bnt 0019 -> fade out
- 0x87, 0x01, // lap 01
- 0x30, 0x14, 0x00, // bnt 0014 -> fade out
- 0x38, 0xa7, 0x00, // pushi 00a7
- 0x76, // push0
- 0x80, 0x29, 0x01, // lag 0129
- 0x4a, 0x04, // send 04 (song::stop)
- 0x39, 0x27, // pushi 27
- 0x78, // push1
- 0x8f, 0x01, // lsp 01
- 0x51, 0x54, // class 54
- 0x4a, 0x06, // send 06 (PlaySong::play)
- 0x33, 0x09, // jmp 09 -> end of routine
- 0x38, 0xaa, 0x00, // pushi 00aa
- 0x76, // push0
- 0x80, 0x29, 0x01, // lag 0129
- 0x4a, 0x04, // send 04
- 0x48, // ret
- 0
-};
-
-const uint16 hoyle4PatchPortFix[] = {
- PATCH_ADDTOOFFSET | +33,
- 0x38, 0x31, 0x01, // pushi 0131 (selector curEvent)
- 0x76, // push0
- 0x80, 0x50, 0x00, // lag 0050 (global var 80h, "User")
- 0x4a, 0x04, // send 04 (read User::curEvent)
-
- 0x38, 0x93, 0x00, // pushi 0093 (selector port)
- 0x78, // push1
- 0x76, // push0
- 0x4a, 0x06, // send 06 (write 0 to that object::port)
- 0x48, // ret
- PATCH_END
-};
+//const byte hoyle4SignaturePortFix[] = {
+// 28,
+// 0x39, 0x09, // pushi 09
+// 0x89, 0x0b, // lsg 0b
+// 0x39, 0x64, // pushi 64
+// 0x38, 0xc8, 0x00, // pushi 00c8
+// 0x38, 0x2c, 0x01, // pushi 012c
+// 0x38, 0x90, 0x01, // pushi 0190
+// 0x38, 0xf4, 0x01, // pushi 01f4
+// 0x38, 0x58, 0x02, // pushi 0258
+// 0x38, 0xbc, 0x02, // pushi 02bc
+// 0x38, 0x20, 0x03, // pushi 0320
+// 0x46, // calle [xxxx] [xxxx] [xx]
+// +5, 43, // [skip 5 bytes]
+// 0x30, 0x27, 0x00, // bnt 0027 -> end of routine
+// 0x87, 0x00, // lap 00
+// 0x30, 0x19, 0x00, // bnt 0019 -> fade out
+// 0x87, 0x01, // lap 01
+// 0x30, 0x14, 0x00, // bnt 0014 -> fade out
+// 0x38, 0xa7, 0x00, // pushi 00a7
+// 0x76, // push0
+// 0x80, 0x29, 0x01, // lag 0129
+// 0x4a, 0x04, // send 04 - call song::stop
+// 0x39, 0x27, // pushi 27
+// 0x78, // push1
+// 0x8f, 0x01, // lsp 01
+// 0x51, 0x54, // class 54
+// 0x4a, 0x06, // send 06 - call PlaySong::play
+// 0x33, 0x09, // jmp 09 -> end of routine
+// 0x38, 0xaa, 0x00, // pushi 00aa
+// 0x76, // push0
+// 0x80, 0x29, 0x01, // lag 0129
+// 0x4a, 0x04, // send 04
+// 0x48, // ret
+// 0
+//};
+
+//const uint16 hoyle4PatchPortFix[] = {
+// PATCH_ADDTOOFFSET | +33,
+// 0x38, 0x31, 0x01, // pushi 0131 (selector curEvent)
+// 0x76, // push0
+// 0x80, 0x50, 0x00, // lag 0050 (global var 80h, "User")
+// 0x4a, 0x04, // send 04 - read User::curEvent
+//
+// 0x38, 0x93, 0x00, // pushi 0093 (selector port)
+// 0x78, // push1
+// 0x76, // push0
+// 0x4a, 0x06, // send 06 - write 0 to that object::port
+// 0x48, // ret
+// PATCH_END
+//};
// script, description, magic DWORD, adjust
-const SciScriptSignature hoyle4Signatures[] = {
- { 0, "port fix when disposing windows", PATCH_MAGICDWORD(0x64, 0x38, 0xC8, 0x00), -5, hoyle4SignaturePortFix, hoyle4PatchPortFix },
- { 0, NULL, 0, 0, NULL, NULL }
-};
+//const SciScriptSignature hoyle4Signatures[] = {
+// { 0, "port fix when disposing windows", PATCH_MAGICDWORD(0x64, 0x38, 0xC8, 0x00), -5, hoyle4SignaturePortFix, hoyle4PatchPortFix },
+// { 0, NULL, 0, 0, NULL, NULL }
+//};
// ===========================================================================
// at least during harpy scene export 29 of script 0 is called in kq5cd and
@@ -270,12 +482,12 @@ const byte kq5SignatureCdHarpyVolume[] = {
0x38, 0x7b, 0x01, // pushi 017b
0x76, // push0
0x81, 0x01, // lag global[1]
- 0x4a, 0x04, // send 04 (getting KQ5::masterVolume)
+ 0x4a, 0x04, // send 04 - read KQ5::masterVolume
0xa5, 0x03, // sat temp[3] (store volume in temp 3)
0x38, 0x7b, 0x01, // pushi 017b
0x76, // push0
0x81, 0x01, // lag global[1]
- 0x4a, 0x04, // send 04 (getting KQ5::masterVolume)
+ 0x4a, 0x04, // send 04 - read KQ5::masterVolume
0x36, // push
0x35, 0x04, // ldi 04
0x20, // ge? (followed by bnt)
@@ -296,7 +508,7 @@ const uint16 kq5PatchCdHarpyVolume[] = {
0x38, 0x7b, 0x01, // pushi 017b
0x76, // push0
0x81, 0x01, // lag global[1]
- 0x4a, 0x04, // send 04 (getting KQ5::masterVolume)
+ 0x4a, 0x04, // send 04 - read KQ5::masterVolume
0xa5, 0x03, // sat temp[3] (store volume in temp 3)
// saving 8 bytes due removing of duplicate code
0x39, 0x04, // pushi 04 (saving 1 byte due swapping)
@@ -304,10 +516,10 @@ const uint16 kq5PatchCdHarpyVolume[] = {
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature kq5Signatures[] = {
- { 0, "CD: harpy volume change", PATCH_MAGICDWORD(0x80, 0x91, 0x01, 0x18), 0, kq5SignatureCdHarpyVolume, kq5PatchCdHarpyVolume },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 0, "CD: harpy volume change", 1, PATCH_MAGICDWORD(0x80, 0x91, 0x01, 0x18), 0, kq5SignatureCdHarpyVolume, kq5PatchCdHarpyVolume },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
// ===========================================================================
@@ -355,10 +567,10 @@ const uint16 larry6PatchDeathDialog[] = {
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature larry6Signatures[] = {
- { 82, "death dialog memory corruption", PATCH_MAGICDWORD(0x3e, 0x33, 0x01, 0x35), 0, larry6SignatureDeathDialog, larry6PatchDeathDialog },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 82, "death dialog memory corruption", 1, PATCH_MAGICDWORD(0x3e, 0x33, 0x01, 0x35), 0, larry6SignatureDeathDialog, larry6PatchDeathDialog },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
// ===========================================================================
@@ -367,7 +579,7 @@ const SciScriptSignature larry6Signatures[] = {
// is not in the room. We fix that.
const byte laurabow2SignaturePaintingClosing[] = {
17,
- 0x4a, 0x04, // send 04 (gets aHeimlich::room)
+ 0x4a, 0x04, // send 04 - read aHeimlich::room
0x36, // push
0x81, 0x0b, // lag global[11d] -> current room
0x1c, // ne?
@@ -386,10 +598,110 @@ const uint16 laurabow2PatchPaintingClosing[] = {
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature laurabow2Signatures[] = {
- { 560, "painting closing immediately", PATCH_MAGICDWORD(0x36, 0x81, 0x0b, 0x1c), -2, laurabow2SignaturePaintingClosing, laurabow2PatchPaintingClosing },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 560, "painting closing immediately", 1, PATCH_MAGICDWORD(0x36, 0x81, 0x0b, 0x1c), -2, laurabow2SignaturePaintingClosing, laurabow2PatchPaintingClosing },
+ SCI_SIGNATUREENTRY_TERMINATOR
+};
+
+// ===========================================================================
+// Mother Goose SCI1/SCI1.1
+// MG::replay somewhat calculates the savedgame-id used when saving again
+// this doesn't work right and we remove the code completely.
+// We set the savedgame-id directly right after restoring in kRestoreGame.
+const byte mothergoose256SignatureReplay[] = {
+ 6,
+ 0x36, // push
+ 0x35, 0x20, // ldi 20
+ 0x04, // sub
+ 0xa1, 0xb3, // sag global[b3]
+ 0
+};
+
+const uint16 mothergoose256PatchReplay[] = {
+ 0x34, 0x00, 0x00, // ldi 0000 (dummy)
+ 0x34, 0x00, 0x00, // ldi 0000 (dummy)
+ PATCH_END
+};
+
+// when saving, it also checks if the savegame-id is below 13.
+// we change this to check if below 113 instead
+const byte mothergoose256SignatureSaveLimit[] = {
+ 5,
+ 0x89, 0xb3, // lsg global[b3]
+ 0x35, 0x0d, // ldi 0d
+ 0x20, // ge?
+ 0
+};
+
+const uint16 mothergoose256PatchSaveLimit[] = {
+ PATCH_ADDTOOFFSET | +2,
+ 0x35, 0x0d + SAVEGAMEID_OFFICIALRANGE_START, // ldi 113d
+ PATCH_END
+};
+
+// script, description, magic DWORD, adjust
+const SciScriptSignature mothergoose256Signatures[] = {
+ { 0, "replay save issue", 1, PATCH_MAGICDWORD(0x20, 0x04, 0xa1, 0xb3), -2, mothergoose256SignatureReplay, mothergoose256PatchReplay },
+ { 0, "save limit dialog (SCI1.1)", 1, PATCH_MAGICDWORD(0xb3, 0x35, 0x0d, 0x20), -1, mothergoose256SignatureSaveLimit, mothergoose256PatchSaveLimit },
+ { 994, "save limit dialog (SCI1)", 1, PATCH_MAGICDWORD(0xb3, 0x35, 0x0d, 0x20), -1, mothergoose256SignatureSaveLimit, mothergoose256PatchSaveLimit },
+ SCI_SIGNATUREENTRY_TERMINATOR
+};
+
+// ===========================================================================
+// script 215 of qfg1vga pointBox::doit actually processes button-presses
+// during fighting with monsters. It strangely also calls kGetEvent. Because
+// the main User::doit also calls kGetEvent it's pure luck, where the event
+// will hit. It's the same issue as in freddy pharkas and if you turn dos-box
+// to max cycles, sometimes clicks also won't get registered. Strangely it's
+// not nearly as bad as in our sci, but these differences may be caused by
+// timing.
+// We just reuse the active event, thus removing the duplicate kGetEvent call.
+const byte qfg1vgaSignatureFightEvents[] = {
+ 25,
+ 0x39, 0x6d, // pushi 6d (selector new)
+ 0x76, // push0
+ 0x51, 0x07, // class Event
+ 0x4a, 0x04, // send 04 - call Event::new
+ 0xa5, 0x00, // sat temp[0]
+ 0x78, // push1
+ 0x76, // push0
+ 0x4a, 0x04, // send 04 - read Event::x
+ 0xa5, 0x03, // sat temp[3]
+ 0x76, // push0 (selector y)
+ 0x76, // push0
+ 0x85, 0x00, // lat temp[0]
+ 0x4a, 0x04, // send 04 - read Event::y
+ 0x36, // push
+ 0x35, 0x0a, // ldi 0a
+ 0x04, // sub (poor mans localization) ;-)
+ 0
+};
+
+const uint16 qfg1vgaPatchFightEvents[] = {
+ 0x38, 0x5a, 0x01, // pushi 15a (selector curEvent)
+ 0x76, // push0
+ 0x81, 0x50, // lag global[50]
+ 0x4a, 0x04, // send 04 - read User::curEvent -> needs one byte more than previous code
+ 0xa5, 0x00, // sat temp[0]
+ 0x78, // push1
+ 0x76, // push0
+ 0x4a, 0x04, // send 04 - read Event::x
+ 0xa5, 0x03, // sat temp[3]
+ 0x76, // push0 (selector y)
+ 0x76, // push0
+ 0x85, 0x00, // lat temp[0]
+ 0x4a, 0x04, // send 04 - read Event::y
+ 0x39, 0x00, // pushi 00
+ 0x02, // add (waste 3 bytes) - we don't need localization, User::doit has already done it
+ PATCH_END
+};
+
+// script, description, magic DWORD, adjust
+const SciScriptSignature qfg1vgaSignatures[] = {
+ { 215, "fight event issue", 1, PATCH_MAGICDWORD(0x6d, 0x76, 0x51, 0x07), -1, qfg1vgaSignatureFightEvents, qfg1vgaPatchFightEvents },
+ { 216, "weapon master event issue", 1, PATCH_MAGICDWORD(0x6d, 0x76, 0x51, 0x07), -1, qfg1vgaSignatureFightEvents, qfg1vgaPatchFightEvents },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
// ===========================================================================
@@ -415,10 +727,10 @@ const uint16 sq4FloppyPatchEndlessFlight[] = {
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature sq4Signatures[] = {
- { 298, "Floppy: endless flight", PATCH_MAGICDWORD(0x67, 0x08, 0x63, 0x44), -3, sq4FloppySignatureEndlessFlight, sq4FloppyPatchEndlessFlight },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 298, "Floppy: endless flight", 1, PATCH_MAGICDWORD(0x67, 0x08, 0x63, 0x44), -3, sq4FloppySignatureEndlessFlight, sq4FloppyPatchEndlessFlight },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
// ===========================================================================
@@ -438,8 +750,8 @@ const byte sq5SignatureScrubbing[] = {
0x39, 0x38, // pushi 38 (selector mover)
0x76, // push0
0x81, 0x00, // lag 00
- 0x4a, 0x04, // send 04 (read ego::mover)
- 0x4a, 0x04, // send 04 (read ego::mover::x)
+ 0x4a, 0x04, // send 04 - read ego::mover
+ 0x4a, 0x04, // send 04 - read ego::mover::x
0x36, // push
0x34, 0xa0, 0x00, // ldi 00a0
0x1c, // ne?
@@ -453,35 +765,67 @@ const uint16 sq5PatchScrubbing[] = {
0x39, 0x38, // pushi 38 (selector mover)
0x76, // push0
0x81, 0x00, // lag 00
- 0x4a, 0x04, // send 04 (read ego::mover)
+ 0x4a, 0x04, // send 04 - read ego::mover
0x31, 0x2e, // bnt 2e (jump if ego::mover is 0)
0x78, // push1 (selector x)
0x76, // push0
- 0x4a, 0x04, // send 04 (read ego::mover::x)
+ 0x4a, 0x04, // send 04 - read ego::mover::x
0x39, 0xa0, // pushi a0 (saving 2 bytes)
0x1c, // ne?
PATCH_END
};
-// script, description, magic DWORD, adjust
+// script, description, magic DWORD, adjust
const SciScriptSignature sq5Signatures[] = {
- { 119, "scrubbing send crash", PATCH_MAGICDWORD(0x18, 0x31, 0x37, 0x78), 0, sq5SignatureScrubbing, sq5PatchScrubbing },
- { 0, NULL, 0, 0, NULL, NULL }
+ { 119, "scrubbing send crash", 1, PATCH_MAGICDWORD(0x18, 0x31, 0x37, 0x78), 0, sq5SignatureScrubbing, sq5PatchScrubbing },
+ SCI_SIGNATUREENTRY_TERMINATOR
};
// will actually patch previously found signature area
void Script::applyPatch(const uint16 *patch, byte *scriptData, const uint32 scriptSize, int32 signatureOffset) {
+ byte orgData[PATCH_VALUELIMIT];
int32 offset = signatureOffset;
uint16 patchWord = *patch;
+ // Copy over original bytes from script
+ uint32 orgDataSize = scriptSize - offset;
+ if (orgDataSize > PATCH_VALUELIMIT)
+ orgDataSize = PATCH_VALUELIMIT;
+ memcpy(&orgData, &scriptData[offset], orgDataSize);
+
while (patchWord != PATCH_END) {
- if (patchWord & PATCH_ADDTOOFFSET) {
- offset += patchWord & ~PATCH_ADDTOOFFSET;
- } else if (patchWord & PATCH_GETORIGINALBYTE) {
- // TODO: implement this
- } else {
- scriptData[offset] = patchWord & 0xFF;
+ uint16 patchValue = patchWord & PATCH_VALUEMASK;
+ switch (patchWord & PATCH_COMMANDMASK) {
+ case PATCH_ADDTOOFFSET:
+ // add value to offset
+ offset += patchValue & ~PATCH_ADDTOOFFSET;
+ break;
+ case PATCH_GETORIGINALBYTE:
+ // get original byte from script
+ if (patchValue >= orgDataSize)
+ error("patching: can not get requested original byte from script");
+ scriptData[offset] = orgData[patchValue];
+ offset++;
+ break;
+ case PATCH_ADJUSTWORD: {
+ // Adjust word right before current position
+ byte *adjustPtr = &scriptData[offset - 2];
+ uint16 adjustWord = READ_LE_UINT16(adjustPtr);
+ adjustWord += patchValue;
+ WRITE_LE_UINT16(adjustPtr, adjustWord);
+ break;
+ }
+ case PATCH_ADJUSTWORD_NEG: {
+ // Adjust word right before current position (negative way)
+ byte *adjustPtr = &scriptData[offset - 2];
+ uint16 adjustWord = READ_LE_UINT16(adjustPtr);
+ adjustWord -= patchValue;
+ WRITE_LE_UINT16(adjustPtr, adjustWord);
+ break;
+ }
+ default:
+ scriptData[offset] = patchValue & 0xFF;
offset++;
}
patch++;
@@ -499,7 +843,7 @@ int32 Script::findSignature(const SciScriptSignature *signature, const byte *scr
uint32 DWordOffset = 0;
// first search for the magic DWORD
while (DWordOffset < searchLimit) {
- if (magicDWord == *(const uint32 *)(scriptData + DWordOffset)) {
+ if (magicDWord == READ_UINT32(scriptData + DWordOffset)) {
// magic DWORD found, check if actual signature matches
uint32 offset = DWordOffset + signature->magicOffset;
uint32 byteOffset = offset;
@@ -529,33 +873,65 @@ int32 Script::findSignature(const SciScriptSignature *signature, const byte *scr
void Script::matchSignatureAndPatch(uint16 scriptNr, byte *scriptData, const uint32 scriptSize) {
const SciScriptSignature *signatureTable = NULL;
- if (g_sci->getGameId() == GID_ECOQUEST)
+ switch (g_sci->getGameId()) {
+ case GID_CASTLEBRAIN:
+ signatureTable = castlebrainSignatures;
+ break;
+ case GID_ECOQUEST:
signatureTable = ecoquest1Signatures;
- if (g_sci->getGameId() == GID_GK1)
+ break;
+ case GID_ECOQUEST2:
+ signatureTable = ecoquest2Signatures;
+ break;
+ case GID_FREDDYPHARKAS:
+ signatureTable = freddypharkasSignatures;
+ break;
+ case GID_GK1:
signatureTable = gk1Signatures;
-// hoyle4 now works due workaround inside GfxPorts
-// if (g_sci->getGameId() == GID_HOYLE4)
-// signatureTable = hoyle4Signatures;
- if (g_sci->getGameId() == GID_KQ5)
+ break;
+ // hoyle4 now works due to workaround inside GfxPorts
+ //case GID_HOYLE4:
+ // signatureTable = hoyle4Signatures;
+ // break;
+ case GID_KQ5:
signatureTable = kq5Signatures;
- if (g_sci->getGameId() == GID_LAURABOW2)
+ break;
+ case GID_LAURABOW2:
signatureTable = laurabow2Signatures;
- if (g_sci->getGameId() == GID_LSL6)
+ break;
+ case GID_LSL6:
signatureTable = larry6Signatures;
- if (g_sci->getGameId() == GID_SQ4)
+ break;
+ case GID_MOTHERGOOSE256:
+ signatureTable = mothergoose256Signatures;
+ break;
+ case GID_QFG1VGA:
+ signatureTable = qfg1vgaSignatures;
+ break;
+ case GID_SQ4:
signatureTable = sq4Signatures;
- if (g_sci->getGameId() == GID_SQ5)
+ break;
+ case GID_SQ5:
signatureTable = sq5Signatures;
+ break;
+ default:
+ break;
+ }
if (signatureTable) {
while (signatureTable->data) {
if (scriptNr == signatureTable->scriptNr) {
- int32 foundOffset = findSignature(signatureTable, scriptData, scriptSize);
- if (foundOffset != -1) {
- // found, so apply the patch
- warning("matched and patched %s on script %d offset %d", signatureTable->description, scriptNr, foundOffset);
- applyPatch(signatureTable->patch, scriptData, scriptSize, foundOffset);
- }
+ int32 foundOffset = 0;
+ int16 applyCount = signatureTable->applyCount;
+ do {
+ foundOffset = findSignature(signatureTable, scriptData, scriptSize);
+ if (foundOffset != -1) {
+ // found, so apply the patch
+ warning("matched and patched %s on script %d offset %d", signatureTable->description, scriptNr, foundOffset);
+ applyPatch(signatureTable->patch, scriptData, scriptSize, foundOffset);
+ }
+ applyCount--;
+ } while ((foundOffset != -1) && (applyCount));
}
signatureTable++;
}
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 1fb37f458d..1cbe9a56f4 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -1004,12 +1004,7 @@ int SegManager::instantiateScript(int scriptNum) {
scr->load(_resMan);
scr->initialiseLocals(this);
scr->initialiseClasses(this);
-
- if (getSciVersion() >= SCI_VERSION_1_1) {
- scr->initialiseObjectsSci11(this, segmentId);
- } else {
- scr->initialiseObjectsSci0(this, segmentId);
- }
+ scr->initialiseObjects(this, segmentId);
return segmentId;
}
@@ -1052,7 +1047,7 @@ void SegManager::uninstantiateScriptSci0(int script_nr) {
reg_t reg = make_reg(segmentId, oldScriptHeader ? 2 : 0);
int objType, objLength = 0;
- // Make a pass over the object in order uninstantiate all superclasses
+ // Make a pass over the object in order to uninstantiate all superclasses
do {
reg.offset += objLength; // Step over the last checked object
@@ -1074,8 +1069,17 @@ void SegManager::uninstantiateScriptSci0(int script_nr) {
if (superclass_script == script_nr) {
if (scr->getLockers())
scr->decrementLockers(); // Decrease lockers if this is us ourselves
- } else
- uninstantiateScript(superclass_script);
+ } else {
+ if (g_sci->getGameId() == GID_HOYLE3 && (superclass_script == 0 || superclass_script >= 990)) {
+ // HACK for Hoyle 3: when exiting Checkers or Pachisi, scripts 0, 999 and some others
+ // are deleted but are never instantiated again. We ignore deletion of these scripts
+ // here for Hoyle 3 - bug #3038837
+ // TODO/FIXME: find out why this happens, seems like there is a problem with the object
+ // lock code
+ } else {
+ uninstantiateScript(superclass_script);
+ }
+ }
// Recurse to assure that the superclass lockers number gets decreased
}
diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h
index c8cb4cd203..6eca708e2e 100644
--- a/engines/sci/engine/segment.h
+++ b/engines/sci/engine/segment.h
@@ -227,8 +227,12 @@ enum ObjectOffsets {
class Object {
public:
Object() {
- _flags = 0;
_offset = getSciVersion() < SCI_VERSION_1_1 ? 0 : 5;
+ _flags = 0;
+ _baseObj = 0;
+ _baseVars = 0;
+ _baseMethod = 0;
+ _methodCount = 0;
}
~Object() { }
@@ -286,9 +290,6 @@ public:
bool isClass() const { return (getInfoSelector().offset & kInfoFlagClass); }
const Object *getClass(SegManager *segMan) const;
- void markAsClone() { setInfoSelector(make_reg(0, kInfoFlagClone)); }
- bool isClone() const { return (getInfoSelector().offset & kInfoFlagClone); }
-
void markAsFreed() { _flags |= OBJECT_FLAG_FREED; }
bool isFreed() const { return _flags & OBJECT_FLAG_FREED; }
diff --git a/engines/sci/engine/selector.cpp b/engines/sci/engine/selector.cpp
index f99a41e088..b31f52aa13 100644
--- a/engines/sci/engine/selector.cpp
+++ b/engines/sci/engine/selector.cpp
@@ -50,7 +50,7 @@ namespace Sci {
void Kernel::mapSelectors() {
// species
// superClass
- // -info-
+ FIND_SELECTOR2(_info_, "-info-");
FIND_SELECTOR(y);
FIND_SELECTOR(x);
FIND_SELECTOR(view);
@@ -86,7 +86,8 @@ void Kernel::mapSelectors() {
// window
FIND_SELECTOR(cursor);
FIND_SELECTOR(max);
- // mark
+ FIND_SELECTOR(mark);
+ FIND_SELECTOR(sort);
// who
FIND_SELECTOR(message);
// edit
@@ -164,7 +165,6 @@ void Kernel::mapSelectors() {
FIND_SELECTOR(vanishingX);
FIND_SELECTOR(vanishingY);
FIND_SELECTOR(iconIndex);
- FIND_SELECTOR(port);
#ifdef ENABLE_SCI32
FIND_SELECTOR(data);
diff --git a/engines/sci/engine/selector.h b/engines/sci/engine/selector.h
index 00e795c1b9..98157c3eaf 100644
--- a/engines/sci/engine/selector.h
+++ b/engines/sci/engine/selector.h
@@ -40,6 +40,7 @@ struct SelectorCache {
}
// Statically defined selectors, (almost the) same in all SCI versions
+ Selector _info_;
Selector y;
Selector x;
Selector view, loop, cel; ///< Description of a specific image
@@ -58,7 +59,9 @@ struct SelectorCache {
Selector state, font, type;///< Used by controls
// window
Selector cursor, max; ///< Used by EditControl
- // mark, who
+ Selector mark; //< Used by list controls
+ Selector sort; //< Used by list controls (script internal, is needed by us for QfG3 import room)
+ // who
Selector message; ///< Used by GetEvent
// edit
Selector play; ///< Play function (first function to be called)
@@ -127,8 +130,6 @@ struct SelectorCache {
// SCI1.1 Mac icon bar selectors
Selector iconIndex; ///< Used to index icon bar objects
- Selector port; // used by a hoyle 4 workaround
-
#ifdef ENABLE_SCI32
Selector data; // Used by Array()/String()
Selector picture; // Used to hold the picture ID for SCI32 pictures
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index a069344d61..732f075257 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -110,6 +110,10 @@ void EngineState::reset(bool isRestoring) {
_lastSaveVirtualId = SAVEGAMEID_OFFICIALRANGE_START;
_lastSaveNewId = 0;
+ _chosenQfGImportItem = 0;
+
+ _cursorWorkaroundActive = false;
+
scriptStepCounter = 0;
scriptGCInterval = GC_INTERVAL;
}
@@ -251,7 +255,7 @@ kLanguage SciEngine::getSciLanguage() {
lang = K_LANG_ENGLISH;
if (SELECTOR(printLang) != -1) {
- lang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(printLang));
+ lang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(printLang));
if ((getSciVersion() >= SCI_VERSION_1_1) || (lang == K_LANG_NONE)) {
// If language is set to none, we use the language from the game detector.
@@ -292,7 +296,7 @@ kLanguage SciEngine::getSciLanguage() {
void SciEngine::setSciLanguage(kLanguage lang) {
if (SELECTOR(printLang) != -1)
- writeSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(printLang), lang);
+ writeSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(printLang), lang);
}
void SciEngine::setSciLanguage() {
@@ -304,7 +308,7 @@ Common::String SciEngine::strSplit(const char *str, const char *sep) {
kLanguage subLang = K_LANG_NONE;
if (SELECTOR(subtitleLang) != -1) {
- subLang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(subtitleLang));
+ subLang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(subtitleLang));
}
kLanguage secondLang;
@@ -327,7 +331,7 @@ Common::String SciEngine::strSplit(const char *str, const char *sep) {
void SciEngine::checkVocabularySwitch() {
uint16 parserLanguage = 1;
if (SELECTOR(parseLang) != -1)
- parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(parseLang));
+ parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(parseLang));
if (parserLanguage != _vocabularyLanguage) {
delete _vocabulary;
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 4f1d686b17..d0ddd5ca06 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -59,17 +59,23 @@ enum AbortGameState {
class DirSeeker {
protected:
reg_t _outbuffer;
- Common::StringArray _savefiles;
+ Common::StringArray _files;
+ Common::StringArray _virtualFiles;
Common::StringArray::const_iterator _iter;
public:
DirSeeker() {
_outbuffer = NULL_REG;
- _iter = _savefiles.begin();
+ _iter = _files.begin();
}
reg_t firstFile(const Common::String &mask, reg_t buffer, SegManager *segMan);
reg_t nextFile(SegManager *segMan);
+
+ Common::String getVirtualFilename(uint fileNumber);
+
+private:
+ void addAsVirtualFiles(Common::String title, Common::String fileMask);
};
enum {
@@ -80,11 +86,11 @@ enum {
MAX_SAVEGAME_NR = 20 /**< Maximum number of savegames */
};
-// We assume that scripts give us savegameId 0->999 for creating a new save slot
-// and savegameId 1000->1999 for existing save slots ffs. kfile.cpp
+// We assume that scripts give us savegameId 0->99 for creating a new save slot
+// and savegameId 100->199 for existing save slots ffs. kfile.cpp
enum {
- SAVEGAMEID_OFFICIALRANGE_START = 1000,
- SAVEGAMEID_OFFICIALRANGE_END = 1999
+ SAVEGAMEID_OFFICIALRANGE_START = 100,
+ SAVEGAMEID_OFFICIALRANGE_END = 199
};
enum {
@@ -136,8 +142,14 @@ public:
DirSeeker _dirseeker;
- uint _lastSaveVirtualId; // last virtual id fed to kSaveGame, if no kGetSaveFiles was called inbetween
- uint _lastSaveNewId; // last newly created filename-id by kSaveGame
+ int16 _lastSaveVirtualId; // last virtual id fed to kSaveGame, if no kGetSaveFiles was called inbetween
+ int16 _lastSaveNewId; // last newly created filename-id by kSaveGame
+
+ uint _chosenQfGImportItem; // Remembers the item selected in QfG import rooms
+
+ bool _cursorWorkaroundActive; // ffs. GfxCursor::setPosition()
+ Common::Point _cursorWorkaroundPoint;
+ Common::Rect _cursorWorkaroundRect;
public:
/* VM Information */
diff --git a/engines/sci/engine/static_selectors.cpp b/engines/sci/engine/static_selectors.cpp
index aae6de01f1..ed8d4193a9 100644
--- a/engines/sci/engine/static_selectors.cpp
+++ b/engines/sci/engine/static_selectors.cpp
@@ -27,6 +27,7 @@
// them. This includes the King's Quest IV Demo and LSL3 Demo.
#include "sci/engine/kernel.h"
+#include "sci/engine/seg_manager.h"
namespace Sci {
@@ -118,6 +119,7 @@ static const SelectorRemap sciSelectorRemap[] = {
{ SCI_VERSION_1_1, SCI_VERSION_1_1, "maxScale", 106 },
{ SCI_VERSION_1_1, SCI_VERSION_1_1, "vanishingX", 107 },
{ SCI_VERSION_1_1, SCI_VERSION_1_1, "vanishingY", 108 },
+ { SCI_VERSION_1_1, SCI_VERSION_2_1, "-info-",4103 },
{ SCI_VERSION_NONE, SCI_VERSION_NONE, 0, 0 }
};
@@ -133,8 +135,12 @@ Common::StringArray Kernel::checkStaticSelectorNames() {
// Resize the list of selector names and fill in the SCI 0 names.
names.resize(count);
- for (int i = 0; i < offset; i++)
- names[i].clear();
+ if (getSciVersion() < SCI_VERSION_1_1) {
+ // Fill selectors 0 - 2 for SCI0 - SCI1 late
+ names[0] = "species";
+ names[1] = "superClass";
+ names[2] = "-info-";
+ }
if (getSciVersion() <= SCI_VERSION_1_1) {
// SCI0 - SCI11
@@ -149,14 +155,82 @@ Common::StringArray Kernel::checkStaticSelectorNames() {
names[i] = sci1Selectors[i - count];
}
- for (const SelectorRemap *selectorRemap = sciSelectorRemap; selectorRemap->slot; ++selectorRemap) {
- if (getSciVersion() >= selectorRemap->minVersion && getSciVersion() <= selectorRemap->maxVersion) {
- const uint32 slot = selectorRemap->slot;
- if (slot >= names.size())
- names.resize(slot + 1);
- names[slot] = selectorRemap->name;
+ // Now, we need to find out selectors which keep changing place...
+ // We do that by dissecting game objects, and looking for selectors at
+ // specified locations.
+
+ // We need to initialize script 0 here, to make sure that it's always
+ // located at segment 1.
+ _segMan->instantiateScript(0);
+
+ // The Actor class contains the init, xLast and yLast selectors, which
+ // we reference directly. It's always in script 998, so we need to
+ // explicitly load it here.
+ if (_resMan->testResource(ResourceId(kResourceTypeScript, 998))) {
+ _segMan->instantiateScript(998);
+
+ const Object *actorClass = _segMan->getObject(_segMan->findObjectByName("Actor"));
+
+ if (actorClass) {
+ // The init selector is always the first function
+ int initSelectorPos = actorClass->getFuncSelector(0);
+
+ if (names.size() < (uint32)initSelectorPos + 2)
+ names.resize((uint32)initSelectorPos + 2);
+
+ names[initSelectorPos] = "init";
+ // dispose comes right after init
+ names[initSelectorPos + 1] = "dispose";
+
+ if ((getSciVersion() >= SCI_VERSION_1_EGA)) {
+ // Find the xLast and yLast selectors, used in kDoBresen
+
+ // xLast and yLast always come between illegalBits and xStep
+ int illegalBitsSelectorPos = actorClass->locateVarSelector(_segMan, 15 + offset); // illegalBits
+ int xStepSelectorPos = actorClass->locateVarSelector(_segMan, 51 + offset); // xStep
+ if (xStepSelectorPos - illegalBitsSelectorPos != 3) {
+ error("illegalBits and xStep selectors aren't found in "
+ "known locations. illegalBits = %d, xStep = %d",
+ illegalBitsSelectorPos, xStepSelectorPos);
+ }
+
+ int xLastSelectorPos = actorClass->getVarSelector(illegalBitsSelectorPos + 1);
+ int yLastSelectorPos = actorClass->getVarSelector(illegalBitsSelectorPos + 2);
+
+ if (names.size() < (uint32)yLastSelectorPos + 1)
+ names.resize((uint32)yLastSelectorPos + 1);
+
+ names[xLastSelectorPos] = "xLast";
+ names[yLastSelectorPos] = "yLast";
+ } // if ((getSciVersion() >= SCI_VERSION_1_EGA))
+ } // if (actorClass)
+
+ _segMan->uninstantiateScript(998);
+ } // if (_resMan->testResource(ResourceId(kResourceTypeScript, 998)))
+
+ if (_resMan->testResource(ResourceId(kResourceTypeScript, 981))) {
+ // The SysWindow class contains the open selectors, which we
+ // reference directly. It's always in script 981, so we need to
+ // explicitly load it here
+ _segMan->instantiateScript(981);
+
+ const Object *sysWindowClass = _segMan->getObject(_segMan->findObjectByName("SysWindow"));
+
+ if (sysWindowClass) {
+ if (sysWindowClass->getMethodCount() < 2)
+ error("The SysWindow class has less than 2 methods");
+
+ // The open selector is always the second function
+ int openSelectorPos = sysWindowClass->getFuncSelector(1);
+
+ if (names.size() < (uint32)openSelectorPos + 1)
+ names.resize((uint32)openSelectorPos + 1);
+
+ names[openSelectorPos] = "open";
}
- }
+
+ _segMan->uninstantiateScript(981);
+ } // if (_resMan->testResource(ResourceId(kResourceTypeScript, 981)))
if (g_sci->getGameId() == GID_HOYLE4) {
// The demo of Hoyle 4 is one of the few demos with lip syncing and no selector vocabulary.
@@ -168,21 +242,26 @@ Common::StringArray Kernel::checkStaticSelectorNames() {
names[274] = "syncTime";
names[275] = "syncCue";
- } else if (g_sci->getGameId() == GID_ISLANDBRAIN) {
- // The demo of Island of Dr. Brain needs the init selector set to match up with the full
- // game's workaround - bug #3035033
- if (names.size() < 111)
- names.resize(111);
+ } else if (g_sci->getGameId() == GID_PEPPER) {
+ // Same as above for the non-interactive demo of Pepper
+ if (names.size() < 539)
+ names.resize(539);
- names[110] = "init";
+ names[263] = "syncTime";
+ names[264] = "syncCue";
+ names[538] = "startText";
} else if (g_sci->getGameId() == GID_LAURABOW2) {
- // The floppy of version needs the open and changeState selectors set to match up with the
- // CD version's workarounds - bugs #3035694 and #3036291
- if (names.size() < 190)
- names.resize(190);
+ // The floppy of version needs the changeState selector set to match up with the
+ // CD version's workarounds.
+ if (names.size() < 251)
+ names.resize(251);
names[144] = "changeState";
- names[189] = "open";
+ } else if (g_sci->getGameId() == GID_CNICK_KQ) {
+ if (names.size() < 447)
+ names.resize(447);
+
+ names[446] = "say";
}
#ifdef ENABLE_SCI32
@@ -193,6 +272,15 @@ Common::StringArray Kernel::checkStaticSelectorNames() {
#endif
}
+ for (const SelectorRemap *selectorRemap = sciSelectorRemap; selectorRemap->slot; ++selectorRemap) {
+ if (getSciVersion() >= selectorRemap->minVersion && getSciVersion() <= selectorRemap->maxVersion) {
+ const uint32 slot = selectorRemap->slot;
+ if (slot >= names.size())
+ names.resize(slot + 1);
+ names[slot] = selectorRemap->name;
+ }
+ }
+
return names;
}
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 0500cc601b..7342f8ca7b 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -207,10 +207,21 @@ static reg_t validate_read_var(reg_t *r, reg_t *stack_base, int type, int max, i
// We need to find correct replacements for each situation manually
SciTrackOriginReply originReply;
SciWorkaroundSolution solution = trackOriginAndFindWorkaround(index, uninitializedReadWorkarounds, &originReply);
- if (solution.type == WORKAROUND_NONE)
+ if (solution.type == WORKAROUND_NONE) {
+#ifdef RELEASE_BUILD
+ // If we are running an official ScummVM release -> fake 0 in unknown cases
+ warning("Uninitialized read for temp %d from method %s::%s (script %d, room %d, localCall %x)",
+ index, originReply.objectName.c_str(), originReply.methodName.c_str(), originReply.scriptNr,
+ g_sci->getEngineState()->currentRoomNumber(), originReply.localCallOffset);
+
+ r[index] = NULL_REG;
+ break;
+#else
error("Uninitialized read for temp %d from method %s::%s (script %d, room %d, localCall %x)",
index, originReply.objectName.c_str(), originReply.methodName.c_str(), originReply.scriptNr,
g_sci->getEngineState()->currentRoomNumber(), originReply.localCallOffset);
+#endif
+ }
assert(solution.type == WORKAROUND_FAKE);
r[index] = make_reg(0, solution.value);
break;
@@ -295,7 +306,7 @@ bool SciEngine::checkExportBreakpoint(uint16 script, uint16 pubfunct) {
_console->DebugPrintf("Break on script %d, export %d\n", script, pubfunct);
_debugState.debugging = true;
_debugState.breakpointWasHit = true;
- return true;;
+ return true;
}
}
}
@@ -318,10 +329,10 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP
// HACK: Temporarily switch to a warning in SCI32 games until we can figure out why Torin has
// an invalid exported function.
if (getSciVersion() >= SCI_VERSION_2)
- warning("Request for invalid exported function 0x%x of script 0x%x", pubfunct, script);
+ warning("Request for invalid exported function 0x%x of script %d", pubfunct, script);
else
#endif
- error("Request for invalid exported function 0x%x of script 0x%x", pubfunct, script);
+ error("Request for invalid exported function 0x%x of script %d", pubfunct, script);
return NULL;
}
@@ -366,27 +377,24 @@ struct CallsStruct {
int type; /**< Same as ExecStack.type */
};
-bool SciEngine::checkSelectorBreakpoint(reg_t send_obj, int selector) {
- if (_debugState._activeBreakpointTypes & BREAK_SELECTOR) {
- char method_name[256];
+bool SciEngine::checkSelectorBreakpoint(BreakpointType breakpointType, reg_t send_obj, int selector) {
+ char method_name[256];
- sprintf(method_name, "%s::%s", _gamestate->_segMan->getObjectName(send_obj), getKernel()->getSelectorName(selector).c_str());
+ sprintf(method_name, "%s::%s", _gamestate->_segMan->getObjectName(send_obj), getKernel()->getSelectorName(selector).c_str());
- Common::List<Breakpoint>::const_iterator bp;
- for (bp = _debugState._breakpoints.begin(); bp != _debugState._breakpoints.end(); ++bp) {
- int cmplen = bp->name.size();
- if (bp->name.lastChar() != ':')
- cmplen = 256;
+ Common::List<Breakpoint>::const_iterator bp;
+ for (bp = _debugState._breakpoints.begin(); bp != _debugState._breakpoints.end(); ++bp) {
+ int cmplen = bp->name.size();
+ if (bp->name.lastChar() != ':')
+ cmplen = 256;
- if (bp->type == BREAK_SELECTOR && !strncmp(bp->name.c_str(), method_name, cmplen)) {
- _console->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj));
- _debugState.debugging = true;
- _debugState.breakpointWasHit = true;
- return true;
- }
+ if (bp->type == breakpointType && !strncmp(bp->name.c_str(), method_name, cmplen)) {
+ _console->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj));
+ _debugState.debugging = true;
+ _debugState.breakpointWasHit = true;
+ return true;
}
}
-
return false;
}
@@ -399,12 +407,13 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
int selector;
int argc;
int origin = s->_executionStack.size()-1; // Origin: Used for debugging
- bool printSendActions = false;
// We return a pointer to the new active ExecStack
// The selector calls we catch are stored below:
Common::Stack<CallsStruct> sendCalls;
+ int activeBreakpointTypes = g_sci->_debugState._activeBreakpointTypes;
+
while (framesize > 0) {
selector = validate_arithmetic(*argp++);
argc = validate_arithmetic(*argp);
@@ -413,9 +422,6 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
error("send_selector(): More than 0x800 arguments to function call");
}
- // Check if a breakpoint is set on this method
- printSendActions = g_sci->checkSelectorBreakpoint(send_obj, selector);
-
#ifdef VM_DEBUG_SEND
printf("Send to %04x:%04x (%s), selector %04x (%s):", PRINT_REG(send_obj),
s->_segMan->getObjectName(send_obj), selector,
@@ -439,18 +445,23 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
// argc == 0: read selector
// argc != 0: write selector
- if (printSendActions && !argc) { // read selector
- debug("[read selector]\n");
- printSendActions = false;
- }
-
- if (printSendActions && argc) {
- reg_t oldReg = *varp.getPointer(s->_segMan);
- reg_t newReg = argp[1];
- warning("[write to selector (%s:%s): change %04x:%04x to %04x:%04x]\n",
- s->_segMan->getObjectName(send_obj), g_sci->getKernel()->getSelectorName(selector).c_str(),
- PRINT_REG(oldReg), PRINT_REG(newReg));
- printSendActions = false;
+ if (!argc) {
+ // read selector
+ if (activeBreakpointTypes & BREAK_SELECTORREAD) {
+ if (g_sci->checkSelectorBreakpoint(BREAK_SELECTORREAD, send_obj, selector))
+ debug("[read selector]\n");
+ }
+ } else {
+ // write selector
+ if (activeBreakpointTypes & BREAK_SELECTORWRITE) {
+ if (g_sci->checkSelectorBreakpoint(BREAK_SELECTORWRITE, send_obj, selector)) {
+ reg_t oldReg = *varp.getPointer(s->_segMan);
+ reg_t newReg = argp[1];
+ warning("[write to selector (%s:%s): change %04x:%04x to %04x:%04x]\n",
+ s->_segMan->getObjectName(send_obj), g_sci->getKernel()->getSelectorName(selector).c_str(),
+ PRINT_REG(oldReg), PRINT_REG(newReg));
+ }
+ }
}
if (argc > 1) {
@@ -482,7 +493,35 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
case kSelectorMethod:
-#ifdef VM_DEBUG_SEND
+#ifndef VM_DEBUG_SEND
+ if (activeBreakpointTypes & BREAK_SELECTOREXEC) {
+ if (g_sci->checkSelectorBreakpoint(BREAK_SELECTOREXEC, send_obj, selector)) {
+ printf("[execute selector]");
+
+ int displaySize = 0;
+ for (int argNr = 1; argNr <= argc; argNr++) {
+ if (argNr == 1)
+ printf(" - ");
+ reg_t curParam = argp[argNr];
+ if (curParam.segment) {
+ printf("[%04x:%04x] ", PRINT_REG(curParam));
+ displaySize += 12;
+ } else {
+ printf("[%04x] ", curParam.offset);
+ displaySize += 7;
+ }
+ if (displaySize > 50) {
+ if (argNr < argc)
+ printf("...");
+ break;
+ }
+ }
+ printf("\n");
+ }
+ }
+#else // VM_DEBUG_SEND
+ if (activeBreakpointTypes & BREAK_SELECTOREXEC)
+ g_sci->checkSelectorBreakpoint(BREAK_SELECTOREXEC, send_obj, selector);
printf("Funcselector(");
for (int i = 0; i < argc; i++) {
printf("%04x:%04x", PRINT_REG(argp[i+1]));
@@ -491,31 +530,6 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
}
printf(") at %04x:%04x\n", PRINT_REG(funcp));
#endif // VM_DEBUG_SEND
- if (printSendActions) {
- printf("[invoke selector]");
-#ifndef VM_DEBUG_SEND
- int displaySize = 0;
- for (int argNr = 1; argNr <= argc; argNr++) {
- if (argNr == 1)
- printf(" - ");
- reg_t curParam = argp[argNr];
- if (curParam.segment) {
- printf("[%04x:%04x] ", PRINT_REG(curParam));
- displaySize += 12;
- } else {
- printf("[%04x] ", curParam.offset);
- displaySize += 7;
- }
- if (displaySize > 50) {
- if (argNr < argc)
- printf("...");
- break;
- }
- }
-#endif
- printf("\n");
- printSendActions = false;
- }
{
CallsStruct call;
@@ -817,7 +831,7 @@ int readPMachineInstruction(const byte *src, byte &extOpcode, int16 opparams[4])
for (int i = 0; g_opcode_formats[opcode][i]; ++i) {
//printf("Opcode: 0x%x, Opnumber: 0x%x, temp: %d\n", opcode, opcode, temp);
- assert(i < 4);
+ assert(i < 3);
switch (g_opcode_formats[opcode][i]) {
case Script_Byte:
@@ -911,7 +925,7 @@ void run_vm(EngineState *s) {
g_sci->_debugState.old_pc_offset = s->xs->addr.pc.offset;
g_sci->_debugState.old_sp = s->xs->sp;
- if (s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit())
+ if (s->abortScriptProcessing != kAbortNone)
return; // Stop processing
if (s->_executionStackPosChanged) {
@@ -942,7 +956,7 @@ void run_vm(EngineState *s) {
s->variables[VAR_PARAM] = s->xs->variables_argp;
}
- if (s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit())
+ if (s->abortScriptProcessing != kAbortNone)
return; // Stop processing
// Debug if this has been requested:
@@ -1319,7 +1333,7 @@ void run_vm(EngineState *s) {
if (validate_unsignedInteger(r_temp, compare1) && validate_unsignedInteger(s->r_acc, compare2))
s->r_acc = make_reg(0, compare1 < compare2);
else
- s->r_acc = arithmetic_lookForWorkaround(opcode, NULL, r_temp, s->r_acc);
+ s->r_acc = arithmetic_lookForWorkaround(opcode, opcodeUltWorkarounds, r_temp, s->r_acc);
}
break;
@@ -1442,7 +1456,7 @@ void run_vm(EngineState *s) {
s->_executionStackPosChanged = true;
// If a game is being loaded, stop processing
- if (s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit())
+ if (s->abortScriptProcessing != kAbortNone)
return; // Stop processing
break;
diff --git a/engines/sci/engine/workarounds.cpp b/engines/sci/engine/workarounds.cpp
index 95674ceaad..d332c64a9d 100644
--- a/engines/sci/engine/workarounds.cpp
+++ b/engines/sci/engine/workarounds.cpp
@@ -48,6 +48,8 @@ const SciWorkaroundEntry opcodeDptoaWorkarounds[] = {
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry opcodeGeWorkarounds[] = {
+ { GID_HOYLE1, 5, 213, 0, "", "export 0", -1, 0, { WORKAROUND_FAKE, 1 } }, // happens sometimes during cribbage - bug #3038433
+ { GID_MOTHERGOOSE256, 4, 998, 0, "door", "setCel", -1, 0, { WORKAROUND_FAKE, 1 } }, // after giving the king his pipe back, listening to his song and leaving the castle - bug #3051475
{ GID_PQ3, 31, 31, 0, "rm031", "init", -1, 0, { WORKAROUND_FAKE, 1 } }, // pq3 english: when exiting the car, while morales is making phonecalls - bug #3037565
SCI_WORKAROUNDENTRY_TERMINATOR
};
@@ -59,6 +61,12 @@ const SciWorkaroundEntry opcodeLeWorkarounds[] = {
};
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
+const SciWorkaroundEntry opcodeUltWorkarounds[] = {
+ { GID_HOYLE3, 400, 0, 1, "Character", "say", -1, 0, { WORKAROUND_FAKE, 0 } }, // While playing Pachisi, when any character starts to talk - bug #3038837
+ SCI_WORKAROUNDENTRY_TERMINATOR
+};
+
+// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry opcodeLaiWorkarounds[] = {
{ GID_CAMELOT, 92, 92, 0, "endingCartoon2", "changeState", 0x20d, 0, { WORKAROUND_FAKE, 0 } }, // during the ending, sub gets called with no parameters, uses parameter 1 which is theGrail in this case - bug #3044734
SCI_WORKAROUNDENTRY_TERMINATOR
@@ -78,37 +86,38 @@ const SciWorkaroundEntry opcodeMulWorkarounds[] = {
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry opcodeAndWorkarounds[] = {
- { GID_MOTHERGOOSE, -1, 999, 0, "Event", "new", -1, 0, { WORKAROUND_FAKE, 0 } }, // constantly during the game
- // ^^ TODO: which of the mother goose versions is affected by this? EGA? SCI1? SCI1.1?
+ { GID_MOTHERGOOSE256, -1, 999, 0, "Event", "new", -1, 0, { WORKAROUND_FAKE, 0 } }, // constantly during the game
+ // ^^ TODO: which of the mother goose versions is affected by this? EGA? SCI1? SCI1.1?
SCI_WORKAROUNDENTRY_TERMINATOR
};
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry opcodeOrWorkarounds[] = {
- { GID_ECOQUEST2, 100, 0, 0, "Rain", "points", 0xcc6, 0, { WORKAROUND_FAKE, 0 } }, // when giving the papers to the customs officer, gets called against a pointer instead of a number - bug #3034464
+ { GID_ECOQUEST2, 100, 0, 0, "Rain", "points", 0xcc6, 0, { WORKAROUND_FAKE, 0 } }, // when giving the papers to the customs officer, gets called against a pointer instead of a number - bug #3034464
+ { GID_MOTHERGOOSE256, -1, 4, 0, "rm004", "doit", -1, 0, { WORKAROUND_FAKE, 0 } }, // when going north and reaching the castle (rooms 4 and 37) - bug #3038228
SCI_WORKAROUNDENTRY_TERMINATOR
};
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry uninitializedReadWorkarounds[] = {
{ GID_CASTLEBRAIN, 280, 280, 0, "programmer", "dispatchEvent", -1, 0, { WORKAROUND_FAKE, 0xf } }, // pressing 'q' on the computer screen in the robot room, and closing the help dialog that pops up (bug #3039656). Moves the cursor to the view with the ID returned (in this case, the robot hand)
- { GID_CNICK_KQ, 200, 0, 1, "Character", "<noname446>", -1, 504, { WORKAROUND_FAKE, 0 } }, // checkers, like in hoyle 3
- { GID_CNICK_KQ, 200, 0, 1, "Character", "<noname446>", -1, 505, { WORKAROUND_FAKE, 0 } }, // checkers, like in hoyle 3
- { GID_CNICK_KQ, -1, 700, 0, "gcWindow", "<noname183>", -1, -1, { WORKAROUND_FAKE, 0 } }, // when entering control menu, like in hoyle 3
- { GID_CNICK_LONGBOW, 0, 0, 0, "RH Budget", "<noname110>", -1, 1, { WORKAROUND_FAKE, 0 } }, // when starting the game
+ { GID_CNICK_KQ, 200, 0, 1, "Character", "say", -1, -1, { WORKAROUND_FAKE, 0 } }, // checkers, like in hoyle 3 - temps 504 and 505
+ { GID_CNICK_KQ, -1, 700, 0, "gcWindow", "open", -1, -1, { WORKAROUND_FAKE, 0 } }, // when entering control menu, like in hoyle 3
+ { GID_CNICK_LONGBOW, 0, 0, 0, "RH Budget", "init", -1, 1, { WORKAROUND_FAKE, 0 } }, // when starting the game
{ GID_ECOQUEST, -1, -1, 0, NULL, "doVerb", -1, 0, { WORKAROUND_FAKE, 0 } }, // almost clicking anywhere triggers this in almost all rooms
{ GID_FANMADE, 516, 979, 0, "", "export 0", -1, 20, { WORKAROUND_FAKE, 0 } }, // Happens in Grotesteing after the logos
{ GID_FANMADE, 528, 990, 0, "GDialog", "doit", -1, 4, { WORKAROUND_FAKE, 0 } }, // Happens in Cascade Quest when closing the glossary - bug #3038757
+ { GID_FANMADE, 488, 1, 0, "RoomScript", "doit", 0x1f17, 1, { WORKAROUND_FAKE, 0 } }, // Happens in Ocean Battle while playing - bug #3059871
{ GID_FREDDYPHARKAS, -1, 24, 0, "gcWin", "open", -1, 5, { WORKAROUND_FAKE, 0xf } }, // is used as priority for game menu
{ GID_FREDDYPHARKAS, -1, 31, 0, "quitWin", "open", -1, 5, { WORKAROUND_FAKE, 0xf } }, // is used as priority for game menu
- { GID_FREDDYPHARKAS, 540, 540, 0, "WaverCode", "init", -1, -1, { WORKAROUND_FAKE, 0 } }, // Gun pratice mini-game (bug #3044218)
+ { GID_FREDDYPHARKAS, 540, 540, 0, "WaverCode", "init", -1, -1, { WORKAROUND_FAKE, 0 } }, // Gun pratice mini-game (bug #3044218)
{ GID_GK1, -1, 64950, -1, "Feature", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // sometimes when walk-clicking
{ GID_GK2, -1, 11, 0, "", "export 10", -1, 3, { WORKAROUND_FAKE, 0 } }, // called when the game starts
{ GID_GK2, -1, 11, 0, "", "export 10", -1, 4, { WORKAROUND_FAKE, 0 } }, // called during the game
{ GID_HOYLE1, 4, 104, 0, "GinRummyCardList", "calcRuns", -1, 4, { WORKAROUND_FAKE, 0 } }, // Gin Rummy / right when the game starts
{ GID_HOYLE1, 5, 204, 0, "tableau", "checkRuns", -1, 2, { WORKAROUND_FAKE, 0 } }, // Cribbage / during the game
- { GID_HOYLE3, -1, 0, 1, "Character", "say", -1, 504, { WORKAROUND_FAKE, 0 } }, // when starting checkers or dominoes, first time a character says something
- { GID_HOYLE3, -1, 0, 1, "Character", "say", -1, 505, { WORKAROUND_FAKE, 0 } }, // when starting checkers or dominoes, first time a character says something
+ { GID_HOYLE1, 3, 16, 0, "", "export 0", 0x37c, 3, { WORKAROUND_FAKE, 0 } }, // Hearts / during the game - bug #3052359
+ { GID_HOYLE3, -1, 0, 1, "Character", "say", -1, -1, { WORKAROUND_FAKE, 0 } }, // when starting checkers or dominoes, first time a character says something - temps 504 and 505
{ GID_HOYLE3, -1, 700, 0, "gcWindow", "open", -1, -1, { WORKAROUND_FAKE, 0 } }, // when entering control menu
{ GID_HOYLE4, -1, 0, 0, "gcWindow", "open", -1, -1, { WORKAROUND_FAKE, 0 } }, // when selecting "Control" from the menu (temp vars 0-3) - bug #3039294
{ GID_HOYLE4, 910, 18, 0, "Tray", "init", -1, 0, { WORKAROUND_FAKE, 0 } }, // during tutorial - bug #3042756
@@ -117,19 +126,18 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = {
{ GID_ISLANDBRAIN, 140, 140, 0, "piece", "init", -1, 3, { WORKAROUND_FAKE, 1 } }, // first puzzle right at the start, some initialization variable. bnt is done on it, and it should be non-0
{ GID_ISLANDBRAIN, 200, 268, 0, "anElement", "select", -1, 0, { WORKAROUND_FAKE, 0 } }, // elements puzzle, gets used before super TextIcon
{ GID_JONES, 1, 232, 0, "weekendText", "draw", 0x3d3, 0, { WORKAROUND_FAKE, 0 } }, // jones/cd only - gets called during the game
- { GID_JONES, 1, 255, 0, "", "export 0", -1, 13, { WORKAROUND_FAKE, 0 } }, // jones/cd only - called when a game ends
- { GID_JONES, 1, 255, 0, "", "export 0", -1, 14, { WORKAROUND_FAKE, 0 } }, // jones/cd only - called when a game ends
- { GID_JONES, 764, 255, 0, "", "export 0", -1, 13, { WORKAROUND_FAKE, 0 } }, // jones/ega&vga only - called when the game starts
- { GID_JONES, 764, 255, 0, "", "export 0", -1, 14, { WORKAROUND_FAKE, 0 } }, // jones/ega&vga only - called when the game starts
+ { GID_JONES, 1, 255, 0, "", "export 0", -1, -1, { WORKAROUND_FAKE, 0 } }, // jones/cd only - called when a game ends, temps 13 and 14
+ { GID_JONES, 764, 255, 0, "", "export 0", -1, -1, { WORKAROUND_FAKE, 0 } }, // jones/ega&vga only - called when the game starts, temps 13 and 14
//{ GID_KQ5, -1, 0, 0, "", "export 29", -1, 3, { WORKAROUND_FAKE, 0xf } }, // called when playing harp for the harpies or when aborting dialog in toy shop, is used for kDoAudio - bug #3034700
- // ^^ shouldn't be needed anymore, we got a script patch instead (kq5PatchCdHarpyVolume)
+ // ^^ shouldn't be needed anymore, we got a script patch instead (kq5PatchCdHarpyVolume)
{ GID_KQ5, 25, 25, 0, "rm025", "doit", -1, 0, { WORKAROUND_FAKE, 0 } }, // inside witch forest, when going to the room where the walking rock is
- { GID_KQ5, 55, 55, 0, "helpScript", "doit", -1, 0, { WORKAROUND_FAKE, 0 } }, // when giving the tambourine to the monster in the labyrinth (only happens at one of the locations) - bug #3041262
+ { GID_KQ5, 55, 55, 0, "helpScript", "doit", -1, 0, { WORKAROUND_FAKE, 0 } }, // when giving the tambourine to the monster in the labyrinth (only happens at one of the locations) - bug #3041262
{ GID_KQ6, -1, 30, 0, "rats", "changeState", -1, -1, { WORKAROUND_FAKE, 0 } }, // rats in the catacombs (temps 1 - 5) - bugs #3034597, #3035495, #3035824
{ GID_KQ6, 210, 210, 0, "rm210", "scriptCheck", -1, 0, { WORKAROUND_FAKE, 1 } }, // using inventory in that room - bug #3034565
{ GID_KQ6, 500, 500, 0, "rm500", "init", -1, 0, { WORKAROUND_FAKE, 0 } }, // going to island of the beast
{ GID_KQ6, 520, 520, 0, "rm520", "init", -1, 0, { WORKAROUND_FAKE, 0 } }, // going to boiling water trap on beast isle
{ GID_KQ6, -1, 903, 0, "controlWin", "open", -1, 4, { WORKAROUND_FAKE, 0 } }, // when opening the controls window (save, load etc)
+ { GID_KQ6, -1, 907, 0, "tomato", "doVerb", -1, 2, { WORKAROUND_FAKE, 0 } }, // when looking at the rotten tomato in the inventory - bug #3059544
{ GID_KQ7, 30, 64996, 0, "User", "handleEvent", -1, 1, { WORKAROUND_FAKE, 0 } }, // called when pushing a keyboard key
{ GID_LAURABOW, 37, 0, 0, "CB1", "doit", -1, 1, { WORKAROUND_FAKE, 0 } }, // when going up the stairs (bug #3037694)
{ GID_LAURABOW, -1, 967, 0, "myIcon", "cycle", -1, 1, { WORKAROUND_FAKE, 0 } }, // having any portrait conversation coming up (initial bug #3034985)
@@ -137,6 +145,7 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = {
{ GID_LAURABOW2, -1, 21, 0, "dropCluesCode", "doit", -1, 1, { WORKAROUND_FAKE, 0x7fff } }, // when asking some questions (e.g. the reporter about the burglary, or the policeman about Ziggy). Must be big, as the game scripts perform lt on it and start deleting journal entries - bugs #3035068, #3036274
{ GID_LAURABOW2, -1, 90, 1, "MuseumActor", "init", -1, 6, { WORKAROUND_FAKE, 0 } }, // Random actors in museum (bug #3041257)
{ GID_LAURABOW2, 240, 240, 0, "sSteveAnimates", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // Steve Dorian's idle animation at the docks - bug #3036291
+ { GID_LONGBOW, -1, 0, 0, "Longbow", "restart", -1, 0, { WORKAROUND_FAKE, 0 } }, // When canceling a restart game - bug #3046200
{ GID_LONGBOW, -1, 213, 0, "clear", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // When giving an answer using the druid hand sign code in any room
{ GID_LONGBOW, -1, 213, 0, "letter", "handleEvent", 0xa8, 1, { WORKAROUND_FAKE, 0 } }, // When using the druid hand sign code in any room - bug #3036601
{ GID_LSL1, 250, 250, 0, "increase", "handleEvent", -1, 2, { WORKAROUND_FAKE, 0 } }, // casino, playing game, increasing bet
@@ -150,23 +159,29 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = {
{ GID_LSL6HIRES, 0, 85, 0, "LL6Inv", "init", -1, 0, { WORKAROUND_FAKE, 0 } }, // on startup
{ GID_LSL6HIRES, -1, 64950, 1, "Feature", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // at least when entering swimming pool area
{ GID_LSL6HIRES, -1, 64964, 0, "DPath", "init", -1, 1, { WORKAROUND_FAKE, 0 } }, // during the game
- { GID_MOTHERGOOSE, -1, 0, 0, "MG", "doit", -1, 5, { WORKAROUND_FAKE, 0 } }, // SCI1.1: When moving the cursor all the way to the left during the game (bug #3043955)
- { GID_MOTHERGOOSE, 18, 992, 0, "AIPath", "init", -1, 0, { WORKAROUND_FAKE, 0 } }, // DEMO: Called when walking north from mother goose's house two screens
+ { GID_MOTHERGOOSE256, -1, 0, 0, "MG", "doit", -1, 5, { WORKAROUND_FAKE, 0 } }, // SCI1.1: When moving the cursor all the way to the left during the game (bug #3043955)
+ { GID_MOTHERGOOSE256, -1, 992, 0, "AIPath", "init", -1, 0, { WORKAROUND_FAKE, 0 } }, // Happens in the demo and full version. In the demo, it happens when walking two screens from mother goose's house to the north. In the full version, it happens in rooms 7 and 23 - bug #3049146
+ { GID_MOTHERGOOSE256, 94, 94, 0, "sunrise", "changeState", -1, 367, { WORKAROUND_FAKE, 0 } }, // At the very end, after the game is completed - bug #3051163
{ GID_MOTHERGOOSEHIRES,-1,64950, 1, "Feature", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // right when clicking on a child at the start and probably also later
{ GID_MOTHERGOOSEHIRES,-1,64950, 1, "View", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // see above
{ GID_PEPPER, -1, 894, 0, "Package", "doVerb", -1, 3, { WORKAROUND_FAKE, 0 } }, // using the hand on the book in the inventory - bug #3040012
+ { GID_PEPPER, 150, 928, 0, "Narrator", "startText", -1, 0, { WORKAROUND_FAKE, 0 } }, // happens during the non-interactive demo of Pepper
{ GID_QFG1, -1, 210, 0, "Encounter", "init", 0xbd0, 0, { WORKAROUND_FAKE, 0 } }, // hq1: going to the brigands hideout
{ GID_QFG1, -1, 210, 0, "Encounter", "init", 0xbe4, 0, { WORKAROUND_FAKE, 0 } }, // qfg1: going to the brigands hideout
+ { GID_QFG1VGA, 16, 16, 0, "lassoFailed", "changeState", -1, -1, { WORKAROUND_FAKE, 0 } }, // qfg1vga: casting the "fetch" spell in the screen with the flowers, temps 0 and 1 - bug #3053268
{ GID_QFG2, -1, 71, 0, "theInvSheet", "doit", -1, 1, { WORKAROUND_FAKE, 0 } }, // accessing the inventory
{ GID_QFG2, -1, 701, -1, "Alley", "at", -1, 0, { WORKAROUND_FAKE, 0 } }, // when walking inside the alleys in the town - bug #3035835 & #3038367
{ GID_QFG2, -1, 990, 0, "Restore", "doit", -1, 364, { WORKAROUND_FAKE, 0 } }, // when pressing enter in restore dialog w/o any saved games present
{ GID_QFG2, 260, 260, 0, "abdulS", "changeState",0x2d22, -1, { WORKAROUND_FAKE, 0 } }, // During the thief's first mission (in the house), just before Abdul is about to enter the house (where you have to hide in the wardrobe), bug #3039891, temps 1 and 2
{ GID_QFG2, 260, 260, 0, "jabbarS", "changeState",0x2d22, -1, { WORKAROUND_FAKE, 0 } }, // During the thief's first mission (in the house), just before Jabbar is about to enter the house (where you have to hide in the wardrobe), bug #3040469, temps 1 and 2
+ { GID_QFG3, 510, 510, 0, "awardPrize", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // Simbani warrior challenge, after throwing the spears and retrieving the ring - bug #3049435
{ GID_QFG3, 140, 140, 0, "rm140", "init", 0x1008, 0, { WORKAROUND_FAKE, 0 } }, // when importing a character and selecting the previous profession - bug #3040460
{ GID_QFG3, 330, 330, -1, "Teller", "doChild", -1, -1, { WORKAROUND_FAKE, 0 } }, // when talking to King Rajah about "Rajah" (bug #3036390, temp 1) or "Tarna" (temp 0), or when clicking on yourself and saying "Greet" (bug #3039774, temp 1)
{ GID_QFG3, 700, 700, -1, "monsterIsDead", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // in the jungle, after winning any fight, bug #3040624
{ GID_QFG3, 470, 470, -1, "rm470", "notify", -1, 0, { WORKAROUND_FAKE, 0 } }, // closing the character screen in the Simbani village in the room with the bridge, bug #3040565
{ GID_QFG3, 490, 490, -1, "computersMove", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // when finishing awari game, bug #3040579
+ { GID_QFG3, 490, 490, -1, "computersMove", "changeState", 0xf53, 4, { WORKAROUND_FAKE, 0 } }, // also when finishing awari game
+ { GID_QFG3, 851, 32, -1, "ProjObj", "doit", -1, 1, { WORKAROUND_FAKE, 0 } }, // near the end, when throwing the spear of death, bug #3050122
{ GID_QFG4, -1, 15, -1, "charInitScreen", "dispatchEvent", -1, 5, { WORKAROUND_FAKE, 0 } }, // floppy version, when viewing the character screen
{ GID_QFG4, -1, 64917, -1, "controlPlane", "setBitmap", -1, 3, { WORKAROUND_FAKE, 0 } }, // floppy version, when entering the game menu
{ GID_QFG4, -1, 64917, -1, "Plane", "setBitmap", -1, 3, { WORKAROUND_FAKE, 0 } }, // floppy version, happen sometimes in fights
@@ -176,7 +191,7 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = {
{ GID_SQ4, -1, 398, 0, "showBox", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // CD: called when rummaging in Software Excess bargain bin
{ GID_SQ4, -1, 928, 0, "Narrator", "startText", -1, 1000, { WORKAROUND_FAKE, 1 } }, // CD: method returns this to the caller
{ GID_SQ5, 201, 201, 0, "buttonPanel", "doVerb", -1, 0, { WORKAROUND_FAKE, 1 } }, // when looking at the orange or red button - bug #3038563
- { GID_SQ6, 100, 0, 0, "SQ6", "init", -1, 2, { WORKAROUND_FAKE, 0 } }, // called when the game starts
+ { GID_SQ6, -1, 0, 0, "SQ6", "init", -1, 2, { WORKAROUND_FAKE, 0 } }, // Demo and full version: called when the game starts (demo: room 0, full: room 100)
{ GID_SQ6, 100, 64950, 0, "View", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // called when pressing "Start game" in the main menu
{ GID_SQ6, -1, 64964, 0, "DPath", "init", -1, 1, { WORKAROUND_FAKE, 0 } }, // during the game
SCI_WORKAROUNDENTRY_TERMINATOR
@@ -196,6 +211,7 @@ const SciWorkaroundEntry kCelHigh_workarounds[] = {
{ GID_KQ5, -1, 255, 0, "deathIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // english floppy: when getting beaten up in the inn and probably more, called with 2nd parameter as object - bug #3037003
{ GID_PQ2, -1, 255, 0, "DIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // when showing picture within windows, called with 2nd/3rd parameters as objects
{ GID_SQ1, 1, 255, 0, "DIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // DEMO: Called with 2nd/3rd parameters as objects when clicking on the menu - bug #3035720
+ { GID_FANMADE, -1, 979, 0, "DIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // In The Gem Scenario and perhaps other fanmade games, this is called with 2nd/3rd parameters as objects - bug #3039679
SCI_WORKAROUNDENTRY_TERMINATOR
};
@@ -204,6 +220,7 @@ const SciWorkaroundEntry kCelWide_workarounds[] = {
{ GID_KQ5, -1, 255, 0, "deathIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // english floppy: when getting beaten up in the inn and probably more, called with 2nd parameter as object - bug #3037003
{ GID_PQ2, -1, 255, 0, "DIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // when showing picture within windows, called with 2nd/3rd parameters as objects
{ GID_SQ1, 1, 255, 0, "DIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // DEMO: Called with 2nd/3rd parameters as objects when clicking on the menu - bug #3035720
+ { GID_FANMADE, -1, 979, 0, "DIcon", "setSize", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // In The Gem Scenario and perhaps other fanmade games, this is called with 2nd/3rd parameters as objects - bug #3039679
SCI_WORKAROUNDENTRY_TERMINATOR
};
@@ -227,13 +244,18 @@ const SciWorkaroundEntry kDisplay_workarounds[] = {
{ GID_PQ2, 23, 23, 0, "rm23Script", "elements", 0x4c1, 0, { WORKAROUND_IGNORE, 0 } }, // when looking at the 2nd page of pate's file - 0x75 as id (another pq2 version, bug #3043904)
{ GID_QFG1, 11, 11, 0, "battle", "<noname90>", -1, 0, { WORKAROUND_IGNORE, 0 } }, // DEMO: When entering battle, 0x75 as id
{ GID_SQ1, -1, 700, 0, "arcadaRegion", "doit", -1, 0, { WORKAROUND_IGNORE, 0 } }, // restoring in some rooms of the arcada (right at the start)
- { GID_SQ4, 397, 0, 0, "", "export 12", -1, 0, { WORKAROUND_IGNORE, 0 } }, // FLOPPY: when going into the computer store (bug #3044044)
+ { GID_SQ4, 397, 0, 0, "", "export 12", -1, 0, { WORKAROUND_IGNORE, 0 } }, // FLOPPY: when going into the computer store (bug #3044044)
{ GID_SQ4, 391, 391, 0, "doCatalog", "mode", 0x84, 0, { WORKAROUND_IGNORE, 0 } }, // CD: clicking on catalog in roboter sale - a parameter is an object
{ GID_SQ4, 391, 391, 0, "choosePlug", "changeState", -1, 0, { WORKAROUND_IGNORE, 0 } }, // CD: ordering connector in roboter sale - a parameter is an object
SCI_WORKAROUNDENTRY_TERMINATOR
};
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
+const SciWorkaroundEntry kDirLoop_workarounds[] = {
+ { GID_KQ4, 4, 992, 0, "Avoid", "doit", -1, 0, { WORKAROUND_IGNORE, 0 } }, // when the ogre catches you in front of his house, second parameter points to the same object as the first parameter, instead of being an integer (the angle) - bug #3042964
+};
+
+// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry kDisposeScript_workarounds[] = {
{ GID_LAURABOW, 777, 777, 0, "myStab", "changeState", -1, 0, { WORKAROUND_IGNORE, 0 } }, // DEMO: after the will is signed, parameter 0 is an object - bug #3034907
{ GID_QFG1, -1, 64, 0, "rm64", "dispose", -1, 0, { WORKAROUND_IGNORE, 0 } }, // when leaving graveyard, parameter 0 is an object
@@ -292,6 +314,7 @@ const SciWorkaroundEntry kGraphRestoreBox_workarounds[] = {
{ GID_LSL6, -1, 86, 0, "LL6Inv", "show", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // happens when restoring, is called with hunk segment, but hunk is not allocated at that time
// ^^ TODO: check, if this is really a script error or an issue with our restore code
{ GID_LSL6, -1, 86, 0, "LL6Inv", "hide", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // happens during the game, gets called with 1 extra parameter
+ { GID_SQ5, 850, 850, 0, "quirksTurn", "changeState", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // happens while playing Battle Cruiser (invalid segment) - bug #3056811
SCI_WORKAROUNDENTRY_TERMINATOR
};
@@ -344,7 +367,7 @@ const SciWorkaroundEntry kMemory_workarounds[] = {
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry kNewWindow_workarounds[] = {
- { GID_ECOQUEST, -1, 981, 0, "SysWindow", "<noname178>", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // EcoQuest 1 demo uses an in-between interpreter from SCI1 to SCI1.1. It's SCI1.1, but uses the SCI1 semantics for this call - bug #3035057
+ { GID_ECOQUEST, -1, 981, 0, "SysWindow", "open", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // EcoQuest 1 demo uses an in-between interpreter from SCI1 to SCI1.1. It's SCI1.1, but uses the SCI1 semantics for this call - bug #3035057
SCI_WORKAROUNDENTRY_TERMINATOR
};
@@ -375,6 +398,12 @@ const SciWorkaroundEntry kStrAt_workarounds[] = {
};
// gameID, room,script,lvl, object-name, method-name, call,index, workaround
+const SciWorkaroundEntry kStrCat_workarounds[] = {
+ { GID_LONGBOW, 210, 210, 0, "giveScroll", "changeState",0x3294, 0, { WORKAROUND_FAKE, 0 } }, // German version, when handing the scroll with the druid hand code to Marion - bug #3048054
+ SCI_WORKAROUNDENTRY_TERMINATOR
+};
+
+// gameID, room,script,lvl, object-name, method-name, call,index, workaround
const SciWorkaroundEntry kUnLoad_workarounds[] = {
{ GID_CAMELOT, 921, 921, 1, "Script", "changeState", 0x36, 0, { WORKAROUND_IGNORE, 0 } }, // DEMO: While showing Camelot (and other places), the reference is invalid - bug #3035000
{ GID_CAMELOT, 921, 921, 1, "Script", "init", 0x36, 0, { WORKAROUND_IGNORE, 0 } }, // DEMO: When being attacked by the boar (and other places), the reference is invalid - bug #3035000
@@ -391,6 +420,7 @@ const SciWorkaroundEntry kUnLoad_workarounds[] = {
{ GID_LSL6HIRES, 130, 130, 0, "recruitLarryScr", "changeState", -1, 0, { WORKAROUND_IGNORE, 0 } }, // during intro, a 3rd parameter is passed by accident
{ GID_PQ3, 877, 998, 0, "View", "delete", -1, 0, { WORKAROUND_IGNORE, 0 } }, // when getting run over on the freeway, the reference is invalid
{ GID_SQ1, 43, 303, 0, "slotGuy", "dispose", -1, 0, { WORKAROUND_IGNORE, 0 } }, // when leaving ulence flats bar, parameter 1 is not passed - script error
+ { GID_SQ3, 2, 998, 0, "View", "delete", -1, 0, { WORKAROUND_IGNORE, 0 } }, // clicking the mouse button during the intro, after the escape pod gets pulled into the garbage freighter, the reference is invalid - bug #3050856
SCI_WORKAROUNDENTRY_TERMINATOR
};
diff --git a/engines/sci/engine/workarounds.h b/engines/sci/engine/workarounds.h
index 55a4b8f885..bf1ac3a445 100644
--- a/engines/sci/engine/workarounds.h
+++ b/engines/sci/engine/workarounds.h
@@ -72,6 +72,7 @@ extern const SciWorkaroundEntry opcodeDivWorkarounds[];
extern const SciWorkaroundEntry opcodeDptoaWorkarounds[];
extern const SciWorkaroundEntry opcodeGeWorkarounds[];
extern const SciWorkaroundEntry opcodeLeWorkarounds[];
+extern const SciWorkaroundEntry opcodeUltWorkarounds[];
extern const SciWorkaroundEntry opcodeLaiWorkarounds[];
extern const SciWorkaroundEntry opcodeLsiWorkarounds[];
extern const SciWorkaroundEntry opcodeMulWorkarounds[];
@@ -83,6 +84,7 @@ extern const SciWorkaroundEntry kCelHigh_workarounds[];
extern const SciWorkaroundEntry kCelWide_workarounds[];
extern const SciWorkaroundEntry kDeviceInfo_workarounds[];
extern const SciWorkaroundEntry kDisplay_workarounds[];
+extern const SciWorkaroundEntry kDirLoop_workarounds[];
extern const SciWorkaroundEntry kDisposeScript_workarounds[];
extern const SciWorkaroundEntry kDoSoundFade_workarounds[];
extern const SciWorkaroundEntry kFindKey_workarounds[];
@@ -101,6 +103,7 @@ extern const SciWorkaroundEntry kPaletteUnsetFlag_workarounds[];
extern const SciWorkaroundEntry kSetCursor_workarounds[];
extern const SciWorkaroundEntry kSetPort_workarounds[];
extern const SciWorkaroundEntry kStrAt_workarounds[];
+extern const SciWorkaroundEntry kStrCat_workarounds[];
extern const SciWorkaroundEntry kUnLoad_workarounds[];
extern SciWorkaroundSolution trackOriginAndFindWorkaround(int index, const SciWorkaroundEntry *workaroundList, SciTrackOriginReply *trackOrigin);
diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp
index 5923e501cf..5d469eda7b 100644
--- a/engines/sci/event.cpp
+++ b/engines/sci/event.cpp
@@ -149,7 +149,7 @@ SciEvent EventManager::getScummVMEvent() {
found = em->pollEvent(ev);
}
- if (found && !ev.synthetic && ev.type != Common::EVENT_MOUSEMOVE) {
+ if (found && ev.type != Common::EVENT_MOUSEMOVE) {
int modifiers = em->getModifierState();
// We add the modifier key status to buckybits
@@ -215,6 +215,11 @@ SciEvent EventManager::getScummVMEvent() {
else
input.character = SCI_KEY_TAB;
}
+ if (input.data == Common::KEYCODE_DELETE) {
+ // Delete key
+ input.type = SCI_EVENT_KEYBOARD;
+ input.data = input.character = SCI_KEY_DELETE;
+ }
} else if ((input.data >= Common::KEYCODE_F1) && input.data <= Common::KEYCODE_F10) {
// F1-F10
input.type = SCI_EVENT_KEYBOARD;
@@ -346,9 +351,17 @@ SciEvent EventManager::getScummVMEvent() {
void EventManager::updateScreen() {
// Update the screen here, since it's called very often.
// Throttle the screen update rate to 60fps.
- if (g_system->getMillis() - g_sci->getEngineState()->_screenUpdateTime >= 1000 / 60) {
+ EngineState *s = g_sci->getEngineState();
+ if (g_system->getMillis() - s->_screenUpdateTime >= 1000 / 60) {
g_system->updateScreen();
- g_sci->getEngineState()->_screenUpdateTime = g_system->getMillis();
+ s->_screenUpdateTime = g_system->getMillis();
+ // Throttle the checking of shouldQuit() to 60fps as well, since
+ // Engine::shouldQuit() invokes 2 virtual functions
+ // (EventManager::shouldQuit() and EventManager::shouldRTL()),
+ // which is very expensive to invoke constantly without any
+ // throttling at all.
+ if (g_engine->shouldQuit())
+ s->abortScriptProcessing = kAbortQuitGame;
}
}
diff --git a/engines/sci/graphics/animate.cpp b/engines/sci/graphics/animate.cpp
index b962e819a6..62c5f9c19e 100644
--- a/engines/sci/graphics/animate.cpp
+++ b/engines/sci/graphics/animate.cpp
@@ -96,7 +96,7 @@ bool GfxAnimate::invoke(List *list, int argc, reg_t *argv) {
invokeSelector(_s, curObject, SELECTOR(doit), argc, argv, 0);
// If a game is being loaded, stop processing
- if (_s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit())
+ if (_s->abortScriptProcessing != kAbortNone)
return true; // Stop processing
// Lookup node again, since the nodetable it was in may have been reallocated.
@@ -141,6 +141,7 @@ void GfxAnimate::makeSortedList(List *list) {
AnimateEntry listEntry;
const reg_t curObject = curNode->value;
listEntry.object = curObject;
+ listEntry.castHandle = NULL_REG;
// Get data from current object
listEntry.givenOrderNo = listNr;
@@ -190,6 +191,34 @@ void GfxAnimate::makeSortedList(List *list) {
Common::sort(_list.begin(), _list.end(), sortHelper);
}
+void GfxAnimate::applyGlobalScaling(AnimateList::iterator entry, GfxView *view) {
+ reg_t curObject = entry->object;
+
+ // Global scaling uses global var 2 and some other stuff to calculate scaleX/scaleY
+ int16 maxScale = readSelectorValue(_s->_segMan, curObject, SELECTOR(maxScale));
+ int16 celHeight = view->getHeight(entry->loopNo, entry->celNo);
+ int16 maxCelHeight = (maxScale * celHeight) >> 7;
+ reg_t globalVar2 = _s->variables[VAR_GLOBAL][2]; // current room object
+ int16 vanishingY = readSelectorValue(_s->_segMan, globalVar2, SELECTOR(vanishingY));
+
+ int16 fixedPortY = _ports->getPort()->rect.bottom - vanishingY;
+ int16 fixedEntryY = entry->y - vanishingY;
+ if (!fixedEntryY)
+ fixedEntryY = 1;
+
+ if ((celHeight == 0) || (fixedPortY == 0))
+ error("global scaling panic");
+
+ entry->scaleY = ( maxCelHeight * fixedEntryY ) / fixedPortY;
+ entry->scaleY = (entry->scaleY * 128) / celHeight;
+
+ entry->scaleX = entry->scaleY;
+
+ // and set objects scale selectors
+ writeSelectorValue(_s->_segMan, curObject, SELECTOR(scaleX), entry->scaleX);
+ writeSelectorValue(_s->_segMan, curObject, SELECTOR(scaleY), entry->scaleY);
+}
+
void GfxAnimate::fill(byte &old_picNotValid, bool maySetNsRect) {
reg_t curObject;
uint16 signal;
@@ -229,44 +258,22 @@ void GfxAnimate::fill(byte &old_picNotValid, bool maySetNsRect) {
it->celNo = viewCelCount - 1;
}
- // Process global scaling, if needed
- if (it->scaleSignal & kScaleSignalDoScaling) {
- if (it->scaleSignal & kScaleSignalGlobalScaling) {
- // Global scaling uses global var 2 and some other stuff to calculate scaleX/scaleY
- int16 maxScale = readSelectorValue(_s->_segMan, curObject, SELECTOR(maxScale));
- int16 celHeight = view->getHeight(it->loopNo, it->celNo);
- int16 maxCelHeight = (maxScale * celHeight) >> 7;
- reg_t globalVar2 = _s->variables[VAR_GLOBAL][2]; // current room object
- int16 vanishingY = readSelectorValue(_s->_segMan, globalVar2, SELECTOR(vanishingY));
-
- int16 fixedPortY = _ports->getPort()->rect.bottom - vanishingY;
- int16 fixedEntryY = it->y - vanishingY;
- if (!fixedEntryY)
- fixedEntryY = 1;
-
- if ((celHeight == 0) || (fixedPortY == 0))
- error("global scaling panic");
-
- it->scaleY = ( maxCelHeight * fixedEntryY ) / fixedPortY;
- it->scaleY = (it->scaleY * 128) / celHeight;
-
- it->scaleX = it->scaleY;
-
- // and set objects scale selectors
- writeSelectorValue(_s->_segMan, curObject, SELECTOR(scaleX), it->scaleX);
- writeSelectorValue(_s->_segMan, curObject, SELECTOR(scaleY), it->scaleY);
- }
- }
-
- //warning("%s view %d, loop %d, cel %d", _s->_segMan->getObjectName(curObject), it->viewId, it->loopNo, it->celNo);
-
if (!view->isScaleable()) {
// Laura Bow 2 (especially floppy) depends on this, some views are not supposed to be scaleable
// this "feature" was removed in later versions of SCI1.1
it->scaleSignal = 0;
it->scaleY = it->scaleX = 128;
+ } else {
+ // Process global scaling, if needed
+ if (it->scaleSignal & kScaleSignalDoScaling) {
+ if (it->scaleSignal & kScaleSignalGlobalScaling) {
+ applyGlobalScaling(it, view);
+ }
+ }
}
+ //warning("%s view %d, loop %d, cel %d, signal %x", _s->_segMan->getObjectName(curObject), it->viewId, it->loopNo, it->celNo, it->signal);
+
bool setNsRect = maySetNsRect;
// Create rect according to coordinates and given cel
@@ -278,6 +285,16 @@ void GfxAnimate::fill(byte &old_picNotValid, bool maySetNsRect) {
} else {
view->getCelRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->celRect);
}
+
+ // This statement must be here for Hoyle4, otherwise cards are unclickable.
+ // This is probably one of the experimental features that were occasionally
+ // added to SCI interpreters; the corresponding check is absent in many SSCI
+ // versions. m_kiewitz knew about this flag before I (lskovlun) implemented it,
+ // so it is possible that more test cases are known. Also, some presently open
+ // SCI1.1 bugs may be fixed by this and should be re-tested with this patch generalized.
+ if (it->scaleSignal & kScaleSignalDontSetNsrect)
+ setNsRect = false;
+
if (setNsRect) {
writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsLeft), it->celRect.left);
writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsTop), it->celRect.top);
@@ -533,19 +550,6 @@ void GfxAnimate::reAnimate(Common::Rect rect) {
}
}
-void GfxAnimate::preprocessAddToPicList() {
- AnimateList::iterator it;
- const AnimateList::iterator end = _list.end();
-
- for (it = _list.begin(); it != end; ++it) {
- if (it->priority == -1)
- it->priority = _ports->kernelCoordinateToPriority(it->y);
-
- // Do not allow priority to get changed by fill()
- it->signal |= kSignalFixedPriority;
- }
-}
-
void GfxAnimate::addToPicDrawCels() {
reg_t curObject;
GfxView *view = NULL;
@@ -558,8 +562,31 @@ void GfxAnimate::addToPicDrawCels() {
// Get the corresponding view
view = _cache->getView(it->viewId);
+ // kAddToPic does not do loop/cel-number fixups, it also doesn't support global scaling
+
+ if (it->priority == -1)
+ it->priority = _ports->kernelCoordinateToPriority(it->y);
+
+ if (!view->isScaleable()) {
+ // Laura Bow 2 specific - ffs. fill()
+ it->scaleSignal = 0;
+ it->scaleY = it->scaleX = 128;
+ }
+
+ // Create rect according to coordinates and given cel
+ if (it->scaleSignal & kScaleSignalDoScaling) {
+ applyGlobalScaling(it, view);
+ view->getCelScaledRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->scaleX, it->scaleY, it->celRect);
+ writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsLeft), it->celRect.left);
+ writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsTop), it->celRect.top);
+ writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsRight), it->celRect.right);
+ writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsBottom), it->celRect.bottom);
+ } else {
+ view->getCelRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->celRect);
+ }
+
// draw corresponding cel
- _paint16->drawCel(it->viewId, it->loopNo, it->celNo, it->celRect, it->priority, it->paletteNo, it->scaleX, it->scaleY);
+ _paint16->drawCel(view, it->loopNo, it->celNo, it->celRect, it->priority, it->paletteNo, it->scaleX, it->scaleY);
if ((it->signal & kSignalIgnoreActor) == 0) {
it->celRect.top = CLIP<int16>(_ports->kernelPriorityToCoordinate(it->priority) - 1, it->celRect.top, it->celRect.bottom - 1);
_paint16->fillRect(it->celRect, GFX_SCREEN_MASK_CONTROL, 0, 0, 15);
@@ -677,6 +704,7 @@ void GfxAnimate::kernelAnimate(reg_t listReference, bool cycle, int argc, reg_t
int16 onlyWidth = onlyCast->celRect.width();
if (((onlyWidth == 12) && (onlyHeight == 35)) || // regular benchmark view ("fred", "Speedy", "ego")
((onlyWidth == 29) && (onlyHeight == 45)) || // King's Quest 5 french "fred"
+ ((onlyWidth == 1) && (onlyHeight == 5)) || // Freddy Pharkas "fred"
((onlyWidth == 1) && (onlyHeight == 1))) { // Laura Bow 2 Talkie
// check further that there is only one cel in that view
GfxView *onlyView = _cache->getView(onlyCast->viewId);
@@ -703,7 +731,6 @@ void GfxAnimate::addToPicSetPicNotValid() {
void GfxAnimate::kernelAddToPicList(reg_t listReference, int argc, reg_t *argv) {
List *list;
- byte tempPicNotValid = 0;
_ports->setPort((Port *)_ports->_picWind);
@@ -712,8 +739,6 @@ void GfxAnimate::kernelAddToPicList(reg_t listReference, int argc, reg_t *argv)
error("kAddToPic called with non-list as parameter");
makeSortedList(list);
- preprocessAddToPicList();
- fill(tempPicNotValid, getSciVersion() >= SCI_VERSION_1_1 ? true : false);
addToPicDrawCels();
addToPicSetPicNotValid();
diff --git a/engines/sci/graphics/animate.h b/engines/sci/graphics/animate.h
index f25e54915e..23e7a624d8 100644
--- a/engines/sci/graphics/animate.h
+++ b/engines/sci/graphics/animate.h
@@ -53,7 +53,8 @@ enum ViewSignals {
enum ViewScaleSignals {
kScaleSignalDoScaling = 0x0001, // enables scaling when drawing that cel (involves scaleX and scaleY)
kScaleSignalGlobalScaling = 0x0002, // means that global scaling shall get applied on that cel (sets scaleX/scaleY)
- kScaleSignalUnknown2 = 0x0004 // really unknown
+ kScaleSignalDontSetNsrect = 0x0004 // do not set nsRect inside kAnimate(); for a test case see bug #3038424
+
};
struct AnimateEntry {
@@ -83,6 +84,7 @@ class GfxPaint16;
class GfxScreen;
class GfxPalette;
class GfxTransitions;
+class GfxView;
/**
* Animate class, kAnimate and relevant functions for SCI16 (SCI0-SCI1.1) games
*/
@@ -94,13 +96,13 @@ public:
void disposeLastCast();
bool invoke(List *list, int argc, reg_t *argv);
void makeSortedList(List *list);
+ void applyGlobalScaling(AnimateList::iterator entry, GfxView *view);
void fill(byte &oldPicNotValid, bool maySetNsRect);
void update();
void drawCels();
void updateScreen(byte oldPicNotValid);
void restoreAndDelete(int argc, reg_t *argv);
void reAnimate(Common::Rect rect);
- void preprocessAddToPicList();
void addToPicDrawCels();
void addToPicDrawView(GuiResourceId viewId, int16 loopNo, int16 celNo, int16 leftPos, int16 topPos, int16 priority, int16 control);
diff --git a/engines/sci/graphics/compare.cpp b/engines/sci/graphics/compare.cpp
index 1c961b2ad6..6a99d2384e 100644
--- a/engines/sci/graphics/compare.cpp
+++ b/engines/sci/graphics/compare.cpp
@@ -185,9 +185,9 @@ reg_t GfxCompare::kernelCanBeHere(reg_t curObject, reg_t listReference) {
checkRect.right = readSelectorValue(_segMan, curObject, SELECTOR(brRight));
checkRect.bottom = readSelectorValue(_segMan, curObject, SELECTOR(brBottom));
- if (!checkRect.isValidRect()) { // can occur in Iceman - HACK? TODO: is this really occuring in sierra sci? check this
+ if (!checkRect.isValidRect()) { // can occur in Iceman and Mother Goose - HACK? TODO: is this really occuring in sierra sci? check this
warning("kCan(t)BeHere - invalid rect %d, %d -> %d, %d", checkRect.left, checkRect.top, checkRect.right, checkRect.bottom);
- return NULL_REG;
+ return NULL_REG; // this means "can be here"
}
adjustedRect = _coordAdjuster->onControl(checkRect);
@@ -237,20 +237,24 @@ void GfxCompare::kernelBaseSetter(reg_t object) {
Common::Rect celRect;
GfxView *tmpView = _cache->getView(viewId);
- if (tmpView->isSci2Hires())
- _screen->adjustToUpscaledCoordinates(y, x);
+ if (!tmpView->isScaleable())
+ scaleSignal = 0;
if (scaleSignal & kScaleSignalDoScaling) {
- int16 scaleX = readSelectorValue(_segMan, object, SELECTOR(scaleX));
- int16 scaleY = readSelectorValue(_segMan, object, SELECTOR(scaleY));
- tmpView->getCelScaledRect(loopNo, celNo, x, y, z, scaleX, scaleY, celRect);
+ celRect.left = readSelectorValue(_segMan, object, SELECTOR(nsLeft));
+ celRect.right = readSelectorValue(_segMan, object, SELECTOR(nsRight));
+ celRect.top = readSelectorValue(_segMan, object, SELECTOR(nsTop));
+ celRect.bottom = readSelectorValue(_segMan, object, SELECTOR(nsBottom));
} else {
+ if (tmpView->isSci2Hires())
+ _screen->adjustToUpscaledCoordinates(y, x);
+
tmpView->getCelRect(loopNo, celNo, x, y, z, celRect);
- }
- if (tmpView->isSci2Hires()) {
- _screen->adjustBackUpscaledCoordinates(celRect.top, celRect.left);
- _screen->adjustBackUpscaledCoordinates(celRect.bottom, celRect.right);
+ if (tmpView->isSci2Hires()) {
+ _screen->adjustBackUpscaledCoordinates(celRect.top, celRect.left);
+ _screen->adjustBackUpscaledCoordinates(celRect.bottom, celRect.right);
+ }
}
celRect.bottom = y + 1;
diff --git a/engines/sci/graphics/controls.cpp b/engines/sci/graphics/controls.cpp
index 5891413be8..66376a793c 100644
--- a/engines/sci/graphics/controls.cpp
+++ b/engines/sci/graphics/controls.cpp
@@ -150,7 +150,7 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
uint16 maxChars = readSelectorValue(_segMan, controlObject, SELECTOR(max));
reg_t textReference = readSelector(_segMan, controlObject, SELECTOR(text));
Common::String text;
- uint16 textSize, eventType, eventKey = 0;
+ uint16 textSize, eventType, eventKey = 0, modifiers = 0;
bool textChanged = false;
bool textAddChar = false;
Common::Rect rect;
@@ -159,6 +159,8 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
error("kEditControl called on object that doesnt have a text reference");
text = _segMan->getString(textReference);
+ uint16 oldCursorPos = cursorPos;
+
if (!eventObject.isNull()) {
textSize = text.size();
eventType = readSelectorValue(_segMan, eventObject, SELECTOR(type));
@@ -169,6 +171,7 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
break;
case SCI_EVENT_KEYBOARD:
eventKey = readSelectorValue(_segMan, eventObject, SELECTOR(message));
+ modifiers = readSelectorValue(_segMan, eventObject, SELECTOR(modifiers));
switch (eventKey) {
case SCI_KEY_BACKSPACE:
if (cursorPos > 0) {
@@ -177,8 +180,10 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
}
break;
case SCI_KEY_DELETE:
- text.deleteChar(cursorPos);
- textChanged = true;
+ if (cursorPos < textSize) {
+ text.deleteChar(cursorPos);
+ textChanged = true;
+ }
break;
case SCI_KEY_HOME: // HOME
cursorPos = 0; textChanged = true;
@@ -196,8 +201,20 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
cursorPos++; textChanged = true;
}
break;
+ case 3: // returned in SCI1 late and newer when Control - C is pressed
+ if (modifiers & SCI_KEYMOD_CTRL) {
+ // Control-C erases the whole line
+ cursorPos = 0; text.clear();
+ textChanged = true;
+ }
+ break;
default:
- if (eventKey > 31 && eventKey < 256 && textSize < maxChars) {
+ if ((modifiers & SCI_KEYMOD_CTRL) && eventKey == 99) {
+ // Control-C in earlier SCI games (SCI0 - SCI1 middle)
+ // Control-C erases the whole line
+ cursorPos = 0; text.clear();
+ textChanged = true;
+ } else if (eventKey > 31 && eventKey < 256 && textSize < maxChars) {
// insert pressed character
textAddChar = true;
textChanged = true;
@@ -208,6 +225,11 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
}
}
+ if (g_sci->getVocabulary() && !textChanged && oldCursorPos != cursorPos) {
+ assert(!textAddChar);
+ textChanged = g_sci->getVocabulary()->checkAltInput(text, cursorPos);
+ }
+
if (textChanged) {
GuiResourceId oldFontId = _text16->GetFontId();
GuiResourceId fontId = readSelectorValue(_segMan, controlObject, SELECTOR(font));
@@ -215,18 +237,28 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
readSelectorValue(_segMan, controlObject, SELECTOR(nsRight)), readSelectorValue(_segMan, controlObject, SELECTOR(nsBottom)));
_text16->SetFont(fontId);
if (textAddChar) {
- // We check, if we are really able to add the new char
- uint16 textWidth = 0;
+
const char *textPtr = text.c_str();
+
+ // We check if we are really able to add the new char
+ uint16 textWidth = 0;
while (*textPtr)
- textWidth += _text16->_font->getCharWidth(*textPtr++);
+ textWidth += _text16->_font->getCharWidth((byte)*textPtr++);
textWidth += _text16->_font->getCharWidth(eventKey);
+
+ // Does it fit?
if (textWidth >= rect.width()) {
_text16->SetFont(oldFontId);
return;
}
+
text.insertChar(eventKey, cursorPos++);
+
+ // Note: the following checkAltInput call might make the text
+ // too wide to fit, but SSCI fails to check that too.
}
+ if (g_sci->getVocabulary())
+ g_sci->getVocabulary()->checkAltInput(text, cursorPos);
texteditCursorErase();
_paint16->eraseRect(rect);
_text16->Box(text.c_str(), 0, rect, SCI_TEXT16_ALIGNMENT_LEFT, -1);
diff --git a/engines/sci/graphics/cursor.cpp b/engines/sci/graphics/cursor.cpp
index a906899113..7a37d7e865 100644
--- a/engines/sci/graphics/cursor.cpp
+++ b/engines/sci/graphics/cursor.cpp
@@ -49,10 +49,21 @@ GfxCursor::GfxCursor(ResourceManager *resMan, GfxPalette *palette, GfxScreen *sc
// center mouse cursor
setPosition(Common::Point(_screen->getWidth() / 2, _screen->getHeight() / 2));
_moveZoneActive = false;
+
+ _zoomZoneActive = false;
+ _zoomZone = Common::Rect();
+ _zoomCursorView = 0;
+ _zoomCursorLoop = 0;
+ _zoomCursorCel = 0;
+ _zoomPicView = 0;
+ _zoomColor = 0;
+ _zoomMultiplier = 0;
+ _cursorSurface = 0;
}
GfxCursor::~GfxCursor() {
purgeCache();
+ kernelClearZoomZone();
}
void GfxCursor::init(GfxCoordAdjuster *coordAdjuster, EventManager *event) {
@@ -266,6 +277,16 @@ void GfxCursor::kernelSetMacCursor(GuiResourceId viewNum, int loopNum, int celNu
kernelShow();
}
+// this list contains all mandatory set cursor changes, that need special handling
+// ffs. GfxCursor::setPosition (below)
+// Game, newPosition, validRect
+static const SciCursorSetPositionWorkarounds setPositionWorkarounds[] = {
+ { GID_ISLANDBRAIN, 84, 109, 46, 76, 174, 243 }, // island of dr. brain / game menu
+ { GID_LSL5, 23, 171, 0, 0, 26, 320 }, // larry 5 / skip forward helper
+ { GID_QFG1VGA, 64, 174, 40, 37, 74, 284 }, // Quest For Glory 1 VGA / run/walk/sleep sub-menu
+ { (SciGameId)0, -1, -1, -1, -1, -1, -1 }
+};
+
void GfxCursor::setPosition(Common::Point pos) {
// Don't set position, when cursor is not visible.
// This fixes eco quest 1 (floppy) right at the start, which is setting
@@ -282,6 +303,31 @@ void GfxCursor::setPosition(Common::Point pos) {
_screen->adjustToUpscaledCoordinates(pos.y, pos.x);
g_system->warpMouse(pos.x, pos.y);
}
+
+ // Some games display a new menu, set mouse position somewhere within and
+ // expect it to be in there. This is fine for a real mouse, but on wii using
+ // wii-mote or touch interfaces this won't work. In fact on those platforms
+ // the menus will close immediately because of that behaviour.
+ // We identify those cases and set a reaction-rect. If the mouse it outside
+ // of that rect, we won't report the position back to the scripts.
+ // As soon as the mouse was inside once, we will revert to normal behaviour
+ // Currently this code is enabled for all platforms, especially because we can't
+ // differentiate between e.g. Windows used via mouse and Windows used via touchscreen
+ // The workaround won't hurt real-mouse platforms
+ const SciGameId gameId = g_sci->getGameId();
+ const SciCursorSetPositionWorkarounds *workaround;
+ workaround = setPositionWorkarounds;
+ while (workaround->newPositionX != -1) {
+ if (workaround->gameId == gameId
+ && ((workaround->newPositionX == pos.x) && (workaround->newPositionY == pos.y))) {
+ EngineState *s = g_sci->getEngineState();
+ s->_cursorWorkaroundActive = true;
+ s->_cursorWorkaroundPoint = pos;
+ s->_cursorWorkaroundRect = Common::Rect(workaround->rectLeft, workaround->rectTop, workaround->rectRight, workaround->rectBottom);
+ return;
+ }
+ workaround++;
+ }
}
Common::Point GfxCursor::getPosition() {
@@ -294,9 +340,10 @@ Common::Point GfxCursor::getPosition() {
}
void GfxCursor::refreshPosition() {
+ Common::Point mousePoint = getPosition();
+
if (_moveZoneActive) {
bool clipped = false;
- Common::Point mousePoint = getPosition();
if (mousePoint.x < _moveZone.left) {
mousePoint.x = _moveZone.left;
@@ -318,6 +365,52 @@ void GfxCursor::refreshPosition() {
if (clipped)
setPosition(mousePoint);
}
+
+ if (_zoomZoneActive) {
+ // Cursor
+ const CelInfo *cursorCelInfo = _zoomCursorView->getCelInfo(_zoomCursorLoop, _zoomCursorCel);
+ const byte *cursorBitmap = _zoomCursorView->getBitmap(_zoomCursorLoop, _zoomCursorCel);
+ // Pic
+ const CelInfo *picCelInfo = _zoomPicView->getCelInfo(0, 0);
+ const byte *rawPicBitmap = _zoomPicView->getBitmap(0, 0);
+
+ // Compute hotspot of cursor
+ Common::Point cursorHotspot = Common::Point((cursorCelInfo->width >> 1) - cursorCelInfo->displaceX, cursorCelInfo->height - cursorCelInfo->displaceY - 1);
+
+ int16 targetX = ((mousePoint.x - _moveZone.left) * _zoomMultiplier);
+ int16 targetY = ((mousePoint.y - _moveZone.top) * _zoomMultiplier);
+ if (targetX < 0)
+ targetX = 0;
+ if (targetY < 0)
+ targetY = 0;
+
+ targetX -= cursorHotspot.x;
+ targetY -= cursorHotspot.y;
+
+ // Sierra SCI actually drew only within zoom area, thus removing the need to fill any other pixels with upmost/left
+ // color of the picture cel. This also made the cursor not appear on top of everything. They actually drew the
+ // cursor manually within kAnimate processing and used a hidden cursor for moving.
+ // TODO: we should also do this
+
+ // Replace the special magnifier color with the associated magnified pixels
+ for (int x = 0; x < cursorCelInfo->width; x++) {
+ for (int y = 0; y < cursorCelInfo->height; y++) {
+ int curPos = cursorCelInfo->width * y + x;
+ if (cursorBitmap[curPos] == _zoomColor) {
+ int16 rawY = targetY + y;
+ int16 rawX = targetX + x;
+ if ((rawY >= 0) && (rawY < picCelInfo->height) && (rawX >= 0) && (rawX < picCelInfo->width)) {
+ int rawPos = picCelInfo->width * rawY + rawX;
+ _cursorSurface[curPos] = rawPicBitmap[rawPos];
+ } else {
+ _cursorSurface[curPos] = rawPicBitmap[0]; // use left and upmost pixel color
+ }
+ }
+ }
+ }
+
+ CursorMan.replaceCursor((const byte *)_cursorSurface, cursorCelInfo->width, cursorCelInfo->height, cursorHotspot.x, cursorHotspot.y, cursorCelInfo->clearKey);
+ }
}
void GfxCursor::kernelResetMoveZone() {
@@ -329,6 +422,44 @@ void GfxCursor::kernelSetMoveZone(Common::Rect zone) {
_moveZoneActive = true;
}
+void GfxCursor::kernelClearZoomZone() {
+ kernelResetMoveZone();
+ _zoomZone = Common::Rect();
+ _zoomColor = 0;
+ _zoomMultiplier = 0;
+ _zoomZoneActive = false;
+ delete _zoomCursorView;
+ _zoomCursorView = 0;
+ delete _zoomPicView;
+ _zoomPicView = 0;
+ delete[] _cursorSurface;
+ _cursorSurface = 0;
+}
+
+void GfxCursor::kernelSetZoomZone(byte multiplier, Common::Rect zone, GuiResourceId viewNum, int loopNum, int celNum, GuiResourceId picNum, byte zoomColor) {
+ kernelClearZoomZone();
+
+ _zoomMultiplier = multiplier;
+
+ if (_zoomMultiplier != 1 && _zoomMultiplier != 2 && _zoomMultiplier != 4)
+ error("Unexpected zoom multiplier (expected 1, 2 or 4)");
+
+ _zoomCursorView = new GfxView(_resMan, _screen, _palette, viewNum);
+ _zoomCursorLoop = (byte)loopNum;
+ _zoomCursorCel = (byte)celNum;
+ _zoomPicView = new GfxView(_resMan, _screen, _palette, picNum);
+ const CelInfo *cursorCelInfo = _zoomCursorView->getCelInfo(_zoomCursorLoop, _zoomCursorCel);
+ const byte *cursorBitmap = _zoomCursorView->getBitmap(_zoomCursorLoop, _zoomCursorCel);
+ _cursorSurface = new byte[cursorCelInfo->width * cursorCelInfo->height];
+ memcpy(_cursorSurface, cursorBitmap, cursorCelInfo->width * cursorCelInfo->height);
+
+ _zoomZone = zone;
+ kernelSetMoveZone(_zoomZone);
+
+ _zoomColor = zoomColor;
+ _zoomZoneActive = true;
+}
+
void GfxCursor::kernelSetPos(Common::Point pos) {
_coordAdjuster->setCursorPos(pos);
kernelMoveCursor(pos);
diff --git a/engines/sci/graphics/cursor.h b/engines/sci/graphics/cursor.h
index 787841f5be..ae3b51e26a 100644
--- a/engines/sci/graphics/cursor.h
+++ b/engines/sci/graphics/cursor.h
@@ -40,6 +40,16 @@ class GfxPalette;
typedef Common::HashMap<int, GfxView *> CursorCache;
+struct SciCursorSetPositionWorkarounds {
+ SciGameId gameId;
+ int16 newPositionY;
+ int16 newPositionX;
+ int16 rectTop;
+ int16 rectLeft;
+ int16 rectBottom;
+ int16 rectRight;
+};
+
class GfxCursor {
public:
GfxCursor(ResourceManager *resMan, GfxPalette *palette, GfxScreen *screen);
@@ -69,6 +79,9 @@ public:
*/
void kernelSetMoveZone(Common::Rect zone);
+ void kernelClearZoomZone();
+ void kernelSetZoomZone(byte multiplier, Common::Rect zone, GuiResourceId viewNum, int loopNum, int celNum, GuiResourceId picNum, byte zoomColor);
+
void kernelSetPos(Common::Point pos);
void kernelMoveCursor(Common::Point pos);
@@ -86,6 +99,16 @@ private:
bool _moveZoneActive;
Common::Rect _moveZone; // Rectangle in which the pointer can move
+ bool _zoomZoneActive;
+ Common::Rect _zoomZone;
+ GfxView *_zoomCursorView;
+ byte _zoomCursorLoop;
+ byte _zoomCursorCel;
+ GfxView *_zoomPicView;
+ byte _zoomColor;
+ byte _zoomMultiplier;
+ byte *_cursorSurface;
+
CursorCache _cachedCursors;
bool _isVisible;
diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp
index a433b26ef2..fc374ea143 100644
--- a/engines/sci/graphics/frameout.cpp
+++ b/engines/sci/graphics/frameout.cpp
@@ -70,6 +70,7 @@ void GfxFrameout::kernelAddPlane(reg_t object) {
newPlane.pictureId = 0xFFFF;
newPlane.priority = readSelectorValue(_segMan, object, SELECTOR(priority));
newPlane.lastPriority = 0xFFFF; // hidden
+ newPlane.planeOffsetX = 0;
_planes.push_back(newPlane);
kernelUpdatePlane(object);
@@ -91,6 +92,43 @@ void GfxFrameout::kernelUpdatePlane(reg_t object) {
addPlanePicture(object, it->pictureId, 0);
}
}
+ it->planeRect.top = readSelectorValue(_segMan, object, SELECTOR(top));
+ it->planeRect.left = readSelectorValue(_segMan, object, SELECTOR(left));
+ it->planeRect.bottom = readSelectorValue(_segMan, object, SELECTOR(bottom)) + 1;
+ it->planeRect.right = readSelectorValue(_segMan, object, SELECTOR(right)) + 1;
+
+ Common::Rect screenRect(_screen->getWidth(), _screen->getHeight());
+ it->planeRect.top = (it->planeRect.top * screenRect.height()) / scriptsRunningHeight;
+ it->planeRect.left = (it->planeRect.left * screenRect.width()) / scriptsRunningWidth;
+ it->planeRect.bottom = (it->planeRect.bottom * screenRect.height()) / scriptsRunningHeight;
+ it->planeRect.right = (it->planeRect.right * screenRect.width()) / scriptsRunningWidth;
+
+ // We get negative left in kq7 in scrolling rooms
+ if (it->planeRect.left < 0) {
+ it->planeOffsetX = -it->planeRect.left;
+ it->planeRect.left = 0;
+ }
+ if (it->planeRect.top < 0)
+ it->planeRect.top = 0;
+ // We get bad plane-bottom in sq6
+ if (it->planeRect.right > _screen->getWidth())
+ it->planeRect.right = _screen->getWidth();
+ if (it->planeRect.bottom > _screen->getHeight())
+ it->planeRect.bottom = _screen->getHeight();
+
+ it->planeClipRect = Common::Rect(it->planeRect.width(), it->planeRect.height());
+ it->upscaledPlaneRect = it->planeRect;
+ it->upscaledPlaneClipRect = it->planeClipRect;
+ if (_screen->getUpscaledHires()) {
+ _screen->adjustToUpscaledCoordinates(it->upscaledPlaneRect.top, it->upscaledPlaneRect.left);
+ _screen->adjustToUpscaledCoordinates(it->upscaledPlaneRect.bottom, it->upscaledPlaneRect.right);
+ _screen->adjustToUpscaledCoordinates(it->upscaledPlaneClipRect.top, it->upscaledPlaneClipRect.left);
+ _screen->adjustToUpscaledCoordinates(it->upscaledPlaneClipRect.bottom, it->upscaledPlaneClipRect.right);
+ }
+
+ it->planePictureMirrored = readSelectorValue(_segMan, object, SELECTOR(mirrored));
+ it->planeBack = readSelectorValue(_segMan, object, SELECTOR(back));
+
sortPlanes();
return;
}
@@ -98,6 +136,10 @@ void GfxFrameout::kernelUpdatePlane(reg_t object) {
error("kUpdatePlane called on plane that wasn't added before");
}
+void GfxFrameout::kernelRepaintPlane(reg_t object) {
+ // TODO
+}
+
void GfxFrameout::kernelDeletePlane(reg_t object) {
deletePlanePictures(object);
for (PlaneList::iterator it = _planes.begin(); it != _planes.end(); it++) {
@@ -147,6 +189,10 @@ void GfxFrameout::kernelAddScreenItem(reg_t object) {
_screenItems.push_back(object);
}
+void GfxFrameout::kernelUpdateScreenItem(reg_t object) {
+ // TODO
+}
+
void GfxFrameout::kernelDeleteScreenItem(reg_t object) {
for (uint32 itemNr = 0; itemNr < _screenItems.size(); itemNr++) {
if (_screenItems[itemNr] == object) {
@@ -207,72 +253,31 @@ void GfxFrameout::kernelFrameout() {
_palette->palVaryUpdate();
// Allocate enough space for all screen items
+ // TODO: Modify _screenItems to hold FrameoutEntry entries instead.
+ // Creating and destroying this in kernelFrameout() is overkill!
FrameoutEntry *itemData = new FrameoutEntry[_screenItems.size()];
for (PlaneList::iterator it = _planes.begin(); it != _planes.end(); it++) {
reg_t planeObject = it->object;
uint16 planeLastPriority = it->lastPriority;
- Common::Rect planeRect;
- planeRect.top = readSelectorValue(_segMan, planeObject, SELECTOR(top));
- planeRect.left = readSelectorValue(_segMan, planeObject, SELECTOR(left));
- planeRect.bottom = readSelectorValue(_segMan, planeObject, SELECTOR(bottom)) + 1;
- planeRect.right = readSelectorValue(_segMan, planeObject, SELECTOR(right)) + 1;
-
// Update priority here, sq6 sets it w/o UpdatePlane
uint16 planePriority = it->priority = readSelectorValue(_segMan, planeObject, SELECTOR(priority));
- Common::Rect screenRect(_screen->getWidth(), _screen->getHeight());
- planeRect.top = (planeRect.top * screenRect.height()) / scriptsRunningHeight;
- planeRect.left = (planeRect.left * screenRect.width()) / scriptsRunningWidth;
- planeRect.bottom = (planeRect.bottom * screenRect.height()) / scriptsRunningHeight;
- planeRect.right = (planeRect.right * screenRect.width()) / scriptsRunningWidth;
-
- int16 planeOffsetX = 0;
-
- // We get negative left in kq7 in scrolling rooms
- if (planeRect.left < 0) {
- planeOffsetX = -planeRect.left;
- planeRect.left = 0;
- }
- if (planeRect.top < 0)
- planeRect.top = 0;
- // We get bad plane-bottom in sq6
- if (planeRect.right > _screen->getWidth())
- planeRect.right = _screen->getWidth();
- if (planeRect.bottom > _screen->getHeight())
- planeRect.bottom = _screen->getHeight();
-
it->lastPriority = planePriority;
if (planePriority == 0xffff) { // Plane currently not meant to be shown
// If plane was shown before, delete plane rect
if (planePriority != planeLastPriority)
- _paint32->fillRect(planeRect, 0);
+ _paint32->fillRect(it->planeRect, 0);
continue;
}
- Common::Rect planeClipRect(planeRect.width(), planeRect.height());
-
- Common::Rect upscaledPlaneRect = planeRect;
- Common::Rect upscaledPlaneClipRect = planeClipRect;
- if (_screen->getUpscaledHires()) {
- _screen->adjustToUpscaledCoordinates(upscaledPlaneRect.top, upscaledPlaneRect.left);
- _screen->adjustToUpscaledCoordinates(upscaledPlaneRect.bottom, upscaledPlaneRect.right);
- _screen->adjustToUpscaledCoordinates(upscaledPlaneClipRect.top, upscaledPlaneClipRect.left);
- _screen->adjustToUpscaledCoordinates(upscaledPlaneClipRect.bottom, upscaledPlaneClipRect.right);
- }
-
- byte planeBack = readSelectorValue(_segMan, planeObject, SELECTOR(back));
- if (planeBack)
- _paint32->fillRect(planeRect, planeBack);
+ if (it->planeBack)
+ _paint32->fillRect(it->planeRect, it->planeBack);
GuiResourceId planeMainPictureId = it->pictureId;
- bool planePictureMirrored = false;
- if (readSelectorValue(_segMan, planeObject, SELECTOR(mirrored)))
- planePictureMirrored = true;
-
- _coordAdjuster->pictureSetDisplayArea(planeRect);
+ _coordAdjuster->pictureSetDisplayArea(it->planeRect);
_palette->drewPicture(planeMainPictureId);
// Fill our itemlist for this plane
@@ -360,25 +365,25 @@ void GfxFrameout::kernelFrameout() {
// Out of view
int16 pictureCelStartX = itemEntry->picStartX + itemEntry->x;
int16 pictureCelEndX = pictureCelStartX + itemEntry->picture->getSci32celWidth(itemEntry->celNo);
- int16 planeStartX = planeOffsetX;
- int16 planeEndX = planeStartX + planeRect.width();
+ int16 planeStartX = it->planeOffsetX;
+ int16 planeEndX = planeStartX + it->planeRect.width();
if (pictureCelEndX < planeStartX)
continue;
if (pictureCelStartX > planeEndX)
continue;
- int16 pictureOffsetX = planeOffsetX;
+ int16 pictureOffsetX = it->planeOffsetX;
int16 pictureX = itemEntry->x;
- if ((planeOffsetX) || (itemEntry->picStartX)) {
- if (planeOffsetX <= itemEntry->picStartX) {
- pictureX += itemEntry->picStartX - planeOffsetX;
+ if ((it->planeOffsetX) || (itemEntry->picStartX)) {
+ if (it->planeOffsetX <= itemEntry->picStartX) {
+ pictureX += itemEntry->picStartX - it->planeOffsetX;
pictureOffsetX = 0;
} else {
- pictureOffsetX = planeOffsetX - itemEntry->picStartX;
+ pictureOffsetX = it->planeOffsetX - itemEntry->picStartX;
}
}
- itemEntry->picture->drawSci32Vga(itemEntry->celNo, pictureX, itemEntry->y, pictureOffsetX, planePictureMirrored);
+ itemEntry->picture->drawSci32Vga(itemEntry->celNo, pictureX, itemEntry->y, pictureOffsetX, it->planePictureMirrored);
// warning("picture cel %d %d", itemEntry->celNo, itemEntry->priority);
} else if (itemEntry->viewId != 0xFFFF) {
@@ -403,7 +408,7 @@ void GfxFrameout::kernelFrameout() {
break;
}
// Adjust according to current scroll position
- itemEntry->x -= planeOffsetX;
+ itemEntry->x -= it->planeOffsetX;
uint16 useInsetRect = readSelectorValue(_segMan, itemEntry->object, SELECTOR(useInsetRect));
if (useInsetRect) {
@@ -426,7 +431,7 @@ void GfxFrameout::kernelFrameout() {
Common::Rect nsRect = itemEntry->celRect;
// Translate back to actual coordinate within scrollable plane
- nsRect.translate(planeOffsetX, 0);
+ nsRect.translate(it->planeOffsetX, 0);
switch (getSciVersion()) {
case SCI_VERSION_2:
if (view->isSci2Hires()) {
@@ -465,13 +470,13 @@ void GfxFrameout::kernelFrameout() {
Common::Rect clipRect, translatedClipRect;
clipRect = itemEntry->celRect;
if (view->isSci2Hires()) {
- clipRect.clip(upscaledPlaneClipRect);
+ clipRect.clip(it->upscaledPlaneClipRect);
translatedClipRect = clipRect;
- translatedClipRect.translate(upscaledPlaneRect.left, upscaledPlaneRect.top);
+ translatedClipRect.translate(it->upscaledPlaneRect.left, it->upscaledPlaneRect.top);
} else {
- clipRect.clip(planeClipRect);
+ clipRect.clip(it->planeClipRect);
translatedClipRect = clipRect;
- translatedClipRect.translate(planeRect.left, planeRect.top);
+ translatedClipRect.translate(it->planeRect.left, it->planeRect.top);
}
if (!clipRect.isEmpty()) {
@@ -501,8 +506,8 @@ void GfxFrameout::kernelFrameout() {
itemEntry->y = ((itemEntry->y * _screen->getHeight()) / scriptsRunningHeight);
itemEntry->x = ((itemEntry->x * _screen->getWidth()) / scriptsRunningWidth);
- uint16 curX = itemEntry->x + planeRect.left;
- uint16 curY = itemEntry->y + planeRect.top;
+ uint16 curX = itemEntry->x + it->planeRect.left;
+ uint16 curY = itemEntry->y + it->planeRect.top;
for (uint32 i = 0; i < text.size(); i++) {
unsigned char curChar = text[i];
// TODO: proper text splitting... this is a hack
diff --git a/engines/sci/graphics/frameout.h b/engines/sci/graphics/frameout.h
index f8f7e54a27..07297a91af 100644
--- a/engines/sci/graphics/frameout.h
+++ b/engines/sci/graphics/frameout.h
@@ -32,7 +32,14 @@ struct PlaneEntry {
reg_t object;
uint16 priority;
uint16 lastPriority;
+ int16 planeOffsetX;
GuiResourceId pictureId;
+ Common::Rect planeRect;
+ Common::Rect planeClipRect;
+ Common::Rect upscaledPlaneRect;
+ Common::Rect upscaledPlaneClipRect;
+ bool planePictureMirrored;
+ byte planeBack;
};
typedef Common::List<PlaneEntry> PlaneList;
@@ -81,8 +88,10 @@ public:
void kernelAddPlane(reg_t object);
void kernelUpdatePlane(reg_t object);
+ void kernelRepaintPlane(reg_t object);
void kernelDeletePlane(reg_t object);
void kernelAddScreenItem(reg_t object);
+ void kernelUpdateScreenItem(reg_t object);
void kernelDeleteScreenItem(reg_t object);
int16 kernelGetHighPlanePri();
void kernelAddPicAt(reg_t planeObj, int16 forWidth, GuiResourceId pictureId);
diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp
index 630626c128..06470bc560 100644
--- a/engines/sci/graphics/menu.cpp
+++ b/engines/sci/graphics/menu.cpp
@@ -905,7 +905,7 @@ void GfxMenu::kernelDrawStatus(const char *text, int16 colorPen, int16 colorBack
_paint16->fillRect(_ports->_menuBarRect, 1, colorBack);
_ports->penColor(colorPen);
_ports->moveTo(0, 1);
- _text16->Draw_String(text);
+ _text16->Draw_Status(text);
_paint16->bitsShow(_ports->_menuBarRect);
_ports->setPort(oldPort);
}
diff --git a/engines/sci/graphics/paint16.cpp b/engines/sci/graphics/paint16.cpp
index dbc738e2f7..3c115f0c8e 100644
--- a/engines/sci/graphics/paint16.cpp
+++ b/engines/sci/graphics/paint16.cpp
@@ -380,6 +380,14 @@ void GfxPaint16::kernelDrawPicture(GuiResourceId pictureId, int16 animationNr, b
drawPicture(pictureId, animationNr, mirroredFlag, addToFlag, EGApaletteNo);
_transitions->setup(animationNr, animationBlackoutFlag);
} else {
+ // We need to set it for SCI1EARLY+ (sierra sci also did so), otherwise we get at least the following issues:
+ // LSL5 (english) - last wakeup (taj mahal flute dream)
+ // SQ5 (english v1.03) - during the scene following the scrubbing
+ // in both situations a window is shown when kDrawPic is called, which would result otherwise in
+ // no showpic getting called from kAnimate and we would get graphic corruption
+ // XMAS1990 EGA did not set it in this case, VGA did
+ if (getSciVersion() >= SCI_VERSION_1_EARLY)
+ _screen->_picNotValid = 1;
_ports->beginUpdate(_ports->_picWind);
drawPicture(pictureId, animationNr, mirroredFlag, addToFlag, EGApaletteNo);
_ports->endUpdate(_ports->_picWind);
diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp
index 5c17f76558..76b2ed53fc 100644
--- a/engines/sci/graphics/palette.cpp
+++ b/engines/sci/graphics/palette.cpp
@@ -340,7 +340,8 @@ void GfxPalette::drewPicture(GuiResourceId pictureId) {
_sysPalette.timestamp++;
if (_palVaryResourceId != -1) {
- palVaryLoadTargetPalette(pictureId);
+ if (g_sci->getEngineState()->gameIsRestarting == 0) // only if not restored nor restarted
+ palVaryLoadTargetPalette(pictureId);
}
}
@@ -613,9 +614,18 @@ bool GfxPalette::kernelPalVaryInit(GuiResourceId resourceId, uint16 ticks, uint1
_palVaryStepStop = stepStop;
_palVaryDirection = direction;
// if no ticks are given, jump directly to destination
- if (!_palVaryTicks)
+ if (!_palVaryTicks) {
_palVaryDirection = stepStop;
- palVaryInstallTimer();
+ // sierra sci set the timer to 1 tick instead of calling it directly
+ // we have to change this to prevent a race condition to happen in
+ // at least freddy pharkas during nighttime. In that case kPalVary is
+ // called right before a transition and because we load pictures much
+ // faster, the 1 tick won't pass sometimes resulting in the palette
+ // being daytime instead of nighttime during the transition.
+ palVaryProcess(1, true);
+ } else {
+ palVaryInstallTimer();
+ }
return true;
}
return false;
@@ -632,9 +642,14 @@ int16 GfxPalette::kernelPalVaryReverse(int16 ticks, uint16 stepStop, int16 direc
_palVaryStepStop = stepStop;
_palVaryDirection = direction != -1 ? -direction : -_palVaryDirection;
- if (!_palVaryTicks)
+ if (!_palVaryTicks) {
_palVaryDirection = _palVaryStepStop - _palVaryStep;
- palVaryInstallTimer();
+ // ffs. see palVaryInit right above, we fix the code here as well
+ // just in case
+ palVaryProcess(1, true);
+ } else {
+ palVaryInstallTimer();
+ }
return kernelPalVaryGetCurrentStep();
}
diff --git a/engines/sci/graphics/picture.cpp b/engines/sci/graphics/picture.cpp
index e568316919..39666b82cb 100644
--- a/engines/sci/graphics/picture.cpp
+++ b/engines/sci/graphics/picture.cpp
@@ -120,10 +120,6 @@ void GfxPicture::drawSci11Vga() {
// [priorityBandData:WORD] * priorityBandCount
// [priority:BYTE] [unknown:BYTE]
- // Create palette and set it
- _palette->createFromData(inbuffer + palette_data_ptr, size - palette_data_ptr, &palette);
- _palette->set(&palette, true);
-
// priority bands are supposed to be 14 for sci1.1 pictures
assert(priorityBandsCount == 14);
@@ -132,8 +128,13 @@ void GfxPicture::drawSci11Vga() {
}
// display Cel-data
- if (has_cel)
+ if (has_cel) {
+ // Create palette and set it
+ _palette->createFromData(inbuffer + palette_data_ptr, size - palette_data_ptr, &palette);
+ _palette->set(&palette, true);
+
drawCelData(inbuffer, size, cel_headerPos, cel_RlePos, cel_LiteralPos, 0, 0, 0);
+ }
// process vector data
drawVectorData(inbuffer + vector_dataPos, vector_size);
@@ -852,11 +853,11 @@ void GfxPicture::vectorFloodFill(int16 x, int16 y, byte color, byte priority, by
// Now remove screens, that already got the right color/priority/control
if ((screenMask & GFX_SCREEN_MASK_VISUAL) && (searchColor == color))
- screenMask ^= GFX_SCREEN_MASK_VISUAL;
+ screenMask &= ~GFX_SCREEN_MASK_VISUAL;
if ((screenMask & GFX_SCREEN_MASK_PRIORITY) && (searchPriority == priority))
- screenMask ^= GFX_SCREEN_MASK_PRIORITY;
+ screenMask &= ~GFX_SCREEN_MASK_PRIORITY;
if ((screenMask & GFX_SCREEN_MASK_CONTROL) && (searchControl == control))
- screenMask ^= GFX_SCREEN_MASK_CONTROL;
+ screenMask &= ~GFX_SCREEN_MASK_CONTROL;
// Exit, if no screens left
if (!screenMask)
diff --git a/engines/sci/graphics/portrait.cpp b/engines/sci/graphics/portrait.cpp
index 8f4fe094a8..f21fa39476 100644
--- a/engines/sci/graphics/portrait.cpp
+++ b/engines/sci/graphics/portrait.cpp
@@ -185,7 +185,7 @@ void Portrait::doit(Common::Point position, uint16 resourceId, uint16 noun, uint
curEvent = _event->getSciEvent(SCI_EVENT_ANY);
if (curEvent.type == SCI_EVENT_MOUSE_PRESS ||
(curEvent.type == SCI_EVENT_KEYBOARD && curEvent.data == SCI_KEY_ESC) ||
- g_engine->shouldQuit())
+ g_sci->getEngineState()->abortScriptProcessing == kAbortQuitGame)
userAbort = true;
curPosition = _audio->getAudioPosition();
} while ((curPosition != -1) && (curPosition < timerPosition) && (!userAbort));
diff --git a/engines/sci/graphics/ports.cpp b/engines/sci/graphics/ports.cpp
index dddd9b1c86..e7f319a25c 100644
--- a/engines/sci/graphics/ports.cpp
+++ b/engines/sci/graphics/ports.cpp
@@ -105,16 +105,9 @@ void GfxPorts::init(bool usesOldGfxFunctions, GfxPaint16 *paint16, GfxText16 *te
case GID_CNICK_KQ:
offTop = 0;
break;
- case GID_MOTHERGOOSE:
- // TODO: if mother goose EGA also uses offTop we can simply remove this check altogether
- switch (getSciVersion()) {
- case SCI_VERSION_1_EARLY:
- case SCI_VERSION_1_1:
- offTop = 0;
- break;
- default:
- break;
- }
+ case GID_MOTHERGOOSE256:
+ // only the SCI1 and SCI1.1 (VGA) versions need this
+ offTop = 0;
break;
case GID_FAIRYTALES:
// Mixed-Up Fairy Tales (& its demo) uses -w 26 0 200 320. If we don't
@@ -308,7 +301,7 @@ Window *GfxPorts::addWindow(const Common::Rect &dims, const Common::Rect *restor
Common::Rect r;
if (!pwnd) {
- error("Can't open window!");
+ error("Can't open window");
return 0;
}
@@ -376,6 +369,20 @@ Window *GfxPorts::addWindow(const Common::Rect &dims, const Common::Rect *restor
if (draw)
drawWindow(pwnd);
setPort((Port *)pwnd);
+
+ // FIXME: changing setOrigin to not clear the rightmost bit fixes the display of windows
+ // in some fanmade games (e.g. New Year's Mystery (Updated)). Since the fanmade games
+ // use an unmodified SCI interpreter, this leads me to believe that there either is some
+ // off-by-one error in the window drawing code, or there is another place where the
+ // rightmost bit should be cleeared. New Year's Mystery is a good test case for this, as
+ // it draws dialogs and then draws cels on top of them, for fancier dialog corners (like,
+ // for example, KQ5). KQ5 has a custom window style, however, whereas New Year's mystery
+ // has a "classic" style with only SCI_WINDOWMGR_STYLE_NOFRAME set. If
+ // SCI_WINDOWMGR_STYLE_NOFRAME is removed, the window is cleared correctly, because it
+ // grows slightly, covering the view pixels on the left. In any case, the views and the
+ // window have a difference of one pixel when they're drawn via kNewWindow and kDrawCel,
+ // which causes the glitch to appear when the window is closed.
+
// All SCI0 games till kq4 .502 (not including) did not adjust against _wmgrPort, we set _wmgrPort->top to 0 in that case
setOrigin(pwnd->rect.left, pwnd->rect.top + _wmgrPort->top);
pwnd->rect.moveTo(0, 0);
diff --git a/engines/sci/graphics/robot.cpp b/engines/sci/graphics/robot.cpp
index 1572a0a9ec..0792c6596e 100644
--- a/engines/sci/graphics/robot.cpp
+++ b/engines/sci/graphics/robot.cpp
@@ -37,7 +37,6 @@ GfxRobot::GfxRobot(ResourceManager *resMan, GfxScreen *screen, GuiResourceId res
: _resMan(resMan), _screen(screen), _resourceId(resourceId) {
assert(resourceId != -1);
initData(resourceId);
- _resourceData = 0;
}
GfxRobot::~GfxRobot() {
@@ -57,119 +56,13 @@ void GfxRobot::initData(GuiResourceId resourceId) {
warning("Unable to open robot file %s", fileName);
return;
}
-
- byte version = _resourceData[6];
- if (version != 4 && version != 5) {
- warning("Robot version %d isn't supported yet", version);
- return;
- }
-
-// sample data:
-// Header - 14 bytes
-// DWORD:Sample Size - 2 needs to be subtracted (??!!)
-// ???
-// Actual samples following
-
-// version may be 3, 4 and 5
-// version 3 has a different header (unknown to this point)
-//
-// main header (56 bytes + 2 bytes resource id)
-// followed by sample data if hasSound == 1
-//
-
-// 90.rbt (640x390, 22050, 1 16, ADPCM) 67 frames
-// 00000000: 16 00 53 4f 4c 00 05 00-ad 08 00 00 f0 00 43 00 ..SOL.........C.
-// ^ signature ^ version ^ ^ ^ frames
-// ^ 2221
-// 00000010: b0 04 00 a0 00 00 00 00-01 01 00 00 0a 00 01 00
-// ^ ^ ^ ^ ^ ^ ^ ^ ^
-// hasSound
-// 00000020: 03 00 01 00 00 cf 03 00-00 00 00 00 00 00 00 00
-// ^ ^ ^ pixel count ^
-// ^
-// 00000030: 00 00 00 00 00 00 00 00-00 00 00 00
-// ^ ^
-// Sample-Data (Header):
-// compression must be 0 for now
-// 0000003c: f2 9f 00 00 00 00 d2 4d 00 00 20 52-00 00
-// ^ ^ ^
-// byte count compression
-// 40946
-// Actual Samples following
-// a5 11 04 02 85 90 ...M.. R........
-//
-// Offset 41020
-// Palette
-
-// 91.rbt (320x240, 22050, 1 16, ADPCM) 90 frames
-// 00000000: 16 00 53 4f 4c 00 05 00-ad 08 00 00 f0 00 5a 00 ..SOL.........Z.
-// ^ frames
-// 00000010: b0 04 00 a0 00 00 00 00-01 01 00 00 0a 00 01 00 ................
-// 00000020: 03 00 01 00 00 2c 01 00-00 00 00 00 00 00 00 00 .....,..........
-// ^ pixel count
-// 00000030: 00 00 00 00 00 00 00 00-00 00 00 00 f2 9f 00 00 ................ offset 60
-// ^ data begin (sample)
-// 00000040: 00 00 d2 4d 00 00 20 52-00 00 82 01 00 01 00 01 ...M.. R........
-// ...
-// 0000a030: 8d 8d 8f 8e 8f 90 90 91-92 92 92 94 0e 00 00 00 ................ offset 41004
-// ^ palette start
-// 0000a040: 00 00 00 00 00 00 01 00-00 09 01 00 00 00 00 00 ................
-// 0000a050: 00 00 00 00 00 37 00 00-00 51 00 01 01 00 00 00 .....7...Q......
-// ^ color start^ color count
-// 0000a060: 00 58 6b 2b 4b 69 28 50-5b 24 68 50 20 5b 53 21 .Xk+Ki(P[$hP [S!
-// ^ start pal data
-// [...]
-// 0000a110: 24 05 41 14 04 18 25 10-64 00 00 2d 18 05 58 00 $.A...%.d..-..X.
-// 0000a120: 00 16 20 07 50 00 00 20-19 01 2d 0e 00 48 00 00 .. .P.. ..-..H..
-// 0000a130: 40 00 00 10 18 05 38 00-00 30 00 00 28 00 00 0b @.....8..0..(...
-// 0000a140: 0e 00 20 00 00 18 00 00-00 08 00 10 00 00 08 00 .. .............
-// 0000a150: 00 00 00 00 70 70 70 70-70 70 70 70 70 70 70 70 ....pppppppppppp
-// [...]
-// 0000a4e0: 70 70 70 70 70 70 70 70-70 70 70 70 34 0a 75 0a pppppppppppp4.u.
-// 0000a4f0: 4a 0b c5 0b f4 0b 54 0c-bd 0c 7a 0d 91 0e 1f 10 J.....T...z.....
-// 0000a500: 16 12 72 14 19 17 ef 19-9a 1c b3 1e 79 20 c1 22 ..r.........y ."
-// 0000a510: 33 22 33 23 e0 25 84 26-eb 26 1a 2d 43 2d af 2d 3"3#.%.&.&.-C-.-
-// [...]
-// 0000aff0: 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20
-// 0000b000: 01 00 7f 64 40 01 f0 00-00 00 00 00 00 00 00 00 ...d@...........
-// ^width^height
-// 0000b010: 1c 0a 02 00 7f 7f 7f 7f-04 08 00 00 00 f0 00 00 ................
-// 0000b020: 00 00 43 e0 7f ff ff ff-ff ff ff ff ff ff ff ff ..C.............
-// 0000b030: ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
-
-// 161.rbt (112x155, 22050, 1 16, ADPCM) 29 frames
-// 00000000: 16 00 53 4f 4c 00 05 00-ad 08 00 00 96 00 1d 00 ..SOL...........
-// ^ frames
-// 00000010: b0 04 00 a0 00 00 00 00-01 01 00 00 0a 00 01 00 ................
-// 00000020: 03 00 01 00 47 3e 00 00-00 00 00 00 00 00 00 00 ....G>..........
-// ^ pixel count
-// 00000030: 00 00 00 00 00 00 00 00-00 00 00 00 f2 9f 00 00 ................
-// ^ data begin (sample)
-// 00000040: 00 00 d2 4d 00 00 20 52-00 00 00 00 00 00 00 00 ...M.. R........
-// 00000050: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
-
-// 213.rbt (125x248, nosound) 30 frames
-// 00000000: 16 00 53 4f 4c 00 05 00-ad 08 00 00 96 00 1e 00 ..SOL...........
-// ^ frames
-// 00000010: b0 04 00 00 00 00 00 00-01 00 00 00 0a 00 01 00 ................
-// ^ ?! ^ no sound?!
-// 00000020: 03 00 01 00 82 6e 00 00-00 00 00 00 00 00 00 00 .....n..........
-// ^ pixel count
-// 00000030: 00 00 00 00 00 00 00 00-00 00 00 00 0e 00 00 00 ................
-// ^ data begin (palette)
-// 00000040: 00 00 00 00 00 00 01 00-00 ca 00 00 00 00 00 00 ................
-// 00000050: 00 00 00 00 00 37 00 00-00 3c 00 01 01 00 00 00 .....7...<......
-// 00000060: 00 d0 d0 c0 d0 c0 a8 c8-b8 c0 d0 b0 a0 c0 a8 88
-// ^ palette data start
-// 00000070: c0 a0 a0 c8 98 90 d0 88-60 b0 90 80 b8 88 80 a0 ........`.......
-// 00000080: 90 98 b0 88 90 c0 78 60-a0 80 80 a0 80 70 c8 70 ......x`.....p.p
-// [...]
-// 00000110: 00 00 00 00 08 70 70 70-70 70 70 70 70 70 70 70 .....ppppppppppp
-// ^ ??
-// 00000120: 70 70 70 70 70 70 70 70-70 70 70 70 70 70 70 70 pppppppppppppppp
+ // The RBT video starts with a SOL audio file, followed by
+ // video data which is appended after it
_frameCount = READ_LE_UINT16(_resourceData + 14);
+ _audioSize = READ_LE_UINT16(_resourceData + 15);
+
//_frameSize = READ_LE_UINT32(_resourceData + 34);
byte hasSound = _resourceData[25];
@@ -179,21 +72,57 @@ void GfxRobot::initData(GuiResourceId resourceId) {
// TODO: just trying around in here...
void GfxRobot::draw() {
- byte *bitmapData = _resourceData + ROBOT_FILE_STARTOFDATA;
+ byte *bitmapData = _resourceData + _audioSize;
int x, y;
- //int frame;
+ int frame;
return;
- //for (frame = 0; frame < 30; frame++) {
- for (y = 0; y < _height; y++) {
- for (x = 0; x < _width; x++) {
- _screen->putPixel(x, y, GFX_SCREEN_MASK_VISUAL, *bitmapData, 0, 0);
- bitmapData++;
+ // Each frame contains these bytes:
+ // 01 00 7f 64 - always the same, perhaps resource type + extra
+ // 40 01 - total frame width (320 in this case)
+ // f0 00 - total frame height (240 in this case)
+ // The total video size is calculated from the maximum width, height
+ // of all the frames in the robot file
+ // 4 zeroes
+ // 4 bytes, perhaps frame x, y on screen?
+ // 2 bytes, unknown
+ // 2 bytes, a small number (e.g. 01 00 or 02 00)
+ // 7f 7f - 127x127
+ // 7f 7f - 127x127
+ // 2 bytes, related to frame size?
+ // 00 00
+ // 00 f0
+ // 4 zeroes
+ // 43 e0
+ // 7f ff
+
+ // The frames themselves seem to contain a size of the actual drawn data
+ // on screen. The frame data seems to be uncompressed, placed on screen
+ // at appropriate x,y coordinates, and each frame can have a different size.
+ // This is apparent from the fact that a 320x240 frame (e.g. in Phantasmagoria
+ // demo, 91.rbt) has 4833, 4898, 5111, etc bytes, whereas a full frame would
+ // be 320x240 = 76800 bytes. Thus, each frame is either somehow compressed
+ // (but the data seems uncompressed?), or only the part that changes is drawn
+ // on screen, something like the MPEG I-frames
+
+ for (frame = 0; frame < _frameCount; frame++) {
+ bitmapData += 4; // skip header bytes
+ _width = READ_LE_UINT16(bitmapData + 4); bitmapData += 2;
+ _height = READ_LE_UINT16(bitmapData + 6); bitmapData += 2;
+
+ for (y = 0; y < _width; y++) {
+ for (x = 0; x < _height; x++) {
+ _screen->putPixel(x, y, GFX_SCREEN_MASK_VISUAL, *bitmapData, 0, 0);
+ bitmapData++;
+ }
}
+
+ _screen->copyToScreen();
+ // Sleep for a second
+ g_sci->sleep(1000);
}
- //}
- _screen->copyToScreen();
+
}
#endif
diff --git a/engines/sci/graphics/robot.h b/engines/sci/graphics/robot.h
index 3ea9a7f735..76dca35a82 100644
--- a/engines/sci/graphics/robot.h
+++ b/engines/sci/graphics/robot.h
@@ -51,6 +51,7 @@ private:
uint16 _height;
uint16 _frameCount;
uint32 _frameSize; // is width * height (pixelCount)
+ uint16 _audioSize;
};
#endif
diff --git a/engines/sci/graphics/screen.cpp b/engines/sci/graphics/screen.cpp
index 839b9975c5..6eabc7c9f0 100644
--- a/engines/sci/graphics/screen.cpp
+++ b/engines/sci/graphics/screen.cpp
@@ -345,11 +345,11 @@ byte GfxScreen::isFillMatch(int16 x, int16 y, byte screenMask, byte t_color, byt
int offset = y * _width + x;
byte match = 0;
- if (screenMask & GFX_SCREEN_MASK_VISUAL && *(_visualScreen + offset) == t_color)
+ if ((screenMask & GFX_SCREEN_MASK_VISUAL) && *(_visualScreen + offset) == t_color)
match |= GFX_SCREEN_MASK_VISUAL;
- if (screenMask & GFX_SCREEN_MASK_PRIORITY && *(_priorityScreen + offset) == t_pri)
+ if ((screenMask & GFX_SCREEN_MASK_PRIORITY) && *(_priorityScreen + offset) == t_pri)
match |= GFX_SCREEN_MASK_PRIORITY;
- if (screenMask & GFX_SCREEN_MASK_CONTROL && *(_controlScreen + offset) == t_con)
+ if ((screenMask & GFX_SCREEN_MASK_CONTROL) && *(_controlScreen + offset) == t_con)
match |= GFX_SCREEN_MASK_CONTROL;
return match;
}
diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp
index f5eb268863..3fba3006c7 100644
--- a/engines/sci/graphics/text16.cpp
+++ b/engines/sci/graphics/text16.cpp
@@ -30,6 +30,7 @@
#include "sci/sci.h"
#include "sci/engine/state.h"
#include "sci/graphics/cache.h"
+#include "sci/graphics/coordadjuster.h"
#include "sci/graphics/ports.h"
#include "sci/graphics/paint16.h"
#include "sci/graphics/font.h"
@@ -88,7 +89,7 @@ void GfxText16::ClearChar(int16 chr) {
// will process the encountered code and set new font/set color. We only support
// one-digit codes currently, don't know if multi-digit codes are possible.
// Returns textcode character count.
-int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor) {
+int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor, bool doingDrawing) {
const char *textCode = text;
int16 textCodeSize = 0;
char curCode;
@@ -126,8 +127,20 @@ int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int1
}
}
break;
- case 'r': // reference?!
- // Used in Pepper, no idea how this works out
+ case 'r': // reference (used in pepper)
+ if (doingDrawing) {
+ if (_codeRefTempRect.top == -1) {
+ // Starting point
+ _codeRefTempRect.top = _ports->_curPort->curTop;
+ _codeRefTempRect.left = _ports->_curPort->curLeft;
+ } else {
+ // End point reached
+ _codeRefTempRect.bottom = _ports->_curPort->curTop + _ports->_curPort->fontHeight;
+ _codeRefTempRect.right = _ports->_curPort->curLeft;
+ _codeRefRects.push_back(_codeRefTempRect);
+ _codeRefTempRect.left = _codeRefTempRect.top = -1;
+ }
+ }
break;
}
return textCodeSize;
@@ -162,7 +175,7 @@ int16 GfxText16::GetLongest(const char *text, int16 maxWidth, GuiResourceId orgF
case 0x7C:
if (getSciVersion() >= SCI_VERSION_1_1) {
curCharCount++;
- curCharCount += CodeProcessing(text, orgFontId, previousPenColor);
+ curCharCount += CodeProcessing(text, orgFontId, previousPenColor, false);
continue;
}
break;
@@ -258,7 +271,7 @@ void GfxText16::Width(const char *text, int16 from, int16 len, GuiResourceId org
break;
case 0x7C:
if (getSciVersion() >= SCI_VERSION_1_1) {
- len -= CodeProcessing(text, orgFontId, 0);
+ len -= CodeProcessing(text, orgFontId, 0, false);
break;
}
default:
@@ -359,7 +372,7 @@ void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgF
break;
case 0x7C:
if (getSciVersion() >= SCI_VERSION_1_1) {
- len -= CodeProcessing(text, orgFontId, orgPenColor);
+ len -= CodeProcessing(text, orgFontId, orgPenColor, true);
break;
}
default:
@@ -408,6 +421,10 @@ void GfxText16::Box(const char *text, int16 bshow, const Common::Rect &rect, Tex
doubleByteMode = true;
}
+ // Reset reference code rects
+ _codeRefRects.clear();
+ _codeRefTempRect.left = _codeRefTempRect.top = -1;
+
maxTextWidth = 0;
while (*text) {
charCount = GetLongest(text, rect.width(), fontId);
@@ -474,6 +491,32 @@ void GfxText16::Draw_String(const char *text) {
_ports->penColor(previousPenColor);
}
+// we need to have a separate status drawing code
+// In KQ4 the IV char is actually 0xA, which would otherwise get considered as linebreak and not printed
+void GfxText16::Draw_Status(const char *text) {
+ uint16 curChar, charWidth;
+ uint16 textLen = strlen(text);
+ Common::Rect rect;
+
+ GetFont();
+ if (!_font)
+ return;
+
+ rect.top = _ports->_curPort->curTop;
+ rect.bottom = rect.top + _ports->_curPort->fontHeight;
+ while (textLen--) {
+ curChar = (*(const byte *)text++);
+ switch (curChar) {
+ case 0:
+ break;
+ default:
+ charWidth = _font->getCharWidth(curChar);
+ _font->draw(curChar, _ports->_curPort->top + _ports->_curPort->curTop, _ports->_curPort->left + _ports->_curPort->curLeft, _ports->_curPort->penClr, _ports->_curPort->greyedOutput);
+ _ports->_curPort->curLeft += charWidth;
+ }
+ }
+}
+
// Sierra did this in their PC98 interpreter only, they identify a text as being
// sjis and then switch to font 900
bool GfxText16::SwitchToFont900OnSjis(const char *text) {
@@ -485,6 +528,30 @@ bool GfxText16::SwitchToFont900OnSjis(const char *text) {
return false;
}
+reg_t GfxText16::allocAndFillReferenceRectArray() {
+ uint rectCount = _codeRefRects.size();
+ if (rectCount) {
+ reg_t rectArray;
+ byte *rectArrayPtr = g_sci->getEngineState()->_segMan->allocDynmem(4 * 2 * (rectCount + 1), "text code reference rects", &rectArray);
+ GfxCoordAdjuster *coordAdjuster = g_sci->_gfxCoordAdjuster;
+ for (uint curRect = 0; curRect < rectCount; curRect++) {
+ coordAdjuster->kernelLocalToGlobal(_codeRefRects[curRect].left, _codeRefRects[curRect].top);
+ coordAdjuster->kernelLocalToGlobal(_codeRefRects[curRect].right, _codeRefRects[curRect].bottom);
+ WRITE_LE_UINT16(rectArrayPtr + 0, _codeRefRects[curRect].left);
+ WRITE_LE_UINT16(rectArrayPtr + 2, _codeRefRects[curRect].top);
+ WRITE_LE_UINT16(rectArrayPtr + 4, _codeRefRects[curRect].right);
+ WRITE_LE_UINT16(rectArrayPtr + 6, _codeRefRects[curRect].bottom);
+ rectArrayPtr += 8;
+ }
+ WRITE_LE_UINT16(rectArrayPtr + 0, 0x7777);
+ WRITE_LE_UINT16(rectArrayPtr + 2, 0x7777);
+ WRITE_LE_UINT16(rectArrayPtr + 4, 0x7777);
+ WRITE_LE_UINT16(rectArrayPtr + 6, 0x7777);
+ return rectArray;
+ }
+ return NULL_REG;
+}
+
void GfxText16::kernelTextSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight) {
Common::Rect rect(0, 0, 0, 0);
Size(rect, text, font, maxWidth);
diff --git a/engines/sci/graphics/text16.h b/engines/sci/graphics/text16.h
index 9b8b6d9f19..dc3ed2f62b 100644
--- a/engines/sci/graphics/text16.h
+++ b/engines/sci/graphics/text16.h
@@ -32,6 +32,8 @@ namespace Sci {
#define SCI_TEXT16_ALIGNMENT_CENTER 1
#define SCI_TEXT16_ALIGNMENT_LEFT 0
+typedef Common::Array<Common::Rect> CodeRefRectArray;
+
class GfxPorts;
class GfxPaint16;
class GfxScreen;
@@ -48,7 +50,7 @@ public:
GfxFont *GetFont();
void SetFont(GuiResourceId fontId);
- int16 CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor);
+ int16 CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor, bool doingDrawing);
void ClearChar(int16 chr);
@@ -62,9 +64,12 @@ public:
void Show(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 orgPenColor);
void Box(const char *text, int16 bshow, const Common::Rect &rect, TextAlignment alignment, GuiResourceId fontId);
void Draw_String(const char *text);
+ void Draw_Status(const char *text);
GfxFont *_font;
+ reg_t allocAndFillReferenceRectArray();
+
void kernelTextSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight);
void kernelTextFonts(int argc, reg_t *argv);
void kernelTextColors(int argc, reg_t *argv);
@@ -83,6 +88,9 @@ private:
GuiResourceId *_codeFonts;
int _codeColorsCount;
uint16 *_codeColors;
+
+ Common::Rect _codeRefTempRect;
+ CodeRefRectArray _codeRefRects;
};
} // End of namespace Sci
diff --git a/engines/sci/graphics/transitions.cpp b/engines/sci/graphics/transitions.cpp
index abb5e74cbd..3f4ce7bbc8 100644
--- a/engines/sci/graphics/transitions.cpp
+++ b/engines/sci/graphics/transitions.cpp
@@ -37,6 +37,8 @@
namespace Sci {
+//#define DISABLE_TRANSITIONS // uncomment to disable room transitions (for development only! helps in testing games quickly)
+
GfxTransitions::GfxTransitions(GfxScreen *screen, GfxPalette *palette, bool isVGA)
: _screen(screen), _palette(palette), _isVGA(isVGA) {
init();
@@ -116,16 +118,33 @@ void GfxTransitions::init() {
void GfxTransitions::setup(int16 number, bool blackoutFlag) {
if (number != -1) {
+#ifndef DISABLE_TRANSITIONS
_number = number;
+#else
+ _number = SCI_TRANSITIONS_NONE;
+#endif
_blackoutFlag = blackoutFlag;
}
}
-void GfxTransitions::updateScreenAndWait(int msec) {
+bool GfxTransitions::doCreateFrame(uint32 shouldBeAtMsec) {
+ uint32 msecPos = g_system->getMillis() - _transitionStartTime;
+
+ if (shouldBeAtMsec > msecPos)
+ return true;
+ return false;
+}
+
+void GfxTransitions::updateScreenAndWait(uint32 shouldBeAtMsec) {
Common::Event ev;
- g_system->updateScreen();
- g_system->delayMillis(msec);
+
while (g_system->getEventManager()->pollEvent(ev)) {} // discard all events
+
+ g_system->updateScreen();
+ // if we have still some time left, delay accordingly
+ uint32 msecPos = g_system->getMillis() - _transitionStartTime;
+ if (shouldBeAtMsec > msecPos)
+ g_system->delayMillis(shouldBeAtMsec - msecPos);
}
// will translate a number and return corresponding translationEntry
@@ -191,6 +210,7 @@ void GfxTransitions::doTransition(int16 number, bool blackoutFlag) {
setNewPalette(blackoutFlag);
}
+ _transitionStartTime = g_system->getMillis();
switch (number) {
case SCI_TRANSITIONS_VERTICALROLL_FROMCENTER:
verticalRollFromCenter(blackoutFlag);
@@ -285,11 +305,14 @@ void GfxTransitions::copyRectToScreen(const Common::Rect rect, bool blackoutFlag
void GfxTransitions::fadeOut() {
byte oldPalette[4 * 256], workPalette[4 * 256];
int16 stepNr, colorNr;
+ // Sierra did not fade in/out color 255 for sci1.1, but they used it in
+ // several pictures (e.g. qfg3 demo/intro), so the fading looked weird
+ int16 tillColorNr = getSciVersion() >= SCI_VERSION_1_1 ? 256 : 255;
g_system->grabPalette(oldPalette, 0, 256);
for (stepNr = 100; stepNr >= 0; stepNr -= 10) {
- for (colorNr = 1; colorNr < 255; colorNr++){
+ for (colorNr = 1; colorNr < tillColorNr; colorNr++){
workPalette[colorNr * 4 + 0] = oldPalette[colorNr * 4] * stepNr / 100;
workPalette[colorNr * 4 + 1] = oldPalette[colorNr * 4 + 1] * stepNr / 100;
workPalette[colorNr * 4 + 2] = oldPalette[colorNr * 4 + 2] * stepNr / 100;
@@ -303,9 +326,12 @@ void GfxTransitions::fadeOut() {
// the load
void GfxTransitions::fadeIn() {
int16 stepNr;
+ // Sierra did not fade in/out color 255 for sci1.1, but they used it in
+ // several pictures (e.g. qfg3 demo/intro), so the fading looked weird
+ int16 tillColorNr = getSciVersion() >= SCI_VERSION_1_1 ? 256 : 255;
for (stepNr = 0; stepNr <= 100; stepNr += 10) {
- _palette->kernelSetIntensity(1, 255, stepNr, true);
+ _palette->kernelSetIntensity(1, tillColorNr, stepNr, true);
g_sci->getEngineState()->wait(2);
}
}
@@ -315,6 +341,7 @@ void GfxTransitions::fadeIn() {
void GfxTransitions::pixelation(bool blackoutFlag) {
uint16 mask = 0x40, stepNr = 0;
Common::Rect pixelRect;
+ uint32 msecCount = 0;
do {
mask = (mask & 1) ? (mask >> 1) ^ 0xB400 : mask >> 1;
@@ -326,7 +353,8 @@ void GfxTransitions::pixelation(bool blackoutFlag) {
if (!pixelRect.isEmpty())
copyRectToScreen(pixelRect, blackoutFlag);
if ((stepNr & 0x3FF) == 0) {
- updateScreenAndWait(5);
+ msecCount += 9;
+ updateScreenAndWait(msecCount);
}
stepNr++;
} while (mask != 0x40);
@@ -337,6 +365,7 @@ void GfxTransitions::pixelation(bool blackoutFlag) {
void GfxTransitions::blocks(bool blackoutFlag) {
uint16 mask = 0x40, stepNr = 0;
Common::Rect blockRect;
+ uint32 msecCount = 0;
do {
mask = (mask & 1) ? (mask >> 1) ^ 0x240 : mask >> 1;
@@ -348,7 +377,8 @@ void GfxTransitions::blocks(bool blackoutFlag) {
if (!blockRect.isEmpty())
copyRectToScreen(blockRect, blackoutFlag);
if ((stepNr & 7) == 0) {
- updateScreenAndWait(4);
+ msecCount += 5;
+ updateScreenAndWait(msecCount);
}
stepNr++;
} while (mask != 0x40);
@@ -359,6 +389,7 @@ void GfxTransitions::blocks(bool blackoutFlag) {
void GfxTransitions::straight(int16 number, bool blackoutFlag) {
int16 stepNr = 0;
Common::Rect newScreenRect = _picRect;
+ uint32 msecCount = 0;
switch (number) {
case SCI_TRANSITIONS_STRAIGHT_FROM_RIGHT:
@@ -366,7 +397,8 @@ void GfxTransitions::straight(int16 number, bool blackoutFlag) {
while (newScreenRect.left >= _picRect.left) {
copyRectToScreen(newScreenRect, blackoutFlag);
if ((stepNr & 1) == 0) {
- updateScreenAndWait(1);
+ msecCount += 2;
+ updateScreenAndWait(msecCount);
}
stepNr++;
newScreenRect.translate(-1, 0);
@@ -378,7 +410,8 @@ void GfxTransitions::straight(int16 number, bool blackoutFlag) {
while (newScreenRect.right <= _picRect.right) {
copyRectToScreen(newScreenRect, blackoutFlag);
if ((stepNr & 1) == 0) {
- updateScreenAndWait(1);
+ msecCount += 2;
+ updateScreenAndWait(msecCount);
}
stepNr++;
newScreenRect.translate(1, 0);
@@ -389,7 +422,8 @@ void GfxTransitions::straight(int16 number, bool blackoutFlag) {
newScreenRect.top = newScreenRect.bottom - 1;
while (newScreenRect.top >= _picRect.top) {
copyRectToScreen(newScreenRect, blackoutFlag);
- updateScreenAndWait(3);
+ msecCount += 4;
+ updateScreenAndWait(msecCount);
stepNr++;
newScreenRect.translate(0, -1);
}
@@ -399,7 +433,8 @@ void GfxTransitions::straight(int16 number, bool blackoutFlag) {
newScreenRect.bottom = newScreenRect.top + 1;
while (newScreenRect.bottom <= _picRect.bottom) {
copyRectToScreen(newScreenRect, blackoutFlag);
- updateScreenAndWait(3);
+ msecCount += 4;
+ updateScreenAndWait(msecCount);
stepNr++;
newScreenRect.translate(0, 1);
}
@@ -428,6 +463,7 @@ void GfxTransitions::scroll(int16 number) {
Common::Rect oldScreenRect = _picRect;
Common::Rect newMoveRect = _picRect;
Common::Rect newScreenRect = _picRect;
+ uint32 msecCount = 0;
_screen->copyFromScreen(_oldScreen);
screenWidth = _screen->getDisplayWidth(); screenHeight = _screen->getDisplayHeight();
@@ -438,42 +474,36 @@ void GfxTransitions::scroll(int16 number) {
newMoveRect.left = newMoveRect.right;
while (oldMoveRect.left < oldMoveRect.right) {
oldMoveRect.right--; oldScreenRect.left++;
- if (oldMoveRect.right > oldMoveRect.left)
- scrollCopyOldToScreen(oldScreenRect, oldMoveRect.left, oldMoveRect.top);
newScreenRect.right++; newMoveRect.left--;
- _screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
if ((stepNr & 1) == 0) {
- updateScreenAndWait(1);
+ msecCount += 5;
+ if (doCreateFrame(msecCount)) {
+ if (oldMoveRect.right > oldMoveRect.left)
+ scrollCopyOldToScreen(oldScreenRect, oldMoveRect.left, oldMoveRect.top);
+ _screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
+ updateScreenAndWait(msecCount);
+ }
}
stepNr++;
}
- if ((stepNr & 1) == 0) {
- if (g_system->getMillis() - g_sci->getEngineState()->_screenUpdateTime >= 1000 / 60) {
- g_system->updateScreen();
- g_sci->getEngineState()->_screenUpdateTime = g_system->getMillis();
- }
- }
break;
case SCI_TRANSITIONS_SCROLL_RIGHT:
newScreenRect.left = newScreenRect.right;
while (oldMoveRect.left < oldMoveRect.right) {
oldMoveRect.left++; oldScreenRect.right--;
- if (oldMoveRect.right > oldMoveRect.left)
- scrollCopyOldToScreen(oldScreenRect, oldMoveRect.left, oldMoveRect.top);
newScreenRect.left--;
- _screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
if ((stepNr & 1) == 0) {
- updateScreenAndWait(1);
+ msecCount += 5;
+ if (doCreateFrame(msecCount)) {
+ if (oldMoveRect.right > oldMoveRect.left)
+ scrollCopyOldToScreen(oldScreenRect, oldMoveRect.left, oldMoveRect.top);
+ _screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
+ updateScreenAndWait(msecCount);
+ }
}
stepNr++;
}
- if ((stepNr & 1) == 0) {
- if (g_system->getMillis() - g_sci->getEngineState()->_screenUpdateTime >= 1000 / 60) {
- g_system->updateScreen();
- g_sci->getEngineState()->_screenUpdateTime = g_system->getMillis();
- }
- }
break;
case SCI_TRANSITIONS_SCROLL_UP:
@@ -481,11 +511,15 @@ void GfxTransitions::scroll(int16 number) {
newMoveRect.top = newMoveRect.bottom;
while (oldMoveRect.top < oldMoveRect.bottom) {
oldMoveRect.top++; oldScreenRect.top++;
- if (oldMoveRect.top < oldMoveRect.bottom)
- scrollCopyOldToScreen(oldScreenRect, _picRect.left, _picRect.top);
newScreenRect.bottom++; newMoveRect.top--;
- _screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
- updateScreenAndWait(3);
+
+ msecCount += 5;
+ if (doCreateFrame(msecCount)) {
+ if (oldMoveRect.top < oldMoveRect.bottom)
+ scrollCopyOldToScreen(oldScreenRect, _picRect.left, _picRect.top);
+ _screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
+ updateScreenAndWait(msecCount);
+ }
}
break;
@@ -493,14 +527,22 @@ void GfxTransitions::scroll(int16 number) {
newScreenRect.top = newScreenRect.bottom;
while (oldMoveRect.top < oldMoveRect.bottom) {
oldMoveRect.top++; oldScreenRect.bottom--;
- if (oldMoveRect.top < oldMoveRect.bottom)
- scrollCopyOldToScreen(oldScreenRect, oldMoveRect.left, oldMoveRect.top);
newScreenRect.top--;
- _screen->copyRectToScreen(newScreenRect, _picRect.left, _picRect.top);
- updateScreenAndWait(3);
+
+ msecCount += 5;
+ if (doCreateFrame(msecCount)) {
+ if (oldMoveRect.top < oldMoveRect.bottom)
+ scrollCopyOldToScreen(oldScreenRect, oldMoveRect.left, oldMoveRect.top);
+ _screen->copyRectToScreen(newScreenRect, _picRect.left, _picRect.top);
+ updateScreenAndWait(msecCount);
+ }
}
break;
}
+
+ // Copy over final position just in case
+ _screen->copyRectToScreen(newScreenRect);
+ g_system->updateScreen();
}
// Vertically displays new screen starting from center - works on _picRect area
@@ -508,6 +550,7 @@ void GfxTransitions::scroll(int16 number) {
void GfxTransitions::verticalRollFromCenter(bool blackoutFlag) {
Common::Rect leftRect = Common::Rect(_picRect.left + (_picRect.width() / 2) -1, _picRect.top, _picRect.left + (_picRect.width() / 2), _picRect.bottom);
Common::Rect rightRect = Common::Rect(leftRect.right, _picRect.top, leftRect.right + 1, _picRect.bottom);
+ uint32 msecCount = 0;
while ((leftRect.left >= _picRect.left) || (rightRect.right <= _picRect.right)) {
if (leftRect.left < _picRect.left)
@@ -516,7 +559,8 @@ void GfxTransitions::verticalRollFromCenter(bool blackoutFlag) {
rightRect.translate(-1, 0);
copyRectToScreen(leftRect, blackoutFlag); leftRect.translate(-1, 0);
copyRectToScreen(rightRect, blackoutFlag); rightRect.translate(1, 0);
- updateScreenAndWait(2);
+ msecCount += 3;
+ updateScreenAndWait(msecCount);
}
}
@@ -525,11 +569,13 @@ void GfxTransitions::verticalRollFromCenter(bool blackoutFlag) {
void GfxTransitions::verticalRollToCenter(bool blackoutFlag) {
Common::Rect leftRect = Common::Rect(_picRect.left, _picRect.top, _picRect.left + 1, _picRect.bottom);
Common::Rect rightRect = Common::Rect(_picRect.right - 1, _picRect.top, _picRect.right, _picRect.bottom);
+ uint32 msecCount = 0;
while (leftRect.left < rightRect.right) {
copyRectToScreen(leftRect, blackoutFlag); leftRect.translate(1, 0);
copyRectToScreen(rightRect, blackoutFlag); rightRect.translate(-1, 0);
- updateScreenAndWait(2);
+ msecCount += 3;
+ updateScreenAndWait(msecCount);
}
}
@@ -538,6 +584,7 @@ void GfxTransitions::verticalRollToCenter(bool blackoutFlag) {
void GfxTransitions::horizontalRollFromCenter(bool blackoutFlag) {
Common::Rect upperRect = Common::Rect(_picRect.left, _picRect.top + (_picRect.height() / 2) - 1, _picRect.right, _picRect.top + (_picRect.height() / 2));
Common::Rect lowerRect = Common::Rect(upperRect.left, upperRect.bottom, upperRect.right, upperRect.bottom + 1);
+ uint32 msecCount = 0;
while ((upperRect.top >= _picRect.top) || (lowerRect.bottom <= _picRect.bottom)) {
if (upperRect.top < _picRect.top)
@@ -546,7 +593,8 @@ void GfxTransitions::horizontalRollFromCenter(bool blackoutFlag) {
lowerRect.translate(0, -1);
copyRectToScreen(upperRect, blackoutFlag); upperRect.translate(0, -1);
copyRectToScreen(lowerRect, blackoutFlag); lowerRect.translate(0, 1);
- updateScreenAndWait(3);
+ msecCount += 4;
+ updateScreenAndWait(msecCount);
}
}
@@ -555,11 +603,13 @@ void GfxTransitions::horizontalRollFromCenter(bool blackoutFlag) {
void GfxTransitions::horizontalRollToCenter(bool blackoutFlag) {
Common::Rect upperRect = Common::Rect(_picRect.left, _picRect.top, _picRect.right, _picRect.top + 1);
Common::Rect lowerRect = Common::Rect(upperRect.left, _picRect.bottom - 1, upperRect.right, _picRect.bottom);
+ uint32 msecCount = 0;
while (upperRect.top < lowerRect.bottom) {
copyRectToScreen(upperRect, blackoutFlag); upperRect.translate(0, 1);
copyRectToScreen(lowerRect, blackoutFlag); lowerRect.translate(0, -1);
- updateScreenAndWait(3);
+ msecCount += 4;
+ updateScreenAndWait(msecCount);
}
}
@@ -571,6 +621,7 @@ void GfxTransitions::diagonalRollFromCenter(bool blackoutFlag) {
Common::Rect lowerRect(upperRect.left, upperRect.top, upperRect.right, upperRect.bottom);
Common::Rect leftRect(upperRect.left, upperRect.top, upperRect.left + 1, lowerRect.bottom);
Common::Rect rightRect(upperRect.right, upperRect.top, upperRect.right + 1, lowerRect.bottom);
+ uint32 msecCount = 0;
while ((upperRect.top >= _picRect.top) || (lowerRect.bottom <= _picRect.bottom)) {
if (upperRect.top < _picRect.top) {
@@ -589,7 +640,8 @@ void GfxTransitions::diagonalRollFromCenter(bool blackoutFlag) {
copyRectToScreen(lowerRect, blackoutFlag); lowerRect.translate(0, 1); lowerRect.left--; lowerRect.right++;
copyRectToScreen(leftRect, blackoutFlag); leftRect.translate(-1, 0); leftRect.top--; leftRect.bottom++;
copyRectToScreen(rightRect, blackoutFlag); rightRect.translate(1, 0); rightRect.top--; rightRect.bottom++;
- updateScreenAndWait(3);
+ msecCount += 4;
+ updateScreenAndWait(msecCount);
}
}
@@ -600,13 +652,15 @@ void GfxTransitions::diagonalRollToCenter(bool blackoutFlag) {
Common::Rect lowerRect(_picRect.left, _picRect.bottom - 1, _picRect.right, _picRect.bottom);
Common::Rect leftRect(_picRect.left, _picRect.top, _picRect.left + 1, _picRect.bottom);
Common::Rect rightRect(_picRect.right - 1, _picRect.top, _picRect.right, _picRect.bottom);
+ uint32 msecCount = 0;
while (upperRect.top < lowerRect.bottom) {
copyRectToScreen(upperRect, blackoutFlag); upperRect.translate(0, 1); upperRect.left++; upperRect.right--;
copyRectToScreen(lowerRect, blackoutFlag); lowerRect.translate(0, -1); lowerRect.left++; lowerRect.right--;
copyRectToScreen(leftRect, blackoutFlag); leftRect.translate(1, 0);
copyRectToScreen(rightRect, blackoutFlag); rightRect.translate(-1, 0);
- updateScreenAndWait(3);
+ msecCount += 4;
+ updateScreenAndWait(msecCount);
}
}
diff --git a/engines/sci/graphics/transitions.h b/engines/sci/graphics/transitions.h
index 233638ffda..674b7a8173 100644
--- a/engines/sci/graphics/transitions.h
+++ b/engines/sci/graphics/transitions.h
@@ -91,7 +91,8 @@ private:
void horizontalRollToCenter(bool blackoutFlag);
void diagonalRollFromCenter(bool blackoutFlag);
void diagonalRollToCenter(bool blackoutFlag);
- void updateScreenAndWait(int msec);
+ bool doCreateFrame(uint32 shouldBeAtMsec);
+ void updateScreenAndWait(uint32 shouldBeAtMsec);
GfxScreen *_screen;
GfxPalette *_palette;
@@ -102,6 +103,8 @@ private:
bool _blackoutFlag;
Common::Rect _picRect;
byte *_oldScreen; // buffer for saving current active screen data to, has dimenions of _screen->_displayScreen
+
+ uint32 _transitionStartTime; // when the current transition started in milliseconds
};
} // End of namespace Sci
diff --git a/engines/sci/graphics/view.cpp b/engines/sci/graphics/view.cpp
index 5f48574dcb..6b22ed397e 100644
--- a/engines/sci/graphics/view.cpp
+++ b/engines/sci/graphics/view.cpp
@@ -128,8 +128,11 @@ void GfxView::initData(GuiResourceId resourceId) {
_palette->createFromData(&_resourceData[palOffset], _resourceSize - palOffset, &_viewPalette);
_embeddedPal = true;
} else {
- // Only use the EGA-mapping, when being SCI1
- if (getSciVersion() >= SCI_VERSION_1_EGA) {
+ // Only use the EGA-mapping, when being SCI1 EGA
+ // SCI1 VGA conversion games (which will get detected as SCI1EARLY/MIDDLE/LATE) have some views
+ // with broken mapping tables. I guess those games won't use the mapping, so I rather disable it
+ // for them
+ if (getSciVersion() == SCI_VERSION_1_EGA) {
_EGAmapping = &_resourceData[palOffset];
for (EGAmapNr = 0; EGAmapNr < SCI_VIEW_EGAMAPPING_COUNT; EGAmapNr++) {
if (memcmp(_EGAmapping, EGAmappingStraight, SCI_VIEW_EGAMAPPING_SIZE) != 0)
diff --git a/engines/sci/module.mk b/engines/sci/module.mk
index 238209c446..344eef76d4 100644
--- a/engines/sci/module.mk
+++ b/engines/sci/module.mk
@@ -67,6 +67,7 @@ MODULE_OBJS := \
sound/soundcmd.o \
sound/drivers/adlib.o \
sound/drivers/amigamac.o \
+ sound/drivers/cms.o \
sound/drivers/fb01.o \
sound/drivers/midi.o \
sound/drivers/pcjr.o \
diff --git a/engines/sci/parser/grammar.cpp b/engines/sci/parser/grammar.cpp
index 6f37b49919..03e9d29660 100644
--- a/engines/sci/parser/grammar.cpp
+++ b/engines/sci/parser/grammar.cpp
@@ -38,8 +38,9 @@ namespace Sci {
#define TOKEN_CPAREN 0xfe000000
#define TOKEN_TERMINAL_CLASS 0x10000
#define TOKEN_TERMINAL_GROUP 0x20000
-#define TOKEN_STUFFING_WORD 0x40000
-#define TOKEN_NON_NT (TOKEN_OPAREN | TOKEN_TERMINAL_CLASS | TOKEN_TERMINAL_GROUP | TOKEN_STUFFING_WORD)
+#define TOKEN_STUFFING_LEAF 0x40000
+#define TOKEN_STUFFING_WORD 0x80000
+#define TOKEN_NON_NT (TOKEN_OPAREN | TOKEN_TERMINAL_CLASS | TOKEN_TERMINAL_GROUP | TOKEN_STUFFING_LEAF | TOKEN_STUFFING_WORD)
#define TOKEN_TERMINAL (TOKEN_TERMINAL_CLASS | TOKEN_TERMINAL_GROUP)
static int _allocd_rules = 0; // FIXME: Avoid non-const global vars
@@ -122,8 +123,10 @@ static void vocab_print_rule(ParseRule *rule) {
printf("C(%04x)", token & 0xffff);
else if (token & TOKEN_TERMINAL_GROUP)
printf("G(%04x)", token & 0xffff);
- else if (token & TOKEN_STUFFING_WORD)
+ else if (token & TOKEN_STUFFING_LEAF)
printf("%03x", token & 0xffff);
+ else if (token & TOKEN_STUFFING_WORD)
+ printf("{%03x}", token & 0xffff);
else
printf("[%03x]", token); /* non-terminal */
wspace = 1;
@@ -206,8 +209,8 @@ static ParseRule *_vbuild_rule(const parse_tree_branch_t *branch) {
rule->_data[tokens++] = value | TOKEN_STUFFING_WORD;
else { // normal inductive rule
rule->_data[tokens++] = TOKEN_OPAREN;
- rule->_data[tokens++] = type | TOKEN_STUFFING_WORD;
- rule->_data[tokens++] = value | TOKEN_STUFFING_WORD;
+ rule->_data[tokens++] = type | TOKEN_STUFFING_LEAF;
+ rule->_data[tokens++] = value | TOKEN_STUFFING_LEAF;
if (i == 0)
rule->_firstSpecial = tokens;
@@ -220,7 +223,7 @@ static ParseRule *_vbuild_rule(const parse_tree_branch_t *branch) {
return rule;
}
-static ParseRule *_vsatisfy_rule(ParseRule *rule, const ResultWord &input) {
+static ParseRule *_vsatisfy_rule(ParseRule *rule, const ResultWordList &input) {
int dep;
if (!rule->_numSpecials)
@@ -228,11 +231,32 @@ static ParseRule *_vsatisfy_rule(ParseRule *rule, const ResultWord &input) {
dep = rule->_data[rule->_firstSpecial];
- if (((dep & TOKEN_TERMINAL_CLASS) && ((dep & 0xffff) & input._class)) ||
- ((dep & TOKEN_TERMINAL_GROUP) && ((dep & 0xffff) & input._group))) {
+ int count = 0;
+ int match = 0;
+ ResultWordList::const_iterator iter;
+ // TODO: Inserting an array in the middle of another array is slow
+ Common::Array<int> matches;
+ matches.reserve(input.size());
+
+ // We store the first match in 'match', and any subsequent matches in
+ // 'matches'. 'match' replaces the special in the rule, and 'matches' gets
+ // inserted after it.
+ for (iter = input.begin(); iter != input.end(); ++iter)
+ if (((dep & TOKEN_TERMINAL_CLASS) && ((dep & 0xffff) & iter->_class)) ||
+ ((dep & TOKEN_TERMINAL_GROUP) && ((dep & 0xffff) & iter->_group))) {
+ if (count == 0)
+ match = TOKEN_STUFFING_WORD | iter->_group;
+ else
+ matches.push_back(TOKEN_STUFFING_WORD | iter->_group);
+ count++;
+ }
+
+ if (count) {
ParseRule *retval = new ParseRule(*rule);
++_allocd_rules;
- retval->_data[rule->_firstSpecial] = TOKEN_STUFFING_WORD | input._group;
+ retval->_data[rule->_firstSpecial] = match;
+ if (count > 1)
+ retval->_data.insert_at(rule->_firstSpecial+1, matches);
retval->_numSpecials--;
retval->_firstSpecial = 0;
@@ -277,10 +301,8 @@ static ParseRuleList *_vocab_add_rule(ParseRuleList *list, ParseRule *rule) {
while (seeker->next/* && seeker->next->terminal <= term*/) {
if (seeker->next->terminal == term) {
if (*(seeker->next->rule) == *rule) {
- delete rule;
- // FIXME: not sure about this change, fixes pq2 crashing when having opened the cabinet
- // and typing "go to bains" - delete rule deletes part of new_elem
- //delete new_elem;
+ delete new_elem; // NB: This also deletes 'rule'
+
return list; // No duplicate rules
}
}
@@ -445,6 +467,7 @@ static int _vbpt_append(ParseTreeNode *nodes, int *pos, int base, int value) {
nodes[base].left = &nodes[++(*pos)];
nodes[*pos].type = kParseTreeLeafNode;
nodes[*pos].value = value;
+ nodes[*pos].right = 0;
nodes[base].right = &nodes[++(*pos)];
nodes[*pos].type = kParseTreeBranchNode;
nodes[*pos].left = 0;
@@ -456,9 +479,29 @@ static int _vbpt_terminate(ParseTreeNode *nodes, int *pos, int base, int value)
// Terminates, overwriting a nextwrite forknode
nodes[base].type = kParseTreeLeafNode;
nodes[base].value = value;
+ nodes[base].right = 0;
+ return *pos;
+}
+static int _vbpt_append_word(ParseTreeNode *nodes, int *pos, int base, int value) {
+ // writes one value to an existing node and creates a sibling for writing
+ nodes[base].type = kParseTreeWordNode;
+ nodes[base].value = value;
+ nodes[base].right = &nodes[++(*pos)];
+ nodes[*pos].type = kParseTreeBranchNode;
+ nodes[*pos].left = 0;
+ nodes[*pos].right = 0;
+ return *pos;
+}
+
+static int _vbpt_terminate_word(ParseTreeNode *nodes, int *pos, int base, int value) {
+ // Terminates, overwriting a nextwrite forknode
+ nodes[base].type = kParseTreeWordNode;
+ nodes[base].value = value;
+ nodes[base].right = 0;
return *pos;
}
+
static int _vbpt_write_subexpression(ParseTreeNode *nodes, int *pos, ParseRule *rule, uint rulepos, int writepos) {
uint token;
@@ -470,11 +513,16 @@ static int _vbpt_write_subexpression(ParseTreeNode *nodes, int *pos, ParseRule *
nexttoken = (rulepos < rule->_data.size()) ? rule->_data[rulepos] : TOKEN_CPAREN;
if (nexttoken != TOKEN_CPAREN)
writepos = _vbpt_parenc(nodes, pos, writepos);
- } else if (token & TOKEN_STUFFING_WORD) {
+ } else if (token & TOKEN_STUFFING_LEAF) {
if (nexttoken == TOKEN_CPAREN)
writepos = _vbpt_terminate(nodes, pos, writepos, token & 0xffff);
else
writepos = _vbpt_append(nodes, pos, writepos, token & 0xffff);
+ } else if (token & TOKEN_STUFFING_WORD) {
+ if (nexttoken == TOKEN_CPAREN)
+ writepos = _vbpt_terminate_word(nodes, pos, writepos, token & 0xffff);
+ else
+ writepos = _vbpt_append_word(nodes, pos, writepos, token & 0xffff);
} else {
printf("\nError in parser (grammar.cpp, _vbpt_write_subexpression()): Rule data broken in rule ");
vocab_print_rule(rule);
@@ -486,16 +534,16 @@ static int _vbpt_write_subexpression(ParseTreeNode *nodes, int *pos, ParseRule *
return rulepos;
}
-int Vocabulary::parseGNF(const ResultWordList &words, bool verbose) {
+int Vocabulary::parseGNF(const ResultWordListList &words, bool verbose) {
Console *con = g_sci->getSciDebugger();
// Get the start rules:
ParseRuleList *work = _vocab_clone_rule_list_by_id(_parserRules, _parserBranches[0].data[1]);
ParseRuleList *results = NULL;
uint word = 0;
const uint words_nr = words.size();
- ResultWordList::const_iterator word_iter = words.begin();
+ ResultWordListList::const_iterator words_iter;
- for (word_iter = words.begin(); word_iter != words.end(); ++word_iter, ++word) {
+ for (words_iter = words.begin(); words_iter != words.end(); ++words_iter, ++word) {
ParseRuleList *new_work = NULL;
ParseRuleList *reduced_rules = NULL;
ParseRuleList *seeker, *subseeker;
@@ -505,8 +553,9 @@ int Vocabulary::parseGNF(const ResultWordList &words, bool verbose) {
seeker = work;
while (seeker) {
- if (seeker->rule->_numSpecials <= (words_nr - word))
- reduced_rules = _vocab_add_rule(reduced_rules, _vsatisfy_rule(seeker->rule, *word_iter));
+ if (seeker->rule->_numSpecials <= (words_nr - word)) {
+ reduced_rules = _vocab_add_rule(reduced_rules, _vsatisfy_rule(seeker->rule, *words_iter));
+ }
seeker = seeker->next;
}
@@ -570,6 +619,7 @@ int Vocabulary::parseGNF(const ResultWordList &words, bool verbose) {
_parserNodes[1].type = kParseTreeLeafNode;
_parserNodes[1].value = 0x141;
+ _parserNodes[1].right = 0;
_parserNodes[2].type = kParseTreeBranchNode;
_parserNodes[2].left = 0;
diff --git a/engines/sci/parser/said.cpp b/engines/sci/parser/said.cpp
index 9c07be2dff..7393874856 100644
--- a/engines/sci/parser/said.cpp
+++ b/engines/sci/parser/said.cpp
@@ -94,6 +94,7 @@ static ParseTreeNode* said_next_node() {
static ParseTreeNode* said_leaf_node(ParseTreeNode* pos, int value) {
pos->type = kParseTreeLeafNode;
pos->value = value;
+ pos->right = 0;
return pos;
}
@@ -101,6 +102,7 @@ static ParseTreeNode* said_leaf_node(ParseTreeNode* pos, int value) {
static ParseTreeNode* said_word_node(ParseTreeNode* pos, int value) {
pos->type = kParseTreeWordNode;
pos->value = value;
+ pos->right = 0;
return pos;
}
@@ -780,17 +782,39 @@ static int matchTrees(ParseTreeNode* parseT, ParseTreeNode* saidT)
// both saidT and parseT are terminals
int said_val = node_terminal_value(saidT);
- int parse_val = node_terminal_value(parseT);
- if (said_val != WORD_NONE &&
- (said_val == parse_val || said_val == WORD_ANY ||
- parse_val == WORD_ANY))
+#ifdef SCI_DEBUG_PARSE_TREE_AUGMENTATION
+ scidprintf("%*smatchTrees matching terminals: %03x", outputDepth, "", node_terminal_value(parseT));
+ ParseTreeNode* t = parseT->right->right;
+ while (t) {
+ scidprintf(",%03x", t->value);
+ t = t->right;
+ }
+ scidprintf(" vs %03x", said_val);
+#endif
+
+ if (said_val == WORD_NONE) {
+ ret = -1;
+ } else if (said_val == WORD_ANY) {
ret = 1;
- else
+ } else {
ret = -1;
- scidprintf("%*smatchTrees matching terminals: %03x vs %03x (%d)\n",
- outputDepth, "", parse_val, said_val, ret);
+ // scan through the word group ids in the parse tree leaf to see if
+ // one matches the word group in the said tree
+ parseT = parseT->right->right;
+ do {
+ assert(parseT->type != kParseTreeBranchNode);
+ int parse_val = parseT->value;
+ if (parse_val == WORD_ANY || parse_val == said_val) {
+ ret = 1;
+ break;
+ }
+ parseT = parseT->right;
+ } while (parseT);
+ }
+
+ scidprintf(" (ret %d)\n", ret);
} else if (node_is_terminal(saidT) && !node_is_terminal(parseT)) {
@@ -1107,7 +1131,7 @@ True
said put washer on shaft & 455 , ( 3fa < cb ) / 8c6
True
-said depth correct & [!*] < 8b1 / 22
+said depth correct & [!*] < 8b1 / 22b
True
said depth acknowledged & / 46d , 460 , 44d < 8b1
diff --git a/engines/sci/parser/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp
index 20436d5b30..f9989b22a8 100644
--- a/engines/sci/parser/vocabulary.cpp
+++ b/engines/sci/parser/vocabulary.cpp
@@ -40,6 +40,7 @@ Vocabulary::Vocabulary(ResourceManager *resMan, bool foreign) : _resMan(resMan),
// Mark parse tree as unused
_parserNodes[0].type = kParseTreeLeafNode;
_parserNodes[0].value = 0;
+ _parserNodes[0].right = 0;
_synonyms.clear(); // No synonyms
@@ -72,6 +73,8 @@ Vocabulary::Vocabulary(ResourceManager *resMan, bool foreign) : _resMan(resMan),
_parserRules = NULL;
}
+ loadAltInputs();
+
parser_base = NULL_REG;
parser_event = NULL_REG;
parserIsValid = false;
@@ -80,6 +83,7 @@ Vocabulary::Vocabulary(ResourceManager *resMan, bool foreign) : _resMan(resMan),
Vocabulary::~Vocabulary() {
freeRuleList(_parserRules);
freeSuffixes();
+ freeAltInputs();
}
void Vocabulary::reset() {
@@ -165,8 +169,14 @@ bool Vocabulary::loadParserWords() {
newWord._class = ((resource->data[seeker]) << 4) | ((c & 0xf0) >> 4);
newWord._group = (resource->data[seeker + 2]) | ((c & 0x0f) << 8);
- // Add the word to the list
- _parserWords[currentWord] = newWord;
+ // SCI01 was the first version to support multiple class/group pairs
+ // per word, so we clear the list in earlier versions
+ // in earlier versions.
+ if (getSciVersion() < SCI_VERSION_01)
+ _parserWords[currentWord].clear();
+
+ // Add this to the list of possible class,group pairs for this word
+ _parserWords[currentWord].push_back(newWord);
seeker += 3;
}
@@ -181,8 +191,9 @@ const char *Vocabulary::getAnyWordFromGroup(int group) {
return "{nothing}";
for (WordMap::const_iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) {
- if (i->_value._group == group)
- return i->_key.c_str();
+ for (ResultWordList::const_iterator j = i->_value.begin(); j != i->_value.end(); ++j)
+ if (j->_group == group)
+ return i->_key.c_str();
}
return "{invalid}";
@@ -264,8 +275,108 @@ bool Vocabulary::loadBranches() {
return true;
}
+bool Vocabulary::loadAltInputs() {
+ Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_ALT_INPUTS), 1);
+
+ if (!resource)
+ return true; // it's not a problem if this resource doesn't exist
+
+ const char *data = (const char*)resource->data;
+ const char *data_end = data + resource->size;
+
+ _altInputs.clear();
+ _altInputs.resize(256);
+
+ while (data < data_end && *data) {
+ AltInput t;
+ t._input = data;
+
+ unsigned int l = strlen(data);
+ t._inputLength = l;
+ data += l + 1;
+
+ t._replacement = data;
+ l = strlen(data);
+ data += l + 1;
+
+ if (data < data_end && strncmp(data, t._input, t._inputLength) == 0)
+ t._prefix = true;
+ else
+ t._prefix = false;
+
+ unsigned char firstChar = t._input[0];
+ _altInputs[firstChar].push_front(t);
+ }
+
+ return true;
+}
+
+void Vocabulary::freeAltInputs() {
+ Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_ALT_INPUTS), 0);
+ if (resource)
+ _resMan->unlockResource(resource);
+
+ _altInputs.clear();
+}
+
+bool Vocabulary::checkAltInput(Common::String& text, uint16& cursorPos) {
+ if (_altInputs.empty())
+ return false;
+ if (SELECTOR(parseLang) == -1)
+ return false;
+ if (readSelectorValue(g_sci->getEngineState()->_segMan, g_sci->getGameObject(), SELECTOR(parseLang)) == 1)
+ return false;
+
+ bool ret = false;
+ unsigned int loopCount = 0;
+ bool changed;
+ do {
+ changed = false;
+
+ const char* t = text.c_str();
+ unsigned int tlen = text.size();
+
+ for (unsigned int p = 0; p < tlen && !changed; ++p) {
+ unsigned char s = t[p];
+ if (s >= _altInputs.size() || _altInputs[s].empty())
+ continue;
+ Common::List<AltInput>::iterator i;
+ for (i = _altInputs[s].begin(); i != _altInputs[s].end(); ++i) {
+ if (p + i->_inputLength > tlen)
+ continue;
+ if (i->_prefix && cursorPos > p && cursorPos <= p + i->_inputLength)
+ continue;
+ if (strncmp(i->_input, t+p, i->_inputLength) == 0) {
+ // replace
+ if (cursorPos > p + i->_inputLength) {
+ cursorPos += strlen(i->_replacement) - i->_inputLength;
+ } else if (cursorPos > p) {
+ cursorPos = p + strlen(i->_replacement);
+ }
+
+ for (unsigned int j = 0; j < i->_inputLength; ++j)
+ text.deleteChar(p);
+ const char *r = i->_replacement;
+ while (*r)
+ text.insertChar(*r++, p++);
+
+ assert(cursorPos <= text.size());
+
+ changed = true;
+ ret = true;
+ break;
+ }
+ }
+ }
+ } while (changed && loopCount < 10);
+
+ return ret;
+}
+
// we assume that *word points to an already lowercased word
-ResultWord Vocabulary::lookupWord(const char *word, int word_len) {
+void Vocabulary::lookupWord(ResultWordList& retval, const char *word, int word_len) {
+ retval.clear();
+
Common::String tempword(word, word_len);
// Remove all dashes from tempword
@@ -277,15 +388,22 @@ ResultWord Vocabulary::lookupWord(const char *word, int word_len) {
}
// Look it up:
- WordMap::iterator dict_word = _parserWords.find(tempword);
+ WordMap::iterator dict_words = _parserWords.find(tempword);
// Match found? Return it!
- if (dict_word != _parserWords.end()) {
- return dict_word->_value;
+ if (dict_words != _parserWords.end()) {
+ retval = dict_words->_value;
+
+ // SCI01 was the first version to support
+ // multiple matches, so no need to look further
+ // in earlier versions.
+ if (getSciVersion() < SCI_VERSION_01)
+ return;
+
}
// Now try all suffixes
- for (SuffixList::const_iterator suffix = _parserSuffixes.begin(); suffix != _parserSuffixes.end(); ++suffix)
+ for (SuffixList::const_iterator suffix = _parserSuffixes.begin(); suffix != _parserSuffixes.end(); ++suffix) {
if (suffix->alt_suffix_length <= word_len) {
int suff_index = word_len - suffix->alt_suffix_length;
@@ -298,27 +416,38 @@ ResultWord Vocabulary::lookupWord(const char *word, int word_len) {
// ...and append "correct" suffix
tempword2 += Common::String(suffix->word_suffix, suffix->word_suffix_length);
- dict_word = _parserWords.find(tempword2);
-
- if ((dict_word != _parserWords.end()) && (dict_word->_value._class & suffix->class_mask)) { // Found it?
- // Use suffix class
- ResultWord tmp = dict_word->_value;
- tmp._class = suffix->result_class;
- return tmp;
+ dict_words = _parserWords.find(tempword2);
+
+ if (dict_words != _parserWords.end()) {
+ for (ResultWordList::const_iterator j = dict_words->_value.begin(); j != dict_words->_value.end(); ++j) {
+ if (j->_class & suffix->class_mask) { // Found it?
+ // Use suffix class
+ ResultWord tmp = *j;
+ tmp._class = suffix->result_class;
+ retval.push_back(tmp);
+
+ // SCI01 was the first version to support
+ // multiple matches, so no need to look further
+ // in earlier versions.
+ if (getSciVersion() < SCI_VERSION_01)
+ return;
+ }
+ }
}
}
}
+ }
+
+ if (!retval.empty())
+ return;
// No match so far? Check if it's a number.
- ResultWord retval = { -1, -1 };
char *tester;
if ((strtol(tempword.c_str(), &tester, 10) >= 0) && (*tester == '\0')) { // Do we have a complete number here?
ResultWord tmp = { VOCAB_CLASS_NUMBER, VOCAB_MAGIC_NUMBER_GROUP };
- retval = tmp;
+ retval.push_back(tmp);
}
-
- return retval;
}
void Vocabulary::debugDecipherSaidBlock(const byte *addr) {
@@ -397,7 +526,7 @@ static const byte lowerCaseMap[256] = {
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff // 0xf0
};
-bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, char **error) {
+bool Vocabulary::tokenizeString(ResultWordListList &retval, const char *sentence, char **error) {
char currentWord[VOCAB_MAX_WORDLENGTH] = "";
int pos_in_sentence = 0;
unsigned char c;
@@ -418,10 +547,12 @@ bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, ch
else {
if (wordLen) { // Finished a word?
- ResultWord lookup_result = lookupWord(currentWord, wordLen);
+ ResultWordList lookup_result;
+
// Look it up
+ lookupWord(lookup_result, currentWord, wordLen);
- if (lookup_result._class == -1) { // Not found?
+ if (lookup_result.empty()) { // Not found?
*error = (char *)calloc(wordLen + 1, 1);
strncpy(*error, currentWord, wordLen); // Set the offending word
retval.clear();
@@ -459,43 +590,19 @@ void Vocabulary::printSuffixes() const {
void Vocabulary::printParserWords() const {
Console *con = g_sci->getSciDebugger();
- int j = 0;
+ int n = 0;
for (WordMap::iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) {
- con->DebugPrintf("%4d: %03x [%03x] %20s |", j, i->_value._class, i->_value._group, i->_key.c_str());
- if (j % 3 == 0)
- con->DebugPrintf("\n");
- j++;
+ for (ResultWordList::iterator j = i->_value.begin(); j != i->_value.end(); ++j) {
+ con->DebugPrintf("%4d: %03x [%03x] %20s |", n, j->_class, j->_group, i->_key.c_str());
+ if (n % 3 == 0)
+ con->DebugPrintf("\n");
+ n++;
+ }
}
con->DebugPrintf("\n");
}
-void _vocab_recursive_ptree_dump_treelike(ParseTreeNode *tree) {
- assert(tree);
-
- if (tree->type == kParseTreeLeafNode)
- printf("%x", tree->value);
- else {
- ParseTreeNode* lbranch = tree->left;
- ParseTreeNode* rbranch = tree->right;
- printf("<");
-
- if (lbranch)
- _vocab_recursive_ptree_dump_treelike(lbranch);
- else
- printf("NULL");
-
- printf(",");
-
- if (rbranch)
- _vocab_recursive_ptree_dump_treelike(rbranch);
- else
- printf("NULL");
-
- printf(">");
- }
-}
-
void _vocab_recursive_ptree_dump(ParseTreeNode *tree, int blanks) {
assert(tree);
@@ -526,33 +633,37 @@ void _vocab_recursive_ptree_dump(ParseTreeNode *tree, int blanks) {
if (rbranch) {
if (rbranch->type == kParseTreeBranchNode)
_vocab_recursive_ptree_dump(rbranch, blanks);
- else
+ else {
printf("%x", rbranch->value);
+ while (rbranch->right) {
+ rbranch = rbranch->right;
+ printf("/%x", rbranch->value);
+ }
+ }
}/* else printf("nil");*/
}
void vocab_dump_parse_tree(const char *tree_name, ParseTreeNode *nodes) {
- //_vocab_recursive_ptree_dump_treelike(nodes, 0, 0);
printf("(setq %s \n'(", tree_name);
_vocab_recursive_ptree_dump(nodes, 1);
printf("))\n");
}
void Vocabulary::dumpParseTree() {
- //_vocab_recursive_ptree_dump_treelike(nodes, 0, 0);
printf("(setq parse-tree \n'(");
_vocab_recursive_ptree_dump(_parserNodes, 1);
printf("))\n");
}
-void Vocabulary::synonymizeTokens(ResultWordList &words) {
+void Vocabulary::synonymizeTokens(ResultWordListList &words) {
if (_synonyms.empty())
return; // No synonyms: Nothing to check
- for (ResultWordList::iterator i = words.begin(); i != words.end(); ++i)
- for (SynonymList::const_iterator sync = _synonyms.begin(); sync != _synonyms.end(); ++sync)
- if (i->_group == sync->replaceant)
- i->_group = sync->replacement;
+ for (ResultWordListList::iterator i = words.begin(); i != words.end(); ++i)
+ for (ResultWordList::iterator j = i->begin(); j != i->end(); ++j)
+ for (SynonymList::const_iterator sync = _synonyms.begin(); sync != _synonyms.end(); ++sync)
+ if (j->_group == sync->replaceant)
+ j->_group = sync->replacement;
}
void Vocabulary::printParserNodes(int num) {
@@ -578,6 +689,7 @@ int Vocabulary::parseNodes(int *i, int *pos, int type, int nr, int argc, const c
if (type == kParseNumber) {
_parserNodes[*pos += 1].type = kParseTreeLeafNode;
_parserNodes[*pos].value = nr;
+ _parserNodes[*pos].right = 0;
return *pos;
}
if (type == kParseEndOfInput) {
diff --git a/engines/sci/parser/vocabulary.h b/engines/sci/parser/vocabulary.h
index d4df8af715..620d50c09d 100644
--- a/engines/sci/parser/vocabulary.h
+++ b/engines/sci/parser/vocabulary.h
@@ -49,7 +49,9 @@ enum {
VOCAB_RESOURCE_SCI1_MAIN_VOCAB = 900,
VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES = 901,
- VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB = 902
+ VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB = 902,
+
+ VOCAB_RESOURCE_ALT_INPUTS = 913
};
@@ -117,8 +119,9 @@ struct ResultWord {
};
typedef Common::List<ResultWord> ResultWordList;
+typedef Common::List<ResultWordList> ResultWordListList;
-typedef Common::HashMap<Common::String, ResultWord, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> WordMap;
+typedef Common::HashMap<Common::String, ResultWordList, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> WordMap;
struct ParseRuleList;
@@ -146,6 +149,15 @@ struct synonym_t {
typedef Common::List<synonym_t> SynonymList;
+
+struct AltInput {
+ const char *_input;
+ const char *_replacement;
+ unsigned int _inputLength;
+ bool _prefix;
+};
+
+
struct parse_tree_branch_t {
int id;
int data[10];
@@ -161,7 +173,7 @@ struct ParseTreeNode {
ParseTypes type; /**< leaf or branch */
int value; /**< For leaves */
ParseTreeNode* left; /**< Left child, for branches */
- ParseTreeNode* right; /**< Right child, for branches */
+ ParseTreeNode* right; /**< Right child, for branches (and word leaves) */
};
enum VocabularyVersions {
@@ -186,11 +198,11 @@ public:
/**
* Looks up a single word in the words and suffixes list.
+ * @param retval the list of matches
* @param word pointer to the word to look up
* @param word_len length of the word to look up
- * @return the matching word (or (-1,-1) if there was no match)
*/
- ResultWord lookupWord(const char *word, int word_len);
+ void lookupWord(ResultWordList &retval, const char *word, int word_len);
/**
@@ -204,7 +216,7 @@ public:
* contain any useful words; if not, *error points to a malloc'd copy of
* the offending word. The returned list may contain anywords.
*/
- bool tokenizeString(ResultWordList &retval, const char *sentence, char **error);
+ bool tokenizeString(ResultWordListList &retval, const char *sentence, char **error);
/**
* Builds a parse tree from a list of words, using a set of Greibach Normal
@@ -215,7 +227,7 @@ public:
* nodes or if the sentence structure in 'words' is not part of the
* language described by the grammar passed in 'rules'.
*/
- int parseGNF(const ResultWordList &words, bool verbose = false);
+ int parseGNF(const ResultWordListList &words, bool verbose = false);
/**
* Constructs the Greibach Normal Form of the grammar supplied in 'branches'.
@@ -262,9 +274,9 @@ public:
/**
* Synonymizes a token list
- * Parameters: (ResultWordList &) words: The word list to synonymize
+ * Parameters: (ResultWordListList &) words: The word list to synonymize
*/
- void synonymizeTokens(ResultWordList &words);
+ void synonymizeTokens(ResultWordListList &words);
void printParserNodes(int num);
@@ -272,6 +284,14 @@ public:
int parseNodes(int *i, int *pos, int type, int nr, int argc, const char **argv);
+ /**
+ * Check text input against alternative inputs.
+ * @param text The text to process. It will be modified in-place
+ * @param cursorPos The cursor position
+ * @return true if anything changed
+ */
+ bool checkAltInput(Common::String& text, uint16& cursorPos);
+
private:
/**
* Loads all words from the main vocabulary.
@@ -304,6 +324,20 @@ private:
*/
void freeRuleList(ParseRuleList *rule_list);
+
+ /**
+ * Retrieves all alternative input combinations from vocab 913.
+ * @return true on success, false on error
+ */
+ bool loadAltInputs();
+
+ /**
+ * Frees all alternative input combinations.
+ */
+ void freeAltInputs();
+
+
+
ResourceManager *_resMan;
VocabularyVersions _vocabVersion;
@@ -318,6 +352,7 @@ private:
Common::Array<parse_tree_branch_t> _parserBranches;
WordMap _parserWords;
SynonymList _synonyms; /**< The list of synonyms */
+ Common::Array<Common::List<AltInput> > _altInputs;
public:
// Accessed by said()
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 00f50714af..9809f10576 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -92,7 +92,7 @@ const char *getSciVersionDesc(SciVersion version) {
#undef SCI_REQUIRE_RESOURCE_FILES
-//#define SCI_VERBOSE_resMan 1
+//#define SCI_VERBOSE_RESMAN 1
static const char *sci_error_types[] = {
"No error",
@@ -142,7 +142,6 @@ static const ResourceType s_resTypeMapSci0[] = {
kResourceTypeTranslation // 0x14
};
-#ifdef ENABLE_SCI32
// TODO: 12 should be "Wave", but SCI seems to just store it in Audio resources
static const ResourceType s_resTypeMapSci21[] = {
kResourceTypeView, kResourceTypePic, kResourceTypeScript, kResourceTypeText, // 0x00-0x03
@@ -152,7 +151,6 @@ static const ResourceType s_resTypeMapSci21[] = {
kResourceTypeMap, kResourceTypeHeap, kResourceTypeChunk, kResourceTypeAudio36, // 0x10-0x13
kResourceTypeSync36, kResourceTypeTranslation, kResourceTypeRobot, kResourceTypeVMD // 0x14-0x17
};
-#endif
ResourceType ResourceManager::convertResType(byte type) {
type &= 0x7f;
@@ -163,7 +161,6 @@ ResourceType ResourceManager::convertResType(byte type) {
return s_resTypeMapSci0[type];
} else {
// SCI2.1+
-#ifdef ENABLE_SCI32
if (type < ARRAYSIZE(s_resTypeMapSci21)) {
// LSL6 hires doesn't have the chunk resource type, to match
// the resource types of the lowres version, thus we use the
@@ -173,9 +170,6 @@ ResourceType ResourceManager::convertResType(byte type) {
else
return s_resTypeMapSci21[type];
}
-#else
- error("SCI32 support not compiled in");
-#endif
}
return kResourceTypeInvalid;
@@ -490,8 +484,9 @@ void ResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
int error = res->decompress(resMan->getVolVersion(), fileStream);
if (error) {
- warning("Error %d occurred while reading %s from resource file: %s",
- error, res->_id.toString().c_str(), sci_error_types[error]);
+ warning("Error %d occurred while reading %s from resource file %s: %s",
+ error, res->_id.toString().c_str(), res->getResourceLocation().c_str(),
+ sci_error_types[error]);
res->unalloc();
}
@@ -852,7 +847,16 @@ void ResourceManager::init() {
debugC(1, kDebugLevelResMan, "resMan: Detected Amiga graphic resources");
break;
default:
+#ifdef ENABLE_SCI32
error("resMan: Couldn't determine view type");
+#else
+ if (getSciVersion() >= SCI_VERSION_2) {
+ // SCI support isn't built in, thus the view type won't be determined for
+ // SCI2+ games. This will be handled further up, so throw no error here
+ } else {
+ error("resMan: Couldn't determine view type");
+ }
+#endif
}
#ifdef ENABLE_SCI32
@@ -904,7 +908,7 @@ void ResourceManager::addToLRU(Resource *res) {
}
_LRU.push_front(res);
_memoryLRU += res->size;
-#if SCI_VERBOSE_resMan
+#if SCI_VERBOSE_RESMAN
debug("Adding %s.%03d (%d bytes) to lru control: %d bytes total",
getResourceTypeName(res->type), res->number, res->size,
mgr->_memoryLRU);
@@ -935,7 +939,7 @@ void ResourceManager::freeOldResources() {
Resource *goner = *_LRU.reverse_begin();
removeFromLRU(goner);
goner->unalloc();
-#ifdef SCI_VERBOSE_resMan
+#ifdef SCI_VERBOSE_RESMAN
printf("resMan-debug: LRU: Freeing %s.%03d (%d bytes)\n", getResourceTypeName(goner->type), goner->number, goner->size);
#endif
}
@@ -1518,7 +1522,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
} while (type != 0x1F); // the last entry is FF
// reading each type's offsets
- uint32 off = 0;
+ uint32 fileOffset = 0;
for (type = 0; type < 32; type++) {
if (resMap[type].wOffset == 0) // this resource does not exist in map
continue;
@@ -1528,15 +1532,15 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
int volume_nr = 0;
if (_mapVersion == kResVersionSci11) {
// offset stored in 3 bytes
- off = fileStream->readUint16LE();
- off |= fileStream->readByte() << 16;
- off <<= 1;
+ fileOffset = fileStream->readUint16LE();
+ fileOffset |= fileStream->readByte() << 16;
+ fileOffset <<= 1;
} else {
// offset/volume stored in 4 bytes
- off = fileStream->readUint32LE();
+ fileOffset = fileStream->readUint32LE();
if (_mapVersion < kResVersionSci11) {
- volume_nr = off >> 28; // most significant 4 bits
- off &= 0x0FFFFFFF; // least significant 28 bits
+ volume_nr = fileOffset >> 28; // most significant 4 bits
+ fileOffset &= 0x0FFFFFFF; // least significant 28 bits
} else {
// in SCI32 it's a plain offset
}
@@ -1547,19 +1551,30 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
return SCI_ERROR_RESMAP_NOT_FOUND;
}
resId = ResourceId(convertResType(type), number);
- // adding new resource only if it does not exist
- if (_resMap.contains(resId) == false) {
- // NOTE: We add the map's volume number here to the specified volume number
- // for SCI2.1 and SCI3 maps that are not resmap.000. The resmap.* files' numbers
- // need to be used in concurrence with the volume specified in the map to get
- // the actual resource file.
- int mapVolumeNr = volume_nr + map->_volumeNumber;
- ResourceSource *source = findVolume(map, mapVolumeNr);
- // FIXME: this code has serious issues with multiple RESMAP.* files (like in unmodified gk2)
- // adding a resource with source == NULL would crash later on
- if (!source)
- error("Unable to find volume for map %s volumeNr %d", map->getLocationName().c_str(), mapVolumeNr);
- addResource(resId, source, off);
+ // NOTE: We add the map's volume number here to the specified volume number
+ // for SCI2.1 and SCI3 maps that are not resmap.000. The resmap.* files' numbers
+ // need to be used in concurrence with the volume specified in the map to get
+ // the actual resource file.
+ int mapVolumeNr = volume_nr + map->_volumeNumber;
+ ResourceSource *source = findVolume(map, mapVolumeNr);
+ // FIXME: this code has serious issues with multiple RESMAP.* files (like in unmodified gk2)
+ // adding a resource with source == NULL would crash later on
+ if (!source)
+ error("Unable to find volume for map %s volumeNr %d", map->getLocationName().c_str(), mapVolumeNr);
+
+ Resource *resource = _resMap.getVal(resId, NULL);
+ if (!resource) {
+ addResource(resId, source, fileOffset);
+ } else {
+ // if resource is already present, change it to new content
+ // this is needed at least for pharkas/german. This version
+ // contains several duplicate resources INSIDE the resource
+ // data files like fonts, views, scripts, etc. And if we use
+ // the first entries, half of the game will be english and
+ // umlauts will also be missing :P
+ resource->_source = source;
+ resource->_fileOffset = fileOffset;
+ resource->size = 0;
}
}
}
@@ -1934,7 +1949,18 @@ void ResourceManager::detectSciVersion() {
s_sciVersion = SCI_VERSION_0_EARLY;
bool oldDecompressors = true;
- ResourceCompression viewCompression = getViewCompression();
+ ResourceCompression viewCompression;
+#ifdef ENABLE_SCI32
+ viewCompression = getViewCompression();
+#else
+ if (_volVersion == kResVersionSci32) {
+ // SCI32 support isn't built in, thus view detection will fail
+ viewCompression = kCompUnknown;
+ } else {
+ viewCompression = getViewCompression();
+ }
+#endif
+
if (viewCompression != kCompLZW) {
// If it's a different compression type from kCompLZW, the game is probably
// SCI_VERSION_1_EGA or later. If the views are uncompressed, it is
@@ -1955,8 +1981,18 @@ void ResourceManager::detectSciVersion() {
// SCI1.1 VGA views
_viewType = kViewVga11;
} else {
+#ifdef ENABLE_SCI32
// Otherwise we detect it from a view
_viewType = detectViewType();
+#else
+ if (_volVersion == kResVersionSci32 && viewCompression == kCompUnknown) {
+ // A SCI32 game, but SCI32 support is disabled. Force the view type
+ // to kViewVga11, as we can't read from the game's resource files
+ _viewType = kViewVga11;
+ } else {
+ _viewType = detectViewType();
+ }
+#endif
}
if (_volVersion == kResVersionSci11Mac) {
@@ -2062,7 +2098,7 @@ void ResourceManager::detectSciVersion() {
// is increment here, but ignore for all the regular sci1late games
// the problem is, we dont have access to that detection till later
// so maybe (part of?) that detection should get moved in here
- if ((g_sci->getGameId() == GID_LSL1) && (g_sci->getLanguage() == Common::ES_ESP)) {
+ if (g_sci && (g_sci->getGameId() == GID_LSL1) && (g_sci->getLanguage() == Common::ES_ESP)) {
s_sciVersion = SCI_VERSION_1_MIDDLE;
return;
}
@@ -2137,6 +2173,19 @@ bool ResourceManager::detectForPaletteMergingForSci11() {
return false;
}
+// is called on SCI0EARLY games to make sure that sound resources are in fact also SCI0EARLY
+bool ResourceManager::detectEarlySound() {
+ Resource *res = findResource(ResourceId(kResourceTypeSound, 1), 0);
+ if (res) {
+ if (res->size >= 0x22) {
+ if (READ_LE_UINT16(res->data + 0x1f) == 0) // channel 15 voice count + play mask is 0 in SCI0LATE
+ if (res->data[0x21] == 0) // last byte right before actual data is 0 as well
+ return false;
+ }
+ }
+ return true;
+}
+
// Functions below are based on PD code by Brian Provinciano (SCI Studio)
bool ResourceManager::hasOldScriptHeader() {
Resource *res = findResource(ResourceId(kResourceTypeScript, 0), 0);
@@ -2329,4 +2378,8 @@ Common::String ResourceManager::findSierraGameId() {
return sierraId;
}
+const Common::String &Resource::getResourceLocation() const {
+ return _source->getLocationName();
+}
+
} // End of namespace Sci
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index 48210b835f..f5d6517398 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -219,6 +219,8 @@ public:
*/
void writeToStream(Common::WriteStream *stream) const;
+ const Common::String &getResourceLocation() const;
+
// FIXME: This audio specific method is a hack. After all, why should a
// Resource have audio specific methods? But for now we keep this, as it
// eases transition.
@@ -315,6 +317,7 @@ public:
void setAudioLanguage(int language);
int getAudioLanguage() const;
+ bool isGMTrackIncluded();
bool isVGA() const { return (_viewType == kViewVga) || (_viewType == kViewVga11); }
bool isAmiga32color() const { return _viewType == kViewAmiga; }
bool isSci11Mac() const { return _volVersion == kResVersionSci11Mac; }
@@ -344,6 +347,8 @@ public:
bool detectFontExtended();
// Detects, if SCI1.1 game uses palette merging
bool detectForPaletteMergingForSci11();
+ // Detects, if SCI0EARLY game also has SCI0EARLY sound resources
+ bool detectEarlySound();
/**
* Finds the internal Sierra ID of the current game from script 0.
diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp
index a25505fe47..e6b8fd06c2 100644
--- a/engines/sci/resource_audio.cpp
+++ b/engines/sci/resource_audio.cpp
@@ -61,7 +61,7 @@ AudioVolumeResourceSource::AudioVolumeResourceSource(ResourceManager *resMan, co
// Now read the whole offset mapping table for later usage
int32 recordCount = fileStream->readUint32LE();
if (!recordCount)
- error("compressed audio volume doesn't contain any entries!");
+ error("compressed audio volume doesn't contain any entries");
int32 *offsetMapping = new int32[(recordCount + 1) * 2];
_audioCompressionOffsetMapping = offsetMapping;
for (int recordNo = 0; recordNo < recordCount; recordNo++) {
@@ -273,6 +273,13 @@ void ResourceManager::removeAudioResource(ResourceId resId) {
// w syncAscSize (iff seq has bit 6 set)
int ResourceManager::readAudioMapSCI11(ResourceSource *map) {
+#ifndef ENABLE_SCI32
+ // SCI32 support is not built in. Check if this is a SCI32 game
+ // and if it is abort here.
+ if (_volVersion == kResVersionSci32)
+ return SCI_ERROR_RESMAP_NOT_FOUND;
+#endif
+
uint32 offset = 0;
Resource *mapRes = findResource(ResourceId(kResourceTypeMap, map->_volumeNumber), false);
@@ -519,6 +526,41 @@ int ResourceManager::getAudioLanguage() const {
return (_audioMapSCI1 ? _audioMapSCI1->_volumeNumber : 0);
}
+bool ResourceManager::isGMTrackIncluded() {
+ // This check only makes sense for SCI1 and newer games
+ if (getSciVersion() < SCI_VERSION_1_EARLY)
+ return false;
+
+ // SCI2 and newer games always have GM tracks
+ if (getSciVersion() >= SCI_VERSION_2)
+ return true;
+
+ // For the leftover games, we can safely use SCI_VERSION_1_EARLY for the soundVersion
+ const SciVersion soundVersion = SCI_VERSION_1_EARLY;
+
+ // Read the first song and check if it has a GM track
+ bool result = false;
+ Common::List<ResourceId> *resources = listResources(kResourceTypeSound, -1);
+ Common::sort(resources->begin(), resources->end());
+ Common::List<ResourceId>::iterator itr = resources->begin();
+ int firstSongId = itr->getNumber();
+ delete resources;
+
+ SoundResource *song1 = new SoundResource(firstSongId, this, soundVersion);
+ if (!song1) {
+ warning("ResourceManager::isGMTrackIncluded: track 1 not found");
+ return false;
+ }
+
+ SoundResource::Track *gmTrack = song1->getTrackByType(0x07);
+ if (gmTrack)
+ result = true;
+
+ delete song1;
+
+ return result;
+}
+
SoundResource::SoundResource(uint32 resourceNr, ResourceManager *resMan, SciVersion soundVersion) : _resMan(resMan), _soundVersion(soundVersion) {
Resource *resource = _resMan->findResource(ResourceId(kResourceTypeSound, resourceNr), true);
int trackNr, channelNr;
@@ -629,6 +671,8 @@ SoundResource::SoundResource(uint32 resourceNr, ResourceManager *resMan, SciVers
channel->data = resource->data + dataOffset;
channel->size = READ_LE_UINT16(data + 4);
channel->curPos = 0;
+ // FIXME: number contains (low nibble) channel and (high nibble) flags
+ // 0x20 is set on rhythm channels to prevent remapping
channel->number = *channel->data;
channel->poly = *(channel->data + 1);
channel->time = channel->prev = 0;
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 7a9a786121..3fe398f426 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -45,6 +45,7 @@
#include "sci/engine/selector.h" // for SELECTOR
#include "sci/sound/audio.h"
+#include "sci/sound/music.h"
#include "sci/sound/soundcmd.h"
#include "sci/graphics/animate.h"
#include "sci/graphics/cache.h"
@@ -173,12 +174,15 @@ SciEngine::~SciEngine() {
g_sci = 0;
}
+extern void showScummVMDialog(const Common::String &message);
+
Common::Error SciEngine::run() {
g_eventRec.registerRandomSource(_rng, "sci");
// Assign default values to the config manager, in case settings are missing
- ConfMan.registerDefault("undither", "true");
- ConfMan.registerDefault("enable_fb01", "false");
+ ConfMan.registerDefault("sci_undither", "true");
+ ConfMan.registerDefault("sci_originalsaveload", "false");
+ ConfMan.registerDefault("native_fb01", "false");
_resMan = new ResourceManager();
assert(_resMan);
@@ -199,17 +203,19 @@ Common::Error SciEngine::run() {
// Add the after market GM patches for the specified game, if they exist
_resMan->addNewGMPatch(_gameId);
- _gameObj = _resMan->findGameObject();
+ _gameObjectAddress = _resMan->findGameObject();
+ _gameSuperClassAddress = NULL_REG;
SegManager *segMan = new SegManager(_resMan);
// Initialize the game screen
_gfxScreen = new GfxScreen(_resMan);
- _gfxScreen->debugUnditherSetState(ConfMan.getBool("undither"));
+ _gfxScreen->debugUnditherSetState(ConfMan.getBool("sci_undither"));
// Create debugger console. It requires GFX to be initialized
_console = new Console(this);
_kernel = new Kernel(_resMan, segMan);
+
_features = new GameFeatures(segMan, _kernel);
// Only SCI0, SCI01 and SCI1 EGA games used a parser
_vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan, false) : NULL;
@@ -229,6 +235,14 @@ Common::Error SciEngine::run() {
return Common::kUnknownError;
}
+ // we try to find the super class address of the game object, we can't do that earlier
+ const Object *gameObject = segMan->getObject(_gameObjectAddress);
+ if (!gameObject) {
+ warning("Could not get game object, aborting...");
+ return Common::kUnknownError;
+ }
+ _gameSuperClassAddress = gameObject->getSuperClassSelector();
+
script_adjust_opcode_formats();
// Must be called after game_init(), as they use _features
@@ -242,52 +256,93 @@ Common::Error SciEngine::run() {
debug("Emulating SCI version %s\n", getSciVersionDesc(getSciVersion()));
+ // Patch in our save/restore code, so that dialogs are replaced
+ patchGameSaveRestore(segMan);
+
if (_gameDescription->flags & ADGF_ADDENGLISH) {
// if game is multilingual
Common::Language selectedLanguage = Common::parseLanguage(ConfMan.get("language"));
if (selectedLanguage == Common::EN_ANY) {
// and english was selected as language
if (SELECTOR(printLang) != -1) // set text language to english
- writeSelectorValue(segMan, _gameObj, SELECTOR(printLang), 1);
+ writeSelectorValue(segMan, _gameObjectAddress, SELECTOR(printLang), 1);
if (SELECTOR(parseLang) != -1) // and set parser language to english as well
- writeSelectorValue(segMan, _gameObj, SELECTOR(parseLang), 1);
+ writeSelectorValue(segMan, _gameObjectAddress, SELECTOR(parseLang), 1);
}
}
// Check whether loading a savestate was requested
- int saveSlot = ConfMan.getInt("save_slot");
- if (saveSlot >= 0) {
- reg_t restoreArgv[2] = { NULL_REG, make_reg(0, saveSlot) }; // special call (argv[0] is NULL)
+ int directSaveSlotLoading = ConfMan.getInt("save_slot");
+ if (directSaveSlotLoading >= 0) {
+ // call GameObject::play (like normally)
+ initStackBaseWithSelector(SELECTOR(play));
+ // We set this, so that the game automatically quit right after init
+ _gamestate->variables[VAR_GLOBAL][4] = TRUE_REG;
+
+ _gamestate->_executionStackPosChanged = false;
+ run_vm(_gamestate);
+
+ // As soon as we get control again, actually restore the game
+ reg_t restoreArgv[2] = { NULL_REG, make_reg(0, directSaveSlotLoading) }; // special call (argv[0] is NULL)
kRestoreGame(_gamestate, 2, restoreArgv);
- // TODO: The best way to do the following would be to invoke Game::init
- // here and stop when the room is about to be changed, otherwise some
- // game initialization won't take place
+ // this indirectly calls GameObject::init, which will setup menu, text font/color codes etc.
+ // without this games would be pretty badly broken
+ }
- // Set audio language for KQ5CD (bug #3039477)
- if (g_sci->getGameId() == GID_KQ5 && Common::File::exists("AUDIO001.002")) {
- reg_t doAudioArgv[2] = { make_reg(0, 9), make_reg(0, 1) };
- kDoAudio(_gamestate, 2, doAudioArgv);
+ // Show any special warnings for buggy scripts with severe game bugs,
+ // which have been patched by Sierra
+ if (getGameId() == GID_LONGBOW) {
+ // Longbow 1.0 has a buggy script which prevents the game
+ // from progressing during the Green Man riddle sequence.
+ // A patch for this buggy script has been released by Sierra,
+ // and is necessary to complete the game without issues.
+ // The patched script is included in Longbow 1.1.
+ // Refer to bug #3036609.
+ Resource *buggyScript = _resMan->findResource(ResourceId(kResourceTypeScript, 180), 0);
+
+ if (buggyScript && (buggyScript->size == 12354 || buggyScript->size == 12362)) {
+ showScummVMDialog("A known buggy game script has been detected, which could "
+ "prevent you from progressing later on in the game, during "
+ "the sequence with the Green Man's riddles. Please, apply "
+ "the latest patch for this game by Sierra to avoid possible "
+ "problems");
}
+ }
- // Initialize the game menu, if there is one.
- // This is not done when loading, so we must do it manually.
- reg_t menuBarObj = _gamestate->_segMan->findObjectByName("MenuBar");
- if (menuBarObj.isNull())
- menuBarObj = _gamestate->_segMan->findObjectByName("TheMenuBar"); // LSL2
- if (menuBarObj.isNull())
- menuBarObj = _gamestate->_segMan->findObjectByName("menuBar"); // LSL6
- if (!menuBarObj.isNull()) {
- // Reset abortScriptProcessing before initializing the game menu, so that the
- // VM call performed by invokeSelector will actually run.
- _gamestate->abortScriptProcessing = kAbortNone;
- Object *menuBar = _gamestate->_segMan->getObject(menuBarObj);
- // Invoke the first method (init) of the menuBar object
- invokeSelector(_gamestate, menuBarObj, menuBar->getFuncSelector(0), 0, _gamestate->stack_base);
- _gamestate->abortScriptProcessing = kAbortLoadGame;
+ // Show a warning if the user has selected a General MIDI device, no GM patch exists
+ // (i.e. patch 4) and the game is one of the known 8 SCI1 games that Sierra has provided
+ // after market patches for in their "General MIDI Utility".
+ if (_soundCmd->getMusicType() == MT_GM && !ConfMan.getBool("native_mt32")) {
+ if (!_resMan->findResource(ResourceId(kResourceTypePatch, 4), 0)) {
+ switch (getGameId()) {
+ case GID_ECOQUEST:
+ case GID_HOYLE3:
+ case GID_LSL1:
+ case GID_LSL5:
+ case GID_LONGBOW:
+ case GID_SQ1:
+ case GID_SQ4:
+ case GID_FAIRYTALES:
+ showScummVMDialog("You have selected General MIDI as a sound device. Sierra "
+ "has provided after-market support for General MIDI for this "
+ "game in their \"General MIDI Utility\". Please, apply this "
+ "patch in order to enjoy MIDI music with this game. Once you "
+ "have obtained it, you can unpack all of the included *.PAT "
+ "files in your ScummVM extras folder and ScummVM will add the "
+ "appropriate patch automatically. Alternatively, you can follow "
+ "the instructions in the READ.ME file included in the patch and "
+ "rename the associated *.PAT file to 4.PAT and place it in the "
+ "game folder. Without this patch, General MIDI music for this "
+ "game will sound badly distorted.");
+ break;
+ default:
+ break;
+ }
}
}
+
runGame();
ConfMan.flushToDisk();
@@ -295,6 +350,101 @@ Common::Error SciEngine::run() {
return Common::kNoError;
}
+static byte patchGameRestoreSave[] = {
+ 0x39, 0x03, // pushi 03
+ 0x76, // push0
+ 0x38, 0xff, 0xff, // pushi -1
+ 0x76, // push0
+ 0x43, 0xff, 0x06, // call kRestoreGame/kSaveGame (will get fixed directly)
+ 0x48, // ret
+};
+
+void SciEngine::patchGameSaveRestore(SegManager *segMan) {
+ const Object *gameObject = segMan->getObject(_gameObjectAddress);
+ const uint16 gameMethodCount = gameObject->getMethodCount();
+ const Object *gameSuperObject = segMan->getObject(_gameSuperClassAddress);
+ const uint16 gameSuperMethodCount = gameSuperObject->getMethodCount();
+ reg_t methodAddress;
+ const uint16 kernelCount = _kernel->getKernelNamesSize();
+ const byte *scriptRestorePtr = NULL;
+ byte kernelIdRestore = 0;
+ const byte *scriptSavePtr = NULL;
+ byte kernelIdSave = 0;
+
+ // this feature is currently not supported on SCI32
+ if (getSciVersion() >= SCI_VERSION_2)
+ return;
+
+ switch (_gameId) {
+ case GID_MOTHERGOOSE256: // mother goose saves/restores directly and has no save/restore dialogs
+ case GID_JONES: // gets confused, when we patch us in, the game is only able to save to 1 slot, so hooking is not required
+ case GID_HOYLE1: // gets confused, although the game doesnt support saving/restoring at all
+ case GID_HOYLE2: // gets confused, see hoyle1
+ return;
+ default:
+ break;
+ }
+
+ if (ConfMan.getBool("sci_originalsaveload"))
+ return;
+
+ for (uint16 kernelNr = 0; kernelNr < kernelCount; kernelNr++) {
+ Common::String kernelName = _kernel->getKernelName(kernelNr);
+ if (kernelName == "RestoreGame")
+ kernelIdRestore = kernelNr;
+ if (kernelName == "SaveGame")
+ kernelIdSave = kernelNr;
+ }
+
+ // Search for gameobject-superclass ::restore
+ for (uint16 methodNr = 0; methodNr < gameSuperMethodCount; methodNr++) {
+ uint16 selectorId = gameSuperObject->getFuncSelector(methodNr);
+ Common::String methodName = _kernel->getSelectorName(selectorId);
+ if (methodName == "restore") {
+ methodAddress = gameSuperObject->getFunction(methodNr);
+ Script *script = segMan->getScript(methodAddress.segment);
+ scriptRestorePtr = script->getBuf(methodAddress.offset);
+ }
+ if (methodName == "save") {
+ methodAddress = gameSuperObject->getFunction(methodNr);
+ Script *script = segMan->getScript(methodAddress.segment);
+ scriptSavePtr = script->getBuf(methodAddress.offset);
+ }
+ }
+
+ // Search for gameobject ::save, if there is one patch that one instead
+ for (uint16 methodNr = 0; methodNr < gameMethodCount; methodNr++) {
+ uint16 selectorId = gameObject->getFuncSelector(methodNr);
+ Common::String methodName = _kernel->getSelectorName(selectorId);
+ if (methodName == "save") {
+ methodAddress = gameObject->getFunction(methodNr);
+ Script *script = segMan->getScript(methodAddress.segment);
+ scriptSavePtr = script->getBuf(methodAddress.offset);
+ break;
+ }
+ }
+
+ switch (_gameId) {
+ case GID_FAIRYTALES: // fairy tales automatically saves w/o dialog
+ scriptSavePtr = NULL;
+ default:
+ break;
+ }
+
+ if (scriptRestorePtr) {
+ // Now patch in our code
+ byte *patchPtr = const_cast<byte *>(scriptRestorePtr);
+ memcpy(patchPtr, patchGameRestoreSave, sizeof(patchGameRestoreSave));
+ patchPtr[8] = kernelIdRestore;
+ }
+ if (scriptSavePtr) {
+ // Now patch in our code
+ byte *patchPtr = const_cast<byte *>(scriptSavePtr);
+ memcpy(patchPtr, patchGameRestoreSave, sizeof(patchGameRestoreSave));
+ patchPtr[8] = kernelIdSave;
+ }
+}
+
bool SciEngine::initGame() {
// Script 0 needs to be allocated here before anything else!
int script0Segment = _gamestate->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK);
@@ -422,8 +572,8 @@ void SciEngine::initStackBaseWithSelector(Selector selector) {
_gamestate->stack_base[1] = NULL_REG;
// Register the first element on the execution stack
- if (!send_selector(_gamestate, _gameObj, _gameObj, _gamestate->stack_base, 2, _gamestate->stack_base)) {
- _console->printObject(_gameObj);
+ if (!send_selector(_gamestate, _gameObjectAddress, _gameObjectAddress, _gamestate->stack_base, 2, _gamestate->stack_base)) {
+ _console->printObject(_gameObjectAddress);
error("initStackBaseWithSelector: error while registering the first selector in the call stack");
}
@@ -445,6 +595,7 @@ void SciEngine::runGame() {
_gamestate->_segMan->resetSegMan();
initGame();
initStackBaseWithSelector(SELECTOR(play));
+ patchGameSaveRestore(_gamestate->_segMan);
_gamestate->gameIsRestarting = GAMEISRESTARTING_RESTART;
if (_gfxMenu)
_gfxMenu->reset();
@@ -453,6 +604,7 @@ void SciEngine::runGame() {
_gamestate->abortScriptProcessing = kAbortNone;
_gamestate->_executionStack.clear();
initStackBaseWithSelector(SELECTOR(replay));
+ patchGameSaveRestore(_gamestate->_segMan);
_gamestate->shrinkStackToBase();
_gamestate->abortScriptProcessing = kAbortNone;
} else {
@@ -521,20 +673,6 @@ Common::String SciEngine::getSavegamePattern() const {
}
Common::String SciEngine::getFilePrefix() const {
- if (_gameId == GID_QFG2) {
- // Quest for Glory 2 wants to read files from Quest for Glory 1 (EGA/VGA) to import character data
- if (_gamestate->currentRoomNumber() == 805)
- return "qfg1";
- // TODO: Include import-room for qfg1vga
- } else if (_gameId == GID_QFG3) {
- // Quest for Glory 3 wants to read files from Quest for Glory 2 to import character data
- if (_gamestate->currentRoomNumber() == 54)
- return "qfg2";
- } else if (_gameId == GID_QFG4) {
- // Quest for Glory 4 wants to read files from Quest for Glory 3 to import character data
- if (_gamestate->currentRoomNumber() == 54)
- return "qfg3";
- }
return _targetName;
}
@@ -549,6 +687,19 @@ Common::String SciEngine::unwrapFilename(const Common::String &name) const {
return name;
}
+int SciEngine::inQfGImportRoom() const {
+ if (_gameId == GID_QFG2 && _gamestate->currentRoomNumber() == 805) {
+ // QFG2 character import screen
+ return 2;
+ } else if (_gameId == GID_QFG3 && _gamestate->currentRoomNumber() == 54) {
+ // QFG3 character import screen
+ return 3;
+ } else if (_gameId == GID_QFG4 && _gamestate->currentRoomNumber() == 54) {
+ return 4;
+ }
+ return 0;
+}
+
void SciEngine::pauseEngineIntern(bool pause) {
_mixer->pauseAll(pause);
}
@@ -563,7 +714,7 @@ void SciEngine::syncSoundSettings() {
int soundVolumeMusic = (mute ? 0 : ConfMan.getInt("music_volume"));
if (_gamestate && g_sci->_soundCmd) {
- int vol = (soundVolumeMusic + 1) * SoundCommandParser::kMaxSciVolume / Audio::Mixer::kMaxMixerVolume;
+ int vol = (soundVolumeMusic + 1) * MUSIC_MASTERVOLUME_MAX / Audio::Mixer::kMaxMixerVolume;
g_sci->_soundCmd->setMasterVolume(vol);
}
}
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index 72d6e7e0cb..7239abad17 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -53,6 +53,7 @@ class Console;
class AudioPlayer;
class SoundCommandParser;
class EventManager;
+class SegManager;
class GfxAnimate;
class GfxCache;
@@ -143,8 +144,9 @@ enum SciGameId {
GID_LSL6,
GID_LSL6HIRES, // We have a separate ID for LSL6 SCI32, because it's actually a completely different game
GID_LSL7,
- GID_MOTHERGOOSE,
- GID_MOTHERGOOSEHIRES, // We have a separate ID for Mother Goose SCI32, because it's actually a completely different game
+ GID_MOTHERGOOSE, // this one is the SCI0 version
+ GID_MOTHERGOOSE256, // this one handles SCI1 and SCI1.1 variants, at least those 2 share a bit in common
+ GID_MOTHERGOOSEHIRES, // this one is the SCI2.1 hires version, completely different from the other ones
GID_MSASTROCHICKEN,
GID_PEPPER,
GID_PHANTASMAGORIA,
@@ -232,7 +234,8 @@ public:
inline EngineState *getEngineState() const { return _gamestate; }
inline Vocabulary *getVocabulary() const { return _vocabulary; }
inline EventManager *getEventManager() const { return _eventMan; }
- inline reg_t getGameObject() const { return _gameObj; }
+ inline reg_t getGameObject() const { return _gameObjectAddress; }
+ inline reg_t getGameSuperClassAddress() const { return _gameSuperClassAddress; }
Common::RandomSource &getRNG() { return _rng; }
@@ -247,11 +250,19 @@ public:
/** Remove the 'TARGET-' prefix of the given filename, if present. */
Common::String unwrapFilename(const Common::String &name) const;
+ /**
+ * Checks if we are in a QfG import screen, where special handling
+ * of file-listings is performed.
+ */
+ int inQfGImportRoom() const;
+
void sleep(uint32 msecs);
void scriptDebug();
bool checkExportBreakpoint(uint16 script, uint16 pubfunct);
- bool checkSelectorBreakpoint(reg_t send_obj, int selector);
+ bool checkSelectorBreakpoint(BreakpointType breakpointType, reg_t send_obj, int selector);
+
+ void patchGameSaveRestore(SegManager *segMan);
public:
@@ -341,7 +352,8 @@ private:
Vocabulary *_vocabulary;
int16 _vocabularyLanguage;
EventManager *_eventMan;
- reg_t _gameObj; /**< Pointer to the game object */
+ reg_t _gameObjectAddress; /**< Pointer to the game object */
+ reg_t _gameSuperClassAddress; // Address of the super class of the game object
Console *_console;
Common::RandomSource _rng;
};
diff --git a/engines/sci/sound/drivers/adlib.cpp b/engines/sci/sound/drivers/adlib.cpp
index 55c3640c9d..20bac4a2c0 100644
--- a/engines/sci/sound/drivers/adlib.cpp
+++ b/engines/sci/sound/drivers/adlib.cpp
@@ -73,6 +73,8 @@ public:
bool loadResource(const byte *data, uint size);
virtual uint32 property(int prop, uint32 param);
+ bool useRhythmChannel() const { return _rhythmKeyMap != NULL; }
+
private:
enum ChannelID {
kLeftChannel = 1,
@@ -171,12 +173,14 @@ public:
int open(ResourceManager *resMan);
void close();
- byte getPlayId();
+ byte getPlayId() const;
int getPolyphony() const { return MidiDriver_AdLib::kVoices; }
bool hasRhythmChannel() const { return false; }
void setVolume(byte volume) { static_cast<MidiDriver_AdLib *>(_driver)->setVolume(volume); }
void playSwitch(bool play) { static_cast<MidiDriver_AdLib *>(_driver)->playSwitch(play); }
void loadInstrument(int idx, byte *data);
+
+ int getLastChannel() const { return (static_cast<const MidiDriver_AdLib *>(_driver)->useRhythmChannel() ? 8 : 15); }
};
static const byte registerOffset[MidiDriver_AdLib::kVoices] = {
@@ -586,7 +590,7 @@ void MidiDriver_AdLib::voiceOn(int voice, int note, int velocity) {
}
// Set patch if different from current patch
- if ((patch != _voices[voice].patch) && _playSwitch)
+ if (patch != _voices[voice].patch)
setPatch(voice, patch);
_voices[voice].velocity = velocity;
@@ -833,7 +837,7 @@ void MidiPlayer_AdLib::close() {
}
}
-byte MidiPlayer_AdLib::getPlayId() {
+byte MidiPlayer_AdLib::getPlayId() const {
switch (_version) {
case SCI_VERSION_0_EARLY:
return 0x01;
diff --git a/engines/sci/sound/drivers/amigamac.cpp b/engines/sci/sound/drivers/amigamac.cpp
index 4fb9146b53..4b591eb609 100644
--- a/engines/sci/sound/drivers/amigamac.cpp
+++ b/engines/sci/sound/drivers/amigamac.cpp
@@ -966,7 +966,7 @@ bool MidiDriver_AmigaMac::loadInstrumentsSCI1(Common::SeekableReadStream &file)
class MidiPlayer_AmigaMac : public MidiPlayer {
public:
MidiPlayer_AmigaMac(SciVersion version) : MidiPlayer(version) { _driver = new MidiDriver_AmigaMac(g_system->getMixer()); }
- byte getPlayId();
+ byte getPlayId() const;
int getPolyphony() const { return MidiDriver_AmigaMac::kVoices; }
bool hasRhythmChannel() const { return false; }
void setVolume(byte volume) { static_cast<MidiDriver_AmigaMac *>(_driver)->setVolume(volume); }
@@ -978,7 +978,7 @@ MidiPlayer *MidiPlayer_AmigaMac_create(SciVersion version) {
return new MidiPlayer_AmigaMac(version);
}
-byte MidiPlayer_AmigaMac::getPlayId() {
+byte MidiPlayer_AmigaMac::getPlayId() const {
if (_version > SCI_VERSION_0_LATE)
return 0x06;
diff --git a/engines/sci/sound/drivers/cms.cpp b/engines/sci/sound/drivers/cms.cpp
new file mode 100644
index 0000000000..cd7b101f03
--- /dev/null
+++ b/engines/sci/sound/drivers/cms.cpp
@@ -0,0 +1,817 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "sci/sound/drivers/mididriver.h"
+
+#include "sound/softsynth/emumidi.h"
+#include "sound/softsynth/cms.h"
+#include "sound/mixer.h"
+
+#include "sci/resource.h"
+
+namespace Sci {
+
+// FIXME: We don't seem to be sending the polyphony init data, so disable this for now
+#define CMS_DISABLE_VOICE_MAPPING
+
+class MidiDriver_CMS : public MidiDriver_Emulated {
+public:
+ MidiDriver_CMS(Audio::Mixer *mixer, ResourceManager *resMan)
+ : MidiDriver_Emulated(mixer), _resMan(resMan), _cms(0), _rate(0), _playSwitch(true), _masterVolume(0) {
+ }
+
+ int open();
+ void close();
+
+ void send(uint32 b);
+ uint32 property(int prop, uint32 param);
+
+ MidiChannel *allocateChannel() { return 0; }
+ MidiChannel *getPercussionChannel() { return 0; }
+
+ bool isStereo() const { return true; }
+ int getRate() const { return _rate; }
+
+ void playSwitch(bool play);
+private:
+ void generateSamples(int16 *buffer, int len);
+
+ ResourceManager *_resMan;
+ CMSEmulator *_cms;
+
+ void writeToChip1(int address, int data);
+ void writeToChip2(int address, int data);
+
+ int32 _samplesPerCallback;
+ int32 _samplesPerCallbackRemainder;
+ int32 _samplesTillCallback;
+ int32 _samplesTillCallbackRemainder;
+
+ int _rate;
+ bool _playSwitch;
+ uint16 _masterVolume;
+
+ uint8 *_patchData;
+
+ struct Channel {
+ Channel()
+ : patch(0), volume(0), pan(0x40), hold(0), extraVoices(0),
+ pitchWheel(0x2000), pitchModifier(0), pitchAdditive(false),
+ lastVoiceUsed(0) {
+ }
+
+ uint8 patch;
+ uint8 volume;
+ uint8 pan;
+ uint8 hold;
+ uint8 extraVoices;
+ uint16 pitchWheel;
+ uint8 pitchModifier;
+ bool pitchAdditive;
+ uint8 lastVoiceUsed;
+ };
+
+ Channel _channel[16];
+
+ struct Voice {
+ Voice() : channel(0xFF), note(0xFF), sustained(0xFF), ticks(0),
+ turnOffTicks(0), patchDataPtr(0), patchDataIndex(0),
+ amplitudeTimer(0), amplitudeModifier(0), turnOff(false),
+ velocity(0) {
+ }
+
+ uint8 channel;
+ uint8 note;
+ uint8 sustained;
+ uint16 ticks;
+ uint16 turnOffTicks;
+ const uint8 *patchDataPtr;
+ uint8 patchDataIndex;
+ uint8 amplitudeTimer;
+ uint8 amplitudeModifier;
+ bool turnOff;
+ uint8 velocity;
+ };
+
+ Voice _voice[12];
+
+ void voiceOn(int voice, int note, int velocity);
+ void voiceOff(int voice);
+
+ void noteSend(int voice);
+
+ void noteOn(int channel, int note, int velocity);
+ void noteOff(int channel, int note);
+ void controlChange(int channel, int control, int value);
+ void pitchWheel(int channel, int value);
+
+ void voiceMapping(int channel, int value);
+ void bindVoices(int channel, int voices);
+ void unbindVoices(int channel, int voices);
+ void donateVoices();
+ int findVoice(int channel);
+
+ int findVoiceBasic(int channel);
+
+ void updateVoiceAmplitude(int voice);
+ void setupVoiceAmplitude(int voice);
+
+ uint8 _octaveRegs[2][3];
+
+ static const int _timerFreq = 60;
+
+ static const int _frequencyTable[];
+ static const int _velocityTable[];
+};
+
+const int MidiDriver_CMS::_frequencyTable[] = {
+ 3, 10, 17, 24,
+ 31, 38, 46, 51,
+ 58, 64, 71, 77,
+ 83, 89, 95, 101,
+ 107, 113, 119, 124,
+ 130, 135, 141, 146,
+ 151, 156, 162, 167,
+ 172, 177, 182, 186,
+ 191, 196, 200, 205,
+ 209, 213, 217, 222,
+ 226, 230, 234, 238,
+ 242, 246, 250, 253
+};
+
+const int MidiDriver_CMS::_velocityTable[] = {
+ 1, 3, 6, 8, 9, 10, 11, 12,
+ 12, 13, 13, 14, 14, 14, 15, 15,
+ 0, 1, 2, 2, 3, 4, 4, 5,
+ 6, 6, 7, 8, 8, 9, 10, 10
+};
+
+int MidiDriver_CMS::open() {
+ if (_cms)
+ return MERR_ALREADY_OPEN;
+
+ assert(_resMan);
+ Resource *res = _resMan->findResource(ResourceId(kResourceTypePatch, 101), 0);
+ if (!res)
+ return -1;
+
+ _patchData = new uint8[res->size];
+ memcpy(_patchData, res->data, res->size);
+
+ for (uint i = 0; i < ARRAYSIZE(_channel); ++i)
+ _channel[i] = Channel();
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i)
+ _voice[i] = Voice();
+
+ _rate = _mixer->getOutputRate();
+ _cms = new CMSEmulator(_rate);
+ assert(_cms);
+ _playSwitch = true;
+ _masterVolume = 0;
+
+ for (int i = 0; i < 31; ++i) {
+ writeToChip1(i, 0);
+ writeToChip2(i, 0);
+ }
+
+ writeToChip1(0x14, 0xFF);
+ writeToChip2(0x14, 0xFF);
+
+ writeToChip1(0x1C, 1);
+ writeToChip2(0x1C, 1);
+
+ _samplesPerCallback = getRate() / _timerFreq;
+ _samplesPerCallbackRemainder = getRate() % _timerFreq;
+ _samplesTillCallback = 0;
+ _samplesTillCallbackRemainder = 0;
+
+ int retVal = MidiDriver_Emulated::open();
+ if (retVal != 0)
+ return retVal;
+
+ _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ return 0;
+}
+
+void MidiDriver_CMS::close() {
+ _mixer->stopHandle(_mixerSoundHandle);
+
+ delete[] _patchData;
+ delete _cms;
+ _cms = 0;
+}
+
+void MidiDriver_CMS::send(uint32 b) {
+ const uint8 command = b & 0xf0;
+ const uint8 channel = b & 0xf;
+ const uint8 op1 = (b >> 8) & 0xff;
+ const uint8 op2 = (b >> 16) & 0xff;
+
+ switch (command) {
+ case 0x80:
+ noteOff(channel, op1);
+ break;
+
+ case 0x90:
+ noteOn(channel, op1, op2);
+ break;
+
+ case 0xB0:
+ controlChange(channel, op1, op2);
+ break;
+
+ case 0xC0:
+ _channel[channel].patch = op1;
+ break;
+
+ case 0xE0:
+ pitchWheel(channel, (op1 & 0x7f) | ((op2 & 0x7f) << 7));
+ break;
+
+ default:
+ break;
+ }
+}
+
+uint32 MidiDriver_CMS::property(int prop, uint32 param) {
+ switch (prop) {
+ case MIDI_PROP_MASTER_VOLUME:
+ if (param != 0xffff)
+ _masterVolume = param;
+ return _masterVolume;
+
+ default:
+ return MidiDriver_Emulated::property(prop, param);
+ }
+}
+
+void MidiDriver_CMS::playSwitch(bool play) {
+ _playSwitch = play;
+}
+
+void MidiDriver_CMS::writeToChip1(int address, int data) {
+ _cms->portWrite(0x221, address);
+ _cms->portWrite(0x220, data);
+
+ if (address >= 16 && address <= 18)
+ _octaveRegs[0][address - 16] = data;
+}
+
+void MidiDriver_CMS::writeToChip2(int address, int data) {
+ _cms->portWrite(0x223, address);
+ _cms->portWrite(0x222, data);
+
+ if (address >= 16 && address <= 18)
+ _octaveRegs[1][address - 16] = data;
+}
+
+void MidiDriver_CMS::voiceOn(int voiceNr, int note, int velocity) {
+ Voice &voice = _voice[voiceNr];
+ voice.note = note;
+ voice.turnOff = false;
+ voice.patchDataIndex = 0;
+ voice.amplitudeTimer = 0;
+ voice.ticks = 0;
+ voice.turnOffTicks = 0;
+ voice.patchDataPtr = _patchData + READ_LE_UINT16(&_patchData[_channel[voice.channel].patch * 2]);
+ if (velocity)
+ velocity = _velocityTable[(velocity >> 3)];
+ voice.velocity = velocity;
+ noteSend(voiceNr);
+}
+
+void MidiDriver_CMS::voiceOff(int voiceNr) {
+ Voice &voice = _voice[voiceNr];
+ voice.velocity = 0;
+ voice.note = 0xFF;
+ voice.sustained = 0;
+ voice.turnOff = false;
+ voice.patchDataIndex = 0;
+ voice.amplitudeTimer = 0;
+ voice.amplitudeModifier = 0;
+ voice.ticks = 0;
+ voice.turnOffTicks = 0;
+
+ setupVoiceAmplitude(voiceNr);
+}
+
+void MidiDriver_CMS::noteSend(int voiceNr) {
+ Voice &voice = _voice[voiceNr];
+
+ int frequency = (CLIP<int>(voice.note, 21, 116) - 21) * 4;
+ if (_channel[voice.channel].pitchModifier) {
+ int modifier = _channel[voice.channel].pitchModifier;
+
+ if (!_channel[voice.channel].pitchAdditive) {
+ if (frequency > modifier)
+ frequency -= modifier;
+ else
+ frequency = 0;
+ } else {
+ int tempFrequency = 384 - frequency;
+ if (modifier < tempFrequency)
+ frequency += modifier;
+ else
+ frequency = 383;
+ }
+ }
+
+ int chipNumber = 0;
+ if (voiceNr >= 6) {
+ voiceNr -= 6;
+ chipNumber = 1;
+ }
+
+ int octave = 0;
+ while (frequency >= 48) {
+ frequency -= 48;
+ ++octave;
+ }
+
+ frequency = _frequencyTable[frequency];
+
+ if (chipNumber == 1)
+ writeToChip2(8 + voiceNr, frequency);
+ else
+ writeToChip1(8 + voiceNr, frequency);
+
+ uint8 octaveData = _octaveRegs[chipNumber][voiceNr >> 1];
+
+ if (voiceNr & 1) {
+ octaveData &= 0x0F;
+ octaveData |= (octave << 4);
+ } else {
+ octaveData &= 0xF0;
+ octaveData |= octave;
+ }
+
+ if (chipNumber == 1)
+ writeToChip2(0x10 + (voiceNr >> 1), octaveData);
+ else
+ writeToChip1(0x10 + (voiceNr >> 1), octaveData);
+}
+
+void MidiDriver_CMS::noteOn(int channel, int note, int velocity) {
+ if (note < 21 || note > 116)
+ return;
+
+ if (velocity == 0) {
+ noteOff(channel, note);
+ return;
+ }
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channel && _voice[i].note == note) {
+ _voice[i].sustained = 0;
+ voiceOff(i);
+ voiceOn(i, note, velocity);
+ return;
+ }
+ }
+
+#ifdef CMS_DISABLE_VOICE_MAPPING
+ int voice = findVoiceBasic(channel);
+#else
+ int voice = findVoice(channel);
+#endif
+ if (voice != -1)
+ voiceOn(voice, note, velocity);
+}
+
+int MidiDriver_CMS::findVoiceBasic(int channel) {
+ int voice = -1;
+ int oldestVoice = -1;
+ int oldestAge = -1;
+
+ // Try to find a voice assigned to this channel that is free (round-robin)
+ for (int i = 0; i < ARRAYSIZE(_voice); i++) {
+ int v = (_channel[channel].lastVoiceUsed + i + 1) % ARRAYSIZE(_voice);
+
+ if (_voice[v].note == 0xFF) {
+ voice = v;
+ break;
+ }
+
+ // We also keep track of the oldest note in case the search fails
+ if (_voice[v].ticks > oldestAge) {
+ oldestAge = _voice[v].ticks;
+ oldestVoice = v;
+ }
+ }
+
+ if (voice == -1) {
+ if (oldestVoice != -1) {
+ voiceOff(oldestVoice);
+ voice = oldestVoice;
+ } else {
+ return -1;
+ }
+ }
+
+ _voice[voice].channel = channel;
+ _channel[channel].lastVoiceUsed = voice;
+ return voice;
+}
+
+void MidiDriver_CMS::noteOff(int channel, int note) {
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channel && _voice[i].note == note) {
+ if (_channel[channel].hold != 0)
+ _voice[i].sustained = true;
+ else
+ _voice[i].turnOff = true;
+ }
+ }
+}
+
+void MidiDriver_CMS::controlChange(int channel, int control, int value) {
+ switch (control) {
+ case 7:
+ if (value) {
+ value >>= 3;
+ if (!value)
+ ++value;
+ }
+
+ _channel[channel].volume = value;
+ break;
+
+ case 10:
+ _channel[channel].pan = value;
+ break;
+
+ case 64:
+ _channel[channel].hold = value;
+
+ if (!value) {
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channel && _voice[i].sustained) {
+ _voice[i].sustained = 0;
+ _voice[i].turnOff = true;
+ }
+ }
+ }
+ break;
+
+ case 75:
+#ifndef CMS_DISABLE_VOICE_MAPPING
+ voiceMapping(channel, value);
+#endif
+ break;
+
+ case 123:
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channel && _voice[i].note != 0xFF)
+ voiceOff(i);
+ }
+ break;
+
+ default:
+ return;
+ }
+}
+
+void MidiDriver_CMS::pitchWheel(int channelNr, int value) {
+ Channel &channel = _channel[channelNr];
+ channel.pitchWheel = value;
+ channel.pitchAdditive = false;
+ channel.pitchModifier = 0;
+
+ if (value < 0x2000) {
+ channel.pitchModifier = (0x2000 - value) / 170;
+ } else if (value > 0x2000) {
+ channel.pitchModifier = (value - 0x2000) / 170;
+ channel.pitchAdditive = true;
+ }
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channelNr && _voice[i].note != 0xFF)
+ noteSend(i);
+ }
+}
+
+void MidiDriver_CMS::voiceMapping(int channelNr, int value) {
+ int curVoices = 0;
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channelNr)
+ ++curVoices;
+ }
+
+ curVoices += _channel[channelNr].extraVoices;
+
+ if (curVoices == value) {
+ return;
+ } else if (curVoices < value) {
+ bindVoices(channelNr, value - curVoices);
+ } else {
+ unbindVoices(channelNr, curVoices - value);
+ donateVoices();
+ }
+}
+
+void MidiDriver_CMS::bindVoices(int channel, int voices) {
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == 0xFF)
+ continue;
+
+ Voice &voice = _voice[i];
+ voice.channel = channel;
+
+ if (voice.note != 0xFF)
+ voiceOff(i);
+
+ --voices;
+ if (voices == 0)
+ break;
+ }
+
+ _channel[channel].extraVoices += voices;
+
+ // The original called "PatchChange" here, since this just
+ // copies the value of _channel[channel].patch to itself
+ // it is left out here though.
+}
+
+void MidiDriver_CMS::unbindVoices(int channelNr, int voices) {
+ Channel &channel = _channel[channelNr];
+
+ if (channel.extraVoices >= voices) {
+ channel.extraVoices -= voices;
+ } else {
+ voices -= channel.extraVoices;
+ channel.extraVoices = 0;
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == channelNr
+ && _voice[i].note == 0xFF) {
+ --voices;
+ if (voices == 0)
+ return;
+ }
+ }
+
+ do {
+ uint16 voiceTime = 0;
+ uint voiceNr = 0;
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel != channelNr)
+ continue;
+
+ uint16 curTime = _voice[i].turnOffTicks;
+ if (curTime)
+ curTime += 0x8000;
+ else
+ curTime = _voice[i].ticks;
+
+ if (curTime >= voiceTime) {
+ voiceNr = i;
+ voiceTime = curTime;
+ }
+ }
+
+ _voice[voiceNr].sustained = 0;
+ voiceOff(voiceNr);
+ _voice[voiceNr].channel = 0xFF;
+ --voices;
+ } while (voices != 0);
+ }
+}
+
+void MidiDriver_CMS::donateVoices() {
+ int freeVoices = 0;
+
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].channel == 0xFF)
+ ++freeVoices;
+ }
+
+ if (!freeVoices)
+ return;
+
+ for (uint i = 0; i < ARRAYSIZE(_channel); ++i) {
+ Channel &channel = _channel[i];
+
+ if (!channel.extraVoices) {
+ continue;
+ } else if (channel.extraVoices < freeVoices) {
+ freeVoices -= channel.extraVoices;
+ channel.extraVoices = 0;
+ bindVoices(i, channel.extraVoices);
+ } else {
+ channel.extraVoices -= freeVoices;
+ bindVoices(i, freeVoices);
+ return;
+ }
+ }
+}
+
+int MidiDriver_CMS::findVoice(int channelNr) {
+ Channel &channel = _channel[channelNr];
+ int voiceNr = channel.lastVoiceUsed;
+
+ int newVoice = 0;
+ uint16 newVoiceTime = 0;
+
+ bool loopDone = false;
+ do {
+ ++voiceNr;
+
+ if (voiceNr == 12)
+ voiceNr = 0;
+
+ Voice &voice = _voice[voiceNr];
+
+ if (voiceNr == channel.lastVoiceUsed)
+ loopDone = true;
+
+ if (voice.channel == channelNr) {
+ if (voice.note == 0xFF) {
+ channel.lastVoiceUsed = voiceNr;
+ return voiceNr;
+ }
+
+ uint16 curTime = voice.turnOffTicks;
+ if (curTime)
+ curTime += 0x8000;
+ else
+ curTime = voice.ticks;
+
+ if (curTime >= newVoiceTime) {
+ newVoice = voiceNr;
+ newVoiceTime = curTime;
+ }
+ }
+ } while (!loopDone);
+
+ if (newVoiceTime > 0) {
+ voiceNr = newVoice;
+ _voice[voiceNr].sustained = 0;
+ voiceOff(voiceNr);
+ channel.lastVoiceUsed = voiceNr;
+ return voiceNr;
+ } else {
+ return -1;
+ }
+}
+
+void MidiDriver_CMS::updateVoiceAmplitude(int voiceNr) {
+ Voice &voice = _voice[voiceNr];
+
+ if (voice.amplitudeTimer != 0 && voice.amplitudeTimer != 254) {
+ --voice.amplitudeTimer;
+ return;
+ } else if (voice.amplitudeTimer == 254) {
+ if (!voice.turnOff)
+ return;
+
+ voice.amplitudeTimer = 0;
+ }
+
+ int nextDataIndex = voice.patchDataIndex;
+ uint8 timerData = 0;
+ uint8 amplitudeData = voice.patchDataPtr[nextDataIndex];
+
+ if (amplitudeData == 255) {
+ timerData = amplitudeData = 0;
+ voiceOff(voiceNr);
+ } else {
+ timerData = voice.patchDataPtr[nextDataIndex + 1];
+ nextDataIndex += 2;
+ }
+
+ voice.patchDataIndex = nextDataIndex;
+ voice.amplitudeTimer = timerData;
+ voice.amplitudeModifier = amplitudeData;
+}
+
+void MidiDriver_CMS::setupVoiceAmplitude(int voiceNr) {
+ Voice &voice = _voice[voiceNr];
+ uint amplitude = 0;
+
+ if (_channel[voice.channel].volume && voice.velocity
+ && voice.amplitudeModifier && _masterVolume) {
+ amplitude = _channel[voice.channel].volume * voice.velocity;
+ amplitude /= 0x0F;
+ amplitude *= voice.amplitudeModifier;
+ amplitude /= 0x0F;
+ amplitude *= _masterVolume;
+ amplitude /= 0x0F;
+
+ if (!amplitude)
+ ++amplitude;
+ }
+
+ uint8 amplitudeData = 0;
+ int pan = _channel[voice.channel].pan >> 2;
+ if (pan >= 16) {
+ amplitudeData = (amplitude * (31 - pan) / 0x0F) & 0x0F;
+ amplitudeData |= (amplitude << 4);
+ } else {
+ amplitudeData = (amplitude * pan / 0x0F) & 0x0F;
+ amplitudeData <<= 4;
+ amplitudeData |= amplitude;
+ }
+
+ if (!_playSwitch)
+ amplitudeData = 0;
+
+ if (voiceNr >= 6)
+ writeToChip2(voiceNr - 6, amplitudeData);
+ else
+ writeToChip1(voiceNr, amplitudeData);
+}
+
+void MidiDriver_CMS::generateSamples(int16 *buffer, int len) {
+ while (len) {
+ if (!_samplesTillCallback) {
+ for (uint i = 0; i < ARRAYSIZE(_voice); ++i) {
+ if (_voice[i].note == 0xFF)
+ continue;
+
+ ++_voice[i].ticks;
+ if (_voice[i].turnOff)
+ ++_voice[i].turnOffTicks;
+
+ updateVoiceAmplitude(i);
+ setupVoiceAmplitude(i);
+ }
+
+ _samplesTillCallback = _samplesPerCallback;
+ _samplesTillCallbackRemainder += _samplesPerCallbackRemainder;
+ if (_samplesTillCallbackRemainder >= _timerFreq) {
+ _samplesTillCallback++;
+ _samplesTillCallbackRemainder -= _timerFreq;
+ }
+ }
+
+ int32 render = MIN<int32>(len, _samplesTillCallback);
+ len -= render;
+ _samplesTillCallback -= render;
+ _cms->readBuffer(buffer, render);
+ buffer += render * 2;
+ }
+}
+
+
+class MidiPlayer_CMS : public MidiPlayer {
+public:
+ MidiPlayer_CMS(SciVersion version) : MidiPlayer(version) {
+ }
+
+ int open(ResourceManager *resMan) {
+ if (_driver)
+ return MERR_ALREADY_OPEN;
+
+ _driver = new MidiDriver_CMS(g_system->getMixer(), resMan);
+ int driverRetVal = _driver->open();
+ if (driverRetVal != 0)
+ return driverRetVal;
+
+ return 0;
+ }
+
+ void close() {
+ _driver->setTimerCallback(0, 0);
+ _driver->close();
+ delete _driver;
+ _driver = 0;
+ }
+
+ bool hasRhythmChannel() const { return false; }
+ byte getPlayId() const { return 9; }
+ int getPolyphony() const { return 12; }
+
+ void playSwitch(bool play) { static_cast<MidiDriver_CMS *>(_driver)->playSwitch(play); }
+};
+
+MidiPlayer *MidiPlayer_CMS_create(SciVersion version) {
+ return new MidiPlayer_CMS(version);
+}
+
+} // End of namespace SCI
+
diff --git a/engines/sci/sound/drivers/fb01.cpp b/engines/sci/sound/drivers/fb01.cpp
index ab9b2e3df5..7560c62f4f 100644
--- a/engines/sci/sound/drivers/fb01.cpp
+++ b/engines/sci/sound/drivers/fb01.cpp
@@ -59,7 +59,7 @@ public:
void send(uint32 b);
void sysEx(const byte *msg, uint16 length);
bool hasRhythmChannel() const { return false; }
- byte getPlayId();
+ byte getPlayId() const;
int getPolyphony() const { return kVoices; } // 9 in SCI1?
void setVolume(byte volume);
int getVolume();
@@ -633,7 +633,7 @@ void MidiPlayer_Fb01::sysEx(const byte *msg, uint16 length) {
g_system->updateScreen();
}
-byte MidiPlayer_Fb01::getPlayId() {
+byte MidiPlayer_Fb01::getPlayId() const {
switch (_version) {
case SCI_VERSION_0_EARLY:
return 0x01;
diff --git a/engines/sci/sound/drivers/map-mt32-to-gm.h b/engines/sci/sound/drivers/map-mt32-to-gm.h
index a552ef0608..05d1aeba24 100644
--- a/engines/sci/sound/drivers/map-mt32-to-gm.h
+++ b/engines/sci/sound/drivers/map-mt32-to-gm.h
@@ -421,131 +421,131 @@ static const Mt32ToGmMap Mt32MemoryTimbreMaps[] = {
{"Acou SD ", MIDI_MAPPED_TO_RHYTHM, 38}, /* R (PQ2) */
{"AcouPnoKA ", 0, MIDI_UNMAPPED}, /* ++ (KQ1) */
{"BASS ", 32, MIDI_UNMAPPED}, /* + (LSL3) */
- {"BASSOONPCM", 70, MIDI_UNMAPPED}, /* + (CB) */
+ {"BASSOONPCM", 70, MIDI_UNMAPPED}, /* + (LB1) */
{"BEACH WAVE", 122, MIDI_UNMAPPED}, /* + (LSL3) */
{"BagPipes ", 109, MIDI_UNMAPPED},
- {"BassPizzMS", 45, MIDI_UNMAPPED}, /* ++ (HQ) */
+ {"BassPizzMS", 45, MIDI_UNMAPPED}, /* ++ (QFG1) */
{"BassoonKA ", 70, MIDI_UNMAPPED}, /* ++ (KQ1) */
- {"Bell MS", 112, MIDI_UNMAPPED}, /* ++ (iceMan) */
- {"Bells MS", 112, MIDI_UNMAPPED}, /* + (HQ) */
- {"Big Bell ", 14, MIDI_UNMAPPED}, /* + (CB) */
+ {"Bell MS", 112, MIDI_UNMAPPED}, /* ++ (Iceman) */
+ {"Bells MS", 112, MIDI_UNMAPPED}, /* + (QFG1) */
+ {"Big Bell ", 14, MIDI_UNMAPPED}, /* + (LB1) */
{"Bird Tweet", 123, MIDI_UNMAPPED},
- {"BrsSect MS", 61, MIDI_UNMAPPED}, /* +++ (iceMan) */
+ {"BrsSect MS", 61, MIDI_UNMAPPED}, /* +++ (Iceman) */
{"CLAPPING ", 126, MIDI_UNMAPPED}, /* ++ (LSL3) */
- {"Cabasa ", MIDI_MAPPED_TO_RHYTHM, 69}, /* R (HBoG) */
- {"Calliope ", 82, MIDI_UNMAPPED}, /* +++ (HQ) */
- {"CelticHarp", 46, MIDI_UNMAPPED}, /* ++ (CoC) */
- {"Chicago MS", 1, MIDI_UNMAPPED}, /* ++ (iceMan) */
+ {"Cabasa ", MIDI_MAPPED_TO_RHYTHM, 69}, /* R (Hoyle) */
+ {"Calliope ", 82, MIDI_UNMAPPED}, /* +++ (QFG1) */
+ {"CelticHarp", 46, MIDI_UNMAPPED}, /* ++ (Camelot) */
+ {"Chicago MS", 1, MIDI_UNMAPPED}, /* ++ (Iceman) */
{"Chop ", 117, MIDI_UNMAPPED},
- {"Chorale MS", 52, MIDI_UNMAPPED}, /* + (CoC) */
+ {"Chorale MS", 52, MIDI_UNMAPPED}, /* + (Camelot) */
{"ClarinetMS", 71, MIDI_UNMAPPED},
{"Claves ", MIDI_MAPPED_TO_RHYTHM, 75}, /* R (PQ2) */
- {"Claw MS", 118, MIDI_UNMAPPED}, /* + (HQ) */
- {"ClockBell ", 14, MIDI_UNMAPPED}, /* + (CB) */
+ {"Claw MS", 118, MIDI_UNMAPPED}, /* + (QFG1) */
+ {"ClockBell ", 14, MIDI_UNMAPPED}, /* + (LB1) */
{"ConcertCym", MIDI_MAPPED_TO_RHYTHM, 55}, /* R ? (KQ1) */
- {"Conga MS", MIDI_MAPPED_TO_RHYTHM, 64}, /* R (HQ) */
+ {"Conga MS", MIDI_MAPPED_TO_RHYTHM, 64}, /* R (QFG1) */
{"CoolPhone ", 124, MIDI_UNMAPPED}, /* ++ (LSL3) */
- {"CracklesMS", 115, MIDI_UNMAPPED}, /* ? (CoC, HQ) */
+ {"CracklesMS", 115, MIDI_UNMAPPED}, /* ? (Camelot, QFG1) */
{"CreakyD MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ??? (KQ1) */
- {"Cricket ", 120, MIDI_UNMAPPED}, /* ? (CB) */
- {"CrshCymbMS", MIDI_MAPPED_TO_RHYTHM, 57}, /* R +++ (iceMan) */
- {"CstlGateMS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (HQ) */
- {"CymSwellMS", MIDI_MAPPED_TO_RHYTHM, 55}, /* R ? (CoC, HQ) */
+ {"Cricket ", 120, MIDI_UNMAPPED}, /* ? (LB1) */
+ {"CrshCymbMS", MIDI_MAPPED_TO_RHYTHM, 57}, /* R +++ (Iceman) */
+ {"CstlGateMS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (QFG1) */
+ {"CymSwellMS", MIDI_MAPPED_TO_RHYTHM, 55}, /* R ? (Camelot, QFG1) */
{"CymbRollKA", MIDI_MAPPED_TO_RHYTHM, 57}, /* R ? (KQ1) */
{"Cymbal Lo ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* R ? (LSL3) */
- {"card ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (HBoG) */
- {"DirtGtr MS", 30, MIDI_UNMAPPED}, /* + (iceMan) */
- {"DirtGtr2MS", 29, MIDI_UNMAPPED}, /* + (iceMan) */
+ {"card ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (Hoyle) */
+ {"DirtGtr MS", 30, MIDI_UNMAPPED}, /* + (Iceman) */
+ {"DirtGtr2MS", 29, MIDI_UNMAPPED}, /* + (Iceman) */
{"E Bass MS", 33, MIDI_UNMAPPED}, /* + (SQ3) */
{"ElecBassMS", 33, MIDI_UNMAPPED},
- {"ElecGtr MS", 27, MIDI_UNMAPPED}, /* ++ (iceMan) */
+ {"ElecGtr MS", 27, MIDI_UNMAPPED}, /* ++ (Iceman) */
{"EnglHornMS", 69, MIDI_UNMAPPED},
{"FantasiaKA", 88, MIDI_UNMAPPED},
{"Fantasy ", 99, MIDI_UNMAPPED}, /* + (PQ2) */
- {"Fantasy2MS", 99, MIDI_UNMAPPED}, /* ++ (CoC, HQ) */
- {"Filter MS", 95, MIDI_UNMAPPED}, /* +++ (iceMan) */
- {"Filter2 MS", 95, MIDI_UNMAPPED}, /* ++ (iceMan) */
- {"Flame2 MS", 121, MIDI_UNMAPPED}, /* ? (HQ) */
- {"Flames MS", 121, MIDI_UNMAPPED}, /* ? (HQ) */
- {"Flute MS", 73, MIDI_UNMAPPED}, /* +++ (HQ) */
+ {"Fantasy2MS", 99, MIDI_UNMAPPED}, /* ++ (Camelot, QFG1) */
+ {"Filter MS", 95, MIDI_UNMAPPED}, /* +++ (Iceman) */
+ {"Filter2 MS", 95, MIDI_UNMAPPED}, /* ++ (Iceman) */
+ {"Flame2 MS", 121, MIDI_UNMAPPED}, /* ? (QFG1) */
+ {"Flames MS", 121, MIDI_UNMAPPED}, /* ? (QFG1) */
+ {"Flute MS", 73, MIDI_UNMAPPED}, /* +++ (QFG1) */
{"FogHorn MS", 58, MIDI_UNMAPPED},
- {"FrHorn1 MS", 60, MIDI_UNMAPPED}, /* +++ (HQ) */
- {"FunnyTrmp ", 56, MIDI_UNMAPPED}, /* ++ (CB) */
+ {"FrHorn1 MS", 60, MIDI_UNMAPPED}, /* +++ (QFG1) */
+ {"FunnyTrmp ", 56, MIDI_UNMAPPED}, /* ++ (LB1) */
{"GameSnd MS", 80, MIDI_UNMAPPED},
- {"Glock MS", 9, MIDI_UNMAPPED}, /* +++ (HQ) */
- {"Gunshot ", 127, MIDI_UNMAPPED}, /* +++ (CB) */
- {"Hammer MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (HQ) */
- {"Harmonica2", 22, MIDI_UNMAPPED}, /* +++ (CB) */
- {"Harpsi 1 ", 6, MIDI_UNMAPPED}, /* + (HBoG) */
- {"Harpsi 2 ", 6, MIDI_UNMAPPED}, /* +++ (CB) */
- {"Heart MS", 116, MIDI_UNMAPPED}, /* ? (iceMan) */
- {"Horse1 MS", 115, MIDI_UNMAPPED}, /* ? (CoC, HQ) */
- {"Horse2 MS", 115, MIDI_UNMAPPED}, /* ? (CoC, HQ) */
- {"InHale MS", 121, MIDI_UNMAPPED}, /* ++ (iceMan) */
+ {"Glock MS", 9, MIDI_UNMAPPED}, /* +++ (QFG1) */
+ {"Gunshot ", 127, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"Hammer MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (QFG1) */
+ {"Harmonica2", 22, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"Harpsi 1 ", 6, MIDI_UNMAPPED}, /* + (Hoyle) */
+ {"Harpsi 2 ", 6, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"Heart MS", 116, MIDI_UNMAPPED}, /* ? (Iceman) */
+ {"Horse1 MS", 115, MIDI_UNMAPPED}, /* ? (Camelot, QFG1) */
+ {"Horse2 MS", 115, MIDI_UNMAPPED}, /* ? (Camelot, QFG1) */
+ {"InHale MS", 121, MIDI_UNMAPPED}, /* ++ (Iceman) */
{"KNIFE ", 120, MIDI_UNMAPPED}, /* ? (LSL3) */
- {"KenBanjo ", 105, MIDI_UNMAPPED}, /* +++ (CB) */
- {"Kiss MS", 25, MIDI_UNMAPPED}, /* ++ (HQ) */
+ {"KenBanjo ", 105, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"Kiss MS", 25, MIDI_UNMAPPED}, /* ++ (QFG1) */
{"KongHit ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ??? (KQ1) */
{"Koto ", 107, MIDI_UNMAPPED}, /* +++ (PQ2) */
- {"Laser MS", 81, MIDI_UNMAPPED}, /* ?? (HQ) */
- {"Meeps MS", 62, MIDI_UNMAPPED}, /* ? (HQ) */
- {"MTrak MS", 62, MIDI_UNMAPPED}, /* ?? (iceMan) */
- {"MachGun MS", 127, MIDI_UNMAPPED}, /* ? (iceMan) */
+ {"Laser MS", 81, MIDI_UNMAPPED}, /* ?? (QFG1) */
+ {"Meeps MS", 62, MIDI_UNMAPPED}, /* ? (QFG1) */
+ {"MTrak MS", 62, MIDI_UNMAPPED}, /* ?? (Iceman) */
+ {"MachGun MS", 127, MIDI_UNMAPPED}, /* ? (Iceman) */
{"OCEANSOUND", 122, MIDI_UNMAPPED}, /* + (LSL3) */
{"Oboe 2001 ", 68, MIDI_UNMAPPED}, /* + (PQ2) */
- {"Ocean MS", 122, MIDI_UNMAPPED}, /* + (iceMan) */
- {"PPG 2.3 MS", 75, MIDI_UNMAPPED}, /* ? (iceMan) */
- {"PianoCrank", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (CB) */
- {"PicSnareMS", MIDI_MAPPED_TO_RHYTHM, 40}, /* R ? (iceMan) */
+ {"Ocean MS", 122, MIDI_UNMAPPED}, /* + (Iceman) */
+ {"PPG 2.3 MS", 75, MIDI_UNMAPPED}, /* ? (Iceman) */
+ {"PianoCrank", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (LB1) */
+ {"PicSnareMS", MIDI_MAPPED_TO_RHYTHM, 40}, /* R ? (Iceman) */
{"PiccoloKA ", 72, MIDI_UNMAPPED}, /* +++ (KQ1) */
{"PinkBassMS", 39, MIDI_UNMAPPED},
- {"Pizz2 ", 45, MIDI_UNMAPPED}, /* ++ (CB) */
+ {"Pizz2 ", 45, MIDI_UNMAPPED}, /* ++ (LB1) */
{"Portcullis", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (KQ1) */
- {"Raspbry MS", 81, MIDI_UNMAPPED}, /* ? (HQ) */
- {"RatSqueek ", 72, MIDI_UNMAPPED}, /* ? (CB, CoC) */
- {"Record78 ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* +++ (CB) */
- {"RecorderMS", 74, MIDI_UNMAPPED}, /* +++ (CoC) */
- {"Red Baron ", 125, MIDI_UNMAPPED}, /* ? (CB) */
- {"ReedPipMS ", 20, MIDI_UNMAPPED}, /* +++ (Coc) */
+ {"Raspbry MS", 81, MIDI_UNMAPPED}, /* ? (QFG1) */
+ {"RatSqueek ", 72, MIDI_UNMAPPED}, /* ? (LauraBow1, Camelot) */
+ {"Record78 ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"RecorderMS", 74, MIDI_UNMAPPED}, /* +++ (Camelot) */
+ {"Red Baron ", 125, MIDI_UNMAPPED}, /* ? (LB1) */
+ {"ReedPipMS ", 20, MIDI_UNMAPPED}, /* +++ (Camelot) */
{"RevCymb MS", 119, MIDI_UNMAPPED},
- {"RifleShot ", 127, MIDI_UNMAPPED}, /* + (CB) */
+ {"RifleShot ", 127, MIDI_UNMAPPED}, /* + (LB1) */
{"RimShot MS", MIDI_MAPPED_TO_RHYTHM, 37}, /* R */
{"SHOWER ", 52, MIDI_UNMAPPED}, /* ? (LSL3) */
{"SQ Bass MS", 32, MIDI_UNMAPPED}, /* + (SQ3) */
- {"ShakuVibMS", 79, MIDI_UNMAPPED}, /* + (iceMan) */
- {"SlapBassMS", 36, MIDI_UNMAPPED}, /* +++ (iceMan) */
- {"Snare MS", MIDI_MAPPED_TO_RHYTHM, 38}, /* R (HQ) */
- {"Some Birds", 123, MIDI_UNMAPPED}, /* + (CB) */
- {"Sonar MS", 78, MIDI_UNMAPPED}, /* ? (iceMan) */
- {"Soundtrk2 ", 97, MIDI_UNMAPPED}, /* +++ (CB) */
- {"Soundtrack", 97, MIDI_UNMAPPED}, /* ++ (CoC) */
+ {"ShakuVibMS", 79, MIDI_UNMAPPED}, /* + (Iceman) */
+ {"SlapBassMS", 36, MIDI_UNMAPPED}, /* +++ (Iceman) */
+ {"Snare MS", MIDI_MAPPED_TO_RHYTHM, 38}, /* R (QFG1) */
+ {"Some Birds", 123, MIDI_UNMAPPED}, /* + (LB1) */
+ {"Sonar MS", 78, MIDI_UNMAPPED}, /* ? (Iceman) */
+ {"Soundtrk2 ", 97, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"Soundtrack", 97, MIDI_UNMAPPED}, /* ++ (Camelot) */
{"SqurWaveMS", 80, MIDI_UNMAPPED},
- {"StabBassMS", 34, MIDI_UNMAPPED}, /* + (iceMan) */
- {"SteelDrmMS", 114, MIDI_UNMAPPED}, /* +++ (iceMan) */
- {"StrSect1MS", 48, MIDI_UNMAPPED}, /* ++ (HQ) */
- {"String MS", 45, MIDI_UNMAPPED}, /* + (CoC) */
+ {"StabBassMS", 34, MIDI_UNMAPPED}, /* + (Iceman) */
+ {"SteelDrmMS", 114, MIDI_UNMAPPED}, /* +++ (Iceman) */
+ {"StrSect1MS", 48, MIDI_UNMAPPED}, /* ++ (QFG1) */
+ {"String MS", 45, MIDI_UNMAPPED}, /* + (Camelot) */
{"Syn-Choir ", 91, MIDI_UNMAPPED},
{"Syn Brass4", 63, MIDI_UNMAPPED}, /* ++ (PQ2) */
{"SynBass MS", 38, MIDI_UNMAPPED},
- {"SwmpBackgr", 120, MIDI_UNMAPPED}, /* ?? (CB,HQ) */
- {"T-Bone2 MS", 57, MIDI_UNMAPPED}, /* +++ (HQ) */
- {"Taiko ", 116, 35}, /* +++ (Coc) */
+ {"SwmpBackgr", 120, MIDI_UNMAPPED}, /* ?? (LB1, QFG1) */
+ {"T-Bone2 MS", 57, MIDI_UNMAPPED}, /* +++ (QFG1) */
+ {"Taiko ", 116, 35}, /* +++ (Camelot) */
{"Taiko Rim ", 118, 37}, /* +++ (LSL3) */
- {"Timpani1 ", 47, MIDI_UNMAPPED}, /* +++ (CB) */
- {"Tom MS", 117, 48}, /* +++ (iceMan) */
- {"Toms MS", 117, 48}, /* +++ (CoC, HQ) */
+ {"Timpani1 ", 47, MIDI_UNMAPPED}, /* +++ (LB1) */
+ {"Tom MS", 117, 48}, /* +++ (Iceman) */
+ {"Toms MS", 117, 48}, /* +++ (Camelot, QFG1) */
{"Tpt1prtl ", 56, MIDI_UNMAPPED}, /* +++ (KQ1) */
- {"TriangleMS", 112, 81}, /* R (CoC) */
- {"Trumpet 1 ", 56, MIDI_UNMAPPED}, /* +++ (CoC) */
- {"Type MS", MIDI_MAPPED_TO_RHYTHM, 39}, /* + (iceMan) */
+ {"TriangleMS", 112, 81}, /* R (Camelot) */
+ {"Trumpet 1 ", 56, MIDI_UNMAPPED}, /* +++ (Camelot) */
+ {"Type MS", MIDI_MAPPED_TO_RHYTHM, 39}, /* + (Iceman) */
{"WaterBells", 98, MIDI_UNMAPPED}, /* + (PQ2) */
{"WaterFallK", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (KQ1) */
- {"Whiporill ", 123, MIDI_UNMAPPED}, /* + (CB) */
- {"Wind ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (CB) */
- {"Wind MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (HQ, iceMan) */
- {"Wind2 MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (CoC) */
- {"Woodpecker", 115, MIDI_UNMAPPED}, /* ? (CB) */
- {"WtrFall MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (CoC, HQ, iceMan) */
+ {"Whiporill ", 123, MIDI_UNMAPPED}, /* + (LB1) */
+ {"Wind ", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (LB1) */
+ {"Wind MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (QFG1, Iceman) */
+ {"Wind2 MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (Camelot) */
+ {"Woodpecker", 115, MIDI_UNMAPPED}, /* ? (LB1) */
+ {"WtrFall MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, /* ? (Camelot, QFG1, Iceman) */
{0, 0, 0}
};
diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp
index 1ef0781906..8ba7a6a352 100644
--- a/engines/sci/sound/drivers/midi.cpp
+++ b/engines/sci/sound/drivers/midi.cpp
@@ -53,9 +53,10 @@ public:
void send(uint32 b);
void sysEx(const byte *msg, uint16 length);
bool hasRhythmChannel() const { return true; }
- byte getPlayId();
+ byte getPlayId() const;
int getPolyphony() const { return kVoices; }
- int getFirstChannel();
+ int getFirstChannel() const;
+ int getLastChannel() const;
void setVolume(byte volume);
int getVolume();
void setReverb(byte reverb);
@@ -97,7 +98,7 @@ private:
};
bool _isMt32;
- bool _isOldPatchFormat;
+ bool _useMT32Track;
bool _hasReverb;
bool _playSwitch;
int _masterVolume;
@@ -119,7 +120,7 @@ private:
byte _sysExBuf[kMaxSysExSize];
};
-MidiPlayer_Midi::MidiPlayer_Midi(SciVersion version) : MidiPlayer(version), _playSwitch(true), _masterVolume(15), _isMt32(false), _hasReverb(false), _isOldPatchFormat(true) {
+MidiPlayer_Midi::MidiPlayer_Midi(SciVersion version) : MidiPlayer(version), _playSwitch(true), _masterVolume(15), _isMt32(false), _hasReverb(false), _useMT32Track(true) {
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI);
_driver = createMidi(dev);
@@ -139,6 +140,10 @@ MidiPlayer_Midi::~MidiPlayer_Midi() {
void MidiPlayer_Midi::noteOn(int channel, int note, int velocity) {
uint8 patch = _channels[channel].mappedPatch;
+ assert(channel <= 15);
+ assert(note <= 127);
+ assert(velocity <= 127);
+
if (channel == MIDI_RHYTHM_CHANNEL) {
if (_percussionMap[note] == MIDI_UNMAPPED) {
debugC(kDebugLevelSound, "[Midi] Percussion instrument %i is unmapped", note);
@@ -175,6 +180,7 @@ void MidiPlayer_Midi::noteOn(int channel, int note, int velocity) {
// We assume that velocity 0 maps to 0 (for note off)
int mapIndex = _channels[channel].velocityMapIdx;
+ assert(velocity <= 127);
velocity = _velocityMap[mapIndex][velocity];
}
@@ -183,6 +189,8 @@ void MidiPlayer_Midi::noteOn(int channel, int note, int velocity) {
}
void MidiPlayer_Midi::controlChange(int channel, int control, int value) {
+ assert(channel <= 15);
+
switch (control) {
case 0x07:
_channels[channel].volume = value;
@@ -232,6 +240,8 @@ void MidiPlayer_Midi::controlChange(int channel, int control, int value) {
void MidiPlayer_Midi::setPatch(int channel, int patch) {
bool resetVol = false;
+ assert(channel <= 15);
+
if ((channel == MIDI_RHYTHM_CHANNEL) || (_channels[channel].patch == patch))
return;
@@ -319,12 +329,19 @@ void MidiPlayer_Midi::send(uint32 b) {
}
// We return 1 for mt32, because if we remap channels to 0 for mt32, those won't get played at all
-int MidiPlayer_Midi::getFirstChannel() {
+// NOTE: SSCI uses channels 1 through 8 for General MIDI as well, in the drivers I checked
+int MidiPlayer_Midi::getFirstChannel() const {
if (_isMt32)
return 1;
return 0;
}
+int MidiPlayer_Midi::getLastChannel() const {
+ if (_isMt32)
+ return 8;
+ return 15;
+}
+
void MidiPlayer_Midi::setVolume(byte volume) {
_masterVolume = volume;
@@ -772,6 +789,9 @@ int MidiPlayer_Midi::open(ResourceManager *resMan) {
_percussionMap[i] = i;
_patchMap[i] = i;
_velocityMap[0][i] = i;
+ _velocityMap[1][i] = i;
+ _velocityMap[2][i] = i;
+ _velocityMap[3][i] = i;
_keyShift[i] = 0;
_volAdjust[i] = 0;
_velocityMapIdx[i] = 0;
@@ -808,17 +828,35 @@ int MidiPlayer_Midi::open(ResourceManager *resMan) {
// Detect the format of patch 1, so that we know what play mask to use
res = resMan->findResource(ResourceId(kResourceTypePatch, 1), 0);
if (!res)
- _isOldPatchFormat = false;
+ _useMT32Track = false;
else
- _isOldPatchFormat = !isMt32GmPatch(res->data, res->size);
+ _useMT32Track = !isMt32GmPatch(res->data, res->size);
+
+ // Check if the songs themselves have a GM track
+ if (!_useMT32Track) {
+ if (!resMan->isGMTrackIncluded())
+ _useMT32Track = true;
+ }
} else {
// No GM patch found, map instruments using MT-32 patch
warning("Game has no native support for General MIDI, applying auto-mapping");
+ // TODO: The MT-32 <-> GM mapping hasn't been worked on for SCI1 games. Throw
+ // a warning to the user
+ if (getSciVersion() >= SCI_VERSION_1_EGA)
+ warning("The automatic mapping for General MIDI hasn't been worked on for "
+ "SCI1 games. Music might sound wrong or broken. Please choose another "
+ "music driver for this game (e.g. Adlib or MT-32) if you are "
+ "experiencing issues with music");
+
// Modify velocity map to make low velocity notes a little louder
- for (uint i = 1; i < 0x40; i++)
+ for (uint i = 1; i < 0x40; i++) {
_velocityMap[0][i] = 0x20 + (i - 1) / 2;
+ _velocityMap[1][i] = 0x20 + (i - 1) / 2;
+ _velocityMap[2][i] = 0x20 + (i - 1) / 2;
+ _velocityMap[3][i] = 0x20 + (i - 1) / 2;
+ }
res = resMan->findResource(ResourceId(kResourceTypePatch, 1), 0);
@@ -872,7 +910,7 @@ void MidiPlayer_Midi::sysEx(const byte *msg, uint16 length) {
g_system->updateScreen();
}
-byte MidiPlayer_Midi::getPlayId() {
+byte MidiPlayer_Midi::getPlayId() const {
switch (_version) {
case SCI_VERSION_0_EARLY:
case SCI_VERSION_0_LATE:
@@ -881,7 +919,7 @@ byte MidiPlayer_Midi::getPlayId() {
if (_isMt32)
return 0x0c;
else
- return _isOldPatchFormat ? 0x0c : 0x07;
+ return _useMT32Track ? 0x0c : 0x07;
}
}
diff --git a/engines/sci/sound/drivers/mididriver.h b/engines/sci/sound/drivers/mididriver.h
index 2db6f25c70..129159ecdc 100644
--- a/engines/sci/sound/drivers/mididriver.h
+++ b/engines/sci/sound/drivers/mididriver.h
@@ -32,6 +32,20 @@
namespace Sci {
+// Music patches in SCI games:
+// ===========================
+// 1.pat - MT-32 driver music patch
+// 2.pat - Yamaha FB01 driver music patch
+// 3.pat - Adlib driver music patch
+// 4.pat - Casio MT-540 (in earlier SCI0 games)
+// 4.pat - GM driver music patch (in later games that support GM)
+// 7.pat (newer) / patch.200 (older) - Mac driver music patch / Casio CSM-1
+// 9.pat (newer) / patch.005 (older) - Amiga driver music patch
+// 98.pat - Unknown, found in later SCI1.1 games. A MIDI format patch
+// 101.pat - CMS/PCjr driver music patch.
+// Only later PCjr drivers use this patch, earlier ones don't use a patch
+// bank.001 - older SCI0 Amiga instruments
+
class ResourceManager;
enum {
@@ -39,7 +53,6 @@ enum {
MIDI_PROP_MASTER_VOLUME = 0
};
-
#define MIDI_RHYTHM_CHANNEL 9
/* Special SCI sound stuff */
@@ -69,7 +82,7 @@ protected:
byte _reverb;
public:
- MidiPlayer(SciVersion version) : _reverb(0), _version(version) { }
+ MidiPlayer(SciVersion version) : _driver(0), _reverb(0), _version(version) { }
int open() {
ResourceManager *resMan = g_sci->getResMan(); // HACK
@@ -84,9 +97,10 @@ public:
MidiChannel *getPercussionChannel() { return _driver->getPercussionChannel(); }
virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _driver->setTimerCallback(timer_param, timer_proc); }
- virtual byte getPlayId() = 0;
+ virtual byte getPlayId() const = 0;
virtual int getPolyphony() const = 0;
- virtual int getFirstChannel() { return 0; }
+ virtual int getFirstChannel() const { return 0; }
+ virtual int getLastChannel() const { return 15; }
virtual void setVolume(byte volume) {
if(_driver)
@@ -97,7 +111,7 @@ public:
return _driver ? _driver->property(MIDI_PROP_MASTER_VOLUME, 0xffff) : 0;
}
- virtual byte getReverb() { return _reverb; }
+ virtual byte getReverb() const { return _reverb; }
virtual void setReverb(byte reverb) { _reverb = reverb; }
virtual void playSwitch(bool play) {
@@ -116,6 +130,7 @@ extern MidiPlayer *MidiPlayer_AdLib_create(SciVersion version);
extern MidiPlayer *MidiPlayer_AmigaMac_create(SciVersion version);
extern MidiPlayer *MidiPlayer_PCJr_create(SciVersion version);
extern MidiPlayer *MidiPlayer_PCSpeaker_create(SciVersion version);
+extern MidiPlayer *MidiPlayer_CMS_create(SciVersion version);
extern MidiPlayer *MidiPlayer_Midi_create(SciVersion version);
extern MidiPlayer *MidiPlayer_Fb01_create(SciVersion version);
diff --git a/engines/sci/sound/drivers/pcjr.cpp b/engines/sci/sound/drivers/pcjr.cpp
index bdf90eff5c..93de072865 100644
--- a/engines/sci/sound/drivers/pcjr.cpp
+++ b/engines/sci/sound/drivers/pcjr.cpp
@@ -234,13 +234,13 @@ class MidiPlayer_PCJr : public MidiPlayer {
public:
MidiPlayer_PCJr(SciVersion version) : MidiPlayer(version) { _driver = new MidiDriver_PCJr(g_system->getMixer()); }
int open(ResourceManager *resMan) { return static_cast<MidiDriver_PCJr *>(_driver)->open(getPolyphony()); }
- byte getPlayId();
+ byte getPlayId() const;
int getPolyphony() const { return 3; }
bool hasRhythmChannel() const { return false; }
void setVolume(byte volume) { static_cast<MidiDriver_PCJr *>(_driver)->_global_volume = volume; }
};
-byte MidiPlayer_PCJr::getPlayId() {
+byte MidiPlayer_PCJr::getPlayId() const {
switch (_version) {
case SCI_VERSION_0_EARLY:
return 0x02;
@@ -259,11 +259,11 @@ class MidiPlayer_PCSpeaker : public MidiPlayer_PCJr {
public:
MidiPlayer_PCSpeaker(SciVersion version) : MidiPlayer_PCJr(version) { }
- byte getPlayId();
+ byte getPlayId() const;
int getPolyphony() const { return 1; }
};
-byte MidiPlayer_PCSpeaker::getPlayId() {
+byte MidiPlayer_PCSpeaker::getPlayId() const {
switch (_version) {
case SCI_VERSION_0_EARLY:
return 0x04;
diff --git a/engines/sci/sound/midiparser_sci.cpp b/engines/sci/sound/midiparser_sci.cpp
index 769df73365..d53f919f8f 100644
--- a/engines/sci/sound/midiparser_sci.cpp
+++ b/engines/sci/sound/midiparser_sci.cpp
@@ -53,6 +53,7 @@ MidiParser_SCI::MidiParser_SCI(SciVersion soundVersion, SciMusic *music) :
_ppqn = 1;
setTempo(16667);
+ _masterVolume = 15;
_volume = 127;
_signalSet = false;
@@ -418,7 +419,7 @@ void MidiParser_SCI::sendToDriver(uint32 midi) {
int channelVolume = (midi >> 16) & 0xFF;
// Remember, if we need to set it ourselves
_channelVolume[midiChannel] = channelVolume;
- // Adjust volume accordingly to current "global" volume
+ // Adjust volume accordingly to current local volume
channelVolume = channelVolume * _volume / 127;
midi = (midi & 0xFFF0) | ((channelVolume & 0xFF) << 16);
}
@@ -445,12 +446,8 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
}
if (_signalSet) {
_signalSet = false;
- if (!_pSnd->signal) {
- _pSnd->signal = _signalToSet;
- } else {
- // signal already set and waiting for getting to scripts, queue new one
- _pSnd->signalQueue.push_back(_signalToSet);
- }
+ _pSnd->setSignal(_signalToSet);
+
debugC(4, kDebugLevelSound, "signal %04x", _signalToSet);
}
@@ -613,12 +610,7 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
jumpToTick(_loopTick);
} else {
_pSnd->status = kSoundStopped;
- if (!_pSnd->signal) {
- _pSnd->signal = SIGNAL_OFFSET;
- } else {
- // signal already set and waiting for getting to scripts, queue new one
- _pSnd->signalQueue.push_back(SIGNAL_OFFSET);
- }
+ _pSnd->setSignal(SIGNAL_OFFSET);
debugC(4, kDebugLevelSound, "signal EOT");
}
@@ -668,6 +660,28 @@ void MidiParser_SCI::allNotesOff() {
memset(_active_notes, 0, sizeof(_active_notes));
}
+void MidiParser_SCI::setMasterVolume(byte masterVolume) {
+ assert(masterVolume <= MUSIC_MASTERVOLUME_MAX);
+ _masterVolume = masterVolume;
+ switch (_soundVersion) {
+ case SCI_VERSION_0_EARLY:
+ case SCI_VERSION_0_LATE:
+ // update driver master volume
+ setVolume(_volume);
+ break;
+
+ case SCI_VERSION_1_EARLY:
+ case SCI_VERSION_1_LATE:
+ case SCI_VERSION_2_1:
+ // directly set master volume (global volume is merged with channel volumes)
+ ((MidiPlayer *)_driver)->setVolume(masterVolume);
+ break;
+
+ default:
+ error("MidiParser_SCI::setVolume: Unsupported soundVersion");
+ }
+}
+
void MidiParser_SCI::setVolume(byte volume) {
assert(volume <= MUSIC_VOLUME_MAX);
_volume = volume;
@@ -676,8 +690,7 @@ void MidiParser_SCI::setVolume(byte volume) {
case SCI_VERSION_0_EARLY:
case SCI_VERSION_0_LATE: {
// SCI0 adlib driver doesn't support channel volumes, so we need to go this way
- // TODO: this should take the actual master volume into account
- int16 globalVolume = _volume * 15 / 127;
+ int16 globalVolume = _volume * _masterVolume / MUSIC_VOLUME_MAX;
((MidiPlayer *)_driver)->setVolume(globalVolume);
break;
}
diff --git a/engines/sci/sound/midiparser_sci.h b/engines/sci/sound/midiparser_sci.h
index 90db06e539..9d0cb15e74 100644
--- a/engines/sci/sound/midiparser_sci.h
+++ b/engines/sci/sound/midiparser_sci.h
@@ -65,6 +65,7 @@ public:
}
void sendInitCommands();
void unloadMusic();
+ void setMasterVolume(byte masterVolume);
void setVolume(byte volume);
void stop() {
_abort_parse = true;
@@ -104,7 +105,8 @@ protected:
SoundResource::Track *_track;
MusicEntry *_pSnd;
uint32 _loopTick;
- byte _volume;
+ byte _masterVolume; // the overall master volume (same for all tracks)
+ byte _volume; // the global volume of the current track
bool _signalSet;
int16 _signalToSet;
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp
index fc1e56fcea..0dfa02c83f 100644
--- a/engines/sci/sound/music.cpp
+++ b/engines/sci/sound/music.cpp
@@ -30,6 +30,7 @@
#include "sci/sci.h"
#include "sci/console.h"
#include "sci/resource.h"
+#include "sci/engine/features.h"
#include "sci/engine/kernel.h"
#include "sci/engine/state.h"
#include "sci/sound/midiparser_sci.h"
@@ -65,9 +66,20 @@ void SciMusic::init() {
// Default to MIDI in SCI2.1+ games, as many don't have AdLib support.
Common::Platform platform = g_sci->getPlatform();
- uint32 dev = MidiDriver::detectDevice((getSciVersion() >= SCI_VERSION_2_1) ? (MDT_PCSPK | MDT_PCJR | MDT_ADLIB | MDT_MIDI | MDT_PREFER_GM) : (MDT_PCSPK | MDT_PCJR | MDT_ADLIB | MDT_MIDI));
- switch (MidiDriver::getMusicType(dev)) {
+ uint32 deviceFlags = MDT_PCSPK | MDT_PCJR | MDT_ADLIB | MDT_MIDI;
+
+ if (getSciVersion() >= SCI_VERSION_2_1)
+ deviceFlags |= MDT_PREFER_GM;
+
+ // Currently our CMS implementation only supports SCI1(.1)
+ if (getSciVersion() >= SCI_VERSION_1_EGA && getSciVersion() <= SCI_VERSION_1_1)
+ deviceFlags |= MDT_CMS;
+
+ uint32 dev = MidiDriver::detectDevice(deviceFlags);
+ _musicType = MidiDriver::getMusicType(dev);
+
+ switch (_musicType) {
case MT_ADLIB:
// FIXME: There's no Amiga sound option, so we hook it up to AdLib
if (g_sci->getPlatform() == Common::kPlatformAmiga || platform == Common::kPlatformMacintosh)
@@ -81,8 +93,11 @@ void SciMusic::init() {
case MT_PCSPK:
_pMidiDrv = MidiPlayer_PCSpeaker_create(_soundVersion);
break;
+ case MT_CMS:
+ _pMidiDrv = MidiPlayer_CMS_create(_soundVersion);
+ break;
default:
- if (ConfMan.getBool("enable_fb01"))
+ if (ConfMan.getBool("native_fb01"))
_pMidiDrv = MidiPlayer_Fb01_create(_soundVersion);
else
_pMidiDrv = MidiPlayer_Midi_create(_soundVersion);
@@ -100,6 +115,7 @@ void SciMusic::init() {
// Find out what the first possible channel is (used, when doing channel
// remapping).
_driverFirstChannel = _pMidiDrv->getFirstChannel();
+ _driverLastChannel = _pMidiDrv->getLastChannel();
}
void SciMusic::miditimerCallback(void *p) {
@@ -260,6 +276,7 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
pSnd->pMidiParser = new MidiParser_SCI(_soundVersion, this);
pSnd->pMidiParser->setMidiDriver(_pMidiDrv);
pSnd->pMidiParser->setTimerRate(_dwTempo);
+ pSnd->pMidiParser->setMasterVolume(_masterVolume);
}
pSnd->pauseCounter = 0;
@@ -288,6 +305,8 @@ int16 SciMusic::tryToOwnChannel(MusicEntry *caller, int16 bestChannel) {
}
// otherwise look for unused channel
for (int channelNr = _driverFirstChannel; channelNr < 15; channelNr++) {
+ if (channelNr == 9) // never map to channel 9 (precussion)
+ continue;
if (!_usedChannel[channelNr]) {
_usedChannel[channelNr] = caller;
return channelNr;
@@ -349,20 +368,25 @@ void SciMusic::soundPlay(MusicEntry *pSnd) {
}
}
- if (pSnd->pStreamAud && !_pMixer->isSoundHandleActive(pSnd->hCurrentAud)) {
- if (pSnd->loop > 1) {
- pSnd->pLoopStream = new Audio::LoopingAudioStream(pSnd->pStreamAud,
- pSnd->loop, DisposeAfterUse::NO);
- _pMixer->playStream(pSnd->soundType, &pSnd->hCurrentAud,
- pSnd->pLoopStream, -1, pSnd->volume, 0,
- DisposeAfterUse::NO);
- } else {
- // Rewind in case we play the same sample multiple times
- // (non-looped) like in pharkas right at the start
- pSnd->pStreamAud->rewind();
- _pMixer->playStream(pSnd->soundType, &pSnd->hCurrentAud,
- pSnd->pStreamAud, -1, pSnd->volume, 0,
- DisposeAfterUse::NO);
+ if (pSnd->pStreamAud) {
+ if (!_pMixer->isSoundHandleActive(pSnd->hCurrentAud)) {
+ // Sierra SCI ignores volume set when playing samples via kDoSound
+ // At least freddy pharkas/CD has a script bug that sets volume to 0
+ // when playing the "score" sample
+ if (pSnd->loop > 1) {
+ pSnd->pLoopStream = new Audio::LoopingAudioStream(pSnd->pStreamAud,
+ pSnd->loop, DisposeAfterUse::NO);
+ _pMixer->playStream(pSnd->soundType, &pSnd->hCurrentAud,
+ pSnd->pLoopStream, -1, _pMixer->kMaxChannelVolume, 0,
+ DisposeAfterUse::NO);
+ } else {
+ // Rewind in case we play the same sample multiple times
+ // (non-looped) like in pharkas right at the start
+ pSnd->pStreamAud->rewind();
+ _pMixer->playStream(pSnd->soundType, &pSnd->hCurrentAud,
+ pSnd->pStreamAud, -1, _pMixer->kMaxChannelVolume, 0,
+ DisposeAfterUse::NO);
+ }
}
} else {
if (pSnd->pMidiParser) {
@@ -375,8 +399,14 @@ void SciMusic::soundPlay(MusicEntry *pSnd) {
if (pSnd->status == kSoundStopped) {
pSnd->pMidiParser->jumpToTick(0);
} else {
+ // Disable sound looping before fast forwarding to the last position,
+ // when loading a saved game. Fixes bug #3083151.
+ uint16 prevLoop = pSnd->loop;
+ pSnd->loop = 0;
// Fast forward to the last position and perform associated events when loading
pSnd->pMidiParser->jumpToTick(pSnd->ticker, true);
+ // Restore looping
+ pSnd->loop = prevLoop;
}
pSnd->pMidiParser->mainThreadEnd();
_mutex.unlock();
@@ -412,7 +442,8 @@ void SciMusic::soundStop(MusicEntry *pSnd) {
void SciMusic::soundSetVolume(MusicEntry *pSnd, byte volume) {
assert(volume <= MUSIC_VOLUME_MAX);
if (pSnd->pStreamAud) {
- _pMixer->setChannelVolume(pSnd->hCurrentAud, volume * 2); // Mixer is 0-255, SCI is 0-127
+ // we simply ignore volume changes for samples, because sierra sci also
+ // doesn't support volume for samples via kDoSound
} else if (pSnd->pMidiParser) {
_mutex.lock();
pSnd->pMidiParser->mainThreadBegin();
@@ -422,6 +453,13 @@ void SciMusic::soundSetVolume(MusicEntry *pSnd, byte volume) {
}
}
+// this is used to set volume of the sample, used for fading only!
+void SciMusic::soundSetSampleVolume(MusicEntry *pSnd, byte volume) {
+ assert(volume <= MUSIC_VOLUME_MAX);
+ assert(pSnd->pStreamAud);
+ _pMixer->setChannelVolume(pSnd->hCurrentAud, volume * 2); // Mixer is 0-255, SCI is 0-127
+}
+
void SciMusic::soundSetPriority(MusicEntry *pSnd, byte prio) {
Common::StackLock lock(_mutex);
@@ -525,8 +563,11 @@ void SciMusic::soundSetMasterVolume(uint16 vol) {
Common::StackLock lock(_mutex);
- if (_pMidiDrv)
- _pMidiDrv->setVolume(vol);
+ const MusicList::iterator end = _playList.end();
+ for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
+ if ((*i)->pMidiParser)
+ (*i)->pMidiParser->setMasterVolume(vol);
+ }
}
void SciMusic::sendMidiCommand(uint32 cmd) {
@@ -681,4 +722,23 @@ void MusicEntry::doFade() {
}
}
+void MusicEntry::setSignal(int newSignal) {
+ // For SCI0, we cache the signals to set, as some songs might
+ // update their signal faster than kGetEvent is called (which is where
+ // we manually invoke kDoSoundUpdateCues for SCI0 games). SCI01 and
+ // newer handle signalling inside kDoSoundUpdateCues. Refer to bug #3042981
+ if (g_sci->_features->detectDoSoundType() <= SCI_VERSION_0_LATE) {
+ if (!signal) {
+ signal = newSignal;
+ } else {
+ // signal already set and waiting for getting to scripts, queue new one
+ signalQueue.push_back(newSignal);
+ }
+ } else {
+ // Set the signal directly for newer games, otherwise the sound
+ // object might be deleted already later on (refer to bug #3045913)
+ signal = newSignal;
+ }
+}
+
} // End of namespace Sci
diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h
index 3cf600fcf3..9fcbb9346d 100644
--- a/engines/sci/sound/music.h
+++ b/engines/sci/sound/music.h
@@ -47,6 +47,8 @@ enum SoundStatus {
#define MUSIC_VOLUME_DEFAULT 127
#define MUSIC_VOLUME_MAX 127
+#define MUSIC_MASTERVOLUME_DEFAULT 15
+#define MUSIC_MASTERVOLUME_MAX 15
class MidiParser_SCI;
class SegManager;
@@ -109,6 +111,7 @@ public:
void doFade();
void onTimer();
+ void setSignal(int signal);
virtual void saveLoadWithSerializer(Common::Serializer &ser);
};
@@ -145,6 +148,7 @@ public:
void soundResume(MusicEntry *pSnd);
void soundToggle(MusicEntry *pSnd, bool pause);
void soundSetVolume(MusicEntry *pSnd, byte volume);
+ void soundSetSampleVolume(MusicEntry *pSnd, byte volume);
void soundSetPriority(MusicEntry *pSnd, byte prio);
uint16 soundGetMasterVolume();
void soundSetMasterVolume(uint16 vol);
@@ -152,6 +156,7 @@ public:
void soundSetSoundOn(bool soundOnFlag);
uint16 soundGetVoices();
uint32 soundGetTempo() const { return _dwTempo; }
+ MusicType soundGetMusicType() const { return _musicType; }
bool soundIsActive(MusicEntry *pSnd) {
assert(pSnd->pStreamAud != 0);
@@ -215,8 +220,10 @@ private:
MusicEntry *_usedChannel[16];
MidiCommandQueue _queuedCommands;
+ MusicType _musicType;
int _driverFirstChannel;
+ int _driverLastChannel;
};
} // End of namespace Sci
diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp
index 567a1605f3..790164cf41 100644
--- a/engines/sci/sound/soundcmd.cpp
+++ b/engines/sci/sound/soundcmd.cpp
@@ -78,8 +78,13 @@ void SoundCommandParser::processInitSound(reg_t obj) {
// a relevant audio resource, play it, otherwise switch to synthesized
// effects. If the resource exists, play it using map 65535 (sound
// effects map)
+ bool checkAudioResource = getSciVersion() >= SCI_VERSION_1_1;
+ if (g_sci->getGameId() == GID_HOYLE4)
+ checkAudioResource = false; // hoyle 4 has garbled audio resources in place of the sound resources
+ // if we play those, we will only make the user deaf and break speakers. Sierra SCI doesn't play anything
+ // on soundblaster. FIXME: check, why this is
- if (getSciVersion() >= SCI_VERSION_1_1 && _resMan->testResource(ResourceId(kResourceTypeAudio, resourceId))) {
+ if (checkAudioResource && _resMan->testResource(ResourceId(kResourceTypeAudio, resourceId))) {
// Found a relevant audio resource, play it
int sampleLen;
newSound->pStreamAud = _audio->getAudioStream(resourceId, 65535, &sampleLen);
@@ -284,8 +289,8 @@ reg_t SoundCommandParser::kDoSoundMasterVolume(int argc, reg_t *argv, reg_t acc)
if (argc > 0) {
debugC(2, kDebugLevelSound, "kDoSound(masterVolume): %d", argv[0].toSint16());
- int vol = CLIP<int16>(argv[0].toSint16(), 0, kMaxSciVolume);
- vol = vol * Audio::Mixer::kMaxMixerVolume / kMaxSciVolume;
+ int vol = CLIP<int16>(argv[0].toSint16(), 0, MUSIC_MASTERVOLUME_MAX);
+ vol = vol * Audio::Mixer::kMaxMixerVolume / MUSIC_MASTERVOLUME_MAX;
ConfMan.setInt("music_volume", vol);
ConfMan.setInt("sfx_volume", vol);
g_engine->syncSoundSettings();
@@ -298,7 +303,7 @@ reg_t SoundCommandParser::kDoSoundFade(int argc, reg_t *argv, reg_t acc) {
MusicEntry *musicSlot = _music->getSlot(obj);
if (!musicSlot) {
- warning("kDoSound(fade): Slot not found (%04x:%04x)", PRINT_REG(obj));
+ debugC(2, kDebugLevelSound, "kDoSound(fade): Slot not found (%04x:%04x)", PRINT_REG(obj));
return acc;
}
@@ -402,7 +407,7 @@ void SoundCommandParser::processUpdateCues(reg_t obj) {
}
// We get a flag from MusicEntry::doFade() here to set volume for the stream
if (musicSlot->fadeSetVolume) {
- _music->soundSetVolume(musicSlot, musicSlot->volume);
+ _music->soundSetSampleVolume(musicSlot, musicSlot->volume);
musicSlot->fadeSetVolume = false;
}
} else if (musicSlot->pMidiParser) {
@@ -688,6 +693,7 @@ void SoundCommandParser::startNewSound(int number) {
}
void SoundCommandParser::setMasterVolume(int vol) {
+ // 0...15
_music->soundSetMasterVolume(vol);
}
@@ -695,4 +701,9 @@ void SoundCommandParser::pauseAll(bool pause) {
_music->pauseAll(pause);
}
+MusicType SoundCommandParser::getMusicType() const {
+ assert(_music);
+ return _music->soundGetMusicType();
+}
+
} // End of namespace Sci
diff --git a/engines/sci/sound/soundcmd.h b/engines/sci/sound/soundcmd.h
index 8e6fb81762..61371d903f 100644
--- a/engines/sci/sound/soundcmd.h
+++ b/engines/sci/sound/soundcmd.h
@@ -27,6 +27,7 @@
#define SCI_SOUNDCMD_H
#include "common/list.h"
+#include "sound/mididrv.h" // for MusicType
#include "sci/engine/state.h"
namespace Sci {
@@ -47,10 +48,6 @@ public:
SoundCommandParser(ResourceManager *resMan, SegManager *segMan, Kernel *kernel, AudioPlayer *audio, SciVersion soundVersion);
~SoundCommandParser();
- enum {
- kMaxSciVolume = 15
- };
-
//reg_t parseCommand(int argc, reg_t *argv, reg_t acc);
// Functions used for game state loading
@@ -71,6 +68,8 @@ public:
void processPlaySound(reg_t obj);
void processStopSound(reg_t obj, bool sampleFinishedPlaying);
+ MusicType getMusicType() const;
+
/**
* Synchronizes the current state of the music list to the rest of the engine, so that
* the changes that the sound thread makes to the music are registered with the engine