summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Rodrigues Couto <gabrielrcouto@gmail.com>2016-02-21 16:30:00 -0300
committerGabriel Rodrigues Couto <gabrielrcouto@gmail.com>2016-02-21 16:30:00 -0300
commit48a6f1c5178c3c9641155297faf79c27d143fc4f (patch)
treebdc7424cdebfad6badf4bbb70f63936c7ed62610
parent522c395e0da277408a8e8735049ab625d4a46b72 (diff)
downloadphp-terminal-gameboy-emulator-48a6f1c5178c3c9641155297faf79c27d143fc4f.zip
php-terminal-gameboy-emulator-48a6f1c5178c3c9641155297faf79c27d143fc4f.tar.gz
php-terminal-gameboy-emulator-48a6f1c5178c3c9641155297faf79c27d143fc4f.tar.bz2
Canvas is now injected - New possibilites :-)
Clear project files
-rw-r--r--.gitignore1
-rw-r--r--boot.php8
-rw-r--r--composer.lock73
-rwxr-xr-xdrmario.gbbin32768 -> 0 bytes
-rw-r--r--src/Gameboy/Canvas/DrawContextInterface.php18
-rw-r--r--src/Gameboy/Canvas/TerminalCanvas.php (renamed from src/Gameboy/DrawContext.php)12
-rw-r--r--src/Gameboy/Core.php11
-rw-r--r--teste.txtbin13085 -> 0 bytes
8 files changed, 35 insertions, 88 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..189ea26
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+material/ \ No newline at end of file
diff --git a/boot.php b/boot.php
index c052438..b249df8 100644
--- a/boot.php
+++ b/boot.php
@@ -2,13 +2,15 @@
require_once __DIR__.'/vendor/autoload.php';
+use GameBoy\Canvas\TerminalCanvas;
use GameBoy\Core;
use GameBoy\Keyboard;
use GameBoy\Settings;
$rom = base64_decode(file_get_contents('pokemon.rom'));
-$core = new Core($rom);
+$canvas = new TerminalCanvas();
+$core = new Core($rom, $canvas);
$keyboard = new Keyboard($core);
$core->start();
@@ -22,8 +24,8 @@ if ($core->stopEmulator & 2 == 2) {
$keyboard->check();
}
} else if (($core->stopEmulator & 2) == 0) {
- echo "The GameBoy core is already running." . PHP_EOL;
+ echo 'The GameBoy core is already running.' . PHP_EOL;
}
else {
- echo "GameBoy core cannot run while it has not been initialized." . PHP_EOL;
+ echo 'GameBoy core cannot run while it has not been initialized.' . PHP_EOL;
} \ No newline at end of file
diff --git a/composer.lock b/composer.lock
deleted file mode 100644
index 5e1e806..0000000
--- a/composer.lock
+++ /dev/null
@@ -1,73 +0,0 @@
-{
- "_readme": [
- "This file locks the dependencies of your project to a known state",
- "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
- "This file is @generated automatically"
- ],
- "hash": "86366dfab291cc63b913e9fd405622b8",
- "content-hash": "9d3f3f2a6403b572b1354b63d683c63a",
- "packages": [
- {
- "name": "whatthejeff/drawille",
- "version": "v1.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/whatthejeff/php-drawille.git",
- "reference": "bafea427f5bf2445413f6807000a95f70cc83bfd"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/whatthejeff/php-drawille/zipball/bafea427f5bf2445413f6807000a95f70cc83bfd",
- "reference": "bafea427f5bf2445413f6807000a95f70cc83bfd",
- "shasum": ""
- },
- "require": {
- "php": ">=5.4.0"
- },
- "require-dev": {
- "phpunit/phpunit": "4.1.*"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Drawille": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Jeff Welch",
- "email": "whatthejeff@gmail.com"
- }
- ],
- "description": "Terminal drawing with braille",
- "homepage": "http://github.com/whatthejeff/php-drawille",
- "keywords": [
- "Turtle",
- "braille",
- "console",
- "drawing",
- "terminal"
- ],
- "time": "2014-05-26 13:45:31"
- }
- ],
- "packages-dev": [],
- "aliases": [],
- "minimum-stability": "stable",
- "stability-flags": [],
- "prefer-stable": false,
- "prefer-lowest": false,
- "platform": {
- "php": ">=5.4.0"
- },
- "platform-dev": []
-}
diff --git a/drmario.gb b/drmario.gb
deleted file mode 100755
index 937b548..0000000
--- a/drmario.gb
+++ /dev/null
Binary files differ
diff --git a/src/Gameboy/Canvas/DrawContextInterface.php b/src/Gameboy/Canvas/DrawContextInterface.php
new file mode 100644
index 0000000..73f0c43
--- /dev/null
+++ b/src/Gameboy/Canvas/DrawContextInterface.php
@@ -0,0 +1,18 @@
+<?php
+namespace GameBoy\Canvas;
+
+/**
+ * Interface to draw the GameBoy output
+ * GameBoy screen size: 160 x 144
+ */
+interface DrawContextInterface
+{
+ /**
+ * Draw image on canvas
+ *
+ * @param Array $canvasBuffer Each pixel => 4 items on array (RGBA)
+ * @param int $left
+ * @param int $top
+ */
+ public function draw($canvasBuffer, $left, $top);
+} \ No newline at end of file
diff --git a/src/Gameboy/DrawContext.php b/src/Gameboy/Canvas/TerminalCanvas.php
index faff5b3..c3a4ac9 100644
--- a/src/Gameboy/DrawContext.php
+++ b/src/Gameboy/Canvas/TerminalCanvas.php
@@ -1,12 +1,11 @@
<?php
-namespace GameBoy;
+namespace GameBoy\Canvas;
use Drawille\Canvas;
+use GameBoy\Settings;
-class DrawContext
+class TerminalCanvas implements DrawContextInterface
{
- // Screen size: 160 x 144
-
protected $canvas;
protected $currentSecond = 0;
protected $framesInSecond = 0;
@@ -18,12 +17,13 @@ class DrawContext
}
/**
- * Put image on canvas
+ * Draw image on canvas using braille font
+ *
* @param Object $canvasBuffer $data = Each pixel = 4 items on array (RGBA)
* @param int $left
* @param int $top
*/
- public function putImageData($canvasBuffer, $left, $top)
+ public function draw($canvasBuffer, $left, $top)
{
//Corner pixel, to draw same size each time
$this->canvas->set(0, 0);
diff --git a/src/Gameboy/Core.php b/src/Gameboy/Core.php
index 83405b6..97097f2 100644
--- a/src/Gameboy/Core.php
+++ b/src/Gameboy/Core.php
@@ -378,8 +378,9 @@ class Core
public $cTIMER = null;
- public function __construct($ROMImage)
+ public function __construct($ROMImage, $drawContext)
{
+ $this->drawContext = $drawContext;
$this->ROMImage = $ROMImage;
$this->DISPLAYOFFCONTROL[] = function ($parentObj) {
@@ -1056,8 +1057,6 @@ class Core
}
}
- $this->drawContext = new DrawContext();
-
$this->width = 160;
$this->height = 144;
@@ -1076,7 +1075,7 @@ class Core
$this->canvasBuffer[$index2 + 3] = 0xFF;
}
- $this->drawContext->putImageData($this->canvasBuffer, 0, 0);
+ $this->drawContext->draw($this->canvasBuffer, 0, 0);
}
public function JoyPadEvent($key, $down)
@@ -1395,7 +1394,7 @@ class Core
public function DisplayShowOff() {
if ($this->drewBlank == 0) {
$this->canvasBuffer = array_fill(0, 4 * $this->width * $this->height, 255);
- $this->drawContext->putImageData($this->canvasBuffer, 0, 0);
+ $this->drawContext->draw($this->canvasBuffer, 0, 0);
$this->drewBlank = 2;
}
}
@@ -1513,7 +1512,7 @@ class Core
}
//Draw out the CanvasPixelArray data:
- $this->drawContext->putImageData($this->canvasBuffer, 0, 0);
+ $this->drawContext->draw($this->canvasBuffer, 0, 0);
if (Settings::$settings[4] > 0) {
//Decrement the frameskip counter:
diff --git a/teste.txt b/teste.txt
deleted file mode 100644
index 45e5939..0000000
--- a/teste.txt
+++ /dev/null
Binary files differ