Code:
#include <dos.h>
#include <stdio.h>
#include <graphics.h>
union REGS regs;
struct SREGS sregs;
int MouseInit(void)
/* Ham khoi tao chuot */
{
regs.x.ax=0x00;
int86(0x33,®s,®s);
return regs.x.ax;
}
int CursorList[28][34]= /* Array includes 28 mask mouse */
{
// 0 : Mui ten chuan nen trang
0x9FFF,0x8FFF,0x87FF,0x83FF,0x81FF,0x80FF,0x807F,0x803F,
0x801F,0x800F,0x80FF,0x887F,0x987F,0xFC3F,0xFC3F,0xFE3F,
0x0000,0x2000,0x3000,0x3800,0x3C00,0x3E00,0x3F00,0x3F80,
0x3FC0,0x3E00,0x3600,0x2300,0x0300,0x0180,0x0180,0x0000,
0,0,
// 1 : Finger
0xF3FF,0xE1FF,0xE1FF,0xE1FF,0xE1FF,0xE049,0xE000,0x8000,
0x0000,0x0000,0x07FC,0x07F8,0x9FF9,0x8FF1,0xC003,0xE007,
0x0C00,0x1200,0x1200,0x1200,0x1200,0x13B6,0x1249,0x7249,
0x9249,0x9001,0x9001,0x8001,0x4002,0x4002,0x2004,0x1FF8,
0,0,
//............
// 27
};
void SetMouseType(int MType)
/* Dat kieu con tro chuot theo cac mang ve chuot tren */
{
regs.x.ax = 0x09;
regs.x.bx = CursorList[MType][32]; // Diem nong theo truc x
regs.x.cx = CursorList[MType][33]; // Diem nong theo truc y
sregs.es = FP_SEG(CursorList[MType]);
regs.x.dx = FP_OFF(CursorList[MType]);
int86x(0x33,®s,®s,&sregs);
}
void SetMouseShowIn(int L,int T,int R,int B)
/* Dat toa do di chuyen chuot chi trong vung */
{
if((B<=T)||(R<=L)) return;
regs.x.ax = 0x07;
regs.x.cx = L;
regs.x.dx = R;
int86(0x33,®s,®s);
regs.x.ax = 0x08;
regs.x.cx = T;
regs.x.dx = B;
int86(0x33,®s,®s);
}
void SetMouseNotShowIn(int L,int T,int R,int B)
/* Ham nay dat vung gioi han ma trong vung do con chuot do hoa duoc */
/* an di. Vung nay bi huy khi goi lai ham voi toa do x hoac y sau nho*/
/* hon hoac bang x,y truoc. */
{
if((B<=T)||(R<=L)) return;
regs.x.ax=0x10;
regs.x.cx=L;
regs.x.dx=T;
regs.x.si=R;
regs.x.di=B;
int86(0x33,®s,®s);
}
void MouseShow(void)
/* Hien con tro chuot */
{
regs.x.ax=0x01;
int86(0x33,®s,®s);
}
void MouseHide(void)
/* An con tro chuot */
{
regs.x.ax=0x02;
int86(0x33,®s,®s);
}
void GetMouse(int *Button,int *MouseX, int *MouseY)
/* Lay vi tri con tro chuot che do GRAPH */
{
regs.x.ax=0x03;
int86(0x33,®s,®s);
*Button=regs.x.bx; *MouseX=regs.x.cx; *MouseY=regs.x.dx;
}
int MouseLPressed(void)
/* Test if Left Mouse clicked, return value not 0 (1) */
{
regs.x.ax=0x03;
int86(0x33,®s,®s);
return regs.x.bx&1;
}
int MouseRPressed(void)
/* Kiem tra neu phim phai chuot bam ham tra lai gia tri khac 0 (2); */
{
regs.x.ax=0x03;
int86(0x33,®s,®s);
return regs.x.bx&2;
}
int MouseReleased(void)
/* Kiem tra neu phim chuot da bam duoc tha ra */
/* ham tra lai gia tri khac 1 */
{
regs.x.ax=0x03;
int86(0x33,®s,®s);
if ((regs.x.bx&1)||(regs.x.bx&2)) return(0); else return(1);
}