I have read many times in several places about how VRAM can only be read/written during VBlank. I am still a little confused about this.
My question is, when do I use data written to 2005/2006 for scrolling and when do I just write to 2005/2006 and ignore the data as scroll data? I know that sometimes what is written to those locations is used for scrolling, but not always. I've been wrestling with this issue for some time now and I'm ready to get past it.
I really would like to know how to handle data when it's being written to 2005 and 2006. It is my understanding that VBlank and BGEnable and SPREnable are somehow involved, but I'm just to sure how.
I'm not sure if either of these are going down the right path, but here is some pseudo code that probably better explains my confusion:
Thanks
EDIT: I guess posting some real code might help, so here it is. This is inside of my setMemoryByte() function.
My question is, when do I use data written to 2005/2006 for scrolling and when do I just write to 2005/2006 and ignore the data as scroll data? I know that sometimes what is written to those locations is used for scrolling, but not always. I've been wrestling with this issue for some time now and I'm ready to get past it.
I really would like to know how to handle data when it's being written to 2005 and 2006. It is my understanding that VBlank and BGEnable and SPREnable are somehow involved, but I'm just to sure how.
I'm not sure if either of these are going down the right path, but here is some pseudo code that probably better explains my confusion:
Code:
if((addr == 0x2005) && !vblank)
{ //place scroll 'data' into 't' }
or
if((addr == 0x2005) && (bgEnabled || spritesEnabled))
{ //place scroll 'data' into 't' }
//and then the same idea with 2006
{ //place scroll 'data' into 't' }
or
if((addr == 0x2005) && (bgEnabled || spritesEnabled))
{ //place scroll 'data' into 't' }
//and then the same idea with 2006
Thanks
EDIT: I guess posting some real code might help, so here it is. This is inside of my setMemoryByte() function.
Code:
// Screen Scroll Offset
else if (intAddr == 0x2005)
{
if (!PPULatchToggle)
{
// Offset X
t &= 0xFFE0;
t |= ((byteOne & 0xF8) >> 3);
fineX = (byte)(byteOne & 0x07);
}
else
{
// Offset Y
t &= 0xFC1F;
t |= ((byteOne & 0xF8) << 2);
t &= 0x8FFF;
t |= ((byteOne & 0x07) << 12);
}
PPULatchToggle = !PPULatchToggle;
}
else if (intAddr == 0x2006)
{
if (!PPULatchToggle)
{
// Copy byte into temporary location
intPPUAccess = byteOne;
#region Scrolling Data
// Get first 2006 write bits
t &= 0xC0FF;
t |= ((byteOne & 0x3F) << 8);
// Clear top two bits
t &= 0x3FFF;
#endregion
}
else if (PPULatchToggle)
{
intPPUAccess = byteOne + intPPUAccess * 16 * 16;
#region Scrolling Data
// Get second 2006 write bits
t &= 0xFF00;
t |= byteOne;
#endregion
}
PPULatchToggle = !PPULatchToggle;
}
else if (intAddr == 0x2005)
{
if (!PPULatchToggle)
{
// Offset X
t &= 0xFFE0;
t |= ((byteOne & 0xF8) >> 3);
fineX = (byte)(byteOne & 0x07);
}
else
{
// Offset Y
t &= 0xFC1F;
t |= ((byteOne & 0xF8) << 2);
t &= 0x8FFF;
t |= ((byteOne & 0x07) << 12);
}
PPULatchToggle = !PPULatchToggle;
}
else if (intAddr == 0x2006)
{
if (!PPULatchToggle)
{
// Copy byte into temporary location
intPPUAccess = byteOne;
#region Scrolling Data
// Get first 2006 write bits
t &= 0xC0FF;
t |= ((byteOne & 0x3F) << 8);
// Clear top two bits
t &= 0x3FFF;
#endregion
}
else if (PPULatchToggle)
{
intPPUAccess = byteOne + intPPUAccess * 16 * 16;
#region Scrolling Data
// Get second 2006 write bits
t &= 0xFF00;
t |= byteOne;
#endregion
}
PPULatchToggle = !PPULatchToggle;
}