How to extract CHR & PRG from a NES/UNiF file

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
MasterDisk
Posts: 6
Joined: Wed Oct 21, 2009 5:30 am

How to extract CHR & PRG from a NES/UNiF file

Post by MasterDisk »

Epic n00b question :D
Everything is in the title:
How to extract CHR & PRG from a NES/UNiF file.

But without using raphnet's ReadNES.exe
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

The vast majority* of iNES ROM files are structured like this:
header, PRG ROM, CHR ROM
-or-
header, PRG ROM

Read the first 16 bytes from the file. This is the header.
Byte 0x0004 of the header is the PRG ROM size in 16384-byte units.
Byte 0x0005 of the header is the CHR ROM size in 8192-byte units. This may be 0, in which case the cartridge uses only CHR RAM.
Now read the PRG ROM, and read the CHR ROM if it is present.


* Excluding a few mapper hacks that use an obscure iNES feature to load 512 bytes of code into PRG RAM before execution begins.
User avatar
Rid
Posts: 66
Joined: Sun May 10, 2009 4:06 am

Post by Rid »

tepples wrote: Byte 0x0005 of the header is the CHR ROM size in 8192-byte units. This may be 0, in which case the cartridge uses only CHR RAM.
How does CHR RAM work?
Are not CHR ROM and CHR RAM the same? I mean, isn"t CHR RAM store into 8192-byte banks placed after PRG ROM into an iNES file?
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

CHR RAM is the stuff you can write to while the program runs, so there's no predefined data for it.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Rid
Posts: 66
Joined: Sun May 10, 2009 4:06 am

Post by Rid »

But, how can a game have a title screen if all its character data is RAM?

Unless, if title screen data is stored into PRG ROM. Which mean that PRG ROM is a melting pot of both PRG and CHR data....
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

The data is stored in the PRG ROM, and the program copies it to CHR RAM.
Last edited by tepples on Thu Oct 22, 2009 7:15 am, edited 2 times in total.
User avatar
Rid
Posts: 66
Joined: Sun May 10, 2009 4:06 am

Post by Rid »

Ok, I've understood :)
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

A program using CHR RAM is a melting pot, but this has the advantage of opening up several possibilities:
  • Fine-grained tile animation (e.g. water in Final Fantasy games)
  • Compression of tile data (e.g. Contra, Codemasters games)
  • Drawing shapes at pixel precision (e.g. Qix, Hatris, Videomation)
  • Displaying video generated by a coprocessor (e.g. Wide Boy)
  • Familiarity for people who grew up programming for other platforms (e.g. ColecoVision, Commodore 64)
The NES and Neo Geo AES are the only consoles I can think of that use CHR ROM on the cartridge at all. Everything else has onboard CHR RAM, either dedicated or unified with main RAM.
Post Reply