-- File: GateCursor.mesa,  Last Edit: HGM  December 20, 1980  11:42 PM

DIRECTORY
  Inline USING [LowHalf],
  Cursor USING [Object, Store, UniqueType],
  Process USING [Detach, MsecToTicks, SetTimeout],
  UserTerminal USING [
    Coordinate, GetState, mouse, screenHeight, screenWidth, SetMousePosition],
  StatsDefs USING [StatGetCounter];

GateCursor: MONITOR IMPORTS Inline, Cursor, Process, UserTerminal, StatsDefs =
  BEGIN

  cursor: Cursor.Object ←
    [info: [type: Cursor.UniqueType[], hotX: 8, hotY: 8],
      array:
      [077776B, 177777B, 140000B, 140000B, 140000B, 140000B, 140000B, 140377B,
	140377B, 140003B, 140003B, 140003B, 140003B, 140003B, 177777B, 077776B]];

  MoveTheCursor: ENTRY PROCEDURE =
    BEGIN
    sleep: CONDITION;
    where: UserTerminal.Coordinate;
    new, old: LONG CARDINAL ← 0;
    Process.SetTimeout[@sleep, Process.MsecToTicks[250]];
    DO
      UNTIL UserTerminal.GetState[] = disconnected DO WAIT sleep; ENDLOOP;
      WHILE UserTerminal.GetState[] = disconnected DO
	WAIT sleep;
	new ← StatsDefs.StatGetCounter[statPupForwarded];
	Cursor.Store[@cursor];
	where ← UserTerminal.mouse↑;
	where.y ← where.y + 1;
	IF where.y >= UserTerminal.screenHeight THEN where.y ← 0;
	where.x ← where.x + Inline.LowHalf[new - old];
	IF where.x >= UserTerminal.screenWidth THEN where.x ← 0;
	UserTerminal.SetMousePosition[where];
	old ← new;
	ENDLOOP;
      ENDLOOP;
    END;

  Process.Detach[FORK MoveTheCursor[]];
  END.