It is currently Thu Nov 23, 2017 5:52 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sat Nov 28, 2015 2:05 pm 
Offline

Joined: Sun Aug 16, 2015 9:02 am
Posts: 11
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.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 2:19 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19251
Location: NE Indiana, USA (NTSC)
The entry point is as if JMP ($FFFC), an indirect jump, had been executed.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 2:24 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 729
Location: New York, NY
On a RESET, the CPU loads the vector from $FFFC/$FFFD into the program counter and continues fetching instructions from there.

Source


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 3:12 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10118
Location: Rio de Janeiro - Brazil
And what's mapped at $FFFC/$FFFD on power up depends on the mapper, which IS specified in the header.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 4:26 pm 
Offline

Joined: Mon Apr 01, 2013 11:17 pm
Posts: 437
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.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 8:37 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2257
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.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 10:16 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5832
Location: Canada
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.


Top
 Profile  
 
PostPosted: Sun Nov 29, 2015 12:03 am 
Offline
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group