read rom from SD card on SNES

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
hoit
Posts: 21
Joined: Sun Dec 24, 2017 10:16 am

read rom from SD card on SNES

Post by hoit » Sat Aug 10, 2019 10:22 am

Hello,

We are trying to create a rom reader for SNES and have some issues. We are using pinouts informations from here :
https://www.caitsith2.com/snes/flashcar ... nouts.html

On snes maskrom, what is the goal of /OE (pin 31) and /CS (pin 22) ?
Do you confirm that :

- /CS means address is ready for SNES ?
- /OE byte is ready for ROM ?

Do you know if value is ready when /CS has HIGH or LOW value ? We think it is ready when value is LOW

When we log informations, we see a lot of adress and values but nothing appear to the screen. Do you have any idea what could be the issue ?
Is it normal that address 80068 appears a lot of times ?
Here is a log we get after few seconds :

Adress and data value: 32238 - 107
Adress and data value: 65406 - 255
Adress and data value: 65422 - 255
Adress and data value: 32735 - 234
Adress and data value: 61299 - 48
Adress and data value: 31630 - 240
Adress and data value: 31695 - 5
Adress and data value: 22511 - 38
Adress and data value: 63487 - 35
Adress and data value: 28415 - 2
Adress and data value: 53246 - 0
Adress and data value: 65535 - 255
Adress and data value: 31707 - 116
Adress and data value: 64477 - 46
Adress and data value: 1856 - 169
Adress and data value: 17226 - 0
Adress and data value: 27353 - 252
Adress and data value: 65391 - 255
Adress and data value: 65386 - 255
Adress and data value: 30699 - 34
Adress and data value: 59982 - 4
Adress and data value: 28671 - 0
Adress and data value: 54987 - 0
Adress and data value: 17218 - 133
Adress and data value: 52062 - 255
Adress and data value: 30450 - 169
Adress and data value: 63340 - 35
Adress and data value: 36723 - 1
Adress and data value: 60379 - 0
Adress and data value: 60271 - 32
Adress and data value: 27483 - 52
Adress and data value: 61266 - 242
Adress and data value: 63307 - 0
Adress and data value: 63199 - 229
Adress and data value: 17226 - 0
Adress and data value: 27358 - 248
Adress and data value: 31476 - 116
Adress and data value: 60234 - 9
Adress and data value: 64367 - 0
Adress and data value: 27507 - 2
Adress and data value: 31739 - 128
Adress and data value: 31699 - 76
Adress and data value: 65151 - 255
Adress and data value: 46911 - 31
Adress and data value: 63227 - 34
Adress and data value: 27507 - 2
Adress and data value: 31575 - 255
Adress and data value: 60239 - 34
Adress and data value: 367 - 74
Adress and data value: 80068 - 22
Adress and data value: 96980 - 0
Adress and data value: 97429 - 0
Adress and data value: 96668 - 47
Adress and data value: 95231 - 2
Adress and data value: 97014 - 0
Adress and data value: 113364 - 176
Adress and data value: 96991 - 16
Adress and data value: 97525 - 76
Adress and data value: 71876 - 149
Adress and data value: 113369 - 5
Adress and data value: 80606 - 11
Adress and data value: 114421 - 240
Adress and data value: 81141 - 159
Adress and data value: 130972 - 255
Adress and data value: 97148 - 10
Adress and data value: 92822 - 68
Adress and data value: 113365 - 2
Adress and data value: 95660 - 48
Adress and data value: 112938 - 134
Adress and data value: 80757 - 166
Adress and data value: 97774 - 28
Adress and data value: 80068 - 22
Adress and data value: 129630 - 206
Adress and data value: 113391 - 73
Adress and data value: 130777 - 14
Adress and data value: 130801 - 165
Adress and data value: 80068 - 22
Adress and data value: 80064 - 76
Adress and data value: 92373 - 14
Adress and data value: 129774 - 128
Adress and data value: 80068 - 22
Adress and data value: 80068 - 22
Adress and data value: 122081 - 144
Adress and data value: 75972 - 201
Adress and data value: 81215 - 159
Adress and data value: 79876 - 240
Adress and data value: 89246 - 201
Adress and data value: 97229 - 194
Adress and data value: 80068 - 22
Adress and data value: 80068 - 22
Adress and data value: 121193 - 173
Adress and data value: 128409 - 224
Adress and data value: 80068 - 22
Adress and data value: 80068 - 22
Adress and data value: 97641 - 26
Adress and data value: 88937 - 107
Adress and data value: 97769 - 9
Adress and data value: 80068 - 22
Adress and data value: 95092 - 171
Adress and data value: 80068 - 22
Adress and data value: 88437 - 196
Adress and data value: 73142 - 176
Adress and data value: 120171 - 0
Adress and data value: 126420 - 201
Adress and data value: 113524 - 149
Adress and data value: 80064 - 76
Adress and data value: 122236 - 18
Adress and data value: 80068 - 22
Adress and data value: 97770 - 201
Adress and data value: 80068 - 22
Adress and data value: 71876 - 149
Adress and data value: 80281 - 185
Adress and data value: 130009 - 232
Adress and data value: 80068 - 22
Adress and data value: 80686 - 107
Adress and data value: 80068 - 22
Adress and data value: 96502 - 16
Adress and data value: 78453 - 0
Adress and data value: 103657 - 74
Adress and data value: 75908 - 34
Adress and data value: 118681 - 60
Adress and data value: 98206 - 169
Adress and data value: 78020 - 152
Adress and data value: 118734 - 56
Adress and data value: 71876 - 149
Adress and data value: 80068 - 22
Adress and data value: 114138 - 144
Adress and data value: 80068 - 22
Adress and data value: 110038 - 50
Adress and data value: 80068 - 22
Adress and data value: 80068 - 22
Adress and data value: 74511 - 169
Adress and data value: 75844 - 2
Adress and data value: 80064 - 76
Adress and data value: 110062 - 153
Adress and data value: 114073 - 133
Adress and data value: 130423 - 6
Adress and data value: 75972 - 201
Adress and data value: 119777 - 30
Adress and data value: 80068 - 22
Adress and data value: 113631 - 181
Adress and data value: 114026 - 25
Adress and data value: 81401 - 10
Adress and data value: 93561 - 34
Adress and data value: 113385 - 10
Adress and data value: 98024 - 34
Adress and data value: 80484 - 41
Adress and data value: 80068 - 22
Adress and data value: 109284 - 169
Adress and data value: 80068 - 22
Adress and data value: 80000 - 0
Adress and data value: 80068 - 22
Adress and data value: 88542 - 50
Adress and data value: 78020 - 152
Adress and data value: 78441 - 0
Adress and data value: 106390 - 208
Adress and data value: 96745 - 3
Adress and data value: 80068 - 22
Adress and data value: 89054 - 30
Adress and data value: 130462 - 28
Adress and data value: 80068 - 22
Adress and data value: 71876 - 149
Adress and data value: 118553 - 207
Adress and data value: 109927 - 54
Adress and data value: 88814 - 149
Adress and data value: 125289 - 194
Adress and data value: 89853 - 26
Adress and data value: 79940 - 26
Adress and data value: 80068 - 22
Adress and data value: 113001 - 0
Adress and data value: 129679 - 0
Adress and data value: 125289 - 194
Adress and data value: 88805 - 40
Adress and data value: 80281 - 185



