Monday, May 5, 2014

NES Dual Port RAM Interface

UPDATE : Thanks for the great response - I'll be posting more videos throughout the week @batslyadams - I'd love to hear your ideas for ways to enhance games! Looking to livestream some development / testing this Thursday, 5/6/14.

I've been writing a game recently and was looking for a way to live debug on real hardware. The original solution was to fire variable information out the second controller port to serial every NMI but I decided to to take a shot at a new PCB for the console I've been dreaming about for a while.

The board routes the left port of the dual port RAM (Cypress CY7C136) to the DIP footprint on the NES and the right port to an AVR (ATMEGA164), this allows me to read and write any location at runtime without bus conflicts. Control is provided through the UART and two additional pins are soldered directly to the 2A03 to control /NMI and /RESET. I took a console and desoldered the 2KB RAM and replaced it with a socket. I'd like to permanently solder this in now that they work but having them removable for debugging was a huge help. AVR control code was written mainly in C with some assembly sprinkled across for the memory control portions.

The AVR sits and wait for serial commands and can perform several functions including :
* Read / write of any memory location
* Quick dump of an entire 256-byte page
* Freezing of memory addresses (rewriting a single value constantly in the busy loop)
* Single frame stepping by controlling the NMI
* Remote reset of console
* Applying auto increment to tables to a single variable (fun for sine waves on x/y positions!)

I had pretty great results with using 250000 baud with the Genesis flasher project which is plenty fast for what I'm trying to do here. Cautionary tale about using this dual port RAM part, be sure to operate the other side normally even though it appears to be decoupled. As far as I can tell from the datasheet leaving CE low shouldn't have an effect on the opposite port but it most certainly does. Next revision could definitely use a few pullups on the AVR side, other than that I'm pretty happy with the layout.

Before wiring up the additional control lines :

Pretty excited to finally use this guy - your usual USB FTDI cable except with a 3.5mm jack. Routed the UART to a standard panel mount TRS on the back of the console.

It has been a blast playing with this thing - stuff I've done so far :

Debug Information
The original intention of this was be able to manipulate values in real time on a console for a game I've been developing, FCEUX is pretty incredible for emulation but I try to do a lot of testing on real hardware.

Blades of Steel used to be my favorite, but I'm starting to come around on Ice Hockey. Heavily using the read function to pull any relevant data from a game then deciding what to do with it.
Would probably be great for automatic splits for speedruns.

Relay Control
Contra has a particular way of allocating shots, there are five slots for one player that a bullet can accommodate. I didn't want to cheap out and just trigger on a button press so all five values are pulled and checked for a new rising edge.

Hex editor
Wrote a live hex editor inspired by FCEUX, lots of fun goofing with variables on the fly. Great fun to have a "co-pilot" looking for ways to help you cheat, like a manual game genie.

Single Frame Step
The /NMI pin is the 60hz interrupt generated from the PPU, this is one of the trickiest parts of the NES since this is the only safe window in which to make writes to VRAM. Due to the limited video bandwidth, the game is typically laid out the following way :

Busy loop / Wait for NMI
Falling edge of NMI / Perform VRAM updates then set flag that NMI has occured
Return from NMI / Perform logic updates / queue VRAM updates

On a "step" command sent from the host the AVR waits until the natural falling edge /NMI then asserts low until it receives the command for another step. This safely inhibits the interrupt and keeps everything in sync. Could also set up a frame level breakpoint here!


