Arbok

Emulators are fascinating, in my opinion. I’ve always enjoyed delving into the core structure of something, understanding it thoroughly, and finding ways to interpret it on a different system. That’s essentially my main motivation for implementing this emulator.
I chose Python because I wanted to explore its capabilities as a typed language using the typing feature.

As for the name – Arbok is a snake pokèmon!

Emulation

You may catch yourself asking: So, uh, how exactly do emulators work? Don’t worry, it’s a common question! Basically, emulators pretend to be a piece of hardware—like an old game console—on a different system, like your computer. They imitate everything the original system did, from processing data to displaying graphics, as if you were using the real thing.

At the core of an emulator is the ability to take instructions meant for the original device (like a Gameboy) and make your modern computer understand and run them. This – in a vague sense – means tricking your game into thinking it’s running on the old hardware, as we handle everything from the CPU to how it draws pixels on the screen and responds to button presses.

At the heart of every emulator is something we will call the ‘core loop.’ This is where the magic happens! The core loop is like the brain of the emulator—it’s responsible for running everything in the right order, just like the original hardware did.

Here’s how it works in a nutshell:

  1. Fetch the Next Instruction: The emulator grabs the next instruction from the game’s code (save this, add that).
  2. Decode the Instruction: It then figures out what that instruction actually means. Is it a command for the CPU to move data, do some math, or maybe draw something on the screen?
  3. Execute the Instruction: Once the emulator knows what the instruction is asking, it goes ahead and does it. This might involve updating the game’s memory, changing the graphics, or playing a sound.
  4. Repeat!: The core loop just keeps doing this over and over, super fast—like thousands or even millions of times per second! This keeps the game running smoothly, as if you were playing on the original console.

In Arbok, this core loop is responsible for making sure the Gameboy’s processor (CPU) runs the game exactly like it would on the real thing. It fetches, decodes, and executes each instruction from the game, while keeping track of things like graphics and input.

Complex emulators

Now, if you’ve looked into more complex emulators, you might have heard about the insane headaches that come with things like precise timing, 3D graphics, or even syncing audio. Emulators for newer consoles, especially ones with 3D graphics or advanced hardware, face all sorts of challenges trying to keep everything running in perfect sync—imagine trying to make sure every frame of a fast-paced 3D game is drawn at the exact right moment without lag or stutter. That’s where stuff like frame rates, clock cycles, and timing precision can cause a lot of problems.

The Gameboy doesn’t have complex 3D graphics or a fast processor, so we don’t have to deal with the same level of timing issues. It’s a simpler 2D machine with a predictable set of instructions, so as long as we can get those basic operations right, we’re golden.

And that’s really all the core loop is—a continuous cycle that makes sure the game keeps running, frame by frame, just like on the original Gameboy.