/*FILE HEADER**************************************************************
 *
 *  File name		: $Id$
 *  RCS Revision Number	: $Revision: 1.1 $
 *  Last Modified	: $Date: 94/10/28 09:23:30 $
 *  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 test_dblbuff( void );

/* ************************************************************************** */

void test_dblbuff( void )
{
    int    i, x, y;
    int    inc_x, inc_y;

    init( "Double buffering test" );

    Initialize_video( 4 ); /* 640 X 480 X 8 non-interlaced master */
    Set_frame_buffering( 0, 1 );
    Flip_buffers( ON, BLACK );
    Flip_buffers( ON, BLACK );

    inc_x = 0x20;
    inc_y = 0x20;
    i = 0;
    for( y = 0 ; y < RES_Y ; y += inc_y )
    {
        i++;
	for( x = 0 ; x < RES_X ; x +=  inc_x )
	{
            if( i++ & 1 )
            {
		Set_foreground_colour( RED );
            }
            else
            {
		Set_foreground_colour( BLUE );
            }
	    Draw_filled_rectangle( x, y, ( x + inc_x ), ( y + inc_y ));
	}
    }

    Printf("There screen should be blank\n");
    Key_wait();

    Flip_buffers( OFF, BLACK );
    Printf("There should be a 2 colour grid on the screen\n");
    Key_wait();

    inc_x = 0x20;
    inc_y = 0x20;
    i = 1;
    for( y = 0 ; y < RES_Y ; y += inc_y )
    {
        i++;
	for( x = 0 ; x < RES_X ; x +=  inc_x )
	{
            if( i++ & 1 )
            {
		Set_foreground_colour( RED );
            }
            else
            {
		Set_foreground_colour( BLUE );
            }
	    Draw_filled_rectangle( x, y, ( x + inc_x ), ( y + inc_y ));
	}
    }
    Printf("The screen should be toggleing between red and blue squares\n");
    Printf("in a very annoying manner\n");
    
    for( i = 0 ; i < 0x100 ; i++ )
    {
        Flip_buffers( OFF, BLACK );
	Gcc_sync();
        Delay( 1 );
    }
    Printf("Test done\n");
}

/*-----------------------------------------------------------------------*/
