flat_shade_dl.c
4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
/*
* File: flat_shade_dl.c
*
* This program reads in a RDP command stream and changes smooth shaded prims
* to be flat shaded using random colors.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef __sgi__
#include <bstring.h>
#endif
#include <string.h>
#include "mbi.h"
#define UsageString "<rdp binfile> <outfile>"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifndef ABS
#define ABS(x) ((x) > 0 ? (x) : (-(x)))
#endif
typedef int bool;
FILE *Outfp = NULL;
static bool do_verbose = FALSE;
static u32 NumPrimitives = 0;
/*
* Parse and dump a RDP-type display list command.
*/
static void
read_rdp(u32 gfx0, u32 gfx1, FILE *in)
{
u32 addr, buffer[44];
char op, b0, tstring[32];
int i;
/* every command has at least 64-bits... */
buffer[0] = gfx0;
buffer[1] = gfx1;
op = (char) ((gfx0 & 0xff000000) >> 24);
switch (op) {
case (char) G_SETCIMG:
case (char) G_SETZIMG:
case (char) G_SETTIMG:
case (char) G_SETENVCOLOR:
case (char) G_SETPRIMCOLOR:
case (char) G_SETBLENDCOLOR:
case (char) G_SETFOGCOLOR:
case (char) G_SETFILLCOLOR:
case (char) G_FILLRECT:
case (char) G_SETTILE:
case (char) G_LOADTILE:
case (char) G_LOADBLOCK:
case (char) G_SETTILESIZE:
case (char) G_LOADTLUT:
case (char) G_RDPSETOTHERMODE:
case (char) G_SETPRIMDEPTH:
case (char) G_SETSCISSOR:
case (char) G_SETCONVERT:
case (char) G_SETKEYR:
case (char) G_SETKEYGB:
case (char) G_RDPFULLSYNC:
case (char) G_RDPTILESYNC:
case (char) G_RDPPIPESYNC:
case (char) G_NOOP:
case (char) G_TEXRECTFLIP:
case (char) G_TEXRECT:
case (char) G_SETCOMBINE:
fwrite( &gfx0, sizeof(u32), 1, Outfp);
fwrite( &gfx1, sizeof(u32), 1, Outfp);
break;
case (char) G_TRI_FILL:
fread(&buffer[2], sizeof(u32), 6, in);
fwrite( buffer, sizeof(u32), 8, Outfp);
break;
case (char) G_TRI_SHADE:
fread(&buffer[2], sizeof(u32), 22, in);
buffer[8] = random() & 0x00ff00ff;
buffer[9] = (random() & 0x00ff0000) | 0xff;
for(i = 10; i < 24; i++)
buffer[i] = 0;
fwrite( buffer, sizeof(u32), 24, Outfp);
break;
case (char) G_TRI_TXTR:
fread(&buffer[2], sizeof(u32), 22, in);
fwrite( buffer, sizeof(u32), 24, Outfp);
break;
case (char) G_TRI_SHADE_TXTR:
fread(&buffer[2], sizeof(u32), 38, in);
fwrite( buffer, sizeof(u32), 40, Outfp);
break;
case (char) G_TRI_FILL_ZBUFF:
fread(&buffer[2], sizeof(u32), 10, in);
fwrite( buffer, sizeof(u32), 12, Outfp);
break;
case (char) G_TRI_SHADE_ZBUFF:
fread(&buffer[2], sizeof(u32), 26, in);
fwrite( buffer, sizeof(u32), 28, Outfp);
break;
case (char) G_TRI_TXTR_ZBUFF:
fread(&buffer[2], sizeof(u32), 26, in);
fwrite( buffer, sizeof(u32), 28, Outfp);
break;
case (char) G_TRI_SHADE_TXTR_ZBUFF:
fread(&buffer[2], sizeof(u32), 42, in);
fwrite( buffer, sizeof(u32), 44, Outfp);
break;
default:
break;
}
}
/*
* main routine.
*/
int
main(int argc, char *argv[])
{
FILE *bin_file;
u32 gfx0, gfx1, *gfxp;
int i;
while ((argc > 1) && (argv[1][0] == '-')) {
switch(argv[1][1]) {
case 'v':
do_verbose = FALSE;
break;
default:
fprintf(stderr,"%s : unknown argument [%s].\n",argv[0],argv[1]);
break;
}
argc--;
argv++;
}
if (argc != 3) {
fprintf(stderr,"usage: %s %s.\n",argv[0],UsageString);
exit(-1);
}
if ((bin_file=fopen(argv[1],"r"))==NULL) {
fprintf(stderr,"can't open bin file [%s].\n",argv[1]);
exit(-1);
}
if (argc > 2) {
if ((Outfp=fopen(argv[2],"w"))==NULL) {
fprintf(stderr,"can't open output file [%s].\n",argv[2]);
exit(-1);
}
}
fread(&gfx0, sizeof(u32), 1, bin_file);
fread(&gfx1, sizeof(u32), 1, bin_file);
while (!feof(bin_file)) {
read_rdp(gfx0, gfx1, bin_file);
fread(&gfx0, sizeof(u32), 1, bin_file);
fread(&gfx1, sizeof(u32), 1, bin_file);
}
fclose(Outfp);
}