2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2001-2003 The ScummVM project
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "scumm.h"
|
2002-05-14 23:32:34 +00:00
|
|
|
#include "actor.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
#include "resource.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
#include "common/util.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
|
|
|
|
/* Script status type (slot.status) */
|
|
|
|
enum {
|
|
|
|
ssDead = 0,
|
|
|
|
ssPaused = 1,
|
|
|
|
ssRunning = 2
|
|
|
|
};
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Start executing script 'script' with parameters 'a' and 'b' */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runScript(int script, int a, int b, int *lvarptr) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *scriptPtr;
|
|
|
|
uint32 scriptOffs;
|
|
|
|
byte scriptType;
|
2001-11-07 18:10:52 +00:00
|
|
|
int slot;
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *s;
|
|
|
|
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (script == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (b == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
stopScriptNr(script);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (script < _numGlobalScripts) {
|
2001-11-05 19:21:49 +00:00
|
|
|
scriptPtr = getResourceAddress(rtScript, script);
|
2002-04-11 15:22:02 +00:00
|
|
|
scriptOffs = _resourceHeaderSize;
|
2001-11-12 20:50:36 +00:00
|
|
|
scriptType = WIO_GLOBAL;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2001-10-16 10:01:48 +00:00
|
|
|
scriptOffs = _localScriptList[script - _numGlobalScripts];
|
2001-10-09 14:30:12 +00:00
|
|
|
if (scriptOffs == 0)
|
|
|
|
error("Local script %d is not in room %d", script, _roomResource);
|
2001-11-12 20:50:36 +00:00
|
|
|
scriptType = WIO_LOCAL;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
slot = getScriptSlot();
|
|
|
|
|
|
|
|
s = &vm.slot[slot];
|
|
|
|
s->number = script;
|
|
|
|
s->offs = scriptOffs;
|
2002-12-09 01:27:40 +00:00
|
|
|
s->status = ssRunning;
|
2001-11-12 20:50:36 +00:00
|
|
|
s->where = scriptType;
|
2001-10-09 14:30:12 +00:00
|
|
|
s->unk1 = a;
|
|
|
|
s->unk2 = b;
|
|
|
|
s->freezeCount = 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2002-08-25 11:35:13 +00:00
|
|
|
s->delayFrameCount = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
initializeLocals(slot, lvarptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
runScriptNested(slot);
|
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Stop script 'script' */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::stopScriptNr(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
|
|
|
NestedScript *nest;
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, num;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (script == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ss = &vm.slot[1];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
2002-12-09 01:27:40 +00:00
|
|
|
if (script != ss->number || ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL || ss->status == ssDead)
|
2001-10-09 14:30:12 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ss->cutsceneOverride)
|
|
|
|
error("Script %d stopped with active cutscene/override", script);
|
|
|
|
ss->number = 0;
|
2002-03-16 18:03:28 +00:00
|
|
|
ss->status = ssDead;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_currentScript == i)
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_numNestedScripts == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nest = &vm.nest[0];
|
|
|
|
num = _numNestedScripts;
|
|
|
|
|
|
|
|
do {
|
2002-07-07 20:25:23 +00:00
|
|
|
if (nest->number == script && (nest->where == WIO_GLOBAL || nest->where == WIO_LOCAL)) {
|
2001-10-16 10:01:48 +00:00
|
|
|
nest->number = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
nest->slot = 0xFF;
|
2001-11-12 20:50:36 +00:00
|
|
|
nest->where = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
} while (nest++, --num);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Stop an object script 'script'*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::stopObjectScript(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
|
|
|
NestedScript *nest;
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, num;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (script == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ss = &vm.slot[1];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
2002-12-25 19:06:31 +00:00
|
|
|
if (script == ss->number && ss->status != ssDead &&
|
|
|
|
(ss->where == WIO_ROOM || ss->where == WIO_INVENTORY || ss->where == WIO_FLOBJECT)) {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (ss->cutsceneOverride)
|
|
|
|
error("Object %d stopped with active cutscene/override", script);
|
|
|
|
ss->number = 0;
|
2002-03-16 18:03:28 +00:00
|
|
|
ss->status = ssDead;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_currentScript == i)
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_numNestedScripts == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nest = &vm.nest[0];
|
|
|
|
num = _numNestedScripts;
|
|
|
|
|
|
|
|
do {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (nest->number == script &&
|
2002-07-07 20:25:23 +00:00
|
|
|
(nest->where == WIO_ROOM || nest->where == WIO_FLOBJECT || nest->where == WIO_INVENTORY)) {
|
2001-10-16 10:01:48 +00:00
|
|
|
nest->number = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
nest->slot = 0xFF;
|
2001-11-12 20:50:36 +00:00
|
|
|
nest->where = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
} while (nest++, --num);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Return a free script slot */
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getScriptSlot() {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
|
|
|
int i;
|
|
|
|
ss = &vm.slot[1];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
2002-12-09 01:27:40 +00:00
|
|
|
if (ss->status == ssDead)
|
2001-10-09 14:30:12 +00:00
|
|
|
return i;
|
|
|
|
}
|
2001-10-26 17:34:50 +00:00
|
|
|
error("Too many scripts running, %d max", NUM_SCRIPT_SLOT);
|
2002-05-05 18:10:29 +00:00
|
|
|
return -1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Run script 'script' nested - eg, within the parent script.*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runScriptNested(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
NestedScript *nest;
|
|
|
|
ScriptSlot *slot;
|
|
|
|
|
|
|
|
updateScriptPtr();
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
nest = &vm.nest[_numNestedScripts];
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_currentScript == 0xFF) {
|
2001-10-09 14:30:12 +00:00
|
|
|
nest->number = 0xFF;
|
2001-11-12 20:50:36 +00:00
|
|
|
nest->where = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
|
|
|
slot = &vm.slot[_currentScript];
|
|
|
|
nest->number = slot->number;
|
2001-11-12 20:50:36 +00:00
|
|
|
nest->where = slot->where;
|
2001-10-09 14:30:12 +00:00
|
|
|
nest->slot = _currentScript;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (++_numNestedScripts > sizeof(vm.nest) / sizeof(vm.nest[0]))
|
2001-10-09 14:30:12 +00:00
|
|
|
error("Too many nested scripts");
|
|
|
|
|
|
|
|
_currentScript = script;
|
|
|
|
|
|
|
|
getScriptBaseAddress();
|
|
|
|
getScriptEntryPoint();
|
|
|
|
executeScript();
|
|
|
|
|
|
|
|
_numNestedScripts--;
|
|
|
|
|
|
|
|
nest = &vm.nest[_numNestedScripts];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (nest->number != 0xFF) {
|
|
|
|
slot = &vm.slot[nest->slot];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (slot->number == nest->number && slot->where == nest->where &&
|
2002-12-09 01:27:40 +00:00
|
|
|
slot->status != ssDead && slot->freezeCount == 0) {
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = nest->slot;
|
|
|
|
getScriptBaseAddress();
|
|
|
|
getScriptEntryPoint();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::updateScriptPtr() {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_currentScript == 0xFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vm.slot[_currentScript].offs = _scriptPointer - _scriptOrgPointer;
|
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Get the code pointer to a script */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::getScriptBaseAddress() {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
2002-03-08 08:42:11 +00:00
|
|
|
int idx;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (_currentScript == 0xFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ss = &vm.slot[_currentScript];
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (ss->where) {
|
|
|
|
case WIO_INVENTORY: /* inventory script * */
|
2002-03-08 08:42:11 +00:00
|
|
|
idx = getObjectIndex(ss->number);
|
|
|
|
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
|
2003-03-07 02:42:39 +00:00
|
|
|
assert(idx < _maxInventoryItems);
|
2002-03-08 08:42:11 +00:00
|
|
|
_lastCodePtr = &_baseInventoryItems[idx];
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_ROOM: /* room script */
|
2002-12-24 23:26:37 +00:00
|
|
|
if (_features & GF_AFTER_V8) {
|
|
|
|
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
|
2003-03-07 02:42:39 +00:00
|
|
|
assert(_roomResource < res.num[rtRoomScripts]);
|
2002-12-24 23:26:37 +00:00
|
|
|
_lastCodePtr = &res.address[rtRoomScripts][_roomResource];
|
|
|
|
} else {
|
|
|
|
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
|
2003-03-07 02:42:39 +00:00
|
|
|
assert(_roomResource < _maxRooms);
|
2002-12-24 23:26:37 +00:00
|
|
|
_lastCodePtr = &_baseRooms[_roomResource];
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_GLOBAL: /* global script */
|
2001-11-05 19:21:49 +00:00
|
|
|
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
|
2003-03-07 02:42:39 +00:00
|
|
|
assert(ss->number < _maxScripts);
|
2001-10-09 14:30:12 +00:00
|
|
|
_lastCodePtr = &_baseScripts[ss->number];
|
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_FLOBJECT: /* flobject script */
|
2002-03-08 08:42:11 +00:00
|
|
|
idx = getObjectIndex(ss->number);
|
2002-07-07 20:25:23 +00:00
|
|
|
_scriptOrgPointer = getResourceAddress(rtFlObject, _objs[idx].fl_object_index);
|
2003-03-07 02:42:39 +00:00
|
|
|
assert(idx < _maxFLObject);
|
|
|
|
_lastCodePtr = &_baseFLObject[idx];
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Bad type while getting base address");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::getScriptEntryPoint() {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_currentScript == 0xFF)
|
|
|
|
return;
|
|
|
|
_scriptPointer = _scriptOrgPointer + vm.slot[_currentScript].offs;
|
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Execute a script - Read opcode, and execute it from the table */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::executeScript() {
|
2001-10-09 14:30:12 +00:00
|
|
|
while (_currentScript != 0xFF) {
|
|
|
|
_opcode = fetchScriptByte();
|
2002-04-11 17:19:16 +00:00
|
|
|
vm.slot[_currentScript].didexec = 1;
|
2003-01-12 01:01:20 +00:00
|
|
|
debug(7, "Script %d, offset 0x%x: [%X] %s()",
|
2002-12-23 18:37:56 +00:00
|
|
|
vm.slot[_currentScript].number,
|
|
|
|
_scriptPointer - _scriptOrgPointer,
|
|
|
|
_opcode,
|
|
|
|
getOpcodeDesc(_opcode));
|
2002-12-16 12:12:31 +00:00
|
|
|
executeOpcode(_opcode);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-16 12:12:31 +00:00
|
|
|
CHECK_HEAP;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
byte Scumm::fetchScriptByte() {
|
2001-12-11 13:34:15 +00:00
|
|
|
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
|
2001-10-09 14:30:12 +00:00
|
|
|
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
|
|
|
|
getScriptBaseAddress();
|
|
|
|
_scriptPointer = _scriptOrgPointer + oldoffs;
|
|
|
|
}
|
|
|
|
return *_scriptPointer++;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
uint Scumm::fetchScriptWord() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int a;
|
2001-12-11 13:34:15 +00:00
|
|
|
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
|
2001-10-09 14:30:12 +00:00
|
|
|
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
|
|
|
|
getScriptBaseAddress();
|
|
|
|
_scriptPointer = _scriptOrgPointer + oldoffs;
|
|
|
|
}
|
|
|
|
a = READ_LE_UINT16(_scriptPointer);
|
|
|
|
_scriptPointer += 2;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::fetchScriptWordSigned() {
|
2002-12-23 00:23:36 +00:00
|
|
|
return (int16)fetchScriptWord();
|
|
|
|
}
|
|
|
|
|
2001-12-29 12:46:15 +00:00
|
|
|
#ifndef BYPASS_COPY_PROT
|
|
|
|
#define BYPASS_COPY_PROT
|
|
|
|
#endif
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::readVar(uint var) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int a;
|
|
|
|
#ifdef BYPASS_COPY_PROT
|
|
|
|
static byte copyprotbypassed;
|
|
|
|
#endif
|
|
|
|
debug(9, "readvar=%d", var);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(var & 0xF000)) {
|
2001-12-01 17:06:13 +00:00
|
|
|
#if defined(BYPASS_COPY_PROT)
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var == 490 && _gameId == GID_MONKEY2 && !copyprotbypassed) {
|
2001-12-01 17:06:13 +00:00
|
|
|
copyprotbypassed = true;
|
|
|
|
var = 518;
|
|
|
|
}
|
2002-11-19 09:16:46 +00:00
|
|
|
|
|
|
|
if (var == 179 && _gameId == GID_MONKEY_VGA && !copyprotbypassed) {
|
|
|
|
copyprotbypassed = true;
|
|
|
|
var = 266;
|
|
|
|
}
|
2001-12-01 17:06:13 +00:00
|
|
|
#endif
|
2002-11-03 15:12:39 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(r)");
|
2001-10-16 10:01:48 +00:00
|
|
|
return _vars[var];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x2000 && !(_features & GF_NEW_OPCODES)) {
|
2001-10-09 14:30:12 +00:00
|
|
|
a = fetchScriptWord();
|
2002-04-11 17:19:16 +00:00
|
|
|
if (a & 0x2000)
|
2002-11-23 13:53:46 +00:00
|
|
|
var += readVar(a & ~0x2000);
|
2001-10-09 14:30:12 +00:00
|
|
|
else
|
2002-11-23 13:53:46 +00:00
|
|
|
var += a & 0xFFF;
|
|
|
|
var &= ~0x2000;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(var & 0xF000))
|
2001-10-16 10:01:48 +00:00
|
|
|
return _vars[var];
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x8000) {
|
2002-07-30 15:20:30 +00:00
|
|
|
if (_gameId == GID_ZAK256) {
|
|
|
|
// Emulate a wierd hack in Zak256 to read individual
|
|
|
|
// bits of a normal global
|
|
|
|
int b = (var & 0x000F);
|
|
|
|
var &= 0x0FFF;
|
|
|
|
var >>= 4;
|
|
|
|
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(rzb)");
|
|
|
|
return (_vars[ var ] & ( 1 << b ) ) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
var &= 0x7FFF;
|
2002-07-07 13:14:34 +00:00
|
|
|
checkRange(_numBitVariables - 1, 0, var, "Bit variable %d out of range(r)");
|
2002-04-11 17:19:16 +00:00
|
|
|
return (_bitVars[var >> 3] & (1 << (var & 7))) ? 1 : 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x4000) {
|
2002-11-03 15:12:39 +00:00
|
|
|
if (_gameId == GID_INDY3_256) {
|
|
|
|
var &= 0xF;
|
|
|
|
} else {
|
|
|
|
var &= 0xFFF;
|
|
|
|
}
|
2003-01-15 15:49:44 +00:00
|
|
|
checkRange(20, 0, var, "Local variable %d out of range(r)");
|
2001-11-07 18:10:52 +00:00
|
|
|
return vm.localvar[_currentScript][var];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error("Illegal varbits (r)");
|
2002-05-05 18:10:29 +00:00
|
|
|
return -1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::writeVar(uint var, int value) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(var & 0xF000)) {
|
|
|
|
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(w)");
|
2002-05-05 20:08:41 +00:00
|
|
|
|
|
|
|
// FIXME: Find some better place to put this.
|
|
|
|
if (var == VAR_CHARINC)
|
|
|
|
_vars[VAR_CHARINC] = _defaultTalkDelay / 20;
|
|
|
|
else
|
2002-07-07 13:14:34 +00:00
|
|
|
_vars[var] = value;
|
2002-03-06 10:03:00 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
if ((_varwatch == (int)var) || (_varwatch == 0)) {
|
|
|
|
if (vm.slot[_currentScript].number < 100)
|
2002-12-23 16:17:23 +00:00
|
|
|
debug(1, "vars[%d] = %d (via script-%d)", var, value, vm.slot[_currentScript].number);
|
2002-04-26 14:13:39 +00:00
|
|
|
else
|
2002-12-23 16:17:23 +00:00
|
|
|
debug(1, "vars[%d] = %d (via room-%d-%d)", var, value, _currentRoom,
|
2002-07-07 13:14:34 +00:00
|
|
|
vm.slot[_currentScript].number);
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x8000) {
|
2002-07-30 15:20:30 +00:00
|
|
|
if (_gameId == GID_ZAK256) {
|
|
|
|
// Emulate a wierd hack in Zak256 to read individual
|
|
|
|
// bits of a normal global
|
|
|
|
int b = (var & 0x000F);
|
|
|
|
var &= 0x7FFF;
|
|
|
|
var >>= 4;
|
|
|
|
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(wzb)");
|
|
|
|
if(value)
|
2003-03-06 17:58:13 +00:00
|
|
|
_vars[ var ] |= ( 1 << b );
|
2002-07-30 15:20:30 +00:00
|
|
|
else
|
|
|
|
_vars[ var ] &= ~( 1 << b );
|
|
|
|
return;
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
var &= 0x7FFF;
|
2002-07-07 13:14:34 +00:00
|
|
|
checkRange(_numBitVariables - 1, 0, var, "Bit variable %d out of range(w)");
|
2002-04-16 05:36:41 +00:00
|
|
|
|
|
|
|
/* FIXME: Enable Indy4 mousefighting by default.
|
2002-07-07 13:14:34 +00:00
|
|
|
is there a better place to put this? */
|
2002-07-07 20:25:23 +00:00
|
|
|
if (_gameId == GID_INDY4 && var == 107 && vm.slot[_currentScript].number == 1)
|
2002-04-16 05:36:41 +00:00
|
|
|
value = 1;
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (value)
|
2002-04-11 17:19:16 +00:00
|
|
|
_bitVars[var >> 3] |= (1 << (var & 7));
|
2001-10-09 14:30:12 +00:00
|
|
|
else
|
2002-04-11 17:19:16 +00:00
|
|
|
_bitVars[var >> 3] &= ~(1 << (var & 7));
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x4000) {
|
2002-11-03 15:12:39 +00:00
|
|
|
if (_gameId == GID_INDY3_256) {
|
|
|
|
var &= 0xF;
|
|
|
|
} else {
|
|
|
|
var &= 0xFFF;
|
|
|
|
}
|
|
|
|
|
2003-01-15 15:49:44 +00:00
|
|
|
checkRange(20, 0, var, "Local variable %d out of range(w)");
|
2001-11-07 18:10:52 +00:00
|
|
|
vm.localvar[_currentScript][var] = value;
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
error("Illegal varbits (w)");
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::getResultPos() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int a;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
_resultVarNumber = fetchScriptWord();
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_resultVarNumber & 0x2000) {
|
2001-10-16 10:01:48 +00:00
|
|
|
a = fetchScriptWord();
|
2002-04-11 17:19:16 +00:00
|
|
|
if (a & 0x2000) {
|
|
|
|
_resultVarNumber += readVar(a & ~0x2000);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
_resultVarNumber += a & 0xFFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
_resultVarNumber &= ~0x2000;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setResult(int value) {
|
2001-10-16 10:01:48 +00:00
|
|
|
writeVar(_resultVarNumber, value);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::push(int a) {
|
2003-03-07 23:49:59 +00:00
|
|
|
assert(_scummStackPos >= 0 && (unsigned int)_scummStackPos < ARRAYSIZE(_scummStack));
|
2002-12-16 12:12:31 +00:00
|
|
|
_scummStack[_scummStackPos++] = a;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::pop() {
|
2002-12-16 12:12:31 +00:00
|
|
|
if ((_scummStackPos < 1) || ((unsigned int)_scummStackPos > ARRAYSIZE(_scummStack))) {
|
2002-12-27 14:04:25 +00:00
|
|
|
error("No items on stack to pop() for %s (0x%X) at [%d-%d]", getOpcodeDesc(_opcode), _opcode, _roomResource, vm.slot[_currentScript].number);
|
2002-12-16 12:12:31 +00:00
|
|
|
}
|
|
|
|
|
2003-03-08 03:52:37 +00:00
|
|
|
return _scummStack[--_scummStackPos];
|
2002-12-16 12:12:31 +00:00
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
|
|
|
|
void Scumm::drawBox(int x, int y, int x2, int y2, int color) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int top, bottom, count;
|
2001-10-26 17:34:50 +00:00
|
|
|
VirtScreen *vs;
|
2001-12-04 10:44:33 +00:00
|
|
|
byte *backbuff, *bgbuff;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if ((vs = findVirtScreen(y)) == NULL)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
top = vs->topline;
|
|
|
|
bottom = top + vs->height;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (x > x2)
|
2002-04-11 17:19:16 +00:00
|
|
|
SWAP(x, x2);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (y > y2)
|
2002-04-11 17:19:16 +00:00
|
|
|
SWAP(y, y2);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
x2++;
|
|
|
|
y2++;
|
|
|
|
|
2002-10-27 09:06:20 +00:00
|
|
|
if (x > _realWidth - 1)
|
2002-04-11 17:19:16 +00:00
|
|
|
return;
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
if (x2 < 0)
|
|
|
|
return;
|
2002-09-01 15:01:40 +00:00
|
|
|
if (x2 > _realWidth)
|
|
|
|
x2 = _realWidth;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (y2 > bottom)
|
|
|
|
y2 = bottom;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
updateDirtyRect(vs->number, x, x2, y - top, y2 - top, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-09-01 15:01:40 +00:00
|
|
|
backbuff = vs->screenPtr + vs->xstart + (y - top) * _realWidth + x;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (color == -1) {
|
|
|
|
if (vs->number != 0)
|
2001-12-04 10:44:33 +00:00
|
|
|
error("can only copy bg to main window");
|
2002-09-01 15:01:40 +00:00
|
|
|
bgbuff = getResourceAddress(rtBuffer, vs->number + 5) + vs->xstart + (y - top) * _realWidth + x;
|
2001-12-04 10:44:33 +00:00
|
|
|
blit(backbuff, bgbuff, x2 - x, y2 - y);
|
|
|
|
} else {
|
|
|
|
count = y2 - y;
|
|
|
|
while (count) {
|
|
|
|
memset(backbuff, color, x2 - x);
|
2002-09-01 15:01:40 +00:00
|
|
|
backbuff += _realWidth;
|
2001-12-04 10:44:33 +00:00
|
|
|
count--;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::stopObjectCode() {
|
2001-10-16 10:01:48 +00:00
|
|
|
ScriptSlot *ss;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
ss = &vm.slot[_currentScript];
|
2002-04-05 17:18:57 +00:00
|
|
|
if (ss->cutsceneOverride == 255) { /* FIXME: What does this? */
|
|
|
|
warning("Cutscene for script %d has overflown. Resetting.", ss->number);
|
|
|
|
ss->cutsceneOverride = 0;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL) {
|
2002-04-06 03:43:54 +00:00
|
|
|
if (ss->cutsceneOverride) {
|
|
|
|
warning("Object %d ending with active cutscene/override", ss->number);
|
|
|
|
ss->cutsceneOverride = 0;
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
2002-04-06 03:43:54 +00:00
|
|
|
if (ss->cutsceneOverride) {
|
2002-07-07 20:25:23 +00:00
|
|
|
warning("Script %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
|
2002-04-06 03:43:54 +00:00
|
|
|
ss->cutsceneOverride = 0;
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
ss->number = 0;
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssDead;
|
2001-10-16 10:01:48 +00:00
|
|
|
_currentScript = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
bool Scumm::isScriptInUse(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (ss->number == script)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runHook(int i) {
|
2002-12-25 14:46:39 +00:00
|
|
|
int tmp[16];
|
2001-10-09 14:30:12 +00:00
|
|
|
tmp[0] = i;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_HOOK_SCRIPT]) {
|
|
|
|
runScript(_vars[VAR_HOOK_SCRIPT], 0, 0, tmp);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::freezeScripts(int flag) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < NUM_SCRIPT_SLOT; i++) {
|
2002-07-07 20:25:23 +00:00
|
|
|
if (_currentScript != i && vm.slot[i].status != ssDead && (vm.slot[i].unk1 == 0 || flag >= 0x80)) {
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[i].status |= 0x80;
|
|
|
|
vm.slot[i].freezeCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
2002-12-09 01:27:40 +00:00
|
|
|
_sentence[i].freezeCount++;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (vm.cutSceneScriptIndex != 0xFF) {
|
|
|
|
vm.slot[vm.cutSceneScriptIndex].status &= 0x7F;
|
|
|
|
vm.slot[vm.cutSceneScriptIndex].freezeCount = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::unfreezeScripts() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < NUM_SCRIPT_SLOT; i++) {
|
|
|
|
if (vm.slot[i].status & 0x80) {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (!--vm.slot[i].freezeCount) {
|
2002-04-11 17:19:16 +00:00
|
|
|
vm.slot[i].status &= 0x7F;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 6; i++) {
|
2002-12-09 01:27:40 +00:00
|
|
|
if (_sentence[i].freezeCount > 0)
|
|
|
|
_sentence[i].freezeCount--;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runAllScripts() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[i].didexec = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-30 02:11:33 +00:00
|
|
|
// FIXME - why is _curExecScript?!? The only place it is ever set is here.
|
|
|
|
// The outer world will only see it as consequence of the calls made in the following
|
|
|
|
// for loop. But in that case, _curExecScript will be equal to _currentScript. Hence
|
|
|
|
// it would seem we can replace all occurances of _curExecScript by _currentScript.
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = 0xFF;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (_curExecScript = 0; _curExecScript < NUM_SCRIPT_SLOT; _curExecScript++) {
|
2002-07-07 20:25:23 +00:00
|
|
|
if (vm.slot[_curExecScript].status == ssRunning && vm.slot[_curExecScript].didexec == 0) {
|
2002-02-24 17:25:03 +00:00
|
|
|
_currentScript = (char)_curExecScript;
|
2001-10-09 14:30:12 +00:00
|
|
|
getScriptBaseAddress();
|
|
|
|
getScriptEntryPoint();
|
|
|
|
executeScript();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runExitScript() {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_EXIT_SCRIPT])
|
|
|
|
runScript(_vars[VAR_EXIT_SCRIPT], 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_EXCD_offs) {
|
|
|
|
int slot = getScriptSlot();
|
2002-03-16 18:03:28 +00:00
|
|
|
vm.slot[slot].status = ssRunning;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].number = 10001;
|
2001-11-12 20:50:36 +00:00
|
|
|
vm.slot[slot].where = WIO_ROOM;
|
2001-12-27 17:51:58 +00:00
|
|
|
vm.slot[slot].offs = _EXCD_offs;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].unk1 = 0;
|
|
|
|
vm.slot[slot].unk2 = 0;
|
|
|
|
vm.slot[slot].freezeCount = 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2002-08-25 11:35:13 +00:00
|
|
|
vm.slot[slot].delayFrameCount = 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2002-11-03 10:33:50 +00:00
|
|
|
// FIXME: the exit script of room 7 in indy3 only seems to have a size and tag
|
|
|
|
// not actual data not even a 00 (stop code)
|
|
|
|
// maybe we should be limiting ourselves to strictly reading the size
|
|
|
|
// described in the header?
|
2002-11-08 18:06:08 +00:00
|
|
|
if (_gameId == GID_INDY3_256) {
|
|
|
|
// FIXME: Oddly, Indy3 seems to contain exit scripts with only a size
|
|
|
|
// and a tag - not even a terminating NULL!
|
|
|
|
byte *roomptr = getResourceAddress(rtRoom, _roomResource);
|
|
|
|
byte *excd = findResourceData(MKID('EXCD'), roomptr) - _resourceHeaderSize;
|
|
|
|
if (!excd || (getResourceDataSize(excd) < 1)) {
|
|
|
|
debug(2, "Exit-%d is empty", _roomResource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runScriptNested(slot);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_EXIT_SCRIPT2])
|
|
|
|
runScript(_vars[VAR_EXIT_SCRIPT2], 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runEntryScript() {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_ENTRY_SCRIPT])
|
|
|
|
runScript(_vars[VAR_ENTRY_SCRIPT], 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_ENCD_offs) {
|
|
|
|
int slot = getScriptSlot();
|
2002-03-16 18:03:28 +00:00
|
|
|
vm.slot[slot].status = ssRunning;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].number = 10002;
|
2001-11-12 20:50:36 +00:00
|
|
|
vm.slot[slot].where = WIO_ROOM;
|
2001-12-27 17:51:58 +00:00
|
|
|
vm.slot[slot].offs = _ENCD_offs;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].unk1 = 0;
|
|
|
|
vm.slot[slot].unk2 = 0;
|
|
|
|
vm.slot[slot].freezeCount = 0;
|
2002-08-25 11:35:13 +00:00
|
|
|
vm.slot[slot].delayFrameCount = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
runScriptNested(slot);
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_ENTRY_SCRIPT2])
|
|
|
|
runScript(_vars[VAR_ENTRY_SCRIPT2], 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::killScriptsAndResources() {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ss = &vm.slot[1];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
|
|
|
if (ss->where == WIO_ROOM || ss->where == WIO_FLOBJECT) {
|
|
|
|
if (ss->cutsceneOverride)
|
2002-07-07 20:25:23 +00:00
|
|
|
error("Object %d stopped with active cutscene/override in exit", ss->number);
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssDead;
|
2002-04-11 17:19:16 +00:00
|
|
|
} else if (ss->where == WIO_LOCAL) {
|
|
|
|
if (ss->cutsceneOverride)
|
2002-07-07 20:25:23 +00:00
|
|
|
error("Script %d stopped with active cutscene/override in exit", ss->number);
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssDead;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
/* Nuke local object names */
|
|
|
|
if (_newNames) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < _numNewNames; i++) {
|
2001-11-05 19:21:49 +00:00
|
|
|
int j = _newNames[i];
|
2001-11-26 19:57:57 +00:00
|
|
|
if (j && getOwner(j) == 0) {
|
2001-11-05 19:21:49 +00:00
|
|
|
_newNames[i] = 0;
|
|
|
|
nukeResource(rtObjectName, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::killAllScriptsExceptCurrent() {
|
2002-12-25 20:29:40 +00:00
|
|
|
for (int i = 1; i < NUM_SCRIPT_SLOT; i++) {
|
|
|
|
if (i != _currentScript)
|
|
|
|
vm.slot[i].status = ssDead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::doSentence(int c, int b, int a) {
|
2003-01-01 18:22:41 +00:00
|
|
|
SentenceTab *st;
|
|
|
|
|
|
|
|
if (_features & GF_AFTER_V7) {
|
|
|
|
|
|
|
|
if (b == a)
|
|
|
|
return;
|
|
|
|
|
|
|
|
st = &_sentence[_sentenceNum - 1];
|
|
|
|
|
|
|
|
|
|
|
|
// Check if this doSentence request is identical to the previous one;
|
|
|
|
// if yes, ignore this invocation.
|
|
|
|
if (_sentenceNum && st->unk5 == c && st->unk4 == b && st->unk3 == a)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_sentenceNum++;
|
|
|
|
st++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
st = &_sentence[_sentenceNum++];
|
|
|
|
|
|
|
|
if (!(st->unk3 & 0xFF00))
|
|
|
|
st->unk2 = 0;
|
|
|
|
else
|
|
|
|
st->unk2 = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
st->unk5 = c;
|
|
|
|
st->unk4 = b;
|
|
|
|
st->unk3 = a;
|
|
|
|
st->freezeCount = 0;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::checkAndRunSentenceScript() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
ScriptSlot *ss;
|
|
|
|
|
|
|
|
memset(_localParamList, 0, sizeof(_localParamList));
|
2001-11-05 19:21:49 +00:00
|
|
|
if (isScriptInUse(_vars[VAR_SENTENCE_SCRIPT])) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
|
2002-12-09 01:27:40 +00:00
|
|
|
if (ss->number == _vars[VAR_SENTENCE_SCRIPT] && ss->status != ssDead && ss->freezeCount == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-09 01:27:40 +00:00
|
|
|
if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
|
|
|
_sentenceNum--;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(_features & GF_AFTER_V7))
|
2002-09-22 01:17:53 +00:00
|
|
|
if (_sentence[_sentenceNum].unk2 && _sentence[_sentenceNum].unk3 == _sentence[_sentenceNum].unk4)
|
2002-03-05 23:41:41 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-09-22 01:17:53 +00:00
|
|
|
_localParamList[0] = _sentence[_sentenceNum].unk5;
|
|
|
|
_localParamList[1] = _sentence[_sentenceNum].unk4;
|
|
|
|
_localParamList[2] = _sentence[_sentenceNum].unk3;
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = 0xFF;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_SENTENCE_SCRIPT])
|
|
|
|
runScript(_vars[VAR_SENTENCE_SCRIPT], 0, 0, _localParamList);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runInputScript(int a, int cmd, int mode) {
|
2002-12-25 14:46:39 +00:00
|
|
|
int args[16];
|
2001-11-26 19:57:57 +00:00
|
|
|
memset(args, 0, sizeof(args));
|
|
|
|
args[0] = a;
|
|
|
|
args[1] = cmd;
|
|
|
|
args[2] = mode;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_vars[VAR_VERB_SCRIPT])
|
2001-11-26 19:57:57 +00:00
|
|
|
runScript(_vars[VAR_VERB_SCRIPT], 0, 0, args);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::decreaseScriptDelay(int amount) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss = &vm.slot[0];
|
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
2002-12-09 01:27:40 +00:00
|
|
|
if (ss->status == ssPaused) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ss->delay -= amount;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ss->delay < 0) {
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssRunning;
|
2001-10-09 14:30:12 +00:00
|
|
|
ss->delay = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::runVerbCode(int object, int entry, int a, int b, int *vars) {
|
2001-10-09 14:30:12 +00:00
|
|
|
uint32 obcd;
|
2001-11-07 18:10:52 +00:00
|
|
|
int slot, where, offs;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!b)
|
2001-10-09 14:30:12 +00:00
|
|
|
stopObjectScript(object);
|
|
|
|
|
|
|
|
where = whereIsObject(object);
|
|
|
|
|
2001-11-12 20:50:36 +00:00
|
|
|
if (where == WIO_NOT_FOUND) {
|
2002-05-06 17:46:32 +00:00
|
|
|
warning("Code for object %d not in room %d", object, _roomResource);
|
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
obcd = getOBCDOffs(object);
|
|
|
|
slot = getScriptSlot();
|
|
|
|
|
|
|
|
offs = getVerbEntrypoint(object, entry);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (offs == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
vm.slot[slot].number = object;
|
|
|
|
vm.slot[slot].offs = obcd + offs;
|
2002-03-16 18:03:28 +00:00
|
|
|
vm.slot[slot].status = ssRunning;
|
2001-11-12 20:50:36 +00:00
|
|
|
vm.slot[slot].where = where;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].unk1 = a;
|
|
|
|
vm.slot[slot].unk2 = b;
|
|
|
|
vm.slot[slot].freezeCount = 0;
|
2002-08-25 11:35:13 +00:00
|
|
|
vm.slot[slot].delayFrameCount = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
initializeLocals(slot, vars);
|
|
|
|
|
|
|
|
runScriptNested(slot);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::initializeLocals(int slot, int *vars) {
|
2001-11-07 18:10:52 +00:00
|
|
|
int i;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (!vars) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
2001-11-07 18:10:52 +00:00
|
|
|
vm.localvar[slot][i] = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
2001-11-07 18:10:52 +00:00
|
|
|
vm.localvar[slot][i] = vars[i];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getVerbEntrypoint(int obj, int entry) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *objptr, *verbptr;
|
|
|
|
int verboffs;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (whereIsObject(obj) == WIO_NOT_FOUND)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
objptr = getOBCDFromObject(obj);
|
2001-11-06 21:29:23 +00:00
|
|
|
assert(objptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
verbptr = objptr + 19;
|
|
|
|
else
|
|
|
|
verbptr = findResource(MKID('VERB'), objptr);
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-12-26 20:37:49 +00:00
|
|
|
assert(verbptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
verboffs = verbptr - objptr;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(_features & GF_SMALL_HEADER))
|
|
|
|
verbptr += _resourceHeaderSize;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-12-27 15:11:43 +00:00
|
|
|
if (_features & GF_AFTER_V8) {
|
|
|
|
uint32 *ptr = (uint32 *)verbptr;
|
|
|
|
uint32 verb;
|
|
|
|
do {
|
|
|
|
verb = READ_LE_UINT32(ptr);
|
|
|
|
if (!verb)
|
|
|
|
return 0;
|
|
|
|
if (verb == (uint32)entry || verb == 0xFFFFFFFF)
|
|
|
|
break;
|
|
|
|
ptr += 2;
|
|
|
|
} while (1);
|
|
|
|
return verboffs + 8 + READ_LE_UINT32(ptr + 1);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (!*verbptr)
|
|
|
|
return 0;
|
|
|
|
if (*verbptr == entry || *verbptr == 0xFF)
|
|
|
|
break;
|
|
|
|
verbptr += 3;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
return READ_LE_UINT16(verbptr + 1);
|
|
|
|
else
|
|
|
|
return verboffs + READ_LE_UINT16(verbptr + 1);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
bool Scumm::isScriptRunning(int script) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int i;
|
|
|
|
ScriptSlot *ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
|
2002-12-09 01:27:40 +00:00
|
|
|
if (ss->number == script && (ss->where == WIO_GLOBAL || ss->where == WIO_LOCAL) && ss->status != ssDead)
|
2001-11-26 19:57:57 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
bool Scumm::isRoomScriptRunning(int script) {
|
2001-11-26 19:57:57 +00:00
|
|
|
int i;
|
|
|
|
ScriptSlot *ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
|
2002-12-09 01:27:40 +00:00
|
|
|
if (ss->number == script && ss->where == WIO_ROOM && ss->status != ssDead)
|
2001-11-26 19:57:57 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::defineArray(int array, int type, int dim2, int dim1) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int id;
|
|
|
|
int size;
|
|
|
|
ArrayHeader *ah;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (type != 5 && type != 4)
|
|
|
|
type = 5;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
nukeArray(array);
|
|
|
|
|
|
|
|
id = getArrayId();
|
|
|
|
|
2002-12-23 00:23:36 +00:00
|
|
|
if (_features & GF_AFTER_V8) {
|
2002-12-25 14:46:39 +00:00
|
|
|
if (array & 0x40000000) {
|
|
|
|
_arrays[id] = (char)vm.slot[_currentScript].number;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array & 0x80000000) {
|
|
|
|
error("Can't define bit variable as array pointer");
|
|
|
|
}
|
|
|
|
|
2002-12-23 16:17:23 +00:00
|
|
|
size = (type == 5) ? 32 : 8;
|
2002-12-23 00:23:36 +00:00
|
|
|
} else {
|
2002-12-25 14:46:39 +00:00
|
|
|
if (array & 0x4000) {
|
|
|
|
_arrays[id] = (char)vm.slot[_currentScript].number;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array & 0x8000) {
|
|
|
|
error("Can't define bit variable as array pointer");
|
|
|
|
}
|
|
|
|
|
2002-12-23 00:23:36 +00:00
|
|
|
size = (type == 5) ? 16 : 8;
|
|
|
|
}
|
2002-12-25 14:46:39 +00:00
|
|
|
|
|
|
|
writeVar(array, id);
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
size *= dim2 + 1;
|
|
|
|
size *= dim1 + 1;
|
2001-10-16 10:01:48 +00:00
|
|
|
size >>= 3;
|
|
|
|
|
2002-07-07 13:14:34 +00:00
|
|
|
ah = (ArrayHeader *)createResource(rtString, id, size + sizeof(ArrayHeader));
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
ah->type = type;
|
2002-04-11 17:19:16 +00:00
|
|
|
ah->dim1_size = dim1 + 1;
|
|
|
|
ah->dim2_size = dim2 + 1;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::nukeArray(int a) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int data;
|
|
|
|
|
|
|
|
data = readVar(a);
|
|
|
|
|
|
|
|
if (data)
|
2001-11-05 19:21:49 +00:00
|
|
|
nukeResource(rtString, data);
|
2001-10-16 10:01:48 +00:00
|
|
|
_arrays[data] = 0;
|
|
|
|
|
|
|
|
writeVar(a, 0);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getArrayId() {
|
2001-10-16 10:01:48 +00:00
|
|
|
byte **addr = _baseArrays;
|
|
|
|
int i;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < _numArray; i++) {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (!addr[i])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
error("Out of array pointers, %d max", _numArray);
|
2002-05-05 18:10:29 +00:00
|
|
|
return -1;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::copyScriptString(byte *dst) {
|
2002-12-28 01:57:19 +00:00
|
|
|
int len = resStrLen(_scriptPointer) + 1;
|
|
|
|
while (len--)
|
|
|
|
*dst++ = fetchScriptByte();
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2002-12-28 01:57:19 +00:00
|
|
|
//
|
|
|
|
// Given a pointer to a Scumm string, this function returns the total byte length
|
|
|
|
// of the string data in that resource. To do so it has to understand certain
|
|
|
|
// special characters embedded into the string. The reason for this function is that
|
|
|
|
// sometimes this embedded data contains zero bytes, thus we can't just use strlen.
|
|
|
|
//
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::resStrLen(const byte *src) const {
|
2002-12-28 01:57:19 +00:00
|
|
|
int num = 0;
|
|
|
|
byte chr;
|
|
|
|
if (src == NULL)
|
|
|
|
src = _scriptPointer;
|
|
|
|
while ((chr = *src++) != 0) {
|
|
|
|
num++;
|
|
|
|
if (chr == 255) {
|
|
|
|
chr = *src++;
|
|
|
|
num++;
|
|
|
|
|
|
|
|
if (chr != 1 && chr != 2 && chr != 3 && chr != 8) {
|
|
|
|
if (_features & GF_AFTER_V8) {
|
|
|
|
src += 4;
|
|
|
|
num += 4;
|
|
|
|
} else {
|
|
|
|
src += 2;
|
|
|
|
num += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
2001-11-09 18:54:15 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::cutscene(int *args) {
|
2003-01-01 18:22:41 +00:00
|
|
|
int scr = _currentScript;
|
|
|
|
vm.slot[scr].cutsceneOverride++;
|
|
|
|
|
|
|
|
if (++vm.cutSceneStackPointer > sizeof(vm.cutSceneData) / sizeof(vm.cutSceneData[0]))
|
|
|
|
error("Cutscene stack overflow");
|
|
|
|
|
|
|
|
vm.cutSceneData[vm.cutSceneStackPointer] = args[0];
|
|
|
|
vm.cutSceneScript[vm.cutSceneStackPointer] = 0;
|
|
|
|
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
|
|
|
|
|
|
|
|
vm.cutSceneScriptIndex = scr;
|
|
|
|
if (_vars[VAR_CUTSCENE_START_SCRIPT])
|
|
|
|
runScript(_vars[VAR_CUTSCENE_START_SCRIPT], 0, 0, args);
|
|
|
|
vm.cutSceneScriptIndex = 0xFF;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::endCutscene() {
|
2003-01-01 18:22:41 +00:00
|
|
|
ScriptSlot *ss = &vm.slot[_currentScript];
|
|
|
|
int args[16];
|
|
|
|
|
|
|
|
memset(args, 0, sizeof(args));
|
|
|
|
|
|
|
|
if (ss->cutsceneOverride > 0) // Only terminate if active
|
|
|
|
ss->cutsceneOverride--;
|
|
|
|
|
|
|
|
args[0] = vm.cutSceneData[vm.cutSceneStackPointer];
|
|
|
|
_vars[VAR_OVERRIDE] = 0;
|
|
|
|
|
|
|
|
if (vm.cutScenePtr[vm.cutSceneStackPointer] && (ss->cutsceneOverride > 0)) // Only terminate if active
|
|
|
|
ss->cutsceneOverride--;
|
|
|
|
|
|
|
|
vm.cutSceneScript[vm.cutSceneStackPointer] = 0;
|
|
|
|
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
|
|
|
|
vm.cutSceneStackPointer--;
|
|
|
|
|
|
|
|
if (_vars[VAR_CUTSCENE_END_SCRIPT])
|
|
|
|
runScript(_vars[VAR_CUTSCENE_END_SCRIPT], 0, 0, args);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::exitCutscene() {
|
2001-11-09 18:54:15 +00:00
|
|
|
uint32 offs = vm.cutScenePtr[vm.cutSceneStackPointer];
|
|
|
|
if (offs) {
|
|
|
|
ScriptSlot *ss = &vm.slot[vm.cutSceneScript[vm.cutSceneStackPointer]];
|
|
|
|
ss->offs = offs;
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssRunning;
|
2001-11-09 18:54:15 +00:00
|
|
|
ss->freezeCount = 0;
|
2002-04-05 16:41:02 +00:00
|
|
|
|
|
|
|
if (ss->cutsceneOverride > 0)
|
2002-04-11 17:19:16 +00:00
|
|
|
ss->cutsceneOverride--;
|
2002-04-05 16:41:02 +00:00
|
|
|
|
2001-11-09 18:54:15 +00:00
|
|
|
_vars[VAR_OVERRIDE] = 1;
|
|
|
|
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::beginOverride() {
|
2003-01-01 18:22:41 +00:00
|
|
|
int idx;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
idx = vm.cutSceneStackPointer;
|
|
|
|
assert(idx < 5);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
vm.cutScenePtr[idx] = _scriptPointer - _scriptOrgPointer;
|
|
|
|
vm.cutSceneScript[idx] = _currentScript;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
// Skip the jump instruction following the override instruction
|
|
|
|
// (the jump is responsible for "skipping" cutscenes, and the reason
|
|
|
|
// why we record the current script position in vm.cutScenePtr).
|
|
|
|
fetchScriptByte();
|
|
|
|
fetchScriptWord();
|
|
|
|
_vars[VAR_OVERRIDE] = 0;
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::endOverride() {
|
2003-01-01 18:22:41 +00:00
|
|
|
int idx;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
idx = vm.cutSceneStackPointer;
|
|
|
|
assert(idx < 5);
|
2002-09-22 01:17:53 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
vm.cutScenePtr[idx] = 0;
|
|
|
|
vm.cutSceneScript[idx] = 0;
|
|
|
|
_vars[VAR_OVERRIDE] = 0;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|