home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / linux / 10586 < prev    next >
Encoding:
Text File  |  1992-09-12  |  2.6 KB  |  125 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watmath!watmsg.uwaterloo.ca!fwbent
  3. From: fwbent@watmsg.uwaterloo.ca (Fred Bent)
  4. Subject: Possible MS Bus Mouse Detect (?)
  5. Message-ID: <BuHtJH.CIF@math.uwaterloo.ca>
  6. Keywords: bus mouse
  7. Sender: news@math.uwaterloo.ca (News Owner)
  8. Organization: University of Waterloo
  9. Date: Sun, 13 Sep 1992 01:30:53 GMT
  10. Lines: 113
  11.  
  12.  
  13. Hello,
  14.  
  15. I have been reading several articles mention that currently
  16. there is no method for detecting a Microsoft Bus Mouse.
  17.  
  18. Well, I have some code that shows how to do this (I think :-).
  19. Is this what you are asking for?  I have not tested this code
  20. with a Logitech so I am not sure what will happen, I only know
  21. that this code should work for detecting IF a Microsoft Bus Mouse
  22. is present (but not sure if will discriminate).
  23.  
  24. -----------CUT HERE----------------
  25. /*
  26.  * bus_mouse.c
  27.  *
  28.  * This code checks for the presence of a Microsoft compatible
  29.  * Bus Mouse.
  30.  * For Borland C++ under MS-DOS
  31.  */
  32.  
  33. #include<stdio.h>    /* fprintf */
  34. #include<dos.h>        /* outp inp */
  35.  
  36. #define    TEST_BYTE    0xA5
  37.  
  38. #define BUS_MOUSE_ADDR    0x023C
  39. #define CMD_ADDR    (BUS_MOUSE_ADDR + 3)
  40. #define BUS_ADDR    (BUS_MOUSE_ADDR + 2)
  41. #define DAT_ADDR    (BUS_MOUSE_ADDR + 1)
  42.  
  43.  
  44. void Delay(void)
  45. /*
  46.  * Since hardware is SLOW, we need some delay....
  47.  */
  48. {
  49.     int    result;
  50.  
  51.     result = inp( 0x43 );        /* any port will do.... */
  52.     result = inp( 0x43 );
  53. }
  54.  
  55. void main(void)
  56. {
  57.     int    result;
  58.     int    temp = !0;
  59.     int    save;
  60.     int    i;
  61.  
  62.     /*
  63.      * This only works for Bus Mouse....
  64.      */
  65.  
  66.     outp( CMD_ADDR, 0x91 );
  67.     Delay();
  68.     outp( DAT_ADDR, TEST_BYTE );    /* Should be echoed by the mouse */
  69.     Delay();
  70.  
  71.     outp( CMD_ADDR, 0x11 );
  72.     Delay();
  73.     result = inp( DAT_ADDR );
  74.  
  75.     if ( result != TEST_BYTE ) {
  76.         fprintf( stderr, "No Microsoft Mouse here! (%X)\n", result );
  77.         exit(1);
  78.     }
  79.  
  80.     /*
  81.      * Get the mouse IRQ
  82.      */
  83.  
  84.     result = inp( BUS_ADDR );
  85.     save = result;
  86.     temp = 0;
  87.  
  88.     for ( i = 0; i < 0x2710; i++ ) {
  89.         Delay();
  90.         result = inp( BUS_ADDR );
  91.         save = save ^ result;
  92.         temp = temp | save;
  93.         save = result;
  94.     }
  95.  
  96.     switch (temp) {
  97.         case 0x00    : result = 2; break;    /* A PC Jr. !?!? */
  98.         case 0x01    : result = 5; break;
  99.         case 0x02    : result = 4; break;
  100.         case 0x04    : result = 3; break;
  101.         case 0x08    : result = 2; break;
  102.         default        : result = 0; break;
  103.     }
  104.  
  105.     /*
  106.      * Should only encounter the Bus Mouse case....
  107.      */
  108.  
  109.     fprintf( stdout, "Bus Mouse, using IRQ %d\n", result );
  110.  
  111.     return;
  112. }
  113.  
  114. ------CUT HERE------
  115.  
  116. Hope this helps!  I can only test this under MS-DOS, but the method
  117. should be clear.  inp and outp simply get/send a byte to a IO port 
  118. (in case not too obvious).
  119.  
  120. Waiting for version 0.98, and a 486-33!
  121.  
  122. --
  123. Fred Bent
  124. fwbent@plg.uwaterloo.ca
  125.