Search
lxdream.org :: lxdream/src/pvr2/tacore.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/tacore.c
changeset 193:31151fcc3cb7
prev189:615b70cfd729
next194:7fcecbcd5f01
author nkeynes
date Fri Aug 04 01:38:30 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Add more tile list limit tests
Implement tile list limits in the ta core.
Rename TA_TILEEND to TA_LISTEND
file annotate diff log raw
nkeynes@189
     1
/**
nkeynes@193
     2
 * $Id: tacore.c,v 1.2 2006-08-04 01:38:27 nkeynes Exp $
nkeynes@189
     3
 *
nkeynes@189
     4
 * PVR2 Tile Accelerator implementation
nkeynes@189
     5
 *
nkeynes@189
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@189
     7
 *
nkeynes@189
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@189
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@189
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@189
    11
 * (at your option) any later version.
nkeynes@189
    12
 *
nkeynes@189
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@189
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@189
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@189
    16
 * GNU General Public License for more details.
nkeynes@189
    17
 */
nkeynes@189
    18
#include "pvr2.h"
nkeynes@189
    19
#include "asic.h"
nkeynes@189
    20
nkeynes@189
    21
#define STATE_IDLE                 0
nkeynes@189
    22
#define STATE_IN_LIST              1
nkeynes@189
    23
#define STATE_EXPECT_POLY_BLOCK2   2
nkeynes@189
    24
#define STATE_EXPECT_VERTEX_BLOCK2 3
nkeynes@189
    25
#define STATE_ERROR                4
nkeynes@189
    26
#define STATE_EXPECT_END_VERTEX_BLOCK2 7
nkeynes@189
    27
nkeynes@189
    28
#define TA_CMD(i) ( (i) >> 29 )
nkeynes@189
    29
#define TA_CMD_END_LIST 0
nkeynes@189
    30
#define TA_CMD_CLIP 1
nkeynes@189
    31
#define TA_CMD_POLYGON_CONTEXT 4
nkeynes@189
    32
#define TA_CMD_SPRITE_CONTEXT 5
nkeynes@189
    33
#define TA_CMD_VERTEX 7
nkeynes@189
    34
nkeynes@189
    35
#define TA_LIST_NONE -1
nkeynes@189
    36
#define TA_LIST_OPAQUE 0
nkeynes@189
    37
#define TA_LIST_OPAQUE_MOD 1
nkeynes@189
    38
#define TA_LIST_TRANS 2
nkeynes@189
    39
#define TA_LIST_TRANS_MOD 3
nkeynes@189
    40
#define TA_LIST_PUNCH_OUT 4
nkeynes@189
    41
#define TA_IS_MODIFIER_LIST(list) (list == TA_LIST_OPAQUE_MOD || list == TA_LIST_TRANS_MOD)
nkeynes@189
    42
nkeynes@189
    43
#define TA_GROW_UP 0
nkeynes@189
    44
#define TA_GROW_DOWN 1
nkeynes@189
    45
nkeynes@189
    46
#define TA_VERTEX_NONE                        -1
nkeynes@189
    47
#define TA_VERTEX_PACKED                      0x00
nkeynes@189
    48
#define TA_VERTEX_TEX_PACKED                  0x08
nkeynes@189
    49
#define TA_VERTEX_TEX_SPEC_PACKED             0x0C
nkeynes@189
    50
#define TA_VERTEX_TEX_UV16_PACKED             0x09
nkeynes@189
    51
#define TA_VERTEX_TEX_UV16_SPEC_PACKED        0x0D
nkeynes@189
    52
#define TA_VERTEX_FLOAT                       0x10
nkeynes@189
    53
#define TA_VERTEX_TEX_FLOAT                   0x18
nkeynes@189
    54
#define TA_VERTEX_TEX_SPEC_FLOAT              0x1C
nkeynes@189
    55
#define TA_VERTEX_TEX_UV16_FLOAT              0x19
nkeynes@189
    56
#define TA_VERTEX_TEX_UV16_SPEC_FLOAT         0x1D
nkeynes@189
    57
#define TA_VERTEX_INTENSITY                   0x20
nkeynes@189
    58
#define TA_VERTEX_TEX_INTENSITY               0x28
nkeynes@189
    59
#define TA_VERTEX_TEX_SPEC_INTENSITY          0x2C
nkeynes@189
    60
#define TA_VERTEX_TEX_UV16_INTENSITY          0x29
nkeynes@189
    61
#define TA_VERTEX_TEX_UV16_SPEC_INTENSITY     0x2D
nkeynes@189
    62
#define TA_VERTEX_PACKED_MOD                  0x40
nkeynes@189
    63
#define TA_VERTEX_TEX_PACKED_MOD              0x48
nkeynes@189
    64
#define TA_VERTEX_TEX_SPEC_PACKED_MOD         0x4C
nkeynes@189
    65
#define TA_VERTEX_TEX_UV16_PACKED_MOD         0x49
nkeynes@189
    66
#define TA_VERTEX_TEX_UV16_SPEC_PACKED_MOD    0x4D
nkeynes@189
    67
#define TA_VERTEX_INTENSITY_MOD               0x60
nkeynes@189
    68
#define TA_VERTEX_TEX_INTENSITY_MOD           0x68
nkeynes@189
    69
#define TA_VERTEX_TEX_SPEC_INTENSITY_MOD      0x6C
nkeynes@189
    70
#define TA_VERTEX_TEX_UV16_INTENSITY_MOD      0x69
nkeynes@189
    71
#define TA_VERTEX_TEX_UV16_SPEC_INTENSITY_MOD 0x6D
nkeynes@189
    72
#define TA_VERTEX_SPRITE                      0x80
nkeynes@189
    73
#define TA_VERTEX_TEX_SPRITE                  0x88
nkeynes@189
    74
#define TA_VERTEX_MOD_VOLUME                  0x81
nkeynes@189
    75
nkeynes@189
    76
#define TA_IS_NORMAL_POLY() (ta_status.current_vertex_type < TA_VERTEX_SPRITE)
nkeynes@189
    77
nkeynes@189
    78
static int strip_lengths[4] = {3,4,6,8}; /* in vertexes */
nkeynes@189
    79
#define TA_POLYCMD_LISTTYPE(i) ( ((i) >> 24) & 0x0F )
nkeynes@189
    80
#define TA_POLYCMD_LENGTH(i)  strip_lengths[((i >> 18) & 0x03)]
nkeynes@189
    81
#define TA_POLYCMD_CLIP(i)  ((i>>16)&0x03)
nkeynes@189
    82
#define TA_POLYCMD_COLOURFMT(i)  (i & 0x00000030)
nkeynes@189
    83
#define TA_POLYCMD_COLOURFMT_ARGB32 0x00000000
nkeynes@189
    84
#define TA_POLYCMD_COLOURFMT_FLOAT 0x00000010
nkeynes@189
    85
#define TA_POLYCMD_COLOURFMT_INTENSITY 0x00000020
nkeynes@189
    86
#define TA_POLYCMD_COLOURFMT_LASTINT 0x00000030
nkeynes@189
    87
nkeynes@189
    88
#define TA_POLYCMD_MODIFIED 0x00000080
nkeynes@189
    89
#define TA_POLYCMD_FULLMOD  0x00000040
nkeynes@189
    90
#define TA_POLYCMD_TEXTURED 0x00000008
nkeynes@189
    91
#define TA_POLYCMD_SPECULAR 0x00000004
nkeynes@189
    92
#define TA_POLYCMD_SHADED 0x00000002
nkeynes@189
    93
#define TA_POLYCMD_UV16 0x00000001
nkeynes@189
    94
nkeynes@189
    95
#define TA_POLYCMD_IS_SPECULAR(i) ((i & 0x0000000C)==0x0000000C) /* Only applies to textured polys */
nkeynes@189
    96
#define TA_POLYCMD_IS_FULLMOD(i) ((i & 0x000000C0)==0x000000C0)
nkeynes@189
    97
nkeynes@189
    98
nkeynes@189
    99
#define TA_IS_END_VERTEX(i) (i & 0x10000000)
nkeynes@189
   100
nkeynes@189
   101
#define MIN3( x1, x2, x3 ) ( (x1)<(x2)? ((x1)<(x3)?(x1):(x3)) : ((x2)<(x3)?(x2):(x3)) )
nkeynes@189
   102
#define MAX3( x1, x2, x3 ) ( (x1)>(x2)? ((x1)>(x3)?(x1):(x3)) : ((x2)>(x3)?(x2):(x3)) )
nkeynes@189
   103
nkeynes@189
   104
#define TILESLOT( x, y ) (ta_status.current_tile_matrix + (ta_status.current_tile_size * (y * ta_status.width+ x) << 2))
nkeynes@189
   105
nkeynes@189
   106
extern char *video_base;
nkeynes@189
   107
#define PVRRAM(addr) (*(uint32_t *)(video_base + ((addr)&PVR2_RAM_MASK)))
nkeynes@189
   108
nkeynes@189
   109
struct pvr2_ta_vertex {
nkeynes@189
   110
    float x,y,z;
nkeynes@189
   111
    uint32_t detail[8]; /* 0-8 detail words */
nkeynes@189
   112
};
nkeynes@189
   113
nkeynes@189
   114
struct tile_bounds {
nkeynes@189
   115
    int x1, y1, x2, y2;
nkeynes@189
   116
};
nkeynes@189
   117
