home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / fractal / fdesi313 / fdes13s / fdesmous.c < prev    next >
Text File  |  1989-11-25  |  6KB  |  194 lines

  1. /*
  2.         Routines for mouse
  3. */
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include "fdestria.h"
  7. #include "fdesign.h"
  8. #include "fdesequa.h"
  9. #include "fdesfile.h"
  10. #include "fdesmenu.h"
  11. #include "fdesplot.h"
  12.  
  13. typedef struct {
  14.     int row,col,buttons;
  15.     } mouse_state;
  16. #define MOUSE_LEFT 1
  17. #define MOUSE_RIGHT 2
  18.  
  19. int mouse_is;                    /* if nonzero, there is a mouse */
  20. int use_grat;
  21. /************************************************************************
  22.         MOUSE STUFF
  23. ************************************************************************/
  24. /*
  25.     this is to be the mouse cursor pixel array
  26.         16 words screen mask
  27.         16 words cursor mask
  28. */
  29. int m_cursor[32] = {
  30.     0xffff,           /* (2)x0000000000000000, */
  31.         0x8fff,           /* (2)x0111000000000000, */
  32.     0x81ff,           /* (2)x0111111000000000, */
  33.     0x803f,           /* (2)x0111111111000000, */
  34.     0x8007,           /* (2)x0111111111111000, */
  35.     0x8000,           /* (2)x0111111111111111, */
  36.     0x8007,           /* (2)x0111111111111000, */
  37.     0x803f,           /* (2)x0111111111000000, */
  38.     0x827f,           /* (2)x0111110110000000, */
  39.     0x9f3f,           /* (2)x0110000011000000, */
  40.         0xff9f,           /* (2)x0000000001100000, */
  41.         0xffcf,           /* (2)x0000000000110000, */
  42.         0xffe7,           /* (2)x0000000000011000, */
  43.     0xffff,           /* (2)x0000000000000000, */
  44.     0xffff,           /* (2)x0000000000000000, */
  45.     0xffff,           /* (2)x0000000000000000  */
  46.  
  47.         0x0000,
  48.         0x7000,
  49.         0x7e00,
  50.         0x7fc0,
  51.         0x7ff8,
  52.         0x7fff,
  53.         0x7ff8,
  54.         0x7fc0,
  55.         0x7d80,
  56.         0x60c0,
  57.         0x0060,
  58.         0x0030,
  59.         0x0018,
  60.         0x0000,
  61.         0x0000,
  62.         0x0000
  63.         } ;
  64.  
  65. int mouse_reset(void)           /* returns -1 if ok, 0 if no mouse driver */
  66. {
  67. int rcode;
  68. struct REGPACK regs;
  69.         regs.r_ax = 0x0000;             /* mouse reset */
  70.         intr(0x33,®s);
  71.         rcode = regs.r_ax;
  72.         if (rcode != 0) {               /* NOTE: return code */
  73.                 regs.r_ax = 0x0009;     /* mouse set cursor bitmap */
  74.                 regs.r_bx = 0;          /* column in bitmap */
  75.                 regs.r_cx = 0;          /* row in bitmap */
  76.                 regs.r_es = FP_SEG((void far *)m_cursor); /* segment of bitmap */
  77.                 regs.r_dx = FP_OFF((void far *)m_cursor); /* offset of bitmap */
  78.                 intr(0x33,®s);
  79.                 mouse_is = 1;
  80.                 return(rcode);
  81.         }
  82.         else {
  83.                 mouse_is = 0;
  84.                 return (rcode);
  85.         }
  86. }
  87. void mouse_on(void)        /* enables the mouse cursor */
  88. {
  89. struct REGPACK regs;
  90.         if (!mouse_is) return;
  91.     regs.r_ax = 0x0001;
  92.     intr(0x33,®s);
  93. }
  94. void mouse_off(void)        /* disables the mouse cursor */
  95. {
  96. struct REGPACK regs;
  97.         if (!mouse_is) return;
  98.     regs.r_ax = 0x0002;
  99.     intr(0x33,®s);
  100. }
  101. int mouse_get(mouse_state *m)        /* get mouse position and button status */
  102. {
  103. struct REGPACK regs;
  104.         if (!mouse_is) return(0);
  105.     regs.r_ax = 0x0003;
  106.     intr(0x33,®s);
  107.     (*m).row = regs.r_dx;
  108.     (*m).col = regs.r_cx;
  109.     (*m).buttons = regs.r_bx;
  110.     return((*m).buttons);
  111. }
  112. void mouse_put(mouse_state *m)         /* put mouse at position */
  113. {
  114. struct REGPACK regs;
  115.     if (!mouse_is) return;
  116.         regs.r_ax = 0x0004;
  117.     regs.r_cx = (*m).col;
  118.     regs.r_dx = (*m).row;
  119.     intr(0x33,®s);
  120. }
  121. /*
  122.         05h     Return Button Press Data
  123.         entry   AL?     05h
  124.                 BX      button
  125.                         0 left
  126.                         1 right
  127.                         2 middle (Mouse Systems mouse)
  128.         return  AL?     button states
  129.                         bit 0   left button pressed if 1
  130.                         bit 1   right button pressed if 1
  131.                         bit 2   middle button pressed if 1 (Mouse Systems mouse)
  132.                 BX      no. of times specified button pressed since last call
  133.                 CX      column at time specified button was last pressed
  134.                 DX      row at time specified button was last pressed
  135. */
  136. int mouse_press(mouse_state *m)
  137. {
  138. struct REGPACK regs;
  139.         if (!mouse_is) return(0);
  140.         regs.r_ax = 0x0005;
  141.         regs.r_bx = 0;
  142.         intr(0x33,®s);
  143.     (*m).row = regs.r_dx;
  144.     (*m).col = regs.r_cx;
  145.         (*m).buttons = regs.r_ax;
  146.         if (regs.r_bx) return(regs.r_ax);
  147.         regs.r_ax = 0x0005;
  148.         regs.r_bx = 1;
  149.         intr(0x33,®s);
  150.     (*m).row = regs.r_dx;
  151.     (*m).col = regs.r_cx;
  152.         (*m).buttons = regs.r_ax;
  153.         if (regs.r_bx) return(regs.r_ax);
  154.         return(0);
  155. }
  156. /**************************************************************************
  157.         A job to do while waiting on the mouse click
  158. ***************************************************************************/
  159. int mouse_idle(void)
  160. {
  161.         return(0);
  162. }
  163. int (*mouse_idle_job)(void) = mouse_idle;       /* the mouse idle task */
  164. int mouse_click(mouse_state *m)    /* mouse wait until click */
  165. {
  166. int rcode;
  167.     mouse_on();
  168.     /* get next button press */
  169.     do {
  170.                 mouse_idle_job();
  171.                 rcode = mouse_press(m);
  172.     } while ((!rcode)&&(!kbhit()));          /* loop while no button pressed */
  173.     mouse_off();
  174.         if (kbhit()) {
  175.                 getch();
  176.                 return(0x02);
  177.         }
  178.     return(rcode);
  179. }
  180. int mouse_click_grat(mouse_state *m)    /* mouse wait until click */
  181. {
  182. int rcode;
  183. int xres,yres;
  184.     xres = maxx/GRAT_X;
  185.     yres = maxy/GRAT_Y;
  186.     rcode = mouse_click(m);
  187.         if (use_grat) {
  188.                 /* adjust mouse position to nearest graticule point */
  189.                 (*m).row = (((*m).row + (yres/2)) / yres) * yres;
  190.                 (*m).col = (((*m).col + (xres/2)) / xres) * xres;
  191.         }
  192.     return(rcode);
  193. }
  194.