filename | src/pvr2/ta.c |
changeset | 108:565de331ccec |
prev | 103:9b9cfc5855e0 |
author | nkeynes |
date | Thu Jun 15 10:25:45 2006 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Add P4 I/O tracing Add ability to set I/O trace by region address |
view | annotate | diff | log | raw |
1 /**
2 * $Id: ta.c,v 1.3 2006-03-15 13:16:50 nkeynes Exp $
3 *
4 * PVR2 Tile Accelerator support. In principle this does a lot more work
5 * than is currently implemented - we cheat. A lot.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
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.
13 *
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.
18 */
20 #include "pvr2/pvr2.h"
21 #include "asic.h"
22 #include "dream.h"
24 /** Tile Accelerator */
26 struct tacmd {
27 uint32_t command;
28 uint32_t param1;
29 uint32_t param2;
30 uint32_t texture;
31 float alpha;
32 float red;
33 float green;
34 float blue;
35 };
37 struct vertex_type1 {
38 uint32_t command;
39 float x, y, z;
40 uint32_t blank, blank2;
41 uint32_t col;
42 float f;
43 };
45 struct pvr2_ta_status {
46 uint32_t *length;
47 unsigned int last_poly_type;
48 } pvr2_ta_status = {NULL,0};
50 /**
51 * (Re)initialize the tile accelerator in preparation for the next scene.
52 * Normally called immediately before commencing polygon transmission.
53 */
54 void pvr2_ta_init( void )
55 {
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;
61 }
63 /**
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.
67 *
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
70 * entirely ignored.
71 */
72 void pvr2_ta_write( char *buf, uint32_t length )
73 {
74 int i;
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 );
79 obj_addr += 4;
80 *pvr2_ta_status.length = length;
81 } else {
82 *pvr2_ta_status.length = *pvr2_ta_status.length + length;
83 }
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 );
93 } else {
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 );
95 }
96 if( type == 0 ) {
97 /* End of list */
98 switch( pvr2_ta_status.last_poly_type ) {
99 case 0x80: /* Opaque polys */
100 asic_event( EVENT_PVR_OPAQUE_DONE );
101 break;
102 case 0x81: /* Opaque poly modifier */
103 asic_event( EVENT_PVR_OPAQUEMOD_DONE );
104 break;
105 case 0x82: /* Transparent polys */
106 asic_event( EVENT_PVR_TRANS_DONE );
107 break;
108 case 0x83: /* Transparent poly modifier */
109 asic_event( EVENT_PVR_TRANSMOD_DONE );
110 break;
111 case 0x84: /* Punchthrough */
112 asic_event( EVENT_PVR_PUNCHOUT_DONE );
113 break;
114 }
115 pvr2_ta_status.last_poly_type = 0;
116 } else if( type >= 0x80 && type <= 0x84 ) {
117 pvr2_ta_status.last_poly_type = type;
118 }
119 }
120 }
.