Creating a Modeline

The key to X video modes lies in the modeline, which may reside in either the Monitor section of XF86Config (in which case it applies to just one monitor) or in a separate Modes section (in which case any monitor can use it). A typical modeline looks like

Modeline "1024x768" 98.9 1024 1056 1216 1408 768 782 788 822 -HSync -VSync

The first line is a comment that describes the effect of the modeline—in this case, it creates a 1024 x 768 display at 85Hz, which is a common video mode. The second line is the modeline itself, and it's broken up into several parts:

Modeline Every modeline begins with this keyword. An alternative form uses the keyword Mode and breaks the entry across multiple lines. This form is more readable but less common than the single-line Modeline entry.

Modeline Name The modeline name appears in quotes—"1024x768" in this example. Modelines are typically named after the resolution they create, sometimes with a refresh rate appended, as in "[email protected]". You refer to the modeline by name in the Modes line in the Screen section. If two modelines have the same name, X uses the one that produces the maximum refresh rate, within your monitor's limits, as defined by the HorizSync and VertRefresh values in the Monitor section, and your video card's maximum dot clock.

Dot Clock The number after the modeline name (98.9 in this example) is the dot clock. This number is a measure of the rate of data flow through the video card when using the mode. All video cards have maximum supported dot clocks, and if a modeline exceeds this value, X won't use it.

Horizontal Timings The next four numbers of the modeline (1024 1056 1216 1408 in this example) represent the horizontal timings for the video mode. The first number is the number of pixels in the actual display. The next three numbers represent the start, stop, and total number of pulses sent to create a single horizontal line of the display.

Vertical Timings The next four numbers of the modeline (768 782 788 822 in this example) are analogous to the horizontal timings, but they provide vertical timing information. The first number is the vertical resolution and the next three numbers provide start, stop, and totals for vertical timing pulses.

Miscellaneous Flags The modeline may include some miscellaneous flags, such as -HSync -VSync in this example. These particular flags tell XFree86 what polarity to use for the horizontal and vertical sync signals. Other common flags include Interlace (to set an interlaced video mode), DoubleScan (to set a mode in which every scan line is doubled), and Composite (to set composite sync). As a general rule, you shouldn't worry about these flags unless you're intimately familiar with your video hardware.

Creating a modeline by hand is a tedious proposition at best and involves crunching through numbers to create the desired timings and dot clock value. Fortunately, there are tools to help you do the job. One of these is the XFree86 Modeline Generator web page, http://xtiming.sourceforge.net, which is shown in Figure 16.6.

Figure 16.6: The XFree86 Modeline Generator page performs the tedious calculations required to create a custom video mode.

To use this tool, you need several pieces of information:

Monitor's Refresh Rates These values are the ones provided on the HorizSync and VertRefresh lines in XF86Config. You need four numbers in total: the minimum and maximum for both horizontal and vertical timings.

Video Card's Maximum Dot Clock The page needs to know the maximum dot clock value your video card can handle. To learn what your video hardware's maximum dot clock is, shut down X and type X -probeonly &> probe.txt and then peruse the probe.txt file for a line that specifies the maximum clock rate, such as Maximum clock: 199 MHz or PixClock max 80Mhz. Some systems place this information in a log file, such as /var/log/XFree86.0.log. Be sure to run the test with the video card connected to the monitor you intend to use; some configurations report the maximum dot clock the monitor can handle.

Desired Resolution You may already know what resolution you want to use. Alternatively, you can provide your target refresh rate and let the tool compute the maximum resolution your system will support.

Desired Overall Refresh Rate You may already know your target refresh rate. This value must be somewhere between the monitor's minimum and maximum refresh rates, but depending on your resolution, it's possible that your monitor won't be able to support anywhere near the high value of the VertRefresh range. Alternatively, if you know the resolution you want to support, you can have the tool compute the maximum refresh rate your hardware will support.

Once you have this information, enter it into the fields in the XFree86 Modeline Generator web page. You must enter values for all five fields in the Monitor Configuration area. In the Basic Configuration area, you can enter values for the Visible Resolution, Refresh Rate, or both. If you leave any value set at 0, the system computes the optimum value given other constraints. The lower half of the Basic Configuration area (not visible in Figure 16.6) provides some additional options. For instance, you can tell the system to constrain your aspect ratio to 4:3, 16:9, or some other ratio, to produce square pixels on common monitor sizes; and you can tell it to create an interlaced video mode. When you're done, scroll to the bottom of the page and click the Calculate Modeline button. The page refreshes, but this time it displays your custom modeline at the top. For instance, when I entered horizontal sync rates of 27 through 115, vertical refresh rates of 50 through 160, a maximum dot clock of 230, a desired refresh rate of 100Hz, and a 4:3 aspect ratio constraint, the system spat out the following modeline:

Modeline "[email protected]" 230.00 1296 1328 2200 2232 972 988 1004 1021

Experience with your monitor might enable you to further tweak this modeline, but doing so requires experimentation. For instance, the system whose specifications I entered to create this modeline is the one I mentioned earlier, which runs at 1360 x 1024 with a 105Hz refresh rate—better than the modeline created by the web page. Creating this modeline took several hours of experimentation, though. If you're interested in such fine-tuning, consult the XFree86 Video Timings HOWTO (http://tldp.org/HOWTO/XFree86-Video-Timings-HOWTO/). Note that this HOWTO claims it's now obsolete except for certain limited situations. In my experience, though, XFree86 often doesn't optimize video modes as well as a person can, even when those conditions don't apply.

0 0

Post a comment