-- FastMouse.mesa

-- Revised by McGregor: June 24, 1983 4:54 pm
-- Revised by Randy Gobbel: 10-May-83 9:56:34
-- Written by: CharlieLevy
Last Edited by: Beach, September 1, 1983 2:08 pm
DIRECTORY
ColorDisplay,
Interminal,
Process USING [SetPriority],
ProcessPriorities USING [priorityPageFaultLow],
Space USING [Error],
SpecialSpace USING [MakeGlobalFrameResident, MakeProcedureResident],
UserProfile,
UserTerminal;
FastMouse: PROGRAM
IMPORTS ColorDisplay, Interminal, Process, Space, SpecialSpace, UserProfile, UserTerminal = BEGIN
mouseProcess: PROCESSNIL;
pauseTicks: CARDINAL ← 1;
position, prevPosition: Interminal.MousePosition ← Interminal.GetMousePosition[];
threshold: INTEGER ← 2;
ampxTen: INTEGER ← 15;
MouseProcess: PROCEDURE =
BEGIN
Process.SetPriority[ProcessPriorities.priorityPageFaultLow];
DO
UserTerminal.WaitForScanLine[0];
position ← Interminal.GetMousePosition[];
IF prevPosition = position THEN LOOP;
IF prevPosition.color = position.color AND (MAX[
ABS[INTEGER[position.mouseX] - INTEGER[prevPosition.mouseX]],
ABS[INTEGER[position.mouseY] - INTEGER[prevPosition.mouseY]]])
> threshold THEN Accelerate[];
prevPosition ← position;
ENDLOOP;
END; -- MouseProcess
Accelerate: PROCEDURE = INLINE
BEGIN
xDelta: INTEGERINTEGER[position.mouseX] - INTEGER[prevPosition.mouseX];
yDelta: INTEGERINTEGER[position.mouseY] - INTEGER[prevPosition.mouseY];
IF xDelta > threshold THEN xDelta ← xDelta - threshold
ELSE IF xDelta < -threshold THEN xDelta ← xDelta + threshold;
IF yDelta > threshold THEN yDelta ← yDelta - threshold
ELSE IF yDelta < -threshold THEN yDelta ← yDelta + threshold;
position ← [
MAX[
MIN[
INTEGER[position.mouseX] + (xDelta * ampxTen / 10),
IF position.color THEN ColorDisplay.width-1 ELSE UserTerminal.screenWidth],
0],
position.color,
MAX[
MIN[
INTEGER[position.mouseY] + (yDelta * ampxTen / 10),
IF position.color THEN ColorDisplay.height-1 ELSE UserTerminal.screenHeight],
0]];
Interminal.SetMousePosition[position];
END; -- Accelerate
ProcessProfile: UserProfile.ProfileChangedProc = TRUSTED BEGIN
 threshold ← UserProfile.Number["FastMouse.Threshold", 2];
 ampxTen ← UserProfile.Number["FastMouse.AmpxTen", 15];
END;
Init: PROCEDURE =
BEGIN
SpecialSpace.MakeGlobalFrameResident[FastMouse ! Space.Error => CONTINUE];
SpecialSpace.MakeProcedureResident[MouseProcess ! Space.Error => CONTINUE];
mouseProcess ← FORK MouseProcess[];
UserProfile.CallWhenProfileChanges[ProcessProfile];
END;
Init[];
END.