nkeynes@189
   118
struct pvr2_ta_status {
nkeynes@189
   119
    int state;
nkeynes@189
   120
    int width, height; /* Tile resolution, ie 20x15 */
nkeynes@189
   121
    int tilelist_dir; /* Growth direction of the tilelist, 0 = up, 1 = down */
nkeynes@189
   122
    uint32_t tilelist_size; /* Size of the tilelist segments */
nkeynes@193
   123
    uint32_t tilelist_start; /* Initial address of the tilelist */
nkeynes@189
   124
    int current_vertex_type;
nkeynes@193
   125
    gboolean accept_vertexes;
nkeynes@189
   126
    int vertex_count; /* index of last start-vertex seen, or -1 if no vertexes 
nkeynes@189
   127
			 * are present
nkeynes@189
   128
			 */
nkeynes@189
   129
    int max_vertex;     /* Maximum number of vertexes in the current polygon (3/4/6/8) */
nkeynes@189
   130
    int current_list_type;
nkeynes@189
   131
    uint32_t current_tile_matrix; /* Memory location of the first tile for the current list. */
nkeynes@189
   132
    uint32_t current_tile_size; /* Size of the tile matrix space  in 32-bit words (0/8/16/32)*/
nkeynes@189
   133
    uint32_t intensity1, intensity2;
nkeynes@189
   134
    /**
nkeynes@189
   135
     * Current working object
nkeynes@189
   136
     */
nkeynes@189
   137
    int poly_context_size;
nkeynes@189
   138
    int poly_vertex_size;
nkeynes@189
   139
    int poly_parity;
nkeynes@189
   140
    uint32_t poly_context[5];
nkeynes@189
   141
    uint32_t poly_pointer;
nkeynes@189
   142
    struct tile_bounds last_triangle_bounds;
nkeynes@189
   143
    struct pvr2_ta_vertex poly_vertex[8];
nkeynes@189
   144
    int debug_output;
nkeynes@189
   145
};
nkeynes@189
   146
nkeynes@189
   147
static struct pvr2_ta_status ta_status;
nkeynes@189
   148
nkeynes@189
   149
static int tilematrix_sizes[4] = {0,8,16,32};
nkeynes@189
   150
nkeynes@189
   151
/**
nkeynes@189
   152
 * Convenience union - ta data is either 32-bit integer or 32-bit float.
nkeynes@189
   153
 */
nkeynes@189
   154
union ta_data {
nkeynes@189
   155
    unsigned int i;
nkeynes@189
   156
    float f;
nkeynes@189
   157
};
nkeynes@189
   158
nkeynes@189
   159
nkeynes@189
   160
void pvr2_ta_reset() {
nkeynes@189
   161
    ta_status.state = STATE_ERROR; /* State not valid until initialized */
nkeynes@189
   162
    ta_status.debug_output = 0;
nkeynes@189
   163
}
nkeynes@189
   164
nkeynes@193
   165
void pvr2_ta_save_state( FILE *f )
nkeynes@193
   166
{
nkeynes@193
   167
    fwrite( &ta_status, sizeof(ta_status), 1, f );
nkeynes@193
   168
}
nkeynes@193
   169
nkeynes@193
   170
int pvr2_ta_load_state( FILE *f )
nkeynes@193
   171
{
nkeynes@193
   172
    if( fread( &ta_status, sizeof(ta_status), 1, f ) != 1 )
nkeynes@193
   173
	return 1;
nkeynes@193
   174
    return 0;
nkeynes@193
   175
}
nkeynes@193
   176
nkeynes@189
   177
void pvr2_ta_init() {
nkeynes@189
   178
    ta_status.state = STATE_IDLE;
nkeynes@189
   179
    ta_status.current_list_type = -1;
nkeynes@189
   180
    ta_status.current_vertex_type = -1;
nkeynes@189
   181
    ta_status.poly_parity = 0;
nkeynes@189
   182
    ta_status.vertex_count = 0;
nkeynes@189
   183
    ta_status.max_vertex = 3;
nkeynes@189
   184
    ta_status.last_triangle_bounds.x1 = -1;
nkeynes@193
   185
    ta_status.accept_vertexes = TRUE;
nkeynes@189
   186
    
nkeynes@189
   187
    uint32_t size = MMIO_READ( PVR2, TA_TILESIZE );
nkeynes@189
   188
    ta_status.width = (size & 0xFFFF) + 1;
nkeynes@189
   189
    ta_status.height = (size >> 16) + 1;
nkeynes@189
   190
    uint32_t control = MMIO_READ( PVR2, TA_TILECFG );
nkeynes@189
   191
    ta_status.tilelist_dir = (control >> 20) & 0x01;
nkeynes@189
   192
    ta_status.tilelist_size = tilematrix_sizes[ (control & 0x03) ];
nkeynes@189
   193
    MMIO_WRITE( PVR2, TA_POLYPOS, MMIO_READ( PVR2, TA_POLYBASE ) );
nkeynes@189
   194
    uint32_t plistpos = MMIO_READ( PVR2, TA_LISTBASE ) >> 2;
nkeynes@189
   195
    if( ta_status.tilelist_dir == TA_GROW_DOWN ) {
nkeynes@189
   196
	plistpos -= ta_status.tilelist_size;
nkeynes@189
   197
    }
nkeynes@189
   198
    MMIO_WRITE( PVR2, TA_LISTPOS, plistpos );
nkeynes@193
   199
    ta_status.tilelist_start = plistpos;
nkeynes@189
   200
}
nkeynes@189
   201
nkeynes@189
   202
static uint32_t parse_float_colour( float a, float r, float g, float b ) {
nkeynes@189
   203
    return
nkeynes@189
   204
    	(((unsigned int)((256 * CLAMP(a,0.0,1.0))-1))<<24) |
nkeynes@189
   205
    	(((unsigned int)((256 * CLAMP(r,0.0,1.0))-1))<<16) |
nkeynes@189
   206
    	(((unsigned int)((256 * CLAMP(g,0.0,1.0))-1))<<8) |
nkeynes@189
   207
    	(((unsigned int)((256 * CLAMP(b,0.0,1.0))-1)));
nkeynes@189
   208
}
nkeynes@189
   209
nkeynes@189
   210
static uint32_t parse_intensity_colour( uint32_t base, float intensity )
nkeynes@189
   211
{
nkeynes@189
   212
    unsigned int i = (unsigned int)(256 * CLAMP(intensity, 0.0,1.0));
nkeynes@189
   213
    
nkeynes@189
   214
    return
nkeynes@189
   215
	(((((base & 0xFF) * i) & 0xFF00) |
nkeynes@189
   216
	  (((base & 0xFF00) * i) & 0xFF0000) |
nkeynes@189
   217
	  (((base & 0xFF0000) * i) & 0xFF000000)) >> 8) |
nkeynes@189
   218
	base & 0xFF000000;
nkeynes@189
   219
}
nkeynes@189
   220
   	
nkeynes@189
   221
/**
nkeynes@189
   222
 * Initialize the specified TA list.
nkeynes@189
   223
 */
nkeynes@189
   224
static void ta_init_list( unsigned int listtype ) {
nkeynes@189
   225
    int config = MMIO_READ( PVR2, TA_TILECFG );
nkeynes@189
   226
    int tile_matrix = MMIO_READ( PVR2, TA_TILEBASE );
nkeynes@193
   227
    int list_end = MMIO_READ( PVR2, TA_LISTEND );
nkeynes@193
   228
nkeynes@193
   229
    ta_status.current_tile_matrix = tile_matrix;
nkeynes@193
   230
nkeynes@193
   231
    /* If the list grows down, the end must be < tile matrix start. 
nkeynes@193
   232
     * If it grows up, the end must be > tile matrix start.
nkeynes@193
   233
     * Don't ask me why, it just does...
nkeynes@193
   234
     */
nkeynes@193
   235
    if( ((ta_status.tilelist_dir == TA_GROW_DOWN && list_end <= tile_matrix) ||
nkeynes@193
   236
	 (ta_status.tilelist_dir == TA_GROW_UP && list_end >= tile_matrix )) &&
nkeynes@193
   237
	listtype <= TA_LIST_PUNCH_OUT ) {
nkeynes@189
   238
	int i;
nkeynes@189
   239
	uint32_t *p;
nkeynes@189
   240
	for( i=0; i < listtype; i++ ) {
nkeynes@189
   241
	    int size = tilematrix_sizes[(config & 0x03)] << 2;
nkeynes@193
   242
	    ta_status.current_tile_matrix += ta_status.width * ta_status.height * size;
nkeynes@189
   243
	    config >>= 4;
nkeynes@189
   244
	}
nkeynes@189
   245
	ta_status.current_tile_size = tilematrix_sizes[(config & 0x03)];
nkeynes@189
   246
nkeynes@189
   247
	/* Initialize each tile to 0xF0000000 */
nkeynes@189
   248
	if( ta_status.current_tile_size != 0 ) {
nkeynes@193
   249
	    p = (uint32_t *)(video_base + ta_status.current_tile_matrix);
nkeynes@189
   250
	    for( i=0; i< ta_status.width * ta_status.height; i++ ) {
nkeynes@189
   251
		*p = 0xF0000000;
nkeynes@189
   252
		p += ta_status.current_tile_size;
nkeynes@189
   253
	    }
nkeynes@189
   254
	}
nkeynes@193
   255
    } else {
nkeynes@193
   256
	ta_status.current_tile_size = 0;
nkeynes@189
   257
    }
nkeynes@193
   258
nkeynes@193
   259
    if( tile_matrix == list_end ) {
nkeynes@193
   260
	ta_status.current_tile_size = 0;
nkeynes@193
   261
    }
nkeynes@193
   262
nkeynes@189
   263
    ta_status.state = STATE_IN_LIST;
nkeynes@189
   264
    ta_status.current_list_type = listtype;
nkeynes@189
   265
    ta_status.last_triangle_bounds.x1 = -1;
nkeynes@189
   266
}
nkeynes@189
   267
