/*FILE HEADER**************************************************************
 *
 *  File name		: $Id$
 *  RCS Revision Number	: $Revision: 1.1 $
 *  Last Modified	: $Date: 94/10/28 09:23:25 $
 *  CSCI name		: Real-Time Graphics System - Applications Interface
 *  CSC name		: All functions
 *  Notes:
 *      This file contains code used to debug and test the SVME-770 RTGS.
 *      This code is provided as an example of how to call the RTGS functions
 *      from a host application.
 *  History		:
 *      Created 94/01/17 by Jeff Sanderson
 *
 *END FILE HEADER*********************************************************/

#include "dy4std.h"
#include "es.h"
#include "css.h"

#include "rtgs_ai.h"
#include "video.h"
#include "colours.h"

#include "test.h"


void time_lines( void );
/*-----------------------------------------------------------------------*/

uint32 buf[200];
point_t llist[10004];

void time_lines( void )
{
    int i;
    int frame_start;
    int frame_end;
    int time;
    float secs;
    int numvects;
    point_t *gcc_llist;
    int x1,x2,y1,y2;
    int incx;


    init( "Line benchmark" );

    Clear_screen( BLACK, 0, 0 );
    Set_foreground_colour( WHITE );
#define TEST_LINES
#ifdef TEST_LINES
    Printf("About to draw 1000000 lines\n");
    Key_wait();

    frame_start = FRAME_COUNT;
#ifdef OVERHEAD
    for( i = 0; i < 50000 ; i++ )
    {
	buf[ 0 ] = 0x00200000;
	buf[ 1 ] = 0x00000000;
	buf[ 2 ] = 0x00140014;

	buf[ 3 ] = 0x00200000;
	buf[ 4 ] = 0x00000000;
	buf[ 5 ] = 0x00140014;

	buf[ 6 ] = 0x00200000;
	buf[ 7 ] = 0x00000000;
	buf[ 8 ] = 0x00140014;

	buf[ 9 ] = 0x00200000;
	buf[10 ] = 0x00000000;
	buf[11 ] = 0x00140014;

	buf[12 ] = 0x00200000;
	buf[13 ] = 0x00000000;
	buf[14 ] = 0x00140014;

	buf[15 ] = 0x00200000;
	buf[16 ] = 0x00000000;
	buf[17 ] = 0x00140014;

	buf[18 ] = 0x00200000;
	buf[19 ] = 0x00000000;
	buf[20 ] = 0x00140014;

	buf[21 ] = 0x00200000;
	buf[22 ] = 0x00000000;
	buf[23 ] = 0x00140014;

	buf[24 ] = 0x00200000;
	buf[25 ] = 0x00000000;
	buf[26 ] = 0x00140014;

	buf[27 ] = 0x00200000;
	buf[28 ] = 0x00000000;
	buf[29 ] = 0x00140014;

	buf[30 ] = 0x00200000;
	buf[31 ] = 0x00000000;
	buf[32 ] = 0x00140014;

	buf[33 ] = 0x00200000;
	buf[34 ] = 0x00000000;
	buf[35 ] = 0x00140014;

	buf[36 ] = 0x00200000;
	buf[37 ] = 0x00000000;
	buf[38 ] = 0x00140014;

	buf[39 ] = 0x00200000;
	buf[40 ] = 0x00000000;
	buf[41 ] = 0x00140014;

	buf[42 ] = 0x00200000;
	buf[43 ] = 0x00000000;
	buf[44 ] = 0x00140014;

	buf[45 ] = 0x00200000;
	buf[46 ] = 0x00000000;
	buf[47 ] = 0x00140014;

	buf[48 ] = 0x00200000;
	buf[49 ] = 0x00000000;
	buf[50 ] = 0x00140014;

	buf[51 ] = 0x00200000;
	buf[52 ] = 0x00000000;
	buf[53 ] = 0x00140014;

	buf[54 ] = 0x00200000;
	buf[55 ] = 0x00000000;
	buf[56 ] = 0x00140014;

	buf[57 ] = 0x00200000;
	buf[58 ] = 0x00000000;
	buf[59 ] = 0x00140014;
	Put_cmd( buf, 60 );
#else
    for( i = 0; i < 20000 ; i++ )
    {
	buf[ 0 ] = 0x00100000;
	buf[ 1 ] = 0x00100000;
	buf[ 2 ] = 0x00100000;
	buf[ 3 ] = 0x00100000;
	buf[ 4 ] = 0x00100000;
	buf[ 5 ] = 0x00100000;
	buf[ 6 ] = 0x00100000;
	buf[ 7 ] = 0x00100000;
	buf[ 8 ] = 0x00100000;
	buf[ 9 ] = 0x00100000;
	buf[10 ] = 0x00100000;
	buf[11 ] = 0x00100000;
	buf[12 ] = 0x00100000;
	buf[13 ] = 0x00100000;
	buf[14 ] = 0x00100000;
	buf[15 ] = 0x00100000;
	buf[16 ] = 0x00100000;
	buf[17 ] = 0x00100000;
	buf[18 ] = 0x00100000;
	buf[19 ] = 0x00100000;
	buf[20 ] = 0x00100000;
	buf[21 ] = 0x00100000;
	buf[22 ] = 0x00100000;
	buf[23 ] = 0x00100000;
	buf[24 ] = 0x00100000;
	buf[25 ] = 0x00100000;
	buf[26 ] = 0x00100000;
	buf[27 ] = 0x00100000;
	buf[28 ] = 0x00100000;
	buf[29 ] = 0x00100000;
	buf[30 ] = 0x00100000;
	buf[31 ] = 0x00100000;
	buf[32 ] = 0x00100000;
	buf[33 ] = 0x00100000;
	buf[34 ] = 0x00100000;
	buf[35 ] = 0x00100000;
	buf[36 ] = 0x00100000;
	buf[37 ] = 0x00100000;
	buf[38 ] = 0x00100000;
	buf[39 ] = 0x00100000;
	buf[40 ] = 0x00100000;
	buf[41 ] = 0x00100000;
	buf[42 ] = 0x00100000;
	buf[43 ] = 0x00100000;
	buf[44 ] = 0x00100000;
	buf[45 ] = 0x00100000;
	buf[46 ] = 0x00100000;
	buf[47 ] = 0x00100000;
	buf[48 ] = 0x00100000;
	buf[49 ] = 0x00100000;
	Put_cmd( buf, 50 );
    }
#endif

    Gcc_sync();
    frame_end = FRAME_COUNT;
    time = frame_end - frame_start;
    secs = (float)((int)(time)) / 60.0;
    numvects = (int)((float)(1000000.0)/(float)(secs));

    Printf("Drew 1000000 lines in %d seconds\n",(int)(secs));
    Printf("Drew %d lines/sec\n",numvects);
    Key_wait();
#else
    Printf("Setting up for polylines\n");
    Clear_screen(0, 0, 0);

    x1 = 1;
    y1 = 1;
    x2 = 21;
    y2 = 21;
    incx = 1;
    for(i = 0 ; i < 1000; i += 2)
    {
        x1 += incx;
        x2 += incx;
        if(x2 >= (RES_X - 1))
        {
            incx = -incx;
        }
        if(x1 <= 0)
        {
            incx = -incx;
        }
     
        llist[i].x   = x1;
        llist[i].y   = y1;
        llist[i+1].x = x2;
        llist[i+1].y = y2;
    }
    gcc_llist = (point_t *)Gcc_malloc( 1002 * sizeof(point_t), 0);
    if( gcc_llist == 0 )
    {
        Printf("Malloc failed\n");
        return;
    }
    Copy_data_to_gcc( (char*)llist, (char*)gcc_llist, 1001 * sizeof(point_t) );

    Key_wait();

    frame_start = FRAME_COUNT;
    for(i = 0 ; i < 10000 ; i++ )
    {
        Draw_polyline( 1000, gcc_llist);
    }
    Gcc_sync();
    frame_end = FRAME_COUNT;
    time = frame_end - frame_start;
    Printf("strt = 0x%0.8x, end = 0x%0.8x\n",frame_start, frame_end);
    Printf("#frames = %d\n",frame_end - frame_start);
    secs = (float)((int)(time)) / 60.0;
    numvects = (int)((float)(10000000.0)/(float)(secs));

    Printf("Drew 10000000 polyline vectors in %d seconds\n",(int)(secs));
    Printf("Drew %d lines/sec\n",numvects);
    Printf("Done\n");
    Key_wait();
#endif
}

/*-----------------------------------------------------------------------*/
