Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : 8514TEST.C

 
Output of file : 8514TEST.C contained in archive : PCTJ8805.ZIP
/* 8514/A Benchmark Test */
/* Requires ibmafi.h, callafi.obj, and hdiload.exe from IBM */
#include
#include
#include
#include
#include
#include
#include
#include

#include "ibmafi.h"

#define HL_COUNT 100 /* Horizontal Line drawing count */
#define VL_COUNT 10 /* Vertical Line drawing count */
#define SF_COUNT 50 /* Screen Fill rectangle count */
#define RL_COUNT 500 /* Random Lines drawing count */
#define RR_COUNT 5 /* Random Rectangle drawing count */

#define RANDOM_PASS 100 /* Number of lines in 1 random pass */
#define NUM_TESTS 35 /* Total number of benchmark tests */

struct testData
{
int loopCount;
long items;
long pixels;
long time;
};

HOPEN_DATA open_data = { 3, 0, 0 };
HCLOSE_DATA close_data = { 2, 0 };

struct timeb startTime, endTime;
struct testData tests[NUM_TESTS];
char *testNames[] = {"Horizontal Lines (REPLACE)",
"Horizontal Lines (XOR)",
"Horizontal Lines (ADD)",
"Horizontal Lines (AVERAGE)",
"Vertical Lines (REPLACE)",
"Vertical Lines (XOR)",
"Vertical Lines (ADD)",
"Vertical Lines (AVERAGE)",
"Screen Clear (REPLACE)",
"Screen Clear (XOR)",
"Screen Clear (ADD)",
"Screen Clear (AVERAGE)",
"Random Long Lines (REPLACE)",
"Random Long Lines (XOR)",
"Random Long Lines (ADD)",
"Random Long Lines (AVERAGE)",
"Random Medium Lines (REPLACE)",
"Random Medium Lines (XOR)",
"Random Medium Lines (ADD)",
"Random Medium Lines (AVERAGE)",
"Random Short Lines (REPLACE)",
"Random Short Lines (XOR)",
"Random Short Lines (ADD)",
"Random Short Lines (AVERAGE)",
"Random Null Lines (REPLACE)",
"Random Null Lines (XOR)",
"Random Null Lines (ADD)",
"Random Null Lines (AVERAGE)",
"Random Rectangles (REPLACE)",
"Random Rectangles (XOR)",
"Random Rectangles (ADD)",
"Random Rectangles (AVERAGE)"};

int xRes, yRes;
int curTest;
int xLineLength, yLineLength;

/*
Local Function Prototypes
*/

void ShowResults (void);
void StartTimer (void);
void StopTimer (void);
void ReportTimer (int, long, long);
int GetRandom (int);
int *MakeRandomTable (int, int);
void SetMix (char);
void ClearScreen (void);
long AddLengths (int *, int *, int);
long AddSizes (int *, int *, int);

long HorizontalLineFill (int);
long VerticalLineFill (int);
long SolidScreenFill (int);
long RandomLines (int);
long RandomRects (int);

void RunSuite (long (*)(int), int, long);
void RunTests (void);
int main (void);

/*
Local Functions
*/

void ShowResults ()
{
register int i;
double temp;

for (i = 0; i < curTest; i++)
{
printf ("%s: %ld pixels,",
testNames[i],
tests[i].pixels);

temp = ((double) tests[i].pixels) * 1000.0;

printf (" %4.2f seconds, %ld pixels/second\n",
((double) tests[i].time) / 1000.0,
(long) (temp / ((double) tests[i].time)));
}

return;
}

void StartTimer ()
{
ftime (&startTime);
return;
}

void StopTimer ()
{
ftime (&endTime);
return;
}

void ReportTimer (loopCount, items, pixels)
int loopCount;
long items;
long pixels;
{
tests[curTest].loopCount = loopCount;
tests[curTest].items = items;
tests[curTest].pixels = pixels;
tests[curTest].time = (((long) endTime.time) * 1000)
+ endTime.millitm
- (((long) startTime.time) * 1000)
- startTime.millitm;
curTest++;

return;
}

long AddLengths (x, y, count)
int *x;
int *y;
int count;
{
long retVal;
register int i;
double dX, dY;

retVal = 0;
for (i = 0; i < count - 1; i++)
{
dX = (double) x[i + 1] - (double) x[i];
dY = (double) y[i + 1] - (double) y[i];
retVal += (long) (sqrt ((dX * dX) + (dY * dY)));
}

return retVal;
}

long AddSizes (x, y, count)
int *x;
int *y;
int count;
{
long retVal;
register int i;

retVal = 0;
for (i = 0; i < count - 1; i++)
retVal += (long) (((xRes / 2) - x[i]) * 2) *
(long) (((yRes / 2) - y[i]) * 2);

return retVal;
}

int GetRandom (limit)
int limit;
{
unsigned long temp;

temp = (long) rand () * (long) limit;
temp >>= 15;
return (int) temp;
}

int *MakeRandomTable (entries, limit)
int entries;
int limit;
{
int *table;
register int i;

table = (int *) malloc (entries * sizeof (int));

for (i = 0; i < entries; i++)
table[i] = GetRandom (limit);

return table;
}

