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

  1. /*
  2.  * menu.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. void FunctionSelect()
  20. {
  21.  
  22.     int function;
  23.     int bStatus, hPosition, vPosition;
  24.     int mouseStatus, numberOfButtons;
  25.     int status, buttonPresses, horizontalCursor, verticalCursor;
  26.     unsigned horizontalCoordinate, verticalCoordinate;
  27.     unsigned minimumPosition, maximumPosition;
  28.  
  29.     BlankMenu();
  30.     SetCursor(0, 7);
  31.     printf("Select number to test mouse function");
  32.     SetCursor(0, 9);
  33.     printf("0 - Mouse reset and status\n");
  34.     printf("1 - Show cursor\n");
  35.     if (cursorLevel)
  36.         printf("2 - Hide cursor (level = %d)\n", cursorLevel);
  37.     else
  38.         printf("2 - Hide cursor\n");
  39.     printf("3 - Get button status and mouse position");
  40.     SetCursor(0, 13);
  41.     printf("4 - Set mouse cursor position\n");
  42.     printf("5 - Get button press information\n");
  43.     printf("6 - Get button release information\n");
  44.     printf("7 - Set min & max horiz cursor position\n");
  45.     printf("8 - Select next menu\n");
  46.     printf("9 to EXIT");
  47.     ClearKB();
  48.  
  49.     switch (function = getch())
  50.         {
  51.     case '0':
  52.         MouseResetAndStatus(&mouseStatus, &numberOfButtons);
  53.         cursorLevel = fUserSub = 0;
  54.         SetCursor(0, 9);
  55.         BlankLine();
  56.         SetCursor(0, 9);
  57.         printf("status = %d, # of buttons = %d",
  58.                mouseStatus,
  59.                numberOfButtons
  60.               );
  61.         SetCursor(0, 18);
  62.         printf("Hit any key to EXIT");
  63.         getch();
  64.         break;
  65.     case '1':
  66.         ShowCursor();
  67.  
  68.         if (cursorLevel != 0)
  69.             cursorLevel--;
  70.  
  71.         break;
  72.     case '2':
  73.         HideCursor();
  74.         cursorLevel++;
  75.         break;
  76.     case '3':
  77.         SetCursor(0, 4);
  78.         printf("_____  button pressed at X=__, Y=__\n");
  79.         printf("Press BOTH button to quit testing.");
  80.         ShowCursor();
  81.         MInput(&bStatus, &hPosition, &vPosition);
  82.         while (bStatus != BOTH) {
  83.             HideCursor();
  84.             SetCursor(0, 4);
  85.             BlankLine();
  86.             SetCursor(0, 4);
  87.             if (bStatus == LEFT)
  88.             printf("LEFT  ");
  89.             else
  90.             printf("RIGHT ");
  91.             printf("button pressed at X=%d, Y=%d",
  92.                    hPosition,
  93.                    vPosition
  94.                   );
  95.             ShowCursor();
  96.             bStatus = 0;
  97.             MInput(&bStatus, &hPosition, &vPosition);
  98.             }
  99.         HideCursor();
  100.         SetCursor(0, 4);
  101.         BlankLine();
  102.         SetCursor(0, 5);
  103.         BlankLine();
  104.         break;
  105.     case '4':
  106.         SetCursor(0, 14);
  107.         BlankLine();
  108.         SetCursor(0, 14);
  109.         printf("Input x and y : ");
  110.         scanf("%u %u", &horizontalCoordinate, &verticalCoordinate);
  111.         SetMouseCursorPosition(horizontalCoordinate,
  112.                                verticalCoordinate
  113.                               );
  114.         break;
  115.     case '5':
  116.         SetCursor(0, 15);
  117.         BlankLine();
  118.         SetCursor(0, 15);
  119.         printf("Input button (0 = Left, 1 = Right) : ");
  120.         scanf("%d", &buttonPresses);
  121.         GetButtonPressInformation(&status,
  122.                                   &buttonPresses,
  123.                                   &horizontalCursor,
  124.                                   &verticalCursor
  125.                                  );
  126.         SetCursor(0, 15);
  127.         BlankLine();
  128.         SetCursor(0, 15);
  129.         printf("M1 = %d, M2 = %d, M3 = %d, M4 = %d",
  130.                status,
  131.                buttonPresses,
  132.                horizontalCursor,
  133.                verticalCursor
  134.               );
  135.         SetCursor(0, 18);
  136.         printf("Hit any key to EXIT");
  137.         getch();
  138.         break;
  139.     case '6':
  140.         SetCursor(0, 16);
  141.         BlankLine();
  142.         SetCursor(0, 16);
  143.         printf("Input button (0 = Left, 1 = Right) : ");
  144.         scanf("%d", &buttonPresses);
  145.         GetButtonReleaseInformation(&status,
  146.                                     &buttonPresses,
  147.                                     &horizontalCursor,
  148.                                     &verticalCursor
  149.                                    );
  150.         SetCursor(0, 16);
  151.         BlankLine();
  152.         SetCursor(0, 16);
  153.         printf("M1 = %d, M2 = %d, M3 = %d, M4 = %d",
  154.                status,
  155.                buttonPresses,
  156.                horizontalCursor,
  157.                verticalCursor
  158.               );
  159.         SetCursor(0, 18);
  160.         printf("Hit any key to EXIT");
  161.         getch();
  162.         break;
  163.     case '7':
  164.         SetCursor(0, 17);
  165.         BlankLine();
  166.         SetCursor(0, 17);
  167.         printf("Input x min and x max : ");
  168.         scanf("%u %u", &minimumPosition, &maximumPosition);
  169.         SetMinimumAndMaximumHorizontalCursorPosition(minimumPosition,
  170.                                                      maximumPosition
  171.                                                     );
  172.         break;
  173.     case '8':
  174.         Menu2();
  175.         ShowCursor();
  176.         return;
  177.     default:
  178.         break;
  179.         }
  180.  
  181.     if (function == '1')
  182.         HideCursor();
  183.  
  184.     BlankMenu();
  185.  
  186.     if (function == '1')
  187.         ShowCursor();
  188.  
  189. }
  190.  
  191. void Menu2()
  192. {
  193.  
  194.     unsigned minimumPosition, maximumPosition;
  195.     unsigned screenMask, cursorMask;
  196.     int scanLineStart, scanLineStop;
  197.     int horizontalCount, verticalCount;
  198.     unsigned horizontalMickeyPixelRatio, verticalMickeyPixelRatio;
  199.     unsigned callMask;
  200.  
  201.     BlankMenu();
  202.     HideCursor();
  203.     SetCursor(0, 7);
  204.     printf("Select number to test mouse function");
  205.     SetCursor(0, 9);
  206.     printf("0 - Set min & max vert cursor position\n");
  207.     printf("1 - Function #9 already tested\n");
  208.     printf("2 - Set text cursor\n");
  209.     printf("3 - Read mouse motion counters\n");
  210.     printf("4 - Set int sub call mask & address\n");
  211.     printf("5 - Light pen emulation mode on\n");
  212.     printf("6 - Light pen emulation mode off\n");
  213.     printf("7 - Set mickey/pixel ratio\n");
  214.     printf("8 - Select next menu\n");
  215.     printf("9 to EXIT");
  216.     ClearKB();
  217.  
  218.     switch (getch())
  219.         {
  220.     case '0':
  221.         SetCursor(0, 9);
  222.         BlankLine();
  223.         SetCursor(0, 9);
  224.         printf("Input y min and y max : ");
  225.         scanf("%u %u", &minimumPosition, &maximumPosition);
  226.         SetMinimumAndMaximumVerticalCursorPosition(minimumPosition,
  227.                                                    maximumPosition
  228.                                                   );
  229.         break;
  230.     case '2':
  231.         SetCursor(0, 11);
  232.         BlankLine();
  233.         SetCursor(0, 11);
  234.         printf("Input cursor (0 = soft, 1 = hard) : ");
  235.         if (getch() == '0')
  236.             {
  237.             SetCursor(0, 11);
  238.             BlankLine();
  239.             SetCursor(0, 11);
  240.             printf("Input screen & cursor masks : ");
  241.             scanf("%x %x", &screenMask, &cursorMask);
  242.             SetTextCursor(0, screenMask, cursorMask);
  243.             }
  244.         else
  245.             {
  246.             SetCursor(0, 11);
  247.             BlankLine();
  248.             SetCursor(0, 11);
  249.             printf("Input line start & line stop : ");
  250.             scanf("%d %d", &scanLineStart, &scanLineStop);
  251.             /* Must print message here since it moves cursor */
  252.             SetCursor(0, 18);
  253.             printf("Hit any key to EXIT");
  254.             SetTextCursor(1, scanLineStart, scanLineStop);
  255.             ShowCursor();
  256.             ShowCursor();
  257.             getch();
  258.             HideCursor();
  259.             HideCursor();
  260.             }
  261.         break;
  262.     case '3':
  263.         ReadMouseMotionCounters(&horizontalCount, &verticalCount);
  264.         SetCursor(0, 12);
  265.         BlankLine();
  266.         SetCursor(0, 12);
  267.         printf("horiz count = %d, vert count = %d",
  268.                horizontalCount,
  269.                verticalCount
  270.               );
  271.         SetCursor(0, 18);
  272.         printf("Hit any key to EXIT");
  273.         getch();
  274.         break;
  275.     case '4':
  276.         SetCursor(0, 13);
  277.         BlankLine();
  278.         SetCursor(0, 13);
  279.         printf("Input call mask : ");
  280.         scanf("%x", &callMask);
  281.         SetInterruptSubroutineCallMaskAndAddress(callMask, Function12);
  282.         fUserSub++;
  283.         break;
  284.     case '5':
  285.         LightPenEmulationModeOn();
  286.         break;
  287.     case '6':
  288.         LightPenEmulationModeOff();
  289.         break;
  290.     case '7':
  291.         SetCursor(0, 16);
  292.         BlankLine();
  293.         SetCursor(0, 16);
  294.         printf("Input horiz & vert ratios : ");
  295.         scanf("%u %u",
  296.               &horizontalMickeyPixelRatio,
  297.               &verticalMickeyPixelRatio
  298.              );
  299.         SetMickeyPixelRatio(horizontalMickeyPixelRatio,
  300.                             verticalMickeyPixelRatio
  301.                            );
  302.         break;
  303.     case '8':
  304.         Menu3();
  305.         ShowCursor();
  306.         return;
  307.     default:
  308.         break;
  309.         }
  310.  
  311.     BlankMenu();
  312.     ShowCursor();
  313. }
  314.  
  315. void Menu3()
  316. {
  317.  
  318.     unsigned conditionalOffRegion[4];
  319.     unsigned thresholdSpeed;
  320.     unsigned storageSize;
  321.     unsigned eventMask;
  322.     int errorStatus;
  323.     unsigned callMask;
  324.     unsigned segment, offset;
  325.     void (*pFunction)();
  326.  
  327.     BlankMenu();
  328.     HideCursor();
  329.     SetCursor(0, 7);
  330.     printf("Select number to test mouse function");
  331.     SetCursor(0, 9);
  332.     printf("0 - Conditional off\n");
  333.     printf("1 - Set double-speed threshold\n");
  334.     printf("2 - Swap interrupt subroutines\n");
  335.     printf("3 - Get mouse storage requirements\n");
  336.     printf("4 - Save & Restore mouse driver state\n");
  337.     printf("5 - Save & Restore mouse driver state\n");
  338.     printf("6 - Set alternate mouse user sub\n");
  339.     printf("7 - Get user alternate int vector\n");
  340.     printf("8 - Select next menu\n");
  341.     printf("9 to EXIT");
  342.     ClearKB();
  343.  
  344.     switch (getch())
  345.         {
  346.     case '0':
  347.         SetCursor(0, 9);
  348.         BlankLine();
  349.         SetCursor(0, 9);
  350.         printf("Input left x & upper y : ");
  351.         scanf("%u %u",
  352.               &conditionalOffRegion[0],
  353.               &conditionalOffRegion[1]
  354.              );
  355.         SetCursor(0, 9);
  356.         BlankLine();
  357.         SetCursor(0, 9);
  358.         printf("Input right x & lower y : ");
  359.         scanf("%u %u",
  360.               &conditionalOffRegion[2],
  361.               &conditionalOffRegion[3]
  362.              );
  363.         SetCursor(0, 18);
  364.         printf("Hit any key to EXIT");
  365.         ShowCursor();
  366.         ShowCursor();
  367.         ShowCursor();
  368.         ConditionalOff((int *)conditionalOffRegion);
  369.         getch();
  370.         HideCursor();
  371.         HideCursor();
  372.         HideCursor();
  373.         break;
  374.     case '1':
  375.         SetCursor(0, 10);
  376.         BlankLine();
  377.         SetCursor(0, 10);
  378.         printf("Input threshold speed : ");
  379.         scanf("%u", &thresholdSpeed);
  380.         SetDoubleSpeedThreshold(thresholdSpeed);
  381.         break;
  382.     case '2':
  383.         SetCursor(0, 11);
  384.         BlankLine();
  385.         SetCursor(0, 11);
  386.         printf("Input call mask : ");
  387.         scanf("%x", &callMask);
  388.         pFunction = Function12;
  389.         segment = FP_SEG(pFunction);
  390.         offset = FP_OFF(pFunction);
  391.  
  392. /* Note:  Segment doesn't need to be passed for small and compact models,
  393.    mouse lib knows it */
  394.  
  395.         SwapInterruptSubroutines(&segment,
  396.                                  &callMask,
  397.                                  &offset
  398.                                 );
  399.         SetCursor(0, 11);
  400.         BlankLine();
  401.         SetCursor(0, 11);
  402.         printf("segment:%x, offset:%x, call mask:%x",
  403.                segment,
  404.                offset,
  405.                callMask
  406.               );
  407.         SetCursor(0, 18);
  408.         printf("Hit any key to EXIT");
  409.         getch();
  410.         fUserSub++;
  411.         break;
  412.     case '3':
  413.         SetCursor(0, 12);
  414.         BlankLine();
  415.         SetCursor(0, 12);
  416.         GetMouseDriverStateStorageRequirements(&storageSize);
  417.         printf("Required Storage Buffer Size = %d bytes", storageSize);
  418.         SetCursor(0, 18);
  419.         printf("Hit any key to EXIT");
  420.         getch();
  421.         break;
  422.     case '4':
  423.     case '5':
  424.         SaveAndRestoreMouseDriverState();
  425.         break;
  426.     case '6':
  427.         SetCursor(0, 15);
  428.         BlankLine();
  429.         SetCursor(0, 15);
  430.         printf("Input event mask : ");
  431.         scanf("%x", &eventMask);
  432.         SetAlternateMouseUserSubroutine(&errorStatus,
  433.                                         eventMask,
  434.                                         Function12
  435.                                        );
  436.  
  437.         if (errorStatus == -1)
  438.             {
  439.             SetCursor(0, 15);
  440.             BlankLine();
  441.             SetCursor(0, 15);
  442.             printf("Error occured");
  443.             SetCursor(0, 18);
  444.             printf("Hit any key to EXIT");
  445.             getch();
  446.             }
  447.         fUserSub++;
  448.         break;
  449.     case '7':
  450.         SetCursor(0, 16);
  451.         BlankLine();
  452.         SetCursor(0, 16);
  453.         printf("Input event mask : ");
  454.         scanf("%x", &eventMask);
  455.         GetUserAlternateInterruptVector(&segment, &eventMask, &offset);
  456.         SetCursor(0, 16);
  457.         BlankLine();
  458.         SetCursor(0, 16);
  459.         printf("segment:%x, offset:%x, event mask:%x",
  460.                segment,
  461.                offset,
  462.                eventMask
  463.               );
  464.         SetCursor(0, 18);
  465.         printf("Hit any key to EXIT");
  466.         getch();
  467.         break;
  468.     case '8':
  469.         Menu4();
  470.         ShowCursor();
  471.         return;
  472.     default:
  473.         break;
  474.         }
  475.  
  476.     BlankMenu();
  477.     ShowCursor();
  478. }
  479.  
  480. void Menu4()
  481. {
  482.  
  483.     int horizontalSensitivity, verticalSensitivity, doubleSpeedThreshold;
  484.     int interruptRate;
  485.     int CRTPageNumber;
  486.     int mouseStatus, numberOfButtons;
  487.     unsigned segment, offset;
  488.     int errorStatus;
  489.  
  490.     BlankMenu();
  491.     HideCursor();
  492.     SetCursor(0, 7);
  493.     printf("Select number to test mouse function");
  494.     SetCursor(0, 9);
  495.     printf("0 - Set mouse sensitivity\n");
  496.     printf("1 - Get mouse sensitivity\n");
  497.     printf("2 - Set mouse maximum interrupt rate\n");
  498.     printf("3 - Set CRT page number\n");
  499.     printf("4 - Get CRT page number\n");
  500.     printf("5 - Disable mouse driver\n");
  501.     printf("6 - Enable mouse driver\n");
  502.     printf("7 - Software reset\n");
  503.     printf("8 - Select next menu\n");
  504.     printf("9 to EXIT");
  505.     ClearKB();
  506.  
  507.     switch (getch())
  508.         {
  509.     case '0':
  510.         SetCursor(0, 9);
  511.         BlankLine();
  512.         SetCursor(0, 9);
  513.         printf("Input horiz & vert sensitivity : ");
  514.         scanf("%d %d", &horizontalSensitivity, &verticalSensitivity);
  515.         SetCursor(0, 9);
  516.         BlankLine();
  517.         SetCursor(0, 9);
  518.         printf("Input double speed threshold : ");
  519.         scanf("%d", &doubleSpeedThreshold);
  520.         SetMouseSensitivity(horizontalSensitivity,
  521.                             verticalSensitivity,
  522.                             doubleSpeedThreshold
  523.                            );
  524.         break;
  525.     case '1':
  526.         GetMouseSensitivity(&horizontalSensitivity,
  527.                             &verticalSensitivity,
  528.                             &doubleSpeedThreshold
  529.                            );
  530.         SetCursor(0, 10);
  531.         BlankLine();
  532.         SetCursor(0, 10);
  533.         printf("horiz = %d, vert = %d, threshold = %d",
  534.                horizontalSensitivity,
  535.                verticalSensitivity,
  536.                doubleSpeedThreshold
  537.               );
  538.         SetCursor(0, 18);
  539.         printf("Hit any key to EXIT");
  540.         getch();
  541.         break;
  542.     case '2':
  543.         SetCursor(0, 11);
  544.         BlankLine();
  545.         SetCursor(0, 11);
  546.         printf("Input interrupt rate : ");
  547.         scanf("%d", &interruptRate);
  548.         SetMouseInterruptRate(interruptRate);
  549.         break;
  550.     case '3':
  551.         SetCursor(0, 12);
  552.         BlankLine();
  553.         SetCursor(0, 12);
  554.         printf("Input CRT page number : ");
  555.         scanf("%d", &CRTPageNumber);
  556.         SetCRTPageNumber(CRTPageNumber);
  557.         break;
  558.     case '4':
  559.         GetCRTPageNumber(&CRTPageNumber);
  560.         SetCursor(0, 13);
  561.         BlankLine();
  562.         SetCursor(0, 13);
  563.         printf("CRT page number = %d", CRTPageNumber);
  564.         SetCursor(0, 18);
  565.         printf("Hit any key to EXIT");
  566.         getch();
  567.         break;
  568.     case '5':
  569.         DisableMouseDriver(&errorStatus,
  570.                            &offset,
  571.                            &segment
  572.                           );
  573.         if (errorStatus != 31)
  574.             {
  575.             SetCursor(0, 14);
  576.             BlankLine();
  577.             SetCursor(0, 14);
  578.             printf("Error occured");
  579.             }
  580.         else
  581.             {
  582.             SetCursor(0, 14);
  583.             BlankLine();
  584.             SetCursor(0, 14);
  585.             printf("segment:%x, offset:%x", segment, offset);
  586.             }
  587.         SetCursor(0, 18);
  588.         printf("Hit any key to EXIT");
  589.         getch();
  590.         break;
  591.     case '6':
  592.         EnableMouseDriver();
  593.         break;
  594.     case '7':
  595.         SoftwareReset(&mouseStatus, &numberOfButtons);
  596.         cursorLevel = fUserSub = 0;
  597.         SetCursor(0, 16);
  598.         BlankLine();
  599.         SetCursor(0, 16);
  600.         printf("status = %d, # of buttons = %d",
  601.                mouseStatus,
  602.                numberOfButtons
  603.               );
  604.         SetCursor(0, 18);
  605.         printf("Hit any key to EXIT");
  606.         getch();
  607.         break;
  608.     case '8':
  609.         Menu5();
  610.         ShowCursor();
  611.         return;
  612.     default:
  613.         break;
  614.         }
  615.  
  616.     BlankMenu();
  617.     ShowCursor();
  618. }
  619.  
  620. void Menu5()
  621. {
  622.  
  623.     int languageNumber;
  624.     int majorVersionNumber, minorVersionNumber, mouseType, IRQNumber;
  625.  
  626.     BlankMenu();
  627.     HideCursor();
  628.     SetCursor(0, 7);
  629.     printf("Select number to test mouse function");
  630.     SetCursor(0, 9);
  631.     printf("0 - Set language number\n");
  632.     printf("1 - Get language number\n");
  633.     printf("2 - Get version number, type, and IRQ #");
  634.     SetCursor(0, 17);
  635.     printf("8 - Select first menu\n");
  636.     printf("9 to EXIT");
  637.     ClearKB();
  638.  
  639.     switch (getch())
  640.         {
  641.     case '0':
  642.         SetCursor(0, 9);
  643.         BlankLine();
  644.         SetCursor(0, 9);
  645.         printf("Input language number : ");
  646.         scanf("%d", &languageNumber);
  647.         SetLanguageForMessages(languageNumber);
  648.         break;
  649.     case '1':
  650.         GetLanguageNumber(&languageNumber);
  651.         SetCursor(0, 10);
  652.         BlankLine();
  653.         SetCursor(0, 10);
  654.         printf("Language number = %d", languageNumber);
  655.         SetCursor(0, 18);
  656.         printf("Hit any key to EXIT");
  657.         getch();
  658.         break;
  659.     case '2':
  660.         GetDriverVersionMouseTypeAndIRQNumber(&majorVersionNumber,
  661.                                               &minorVersionNumber,
  662.                                               &mouseType,
  663.                                               &IRQNumber
  664.                                              );
  665.         BlankMenu();
  666.         SetCursor(0, 11);
  667.         printf("Mouse driver version number = %x.%x\n",
  668.                majorVersionNumber,
  669.                minorVersionNumber
  670.               );
  671.         printf("Mouse type = %d, IRQ # = %d", mouseType, IRQNumber);
  672.         SetCursor(0, 18);
  673.         printf("Hit any key to EXIT");
  674.         getch();
  675.         break;
  676.     case '8':
  677.         FunctionSelect();
  678.         ShowCursor();
  679.         return;
  680.     default:
  681.         break;
  682.         }
  683.  
  684.     BlankMenu();
  685.     ShowCursor();
  686. }
  687.