/********************************************************************

Mouse Routine:

NOTE: THIS EXAMPLE HAS TO BE COMPILED WITH LARGE MEMORY MODEL.

		condition passed to handler
    AX = condition mask causing call
    CX = horizontal cursor position
    DX = vertical cursor position
    DI = horizontal counts
    SI = vertical counts
    DS = mouse driver data segment
    BX = button state:

*********************************************************************/
#include 
#include 
#include 
#include 
#include 
#include 

struct mouse_structure {
	unsigned char minor;
	unsigned char major;
	unsigned char type;
	unsigned char IRQ;
};

typedef unsigned int word;

#define BN_RIGHT 1
#define BN_LEFT  2

#define MS_BUS			1
#define MS_SERIAL		2
#define MS_INPORT		3
#define MS_PS2			4
#define MS_HP				5

void far interrupt mouse_handler(void);
void mouse_hidden(word x1,word y1,word x2,word y2);
void mouse_sethandler();
void mouse_show(void);
void mouse_hide(void);
int mouse_reset(void);
void mouse_get_ver(struct mouse_structure *mouse);
void mouse_set_grphcur(void *cursor);

void scan_key(char *ch, word *scancode){
  *scancode=bioskey(0);
  *ch=*scancode & 0x00FF;
}

main()
{
char ch=0x00;
word ext=0x00;
int grph=DETECT,gmode=0;

	initgraph(&grph,&gmode,"");
	mouse_reset();
	mouse_show();
	mouse_sethandler();
	scan_key(&ch,&ext);
	closegraph();
	mouse_reset();
}

/******************************
*** reset mouse  >> int 33,00
*******************************/
int mouse_reset(void)
{
union REGS regs={0};
	regs.x.ax=00;
	int86(0x33,®s,®s);
	return regs.x.ax;
}

/*****************************
*** show mouse >> int 33,01
*****************************/
void mouse_show(void)
{
	union REGS regs={0};
	regs.x.ax=01;
	int86(0x33,®s,®s);
}

/****************************
*** hide mouse  >> int 33,02
****************************/
void mouse_hide(void)
{
union REGS regs={0};
	regs.x.ax=0x02;
	int86(0x33,®s,®s);
}

/*************************************************
*** get driver info buffer length  >> int 33,0x15
**************************************************/
void mouse_getdriverinfo(int *driverlen)
{
union REGS regs={0};
	regs.x.ax=0x15;
	int86(0x33,®s,®s);
	*driverlen=regs.x.bx;
}

/*************************************************
*** save driver info state >> int 33,0x16
**************************************************/
void mouse_savedriver(char *driver)
{
union REGS regs={0};
struct SREGS sregs={0};
	regs.x.ax=0x16;
	regs.x.dx=FP_OFF(driver);
	sregs.es=FP_SEG(driver);
	int86x(0x33,®s,®s,&sregs);
}

/*************************************************
*** get driver info state >> int 33,0x17
*************************************************/
void mouse_getdriver(char *driver)
{
union REGS regs={0};
struct SREGS sregs={0};
	regs.x.ax=0x17;
	regs.x.dx=FP_OFF(driver);
	sregs.es=FP_SEG(driver);
	int86x(0x33,®s,®s,&sregs);
}


/***************************************************
*** set user define interupt routine >> int 33,0C
***************************************************/
void mouse_sethandler()
{
struct SREGS sregs={0};
union REGS regs={0};
	regs.x.ax=0x0C;
	regs.x.dx=FP_OFF(mouse_handler);
	regs.x.cx=0xFF;
	sregs.es=FP_SEG(mouse_handler);
	int86x(0x33,®s,®s,&sregs);
}


/************************************
**** set hidden area >> int 33,0x10
*************************************/
void mouse_hidden(word x1,word y1,word x2,word y2)
{
union REGS regs={0};
	regs.x.ax=0x10;
	regs.x.cx=x1;
	regs.x.dx=y1;
	regs.x.si=x2;
	regs.x.di=y2;

	int86(0x33,®s,®s);
}

/**************************************
*** get mouse version >> int 33,0x24
***************************************/
void mouse_get_ver(struct mouse_structure *mouse)
{
union REGS regs={0};

	regs.x.ax=0x24;
	int86(0x33,®s,®s);
	mouse->major=regs.h.bh;
	mouse->minor=regs.h.bl;
	mouse->type=regs.h.ch;
	mouse->IRQ=regs.h.cl;
}

/**********************************
*** set text cursor >> int 33,0x0A
**********************************/
void mouse_set_textcur(char *screenmask)
{
union REGS regs={0};
	regs.x.ax=0x0A;
	regs.x.bx=0x0;
/*
	regs.x.cx=(char far*)screenmask;
	regs.x.dx=screenmask+16;
*/
	int86(0x33,®s,®s);
}


/****************************************
*** set threshold speed  >> int 33,0x13
*****************************************/
void mouse_set_thrspeed(unsigned speed)
{
union REGS regs={0};
	regs.x.ax=0x13;
	regs.x.dx=speed;
	int86(0x33,®s,®s);
}


/*******************************
*** set graphic cursor.
*** cursor is 16 byte array.
*** 0-7 screen mask.
*** 8-F cursor mask.
*** >> int 33,0x09
********************************/
void mouse_set_grphcur(void *cursor)
{
struct SREGS sregs={0};
union REGS regs={0};

word sseg=FP_SEG(cursor);
word soff=FP_OFF(cursor);

	regs.x.ax=0x09;
	regs.x.bx=0;
	regs.x.cx=0;
	regs.x.dx=soff;
	sregs.es=sseg;
	int86x(0x33,®s,®s,&sregs);
}


/************************ user defined interrupt handler *****************/

/**************************
*** mouse handler
**************************/
void far interrupt mouse_handler(void)
{

unsigned int x=_CX, y=_DX, dispx=_DI,dispy=_SI;
unsigned int bn_state=_BX,  event=_AX;

	gotoxy(1,1);
	printf("X axis %u     \n",x);
	printf("Y axis %u     \n",y);
	printf("Hcount %u     \n",dispx);
	printf("Vcount %u     \n",dispy);
	printf("State  %d     \n",bn_state);
	printf("event  %x       ",event);

}


    Source: geocities.com/siliconvalley/vista/2459/programming

               ( geocities.com/siliconvalley/vista/2459)                   ( geocities.com/siliconvalley/vista)                   ( geocities.com/siliconvalley)