Is there any math to the quick phase changes and the resulting composite artifact color or is it all done my experiment?
Have all values already been calculated by someone? (Is there a table of 512/1024 entries that have as an address (a combination of the character byte and the foreground and background colors) and an output which is the resulting artifact color?)
I'm curious how to populate 512-1024 values in a translation table...
What is the "window" of consecutive pixels that should be grouped to decide on an artifact color - which bits to feed to the table?
My old 1024 colors article (see post #48) goes into the very rudimentary basics of how artifact colors are generated in 'standard' modes, before it goes into the tweaked text mode/more-color hacks.
Some important things to remember: there are 160 NTSC color cycles within an active 320- or 640-pixel CGA scanline, and a composite waveform at the NTSC color frequency will generate a "solid" artifact color. So any repeating pattern of four hi-res pixels (or two low-res pixels) will do that. That's half a character width in 80-column text mode, or one quarter of a character in 40 columns.
However, artifact color emulation can't be done right by just rendering blocks of solid colors from a lookup table. A few early attempts did something along those lines (see e.g. very old Applewin or DOSBox circa 20 years ago), and it looks completely off. The reason lies in how NTSC is encoded and decoded: there's no perfect separation between luma and chroma (brightness and hue if you prefer), and the latter varies smoothly across the color cycle. Basically
every transition between colors will be somewhat artifacted - among other things, that's why you get color "fringing" on text, even when it's white on a black background and contains no neat repeating patterns.
In other words, the trick of lining up characters, dot patterns, etc. may be useful for the graphic artist (for solid blocks of color), but not as a basis for simulating the actual rendering... it's just one specific 'high-level' phenomenon resulting from what's really going on at the signal level. After all, the NTSC
decoder doesn't (and can't) know anything about repeated pixel patterns, let alone character bitmaps. For a passable emulation, you'd really have to forget about these 'logical' units and consider the physical signal.
So what's the optimal way to go about it? The best approach I've seen is
@reenigne's: it *is* based on a table, which IIRC has 1024 entries - each representing one possible color transition (between the 16 'direct' CGA colors) at one of the 4 possible phases within the color carrier cycle (640/160), or 16*16*4 values. The actual values themselves were sampled from the CGA multiplexer's output, so they basically allow you to reconstruct the raw composite signal, and decode that (using a filter) much like a true NTSC device.
There should be a few versions of this code around, e.g. in MartyPC, variants of 86box and DOSBox (I could try to find the specific ones if needed), and reenigne's own
CGAArt. I'm guessing this approach should be somewhat adaptable to FPGA hardware - at least I hope so!
I see from the
@VileR 512 colors example that a characters like 0xB1 repeats a 01010101 pattern of a certain color with a black background will result in a block of a certain artifact color.
Was this resulting artifact color block the smallest block achievable? What if the pattern was 0101_1010. Would there be two artifact colors? What if it was 01_10_01_10? Would this be four artifact color changes?
Im curious what the limit is - what is the smallest phase shift that produces an artifact color.
As mentioned above, you get *some* color artifacting at pretty much every transition. But for a solid 'block' of color, it's anything that matches the frequency of the NTSC color carrier - 160 cycles per line (four hi-res/80-column pixels). The patterns in my 512/1024 examples are twice as long, but that's only because they use text mode, so the limitation is the width of the character cell.
With the above mentioned low-level approach, you could get a faithful reproduction no matter the video mode - the 512/1024 color trick would simply 'fall out' of that.
I guess this is just academic as there are only a limited number of text values in the character ROM which have alternating 1's and 0's.
Yes, but if you choose to go one better and allow arbitrary/'soft' character sets, then nobody's stopping us from picking more "suitable" character bitmaps.
