/******************************************************************************
;
;	SELFADDR.C: Does a self-address test.
;
;
;	[-kdb-] 10:43:39.21 08-29-1996
*******************************************************************************/
#include <stdio.h>
#include "devreg.h"
/******************************************************************************/
/*                           C O N S T A N T S                                */
/******************************************************************************/
/******************************************************************************/
/*                            T Y P E D E F S                                 */
/******************************************************************************/
/******************************************************************************/
/*                          P R O T O T Y P E S                               */
/******************************************************************************/
/*--------------[helpers]-----------*/
/*--------------[the usual suspects]-----------*/
void main(int,char**);
/******************************************************************************/
/*                           F U N C T I O N S                                */
/******************************************************************************/
/******************************************************************************/
void main(int argc,char**argv)
/******************************************************************************/
{
	DWORD dw,dwVal,dwTval,dwBaseLine;
	WORD  wOft;
	/*---
	  Make sure the A20 line is on. The device registers ftns
	  require it.
	  ---*/
	A20On();
	/*---
	  Start at the so-called High Memory Area. This is
	  the region b/w 100000h and 10ffefh, or 0ffffh:00010h
	  and 0ffffh:0ffffh. Any memory beyond 10ffefh is
	  referred to as Extended Memory.
	  ---*/
	dw = 1l << 20;
	printf("%8.8lx\n",dw);
	
	/*---
	    Write the 32-bit address of the current DWORD to itself.
	  Read back the value from the same address and see if it's
	  equal to itself. Continue until the value read back is
	  not the same as what was written. At this point we
	  assume either that we've run out of memory or we have found
	  an error in one of the DeviceRegister ftns. In either case
	  we exit the loop.
	  ---*/	
	for(;;){
	  WriteDeviceRegister(dw,0,dw);
	  dwTval = ReadDeviceRegister(dw,0);
	  if (dwTval != dw ){
	    printf("\n%8.8lx\n",dw);
	    break;
	  }
	  dw += sizeof(DWORD);
	  if( !(dw & 0xffffl) )
	    printf("%8.8lx\n",dw);
	} /* [---end.for---] */
	
	/*---
	  Just to be sure we read back what we've just written.
	  ---*/	
	dw = 1l << 20;
	printf("%8.8lx\n",dw);
	for(;;){
	  dwVal = ReadDeviceRegister(dw,0);
	  if (dwVal != dw ){
	  	/*--- 
		  we've found a mismatch, display the value at
		  the current address
		  ---*/
	    printf("\n%8.8lx: %8.8lx\n",dw,dwVal);
	    break;
	  }
	  dw += sizeof(DWORD);
	  if( !(dw & 0xffffl) ){
	    printf("%8.8lx\n",dw);
	  }	
	} /* [---end.for---] */
}
