home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watmath!watmsg.uwaterloo.ca!fwbent
- From: fwbent@watmsg.uwaterloo.ca (Fred Bent)
- Subject: Possible MS Bus Mouse Detect (?)
- Message-ID: <BuHtJH.CIF@math.uwaterloo.ca>
- Keywords: bus mouse
- Sender: news@math.uwaterloo.ca (News Owner)
- Organization: University of Waterloo
- Date: Sun, 13 Sep 1992 01:30:53 GMT
- Lines: 113
-
-
- Hello,
-
- I have been reading several articles mention that currently
- there is no method for detecting a Microsoft Bus Mouse.
-
- Well, I have some code that shows how to do this (I think :-).
- Is this what you are asking for? I have not tested this code
- with a Logitech so I am not sure what will happen, I only know
- that this code should work for detecting IF a Microsoft Bus Mouse
- is present (but not sure if will discriminate).
-
- -----------CUT HERE----------------
- /*
- * bus_mouse.c
- *
- * This code checks for the presence of a Microsoft compatible
- * Bus Mouse.
- * For Borland C++ under MS-DOS
- */
-
- #include<stdio.h> /* fprintf */
- #include<dos.h> /* outp inp */
-
- #define TEST_BYTE 0xA5
-
- #define BUS_MOUSE_ADDR 0x023C
- #define CMD_ADDR (BUS_MOUSE_ADDR + 3)
- #define BUS_ADDR (BUS_MOUSE_ADDR + 2)
- #define DAT_ADDR (BUS_MOUSE_ADDR + 1)
-
-
- void Delay(void)
- /*
- * Since hardware is SLOW, we need some delay....
- */
- {
- int result;
-
- result = inp( 0x43 ); /* any port will do.... */
- result = inp( 0x43 );
- }
-
- void main(void)
- {
- int result;
- int temp = !0;
- int save;
- int i;
-
- /*
- * This only works for Bus Mouse....
- */
-
- outp( CMD_ADDR, 0x91 );
- Delay();
- outp( DAT_ADDR, TEST_BYTE ); /* Should be echoed by the mouse */
- Delay();
-
- outp( CMD_ADDR, 0x11 );
- Delay();
- result = inp( DAT_ADDR );
-
- if ( result != TEST_BYTE ) {
- fprintf( stderr, "No Microsoft Mouse here! (%X)\n", result );
- exit(1);
- }
-
- /*
- * Get the mouse IRQ
- */
-
- result = inp( BUS_ADDR );
- save = result;
- temp = 0;
-
- for ( i = 0; i < 0x2710; i++ ) {
- Delay();
- result = inp( BUS_ADDR );
- save = save ^ result;
- temp = temp | save;
- save = result;
- }
-
- switch (temp) {
- case 0x00 : result = 2; break; /* A PC Jr. !?!? */
- case 0x01 : result = 5; break;
- case 0x02 : result = 4; break;
- case 0x04 : result = 3; break;
- case 0x08 : result = 2; break;
- default : result = 0; break;
- }
-
- /*
- * Should only encounter the Bus Mouse case....
- */
-
- fprintf( stdout, "Bus Mouse, using IRQ %d\n", result );
-
- return;
- }
-
- ------CUT HERE------
-
- Hope this helps! I can only test this under MS-DOS, but the method
- should be clear. inp and outp simply get/send a byte to a IO port
- (in case not too obvious).
-
- Waiting for version 0.98, and a 486-33!
-
- --
- Fred Bent
- fwbent@plg.uwaterloo.ca
-