Detecting an NES rom based on file contents.
Moderator: Moderators
-
- Posts: 7
- Joined: Tue Nov 12, 2013 7:05 am
Detecting an NES rom based on file contents.
Hey everyone!
I am writing a rom manager, and i'm a little stumped by this issue.
Is there any data inside of an NES rom that will accurately identify it as an NES rom?
Maybe something in the header?
I am writing a rom manager, and i'm a little stumped by this issue.
Is there any data inside of an NES rom that will accurately identify it as an NES rom?
Maybe something in the header?
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Detecting an NES rom based on file contents.
Traditionally you would use the entire data of the file hashed down to a single large number.
http://en.wikipedia.org/wiki/Cyclic_redundancy_check
For a .NES file it's probably best to skip the header, though, since your reasons for identifying the ROM programmatically probably have to do with a bad or inadequate header.
http://en.wikipedia.org/wiki/Cyclic_redundancy_check
For a .NES file it's probably best to skip the header, though, since your reasons for identifying the ROM programmatically probably have to do with a bad or inadequate header.
Re: Detecting an NES rom based on file contents.
If you're just asking about the magic number at the beginning of a file, it's "NES", 0x1A. That will identify a iNES format file.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
-
- Posts: 7
- Joined: Tue Nov 12, 2013 7:05 am
Re: Detecting an NES rom based on file contents.
Thanks for the reply.
The only problem with this is that I would need to check it against a database. A rom might be a work in progress, a very obscure demo, custom patch, etc.
However, the goal is to identify IF it is a NES rom but not necessarily what game it is.
I was thinking that maybe there is some tiny piece of data that is in every NES ROM that I could check against.
Any ideas are welcome!
The only problem with this is that I would need to check it against a database. A rom might be a work in progress, a very obscure demo, custom patch, etc.
However, the goal is to identify IF it is a NES rom but not necessarily what game it is.
I was thinking that maybe there is some tiny piece of data that is in every NES ROM that I could check against.
Any ideas are welcome!
-
- Posts: 7
- Joined: Tue Nov 12, 2013 7:05 am
Re: Detecting an NES rom based on file contents.
That might be what i'm looking for. I'll give this a shot!Dwedit wrote:If you're just asking about the magic number at the beginning of a file, it's "NES", 0x1A. That will identify a iNES format file.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Detecting an NES rom based on file contents.
Oh, sorry, I misunderstood the question. Yes, I think Dwedit's answer should be enough. Normally they also have the .NES file extension... How come you need to identify it from the file contents?
-
- Posts: 7
- Joined: Tue Nov 12, 2013 7:05 am
Re: Detecting an NES rom based on file contents.
Better usabilityrainwarrior wrote:Oh, sorry, I misunderstood the question. Yes, I think Dwedit's answer should be enough. Normally they also have the .NES file extension... How come you need to identify it from the file contents?
I'm going to assume that the user may have (incorrectly) renamed/removed the file extension
This is also an issue with other roms/images that use the same extension.
For example, I would need to do something similar for gamecube and PS2
roms that use the same file extension .ISO
Re: Detecting an NES rom based on file contents.
PlayStation and PlayStation 2 games should use ISO because they are images of ISO 9660 (CD) or ISO/IEC 13346 (DVD) file systems. I was under the impression that GameCube games should use a different extension because they use a different file system. I've seen .gcm in use.
The problem is similar to distinguishing a program written in Python 2 from a program written in Python 3. The "open" action under Windows looks only at the file name suffix, and it took Python Software Foundation years to get a proper handler for .py files under Windows that distinguishes Python 2 from Python 3 by the #! line.
The problem is similar to distinguishing a program written in Python 2 from a program written in Python 3. The "open" action under Windows looks only at the file name suffix, and it took Python Software Foundation years to get a proper handler for .py files under Windows that distinguishes Python 2 from Python 3 by the #! line.
-
- Posts: 7
- Joined: Tue Nov 12, 2013 7:05 am
Re: Detecting an NES rom based on file contents.
This is the root of my problem. Some roms (or disk images) may use the same file extension for different platforms.tepples wrote:PlayStation and PlayStation 2 games should use ISO because they are images of ISO 9660 (CD) or ISO/IEC 13346 (DVD) file systems. I was under the impression that GameCube games should use a different extension because they use a different file system. I've seen .gcm in use.
Dolphin can read: .gcm, .ISO, ..
PCSX2 can read: .bin, .ISO, ..
So I'm looking for ways to read the files contents and look for parters to determine the type of rom (or disk image)
Re: Detecting an NES rom based on file contents.
If the file doesn't have the correct extension, then most (if not all) emulators won't even list it in their Open dialogs (for those that have Open dialogs, which is most of them), so that assumption probably isn't meaningful. Some emulators (such as my own) also check the extension to determine how to load the file, in which case an incorrect extension would prevent them from being loaded at all.simonwjackson wrote:I'm going to assume that the user may have (incorrectly) renamed/removed the file extension
For other platforms, there's certainly the issue of one extension possibly having multiple meanings (especially Genesis ROMs which idiotically use the .BIN extension), but that's not a problem with the NES.
Last edited by Quietust on Tue Nov 12, 2013 8:52 am, edited 2 times in total.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
P.S. If you don't get this note, let me know and I'll write you another.
Re: Detecting an NES rom based on file contents.
I wrote a program that needed to distinguish different kinds of ROMs. I didn't deal with any disk based systems, so I can't help you there. For most ROMs, I just looked for some kind of magic number or standard string. You could go further and start verifying header data, but in my case this didn't seem necessary.
For SNES, there isn't any magic number or standard string that I was aware of. (SMC headers have become much less popular, and if added back on, they may consist of all zeros instead of the correct SMC values.) Instead I verified the internal checksum if the ROM wasn't exceedingly large.
In cases where more than one possible system was identified (or zero), I would disambiguate by file extension. If that failed, I simply asked the user to manually specify the system. But my program only worked on one ROM at a time. If it saves you any trouble, the utility is here, as well as a link to the source, and includes an HTML file that details platform detection.
For SNES, there isn't any magic number or standard string that I was aware of. (SMC headers have become much less popular, and if added back on, they may consist of all zeros instead of the correct SMC values.) Instead I verified the internal checksum if the ROM wasn't exceedingly large.
In cases where more than one possible system was identified (or zero), I would disambiguate by file extension. If that failed, I simply asked the user to manually specify the system. But my program only worked on one ROM at a time. If it saves you any trouble, the utility is here, as well as a link to the source, and includes an HTML file that details platform detection.
-
- Posts: 7
- Joined: Tue Nov 12, 2013 7:05 am
Re: Detecting an NES rom based on file contents.
Awesome, thanks for the link! This really helps!
Re: Detecting an NES rom based on file contents.
Tell that to Linux/OSX/Other flavor of Unix users where file extensions are just for user's convenience and shouldn't be used to detect file types (10th paragraph, possibly more later on). So let's say, Mario rom can be called (in file system)Quietust wrote:If the file doesn't have the correct extension, then most (if not all) emulators won't even list it in their Open dialogs (for those that have Open dialogs, which is most of them), so that assumption probably isn't meaningful. Some emulators (such as my own) also check the extension to determine how to load the file, in which case an incorrect extension would prevent them from being loaded at all.simonwjackson wrote:I'm going to assume that the user may have (incorrectly) renamed/removed the file extension
For other platforms, there's certainly the issue of one extension possibly having multiple meanings (especially Genesis ROMs which idiotically use the .BIN extension), but that's not a problem with the NES.
mario.nes
mario.rom
mario
(or if someone is particularly crazy)
mario.bin.doc.xls
So detecting by header structure (should look like iNES header) rather than file extension has certain benefits as you can see unless you are ABSOLUTELY sure you'll NEVER port it on unix-like system.
Re: Detecting an NES rom based on file contents.
Find a file with lots of occurrences of the pairs $15 $40 and $07 $20
Re: Detecting an NES rom based on file contents.
I'd be surprised in PS1 images uses ISO, it's very common for PS1 games to use MODE2 sectors (that is, store meaningful data in what is error correction data in MODE1), so it can't be represented by ISO images. CUE/BIN or CUE/IMG is often used.