Hi!
I restarted the development of my NES emulator that I started back in 1997. I thought that nothing would work but to my surprise, I did not had much tweaking to do to at least make the intro screens of a few games show. But now my next step is to make the attribute table works. I don't plan release this emulator, I am doing this for fun.
Right now, I can see the intro of Ice Hockey with a few animations with also a few glitches. I succeeded to get the sprites colours right, but the backgrounds colours are still off. I think that my attribute table code is the problem. So, I would like to know if someone can tell me if I am wrong or not and why.
So, this is how I do it (I changed a few things for readability, it is coded in C):
xTile and yTile are the coordinates of the tile, not in pixels, but in tile coordinates.
address is the address of the attribute table, I add 23C0 to it later.
xP = (xTile / 4);
yP = (yYile / 4) * 32;
address = yP + xP;
Then to isolate the group of 2 bits to use in the final palette index (33 - 22 - 11 - 00)
I do :
x = (xTile / 2) mod 2;
y = (yTile / 2) mod 2;
bits = y << 1 or x;
So, bits contains values : 0, 1, 2 or 3.
Then I take the byte from the attribute table with the address that I found in the upper code and I isolate the bits to place them in the right position.
So that I get xx00 where xx the bits variable that I got.
bits = ((attTable[address ] >> (bits * 2)) << 2)
This code is NOT optimized. It is somewhat hard to understand and maybe there is easier way to do this. I am open to suggestions.
Tell me me if it is too complicated or if I forgot something.
Thanks!
I restarted the development of my NES emulator that I started back in 1997. I thought that nothing would work but to my surprise, I did not had much tweaking to do to at least make the intro screens of a few games show. But now my next step is to make the attribute table works. I don't plan release this emulator, I am doing this for fun.
Right now, I can see the intro of Ice Hockey with a few animations with also a few glitches. I succeeded to get the sprites colours right, but the backgrounds colours are still off. I think that my attribute table code is the problem. So, I would like to know if someone can tell me if I am wrong or not and why.
So, this is how I do it (I changed a few things for readability, it is coded in C):
xTile and yTile are the coordinates of the tile, not in pixels, but in tile coordinates.
address is the address of the attribute table, I add 23C0 to it later.
xP = (xTile / 4);
yP = (yYile / 4) * 32;
address = yP + xP;
Then to isolate the group of 2 bits to use in the final palette index (33 - 22 - 11 - 00)
I do :
x = (xTile / 2) mod 2;
y = (yTile / 2) mod 2;
bits = y << 1 or x;
So, bits contains values : 0, 1, 2 or 3.
Then I take the byte from the attribute table with the address that I found in the upper code and I isolate the bits to place them in the right position.
So that I get xx00 where xx the bits variable that I got.
bits = ((attTable[address ] >> (bits * 2)) << 2)
This code is NOT optimized. It is somewhat hard to understand and maybe there is easier way to do this. I am open to suggestions.
Tell me me if it is too complicated or if I forgot something.
Thanks!