what does "Mask" refer to in the mapper docs?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
what does "Mask" refer to in the mapper docs?
by on (#144006)
for example looking at mapper 4 http://wiki.nesdev.com/w/index.php/INES_Mapper_004

Code:
Registers:
 ---------------------------
 Range,Mask:   $8000-FFFF, $E001


I understand which addresses are used for banking, mirroring, etc, and that $E001 is used for IRQ enable. Why is it called out specifically there? Does it have some use beyond IRQ enable?
Re: what does "Mask" refer to in the mapper docs?
by on (#144010)
The term "mask" is from an analogy with painting. e.g. If you apply masking tape to part a surface before painting it, you won't get paint anywhere it was "masked".

Usually in this context "mask" means a bitwise AND operation. Any 0 bit in the "mask" value makes that bit irrelevant (masking it).

It's saying that for these purposes "(address & mask)" should reduce the valid range of addresses to a single value that you can test against.
Re: what does "Mask" refer to in the mapper docs?
by on (#144014)
On the NES, registers are always mapped to memory locations. In order for this to happen, the addresses have to be decoded every time they are accessed so the hardware can tell whether a register is being accessed or not. To make the decoding process simpler (i.e. cheaper), not all bits of the address are observed, only the crucial ones are.

For example, take a look at a simple mapper like UNROM, which has a single register at $8000-$FFFF. The hardware only has to look at one bit of the address to know whether this register is being accessed: A15. This is because all addresses below $8000 have this bit cleared (%0xxxxxxxxxxxxxxx), while all addresses from $8000 up have this bit set (%1xxxxxxxxxxxxxxx).

The mask in the page you linked to shows which bits the MMC3 is watching in order to identify when its registers are accessed: $E001 = %1110000000000001, which means that it's watching only 4 bits out of the 16 that form an address. The highest bit selects between $0000-$7FFF and $8000-$FFFF. The next 2 bits select between $8000-9FFF, $A000-$BFFF, $C000-$DFFF and $E000-$FFFF. The lowest bit selects between even and odd addresses. This is all the MMC3 needs to know, so there's no point is wasting hardware looking at the other bits.

This is the reason why mirroring happens: since some bits of the addresses are completely ignored in the decoding process, even if two addresses have different values in the ignored bits, they will be interpreted as pointing to the same register/memory.
Re: what does "Mask" refer to in the mapper docs?
by on (#144017)
understood, thanks guys.
Re: what does "Mask" refer to in the mapper docs?
by on (#144023)
Just wanted to add the wiki explains the notations used in Disch's mapper documents at INES Mapper DischDocs*, if you hadn't already found that page.

*How to get there: wiki.nesdev.com -> NES reference guide -> Mapper -> ..."The notation used in Disch's docs is explained here."
Re: what does "Mask" refer to in the mapper docs?
by on (#144046)
I had not, that's very helpful. That would have saved me a bunch of time and has already answered a couple questions I wasn't sure I had. thanks!