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

  1. /*-------------------------------------------------------------------------
  2.  *    Mouse cursor movement in different video mode test (Lib calls)
  3.  *
  4.  * Copyright (c) 1988-1989, Microsoft Corporation.  All rights reserved.
  5.  *
  6.  *        library :    MOUSE.LIB (6.25)
  7.  *        compiler :    Microsoft C (5.10)
  8.  *        run :        Make mouststx.mak
  9.  *                where x = s, c, m, or l for model
  10.  *        by : Ben Hsu    June 4, 1986
  11.  *             Ben Hsu    Feb. 29, 1988
  12.  *             Tom Hensel    March 10, 1988
  13.  *                Added missing mouse tests
  14.  *             Tom Hensel    November 11, 1988
  15.  *                Converted to 4 memory models
  16.  *
  17.  *        Disclaimer:    This code is example code only,
  18.  *                and does not warranty any product
  19.  *                as being Microsoft compatible.
  20.  *                Microsoft will not be held responsible
  21.  *                for claims made pertaining to this software.
  22.  *
  23.  -------------------------------------------------------------------------*/
  24.  
  25. #include "mousetst.h"
  26.  
  27.     unsigned originalSegment, originalCallMask, originalOffset;
  28.     int escState = 0, fUserSub = 0, cursorLevel = 0;
  29.     int videoMode, fLightPenBigVert = FALSE;
  30.  
  31. void
  32. main()
  33. {
  34.  
  35.     int status, cbuttons;
  36.     int buttonStatus = 0, testChoice;
  37.     unsigned originalSegmentTemp, originalCallMaskTemp, originalOffsetTemp;
  38.  
  39.     MouseResetAndStatus(&status, &cbuttons);
  40.     if (status == 0) {
  41.         puts("MOUSETST: Microsoft mouse not installed");
  42.         exit(0);
  43.         }
  44.  
  45.     /* Get original values and then restore them again */
  46.  
  47.     SwapInterruptSubroutines(&originalSegment,
  48.                              &originalCallMask,
  49.                              &originalOffset
  50.                             );
  51.     originalSegmentTemp = originalSegment;
  52.     originalCallMaskTemp = originalCallMask;
  53.     originalOffsetTemp = originalOffset;
  54.     SwapInterruptSubroutines(&originalSegmentTemp,
  55.                              &originalCallMaskTemp,
  56.                              &originalOffsetTemp
  57.                             );
  58.     VideoModeSaveRestore(SAVE);
  59.     ShowLogo();
  60.     cls();
  61.  
  62.     SetCursor(10, 3);
  63.     puts("Select video adapter to test:");
  64.     SetCursor(12, 5);
  65.     puts(" 0  for individual video mode test");
  66.     SetCursor(12, 6);
  67.     puts(" 1  for IBM Enhanced Graphics Adapter (EGA)");
  68.     SetCursor(12, 7);
  69.     puts(" 2  for IBM Color Graphics Adapter (CGA)");
  70.     SetCursor(12, 8);
  71.     puts(" 3  for IBM PS/2 Model 30 (MCGA)");
  72.     SetCursor(12, 9);
  73.     puts(" 4  for IBM PS/2 Model 50, 60, 80 (VGA)");
  74.     SetCursor(12, 10);
  75.     puts(" 5  for IBM Monochrome display Adapter");
  76.     SetCursor(12, 11);
  77.     puts(" 6  for AT&T (Olivetti) display");
  78.     SetCursor(12, 12);
  79.     puts(" 7  for Toshiba 2100, 3100 display");
  80.     SetCursor(10, 14);
  81.     puts("Any other key to EXIT");
  82.     ClearKB();
  83.     testChoice = getch();
  84.     cls();
  85.     switch (testChoice)
  86.         {
  87.     case '0':
  88.         IndividualTest();
  89.         break;
  90.     case '1':
  91.         EGATest();
  92.         break;
  93.     case '2':
  94.         CGATest();
  95.         break;
  96.     case '3':
  97.         MCGATest();
  98.         break;
  99.     case '4':
  100.         VGATest();
  101.         break;
  102.     case '5':
  103.         MONOTest();
  104.         break;
  105.     case '6':
  106.         ATTTest();
  107.         break;
  108.     case '7':
  109.         TOSHTest();
  110.         break;
  111.     default:
  112.         Cleanup();
  113.         exit(-1);
  114.         }
  115.  
  116.     Cleanup();
  117. }
  118.  
  119. void IndividualTest()
  120. {
  121.     int fGraphics;
  122.  
  123.     SetCursor(0, 5);
  124.     printf("Input video mode and text(0)/graphics flag(1) : ");
  125.     scanf("%u %u", &videoMode, &fGraphics);
  126.     cls();
  127.     /* fLightPenBigVert is unknown.  Set it to true if vertical scan
  128.        lines > 200 */
  129.  
  130.     if (fGraphics)
  131.         MouseTest(videoMode, INDIVIDUAL, GRAPHICS);
  132.     else
  133.         MouseTest(videoMode, INDIVIDUAL, TEXT);
  134.  
  135. }
  136.  
  137. void ATTTest()
  138. {
  139.  
  140.     for ( videoMode = 0; videoMode <= 3; videoMode++ )
  141.         MouseTest(videoMode, ATT, TEXT);
  142.  
  143.     for ( videoMode = 4; videoMode <= 6; videoMode++ )
  144.         MouseTest(videoMode, ATT, GRAPHICS);
  145.  
  146.     fLightPenBigVert = TRUE;
  147.     videoMode = 0x40;
  148.     MouseTest(videoMode, ATT, GRAPHICS);
  149.  
  150. }
  151.  
  152. void CGATest()
  153. {
  154.  
  155.     for ( videoMode = 0; videoMode <= 3; videoMode++ )
  156.         MouseTest(videoMode, CGA, TEXT);
  157.  
  158.     for ( videoMode = 4; videoMode <= 6; videoMode++ )
  159.         MouseTest(videoMode, CGA, GRAPHICS);
  160. }
  161.  
  162. void EGATest()
  163. {
  164.  
  165.     for ( videoMode = 0; videoMode <= 3; videoMode++ )
  166.         MouseTest(videoMode, EGA, TEXT);
  167.  
  168.     for ( videoMode = 4; videoMode <= 6; videoMode++ )
  169.         MouseTest(videoMode, EGA, GRAPHICS);
  170.  
  171.     for ( videoMode = 0xD; videoMode <= 0xE; videoMode++ )
  172.         MouseTest(videoMode, EGA, GRAPHICS);
  173.  
  174.     fLightPenBigVert = TRUE;
  175.     videoMode = 0x10;
  176.     MouseTest(videoMode, EGA, GRAPHICS);
  177.  
  178. }
  179.  
  180. void MCGATest()
  181. {
  182.  
  183.     for ( videoMode = 0; videoMode <= 3; videoMode++ )
  184.         MouseTest(videoMode, MCGA, TEXT);
  185.  
  186.     for ( videoMode = 4; videoMode <= 6; videoMode++ )
  187.         MouseTest(videoMode, MCGA, GRAPHICS);
  188.  
  189.     fLightPenBigVert = TRUE;
  190.     videoMode = 0x11;
  191.     MouseTest(videoMode, MCGA, GRAPHICS);
  192.  
  193.     videoMode = 0x13;
  194.     MouseTest(videoMode, MCGA, GRAPHICS);
  195.  
  196. }
  197.  
  198. void MONOTest()
  199. {
  200.  
  201.     videoMode = 7;
  202.     MouseTest(videoMode, MONO, TEXT);
  203. }
  204.  
  205. void TOSHTest()
  206. {
  207.  
  208.     for ( videoMode = 0; videoMode <= 3; videoMode++ )
  209.         MouseTest(videoMode, TOSH, TEXT);
  210.  
  211.     for ( videoMode = 4; videoMode <= 6; videoMode++ )
  212.         MouseTest(videoMode, TOSH, GRAPHICS);
  213.  
  214.     fLightPenBigVert = TRUE;
  215.     videoMode = 0x74;
  216.     MouseTest(videoMode, TOSH, GRAPHICS);
  217.  
  218. }
  219.  
  220. void VGATest()
  221. {
  222.  
  223.     for ( videoMode = 0; videoMode <= 3; videoMode++ )
  224.         MouseTest(videoMode, VGA, TEXT);
  225.  
  226.     for ( videoMode = 4; videoMode <= 6; videoMode++ )
  227.         MouseTest(videoMode, VGA, GRAPHICS);
  228.  
  229.     videoMode = 7;
  230.     MouseTest(videoMode, VGA, TEXT);
  231.  
  232.     for ( videoMode = 0xD; videoMode <= 0x13; videoMode++ )
  233.         {
  234.         if (videoMode == 0xF)
  235.             fLightPenBigVert = TRUE;
  236.         MouseTest(videoMode, VGA, GRAPHICS);
  237.         }
  238.  
  239. }
  240.  
  241. void MouseTest(videoMode, videoCard, fGraphics)
  242. int videoMode, videoCard, fGraphics;
  243. {
  244.  
  245.     int status, cbuttons;
  246.  
  247.     SetVideoMode(videoMode);
  248.  
  249.     switch (videoCard)
  250.         {
  251.     case INDIVIDUAL:
  252.         if (fGraphics)
  253.             printf("Individual Graphics Mode %xh\n", videoMode);
  254.         else
  255.             printf("Individual Text Mode %xh\n", videoMode);
  256.         break;
  257.     case ATT:
  258.         if (fGraphics)
  259.             printf("AT&T (Olivetti) Graphics Mode %xh\n",
  260.                    videoMode
  261.                   );
  262.         else
  263.             printf("AT&T (Olivetti) Text Mode %xh\n", videoMode);
  264.         break;
  265.     case CGA:
  266.         if (fGraphics)
  267.             printf("IBM CGA Graphics Mode %xh\n", videoMode);
  268.         else
  269.             printf("IBM CGA Text Mode %xh\n", videoMode);
  270.         break;
  271.     case EGA:
  272.         if (fGraphics)
  273.             printf("IBM EGA Graphics Mode %xh\n", videoMode);
  274.         else
  275.             printf("IBM EGA Text Mode %xh\n", videoMode);
  276.         break;
  277.     case MCGA:
  278.         if (fGraphics)
  279.             printf("IBM PS/2 Model 30 Graphics Mode %xh\n",
  280.                    videoMode
  281.                   );
  282.         else
  283.             printf("IBM PS/2 Model 30 Text Mode %xh\n", videoMode);
  284.         break;
  285.     case MONO:
  286.         printf("\nIBM Monochrome Text Mode %xh\n", videoMode);
  287.         break;
  288.     case VGA:
  289.         if (fGraphics)
  290.             printf("IBM PS/2 Model 50,60,80 Graphics Mode %xh\n",
  291.                    videoMode
  292.                   );
  293.         else
  294.             printf("IBM PS/2 Model 50,60,80 Text Mode %xh\n",
  295.                    videoMode
  296.                   );
  297.         break;
  298.     case TOSH:
  299.         if (fGraphics)
  300.             printf("Toshiba 2100, 3100 Graphics Mode %xh\n",
  301.                    videoMode
  302.                   );
  303.         else
  304.             printf("Toshiba 2100, 3100 Text Mode %xh\n", videoMode);
  305.         break;
  306.     default:
  307.         printf("Unknown video card Mode %xh\n", videoMode);
  308.         break;
  309.         }
  310.  
  311.     printf("LEFT  Button for current mouse location\n");
  312.     printf("RIGHT Button or key to select functions\n");
  313.     printf("BOTH  Buttons to change video mode\n");
  314.     printf("ESC   Key to toggle light pen emulation");
  315.     MouseResetAndStatus(&status, &cbuttons);
  316.  
  317.     if (fGraphics)
  318.         GMouse();
  319.  
  320.     ShowCursor();
  321.     ScreenPixel();
  322.     cursorLevel = 0;    /* New mode re-initializes cursor level */
  323.     fUserSub = 0;        /* No user sub defined */
  324. }
  325.  
  326. void ScreenPixel()
  327. {
  328.  
  329.     int buttonStatus = 0;
  330.     unsigned horizontalPosition, verticalPosition, row = 0, column = 0;
  331.  
  332.     MInput(&buttonStatus, &horizontalPosition, &verticalPosition);
  333.     while (buttonStatus != BOTH) {
  334.         if (buttonStatus == RIGHT) {
  335.             HideCursor();
  336.             SetCursor(0, 1);
  337.             BlankLine();
  338.             SetCursor(0, 2);
  339.             BlankLine();
  340.             SetCursor(0, 3);
  341.             BlankLine();
  342.             SetCursor(0, 4);
  343.             BlankLine();
  344.             SetCursor(0, 5);
  345.             BlankLine();
  346.             SetCursor(0, 3);
  347.             cprintf("Mouse Function Call Test Menu:");
  348.             FunctionSelect();
  349.             SetCursor(0, 1);
  350.             printf("LEFT  Button for current mouse location\n");
  351.             printf("RIGHT Button or key to select functions\n");
  352.             printf("BOTH  Buttons to change video mode\n");
  353.             printf("ESC   Key to toggle light pen emulation\n");
  354.             BlankLine();
  355.             ShowCursor();
  356.             }
  357.         else if (buttonStatus == LEFT) {
  358.             HideCursor();
  359.             SetCursor(0, 5);
  360.             BlankLine();
  361.             SetCursor(0, 5);
  362.             printf("x=%d, y=%d", horizontalPosition, verticalPosition);
  363.             ShowCursor();
  364.             }
  365.         else {
  366.             HideCursor();
  367.             SetCursor(0, 5);
  368.             BlankLine();
  369.             ReadLightPenPosition(&horizontalPosition,
  370.                                  &verticalPosition,
  371.                                  &row,
  372.                                  &column
  373.                                 );
  374.  
  375.             if (! fLightPenBigVert)
  376.             verticalPosition >>= 8;
  377.  
  378.             SetCursor(0, 5);
  379.             printf("x=%u, y=%u, row = %u, column = %u",
  380.                    horizontalPosition,
  381.                    verticalPosition,
  382.                    row,
  383.                    column
  384.                   );
  385.             ShowCursor();
  386.             }
  387.  
  388.         if (fUserSub)
  389.             CFunction12();
  390.         buttonStatus = 0;
  391.         MInput(&buttonStatus, &horizontalPosition, &verticalPosition);
  392.         }
  393.  
  394. }
  395.  
  396. void GMouse()
  397. {
  398.     int horizontalHotSpot = 1, verticalHotSpot = 1;
  399.     static int screenAndCursorMasks[] =
  400.     {
  401.     /*  screen mask  */
  402.     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  403.     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  404.     /*  cursor mask  */
  405.     0x0780, 0xb8b8, 0x3060, 0x6038, 0xf07e, 0x8841, 0xf031, 0x7020,
  406.     0x401c, 0x6006, 0x3c06, 0x03fe, 0x0001, 0xf001, 0x0301, 0x007c
  407.     };
  408.  
  409.     SetGraphicsCursorBlock(horizontalHotSpot,
  410.                            verticalHotSpot,
  411.                            screenAndCursorMasks
  412.                           );
  413. }
  414.  
  415. void MInput(pButtonStatus, pHorizontalPosition, pVerticalPosition)
  416.     int *pButtonStatus;
  417.     int *pHorizontalPosition;
  418.     int *pVerticalPosition;
  419. {
  420.  
  421.     int key;
  422.  
  423.     while ( *pButtonStatus != LEFT &&
  424.             *pButtonStatus != RIGHT &&
  425.             *pButtonStatus != BOTH
  426.           )
  427.         {
  428.  
  429.         if (key = getchnowait())
  430.             {
  431.             if ((key & 0xFF) == ESC)
  432.                 escState ^= -1;
  433.             else
  434.                 *pButtonStatus = RIGHT;
  435.             break;
  436.             }
  437.         if (escState)
  438.             break;
  439.         else
  440.             GetButtonStatusAndMousePosition(pButtonStatus,
  441.                                             pHorizontalPosition,
  442.                                             pVerticalPosition
  443.                                            );
  444.         }
  445. }
  446.