It is currently Tue Oct 17, 2017 4:40 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Mar 24, 2017 5:05 pm 
Offline

Joined: Tue Mar 14, 2017 6:11 pm
Posts: 2
Hello there, first time posting here and first time working with the nes, so sorry in advance if this has been asked before as I wasnt able to find a post.

I am currently writing an NES emulator in verilog to be synthesized for an FPGA. And I am running into some issues understanding where the PRG and CHR ROM would be located if I was loading a ROM block with the data from a .nes file. (I'm only talking about NROM due to it's simplicity at the moment)

As I understand it, the NROM cartridge (aka mapper 0) contains 16 bytes of header data followed by 16384 bytes of PRG ROM (assuming there isn't a trainer.) In the actual NES this ROM would be mapped to $C000 to $FFFF and consequently mirrored to $8000 to $BFFF. Knowing this I think I should be able to read the .nes file and locate the end of the PRG ROM and consequently find the $FFFC/D reset vector for the 6502.

The ROM I used to test so far was the nestest.nes file from the nesdev wiki

So by some simple arithmetic I found what I think is the Reset Vector at byte $400C/D inside the .nes file. Following the vector to address location $C004,
Image
Image

I go to byte $0014 in the .nes file. finding the instruction #78 which is the opcode for SEI, so it appears that my assumption is correct for this file. Additionally I did the same with donkey kong as well and it would seem that the address at the reset vector leads me to $07AE which has again the instruction #78.

Image

Image

Now my question is this, have I made any mistaken assumptions regarding the organization of the format? if not, is the CHR rom just the next 2k bytes from the $400F in the file?

Additionally, are all NROM-mapped roms organized the same way?

Thanks in advance to anybody who can lend an answer.


Top
 Profile  
 
PostPosted: Fri Mar 24, 2017 5:12 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5709
Location: Canada
The format is described here:
https://wiki.nesdev.com/w/index.php/INES

One byte in the header will tell you how many 16k blocks of PRG there are. Another byte will tell you how many 8k blocks of CHR there are.

Some NROM games have 32k instead of 16k of PRG. I think there might be one or two with no CHR in the file as well (using RAM instead of ROM). Again, though, this is all specified by the header, so you can figure it out from that.


Top
 Profile  
 
PostPosted: Fri Mar 24, 2017 5:26 pm 
Offline

Joined: Mon Nov 10, 2008 3:09 pm
Posts: 429
searzocom wrote:
Hello there, first time posting here and first time working with the nes, so sorry in advance if this has been asked before as I wasnt able to find a post.

I am currently writing an NES emulator in verilog to be synthesized for an FPGA. And I am running into some issues understanding where the PRG and CHR ROM would be located if I was loading a ROM block with the data from a .nes file. (I'm only talking about NROM due to it's simplicity at the moment)

As I understand it, the NROM cartridge (aka mapper 0) contains 16 bytes of header data followed by 16384 bytes of PRG ROM (assuming there isn't a trainer.) In the actual NES this ROM would be mapped to $C000 to $FFFF and consequently mirrored to $8000 to $BFFF. Knowing this I think I should be able to read the .nes file and locate the end of the PRG ROM and consequently find the $FFFC/D reset vector for the 6502.

The ROM I used to test so far was the nestest.nes file from the nesdev wiki

So by some simple arithmetic I found what I think is the Reset Vector at byte $400C/D inside the .nes file. Following the vector to address location $C004,
Image
Image

I go to byte $0014 in the .nes file. finding the instruction #78 which is the opcode for SEI, so it appears that my assumption is correct for this file. Additionally I did the same with donkey kong as well and it would seem that the address at the reset vector leads me to $07AE which has again the instruction #78.

Image

Image

Now my question is this, have I made any mistaken assumptions regarding the organization of the format? if not, is the CHR rom just the next 2k bytes from the $400F in the file?

Additionally, are all NROM-mapped roms organized the same way?

Thanks in advance to anybody who can lend an answer.


The fifth and sixth bytes in the .nes header, immediately after the FourCC ("NES\x1a"), indicate the amount of PRG and CHR data in units of 16KB and 8KB respectively. .nes dumps of cartridges without PRG ROM bankswitching can have either 16KB (fifth byte of header = 01) or 32KB (fifth byte of header = 02) of PRG ROM.


Top
 Profile  
 
PostPosted: Fri Mar 24, 2017 5:37 pm 
Offline

Joined: Tue Mar 14, 2017 6:11 pm
Posts: 2
oh shit yeah, I see so the header does contain that info.

My next question is if i wanted to understand how bank-switching works for other types of roms, what's a good starting point to read?


Top
 Profile  
 
PostPosted: Fri Mar 24, 2017 5:51 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5709
Location: Canada
Every mapper does it differently. Maybe just start here and read about the mapper that corresponds to a file you're interested in:
http://wiki.nesdev.com/w/index.php/Mapper

The common mappers generally have low numbers (e.g. the original version of iNES only went from 0-15, wasn't expecting there to be hundreds of mappers like there is). You can cover like 95% of ROMs with only a handful of them.

In general, PRG banks come in 8, 16, or 32k blocks. CHR banks come in 1, 2, 4, or 8k blocks. The iNES file format doesn't distinguish this though, it just expects the total size to be a multiple of 16k/8k but this has nothing to do with how the mapper banks it.

If something is using 8k banking, bank 0 is the first 8k of the PRG, bank 1 is the second 8k, etc.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 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:  
Powered by phpBB® Forum Software © phpBB Group