Thanks for your help

lidnariq
Posts: 9658
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: read rom from SD card on SNES

Post by lidnariq » Sat Aug 10, 2019 11:54 am

On the physical ROM, /CE and /OE are signals that respectively power up the matrix of bits inside, and drive the contents of the powered-up matrix onto the data bus.

On the SNES cartridge connector, pin 49 ('/ROMSEL') is low if
A15 is high or A22 is high
and A23 downto A17 is not b'0111111'

The SNES is an asynchronous device, and there is no "address ready" signal.

nocash
Posts: 1228
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: read rom from SD card on SNES

Post by nocash » Sun Aug 11, 2019 11:39 am

hoit wrote:Here is a log we get after few seconds :
Adress and data value: 32238 - 107
Adress and data value: 65406 - 255
Adress and data value: 65422 - 255
Adress and data value: 32735 - 234
Adress and data value: 61299 - 48
Adress and data value: 31630 - 240
Adress and data value: 31695 - 5
I don't what you have logged there and why. If you store the ROM-image in a SRAM, then the SRAM should handle all memory accesses by itself, and there is no point in (trying to) log that accesses. What I can say is that the log is huge failure : )
First of, if you were intersted in the log values, then you would show them in hexadecimal, and compare them with bytes and addresses in the ROM-image disassembly.
Even with the decimal values, it looks obvious that the values are random, without any opcode fetches from increasing addresses.
It may be also goot to start logging at the rom entrypoint, not after a few seconds.
lidnariq wrote:The SNES is an asynchronous device, and there is no "address ready" signal.
What is with the CPU_CLK edges? I guess they could serve as "address ready".
I am not sure, they might also serve as "address is ready, and data must be ready, too".
The latter might be useful when logging address+data from an already existing & working memory chip.
But it might be not useful when trying to emulate a memory chip.
homepage - patreon - you can think of a bit as a bottle that is either half full or half empty

hoit
Posts: 21
Joined: Sun Dec 24, 2017 10:16 am

Re: read rom from SD card on SNES

Post by hoit » Fri Sep 27, 2019 8:48 am

Hello,

Sorry for the late reply but we are still working on this project and we didn't find why the rom is not loading.
In fact, i think we need to know the entry point of the rom.

