🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #4073

Need help w/mouse func 12, src incl.

#4073
From: Edward Collins
Date: Sun, 30 Dec 1990 17:50
168 lines
5262 bytes
Hello,

Would someone please pass along an example of how to setup and use mouse
function 12 ( define event handler ) or point out what's wrong with the
test pgm below?

I'm curious why this function (12) seems to be neglected in all the books
I've looked in. It seems like the most useful of all the functions
in the mouse driver, after all why would we want to do any polling 
if we don't have to.

Does anyone know of a good reason not to use mouse function 12? 
Do most people simply poll for mouse events?

Please respond via e-mail.  I'll summarize if there's enough interest.

Thanks in advance.

Mike.
ecollins@nmsu.edu

---

This minimal test program is self contained, except for a BGI driver which
is assumed to be in the current directory.

/*
**============================================================================
**  mtest() --
**
**      Turbo C/C++ test program for ms mouse function 12 (set event handler).
**
**      Executes fine, but handler is not entered.
**
**      Assumes a proper BGI driver in current directory, ie EGAVGA.BGI.
**
**============================================================================
*/

#include <dos.h>
#include <stdio.h>
#include <graphics.h>

void Handler( void );

void SetEventHandler( int Mask, void far (*handler)( void ) );
void DetectMouse( int *MouseStatus, int *NumberOfButtons );
void ShowCursor( void );

union  REGS regs;
struct SREGS sregs;

int 
  main() 
{       
    int graphdriver = DETECT;
    int graphmode;
    int MouseStatus, NumberOfButtons;

    initgraph( &graphdriver, &graphmode, "" );

    DetectMouse( &MouseStatus, &NumberOfButtons );

    if ( !MouseStatus )
    {
        closegraph();
        printf( "No mouse was detected\n" );
        return 0;
    }

    ShowCursor();

    SetEventHandler( 0xff, (void far (*) (void)) (Handler) );

    while ( !kbhit() );

    closegraph();
    return 0;
}

/*===========================================================================*/

void
  Handler()
{
  printf( "In event handler\n" );
}

/*===========================================================================*/

void 
  DetectMouse( int *MouseStatus, 
               int *NumberOfButtons )
{
    regs.x.ax = 0;
    int86( 51, &regs, &regs );
    *MouseStatus = regs.x.ax;
    *NumberOfButtons = regs.x.bx;
}

/*===========================================================================*/

void 
  ShowCursor( void )
{
   regs.x.ax = 1;
   int86( 51, &regs, &regs );
}

/*
**=============================================================================
** SetEventHandler() --
**
** Function 12 defines the address entry location of an event handler routine 
** which is called when a certain event (defined by the call mask) occurs.  
** The program is temporarily interrupted by the mouse driver. At the end of 
** the event handler routine  the program continues at the point it was 
** interrupted.
** 
** The call mask is a single integer value defining the conditions which will 
** cause an interrupt.
** 
** A specific condition corresponds to a bit in the call mask:
** 
**  Mask Bit                Condition
** --------------------------------------------------
**    0                    cursor location changed
**    1                    left button pressed
**    2                    left button released
**    3                    right button pressed
**    4                    right button released
**    5                    middle button pressed
**    6                    middle button released
**    7 - 15               not used
** 
**   To enable the event handler routine, set the mask bit to non-zero, to
**   disable it set it to zero and make a call to this function.
**   Always be sure to set the call mask to 0 before the program finishes.
**   (Leave the system in the same state upon exit as if was upon entrance.)
** 
** Input:  AX = 12
**         CX = call mask
**         ES:DX = pointer to event handler routine
** Return: none
** 
**=============================================================================
*/

void 
  SetEventHandler( int Mask, 
                   void far (*handler)( void ) )
{
    regs.x.ax = 12;
    regs.x.cx = Mask;
    regs.x.dx = FP_OFF( handler );
    sregs.es  = FP_SEG( handler );

    int86x( 51, &regs, &regs, &sregs );
}

--

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=  Mike Collins                   | "Why would I want to change my    =
=  New Mexico State University    |  mind?  Is there something wrong  =
=  e-mail: ecollins@nmsu.edu      |  with the one I have?" -- Spock   =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID: <ECOLLINS.90Dec30105010@silicon.nmsu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!news.cs.indiana.edu!ariel.unm.edu!nmsu!opus!ecollins

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!news.cs.indiana.edu!ariel.unm.edu!nmsu!opus!ecollins
From: ecollins@nmsu.edu (Edward Collins)
Newsgroups: comp.os.msdos.programmer
Subject: Need help w/mouse func 12, src incl.
Message-ID: <ECOLLINS.90Dec30105010@silicon.nmsu.edu>
Date: 30 Dec 90 17:50:10 GMT
Sender: news@NMSU.Edu
Distribution: comp.os.msdos.programmer
Organization: NMSU Computer Science
Lines: 168