STM32 NES Emulator

jefflongo

Broke BitBuilt
Staff member
.
.
Joined
Dec 15, 2016
Messages
1,017
Likes
1,361
Location
Santa Barbara, CA
Portables
3
So I'm taking a microcontrollers class and we need to create a project. Most projects are pretty basic, but my partner and I wanted to go above and beyond. I've always wanted to write an NES emulator, so we decided to write an NES emulator to run on an STM32 microcontroller. We are designing a PCB to house the controller alongside with extra memory, an LCD display, a microSD card slot, and controller ports. In the future, we plan to revise the board to be a full handheld. But 2 months is not enough time for this goal. I need to write a worklog for the class so I figured I'd post my updates here as well.

I spent a week reading through the abundant MOS6502 documentation and starting writing the CPU emulator in Python as a proof-of-concept. I tested the CPU on a custom .nes file which tests for correctness and after much debugging my emulator is successful for the majority of the tests. I did my best to document every addressing and mode and instruction, making each operation cycle-correct. Tests involving illegal opcodes I didn't worry about since they are only used by a few games and time is limited. After this success, I ported the code to C which will be put on the MCU. The next step will be implementing mappers, finishing and ordering the PCB, and spending more time researching the PPU.

Feel free to follow the progress on my GitHub as well. https://github.com/jefflongo/STM32NES
 
Last edited:

cheese

the tallest memer in town
Staff member
.
.
.
Joined
Mar 2, 2016
Messages
2,758
Likes
2,422
Location
Florida
PPU is gonna be fun :P
You planning on using the original ports ye? And are you gonna have a menu or just read the first file from the SD?
 

jefflongo

Broke BitBuilt
Staff member
.
.
Joined
Dec 15, 2016
Messages
1,017
Likes
1,361
Location
Santa Barbara, CA
Portables
3
PPU is gonna be fun :P
You planning on using the original ports ye? And are you gonna have a menu or just read the first file from the SD?
Yeah I'm going to use the original ports. The plan is for a menu but if we run out of time we will do the latter. ;)
 

jefflongo

Broke BitBuilt
Staff member
.
.
Joined
Dec 15, 2016
Messages
1,017
Likes
1,361
Location
Santa Barbara, CA
Portables
3
So I haven't updated this thread in awhile but we've made huge progress. We finished the PCB design, ordered, and assembled the board. After a few hours of troubleshooting, we got the MCU to blink an LED, which means the circuit design works. We've also written the 16 bit parallel display driver, and are working on an SD card driver (with some frustration). On the NES side, we've finished the CPU, mapper0 (we will add more mappers later, just need to make a game run), and are working on the PPU. We've got 8 days until our deadline, I'm hoping the next update will be a game running. Here's some pics of the PCB, the assembly, and the finished hardware.
Screenshot_20190304-071213.png 20190309_161309.jpg 20190312_161455.jpg
 
Last edited:

jefflongo

Broke BitBuilt
Staff member
.
.
Joined
Dec 15, 2016
Messages
1,017
Likes
1,361
Location
Santa Barbara, CA
Portables
3
Hoping to revive this project soon. Long story short my partner and I pulled an all nighter the day of the presentation trying to get the system up and running. I got the SD card driver running and we attempted merging my code with the PPU code. Unfortunately it didn't work, through debugging we could see instructions being ran (we stepped through SMB) but the ppu seemed to not be working. In the last few hours we decided to just implement a brick break like game to demo, which we were able to do. We dropped the project due to being busy afterwards.

I decided to take a step back and implement the emulator in a portable way using SDL2 first. My C has improved a ton in the last few months so I've gone through and refactored a lot of the codebase. I also found a critical bug in the cpu with interrupts and branches with negative offsets. The CPU now passes the 27k instruction nestest! I've even implemented all of the illegal opcodes. I'm likely going to begin working on refactoring and understanding the PPU next as I didn't work on it. Hoping to have a game running soon!
 
Top