Inspiration

I’ve always been fascinated with retro video games. As a kid, I didn’t get a chance to own or play many of the consoles and games that shaped my generation’s gaming experience. However, as I got older, I found that I could experience those classic games on my own computer. The idea of being able to play these games without needing the original hardware was exciting, but I also became curious about the underlying technology that made these games and systems work. I wanted to understand how an emulator could accurately replicate a Game Boy’s behavior on modern hardware. That curiosity led me to the idea of writing my own Game Boy emulator from scratch, not just to play games, but to learn more about computer architecture and systems programming as a whole.

What it does

"gbemu," allows users to play Game Boy games directly on a computer without needing to own any physical Game Boy hardware. It emulates the hardware components of the original Game Boy, such as the CPU, RAM, and PPU. By replicating these components in code, the emulator can read and execute the same machine instructions that the actual Game Boy would, creating an environment where games run just like they would on the original device. This means users can load cartridge files and play them as if they were running on a real Game Boy, with the emulator handling everything from graphics rendering to user input, all while running on a modern PC.

How I built it

The project was developed in C, which I chose due to its efficiency and low level features. Since a Game Boy emulator requires close interaction with the hardware, C was the perfect fit for this project. To guide the development, I used a variety of resources, including the gbdev pandocs (a documentation resource for Game Boy development) to understand the specific behavior of the Game Boy's hardware components. Additionally, I watched several YouTube tutorials to deepen my understanding of emulation techniques and troubleshooting methods. The project also required a solid grasp of how hardware components interact, such as how memory is mapped or how the PPU handles tiles and sprites, which meant doing a lot of research and learning on the fly. While building the emulator, I also used the SDL (Simple DirectMedia Layer) library to handle video rendering and user input, which simplified the development process since I didn't need to directly interact with OpenGL or Vulkan.

Challenges I ran into

I encountered various challenges, but one of the most frustrating was implementing the CPU instructions. The Game Boy’s CPU has a set of instructions that perform a wide range of operations, from simple arithmetic to more complex memory management tasks. In C, if you make a mistake, it can be very difficult to pinpoint exactly what went wrong. Often, the program would just segfault, and I had to debug by tracing through the code manually.

Accomplishments that I'm proud of

One of the accomplishments I’m most proud of is the fact that I stuck with the project despite the challenges. When I first started, the task seemed impossible, and there were moments where I seriously considered quitting. However, instead of giving up, I chose to continue anyway, knowing that even if I couldn't implement everything, I would learn an immense amount in the process. Overall, I’m proud of how much I grew as a programmer by diving into such a technically demanding project. I’m most proud of the perseverance and problem solving skills I developed. This project wasn’t just about writing an emulator, but about gaining a better understanding of computer architecture and systems programming.

What I learned

This project taught me a lot about computer architecture and systems programming. While I had some prior knowledge of how computers worked at a high level, writing an emulator required me to understand the low level interactions between hardware and software in ways I hadn't before. I also gained a deeper understanding of multi-threading and concurrency through the use of the POSIX threads library. This helped me manage tasks like processing input and updating the screen independently, creating a more responsive and fluid user experience

What's next for gbemu

The next major step is implementing sound by implementing the APU. Currently, the emulator doesn't produce any sound, which is a key feature missing for many users. Additionally, I plan to work on implementing Windows threads so that the emulator can run natively on Windows without needing additional tools like Cygwin or MSYS2. Right now, the emulator works on Unix-like systems, but broadening its compatibility to other operating systems will make it more accessible to a wider audience.

Built With

Share this project:

Updates