C鼠标初始化问题,请教高手!!!

BEISHUISHILAN 2008-09-12 10:32:59
为什么按照书上或网上说的方法鼠标的状态可以正常读出却无法显示呢?

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);


}
}
...全文
144 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kapaskey 2008-09-21
  • 打赏
  • 举报
回复
TC哦
xiansizhe 2008-09-21
  • 打赏
  • 举报
回复
dos.h 中 /* 向指定的接口输出指定的字节 */
void outportb(int port,char byte)
#include <stdio.h>
#include <dos.h>

int main(void)
{
int port = 2; /* 这是指定的字节 */
char value = 'C';

outportb(port, value);
printf("Value %c sent to port number %d\n", value, port);
return 0;
}
K行天下 2008-09-13
  • 打赏
  • 举报
回复
tc的吧
BEISHUISHILAN 2008-09-13
  • 打赏
  • 举报
回复
我知道这个函数的原形及作用,我问的是它在该程序中的作用
_石头_ 2008-09-12
  • 打赏
  • 举报
回复
outportb函数有用么?
----------------------
原型: void outportb(unsigned char port, unsigned char value)
作用:向port端口(i/o端口)输出8bit的数据value

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