2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
7 #include <intuition/intuition.h>
8 #include <graphics/gfx.h>
9 #include <utility/hooks.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
16 #include <clib/alib_protos.h>
22 /****************************************************************************************/
24 #define SIGF_READY SIGBREAKF_CTRL_C
26 #define SIGF_INIT SIGBREAKF_CTRL_C
27 #define SIGF_STOP SIGBREAKF_CTRL_D
28 #define SIGF_HELLO SIGBREAKF_CTRL_E
30 /****************************************************************************************/
32 struct IntuitionBase
*IntuitionBase
;
33 struct GfxBase
*GfxBase
;
35 static struct Screen
*scr
;
36 static struct Window
*win
;
37 static struct Task
*task1
, *task2
, *maintask
;
43 /****************************************************************************************/
45 static void Cleanup(char *msg
)
51 printf("taskswitchbench: %s\n",msg
);
58 if (task1
) DeleteTask(task1
);
59 if (task2
) DeleteTask(task2
);
62 if (win
) CloseWindow(win
);
63 if (scr
) UnlockPubScreen(0,scr
);
65 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
66 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
71 /****************************************************************************************/
73 static void OpenLibs(void)
75 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",39)))
77 Cleanup("Can't open intuition.library V39!");
80 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",39)))
82 Cleanup("Can't open graphics.library V39!");
87 /****************************************************************************************/
89 static void GetVisual(void)
91 if (!(scr
= LockPubScreen(0)))
93 Cleanup("Can't lock pub screen!");
97 /****************************************************************************************/
99 static void MakeWin(void)
101 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
105 WA_Height
,scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 +
107 scr
->Font
->ta_YSize
* 2,
108 WA_Title
,(IPTR
)"Press RETURN key to start and any key to stop!",
109 WA_SimpleRefresh
,TRUE
,
114 WA_IDCMP
,IDCMP_CLOSEWINDOW
|
119 Cleanup("Can't open window!");
122 ScreenToFront(win
->WScreen
);
126 /****************************************************************************************/
128 #define OTHERTASK task2
130 static void Task1(void)
137 SetSignal(0, SIGF_HELLO
);
139 Signal(maintask
, SIGF_READY
);
143 sigs
= Wait(SIGF_STOP
| SIGF_HELLO
);
144 if (sigs
& SIGF_STOP
) stop
= TRUE
;
145 if (sigs
& SIGF_HELLO
) Signal(OTHERTASK
, SIGF_HELLO
);
150 /****************************************************************************************/
153 #define OTHERTASK task1
155 static void Task2(void)
162 SetSignal(0, SIGF_HELLO
);
164 Signal(maintask
, SIGF_READY
);
168 sigs
= Wait(SIGF_STOP
| SIGF_HELLO
);
169 if (sigs
& SIGF_STOP
) stop
= TRUE
;
170 if (sigs
& SIGF_HELLO
)
172 Signal(OTHERTASK
, SIGF_HELLO
);
179 /****************************************************************************************/
181 static void MakeTasks(void)
183 maintask
= FindTask(NULL
);
185 task1
= CreateTask("Task 1", 0, Task1
, AROS_STACKSIZE
);
186 task2
= CreateTask("Task 2", 0, Task2
, AROS_STACKSIZE
);
188 if (!task1
|| !task2
) Cleanup("Can't create tasks!");
192 /****************************************************************************************/
194 static void Action(void)
196 struct RastPort
*rp
= win
->RPort
;
197 char *msg
= "Starting to benchmark when countdown reaches 0. Countdown: 5";
200 WORD x
= win
->BorderLeft
+ 8;
201 WORD y
= win
->BorderTop
+ rp
->TxHeight
/ 2;
202 WORD len
= strlen(msg
);
203 WORD pixellen
= TextLength(rp
, msg
, len
);
205 Signal(task1
, SIGF_INIT
);
208 Signal(task2
, SIGF_INIT
);
211 ModifyIDCMP(win
, IDCMP_VANILLAKEY
);
214 RectFill(rp
, x
, y
, win
->Width
- win
->BorderRight
- 1, y
+ rp
->TxHeight
- 1);
217 Move(rp
, x
, y
+ rp
->TxBaseline
);
220 x
+= pixellen
- rp
->TxWidth
;
222 for(i
= 5; i
>= 0; i
--)
226 Delay(25); /* should be 50 (1 sec), but AROS clock is somewhat slow */
228 Move(rp
, x
, y
+ rp
->TxBaseline
);
232 /* start everything by sending hello to first task */
234 Signal(task1
, SIGF_HELLO
);
236 WaitPort(win
->UserPort
);
237 ReplyMsg(GetMsg(win
->UserPort
));
240 Signal(task1
, SIGF_STOP
);
241 Signal(task2
, SIGF_STOP
);
243 ModifyIDCMP(win
, IDCMP_VANILLAKEY
| IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
);
245 x
-= (pixellen
- rp
->TxWidth
);
248 RectFill(rp
, x
, y
, win
->Width
- win
->BorderRight
- 1, y
+ rp
->TxHeight
- 1);
252 sprintf(s
, "Benchmark result: %ld",counter
);
254 Move(rp
, x
, y
+ rp
->TxBaseline
);
255 Text(rp
, s
, strlen(s
));
260 /****************************************************************************************/
262 static void HandleAll(void)
264 struct IntuiMessage
*msg
;
270 WaitPort(win
->UserPort
);
271 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
275 case IDCMP_CLOSEWINDOW
:
279 case IDCMP_REFRESHWINDOW
:
281 EndRefresh(win
,TRUE
);
284 case IDCMP_VANILLAKEY
:
285 if (msg
->Code
== 13) Action();
289 ReplyMsg((struct Message
*)msg
);
294 /****************************************************************************************/
307 /****************************************************************************************/
308 /****************************************************************************************/
309 /****************************************************************************************/
310 /****************************************************************************************/