aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/director/lingo/lingo-code.cpp8
-rw-r--r--engines/director/lingo/lingo-codegen.cpp18
-rw-r--r--engines/director/lingo/lingo.cpp4
-rw-r--r--engines/director/lingo/lingo.h4
4 files changed, 18 insertions, 16 deletions
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index 81fad9b4c6..05ad0ccfc3 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -1002,14 +1002,14 @@ void Lingo::c_whencode() {
int entity = g_lingo->_currentEntityId;
g_lingo->_currentEntityId = 0;
- g_lingo->define(eventname, start, 0, NULL, end);
+ Symbol *sym = g_lingo->define(eventname, start, 0, NULL, end);
g_lingo->_currentEntityId = entity;
if (debugChannelSet(1, kDebugLingoExec)) {
- uint pc = start;
- while (pc <= end) {
- Common::String instr = g_lingo->decodeInstruction(pc, &pc);
+ uint pc = 0;
+ while (pc < sym->u.defn->size()) {
+ Common::String instr = g_lingo->decodeInstruction(sym->u.defn, pc, &pc);
debugC(1, kDebugLingoExec, "[%5d] %s", pc, instr.c_str());
}
}
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index 2be88487d7..16874f66c8 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -54,7 +54,7 @@ namespace Director {
void Lingo::execute(uint pc) {
for (_pc = pc; !_returning && (*_currentScript)[_pc] != STOP;) {
- Common::String instr = decodeInstruction(_pc);
+ Common::String instr = decodeInstruction(_currentScript, _pc);
if (debugChannelSet(5, kDebugLingoExec))
printStack("Stack before: ");
@@ -85,11 +85,11 @@ void Lingo::printStack(const char *s) {
debugC(5, kDebugLingoExec, "%s", stack.c_str());
}
-Common::String Lingo::decodeInstruction(uint pc, uint *newPc) {
+Common::String Lingo::decodeInstruction(ScriptData *sd, uint pc, uint *newPc) {
Symbol sym;
Common::String res;
- sym.u.func = (*_currentScript)[pc++];
+ sym.u.func = (*sd)[pc++];
if (_functions.contains((void *)sym.u.s)) {
res = _functions[(void *)sym.u.s]->name;
const char *pars = _functions[(void *)sym.u.s]->proto;
@@ -99,7 +99,7 @@ Common::String Lingo::decodeInstruction(uint pc, uint *newPc) {
switch (*pars++) {
case 'i':
{
- i = (*_currentScript)[pc++];
+ i = (*sd)[pc++];
int v = READ_UINT32(&i);
res += Common::String::format(" %d", v);
@@ -108,7 +108,7 @@ Common::String Lingo::decodeInstruction(uint pc, uint *newPc) {
case 'f':
{
Datum d;
- i = (*_currentScript)[pc++];
+ i = (*sd)[pc++];
d.u.f = *(double *)(&i);
res += Common::String::format(" %f", d.u.f);
@@ -116,7 +116,7 @@ Common::String Lingo::decodeInstruction(uint pc, uint *newPc) {
}
case 'o':
{
- i = (*_currentScript)[pc++];
+ i = (*sd)[pc++];
int v = READ_UINT32(&i);
res += Common::String::format(" [%5d]", v);
@@ -124,7 +124,7 @@ Common::String Lingo::decodeInstruction(uint pc, uint *newPc) {
}
case 's':
{
- char *s = (char *)&(*_currentScript)[pc];
+ char *s = (char *)&(*sd)[pc];
pc += calcStringAlignment(s);
res += Common::String::format(" \"%s\"", s);
@@ -212,7 +212,7 @@ void Lingo::cleanLocalVars() {
g_lingo->_localvars = 0;
}
-void Lingo::define(Common::String &name, int start, int nargs, Common::String *prefix, int end) {
+Symbol *Lingo::define(Common::String &name, int start, int nargs, Common::String *prefix, int end) {
if (prefix)
name = *prefix + "-" + name;
@@ -243,6 +243,8 @@ void Lingo::define(Common::String &name, int start, int nargs, Common::String *p
sym->u.defn = new ScriptData(&(*_currentScript)[start], end - start + 1);
sym->nargs = nargs;
sym->maxArgs = nargs;
+
+ return sym;
}
int Lingo::codeString(const char *str) {
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index b9236d8627..703a5b28c4 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -182,7 +182,7 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) {
if (debugChannelSet(3, kDebugLingoCompile)) {
uint pc = 0;
while (pc < _currentScript->size()) {
- Common::String instr = decodeInstruction(pc, &pc);
+ Common::String instr = decodeInstruction(_currentScript, pc, &pc);
debugC(2, kDebugLingoCompile, "[%5d] %s", pc, instr.c_str());
}
}
@@ -215,7 +215,7 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) {
uint pc = 0;
while (pc < _currentScript->size()) {
- Common::String instr = decodeInstruction(pc, &pc);
+ Common::String instr = decodeInstruction(_currentScript, pc, &pc);
debugC(2, kDebugLingoCompile, "[%5d] %s", pc, instr.c_str());
}
}
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index b2acdd82f0..13dbc0a785 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -179,7 +179,7 @@ public:
void addNamesV4(Common::SeekableSubReadStreamEndian &stream);
void executeScript(ScriptType type, uint16 id, uint16 function);
void printStack(const char *s);
- Common::String decodeInstruction(uint pc, uint *newPC = NULL);
+ Common::String decodeInstruction(ScriptData *sd, uint pc, uint *newPC = NULL);
void initBuiltIns();
void initFuncs();
@@ -214,7 +214,7 @@ public:
void popContext();
Symbol *lookupVar(const char *name, bool create = true, bool putInGlobalList = false);
void cleanLocalVars();
- void define(Common::String &s, int start, int nargs, Common::String *prefix = NULL, int end = -1);
+ Symbol *define(Common::String &s, int start, int nargs, Common::String *prefix = NULL, int end = -1);
void processIf(int elselabel, int endlabel);
int alignTypes(Datum &d1, Datum &d2);