www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/19/16:49:26

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Mouse Callback function using Allegro 3.0
Date: Tue, 19 May 1998 21:07:04 +0100
Organization: None
Message-ID: <bzQxWIAoZeY1Ewsj@talula.demon.co.uk>
References: <355fcc53 DOT 30849407 AT news DOT sas DOT shaw DOT wave DOT ca>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 45
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

(anon) writes:
>volatile struct evrev {
>  int mev,x,y;
>} events[50];
>volatile int nev=0;
>
>void mouseCB( int mev)
>{
>  events[nev].mev=mev;
>  events[nev].x=mouse_x;
>  events[nev].y=mouse_y;
>  nev++;
>}
[snip]
>      while(nev>0)
>        {
>          disable();
>          sprintf(s,"event %i",nev);
>          textout(screen,font,s,events[nev].x,events[nev].y,15);
>          nev--;
>          enable();
>        }

Are you sure that you really want this structure to be a stack? A
circular FIFO buffer would make more sense, so that the mouse events
will be processed in the same order that they occur.

More seriously, what happens when your stack overflows? The handler
never checks for this, and a lot of mouse movement interrupts can occur
over a very short space of time.

Final niggle: I don't recommend just disabling interrupts and then
assuming that the data will be unable to change while you are reading
it. I'm not even sure that you can count on this working reliably (if
the mouse driver is being virtualised by something like win95, it might
not respect the interrupt settings for the current DOS session), but in
any case that isn't a very polite thing to do to your machine. If you
set up a circular buffer and take care to update the start and end
pointers in a sensible order, it is possible to read data without ever
needing to mess with the interrupt settings.


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Miracles are nothing if you've got the wrong intentions" - Mike Keneally

- Raw text -


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