SlideShare une entreprise Scribd logo
1  sur  74
Télécharger pour lire hors ligne
Reading
php-terminal-gameboy-emulator
Digital Circus, Inc.
HASEGAWA Tomki
HASEGAWA Tomoki
@tomzoh
Web / iOS App Development,
Rental Kart Race, Beer, IoT crafting, …
hasegawa

tomoki
Digital Circus, Inc. Vice-master CTO
Tokyo, Japan
Interests
・ Web Development
・ Mobile Apps Development
・ Service
( )
(iOS, Android)
(http://appbuilder.jp)
Twitter: @tomzoh
Twitter: @tomzoh
Today’s theme
Reading
php-terminal-gameboy-emulator
Today’s theme
Reading
php-terminal-gameboy-emulator
By Transfrom JPEG version and remove white background. Original by Evan-Amos. - Media:Game-Boy-FL.jpg,
Public Domain, https://commons.wikimedia.org/w/index.php?curid=37808150
23, February
😮
😮
😮
Awesome!!
😮
Awesome!!
Waste of talent!!
😮
Awesome!!
Waste of talent!! Cool!!
Source Files
Source Files
It’s PHP !
Source Files
It’s PHP !
We can read it.
Source Files
It’s PHP !
Yes, We can!
We can read it.
Source Files
It’s PHP !
Yes, We can!
Yes, We can!
We can read it.
Today’s theme
Reading
php-terminal-gameboy-emulator
Components of GAMEBOY
• CPU / Memory
• Display
• Sound
• Buttons
• Communication Port
Components of GAMEBOY
• CPU / Memory
• Display
• Sound
• Buttons
• Communication Port
Buttons
Buttons - Keyboard.php
<?php
namespace GameBoy;
class Keyboard
{
public $core;
public $file;
public $keyPressing = null;
public $started = false;
public function __construct(Core $core)
{
$this->core = $core;
exec('stty -icanon');
$this->file = fopen('php://stdin', 'r');
stream_set_blocking($this->file, false);
}
public function check()
{
Buttons - Keyboard.php
<?php
namespace GameBoy;
class Keyboard
{
public $core;
public $file;
public $keyPressing = null;
public $started = false;
public function __construct(Core $core)
{
$this->core = $core;
exec('stty -icanon');
$this->file = fopen('php://stdin', 'r');
stream_set_blocking($this->file, false);
}
public function check()
{
How to sense buttons
How to sense buttons
$this->file = fopen('php://stdin', 'r');
How to sense buttons
$this->file = fopen('php://stdin', 'r');
$key = fread($this->file, 1);
Simple
CPU / Memory
CPU
SHARP LR35902 instruction set
http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html
1byte instructions Prefix CB instructions
144 instructions 256 instructions+
= 400 instructions
SHARP LR35902 resistors
http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html
15 … 8 7 … 0
A F
B C
H L
15 … 8 7 … 0
SP (Stack Pointer)
PC (Program Counter)
8bit / 16bit resistors
16bit resistors
Flag registor
7 6 5 4 3 2 1 0
Z N H C 0 0 0 0
•Z - Zero Flag
•N - Subtract Flag
•H - Half Carry Flag
•C - Carry Flag
•0 - Not uses, always zero
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Length in bytes
Address
LD A, d8
2 8
- - - -
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Duration in cyclesLength in bytes
Address
LD A, d8
2 8
- - - -
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Duration in cycles
Flags affected
Length in bytes
Address
LD A, d8
2 8
- - - -
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
PC (Program Counter)
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
Load 0x0301 into BC resistor
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
PC (Program Counter)
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
PC (Program Counter)
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
Load 0x99 into A resistor
PC (Program Counter)
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
PC (Program Counter)
Instruction in memory
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
Load A resistor’s value into memory
indicates with BC resistor
x0 x1 x2 xE
0x 3x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Address
LD A, d8
2 8
- - - -
PC (Program Counter)
CPU - Opcode.php
<?php
namespace GameBoy;
class Opcode
{
public $functionsArray = [];
public function __construct()
{
//NOP
//#0x00:
$this->functionsArray[] = function ($parentObj) {
//Do Nothing...
};
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
CPU - Opcode.php
<?php
namespace GameBoy;
class Opcode
{
public $functionsArray = [];
public function __construct()
{
//NOP
//#0x00:
$this->functionsArray[] = function ($parentObj) {
//Do Nothing...
};
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
x0 x1 x2
0x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
CPU - Opcode.php
<?php
namespace GameBoy;
class Opcode
{
public $functionsArray = [];
public function __construct()
{
//NOP
//#0x00:
$this->functionsArray[] = function ($parentObj) {
//Do Nothing...
};
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
Implementation of 0x00 NOP
x0 x1 x2
0x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
CPU - Opcode.php
<?php
namespace GameBoy;
class Opcode
{
public $functionsArray = [];
public function __construct()
{
//NOP
//#0x00:
$this->functionsArray[] = function ($parentObj) {
//Do Nothing...
};
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
x0 x1 x2
0x
LD BC, d16
3 12
- - - -
NOP
1 4
- - - -
LD (BC), A
1 8
- - - -
Implementation of 0x01 LD BC, d16
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
$parentObj->registerC =
$parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter);
$parentObj->registerB =
$parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF);
$parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF;
};
Implementation of LD BC, d16
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
Address
PC (Program Counter)
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
$parentObj->registerC =
$parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter);
$parentObj->registerB =
$parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF);
$parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF;
};
Implementation of LD BC, d16
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
Address
PC (Program Counter)
C
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
$parentObj->registerC =
$parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter);
$parentObj->registerB =
$parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF);
$parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF;
};
Implementation of LD BC, d16
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
Address
PC (Program Counter)
B
//LD BC, nn
//#0x01:
$this->functionsArray[] = function ($parentObj) {
$parentObj->registerC =
$parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter);
$parentObj->registerB =
$parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF);
$parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF;
};
Implementation of LD BC, d16
0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301
0x01 0x01 0x03 0x3e 0x99 0x02 0x99
LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A
Data
Instruction
Address
PC (Program Counter)
Implementation of JP a16
x3
cx
JP a16
3 16
- - - -
Implementation of JP a16
x3
cx
JP a16
3 16
- - - -
Jump to address a16
Implementation of JP a16
x3
cx
JP a16
3 16
- - - -
Jump to address a16
0x0000 0x0001 0x0002
0xc3 0x29 0x03
JP a16 0x0329
Data
Instruction
Address
Implementation of JP a16
x3
cx
JP a16
3 16
- - - -
Jump to address a16
0x0000 0x0001 0x0002
0xc3 0x29 0x03
JP a16 0x0329
Data
Instruction
Address
Jump to address 0x0329
Implementation of JP a16
x3
cx
JP a16
3 16
- - - -
Jump to address a16
//JP nn
//#0xC3:
$this->functionsArray[] = function ($parentObj) {
$parentObj->programCounter =
($parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF) << 8) +
$parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter);
};
0x0000 0x0001 0x0002
0xc3 0x29 0x03
JP a16 0x0329
Data
Instruction
Address
Jump to address 0x0329
Run loop
public function executeIteration()
{
$op = 0;
while ($this->stopEmulator == 0) {
$op = $this->memoryRead($this->programCounter);
$this->programCounter = ($this->programCounter + 1) & 0xFFFF;
$this->CPUTicks = $this->TICKTable[$op];
$this->OPCODE[$op]($this);
$this->updateCore();
}
}
Not difficult
Simple, Easy
Let’s read
php-terminal-gameboy-emulator
Thanks
@tomzoh
WE ARE HIRING
Drupal / Mobile App Engineer

