/*FILE HEADER**************************************************************
 *
 *  File name		: $Id$
 *  RCS Revision Number	: $Revision: 1.1 $
 *  Last Modified	: $Date: 94/10/28 09:23:29 $
 *  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_cursor( void );
/*-----------------------------------------------------------------------*/

int cur_bitmap1[] = {
    0x00000000, 0x7FFF0000, 0x7FFE0000, 0x7FFC0000,
    0x7FF80000, 0x7FF00000, 0x7FE00000, 0x7FC00000,
    0x7FE00000, 0x7FF00000, 0x7EF80000, 0x7C7C0000,
    0x783E0000, 0x701F0000, 0x600F8000, 0x4007C000,
    0x0003E000, 0x0001F000, 0x0000F800, 0x00007C00,
    0x00003E00, 0x00001F00, 0x00000F80, 0x000007C0,
    0x000003E0, 0x000001F0, 0x000000F8, 0x0000007C,
    0x0000003E, 0x0000001E, 0x0000000E, 0x00000000
};

int cur_bitmap2[] = {
    0xFFFF8000, 0xFFFF8000, 0xFFFF8000, 0xFFFF0000,
    0xFFFE0000, 0xFFFC0000, 0xFFF80000, 0xFFF00000,
    0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
    0xFEFF8000, 0xFC7FC000, 0xF83FE000, 0xF01FF000,
    0xE00FF800, 0x0007FC00, 0x0003FE00, 0x0001FF00,
    0x0000FF80, 0x00007FC0, 0x00003FE0, 0x00001FF0,
    0x00000FF8, 0x000007FC, 0x000003FE, 0x000001FF,
    0x000000FF, 0x0000007F, 0x0000003F, 0x0000001F
};

void test_cursor( void )
{
    int          x, y;
    cursor_def_t *gcc_curs_def;
    uint32       *gcc_bitmap1;
    uint32       *gcc_bitmap2;
    int          *outcodes;
/*
    init( "Cursor test" );
*/
    gcc_curs_def = ( cursor_def_t * )Gcc_malloc( sizeof( cursor_def_t ), 0 );
    malloc_check( gcc_curs_def );

    gcc_bitmap1 = ( uint32 * )Gcc_malloc( sizeof( cur_bitmap1 ) + 8, 0 );
    malloc_check( gcc_bitmap1 );
    Copy_bitmap_to_gcc(( char * )cur_bitmap1, ( char * )gcc_bitmap1, 
                       sizeof( cur_bitmap1 ));

    gcc_bitmap2 = ( uint32 * )Gcc_malloc( sizeof( cur_bitmap2 ) + 8, 0 );
    malloc_check( gcc_bitmap2 );
    Copy_bitmap_to_gcc(( char * )cur_bitmap2, ( char * )gcc_bitmap2, 
                       sizeof( cur_bitmap2 ));

    outcodes = ( int * )Gcc_malloc( sizeof( int ) + 4, 0 );
    malloc_check( outcodes );


    Printf("Defining a crosshair cursor\n");

    Define_cursor( 0, gcc_curs_def );
    Set_cursor_mode( ON );

    Printf("The cursor should be tracking from left to right\n");
    Printf("halfway up the screen\n");

    Move_cursor(  0, ( RES_Y / 2 ));
    Delay( 1 );
    Gcc_sync();

    for( x = 0 ; x < RES_X ; x += 4 )
    {
	Move_cursor(  x, ( RES_Y / 2 ));
        Delay( 1 );
	Gcc_sync();
    }
    Key_wait();

    Printf("Turning on rubberband line\n");
    Move_cursor( (RES_X / 2 ), ( RES_Y / 4 ) );
    Delay( 1 );
    Gcc_sync();
    Set_rubberband_mode( ON, RUBBER_LINE );

    for( x = 0 ; x < RES_X ; x += 4 )
    {
	Move_cursor(  x, ( RES_Y / 2 ));
        Delay( 1 );
	Gcc_sync();
    }
    Set_rubberband_mode( OFF, RUBBER_LINE );
    Key_wait();

    Printf("Turning on rubberband box\n");
    Move_cursor( (RES_X / 2 ), ( RES_Y / 4 ) );
    Delay( 1 );
    Gcc_sync();
    Set_rubberband_mode( ON, RUBBER_BOX );

    for( x = 0 ; x < RES_X ; x += 4 )
    {
	Move_cursor(  x, ( RES_Y / 2 ));
        Delay( 1 );
	Gcc_sync();
    }
    Set_rubberband_mode( OFF, RUBBER_BOX );
    Key_wait();

    Printf("Defining a 1 bit per pixel cursor\n");

    gcc_curs_def->bitmap1.colour    = GREEN;
    gcc_curs_def->bitmap1.size_x    = 32;
    gcc_curs_def->bitmap1.size_y    = 32;
    gcc_curs_def->bitmap1.hotspot_x = 1;
    gcc_curs_def->bitmap1.hotspot_y = 1;
    gcc_curs_def->bitmap1.bitmap    = ( uint32 * )GSP_ADDR( gcc_bitmap1 );

    Define_cursor( 1, gcc_curs_def );
    Set_cursor_mode( ON );

    Printf("The cursor should be tracking from left to right\n");
    Printf("halfway up the screen\n");

    for( x = 0 ; x < RES_X ; x += 4 )
    {
	Move_cursor(  x, ( RES_Y / 2 ));
        Delay( 1 );
	Gcc_sync();
    }
    Key_wait();

    Printf("Defining a 2 bit per pixel cursor\n");

    gcc_curs_def->bitmap2.colour1   = GREEN;
    gcc_curs_def->bitmap2.colour2   = RED;
    gcc_curs_def->bitmap2.size_x    = 32;
    gcc_curs_def->bitmap2.size_y    = 32;
    gcc_curs_def->bitmap2.hotspot_x = 1;
    gcc_curs_def->bitmap2.hotspot_y = 1;
    gcc_curs_def->bitmap2.bitmap1   = ( uint32 * )GSP_ADDR( gcc_bitmap2 );
    gcc_curs_def->bitmap2.bitmap2   = ( uint32 * )GSP_ADDR( gcc_bitmap1 );


    Define_cursor( 2, gcc_curs_def );
    Set_cursor_mode( ON );

    Printf("The cursor should be tracking from top to bottom\n");
    Printf("halfway across the screen\n");

    for( y = 0 ; y < RES_Y ; y += 4 )
    {
	Move_cursor(( RES_X / 2 ), y );
        Delay( 1 );
	Gcc_sync();
    }
    Key_wait();
}
