checkall.c
5.51 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include <stdio.h>
#include <stdlib.h>
#include <gl/image.h>
#include "PR/rdpsim/test/vi/OutData/vi_pipe/vi_pipe.c"
char *OutFileName = NULL;
char *InFileName = NULL;
char *RGBFileName = NULL;
int OutputRgb = 0;
FILE *InFile;
FILE *OutFile;
IMAGE *RGBFile;
int CurrentX, CurrentY, SyncsSeen, PixelsValid;
unsigned short *BufferPtr[3];
unsigned short *RedBuffer, *GreenBuffer, *BlueBuffer, BufferIndex;
unsigned int ImageWidth = 320;
unsigned int ImageHeight = 240;
unsigned int ValidLines = 0;
int NumLines = 0;
int NumErrors = 0;
void InitPixelVariables()
{
RedBuffer = (unsigned short *) malloc(ImageWidth * sizeof(unsigned short));
GreenBuffer = (unsigned short *) malloc(ImageWidth * sizeof(unsigned short));
BlueBuffer = (unsigned short *) malloc(ImageWidth * sizeof(unsigned short));
BufferPtr[0] = RedBuffer;
BufferPtr[1] = GreenBuffer;
BufferPtr[2] = BlueBuffer;
CurrentX = 0; CurrentY = 0;
BufferIndex = 0;
PixelsValid = 0;
SyncsSeen = 0;
}
void usage(void)
{
printf("Try again \n");
exit(1);
}
GetOptions(int argc, char *argv[])
{
int c;
extern char *optarg;
extern int optind;
int errflg = 0;
while ((c = getopt(argc, argv, "i:o:r:w:h:")) != EOF)
switch (c)
{
case 'i':
InFileName = optarg;
break;
case 'o':
OutFileName = optarg;
break;
case 'r':
RGBFileName = optarg;
break;
case 'w':
ImageWidth = atoi(optarg);
break;
case 'h':
ImageHeight = atoi(optarg);
break;
case '?':
errflg++;
}
if (errflg) usage;
}
void OpenFiles(void)
{
if ((InFile = fopen(InFileName, "r")) == NULL)
{
fprintf(stderr, "ERROR, cannot open input file %s \n",
InFileName);
exit(1);
}
if (OutFileName != NULL)
{
if ((OutFile = fopen(OutFileName, "w")) == NULL)
{
fprintf(stderr, "ERROR, cannot open output file %s \n",
OutFileName);
exit(1);
}
}
if (RGBFileName != NULL)
{
InitPixelVariables();
if ((RGBFile = iopen(RGBFileName, "w", RLE(1), 3, ImageWidth, ImageHeight, 3)) == NULL)
{
fprintf(stderr, "ERROR, cannot open output rgb file");
exit(1);
}
printf("Using width of %d height of %d \n", ImageWidth, ImageHeight);
OutputRgb = 1;
}
}
void CloseFiles(void)
{
if (InFile != NULL) fclose(InFile);
if (OutFile != NULL) fclose(OutFile);
if (RGBFile != NULL) iclose(RGBFile);
}
void WritePixel(unsigned int sync, unsigned int srgb)
{
if (!sync & (srgb >> 3))
{
SyncsSeen++;
}
else /* sync == 0 */
{
if (SyncsSeen >= 12)
{
PixelsValid = 1;
}
if (PixelsValid && (CurrentX >= 0) && (CurrentX <= ImageWidth-1) &&
(CurrentY <= ImageHeight-1))
{
*(BufferPtr[BufferIndex]) = srgb;
(BufferPtr[BufferIndex])++;
}
if ((CurrentX == ImageWidth+1) && (BufferIndex == 2))
{
putrow(RGBFile, RedBuffer, ImageHeight - 1 - CurrentY, 0);
putrow(RGBFile, GreenBuffer, ImageHeight - 1 - CurrentY, 1);
putrow(RGBFile, BlueBuffer, ImageHeight - 1 - CurrentY, 2);
CurrentX = -3; CurrentY++;
BufferPtr[0] = RedBuffer;
BufferPtr[1] = GreenBuffer;
BufferPtr[2] = BlueBuffer;
}
if (PixelsValid)
{
BufferIndex++;
ValidLines++;
}
if (BufferIndex == 3)
{
CurrentX++;
BufferIndex = 0;
}
}
}
main(int argc, char *argv[])
{
char InData[200] = "foo";
char *ReadOk = "foo";
int CurrentLine = 0;
int SyncsSeen = 0;
unsigned int divot_enable, type, aa_off, gamma_enable, gamma_dither_enable,
rand, hfrac, vfrac, rgb0i, rgb1i, rgb2i, rgb3i, cvg0i, cvg1i,
cvg2i, cvg3i, synci, csrgb, csync, vsrgb, vsync;
GetOptions(argc, argv);
OpenFiles();
while((InData[0] != '0') && (InData[0] != '1'))
{
fgets(InData, 150, InFile);
CurrentLine++;
}
while (ReadOk)
{
if (OutputRgb)
{
sscanf(InData, "%d %x %d %d %d %x %x %x %x %x %x %x %x %x %x %x %d",
&divot_enable, &type, &aa_off, &gamma_enable, &gamma_dither_enable, &rand, &hfrac, &vfrac,
&rgb0i, &rgb1i, &rgb2i, &rgb3i, &cvg0i, &cvg1i, &cvg2i, &cvg3i, &synci);
}
else
{
sscanf(InData, "%d %x %d %d %d %x %x %x %x %x %x %x %x %x %x %x %d %x %d",
&divot_enable, &type, &aa_off, &gamma_enable, &gamma_dither_enable, &rand, &hfrac, &vfrac,
&rgb0i, &rgb1i, &rgb2i, &rgb3i, &cvg0i, &cvg1i, &cvg2i,
&cvg3i, &synci, &vsrgb, &vsync);
}
vi_pipe(divot_enable, type, aa_off , gamma_enable, gamma_dither_enable, rand, hfrac, vfrac,
rgb0i, rgb1i, rgb2i, rgb3i, cvg0i, cvg1i, cvg2i, cvg3i, synci, &csrgb, &csync);
if (OutputRgb)
{
WritePixel(csync, csrgb);
}
else
{
/* Need to skip the first batch of output to get to valid values */
if (!csync & (csrgb >> 3))
{
SyncsSeen++;
}
if (SyncsSeen >= 12)
{
ValidLines++;
if (csrgb != vsrgb)
{
printf("ERROR srgb, line %d (computed) 0x%.2x != (verilog) 0x%.2x \n",
ValidLines, csrgb, vsrgb);
NumErrors++;
}
if (csync != vsync)
{
printf("ERROR sync, line %d (computed) %d != (verilog) %d \n",
ValidLines, csync, vsync);
NumErrors++;
}
}
}
if (ValidLines && !(ValidLines % 1000))
{
fprintf(stderr, ".");
}
ReadOk = fgets(InData, 150, InFile);
CurrentLine++;
}
fprintf(stderr, "\n");
CloseFiles();
printf("!!! %s of vi_pipe: number of errors:\t\t%d\n", InFileName, NumErrors);
}