Article View: comp.os.msdos.programmer
Article #6725Re: Notes about Borland C++ interrupt keyword
From: Mike Percy
Date: Tue, 21 May 1991 20:30
Date: Tue, 21 May 1991 20:30
44 lines
2787 bytes
2787 bytes
sorrow@oak.circa.ufl.edu writes:
>Actually, I found out that I must be doing something terribly wrong. When
>I installed my own mouse interrupt handler, if the function was declared
>as "void far interrupt" it would die. "void far" worked just fine. I just
>don't USE the interrupt keyword. The documentation is too skimpy on it
>for me to be able to use it decently.
If you are talking about mouse function 12(?), theone that lets you have
the mouse driver call your function whenever certain mouse events
happen, then you are on the right track. The "interrupt" handler you
give to the mouse is not of type void interrupt. TurboC interrupt
functions push regs to the stack, do your stuff, pop the regs and --
IRET. This is what screws you. The driver does a simple far CALL to your
routine, expecting to have control come back to it with a far RET. The
IRET is simply wrong here. Declaring your mouse function to be void far
fixes this problem, but you still cannot access global/static data
except by sheer accident, as DS will likely not be pointing to your
DGROUP. Declaring it as void huge does this trick. But the mouse
driver also apparantly assumes a called-saved register scheme, while the
C compiler assumes a caller-saved scheme. Your routine can trash
registers the mouse driver expected you to leave alone. I use #pragma
savregs. This guarantees that a huge function will not change the value
of any of the register when it is entered. I like the pragma rather than
declaring the function as _saveregs. _saveregs pushes all register and
pops them at the end. This is costly in time/space. The #pragma
saveregs costs more at compile time, but is much smaller/faster at
runtime.
In short, when installing a mouse handler (function 12), I declare it
#pragma saveregs
void huge handler(void)
{
/* handler code */
}
I spent a lot of time before getting this to work...
"I don't know about your brain, but mine is really...bossy."
Mike Percy grimlok@hubcap.clemson.edu
ISD, Clemson University mspercy@clemson.BITNET
(803)656-3780 mspercy@clemson.clemson.edu
Technical Details
Message-ID:
<1991May21.203019.20728@hubcap.clemson.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!stanford.edu!hubcap!grimlokReferences:
<1991May20.171545.23591@amc.com>,<1991May20.230908.7178@maytag.waterloo.edu> <00948EEF.C05FAA40@MAPLE.CIRCA.UFL.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!stanford.edu!hubcap!grimlok From: grimlok@hubcap.clemson.edu (Mike Percy) Newsgroups: comp.os.msdos.programmer,comp.sys.ibm.pc.programmer,alt.msdos.programmer Subject: Re: Notes about Borland C++ interrupt keyword Message-ID: <1991May21.203019.20728@hubcap.clemson.edu> Date: 21 May 91 20:30:19 GMT Article-I.D.: hubcap.1991May21.203019.20728 References: <1991May20.171545.23591@amc.com>,<1991May20.230908.7178@maytag.waterloo.edu> <00948EEF.C05FAA40@MAPLE.CIRCA.UFL.EDU> Organization: Clemson University Lines: 44