summaryrefslogtreecommitdiffstats
path: root/src
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 /src
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
Diffstat (limited to 'src')
-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
3 files changed, 29 insertions, 12 deletions
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: