vi_rand.c 2.41 KB
extern int CurrentLine;

void vi_rand(unsigned int reset_l, unsigned int *vrand)
{
    static unsigned int reset, orand29b, orand27b, orand25b, 
	orand23b, orand19b, orand17b, orand29q, orand27q, 
	orand25q, orand23q, orand19q, orand17q, nrand29b, 
	nrand27b, nrand25b, nrand23b, nrand19b, nrand17b,
	nrand29q, nrand27q, nrand25q, nrand23q, nrand19q, 
	nrand17q;

    reset = !reset_l;

    /* printf("%.3d: %d %d %d %d %d %d 0x%.2x \n", CurrentLine, 
	   orand29q, orand27q, orand25q, orand23q, orand19q, orand17q, *vrand); */

    /* printf("%.3d: %d -> %.7x %.7x %.6x %.6x %.5x %.4x \n", 
	   CurrentLine, reset_l, 
	   orand29b, orand27b, orand25b,
	   orand23b, orand19b, orand17b); */

    /* printf("%.3d: %d -> %d %d %d %d %d %d \n", 
	   CurrentLine, reset_l, 
	   orand29q, orand27q, orand25q,
	   orand23q, orand19q, orand17q); */

    if (reset == 1)
	{
	    orand29q = nrand29q = 1;
	    orand27q = nrand27q = 1;
	    orand25q = nrand25q = 1;
	    orand23q = nrand23q = 1;	    
	    orand19q = nrand19q = 1;
	    orand17q = nrand17q = 1;
	}
    else
	{
	    nrand29q = ((orand29b & (1 << 27)) >> 27) ^ (orand29b & 1);
	    nrand27q = ((orand27b & (1 << 25)) >> 25) ^ ((orand27b & (1 << 3)) >> 3) ^ (orand27b & 1) ^ (orand27q);
	    nrand25q = ((orand25b & (1 << 23)) >> 23) ^ ((orand25b & (1 << 1)) >> 1);
	    nrand23q = ((orand23b & (1 << 21)) >> 21) ^ ((orand23b & (1 << 3)) >> 3);
	    nrand19q = ((orand19b & (1 << 17)) >> 17) ^ ((orand19b & (1 << 3)) >> 3) ^ (orand19b & 1) ^ (orand19q);
	    nrand17q = ((orand17b & (1 << 15)) >> 15) ^ ((orand17b & (1 << 1)) >> 1);
	}
    
    /* printf("%.3d: %d %d 0x%.7x %d \n", CurrentLine, reset_l, orand27q, orand27b, reset); */

    *vrand = 
	(orand29q << 5) | (orand27q << 4) | (orand25q << 3) | 
	(orand23q << 2) | (orand19q << 1) | (orand17q << 0);
    
    nrand29b = ((orand29b & 0x7ffffff) << 1) | orand29q;
    nrand27b = ((orand27b & 0x1ffffff) << 1) | orand27q;
    nrand25b = ((orand25b & 0x07fffff) << 1) | orand25q;
    nrand23b = ((orand23b & 0x01fffff) << 1) | orand23q;
    nrand19b = ((orand19b & 0x001ffff) << 1) | orand19q;
    nrand17b = ((orand17b & 0x0007fff) << 1) | orand17q;

    orand29b = nrand29b;
    orand27b = nrand27b;
    orand25b = nrand25b;
    orand23b = nrand23b;
    orand19b = nrand19b;
    orand17b = nrand17b;

    orand29q = nrand29q;
    orand27q = nrand27q;
    orand25q = nrand25q;
    orand23q = nrand23q;
    orand19q = nrand19q;
    orand17q = nrand17q;
}