callVS method

void callVS()

Implementation

void callVS() {
  //Debugger.verbose('${pcHex(-1)} [call_vs]');
  final operands = visitOperandsVar(4, true);

  final resultStore = readb();
  final 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!;

    operands.removeAt(0);

    //setup the routine stack frame and locals
    visitRoutine(operands.map((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);
  }
}