エミュレータ エミュレータとは、機械装置やコンピュータのハードウェア (PC、ゲーム機など)の構造を、別の装置やソフトウェアで 模倣することで実現させたもの。 In computing, an emulator is hardware or software that enables one computer system to behave like another computer system. Emulator terminal-gameboy-emulator
プログラムの実行 Program execution AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 AをAでXOR HLに0xffdfを入れる Cに0x10を入れる Bに0x00を入れる HLが指すアドレスにAの値を入れる Bを-1する Load 0xffdf into HL XOR A with A Load 0x10 into C Load 0x00 into B Load a value A has into memory address HL points at Decrement B
8bit / 16bit registers 16bit registers Flag register
; / ) $ •Z - Zero Flag •N - Subtract Flag •H - Half Carry Flag •C - Carry Flag •0 - Not uses, always zero レジスタ: CPUが持つ、プログラム言語で言う変数 Registers: Variables in programing language.
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B PC
プログラムカウンタ Program Counter +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 01E0 01 E0 85 E1 D1 C1 F1 D9 AF 21 FF DF 0E 10 06 00 01F0 32 05 20 FC 0D 20 F9 3E 0D F3 E0 0F E0 FF AF E0 現在実行中の命令のアドレスを指す特殊なレジスタ。 A special register that contains the address of the instruction being executed now. AF 21 DF FF 0E 10 06 00 32 05 XOR A LD HL, 0xFFDF LD C, 0x10 LD B, 0x00 LD (HL-), A DEC B PC
LR35902 の命令 - LD LR35902 instructions - LD LD BC, 0x1234 BCレジスタに0x1234を入れる。 Load BC register with 0x1234. LD (BC), A BCレジスタの指し示すメモリアドレスにAレジスタ の内容を入れる。 Load a value A register has into memory BC register points at.
LR35902 の命令 - JP / CD LR35902 instructions - JP / CD JP 0x5678 0x5678番地にジャンプする。 Jump to location 0x5678. CALL 0x8181 スタックに現在のアドレスを入れて0x8181番地に ジャンプする。 Push current address to stack pointer, then jump to 0x8181. RET スタック先頭のアドレスにジャンプする。 Jump to the location of top of stack pointer.
public static function opcode1(Core $core) { $core->registerC = $core->memoryRead($core->programCounter); $core->registerB = $core->memoryRead(($core->programCounter + 1) & 0xFFFF); $core->programCounter = ($core->programCounter + 2) & 0xFFFF; } LC BC, nn の実装 Implementation of LD BC, nn PC PC + 1 0x01 0x01 0x03 LD BC, nn 0x0301 Data Address BCレジスタに指定したアドレスのメモリの値を入れる。 Load BC register with nn.
public static function opcode1(Core $core) { $core->registerC = $core->memoryRead($core->programCounter); $core->registerB = $core->memoryRead(($core->programCounter + 1) & 0xFFFF); $core->programCounter = ($core->programCounter + 2) & 0xFFFF; } LC BC, nn の実装 Implementation of LD BC, nn PC PC + 1 0x01 0x01 0x03 LD BC, nn 0x0301 Data Address PCを次の命令まで進める。 Move PC register to next instruction.
$core->memoryRead($core->programCounter); // //Main RAM, MBC RAM, GBC Main RAM, VRAM, etc. // //Main Core Memory public $memory = []; Core.php メインメモリは配列になっている。 Main memory is defined as array.
$core->memoryRead($core->programCounter); // //Main RAM, MBC RAM, GBC Main RAM, VRAM, etc. // //Main Core Memory public $memory = []; Core.php メインメモリは配列になっている。 Main memory is defined as array. なぜ $core->memory[$core->programCounter] ではない? Q Why not $core->memory[$core->programCounter] ?
GAMEBOYのメモリマップ Memory map of GAMEBOY $FFFF Interrupt Enable Flag I/O $FF80-$FFFE Zero Page - 127 bytes RAM $FF00-$FF7F Hardware I/O Registers I/O $FEA0-$FEFF Unusable Memory $FE00-$FE9F OAM - Object Attribute Memory Video RAM $E000-$FDFF Echo RAM - Reserved, Do Not Use $D000-$DFFF Internal RAM - Bank 1-7 (switchable - CGB only) RAM $C000-$CFFF Internal RAM - Bank 0 (fixed) $A000-$BFFF Cartridge RAM (If Available) Cartridge $9C00-$9FFF BG Map Data 2 Video RAM $9800-$9BFF BG Map Data 1 $8000-$97FF Character RAM $4000-$7FFF Cartridge ROM - Switchable Banks 1-xx Cartridge $0150-$3FFF Cartridge ROM - Bank 0 (fixed) $0100-$014F Cartridge Header Area $0000-$00FF Restart and Interrupt Vectors ROM IUUQXXXIVDLpOHBNFTDPN QJE #Z5SBOTGSPN+1&(WFSTJPOBOESFNPWFXIJUFCBDLHSPVOE0SJHJOBMCZ&WBO"NPT.FEJB(BNF#PZ'-KQH
1VCMJD%PNBJO
IUUQTDPNNPOTXJLJNFEJBPSHXJOEFYQIQ DVSJE A. メモリアクセスはそのアドレスに よって動作が違うから。 A. Because a result of memory access depends on its location.
ゲームボーイのハードウェアコンポネント CPU I/O Keys Sound Video Display Com Port Memory • RAM • Game Cartridge • Video RAM Hardware components of GAMEBOY CPUはキーにI/O経由でアクセスする CPU accesses keys through the I/O
キー状態の取得 public function __construct(Core $core) { $this->core = $core; exec('stty -icanon -echo'); $this->file = fopen('php://stdin', 'r'); stream_set_blocking($this->file, false); } public function check() { $key = fread($this->file, 1); if (!empty($key)) { $this->keyDown($key); } elseif (!empty($this->keyPressing)) { $this->keyUp($this->keyPressing); } $this->keyPressing = $key; } Get key status 標準入力を開いて… Open standard in and...
キー状態の取得 public function __construct(Core $core) { $this->core = $core; exec('stty -icanon -echo'); $this->file = fopen('php://stdin', 'r'); stream_set_blocking($this->file, false); } public function check() { $key = fread($this->file, 1); if (!empty($key)) { $this->keyDown($key); } elseif (!empty($this->keyPressing)) { $this->keyUp($this->keyPressing); } $this->keyPressing = $key; } Get key status 標準入力を開いて… Open standard in and... fread()で1文字取る! Get a character with fread!
セットアップ How to run $ git clone https://github.com/gabrielrcouto/php- terminal-gameboy-emulator.git $ cd php-terminal-gameboy-emulator $ composer install -o $ bin/php-gameboy drmario.rom
Pentiumのアドレスバスとデータバス IUUQEPXOMPBEJOUFMDPNEFTJHOQFOUJVNEBUBTIUTQEG $$දࣔܧঝ
IUUQTDPNNPOTXJLJNFEJBPSHXJOEFYQIQ DVSJE D0〜D63 A3〜A31 Data bus and address bus of Pentium