How to write a Game Boy emulator
Writing an emulator may seem like an impossible task, but I can assure you that it's very possible. I'll go further and say that it's fun and rewarding. The difficult part is not writing the emulator, it's understanding how the emulated machine works. As always, code is cheap, but documentation is priceless.
This tutorial will be divided into a series of blog posts. Each post will come with all needed code, and will be associated to a single commit in the gammaboy GitHub repository . The goal is to write the emulator incrementally, so that people can follow along if they want and create their own emulator.
Table of contents
- 2017-02-04 Part 1: Loading the bios
- 2017-02-19 Part 2: Registers and flags
- 2017-05-27 Part 3: Fetch, decode, execute
- 2017-07-01 Part 4: The CPU instructions of the bios
- 2017-12-23 Part 5: Rewriting gammaboy in Go
- 2018-02-18 Part 6: Drawing the background
- 2018-02-24 Part 7: Blargg's CPU test ROM #6
- 2018-03-04 Part 8: Blargg's CPU test ROMs #1,3,4,5,7,8,9,10,11
- 2018-03-17 Part 9: Interrupts
- 2018-03-25 Part 10: The timer
Credits & references
This tutorial is only possible because people before me have documented how the Game Boy works, and made it available for free on the internet. Here is a non-exhaustive list of references I've used to write this blog post series:
- http://bgb.bircd.org/pandocs.htm
- http://gbdev.gg8.se/wiki/articles/Main_Page
- http://goldencrystal.free.fr/GBZ80Opcodes.pdf
- http://imrannazar.com/GameBoy-Emulation-in-JavaScript
- http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf
- http://zilog.com/docs/z80/um0080.pdf
- http://www.codeslinger.co.uk/pages/projects/gameboy.html
- http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html
- https://github.com/AntonioND/giibiiadvance/blob/master/docs/TCAGBD.pdf
- https://realboyemulator.wordpress.com/
- https://www.reddit.com/r/EmuDev/