nkeynes@189
   268
static int list_events[5] = {EVENT_PVR_OPAQUE_DONE, EVENT_PVR_OPAQUEMOD_DONE, 
nkeynes@189
   269
			     EVENT_PVR_TRANS_DONE, EVENT_PVR_TRANSMOD_DONE,
nkeynes@189
   270
			     EVENT_PVR_PUNCHOUT_DONE };
nkeynes@189
   271
nkeynes@189
   272
static void ta_end_list() {
nkeynes@189
   273
    if( ta_status.current_list_type != TA_LIST_NONE ) {
nkeynes@189
   274
	asic_event( list_events[ta_status.current_list_type] );
nkeynes@189
   275
	ta_status.current_list_type = TA_LIST_NONE;
nkeynes@189
   276
	ta_status.current_vertex_type = -1;
nkeynes@189
   277
	ta_status.state = STATE_IDLE;
nkeynes@189
   278
    }
nkeynes@189
   279
}
nkeynes@189
   280
nkeynes@189
   281
/**
nkeynes@189
   282
 * Write data out to the polygon buffer.
nkeynes@189
   283
 * If the end-of-buffer is reached, asserts EVENT_PVR_PRIM_ALLOC_FAIL
nkeynes@189
   284
 * @param data to be written
nkeynes@189
   285
 * @param length Number of 32-bit words to write.
nkeynes@189
   286
 * @return number of words actually written
nkeynes@189
   287
 */
nkeynes@189
   288
static int ta_write_polygon_buffer( uint32_t *data, int length )
nkeynes@189
   289
{
nkeynes@189
   290
    int rv;
nkeynes@189
   291
    int posn = MMIO_READ( PVR2, TA_POLYPOS );
nkeynes@189
   292
    int end = MMIO_READ( PVR2, TA_POLYEND );
nkeynes@189
   293
    uint32_t *target = (uint32_t *)(video_base + posn);
nkeynes@189
   294
    for( rv=0; rv < length; rv++ ) {
nkeynes@189
   295
	if( posn == end ) {
nkeynes@189
   296
	    asic_event( EVENT_PVR_PRIM_ALLOC_FAIL );
nkeynes@189
   297
	    asic_event( EVENT_TA_ERROR );
nkeynes@189
   298
	    //	    ta_status.state = STATE_ERROR;
nkeynes@189
   299
	    break;
nkeynes@189
   300
	}
nkeynes@189
   301
	*target++ = *data++;
nkeynes@189
   302
	posn += 4;
nkeynes@189
   303
    }
nkeynes@189
   304
nkeynes@189
   305
    MMIO_WRITE( PVR2, TA_POLYPOS, posn );
nkeynes@189
   306
    return rv;
nkeynes@189
   307
}
nkeynes@189
   308
nkeynes@193
   309
#define TA_NO_ALLOC 0xFFFFFFFF
nkeynes@193
   310
nkeynes@189
   311
/**
nkeynes@193
   312
 * Allocate a new tile list block from the grow space and update the
nkeynes@193
   313
 * word at reference to be a link to the new block.
nkeynes@189
   314
 */
nkeynes@193
   315
static uint32_t ta_alloc_tilelist( uint32_t reference ) {
nkeynes@189
   316
    uint32_t posn = MMIO_READ( PVR2, TA_LISTPOS );
nkeynes@193
   317
    uint32_t limit = MMIO_READ( PVR2, TA_LISTEND ) >> 2;
nkeynes@189
   318
    uint32_t newposn;
nkeynes@193
   319
    uint32_t result;
nkeynes@189
   320
    if( ta_status.tilelist_dir == TA_GROW_DOWN ) {
nkeynes@189
   321
	newposn = posn - ta_status.tilelist_size;
nkeynes@193
   322
	if( posn == limit ) {
nkeynes@193
   323
	    PVRRAM(posn<<2) = 0xF0000000;
nkeynes@193
   324
	    PVRRAM(reference) = 0xE0000000 | (posn<<2);
nkeynes@193
   325
	    return TA_NO_ALLOC;
nkeynes@193
   326
	} else if( posn < limit ) {
nkeynes@193
   327
	    PVRRAM(reference) = 0xE0000000 | (posn<<2);
nkeynes@193
   328
	    return TA_NO_ALLOC;
nkeynes@193
   329
	} else if( newposn <= limit ) {
nkeynes@193
   330
	} else if( newposn <= (limit + ta_status.tilelist_size) ) {
nkeynes@193
   331
	    asic_event( EVENT_TA_ERROR );
nkeynes@193
   332
	    asic_event( EVENT_PVR_MATRIX_ALLOC_FAIL );
nkeynes@193
   333
	    MMIO_WRITE( PVR2, TA_LISTPOS, newposn );
nkeynes@193
   334
	} else {
nkeynes@193
   335
	    MMIO_WRITE( PVR2, TA_LISTPOS, newposn );
nkeynes@193
   336
	}
nkeynes@193
   337
	PVRRAM(reference) = 0xE0000000 | (posn<<2);
nkeynes@193
   338
	return posn << 2;
nkeynes@189
   339
    } else {
nkeynes@189
   340
	newposn = posn + ta_status.tilelist_size;
nkeynes@193
   341
	if( posn == limit ) {
nkeynes@193
   342
	    PVRRAM(posn<<2) = 0xF0000000;
nkeynes@193
   343
	    PVRRAM(reference) = 0xE0000000 | (posn<<2);
nkeynes@193
   344
	    return TA_NO_ALLOC;
nkeynes@193
   345
	} else if ( posn > limit ) {
nkeynes@193
   346
	    PVRRAM(reference) = 0xE0000000 | (posn<<2);
nkeynes@193
   347
	    return TA_NO_ALLOC;
nkeynes@193
   348
	} else if( newposn >= limit ) {
nkeynes@193
   349
	} else if( newposn >= (limit - ta_status.tilelist_size) ) {
nkeynes@193
   350
	    asic_event( EVENT_TA_ERROR );
nkeynes@193
   351
	    asic_event( EVENT_PVR_MATRIX_ALLOC_FAIL );
nkeynes@193
   352
	    MMIO_WRITE( PVR2, TA_LISTPOS, newposn );
nkeynes@193
   353
	} else {
nkeynes@193
   354
	    MMIO_WRITE( PVR2, TA_LISTPOS, newposn );
nkeynes@193
   355
	}	    
nkeynes@193
   356
	PVRRAM(reference) = 0xE0000000 | (posn<<2);
nkeynes@193
   357
	return posn << 2;
nkeynes@189
   358
    }
nkeynes@189
   359
}
nkeynes@189
   360
nkeynes@189
   361
/**
nkeynes@189
   362
 * Write a tile entry out to the matrix.
nkeynes@189
   363
 */
nkeynes@189
   364
static int ta_write_tile_entry( int x, int y, uint32_t tile_entry ) {
nkeynes@189
   365
    uint32_t tile = TILESLOT(x,y);
nkeynes@193
   366
    uint32_t tilestart = tile;
nkeynes@189
   367
    uint32_t value;
nkeynes@189
   368
    uint32_t lasttri = 0;
nkeynes@189
   369
    int i,l;
nkeynes@189
   370
nkeynes@189
   371
    if( (tile_entry & 0x80000000) && 
nkeynes@189
   372
	ta_status.last_triangle_bounds.x1 != -1 &&
nkeynes@189
   373
	ta_status.last_triangle_bounds.x1 <= x &&
nkeynes@189
   374
	ta_status.last_triangle_bounds.x2 >= x &&
nkeynes@189
   375
	ta_status.last_triangle_bounds.y1 <= y &&
nkeynes@189
   376
	ta_status.last_triangle_bounds.y2 >= y ) {
nkeynes@189
   377
	/* potential for triangle stacking */
nkeynes@189
   378
	lasttri = tile_entry & 0xE1E00000;
nkeynes@189
   379
    }
nkeynes@189
   380
    
nkeynes@189
   381
    
nkeynes@189
   382
    if( PVRRAM(tile) == 0xF0000000 ) {
nkeynes@189
   383
	PVRRAM(tile) = tile_entry;
nkeynes@189
   384
	PVRRAM(tile+4) = 0xF0000000;
nkeynes@189
   385
	return;
nkeynes@189
   386
    }
nkeynes@189
   387
nkeynes@189
   388
    while(1) {
nkeynes@189
   389
	value = PVRRAM(tile);
nkeynes@189
   390
	for( i=1; i<ta_status.current_tile_size; i++ ) {
nkeynes@189
   391
	    tile += 4;
nkeynes@189
   392
	    uint32_t nextval = PVRRAM(tile);
nkeynes@189
   393
	    if( nextval == 0xF0000000 ) {
nkeynes@189
   394
		if( lasttri != 0 && lasttri == (value&0xE1E00000) ) {
nkeynes@189
   395
		    int count = (value & 0x1E000000) + 0x02000000;
nkeynes@189
   396
		    if( count < 0x20000000 ) {
nkeynes@189
   397
			PVRRAM(tile-4) = (value & 0xE1FFFFFF) | count;
nkeynes@189
   398
			return;
nkeynes@189
   399
		    }
nkeynes@189
   400
		}
nkeynes@189
   401
		if( i < ta_status.current_tile_size-1 ) {
nkeynes@189
   402
		    PVRRAM(tile) = tile_entry;
nkeynes@189
   403
		    PVRRAM(tile+4) = 0xF0000000;
nkeynes@189
   404
		    return;
nkeynes@189
   405
		}
nkeynes@189
   406
	    }
nkeynes@189
   407
	    value = nextval;
nkeynes@189
   408
	}
nkeynes@189
   409
nkeynes@189
   410
	if( value == 0xF0000000 ) {
nkeynes@193
   411
	    tile = ta_alloc_tilelist(tile);
nkeynes@193
   412
	    if( tile != TA_NO_ALLOC ) {
nkeynes@193
   413
		PVRRAM(tile) = tile_entry;
nkeynes@193
   414
		PVRRAM(tile+4) = 0xF0000000;
nkeynes@193
   415
	    }
nkeynes@189
   416
	    return;
nkeynes@189
   417
	} else if( (value & 0xFF000000) == 0xE0000000 ) {
nkeynes@193
   418
	    value &= 0x00FFFFFF;
nkeynes@193
   419
	    if( value == tilestart )
nkeynes@193
   420
		return 0; /* Loop */
nkeynes@193
   421
	    tilestart = tile = value;
nkeynes@189
   422
	} else {
nkeynes@189
   423
	    /* This should never happen */
nkeynes@189
   424
	    return 0;
nkeynes@189
   425
	}
nkeynes@189
   426
    }
nkeynes@189
   427
}
nkeynes@189
   428
