delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/25/07:00:22

From: Shawn Hargreaves <shawn AT talula DOT demon DOT co DOT uk>
To: djgpp AT delorie DOT com
MMDF-Warning: Parse error in original version of preceding line at relay-7.mail.demon.net
Subject: Re: timer interrupt - sample code anyone?
Date: Fri, 25 Apr 1997 10:21:42 +0100
MIME-Version: 1.0
Message-ID: <861961290.0526444.0@[194.129.18.166]>

Roger Noss writes: 
> > tgrand AT canvaslink DOT com wrote:
> > Then there is a function called _vga_vsync(), which simply calls
> > _vsync_out() and then _vsync_in().  So I think this is how Allegro is
> > waiting until the monitor has finished drawing a frame... (at least in
> > VGA mode anyway.)

Allegro defines the vsync() point as the exact start of a retrace, not just
any point within it (otherwise it could return, making you think you were
in a retrace, when in fact the retrace period was nearly finished so you
wouldn't have time to do any lengthy operations like modifying the
palette).
To do this, vsync() waits first for you not to be in a retrace and then for
you
to be in a retrace: this ensures it will return exactly at the leading edge
of the blanking period...

> The Allegro web pages also discuss some "vertical retrace emulator" which
> may be built on these functions.  I'm not sure what exactly the emulator
> does, 

The retrace emulator works by programming the timer chip to generate an
interrupt in sync with the retrace. It does this by measuring the retrace
rate,
setting the timer to fire an interrupt slightly before the next retrace is
due,
and then polling the retrace port inside the interrupt handler to make sure
it stays exactly in sync with the monitor. The benefit of this approach is
that 
you can go off and do other stuff in your mainline code, and be notified by
an interrupt when the next retrace occurs, rather than having to just sit
around in a loop polling the status bits. Also, it reduces the chances of
missing retraces due to other things (in particular soundcard interrupts)
getting in the way...

> and I want the actual retrace, not just an emulated one.  Anyway, the

The Allegro emulator routines will give you the exact time of the hardware
retrace. I describe the technique as 'emulation' because it is using an
unrelated bit of hardware (the timer chip) to generate the interrupts,
rather 
than them coming directly from the video board. That's a pity, but since
most VGA boards don't support interrupts on retrace, the only other way
to detect it is with a polling vysnc() type function (fine for many
purposes,
but there are times when an interrupt is much more convenient).

> web page for it says that it won't work in Win95.  My rule of thumb is,
if
> not Win95, then probably not NT.

Very true. The reason it doesn't work under such systems is that the
technique
depends on split-second timing (the clock chip has to be constantly
reprogrammed to stay in sync with the video board), and I don't know of any
multitasking OS that is good enough at emulating the PIT for this to
work...

> I have no way of knowing what NT is doing.  I also posted a puzzling test
of
> uclock() which suggests that NT is stealing resources at about 10 ms per
> call, but there has been no response on the list.  My intuition is that
NT
> must let port reads go through or it would be very difficult to write
device
> drivers.

Rather the opposite: NT lets device drivers access the ports directly, but
the 
drivers are the only things that are allowed to do that. When a DOS prog
tries 
to touch hardware ports under NT, the device driver intercepts the
operation 
and usually tries to emulate the desired action. How well it does that
determines 
how well your program will work :-)

I've never tried NT, but my experience of Win95 is that it handles retraces
quite well, but the timer (and hence uclock()) very badly. It supports
programs
that speed up the clock (which is how Allegro gets 5 msec timing accuracy
under Win95), but doesn't handle reading the elapsed time (hence uclock()
will have errors of up to 18.2 of a second), and defers speed adjustments
until the tick after they are made (hence anything that tries to adjust the
timer on the fly, eg. the retrace syncing code in Allegro, isn't going to
work).


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk
"Beauty is a French phonetic corruption of a short cloth neck ornament"

- Raw text -


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