TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BEN LIPPMEIER
from: DON GUY
date: 1997-03-17 00:38:00
subject: Need help getting &Mouse::eventhandler 00:38:1003/17/97

.286p
.model small
name Replying_To_A_Message_from_Ben
assume CS:ReplyBody
ReplyBody segment byte public
Ben:
 BL> for a current project, i have the desire to write an oop mouse handler..
/snip/
 BL> anyhow, i've come to a wall, trying to load the address of the handler
 BL> into es:dx (as requested by the tsr).
A friend and I ran into a similar problem when writing an API for serial 
ports. The solution we used, stemmed from a somewhat undocumented feature of 
C++. I say ~somewhat~ undocumented 'cause the only place I've found a 
reference to it so far is on Borland's web site. No text I've seen mentions 
it, nor does the online help in v3.0.
Anyways, here goes; I'm assuming you're working with a class named, oddly 
enough, "Mouse." :)
In front of the class definition, insert "_CLASSDEF( Mouse )". Now inside the 
definition you're going to need:
static PMouse Mouse_ISR; /* Mouse_ISR is a pointer to an instance of class
                            Mouse. PMouse is a type which the _CLASSDEF()
                            macro set up. The type identifier is simply the
                            class name with a "P" slapped onto the front of
                            it. */
static void interrupt MouseEvent(...); /* This interrupt handler does nothing
                                          more than call the function
                                          MouseHandler(). */
void MouseHandler( [parameter list] ); /* The function which does all the 
dirty
                                          work. */
Now, inside the constructor, point Mouse_ISR to this instance of Mouse (i.e. 
Mouse_ISR = this; ). When you're ready to load the ISR, get the segment & 
offset of MouseEvent() with FP_SEG( MouseEvent ) and FP_OFF( MouseEvent ). 
Note that the trailing parentheses are *not* placed after the function name 
in this case.
As for the two functions which do all the work, I'm including a clip of the 
class I've been using. I believe it's sufficiently commented to be 
self-explanatory, but if not, don't hesitate to ask just what the heck was it 
that I did... :)
=== Start mouse.cpp ===
/*²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²*
/
// Mouse.Cpp                                                           CS 059
// Copywrong 1997 by Don Guy & Scott Barr
//
// See Mouse.H for description of this class.
//
/*²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²*
/
#include "mouse.h"
PMouse Mouse::Mouse_ISR = NULL; /* This sucker needs to be exactly where you
                                   see it. Until you create an object of 
lass
                                   Mouse, the pointer to that object 
houldn't
                                   be pointing anywhere . */
/***********************************************************************
The next two functions trigger a rudimentary handler every time a mouse
event occurs. The handler provides only basic status information--it may
be overridden with a program's virtual function of the same name for
customized performance.
***********************************************************************/
void interrupt Mouse::MouseEvent(...)
{
  /* Disable further interrupts, and call the event handler, supplying
     parameters made available in the registers. */
  disable();
  if ( Mouse_ISR )
   Mouse_ISR->MouseHandler( _AX, _BX, _CX, _DX, _DI, _SI );
  enable();
  // This block is necessary for the ISR to return properly.
  asm { pop bp; pop di; pop si
        pop ds; pop es; pop dx
        pop cx; pop bx; pop ax;
        retf };
}
void Mouse::MouseHandler( word AX, word BX, word CX,
                          word DX, word DI, word SI )
{
  Trigger      = AX & 0x7F;
  ButtonStatus = BX & 0x07;
  HorzCoord    = CX;
  VertCoord    = DX;
  HorzCount    = DI;
  VertCount    = SI;
}
=== End mouse.cpp ===
One thing to note:
    Depending on how you have your compiler options set, you may receive a 
warning about the "retf" assembly instruction at the end of MouseEvent(). If 
so, don't worry about it. It's as legit an instruction as they come.
Hope this helps...
 mov ax,4C00h
 int 21h
Reply ends
end Ben
... CCITT: Can't Conjure Intelligent Thoughts Today
---
---------------
* Origin: Extreme Impossibility/2 [Kingston, Ontario, Canada] (1:249/176)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.