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

📄 mousinfo.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
 * Microsoft Diagnostics Version 2.0
 *
 * A diagnostic utility to detect as much useful information about a
 *   customer's computer system as is possible.
 *
 * Microsoft Diagnostics:  We detect the World.
 *
 * MOUSINFO.C - Source file for mouse detection code.
 ********************************************************************/


/* Include Files */

#include "msd.h"


/*********************************************************************
 * GetMouseInfo - Gets the mouse information.
 *
 * pMouse       - Mouse information structure
 * fMinimumInfo - TRUE if minimum information is requested.
 *
 * Returns:  TRUE if an error occured.
 *********************************************************************/

BOOL GetMouseInfo (MOUSE_STRUCT *pMouse)
{
  union  REGS  inregs, outregs;   /* Register structure for int86()        */
  struct SREGS sregs;             /* Segment regs for int86x()             */
  WORD  wType;                    /* Mouse driver type (InPort, Bus, etc). */
  WORD  wMouseHardware;           /* Mouse hardware type                   */
  WORD  wSize;                    /* Size required to store mouse state    */
  WORD  wMouseVersion;            /* Mouse version (ie 801 == 8.01)        */
  BYTE FAR *fbMouseState = NULL;  /* Pointer to mouse state                */
  static BOOL fMouseInfoLoaded = FALSE;   /* Set to TRUE after mouse       */
                                          /*   info obtained               */
  static MOUSE_STRUCT FAR *fpMouse = NULL;/* Stored mouse info             */


  /* We obtain the mouse information only once, then store the mouse */
  /*   information for later requests.  If a second request is made  */
  /*   (ie., for IRQ info, etc.), this routine will copy the stored  */
  /*   mouse information to pMouse and return immediately.  This is  */
  /*   done because the mouse information is very time consuming to  */
  /*   obtain on some computers and/or mice.                         */

  if (fMouseInfoLoaded)
    {
      _fmemcpy ((MOUSE_STRUCT FAR *) pMouse, fpMouse, sizeof (MOUSE_STRUCT));
      return (FALSE);
    }


  /* Check to see if the mouse driver is safe to call */

  /* Get interrupt vector */
  inregs.h.ah = 0x35;
  inregs.h.al = 33;
  int86x (0x21, &inregs, &outregs, &sregs);

  if ((sregs.es | outregs.x.bx) == 0)
    {
      NoMouseDriver (pMouse);
      return (FALSE);
    }


  /* Save Microsoft Mouse state (important for the CW routines) */

  inregs.x.ax = 0x0015;
  inregs.x.bx = 0x0000;
  int86 (0x33, &inregs, &outregs);
  wSize = outregs.x.bx;

  if (wSize == 0)
    fbMouseState = NULL;
  else
    {
      fbMouseState = _fmalloc (wSize);
      if (fbMouseState != NULL)
        {
          inregs.x.ax = 0x0016;
          sregs.es    = FP_SEG (fbMouseState);
          inregs.x.dx = FP_OFF (fbMouseState);
          inregs.x.bx = wSize;
          int86x (0x33, &inregs, &outregs, &sregs);
        }
    }


  /* Zero out the OEM version number, driver mfgr, and COM port */
  pMouse->wOemMajorVersion = 0;
  pMouse->wOemMinorVersion = 0;
  pMouse->wDriverMfgr      = 0;
  memset (pMouse->szDriverMfgr, '\0', MAX_MOUSE_DRIVER_MFGR);
  pMouse->wComPort         = 0;
  pMouse->szComPort[0]     = '\0';


  /* Determine mouse hardware */

  wMouseHardware = fnHardMouseDetect();
  pMouse->wMouseHardwareType = wMouseHardware;

  if (wMouseHardware == 0xFFFF)
    {
      strcpy (pMouse->szMouseHardwareType, pszDeviceNotDetected);
      pMouse->fHardwareInstalled = FALSE;
    }
  else
    {
      if (wMouseHardware == MSPS2_MOUSE)
        wMouseHardware = PS2_STYLE_MOUSE;

      strcpy (pMouse->szMouseHardwareType, paszMouseTypes[wMouseHardware]);
      pMouse->fHardwareInstalled = TRUE;
    }


  if (AltPS2MouseChk() == TRUE)
    {
      /* A PS/2 Style mouse has been detected.  I can tell the     */
      /*   difference between a Logitech PS/2 mouse and a IBM/     */
      /*   Microsoft PS/2 mouse only at DOS.  If we're in Windows, */
      /*   the mice behave identically.  Therefore, if we're in    */
      /*   Windows, I'll declare it to be a PS/2 Style Mouse, but  */
      /*   if we're at DOS, I'll say it's a Logitech if that was   */
      /*   detected.                                               */

      if (wMouseHardware == LOGITECH_PS2_MOUSE)
        {
          WORD wWindowsType;        /* Local copies of data */
          WORD wWindowsMajor;
          WORD wWindowsMinor;
          BOOL fDosShell;


          /* Determine if we are running in Windows 3.0 or above */
          WinVerDetect (&wWindowsType,
                        &wWindowsMajor,
                        &wWindowsMinor,
                        &fDosShell);

          if (wWindowsType != NO_WINDOWS && wWindowsMajor >= 3)
            {
              strcpy (pMouse->szMouseHardwareType,
                      paszMouseTypes[PS2_STYLE_MOUSE]);
              pMouse->wMouseHardwareType = PS2_STYLE_MOUSE;
              pMouse->fHardwareInstalled = TRUE;
            }
        }
      else if (wMouseHardware == NO_MOUSE_INSTALLED)
        {
          strcpy (pMouse->szMouseHardwareType,
                  paszMouseTypes[PS2_STYLE_MOUSE]);
          pMouse->wMouseHardwareType = PS2_STYLE_MOUSE;
          pMouse->fHardwareInstalled = TRUE;
        }
    }

  /* Check to see if non-Microsoft mouse drivers are resident */

  /* PC Mouse Driver */
  inregs.x.ax = 0x0042;
  int86 (0x33, &inregs, &outregs);
  if (outregs.x.ax == 0xFFFF)
    {
      pMouse->wOemMajorVersion = 0;
      pMouse->wOemMinorVersion = 0;
      pMouse->wDriverMfgr      = MOUSE_MFGR_PC_MOUSE;
      strcpy (pMouse->szDriverMfgr, paszMouseMfgrs[MOUSE_MFGR_PC_MOUSE]);
    }

  /* Logitech Mouse Driver */
  inregs.x.ax = 0x266C;
  int86 (0x33, &inregs, &outregs);
  if (outregs.x.bx == 0x5353)  /* 'SS' */
    {
      WORD rgwLMouseInfo[16];   /* An array to hold mouse info */

      pMouse->wOemMajorVersion = outregs.h.ch - '0';
      pMouse->wOemMinorVersion = outregs.h.cl - '0';
      pMouse->wDriverMfgr      = MOUSE_MFGR_LOGITECH;
      strcpy (pMouse->szDriverMfgr, paszMouseMfgrs[MOUSE_MFGR_LOGITECH]);

      /* Load Logitech serial mouse port number */
      segread (&sregs);
      inregs.x.ax = 0x246C;
      inregs.x.dx = (WORD) &rgwLMouseInfo[0];
      int86x (0x33, &inregs, &outregs, &sregs);
      if (outregs.x.ax == 0xFFFF) /* AX = FFFFh means it's a serial mouse */
        {
          if (rgwLMouseInfo[5] <= 4)
            pMouse->wComPort = rgwLMouseInfo[5];
        }
    }


  /* Reset Microsoft driver and read status */

  inregs.x.ax = 0x0000;
  int86 (0x33, &inregs, &outregs);

  if (outregs.x.ax == 0xFFFF)
    {
      /* Microsoft mouse driver (or compatible) installed */
      if (pMouse->wDriverMfgr == 0)
        {
          pMouse->wDriverMfgr = MOUSE_MICROSOFT_DRIVER;
          strcpy (pMouse->szDriverMfgr, paszMouseMfgrs[MOUSE_MFGR_MICROSOFT]);
        }


      /* Set the number of mouse buttons */
      if (outregs.x.bx == 0xFFFF)
        pMouse->wNmbrButtons = 2;
      else
        pMouse->wNmbrButtons = outregs.x.bx;


      /* Most of the information is not available under OS/2 */
      if (wDosMajor >= 10)
        {
          /* A mouse IRQ of zero will not be checked for IRQ conflicts */
          pMouse->wIrq = 0;

          /* Restore Microsoft Mouse state */
          if (fbMouseState)
            {
              inregs.x.ax = 0x0017;
              sregs.es    = FP_SEG (fbMouseState);
              inregs.x.dx = FP_OFF (fbMouseState);
              inregs.x.bx = wSize;
              int86x (0x33, &inregs, &outregs, &sregs);
              _ffree (fbMouseState);
            }
        }


      /* Get Mouse driver version and mouse type */
      inregs.x.ax = 0x0024;
      int86 (0x33, &inregs, &outregs);


      /* Driver version number */
      pMouse->wMsMajorVersion = outregs.h.bh;
      pMouse->wMsMinorVersion = outregs.h.bl;
      wMouseVersion = ((WORD) outregs.h.bh) * 100 + (WORD) outregs.h.bl;


      /* Mouse IRQ */
      if (outregs.h.cl == 0 || outregs.h.cl == 0xFF)
        pMouse->wIrq = 12;    /* PS/2 mice use IRQ 12 */
      else
        pMouse->wIrq = outregs.h.cl;


      /* Mouse Type from int 33H, AX=0024H */
      wType = outregs.h.ch;


      /* Check for Ballpoint mouse */
      inregs.x.ax = 0x0030;
      inregs.h.ch = 0x00;
      int86 (0x33, &inregs, &outregs);


      /* Set the mouse type */
      if (outregs.x.ax != 0x30 && outregs.x.ax != 0xFFFF)
        {
          pMouse->wMouseDriverType = 0x80;
          strcpy (pMouse->szMouseDriverType, pszBallPoint);
        }
      else
        {
          pMouse->wMouseDriverType  = wType;
          strcpy (pMouse->szMouseDriverType, paszMouseTypes[wType]);
        }


      /* Set mouse's COM port */
      if (pMouse->wComPort == 0 &&
          (pMouse->wMouseDriverType == SERIAL_MOUSE          ||
           pMouse->wMouseDriverType == LOGITECH_SERIAL_MOUSE ||
           pMouse->wMouseDriverType == BALLPOINT_MOUSE))
        {
          /* Serial mouse.  Determine the serial port */
          if (pMouse->wIrq == 3)
            pMouse->wComPort = 2;
          else if (pMouse->wIrq == 4)
            pMouse->wComPort = 1;
          else
            {
              pMouse->wComPort        = 0;
              pMouse->wComPortAddress = 0;
              strcpy (pMouse->szComPort, pszUnknown);
            }
        }


      /* Set mouse's COM port address */
      if (pMouse->wComPort != 0)
        {
          /* 40:0 is the DOS Device Table */
          WORD FAR *fwDosDeviceTable = (WORD FAR *) 0x00400000;
          WORD wPort;     /* COM port number (ie, 0 = COM1:) */

          wPort = pMouse->wComPort;
          pMouse->wComPortAddress = fwDosDeviceTable[wPort - 1];
          strcpy (pMouse->szComPort, pszCom[wPort]);
        }


      /* Mouse Sensitivity */
      inregs.x.ax = 0x001B;
      int86 (0x33, &inregs, &outregs);


      /* Set sensitivities */
      pMouse->wHMickeys       = outregs.x.bx;
      pMouse->wVMickeys       = outregs.x.cx;
      pMouse->wThresholdSpeed = outregs.x.dx;


      /* Mouse Language */
      inregs.x.ax = 0x0023;
      inregs.x.bx = 0x0000;
      int86 (0x33, &inregs, &outregs);


      /* Set the mouse language */
      pMouse->wLanguage = outregs.x.bx;
      strcpy (pMouse->szLanguage, paszMouseLanguages[outregs.x.bx]);


      /* Determine the Mouse driver's file type (.SYS, .COM) */
      if (wMouseVersion >= 626)
        {
          inregs.x.ax = 0x0025;
          int86 (0x33, &inregs, &outregs);

          /* Bit 15 is set for .SYS files, clear for .COM files */
          if (outregs.x.ax & 0x8000)
            {
              pMouse->wDriverFileType = MOUSE_SYS_FILE;
              strcpy (pMouse->szDriverFileType,
                      paszDriverFileTypes[MOUSE_SYS_FILE]);
            }
          else
            {
              pMouse->wDriverFileType = MOUSE_COM_FILE;
              strcpy (pMouse->szDriverFileType,
                      paszDriverFileTypes[MOUSE_COM_FILE]);
            }
        }
      else
        {
          pMouse->wDriverFileType = MOUSE_UNKNOWN_FILE;
          pMouse->szDriverFileType[0] = '\0';
        }


      /* Determine the location of the MOUSE.INI file */
      if (wMouseVersion >= 800)
        {
          inregs.x.ax = 0x0034;
          int86x (0x33, &inregs, &outregs, &sregs);

          /* ES:DX point to the fully qualified path to MOUSE.INI */
          if (outregs.x.ax != 0 && (sregs.es | outregs.x.dx))
            {
              CHAR FAR * fpszString = NULL;  /* Far string pointer */

              fpszString = (CHAR FAR *)
                             ((DWORD) sregs.es << 16) + outregs.x.dx;

              _fstrncpy ((CHAR FAR *) pMouse->szMouseIniPath, fpszString,
                         MAX_MOUSE_INI_PATH - 1);
              pMouse->szMouseIniPath[MAX_MOUSE_INI_PATH - 1] = '\0';
            }
          else
            pMouse->szMouseIniPath[0] = '\0';
        }
      else
        pMouse->szMouseIniPath[0] = '\0';

⌨️ 快捷键说明

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