You are on page 1of 29

15 VDU Basics

Components of VDU
Monitors (Display Screens)
Refresh Rate
Resolution
Multisync Monitor
FST Monitor
Interlaced and Non-Interlaced Monitors
Energy Saving Monitors
Active Matrix LCD Display
Graphics Circuitry
Graphics Card Standards
Modern Graphics Cards
Graphics Processor
Video Memory
Digital to Analog Converter (DAC)
Display Connector
Computer (Bus) Connector
Graphics BIOS
Video Display Modes
Text or Graphics
Colors in Text Mode
Colors in Graphics Mode
Colors in VGA
Colors in SVGA
Video Pages
The DOS Perspective
Writing to Video Memory in Text Mode
Exercise

495
240 Let Us C

F or most computer users, the two most important


components of the computer system are the Video Display
Unit (VDU) and the keyboard. It has been observed that the
decision of customers, who purchase software, is more often than
not strongly influenced by how the screens have been designed in
the software. Jazzier the screen, more appeal it carries for the
users. Your monitor provides the link between you and your
computer. Although you can get rid of your printer, disk drives,
etc. you cannot sacrifice the monitor. Without it, you would be
operating blind!

Components of VDU
The video system consists of two basic components:
(a) A monitor on which we actually see the images either in text
or in graphics.
(b) Video or graphics circuitry usually fitted on a card but
sometimes found on the motherboard itself.

Let us discuss each of these now.

Monitors (Display Screens)


In early days of PC not every monitor could support text,
graphics and colors. But that is history now. Today almost all
monitors support text and graphics capabilities and produce
colors. Today what is of more significance regarding the
monitor is its refresh rate and resolution. Let us now examine
them.

Refresh Rate
How are the images, either text or graphics, produced on the
screen? The microprocessor does not have the ability to send
Chapter 15: VDU Basics 241
signals necessary to produce the images on the screen. This task is
performed by graphics card circuitry.

Either the microprocessor or the graphics processor present in the


graphics card writes the information to be displayed on the screen
into the video memory. Once written, the graphics card circuitry
reads the digital information from video memory, converts it to
analog signals and transmits them to the electronic gun inside the
monitor. The screen is coated with a material called Phosphor
Bronze. When the electron beam strikes the Phosphor-Bronze
particles they glow. The phosphor particles have a property that
unless the electron beam again strikes them they would vanish. To
prevent this the graphics card circuitry repeatedly (80 to 100 times
a second) reads information from video memory and transfers it to
the screen, making the images displayed on the screen clear and
steady. This process is called ‘refreshing the screen’, and the rate
at which it is refreshed is called ‘refresh rate’. Low refresh rates
cause the screen to flicker contributing to eye-strain. The higher
the refresh rate better it is for your eyes.

Resolution
Text or graphics on the screen are built up from tiny dots called
picture elements or ‘pixels’. The display resolution is defined by
the number of rows (called scan lines) from top to bottom, and
number of pixels from left to right on each scan line. In general,
higher the resolution, more pleasing is the display. Higher
resolution means a sharper, clearer picture, with less pronounced
‘staircase’ effect on lines drawn diagonally and better looking text
characters. On the other hand, higher resolution also means more
memory requirement for the display.

Frequently, one comes across confusing and conflicting


terminologies related with the monitor. This involves interlaced
and non-interlaced monitors, multisync monitors, energy saving
242 Let Us C
monitors, active matrix LCD display, etc. Let us now try to de-
mystify this jargon.

Multisync Monitor
Some monitors have a fixed refresh rate, whereas, others may
support a range of frequencies. This multiple frequency support
provides built-in compatibility with future video standards. A
monitor that supports many video standards is called a multiple-
frequency monitor. Different vendors call multiple-frequency
monitor by different names, including multisync, multifrequency,
multiscan and asynchronous monitors.

FST Monitor
The traditional screen is curved, meaning that it bulges outwards
from the middle of the screen. This design is consistent with the
vast majority of cathode ray tube designs, including your
television set. FST stands for flat square tube. The flat screen
results in reduced glare and a higher quality, more accurate image.
The disadvantage is that the technology required to produce flat-
screen displays is more expensive, resulting in higher prices for
the monitors.

