Specifications.
[pintos-anon] / specs / freevga / vga / vgacrtc.htm
diff --git a/specs/freevga/vga/vgacrtc.htm b/specs/freevga/vga/vgacrtc.htm
new file mode 100644 (file)
index 0000000..71c5b7a
--- /dev/null
@@ -0,0 +1,210 @@
+<HTML>
+<HEAD>
+   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
+   <META NAME="Author" CONTENT="Joshua Neal">
+   <META NAME="Description" CONTENT="Pure VGA/SVGA hardware programming (registers, identification, and otherlow-level stuff.)">
+   <META NAME="KeyWords" CONTENT="VGA SVGA hardware video programming">
+   <TITLE>FreeVGA - VGA Display Generation</TITLE>
+</HEAD>
+<BODY>
+
+<CENTER><A HREF="../home.htm">Home</A> <A HREF="#intro">Intro</A> <A HREF="#clocks">Clocks</A>
+<A HREF="#horiz">Horizontal</A> <A HREF="#vert">Vertical</A> <A HREF="#monitor">Monitoring</A>
+<A HREF="#misc">Misc</A> <A HREF="vga.htm#general">Back</A>&nbsp;
+<HR><B>Hardware Level VGA and SVGA Video Programming Information Page</B></CENTER>
+
+<CENTER>VGA Display Generation&nbsp;
+<HR></CENTER>
+<A NAME="intro"></A><B>Introduction</B>
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This page documents the
+configuration of the VGA's CRTC registers which control the framing and
+timing of video signals sent to the display device, usually a monitor.
+
+<P><A NAME="clocks"></A><B>Dot Clocks</B>
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The standard VGA has two
+"standard" dot clock frequencies available to it, as well as a possible
+"external" clock source, which is implementation dependent.&nbsp; The two
+standard clock frequencies are nominally 25 Mhz and 28 MHz.&nbsp; Some
+chipsets use 25.000 MHz and 28.000 MHz, while others use slightly greater
+clock frequencies.&nbsp; The IBM VGA chipset I have uses 25.1750 MHz&nbsp;
+Mhz and 28.3220 crystals.&nbsp; Some newer cards use the closest generated
+frequency produced by their clock chip.&nbsp; In most circumstances the
+IBM VGA timings can be assumed as the monitor should allow an amount of
+variance; however, if you know the actual frequencies used you should use
+them in your timing calculations.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The dot clock source in
+the VGA hardware is selected using the <A HREF="extreg.htm#3CCR3C2W">Clock
+Select</A> field.&nbsp; For the VGA, two of the values are undefined; some
+SVGA chipsets use the undefined values for clock frequencies used for 132
+column mode and such.&nbsp; The 25 MHz clock is designed for 320 and 640
+pixel modes and the 28 MHz is designed for 360 and 720 pixel modes. The
+<A HREF="seqreg.htm#01">Dot Clock Rate</A> field specifies whether to use
+the dot clock source directly or to divide it in half before using it as
+the actual dot clock rate.
+
+<P><A NAME="horiz"></A><B>Horizontal Timing</B>
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The VGA measures horizontal
+timing periods in terms of character clocks, which can either be 8 or 9
+dot clocks, as specified by the <A HREF="seqreg.htm#01">9/8 Dot Mode</A>
+field.&nbsp; The 9 dot clock mode was included for monochrome emulation
+and 9-dot wide character modes, and can be used to provide 360 and 720
+pixel wide modes that work on all standard VGA monitors, when combined
+with a 28 Mhz dot clock. The VGA uses a horizontal character counter which
+is incremented at each character, which the horizontal timing circuitry
+compares against the values of the horizontal timing fields to control
+the horizontal state. The horizontal periods that are controlled are the
+active display, overscan, blanking, and refresh periods.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The start of the active
+display period coincides with the resetting of the horizontal character
+counter, thus is fixed at zero.&nbsp; The value at which the horizontal
+character is reset is controlled by the <A HREF="crtcreg.htm#00">Horizontal
+Total</A> field. Note, however, that the value programmed into the <A HREF="crtcreg.htm#00">Horizontal
+Total</A> field is actually 5 less than the actual value due to timing
+concerns.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The end of the active display
+period is controlled by the <A HREF="crtcreg.htm#01">End Horizontal Display</A>
+field.&nbsp; When the horizontal character counter is equal to the value
+of this field, the sequencer begins outputting the color specified by the
+<A HREF="attrreg.htm#11">Overscan Palette Index</A> field.&nbsp; This continues
+until the active display begins at the beginning of the next scan line
+when the active display begins again.&nbsp; Note that the horizontal blanking
+takes precedence over the sequencer and attribute controller.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The horizontal blanking
+period begins when the character clock equals the value of the <A HREF="crtcreg.htm#02">Start
+Horizontal Blanking</A> field.&nbsp; During the horizontal blanking period,
+the output voltages of the DAC signal the monitor to turn off the guns.&nbsp;&nbsp;
+Under normal conditions, this prevents the overscan color from being displayed
+during the horizontal retrace period.&nbsp; This period extends until the
+lower 6 bits of the <A HREF="crtcreg.htm#03">End Horizontal Blanking</A>
+field match the lower 6 bits of the horizontal character counter.&nbsp;
+This allows for a blanking period from 1 to 64 character clocks, although
+some implementations may treat 64 as 0 character clocks in length.&nbsp;
+The blanking period may occur anywhere in the scan line, active display
+or otherwise even though its meant to appear outside the active display
+period.&nbsp; It takes precedence over all other VGA output.&nbsp; There
+is also no requirement that blanking occur at all.&nbsp; If the <A HREF="crtcreg.htm#02">Start
+Horizontal Blanking</A> field falls outside the maximum value of the character
+clock determined by the <A HREF="crtcreg.htm#00">Horizontal Total</A> field,
+then no blanking will occur at all.&nbsp; Note that due to the setting
+of the <A HREF="crtcreg.htm#00">Horizontal Total</A> field, the first match
+for the <A HREF="crtcreg.htm#03">End Horizontal Blanking</A> field may
+be on the following scan line.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Similar to the horizontal
+blanking period, the horizontal retrace period is specified by the <A HREF="crtcreg.htm#04">Start
+Horizontal Retrace</A> and <A HREF="crtcreg.htm#05">End Horizontal Retrace</A>
+fields. The horizontal retrace period begins when the character clock equals
+the value stored in the <A HREF="crtcreg.htm#04">Start Horizontal Retrace</A>
+field.&nbsp; The horizontal retrace ends when the lower 5 bits of the character
+clock match the bit pattern stored in the <A HREF="crtcreg.htm#05">End
+Horizontal Retrace</A> field, allowing a retrace period from 1 to 32 clocks;
+however, a particular implementation may treat 32 clocks as zero clocks
+in length.&nbsp; The operation of this is identical to that of the horizontal
+blanking mechanism with the exception of being a 5 bit comparison instead
+of 6, and affecting the horizontal retrace signal instead of the horizontal
+blanking.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There are two horizontal
+timing fields that are described as being related to internal timings of
+the VGA, the <A HREF="crtcreg.htm#03">Display Enable Skew</A> and <A HREF="crtcreg.htm#05">Horizontal
+Retrace Skew</A> fields.&nbsp; In the VGA they do seem to affect the timing,
+but also do not seem to be necessary for the operation of the VGA and are
+pretty much unused.&nbsp; These registers were required by the IBM VGA
+implementations, so I'm assuming this was added in the early stages of
+the VGA design for EGA compatibility, but the internal timings were changed
+to more friendly ones making the use of these fields unnecessary.&nbsp;
+It seems to be totally safe to set these fields to 0 and ignore them.&nbsp;
+See the register descriptions for more details, if you have to deal with
+software that programs them.
+
+<P><A NAME="vert"></A><B>Vertical Timing</B>
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The VGA maintains a scanline
+counter which is used to measure vertical timing periods.&nbsp; This counter
+begins at zero which coincides with the first scan line of the active display.&nbsp;
+This counter is set to zero before the beginning of the first scanline
+of the active display.&nbsp; Depending on the setting of the <A HREF="crtcreg.htm#17">Divide
+Scan Line Clock by 2</A> field, this counter is incremented either every
+scanline, or every second scanline.&nbsp; The vertical scanline counter
+is incremented before the beginning of each horizontal scan line, as all
+of the VGA's vertical timing values are measured at the beginning of the
+scan line, after the counter has ben set/incremented.&nbsp; The maximum
+value of the scanline counter is specified by the <A HREF="crtcreg.htm#06">Vertical
+Total</A> field.&nbsp; Note that, like the rest of the vertical timing
+values that "overflow" an 8-bit register, the most significant bits are
+located in the <A HREF="crtcreg.htm#07">Overflow Register</A>.&nbsp; The
+<A HREF="crtcreg.htm#06">Vertical Total</A> field is programmed with the
+value of the scanline counter at the beginning of the last scanline.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The vertical active display
+period begins when the scanline counter is at zero, and extends up to the
+value specified by the <A HREF="crtcreg.htm#12">Vertical Display End</A>
+field.&nbsp; This field is set with the value of the scanline counter at
+the beginning of the first inactive scanline, telling the video hardware
+when to stop outputting scanlines of sequenced pixel data and outputs the
+attribute specified by the <A HREF="attrreg.htm#11">Overscan Palette Index</A>
+field in the horizontal active display period of those scanlines.&nbsp;
+This continues until the start of the next frame when the active display
+begins again.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The <A HREF="crtcreg.htm#15">Start
+Vertical Blanking</A> and <A HREF="crtcreg.htm#16">End Vertical Blanking</A>
+fields control the vertical blanking interval.&nbsp; The <A HREF="crtcreg.htm#15">Start
+Vertical Blanking</A> field is programmed with the value of the scanline
+counter at the beginning of the scanline to begin blanking at.&nbsp; The
+value of the <A HREF="crtcreg.htm#16">End Vertical Blanking</A> field is
+set to the lower eight bits of the scanline counter at the beginning of
+the scanline after the last scanline of vertical blanking.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The <A HREF="crtcreg.htm#10">Vertical
+Retrace Start</A> and <A HREF="crtcreg.htm#11">Vertical Retrace End</A>
+fields determine the length of the vertical retrace interval.&nbsp; The
+<A HREF="crtcreg.htm#10">Vertical Retrace Start</A> field contains the
+value of the scanline counter at the beginning of the first scanline where
+the vertical retrace signal is asserted.&nbsp; The <A HREF="crtcreg.htm#11">Vertical
+Retrace End</A> field is programmed with the value of the lower four bits
+of the scanline counter at the beginning of the scanline after the last
+scanline where the vertical retrace signal is asserted.
+
+<P><A NAME="monitor"></A><B>Monitoring Timing</B>
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There are certain operations
+that should be performed during certain periods of the display cycle to
+minimize visual artifacts, such as attribute and DAC writes.&nbsp; There
+are two bit fields that return the current state of the VGA, the <A HREF="extreg.htm#3xAR">Display
+Disabled</A> and <A HREF="extreg.htm#3xAR">Vertical Retrace</A> fields.
+The <A HREF="extreg.htm#3xAR">Display Disabled</A> field is set to 1 when
+the display enable signal is not asserted, providing the programmer with
+a means to determine if the video hardware is currently refreshing the
+active display or it is currently outputting blanking.
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The <A HREF="extreg.htm#3xAR">Vertical
+Retrace</A> field signals whether or not the VGA is in a vertical retrace
+period.&nbsp; This is useful for determining the end of a display period,
+which can be used by applications that need to update the display every
+period such as when doing animation.&nbsp; Under normal conditions, when
+the blanking signal is asserted during the entire vertical retrace, this
+can also be used to detect this period of blanking, such that a large amount
+of register accesses can be performed, such as reloading the complete set
+of DAC entries.
+
+<P><A NAME="misc"></A><B>Miscellaneous</B>
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There are a few registers
+that affect display generation, but don't fit neatly into the horizontal
+or vertical timing categories.&nbsp; The first is the <A HREF="crtcreg.htm#17">Sync
+Enable</A> field which controls whether the horizontal and vertical sync
+signals are sent to the display or masked off.&nbsp; The sync signals should
+be disabled while setting up a new mode to ensure that an improper signal
+that could damage the display is not being output.&nbsp; Keeping the sync
+disabled for a period of one or more frames helps the display determine
+that a mode change has occurred as well.
+<BR>&nbsp;&nbsp;&nbsp; The <A HREF="crtcreg.htm#11">Memory Refresh Bandwidth</A>
+field is used by the original IBM VGA hardware and some compatible VGA/SVGA
+chipsets to control how often the display memory is refreshed.&nbsp; This
+field controls whether the VGA hardware provides 3 or 5 memory refresh
+cycles per scanline.&nbsp; At or above VGA horizontal refresh rates, this
+field should be programmed for 3 memory refresh cycles per scanline.&nbsp;
+Below this rate, for compatibility's sake the 5 memory refresh cycles per
+scanline setting might be safer, see the <A HREF="crtcreg.htm#11">Memory
+Refresh Bandwidth</A> field for (slightly) more information.
+
+<P>&nbsp;
+<BR>Notice: All trademarks used or referred to on this page are the property
+of their respective owners.
+<BR>All pages are Copyright &copy; 1997, 1998, J. D. Neal, except where
+noted. Permission for utilization and distribution is subject to the terms
+of the <A HREF="license.htm">FreeVGA Project Copyright License</A>.
+</BODY>
+</HTML>