initializeEngine static method

void initializeEngine([
  1. Engine? newEngine
])

Selects the best suited Engine version for the game file. will also accept optional newEngine which will be used to run the game (throws a GameException if newEngine version and game version do not match).

Implementation

static void initializeEngine([Engine? newEngine]) {
  Z.inInterrupt = true;
  if (!Z.isLoaded) {
    throw GameException(
        "Unable to initialize Z-Machine.  No game file is loaded.");
  }

  if (newEngine != null && newEngine.version != Z.ver) {
    throw GameException(
        'Machine/Story version mismatch. Expected ${Z.ver}. Got ${newEngine.version}');
  }

  Z.engine = newEngine ?? _getEngineByVersion(Z.ver);
  Z.engine.mem = MemoryMap(Z.rawBytes);
  Z.engine.visitHeader();
  debug('<<< machine installed: v${Z.engine.version} >>>');
  Z.inInterrupt = false;
}