/*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_custinit( void );
void Save_video_mode_test( void );
/*-----------------------------------------------------------------------*/

void test_custinit( void )
{
    video_params_t  *params;

    init( "Custom initialize video test" );

    Printf(" setting video to mode 2\n");
    Initialize_video(2);
    Clear_screen( WHITE, 0, 0 );

    Printf("getting video parameters \n");
    params = (video_params_t *)Gcc_malloc( sizeof(video_params_t), 0);
    malloc_check(params);
    Get_video_mode( params );
    Gcc_sync();

    Printf("Setting video to mode 4\n");
    Initialize_video(4);
    Clear_screen( WHITE, 0, 0 );
    Key_wait();

    Printf("reseting to mode 2 by calling custom init vide\n");
    Custom_initialize_video( params );
    Clear_screen( WHITE, 0, 0 );
    Key_wait();
    Gcc_free( (char *)( params ));
}

/*-----------------------------------------------------------------------*/


void Save_video_mode_test( void )
{
    uint32 tmp1;
    uint32 tmp2;


    init(" Save video mode test");

    Printf("Setting video mode to 1024x768\n");
    Initialize_video( 11 );  /* 1024x768 */
    Clear_screen( 0, 0, 0 );   /* black screen */
    Draw_line( 1024, 0, 0, 768 );
    Printf("There should be a line from the top right to the bottom left\n");
    Key_wait();

    Printf("Calling save video mode\n");
    Save_video_mode();
    Gcc_sync();

    Printf("Setting video mode to 1280x1024\n");
    Initialize_video( 3 );  /* 1280x1024 */
    Clear_screen( 0, 0, 0 );   /* black screen */
    Draw_line( 0, 0, 1280, 1024 );
    Printf("There should be a line from the top left to the bottom right\n");
    Key_wait();

    Printf("Reseting the 770, wait while RTGS re-inits\n");
    Gcc_sync();
    INT_LEVEL_REG |= 0x20;
    Wait( 2000 );      
    Take_gcc_out_of_bi_mode();
    INT_LEVEL_REG &= ~0x20;
    do{
	tmp1 = FRAME_COUNT;
	Wait( 20000 );      /* wait 20 mS for tick incr */
	tmp2 = FRAME_COUNT;
    }while( tmp1 == tmp2 );
    
    Initialize_graphics();
    Clear_screen( 0, 0, 0 );   /* black screen */
    Draw_line( 1024, 0, 0, 768 );
    Printf("There should be a line from the top right to the bottom left\n");
    Key_wait();

    Printf("Reseting the 770 seeprom\n");
    Reset_seeprom();
    Gcc_sync();

    Printf("Reseting the 770, wait while RTGS re-inits\n");
    INT_LEVEL_REG |= 0x20;
    Wait( 2000 );      
    Take_gcc_out_of_bi_mode();
    INT_LEVEL_REG &= ~0x20;
    do{
	tmp1 = FRAME_COUNT;
	Wait( 20000 );      /* wait 20 mS for tick incr */
	tmp2 = FRAME_COUNT;
    }while( tmp1 == tmp2 );
    

    Initialize_graphics();
    Clear_screen( 0, 0, 0 );   /* black screen */
    Draw_line( 0, 0, 1280, 1024 );
    Printf("There should be a line from the top left to the bottom right\n");
    Key_wait();
}
