tokumaru wrote:
I didn't catch anything that would result in the output you showed us, but I did notice a few problems:
- The attribute table base address is wrong;
- The attribute data is not used at all;
- extractCurrentBitFromPatternTable doesn't use i;
I rewrote a few formulas and completed some things that were missing (attributes, mostly), hopefully I didn't make any horrible mistakes:
Code:
for (row < 30) {
for (col < 32) {
nameTable = read(0x2000 + (row << 5) + col);
attrTable = read(0x23c0 + ((row >> 2) << 3) + (col >> 2));
attribute = (attrTable >> (((row & 0x02) << 1) + (col & 0x02))) & 0x03;
patternTableAddr = (nameTable << 4) + ((ctrl & 0x10) << 8);
for (i < 8) {
for (bit < 8) {
currentPixel = ((pattern[patternTableAddr + i] >> (7 - bit)) & 0x01) + (((pattern[patternTableAddr + i + 8] >> (7 - bit)) & 0x01) << 1);
pixelColor = palette[(attribute << 2) + currentPixel];
screen[(row << 3) + i][(col << 3) + bit] = pixelColor;
}
}
}
}
There's another thing I'd like to get out of the way: Are you separating CPU RAM from PPU RAM? People are sometimes confused by the fact that there are 2 separate buses, and if you don't emulate this correctly there's no way that the various tables will be populated and read correctly. I'm particularly worried about your read() function... is it reading from VRAM?
Sorry about that. I made it pseudocode and left a few things out. (I am using i in my real calculation for the pixel).
Also, I am seperating PPU and CPU ram, so that isn't an issue. If you don't mind helping I can PM you the repo where my code is located.
edit: By examining your code i realized I was rendering each pattern mirrored and fixed that. Now the letters are in the correct direction and I have color. However, it is still the same jumbled pattern and still turns to grey after only a few frames of this jumble.
Attachment:
CaptureColor.JPG [ 25.75 KiB | Viewed 707 times ]