forked from hasegawa-tomoki/php-terminal-nes-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.php
46 lines (41 loc) · 1.22 KB
/
boot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require_once "vendor/autoload.php";
$c = new Console_CommandLine();
$c->description = 'php-terminal-nes-emulator';
$c->version = '1.0.0';
$c->addArgument('file', [
'description' => 'Nes ROM image.',
]);
$c->addOption('canvas', [
'short_name' => '-c',
'long_name' => '--canvas',
'description' => 'Canvas to display screen.'.PHP_EOL.'Option: terminal (default), png, null',
'action' => 'StoreString',
'default' => 'Terminal',
]);
$filename = null;
$canvas = null;
try {
$parsed = $c->parse();
if (! isset($parsed->args['file'])) {
throw new \RuntimeException('You need to pass the ROM file name.');
}
$filename = $parsed->args['file'];
if (isset($parsed->options['canvas'])) {
$canvasName = ucfirst(strtolower($parsed->options['canvas']));
$canvasClassName = sprintf('\\Nes\\Ppu\\Canvas\\%sCanvas', $canvasName);
if (! class_exists($canvasClassName)) {
throw new \RuntimeException('Invalid canvas.');
}
$canvas = new $canvasClassName();
}
} catch (Exception $e) {
die($e->getMessage().PHP_EOL);
}
$nes = new \Nes\Nes($canvas);
try {
$nes->load($filename);
$nes->start();
} catch (Exception $e) {
echo $e->getMessage();
}