GameBoy\Core::run PHP Method

run() public method

public run ( )
    public function run()
    {
        //The preprocessing before the actual iteration loop:
        try {
            if (($this->stopEmulator & 2) == 0) {
                if (($this->stopEmulator & 1) == 1) {
                    $this->stopEmulator = 0;
                    $this->clockUpdate();
                    //Frame skip and RTC code.
                    //If no HALT... Execute normally
                    if (!$this->halt) {
                        $this->executeIteration();
                        //If we bailed out of a halt because the iteration ran down its timing.
                    } else {
                        $this->CPUTicks = 1;
                        Opcode::run($this, 0x76);
                        //Execute Interrupt:
                        $this->runInterrupt();
                        //Timing:
                        $this->updateCore();
                        $this->executeIteration();
                    }
                    //We can only get here if there was an internal error, but the loop was restarted.
                } else {
                    echo 'Iterator restarted a faulted core.' . PHP_EOL;
                    pause();
                }
            }
        } catch (\Exception $error) {
            if ($error->getMessage() != 'HALT_OVERRUN') {
                echo 'GameBoy runtime error' . PHP_EOL;
            }
        }
    }

Usage Example

    });
}
if (count($argv) < 2) {
    throw new \RuntimeException('You need to pass the ROM file name (Ex: drmario.rom)');
}
$filename = $argv[1];
if (!file_exists($filename)) {
    throw new \RuntimeException(sprintf('"%s" does not exist', $filename));
}
if (extension_loaded('xdebug')) {
    fwrite(STDERR, 'Running php-gameboy with Xdebug enabled reduces its speed considerably.' . PHP_EOL);
    fwrite(STDERR, 'You should consider to disable it before execute php-gameboy.' . PHP_EOL);
    sleep(1);
}
$rom = file_get_contents($filename);
$canvas = new TerminalCanvas();
$core = new Core($rom, $canvas);
$keyboard = new Keyboard($core);
$core->start();
if (($core->stopEmulator & 2) == 0) {
    throw new \RuntimeException('The GameBoy core is already running.');
}
if ($core->stopEmulator & 2 != 2) {
    throw new \RuntimeException('GameBoy core cannot run while it has not been initialized.');
}
$core->stopEmulator &= 1;
$core->lastIteration = (int) (microtime(true) * 1000);
while (true) {
    $core->run();
    $keyboard->check();
}