CGA Hydra

A while ago, Trixter challenged me to figure out if it was possible for a CGA card with both composite and RGB monitors attached to it to display a different image on each display. At first I thought this was impossible because the composite output is just a transformation of the RGB output - the RGB output contains all the information that the composite output contains.

But that reasoning only works if you're close up. If you stand back sufficiently far from the screens, adjacent pixels will blur into each other so this is no longer necessarily true. Suppose we have a pattern that repeats every 4 high-resolution pixels (or half an 80-column character, or 1/160th of the screen width, or one colour carrier cycle) and we stand sufficiently far back that this looks like a solid colour. On the RGB monitor this will just be an average of the 4 colours making up the pattern. So, for example, black-black-white-black and white-black-black-black will look the same on the RGB monitor, but they will look different on the composite monitor because these two patterns have different phases with respect to the color carrier, so they will have different hues.

That explains how we can get details on the composite monitor but not on the RGB monitor, but what about the other way around? This is a bit more complicated, because it requires knowing some more details about how the CGA generates (non-artifact) colour on the composite output. For each of the 8 basic colours (black, blue, green, cyan, red, magenta, yellow and white) there is a different waveform generated on the card. The waveform for the current beam colour is sent to the composite output. The waveforms for black and white are just constant high and low pulses, but the waveforms for the 6 saturated colours are all square waves of the colour carrier frequency at different phases. The green and magenta lines switch between high and low on pixel boundaries, the other 4 at half-pixel boundaries (determined by the colour adjust trimpot on the motherboard).

What this means is that if you're displaying a green and black or magenta and black image, the pixels are essentially ANDed with this square wave. The pixels corresponding to the low parts of these waves have no effect on the composite output. So you can use these pixels to make the image on the RGB monitor lighter or darker whilst having no effect on the composite image.

Here's what the finished result is supposed to look like (with another image on an MDA display as well):

Note that I've allowed the composite image to show through on the RGB monitor a little in order to improve contrast.

5 Responses to “CGA Hydra”

1. [...] - real power users would have had two monitors, one for CGA and one for MDA (and maybe even a composite monitor as well for games which preferred that mode). The 9-pin digital connectors for CGA and MDA were physically [...]

2. […] first attempt at this was the one I used for the Hydra image - I assumed that the direct colours had hue/phase angles that were multiples of exactly 45 degrees, […]

3. Mitch says:

Super, super cool. Really brilliant work/concept. I can't believe the ingenuity you guys displayed here.

Reading the '1K Colours on CGA' article now. Fascinating stuff!

Thanks for taking the time to think outside the box (no pun intended) and do something really different and interesting =)

--Mitch

4. Jani "robsku" Saksa says:

I don't think I can understand how exactly did you "calculate" the right image two draw, combining two images, from your text - nevertheless I'm in ave. I take it you wrote some kind of algorithm to combine two bitmaps into one that gets output to video memory, but haven't the faintest idea how.

• Andrew says:

As a first approximation, the algorithm is: for each small group of pixels, go through all possible values and pick the one that gives the best match to the target images. Using the particular CGA mode/palette that I did makes it possible for the different monitors to display different images.

At some point I will put the code I used to generate it online, so you can see exactly how it was done (this little project predates my github account or it would be there already). Before I do that, though, I want to rewrite it - the current version is based on a theoretical model of the CGA card which turns out to not be sufficiently accurate, so the pictures don't turn so nice on the real hardware. Now that I have the real hardware and a good model of it, I should be able to do a much better job.