

The challenge with this approach is that you (the developer building the emulator) need to be able to write a function to implement each of these instructions. In JavaScript, that might look something like this:Ĭonst lookup = One way to implement the CPU is to have a lookup table that maps opcodes to functions that execute a particular instruction. You're using a programming language to fake (or emulate) the internals of how the Game Boy works. But in an emulator, you don't have the physical Game Boy hardware. So now you know what the CPU is supposed to do, but how does it actually do it? In an actual Game Boy, each of the bits from a single instruction gets sent to various hardware components, and those components behave differently based on whether each bit was a 1 or a 0. That's why these instruction names are also referred to as mnemonics. It's easier for humans to remember what LD B, C means than it is to remember what 01000001 stands for. Although while I have you here, a quick sidebar about instruction names: These names like LD B, C aren't for the Game Boy they're for the humans trying to write Game Boy games. The main takeaway is that each unique 8-bit value has a corresponding CPU instruction. If that sounded like a bunch of nonsense, don't worry. For example, the opcode 01000001 (or 0x41 in hexadecimal) corresponds to the instruction called LD B, C, which tells the CPU to load the contents of register C into register B. On the original Game Boy, each of these chunks is eight bits long (which is why you'll sometimes hear people refer to it as an "8-bit system").īut how does the Game Boy CPU know what to do with those chunks? Well, each unique 8-bit chunk (also called an opcode) can be translated to a particular instruction for the CPU. It has to break the program down into smaller chunks, which it will then read one at a time. But your Game Boy's tiny little brain - the CPU - can't read all those bits at once. These bits are the program instructions that tell your Game Boy how the game should work. The game on your Game Boy cartridge is really a bunch of bits - 1s and 0s - stored on a memory card. "Okay, but what does that actually mean?" Right, let me back up. "Wow Megan, those are some pretty colorful tables, but what actually is this thing?" Great question! These tables are a way of visualizing all the opcodes for the original Game Boy central processing unit (CPU).

But I have built something else: an interactive table of all the Game Boy opcodes.

Then, last July, I started wondering how those emulators worked, and I decided I wanted to try building one myself. As I've gotten older and that millennial nostalgia has kicked in, I've been able to revisit some of my childhood-favorite titles, thanks to emulators like VisualBoy Advance. Like many people my age, I grew up on Nintendo handheld gaming systems.
