Hi, I've been trying to develop an NES emulator and my PPU has been displaying stripes of incorrect color. The red color is color 0 of palette 0, so I've associated the problem with either shifting, loading, or reading the 8 bit attribute registers, but I'm not sure what's wrong.
From what I've read on the forums and wiki, in order to load the registers I have to pass the attribute byte through a 4 to 1 multiplexer with bit 1 of the coarse X and coarse Y as select bits and fill the registers with that:
I shift all 4 registers between cycles 2 and 257, and 322 and 337:
I get the palette number by passing the shift register into a 8 to 1 multiplexer with the fine scroll as the select bits:
Is my understanding correct? Thanks for any help!
From what I've read on the forums and wiki, in order to load the registers I have to pass the attribute byte through a 4 to 1 multiplexer with bit 1 of the coarse X and coarse Y as select bits and fill the registers with that:
Code:
uint8_t yBit = (this->currentVramAddr & 0x40) >> 5; // Bit 1 of coarse y in pos 1
uint8_t xBit = (this->currentVramAddr & 0x2) >> 1; // Bit 1 of carse x
// yx is used to select the corresponding 2 bits from the attribute byte
uint8_t paletteNum = (this->atByte >> ((yBit | xBit) * 2)) & 0x3;
this->highAttrShiftRegister = (paletteNum >> 1) * 0xFF;
this->lowAttrShiftRegister = (paletteNum & 0x1) * 0xFF;
uint8_t xBit = (this->currentVramAddr & 0x2) >> 1; // Bit 1 of carse x
// yx is used to select the corresponding 2 bits from the attribute byte
uint8_t paletteNum = (this->atByte >> ((yBit | xBit) * 2)) & 0x3;
this->highAttrShiftRegister = (paletteNum >> 1) * 0xFF;
this->lowAttrShiftRegister = (paletteNum & 0x1) * 0xFF;
I shift all 4 registers between cycles 2 and 257, and 322 and 337:
Code:
if(this->cycleNum >= 2 && this->cycleNum <= 257 || this->cycleNum >= 322 && this->cycleNum <= 337) {
this->lowBGShiftRegister <<= 1;
this->highBGShiftRegister <<= 1;
this->lowAttrShiftRegister <<= 1;
this->highAttrShiftRegister <<= 1;
}
this->lowBGShiftRegister <<= 1;
this->highBGShiftRegister <<= 1;
this->lowAttrShiftRegister <<= 1;
this->highAttrShiftRegister <<= 1;
}
I get the palette number by passing the shift register into a 8 to 1 multiplexer with the fine scroll as the select bits:
Code:
uint8_t lowAttrBit = (this->lowAttrShiftRegister >> (7 - this->fineXScroll)) & 0x1;
uint8_t highAttrBit = (this->highAttrShiftRegister >> (7 - this->fineXScroll - 1)) & 0x2;
uint8_t highAttrBit = (this->highAttrShiftRegister >> (7 - this->fineXScroll - 1)) & 0x2;
Is my understanding correct? Thanks for any help!