delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/03/18:56:42

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: 2 graphics questions
Date: Mon, 3 Feb 1997 19:38:10 +0000
Organization: None
Distribution: world
Message-ID: <md4agBAi6j9yEwsX@talula.demon.co.uk>
References: <01bc0fa6$3d6be440$5357f8ce AT 698130>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 63
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ian Mausolus writes:
>What is that vertical retrace stuff all about?  Do you actaully have to
>check to see if the video card or monitor is finished drawing to the screen
>before displaying another picture?  and how do you do that?

The retrace is the period when the electron beam in your monitor has
finished scanning one image onto the screen, and is moving back to the
top of the monitor ready to display another frame. How often this
happens depends on the video mode: it's 70 times a second in VGA
320x200, 60 times a second in mode-X 320x240, and varies somewhere
between 60 and 90 in most SVGA modes.

There is no reason why you have to wait for this period before you draw
to the screen (unless you are programming on a CGA, which is hardly an
issue these days :-) but you do need to synchronise with it before you
change the palette registers or do any hardware scrolling. In the case
of the palette, it is because most cards can't read and write the
palette registers at the same time. If you write to them while the
electron beam is scanning an image onto the screen, for a few pixels the
hardware is unable to read the correct colors from the palette, so it
displays a couple of garbage pixels, resulting in a nasty flicker called
"snow".

When you are doing hardware scrolling, the problem is that the VGA only
reads the address start registers at the top of the screen, so if you
change them partway through a scan, the change doesn't take effect until
the next retrace. This is a bad thing if you are doing page flipping,
since you may think you have flipped pages and thus reuse the old page
for a new image, but the hardware is still actually displaying the old
page so your temporary scribblings are visible to the user...

If you aren't changing the palette or doing hardware scrolling, you
might still want to synchronise with the retrace is to prevent shearing
artifacts, but this is only rarely a problem. Image a simple animation
of a vertical line moving horizontally across the screen, shifting by a
pixel every 70'th of a second. If you move it in sync with the retrace,
it will move completely smoothly. If you move it exactly 140'th of a
second _after_ the retrace, the electron beam will scan the top half of
the image while it is in the old position, and the bottom half after you
have moved it to the new position, so the line will have a split half
way down the screen. It can look even worse if your update isn't going
at exactly the same speed as the retrace, as your code will gradually
move in and out of sync with the hardware, causing the shear line to
move up and down the screen...

>Also, how can you do page flipping w/out using a VESA interrupt function?

Depends on the video mode. If you are using mode-X, write to the VGA
video address registers (port 0x3D4, registers 0x0C and 0x0D). In SVGA
modes it is normally done by using these registers for the low 16 bits
of the address, and sending the high bits to some other chip-specific
register. This means either writing different code for every single
chipset (and there are hundreds around!) or using VESA functions. If you
are worried about the overhead of calling the scroll interrupt (0x4F07),
you can use the VBE 2.0 function 0x4F0A to obtain a protected mode bank
switch routine, which can be copied into your address space and then
called directly. Look on SciTech's web page for a copy of the VBE
spec...

/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
 */

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019