2 #include <intuition/intuition.h>
3 #include <graphics/gfx.h>
4 #include <utility/hooks.h>
6 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/graphics.h>
11 #include <clib/alib_protos.h>
17 /****************************************************************************************/
19 #define SIGF_READY SIGBREAKF_CTRL_C
21 #define SIGF_INIT SIGBREAKF_CTRL_C
22 #define SIGF_STOP SIGBREAKF_CTRL_D
23 #define SIGF_HELLO SIGBREAKF_CTRL_E
25 /****************************************************************************************/
27 struct IntuitionBase
*IntuitionBase
;
28 struct GfxBase
*GfxBase
;
30 static struct Screen
*scr
;
31 static struct Window
*win
;
32 static struct Task
*task1
, *task2
, *maintask
;
38 /****************************************************************************************/
40 static void Cleanup(char *msg
)
46 printf("taskswitchbench: %s\n",msg
);
53 if (task1
) DeleteTask(task1
);
54 if (task2
) DeleteTask(task2
);
57 if (win
) CloseWindow(win
);
58 if (scr
) UnlockPubScreen(0,scr
);
60 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
61 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
66 /****************************************************************************************/
68 static void OpenLibs(void)
70 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",39)))
72 Cleanup("Can't open intuition.library V39!");
75 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",39)))
77 Cleanup("Can't open graphics.library V39!");
82 /****************************************************************************************/
84 static void GetVisual(void)
86 if (!(scr
= LockPubScreen(0)))
88 Cleanup("Can't lock pub screen!");
92 /****************************************************************************************/
94 static void MakeWin(void)
96 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
100 WA_Height
,scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 +
102 scr
->Font
->ta_YSize
* 2,
103 WA_Title
,(IPTR
)"Press RETURN key to start and any key to stop!",
104 WA_SimpleRefresh
,TRUE
,
109 WA_IDCMP
,IDCMP_CLOSEWINDOW
|
114 Cleanup("Can't open window!");
117 ScreenToFront(win
->WScreen
);
121 /****************************************************************************************/
123 #define OTHERTASK task2
125 static void Task1(void)
132 SetSignal(0, SIGF_HELLO
);
134 Signal(maintask
, SIGF_READY
);
138 sigs
= Wait(SIGF_STOP
| SIGF_HELLO
);
139 if (sigs
& SIGF_STOP
) stop
= TRUE
;
140 if (sigs
& SIGF_HELLO
) Signal(OTHERTASK
, SIGF_HELLO
);
145 /****************************************************************************************/
148 #define OTHERTASK task1
150 static void Task2(void)
157 SetSignal(0, SIGF_HELLO
);
159 Signal(maintask
, SIGF_READY
);
163 sigs
= Wait(SIGF_STOP
| SIGF_HELLO
);
164 if (sigs
& SIGF_STOP
) stop
= TRUE
;
165 if (sigs
& SIGF_HELLO
)
167 Signal(OTHERTASK
, SIGF_HELLO
);
174 /****************************************************************************************/
176 static void MakeTasks(void)
178 maintask
= FindTask(NULL
);
180 task1
= CreateTask("Task 1", 0, Task1
, AROS_STACKSIZE
);
181 task2
= CreateTask("Task 2", 0, Task2
, AROS_STACKSIZE
);
183 if (!task1
|| !task2
) Cleanup("Can't create tasks!");
187 /****************************************************************************************/
189 static void Action(void)
191 struct RastPort
*rp
= win
->RPort
;
192 char *msg
= "Starting to benchmark when countdown reaches 0. Countdown: 5";
195 WORD x
= win
->BorderLeft
+ 8;
196 WORD y
= win
->BorderTop
+ rp
->TxHeight
/ 2;
197 WORD len
= strlen(msg
);
198 WORD pixellen
= TextLength(rp
, msg
, len
);
200 Signal(task1
, SIGF_INIT
);
203 Signal(task2
, SIGF_INIT
);
206 ModifyIDCMP(win
, IDCMP_VANILLAKEY
);
209 RectFill(rp
, x
, y
, win
->Width
- win
->BorderRight
- 1, y
+ rp
->TxHeight
- 1);
212 Move(rp
, x
, y
+ rp
->TxBaseline
);
215 x
+= pixellen
- rp
->TxWidth
;
217 for(i
= 5; i
>= 0; i
--)
221 Delay(25); /* should be 50 (1 sec), but AROS clock is somewhat slow */
223 Move(rp
, x
, y
+ rp
->TxBaseline
);
227 /* start everything by sending hello to first task */
229 Signal(task1
, SIGF_HELLO
);
231 WaitPort(win
->UserPort
);
232 ReplyMsg(GetMsg(win
->UserPort
));
235 Signal(task1
, SIGF_STOP
);
236 Signal(task2
, SIGF_STOP
);
238 ModifyIDCMP(win
, IDCMP_VANILLAKEY
| IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
);
240 x
-= (pixellen
- rp
->TxWidth
);
243 RectFill(rp
, x
, y
, win
->Width
- win
->BorderRight
- 1, y
+ rp
->TxHeight
- 1);
247 sprintf(s
, "Benchmark result: %ld",counter
);
249 Move(rp
, x
, y
+ rp
->TxBaseline
);
250 Text(rp
, s
, strlen(s
));
255 /****************************************************************************************/
257 static void HandleAll(void)
259 struct IntuiMessage
*msg
;
265 WaitPort(win
->UserPort
);
266 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
270 case IDCMP_CLOSEWINDOW
:
274 case IDCMP_REFRESHWINDOW
:
276 EndRefresh(win
,TRUE
);
279 case IDCMP_VANILLAKEY
:
280 if (msg
->Code
== 13) Action();
284 ReplyMsg((struct Message
*)msg
);
289 /****************************************************************************************/
302 /****************************************************************************************/
303 /****************************************************************************************/
304 /****************************************************************************************/
305 /****************************************************************************************/