Do you know which adress is the first called by the SNES ?
With it, we will better undestand what are these address.

Thanks

lidnariq
Posts: 9658
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: read rom from SD card on SNES

Post by lidnariq » Fri Sep 27, 2019 9:53 am

The very first thing that the SNES does when the CIC releases it from reset is read the reset vector from addresses $00FFFC and $00FFFD, followed by starting execution at the location specified by those two bytes.

hoit
Posts: 21
Joined: Sun Dec 24, 2017 10:16 am

Re: read rom from SD card on SNES

Post by hoit » Sat Sep 28, 2019 8:11 am

We tried with this online editor
https://hex-works.com/eng
then with Sublime text (0xFFFC and 0xFFFD) but they both return 0000.

With no$sns, we saw that the value is b780.

Why value are differents between hex editor and emulator ?

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

Re: read rom from SD card on SNES

Post by tepples » Sat Sep 28, 2019 8:48 am

You might not be taking into account the difference between LoROM (mode $20) and HiROM (mode $21). Unlike HiROM, which uses 64 KiB ($10000 byte) banks, LoROM uses 32 KiB ($8000 byte) banks. In LoROM, the data for the first bank ($008000-$00FFFF) is at offset $000000-$007FFF in the file, and the data for the second bank ($018000-$01FFFF) is at $008000-$00FFFF in the file. In addition, old-fashioned copiers with floppy disk drives inserted a 512-byte header before the ROM header.

Here's a quick test to try in your hex editor. Look in the following places for the game title.
  • Title at $007FC0, $20 or $30 at $007FD5: You have LoROM, and reset vector is at $007FFC in the file
  • Title at $00FFC0, $21 or $31 at $00FFD5: You have HiROM, and reset vector is at $00FFFC in the file
  • Title at $0081C0, $20 or $30 at $0081D5: You have LoROM with a floppy copier header, and reset vector is at $0081FC in the file
  • Title at $0101C0, $21 or $31 at $0101D5: You have HiROM with a floppy copier header, and reset vector is at $0101FC in the file

hoit
Posts: 21
Joined: Sun Dec 24, 2017 10:16 am

Re: read rom from SD card on SNES

Post by hoit » Sat Sep 28, 2019 9:53 am

ok thanks, we are in 1st case (lorom without floppy copier header).

But one point is not clear because no$sns provide the value on $00FFFC, like for hirom game.
maybe emulator transform data to get common range between lo and hirom...

To avoid an out of range address, we did a check for the value :

Code: Select all