nkeynes@189
   429
/**
nkeynes@189
   430
 * Write a completed polygon out to the memory buffers 
nkeynes@189
   431
 * OPTIMIZEME: This is not terribly efficient at the moment.
nkeynes@189
   432
 */
nkeynes@189
   433
static void ta_commit_polygon( ) {
nkeynes@189
   434
    int i, x, y;
nkeynes@189
   435
    int tx[ta_status.vertex_count], ty[ta_status.vertex_count];
nkeynes@189
   436
    struct tile_bounds triangle_bound[ta_status.vertex_count - 2];
nkeynes@189
   437
    struct tile_bounds polygon_bound;
nkeynes@189
   438
    uint32_t poly_context[5];
nkeynes@189
   439
nkeynes@189
   440
    if( ta_status.vertex_count < 2 ) {
nkeynes@189
   441
	return; /* No polygons - ignore */
nkeynes@189
   442
    }
nkeynes@189
   443
    memcpy( poly_context, ta_status.poly_context, ta_status.poly_context_size * 4 );
nkeynes@189
   444
nkeynes@189
   445
    /* Compute the tile coordinates for each vertex (need to be careful with
nkeynes@189
   446
     * clamping here)
nkeynes@189
   447
     */
nkeynes@189
   448
    for( i=0; i<ta_status.vertex_count; i++ ) {
nkeynes@189
   449
	if( ta_status.poly_vertex[i].x < 0.0 ) {
nkeynes@189
   450
	    tx[i] = -1;
nkeynes@189
   451
	} else if( ta_status.poly_vertex[i].x > (float)INT_MAX ) {
nkeynes@189
   452
	    tx[i] = INT_MAX/32;
nkeynes@189
   453
	} else {
nkeynes@189
   454
	    tx[i] = (int)(ta_status.poly_vertex[i].x / 32.0);
nkeynes@189
   455
	}
nkeynes@189
   456
	if( ta_status.poly_vertex[i].y < 0.0 ) {
nkeynes@189
   457
	    ty[i] = -1;
nkeynes@189
   458
	} else if( ta_status.poly_vertex[i].y > (float)INT_MAX ) {
nkeynes@189
   459
	    ty[i] = INT_MAX/32;
nkeynes@189
   460
	} else {
nkeynes@189
   461
	    ty[i] = (int)(ta_status.poly_vertex[i].y / 32.0);
nkeynes@189
   462
	}
nkeynes@189
   463
	
nkeynes@189
   464
    }
nkeynes@189
   465
nkeynes@189
   466
    /* Compute bounding box for each triangle individually, as well
nkeynes@189
   467
     * as the overall polygon.
nkeynes@189
   468
     */
nkeynes@189
   469
nkeynes@189
   470
    for( i=0; i<ta_status.vertex_count-2; i++ ) {
nkeynes@189
   471
	triangle_bound[i].x1 = MIN3(tx[i],tx[i+1],tx[i+2]);
nkeynes@189
   472
	triangle_bound[i].x2 = MAX3(tx[i],tx[i+1],tx[i+2]);
nkeynes@189
   473
	triangle_bound[i].y1 = MIN3(ty[i],ty[i+1],ty[i+2]);
nkeynes@189
   474
	triangle_bound[i].y2 = MAX3(ty[i],ty[i+1],ty[i+2]);
nkeynes@189
   475
	if( i == 0 ) {
nkeynes@189
   476
	    polygon_bound.x1 = triangle_bound[0].x1;
nkeynes@189
   477
	    polygon_bound.y1 = triangle_bound[0].y1;
nkeynes@189
   478
	    polygon_bound.x2 = triangle_bound[0].x2;
nkeynes@189
   479
	    polygon_bound.y2 = triangle_bound[0].y2;
nkeynes@189
   480
	} else {
nkeynes@189
   481
	    polygon_bound.x1 = MIN(polygon_bound.x1, triangle_bound[i].x1);
nkeynes@189
   482
	    polygon_bound.x2 = MAX(polygon_bound.x2, triangle_bound[i].x2);
nkeynes@189
   483
	    polygon_bound.y1 = MIN(polygon_bound.y1, triangle_bound[i].y1);
nkeynes@189
   484
	    polygon_bound.y2 = MAX(polygon_bound.y2, triangle_bound[i].y2);
nkeynes@189
   485
	}
nkeynes@189
   486
    }
nkeynes@189
   487
nkeynes@189
   488
    /* If the polygon is actually entirely out of the frustum, clip it entirely */
nkeynes@189
   489
    if( polygon_bound.x2 < 0 || polygon_bound.x1 > ta_status.width ||
nkeynes@189
   490
	polygon_bound.y2 < 0 || polygon_bound.y1 > ta_status.height ) {
nkeynes@189
   491
	return;
nkeynes@189
   492
    }
nkeynes@189
   493
nkeynes@189
   494
    /* Clamp the polygon bounds to the frustum */
nkeynes@189
   495
    if( polygon_bound.x1 < 0 ) polygon_bound.x1 = 0;
nkeynes@189
   496
    if( polygon_bound.x2 >= ta_status.width ) polygon_bound.x2 = ta_status.width-1;
nkeynes@189
   497
    if( polygon_bound.y1 < 0 ) polygon_bound.y1 = 0;
nkeynes@189
   498
    if( polygon_bound.y2 >= ta_status.width ) polygon_bound.y2 = ta_status.height-1;
nkeynes@189
   499
nkeynes@189
   500
    /* Set the "single tile" flag if it's entirely contained in 1 tile */
nkeynes@189
   501
    if( polygon_bound.x1 == polygon_bound.x2 &&
nkeynes@189
   502
	polygon_bound.y1 == polygon_bound.y2 ) {
nkeynes@189
   503
	poly_context[0] |= 0x00200000;
nkeynes@189
   504
    }
nkeynes@189
   505
nkeynes@189
   506
    /* Ok, we're good to go - write out the polygon first */
nkeynes@189
   507
    uint32_t tile_entry = MMIO_READ( PVR2, TA_POLYPOS ) >> 2 | ta_status.poly_pointer;
nkeynes@189
   508
    
nkeynes@189
   509
    int status = ta_write_polygon_buffer( poly_context, ta_status.poly_context_size );
nkeynes@189
   510
    if( status == 0 ) {
nkeynes@189
   511
	/* No memory available - abort */
nkeynes@189
   512
	return;
nkeynes@189
   513
    } else {
nkeynes@189
   514
	for( i=0; i<ta_status.vertex_count && status != 0; i++ ) {
nkeynes@189
   515
	    status = ta_write_polygon_buffer( (uint32_t *)(&ta_status.poly_vertex[i]), 3 + ta_status.poly_vertex_size );
nkeynes@189
   516
	}
nkeynes@189
   517
    }
nkeynes@189
   518
nkeynes@193
   519
    if( ta_status.current_tile_size == 0 ) {
nkeynes@193
   520
	/* No memory for tile entry, so don't write anything */
nkeynes@193
   521
	return;
nkeynes@193
   522
    }
nkeynes@193
   523
nkeynes@189
   524
    /* And now the tile entries. Triangles are different from everything else */
nkeynes@189
   525
    if( ta_status.vertex_count == 3 ) {
nkeynes@189
   526
	tile_entry |= 0x80000000;
nkeynes@189
   527
	for( y=polygon_bound.y1; y<=polygon_bound.y2; y++ ) {
nkeynes@189
   528
	    for( x=polygon_bound.x1; x<=polygon_bound.x2; x++ ) {
nkeynes@189
   529
		ta_write_tile_entry( x,y,tile_entry );
nkeynes@189
   530
	    }
nkeynes@189
   531
	}
nkeynes@189
   532
	ta_status.last_triangle_bounds.x1 = polygon_bound.x1;
nkeynes@189
   533
	ta_status.last_triangle_bounds.y1 = polygon_bound.y1;
nkeynes@189
   534
	ta_status.last_triangle_bounds.x2 = polygon_bound.x2;
nkeynes@189
   535
	ta_status.last_triangle_bounds.y2 = polygon_bound.y2;
nkeynes@189
   536
    } else if( ta_status.current_vertex_type == TA_VERTEX_SPRITE ||
nkeynes@189
   537
	       ta_status.current_vertex_type == TA_VERTEX_TEX_SPRITE ) {
nkeynes@189
   538
	tile_entry |= 0xA0000000;
nkeynes@189
   539
	for( y=polygon_bound.y1; y<=polygon_bound.y2; y++ ) {
nkeynes@189
   540
	    for( x=polygon_bound.x1; x<=polygon_bound.x2; x++ ) {
nkeynes@189
   541
		ta_write_tile_entry( x,y,tile_entry );
nkeynes@189
   542
	    }
nkeynes@189
   543
	}
nkeynes@189
   544
	ta_status.last_triangle_bounds.x1 = polygon_bound.x1;
nkeynes@189
   545
	ta_status.last_triangle_bounds.y1 = polygon_bound.y1;
nkeynes@189
   546
	ta_status.last_triangle_bounds.x2 = polygon_bound.x2;
nkeynes@189
   547
	ta_status.last_triangle_bounds.y2 = polygon_bound.y2;
nkeynes@189
   548
    } else {
nkeynes@189
   549
	for( y=polygon_bound.y1; y<=polygon_bound.y2; y++ ) {
nkeynes@189
   550
	    for( x=polygon_bound.x1; x<=polygon_bound.x2; x++ ) {
nkeynes@189
   551
		uint32_t entry = tile_entry;
nkeynes@189
   552
		for( i=0; i<ta_status.vertex_count-2; i++ ) {
nkeynes@189
   553
		    if( triangle_bound[i].x1 <= x && triangle_bound[i].x2 >= x &&
nkeynes@189
   554
			triangle_bound[i].y1 <= y && triangle_bound[i].y2 >= y ) {
nkeynes@189
   555
			entry |= (0x40000000>>i);
nkeynes@189
   556
		    }
nkeynes@189
   557
		}
nkeynes@189
   558
		ta_write_tile_entry( x, y, entry );
nkeynes@189
   559
	    }
nkeynes@189
   560
	}
nkeynes@189
   561
	ta_status.last_triangle_bounds.x1 = -1;
nkeynes@189
   562
    }
nkeynes@189
   563
}
nkeynes@189
   564
