Porting NES To The ESP32

There’s an elephant in the room when it comes to the Raspberry Pi Zero. The Pi Zero is an immensely popular single board computer, but out of stock issues for the first year may be due to one simple fact: you can run a Nintendo emulator on it. Instead of cool projects like clusters, CNC controllers, and Linux-based throwies, all the potential for the Pi Zero was initially wasted on rescuing the princess.

Espressif has a new chip coming out, the ESP32, and it’s a miraculous Internet of Things thing. It’s cheap, exceptionally powerful, and although we expect the stock issues to be fixed faster than the Pi Zero, there’s still a danger: if the ESP32 can emulate an NES, it may be too popular. This was the hypothetical supply issue I posited in this week’s Hackaday Links post just twenty-four hours ago.

Hackaday fellow, Hackaday Supercon speaker, Espressif employee, and generally awesome dude [Sprite_tm] just ported an NES emulator to the ESP32. It seems Espressif really knows how to sell chips: just give one of your engineers a YouTube channel.

This build began when [Sprite] walked into his office yesterday and found a new board waiting for him to test. This board features the ESP-WROOM-32 module and breaks out a few of the pins to a microSD card, an FT2232 USB/UART module, JTAG support, a bunch of GPIOs, and a 320×240 LCD on the back. [Sprite]’s job for the day was to test this board, but he reads Hackaday with a cup of coffee every morning (like any civilized hacker) and took the links post as a challenge. The result is porting an NES emulator to the ESP32.

The ESP-32-NESEMU is built on the Nofrendo emulator, and when it comes to emulation, the ESP32 is more than capable of keeping the frame rate up. According to [Sprite], the display is the bottleneck; the SPI-powered display doesn’t quite update fast enough. [Sprite] didn’t have enough time to work on the sound, either, but the source for the project is available, even if this dev board isn’t.

Right now, you can order an ESP32; mine are stuck on a container ship a few miles from the port of Long Beach. Supply is still an issue, and now [Sprite] has ensured the ESP32 will be the most popular embedded development platform in recent memory. All of this happened in the space of 24 hours. This is awesome.

Get yourself up to speed while you wait for a dev board to travel ashore. [Elliot Williams] has already posted the first in what will surely be a series of ESP32 tutorials.

34 thoughts on “Porting NES To The ESP32

    1. I recently read that the in-game timer was actually based off the electrical clock. If this is drawing more power, it is probably clocking faster. I am sure there is some tweak in the emulator software to correct this but since this is prototype, it may not be implemented yet.

          1. Hehe, you forgot the fact that you can add external SPI RAM to the ESP32. Unfortunately, there’s a bug in the cache logic for that, causing it to glitch every now and then… that’s also one of the reasons there’s no (finished) support for external flash in esp-idf yet. We have a fix for that in the making, but it’ll take some time before the revised chip comes out. Until then no Doom, sorry.

          2. On top of that, after profiling, I found out DOOM allocates about 2 MB of ram right off the bat, so, that would make it more difficult. I’m kinda annoyed the Linux Doom port got rid of all the fixed point work. I’m gonna have to poke at that, see if anyone has a version out there from before they made them floats

            Sprite_tm: Is there any hope to shadow the external RAM chips like you did on your MP3 player project? Wouldn’t be bad if I could get everything to execute from whatever the equivalent of IRAM is on the ESP32. Wait… what? I don’t see IRAM on the ESP32! Is the whole “ROM” area internal FLASH? I can’t imagine that executing at the full 240 MHz! (Can’t wait to get my ESP32)

          3. The ESP32 has a bunch of regions: some is IRAM, some can be accessed as both IRAM as well as DRAM and some is DRAM. I don’t have the exact sizes here, but check heap_alloc_caps.c in esp-idf, it’ll give you an overview.

            What do you mean with ‘shadow’ the RAM? On the ESP32, I just use the RAM as a generic SPI peripheral, nothing more, nothing less. The ESP32 has the capability of integrating external SPI RAM into the address map (as DRAM, for a max of 4MB at a time) but as I said, that’s not entirely working yet.

            The ROM is just that, mask ROM. No flash there.

            If your ESP32 is taking longer than a week or so to get to you, gimme a poke. I imagine all the stuff you did with the ESP8266 warrants a free sample DHLled to you. If anything because I want to know if the RF-TV-out still works on the ESP32 and if you can use it to show Mario :P

          4. Also: The ESP32 has a (single-precision, but still) FPU, so floats aren’t actually that much of an issue. (Although I imagine fixed point calculations still are faster.) I used prboom, which afaik only uses floats in situations where it is known that the fixed point solutions are way off.

          5. @Sprite_tm : I think this RF-TV-out hack on Esp8266 you’re talking about was using the I2S output at 80 MHz, but Esp32 datasheet says for I2S : “BCK clock frequency from 10 kHz up to 40 MHz are supported” (page 24), so that would be out of specs ??

            Someone asked about this weeks ago on official Espressif’s ESP32 forum after chip release, but it wasn’t answered ( http://esp32.com/viewtopic.php?f=2&t=136 ). Could you clarify this point, please ?

          1. Yeah man. It’d be cool to see your take on it, like if you could get sound working or make a PCB prototype…… But the challenge is up to anyone really.

  1. What’s the maximum SPI-bus speed of the ESP32? On the ESP8266 these 320×240 ILI9341-displays I’ve got run fine at 80MHz SPI-bus, tho I have to drop the speed to 40MHz if I want to read pixel-data from them — at 80MHz writing to the display is fine, but reading results in something around 1-3 corrupt bits for every 16 bits. (I haven’t bothered testing 18-bit depth yet, 16 bits is much easier for the ESP8266 to handle)

    When just clearing the whole 320×240 pixels at 16-bit depth to a single colour I can easily hit just a bit over 60FPS, but due to the small FIFO-buffer and no DMA the speed drops quickly when actually displaying something meaningful. The ESP32, with its DMA and all, should easily hit 60FPS after some optimization.

  2. The times we live in…
    “There is no sound because I wanted to implement this in 24 hours…”
    Open Source has come a long way and THIS is how it manifests itself!
    Now all we have to do is wait 3 weeks until aliexpress starts selling $3 NES emulators :-)

    1. A bit of a “I liked the product so much I joined the company!” moment :)

      Still waiting for my ESP32s to turn up. I will be putting a colour LCD on them asap and running this up. It needs a little 3D printed Television case for the screen and a tiny 3D printed NES to house the ESP.

  3. Good and experienced folks here,
    Can someone explain what his approach towards porting might have been. Suppose i wanted to port the NES Emulator to a different microcontroller then what should be my approach ? Basically how do you port something from one microcontroller to another ?
    Note: I dont know much about microcontroller programming from inside out, like writing drivers. i mostly use already existing libraries. However i have a good knowledge of C and C++ …. you know university level programming in general.

Leave a Reply to UniStudCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.