Digital Circus, Inc. Tokyo, Japan
@tomzoh
Links
• https://en.wikipedia.org/wiki/Game_Boy
• http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html
• http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header
• http://gameboy.mongenel.com/dmg/asmmemmap.html
More FPS?
PHP5.5.30 OSX Native
FPS: 4
PHP7.0.1 VirtualBox
FPS: 14
Duration in cycles table
<?php
namespace GameBoy;
class TickTables
{
public static $primary = [
//Number of machine cycles for each instruction:
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/
1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0
1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1
2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2
2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3
Duration in cycles table
<?php
namespace GameBoy;
class TickTables
{
public static $primary = [
//Number of machine cycles for each instruction:
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/
1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0
1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1
2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2
2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3
1 machine cycle = 4 clocks
Duration in cycles table
<?php
namespace GameBoy;
class TickTables
{
public static $primary = [
//Number of machine cycles for each instruction:
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/
1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0
1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1
2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2
2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3
1 machine cycle = 4 clocks
x4
cx
CALL NZ,a16
3 24/12
- - - -
Duration in cycles table
<?php
namespace GameBoy;
class TickTables
{
public static $primary = [
//Number of machine cycles for each instruction:
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/
1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0
1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1
2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2
2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3
1 machine cycle = 4 clocks
x4
cx
CALL NZ,a16
3 24/12
- - - -Call address a16 if A resistor
is zero. It takes 24 clocks.
5月 チケット販売開始 /トーク募集開始

6月上旬 トーク募集〆切

6月下旬 タイムテーブル決定
iOS Developers Conference Japan 2016
2016.08.20 https://iosdc.jp
スポンサー企業さま、大絶賛募集中

Contenu connexe

Similaire à Play Gameboy Games in Your Terminal with PHP

Basic computer organization design
Basic computer organization designBasic computer organization design
Basic computer organization designndasharath
 
Ecet 330 final exam new 2016
Ecet 330 final exam new 2016Ecet 330 final exam new 2016
Ecet 330 final exam new 2016Olly_March
 
Section 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction setSection 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction setnueng-kk
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsSreenivas Hanumandla
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Sadiq Rahim
 
Displaying Animated Images on GLCD display with LPC2148 Microcontroller
Displaying Animated Images on GLCD display with LPC2148 MicrocontrollerDisplaying Animated Images on GLCD display with LPC2148 Microcontroller
Displaying Animated Images on GLCD display with LPC2148 MicrocontrollerOmkar Rane
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarizeHisham Mat Hussin
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Kernel Recipes 2013 - Deciphering Oopsies
Kernel Recipes 2013 - Deciphering OopsiesKernel Recipes 2013 - Deciphering Oopsies
Kernel Recipes 2013 - Deciphering OopsiesAnne Nicolas
 

Similaire à Play Gameboy Games in Your Terminal with PHP (20)

amba.ppt
amba.pptamba.ppt
amba.ppt
 
Basic computer organization design
Basic computer organization designBasic computer organization design
Basic computer organization design
 
Ecet 330 final exam new 2016
Ecet 330 final exam new 2016Ecet 330 final exam new 2016
Ecet 330 final exam new 2016
 
Section 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction setSection 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction set
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller ppts
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 
amba (1).ppt
amba (1).pptamba (1).ppt
amba (1).ppt
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Displaying Animated Images on GLCD display with LPC2148 Microcontroller
Displaying Animated Images on GLCD display with LPC2148 MicrocontrollerDisplaying Animated Images on GLCD display with LPC2148 Microcontroller
Displaying Animated Images on GLCD display with LPC2148 Microcontroller
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarize
 
Computer Organisation Part 4
Computer Organisation Part 4Computer Organisation Part 4
Computer Organisation Part 4
 
Assemblers
AssemblersAssemblers
Assemblers
 
Lil endian.ppt
Lil endian.pptLil endian.ppt
Lil endian.ppt
 
Memory Reference instruction
Memory Reference instructionMemory Reference instruction
Memory Reference instruction
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
How old consoles work!
How old consoles work!How old consoles work!
How old consoles work!
 
Kernel Recipes 2013 - Deciphering Oopsies
Kernel Recipes 2013 - Deciphering OopsiesKernel Recipes 2013 - Deciphering Oopsies
Kernel Recipes 2013 - Deciphering Oopsies
 
unit 5.ppt
unit 5.pptunit 5.ppt
unit 5.ppt
 

Plus de Tomoki Hasegawa

Drupal8 〜 モダンなアーキテクチャのPHPベース OSS CMS
Drupal8 〜 モダンなアーキテクチャのPHPベース OSS CMSDrupal8 〜 モダンなアーキテクチャのPHPベース OSS CMS
Drupal8 〜 モダンなアーキテクチャのPHPベース OSS CMSTomoki Hasegawa
 
とある受託ベンダの開発環境
とある受託ベンダの開発環境とある受託ベンダの開発環境
とある受託ベンダの開発環境Tomoki Hasegawa
 
iOS Developers Conference Japan 2016
iOS Developers Conference Japan 2016iOS Developers Conference Japan 2016
iOS Developers Conference Japan 2016Tomoki Hasegawa
 
エンジニアのお祭り
エンジニアのお祭りエンジニアのお祭り
エンジニアのお祭りTomoki Hasegawa
 
勉強会のこちら側とあちら側
勉強会のこちら側とあちら側勉強会のこちら側とあちら側
勉強会のこちら側とあちら側Tomoki Hasegawa
 
tvOSでWebSocketを使う
tvOSでWebSocketを使うtvOSでWebSocketを使う
tvOSでWebSocketを使うTomoki Hasegawa
 
「これを買っている人はこれも買っています」実装してみた PHP side
「これを買っている人はこれも買っています」実装してみた PHP side「これを買っている人はこれも買っています」実装してみた PHP side
「これを買っている人はこれも買っています」実装してみた PHP sideTomoki Hasegawa
 
tvOSネイティブアプリを作る
tvOSネイティブアプリを作るtvOSネイティブアプリを作る
tvOSネイティブアプリを作るTomoki Hasegawa
 
「これを買っている人はこれも買っています」実装してみた
「これを買っている人はこれも買っています」実装してみた「これを買っている人はこれも買っています」実装してみた
「これを買っている人はこれも買っています」実装してみたTomoki Hasegawa
 
Drupal 8 - モダンなアーキテクチャのPHPベースOSS CMS
Drupal 8 - モダンなアーキテクチャのPHPベースOSS CMSDrupal 8 - モダンなアーキテクチャのPHPベースOSS CMS
Drupal 8 - モダンなアーキテクチャのPHPベースOSS CMSTomoki Hasegawa
 
TestFlightみたいなのを自作する
TestFlightみたいなのを自作するTestFlightみたいなのを自作する
TestFlightみたいなのを自作するTomoki Hasegawa
 
PHPでスマホアプリにプッシュ通知する
PHPでスマホアプリにプッシュ通知するPHPでスマホアプリにプッシュ通知する
PHPでスマホアプリにプッシュ通知するTomoki Hasegawa
 
PUSH通知証明書作成ツールを作った
PUSH通知証明書作成ツールを作ったPUSH通知証明書作成ツールを作った
PUSH通知証明書作成ツールを作ったTomoki Hasegawa
 
PHPカンファレンス福岡に 行ってきた
PHPカンファレンス福岡に 行ってきたPHPカンファレンス福岡に 行ってきた
PHPカンファレンス福岡に 行ってきたTomoki Hasegawa
 
CakePHP3ウォークスルー
CakePHP3ウォークスルーCakePHP3ウォークスルー
CakePHP3ウォークスルーTomoki Hasegawa
 
はじめてのiOSアプリ開発 Swift対応版
はじめてのiOSアプリ開発 Swift対応版はじめてのiOSアプリ開発 Swift対応版
はじめてのiOSアプリ開発 Swift対応版Tomoki Hasegawa
 
AppStore申請を一式まるっと自動化する
AppStore申請を一式まるっと自動化するAppStore申請を一式まるっと自動化する
AppStore申請を一式まるっと自動化するTomoki Hasegawa
 
PHPerのためのSwift入門
PHPerのためのSwift入門PHPerのためのSwift入門
PHPerのためのSwift入門Tomoki Hasegawa
 
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版Tomoki Hasegawa
 

Plus de Tomoki Hasegawa (20)

Drupal8 〜 モダンなアーキテクチャのPHPベース OSS CMS
Drupal8 〜 モダンなアーキテクチャのPHPベース OSS CMSDrupal8 〜 モダンなアーキテクチャのPHPベース OSS CMS
Drupal8 〜 モダンなアーキテクチャのPHPベース OSS CMS
 
とある受託ベンダの開発環境
とある受託ベンダの開発環境とある受託ベンダの開発環境
とある受託ベンダの開発環境
 
iOS Developers Conference Japan 2016
iOS Developers Conference Japan 2016iOS Developers Conference Japan 2016
iOS Developers Conference Japan 2016
 
エンジニアのお祭り
エンジニアのお祭りエンジニアのお祭り
エンジニアのお祭り
 
勉強会のこちら側とあちら側
勉強会のこちら側とあちら側勉強会のこちら側とあちら側
勉強会のこちら側とあちら側
 
tvOSでWebSocketを使う
tvOSでWebSocketを使うtvOSでWebSocketを使う
tvOSでWebSocketを使う
 
「これを買っている人はこれも買っています」実装してみた PHP side
「これを買っている人はこれも買っています」実装してみた PHP side「これを買っている人はこれも買っています」実装してみた PHP side
「これを買っている人はこれも買っています」実装してみた PHP side
 
tvOSネイティブアプリを作る
tvOSネイティブアプリを作るtvOSネイティブアプリを作る
tvOSネイティブアプリを作る
 
「これを買っている人はこれも買っています」実装してみた
「これを買っている人はこれも買っています」実装してみた「これを買っている人はこれも買っています」実装してみた
「これを買っている人はこれも買っています」実装してみた
 
Drupal 8 - モダンなアーキテクチャのPHPベースOSS CMS
Drupal 8 - モダンなアーキテクチャのPHPベースOSS CMSDrupal 8 - モダンなアーキテクチャのPHPベースOSS CMS
Drupal 8 - モダンなアーキテクチャのPHPベースOSS CMS
 
TestFlightみたいなのを自作する
TestFlightみたいなのを自作するTestFlightみたいなのを自作する
TestFlightみたいなのを自作する
 
PHPでスマホアプリにプッシュ通知する
PHPでスマホアプリにプッシュ通知するPHPでスマホアプリにプッシュ通知する
PHPでスマホアプリにプッシュ通知する
 
Stargazer Meetup #1
Stargazer Meetup #1Stargazer Meetup #1
Stargazer Meetup #1
 
PUSH通知証明書作成ツールを作った
PUSH通知証明書作成ツールを作ったPUSH通知証明書作成ツールを作った
PUSH通知証明書作成ツールを作った
 
PHPカンファレンス福岡に 行ってきた
PHPカンファレンス福岡に 行ってきたPHPカンファレンス福岡に 行ってきた
PHPカンファレンス福岡に 行ってきた
 
CakePHP3ウォークスルー
CakePHP3ウォークスルーCakePHP3ウォークスルー
CakePHP3ウォークスルー
 
はじめてのiOSアプリ開発 Swift対応版
はじめてのiOSアプリ開発 Swift対応版はじめてのiOSアプリ開発 Swift対応版
はじめてのiOSアプリ開発 Swift対応版
 
AppStore申請を一式まるっと自動化する
AppStore申請を一式まるっと自動化するAppStore申請を一式まるっと自動化する
AppStore申請を一式まるっと自動化する
 
PHPerのためのSwift入門
PHPerのためのSwift入門PHPerのためのSwift入門
PHPerのためのSwift入門
 
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
オプショナル型。〜なんとなく付ける ! ? 撲滅〜 改訂版
 

Dernier

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

Dernier (20)

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Play Gameboy Games in Your Terminal with PHP

  • 2. HASEGAWA Tomoki @tomzoh Web / iOS App Development, Rental Kart Race, Beer, IoT crafting, … hasegawa
 tomoki Digital Circus, Inc. Vice-master CTO Tokyo, Japan Interests
  • 3. ・ Web Development ・ Mobile Apps Development ・ Service ( ) (iOS, Android) (http://appbuilder.jp) Twitter: @tomzoh
  • 7. By Transfrom JPEG version and remove white background. Original by Evan-Amos. - Media:Game-Boy-FL.jpg, Public Domain, https://commons.wikimedia.org/w/index.php?curid=37808150
  • 9.
  • 10.
  • 11.
  • 12. 😮
  • 13. 😮
  • 19. Source Files It’s PHP ! We can read it.
  • 20. Source Files It’s PHP ! Yes, We can! We can read it.
  • 21. Source Files It’s PHP ! Yes, We can! Yes, We can! We can read it.
  • 23. Components of GAMEBOY • CPU / Memory • Display • Sound • Buttons • Communication Port
  • 24. Components of GAMEBOY • CPU / Memory • Display • Sound • Buttons • Communication Port
  • 26.
  • 27.
  • 28. Buttons - Keyboard.php <?php namespace GameBoy; class Keyboard { public $core; public $file; public $keyPressing = null; public $started = false; public function __construct(Core $core) { $this->core = $core; exec('stty -icanon'); $this->file = fopen('php://stdin', 'r'); stream_set_blocking($this->file, false); } public function check() {
  • 29. Buttons - Keyboard.php <?php namespace GameBoy; class Keyboard { public $core; public $file; public $keyPressing = null; public $started = false; public function __construct(Core $core) { $this->core = $core; exec('stty -icanon'); $this->file = fopen('php://stdin', 'r'); stream_set_blocking($this->file, false); } public function check() {
  • 30. How to sense buttons
  • 31. How to sense buttons $this->file = fopen('php://stdin', 'r');
  • 32. How to sense buttons $this->file = fopen('php://stdin', 'r'); $key = fread($this->file, 1);
  • 35. CPU
  • 36. SHARP LR35902 instruction set http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html 1byte instructions Prefix CB instructions 144 instructions 256 instructions+ = 400 instructions
  • 37. SHARP LR35902 resistors http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html 15 … 8 7 … 0 A F B C H L 15 … 8 7 … 0 SP (Stack Pointer) PC (Program Counter) 8bit / 16bit resistors 16bit resistors Flag registor 7 6 5 4 3 2 1 0 Z N H C 0 0 0 0 •Z - Zero Flag •N - Subtract Flag •H - Half Carry Flag •C - Carry Flag •0 - Not uses, always zero
  • 38. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - -
  • 39. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Length in bytes Address LD A, d8 2 8 - - - -
  • 40. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Duration in cyclesLength in bytes Address LD A, d8 2 8 - - - -
  • 41. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Duration in cycles Flags affected Length in bytes Address LD A, d8 2 8 - - - -
  • 42. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - -
  • 43. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - - PC (Program Counter)
  • 44. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction Load 0x0301 into BC resistor x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - - PC (Program Counter)
  • 45. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - - PC (Program Counter)
  • 46. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - - Load 0x99 into A resistor PC (Program Counter)
  • 47. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - - PC (Program Counter)
  • 48. Instruction in memory 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction Load A resistor’s value into memory indicates with BC resistor x0 x1 x2 xE 0x 3x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Address LD A, d8 2 8 - - - - PC (Program Counter)
  • 49.
  • 50.
  • 51. CPU - Opcode.php <?php namespace GameBoy; class Opcode { public $functionsArray = []; public function __construct() { //NOP //#0x00: $this->functionsArray[] = function ($parentObj) { //Do Nothing... }; //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) {
  • 52. CPU - Opcode.php <?php namespace GameBoy; class Opcode { public $functionsArray = []; public function __construct() { //NOP //#0x00: $this->functionsArray[] = function ($parentObj) { //Do Nothing... }; //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { x0 x1 x2 0x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - -
  • 53. CPU - Opcode.php <?php namespace GameBoy; class Opcode { public $functionsArray = []; public function __construct() { //NOP //#0x00: $this->functionsArray[] = function ($parentObj) { //Do Nothing... }; //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { Implementation of 0x00 NOP x0 x1 x2 0x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - -
  • 54. CPU - Opcode.php <?php namespace GameBoy; class Opcode { public $functionsArray = []; public function __construct() { //NOP //#0x00: $this->functionsArray[] = function ($parentObj) { //Do Nothing... }; //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { x0 x1 x2 0x LD BC, d16 3 12 - - - - NOP 1 4 - - - - LD (BC), A 1 8 - - - - Implementation of 0x01 LD BC, d16
  • 55. //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { $parentObj->registerC = $parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter); $parentObj->registerB = $parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF); $parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF; }; Implementation of LD BC, d16 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction Address PC (Program Counter)
  • 56. //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { $parentObj->registerC = $parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter); $parentObj->registerB = $parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF); $parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF; }; Implementation of LD BC, d16 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction Address PC (Program Counter) C
  • 57. //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { $parentObj->registerC = $parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter); $parentObj->registerB = $parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF); $parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF; }; Implementation of LD BC, d16 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction Address PC (Program Counter) B
  • 58. //LD BC, nn //#0x01: $this->functionsArray[] = function ($parentObj) { $parentObj->registerC = $parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter); $parentObj->registerB = $parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF); $parentObj->programCounter = ($parentObj->programCounter + 2) & 0xFFFF; }; Implementation of LD BC, d16 0x0000 0x0001 0x0002 0x003 0x004 0x005 0x0301 0x01 0x01 0x03 0x3e 0x99 0x02 0x99 LD BC, d16 0x0301 LD A, d8 0x99 LD (BC), A Data Instruction Address PC (Program Counter)
  • 59. Implementation of JP a16 x3 cx JP a16 3 16 - - - -
  • 60. Implementation of JP a16 x3 cx JP a16 3 16 - - - - Jump to address a16
  • 61. Implementation of JP a16 x3 cx JP a16 3 16 - - - - Jump to address a16 0x0000 0x0001 0x0002 0xc3 0x29 0x03 JP a16 0x0329 Data Instruction Address
  • 62. Implementation of JP a16 x3 cx JP a16 3 16 - - - - Jump to address a16 0x0000 0x0001 0x0002 0xc3 0x29 0x03 JP a16 0x0329 Data Instruction Address Jump to address 0x0329
  • 63. Implementation of JP a16 x3 cx JP a16 3 16 - - - - Jump to address a16 //JP nn //#0xC3: $this->functionsArray[] = function ($parentObj) { $parentObj->programCounter = ($parentObj->memoryRead(($parentObj->programCounter + 1) & 0xFFFF) << 8) + $parentObj->memoryReader[$parentObj->programCounter]($parentObj, $parentObj->programCounter); }; 0x0000 0x0001 0x0002 0xc3 0x29 0x03 JP a16 0x0329 Data Instruction Address Jump to address 0x0329
  • 64. Run loop public function executeIteration() { $op = 0; while ($this->stopEmulator == 0) { $op = $this->memoryRead($this->programCounter); $this->programCounter = ($this->programCounter + 1) & 0xFFFF; $this->CPUTicks = $this->TICKTable[$op]; $this->OPCODE[$op]($this); $this->updateCore(); } }
  • 67. Thanks @tomzoh WE ARE HIRING Drupal / Mobile App Engineer
 Digital Circus, Inc. Tokyo, Japan @tomzoh
  • 68. Links • https://en.wikipedia.org/wiki/Game_Boy • http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html • http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header • http://gameboy.mongenel.com/dmg/asmmemmap.html
  • 69. More FPS? PHP5.5.30 OSX Native FPS: 4 PHP7.0.1 VirtualBox FPS: 14
  • 70. Duration in cycles table <?php namespace GameBoy; class TickTables { public static $primary = [ //Number of machine cycles for each instruction: /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/ 1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0 1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1 2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2 2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3
  • 71. Duration in cycles table <?php namespace GameBoy; class TickTables { public static $primary = [ //Number of machine cycles for each instruction: /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/ 1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0 1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1 2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2 2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3 1 machine cycle = 4 clocks
  • 72. Duration in cycles table <?php namespace GameBoy; class TickTables { public static $primary = [ //Number of machine cycles for each instruction: /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/ 1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0 1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1 2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2 2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3 1 machine cycle = 4 clocks x4 cx CALL NZ,a16 3 24/12 - - - -
  • 73. Duration in cycles table <?php namespace GameBoy; class TickTables { public static $primary = [ //Number of machine cycles for each instruction: /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/ 1, 3, 2, 2, 1, 1, 2, 1, 5, 2, 2, 2, 1, 1, 2, 1, //0 1, 3, 2, 2, 1, 1, 2, 1, 3, 2, 2, 2, 1, 1, 2, 1, //1 2, 3, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, //2 2, 3, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 2, 1, //3 1 machine cycle = 4 clocks x4 cx CALL NZ,a16 3 24/12 - - - -Call address a16 if A resistor is zero. It takes 24 clocks.
  • 74. 5月 チケット販売開始 /トーク募集開始
 6月上旬 トーク募集〆切
 6月下旬 タイムテーブル決定 iOS Developers Conference Japan 2016 2016.08.20 https://iosdc.jp スポンサー企業さま、大絶賛募集中