• Please review our updated Terms and Rules here

Question about programming the 6845 video IC

Ruud

Veteran Member
Joined
Nov 30, 2009
Messages
1,408
Location
Heerlen, NL
A friend of mine mentioned that MDA mode worked on his monitor but graphical mode didn't. I always thought that the only difference between MDA and graphical mode was that in MDA mode the pixels were generated by ROM in graphical mode by RAM. Same for CGA text an graphical mode. But having a look at a BIOS for a XT, I noticed there were differences in the values that have to be written to the 6845 registers for the various modes. I'm not familiar with the 6845 so I have no idea why these differences.

Could anybody be so kind to explain to me why these differences are needed, please? Thank you in advance!
 
IBM MDA output is 350 lines at 18.4 KHz. CGA is 200 lines at 15.7 KHz. Most early monitors cannot sync to both (although a few can).

This is what made the Hercules card an attractive upgrade. Since the output was also 18.4 KHz, users could display graphics on their existing monochrome monitor.
 
IBM MDA output is 350 lines at 18.4 KHz. CGA is 200 lines at 15.7 KHz. Most early monitors cannot sync to both (although a few can).
OK, maybe I was not clear enough: why the differences in parameters for CGA text and graphics? NOT about the differences between MDA end CGA, that is clear enough.

This is what made the Hercules card an attractive upgrade. Since the output was also 18.4 KHz, users could display graphics on their existing monochrome monitor.
In the case of my friend it didn't work out that way. I remember having seen parameters for a Hercules-clone card for the graphical mode that differed as well from the text mode. But that was at least 25 years ago because end '90s I switched to VGA for all my PCs. To test PCs I sometimes use MDA but only in text mode. It is pure curiosity that I asked about these differences
 
OK, maybe I was not clear enough: why the differences in parameters for CGA text and graphics? NOT about the differences between MDA end CGA, that is clear enough.
Referring to CGA text mode as "MDA mode" is about as clear as mud. Anyway, I don't understand why you think the 6845 would not have to be reprogrammed to change modes. How else would you do it?
I recommend checking out the IBM CGA manual if you haven't already.

CGA monitors are fixed frequency. If text modes are working but graphics modes are not, there is a problem with the CGA card or the BIOS.


In the case of my friend it didn't work out that way. I remember having seen parameters for a Hercules-clone card for the graphical mode that differed as well from the text mode. But that was at least 25 years ago because end '90s I switched to VGA for all my PCs. To test PCs I sometimes use MDA but only in text mode. It is pure curiosity that I asked about these differences
I'm not sure what you are saying here. Yes, Hercules has text and graphics modes. Both work on an MDA monitor. The signal looks the same on the monitor side.
 
Last edited:
To further muddy the waters, there are different versions of the 6845 made by various vendors. Not all are interchangeable. That one stung me years ago as documented here
 
I noticed there were differences in the values that have to be written to the 6845 registers for the various modes. I'm not familiar with the 6845 so I have no idea why these differences.

