A NES emulator written in Odin
In late June 2024, an individual began a project to create a NES emulator written in Odin, a simple C-like language. They worked on it in their spare time for several months before taking a break in January 2025 to focus on other tasks. The project, which has been an enjoyable yet challenging experience, took significantly longer than expected to achieve its current state. The emulator is 80-90% complete, with the last 10% remaining as the most difficult part to perfect.
The NES hardware has many intricacies that need emulation for certain games to run correctly. The CPU and PPU (the graphics rendering chip) work in parallel and must communicate accurately for the emulator to function properly. This timing complexity, along with issues related to mappers (implementations of NES cartridges), made the project particularly challenging.
Implementing mappers correctly is crucial for certain games to function, but some mappers are still poorly documented and implemented, causing difficulties in getting some games to run.
The creator of the emulator found Odin to be an ideal language for this project due to its simplicity and strong typing, allowing them to focus on the core functionality without unnecessary complexities. However, Odin's lack of automatic integer promotion and memory management proved to be stumbling blocks. They had to implement their own strategies for memory allocation and handle custom serialization of Odin objects using the CBOR library.
Despite these challenges, Odin's raw unions and bit fields proved to be particularly useful for emulator development.
Currently, the emulator is far from complete. There are several notable gaps to fill, including additional mappers, better memory management strategies, and improved serialization techniques. The creator acknowledges that the project will never truly be finished, but they plan to continue working on it to bring it closer to a "complete" state. Their journey through developing this emulator has provided them with valuable insights into both the NES hardware and the Odin programming language.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.