nkeynes@189
   565
/**
nkeynes@189
   566
 * Variant of ta_split_polygon called when vertex_count == max_vertex, but 
nkeynes@189
   567
 * the client hasn't sent the LAST VERTEX flag. Commit the poly as normal
nkeynes@189
   568
 * first, then start a new poly with the first 2 vertexes taken from the 
nkeynes@189
   569
 * current one.
nkeynes@189
   570
 */
nkeynes@189
   571
static void ta_split_polygon() {
nkeynes@189
   572
    ta_commit_polygon();
nkeynes@189
   573
    if( TA_IS_NORMAL_POLY() ) { 
nkeynes@189
   574
	/* This only applies to ordinary polys - Sprites + modifier lists are
nkeynes@189
   575
	 * handled differently
nkeynes@189
   576
	 */
nkeynes@189
   577
	if( ta_status.vertex_count == 3 ) {
nkeynes@189
   578
	    /* Triangles use an odd/even scheme */
nkeynes@189
   579
	    if( ta_status.poly_parity == 0 ) {
nkeynes@189
   580
		memcpy( &ta_status.poly_vertex[0], &ta_status.poly_vertex[2], 
nkeynes@189
   581
			sizeof(struct pvr2_ta_vertex) );
nkeynes@189
   582
		ta_status.poly_parity = 1;
nkeynes@189
   583
	    } else {
nkeynes@189
   584
		memcpy( &ta_status.poly_vertex[1], &ta_status.poly_vertex[2],
nkeynes@189
   585
			sizeof(struct pvr2_ta_vertex) );
nkeynes@189
   586
		ta_status.poly_parity = 0;
nkeynes@189
   587
	    }
nkeynes@189
   588
	} else {
nkeynes@189
   589
	    /* Everything else just uses the last 2 vertexes in order */
nkeynes@189
   590
	    memcpy( &ta_status.poly_vertex[0], &ta_status.poly_vertex[ta_status.vertex_count-2], 
nkeynes@189
   591
		    sizeof(struct pvr2_ta_vertex)*2 );
nkeynes@189
   592
	    ta_status.poly_parity = 0;
nkeynes@189
   593
	}
nkeynes@189
   594
	ta_status.vertex_count = 2;
nkeynes@189
   595
    } else {
nkeynes@189
   596
	ta_status.vertex_count = 0;
nkeynes@189
   597
    }
nkeynes@189
   598
}
nkeynes@189
   599
nkeynes@189
   600
/**
nkeynes@189
   601
 * Parse the polygon context block and setup the internal state to receive
nkeynes@189
   602
 * vertexes.
nkeynes@189
   603
 * @param data 32 bytes of parameter data.
nkeynes@189
   604
 */
nkeynes@189
   605
static void ta_parse_polygon_context( union ta_data *data ) {
nkeynes@189
   606
    int colourfmt = TA_POLYCMD_COLOURFMT(data[0].i);
nkeynes@189
   607
    ta_status.max_vertex = TA_POLYCMD_LENGTH(data[0].i);
nkeynes@189
   608
    ta_status.vertex_count = 0;
nkeynes@189
   609
    ta_status.poly_context[0] = 
nkeynes@189
   610
	(data[1].i & 0xFC1FFFFF) | ((data[0].i & 0x0B) << 22);
nkeynes@189
   611
    ta_status.poly_context[1] = data[2].i;
nkeynes@189
   612
    ta_status.poly_context[3] = data[4].i;
nkeynes@189
   613
    ta_status.poly_parity = 0;
nkeynes@189
   614
    if( data[0].i & TA_POLYCMD_TEXTURED ) {
nkeynes@189
   615
	ta_status.current_vertex_type = data[0].i & 0x0D;
nkeynes@189
   616
	ta_status.poly_context[2] = data[3].i;
nkeynes@189
   617
	ta_status.poly_context[4] = data[5].i;
nkeynes@189
   618
	if( data[0].i & TA_POLYCMD_SPECULAR ) {
nkeynes@189
   619
	    ta_status.poly_context[0] |= 0x01000000;
nkeynes@189
   620
	    ta_status.poly_vertex_size = 4;
nkeynes@189
   621
	} else {
nkeynes@189
   622
	    ta_status.poly_vertex_size = 3;
nkeynes@189
   623
	}
nkeynes@189
   624
	if( data[0].i & TA_POLYCMD_UV16 ) {
nkeynes@189
   625
	    ta_status.poly_vertex_size--;
nkeynes@189
   626
	}
nkeynes@189
   627
    } else {
nkeynes@189
   628
	ta_status.current_vertex_type = 0;
nkeynes@189
   629
	ta_status.poly_vertex_size = 1;
nkeynes@189
   630
	ta_status.poly_context[2] = 0;
nkeynes@189
   631
	ta_status.poly_context[4] = 0;
nkeynes@189
   632
    }
nkeynes@189
   633
nkeynes@189
   634
    ta_status.poly_pointer = (ta_status.poly_vertex_size << 21);
nkeynes@189
   635
    ta_status.poly_context_size = 3;
nkeynes@189
   636
    if( data[0].i & TA_POLYCMD_MODIFIED ) {
nkeynes@189
   637
	ta_status.poly_pointer |= 0x01000000;
nkeynes@189
   638
	if( data[0].i & TA_POLYCMD_FULLMOD ) {
nkeynes@189
   639
	    ta_status.poly_context_size = 5;
nkeynes@189
   640
	    ta_status.poly_vertex_size <<= 1;
nkeynes@189
   641
	    ta_status.current_vertex_type |= 0x40;
nkeynes@189
   642
	    /* Modified/float not supported - behaves as per last intensity */
nkeynes@189
   643
	    if( colourfmt == TA_POLYCMD_COLOURFMT_FLOAT ) {
nkeynes@189
   644
		colourfmt = TA_POLYCMD_COLOURFMT_LASTINT;
nkeynes@189
   645
	    }
nkeynes@189
   646
	}
nkeynes@189
   647
    }
nkeynes@189
   648
    
nkeynes@189
   649
    if( colourfmt == TA_POLYCMD_COLOURFMT_INTENSITY ) {
nkeynes@189
   650
	if( TA_POLYCMD_IS_FULLMOD(data[0].i) ||
nkeynes@189
   651
	    TA_POLYCMD_IS_SPECULAR(data[0].i) ) {
nkeynes@189
   652
	    ta_status.state = STATE_EXPECT_POLY_BLOCK2;
nkeynes@189
   653
	} else {
nkeynes@189
   654
	    ta_status.intensity1 = 
nkeynes@189
   655
		parse_float_colour( data[4].f, data[5].f, data[6].f, data[7].f );
nkeynes@189
   656
	}
nkeynes@189
   657
    } else if( colourfmt == TA_POLYCMD_COLOURFMT_LASTINT ) {
nkeynes@189
   658
	colourfmt = TA_POLYCMD_COLOURFMT_INTENSITY;
nkeynes@189
   659
    }
nkeynes@189
   660
nkeynes@189
   661
    ta_status.current_vertex_type |= colourfmt;
nkeynes@189
   662
}
nkeynes@189
   663
