Page 1 of 1

iNES header missing entry point?

Posted: Sat Nov 28, 2015 2:05 pm
by Bowie90333212391
Where can I find the entry point for a ROM from parsing the iNES header? After getting a lot of my logic working I just realized that I have no idea where I'd be setting PC when a ROM gets loaded.

I originally thought that it was PRG ($8000), but it doesn't appear to be. Thanks.

Re: iNES header missing entry point?

Posted: Sat Nov 28, 2015 2:19 pm
by tepples
The entry point is as if JMP ($FFFC), an indirect jump, had been executed.

Re: iNES header missing entry point?

Posted: Sat Nov 28, 2015 2:24 pm
by zeroone
On a RESET, the CPU loads the vector from $FFFC/$FFFD into the program counter and continues fetching instructions from there.

Source

Re: iNES header missing entry point?

Posted: Sat Nov 28, 2015 3:12 pm
by tokumaru
And what's mapped at $FFFC/$FFFD on power up depends on the mapper, which IS specified in the header.

Re: iNES header missing entry point?

Posted: Sat Nov 28, 2015 4:26 pm
by Joe
Bowie90333212391 wrote:entry point
Only executable file formats have an entry point. The iNES header doesn't contain an entry point because it's not an executable file format.

It sounds like you're already familiar with executable file formats, so you probably already know that executable files are loaded into memory by some other program, and the entry point tells the loader where to jump after the file is loaded. On the NES, there is no loader. As soon as you plug the cartridge in, the program is present in the CPU's address space. From there, the CPU's reset behavior causes it to begin running the game.


For comparison, N64 ROMs are an executable file format. The N64 BIOS parses the executable header in order to load the game from the cartridge ROM into RAM and begin executing it.

Re: iNES header missing entry point?

Posted: Sat Nov 28, 2015 8:37 pm
by 3gengames
Wrong. The NES's entry point is the reset vector at the end of the ROM. Don't say different, that is where it is. It's not contained in the header, no. But like tokumaru said, the header tells which mapper, which tells the layout, which tells the entry.

Re: iNES header missing entry point?

Posted: Sat Nov 28, 2015 10:16 pm
by rainwarrior
Some mappers have multiple possible entry points, depending on which page of PRG is mapped into the $FXXX region on reset. Many mappers do not guarantee any particular banking setup, so a reset stub needs to be present in every bank.

Like, $FFFC/D should usually correspond to 4 bytes before the end of PRG region of the iNES file, but it could be in other places as well, and some mappers might not map the last bank to that region.

Re: iNES header missing entry point?

Posted: Sun Nov 29, 2015 12:03 am
by tokumaru
rainwarrior wrote:Like, $FFFC/D should usually correspond to 4 bytes before the end of PRG region of the iNES file, but it could be in other places as well, and some mappers might not map the last bank to that region.
Hence the need to know the mapper in order to map the contents of the ROM in the NES memory map as a real cartridge would, even if that means mapping random banks in some cases (an emulator doesn't have to bother with randomizing banks though, since games that are programmed to work on such mappers are able to boot from any bank, so you could get away with always loading the last, or the first, or whatever bank you'd like). Once everything is mapped, just read the 16-bit value at $FFFC and use that as the starting value of your PC.