The meaning of to use mirroring on ppu or cpu memory.

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
The meaning of to use mirroring on ppu or cpu memory.
by on (#46377)
When I read :
"2000h-2007h Internal PPU Registers (mirrored to 2008h-3FFFh)"

I interpreted as :
every time I write to 200x (x varying from 0 to 7) I also write to:
Code:
while ((address + 0x08) <= 0x3FFF) {
            Memory.writeUnhandled(address + 0x08, value);
            address += 8;
        }


but i don't do this on reverse, I mean when the cpu writes to address 2008.. I don't do nothing, must I need to do the same treatment?

why or where the mirroring is used?
all mirroring works like how?

thanks in advance

by on (#46378)
Instead of writing to $2000, $2008, $2010, $2018, etc. Just write to $200x any time there is a write between $2000 and $3FFF. I'm not so studied up on my C/C++, so in a sort of basic code:

Code:
If (Address >= 0x2000) AND (Address <=3FFF)
     WriteTo((Address AND #7)) + 0x2000)
End If


If that makes any sense. On a read/write to that location, only pay attention to bits 0-2 and add $2000 to it. So if a piece of code tries to write to $3012, it will actually write to $2002 (well, it would actually read $2002 as you don't write to that register). I don't think that there actually is a memory location $2008, or $2010. I think it only reads bits 0-2 when writing to that address range. But I don't know much about that. The code above will effectively implement mirroring though.

by on (#46380)
Mirroring means ignoring one or more signals on an address bus.

In the case of PPU registers, it means "the side of the PPU on the CPU bus ignores address lines A12 through A3" because those lines aren't even connected. You can simulate this behavior by having the emulated PPU pretend that these address lines are 0 even when they aren't; hence (Address AND #7).

by on (#46385)
thanks you all...
I was doing all WRONG :$

by on (#46386)
NOTE: I had this all typed up a few hours ago, but fordot to send it! Now I'm sending it anyway, even though everything has been explained already, just because I'd hate to waste a session of typing... =)

You're doing it wrong. Mirroring means that the NES makes no distinction between an address and it's mirrors, it just thinks they are the same. If $2008 is a mirrot of $2000, writing to $2008 has the exact same effect of writing to $2000. That while statement you have there makes no sense.

In order to implement "2000h-2007h Internal PPU Registers (mirrored to 2008h-3FFFh)", you have to identify a memory access in this range and then dischard the ignored bits whenever such access happens. Look at the binary representation of the range in question:

0010000000000000 ($2000)
0011111111111111 ($3FFF)

What they have in common is the top 3 bits (001) which is what you'll use to identify a memory access to this range. Once you have identified it, and you know that the NES only cares for 8 unique addresses, ignore everything but the lower 3 bits. So, whenever an address starts with "001", use "address AND %1110000000000111".

by on (#46506)
tokumaru wrote:
NOTE: I had this all typed up a few hours ago, but fordot to send it! Now I'm sending it anyway, even though everything has been explained already, just because I'd hate to waste a session of typing... =)

You're doing it wrong. Mirroring means that the NES makes no distinction between an address and it's mirrors, it just thinks they are the same. If $2008 is a mirrot of $2000, writing to $2008 has the exact same effect of writing to $2000. That while statement you have there makes no sense.

In order to implement "2000h-2007h Internal PPU Registers (mirrored to 2008h-3FFFh)", you have to identify a memory access in this range and then dischard the ignored bits whenever such access happens. Look at the binary representation of the range in question:

0010000000000000 ($2000)
0011111111111111 ($3FFF)

What they have in common is the top 3 bits (001) which is what you'll use to identify a memory access to this range. Once you have identified it, and you know that the NES only cares for 8 unique addresses, ignore everything but the lower 3 bits. So, whenever an address starts with "001", use "address AND %1110000000000111".


This technique works in almost all cases... thanks very much.