/*FILE HEADER**************************************************************
 *
 *  File name		: $Id$
 *  RCS Revision Number	: $Revision: 1.1 $
 *  Last Modified	: $Date: 94/10/28 09:23:31 $
 *  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_hostint( void );
/*-----------------------------------------------------------------------*/
void test_hostint( void )
{
    fifo_t *buff;
    char   *str = "some text";
    int    i;


    init( "Host interrupt test" );
    W_vector_mask = ( CONDITION_ERROR | 
                      CONDITION_RAISE_INTERRUPT | 
                      CONDITION_BUFFER_FLIP | 
                      CONDITION_MALLOC | 
                      CONDITION_INQUIRE_TEXT_EXTENT | 
                      CONDITION_INQUIRE_PIXEL_SIZE | 
                      CONDITION_COMPARE_CURS_CLIPRECT | 
                      CONDITION_GET_PIXEL_ADDRESS | 
                      CONDITION_FRAME_TICK | 
                      CONDITION_CREATE_FIFO | 
                      CONDITION_GET_PIXEL );

    Set_interrupt_mode( ( int )GCC_VECT, ( int )GCC_LEVEL, W_vector_mask );

    /*
     * CONDITION_RAISE_INTERRUPT 
     */
    Printf("Testing interrupt source: raise interrupt\n");
    W_interrupt_flag = FALSE;
    Raise_interrupt( );
    Gcc_sync();
    if( W_interrupt_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_BUFFER_FLIP 
     */
    Printf("Testing interrupt source: flip buffers\n");
    W_flip_flag = FALSE;
    Set_frame_buffering( 0, 1 );
    Flip_buffers( BLACK, 0 );
    Gcc_sync();
    if( W_flip_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }
    Set_frame_buffering( 0, 0 );

    /*
     * CONDITION_MALLOC 
     */
    Printf("Testing interrupt source: malloc\n");
    W_malloc_flag = FALSE;
    buff = (fifo_t *)Gcc_malloc( sizeof(fifo_t ), 0 );
    malloc_check( buff );
    Gcc_sync();
    if( W_malloc_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_INQUIRE_TEXT_EXTENT 
     */
    Printf("Testing interrupt source: inquire text extent\n");
    W_inq_text_flag = FALSE;
    Copy_string_to_gcc( str, ( char *)( buff ), sizeof( str ) + 1 );
    Inquire_text_extent(( char * )( buff ), 
                        ( point_t *)(( uint32 )( buff ) + 0x100 ) );
    Gcc_sync();
    if( W_inq_text_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_INQUIRE_PIXEL_SIZE 
     */
    Printf("Testing interrupt source: inquire pixel size\n");
    W_inq_pixs_flag = FALSE;
    Inquire_pixel_size( ( int * )( buff ) );
    Gcc_sync();
    if( W_inq_pixs_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_COMPARE_CURS_CLIPRECT 
     */
    Printf("Testing interrupt source: compare point to cliprect\n");
    W_inq_pt_flag = FALSE;
    Compare_point_to_cliprect( 10, 20,  ( int * )( buff ) );
    Gcc_sync();
    if( W_inq_pt_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_GET_PIXEL_ADDRESS
     */
    Printf("Testing interrupt source: get pixel address\n");
    W_inq_addr_flag = FALSE;
    Get_pixel_address( 10, 20, ( int * )( buff ) );
    Gcc_sync();
    if( W_inq_addr_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_FRAME_TICK
     */
    Printf("Testing interrupt source: tick\n");
    W_tick_flag = 0;
    Gcc_sync();
    for( i = 0 ; i < 0xFFFF ; i++ ) ;
    if( W_tick_flag != 0 )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_CREATE_FIFO
     */
    Printf("Testing interrupt source: create fifo\n");
    W_new_fifo_flag = FALSE;
    Create_fifo( buff );
    Gcc_sync();
    if( W_new_fifo_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }

    /*
     * CONDITION_GET_PIXEL
     */
    Printf("Testing interrupt source: get pixel\n");
    W_get_pixl_flag = FALSE;

    Get_pixel( 10, 20, ( int * )( buff ) );
    Gcc_sync();
    if( W_get_pixl_flag )
    {
        Printf("Pass\n");
    }
    else
    {
        Printf("Fail\n");
    }
    Set_interrupt_mode( ( int )GCC_VECT, ( int )GCC_LEVEL, 0 );
}


/*-----------------------------------------------------------------------*/
