checkall.c 5.51 KB
#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);    
}