Interlaced and Non-Interlaced Monitors


In non-interlaced (conventional) monitors the electron beam
sweeps the screen in lines from top to bottom one line after the
other, completing the screen in one pass. In interlaced monitors
too, the electron beam sweeps the screen from top to bottom, but it
does so in two passes, sweeping the odd lines first and the even
lines second. Non-interlaced monitors offer better and stable
Chapter 15: VDU Basics 243
displays when compared with interlaced ones, even though they
are costlier. Most monitors today are non-interlaced.

Energy Saving Monitors


Monitor is one of the most power-hungry computer components.
Hence, putting off the monitor if it is idle for a specific period of
time can save energy. Many PC manufacturers are trying to meet
Environmental Protection Agency’s (EPA’s) Energy Store
Requirements. Any PC-monitor that consumes less than 70 watts
can use the Energy Star logo. There are different energy saving
standards available for monitors, By far the most popular amongst
these is Video Electronic Standards Associations’ Display Power
Management Signal (VESA-DPMS) specifications.

Active Matrix LCD Display


Instead of using the CRT technology, the laptop computers make
use of Liquid Crystal Diode (LCD) displays. These displays have
low glare flat screens and low power requirements (5 watts versus
nearly 60 watts for an ordinary monitor). There are 3 LCD choices
—passive-matrix monochrome, passive-matrix color and active-
matrix color. The differences between these types are beyond the
scope of this book.

Graphics Circuitry
Apart from the monitor another major component of the VDU is
the graphics circuitry. It is responsible for converting the digital
information that the computer produces into something human
244 Let Us C
beings can see. Most desktops use analog display monitors, hence
the graphics card convert digital information to analog information
for display on the monitor. On laptops the data remains digital
because the laptop displays are digital. The graphics circuitry is
either placed on a card that is plugged into an expansion slot.
Alternately, it can also be built right inside the mother board. The
graphics cards have evolved over the years. It might be interesting
to follow this evolution.

Graphics Card Standards


The first graphics card, introduced in August of 1981 by IBM, was
Monochrome Display Adapter (MDA). The monitors that used
these cards were typically text-only, with green, amber or white
text on a black background.

Color for IBM-compatible computers appeared on the scene with


the 4-color Hercules Graphics Card (HGC), followed by the 8-
color Color Graphics Adapter (CGA) and 16-color Enhanced
Graphics Adapter (EGA).

When IBM introduced the Video Graphics Array (VGA) in 1987, a


new graphics standard came into being. A VGA display could
support up to 256 colors (out of a possible 2,62,144 colors) at
resolutions up to 720 x 400 (resolution and its impact on the image
is discussed in the next section). Perhaps the most interesting
difference between VGA and the preceding formats is that VGA
was analog, whereas displays had been digital up to that point.
Why were displays moved from digital to analog when most other
electronic systems like compact disk players, newer VCRs and
camcorders use digital picture storage? The answer is color. A
digital display generates different colors by using the red, green
and blue electron beams. In addition an intensity signal is used to
display each color at one of the two intensity levels. This gives rise
to a capability to generate 16 colors (24).
Chapter 15: VDU Basics 245
An analog display works like digital displays that use RGB
electron beams to construct various colors, but each color in the
analog system can be displayed at varying levels of intensity—64
levels, in the case of the VGA. This versatility provides 2,62,144
possible colors (643). In computer graphics the color is often
important than the resolution, because the human eye perceives the
picture that has more colors as being more realistic. Thus IBM
moved display system into analog to enhance the color
capabilities.

Over the years, VGA gave way to Super Video Graphics Array
(SVGA). SVGA cards were based on VGA, but each card
manufacturer added resolutions and increased color depth in
different ways. Thus SVGA refers to a group of video cards, all
with roughly the same capabilities. It does not refer to a specific
card, like the VGA technically does.

In order to create some standard out of the chaos of SVGA, the


