ARMtendo

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
ARMtendo
by on (#91507)
Thought I'd make a post and share for anyone that might be interested. I've been working on a project for the last few months making a microcontroller based NES emulator. The goal is to design the least powerful, least expensive piece of hardware using off the shelf components that can emulate the nintendo at a level I consider "mostly accurate". Obviously I can't do cycle-by-cycle emulation, but I don't want to sacrifice accuracy too much. I'm currently aiming for a quality similar to loopynes.

The board uses an STMicro ARM Cortex-M3 (STM32F205ZE) microcontroller running at 120MHz. It comes with 512KB of flash, 128KB of RAM, 16-bit external bus, and a buffered internal DAC I'm going to use for audio (maybe). I needed more RAM, so I put a 512KB SRAM on the bus. I'm also using an Epson S1D13746 video controller. It has an internal frame buffer you can write to and it spits out s-video. It's intended for mobile applications, but has a lot of features that are useful for any embedded video system, such as double buffering, rotation, window support, etc. I have a micro SD slot for a flash card that will store ROMs, but I plan on switching to USB on the next board. I also wanted to use the NES joypads, so there's 2 connectors for those as well.

Here's what the board looks like now. It's a 4 inch x 3 inch 2 layer board, so the routing was a bit tight. Using an SOJ package for the RAM helped out a lot, and the analog and digital response actually ended up to be really good.

Image

Originally I was going to start with a PIC32 or AVR32, but I got caught up in too much early optimization and it was making the project excessively limited. The AVR32 is more expensive, and the PIC32 has limited RAM and no external bus, so I decided to just use an ARM Cortex-M3 to start out with and get a platform designed that I could start working with. My intention is to move back to a lower powered micro, if possible, once I get the current system emulating basic mappers at 60 FPS. I'm at around 40 FPS right now on mapper 0 games, but I haven't done any PPU optimization really. It's all written in C and coded for simplicity just so I could get it functioning. I have some graphical glitches when scrolling, but once I figure that out I'll start rewriting for speed.

I'm using a 16-bit RGB pallette here.
Image

Some more of the board.
Image

The main 5V to 3.3V regulator has an exposed pad, so I hot plated the other ICs as well.
Image

The predecessor. It was from another project and used a Wiznet microcontroller with a modified 8052 core. I was only getting 1 FPS on this :) My code is still written for an 8-bit micro, so when I change that, that should yield a significant bump in speed as well.

Image

I'll post updates as I continue to make progress on the project if people are interested. I plan on open-sourcing it after it's fully functional.

by on (#91508)
I'd want one. :D

by on (#91509)
Sounds like the exact opposite of PocketNES.

by on (#91510)
GREAT WORK!

Looking forward to playing around with one. How are you play the ROM out of curiousity? I assume you can store them on the SD card but are they loaded into external/internal RAM during play time, along with CHR data? I guess I'm more curious how you plan to implement larger games and mappers really.

good to see the progress, keep it up!

by on (#91532)
Very cool. Do you plan to eventually sell and distribute this? Perhaps out of your scope of this project, but have you thought of having the ability to hookup a cartridge reader so the user could actually load a game from a real NES cartridge and play it? Obviously they'd need to be able to tell what sort of mapper the game has but it would be a very neat feature. An emulated NES clone.

by on (#91533)
infiniteneslives wrote:
GREAT WORK!

Looking forward to playing around with one. How are you play the ROM out of curiousity? I assume you can store them on the SD card but are they loaded into external/internal RAM during play time, along with CHR data? I guess I'm more curious how you plan to implement larger games and mappers really.

good to see the progress, keep it up!


Thanks! The SD card will be FAT formatted, so it'll show up as a mountable drive on a PC and let you drag and drop ROMs to it. The microcontroller will read the ROM from the card and copy the entire PRG and CHR to the external SRAM before play time. There's 512KB of SRAM on the board, so games using more than that aren't currently supported, like Kirby's Adventure. I couldn't find an 8M SRAM in a SOJ package, so I'd have to go to a SSOP which makes the PCB layout a bit more difficult. I'll eventually move up though which will support the few games that need more than 512KB.

by on (#91535)
MottZilla wrote:
Very cool. Do you plan to eventually sell and distribute this? Perhaps out of your scope of this project, but have you thought of having the ability to hookup a cartridge reader so the user could actually load a game from a real NES cartridge and play it? Obviously they'd need to be able to tell what sort of mapper the game has but it would be a very neat feature. An emulated NES clone.


I might end up selling them. I wasn't sure of the legality of doing that honestly, but haven't spent a lot of time thinking about it yet.

Cartridge support wasn't something I was planning on doing. It would be a cool idea though. Maybe for another project. An FPGA would be better suited for that.

by on (#91537)
I don't think there would be any legal problem other than the name might attract attention as ARMtendo is probably close enough to Nintendo they might be annoyed, or they might not care at all.

Glad to hear you might sell them or have them produced. I do think a cartridge reader (as an option) would be really cool.

by on (#91539)
runaway pancake wrote:
I'll eventually move up though which will support the few games that need more than 512KB.

This sentence makes it look like you're only interested in running Nintendo-approved NES games. Many unlicensed games are larger than 512KB, and more importantly, homebrews will probably start breaking that barrier soon.

You have to think about the future. You and others here who have the knowledge to create new NES systems are the ones that will make it possible for classic gaming to continue existing after all original consoles have died. Similarly, homebrewers will keep making new games to keep the spirit of these consoles alive. You should always consider that when creating emulators or clones.

by on (#91542)
tokumaru wrote:
runaway pancake wrote:
I'll eventually move up though which will support the few games that need more than 512KB.

This sentence makes it look like you're only interested in running Nintendo-approved NES games. Many unlicensed games are larger than 512KB, and more importantly, homebrews will probably start breaking that barrier soon.

You have to think about the future. You and others here who have the knowledge to create new NES systems are the ones that will make it possible for classic gaming to continue existing after all original consoles have died. Similarly, homebrewers will keep making new games to keep the spirit of these consoles alive. You should always consider that when creating emulators or clones.


This is something I've put a lot of thought into. My intent is to accomodate the largest size games possible, licensed or not. Unfortunately, I'm at the point where RAM cost and physical size are the major limiting factors. SRAM is really expensive when you go above 512 KiB. The SRAM I'm using now is 512KiB and costs about 7 bucks. The 1024KiB equivalent is like 18 bucks. The 2048 KiB chip is like 50 bucks. So I'm kind of limited in what is cost effective. The larger chips are only BGA, so I'd have to move to a 4-layer board. I also can't easily use multiple smaller chips due to the size of the board. I could make it bigger, or 4-layers, but that also adds to the cost.

Moving to 1024 KiB is the only real possibility at the moment. That's going to be the size cutoff unless someone releases a high speed microcontroller with DRAM support. Or come up with some sort of cacheing and compression scheme for game data, but I don't think that's going to be possible.

by on (#91543)
MottZilla wrote:
I don't think there would be any legal problem other than the name might attract attention as ARMtendo is probably close enough to Nintendo they might be annoyed, or they might not care at all.

Glad to hear you might sell them or have them produced. I do think a cartridge reader (as an option) would be really cool.


Yeah, the name could be an issue. The cartridge reader would probably have to be a USB add-on, otherwise I'd have to switch to a multilayer PCB, which I've purposefully avoided doing so far.

by on (#91544)
tokumaru wrote:
runaway pancake wrote:
I'll eventually move up though which will support the few games that need more than 512KB.

This sentence makes it look like you're only interested in running Nintendo-approved NES games. Many unlicensed games are larger than 512KB

As I understand it, most of these are either A. in the Chinese language only, B. pirate-original ports of 16-bit games, C. multicarts, or D. more than one of the above. Freeware homebrew games bigger than 512 KiB are limited by the amount of labor needed to make that much data (tiles, maps, and the like).

runaway pancake wrote:
SRAM is really expensive when you go above 512 KiB.

Which is why a lot of systems use PSRAM (pseudo-static RAM), which is DRAM with glue logic on the same die to make it look like SRAM.

Quote:
Or come up with some sort of cacheing and compression scheme for game data

PocketNES (for GBA Movie Player) is an NES emulator for an ARM7TDMI based platform that uses a caching mechanism to fit as much of the working set as possible into 384 KiB of RAM. One-third is fast SRAM, and the rest is slower memory (probably PSRAM). All it's missing are a PPU and an APU, because it virtualizes those on top of the GBA's PPU and the GBA's GBC-compatible APU. And it began as a port of LoopyNES.

by on (#91547)
tepples wrote:
runaway pancake wrote:
SRAM is really expensive when you go above 512 KiB.

Which is why a lot of systems use PSRAM (pseudo-static RAM), which is DRAM with glue logic on the same die to make it look like SRAM.


This is also another possibility. I was worried about the access speed of PSRAM. I figured the data reads could be fairly random and the burst reads wouldn't be as fast as I needed. I've never used PSRAM though, so I could be wrong.

tepples wrote:
runaway pancake wrote:
Or come up with some sort of cacheing and compression scheme for game data

PocketNES (for GBA Movie Player) is an NES emulator for an ARM7TDMI based platform that uses a caching mechanism to fit as much of the working set as possible into 384 KiB of RAM. One-third is fast SRAM, and the rest is slower memory (probably PSRAM). All it's missing are a PPU and an APU, because it virtualizes those on top of the GBA's PPU and the GBA's GBC-compatible APU. And it began as a port of LoopyNES.


Yeah, I'm definitely aware of the impressive PocketNES. I was planning on looking at the source to see what was done, but haven't had a chance yet. I was also thinking of adapting some of the speed hacks it uses as well, although they won't be as beneficial for my system as PocketNES.

by on (#91557)
Very, very nice job with this!

A question: does the video chip output non-interlaced video (240p for people born after 1998)?

If it doesn't and the video is interlaced, does the chip output nice blocky 256x240 video, or the same upscaled & interpolated to 400 lines? Ugh.

by on (#91563)
ccovell wrote:
Very, very nice job with this!

A question: does the video chip output non-interlaced video (240p for people born after 1998)?

If it doesn't and the video is interlaced, does the chip output nice blocky 256x240 video, or the same upscaled & interpolated to 400 lines? Ugh.


It's upscaled to 480i.
YES!!
by on (#91576)
i have been dreaming of this for ages but i have no knowledge on this, why not just use a raspberry pi? 700mhz 256mb of ram , its powered by usb and has hdmi and analog output would be perfect for a low powered nes ,

good luck on this i would defiantly buy one if you plan on selling

by on (#91577)
It is certainly an interesting thing as a DIY project, and would be especially cool as an open source HW/SW project, but I should note that these days there is a ton of cheap Chinese portable consoles (Dingoo, Gemei, Caanoo, Ritmix, and countless others) with emulators, some of them also has TV out. I also recall something similar that had no screen, just a small box with USB and TV out. So if someone just wants a ready-made product, there are existing devices already.

by on (#91584)
dreamer wrote:
i have been dreaming of this for ages but i have no knowledge on this, why not just use a raspberry pi? 700mhz 256mb of ram , its powered by usb and has hdmi and analog output would be perfect for a low powered nes ,

good luck on this i would defiantly buy one if you plan on selling


I could just use a laptop if all I wanted to do was play NES games on a TV :)

by on (#91594)
runaway pancake wrote:
I could just use a laptop if all I wanted to do was play NES games on a TV :)

You could, but others might not:
  1. Not many people are aware that PCs can display on TVs. They aren't aware that DVI out connects to HDMI in, that a lot of North American HDTVs have a VGA input (which European TVs often give up for SCART), or that SewellDirect.com sells a $30 cable to turn a VGA signal into a PAL or NTSC composite signal for an SDTV. In the mind of the general public, TVs are for living rooms and PCs are for desks and never the twain shall meet.
  2. There tends to be a lot more controller-to-video and controller-to-audio latency in PC-based emulation than there is on an NES. I once measured 100 ms for VisualBoyAdvance on Windows, which made rhythm games unplayable. A single-tasking embedded system could shave tens of milliseconds off this.

by on (#91596)
Honestly speaking, I see little use for emulators that trade accuracy for speed. Today we have very portable computers that can accurately emulate a NES at full speed, just hook those to a TV and NES controllers and you get a relatively faithful experience.

Hardware clones are a different story, because those have the potential to be 100% accurate and still use original peripherals and carts, which I consider a big deal.

by on (#91602)
tepples wrote:
runaway pancake wrote:
I could just use a laptop if all I wanted to do was play NES games on a TV :)

You could, but others might not:
  1. Not many people are aware that PCs can display on TVs. They aren't aware that DVI out connects to HDMI in, that a lot of North American HDTVs have a VGA input (which European TVs often give up for SCART), or that SewellDirect.com sells a $30 cable to turn a VGA signal into a PAL or NTSC composite signal for an SDTV. In the mind of the general public, TVs are for living rooms and PCs are for desks and never the twain shall meet.
  2. There tends to be a lot more controller-to-video and controller-to-audio latency in PC-based emulation than there is on an NES. I once measured 100 ms for VisualBoyAdvance on Windows, which made rhythm games unplayable. A single-tasking embedded system could shave tens of milliseconds off this.


The point was that I'm not interested in buying a SBC, I'm interested in having fun designing an embedded system.

by on (#91603)
tokumaru wrote:
Hardware clones are a different story, because those have the potential to be 100% accurate and still use original peripherals and carts, which I consider a big deal.


That's probably what I'll start after I "finish" this.

by on (#91659)
That's a cool project (and unusual too). Can't wait to see how it end up. When can we expect an Arduino nes? :lol:

by on (#91661)
When Arduino turns into Armduino, perharps?

by on (#91664)
SkinnyV wrote:
That's a cool project (and unusual too). Can't wait to see how it end up. When can we expect an Arduino nes? :lol:


You could probably emulate a 6502 with one, but not much else :P

by on (#91665)
Shiru wrote:
When Arduino turns into Armduino, perharps?

By "ARMduino" do you mean the Due? 50 KiB of SRAM, 256 KiB of flash, but I don't know what video output circuits are commonly used with Arduino projects.