callVS2 method

void callVS2()

Implementation

void callVS2() {
  //Debugger.verbose('${pcHex(-1)} [call_vn2]');

  var operands = visitOperandsVar(8, true);

  var resultStore = readb();

  var returnAddr = programCounter;

  assert(operands.isNotEmpty);

  if (operands[0].value == 0) {
    //calling routine at address 0x00 automatically returns FALSE (ref 6.4.3)

    writeVariable(resultStore, Engine.gameFalse);
  } else {
    //unpack function address
    operands[0].rawValue = unpack(operands[0].value!);

    //move to the routine address
    programCounter = operands[0].rawValue!;

    //peel off the first operand
    operands.removeAt(0);

    //setup the routine stack frame and locals
    visitRoutine(operands.map<int?>((o) => o.value).toList());

    //push the result store address onto the call stack
    callStack.push(resultStore);

    //push the return address onto the call stack
    callStack.push(returnAddr);
  }
}