Removed EBF_SILENTSTART, it was not meant to be included with rev 36660.
[AROS.git] / test / amigademo.c
blob87c8dfa8da15fcc91761e62688c473eac36fc88f
1 /*
2 * Article 2386 of net.sources:
3 * ion: version B 2.10.2 9/17/84 chuqui version 1.9 3/12/85; site unisoft.UUCP
4 * Posting-Version: version B 2.10.2 9/17/84; site cirl.UUCP
5 * Path: unisoft!dual!qantel!hplabs!tektronix!uw-beaver!cornell!vax135!houxm!mhuxt!mhuxr!ulysses!allegra!mit-eddie!think!cirl!gary
6 * From: gary@cirl.UUCP (Gary Girzon)
7 * Newsgroups: net.sources
8 * Subject: amigademo.c
9 * Message-ID: <224@cirl.UUCP>
10 * Date: 31 Oct 85 15:14:27 GMT
11 * Date-Received: 5 Nov 85 06:45:37 GMT
12 * Distribution: net
13 * Organization: Cochlear Implant Res. Lab, Boston, MA
14 * Lines: 533
16 * The following is a graphics benchmark for the Commodore Amiga.
17 * It performs several graphics and Intuition ( Amiga's user interface )
18 * tasks. Some of the tests take some time, so be patient! There is a
19 * nice punch at the end.
21 * Here are the results: ( ran as 1> amigademo > raw:file )
23 * Doing point test in a full-screen window
24 * Write pixel 640*200 took 31.5 Readpixel 640*200 took 23.1
25 * Move 640*200 took 6.8 Control 640*200 took 0.9
26 * Now doing point test directly to screen rastport
27 * Write pixel 640*200 took 23.7 Readpixel 640*200 took 15.4
28 * Move 640*200 took 6.8 Control 640*200 took 0.9
29 * Block clear blitter 1:6.9 CPU 20.0
30 * Block test in a full-screen window
31 * Set 32K 10.2 Copy 14.7 Complement 14.7
32 * Block test directly to screen rastport
33 * Set 32K 10.1 Copy 14.4 Complement 14.3
34 * Line test in window
35 * Offset 0 result:10.5
36 * Offset 1 result:10.6
37 * Offset 20 result:10.5
38 * Offset 100 result:10.4
39 * Window Benchmark #1 took 30.9
40 * Window Benchmark #2 took 0.1
45 * amiga/tutorial #88, from cheath, 13531 chars, Sat Oct 26 21:49:20 1985
47 * amigademo.c
48 * Contains some example code for graphics and I/O,
49 * organized as simple benchmarks. This is NOT the
50 * final vesion of these tests; it will be posted at a
51 * later date.
53 * Copyright 1985 by MicroSmiths.
54 * Permission is granted to use this code as an example for
55 * personal or commercial use. If you use these as a benchmark
56 * for publication, please credit MicroSmiths as the origin.
60 #include <proto/exec.h>
61 #include <proto/intuition.h>
62 #include <proto/graphics.h>
63 #include <exec/types.h>
64 #include <exec/devices.h>
65 #include <intuition/intuition.h>
66 #include <intuition/iobsolete.h>
67 #include <stdlib.h>
68 #include <stdio.h>
70 #include <aros/oldprograms.h>
71 #define register
72 /* #define USE_RAST to enable ClipBlit() test and writing to screens */
73 #undef USE_RAST
75 #include <exec/memory.h> /* Need for AllocMem */
77 #define INTUITION_REV 29
78 #define GRAPHICS_REV 29
80 #define WDTH 640 /* For a 640 * 200 , 16 color display */
81 #define HGHT 200
82 #define DPTH 2
84 #define VIEW_MODE HIRES /* Set this for a 640 screen */
86 #define NL NULL
88 #define VID MEMF_CHIP | MEMF_CLEAR /* For allocating blitter-ram */
90 /************************************************************************/
91 /* These structures are included to avoid compile-time warnings. */
92 /* This is safe UNLESS YOU DECLARE A STRUCTURE THAT REQUIRES THEM. */
93 /************************************************************************/
96 /* These librarie handles are needed. No need to include a file ferem.. */
97 struct GfxBase *GfxBase;
98 struct IntuitionBase *IntuitionBase;
100 #ifdef USE_RAST
101 WORD *t_rast; /* Temporary raster from AllocMem */
102 #endif
103 WORD *area_buf; /* Area used for AreaInfo */
105 /**** Variables Initialized by init_generic() **********/
106 struct Screen *Screen;
107 struct Window *Window;
108 struct RastPort *pRp; /* Graphics rendering area */
109 struct MsgPort *pUp; /* Input message port */
111 struct ViewPort *pVp;
113 struct timer { /* Timer struct used to record times */
114 ULONG seconds,micros;
117 /* AROS */
118 /* Added return types for functions */
119 void close_generic();
120 void init_generic();
121 void window_test();
122 void clear_test();
123 void line_test(struct RastPort *);
124 void block_test(struct RastPort *);
125 void point_test(struct RastPort *);
126 void line_sub(struct RastPort *, int);
127 void delta(struct timer *,struct timer *);
128 /* AROS */
130 /******************************************************
131 * Alright already, here's the stuff */
132 int main()
134 struct IntuiMessage *imsg;
136 init_generic();
138 printf("Doing point test in a full-screen window\n");
139 point_test(pRp); /* First try with the 'window' rastport */
140 #ifdef USE_RAST
141 printf("Now doing point test directly to screen rastport\n");
142 point_test(&Screen->RastPort); /* Next try the 'screen' rastport */
143 #endif
146 clear_test(); /* Does block clear of 32Kbytes */
148 printf("Block test in a full-screen window\n");
149 block_test(pRp);
150 #ifdef USE_RAST
151 printf("Block test directly to screen rastport\n");
152 block_test(&Screen->RastPort);
153 #endif
154 printf("Line test in window\n");
155 line_test(pRp);
157 window_test();
159 SetWindowTitles(Window,"Press any Key or Click Close to Quit...",NL);
161 SetDrMd(pRp,COMPLEMENT);
162 FOREVER {
163 Draw(pRp,2+rand()%(WDTH-4),9+rand()%(HGHT-11));
164 if (( imsg = (struct IntuiMessage *)GetMsg(pUp) )) {
165 if ( imsg->Class == CLOSEWINDOW || imsg->Class == RAWKEY ) {
167 close_generic();
169 SetRGB4(pVp,rand()&3,rand(),rand(),rand());
170 ReplyMsg((struct Message *)imsg);
174 return 0;
178 /* Used to open the test Window */
179 struct NewWindow TstWindow = {
180 0,0,WDTH,HGHT, /* LeftEdge,TopEdge,Width,Height */
181 8,9, /* DetailPen,BlockPen */
183 SMART_REFRESH | ACTIVATE, /*Flags*/
184 NL,NL,"Test", /* FirstGadget, CheckMark, Title */
185 NL, /* MUST SET SCREEN AFTER OPENSCREEN!!! */
186 NL, /* BitMap */
187 100,60,32767,32767, /* MinW, MinH, MaxW, MaxH */
188 CUSTOMSCREEN }; /* Type */
192 /***************************************************************
193 * window_test()
194 * This test opens up a window 100 times. The window is
195 * a full-screen WDTH*HGHT * 4 BitPlane display.
196 * Next, it does the same test but instead just does window-
197 * to-front, window-to-back 100 times.
198 ***************************************************************/
199 void window_test()
201 register int i;
202 register struct Window *tst_window;
203 struct timer start,finish ,t2start,t2finish;
205 TstWindow.Screen = Screen;
207 CurrentTime(&start.seconds,&start.micros);
208 for ( i=0 ; i<100 ; i++) {
209 if ( ! (tst_window=(struct Window *)OpenWindow(&TstWindow)) ) {
211 printf("Error Openeing Window, aborted!\n");
212 close_generic();
214 CloseWindow(tst_window);
216 CurrentTime(&finish.seconds,&finish.micros);
217 printf("Window Benchmark #1 took "); delta(&finish,&start);
218 printf("\n");
220 /* Now do second test... Just WindowToFront, WindowToBack */
221 tst_window = (struct Window *)OpenWindow(&TstWindow);
223 CurrentTime(&t2start.seconds,&t2start.micros);
224 for ( i=0; i<100 ; i++) {
225 WindowToBack(tst_window);
226 WindowToFront(tst_window);
228 CloseWindow(tst_window);
229 CurrentTime(&t2finish.seconds,&t2finish.micros);
232 printf("Window Benchmark #2 took "); delta(&t2finish,&t2start);
233 printf("\n");
239 /**************************************************************
240 * point_test(rastport)
241 * This routine tests the Read/Write/Move pixel functions
242 ***************************************************************/
243 void point_test(rastport)
244 struct RastPort *rastport;
246 register struct RastPort *fRp;
247 register int x,y;
249 struct timer write,read,move,control, start;
251 fRp = rastport;
254 CurrentTime(&start.seconds,&start.micros);
255 for (y=0;y<HGHT;y++) {
256 SetAPen(fRp,y&15);
257 for (x=0;x<WDTH; x++)
258 WritePixel(fRp,x,y);
260 CurrentTime(&write.seconds,&write.micros);
262 for (y=0;y<HGHT;y++) {
263 for (x=0;x<WDTH; x++)
264 ReadPixel(fRp,x,y);
266 CurrentTime(&read.seconds,&read.micros);
268 for (y=0;y<HGHT;y++) {
269 for (x=0;x<WDTH; x++)
270 Move(pRp,x,y);
272 CurrentTime(&move.seconds,&move.micros);
275 for (y=0;y<HGHT;y++)
276 for (x=0;x<WDTH; x++)
278 CurrentTime(&control.seconds,&control.micros);
279 printf("Write pixel 640*200 took "); delta(&write,&start);
280 printf(" Readpixel 640*200 took "); delta(&read,&write);
281 printf("\nMove 640*200 took "); delta(&move,&read);
282 printf(" Control 640*200 took "); delta(&control,&move);
283 printf("\n");
287 /***********************************************************
288 * block_test
289 * Does block copy, set block to value, block complement.
290 * These are all done by "applications" functions supplied in the
291 * Amiga graphics library. It may be possible to speed these up a
292 * bit if you are not rendering in a rastport, using direct blitter
293 * manipulations.
295 *****************************************************************/
297 void block_test(rastport)
298 struct RastPort *rastport;
300 struct timer start1,finish1,finish2,finish3;
302 register int i;
304 #define COPY 0xc0 /* These are blitter minterms */
305 #define XOR 0x50
307 CurrentTime(&start1.seconds,&start1.micros);
309 for ( i=0; i<500; i++ )
310 SetRast(rastport,i&3);
312 CurrentTime(&finish1.seconds,&finish1.micros);
314 #ifdef USE_RAST
315 for ( i=0; i<500; i++)
317 ClipBlit(rastport,0,0,rastport,0,0,WDTH,HGHT,COPY);
318 #endif
319 CurrentTime(&finish2.seconds,&finish2.micros);
320 #ifdef USE_RAST
321 for ( i=0; i<500; i++)
322 ClipBlit(rastport,0,0,rastport,0,0,WDTH,HGHT,COPY);
323 #endif
324 CurrentTime(&finish3.seconds,&finish3.micros);
326 printf("Set 32K "); delta(&finish1,&start1);
327 printf(" Copy "); delta(&finish2,&finish1);
328 printf(" Complement "); delta(&finish3,&finish2);
329 printf("\n");
332 /*****************************************************************
333 * clear_test()
334 * This test clears a block of memory two ways:
335 * First, using an applications blitter-clear call;
336 * Then using a somewhat optimized long-word clear using the
338 * 68000.
339 *****************************************************************/
340 void clear_test()
342 struct timer start1,finish1,finish2;
344 register WORD *mem_ptr;
345 register LONG *mp2;
347 register int i,j;
349 if ( ! (mem_ptr = (WORD *) AllocMem(32000,VID)) ) {
350 printf("Can't get mem for clear test\n");
351 close_generic();
354 CurrentTime(&start1.seconds,&start1.micros);
356 /* Use the blitter alone to clear mem */
357 for ( i = 0; i < 499 ; i++)
359 BltClear(mem_ptr,32000,0); /* flags are 'Don't Wait' */
360 #ifdef USE_RAST
361 WaitBlit(); /* Wait for the above to finish... */
362 #endif
364 CurrentTime(&finish1.seconds,&finish1.micros);
366 /* Use the CPU alone to clear mem */
367 for ( i=0; i<500 ; i++) {
368 mp2 = (LONG *)mem_ptr;
369 for ( j = 0; j < 2000 ; j++) {
370 *mp2++ = 0L;
371 *mp2++ = 0L;
372 *mp2++ = 0L;
373 *mp2++ = 0L;
377 CurrentTime(&finish2.seconds,&finish2.micros);
379 printf("Block clear blitter 1:"); delta(&finish1,&start1);
380 printf(" CPU "); delta(&finish2,&finish1);
382 printf("\n");
383 FreeMem(mem_ptr,32000);
386 void line_test(rastport)
387 struct RastPort *rastport;
390 line_sub(rastport,0);
391 line_sub(rastport,1);
392 line_sub(rastport,20);
393 line_sub(rastport,100);
396 /************************************************************
397 * line_sub(offset)
398 * This routine was borrowed from bwebster, originating from
399 * a guy in Switzerland named Fons Rademakers of CERNS, who
400 * designed the test for comparing Mac and Apollos */
401 void line_sub(rastport,offset)
403 int offset;
404 struct RastPort *rastport;
406 register int x1,y1,x2,y2,i,j;
407 register struct RastPort *fastrp;
409 struct timer start,finish;
411 fastrp = rastport;
413 CurrentTime(&start.seconds,&start.micros);
415 x1 = 150 - offset;
416 y1 = 0;
417 x2 = 150+offset;
418 y2 = 199;
420 for ( i=0; i<20; i++) {
421 SetAPen(fastrp,i&3);
422 for ( j=0; j < 200; j++) {
424 Move(fastrp,x1++,y1);
425 Draw(fastrp,x2++,y2);
427 SetAPen(fastrp,(~i)&3);
428 for ( j=0; j<200; j++) {
429 Move(fastrp,x1--,y1);
430 Draw(fastrp,x2--,y2);
433 CurrentTime(&finish.seconds,&finish.micros);
434 printf("Offset %d result:",offset); delta(&finish,&start);
435 printf("\n");
439 /***************************************************
440 * delta()
441 * This little cluge calculates the delta-time
442 * and prints it, along with a '\n' */
443 void delta(finish,start)
445 struct timer *finish,*start;
447 int dsec,dmic;
449 dmic = finish->micros - start->micros;
450 dsec = finish->seconds - start->seconds;
452 if (dmic < 0) {
453 dmic += 1000000;
454 dsec--;
456 printf("%d.%d",dsec,dmic/100000);
463 /************************************************************************/
464 /* Many of the Amiga 'C' language structures are most efficiently set */
466 /* up by initializing the values with the declarations */
467 /************************************************************************/
469 /* Font Descriptor */
470 struct TextAttr MyFont = {"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT };
472 /* Used to open a Screen */
473 struct NewScreen NewScreen = {
474 0,0,WDTH,HGHT,DPTH, /* Left,Top,Width,Height,Depth */
475 7,8,VIEW_MODE, /* DetailPen, BlockPen, ViewModes */
476 CUSTOMSCREEN,&MyFont,/* Type, Font */
477 (UBYTE *)"Expletive Deletion", /* Title */
478 NL,NL }; /* Gadgets, BitMap */
480 /* Used to open a Window */
481 struct NewWindow NewWindow = {
482 0,0,WDTH,HGHT, /* LeftEdge,TopEdge,Width,Height */
483 8,9, /* DetailPen,BlockPen */
484 CLOSEWINDOW | MOUSEMOVE | RAWKEY,
485 WINDOWCLOSE | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH |
487 ACTIVATE | REPORTMOUSE, /*Flags*/
488 NL,NL,"Main Window", /* FirstGadget, CheckMark, Title */
489 NL, /* MUST SET SCREEN AFTER OPENSCREEN!!! */
490 NL, /* BitMap */
491 100,60,32767,32767, /* MinW, MinH, MaxW, MaxH */
492 CUSTOMSCREEN }; /* Type */
495 /* These items are used as temp buffers for fill etc */
496 #define AREA_ENTS 400 /* Number of areabuffer entries, area_buf */
497 #define AREASIZ AREA_ENTS*5 /* Space for AreaInfo */
499 struct AreaInfo area_info;
500 struct TmpRas tmp_ras;
504 /****************************************************************
505 * init_generic()
508 * Opens Screen and full-sized Window for ****** program.
509 * Sets up TmpRas for draw and flood-fill
510 * Allocates and initializes various buffer areas...
512 * Initializes handles Screen,Window,pRp
514 * See also: close_generic() */
515 void init_generic()
517 if ( ! (IntuitionBase = (struct IntuitionBase *)
518 OpenLibrary("intuition.library",INTUITION_REV)) ||
519 ! (GfxBase = (struct GfxBase *)
520 OpenLibrary("graphics.library",GRAPHICS_REV)) ||
521 ! (Screen =(struct Screen *)OpenScreen(&NewScreen)) ) {
522 printf("Wow this shouldn't happen!!!\n");
523 exit(101);
526 NewWindow.Screen = Screen; /* NEED TO SET SCREEN!!! */
529 if ( ! (Window =(struct Window *)OpenWindow(&NewWindow))) {
530 printf("Sombody stole your memory!");
531 exit(102);
534 pRp = Window->RPort; /* Get E-Z acess to handles */
535 pUp = Window->UserPort;
536 pVp = (struct ViewPort *)ViewPortAddress(Window);
538 /* Allocate major buffer entries */
539 #ifdef USE_RAST
540 t_rast = (WORD *) AllocMem(RASSIZE(WDTH,HGHT), VID);
541 #endif
542 area_buf = (WORD *) AllocMem(2000,VID);
544 #ifdef USE_RAST
545 if ( ! t_rast || ! area_buf ) {
546 #else
547 if ( ! area_buf ) {
548 #endif
549 printf("Out of memory\n");
550 exit(103);
553 /* Initialize rastport temp buffers */
554 InitArea(&area_info,area_buf,AREA_ENTS);
556 pRp->AreaInfo = &area_info;
557 #ifdef USE_RAST
558 tmp_ras.RasPtr = (BYTE *)t_rast;
559 tmp_ras.Size = RASSIZE(WDTH,HGHT);
560 #endif
561 pRp->TmpRas = &tmp_ras;
565 /*************************************************
566 * close_generic
568 * Returns all resources gotten by init_generic
569 *************************************************/
570 void close_generic()
572 #ifdef USE_RAST
573 FreeMem(t_rast,RASSIZE(WDTH,HGHT));
574 #endif
575 FreeMem(area_buf,2000);
577 CloseWindow(Window);
578 CloseScreen(Screen);
580 exit(0);