11 March 2016 - Forum Rules

Main Menu

Working out where PRG and CHR ROM start?

Started by jackwilsdon, December 19, 2013, 06:21:18 PM

Previous topic - Next topic


I currently calculate the size of PRG and CHR ROM using the following code;

prg_page_size = 16384;
chr_page_size = 8192;

prg_rom_size = header[4] * prg_page_size
chr_rom_size = header[5] * chr_page_size

But what do I do after this? I don't know how to calculate the position of PRG and CHR ROM inside the .nes file itself.

iNES file format documentation
The important parts of the documentation are under Section 2 (there is a table of header bytes) and Section 4 (list of rom sizes).


Quote from: Disch
- $10 byte header
- optional $200 byte trainer (typically absent)
- X*$4000 PRG-ROM banks
- X*$2000 CHR-ROM banks
So, PRG ROM will be offset by

0x10 + trainer ? 0x200 : 0

and CHR ROM will be offset by

0x10 + trainer ? 0x200 : 0 + prg_rom_size.
we are in a horrible and deadly danger


Thanks, I guessed it would be offset by the the header and PRG size (when finding CHR), but I completely forgot about the trainer. Do any iNES roms even have trainers nowadays?


we are in a horrible and deadly danger


I think it's not unheard of for pirate/unlicensed ROMs to use the trainer for initialization. If so, it's probably the only thing they're used for anymore.


From what I heard, trainers, when they were used was, was often for mapper hacks (possibly part of the now-depreciated mappers 6 and 8, which were copier mappers). Kind of pointless now that all official mappers are supported (minus any variations that come up. You know, like obscure MMC3 games that really on obscure hardware behavior to run right.)
"My watch says 30 chickens" Google, 2018