nkeynes@189
   664
/**
nkeynes@189
   665
 * Parse the modifier volume context block and setup the internal state to 
nkeynes@189
   666
 * receive modifier vertexes.
nkeynes@189
   667
 * @param data 32 bytes of parameter data.
nkeynes@189
   668
 */
nkeynes@189
   669
static void ta_parse_modifier_context( union ta_data *data ) {
nkeynes@189
   670
    ta_status.current_vertex_type = TA_VERTEX_MOD_VOLUME;
nkeynes@189
   671
    ta_status.poly_vertex_size = 0;
nkeynes@189
   672
    ta_status.poly_context_size = 3;
nkeynes@189
   673
    ta_status.poly_context[0] = (data[1].i & 0xFC1FFFFF) |
nkeynes@189
   674
	((data[0].i & 0x0B)<<22);
nkeynes@189
   675
    if( TA_POLYCMD_IS_SPECULAR(data[0].i) ) {
nkeynes@189
   676
	ta_status.poly_context[0] |= 0x01000000;
nkeynes@189
   677
    }
nkeynes@189
   678
    ta_status.poly_context[1] = 0;
nkeynes@189
   679
    ta_status.poly_context[2] = 0;
nkeynes@189
   680
    ta_status.vertex_count = 0;
nkeynes@189
   681
    ta_status.max_vertex = 3;
nkeynes@189
   682
    ta_status.poly_pointer = 0;
nkeynes@189
   683
}
nkeynes@189
   684
nkeynes@189
   685
/**
nkeynes@189
   686
 * Parse the sprite context block and setup the internal state to receive
nkeynes@189
   687
 * vertexes.
nkeynes@189
   688
 * @param data 32 bytes of parameter data.
nkeynes@189
   689
 */
nkeynes@189
   690
static void ta_parse_sprite_context( union ta_data *data ) {
nkeynes@189
   691
    ta_status.poly_context_size = 3;
nkeynes@189
   692
    ta_status.poly_context[0] = (data[1].i & 0xFC1FFFFF) |
nkeynes@189
   693
	((data[0].i & 0x0B)<<22) | 0x00400000;
nkeynes@189
   694
    if( TA_POLYCMD_IS_SPECULAR(data[0].i) ) {
nkeynes@189
   695
	ta_status.poly_context[0] |= 0x01000000;
nkeynes@189
   696
    }
nkeynes@189
   697
    ta_status.poly_context[1] = data[2].i;
nkeynes@189
   698
    ta_status.poly_context[2] = data[3].i;
nkeynes@189
   699
    if( data[0].i & TA_POLYCMD_TEXTURED ) {
nkeynes@189
   700
	ta_status.poly_vertex_size = 2;
nkeynes@189
   701
	ta_status.poly_vertex[2].detail[1] = data[4].i;
nkeynes@189
   702
	ta_status.current_vertex_type = TA_VERTEX_TEX_SPRITE;
nkeynes@189
   703
    } else {
nkeynes@189
   704
	ta_status.poly_vertex_size = 1;
nkeynes@189
   705
	ta_status.poly_vertex[2].detail[0] = data[4].i;
nkeynes@189
   706
	ta_status.current_vertex_type = TA_VERTEX_SPRITE;
nkeynes@189
   707
    }
nkeynes@189
   708
    ta_status.vertex_count = 0;
nkeynes@189
   709
    ta_status.max_vertex = 4;
nkeynes@189
   710
    ta_status.poly_pointer = (ta_status.poly_vertex_size << 21);
nkeynes@189
   711
}
nkeynes@189
   712
nkeynes@189
   713
/**
nkeynes@189
   714
 * Copy the last read vertex into all vertexes up to max_vertex. Used for
nkeynes@189
   715
 * Aborted polygons under some circumstances.
nkeynes@189
   716
 */
nkeynes@189
   717
static void ta_fill_vertexes( ) {
nkeynes@189
   718
    int i;
nkeynes@189
   719
    for( i=ta_status.vertex_count; i<ta_status.max_vertex; i++ ) {
nkeynes@189
   720
	memcpy( &ta_status.poly_vertex[i], &ta_status.poly_vertex[ta_status.vertex_count-1],
nkeynes@189
   721
		sizeof( struct pvr2_ta_vertex ) );
nkeynes@189
   722
    }
nkeynes@189
   723
}
nkeynes@189
   724
nkeynes@189
   725
static void ta_parse_vertex( union ta_data *data ) {
nkeynes@189
   726
    struct pvr2_ta_vertex *vertex = &ta_status.poly_vertex[ta_status.vertex_count];
nkeynes@189
   727
    vertex->x = data[1].f;
nkeynes@189
   728
    vertex->y = data[2].f;
nkeynes@189
   729
    vertex->z = data[3].f;
nkeynes@189
   730
nkeynes@189
   731
    switch( ta_status.current_vertex_type ) {
nkeynes@189
   732
    case TA_VERTEX_PACKED:
nkeynes@189
   733
	vertex->detail[0] = data[6].i;
nkeynes@189
   734
	break;
nkeynes@189
   735
    case TA_VERTEX_FLOAT:
nkeynes@189
   736
	vertex->detail[0] = parse_float_colour( data[4].f, data[5].f, data[6].f, data[7].f );
nkeynes@189
   737
	break;
nkeynes@189
   738
    case TA_VERTEX_INTENSITY:
nkeynes@189
   739
	vertex->detail[0] = parse_intensity_colour( ta_status.intensity1, data[6].f );
nkeynes@189
   740
	break;
nkeynes@189
   741
nkeynes@189
   742
    case TA_VERTEX_TEX_SPEC_PACKED:
nkeynes@189
   743
	vertex->detail[3] = data[7].i; /* ARGB */
nkeynes@189
   744
	/* Fallthrough */
nkeynes@189
   745
    case TA_VERTEX_TEX_PACKED:
nkeynes@189
   746
	vertex->detail[0] = data[4].i; /* U */
nkeynes@189
   747
	vertex->detail[1] = data[5].i; /* V */
nkeynes@189
   748
	vertex->detail[2] = data[6].i; /* ARGB */
nkeynes@189
   749
	break;
nkeynes@189
   750
    case TA_VERTEX_TEX_UV16_SPEC_PACKED:
nkeynes@189
   751
	vertex->detail[2] = data[7].i; /* ARGB */
nkeynes@189
   752
	/* Fallthrough */
nkeynes@189
   753
    case TA_VERTEX_TEX_UV16_PACKED:
nkeynes@189
   754
	vertex->detail[0] = data[4].i; /* UV */
nkeynes@189
   755
	vertex->detail[1] = data[6].i; /* ARGB */
nkeynes@189
   756
	break;
nkeynes@189
   757
nkeynes@189
   758
    case TA_VERTEX_TEX_FLOAT:
nkeynes@189
   759
    case TA_VERTEX_TEX_SPEC_FLOAT:
nkeynes@189
   760
	vertex->detail[0] = data[4].i; /* U */
nkeynes@189
   761
	vertex->detail[1] = data[5].i; /* UV */
nkeynes@189
   762
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   763
	break;
nkeynes@189
   764
    case TA_VERTEX_TEX_UV16_FLOAT:
nkeynes@189
   765
    case TA_VERTEX_TEX_UV16_SPEC_FLOAT:
nkeynes@189
   766
	vertex->detail[0] = data[4].i; /* UV */
nkeynes@189
   767
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   768
	break;
nkeynes@189
   769
nkeynes@189
   770
    case TA_VERTEX_TEX_SPEC_INTENSITY:
nkeynes@189
   771
	vertex->detail[3] = parse_intensity_colour( ta_status.intensity2, data[7].f );
nkeynes@189
   772
	/* Fallthrough */
nkeynes@189
   773
    case TA_VERTEX_TEX_INTENSITY:
nkeynes@189
   774
	vertex->detail[0] = data[4].i; /* U */
nkeynes@189
   775
	vertex->detail[1] = data[5].i; /* V */
nkeynes@189
   776
	vertex->detail[2] = parse_intensity_colour( ta_status.intensity1, data[6].f );
nkeynes@189
   777
	break;
nkeynes@189
   778
    case TA_VERTEX_TEX_UV16_SPEC_INTENSITY:
nkeynes@189
   779
	vertex->detail[2] = parse_intensity_colour( ta_status.intensity2, data[7].f );
nkeynes@189
   780
	/* Fallthrough */
nkeynes@189
   781
    case TA_VERTEX_TEX_UV16_INTENSITY:
nkeynes@189
   782
	vertex->detail[0] = data[4].i; /* UV */
nkeynes@189
   783
	vertex->detail[1] = parse_intensity_colour( ta_status.intensity1, data[6].f );
nkeynes@189
   784
	break;
nkeynes@189
   785
nkeynes@189
   786
    case TA_VERTEX_PACKED_MOD:
nkeynes@189
   787
	vertex->detail[0] = data[4].i; /* ARGB */
nkeynes@189
   788
	vertex->detail[1] = data[5].i; /* ARGB */
nkeynes@189
   789
	break;
nkeynes@189
   790
    case TA_VERTEX_INTENSITY_MOD:
nkeynes@189
   791
	vertex->detail[0] = parse_intensity_colour( ta_status.intensity1, data[4].f );
nkeynes@189
   792
	vertex->detail[1] = parse_intensity_colour( ta_status.intensity2, data[5].f );
nkeynes@189
   793
	break;
nkeynes@189
   794
nkeynes@189
   795
    case TA_VERTEX_TEX_SPEC_PACKED_MOD:
nkeynes@189
   796
	vertex->detail[3] = data[7].i; /* ARGB0 */
nkeynes@189
   797
	/* Fallthrough */
nkeynes@189
   798
    case TA_VERTEX_TEX_PACKED_MOD:
nkeynes@189
   799
	vertex->detail[0] = data[4].i; /* U0 */
nkeynes@189
   800
	vertex->detail[1] = data[5].i; /* V0 */
nkeynes@189
   801
	vertex->detail[2] = data[6].i; /* ARGB0 */
nkeynes@189
   802
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   803
	break;
nkeynes@189
   804
    case TA_VERTEX_TEX_UV16_SPEC_PACKED_MOD:
nkeynes@189
   805
	vertex->detail[2] = data[7].i; /* ARGB0 */
nkeynes@189
   806
	/* Fallthrough */
nkeynes@189
   807
    case TA_VERTEX_TEX_UV16_PACKED_MOD:
nkeynes@189
   808
	vertex->detail[0] = data[4].i; /* UV0 */
nkeynes@189
   809
	vertex->detail[1] = data[6].i; /* ARGB0 */
nkeynes@189
   810
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   811
	break;
nkeynes@189
   812
nkeynes@189
   813
    case TA_VERTEX_TEX_SPEC_INTENSITY_MOD:
nkeynes@189
   814
	vertex->detail[3] = parse_intensity_colour( ta_status.intensity1, data[7].f );
nkeynes@189
   815
	/* Fallthrough */
nkeynes@189
   816
    case TA_VERTEX_TEX_INTENSITY_MOD:
nkeynes@189
   817
	vertex->detail[0] = data[4].i; /* U0 */
nkeynes@189
   818
	vertex->detail[1] = data[5].i; /* V0 */
nkeynes@189
   819
	vertex->detail[2] = parse_intensity_colour( ta_status.intensity1, data[6].f );
nkeynes@189
   820
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   821
	break;
nkeynes@189
   822
    case TA_VERTEX_TEX_UV16_SPEC_INTENSITY_MOD:
nkeynes@189
   823
	vertex->detail[2] = parse_intensity_colour( ta_status.intensity1, data[7].f );
nkeynes@189
   824
	/* Fallthrough */
nkeynes@189
   825
    case TA_VERTEX_TEX_UV16_INTENSITY_MOD:
nkeynes@189
   826
	vertex->detail[0] = data[4].i; /* UV0 */
nkeynes@189
   827
	vertex->detail[1] = parse_intensity_colour( ta_status.intensity1, data[6].f );
nkeynes@189
   828
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   829
	break;
nkeynes@189
   830
	
nkeynes@189
   831
    case TA_VERTEX_SPRITE:
nkeynes@189
   832
    case TA_VERTEX_TEX_SPRITE:
nkeynes@189
   833
    case TA_VERTEX_MOD_VOLUME:
nkeynes@189
   834
	vertex++;
nkeynes@189
   835
	vertex->x = data[4].f;
nkeynes@189
   836
	vertex->y = data[5].f;
nkeynes@189
   837
	vertex->z = data[6].f;
nkeynes@189
   838
	vertex++;
nkeynes@189
   839
	vertex->x = data[7].f;
nkeynes@189
   840
	ta_status.vertex_count += 2;
nkeynes@189
   841
	ta_status.state = STATE_EXPECT_VERTEX_BLOCK2;
nkeynes@189
   842
	break;
nkeynes@189
   843
    }
nkeynes@189
   844
    ta_status.vertex_count++;
nkeynes@189
   845
}
nkeynes@189
   846
