It's been almost a year since I've looked at my old NES emulator (and the code is ugly....ugh) but I want to get back in the swing of things. First off, I'd like to solve an issue that had been plaguing me for a while.
I still cannot figure out how to correctly load the two attribute shift registers. I can find nothing on the wiki about how to reload the shift registers. From searching on the forum (and from looking at my old code), I know a 4 to 1 mux is used to somehow refill the two attribute shift registers. However, there is a ton of conflicting information out on the forums.
This post from one of my old threads states that the two attribute shift registers are filled at the same time: http://forums.nesdev.com/viewtopic.php?f=3&t=10351&p=116394&hilit=attribute+shift#p116394
This post states that only the high attribute shift register is reloaded and the low shift register is untouched: http://forums.nesdev.com/viewtopic.php?f=3&t=10817&hilit=attribute+shift&start=30#p123316
This post states that two adjacent tiles should have the same attribute bits: http://forums.nesdev.com/viewtopic.php?f=3&t=10817&hilit=attribute+shift&start=30#p123307
There were a few more posts I read as well, that only added more conflicting information onto this. I just need to know three things:
1. Are both shift registers reloaded?
2. What are the mux select bits? Right now I am using coarseX and coarseY.
3. Are adjacent tiles supposed to have the same attribute bits?
This is the code I have right now:
I still cannot figure out how to correctly load the two attribute shift registers. I can find nothing on the wiki about how to reload the shift registers. From searching on the forum (and from looking at my old code), I know a 4 to 1 mux is used to somehow refill the two attribute shift registers. However, there is a ton of conflicting information out on the forums.
This post from one of my old threads states that the two attribute shift registers are filled at the same time: http://forums.nesdev.com/viewtopic.php?f=3&t=10351&p=116394&hilit=attribute+shift#p116394
This post states that only the high attribute shift register is reloaded and the low shift register is untouched: http://forums.nesdev.com/viewtopic.php?f=3&t=10817&hilit=attribute+shift&start=30#p123316
This post states that two adjacent tiles should have the same attribute bits: http://forums.nesdev.com/viewtopic.php?f=3&t=10817&hilit=attribute+shift&start=30#p123307
There were a few more posts I read as well, that only added more conflicting information onto this. I just need to know three things:
1. Are both shift registers reloaded?
2. What are the mux select bits? Right now I am using coarseX and coarseY.
3. Are adjacent tiles supposed to have the same attribute bits?
This is the code I have right now:
Code:
const void ppu::fourToOneMux() //Used to refill attribute shift registers
{
//Select first bit of coarse X and Y for MUX select
const byte coarseX = 0x1;
const byte coarseY = 0x20;
bool xBit, yBit; //Holds the coarse X and Y bits
bool attBit1, attBit2; //Holds the two attrbute bits. 1 = low bit, 2 = high bit
xBit = ppuAddress & coarseX;
yBit = ppuAddress & coarseY;
//Bit 0 = xBit, Bit 1 = yBit
if(xBit == true && yBit == true) //Choose bits 6 and 7
{
attBit1 = attFetch & 0x40;
attBit2 = attFetch & 0x80;
}
else if(xBit) //Choose bits 4 and 5
{
attBit1 = attFetch & 0x10;
attBit2 = attFetch & 0x20;
}
else if(yBit) //Choose bits 2 and 3
{
attBit1 = attFetch & 0x04;
attBit2 = attFetch & 0x08;
}
else //Choose bits 0 and 1
{
attBit1 = attFetch & 0x01;
attBit2 = attFetch & 0x02;
}
//Sets all the bits the same
if(attBit1) highAttShift |= 0xFF; //Low byte 1s
else highAttShift &= ~0xFF; //Low byte 0s
if(attBit2) lowAttShift |= 0xFF; //Low byte 1s
else lowAttShift &= ~0xFF; //Low byte 0s
}
{
//Select first bit of coarse X and Y for MUX select
const byte coarseX = 0x1;
const byte coarseY = 0x20;
bool xBit, yBit; //Holds the coarse X and Y bits
bool attBit1, attBit2; //Holds the two attrbute bits. 1 = low bit, 2 = high bit
xBit = ppuAddress & coarseX;
yBit = ppuAddress & coarseY;
//Bit 0 = xBit, Bit 1 = yBit
if(xBit == true && yBit == true) //Choose bits 6 and 7
{
attBit1 = attFetch & 0x40;
attBit2 = attFetch & 0x80;
}
else if(xBit) //Choose bits 4 and 5
{
attBit1 = attFetch & 0x10;
attBit2 = attFetch & 0x20;
}
else if(yBit) //Choose bits 2 and 3
{
attBit1 = attFetch & 0x04;
attBit2 = attFetch & 0x08;
}
else //Choose bits 0 and 1
{
attBit1 = attFetch & 0x01;
attBit2 = attFetch & 0x02;
}
//Sets all the bits the same
if(attBit1) highAttShift |= 0xFF; //Low byte 1s
else highAttShift &= ~0xFF; //Low byte 0s
if(attBit2) lowAttShift |= 0xFF; //Low byte 1s
else lowAttShift &= ~0xFF; //Low byte 0s
}