News: 11 March 2016 - Forum Rules

Author Topic: Working out where PRG and CHR ROM start?  (Read 3468 times)

jackwilsdon

  • Guest
Working out where PRG and CHR ROM start?
« on: December 19, 2013, 06:21:18 pm »
I currently calculate the size of PRG and CHR ROM using the following code;

Code: [Select]
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).

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: Working out where PRG and CHR ROM start?
« Reply #1 on: December 19, 2013, 06:57:44 pm »
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

jackwilsdon

  • Guest
Re: Working out where PRG and CHR ROM start?
« Reply #2 on: December 20, 2013, 08:08:12 am »
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?

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: Working out where PRG and CHR ROM start?
« Reply #3 on: December 20, 2013, 09:57:15 am »
It is doubtful.
we are in a horrible and deadly danger

furrykef

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: Working out where PRG and CHR ROM start?
« Reply #4 on: December 20, 2013, 06:46:55 pm »
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.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7255
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Working out where PRG and CHR ROM start?
« Reply #5 on: December 20, 2013, 07:35:07 pm »
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