golangemusIgnacio Sánchez Ginés
@drhelius
Emulator = legalROM = ilegal
Emulator ≠ Simulator
InterpreterLD A,(HL)SUB 1JR C,CONTINUECP BJR NZ,LOOP
Decode
Read
Exec
Binary Translation
TargetMachineCode
LD A,(HL)SUB 1JR C,CONTINUECP BJR NZ,LOOP
Dynamic Recompilation
Trans
Read
Exec
LD A,(HL)SUB 1JR C,CONTINUECP BJR NZ,LOOP
TargetMachineCode
CPUMEM
IO
Audio
Video
Input
CPU6502 Z80
Game Boy *Master SystemGame Gear
MSXZX Spectrum
NESAtari 2600Commodore 64
Apple 2Super NES 65816
CPU MEM8-bit
16-bit
0000
FFFF
0
65535
16KB
16KB
16KB
16KB
8DC4F3CD293D2144FF3E92BE20FDCD0C........
parameter
opcode opcodeopcode
parameter
Main Loopwhile true {
updateCPU() updateVideo() updateInput() updateAudio()
}
updateCPU() { opcode = fetchOpcode()runOpcode(opcode)
}
100 clks N clks
CPU
Video
Input
CPU4 MHz
MEM
Timer
Audio
Video
InputCart
Game Boy
CPU
H L
B C D E
SPPC
A F
16 bit 8 bit
Flags
0 0H C 0 0Z N1 05 4 3 27 6
16 KB ROM Bank 016 KB switchable ROM bank
8 KB Video RAM
8 KB switchable RAM bank8 KB internal RAM
Mirror 8 KB internal RAMSprite Memory (OAM)
EmptyIO PortsEmpty
Internal RAM
Interrupt Register
cartridge
FF4CFF80
FEA0
FF00
FFFF
FE00E000
C000A000
80004000
0000
cartridge
16 KB ROM Bank 0
16 KB switchable ROM bank
8000
4000
0000
Bank 0
Bank 1
Bank 2
Bank 3
Bank 4
...
fixed00000
04000
08000
0C000
10000
14000
switchable
Bank 4
Visible160x144
HBlank
VBlank 1.08 ms
48.6 us
Demo Emulator
main
core
glfw
opengl
cpu
video
input
Workshop
go get -u github.com/drhelius/demo-emulator
cd $GOPATH/src/github.com/drhelius
go run main.go -rom workshop.rom