From c003d62429399db2d8ca11dc66461a98c52d0538 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 18 Jan 2009 17:24:47 +0000 Subject: [PATCH] - Fixed bug in script code of LoL - Cleanup svn-id: r35905 --- engines/kyra/script.cpp | 12 ++++++------ engines/kyra/script.h | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/engines/kyra/script.cpp b/engines/kyra/script.cpp index 9635b0b29a6..da99abed73d 100644 --- a/engines/kyra/script.cpp +++ b/engines/kyra/script.cpp @@ -152,9 +152,9 @@ void EMCInterpreter::unload(EMCData *data) { void EMCInterpreter::init(EMCState *scriptStat, const EMCData *data) { scriptStat->dataPtr = data; scriptStat->ip = 0; - scriptStat->stack[60] = 0; - scriptStat->bp = 62; - scriptStat->sp = 60; + scriptStat->stack[EMCState::kStackLastEntry] = 0; + scriptStat->bp = EMCState::kStackSize+1; + scriptStat->sp = EMCState::kStackLastEntry; } bool EMCInterpreter::start(EMCState *script, int function) { @@ -346,7 +346,7 @@ void EMCInterpreter::cmd_popRetOrPos(EMCState* script) { break; case 1: - if (script->sp >= 60) { + if (script->sp >= EMCState::kStackLastEntry) { script->ip = 0; } else { script->bp = script->stack[script->sp++]; @@ -519,12 +519,12 @@ void EMCInterpreter::cmd_eval(EMCState* script) { } void EMCInterpreter::cmd_setRetAndJmp(EMCState* script) { - if (script->sp >= 60) { + if (script->sp >= EMCState::kStackLastEntry) { script->ip = 0; } else { script->retValue = script->stack[script->sp++]; uint16 temp = script->stack[script->sp++]; - script->stack[60] = 0; + script->stack[EMCState::kStackLastEntry] = 0; script->ip = &script->dataPtr->data[temp]; } } diff --git a/engines/kyra/script.h b/engines/kyra/script.h index ae9ece8154a..7d6c9d5243c 100644 --- a/engines/kyra/script.h +++ b/engines/kyra/script.h @@ -47,13 +47,18 @@ struct EMCData { }; struct EMCState { + enum { + kStackSize = 100, + kStackLastEntry = kStackSize - 1 + }; + const uint16 *ip; const EMCData *dataPtr; int16 retValue; uint16 bp; uint16 sp; - int16 regs[30]; // VM registers - int16 stack[100]; // VM stack + int16 regs[30]; // VM registers + int16 stack[kStackSize]; // VM stack }; #define stackPos(x) (script->stack[script->sp+x])