14

In DOS, the memory mapped IO base address for the CGA video buffer is 0xB8000. So when you write to 0xB8000, you are actually writing to a buffer in the CGA card itself and not to RAM.

What I want to know is who decides what is the memory address that the CGA video buffer will be mapped to, does this information exists in the CGA card itself, and when DOS (or BIOS I don't know) scans to see what PCI devices exists on the PCI bus, it reads this information from the CGA card? Or is it only a convention to map the CGA video buffer to address 0xB8000?

16

CGA pre-dates dynamic allocation of addresses in the PC world, by quite a few years. The video buffer appears at the area starting at 0xB8000 because the adapter responds to reads and writes at those addresses. Basically, when the CPU wants to read or write a value from or to a certain address, it places that address on its address bus (and asserts a given state using other pins); then any device which is also on the bus (memory, ROM, and cards on the ISA bus) can fulfill the request.

So the answer to your question is, it’s the CGA which decides that its video buffer appears at 0xB8000.

  • 2
    In the original IBM PC the BIOS figured out (prior to booting any OS) what video adapter (initially MDA or CGA) was installed, I suspect by checking memory locations and/or I/O ports for responses to indicate "card present". There were very few choices and, as part of the "IBM PC standard", one could argue that IBM made the decision as few people used a 3rd-party adapter that used different memory addresses, at least for basic compatible video modes. Even years later, plenty of software would simply check for the installed adapter type and make an assumption about the memory location. – manassehkatz Jun 7 '17 at 16:02
  • 1
    @Stephen Kitt 1) So a device that is plugged into an ISA bus can't give away its address to a program, and the program must already know what the address of the device is (so this means that the address of the device must be fixed), correct?. 2) I think that a device plugged into a PCI bus can give away its address to a program, and its address can be changed each time the computer is turned on, is this true? – user5161 Jun 7 '17 at 16:18
  • 2
    A device on the ISA bus has a fixed address, yes, or one of a few (hardware-selectable using jumpers typically, later software-selectable using plug-and-play). Software usually has to be told where to find a configurable adapter (see e.g. the BLASTER environment variable); for ROMs there’s an explicit protocol which allows them to be found during boot. PCI is software-configurable; the allocation algorithms are deterministic though so the addresses typically won’t vary from one boot to the next, unless hardware is added or removed. – Stephen Kitt Jun 7 '17 at 16:22
  • 1
    @StephenKitt - In theory a video card could be memory mapped anywhere (or at least anywhere > 640k). In practice,if you manufactured a CGA or MDA compatible card but used a different default base memory address, plenty of software (admittedly poorly designed) would break. The IBM defaults became "standard" pretty quickly as even business applications quickly moved to direct video memory access for performance reasons. – manassehkatz Jun 7 '17 at 16:31
  • 2
    @manassehkatz "In the original IBM PC the BIOS figured out" is not correct. On the original IBM PC, the installed video adapter was indicated with jumper settings on the main board. The BIOS didn't start figuring it out or probing until several generations later. I agree you are otherwise correct about the address of the video adapter boards being defined by the IBM technical specifications. They designed the video boards, too, so the argument between you and Stephen seems like splitting hairs. – Cody Gray Jun 7 '17 at 16:44
4

CGA cards provide their own RAM to the address space. This memory lies in the hole between 640KB and 1MB. By convention, it was stated that the video memory (for CGA cards) would begin at segment B000 if the CGA card is being connected to a B/W monitor, and B800 if connected to a colour monitor. This way, two CGA cards would coexist in the same system, providing a means of multimonitor environment (text only for the monochrome monitor and graphics for the colour monitor in a typical CAD environment).

So it seems that the base memory location can be changed somehow. Actually, it is more flexible than that. In text video modes, scrolling text is a fast operation not because the CPU shifts blocks of memory to make room for new lines, but because the CPU changes the starting address of the video memory so that the user sees a new page of video memory. There were 4 pages of video memory for text on a basic 16KB CGA card using 80 columns mode, and 8 pages if using 40 columns mode. This was possible because the CGA (and subsequent compatible graphics cards) used the well known CRTC controller Motorola 6845, which provides registers to specify where in memory the video data should begin.

  • Are you sure that CGA configures itself for monochrome in this way? MDA appears at B0000, but I don’t think CGA can. You could have two display outputs by combining an MDA or Hercules card with CGA, EGA, VGA or greater, or in some cases with jumpered EGA or VGA cards which could be set up as MDA. – Stephen Kitt Jun 14 '17 at 8:16
  • 1
    The CGA card is always at 0xB8000 regardless of whether it is connected to a composite monochrome or RGB color monitor. – supercat Jun 14 '17 at 14:16
  • Scrolling an entire screen of text could be a fast operation [a standard XT with CGA could scroll two lines/frame without snow using the proper software] but generally wasn't. The reason CGA text scrolling isn't as slow as normal text output is that the BIOS blanks the screen and then moves display memory without having to wait for vertical or horizontal blanking intervals. It's too bad that the CGA made the main CPU conflict with attribute fetches rather than character fetches; had it done the latter, scrolling of screen with a non-black background could have been much cleaner. – supercat Mar 27 '18 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.