/*FILE HEADER**************************************************************
 *
 *  File name		: $Id$
 *  RCS Revision Number	: $Revision: 1.1 $
 *  Last Modified	: $Date: 94/10/28 09:23:33 $
 *  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_pixel( void );
/*-----------------------------------------------------------------------*/


void test_pixel( void )
{
    int    *buffer;
    int    *tmp;
    int    *tmp1;


    init( "Pixel test" );

    Initialize_video( 3 );
    Clear_screen( BLACK, 0, 0 );
    Draw_grid( 0x10 );

    buffer = ( int * )Gcc_malloc( sizeof( int ), 0 );
    malloc_check( buffer );

    Printf("Calling get pixel size\n");

    Inquire_pixel_size( buffer );
    Gcc_sync();
    Printf("Pixel size is 0x%02x\n", *buffer );
    Key_wait();

    Set_foreground_colour( GREEN );
    Draw_filled_rectangle( 0, 0, 16, 16 );

    Printf("Calling put and get pixel\n");

    Put_pixel( 0, 0, 0xA5 );
    Get_pixel( 0, 0, buffer );
    Gcc_sync();

    if( *buffer != 0x000000A5 )
    {
        Printf("Put pixel A5, read pixel, 0x%08x\n", *buffer );
    }
    else
    {
        Printf("Pass\n");
    }
    Key_wait();

    Printf("Calling get pixel_address\n");

    Get_pixel_address( 0, 0, buffer );
    Gcc_sync();

    tmp = ( int * )( VME_ADDR( *buffer ));
    Printf("Pixel local address is , 0x%08x\n", *buffer );
    Printf("Pixel vme   address is , 0x%08x\n", tmp );

    if( ( *tmp  & 0xFF ) != 0xA5 )
    {
        Printf("Put pixel A5, read pixel, 0x%08x\n", *tmp );
    }
    else
    {
        Printf("Pass\n");
    }
    Key_wait();

    Printf("Calling Move_screen\n");

    Get_pixel_address( 0, 100, buffer );
    Gcc_sync();
    tmp = ( int * )( VME_ADDR( *buffer ));

    Get_pixel_address( 0, 0, buffer );
    Gcc_sync();
    tmp1 = ( int * )( VME_ADDR( *buffer ));

    Printf("There should be a rectangle at 0,100 \n");
    Draw_filled_rectangle( 0, 100, 16, 116 );
    Key_wait();

    Printf("the rectangle should be at the top of the screen\n");
    Move_screen( tmp, tmp );
    Gcc_sync();
    Key_wait();
    
    Printf("There should be a rectangle at 0,100 \n");
    Move_screen( tmp1, tmp1 );
    Gcc_sync();
    Key_wait();
    
    Printf("Calling set screen offset\n");

    Set_screen_offset( 0x10, 0 );

    Set_foreground_colour( BLUE );
    Draw_filled_rectangle( 0, 0, 16, 16 );

    Printf("Calling put and get pixel\n");

    Put_pixel( 0, 0, 0xA5 );
    Get_pixel( 0, 0, buffer );
    Gcc_sync();

    if( *buffer != 0x000000A5 )
    {
        Printf("Put pixel A5, read pixel, 0x%08x\n", *buffer );
    }
    else
    {
        Printf("Pass\n");
    }
    Key_wait();

    Printf("Calling get pixel_address\n");

    Get_pixel_address( 0, 0, buffer );
    Gcc_sync();
    tmp = ( int * )( VME_ADDR( *buffer ));
    Printf("Pixel local address is , 0x%08x\n", *buffer );
    Printf("Pixel vme   address is , 0x%08x\n", tmp );
    
    if( ( *tmp & 0xFF ) != 0xA5 )
    {
        Printf("Put pixel A5, read pixel, 0x%08x\n", *tmp );
    }
    else
    {
        Printf("Pass\n");
    }
}