nkeynes@189
   847
static void ta_parse_vertex_block2( union ta_data *data ) {
nkeynes@189
   848
    struct pvr2_ta_vertex *vertex = &ta_status.poly_vertex[ta_status.vertex_count-1];
nkeynes@189
   849
nkeynes@189
   850
    switch( ta_status.current_vertex_type ) {
nkeynes@189
   851
    case TA_VERTEX_TEX_SPEC_FLOAT:
nkeynes@189
   852
	vertex->detail[3] = parse_float_colour( data[4].f, data[5].f, data[6].f, data[7].f );
nkeynes@189
   853
	/* Fallthrough */
nkeynes@189
   854
    case TA_VERTEX_TEX_FLOAT:
nkeynes@189
   855
	vertex->detail[2] = parse_float_colour( data[0].f, data[1].f, data[2].f, data[3].f );
nkeynes@189
   856
	break;
nkeynes@189
   857
    case TA_VERTEX_TEX_UV16_SPEC_FLOAT:
nkeynes@189
   858
	vertex->detail[2] = parse_float_colour( data[4].f, data[5].f, data[6].f, data[7].f );
nkeynes@189
   859
	/* Fallthrough */
nkeynes@189
   860
    case TA_VERTEX_TEX_UV16_FLOAT:
nkeynes@189
   861
	vertex->detail[1] = parse_float_colour( data[0].f, data[1].f, data[2].f, data[3].f );
nkeynes@189
   862
	break;
nkeynes@189
   863
    case TA_VERTEX_TEX_PACKED_MOD:
nkeynes@189
   864
	vertex->detail[3] = data[0].i; /* U1 */
nkeynes@189
   865
	vertex->detail[4] = data[1].i; /* V1 */
nkeynes@189
   866
	vertex->detail[5] = data[2].i; /* ARGB1 */
nkeynes@189
   867
	break;
nkeynes@189
   868
    case TA_VERTEX_TEX_SPEC_PACKED_MOD:
nkeynes@189
   869
	vertex->detail[4] = data[0].i; /* U1 */
nkeynes@189
   870
	vertex->detail[5] = data[1].i; /* V1 */
nkeynes@189
   871
	vertex->detail[6] = data[2].i; /* ARGB1 */
nkeynes@189
   872
	vertex->detail[7] = data[3].i; /* ARGB1 */
nkeynes@189
   873
	break;
nkeynes@189
   874
    case TA_VERTEX_TEX_UV16_PACKED_MOD:
nkeynes@189
   875
	vertex->detail[2] = data[0].i; /* UV1 */
nkeynes@189
   876
	vertex->detail[3] = data[2].i; /* ARGB1 */
nkeynes@189
   877
	break;
nkeynes@189
   878
    case TA_VERTEX_TEX_UV16_SPEC_PACKED_MOD:
nkeynes@189
   879
	vertex->detail[3] = data[0].i; /* UV1 */
nkeynes@189
   880
	vertex->detail[4] = data[2].i; /* ARGB1 */
nkeynes@189
   881
	vertex->detail[5] = data[3].i; /* ARGB1 */
nkeynes@189
   882
	break;
nkeynes@189
   883
nkeynes@189
   884
    case TA_VERTEX_TEX_INTENSITY_MOD:
nkeynes@189
   885
	vertex->detail[3] = data[0].i; /* U1 */
nkeynes@189
   886
	vertex->detail[4] = data[1].i; /* V1 */
nkeynes@189
   887
	vertex->detail[5] = parse_intensity_colour( ta_status.intensity2, data[2].f ); /* ARGB1 */
nkeynes@189
   888
	break;
nkeynes@189
   889
    case TA_VERTEX_TEX_SPEC_INTENSITY_MOD:
nkeynes@189
   890
	vertex->detail[4] = data[0].i; /* U1 */
nkeynes@189
   891
	vertex->detail[5] = data[1].i; /* V1 */
nkeynes@189
   892
	vertex->detail[6] = parse_intensity_colour( ta_status.intensity2, data[2].f ); /* ARGB1 */
nkeynes@189
   893
	vertex->detail[7] = parse_intensity_colour( ta_status.intensity2, data[3].f ); /* ARGB1 */
nkeynes@189
   894
	break;
nkeynes@189
   895
    case TA_VERTEX_TEX_UV16_INTENSITY_MOD:
nkeynes@189
   896
	vertex->detail[2] = data[0].i; /* UV1 */
nkeynes@189
   897
	vertex->detail[3] = parse_intensity_colour( ta_status.intensity2, data[2].f ); /* ARGB1 */
nkeynes@189
   898
	break;
nkeynes@189
   899
    case TA_VERTEX_TEX_UV16_SPEC_INTENSITY_MOD:
nkeynes@189
   900
	vertex->detail[3] = data[0].i; /* UV1 */
nkeynes@189
   901
	vertex->detail[4] = parse_intensity_colour( ta_status.intensity2, data[2].f ); /* ARGB1 */
nkeynes@189
   902
	vertex->detail[5] = parse_intensity_colour( ta_status.intensity2, data[3].f ); /* ARGB1 */
nkeynes@189
   903
	break;
nkeynes@189
   904
nkeynes@189
   905
    case TA_VERTEX_SPRITE:
nkeynes@189
   906
	vertex->y = data[0].f;
nkeynes@189
   907
	vertex->z = data[1].f;
nkeynes@189
   908
	vertex++;
nkeynes@189
   909
	ta_status.vertex_count++;
nkeynes@189
   910
	vertex->x = data[2].f;
nkeynes@189
   911
	vertex->y = data[3].f;
nkeynes@189
   912
	vertex->z = 0;
nkeynes@189
   913
	vertex->detail[0] = 0;
nkeynes@189
   914
	ta_status.poly_vertex[0].detail[0] = 0;
nkeynes@189
   915
	ta_status.poly_vertex[1].detail[0] = 0;
nkeynes@189
   916
	break;
nkeynes@189
   917
    case TA_VERTEX_TEX_SPRITE:
nkeynes@189
   918
	vertex->y = data[0].f;
nkeynes@189
   919
	vertex->z = data[1].f;
nkeynes@189
   920
	vertex++;
nkeynes@189
   921
	ta_status.vertex_count++;
nkeynes@189
   922
	vertex->x = data[2].f;
nkeynes@189
   923
	vertex->y = data[3].f;
nkeynes@189
   924
	vertex->z = 0;
nkeynes@189
   925
	vertex->detail[0] = 0;
nkeynes@189
   926
	vertex->detail[1] = 0;
nkeynes@189
   927
	ta_status.poly_vertex[0].detail[0] = data[5].i;
nkeynes@189
   928
	ta_status.poly_vertex[0].detail[1] = 0;
nkeynes@189
   929
	ta_status.poly_vertex[1].detail[0] = data[6].i;
nkeynes@189
   930
	ta_status.poly_vertex[1].detail[1] = 0;
nkeynes@189
   931
	ta_status.poly_vertex[2].detail[0] = data[7].i;
nkeynes@189
   932
	break;
nkeynes@189
   933
    case TA_VERTEX_MOD_VOLUME:
nkeynes@189
   934
	vertex->y = data[0].f;
nkeynes@189
   935
	vertex->z = data[1].f;
nkeynes@189
   936
	break;
nkeynes@189
   937
    }
nkeynes@189
   938
    ta_status.state = STATE_IN_LIST;
nkeynes@189
   939
}
nkeynes@189
   940
