DLionTTYSwatWatcher.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Tim Diebert: December 19, 1985 4:29:47 pm PST
DIRECTORY
DebuggerSwap USING [CallDebugger, WorryCallDebugger, teledebug],
PrincOps USING [Priority],
Process USING [Detach, DisableTimeout, GetPriority, InitializeCondition, Priority, priorityClient3, prioritySwatWatcher, SetPriority],
TerminalDefs USING [DownUp, KeyBits],
TerminalFace USING [keyboard]
;
~
BEGIN
swatWatcherEnabled: BOOL ← FALSE;
interruptWanted: BOOL;
interrupter: CONDITION;
CheckInterrupt:
ENTRY
PROC = {
interruptState: TerminalDefs.DownUp ← up;
keyboard: LONG POINTER TO READONLY TerminalDefs.KeyBits ~ TerminalFace.keyboard;
wakeup: CONDITION;
Process.InitializeCondition[@wakeup, 1];
DO
--FOREVER--
ENABLE ABORTED => CONTINUE;
WAIT wakeup;
IF keyboard[Yellow]=down
-- middle button = swat for TTY DLion --
THEN {
IF interruptState=up
THEN {
interruptState ← down;
DebuggerSwap.teledebug ← TRUE;
IF keyboard[Red]=down
-- left button = shift for TTY DLion --
THEN
DebuggerSwap.WorryCallDebugger["Keyboard interrupt (worry mode)"L]
ELSE { interruptWanted ← TRUE; NOTIFY interrupter };
};
}
ELSE interruptState ← up;
ENDLOOP;
};
InterruptSpawner:
PROC = {
WaitUntilWanted:
ENTRY
PROC = {
ENABLE UNWIND => NULL;
interruptWanted ← FALSE;
UNTIL interruptWanted DO WAIT interrupter ENDLOOP;
};
DO
ENABLE
ABORTED =>
CONTINUE;
WaitUntilWanted[];
Process.Detach[FORK Interrupt[]];
ENDLOOP;
};
Interrupt:
PROC = {
DebuggerSwap.CallDebugger["Keyboard interrupt"L];
};
swatWatcherStarted: BOOL ← FALSE;
StartSwatWatcher:
PUBLIC
ENTRY
SAFE
PROC[enabled:
BOOL] =
TRUSTED {
Must not be invoked until KeyboardFace and Process have been initialized.
IF NOT swatWatcherStarted
THEN {
priorityPrev: PrincOps.Priority = Process.GetPriority[];
Process.InitializeCondition[@interrupter, 0];
Process.DisableTimeout[@interrupter];
Process.SetPriority[Process.priorityClient3];
Process.Detach[FORK InterruptSpawner[]];
Process.SetPriority[Process.prioritySwatWatcher];
Process.Detach[FORK CheckInterrupt[]];
Process.SetPriority[priorityPrev];
swatWatcherStarted ← TRUE;
};
swatWatcherEnabled ← enabled;
};
EnableSwatWatcher:
PUBLIC
ENTRY
SAFE
PROCEDURE[enabled:
BOOL] =
CHECKED{ swatWatcherEnabled ← enabled };
Initialize:
PUBLIC
PROC =
BEGIN
swatWatcherStarted ← FALSE;
swatWatcherEnabled ← FALSE;
StartSwatWatcher[TRUE];
END;
Initialize[];