Video Electronics Standards Association (VESA) introduced a
standard programming interface called the VESA BIOS Extension.
This provided programmers with one common interface to write
for instead of trying to tailor their programs to work with several
different SVGA cards. All SVGA cards in use today comply with
the VESA standard.

Modern Graphics Cards


The graphics card in a modern PC can be connected either to the
PCI slot (Peripheral Component Interconnect expansion slot) or to
the AGP (Accelerated Graphics Port) slot. The communication
between the PCI slot and the main processor takes place through a
PCI bus. All the cards connected to different PCI slots share the
PCI bus. Unlike this the AGP bus is not shared and is dedicated to
exclusive graphics use. As a result, AGP offers a faster
performance as compared to PCI.
246 Let Us C
The modern PC graphics card consists of six main components:
(a) Graphics processor
(b) Video memory
(c) Digital to Analog converter (DAC)
(d) Display Connector
(e) Bus Connector
(f) Graphics BIOS
Let us discuss these components now.

Graphics Processor
Early graphics cards merely used to have video memory and
circuitry to convert digital data to analog display. The job of
writing digital data into video memory used to be done by the
main processor. As a result, the main processor used to spent lot of
time in performing complex graphics operations. These cards are
hardly used any more.

The advent of graphical OS like Windows as well as advances in


Multimedia and 3D graphics has dramatically increased the
amount of information needing to be displayed on the monitor.
This has made it impractical for the main processor to handle all
graphics activities. Hence these activities have been now assigned
to the dedicated processor present on the graphics card. They have
special command sets for graphics manipulation built right into the
chip.

This graphics processor is optimized for performing graphics


operations. The CPU sends a set of drawing instructions that are
interpreted by the graphics card’s proprietary driver and executed
by the card’s on-board graphics processor. This greatly reduces
the main processor’s workload. Such a graphics processor is often
known as Graphics Accelerator.
Chapter 15: VDU Basics 247
Another variety of graphics processor called Coprocessor also
exists. In this system the graphic cards driver software sends
graphics-related tasks directly to the Coprocessor, which proceeds
to carry out those tasks without any assistance from the main
processor. The OS sends everything else to the main processor.
Thus both the processors work simultaneously resulting in better
performance. These Coprocessors are typically used in higher end
graphics cards.

Operations including bitmap transfers and painting, window


resizing and repositioning, line drawing, font scaling and polygon
drawing can be handled by the graphics processor at far greater
speeds than the software running on the system’ main processor.
The graphics processor then writes the display data to the video
memory (also called frame buffer). As there’s less data to transfer,
there’s less congestion on the bus.

Video Memory
The memory that holds the video image is called video memory. It
is also referred to as the frame buffer. Anything drawn on the
screen is made up of individual dots. These dots are called pixels
and each pixel has a color. The memory is used to hold the color of
each pixel. Today’s graphics cards typically have 4 MB or 8 MB of
video memory. The amount of video memory installed on the
graphics card has a direct bearing on the number of colors and the
resolution that it can support.

Digital to Analog Converter (DAC)


The information in the video memory frame buffer is an image of
what appears on the screen, stored as a digital bitmap. But while
the video memory contains digital information its output medium,
the monitor, uses analogue signals. The analog signal requires
more than just an on or off signal, as it’s used to determine where,
248 Let Us C
when and with what intensity the electron guns inside the monitor
should be fired as they scan across and down the front of the
monitor. This is where the DAC comes in. The DAC takes the
input from the video.

Display Connector
Graphics cards use standard connectors. Most cards use the 15-pin
female connector. The monitor cable is plugged into this
connector.

Computer (Bus) Connector


The graphics card connects to the PCI/AGP slot through this
connector. Main processor communicates with the graphics card
through this connector. Today most of the graphics cards are
connected to the AGP slot.

Graphics BIOS
Graphics cards have a small ROM chip containing basic
information that tells the other components of the card how to
function in relation to each other. The BIOS also performs
diagnostic tests on the card’s memory and input/output (I/O) to
ensure that everything is functioning correctly.

