home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 35 / hot35.iso / ficheros / LC / SIMPWN93.ZIP / SIMPWIN.ZIP / MOUSE92.C < prev    next >
C/C++ Source or Header  |  1997-05-04  |  3KB  |  234 lines

  1. /* simpwin9 copyright 1995 - 1997 by bruce r. o'banion */
  2.  
  3. # include <stdio.h>
  4. # include <string.h>
  5. # include <dos.h>
  6. # include <stdlib.h>
  7. # include <conio.h>
  8. # include <mem.h>
  9. # include <alloc.h>
  10.  
  11. # include "mouse92.h"
  12.  
  13. int mou_installed = 0;
  14. unsigned int old_mov_x;
  15. unsigned int old_mov_y;
  16.  
  17.  
  18. void mouinterrupt(int mou_ax,int mou_bx,int mou_cx,int mou_dx)
  19. {
  20.     asm  mov ax,mou_ax;
  21.     asm mov bx,mou_bx;
  22.     asm mov cx,mou_cx;
  23.     asm mov dx,mou_dx;
  24.     asm int 0x33;
  25. }
  26.  
  27.  
  28. int mouinstalled(void)
  29. {
  30.     int rows,cols;
  31.  
  32.     if(mou_get_adapter() == 0)
  33.     {
  34.  
  35.         return(-1);
  36.     }
  37.     mouinterrupt(0,0,0,0);
  38.     asm mov mou_installed,bx;
  39.     if(_AX == 0)
  40.     {
  41.         mou_installed = 0;
  42.     }
  43.     else
  44.     {
  45.         if(mou_get_mode(&rows,&cols) == -1)
  46.         {
  47.  
  48.             return(-1);
  49.         }
  50.     }
  51.     mousetmaxposition(1,cols,1,rows);
  52.     old_mov_x = -1;
  53.     old_mov_y = -1;
  54.     return(mou_installed);
  55. }
  56.  
  57. void moureset(void)
  58. {
  59.     mouinterrupt(0,0,0,0);
  60. }
  61.  
  62. int moubuttonpressed(int button)
  63. {
  64.  
  65.     int code;
  66.  
  67.     if(mou_installed)
  68.     {
  69.         mouinterrupt(0x0005,button,0,0);
  70.         asm mov code,bx;
  71.         return(code);
  72.     }
  73.     return(0);
  74. }
  75.  
  76.  
  77. void mouhide(void)
  78. {
  79.     if(mou_installed)
  80.     {
  81.         mouinterrupt(0x02,0,0,0);
  82.     }
  83. }
  84.  
  85.  
  86. void moushow(void)
  87. {
  88.     if(mou_installed)
  89.     {
  90.         mouinterrupt(0x01,0,0,0);
  91.     }
  92. }
  93.  
  94. void mousetposition(int x,int y)
  95. {
  96.     if(mou_installed)
  97.     {
  98.         mouinterrupt(0x04,0x00,(x - 1) * 8,(y - 1) * 8);
  99.     }
  100. }
  101.  
  102.  
  103. int mouposition(int *x,int *y)
  104. {
  105.     int mov_x,mov_y;
  106.  
  107.     if(mou_installed)
  108.     {
  109.         mouinterrupt(0x03,0,0,0);
  110.         asm mov mov_x,cx;
  111.         asm mov mov_y,dx;
  112.         *x = (mov_x / 8) + 1;
  113.         *y = (mov_y / 8) + 1;
  114.         if((old_mov_x != mov_x) | (old_mov_y != mov_y))
  115.         {
  116.             old_mov_x = mov_x;
  117.             old_mov_y = mov_y;
  118.             return(1);
  119.         }
  120.         else
  121.         {
  122.             return(0);
  123.         }
  124.     }
  125.     return(0);
  126. }
  127.  
  128. int mousetmaxposition(int minx,int maxx,int miny,int maxy)
  129. {
  130.     mouinterrupt(0x0007,0x0000,(minx - 1) * 8,(maxx - 1) * 8);
  131.     mouinterrupt(0x0008,0x0000,(miny - 1) * 8,(maxy - 1) * 8);
  132.     return(0);
  133. }
  134.  
  135. int moubuttonrelease(int button)
  136. {
  137.     int code;
  138.  
  139.     if(mou_installed)
  140.     {
  141.         mouinterrupt(0x06,button,0x00,0x00);
  142.         code = _BX;
  143.         return(code);
  144.     }
  145.     return(0);
  146. }
  147.  
  148. int mou_get_adapter(void)
  149. {
  150.     char *adapt_buff;
  151.  
  152.     if((adapt_buff = (char*)malloc(64)) == NULL)
  153.     {
  154.  
  155.         return(0);
  156.     }
  157.     asm push es;
  158.     asm  mov ax,ds;
  159.     asm mov es,ax;
  160.     asm mov ax,adapt_buff;
  161.     asm push di;
  162.     asm mov di,ax;
  163.     asm mov bx,0x00;
  164.     asm mov ah,0x1b;
  165.     asm int 0x10;
  166.     asm pop di;
  167.     asm pop es;
  168.     if(_AL == 0x1b)
  169.     {
  170.  
  171.         free(adapt_buff);
  172.         return(9);
  173.     }
  174.     if(peek(0x0000,0x0487))
  175.     {
  176.         free(adapt_buff);
  177.         return(3);
  178.     }
  179.     free(adapt_buff);
  180.     return(0);
  181. }
  182.  
  183. int mou_get_mode(int *rows,int *cols)
  184. {
  185.     int mode;
  186.  
  187.     asm push bp;
  188.     asm push es;
  189.     asm mov ah,0x11;
  190.     asm mov al,0x30;
  191.     asm mov bh,0x03;
  192.     asm int 0x10;
  193.     asm pop es;
  194.     asm pop bp;
  195.     *rows = _DL + 1;
  196.     asm mov ah,0x0f;
  197.     asm int 0x10;
  198.     asm push ax;
  199.     *cols = _AH;
  200.     asm pop ax;
  201.     mode = _AL;
  202.     if((mode == 3) & (*rows > 25))
  203.     {
  204.         mode = 64;
  205.     }
  206.     switch(mode)
  207.     {
  208.         case 3 :
  209.         case 64 :
  210.         case 84 :
  211.         case 85 : break;
  212.         default : mode = -1;
  213.     }
  214.     return(mode);
  215. }
  216.  
  217. void moucursortype(unsigned int type)
  218. {
  219.     if(mou_installed)
  220.     {
  221.         if(type == 0)
  222.         {
  223.             mouinterrupt(0x000a,0x0000,0xffff,0x3300);
  224.         }
  225.         else
  226.         {
  227.             mouinterrupt(0x000a,0x0000,0xff00,type);
  228.         }
  229.     }
  230. }
  231.  
  232.  
  233.  
  234.