Aeon Emulator Blog

October 23, 2009

Emulating VGA

Filed under: Aeon, Graphics — Greg Divis @ 2:13 pm

On a normal x86 real-mode PC with a VGA-compatible video card, a 64k region of memory starting at segment 0xA000 is mapped to video RAM. For a DOS application, displaying an image on the screen may or may not be as simple as writing the pixel data to this area. DOS is pretty minimalist, and has no concept of a display driver, so any nontrivial graphical DOS program has to talk to the hardware directly. Ok, what is the hardware besides a region of reserved memory address space? These are the basic components of a VGA device:

  • CRT controller: generates display data and timing signals for the monitor.
  • Attribute controller: performs color palette mapping to maintain compatibility with CGA/EGA.
  • DAC: maps pixel data to RGB values stored in its 256-color palette.
  • Sequencer: generates input data for the DAC based on video RAM.
  • Graphics controller: controls the flow of data between the CPU and video RAM.

So basically, when you write a byte to video memory, the graphics controller decides where (or if!) your byte actually gets stored. Everything else comes into play when it’s time to actually show the data on the monitor. These components can be programmed by sending data to various CPU data ports, but why would you need to?

The DAC is probably the most straightforward component – VGA display modes usually have either 4 or 8 bits per pixel. Each pixel then represents an index into the DAC’s color palette, meaning a 4-bit mode allows no more than 16 colors on the screen at once, and an 8-bit mode allows 256. By programming new RGB data to the DAC, a program can change the current palette. Pretty useful, as otherwise everything would be locked to the same set of 256 colors.

The CRT controller is also pretty straightforward. At the time a CRT monitor was pretty much taken for granted, so this component could be programmed to alter the video output in some clever ways to achieve otherwise computationally expensive effects. It also allows some very low-level manipulation of the monitor’s electron gun behavior and timing.

The attribute controller is mainly there for compatibility and Aeon doesn’t emulate many of its functions at the moment.

There’s a reason I’ve left the graphics controller and sequencer for last; they are responsible for more headaches than the rest of the VGA emulation combined. I still don’t have them quite right, and trying to implement them completely turned my nice design into a tangled mess. I’ll talk about them at great length in another post.

Advertisements

1 Comment »

  1. […] Video Memory Filed under: Aeon, Graphics — Greg @ 3:19 pm In a previous post, I gave a brief overview of the components of a VGA card, but I didn’t talk about the two […]

    Pingback by Planar Video Memory « Aeon Emulator Blog — October 30, 2009 @ 3:19 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: