Skip to content

Commit

Permalink
GLK: ADVSYS: Script interpreter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jun 15, 2019
1 parent 23c6c13 commit 75fe5b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions engines/glk/advsys/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ void VM::executeOpcode() {
// Get next opcode
uint opcode = readCodeByte();

if (gDebugLevel > 0) {
Common::String s;
for (int idx = (int)_stack.size() - 1; idx >= 0; --idx) s += Common::String::format(" %d", _stack[idx]);
debug("%.4x - %.2x - %d%s", _pc - 1, opcode, _stack.size(), s.c_str());
}

if (opcode >= OP_BRT && opcode <= OP_VOWEL) {
(this->*_METHODS[(int)opcode - 1])();
} else if (opcode >= OP_XVAR && opcode < OP_XSET) {
Expand Down Expand Up @@ -256,7 +262,7 @@ void VM::opEXIT() {
}

void VM::opRETURN() {
if (_stack.empty()) {
if (_fp == 0) {
_status = CHAIN;
} else {
int val = _stack.top();
Expand Down Expand Up @@ -314,18 +320,16 @@ void VM::opRESTORE() {

void VM::opARG() {
int argNum = readCodeByte();
int varsSize = _stack[_fp - 3];
if (argNum >= varsSize)
if (argNum >= _fp[FP_ARGS_SIZE])
error("Invalid argument number");
_stack.top() = _stack[_fp - 4 - argNum];
_stack.top() = _fp[argNum + FP_ARGS];
}

void VM::opASET() {
int argNum = readCodeByte();
int varsSize = _stack[_fp - 3];
if (argNum >= varsSize)
if (argNum >= _fp[FP_ARGS_SIZE])
error("Invalid argument number");
_stack[_fp - 4 - argNum] = _stack.top();
_fp[argNum + FP_ARGS] = _stack.top();
}

void VM::opTMP() {
Expand Down
4 changes: 3 additions & 1 deletion engines/glk/advsys/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ class VM : public GlkInterface, public Game {
* Gets the next code word and increases the PC counter to after it
*/
int readCodeWord() {
return getCodeWord(_pc += 2);
int v = getCodeWord(_pc);
_pc += 2;
return v;
}

/**
Expand Down

0 comments on commit 75fe5b5

Please sign in to comment.