home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / sphinx / examples / tsr / moose.c__ < prev    next >
Encoding:
Text File  |  1994-05-27  |  8.7 KB  |  414 lines

  1. /*
  2.    NAME:  MOOSE.C--
  3.    DESCRIPTION:  A TSR that enables limited emulation of a mouse by use of
  4.                  the keyboard.  Host program required to display pointer.
  5.                  This program is pretty sketchy right now.  You were warned.
  6.                  I only made it so I could play RISK on my notebook, and it
  7.                  works fine for that.
  8. */
  9.  
  10. ?resize FALSE
  11.  
  12. ?include "VIDEO.H--"
  13. ?include "KEYCODES.H--"
  14. ?include "WRITE.H--"
  15. ?include "SYSTEM.H--"
  16. ?include "DOS.H--"
  17. ?include "TSR.H--"
  18.  
  19. ?define  MOUSE_INT  0x33
  20.  
  21. dword oldkeyhandle={};
  22. byte altflag=0,ctrlflag=0,scrolllock=0;
  23. byte upflag=0,downflag=0,leftflag=0,rightflag=0;
  24. byte button1flag=0,button2flag=0,button3flag=0;
  25. word showcounter=0;           /* show mouse if showcounter > 0 */
  26. int mousex=0,mousey=0;        /* mouse x and y coordinates */  
  27. int oldmousex=0,oldmousey=0;  /* last mouse position */
  28. int mouseb=0;                 /* mouse button status */
  29. byte currentvidmode=0;
  30. word mouseevent=0;
  31. word intmask=0;
  32. dword inthandle=0;
  33. enum { e_moved=1, e_leftpressed=2, e_leftreleased=4, e_rightpressed=8,
  34.        e_rightreleased=16, e_middlepressed=32, e_middlereleased=64 };
  35. enum { button1=1, button2=2, button3=4 };  /* button bits */
  36.  
  37. int buttonpressx[3]=0;
  38. int buttonpressy[3]=0;
  39. int buttonpresscount[3]=0;
  40.  
  41. int buttonreleasex[3]=0;
  42. int buttonreleasey[3]=0;
  43. int buttonreleasecount[3]=0;
  44.  
  45. int maxmousex=1023,minmousex=0;  /* maximum and minimum x ranges */
  46. int maxmousey=767,minmousey=0;   /* maximum and minimum y ranges */
  47. int jump=1;   /* use for jump distance */
  48.  
  49.  
  50. interrupt keyhandle ()
  51. {
  52. $ PUSH DS
  53. $ PUSH AX
  54. $ PUSH BX
  55. BL = FALSE;
  56. DS = CS;
  57. button1flag = 0;
  58. button2flag = 0;
  59. button3flag = 0;
  60. $ IN AL,KEYBOARD_PORT
  61. IF( AL == s_scrolllock )
  62.     scrolllock = 1 - scrolllock;
  63. else IF( AL == s_alt )
  64.     altflag = 1;
  65. else IF( AL == s_ctrl )
  66.     ctrlflag = 1;
  67. else IF( AL == sr_alt )
  68.     altflag = 0;
  69. else IF( AL == sr_ctrl )
  70.     ctrlflag = 0;
  71. else IF( AL == s_up )
  72.     {upflag = TRUE;
  73.     BL = TRUE;}
  74. else IF( AL == sr_up )
  75.     upflag = FALSE;
  76. else IF( AL == s_down )
  77.     {downflag = TRUE;
  78.     BL = TRUE;}
  79. else IF( AL == sr_down )
  80.     downflag = FALSE;
  81. else IF( AL == s_right )
  82.     {rightflag = TRUE;
  83.     BL = TRUE;}
  84. else IF( AL == sr_right )
  85.     rightflag = FALSE;
  86. ELSE IF( AL == s_left )
  87.     {leftflag = TRUE;
  88.     BL = TRUE;}
  89. ELSE IF( AL == sr_left )
  90.     leftflag = FALSE;
  91. ELSE IF( AL == s_space )
  92.     {button1flag = 1;
  93.     BL = TRUE;}
  94. ELSE IF( AL == sr_space )
  95.     {button1flag = 2;
  96.     BL = TRUE;}
  97. ELSE IF( AL == s_1 )
  98.     {button1flag = 1;
  99.     BL = TRUE;}
  100. ELSE IF( AL == sr_1 )
  101.     {button1flag = 2;
  102.     BL = TRUE;}
  103. ELSE IF( AL == s_2 )
  104.     {button2flag = 1;
  105.     BL = TRUE;}
  106. ELSE IF( AL == sr_2 )
  107.     {button2flag = 2;
  108.     BL = TRUE;}
  109. ELSE IF( AL == s_3 )
  110.     {button3flag = 1;
  111.     BL = TRUE;}
  112. ELSE IF( AL == sr_3 )
  113.     {button3flag = 2;
  114.     BL = TRUE;}
  115. IF( BL == TRUE )
  116.     IF( scrolllock == 1 )
  117.         {@ EATKEY();
  118.         @ EOI();
  119.         dokeys();
  120.         $ POP BX
  121.         $ POP AX
  122.         $ POP DS
  123.         return();
  124.         }
  125. $ POP BX
  126. $ POP AX
  127. $ POP DS
  128. $ JMP CSDWORD[#oldkeyhandle]
  129. }
  130.  
  131.  
  132. void dokeys ()
  133. {$ PUSH CX
  134. $ PUSH DX
  135. $ PUSH DI
  136. $ PUSH SI
  137. $ PUSH BP
  138. $ PUSH ES
  139.  
  140. IF( button1flag == 1 )
  141.     pressbutton1();
  142. ELSE IF( button1flag == 2 )
  143.     releasebutton1();
  144. IF( button2flag == 1 )
  145.     pressbutton2();
  146. ELSE IF( button2flag == 2 )
  147.     releasebutton2();
  148. IF( button3flag == 1 )
  149.     pressbutton3();
  150. ELSE IF( button3flag == 2 )
  151.     releasebutton3();
  152.  
  153. jump = 5;
  154. IF( ctrlflag == 1 )
  155.     jump = 10; 
  156. IF( altflag == 1 )
  157.     jump = 1;
  158.  
  159. IF( upflag == TRUE )
  160.     mousey -= jump;    
  161. ELSE IF( downflag == TRUE )
  162.     mousey += jump;    
  163. ELSE IF( leftflag == TRUE )
  164.     mousex -= jump;    
  165. ELSE IF( rightflag == TRUE )
  166.     mousex += jump;    
  167.  
  168. checkmouserange();
  169.  
  170. IF( oldmousex <> mousex )
  171.     mouseevent |= e_moved;
  172. IF( oldmousey <> mousey )
  173.     mouseevent |= e_moved;
  174. /* int handling jmp still to be done a long with mouse display. */
  175. IF( mouseevent & e_moved )
  176.     IF( showcounter > 0 )
  177.         {erasemouse();
  178.         drawmouse();
  179.         }
  180. oldmousex = mousex;
  181. oldmousey = mousey;
  182.  
  183. IF( mouseevent & intmask )
  184.     {AH = mouseevent;
  185.     BX = mouseb;
  186.     CX = mousex;
  187.     DX = mousey;
  188.  /* DI = x mickey count; */ 
  189.  /* SI = y mickey count; */ 
  190.     $ JMP inthandle;
  191.     }
  192.  
  193. $ POP ES
  194. $ POP BP
  195. $ POP SI
  196. $ POP DI
  197. $ POP DX
  198. $ POP CX
  199. }
  200.  
  201.  
  202. void erasemouse ()
  203. {
  204. }
  205.  
  206.  
  207. void drawmouse ()
  208. {
  209. }
  210.  
  211.  
  212. void pressbutton1 ()
  213. {IF( mouseb & button1 == 0 )
  214.     {mouseb |= button1;
  215.     buttonpresscount[0]++;
  216.     buttonpressx[0]=mousex;
  217.     buttonpressy[0]=mousey;
  218.     mouseevent |= e_leftpressed;}
  219. }
  220.  
  221.  
  222. void pressbutton2 ()
  223. {IF( mouseb & button2 == 0 )
  224.     {mouseb |= button2;
  225.     buttonpresscount[2]++;
  226.     buttonpressx[2]=mousex;
  227.     buttonpressy[2]=mousey;
  228.     mouseevent |= e_rightpressed;}
  229. }
  230.  
  231.  
  232. void pressbutton3 ()
  233. {IF( mouseb & button3 == 0 )
  234.     {mouseb |= button3;
  235.     buttonpresscount[4]++;
  236.     buttonpressx[4]=mousex;
  237.     buttonpressy[4]=mousey;
  238.     mouseevent |= e_middlepressed;}
  239. }
  240.  
  241.  
  242. void releasebutton1 ()
  243. {IF( mouseb & button1 != 0 )
  244.     {mouseb &= button1^0xFF;    
  245.     buttonreleasecount[0]++;
  246.     buttonreleasex[0]=mousex;
  247.     buttonreleasey[0]=mousey;
  248.     mouseevent |= e_leftreleased;}
  249. }
  250.  
  251.  
  252. void releasebutton2 ()
  253. {IF( mouseb & button2 != 0 )
  254.     {mouseb &= button2^0xFF;    
  255.     buttonreleasecount[2]++;
  256.     buttonreleasex[2]=mousex;
  257.     buttonreleasey[2]=mousey;
  258.     mouseevent |= e_rightreleased;}
  259. }
  260.  
  261.  
  262. void releasebutton3 ()
  263. {IF( mouseb & button3 == 0 )
  264.     {mouseb &= button3^0xFF;    
  265.     buttonreleasecount[3]++;
  266.     buttonreleasex[3]=mousex;
  267.     buttonreleasey[3]=mousey;
  268.     mouseevent |= e_middlereleased;}
  269. }
  270.  
  271.  
  272. void checkmouserange ()
  273. {IF( mousex < minmousex )
  274.     mousex = minmousex;
  275. IF( mousey < minmousey )
  276.     mousey = minmousey;
  277. IF( mousex > maxmousex )
  278.     mousex = maxmousex;
  279. IF( mousey > maxmousey )
  280.     mousey = maxmousey;
  281. }
  282.  
  283.  
  284. enum { m_reset, m_show, m_hide, m_getposition, m_setposition,
  285.        m_getpressdata, m_getreleasedata, m_setxranges, m_setyranges,
  286.        m_setgraphicscursor, m_settextcursor, m_readmickeys,
  287.        m_setintsubroutine, m_penemulationon, m_penemulationoff,
  288.        m_definemickeys };
  289.  
  290.  
  291. dword oldmousehandle={};
  292.  
  293. interrupt mousehandle ()
  294. {
  295. IF( AX == m_reset )
  296.     {$ PUSH DS
  297.     $ PUSH CS
  298.     $ POP DS
  299.     showcounter = 0;
  300.     AX = @ GETVIDEOMODE();   /* BH = display page */
  301.     currentvidmode = AL;
  302.            /* proper determining of max X and Y to be done */
  303.     maxmousex=1023;
  304.     minmousex=0; 
  305.     maxmousey=767;
  306.     minmousey=0; 
  307.     mousex = maxmousex/2;
  308.     oldmousex = AX;
  309.     mousey = maxmousey/2;
  310.     oldmousey = AX;
  311.     intmask = 0;
  312.     AL = 0;
  313.     AH = -1;
  314.     BX = -1;   /* signify two button mouse */
  315.     $ POP DS
  316.     return();
  317.     }
  318. IF( AX == m_show )
  319.     {CSINT[#showcounter]++;
  320.     return();
  321.     }
  322. IF( AX == m_hide )
  323.     {CSINT[#showcounter]--;
  324.     return();
  325.     }
  326. IF( AX == m_getposition )
  327.     {BX = CSWORD[#mouseb];
  328.     CX = CSINT[#mousex];
  329.     DX = CSINT[#mousey];
  330.     return();}
  331. IF( AX == m_setposition )
  332.     {$ PUSH DS
  333.     $ PUSH CS
  334.     $ POP DS
  335.     mousex = CX;
  336.     mousey = DX;
  337.     checkmouserange();
  338.     $ POP DS
  339.     return();}
  340. IF( AX == m_getpressdata )
  341.     {$ PUSH DS
  342.     $ PUSH CS
  343.     $ POP DS
  344.     @ ENABLE();
  345.     BX += BX;
  346. //    do { } while( buttonpresscount[BX] == 0 );
  347.     @ DISABLE ();
  348.     AX = buttonpresscount[BX];
  349.     CX = buttonpressx[BX];
  350.     DX = buttonpressy[BX];
  351.     buttonpresscount[BX] = 0;
  352.     BX = AX;
  353.     AH = mouseb;
  354.     $ POP DS
  355.     return();}
  356. IF( AX == m_getreleasedata )
  357.     {$ PUSH DS
  358.     $ PUSH CS
  359.     $ POP DS
  360.     @ ENABLE();
  361.     BX += BX;
  362.   //  do { } while( buttonreleasecount[BX] == 0 );
  363.     @ DISABLE ();
  364.     AX = buttonreleasecount[BX];
  365.     CX = buttonreleasex[BX];
  366.     DX = buttonreleasey[BX];
  367.     buttonreleasecount[BX] = 0;
  368.     BX = AX;
  369.     AH = mouseb;
  370.     $ POP DS
  371.     return();}
  372. IF( AX == m_setxranges )
  373.     {$ PUSH AX
  374.     $ PUSH DS
  375.     DS = CS;
  376.     minmousex = CX;
  377.     maxmousex = DX;
  378.     $ POP DS
  379.     $ POP AX
  380.     return();
  381.     }
  382. IF( AX == m_setyranges )
  383.     {$ PUSH AX
  384.     $ PUSH DS
  385.     DS = CS;
  386.     minmousey = CX;
  387.     maxmousey = DX;
  388.     $ POP DS
  389.     $ POP AX
  390.     return();
  391.     }
  392. IF( AX == m_setintsubroutine )
  393.     {CSWORD[#intmask] = CX;
  394.     CSWORD[#inthandle] = DX;
  395.     CSWORD[#inthandle+2] = ES;
  396.     return();
  397.     }
  398. }
  399.  
  400.  
  401.  
  402. main ()
  403. {
  404. MAXKEYRATE();
  405. WRITESTR("MOOSE installed.  <Scroll Lock> to activate/disactivate.\n");
  406. GETINTVECT(#oldkeyhandle,KEYBOARD_INT);
  407. SETINTVECT( ,KEYBOARD_INT,CS,#keyhandle);
  408. GETINTVECT(#oldmousehandle,MOUSE_INT);
  409. SETINTVECT( ,MOUSE_INT,CS,#mousehandle);
  410. @ KEEP( , , ,#main);
  411. }
  412.  
  413. /* end of MOOSE.C-- */
  414.