OSD Home
Graphics in pmode
'How do I enable graphics from protected mode?'
- You don't. Graphics programming is fun, but graphics are
hardly essential for an OS. Don't get side-tracked.
- Call the BIOS mode-set interrupt in the 16-bit boot code,
before the pmode kernel starts.
- Use protected-mode code to program the VGA directly, without
using the BIOS. This works only with VGA-compatible video boards
and VGA-compatible video modes.
- Add a virtual 8086 mode monitor (VMM) to your OS. Call the
BIOS mode-set interrupt in virtual 8086 mode.
- Switch from pmode to real mode, call the BIOS mode-set interrupt in
real mode, then return to pmode.
- Write a protected-mode driver specifically for the SVGA chip
used in your video board. Someone else who wants to use your OS must have
the same video board (or they must write a new driver for their own video
board).
- Call VBE 3.x BIOS functions in 16-bit protected mode. VBE 3.x is
supported only by very new video cards.
Video timing
- Dot clock (pixel clock)
- Character clock = dot clock divided by 8 or 9
- Horizontal sync (retrace) frequency = character clock / horizontal total
- Horizontal total / horizontal displayed ~ 1.2 (20% overscan)
- Vertical sync (retrace) frequency = horizontal sync frequency / vertical total
- Vertical total / vertical displayed ~ 1.1 (10% overscan)
VGA
- INT 10h VGA BIOS interrupts which work in real or virtual-8086
mode only, to set mode, change font, etc.
- Dot clock is one of: 28.35, 25.2, 14.175, or 12.6 MHz
- Character clock is dot clock divided by 8 or 9
- Horizontal sync frequency for very old VGA monitors is always
31.5 kHz. Other frequencies can be produced by the VGA board and
are supported by newer SVGA monitors.
- Vertical sync frequency for very old VGA monitors is always 60 or
70 Hz. Other frequencies can be produced by the VGA board and are
supported by newer SVGA monitors.
- No interlace. No video memory 'banks'. No color depth > 8.
Only 256K usable video memory max.
- Four memory planes, 64K each: P1, P2, P4, and P8
- Text: characters occupy even bytes in plane P1, attributes
occupy odd bytes in plane P2, fonts are in plane P4. Text mode uses
Even/Odd addressing: bit b0 of
address selects between planes P1 and P2, so you need not change
planes to set the attributes.
- 4-color (CGA) graphics: 4 pixels per byte; uses planes P1 and P2.
As with text, Even/Odd addressing eliminates the need to switch planes.
- 16-color graphics: four monochrome planes: blue, green, red,
and intense (the 16- and 256-color palettes can be re-defined to give
you any 16 colors you want). Highest graphics resolution available with
plain VGA, but very difficult to write software for this mode.
- 256-color graphics: one byte per pixel. Simple software, but low
resolution with plain VGA. All four planes are used with Chain-4
addressing: bits b0 and b1 of the address select the plane so you need not
worry about it. Mode-X is unchained 256-color mode:
difficult to program, but it lets you use up to 256K video memory for
256-color modes up to 360x480 resolution.
Super VGA (SVGA)
- INT 10h AH=4Fh BIOS interrupts (VESA BIOS extensions; VBE). VBE 1.x
runs in real or virtual-8086 mode only. VBE 2.x has a few
not-too-useful pmode functions. For VBE 3.x, most functions (including
mode-set) are carefully written to work in real mode or 16-bit
protected mode.
- More than 256K video memory
- SVGA boards support many dot clock frequencies. SVGA monitors
support many sync frequencies.
- 16-bit SVGA, VBE 1.x BIOS: video memory accessible one 64K 'bank' at
a time. Paging can be used to simulate a linear framebuffer, but
there are some 'gotchas' with this method (see links below)
- 32-bit SVGA, VBE 2.x or 3.x BIOS: Linear framebuffer for
video memory -- no banks or planes, but video memory is no longer at A000:0000
Code snippets
VGA graphics demo. Pixels, rectangular fill,
horizontal and vertical lines, and text blitting in 5 different
graphics modes.
Set text or graphics video modes (including text font)
without using the BIOS
Simple V86 mode monitor;
calls 16-bit video BIOS from 32-bit pmode.
Links
Tauron VGA utilities:
http://alexfru.narod.ru/miscdocs/ega_vga/tauron30.zip
Finn Thøgersen's VGADOC:
http://home.worldonline.dk/finth/
Simulated linear framebuffer:
TO DO
(S)VGA functional units:
- Miscellaneous register
- Sequencer (SEQ)
- In unchained modes, SEQ register 2 selects one
(or more!) planes to write
- CRT Controller (CRTC)
- Graphics Controller (GC)
- In unchained modes, GC register 4 selects a plane to read
- Attribute Controller (AC)
- 16-color palette in first 16 registers of AC
- 256-color palette (DAC)
Gotchas:
- 'Lock' bits in CRTC registers 3 and 17
- Screwy CGA addressing (disabled by bit b0 in CRTC register 23)
- Palette is not compact, i.e. for the 16-color palette
entry[i] != i