home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 521.lha / ProMouse_v1.20 / ProMouse.mod < prev    next >
Text File  |  1991-06-09  |  4KB  |  142 lines

  1. MODULE ProMouse;
  2. (******************************************************************************
  3.  
  4. Program name: ProMouse
  5. Version        : 1.20
  6. Created     : Sept. 17, 1989
  7. Author      : Robert Kozak
  8.  
  9. Description : A Proportional Mouse accellerator. From what I hear most mouse
  10. accellerators speed up the mouse by a constant value. This one is
  11. proportional to the individual mouse movements. You may set a sensitivity
  12. value (1-10) from the command line like this :
  13.                         Promouse 3
  14. Also as you'll notice this program doesn't do anything fancy like display
  15. memory or system time. This just does what it claims.
  16.                         
  17. Status      : This program is copyrighted and freely redistributable as long
  18. as it isn't sold for profit. You may use the routines within for whatever you
  19. wish. 
  20.  
  21. ******************************************************************************)    
  22. FROM SYSTEM       IMPORT ADR, ADDRESS, TSIZE, SETREG, SAVEREGS, LOADREGS,
  23.                   REGISTER, BYTE, STRPTR;
  24. FROM RunTime       IMPORT CurrentProcess;
  25. FROM Ports       IMPORT MsgPortPtr;
  26. FROM Tasks       IMPORT Wait, SignalSet;
  27. FROM Interrupts       IMPORT Interrupt;
  28. FROM Devices       IMPORT OpenDevice, CloseDevice;
  29. FROM IO           IMPORT IOStdReq, DoIO;
  30. FROM InputEvents   IMPORT InputEventPtr, IEClass, IEQualifiers, IEQualifierSet;
  31. FROM InputDevice   IMPORT INDAddHandler, INDRemHandler;
  32. FROM PortUtils       IMPORT CreatePort, DeletePort;
  33. FROM DOS       IMPORT SIGBreakC;
  34. FROM ConsoleDevice IMPORT RawKeyConvert, ConsoleName, ConsoleBase;
  35. FROM CmdLineUtils  IMPORT argc, argv;
  36. FROM TermOut       IMPORT WriteString, WriteLn, WriteInt;
  37. FROM ExtConversions IMPORT ConvStrToInt;
  38.  
  39. VAR
  40.   ioreq    : IOStdReq;    (* for input handler  *)
  41.   iostdreq : IOStdReq;    (* for console device *)
  42.   int      : Interrupt;
  43.   port     : MsgPortPtr;
  44.   x       : INTEGER;
  45.  
  46. CONST
  47.   threshold = 11;    (* Used so that sensitivity can be from (1-10)
  48.                  instead of (10-1)                *)
  49.  
  50. PROCEDURE InputHandler(): LONGCARD;
  51. VAR
  52.   event  : InputEventPtr;
  53.   S     : INTEGER;
  54.   
  55. BEGIN
  56.   SAVEREGS({2..7,10,11,14});
  57.   S := threshold - x;    (* set up the sensitivity        *) 
  58.   event:=ADDRESS(REGISTER(8));
  59.   WITH event^ DO    (* Do the calc on the Mouse values for x and y  *)
  60.   
  61.     IF ieClass=IEClassRawMouse THEN
  62.     IF (ABS(ieX) < 15) AND (ABS(ieX) > S) THEN 
  63.         ieX := (ieX * ABS(ieX)) DIV S; 
  64.     END;
  65.     IF (ABS(ieY) < 15) AND (ABS(ieY) > S) THEN 
  66.         ieY := (ieY * ABS(ieY)) DIV S;
  67.     END;
  68.     END;
  69.   END;
  70.  
  71.   LOADREGS({2..7,10,11,14});
  72.   RETURN LONGCARD(event);
  73. END InputHandler;
  74.  
  75.  
  76. PROCEDURE AddInputHandler();
  77. VAR
  78.   x : LONGINT;
  79. BEGIN
  80.   port:=CreatePort(NIL,0);
  81.   IF port # NIL THEN
  82.     ioreq.ioMessage.mnReplyPort:=port;
  83.     WITH int DO
  84.       isNode.lnPri:=BYTE(75);
  85.       isCode:=InputHandler;
  86.     END;
  87.     IF OpenDevice(ADR("input.device"),0,ADR(ioreq),LONGBITSET{})=0 THEN
  88.       ioreq.ioCommand:=INDAddHandler;
  89.       ioreq.ioData:=ADR(int);
  90.       x:=DoIO(ADR(ioreq));
  91.     END;
  92.   END;
  93. END AddInputHandler;
  94.  
  95.  
  96. PROCEDURE RemInputHandler;
  97. VAR
  98.   x : LONGINT;
  99. BEGIN
  100.   ioreq.ioCommand:=INDRemHandler;
  101.   ioreq.ioData:=ADR(int);
  102.   x:=DoIO(ADR(ioreq));
  103.   CloseDevice(ADR(ioreq));
  104.   DeletePort(port);
  105. END RemInputHandler;
  106.  
  107.  
  108. PROCEDURE Control;
  109. VAR
  110.   wakeup : SignalSet;
  111. BEGIN
  112.   AddInputHandler();
  113.                 (* No busy waiting here. NO LOITERING!     *)
  114.     wakeup:=Wait(SignalSet{SIGBreakC});
  115.  
  116.     IF SIGBreakC IN wakeup THEN
  117.       WriteString("ProMouse ... Disabled\n");
  118.     END;
  119.  
  120.   RemInputHandler();
  121. END Control;
  122.  
  123. PROCEDURE GetArgs;
  124. VAR
  125.     done : BOOLEAN;
  126. BEGIN
  127.     IF argc >= 1 THEN done := ConvStrToInt(argv[1]^,x);
  128.     IF (x < 1) OR (x > 10) THEN x := 5; END; 
  129.     WriteString("Sensitivity value set at "); WriteInt(x,0); WriteLn; 
  130.     END;
  131. END GetArgs;
  132.  
  133. BEGIN
  134.   WriteString("ProMouse Version 1.20 (C) 1989 by Robert Kozak\n");
  135.   GetArgs();
  136.   IF OpenDevice(ADR(ConsoleName),-1,ADR(iostdreq),LONGBITSET{})=0 THEN
  137.     ConsoleBase:=iostdreq.ioDevice;
  138.     Control;
  139.     CloseDevice(ADR(iostdreq));
  140.   END;
  141. END ProMouse.
  142.