home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MSMOUSE2.ZIP / UTILS.ZIP / MOUSUTIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-10  |  6.7 KB  |  335 lines

  1. /*
  2.  * mousutil.c
  3.  * 
  4.  * Module for mouse test utility
  5.  *
  6.  * Copyright (c) 1988-1989, Microsoft Corporation.  All rights reserved.
  7.  *
  8.  *
  9.  *        Disclaimer:    This code is example code only,
  10.  *                and does not warranty any product
  11.  *                as being Microsoft compatible.
  12.  *                Microsoft will not be held responsible
  13.  *                for claims made pertaining to this software.
  14.  *
  15.  */
  16.  
  17. #include "mousetst.h"
  18.  
  19.     unsigned savedMode;
  20.  
  21. void
  22. SetCursor(x, y)
  23. unsigned int x, y;
  24. {
  25.     union REGS inregs, outregs;
  26.  
  27.     inregs.h.ah = 2;
  28.     inregs.h.bh = 0;
  29.     inregs.h.dh = (char) y;
  30.     inregs.h.dl = (char) x;
  31.     int86(0x10, &inregs, &outregs);
  32. }
  33.  
  34. void
  35. cls()
  36. {
  37.     union REGS inregs, outregs;
  38.  
  39.     inregs.x.ax = 0x0600;
  40.     inregs.h.bh = 7;
  41.     inregs.x.cx = 0;
  42.     inregs.h.dh = 24;
  43.     inregs.h.dl = 79;
  44.     int86(0x10, &inregs, &outregs);
  45. }
  46.  
  47. void
  48. BlankLine()
  49. {
  50.     printf("                                        ");
  51. }
  52.  
  53. void
  54. BlankMenu()
  55. {
  56.  
  57.     int    i;
  58.  
  59.     for ( i = 7 ; i <= 18 ; i++ )
  60.         {
  61.         SetCursor(0, i);
  62.         BlankLine();
  63.         }
  64.  
  65. }
  66.  
  67. void
  68. Cleanup()
  69. {
  70.     int    dummy, errorStatus, eventMask;
  71.     extern    unsigned originalSegment, originalCallMask, originalOffset;
  72.  
  73.     MouseResetAndStatus(&dummy, &dummy);
  74.     SwapInterruptSubroutines(&originalSegment,
  75.                              &originalCallMask,
  76.                              &originalOffset
  77.                             );
  78.     VideoModeSaveRestore(RESTORE);
  79.  
  80. /* Now disable all possible function 24 subroutines */
  81.  
  82.     eventMask = 0x20;    /* Disable Shift Key subroutine */
  83.     SetAlternateMouseUserSubroutine(&errorStatus, eventMask, Function12);
  84.  
  85.     if (errorStatus == -1)
  86.         printf("Error occured disabling Function 24 Shift Key subroutine\n");
  87.  
  88.     eventMask = 0x40;    /* Disable Ctrl Key subroutine */
  89.     SetAlternateMouseUserSubroutine(&errorStatus, eventMask, Function12);
  90.  
  91.     if (errorStatus == -1)
  92.         printf("Error occured disabling Function 24 Ctrl Key subroutine\n");
  93.  
  94.     eventMask = 0x80;    /* Disable Alt Key subroutine */
  95.     SetAlternateMouseUserSubroutine(&errorStatus, eventMask, Function12);
  96.  
  97.     if (errorStatus == -1)
  98.         printf("Error occured disabling Function 24 Alt Key subroutine\n");
  99. }
  100.  
  101. void
  102. VideoModeSaveRestore(function)
  103.  
  104.     unsigned int function;
  105.  
  106. {
  107.     union REGS inregs, outregs;
  108.  
  109.     switch (function)
  110.         {
  111.     case SAVE:
  112.         inregs.h.ah = 0x0f;
  113.         int86(0x10, &inregs, &outregs);
  114.         savedMode = outregs.h.al;
  115.         break;
  116.     case RESTORE:
  117.         inregs.h.ah = 0;
  118.         inregs.h.al = (char) savedMode;
  119.         int86(0x10, &inregs, &outregs);
  120.         break;
  121.     default:
  122.         printf("Bad function for VideoModeSaveRestore\n");
  123.         break;
  124.     }
  125. }
  126.  
  127. void
  128. SetVideoMode(vMode)
  129.  
  130.     unsigned int vMode;
  131.  
  132. {
  133.     union REGS inregs, outregs;
  134.     int videoModeNumber = 0;
  135.  
  136.     inregs.h.ah = 0;
  137.     inregs.h.al = (char) vMode;
  138.     int86(0x10, &inregs, &outregs);
  139.  
  140. }
  141.  
  142. void
  143. Pause(s)
  144. /*  timer, when t=1  is about  1 sec 
  145.  */
  146. int s;
  147. {
  148.     int i, j;
  149.  
  150.     for ( i = 0; i < s; i++ )
  151.         for ( j = 0 ; j < 500 ; j++ )
  152.             printf("");
  153. }
  154.  
  155. void
  156. ShowLogo()
  157. {
  158.     int i;
  159.     union REGS inregs, outregs;
  160.     char lu = 0xc9, lb = 0xc8, ru = 0xbb, rb = 0xbc, hbar= 0xcd, vbar= 0xba;
  161.  
  162.     cls();
  163.  
  164.     /* Draw upper corners of box */
  165.  
  166.     SetCursor(8, 10);
  167.     putch(lu);
  168.     SetCursor(72, 10);
  169.     putch(ru);
  170.  
  171.     /* Draw horizontal section of box */
  172.  
  173.     for ( i = 9 ; i <= 71 ; i++)
  174.         {
  175.         SetCursor(i, 10);
  176.         putch(hbar);
  177.         SetCursor(i, 15);
  178.         putch(hbar);
  179.         }
  180.  
  181.     /* Draw lower corners of box */
  182.  
  183.     SetCursor(8, 15);
  184.     putch(lb);
  185.     SetCursor(72, 15);
  186.     putch(rb);
  187.  
  188.     /* Draw vertical section of box */
  189.  
  190.     for ( i = 11 ; i <= 14 ; i++ )
  191.         {
  192.         SetCursor(8, i);
  193.         putch(vbar);
  194.         SetCursor(72, i);
  195.         putch(vbar);
  196.         }
  197.  
  198.     SetCursor(15, 12);
  199.     puts("Microsoft (R) Mouse Test Program Version 1.00");
  200.     SetCursor(10, 13);
  201.     puts("Copyright (C) Microsoft Corp 1986-1989.  All rights reserved.");
  202.  
  203.     /* Display "mouse" hanging off of box */
  204.  
  205.     SetCursor(60, 15);
  206.     putch(0x5e);
  207.     SetCursor(60, 16);
  208.     putch(0x99);
  209.     SetCursor(60, 17);
  210.     putch(0xf5);
  211.  
  212.     /* set the text cursor to minimun  */
  213.  
  214.     inregs.h.ah = 1;
  215.     inregs.h.ch = 32;
  216.     inregs.h.cl = 0;
  217.     int86(0x10, &inregs, &outregs);
  218.     Pause(20);
  219. }
  220.  
  221. void
  222. CFunction12()
  223. {
  224.     unsigned conditionMask, buttonState;
  225.     int    horizCursorCoordinate, vertCursorCoordinate;
  226.     int    horizMouseCounts, vertMouseCounts;
  227.  
  228.     Function12Info(&conditionMask,
  229.                    &buttonState,
  230.                    &horizCursorCoordinate,
  231.                    &vertCursorCoordinate,
  232.                    &horizMouseCounts,
  233.                    &vertMouseCounts
  234.                   );
  235.     HideCursor();
  236.     SetCursor(0, 13);
  237.     BlankLine();
  238.     SetCursor(0, 13);
  239.     printf("Condition Mask = %x", conditionMask);
  240.     SetCursor(0, 14);
  241.     BlankLine();
  242.     SetCursor(0, 14);
  243.     printf("Button State = %x", buttonState);
  244.     SetCursor(0, 15);
  245.     BlankLine();
  246.     SetCursor(0, 15);
  247.     printf("Horizontal Cursor Coordinate = %d", horizCursorCoordinate);
  248.     SetCursor(0, 16);
  249.     BlankLine();
  250.     SetCursor(0, 16);
  251.     printf("Vertical Cursor Coordinate = %d", vertCursorCoordinate);
  252.     SetCursor(0, 17);
  253.     BlankLine();
  254.     SetCursor(0, 17);
  255.     printf("Horizontal Mouse Counts = %d", horizMouseCounts);
  256.     SetCursor(0, 18);
  257.     BlankLine();
  258.     SetCursor(0, 18);
  259.     printf("Vertical Mouse Counts = %d", vertMouseCounts);
  260.     ShowCursor();
  261. }
  262.  
  263. void
  264. SaveAndRestoreMouseDriverState()
  265. {
  266.     int X = 0;
  267.     int Y = 0;
  268.     unsigned buff;
  269.     int *bufptr;
  270.  
  271.     BlankMenu();
  272.     SetCursor(0, 7);
  273.     printf("Save & Restore Mouse Driver State Test:");
  274.     SetCursor(0, 11);
  275.     printf("Move Mouse Cursor to LOWER RIGHT corner\n");
  276.     printf("     then hit any key ...");
  277.     ShowCursor();
  278.     ShowCursor();
  279.     ShowCursor();
  280.     getch();
  281.     SetCursor(0, 11);
  282.     BlankLine();
  283.     SetCursor(0, 12);
  284.     BlankLine();
  285.     GetMouseDriverStateStorageRequirements(&buff);
  286.     if ((bufptr = malloc(buff)) == NULL) {
  287.         SetCursor(0, 15);
  288.         printf("Insufficient memory for this test routine.");
  289.         SetCursor(0, 18);
  290.         printf("Hit any key to EXIT");
  291.         getch();
  292.         HideCursor();
  293.         HideCursor();
  294.         HideCursor();
  295.         return;
  296.         }
  297.     SaveMouseDriverState(bufptr);
  298.     SetCursor(0, 11);
  299.     printf("Move cursor to another spot on screen");
  300.     SetCursor(0, 12);
  301.     BlankLine();
  302.     SetCursor(5, 12);
  303.     printf("hit a key when done moving...");
  304.     getch();
  305.     SetCursor(0, 11);
  306.     BlankLine();
  307.     SetCursor(0, 12);
  308.     BlankLine();
  309.     HideCursor();
  310.     RestoreMouseDriverState(bufptr);
  311.     SetCursor(0, 11);
  312.     printf("Is cursor back at LOWER RIGHT again ? ");
  313.     if (tolower(getch()) == 'y') {
  314.         SetCursor(0, 11);
  315.         BlankLine();
  316.         SetCursor(0, 11);
  317.         printf("Function 22 Save Driver State PASSED.\n");
  318.         printf("Function 23 Restore Driver State PASSED.");
  319.         }
  320.     else
  321.         {
  322.         SetCursor(0, 11);
  323.         BlankLine();
  324.         SetCursor(0, 11);
  325.         printf("Save & Restore Driver State FAILED.");
  326.         }
  327.  
  328.     free(bufptr);
  329.     SetCursor(0, 18);
  330.     printf("Hit any key to EXIT");
  331.     getch();
  332.     HideCursor();
  333.     HideCursor();
  334. }
  335.