Video Display Modes


Just as an artist can choose from a variety of media when creating
a picture (oils, etching, watercolors etc.), so a programmer can
choose from a variety of modes, or formats. Each mode provides a
different combination of display characteristics. These
characteristics include:
Chapter 15: VDU Basics 249
(a) whether text or graphics is to be displayed
(b) the amount of text to be displayed in one line
(c) the resolution
(d) the number of possible colors
Each mode requires certain hardware (monitor and display
adapter) and programming approaches. Each and every mode will
not be supported by a particular combination of monitor and
display adapter. There are several modes available. Figure 15.1
lists the popular along with the number of colors and resolution
they offer.

Mode Reaolution. Colors Bits/Pixel Remark


5 320 x 200 4 2
12 640 x 480 16 4
13 320 x 200 256 8
101h 640 x 480 256 8 Palette-index mode
103h 800 x 600 256 8 Palette-index mode
104h 1024 x 768 16 4 Palette-index mode
105h 1024 x 768 256 8 Palette-index mode
111h 640 x 480 65536 16 Direct color mode
112h 640 x 480 1677716 32 Direct color mode
114h 800 x 600 65536 16 Direct color mode
115h 800 x 600 1677716 32 Direct color mode
117h 1024 x 768 65536 16 Direct color mode
118h 1024 x 768 1677716 32 Direct color mode
11Ah 1280 x 1024 65536 16 Direct color mode
11Bh 1280 x 1024 1677716 32 Direct color mode
3 640 x 200 16 2 bytes/char Text mode

Figure 15.1

Text or Graphics
250 Let Us C
All modes are fundamentally of two types, text or graphics. Some
modes display only text, some support more colors, whereas some
are made only for graphics. As seen earlier, the graphics card
continuously dumps the contents of the video memory on the
screen. The amount of memory required for representing a
character on screen in text mode and a pixel in graphics mode
varies from mode to mode. Figure 15.1 shows the amount of
memory required do display a fundamental element in each mode.

In mode 5 each pixel displayed on the screen occupies two bits in


video memory. These two bits can generate four values (00, 01, 10
and 11) and hence a pixel can be drawn in four possible colors. In
modes 18 and 19 a pixel can be drawn in 16 and 256 colors
respectively. How these colors are generated is discussed in a later
section in this chapter.

As seen from Figure 15.1, text mode needs two bytes in video
memory to represent one character on screen. Of these two bytes
the first byte contains the ASCII value of the character being
displayed, whereas the second byte is the attribute byte. The
attribute byte controls the color in which the character is being
displayed.

How does the character actually get displayed on the screen? The
ASCII value present in video memory must be translated into a
character and drawn on the screen. A character generator program
does this drawing. On older display adapters like MA and CGA,
the character generator used to be located in ROM (Read Only
Memory). VGA and SVGA do not have a character generator
ROM. Instead, character generator data is loaded into display
RAM. This feature makes it easy for custom character sets to be
loaded. Multiple character sets may reside in RAM
simultaneously. A set of BIOS services is available for easy
loading of character sets. Each character set can contain 256
characters. Either one or two character sets may be active giving
these adapters the capability to display up to 512 different
Chapter 15: VDU Basics 251
characters on the screen simultaneously. When two character sets
are active, a bit in each character attribute byte selects which
character set will be used for that character. Using a ROM-BIOS
service we can select the active character set. Each character in the
standard character set in VGA is 9 pixels wide and 16 pixels tall.
Custom character set can also be loaded using BIOS video services
(refer appendix B).

The graphics modes can also display characters, but they are
produced quite differently. The graphics modes can only store
information bit-by-bit and characters are no exception... they must
be drawn one bit at a time. The big advantage of this method is
that one can design characters of desired style, shape and size.

Colors in Text Mode


In text mode for each character on screen there are two bytes in
video memory, one containing the ASCII value of the character
and other containing its color. The color byte contains three
components—the foreground color (color of the character itself),
the background color (color of the area not covered by the
character) and the blinking component of the character. Figure
15.2 shows the breakup of the color byte.

