2009-02-17 15:05:16 +00:00
|
|
|
/* 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$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-24 15:33:40 +00:00
|
|
|
#ifndef SCI_ENGINE_VM_H
|
|
|
|
#define SCI_ENGINE_VM_H
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 19:54:15 +00:00
|
|
|
/* VM and kernel declarations */
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-27 02:23:00 +00:00
|
|
|
#include "sci/engine/vm_types.h" // for reg_t
|
2009-08-17 05:55:21 +00:00
|
|
|
#include "sci/resource.h" // for SciVersion
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-04 16:52:13 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-05-08 09:53:49 +00:00
|
|
|
class SegManager;
|
2009-05-14 12:38:50 +00:00
|
|
|
struct EngineState;
|
2009-10-10 15:58:51 +00:00
|
|
|
class Object;
|
2009-08-17 05:55:21 +00:00
|
|
|
class ResourceManager;
|
2009-02-26 23:03:35 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Number of bytes to be allocated for the stack */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define VM_STACK_SIZE 0x1000
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Maximum number of calls residing on the stack */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_MAX_EXEC_STACK 256
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Maximum number of entries in the class table */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_MAX_CLASSTABLE_SIZE 256
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Maximum number of cloned objects on the heap */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_MAX_CLONES 256
|
|
|
|
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Object-relative offset of the selector area inside a script */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_SELECTOR_OFFSET 8 -8
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Object-relative offset of the pointer to the underlying script's local variables */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_LOCALVARPTR_OFFSET 2 -8
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Object-relative offset of the selector counter */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_SELECTORCTR_OFFSET 6 -8
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Object-relative offset of the offset of the function area */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_FUNCTAREAPTR_OFFSET 4 -8
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Offset that has to be added to the function area pointer */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_FUNCTAREAPTR_MAGIC 8 -8
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Offset of the name pointer */
|
2009-09-17 16:50:53 +00:00
|
|
|
#define SCRIPT_NAME_OFFSET (getSciVersion() < SCI_VERSION_1_1 ? 14 -8 : 16)
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Object-relative offset of the -info- selector */
|
2009-09-17 16:50:53 +00:00
|
|
|
#define SCRIPT_INFO_OFFSET (getSciVersion() < SCI_VERSION_1_1 ? 12 -8 : 14)
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Flag fo the -info- selector */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_INFO_CLONE 0x0001
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Flag for the -info- selector */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_INFO_CLASS 0x8000
|
|
|
|
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Magical object identifier */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_OBJECT_MAGIC_NUMBER 0x1234
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Offset of this identifier */
|
2009-09-17 16:50:53 +00:00
|
|
|
#define SCRIPT_OBJECT_MAGIC_OFFSET (getSciVersion() < SCI_VERSION_1_1 ? -8 : 0)
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Script-relative offset of the species ID */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_SPECIES_OFFSET 8 -8
|
|
|
|
|
2009-09-17 16:50:53 +00:00
|
|
|
#define SCRIPT_SUPERCLASS_OFFSET (getSciVersion() < SCI_VERSION_1_1 ? 10 -8 : 12)
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Magic adjustment value for lofsa and lofss */
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCRIPT_LOFS_MAGIC 3
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Stack pointer value: Use predecessor's value */
|
|
|
|
#define CALL_SP_CARRY NULL
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Types of selectors as returned by lookup_selector() below. */
|
2009-02-28 11:12:59 +00:00
|
|
|
enum SelectorType {
|
|
|
|
kSelectorNone = 0,
|
|
|
|
kSelectorVariable,
|
|
|
|
kSelectorMethod
|
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
struct Class {
|
2009-11-20 22:41:17 +00:00
|
|
|
int script; ///< number of the script the class is in, -1 for non-existing
|
|
|
|
reg_t reg; ///< offset; script-relative offset, segment: 0 if not instantiated
|
2009-02-21 22:06:42 +00:00
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-03-07 16:14:20 +00:00
|
|
|
#define RAW_IS_OBJECT(datablock) (READ_LE_UINT16(((byte *) datablock) + SCRIPT_OBJECT_MAGIC_OFFSET) == SCRIPT_OBJECT_MAGIC_NUMBER)
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Contains selector IDs for a few selected selectors */
|
2009-09-17 13:21:42 +00:00
|
|
|
struct SelectorCache {
|
|
|
|
SelectorCache() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
2009-11-20 13:29:42 +00:00
|
|
|
// Statically defined selectors, (almost the) same in all SCI versions
|
|
|
|
Selector y;
|
|
|
|
Selector x;
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector view, loop, cel; ///< Description of a specific image
|
|
|
|
Selector underBits; ///< Used by the graphics subroutines to store backupped BG pic data
|
|
|
|
Selector nsTop, nsLeft, nsBottom, nsRight; ///< View boundaries ('now seen')
|
|
|
|
Selector lsTop, lsLeft, lsBottom, lsRight; ///< Used by Animate() subfunctions and scroll list controls
|
|
|
|
Selector signal; ///< Used by Animate() to control a view's behaviour
|
|
|
|
Selector illegalBits; ///< Used by CanBeHere
|
|
|
|
Selector brTop, brLeft, brBottom, brRight; ///< Bounding Rectangle
|
2009-11-20 13:29:42 +00:00
|
|
|
// name, key, time
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector text; ///< Used by controls
|
|
|
|
Selector elements; ///< Used by SetSynonyms()
|
2009-11-20 13:29:42 +00:00
|
|
|
// color, back
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector mode; ///< Used by text controls (-> DrawControl())
|
2009-11-20 13:29:42 +00:00
|
|
|
// style
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector state, font, type;///< Used by controls
|
2009-11-20 13:29:42 +00:00
|
|
|
// window
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector cursor, max; ///< Used by EditControl
|
2009-11-20 13:29:42 +00:00
|
|
|
// mark, who
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector message; ///< Used by GetEvent
|
2009-11-20 13:29:42 +00:00
|
|
|
// edit
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector play; ///< Play function (first function to be called)
|
2009-02-28 11:12:59 +00:00
|
|
|
Selector number;
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector handle; ///< Replaced by nodePtr in SCI1+
|
|
|
|
Selector nodePtr; ///< Replaces handle in SCI1+
|
|
|
|
Selector client; ///< The object that wants to be moved
|
|
|
|
Selector dx, dy; ///< Deltas
|
|
|
|
Selector b_movCnt, b_i1, b_i2, b_di, b_xAxis, b_incr; ///< Various Bresenham vars
|
|
|
|
Selector xStep, yStep; ///< BR adjustments
|
|
|
|
Selector moveSpeed; ///< Used for DoBresen
|
|
|
|
Selector canBeHere; ///< Funcselector: Checks for movement validity in SCI0
|
|
|
|
Selector heading, mover; ///< Used in DoAvoider
|
|
|
|
Selector doit; ///< Called (!) by the Animate() system call
|
|
|
|
Selector isBlocked, looper; ///< Used in DoAvoider
|
2009-11-20 13:29:42 +00:00
|
|
|
Selector priority;
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector modifiers; ///< Used by GetEvent
|
|
|
|
Selector replay; ///< Replay function
|
2009-11-20 13:29:42 +00:00
|
|
|
// setPri, at, next, done, width
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector wordFail, syntaxFail; ///< Used by Parse()
|
2009-11-20 13:29:42 +00:00
|
|
|
// semanticFail, pragmaFail
|
|
|
|
// said
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector claimed; ///< Used generally by the event mechanism
|
2009-11-20 13:29:42 +00:00
|
|
|
// value, save, restore, title, button, icon, draw
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector delete_; ///< Called by Animate() to dispose a view object
|
2009-11-20 13:29:42 +00:00
|
|
|
Selector z;
|
|
|
|
|
|
|
|
// SCI1+ static selectors
|
|
|
|
Selector parseLang;
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector printLang; ///< Used for i18n
|
2009-11-20 13:29:42 +00:00
|
|
|
Selector subtitleLang;
|
|
|
|
Selector size;
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector points; ///< Used by AvoidPath()
|
2009-11-20 13:29:42 +00:00
|
|
|
Selector palette;
|
|
|
|
Selector dataInc;
|
|
|
|
// handle (in SCI1)
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector min; ///< SMPTE time format
|
2009-02-28 11:12:59 +00:00
|
|
|
Selector sec;
|
|
|
|
Selector frame;
|
2009-11-20 13:29:42 +00:00
|
|
|
Selector vol;
|
|
|
|
Selector pri;
|
|
|
|
// perform
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector moveDone; ///< used for DoBresen
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-11-20 13:29:42 +00:00
|
|
|
// SCI1 selectors which have been moved a bit in SCI1.1, but otherwise static
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector cantBeHere; ///< Checks for movement avoidance in SCI1+. Replaces canBeHere
|
|
|
|
Selector topString; ///< SCI1 scroll lists use this instead of lsTop
|
2009-02-28 11:12:59 +00:00
|
|
|
Selector flags;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-11-20 20:30:31 +00:00
|
|
|
// SCI1+ audio sync related selectors, not static. They're used for lip syncing in
|
|
|
|
// CD talkie games
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector syncCue; ///< Used by DoSync()
|
2009-06-24 19:12:45 +00:00
|
|
|
Selector syncTime;
|
|
|
|
|
2009-11-20 13:29:42 +00:00
|
|
|
// SCI1.1 specific selectors
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector scaleX, scaleY; ///< SCI1.1 view scaling
|
2009-08-30 01:37:52 +00:00
|
|
|
|
2009-11-20 13:29:42 +00:00
|
|
|
// Used for auto detection purposes
|
2009-11-20 22:41:17 +00:00
|
|
|
Selector overlay; ///< Used to determine if a game is using old gfx functions or not
|
|
|
|
Selector setCursor; ///< For cursor semantics autodetection
|
2009-12-21 14:32:54 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
Selector data; // Used by Array()
|
|
|
|
#endif
|
2009-05-03 09:19:21 +00:00
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-06 11:38:20 +00:00
|
|
|
// A reference to an object's variable.
|
|
|
|
// The object is stored as a reg_t, the variable as an index into _variables
|
|
|
|
struct ObjVarRef {
|
|
|
|
reg_t obj;
|
|
|
|
int varindex;
|
|
|
|
|
2009-09-06 12:57:42 +00:00
|
|
|
reg_t* getPointer(SegManager *segMan) const;
|
2009-06-06 11:38:20 +00:00
|
|
|
};
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
enum ExecStackType {
|
|
|
|
EXEC_STACK_TYPE_CALL = 0,
|
|
|
|
EXEC_STACK_TYPE_KERNEL = 1,
|
|
|
|
EXEC_STACK_TYPE_VARSELECTOR = 2
|
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
struct ExecStack {
|
2009-11-20 22:41:17 +00:00
|
|
|
reg_t objp; ///< Pointer to the beginning of the current object
|
|
|
|
reg_t sendp; ///< Pointer to the object containing the invoked method
|
2009-06-06 11:38:20 +00:00
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
union {
|
2009-07-08 10:25:37 +00:00
|
|
|
ObjVarRef varp; // Variable pointer for r/w access
|
|
|
|
reg_t pc; // Pointer to the initial program counter. Not accurate for the TOS element
|
2009-02-15 06:10:59 +00:00
|
|
|
} addr;
|
2009-06-06 11:38:20 +00:00
|
|
|
|
2009-07-08 10:25:37 +00:00
|
|
|
StackPtr fp; // Frame pointer
|
|
|
|
StackPtr sp; // Stack pointer
|
2009-02-15 06:10:59 +00:00
|
|
|
int argc;
|
|
|
|
|
2009-07-08 10:25:37 +00:00
|
|
|
StackPtr variables_argp; // Argument pointer
|
|
|
|
SegmentId local_segment; // local variables etc
|
2009-05-03 09:19:21 +00:00
|
|
|
|
2009-07-08 10:25:37 +00:00
|
|
|
Selector selector; // The selector which was used to call or -1 if not applicable
|
|
|
|
int origin; // The stack frame position the call was made from, or -1 if it was the initial call
|
2009-05-03 09:19:21 +00:00
|
|
|
ExecStackType type;
|
2009-06-06 11:38:20 +00:00
|
|
|
|
2009-09-06 12:57:42 +00:00
|
|
|
reg_t* getVarPointer(SegManager *segMan) const;
|
2009-05-03 09:19:21 +00:00
|
|
|
};
|
|
|
|
|
2009-09-17 13:21:19 +00:00
|
|
|
enum {
|
|
|
|
VAR_GLOBAL = 0,
|
|
|
|
VAR_LOCAL = 1,
|
|
|
|
VAR_TEMP = 2,
|
|
|
|
VAR_PARAM = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure for storing the current internal state of the VM.
|
|
|
|
*/
|
|
|
|
struct ScriptState {
|
|
|
|
ExecStack *xs;
|
|
|
|
int16 restAdjust;
|
2009-11-20 22:41:17 +00:00
|
|
|
reg_t *variables[4]; ///< global, local, temp, param, as immediate pointers
|
|
|
|
reg_t *variables_base[4]; ///< Used for referencing VM ops
|
|
|
|
SegmentId variables_seg[4]; ///< Same as above, contains segment IDs
|
|
|
|
int variables_max[4]; ///< Max. values for all variables
|
2009-09-17 13:21:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current internal state of the VM.
|
|
|
|
*/
|
|
|
|
extern ScriptState scriptState;
|
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-07-18 22:46:07 +00:00
|
|
|
// These types are used both as identifiers and as elements of bitfields
|
2009-05-03 09:19:21 +00:00
|
|
|
enum BreakpointType {
|
|
|
|
/**
|
|
|
|
* Break when selector is executed. data contains (char *) selector name
|
|
|
|
* (in the format Object::Method)
|
|
|
|
*/
|
2009-07-18 22:46:07 +00:00
|
|
|
BREAK_SELECTOR = 1,
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/**
|
|
|
|
* Break when an exported function is called. data contains
|
|
|
|
* script_no << 16 | export_no.
|
|
|
|
*/
|
2009-07-18 22:46:07 +00:00
|
|
|
BREAK_EXPORT = 2
|
2009-02-21 22:06:42 +00:00
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
struct Breakpoint {
|
2009-05-03 09:19:21 +00:00
|
|
|
BreakpointType type;
|
2009-02-15 06:10:59 +00:00
|
|
|
union {
|
2009-11-20 22:41:17 +00:00
|
|
|
uint32 address; ///< Breakpoints on exports
|
|
|
|
char *name; ///< Breakpoints on selector names
|
2009-02-15 06:10:59 +00:00
|
|
|
} data;
|
2009-02-28 11:12:59 +00:00
|
|
|
Breakpoint *next;
|
2009-02-21 22:06:42 +00:00
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/**
|
2009-06-18 22:09:57 +00:00
|
|
|
* Set this to 1 to abort script execution immediately. Aborting will
|
|
|
|
* leave the debug exec stack intact.
|
2009-06-05 19:04:14 +00:00
|
|
|
* Set it to 2 to force a replay afterwards.
|
2009-05-03 09:19:21 +00:00
|
|
|
*/
|
2009-02-15 10:33:31 +00:00
|
|
|
extern int script_abort_flag;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Number of kernel calls in between gcs; should be < 50000 */
|
2009-06-04 11:44:55 +00:00
|
|
|
enum {
|
|
|
|
GC_INTERVAL = 32768
|
|
|
|
};
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Initially GC_DELAY, can be set at runtime */
|
2009-02-15 06:10:59 +00:00
|
|
|
extern int script_gc_interval;
|
|
|
|
|
2009-05-03 09:19:21 +00:00
|
|
|
/** Number of steps executed */
|
2009-02-15 06:10:59 +00:00
|
|
|
extern int script_step_counter;
|
|
|
|
|
|
|
|
|
2009-05-18 18:15:45 +00:00
|
|
|
/**
|
|
|
|
* Executes function pubfunct of the specified script.
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param[in] s The state which is to be executed with
|
|
|
|
* @param[in] script The script which is called
|
|
|
|
* @param[in] pubfunct The exported script function which is to
|
|
|
|
* be called
|
|
|
|
* @param[in] sp Stack pointer position
|
|
|
|
* @param[in] calling_obj The heap address of the object that
|
|
|
|
* executed the call
|
|
|
|
* @param[in] argc Number of arguments supplied
|
|
|
|
* @param[in] argp Pointer to the first supplied argument
|
|
|
|
* @return A pointer to the new exec stack TOS entry
|
2009-05-18 18:15:45 +00:00
|
|
|
*/
|
2009-06-18 22:09:57 +00:00
|
|
|
ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct,
|
|
|
|
StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
|
2009-05-18 18:15:45 +00:00
|
|
|
/**
|
|
|
|
* Executes a "send" or related operation to a selector.
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param[in] s The EngineState to operate on
|
|
|
|
* @param[in] send_obj Heap address of the object to send to
|
|
|
|
* @param[in] work_obj Heap address of the object initiating the send
|
|
|
|
* @param[in] sp Stack pointer position
|
|
|
|
* @param[in] framesize Size of the send as determined by the "send"
|
|
|
|
* operation
|
|
|
|
* @param[in] argp Pointer to the beginning of the heap block
|
|
|
|
* containing the data to be sent. This area is a
|
|
|
|
* succession of one or more sequences of
|
|
|
|
* [selector_number][argument_counter] and then
|
|
|
|
* "argument_counter" word entries with the
|
|
|
|
* parameter values.
|
|
|
|
* @return A pointer to the new execution stack TOS entry
|
2009-05-18 18:15:45 +00:00
|
|
|
*/
|
2009-02-28 11:12:59 +00:00
|
|
|
ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj,
|
|
|
|
StackPtr sp, int framesize, StackPtr argp);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
|
2009-09-06 12:58:16 +00:00
|
|
|
#define SCI_XS_CALLEE_LOCALS ((SegmentId)-1)
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-18 18:15:45 +00:00
|
|
|
/**
|
|
|
|
* Adds an entry to the top of the execution stack.
|
|
|
|
*
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param[in] s The state with which to execute
|
|
|
|
* @param[in] pc The initial program counter
|
|
|
|
* @param[in] sp The initial stack pointer
|
|
|
|
* @param[in] objp Pointer to the beginning of the current object
|
|
|
|
* @param[in] argc Number of parameters to call with
|
|
|
|
* @param[in] argp Heap pointer to the first parameter
|
|
|
|
* @param[in] selector The selector by which it was called or
|
|
|
|
* NULL_SELECTOR if n.a. For debugging.
|
|
|
|
* @param[in] sendp Pointer to the object which the message was
|
|
|
|
* sent to. Equal to objp for anything but super.
|
|
|
|
* @param[in] origin Number of the execution stack element this
|
|
|
|
* entry was created by (usually the current TOS
|
|
|
|
* number, except for multiple sends).
|
|
|
|
* @param[in] local_segment The segment to use for local variables,
|
|
|
|
* or SCI_XS_CALLEE_LOCALS to use obj's segment.
|
|
|
|
* @return A pointer to the new exec stack TOS entry
|
|
|
|
*/
|
|
|
|
ExecStack *add_exec_stack_entry(EngineState *s, reg_t pc, StackPtr sp,
|
|
|
|
reg_t objp, int argc, StackPtr argp, Selector selector,
|
|
|
|
reg_t sendp, int origin, SegmentId local_segment);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
|
2009-05-18 18:15:45 +00:00
|
|
|
/**
|
|
|
|
* Adds one varselector access to the execution stack.
|
|
|
|
* This function is called from send_selector only.
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param[in] s The EngineState to use
|
|
|
|
* @param[in] objp Pointer to the object owning the selector
|
|
|
|
* @param[in] argc 1 for writing, 0 for reading
|
|
|
|
* @param[in] argp Pointer to the address of the data to write -2
|
|
|
|
* @param[in] selector Selector name
|
|
|
|
* @param[in] address Heap address of the selector
|
|
|
|
* @param[in] origin Stack frame which the access originated from
|
|
|
|
* @return Pointer to the new exec-TOS element
|
2009-05-18 18:15:45 +00:00
|
|
|
*/
|
2009-06-18 22:09:57 +00:00
|
|
|
ExecStack *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc,
|
|
|
|
StackPtr argp, Selector selector, const ObjVarRef& address,
|
|
|
|
int origin);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* This function executes SCI bytecode
|
|
|
|
* It executes the code on s->heap[pc] until it hits a 'ret' operation
|
|
|
|
* while (stack_base == stack_pos). Requires s to be set up correctly.
|
|
|
|
* @param[in] s The state to use
|
|
|
|
* @param[in] restoring 1 if s has just been restored, 0 otherwise
|
|
|
|
*/
|
2009-02-21 10:47:56 +00:00
|
|
|
void run_vm(EngineState *s, int restoring);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Debugger functionality
|
2009-07-08 10:25:37 +00:00
|
|
|
* @param[in] s The state at which debugging should take place
|
|
|
|
* @param[in] bp Flag, set to true when a breakpoint is triggered
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-07-08 10:25:37 +00:00
|
|
|
void script_debug(EngineState *s, bool bp);
|
2009-06-18 22:09:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a EngineState block
|
|
|
|
* @param[in] s The state to initialize
|
|
|
|
* @return 0 on success, 1 if vocab.996 (the class table) is missing
|
|
|
|
* or corrupted
|
|
|
|
*/
|
2009-07-11 23:45:54 +00:00
|
|
|
int script_init_engine(EngineState *);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Looks up a selector and returns its type and value
|
|
|
|
* varindex is written to iff it is non-NULL and the selector indicates a property of the object.
|
2009-09-06 12:57:42 +00:00
|
|
|
* @param[in] segMan The Segment Manager
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param[in] obj Address of the object to look the selector up in
|
|
|
|
* @param[in] selectorid The selector to look up
|
|
|
|
* @param[out] varp A reference to the selector, if it is a
|
|
|
|
* variable.
|
|
|
|
* @param[out] fptr A reference to the function described by that
|
|
|
|
* selector, if it is a valid function selector.
|
|
|
|
* fptr is written to iff it is non-NULL and the
|
|
|
|
* selector indicates a member function of that
|
|
|
|
* object.
|
|
|
|
* @return kSelectorNone if the selector was not found in
|
|
|
|
* the object or its superclasses.
|
|
|
|
* kSelectorVariable if the selector represents an
|
|
|
|
* object-relative variable.
|
|
|
|
* kSelectorMethod if the selector represents a
|
|
|
|
* method
|
|
|
|
*/
|
2009-09-06 12:57:42 +00:00
|
|
|
SelectorType lookup_selector(SegManager *segMan, reg_t obj, Selector selectorid,
|
2009-06-18 22:09:57 +00:00
|
|
|
ObjVarRef *varp, reg_t *fptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure that a script and its superclasses get loaded to the heap.
|
|
|
|
* If the script already has been loaded, only the number of lockers is
|
|
|
|
* increased. All scripts containing superclasses of this script are loaded
|
|
|
|
* recursively as well, unless 'recursive' is set to zero. The
|
|
|
|
* complementary function is "script_uninstantiate()" below.
|
2009-09-02 12:02:37 +00:00
|
|
|
* @param[in] resMan The resource manager
|
2009-09-06 12:57:42 +00:00
|
|
|
* @param[in] segMan The segment manager
|
2009-08-17 05:55:21 +00:00
|
|
|
* @param[in] script_nr The script number to load
|
|
|
|
* @return The script's segment ID or 0 if out of heap
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-09-06 12:57:42 +00:00
|
|
|
int script_instantiate(ResourceManager *resMan, SegManager *segMan, int script_nr);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Decreases the numer of lockers of a script and unloads it if that number
|
|
|
|
* reaches zero.
|
|
|
|
* This function will recursively unload scripts containing its
|
|
|
|
* superclasses, if those aren't locked by other scripts as well.
|
2009-09-06 12:57:42 +00:00
|
|
|
* @param[in] segMan The segment manager
|
2009-08-17 05:55:21 +00:00
|
|
|
* @param[in] version The SCI version to use
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param[in] script_nr The script number that is requestet to be unloaded
|
|
|
|
*/
|
2009-09-06 12:57:42 +00:00
|
|
|
void script_uninstantiate(SegManager *segMan, int script_nr);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-09-01 17:09:59 +00:00
|
|
|
/**
|
|
|
|
* Converts the builtin Sierra game IDs to the ones we use in ScummVM
|
|
|
|
* @param[in] gameName The internal game name
|
|
|
|
* @param[in] gameFlags The game's flags, which are adjusted accordingly for demos
|
|
|
|
* @return The equivalent ScummVM game id
|
|
|
|
*/
|
|
|
|
const char *convertSierraGameId(const char *gameName, uint32 *gameFlags);
|
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Initializes an SCI game
|
|
|
|
* This function must be run before script_run() is executed. Graphics data
|
|
|
|
* is initialized iff s->gfx_state != NULL.
|
|
|
|
* @param[in] s The state to operate on
|
|
|
|
* @return 0 on success, 1 if an error occured.
|
|
|
|
*/
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_init(EngineState *s);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-11-04 12:16:08 +00:00
|
|
|
#ifdef INCLUDE_OLDGFX
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Initializes the graphics part of an SCI game
|
|
|
|
* This function may only be called if game_init() did not initialize
|
|
|
|
* the graphics data.
|
|
|
|
* @param[in] s The state to initialize the graphics in
|
|
|
|
* @return 0 on success, 1 if an error occured
|
|
|
|
*/
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_init_graphics(EngineState *s);
|
2009-11-04 12:16:08 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-12-26 00:50:09 +00:00
|
|
|
#ifdef USE_OLD_MUSIC_FUNCTIONS
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Initializes the sound part of an SCI game
|
|
|
|
* This function may only be called if game_init() did not initialize
|
|
|
|
* the sound data.
|
|
|
|
* @param[in] s The state to initialize the sound in
|
|
|
|
* @param[in] sound_flags Flags to pass to the sound subsystem
|
2009-12-25 18:59:15 +00:00
|
|
|
* @param[in] soundVersion sound-version that got detected during game init
|
2009-06-18 22:09:57 +00:00
|
|
|
* @return 0 on success, 1 if an error occured
|
|
|
|
*/
|
2009-12-25 18:59:15 +00:00
|
|
|
int game_init_sound(EngineState *s, int sound_flags, SciVersion soundVersion);
|
2009-12-26 00:50:09 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Runs an SCI game
|
|
|
|
* This is the main function for SCI games. It takes a valid state, loads
|
|
|
|
* script 0 to it, finds the game object, allocates a stack, and runs the
|
|
|
|
* init method of the game object. In layman's terms, this runs an SCI game.
|
|
|
|
* Note that, EngineState *s may be changed during the game, e.g. if a game
|
|
|
|
* state is restored.
|
|
|
|
* @param[in] s Pointer to the pointer of the state to operate on
|
|
|
|
* @return 0 on success, 1 if an error occured.
|
|
|
|
*/
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_run(EngineState **s);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Restores an SCI game state and runs the game
|
|
|
|
* This restores a savegame; otherwise, it behaves just like game_run().
|
|
|
|
* @param[in] s Pointer to the pointer of the state to
|
|
|
|
* operate on
|
|
|
|
* @param[in] savegame_name Name of the savegame to restore
|
|
|
|
* @return 0 on success, 1 if an error occured.
|
|
|
|
*/
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_restore(EngineState **s, char *savegame_name);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Uninitializes an initialized SCI game
|
|
|
|
* This function should be run after each script_run() call.
|
|
|
|
* @param[in] s The state to operate on
|
|
|
|
* @return 0 on success, 1 if an error occured.
|
|
|
|
*/
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_exit(EngineState *s);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Instructs the virtual machine to abort
|
|
|
|
*/
|
2009-02-21 17:29:03 +00:00
|
|
|
void quit_vm();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocates "kernel" memory and returns a handle suitable to be passed on
|
|
|
|
* to SCI scripts
|
2009-09-06 12:57:42 +00:00
|
|
|
* @param[in] segMan The Segment Manager
|
2009-08-25 08:38:14 +00:00
|
|
|
* @param[in] type A free-form type description string (static)
|
|
|
|
* @param[in] space The space to allocate
|
|
|
|
* @return The handle
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-09-06 12:57:42 +00:00
|
|
|
reg_t kalloc(SegManager *segMan, const char *type, int space);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to "kernel" memory based on the handle
|
2009-09-06 12:57:42 +00:00
|
|
|
* @param[in] segMan The Segment Manager
|
2009-08-25 08:38:14 +00:00
|
|
|
* @param[in] handle The handle to use
|
|
|
|
* @return A pointer to the allocated memory
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-09-06 12:57:42 +00:00
|
|
|
byte *kmem(SegManager *segMan, reg_t handle);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Frees all "kernel" memory associated with a handle
|
2009-09-06 12:57:42 +00:00
|
|
|
* @param[in] segMan The Segment Manager
|
2009-08-25 08:38:14 +00:00
|
|
|
* @param[in] handle The handle to free
|
|
|
|
* @return 0 on success, 1 otherwise
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-09-06 12:57:42 +00:00
|
|
|
int kfree(SegManager *segMan, reg_t handle);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Shrink execution stack to size.
|
|
|
|
* Contains an assert it is not already smaller.
|
|
|
|
*/
|
2009-05-28 22:42:18 +00:00
|
|
|
void shrink_execution_stack(EngineState *s, uint size);
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|
|
|
|
|
2009-02-24 15:33:40 +00:00
|
|
|
#endif // SCI_ENGINE_VM_H
|