home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MOUSE / MSMOUSE1.ZIP / C&QC.ZIP / CMOUSE.C next >
Encoding:
C/C++ Source or Header  |  1989-02-10  |  8.1 KB  |  303 lines

  1. /*-----------------------------------------------------------*/
  2. /*  CMOUSE.C - Mouse driver interface test                   */
  3. /*                                                           */
  4. /*  Demonstrates and verifies several of the most useful     */
  5. /*  mouse functions.                                         */
  6. /*                                                           */
  7. /*   cmousem() is for medium model (QuickC default).         */
  8. /*   For other memory models, replace cmousem() with the     */
  9. /*   appropriate function...                                 */
  10. /*      cmouses() - C small model                            */
  11. /*      cmousec() - C compact model                          */
  12. /*      cmousem() - C medium model                           */
  13. /*      cmousel() - C large or huge model                    */
  14. /*                                                           */
  15. /*  Microsoft C 5.1:                                         */
  16. /*       cl /AM cmouse.c -link mouse                         */
  17. /*                                                           */
  18. /*  QuickC:                                                  */
  19. /*       Program List.. CMOUSE.C, MOUSE.LIB                  */
  20. /*-----------------------------------------------------------*/
  21.  
  22. #include <stdio.h>
  23. #include <dos.h>
  24.  
  25. #define mouse(a, b, c, d)   cmousem(a, b, c, d)
  26.  
  27. #define M_RESET     0
  28. #define M_SHOW_CURS 1
  29. #define M_HIDE_CURS 2
  30. #define M_GET_STATUS    3
  31. #define M_SET_CURS  4
  32. #define M_GET_PRESS 5
  33. #define M_GET_REL   6
  34. #define M_SET_MAX_POS   7
  35. #define M_SET_MIN_POS   8
  36. #define M_SET_G_CURS    9
  37. #define M_SET_T_CURS    10
  38. #define M_READ_COUNT    11
  39. #define M_USER_SUB  12
  40. #define M_LPEN_ON   13
  41. #define M_LPEN_OFF  14
  42. #define M_MICK_2_PIX    15
  43. #define M_COND_OFF  16
  44. #define M_D_SPEED   19
  45.  
  46. #define XMAX        640
  47. #define YMAX        200
  48.  
  49. main()
  50. {
  51.     int m1, m2, m3, m4, m5;
  52.     int t, b, l, r;
  53.     int bounds[4];
  54.     int *bptr = bounds;
  55.  
  56.     cls();
  57.     chkdrv();
  58.  
  59.     m1 = M_RESET;
  60.     mouse(&m1, &m2, &m3, &m4);
  61.     if (m1)
  62.         {
  63.         printf("\nMouse driver installed, %d button mouse", m2);
  64.         }
  65.     else
  66.         {
  67.         printf("\nMouse driver not installed, exiting.");
  68.         return;
  69.         }
  70.  
  71.     test_graphics_cursor();
  72.  
  73.     m1 = M_SET_CURS;
  74.     m3 = XMAX;
  75.     m4 = YMAX/2;
  76.     mouse(&m1, &m2, &m3, &m4);
  77.  
  78.     m1 = M_SHOW_CURS;
  79.     mouse(&m1, &m2, &m3, &m4);
  80.  
  81.     printf("\nCursor should appear at end of middle line (press a key)...");
  82.     getch();
  83.  
  84.     t = 0;    b = YMAX;    l = 0;    r = XMAX;
  85.     do
  86.         {
  87.         circle(t, b, l, r);
  88.         t += 8;
  89.         b -= 8;
  90.         l += 8;
  91.         r -= 8;
  92.         }
  93.     while (t <= b);
  94.  
  95.     m1 = M_HIDE_CURS;
  96.     mouse(&m1, &m2, &m3, &m4);
  97.     cls();
  98.     m1 = M_SHOW_CURS;
  99.     mouse(&m1, &m2, &m3, &m4);
  100.  
  101.     printf("+----------------------------------------------------+\n");
  102.     printf("|  Test of conditional off function call.  Move the  |\n");
  103.     printf("|  cursor around, and verify that it disappears in   |\n");
  104.     printf("|  the area bounded by the dashed line.              |\n");
  105.     printf("|                                                    |\n");
  106.     printf("|  Press any key to redisplay the cursor.            |\n");
  107.     printf("|                                                    |\n");
  108.     printf("|  Press Esc when verified.                          |\n");
  109.     printf("+----------------------------------------------------+\n");
  110.  
  111.     do
  112.         {
  113.         m1 = M_SET_CURS;
  114.         m3 = XMAX;
  115.         m4 = YMAX / 2;
  116.         mouse(&m1, &m2, &m3, &m4);
  117.  
  118.         m1 = M_SHOW_CURS;
  119.         mouse(&m1, &m2, &m3, &m4);
  120.  
  121.         m1 = M_COND_OFF;
  122.         bounds[0] = 0;
  123.         bounds[1] = 0;
  124.         bounds[2] = 424;
  125.         bounds[3] = 64;
  126.         mouse(&m1, &m2, &m3, &bptr);
  127.         }
  128.     while (getch() != 0x1B);
  129.  
  130.     m1 = M_SHOW_CURS;
  131.     mouse(&m1, &m2, &m3, &m4);
  132.  
  133.     read_pos();
  134.  
  135.     printf("\n\n\nPress a key to terminate this program");
  136.     getch();
  137.     m1 = M_RESET;
  138.     mouse(&m1, &m2, &m3, &m4);
  139. }
  140.  
  141.  
  142. chkdrv()
  143. {
  144.     union REGS inregs, outregs;
  145.     struct SREGS segregs;
  146.     long address;
  147.     unsigned char first_byte;
  148.  
  149.     inregs.x.ax = 0x3533;
  150.     intdosx ( &inregs, &outregs, &segregs );
  151.  
  152.     address = (((long) segregs.es) << 16) + (long) outregs.x.bx;
  153.     first_byte = (unsigned char) * (long far *) address;
  154.  
  155.     if ((address == 0L) || (first_byte == 0xcf))
  156.         {
  157.         printf("Mouse driver NOT installed");
  158.         exit();
  159.         }
  160. }
  161.  
  162.  
  163. cls()
  164. {
  165.     union REGS inregs, outregs;
  166.  
  167.     inregs.x.ax = 0x0600;                /* Scroll up entire window */
  168.     inregs.h.bh = 7;                     /* Normal attribute */
  169.     inregs.x.cx = 0;                     /* Row 0, Col 0 */
  170.     inregs.x.dx = 0x184f;                /* Row 24, Col 79 */
  171.     int86(0x10, &inregs, &outregs);      /* Video interrupt */
  172.  
  173.     inregs.x.ax = 0x0200;                /* Set cursor position */
  174.     inregs.h.bh = 0;                     /* Page 0 */
  175.     inregs.x.dx = 0;                     /* Row 0, Col 0 */
  176.     int86(0x10, &inregs, &outregs);      /* Video interrupt */
  177. }
  178.  
  179.  
  180. #define VWAIT 100
  181. #define HWAIT 50
  182.  
  183. circle (t, b, l, r)                      /* Spiral the cursor position */
  184. int t, b, l, r;
  185. {
  186.     int m1, m2, m3, m4, i;
  187.  
  188.     m1 = M_SET_CURS;
  189.     m4 = t;
  190.  
  191.     for (m3 = l; m3 < r; m3++)
  192.         {
  193.         for (i=0; i < HWAIT; i++);
  194.         mouse(&m1, &m2, &m3, &m4);
  195.         }
  196.  
  197.     for (m4 = t; m4 < b; m4++)
  198.         {
  199.         for (i=0; i < VWAIT; i++);
  200.         mouse(&m1, &m2, &m3, &m4);
  201.         }
  202.  
  203.     for (; m3 >= l; m3--)
  204.         {
  205.         for (i=0; i < HWAIT; i++);
  206.         mouse(&m1, &m2, &m3, &m4);
  207.         }
  208.  
  209.     for (; m4 >= t; m4--)
  210.         {
  211.         for (i=0; i < VWAIT; i++);
  212.         mouse(&m1, &m2, &m3, &m4);
  213.         }
  214. }
  215.  
  216.  
  217. read_pos()
  218. {
  219.     int m1, m2, m3, m4;
  220.  
  221.     m1 = M_HIDE_CURS;
  222.     mouse(&m1, &m2, &m3, &m4);
  223.  
  224.     cls();
  225.  
  226.     m1 = M_SHOW_CURS;
  227.     mouse(&m1, &m2, &m3, &m4);
  228.  
  229.     printf("\nMove mouse to the UPPER-LEFT corner, RELEASE both buttons");
  230.     printf("\nand then press Enter: ");
  231.  
  232.     while(getch() != 0x0d)               /* Wait for the Enter key */
  233.         ;
  234.  
  235.     m1 = M_GET_STATUS;
  236.     mouse(&m1, &m2, &m3, &m4);
  237.  
  238.     if (m2 != 0)    printf("\nBUTTON INFO WRONG.");
  239.     if (m3 != 0)    printf("\nX VALUE WRONG, EXPECT 0, READ %d", m3);
  240.     if (m4 != 0)    printf("\nY VALUE WRONG, EXPECT 0, READ %d", m4);
  241.  
  242.     printf("\nMove mouse to the BOTTOM RIGHT corner, then simultaneously");
  243.     printf("\nPRESS both buttons and the Enter key: ");
  244.  
  245.     while(getch() != 0x0d)               /* Wait for the Enter key */
  246.         ;
  247.  
  248.     m1 = M_GET_STATUS;
  249.     mouse(&m1, &m2, &m3, &m4);
  250.  
  251.     if (m2 != 3)    printf("\nBUTTON INFO WRONG.");
  252.     if (m3 != 632)  printf("\nX VALUE WRONG, EXPECT 632, READ %d", m3);
  253.     if (m4 != 192)  printf("\nY VALUE WRONG, EXPECT 192, READ %d", m4);
  254. }
  255.  
  256.  
  257. test_graphics_cursor()
  258. {
  259.     static int cursor[32] =
  260.     {
  261.     /* SCREEN MASK FOR POINTING HAND */
  262.  
  263.     0xE1FF, 0xE1FF, 0xE1FF, 0xE1FF, 0xE1FF, 0, 0, 0,
  264.     0, 0, 0, 0, 0, 0, 0, 0,
  265.  
  266.     /* CURSOR MASK FOR POINTING HAND */
  267.  
  268.     0x1E00, 0x1200, 0x1200, 0x1200, 0x1200, 0x13FF, 0x1249, 0x1249,
  269.     0xF249, 0x9001, 0x9001, 0x9001, 0x8001, 0x8001, 0x8001, 0xFFFF
  270.     };
  271.  
  272.     int *cptr = cursor;
  273.     int m1, m2, m3, m4;
  274.  
  275.     video_mode(6);                       /* 640 X 200 B&W */
  276.  
  277.     m1 = 9;                              /* Set Graphics Cursor Block */
  278.     m2 = 0;
  279.     m3 = 0;
  280.     mouse(&m1, &m2, &m3, &cptr);
  281.  
  282.     m1 = 1;                              /* Show Cursor */
  283.     mouse(&m1, &m2, &m3, &m4);
  284.  
  285.     printf("\nCursor should now be a pointing hand.");
  286.     printf("\nMove around, press Enter when done...");
  287.  
  288.     getch();                             /* Wait for any key press */
  289.  
  290.     video_mode(3);
  291. }
  292.  
  293.  
  294. video_mode(mode)
  295. int mode;
  296. {
  297.     union REGS inregs, outregs;
  298.  
  299.     inregs.h.ah = 0;                     /* Set Video Mode */
  300.     inregs.h.al = mode;                  /* The mode */
  301.     int86(0x10, &inregs, &outregs);      /* Video Interrupt */
  302. }
  303.