summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Rodrigues Couto <gabriel@rodriguescouto.com.br>2016-02-23 10:47:35 -0300
committerGabriel Rodrigues Couto <gabriel@rodriguescouto.com.br>2016-02-23 10:47:35 -0300
commit13ac12486fca028d15a2a88ae064b7d9d031923b (patch)
tree86e7375ebe17ee7d38bb752327e85893622b91dd
parent22de1d58616e9f6613bd535083bb8ada9ed839dc (diff)
parentb1d20660d2d9767c340a4eb610a379ff67044d04 (diff)
downloadphp-terminal-gameboy-emulator-13ac12486fca028d15a2a88ae064b7d9d031923b.zip
php-terminal-gameboy-emulator-13ac12486fca028d15a2a88ae064b7d9d031923b.tar.gz
php-terminal-gameboy-emulator-13ac12486fca028d15a2a88ae064b7d9d031923b.tar.bz2
Merge pull request #11 from henriquemoody/boot
Small improvements on "boot.php"
-rw-r--r--boot.php33
1 files changed, 20 insertions, 13 deletions
diff --git a/boot.php b/boot.php
index bba0021..292e90f 100644
--- a/boot.php
+++ b/boot.php
@@ -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();
}