/*FILE HEADER**************************************************************
 *
 *  File name		: utile.c
 *  RCS Revision Number	: 
 *  Last Modified	: oct-10-1994 by s.coudray/MBARI-IFREMER
 *  CSCI name		: Real-Time Graphics System - Applications Interface
 *  CSC name		: All functions
 *  Notes:
 *	This file contains the set of functions which can be used by
 *	application programs to drive a DY 4 Graphics Controller Card
 *	equipped with Real-Time Graphics System - Command Processor
 *	firmware.
 *  History		:
 *	1993 Nov 15	Jeff Sanderson
 *        Created for use with test code for SVME-770 RTGS
 *	1994 Oct 10	Sylvain Coudray
 *		Taking out all statements relative to CIT that is
 *		not provided with video card in function Key_wait.
 *
 *END FILE HEADER*********************************************************/

#include "dy4std.h"
#include "es.h"
#include "css.h"

#include "rtgs_ai.h"
#include "video.h"
#include "colours.h"

/*- Local function prototypes -----------------------------------------------*/

void Key_wait( void );  
void malloc_check( void *ptr );
void init( char *str );
void bkpb(char *str);
void Draw_grid( int step );


/*---------------------------------------------------------------------------*/
/* Debugging function, prints, if you don't have an emulator on the host, it */
/* allows you to print out where you got to in the code and whats gone wrong */
/*---------------------------------------------------------------------------*/

void bkpt(char *str)
{
    Printf("%s\n",str);
    Printf("Error code: 0x%08x\n", Get_error_code() );
    Getc(CSS_SIO0);
}


/*---------------------------------------------------------------------------*/
/* User interactive flow control for test code                               */
/*---------------------------------------------------------------------------*/

void Key_wait( void )
{
    int i;

    Gcc_sync();
    Printf("Hit any key to continue\n");

/*MBARI-IFREMER ### This part of software is not provided with our card
 *   Getc(CSS_SIO0);
 *ENDMBARI-IFREMER*/

    i = Getchar ();
    Printf("\n\n");
}


/*---------------------------------------------------------------------------*/
/* Check the return from Gcc_malloc()                                        */
/*---------------------------------------------------------------------------*/

void malloc_check( void *ptr )
{
    if( ptr == 0 )
    {
        Printf("Malloc error\n");
    }
}


/*---------------------------------------------------------------------------*/
/* Set the card to a known base mode before each test                        */
/*---------------------------------------------------------------------------*/

void init( char *str )
{
    Initialize_graphics();
    Initialize_video( VIDEO_MODE );
    W_vector_mask = ( CONDITION_ERROR | CONDITION_RAISE_INTERRUPT );
    Set_interrupt_mode( ( int )GCC_VECT, ( int )GCC_LEVEL, W_vector_mask );

    Draw_grid( 0x10 );

    Printf( "\n\n%s\n", str );
    Key_wait();
}


/*---------------------------------------------------------------------------*/
/* Print a grid on the screen                                                */
/*---------------------------------------------------------------------------*/

void Draw_grid( int step )
{
    int i;
/*MBARI
    for( i = 0 ; i <= RES_X ; i += step )
    {
        Draw_line( i, 0, i, RES_Y );
    }

    for( i = 0 ; i <= RES_Y ; i += step )
    {
        Draw_line( 0, i, RES_X, i );
    }
ENDMBARI*/
}


/*---------------------------------------------------------------------------*/

int strlen( char *str )
{
    int len = 0;

    while( *str++ )
    {
        len++;
    }
    return( len );
}

/*---------------------------------------------------------------------------*/
