11 ms·
I mentioned this already in another thread, but if you are interested in emulating hardware or just how CPUs and hardware work in general, writing a Game Boy em
by anyfoo 8y ago
I mentioned this already in another thread, but if you are interested in emulating hardware or just how CPUs and hardware work in general, writing a Game Boy emulator is about the most fun and educational project you can take.
The Game Boy hardware is, on its surface, extremely simple (as an example, there is no “operating system”, only a 256 byte (!) boot ROM that pretty much only serves to display and validate the Nintendo logo shown at start), and it has a vast library of games available for it that make use of that hardware to varying degrees.
This means that you can get really good results really fast. Especially the earlier games, like Tetris, don’t rely on fine grained implementation details too much, so even a sloppy, quickly put together emulation can run them well.
But if you then strive for accuracy or just being able to run more complex games, you can take things to almost arbitrarily detailed levels of this somewhat “fractal” complexity, uncovering and implementing all sorts of interesting hardware intricacies.
Contrast this with even slightly more recent game consoles, where you will have a lot of busywork ahead of you to even get the system past any reasonable definition of “booting”, without any gratifying visual feedback. With the Game Boy on the other hand, getting to a game’s title screen, with working buttons and all, is actually pretty simple.
- Legogris 8y agoI actually started C programming on Game Boy back in the days, but for me the Game Boy Advance really hit the sweet spot. ARM (nicer instruction set) and all of the close-to-the-metal characteristics you name above. If you want to write a complete emulator, I can imagine that the Game Boy Advance can be a bit more of an undertaking with the different alternative graphics modes.
- qop 8y agoA gba emulator is my dream project. Gosh I've wanted to sit down and do it forever! There are some really nice ones out there too. There are a few js-based ones that can run in the browser!
- Graziano_M 8y agoI haven't written a GBA emulator, but GBA got me into ARM. Tonc's old guide to ARM[1] I'll still send to people who want to learn ARM. [1] https://www.coranac.com/tonc/text/asm.htm https://www.coranac.com/tonc/text/asm.htm
- severino 8y agoSo, how does one guy not familiar with this low level stuff, nor with GB internals or those 8-bit processors starts writing an emulator like this? Is there any suggested road one could follow, or something like that?
- anyfoo 8y agoLearning how to program a similar 8bit processor in assembly is the first step. Z80 is closest as the Game Boy CPU is based on that (though Z80 has some more features), but any relatively common 8bit CPU such as 8080 or the different 6502 will give you enough context. If you've done assembly already, this is trivial, if not, those CPUs are a good place to start and not hard. I'd say that merely getting a feel for the basics are enough. After that, realistically, I would start looking at one of the existing GB emulator write ups, just enough to understand how things fit together. You can get pretty far on the Game Boy e.g. without even implementing interrupts (not sure, I don't think the boot ROM really needs them), so don't hesitate to experiment already. Finally, have a few references ready (like available opcode tables and the infamous Game Boy CPU pdf that's easy to find), but keeping in mind that they do contain inaccuracies. A lot of understanding will come while implementing.
- severino 8y agoThanks for your advice. Being my first computer a MSX, it's good to know the GameBoy CPU is similar to the Z80. When I read it was a custom Sharp one, I thought it was a completely different world.