VGA timing

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

VGA timing

Post by Jezze »

Hi,

I started looking at the values for VGA CRT timings. When I look at the wiki here http://wiki.osdev.org/VGA_Hardware I found that for instance mode13h has these values for the CRT:

Code: Select all

0x5F
0x4F
0x50
0x82
0x54
0x80
0xBF
0x1F
0x00
0x41
0x9C
0x8E
0x8F
0x28
0x40
0x96
0xB9
0xA3
Now I'm trying to figure these out by looking at the video signal and timings wiki page found here: http://wiki.osdev.org/Video_Signals_And_Timing

But I can not really figure them out because no matter how I twist and turn they don't seem to match. Anyone can tell me how to exactly calculate these?
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: VGA timing

Post by Combuster »

There are a fair number of conversion steps to be taken in this process:

- Choose desired width and height and refresh rate
- (see VGA timings) Determine overscan, blank and retrace times and pixel clocks (from established timings, GTF, or its successors)
- (see VGA hardware) In the case of GTF, ask the device for the closest pixel clock, which is either 25MHz or 28MHz for a VGA
- (see VGA timings) In the case of GTF, Determine a new set of blank and retrace times to make sure it works with the actual pixel clock
- (see DDC or ignore at your hardware's peril) Check if the vertical and horizontal refresh are appropriate for the screen
- (see VGA hardware) convert the resolution, blanks and overscans to register values
- (see VGA Hardware) disable display, write settings, enable display

The VGA is an 8-bit device, so it won't easily store numbers like 640 or 480, but rather has shifted and precalculated versions of those values that are more useful to the internal circuitry. As in, a width of 0 is not meaningful so it's reused to mean "one". Thus, 4F (79) actually means 50 groups (80), shift it by 3 bits (multiply by byte size) to get 280 (= 640 decimal = pixels wide, see?).

The VGA hardware page does have a short description as to how the resolution/blank/retrace registers correspond to actual timings, but it's essentially documented the wrong way around. My OS has an implementation for the process in the other direction, but it takes a few more things into account than the most basic model. Essentially, it performs the last two steps of the sequence.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply