/*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_pttoclip( void );
/*-----------------------------------------------------------------------*/

void test_pttoclip( void )
{
    int          *outcodes;

    init( "Compare point to cliprect test" );
    Clear_screen( BLACK, 0, 0 );

    outcodes = ( int * )Gcc_malloc( sizeof( int ) + 4, 0 );
    malloc_check( outcodes );

    Set_foreground_colour( WHITE );

    Draw_line((     RES_X / 3 ), 0, (     RES_X / 3 ), RES_Y );
    Draw_line(( 2 * RES_X / 3 ), 0, ( 2 * RES_X / 3 ), RES_Y );
    Draw_line( 0, (     RES_Y / 3 ), RES_X, (     RES_Y / 3 ));
    Draw_line( 0, ( 2 * RES_Y / 3 ), RES_X, ( 2 * RES_Y / 3 ));
    
    Set_clip_rectangle(( RES_X / 3 ), ( RES_Y / 3 ), 
                       ( 2 * RES_X / 3 ), ( 2 * RES_Y / 3 ));
    Set_clipping_mode( ON );
    

    Define_cursor( 0, (cursor_def_t *)( NULL ));
    Set_cursor_mode( ON );

    *outcodes = 0x12345678;
    Move_cursor( ( RES_X / 6 ), ( RES_Y / 6 ) );
    Compare_point_to_cliprect( ( RES_X / 6 ), ( RES_Y / 6 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x000000A0 )
    {
	Printf("Invalid outcodes for upper left sector\n");
        Printf("expected outcodes 0x000000A0, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Upper left sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( RES_X / 2 ), ( RES_Y / 6 ) );
    Compare_point_to_cliprect( ( RES_X / 2 ), ( RES_Y / 6 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000080 )
    {
	Printf("Invalid outcodes for upper centre sector\n");
        Printf("expected outcodes 0x00000080, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Upper centre sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( 5 * RES_X / 6 ), ( RES_Y / 6 ) );
    Compare_point_to_cliprect( ( 5 * RES_X / 6 ), ( RES_Y / 6 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x000000C0 )
    {
	Printf("Invalid outcodes for upper right sector\n");
        Printf("expected outcodes 0x000000C0, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Upper right sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( RES_X / 6 ), ( RES_Y / 2 ) );
    Compare_point_to_cliprect( ( RES_X / 6 ), ( RES_Y / 2 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000020 )
    {
	Printf("Invalid outcodes for centre left sector\n");
        Printf("expected outcodes 0x00000020, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Centre left sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( RES_X / 2 ), ( RES_Y / 2 ) );
    Compare_point_to_cliprect( ( RES_X / 2 ), ( RES_Y / 2 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000000 )
    {
	Printf("Invalid outcodes for centre sector\n");
        Printf("expected outcodes 0x00000000, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Centre sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( 5 * RES_X / 6 ), ( RES_Y / 2 ) );
    Compare_point_to_cliprect( ( 5 * RES_X / 6 ), ( RES_Y / 2 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000040 )
    {
	Printf("Invalid outcodes for centre right sector\n");
        Printf("expected outcodes 0x00000040, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Centre right sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( RES_X / 6 ), ( 5 * RES_Y / 6 ) );
    Compare_point_to_cliprect( ( RES_X / 6 ), ( 5 * RES_Y / 6 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000120 )
    {
	Printf("Invalid outcodes for lower left sector\n");
        Printf("expected outcodes 0x00000120, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Lower left sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( RES_X / 2 ), ( 5 * RES_Y / 6 ) );
    Compare_point_to_cliprect( ( RES_X / 2 ), ( 5 * RES_Y / 6 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000100 )
    {
	Printf("Invalid outcodes for lower centre sector\n");
        Printf("expected outcodes 0x00000100, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Lower centre sector passed\n");
    }
    Key_wait();

    *outcodes = 0x12345678;
    Move_cursor( ( 5 * RES_X / 6 ), ( 5 * RES_Y / 6 ) );
    Compare_point_to_cliprect( ( 5 * RES_X / 6 ), ( 5 * RES_Y / 6 ), outcodes );
    Gcc_sync();
    if( *outcodes != 0x00000140 )
    {
	Printf("Invalid outcodes for lower right sector\n");
        Printf("expected outcodes 0x00000140, got 0x%08x\n", *outcodes);
    }
    else
    {
	Printf("Lower right sector passed\n");
    }
    Key_wait();
    Set_cursor_mode( OFF );
}

