What I (think I) understand about the basic CHR format, not counting setting colors, for the standard 2BPP NES format, from hex viewing:
Each byte acts like a vertical bitflag, e.g. 0 = nothing there, 1 = pixel on 1st row, 2 = pixel on 2nd row, 3 = pixel on 1st and 2nd row etc...
And it is repeated for each color every 8(???) bytes. Something like that. But I'm NOT interested in color right now, I just want the shape to be right!
I am attempting to load CHR with this code:
Using the default rotation: 270.
Works great. For the first row.
Otherwise I just get garbage that is very vaguely reminiscent of a messed up version of the tile.
Can someone clear up a few things on the CHR format? How should I really be loading this? And yes, I know my code is probably horribly written...
I really hope this is the right place to post it. CHR info is kind of scarce.
Each byte acts like a vertical bitflag, e.g. 0 = nothing there, 1 = pixel on 1st row, 2 = pixel on 2nd row, 3 = pixel on 1st and 2nd row etc...
And it is repeated for each color every 8(???) bytes. Something like that. But I'm NOT interested in color right now, I just want the shape to be right!
I am attempting to load CHR with this code:
Using the default rotation: 270.
Code:
unsigned char _bit[9];
_bit[0] = 0x00;
_bit[1] = 0x01;
_bit[2] = 0x02;
_bit[3] = 0x04;
_bit[4] = 0x08;
_bit[5] = 0x10;
_bit[6] = 0x20;
_bit[7] = 0x40;
_bit[8] = 0x80;
int _i = 0;
// ...
while (chr.read(&_b, 1)) {
if (_i <= imgw) {
std::cout << "#" << _i << ";\n";
bool bPixel = false;
for (int _ii=1; _ii<8; ++_ii) {
bool bPixel = (_bit[_ii] &_b != 0);
if (bPixel) {
tile[_ii-1][_i][_b] = 255; // TESTING PURPOSES NO COLOR YET
}
}
std::cout << "\n";
_i = _i + 1;
}
}
_bit[0] = 0x00;
_bit[1] = 0x01;
_bit[2] = 0x02;
_bit[3] = 0x04;
_bit[4] = 0x08;
_bit[5] = 0x10;
_bit[6] = 0x20;
_bit[7] = 0x40;
_bit[8] = 0x80;
int _i = 0;
// ...
while (chr.read(&_b, 1)) {
if (_i <= imgw) {
std::cout << "#" << _i << ";\n";
bool bPixel = false;
for (int _ii=1; _ii<8; ++_ii) {
bool bPixel = (_bit[_ii] &_b != 0);
if (bPixel) {
tile[_ii-1][_i][_b] = 255; // TESTING PURPOSES NO COLOR YET
}
}
std::cout << "\n";
_i = _i + 1;
}
}
Works great. For the first row.
Otherwise I just get garbage that is very vaguely reminiscent of a messed up version of the tile.
Can someone clear up a few things on the CHR format? How should I really be loading this? And yes, I know my code is probably horribly written...
I really hope this is the right place to post it. CHR info is kind of scarce.