/* checks the memblock of <size> bytes from <startaddr> returns the address of the error or NULL if all is well  */
void* RAM_MemTest_CheckRandomPattern(int mode, unsigned long startaddr, unsigned long size, unsigned long *pat)
/* checks the memblock of <size> bytes from <startaddr> returns the address of the error or NULL if all is well  */
void* RAM_MemTest_CheckRandomPattern(int mode, unsigned long startaddr, unsigned long size, unsigned long *pat)
{
	void *perr = NULL;
	unsigned long i, p, p1;
	p = *pat;
	for (i = 0; i < (size / 4); i++) {
		p1 = *(unsigned long *) (startaddr + i * 4);
		if (p1 != p) {
			if (perr == NULL) {
				Write_Error (mode, startaddr + i * 4, p, p1);
				perr = (void *) (startaddr + i * 4);
			}
		}
		if ((p % 2) > 0) {
			p ^= i;
			p >>= 1;
			p |= 0x80000000;
		} else {
			p ^= ~i;
			p >>= 1;
		}
	}
	*pat = p;
	return (perr);
}