Reading MaskROM with a microcontroller

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

Reading MaskROM with a microcontroller

Post by qwertymodo »

I'm trying to read a MaskROM that has been removed from a cart using a Teensy++ 2.0 microcontroller board. The Teensy++ 2.0 has a ton of I/O pins, enough for a 1:1 connection to the MaskROM. However, I'm having issues doing the reading. I couldn't find a timing diagram for the MaskROM I/O, so I used the diagrams from the AM29F032B datasheet, since I know they work in repros. Here's the diagram for a read operation:

Image

And here's my code

Code: Select all

void Init()
{
  // Address lines as outputs
  A7_0_DDR   = 0xFF;
  A15_8_DDR  = 0xFF;
  A22_16_DDR = 0x7F;
  
  // Data line defaults to input (read mode)
  DATA_DDR   = 0x00;
  
  // Control lines as outputs, pulled high
  CONTROL_PORT |= (CS_BIT | OE_BIT | WE_BIT | RST_BIT);
  CONTROL_DDR  |= (CS_BIT | OE_BIT | WE_BIT | RST_BIT);
}

uint8_t ReadByte(uint32_t address){
  CONTROL_PORT |= WE_BIT;
  
  A7_0_PORT   = address & 0xFF;
  A15_8_PORT  = (address >> 8) & 0xFF;
  A22_16_PORT = (address >> 16) & 0x7F;
  
  CONTROL_PORT &= ~CS_BIT;
  CONTROL_PORT &= ~OE_BIT;
  
  uint8_t data = DATA_PORT;

  CONTROL_PORT |= OE_BIT;
  CONTROL_PORT |= CS_BIT;
  CONTROL_PORT &= ~WE_BIT;
  
  return data;
}
Basically, my main is just calling Init(), then calling ReadByte in a loop with incrementing addresses starting at 0, then printing the result to the serial line. All of the *_PORT and *_BIT names are #define'd in my header, and I've double-checked that the #define's match my connections. I've even added busy waits between each command, but it doesn't help. All I get back are 0x00 over and over. I have a feeling I'm just doing something really stupid, but I don't know what it might be... any ideas?
lidnariq
Site Admin
Posts: 11643
Joined: Sun Apr 13, 2008 11:12 am

Re: Reading MaskROM with a microcontroller

Post by lidnariq »

I don't think you should need to do anything with the /WE line, but that shouldn't be causing the problems you're seeing.

At this point I'd probably resort to LED or 'scope debugging to make sure that my code does what I believe it does.
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

Re: Reading MaskROM with a microcontroller

Post by qwertymodo »

Yeah, I'll probably have to go with LED's... that's way too many I/O lines to get anything useful from an Oscilloscope...
User avatar
infiniteneslives
Posts: 2104
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: Reading MaskROM with a microcontroller

Post by infiniteneslives »

You can get all kinds of info from a single oscope probe. They're really good it showing you things like conflicting data busses and such in real time. I'm not familiar with the teensy definitions, but it looks pretty choose to the avr definitions. With that I'd assume "DATA_PORT" is an output reg, and something like "DATA_PIN" is your input reg. You should use the input ref for reading, looks like you're using the output reg.
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

Re: Reading MaskROM with a microcontroller

Post by qwertymodo »

The Teensy is an AVR. Good call on the inputs being PIN_ rather than PORT_, I think that did it... Now I'm getting results that look reasonable, but are wrong about 50-60% of the time. It may be a bad socket connection or something, but hey, real results, that's a start :)

Edit: It looks like it's a single bit giving me problems (i.e. reading 0x0F when it should be 0x07, it seems to be a consistent issue with D3), so it has to be the connection. Thanks for the tip!
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

Re: Reading MaskROM with a microcontroller

Post by qwertymodo »

Putting the sockets on opposite sides of the board effectively cut the PCB size in half (as well as cutting the cost in half as well). Made the tracing a bit tricky, but I managed to do it with 0 vias :)

Image
Image
Post Reply