Download - Como programar melhor jogando game boy
2016 PHPSP+IMA
COMO PROGRAMAR
MELHOR JOGANDO
GAME BOY
IT’S ME, BOB!
BOB S2 PHP
Cara, o que dá
para fazer com
PHP?
?
Level 1 - Motivação
X 1
Praticamente
tudo o que você
queira fazer!
Rasmus
Lerdorf
TIME
1994
I NEED TO DO A
GUEST BOOK FOR
MY WEBSITE
TIME
1994
PERSONAL HOME
PAGE TOOLS!
TIME
1994
PHP = Scripts
TIME
1994
PHP = Linguagem
TIME
1997
PHP: Hypertext
Preprocessor
TIME
1997
vvsvvhvvrvvWebAbrangente
Java - 1991
James Gosling
Sun Microsystems
Originally designed
for interactive
television, but it
was too advanced for
the digital cable
television industry
at the time.
ECMAscript - 1995
Brendan Eich
Netscape
Standardized
specification of a
scripting language
for browsers.
CAMPINAS
SÃO PAULO
Projetos que gostei
+game engine
+websocket server
+3D printer
+wifi booster
+..
+..
+..
+js gameboy emulator
+..
+..
+..
+..
JavaScript GameBoy
Emulator
by Grant Galitz
de 2010
suportava até IE
era possível salvar
emulava colorido
perfeito!
vvvvvivvvvv
Se alguém me falasse
que existia um
emulador de Game Boy
em PHP, eu iria
duvidar!
Um projeto desses
vai inspirar as
pessoas a programar o
que gostam, e a ver o
PHP com outros olhos.
Level 2 - Desafios
X 1
Como vou renderizar
o jogo?
ASCII
DRAWILLE
8 pontos por
caractere
..
..
..
..
DRAWILLE
GameBoy Hardware
CPU
8-bit Sharp LR35902
4.19 MHz
RAM / VIDEO RAM
8 kB
DISPLAY
160 × 144 pixels
Tudo está na
PAN DOCS
bgb.bircd.org/
pandocs.txt
0100-014F
cartridge header
0100-0103 entry point
0134-0143 game title
0149 RAM size
014E-014F checksums
3e01 1801 af02 c9fa
46d0 e001 18f6 cd59
23f0 41e6 0320 fa46
f041 e603 20fa 7ea0
c97b 8627 227a 8e27
223e 008e 2722 3e00
8e27 773e 01e0 e07e
cb37 e60f c83e 0932
3e99 3232 77c9 f5c5
d5e5 f0b1 a728 0bfa
f1c4 a728 05f0 efa7
2009 f0e1 fe03 2803
cdb6 ffcd 2d2e f0b1
3e01 1801 af02 c9fa
46d0 e001 18f6 cd59
23f0 41e6 0320 fa46
f041 e603 20fa 7ea0
c97b 8627 227a 8e27
223e 008e 2722 3e00
8e27 773e 01e0 e07e
cb37 e60f c83e 0932
3e99 3232 77c9 f5c5
d5e5 f0b1 a728 0bfa
f1c4 a728 05f0 efa7
2009 f0e1 fe03 2803
cdb6 ffcd 2d2e f0b1
EXECUTÁVEL
Conjunto de instruções
Bytecode
Cada instrução
Opcode + Parâmeros
A CPU do GameBoy tem
quase 512 Opcodes
0x03
INC BC
1 8
INC - Incrementa
BC - Registro da CPU
1 - Tamanho da
instrução (em bytes)
8 - Ciclos de CPU
Opcode.php
Função opcode3
$core->registerB =
(($temp_var >> 8) & 0xFF);
$core->registerC =
($temp_var & 0xFF);
<?php
while (true) {
executeIteration();
runInterrupt();
updateCore();
}
EMULAR UMA CPU
=
LOOP INFINITO
INTERRUPÇÕES
LCD
SOUND
TIME
JOYPAD
SERIAL
Keyboard.php
exec('stty -icanon -echo');
$this->file = fopen(
'php://stdin', 'r');
stream_set_blocking(
$this->file, false);
// Quando é pressionado
$this->core->
joyPadEvent($keyCode,
true);
Core.php
drawSpritesForLine($line)
$spriteX = (0xFF & $this-
>memory[0xFE00 + $oamIx--])
- 8;
$spriteY = (0xFF & $this-
>memory[0xFE00 + $oamIx--])
- 16;
drawPartBgSprite();
drawPartFgSprite();
TIME
03:00
RODOU!
Level 3 - Aprendizado
X 1
O PHP NÃO TEM INT8/
INT16/INT32 E ISSO FAZ
FALTA
PHP 7
MEMORY OPTIMIZATION
Reduce number of
allocations
Reduce memory usage
Reduce indirection
PHP 5
PHP 7
UM EMULADOR
FUNCIONA QUASE
DA MESMA FORMA QUE
UM INTERPRETADOR
GRANDE PARTE DO
CÓDIGO É EXECUTADA
MILHARES DE VEZES!
XDEBUG PROFILING
<?php
$a = 1;
ASSIGN $a 1
RETURN 1
LEXER/PARSER/COMPILER
ZEND VM
zend_vm_execute.h
ZEND_API void execute_ex
while (1) {
…
…
…
}
OTIMIZANDO AO EXTREMO
<?php
$a = 0;
$a++;
ASSIGN !0, 0
POST_INC ~2 !0
FREE ~2
RETURN 1
OTIMIZANDO AO EXTREMO
<?php
$a = 0;
++$a;
ASSIGN !0, 0
PRE_INC !0
RETURN 1
OTIMIZANDO AO EXTREMO
Use o que o PHP te permite
fazer!
Opcode::run($this, 0x76);
…
$function = 'opcode'.$address;
return Opcode:$function($core);
…
Opcode::{‘opcode'.$op}($this);
v0.0.1
2 FPS
v0.1.0
14 FPS
Level 4 - Repercussão
X 1
Hey Pokemao, agora
você já pode jogar no
servidor do trampo!
.gitignore
vendor/
This is important
because the install
command checks if a
lock file is present,
and if it is, it
downloads the versions
specified there
(regardless of what
composer.json says).
LINT / PHP CS
BUILD
CORREÇÕES DE INGLÊS
…
.travis.yml
language: php
php:
- 5.6
- 7.0
script:
- bin/phing
build.xml
…
<phingCall target="phplint" />
<phingCall target="phpunit" />
<phingCall target="phpcs" />
…
CONSEGUI!
VAI BRASIL!
ZEREI A VIDA!
GC = Garbage
Collection
PHP 7
Strings/Arrays/Objetos
zend.enable_gc = 0
"when you create a lot
of objects that should
stay in memory. So GC
can't clean them up
and just wasting CPU
time."
O Composer já teve
problemas com isso.
ZEREI A VIDA 2X!
hasegawatomoki/reading-php-
terminalgameboyemulator
1107
php-terminal-gameboy-
emulator
9773
php-src
8097
composer
3188
doctrine2
47518
facebook/react
19678
rg3/youtube-dl
35013
torvalds/linux
Level 5 - Futuro
X 1
Eu não sou DIFERENTE
de vocês, apenas tive
FOCO!
Acredito que TODOS
VOCÊS POSSUEM
CAPACIDADE para FAZER
projetos SUPER
INCRÍVEIS.
MEU MUITO OBRIGADO
DE CORAÇÃO!
PHP
@GABRIELRCOUTO
GITHUB.COM/
GABRIELRCOUTO
joind.in/talk/32aa5
TRABALHE COMIGO!
MEMED PHPSPAAAAAAAAAAP
Level Bônus
X 9999999999
overflow
AS ESTRELAS DESSE
PROJETO,
SÃO VOCÊS
OBRIGADO POR FAZER
PARTE!