Tube Time Profile picture
Jan 5, 2021 64 tweets 14 min read Read on X
ever wonder why the IBM CGA card had such a terrible color palette in graphics mode? Image
(technically two color palettes, this was the other one) Image
you could switch between those two ugly palettes using bit 4 of register 3D9, the "color select register"
but to find out the *exact, technical reason* we need to dig into some schematics! let me get my boots...
first, text mode: the character byte comes in on the left and gets latched. the attribute byte also gets latched, because they alternate in video memory: character byte, attribute, character, attribute, character, and so on. Image
in text mode, the character byte gets fed through a look-up table in the character ROM (red) along with the current character *row* (the font is 14 lines tall). the output of that goes into a shift register (orange) because each character is 8 pixels wide. Image
the attribute byte contains the foreground and background color of the character, so if current pixel = 0, you get the background color, and =1 you get foreground.
in graphics mode, things work differently. the character byte and attribute byte get fed into two separate shift registers (green). the bits are swizzled so each shift register gets 4 bits of cc and 4 bits of att. in hi-res mode, the output toggles between each shift register. Image
the end effect is that in hi-res monochrome mode, two bytes in the framebuffer -> 16 adjacent pixels. simple.
but what about color?
the signals from those shift registers go into a mux (mainly for text vs. graphics mode) and through a latch and out to the display, but they are mapped to the red and green channels only! blue comes from somewhere else... where could that be? Image
it snakes across another schematic page... Image
and we wind up back on the same page again! it connects to bit 5 of a register. the color select register! this is the palette select bit. Image
so the "palette bit" doesn't really pick a palette, it controls the blue component of the video signal! so if red/green are not both 00 (black), then the color has blue added to it. or it has no blue at all!
so you wind up with the colors on the top without blue, and the colors on the bottom with blue added. those are the two options. Image
but wait! with some simple wiring changes, we could swap those RGB wires around and the CGA card could have had different palettes. if the palette bit controlled green instead of blue, we'd get this: Image
or if the palette bit controlled red, we'd get this. Image
actually these are all kind of terrible.
but what if there was another option?
some sort of...color lookup table?
IBM could have put in a 74LS170, which is a "register file" containing four 4-bit registers. this is enough for our palette, and each color can be one of the 16 possible colors (given the RGBI digital monitor output) Image
but we'd need a way to *write* to the palette register. since status register 3DA is read-only, we could borrow the select line and make it so that when you write to it, the lower 4 bits select the palette position and the upper 4 bits select the resulting color.
something like this. since the '170 has separate address lines for read vs. write i don't think you'd need any extra gates. just this one chip. Image
glancing at the schematic, i also realized that bit 4 of register 3D9 acts sort of like another palette select bit. this controls the intensity bit, I. so you either get a dark version or a light version of the two existing palettes, with one interesting exception...
so with the intensity bit turned off, the colors all darken, but yellow turns into brown instead of dark yellow. this is because the IBM CGA monitor has some circuitry that tweaks dark yellow and turns it into brown! Image
anyway, the palette mod looks really simple except i don't have a 74LS170 chip. i've got a few original CGA cards so next time i'm at the surplus store i'll see if they have one of those chips.
another device that could do it is the 74LS670. it's similar but instead of having open collector outputs it has tri-state outputs. funny, this part looks familiar... Image
and the reason it looks familiar is that Intel, in the late 1970s, was devoting a TON of resources to the iAPX432 project.
they had just finished up the 8080 CPU project and had embarked on the very ambitious 432. well, it was taking a very long time to develop, and the 8080 was only 8-bit, and they needed a 16-bit entry to compete in the market...
so a small team made some improvements to the 8080 and released the 8086, which was supposed to be a stopgap. they didn't really make specific peripheral chips for it, and they recommended that customers use the interrupt controller, DMA controller, and so on from the 8080 line.
this was a bit of a problem for the DMA controller since it only had 16 address lines whereas the 8086 (and the 8088) supported 20.
so what did IBM do? they used the 8080's DMA controller (8237) but they needed a way to store the extra 4 address bits for each DMA channel. for that, they used the 74LS670 register file chip! Image
this worked great. the only limitation is that the DMA controller doesn't know about this external circuit and can't increment it. so a DMA operation is limited to 64K pages (where the page is controlled by the register file chip).
unfortunately this causes issues for people doing things like writing drivers for sound cards:
DOS has no idea that pages exist, so when you allocate RAM, it just gives you the number of paragraphs you wanted (16 byte increments).
so people writing sound card drivers or games needed a way to allocate memory for playback buffers, and those buffers had to fit within a page and not span two pages.
apparently the most common way to do this was to allocate the block, then check the address. if it spanned two pages, then you try again. one driver i saw tried 16 times and if it still spanned two pages, it just exited to DOS with a cryptic "memory allocation" error!
well that was surely a @Foone-worthy tangent! 😜 getting back to video, some people have been talking about CGA composite mode so let's look at that briefly.
the IBM CGA card comes with an RCA jack on the back so you can plug it directly into your NTSC television, if it can handle composite video (or an RF modulator, if it can't). Image
here's the circuit that generates NTSC. in red is a buffer, basically a resistor DAC. in yellow is the composite sync generator. and orange is a mux. the mux uses the RGB inputs to select between 6 different signals... Image
the signals come from this chain of 3 cleverly-connected flip flops. the input signals are 14.318MHz and 3.549MHz (the NTSC colorburst and 4x that frequency) Image
each output is a 3.579MHz square wave with a different phase relationship.
at the beginning of every NTSC video line, there's a colorburst signal. that comes from the first flip flop output signal. all the colors are determined by comparing the phase of the 3.579MHz signal to this reference. Image
so to get yellow, we just output another square wave that's the *same* phase as the colorburst, and we get yellow. shift it by some angle, and you get a different color. ImageImage
if you want, you can look at the flip-flop circuit and figure out what phase shift gets created for each color. (fyi, the -14MHz signal is just the inverted version of that clock; the minus sign indicates logical inversion on IBM schematics)
naturally there are ways to abuse all this circuitry for the purposes of making dramatic demos, and the demoscene folks have done some amazing work there.
for example, you can turn the colorburst on and enter text mode, using both the attribute byte colors (16) plus certain specific characters that have a pattern to create something called artifact colors.
the idea with an artifact color is that pixels turning on and off really quickly start to look like a color to a TV that is decoding the signal
(i.e. the luma signal spills over into the chroma signal, in the frequency domain) Image
the folks who wrote "8088MPH" used this trick to create a low resolution 1024-color "mode" on the CGA card! Image
here's the demo if you've never seen it before. you should go watch it now if you haven't.
and here's the behind-the-scenes discussing some of the tricks involved. trixter.oldskool.org/2015/04/07/808…
quite surprisingly, it's also possible to display full motion video on an 8088 at 4.77MHz using a CGA card. in color. blows me away whenever i watch it.
look what I got! Image
look there's an extra spot on the board, I wonder if the chip will fit. Image
there! it no longer looks like the board has a missing tooth. Image
now for the hard part. I have to intercept some signals and I don't want to cut any traces Image
mods aren't too extensive Image
uhh these are not the normal CGA colors. 😂 Image
CGA can't do color cycling oh wait what
commander keen never looked this...odd Image
if you want to build this mod, this is the schematic. "isolate" means you have to disconnect those IC pins from the original circuit and connect them to the mod wiring instead. Image
so how does it end up working? to change a palette register, write a value to 0x3DD. bits 4-5 is the CGA color attribute to change, bit 0 is red, bit 1 is green, bit 2 is blue, and bit 3 is intensity.
sadly you can't change attribute 0, that's always black since that color is generated in hardware. but the other 3 are fair game.
OUT &H3DD, &H19
OUT &H3DD, &H2A
OUT &H3DD, &H3C
will give you a palette of bright red, bright green, and bright blue.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Tube Time

Tube Time Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @TubeTimeUS

Jun 13, 2023
here's a weird object! it's some kind of foot pedal with an IBM logo. is it for a sewing machine? electronic synthesizer? what do you think? 🧵 Image
it's got a cursed connector! what IS that? Image
amazingly enough, I found something with the mating connector on it! but what is it? Image
Read 24 tweets
Jan 11, 2023
hey so remember the world's cutest oscilloscope i picked up last year? i think it's time to fix the probe socket issue.
i printed a new panel insert that has two BNC sockets on it (the original probes would have had captive cables)
the tricky part is that this oscilloscope has a 333K ohm input impedance instead of 1M like umm every other scope on the planet. fortunately someone designed a little conversion circuit...
Read 11 tweets
Jan 5, 2023
in honor of Sim Wong Hoo, here's a quick historical review of the Sound Blaster! 🧵
but first we have to go back to their first sound card, the Creative Music System from 1987. (image credit: Bratgoul on Wikipedia)
this card has some special "CMS-301" chips. if you peel back the sticker, they have had their top marks removed. they're actually SAA1099 synthesizer chips made by Philips. Creative wrote music composition software for musicians on the PC.
Read 23 tweets
Dec 31, 2022
Tube Time: a 2022 retrospective 🧵
(and stuff you might have missed!) Image
starting things off in january, i found a tube of super old 555 timer chips! i also decapped one of them.
i also started fixing up an old HP 150 computer. it's not PC compatible but it runs MS-DOS--how odd!
Read 65 tweets
Dec 29, 2022
today's mini project: fixing this Radius Thunder IV GX daughtercard. it looks fine, but... 🧵 Image
one of the chips has some broken pins! Image
looks like two of the pins got mashed and broke right at the plastic package. Image
Read 11 tweets
Dec 8, 2022
on the bench of healing tonight: my coffee grinder which decided to bite the dust. Image
symptoms: i push the start button and the motor just bumps a little bit and stops.
how to take it apart? hmm, i bet there are screws under the rubber feet. Image
Read 23 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(