⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mouse.c

📁 此為philip 1362 USB DOS下的驅動程式包, 已經共測試並內含有說明文件
💻 C
字号:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <bios.h>
#include <mem.h>
#include <graphics.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <math.h>

#include "isp1362.h"
#include "isa290.h"
#include "reg.h"
#include "cheeyu.h"

int maxmin(int no, int max, int min)
{
 if(no>max) {no=max;}
 if(no<min) {no=min;}

 return(no);
}

void play_mouse(unsigned int addr)
{
 unsigned int cbuf[128];
 unsigned int rbuf[128];

 //buffer information
 unsigned int atllen,ptllen,intllen;
 unsigned int int_start;

 //int parameters
 unsigned long int_skip=0xFFFFFFFE;
// unsigned long int_done=0;
 unsigned long int_last=0x00000001;
 unsigned int  int_blk_size=64;

 unsigned int mycode;
 unsigned int timecnt;
 unsigned int freq;

 unsigned long rhp1,rhp2;

 unsigned int user_in;

 signed char X=0,Y=0,B=0;

 unsigned int pX=320,pY=240;
 unsigned int oX=320,oY=240;

 unsigned int bx=489;
 unsigned int by=30;

 unsigned int tog=0;


 freq=0x60;

 gui();

 erase_all();

 w16(HcBufStatus,0x00);

 //Setup Int Parameters
 w32(HcIntSkip,int_skip);
 w32(HcIntLast,int_last);
 w16(HcIntBlkSize,int_blk_size);

 //Setup Buffer
 atllen  =r16(HcATLLen);
 ptllen  =r16(HcPTLLen);
 intllen =r16(HcINTLen);

 int_start=ptllen+ptllen;

 e_box(320,192,580,266);
 e_box(bx    ,by,40,30);
 e_box(bx+50 ,by,40,30);
 e_box(bx+100,by,40,30);

 advlogo();

 gotoxy(5,1);
 printf("Displaying mouse movement @Port %X",addr);

 do
  {
   //send out DATA IN packet
   make_int_ptd(cbuf,IN,1,4,tog%2,addr,addr,freq);
   timecnt=send_int(cbuf,rbuf);

   if(timecnt!=0)
   {
	X=(rbuf[4]>>8);
	Y=(rbuf[5]&0x00FF);
	B=(rbuf[4]&0x000F);
   }

   else
   {
	X=0;
	Y=0;
	B=0;
   }

   if( (B&0x01)!=0)
   {
	setfillstyle(SOLID_FILL,YELLOW);
	floodfill(bx,by,WHITE);
   }
   else
   {
	setfillstyle(SOLID_FILL,BLUE);
	floodfill(bx,by,WHITE);
   }

   if( (B&0x02)!=0)
   {
	setfillstyle(SOLID_FILL,GREEN);
	floodfill(bx+100,by,WHITE);
   }
   else
   {
	setfillstyle(SOLID_FILL,BLUE);
	floodfill(bx+100,by,WHITE);
   }

   if( (B&0x04)!=0)
   {
	setfillstyle(SOLID_FILL,CYAN);
	floodfill(bx+50,by,WHITE);
   }
   else
   {
	setfillstyle(SOLID_FILL,BLUE);
	floodfill(bx+50,by,WHITE);
   }

   oX=pX;
   oY=pY;

   pX=pX+X;
   pY=pY+Y;

   pX=maxmin(pX,605,35);
   pY=maxmin(pY,320,65);

   if(timecnt!=0) {tog++;}

   line(pX,pY,oX,oY);

   gotoxy(5,2);
   printf("X:%4d Y:%4d B:%4X",X,Y,B);
   gotoxy(5,3);
   printf("pX:%4d pY:%4d  Press '1' to Exit",pX,pY);
   user_in=read_key(0);
  }
 while(user_in!='1');

 close_gui();
}

