diff options
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | boot.php | 33 |
2 files changed, 28 insertions, 18 deletions
@@ -15,21 +15,24 @@ Want to play Dr Mario or Pokémon on your server terminal? That's for you! ## Why -Some people will ask me: "Why you did that?" +Some people will ask me: _"Why you did that?"_ -Well, a friend asked me "What PHP can do?". I thinked about a while, and the idea comes. With PHP 7, it's now possible to emulate some systems because of the performance improvement :-) And come on, it's funny! \o/ +Well, a friend asked me _"What PHP can do?"_. I thought about that awhile and +the idea came up. With PHP7's performance improvement now it's possible to +emulate some systems :smile: and, come on, that's funny! :dancers: -It's based on a [GameBoy JS Emulator](https://github.com/taisel/GameBoy-Online). +It's based on the [GameBoy JS Emulator](https://github.com/taisel/GameBoy-Online). ## Requirements -The following versions of PHP are supported by this version. +The following PHP versions are supported: + PHP 5.6 + PHP 7 + HHVM -You will need a good terminal! Tested on MacOSX and Linux. Sorry Windows guys :-( +You will need a good terminal! I've tested only on MacOSX and Linux. I'm sorry +about that Windows guys :disappointed: ## Running @@ -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(); } |