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

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
How to extract CHR & PRG from a NES/UNiF file
by on (#51575)
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

by on (#51577)
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.

by on (#51603)
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?

by on (#51604)
CHR RAM is the stuff you can write to while the program runs, so there's no predefined data for it.

by on (#51605)
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....

by on (#51607)
The data is stored in the PRG ROM, and the program copies it to CHR RAM.

by on (#51608)
Ok, I've understood :)

by on (#51609)
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.