void mouse(void)
{
 unsigned int user_in;
 unsigned int cbuf[128];
 unsigned int rbuf[128];
 unsigned int dev_req[4]={0x0680,0x0100,0x0000,0x0008};
 unsigned int uni_req[4]={0x0500,3,0x0000,0x0000};
 unsigned char udn[64];

 //buffer information
 unsigned int atllen,ptllen,intllen;
 unsigned int atl_start;

 //atl parameters
 unsigned long atl_skip=0xFFFFFFFE;
 unsigned long atl_done=0;
 unsigned long atl_last=0x00000001;
 unsigned int  atl_blk_size=64;
 unsigned int  atl_cnt=1;
 unsigned int  atl_timeout=200;
 unsigned int mycode;
 unsigned int cnt,name_length;
 unsigned int iManufacturer,iProduct;
 unsigned long rhp1,rhp2;
 unsigned int starty=5;
 unsigned int status;
 unsigned int mouse01=0,mouse02=0;

 clrscr();

 set_operational();
 enable_port();
 delay(300);

 reset_usb();
 erase_all();
 set_operational();
 enable_port();
 delay(300);

 w16(HcBufStatus,0x00);

 //Setup ATL Parameters
 w32(HcATLSkip,atl_skip);
 w32(HcATLLast,atl_last);
 w16(HcATLBlkSize,atl_blk_size);
 w16(HcATLThrsCnt,atl_cnt);
 w16(HcATLTimeOut,atl_timeout);

 //Setup ATL Buffer
 atllen  =r16(HcATLLen);
 ptllen  =r16(HcPTLLen);
 intllen =r16(HcINTLen);

 atl_start=ptllen+ptllen+intllen;

 status=assign_address(1,2,0);
 status=assign_address(1,2,0);

 gotoxy(1,1);
 printf("ISP1362 Mouse Demo");

 gotoxy(1,2);
 printf("Probing USB downstream ports... ");
 if(status==0x0100) {printf("Connection detected at port 1.");}
 else if(status==0x0001) {printf("Connection detected at port 2.");}
 else if(status==0x0101) {printf("Connection detected at port 1 and 2.");}
 else {printf("No connection detected.");}

 w16(HcUpIntEnable,0x100);

 if( (status&0x0100)!=0) //port 1 active
 {
  //Check port 1 for mouse
  printf("\nGetting device descriptor for device at port 1... ");

  mycode=get_control(rbuf,1,'D',0,1);
  printf("%04X",mycode);

  if(mycode==0x0300)
  {
   iManufacturer = rbuf[7]&0xFF;
   iProduct = (rbuf[7]&0xFF00)>>8;

   addr_info(1,'W','O',iManufacturer);
   addr_info(1,'W','P',iProduct);

   mycode=get_control(rbuf,1,'H',addr_info(1,'R','P',0),1);

   if( *(rbuf+1)==0x0209  )
   {
	printf("\nMouse Detected @Port1!!! ");

	mouse01=1;
   }
  }
 }

 if( (status&0x0001)!=0) //port 2 active
 {
  //Check port 2 for mouse
  mycode=get_control(rbuf,2,'D',0,2);
  printf("\nGetting device descriptor for device at port 2... ");
  printf("%04X",mycode);
  if(mycode==0x0300)
  {
   iManufacturer = rbuf[7]&0xFF;
   iProduct = (rbuf[7]&0xFF00)>>8;

   addr_info(2,'W','O',iManufacturer);
   addr_info(2,'W','P',iProduct);

   mycode=get_control(rbuf,2,'H',addr_info(2,'R','P',0),2);

   if( *(rbuf+1)==0x0209  )
   {
	printf("\nMouse Detected @Port2!!! ");

	mouse02=1;
   }
  }
 }

 if((mouse01==1)&&(mouse02==0))
 {
  mycode=set_config(1,1);
  printf("\nSetting config of device 1 to config 1... %04X",mycode);

  if(mycode==0)
  {
   play_mouse(1);
  }
 }

 if((mouse02==1)&&(mouse01==0))
 {
  mycode=set_config(2,1);
  printf("\nSetting config of device 2 to config 2... %04X",mycode);

  if(mycode==0)
  {
   play_mouse(2);
  }
 }

 if((mouse02==1)&&(mouse01==1))
 {
  printf("\nUSB Mouse detected at both ports, using mouse @Port1");

  printf("\nPress any key to confirm...");

  getch();

  mycode=set_config(1,1);
  printf("\nSetting config of device 1 to config 1... %04X",mycode);

  if(mycode==0)
  {
   play_mouse(1);
  }
 }

 if((mouse02==0)&&(mouse01==0))
 {
  printf("\nUSB Mouse NOT detected, press any keys to continue...");

  getch();
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -