Specifications.
[pintos-anon] / specs / freevga / vga / vgatext.htm
1 <HTML>
2 <HEAD>
3    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
4    <META NAME="Author" CONTENT="Joshua Neal">
5    <META NAME="Description" CONTENT="Pure VGA/SVGA hardware programming (registers, identification, and other low-level stuff.)">
6    <META NAME="KeyWords" CONTENT="VGA SVGA hardware video programming">
7    <TITLE>VGA/SVGA Video Programming--VGA Text Mode Operation</TITLE>
8 </HEAD>
9 <BODY>
10
11 <CENTER><A HREF="../home.htm">Home</A> <A HREF="#intro">Intro</A> <A HREF="#memory">Memory</A>
12 <A HREF="#attributes">Attributes</A> <A HREF="#fonts">Fonts</A> <A HREF="#cursor">Cursor</A>
13 <A HREF="vga.htm#general">Back</A>&nbsp;
14 <HR WIDTH="100%"><B>Hardware Level VGA and SVGA Video Programming Information
15 Page</B></CENTER>
16
17 <CENTER>VGA Text Mode Operation&nbsp;
18 <HR WIDTH="100%"></CENTER>
19
20 <UL>
21 <LI>
22 <A HREF="#intro">Introduction</A> -- gives scope of this page.</LI>
23
24 <LI>
25 <A HREF="#memory">Display Memory Organization</A> -- details how the VGA's
26 planes are utilized when in text mode.</LI>
27
28 <LI>
29 <A HREF="#attributes">Attributes</A> -- details the fields of the attribute
30 byte.</LI>
31
32 <LI>
33 <A HREF="#fonts">Fonts</A> -- details the operation of the character generation
34 hardware.</LI>
35
36 <LI>
37 <A HREF="#cursor">Cursor</A> -- details on manipulating the text-mode cursor.</LI>
38 </UL>
39 <A NAME="intro"></A><B>Introduction</B>
40 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This section is intended
41 to document the VGA's operation when it is in the text modes, including
42 attributes and fonts. While it would seem that the text modes are adequately
43 supported by the VGA BIOS, there is actually much that can be done with
44 the VGA text modes that can only be accomplished by going directly to the
45 hardware. Furthermore, I have found no good reference on the VGA text modes;
46 most VGA references take them for granted without delving into their operation.
47
48 <P><A NAME="memory"></A><B>Display Memory Organization</B>
49 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The four display memory
50 planes are used for different purposes when the VGA is in text mode. Each
51 byte in plane 0 is used to store an index into the character font map.
52 The corresponding byte in plane 1 is used to specify the attributes of
53 the character possibly including color, font select, blink, underline and
54 reverse. For more details on attribute operation see the Attributes section
55 below. Display plane 2 is used to store the bitmaps for the characters
56 themselves. This is discussed in the Fonts section below. Normally, the
57 odd/even read and write addressing mode is used to make planes 0 and 1
58 accessible at interleaved host memory addresses.
59
60 <P><A NAME="attributes"></A><B>Attributes</B>
61 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The attribute byte is divided
62 into two four bit fields. The field from 7-4 is used as an index into the
63 palette registers for the background color which used when a font bit is
64 0. The field from 3-0 is used as an index into the palette registers for
65 the foreground which is used when a font bit is 1. Also the attribute can
66 control several other aspects which may modify the way the character is
67 displayed.
68 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If the <A HREF="attrreg.htm#10">Blink
69 Enable</A> field is set to 1, character blinking is enabled. When blinking
70 is enabled, bit 3 of the background color is forced to 0 for attribute
71 generation purposes, and if bit 7 of the attribute byte for a character
72 is set to 1, the foreground color alternates between the foreground and
73 background, causing the character to blink. The blink rate is determined
74 by the vertical sync rate divided by 32.
75 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If the bits 2-0 of the attribute
76 byte is equal to 001b and bits 6-4 of the attribute byte is equal to 000b,
77 then the line of the character specified by the <A HREF="crtcreg.htm#14">Underline
78 Location</A> field is replaced with the foreground color. Note if the line
79 specified by the <A HREF="crtcreg.htm#14">Underline Location</A> field
80 is not normally displayed because it is greater than the maximum scan line
81 of the characters displayed, then the underline capability is effectively
82 disabled.
83 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bit 3 of the attribute byte,
84 as well as selecting the foreground color for its corresponding character,
85 also is used to select between the two possible character sets (see <A HREF="#fonts">Fonts</A>
86 below.) If both character sets are the same, then the bit effectively functions
87 only to select the foreground color.
88
89 <P><A NAME="fonts"></A><B>Fonts</B>
90 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The VGA's text-mode hardware
91 provides for a very fast text mode. While this mode is not used as often
92 these days, it used to be the predominant mode of operation for applications.
93 The reason that the text mode was fast, much faster than a graphics mode
94 at the same resolution was that in text mode, the screen is partitioned
95 into characters. A single character/attribute pair is written to screen,
96 and the hardware uses a font table in video memory to map those character
97 and attribute pairs into video output, as opposed to having to write all
98 of the bits in a character, which could take over 16 operations to write
99 to screen. As CPU display memory bandwidth is somewhat limited (particularly
100 on on older cards), this made text mode the mode of choice for applications
101 which did not require graphics.
102
103 <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For each character
104 position, bit 3 of the attribute byte selects which character set is used,
105 and the character byte selects which of the 256 characters in that font
106 are used. Up to eight sets of font bitmaps can be stored simultaneously
107 in display memory plane 2. The VGA's hardware provides for two banks of
108 256 character bitmaps to displayed simultaneously. Two fields, <A HREF="seqreg.htm#03">Character
109 Set A Select</A> and <A HREF="seqreg.htm#03">Character Set B Select</A>
110 field are used to determine which of the eight font bitmaps are currently
111 displayed. If bit 3 of a character's attribute byte is set to 1, then the
112 character set selected by <A HREF="seqreg.htm#03">Character Set A Select</A>
113 field, otherwise the character set specified by <A HREF="seqreg.htm#03">Character
114 Set B Select</A> field is used. Ordinarily, both character sets use the
115 same map in memory, as utilizing 2 different character sets causes character
116 set A to be limited to colors 0-7, and character set B to be limited to
117 colors 8-15.
118 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fonts are either 8 or 9
119 pixels wide and can be from 1 to 32 pixels high. The width is determined
120 by the <A HREF="seqreg.htm#01">9/8 Dot Mode</A> field. Characters normally
121 have a line of blank pixels to the right and bottom of the character to
122 separate the character from its neighbor. Normally this is included in
123 the character's bitmap, leaving only 7 bit columns for the character. Characters
124 such as the capital M have to be squished to fit this, and would look better
125 if all 8 pixels in the bitmap could be used, as in 9 Dot mode where the
126 characters have an extra ninth bit in width, which is displayed in the
127 text background color, However, this causes the line drawing characters
128 to be discontinuous due to the blank column. Fortunately, the <A HREF="attrreg.htm#10">Line
129 Graphics Enable</A> field can be set to allow character codes C0h-DFh to
130 have their ninth column be identical to their eighth column, providing
131 for continuity between line drawing characters. The height is determined
132 by the <A HREF="crtcreg.htm#09">Maximum Scan Line</A> field which is set
133 to one less than the number of scan lines in the character.
134 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Display memory plane 2 is
135 divided up into eight 8K banks of characters, each of which holds 256 character
136 bitmaps. Each character is on a 32 byte boundary and is 32 bytes long.
137 The offset in plane 2 of a character within a bank is determined by taking
138 the character's value and multiplying it by 32. The first byte at this
139 offset contains the 8 pixels of the top scan line of the characters. Each
140 successive byte contains another scan line's worth of pixels. The best
141 way to read and write fonts to display memory, assuming familiarity with
142 the information from the <A HREF="vgamem.htm">Accessing the Display Memory</A>
143 page, is to use standard (not Odd/Even) addressing and Read Mode 0 and
144 Write Mode 0 with plane 2 selected for read or write.
145 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The following example shows
146 three possible bitmap representations of text characters. In the left example
147 an 8x8 character box is used. In this case, the <A HREF="crtcreg.htm#09">Maximum
148 Scan Line</A> field is programmed to 7 and the <A HREF="seqreg.htm#01">9/8
149 Dot Mode</A> field is programmed to 0. Note that the bottom row and right-most
150 column is blank. This is used to provide inter-character spacing. The middle
151 example shows an 8x16 character. In this case the <A HREF="crtcreg.htm#09">Maximum
152 Scan Line</A> field is programmed to 15 and the <A HREF="seqreg.htm#01">9/8
153 Dot Mode</A> field is programmed to 0. Note that the character has extra
154 space at the bottom below the baseline of the character. This is used by
155 characters with parts descending below the baseline, such as the lowercase
156 letter "g". The right example shows a 9x16 character. In this case the
157 <A HREF="crtcreg.htm#09">Maximum Scan Line</A> field is programmed to 15
158 and the <A HREF="seqreg.htm#01">9/8 Dot Mode</A> field is programmed to
159 1. Note that the rightmost column is used by the character, as the ninth
160 column for 9-bit wide characters is assumed blank (excepting for the behavior
161 of the the <A HREF="attrreg.htm#10">Line Graphics Enable</A> field.) allowing
162 all eight bits of width to be used to specify the character, instead of
163 having to devote an entire column for inter-character spacing.
164 <CENTER><A HREF="char.txt"><IMG SRC="Char.gif" ALT="Click for Textified Examples of Text Mode Bitmap Characters" BORDER=0 HEIGHT=256 WIDTH=376></A></CENTER>
165 &nbsp;
166
167 <P>&nbsp;
168 <BR><A NAME="cursor"></A><B>Cursor</B>
169 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The VGA has the hardware capability
170 to display a cursor in the text modes. Further details on the text-mode
171 cursor's operation can be found in the following section:
172 <UL>
173 <LI>
174 <A HREF="textcur.htm">Manipulating the Text-mode Cursor</A> -- details
175 controlling the appearance and location of the cursor.</LI>
176 </UL>
177 Notice: All trademarks used or referred to on this page are the property
178 of their respective owners.
179 <BR>All pages are Copyright &copy; 1997, 1998, J. D. Neal, except where
180 noted. Permission for utilization and distribution is subject to the terms
181 of the <A HREF="license.htm">FreeVGA Project Copyright License</A>.
182 <BR>&nbsp;
183 <BR>&nbsp;
184 </BODY>
185 </HTML>