diff options
author | Henrique Moody <henriquemoody@gmail.com> | 2016-02-23 10:38:56 -0300 |
---|---|---|
committer | Henrique Moody <henriquemoody@gmail.com> | 2016-02-23 10:38:56 -0300 |
commit | b1d20660d2d9767c340a4eb610a379ff67044d04 (patch) | |
tree | 86e7375ebe17ee7d38bb752327e85893622b91dd | |
parent | 22de1d58616e9f6613bd535083bb8ada9ed839dc (diff) | |
download | php-terminal-gameboy-emulator-b1d20660d2d9767c340a4eb610a379ff67044d04.zip php-terminal-gameboy-emulator-b1d20660d2d9767c340a4eb610a379ff67044d04.tar.gz php-terminal-gameboy-emulator-b1d20660d2d9767c340a4eb610a379ff67044d04.tar.bz2 |
Small improvements on "boot.php"
- Avoid using `else`;
- Create an exception handler;
- Exists when a ROM is not defined.
-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(); } |