diff options
-rw-r--r-- | boot.php | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -6,8 +6,13 @@ use GameBoy\Canvas\TerminalCanvas; use GameBoy\Core; use GameBoy\Keyboard; +set_exception_handler(function (Exception $exception) { + fwrite(STDERR, $exception->getMessage().PHP_EOL); + exit(254); +}); + if (count($argv) < 2) { - echo 'You need to pass the ROM file name (Ex: drmario.rom)'; + throw new RuntimeException('You need to pass the ROM file name (Ex: drmario.rom)'); } $rom = base64_decode(file_get_contents($argv[1])); @@ -18,16 +23,18 @@ $keyboard = new Keyboard($core); $core->start(); -if ($core->stopEmulator & 2 == 2) { - $core->stopEmulator &= 1; - $core->lastIteration = (int) (microtime(true) * 1000); - - while (true) { - $core->run(); - $keyboard->check(); - } -} else if (($core->stopEmulator & 2) == 0) { - echo 'The GameBoy core is already running.' . PHP_EOL; -} else { - echo 'GameBoy core cannot run while it has not been initialized.' . PHP_EOL; +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(); } |