nkeynes@189
   941
/**
nkeynes@189
   942
 * Process 1 32-byte block of ta data
nkeynes@189
   943
 */
nkeynes@189
   944
void pvr2_ta_process_block( char *input ) {
nkeynes@189
   945
    union ta_data *data = (union ta_data *)input;
nkeynes@189
   946
nkeynes@189
   947
    switch( ta_status.state ) {
nkeynes@189
   948
    case STATE_ERROR:
nkeynes@189
   949
	/* Error raised - stop processing until reset */
nkeynes@189
   950
	return;
nkeynes@189
   951
nkeynes@189
   952
    case STATE_EXPECT_POLY_BLOCK2:
nkeynes@189
   953
	/* This is always a pair of floating-point colours */
nkeynes@189
   954
	ta_status.intensity1 = 
nkeynes@189
   955
	    parse_float_colour( data[0].f, data[1].f, data[2].f, data[3].f );
nkeynes@189
   956
	ta_status.intensity2 =
nkeynes@189
   957
	    parse_float_colour( data[4].f, data[5].f, data[6].f, data[7].f );
nkeynes@189
   958
	ta_status.state = STATE_IN_LIST;
nkeynes@189
   959
	break;
nkeynes@189
   960
nkeynes@189
   961
    case STATE_EXPECT_VERTEX_BLOCK2:
nkeynes@189
   962
	ta_parse_vertex_block2( data );
nkeynes@189
   963
	if( ta_status.vertex_count == ta_status.max_vertex ) {
nkeynes@189
   964
	    ta_split_polygon();
nkeynes@189
   965
	}
nkeynes@189
   966
	break;
nkeynes@189
   967
nkeynes@189
   968
    case STATE_EXPECT_END_VERTEX_BLOCK2:
nkeynes@189
   969
	ta_parse_vertex_block2( data );
nkeynes@189
   970
	ta_commit_polygon();
nkeynes@189
   971
	ta_status.vertex_count = 0;
nkeynes@189
   972
	ta_status.poly_parity = 0;
nkeynes@189
   973
nkeynes@189
   974
    case STATE_IN_LIST:
nkeynes@189
   975
    case STATE_IDLE:
nkeynes@189
   976
	switch( TA_CMD( data->i ) ) {
nkeynes@189
   977
	case TA_CMD_END_LIST:
nkeynes@189
   978
	    ta_end_list();
nkeynes@189
   979
	    break;
nkeynes@189
   980
	case TA_CMD_CLIP: /* TODO */
nkeynes@189
   981
	    break;
nkeynes@189
   982
	case TA_CMD_POLYGON_CONTEXT:
nkeynes@189
   983
	    if( ta_status.state == STATE_IDLE ) {
nkeynes@189
   984
		ta_init_list( TA_POLYCMD_LISTTYPE( data->i ) );
nkeynes@189
   985
	    }
nkeynes@189
   986
	    
nkeynes@189
   987
	    if( ta_status.vertex_count != 0 ) {
nkeynes@193
   988
		/* Error, and not a very well handled one either */
nkeynes@193
   989
		asic_event( EVENT_PVR_BAD_INPUT );
nkeynes@193
   990
		asic_event( EVENT_TA_ERROR );
nkeynes@193
   991
		ta_status.accept_vertexes = FALSE;
nkeynes@189
   992
		ta_fill_vertexes();
nkeynes@189
   993
	    } else {
nkeynes@193
   994
		if( TA_IS_MODIFIER_LIST( ta_status.current_list_type ) ) {
nkeynes@193
   995
		    ta_parse_modifier_context(data);
nkeynes@193
   996
		} else {
nkeynes@193
   997
		    ta_parse_polygon_context(data);
nkeynes@193
   998
		}
nkeynes@189
   999
	    }
nkeynes@189
  1000
	    break;
nkeynes@189
  1001
	case TA_CMD_SPRITE_CONTEXT:
nkeynes@189
  1002
	    if( ta_status.state == STATE_IDLE ) {
nkeynes@189
  1003
		ta_init_list( TA_POLYCMD_LISTTYPE( data->i ) );
nkeynes@189
  1004
	    }
nkeynes@189
  1005
nkeynes@189
  1006
	    if( ta_status.vertex_count != 0 ) {
nkeynes@189
  1007
		ta_fill_vertexes();
nkeynes@189
  1008
		ta_commit_polygon();
nkeynes@189
  1009
	    }
nkeynes@189
  1010
nkeynes@189
  1011
	    ta_parse_sprite_context(data);
nkeynes@189
  1012
	    break;
nkeynes@189
  1013
	case TA_CMD_VERTEX:
nkeynes@189
  1014
	    ta_parse_vertex(data);
nkeynes@189
  1015
	    
nkeynes@189
  1016
	    if( ta_status.state == STATE_EXPECT_VERTEX_BLOCK2 ) {
nkeynes@189
  1017
		if( TA_IS_END_VERTEX(data[0].i) ) {
nkeynes@189
  1018
		    ta_status.state = STATE_EXPECT_END_VERTEX_BLOCK2;
nkeynes@189
  1019
		}
nkeynes@189
  1020
	    } else if( TA_IS_END_VERTEX(data->i) ) {
nkeynes@189
  1021
		ta_commit_polygon();
nkeynes@189
  1022
		ta_status.vertex_count = 0;
nkeynes@189
  1023
		ta_status.poly_parity = 0;
nkeynes@189
  1024
	    } else if( ta_status.vertex_count == ta_status.max_vertex ) {
nkeynes@189
  1025
		ta_split_polygon();
nkeynes@189
  1026
	    }
nkeynes@189
  1027
	    break;
nkeynes@189
  1028
	}
nkeynes@189
  1029
	break;
nkeynes@189
  1030
    }
nkeynes@189
  1031
nkeynes@189
  1032
}
nkeynes@189
  1033
nkeynes@189
  1034
nkeynes@189
  1035
nkeynes@189
  1036
/**
nkeynes@189
  1037
 * Write a block of data to the tile accelerator, adding the data to the 
nkeynes@189
  1038
 * current scene. We don't make any particular attempt to interpret the data
nkeynes@189
  1039
 * at this stage, deferring that until render time.
nkeynes@189
  1040
 *
nkeynes@189
  1041
 * Currently copies the data verbatim to the vertex buffer, processing only
nkeynes@189
  1042
 * far enough to generate the correct end-of-list events. Tile buffer is
nkeynes@189
  1043
 * entirely ignored.
nkeynes@189
  1044
 */
nkeynes@189
  1045
void pvr2_ta_write( char *buf, uint32_t length )
nkeynes@189
  1046
{
nkeynes@189
  1047
    if( ta_status.debug_output ) {
nkeynes@189
  1048
	fwrite_dump32( (uint32_t *)buf, length, stderr );
nkeynes@189
  1049
    }
nkeynes@189
  1050
nkeynes@189
  1051
    for( ; length >=32; length -= 32 ) {
nkeynes@189
  1052
	pvr2_ta_process_block( buf );
nkeynes@189
  1053
	buf += 32;
nkeynes@189
  1054
    }
nkeynes@189
  1055
}
.