iNES header missing entry point?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Bowie90333212391
Posts: 11
Joined: Sun Aug 16, 2015 9:02 am

iNES header missing entry point?

Post 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.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: iNES header missing entry point?

Post by tepples »

The entry point is as if JMP ($FFFC), an indirect jump, had been executed.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: iNES header missing entry point?

Post by zeroone »

On a RESET, the CPU loads the vector from $FFFC/$FFFD into the program counter and continues fetching instructions from there.

Source
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: iNES header missing entry point?

Post by tokumaru »

And what's mapped at $FFFC/$FFFD on power up depends on the mapper, which IS specified in the header.
Joe
Posts: 649
Joined: Mon Apr 01, 2013 11:17 pm

Re: iNES header missing entry point?

Post 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.
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Re: iNES header missing entry point?

Post 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.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: iNES header missing entry point?

Post 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.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: iNES header missing entry point?

Post 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.
Post Reply