C鼠标初始化问题,请教高手!!!
为什么按照书上或网上说的方法鼠标的状态可以正常读出却无法显示呢?
outportb函数有用么?
/* Note:Your choice is C IDE */
#include <stdio.h>
#include <graphics.h>
#include <io.h>
#include <dos.h>
#include <conio.h>
#define MOUSE_ID 0x33
int mouse_x,mouse_y,mouse_b;
unsigned int pattern[32]={
0x3fff,
0x1fff,
0x0fff,
0x07ff,
0x01ff,
0x00ff,
0x007f,
0x003f,
0x001f,
0x01ff,
0x10ff,
0x30ff,
0xf87f,
0xf87f,
0xfc3f,
0x0000,
0x4000,
0x6000,
0x7000,
0x7800,
0x7c00,
0x7e00,
0x7f80,
0x7fc0,
0x6c00,
0x4600,
0x0600,
0x0300,
0x0300,
0x0180,
};
mouse_read()
{
union REGS oreg,ireg;
int i;
mouse_b=0;
outportb(0x443,0x0e);
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
mouse_x=oreg.x.cx;
mouse_y=oreg.x.dx;
i=oreg.x.bx;
if(i==0x01)mouse_b=1;
if(i==0x02)mouse_b=2;
if(i==0x03)mouse_b=3;
outportb(0x441,0);
if(mouse_b)
return 1;
else
return mouse_b;
}
set_gr_sursor(int x,int y,unsigned int far*pattern)
{
union REGS regs;
struct SREGS isreg;
regs.x.ax=9;
regs.x.bx=x;
regs.x.cx=y;
regs.x.dx=FP_OFF(pattern);
isreg.es=FP_SEG(pattern);
int86x(MOUSE_ID,®s,®s,&isreg);
outportb(0x441,0);
}
show_mouse()
{
union REGS regs;
outportb(0x443,0x0e);
regs.x.ax=1;
int86(MOUSE_ID,®s,®s);
outportb(0x441,0);
}
main()
{
int graphdriver,graphmode;
graphdriver=VGA;
graphmode=VGAHI;
initgraph(&graphdriver,&graphmode,"");
cleardevice();
set_gr_sursor(mouse_x,mouse_y,pattern) ;
show_mouse();
while(1)
{
mouse_read();
gotoxy(50,25);
printf("x:%-3d,y:%-3d,button:%4d",mouse_x,mouse_y,mouse_b);
}
}