Skip to content
Tech News
← Back to articles

VGA Memory Access Is Complicated

read original get VGA to HDMI Adapter → more articles
Why This Matters

The complexity of VGA memory access stems from its layered architecture and the lack of comprehensive documentation, making hardware implementation and emulation challenging. This intricacy impacts both developers working on VGA-related projects and consumers relying on legacy graphics systems, highlighting the importance of detailed technical resources for accurate emulation and hardware compatibility.

Key Takeaways

Last week I had another run-in with VGA emulation, and like last time, the cause was very likely the generally woefully inadequate VGA documentation.

The VGA is not, all things considered, a particularly complicated piece of hardware. It has no microcode, no CPU/microcontroller, and performs relatively simple functions. However, the VGA does consist of several logically separate components that work together, and this creates a perhaps underappreciated level of complexity.

By far the biggest difficulty in implementing VGA hardware or emulation is the lack of detailed and accurate documentation. The problem really started with the IBM EGA, because the VGA is only a slightly extended superset of the EGA.

The IBM EGA (Enhanced Graphics Adapter) was designed to support high-resolution (by 1984 standards) graphics in up to 16 colors, programmable fonts, but also with a high degree of compatibility with MDA/CGA text as well as CGA graphics modes.

However, the EGA is not register compatible with the earlier IBM adapters (and its internal architecture is quite different). Using code that directly sets up a CGA graphics mode (for example) will not work on an EGA. What does work is using the BIOS to establish the mode and then accessing video memory as if it were a CGA.

At the same time, the EGA is old enough that it was not a single integrated chip. It was built from four core chips: Graphics Controller, Sequencer, Attribute Controller, and CRT Controller. Each of these chips had its own set of registers.

The difficulty with EGA/VGA documentation is that the vast majority of it (starting with IBM’s own Technical References) is written for someone using a VGA, not implementing VGA functionality. And it is written with the assumption that the user is primarily interested in standard modes supported by the BIOS.

Most VGA references then say things like “for text modes, set bit X to 1 and bit Y to 0”. Which is useful enough if one wants to program text modes, but it does not at all explain what the bits actually do. Because the EGA consisted of several chips, it is common that bits in two or three chips have to be set certain way to achieve, say, CGA text mode compatibility or CGA graphics compatibility. Obviously each bit does something different, but users are “supposed” to set them all together. At the same time nothing actually stops programmers from flipping one or two bits out of a set of three, and then what happens? Some of the “undocumented” combinations turn out to be quite useful, such as the famous VGA Mode X.

The problem I tried to solve was related to the Odd/Even control registers in the VGA (or EGA, really) Sequencer and Graphics controller. Odd/Even access is used for text modes, and the name references the fact that the character codes are stored in even bytes and attributes in odd bytes, although really they’re stored in separate planes of the EGA/VGA four-plane memory organization.

IBM…

... continue reading