🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: rec.games.programmer
9 messages
9 total messages Started by Christopher David Miller Mon, 03 Aug 1992 23:32
Vertical Retrace interrupt?
#401
Author: Christopher David Miller
Date: Mon, 03 Aug 1992 23:32
5 lines
793 bytes
Hi, I'm new to VGA programming, and I want to know if it is possible to
detect the retrace with an interrupt, rather than polling for it.  I want to
use this so I can flip screens for animation every retrace - I think this is
how it's done?  If anyone has some source, I'd really appreciate it
Cheers,  Chris.
Re: Vertical Retrace interrupt?
#402
Author: sl8nl
Date: Tue, 04 Aug 1992 03:05
11 lines
908 bytes
> detect the retrace with an interrupt, rather than polling for it.  I want to
> use this so I can flip screens for animation every retrace - I think this is
> how it's done?  If anyone has some source, I'd really appreciate it

Question:  If you set the retrace up as an interrupt (possible...by modifying
the timer interrupt to run at 60 times a second), wouldn't you still have
to poll for it.  For instance, the polling code sets a flag to true for the
retrace.  Wouldn't you still have to poll for this flag the same way to
poll for the retrace?

Josh
Re: Vertical Retrace interrupt?
#406
Author: Peter SPHINX Cellik
Date: Tue, 04 Aug 1992 12:32
34 lines
2152 bytes
In article <1992Aug3.210504.57823@cc.usu.edu>, sl8nl@cc.usu.edu writes:
|> > detect the retrace with an interrupt, rather than polling for it.  I want to
|> > use this so I can flip screens for animation every retrace - I think this is
|> > how it's done?  If anyone has some source, I'd really appreciate it
|> 
|> Question:  If you set the retrace up as an interrupt (possible...by modifying
|> the timer interrupt to run at 60 times a second), wouldn't you still have
|> to poll for it.  For instance, the polling code sets a flag to true for the
|> retrace.  Wouldn't you still have to poll for this flag the same way to
|> poll for the retrace?
|> 
|> Josh

No Josh, your wrong.  Some VGA board create a vertical retrace interrupt
whenever they enter the retrace period.  A program would merely have to 
trap the interrupt to know when the retrace period is happening.  The 
program could carry on doing its own thing until it gets the interrupt,
then it can update the screen.  No polling required.
I don't think the timer interrupt trick would work, even though the 
interrupt could be generated 60Hz (or 70Hz), it still would not inform 
the program that it is a safe time to write to the VGA.

I have tried the retrace interrupt a little, without any real success,
an I would also like to know how to enable the retrace interrupt, and
how to signal to the VGA that the interrupt had been recieved.

     SPHINX


====================================================
=== Kill others only if you wish to be killed.   ===
===                                       SPHINX ===   
====================================================
Re: Vertical Retrace interrupt?
#503
Author: Khan
Date: Tue, 04 Aug 1992 15:17
15 lines
1279 bytes
In article <1992Aug3.233204.16778@cs.aukuni.ac.nz> cmil2@cs.aukuni.ac.nz (Christopher David   Miller         ) writes:
>Hi, I'm new to VGA programming, and I want to know if it is possible to
>detect the retrace with an interrupt, rather than polling for it.  I want to
>use this so I can flip screens for animation every retrace - I think this is
>how it's done?

EGA and up should be able to do this (I say SHOULD because apparently
some cards don't implement the retrace interrupt properly). I don't have
any source, but everything you need to know is contained in Richard
Wilton's Programmer's Guide to PC and PS/2 Video Systems. The source for
the examples in this book are floating around the net somewhere as
MSCVIDEO.ZIP (sorry, I don't know where exactly).

Hope this helps at least somewhat.
Re: Vertical Retrace interrupt?
#504
Author: Khan
Date: Tue, 04 Aug 1992 15:17
50 lines
3452 bytes
In article <1992Aug3.210504.57823@cc.usu.edu> sl8nl@cc.usu.edu writes:
>> detect the retrace with an interrupt, rather than polling for it.  I want to
>> use this so I can flip screens for animation every retrace - I think this is
>> how it's done?  If anyone has some source, I'd really appreciate it
>
>Question:  If you set the retrace up as an interrupt (possible...by modifying
>the timer interrupt to run at 60 times a second), wouldn't you still have
>to poll for it.  For instance, the polling code sets a flag to true for the
>retrace.  Wouldn't you still have to poll for this flag the same way to
>poll for the retrace?

First of all, you don't use the timer interrupt. Even if you COULD
program it for 60Hz (or 72Hz or whatever rate the mode/monitor is
using), there's no way you could synchronize the timer chip to the
display refresh cycle. And besides, the video card itself is capable of
generating an interrupt request at the start of the vertical retrace.

You set up an interrupt service routine (for INT 2, the interrupt
request level generated by the video card) which swaps display buffers.
When the vertical retrace starts, the ISR is called, and the display
buffers are swapped without any direct action on the part of the
program.

Potential pitfalls: retrace occurs every 60th of a second (varies
depending on video mode). If the animation is not "slaved" to the
retrace rate, some synchronization problems will result. For example:

Suppose it takes the program 1/30th of a second to draw one complete
frame of animation. Suppose the program is drawing on page 1 while page
0 is being displayed. 1/60th of a second later, page 1 is displayed and
page 0 becomes the active page for drawing. Since the frame is only half
drawn when the buffer swap occurs, you have half a frame drawn in one
display buffer and half in another. To solve this, you would put a flag
in an areas of memory shared by the ISR and the main program. If the
flag is set, then the ISR should flip pages and clear the flag; if the flag
is clear, the ISR should do nothing and return immediately. The drawing code
can then set the flag when it has finished drawing the current frame.

Another potential problem arises when a complete frame can be rendered in
less than 1/60th of a second. For the sake of argument, let's say the
code could sustain an animation rate of 120 frames per second. In this
situation, the program could potentially draw more than one frame during one
retrace period. This would result in frames of animation which were drawn but
never seen by the user (and thus wasted). Solution: the frame drawing code has
to set the retrace flag and then WAIT until the retrace has occurred
before starting to draw the next frame. This means the code ends up
polling the retrace flag, though not for the reason sl8nl mentions.

BTW, I should have such problems as too HIGH an animation rate... ;-)
Re: Vertical Retrace interrupt?
#417
Author: Stokes Kevin
Date: Wed, 05 Aug 1992 15:02
27 lines
1761 bytes
In article <1992Aug3.210504.57823@cc.usu.edu> sl8nl@cc.usu.edu writes:
> detect the retrace with an interrupt, rather than polling for it. 

>
>>Question:  If you set the retrace up as an interrupt (possible...by modifying
>>the timer interrupt to run at 60 times a second), wouldn't you still have

  I think the original posting was about the user of the VGA Card's hardware
interrupt, not the timer chip.  The timer chip wouldn't stay in phase with the
video retrace, and therefore wouldn't help.
  The VGA card does have an interrupt line which can be used for this, but I
wouldn't use it if you plan to distribute the program to others.  Since the
PC stupidly has so few interrupt lines, this line get used for all sorts of
other things.  Infact this video int is always disabled normally, and
I've never heard of a program that uses it.  I have a feeling that this would
be the kind of thing that would fail on about 1/2 the people's computers.
  Anyone else out there have any experience in this?

  I believe Micheal Abrash's book covers the use of the interrupt line,
certainly Ferraro's book would.

                                         -Kevin

-- 
	Kevin Stokes
	Duke University Dept. of Physics	kds@phy.duke.edu
	Durham, N.C.      27706			
Re: Vertical Retrace interrupt?
#418
Author: Matthew Smith
Date: Wed, 05 Aug 1992 15:29
18 lines
1295 bytes
In article <1992Aug3.233204.16778@cs.aukuni.ac.nz> cmil2@cs.aukuni.ac.nz (Christopher David   Miller         ) writes:
>Hi, I'm new to VGA programming, and I want to know if it is possible to
>detect the retrace with an interrupt, rather than polling for it.  I want to
>use this so I can flip screens for animation every retrace - I think this is
>how it's done?  If anyone has some source, I'd really appreciate it
>Cheers,  Chris.
>

That's kind of tricky.  Some video controllers generate an IRQ 2 whenever a 
vertical retrace begins.  However, some don't.  It's a hit and miss situation,
although, I do believe that most adapters made today *do* generate the 
interrupt.  It's those old ones you have to watch out for.


~
Matt Smith
msmith@peruvian.utah.edu
Student - University of Utah Department of Computer Science
Re: Vertical Retrace interrupt?
#421
Author: Matthew Smith
Date: Wed, 05 Aug 1992 15:38
17 lines
1259 bytes
In article <1992Aug3.233204.16778@cs.aukuni.ac.nz> cmil2@cs.aukuni.ac.nz (Christopher David   Miller         ) writes:
>Hi, I'm new to VGA programming, and I want to know if it is possible to
>detect the retrace with an interrupt, rather than polling for it.  I want to
>use this so I can flip screens for animation every retrace - I think this is
>how it's done?  If anyone has some source, I'd really appreciate it
>Cheers,  Chris.
>

You can program the majority of video cards to generate an IRQ 2 whenever a 
vertical retrace occurs.  However, some of the older cards don't support this
as well as they should (read: it won't work on some older cards).

e
l
Matt Smith
msmith@peruvian.utah.edu
Student - University of Utah Department of Computer Science
Re: Vertical Retrace interrupt?
#502
Author: Tomi H Engdahl
Date: Fri, 07 Aug 1992 19:23
27 lines
1764 bytes
In article <4284@news.duke.edu> kds@phy.duke.edu (Stokes Kevin) writes:

>  I think the original posting was about the user of the VGA Card's hardware
>interrupt, not the timer chip.  The timer chip wouldn't stay in phase with the
>video retrace, and therefore wouldn't help.

There is a way to keep timer interrupt in phase with VGA hardware.
First you measure the time between VGA retraces. Then set the timer
to one-shot mode and set the pulse time a little more shorter than 
interrupt period. Then set the original IRQ0 interrupt to your own interrupt
routine. The you just send start signal to timer, and the system syncs
to VGA vertical retrace in few frames.

The interrupt routine does following:

1. Wait for vertical retrace to start
2. Send the start timer period signal to timer
3. (put here your own code)
4. Return from interrupt routine

I have heard that this system has been implemented with only few per cent
processing time overhed.

--

Tomi.Engdahl@hut.fi            "Don't force it; get a larger hammer"
then@vipunen.hut.fi                        
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads