Hello,
I have some programmatically created 2-bit pixel data that is laid out "in order", four pixels to a byte. For the four colors supported (0-3, or %00 - %11) i have them organized one after another. For example, if I had 8 pixels of color 0, 1, 2, 3 repeating in order I would have a 2 bytes as follows: % 00 01 10 11, % 00 01 10 11
Now I want to push this into CHR RAM in the PPU pattern table format. The Pattern table, however, is not laid out in order. It is laid out in "planes" of 8 bytes, such that the high bit of each pixel is supposed to be set in a byte 8 bytes later as described here: http://wiki.nesdev.com/w/index.php/PPU_pattern_tables
Perhaps this is a clearer example. Given two input bytes as follows:
% 01010101, % 01010101
I need the output to be
%11111111, %00000000 (the order isn't that important as I can easily switch them, but if I understand the pattern table correctly, the low pixel bits go in the first byte and the high pixel bits go 8 bytes later, so in this case the 0's go 8 bytes later.)
I have been working through various schemes to cut up the bits and put them in the right place. The idea is to take the odd bits of the two input bytes and put them into one output byte and put the even bits into the other output byte. I have (barely) managed to get this to work by looping through 16 times for the two input bytes, bit shifting and setting bits on alternating output bytes. I then write these output bytes to a buffer with 8 bytes of spacing as required.
But my question is if there is any more efficient way to transform the input bytes to the output bytes. Is there some direct way, without looping (whether unrolled or not) through every bit? What I want is some way to take all the even bits of two input bytes and make one output byte, then take all the odd bits of the two input bytes and make a second output byte.
I've been going through all sorts of ideas but can't seem to find a shortcut. Any ideas?
Thanks,
Splitpane
I have some programmatically created 2-bit pixel data that is laid out "in order", four pixels to a byte. For the four colors supported (0-3, or %00 - %11) i have them organized one after another. For example, if I had 8 pixels of color 0, 1, 2, 3 repeating in order I would have a 2 bytes as follows: % 00 01 10 11, % 00 01 10 11
Now I want to push this into CHR RAM in the PPU pattern table format. The Pattern table, however, is not laid out in order. It is laid out in "planes" of 8 bytes, such that the high bit of each pixel is supposed to be set in a byte 8 bytes later as described here: http://wiki.nesdev.com/w/index.php/PPU_pattern_tables
Perhaps this is a clearer example. Given two input bytes as follows:
% 01010101, % 01010101
I need the output to be
%11111111, %00000000 (the order isn't that important as I can easily switch them, but if I understand the pattern table correctly, the low pixel bits go in the first byte and the high pixel bits go 8 bytes later, so in this case the 0's go 8 bytes later.)
I have been working through various schemes to cut up the bits and put them in the right place. The idea is to take the odd bits of the two input bytes and put them into one output byte and put the even bits into the other output byte. I have (barely) managed to get this to work by looping through 16 times for the two input bytes, bit shifting and setting bits on alternating output bytes. I then write these output bytes to a buffer with 8 bytes of spacing as required.
But my question is if there is any more efficient way to transform the input bytes to the output bytes. Is there some direct way, without looping (whether unrolled or not) through every bit? What I want is some way to take all the even bits of two input bytes and make one output byte, then take all the odd bits of the two input bytes and make a second output byte.
I've been going through all sorts of ideas but can't seem to find a shortcut. Any ideas?
Thanks,
Splitpane