2 * $Id: ta.c,v 1.3 2006-03-15 13:16:50 nkeynes Exp $
4 * PVR2 Tile Accelerator support. In principle this does a lot more work
5 * than is currently implemented - we cheat. A lot.
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include "pvr2/pvr2.h"
24 /** Tile Accelerator */
40 uint32_t blank, blank2;
45 struct pvr2_ta_status {
47 unsigned int last_poly_type;
48 } pvr2_ta_status = {NULL,0};
51 * (Re)initialize the tile accelerator in preparation for the next scene.
52 * Normally called immediately before commencing polygon transmission.
54 void pvr2_ta_init( void )
56 /* Set the buffer indexes */
57 MMIO_WRITE( PVR2, TAOBJPOS, MMIO_READ( PVR2, TAOBJBASE ) );
58 MMIO_WRITE( PVR2, TAOBJPPOS, MMIO_READ( PVR2, TAOBJPBASE ) );
59 pvr2_ta_status.last_poly_type = 0;
60 pvr2_ta_status.length = NULL;
64 * Write a block of data to the tile accelerator, adding the data to the
65 * current scene. We don't make any particular attempt to interpret the data
66 * at this stage, deferring that until render time.
68 * Currently copies the data verbatim to the vertex buffer, processing only
69 * far enough to generate the correct end-of-list events. Tile buffer is
72 void pvr2_ta_write( char *buf, uint32_t length )
75 struct tacmd *cmd_list = (struct tacmd *)buf;
76 uint32_t obj_addr = MMIO_READ( PVR2, TAOBJPOS );
77 if( pvr2_ta_status.length == NULL ) { /* Start */
78 pvr2_ta_status.length = (uint32_t *)mem_get_region( PVR2_RAM_BASE + obj_addr );
80 *pvr2_ta_status.length = length;
82 *pvr2_ta_status.length = *pvr2_ta_status.length + length;
84 mem_copy_to_sh4( PVR2_RAM_BASE + obj_addr, buf, length );
85 MMIO_WRITE( PVR2, TAOBJPOS, obj_addr + length );
87 int count = length >> 5;
88 for( i=0; i<count; i++ ){
89 unsigned int type = (cmd_list[i].command >> 24) & 0xFF;
90 if( type == 0xE0 || type == 0xF0 ) {
91 struct vertex_type1 *vert = (struct vertex_type1 *)&cmd_list[i];
92 // DEBUG( "PVR2 vrt: %f %f %f %08X %08X %08X %f", vert->x, vert->y, vert->z, vert->blank, vert->blank2, vert->col, vert->f );
94 // DEBUG( "PVR2 cmd: %08X %08X %08X %08X %08X %08X %08X %08X", cmd_list[i].command, cmd_list[i].param1, cmd_list[i].param2, cmd_list[i].texture, cmd_list[i].alpha, cmd_list[i].red, cmd_list[i].green, cmd_list[i].blue );
98 switch( pvr2_ta_status.last_poly_type ) {
99 case 0x80: /* Opaque polys */
100 asic_event( EVENT_PVR_OPAQUE_DONE );
102 case 0x81: /* Opaque poly modifier */
103 asic_event( EVENT_PVR_OPAQUEMOD_DONE );
105 case 0x82: /* Transparent polys */
106 asic_event( EVENT_PVR_TRANS_DONE );
108 case 0x83: /* Transparent poly modifier */
109 asic_event( EVENT_PVR_TRANSMOD_DONE );
111 case 0x84: /* Punchthrough */
112 asic_event( EVENT_PVR_PUNCHOUT_DONE );
115 pvr2_ta_status.last_poly_type = 0;
116 } else if( type >= 0x80 && type <= 0x84 ) {
117 pvr2_ta_status.last_poly_type = type;
.