Emulation Gameboy
Emulation Gameboy
Emulation Gameboy
Petar Veličković
University of Cambridge
C�������� C����� S����� S�����
13 July 2016
What is emulation?
Emulation
What is emulation?
Emulator vs simulator
An emulator executes the original code (ROM) wri�en for the console,
whereas the simulator represents an entirely new game.
GameBoy
Console exterior
Today’s task
Cartridge GameBoy
insert
⇡
⇡
1100 0011 0000 1100
0000 0010 0000 0000
input
0000 0000 0000 0000
0000 0010 1111 1111
1111 1111 1111 1111
ROM (Game code) Emulator
How to make a (GameBoy) emulator? Petar Veličković
Introduction Essential emulator Emulator extensions
Modular approach
I Why do this?
I Debugging becomes much easier because the e�ects of
programmer errors are local to a subsystem.
I The modules may be reusable in other emulator projects – the
hardware is standardised.
I Amenable to object-oriented programming.
Memory
Memory ROM Cartridge
Processor
controller reader
RAM
Processor
Processor
Processor
Processor
Interpreter emulator
IF DC EX
Instruction Fetch Decode Execute
Processor
Instruction Fetch
IF
Instruction Fetch
Processor
Memory interface
I For now, the processor only needs to know that these functions
exist—we will consider their actual implementations later.
Processor
Decode
DC
Decode
Processor
GameBoy arhitecture
Processor
Execute
EX
Execute
Processor
Processor state
Processor
Flags
ZF OF HCF CF
Processor
11 25 6 7 3 ...
PC SP A B C
T F F F 15732
ZF OF HCF CF ticks
CPU
Processor
Example: Sub(A, 5)
Memory
6 12 1 214 5 0 255 4
... 9 10 11 12 13 14 ... Address
11 25 6 7 3 ...
PC SP A B C
T F F F 15732
ZF OF HCF CF ticks
CPU
Processor
Example: Sub(A, 5)
Memory
6 12 1 214 5 0 255 4
... 9 10 11 12 13 14 ... Address
11 25 6 7 3 ... Sub(A, n)
PC SP A B C
T F F F 15732
ZF OF HCF CF ticks
CPU
Processor
Example: Sub(A, 5)
Memory
6 12 1 214 5 0 255 4
... 9 10 11 12 13 14 ... Address
12 25 6 7 3 ... Sub(A, 5)
PC SP A B C
T F F F 15732
ZF OF HCF CF ticks
CPU
Processor
Example: Sub(A, 5)
Memory
6 12 1 214 5 0 255 4
... 9 10 11 12 13 14 ... Address
13 25 1 7 3 ... Sub(A, 5)
PC SP A B C
F T F F 15739
ZF OF HCF CF ticks
CPU
Memory
Memory
Memory
Memory ROM
controller
RAM
Memory
Naïve implementation
Memory
Gotchas
GPU
GPU
GPU
GPU
GameBoy graphics
GPU
GPU
GPU
Tiling system
GPU
1 2 2 3 ...
.. .. .. .. . .
. . . . .
Background map Background
Input
Input
Input
Input
Input
I Input is processed using a special-purpose JOYP register, which
the processor may access at address 65280. The wires leading
to that register are connected in the following way:
7
6
5
4
# START
3
JOYP
" SELECT
B
2
! A
1
0
Sprites
Sprites
Sprites
Sprites
Interrupts
Interrupts
Interrupts
Interrupts
IF DC EX
Instruction Fetch Decode Execute
IRQ
Interrupt Request
Interrupts
Interrupts
GameBoy interrupts
Interrupts
We’re done!
I Thank you!