Bits
7 6 5 4 3 2 1 0 Purpose
1 Blue component of f/g color
1 Green component of f/g color
1 Red component of f/g color
1 Intensity component of f/g color
1 Blue component of b/g color
1 Green component of b/g color
1 Red component of b/g color
1 Blinking component
252 Let Us C

Figure 15.2

The first four bits can produce 16 different colors, whereas the
Red, Green and Blue components of background colors can
produce 8 different colors. Figure 15.3 shows, which bit setting,
will produce what color.

Color Components

Intensity Red Green Blue

Black 0 0 0 0
Blue 0 0 0 1
Green 0 0 1 0
Cyan 0 0 1 1
Red 0 1 0 0
Magenta 0 1 0 1
Brown 0 1 1 0
White 0 1 1 1
Light Black 1 0 0 0
Light Blue 1 0 0 1
Light Green 1 0 1 0
Light Cyan 1 0 1 1
Light Red 1 1 0 0
Light Magenta 1 1 0 1
Yellow 1 1 1 0
Chapter 15: VDU Basics 253
Intense White 1 1 1 1

Figure 15.3
If the bit settings of the color byte are, say, 00010100, then the
character produced would be of red color on a blue background.
Similarly, 10001110 would produce a yellow character on a black
background, and the character would blink on the screen.

Colors in Graphics Mode


So far we have seen how to set color in text modes. Setting color
in graphics modes is quite different. In the graphics mode each
pixel on the screen has a color associated with it. There are
important differences here as compared to setting color is text
mode. First, the pixels cannot blink. Second, each pixel is a
discrete dot of color, there is no foreground and background; each
pixel is simply one color or another. The number of colors that
each mode can support and the way each graphics card generates
these colors is drastically different. Here we would examine the
color generation technique used by VGA.

Colors in VGA
VGA’s video memory is organized in four planes—red, green, blue
and intensity. Each plane provides one bit of data for each pixel.
Thus any pixel is represented by a 4-bit value, each plane
contributing one bit of this 4-bit value. The 4-bit pixel value is
from the display memory is used as the address of 1 of the 16
palette registers. For example, a pixel value of 0000 selects the
palette register 0, a pixel value of 0001 selects register 1, a pixel
value of 0010 selects register 2, and so on.

Each palette register is 6 bits long. Once the palette register has
been chosen the 6-bit value in it is combined with a 2-bit value
254 Let Us C
from a color select register, resulting into a 8-bit value. This 8-bit
value is used as the address of 1 of the 256 DAC (Digital to
Analog Converter) registers. Each DAC register contains an 18-bit
value that represents the color. The 18-bit value is organized as 6-
bit red, green and blue color components. This value is sent to the
analog conversion circuitry, which converts it into three
proportional analog signals and sends them to the monitor. Since
each DAC register is 18-bit long, a pixel can have any of the
2,62,144 values (218).

The translation of a 4-bit color value into a 18-bit DAC register


value is shown in Figure 15.4.
Chapter 15: VDU Basics 255
Palette Register DAC Registers
0000 00000000
0001
00000001
0010
00000010
00000011
Pixel Value
0 1 1 0

0110 011100 Color Select


0111 Register
1111 0 1

0 1 1 1 0 0 0 1
18-bit Color Value
01110001 001101 001110 101101

R
Analog
G
Conversion
Circuit B
11111100
11111101
11111110
11111111

Figure 15.4

In summary, we cannot speak of ‘color’ at any point in the color


translation process until the output stage of DAC. The 4-bit pixel
256 Let Us C
value in memory, the 6-bit value in the palette registers and the 8-
bit value sent to the DAC are all addresses, not colors. For
example, a pixel with a 4-bit value of 0 is not black; it is address 0
of the palette register. If this palette register contains a value 3Fh
then this value is not the white color but a value which would be
combined with the 2 bits from the color select register to give a 8-
bit value. Suppose the 2-bit value is 0 then the 8-bit value would
remain 3Fh. This value is also not the white color. It is the address
of the DAC register. It is the value stored in the DAC register 3Fh
that represents the color. Suppose the value stored in the DAC
register 0x3F is 63 then the pixel would be displayed in color 63.
Thus, a pixel value of 0 in display memory can become color 63
when displayed on the screen. In short, it isn’t color until the DAC
says it is color.

