Search
lxdream.org :: lxdream/test/pvr.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/pvr.c
changeset 213:da6b1904f67b
prev190:f7653df5e832
next306:818c11570593
author nkeynes
date Fri Aug 18 09:33:19 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Initial rendering tests (no support for result comparison yet)
file annotate diff log raw
1.1 --- a/test/pvr.c Wed Aug 02 04:13:15 2006 +0000
1.2 +++ b/test/pvr.c Fri Aug 18 09:33:19 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr.c,v 1.2 2006-08-02 04:13:15 nkeynes Exp $
1.6 + * $Id: pvr.c,v 1.3 2006-08-18 09:33:19 nkeynes Exp $
1.7 *
1.8 * PVR support code
1.9 *
1.10 @@ -30,8 +30,26 @@
1.11 #define TA_OBJPOSN (PVR_BASE+0x138)
1.12 #define TA_SIZE (PVR_BASE+0x13C)
1.13 #define TA_TILECFG (PVR_BASE+0x140)
1.14 +#define TA_REINIT (PVR_BASE+0x160)
1.15 #define TA_PLISTSTART (PVR_BASE+0x164)
1.16
1.17 +#define RENDER_START (PVR_BASE+0x014)
1.18 +#define RENDER_POLYBASE (PVR_BASE+0x020)
1.19 +#define RENDER_TILEBASE (PVR_BASE+0x02C)
1.20 +#define RENDER_MODE (PVR_BASE+0x048)
1.21 +#define RENDER_SIZE (PVR_BASE+0x04C)
1.22 +#define RENDER_ADDR1 (PVR_BASE+0x060)
1.23 +#define RENDER_ADDR2 (PVR_BASE+0x064)
1.24 +#define RENDER_HCLIP (PVR_BASE+0x068)
1.25 +#define RENDER_VCLIP (PVR_BASE+0x06C)
1.26 +#define RENDER_NEARCLIP (PVR_BASE+0x078)
1.27 +#define RENDER_FARCLIP (PVR_BASE+0x088)
1.28 +#define RENDER_BGPLANE (PVR_BASE+0x08C)
1.29 +
1.30 +#define DISPLAY_MODE (PVR_BASE+0x044)
1.31 +#define DISPLAY_ADDR1 (PVR_BASE+0x050)
1.32 +#define DISPLAY_ADDR2 (PVR_BASE+0x054)
1.33 +#define DISPLAY_SIZE (PVR_BASE+0x05C
1.34
1.35 void ta_dump_regs( FILE *f )
1.36 {
1.37 @@ -59,11 +77,21 @@
1.38 long_write( TA_INIT, 0x80000000 );
1.39 }
1.40
1.41 +void ta_reinit( )
1.42 +{
1.43 + long_write( TA_REINIT, 0x80000000 );
1.44 +}
1.45 +
1.46 int pvr_get_objbuf_size( )
1.47 {
1.48 return long_read( TA_OBJPOSN ) - long_read( TA_OBJSTART );
1.49 }
1.50
1.51 +int pvr_get_objbuf_posn( )
1.52 +{
1.53 + return long_read( TA_OBJPOSN );
1.54 +}
1.55 +
1.56 int pvr_get_plist_posn( )
1.57 {
1.58 unsigned int addr = long_read( TA_TILEPOSN ) << 2;
1.59 @@ -108,6 +136,138 @@
1.60 fwrite_dump( f, buf, length );
1.61 }
1.62
1.63 +static int ta_tile_sizes[4] = { 0, 32, 64, 128 };
1.64 +#define TILE_SIZE(cfg, tile) ta_tile_sizes[((((cfg->ta_cfg) >> (4*tile))&0x03))]
1.65 +#define TILE_ENABLED(cfg, tile) ((((cfg->ta_cfg) >> (4*tile))&0x03) != 0)
1.66 +void pvr_compute_tilematrix_addr( int *tile_ptrs, struct ta_config *config ) {
1.67 + int tile_sizes[5], i;
1.68 + int hsegs = (config->grid_size & 0xFFFF)+1;
1.69 + int vsegs = (config->grid_size >> 16) + 1;
1.70 + for( i=0; i<5; i++ ) {
1.71 + tile_sizes[i] = TILE_SIZE(config,i);
1.72 + }
1.73 + tile_ptrs[0] = config->tile_start;
1.74 + tile_ptrs[1] = tile_ptrs[0] + (hsegs*vsegs*tile_sizes[0]);
1.75 + tile_ptrs[2] = tile_ptrs[1] + (hsegs*vsegs*tile_sizes[1]);
1.76 + tile_ptrs[3] = tile_ptrs[2] + (hsegs*vsegs*tile_sizes[2]);
1.77 + tile_ptrs[4] = tile_ptrs[3] + (hsegs*vsegs*tile_sizes[3]);
1.78 +}
1.79 +
1.80 +static uint32_t *pvr_compute_tile_ptrs( uint32_t *target, struct ta_config *config, int x, int y )
1.81 +{
1.82 + int i;
1.83 + int cfg = config->ta_cfg;
1.84 + int hsegs = (config->grid_size & 0xFFFF)+1;
1.85 + int vsegs = (config->grid_size >> 16) + 1;
1.86 + int tilematrix = config->tile_start;
1.87 + for( i=0; i<5; i++ ) {
1.88 + if( cfg & 0x03 ) {
1.89 + int tile_size = ta_tile_sizes[cfg&0x03];
1.90 + *target++ = tilematrix + (((y*hsegs)+x)*tile_size);
1.91 + tilematrix += hsegs*vsegs*tile_size;
1.92 + } else {
1.93 + *target++ = 0x80000000;
1.94 + }
1.95 + cfg = cfg >> 4;
1.96 + }
1.97 + return target;
1.98 +}
1.99 +
1.100 +void pvr_build_tilemap1( uint32_t addr, struct ta_config *config, uint32_t control_word )
1.101 +{
1.102 + uint32_t *dest = (uint32_t *)(PVR_VRAM_BASE+addr);
1.103 + int w = (config->grid_size & 0x0000FFFF) + 1;
1.104 + int h = (config->grid_size >> 16) + 1;
1.105 +
1.106 + int x,y;
1.107 + memset( (char *)(dest-18), 0, 18*4 );
1.108 + *dest++ = 0x10000000;
1.109 + *dest++ = 0x80000000;
1.110 + *dest++ = 0x80000000;
1.111 + *dest++ = 0x80000000;
1.112 + *dest++ = 0x80000000;
1.113 + *dest++ = 0x80000000;
1.114 + for( x=0; x<w; x++ ) {
1.115 + for( y=0; y<h; y++ ) {
1.116 + *dest++ = control_word | (y << 8) | (x << 2);
1.117 + dest = pvr_compute_tile_ptrs(dest, config, x, y);
1.118 + }
1.119 + }
1.120 + dest[-6] |= 0x80000000; /* End-of-render */
1.121 +}
1.122 +
1.123 +void pvr_build_tilemap2( uint32_t addr, struct ta_config *config, uint32_t control_word )
1.124 +{
1.125 + uint32_t *dest = (uint32_t *)(PVR_VRAM_BASE+addr);
1.126 + int w = (config->grid_size & 0x0000FFFF) + 1;
1.127 + int h = (config->grid_size >> 16) + 1;
1.128 +
1.129 + int x,y;
1.130 + *dest++ = 0x10000000;
1.131 + *dest++ = 0x80000000;
1.132 + *dest++ = 0x80000000;
1.133 + *dest++ = 0x80000000;
1.134 + *dest++ = 0x80000000;
1.135 + *dest++ = 0x80000000;
1.136 + for( x=0; x<w; x++ ) {
1.137 + for( y=0; y<h; y++ ) {
1.138 + *dest++ = 0x40000000;
1.139 + *dest++ = 0x80000000;
1.140 + *dest++ = 0x80000000;
1.141 + *dest++ = 0x80000000;
1.142 + *dest++ = 0x80000000;
1.143 + *dest++ = 0x80000000;
1.144 + *dest++ = control_word | (y << 8) | (x << 2);
1.145 + dest = pvr_compute_tile_ptrs(dest, config, x, y);
1.146 + }
1.147 + }
1.148 + dest[-6] |= 0x80000000; /* End-of-render */
1.149 +}
1.150 +
1.151 +void render_set_backplane( uint32_t mode )
1.152 +{
1.153 + long_write( RENDER_BGPLANE, mode );
1.154 +}
1.155 +
1.156 +int get_line_size( struct render_config *config )
1.157 +{
1.158 + int modulo = config->width;
1.159 + switch( config->mode & 0x07 ) {
1.160 + case 4:
1.161 + modulo *= 3; /* ??? */
1.162 + break;
1.163 + case 5:
1.164 + case 6:
1.165 + modulo *= 4;
1.166 + break;
1.167 + default:
1.168 + modulo *= 2;
1.169 + }
1.170 + return modulo;
1.171 +}
1.172 +
1.173 +void render_start( struct render_config *config )
1.174 +{
1.175 + int modulo = get_line_size( config );
1.176 + long_write( RENDER_POLYBASE, config->polybuf );
1.177 + long_write( RENDER_TILEBASE, config->tilemap );
1.178 + long_write( RENDER_ADDR1, config->render_addr );
1.179 + long_write( RENDER_SIZE, modulo >> 3 );
1.180 + long_write( RENDER_ADDR2, config->render_addr + modulo ); /* Not used? */
1.181 + long_write( RENDER_HCLIP, (config->width - 1) << 16 );
1.182 + long_write( RENDER_VCLIP, (config->height - 1) << 16 );
1.183 + long_write( RENDER_MODE, config->mode );
1.184 + float_write( RENDER_FARCLIP, config->farclip );
1.185 + float_write( RENDER_NEARCLIP, config->nearclip );
1.186 + long_write( RENDER_START, 0xFFFFFFFF );
1.187 +}
1.188 +
1.189 +void display_render( struct render_config *config )
1.190 +{
1.191 + long_write( DISPLAY_ADDR1, config->render_addr );
1.192 + long_write( DISPLAY_ADDR2, config->render_addr + get_line_size(config) );
1.193 +}
1.194 +
1.195 /************** Stolen from TATEST *************/
1.196
1.197 static unsigned int three_d_params[] = {
.