www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/02/22/15:34:04

Date: Mon, 22 Feb 93 14:15:16 CST
From: (csaba AT vuse DOT vanderbilt DOT edu) <csaba AT vuse DOT vanderbilt DOT edu>
To: dmb AT case DOT ai DOT mit DOT edu
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Replacing arbitrary interrupt handlers

On Mon, 22 Feb 93 13:42:30 -0500,
  David Baggett writes:

>
>A while back I asked how to intercept the timer interrupt from within a
>DJGCC program, and several people pointed me to the source to gcrt0.o.
>(Thanks!)
>
>I've successfully inserted my own timer interrupt that chains properly
>in my program, but I still have a few questions.  (BTW, I'm using v108
>and not v109 since the timer code doesn't work with v109.)
>
>1. In my timer interrupt I just update a global counter.  I run my
>   interrupt at 5 times the normal rate and then chain to the old
>   vector every 5th time to keep things kosher for DOS.  However, it
>   seems that if I busy wait on the timer variable it doesn't get
>   updated!  E.g., the code
>
> for (;;) {
>  if (ticks > 100)
>   break;
> }
>
>   never ends.  I know the variable is getting updated properly because
>   if I do
>
> for (;;) {
>  vsync(); /* wait for vertical blank */
>
>  if (ticks > 100)
>   break;
> }
>
>   it does terminate.  (vsync() just polls the VGA card to see if the
>   vblank bit is set).
>
>   Does anyone have any clue why this might be happening?  (It seems
>   awfully bizarre to me.)
>
>2. The code that steals the timer interrupt seems to be specific to
>   go32.  Is there any way I can steal other vectors?  I need to grab
>   the "terminate addresss" vector (called by DOS when the program
>   terminates) and the mouse movement interrupt in particular.  I'd
>   like to be able to do this without hacking go32.  Is it possible?
>   (BTW, I don't care how disgusting the process is, as long as I can
>   get something working. :)
>
>Thanks!
>
>Dave Baggett
>dmb AT ai DOT mit DOT edu

Just one idea:

Try declaring the 'ticks' variable as 'volatile'. Without this GCC's 
optimizer could copy the variable into a register before the loop and use 
the copy afterwards. The second example works because calling 'vsync' 
(actually any function) inside the loop will force the reloading of 'ticks' 
in every iteration. This is because the compiler cannot predict all 
possible side effects of the called function. 


Csaba Biegl
csaba AT vuse DOT vanderbilt DOT edu

- Raw text -


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