Enhanced Rules / Displays
Every game needs a place to store the controller reads after a $4016/$4017 fetch. Typically these routines will still run in a pause menu (so you'll know when to exit). The idea is that the host can read that we are in a pause state AND the controller data you can control a menu offscreen.

Remote Reset
I provided two pins for the NMI and RESET on the console, these are jumpered from the 2A03 directly to GPIO on the AVR. Both of these inputs to the CPU are open drain.

The /RESET pin allows you to command a console reset the host so you wouldn't have to fuss with the console. You can provide an argument for a short reset (10ms) to jump to reset vector within the game and a long reset (~1s) which will bring you back to the powerpak menu.

Glitch Roulette
This was a lot of fun. The idea that every time the player jumps (memory location / method of determining jumping will vary from game to game) the host will write a random value to a random location. The sound engine is usually the first to go since they typically require a good amount of RAM and are overwriting is fairly harmless. A hit on an indirect memory address/stack is usually catastrophic.

Biggest ups to Todd Bailey for the help with assembling these things and Adam Stankiewicz and Nick Gargiulo for tirelessly testing blades of steel.


  1. It's amazing, you can now write a kinect based game for nes ;)

  2. I've been wanting to do this for a pinball scoreboard, using the same dual port ram chip. Do you happen to have a schematic/KiCAD files online anywhere? If not it's great to see that the idea is at least sound.


    1. if my mother board 1 or 2 pin have damaged yet it will repair. 1 Dollar Hosting and thank ;you for these informative post.

  3. This is incredible! We've been looking for something like this. We play a TON of Blades at our office, and have even built a scorekeeper app:

    It relies on hand-fed data though, and doesn't have any of the more advanced stats direct data would provide.

  4. Awesome! I've been wanting to do something like this for the last 6 months or so. I was borrowing an fpga from a friend, that I was going to program to emulate the memory chip, but this is so much easier. Any chance you'll open source the AVR code?

  5. This is awesome. Exactly what I was looking to do -- grab values during runtime. I wanted to get them, then post to an online leaderboard.

  6. the big bang broderie Replica Watches Anglais, Bischoff, home to see the acquisition of major cooperative Mimi handbag replica ace, and 11 and Diamond Bezel contains a pattern of straps soft.Raffaelli before Ambassador, Kobe Bryant, Jay · Z, Replica handbags her footprints, including the bolt and Wade, to follow, she will attend today to the latest (maximum) Hublot flagship Replica watches UK store at 743 Fifth Avenue Surprise. (This NYFW is your schedule to add another NBA events.) Rolex Daytona .

  7. Great to see that someone still understand how to create an awesome blog. The blog is genuinely impressive in all aspects.
    judi poker

  8. The price of excellence is discipline; the cost of mediocrity is disappointment - William Arthur Ward

    Judi Casino
    Judi Casino Online
    Agen Casino
    Dragon Tiger
    Jadwal Bola

  9. very nice and interesting

  10. Information That Is Very Helpful and very complete, thanks for the news Greetings Dwi ^^

    Togel Online
    Agen Casino Online
    Prediksi Togel Singapura


  11. Ayo Bergabung Bersama kami di
    Proses Deposit / Withdraw Super Cepat Dan,
    Didukung Oleh Costumer Service Kami Yang Ramah.
    Kami Juga menyediakan berbagai macam game dalam 1 ID :
    - Poker
    - Capsa
    - Ceme
    - Q- Kick
    - Ceme Keliling Dan
    - Live Poker
    Banyak Bonus Dan Jackpot yang akan menanti anda
    kami Juga memberikan bonus Seperti
    - Bonus New member 10%
    - Bonus Turnover 0.5% Dan
    - Bonus Refferal 20%
    Tunggu apa lagi Gan.. !!
    Buruan Daftar diri anda di
    Anda juga bisa Hubungi CS kami :
    - Skype : Pokersemi
    - Yahoo : Pokersemi
    - Twitter : Pokersemi
    - Facebook : Pokersemi

    Poker Terpercaya
    Agen Domino
    Agen Domino Terpercaya
    Judi Poker
    Judi Poker Online

  12. Thanks for sharing your information, its great and i appreciated about it!
    Judi Bola Online

  13. presentation of the article in this blog is very nice, I like it

    Nonton Film Online
    Bioskop Online
    Nonton Online

  14. Thank You Sir, Very Good and Helpful Articles .. Update continues and always success sir

    Bandar QQ
    BandarQ Online
    Poker Online
    Domino QQ

  15. Your article is very useful and has real knowledge. It’s very helpful information. I will be waiting for your Agen Bola Terpercaya

  16. Some problems are difficult to solve, but I will try. I have a part time job to cover life. Learning by doing is very tired, but it's my life.

  17. Good Articel and so Important topic in this page.
    Good Well.. and thanks.
    BandarQ Terpercaya

  18. Artikelnya bagus ....kunjungi situs resmi kami juga ya

  19. Situs Judi Online Poker terpercaya we from the online gambling site poker reliably thank you for the information you provide

  20. Nice writing , thankyou for sharing this article !

    agen sbobet

  21. Very nice post.really I apperciate your blog.
    Thanks for sharing, keep sharing more blogs.

    Sbobet Casino

  22. This is very educating post, thanks for sharing with us.
    Tips Menang AduQ
    Tips Bermain AduQ



  25. Wah kami Sangat Senang Bisa Menemukan Artikel Sebagus Ini Dan Sangat Bermanfaat Sekali, Kami Menunggu Artikel Berikutnya Yah Gan.

    Agen Poker
    Agen Poker Online
    Agen Poker Terpercaya
    Poker Online
    Poker Online Terpercaya
    Poker Terpercaya
    Poker Online Aman dan Terpercaya

  26. This comment has been removed by the author.

  27. Online Betting Games Get special privileges.

    Royal1688 Online Gambling Games Gives you the pleasure of online gambling all day. Make Money Forward with joy to us. Join the fun. Of Online Gambling At Home All the routes of enjoyment are always good services all the way through the fun as you like. This is an online casino. It is a game that has been very popular. With the opportunity to progress to good service. The bets are over. For online entertainment The fun of online gambling every day, every time, the choice of fun to take to the best opportunity. Current Online Casino Site It is a game that meets the needs of many gamers. Make fun with people who are interested in online betting all day. Online games that give a good return. Get the most out of online gambling. Get the privilege to play casino games in the entertainment you want. Enjoy the full range of gambling options available today through the website Goldclub Slo

  28. Cuma di
    Segera Gabung Bersama kami di AGEN POKER TERPERCAYA,TERBESAR dan TERBAIK DI INDONESIA dengan memberikan pelayanan 24jam nonstop dan proses deposit withdraw yang sangat cepat serta Memberikan Respon Langsung Ramah dan Sopan kenyamanan para member adalah perioritas kami yaitu keunggulan dari Kami, Segera Lakukan Pendaftaran di dan nikmati hadiah yang didapat
    ayooo...... tunggu apa lagi, Join Sekarang bersama POKER ONLINE TERPERCAYA
    Poker Online
    Poker Online Terpercaya
    Poker Terpercaya
    Poker Online Aman dan Terpercaya
    Situs Poker Online Terpercaya
    Situs Poker Online Yang Banyak Bonus

  29. Famous Casino Club That makes ordinary people rich.

    Gclub Slot Is a g club website Casinos are another new opportunity to play very much for people who love and fall in love playing online casino games because of the fun and opportunities for players from all over the world. Online casino games can be played at the same time, because the current online casino games can play the game, which is not the only player who is a player. Thousands loves to play the lottery online is a risk I was able to play the lottery every online form on page G Club. Our casino.

    Nowadays, online casino games can also be played on mobile phones and on the computer, the fluidity is constantly being developed, making it even more exciting to play online casino games. Play more. Players can also play online games. You can join the fun and play online gambling games all day, all night and all the time as well.

    So if you are thinking about playing the online gambling games, do not forget to choose the service with our casino gambling club only. By playing online gambling games, you can make money by playing online casino games easily. When the player is thinking about the fun of playing online gambling games, do not forget to play online gambling games with the web Holiday Palace

  30. togel online

    I love this post it very nice and integrating post.I really enjoy to reading this article thanks for sharing this article.