void SetMix (rasterOp)
char rasterOp;
{
HSMX_DATA mix;

mix.length = 2;
mix.foremix = rasterOp;
mix.backmix = rasterOp;
HSMX (&mix);
return;
}

void ClearScreen ()
{
HEGS ();
return;
}

long HorizontalLineFill (loopCount)
int loopCount; /* Number of times to run the test */
{
register int i, j; /* Loop counters */
HLINE_DATA(2) line; /* Data structure for line drawing */
HSCOL_DATA color; /* Data structure for color setting */

color.length = 4;
color.index = 0; /* Cycle colors as we run the test */
HSCOL (&color);

line.length = 8; /* Only draw 4 coords (two points) */
line.coords[0].x_coord = 0; /* Draw full-width scan lines */
line.coords[1].x_coord = xRes - 1;

StartTimer ();
j = loopCount; /* Number of times to run test */
while (j--)
{
line.coords[0].y_coord = 0;
line.coords[1].y_coord = 0;

i = yRes; /* Number of lines on the screen */
while (i--)
{
HLINE (&line); /* Issue line drawing command */
line.coords[0].y_coord++;
line.coords[1].y_coord++;
} /* Go to next scan line */

color.index += 16; /* Move to the next color */
HSCOL (&color);
} /* Run next loop of test */

StopTimer ();
return (long) xRes * yRes * loopCount;
}

long VerticalLineFill (loopCount)
int loopCount; /* Number of times to run the test */
{
register int i, j; /* Loop counters */
HLINE_DATA(2) line; /* Data structure for line drawing */
HSCOL_DATA color; /* Data structure for color setting */

color.length = 4;
color.index = 0; /* Cycle colors as we run the test */
HSCOL (&color);

line.length = 8; /* Only draw 4 coords (two points) */
line.coords[0].y_coord = 0; /* Draw full-height vertical lines */
line.coords[1].y_coord = yRes - 1;

StartTimer ();
j = loopCount; /* Number of times to run test */
while (j--)
{
line.coords[0].x_coord = 0;
line.coords[1].x_coord = 0;

i = xRes; /* Number of lines on the screen */
while (i--)
{
HLINE (&line); /* Issue line drawing command */
line.coords[0].x_coord++;
line.coords[1].x_coord++;
} /* Go to next scan line */

color.index += 16; /* Move to the next color */
HSCOL (&color);
} /* Run next loop of test */

StopTimer ();
return (long) xRes * yRes * loopCount;
}

long SolidScreenFill (loopCount)
int loopCount; /* Number of times to run the test */
{
register int i; /* Loop counter */
HRECT_DATA rect; /* Data structure for rect filling */
HSCOL_DATA color; /* Data structure for color setting */

color.length = 4;
color.index = 0; /* Cycle colors as we run the test */
HSCOL (&color);

rect.length = 8; /* Four coordinates for the corners */
rect.coord.x_coord = 0; /* Draw a full-screen rectangle */
rect.coord.y_coord = 0;
rect.width = xRes;
rect.height = yRes;

StartTimer ();
i = loopCount; /* Number of times to run test */
while (i--)
{
HRECT (&rect); /* Clear the entire screen */
color.index += 16; /* Move to the next color */
HSCOL (&color);
} /* Run next loop of test */

StopTimer ();
return (long) xRes * yRes * loopCount;
}

long RandomLines (loopCount)
int loopCount;
{
register int i, j; /* Loop counters */
HLINE_DATA(2) line; /* Data structure for line drawing */
HSCOL_DATA color; /* Data structure for color setting */
int *randX; /* Table of random X values */
int *randY; /* Table of random Y values */
long retVal; /* Returned number of pixels */

color.length = 4;
color.index = 0; /* Cycle colors as we run the test */
HSCOL (&color);

randX = MakeRandomTable (RANDOM_PASS + 1, xLineLength);
randY = MakeRandomTable (RANDOM_PASS + 1, yLineLength);
retVal = AddLengths (randX, randY, RANDOM_PASS + 1);

line.length = 8; /* Only draw 4 coords (two points) */

StartTimer ();
j = loopCount; /* Number of times to run test */
while (j--)
{
i = RANDOM_PASS; /* Number of random lines to draw */
while (--i >= 0)
{
line.coords[0].x_coord = randX[i];
line.coords[0].y_coord = randY[i];
line.coords[1].x_coord = randX[i + 1];
line.coords[1].y_coord = randY[i + 1];
HLINE (&line); /* Issue line drawing command */
} /* Go to next scan line */

color.index += 16; /* Move to the next color */
HSCOL (&color);
} /* Run next loop of test */

StopTimer ();
free (randX);
free (randY);

return retVal * RL_COUNT;
}

