3 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
\r
4 <META NAME="Author" CONTENT="Joshua Neal">
\r
5 <META NAME="Description" CONTENT="Pure VGA/SVGA hardware programming (registers, identification, and otherlow-level stuff.)">
\r
6 <META NAME="KeyWords" CONTENT="VGA SVGA hardware video programming">
\r
7 <TITLE>FreeVGA--Special Effects Hardware</TITLE>
\r
11 <CENTER><A HREF="../home.htm">Home</A> <A HREF="#intro">Intro</A> <A HREF="#window">Windowing</A>
\r
12 <A HREF="#paging">Paging</A> <A HREF="#smooth">Smooth Scrolling</A> <A HREF="#split">Split-Screen</A>
\r
13 <A HREF="vga.htm#general">Back
\r
14 <HR WIDTH="100%"></A><B>Hardware Level VGA and SVGA Video Programming Information
\r
17 <CENTER>Special Effects Hardware
\r
18 <HR WIDTH="100%"></CENTER>
\r
22 <A HREF="#intro">Introduction</A> -- describes the capabilities of the
\r
23 VGA special effects hardware.</LI>
\r
26 <A HREF="#window">Windowing</A> -- provides rough panning and scrolling
\r
27 of a larger virtual image.</LI>
\r
30 <A HREF="#paging">Paging</A> -- provides the ability to switch between
\r
31 multiple screens rapidly.</LI>
\r
34 <A HREF="#smooth">Smooth Panning and Scrolling</A> -- provides more precise
\r
35 control when panning and scrolling.</LI>
\r
38 <A HREF="#split">Split-Screen Operation</A> -- provides a horizontal division
\r
39 which allows independent scrolling and panning of the top window.</LI>
\r
41 <A NAME="intro"></A><B>Introduction</B>
\r
42 <BR> This section describes the
\r
43 capabilities of the VGA hardware that can be used to implement special
\r
44 effects such as windowing, paging, smooth panning and scrolling, and split
\r
45 screen operation.. These functions are probably the least utilized of all
\r
46 of the VGA's capabilities, possibly because most texts devoted to video
\r
47 hardware provide only brief documentation. Also, the video BIOS provides
\r
48 no support for these capabilities so the VGA card must be programmed at
\r
49 the hardware level in order to utilize these capabilities. Windowing allows
\r
50 a program to view a portion of an image in display memory larger than the
\r
51 current display resolution, providing rough panning and scrolling. Paging
\r
52 allows multiple display screens to be stored in the display memory allowing
\r
53 rapid switching between them. Smooth panning and scrolling works in conjunction
\r
54 with windowing to provide more precise control of window position. Split-screen
\r
55 operation allows the creation of a horizontal division on the screen that
\r
56 creates a window below that remains fixed in place independent of the panning
\r
57 and scrolling of the window above. These features can be combined to provide
\r
58 powerful control of the display with minimal demand on the host CPU.
\r
60 <P><A NAME="window"></A><B>Windowing</B>
\r
61 <BR> The VGA hardware has the
\r
62 ability treat the display as a window which can pan and/or scroll across
\r
63 an image larger than the screen, which is used by some windowing systems
\r
64 to provide a virtual scrolling desktop, and by some games and assembly
\r
65 demos to provide scrolling. Some image viewers use this to allow viewing
\r
66 of images larger than the screen. This capability is not limited to graphics
\r
67 mode; some terminal programs use this capability to provide a scroll-back
\r
68 buffer, and some editors use this to provide an editing screen wider than
\r
70 <BR> This feature can be implemented
\r
71 by brute force by simply copying the portion of the image to be displayed
\r
72 to the screen. Doing this, however takes significant processor horsepower.
\r
73 For example, scrolling a 256 color 320x200 display at 30 frames per second
\r
74 by brute force requires a data transfer rate of 1.92 megabytes/second.
\r
75 However, using the hardware capability of the VGA the same operation would
\r
76 require a data transfer rate of only 120 bytes/second. Obviously there
\r
77 is an advantage to using the VGA hardware. However, there are some limitations--one
\r
78 being that the entire screen must scroll (or the top portion of the screen
\r
79 if split-screen mode is used.) and the other being that the maximum size
\r
80 of the virtual image is limited to the amount of video memory accessible,
\r
81 although it is possible to redraw portions of the display memory to display
\r
82 larger virtual images.
\r
83 <BR> In text mode, windowing
\r
84 allows panning at the character resolution. In graphics mode, windowing
\r
85 allows panning at 8-bit resolution and scrolling at scan-line resolution.
\r
86 For more precise control, see <A HREF="#smooth">Smooth Panning and Scrolling</A>
\r
87 below. Because the VGA BIOS and most programming environment's graphics
\r
88 libraries do not support windowing, you must modify or write your own routines
\r
89 to write to the display for functions such as writing text or graphics.
\r
90 This section assumes that you have the ability to work with the custom
\r
91 resolutions possible when windowing is used.
\r
92 <BR> In order to understand virtual
\r
93 resolutions it is necessary to understand how the VGA's <A HREF="crtcreg.htm#0C">Start
\r
94 Address High Register</A>, <A HREF="crtcreg.htm#0D">Start Address Low Register</A>,
\r
95 and <A HREF="crtcreg.htm#13">Offset</A> field work. Because display memory
\r
96 in the VGA is accessed by a 32-bit bus, a 16-bit address is sufficient
\r
97 to uniquely identify any location in the VGA's 256K address space. The
\r
98 <A HREF="crtcreg.htm#0C">Start Address High Register</A> and <A HREF="crtcreg.htm#0D">Start
\r
99 Address Low Register</A> provide such an address. This address is used
\r
100 to specify either the location of the first character in text mode or the
\r
101 position of the first byte of pixels in graphics mode. At the end of the
\r
102 vertical retrace, the current line start address is loaded with this value.
\r
103 This causes one scan line of pixels or characters to be output starting
\r
104 at this address. At the beginning of the next scan-line (or character row
\r
105 in text mode) the value of the <A HREF="crtcreg.htm#13">Offset Register</A>
\r
106 multiplied by the current memory address size * 2 is added to the current
\r
107 line start address. The <A HREF="crtcreg.htm#14">Double-Word Addressing</A>
\r
108 field and the <A HREF="crtcreg.htm#17">Word/Byte</A> field specify the
\r
109 current memory address size. If the value of the <A HREF="crtcreg.htm#14">Double-Word
\r
110 Addressing</A> field is 1, then the current memory address size is four
\r
111 (double-word). Otherwise, the <A HREF="crtcreg.htm#17">Word/Byte</A> field
\r
112 specifies the current memory address size. If the value of the <A HREF="crtcreg.htm#17">Word/Byte</A>
\r
113 field is 0 then the current memory address size is 2 (word) otherwise,
\r
114 the current memory address size is 1 (byte).
\r
115 <BR> Normally in graphics modes,
\r
116 the offset register is programmed to represent (after multiplication) the
\r
117 number of bytes in a scan line. This means that (unless a CGA/MDA emulation
\r
118 mode is in effect) scan lines will be arranged sequentially in memory with
\r
119 no space in between, allowing for the most compact representation in display
\r
120 memory. However, this does not have to be the case--in fact, by increasing
\r
121 the value of the offset register we can leave "extra space" between lines.
\r
122 This is what provides for virtual widths. By programming the offset register
\r
123 to the value of the equation:
\r
125 <P> <B>Offset = VirtualWidth
\r
126 / ( PixelsPerAddress * MemoryAddressSize * 2 )</B>
\r
128 <P>VirtualWidth is the width of the virtual resolution in pixels, and PixelsPerAddress
\r
129 is the number of pixels per display memory address (1, 2, 4 or 8) depending
\r
130 on the current video mode. For virtual text modes, the offset register
\r
131 is programmed with the value of the equation:
\r
133 <P> <B>Offset = VirtualWidth
\r
134 / ( MemoryAddressSize * 2 )</B>
\r
136 <P>In text mode, there is always one character per display memory address.
\r
137 In standard CGA compatible text modes, MemoryAddressSize is 2 (word).
\r
138 <BR> After you have programmed
\r
139 the new offset, the screen will now display only a portion of a virtual
\r
140 display. The screen will display the number of scan-lines as specified
\r
141 by the current mode. If the screen reaches the last byte of memory, the
\r
142 next byte of memory will wrap around to the first byte of memory. Remember
\r
143 that the Start Address specifies the display memory address of the upper-left
\r
144 hand character or pixel. Thus the maximum height of a virtual screen depends
\r
145 on the width of the virtual screen. By increasing this by the number of
\r
146 bytes in a scan-line (or character row), the display will scroll one scan-line
\r
147 or character row vertically downwards. By increasing the Start Address
\r
148 by less than the number of bytes in a scan line, you can move the virtual
\r
149 window horizontally to the right. If the virtual width is the same as the
\r
150 actual width, one can create a vertical scrolling mode. This is used sometimes
\r
151 as an "elevator" mode or to provide rapid scrollback capability in text
\r
152 mode. If the virtual height is the same as the actual height, then only
\r
153 horizontal panning is possible, sometimes called "panoramic" mode. In any
\r
154 case, the equation for calculating the Start Address is:
\r
156 <P><B> Start Address = StartingOffset
\r
157 + Y * BytesPerVirtualRow + X</B>
\r
159 <P>Y is the vertical position, from 0 to the value of the VitrualHeight
\r
160 - ActualHeight. X is the horizontal position, from 0 to the value of BytesPerVirtualRow
\r
161 - BytesPerActualRow . These ranges prevent wrapping around to the left
\r
162 side of the screen, although you may find it useful to use the wrap-around
\r
163 for whatever your purpose. Note that the wrap-around simply starts displaying
\r
164 the next row/scan-line rather than the current one, so is not that useful
\r
165 (except when using programming techniques that take this factor into account.)
\r
166 Normally StartingOffset is 0, but if paging or split-screen mode is being
\r
167 used, or even if you simply want to relocate the screen, you must change
\r
168 the starting offset to the address of the upper-left hand pixel of the
\r
170 <BR> For example, a 512x300 virtual
\r
171 screen in a 320x200 16-color 1 bit/pixel planar display would require 512
\r
172 pixels / 8 pixels/byte = 64 bytes per row and 64 bytes/row * 300 lines
\r
173 = 19200 bytes per screen. Assuming the VGA is in byte addressing mode,
\r
174 this means that we need to program the offset register <A HREF="crtcreg.htm#13">Offset</A>
\r
175 field with 512 pixels / (8 pixels/byte * 1 * 2) = 32 (20h). Adding one
\r
176 to the start address will move the display screen to the right eight pixels.
\r
177 More precise control is provided by the smooth scrolling mechanism. Adding
\r
178 64 to the start address will move the virtual screen down one scan line.
\r
179 See the following chart which shows the virtual screen when the start address
\r
180 is calculated with an X and Y of 0:
\r
181 <CENTER><A HREF="virtual.txt"><IMG SRC="virtual.gif" ALT="Click for Textified Virtual Screen Mode Example" HEIGHT=256 WIDTH=376></A></CENTER>
\r
184 <P><A NAME="paging"></A><B>Paging</B>
\r
185 <BR> The video display memory
\r
186 may be able to hold more than one screen of data (or virtual screen if
\r
187 virtual resolutions are used.) These multiple screens, called pages, allows
\r
188 rapid switching between them. As long as they both have the same actual
\r
189 (and virtual if applicable) resolution, simply changing the Start Address
\r
190 as given by the <A HREF="crtcreg.htm#0C">Start Address High Register</A>
\r
191 and <A HREF="crtcreg.htm#0D">Start Address Low Register</A> pair to point
\r
192 to the memory address of the first byte of the page (or set the StartingOffset
\r
193 term in the equation for virtual resolutions to the first memory address
\r
194 of the page.) If they have different virtual widths, then the <A HREF="crtcreg.htm#13">Offset</A>
\r
195 field must be reprogrammed. It is possible to store both graphics and text
\r
196 pages simultaneously in memory, in addition to different graphics mode
\r
197 pages. In this case, the video mode must be changed when changing pages.
\r
198 In addition, in text mode the Cursor Location must be reprogrammed for
\r
199 each page if it is to be displayed. Also paging allows for double buffering
\r
200 of the display -- the CPU can write to one page while the VGA hardware
\r
201 is displaying another. By switching between pages during the vertical retrace
\r
202 period, flicker free screen updates can be implemented.
\r
203 <BR> An example of paging is
\r
204 that used by the VGA BIOS in the 80x25 text mode. Each page of text takes
\r
205 up 2000 memory address locations, and the VGA uses a 32K memory aperture,
\r
206 with the Odd/Even addressing enabled. Because Odd/Even addressing is enabled,
\r
207 each page of text takes up 4000 bytes in host memory, thus 32768 / 4000
\r
208 = 8 (rounded down) pages can be provided and can be accessed at one time
\r
209 by the CPU. Each page starts at a multiple of 4096 (1000h). Because the
\r
210 display controller circuitry works independent of the host memory access
\r
211 mode, this means that each page starts at a display address that is a multiple
\r
212 of 2048 (800h), thus the Starting Address is programmed to the value obtained
\r
213 by multiplying the page to be displayed by 2048 (800h). See the following
\r
214 chart which shows the arrangement of these pages in display memory:
\r
216 <CENTER><A HREF="paging.txt"><IMG SRC="paging.gif" ALT="Click here to display a textified Paging Memory Utilization Example" HEIGHT=256 WIDTH=376></A></CENTER>
\r
219 <P><A NAME="smooth"></A><B>Smooth Panning and Scrolling</B>
\r
220 <BR> Because the Start Address
\r
221 field only provides for scrolling and panning at the memory address level,
\r
222 more precise panning and scrolling capability is needed to scroll at the
\r
223 pixel level as multiple pixels may reside at the same memory address especially
\r
224 in text mode where the Start Address field only allows panning and scrolling
\r
225 at the character level.
\r
226 <BR> Pixel level panning is controlled
\r
227 by the <A HREF="attrreg.htm#13">Pixel Shift Count</A> and <A HREF="crtcreg.htm#08">Byte
\r
228 Panning</A> fields. The <A HREF="attrreg.htm#13">Pixel Shift Count</A>
\r
229 field specifies the number of pixels to shift left. In all graphics modes
\r
230 and text modes except 9 dot text modes and 256 color graphics modes, the
\r
231 <A HREF="attrreg.htm#13">Pixel Shift Count</A> is defined for values 0-7.
\r
232 This provides the pixel level control not provided by the <A HREF="crtcreg.htm#0D">Start
\r
233 Address Register</A> or the <A HREF="crtcreg.htm#08">Byte Panning</A> fields.
\r
234 In 9 dot text modes the <A HREF="attrreg.htm#13">Pixel Shift Count</A>
\r
235 is field defined for values 8, and 0-7, with 8 being the minimum shift
\r
236 amount and 7 being the maximum. In 256 color graphics modes, due to the
\r
237 way the hardware makes a 256 color value by combining 2 16-bit values,
\r
238 the <A HREF="attrreg.htm#13">Pixel Shift Count</A> field is only defined
\r
239 for values 0, 2, 4, and 6. Values 1, 3, 5, and 7 cause the screen to be
\r
240 distorted due to the hardware combining 4 bits from each of 2 adjacent
\r
241 pixels. The <A HREF="crtcreg.htm#08">Byte Panning</A> field is added to
\r
242 the <A HREF="crtcreg.htm#0D">Start Address Register</A> when determining
\r
243 the address of the top-left hand corner of the screen, and has the value
\r
244 from 0-3. Combined, both panning fields allow a shift of 15, 31, or 35
\r
245 pixels, dependent upon the video mode. Note that programming the <A HREF="attrreg.htm#13">Pixel
\r
246 Shift Count</A> field to an undefined value may cause undesired effects
\r
247 and these effects are not guaranteed to be identical on all chipsets, so
\r
248 it is best to be avoided.
\r
249 <BR> Pixel level scrolling is
\r
250 controlled by the <A HREF="crtcreg.htm#08">Preset Row Scan</A> field. This
\r
251 field may take any value from 0 up to the value of the <A HREF="crtcreg.htm#09">Maximum
\r
252 Scan Line</A> field; anything greater causes interesting artifacts (there
\r
253 is no guarantee that the result will be the same for all VGA chipsets.)
\r
254 Incrementing this value will shift the screen upwards by one scan line,
\r
255 allowing for smooth scrolling in modes where the Offset field does not
\r
256 provide precise control.
\r
258 <P><A NAME="split"></A><B>Split-screen Operation</B>
\r
259 <BR> The VGA hardware provides
\r
260 the ability to specify a horizontal division which divides the screen into
\r
261 two windows which can start at separate display memory addresses. In addition,
\r
262 it provides the facility for panning the top window independent of the
\r
263 bottom window. The hardware does not provide for split-screen modes where
\r
264 multiple video modes are possible in one display screen as provided by
\r
265 some non-VGA graphics controllers. In addition, there are some limitations,
\r
266 the first being that the bottom window's starting display memory address
\r
267 is fixed at 0. This means that (unless you are using split screen mode
\r
268 to duplicate memory on purpose) the bottom screen must be located first
\r
269 in memory and followed by the top. The second limitation is that either
\r
270 both windows are panned by the same amount, or only the top window pans,
\r
271 in which case, the bottom window's panning values are fixed at 0. Another
\r
272 limitation is that the <A HREF="crtcreg.htm#08">Preset Row Scan</A> field
\r
273 only applies to the top window -- the bottom window has an effective Preset
\r
274 Row Scan value of 0.
\r
275 <BR> The Line Compare field in
\r
276 the VGA, of which bit 9 is in the <A HREF="crtcreg.htm#09">Maximum Scan
\r
277 Line Register</A>, bit 8 is in the <A HREF="crtcreg.htm#07">Overflow Register</A>,
\r
278 and bits 7-0 are in the <A HREF="crtcreg.htm#18">Line Compare Register</A>,
\r
279 specifies the scan line address of the horizontal division. When the line
\r
280 counter reaches the value in the Line Compare Register, the current scan
\r
281 line start address is reset to 0. If the <A HREF="attrreg.htm#10">Pixel
\r
282 Panning Mode</A> field is set to 1 then the <A HREF="attrreg.htm#13">Pixel
\r
283 Shift Count</A> and <A HREF="crtcreg.htm#08">Byte Panning</A> fields are
\r
284 reset to 0 for the remainder of the display cycle allowing the top window
\r
285 to pan while the bottom window remains fixed. Otherwise, both windows pan
\r
286 by the same amount.
\r
289 <P>Notice: All trademarks used or referred to on this page are the property
\r
290 of their respective owners.
\r
291 <BR>All pages are Copyright © 1997, 1998, J. D. Neal, except where
\r
292 noted. Permission for utilization and distribution is subject to the terms
\r
293 of the <A HREF="license.htm">FreeVGA Project Copyright License</A>.
\r