DIRECTOR: Lingo: Start of script execution trace code

This commit is contained in:
Eugene Sandulenko 2016-08-16 18:48:09 +02:00
parent 09138c9e9f
commit 289d10c26b
3 changed files with 42 additions and 2 deletions

View file

@ -136,6 +136,8 @@ void Lingo::initBuiltIns() {
sym->u.bltin = blt->func;
_handlers[blt->name] = sym;
_functions[(void *)sym->u.s] = new FuncDesc(blt->name, "");
}
}

View file

@ -53,17 +53,28 @@ namespace Director {
void Lingo::execute(int pc) {
for(_pc = pc; (*_currentScript)[_pc] != STOP && !_returning;) {
Common::String instr = decodeInstruction(_pc);
debugC(1, kDebugLingoExec, "%s", instr.c_str());
for (uint i = 0; i < _stack.size(); i++) {
debugN(5, "%d ", _stack[i].u.i);
debugCN(5, kDebugLingoExec, "%d ", _stack[i].u.i);
}
debug(5, "%s", "");
debugCN(5, kDebugLingoExec, "%s", "");
_pc++;
(*((*_currentScript)[_pc - 1]))();
}
}
Common::String Lingo::decodeInstruction(int pc) {
if (_functions.contains((void *)(*_currentScript)[pc])) {
return _functions[(void *)(*_currentScript)[pc]]->name;
} else {
return "<unknown>";
}
}
Symbol *Lingo::lookupVar(const char *name, bool create, bool putInGlobalList) {
Symbol *sym;

View file

@ -83,6 +83,30 @@ typedef void (*inst)(void);
typedef Common::Array<inst> ScriptData;
typedef Common::Array<double> FloatArray;
struct FuncDesc {
Common::String name;
const char *proto;
FuncDesc(Common::String n, const char *p) { name = n; proto = p; }
};
struct Pointer_EqualTo {
bool operator()(const void *x, const void *y) const { return x == y; }
};
struct Pointer_Hash {
uint operator()(const void *x) const {
#ifdef SCUMM_64BITS
uint64 v = (uint64)x;
return (v >> 32) ^ (v & 0xffffffff);
#else
return (uint)x;
#endif
}
};
typedef Common::HashMap<void *, FuncDesc *, Pointer_Hash, Pointer_EqualTo> FuncHash;
struct Symbol { /* symbol table entry */
char *name;
int type;
@ -156,6 +180,7 @@ public:
void addCode(const char *code, ScriptType type, uint16 id);
void executeScript(ScriptType type, uint16 id);
Common::String decodeInstruction(int pc);
void processEvent(LEvent event, int entityId);
@ -403,6 +428,8 @@ private:
SymbolHash _globalvars;
SymbolHash *_localvars;
FuncHash _functions;
int _pc;
StackData _stack;