+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  Converting .prg and .chr back to .nes file
Pages: [1] 2
Author Topic: Converting .prg and .chr back to .nes file  (Read 1 times)
haogden
Guest
« on: March 05, 2010, 04:50:16 pm »

Hi, I haven't been on here in a long time, and I have a question. A year ago, I made a hacked Super Mario Bros .nes file. I then converted, or split, the .nes file into a .prg and a .chr file. I now only have the .prg and .chr file. How can I make them back into a .nes file, as in what's the easiest way? Thanks in advance.
KingMike
Guest
« Reply #1 on: March 05, 2010, 09:09:31 pm »

If I remember the DOS command right it's
Code:
copy file.prg+file.chr newfile.nes
(add an iNES header to the beginning of the resulting file if it isn't already there).
Karatorian
Guest
« Reply #2 on: March 05, 2010, 10:18:55 pm »

Um, I think that command is wrong. I belive it's:
Code:
copy /b smb.prg smb.chr smb.nes

On un*x (including Mac OS X), you can do:
Code:
cat smb.prg smb.chr > smb.nes
haogden
Guest
« Reply #3 on: March 06, 2010, 11:37:07 am »

I did just as you suggested, but unfortunately it did not work.  I created the file in command prompt.  Then, to add the iNES header, I've been told that i should open the original Super Mario Bros .nes file in a hex editor, copy the first 32 digits of it, and insert (but not overwrite) those 32 digits into the beginning of the file I created in command prompt.  So that's what I did.  Did I do the right thing there?  When I open the .nes file in an emulator, I just get a gray screen.  Any ideas?
Karatorian
Guest
« Reply #4 on: March 06, 2010, 11:51:35 am »

Ok, I did some looking and it seems that both be and KingMike where half right. The + is require to combine the files. However, the /b is required to do a binary copy. Otherwise, it assumes they're ASCII text, which probably trashed your ROM.

I suggest you make the header as a seperate file, then run:
Code:
copy /b header.bin+smb.prg+smb.chr smb.nes
« Last Edit: March 06, 2010, 11:57:36 am by Karatorian »
haogden
Guest
« Reply #5 on: March 06, 2010, 01:42:47 pm »

Tried that too, exactly as described.  Same problem, gray screen.  Just to be more descriptive, I used a program called readnes to split the .nes file into the .prg and .chr (which I got here: http://www.raphnet.net/electronique/nes_cart/nes_cart_en.php).  Obviously, I don't have that .nes file anymore because I am trying to recreate it.  Also, I had modified the game using a program from zophar's domain called SMB utitility and used an option named "edit header" to change some things in some of the levels.  But I don't think that is the same header we are talking about here.  I don't know if this information matters, I'm just trying to be as descriptive as I can so as to figure out what has gone wrong here.

Anything else that could help would be greatly appreciated.  If not, thanks for all the help you have given me anyway.
Gideon Zhi
Guest
« Reply #6 on: March 06, 2010, 03:16:10 pm »

You may not be copying the right number of bytes out of the original file for the header. The header itself is *16 bytes* which looks like 32 hex digits but is only 16 decimal digits (hex pane vs ascii pane.) Try just copying 16 instead of 32.
UglyJoe
Guest
« Reply #7 on: March 06, 2010, 03:33:27 pm »

I tried dumping SMB using that tool you linked to.  Whenever it encountered 0x0a in the rom, it replaced it with 0x0d0a in the dump.  This is a conversion from a UNIX newline to a DOS newline and it shouldn't be doing it since it's dealing with binary data.  This means the prg and chr dumps are probably incorrect.

Can you post the exact file sizes of the prg and chr files?
haogden
Guest
« Reply #8 on: March 06, 2010, 04:08:38 pm »

Gideon Zhi: I tried what you suggested.  It didn't work, but instead of the usual problem with the gray screen, when I try to open it in my emulator (VirtuaNES), I first get the message "Because a NES header is illegal, there can be the thing that does not work normally.  Do Execute?" (I always get that message when playing hacked games).  But then, after I click Yes, I get this message:   "Error:  Executed an Undefined order".  Just to be clear, when I open the regular unhacked SMB.nes file in my hex editor, I see this:  4E45531A020101000000000000000000, so before when I was copying 32 digits, I was copying the whole string you see there.  When I copied the 16 digits as you suggested, I just copied 4E45531A02010100.

UglyJoe: 
SMBHack.prg:  size:  33,066 bytes          size on disc:  36,864 bytes
SMBHack.chr:  size:  8,219 bytes            size on disc:  12,288 bytes

Again, thanks to everyone who is helping me with this.  I can't express my gratitude enough for how helpful everyone here has been.  This hacked game actually has some sentimental value to me, that is why it is so important to me that i restore it.
UglyJoe
Guest
« Reply #9 on: March 06, 2010, 04:20:36 pm »

Yeah, those should have file sizes of 32768 bytes and 8192 bytes.  You'll have to go in and fix those dumps before you can make a rom out of them.  I don't have time to explain how at the moment, but I'll reply again later.  If you attempt to fix them, remember to always make a backup first!
haogden
Guest
« Reply #10 on: March 06, 2010, 04:42:43 pm »

I think I'll just wait until you get back on and explain since I wouldn't really even know where to begin
Karatorian
Guest
« Reply #11 on: March 06, 2010, 05:09:09 pm »

Quote from: UglyJoe on March 06, 2010, 03:33:27 pm
Whenever it encountered 0x0a in the rom, it replaced it with 0x0d0a in the dump.  This is a conversion from a UNIX newline to a DOS newline and it shouldn't be doing it since it's dealing with binary data.
I just checked out the source code of readnes. It opens the input file in "rb", but the output file in "w" mode. On un*x, where I suspect it was written, this wouldn't make any difference. But on other OSes, that could be a problem.
Vegetaman
Guest
« Reply #12 on: March 06, 2010, 06:10:10 pm »

Quote from: Karatorian on March 06, 2010, 05:09:09 pm
Quote from: UglyJoe on March 06, 2010, 03:33:27 pm
Whenever it encountered 0x0a in the rom, it replaced it with 0x0d0a in the dump.  This is a conversion from a UNIX newline to a DOS newline and it shouldn't be doing it since it's dealing with binary data.
I just checked out the source code of readnes. It opens the input file in "rb", but the output file in "w" mode. On un*x, where I suspect it was written, this wouldn't make any difference. But on other OSes, that could be a problem.

Yep. This can be a major, major problem.

Of course, it is fixable (a short program could fix it, I believe), just time consuming.
haogden
Guest
« Reply #13 on: March 06, 2010, 08:18:25 pm »

Quote from: Vegetaman on March 06, 2010, 06:10:10 pm
Quote from: Karatorian on March 06, 2010, 05:09:09 pm
Quote from: UglyJoe on March 06, 2010, 03:33:27 pm
Whenever it encountered 0x0a in the rom, it replaced it with 0x0d0a in the dump.  This is a conversion from a UNIX newline to a DOS newline and it shouldn't be doing it since it's dealing with binary data.
I just checked out the source code of readnes. It opens the input file in "rb", but the output file in "w" mode. On un*x, where I suspect it was written, this wouldn't make any difference. But on other OSes, that could be a problem.

Yep. This can be a major, major problem.

Of course, it is fixable (a short program could fix it, I believe), just time consuming.

Well I am willing to take the time.  I probably spent over a month making that game.  I just need to know how.
UglyJoe
Guest
« Reply #14 on: March 06, 2010, 09:06:10 pm »

Okay, here's how you can (hopefully) fix them.  Download Translhextion from here:

http://www.romhacking.net/utils/219/

Make a backup of your prg and chr files and then open one of them up in Translhextion.  Go to Search -> Replace.  Check the "Match case" option.  In the "Find what:" field, type "<bh:0d><bh:0a>" (without the quotes).  In the "Replace with:" field, type "<bh:0a>" (again, without the quotes).  Hit the "...following occurances" button.  You should see a popup that says "XX occurances replaced", where XX is a number that isn't 0.  Save the file and then repeat the process for the other file.

With any luck, the two files should now have the file sizes I listed above.  If they do, they're fixed and you should be able to combine them and make a nes rom by following the instructions earlier in the thread.  Good luck!
Pages: [1] 2  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC