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