home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 28
/
amigaformatcd28.iso
/
-seriously_amiga-
/
misc
/
posbb
/
src
/
amigaos
/
gfx.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-05-09
|
7KB
|
266 lines
#include <stdio.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <math.h>
#include "compiler.h"
/****** posbb_tests.c/Test_WritePixel ********************************************
*
* NAME
* Test_WritePixel -- Tests pixel writing speed.
*
* SYNOPSIS
* time = Test_WritePixel(struct RastPort *rport,int precision)
* ULONG Test_WritePixel( struct RastPort,int );
*
* FUNCTION
* Fill the given rastport pixel by pixel with graphics.library/WritePixel()
* and returns the time taken.
*
* INPUT
* *rport pointer to a valid RastPort structure to draw on.
*
* int precision the precision of the results. Can be any of
* POSBB_PREECISION#?. The higher is the precision wanted,
* the higher the time taken. precision is useful on faster
* machines,on wich the times will be too low.
*
* RESULT
* time - Time spent in seconds. No errors can be returned.
*
* EXAMPLE
* See posbb.c/Perform_Tests.
*
* BUGS
* No known bugs.
*
****************************************************************************
*/
ULONG Test_WritePixel( rport,precision,freeze,mt)
struct RastPort *rport;
int precision;
BOOL freeze,mt;
{
struct timeval *time1,*time2;
int x,y,pen;
ULONG secs,time;
char tmpstr[20];
time1 = (struct timeval *) POSBB_AllocMem(sizeof(struct timeval),0);
time2 = (struct timeval *) POSBB_AllocMem(sizeof(struct timeval),0);
#ifndef NOFORBID
if (freeze == TRUE) Forbid();
#endif
if (mt)
{
printf("Press RETURN to start");
getchar();
}
else GetSysTime(time1); /* This gets the system time using timer.device. It is opened by posbb.c */
for (pen=0;pen<4*precision;pen++)
{
SetAPen(rport,pen);
for (y=0;y<255;y++)
{
for (x=0;x<319;x++)
{
WritePixel(rport,x,y);
}
}
}
if (mt)
{
DisplayBeep();
printf("Test finished. Type in the number of seconds taken:");
secs = atoi(gets(tmpstr));
}
else GetSysTime(time2);
#ifndef NOFORBID
if (freeze == TRUE) Permit();
#endif
if (mt) time = secs * 1000;
else
{
SubTime(time2,time1);
time = (time2->tv_secs)*1000+(time2->tv_micro)/1000;
}
POSBB_FreeMem(time1,sizeof(struct timeval));
POSBB_FreeMem(time2,sizeof(struct timeval));
return time;
}
/****** posbb_tests.c/Test_DrawEllipse ********************************************
*
* NAME
* Test_DrawEllipse -- Tests pixel ellipse drawing speed.
*
* SYNOPSIS
* time = Test_DrawEllipse(struct RastPort *rport,int precision)
* ULONG Test_DrawEllipse( struct RastPort,int );
*
* FUNCTION
* Draws some ellipses in the given rastport and returns the time taken.
*
*
* INPUT
* struct RastPort *rport pointer to a valid RastPort structure
*
* int precision the precision of the results. Can be any of
* POSBB_PREECISION#?. The higher is the precision wanted,
* the higher the time taken. precision is useful on faster
* machines,on wich the times will be too low.
*
* RESULT
* time - Time spent in seconds. No error can be returned.
*
* EXAMPLE
* See posbb.c/Perform_Tests.
*
* BUGS
* No known bugs.
*
****************************************************************************
*/
ULONG Test_DrawEllipse(rport,precision,freeze,mt)
struct RastPort *rport;
int precision;
BOOL freeze,mt;
{
struct timeval *time1,*time2;
short a,b,pen;
ULONG secs,time;
char tmpstr[20];
time1 = (struct timeval *) POSBB_AllocMem(sizeof(struct timeval),0);
time2 = (struct timeval *) POSBB_AllocMem(sizeof(struct timeval),0);
#ifndef NOFORBID
if (freeze == TRUE) Forbid();
#endif
if (mt)
{
printf("Press RETURN to start");
getchar();
}
else GetSysTime(time1); /* This gets the system time using timer.device. It is opened by posbb.c */
for (pen=0;pen<4*precision;pen++)
{
SetAPen(rport,pen);
for (a=1;a<159;a++)
{
b = ((a * 256) / 320);
DrawEllipse(rport,159,127,a,b);
}
}
if (mt)
{
DisplayBeep();
printf("Test finished. Type in the number of seconds taken:");
secs = atoi(gets(tmpstr));
}
else GetSysTime(time2);
#ifndef NOFORBID
if (freeze == TRUE) Permit();
#endif
if (mt) time = secs * 1000;
else
{
SubTime(time2,time1);
time = (time2->tv_secs)*1000+(time2->tv_micro)/1000;
}
POSBB_FreeMem(time1,sizeof(struct timeval));
POSBB_FreeMem(time2,sizeof(struct timeval));
return time;
}
/****** posbb_tests.c/Test_Draw ***********************************************
*
* NAME
* Test_Draw -- Tests pixel ellipse drawing speed.
*
* SYNOPSIS
* time = Test_Draw(struct RastPort *rport,int precision)
* ULONG Test_Draw( struct RastPort,int );
*
* FUNCTION
* Draws some lines in the given rastport and returns the time taken.
*
*
* INPUT
* struct RastPort *rport Pointer to a valid RastPort structure to draw on.
*
* int precision the precision of the results. Can be any of
* POSBB_PREECISION#?. The higher is the precision wanted,
* the higher the time taken. precision is useful on faster
* machines,on wich the times will be too low.
*
* RESULT
* time - Time spent,in seconds.
*
* EXAMPLE
* See posbb.c/Perform_Tests.
*
* BUGS
* No known bugs.
*
****************************************************************************
*/
ULONG Test_Draw(rport,precision,freeze,mt)
struct RastPort *rport;
int precision;
BOOL freeze,mt;
{
struct timeval *time1,*time2;
short x,y,x1,y1,pen;
ULONG secs,time;
char tmpstr[20];
time1 = (struct timeval *) POSBB_AllocMem(sizeof(struct timeval),0);
time2 = (struct timeval *) POSBB_AllocMem(sizeof(struct timeval),0);
#ifndef NOFORBID
if (freeze == TRUE) Forbid();
#endif
if (mt)
{
printf("Press RETURN to start");
getchar();
}
else GetSysTime(time1); /* This gets the system time using timer.device. It is opened by posbb.c */
Move(rport,0,0);
for(pen=0;pen<4*precision;pen++)
{
SetAPen(rport,pen);
for (y=0;y<256;y++)
{
Draw(rport,320,y);
Move(rport,0,0);
}
for (x=0;x<320;x++) {
Draw(rport,x,256);
Move(rport,0,0);}
SetAPen(rport,pen-1);
for(y=0;y<256;y++) {
Draw(rport,320,y);
Draw(rport,0,y+1); }
}
if (mt)
{
DisplayBeep();
printf("Test finished. Type in the number of seconds taken:");
secs = atoi(gets(tmpstr));
}
else GetSysTime(time2);
#ifndef NOFORBID
if (freeze == TRUE) Permit();
#endif
if (mt) time = secs * 1000;
else
{
SubTime(time2,time1);
time = (time2->tv_secs)*1000+(time2->tv_micro)/1000;
}
POSBB_FreeMem(time1,sizeof(struct timeval));
POSBB_FreeMem(time2,sizeof(struct timeval));
return time;
}