VGA supports several graphics modes. The two popular ones are
—640 x 480, 16-color mode and a 320 x 200, 256-color mode.
How come only 16 or 256 colors can be availed at a time from
2,62,144 colors?

In the 256-color mode, the 2-bits from the color select register and
6 bits from the palette register are combined to form a 8-bit value.
This 8-bit value can give rise to 256 different combinations. Each
combination references a particular DAC register, which holds the
actual 18-bit color value. As a result, we can use 256 out of the
possible 2,62,144 color values (218).

In the 16-color mode, the color select register bits always have a
value 0. Hence, in this mode only the first 64 DAC registers get
used. And since there are only 16 palette registers that can be used
to refer to these DAC registers, in this mode we can use any 16 out
of the 2,62,144 colors.
Chapter 15: VDU Basics 257

Colors in SVGA
There are several modes that are specific to SVGA. These modes
can be broadly categorized into:
(a) Palette-indexed modes
(b) Direct color modes

In the palette-indexed modes SVGA uses either 4 bits 8 bits to


represent a pixel. We would discuss here the case when it uses 8
bits to represent a pixel (the 4-bit model’s discussion would be
similar). In the 8-bit model SVGA uses 256 palette registers. Using
the 8-bit pixel value it can access 256 palette registers. Each value
in the palette register can further access 256 DAC registers. Each
DAC register is 24 bits long. Hence, in SVGA we can choose 256
colors simultaneously out of the possible 16,77,716 colors (224).
Note that the 8-bit pixel value is merely an index into the palette
registers and the palette register value is an index into the DAC
registers. The actual color value is the one in the DAC registers.

In direct color modes there are no palette registers or planes. These


modes typically use either 16 bits or 32 bits to represent a pixel
color. A 16-bit or 32-bit value directly represents the pixel color. In
these modes we get either 65536 (216) or 16777216 (224) colors at
a time. The first category is often known as a ‘high color’ mode
and the second is known as ‘true color’ mode. Why were the
palettes abandoned? Two reasons. For one the video memory
became cheap and for another the advent of multimedia and 3D
graphics demanded more colors to be displayed simultaneously.

Video Pages
In text mode each character displayed on the screen takes 2 bytes
in video memory. As a result a total of 2000 characters (25 x 80)
258 Let Us C
would require 4000 bytes, or roughly 4 KB. As size of video
memory is bigger than 4 KB, if only the first 4 KB of video
memory is used then the rest would remain unutilized. To avoid
this the display memory can be split into several chunks of 4 KB
each. These chunks of memory are called video pages. Thus, there
are four video pages in mode 3, numbered from 0 to 3. At any
given time, contents of one page are displayed on the screen.
Information can be written into the displayed page or any of the
other pages. Using this technique we can build a screen on an
invisible page while another page is being displayed, then switch
to the new page when appropriate time comes. Switching screen
images this way makes them appear to regenerate instantaneously.

This technique is often used in writing menu-driven programs,


where a different menu is written on each page. As a result, to
switch over from one menu to another, all that we are required to
do is to switch over to an appropriate page, where the menu is
already written and ready to be displayed. This is obviously a
better procedure than erasing the existing menu and writing a new
menu.

In graphics modes too, the display memory is split into video


pages. The maximum number of pages permitted depends on the
bits required to store information of one pixel and the amount of
display memory available.

The DOS Perspective


While working under DOS the processor is made to work in Real
mode. In this mode all the CPU registers are reduced to 16-bit. As
a result under DOS we cannot access memory blocks bigger than
64 KB (216 bytes). This barrier has been overcome to an extent by
using a segment:offset scheme (Refer Appendix G for details of
this scheme) that lets you access any byte within 1 MB memory.
Chapter 15: VDU Basics 259
Even with this scheme from any given address we can access only
the next 64 KB chunk.

