home *** CD-ROM | disk | FTP | other *** search
/ Mega A/V / mega_av.zip / mega_av / SOUNDUTL / MUSIQUE.ZIP / SOURCE.ZIP / MOUSE.C < prev    next >
C/C++ Source or Header  |  1991-09-06  |  4KB  |  164 lines

  1. /* Warning! This C source contains extended characters! */
  2.  
  3. #include <dos.h>
  4. #include <bios.h>
  5. #include <musique.h>
  6. #include <mouse.e>
  7.  
  8. int colorcursor;
  9.  
  10. void mouseshow(int x, int y, char *c, int *color)
  11. /* Turbo-C doesn't like extended or non-text modes */
  12. /* Turbo-C scrolls the screen too much (lower-right corner) */
  13. /* prints the mouse cursor */
  14. {
  15.   union REGS regs;
  16.  
  17.   regs.h.ah=(unsigned)'\x2'; /* set cursor position */
  18.   regs.h.bh=(unsigned)'\x0';
  19.   regs.h.dl=(unsigned char)(x-1);
  20.   regs.h.dh=(unsigned char)(y-1);
  21.   int86(0x10,®s,®s);
  22.   regs.h.ah=(unsigned)'\x8'; /* read one character */
  23.   regs.h.bh=(unsigned)'\x0';
  24.   int86(0x10,®s,®s);
  25.   *c=(char)regs.h.al;
  26.   *color=(int)regs.h.ah;
  27.   regs.h.ah=(unsigned)'\x9'; /* print one character */
  28.   regs.h.bh=(unsigned)'\x0';
  29.   regs.x.cx=(unsigned)0x1;
  30.   regs.h.bl=(unsigned char)((*color&0xF)|colorcursor);
  31.   regs.h.al=(unsigned)*c;
  32.   int86(0x10,®s,®s);
  33. }
  34.  
  35. void mousehide(int x, int y, char c, int color)
  36. /* Turbo-C doesn't like extended or non-text modes */
  37. /* Turbo-C scrolls the screen too much (lower-right corner) */
  38. /* hides the mouse cursor */
  39. {
  40.   union REGS regs;
  41.  
  42.   regs.h.ah=(unsigned)'\x2'; /* set cursor position */
  43.   regs.h.bh=(unsigned)'\x0';
  44.   regs.h.dl=(unsigned char)(x-1);
  45.   regs.h.dh=(unsigned char)(y-1);
  46.   int86(0x10,®s,®s);
  47.   regs.h.ah=(unsigned)'\x9'; /* print one character */
  48.   regs.h.bh=(unsigned)'\x0';
  49.   regs.x.cx=(unsigned)0x1;
  50.   regs.h.bl=(unsigned char)color;
  51.   regs.h.al=(unsigned)c;
  52.   int86(0x10,®s,®s);
  53. }
  54.  
  55. int mouseinit(void)
  56. /* returns TRUE iff mouse responding */
  57. {
  58.   union REGS regs;
  59.  
  60.   regs.x.ax=(unsigned)0x0;
  61.   int86(0x33,®s,®s);
  62.   return((int)regs.x.ax);
  63. }
  64.  
  65. void mouseratio(int X, int Y)
  66. /* sets X/Y motion/pixel ratio */
  67. {
  68.   union REGS regs;
  69.  
  70.   regs.x.ax=(unsigned)0xF;
  71.   regs.x.cx=(unsigned)X;
  72.   regs.x.dx=(unsigned)Y;
  73.   int86(0x33,®s,®s);
  74. }
  75.  
  76. void mouselimits(int xmin, int ymin, int xmax, int ymax)
  77. /* sets X/Y intervals */
  78. {
  79.   union REGS regs;
  80.  
  81.   regs.x.ax=(unsigned)0x7;
  82.   regs.x.cx=(unsigned)(xmin<<4);
  83.   regs.x.dx=(unsigned)(xmax<<4);
  84.   int86(0x33,®s,®s);
  85.   regs.x.ax=(unsigned)0x8;
  86.   regs.x.cx=(unsigned)(ymin<<4);
  87.   regs.x.dx=(unsigned)(ymax<<4);
  88.   int86(0x33,®s,®s);
  89. }
  90.  
  91. void mousewrite(int X, int Y)
  92. /* sets mouse position */
  93. {
  94.   union REGS regs;
  95.  
  96.   regs.x.ax=(unsigned)0x4;
  97.   regs.x.cx=(unsigned)(X<<4);
  98.   regs.x.dx=(unsigned)(Y<<4);
  99.   int86(0x33,®s,®s);
  100. }
  101.  
  102. void mouseread(MOUSETYPE *mousedata)
  103. /* reads mouse position and button status*/
  104. {
  105.   union REGS regs;
  106.  
  107.   regs.x.ax=(unsigned)0x3;
  108.   int86(0x33,®s,®s);
  109.   mousedata->x=((int)regs.x.cx)>>4;
  110.   mousedata->y=((int)regs.x.dx)>>4;
  111.   mousedata->left=((int)regs.x.bx & 0x1);
  112.   mousedata->right=((int)regs.x.bx & 0x2);
  113. }
  114.  
  115. int setupmouse(PARAMETERTYPE *parameter, MOUSETYPE *mousedata)
  116. /* returns TRUE iff could set up the mouse */
  117. {
  118.   if (mouseinit()) {
  119.     mousedata->x=parameter->maxcolumn/2;
  120.     mousedata->y=parameter->maxline/2;
  121.     mouseratio(XRATIO,YRATIO);
  122.     mouselimits(2,2,parameter->maxcolumn-1,parameter->maxline-1);
  123.     mousewrite(mousedata->x,mousedata->y);
  124.     return(TRUE);
  125.   }
  126.   else return (FALSE);
  127. }
  128.  
  129. int readmouse(SONGSTYPE *songs, PARAMETERTYPE *parameter, MOUSETYPE *mousedata)
  130. /* translates mouse activity in equivalent keyboard keys */
  131. /* left button is <Space> */
  132. /* right button is <Enter> */
  133. /* both buttons are <Escape> since hard to do by mistake */
  134. {
  135.   int left,right,x,y;
  136.  
  137.   left=mousedata->left;
  138.   right=mousedata->right;
  139.   x=mousedata->x;
  140.   y=mousedata->y;
  141.   mouseread(mousedata);
  142.   if ((mousedata->x!=x) || (mousedata->y!=y)) {
  143.     mousehide(x,y,mousedata->c,mousedata->color);
  144.     mouseshow(mousedata->x,mousedata->y,&(mousedata->c),&(mousedata->color));
  145.     movecursor(parameter);
  146.   }
  147.   if (mousedata->left)
  148.     if (mousedata->right) {
  149.       if (!left && !right) return(KEYESC);
  150.     }
  151.     else {
  152.       if (!left) return(KEYSPACE);
  153.     }
  154.   else
  155.     if (mousedata->right)
  156.       if (!right) return(KEYENTER);
  157.   if (mousedata->y==2)
  158.     if (songs->songcorner>1) return(KEYUP);
  159.   if (mousedata->y==(parameter->maxline-1))
  160.     if ((songs->songcorner+parameter->bigline)<=parameter->hugeline) 
  161.       return(KEYDOWN);
  162.   return(FALSE);
  163. }
  164.