Minor fixes to comments.
[AROS.git] / rom / intuition / freezedemon.c
blobeef1f0bb2a5b316279a49c2775ca4a5c2597885f
1 #include <intuition/intuitionbase.h>
2 #include <exec/io.h>
3 #include <devices/input.h>
4 #include <devices/inputevent.h>
5 #include <proto/exec.h>
6 #include <proto/intuition.h>
8 #include LC_LIBDEFS_FILE
10 void dprintf(const char *, ...);
12 /* Dump intuition's state if F10 is pressed while F1 is down */
14 struct InputEvent *handler(void)
16 struct InputEvent *events = (APTR)REG_A0;
17 struct InputEvent *event;
18 static BOOL F1_pressed = FALSE;
20 for (event = events; event; event = event->ie_NextEvent)
22 if (event->ie_Class == IECLASS_RAWKEY)
24 switch (event->ie_Code)
26 case 0x50: /* F1 */
27 F1_pressed = TRUE;
28 break;
30 case 0xd0: /* F1 up */
31 F1_pressed = FALSE;
32 break;
34 case 0x59: /* F10 */
35 if (F1_pressed)
37 REG_A6 = (ULONG)IntuitionBase;
38 MyEmulHandle->EmulCallDirectOS(-152 * 6);
40 break;
45 return events;
48 struct EmulLibEntry gate =
50 TRAP_LIB, 0, (void(*)(void))handler
53 struct Interrupt interrupt =
56 NULL, NULL, NT_INTERRUPT, 120, "FreezeDemon"
58 NULL,
59 (void(*)())&gate
62 int main(void)
64 if (IntuitionBase->LibNode.lib_Version == VERSION_NUMBER)
66 struct MsgPort *port = CreateMsgPort();
67 if (port)
69 struct IOStdReq *req = CreateIORequest(port, sizeof(*req));
70 if (req)
72 if (OpenDevice("input.device", 0, req, 0) == 0)
74 BYTE old_pri;
76 req->io_Command = IND_ADDHANDLER;
77 req->io_Data = &interrupt;
78 DoIO(req);
80 /* Make sure we have a higher priority than the
81 * input.device, in case it gets trapped in an
82 * endless loop.
84 old_pri = SetTaskPri(FindTask(NULL), 50);
86 /* Also dump if intuition's input handler has been
87 * frozen for more than 2s.
91 ULONG old_secs = IntuitionBase->Seconds;
92 ULONG old_micros = IntuitionBase->Micros;
94 Delay(200);
96 if (old_secs == IntuitionBase->Seconds &&
97 old_micros == IntuitionBase->Micros)
99 REG_A6 = (ULONG)IntuitionBase;
100 MyEmulHandle->EmulCallDirectOS(-152 * 6);
104 Delay(50);
106 while (old_secs == IntuitionBase->Seconds &&
107 old_micros == IntuitionBase->Micros);
111 while ((SetSignal(0,0) & 0x1000) == 0);
113 SetTaskPri(FindTask(NULL), old_pri);
115 req->io_Command = IND_REMHANDLER;
116 req->io_Data = &interrupt;
117 DoIO(req);
119 CloseDevice(req);
122 DeleteIORequest(req);
125 DeleteMsgPort(port);
129 return 0;