asm.h: use only .asciz sections of the .s file
[AROS.git] / rom / intuition / freezedemon.c
blobf4b34b6650d17f91afa71208fa720eac24c0a2e1
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <intuition/intuitionbase.h>
7 #include <exec/io.h>
8 #include <devices/input.h>
9 #include <devices/inputevent.h>
10 #include <proto/exec.h>
11 #include <proto/intuition.h>
13 #include LC_LIBDEFS_FILE
15 void dprintf(const char *, ...);
17 /* Dump intuition's state if F10 is pressed while F1 is down */
19 struct InputEvent *handler(void)
21 struct InputEvent *events = (APTR)REG_A0;
22 struct InputEvent *event;
23 static BOOL F1_pressed = FALSE;
25 for (event = events; event; event = event->ie_NextEvent)
27 if (event->ie_Class == IECLASS_RAWKEY)
29 switch (event->ie_Code)
31 case 0x50: /* F1 */
32 F1_pressed = TRUE;
33 break;
35 case 0xd0: /* F1 up */
36 F1_pressed = FALSE;
37 break;
39 case 0x59: /* F10 */
40 if (F1_pressed)
42 REG_A6 = (ULONG)IntuitionBase;
43 MyEmulHandle->EmulCallDirectOS(-152 * 6);
45 break;
50 return events;
53 struct EmulLibEntry gate =
55 TRAP_LIB, 0, (void(*)(void))handler
58 struct Interrupt interrupt =
61 NULL, NULL, NT_INTERRUPT, 120, "FreezeDemon"
63 NULL,
64 (void(*)())&gate
67 int main(void)
69 if (IntuitionBase->LibNode.lib_Version == VERSION_NUMBER)
71 struct MsgPort *port = CreateMsgPort();
72 if (port)
74 struct IOStdReq *req = CreateIORequest(port, sizeof(*req));
75 if (req)
77 if (OpenDevice("input.device", 0, req, 0) == 0)
79 BYTE old_pri;
81 req->io_Command = IND_ADDHANDLER;
82 req->io_Data = &interrupt;
83 DoIO(req);
85 /* Make sure we have a higher priority than the
86 * input.device, in case it gets trapped in an
87 * endless loop.
89 old_pri = SetTaskPri(FindTask(NULL), 50);
91 /* Also dump if intuition's input handler has been
92 * frozen for more than 2s.
96 ULONG old_secs = IntuitionBase->Seconds;
97 ULONG old_micros = IntuitionBase->Micros;
99 Delay(200);
101 if (old_secs == IntuitionBase->Seconds &&
102 old_micros == IntuitionBase->Micros)
104 REG_A6 = (ULONG)IntuitionBase;
105 MyEmulHandle->EmulCallDirectOS(-152 * 6);
109 Delay(50);
111 while (old_secs == IntuitionBase->Seconds &&
112 old_micros == IntuitionBase->Micros);
116 while ((SetSignal(0,0) & 0x1000) == 0);
118 SetTaskPri(FindTask(NULL), old_pri);
120 req->io_Command = IND_REMHANDLER;
121 req->io_Data = &interrupt;
122 DoIO(req);
124 CloseDevice(req);
127 DeleteIORequest(req);
130 DeleteMsgPort(port);
134 return 0;