Developing an NES Emulator
Table of Contents

Introduction
Developing an NES emulator was a challenging yet rewarding experience. Our goal was to replicate the functionality of the iconic Nintendo Entertainment System (NES) inside Minix using our own device drivers for the timer, mouse, keyboard, graphics card, and even UART. The project was written entirely in C and supports real physical controllers.
1. Understanding the NES Architecture
The NES is built around an 8-bit Ricoh 2A03 processor (a modified MOS 6502, the processor used in the Apple II) and a Picture Processing Unit (PPU) for graphics. To emulate it, I had to study its instruction set, memory layout, and hardware quirks, including replicating some bugs!
The NES Dev Wiki was invaluable for this, providing detailed documentation on the CPU and PPU.
2. CPU Emulation
The first step was to emulate the CPU. This involved implementing the 6502 instruction set, handling memory addressing modes, and simulating the CPU clock cycles.
NES Test Passing
Below is a demonstration of the NES emulator successfully passing the NESTest ROM.
3. Graphics Rendering
The PPU was the next challenge. I implemented a framebuffer to simulate the NES's 256x240 resolution and wrote code to render sprites and tiles based on the PPU's memory.

PPU Buged

PPU Almost Working
4. Input Handling
To support real NES controllers, I developed custom device drivers on Minix3. This allowed the emulator to read input directly from the hardware.

Adding header pins to the controller

Controller and serial bride built!
5. Challenges and Lessons Learned
One of the biggest challenges was the PPU. The NES relies on the PPU to generate graphics however I severly underestimated the complexity of this. I had to implement a lot of features, including sprite rendering, background scrolling, and palette management. Debugging was also tricky, at one point running the emulator for 4 frames was creating about 2GB of logs and took arroung 5min.
6. Final Thoughts
This project deepened my understanding of low-level programming, hardware emulation, and operating systems. It was a great way to combine my passion for retro gaming with my technical skills.
Thanks to my colleagues @feup for the amazing main menu to choose games!
Thank you for reading! If you're interested in the code, you can find it on my GitHub. I hope this inspires you to take on your own projects and challenges!
Other Projects
AuctionPeerAcademic Project
A fully functional, deployment-ready auction website built using Laravel and PostgreSQL.
View Project OwlSort AIAcademic Project
A fun game tasking players to sort colored birds, featuring various AI algorithms to assist.
View Project