home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12060a < prev    next >
Text File  |  1990-01-12  |  3KB  |  109 lines

  1.  
  2.  
  3.  
  4. /*      HEADER:        CUG0000;
  5.     TITLE:      Mouse Event Queue Test Driver;
  6.  
  7.     FILENAME:   TESTQ.C;
  8.  
  9.     COMPILER:   TURBO C V. 1.5+ Small Memory Model;
  10.  
  11.     REQUIRES:   TESTQ.PRJ, MOUSEQ.H, MOUSEQ.OBJ, TC_MOUSE.H,
  12.             TC_MOUSE.LIB, DEBUG.H, DEBUG.OBJ, HANDLER.OBJ;
  13.  
  14.     VERSION:    1.0;
  15.     DATE:       12/31/89;
  16.     AUTHOR:     Michael Kelly;
  17.  
  18. */
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <conio.h>
  23. #include <dos.h>
  24. #include "tc_mouse.h"
  25. #include "mouseq.h"
  26.  
  27. extern void far handler(void);  /* the mouse event handler */
  28.  
  29. #define DEBUG
  30.  
  31. #include "debug.h"
  32.  
  33.  
  34. #define write_char(c)  { video_buf = MK_FP(segg,ofset); *video_buf = (c); }
  35.  
  36.  
  37. unsigned int far *crt_address;
  38. unsigned int segg,ofset;
  39. unsigned char far *video_buf;
  40.  
  41. void main(void)
  42. {
  43.     int buttons = 0;
  44.     int result = 0;
  45.     unsigned int qsize = 256;
  46.  
  47.     crt_address = MK_FP(0x40,0x63);
  48.  
  49.     /*
  50.      *  x and y mouse coordinate conversion to text mode
  51.      *  row and column mouse cursor location assumes Ega or Cga
  52.      *  text mode 2 or 3
  53.      *
  54.      *  source must be modified for other video configurations
  55.      */
  56.     if(*crt_address == 0x03D4)
  57.     segg = 0xB800;
  58.     else
  59.     err_exit("  Program requires Ega or Cga Monitor");
  60.  
  61.     clrscr();
  62.  
  63.  
  64.     result = mouse_reset(&buttons); /* INT 33h FUNCTION 00h */
  65.     if(! result)
  66.     err_exit("    No mouse detected in System!");
  67.  
  68.     /*
  69.      *  attempt to create EVENT queue with qsize links
  70.      */
  71.     if(! set_que(qsize))
  72.     err_exit("  Mouse Event Queue Set Up Failure");
  73.  
  74.     printf(
  75.     "\n\tDrag Left Mouse Button  ...  or  ..."
  76.     "   Press Right Button to Quit\n"
  77.     );
  78.  
  79.  
  80.     mouse_show();   /* INT 33h FUNTION 01h */
  81.  
  82.     /*
  83.      *  INT 33h FUNTION 0Ch -- Register mouse EVENT handler
  84.      *
  85.      *  0x1f is EVENT mask (all EVENT bits set)
  86.      */
  87.     mouse_set_eventhandler(0x1f, handler);
  88.  
  89.     while(! (head->buttonbits & RIGHT_BUTTON))  {
  90.     if(head->valid)  {
  91.         /*
  92.          *  xcoord and ycoord are in pixels
  93.          *  ofset calc assumes 640 x 200 (cga or ega text modes 2 & 3)
  94.          *  you may have to alter for mono
  95.          */
  96.         ofset = ((head->ycoord >> 3) * 160) + ((head->xcoord >> 3) << 1);
  97.         if(head->buttonbits & LEFT_BUTTON)
  98.         write_char('Φ');
  99.         head->valid = 0;
  100.             head = head->next;
  101.     }
  102.     }
  103.  
  104.     mouse_hide();           /* INT 33h FUNCTION 02h */
  105.     mouse_reset(&buttons);  /* INT 33h FUNCTION 00h */
  106.     free_que();             /* destroy the EVENT queue */
  107.     clrscr();
  108. }
  109.