Mail Archives: djgpp/1998/05/19/16:49:26
(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 -