nesdev.com
http://forums.nesdev.com/

iNES header missing entry point?
http://forums.nesdev.com/viewtopic.php?f=3&t=13560
Page 1 of 1

Author:  Bowie90333212391 [ Sat Nov 28, 2015 2:05 pm ]
Post subject:  iNES header missing entry point?

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.

Author:  tepples [ Sat Nov 28, 2015 2:19 pm ]
Post subject:  Re: iNES header missing entry point?

The entry point is as if JMP ($FFFC), an indirect jump, had been executed.

Author:  zeroone [ Sat Nov 28, 2015 2:24 pm ]
Post subject:  Re: iNES header missing entry point?

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

Source

Author:  tokumaru [ Sat Nov 28, 2015 3:12 pm ]
Post subject:  Re: iNES header missing entry point?

And what's mapped at $FFFC/$FFFD on power up depends on the mapper, which IS specified in the header.

Author:  Joe [ Sat Nov 28, 2015 4:26 pm ]
Post subject:  Re: iNES header missing entry point?

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.

Author:  3gengames [ Sat Nov 28, 2015 8:37 pm ]
Post subject:  Re: iNES header missing entry point?

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.

Author:  rainwarrior [ Sat Nov 28, 2015 10:16 pm ]
Post subject:  Re: iNES header missing entry point?

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.

Author:  tokumaru [ Sun Nov 29, 2015 12:03 am ]
Post subject:  Re: iNES header missing entry point?

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.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/