6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 2:41 pm

All times are UTC




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat May 08, 2021 7:48 pm 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
Hi everybody
I am new here
I am doing some basic work reading Nes rom , I've choosed a small size rom (Nuts & Milk) , which is 6000 bytes
I have read that the program's banks addresses are :
$8000 $4000 PRG-ROM
$C000 $4000 PRG-ROM

how that would be applicable on the rom I've mentioned above ?
any explanations are welcomed .


Top
 Profile  
Reply with quote  
PostPosted: Sat May 08, 2021 9:04 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
Welcome! 6000 bytes sounds very unlikely to me. A quick look leads me to expect a 16k program ROM and an 8k character ROM.

AFAICT a 16k NES ROM will appear at $8000 and $c000 because of incomplete address decoding, so that's probably what's meant by the bank addresses.

http://wiki.nesdev.com/ is a good place to look for details.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 08, 2021 9:19 pm 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
Thanks for welcoming me :)
you are right
I opened it with a hex viewer , last address was 6000 , but that is in hexadecimal !
then it should be 24576 bytes , windows explorer says it is 24.0 KB (24,592 bytes)
I will check the link you've posted , I will be back soon , I need to ask some more questions .


Top
 Profile  
Reply with quote  
PostPosted: Sat May 08, 2021 9:23 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
If you're seeing 24k, you're probably seeing the concatenation of the program ROM and the character ROM. I think not how the two ROMs look to the NES: "An NES cartridge has at least two memory chips on it: PRG (connected to the CPU) and CHR (connected to the PPU)."

If you're seeing 24k+16 bytes, thats a file format for emulators which has a 16 byte header.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 08, 2021 9:37 pm 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
I am using a C compiler to read the entire rom inside a buffer byte array as the following :
Code:
rom = (unsigned char*) malloc (sizeof(unsigned char)*64001); // allocate enough space
fread (rom,sizeof(unsigned char),24592,fp); //

I checked my array compared to the hex editor , and it's fine , both are equal
now , how to jump to program first instruction ?
just like the following :

Code:
pc=0x8000; // program counter variable
instruction = rom [pc] ;


something confusing me alot :
$8000 in hexadecimal = 32768 !
$C000 in hexadecimal = 786432 !

how would these values fit to my rom file , it's only 24 kb ?

forgive me I am new to that stuff .


Last edited by Santa-Fe on Sat May 08, 2021 9:43 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat May 08, 2021 9:39 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
You need to read the reset vector to find the start address of the code. Check out the nesdev wiki.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 08, 2021 11:38 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 894
Santa-Fe wrote:
I am using a C compiler to read the entire rom inside a buffer byte array as the following :
Code:
rom = (unsigned char*) malloc (sizeof(unsigned char)*64001); // allocate enough space
fread (rom,sizeof(unsigned char),24592,fp); //

I checked my array compared to the hex editor , and it's fine , both are equal
now , how to jump to program first instruction ?
just like the following :

Code:
pc=0x8000; // program counter variable
instruction = rom [pc] ;


something confusing me alot :
$8000 in hexadecimal = 32768 !
$C000 in hexadecimal = 786432 !

how would these values fit to my rom file , it's only 24 kb ?

forgive me I am new to that stuff .


Hexadecimal $C000 = 49152 decimal.
Hexadecimal $C0000 = 786432 decimal.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 9:50 am 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
JimBoyd wrote:
Hexadecimal $C000 = 49152 decimal.
Hexadecimal $C0000 = 786432 decimal.

Still larger than my 24 kb rom addresses .


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 11:11 am 
Offline

Joined: Sat Jan 02, 2016 10:22 am
Posts: 197
If your file is 16 bytes longer than 24k, then as, there's likely a 16 byte header. Unless you know the format of the header, ignore it ! it's very unlikely to be part of the orignal game.

If you're expexting data from 2 chips one 8k for graphic definitions one 16k for the game code, then there's 2 options, 8k first or 16k first.

What you're interested in is the last bytes of the code rom, as they will be most likely be the 6502 hardware vectors.

If the 8k graphic one is first, then the last 6 bytes of the 16k rom will be the very last 6 bytes of the file.
Code:
Option 1 -  file offsets
0000-000F - Header
0010-200F - Graphic data
2010-6009 - game code
600A-600F - 6502 Vectors

If the 16k rom is first, then the last 6 bytes of the 16k rom will be at offset 0x400A
Code:
Option 2 -  file offsets
0000-000F - Header
0010-4009 - game code
400A-400F - 6502 Vectors
4010-600F - Graphic data


If all 3 vectors look sensible, then you could have the right spot. If they don't make sense, you could be looking at graphic data. Where the vecors jump too should give you clues as to where the rom expects to be run from.

For example reset or interrupt vector of 0xBXXX wouldn't be in a rom located at 0xC000 to 0xFFFF so the rom in that case would probably expect to be 0x8000 to 0xFFFF.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 1:56 pm 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
Hi Martin
your explanation is interested
is that the way how emulators get the start address of the program ?
I am currently working on a (mapper 0) rom , (no mapper ,no scrolling right now)
I just need to start with a simple emulator (currently the CPU)

I am still confused how addresses like : $C000 = 49152 decimal, $8000 = 32768 decimal
can be used to addressing a rom with 24592 decimal ?


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 4:30 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
Hmm, what did you make of my message mentioning the PRG and CHR ROMs?


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 5:00 pm 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
BigEd wrote:
Hmm, what did you make of my message mentioning the PRG and CHR ROMs?

I am totally lost , I have read the wiki that you've mentioned , also googled alot before and after posted my question
but I can't figure how a rom ends with address $6000, can be addressed with range $8000 and $c000 !


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 6:07 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
I've just realised something which might be a root of confusion.

In the world of emulated cartridge games, people say 'ROM' when they mean 'Some binary data which encapsulates everything important about a particular cartridge'

In the world of 6502 computers, people say 'ROM' when they mean 'Some binary data which will be found in an EPROM which is seen at some range of addresses in the 6502 address space'

The *.nes file which you have, of length 24592, is a ROM in the first sense. It's not a ROM in the second sense. It contains 3 things
- a 16 byte header
- 16k of program data to be mapped at $8000 and also at $C000
- 8k of character data to be made available to the PPU

If you want to investigate the 6502's view of the game, you need to extract the 16k PRG ROM image and map it into memory twice, once at $8000 and again at $C000. And then you can read the reset vector at $FFFC to get the start address.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 7:04 pm 
Offline

Joined: Thu May 06, 2021 7:07 pm
Posts: 14
Hi BigEd
Quote:
- 16k of program data to be mapped at $8000 and also at $C000


1. What I can understand of that is :
the 16k prog. data will start at $8000 and end at $C000

2. is the meaning of map it
put it at a new addresses ranges which are ($8000 - $C000) to be suitable for the 6502 nes system ?


Top
 Profile  
Reply with quote  
PostPosted: Sun May 09, 2021 7:09 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
The same data has to appear twice in the memory map, because that's how the machine works. An emulator might possibly do that for you, or you might need to place the ROM data twice.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 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: