I don't know about YUV... but:
mattmatteh wrote:
i think i know how i want to code it but stuck on how to efficiently handle emphasis and monochrome.
I keep a 512 entry lookup table that has the output colors in RGB format. The first 64 represent the NES palette with no emphasis, which would be filled by the loading of whatever .pal file. The remaining 7 sets of 64 each represent a different color emphasis mode and are calculated once based on the first 64 colors.
Monochrome can be handled very easily by applying a mask to the color prior to the lookup in the above table. A mask of $3F would be full color, and $30 would be monochrome mode. And in fact... I believe this is actually more or less how monochrome works on the system.
My output looks something like:
Code:
output_pixel = rgb_output_lut[ emphasis_bits | ( nes_color & monochrome_mask ) ];
where 'nes_color' is the desired color ($0F = black, etc), and 'monochrome_mask' is either $3F or $30.
emphasis_bits would be the bits as written to $2001, left shift 1 (0x01C0)
EDIT
------------
An optimization I just thought of....
To avoid the additional AND operation for each pixel... you could keep two seperate buffers for the palette at $3F00. One which has the colors as written (full color mode), and one which has the same entries but pre-masked with $30 (for monochrome mode). When the game switches between color/monochrome modes, you can simply adjust a pointer which points to which buffer the PPU is to use.
This of course would require you to maintain two buffers and keep them updated as the game writes to $3F00, but palette writes occur far less often than pixels are output.
To avoid the emphasis OR, you could just use a pointer to the lut instead of looking up the LUT directly. Update the pointer when the game changes emphasis.