from Hacker News

Writing my first Gameboy Emulator

by RupertWiser on 12/30/20, 5:52 PM with 18 comments

  • by fwsgonzo on 12/30/20, 7:41 PM

    It's super interesting to write your first emulator. I wrote a GBC emulator too once, and I wrote down all the problems I encountered that weren't easy to solve:

    https://github.com/fwsGonzo/gamebro/blob/master/POSTERITY.md

    Many of the issues are not documented anywhere, and it is just about guessing what the hardware did - and thus, what the developers back in the day relied on!

  • by Gunax on 12/31/20, 12:27 AM

    I also wrote a gameboy emulator a few years ago... But I disagree about it being fun.

    The truth is it's rather tedious. There are 256 opcodes you will need to create. Each has certain flags you will need to check that change it's operation.

    Some of those flags are undocumented, and several of the opcodes actually have hardware level bugs that make them act differently than the CPU document describes.

    So after creating every opcode, you will inevitably have bugs which you need to fix.

    After fixing those you will still not have games running because of so many undocumented/buggy opcodes, so now you need to figure out how an actual gameboy operated.

    At this point I was only able to solve it be getting a working emulator and executing the same program on each until their states diverged.

    I did find it interesting to learn about low level hardware, but I'd say the project is 50% reading specs, 10% interesting, and 40% tedious pain-in-the-butt.

    I never did get sound working, and the graphics are buggy, but I think I got far enough that I learned all there was to learn.

  • by anshargal on 12/30/20, 9:31 PM

    If you want to write a game console emulator, but prefer to start with something simple — I suggest to look into https://en.wikipedia.org/wiki/CHIP-8 It could be implemented in a couple of evenings in any language.
  • by someperson on 12/31/20, 1:39 AM

    There are dozens of toy GB emulators, but nobody has yet emulated the wildly successful Bandai Digimon Digivice. It's based on near-identical technology to Bandai's "Tamagotchi" virtual pet though Digimon was marketed mostly towards at boys and Tamagotchi was marketed mostly towards girls.

    It's from the same era as the Game Boy Color and has some interesting features (serial communications between devices, and the infamous "tab cheat" that momentarily disconnecting the battery with a plastic tab to randomize the memory contents).

    Interesting how Pokemon is widely emulated, but nobody ever bothered with Digimon. There has been multiple generations of Digivice hardware, so best start at the original.

    I'd like to see somebody take on the reverse-engineering challenge. I don't think there's even a ROM dump yet.

    They've actually started selling new stock recently (20th Anniversary Digivice), including at retail stores for around $30 each.

  • by luxurytent on 12/30/20, 9:42 PM

    Thank you for sharing! One of my very slow (two kids one new born makes life slow) but deliberate projects is to write a Gameboy emulator and every new article or write-up provides more context into this confusing world.
  • by CyberRabbi on 12/30/20, 7:40 PM

    Excited to see his next gameboy emulator
  • by TheChaplain on 12/31/20, 11:14 AM

    Very interesting article but a bit short. If anyone have links to more in-depths journals of writing emulators, please let me know. I'm very interested in learning.
  • by edoceo on 12/30/20, 9:32 PM

    Is it possible to get QEMU to emulate these kinds of hardware? Assuming one knows enough C to make the machine and bus emulator that fits into QEMU?