[comp.lang.pascal] Mouse event handler problem solved!

tswingle@oucsace.cs.ohiou.edu (Tom Swingle) (02/28/91)

Thanks to everyone who replied to my previous post about the problem I was 
having with writing an event handler for the mouse.  Here was the basic problem
that was before me, as a few people seemed to be pointing out:  The procedure
was being called from within an interrupt, by the mouse handler.  This means
that, since one interrupt is going on, interrupts should be disabled during my
service routine.  (A little peek with Turbo Debugger showed that the mouse
driver enables interrupts, calls the service routine, then disables them 
again on return to the driver.)  Now, the dilemma before me was that I could
declare the procedure as interrupt, in which case the compiler would insert
code to disable interrupts.  However, on exit the procedure would generate an
IRET rather than a RETF as I wanted to generate.  In order for the compiler to
generate a RETF, the procedure would have to be declared as a plain, non-
interrupt far procedure.  However, this would mean no code would be inserted to
disable interrupts, and I would not have access to any of the registers, and
some information is passed from the driver to the routine via the registers.

This left me with two solutions (maybe more than two, but only two that I could
think of), each of which was pointed out by at least one person who replied.
I could either declare the procedure as an interrupt, then insert the inline
code necessary to pop off the registers that would be pushed on at the
beginning of the routine and to generate a RETF to leave the procedure, or I
could write the procedure in assembly language and link it in as an external.
I chose to go with an external assembly language routine, since I don't like
inline code, it made good practice, and since the procedure was going to be
called in an interrupt, it should be as compact and fast as possible. 

The issue of reentrancy also came up in some replies I received, since I was
using a writeln statement in the event handler procedure I posted as part of my
test program.  Actually, the real purpose for which I was writing this would
not involve reentrancy, since it would just manipulate an array within my unit
and would not do any dos or bios calls.  The writeln statement was just part of
the test to see if the procedure was being called.

Anyhow, thanks to everyone who replied, some of whom even sent code as 
examples.  I'm afraid I can't thank everyone due to the large amount of replies
this generated, but if you did reply to me, I'm very grateful for it.