Could anybody be so kind to explain to me why these differences are needed, please? Thank you in advance!
My guess would be that in text mode you have to read the same 80 byte row of frame buffer memory 14 times over for the 14 scan lines of a character row, whereas in text mode you need to read a different 90-byte (720 pixels across) row of memory for each of those 14 lines. (And of course, there's the 80- vs. 90-byte difference in row length.)

The same would apply to CGA text vs. graphics modes except that, being only 640 pixels across, the rows are the same length. But you still need to increment your memory read address with every scan line, rather than only after you've generated all the scan lines for a row of characters.
 
I'm going to ignore the MDA part of this, because MDA/Hercules is potentially a huge rabbit hole. Long and short of it is Hercules was *never* a "BIOS supported" video standard; the PC BIOS supports *MDA* in text-only mode, there's zero BIOS support for the graphics extensions. Complicating matters further is apparently there were sometimes significant implementation differences in clone Hercules cards, so honestly I'm not comfortable going 100% on the record saying that it's impossible that this person you knew had some bad brand-X semi-compatible Hercules card that was MDA compatible enough to work fine for text but had problems in graphics mode.

I always thought that the only difference between MDA and graphical mode was that in MDA mode the pixels were generated by ROM in graphical mode by RAM. Same for CGA text an graphical mode. But having a look at a BIOS for a XT, I noticed there were differences in the values that have to be written to the 6845 registers for the various modes. I'm not familiar with the 6845 so I have no idea why these differences.

Aaaanyway. On the CGA side of the fence, the main reason you need to reprogram the 6845 when you go from text to graphics mode is because the 6845's main job other than generating video mode sync and timing signals is acting as a video ram address generator, IE, it's the thing that dictates what location in RAM memory is accessed to get the block of pixels that's next in line to get shoved out through the pixel generation hardware as the refresh scan progresses through the screen. The memory layout is different between the graphics and text modes, so the CRTC has to be reprogrammed to generate the correct progression of memory addresses.

I don't have time to lay it out in complete detail, but the short version is:

A: In (80 column) text mode the CRTC is programmed to count from 0 to 1999 in 80 character blocks of addresses, each of which is repeated 8 times (for the 8 scan lines of each character), and these addresses are fed into pixel generation hardware which fetches 2 consecutive bytes for each character (the glyph code and an attribute) which then dictate the state and color palette used for the next 8 pixels to be shifted out to the monitor.

B: In graphics mode the CRTC is programmed to count from 0 to 3999, in 40 byte blocks. (Why 40 when a 640 pixel B/W screen is 80 bytes wide? Like in text mode the hardware fetches 2 successive bytes for each address.) Each one of these blocks of addresses is repeated *twice*, and for every other line the hardware adds an 8192 byte offset to the address; this is why CGA graphics modes have a 2:1 logical interlace; there aren't enough address lines wired between the CRTC and the video RAM memory for it to create a completely linear framebuffer so one of the character row lines is used as the highest bit.

It would in theory at least have been possible for IBM to design the system so the graphics and text modes would use the same CRTC settings; the CRTC settings other than character height and total number of characters per screen are already the same between 40 column text mode and graphics; if IBM had opted to make people deal with 8-way interlacing instead of 2-way you'd be able to flip between the 40 column text mode and the two true graphics modes just by flipping the (not part of the CRTC) hardware bit that selects the appropriate pixel output hardware. But that's not what they opted to do.
 
Last edited:
A friend of mine mentioned that MDA mode worked on his monitor but graphical mode didn't. I always thought that the only difference between MDA and graphical mode was that in MDA mode the pixels were generated by ROM in graphical mode by RAM. Same for CGA text an graphical mode. But having a look at a BIOS for a XT, I noticed there were differences in the values that have to be written to the 6845 registers for the various modes. I'm not familiar with the 6845 so I have no idea why these differences.

Could anybody be so kind to explain to me why these differences are needed, please? Thank you in advance!
I am re-reading this for a third time and I think I finally understand. Your friend had a Hercules (clone?) card, but only text mode worked. The BIOS part was throwing me off, since that's not applicable to Hercules graphics.

As I said before though, Hercules graphics mode should work with any MDA monitor. So the issue lies either with the card itself, or the programming.
 
IBM MDA output is 350 lines at 18.4 KHz. CGA is 200 lines at 15.7 KHz. Most early monitors cannot sync to both (although a few can).

This is what made the Hercules card an attractive upgrade. Since the output was also 18.4 KHz, users could display graphics on their existing monochrome monitor.
Even with modern monitors, syncing to both NTSC RGB (either analog or TTL) and VGA is rather uncommon. (syncing to NTSC component is much more common, but it didn't exist until the '90s) This is because the frequency gap is so wide between 15K and 31K that it's hard to make a CRT that can do both. But LCDs have no such excuse.

I'm really not familiar with MDA scan rates, but back in the day most CRTs were fixed-frequency.

The 6845 is a very flexible chip, especially when it comes to scan rates. It will happily generate sync that your monitor can't deal with. I remember there was some concern when people realized that you could burn out a monitor with software that changes the 6845 timing.
 
I recall my Sony monitor--every time the scan rates changed, you'd hear relays clicking.

One burnout monitor casualty was the MDA/MGA 5151 that lacks a horizontal deflection oscillator. Basically, it will use whatever frequency for horizontal scan that is fed it. Fatality usually involved the flyback transformer.
 
Even with modern monitors, syncing to both NTSC RGB (either analog or TTL) and VGA is rather uncommon. (syncing to NTSC component is much more common, but it didn't exist until the '90s) This is because the frequency gap is so wide between 15K and 31K that it's hard to make a CRT that can do both. But LCDs have no such excuse.

I'm really not familiar with MDA scan rates, but back in the day most CRTs were fixed-frequency.
By "early" I meant early 80s. In the mid to late 80s, there were monochrome monitors that could sync to both MDA and CGA, and also multisync color monitors from Sony, NEC, and Mitsubishi. But I agree that fixed frequency was always the most common.
 
Referring to CGA text mode as "MDA mode" is about as clear as mud
MDA = Monochrome Display Adapter, CGA = Color Graphics Adapter. Two complete different cards and monitors, knowing that for already 39 years.
 
My guess would be that in text mode you have to read the same 80 byte row of frame buffer memory 14 times over for the 14 scan lines of a character row, whereas in text mode you need to read a different 90-byte (720 pixels across) row of memory for each of those 14 lines. (And of course, there's the 80- vs. 90-byte difference in row length.)

The same would apply to CGA text vs. graphics modes except that, being only 640 pixels across, the rows are the same length. But you still need to increment your memory read address with every scan line, rather than only after you've generated all the scan lines for a row of characters.
Aha, THAT makes sense! Now I have a solid base to figure out the rest. Thank you very much!
 
MDA = Monochrome Display Adapter, CGA = Color Graphics Adapter. Two complete different cards and monitors, knowing that for already 39 years.
I am aware. As I said before, I misinterpreted your post because you refer to Hercules as just "graphical mode" and discuss BIOS source which is only applicable to CGA graphics.
 
I am aware. As I said before, ....
I only just saw that post, must have missed that for one or another reason. My apologies.

In the mean time I found some 6502 sources that either displayed 24 or 25 lines on the screen. And I found a datasheet of the 6845 giving the parameters for PAL and NTSC. So I'm learning every day.
 
The *really* important thing you need to understand about the 6845 is what it *doesn’t* do. The chip generates sync/timing signals, spits out video RAM and character row addresses (there’s technically two separate sets of output address lines on it), and provides a couple other more obscure functions (hardware cursor register, light pen trigger)… but it does *not* itself handle *anything* related to the actual character/pixel generation. The details of what actually happens between a memory address being taken off the 6845’s outputs and a pixel coming out of the back of your computer on the way to the monitor can be *wildly* different between computers.

See in my post, for instance, about how in graphics mode CGA only counts half as many addresses as you’d expect horizontally because the video hardware grabs bytes two at a time. The same thing is true on 80 column Commodore PETs in text mode… but it’s *not* true on 40 column PETs. (And graphics modes are themselves a huge rabbit hole; the 6845 was primarily designed for character displays, so large framebuffers usually require having to use the character row outputs as additional RAM address lines. Which is why you run into the topic of memory interlacing… which every company using the 6845 pretty much handled differently.) To program the CRTC correctly you need to *genuinely* understand a slew of details about your machine’s actual hardware implementation.
 
Last edited:
  • Like
Reactions: cjs
Back
Top