PHP Classes

PHP Gameboy Emulator: Emulate Gameboy console in a terminal in pure PHP

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (17)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 66%Total: 375 All time: 6,745 This week: 156Up
Version License PHP version Categories
php-terminal-gameboy 1.0.4MIT/X Consortium ...5.6PHP 5, Emulators, Games, Console
Collaborate with this project 

Author

Description

This package can emulate Gameboy console in a terminal in pure PHP.

It can run a Gameboy virtual machine by emulating its hardware and executing games Z80 CPU assembly code with PHP code.

The Gameboy screen is outputted to the terminal console using braille characters. Keyboard inputs are mapped to Gameboy key controls.

Innovation Award
PHP Programming Innovation award winner
March 2016
Winner


Prize: One big elePHPant Plush Mascott
Gameboy is a popular 8 bit console created in the 1980 decade.

This package can emulate a Gameboy in pure PHP code. It outputs the Gameboy screen to your console terminal using Braille characters.

Manuel Lemos
Picture of Gabriel Couto
  Performance   Level  
Name: Gabriel Couto <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: 35
All time rank: 3607283 in Brazil Brazil
Week rank: 569 Up33 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Example

<?php


foreach (['../../autoload.php', '../vendor/autoload.php', 'vendor/autoload.php'] as $autoload) {
   
$autoload = __DIR__.'/'.$autoload;
    if (
file_exists($autoload)) {
        require
$autoload;
        break;
    }
}
unset(
$autoload);

use
GameBoy\Canvas\TerminalCanvas;
use
GameBoy\Core;
use
GameBoy\Keyboard;

if (
PHP_VERSION_ID >= 70000) {
   
set_exception_handler(function (\Throwable $exception) {
       
fwrite(STDERR, $exception->getMessage() . PHP_EOL);
        exit(
254);
    });
} else {
   
set_exception_handler(function (Exception $exception) {
       
fwrite(STDERR, $exception->getMessage() . PHP_EOL);
        exit(
254);
    });
}

if (
count($argv) < 2) {
    throw new \
RuntimeException('You need to pass the ROM file name (Ex: drmario.rom)');
}

$filename = $argv[1];

if (!
file_exists($filename)) {
    throw new \
RuntimeException(sprintf('"%s" does not exist', $filename));
}

if (
extension_loaded('xdebug')) {
   
fwrite(STDERR, 'Running php-gameboy with Xdebug enabled reduces its speed considerably.'.PHP_EOL);
   
fwrite(STDERR, 'You should consider to disable it before execute php-gameboy.'.PHP_EOL);
   
sleep(1);
}

$rom = file_get_contents($filename);

$canvas = new TerminalCanvas();
$core = new Core($rom, $canvas);
$keyboard = new Keyboard($core);

$core->start();

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();
}


Screenshots  
  • dr-mario.png
  Files folder image Files  
File Role Description
Files folder imagebin (2 files)
Files folder imagesrc (8 files, 1 directory)
Accessible without login Plain text file boot.php Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file docker-php-7 Data Auxiliary data
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file build Aux. Auxiliary script
  Accessible without login Plain text file php-gameboy Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageCanvas (2 files)
  Plain text file Cbopcode.php Class Class source
  Plain text file Core.php Class Class source
  Plain text file Data.php Class Class source
  Plain text file Keyboard.php Class Class source
  Plain text file LcdController.php Class Class source
  Plain text file Opcode.php Class Class source
  Plain text file Settings.php Class Class source
  Plain text file TICKTables.php Class Class source

  Files folder image Files  /  src  /  Canvas  
File Role Description
  Plain text file DrawContextInterface.php Class Class source
  Plain text file TerminalCanvas.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 94%
Total:375
This week:0
All time:6,745
This week:156Up
User Ratings User Comments (5)
 All time
Utility:96%StarStarStarStarStar
Consistency:92%StarStarStarStarStar
Documentation:-
Examples:89%StarStarStarStarStar
Tests:-
Videos:-
Overall:66%StarStarStarStar
Rank:715
 
Haha, I liked to play with this
7 years ago (Joubert RedRat)
70%StarStarStarStar
Excellent php class package, great idea, this Mister Gabriel ...
7 years ago (marcosptf)
70%StarStarStarStar
Congratulations, this is a superb class ;-)
7 years ago (Josť Filipe Lopes Santos)
70%StarStarStarStar
Congratulations, this is a superb class ;-)
7 years ago (Josť Filipe Lopes Santos)
70%StarStarStarStar
Congratulations, this is a superb class ;-)
7 years ago (Josť Filipe Lopes Santos)
70%StarStarStarStar