Making a Cartridge Dumper for my Emulation System

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
ToxicNugget
Posts: 3
Joined: Wed Mar 18, 2020 8:00 am

Making a Cartridge Dumper for my Emulation System

Post by ToxicNugget » Wed Mar 18, 2020 8:11 am

Hi, I'm a student and am making an electronics project for a class that pretty much clones the NES in a means of learning about the workings of these older consoles and more about the 6502 CPU etc.
I have started programming an NES emulator with the help of online resources and so far I am finding it really interesting.
Now my only question is that after I have finished the programming of this emulator and I will have it running on a Raspberry Pi which will be able to plug into a TV, is there any way I can make a cartridge reader with the help of an Arduino, etc, that will be able to generate a ROM and copy it over serial to the Pi? I am thinking of using one of the 72 pin connectors like this but have no idea where to start from an electronics perspective:
Image

I know there are existing products that can do this but I want to be able to learn how to do this for myself, which would make it a much more fulfilling project. If anybody could give me any tips or pointers I would be very grateful :)

User avatar
Quietust
Posts: 1555
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Making a Cartridge Dumper for my Emulation System

Post by Quietust » Wed Mar 18, 2020 9:56 am

In order to interact with an NES cartridge, you're going to need a 5 volt I/O interface, so you'll need to make sure your Arduino can actually do that. Note that "5V tolerant" might not be good enough - those can typically handle 5V input but only generate 3.3V output, which might not be enough for an NES cart.

Once you've got that, there are a few important setup steps you need to do:
  1. Make sure your device has all of the Data pins in INPUT mode and all of the Address+Control pins in OUTPUT mode, otherwise bad things can happen which could damage your device (like Bus conflicts)
  2. Drive M2 (pin 38) low and /ROMSEL (pin 50) high, to signify that the bus is inactive
Once you've got that, reading from ROM involves the following steps:
  1. Drive all of the address lines (pins 2-13 and 39-41) to their appropriate states
  2. Drive R/W (pin 14) high, to indicate that you're performing a Read
  3. Drive M2 (pin 38) high and /ROMSEL (pin 50) low, to actually perform the read
  4. Wait at least 200ns for the bus to settle
  5. Read the state of the data lines (pins 42-49)
  6. Drive M2 (pin 38) low and /ROMSEL (pin 50) high, to end the bus cycle
Similarly, writing to ROM (which is more likely to actually write to a memory mapper) goes like this:
  1. Drive all of the address lines (pins 2-13 and 39-41) to their appropriate states
  2. Drive R/W (pin 14) low, to indicate that you're performing a Write
  3. Set your device's Data pins to OUTPUT mode, then drive them (pins 42-49) to the values you want to write
  4. Drive M2 (pin 38) high and /ROMSEL (pin 50) low
  5. Wait at least 200ns for the bus to settle
  6. Drive M2 (pin 38) low and /ROMSEL (pin 50) high
Note that these all assume that you're accessing $8000-$FFFF, which is fine for most cartridges - however, if you need to access lower regions (like $6000-$7FFF for battery-backed RAM or $4020-$5FFF for control registers on special mappers like the MMC5), you'll need to leave /ROMSEL (pin 50) high.

Once you've done that on your Arduino (or equivalent), then transferring it to your Raspberry Pi (or other device) can be done however you want.

More information can be found on the wiki: https://wiki.nesdev.com/w/index.php/Cartridge_connector
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

tepples
Posts: 21971
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Making a Cartridge Dumper for my Emulation System

Post by tepples » Wed Mar 18, 2020 11:25 am

On the other hand, 3.3 V CMOS outputs are within the normal limits of 5 V TTL inputs.

5 V TTL output: 0.0 V to 0.4 V low, 2.7 V to 5.0 V high
5 V TTL input: 0.0 V to 0.8 V low, 2.0 V to 5.0 V high
3.3 V CMOS output: 0.0 V to 0.5 V low, 2.4 V to 3.3 V high
3.3 V CMOS input: 0.0 to 0.8 V low, 2.0 to 3.3 V high

It's almost as if 3.3 V was chosen for CMOS precisely because its output could feed a 5 V TTL input.

Source: "TTL Logic Levels" and "CMOS Logic Levels" by bri_huang

ToxicNugget
Posts: 3
Joined: Wed Mar 18, 2020 8:00 am

Re: Making a Cartridge Dumper for my Emulation System

Post by ToxicNugget » Wed Mar 18, 2020 1:01 pm

Thanks for all the help, I'll try giving this a go with my Arduino when my 72 pin connector comes and then report back on my progress. Hopefully the voltage output of the Arduino board should be sufficient :)

I still do have a couple more questions though, since things like pin-outs confuse me a little.
Firstly, what does driving all the address line pins to their "appropriate states" mean?
Also just purely out of interest what would happen if pin 50 was left high for an average cartridge that only needs the normal range $8000-$FFFF?

User avatar
Quietust
Posts: 1555
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Making a Cartridge Dumper for my Emulation System

Post by Quietust » Wed Mar 18, 2020 4:54 pm

ToxicNugget wrote:
Wed Mar 18, 2020 1:01 pm
Firstly, what does driving all the address line pins to their "appropriate states" mean?
I meant that if you wanted to read from address 0xC000, you'd want to set A0-A13 to be Low and A14/A15 to be High, but because A15 isn't directly present on the cartridge connector, you'd only set A14 directly and set /ROMSEL based on what A15 would be (specifically, A15 NAND M2).
ToxicNugget wrote:
Wed Mar 18, 2020 1:01 pm
Also just purely out of interest what would happen if pin 50 was left high for an average cartridge that only needs the normal range $8000-$FFFF?
Then you wouldn't be able to read anything - you'd get back "open bus", which for your device would probably just be the last value you successfully read (or perhaps all 0s or 1s after a short time).

Since simple cartridges just want to map a ROM chip to $8000-$FFFF, the cartridge connector provides a simple signal that can be directly connected to the ROM chip's output enable pin, and that signal is just a combination of A15 and M2 both being high at the same time (i.e. A15 AND M2), and since the "output enable" input on most ROM chips is active low (i.e. 0 to output, 1 to not output), it's also inverted, so you get NOT(A15 AND M2), or A15 NAND M2 (which is pin 50, what we label as "/ROMSEL").

It would've been nice if Nintendo had also included the real A15 signal on the cartridge connector, but that would've required making the connector wider.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

ToxicNugget
Posts: 3
Joined: Wed Mar 18, 2020 8:00 am

Re: Making a Cartridge Dumper for my Emulation System

Post by ToxicNugget » Thu Mar 19, 2020 12:20 pm

Ok thanks for all your help,
I'll try this out when my connector arrives then come back here if I have any more issues. :)

Post Reply