if(address >= 0 && address < 262144) // 256 KB rom 
and we still get addresses outside this range (that's why the log provided in the first post seems to be corrupted).

Do you have any solution to debug directly with the snes ?
We do not have any idea to understand why it doesn't work.

We are using esp8266-12e with 2 MCP23017 (to get more GPIO) and an external SD Card. Everything seems to be correctly linked and we find address like that :

Code: Select all

  address = 0;
  if(mcp1.digitalRead(0) == HIGH) // GPA0 - mcp1 => A0 (mask rom SNES 32pin)
    address += 1;
  if(mcp1.digitalRead(1) == HIGH) // GPA1 - mcp1 => A1 (mask rom SNES 32pin)
    address += 2;
  if(mcp1.digitalRead(2) == HIGH) // GPA2 - mcp1 => A2 (mask rom SNES 32pin)
    address += 4;
  if(mcp1.digitalRead(3) == HIGH) // GPA3 - mcp1 => A3 (mask rom SNES 32pin)
    address += 8;
  if(mcp1.digitalRead(4) == HIGH) // GPA4 - mcp1 => A4 (mask rom SNES 32pin)
    address += 16;
  if(mcp1.digitalRead(5) == HIGH) // GPA5 - mcp1 => A5 (mask rom SNES 32pin)
    address += 32;
  if(mcp1.digitalRead(6) == HIGH) // GPA6 - mcp1 => A6 (mask rom SNES 32pin)
    address += 64;
  if(mcp1.digitalRead(7) == HIGH) // GPA7 - mcp1 => A7 (mask rom SNES 32pin)
    address += 128;
  if(mcp1.digitalRead(8) == HIGH) // GPB0 - mcp1 => A8 (mask rom SNES 32pin)
    address += 256;
  if(mcp1.digitalRead(9) == HIGH) // GPB1 - mcp1 => A9 (mask rom SNES 32pin)
    address += 512;
  if(mcp1.digitalRead(10) == HIGH) // GPB2 - mcp1 => A10 (mask rom SNES 32pin)
    address += 1024;
  if(mcp1.digitalRead(11) == HIGH) // GPB3 - mcp1 => A11 (mask rom SNES 32pin)
    address += 2048;
  if(mcp1.digitalRead(12) == HIGH) // GPB4 - mcp1 => A12 (mask rom SNES 32pin)
    address += 4096;
  if(mcp1.digitalRead(13) == HIGH) // GPB5 - mcp1 => A13 (mask rom SNES 32pin)
    address += 8192;
  if(mcp1.digitalRead(14) == HIGH) // GPB6 - mcp1 => A14 (mask rom SNES 32pin)
    address += 16384;
  if(mcp1.digitalRead(15) == HIGH) // GPB7 - mcp1 => A15 (mask rom SNES 32pin)
    address += 32768;

  if(mcp2.digitalRead(0) == HIGH) // GPA0 - mcp2 => A16 (mask rom SNES 32pin)
    address += 65536;
  if(mcp2.digitalRead(1) == HIGH) // GPA1 - mcp2 => A17 (mask rom SNES 32pin)
    address += 131072;
  if(mcp2.digitalRead(2) == HIGH) // GPA2 - mcp2 => A18 (mask rom SNES 32pin)
    address += 262144;
  if(mcp2.digitalRead(3) == HIGH) // GPA3 - mcp2 => A19 (mask rom SNES 32pin)
    address += 524288;

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

Re: read rom from SD card on SNES

Post by tepples » Sat Sep 28, 2019 10:12 am

hoit wrote:But one point is not clear because no$sns provide the value on $00FFFC, like for hirom game.
maybe emulator transform data to get common range between lo and hirom...
Correct. Any emulator has to emulate the memory mapping, which transforms CPU addresses into ROM addresses. In the case of the NES, Game Boy, and Game Gear, half the memory controller is on the cartridge.

nocash
Posts: 1228
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: read rom from SD card on SNES

Post by nocash » Sat Sep 28, 2019 11:03 am

Uhm, that find-the-entrypoint issue reminds of the near-finished blockbuster PSX game that got canceled shortly before release because they couldn't find out if the PSX hardware was capable of reading the current DPAD state.

Better luck to you, but if you don't even know about lorom and hirom then you won't get far with luck alone. You might really need to learn some basics about the SNES memory map, and understand differences between ROM addresses and CPU addresses.

You are tunneling the SNES address bus through a serial I2C bus in realtime, and then use software to calculate the sum of the address bits? If you can get that working then it will be absolutely impressive and outstanding; it does sound quite like an ultimate victory of technology over common sense - I only hope you have already considered details like how fast is realtime?
homepage - patreon - you can think of a bit as a bottle that is either half full or half empty

skaman
Posts: 87
Joined: Fri Oct 24, 2014 1:56 am

Re: read rom from SD card on SNES

Post by skaman » Sat Sep 28, 2019 2:14 pm

Maybe looking at the code from Arduino-based SNES Cart Reader will help you: https://forum.arduino.cc/index.php?topic=158974.0

MichlK's posts have the initial SNES reader code.

The project has evolved into a multi-console reader by sanni. sanni's Github is here: https://github.com/sanni/cartreader

nocash
Posts: 1228
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: read rom from SD card on SNES

Post by nocash » Sat Sep 28, 2019 5:55 pm

One thing that I am unsure of is what is talked about here. The first post says "rom reader", but on the other hand, the subject line saying "sd card", and the mentioning of "nothing appearing on the screen" makes me think that it is actually a "rom emulator"?
If it is a rom reader, it would be well possible with i2c hardware, the trick for dumping roms would be to write the address bits, instead of reading them.
If it is a rom emulator, I doubt that there is any chance to get that working with current i2c hardware, maybe in a 5-10 years if hardware gets yet faster.
homepage - patreon - you can think of a bit as a bottle that is either half full or half empty

hoit
Posts: 21
Joined: Sun Dec 24, 2017 10:16 am

Re: read rom from SD card on SNES

Post by hoit » Sun Sep 29, 2019 3:22 am

I confirm that we would like to read a rom on the real hardware by loading it from SD Card (like sd2snes or everdrive proejct).

If esp8266 is slow for this kind of things, i need to search on internet other way to do it.
Any clues will be welcome !

User avatar
Memblers
Site Admin
Posts: 3877
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: read rom from SD card on SNES

Post by Memblers » Sun Sep 29, 2019 5:02 am

ESP8266 is too slow. Probably any CPU will be too slow, even a blazing fast one running without an OS is still going stall and have cache misses, etc. Fast speed overall, but there's too much I/O latency for this degree of real-time control. SNES CPU won't wait for anything, so this is where digital logic is used.

If you went the most practical way, you'll probably end up with something that looks pretty much like the EverDrive. It's just going to be difficult to do it any other way.

Similar questions have come up in the past:
https://forums.nesdev.com/viewtopic.php?f=12&t=17996
https://forums.nesdev.com/viewtopic.php?f=9&t=17448

Post Reply