Due to this limitation, while working under DOS 2 blocks of


memory—A block and B block, each of 64 KB—are reserved for
access to video memory. In fact, these blocks act as a window to
the video memory. Anytime we are to display anything on the
screen we write to these blocks, which are mapped into the video
memory.

Figure 15.5 shows the exact location of A and B blocks in 1 MB


memory map. Note that the first megabyte of memory is divided
into 16 blocks of 64 KB each. These blocks are numbered from 0
to 15. As said earlier, blocks A and B map into the video memory.
Which out of these two blocks would be used depends on the
mode in which you are working (text/graphics).

F
E
D
C
Window to video memory B
Window to video memory A
1MB

640KB
260 Let Us C

Figure 15.5

Writing to Video Memory in Text Mode


Windows doesn’t work under text mode so the discussion that
follows is specific to MS-DOS. There are 3 ways of displaying
characters on the screen.
(a) Using standard library functions
(b) Using ROM-BIOS or DOS routines
(c) Writing characters directly into video memory
The last option works faster than the other two, because, the
standard library functions or ROM-BIOS/DOS routines ultimately
write the characters to be displayed into video memory. Obviously,
if we are able to write characters directly into video memory we
would be able to bypass the standard library functions as well as
the ROM-BIOS/DOS routines.

We know that above the 640 KB RAM, there are 2 blocks (block A
and Block B) of 64 KB each. While working in text mode all text
displayed on the screen is written to the B block starting at address
0xB8000. Each character present on the screen uses 2 bytes in B
block. The first byte contains the ASCII value of the character,
whereas the next byte contains the color of the character. For
example, if ‘A’ is displayed in 0th row, 0th column on the screen,
then address 0xB8000 contains the ASCII value of ‘A’, whereas
the immediately adjacent address contains the color of ‘A’.

Thus, if one character occupies two bytes in B block, 80 characters


of 0th row will be represented by first 160 bytes from 0xB8000
onwards. Similarly, one screenful of characters would need 4000
bytes (80 x 25 x 2).
Chapter 15: VDU Basics 261
Using this concept let us now write a program which fills the
entire screen with ‘A’s by writing this character directly into B
block of memory.

/* Screenful of 'A's */
main( )
{
int i ;
char far *vidmem = 0xB8000000 ;

for ( i = 0 ; i <= 3999 ; i = i + 2 )


* ( vidmem + i ) = 'A' ;
}

The variable vidmem has been defined as a far pointer since we


are trying to access the memory that is beyond the data segment of
our program. Data segment is the place where all the variables
used in the program reside.

Now suppose we want to change the color of all the characters on


the screen to 112, it can be done using the following program.

/* Changing screen attributes */


main( )
{
int i ;
char far *vidmem = 0xB8000000 ;

for ( i = 1 ; i <= 3999 ; i = i + 2 )


* ( vidmem + i ) = 112 ;
}

Now it’s time for something more complicated. The following


program draws a filled box on the screen and displays a message
in it.

char far *vidmem = 0xB8000000 ;


262 Let Us C
main( )
{
int r, c, i ;
char message[ ] = "Al Italia!!" ;

for ( r = 5 ; r <= 20 ; r++ )


{
for ( c = 5 ; c <= 50 ; c++ )
write2vdu ( ' ', 64, r, c ) ;
}

c = 10 ;
for ( i = 0 ; i <= 10 ; i++ )
{
write2vdu ( message[i], 77, 10, c ) ;
c++ ;
}
}

write2vdu ( char ch, char color, int row, int col )


{
char far *v ;
v = vidmem + row * 160 + col * 2 ;
*v = ch ;
v++ ;
*v = color ;
}

In the above example, a separate function write2vdu( ) has been


called from the main( ). To it we have sent character to be
displayed (ch), its color (color) and the row & column where it is
to be displayed. Upon receiving the arguments, the character and
its color are stored at appropriate locations in the B block of
memory. Work through the function write2vdu( ) carefully till you
have analyzed the whole process.

