Can addresses conflict in main and included source codes?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
Esns68
Posts: 31
Joined: Tue Jan 07, 2020 2:03 pm

Can addresses conflict in main and included source codes?

Post by Esns68 »

I'm just a little confused about something...

While observing project source codes, it seems like things are written to the same address in the same bank.

Like in the SNES Starter-kit, in one of the projects I noticed in the main source code page,
that graphics files are written across around $0000 to $6000 in the beginning in Bank 0.
From what I understand, in bank 0 the memory registers are in the $2100's.
So it looks like all the bytes of the graphic files are written over those memory registers.
But I guess everything is still functional.

In the includes, which all like the main source, define the bank and org as 0,
have a have some things written to the same addresses as things in the other includes.
It *could* just be my imagination, but that's what it looks like to me as a noob.
But I'm very sure I'm seeing the graphics thing above the way I do.

What happens when you do that?
How does this work?
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Can addresses conflict in main and included source codes?

Post by dougeff »

The ROM is usually mapped to $8000-Ffff. So, although the graphics are at $0000 in the ROM, the SNES will see them at address $8000.

That's just how LoROM boards are designed. The address pin for that upper address bit a15 doesn't connect. Instead, the bank byte address is shifted right and the b0 pin connects to a15 of the ROM.

Thus 0-7fff of the ROM is at bank 0, $8000-ffff
8000-ffff of the ROM is at bank 1, $8000-ffff
10000-17fff of the ROM is at bank 2, $8000-ffff
etc.
nesdoug.com -- blog/tutorial on programming for the NES
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Can addresses conflict in main and included source codes?

Post by Oziphantom »

To expand on dougeff.

ROM file and SNES Address space are different.

The ROM is not linearly mapped on the SNES. To save space the ROM file skips the "empty" parts.
Post Reply