long RandomRects (loopCount)
int loopCount;
{
register int i, j; /* Loop counters */
HRECT_DATA rect; /* Data structure for rect drawing */
HSCOL_DATA color; /* Data structure for color setting */
int *randX; /* Table of random X values */
int *randY; /* Table of random Y values */
long retVal; /* Returned number of pixels */

color.length = 4;
color.index = 0; /* Cycle colors as we run the test */
HSCOL (&color);

randX = MakeRandomTable (RANDOM_PASS + 1, xRes / 2);
randY = MakeRandomTable (RANDOM_PASS + 1, yRes / 2);
retVal = AddSizes (randX, randY, RANDOM_PASS + 1);

rect.length = 8; /* Only draw 4 coords (two points) */

StartTimer ();
j = loopCount; /* Number of times to run test */
while (j--)
{
i = RANDOM_PASS; /* Number of random lines to draw */
while (--i >= 0)
{
rect.coord.x_coord = randX[i];
rect.coord.y_coord = randY[i];
rect.width = ((xRes / 2) - randX[i]) << 1;
rect.height = ((yRes / 2) - randY[i]) << 1;
HRECT (&rect); /* Issue line drawing command */

color.index += 16; /* Move to the next color */
HSCOL (&color);
} /* Go to next scan line */
} /* Run next loop of test */

StopTimer ();
free (randX);
free (randY);

return retVal * RR_COUNT;
}

void RunSuite (suiteTest, count, items)
long (*suiteTest) (int);
int count;
long items;
{
ClearScreen ();
SetMix (MIX_OVER);
ReportTimer (count, items, (*suiteTest) (count));

ClearScreen ();
SetMix (MIX_XOR);
ReportTimer (count, items, (*suiteTest) (count));

ClearScreen ();
SetMix (MIX_ADD);
ReportTimer (count, items, (*suiteTest) (count));

ClearScreen ();
SetMix (MIX_MEAN);
ReportTimer (count, items, (*suiteTest) (count));

return;
}

void RunTests ()
{

/*
Horizontal Lines - Fill the screen with horizontal lines
*/

RunSuite (HorizontalLineFill, HL_COUNT, (long) yRes * HL_COUNT);

/*
Vertical Lines - Fill the screen with vertical lines
*/

RunSuite (VerticalLineFill, VL_COUNT, (long) xRes * VL_COUNT);

/*
Filled Rectangles - Full-screen solid filled rectangles
*/

RunSuite (SolidScreenFill, SF_COUNT, (long) SF_COUNT);

/*
Random Lines - RANDOM_PASS random lines
*/

xLineLength = xRes;
yLineLength = yRes;
RunSuite (RandomLines, RL_COUNT, (long) RL_COUNT);
xLineLength = 50;
yLineLength = 50;
RunSuite (RandomLines, RL_COUNT, (long) RL_COUNT);
xLineLength = 5;
yLineLength = 5;
RunSuite (RandomLines, RL_COUNT, (long) RL_COUNT);
xLineLength = 0;
yLineLength = 0;
RunSuite (RandomLines, RL_COUNT, (long) RL_COUNT);

/*
Random Rectangles - RANDOM_PASS random rectangles
*/

RunSuite (RandomRects, RR_COUNT, (long) RR_COUNT);

return;
}

int main ()
{
HINIT_DATA taskState;
HQDPS_DATA stateBufferInfo;
HQMODE_DATA modeData;
union REGS inregs, outregs;
struct SREGS segregs;

/*
Check to see that the adapter interface is installed. If it is
not, we can't proceed.
*/

if (getafi () == NULL)
{
printf ("Please run HDILOAD to install the Adapter Interface.\n");
return 1;
}

/*
The adapter interface is installed, so the entry points in it
can be called safely. Open the adapter to its default state
and verify that the open worked.
*/

HOPEN (&open_data); /* Open the Adapter Interface */
if (open_data.iflags) /* If an error occurred on the open */
{
printf ("Adapter Open error: %X\n", open_data.iflags);
return 1;
}

/*
Allocate a block of memory for the task-dependent state buffer.
This buffer is filled in by a call to HINIT, and must be set up
even if the adapter's state will not be switched later.
*/

stateBufferInfo.length = 6; /* Size of the returned buffer info */
HQDPS (&stateBufferInfo);

/*
The state buffer info block now holds the size of the task-
dependent state buffer required by HINIT. Since HINIT is passed
a segment value as a pointer to the buffer and assumes that the
buffer begins at offset 0 in that segment, we'll call the DOS
memory allocation service to allocate an appropriate block.
*/

inregs.h.ah = 0x48; /* Allocate DOS memory segment */
inregs.x.bx = stateBufferInfo.size;
intdos (&inregs, &outregs);
taskState.segment = outregs.x.ax;

taskState.length = 2; /* Size of the segment pointer */
HINIT (&taskState); /* Initialize the opened adapter */

modeData.length = 18; /* Get the adapter's default mode */
HQMODE (&modeData);

xRes = modeData.width; /* Store screen size for benchmark */
yRes = modeData.height; /* use later */

RunTests (); /* Execute the benchmarks */

/*
Release the task state buffer and close the adapter.
*/

inregs.h.ah = 0x49; /* Free DOS memory segment */
segregs.es = taskState.segment;
int86x (0x21, &inregs, &outregs, &segregs);

HCLOSE (&close_data); /* Close Adapter Interface */

ShowResults (); /* Display accumulated test data */

return 0; /* Successful operation */
}


  3 Responses to “Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : 8514TEST.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/