Page 1 of 1

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

Posted: Wed Oct 21, 2009 1:08 pm
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

Posted: Wed Oct 21, 2009 1:34 pm
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.

Posted: Thu Oct 22, 2009 2:06 am
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?

Posted: Thu Oct 22, 2009 6:05 am
by Dwedit
CHR RAM is the stuff you can write to while the program runs, so there's no predefined data for it.

Posted: Thu Oct 22, 2009 6:40 am
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....

Posted: Thu Oct 22, 2009 6:54 am
by tepples
The data is stored in the PRG ROM, and the program copies it to CHR RAM.

Posted: Thu Oct 22, 2009 6:58 am
by Rid
Ok, I've understood :)

Posted: Thu Oct 22, 2009 7:16 am
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.