/*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_environ( void );
void copy_env( environment_t *senv, environment_t *denv );
void print_env( environment_t *env );
void show_env( environment_t *env );
/*-----------------------------------------------------------------------*/


void test_environ( void )
{
    environment_t *gcc_env;
    environment_t env;
    cursor_def_t *gcc_curs_def;
    uint32       *gcc_bitmap1;

    init( "Environment test" );
    
    gcc_env = ( environment_t * )Gcc_malloc( sizeof( environment_t ), 0 );
    malloc_check( gcc_env );

    gcc_curs_def = ( cursor_def_t * )Gcc_malloc( sizeof( cursor_def_t ), 0 );
    malloc_check( gcc_curs_def );

    gcc_bitmap1 = ( uint32 * )Gcc_malloc( 8, 0 );
    malloc_check( gcc_bitmap1 );

    show_env( gcc_env );
    copy_env( gcc_env, &env );
    
    Printf("setting cliprect to 0x12, 0x34, 0x56, 0x78\n");
    Set_clip_rectangle( 0x12, 0x34, 0x56, 0x78 );
    show_env( gcc_env );
    Set_clip_rectangle( 0x0, 0x0, RES_X, RES_Y );

    Printf("setting clipmode to on \n");
    Set_clipping_mode( ON );
    show_env( gcc_env );
    Set_clipping_mode( OFF );

    Printf("setting foreground colour to 0x9a \n");
    Set_foreground_colour( 0x9A );
    show_env( gcc_env );
    Set_foreground_colour( 0x1 );

    Printf("setting background colour to 0xbc \n");
    Set_background_colour( 0xBC );
    show_env( gcc_env );
    Set_background_colour( 0 );

    Printf("setting plane mask to 0x12\n");
    Set_plane_mask( 0x12 );
    show_env( gcc_env );
    Set_plane_mask( 0 );

    Printf("setting transparency to OPAQUE \n");
    Set_transparency_mode( OPAQUE );
    show_env( gcc_env );
    Set_transparency_mode( TRANSPARENT );

    Printf("setting ppop to 0x13 \n");
    Set_pixel_processing_operation( 0x13 );
    show_env( gcc_env );
    Set_pixel_processing_operation( 0 );

    Printf("setting line style to 0x12345678\n");
    Set_line_style( 0x12345678 );
    show_env( gcc_env );
    Set_line_style( 0xFFFFFFFF );

    Printf("setting line width to 0x123\n");
    Set_line_width( 0x123 );
    show_env( gcc_env );
    Set_line_width( 1 );

    Printf("setting keying mode on\n");
    Set_keying_mode( ON );
    show_env( gcc_env );
    Set_keying_mode( OFF );

    Printf("setting text font to 0x14 \n");
    Set_text_font( 0x14 );
    show_env( gcc_env );
    Set_text_font( 0 );

    Printf("setting text spacing to 0x56 \n");
    Set_text_spacing( 0x56 );
    show_env( gcc_env );
    Set_text_spacing( 0 );

    Printf("setting marker type to 0x4 \n");
    Set_marker_type( 0x4 );
    show_env( gcc_env );
    Set_marker_type( 0 );

    Printf("setting marker size to 0x23 \n");
    Set_marker_size( 0x23 );
    show_env( gcc_env );
    Set_marker_size( 0 );

    Printf("setting cursor mode on \n");
    Set_cursor_mode( ON );
    show_env( gcc_env );
    Set_cursor_mode( OFF );

    gcc_curs_def->bitmap1.colour    = 3;
    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 );

    Set_cursor_mode( ON );

    Printf("setting cursor type to 1\n");
    Define_cursor( 1, gcc_curs_def );
    show_env( gcc_env );
    Define_cursor( 0, ( cursor_def_t * )( 0 ));

    Printf("setting rubbermode to on box\n");
    Set_rubberband_mode( ON , RUBBER_BOX );
    show_env( gcc_env );
    Set_rubberband_mode( OFF , RUBBER_BOX );

    Printf("setting scl/ofst to *2x, *3y, offsx 4 offsy 5, tx 6 ty 7\n");
    Set_scale_and_offset( 0x00020000L, 0x00030000L, 0x04, 0x05, 0x06, 0x07 );
    show_env( gcc_env );
    Set_scale_and_offset( 0x00010000L, 0x00010000L, 0x0, 0x0, 0x0, 0x0 );

    Printf("setting screen offset to 0x98, 0x76\n");
    Set_screen_offset( 0x98, 0x76 );
    show_env( gcc_env );

}
    

void show_env( environment_t *env )
{
    Get_environment( env );
    Gcc_sync();
    print_env( env );
    Key_wait();
}

void copy_env( environment_t *senv, environment_t *denv )
{
    denv->clip_rect[0].x    = senv->clip_rect[0].x;
    denv->clip_rect[0].y    = senv->clip_rect[0].y;
    denv->clip_rect[1].x    = senv->clip_rect[1].x;
    denv->clip_rect[1].y    = senv->clip_rect[1].y;
    denv->clip_mode         = senv->clip_mode;
    denv->foreground_colour = senv->foreground_colour;
    denv->background_colour = senv->background_colour;
    denv->plane_mask        = senv->plane_mask;
    denv->transparency_mode = senv->transparency_mode;
    denv->ppop              = senv->ppop;
    denv->line_style        = senv->line_style;
    denv->line_width        = senv->line_width;
    denv->keying_mode       = senv->keying_mode;
    denv->text_font         = senv->text_font;
    denv->text_spacing      = senv->text_spacing;
    denv->marker_type       = senv->marker_type;
    denv->marker_size       = senv->marker_size;
    denv->cursor_mode       = senv->cursor_mode;
    denv->cursor_type       = senv->cursor_type;
    denv->rubber_mode       = senv->rubber_mode;
    denv->rubber_type       = senv->rubber_type;
    denv->scale_x           = senv->scale_x;
    denv->scale_y           = senv->scale_y;
    denv->scale_point.x     = senv->scale_point.x;
    denv->scale_point.y     = senv->scale_point.y;
    denv->offset.x          = senv->offset.x;
    denv->offset.y          = senv->offset.y;
    denv->screen_offset.x   = senv->screen_offset.x;
    denv->screen_offset.y   = senv->screen_offset.y;
}
    
void print_env( environment_t *env )
{
    Printf("clip_rect[0].x    0x%08x  ", env->clip_rect[0].x    );
    Printf("clip_rect[0].y    0x%08x\n", env->clip_rect[0].y    );
    Printf("clip_rect[1].x    0x%08x  ", env->clip_rect[1].x    );
    Printf("clip_rect[1].y    0x%08x\n", env->clip_rect[1].y    );
    Printf("clip_mode         0x%08x\n", env->clip_mode         );
    Printf("foreground_colour 0x%08x  ", env->foreground_colour );
    Printf("background_colour 0x%08x\n", env->background_colour );
    Printf("plane_mask        0x%08x  ", env->plane_mask        );
    Printf("transparency_mode 0x%08x\n", env->transparency_mode );
    Printf("ppop              0x%08x  ", env->ppop              );
    Printf("line_style        0x%08x\n", env->line_style        );
    Printf("line_width        0x%08x  ", env->line_width        );
    Printf("keying_mode       0x%08x\n", env->keying_mode       );
    Printf("text_font         0x%08x  ", env->text_font         );
    Printf("text_spacing      0x%08x\n", env->text_spacing      );
    Printf("marker_type       0x%08x  ", env->marker_type       );
    Printf("marker_size       0x%08x\n", env->marker_size       );
    Printf("cursor_mode       0x%08x  ", env->cursor_mode       );
    Printf("cursor_type       0x%08x\n", env->cursor_type       );
    Printf("rubber_mode       0x%08x  ", env->rubber_mode       );
    Printf("rubber_type       0x%08x\n", env->rubber_type       );
    Printf("scale_x           0x%08x  ", env->scale_x           );
    Printf("scale_y           0x%08x\n", env->scale_y           );
    Printf("scale_point.x     0x%08x  ", env->scale_point.x     );
    Printf("scale_point.y     0x%08x\n", env->scale_point.y     );
    Printf("offset.x          0x%08x  ", env->offset.x          );
    Printf("offset.y          0x%08x\n", env->offset.y          );
    Printf("screen_offset.x   0x%08x  ", env->screen_offset.x   );
    Printf("screen_offset.y   0x%08x\n", env->screen_offset.y   );
}
    