Exercise
Chapter 15: VDU Basics 263
[A] State True or False:
(a) High refresh rates cause the screen to flicker contributing to
eye-strain.
(b) The microprocessor does not have the ability to send signals
necessary to produce the images on the screen.
(c) Text or graphics on the screen are built up from tiny dots
called picture elements or ‘pixels’.
(d) The flat screen results in reduced glare and a higher quality,
more accurate image.
(e) Interlaced monitors offer better and stable displays as
compared with non-interlaced monitors.
(f) The graphics card in a modern PC can be connected either to
the PCI slot or to the AGP slot.
(g) In text mode for each character on screen there are two bytes
in video memory, one containing the ASCII value of the
character and other containing its color.
(h) The amount of memory that is required for representing a
character on screen in text mode and a pixel in graphics mode
is always same.
(i) VGA’s video memory is organized in four planes and each
plane provides one bit of data for each pixel.
(j) In VGA since each DAC register is 18-bit long, a pixel can
have any of the 2,62,144 values (218).
(k) In SVGA graphics mode, each DAC register is 24 bits long.
(l) While accessing video memory under DOS, A block is used
for the text mode and B block is used for the Graphics mode.

[B] Pick up the correct alternative for each of the following:

(a) Which of the following would display a message on the


screen fastest
(1) printf( ) function
(2) puts( ) function
(3) ROM-BIOS function
(4) Directly writing to VDU memory
264 Let Us C
(b) A multiple-frequency monitor is also called
(1) Multisync monitor
(2) Multiscan monitor
(3) Asynchronous monitor
(4) All the above

(c) The monitors that sweeps the screen in lines from top to
bottom one line after the other in one pass are known as
(1) Non-interlaced monitors
(2) Interlaced monitors
(3) FST monitors
(4) All the above

(d) The first graphics card, introduced in August of 1981 by IBM,


was known as
(1) Monochrome Display Adapter (MDA)
(2) Hercules Graphics Card (HGC)
(3) Color Graphics Adapter (CGA)
(4) Enhanced Graphics Adapter (EGA)

(e) In the text mode each character displayed on the screen


occupies ______ bytes in VDU memory
(1) 2
(2) 4
(3) 6
(4) 1
(f) The total number of DAC registers in VGA card are
(1) 64
(2) 128
(3) 256
(4) 512

[C] Answer the following:


Chapter 15: VDU Basics 265
(a) What do you mean by refresh rate? Is it true that higher the
refresh rate better is the image on the screen?

(b) What is the purpose of the graphics card? Where is it present


in the computer?

(c) Why is it that in text mode there is only one font available,
whereas in graphics mode characters can be displayed in a
variety of fonts?

(d) What colour byte would you use if a message is to be


displayed on the screen with brown background and yellow
coloured characters?

(e) When we change over from one mode to another do the


screen’s current contents remain intact?

[D] Answer the following:

(a) In the following program the displaymenu( ) function is


supposed to write a given menu on a given VDU page by
directly writing it in VDU memory. You are required to write
the function displaymenu( ). Make it as general as you can.

char *filemenu[ ] = {
"Rename file",
"Copy file",
"Delete file",
"Display file"
};

char *dirmenu[ ] = {
"Make directory",
"Change directory",
"Remove directory"
"List directory"
};
266 Let Us C
main( )
{
int row = 5, col = 20, vdupage, num ;

num = 4 ; /* number of menu items */


vdupage = 0 ;
displaymenu ( filemenu, row, col, vdupage, num ) ;
vdupage = 1 ;
displaymenu ( dirmenu, row, col, vdupage, num ) ;
}

(b) Write a general purpose function writestring( ) which will


display a message on the screen by writing it directly into
VDU memory. The function should be capable of displaying
the message in the colour which is sent to it.
(c) Write a program which continuously keeps changing the
capital letters present on the screen into small case letters and
small case letters present on the screen into capitals. You are
not allowed to use printf( ), putchar( ), puts( ) or putch( ).
Chapter 15: VDU Basics 267

You might also like