Search
lxdream.org :: lxdream/test/testrend.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/testrend.c
changeset 307:a357a469f5ff
prev216:657ce4d3edd9
next346:9b495cc4db65
author nkeynes
date Sun Jan 21 05:24:27 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Add texture input data block
view annotate diff log raw
     1 /**
     2  * $Id: testrend.c,v 1.3 2007-01-21 05:24:27 nkeynes Exp $
     3  * 
     4  * Renderer test cases
     5  *
     6  * Copyright (c) 2006 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    18 #include <stdio.h>
    19 #include "testdata.h"
    20 #include "pvr.h"
    21 #include "lib.h"
    22 #include "asic.h"
    24 #define OBJ_START 0x00010000
    25 #define OBJ_LENGTH 0x00010000
    26 #define TILE_START 0x00060000
    27 #define TILE_LENGTH 0x00010000
    28 #define TILEMAP_ADDR 0x050B2C8
    29 #define RENDER_ADDR 0x00600000
    31 struct ta_config default_ta_config = { 0x00111111, GRID_SIZE(640,480), OBJ_START,
    32 				       OBJ_START+OBJ_LENGTH, TILE_START+TILE_LENGTH,
    33 				       TILE_START, TILE_START+TILE_LENGTH };
    35 struct render_config default_render_config = { OBJ_START, TILEMAP_ADDR, RENDER_ADDR, 640, 480, 
    36 					       0x00000009, 0.2, 1.0 };
    38 int test_render( test_data_t test_case )
    39 {
    40     int i;
    42     /* Check input */
    43     test_data_block_t input = get_test_data(test_case, "input");
    44     test_data_block_t event = get_test_data(test_case, "event");
    45     test_data_block_t backplane = get_test_data(test_case, "backplane");
    46     if( input == NULL ) {
    47 	fprintf( stderr, "Skipping test '%s' - no input\n", test_case->test_name );
    48 	return -1;
    49     }
    50     if( event == NULL ) {
    51 	fprintf( stderr, "Skipping test '%s' - no event list\n", test_case->test_name );
    52     }
    54     test_data_block_t tex = get_test_data(test_case, "textures");
    55     if( tex != NULL ) {
    56 	uint32_t addr = *(uint32_t *)tex->data;
    57 	memcpy( (char *)(0xA5000000 + addr), tex->data+4, tex->length-4 );
    58     }
    60     test_data_block_t config_data = get_test_data( test_case, "config" );
    61     struct ta_config *config = &default_ta_config;
    62     if( config_data != NULL ) {
    63 	if( config_data->length != sizeof(struct ta_config) ) {
    64 	    fprintf( stderr, "Invalid config data length %d - aborting test %s\n",
    65 		     config_data->length, test_case->test_name );
    66 	    return -1;
    67 	}
    68 	config = (struct ta_config *)config_data->data;
    69     }
    71     /* Send TA data */
    72     asic_clear();
    73     pvr_init();
    74     ta_init(config);
    75     default_render_config.polybuf = config->obj_start & 0x00F00000;
    76     if( pvr_dma_write( 0x10000000, input->data, input->length, 0 ) == -1 ) {
    77 	return -1;
    78     }
    80     /* Wait for events */
    81     for( i=0; i<event->length; i++ ) {
    82 	if( asic_wait( event->data[i] ) == -1 ) {
    83 	    fprintf( stderr, "Test %s: failed (Timeout waiting for event %d)\n",
    84 		     test_case->test_name, event->data[i] );
    85 	    asic_dump( stderr );
    86 	    return -1;
    87 	}
    88     }
    90     /* Write backplane (if any) */
    91     if( backplane != NULL ) {
    92 	uint32_t bgplane = pvr_get_objbuf_posn();
    93 	memcpy( (char *)(PVR_VRAM_BASE + bgplane), backplane->data, backplane->length );
    94 	bgplane -= default_render_config.polybuf;
    95 	render_set_backplane( (bgplane << 1) | 0x01000000 );
    96     } else {
    97 	render_set_backplane( 0 );
    98     }
    99     /* Setup the tilemap */
   100     pvr_build_tilemap1( TILEMAP_ADDR, config, 0x20000000 );
   101     render_start( &default_render_config );
   102     if( asic_wait( EVENT_PVR_RENDER_DONE ) == -1 ) {
   103 	fprintf( stderr, "Test %s: failed (timeout waiting for render)\n",
   104 		 test_case->test_name );
   105 	asic_dump( stderr );
   106 	return -1;
   107     }
   108     asic_wait( EVENT_RETRACE );
   109     display_render( &default_render_config );
   110     return 0;
   112 }
   114 int main( int argc, char *argv[] ) 
   115 {
   116     int test_cases = 0;
   117     int test_failures = 0;
   118     test_data_t test_data = load_test_dataset(stdin);
   119     test_data_t test_case = test_data;
   121     asic_mask_all();
   122     pvr_init();
   124     while( test_case != NULL ) {
   125 	test_cases++;
   126 	int result = test_render(test_case);
   127 	if( result != 0 ) {
   128 	    test_failures++;
   129 	}
   130 	test_case = test_case->next;
   131     }
   132     free_test_dataset(test_data);
   133     if( test_failures != 0 ) {
   134 	fprintf( stderr, "%d/%d test failures!\n", test_failures, test_cases );
   135 	return 1;
   136     } else {
   137 	fprintf( stderr, "%d tests OK\n", test_cases );
   138 	return 0;
   139     }
   140 }
.